1
0
Fork 0
Commit Graph

206 Commits

Author SHA1 Message Date
Andreas Rheinhardt 348461e550 avcodec/h264_refs: Use smaller scope, don't use av_uninit
In particular, declare iterators with loop scope.
Also remove av_uninit while at it, because they
are now unnecessary due to the changes of the preceding
commit.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-03-30 05:06:28 +01:00
Andreas Rheinhardt ac14d68277 avcodec/h264_refs: Rewrite code to make control flow clearer
While this change IMO makes the control flow clearer
for the human reader, it is especially important for
GCC: It erroneously believes that it is possible to
enter the SHORT2(UNUSED|LONG) cases without having
entered the preceding block that initializes pic,
frame_num, structure and j; it would emit -Wmaybe-uninitialized
warnings for these variables if they were not pseudo-
initialized with av_uninit(). This patch allows to remove
the latter.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-03-30 05:06:28 +01:00
Michael Niedermayer 6364fa9e9a
avcodec/h264: Avoid using gray gap frames as references
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2023-11-20 00:19:25 +01:00
Michael Niedermayer 68e1cf204a
avcodec/h264: Use FRAME_RECOVERED_HEURISTIC instead of IDR/SEI
This keeps IDR/SEI and heuristically detected recovery points cleaner seperated

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2023-11-20 00:12:30 +01:00
Michael Niedermayer 3f4a1a24a5
avcodec/h264: Seperate SEI and IDR recovery handling
This avoids SEI and IDR recovery flags affecting each other

Also eliminate litteral numbers from recovery handling
This should make the code clearer

Improves: tickets/4738/tickets_cut.ts

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2023-11-20 00:12:29 +01:00
Andreas Rheinhardt 315c956cbd avcodec/pthread_frame: Remove ff_thread_release_buffer()
It is unnecessary since the removal of non-thread-safe callbacks
in e0786a8eeb. Since then, the
AVCodecContext has only been used as logcontext.

Removing ff_thread_release_buffer() allowed to remove AVCodecContext*
parameters from several other functions (not only unref functions,
but also e.g. ff_h264_ref_picture() which calls ff_h264_unref_picture()
on error).

Reviewed-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2023-10-22 22:09:59 +02:00
Andreas Rheinhardt 4e6cf5e52b avcodec/h264dec: Constify H.264 decoder
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2023-10-13 14:35:07 +02:00
Andreas Rheinhardt 787351a68e avcodec/h264_ps: Use RefStruct API for SPS/PPS
Avoids allocations and error checks for these allocations;
e.g. syncing buffers across threads can't fail any more
and needn't be checked. It also avoids having to keep
H264ParamSets.pps and H264ParamSets.pps_ref and PPS.sps
and PPS.sps_ref in sync and gets rid of casts and indirections.

(The removal of these checks and the syncing code even more
than offset the additional code for RefStruct.)

Reviewed-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2023-10-07 22:34:20 +02:00
Andreas Rheinhardt 27f22f3383 all: Remove unnecessary libavcodec/internal.h inclusions
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-02-08 06:16:26 +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
Anton Khirnov b05cebe602 lavc/h264: replace MAX_MMCO_COUNT with H264_MAX_MMCO_COUNT
They apparently serve the same purpose; the latter is one larger and has
a comment explaining how the value is derived, so seems more
trustworthy.
2022-01-26 15:23:08 +01:00
Paul B Mahol ef73ccc2c4 avcodec/h264_refs: do not use invalid mmco values in case of error
Change one relevant assert to av_assert0 while here.
2019-08-28 16:31:00 +02:00
Michael Niedermayer 7d3581e6bb avcodec/h264_refs: Also check reference in ff_h264_build_ref_list()
Fixes: out of array read
Fixes: 15409/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_H264_fuzzer-5758846959616000

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2019-07-19 21:42:38 +02:00
Michael Niedermayer 697984b9db avcodec/h264_refs: Document last if() in ff_h264_execute_ref_pic_marking()
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2018-09-03 00:01:32 +02:00
Michael Niedermayer b544850a52 avcodec/h264_refs: Detect more random access points which are not marked
Fixes: nature_360-7501616eb5eafca5-1111.mp4

