]> git.sesse.net Git - ffmpeg/log
ffmpeg
3 years agolavd/caca: do not access deprecated codec context
Anton Khirnov [Sun, 29 Nov 2020 15:28:08 +0000 (16:28 +0100)]
lavd/caca: do not access deprecated codec context

Use the stream timebase instead.

3 years agocodec_desc: add SMVJPEG flags
Anton Khirnov [Tue, 1 Dec 2020 17:55:22 +0000 (18:55 +0100)]
codec_desc: add SMVJPEG flags

Same flags as MJPEG, as it's essentially the same codec.

3 years agoimg2dec: export avg_frame_rate
Anton Khirnov [Wed, 7 Oct 2020 11:02:39 +0000 (13:02 +0200)]
img2dec: export avg_frame_rate

3 years agoavcodec/hevcdec: dynamic allocate sList and HEVClcList
Nuo Mi [Sun, 29 Nov 2020 15:30:10 +0000 (23:30 +0800)]
avcodec/hevcdec: dynamic allocate sList and HEVClcList

following comandline will crash the ffmpeg
ffmpeg -threads 17 -thread_type slice -i WPP_A_ericsson_MAIN_2.bit out.yuv -y

the HEVCContext->sList size is MAX_NB_THREADS(16), any > 16 thread number will crash the application

Signed-off-by: Anton Khirnov <anton@khirnov.net>
3 years agoavcodec/snow: Use ff_thread_once() in ff_snow_common_init()
Andreas Rheinhardt [Tue, 1 Dec 2020 23:10:13 +0000 (00:10 +0100)]
avcodec/snow: Use ff_thread_once() in ff_snow_common_init()

ff_snow_common_init() currently initializes static data every time it is
invoked; given that both the Snow encoder and decoder have the
FF_CODEC_CAP_INIT_THREADSAFE flag set, this can lead to data races (and
therefore undefined behaviour) even though all threads write the same
values. This commit fixes this by using ff_thread_once() for the
initializations.

Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/idcinvideo: Mark decoder as init-threadsafe
Andreas Rheinhardt [Mon, 30 Nov 2020 17:24:37 +0000 (18:24 +0100)]
avcodec/idcinvideo: Mark decoder as init-threadsafe

Reviewed-by: Tomas Härdin <tjoppen@acc.umu.se>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/cinepak: Mark decoder as init-threadsafe
Andreas Rheinhardt [Mon, 30 Nov 2020 13:46:30 +0000 (14:46 +0100)]
avcodec/cinepak: Mark decoder as init-threadsafe

Reviewed-by: Tomas Härdin <tjoppen@acc.umu.se>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/cinepakenc: Mark encoder as init-threadsafe
Andreas Rheinhardt [Mon, 30 Nov 2020 13:44:49 +0000 (14:44 +0100)]
avcodec/cinepakenc: Mark encoder as init-threadsafe

Reviewed-by: Tomas Härdin <tjoppen@acc.umu.se>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavformat/matroskadec: Sanity check codec_id/track type
Michael Niedermayer [Sun, 6 Dec 2020 23:37:25 +0000 (00:37 +0100)]
avformat/matroskadec: Sanity check codec_id/track type

Fixes: memleak
Fixes: 27766/clusterfuzz-testcase-minimized-ffmpeg_dem_MATROSKA_fuzzer-5198300814508032
Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
3 years agoavformat/rpl: Check the number of streams
Michael Niedermayer [Tue, 8 Dec 2020 23:49:29 +0000 (00:49 +0100)]
avformat/rpl: Check the number of streams

Fixes: out of memory access
Fixes: 27787/clusterfuzz-testcase-minimized-ffmpeg_dem_RPL_fuzzer-4743666463408128.fuzz
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>
3 years agoavformat/vividas: Check sample_rate
Michael Niedermayer [Tue, 10 Nov 2020 21:36:25 +0000 (22:36 +0100)]
avformat/vividas: Check sample_rate

Fixes: Assertion c > 0 failed at libavutil/mathematics.c
Fixes: 27001/clusterfuzz-testcase-minimized-ffmpeg_dem_VIVIDAS_fuzzer-5726041328582656
Fixes: 27453/clusterfuzz-testcase-minimized-ffmpeg_dem_VIVIDAS_fuzzer-5716060384526336
Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
3 years agoavformat/vividas: Make len signed
Michael Niedermayer [Sun, 22 Nov 2020 16:24:20 +0000 (17:24 +0100)]
avformat/vividas: Make len signed

Fixes: out of array access
Fixes: 27424/clusterfuzz-testcase-minimized-ffmpeg_dem_VIVIDAS_fuzzer-5682070692823040
Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
3 years agoavcodec/vaapi_av1: fill the remaining VAFilmGrainStructAV1 fields
James Almer [Mon, 30 Nov 2020 16:55:11 +0000 (13:55 -0300)]
avcodec/vaapi_av1: fill the remaining VAFilmGrainStructAV1 fields

Signed-off-by: James Almer <jamrial@gmail.com>
3 years agoavcodec/exr: preserve half-float NaN bits and add fate test
Mark Reid [Mon, 23 Nov 2020 04:32:15 +0000 (20:32 -0800)]
avcodec/exr: preserve half-float NaN bits and add fate test

Handles NaNs more like the official implementation handles them, preserving
the original bits.

3 years agoavfilter/cropdetect: add option for initial skip
Gyan Doshi [Tue, 8 Dec 2020 13:22:37 +0000 (18:52 +0530)]
avfilter/cropdetect: add option for initial skip

The cropdetect filter, at present, skips the first two frames. This
behaviour is hardcoded.

New option 'skip' allows users to change this. Convenient for when
input is a single image or a trimmed video stream.

