Commit 8072345e authored by Vittorio Giovara's avatar Vittorio Giovara

intrax8: Keep a reference to the GetBitContext reader

Helps in decoupling this code from mpegvideo.
parent 65f14128
...@@ -132,7 +132,6 @@ static void x8_reset_vlc_tables(IntraX8Context *w) ...@@ -132,7 +132,6 @@ static void x8_reset_vlc_tables(IntraX8Context *w)
static inline void x8_select_ac_table(IntraX8Context *const w, int mode) static inline void x8_select_ac_table(IntraX8Context *const w, int mode)
{ {
MpegEncContext *const s = w->s;
int table_index; int table_index;
assert(mode < 4); assert(mode < 4);
...@@ -140,7 +139,7 @@ static inline void x8_select_ac_table(IntraX8Context *const w, int mode) ...@@ -140,7 +139,7 @@ static inline void x8_select_ac_table(IntraX8Context *const w, int mode)
if (w->j_ac_vlc[mode]) if (w->j_ac_vlc[mode])
return; return;
table_index = get_bits(&s->gb, 3); table_index = get_bits(w->gb, 3);
// 2 modes use same tables // 2 modes use same tables
w->j_ac_vlc[mode] = &j_ac_vlc[w->quant < 13][mode >> 1][table_index]; w->j_ac_vlc[mode] = &j_ac_vlc[w->quant < 13][mode >> 1][table_index];
...@@ -149,16 +148,14 @@ static inline void x8_select_ac_table(IntraX8Context *const w, int mode) ...@@ -149,16 +148,14 @@ static inline void x8_select_ac_table(IntraX8Context *const w, int mode)
static inline int x8_get_orient_vlc(IntraX8Context *w) static inline int x8_get_orient_vlc(IntraX8Context *w)
{ {
MpegEncContext *const s = w->s;
if (!w->j_orient_vlc) { if (!w->j_orient_vlc) {
int table_index = get_bits(&s->gb, 1 + (w->quant < 13)); int table_index = get_bits(w->gb, 1 + (w->quant < 13));
w->j_orient_vlc = &j_orient_vlc[w->quant < 13][table_index]; w->j_orient_vlc = &j_orient_vlc[w->quant < 13][table_index];
} }
assert(w->j_orient_vlc); assert(w->j_orient_vlc);
assert(w->j_orient_vlc->table); assert(w->j_orient_vlc->table);
return get_vlc2(&s->gb, w->j_orient_vlc->table, OR_VLC_BITS, OR_VLC_MTD); return get_vlc2(w->gb, w->j_orient_vlc->table, OR_VLC_BITS, OR_VLC_MTD);
} }
#define extra_bits(eb) (eb) // 3 bits #define extra_bits(eb) (eb) // 3 bits
...@@ -211,11 +208,10 @@ static const uint32_t ac_decode_table[] = { ...@@ -211,11 +208,10 @@ static const uint32_t ac_decode_table[] = {
static void x8_get_ac_rlf(IntraX8Context *const w, const int mode, static void x8_get_ac_rlf(IntraX8Context *const w, const int mode,
int *const run, int *const level, int *const final) int *const run, int *const level, int *const final)
{ {
MpegEncContext *const s = w->s;
int i, e; int i, e;
// x8_select_ac_table(w, mode); // x8_select_ac_table(w, mode);
i = get_vlc2(&s->gb, w->j_ac_vlc[mode]->table, AC_VLC_BITS, AC_VLC_MTD); i = get_vlc2(w->gb, w->j_ac_vlc[mode]->table, AC_VLC_BITS, AC_VLC_MTD);
if (i < 46) { // [0-45] if (i < 46) { // [0-45]
int t, l; int t, l;
...@@ -254,7 +250,7 @@ static void x8_get_ac_rlf(IntraX8Context *const w, const int mode, ...@@ -254,7 +250,7 @@ static void x8_get_ac_rlf(IntraX8Context *const w, const int mode,
i -= 46; i -= 46;
sm = ac_decode_table[i]; sm = ac_decode_table[i];
e = get_bits(&s->gb, sm & 0xF); e = get_bits(w->gb, sm & 0xF);
sm >>= 8; // 3bits sm >>= 8; // 3bits
mask = sm & 0xff; mask = sm & 0xff;
sm >>= 8; // 1bit sm >>= 8; // 1bit
...@@ -271,13 +267,13 @@ static void x8_get_ac_rlf(IntraX8Context *const w, const int mode, ...@@ -271,13 +267,13 @@ static void x8_get_ac_rlf(IntraX8Context *const w, const int mode,
}; };
(*final) = !(i & 1); (*final) = !(i & 1);
e = get_bits(&s->gb, 5); // get the extra bits e = get_bits(w->gb, 5); // get the extra bits
(*run) = crazy_mix_runlevel[e] >> 4; (*run) = crazy_mix_runlevel[e] >> 4;
(*level) = crazy_mix_runlevel[e] & 0x0F; (*level) = crazy_mix_runlevel[e] & 0x0F;
} else { } else {
(*level) = get_bits(&s->gb, 7 - 3 * (i & 1)); (*level) = get_bits(w->gb, 7 - 3 * (i & 1));
(*run) = get_bits(&s->gb, 6); (*run) = get_bits(w->gb, 6);
(*final) = get_bits1(&s->gb); (*final) = get_bits1(w->gb);
} }
return; return;
} }
...@@ -292,19 +288,18 @@ static const uint8_t dc_index_offset[] = { ...@@ -292,19 +288,18 @@ static const uint8_t dc_index_offset[] = {
static int x8_get_dc_rlf(IntraX8Context *const w, const int mode, static int x8_get_dc_rlf(IntraX8Context *const w, const int mode,
int *const level, int *const final) int *const level, int *const final)
{ {
MpegEncContext *const s = w->s;
int i, e, c; int i, e, c;
assert(mode < 3); assert(mode < 3);
if (!w->j_dc_vlc[mode]) { if (!w->j_dc_vlc[mode]) {
int table_index = get_bits(&s->gb, 3); int table_index = get_bits(w->gb, 3);
// 4 modes, same table // 4 modes, same table
w->j_dc_vlc[mode] = &j_dc_vlc[w->quant < 13][table_index]; w->j_dc_vlc[mode] = &j_dc_vlc[w->quant < 13][table_index];
} }
assert(w->j_dc_vlc); assert(w->j_dc_vlc);
assert(w->j_dc_vlc[mode]->table); assert(w->j_dc_vlc[mode]->table);
i = get_vlc2(&s->gb, w->j_dc_vlc[mode]->table, DC_VLC_BITS, DC_VLC_MTD); i = get_vlc2(w->gb, w->j_dc_vlc[mode]->table, DC_VLC_BITS, DC_VLC_MTD);
/* (i >= 17) { i -= 17; final =1; } */ /* (i >= 17) { i -= 17; final =1; } */
c = i > 16; c = i > 16;
...@@ -318,7 +313,7 @@ static int x8_get_dc_rlf(IntraX8Context *const w, const int mode, ...@@ -318,7 +313,7 @@ static int x8_get_dc_rlf(IntraX8Context *const w, const int mode,
c = (i + 1) >> 1; // hackish way to calculate dc_extra_sbits[] c = (i + 1) >> 1; // hackish way to calculate dc_extra_sbits[]
c -= c > 1; c -= c > 1;
e = get_bits(&s->gb, c); // get the extra bits e = get_bits(w->gb, c); // get the extra bits
i = dc_index_offset[i] + (e >> 1); i = dc_index_offset[i] + (e >> 1);
e = -(e & 1); // 0, 0xffffff e = -(e & 1); // 0, 0xffffff
...@@ -647,7 +642,7 @@ static int x8_decode_intra_mb(IntraX8Context *const w, const int chroma) ...@@ -647,7 +642,7 @@ static int x8_decode_intra_mb(IntraX8Context *const w, const int chroma)
level = (level + 1) * w->dquant; level = (level + 1) * w->dquant;
level += w->qsum; level += w->qsum;
sign = -get_bits1(&s->gb); sign = -get_bits1(w->gb);
level = (level ^ sign) - sign; level = (level ^ sign) - sign;
if (use_quant_matrix) if (use_quant_matrix)
...@@ -775,18 +770,20 @@ av_cold void ff_intrax8_common_end(IntraX8Context *w) ...@@ -775,18 +770,20 @@ av_cold void ff_intrax8_common_end(IntraX8Context *w)
} }
int ff_intrax8_decode_picture(IntraX8Context *const w, Picture *pict, int ff_intrax8_decode_picture(IntraX8Context *const w, Picture *pict,
GetBitContext *gb,
int dquant, int quant_offset, int loopfilter) int dquant, int quant_offset, int loopfilter)
{ {
MpegEncContext *const s = w->s; MpegEncContext *const s = w->s;
int mb_xy; int mb_xy;
assert(s); assert(s);
w->use_quant_matrix = get_bits1(&s->gb);
w->gb = gb;
w->dquant = dquant; w->dquant = dquant;
w->quant = dquant >> 1; w->quant = dquant >> 1;
w->qsum = quant_offset; w->qsum = quant_offset;
w->frame = pict->f; w->frame = pict->f;
w->loopfilter = loopfilter; w->loopfilter = loopfilter;
w->use_quant_matrix = get_bits1(w->gb);
w->divide_quant_dc_luma = ((1 << 16) + (w->quant >> 1)) / w->quant; w->divide_quant_dc_luma = ((1 << 16) + (w->quant >> 1)) / w->quant;
if (w->quant < 5) { if (w->quant < 5) {
......
...@@ -45,6 +45,7 @@ typedef struct IntraX8Context { ...@@ -45,6 +45,7 @@ typedef struct IntraX8Context {
int qsum; int qsum;
int loopfilter; int loopfilter;
AVFrame *frame; AVFrame *frame;
GetBitContext *gb;
// calculated per frame // calculated per frame
int quant_dc_chroma; int quant_dc_chroma;
...@@ -82,17 +83,18 @@ void ff_intrax8_common_end(IntraX8Context *w); ...@@ -82,17 +83,18 @@ void ff_intrax8_common_end(IntraX8Context *w);
/** /**
* Decode single IntraX8 frame. * Decode single IntraX8 frame.
* The parent codec must fill s->gb (bitstream).
* The parent codec must call ff_mpv_frame_start() before calling this function. * The parent codec must call ff_mpv_frame_start() before calling this function.
* The parent codec must call ff_mpv_frame_end() after calling this function. * The parent codec must call ff_mpv_frame_end() after calling this function.
* This function does not use ff_mpv_decode_mb(). * This function does not use ff_mpv_decode_mb().
* @param w pointer to IntraX8Context * @param w pointer to IntraX8Context
* @param pict the output Picture containing an AVFrame * @param pict the output Picture containing an AVFrame
* @param gb open bitstream reader
* @param dquant doubled quantizer, it would be odd in case of VC-1 halfpq==1. * @param dquant doubled quantizer, it would be odd in case of VC-1 halfpq==1.
* @param quant_offset offset away from zero * @param quant_offset offset away from zero
* @param loopfilter enable filter after decoding a block * @param loopfilter enable filter after decoding a block
*/ */
int ff_intrax8_decode_picture(IntraX8Context *w, Picture *pict, int ff_intrax8_decode_picture(IntraX8Context *w, Picture *pict,
GetBitContext *gb,
int quant, int halfpq, int loopfilter); int quant, int halfpq, int loopfilter);
#endif /* AVCODEC_INTRAX8_H */ #endif /* AVCODEC_INTRAX8_H */
...@@ -3022,7 +3022,7 @@ void ff_vc1_decode_blocks(VC1Context *v) ...@@ -3022,7 +3022,7 @@ void ff_vc1_decode_blocks(VC1Context *v)
v->s.esc3_level_length = 0; v->s.esc3_level_length = 0;
if (v->x8_type) { if (v->x8_type) {
ff_intrax8_decode_picture(&v->x8, &v->s.current_picture, ff_intrax8_decode_picture(&v->x8, &v->s.current_picture, &v->s.gb,
2 * v->pq + v->halfpq, v->pq * !v->pquantizer, 2 * v->pq + v->halfpq, v->pq * !v->pquantizer,
v->s.loop_filter); v->s.loop_filter);
......
...@@ -228,7 +228,7 @@ int ff_wmv2_decode_secondary_picture_header(MpegEncContext *s) ...@@ -228,7 +228,7 @@ int ff_wmv2_decode_secondary_picture_header(MpegEncContext *s)
s->picture_number++; // FIXME ? s->picture_number++; // FIXME ?
if (w->j_type) { if (w->j_type) {
ff_intrax8_decode_picture(&w->x8, &s->current_picture, ff_intrax8_decode_picture(&w->x8, &s->current_picture, &s->gb,
2 * s->qscale, (s->qscale - 1) | 1, 2 * s->qscale, (s->qscale - 1) | 1,
s->loop_filter); s->loop_filter);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment