1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-12-02 03:06:28 +02:00
Commit Graph

46080 Commits

Author SHA1 Message Date
Andreas Rheinhardt
321c31cfe6 avcodec/cbs_jpeg: Fix size of huffman symbol table array
L[i] can be in the range of 0-255, see table B.5 of ITU T.81.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-02-11 19:38:40 +01:00
Martin Storsjö
402784ba9f aarch64: h264dsp: Fix incorrectly indented code
Signed-off-by: Martin Storsjö <martin@martin.st>
2022-02-11 10:49:12 +02:00
Andreas Rheinhardt
10e520f1f1 avcodec/pngdec: Cleanup generically on init failure
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-02-11 06:52:12 +01:00
Jiasheng Jiang
c4d63dbc94 avcodec/vp6: return value check for av_mallocz
As the potential failure of the av_mallocz(), the 's->alpha_context'
could be NULL and be dereferenced later.
Therefore, it should be better to check it and deal with it if fails
in order to prevent memory leak, same as the av_frame_alloc() in
ff_vp56_init().

Fixes: 39a3894ad5 ("lavc/vp6: Implement "slice" threading for VP6A decode")
Reviewed-by: Peter Ross <pross@xvid.org>
Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>
2022-02-11 16:29:50 +11:00
Andreas Rheinhardt
e1edfe6416 avcodec/pthread_frame: Properly unref frame in case of decoding failure
Use ff_thread_release_buffer() instead of av_frame_unref(),
as the former handles the case of non-thread-safe callbacks
properly. (This is possible now that ff_thread_release_buffer()
no longer requires a ThreadFrame.)

Reviewed-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-02-09 17:22:51 +01:00
Andreas Rheinhardt
02220b88fc avcodec/thread: Don't use ThreadFrame when unnecessary
The majority of frame-threaded decoders (mainly the intra-only)
need exactly one part of ThreadFrame: The AVFrame. They don't
need the owners nor the progress, yet they had to use it because
ff_thread_(get|release)_buffer() requires it.

This commit changes this and makes these functions work with ordinary
AVFrames; the decoders that need the extra fields for progress
use ff_thread_(get|release)_ext_buffer() which work exactly
as ff_thread_(get|release)_buffer() used to do.

This also avoids some unnecessary allocations of progress AVBuffers,
namely for H.264 and HEVC film grain frames: These frames are not
used for synchronization and therefore don't need a ThreadFrame.

Also move the ThreadFrame structure as well as ff_thread_ref_frame()
to threadframe.h, the header for frame-threaded decoders with
inter-frame dependencies.

Reviewed-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-02-09 17:22:35 +01:00
Andreas Rheinhardt
f025b8e110 avcodec/threadframe: Add ff_thread_(get|release)_ext_buffer()
These will be used by the codecs that need allocated progress
and is in preparation for no longer using ThreadFrame by the codecs
that don't.

Reviewed-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-02-09 17:22:23 +01:00
Andreas Rheinhardt
b3551b6072 avcodec/thread: Move ff_thread_(await|report)_progress to new header
This is in preparation for further commits that will stop
using ThreadFrame for frame-threaded codecs that don't use
ff_thread_(await|report)_progress(); the API for those codecs
having inter-frame depdendencies will live in threadframe.h.

Reviewed-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-02-09 17:22:16 +01:00
Andreas Rheinhardt
7fc10e273b avcodec/hapdec: Remove always-false check
Reviewed-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-02-09 17:22:05 +01:00
Andreas Rheinhardt
7bf38eb000 avcodec/pthread_frame: Don't prematurily presume frame-threading
Several of our decoders support both frame- as well as slice-threading;
in case of the latter avctx->internal->thread_ctx points to
a SliceThreadContext, not to a frame-thread PerThreadContext.
So only treat avctx->internal->thread_ctx as the latter after
having checked that frame-threading is active.

Reviewed-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-02-09 17:18:43 +01:00
Michael Niedermayer
ce43e1c581 avcodec/motion_est: fix indention of ff_get_best_fcode()
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2022-02-09 10:54:30 +01:00
Michael Niedermayer
634312a70f avcodec/motion_est: Fix xy indexing on range violation in ff_get_best_fcode()
This codepath seems untested, no testcases change