Default is kept at 2 to preserve current behaviour.

3 years agoavcodec/mpegvideo_enc: check for SpeedHQ encoder
Gyan Doshi [Tue, 8 Dec 2020 13:32:41 +0000 (19:02 +0530)]
avcodec/mpegvideo_enc: check for SpeedHQ encoder

Avoids build failure when mpegvideo_enc is built but SpeedHQ encoder
isn't.

3 years agoavcodec/libaom: Support monochrome encoding with libaom >= 2.0.1
Philip Langdale [Tue, 8 Dec 2020 00:33:29 +0000 (16:33 -0800)]
avcodec/libaom: Support monochrome encoding with libaom >= 2.0.1

Monochrome encoding with libaom was buggy for a long time, but this was
finally sorted out in libaom 2.0.1 (2.0.0 is almost there but was still
buggy in realtime mode).

We'll keep support for libaom 1.x around until the LTS distros that
include it are EOL (which is still a long time from now).

Fixes: https://trac.ffmpeg.org/ticket/7599
3 years agoavformat/framecrcenc: Make side-data checksums endian-independent
Andreas Rheinhardt [Sun, 6 Dec 2020 02:48:22 +0000 (03:48 +0100)]
avformat/framecrcenc: Make side-data checksums endian-independent

Do this by converting big-endian side data to little endian for
checksumming.

Reviewed-by: Andriy Gelman <andriy.gelman@gmail.com>
Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavformat/framecrcenc: Don't read after the end of side-data
Andreas Rheinhardt [Sun, 6 Dec 2020 00:45:14 +0000 (01:45 +0100)]
avformat/framecrcenc: Don't read after the end of side-data

Nothing guarantees that the size of side data containing a palette
is actually divisible by four (although it should be); but for
big-endian systems, an algorithm is used that presupposed this.
So switch to an algorithm that does not overread: It processes
four bytes at a time, but only if all of them are contained in
the side data.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/wmadec: Apply VLC offset during init
Andreas Rheinhardt [Mon, 23 Nov 2020 04:12:02 +0000 (05:12 +0100)]
avcodec/wmadec: Apply VLC offset during init

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/wmadec: Reduce the size of tables used to initialize VLC
Andreas Rheinhardt [Mon, 23 Nov 2020 04:09:57 +0000 (05:09 +0100)]
avcodec/wmadec: Reduce the size of tables used to initialize VLC

By switching from ff_init_vlc_sparse() to ff_init_vlc_from_lengths() one
can replace a table of codes of type uint16_t by a table of symbols of
type uint8_t, saving space.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/ivi: Make initializing VLCs thread-safe
Andreas Rheinhardt [Mon, 23 Nov 2020 03:57:03 +0000 (04:57 +0100)]
avcodec/ivi: Make initializing VLCs thread-safe

This automatically makes indeo4/5 init-threadsafe.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/dsddec: Inline constant
Andreas Rheinhardt [Mon, 23 Nov 2020 03:33:33 +0000 (04:33 +0100)]
avcodec/dsddec: Inline constant

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/dsd: Make initializing DSD tables thread-safe
Andreas Rheinhardt [Mon, 23 Nov 2020 03:20:07 +0000 (04:20 +0100)]
avcodec/dsd: Make initializing DSD tables thread-safe

This automatically makes the DSD formats as well as DST and WavPack
init-threadsafe.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/wavpack: Fix leak on init failure
Andreas Rheinhardt [Mon, 23 Nov 2020 03:09:56 +0000 (04:09 +0100)]
avcodec/wavpack: Fix leak on init failure

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/h261enc: Remove unused function parameter
Andreas Rheinhardt [Mon, 23 Nov 2020 02:21:34 +0000 (03:21 +0100)]
avcodec/h261enc: Remove unused function parameter

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/asvdec: Reindentation
Andreas Rheinhardt [Mon, 23 Nov 2020 02:49:35 +0000 (03:49 +0100)]
avcodec/asvdec: Reindentation

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/asvdec: Make decoders init-threadsafe
Andreas Rheinhardt [Mon, 23 Nov 2020 02:49:05 +0000 (03:49 +0100)]
avcodec/asvdec: Make decoders init-threadsafe

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/sinewin: Fix wrong number of elements of array declaration
Andreas Rheinhardt [Mon, 23 Nov 2020 01:45:27 +0000 (02:45 +0100)]
avcodec/sinewin: Fix wrong number of elements of array declaration

There are actually only 14 elements in each ff_sine_windows array.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/aactab: Make AAC encoder and decoders actually init-threadsafe
Andreas Rheinhardt [Sun, 22 Nov 2020 22:42:40 +0000 (23:42 +0100)]
avcodec/aactab: Make AAC encoder and decoders actually init-threadsafe

Commit 1a29804558c13ef512d9ef73a9b0d782af4fa5f2 guarded several
initializations of static data in the AAC decoders with an AVOnce and
set the FF_CODEC_CAP_INIT_THREADSAFE flag, believing the former to be
sufficient for the latter. It wasn't, because several of these static
tables are shared with other components, so that there might be data
races if they are initialized from multiple threads. This affected
initializing the ff_sine_* tables as well as initializing the
ff_aac_pow*sf_tab tables (shared between both decoders and encoder) as
well as ff_aac_kbd_* tables (shared between encoder and floating point
decoder).

Commit 3d62e7a30fa552be52d12b31e3e0f79153aff891 set the
FF_CODEC_CAP_INIT_THREADSAFE flag for the AAC encoder. More explicitly,
this commit used the same AVOnce to guard initializing ff_aac_pow*sf_tab
in the encoder and to guard initializing the static data of each
decoder; the ensuing catastrophe was "fixed" in commit
ec0719264cb9a9d5cbaf225da48929aea24997a3 by using a single AVOnce
for each codec again. But the codec cap has not been removed and
therefore the encoder claimed to be init-threadsafe, but wasn't, because
of the same tables as above.