Reported-by: Thierry Foucu <tfoucu@google.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2018-09-03 00:01:32 +02:00
James Almer 0e5a47693c Merge commit 'cb167f2947f1a2c446bd8db196d0e64ef4a6d06b'
* commit 'cb167f2947f1a2c446bd8db196d0e64ef4a6d06b':
  h264_refs: validate the SPS pointer in ff_h264_execute_ref_pic_marking()

Merged-by: James Almer <jamrial@gmail.com>
2017-10-30 20:40:28 -03:00
Sean McGovern cb167f2947 h264_refs: validate the SPS pointer in ff_h264_execute_ref_pic_marking()
Bug-Id: 1036
CC: libav-stable@libav.org
2017-05-09 17:28:36 -04:00
Clément Bœsch b6e88bf323 Merge commit 'b96f0ab3d29cdd9ea9ddabfb2052f72bf8615661'
* commit 'b96f0ab3d29cdd9ea9ddabfb2052f72bf8615661':
  h264: Kill broken disabled cruft

Merged-by: Clément Bœsch <u@pkh.me>
2017-03-19 15:56:19 +01:00
Aman Gupta b6eaa3928e avcodec/h264, videotoolbox: fix crash after VT decoder fails
The way videotoolbox hooks in as a hwaccel is pretty hacky. The VT decode
API is not invoked until end_frame(), so alloc_frame() returns a dummy
frame with a 1-byte buffer. When end_frame() is eventually called, the
dummy buffer is replaced with the actual decoded data from
VTDecompressionSessionDecodeFrame().

When the VT decoder fails, the frame returned to the h264 decoder from
alloc_frame() remains invalid and should not be used. Before
9747219958, it was accidentally being
returned all the way up to the API user. After that commit, the dummy
frame was unref'd so the user received an error.

However, since that commit, VT hwaccel failures started causing random
segfaults in the h264 decoder. This happened more often on iOS where the
VT implementation is more likely to throw errors on bitstream anomolies.
A recent report of this issue can be see in
http://ffmpeg.org/pipermail/libav-user/2016-November/009831.html

The issue here is that the dummy frame is still referenced internally by the
h264 decoder, as part of the reflist and cur_pic_ptr. Deallocating the
frame causes assertions like this one to trip later on during decoding:

  Assertion h->cur_pic_ptr->f->buf[0] failed at src/libavcodec/h264_slice.c:1340

With this commit, we leave the dummy 1-byte frame intact, but avoid returning it
to the user.

This reverts commit 9747219958.

Signed-off-by: wm4 <nfxjfg@googlemail.com>
2017-03-07 11:58:38 +01:00
Diego Biurrun d4c2103bd3 golomb: Convert to the new bitstream reader 2017-01-31 17:46:19 +01:00
Michael Niedermayer 5bbffe3412 avcodec/h264_refs: Change default case to av_assert0() to suppress warning
Should fix "libavcodec/h264_refs.c:372:13: warning: variable 'i' is used uninitialized whenever switch default is taken"

Found-by: durandal_17
Suggested-by: jkqxz
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2016-09-12 12:33:44 +02:00
Diego Biurrun b96f0ab3d2 h264: Kill broken disabled cruft 2016-08-17 12:16:42 +02:00
Timothy Gu bca30ed2b6 Merge commit 'b13fc1e344011949929975a3451f78f226aa1de3'
* commit 'b13fc1e344011949929975a3451f78f226aa1de3':
  h264: do not pass H264Context to h264_slice_header_parse()

Conflicts:
	libavcodec/h264dec.h

Did not merge the h264_slice_header_parse() part. We use a few other
members of H264Context for error checking in that function.

Merged-by: Timothy Gu <timothygu99@gmail.com>
2016-08-03 15:41:59 -07:00
James Almer f41048f6ec Merge commit '5c2fb561d94fc51d76ab21d6f7cc5b6cc3aa599c'
* commit '5c2fb561d94fc51d76ab21d6f7cc5b6cc3aa599c':
  h264: add H264_ prefix to the NAL unit types

Conflicts:
libavcodec/h264_parse.c
libavcodec/h264_parser.c
libavcodec/h264_slice.c
libavcodec/h264dec.c

