]> git.sesse.net Git - ffmpeg/log
ffmpeg
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>
3 years agoavcodec/rv40: Make the tables used to initialize VLCs smaller
Andreas Rheinhardt [Sat, 31 Oct 2020 20:35:13 +0000 (21:35 +0100)]
avcodec/rv40: Make the tables used to initialize VLCs smaller

After permuting the codes, symbols and lengths tables used to initialize
the VLC so that the codes are ordered from left to right in the Huffman
tree, the codes become redundant as they can be easily computed from the
lengths at runtime; in this case one has to use explicit symbol tables,
but all the symbols used here fit into an uint8_t, whereas some codes
needed uint16_t. This saves about 1.6KB.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/qdm2: Make decoder init-threadsafe
Andreas Rheinhardt [Sun, 15 Nov 2020 21:09:31 +0000 (22:09 +0100)]
avcodec/qdm2: Make decoder init-threadsafe

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/qdm2: Avoid offsets table when initializing VLCs
Andreas Rheinhardt [Tue, 3 Nov 2020 22:16:47 +0000 (23:16 +0100)]
avcodec/qdm2: Avoid offsets table when initializing VLCs

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/qdm2: Initialize array of VLCs in a loop
Andreas Rheinhardt [Sat, 31 Oct 2020 18:26:39 +0000 (19:26 +0100)]
avcodec/qdm2: Initialize array of VLCs in a loop

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/qdm2: Apply offsets when initializing VLCs
Andreas Rheinhardt [Sat, 31 Oct 2020 17:23:47 +0000 (18:23 +0100)]
avcodec/qdm2: Apply offsets when initializing VLCs

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/qdm2: Make tables used to initialize VLCs smaller
Andreas Rheinhardt [Sat, 31 Oct 2020 16:33:28 +0000 (17:33 +0100)]
avcodec/qdm2: Make tables used to initialize VLCs smaller

After permuting the codes, symbols and lengths tables used to initialize
the VLCs so that the codes are ordered from left to right in the Huffman
tree, the codes become redundant as they can be easily computed from the
lengths at runtime (or at compile time with --enable-hardcoded-tables);
in this case one has to use explicit symbol tables, but all the symbols
used here fit into an uint8_t, whereas some codes needed uint16_t.
Furthermore, the codes had holes because the range of the symbols was not
contiguous; these have also been removed.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/mobiclip: Reindentation
Andreas Rheinhardt [Sat, 31 Oct 2020 11:37:01 +0000 (12:37 +0100)]
avcodec/mobiclip: Reindentation

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/mobiclip: Make decoder init-threadsafe
Andreas Rheinhardt [Sun, 15 Nov 2020 20:39:19 +0000 (21:39 +0100)]
avcodec/mobiclip: Make decoder init-threadsafe

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/mobiclip: Avoid code duplication when initializing VLCs
Andreas Rheinhardt [Sat, 31 Oct 2020 11:34:13 +0000 (12:34 +0100)]
avcodec/mobiclip: Avoid code duplication when initializing VLCs

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/mobiclip: Avoid redundant codes table to initialize VLCs
Andreas Rheinhardt [Sat, 31 Oct 2020 00:23:34 +0000 (01:23 +0100)]
avcodec/mobiclip: Avoid redundant codes table to initialize VLCs

If both codes, lengths and symbols tables are ordered so that the codes
are sorted from left to right in the tree, the codes can be easily
derived from the lengths and therefore become redundant. This is
exploited in this commit to remove the codes tables for the mobiclip
decoder; notice that tables for the run-length VLC were already ordered
correctly.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/mpc8: Make decoder init-threadsafe
Andreas Rheinhardt [Sun, 15 Nov 2020 20:31:31 +0000 (21:31 +0100)]
avcodec/mpc8: Make decoder init-threadsafe

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/mpc7: Make decoder init-threadsafe
Andreas Rheinhardt [Sun, 15 Nov 2020 20:21:48 +0000 (21:21 +0100)]
avcodec/mpc7: Make decoder init-threadsafe

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/imc: Make imc/iac decoders init-threadsafe
Andreas Rheinhardt [Sun, 15 Nov 2020 10:42:24 +0000 (11:42 +0100)]
avcodec/imc: Make imc/iac decoders init-threadsafe

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/mpc8: Avoid code duplication when initializing VLCs
Andreas Rheinhardt [Fri, 30 Oct 2020 10:43:06 +0000 (11:43 +0100)]
avcodec/mpc8: Avoid code duplication when initializing VLCs

Up until now, VLCs that were part of an array of VLCs were often not
initialized in a loop, but separately. The probable reason for this
was that these VLCs differed slightly in the parameters to be used for
them (i.e. the number of codes or the number of bits to be used
differs), so that one would have to provide these parameters e.g. via
arrays.

Yet these problems have actually largely been solved by now: The length
information is contained in a run-length encoded form that is the same
for all VLCs and both the number of codes as well as the number of bits
to use for each VLC can be easily derived from them.

There is just one problem to be solved: When the underlying tables have
a different number of elements, putting them into an array of arrays
would be wasteful; using an array of pointers to the arrays would
also be wasteful. Therefore this commit combines the tables into bigger
tables. (Given that all the length tables have the same layout this
applies only to the symbols tables.)

