Commit Graph

1587 Commits

Author SHA1 Message Date
Anton Khirnov
9e30859cb6 lavc: shedule old encoding/decoding API for removal
It has been deprecated for 4 years and certain new codecs do not work
with it.

Also include AVCodecContext.refcounted_frames, as it has no effect with
the new API.
2021-01-26 17:05:58 +01:00
Michael Niedermayer
2488ba85a0 avcodec/utils: Check for integer overflow in get_audio_frame_duration() for ADPCM_DTK
Fixes: signed integer overflow: 131203586 * 28 cannot be represented in type 'int'
Fixes: 26817/clusterfuzz-testcase-minimized-ffmpeg_dem_MSF_fuzzer-6296902548848640

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2021-01-23 01:05:25 +01:00
Michael Niedermayer
8aadae670f avcodec/utils: Check bitrate for overflow in get_bit_rate()
Fixes: signed integer overflow: 617890810133996544 * 16 cannot be represented in type 'long'
Fixes: 26565/clusterfuzz-testcase-minimized-ffmpeg_dem_MV_fuzzer-5092054700654592

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2020-12-19 20:07:56 +01:00
Andreas Rheinhardt
5766c8e968 avcodec/utils: Remove ff_codec_open2_recursive()
This function existed to enable codecs with non-threadsafe init functions
to initialize other codecs despite the fact that normally no two codecs
with non-threadsafe init functions can be initialized at the same time
(there is a mutex guarding this). Yet there are no users of this
function any more as all users have been made thread-safe (switching
away from ff_codec_open2_recursive() was required for this as said
function requires the caller to hold the lock to the mutex guarding the
initializations and this is only true for codecs with the
FF_CODEC_CAP_INIT_THREADSAFE flag unset); so remove it.

Reviewed-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-12-04 15:46:46 +01:00
Michael Niedermayer
81503ac58a avcodec/utils: Require a non zero channels unless AV_CODEC_CAP_CHANNEL_CONF is set
This avoids per codec checks for channels not being 0

Fixes: division by 0
Fixes: 25419/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_FASTAUDIO_fuzzer-5632544761184256
Fixes: 25433/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_FASTAUDIO_fuzzer-6215671900536832

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Suggested-by: Paul B Mahol <onemda@gmail.com>
See: [FFmpeg-devel] [PATCH 1/3] avcodec/fastaudio: Check channel
Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2020-11-28 00:41:51 +01:00
Anton Khirnov
a83098ab03 avcodec: deprecate thread_safe_callbacks
They add considerable complexity to frame-threading implementation,
which includes an unavoidably leaking error path, while the advantages
of this option to the users are highly dubious.

It should be always possible and desirable for the callers to make their
get_buffer2() implementation thread-safe, so deprecate this option.
2020-11-27 15:46:50 +01:00
James Almer
d2dcb113f8 avcodec/utils: clear the packet props queue on flushing
This ensures no queued timestamps or side data are kept and used after
seeking, preventing potential desyncs.

Signed-off-by: James Almer <jamrial@gmail.com>
2020-11-09 15:57:56 -03:00
Zane van Iperen
555f5c1fc5
avcodec: add adpcm_ima_amv encoder
Fixes ticket #747.

Signed-off-by: Zane van Iperen <zane@zanevaniperen.com>
2020-11-09 14:58:38 +10:00
Zane van Iperen
d6912294d3
avcodec/adpcm_ima_amv: restrict to 1 channel
The format doesn't allow for anything else.

Signed-off-by: Zane van Iperen <zane@zanevaniperen.com>
2020-11-09 14:58:30 +10:00
Zane van Iperen
2433b62f79
avcodec/utils: add adpcm_ima_alp to av_get_exact_bits_per_sample()
Signed-off-by: Zane van Iperen <zane@zanevaniperen.com>
2020-11-03 12:25:01 +10:00
Michael Niedermayer
ec7e0d4288 avcodec/utils: Check sample rate before use for AV_CODEC_ID_BINKAUDIO_DCT in get_audio_frame_duration()
Fixes: shift exponent 95 is too large for 32-bit type 'int'
Fixes: 26590/clusterfuzz-testcase-minimized-ffmpeg_dem_SMACKER_fuzzer-5120609937522688

