1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-11-26 19:01:44 +02:00
Commit Graph

458 Commits

Author SHA1 Message Date
Andreas Rheinhardt
02220b88fc avcodec/thread: Don't use ThreadFrame when unnecessary
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>
2022-02-09 17:22:35 +01:00
Andreas Rheinhardt
f025b8e110 avcodec/threadframe: Add ff_thread_(get|release)_ext_buffer()
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>
2022-02-09 17:22:23 +01:00
Andreas Rheinhardt
b3551b6072 avcodec/thread: Move ff_thread_(await|report)_progress to new header
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>
2022-02-09 17:22:16 +01:00
Andreas Rheinhardt
5fef87f140 avcodec/h264*: Remove unnecessary h264_mvpred.h inclusions
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>
2022-01-26 15:30:54 +01:00
Anton Khirnov
b6f3334a13 lavc/h264: replace MAX_DELAYED_PIC_COUNT by H264_MAX_DPB_FRAMES 2022-01-26 15:23:30 +01:00
Anton Khirnov
ef4537bd1b lavc/h264: replace MAX_DELAYED_PIC_COUNT with FF_ARRAY_ELEMS where appropriate 2022-01-26 15:23:29 +01:00
Andreas Rheinhardt
d0bf242d02 avcodec/h264_slice: Inline H264 codec id
This code is only reached by the H.264 decoder.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-01-13 08:26:26 +01:00
Andreas Rheinhardt
75a3268bee avcodec/h264_slice, mpeg4videodec: Don't use %s to write single char
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-01-13 08:24:47 +01:00
Andreas Rheinhardt
ab6f9d86a9 avcodec/h2645: Fix SEI->display matrix transformation
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>
2021-12-23 18:09:46 +01:00
rcombs
caad1146e2 lavc/h264dec: support all color formats in videotoolbox hwaccel 2021-11-28 16:40:43 -06:00
Michael Niedermayer
f054871a65 avcodec/h264_slice: Check idr_pic_id
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>
2021-10-09 11:42:16 +02:00
James Almer
9677053884 avcodec/h264_slice: don't allocate film grain buffers when using hwaccel
Fixes regression since 66845cffc3

Signed-off-by: James Almer <jamrial@gmail.com>
2021-08-25 18:01:00 -03:00
James Almer
ab25874e32 avcodec/h264_slice: signal the presence of Film Grain in the decoder context
Signed-off-by: James Almer <jamrial@gmail.com>
2021-08-24 10:00:20 -03:00
Niklas Haas
66845cffc3 avcodec/h264dec: apply H.274 film grain
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>
2021-08-24 09:58:52 -03:00
Niklas Haas
cf37c3fb6c avcodec/h264_slice: compute and export film grain seed
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>
2021-08-24 09:58:52 -03:00
James Almer
90bf83d6f1 avcodec/h264_slice: use ff_h264_replace_picture when syncing thread contexts
Signed-off-by: James Almer <jamrial@gmail.com>
2021-08-10 15:11:46 -03:00
James Almer
ce4a31cd1f avcodec/h264_slice: clear old slice POC values on parsing failure
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>
2021-08-10 15:11:41 -03:00
James Almer
4ff73add5d avcodec/h264_sei: parse and export Film Grain Characteristics SEI messages
Signed-off-by: James Almer <jamrial@gmail.com>
2021-07-23 11:06:45 -03:00
Andreas Rheinhardt
e0b4fe0efa avcodec: Remove some unnecessary mpegvideo.h inclusions
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-07-22 15:02:46 +02:00
James Almer
42551a3407 avcodec/h264dec: update exported AVOptions in the user-facing context
Based on a patch by Hendrik Leppkes.

Fixes ticket #9176.

Signed-off-by: James Almer <jamrial@gmail.com>
2021-04-14 20:07:52 -03:00
Michael Niedermayer
ceae92cb29 avcodec/h264_slice: Check input SPS in ff_h264_update_thread_context()
Fixes: crash
Fixes: check_pkt.mp4

Found-by: Rafael Dutra <rafael.dutra@cispa.de>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2021-03-31 23:09:35 +02:00
Michael Niedermayer
8047243899 avcodec/h264_slice: Check sps in h264_slice_header_init()
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>
2021-03-26 16:00:14 +01:00
James Almer
99042c2bf6 avcodec/h264_slice: don't copy frame data during error concealment
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>
2021-03-11 17:57:37 -03:00
Michael Niedermayer
182d7a7427 avcodec/h264_slice: fix undefined integer overflow with POC in error concealment
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>
2020-10-18 21:27:23 +02:00
James Almer
0b6541368d avcodec/h264_slice: use av_buffer_replace() to simplify code
Based on eff289ce9f.

