Commit Graph

68 Commits

Author SHA1 Message Date
Rodger Combs 63d875772d lavc/videotoolbox: fix threaded decoding
AVHWAccel.end_frame can run on a worker thread. The assumption of the
frame threading code is that the worker thread will change the AVFrame
image data, not the AVFrame fields. So the AVFrame fields are not synced
back to the main thread. But this breaks videotoolbox due to its special
requirements (everything else is fine). It actually wants to update
AVFrame fields.

The actual videotoolbox frame is now stored in the dummy AVBufferRef, so
it mimics what happens in non-videotoolbox cases. (Changing the
AVBufferRef contents is a bit like changing the image data.) The
post_process callback copies that reference to the proper AVFrame field.

Based on a patch by wm4.

Signed-off-by: Aman Gupta <aman@tmm1.net>
2018-03-08 14:04:25 -08:00
wm4 cf57cb3ae4 h264: add AVOption to set x264_build default
This provides a generic way to the API user to deal with files that
either lack this SEI, or which have the SEI only in packets not passed
to the decoder (such as the common case of the SEI being in the very
firsat video packet, but decoding is started somewhere in the middle of
the file). Bugs like 840b41b2a6 make this
somewhat of a necessity.

This intentionally uses the version in the SEI instead, if any is found.
2017-12-26 02:56:09 +01:00
Kieran Kunhya 918de766f5 h264dec: Remove mpeg4video.h header dependency 2017-12-11 00:09:25 +00: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
Mark Thompson 758fbc54fe lavc: Add hardware config metadata for decoders supporting hardware output
This includes a pointer to the associated hwaccel for decoders using
hwaccels - these will be used later to implement the hwaccel setup
without needing a global list.

Also added is a new file listing all hwaccels as external declarations -
this will be used later to generate the hwaccel list at configure time.
2017-11-26 21:35:53 +00:00
Aman Gupta 872add0854 avcodec/h264: implement new decode_params callback for PPS/SPS
This callback will be used by the VideoToolbox H264 hwaccel so that it
can receive SPS and PPS NALUs. VideoToolbox requires PPS changes to be
fed into the decoder session, and for the session to be recreated when
the SPS changes.

Signed-off-by: Aman Gupta <aman@tmm1.net>
2017-11-13 14:32:48 -08:00
Aman Gupta dad42bc5a1 avcodec/h264, videotoolbox: return AVERROR_INVALIDDATA when no frames are produced
The only reason videotoolbox wouldn't produce frames is if the data fed
to it was invalid, so returning AVERROR_INVALIDDATA makes sense here.

Further, it means AVERROR_EXTERNAL can be used in further commits to signal
fatal VideoToolbox errors, letting the user know that they need to fallback to
another decoder.

Signed-off-by: Aman Gupta <aman@tmm1.net>
Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
2017-11-13 14:32:27 -08:00
James Almer bc987cf91d Merge commit '45c4bf3df03ef53ae61fa1473424d4ae024f22e4'
* commit '45c4bf3df03ef53ae61fa1473424d4ae024f22e4':
  h264dec: track the last seen value of x264_build

Merged-by: James Almer <jamrial@gmail.com>
2017-11-08 14:23:48 -03:00
James Almer b773a8d8c1 Merge commit 'dd343fd986459f467a2d1d70c26101dff1d47d68'
* commit 'dd343fd986459f467a2d1d70c26101dff1d47d68':
  lavu: Drop deprecated VDPAU pixel formats

Merged-by: James Almer <jamrial@gmail.com>
2017-10-23 18:15:49 -03:00
James Almer 2ccd00dabd Merge commit '5182a28b5de060c51c21b36053ab205bfbbbbe31'
* commit '5182a28b5de060c51c21b36053ab205bfbbbbe31':
  lavc: Drop deprecated global afd field

Merged-by: James Almer <jamrial@gmail.com>
2017-10-23 16:31:50 -03:00
James Almer c68a3ab96e Merge commit '7b917041184874e7d7cba4450813de7e0bb28a33'
* commit '7b917041184874e7d7cba4450813de7e0bb28a33':
  lavc: Drop deprecated VDPAU codec capability

