summaryrefslogtreecommitdiff
path: root/libavcodec/cbs_h2645.c
Commit message (Collapse)AuthorAge
* cbs_h2645: Merge SEI message handling in common between codecsMark Thompson2021-01-21
|
* hevc: Use common SEI typesMark Thompson2021-01-21
|
* h264: Use common SEI typesMark Thompson2021-01-21
|
* cbs_h2645: Merge SEI messages in common between codecsMark Thompson2021-01-21
| | | | | Make a new template file for common SEI messages - this will also apply to H.266.
* avcodec/cbs_h2645: Move zero_byte check to its own functionNuo Mi2021-01-11
| | | | Signed-off-by: Mark Thompson <sw@jkqxz.net>
* avcodec/cbs_h2645: remove dead code in cbs_h2645_replace_ps()James Almer2020-12-01
| | | | | | | Missed in 0720e15c0330f0f101c02d5c2c6548e964079f6d. PS units are now guaranteed to always be reference counter. Signed-off-by: James Almer <jamrial@gmail.com>
* avcodec/cbs_h2645: implement CodedBitstreamType.flush() callbacksJames Almer2020-09-29
| | | | Signed-off-by: James Almer <jamrial@gmail.com>
* cbs_h265: Use table-based alloc/freeMark Thompson2020-09-02
|
* cbs_h2645: Ensure that non-refcounted parameter sets are fully copiedMark Thompson2020-09-02
| | | | | Only copying the main structure is not necessarily sufficient - there could be references to substructures.
* cbs_h264: Use table-based alloc/freeMark Thompson2020-09-02
|
* avcodec/cbs: Remove unused function parametersAndreas Rheinhardt2020-07-07
| | | | | | | | Several cbs-functions had an unused CodedBitstreamContext parameter. This commit removes these. Reviewed-by: Mark Thompson <sw@jkqxz.net> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* avcodec/cbs_h2645: abort when written inferred values don't matchJames Almer2020-06-14
| | | | | | | | | | If this happens, it's a sign of parsing issues earlier in the process, or misuse by the calling module. Prevents writing invalid bitstreams. Reviewed-by: Michael Niedermayer <michael@niedermayer.cc> Signed-off-by: James Almer <jamrial@gmail.com>
* avcodec/cbs_h265: add missing support for reserved_payload_extension_data ↵James Almer2020-05-03
| | | | | | | | | | SEI bits Fixes ticket #8622 Reviewed-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com> Reviewed-by: Mark Thompson <sw@jkqxz.net> Signed-off-by: James Almer <jamrial@gmail.com>
* avcodec/cbs_h265: move the payload_extension_present check into its own functionJames Almer2020-05-03
| | | | | | Will be reused in the following patch. Signed-off-by: James Almer <jamrial@gmail.com>
* avcodec/cbs: Avoid leaving the ... out in calls to variadic macrosAndreas Rheinhardt2020-04-12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | According to C99, there has to be at least one argument for every ... in a variadic function-like macro. In practice most (all?) compilers also allow to leave it completely out, but it is nevertheless required: In a variadic macro "there shall be more arguments in the invocation than there are parameters in the macro definition (excluding the ...)." (C99, 6.10.3.4). CBS (not the framework itself, but the macros used in the cbs_*_syntax_template.c files) relies on the compiler allowing to leave a variadic macro argument out. This leads to warnings when compiling in -pedantic mode, e.g. "warning: must specify at least one argument for '...' parameter of variadic macro [-Wgnu-zero-variadic-macro-arguments]" from Clang. Most of these warnings can be easily avoided: The syntax_templates mostly contain helper macros that expand to more complex variadic macros and these helper macros often omit an argument for the .... Modifying them to always expand to complex macros with an empty argument for the ... at the end fixes most of these warnings: The number of warnings went down from 400 to 0 for cbs_av1, from 1114 to 32 for cbs_h2645, from 38 to 0 for cbs_jpeg, from 166 to 0 for cbs_mpeg2 and from 110 to 8 for cbs_vp9. These eight remaining warnings for cbs_vp9 have been fixed by switching to another macro in cbs_vp9_syntax_template: The fixed values for the sync bytes as well as the trailing bits for byte-alignment are now read via the fixed() macro (this also adds a check to ensure that trailing bits are indeed zero as they have to be). Reviewed-by: Mark Thompson <sw@jkqxz.net> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* avcodec/cbs_h2645: Treat slices without data as invalidAndreas Rheinhardt2020-03-10
| | | | | | | | | | | Slices that end after their header (meaning slices after the header without any data before the rbsp_stop_one_bit or possibly without any rbsp_stop_one_bit at all) are invalid and are now dropped. This ensures that one doesn't run into two asserts in cbs_h2645_write_slice_data(). Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com> Fixes: 19629/clusterfuzz-testcase-minimized-ffmpeg_BSF_H264_METADATA_fuzzer-5676822528524288 Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avcodec/cbs_h2645: Remove dead code to delete trailing zeroesAndreas Rheinhardt2020-03-10
| | | | | | | | Trailing zeroes are already discarded when splitting a fragment, which makes the code to remove them when decomposing slices dead code. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* lavc/cbs_h2645: Add missing newlines in log messagesMark Thompson2020-02-09
|
* lavc/h2645_parse: Don't automatically remove nuh_layer_id > 0 packetsAndriy Gelman2020-01-17
| | | | | | | | | | | | | | | | | | | HEVC standard supports multi-layer streams (ITU-T H.265 02/2018 Annex F). Each NAL unit belongs to a particular layer defined by nuh_layer_id in the header. Currently, all NAL units that do not belong to a base layer are automatically removed in ff_h2645_packet_split(). Some data may therefore be lost when future filters/decoders are designed to support multi-layer streams. A better approach is to forward nuh_layer_id > 0 packets and let blocks down the chain decide how to process them. The condition to remove packets has been moved to hevcdec and cbs. Found-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com> Signed-off-by: Andriy Gelman <andriy.gelman@gmail.com> Signed-off-by: James Almer <jamrial@gmail.com>
* avcodec/cbs_h2645: Skip all 0 NAL unitsMichael Niedermayer2020-01-11
| | | | | | | | Fixes: assertion failure Fixes: 19286/clusterfuzz-testcase-minimized-ffmpeg_BSF_H264_REDUNDANT_PPS_fuzzer-5707990724509696 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* lavc/cbs_h2645: Fix incorrect max size of nalu unitAndriy Gelman2019-12-06
| | | | | | | | | | | In the worst case the startcode prefix has 4 bytes. This fixes a trigerred assertion: Assertion dp <= max_size failed at libavcodec/cbs_h2645.c:1451 Found-by:libFuzzer Reviewed-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com> Signed-off-by: Andriy Gelman <andriy.gelman@gmail.com>
* avcodec/cbs: Fix potential overflowAndreas Rheinhardt2019-11-17
| | | | | | | | | | | | | The number of bits in a PutBitContext must fit into an int, yet nothing guaranteed the size argument cbs_write_unit_data() uses in init_put_bits() to be in the range 0..INT_MAX / 8. This has been changed. Furthermore, the check 8 * data_size > data_bit_start that there is data beyond the initial padding when writing mpeg2 or H.264/5 slices could also overflow, so divide it by 8 to get an equivalent check without this problem. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* avcodec/cbs: Factor out common code for writing unitsAndreas Rheinhardt2019-11-17
| | | | | | | | | | | | | | | | | All cbs-functions to write units share a common pattern: 1. They check whether they have a write buffer (that is used to store the unit's data until the needed size becomes known after writing the unit when a dedicated buffer will be allocated). 2. They use this buffer for a PutBitContext. 3. The (codec-specific) writing takes place through the PutBitContext. 4. The return value is checked. AVERROR(ENOSPC) here always indicates that the buffer was too small and leads to a reallocation of said buffer. 5. The final buffer will be allocated and the data copied. This commit factors this common code out in a single function in cbs.c. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* avcodec/cbs_h2645: Fix potential out-of-bounds array accessAndreas Rheinhardt2019-09-29
| | | | | | | | | | | The maximum allowed index for an array access is FF_ARRAY_ELEMS - 1; yet the current code allowed FF_ARRAY_ELEMS. This wasn't dangerous in practice, as parameter sets with invalid ids were already filtered out during reading. Found via PVS-Studio (see ticket #8156). Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* avcodec/cbs_h264: Automatically free SEI payload on errorAndreas Rheinhardt2019-09-24
| | | | | | | | | | | | | If adding an SEI message to an access unit fails, said SEI message was not touched, so that the caller had to free any data associated with it that might need to be freed. But given that ff_cbs_h264_add_sei_message can simply call cbs_h264_free_sei_payload, one can easily free the content of the SEI payload. This fixes a memleak when inserting a user data unregistered string for h264_metadata fails. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* lavc/cbs_h2645: Use av_realloc instead of av_mallocThierry Foucu2019-08-28
| | | | | Follow the description of av_realloc, the memory needs to be allocated by av_realloc.
* cbs_h264: Improve adding SEI messagesAndreas Rheinhardt2019-07-29
| | | | | | | | | | | | Up until now, if an SEI messages was to be added to a fragment, it was tried to add said SEI message to the first SEI NAL unit of the fragment and if this SEI NAL unit already contained H264_NAL_SEI SEI messages (an arbitrary limit imposed by cbs_h264), adding failed; if there was no SEI NAL unit, a new one has been added. With this commit, the fragment is searched for further NAL units to add the SEI messages to. If all of them are full, a new SEI NAL unit is added. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* cbs: Don't set AVBuffer's opaqueAndreas Rheinhardt2019-07-29
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | cbs is currently inconsistent regarding the opaque field that can be used as a special argument to av_buffer_create in order to be used during freeing the buffer: ff_cbs_alloc_unit_content and all the free functions used name this parameter as if it should contain a pointer to the unit whose content is about to be created; but both ff_cbs_alloc_unit_content as well as ff_cbs_h264_add_sei_message actually use a pointer to the CodedBitstreamContext as opaque. It should actually be neither, because it is unneeded (as is evidenced by the fact that none of the free functions use this pointer at all) and because it ties the unit's content to the lifetime of other objects, although a refcounted buffer is supposed to have its own lifetime that only ends when its reference count reaches zero. This problem manifests itself in the pointer becoming dangling. The pointer to the unit can become dangling if another unit is added to the fragment later as happens in the bitstream filters; in this case, the pointer can point to the wrong unit (if the fragment's unit array needn't be relocated) or it can point to where the array was earlier. It can also become dangling if the unit's content is meant to survive the resetting of the fragment it was originally read with. This applies to the extradata of H.264 and HEVC. The pointer to the context can become dangling if the context is closed before the content is freed. Although this doesn't seem to happen right now, it could happen, in particular if one uses different CodedBitstreamContexts for in- and output. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* cbs: Remove useless initializationsAndreas Rheinhardt2019-07-27
| | | | | | | | | | | Up until now, a temporary variable was used and initialized every time a value was read in CBS; if reading turned out to be successfull, this value was overwritten (without having ever been looked at) with the value read if reading was successfull; on failure the variable wasn't touched either. Therefore these initializations can be and have been removed. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* avcodec/cbs_h265: add support for Alpha Channel Info SEI messagesJames Almer2019-07-20
| | | | | | | As defined in sections F.14.2.8 and F.14.3.8 Reviewed-by: Mark Thompson <sw@jkqxz.net> Signed-off-by: James Almer <jamrial@gmail.com>
* cbs_h2645: Fix infinite loop in more_rbsp_dataAndreas Rheinhardt2019-07-20
| | | | | | | | | | | | | | | | | | | | | | cbs_h2645_read_more_rbsp_data does not handle malformed input very well: 1. If there were <= 8 bits left in the bitreader, these bits were read via show_bits. But show_bits requires the number of bits to be read to be > 0 (internally it shifts by 32 - number of bits to be read which is undefined behaviour if said number is zero; there is also an assert for this, but it is only an av_assert2). Furthermore, in this case a shift by -1 was performed which is of course undefined behaviour, too. 2. If there were > 0 and <= 8 bits left and all of them were zero (this can only happen for defective input), it was reported that there was further RBSP data. This can lead to an infinite loop in H.265's cbs_h265_read_extension_data corresponding to the [vsp]ps_extension_data_flag syntax elements. If the relevant flag indicates the (potential) occurence of these syntax elements, while all bits after this flag are zero, cbs_h2645_read_more_rbsp_data always returns 1 on x86. Given that a checked bitstream reader is used, we are also not "saved" by an overflow in the bitstream reader's index. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* configure, cbs_h2645: Remove unneeded golomb dependencyAndreas Rheinhardt2019-07-08
| | | | | | This has been forgotten in 44cde38c. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* cbs_h264, h264_metadata: Deleting SEI messages never failsAndreas Rheinhardt2019-07-08
| | | | | | | | | | | | Given the recent changes to ff_cbs_delete_unit, it is no longer sensible to use a return value for ff_cbs_h264_delete_sei_message; instead, use asserts to ensure that the required conditions are met and remove the callers' checks for the return value. Also, document said conditions. An assert that is essentially equivalent to the one used in ff_cbs_delete_unit has been removed, too. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* cbs: ff_cbs_delete_unit: Replace return value with assertAndreas Rheinhardt2019-07-08
| | | | | | | | | | ff_cbs_delete_unit never fails if the index of the unit to delete is valid, as it is with all current callers of the function. So just assert in ff_cbs_delete_unit that the index is valid and change the return value to void in order to remove the callers' checks for whether ff_cbs_delete_unit failed. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* avcodec/cbs_h264: add support for Alternative Transfer Characteristics SEI ↵James Almer2019-06-03
| | | | | | | message Reviewed-by: Mark Thompson <sw@jkqxz.net> Signed-off-by: James Almer <jamrial@gmail.com>
* avcodec/cbs_h2645: add macros to read and write fields with no custom range ↵James Almer2019-04-28
| | | | | | | of values Reviewed-by: Mark Thompson <sw@jkqxz.net> Signed-off-by: James Almer <jamrial@gmail.com>
* avcodec/cbs_h2645: add helper macros for signed valuesJames Almer2019-04-16
| | | | | Reviewed-by: Mark Thompson <sw@jkqxz.net> Signed-off-by: James Almer <jamrial@gmail.com>
* cbs_h2645: Avoid memcpy when splitting fragment #2Andreas Rheinhardt2019-01-23
| | | | | | | | | | | Now memcpy can be avoided for NAL units containing escapes, too. Particularly improves performance for files with hardcoded black bars. For such a file, time spent in cbs_h2645_split_fragment went down from 369410 decicycles to 327677 decicycles. (It were 379114 decicycles when every NAL unit was copied.) Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@googlemail.com>
* h2645_parse: Make ff_h2645_packet_split reference-compatibleAndreas Rheinhardt2019-01-23
| | | | | | | This is in preparation for a patch for cbs_h2645. Now the packet's rbsp_buffer can be owned by an AVBuffer. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@googlemail.com>
* cbs_h2645: Avoid memcpy when splitting fragmentAndreas Rheinhardt2018-11-22
| | | | | | | | | | | | Now memcpy is avoided for NAL units that don't contain 0x03 escape characters. Improves performance of cbs_h2645_fragment_add_nals from 36940 decicycles to 6364 decicycles based on 8 runs with a 5.1 Mb/s H.264 sample (262144 runs each). Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@googlemail.com> Signed-off-by: Mark Thompson <sw@jkqxz.net>
* cbs_h265: Add a lot more SEI parsing supportMark Thompson2018-11-18
| | | | | | Supports both prefix and suffix SEI, decoding all of the common SEI types and some more obscure ones. Most of this is tested by the existing tests in fate.
* cbs_h2645: Improve performance of writing slicesAndreas Rheinhardt2018-11-12
| | | | | | | | | | | | Instead of using a combination of bitreader and -writer for copying data, one can byte-align the (obsolete and removed) bitreader to improve performance. With the right alignment one can even use memcpy. The right alignment normally exists for CABAC and hence for H.265 in general. For aligned data this reduced the time to copy the slicedata from 776520 decicycles to 33889 with 262144 runs and a 6.5mb/s H.264 video. For unaligned data the number went down from 279196 to 97739 decicycles. Signed-off-by: Mark Thompson <sw@jkqxz.net>
* cbs_h2645: Allocate all internal buffers with paddingMark Thompson2018-10-22
| | | | | Any of these buffers (for both H.264 and H.265) might reasonably be parsed using the bitstream reader, so include padding on all of them.
* cbs_h264: Actually decompose end-of-sequence NAL unitsMark Thompson2018-10-22
| | | | | | | 64c50c0e978cd556dc2da238dfe0bb367e7c1ab9 declared support for decomposing them but omitted to implement it; this adds an implementation. Also do the same for end-of-stream NAL units, since they are equivalent.
* avcodec/cbs_h264: silence errors about end_of_seq nalusAman Gupta2018-10-15
| | | | | | [ffmpeg] AVBSFContext: Decomposition unimplemented for unit 4 (type 10). Signed-off-by: Aman Gupta <aman@tmm1.net>
* cbs_h264: Add support for mastering display SEI messagesMark Thompson2018-05-10
|
* cbs_h264: Add support for pan-scan rectangle SEI messagesMark Thompson2018-05-10
|
* cbs_h265: read/write content light level information SEI messageHaihao Xiang2018-05-10
| | | | Signed-off-by: Haihao Xiang <haihao.xiang@intel.com>
* cbs_h265: read/write HEVC PREFIX SEIHaihao Xiang2018-05-10
| | | | | | | | Similar to H264, cbs_h265_{read, write}_nal_unit() can handle HEVC prefix SEI NAL units. Currently mastering display colour volume SEI message is added only, we may add more SEI message if needed later Signed-off-by: Haihao Xiang <haihao.xiang@intel.com>
* avcodec/cbs_h2645: use AVBufferRef to store list of active parameter setsJames Almer2018-05-09
| | | | | | | | Removes unnecessary data copies, and partially fixes potential issues with dangling references held in said lists. Reviewed-by: Mark Thompson <sw@jkqxz.net> Signed-off-by: James Almer <jamrial@gmail.com>