summaryrefslogtreecommitdiff
path: root/libavcodec/dvdec.c
diff options
context:
space:
mode:
authorAndreas Rheinhardt <andreas.rheinhardt@gmail.com>2020-12-29 18:24:40 +0100
committerAndreas Rheinhardt <andreas.rheinhardt@outlook.com>2021-05-06 06:13:54 +0200
commit6d484671ecb612c32cbda0fab65f961743aff5f8 (patch)
treecd5b3460687baeeaee27218b289453efa387f1ee /libavcodec/dvdec.c
parentfbb9e0dbc8a685917e25837d01f4d159e84152d7 (diff)
avcodec/dv: Don't initialize RL VLC for encoder
Said RL VLC is only used by the decoder, ergo don't initialize it for the encoder and move the whole code and the RL VLC table itself to dvdec.c. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Diffstat (limited to 'libavcodec/dvdec.c')
-rw-r--r--libavcodec/dvdec.c74
1 files changed, 70 insertions, 4 deletions
diff --git a/libavcodec/dvdec.c b/libavcodec/dvdec.c
index d768326661..da6112ff1f 100644
--- a/libavcodec/dvdec.c
+++ b/libavcodec/dvdec.c
@@ -128,6 +128,70 @@ static const uint16_t dv_iweight_720_c[64] = {
394, 406, 418, 438, 418, 464, 464, 492,
};
+#define TEX_VLC_BITS 10
+
+/* XXX: also include quantization */
+static RL_VLC_ELEM dv_rl_vlc[1664];
+
+static void dv_init_static(void)
+{
+ VLC_TYPE vlc_buf[FF_ARRAY_ELEMS(dv_rl_vlc)][2] = { 0 };
+ VLC dv_vlc = { .table = vlc_buf, .table_allocated = FF_ARRAY_ELEMS(vlc_buf) };
+ uint16_t new_dv_vlc_bits[NB_DV_VLC * 2];
+ uint8_t new_dv_vlc_len[NB_DV_VLC * 2];
+ uint8_t new_dv_vlc_run[NB_DV_VLC * 2];
+ int16_t new_dv_vlc_level[NB_DV_VLC * 2];
+ int i, j;
+ static int done = 0;
+
+ if (done)
+ return;
+
+ done = 1;
+
+ /* it's faster to include sign bit in a generic VLC parsing scheme */
+ for (i = 0, j = 0; i < NB_DV_VLC; i++, j++) {
+ new_dv_vlc_bits[j] = ff_dv_vlc_bits[i];
+ new_dv_vlc_len[j] = ff_dv_vlc_len[i];
+ new_dv_vlc_run[j] = ff_dv_vlc_run[i];
+ new_dv_vlc_level[j] = ff_dv_vlc_level[i];
+
+ if (ff_dv_vlc_level[i]) {
+ new_dv_vlc_bits[j] <<= 1;
+ new_dv_vlc_len[j]++;
+
+ j++;
+ new_dv_vlc_bits[j] = (ff_dv_vlc_bits[i] << 1) | 1;
+ new_dv_vlc_len[j] = ff_dv_vlc_len[i] + 1;
+ new_dv_vlc_run[j] = ff_dv_vlc_run[i];
+ new_dv_vlc_level[j] = -ff_dv_vlc_level[i];
+ }
+ }
+
+ /* NOTE: as a trick, we use the fact the no codes are unused
+ * to accelerate the parsing of partial codes */
+ init_vlc(&dv_vlc, TEX_VLC_BITS, j, new_dv_vlc_len,
+ 1, 1, new_dv_vlc_bits, 2, 2, INIT_VLC_USE_NEW_STATIC);
+ av_assert1(dv_vlc.table_size == 1664);
+
+ for (int i = 0; i < dv_vlc.table_size; i++) {
+ int code = dv_vlc.table[i][0];
+ int len = dv_vlc.table[i][1];
+ int level, run;
+
+ if (len < 0) { // more bits needed
+ run = 0;
+ level = code;
+ } else {
+ run = new_dv_vlc_run[code] + 1;
+ level = new_dv_vlc_level[code];
+ }
+ dv_rl_vlc[i].len = len;
+ dv_rl_vlc[i].level = level;
+ dv_rl_vlc[i].run = run;
+ }
+}
+
static void dv_init_weight_tables(DVVideoContext *ctx, const AVDVProfile *d)
{
int j, i, c, s;
@@ -195,6 +259,8 @@ static av_cold int dvvideo_decode_init(AVCodecContext *avctx)
s->idct_put[0] = s->idsp.idct_put;
s->idct_put[1] = ff_simple_idct248_put;
+ dv_init_static();
+
return ff_dvvideo_init(avctx);
}
@@ -225,14 +291,14 @@ static void dv_decode_ac(GetBitContext *gb, BlockInfo *mb, int16_t *block)
pos, SHOW_UBITS(re, gb, 16), re_index);
/* our own optimized GET_RL_VLC */
index = NEG_USR32(re_cache, TEX_VLC_BITS);
- vlc_len = ff_dv_rl_vlc[index].len;
+ vlc_len = dv_rl_vlc[index].len;
if (vlc_len < 0) {
index = NEG_USR32((unsigned) re_cache << TEX_VLC_BITS, -vlc_len) +
- ff_dv_rl_vlc[index].level;
+ dv_rl_vlc[index].level;
vlc_len = TEX_VLC_BITS - vlc_len;
}
- level = ff_dv_rl_vlc[index].level;
- run = ff_dv_rl_vlc[index].run;
+ level = dv_rl_vlc[index].level;
+ run = dv_rl_vlc[index].run;
/* gotta check if we're still within gb boundaries */
if (re_index + vlc_len > last_index) {