Merged-by: James Almer <jamrial@gmail.com>
2017-10-21 23:40:03 -03:00
James Almer 73c85d3af2 Merge commit '248dc5c1646dcdd96fe79761105c4ae889e711fd'
* commit '248dc5c1646dcdd96fe79761105c4ae889e711fd':
  h264dec: fix dropped initial SEI recovery point

Merged-by: James Almer <jamrial@gmail.com>
2017-10-03 20:09:46 -03:00
Anton Khirnov 45c4bf3df0 h264dec: track the last seen value of x264_build
Do not use the one in the SEI directly as that is reset at certain
points.

Inspired by patches from Michael Niedermayer <michaelni@gmx.at> and
Anton Mitrofanov <BugMaster@narod.ru>.

CC: libav-stable@libav.org
2017-07-26 23:23:13 +02:00
Rafaël Carré 3b9cf943c9 h264dec: remove unneeded prototype
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2017-07-07 03:48:56 +02:00
James Almer 07596e45c5 avcodec/h264dec: export cropping information instead of handling it internally
This merges commit c3e84820d6 from libav,
originally written by Anton Khirnov and skipped in
fc63d5ceb3.

 libavcodec/h264_picture.c |  3 ---
 libavcodec/h264_ps.c      |  9 ---------
 libavcodec/h264_slice.c   | 25 +++++++++++++++++++------
 libavcodec/h264dec.c      | 13 +------------
 libavcodec/h264dec.h      |  9 +++++----
 5 files changed, 25 insertions(+), 34 deletions(-)
2017-05-26 11:15:45 -03:00
James Almer 6505e8cfd0 avcodec/h264dec: be more explicit in handling container cropping
This merges commit 4fded0480f from libav,
originally written by Anton Khirnov and skipped in
fc63d5ceb3.

 libavcodec/h264_slice.c | 20 +++++++++++++-------
 libavcodec/h264dec.c    |  3 +++
 libavcodec/h264dec.h    |  5 +++++
 3 files changed, 21 insertions(+), 7 deletions(-)
2017-05-26 11:15:45 -03:00
Clément Bœsch 20e72faef6 Merge commit 'f1af37b51033ad90e56a8d7dfcc366f2bd9d2fed'
* commit 'f1af37b51033ad90e56a8d7dfcc366f2bd9d2fed':
  h264dec: make ff_h264_decode_init() static

Merged-by: Clément Bœsch <cboesch@gopro.com>
2017-05-05 11:33:39 +02:00
Ronald S. Bultje 8c2aa45d4a h264: revert 1189af4292.
The patch introduces race conditions.
2017-03-28 18:04:27 -04:00
Anton Khirnov 14bb15bfd5 pthread_frame: ensure the threads don't run simultaneously with hwaccel
Merges Libav commit 8dfba25c.

Signed-off-by: wm4 <nfxjfg@googlemail.com>
2017-03-21 06:16:49 +01:00
Matthieu Bouron 1ade4d87ba lavc/h264dec: use OFFSET macro 2017-03-15 11:46:15 +01:00
Anton Khirnov b76f6a76c6 h264dec: initialize field_started to 0 on each decode call
It might be incorrectly set to 1 if the previous call exited with an
error.

Bug-Id: 1019
CC: libav-stable@libav.org
2017-03-12 20:42:12 +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
John Stebbins 248dc5c164 h264dec: fix dropped initial SEI recovery point 2017-02-24 08:24:13 -07:00
Diego Biurrun d4c2103bd3 golomb: Convert to the new bitstream reader 2017-01-31 17:46:19 +01:00
Clément Bœsch 4039076dc3 Merge commit '76f7e70aa04fc5dbef5242b11cbf8fe4499f61d4'
* commit '76f7e70aa04fc5dbef5242b11cbf8fe4499f61d4':
  h264dec: handle zero-sized NAL units in get_last_needed_nal()

See 641dccc2aa