The ff_sine_* tables as well as ff_aac_pow*sf_tab tables have already
been fixed; this commit deals with the ff_aac_kbd_* tables, making the
encoder as well as the floating-point decoder init-threadsafe (the
fixed-point decoder is it already).

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/aac: Share common init code of float decoder and encoder
Andreas Rheinhardt [Sun, 22 Nov 2020 22:33:03 +0000 (23:33 +0100)]
avcodec/aac: Share common init code of float decoder and encoder

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/aacdec, aactab: Move kbd tables to their only user
Andreas Rheinhardt [Sun, 22 Nov 2020 19:09:02 +0000 (20:09 +0100)]
avcodec/aacdec, aactab: Move kbd tables to their only user

The floating point kbd tables for 120 and 960 samples are only used by
the floating point decoder whereas the fixed point kbd tables for 128
and 1024 samples are only used by the fixed point AAC decoder. So move
these tables to their only users. This ensures that they are not
accidentally used somewhere else without ensuring that initializing
these tables stays thread-safe (as it is now because the only place from
where they are initialized is guarded by an AVOnce).

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/aactab: Remove declaration of inexistent array
Andreas Rheinhardt [Sun, 22 Nov 2020 19:00:30 +0000 (20:00 +0100)]
avcodec/aactab: Remove declaration of inexistent array

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/nellymoserenc: Make encoder init-threadsafe
Andreas Rheinhardt [Sun, 22 Nov 2020 17:12:58 +0000 (18:12 +0100)]
avcodec/nellymoserenc: Make encoder init-threadsafe

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/nellymoserenc: Cleanup generically on init failure
Andreas Rheinhardt [Sun, 22 Nov 2020 17:04:02 +0000 (18:04 +0100)]
avcodec/nellymoserenc: Cleanup generically on init failure

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/nellymoserdec: Make decoder init-threadsafe
Andreas Rheinhardt [Sun, 22 Nov 2020 16:57:38 +0000 (17:57 +0100)]
avcodec/nellymoserdec: Make decoder init-threadsafe

Easy now that initializing the ff_sine_* tables is thread-safe.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/atrac3plus: Make decoders init-threadsafe
Andreas Rheinhardt [Sun, 22 Nov 2020 16:51:00 +0000 (17:51 +0100)]
avcodec/atrac3plus: Make decoders init-threadsafe

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/atrac1: Mark decoder as init-threadsafe
Andreas Rheinhardt [Sun, 22 Nov 2020 16:32:26 +0000 (17:32 +0100)]
avcodec/atrac1: Mark decoder as init-threadsafe

Possible because ff_init_ff_sine_windows() is now threadsafe.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/sinewin_tablegen: Make initializing ff_sine_windows thread-safe
Andreas Rheinhardt [Sun, 22 Nov 2020 16:29:21 +0000 (17:29 +0100)]
avcodec/sinewin_tablegen: Make initializing ff_sine_windows thread-safe

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/aacdec, sinewin: Move 120 and 960 point sine tables to aacdec
Andreas Rheinhardt [Sun, 22 Nov 2020 13:27:45 +0000 (14:27 +0100)]
avcodec/aacdec, sinewin: Move 120 and 960 point sine tables to aacdec

The floating point AAC decoder is the only user of these tables, so it
makes sense to move them there. Furthermore, initializing the ordinary
power-of-two sinetables is currently not thread-safe and if the 120- and
960-point sinetables were not moved, one would have to choose whether
to guard initializing these two tables with their own AVOnces or not.
Doing so would add unnecessary AVOnces as the AAC decoder already guards
initializing its static data by an AVOnce; not doing so would be fragile
if a second user of these tables were to be added.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/sinewin_tablegen: Use better check in assert
Andreas Rheinhardt [Sun, 22 Nov 2020 13:02:06 +0000 (14:02 +0100)]
avcodec/sinewin_tablegen: Use better check in assert

There are no ff_sine_windows for 2^i, 0 <= i < 5, so one should check
for the index being >= 5.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/atrac3: Make decoders init-threadsafe
Andreas Rheinhardt [Sun, 22 Nov 2020 12:38:44 +0000 (13:38 +0100)]
avcodec/atrac3: Make decoders init-threadsafe

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/atrac: Make generating tables thread-safe
Andreas Rheinhardt [Sun, 22 Nov 2020 12:30:07 +0000 (13:30 +0100)]
avcodec/atrac: Make generating tables thread-safe

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/mpegaudio_tablegen: Make exponential LUT shared
Andreas Rheinhardt [Wed, 18 Nov 2020 12:13:45 +0000 (13:13 +0100)]
avcodec/mpegaudio_tablegen: Make exponential LUT shared

Both the fixed as well as the floating point mpegaudio decoders use
LUTs of type int8_t and uint32_t with 32K entries each; these tables
are completely the same, yet they are not shared. This commit makes
them shared. When both fixed as well as floating point decoders are
enabled, this saves 160KiB from the bss segment for a normal build
(translating into 160KiB less memory usage if both a shared as well as
a floating point decoder have actually been used) and 160KiB from the
binary for a build with hardcoded tables.

It also means that the code to create said LUTs is no longer duplicated
(for a normal build).

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/mpegaudiodec: Hardcode tables to save space
Andreas Rheinhardt [Wed, 18 Nov 2020 01:19:53 +0000 (02:19 +0100)]
avcodec/mpegaudiodec: Hardcode tables to save space

