From 7ee44eef13012a3163052dcd56b3197835cee2c8 Mon Sep 17 00:00:00 2001 From: Scott LaVarnway Date: Fri, 2 Nov 2012 16:04:52 -0700 Subject: [PATCH] Moving coef_counts to macroblock struct Change-Id: I289564a5a27f0d03ddc6f19c7838542ff22719be --- vp8/encoder/bitstream.c | 6 ++- vp8/encoder/block.h | 1 + vp8/encoder/encodeframe.c | 42 +++++++++++++++++-- vp8/encoder/ethreading.c | 2 + vp8/encoder/onyx_int.h | 4 +- vp8/encoder/tokenize.c | 100 ++++++++++++++++++++++++---------------------- 6 files changed, 99 insertions(+), 56 deletions(-) diff --git a/vp8/encoder/bitstream.c b/vp8/encoder/bitstream.c index 2799143..cc8f439 100644 --- a/vp8/encoder/bitstream.c +++ b/vp8/encoder/bitstream.c @@ -851,6 +851,7 @@ static int prob_update_savings(const unsigned int *ct, static int independent_coef_context_savings(VP8_COMP *cpi) { + MACROBLOCK *const x = & cpi->mb; int savings = 0; int i = 0; do @@ -867,7 +868,7 @@ static int independent_coef_context_savings(VP8_COMP *cpi) */ probs = (const unsigned int (*)[MAX_ENTROPY_TOKENS]) - cpi->coef_counts[i][j]; + x->coef_counts[i][j]; /* Reset to default probabilities at key frames */ if (cpi->common.frame_type == KEY_FRAME) @@ -926,6 +927,7 @@ static int independent_coef_context_savings(VP8_COMP *cpi) static int default_coef_context_savings(VP8_COMP *cpi) { + MACROBLOCK *const x = & cpi->mb; int savings = 0; int i = 0; do @@ -945,7 +947,7 @@ static int default_coef_context_savings(VP8_COMP *cpi) MAX_ENTROPY_TOKENS, vp8_coef_encodings, vp8_coef_tree, cpi->frame_coef_probs [i][j][k], cpi->frame_branch_ct [i][j][k], - cpi->coef_counts [i][j][k], + x->coef_counts [i][j][k], 256, 1 ); diff --git a/vp8/encoder/block.h b/vp8/encoder/block.h index 0b0a234..ec316ea 100644 --- a/vp8/encoder/block.h +++ b/vp8/encoder/block.h @@ -127,6 +127,7 @@ typedef struct macroblock unsigned char need_to_clamp_best_mvs; #endif + unsigned int coef_counts [BLOCK_TYPES] [COEF_BANDS] [PREV_COEF_CONTEXTS] [MAX_ENTROPY_TOKENS]; void (*short_fdct4x4)(short *input, short *output, int pitch); diff --git a/vp8/encoder/encodeframe.c b/vp8/encoder/encodeframe.c index 333e7d9..e3e7d9d 100644 --- a/vp8/encoder/encodeframe.c +++ b/vp8/encoder/encodeframe.c @@ -674,6 +674,38 @@ static void init_encode_frame_mb_context(VP8_COMP *cpi) xd->fullpixel_mask = 0xffffffff; if(cm->full_pixel) xd->fullpixel_mask = 0xfffffff8; + + vp8_zero(x->coef_counts); +} + +static void sum_coef_counts(MACROBLOCK *x, MACROBLOCK *x_thread) +{ + int i = 0; + do + { + int j = 0; + do + { + int k = 0; + do + { + /* at every context */ + + /* calc probs and branch cts for this frame only */ + int t = 0; /* token/prob index */ + + do + { + x->coef_counts [i][j][k][t] += + x_thread->coef_counts [i][j][k][t]; + } + while (++t < ENTROPY_NODES); + } + while (++k < PREV_COEF_CONTEXTS); + } + while (++j < COEF_BANDS); + } + while (++i < BLOCK_TYPES); } void vp8_encode_frame(VP8_COMP *cpi) @@ -732,8 +764,6 @@ void vp8_encode_frame(VP8_COMP *cpi) vp8_zero(cpi->MVcount); - vp8_zero(cpi->coef_counts); - vp8cx_frame_init_quantizer(cpi); vp8_initialize_rd_consts(cpi, @@ -838,12 +868,16 @@ void vp8_encode_frame(VP8_COMP *cpi) for (i = 0; i < cpi->encoding_thread_count; i++) { totalrate += cpi->mb_row_ei[i].totalrate; + + /* add up counts for each thread */ + sum_coef_counts(x, &cpi->mb_row_ei[i].mb); } } else #endif { + /* for each macroblock row in image */ for (mb_row = 0; mb_row < cm->mb_rows; mb_row++) { @@ -1119,7 +1153,7 @@ int vp8cx_encode_intra_macroblock(VP8_COMP *cpi, MACROBLOCK *x, sum_intra_stats(cpi, x); - vp8_tokenize_mb(cpi, &x->e_mbd, t); + vp8_tokenize_mb(cpi, x, t); if (xd->mode_info_context->mbmi.mode != B_PRED) vp8_inverse_transform_mby(xd); @@ -1305,7 +1339,7 @@ int vp8cx_encode_inter_macroblock if (!x->skip) { - vp8_tokenize_mb(cpi, xd, t); + vp8_tokenize_mb(cpi, x, t); if (xd->mode_info_context->mbmi.mode != B_PRED) vp8_inverse_transform_mby(xd); diff --git a/vp8/encoder/ethreading.c b/vp8/encoder/ethreading.c index cff982d..fc47248 100644 --- a/vp8/encoder/ethreading.c +++ b/vp8/encoder/ethreading.c @@ -471,6 +471,8 @@ void vp8cx_init_mbrthread_data(VP8_COMP *cpi, mbd->fullpixel_mask = 0xffffffff; if(cm->full_pixel) mbd->fullpixel_mask = 0xfffffff8; + + vp8_zero(mb->coef_counts); } } diff --git a/vp8/encoder/onyx_int.h b/vp8/encoder/onyx_int.h index 3f1fad6..72d96b5 100644 --- a/vp8/encoder/onyx_int.h +++ b/vp8/encoder/onyx_int.h @@ -457,8 +457,6 @@ typedef struct VP8_COMP unsigned int MVcount [2] [MVvals]; /* (row,col) MV cts this frame */ - unsigned int coef_counts [BLOCK_TYPES] [COEF_BANDS] [PREV_COEF_CONTEXTS] [MAX_ENTROPY_TOKENS]; /* for this frame */ - vp8_prob frame_coef_probs [BLOCK_TYPES] [COEF_BANDS] [PREV_COEF_CONTEXTS] [ENTROPY_NODES]; char update_probs [BLOCK_TYPES] [COEF_BANDS] [PREV_COEF_CONTEXTS] [ENTROPY_NODES]; @@ -729,7 +727,7 @@ void vp8_pack_bitstream(VP8_COMP *cpi, unsigned char *dest, unsigned char *dest_ int rd_cost_intra_mb(MACROBLOCKD *x); -void vp8_tokenize_mb(VP8_COMP *, MACROBLOCKD *, TOKENEXTRA **); +void vp8_tokenize_mb(VP8_COMP *, MACROBLOCK *, TOKENEXTRA **); void vp8_set_speed_features(VP8_COMP *cpi); diff --git a/vp8/encoder/tokenize.c b/vp8/encoder/tokenize.c index ef41fa8..90463ef 100644 --- a/vp8/encoder/tokenize.c +++ b/vp8/encoder/tokenize.c @@ -23,7 +23,7 @@ #ifdef ENTROPY_STATS _int64 context_counters[BLOCK_TYPES] [COEF_BANDS] [PREV_COEF_CONTEXTS] [MAX_ENTROPY_TOKENS]; #endif -void vp8_stuff_mb(VP8_COMP *cpi, MACROBLOCKD *x, TOKENEXTRA **t) ; +void vp8_stuff_mb(VP8_COMP *cpi, MACROBLOCK *x, TOKENEXTRA **t) ; void vp8_fix_contexts(MACROBLOCKD *x); #include "dct_value_tokens.h" @@ -102,11 +102,12 @@ static void fill_value_tokens() static void tokenize2nd_order_b ( - MACROBLOCKD *x, + MACROBLOCK *x, TOKENEXTRA **tp, VP8_COMP *cpi ) { + MACROBLOCKD *xd = &x->e_mbd; int pt; /* near block/prev token context index */ int c; /* start at DC */ TOKENEXTRA *t = *tp;/* store tokens starting here */ @@ -117,11 +118,11 @@ static void tokenize2nd_order_b int band, rc, v, token; int eob; - b = x->block + 24; + b = xd->block + 24; qcoeff_ptr = b->qcoeff; - a = (ENTROPY_CONTEXT *)x->above_context + 8; - l = (ENTROPY_CONTEXT *)x->left_context + 8; - eob = x->eobs[24]; + a = (ENTROPY_CONTEXT *)xd->above_context + 8; + l = (ENTROPY_CONTEXT *)xd->left_context + 8; + eob = xd->eobs[24]; VP8_COMBINEENTROPYCONTEXTS(pt, *a, *l); if(!eob) @@ -131,7 +132,7 @@ static void tokenize2nd_order_b t->context_tree = cpi->common.fc.coef_probs [1] [0] [pt]; t->skip_eob_node = 0; - ++cpi->coef_counts [1] [0] [pt] [DCT_EOB_TOKEN]; + ++x->coef_counts [1] [0] [pt] [DCT_EOB_TOKEN]; t++; *tp = t; *a = *l = 0; @@ -145,7 +146,7 @@ static void tokenize2nd_order_b t->context_tree = cpi->common.fc.coef_probs [1] [0] [pt]; t->skip_eob_node = 0; - ++cpi->coef_counts [1] [0] [pt] [token]; + ++x->coef_counts [1] [0] [pt] [token]; pt = vp8_prev_token_class[token]; t++; c = 1; @@ -164,7 +165,7 @@ static void tokenize2nd_order_b t->skip_eob_node = ((pt == 0)); - ++cpi->coef_counts [1] [band] [pt] [token]; + ++x->coef_counts [1] [band] [pt] [token]; pt = vp8_prev_token_class[token]; t++; @@ -177,7 +178,7 @@ static void tokenize2nd_order_b t->skip_eob_node = 0; - ++cpi->coef_counts [1] [band] [pt] [DCT_EOB_TOKEN]; + ++x->coef_counts [1] [band] [pt] [DCT_EOB_TOKEN]; t++; } @@ -189,12 +190,13 @@ static void tokenize2nd_order_b static void tokenize1st_order_b ( - MACROBLOCKD *x, + MACROBLOCK *x, TOKENEXTRA **tp, int type, /* which plane: 0=Y no DC, 1=Y2, 2=UV, 3=Y with DC */ VP8_COMP *cpi ) { + MACROBLOCKD *xd = &x->e_mbd; unsigned int block; const BLOCKD *b; int pt; /* near block/prev token context index */ @@ -207,15 +209,15 @@ static void tokenize1st_order_b int band, rc, v; int tmp1, tmp2; - b = x->block; + b = xd->block; /* Luma */ for (block = 0; block < 16; block++, b++) { tmp1 = vp8_block2above[block]; tmp2 = vp8_block2left[block]; qcoeff_ptr = b->qcoeff; - a = (ENTROPY_CONTEXT *)x->above_context + tmp1; - l = (ENTROPY_CONTEXT *)x->left_context + tmp2; + a = (ENTROPY_CONTEXT *)xd->above_context + tmp1; + l = (ENTROPY_CONTEXT *)xd->left_context + tmp2; VP8_COMBINEENTROPYCONTEXTS(pt, *a, *l); @@ -228,7 +230,7 @@ static void tokenize1st_order_b t->context_tree = cpi->common.fc.coef_probs [type] [c] [pt]; t->skip_eob_node = 0; - ++cpi->coef_counts [type] [c] [pt] [DCT_EOB_TOKEN]; + ++x->coef_counts [type] [c] [pt] [DCT_EOB_TOKEN]; t++; *tp = t; *a = *l = 0; @@ -243,7 +245,7 @@ static void tokenize1st_order_b t->context_tree = cpi->common.fc.coef_probs [type] [c] [pt]; t->skip_eob_node = 0; - ++cpi->coef_counts [type] [c] [pt] [token]; + ++x->coef_counts [type] [c] [pt] [token]; pt = vp8_prev_token_class[token]; t++; c++; @@ -261,7 +263,7 @@ static void tokenize1st_order_b t->context_tree = cpi->common.fc.coef_probs [type] [band] [pt]; t->skip_eob_node = (pt == 0); - ++cpi->coef_counts [type] [band] [pt] [token]; + ++x->coef_counts [type] [band] [pt] [token]; pt = vp8_prev_token_class[token]; t++; @@ -273,7 +275,7 @@ static void tokenize1st_order_b t->context_tree = cpi->common.fc.coef_probs [type] [band] [pt]; t->skip_eob_node = 0; - ++cpi->coef_counts [type] [band] [pt] [DCT_EOB_TOKEN]; + ++x->coef_counts [type] [band] [pt] [DCT_EOB_TOKEN]; t++; } @@ -287,8 +289,8 @@ static void tokenize1st_order_b tmp1 = vp8_block2above[block]; tmp2 = vp8_block2left[block]; qcoeff_ptr = b->qcoeff; - a = (ENTROPY_CONTEXT *)x->above_context + tmp1; - l = (ENTROPY_CONTEXT *)x->left_context + tmp2; + a = (ENTROPY_CONTEXT *)xd->above_context + tmp1; + l = (ENTROPY_CONTEXT *)xd->left_context + tmp2; VP8_COMBINEENTROPYCONTEXTS(pt, *a, *l); @@ -299,7 +301,7 @@ static void tokenize1st_order_b t->context_tree = cpi->common.fc.coef_probs [2] [0] [pt]; t->skip_eob_node = 0; - ++cpi->coef_counts [2] [0] [pt] [DCT_EOB_TOKEN]; + ++x->coef_counts [2] [0] [pt] [DCT_EOB_TOKEN]; t++; *tp = t; *a = *l = 0; @@ -314,7 +316,7 @@ static void tokenize1st_order_b t->context_tree = cpi->common.fc.coef_probs [2] [0] [pt]; t->skip_eob_node = 0; - ++cpi->coef_counts [2] [0] [pt] [token]; + ++x->coef_counts [2] [0] [pt] [token]; pt = vp8_prev_token_class[token]; t++; c = 1; @@ -333,7 +335,7 @@ static void tokenize1st_order_b t->skip_eob_node = (pt == 0); - ++cpi->coef_counts [2] [band] [pt] [token]; + ++x->coef_counts [2] [band] [pt] [token]; pt = vp8_prev_token_class[token]; t++; @@ -346,7 +348,7 @@ static void tokenize1st_order_b t->skip_eob_node = 0; - ++cpi->coef_counts [2] [band] [pt] [DCT_EOB_TOKEN]; + ++x->coef_counts [2] [band] [pt] [DCT_EOB_TOKEN]; t++; } @@ -374,16 +376,18 @@ static int mb_is_skippable(MACROBLOCKD *x, int has_y2_block) } -void vp8_tokenize_mb(VP8_COMP *cpi, MACROBLOCKD *x, TOKENEXTRA **t) +void vp8_tokenize_mb(VP8_COMP *cpi, MACROBLOCK *x, TOKENEXTRA **t) { + MACROBLOCKD *xd = &x->e_mbd; int plane_type; int has_y2_block; - has_y2_block = (x->mode_info_context->mbmi.mode != B_PRED - && x->mode_info_context->mbmi.mode != SPLITMV); + has_y2_block = (xd->mode_info_context->mbmi.mode != B_PRED + && xd->mode_info_context->mbmi.mode != SPLITMV); - x->mode_info_context->mbmi.mb_skip_coeff = mb_is_skippable(x, has_y2_block); - if (x->mode_info_context->mbmi.mb_skip_coeff) + xd->mode_info_context->mbmi.mb_skip_coeff = + mb_is_skippable(xd, has_y2_block); + if (xd->mode_info_context->mbmi.mb_skip_coeff) { if (!cpi->common.mb_no_coeff_skip) { @@ -391,7 +395,7 @@ void vp8_tokenize_mb(VP8_COMP *cpi, MACROBLOCKD *x, TOKENEXTRA **t) } else { - vp8_fix_contexts(x); + vp8_fix_contexts(xd); cpi->skip_true_count++; } @@ -488,7 +492,8 @@ static void stuff2nd_order_b TOKENEXTRA **tp, ENTROPY_CONTEXT *a, ENTROPY_CONTEXT *l, - VP8_COMP *cpi + VP8_COMP *cpi, + MACROBLOCK *x ) { int pt; /* near block/prev token context index */ @@ -498,13 +503,12 @@ static void stuff2nd_order_b t->Token = DCT_EOB_TOKEN; t->context_tree = cpi->common.fc.coef_probs [1] [0] [pt]; t->skip_eob_node = 0; - ++cpi->coef_counts [1] [0] [pt] [DCT_EOB_TOKEN]; + ++x->coef_counts [1] [0] [pt] [DCT_EOB_TOKEN]; ++t; *tp = t; pt = 0; *a = *l = pt; - } static void stuff1st_order_b @@ -513,7 +517,8 @@ static void stuff1st_order_b ENTROPY_CONTEXT *a, ENTROPY_CONTEXT *l, int type, - VP8_COMP *cpi + VP8_COMP *cpi, + MACROBLOCK *x ) { int pt; /* near block/prev token context index */ @@ -524,20 +529,21 @@ static void stuff1st_order_b t->Token = DCT_EOB_TOKEN; t->context_tree = cpi->common.fc.coef_probs [type] [band] [pt]; t->skip_eob_node = 0; - ++cpi->coef_counts [type] [band] [pt] [DCT_EOB_TOKEN]; + ++x->coef_counts [type] [band] [pt] [DCT_EOB_TOKEN]; ++t; *tp = t; pt = 0; /* 0 <-> all coeff data is zero */ *a = *l = pt; - } + static void stuff1st_order_buv ( TOKENEXTRA **tp, ENTROPY_CONTEXT *a, ENTROPY_CONTEXT *l, - VP8_COMP *cpi + VP8_COMP *cpi, + MACROBLOCK *x ) { int pt; /* near block/prev token context index */ @@ -547,38 +553,38 @@ void stuff1st_order_buv t->Token = DCT_EOB_TOKEN; t->context_tree = cpi->common.fc.coef_probs [2] [0] [pt]; t->skip_eob_node = 0; - ++cpi->coef_counts[2] [0] [pt] [DCT_EOB_TOKEN]; + ++x->coef_counts[2] [0] [pt] [DCT_EOB_TOKEN]; ++t; *tp = t; pt = 0; /* 0 <-> all coeff data is zero */ *a = *l = pt; - } -void vp8_stuff_mb(VP8_COMP *cpi, MACROBLOCKD *x, TOKENEXTRA **t) +void vp8_stuff_mb(VP8_COMP *cpi, MACROBLOCK *x, TOKENEXTRA **t) { - ENTROPY_CONTEXT * A = (ENTROPY_CONTEXT *)x->above_context; - ENTROPY_CONTEXT * L = (ENTROPY_CONTEXT *)x->left_context; + MACROBLOCKD *xd = &x->e_mbd; + ENTROPY_CONTEXT * A = (ENTROPY_CONTEXT *)xd->above_context; + ENTROPY_CONTEXT * L = (ENTROPY_CONTEXT *)xd->left_context; int plane_type; int b; plane_type = 3; - if((x->mode_info_context->mbmi.mode != B_PRED - && x->mode_info_context->mbmi.mode != SPLITMV)) + if((xd->mode_info_context->mbmi.mode != B_PRED + && xd->mode_info_context->mbmi.mode != SPLITMV)) { stuff2nd_order_b(t, - A + vp8_block2above[24], L + vp8_block2left[24], cpi); + A + vp8_block2above[24], L + vp8_block2left[24], cpi, x); plane_type = 0; } for (b = 0; b < 16; b++) stuff1st_order_b(t, A + vp8_block2above[b], - L + vp8_block2left[b], plane_type, cpi); + L + vp8_block2left[b], plane_type, cpi, x); for (b = 16; b < 24; b++) stuff1st_order_buv(t, A + vp8_block2above[b], - L + vp8_block2left[b], cpi); + L + vp8_block2left[b], cpi, x); } void vp8_fix_contexts(MACROBLOCKD *x) -- 2.7.4