Finally, the array containing the offset of the VLC's buffer in the big
buffer has also been removed.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/mpc8: Reduce the size of some VLCs
Andreas Rheinhardt [Fri, 30 Oct 2020 01:27:15 +0000 (02:27 +0100)]
avcodec/mpc8: Reduce the size of some VLCs

Several of the quantisation VLCs come in pairs and up until now the
number of bits used for each VLC was set to the same value for both VLCs
in such a pair even when one of the two required only a lower number.
This is a waste given that the get_vlc2() call is compatible with these
two VLCs using a different number of bits (it uses vlc->bits).

Given that the code lengths are descending it is easily possible to know
the length of the longest code for a given VLC: It is the length of the
first one. With this information one can easily use the least amount of
bits.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/mpc8: Reduce the size of the length tables to initialize VLCs
Andreas Rheinhardt [Fri, 30 Oct 2020 01:10:36 +0000 (02:10 +0100)]
avcodec/mpc8: Reduce the size of the length tables to initialize VLCs

After permuting both length, code as well as symbol tables so that
the codes are ordered from left to right in the tree, it became apparent
that the length of the codes decreases from left to right. Therefore one
can run-length encode the lengths to save space. This commit implements
this.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/mpc8: Apply offsets when initializing VLCs
Andreas Rheinhardt [Thu, 29 Oct 2020 22:54:07 +0000 (23:54 +0100)]
avcodec/mpc8: Apply offsets when initializing VLCs

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/mpc8: Reduce size of tables used to initialize VLCs
Andreas Rheinhardt [Thu, 29 Oct 2020 22:34:18 +0000 (23:34 +0100)]
avcodec/mpc8: Reduce size of tables used to initialize VLCs

By switching to ff_init_vlc_from_lengths() one can make a table of
codes of type uint8_t superfluous, saving space.

Other VLCs (those without dedicated symbols table and with codes of
type uint8_t) have been made to use ff_init_vlc_from_lengths(), too,
because it reduces codesize (ff_init_vlc_from_lengths() has two
parameters less than ff_init_vlc_sparse()) and because it allows to
use the offset parameter in future commits.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/mpc7: Avoid offsets table when creating VLCs
Andreas Rheinhardt [Tue, 3 Nov 2020 21:41:51 +0000 (22:41 +0100)]
avcodec/mpc7: Avoid offsets table when creating VLCs

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/mpc7: Apply offsets when creating VLCs
Andreas Rheinhardt [Thu, 29 Oct 2020 19:21:59 +0000 (20:21 +0100)]
avcodec/mpc7: Apply offsets when creating VLCs

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/mpc7: Reduce size of tables used to initialize VLCs
Andreas Rheinhardt [Thu, 29 Oct 2020 19:13:56 +0000 (20:13 +0100)]
avcodec/mpc7: Reduce size of tables used to initialize VLCs

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

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/motionpixels: Simplify creating VLC tables
Andreas Rheinhardt [Thu, 29 Oct 2020 10:12:32 +0000 (11:12 +0100)]
avcodec/motionpixels: Simplify creating VLC tables

By using ff_init_vlc_from_lengths(), we do not have to keep track of the
codes themselves, but can offload this to ff_init_vlc_from_lengths().

Furthermore, the old code presumed sizeof(int) == 4; this is no longer
so.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/mimic: Make VLC static
Andreas Rheinhardt [Wed, 28 Oct 2020 13:35:19 +0000 (14:35 +0100)]
avcodec/mimic: Make VLC static

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/mimic: Reduce size of tables used to initialize VLCs
Andreas Rheinhardt [Wed, 28 Oct 2020 13:17:40 +0000 (14:17 +0100)]
avcodec/mimic: Reduce size of tables used to initialize VLCs

By switching to ff_init_vlc_from_lengths() one can replace a table of
codes of type uint32_t with a table of symbols of type uint8_t saving
space. The old tables also had holes in it (because of the symbols) which
are now superfluous, saving ever more space.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/rv10: Simplify handling of skip VLC entries
Andreas Rheinhardt [Wed, 28 Oct 2020 12:15:15 +0000 (13:15 +0100)]
avcodec/rv10: Simplify handling of skip VLC entries

The VLC tables to be used for parsing RealVideo 1.0 DC coefficients are
weird: The luma table contains a block of 2^11 codes beginning with the
same prefix and length that all have the same symbol (i.e. value only
depends upon the prefix); the same goes for the chroma block (except
it's only 2^9 codes). Up until now, these entries (which generally could
be parsed like ordinary entries with subtables) have been treated
specially: They have been treated like open ends of the tree, so that
get_vlc2() returned a value < 0 upon encountering them; afterwards it
was checked whether the right prefix was used and if so, the appropriate
number of bytes was skipped.

But there is actually an easy albeit slightly hacky way to support them
directly without pointless subtables: Just modify the VLC table so that
all the entries sharing the right prefix have a length that equals the
length of the whole entry.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
3 years agoavcodec/rv10: Make VLC tables smaller
Andreas Rheinhardt [Wed, 28 Oct 2020 09:48:09 +0000 (10:48 +0100)]
avcodec/rv10: Make VLC tables smaller

These tables were huge (14 bits) because one needed 14 bits in order to
find out whether a code is valid and in the VLC table or a valid code that
required hacky workarounds due to RealVideo 1.0 using multiple codes
for the same symbol and the code predating the introduction of symbols
tables for VLCs.

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