The csa_tables (which always consist of 32 entries of four byte each,
but the type depends upon whether the decoder is fixed or
floating-point) are currently initialized once during decoder
initialization; yet it turns out that this is actually no benefit: The
code used to initialize these tables takes up 153 (fixed point) and 122
(floating point) bytes when compiled with GCC 9.3 with -O3 on x64, so it
is better to just hardcode these tables.

Essentially the same applies to the is_tables: They have a size of 128B
each and the code to initialize them occupies 149 (fixed point) resp.
140 (floating point) bytes. So hardcode them, too.

To make the origin of the tables clear, references to the code used to
create them have been added.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/mpegaudio_tablegen: Don't inappropriately use static array
Andreas Rheinhardt [Tue, 17 Nov 2020 22:42:58 +0000 (23:42 +0100)]
avcodec/mpegaudio_tablegen: Don't inappropriately use static array

Each invocation of this function is only entered once, so using a static
array makes no sense (and given that the whole array is reinitialized at
the beginning of this function, it wouldn't even make sense if the
function were called multiple times).

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/mpegaudio_tablegen: Avoid write-only buffers
Andreas Rheinhardt [Tue, 17 Nov 2020 22:20:03 +0000 (23:20 +0100)]
avcodec/mpegaudio_tablegen: Avoid write-only buffers

The mpegaudio_tablegen header contains code to initialize several
tables; it is included in both the fixed as well as the floating point
mpegaudio decoders and some of these tables are only used by the fixed
resp. floating point decoders; yet both types are always initialized,
leaving the compiler to figure out that one of them is unused.

GCC 9.3 fails at this (even with -O3):
$ readelf -s mpegaudiodec_fixed.o|grep _float
    28: 0000000000001660 32768 OBJECT  LOCAL  DEFAULT    4 expval_table_float
An actually unused table (expval_table_fixed/float) of size 32KiB is kept
and initialized (the reason for this is probably that this table is read
from, namely to initialize another table: exp_table_fixed/float; of course
the float resp. fixed tables are not used in the fixed resp. floating point
decoder).

Therefore #ifdef the unneeded tables away.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/mpegaudiodec: Share fixed and floating point data and init code
Andreas Rheinhardt [Tue, 17 Nov 2020 21:25:35 +0000 (22:25 +0100)]
avcodec/mpegaudiodec: Share fixed and floating point data and init code

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/mpegaudiodec_template: Apply shift during init
Andreas Rheinhardt [Tue, 17 Nov 2020 20:37:21 +0000 (21:37 +0100)]
avcodec/mpegaudiodec_template: Apply shift during init

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/mpegaudiodec: Make decoders init-threadsafe
Andreas Rheinhardt [Tue, 17 Nov 2020 17:44:18 +0000 (18:44 +0100)]
avcodec/mpegaudiodec: Make decoders init-threadsafe

Simple now that ff_mpadsp_init() and ff_mpa_synth_init_* are thread-safe.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/mpegaudiodec: Combine tables used to initialize VLCs
Andreas Rheinhardt [Tue, 17 Nov 2020 16:34:04 +0000 (17:34 +0100)]
avcodec/mpegaudiodec: Combine tables used to initialize VLCs

Up until now, there were several indiviual tables which were accessed
via pointers to them; by combining the tables, one can avoid said
pointers, saving space.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/mpegaudiodec: Reduce the size of tables used to initialize VLCs
Andreas Rheinhardt [Tue, 17 Nov 2020 14:53:43 +0000 (15:53 +0100)]
avcodec/mpegaudiodec: Reduce the size of tables used to initialize VLCs

By switching from ff_init_vlc_sparse() to ff_init_vlc_from_lengths() one
can replace tables of codes of type uint16_t by tables of symbols of
type uint8_t; this saves about 1.3KB for both the fixed and floating
point decoders (if enabled).

Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/mpegaudiotab: Avoid unused entry in table
Andreas Rheinhardt [Tue, 17 Nov 2020 14:16:01 +0000 (15:16 +0100)]
avcodec/mpegaudiotab: Avoid unused entry in table

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/mpegaudiodec_template: Avoid VLC size tables
Andreas Rheinhardt [Tue, 17 Nov 2020 14:03:02 +0000 (15:03 +0100)]
avcodec/mpegaudiodec_template: Avoid VLC size tables

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/mv30: Inline constants
Andreas Rheinhardt [Mon, 16 Nov 2020 13:58:06 +0000 (14:58 +0100)]
avcodec/mv30: Inline constants

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/mv30: Reduce the size of tables used to initialize VLCs
Andreas Rheinhardt [Mon, 16 Nov 2020 13:56:13 +0000 (14:56 +0100)]
avcodec/mv30: Reduce the size of tables used to initialize VLCs

By switching from ff_init_vlc_sparse() to ff_init_vlc_from_lengths() one
can remove the array of codes of type uint16_t here; given that the
symbols are the default ones (0,1,2,...), no explicit symbols table
needs to be added.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/imm4: Inline constants
Andreas Rheinhardt [Mon, 16 Nov 2020 13:46:18 +0000 (14:46 +0100)]
avcodec/imm4: Inline constants

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/imm4: Reduce the size of tables used to initialize VLCs
Andreas Rheinhardt [Mon, 16 Nov 2020 13:43:01 +0000 (14:43 +0100)]
avcodec/imm4: Reduce the size of tables used to initialize VLCs

By switching from ff_init_vlc_sparse() to ff_init_vlc_from_lengths() one
can remove arrays of codes in cases where there were already symbols
tables.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/imm4: Make better use of symbols table
Andreas Rheinhardt [Mon, 16 Nov 2020 12:40:08 +0000 (13:40 +0100)]
avcodec/imm4: Make better use of symbols table