Reviewed-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: James Almer <jamrial@gmail.com>
2020-10-05 11:20:17 -03:00
James Almer
184fc42b46 avcodec/h264_slice: sync User Data Unregistered SEI buffers across threads
Signed-off-by: James Almer <jamrial@gmail.com>
2020-09-23 10:22:28 -03:00
Marton Balint
5673802511 avcodec: use av_timecode_make_smpte_tc_string2 in hevc and h264 decoder
Signed-off-by: Marton Balint <cus@passwd.hu>
2020-09-13 17:51:57 +02:00
Limin Wang
10c7745ae9 avcodec/h264_slice: add timecode metadata
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>
2020-07-09 22:18:42 +08:00
Limin Wang
b531216e6a avcodec/h264_slice: replace cur->f with out for better readability
Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
2020-07-09 22:18:42 +08:00
Limin Wang
acca2aecb0 avcodec/h264_slice: use av_timecode_get_smpte()
Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
2020-06-28 21:00:52 +08:00
Limin Wang
4b3b217e30 avcodec/h264: create user data unregistered SEI side data for H.264
Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
2020-06-15 07:19:55 +08:00
Anton Khirnov
064b875e89 h264dec: support exporting QP tables through the AVVideoEncParams API 2020-05-25 11:59:42 +02:00
Anton Khirnov
5e316096fa h264_ps: make the PPS hold a reference to its SPS
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.
2020-04-10 15:52:41 +02:00
Anton Khirnov
ec7f33a38e h264_sei: parse the picture timing SEIs correctly
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.
2020-04-10 15:52:22 +02:00
Anton Khirnov
6eae7e5644 h264dec: do not export the chroma sample location immediately on parsing the SPS
This SPS is not necessarily the one that will be used. Export the chroma
location along with all the other SPS properties.
2020-03-20 09:16:05 +01:00
Anton Khirnov
e38b8b0dc6 h264dec: do not return a value from init_dimensions()
There are no failure cases left in this function.
2020-03-16 09:27:48 +01:00
Andreas Rheinhardt
cc2a9509ce libavcodec, libpostproc: Remove outcommented START/STOP_TIMER
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>
2020-03-14 18:24:04 +01:00
Michael Niedermayer
1e984a6915 avcodec/h264_slice: clear frame only on gaps when it is not otherwise 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>
2019-09-24 17:53:39 +02:00
Steve Lhomme
8788dd67b8 avcodec/h264_slice: set the SEI parameters early on the AVCodecContext
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>
2019-07-14 13:04:46 -03:00
Michael Niedermayer
77e56d74f9 avcodec/h264_slice: Fix integer overflow in implicit_weight_table()
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>
2019-01-12 16:46:41 +01:00
Josh de Kock
76a8c3b522 h264/pic_timing: support multiple timecodes 2018-10-23 15:46:30 +01:00
Devin Heitmueller
4241e44a3c lavc/h264: create AVFrame side data from H.264 timecodes
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.
2018-10-23 15:46:30 +01:00
Derek Buitenhuis
b1504e7796 h264_slice: Copy the value of x264_build before calling 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>
2018-10-09 15:05:44 +01:00
Kieran Kunhya
c85852d3de h264: Support multi-field closed captions by using AVBufferRef and not resetting per field
Signed-off-by: Josh de Kock <joshdk@obe.tv>
2018-08-17 16:24:19 +01:00
John Stebbins
08b1d1d812 h264_slice: Fix return of incomplete frames from decoder
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>
2018-06-28 21:35:01 +02:00
Michael Niedermayer
8c02cd8ca0 avcodec/h264_slice: Fix integer overflow with last_poc
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>
2018-04-12 23:52:59 +02:00
Michael Niedermayer
1be49cee34 avcodec/h264: Increase field_poc to 64bit in ff_h264_init_poc() to detect 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>
2018-02-17 20:31:39 +01:00
Michael Niedermayer
476665d4de avcodec/h264_slice: Do not attempt to render into frames already output
Fixes: null pointer dereference
Fixes: 4698/clusterfuzz-testcase-minimized-5096956322906112

This testcase does not reproduce the issue before 03b82b3ab9

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2018-01-07 04:47:32 +01:00
James Almer
e01d2c00ae avcodec/h264_slice: use H264_SEI_FpaType enum constants
Cosmetic change.

Signed-off-by: James Almer <jamrial@gmail.com>
2017-12-01 01:18:47 -03:00
James Almer
5e9b39b373 avcodec/h264_sei: remove redundant prefix to H264SEIFramePacking fields
Cosmetic change.

Signed-off-by: James Almer <jamrial@gmail.com>
2017-12-01 01:10:11 -03:00