Found-by: <mkver>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2022-02-09 10:54:30 +01:00
Michael Niedermayer
6ee283d7d0 avcodec/jpeglsdec: Increase range for N in ls_get_code_runterm() by using unsigned
Fixes: left shift of 32768 by 16 places cannot be represented in type 'int'
Fixes: Timeout
Fixes: 44219/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_SMVJPEG_fuzzer-4679455379947520
Fixes: 44088/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_SMVJPEG_fuzzer-4885976600674304

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2022-02-09 10:50:35 +01:00
Andreas Rheinhardt
8b49436452 avcodec/vp8: Remove always-false check
Since e9b6617579 a codec's close
function is never ever called for a codec whose init function has not
been called; in particular, it is never ever called if the
AVCodecContext's private data has not been allocated.

Reviewed-by: Peter Ross <pross@xvid.org>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-02-09 06:52:41 +01:00
Andreas Rheinhardt
42140010a2 avcodec/hcadec: Mark decoder as init-threadsafe
Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-02-09 06:52:41 +01:00
Andreas Rheinhardt
2c7f25d460 avcodec/hcadec: Fix memleak upon allocation error
An AVFloatDSPContext would leak upon av_tx_init() failure.

Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-02-09 06:52:41 +01:00
Andreas Rheinhardt
67e1013a96 avcodec/cbs_mpeg2: Use smaller scope for variables
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-02-08 07:11:14 +01:00
Andreas Rheinhardt
70a90fb73e avcodec/internal.h: Move avpriv_find_start_code() to startcode.h
This is by definition the appropriate place for it.
Remove all the now unnecessary libavcodec/internal.h inclusions;
also remove other unnecessary headers from the affected files.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-02-08 06:22:14 +01: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
Andreas Rheinhardt
115ac90ec9 avcodec/cbs_mpeg2: Simplify splitting fragment
avpriv_find_start_code() supports non-contiguous buffers
by maintaining a state that allows to find start codes
that span across multiple buffers; a consequence thereof
is that avpriv_find_start_code() is given a zero-sized
buffer, it does not modify this state, so that it appears
as if a start code was found if the state contained a start code.

This can e.g. happen with Sequence End units in MPEG-2 and
to counter this, cbs_mpeg2_split_fragment() reset the state
when it has already encountered the end of the fragment
in order to add the last unit (if it is only of the form 00 00 01 xy)
only once; it also used a flag to set whether this is the final unit.

Yet this can be improved by simply resetting state unconditionally
(thereby avoiding a branch); the flag can be removed by just checking
whether we have a valid start code (of the next unit to add)
at the end.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-02-08 06:10:08 +01:00
Andreas Rheinhardt
66d7a21132 avcodec/cbs: Make ff_cbs_insert_unit_data() always append the new unit
All split functions (the only users of this function) only
append units.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-02-08 06:02:05 +01:00
Andreas Rheinhardt
f183ae787a avcodec/cbs_jpeg: Remove redundant counter
Use -1 as the position in ff_cbs_insert_unit_data()
which implicitly reuses frag->nb_units as the counter.

Also switch to a do-while-loop, as it is more natural
than a for-loop now that the counter is gone.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-02-08 04:30:02 +01:00
Andreas Rheinhardt
d64e27f521 avcodec/cbs_mpeg2: Remove redundant counter
Use -1 as the position in ff_cbs_insert_unit_data()
which implicitly reuses frag->nb_units as the counter.