Merged-by: Clément Bœsch <cboesch@gopro.com>
2017-01-31 17:23:14 +01:00
Michael Niedermayer f28299da8d avcodec/h264dec: Clear ref_count on slice header processing failure
Fixes using freed memory
Introduced in 7448019890
Fixes: 471/fuzz-1-ffmpeg_VIDEO_AV_CODEC_ID_H264_fuzzer

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/targets/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2017-01-27 00:52:49 +01:00
Clément Bœsch 7448019890 Merge commit '38efff92f1ef81f3de20ff0460ec7b70c253d714'
* commit '38efff92f1ef81f3de20ff0460ec7b70c253d714':
  FATE: add a test for H.264 with two fields per packet
  h264: fix decoding multiple fields per packet with slice threads

This merge includes two commits because the FATE test was useful in
order to make proper testing.

The merge gets rid of the now unused:
- SLICE_SINGLETHREAD and SLICE_SKIPED macros
- max_contexts
- "again" label in decode_nal_units()

This commit also includes the fix from d3e4d406b.

Thanks to wm4 and Michael Niedermayer for their testing.

Merged-by: Clément Bœsch <u@pkh.me>
Merged-by: Matthieu Bouron <matthieu.bouron@gmail.com>
2017-01-24 16:13:03 +01:00
Michael Niedermayer 25f4f08ba5 avcodec/h264dec: Fix regression with "make fate-h264-attachment-631 THREADS=8"
This treats the case of no slices like no frames which it basically is.

The field is added to the context as other nal related fields are also there
and passing the has_slices field per *arguments is ugly and not consistent

Found-by: ubitux
Approved-by: ubitux

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2017-01-24 12:13:59 +01:00
Michael Niedermayer d9d9fd9446 avcodec/error_resilience: Optimize motion recovery code by using blcok lists
This makes the code 7 times faster with the testcase from libfuzzer
and should reduce the amount of timeouts we hit in automated fuzzing.
(for example 438/fuzz-2-ffmpeg_VIDEO_AV_CODEC_ID_RV40_fuzzer)

The code is also faster with more realistic input though the difference
is small here as that is far from the worst cases the fuzzers pick out

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/targets/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2017-01-22 21:39:43 +01:00
Matthieu Bouron cf3affabb4 lavc/h264dec: re-indent after previous commit 2017-01-20 17:29:09 +01:00
Matthieu Bouron 639e262971 lavc/h264dec: make sure a slice is decoded before finishing setup
Fixes regression in fate-h264-attachment-631 with THREADS=8 introduced
by bdbbb8f11e.
2017-01-20 17:28:40 +01:00
Clément Bœsch c3050fcbdc lavc/h264dec: remove flush goto in decode callback 2017-01-18 18:06:21 +01:00
Matthieu Bouron bdbbb8f11e Merge commit 'f450cc7bc595155bacdb9f5d2414a076ccf81b4a'
* commit 'f450cc7bc595155bacdb9f5d2414a076ccf81b4a':
  h264: eliminate decode_postinit()

Also includes fixes from 1f7b4f9abc and e344e65109.

Original patch replace H264Context.next_output_pic (H264Picture *) by
H264Context.output_frame (AVFrame *). This change is discarded as it
is incompatible with the frame reconstruction and motion vectors
display code which needs the extra information from the H264Picture.

Merged-by: Clément Bœsch <u@pkh.me>
Merged-by: Matthieu Bouron <matthieu.bouron@gmail.com>
2017-01-17 14:38:48 +01:00
Clément Bœsch 9561de4183 lavc/h264dec: reconstruct and debug flush frames as well 2017-01-16 10:43:41 +01:00
Anton Khirnov c3e84820d6 h264dec: export cropping information instead of handling it internally 2017-01-12 16:29:12 +01:00
Anton Khirnov 4fded0480f h264dec: be more explicit in handling container cropping
The current condition can trigger in cases where it shouldn't, with
unexpected results.
Make sure that:
- container cropping is really based on the original dimensions from the
  caller
- those dimenions are discarded on size change

