1
mirror of https://git.videolan.org/git/ffmpeg.git synced 2024-09-18 20:44:59 +02:00
Commit Graph

97 Commits

Author SHA1 Message Date
Andreas Rheinhardt
56e9e0273a avcodec/encode: Always use intermediate buffer in ff_alloc_packet2()
Up until now, ff_alloc_packet2() has a min_size parameter:
It is supposed to be a lower bound on the final size of the packet
to allocate. If it is not too far from the upper bound (namely,
if it is at least half the upper bound), then ff_alloc_packet2()
already allocates the final, already refcounted packet; if it is
not, then the packet is not refcounted and its data only points to
a buffer owned by the AVCodecContext (in this case, the packet will
be made refcounted in encode_simple_internal() in libavcodec/encode.c).
The goal of this was to avoid data copies and intermediate buffers
if one has a precise lower bound.

Yet those encoders for which precise lower bounds exist have recently
been switched to ff_get_encode_buffer() (which automatically allocates
final buffers), leaving only two encoders to actually set the min_size
to something else than zero (namely aliaspixenc and hapenc). Both of
these encoders use a very low lower bound that is not helpful in any
nontrivial case.

This commit therefore removes the min_size parameter as well as the
codepath in ff_alloc_packet2() for the allocation of final buffers.
Furthermore, the function has been renamed to ff_alloc_packet() and
moved to encode.h alongside ff_get_encode_buffer().

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-06-08 12:52:50 +02:00
Andreas Rheinhardt
30a947b8f8 avcodec/sonic: Mark decoder as init-threadsafe
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2021-05-02 05:14:42 +02:00
Andreas Rheinhardt
0878ccdcd2 avcodec/sonic: Mark encoders as init-threadsafe
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2021-05-02 05:14:41 +02:00
Andreas Rheinhardt
a247ac640d avcodec: Constify AVCodecs
Given that the AVCodec.next pointer has now been removed, most of the
AVCodecs are not modified at all any more and can therefore be made
const (as this patch does); the only exceptions are the very few codecs
for external libraries that have a init_static_data callback.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
2021-04-27 10:43:15 -03:00
Andreas Rheinhardt
c81b8e04aa Avoid intermediate bitcount for number of bytes in PutBitContext
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2021-03-30 12:36:32 +02:00
Andreas Rheinhardt
0ab70230f2 avcodec/sonic: Remove outdated outcommented line
Compilation would fail if it were outcommented as it refers to a
nonexistent PutBitContext.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2021-03-30 12:36:31 +02:00
Michael Niedermayer
075d793ba8 avcodec/sonic: Use unsigned temporary in predictor_calc_error()
Fixes: signed integer overflow: -2147471366 - 18638 cannot be represented in type 'int'
Fixes: 30157/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_SONIC_fuzzer-5171199746506752

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2021-03-28 14:20:00 +02:00
Hendrik Leppkes
494f868e93 avcodec: set AV_CODEC_CAP_CHANNEL_CONF on decoders which set their own channels
The decoders in this set either have a fixed channel count, or read it
from the bitstream, and thus do not require the channel count as
external information.

Fixes various regressions since
81503ac58a, which requires a valid channel
count for decoders which do not set this capability.