Reviewed-by: Peter Ross <pross@xvid.org>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2020-10-29 20:42:48 +01:00
Anton Khirnov
0438521888 lavc: un-avpriv avpriv_bprint_to_extradata()
It has not been used outside of lavc since 6f69f7a8bf.

Also, move it to the only place where it is used.
2020-10-28 13:53:23 +01:00
Michael Niedermayer
01bb12f883 avcodec/utils: Check for overflow with ATRAC* in get_audio_frame_duration()
Fixes: signed integer overflow: 1024 * 13129048 cannot be represented in type 'int'
Fixes: 26378/clusterfuzz-testcase-minimized-ffmpeg_dem_CODEC2RAW_fuzzer-5634018353348608

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-17 14:36:11 +02:00
James Almer
137a36bdfc avcodec/utils: add missing FF_API_TAG_STRING check
Signed-off-by: James Almer <jamrial@gmail.com>
2020-10-01 22:43:28 -03:00
Andreas Rheinhardt
66eadb3926 avcodec/utils: Reindentation
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-10-01 13:35:28 +02:00
Andreas Rheinhardt
b8e0ceda11 avcodec/utils: Also free encoder extradata on avcodec_open2() error
It is owned by libavcodec for encoders.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-10-01 13:34:57 +02:00
Andreas Rheinhardt
d1dcc20126 avcodec/utils: Don't forget cleaning up when allocating priv_data fails
Allocating an AVCodecContext's priv_data used to be the first object
allocated in avcodec_open2(), so it was unnecessary to goto free_and_end
(which does the cleanup) upon error here. But this is no longer so since
f3a29b750a.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-10-01 13:19:42 +02:00
Andreas Rheinhardt
c6e54d14c5 avcodec/utils: Improve check for freeing codec private options
Don't check for AVCodec.priv_data_size (which is always true if
AVCodec.priv_class is set). Instead check for AVCodecContext.priv_data
to actually exist.

(Note: av_opt_free(NULL) is a no-op.)

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-10-01 13:18:18 +02:00
Andreas Rheinhardt
502c5fe101 avcodec/utils: Remove always-true check
The first thing avcodec_open2() allocates is the AVCodecInternal. If
allocating it fails, a jump to end occurs; but if an error happens after
its allocation, a jump to free_and_end happens which frees all
allocations performed so far and then jumps to end. Yet free_and_end
contained a check for AVCodecInternal (after having already dereferenced
it to check whether ff_thread_free() needs to be called) which is of
course always true. So remove it.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-10-01 12:50:57 +02:00
Andreas Rheinhardt
5bc74d06da avcodec/utils: Only call codec->close if init has been called
avcodec_open2() also called the AVCodec's close function if an error
happened before init had ever been called if the AVCodec has the
FF_CODEC_CAP_INIT_CLEANUP flag set. This is against the documentation of
said flag: "The codec allows calling the close function for deallocation
even if the init function returned a failure."

E.g. the SVQ3 decoder is not ready to be closed if init has never been
called.

Fixes: NULL dereference
Fixes: 25762/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_SVQ3_fuzzer-5716279070294016

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg

Reviewed-by: Paul B Mahol <onemda@gmail.com>
Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-09-29 21:18:19 +02:00
James Almer
022a12b306 avcodec/decode: use a packet list to store packet properties
Keeping only the latest packet fed to the decoder works only for decoders that
return a frame immediately after every consumed packet. Decoders that consume
several packets before they return a frame will fill said frame with properties
taken from the last consumed packet instead of the earliest.