The code is still quite hacky and eventually should be deprecated and
removed, with the decision about which cropping is used delegated to the
caller.
2017-01-12 16:28:05 +01:00
Anton Khirnov f1af37b510 h264dec: make ff_h264_decode_init() static
It is not called from outside h264dec.c anymore.
2017-01-09 13:21:13 +01:00
Anton Khirnov 45286a625c h264dec: make sure to only end a field if it has been started
Calling ff_h264_field_end() when the per-field state is not properly
initialized leads to all kinds of undefined behaviour.

CC: libav-stable@libav.org
Bug-Id: 977 978 992
2016-12-19 08:15:58 +01:00
Anton Khirnov 8dfba25ce8 pthread_frame: ensure the threads don't run simultaneously with hwaccel 2016-12-19 08:09:19 +01:00
Anton Khirnov 5bf2454e7c h264dec: support broken files with mp4 extradata/annex b data
Bug-Id: 966
2016-10-02 11:41:45 +02:00
Carl Eugen Hoyos 3c36d960f4 lavc/h264dec: Improve "Increasing reorder buffer" message loglevel.
Do not show the message for the first frame by default, show a
warning if increasing is necessary in the middle of the stream.
2016-08-23 15:05:06 +02:00
Michael Niedermayer cc13bc8c4f avcodec/h2645: Fix NAL unit padding
The parser changes have lost the support for the needed padding, this adds it back
Fixes out of array reads
Fixes: 03ea21d271abc8acf428d42ace51d8b4/asan_heap-oob_3358eef_5692_16f0cc01ab5225e9ce591659e5c20e35.mkv

Found-by: Mateusz "j00ru" Jurczyk and Gynvael Coldwind
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2016-08-18 23:36:18 +02:00
Timothy Gu f297d1e9e5 h264dec: Fix indentation 2016-08-04 11:16:44 -07:00
Timothy Gu 7f7cedd713 Merge commit '58640fe89ec4f2a3d67c0a2585fca8de34440857'
* commit '58640fe89ec4f2a3d67c0a2585fca8de34440857':
  h264: handle frame recovery in h264_field_start()

Conflicts:
	libavcodec/h264dec.c

Merged-by: Timothy Gu <timothygu99@gmail.com>
2016-08-03 20:07:21 -07:00
Timothy Gu de62531286 Merge commit 'e26c64148be8a20ace7512d96503172fb5e9753b'
* commit 'e26c64148be8a20ace7512d96503172fb5e9753b':
  h264: discard slices of redundant pictures right after parsing the slice header

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

TODO: fix indentation

Merged-by: Timothy Gu <timothygu99@gmail.com>
2016-08-03 19:50:06 -07:00
Timothy Gu 826c780c12 Revert "Revert "Merge commit 'd1d7678040cd60148f97b372cb4291bcc45b2e22'""
This reverts commit e4af9be0f4 and redoes
796027f221.

Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
2016-08-03 17:45:52 -07:00
Timothy Gu e4af9be0f4 Revert "Merge commit 'd1d7678040cd60148f97b372cb4291bcc45b2e22'"
This reverts commit 796027f221, reversing
changes made to bca30ed2b6.

Preemptive revert before further testing has been done.
2016-08-03 17:06:55 -07:00
Timothy Gu 796027f221 Merge commit 'd1d7678040cd60148f97b372cb4291bcc45b2e22'
* commit 'd1d7678040cd60148f97b372cb4291bcc45b2e22':
  h264: fix the check for mixed IDR/non-IDR slices

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

Merged-by: Timothy Gu <timothygu99@gmail.com>
2016-08-03 15:59:51 -07:00
Anton Khirnov d3e4d406b0 h264dec: reset nb_slice_ctx_queued for hwaccel decoding
Fixes hwaccel decoding of files with multiple slices.

Found-By: Mark Thompson <sw@jkqxz.net>
2016-08-03 10:56:52 +02:00
James Almer 517dd04f6d Merge commit 'bc7f4268514624e1286ea76d27a89a56b4ee18e1'
* commit 'bc7f4268514624e1286ea76d27a89a56b4ee18e1':
  h264: drop tests whether the codec id is AV_CODEC_ID_H264

Conflicts:
libavcodec/h264dec.c

Merged-by: James Almer <jamrial@gmail.com>
2016-08-01 18:15:07 -03:00