Also inline the VLC's number of bits while at it.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/aacdec_template: Use VLC symbols table
Andreas Rheinhardt [Thu, 19 Nov 2020 14:57:23 +0000 (15:57 +0100)]
avcodec/aacdec_template: Use VLC symbols table

Expressions like array[get_vlc2()] can be optimized by using a symbols
table if the array is always the same for a given VLC. This requirement
is fulfilled for several VLCs used by the AAC decoders.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/aacdec_template: Avoid code duplication when initializing VLCs
Andreas Rheinhardt [Thu, 19 Nov 2020 14:11:07 +0000 (15:11 +0100)]
avcodec/aacdec_template: Avoid code duplication when initializing VLCs

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/qdmc: Avoid code duplication when initializing VLC
Andreas Rheinhardt [Sun, 8 Nov 2020 10:56:23 +0000 (11:56 +0100)]
avcodec/qdmc: Avoid code duplication when initializing VLC

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/qdmc: Apply offset when creating VLC
Andreas Rheinhardt [Sun, 8 Nov 2020 10:05:15 +0000 (11:05 +0100)]
avcodec/qdmc: Apply offset when creating VLC

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/qdmc: Make tables used to initialize VLCs smaller
Andreas Rheinhardt [Sun, 8 Nov 2020 09:48:24 +0000 (10:48 +0100)]
avcodec/qdmc: Make tables used to initialize VLCs smaller

This is possible by switching to ff_init_vlc_from_lengths() which allows
to replace tables of codes of size uint16_t or uint32_t by tables of
symbols of size uint8_t; in case there already were symbols tables the
savings are even bigger.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/magicyuv: Optimize creating Huffman tables
Andreas Rheinhardt [Mon, 9 Nov 2020 04:11:31 +0000 (05:11 +0100)]
avcodec/magicyuv: Optimize creating Huffman tables

MagicYUV transmits its Huffman trees by providing the length of the code
corresponding to each symbol; then the decoder has to assemble the table
in such a way that (i) longer codes are to the left of the tree and (ii)
for codes of the same length the symbols are ascending from left to right.

Up until now the decoder did this as follows: It counted the number of
codes of each length and derived the first code of a given length via
(ii). Then the array of lengths is traversed a second time to create
the codes; there is one running counter for each length to do so. This
process creates a default symbol table (that is omitted).

This commit changes this as follows: Everything is indexed by the
position in the tree (with codes to the left first); given (i), we can
calculate the ranges occupied by the codes of each length; and with (ii)
we can derive the actual symbols of each code; the running counters for
each length are now used for the symbols and not for the codes.

Doing so allows us to switch to ff_init_vlc_from_lengths(); this has the
advantage that the codes table needs only be traversed once and that the
codes need not be sorted any more (right now, the codes that are so long
that they will be put into subtables need to be sorted so that codes
that end up in the same subtable are contiguous).

For a sample produced by our encoder (natural content, 4000 frames,
YUV420p, ten iterations, GCC 9.3) this decreased the amount of
decicycles for each call to build_huffman() from 1336049 to 1309401.
Notice that our encoder restricts the code lengths to 12 and our decoder
only uses subtables when the code is longer than 12 bits, so the sorting
that can be avoided does not happen at the moment. If one reduces the
decoder's tables to nine bits, the performance improvement becomes more
apparent: The amount of decicycles for build_huffman() decreased from
1165210 to 654055.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/utvideodec: Avoid implicit qsort when creating Huffman tables
Andreas Rheinhardt [Sun, 8 Nov 2020 04:15:56 +0000 (05:15 +0100)]
avcodec/utvideodec: Avoid implicit qsort when creating Huffman tables

The Huffman trees used by Ut Video have two important characteristics:
(i) Longer codes are on the left of the tree and (ii) for codes of the
same length, the symbol is descending from left to right in the tree.
Therefore all the information that needs to be transmitted is how long
the code corresponding to a given symbol is; and this is also all that
is transmitted.

Before 341914495e5c2f60bc920b0c6f660e5948a47f5a, the decoder used qsort
to sort the (length, symbol) pairs by ascending length and for equal
lengths by ascending symbol. Since said commit, the decoder uses
a first pass over the lengths table to count how many symbols of each
length there are; with (i) one can then easily calculate the code of
the left-most code with a given length in the tree and from there one
can calculate the codes for all entries, using one running counter for
each possible length. This eliminated the explicit qsort in
build_huff().

Yet ff_init_vlc_sparse() sorts the table itself as it has to ensure that
all the entries that will be placed in the same subtable are contiguous.
The tables created now are non-contiguous (they are ordered by symbol
and codes of different length aren't ordered at all; only codes of the
same length are ordered according to (ii)).

This commit therefore modifies the algorithm used to automatically create
tables whose codes are sorted from left to right in the tree. The key to
do so is the observation that the counts obtained in the first pass can
be used to contain the range of the codes of each length in the second
pass: If counts[i] is the count of codes with length i, then the first
counts[32] codes are of length 32, the next counts[31] codes are of
length 31 etc. So one knows the index of the lowest symbol whose code
has length 32 (if any): It is counts[32] - 1 due to (ii), whereas the
index of the lowest symbol whose code has length 31 (if any) is
counts[32] + counts[31] - 1; the index of the second-to-lowest symbol of
length 32 (if existing) is counts[32] - 2 etc.

If one follows the algorithm outlined above, one can switch to
ff_init_vlc_from_lengths() which has no implicit qsort; it also means
that one can offload the computation of the codes.