Signed-off-by: James Almer <jamrial@gmail.com>
2020-09-15 09:53:39 -03:00
James Almer
6a5b38ef44 avcodec/utils: make the src paramater for ff_thread_ref_frame const
Signed-off-by: James Almer <jamrial@gmail.com>
2020-09-11 10:36:57 -03:00
Andreas Rheinhardt
0086432fc7 fftools, libavcodec, libavfilter: Add const to some AVCodec *
The user has no business modifying the underlying AVCodec.

Reviewed-by: Paul B Mahol <onemda@gmail.com>
Reviewed-by: Nicolas George <george@nsup.org>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-09-11 14:42:36 +02:00
Paul B Mahol
1304078d3c avcodec: add FastAudio decoder 2020-09-03 18:07:58 +02:00
Paul B Mahol
a1caa16d45 avcodec: add ADPCM IMA MOFLEX decoder 2020-09-03 18:06:50 +02:00
Limin Wang
d7af6d1469 avcodec/utils: calculate frame number of HEVC if the framerate > 30FPS
Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
2020-08-16 22:51:11 +08:00
James Almer
0de01da1d2 avcodec: move ff_alloc_a53_sei() to atsc_53
Signed-off-by: James Almer <jamrial@gmail.com>
2020-08-15 13:01:25 -03:00
Zane van Iperen
62da99e1d0
avcodec: add adpcm_argo encoder
Signed-off-by: Zane van Iperen <zane@zanevaniperen.com>
2020-08-07 23:04:28 +10:00
Zane van Iperen
80dda80981 avcodec: add adpcm_ima_apm encoder
Signed-off-by: Zane van Iperen <zane@zanevaniperen.com>
2020-07-21 11:36:14 +10:00
Limin Wang
9294f5b497 avcodec/utils: add ff_alloc_timecode_sei() for hevc timecode sei
Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
2020-06-28 21:00:52 +08:00
James Almer
93016f5d1d avcodec/encode: restructure the old encode API
Following the same logic as 061a0c14bb, this commit turns the old encode API
into a wrapper for the new one.

Signed-off-by: James Almer <jamrial@gmail.com>
2020-06-18 17:11:37 -03:00
James Almer
827d6fe73d avcodec/encode: restructure the core encoding code
This commit follows the same logic as 061a0c14bb, but for the encode API: The
new public encoding API will no longer be a wrapper around the old deprecated
one, and the internal API used by the encoders now consists of a single
receive_packet() callback that pulls frames as required.

amf encoders adapted by James Almer
librav1e encoder adapted by James Almer
nvidia encoders adapted by James Almer
MediaFoundation encoders adapted by James Almer
vaapi encoders adapted by Linjie Fu
v4l2_m2m encoders adapted by Andriy Gelman

Signed-off-by: James Almer <jamrial@gmail.com>
2020-06-18 17:11:37 -03:00
Zane van Iperen
b1189c1571 avcodec: add adpcm_ima_ssi encoder
Signed-off-by: Zane van Iperen <zane@zanevaniperen.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2020-05-27 22:13:39 +02:00
James Almer
c7c8f141eb avcodec: move avcodec_flush_buffers from decode.c to utils.c
It's not a decoding exclusive function anymore.

Signed-off-by: James Almer <jamrial@gmail.com>
2020-05-24 12:05:40 -03:00
James Almer
d3bedba97f avcodec/decode: remove ff_decode_bsfs_uninit()
It's been a wrapper for a simple av_bsf_free() call since c96904f525.

Signed-off-by: James Almer <jamrial@gmail.com>
2020-05-21 12:32:15 -03:00
Limin Wang
79e3c4dd74 avcodec/utils: simplify, remove duplicate code
Reviewed-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
2020-05-05 08:20:45 +08:00
Mark Thompson
2594f6a362 lavc: Rename hwaccel.h to hwconfig.h
This already applied to decoders as well as hwaccels, and adding encoder
support was going to make the name even more inaccurate.
2020-04-26 18:38:25 +01:00
Anton Khirnov
9d6785d426 lavc: do not implicitly share the frame pool between threads
Currently the frame pool used by the default get_buffer2()
implementation is a single struct, allocated when opening the decoder.
A pointer to it is simply copied to each frame thread and we assume that
no thread attempts to modify it at an unexpected time. This is rather
fragile and potentially dangerous.

