summaryrefslogtreecommitdiff
path: root/libavcodec/cbs_av1.c
Commit message (Collapse)AuthorAgeFilesLines
* cbs_av1: Don't reject unknown metadataMark Thompson2023-05-171-0/+7
| | | | | | | Accept it and pass it through unchanged. The standard requires that decoders ignore unknown metadata, and indeed this is tested by some of the Argon coverage streams.
* lavc/cbs_av1: restore CodedBitstreamAV1Context when AVERROR(ENOSPC)Haihao Xiang2022-10-071-17/+47
| | | | | | | | | | | | | | | | | | | | | | The current pbc might be small for an obu frame, so a new pbc is required then parse this obu frame again. Because CodedBitstreamAV1Context has already been updated for this obu frame, we need to restore CodedBitstreamAV1Context, otherwise CodedBitstreamAV1Context doesn't match this obu frame when parsing obu frame again, e.g. CodedBitstreamAV1Context.order_hint. $ ffmpeg -i input.ivf -c:v copy -f null - [...] [av1_frame_merge @ 0x558bc3d6f880] ref_order_hint[i] does not match inferred value: 20, but should be 22. [av1_frame_merge @ 0x558bc3d6f880] Failed to write unit 1 (type 6). [av1_frame_merge @ 0x558bc3d6f880] Failed to write packet. [obu @ 0x558bc3d6e040] av1_frame_merge filter failed to send output packet Reviewed-by: James Almer <jamrial@gmail.com> Reviewed-by: Wenbin Chen <wenbin.chen@intel.com> Signed-off-by: Haihao Xiang <haihao.xiang@intel.com>
* avcodec/cbs: Remove ff_cbs_alloc_unit_contentAndreas Rheinhardt2022-08-081-1/+1
| | | | | | | It is no longer used. Also rename ff_cbs_alloc_unit_content2 to ff_cbs_alloc_unit_content. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* all: Remove unnecessary libavcodec/internal.h inclusionsAndreas Rheinhardt2022-02-081-1/+1
| | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/cbs: Make ff_cbs_insert_unit_data() always append the new unitAndreas Rheinhardt2022-02-081-1/+1
| | | | | | | All split functions (the only users of this function) only append units. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/cbs_av1: add an option to select an operating pointJames Almer2021-01-041-1/+29
| | | | | | | | | This implements the function drop_obu() as defined in Setion 6.2.1 from the spec. In a reading only scenario, units that belong to an operating point the caller doesn't want should not be parsed. Signed-off-by: James Almer <jamrial@gmail.com>
* avcodec/cbs_av1: ensure Sequence Header unit content is always reference countedJames Almer2020-12-011-0/+4
| | | | | | Prevents a NULL pointer dereference. Signed-off-by: James Almer <jamrial@gmail.com>
* avcodec/cbs_av1: add support for standard MP4/Matroska extradataJan Ekström2020-11-241-0/+34
| | | | | This way API clients can just pass the AV1CodecConfigurationRecord as extradata as-is without further filtering.
* avcodec/cbs_av1: add a range check to tg_endJames Almer2020-11-111-0/+1
| | | | | | | | | | | Section 6.10.1 of the AV1 spec states: It is a requirement of bitstream conformance that the value of tg_start is equal to the value of TileNum at the point that tile_group_obu is invoked. It is a requirement of bitstream conformance that the value of tg_end is greater than or equal to tg_start. Signed-off-by: James Almer <jamrial@gmail.com>
* avcodec/cbs_av1: Free content in cbs_av1_free_metadata()Michael Niedermayer2020-10-121-0/+1
| | | | | | | | | Fixes: memleak Fixes: 25838/clusterfuzz-testcase-minimized-ffmpeg_BSF_TRACE_HEADERS_fuzzer-5736255957237760 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Reviewed-by: James Almer <jamrial@gmail.com> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avcodec/cbs_av1: implement a CodedBitstreamType.flush() callbackJames Almer2020-09-291-0/+14
| | | | Signed-off-by: James Almer <jamrial@gmail.com>
* cbs_av1: Use table-based alloc/freeMark Thompson2020-09-021-46/+39
|
* avcodec/cbs_av1: always store temporal_id and spatial_id in ↵James Almer2020-08-231-6/+0
| | | | | | | | | CodedBitstreamAV1Context Also infer them when not coded in the bitstream. Reviewed-by: jkqxz Signed-off-by: James Almer <jamrial@gmail.com>
* Revert "avcodec/cbs_av1: keep separate reference frame state for reading and ↵James Almer2020-07-161-4/+0
| | | | | | | | writing" This reverts commit 4e2bef6a82b356772a5919c51c9be1530268bd79. It's no longer needed now that all the bsfs use separate contexts for reading and writing.
* avcodec/cbs: Remove unused function parametersAndreas Rheinhardt2020-07-071-2/+2
| | | | | | | | 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_av1: Simplify writing uvlc elementsAndreas Rheinhardt2020-06-241-10/+5
| | | | | | | There is no reason to special-case writing a value of zero as uvlc element as the generic code is perfectly capable of doing so. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* avcodec/cbs_av1: Fix writing uvlc numbers >= INT_MAXAndreas Rheinhardt2020-06-241-2/+3
| | | | | | | | | | Fixes: assertion failure Fixes: left shift of 1 by 31 places cannot be represented in type 'int' Fixes: 23264/clusterfuzz-testcase-minimized-ffmpeg_BSF_AV1_METADATA_fuzzer-6308429248593920 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* avcodec/cbs_av1: abort when written inferred values don't matchJames Almer2020-06-141-1/+2
| | | | | | | | | | 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: Avoid leaving the ... out in calls to variadic macrosAndreas Rheinhardt2020-04-121-8/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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_av1: Check leb128 values readMichael Niedermayer2020-01-181-0/+3
| | | | | | | | | | | "It is a requirement of bitstream conformance that the value returned from the leb128 parsing process is less than or equal to (1 << 32) - 1." Fixes: assertion failure Fixes: 19293/clusterfuzz-testcase-minimized-ffmpeg_BSF_TRACE_HEADERS_fuzzer-5749508361420800 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avcodec/cbs_av1: avoid reading trailing bits when obu type is OBU_TILE_LISTFei Wang2019-12-101-0/+1
| | | | | Signed-off-by: Fei Wang <fei.w.wang@intel.com> Signed-off-by: James Almer <jamrial@gmail.com>
* avcodec/cbs_av1: keep separate reference frame state for reading and writingJames Almer2019-11-181-0/+4
| | | | | | | | | | | In scearios where a Temporal Unit is written right after reading it using the same CBS context (av1_metadata, av1_frame_merge, etc), the reference frame state used by the writer must not be the state that's the result of the reader having already parsed the current frame in question. This fixes writing Switch frames, and frames using short ref signaling. Signed-off-by: James Almer <jamrial@gmail.com>
* avcodec/cbs: Factor out common code for writing unitsAndreas Rheinhardt2019-11-171-54/+5
| | | | | | | | | | | | | | | | | 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_av1: support one byte long OBUs when the size is not set in the ↵James Almer2019-11-121-7/+6
| | | | | | | | | bitstream This will be needed by the next commit, where packets with a single Temporal Delimiter OBU with no size will need to be parsed Signed-off-by: James Almer <jamrial@gmail.com>
* avcodec/cbs_av1: Make overread check more robustAndreas Rheinhardt2019-09-291-2/+2
| | | | | | | | | | | When performing a comparison of a signed int and an unsigned int, the signed int is first converted to an unsigned int, so that negative values are being treated as big, positive values. This can become a problem in an overread check, namely when an overread already happened. So change the type of the variable containing the amount of bits that need to be left to signed. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* cbs: Don't set AVBuffer's opaqueAndreas Rheinhardt2019-07-291-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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-271-7/+7
| | | | | | | | | | | 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>
* cbs_av1, cbs_jpeg, cbs_mpeg2, cbs_vp9: Fix undefAndreas Rheinhardt2019-06-071-3/+2
| | | | | | | | | READ has already been undefined at this point; it is obviously intended to undef WRITE. Furthermore, leb128 (in cbs_av1) was undefined too often and inconsistently. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* avcodec/cbs_av1: use the new signed value read/write functionsJames Almer2019-04-161-60/+8
| | | | | Reviewed-by: Mark Thompson <sw@jkqxz.net> Signed-off-by: James Almer <jamrial@gmail.com>
* avcodec/cbs_av1: add support for Padding OBUsJames Almer2019-04-141-0/+20
| | | | | | | Based on itut_t35 Matadata OBU parsing code. Reviewed-by: Mark Thompson <sw@jkqxz.net> Signed-off-by: James Almer <jamrial@gmail.com>
* avcodec/cbs_av1: add a function to strip trailing zeroes from a buffer sizeJames Almer2019-04-141-0/+11
| | | | | | | Factor it out from cbs_av1_read_metadata_itut_t35() Reviewed-by: Mark Thompson <sw@jkqxz.net> Signed-off-by: James Almer <jamrial@gmail.com>
* avcodec/cbs_av1: fix parsing spatial_idJames Almer2019-04-021-1/+1
| | | | | Reviewed-by: Mark Thompson <sw@jkqxz.net> Signed-off-by: James Almer <jamrial@gmail.com>
* avcodec/cbs_av1: don't call cbs_av1_read_trailing_bits() when no bits remain ↵James Almer2019-02-101-2/+6
| | | | | | | in the OBU Reviewed-by: jkqxz Signed-off-by: James Almer <jamrial@gmail.com>
* cbs_av1: Fix reading of overlong uvlc codesMark Thompson2018-12-221-18/+40
| | | | | | | | | | | | | | | | The specification allows 2^32-1 to be encoded as any number of zeroes greater than 31, followed by a one. This previously failed because the trace code would overflow the array containing the string representation of the bits if there were more than 63 zeroes. Fix that by splitting the trace output into batches, and at the same time move it out of the default path. (While this seems likely to be a specification error, libaom does support it so we probably should as well.) From a test case by keval shah <skeval65@gmail.com>. Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
* lavc/cbs: Do not use format specifier "z" on Windows.Carl Eugen Hoyos2018-12-171-5/+5
|
* avcodec/cbs_av1: don't abort when splitting Temporal Units containing OBUs ↵James Almer2018-11-181-10/+6
| | | | | | | | | | with no obu_size field The ISOBMFF and Matroska specs allow the last OBU in a Sample/Block to have obu_has_size_field equal to 0. Reviewed-by: Mark Thompson <sw@jkqxz.net> Signed-off-by: James Almer <jamrial@gmail.com>
* avcodec/cbs_av1: fix parsing signed integer valuesJames Almer2018-11-141-21/+9
| | | | | Reviewed-by: Mark Thompson <sw@jkqxz.net> Signed-off-by: James Almer <jamrial@gmail.com>
* cbs_av1: Support redundant frame headersMark Thompson2018-11-051-4/+12
|
* cbs_av1: Fix header writing when already alignedMark Thompson2018-11-051-1/+1
|
* lavc: Add coded bitstream read/write support for AV1Mark Thompson2018-09-261-0/+1320