Merged-by: James Almer <jamrial@gmail.com>
2016-08-01 15:11:05 -03:00
Clément Bœsch ecf65c30cf Merge commit '251cbb44003caf179fb17afbb8a6c56643c2a646'
* commit '251cbb44003caf179fb17afbb8a6c56643c2a646':
  h264: create a new header for common h264 definitions

Merged-by: Clément Bœsch <u@pkh.me>
2016-07-29 11:13:44 +02:00
Clément Bœsch 15b26e88cb Merge commit '9df889a5f116c1ee78c2f239e0ba599c492431aa'
* commit '9df889a5f116c1ee78c2f239e0ba599c492431aa':
  h264: rename h264.[ch] to h264dec.[ch]

Merged-by: Clément Bœsch <u@pkh.me>
2016-07-29 11:01:36 +02:00
Clément Bœsch 6c41eda18e Merge commit 'debca90863e4ee53447efd02483c500f89766384'
* commit 'debca90863e4ee53447efd02483c500f89766384':
  h264: store {curr,max}_pic_num in the per-slice context

Merged-by: Clément Bœsch <u@pkh.me>
2016-07-27 18:07:30 +02:00
Michael Niedermayer fd1588919d avcodec/h264: remove list_count and ref_count clearing
The code conflicts with moving the h264_init_ps() call point

Without this, ff_h264_parse_ref_count() fills ref and list count and
h264_init_ps() subsequently wipes them out on a "success" path.
Subsequently things crash as the wiped fields are used.

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2016-07-20 00:02:12 +02:00
Michael Niedermayer 58dc8bbca4 avcodec/h264_refs: Assert that op is 0-2
Coverity fails to realize this

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2016-07-10 21:23:11 +02:00
Clément Bœsch a7ce5b25c0 Merge commit '84b2d3fb68caf71cff4b80b44ff865d7ae2531ce'
* commit '84b2d3fb68caf71cff4b80b44ff865d7ae2531ce':
  h264: Drop unused function check_opcodes()

Merged-by: Clément Bœsch <u@pkh.me>
2016-07-09 14:45:12 +02:00
Clément Bœsch f48aea66dd Merge commit 'bec993381cfec72051b0d9f12ac9d9bb9c750983'
* commit 'bec993381cfec72051b0d9f12ac9d9bb9c750983':
  h264: postpone generating the implicit MMCOs

Merged-by: Clément Bœsch <clement@stupeflix.com>
2016-06-30 10:24:03 +02:00
Clément Bœsch d407e76c42 Merge commit '2d410ebbaa1e760d6837cb434a6d1d4c3c6f0d85'
* commit '2d410ebbaa1e760d6837cb434a6d1d4c3c6f0d85':
  h264: decode the MMCOs into per-slice contexts

Merged-by: Clément Bœsch <clement@stupeflix.com>
2016-06-30 10:15:51 +02:00
Clément Bœsch 57d30fde9e Merge commit '39ab2ea53121b9976a619cd545fbd3464b908696'
* commit '39ab2ea53121b9976a619cd545fbd3464b908696':
  h264: rename mmco_index to nb_mmco

Merged-by: Clément Bœsch <u@pkh.me>
2016-06-29 20:07:52 +02:00
Clément Bœsch 2aff557c6a Merge commit 'ed9a20ebe4a89de119ea97bdccf688ece8c6648c' into merge-libav-new
* commit 'ed9a20ebe4a89de119ea97bdccf688ece8c6648c':
  h264: split reading the ref list modifications and actually building the ref list

ref_modifications.val are read as u32 instead of u8 in FFmpeg.

Merged-by: Clément Bœsch <clement@stupeflix.com>
2016-06-29 17:32:05 +02:00
Clément Bœsch 527a579327 Merge commit '7b50d60442af8d9527e9da46818011fe15a5265a'
* commit '7b50d60442af8d9527e9da46818011fe15a5265a':
  h264: call ff_h264_fill_mbaff_ref_list() when constructing the normal ref list

Merged-by: Clément Bœsch <clement@stupeflix.com>
2016-06-29 15:17:16 +02:00
Clément Bœsch d7a2451688 Merge commit 'b16e9b9ac9db449cae2242767dd3c3fc309357c4'
* commit 'b16e9b9ac9db449cae2242767dd3c3fc309357c4':
  h264: move initialising the explicit pred weight table for MBAFF

