Commit Graph

48 Commits

Author SHA1 Message Date
Andreas Rheinhardt
4c7e8b969e avcodec/clearvideo: Avoid superfluous VLC structures
Of all these VLCs here, only VLC.table was really used
after init, so use the ff_vlc_init_tables API
to get rid of them.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2023-10-31 20:47:00 +01:00
Andreas Rheinhardt
9cdf82c2c2 avcodec/vlc: Use proper namespace
Therefore use a proper prefix for this API, e.g.
ff_init_vlc_sparse -> ff_vlc_init_sparse
ff_free_vlc        -> ff_vlc_free
INIT_VLC_LE        -> VLC_INIT_LE
INIT_VLC_USE_NEW_STATIC -> VLC_INIT_USE_STATIC
(The ancient INIT_VLC_USE_STATIC has been removed
in 595324e143, so that
the NEW has been dropped.)
Finally, reorder the flags and change their values
accordingly.

Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2023-09-11 00:27:45 +02:00
James Almer
dc7bd7c5a5 avcodec: use the new AVFrame key_frame flag in all decoders and encoders
Signed-off-by: James Almer <jamrial@gmail.com>
2023-05-04 18:48:22 -03:00
Andreas Rheinhardt
65f3bc9e7e avcodec/clearvideo: Avoid allocations when decoding tiles
Up until now, the ClearVideo decoder separates parsing tiles
and actually using the parsed information: The information is
instead stored in structures which are constantly allocated
and freed. This commit changes this to use the information
immediately, avoiding said allocations. This e.g. reduced
the amount of allocations for [1] from 2,866,462 to 24,720.
For said sample decoding speed improved by 143%.

[1]: https://samples.ffmpeg.org/V-codecs/UCOD/AccordianDance-300.avi

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-11-10 00:39:43 +01:00
Andreas Rheinhardt
165682a6d4 avcodec/clearvideo: Use const where appropriate
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-11-10 00:39:43 +01:00
Andreas Rheinhardt
c2966ae14c avcodec/clearvideo: Redo updating predicition
This is in preparation for further commits.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-11-10 00:39:43 +01:00
Andreas Rheinhardt
a7a783a5c5 avcodec/clearvideo: Move tile_do_block() upwards
Will avoid a forward-declaration later.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-11-10 00:39:43 +01:00
Andreas Rheinhardt
4e6ca99c36 avcodec/clearvideo: Remove unnecessary level parameter
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-11-10 00:39:43 +01:00
Andreas Rheinhardt
48286d4d98 avcodec/codec_internal: Add macro to set AVCodec.long_name
It reduces typing: Before this patch, there were 105 codecs
whose long_name-definition exceeded the 80 char line length
limit. Now there are only nine of them.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-09-03 15:42:57 +02:00
Andreas Rheinhardt
b9eaf77ed1 avcodec/internal: Move ff_set_dimensions() to decode.h
Decoder-only, as the dimensions are set by the user when encoding.

Also fixup the other headers a bit while removing unnecessary internal.h
inclusions.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-08-27 14:14:57 +02:00
Andreas Rheinhardt
e2c24e6a29 avcodec/internal: Move ff_reget_buffer() to decode.h
Only used by decoders.

Also clean up the headers a bit while removing now unnecessary
internal.h inclusions.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-08-27 14:14:56 +02:00
Andreas Rheinhardt
21b23ceab3 avcodec: Make init-threadsafety the default
and remove FF_CODEC_CAP_INIT_THREADSAFE
All our native codecs are already init-threadsafe
(only wrappers for external libraries and hwaccels
are typically not marked as init-threadsafe yet),
so it is only natural for this to also be the default state.

Reviewed-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-07-18 20:04:59 +02:00
Andreas Rheinhardt
2d764069be avcodec/vlc: Use structure instead of VLC_TYPE array as VLC element
In C, qualifiers for arrays are broken:
const VLC_TYPE (*foo)[2] is a pointer to an array of two const VLC_TYPE
elements and unfortunately this is not compatible with a pointer
to a const array of two VLC_TYPE, because the latter does not exist
as array types are never qualified (the qualifier applies to the base
type instead). This is the reason why get_vlc2() doesn't accept
a const VLC table despite not modifying the table at all, as
there is no automatic conversion from VLC_TYPE (*)[2] to
const VLC_TYPE (*)[2].

