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>
This commit is contained in:
Andreas Rheinhardt 2020-12-29 18:24:40 +01:00 committed by Andreas Rheinhardt
parent fbb9e0dbc8
commit 6d484671ec
3 changed files with 70 additions and 67 deletions

View File

@ -48,9 +48,6 @@
#include "put_bits.h" #include "put_bits.h"
#include "simple_idct.h" #include "simple_idct.h"
/* XXX: also include quantization */
RL_VLC_ELEM ff_dv_rl_vlc[1664];
static inline void dv_calc_mb_coordinates(const AVDVProfile *d, int chan, static inline void dv_calc_mb_coordinates(const AVDVProfile *d, int chan,
int seq, int slot, uint16_t *tbl) int seq, int slot, uint16_t *tbl)
{ {
@ -198,65 +195,9 @@ int ff_dv_init_dynamic_tables(DVVideoContext *ctx, const AVDVProfile *d)
av_cold int ff_dvvideo_init(AVCodecContext *avctx) av_cold int ff_dvvideo_init(AVCodecContext *avctx)
{ {
DVVideoContext *s = avctx->priv_data; DVVideoContext *s = avctx->priv_data;
static int done = 0;
int i, j;
if (!done) {
VLC_TYPE vlc_buf[FF_ARRAY_ELEMS(ff_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];
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 (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];
}
ff_dv_rl_vlc[i].len = len;
ff_dv_rl_vlc[i].level = level;
ff_dv_rl_vlc[i].run = run;
}
}
s->avctx = avctx; s->avctx = avctx;
avctx->chroma_sample_location = AVCHROMA_LOC_TOPLEFT; avctx->chroma_sample_location = AVCHROMA_LOC_TOPLEFT;
return 0; return 0;
} }

View File

@ -96,10 +96,6 @@ enum dv_pack_type {
*/ */
#define DV_MAX_BPM 8 #define DV_MAX_BPM 8
#define TEX_VLC_BITS 10
extern RL_VLC_ELEM ff_dv_rl_vlc[1664];
int ff_dv_init_dynamic_tables(DVVideoContext *s, const AVDVProfile *d); int ff_dv_init_dynamic_tables(DVVideoContext *s, const AVDVProfile *d);
int ff_dvvideo_init(AVCodecContext *avctx); int ff_dvvideo_init(AVCodecContext *avctx);

View File

@ -128,6 +128,70 @@ static const uint16_t dv_iweight_720_c[64] = {
394, 406, 418, 438, 418, 464, 464, 492, 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) static void dv_init_weight_tables(DVVideoContext *ctx, const AVDVProfile *d)
{ {
int j, i, c, s; 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[0] = s->idsp.idct_put;
s->idct_put[1] = ff_simple_idct248_put; s->idct_put[1] = ff_simple_idct248_put;
dv_init_static();
return ff_dvvideo_init(avctx); 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); pos, SHOW_UBITS(re, gb, 16), re_index);
/* our own optimized GET_RL_VLC */ /* our own optimized GET_RL_VLC */
index = NEG_USR32(re_cache, TEX_VLC_BITS); 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) { if (vlc_len < 0) {
index = NEG_USR32((unsigned) re_cache << TEX_VLC_BITS, -vlc_len) + 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; vlc_len = TEX_VLC_BITS - vlc_len;
} }
level = ff_dv_rl_vlc[index].level; level = dv_rl_vlc[index].level;
run = ff_dv_rl_vlc[index].run; run = dv_rl_vlc[index].run;
/* gotta check if we're still within gb boundaries */ /* gotta check if we're still within gb boundaries */
if (re_index + vlc_len > last_index) { if (re_index + vlc_len > last_index) {