summaryrefslogtreecommitdiff
path: root/libavcodec/h264_slice.c
Commit message (Collapse)AuthorAge
* avcodec/decode: Extend ff_hwaccel_frame_priv_alloc()'s taskAndreas Rheinhardt2023-08-07
| | | | | | | | | | | | | | | | All usages of ff_hwaccel_frame_priv_alloc() have the same pattern: Check for whether a hwaccel is in use; check whether it needs private frame-specific data; allocate the AVBuffer and set it. This commit modifies ff_hwaccel_frame_priv_alloc() to perform this task on its own. (It also seems that the H.264 decoder did not perform proper cleanup in case the buffer could not be allocated. This has been changed.) Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/utils: Move ff_color_frame() to its only userAndreas Rheinhardt2023-08-05
| | | | | | Namely h264_slice.c. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/h264_slice: Remove always-false checkAndreas Rheinhardt2023-07-30
| | | | | | | The H.264 decoder, the only codec with which this code is ever called, does not set AVCodec.pix_fmts. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec: move content light level SEI handling to h2645_seiJan Ekström2023-07-27
| | | | | | | | | | This allows this common H.274 SEI to be parsed from both H.264 as well as HEVC, as well as probably from VVC in the future. Generally attempts to keep the original code as similar as possible. FATE test refererence changes only change the order of side data export within a single frame. Nothing else seems to have changed.
* avcodec: move mastering display colour volume SEI handling to h2645_seiJan Ekström2023-07-27
| | | | | | | | | | This allows this common H.274 SEI to be parsed from both H.264 as well as HEVC, as well as probably from VVC in the future. Generally attempts to keep the original code as similar as possible. FATE test refererence changes only change the order of side data export within a single frame. Nothing else seems to have changed.
* h264dec: add Vulkan hwaccelLynne2023-05-29
| | | | Thanks to Dave Airlie for figuring out a lot of the parameters.
* avcodec: add AVHWAccel.free_frame_priv callbackLynne2023-05-29
|
* lavc: deprecate AVCodecContext.ticks_per_frameAnton Khirnov2023-05-15
| | | | | | | | For encoding, this field is entirely redundant with AVCodecContext.framerate. For decoding, this field is entirely redundant with AV_CODEC_PROP_FIELDS.
* avcodec: use the new AVFrame key_frame flag in all decoders and encodersJames Almer2023-05-04
| | | | Signed-off-by: James Almer <jamrial@gmail.com>
* avcodec: use the new AVFrame interlace flags in all decoders and encodersJames Almer2023-05-04
| | | | Signed-off-by: James Almer <jamrial@gmail.com>
* vaapi: support VAProfileH264High10 decodingjianfeng.zheng2023-04-17
| | | | | | see https://github.com/intel/libva/pull/664 Signed-off-by: jianfeng.zheng <jianfeng.zheng@mthreads.com>
* avutil/frame: deprecate AVFrame.coded_picture_number and display_picture_numberMarton Balint2023-02-13
| | | | | | | | Their usefulness is questionable, very few decoders set them, and their type should have been int64_t. A replacement field can be added later if a valid use case is found. Signed-off-by: Marton Balint <cus@passwd.hu>
* avcodec: add AVCodecContext.frame_num as 64 bit variant to frame_numberMarton Balint2023-02-13
| | | | | | | | | | Frame counters can overflow relatively easily (INT_MAX number of frames is slightly more than 1 year for 60 fps content), so make sure we use 64 bit values for them. Also deprecate the old 32 bit frame_number attribute. Signed-off-by: Marton Balint <cus@passwd.hu>
* avcodec/h264_slice: Use unsigned for fgs seed computationMichael Niedermayer2023-01-11
| | | | | | | | Fixes: signed integer overflow: 2147481600 + 13408 cannot be represented in type 'int' Fixes: 53963/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_H264_fuzzer-4650467311616000 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avcodec/h2645_sei: Factor attaching film grain side-data to frame outAndreas Rheinhardt2022-12-01
| | | | | | | This unfortunately involved adding some parameters to ff_h2645_sei_to_frame() that will be mostly unused. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/(h264|hevc)_ps: Factor common VUI code outAndreas Rheinhardt2022-12-01
| | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/h2645_sei: Also support Active Format Descriptor for HEVCAndreas Rheinhardt2022-12-01
| | | | | | | | | | | | | | | It is valid for HEVC; in fact, the ATSC-HEVC spec [1] simply refers to the relevant H.264 spec. It is also trivial to implement now: Just move applying AFD to ff_h2645_sei_to_frame() and stop ignoring AFD when parsing a HEVC SEI containing it. A FATE-test for this has been added. [1]: https://www.atsc.org/atsc-documents/a3412017-video-hevc/ Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/h2645_sei: Attach AVStereo3D side data genericallyAndreas Rheinhardt2022-12-01
| | | | | | | There are only slight differences between H.264 and HEVC for this side data, so it makes sense to share the code. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/h264_sei, sei: Make H264_SEI_FpaType genericAndreas Rheinhardt2022-12-01
| | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/h2645_sei: Factor out applying SEIs to framesAndreas Rheinhardt2022-12-01
| | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/h2645_sei: Factor updating H.2645 SEIs outAndreas Rheinhardt2022-12-01
| | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/h2645_sei: Factor parsing common SEI messages outAndreas Rheinhardt2022-12-01
| | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/internal: Move ff_set_sar() to decode.hAndreas Rheinhardt2022-08-27
| | | | | | | Only used by decoders, as the SAR has to be set by the user when encoding. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec: Constify ThreadFrames if possibleAndreas Rheinhardt2022-07-31
| | | | | | | This is possible now that ff_thread_await_progress() accepts a const ThreadFrame*. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/h264dec: Move ERContext to H264ContextAndreas Rheinhardt2022-03-25
| | | | | | | | | | | | | | | | Since 7be2d2a70cd20d88fd826a83f87037d14681a579 only one context is used. Moving it to H264Context from H264SliceContext is natural. One could access the ERContext from H264SliceContext via H264SliceContext.h264->er; yet H264SliceContext.h264 should naturally be const-qualified, because slice threads should not modify the main context. The ERContext is an exception to this, as ff_er_add_slice() is intended to be called simultaneously by multiple threads. And for this one needs a pointer whose pointed-to-type is not const-qualified. Reviewed-by: Michael Niedermayer <michael@niedermayer.cc> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/h264_slice: Fix decoding undamaged input with slicesAndreas Rheinhardt2022-03-25
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | ff_er_frame_start() initializes ERContext.error_count to three times the number of macroblocks to decode. Later ff_er_add_slice() reduces this number by the amount of macroblocks whose AC resp. DC resp. MV have been finished (so every correctly decoded MB counts three times). So the frame has been decoded correctly if error_count is zero at the end. The H.264 decoder uses multiple ERContexts when using slice threading and therefore combines these error counts: The first slice's ERContext is intended to be initialized by ff_er_frame_start(), error_count of all the other slice contexts is intended to be zeroed initially and all afterwards all the error_counts are summed. Yet commit 43b434210e597d484aef57c4139c3126d22b7e2b (probably unintentionally) changed the code to set the first slice's error_count to zero as well. This leads to bogus error messages in case one decodes an input video using multiple slices with slice threading with error concealment enabled (which is not the default) ("concealing 0 DC, 0 AC, 0 MV errors in [IPB] frame"); furthermore the returned frame is marked as corrupt as well (ffmpeg reports "corrupt decoded frame in stream %d" for this). This can be fixed easily given that only the first ERContext is really used since 7be2d2a70cd20d88fd826a83f87037d14681a579: Don't reset the error_count; and don't sum the error counts as well. Reviewed-by: Michael Niedermayer <michael@niedermayer.cc> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* configure: Use a separate config_components.h header for $ALL_COMPONENTSMartin Storsjö2022-03-16
| | | | | | | | This avoids unnecessary rebuilds of most source files if only the list of enabled components has changed, but not the other properties of the build, set in config.h. Signed-off-by: Martin Storsjö <martin@martin.st>
* avcodec/thread: Don't use ThreadFrame when unnecessaryAndreas Rheinhardt2022-02-09
| | | | | | | | | | | | | | | | | | | | | | | The majority of frame-threaded decoders (mainly the intra-only) need exactly one part of ThreadFrame: The AVFrame. They don't need the owners nor the progress, yet they had to use it because ff_thread_(get|release)_buffer() requires it. This commit changes this and makes these functions work with ordinary AVFrames; the decoders that need the extra fields for progress use ff_thread_(get|release)_ext_buffer() which work exactly as ff_thread_(get|release)_buffer() used to do. This also avoids some unnecessary allocations of progress AVBuffers, namely for H.264 and HEVC film grain frames: These frames are not used for synchronization and therefore don't need a ThreadFrame. Also move the ThreadFrame structure as well as ff_thread_ref_frame() to threadframe.h, the header for frame-threaded decoders with inter-frame dependencies. Reviewed-by: Anton Khirnov <anton@khirnov.net> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/threadframe: Add ff_thread_(get|release)_ext_buffer()Andreas Rheinhardt2022-02-09
| | | | | | | | | These will be used by the codecs that need allocated progress and is in preparation for no longer using ThreadFrame by the codecs that don't. Reviewed-by: Anton Khirnov <anton@khirnov.net> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/thread: Move ff_thread_(await|report)_progress to new headerAndreas Rheinhardt2022-02-09
| | | | | | | | | | This is in preparation for further commits that will stop using ThreadFrame for frame-threaded codecs that don't use ff_thread_(await|report)_progress(); the API for those codecs having inter-frame depdendencies will live in threadframe.h. Reviewed-by: Anton Khirnov <anton@khirnov.net> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/h264*: Remove unnecessary h264_mvpred.h inclusionsAndreas Rheinhardt2022-01-26
| | | | | | | This is only needed by h264_cabac.c and h264_cavlc.c. Also fix up the other headers while at it. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* lavc/h264: replace MAX_DELAYED_PIC_COUNT by H264_MAX_DPB_FRAMESAnton Khirnov2022-01-26
|
* lavc/h264: replace MAX_DELAYED_PIC_COUNT with FF_ARRAY_ELEMS where appropriateAnton Khirnov2022-01-26
|
* avcodec/h264_slice: Inline H264 codec idAndreas Rheinhardt2022-01-13
| | | | | | This code is only reached by the H.264 decoder. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/h264_slice, mpeg4videodec: Don't use %s to write single charAndreas Rheinhardt2022-01-13
| | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/h2645: Fix SEI->display matrix transformationAndreas Rheinhardt2021-12-23
| | | | | | | | | | | The earlier code did not account for the fact that av_display_rotation_set() wants the angle in the anticlockwise direction (despite what its documentation stated for a long time); furthermore, the H.2645 spec wants the flips applied first, whereas our code did it the other way around. This can be fixed by negating the angle once for every flip. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* lavc/h264dec: support all color formats in videotoolbox hwaccelrcombs2021-11-28
|
* avcodec/h264_slice: Check idr_pic_idMichael Niedermayer2021-10-09
| | | | | | | | Fixes: left shift of negative value -1 Fixes: 39223/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_H264_fuzzer-5498831521841152 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avcodec/h264_slice: don't allocate film grain buffers when using hwaccelJames Almer2021-08-25
| | | | | | Fixes regression since 66845cffc3bbb17f91294d15cd6f57f3df3bce97 Signed-off-by: James Almer <jamrial@gmail.com>
* avcodec/h264_slice: signal the presence of Film Grain in the decoder contextJames Almer2021-08-24
| | | | Signed-off-by: James Almer <jamrial@gmail.com>
* avcodec/h264dec: apply H.274 film grainNiklas Haas2021-08-24
| | | | | | | | | | | | | | | | | | | | | | | Because we need access to ref frames without film grain applied, we have to add an extra AVFrame to H264Picture to avoid messing with the original. This requires some amount of overhead to make the reference moves work out, but it allows us to benefit from frame multithreading for film grain application "for free". Unfortunately, this approach requires twice as much RAM to be constantly allocated for ref frames, due to the need for an extra buffer per H264Picture. In theory, we could get away with freeing up this memory as soon as it's no longer needed (since ref frames do not need film grain buffers any longer), but trying to call ff_thread_release_buffer() from output_frame() conflicts with possible later accesses to that same frame and I'm not sure how to synchronize that well. Tested on all three cases of (no fg), (fg present but exported) and (fg present and not exported), with and without threading. Co-authored-by: James Almer <jamrial@gmail.com> Signed-off-by: Niklas Haas <git@haasn.dev> Signed-off-by: James Almer <jamrial@gmail.com>
* avcodec/h264_slice: compute and export film grain seedNiklas Haas2021-08-24
| | | | | | | | | | | | | | | | | | | | | | | | From SMPTE RDD 5-2006, the grain seed is to be computed from the following definition of `pic_offset`: > When decoding H.264 | MPEG-4 AVC bitstreams, pic_offset is defined as > follows: > - pic_offset = PicOrderCnt(CurrPic) + (PicOrderCnt_offset << 5) > where: > - PicOrderCnt(CurrPic) is the picture order count of the current frame, > which shall be derived from [the video stream]. > > - PicOrderCnt_offset is set to idr_pic_id on IDR frames. idr_pic_id > shall be read from the slice header of [the video stream]. On non-IDR I > frames, PicOrderCnt_offset is set to 0. A frame shall be classified as I > frame when all its slices are I slices, which may be optionally > designated by setting primary_pic_type to 0 in the access delimiter NAL > unit. Otherwise, PicOrderCnt_offset it not changed. PicOrderCnt_offset is > updated in decoding order. Co-authored-by: James Almer <jamrial@gmail.com> Signed-off-by: Niklas Haas <git@haasn.dev> Signed-off-by: James Almer <jamrial@gmail.com>
* avcodec/h264_slice: use ff_h264_replace_picture when syncing thread contextsJames Almer2021-08-10
| | | | Signed-off-by: James Almer <jamrial@gmail.com>
* avcodec/h264_slice: clear old slice POC values on parsing failureJames Almer2021-08-10
| | | | | | | | If a slice header fails to parse, and the next one uses different Sequence and Picture parameter sets, certain values may not be read if they are not coded, resulting in the previous slice values being used. Signed-off-by: James Almer <jamrial@gmail.com>
* avcodec/h264_sei: parse and export Film Grain Characteristics SEI messagesJames Almer2021-07-23
| | | | Signed-off-by: James Almer <jamrial@gmail.com>
* avcodec: Remove some unnecessary mpegvideo.h inclusionsAndreas Rheinhardt2021-07-22
| | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/h264dec: update exported AVOptions in the user-facing contextJames Almer2021-04-14
| | | | | | | | Based on a patch by Hendrik Leppkes. Fixes ticket #9176. Signed-off-by: James Almer <jamrial@gmail.com>
* avcodec/h264_slice: Check input SPS in ff_h264_update_thread_context()Michael Niedermayer2021-03-31
| | | | | | | | Fixes: crash Fixes: check_pkt.mp4 Found-by: Rafael Dutra <rafael.dutra@cispa.de> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avcodec/h264_slice: Check sps in h264_slice_header_init()Michael Niedermayer2021-03-26
| | | | | | | | | Fixes: null pointer dereference Fixes: h264_slice_header_init.mp4 Found-by: Rafael Dutra <rafael.dutra@cispa.de> Tested-by: Rafael Dutra <rafael.dutra@cispa.de> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avcodec/h264_slice: don't copy frame data during error concealmentJames Almer2021-03-11
| | | | | | | | | In addition to the fact that av_image_copy() cannot handle hardware pixel formats, h->short_ref[0]->f may not be writable at this point. Based on a patch by Hendrik Leppkes. Signed-off-by: James Almer <jamrial@gmail.com>