Fix this by using a structure VLCElem for the VLC table.
This also has the advantage of making it clear which
element is which.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-06-17 16:47:29 +02:00
Andreas Rheinhardt
4243da4ff4 avcodec/codec_internal: Use union for FFCodec decode/encode callbacks
This is possible, because every given FFCodec has to implement
exactly one of these. Doing so decreases sizeof(FFCodec) and
therefore decreases the size of the binary.
Notice that in case of position-independent code the decrease
is in .data.rel.ro, so that this translates to decreased
memory consumption.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-04-05 20:02:37 +02:00
Andreas Rheinhardt
ce7dbd0481 avcodec/codec_internal: Make FFCodec.decode use AVFrame*
This increases type-safety by avoiding conversions from/through void*.
It also avoids the boilerplate "AVFrame *frame = data;" line
for non-subtitle decoders.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-04-05 19:54:09 +02:00
Andreas Rheinhardt
20f9727018 avcodec/codec_internal: Add FFCodec, hide internal part of AVCodec
Up until now, codec.h contains both public and private parts
of AVCodec. This exposes the internals of AVCodec to users
and leads them into the temptation of actually using them
and forces us to forward-declare structures and types that
users can't use at all.

This commit changes this by adding a new structure FFCodec to
codec_internal.h that extends AVCodec, i.e. contains the public
AVCodec as first member; the private fields of AVCodec are moved
to this structure, leaving codec.h clean.

Reviewed-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-03-21 01:33:09 +01:00
Andreas Rheinhardt
a688f3c13c avcodec/internal: Move FF_CODEC_CAP_* to a new header codec_internal.h
Also move FF_CODEC_TAGS_END as well as struct AVCodecDefault.
This reduces the amount of files that have to include internal.h
(which comes with quite a lot of indirect inclusions), as e.g.
most encoders don't need it. It is furthemore in preparation
for moving the private part of AVCodec out of the public codec.h.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-03-21 01:33:09 +01:00
Michael Niedermayer
11fac9613e avcodec/clearvideo: Check tile_size to be not too large
Fixes: left shift of 1 by 31 places cannot be represented in type 'int'
Fixes: 35023/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_CLEARVIDEO_fuzzer-6740166587842560

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2021-06-29 19:36:36 +02:00
Michael Niedermayer
63e75e09ae avcodec/clearvideo: Check for 0 tile_shift
Fixes: shift exponent -1 is negative
Fixes: 33401/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_CLEARVIDEO_fuzzer-5908683596890112

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2021-05-12 23:00:07 +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
Anton Khirnov
e15371061d lavu/mem: move the DECLARE_ALIGNED macro family to mem_internal on next+1 bump
They are not properly namespaced and not intended for public use.
2021-01-01 14:14:57 +01:00
Andreas Rheinhardt
f86dcd007f avcodec/clearvideo: Make VLC tables static
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-12-08 17:51:45 +01:00
Andreas Rheinhardt
e67e4d43bd avcodec/clearvideo: Apply VLC offset during init
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-12-08 17:51:45 +01:00
Andreas Rheinhardt
222cc6ea26 avcodec/clearvideo: Use minimal max_depth in get_vlc2()
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-12-08 17:51:45 +01:00
Andreas Rheinhardt
c880889cfd avcodec/clearvideo: Inline constants
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-12-08 17:51:45 +01:00
Andreas Rheinhardt
ef9652bab2 avcodec/clearvideo: Improve handling of VLC escape values
Both the motion vector as well as the bias VLCs have an escape code;
for the motion vectors, this value depended on the specific VLC table,
whereas all the bias VLCs used the same value; the escape value has not
been inlined in the latter case.

But for both kinds of VLCs there are lots of values that are unused for
all the VLCs of each kind and each of these can be used as common escape
value, thus allowing to inline the escape value. This commit implements
this.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-12-08 17:51:45 +01:00
Andreas Rheinhardt
1d3ec27bd5 avcodec/clearvideo: Avoid huge VLC length tables
After the motion vector and bias values tables have been reordered so
that the codes are ordered from left to right, it emerged that the
length of these entries are actually ascending for every table.
Therefore it is possible to encode them in a run-length style and create
the actual length tables during runtime. This commit implements this.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-12-08 17:51:45 +01:00
Andreas Rheinhardt
e97081a624 avcodec/clearvideo: Avoid code duplication when initializing VLCs
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-12-08 17:51:45 +01:00
Andreas Rheinhardt
c82a559e6f avcodec/clearvideo: Avoid code tables for initializing VLCs
The ClearVideo decoder uses VLC tables that are initialized at runtime
from static length, symbol and codes tables. Yet the code tables can be
omitted by subjecting all of these tables to the permutation that orders
the codes from left to right in the tree. After this is done, the codes
can be easily computed at runtime from the lengths and therefore
omitted. This saves about 10KB.

Only one minor complication is encountered when doing so: The tree
corresponding to the AC VLC codes is incomplete; but this can be
handled by adding an entry with negative length.

