1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-12-23 12:43:46 +02:00
Commit Graph

43448 Commits

Author SHA1 Message Date
Andreas Rheinhardt
aae499f77a avcodec/magicyuv: Reuse array instead of using multiple arrays
The lengths of the VLC codes are implicitly contained in the VLC tables
itself; apart from that they are not used lateron. So it is unnecessary
to store them and the very same array can be reused to parse the Huffman
table for the next plane.

Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-09-01 11:05:38 +02:00
Andreas Rheinhardt
7f452c099a avcodec/magicyuv: Don't zero unnecessarily
The code already checks that exactly the expected amount of entries are
read and set. Ergo it is unnecessary to zero them at the beginning.

Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-09-01 11:05:38 +02:00
Andreas Rheinhardt
e8716b7e4c avcodec/magicyuv: Simplify check for invalid Huffman codes
Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-09-01 11:05:38 +02:00
Andreas Rheinhardt
18dbbff525 avcodec/magicyuv: Unify qsort comparison functions
Up until now, there were three comparison functions depending upon
bitness. But they all are actually the same, namely a lexical ordering:
entry a > entry b iff a.len > b.len or a.len == b.len and a.sym < b.sym.
So they can be easily unified.

Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-09-01 11:05:38 +02:00
Andreas Rheinhardt
d0b0fc7cb9 avcodec/magicyuv: Avoid copying values around pointlessly
When parsing Huffman tables, an array of HuffEntries (a struct
containing a code's bitlength, its bits and its symbol) is used as
intermediate tables in order to sort the entries (the order depends on
both the length of the entries as well as on their symbols). After sorting
them, the symbol and len components are copied into other arrays (the
HuffEntries' code has never been set or used, despite using quite a lot
of stack space) and the codes are generated. Afterwards, the VLC is
created.

Yet ff_init_vlc_sparse() can handle non-continuous arrays as input;
there is no need to copy the entries at all. This commit implements
this.

Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-09-01 11:05:38 +02:00
Andreas Rheinhardt
7332a23b84 avcodec/magicyuv: Don't invert Huffman table symbols twice
When the MagicYUV decoder builds Huffman tables from an array of code
lengths, it proceeds as follows: First it copies the entries of the
array of lengths into an array of HuffEntries (a struct which contains
a length and a symbol field); it also sets the symbol field in
descending order from nb_elem - 1 to 0, where nb_elem is the common number
of elements of the length and HuffEntry arrays. Then the HuffEntry array
is sorted lexicographically: a > b iff a.len > b.len or a.len == b.len and
a.sym > b.sym. Afterwards the symbols of the so sorted array are
inverted again (i.e. each symbol sym is replaced by nb_elem - sym).

Yet inverting can easily be avoided altogether: Just modify the order so
that smaller symbols correspond to bigger HuffEntries. This leads to the
same permutation as the current code does and given that the two
inversions just cancel each other out, the result is the same.

Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-09-01 11:05:38 +02:00
Andreas Rheinhardt
6fad76b51d avcodec/bitstream: Remove outdated comment
The comment referred to the INIT_VLC_USE_STATIC flag which has been
removed in 2009 in 595324e143b57a52e2329eb47b84395c70f93087; the
function it referred to was removed even earlier in commit
83422c1940 in 2008.

Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-09-01 09:07:58 +02:00
Paul B Mahol
04d335e436 avcodec/sheervideo: use cached bitstream reader except for x32 2020-08-31 20:10:24 +02:00
Paul B Mahol
57915df230 avcodec/magicyuv: change bits used by 12bit tables
Higher number slows decoder.
2020-08-31 19:56:22 +02:00
Paul B Mahol
276d86a8b8 avcodec/magicyuv: use cached bitstream reader except for x32 2020-08-31 16:31:25 +02:00
Paul B Mahol
445e5fb67a avcodec/magicyuv: invert symbols when building vlc
Instead at every decoded symbol.
2020-08-31 16:31:10 +02:00
Andreas Rheinhardt
e6c5102fb4 avcodec/roqvideodec: Remove set-but-unused frame stats
Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-08-31 03:00:09 +02:00
Andreas Rheinhardt
a067d44955 avcodec/roqvideodec: Move transient GetByteContext to the stack
This avoids keeping potentially dangling pointers in the context,
beautifies the code (by replacing "&ri->gb" by gb for every access to
the GetByteContext) and also highlights the GetByteContext's short-lived
nature better.

Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-08-31 02:59:36 +02:00
Paul B Mahol
72942ad6d4 avcodec/cdxl: also mark decoded frame as keyframe 2020-08-31 00:15:22 +02:00
Paul B Mahol
ef46de695f avcodec/qpeg: reduce unnecessary size of tables 2020-08-30 23:52:21 +02:00
Gautam Ramakrishnan
341064d68a libavcodec/jpeg2000: fix tag tree reset
The implementation of the tag tree did not
set the correct reset value for the encoder.
This lead to inefficent tag tree being encoded.
This patch fixes the implementation of the
ff_tag_tree_zero() function.

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2020-08-30 16:18:37 +02:00
Gautam Ramakrishnan
f0e33119e4 libavcodec/j2kenc: Support for multiple layers
This patch allows setting a compression ratio and to
set multiple layers. The user has to input a compression
ratio for each layer.
The per layer compression ration can be set as follows:
-layer_rates "r1,r2,...rn"
for to create 'n' layers.

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2020-08-30 16:18:37 +02:00
Gautam Ramakrishnan
3c06045a8b libavcodec/j2kenc: Fix tag tree coding
The implementation of tag tree encoding was incorrect.
However, this error was not visible as the current j2k
encoder encodes only 1 layer.
This patch fixes tag tree coding for JPEG2000 such tag
tree coding would work for multi layer encoding.

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2020-08-30 16:18:37 +02:00
Gautam Ramakrishnan
87567fc398 libavcodec/jpeg2000: Make tag tree functions non static
This patch makes the tag_tree_zero() and tag_tree_size()
functions non static and callable from other files.

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2020-08-30 16:18:37 +02:00
Michael Niedermayer
659658d08b avcodec/cfhd: Check transform type
Fixes: out of array access
Fixes: 24823/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_CFHD_fuzzer-4855119863349248

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2020-08-30 16:18:37 +02:00
Xiaohan Wang
b54c7797c5 avcodec/aacdec_template: Initialize layout_map on declaration
Without this change, it'll cause use-of-uninitialized-variable error.

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2020-08-30 16:18:37 +02:00
Michael Niedermayer
a0f20c3b3f avcodec/mpegvideo_enc: Replace some s->avctx by avctx
Fixes issue reported by: Xu Guangxin <guangxin.xu@intel.com>
Original report:
Steps to reproduce:
1. ./configure --enable-debug=3 --disable-libx264 && make install
2. ffmpeg -i input.mp4 -profile:v baseline output.mp4 -y

you will see a crash like this:
[mpeg4 @ 0x5555575854c0] [Eval @ 0x7fffffffbf80] Undefined constant or missing '(' in 'baseline'
[mpeg4 @ 0x5555575854c0] Unable to parse option value "baseline"
[mpeg4 @ 0x5555575854c0] Error setting option profile to value baseline.
Thread 1 "ffmpeg" received signal SIGSEGV, Segmentation fault.

root cause:
If the codec has FF_CODEC_CAP_INIT_CLEANUP flag, and avcodec_open2 got an error before avctx->codec->init,
the ff_mpv_encode_end will face a null s->avctx.

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2020-08-30 16:18:37 +02:00
Michael Niedermayer
2359656da2 avcodec/cfhd: Replace a few literal numbers by named constants
Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2020-08-30 16:18:37 +02:00
Andreas Rheinhardt
9372eb00c8 avcodec/truemotion1: Cleanup generically after init failure
Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-08-30 03:07:33 +02:00
Andreas Rheinhardt
c767af97f8 avcodec/y41penc: Remove empty close function
Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-08-30 03:06:50 +02:00
Andreas Rheinhardt
beca89ed28 avcodec/yuv4enc: Remove empty functions
Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-08-30 03:06:18 +02:00
Andreas Rheinhardt
099bc252c6 avcodec/wnv1: Move temporary variables from context to stack
Here it even leads to the complete removal of the context.

Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-08-30 03:05:03 +02:00
Andreas Rheinhardt
0166b1d1a6 avcodec/wnv1: Use LE bitstream reader, avoid copying packet, fix memleak
The Winnov WNV1 format is designed for a little-endian bitstream reader;
yet our decoder reversed every byte bitwise (in a buffer only
allocated for this purpose) to use a big-endian bitstream reader. This
commit stops this.

Two things needed to be done to achieve this: The codes in the table used
to initialize a VLC reader needed to be reversed bitwise (when
initializing a VLC in LE mode, it is expected that the first bit to be
read is in the least significant bit; with BE codes the first bit to be
read is the most significant bit of the code) and the following
expression needed to be adapted:

ff_reverse[get_bits(&w->gb, 8 - w->shift)]

But this is easy: When only the bits read are reversed, they coincide
with what a little-endian bitstream reader reads that reads the
original, not-reversed data. But ff_reverse always reverses the full
eight bits and this also performs a shift by (8 - (8 - w->shift)) on top
of reversing the bits read. So the above line needs to be changed to

get_bits(&w->gb, 8 - w->shift) << w->shift

and this also shows why the variable shift is named the way it is.

Finally, this also fixes a hypothetical memleak: For gigantic packets,
initializing a GetBitContext can fail and in this case, the buffer
containing the reversed data would leak.

Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-08-30 03:02:13 +02:00
Andreas Rheinhardt
7c8cf40adc avcodec/roqvideoenc: Cleanup generically after init failure
Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-08-30 03:00:42 +02:00
Andreas Rheinhardt
c38405c149 avcodec/roqvideodec: Cleanup generically after init failure
Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-08-30 03:00:13 +02:00
Andreas Rheinhardt
3a76076513 avcodec/mss3: Cleanup generically after init failure
Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-08-30 02:59:08 +02:00
Andreas Rheinhardt
c1d3b4705e avcodec/mss3: Remove unnecessary free of unallocated frame
The frame will only be allocated a few lines below.

Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-08-30 02:58:52 +02:00
Andreas Rheinhardt
35b478de5b avcodec/interplayvideo: Cleanup generically after init failure
Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-08-30 02:57:37 +02:00
Andreas Rheinhardt
3c7ca68eeb avcodec/eacmv: Cleanup generically after init failure
Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-08-30 02:57:06 +02:00
Andreas Rheinhardt
fea984d5c7 avcodec/cinepakenc: Cleanup generically after init failure
Reviewed-by: Tomas Härdin <tjoppen@acc.umu.se>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-08-30 02:55:43 +02:00
Andreas Rheinhardt
5ff2ff6bd9 avcodec/truemotion2: Avoid duplicating array, fix memleak
TrueMotion 2.0 uses Huffmann trees. To parse them, the decoder allocates
arrays for the codes, their lengths and their value; afterwards a VLC
table is initialized using these values. If everything up to this point
succeeds, a new buffer of the same size as the already allocated arrays
for the values is allocated and upon success the values are copied into
the new array; all the old arrays are then freed. Yet if allocating the
new array fails, the old arrays get freed, but the VLC table doesn't.

This leak is fixed by not allocating a new array at all; instead the old
array is simply reused, ensuring that nothing can fail after the
creation of the VLC table.

Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-08-29 18:49:51 +02:00
James Almer
1a35fffaf2 x86/cfhddsp: zero extend int arguments
if taken from stack, they may have garbage in the upper bits otherwise.
Also, there are only 8 arguments, so don't attempt to load 11.

Fixes SIGSEV crashes in some targets.

Reviewed-by: durandal_1707
Signed-off-by: James Almer <jamrial@gmail.com>
2020-08-28 20:09:25 -03:00
Paul B Mahol
ccc7120ee7 avcodec/flacdec: use designated initializers for AVClass 2020-08-28 01:16:55 +02:00
Andreas Rheinhardt
5c923ce668 avcodec/cfhd: Remove unused-but-set variable
Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-08-28 00:43:28 +02:00
Paul B Mahol
4aac742505 avcodec/x86/cfhddsp: try to fix build on x32 2020-08-26 23:39:58 +02:00
Paul B Mahol
389cc142fb avcodec/cfhd: add x86 SIMD
Overall speed changes for 1920x1080, yuv422p10le, 60fps from: 0.19x to 0.343x
2020-08-26 21:13:38 +02:00
Michael Niedermayer
b9ea493afe avcodec/tiff: Check jpeg context against jpeg frame parameters
Fixes: out of array access
Fixes: 24825/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_TIFF_fuzzer-6326925027704832

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2020-08-26 20:31:09 +02:00
Michael Niedermayer
ad29f9e47c avcodec/tiff: Restrict tag order based on specification
"The entries in an IFD must be sorted in ascending order by Tag. Note that this is
 not the order in which the fields are described in this document."

This way various dimensions, sample and bit sizes cannot be changed at
arbitrary times which reduces the potential for bugs.
The tag reading code also on various places assumes that numerically previous
tags have already been parsed, so this needs to be enforced one way or another.

If this commit causes problems with real world files which are not easy to fix
then some other form of checks are needed to ensure the various dependencies
in the tag reading are not violated.

Fixes: out of array access
Fixes: 24825/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_TIFF_fuzzer-6326925027704832

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2020-08-26 20:31:09 +02:00
Michael Niedermayer
ca47402a06 avcodec/tiff: Avoid abort with DNG RAW TIFF with YA8
Fixes: Assertion failure
Fixes: 24707/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_TIFF_fuzzer-5179910197608448

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2020-08-26 20:31:09 +02:00
Michael Niedermayer
7577f8332a avcodec/tiff: Check the linearization table size
Fixes: out of array access
Fixes: 24604/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_TIFF_fuzzer-4843529818603520

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2020-08-26 20:31:09 +02:00
Derek Buitenhuis
649a6969f7 avcodec/libdav1d: Call ff_set_sar in addition to setting the frame SAR
Similar to what we do in libaomdec.c.

Signed-off-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
2020-08-26 16:44:03 +01:00
James Almer
98f7e0081b avcodec/cbs_av1: fix setting FrameWidth in frame_size_with_refs()
Section 5.9.7 of the spec states

    UpscaledWidth = RefUpscaledWidth[ ref_frame_idx[ i ] ]
    FrameWidth    = UpscaledWidth
    FrameHeight   = RefFrameHeight[ ref_frame_idx[ i ] ]
    RenderWidth   = RefRenderWidth[ ref_frame_idx[ i ] ]
    RenderHeight  = RefRenderHeight[ ref_frame_idx[ i ] ]

Meaning FrameWidth must not be set to RefFrameWidth[ ref_frame_idx[ i ] ]
like we're currently doing.

Reviewed-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
2020-08-25 18:46:06 -03:00
James Almer
0892b04509 avcodec/av1_parser: fix parsing show_existing_frame headers
Regression since c8716b5029

Signed-off-by: James Almer <jamrial@gmail.com>
2020-08-25 15:01:43 -03:00
James Almer
97819f15a8 avcodec/cbs_av1: use a more appropiate AV1ReferenceFrameState pointer variable name
frame is more commonly used for AV1RawFrameHeader and AV1RawFrame.

Signed-off-by: James Almer <jamrial@gmail.com>
2020-08-25 14:53:42 -03:00
James Almer
e76b4b2a6b avcodec/cbs_av1: fix handling reference frames on show_existing_frame frames
Implement Section 7.21 "Reference frame loading process" and Section 7.20
"Reference frame update process" for show_existing_frame frames, as required by
the definition in Section 7.4 "Decode frame wrapup process".

Signed-off-by: James Almer <jamrial@gmail.com>
2020-08-25 14:49:33 -03:00