summaryrefslogtreecommitdiff
path: root/libavcodec/h264_slice.c
Commit message (Collapse)AuthorAge
* 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>
* avcodec/h264_slice: fix undefined integer overflow with POC in error concealmentMichael Niedermayer2020-10-18
| | | | | | | | | | Alternatively the POC could be changed to 64bit. the large values seem to be within what is allowed. Fixes: signed integer overflow: 2147483646 + 2 cannot be represented in type 'int' Fixes: 26076/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_H264_fuzzer-5711127201447936 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: use av_buffer_replace() to simplify codeJames Almer2020-10-05
| | | | | | | Based on eff289ce9f030f023e218ee7ce354d4f0e035b6d. Reviewed-by: Anton Khirnov <anton@khirnov.net> Signed-off-by: James Almer <jamrial@gmail.com>
* avcodec/h264_slice: sync User Data Unregistered SEI buffers across threadsJames Almer2020-09-23
| | | | Signed-off-by: James Almer <jamrial@gmail.com>
* avcodec: use av_timecode_make_smpte_tc_string2 in hevc and h264 decoderMarton Balint2020-09-13
| | | | Signed-off-by: Marton Balint <cus@passwd.hu>
* avcodec/h264_slice: add timecode metadataLimin Wang2020-07-09
| | | | | | | | Please test with below command: ./ffplay -vf drawtext="fontfile=/Library/Fonts/Arial.ttf:text=\\'%{metadata\\:timecode}\\'" \ ../fate-suite/h264/crew_cif_timecode-2.h264 Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
* avcodec/h264_slice: replace cur->f with out for better readabilityLimin Wang2020-07-09
| | | | Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
* avcodec/h264_slice: use av_timecode_get_smpte()Limin Wang2020-06-28
| | | | Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
* avcodec/h264: create user data unregistered SEI side data for H.264Limin Wang2020-06-15
| | | | Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
* h264dec: support exporting QP tables through the AVVideoEncParams APIAnton Khirnov2020-05-25
|
* h264_ps: make the PPS hold a reference to its SPSAnton Khirnov2020-04-10
| | | | | | | | It represents the relationship between them more naturally and will be useful in the following commits. Allows significantly more frames in fate-h264-attachment-631 to be decoded.
* h264_sei: parse the picture timing SEIs correctlyAnton Khirnov2020-04-10
| | | | | | | | | Those SEIs refer to the currently active SPS. However, since the SEI NALUs precede the coded picture data in the bitstream, the active SPS is in general not known when we are decoding the SEI. Therefore, store the content of the picture timing SEIs and actually parse it when the active SPS is known.
* h264dec: do not export the chroma sample location immediately on parsing the SPSAnton Khirnov2020-03-20
| | | | | This SPS is not necessarily the one that will be used. Export the chroma location along with all the other SPS properties.
* h264dec: do not return a value from init_dimensions()Anton Khirnov2020-03-16
| | | | There are no failure cases left in this function.
* libavcodec, libpostproc: Remove outcommented START/STOP_TIMERAndreas Rheinhardt2020-03-14
| | | | | | | as well as includes of libavutil/timer.h. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avcodec/h264_slice: clear frame only on gaps when it is not otherwise ↵Michael Niedermayer2019-09-24
| | | | | | | | | | initilaized Fixes: Timeout (53sec -> 31sec) Fixes: 16908/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_H264_fuzzer-5711207859748864 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: set the SEI parameters early on the AVCodecContextSteve Lhomme2019-07-14
| | | | | | | | | It's better to do it before the buffers are actually created. At least in VLC we currently don't support changing some parameters dynamically easily so we don't use the information if it comes after the buffer are created. Co-authored-by: James Almer <jamrial@gmail.com> Signed-off-by: James Almer <jamrial@gmail.com>
* avcodec/h264_slice: Fix integer overflow in implicit_weight_table()Michael Niedermayer2019-01-12
| | | | | | | | Fixes: signed integer overflow: 2 * 2132811760 cannot be represented in type 'int' Fixes: 11156/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_H264_fuzzer-6237685933408256 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* h264/pic_timing: support multiple timecodesJosh de Kock2018-10-23
|
* lavc/h264: create AVFrame side data from H.264 timecodesDevin Heitmueller2018-10-23
| | | | | | | | | Create SMPTE ST 12-1 timecodes based on H.264 SEI picture timing info. For framerates > 30 FPS, the field flag is used in conjunction with pairs of frames which contain the same frame timestamp in S12M. Ensure the field is properly set per the spec.
* h264_slice: Copy the value of x264_build before calling ↵Derek Buitenhuis2018-10-09
| | | | | | | | | | | | | h264_slice_header_init during thread init If we don't copy this value first, it is seen as 0 by h264_slice_header_init, due to zero-allocation of the new context, triggering an old hack that multiplied the denominator by 2 for files produced by old x264 versions, but only if more than one thread was used. Fixes #7475 and #7083. Signed-off-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
* h264: Support multi-field closed captions by using AVBufferRef and not ↵Kieran Kunhya2018-08-17
| | | | | | resetting per field Signed-off-by: Josh de Kock <joshdk@obe.tv>
* h264_slice: Fix return of incomplete frames from decoderJohn Stebbins2018-06-28
| | | | | | | | | | | When not using libavformat for demuxing, AVCodecContext.has_b_frames gets set too late causing the recovery frame heuristic in h264_refs to incorrectly flag an early frame as recovered. This patch sets has_b_frames earlier to prevent improperly flagging the frame as recovered. Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avcodec/h264_slice: Fix integer overflow with last_pocMichael Niedermayer2018-04-12
| | | | | | | | Fixes: signed integer overflow: 2147483646 - -2816 cannot be represented in type 'int' Fixes: crbug 823145 Reported-by: Matt Wolenetz <wolenetz@google.com> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avcodec/h264: Increase field_poc to 64bit in ff_h264_init_poc() to detect ↵Michael Niedermayer2018-02-17
| | | | | | | | | | overflows Fixes: Integer overflow Fixes: 5746/clusterfuzz-testcase-minimized-6270097623613440 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>