With this commit, the frame pool is made refcounted, with the reference
being propagated across threads along with other context variables. The
frame pool is now also immutable - when the stream parameters change we
drop the old reference and create a new one.
2020-04-10 15:47:30 +02:00
Nicolas Gaullier
42271f8e18 avcodec/utils: Fix ff_add_cpb_side_data() add twice
Makes it behave similarly to av_stream_add_side_data().

Signed-off-by: Anton Khirnov <anton@khirnov.net>
2020-03-20 09:16:05 +01:00
Paul B Mahol
c6bbdba9cd avcodec: add derf dpcm decoder 2020-03-17 16:05:15 +01:00
James Almer
c666689491 avcodec: add an AVCodecContext field to signal types of packet, frame, and coded stream side data to export
Add an initial mvs flag to is, analog to the export_mvs flags2 one.

Signed-off-by: James Almer <jamrial@gmail.com>
2020-02-22 23:19:07 -03:00
Paul B Mahol
dfb0b9370d avcodec: fix pcm zork decoder
Fixes #1939
2020-02-16 12:54:57 +01:00
leozhang
81d25e5bfc avcodec/utils: remove extra brackets
Signed-off-by: leozhang <leozhang@qiyi.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2020-02-01 19:04:50 +01:00
Limin Wang
8a62d88b0e avcodec/utils: replace avctx->internal with avci for better readability
Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2020-01-10 17:52:14 +01:00
Carl Eugen Hoyos
96fab29e96 Silence "string-plus-int" warning shown by clang.
libswscale/utils.c:89:42: warning: adding 'unsigned long' to a string does not append to the string [-Wstring-plus-int]
2020-01-06 22:38:56 +01:00
Zhao Zhili
f78dc66089 avcodec/utils: remove access of AV_SAMPLE_FMT_NB
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2019-12-31 12:37:47 +01:00
Linjie Fu
7aef2f59b5 lavc/utils.c: fix code indentations
Introduced since 4b4a02b8.

Signed-off-by: Linjie Fu <linjie.fu@intel.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2019-12-12 19:25:33 +01:00
Michael Niedermayer
f011572e66 avcodec/utils: Check block_align
Fixes: out of array access
Fixes: 18432/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_WMAV2_fuzzer-5675574936207360
Fixes: 18326/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_WMAV2_fuzzer-5071752362721280
Fixes: 18384/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_WMAV1_fuzzer-5769439500304384

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2019-11-01 14:43:16 +01:00
Michael Niedermayer
75fefb1fb7 avcodec/utils: Check sample_rate before opening the decoder
Fixes: signed integer overflow: 2 * -1306460384 cannot be represented in type 'int'
Fixes: 17685/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_AAC_fuzzer-5747390337777664
Fixes: 17688/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_INTERPLAY_ACM_fuzzer-5739287210885120
Fixes: 17699/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_INTERPLAY_ACM_fuzzer-5678394531905536
Fixes: 17738/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_TAK_fuzzer-5763415733174272
Fixes: 17746/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_BINKAUDIO_RDFT_fuzzer-5703008159006720

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Reviewed-by: James Almer <jamrial@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2019-09-30 22:44:43 +02:00
Michael Niedermayer
95e5396919 avcodec/utils: Optimize ff_color_frame() using memcpy()
4650975 -> 4493240 dezicycles

This optimizes lines 2 and later. Line 1 still uses av_memcpy_backptr()
This change originally fixed ossfuzz 10790 but this is now fixed by other
optimizations already

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2019-09-24 17:53:39 +02:00