This turned out to be beneficial for performance: For the sample from
ticket #4044 it decreased the decicycles spent on one call to
build_huff() from 508480 to 340688 (GCC 9.3, looping 10 times over the
file to get enough runs and then repeating this ten times); for another
sample (YUV420p, natural content, 5500 frames, also ten iterations)
the time went down from 382346 to 275533 decicycles.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/atrac3: Use symbols table
Andreas Rheinhardt [Sat, 7 Nov 2020 08:46:17 +0000 (09:46 +0100)]
avcodec/atrac3: Use symbols table

Expressions like array[get_vlc2()] can be optimized by using a symbols
table if the array is always the same for a given VLC. This requirement
is fulfilled for several VLCs used by ATRAC3, therefore this commit
implements this. This comes without any additional costs when using
ff_init_vlc_from_lengths() as one can then remove the codes tables.

While at it, remove the arrays of pointers to the individual arrays and
put all lengths+symbol pairs in one big array.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/intrax8: Reduce the size of tables used to initialize VLCs
Andreas Rheinhardt [Fri, 6 Nov 2020 12:50:56 +0000 (13:50 +0100)]
avcodec/intrax8: Reduce the size of tables used to initialize VLCs

By switching from ff_init_vlc_sparse() to ff_init_vlc_from_lengths() one
can replace an array of codes of type uint16_t with an array of symbols
of type uint8_t, saving space.

Also remove some more code duplication while at it.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/intrax8: Avoid code duplication when initializing VLCs
Andreas Rheinhardt [Fri, 6 Nov 2020 12:43:03 +0000 (13:43 +0100)]
avcodec/intrax8: Avoid code duplication when initializing VLCs

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/intrax8: Remove VLC offsets table
Andreas Rheinhardt [Fri, 6 Nov 2020 12:30:20 +0000 (13:30 +0100)]
avcodec/intrax8: Remove VLC offsets table

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/vp3: Remove code duplication when initializing Theora VLCs
Andreas Rheinhardt [Fri, 6 Nov 2020 10:03:34 +0000 (11:03 +0100)]
avcodec/vp3: Remove code duplication when initializing Theora VLCs

theora_init_huffman_tables() does essentially the same as
ff_init_vlcs_from_lengths().

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/vp3: Use symbols table for VP3 motion vectors
Andreas Rheinhardt [Fri, 6 Nov 2020 09:48:55 +0000 (10:48 +0100)]
avcodec/vp3: Use symbols table for VP3 motion vectors

Expressions like array[get_vlc2()] can be optimized by using a symbols
table if the array is always the same for a given VLC. This requirement
is fulfilled for the VLC used for VP3 motion vectors. The reason it
hasn't been done before is probably that the array in this case
contained entries in the range -31..31; but this is no problem with
ff_init_vlc_from_lengths(): Just apply an offset of 31 to the symbols
before storing them in the table used to initialize VP3 motion vectors
and apply an offset of -31 when initializing the actual VLC.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/vp3: Make tables used to initialize VLCs smaller
Andreas Rheinhardt [Fri, 6 Nov 2020 09:35:12 +0000 (10:35 +0100)]
avcodec/vp3: Make tables used to initialize VLCs smaller

This is possible by switching to ff_init_vlc_from_lengths() because it
allows to replace codes of type uint16_t by symbols of type uint8_t; in
some cases (like here) it also allows to replace explicitly coded
codes by implicitly coded symbols.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/vp3: Apply VLC offset during init
Andreas Rheinhardt [Fri, 6 Nov 2020 09:14:22 +0000 (10:14 +0100)]
avcodec/vp3: Apply VLC offset during init

By switching to ff_init_vlc_from_lengths() one can apply both positive
as well as negative offsets for free; in this case it even saves space
because one replaces codes tables that don't fit into an uint8_t by
symbols tables that fit into an uint8_t or can even be completely
avoided as they are trivial.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/atrac9dec: Make VLCs static
Andreas Rheinhardt [Thu, 5 Nov 2020 02:25:47 +0000 (03:25 +0100)]
avcodec/atrac9dec: Make VLCs static

Also remove code duplication and use a named constant for the number of
VLC bits while just at it.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/atrac9dec: Don't create VLCs that are never used
Andreas Rheinhardt [Thu, 5 Nov 2020 01:29:26 +0000 (02:29 +0100)]
avcodec/atrac9dec: Don't create VLCs that are never used

The ATRAC9 decoder creates VLCs with parameters contained in
HuffmanCodebooks; some of these HuffmanCodebooks are empty and yet
VLCs (that were completely unused*) were created from them. Said VLC
contained a single table with 512 VLC_TYPE[2] entries, each of which
indicated that this is an invalid code. This commit stops creating said
VLCs.

*: read_coeffs_coarse() uses the HuffmanCodebook
at9_huffman_coeffs[cb][prec][cbi]. prec is c->precision_coarse[i] + 1
and every precision_coarse entry is in the 1..15 range after
calc_precision(), so prec is >= 2 (all codebooks with prec < 2 are
empty). The remaining empty codebooks are those with cb == 1 and cbi ==
0, yet this is impossible, too: cb is given by c->codebookset[i] and
this is always 0 if i < 8 (because those are never set to anything else
in calc_codebook_idx()) and cbi is given by at9_q_unit_to_codebookidx[i]
which is never zero if i >= 8.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/atrac9tab: Unify tables used to initialize VLCs
Andreas Rheinhardt [Wed, 4 Nov 2020 19:41:35 +0000 (20:41 +0100)]
avcodec/atrac9tab: Unify tables used to initialize VLCs

Using separate tables has the downside that one needs a big number of
pointers to the separate tables (currently 77); unifying them avoids
this.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/atrac9dec: Make tables used to initialize VLCs smaller
Andreas Rheinhardt [Wed, 4 Nov 2020 07:25:47 +0000 (08:25 +0100)]
avcodec/atrac9dec: Make tables used to initialize VLCs smaller