Signed-off-by: Hendrik Leppkes <h.leppkes@gmail.com>
2020-12-10 13:28:35 +01:00
Andreas Rheinhardt
992adc8aaf avcodec/sonic: Don't allocate a temporary buffer for every frame
Instead allocate it together with the buffer that it mirrors.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-11-06 13:57:49 +01:00
Andreas Rheinhardt
63f5f01226 avcodec/sonic: Don't hardcode sizeof(int) == 4
Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-11-04 21:30:56 +01:00
Andreas Rheinhardt
cba55c3353 avcodec/sonic: Allocate several buffers together
It simplifies freeing them and reduces the amount of allocations.

Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-11-04 21:09:58 +01:00
Michael Niedermayer
eeabdef1bf avcodec/sonic: Check for overread
Fixes: Timeout (too long -> 1.3 sec)
Fixes: 24358/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_SONIC_fuzzer-5107284099989504

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-15 22:53:56 +02:00
Michael Niedermayer
f249981976 avcodec/sonic: Check channels before deallocating
Fixes: heap-buffer-overflow
Fixes: 25744/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_SONIC_fuzzer-5172961169113088

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Reviewed-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2020-09-25 10:21:28 +02:00
Andreas Rheinhardt
7d91f9271e avcodec/sonic: Fix leaks upon allocation errors
The Sonic decoder and encoders allocate several buffers in their init
function and return immediately if one of these allocations fails; this
will lead to leaks if there was an earlier successfull allocation. Fix
this by setting the FF_CODEC_CAP_INIT_CLEANUP flag.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-09-17 00:09:08 +02:00
Michael Niedermayer
61d9bf514d avcodec/sonic: Fix several integer state overflows
Fixes: signed integer overflow: -234 * -14797801 cannot be represented in type 'int'
Fixes: 20492/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_SONIC_fuzzer-5695924975435776
Fixes: 22275/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_SONIC_fuzzer-5695924975435776

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2020-06-14 19:17:07 +02:00
Michael Niedermayer
75d520e337 avcodec/sonic: Fix several integer overflows
Fixes: signed integer overflow: 2129689466 + 2129689466 cannot be represented in type 'int'
Fixes: 20715/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_SONIC_fuzzer-5155263109922816

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2020-06-14 19:17:07 +02:00
Michael Niedermayer
aea6755611 avcodec/sonic: Check e in get_symbol()
Fixes: signed integer overflow: 1721520852 + 1721520852 cannot be represented in type 'int'
Fixes: 18346/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_SONIC_fuzzer-5709623893426176
Fixes: 18753/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_SONIC_fuzzer-5663299131932672

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2019-12-31 18:43:50 +01:00
Michael Niedermayer
c8c17b8cef avcodec/sonic: Fix integer overflow in predictor_calc_error()
Fixes: signed integer overflow: 5 * -1094995529 cannot be represented in type 'int'
Fixes: 18346/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_SONIC_fuzzer-5709623893426176

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2019-11-20 15:50:15 +01:00
Michael Niedermayer
1be9a28f8e avcodec/rangecoder: factorize termination version code
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2018-12-31 17:44:18 +01:00
Andreas Cadhalpun
9637c2531f sonic: make sure num_taps * channels is not larger than frame_size
If that is the case, the loop setting predictor_state in
sonic_decode_frame causes out of bounds reads of int_samples, which has
only frame_size number of elements.

Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: Andreas Cadhalpun <Andreas.Cadhalpun@googlemail.com>
2015-12-17 19:55:09 +01:00
Michael Niedermayer
6ae1a32d8a avcodec/sonic: Check init_get_bits8() for failure
Fixes: CID1322310

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2015-09-04 02:14:10 +02:00
Michael Niedermayer
444e9874a7 Merge commit 'def97856de6021965db86c25a732d78689bd6bb0'
* commit 'def97856de6021965db86c25a732d78689bd6bb0':
  lavc: AV-prefix all codec capabilities

Conflicts:
	cmdutils.c
	ffmpeg.c
	ffplay.c
	libavcodec/8svx.c
	libavcodec/aacenc.c
	libavcodec/ac3dec.c
	libavcodec/adpcm.c
	libavcodec/alac.c
	libavcodec/atrac3plusdec.c
	libavcodec/bink.c
	libavcodec/dnxhddec.c
	libavcodec/dvdec.c
	libavcodec/dvenc.c
	libavcodec/ffv1dec.c
	libavcodec/ffv1enc.c
	libavcodec/fic.c
	libavcodec/flacdec.c
	libavcodec/flacenc.c
	libavcodec/flvdec.c
	libavcodec/fraps.c
	libavcodec/frwu.c
	libavcodec/gifdec.c
	libavcodec/h261dec.c
	libavcodec/hevc.c
	libavcodec/iff.c
	libavcodec/imc.c
	libavcodec/libopenjpegdec.c
	libavcodec/libvo-aacenc.c
	libavcodec/libvorbisenc.c
	libavcodec/libvpxdec.c
	libavcodec/libvpxenc.c
	libavcodec/libx264.c
	libavcodec/mjpegbdec.c
	libavcodec/mjpegdec.c
	libavcodec/mpegaudiodec_float.c
	libavcodec/msmpeg4dec.c
	libavcodec/mxpegdec.c
	libavcodec/nvenc_h264.c
	libavcodec/nvenc_hevc.c
	libavcodec/pngdec.c
	libavcodec/qpeg.c
	libavcodec/ra288.c
	libavcodec/rv10.c
	libavcodec/s302m.c
	libavcodec/sp5xdec.c
	libavcodec/takdec.c
	libavcodec/tiff.c
	libavcodec/tta.c
	libavcodec/utils.c
	libavcodec/v210dec.c
	libavcodec/vp6.c
	libavcodec/vp9.c
	libavcodec/wavpack.c
	libavcodec/yop.c

