Commit Graph

195 Commits

Author SHA1 Message Date
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
Anton Khirnov
7b50d60442 h264: call ff_h264_fill_mbaff_ref_list() when constructing the normal ref list
There is no real reason to call it separately.
2016-06-12 20:27:52 +02:00
Anton Khirnov
b16e9b9ac9 h264: move initialising the explicit pred weight table for MBAFF
Currently it's done in the code that initialises the ref list for
MBAFF, which is not a logical place for it. Move it to the function that
parses the pred table from the bitstream, which is analogous to what is
done for the implicit weight table as well.
2016-06-12 20:27:52 +02:00
Anton Khirnov
b93c0aed79 h264: drop an outdated comment 2016-06-12 20:27:52 +02:00
Clément Bœsch
bd3fd467fe Merge commit 'c8dcff0cdb17d0aa03ac729eba12d1a20f1f59c8'
* commit 'c8dcff0cdb17d0aa03ac729eba12d1a20f1f59c8':
  h264: factor out calculating the POC count into a separate file

Merged-by: Clément Bœsch <u@pkh.me>
2016-06-12 19:01:43 +02:00
Clément Bœsch
1534ef87c7 Merge commit '3176217c60ca7828712985092d9102d331ea4f3d'
* commit '3176217c60ca7828712985092d9102d331ea4f3d':
  h264: decouple h264_ps from the h264 decoder

Main changes:

- a local GetBitContext is created for the various
  ff_h264_decode_seq_parameter_set() attempts

- just like the old code, remove_sps() is adjusted so it doesn't remove
  the pps.

  Fixes decode with Ticket #631
  http://ffmpeg.org/pipermail/ffmpeg-user/attachments/20111108/dae58f17/attachment.mp4
  but see next point as well.

- ff_h264_update_thread_context() is updated to work even when SPS
  isn't set as it breaks current skip_frame code. This makes sure we
  can still decode the sample from ticket #631 without the need for
  -flags2 +chunks. (Thanks to Michael)

- keep {sps,pps}_ref pointers that stay alive even when the active
  pps/sps get removed from the available lists (patch by michaelni with
  additionnal frees in ff_h264_free_context() from mateo)

- added a check on sps in avpriv_h264_has_num_reorder_frames() to fix
  crashes with mpegts_with_dvbsubs.ts from Ticket #4074
  http://samples.ffmpeg.org/ffmpeg-bugs/trac/ticket4074/mpegts_with_dvbsubs.ts

- in h264_parser.c:h264_parse(), after the ff_h264_decode_extradata() is
  called, the pps and sps from the local parser context are updated with
  the pps and sps from the used h264context. This fixes fate-flv-demux.

- in h264_slice.c, "PPS changed between slices" error is not triggered
  anymore in one condition as it makes fate-h264-xavc-4389 fails with
  THREADS=N (Thanks to Michael)

Merged-by: Clément Bœsch <clement@stupeflix.com>
Merged-by: Michael Niedermayer <michael@niedermayer.cc>
Merged-by: Matthieu Bouron <matthieu.bouron@stupeflix.com>
2016-06-12 13:26:52 +02:00
Michael Niedermayer
3402871f36 avcodec/h264_refs: Fix pps_ref_count with multiple PPS
Found-by: ubitux
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2016-06-02 14:51:49 +02:00
Michael Niedermayer
a8289d2407 avcodec/h264_refs: Remove unused pps_count
Found-by: ubitux
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2016-06-02 14:48:12 +02:00
Vittorio Giovara
41ed7ab45f cosmetics: Fix spelling mistakes
Signed-off-by: Diego Biurrun <diego@biurrun.de>
2016-05-04 18:16:21 +02:00
Derek Buitenhuis
ee38234c43 Merge commit 'e481458bc308ee838deaeacac51929514762e7a7'
* commit 'e481458bc308ee838deaeacac51929514762e7a7':
  h264: factor out pred weight table parsing into a separate file

Merged-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
2016-04-26 15:04:29 +01:00
Anton Khirnov
89ae244e78 h264_refs: remove an unused parameter from ff_h264_fill_mbaff_ref_list() 2016-04-24 10:06:24 +02:00
Anton Khirnov
755f79f84c h264_refs: make the H264Context const where possible 2016-04-24 10:06:24 +02:00