Also switch to a do-while-loop, as it is more natural
than a for-loop now that the counter is gone.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-02-08 04:00:30 +01:00
Andreas Rheinhardt
d3c6156ce3 avcodec/qsvenc: Reindent after the previous commit
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-02-07 00:31:23 +01:00
Anton Khirnov
35e52d21dc lavc/qsvenc: switch to new FIFO API 2022-02-07 00:31:23 +01:00
Anton Khirnov
08181624e0 lavc/qsvdec: switch to the new FIFO API 2022-02-07 00:31:23 +01:00
Anton Khirnov
587545c9e0 lavc/nvenc: switch to the new FIFO API 2022-02-07 00:31:23 +01:00
Anton Khirnov
9ef4b6699b lavc/libvpxenc: remove unneeded context variable
discard_hdr10_plus is 0 IFF hdr10_plus_fifo is non-NULL, so we can test
for the latter and avoid an extra variable.
2022-02-07 00:31:23 +01:00
Anton Khirnov
4b066b53b2 lavc/libvpxenc: switch to the new FIFO API 2022-02-07 00:31:23 +01:00
Anton Khirnov
a718d84e92 lavc/libvorbisenc: switch to new FIFO API 2022-02-07 00:31:23 +01:00
Anton Khirnov
6eaf5cd00a lavc/cuviddec: convert to the new FIFO API 2022-02-07 00:31:23 +01:00
Anton Khirnov
de40342c04 lavc/cuviddec: do not reallocate the fifo unnecessarily 2022-02-07 00:31:23 +01:00
Anton Khirnov
70611d7f3b lavc/amfenc: switch to new FIFO API 2022-02-07 00:31:23 +01:00
Anton Khirnov
37e70d4802 lavc/avcodec: switch to new FIFO API 2022-02-07 00:31:23 +01:00
James Almer
22d6d2b481 avcodec/decode: ignore unsupported skip samples packet side data values
Same as in the AV_FRAME_FLAG_DISCARD codepath, ensure avci->skip_samples is not
negative.

Signed-off-by: James Almer <jamrial@gmail.com>
2022-02-05 09:44:59 -03:00
Martin Storsjö
c69b1a12bb libfdk-aacdec: Flush delayed samples at the end
The fdk-aac decoder can return decoded audio data with a delay.
(Whether it does this or not depends on the options set; by default
it does add some delay.) Previously, this delay was handled by
adjusting the timestamps of the decoded frames, but the last delayed
samples weren't returned.

Set the AV_CODEC_CAP_DELAY flag to indicate that the caller should
flush remaining samples at the end. Also trim off the corresponding
amount of samples at the start instead of adjusting timestamps.

Signed-off-by: Martin Storsjö <martin@martin.st>
2022-02-03 23:57:57 +02:00
Martin Storsjö
340a78afeb libfdk-aacdec: Add an option for setting the decoder's DRC album mode
Signed-off-by: Martin Storsjö <martin@martin.st>
2022-02-03 23:51:47 +02:00
James Almer
61b104caaa avcodec/libdav1d: free the Dav1dData packet on dav1d_send_data() failure
We still own it on failure, and there's no point trying to feed it again.

This should address the issue reported in dav1d #383 and part of VLC #26259.

Signed-off-by: James Almer <jamrial@gmail.com>
Reviewed-by: Ronald S. Bultje <rsbultje@gmail.com>
2022-02-01 13:03:12 -03:00
Michael Niedermayer
cd6ac013a0 avcodec/cfhd: Avoid signed integer overflow in coeff
Fixes: signed integer overflow: 15244032 * 256 cannot be represented in type 'int'
Fixes: 43504/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_CFHD_fuzzer-4865014842916864

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2022-02-01 16:50:27 +01:00
Andreas Rheinhardt
f0a7db12a2 avcodec/h264_ps: Remove ALLOW_INTERLACED cruft
Since e1027aba68,
ALLOW_INTERLACED is no longer defined in h264_ps.c,
leading to a warning when encountering an SPS compatible
with MBAFF. This warning was always nonsense, because
ff_h264_decode_seq_parameter_set() is also used by the parser
and it makes no sense for the parser to warn about missing
decoder features; after all, it is not a parser's job
to warn when a feature is unsupported by a decoder
(and in this case it is even weirder, because even if the H.264
decoder is disabled, the warning will only be shown for MBAFF
sequence parameter sets). So remove the warning in h264_ps.c.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-01-29 20:35:05 +01:00
Andreas Rheinhardt
b065a70afa avcodec/libxvid: Don't set AVCodecContext.codec_id
Unnecessary since 2325bdad7b
(and crazy even before then).

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-01-29 19:30:25 +01:00
Andreas Rheinhardt
577ba4a1af avcodec/mpeg4videodec: Move use_intra_dc_vlc to stack, fix data race
use_intra_dc_vlc is currently kept in sync between frame threads
in mpeg4_update_thread_context(), yet it is set when decoding
blocks, i.e. after ff_thread_finish_setup(). This is a data race
and therefore undefined behaviour.

