--- NOTE: both these elements are not actually used by the decoders: vc1 modifies them only for intra (non-j) or interframes, wmv2 does something similar. I'm not extremely confident in dropping the references, at least not right now, however these two buffers could and should be made local.
Opinions? Vittorio libavcodec/intrax8.c | 31 ++++++++++++++++--------------- libavcodec/intrax8.h | 6 ++++++ libavcodec/vc1dec.c | 1 + libavcodec/wmv2dec.c | 1 + 4 files changed, 24 insertions(+), 15 deletions(-) diff --git a/libavcodec/intrax8.c b/libavcodec/intrax8.c index 44cf141..ffb40b6 100644 --- a/libavcodec/intrax8.c +++ b/libavcodec/intrax8.c @@ -472,9 +472,8 @@ static void x8_get_prediction(IntraX8Context *const w) static void x8_ac_compensation(IntraX8Context *const w, int const direction, int const dc_level) { - MpegEncContext *const s = w->s; int t; -#define B(x, y) s->block[0][w->idsp.idct_permutation[(x) + (y) * 8]] +#define B(x, y) w->block[0][w->idsp.idct_permutation[(x) + (y) * 8]] #define T(x) ((x) * dc_level + 0x8000) >> 16; switch (direction) { case 0: @@ -518,7 +517,7 @@ static void x8_ac_compensation(IntraX8Context *const w, int const direction, t = T(1084); // g B(1, 1) += t; - s->block_last_index[0] = FFMAX(s->block_last_index[0], 7 * 8); + w->block_last_index[0] = FFMAX(w->block_last_index[0], 7 * 8); break; case 1: B(0, 1) -= T(6269); @@ -526,7 +525,7 @@ static void x8_ac_compensation(IntraX8Context *const w, int const direction, B(0, 5) -= T(172); B(0, 7) -= T(73); - s->block_last_index[0] = FFMAX(s->block_last_index[0], 7 * 8); + w->block_last_index[0] = FFMAX(w->block_last_index[0], 7 * 8); break; case 2: B(1, 0) -= T(6269); @@ -534,7 +533,7 @@ static void x8_ac_compensation(IntraX8Context *const w, int const direction, B(5, 0) -= T(172); B(7, 0) -= T(73); - s->block_last_index[0] = FFMAX(s->block_last_index[0], 7); + w->block_last_index[0] = FFMAX(w->block_last_index[0], 7); break; } #undef B @@ -564,8 +563,6 @@ static const int16_t quant_table[64] = { static int x8_decode_intra_mb(IntraX8Context *const w, const int chroma) { - MpegEncContext *const s = w->s; - uint8_t *scantable; int final, run, level; int ac_mode, dc_mode, est_run, dc_level; @@ -575,7 +572,7 @@ static int x8_decode_intra_mb(IntraX8Context *const w, const int chroma) int sign; assert(w->orient < 12); - w->bdsp.clear_block(s->block[0]); + w->bdsp.clear_block(w->block[0]); if (chroma) dc_mode = 2; @@ -636,12 +633,12 @@ static int x8_decode_intra_mb(IntraX8Context *const w, const int chroma) if (use_quant_matrix) { level = (level * quant_table[pos]) >> 8; } - s->block[0][scantable[pos]] = level; + w->block[0][scantable[pos]] = level; } while (!final); - s->block_last_index[0] = pos; + w->block_last_index[0] = pos; } else { // DC only - s->block_last_index[0] = 0; + w->block_last_index[0] = 0; if (w->flat_dc && ((unsigned) (dc_level + 1)) < 3) { // [-1; 1] int32_t divide_quant = !chroma ? w->divide_quant_dc_luma : w->divide_quant_dc_chroma; @@ -661,9 +658,9 @@ static int x8_decode_intra_mb(IntraX8Context *const w, const int chroma) zeros_only = (dc_level == 0); } if (!chroma) { - s->block[0][0] = dc_level * w->quant; + w->block[0][0] = dc_level * w->quant; } else { - s->block[0][0] = dc_level * w->quant_dc_chroma; + w->block[0][0] = dc_level * w->quant_dc_chroma; } // there is !zero_only check in the original, but dc_level check is enough @@ -674,7 +671,7 @@ static int x8_decode_intra_mb(IntraX8Context *const w, const int chroma) direction = (0x6A017C >> (w->orient * 2)) & 3; if (direction != 3) { // modify block_last[] - x8_ac_compensation(w, direction, s->block[0][0]); + x8_ac_compensation(w, direction, w->block[0][0]); } } @@ -689,7 +686,7 @@ static int x8_decode_intra_mb(IntraX8Context *const w, const int chroma) if (!zeros_only) w->idsp.idct_add(w->dest[chroma], w->frame->linesize[!!chroma], - s->block[0]); + w->block[0]); block_placed: if (!chroma) @@ -728,6 +725,8 @@ static void x8_init_block_index(IntraX8Context *w, AVFrame *frame) av_cold int ff_intrax8_common_init(AVCodecContext *avctx, IntraX8Context *w, IDCTDSPContext *idsp, + int16_t (*block)[64], + int block_last_index[12], int mb_width, int mb_height, MpegEncContext *const s) { @@ -741,6 +740,8 @@ av_cold int ff_intrax8_common_init(AVCodecContext *avctx, w->mb_y = 0; w->mb_width = mb_width; w->mb_height = mb_height; + w->block = block; + w->block_last_index = block_last_index; w->s = s; // two rows, 2 blocks per cannon mb diff --git a/libavcodec/intrax8.h b/libavcodec/intrax8.h index 39597cd..6e7549c 100644 --- a/libavcodec/intrax8.h +++ b/libavcodec/intrax8.h @@ -37,6 +37,8 @@ typedef struct IntraX8Context { uint8_t *prediction_table; // 2 * (mb_w * 2) ScanTable scantable[3]; AVCodecContext *avctx; + int *block_last_index; ///< last non zero coefficient in block + int16_t (*block)[64]; // set by the caller codec MpegEncContext *s; @@ -78,6 +80,8 @@ typedef struct IntraX8Context { * @param avctx pointer to AVCodecContext * @param w pointer to IntraX8Context * @param idsp pointer to IDCTDSPContext + * @param block pointer to the array of blocks + * @param block_last_index pointer to the array of indexes * @param mb_width macroblock width * @param mb_height macroblock height * @param s pointer to MpegEncContext of the parent codec @@ -85,6 +89,8 @@ typedef struct IntraX8Context { */ int ff_intrax8_common_init(AVCodecContext *avctx, IntraX8Context *w, IDCTDSPContext *idsp, + int16_t (*block)[64], + int block_last_index[12], int mb_width, int mb_height, MpegEncContext *const s); diff --git a/libavcodec/vc1dec.c b/libavcodec/vc1dec.c index b31089d..023e387 100644 --- a/libavcodec/vc1dec.c +++ b/libavcodec/vc1dec.c @@ -361,6 +361,7 @@ av_cold int ff_vc1_decode_init_alloc_tables(VC1Context *v) } ret = ff_intrax8_common_init(s->avctx, &v->x8, &s->idsp, + s->block, s->block_last_index, s->mb_width, s->mb_height, s); diff --git a/libavcodec/wmv2dec.c b/libavcodec/wmv2dec.c index a1620b0..9edfdd3 100644 --- a/libavcodec/wmv2dec.c +++ b/libavcodec/wmv2dec.c @@ -470,6 +470,7 @@ static av_cold int wmv2_decode_init(AVCodecContext *avctx) ff_wmv2_common_init(w); return ff_intrax8_common_init(avctx, &w->x8, &w->s.idsp, + w->s.block, w->s.block_last_index, w->s.mb_width, w->s.mb_height, &w->s); } -- 2.7.0 _______________________________________________ libav-devel mailing list libav-devel@libav.org https://lists.libav.org/mailman/listinfo/libav-devel