diff options
author | Andreas Rheinhardt <andreas.rheinhardt@gmail.com> | 2020-11-17 08:46:53 +0100 |
---|---|---|
committer | Andreas Rheinhardt <andreas.rheinhardt@gmail.com> | 2020-12-08 17:51:45 +0100 |
commit | ef9652bab2921126a88111cebfbd645050a5e373 (patch) | |
tree | 6525bd82130f23992b62704e406bfb1730f1a244 | |
parent | 1d3ec27bd54ceb5108ad9f9ed430266ccc4cbc71 (diff) | |
download | ffmpeg-ef9652bab2921126a88111cebfbd645050a5e373.tar.gz |
avcodec/clearvideo: Improve handling of VLC escape values
Both the motion vector as well as the bias VLCs have an escape code;
for the motion vectors, this value depended on the specific VLC table,
whereas all the bias VLCs used the same value; the escape value has not
been inlined in the latter case.
But for both kinds of VLCs there are lots of values that are unused for
all the VLCs of each kind and each of these can be used as common escape
value, thus allowing to inline the escape value. This commit implements
this.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
-rw-r--r-- | libavcodec/clearvideo.c | 8 | ||||
-rw-r--r-- | libavcodec/clearvideodata.h | 36 |
2 files changed, 19 insertions, 25 deletions
diff --git a/libavcodec/clearvideo.c b/libavcodec/clearvideo.c index 39e3991053..3e666b98e9 100644 --- a/libavcodec/clearvideo.c +++ b/libavcodec/clearvideo.c @@ -33,8 +33,6 @@ #include "clearvideodata.h" typedef struct LevelCodes { - uint16_t mv_esc; - uint16_t bias_esc; VLC flags_cb; VLC mv_cb; VLC bias_cb; @@ -371,7 +369,7 @@ static TileInfo* decode_tile_info(GetBitContext *gb, LevelCodes *lc, int level) if (lc[level].mv_cb.table) { uint16_t mv_code = get_vlc2(gb, lc[level].mv_cb.table, lc[level].mv_cb.bits, 3); - if (mv_code != lc[level].mv_esc) { + if (mv_code != MV_ESC) { mv.x = (int8_t)(mv_code & 0xff); mv.y = (int8_t)(mv_code >> 8); } else { @@ -383,7 +381,7 @@ static TileInfo* decode_tile_info(GetBitContext *gb, LevelCodes *lc, int level) if (lc[level].bias_cb.table) { uint16_t bias_val = get_vlc2(gb, lc[level].bias_cb.table, lc[level].bias_cb.bits, 2); - if (bias_val != lc[level].bias_esc) { + if (bias_val != BIAS_ESC) { bias = (int16_t)(bias_val); } else { bias = get_sbits(gb, 16); @@ -728,7 +726,6 @@ static av_cold int clv_decode_init(AVCodecContext *avctx) for (int i = 0, j = 0, k = 0;; i++) { if (0x36F & (1 << i)) { - c->lev[i].mv_esc = clv_mv_escape[i]; ret = build_vlc(&c->lev[i].mv_cb, clv_mv_len_counts[k], &mv_syms); if (ret < 0) return ret; @@ -743,7 +740,6 @@ static av_cold int clv_decode_init(AVCodecContext *avctx) if (ret < 0) return ret; - c->lev[i + 1].bias_esc = 0x100; ret = build_vlc(&c->lev[i + 1].bias_cb, clv_bias_len_counts[j], &bias_syms); if (ret < 0) diff --git a/libavcodec/clearvideodata.h b/libavcodec/clearvideodata.h index d2c658eb5d..89bf192bce 100644 --- a/libavcodec/clearvideodata.h +++ b/libavcodec/clearvideodata.h @@ -111,10 +111,6 @@ static const uint8_t clv_flags_syms[][16] = { { 0, 8, 3, 4, 2, 1, 12, 5, 10, 7, 9, 6, 14, 11, 13, 15 } // V_1 }; -static const uint16_t clv_mv_escape[] = { - 0x0909, 0x0A0A, 0x1010, 0x1313, 0, 0x0808, 0x0B0B, 0, 0x0808, 0x0B0B -}; - static const uint8_t clv_mv_len_counts[][16] = { { 1, 0, 0, 2, 2, 6, 13, 6, 14, 28, 38, 38, 58, 56, 20, 8 }, { 1, 0, 0, 2, 3, 4, 8, 10, 20, 30, 37, 63, 84, 68, 32, 0 }, @@ -126,9 +122,10 @@ static const uint8_t clv_mv_len_counts[][16] = { { 1, 0, 0, 0, 4, 5, 14, 18, 20, 39, 6, 80, 75, 112, 36, 32 }, }; +#define MV_ESC 0x13 static const uint16_t clv_mv_syms[] = { /* Y_0 motion vectors - 290 entries */ - 0x0000, 0x00FF, 0x0001, 0xFF00, 0x0100, 0x0002, 0x00FE, 0x0909, 0x00FD, + 0x0000, 0x00FF, 0x0001, 0xFF00, 0x0100, 0x0002, 0x00FE, MV_ESC, 0x00FD, 0x0004, 0x00FC, 0x0003, 0x01FF, 0xFF01, 0x0101, 0xFFFF, 0xFE00, 0x0200, 0x0005, 0x00FB, 0x00FA, 0x0006, 0x0007, 0x00F9, 0xFF02, 0x0102, 0xFFFE, 0x01FE, 0xFD00, 0x0300, 0xFC00, 0x0400, 0x02FF, 0xFE01, 0x0201, 0xFEFF, @@ -162,7 +159,7 @@ static const uint16_t clv_mv_syms[] = { 0x08FA, 0xF806, 0xF8FA, 0x0804, 0x08FC, 0xF804, 0xF8FC, 0x0808, 0xF8F8, 0x08F8, 0xF808, /* Y_1 motion vectors - 362 entries */ - 0x0000, 0x00FF, 0x0001, 0xFF00, 0x0100, 0x0A0A, 0xFFFF, 0x01FF, 0xFF01, + 0x0000, 0x00FF, 0x0001, 0xFF00, 0x0100, MV_ESC, 0xFFFF, 0x01FF, 0xFF01, 0x0101, 0x00FE, 0x0002, 0x0003, 0x00FD, 0x0004, 0x00FC, 0xFE00, 0x0200, 0x0005, 0x00FB, 0x00FA, 0x0006, 0x0007, 0x00F9, 0xFFFE, 0x01FE, 0xFF02, 0x0102, 0xFF03, 0x0103, 0xFFFD, 0x01FD, 0xFEFF, 0x02FF, 0xFE01, 0x0201, @@ -205,7 +202,7 @@ static const uint16_t clv_mv_syms[] = { 0x0907, 0xF707, /* Y_2 motion vectors - 962 entries */ 0x0000, 0x0001, 0x00FF, 0xFF00, 0x0100, 0x0002, 0x00FE, 0x0101, 0xFFFF, - 0x01FF, 0xFF01, 0x0003, 0x00FD, 0x0004, 0x00FC, 0x1010, 0x0005, 0x00FB, + 0x01FF, 0xFF01, 0x0003, 0x00FD, 0x0004, 0x00FC, MV_ESC, 0x0005, 0x00FB, 0xFE00, 0x0200, 0xFF02, 0x0102, 0xFFFE, 0x01FE, 0x00FA, 0x0006, 0x00F9, 0x0007, 0x0201, 0xFEFF, 0x02FF, 0xFE01, 0xFD00, 0x0300, 0xFF03, 0x0103, 0xFFFD, 0x01FD, 0xFC00, 0x0400, 0x0008, 0x00F8, 0xFB00, 0x0500, 0x0009, @@ -314,7 +311,7 @@ static const uint16_t clv_mv_syms[] = { /* Y_3 motion vectors - 1370 elements */ 0x0000, 0x00FF, 0x0001, 0xFF00, 0x0100, 0x00FE, 0x0002, 0xFFFF, 0x01FF, 0xFF01, 0x0101, 0x00FD, 0x0003, 0x00FC, 0x0004, 0xFE00, 0x0200, 0x0005, - 0x00FB, 0x1313, 0xFFFE, 0x01FE, 0xFF02, 0x0102, 0x0006, 0x00FA, 0xFEFF, + 0x00FB, MV_ESC, 0xFFFE, 0x01FE, 0xFF02, 0x0102, 0x0006, 0x00FA, 0xFEFF, 0x02FF, 0xFE01, 0x0201, 0xFD00, 0x0300, 0xFC00, 0x0400, 0x00F9, 0x0007, 0xFFFD, 0x01FD, 0xFF03, 0x0103, 0x00F8, 0x0008, 0x00F7, 0x0009, 0x000A, 0x00F6, 0xFEFE, 0x02FE, 0xFE02, 0x0202, 0xFFFC, 0x01FC, 0xFF04, 0x0104, @@ -468,7 +465,7 @@ static const uint16_t clv_mv_syms[] = { /* U_1 motion vectors - 226 entries */ 0x0001, 0x00FF, 0x0000, 0x0002, 0x00FE, 0x00FD, 0x0003, 0xFF00, 0x0100, 0xFE00, 0x0200, 0x0101, 0xFFFF, 0x01FF, 0xFF01, 0x00FB, 0x0005, 0xFD00, - 0x0300, 0xFC00, 0x0400, 0x0004, 0x00FC, 0x0808, 0x00FA, 0x0006, 0x0201, + 0x0300, 0xFC00, 0x0400, 0x0004, 0x00FC, MV_ESC, 0x00FA, 0x0006, 0x0201, 0xFEFF, 0x02FF, 0xFE01, 0xFFFD, 0x01FD, 0xFF03, 0x0103, 0xFEFD, 0x02FD, 0xFE03, 0x0203, 0xFF02, 0x0102, 0xFFFE, 0x01FE, 0xFB00, 0x0500, 0xFDFD, 0x03FD, 0xFD03, 0x0303, 0xFF04, 0x0104, 0xFFFC, 0x01FC, 0xFE02, 0x0202, @@ -494,7 +491,7 @@ static const uint16_t clv_mv_syms[] = { 0x0707, /* U_2 motion vectors - 442 entries */ 0x0000, 0xFF00, 0x0100, 0x00FF, 0x0001, 0xFFFF, 0x01FF, 0xFF01, 0x0101, - 0x0B0B, 0x0002, 0x00FE, 0xFE00, 0x0200, 0x0003, 0x00FD, 0xFEFF, 0x02FF, + MV_ESC, 0x0002, 0x00FE, 0xFE00, 0x0200, 0x0003, 0x00FD, 0xFEFF, 0x02FF, 0xFE01, 0x0201, 0xFF02, 0x0102, 0xFFFE, 0x01FE, 0xFD00, 0x0300, 0x00FC, 0x0005, 0xFDFF, 0x03FF, 0xFD01, 0x0301, 0xFF03, 0x0103, 0xFFFD, 0x01FD, 0xFE02, 0x0202, 0xFEFE, 0x02FE, 0xFCFF, 0x04FF, 0xFC01, 0x0401, 0xFBFF, @@ -546,7 +543,7 @@ static const uint16_t clv_mv_syms[] = { /* V_1 motion vectors - 226 entries */ 0x0001, 0x00FF, 0x0000, 0xFF00, 0x0100, 0x0002, 0x00FE, 0x00FD, 0x0003, 0x0004, 0x00FC, 0x00FB, 0x0005, 0x0101, 0xFFFF, 0x01FF, 0xFF01, 0xFE00, - 0x0200, 0xFD00, 0x0300, 0x0808, 0xFF02, 0x0102, 0xFFFE, 0x01FE, 0xFC00, + 0x0200, 0xFD00, 0x0300, MV_ESC, 0xFF02, 0x0102, 0xFFFE, 0x01FE, 0xFC00, 0x0400, 0x0201, 0xFEFF, 0x02FF, 0xFE01, 0xFFFD, 0x01FD, 0xFF03, 0x0103, 0x00FA, 0x0006, 0xFE02, 0x0202, 0xFEFE, 0x02FE, 0xFD02, 0x0302, 0xFDFE, 0x03FE, 0xFEFD, 0xFC02, 0x02FD, 0x0402, 0xFE03, 0xFCFE, 0x0203, 0x04FE, @@ -572,7 +569,7 @@ static const uint16_t clv_mv_syms[] = { 0x0707, /* V_2 motion vectors - 442 elements */ 0x0000, 0x00FF, 0x0001, 0xFF00, 0x0100, 0xFFFF, 0x01FF, 0xFF01, 0x0101, - 0x0B0B, 0xFE00, 0x0200, 0xFEFF, 0x02FF, 0xFE01, 0x0201, 0x0002, 0x00FE, + MV_ESC, 0xFE00, 0x0200, 0xFEFF, 0x02FF, 0xFE01, 0x0201, 0x0002, 0x00FE, 0x00FC, 0x0003, 0x0004, 0x00FD, 0x0005, 0x00FB, 0xFDFF, 0x03FF, 0xFD01, 0x0301, 0xFFFC, 0x01FC, 0xFF03, 0x0103, 0xFF04, 0x0104, 0xFFFD, 0x01FD, 0xFD00, 0x0300, 0xFF02, 0x0102, 0xFFFE, 0x01FE, 0xFC00, 0x0400, 0xFEFC, @@ -633,12 +630,13 @@ static const uint8_t clv_bias_len_counts[][16] = { { 1, 0, 2, 2, 2, 1, 3, 2, 4, 5, 1, 4, 10, 2, 3, 2 }, }; +#define BIAS_ESC 1 static const uint16_t clv_bias_syms[] = { /* Y_1 bias values - 78 entries */ 0x0000, 0xFFFC, 0x0004, 0xFFF8, 0x0008, 0xFFF4, 0x000C, 0xFFF0, 0x0010, 0xFFEC, 0x0014, 0xFFE8, 0x0018, 0xFFE4, 0x001C, 0x0020, 0xFFE0, 0x0024, 0xFFDC, 0x0028, 0xFFD8, 0x002C, 0xFFD4, 0x0030, 0xFFD0, 0xFFCC, 0x0034, - 0xFFC8, 0x0038, 0x0100, 0xFFC4, 0x003C, 0xFFC0, 0x0040, 0xFFBC, 0x0044, + 0xFFC8, 0x0038, BIAS_ESC, 0xFFC4, 0x003C, 0xFFC0, 0x0040, 0xFFBC, 0x0044, 0xFFB8, 0x0048, 0xFFB4, 0x004C, 0xFFB0, 0x0050, 0xFFAC, 0x0054, 0xFFA8, 0x0058, 0xFFA4, 0x005C, 0x0060, 0xFFA0, 0x0064, 0xFF9C, 0x0068, 0xFF98, 0x006C, 0xFF94, 0x0070, 0xFF90, 0x0074, 0xFF8C, 0xFF88, 0x0078, 0x007C, @@ -652,7 +650,7 @@ static const uint16_t clv_bias_syms[] = { 0xFFB8, 0x004C, 0xFFB4, 0x0050, 0xFFB0, 0x0054, 0xFFAC, 0xFFA8, 0x0058, 0x005C, 0xFFA4, 0x0060, 0xFFA0, 0x0064, 0xFF9C, 0xFF98, 0x0068, 0x006C, 0xFF94, 0x0070, 0xFF90, 0x0074, 0xFF8C, 0xFF88, 0x0078, 0xFF84, 0x007C, - 0xFF80, 0x0080, 0xFF7C, 0x0084, 0x0100, 0xFF78, 0x0088, 0x008C, 0xFF74, + 0xFF80, 0x0080, 0xFF7C, 0x0084, BIAS_ESC, 0xFF78, 0x0088, 0x008C, 0xFF74, 0x0090, 0xFF70, 0x0094, 0xFF6C, 0xFF64, 0x009C, 0xFF68, 0x0098, 0xFF60, 0x00A0, 0xFF5C, 0x00A4, 0x00A8, 0xFF58, 0x00AC, 0xFF54, 0xFF50, 0x00B0, 0x00B4, 0xFF4C, 0xFF48, 0x00B8, 0xFF44, 0x00BC, 0xFF40, 0x00C0, @@ -666,33 +664,33 @@ static const uint16_t clv_bias_syms[] = { 0xFF94, 0xFF90, 0x0070, 0xFF8C, 0x0074, 0x0078, 0xFF88, 0xFF84, 0x007C, 0xFF80, 0x0080, 0x0084, 0xFF7C, 0x0088, 0xFF78, 0x008C, 0xFF74, 0xFF70, 0x0090, 0x0094, 0xFF6C, 0x0098, 0xFF68, 0xFF64, 0x009C, 0xFF60, 0x00A0, - 0xFF5C, 0x00A4, 0x0100, 0xFF58, 0x00A8, 0x00AC, 0xFF54, 0xFF50, 0x00B0, + 0xFF5C, 0x00A4, BIAS_ESC, 0xFF58, 0x00A8, 0x00AC, 0xFF54, 0xFF50, 0x00B0, 0xFF4C, 0x00B4, 0x00B8, 0xFF48, /* U_1 bias values - 42 entries */ 0x0000, 0xFFFC, 0x0004, 0xFFF8, 0x0008, 0xFFF4, 0x000C, 0xFFF0, 0x0010, 0xFFEC, 0x0014, 0x0018, 0xFFE8, 0xFFE4, 0x001C, 0xFFE0, 0x0020, 0xFFDC, 0x0024, 0xFFD8, 0x0028, 0x002C, 0xFFD4, 0x0030, 0xFFCC, 0xFFD0, 0x0034, 0xFFC8, 0x0038, 0x003C, 0xFFC4, 0xFFC0, 0x0040, 0xFFBC, 0x0044, 0xFFB8, - 0x0048, 0xFFB4, 0x004C, 0x0050, 0xFFB0, 0x0100, + 0x0048, 0xFFB4, 0x004C, 0x0050, 0xFFB0, BIAS_ESC, /* U_2 bias values - 54 entries */ 0x0000, 0xFFFC, 0x0004, 0xFFF8, 0x0008, 0xFFF4, 0x000C, 0xFFF0, 0x0010, 0x0014, 0xFFEC, 0x0018, 0xFFE8, 0x001C, 0xFFE4, 0x0020, 0xFFE0, 0xFFDC, 0x0024, 0xFFD8, 0x0028, 0xFFD4, 0x002C, 0x0030, 0xFFD0, 0x0034, 0xFFCC, 0x0038, 0xFFC8, 0x003C, 0xFFC4, 0x0040, 0xFFC0, 0xFFBC, 0x0044, 0xFFB4, - 0xFFB8, 0x0048, 0x004C, 0x0100, 0x0058, 0xFFB0, 0xFFA8, 0x0054, 0xFFAC, + 0xFFB8, 0x0048, 0x004C, BIAS_ESC, 0x0058, 0xFFB0, 0xFFA8, 0x0054, 0xFFAC, 0x0050, 0xFF9C, 0x005C, 0xFFA0, 0x0068, 0xFF98, 0xFFA4, 0x0064, 0x0060, /* V_1 bias values - 42 entries */ 0x0000, 0xFFFC, 0x0004, 0xFFF8, 0x0008, 0xFFF4, 0x000C, 0xFFF0, 0x0010, 0xFFEC, 0x0014, 0x0018, 0xFFE8, 0xFFE4, 0x001C, 0xFFE0, 0x0020, 0xFFDC, 0x0024, 0xFFD8, 0x0028, 0x002C, 0xFFD4, 0x0030, 0xFFD0, 0xFFCC, 0x0034, - 0xFFC8, 0x0038, 0x003C, 0xFFC4, 0x0100, 0xFFC0, 0x0040, 0xFFBC, 0x0044, + 0xFFC8, 0x0038, 0x003C, 0xFFC4, BIAS_ESC, 0xFFC0, 0x0040, 0xFFBC, 0x0044, 0xFFB8, 0x0048, 0xFFB4, 0x004C, 0x0050, 0xFFB0, /* V_2 bias values - 44 entries */ 0x0000, 0xFFFC, 0x0004, 0xFFF8, 0x0008, 0xFFF4, 0x000C, 0xFFF0, 0x0010, 0xFFEC, 0x0014, 0xFFE8, 0x0018, 0x001C, 0xFFE4, 0xFFE0, 0x0020, 0xFFDC, 0x0024, 0x0028, 0xFFD8, 0x002C, 0xFFD4, 0x0030, 0xFFD0, 0xFFCC, 0x0034, 0xFFC8, 0x0038, 0x0040, 0xFFC4, 0xFFC0, 0x003C, 0x0044, 0xFFBC, 0xFFB8, - 0x0048, 0xFFB4, 0x004C, 0x0100, 0xFFB0, 0x0054, 0xFFAC, 0x0050 + 0x0048, 0xFFB4, 0x004C, BIAS_ESC, 0xFFB0, 0x0054, 0xFFAC, 0x0050 }; #endif /* AVCODEC_CLEARVIDEODATA_H */ |