├── .gitignore ├── .gitmodules ├── LICENSE ├── Makefile ├── README ├── gstbitreader.c ├── gstbitreader.h ├── gstbytereader.c ├── gstbytereader.h ├── gsth265parser.c ├── gsth265parser.h ├── main.c ├── nalutils.c └── nalutils.h /.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | vdpau_hw_hevc 3 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "vdpau-win-x11"] 2 | path = vdpau-win-x11 3 | url = https://github.com/NVIDIA/vdpau-win-x11.git 4 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU LESSER GENERAL PUBLIC LICENSE 2 | Version 2.1, February 1999 3 | 4 | Copyright (C) 1991, 1999 Free Software Foundation, Inc. 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | [This is the first released version of the Lesser GPL. It also counts 10 | as the successor of the GNU Library Public License, version 2, hence 11 | the version number 2.1.] 12 | 13 | Preamble 14 | 15 | The licenses for most software are designed to take away your 16 | freedom to share and change it. By contrast, the GNU General Public 17 | Licenses are intended to guarantee your freedom to share and change 18 | free software--to make sure the software is free for all its users. 19 | 20 | This license, the Lesser General Public License, applies to some 21 | specially designated software packages--typically libraries--of the 22 | Free Software Foundation and other authors who decide to use it. You 23 | can use it too, but we suggest you first think carefully about whether 24 | this license or the ordinary General Public License is the better 25 | strategy to use in any particular case, based on the explanations below. 26 | 27 | When we speak of free software, we are referring to freedom of use, 28 | not price. Our General Public Licenses are designed to make sure that 29 | you have the freedom to distribute copies of free software (and charge 30 | for this service if you wish); that you receive source code or can get 31 | it if you want it; that you can change the software and use pieces of 32 | it in new free programs; and that you are informed that you can do 33 | these things. 34 | 35 | To protect your rights, we need to make restrictions that forbid 36 | distributors to deny you these rights or to ask you to surrender these 37 | rights. These restrictions translate to certain responsibilities for 38 | you if you distribute copies of the library or if you modify it. 39 | 40 | For example, if you distribute copies of the library, whether gratis 41 | or for a fee, you must give the recipients all the rights that we gave 42 | you. You must make sure that they, too, receive or can get the source 43 | code. If you link other code with the library, you must provide 44 | complete object files to the recipients, so that they can relink them 45 | with the library after making changes to the library and recompiling 46 | it. And you must show them these terms so they know their rights. 47 | 48 | We protect your rights with a two-step method: (1) we copyright the 49 | library, and (2) we offer you this license, which gives you legal 50 | permission to copy, distribute and/or modify the library. 51 | 52 | To protect each distributor, we want to make it very clear that 53 | there is no warranty for the free library. Also, if the library is 54 | modified by someone else and passed on, the recipients should know 55 | that what they have is not the original version, so that the original 56 | author's reputation will not be affected by problems that might be 57 | introduced by others. 58 | 59 | Finally, software patents pose a constant threat to the existence of 60 | any free program. We wish to make sure that a company cannot 61 | effectively restrict the users of a free program by obtaining a 62 | restrictive license from a patent holder. Therefore, we insist that 63 | any patent license obtained for a version of the library must be 64 | consistent with the full freedom of use specified in this license. 65 | 66 | Most GNU software, including some libraries, is covered by the 67 | ordinary GNU General Public License. This license, the GNU Lesser 68 | General Public License, applies to certain designated libraries, and 69 | is quite different from the ordinary General Public License. We use 70 | this license for certain libraries in order to permit linking those 71 | libraries into non-free programs. 72 | 73 | When a program is linked with a library, whether statically or using 74 | a shared library, the combination of the two is legally speaking a 75 | combined work, a derivative of the original library. The ordinary 76 | General Public License therefore permits such linking only if the 77 | entire combination fits its criteria of freedom. The Lesser General 78 | Public License permits more lax criteria for linking other code with 79 | the library. 80 | 81 | We call this license the "Lesser" General Public License because it 82 | does Less to protect the user's freedom than the ordinary General 83 | Public License. It also provides other free software developers Less 84 | of an advantage over competing non-free programs. These disadvantages 85 | are the reason we use the ordinary General Public License for many 86 | libraries. However, the Lesser license provides advantages in certain 87 | special circumstances. 88 | 89 | For example, on rare occasions, there may be a special need to 90 | encourage the widest possible use of a certain library, so that it becomes 91 | a de-facto standard. To achieve this, non-free programs must be 92 | allowed to use the library. A more frequent case is that a free 93 | library does the same job as widely used non-free libraries. In this 94 | case, there is little to gain by limiting the free library to free 95 | software only, so we use the Lesser General Public License. 96 | 97 | In other cases, permission to use a particular library in non-free 98 | programs enables a greater number of people to use a large body of 99 | free software. For example, permission to use the GNU C Library in 100 | non-free programs enables many more people to use the whole GNU 101 | operating system, as well as its variant, the GNU/Linux operating 102 | system. 103 | 104 | Although the Lesser General Public License is Less protective of the 105 | users' freedom, it does ensure that the user of a program that is 106 | linked with the Library has the freedom and the wherewithal to run 107 | that program using a modified version of the Library. 108 | 109 | The precise terms and conditions for copying, distribution and 110 | modification follow. Pay close attention to the difference between a 111 | "work based on the library" and a "work that uses the library". The 112 | former contains code derived from the library, whereas the latter must 113 | be combined with the library in order to run. 114 | 115 | GNU LESSER GENERAL PUBLIC LICENSE 116 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 117 | 118 | 0. This License Agreement applies to any software library or other 119 | program which contains a notice placed by the copyright holder or 120 | other authorized party saying it may be distributed under the terms of 121 | this Lesser General Public License (also called "this License"). 122 | Each licensee is addressed as "you". 123 | 124 | A "library" means a collection of software functions and/or data 125 | prepared so as to be conveniently linked with application programs 126 | (which use some of those functions and data) to form executables. 127 | 128 | The "Library", below, refers to any such software library or work 129 | which has been distributed under these terms. A "work based on the 130 | Library" means either the Library or any derivative work under 131 | copyright law: that is to say, a work containing the Library or a 132 | portion of it, either verbatim or with modifications and/or translated 133 | straightforwardly into another language. (Hereinafter, translation is 134 | included without limitation in the term "modification".) 135 | 136 | "Source code" for a work means the preferred form of the work for 137 | making modifications to it. For a library, complete source code means 138 | all the source code for all modules it contains, plus any associated 139 | interface definition files, plus the scripts used to control compilation 140 | and installation of the library. 141 | 142 | Activities other than copying, distribution and modification are not 143 | covered by this License; they are outside its scope. The act of 144 | running a program using the Library is not restricted, and output from 145 | such a program is covered only if its contents constitute a work based 146 | on the Library (independent of the use of the Library in a tool for 147 | writing it). Whether that is true depends on what the Library does 148 | and what the program that uses the Library does. 149 | 150 | 1. You may copy and distribute verbatim copies of the Library's 151 | complete source code as you receive it, in any medium, provided that 152 | you conspicuously and appropriately publish on each copy an 153 | appropriate copyright notice and disclaimer of warranty; keep intact 154 | all the notices that refer to this License and to the absence of any 155 | warranty; and distribute a copy of this License along with the 156 | Library. 157 | 158 | You may charge a fee for the physical act of transferring a copy, 159 | and you may at your option offer warranty protection in exchange for a 160 | fee. 161 | 162 | 2. You may modify your copy or copies of the Library or any portion 163 | of it, thus forming a work based on the Library, and copy and 164 | distribute such modifications or work under the terms of Section 1 165 | above, provided that you also meet all of these conditions: 166 | 167 | a) The modified work must itself be a software library. 168 | 169 | b) You must cause the files modified to carry prominent notices 170 | stating that you changed the files and the date of any change. 171 | 172 | c) You must cause the whole of the work to be licensed at no 173 | charge to all third parties under the terms of this License. 174 | 175 | d) If a facility in the modified Library refers to a function or a 176 | table of data to be supplied by an application program that uses 177 | the facility, other than as an argument passed when the facility 178 | is invoked, then you must make a good faith effort to ensure that, 179 | in the event an application does not supply such function or 180 | table, the facility still operates, and performs whatever part of 181 | its purpose remains meaningful. 182 | 183 | (For example, a function in a library to compute square roots has 184 | a purpose that is entirely well-defined independent of the 185 | application. Therefore, Subsection 2d requires that any 186 | application-supplied function or table used by this function must 187 | be optional: if the application does not supply it, the square 188 | root function must still compute square roots.) 189 | 190 | These requirements apply to the modified work as a whole. If 191 | identifiable sections of that work are not derived from the Library, 192 | and can be reasonably considered independent and separate works in 193 | themselves, then this License, and its terms, do not apply to those 194 | sections when you distribute them as separate works. But when you 195 | distribute the same sections as part of a whole which is a work based 196 | on the Library, the distribution of the whole must be on the terms of 197 | this License, whose permissions for other licensees extend to the 198 | entire whole, and thus to each and every part regardless of who wrote 199 | it. 200 | 201 | Thus, it is not the intent of this section to claim rights or contest 202 | your rights to work written entirely by you; rather, the intent is to 203 | exercise the right to control the distribution of derivative or 204 | collective works based on the Library. 205 | 206 | In addition, mere aggregation of another work not based on the Library 207 | with the Library (or with a work based on the Library) on a volume of 208 | a storage or distribution medium does not bring the other work under 209 | the scope of this License. 210 | 211 | 3. You may opt to apply the terms of the ordinary GNU General Public 212 | License instead of this License to a given copy of the Library. To do 213 | this, you must alter all the notices that refer to this License, so 214 | that they refer to the ordinary GNU General Public License, version 2, 215 | instead of to this License. (If a newer version than version 2 of the 216 | ordinary GNU General Public License has appeared, then you can specify 217 | that version instead if you wish.) Do not make any other change in 218 | these notices. 219 | 220 | Once this change is made in a given copy, it is irreversible for 221 | that copy, so the ordinary GNU General Public License applies to all 222 | subsequent copies and derivative works made from that copy. 223 | 224 | This option is useful when you wish to copy part of the code of 225 | the Library into a program that is not a library. 226 | 227 | 4. You may copy and distribute the Library (or a portion or 228 | derivative of it, under Section 2) in object code or executable form 229 | under the terms of Sections 1 and 2 above provided that you accompany 230 | it with the complete corresponding machine-readable source code, which 231 | must be distributed under the terms of Sections 1 and 2 above on a 232 | medium customarily used for software interchange. 233 | 234 | If distribution of object code is made by offering access to copy 235 | from a designated place, then offering equivalent access to copy the 236 | source code from the same place satisfies the requirement to 237 | distribute the source code, even though third parties are not 238 | compelled to copy the source along with the object code. 239 | 240 | 5. A program that contains no derivative of any portion of the 241 | Library, but is designed to work with the Library by being compiled or 242 | linked with it, is called a "work that uses the Library". Such a 243 | work, in isolation, is not a derivative work of the Library, and 244 | therefore falls outside the scope of this License. 245 | 246 | However, linking a "work that uses the Library" with the Library 247 | creates an executable that is a derivative of the Library (because it 248 | contains portions of the Library), rather than a "work that uses the 249 | library". The executable is therefore covered by this License. 250 | Section 6 states terms for distribution of such executables. 251 | 252 | When a "work that uses the Library" uses material from a header file 253 | that is part of the Library, the object code for the work may be a 254 | derivative work of the Library even though the source code is not. 255 | Whether this is true is especially significant if the work can be 256 | linked without the Library, or if the work is itself a library. The 257 | threshold for this to be true is not precisely defined by law. 258 | 259 | If such an object file uses only numerical parameters, data 260 | structure layouts and accessors, and small macros and small inline 261 | functions (ten lines or less in length), then the use of the object 262 | file is unrestricted, regardless of whether it is legally a derivative 263 | work. (Executables containing this object code plus portions of the 264 | Library will still fall under Section 6.) 265 | 266 | Otherwise, if the work is a derivative of the Library, you may 267 | distribute the object code for the work under the terms of Section 6. 268 | Any executables containing that work also fall under Section 6, 269 | whether or not they are linked directly with the Library itself. 270 | 271 | 6. As an exception to the Sections above, you may also combine or 272 | link a "work that uses the Library" with the Library to produce a 273 | work containing portions of the Library, and distribute that work 274 | under terms of your choice, provided that the terms permit 275 | modification of the work for the customer's own use and reverse 276 | engineering for debugging such modifications. 277 | 278 | You must give prominent notice with each copy of the work that the 279 | Library is used in it and that the Library and its use are covered by 280 | this License. You must supply a copy of this License. If the work 281 | during execution displays copyright notices, you must include the 282 | copyright notice for the Library among them, as well as a reference 283 | directing the user to the copy of this License. Also, you must do one 284 | of these things: 285 | 286 | a) Accompany the work with the complete corresponding 287 | machine-readable source code for the Library including whatever 288 | changes were used in the work (which must be distributed under 289 | Sections 1 and 2 above); and, if the work is an executable linked 290 | with the Library, with the complete machine-readable "work that 291 | uses the Library", as object code and/or source code, so that the 292 | user can modify the Library and then relink to produce a modified 293 | executable containing the modified Library. (It is understood 294 | that the user who changes the contents of definitions files in the 295 | Library will not necessarily be able to recompile the application 296 | to use the modified definitions.) 297 | 298 | b) Use a suitable shared library mechanism for linking with the 299 | Library. A suitable mechanism is one that (1) uses at run time a 300 | copy of the library already present on the user's computer system, 301 | rather than copying library functions into the executable, and (2) 302 | will operate properly with a modified version of the library, if 303 | the user installs one, as long as the modified version is 304 | interface-compatible with the version that the work was made with. 305 | 306 | c) Accompany the work with a written offer, valid for at 307 | least three years, to give the same user the materials 308 | specified in Subsection 6a, above, for a charge no more 309 | than the cost of performing this distribution. 310 | 311 | d) If distribution of the work is made by offering access to copy 312 | from a designated place, offer equivalent access to copy the above 313 | specified materials from the same place. 314 | 315 | e) Verify that the user has already received a copy of these 316 | materials or that you have already sent this user a copy. 317 | 318 | For an executable, the required form of the "work that uses the 319 | Library" must include any data and utility programs needed for 320 | reproducing the executable from it. However, as a special exception, 321 | the materials to be distributed need not include anything that is 322 | normally distributed (in either source or binary form) with the major 323 | components (compiler, kernel, and so on) of the operating system on 324 | which the executable runs, unless that component itself accompanies 325 | the executable. 326 | 327 | It may happen that this requirement contradicts the license 328 | restrictions of other proprietary libraries that do not normally 329 | accompany the operating system. Such a contradiction means you cannot 330 | use both them and the Library together in an executable that you 331 | distribute. 332 | 333 | 7. You may place library facilities that are a work based on the 334 | Library side-by-side in a single library together with other library 335 | facilities not covered by this License, and distribute such a combined 336 | library, provided that the separate distribution of the work based on 337 | the Library and of the other library facilities is otherwise 338 | permitted, and provided that you do these two things: 339 | 340 | a) Accompany the combined library with a copy of the same work 341 | based on the Library, uncombined with any other library 342 | facilities. This must be distributed under the terms of the 343 | Sections above. 344 | 345 | b) Give prominent notice with the combined library of the fact 346 | that part of it is a work based on the Library, and explaining 347 | where to find the accompanying uncombined form of the same work. 348 | 349 | 8. You may not copy, modify, sublicense, link with, or distribute 350 | the Library except as expressly provided under this License. Any 351 | attempt otherwise to copy, modify, sublicense, link with, or 352 | distribute the Library is void, and will automatically terminate your 353 | rights under this License. However, parties who have received copies, 354 | or rights, from you under this License will not have their licenses 355 | terminated so long as such parties remain in full compliance. 356 | 357 | 9. You are not required to accept this License, since you have not 358 | signed it. However, nothing else grants you permission to modify or 359 | distribute the Library or its derivative works. These actions are 360 | prohibited by law if you do not accept this License. Therefore, by 361 | modifying or distributing the Library (or any work based on the 362 | Library), you indicate your acceptance of this License to do so, and 363 | all its terms and conditions for copying, distributing or modifying 364 | the Library or works based on it. 365 | 366 | 10. Each time you redistribute the Library (or any work based on the 367 | Library), the recipient automatically receives a license from the 368 | original licensor to copy, distribute, link with or modify the Library 369 | subject to these terms and conditions. You may not impose any further 370 | restrictions on the recipients' exercise of the rights granted herein. 371 | You are not responsible for enforcing compliance by third parties with 372 | this License. 373 | 374 | 11. If, as a consequence of a court judgment or allegation of patent 375 | infringement or for any other reason (not limited to patent issues), 376 | conditions are imposed on you (whether by court order, agreement or 377 | otherwise) that contradict the conditions of this License, they do not 378 | excuse you from the conditions of this License. If you cannot 379 | distribute so as to satisfy simultaneously your obligations under this 380 | License and any other pertinent obligations, then as a consequence you 381 | may not distribute the Library at all. For example, if a patent 382 | license would not permit royalty-free redistribution of the Library by 383 | all those who receive copies directly or indirectly through you, then 384 | the only way you could satisfy both it and this License would be to 385 | refrain entirely from distribution of the Library. 386 | 387 | If any portion of this section is held invalid or unenforceable under any 388 | particular circumstance, the balance of the section is intended to apply, 389 | and the section as a whole is intended to apply in other circumstances. 390 | 391 | It is not the purpose of this section to induce you to infringe any 392 | patents or other property right claims or to contest validity of any 393 | such claims; this section has the sole purpose of protecting the 394 | integrity of the free software distribution system which is 395 | implemented by public license practices. Many people have made 396 | generous contributions to the wide range of software distributed 397 | through that system in reliance on consistent application of that 398 | system; it is up to the author/donor to decide if he or she is willing 399 | to distribute software through any other system and a licensee cannot 400 | impose that choice. 401 | 402 | This section is intended to make thoroughly clear what is believed to 403 | be a consequence of the rest of this License. 404 | 405 | 12. If the distribution and/or use of the Library is restricted in 406 | certain countries either by patents or by copyrighted interfaces, the 407 | original copyright holder who places the Library under this License may add 408 | an explicit geographical distribution limitation excluding those countries, 409 | so that distribution is permitted only in or among countries not thus 410 | excluded. In such case, this License incorporates the limitation as if 411 | written in the body of this License. 412 | 413 | 13. The Free Software Foundation may publish revised and/or new 414 | versions of the Lesser General Public License from time to time. 415 | Such new versions will be similar in spirit to the present version, 416 | but may differ in detail to address new problems or concerns. 417 | 418 | Each version is given a distinguishing version number. If the Library 419 | specifies a version number of this License which applies to it and 420 | "any later version", you have the option of following the terms and 421 | conditions either of that version or of any later version published by 422 | the Free Software Foundation. If the Library does not specify a 423 | license version number, you may choose any version ever published by 424 | the Free Software Foundation. 425 | 426 | 14. If you wish to incorporate parts of the Library into other free 427 | programs whose distribution conditions are incompatible with these, 428 | write to the author to ask for permission. For software which is 429 | copyrighted by the Free Software Foundation, write to the Free 430 | Software Foundation; we sometimes make exceptions for this. Our 431 | decision will be guided by the two goals of preserving the free status 432 | of all derivatives of our free software and of promoting the sharing 433 | and reuse of software generally. 434 | 435 | NO WARRANTY 436 | 437 | 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO 438 | WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. 439 | EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR 440 | OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY 441 | KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE 442 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 443 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE 444 | LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME 445 | THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 446 | 447 | 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN 448 | WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY 449 | AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU 450 | FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR 451 | CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE 452 | LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING 453 | RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A 454 | FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF 455 | SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH 456 | DAMAGES. 457 | 458 | END OF TERMS AND CONDITIONS 459 | 460 | How to Apply These Terms to Your New Libraries 461 | 462 | If you develop a new library, and you want it to be of the greatest 463 | possible use to the public, we recommend making it free software that 464 | everyone can redistribute and change. You can do so by permitting 465 | redistribution under these terms (or, alternatively, under the terms of the 466 | ordinary General Public License). 467 | 468 | To apply these terms, attach the following notices to the library. It is 469 | safest to attach them to the start of each source file to most effectively 470 | convey the exclusion of warranty; and each file should have at least the 471 | "copyright" line and a pointer to where the full notice is found. 472 | 473 | 474 | Copyright (C) 475 | 476 | This library is free software; you can redistribute it and/or 477 | modify it under the terms of the GNU Lesser General Public 478 | License as published by the Free Software Foundation; either 479 | version 2.1 of the License, or (at your option) any later version. 480 | 481 | This library is distributed in the hope that it will be useful, 482 | but WITHOUT ANY WARRANTY; without even the implied warranty of 483 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 484 | Lesser General Public License for more details. 485 | 486 | You should have received a copy of the GNU Lesser General Public 487 | License along with this library; if not, write to the Free Software 488 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 489 | 490 | Also add information on how to contact you by electronic and paper mail. 491 | 492 | You should also get your employer (if you work as a programmer) or your 493 | school, if any, to sign a "copyright disclaimer" for the library, if 494 | necessary. Here is a sample; alter the names: 495 | 496 | Yoyodyne, Inc., hereby disclaims all copyright interest in the 497 | library `Frob' (a library for tweaking knobs) written by James Random Hacker. 498 | 499 | , 1 April 1990 500 | Ty Coon, President of Vice 501 | 502 | That's all there is to it! 503 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2015, NVIDIA CORPORATION. All rights reserved. 2 | # 3 | # This library is free software; you can redistribute it and/or 4 | # modify it under the terms of the GNU Lesser General Public 5 | # License, version 2.1, as published by the Free Software Foundation. 6 | # 7 | # This library is distributed in the hope that it will be useful, 8 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 10 | # Lesser General Public License for more details. 11 | # 12 | # You should have received a copy of the GNU Lesser General Public 13 | # License along with this program. If not, see 14 | # . 15 | 16 | # parser: a simple HEVC elementary stream parser wrapper 17 | CC = gcc 18 | 19 | CFLAGS = \ 20 | -DGST_USE_UNSTABLE_API \ 21 | -Wall \ 22 | -Werror \ 23 | -O0 \ 24 | -ggdb 25 | 26 | INCLUDES = \ 27 | -I /usr/include/gstreamer-0.10 \ 28 | $(shell pkg-config --cflags glib-2.0) \ 29 | -I /usr/include/libxml2 \ 30 | -I vdpau-win-x11 \ 31 | -I /usr/include/X11 32 | 33 | LFLAGS = 34 | 35 | LIBS = \ 36 | -lm \ 37 | $(shell pkg-config --libs glib-2.0) \ 38 | -lvdpau \ 39 | -lX11 40 | 41 | SRCS = \ 42 | nalutils.c \ 43 | gstbitreader.c \ 44 | gstbytereader.c \ 45 | gsth265parser.c \ 46 | vdpau-win-x11/win_x11.c \ 47 | main.c 48 | 49 | OBJS = $(SRCS:.c=.o) 50 | 51 | MAIN = vdpau_hw_hevc 52 | 53 | .PHONY: depend clean 54 | 55 | all: $(MAIN) 56 | @echo parser compiled. 57 | 58 | $(MAIN): $(OBJS) 59 | $(CC) $(CFLAGS) $(INCLUDES) -o $(MAIN) $(OBJS) $(LFLAGS) $(LIBS) 60 | 61 | .c.o: 62 | $(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@ 63 | 64 | clean: 65 | $(RM) *.o *~ $(MAIN) 66 | 67 | depend: $(SRCS) 68 | makedepend $(INCLUDES) $^ 69 | 70 | # DO NOT DELETE THIS LINE -- make depend needs it 71 | 72 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | vdpau_hw_hevc - a sample VDPAU H.265/HEVC video player 2 | José Hiram Soltren 3 | 05 June 2015 4 | 5 | vdpau_hw_hevc demonstrates how to parse an H.265/HEVC elementary bitstream, 6 | store client side state, and hand off frame data to VDPAU for hardware 7 | accelerated decoding. 8 | 9 | The program is designed to demonstrate correct programming of the VDPAU API 10 | for the H.265/HEVC format. It is not a fully featured video player. 11 | 12 | vdpau_hw_hevc utilizes a patched version of gstreamer's H.265/HEVC bitstream 13 | parsing code. In particular, patches are necessary to correctly calculate 14 | the NumShortTermPictureSliceHeaderBits and NumLongTermPictureSliceHeaderBits 15 | fields in VdpPictureInfoHEVC. Please consult the comments in libvdpau's 16 | vdpau.h for additional information. 17 | 18 | DEPENDENCIES 19 | 20 | libvdpau 1.0 or later, available from: 21 | https://wiki.freedesktop.org/www/Software/VDPAU/ 22 | 23 | gstreamer 0.10 or later 24 | 25 | libxml2 26 | 27 | X11 development files 28 | 29 | This package contains code from the gstreamer project. These files are 30 | identical to the correspinding files in gstreamer commit 31 | d99e621533b73a6839de0faa991737b7e84676f2: 32 | 33 | gstbitreader.c gstbytereader.c 34 | gstbitreader.h gstbytereader.h 35 | 36 | These files are derived from the corresponding files in gst-plugins-bad 37 | commit 7eef9dd0adb1daaada97490bc01c6b05ba973315: 38 | 39 | gsth265parser.c gsth265parser.h 40 | nalutils.c nalutils.h 41 | 42 | BUILDING 43 | 44 | Typing "make" in this directory should generate the vdpau_hw_hevc binary. 45 | 46 | RUNNING 47 | 48 | To run, do: 49 | 50 | $ ./vdpau_hw_hevc path/to/stream.bin 51 | 52 | Sample content is available from multiple sources, such as: 53 | 54 | http://fate-suite.ffmpeg.org/hevc-conformance/ 55 | 56 | OPTIONS 57 | 58 | vdpau_hw_hevc has a number of options. See the arguments to main() in main.c 59 | for a complete list of features. 60 | 61 | Without any additional arguments, vdpau_hw_hevc will open a bitstream, 62 | play it once in decode order, and exit. 63 | 64 | KNOWN ISSUES 65 | 66 | The call to VdpDecoderCreate will fail at run time, unless vdpau_hw_hevc is 67 | executed on a system that offers both libvdpau 1.0 or later and a VDPAU 68 | implementation supporting H.265/HEVC playback. 69 | 70 | KNOWN LIMITATIONS 71 | 72 | vdpau_hw_hevc will only play H.265/HEVC elementary streams using the bitstream 73 | format described in the H.265/HEVC specification. Any other formats must be 74 | demuxed externally prior to attempting playback with vdpau_hw_hevc. 75 | 76 | As it does not contain a demuxer, vdpau_hw_hevc has no facilities for audio 77 | playback. 78 | 79 | Seeking is not supported. 80 | 81 | vdpau_hw_hevc will only play streams in decode, not display, order as of this 82 | writing. A correct video player must present frames in display order. 83 | 84 | -------------------------------------------------------------------------------- /gstbitreader.c: -------------------------------------------------------------------------------- 1 | /* GStreamer 2 | * 3 | * Copyright (C) 2008 Sebastian Dröge . 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License, version 2.1, as published by the Free Software Foundation. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this program. If not, see 16 | * . 17 | */ 18 | 19 | #ifdef HAVE_CONFIG_H 20 | #include "config.h" 21 | #endif 22 | 23 | #define GST_BIT_READER_DISABLE_INLINES 24 | #include "gstbitreader.h" 25 | 26 | #include 27 | 28 | /** 29 | * SECTION:gstbitreader 30 | * @short_description: Reads any number of bits from a memory buffer 31 | * 32 | * #GstBitReader provides a bit reader that can read any number of bits 33 | * from a memory buffer. It provides functions for reading any number of bits 34 | * into 8, 16, 32 and 64 bit variables. 35 | */ 36 | 37 | /** 38 | * gst_bit_reader_new: 39 | * @data: (array length=size): Data from which the #GstBitReader 40 | * should read 41 | * @size: Size of @data in bytes 42 | * 43 | * Create a new #GstBitReader instance, which will read from @data. 44 | * 45 | * Free-function: gst_bit_reader_free 46 | * 47 | * Returns: (transfer full): a new #GstBitReader instance 48 | */ 49 | GstBitReader * 50 | gst_bit_reader_new (const guint8 * data, guint size) 51 | { 52 | GstBitReader *ret = g_slice_new0 (GstBitReader); 53 | 54 | ret->data = data; 55 | ret->size = size; 56 | 57 | return ret; 58 | } 59 | 60 | /** 61 | * gst_bit_reader_free: 62 | * @reader: (in) (transfer full): a #GstBitReader instance 63 | * 64 | * Frees a #GstBitReader instance, which was previously allocated by 65 | * gst_bit_reader_new(). 66 | */ 67 | void 68 | gst_bit_reader_free (GstBitReader * reader) 69 | { 70 | g_return_if_fail (reader != NULL); 71 | 72 | g_slice_free (GstBitReader, reader); 73 | } 74 | 75 | /** 76 | * gst_bit_reader_init: 77 | * @reader: a #GstBitReader instance 78 | * @data: (in) (array length=size): data from which the bit reader should read 79 | * @size: Size of @data in bytes 80 | * 81 | * Initializes a #GstBitReader instance to read from @data. This function 82 | * can be called on already initialized instances. 83 | */ 84 | void 85 | gst_bit_reader_init (GstBitReader * reader, const guint8 * data, guint size) 86 | { 87 | g_return_if_fail (reader != NULL); 88 | 89 | reader->data = data; 90 | reader->size = size; 91 | reader->byte = reader->bit = 0; 92 | } 93 | 94 | /** 95 | * gst_bit_reader_set_pos: 96 | * @reader: a #GstBitReader instance 97 | * @pos: The new position in bits 98 | * 99 | * Sets the new position of a #GstBitReader instance to @pos in bits. 100 | * 101 | * Returns: %TRUE if the position could be set successfully, %FALSE 102 | * otherwise. 103 | */ 104 | gboolean 105 | gst_bit_reader_set_pos (GstBitReader * reader, guint pos) 106 | { 107 | g_return_val_if_fail (reader != NULL, FALSE); 108 | 109 | if (pos > reader->size * 8) 110 | return FALSE; 111 | 112 | reader->byte = pos / 8; 113 | reader->bit = pos % 8; 114 | 115 | return TRUE; 116 | } 117 | 118 | /** 119 | * gst_bit_reader_get_pos: 120 | * @reader: a #GstBitReader instance 121 | * 122 | * Returns the current position of a #GstBitReader instance in bits. 123 | * 124 | * Returns: The current position of @reader in bits. 125 | */ 126 | guint 127 | gst_bit_reader_get_pos (const GstBitReader * reader) 128 | { 129 | return _gst_bit_reader_get_pos_inline (reader); 130 | } 131 | 132 | /** 133 | * gst_bit_reader_get_remaining: 134 | * @reader: a #GstBitReader instance 135 | * 136 | * Returns the remaining number of bits of a #GstBitReader instance. 137 | * 138 | * Returns: The remaining number of bits of @reader instance. 139 | */ 140 | guint 141 | gst_bit_reader_get_remaining (const GstBitReader * reader) 142 | { 143 | return _gst_bit_reader_get_remaining_inline (reader); 144 | } 145 | 146 | /** 147 | * gst_bit_reader_get_size: 148 | * @reader: a #GstBitReader instance 149 | * 150 | * Returns the total number of bits of a #GstBitReader instance. 151 | * 152 | * Returns: The total number of bits of @reader instance. 153 | */ 154 | guint 155 | gst_bit_reader_get_size (const GstBitReader * reader) 156 | { 157 | return _gst_bit_reader_get_size_inline (reader); 158 | } 159 | 160 | /** 161 | * gst_bit_reader_skip: 162 | * @reader: a #GstBitReader instance 163 | * @nbits: the number of bits to skip 164 | * 165 | * Skips @nbits bits of the #GstBitReader instance. 166 | * 167 | * Returns: %TRUE if @nbits bits could be skipped, %FALSE otherwise. 168 | */ 169 | gboolean 170 | gst_bit_reader_skip (GstBitReader * reader, guint nbits) 171 | { 172 | return _gst_bit_reader_skip_inline (reader, nbits); 173 | } 174 | 175 | /** 176 | * gst_bit_reader_skip_to_byte: 177 | * @reader: a #GstBitReader instance 178 | * 179 | * Skips until the next byte. 180 | * 181 | * Returns: %TRUE if successful, %FALSE otherwise. 182 | */ 183 | gboolean 184 | gst_bit_reader_skip_to_byte (GstBitReader * reader) 185 | { 186 | return _gst_bit_reader_skip_to_byte_inline (reader); 187 | } 188 | 189 | /** 190 | * gst_bit_reader_get_bits_uint8: 191 | * @reader: a #GstBitReader instance 192 | * @val: (out): Pointer to a #guint8 to store the result 193 | * @nbits: number of bits to read 194 | * 195 | * Read @nbits bits into @val and update the current position. 196 | * 197 | * Returns: %TRUE if successful, %FALSE otherwise. 198 | */ 199 | 200 | /** 201 | * gst_bit_reader_get_bits_uint16: 202 | * @reader: a #GstBitReader instance 203 | * @val: (out): Pointer to a #guint16 to store the result 204 | * @nbits: number of bits to read 205 | * 206 | * Read @nbits bits into @val and update the current position. 207 | * 208 | * Returns: %TRUE if successful, %FALSE otherwise. 209 | */ 210 | 211 | /** 212 | * gst_bit_reader_get_bits_uint32: 213 | * @reader: a #GstBitReader instance 214 | * @val: (out): Pointer to a #guint32 to store the result 215 | * @nbits: number of bits to read 216 | * 217 | * Read @nbits bits into @val and update the current position. 218 | * 219 | * Returns: %TRUE if successful, %FALSE otherwise. 220 | */ 221 | 222 | /** 223 | * gst_bit_reader_get_bits_uint64: 224 | * @reader: a #GstBitReader instance 225 | * @val: (out): Pointer to a #guint64 to store the result 226 | * @nbits: number of bits to read 227 | * 228 | * Read @nbits bits into @val and update the current position. 229 | * 230 | * Returns: %TRUE if successful, %FALSE otherwise. 231 | */ 232 | 233 | /** 234 | * gst_bit_reader_peek_bits_uint8: 235 | * @reader: a #GstBitReader instance 236 | * @val: (out): Pointer to a #guint8 to store the result 237 | * @nbits: number of bits to read 238 | * 239 | * Read @nbits bits into @val but keep the current position. 240 | * 241 | * Returns: %TRUE if successful, %FALSE otherwise. 242 | */ 243 | 244 | /** 245 | * gst_bit_reader_peek_bits_uint16: 246 | * @reader: a #GstBitReader instance 247 | * @val: (out): Pointer to a #guint16 to store the result 248 | * @nbits: number of bits to read 249 | * 250 | * Read @nbits bits into @val but keep the current position. 251 | * 252 | * Returns: %TRUE if successful, %FALSE otherwise. 253 | */ 254 | 255 | /** 256 | * gst_bit_reader_peek_bits_uint32: 257 | * @reader: a #GstBitReader instance 258 | * @val: (out): Pointer to a #guint32 to store the result 259 | * @nbits: number of bits to read 260 | * 261 | * Read @nbits bits into @val but keep the current position. 262 | * 263 | * Returns: %TRUE if successful, %FALSE otherwise. 264 | */ 265 | 266 | /** 267 | * gst_bit_reader_peek_bits_uint64: 268 | * @reader: a #GstBitReader instance 269 | * @val: (out): Pointer to a #guint64 to store the result 270 | * @nbits: number of bits to read 271 | * 272 | * Read @nbits bits into @val but keep the current position. 273 | * 274 | * Returns: %TRUE if successful, %FALSE otherwise. 275 | */ 276 | 277 | #define GST_BIT_READER_READ_BITS(bits) \ 278 | gboolean \ 279 | gst_bit_reader_peek_bits_uint##bits (const GstBitReader *reader, guint##bits *val, guint nbits) \ 280 | { \ 281 | return _gst_bit_reader_peek_bits_uint##bits##_inline (reader, val, nbits); \ 282 | } \ 283 | \ 284 | gboolean \ 285 | gst_bit_reader_get_bits_uint##bits (GstBitReader *reader, guint##bits *val, guint nbits) \ 286 | { \ 287 | return _gst_bit_reader_get_bits_uint##bits##_inline (reader, val, nbits); \ 288 | } 289 | 290 | GST_BIT_READER_READ_BITS (8); 291 | GST_BIT_READER_READ_BITS (16); 292 | GST_BIT_READER_READ_BITS (32); 293 | GST_BIT_READER_READ_BITS (64); 294 | -------------------------------------------------------------------------------- /gstbitreader.h: -------------------------------------------------------------------------------- 1 | /* GStreamer 2 | * 3 | * Copyright (C) 2008 Sebastian Dröge . 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License, version 2.1, as published by the Free Software Foundation. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this program. If not, see 16 | * . 17 | */ 18 | 19 | #ifndef __GST_BIT_READER_H__ 20 | #define __GST_BIT_READER_H__ 21 | 22 | #include 23 | 24 | /* FIXME: inline functions */ 25 | 26 | G_BEGIN_DECLS 27 | 28 | #define GST_BIT_READER(reader) ((GstBitReader *) (reader)) 29 | 30 | /** 31 | * GstBitReader: 32 | * @data: (array length=size): Data from which the bit reader will 33 | * read 34 | * @size: Size of @data in bytes 35 | * @byte: Current byte position 36 | * @bit: Bit position in the current byte 37 | * 38 | * A bit reader instance. 39 | */ 40 | typedef struct { 41 | const guint8 *data; 42 | guint size; 43 | 44 | guint byte; /* Byte position */ 45 | guint bit; /* Bit position in the current byte */ 46 | 47 | /* < private > */ 48 | gpointer _gst_reserved[GST_PADDING]; 49 | } GstBitReader; 50 | 51 | GstBitReader * gst_bit_reader_new (const guint8 *data, guint size) G_GNUC_MALLOC; 52 | void gst_bit_reader_free (GstBitReader *reader); 53 | 54 | void gst_bit_reader_init (GstBitReader *reader, const guint8 *data, guint size); 55 | 56 | gboolean gst_bit_reader_set_pos (GstBitReader *reader, guint pos); 57 | guint gst_bit_reader_get_pos (const GstBitReader *reader); 58 | 59 | guint gst_bit_reader_get_remaining (const GstBitReader *reader); 60 | 61 | guint gst_bit_reader_get_size (const GstBitReader *reader); 62 | 63 | gboolean gst_bit_reader_skip (GstBitReader *reader, guint nbits); 64 | gboolean gst_bit_reader_skip_to_byte (GstBitReader *reader); 65 | 66 | gboolean gst_bit_reader_get_bits_uint8 (GstBitReader *reader, guint8 *val, guint nbits); 67 | gboolean gst_bit_reader_get_bits_uint16 (GstBitReader *reader, guint16 *val, guint nbits); 68 | gboolean gst_bit_reader_get_bits_uint32 (GstBitReader *reader, guint32 *val, guint nbits); 69 | gboolean gst_bit_reader_get_bits_uint64 (GstBitReader *reader, guint64 *val, guint nbits); 70 | 71 | gboolean gst_bit_reader_peek_bits_uint8 (const GstBitReader *reader, guint8 *val, guint nbits); 72 | gboolean gst_bit_reader_peek_bits_uint16 (const GstBitReader *reader, guint16 *val, guint nbits); 73 | gboolean gst_bit_reader_peek_bits_uint32 (const GstBitReader *reader, guint32 *val, guint nbits); 74 | gboolean gst_bit_reader_peek_bits_uint64 (const GstBitReader *reader, guint64 *val, guint nbits); 75 | 76 | /** 77 | * GST_BIT_READER_INIT: 78 | * @data: Data from which the #GstBitReader should read 79 | * @size: Size of @data in bytes 80 | * 81 | * A #GstBitReader must be initialized with this macro, before it can be 82 | * used. This macro can used be to initialize a variable, but it cannot 83 | * be assigned to a variable. In that case you have to use 84 | * gst_bit_reader_init(). 85 | */ 86 | #define GST_BIT_READER_INIT(data, size) {data, size, 0, 0} 87 | 88 | /* Unchecked variants */ 89 | 90 | static inline void 91 | gst_bit_reader_skip_unchecked (GstBitReader * reader, guint nbits) 92 | { 93 | reader->bit += nbits; 94 | reader->byte += reader->bit / 8; 95 | reader->bit = reader->bit % 8; 96 | } 97 | 98 | static inline void 99 | gst_bit_reader_skip_to_byte_unchecked (GstBitReader * reader) 100 | { 101 | if (reader->bit) { 102 | reader->bit = 0; 103 | reader->byte++; 104 | } 105 | } 106 | 107 | #define __GST_BIT_READER_READ_BITS_UNCHECKED(bits) \ 108 | static inline guint##bits \ 109 | gst_bit_reader_peek_bits_uint##bits##_unchecked (const GstBitReader *reader, guint nbits) \ 110 | { \ 111 | guint##bits ret = 0; \ 112 | const guint8 *data; \ 113 | guint byte, bit; \ 114 | \ 115 | data = reader->data; \ 116 | byte = reader->byte; \ 117 | bit = reader->bit; \ 118 | \ 119 | while (nbits > 0) { \ 120 | guint toread = MIN (nbits, 8 - bit); \ 121 | \ 122 | ret <<= toread; \ 123 | ret |= (data[byte] & (0xff >> bit)) >> (8 - toread - bit); \ 124 | \ 125 | bit += toread; \ 126 | if (bit >= 8) { \ 127 | byte++; \ 128 | bit = 0; \ 129 | } \ 130 | nbits -= toread; \ 131 | } \ 132 | \ 133 | return ret; \ 134 | } \ 135 | \ 136 | static inline guint##bits \ 137 | gst_bit_reader_get_bits_uint##bits##_unchecked (GstBitReader *reader, guint nbits) \ 138 | { \ 139 | guint##bits ret; \ 140 | \ 141 | ret = gst_bit_reader_peek_bits_uint##bits##_unchecked (reader, nbits); \ 142 | \ 143 | gst_bit_reader_skip_unchecked (reader, nbits); \ 144 | \ 145 | return ret; \ 146 | } 147 | 148 | __GST_BIT_READER_READ_BITS_UNCHECKED (8) 149 | __GST_BIT_READER_READ_BITS_UNCHECKED (16) 150 | __GST_BIT_READER_READ_BITS_UNCHECKED (32) 151 | __GST_BIT_READER_READ_BITS_UNCHECKED (64) 152 | 153 | #undef __GST_BIT_READER_READ_BITS_UNCHECKED 154 | 155 | /* unchecked variants -- do not use */ 156 | 157 | static inline guint 158 | _gst_bit_reader_get_size_unchecked (const GstBitReader * reader) 159 | { 160 | return reader->size * 8; 161 | } 162 | 163 | static inline guint 164 | _gst_bit_reader_get_pos_unchecked (const GstBitReader * reader) 165 | { 166 | return reader->byte * 8 + reader->bit; 167 | } 168 | 169 | static inline guint 170 | _gst_bit_reader_get_remaining_unchecked (const GstBitReader * reader) 171 | { 172 | return reader->size * 8 - (reader->byte * 8 + reader->bit); 173 | } 174 | 175 | /* inlined variants -- do not use directly */ 176 | static inline guint 177 | _gst_bit_reader_get_size_inline (const GstBitReader * reader) 178 | { 179 | g_return_val_if_fail (reader != NULL, 0); 180 | 181 | return _gst_bit_reader_get_size_unchecked (reader); 182 | } 183 | 184 | static inline guint 185 | _gst_bit_reader_get_pos_inline (const GstBitReader * reader) 186 | { 187 | g_return_val_if_fail (reader != NULL, 0); 188 | 189 | return _gst_bit_reader_get_pos_unchecked (reader); 190 | } 191 | 192 | static inline guint 193 | _gst_bit_reader_get_remaining_inline (const GstBitReader * reader) 194 | { 195 | g_return_val_if_fail (reader != NULL, 0); 196 | 197 | return _gst_bit_reader_get_remaining_unchecked (reader); 198 | } 199 | 200 | static inline gboolean 201 | _gst_bit_reader_skip_inline (GstBitReader * reader, guint nbits) 202 | { 203 | g_return_val_if_fail (reader != NULL, FALSE); 204 | 205 | if (_gst_bit_reader_get_remaining_unchecked (reader) < nbits) 206 | return FALSE; 207 | 208 | gst_bit_reader_skip_unchecked (reader, nbits); 209 | 210 | return TRUE; 211 | } 212 | 213 | static inline gboolean 214 | _gst_bit_reader_skip_to_byte_inline (GstBitReader * reader) 215 | { 216 | g_return_val_if_fail (reader != NULL, FALSE); 217 | 218 | if (reader->byte > reader->size) 219 | return FALSE; 220 | 221 | gst_bit_reader_skip_to_byte_unchecked (reader); 222 | 223 | return TRUE; 224 | } 225 | 226 | #define __GST_BIT_READER_READ_BITS_INLINE(bits) \ 227 | static inline gboolean \ 228 | _gst_bit_reader_get_bits_uint##bits##_inline (GstBitReader *reader, guint##bits *val, guint nbits) \ 229 | { \ 230 | g_return_val_if_fail (reader != NULL, FALSE); \ 231 | g_return_val_if_fail (val != NULL, FALSE); \ 232 | g_return_val_if_fail (nbits <= bits, FALSE); \ 233 | \ 234 | if (_gst_bit_reader_get_remaining_unchecked (reader) < nbits) \ 235 | return FALSE; \ 236 | \ 237 | *val = gst_bit_reader_get_bits_uint##bits##_unchecked (reader, nbits); \ 238 | return TRUE; \ 239 | } \ 240 | \ 241 | static inline gboolean \ 242 | _gst_bit_reader_peek_bits_uint##bits##_inline (const GstBitReader *reader, guint##bits *val, guint nbits) \ 243 | { \ 244 | g_return_val_if_fail (reader != NULL, FALSE); \ 245 | g_return_val_if_fail (val != NULL, FALSE); \ 246 | g_return_val_if_fail (nbits <= bits, FALSE); \ 247 | \ 248 | if (_gst_bit_reader_get_remaining_unchecked (reader) < nbits) \ 249 | return FALSE; \ 250 | \ 251 | *val = gst_bit_reader_peek_bits_uint##bits##_unchecked (reader, nbits); \ 252 | return TRUE; \ 253 | } 254 | 255 | __GST_BIT_READER_READ_BITS_INLINE (8) 256 | __GST_BIT_READER_READ_BITS_INLINE (16) 257 | __GST_BIT_READER_READ_BITS_INLINE (32) 258 | __GST_BIT_READER_READ_BITS_INLINE (64) 259 | 260 | #undef __GST_BIT_READER_READ_BITS_INLINE 261 | 262 | #ifndef GST_BIT_READER_DISABLE_INLINES 263 | 264 | #define gst_bit_reader_get_size(reader) \ 265 | _gst_bit_reader_get_size_inline (reader) 266 | #define gst_bit_reader_get_pos(reader) \ 267 | _gst_bit_reader_get_pos_inline (reader) 268 | #define gst_bit_reader_get_remaining(reader) \ 269 | _gst_bit_reader_get_remaining_inline (reader) 270 | 271 | /* we use defines here so we can add the G_LIKELY() */ 272 | 273 | #define gst_bit_reader_skip(reader, nbits)\ 274 | G_LIKELY (_gst_bit_reader_skip_inline(reader, nbits)) 275 | #define gst_bit_reader_skip_to_byte(reader)\ 276 | G_LIKELY (_gst_bit_reader_skip_to_byte_inline(reader)) 277 | 278 | #define gst_bit_reader_get_bits_uint8(reader, val, nbits) \ 279 | G_LIKELY (_gst_bit_reader_get_bits_uint8_inline (reader, val, nbits)) 280 | #define gst_bit_reader_get_bits_uint16(reader, val, nbits) \ 281 | G_LIKELY (_gst_bit_reader_get_bits_uint16_inline (reader, val, nbits)) 282 | #define gst_bit_reader_get_bits_uint32(reader, val, nbits) \ 283 | G_LIKELY (_gst_bit_reader_get_bits_uint32_inline (reader, val, nbits)) 284 | #define gst_bit_reader_get_bits_uint64(reader, val, nbits) \ 285 | G_LIKELY (_gst_bit_reader_get_bits_uint64_inline (reader, val, nbits)) 286 | 287 | #define gst_bit_reader_peek_bits_uint8(reader, val, nbits) \ 288 | G_LIKELY (_gst_bit_reader_peek_bits_uint8_inline (reader, val, nbits)) 289 | #define gst_bit_reader_peek_bits_uint16(reader, val, nbits) \ 290 | G_LIKELY (_gst_bit_reader_peek_bits_uint16_inline (reader, val, nbits)) 291 | #define gst_bit_reader_peek_bits_uint32(reader, val, nbits) \ 292 | G_LIKELY (_gst_bit_reader_peek_bits_uint32_inline (reader, val, nbits)) 293 | #define gst_bit_reader_peek_bits_uint64(reader, val, nbits) \ 294 | G_LIKELY (_gst_bit_reader_peek_bits_uint64_inline (reader, val, nbits)) 295 | #endif 296 | 297 | G_END_DECLS 298 | 299 | #endif /* __GST_BIT_READER_H__ */ 300 | -------------------------------------------------------------------------------- /gstbytereader.c: -------------------------------------------------------------------------------- 1 | /* GStreamer byte reader 2 | * 3 | * Copyright (C) 2008 Sebastian Dröge . 4 | * Copyright (C) 2009 Tim-Philipp Müller 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License, version 2.1, as published by the Free Software Foundation. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this program. If not, see 17 | * . 18 | */ 19 | 20 | #ifdef HAVE_CONFIG_H 21 | #include "config.h" 22 | #endif 23 | 24 | #define GST_BYTE_READER_DISABLE_INLINES 25 | #include "gstbytereader.h" 26 | 27 | #include 28 | 29 | /** 30 | * SECTION:gstbytereader 31 | * @short_description: Reads different integer, string and floating point 32 | * types from a memory buffer 33 | * 34 | * #GstByteReader provides a byte reader that can read different integer and 35 | * floating point types from a memory buffer. It provides functions for reading 36 | * signed/unsigned, little/big endian integers of 8, 16, 24, 32 and 64 bits 37 | * and functions for reading little/big endian floating points numbers of 38 | * 32 and 64 bits. It also provides functions to read NUL-terminated strings 39 | * in various character encodings. 40 | */ 41 | 42 | /** 43 | * gst_byte_reader_new: 44 | * @data: (in) (transfer none) (array length=size): data from which the 45 | * #GstByteReader should read 46 | * @size: Size of @data in bytes 47 | * 48 | * Create a new #GstByteReader instance, which will read from @data. 49 | * 50 | * Free-function: gst_byte_reader_free 51 | * 52 | * Returns: (transfer full): a new #GstByteReader instance 53 | */ 54 | GstByteReader * 55 | gst_byte_reader_new (const guint8 * data, guint size) 56 | { 57 | GstByteReader *ret = g_slice_new0 (GstByteReader); 58 | 59 | ret->data = data; 60 | ret->size = size; 61 | 62 | return ret; 63 | } 64 | 65 | /** 66 | * gst_byte_reader_free: 67 | * @reader: (in) (transfer full): a #GstByteReader instance 68 | * 69 | * Frees a #GstByteReader instance, which was previously allocated by 70 | * gst_byte_reader_new(). 71 | */ 72 | void 73 | gst_byte_reader_free (GstByteReader * reader) 74 | { 75 | g_return_if_fail (reader != NULL); 76 | 77 | g_slice_free (GstByteReader, reader); 78 | } 79 | 80 | /** 81 | * gst_byte_reader_init: 82 | * @reader: a #GstByteReader instance 83 | * @data: (in) (transfer none) (array length=size): data from which 84 | * the #GstByteReader should read 85 | * @size: Size of @data in bytes 86 | * 87 | * Initializes a #GstByteReader instance to read from @data. This function 88 | * can be called on already initialized instances. 89 | */ 90 | void 91 | gst_byte_reader_init (GstByteReader * reader, const guint8 * data, guint size) 92 | { 93 | g_return_if_fail (reader != NULL); 94 | 95 | reader->data = data; 96 | reader->size = size; 97 | reader->byte = 0; 98 | } 99 | 100 | /** 101 | * gst_byte_reader_set_pos: 102 | * @reader: a #GstByteReader instance 103 | * @pos: The new position in bytes 104 | * 105 | * Sets the new position of a #GstByteReader instance to @pos in bytes. 106 | * 107 | * Returns: %TRUE if the position could be set successfully, %FALSE 108 | * otherwise. 109 | */ 110 | gboolean 111 | gst_byte_reader_set_pos (GstByteReader * reader, guint pos) 112 | { 113 | g_return_val_if_fail (reader != NULL, FALSE); 114 | 115 | if (pos > reader->size) 116 | return FALSE; 117 | 118 | reader->byte = pos; 119 | 120 | return TRUE; 121 | } 122 | 123 | /** 124 | * gst_byte_reader_get_pos: 125 | * @reader: a #GstByteReader instance 126 | * 127 | * Returns the current position of a #GstByteReader instance in bytes. 128 | * 129 | * Returns: The current position of @reader in bytes. 130 | */ 131 | guint 132 | gst_byte_reader_get_pos (const GstByteReader * reader) 133 | { 134 | return _gst_byte_reader_get_pos_inline (reader); 135 | } 136 | 137 | /** 138 | * gst_byte_reader_get_remaining: 139 | * @reader: a #GstByteReader instance 140 | * 141 | * Returns the remaining number of bytes of a #GstByteReader instance. 142 | * 143 | * Returns: The remaining number of bytes of @reader instance. 144 | */ 145 | guint 146 | gst_byte_reader_get_remaining (const GstByteReader * reader) 147 | { 148 | return _gst_byte_reader_get_remaining_inline (reader); 149 | } 150 | 151 | /** 152 | * gst_byte_reader_get_size: 153 | * @reader: a #GstByteReader instance 154 | * 155 | * Returns the total number of bytes of a #GstByteReader instance. 156 | * 157 | * Returns: The total number of bytes of @reader instance. 158 | */ 159 | guint 160 | gst_byte_reader_get_size (const GstByteReader * reader) 161 | { 162 | return _gst_byte_reader_get_size_inline (reader); 163 | } 164 | 165 | #define gst_byte_reader_get_remaining _gst_byte_reader_get_remaining_inline 166 | #define gst_byte_reader_get_size _gst_byte_reader_get_size_inline 167 | 168 | /** 169 | * gst_byte_reader_skip: 170 | * @reader: a #GstByteReader instance 171 | * @nbytes: the number of bytes to skip 172 | * 173 | * Skips @nbytes bytes of the #GstByteReader instance. 174 | * 175 | * Returns: %TRUE if @nbytes bytes could be skipped, %FALSE otherwise. 176 | */ 177 | gboolean 178 | gst_byte_reader_skip (GstByteReader * reader, guint nbytes) 179 | { 180 | return _gst_byte_reader_skip_inline (reader, nbytes); 181 | } 182 | 183 | /** 184 | * gst_byte_reader_get_uint8: 185 | * @reader: a #GstByteReader instance 186 | * @val: (out): Pointer to a #guint8 to store the result 187 | * 188 | * Read an unsigned 8 bit integer into @val and update the current position. 189 | * 190 | * Returns: %TRUE if successful, %FALSE otherwise. 191 | */ 192 | 193 | /** 194 | * gst_byte_reader_get_int8: 195 | * @reader: a #GstByteReader instance 196 | * @val: (out): Pointer to a #gint8 to store the result 197 | * 198 | * Read a signed 8 bit integer into @val and update the current position. 199 | * 200 | * Returns: %TRUE if successful, %FALSE otherwise. 201 | */ 202 | 203 | /** 204 | * gst_byte_reader_peek_uint8: 205 | * @reader: a #GstByteReader instance 206 | * @val: (out): Pointer to a #guint8 to store the result 207 | * 208 | * Read an unsigned 8 bit integer into @val but keep the current position. 209 | * 210 | * Returns: %TRUE if successful, %FALSE otherwise. 211 | */ 212 | 213 | /** 214 | * gst_byte_reader_peek_int8: 215 | * @reader: a #GstByteReader instance 216 | * @val: (out): Pointer to a #gint8 to store the result 217 | * 218 | * Read a signed 8 bit integer into @val but keep the current position. 219 | * 220 | * Returns: %TRUE if successful, %FALSE otherwise. 221 | */ 222 | 223 | /** 224 | * gst_byte_reader_get_uint16_le: 225 | * @reader: a #GstByteReader instance 226 | * @val: (out): Pointer to a #guint16 to store the result 227 | * 228 | * Read an unsigned 16 bit little endian integer into @val 229 | * and update the current position. 230 | * 231 | * Returns: %TRUE if successful, %FALSE otherwise. 232 | */ 233 | 234 | /** 235 | * gst_byte_reader_get_int16_le: 236 | * @reader: a #GstByteReader instance 237 | * @val: (out): Pointer to a #gint16 to store the result 238 | * 239 | * Read a signed 16 bit little endian integer into @val 240 | * and update the current position. 241 | * 242 | * Returns: %TRUE if successful, %FALSE otherwise. 243 | */ 244 | 245 | /** 246 | * gst_byte_reader_peek_uint16_le: 247 | * @reader: a #GstByteReader instance 248 | * @val: (out): Pointer to a #guint16 to store the result 249 | * 250 | * Read an unsigned 16 bit little endian integer into @val 251 | * but keep the current position. 252 | * 253 | * Returns: %TRUE if successful, %FALSE otherwise. 254 | */ 255 | 256 | /** 257 | * gst_byte_reader_peek_int16_le: 258 | * @reader: a #GstByteReader instance 259 | * @val: (out): Pointer to a #gint16 to store the result 260 | * 261 | * Read a signed 16 bit little endian integer into @val 262 | * but keep the current position. 263 | * 264 | * Returns: %TRUE if successful, %FALSE otherwise. 265 | */ 266 | 267 | /** 268 | * gst_byte_reader_get_uint16_be: 269 | * @reader: a #GstByteReader instance 270 | * @val: (out): Pointer to a #guint16 to store the result 271 | * 272 | * Read an unsigned 16 bit big endian integer into @val 273 | * and update the current position. 274 | * 275 | * Returns: %TRUE if successful, %FALSE otherwise. 276 | */ 277 | 278 | /** 279 | * gst_byte_reader_get_int16_be: 280 | * @reader: a #GstByteReader instance 281 | * @val: (out): Pointer to a #gint16 to store the result 282 | * 283 | * Read a signed 16 bit big endian integer into @val 284 | * and update the current position. 285 | * 286 | * Returns: %TRUE if successful, %FALSE otherwise. 287 | */ 288 | 289 | /** 290 | * gst_byte_reader_peek_uint16_be: 291 | * @reader: a #GstByteReader instance 292 | * @val: (out): Pointer to a #guint16 to store the result 293 | * 294 | * Read an unsigned 16 bit big endian integer into @val 295 | * but keep the current position. 296 | * 297 | * Returns: %TRUE if successful, %FALSE otherwise. 298 | */ 299 | 300 | /** 301 | * gst_byte_reader_peek_int16_be: 302 | * @reader: a #GstByteReader instance 303 | * @val: (out): Pointer to a #gint16 to store the result 304 | * 305 | * Read a signed 16 bit big endian integer into @val 306 | * but keep the current position. 307 | * 308 | * Returns: %TRUE if successful, %FALSE otherwise. 309 | */ 310 | 311 | /** 312 | * gst_byte_reader_get_uint24_le: 313 | * @reader: a #GstByteReader instance 314 | * @val: (out): Pointer to a #guint32 to store the result 315 | * 316 | * Read an unsigned 24 bit little endian integer into @val 317 | * and update the current position. 318 | * 319 | * Returns: %TRUE if successful, %FALSE otherwise. 320 | */ 321 | 322 | /** 323 | * gst_byte_reader_get_int24_le: 324 | * @reader: a #GstByteReader instance 325 | * @val: (out): Pointer to a #gint32 to store the result 326 | * 327 | * Read a signed 24 bit little endian integer into @val 328 | * and update the current position. 329 | * 330 | * Returns: %TRUE if successful, %FALSE otherwise. 331 | */ 332 | 333 | /** 334 | * gst_byte_reader_peek_uint24_le: 335 | * @reader: a #GstByteReader instance 336 | * @val: (out): Pointer to a #guint32 to store the result 337 | * 338 | * Read an unsigned 24 bit little endian integer into @val 339 | * but keep the current position. 340 | * 341 | * Returns: %TRUE if successful, %FALSE otherwise. 342 | */ 343 | 344 | /** 345 | * gst_byte_reader_peek_int24_le: 346 | * @reader: a #GstByteReader instance 347 | * @val: (out): Pointer to a #gint32 to store the result 348 | * 349 | * Read a signed 24 bit little endian integer into @val 350 | * but keep the current position. 351 | * 352 | * Returns: %TRUE if successful, %FALSE otherwise. 353 | */ 354 | 355 | /** 356 | * gst_byte_reader_get_uint24_be: 357 | * @reader: a #GstByteReader instance 358 | * @val: (out): Pointer to a #guint32 to store the result 359 | * 360 | * Read an unsigned 24 bit big endian integer into @val 361 | * and update the current position. 362 | * 363 | * Returns: %TRUE if successful, %FALSE otherwise. 364 | */ 365 | 366 | /** 367 | * gst_byte_reader_get_int24_be: 368 | * @reader: a #GstByteReader instance 369 | * @val: (out): Pointer to a #gint32 to store the result 370 | * 371 | * Read a signed 24 bit big endian integer into @val 372 | * and update the current position. 373 | * 374 | * Returns: %TRUE if successful, %FALSE otherwise. 375 | */ 376 | 377 | /** 378 | * gst_byte_reader_peek_uint24_be: 379 | * @reader: a #GstByteReader instance 380 | * @val: (out): Pointer to a #guint32 to store the result 381 | * 382 | * Read an unsigned 24 bit big endian integer into @val 383 | * but keep the current position. 384 | * 385 | * Returns: %TRUE if successful, %FALSE otherwise. 386 | */ 387 | 388 | /** 389 | * gst_byte_reader_peek_int24_be: 390 | * @reader: a #GstByteReader instance 391 | * @val: (out): Pointer to a #gint32 to store the result 392 | * 393 | * Read a signed 24 bit big endian integer into @val 394 | * but keep the current position. 395 | * 396 | * Returns: %TRUE if successful, %FALSE otherwise. 397 | */ 398 | 399 | 400 | /** 401 | * gst_byte_reader_get_uint32_le: 402 | * @reader: a #GstByteReader instance 403 | * @val: (out): Pointer to a #guint32 to store the result 404 | * 405 | * Read an unsigned 32 bit little endian integer into @val 406 | * and update the current position. 407 | * 408 | * Returns: %TRUE if successful, %FALSE otherwise. 409 | */ 410 | 411 | /** 412 | * gst_byte_reader_get_int32_le: 413 | * @reader: a #GstByteReader instance 414 | * @val: (out): Pointer to a #gint32 to store the result 415 | * 416 | * Read a signed 32 bit little endian integer into @val 417 | * and update the current position. 418 | * 419 | * Returns: %TRUE if successful, %FALSE otherwise. 420 | */ 421 | 422 | /** 423 | * gst_byte_reader_peek_uint32_le: 424 | * @reader: a #GstByteReader instance 425 | * @val: (out): Pointer to a #guint32 to store the result 426 | * 427 | * Read an unsigned 32 bit little endian integer into @val 428 | * but keep the current position. 429 | * 430 | * Returns: %TRUE if successful, %FALSE otherwise. 431 | */ 432 | 433 | /** 434 | * gst_byte_reader_peek_int32_le: 435 | * @reader: a #GstByteReader instance 436 | * @val: (out): Pointer to a #gint32 to store the result 437 | * 438 | * Read a signed 32 bit little endian integer into @val 439 | * but keep the current position. 440 | * 441 | * Returns: %TRUE if successful, %FALSE otherwise. 442 | */ 443 | 444 | /** 445 | * gst_byte_reader_get_uint32_be: 446 | * @reader: a #GstByteReader instance 447 | * @val: (out): Pointer to a #guint32 to store the result 448 | * 449 | * Read an unsigned 32 bit big endian integer into @val 450 | * and update the current position. 451 | * 452 | * Returns: %TRUE if successful, %FALSE otherwise. 453 | */ 454 | 455 | /** 456 | * gst_byte_reader_get_int32_be: 457 | * @reader: a #GstByteReader instance 458 | * @val: (out): Pointer to a #gint32 to store the result 459 | * 460 | * Read a signed 32 bit big endian integer into @val 461 | * and update the current position. 462 | * 463 | * Returns: %TRUE if successful, %FALSE otherwise. 464 | */ 465 | 466 | /** 467 | * gst_byte_reader_peek_uint32_be: 468 | * @reader: a #GstByteReader instance 469 | * @val: (out): Pointer to a #guint32 to store the result 470 | * 471 | * Read an unsigned 32 bit big endian integer into @val 472 | * but keep the current position. 473 | * 474 | * Returns: %TRUE if successful, %FALSE otherwise. 475 | */ 476 | 477 | /** 478 | * gst_byte_reader_peek_int32_be: 479 | * @reader: a #GstByteReader instance 480 | * @val: (out): Pointer to a #gint32 to store the result 481 | * 482 | * Read a signed 32 bit big endian integer into @val 483 | * but keep the current position. 484 | * 485 | * Returns: %TRUE if successful, %FALSE otherwise. 486 | */ 487 | 488 | /** 489 | * gst_byte_reader_get_uint64_le: 490 | * @reader: a #GstByteReader instance 491 | * @val: (out): Pointer to a #guint64 to store the result 492 | * 493 | * Read an unsigned 64 bit little endian integer into @val 494 | * and update the current position. 495 | * 496 | * Returns: %TRUE if successful, %FALSE otherwise. 497 | */ 498 | 499 | /** 500 | * gst_byte_reader_get_int64_le: 501 | * @reader: a #GstByteReader instance 502 | * @val: (out): Pointer to a #gint64 to store the result 503 | * 504 | * Read a signed 64 bit little endian integer into @val 505 | * and update the current position. 506 | * 507 | * Returns: %TRUE if successful, %FALSE otherwise. 508 | */ 509 | 510 | /** 511 | * gst_byte_reader_peek_uint64_le: 512 | * @reader: a #GstByteReader instance 513 | * @val: (out): Pointer to a #guint64 to store the result 514 | * 515 | * Read an unsigned 64 bit little endian integer into @val 516 | * but keep the current position. 517 | * 518 | * Returns: %TRUE if successful, %FALSE otherwise. 519 | */ 520 | 521 | /** 522 | * gst_byte_reader_peek_int64_le: 523 | * @reader: a #GstByteReader instance 524 | * @val: (out): Pointer to a #gint64 to store the result 525 | * 526 | * Read a signed 64 bit little endian integer into @val 527 | * but keep the current position. 528 | * 529 | * Returns: %TRUE if successful, %FALSE otherwise. 530 | */ 531 | 532 | /** 533 | * gst_byte_reader_get_uint64_be: 534 | * @reader: a #GstByteReader instance 535 | * @val: (out): Pointer to a #guint64 to store the result 536 | * 537 | * Read an unsigned 64 bit big endian integer into @val 538 | * and update the current position. 539 | * 540 | * Returns: %TRUE if successful, %FALSE otherwise. 541 | */ 542 | 543 | /** 544 | * gst_byte_reader_get_int64_be: 545 | * @reader: a #GstByteReader instance 546 | * @val: (out): Pointer to a #gint64 to store the result 547 | * 548 | * Read a signed 64 bit big endian integer into @val 549 | * and update the current position. 550 | * 551 | * Returns: %TRUE if successful, %FALSE otherwise. 552 | */ 553 | 554 | /** 555 | * gst_byte_reader_peek_uint64_be: 556 | * @reader: a #GstByteReader instance 557 | * @val: (out): Pointer to a #guint64 to store the result 558 | * 559 | * Read an unsigned 64 bit big endian integer into @val 560 | * but keep the current position. 561 | * 562 | * Returns: %TRUE if successful, %FALSE otherwise. 563 | */ 564 | 565 | /** 566 | * gst_byte_reader_peek_int64_be: 567 | * @reader: a #GstByteReader instance 568 | * @val: (out): Pointer to a #gint64 to store the result 569 | * 570 | * Read a signed 64 bit big endian integer into @val 571 | * but keep the current position. 572 | * 573 | * Returns: %TRUE if successful, %FALSE otherwise. 574 | */ 575 | 576 | #define GST_BYTE_READER_PEEK_GET(bits,type,name) \ 577 | gboolean \ 578 | gst_byte_reader_get_##name (GstByteReader * reader, type * val) \ 579 | { \ 580 | return _gst_byte_reader_get_##name##_inline (reader, val); \ 581 | } \ 582 | \ 583 | gboolean \ 584 | gst_byte_reader_peek_##name (const GstByteReader * reader, type * val) \ 585 | { \ 586 | return _gst_byte_reader_peek_##name##_inline (reader, val); \ 587 | } 588 | 589 | /* *INDENT-OFF* */ 590 | 591 | GST_BYTE_READER_PEEK_GET(8,guint8,uint8) 592 | GST_BYTE_READER_PEEK_GET(8,gint8,int8) 593 | 594 | GST_BYTE_READER_PEEK_GET(16,guint16,uint16_le) 595 | GST_BYTE_READER_PEEK_GET(16,guint16,uint16_be) 596 | GST_BYTE_READER_PEEK_GET(16,gint16,int16_le) 597 | GST_BYTE_READER_PEEK_GET(16,gint16,int16_be) 598 | 599 | GST_BYTE_READER_PEEK_GET(24,guint32,uint24_le) 600 | GST_BYTE_READER_PEEK_GET(24,guint32,uint24_be) 601 | GST_BYTE_READER_PEEK_GET(24,gint32,int24_le) 602 | GST_BYTE_READER_PEEK_GET(24,gint32,int24_be) 603 | 604 | GST_BYTE_READER_PEEK_GET(32,guint32,uint32_le) 605 | GST_BYTE_READER_PEEK_GET(32,guint32,uint32_be) 606 | GST_BYTE_READER_PEEK_GET(32,gint32,int32_le) 607 | GST_BYTE_READER_PEEK_GET(32,gint32,int32_be) 608 | 609 | GST_BYTE_READER_PEEK_GET(64,guint64,uint64_le) 610 | GST_BYTE_READER_PEEK_GET(64,guint64,uint64_be) 611 | GST_BYTE_READER_PEEK_GET(64,gint64,int64_le) 612 | GST_BYTE_READER_PEEK_GET(64,gint64,int64_be) 613 | 614 | /** 615 | * gst_byte_reader_get_float32_le: 616 | * @reader: a #GstByteReader instance 617 | * @val: (out): Pointer to a #gfloat to store the result 618 | * 619 | * Read a 32 bit little endian floating point value into @val 620 | * and update the current position. 621 | * 622 | * Returns: %TRUE if successful, %FALSE otherwise. 623 | */ 624 | 625 | /** 626 | * gst_byte_reader_peek_float32_le: 627 | * @reader: a #GstByteReader instance 628 | * @val: (out): Pointer to a #gfloat to store the result 629 | * 630 | * Read a 32 bit little endian floating point value into @val 631 | * but keep the current position. 632 | * 633 | * Returns: %TRUE if successful, %FALSE otherwise. 634 | */ 635 | 636 | /** 637 | * gst_byte_reader_get_float32_be: 638 | * @reader: a #GstByteReader instance 639 | * @val: (out): Pointer to a #gfloat to store the result 640 | * 641 | * Read a 32 bit big endian floating point value into @val 642 | * and update the current position. 643 | * 644 | * Returns: %TRUE if successful, %FALSE otherwise. 645 | */ 646 | 647 | /** 648 | * gst_byte_reader_peek_float32_be: 649 | * @reader: a #GstByteReader instance 650 | * @val: (out): Pointer to a #gfloat to store the result 651 | * 652 | * Read a 32 bit big endian floating point value into @val 653 | * but keep the current position. 654 | * 655 | * Returns: %TRUE if successful, %FALSE otherwise. 656 | */ 657 | 658 | /** 659 | * gst_byte_reader_get_float64_le: 660 | * @reader: a #GstByteReader instance 661 | * @val: (out): Pointer to a #gdouble to store the result 662 | * 663 | * Read a 64 bit little endian floating point value into @val 664 | * and update the current position. 665 | * 666 | * Returns: %TRUE if successful, %FALSE otherwise. 667 | */ 668 | 669 | /** 670 | * gst_byte_reader_peek_float64_le: 671 | * @reader: a #GstByteReader instance 672 | * @val: (out): Pointer to a #gdouble to store the result 673 | * 674 | * Read a 64 bit little endian floating point value into @val 675 | * but keep the current position. 676 | * 677 | * Returns: %TRUE if successful, %FALSE otherwise. 678 | */ 679 | 680 | /** 681 | * gst_byte_reader_get_float64_be: 682 | * @reader: a #GstByteReader instance 683 | * @val: (out): Pointer to a #gdouble to store the result 684 | * 685 | * Read a 64 bit big endian floating point value into @val 686 | * and update the current position. 687 | * 688 | * Returns: %TRUE if successful, %FALSE otherwise. 689 | */ 690 | 691 | /** 692 | * gst_byte_reader_peek_float64_be: 693 | * @reader: a #GstByteReader instance 694 | * @val: (out): Pointer to a #gdouble to store the result 695 | * 696 | * Read a 64 bit big endian floating point value into @val 697 | * but keep the current position. 698 | * 699 | * Returns: %TRUE if successful, %FALSE otherwise. 700 | */ 701 | 702 | GST_BYTE_READER_PEEK_GET(32,gfloat,float32_le) 703 | GST_BYTE_READER_PEEK_GET(32,gfloat,float32_be) 704 | GST_BYTE_READER_PEEK_GET(64,gdouble,float64_le) 705 | GST_BYTE_READER_PEEK_GET(64,gdouble,float64_be) 706 | 707 | /* *INDENT-ON* */ 708 | 709 | /** 710 | * gst_byte_reader_get_data: 711 | * @reader: a #GstByteReader instance 712 | * @size: Size in bytes 713 | * @val: (out) (transfer none) (array length=size): address of a 714 | * #guint8 pointer variable in which to store the result 715 | * 716 | * Returns a constant pointer to the current data 717 | * position if at least @size bytes are left and 718 | * updates the current position. 719 | * 720 | * 721 | * Returns: %TRUE if successful, %FALSE otherwise. 722 | */ 723 | gboolean 724 | gst_byte_reader_get_data (GstByteReader * reader, guint size, 725 | const guint8 ** val) 726 | { 727 | return _gst_byte_reader_get_data_inline (reader, size, val); 728 | } 729 | 730 | /** 731 | * gst_byte_reader_peek_data: 732 | * @reader: a #GstByteReader instance 733 | * @size: Size in bytes 734 | * @val: (out) (transfer none) (array length=size): address of a 735 | * #guint8 pointer variable in which to store the result 736 | * 737 | * Returns a constant pointer to the current data 738 | * position if at least @size bytes are left and 739 | * keeps the current position. 740 | * 741 | * 742 | * Returns: %TRUE if successful, %FALSE otherwise. 743 | */ 744 | gboolean 745 | gst_byte_reader_peek_data (const GstByteReader * reader, guint size, 746 | const guint8 ** val) 747 | { 748 | return _gst_byte_reader_peek_data_inline (reader, size, val); 749 | } 750 | 751 | /** 752 | * gst_byte_reader_dup_data: 753 | * @reader: a #GstByteReader instance 754 | * @size: Size in bytes 755 | * @val: (out) (transfer full) (array length=size): address of a 756 | * #guint8 pointer variable in which to store the result 757 | * 758 | * Free-function: g_free 759 | * 760 | * Returns a newly-allocated copy of the current data 761 | * position if at least @size bytes are left and 762 | * updates the current position. Free with g_free() when no longer needed. 763 | * 764 | * Returns: %TRUE if successful, %FALSE otherwise. 765 | */ 766 | gboolean 767 | gst_byte_reader_dup_data (GstByteReader * reader, guint size, guint8 ** val) 768 | { 769 | return _gst_byte_reader_dup_data_inline (reader, size, val); 770 | } 771 | 772 | /* Special optimized scan for mask 0xffffff00 and pattern 0x00000100 */ 773 | static inline gint 774 | _scan_for_start_code (const guint8 * data, guint offset, guint size) 775 | { 776 | guint8 *pdata = (guint8 *) data; 777 | guint8 *pend = (guint8 *) (data + size - 4); 778 | 779 | while (pdata <= pend) { 780 | if (pdata[2] > 1) { 781 | pdata += 3; 782 | } else if (pdata[1]) { 783 | pdata += 2; 784 | } else if (pdata[0] || pdata[2] != 1) { 785 | pdata++; 786 | } else { 787 | return (pdata - data + offset); 788 | } 789 | } 790 | 791 | /* nothing found */ 792 | return -1; 793 | } 794 | 795 | /** 796 | * gst_byte_reader_masked_scan_uint32: 797 | * @reader: a #GstByteReader 798 | * @mask: mask to apply to data before matching against @pattern 799 | * @pattern: pattern to match (after mask is applied) 800 | * @offset: offset from which to start scanning, relative to the current 801 | * position 802 | * @size: number of bytes to scan from offset 803 | * 804 | * Scan for pattern @pattern with applied mask @mask in the byte reader data, 805 | * starting from offset @offset relative to the current position. 806 | * 807 | * The bytes in @pattern and @mask are interpreted left-to-right, regardless 808 | * of endianness. All four bytes of the pattern must be present in the 809 | * byte reader data for it to match, even if the first or last bytes are masked 810 | * out. 811 | * 812 | * It is an error to call this function without making sure that there is 813 | * enough data (offset+size bytes) in the byte reader. 814 | * 815 | * Returns: offset of the first match, or -1 if no match was found. 816 | * 817 | * Example: 818 | * 819 | * // Assume the reader contains 0x00 0x01 0x02 ... 0xfe 0xff 820 | * 821 | * gst_byte_reader_masked_scan_uint32 (reader, 0xffffffff, 0x00010203, 0, 256); 822 | * // -> returns 0 823 | * gst_byte_reader_masked_scan_uint32 (reader, 0xffffffff, 0x00010203, 1, 255); 824 | * // -> returns -1 825 | * gst_byte_reader_masked_scan_uint32 (reader, 0xffffffff, 0x01020304, 1, 255); 826 | * // -> returns 1 827 | * gst_byte_reader_masked_scan_uint32 (reader, 0xffff, 0x0001, 0, 256); 828 | * // -> returns -1 829 | * gst_byte_reader_masked_scan_uint32 (reader, 0xffff, 0x0203, 0, 256); 830 | * // -> returns 0 831 | * gst_byte_reader_masked_scan_uint32 (reader, 0xffff0000, 0x02030000, 0, 256); 832 | * // -> returns 2 833 | * gst_byte_reader_masked_scan_uint32 (reader, 0xffff0000, 0x02030000, 0, 4); 834 | * // -> returns -1 835 | * 836 | */ 837 | guint 838 | gst_byte_reader_masked_scan_uint32 (const GstByteReader * reader, guint32 mask, 839 | guint32 pattern, guint offset, guint size) 840 | { 841 | const guint8 *data; 842 | guint32 state; 843 | guint i; 844 | 845 | g_return_val_if_fail (size > 0, -1); 846 | g_return_val_if_fail ((guint64) offset + size <= reader->size - reader->byte, 847 | -1); 848 | 849 | /* we can't find the pattern with less than 4 bytes */ 850 | if (G_UNLIKELY (size < 4)) 851 | return -1; 852 | 853 | data = reader->data + reader->byte + offset; 854 | 855 | /* Handle special case found in MPEG and H264 */ 856 | if ((pattern == 0x00000100) && (mask == 0xffffff00)) 857 | return _scan_for_start_code (data, offset, size); 858 | 859 | /* set the state to something that does not match */ 860 | state = ~pattern; 861 | 862 | /* now find data */ 863 | for (i = 0; i < size; i++) { 864 | /* throw away one byte and move in the next byte */ 865 | state = ((state << 8) | data[i]); 866 | if (G_UNLIKELY ((state & mask) == pattern)) { 867 | /* we have a match but we need to have skipped at 868 | * least 4 bytes to fill the state. */ 869 | if (G_LIKELY (i >= 3)) 870 | return offset + i - 3; 871 | } 872 | } 873 | 874 | /* nothing found */ 875 | return -1; 876 | } 877 | 878 | #define GST_BYTE_READER_SCAN_STRING(bits) \ 879 | static guint \ 880 | gst_byte_reader_scan_string_utf##bits (const GstByteReader * reader) \ 881 | { \ 882 | guint len, off, max_len; \ 883 | \ 884 | max_len = (reader->size - reader->byte) / sizeof (guint##bits); \ 885 | \ 886 | /* need at least a single NUL terminator */ \ 887 | if (max_len < 1) \ 888 | return 0; \ 889 | \ 890 | len = 0; \ 891 | off = reader->byte; \ 892 | /* endianness does not matter if we are looking for a NUL terminator */ \ 893 | while (GST_READ_UINT##bits##_LE (&reader->data[off]) != 0) { \ 894 | ++len; \ 895 | off += sizeof (guint##bits); \ 896 | /* have we reached the end without finding a NUL terminator? */ \ 897 | if (len == max_len) \ 898 | return 0; \ 899 | } \ 900 | /* return size in bytes including the NUL terminator (hence the +1) */ \ 901 | return (len + 1) * sizeof (guint##bits); \ 902 | } 903 | 904 | #define GST_READ_UINT8_LE GST_READ_UINT8 905 | GST_BYTE_READER_SCAN_STRING (8); 906 | #undef GST_READ_UINT8_LE 907 | GST_BYTE_READER_SCAN_STRING (16); 908 | GST_BYTE_READER_SCAN_STRING (32); 909 | 910 | #define GST_BYTE_READER_SKIP_STRING(bits) \ 911 | gboolean \ 912 | gst_byte_reader_skip_string_utf##bits (GstByteReader * reader) \ 913 | { \ 914 | guint size; /* size in bytes including the terminator */ \ 915 | \ 916 | g_return_val_if_fail (reader != NULL, FALSE); \ 917 | \ 918 | size = gst_byte_reader_scan_string_utf##bits (reader); \ 919 | reader->byte += size; \ 920 | return (size > 0); \ 921 | } 922 | 923 | /** 924 | * gst_byte_reader_skip_string: 925 | * @reader: a #GstByteReader instance 926 | * 927 | * Skips a NUL-terminated string in the #GstByteReader instance, advancing 928 | * the current position to the byte after the string. This will work for 929 | * any NUL-terminated string with a character width of 8 bits, so ASCII, 930 | * UTF-8, ISO-8859-N etc. 931 | * 932 | * This function will fail if no NUL-terminator was found in in the data. 933 | * 934 | * Returns: %TRUE if a string could be skipped, %FALSE otherwise. 935 | */ 936 | /** 937 | * gst_byte_reader_skip_string_utf8: 938 | * @reader: a #GstByteReader instance 939 | * 940 | * Skips a NUL-terminated string in the #GstByteReader instance, advancing 941 | * the current position to the byte after the string. This will work for 942 | * any NUL-terminated string with a character width of 8 bits, so ASCII, 943 | * UTF-8, ISO-8859-N etc. No input checking for valid UTF-8 is done. 944 | * 945 | * This function will fail if no NUL-terminator was found in in the data. 946 | * 947 | * Returns: %TRUE if a string could be skipped, %FALSE otherwise. 948 | */ 949 | GST_BYTE_READER_SKIP_STRING (8); 950 | 951 | /** 952 | * gst_byte_reader_skip_string_utf16: 953 | * @reader: a #GstByteReader instance 954 | * 955 | * Skips a NUL-terminated UTF-16 string in the #GstByteReader instance, 956 | * advancing the current position to the byte after the string. 957 | * 958 | * No input checking for valid UTF-16 is done. 959 | * 960 | * This function will fail if no NUL-terminator was found in in the data. 961 | * 962 | * Returns: %TRUE if a string could be skipped, %FALSE otherwise. 963 | */ 964 | GST_BYTE_READER_SKIP_STRING (16); 965 | 966 | /** 967 | * gst_byte_reader_skip_string_utf32: 968 | * @reader: a #GstByteReader instance 969 | * 970 | * Skips a NUL-terminated UTF-32 string in the #GstByteReader instance, 971 | * advancing the current position to the byte after the string. 972 | * 973 | * No input checking for valid UTF-32 is done. 974 | * 975 | * This function will fail if no NUL-terminator was found in in the data. 976 | * 977 | * Returns: %TRUE if a string could be skipped, %FALSE otherwise. 978 | */ 979 | GST_BYTE_READER_SKIP_STRING (32); 980 | 981 | /** 982 | * gst_byte_reader_peek_string: 983 | * @reader: a #GstByteReader instance 984 | * @str: (out) (transfer none) (array zero-terminated=1): address of a 985 | * #gchar pointer variable in which to store the result 986 | * 987 | * Returns a constant pointer to the current data position if there is 988 | * a NUL-terminated string in the data (this could be just a NUL terminator). 989 | * The current position will be maintained. This will work for any 990 | * NUL-terminated string with a character width of 8 bits, so ASCII, 991 | * UTF-8, ISO-8859-N etc. 992 | * 993 | * This function will fail if no NUL-terminator was found in in the data. 994 | * 995 | * Returns: %TRUE if a string could be skipped, %FALSE otherwise. 996 | */ 997 | /** 998 | * gst_byte_reader_peek_string_utf8: 999 | * @reader: a #GstByteReader instance 1000 | * @str: (out) (transfer none) (array zero-terminated=1): address of a 1001 | * #gchar pointer variable in which to store the result 1002 | * 1003 | * Returns a constant pointer to the current data position if there is 1004 | * a NUL-terminated string in the data (this could be just a NUL terminator). 1005 | * The current position will be maintained. This will work for any 1006 | * NUL-terminated string with a character width of 8 bits, so ASCII, 1007 | * UTF-8, ISO-8859-N etc. 1008 | * 1009 | * No input checking for valid UTF-8 is done. 1010 | * 1011 | * This function will fail if no NUL-terminator was found in in the data. 1012 | * 1013 | * Returns: %TRUE if a string could be skipped, %FALSE otherwise. 1014 | */ 1015 | gboolean 1016 | gst_byte_reader_peek_string_utf8 (const GstByteReader * reader, 1017 | const gchar ** str) 1018 | { 1019 | g_return_val_if_fail (reader != NULL, FALSE); 1020 | g_return_val_if_fail (str != NULL, FALSE); 1021 | 1022 | if (gst_byte_reader_scan_string_utf8 (reader) > 0) { 1023 | *str = (const gchar *) (reader->data + reader->byte); 1024 | } else { 1025 | *str = NULL; 1026 | } 1027 | return (*str != NULL); 1028 | } 1029 | 1030 | /** 1031 | * gst_byte_reader_get_string_utf8: 1032 | * @reader: a #GstByteReader instance 1033 | * @str: (out) (transfer none) (array zero-terminated=1): address of a 1034 | * #gchar pointer variable in which to store the result 1035 | * 1036 | * Returns a constant pointer to the current data position if there is 1037 | * a NUL-terminated string in the data (this could be just a NUL terminator), 1038 | * advancing the current position to the byte after the string. This will work 1039 | * for any NUL-terminated string with a character width of 8 bits, so ASCII, 1040 | * UTF-8, ISO-8859-N etc. 1041 | * 1042 | * No input checking for valid UTF-8 is done. 1043 | * 1044 | * This function will fail if no NUL-terminator was found in in the data. 1045 | * 1046 | * Returns: %TRUE if a string could be found, %FALSE otherwise. 1047 | */ 1048 | gboolean 1049 | gst_byte_reader_get_string_utf8 (GstByteReader * reader, const gchar ** str) 1050 | { 1051 | guint size; /* size in bytes including the terminator */ 1052 | 1053 | g_return_val_if_fail (reader != NULL, FALSE); 1054 | g_return_val_if_fail (str != NULL, FALSE); 1055 | 1056 | size = gst_byte_reader_scan_string_utf8 (reader); 1057 | if (size == 0) { 1058 | *str = NULL; 1059 | return FALSE; 1060 | } 1061 | 1062 | *str = (const gchar *) (reader->data + reader->byte); 1063 | reader->byte += size; 1064 | return TRUE; 1065 | } 1066 | 1067 | #define GST_BYTE_READER_DUP_STRING(bits,type) \ 1068 | gboolean \ 1069 | gst_byte_reader_dup_string_utf##bits (GstByteReader * reader, type ** str) \ 1070 | { \ 1071 | guint size; /* size in bytes including the terminator */ \ 1072 | \ 1073 | g_return_val_if_fail (reader != NULL, FALSE); \ 1074 | g_return_val_if_fail (str != NULL, FALSE); \ 1075 | \ 1076 | size = gst_byte_reader_scan_string_utf##bits (reader); \ 1077 | if (size == 0) { \ 1078 | *str = NULL; \ 1079 | return FALSE; \ 1080 | } \ 1081 | *str = g_memdup (reader->data + reader->byte, size); \ 1082 | reader->byte += size; \ 1083 | return TRUE; \ 1084 | } 1085 | 1086 | /** 1087 | * gst_byte_reader_dup_string_utf8: 1088 | * @reader: a #GstByteReader instance 1089 | * @str: (out) (transfer full) (array zero-terminated=1): address of a 1090 | * #gchar pointer variable in which to store the result 1091 | * 1092 | * Free-function: g_free 1093 | * 1094 | * FIXME:Reads (copies) a NUL-terminated string in the #GstByteReader instance, 1095 | * advancing the current position to the byte after the string. This will work 1096 | * for any NUL-terminated string with a character width of 8 bits, so ASCII, 1097 | * UTF-8, ISO-8859-N etc. No input checking for valid UTF-8 is done. 1098 | * 1099 | * This function will fail if no NUL-terminator was found in in the data. 1100 | * 1101 | * Returns: %TRUE if a string could be read into @str, %FALSE otherwise. The 1102 | * string put into @str must be freed with g_free() when no longer needed. 1103 | */ 1104 | GST_BYTE_READER_DUP_STRING (8, gchar); 1105 | 1106 | /** 1107 | * gst_byte_reader_dup_string_utf16: 1108 | * @reader: a #GstByteReader instance 1109 | * @str: (out) (transfer full) (array zero-terminated=1): address of a 1110 | * #guint16 pointer variable in which to store the result 1111 | * 1112 | * Free-function: g_free 1113 | * 1114 | * Returns a newly-allocated copy of the current data position if there is 1115 | * a NUL-terminated UTF-16 string in the data (this could be an empty string 1116 | * as well), and advances the current position. 1117 | * 1118 | * No input checking for valid UTF-16 is done. This function is endianness 1119 | * agnostic - you should not assume the UTF-16 characters are in host 1120 | * endianness. 1121 | * 1122 | * This function will fail if no NUL-terminator was found in in the data. 1123 | * 1124 | * Note: there is no peek or get variant of this function to ensure correct 1125 | * byte alignment of the UTF-16 string. 1126 | * 1127 | * Returns: %TRUE if a string could be read, %FALSE otherwise. The 1128 | * string put into @str must be freed with g_free() when no longer needed. 1129 | */ 1130 | GST_BYTE_READER_DUP_STRING (16, guint16); 1131 | 1132 | /** 1133 | * gst_byte_reader_dup_string_utf32: 1134 | * @reader: a #GstByteReader instance 1135 | * @str: (out) (transfer full) (array zero-terminated=1): address of a 1136 | * #guint32 pointer variable in which to store the result 1137 | * 1138 | * Free-function: g_free 1139 | * 1140 | * Returns a newly-allocated copy of the current data position if there is 1141 | * a NUL-terminated UTF-32 string in the data (this could be an empty string 1142 | * as well), and advances the current position. 1143 | * 1144 | * No input checking for valid UTF-32 is done. This function is endianness 1145 | * agnostic - you should not assume the UTF-32 characters are in host 1146 | * endianness. 1147 | * 1148 | * This function will fail if no NUL-terminator was found in in the data. 1149 | * 1150 | * Note: there is no peek or get variant of this function to ensure correct 1151 | * byte alignment of the UTF-32 string. 1152 | * 1153 | * Returns: %TRUE if a string could be read, %FALSE otherwise. The 1154 | * string put into @str must be freed with g_free() when no longer needed. 1155 | */ 1156 | GST_BYTE_READER_DUP_STRING (32, guint32); 1157 | -------------------------------------------------------------------------------- /gstbytereader.h: -------------------------------------------------------------------------------- 1 | /* GStreamer byte reader 2 | * 3 | * Copyright (C) 2008 Sebastian Dröge . 4 | * Copyright (C) 2009 Tim-Philipp Müller 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License, version 2.1, as published by the Free Software Foundation. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this program. If not, see 17 | * . 18 | */ 19 | 20 | #ifndef __GST_BYTE_READER_H__ 21 | #define __GST_BYTE_READER_H__ 22 | 23 | #include 24 | 25 | G_BEGIN_DECLS 26 | 27 | #define GST_BYTE_READER(reader) ((GstByteReader *) (reader)) 28 | 29 | /** 30 | * GstByteReader: 31 | * @data: (array length=size): Data from which the bit reader will 32 | * read 33 | * @size: Size of @data in bytes 34 | * @byte: Current byte position 35 | * 36 | * A byte reader instance. 37 | */ 38 | typedef struct { 39 | const guint8 *data; 40 | guint size; 41 | 42 | guint byte; /* Byte position */ 43 | 44 | /* < private > */ 45 | gpointer _gst_reserved[GST_PADDING]; 46 | } GstByteReader; 47 | 48 | GstByteReader * gst_byte_reader_new (const guint8 *data, guint size) G_GNUC_MALLOC; 49 | void gst_byte_reader_free (GstByteReader *reader); 50 | 51 | void gst_byte_reader_init (GstByteReader *reader, const guint8 *data, guint size); 52 | 53 | gboolean gst_byte_reader_set_pos (GstByteReader *reader, guint pos); 54 | guint gst_byte_reader_get_pos (const GstByteReader *reader); 55 | 56 | guint gst_byte_reader_get_remaining (const GstByteReader *reader); 57 | 58 | guint gst_byte_reader_get_size (const GstByteReader *reader); 59 | 60 | gboolean gst_byte_reader_skip (GstByteReader *reader, guint nbytes); 61 | 62 | gboolean gst_byte_reader_get_uint8 (GstByteReader *reader, guint8 *val); 63 | gboolean gst_byte_reader_get_int8 (GstByteReader *reader, gint8 *val); 64 | gboolean gst_byte_reader_get_uint16_le (GstByteReader *reader, guint16 *val); 65 | gboolean gst_byte_reader_get_int16_le (GstByteReader *reader, gint16 *val); 66 | gboolean gst_byte_reader_get_uint16_be (GstByteReader *reader, guint16 *val); 67 | gboolean gst_byte_reader_get_int16_be (GstByteReader *reader, gint16 *val); 68 | gboolean gst_byte_reader_get_uint24_le (GstByteReader *reader, guint32 *val); 69 | gboolean gst_byte_reader_get_int24_le (GstByteReader *reader, gint32 *val); 70 | gboolean gst_byte_reader_get_uint24_be (GstByteReader *reader, guint32 *val); 71 | gboolean gst_byte_reader_get_int24_be (GstByteReader *reader, gint32 *val); 72 | gboolean gst_byte_reader_get_uint32_le (GstByteReader *reader, guint32 *val); 73 | gboolean gst_byte_reader_get_int32_le (GstByteReader *reader, gint32 *val); 74 | gboolean gst_byte_reader_get_uint32_be (GstByteReader *reader, guint32 *val); 75 | gboolean gst_byte_reader_get_int32_be (GstByteReader *reader, gint32 *val); 76 | gboolean gst_byte_reader_get_uint64_le (GstByteReader *reader, guint64 *val); 77 | gboolean gst_byte_reader_get_int64_le (GstByteReader *reader, gint64 *val); 78 | gboolean gst_byte_reader_get_uint64_be (GstByteReader *reader, guint64 *val); 79 | gboolean gst_byte_reader_get_int64_be (GstByteReader *reader, gint64 *val); 80 | 81 | gboolean gst_byte_reader_peek_uint8 (const GstByteReader *reader, guint8 *val); 82 | gboolean gst_byte_reader_peek_int8 (const GstByteReader *reader, gint8 *val); 83 | gboolean gst_byte_reader_peek_uint16_le (const GstByteReader *reader, guint16 *val); 84 | gboolean gst_byte_reader_peek_int16_le (const GstByteReader *reader, gint16 *val); 85 | gboolean gst_byte_reader_peek_uint16_be (const GstByteReader *reader, guint16 *val); 86 | gboolean gst_byte_reader_peek_int16_be (const GstByteReader *reader, gint16 *val); 87 | gboolean gst_byte_reader_peek_uint24_le (const GstByteReader *reader, guint32 *val); 88 | gboolean gst_byte_reader_peek_int24_le (const GstByteReader *reader, gint32 *val); 89 | gboolean gst_byte_reader_peek_uint24_be (const GstByteReader *reader, guint32 *val); 90 | gboolean gst_byte_reader_peek_int24_be (const GstByteReader *reader, gint32 *val); 91 | gboolean gst_byte_reader_peek_uint32_le (const GstByteReader *reader, guint32 *val); 92 | gboolean gst_byte_reader_peek_int32_le (const GstByteReader *reader, gint32 *val); 93 | gboolean gst_byte_reader_peek_uint32_be (const GstByteReader *reader, guint32 *val); 94 | gboolean gst_byte_reader_peek_int32_be (const GstByteReader *reader, gint32 *val); 95 | gboolean gst_byte_reader_peek_uint64_le (const GstByteReader *reader, guint64 *val); 96 | gboolean gst_byte_reader_peek_int64_le (const GstByteReader *reader, gint64 *val); 97 | gboolean gst_byte_reader_peek_uint64_be (const GstByteReader *reader, guint64 *val); 98 | gboolean gst_byte_reader_peek_int64_be (const GstByteReader *reader, gint64 *val); 99 | 100 | gboolean gst_byte_reader_get_float32_le (GstByteReader *reader, gfloat *val); 101 | gboolean gst_byte_reader_get_float32_be (GstByteReader *reader, gfloat *val); 102 | gboolean gst_byte_reader_get_float64_le (GstByteReader *reader, gdouble *val); 103 | gboolean gst_byte_reader_get_float64_be (GstByteReader *reader, gdouble *val); 104 | 105 | gboolean gst_byte_reader_peek_float32_le (const GstByteReader *reader, gfloat *val); 106 | gboolean gst_byte_reader_peek_float32_be (const GstByteReader *reader, gfloat *val); 107 | gboolean gst_byte_reader_peek_float64_le (const GstByteReader *reader, gdouble *val); 108 | gboolean gst_byte_reader_peek_float64_be (const GstByteReader *reader, gdouble *val); 109 | 110 | gboolean gst_byte_reader_dup_data (GstByteReader * reader, guint size, guint8 ** val); 111 | gboolean gst_byte_reader_get_data (GstByteReader * reader, guint size, const guint8 ** val); 112 | gboolean gst_byte_reader_peek_data (const GstByteReader * reader, guint size, const guint8 ** val); 113 | 114 | #define gst_byte_reader_dup_string(reader,str) \ 115 | gst_byte_reader_dup_string_utf8(reader,str) 116 | 117 | gboolean gst_byte_reader_dup_string_utf8 (GstByteReader * reader, gchar ** str); 118 | gboolean gst_byte_reader_dup_string_utf16 (GstByteReader * reader, guint16 ** str); 119 | gboolean gst_byte_reader_dup_string_utf32 (GstByteReader * reader, guint32 ** str); 120 | 121 | #define gst_byte_reader_skip_string(reader) \ 122 | gst_byte_reader_skip_string_utf8(reader) 123 | 124 | gboolean gst_byte_reader_skip_string_utf8 (GstByteReader * reader); 125 | gboolean gst_byte_reader_skip_string_utf16 (GstByteReader * reader); 126 | gboolean gst_byte_reader_skip_string_utf32 (GstByteReader * reader); 127 | 128 | #define gst_byte_reader_get_string(reader,str) \ 129 | gst_byte_reader_get_string_utf8(reader,str) 130 | 131 | #define gst_byte_reader_peek_string(reader,str) \ 132 | gst_byte_reader_peek_string_utf8(reader,str) 133 | 134 | gboolean gst_byte_reader_get_string_utf8 (GstByteReader * reader, const gchar ** str); 135 | gboolean gst_byte_reader_peek_string_utf8 (const GstByteReader * reader, const gchar ** str); 136 | 137 | guint gst_byte_reader_masked_scan_uint32 (const GstByteReader * reader, 138 | guint32 mask, 139 | guint32 pattern, 140 | guint offset, 141 | guint size); 142 | 143 | /** 144 | * GST_BYTE_READER_INIT: 145 | * @data: Data from which the #GstByteReader should read 146 | * @size: Size of @data in bytes 147 | * 148 | * A #GstByteReader must be initialized with this macro, before it can be 149 | * used. This macro can used be to initialize a variable, but it cannot 150 | * be assigned to a variable. In that case you have to use 151 | * gst_byte_reader_init(). 152 | */ 153 | #define GST_BYTE_READER_INIT(data, size) {data, size, 0} 154 | 155 | /* unchecked variants */ 156 | static inline void 157 | gst_byte_reader_skip_unchecked (GstByteReader * reader, guint nbytes) 158 | { 159 | reader->byte += nbytes; 160 | } 161 | 162 | #define __GST_BYTE_READER_GET_PEEK_BITS_UNCHECKED(bits,type,lower,upper,adj) \ 163 | \ 164 | static inline type \ 165 | gst_byte_reader_peek_##lower##_unchecked (const GstByteReader * reader) \ 166 | { \ 167 | type val = (type) GST_READ_##upper (reader->data + reader->byte); \ 168 | adj \ 169 | return val; \ 170 | } \ 171 | \ 172 | static inline type \ 173 | gst_byte_reader_get_##lower##_unchecked (GstByteReader * reader) \ 174 | { \ 175 | type val = gst_byte_reader_peek_##lower##_unchecked (reader); \ 176 | reader->byte += bits / 8; \ 177 | return val; \ 178 | } 179 | 180 | __GST_BYTE_READER_GET_PEEK_BITS_UNCHECKED(8,guint8,uint8,UINT8,/* */) 181 | __GST_BYTE_READER_GET_PEEK_BITS_UNCHECKED(8,gint8,int8,UINT8,/* */) 182 | 183 | __GST_BYTE_READER_GET_PEEK_BITS_UNCHECKED(16,guint16,uint16_le,UINT16_LE,/* */) 184 | __GST_BYTE_READER_GET_PEEK_BITS_UNCHECKED(16,guint16,uint16_be,UINT16_BE,/* */) 185 | __GST_BYTE_READER_GET_PEEK_BITS_UNCHECKED(16,gint16,int16_le,UINT16_LE,/* */) 186 | __GST_BYTE_READER_GET_PEEK_BITS_UNCHECKED(16,gint16,int16_be,UINT16_BE,/* */) 187 | 188 | __GST_BYTE_READER_GET_PEEK_BITS_UNCHECKED(32,guint32,uint32_le,UINT32_LE,/* */) 189 | __GST_BYTE_READER_GET_PEEK_BITS_UNCHECKED(32,guint32,uint32_be,UINT32_BE,/* */) 190 | __GST_BYTE_READER_GET_PEEK_BITS_UNCHECKED(32,gint32,int32_le,UINT32_LE,/* */) 191 | __GST_BYTE_READER_GET_PEEK_BITS_UNCHECKED(32,gint32,int32_be,UINT32_BE,/* */) 192 | 193 | __GST_BYTE_READER_GET_PEEK_BITS_UNCHECKED(24,guint32,uint24_le,UINT24_LE,/* */) 194 | __GST_BYTE_READER_GET_PEEK_BITS_UNCHECKED(24,guint32,uint24_be,UINT24_BE,/* */) 195 | 196 | /* fix up the sign for 24-bit signed ints stored in 32-bit signed ints */ 197 | __GST_BYTE_READER_GET_PEEK_BITS_UNCHECKED(24,gint32,int24_le,UINT24_LE, 198 | if (val & 0x00800000) val |= 0xff000000;) 199 | __GST_BYTE_READER_GET_PEEK_BITS_UNCHECKED(24,gint32,int24_be,UINT24_BE, 200 | if (val & 0x00800000) val |= 0xff000000;) 201 | 202 | __GST_BYTE_READER_GET_PEEK_BITS_UNCHECKED(64,guint64,uint64_le,UINT64_LE,/* */) 203 | __GST_BYTE_READER_GET_PEEK_BITS_UNCHECKED(64,guint64,uint64_be,UINT64_BE,/* */) 204 | __GST_BYTE_READER_GET_PEEK_BITS_UNCHECKED(64,gint64,int64_le,UINT64_LE,/* */) 205 | __GST_BYTE_READER_GET_PEEK_BITS_UNCHECKED(64,gint64,int64_be,UINT64_BE,/* */) 206 | 207 | __GST_BYTE_READER_GET_PEEK_BITS_UNCHECKED(32,gfloat,float32_le,FLOAT_LE,/* */) 208 | __GST_BYTE_READER_GET_PEEK_BITS_UNCHECKED(32,gfloat,float32_be,FLOAT_BE,/* */) 209 | __GST_BYTE_READER_GET_PEEK_BITS_UNCHECKED(64,gdouble,float64_le,DOUBLE_LE,/* */) 210 | __GST_BYTE_READER_GET_PEEK_BITS_UNCHECKED(64,gdouble,float64_be,DOUBLE_BE,/* */) 211 | 212 | #undef __GET_PEEK_BITS_UNCHECKED 213 | 214 | static inline const guint8 * 215 | gst_byte_reader_peek_data_unchecked (const GstByteReader * reader) 216 | { 217 | return (const guint8 *) (reader->data + reader->byte); 218 | } 219 | 220 | static inline const guint8 * 221 | gst_byte_reader_get_data_unchecked (GstByteReader * reader, guint size) 222 | { 223 | const guint8 *data; 224 | 225 | data = gst_byte_reader_peek_data_unchecked (reader); 226 | gst_byte_reader_skip_unchecked (reader, size); 227 | return data; 228 | } 229 | 230 | static inline guint8 * 231 | gst_byte_reader_dup_data_unchecked (GstByteReader * reader, guint size) 232 | { 233 | gconstpointer data = gst_byte_reader_get_data_unchecked (reader, size); 234 | return (guint8 *) g_memdup (data, size); 235 | } 236 | 237 | /* Unchecked variants that should not be used */ 238 | static inline guint 239 | _gst_byte_reader_get_pos_unchecked (const GstByteReader * reader) 240 | { 241 | return reader->byte; 242 | } 243 | 244 | static inline guint 245 | _gst_byte_reader_get_remaining_unchecked (const GstByteReader * reader) 246 | { 247 | return reader->size - reader->byte; 248 | } 249 | 250 | static inline guint 251 | _gst_byte_reader_get_size_unchecked (const GstByteReader * reader) 252 | { 253 | return reader->size; 254 | } 255 | 256 | /* inlined variants (do not use directly) */ 257 | 258 | static inline guint 259 | _gst_byte_reader_get_remaining_inline (const GstByteReader * reader) 260 | { 261 | g_return_val_if_fail (reader != NULL, 0); 262 | 263 | return _gst_byte_reader_get_remaining_unchecked (reader); 264 | } 265 | 266 | static inline guint 267 | _gst_byte_reader_get_size_inline (const GstByteReader * reader) 268 | { 269 | g_return_val_if_fail (reader != NULL, 0); 270 | 271 | return _gst_byte_reader_get_size_unchecked (reader); 272 | } 273 | 274 | #define __GST_BYTE_READER_GET_PEEK_BITS_INLINE(bits,type,name) \ 275 | \ 276 | static inline gboolean \ 277 | _gst_byte_reader_peek_##name##_inline (const GstByteReader * reader, type * val) \ 278 | { \ 279 | g_return_val_if_fail (reader != NULL, FALSE); \ 280 | g_return_val_if_fail (val != NULL, FALSE); \ 281 | \ 282 | if (_gst_byte_reader_get_remaining_unchecked (reader) < (bits / 8)) \ 283 | return FALSE; \ 284 | \ 285 | *val = gst_byte_reader_peek_##name##_unchecked (reader); \ 286 | return TRUE; \ 287 | } \ 288 | \ 289 | static inline gboolean \ 290 | _gst_byte_reader_get_##name##_inline (GstByteReader * reader, type * val) \ 291 | { \ 292 | g_return_val_if_fail (reader != NULL, FALSE); \ 293 | g_return_val_if_fail (val != NULL, FALSE); \ 294 | \ 295 | if (_gst_byte_reader_get_remaining_unchecked (reader) < (bits / 8)) \ 296 | return FALSE; \ 297 | \ 298 | *val = gst_byte_reader_get_##name##_unchecked (reader); \ 299 | return TRUE; \ 300 | } 301 | 302 | __GST_BYTE_READER_GET_PEEK_BITS_INLINE(8,guint8,uint8) 303 | __GST_BYTE_READER_GET_PEEK_BITS_INLINE(8,gint8,int8) 304 | 305 | __GST_BYTE_READER_GET_PEEK_BITS_INLINE(16,guint16,uint16_le) 306 | __GST_BYTE_READER_GET_PEEK_BITS_INLINE(16,guint16,uint16_be) 307 | __GST_BYTE_READER_GET_PEEK_BITS_INLINE(16,gint16,int16_le) 308 | __GST_BYTE_READER_GET_PEEK_BITS_INLINE(16,gint16,int16_be) 309 | 310 | __GST_BYTE_READER_GET_PEEK_BITS_INLINE(32,guint32,uint32_le) 311 | __GST_BYTE_READER_GET_PEEK_BITS_INLINE(32,guint32,uint32_be) 312 | __GST_BYTE_READER_GET_PEEK_BITS_INLINE(32,gint32,int32_le) 313 | __GST_BYTE_READER_GET_PEEK_BITS_INLINE(32,gint32,int32_be) 314 | 315 | __GST_BYTE_READER_GET_PEEK_BITS_INLINE(24,guint32,uint24_le) 316 | __GST_BYTE_READER_GET_PEEK_BITS_INLINE(24,guint32,uint24_be) 317 | __GST_BYTE_READER_GET_PEEK_BITS_INLINE(24,gint32,int24_le) 318 | __GST_BYTE_READER_GET_PEEK_BITS_INLINE(24,gint32,int24_be) 319 | 320 | __GST_BYTE_READER_GET_PEEK_BITS_INLINE(64,guint64,uint64_le) 321 | __GST_BYTE_READER_GET_PEEK_BITS_INLINE(64,guint64,uint64_be) 322 | __GST_BYTE_READER_GET_PEEK_BITS_INLINE(64,gint64,int64_le) 323 | __GST_BYTE_READER_GET_PEEK_BITS_INLINE(64,gint64,int64_be) 324 | 325 | __GST_BYTE_READER_GET_PEEK_BITS_INLINE(32,gfloat,float32_le) 326 | __GST_BYTE_READER_GET_PEEK_BITS_INLINE(32,gfloat,float32_be) 327 | __GST_BYTE_READER_GET_PEEK_BITS_INLINE(64,gdouble,float64_le) 328 | __GST_BYTE_READER_GET_PEEK_BITS_INLINE(64,gdouble,float64_be) 329 | 330 | #undef __GST_BYTE_READER_GET_PEEK_BITS_INLINE 331 | 332 | #ifndef GST_BYTE_READER_DISABLE_INLINES 333 | 334 | #define gst_byte_reader_init(reader,data,size) \ 335 | _gst_byte_reader_init_inline(reader,data,size) 336 | 337 | #define gst_byte_reader_get_remaining(reader) \ 338 | _gst_byte_reader_get_remaining_inline(reader) 339 | 340 | #define gst_byte_reader_get_size(reader) \ 341 | _gst_byte_reader_get_size_inline(reader) 342 | 343 | #define gst_byte_reader_get_pos(reader) \ 344 | _gst_byte_reader_get_pos_inline(reader) 345 | 346 | /* we use defines here so we can add the G_LIKELY() */ 347 | #define gst_byte_reader_get_uint8(reader,val) \ 348 | G_LIKELY(_gst_byte_reader_get_uint8_inline(reader,val)) 349 | #define gst_byte_reader_get_int8(reader,val) \ 350 | G_LIKELY(_gst_byte_reader_get_int8_inline(reader,val)) 351 | #define gst_byte_reader_get_uint16_le(reader,val) \ 352 | G_LIKELY(_gst_byte_reader_get_uint16_le_inline(reader,val)) 353 | #define gst_byte_reader_get_int16_le(reader,val) \ 354 | G_LIKELY(_gst_byte_reader_get_int16_le_inline(reader,val)) 355 | #define gst_byte_reader_get_uint16_be(reader,val) \ 356 | G_LIKELY(_gst_byte_reader_get_uint16_be_inline(reader,val)) 357 | #define gst_byte_reader_get_int16_be(reader,val) \ 358 | G_LIKELY(_gst_byte_reader_get_int16_be_inline(reader,val)) 359 | #define gst_byte_reader_get_uint24_le(reader,val) \ 360 | G_LIKELY(_gst_byte_reader_get_uint24_le_inline(reader,val)) 361 | #define gst_byte_reader_get_int24_le(reader,val) \ 362 | G_LIKELY(_gst_byte_reader_get_int24_le_inline(reader,val)) 363 | #define gst_byte_reader_get_uint24_be(reader,val) \ 364 | G_LIKELY(_gst_byte_reader_get_uint24_be_inline(reader,val)) 365 | #define gst_byte_reader_get_int24_be(reader,val) \ 366 | G_LIKELY(_gst_byte_reader_get_int24_be_inline(reader,val)) 367 | #define gst_byte_reader_get_uint32_le(reader,val) \ 368 | G_LIKELY(_gst_byte_reader_get_uint32_le_inline(reader,val)) 369 | #define gst_byte_reader_get_int32_le(reader,val) \ 370 | G_LIKELY(_gst_byte_reader_get_int32_le_inline(reader,val)) 371 | #define gst_byte_reader_get_uint32_be(reader,val) \ 372 | G_LIKELY(_gst_byte_reader_get_uint32_be_inline(reader,val)) 373 | #define gst_byte_reader_get_int32_be(reader,val) \ 374 | G_LIKELY(_gst_byte_reader_get_int32_be_inline(reader,val)) 375 | #define gst_byte_reader_get_uint64_le(reader,val) \ 376 | G_LIKELY(_gst_byte_reader_get_uint64_le_inline(reader,val)) 377 | #define gst_byte_reader_get_int64_le(reader,val) \ 378 | G_LIKELY(_gst_byte_reader_get_int64_le_inline(reader,val)) 379 | #define gst_byte_reader_get_uint64_be(reader,val) \ 380 | G_LIKELY(_gst_byte_reader_get_uint64_be_inline(reader,val)) 381 | #define gst_byte_reader_get_int64_be(reader,val) \ 382 | G_LIKELY(_gst_byte_reader_get_int64_be_inline(reader,val)) 383 | 384 | #define gst_byte_reader_peek_uint8(reader,val) \ 385 | G_LIKELY(_gst_byte_reader_peek_uint8_inline(reader,val)) 386 | #define gst_byte_reader_peek_int8(reader,val) \ 387 | G_LIKELY(_gst_byte_reader_peek_int8_inline(reader,val)) 388 | #define gst_byte_reader_peek_uint16_le(reader,val) \ 389 | G_LIKELY(_gst_byte_reader_peek_uint16_le_inline(reader,val)) 390 | #define gst_byte_reader_peek_int16_le(reader,val) \ 391 | G_LIKELY(_gst_byte_reader_peek_int16_le_inline(reader,val)) 392 | #define gst_byte_reader_peek_uint16_be(reader,val) \ 393 | G_LIKELY(_gst_byte_reader_peek_uint16_be_inline(reader,val)) 394 | #define gst_byte_reader_peek_int16_be(reader,val) \ 395 | G_LIKELY(_gst_byte_reader_peek_int16_be_inline(reader,val)) 396 | #define gst_byte_reader_peek_uint24_le(reader,val) \ 397 | G_LIKELY(_gst_byte_reader_peek_uint24_le_inline(reader,val)) 398 | #define gst_byte_reader_peek_int24_le(reader,val) \ 399 | G_LIKELY(_gst_byte_reader_peek_int24_le_inline(reader,val)) 400 | #define gst_byte_reader_peek_uint24_be(reader,val) \ 401 | G_LIKELY(_gst_byte_reader_peek_uint24_be_inline(reader,val)) 402 | #define gst_byte_reader_peek_int24_be(reader,val) \ 403 | G_LIKELY(_gst_byte_reader_peek_int24_be_inline(reader,val)) 404 | #define gst_byte_reader_peek_uint32_le(reader,val) \ 405 | G_LIKELY(_gst_byte_reader_peek_uint32_le_inline(reader,val)) 406 | #define gst_byte_reader_peek_int32_le(reader,val) \ 407 | G_LIKELY(_gst_byte_reader_peek_int32_le_inline(reader,val)) 408 | #define gst_byte_reader_peek_uint32_be(reader,val) \ 409 | G_LIKELY(_gst_byte_reader_peek_uint32_be_inline(reader,val)) 410 | #define gst_byte_reader_peek_int32_be(reader,val) \ 411 | G_LIKELY(_gst_byte_reader_peek_int32_be_inline(reader,val)) 412 | #define gst_byte_reader_peek_uint64_le(reader,val) \ 413 | G_LIKELY(_gst_byte_reader_peek_uint64_le_inline(reader,val)) 414 | #define gst_byte_reader_peek_int64_le(reader,val) \ 415 | G_LIKELY(_gst_byte_reader_peek_int64_le_inline(reader,val)) 416 | #define gst_byte_reader_peek_uint64_be(reader,val) \ 417 | G_LIKELY(_gst_byte_reader_peek_uint64_be_inline(reader,val)) 418 | #define gst_byte_reader_peek_int64_be(reader,val) \ 419 | G_LIKELY(_gst_byte_reader_peek_int64_be_inline(reader,val)) 420 | 421 | #define gst_byte_reader_get_float32_le(reader,val) \ 422 | G_LIKELY(_gst_byte_reader_get_float32_le_inline(reader,val)) 423 | #define gst_byte_reader_get_float32_be(reader,val) \ 424 | G_LIKELY(_gst_byte_reader_get_float32_be_inline(reader,val)) 425 | #define gst_byte_reader_get_float64_le(reader,val) \ 426 | G_LIKELY(_gst_byte_reader_get_float64_le_inline(reader,val)) 427 | #define gst_byte_reader_get_float64_be(reader,val) \ 428 | G_LIKELY(_gst_byte_reader_get_float64_be_inline(reader,val)) 429 | #define gst_byte_reader_peek_float32_le(reader,val) \ 430 | G_LIKELY(_gst_byte_reader_peek_float32_le_inline(reader,val)) 431 | #define gst_byte_reader_peek_float32_be(reader,val) \ 432 | G_LIKELY(_gst_byte_reader_peek_float32_be_inline(reader,val)) 433 | #define gst_byte_reader_peek_float64_le(reader,val) \ 434 | G_LIKELY(_gst_byte_reader_peek_float64_le_inline(reader,val)) 435 | #define gst_byte_reader_peek_float64_be(reader,val) \ 436 | G_LIKELY(_gst_byte_reader_peek_float64_be_inline(reader,val)) 437 | 438 | #endif /* GST_BYTE_READER_DISABLE_INLINES */ 439 | 440 | static inline void 441 | _gst_byte_reader_init_inline (GstByteReader * reader, const guint8 * data, guint size) 442 | { 443 | g_return_if_fail (reader != NULL); 444 | 445 | reader->data = data; 446 | reader->size = size; 447 | reader->byte = 0; 448 | } 449 | 450 | static inline gboolean 451 | _gst_byte_reader_dup_data_inline (GstByteReader * reader, guint size, guint8 ** val) 452 | { 453 | g_return_val_if_fail (reader != NULL, FALSE); 454 | g_return_val_if_fail (val != NULL, FALSE); 455 | 456 | if (G_UNLIKELY (size > reader->size || _gst_byte_reader_get_remaining_inline (reader) < size)) 457 | return FALSE; 458 | 459 | *val = gst_byte_reader_dup_data_unchecked (reader, size); 460 | return TRUE; 461 | } 462 | 463 | static inline gboolean 464 | _gst_byte_reader_get_data_inline (GstByteReader * reader, guint size, const guint8 ** val) 465 | { 466 | g_return_val_if_fail (reader != NULL, FALSE); 467 | g_return_val_if_fail (val != NULL, FALSE); 468 | 469 | if (G_UNLIKELY (size > reader->size || _gst_byte_reader_get_remaining_inline (reader) < size)) 470 | return FALSE; 471 | 472 | *val = gst_byte_reader_get_data_unchecked (reader, size); 473 | return TRUE; 474 | } 475 | 476 | static inline gboolean 477 | _gst_byte_reader_peek_data_inline (const GstByteReader * reader, guint size, const guint8 ** val) 478 | { 479 | g_return_val_if_fail (reader != NULL, FALSE); 480 | g_return_val_if_fail (val != NULL, FALSE); 481 | 482 | if (G_UNLIKELY (size > reader->size || _gst_byte_reader_get_remaining_inline (reader) < size)) 483 | return FALSE; 484 | 485 | *val = gst_byte_reader_peek_data_unchecked (reader); 486 | return TRUE; 487 | } 488 | 489 | static inline guint 490 | _gst_byte_reader_get_pos_inline (const GstByteReader * reader) 491 | { 492 | g_return_val_if_fail (reader != NULL, 0); 493 | 494 | return _gst_byte_reader_get_pos_unchecked (reader); 495 | } 496 | 497 | static inline gboolean 498 | _gst_byte_reader_skip_inline (GstByteReader * reader, guint nbytes) 499 | { 500 | g_return_val_if_fail (reader != NULL, FALSE); 501 | 502 | if (G_UNLIKELY (_gst_byte_reader_get_remaining_unchecked (reader) < nbytes)) 503 | return FALSE; 504 | 505 | reader->byte += nbytes; 506 | return TRUE; 507 | } 508 | 509 | #ifndef GST_BYTE_READER_DISABLE_INLINES 510 | 511 | #define gst_byte_reader_dup_data(reader,size,val) \ 512 | G_LIKELY(_gst_byte_reader_dup_data_inline(reader,size,val)) 513 | #define gst_byte_reader_get_data(reader,size,val) \ 514 | G_LIKELY(_gst_byte_reader_get_data_inline(reader,size,val)) 515 | #define gst_byte_reader_peek_data(reader,size,val) \ 516 | G_LIKELY(_gst_byte_reader_peek_data_inline(reader,size,val)) 517 | #define gst_byte_reader_skip(reader,nbytes) \ 518 | G_LIKELY(_gst_byte_reader_skip_inline(reader,nbytes)) 519 | 520 | #endif /* GST_BYTE_READER_DISABLE_INLINES */ 521 | 522 | G_END_DECLS 523 | 524 | #endif /* __GST_BYTE_READER_H__ */ 525 | -------------------------------------------------------------------------------- /gsth265parser.h: -------------------------------------------------------------------------------- 1 | /* Gstreamer H.265 bitstream parser 2 | * Copyright (C) 2013 Intel Corporation 3 | * Copyright (C) 2013 Sreerenj Balachandran 4 | * 5 | * Contact: Sreerenj Balachandran 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License, version 2.1, as published by the Free Software Foundation. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program. If not, see 18 | * . 19 | */ 20 | 21 | #ifndef __GST_H265_PARSER_H__ 22 | #define __GST_H265_PARSER_H__ 23 | 24 | #ifndef GST_USE_UNSTABLE_API 25 | #warning "The H.265 parsing library is unstable API and may change in future." 26 | #warning "You can define GST_USE_UNSTABLE_API to avoid this warning." 27 | #endif 28 | 29 | #include 30 | 31 | G_BEGIN_DECLS 32 | 33 | #define GST_H265_MAX_SUB_LAYERS 8 34 | #define GST_H265_MAX_VPS_COUNT 16 35 | #define GST_H265_MAX_SPS_COUNT 16 36 | #define GST_H265_MAX_PPS_COUNT 64 37 | 38 | #define GST_H265_IS_B_SLICE(slice) ((slice)->type == GST_H265_B_SLICE) 39 | #define GST_H265_IS_P_SLICE(slice) ((slice)->type == GST_H265_P_SLICE) 40 | #define GST_H265_IS_I_SLICE(slice) ((slice)->type == GST_H265_I_SLICE) 41 | 42 | #ifdef GST_WARNING 43 | #undef GST_WARNING 44 | #define GST_WARNING printf 45 | #endif 46 | 47 | #ifdef GST_DEBUG 48 | #undef GST_DEBUG 49 | #define GST_DEBUG printf 50 | #endif 51 | 52 | #define READ_UE_MAX(nr, val, max) { \ 53 | guint32 tmp; \ 54 | READ_UE (nr, tmp); \ 55 | CHECK_ALLOWED_MAX (tmp, max); \ 56 | val = tmp; \ 57 | } 58 | 59 | #define CHECK_ALLOWED_MAX(val, max) { \ 60 | if (val > max) { \ 61 | GST_WARNING ("value greater than max. value: %d, max %d", \ 62 | val, max); \ 63 | goto error; \ 64 | } \ 65 | } 66 | 67 | /** 68 | * GstH265Profile: 69 | * @GST_H265_PROFILE_MAIN: Main profile (A.3.2) 70 | * @GST_H265_PROFILE_MAIN_10: Main 10 profile (A.3.3) 71 | * @GST_H265_PROFILE_MAIN_STILL_PICTURE: Main Still Picture profile (A.3.4) 72 | * 73 | * H.265 Profiles. 74 | * 75 | */ 76 | typedef enum { 77 | GST_H265_PROFILE_MAIN = 1, 78 | GST_H265_PROFILE_MAIN_10 = 2, 79 | GST_H265_PROFILE_MAIN_STILL_PICTURE = 3 80 | } GstH265Profile; 81 | 82 | /** 83 | * GstH265NalUnitType: 84 | * @GST_H265_NAL_SLICE_TRAIL_N: Slice nal of a non-TSA, non-STSA trailing picture 85 | * @GST_H265_NAL_SLICE_TRAIL_R: Slice nal of a non-TSA, non-STSA trailing picture 86 | * @GST_H265_NAL_SLICE_TSA_N: Slice nal of a TSA picture 87 | * @GST_H265_NAL_SLICE_TSA_R: Slice nal of a TSA picture 88 | * @GST_H265_NAL_SLICE_STSA_N: Slice nal of a STSA picture 89 | * @GST_H265_NAL_SLICE_STSA_R: Slice nal of a STSA picture 90 | * @GST_H265_NAL_SLICE_RADL_N: Slice nal of a RADL picture 91 | * @GST_H265_NAL_SLICE_RADL_R: Slice nal of a RADL piicture 92 | * @GST_H265_NAL_SLICE_RASL_N: Slice nal of a RASL picture 93 | * @GST_H265_NAL_SLICE_RASL_R: Slice nal of a RASL picture 94 | * @GST_H265_NAL_SLICE_BLA_W_LP: Slice nal of a BLA picture 95 | * @GST_H265_NAL_SLICE_BLA_W_RADL: Slice nal of a BLA picture 96 | * @GST_H265_NAL_SLICE_BLA_N_LP: Slice nal of a BLA picture 97 | * @GST_H265_NAL_SLICE_IDR_W_RADL: Slice nal of an IDR picture 98 | * @GST_H265_NAL_SLICE_IDR_N_LP: Slice nal of an IDR picture 99 | * @GST_H265_NAL_SLICE_CRA_NUT: Slice nal of a CRA picture 100 | * @GST_H265_NAL_VPS: Video parameter set(VPS) nal unit 101 | * @GST_H265_NAL_SPS: Sequence parameter set (SPS) nal unit 102 | * @GST_H265_NAL_PPS: Picture parameter set (PPS) nal unit 103 | * @GST_H265_NAL_AUD: Access unit (AU) delimiter nal unit 104 | * @GST_H265_NAL_EOS: End of sequence (EOS) nal unit 105 | * @GST_H265_NAL_EOB: End of bitstream (EOB) nal unit 106 | * @GST_H265_NAL_FD: Filler data (FD) nal lunit 107 | * @GST_H265_NAL_PREFIX_SEI: Supplemental enhancement information prefix nal unit 108 | * @GST_H265_NAL_SUFFIX_SEI: Suppliemental enhancement information suffix nal unit 109 | * 110 | * Indicates the type of H265 Nal Units 111 | */ 112 | typedef enum 113 | { 114 | GST_H265_NAL_SLICE_TRAIL_N = 0, 115 | GST_H265_NAL_SLICE_TRAIL_R = 1, 116 | GST_H265_NAL_SLICE_TSA_N = 2, 117 | GST_H265_NAL_SLICE_TSA_R = 3, 118 | GST_H265_NAL_SLICE_STSA_N = 4, 119 | GST_H265_NAL_SLICE_STSA_R = 5, 120 | GST_H265_NAL_SLICE_RADL_N = 6, 121 | GST_H265_NAL_SLICE_RADL_R = 7, 122 | GST_H265_NAL_SLICE_RASL_N = 8, 123 | GST_H265_NAL_SLICE_RASL_R = 9, 124 | GST_H265_NAL_SLICE_BLA_W_LP = 16, 125 | GST_H265_NAL_SLICE_BLA_W_RADL = 17, 126 | GST_H265_NAL_SLICE_BLA_N_LP = 18, 127 | GST_H265_NAL_SLICE_IDR_W_RADL = 19, 128 | GST_H265_NAL_SLICE_IDR_N_LP = 20, 129 | GST_H265_NAL_SLICE_CRA_NUT = 21, 130 | GST_H265_NAL_VPS = 32, 131 | GST_H265_NAL_SPS = 33, 132 | GST_H265_NAL_PPS = 34, 133 | GST_H265_NAL_AUD = 35, 134 | GST_H265_NAL_EOS = 36, 135 | GST_H265_NAL_EOB = 37, 136 | GST_H265_NAL_FD = 38, 137 | GST_H265_NAL_PREFIX_SEI = 39, 138 | GST_H265_NAL_SUFFIX_SEI = 40 139 | } GstH265NalUnitType; 140 | 141 | #define RESERVED_NON_IRAP_SUBLAYER_NAL_TYPE_MIN 10 142 | #define RESERVED_NON_IRAP_SUBLAYER_NAL_TYPE_MAX 15 143 | 144 | #define RESERVED_IRAP_NAL_TYPE_MIN 22 145 | #define RESERVED_IRAP_NAL_TYPE_MAX 23 146 | 147 | #define RESERVED_NON_IRAP_NAL_TYPE_MIN 24 148 | #define RESERVED_NON_IRAP_NAL_TYPE_MAX 31 149 | 150 | #define RESERVED_NON_VCL_NAL_TYPE_MIN 41 151 | #define RESERVED_NON_VCL_NAL_TYPE_MAX 47 152 | 153 | #define UNSPECIFIED_NON_VCL_NAL_TYPE_MIN 48 154 | #define UNSPECIFIED_NON_VCL_NAL_TYPE_MAX 63 155 | 156 | /** 157 | * GstH265ParserResult: 158 | * @GST_H265_PARSER_OK: The parsing succeded 159 | * @GST_H265_PARSER_BROKEN_DATA: The data to parse is broken 160 | * @GST_H265_PARSER_BROKEN_LINK: The link to structure needed for the parsing couldn't be found 161 | * @GST_H265_PARSER_ERROR: An error accured when parsing 162 | * @GST_H265_PARSER_NO_NAL: No nal found during the parsing 163 | * @GST_H265_PARSER_NO_NAL_END: Start of the nal found, but not the end. 164 | * 165 | * The result of parsing H265 data. 166 | */ 167 | typedef enum 168 | { 169 | GST_H265_PARSER_OK, 170 | GST_H265_PARSER_BROKEN_DATA, 171 | GST_H265_PARSER_BROKEN_LINK, 172 | GST_H265_PARSER_ERROR, 173 | GST_H265_PARSER_NO_NAL, 174 | GST_H265_PARSER_NO_NAL_END 175 | } GstH265ParserResult; 176 | 177 | /** 178 | * GstH265SEIPayloadType: 179 | * @GST_H265_SEI_BUF_PERIOD: Buffering Period SEI Message 180 | * @GST_H265_SEI_PIC_TIMING: Picture Timing SEI Message 181 | * ... 182 | * 183 | * The type of SEI message. 184 | */ 185 | typedef enum 186 | { 187 | GST_H265_SEI_BUF_PERIOD = 0, 188 | GST_H265_SEI_PIC_TIMING = 1 189 | /* and more... */ 190 | } GstH265SEIPayloadType; 191 | 192 | /** 193 | * GstH265SEIPicStructType: 194 | * @GST_H265_SEI_PIC_STRUCT_FRAME: Picture is a frame 195 | * @GST_H265_SEI_PIC_STRUCT_TOP_FIELD: Top field of frame 196 | * @GST_H265_SEI_PIC_STRUCT_BOTTOM_FIELD: Botom field of frame 197 | * @GST_H265_SEI_PIC_STRUCT_TOP_BOTTOM: Top bottom field of frame 198 | * @GST_H265_SEI_PIC_STRUCT_BOTTOM_TOP: bottom top field of frame 199 | * @GST_H265_SEI_PIC_STRUCT_TOP_BOTTOM_TOP: top bottom top field of frame 200 | * @GST_H265_SEI_PIC_STRUCT_BOTTOM_TOP_BOTTOM: bottom top bottom field of frame 201 | * @GST_H265_SEI_PIC_STRUCT_FRAME_DOUBLING: indicates that the frame should 202 | * be displayed two times consecutively 203 | * @GST_H265_SEI_PIC_STRUCT_FRAME_TRIPLING: indicates that the frame should be 204 | * displayed three times consecutively 205 | * @GST_H265_SEI_PIC_STRUCT_TOP_PAIRED_PREVIOUS_BOTTOM: top field paired with 206 | * previous bottom field in output order 207 | * @GST_H265_SEI_PIC_STRUCT_BOTTOM_PAIRED_PREVIOUS_TOP: bottom field paried with 208 | * previous top field in output order 209 | * @GST_H265_SEI_PIC_STRUCT_TOP_PAIRED_NEXT_BOTTOM: top field paired with next 210 | * bottom field in output order 211 | * @GST_H265_SEI_PIC_STRUCT_BOTTOM_PAIRED_NEXT_TOP: bottom field paired with 212 | * next top field in output order 213 | * 214 | * SEI pic_struct type 215 | */ 216 | typedef enum 217 | { 218 | GST_H265_SEI_PIC_STRUCT_FRAME = 0, 219 | GST_H265_SEI_PIC_STRUCT_TOP_FIELD = 1, 220 | GST_H265_SEI_PIC_STRUCT_BOTTOM_FIELD = 2, 221 | GST_H265_SEI_PIC_STRUCT_TOP_BOTTOM = 3, 222 | GST_H265_SEI_PIC_STRUCT_BOTTOM_TOP = 4, 223 | GST_H265_SEI_PIC_STRUCT_TOP_BOTTOM_TOP = 5, 224 | GST_H265_SEI_PIC_STRUCT_BOTTOM_TOP_BOTTOM = 6, 225 | GST_H265_SEI_PIC_STRUCT_FRAME_DOUBLING = 7, 226 | GST_H265_SEI_PIC_STRUCT_FRAME_TRIPLING = 8, 227 | GST_H265_SEI_PIC_STRUCT_TOP_PAIRED_PREVIOUS_BOTTOM = 9, 228 | GST_H265_SEI_PIC_STRUCT_BOTTOM_PAIRED_PREVIOUS_TOP = 10, 229 | GST_H265_SEI_PIC_STRUCT_TOP_PAIRED_NEXT_BOTTOM = 11, 230 | GST_H265_SEI_PIC_STRUCT_BOTTOM_PAIRED_NEXT_TOP = 12 231 | } GstH265SEIPicStructType; 232 | 233 | /** 234 | * GstH265SliceType: 235 | * 236 | * Type of Picture slice 237 | */ 238 | 239 | typedef enum 240 | { 241 | GST_H265_B_SLICE = 0, 242 | GST_H265_P_SLICE = 1, 243 | GST_H265_I_SLICE = 2 244 | } GstH265SliceType; 245 | 246 | typedef enum 247 | { 248 | GST_H265_QUANT_MATIX_4X4 = 0, 249 | GST_H265_QUANT_MATIX_8X8 = 1, 250 | GST_H265_QUANT_MATIX_16X16 = 2, 251 | GST_H265_QUANT_MATIX_32X32 = 3 252 | } GstH265QuantMatrixSize; 253 | 254 | typedef struct _GstH265Parser GstH265Parser; 255 | 256 | typedef struct _GstH265NalUnit GstH265NalUnit; 257 | 258 | typedef struct _GstH265VPS GstH265VPS; 259 | typedef struct _GstH265SPS GstH265SPS; 260 | typedef struct _GstH265PPS GstH265PPS; 261 | typedef struct _GstH265ProfileTierLevel GstH265ProfileTierLevel; 262 | typedef struct _GstH265SubLayerHRDParams GstH265SubLayerHRDParams; 263 | typedef struct _GstH265HRDParams GstH265HRDParams; 264 | typedef struct _GstH265VUIParams GstH265VUIParams; 265 | 266 | typedef struct _GstH265ScalingList GstH265ScalingList; 267 | typedef struct _GstH265RefPicListModification GstH265RefPicListModification; 268 | typedef struct _GstH265PredWeightTable GstH265PredWeightTable; 269 | typedef struct _GstH265ShortTermRefPicSet GstH265ShortTermRefPicSet; 270 | typedef struct _GstH265SliceHdr GstH265SliceHdr; 271 | 272 | typedef struct _GstH265PicTiming GstH265PicTiming; 273 | typedef struct _GstH265BufferingPeriod GstH265BufferingPeriod; 274 | typedef struct _GstH265SEIMessage GstH265SEIMessage; 275 | 276 | /** 277 | * GstH265NalUnit: 278 | * @type: A #GstH265NalUnitType 279 | * @layer_id: A nal unit layer id 280 | * @temporal_id_plus1: A nal unit temporal identifier 281 | * @size: The size of the nal unit starting from @offset 282 | * @offset: The offset of the actual start of the nal unit 283 | * @sc_offset:The offset of the start code of the nal unit 284 | * @valid: If the nal unit is valid, which mean it has 285 | * already been parsed 286 | * @data: The data from which the Nalu has been parsed 287 | * 288 | * Structure defining the Nal unit headers 289 | */ 290 | struct _GstH265NalUnit 291 | { 292 | guint8 type; 293 | guint8 layer_id; 294 | guint8 temporal_id_plus1; 295 | 296 | /* calculated values */ 297 | guint size; 298 | guint offset; 299 | guint sc_offset; 300 | gboolean valid; 301 | 302 | guint8 *data; 303 | guint8 header_bytes; 304 | }; 305 | 306 | /** 307 | * GstH265ProfileTierLevel: 308 | * @profile_space: specifies the context for the interpretation of 309 | * general_profile_idc and general_profile_combatibility_flag 310 | * @tier_flag: the tier context for the interpretation of general_level_idc 311 | * @profile_idc: profile id 312 | * @profile_compatibility_flag: compatibility flags 313 | * @progressive_source_flag: flag to indicate the type of stream 314 | * @interlaced_source_flag: flag to indicate the type of stream 315 | * @non_packed_constraint_flag: indicate the presence of frame packing 316 | * arragement sei message 317 | * @frame_only_constraint_flag: recognize the field_seq_flag 318 | * @level idc: indicate the level which the CVS confirms 319 | * @sub_layer_profile_present_flag: sublayer profile presence ind 320 | * @sub_layer_level_present_flag:sublayer level presence indicator. 321 | * @sub_layer_profile_space: profile space for sublayers 322 | * @sub_layer_tier_flag: tier flags for sublayers. 323 | * @sub_layer_profile_idc: conformant profile indicator for sublayers. 324 | * @sub_layer_profile_compatibility_flag[6][32]: compatibility flags for sublayers 325 | * @sub_layer_progressive_source_flag:progressive stream indicator for sublayer 326 | * @sub_layer_interlaced_source_flag: interlaced stream indicator for sublayer 327 | * @sub_layer_non_packed_constraint_flag: indicate the presence of 328 | * frame packing arrangement sei message with in sublayers 329 | * @sub_layer_frame_only_constraint_flag:recognize the sublayer 330 | * specific field_seq_flag 331 | * @sub_layer_level_idc:indicate the sublayer specific level 332 | * 333 | * Define ProfileTierLevel parameters 334 | */ 335 | struct _GstH265ProfileTierLevel { 336 | guint8 profile_space; 337 | guint8 tier_flag; 338 | guint8 profile_idc; 339 | 340 | guint8 profile_compatibility_flag[32]; 341 | 342 | guint8 progressive_source_flag; 343 | guint8 interlaced_source_flag; 344 | guint8 non_packed_constraint_flag; 345 | guint8 frame_only_constraint_flag; 346 | guint8 level_idc; 347 | 348 | guint8 sub_layer_profile_present_flag[6]; 349 | guint8 sub_layer_level_present_flag[6]; 350 | 351 | guint8 sub_layer_profile_space[6]; 352 | guint8 sub_layer_tier_flag[6]; 353 | guint8 sub_layer_profile_idc[6]; 354 | guint8 sub_layer_profile_compatibility_flag[6][32]; 355 | guint8 sub_layer_progressive_source_flag[6]; 356 | guint8 sub_layer_interlaced_source_flag[6]; 357 | guint8 sub_layer_non_packed_constraint_flag[6]; 358 | guint8 sub_layer_frame_only_constraint_flag[6]; 359 | guint8 sub_layer_level_idc[6]; 360 | }; 361 | 362 | /** 363 | * GstH265SubLayerHRDParams: 364 | * @bit_rate_value_minus1:togeter with bit_rate_scale, it specifies 365 | * the maximum input bitrate when the CPB operates at the access 366 | * unit level 367 | * @cpb_size_value_minus1: is used together with cpb_size_scale to 368 | * specify the CPB size when the CPB operates at the access unit 369 | * level 370 | * @cpb_size_du_value_minus1: is used together with cpb_size_du_scale 371 | * to specify the CPB size when the CPB operates at sub-picture 372 | * level 373 | * @bit_rate_du_value_minus1: together with bit_rate_scale, it 374 | * specifies the maximum input bit rate when the CPB operates at the 375 | * sub-picture level 376 | * @cbr_flag: indicate whether HSS operates in intermittent bit rate 377 | * mode or constant bit rate mode. 378 | * 379 | * Defines the Sublayer HRD parameters 380 | */ 381 | struct _GstH265SubLayerHRDParams 382 | { 383 | guint32 bit_rate_value_minus1[32]; 384 | guint32 cpb_size_value_minus1[32]; 385 | 386 | guint32 cpb_size_du_value_minus1[32]; 387 | guint32 bit_rate_du_value_minus1[32]; 388 | 389 | guint8 cbr_flag[32]; 390 | }; 391 | 392 | /** 393 | * GstH265HRDParams: 394 | * @nal_hrd_parameters_present_flag: indicate the presence of NAL HRD parameters 395 | * @vcl_hrd_parameters_present_flag: indicate the presence of VCL HRD parameters 396 | * @sub_pic_hrd_params_present_flag: indicate the presence of sub_pic_hrd_params 397 | * @tick_divisor_minus2: is used to specify the clock sub-tick 398 | * @du_cpb_removal_delay_increment_length_minus1: specifies the length, 399 | * in bits, of the nal_initial_cpb_removal_delay 400 | * @sub_pic_cpb_params_in_pic_timing_sei_flag: specifies the length, in bits, of 401 | * the cpb_delay_offset and the au_cpb_removal_delay_minus1 syntax elements. 402 | * @dpb_output_delay_du_length_minu1: specifies the length, in bits, of the 403 | * dpb_delay_offset and the pic_dpb_output_delay syntax elements 404 | * @bit_rate_scale: maximum input bitrate 405 | * @cpb_size_scale: CPB size when operates in access unit level 406 | * @cpb_size_du_scale: CPB size when operates in sub-picture level 407 | * @initial_cpb_removal_delay_length_minus1: specifies the length, in bits, of the 408 | * nal_initial_cpb_removal_delay, nal_initial_cpb_removal_offset, 409 | * vcl_initial_cpb_removal_delay and vcl_initial_cpb_removal_offset. 410 | * @au_cpb_removal_delay_length_minus1: specifies the length, in bits, of the 411 | * cpb_delay_offset and the au_cpb_removal_delay_minus1 syntax elements 412 | * @dpb_output_delay_length_minus1: specifies the length, in bits, of the 413 | * dpb_delay_offset and the pic_dpb_output_delay syntax elements 414 | * @fixed_pic_rate_general_flag: flag to indicate the presence of constraint 415 | * on the temporal distance between the HRD output times of consecutive 416 | * pictures in output order 417 | * @fixed_pic_rate_within_cvs_flag: same as fixed_pic_rate_general_flag 418 | * @elemental_duration_in_tc_minus1: temporal distance in clock ticks 419 | * @low_delay_hrd_flag: specifies the HRD operational mode 420 | * @cpb_cnt_minus1:specifies the number of alternative CPS specifications. 421 | * @sublayer_hrd_params: Sublayer HRD parameters. 422 | * 423 | * Defines the HRD parameters 424 | */ 425 | struct _GstH265HRDParams 426 | { 427 | guint8 nal_hrd_parameters_present_flag; 428 | guint8 vcl_hrd_parameters_present_flag; 429 | guint8 sub_pic_hrd_params_present_flag; 430 | 431 | guint8 tick_divisor_minus2; 432 | guint8 du_cpb_removal_delay_increment_length_minus1; 433 | guint8 sub_pic_cpb_params_in_pic_timing_sei_flag; 434 | guint8 dpb_output_delay_du_length_minus1; 435 | 436 | guint8 bit_rate_scale; 437 | guint8 cpb_size_scale; 438 | guint8 cpb_size_du_scale; 439 | 440 | guint8 initial_cpb_removal_delay_length_minus1; 441 | guint8 au_cpb_removal_delay_length_minus1; 442 | guint8 dpb_output_delay_length_minus1; 443 | 444 | guint8 fixed_pic_rate_general_flag [7]; 445 | guint8 fixed_pic_rate_within_cvs_flag [7]; 446 | guint16 elemental_duration_in_tc_minus1 [7]; 447 | guint8 low_delay_hrd_flag [7]; 448 | guint8 cpb_cnt_minus1[7]; 449 | 450 | GstH265SubLayerHRDParams sublayer_hrd_params[7]; 451 | }; 452 | 453 | /** 454 | * GstH265VPS: 455 | * @id: vps id 456 | * @max_layers_minus1: should be zero, but can be other values in future 457 | * @max_sub_layers_minus1:specifies the maximum number of temporal sub-layers 458 | * @temporal_id_nesting_flag: specifies whether inter prediction is 459 | * additionally restricted 460 | * @profile_tier_level: ProfileTierLevel info 461 | * @sub_layer_ordering_info_present_flag: indicates the presense of 462 | * vps_max_dec_pic_buffering_minus1, vps_max_num_reorder_pics and 463 | * vps_max_latency_increase_plus1 464 | * @max_dec_pic_buffering_minus1: specifies the maximum required size 465 | * of the decoded picture buffer 466 | * @max_num_reorder_pics: indicates the maximum allowed number of 467 | * pictures that can precede any picture in the CVS in decoding 468 | * order 469 | * @max_latency_increase_plus1: is used to compute the value of 470 | * VpsMaxLatencyPictures 471 | * @max_layer_id: specifies the maximum allowed value of nuh_layer_id 472 | * @num_layer_sets_minus1: specifies the number of layer sets 473 | * @layer_id_included_flag: specifies whether a nuh_layer_id included 474 | * in the layer identifier list 475 | * @timing_info_present_flag: indicate the presence of 476 | * num_units_in_tick, time_scale, poc_proportional_to_timing_flag 477 | * and num_hrd_parameters 478 | * @num_units_in_tick: number of time units in a tick 479 | * @time_scale: number of time units that pass in one second 480 | * @poc_proportional_to_timing_flag: indicate whether the picture 481 | * order count is proportional to output timin 482 | * @num_ticks_poc_diff_one_minus1: specifies the number of clock ticks 483 | * corresponding to a difference of picture order count values equal 484 | * to 1 485 | * @num_hrd_parameters: number of hrd_parameters present 486 | * @hrd_layer_set_idx: index to the list of layer hrd params. 487 | * @hrd_params: the GstH265HRDParams list 488 | * 489 | * Defines the VPS parameters 490 | */ 491 | struct _GstH265VPS { 492 | guint8 id; 493 | 494 | guint8 max_layers_minus1; 495 | guint8 max_sub_layers_minus1; 496 | guint8 temporal_id_nesting_flag; 497 | 498 | GstH265ProfileTierLevel profile_tier_level; 499 | 500 | guint8 sub_layer_ordering_info_present_flag; 501 | guint8 max_dec_pic_buffering_minus1[GST_H265_MAX_SUB_LAYERS]; 502 | guint8 max_num_reorder_pics[GST_H265_MAX_SUB_LAYERS]; 503 | guint32 max_latency_increase_plus1[GST_H265_MAX_SUB_LAYERS]; 504 | 505 | guint8 max_layer_id; 506 | guint16 num_layer_sets_minus1; 507 | 508 | guint8 timing_info_present_flag; 509 | guint32 num_units_in_tick; 510 | guint32 time_scale; 511 | guint8 poc_proportional_to_timing_flag; 512 | guint32 num_ticks_poc_diff_one_minus1; 513 | 514 | guint16 num_hrd_parameters; 515 | guint16 hrd_layer_set_idx; 516 | guint8 cprms_present_flag; 517 | 518 | GstH265HRDParams hrd_params; 519 | 520 | guint8 vps_extension; 521 | 522 | gboolean valid; 523 | }; 524 | /** 525 | * GstH265ShortTermRefPicSet: 526 | * @inter_ref_pic_set_prediction_flag: %TRUE specifies that the stRpsIdx-th candidate 527 | * short-term RPS is predicted from another candidate short-term RPS 528 | * @delta_idx_minus1: plus 1 specifies the difference between the value of source and 529 | * candidate short term RPS. 530 | * @delta_rps_sign: delta_rps_sign and abs_delta_rps_minus1 together specify 531 | * the value of the variable deltaRps. 532 | * @abs_delta_rps_minus1: delta_rps_sign and abs_delta_rps_minus1 together specify 533 | * the value of the variable deltaRps 534 | * 535 | * Defines the #GstH265ShortTermRefPicSet params 536 | */ 537 | struct _GstH265ShortTermRefPicSet 538 | { 539 | guint8 inter_ref_pic_set_prediction_flag; 540 | guint8 delta_idx_minus1; 541 | guint8 delta_rps_sign; 542 | guint16 abs_delta_rps_minus1; 543 | 544 | /* calculated values */ 545 | guint8 NumDeltaPocs; 546 | guint8 NumNegativePics; 547 | guint8 NumPositivePics; 548 | guint8 UsedByCurrPicS0[16]; 549 | guint8 UsedByCurrPicS1[16]; 550 | gint32 DeltaPocS0[16]; 551 | gint32 DeltaPocS1[16]; 552 | }; 553 | 554 | /** 555 | * GstH265VUIParams: 556 | * @aspect_ratio_info_present_flag: %TRUE specifies that aspect_ratio_idc is present. 557 | * %FALSE specifies that aspect_ratio_idc is not present 558 | * @aspect_ratio_idc specifies the value of the sample aspect ratio of the luma samples 559 | * @sar_width indicates the horizontal size of the sample aspect ratio 560 | * @sar_height indicates the vertical size of the sample aspect ratio 561 | * @overscan_info_present_flag: %TRUE overscan_appropriate_flag is present %FALSE otherwize 562 | * @overscan_appropriate_flag: %TRUE indicates that the cropped decoded pictures 563 | * output are suitable for display using overscan. %FALSE the cropped decoded pictures 564 | * output contain visually important information 565 | * @video_signal_type_present_flag: %TRUE specifies that video_format, video_full_range_flag and 566 | * colour_description_present_flag are present. 567 | * @video_format: indicates the representation of the picture 568 | * @video_full_range_flag: indicates the black level and range of the luma and chroma signals 569 | * @colour_description_present_flag: %TRUE specifies that colour_primaries, 570 | * transfer_characteristics and matrix_coefficients are present 571 | * @colour_primaries: indicates the chromaticity coordinates of the source primaries 572 | * @transfer_characteristics: indicates the opto-electronic transfer characteristic 573 | * @matrix_coefficients: describes the matrix coefficients used in deriving luma and chroma signals 574 | * @chroma_loc_info_present_flag: %TRUE specifies that chroma_sample_loc_type_top_field and 575 | * chroma_sample_loc_type_bottom_field are present, %FALSE otherwize 576 | * @chroma_sample_loc_type_top_field: specify the location of chroma for top field 577 | * @chroma_sample_loc_type_bottom_field specify the location of chroma for bottom field 578 | * @neutral_chroma_indication_flag: %TRUE indicate that the value of chroma samples is equla 579 | * to 1<<(BitDepthchrom-1). 580 | * @field_seq_flag: %TRUE indicate field and %FALSE indicate frame 581 | * @frame_field_info_present_flag: %TRUE indicate picture timing SEI messages are present for every 582 | * picture and include the pic_struct, source_scan_type, and duplicate_flag syntax elements. 583 | * @default_display_window_flag: %TRUE indicate that the default display window parameters present 584 | * def_disp_win_left_offset:left offset of display rect 585 | * def_disp_win_right_offset: right offset of display rect 586 | * def_disp_win_top_offset: top offset of display rect 587 | * def_disp_win_bottom_offset: bottom offset of display rect 588 | * @timing_info_present_flag: %TRUE specifies that num_units_in_tick, 589 | * time_scale and fixed_frame_rate_flag are present in the bitstream 590 | * @num_units_in_tick: is the number of time units of a clock operating at the frequency time_scale Hz 591 | * @time_scale: is the number of time units that pass in one second 592 | * @poc_proportional_to_timing_flag: %TRUE indicates that the picture order count value for each picture 593 | * in the CVS that is not the first picture in the CVS, in decoding order, is proportional to the output 594 | * time of the picture relative to the output time of the first picture in the CVS. 595 | * @num_ticks_poc_diff_one_minus1: plus 1 specifies the number of clock ticks corresponding to a 596 | * difference of picture order count values equal to 1 597 | * @hrd_parameters_present_flag: %TRUE if hrd parameters present in the bitstream 598 | * @bitstream_restriction_flag: %TRUE specifies that the following coded video sequence bitstream restriction 599 | * parameters are present 600 | * @tiles_fixed_structure_flag: %TRUE indicates that each PPS that is active in the CVS has the same value 601 | * of the syntax elements num_tile_columns_minus1, num_tile_rows_minus1, uniform_spacing_flag, 602 | * column_width_minus1, row_height_minus1 and loop_filter_across_tiles_enabled_flag, when present 603 | * @motion_vectors_over_pic_boundaries_flag: %FALSE indicates that no sample outside the 604 | * picture boundaries and no sample at a fractional sample position, %TRUE indicates that one or more 605 | * samples outside picture boundaries may be used in inter prediction 606 | * @restricted_ref_pic_list_flag: %TRUE indicates that all P and B slices (when present) that belong to 607 | * the same picture have an identical reference picture list 0, and that all B slices (when present) 608 | * that belong to the same picture have an identical reference picture list 1 609 | * @min_spatial_segmentation_idc: when not equal to 0, establishes a bound on the maximum possible size 610 | * of distinct coded spatial segmentation regions in the pictures of the CVS 611 | * @max_bytes_per_pic_denom: indicates a number of bytes not exceeded by the sum of the sizes of 612 | * the VCL NAL units associated with any coded picture in the coded video sequence. 613 | * @max_bits_per_min_cu_denom: indicates an upper bound for the number of coded bits of coding_unit 614 | * data for any coding block in any picture of the CVS 615 | * @log2_max_mv_length_horizontal: indicate the maximum absolute value of a decoded horizontal 616 | * motion vector component 617 | * @log2_max_mv_length_vertical: indicate the maximum absolute value of a decoded vertical 618 | * motion vector component 619 | * 620 | * The structure representing the VUI parameters. 621 | */ 622 | struct _GstH265VUIParams 623 | { 624 | guint8 aspect_ratio_info_present_flag; 625 | guint8 aspect_ratio_idc; 626 | /* if aspect_ratio_idc == 255 */ 627 | guint16 sar_width; 628 | guint16 sar_height; 629 | 630 | guint8 overscan_info_present_flag; 631 | /* if overscan_info_present_flag */ 632 | guint8 overscan_appropriate_flag; 633 | 634 | guint8 video_signal_type_present_flag; 635 | guint8 video_format; 636 | guint8 video_full_range_flag; 637 | guint8 colour_description_present_flag; 638 | guint8 colour_primaries; 639 | guint8 transfer_characteristics; 640 | guint8 matrix_coefficients; 641 | 642 | guint8 chroma_loc_info_present_flag; 643 | guint8 chroma_sample_loc_type_top_field; 644 | guint8 chroma_sample_loc_type_bottom_field; 645 | 646 | guint8 neutral_chroma_indication_flag; 647 | guint8 field_seq_flag; 648 | guint8 frame_field_info_present_flag; 649 | guint8 default_display_window_flag; 650 | guint32 def_disp_win_left_offset; 651 | guint32 def_disp_win_right_offset; 652 | guint32 def_disp_win_top_offset; 653 | guint32 def_disp_win_bottom_offset; 654 | 655 | guint8 timing_info_present_flag; 656 | /* if timing_info_present_flag */ 657 | guint32 num_units_in_tick; 658 | guint32 time_scale; 659 | guint8 poc_proportional_to_timing_flag; 660 | /* if poc_proportional_to_timing_flag */ 661 | guint32 num_ticks_poc_diff_one_minus1; 662 | guint8 hrd_parameters_present_flag; 663 | /*if hrd_parameters_present_flat */ 664 | GstH265HRDParams hrd_params; 665 | 666 | guint8 bitstream_restriction_flag; 667 | /* if bitstream_restriction_flag */ 668 | guint8 tiles_fixed_structure_flag; 669 | guint8 motion_vectors_over_pic_boundaries_flag; 670 | guint8 restricted_ref_pic_lists_flag; 671 | guint16 min_spatial_segmentation_idc; 672 | guint8 max_bytes_per_pic_denom; 673 | guint8 max_bits_per_min_cu_denom; 674 | guint8 log2_max_mv_length_horizontal; 675 | guint8 log2_max_mv_length_vertical; 676 | 677 | /* calculated values */ 678 | guint par_n; 679 | guint par_d; 680 | }; 681 | 682 | /** 683 | * GstH265ScalingList: 684 | * @scaling_list_dc_coef_minus8_16x16: this plus 8 specifies the DC 685 | * Coefficient values for 16x16 scaling list 686 | * @scaling_list_dc_coef_minus8_32x32: this plus 8 specifies the DC 687 | * Coefficient values for 32x32 scaling list 688 | * @scaling_lists_4x4: 4x4 scaling list 689 | * @scaling_lists_8x8: 8x8 scaling list 690 | * @scaling_lists_16x16: 16x16 scaling list 691 | * @guint8 scaling_lists_32x32: 32x32 scaling list 692 | * 693 | * Defines the GstH265ScalingList 694 | */ 695 | struct _GstH265ScalingList { 696 | 697 | gint16 scaling_list_dc_coef_minus8_16x16[6]; 698 | gint16 scaling_list_dc_coef_minus8_32x32[2]; 699 | 700 | guint8 scaling_lists_4x4 [6][16]; 701 | guint8 scaling_lists_8x8 [6][64]; 702 | guint8 scaling_lists_16x16 [6][64]; 703 | guint8 scaling_lists_32x32 [2][64]; 704 | }; 705 | 706 | /** 707 | * GstH265SPS: 708 | * @id: The ID of the sequence parameter set 709 | * @profile_idc: indicate the profile to which the coded video sequence conforms 710 | * 711 | * H265 Sequence Parameter Set (SPS) 712 | */ 713 | struct _GstH265SPS 714 | { 715 | guint8 id; 716 | 717 | GstH265VPS *vps; 718 | 719 | guint8 max_sub_layers_minus1; 720 | guint8 temporal_id_nesting_flag; 721 | 722 | GstH265ProfileTierLevel profile_tier_level; 723 | 724 | guint8 chroma_format_idc; 725 | guint8 separate_colour_plane_flag; 726 | guint16 pic_width_in_luma_samples; 727 | guint16 pic_height_in_luma_samples; 728 | 729 | guint8 conformance_window_flag; 730 | /* if conformance_window_flag */ 731 | guint32 conf_win_left_offset; 732 | guint32 conf_win_right_offset; 733 | guint32 conf_win_top_offset; 734 | guint32 conf_win_bottom_offset; 735 | 736 | guint8 bit_depth_luma_minus8; 737 | guint8 bit_depth_chroma_minus8; 738 | guint8 log2_max_pic_order_cnt_lsb_minus4; 739 | 740 | guint8 sub_layer_ordering_info_present_flag; 741 | guint8 max_dec_pic_buffering_minus1[GST_H265_MAX_SUB_LAYERS]; 742 | guint8 max_num_reorder_pics[GST_H265_MAX_SUB_LAYERS]; 743 | guint8 max_latency_increase_plus1[GST_H265_MAX_SUB_LAYERS]; 744 | 745 | guint8 log2_min_luma_coding_block_size_minus3; 746 | guint8 log2_diff_max_min_luma_coding_block_size; 747 | guint8 log2_min_transform_block_size_minus2; 748 | guint8 log2_diff_max_min_transform_block_size; 749 | guint8 max_transform_hierarchy_depth_inter; 750 | guint8 max_transform_hierarchy_depth_intra; 751 | 752 | guint8 scaling_list_enabled_flag; 753 | /* if scaling_list_enabled_flag */ 754 | guint8 scaling_list_data_present_flag; 755 | 756 | GstH265ScalingList scaling_list; 757 | 758 | guint8 amp_enabled_flag; 759 | guint8 sample_adaptive_offset_enabled_flag; 760 | guint8 pcm_enabled_flag; 761 | /* if pcm_enabled_flag */ 762 | guint8 pcm_sample_bit_depth_luma_minus1; 763 | guint8 pcm_sample_bit_depth_chroma_minus1; 764 | guint8 log2_min_pcm_luma_coding_block_size_minus3; 765 | guint8 log2_diff_max_min_pcm_luma_coding_block_size; 766 | guint8 pcm_loop_filter_disabled_flag; 767 | 768 | guint8 num_short_term_ref_pic_sets; 769 | GstH265ShortTermRefPicSet short_term_ref_pic_set[65]; 770 | 771 | guint8 long_term_ref_pics_present_flag; 772 | /* if long_term_ref_pics_present_flag */ 773 | guint8 num_long_term_ref_pics_sps; 774 | guint16 lt_ref_pic_poc_lsb_sps[32]; 775 | guint8 used_by_curr_pic_lt_sps_flag[32]; 776 | 777 | guint8 temporal_mvp_enabled_flag; 778 | guint8 strong_intra_smoothing_enabled_flag; 779 | guint8 vui_parameters_present_flag; 780 | 781 | /* if vui_parameters_present_flat */ 782 | GstH265VUIParams vui_params; 783 | 784 | guint8 sps_extension_flag; 785 | 786 | /* calculated values */ 787 | guint8 chroma_array_type; 788 | gint width, height; 789 | gint fps_num, fps_den; 790 | gboolean valid; 791 | }; 792 | 793 | /** 794 | * GstH265PPS: 795 | * 796 | * H265 Picture Parameter Set 797 | */ 798 | struct _GstH265PPS 799 | { 800 | guint id; 801 | 802 | GstH265SPS *sps; 803 | 804 | guint8 dependent_slice_segments_enabled_flag; 805 | guint8 output_flag_present_flag; 806 | guint8 num_extra_slice_header_bits; 807 | guint8 sign_data_hiding_enabled_flag; 808 | guint8 cabac_init_present_flag; 809 | guint8 num_ref_idx_l0_default_active_minus1; 810 | guint8 num_ref_idx_l1_default_active_minus1; 811 | gint8 init_qp_minus26; 812 | guint8 constrained_intra_pred_flag; 813 | guint8 transform_skip_enabled_flag; 814 | guint8 cu_qp_delta_enabled_flag; 815 | /*if cu_qp_delta_enabled_flag */ 816 | guint8 diff_cu_qp_delta_depth; 817 | 818 | gint8 cb_qp_offset; 819 | gint8 cr_qp_offset; 820 | guint8 slice_chroma_qp_offsets_present_flag; 821 | guint8 weighted_pred_flag; 822 | guint8 weighted_bipred_flag; 823 | guint8 transquant_bypass_enabled_flag; 824 | guint8 tiles_enabled_flag; 825 | guint8 entropy_coding_sync_enabled_flag; 826 | 827 | guint8 num_tile_columns_minus1; 828 | guint8 num_tile_rows_minus1; 829 | guint8 uniform_spacing_flag; 830 | guint32 column_width_minus1[19]; 831 | guint32 row_height_minus1[21]; 832 | guint8 loop_filter_across_tiles_enabled_flag; 833 | 834 | guint8 loop_filter_across_slices_enabled_flag; 835 | guint8 deblocking_filter_control_present_flag; 836 | guint8 deblocking_filter_override_enabled_flag; 837 | guint8 deblocking_filter_disabled_flag; 838 | gint8 beta_offset_div2; 839 | gint8 tc_offset_div2; 840 | 841 | guint8 scaling_list_data_present_flag; 842 | 843 | GstH265ScalingList scaling_list; 844 | 845 | guint8 lists_modification_present_flag; 846 | guint8 log2_parallel_merge_level_minus2; 847 | guint8 slice_segment_header_extension_present_flag; 848 | 849 | guint8 pps_extension_flag; 850 | 851 | gboolean valid; 852 | }; 853 | 854 | struct _GstH265RefPicListModification 855 | { 856 | guint8 ref_pic_list_modification_flag_l0; 857 | guint32 list_entry_l0[15]; 858 | guint8 ref_pic_list_modification_flag_l1; 859 | guint32 list_entry_l1[15]; 860 | }; 861 | 862 | struct _GstH265PredWeightTable 863 | { 864 | guint8 luma_log2_weight_denom; 865 | gint8 delta_chroma_log2_weight_denom; 866 | 867 | guint8 luma_weight_l0_flag[15]; 868 | guint8 chroma_weight_l0_flag[15]; 869 | gint8 delta_luma_weight_l0[15]; 870 | gint8 luma_offset_l0[15]; 871 | gint8 delta_chroma_weight_l0 [15][2]; 872 | gint16 delta_chroma_offset_l0 [15][2]; 873 | 874 | guint8 luma_weight_l1_flag[15]; 875 | guint8 chroma_weight_l1_flag[15]; 876 | gint8 delta_luma_weight_l1[15]; 877 | gint8 luma_offset_l1[15]; 878 | gint8 delta_chroma_weight_l1[15][2]; 879 | gint16 delta_chroma_offset_l1[15][2]; 880 | }; 881 | 882 | struct _GstH265SliceHdr 883 | { 884 | guint8 first_slice_segment_in_pic_flag; 885 | guint8 no_output_of_prior_pics_flag; 886 | 887 | GstH265PPS *pps; 888 | 889 | guint8 dependent_slice_segment_flag; 890 | guint32 segment_address; 891 | 892 | guint8 type; 893 | 894 | guint8 pic_output_flag; 895 | guint8 colour_plane_id; 896 | guint16 pic_order_cnt_lsb; 897 | 898 | guint8 short_term_ref_pic_set_sps_flag; 899 | GstH265ShortTermRefPicSet short_term_ref_pic_sets; 900 | guint8 short_term_ref_pic_set_idx; 901 | 902 | guint8 num_long_term_sps; 903 | guint8 num_long_term_pics; 904 | guint8 lt_idx_sps[16]; 905 | guint32 poc_lsb_lt[16]; 906 | guint8 used_by_curr_pic_lt_flag[16]; 907 | guint8 delta_poc_msb_present_flag[16]; 908 | guint32 delta_poc_msb_cycle_lt[16]; 909 | 910 | guint8 temporal_mvp_enabled_flag; 911 | guint8 sao_luma_flag; 912 | guint8 sao_chroma_flag; 913 | guint8 num_ref_idx_active_override_flag; 914 | guint8 num_ref_idx_l0_active_minus1; 915 | guint8 num_ref_idx_l1_active_minus1; 916 | 917 | GstH265RefPicListModification ref_pic_list_modification; 918 | 919 | guint8 mvd_l1_zero_flag; 920 | guint8 cabac_init_flag; 921 | guint8 collocated_from_l0_flag; 922 | guint8 collocated_ref_idx; 923 | 924 | GstH265PredWeightTable pred_weight_table; 925 | 926 | guint8 five_minus_max_num_merge_cand; 927 | 928 | gint8 qp_delta; 929 | gint8 cb_qp_offset; 930 | gint8 cr_qp_offset; 931 | 932 | guint8 deblocking_filter_override_flag; 933 | guint8 deblocking_filter_disabled_flag; 934 | gint8 beta_offset_div2; 935 | gint8 tc_offset_div2; 936 | 937 | guint8 loop_filter_across_slices_enabled_flag; 938 | 939 | guint32 num_entry_point_offsets; 940 | guint8 offset_len_minus1; 941 | guint32 *entry_point_offset_minus1; 942 | 943 | /* calculated values */ 944 | 945 | gint NumPocTotalCurr; 946 | /* Size of the slice_header() in bits */ 947 | guint header_size; 948 | /* Number of emulation prevention bytes (EPB) in this slice_header() */ 949 | guint n_emulation_prevention_bytes; 950 | 951 | /* VDPAU NVIDIA implementation */ 952 | guint32 NumShortTermPictureSliceHeaderBits; 953 | guint32 NumLongTermPictureSliceHeaderBits; 954 | }; 955 | 956 | struct _GstH265PicTiming 957 | { 958 | guint8 pic_struct; 959 | guint8 source_scan_type; 960 | guint8 duplicate_flag; 961 | 962 | guint8 au_cpb_removal_delay_minus1; 963 | guint8 pic_dpb_output_delay; 964 | guint8 pic_dpb_output_du_delay; 965 | guint32 num_decoding_units_minus1; 966 | guint8 du_common_cpb_removal_delay_flag; 967 | guint8 du_common_cpb_removal_delay_increment_minus1; 968 | guint32 *num_nalus_in_du_minus1; 969 | guint8 *du_cpb_removal_delay_increment_minus1; 970 | }; 971 | 972 | struct _GstH265BufferingPeriod 973 | { 974 | GstH265SPS *sps; 975 | 976 | guint8 irap_cpb_params_present_flag; 977 | guint8 cpb_delay_offset; 978 | guint8 dpb_delay_offset; 979 | guint8 concatenation_flag; 980 | guint8 au_cpb_removal_delay_delta_minus1; 981 | 982 | /* seq->vui_parameters->nal_hrd_parameters_present_flag */ 983 | guint8 nal_initial_cpb_removal_delay[32]; 984 | guint8 nal_initial_cpb_removal_offset[32]; 985 | guint8 nal_initial_alt_cpb_removal_delay[32]; 986 | guint8 nal_initial_alt_cpb_removal_offset [32]; 987 | 988 | /* seq->vui_parameters->vcl_hrd_parameters_present_flag */ 989 | guint8 vcl_initial_cpb_removal_delay[32]; 990 | guint8 vcl_initial_cpb_removal_offset[32]; 991 | guint8 vcl_initial_alt_cpb_removal_delay[32]; 992 | guint8 vcl_initial_alt_cpb_removal_offset[32]; 993 | }; 994 | 995 | struct _GstH265SEIMessage 996 | { 997 | GstH265SEIPayloadType payloadType; 998 | 999 | union { 1000 | GstH265BufferingPeriod buffering_period; 1001 | GstH265PicTiming pic_timing; 1002 | /* ... could implement more */ 1003 | } payload; 1004 | }; 1005 | 1006 | /** 1007 | * GstH265Parser: 1008 | * 1009 | * H265 NAL Parser (opaque structure). 1010 | */ 1011 | struct _GstH265Parser 1012 | { 1013 | /*< private >*/ 1014 | GstH265VPS vps[GST_H265_MAX_VPS_COUNT]; 1015 | GstH265SPS sps[GST_H265_MAX_SPS_COUNT]; 1016 | GstH265PPS pps[GST_H265_MAX_PPS_COUNT]; 1017 | GstH265VPS *last_vps; 1018 | GstH265SPS *last_sps; 1019 | GstH265PPS *last_pps; 1020 | }; 1021 | 1022 | GstH265Parser * gst_h265_parser_new (void); 1023 | 1024 | GstH265ParserResult gst_h265_parser_identify_nalu (GstH265Parser * parser, 1025 | const guint8 * data, 1026 | guint offset, 1027 | gsize size, 1028 | GstH265NalUnit * nalu); 1029 | 1030 | GstH265ParserResult gst_h265_parser_identify_nalu_unchecked (GstH265Parser * parser, 1031 | const guint8 * data, 1032 | guint offset, 1033 | gsize size, 1034 | GstH265NalUnit * nalu); 1035 | 1036 | GstH265ParserResult gst_h265_parser_identify_nalu_hevc (GstH265Parser * parser, 1037 | const guint8 * data, 1038 | guint offset, 1039 | gsize size, 1040 | guint8 nal_length_size, 1041 | GstH265NalUnit * nalu); 1042 | 1043 | GstH265ParserResult gst_h265_parser_parse_nal (GstH265Parser * parser, 1044 | GstH265NalUnit * nalu); 1045 | 1046 | GstH265ParserResult gst_h265_parser_parse_slice_hdr (GstH265Parser * parser, 1047 | GstH265NalUnit * nalu, 1048 | GstH265SliceHdr * slice); 1049 | 1050 | GstH265ParserResult gst_h265_parser_parse_vps (GstH265Parser * parser, 1051 | GstH265NalUnit * nalu, 1052 | GstH265VPS * vps); 1053 | 1054 | GstH265ParserResult gst_h265_parser_parse_sps (GstH265Parser * parser, 1055 | GstH265NalUnit * nalu, 1056 | GstH265SPS * sps, 1057 | gboolean parse_vui_params); 1058 | 1059 | GstH265ParserResult gst_h265_parser_parse_pps (GstH265Parser * parser, 1060 | GstH265NalUnit * nalu, 1061 | GstH265PPS * pps); 1062 | 1063 | GstH265ParserResult gst_h265_parser_parse_sei (GstH265Parser * parser, 1064 | GstH265NalUnit * nalu, 1065 | GstH265SEIMessage * sei); 1066 | 1067 | void gst_h265_parser_free (GstH265Parser * parser); 1068 | 1069 | GstH265ParserResult gst_h265_parse_vps (GstH265NalUnit * nalu, 1070 | GstH265VPS * vps); 1071 | 1072 | GstH265ParserResult gst_h265_parse_sps (GstH265Parser * parser, 1073 | GstH265NalUnit * nalu, 1074 | GstH265SPS * sps, 1075 | gboolean parse_vui_params); 1076 | 1077 | GstH265ParserResult gst_h265_parse_pps (GstH265Parser * parser, 1078 | GstH265NalUnit * nalu, 1079 | GstH265PPS * pps); 1080 | 1081 | gboolean gst_h265_slice_hdr_copy (GstH265SliceHdr * dst_slice, 1082 | const GstH265SliceHdr * src_slice); 1083 | 1084 | void gst_h265_slice_hdr_free (GstH265SliceHdr * slice_hdr); 1085 | 1086 | gboolean gst_h265_sei_copy (GstH265SEIMessage * dest_sei, 1087 | const GstH265SEIMessage * src_sei); 1088 | 1089 | void gst_h265_sei_free (GstH265SEIMessage * sei); 1090 | 1091 | G_END_DECLS 1092 | #endif 1093 | -------------------------------------------------------------------------------- /nalutils.c: -------------------------------------------------------------------------------- 1 | /* Gstreamer 2 | * Copyright (C) <2011> Intel Corporation 3 | * Copyright (C) <2011> Collabora Ltd. 4 | * Copyright (C) <2011> Thibault Saunier 5 | * 6 | * Some bits C-c,C-v'ed and s/4/3 from h264parse and videoparsers/h264parse.c: 7 | * Copyright (C) <2010> Mark Nauwelaerts 8 | * Copyright (C) <2010> Collabora Multimedia 9 | * Copyright (C) <2010> Nokia Corporation 10 | * 11 | * (C) 2005 Michal Benes 12 | * (C) 2008 Wim Taymans 13 | * 14 | * This library is free software; you can redistribute it and/or 15 | * modify it under the terms of the GNU Lesser General Public 16 | * License, version 2.1, as published by the Free Software Foundation. 17 | * 18 | * This library is distributed in the hope that it will be useful, 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 21 | * Lesser General Public License for more details. 22 | * 23 | * You should have received a copy of the GNU Lesser General Public 24 | * License along with this program. If not, see 25 | * . 26 | */ 27 | 28 | /** 29 | * Common code for NAL parsing from h264 and h265 parsers. 30 | */ 31 | 32 | #ifdef HAVE_CONFIG_H 33 | # include "config.h" 34 | #endif 35 | 36 | #include "nalutils.h" 37 | 38 | /* Compute Ceil(Log2(v)) */ 39 | /* Derived from branchless code for integer log2(v) from: 40 | */ 41 | guint 42 | ceil_log2 (guint32 v) 43 | { 44 | guint r, shift; 45 | 46 | v--; 47 | r = (v > 0xFFFF) << 4; 48 | v >>= r; 49 | shift = (v > 0xFF) << 3; 50 | v >>= shift; 51 | r |= shift; 52 | shift = (v > 0xF) << 2; 53 | v >>= shift; 54 | r |= shift; 55 | shift = (v > 0x3) << 1; 56 | v >>= shift; 57 | r |= shift; 58 | r |= (v >> 1); 59 | return r + 1; 60 | } 61 | 62 | /****** Nal parser ******/ 63 | 64 | void 65 | nal_reader_init (NalReader * nr, const guint8 * data, guint size) 66 | { 67 | nr->data = data; 68 | nr->size = size; 69 | nr->n_epb = 0; 70 | 71 | nr->byte = 0; 72 | nr->bits_in_cache = 0; 73 | /* fill with something other than 0 to detect emulation prevention bytes */ 74 | nr->first_byte = 0xff; 75 | nr->cache = 0xff; 76 | } 77 | 78 | inline gboolean 79 | nal_reader_read (NalReader * nr, guint nbits) 80 | { 81 | if (G_UNLIKELY (nr->byte * 8 + (nbits - nr->bits_in_cache) > nr->size * 8)) { 82 | GST_DEBUG ("Can not read %u bits, bits in cache %u, Byte * 8 %u, size in " 83 | "bits %u", nbits, nr->bits_in_cache, nr->byte * 8, nr->size * 8); 84 | return FALSE; 85 | } 86 | 87 | while (nr->bits_in_cache < nbits) { 88 | guint8 byte; 89 | gboolean check_three_byte; 90 | 91 | check_three_byte = TRUE; 92 | next_byte: 93 | if (G_UNLIKELY (nr->byte >= nr->size)) 94 | return FALSE; 95 | 96 | byte = nr->data[nr->byte++]; 97 | 98 | /* check if the byte is a emulation_prevention_three_byte */ 99 | if (check_three_byte && byte == 0x03 && nr->first_byte == 0x00 && 100 | ((nr->cache & 0xff) == 0)) { 101 | /* next byte goes unconditionally to the cache, even if it's 0x03 */ 102 | check_three_byte = FALSE; 103 | nr->n_epb++; 104 | goto next_byte; 105 | } 106 | nr->cache = (nr->cache << 8) | nr->first_byte; 107 | nr->first_byte = byte; 108 | nr->bits_in_cache += 8; 109 | } 110 | 111 | return TRUE; 112 | } 113 | 114 | /* Skips the specified amount of bits. This is only suitable to a 115 | cacheable number of bits */ 116 | inline gboolean 117 | nal_reader_skip (NalReader * nr, guint nbits) 118 | { 119 | g_assert (nbits <= 8 * sizeof (nr->cache)); 120 | 121 | if (G_UNLIKELY (!nal_reader_read (nr, nbits))) 122 | return FALSE; 123 | 124 | nr->bits_in_cache -= nbits; 125 | 126 | return TRUE; 127 | } 128 | 129 | /* Generic version to skip any number of bits */ 130 | gboolean 131 | nal_reader_skip_long (NalReader * nr, guint nbits) 132 | { 133 | /* Leave out enough bits in the cache once we are finished */ 134 | const guint skip_size = 4 * sizeof (nr->cache); 135 | guint remaining = nbits; 136 | 137 | nbits %= skip_size; 138 | while (remaining > 0) { 139 | if (!nal_reader_skip (nr, nbits)) 140 | return FALSE; 141 | remaining -= nbits; 142 | nbits = skip_size; 143 | } 144 | return TRUE; 145 | } 146 | 147 | inline guint 148 | nal_reader_get_pos (const NalReader * nr) 149 | { 150 | return nr->byte * 8 - nr->bits_in_cache; 151 | } 152 | 153 | inline guint 154 | nal_reader_get_remaining (const NalReader * nr) 155 | { 156 | return (nr->size - nr->byte) * 8 + nr->bits_in_cache; 157 | } 158 | 159 | inline guint 160 | nal_reader_get_epb_count (const NalReader * nr) 161 | { 162 | return nr->n_epb; 163 | } 164 | 165 | #define NAL_READER_READ_BITS(bits) \ 166 | gboolean \ 167 | nal_reader_get_bits_uint##bits (NalReader *nr, guint##bits *val, guint nbits) \ 168 | { \ 169 | guint shift; \ 170 | \ 171 | if (!nal_reader_read (nr, nbits)) \ 172 | return FALSE; \ 173 | \ 174 | /* bring the required bits down and truncate */ \ 175 | shift = nr->bits_in_cache - nbits; \ 176 | *val = nr->first_byte >> shift; \ 177 | \ 178 | *val |= nr->cache << (8 - shift); \ 179 | /* mask out required bits */ \ 180 | if (nbits < bits) \ 181 | *val &= ((guint##bits)1 << nbits) - 1; \ 182 | \ 183 | nr->bits_in_cache = shift; \ 184 | \ 185 | return TRUE; \ 186 | } \ 187 | 188 | NAL_READER_READ_BITS (8); 189 | NAL_READER_READ_BITS (16); 190 | NAL_READER_READ_BITS (32); 191 | 192 | #define NAL_READER_PEEK_BITS(bits) \ 193 | gboolean \ 194 | nal_reader_peek_bits_uint##bits (const NalReader *nr, guint##bits *val, guint nbits) \ 195 | { \ 196 | NalReader tmp; \ 197 | \ 198 | tmp = *nr; \ 199 | return nal_reader_get_bits_uint##bits (&tmp, val, nbits); \ 200 | } 201 | 202 | NAL_READER_PEEK_BITS (8); 203 | 204 | gboolean 205 | nal_reader_get_ue (NalReader * nr, guint32 * val) 206 | { 207 | guint i = 0; 208 | guint8 bit; 209 | guint32 value; 210 | 211 | if (G_UNLIKELY (!nal_reader_get_bits_uint8 (nr, &bit, 1))) { 212 | 213 | return FALSE; 214 | } 215 | 216 | while (bit == 0) { 217 | i++; 218 | if G_UNLIKELY 219 | ((!nal_reader_get_bits_uint8 (nr, &bit, 1))) 220 | return FALSE; 221 | } 222 | 223 | if (G_UNLIKELY (i > 32)) 224 | return FALSE; 225 | 226 | if (G_UNLIKELY (!nal_reader_get_bits_uint32 (nr, &value, i))) 227 | return FALSE; 228 | 229 | *val = (1 << i) - 1 + value; 230 | 231 | return TRUE; 232 | } 233 | 234 | inline gboolean 235 | nal_reader_get_se (NalReader * nr, gint32 * val) 236 | { 237 | guint32 value; 238 | 239 | if (G_UNLIKELY (!nal_reader_get_ue (nr, &value))) 240 | return FALSE; 241 | 242 | if (value % 2) 243 | *val = (value / 2) + 1; 244 | else 245 | *val = -(value / 2); 246 | 247 | return TRUE; 248 | } 249 | 250 | gboolean 251 | nal_reader_is_byte_aligned (NalReader * nr) 252 | { 253 | if (nr->bits_in_cache != 0) 254 | return FALSE; 255 | return TRUE; 256 | } 257 | 258 | gboolean 259 | nal_reader_has_more_data (NalReader * nr) 260 | { 261 | NalReader nr_tmp; 262 | guint remaining, nbits; 263 | guint8 rbsp_stop_one_bit, zero_bits; 264 | 265 | remaining = nal_reader_get_remaining (nr); 266 | if (remaining == 0) 267 | return FALSE; 268 | 269 | nr_tmp = *nr; 270 | nr = &nr_tmp; 271 | 272 | /* The spec defines that more_rbsp_data() searches for the last bit 273 | equal to 1, and that it is the rbsp_stop_one_bit. Subsequent bits 274 | until byte boundary is reached shall be zero. 275 | 276 | This means that more_rbsp_data() is FALSE if the next bit is 1 277 | and the remaining bits until byte boundary are zero. One way to 278 | be sure that this bit was the very last one, is that every other 279 | bit after we reached byte boundary are also set to zero. 280 | Otherwise, if the next bit is 0 or if there are non-zero bits 281 | afterwards, then then we have more_rbsp_data() */ 282 | if (!nal_reader_get_bits_uint8 (nr, &rbsp_stop_one_bit, 1)) 283 | return FALSE; 284 | if (!rbsp_stop_one_bit) 285 | return TRUE; 286 | 287 | nbits = --remaining % 8; 288 | while (remaining > 0) { 289 | if (!nal_reader_get_bits_uint8 (nr, &zero_bits, nbits)) 290 | return FALSE; 291 | if (zero_bits != 0) 292 | return TRUE; 293 | remaining -= nbits; 294 | nbits = 8; 295 | } 296 | return FALSE; 297 | } 298 | 299 | /*********** end of nal parser ***************/ 300 | 301 | inline gint 302 | scan_for_start_codes (const guint8 * data, guint size) 303 | { 304 | GstByteReader br; 305 | gst_byte_reader_init (&br, data, size); 306 | 307 | /* NALU not empty, so we can at least expect 1 (even 2) bytes following sc */ 308 | return gst_byte_reader_masked_scan_uint32 (&br, 0xffffff00, 0x00000100, 309 | 0, size); 310 | } 311 | -------------------------------------------------------------------------------- /nalutils.h: -------------------------------------------------------------------------------- 1 | /* Gstreamer 2 | * Copyright (C) <2011> Intel Corporation 3 | * Copyright (C) <2011> Collabora Ltd. 4 | * Copyright (C) <2011> Thibault Saunier 5 | * 6 | * Some bits C-c,C-v'ed and s/4/3 from h264parse and videoparsers/h264parse.c: 7 | * Copyright (C) <2010> Mark Nauwelaerts 8 | * Copyright (C) <2010> Collabora Multimedia 9 | * Copyright (C) <2010> Nokia Corporation 10 | * 11 | * (C) 2005 Michal Benes 12 | * (C) 2008 Wim Taymans 13 | * 14 | * This library is free software; you can redistribute it and/or 15 | * modify it under the terms of the GNU Lesser General Public 16 | * License, version 2.1, as published by the Free Software Foundation. 17 | * 18 | * This library is distributed in the hope that it will be useful, 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 21 | * Lesser General Public License for more details. 22 | * 23 | * You should have received a copy of the GNU Lesser General Public 24 | * License along with this program. If not, see 25 | * . 26 | */ 27 | 28 | /** 29 | * Common code for NAL parsing from h264 and h265 parsers. 30 | */ 31 | 32 | #ifdef HAVE_CONFIG_H 33 | # include "config.h" 34 | #endif 35 | 36 | #include 37 | #include 38 | #include 39 | 40 | #ifdef GST_WARNING 41 | #undef GST_WARNING 42 | #define GST_WARNING printf 43 | #endif 44 | 45 | #ifdef GST_DEBUG 46 | #undef GST_DEBUG 47 | #define GST_DEBUG printf 48 | #endif 49 | 50 | guint ceil_log2 (guint32 v); 51 | 52 | typedef struct 53 | { 54 | const guint8 *data; 55 | guint size; 56 | 57 | guint n_epb; /* Number of emulation prevention bytes */ 58 | guint byte; /* Byte position */ 59 | guint bits_in_cache; /* bitpos in the cache of next bit */ 60 | guint8 first_byte; 61 | guint64 cache; /* cached bytes */ 62 | } NalReader; 63 | 64 | void nal_reader_init (NalReader * nr, const guint8 * data, guint size); 65 | 66 | gboolean nal_reader_read (NalReader * nr, guint nbits); 67 | gboolean nal_reader_skip (NalReader * nr, guint nbits); 68 | gboolean nal_reader_skip_long (NalReader * nr, guint nbits); 69 | guint nal_reader_get_pos (const NalReader * nr); 70 | guint nal_reader_get_remaining (const NalReader * nr); 71 | guint nal_reader_get_epb_count (const NalReader * nr); 72 | 73 | gboolean nal_reader_is_byte_aligned (NalReader * nr); 74 | gboolean nal_reader_has_more_data (NalReader * nr); 75 | 76 | #define NAL_READER_READ_BITS_H(bits) \ 77 | gboolean nal_reader_get_bits_uint##bits (NalReader *nr, guint##bits *val, guint nbits) 78 | 79 | NAL_READER_READ_BITS_H (8); 80 | NAL_READER_READ_BITS_H (16); 81 | NAL_READER_READ_BITS_H (32); 82 | 83 | #define NAL_READER_PEEK_BITS_H(bits) \ 84 | gboolean nal_reader_peek_bits_uint##bits (const NalReader *nr, guint##bits *val, guint nbits) 85 | 86 | NAL_READER_PEEK_BITS_H (8); 87 | 88 | gboolean nal_reader_get_ue (NalReader * nr, guint32 * val); 89 | gboolean nal_reader_get_se (NalReader * nr, gint32 * val); 90 | 91 | #define CHECK_ALLOWED(val, min, max) { \ 92 | if (val < min || val > max) { \ 93 | GST_WARNING ("value not in allowed range. value: %d, range %d-%d", \ 94 | val, min, max); \ 95 | goto error; \ 96 | } \ 97 | } 98 | 99 | #define READ_UINT8(nr, val, nbits) { \ 100 | if (!nal_reader_get_bits_uint8 (nr, &val, nbits)) { \ 101 | GST_WARNING ("failed to read uint8, nbits: %d", nbits); \ 102 | goto error; \ 103 | } \ 104 | } 105 | 106 | #define READ_UINT16(nr, val, nbits) { \ 107 | if (!nal_reader_get_bits_uint16 (nr, &val, nbits)) { \ 108 | GST_WARNING ("failed to read uint16, nbits: %d", nbits); \ 109 | goto error; \ 110 | } \ 111 | } 112 | 113 | #define READ_UINT32(nr, val, nbits) { \ 114 | if (!nal_reader_get_bits_uint32 (nr, &val, nbits)) { \ 115 | GST_WARNING ("failed to read uint32, nbits: %d", nbits); \ 116 | goto error; \ 117 | } \ 118 | } 119 | 120 | #define READ_UINT64(nr, val, nbits) { \ 121 | if (!nal_reader_get_bits_uint64 (nr, &val, nbits)) { \ 122 | GST_WARNING ("failed to read uint32, nbits: %d", nbits); \ 123 | goto error; \ 124 | } \ 125 | } 126 | 127 | #define READ_UE(nr, val) { \ 128 | if (!nal_reader_get_ue (nr, &val)) { \ 129 | GST_WARNING ("failed to read UE"); \ 130 | goto error; \ 131 | } \ 132 | } 133 | 134 | #define READ_UE_ALLOWED(nr, val, min, max) { \ 135 | guint32 tmp; \ 136 | READ_UE (nr, tmp); \ 137 | CHECK_ALLOWED (tmp, min, max); \ 138 | val = tmp; \ 139 | } 140 | 141 | #define READ_SE(nr, val) { \ 142 | if (!nal_reader_get_se (nr, &val)) { \ 143 | GST_WARNING ("failed to read SE"); \ 144 | goto error; \ 145 | } \ 146 | } 147 | 148 | #define READ_SE_ALLOWED(nr, val, min, max) { \ 149 | gint32 tmp; \ 150 | READ_SE (nr, tmp); \ 151 | CHECK_ALLOWED (tmp, min, max); \ 152 | val = tmp; \ 153 | } 154 | 155 | gint scan_for_start_codes (const guint8 * data, guint size); 156 | --------------------------------------------------------------------------------