Furthermore, there are also VLCs that are only initialized with lengths
and codes tables with codes of type uint16_t. These have also been
switched to ff_init_vlc_from_lengths() as this means that one can
replace the uint16_t codes tables with uint8_t symbols tables.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-12-08 17:51:45 +01:00
Andreas Rheinhardt
1d658e65ab avcodec/clearvideo: Don't check for errors for complete VLC
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-10-29 11:22:35 +01:00
James Almer
9ea6d2149e avcodec/decode: add a flags parameter to ff_reget_buffer()
Some decoders may not need a writable buffer in some specific cases, but only
a reference to the existing buffer with updated frame properties instead, for
the purpose of returning duplicate frames. For this, the
FF_REGET_BUFFER_FLAG_READONLY flag is added, which will prevent potential
allocations and buffer copies when they are not needed.

Signed-off-by: James Almer <jamrial@gmail.com>
2019-09-04 10:07:12 -03:00
Michael Niedermayer
5dc94924d0 avcodec/clearvideo: fix invalid shift in tile size check
Fixes: left shift of 1 by 31 places cannot be represented in type 'int'
Fixes: 15631/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_CLEARVIDEO_fuzzer-5690110605000704

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2019-08-03 17:44:23 +02:00
Michael Niedermayer
41f93f9411 avcodec/clearvideo: Check remaining data in P frames
Fixes: Timeout (19sec -> 419msec)
Fixes: 13411/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_CLEARVIDEO_fuzzer-5733153811988480

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2019-03-17 11:35:00 +01:00
Michael Niedermayer
7aaab127be avcodec/clearvideo: Check remaining input bits in P macro block loop
Fixes: Timeout
Fixes: 11083/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_CLEARVIDEO_fuzzer-5657180351496192

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2018-12-14 23:24:20 +01:00
Paul B Mahol
f09fdf2d9c avcodec/clearvideo: display warning if decoder overreads input
Signed-off-by: Paul B Mahol <onemda@gmail.com>
2018-04-24 17:20:26 +02:00
Paul B Mahol
e34751cb8a avcodec/clearvideo: do not try to return frame when it is same as previous one
Signed-off-by: Paul B Mahol <onemda@gmail.com>
2018-04-24 17:10:26 +02:00
Carl Eugen Hoyos
916632dfbb lavc/clearvideo: Allow decoding without extradata. 2018-04-07 22:13:20 +02:00
James Almer
fefe47b701 avcodec/clearvideo: fix mixed code and declarations
Signed-off-by: James Almer <jamrial@gmail.com>
2018-04-04 00:43:01 -03:00
Paul B Mahol
a874586994 avcodec/clearvideo: add inter-frame decoding
Signed-off-by: Paul B Mahol <onemda@gmail.com>
2018-04-03 17:28:16 +02:00
James Almer
269ed71e93 Merge commit '189157c3fc8eeb691e3684b09d971eb5ddb47d5b'
* commit '189157c3fc8eeb691e3684b09d971eb5ddb47d5b':
  Add ClearVideo decoder

See a63496cc88

Merged-by: James Almer <jamrial@gmail.com>
2017-10-30 15:49:38 -03:00
Michael Niedermayer
f0efd795f4 avcodec/clearvideo: Only output a frame if one is coded in the packet
Fixes: Timeout (183 ms instead of about 20 sec)
Fixes: 3147/clusterfuzz-testcase-4870592182353920

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2017-09-11 12:23:59 +02:00
Michael Niedermayer
43c394dcae avcodec/clearvideo: Check buf_size before decoding frame
Fixes; Timeout
Fixes: 1826/clusterfuzz-testcase-minimized-5728569256837120

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2017-05-26 01:38:03 +02:00
Michael Niedermayer
28230a690e avcodec/clearvideo: Fix runtime error: signed integer overflow: 181 * 18050756 cannot be represented in type 'int'
Fixes: 1417/clusterfuzz-testcase-minimized-6606778030620672

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/targets/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2017-05-09 00:42:20 +02:00
Michael Niedermayer
c0ffcb34c7 avcodec/clearvideo: Fix multiple runtime error: left shift of negative value -1024
Fixes: 1360/clusterfuzz-testcase-minimized-5606472043986944

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/targets/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2017-05-06 12:17:54 +02:00
Kostya Shishkov
189157c3fc Add ClearVideo decoder
Only I-frames are decoded for now.

Signed-off-by: Diego Biurrun <diego@biurrun.de>
2017-04-25 15:39:10 +02:00
Michael Niedermayer
fe46d92c15 avcodec/clearvideo: Do not lose the return code of decode_mb()
Fixes CID1401671

Reviewed-by: Paul B Mahol <onemda@gmail.com>
Reviewed-by: Nicolas George <george@nsup.org>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2017-03-30 23:35:18 +02:00
James Almer
f5c8d004c2 avcodec: stop using deprecated codec flags
Signed-off-by: James Almer <jamrial@gmail.com>
2017-03-25 21:37:05 -03:00
Kostya Shishkov
a63496cc88 avcodec: add ClearVideo decoder
Only I-frames are decoded for now.

Signed-off-by: Paul B Mahol <onemda@gmail.com>
2017-03-02 11:39:54 +01:00