The ATRAC9 decoder uses VLCs which are currently initialized with
static length tables of type uint8_t and code tables of type uint16_t.
Furthermore, in one case the actually desired symbols are in the range
-16..15 and in order to achieve this an ad-hoc symbols table of type
int16_t is calculated.

This commit modifies this process by replacing the codes tables by
symbols tables and switching to ff_init_vlc_from_lengths(); the signed
symbols are stored in the table after having been shifted by 16 to fit
into an uint8_t and are shifted back when the VLC is created. This makes
all symbols fit into an uint8_t, saving space. Furthermore, the earlier
tables had holes in them (entries with length zero that were inserted
because the actually used symbols were not contiguous); these holes are
unnecessary in the new approach, leading to further saving.

Finally, given that now both lengths as well as symbols are of the same
type, they can be combined; this saves a pointer for each VLC.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/rv34: Make initializing static VLC tables thread-safe
Andreas Rheinhardt [Tue, 17 Nov 2020 10:13:56 +0000 (11:13 +0100)]
avcodec/rv34: Make initializing static VLC tables thread-safe

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/rv34: Avoid offsets table for initialization of static VLCs
Andreas Rheinhardt [Wed, 4 Nov 2020 02:27:18 +0000 (03:27 +0100)]
avcodec/rv34: Avoid offsets table for initialization of static VLCs

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/vc1: Make ff_vc1_init_common() thread-safe
Andreas Rheinhardt [Mon, 16 Nov 2020 14:09:01 +0000 (15:09 +0100)]
avcodec/vc1: Make ff_vc1_init_common() thread-safe

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/atrac3plus: Run-length encode length tables to make them smaller
Andreas Rheinhardt [Sun, 1 Nov 2020 22:19:18 +0000 (23:19 +0100)]
avcodec/atrac3plus: Run-length encode length tables to make them smaller

This is very beneficial for the scale factor tables where 4*64+4*15
bytes of length information can be replaced by eight codebooks of 12
bytes each; furthermore the number of codes as well as the maximum
length of a code can be easily derived from said codebooks, making
tables containing said information superfluous. This and combining the
symbols into one big array also made an array of pointers to the tables
redundant.