Merged-by: Clément Bœsch <clement@stupeflix.com>
2016-06-29 15:03:12 +02:00
Clément Bœsch 8ef57a0d61 Merge commit '41ed7ab45fc693f7d7fc35664c0233f4c32d69bb'
* commit '41ed7ab45fc693f7d7fc35664c0233f4c32d69bb':
  cosmetics: Fix spelling mistakes

Merged-by: Clément Bœsch <u@pkh.me>
2016-06-21 21:55:34 +02:00
Anton Khirnov b13fc1e344 h264: do not pass H264Context to h264_slice_header_parse()
This should make it more clear that this function does not need any
decoder-global state other than the parameter sets.
2016-06-21 11:18:44 +02:00
Anton Khirnov 5c2fb561d9 h264: add H264_ prefix to the NAL unit types
This will prevent conflicts e.g. in code that deals with both h264 and
hevc.
2016-06-21 11:17:28 +02:00
Anton Khirnov 251cbb4400 h264: create a new header for common h264 definitions
Move the NAL unit types into it. This will allow to stop including the
whole decoder-specific h264dec.h in some code that is unrelated to the
decoder and only needs some enum values.
2016-06-21 11:12:41 +02:00
Anton Khirnov 9df889a5f1 h264: rename h264.[ch] to h264dec.[ch]
This is more consistent with the naming of other decoders.
2016-06-21 11:11:26 +02:00
Anton Khirnov debca90863 h264: store {curr,max}_pic_num in the per-slice context
While the value of those variables will be constant for the whole frame,
they are only used in two functions called from slice header decoding.
Moving them to the per-slice context allows us to make the H264Context
passed to slice_header_parse() constant.
2016-06-21 11:09:21 +02:00
Clément Bœsch d5cfe23324 Merge commit '89ae244e78a8d636fbb8427a2da052b04cf710bd'
* commit '89ae244e78a8d636fbb8427a2da052b04cf710bd':
  h264_refs: remove an unused parameter from ff_h264_fill_mbaff_ref_list()

Merged-by: Clément Bœsch <u@pkh.me>
2016-06-19 13:45:59 +02:00
Clément Bœsch 222e7d23d0 Merge commit '755f79f84cbeb5d749fb120e55e0098a2d7663a0'
* commit '755f79f84cbeb5d749fb120e55e0098a2d7663a0':
  h264_refs: make the H264Context const where possible

ff_h264_decode_ref_pic_list_reordering() and h264_initialise_ref_list()
do not have a const H264Context * as they modify the default_ref inside
that context.

Merged-by: Clément Bœsch <u@pkh.me>
2016-06-19 13:36:33 +02:00
Clément Bœsch 902862bb4b Merge commit 'a2fd547839d3ef8f342b6f2c096d0887675d3b1a'
* commit 'a2fd547839d3ef8f342b6f2c096d0887675d3b1a':
  h264_refs: reorder functions to avoid forward declarations

Merged-by: Clément Bœsch <u@pkh.me>
2016-06-19 13:04:17 +02:00
Diego Biurrun 84b2d3fb68 h264: Drop unused function check_opcodes() 2016-06-14 11:14:06 +02:00
Anton Khirnov bec993381c h264: postpone generating the implicit MMCOs
Do it right before the MMCOs are applied to the DPB. This will allow
moving the frame_start() call out of the slice header parsing, since
generating the implicit MMCOs needs to be done after frame_start().
2016-06-12 20:27:53 +02:00
Anton Khirnov 2d410ebbaa h264: decode the MMCOs into per-slice contexts
They are stored in the slice header, so technically they are per-slice
(though they must be the same in every slice). This will simplify the
following commits.
2016-06-12 20:27:53 +02:00
Anton Khirnov 39ab2ea531 h264: rename mmco_index to nb_mmco
The variable stores the number of mmco entries, so the current name is
misleading.
2016-06-12 20:27:53 +02:00
Anton Khirnov ed9a20ebe4 h264: split reading the ref list modifications and actually building the ref list
This will allow postponing the reference list construction (and by
consequence some other functions, like frame_start) until the whole
slice header has been parsed.
2016-06-12 20:27:52 +02:00