]> git.sesse.net Git - ffmpeg/commit
avcodec/rv10: Reduce number of exceptions when reading VLC value
authorAndreas Rheinhardt <andreas.rheinhardt@gmail.com>
Tue, 27 Oct 2020 22:26:17 +0000 (23:26 +0100)
committerAndreas Rheinhardt <andreas.rheinhardt@gmail.com>
Tue, 8 Dec 2020 16:51:45 +0000 (17:51 +0100)
commitdf3269f5f74ff8ab976d00927a55a2940cc2255f
tree16c93922bf62d9950898085628640b6679f0cf0f
parente730b1558367614ef396df596425a462a56739df
avcodec/rv10: Reduce number of exceptions when reading VLC value

RealVideo 1.0 uses an insane way to encode DC coefficients: There are
several symbols that (for no good reason whatsoever) have multiple
encodings, leading to longer codes than necessary.

More specifically, the tree for the 256 luma symbols contains 255 codes
belonging to 255 different symbols on the left; going further right,
the tree consists of two blocks of 128 codes each of length 14 encoding
consecutive numbers (including two encodings for the symbol missing among
the 255 codes on the left); this is followed by two blocks of codes of
length 16 each containing 256 elements with consecutive symbols (i.e.
each of the blocks allows to encode all symbols). The rest of the tree
consists of 2^11 codes that all encode the same symbol.

The tree for the 256 chroma symbols is similar, but is missing the
blocks of length 256 and there are only 2^9 consecutive codes that
encode the same symbol; furthermore, the chroma tree is incomplete:
The right-most node has no right child.

All of this caused problems when parsing these codes; the reason is that
the code for this predates commit b613bacca9c256f1483c46847f713e47a0e9a5f6
which added support for explicit symbol tables and thereby removed the
requirement that different codes have different symbols. In order to
address this, the trees used for parsing were incomplete: They contained
the 255 codes on the left and one code for the remaining symbol. Whenever
a code not in these trees was encountered, it was dealt with in
special cases (one for each of the blocks mentioned above).

This commit reduces the number of special cases: Using a symbols table
allows to treat the blocks of consecutive symbols like ordinary codes;
only the blocks encoding a single symbol are still treated specially
(in order not to waste memory on tables for them).

In order to not increment the size of the tables used to initialize the
VLCs both the symbols as well as the lengths are now run-length encoded.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
libavcodec/rv10.c