For the wordlen and code table tables the benefits are not that big
(given these tables don't contain that many elements), but all in all
using codebooks is also advantageouos for them. Therefore it has been
done.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/atrac3plus: Combine codebooks into one array
Andreas Rheinhardt [Sun, 1 Nov 2020 19:44:12 +0000 (20:44 +0100)]
avcodec/atrac3plus: Combine codebooks into one array

ATRAC3+ uses VLCs whose code lengths are ascending from left to right in
the tree; ergo it is possible (and done) to run-length encode the
lengths into so-called codebooks. These codebooks were variable-sized:
The first byte contained the minimum length of a code, the second the
maximum length; this was followed by max - min + 1 bytes containing the
actual numbers. The minimal min was 1, the maximal max 12.

While one saves a few bytes by only containing the range that is
actually used, this is more than offset by the fact that there needs
to be a pointer to each of these codebooks.

Furthermore, since 5f8de7b74147e2a347481d7bc900ebecba6f340f the content
of the Atrac3pSpecCodeTab structure (containing data for spectrum
decoding) can be cleanly separated into fields that are only used during
initialization and fields used during actual decoding: The pointers to
the codebooks and the field indicating whether an earlier codebook should
be reused constitute the former category. Therefore the new codebooks are
not placed into the Atrac3pSpecCodeTab (which is now unused during
init), but in an array of its own. The information whether an earlier
codebook should be reused is encoded in the first number of each
spectrum codebook: If it is negative, an earlier codebook (given by the
number) should be reused.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/atrac3plus: Combine symbols tables
Andreas Rheinhardt [Sun, 1 Nov 2020 17:52:17 +0000 (18:52 +0100)]
avcodec/atrac3plus: Combine symbols tables

This allows to remove lots of pointers (130) to small symbol tables;
it has the downside that some of the default tables must now be coded
explicitly, but this costs only 6 + 4 + 8 + 16 + 8 bytes and is therefore
dwarfed by the gains.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/atrac3plus: Simplify getting offset of VLC in VLC_TYPE buf
Andreas Rheinhardt [Sun, 1 Nov 2020 16:59:12 +0000 (17:59 +0100)]
avcodec/atrac3plus: Simplify getting offset of VLC in VLC_TYPE buf

The earlier code used several different offset parameters that were
initialized to magic values. This is unnecessary.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/atrac3plus: Make tables used to initialize VLCs smaller
Andreas Rheinhardt [Sun, 1 Nov 2020 16:01:53 +0000 (17:01 +0100)]
avcodec/atrac3plus: Make tables used to initialize VLCs smaller

The ATRAC3+ decoder currently uses ff_init_vlc_sparse() to initialize
several VLCs; sometimes a symbols table is used, sometimes not; some of
the codes tables are uint16_t, some are uint8_t. Because of these two
latter facts it makes sense to switch to ff_init_vlc_from_lengths()
because it allows to remove the codes at the cost of adding symbols
tables of type uint8_t in the cases where there were none before.

Notice that sometimes the same codes and lengths tables were reused with
two different symbols tables; this could have been preserved (meaning
one could use a lengths table twice), but hasn't, because this allows
to use only one pointer to both the symbols and lengths instead of two
pointers.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/atrac3plus: Simplify creating VLCs
Andreas Rheinhardt [Sun, 1 Nov 2020 15:21:32 +0000 (16:21 +0100)]
avcodec/atrac3plus: Simplify creating VLCs

Use ff_init_vlc_from_lengths() to offload the computation of the codes.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/truemotion2: Simplify creating VLC table
Andreas Rheinhardt [Sun, 1 Nov 2020 13:23:33 +0000 (14:23 +0100)]
avcodec/truemotion2: Simplify creating VLC table

ff_init_vlc_from_lengths() can be used to offload the computation
of the codes; it also allows to omit the check whether the codes
are already properly ordered (they are). In this case, this also allows
to avoid the allocation of the buffer for the codes.

This improves performance: The amount of decicycles for one call to
tm2_build_huff_tables() when decoding tm20.avi from the FATE-suite
decreased from 46239 to 40035. This test consisted of looping 50 times
over the file and iterating the test ten times.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/mpeg4videodec: Make studio VLCs static
Andreas Rheinhardt [Wed, 4 Nov 2020 00:37:39 +0000 (01:37 +0100)]
avcodec/mpeg4videodec: Make studio VLCs static

Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/mpeg4video: Make tables used to initialize VLCs smaller
Andreas Rheinhardt [Sun, 1 Nov 2020 04:36:35 +0000 (05:36 +0100)]
avcodec/mpeg4video: Make tables used to initialize VLCs smaller

Switching from ff_init_vlc_sparse() to ff_init_vlc_from_lengths()
allows to replace codes which are so long that they need to be stored
in an uint16_t by symbols which fit into an uint8_t; and even these can
be avoided in case of the sprite trajectory VLC.

Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/indeo2: Make decoder init-threadsafe
Andreas Rheinhardt [Sun, 15 Nov 2020 21:48:35 +0000 (22:48 +0100)]
avcodec/indeo2: Make decoder init-threadsafe

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/indeo2: Make tables used to initialize VLCs smaller
Andreas Rheinhardt [Sun, 1 Nov 2020 03:16:25 +0000 (04:16 +0100)]
avcodec/indeo2: Make tables used to initialize VLCs smaller

Switching from ff_init_vlc_sparse() to ff_init_vlc_from_lengths()
allows to replace codes which are so long that they need to be stored
in an uint16_t by symbols which fit into an uint8_t; furthermore, it is
also easily possible to already incorporate the offset (the real range
of Indeo 2 symbols starts at one, not zero) into the symbols.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/mjpegdec: Simplify creating VLC table
Andreas Rheinhardt [Sun, 1 Nov 2020 02:01:05 +0000 (03:01 +0100)]
avcodec/mjpegdec: Simplify creating VLC table

ff_init_vlc_from_lengths() can be used to offload the computation
of the codes; it also allows to omit the check whether the codes
are already properly ordered (they are).

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/sheervideo: Simplify creating VLC table
Andreas Rheinhardt [Sun, 1 Nov 2020 00:21:06 +0000 (01:21 +0100)]
avcodec/sheervideo: Simplify creating VLC table

ff_init_vlc_from_lengths() can be used to offload the computation
of the codes; it also needn't check whether the codes are already
properly ordered (they are).

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/mss4: Make VLCs static
Andreas Rheinhardt [Tue, 3 Nov 2020 23:04:08 +0000 (00:04 +0100)]
avcodec/mss4: Make VLCs static

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/mss4: Don't duplicate standard JPEG tables
Andreas Rheinhardt [Sun, 1 Nov 2020 00:08:15 +0000 (01:08 +0100)]
avcodec/mss4: Don't duplicate standard JPEG tables

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/mss4: Simplify creating VLC tables
Andreas Rheinhardt [Sat, 31 Oct 2020 23:26:32 +0000 (00:26 +0100)]
avcodec/mss4: Simplify creating VLC tables

The lengths of the codes used by the mss4 decoder are ascending from
left to right and therefore the lengths can be run-length encoded and
the codes can be easily derived from them. And this is how it is indeed
done. Yet some things can nevertheless be improved:

a) The number of entries of the current VLC is implicitly contained in
the run-length table and needn't be externally prescribed.
b) The maximum length of a code is just the length of the last code
(given that the lengths are ascending), so there is no point in setting
max_bits in the loop itself.
c) One can offload the actual calculation of the codes to
ff_init_vlc_from_lengths().

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/rv40: Avoid code duplication when initializing VLCs
Andreas Rheinhardt [Thu, 5 Nov 2020 00:59:08 +0000 (01:59 +0100)]
avcodec/rv40: Avoid code duplication when initializing VLCs

Besides removing code duplication the method for determining the offset
of each VLC table in the VLC_TYPE buffer also has the advantage of not
wasting space for skipped AIC mode 1 VLCs.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/rv40: Avoid offset table when initializing static VLCs
Andreas Rheinhardt [Wed, 4 Nov 2020 23:42:56 +0000 (00:42 +0100)]
avcodec/rv40: Avoid offset table when initializing static VLCs

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/rv40: Make better use of VLC symbols table
Andreas Rheinhardt [Sat, 31 Oct 2020 21:44:12 +0000 (22:44 +0100)]
avcodec/rv40: Make better use of VLC symbols table

RealVideo 4.0 has a VLC that encodes two intra types per code; each
intra type is in the range 0..8 (inclusive) and up until now the VLC
used symbols in the range 0..80; one type was encoded as the remainder
when dividing the symbol by 9 whereas the other type was encoded as
symbol / 9. This is suboptimal; a better way would be to use the high
and low nibble to encode each symbol. But an even better way is to use
16bit symbols so that the two intra types can be directly written as
a 16bit value.

This commit implements this; in order to avoid huge tables the symbols
are stored as uint8_t with high and low nibbles encoding one type each;
they are only unpacked to uint16_t during initialization.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>