Merged-by: Michael Niedermayer <michael@niedermayer.cc>
2015-07-27 22:50:18 +02:00
Michael Niedermayer
e36db49b7b avcodec: Add a min size parameter to ff_alloc_packet2()
This parameter can be used to inform the allocation code about how much
downsizing might occur, and can be used to optimize how to allocate the
packet

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2015-07-27 19:57:52 +02:00
Andreas Cadhalpun
58995f647b sonic: set avctx->channels in sonic_decode_init
Otherwise it can be 0 in sonic_decode_frame, causing SIGFPE crashes.

Reviewed-by: Michael Niedermayer <michaelni@gmx.at>
Signed-off-by: Andreas Cadhalpun <Andreas.Cadhalpun@googlemail.com>
2015-06-09 23:21:51 +02:00
Michael Niedermayer
ade8a46154 avcodec/sonic: More completely check sample_rate_index and channels
Fixes CID1271783

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2015-05-15 17:31:58 +02:00
Michael Niedermayer
c131a9fead avcodec/sonic: check memory allocations
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2015-05-15 17:26:54 +02:00
Michael Niedermayer
6026a5ad4f sonic: Switch to rangecoder
significantly improves compression rate

This also bumps version to 2 and drops support for version 0/1
If someone used version 0/1 despite their experimental status then support
for these can and should be added back

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2013-12-10 16:18:51 +01:00
Michael Niedermayer
c61daa68e4 avcodec/sonic: add larger version and minor_version fields with version >= 2
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2013-12-10 15:56:01 +01:00
Michael Niedermayer
4c32629b82 avcodec/sonic: move version to the context
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2013-12-10 15:50:12 +01:00
Michael Niedermayer
ec4d761c74 avcodec/sonic: fix memleaks
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2013-12-10 14:42:17 +01:00
Michael Niedermayer
8477e63d3c sonic: use M_SQRT2
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2013-12-10 14:38:38 +01:00
Clément Bœsch
b46f19100b cosmetics: group remaining .name and .long_name.
See b2bed9325.
2013-10-04 13:33:20 +00:00
Michael Niedermayer
6d05039c7e avcodec/sonic: Fix usage of init_get_bits() and use init_get_bits8()
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2013-07-04 13:40:08 +02:00
Michael Niedermayer
9375f5003d sonic: use av_freep() as its safer than av_free()
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2013-06-23 19:45:39 +02:00
Michael Niedermayer
69d0a2922f sonic: cleanup/simplify num_taps check
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2013-06-23 19:44:24 +02:00
Michael Niedermayer
db27dadcb0 sonic: replace divide() by ROUNDED_DIV()
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2013-06-23 19:42:24 +02:00
Michael Niedermayer
730e07f10b sonic: avoid float sqrt() for integer input & output
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2013-06-23 01:35:34 +02:00
Michael Niedermayer
4ec7ef56bd sonic: simplify quant cliping
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2013-06-23 01:35:34 +02:00
Michael Niedermayer
bcb42fb6db sonic: use av_calloc()
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2013-06-23 01:26:18 +02:00
Michael Niedermayer
37c7a8be19 sonic: replace literal numbers by sizeof()
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2013-06-22 22:25:18 +02:00
Michael Niedermayer
081a7f3ed0 sonic: replace some float by integers to improve platform independance
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2013-06-22 21:58:13 +02:00
Michael Niedermayer
12de2933da sonic: Improve error codes
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2013-06-22 21:42:04 +02:00
Michael Niedermayer
8689ee0eef sonic: simplify shift_down()
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2013-06-22 21:34:11 +02:00
Michael Niedermayer
ddefb80c95 sonicenc: fix off by 1 error
Fixes out of array accesses

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2013-06-19 10:06:38 +02:00
Michael Niedermayer
694c2d1ab3 sonicenc: dont put multiple assignments per line
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2013-06-19 10:06:10 +02:00
Michael Niedermayer
6df61c3ae0 sonicenc: set supported samples formats array
This ensures that only supported formats are input

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2013-06-19 09:50:01 +02:00
Paul B Mahol
dc5c029f02 sonicenc: don't allocate unused avctx->coded_frame
Signed-off-by: Paul B Mahol <onemda@gmail.com>
2013-06-07 09:29:34 +00:00
Michael Niedermayer
4aa8503399 sonicdec: update to new buffer API
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2013-03-21 16:01:53 +01:00
Michael Niedermayer
85d7f54662 sonicenc: fix mono decorrelation
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2013-03-21 15:49:22 +01:00
Michael Niedermayer
6ec037c5a9 sonicdec: fix frame size
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2013-03-21 15:46:16 +01:00