This race can be fixed easily by moving the variable from the context
to the stack: use_intra_dc_vlc is only read in
mpeg4_decode_block() and only if one is decoding an intra block.
There are three callsites for this function: One in
mpeg4_decode_partitioned_mb() which always sets use_intra_dc_vlc
before the call and two in mpeg4_decode_mb(). One of these callsites
is for intra blocks and use_intra_dc_vlc is set before it;
the last callsite is for non-intra blocks, where use_intra_dc_vlc
is ignored. So if it is used, it always uses a new value and can
therefore be moved to the stack.

The above also explains why this data race did not lead to
FATE-test failures.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-01-29 19:30:25 +01:00
Andreas Rheinhardt
24a654c6c9 avcodec/mpegvideo: Use offset instead of pointer for vbv_delay
An offset has the advantage of not needing to be updated
when the buffer is reallocated. Furthermore, the way the pointer
is currently updated is undefined behaviour in case the pointer
is not already set (i.e. when not encoding MPEG-1/2), because
it calculates the nonsense NULL - s->pb.buf.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-01-29 19:30:25 +01:00
Andreas Rheinhardt
5a04c6a269 avcodec/mpegpicture: Add function to completely free MPEG-Picture
Also use said function in mpegvideo.c and mpegvideo_enc.c;
and make ff_free_picture_tables() static as it isn't needed anymore
outside of mpegpicture.c.

Reviewed-by: James Almer <jamrial@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-01-29 19:30:25 +01:00
Andreas Rheinhardt
d0ceb90f44 avcodec/mpegpicture: Let ff_mpeg_unref_picture() free picture tables
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-01-29 19:30:25 +01:00
Andreas Rheinhardt
dcdb34be91 avcodec/mpegvideo: Move MPEG-4 Simple Studio Profile fields to mpeg4video
This is possible now that dealing with the Simple Studio Profile
has been moved to mpeg4videodec.c. It also allows to avoid
allocations, because one can simply put the required buffers
on the context (if one made these buffers part of MpegEncContext,
the memory would be wasted for every codec other than MPEG-4).

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-01-29 19:30:25 +01:00
Andreas Rheinhardt
85ac29ad1c avcodec/mpegvideo: Move handling Simple Studio Profile to mpeg4videodec
This is its only user.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-01-29 19:30:25 +01:00
Andreas Rheinhardt
d4d87f2ac5 avcodec/mpegvideo: Fix crash when using lowres with 10bit MPEG-4
In this case the macroblocks written to are smaller, yet
the MPEG-4 Simple Studio Profile code for 10bit DPCM ignored this;
e.g. in case of lowres = 2 or = 3, the sample mpeg4_sstp_dpcm.m4v
from the FATE-suite reads beyond the end of the buffer.

This commit fixes this by taking lowres into account.
The DPCM macroblocks of the aforementioned sample look
as good as can be expected after this patch; yet the non-DPCM
coded macroblocks are simply corrupt.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-01-29 19:30:25 +01:00
Andreas Rheinhardt
9953fc9a23 avcodec/mpegvideo: Fix off-by-one error when decoding >8 bit MPEG-4
Fixes visual corruptions on two macroblocks from two frames from
https://samples.ffmpeg.org/ffmpeg-bugs/trac/ticket4447/A003C003_SR_422_23.98p.mxf

Reviewed-by: Kieran Kunhya <kierank@obe.tv>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-01-29 19:30:25 +01:00
Andreas Rheinhardt
83c1ac6570 avcodec/mpegvideo_enc: Don't hardcode list of codecs supporting bframes
Check for the encoder's AV_CODEC_CAP_DELAY instead.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-01-29 19:30:24 +01:00