diff options
author | hkuang <hkuang@google.com> | 2013-11-14 22:50:46 -0800 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2013-11-14 22:50:46 -0800 |
commit | aa43d6ba5f5fb7eaeca1d0573ecb16ea4d388197 (patch) | |
tree | 6ff3bfc5090953c49fa26fac842b924d88e0983d /libvpx/vp9/encoder/vp9_encodeframe.c | |
parent | a1b7a7bb1ccf3f479bbca69a52a76eb05789dbaf (diff) | |
parent | 9b35249446b07f40ac5fcc3205f2c048616efacc (diff) | |
download | android_external_libvpx-aa43d6ba5f5fb7eaeca1d0573ecb16ea4d388197.tar.gz android_external_libvpx-aa43d6ba5f5fb7eaeca1d0573ecb16ea4d388197.tar.bz2 android_external_libvpx-aa43d6ba5f5fb7eaeca1d0573ecb16ea4d388197.zip |
am 9b352494: Roll latest libvpx to fix scalling bug. Checkout is from master:Ib748eb287520c794631697204da6ebe19523ce95
* commit '9b35249446b07f40ac5fcc3205f2c048616efacc':
Roll latest libvpx to fix scalling bug. Checkout is from master:Ib748eb287520c794631697204da6ebe19523ce95
Diffstat (limited to 'libvpx/vp9/encoder/vp9_encodeframe.c')
-rw-r--r-- | libvpx/vp9/encoder/vp9_encodeframe.c | 129 |
1 files changed, 75 insertions, 54 deletions
diff --git a/libvpx/vp9/encoder/vp9_encodeframe.c b/libvpx/vp9/encoder/vp9_encodeframe.c index a45299b..3e75f3b 100644 --- a/libvpx/vp9/encoder/vp9_encodeframe.c +++ b/libvpx/vp9/encoder/vp9_encodeframe.c @@ -50,25 +50,25 @@ int enc_debug = 0; #endif -static INLINE uint8_t *get_sb_index(MACROBLOCKD *xd, BLOCK_SIZE subsize) { +static INLINE uint8_t *get_sb_index(MACROBLOCK *x, BLOCK_SIZE subsize) { switch (subsize) { case BLOCK_64X64: case BLOCK_64X32: case BLOCK_32X64: case BLOCK_32X32: - return &xd->sb_index; + return &x->sb_index; case BLOCK_32X16: case BLOCK_16X32: case BLOCK_16X16: - return &xd->mb_index; + return &x->mb_index; case BLOCK_16X8: case BLOCK_8X16: case BLOCK_8X8: - return &xd->b_index; + return &x->b_index; case BLOCK_8X4: case BLOCK_4X8: case BLOCK_4X4: - return &xd->ab_index; + return &x->ab_index; default: assert(0); return NULL; @@ -367,6 +367,8 @@ static void update_state(VP9_COMP *cpi, PICK_MODE_CONTEXT *ctx, VP9_COMMON *const cm = &cpi->common; MACROBLOCK *const x = &cpi->mb; MACROBLOCKD *const xd = &x->e_mbd; + struct macroblock_plane *const p = x->plane; + struct macroblockd_plane *const pd = xd->plane; MODE_INFO *mi = &ctx->mic; MB_MODE_INFO *const mbmi = &xd->mi_8x8[0]->mbmi; MODE_INFO *mi_addr = xd->mi_8x8[0]; @@ -375,6 +377,7 @@ static void update_state(VP9_COMP *cpi, PICK_MODE_CONTEXT *ctx, const int mis = cm->mode_info_stride; const int mi_width = num_8x8_blocks_wide_lookup[bsize]; const int mi_height = num_8x8_blocks_high_lookup[bsize]; + int max_plane; assert(mi->mbmi.mode < MB_MODE_COUNT); assert(mi->mbmi.ref_frame[0] < MAX_REF_FRAMES); @@ -383,6 +386,21 @@ static void update_state(VP9_COMP *cpi, PICK_MODE_CONTEXT *ctx, *mi_addr = *mi; + max_plane = is_inter_block(mbmi) ? MAX_MB_PLANE : 1; + for (i = 0; i < max_plane; ++i) { + p[i].coeff = ctx->coeff_pbuf[i][1]; + pd[i].qcoeff = ctx->qcoeff_pbuf[i][1]; + pd[i].dqcoeff = ctx->dqcoeff_pbuf[i][1]; + pd[i].eobs = ctx->eobs_pbuf[i][1]; + } + + for (i = max_plane; i < MAX_MB_PLANE; ++i) { + p[i].coeff = ctx->coeff_pbuf[i][2]; + pd[i].qcoeff = ctx->qcoeff_pbuf[i][2]; + pd[i].dqcoeff = ctx->dqcoeff_pbuf[i][2]; + pd[i].eobs = ctx->eobs_pbuf[i][2]; + } + // Restore the coding context of the MB to that that was in place // when the mode was picked for it for (y = 0; y < mi_height; y++) @@ -578,6 +596,9 @@ static void pick_sb_modes(VP9_COMP *cpi, const TileInfo *const tile, VP9_COMMON *const cm = &cpi->common; MACROBLOCK *const x = &cpi->mb; MACROBLOCKD *const xd = &x->e_mbd; + struct macroblock_plane *const p = x->plane; + struct macroblockd_plane *const pd = xd->plane; + int i; int orig_rdmult = x->rdmult; double rdmult_ratio; @@ -590,7 +611,7 @@ static void pick_sb_modes(VP9_COMP *cpi, const TileInfo *const tile, if (bsize < BLOCK_8X8) { // When ab_index = 0 all sub-blocks are handled, so for ab_index != 0 // there is nothing to be done. - if (xd->ab_index != 0) { + if (x->ab_index != 0) { *totalrate = 0; *totaldist = 0; return; @@ -600,6 +621,15 @@ static void pick_sb_modes(VP9_COMP *cpi, const TileInfo *const tile, set_offsets(cpi, tile, mi_row, mi_col, bsize); xd->mi_8x8[0]->mbmi.sb_type = bsize; + for (i = 0; i < MAX_MB_PLANE; ++i) { + p[i].coeff = ctx->coeff_pbuf[i][0]; + pd[i].qcoeff = ctx->qcoeff_pbuf[i][0]; + pd[i].dqcoeff = ctx->dqcoeff_pbuf[i][0]; + pd[i].eobs = ctx->eobs_pbuf[i][0]; + } + ctx->is_coded = 0; + x->skip_recode = 0; + // Set to zero to make sure we do not use the previous encoded frame stats xd->mi_8x8[0]->mbmi.skip_coeff = 0; @@ -687,16 +717,15 @@ static void update_stats(VP9_COMP *cpi) { } static BLOCK_SIZE *get_sb_partitioning(MACROBLOCK *x, BLOCK_SIZE bsize) { - MACROBLOCKD *const xd = &x->e_mbd; switch (bsize) { case BLOCK_64X64: return &x->sb64_partitioning; case BLOCK_32X32: - return &x->sb_partitioning[xd->sb_index]; + return &x->sb_partitioning[x->sb_index]; case BLOCK_16X16: - return &x->mb_partitioning[xd->sb_index][xd->mb_index]; + return &x->mb_partitioning[x->sb_index][x->mb_index]; case BLOCK_8X8: - return &x->b_partitioning[xd->sb_index][xd->mb_index][xd->b_index]; + return &x->b_partitioning[x->sb_index][x->mb_index][x->b_index]; default: assert(0); return NULL; @@ -769,20 +798,19 @@ static void save_context(VP9_COMP *cpi, int mi_row, int mi_col, static void encode_b(VP9_COMP *cpi, const TileInfo *const tile, TOKENEXTRA **tp, int mi_row, int mi_col, int output_enabled, BLOCK_SIZE bsize, int sub_index) { - VP9_COMMON * const cm = &cpi->common; - MACROBLOCK * const x = &cpi->mb; - MACROBLOCKD * const xd = &x->e_mbd; + VP9_COMMON *const cm = &cpi->common; + MACROBLOCK *const x = &cpi->mb; if (mi_row >= cm->mi_rows || mi_col >= cm->mi_cols) return; if (sub_index != -1) - *get_sb_index(xd, bsize) = sub_index; + *get_sb_index(x, bsize) = sub_index; if (bsize < BLOCK_8X8) { // When ab_index = 0 all sub-blocks are handled, so for ab_index != 0 // there is nothing to be done. - if (xd->ab_index > 0) + if (x->ab_index > 0) return; } set_offsets(cpi, tile, mi_row, mi_col, bsize); @@ -800,9 +828,8 @@ static void encode_b(VP9_COMP *cpi, const TileInfo *const tile, static void encode_sb(VP9_COMP *cpi, const TileInfo *const tile, TOKENEXTRA **tp, int mi_row, int mi_col, int output_enabled, BLOCK_SIZE bsize) { - VP9_COMMON * const cm = &cpi->common; - MACROBLOCK * const x = &cpi->mb; - MACROBLOCKD * const xd = &x->e_mbd; + VP9_COMMON *const cm = &cpi->common; + MACROBLOCK *const x = &cpi->mb; BLOCK_SIZE c1 = BLOCK_8X8; const int bsl = b_width_log2(bsize), bs = (1 << bsl) / 4; int pl = 0; @@ -848,7 +875,7 @@ static void encode_sb(VP9_COMP *cpi, const TileInfo *const tile, for (i = 0; i < 4; i++) { const int x_idx = i & 1, y_idx = i >> 1; - *get_sb_index(xd, subsize) = i; + *get_sb_index(x, subsize) = i; encode_sb(cpi, tile, tp, mi_row + y_idx * bs, mi_col + x_idx * bs, output_enabled, subsize); } @@ -975,9 +1002,8 @@ static void rd_use_partition(VP9_COMP *cpi, TOKENEXTRA **tp, int mi_row, int mi_col, BLOCK_SIZE bsize, int *rate, int64_t *dist, int do_recon) { - VP9_COMMON * const cm = &cpi->common; - MACROBLOCK * const x = &cpi->mb; - MACROBLOCKD *xd = &cpi->mb.e_mbd; + VP9_COMMON *const cm = &cpi->common; + MACROBLOCK *const x = &cpi->mb; const int mis = cm->mode_info_stride; int bsl = b_width_log2(bsize); const int num_4x4_blocks_wide = num_4x4_blocks_wide_lookup[bsize]; @@ -1012,7 +1038,7 @@ static void rd_use_partition(VP9_COMP *cpi, if (bsize < BLOCK_8X8) { // When ab_index = 0 all sub-blocks are handled, so for ab_index != 0 // there is nothing to be done. - if (xd->ab_index != 0) { + if (x->ab_index != 0) { *rate = 0; *dist = 0; return; @@ -1070,7 +1096,7 @@ static void rd_use_partition(VP9_COMP *cpi, bsize, get_block_context(x, bsize), INT64_MAX); break; case PARTITION_HORZ: - *get_sb_index(xd, subsize) = 0; + *get_sb_index(x, subsize) = 0; pick_sb_modes(cpi, tile, mi_row, mi_col, &last_part_rate, &last_part_dist, subsize, get_block_context(x, subsize), INT64_MAX); if (last_part_rate != INT_MAX && @@ -1079,7 +1105,7 @@ static void rd_use_partition(VP9_COMP *cpi, int64_t dt = 0; update_state(cpi, get_block_context(x, subsize), subsize, 0); encode_superblock(cpi, tp, 0, mi_row, mi_col, subsize); - *get_sb_index(xd, subsize) = 1; + *get_sb_index(x, subsize) = 1; pick_sb_modes(cpi, tile, mi_row + (ms >> 1), mi_col, &rt, &dt, subsize, get_block_context(x, subsize), INT64_MAX); if (rt == INT_MAX || dt == INT_MAX) { @@ -1093,7 +1119,7 @@ static void rd_use_partition(VP9_COMP *cpi, } break; case PARTITION_VERT: - *get_sb_index(xd, subsize) = 0; + *get_sb_index(x, subsize) = 0; pick_sb_modes(cpi, tile, mi_row, mi_col, &last_part_rate, &last_part_dist, subsize, get_block_context(x, subsize), INT64_MAX); if (last_part_rate != INT_MAX && @@ -1102,7 +1128,7 @@ static void rd_use_partition(VP9_COMP *cpi, int64_t dt = 0; update_state(cpi, get_block_context(x, subsize), subsize, 0); encode_superblock(cpi, tp, 0, mi_row, mi_col, subsize); - *get_sb_index(xd, subsize) = 1; + *get_sb_index(x, subsize) = 1; pick_sb_modes(cpi, tile, mi_row, mi_col + (ms >> 1), &rt, &dt, subsize, get_block_context(x, subsize), INT64_MAX); if (rt == INT_MAX || dt == INT_MAX) { @@ -1128,7 +1154,7 @@ static void rd_use_partition(VP9_COMP *cpi, if ((mi_row + y_idx >= cm->mi_rows) || (mi_col + x_idx >= cm->mi_cols)) continue; - *get_sb_index(xd, subsize) = i; + *get_sb_index(x, subsize) = i; rd_use_partition(cpi, tile, mi_8x8 + jj * bss * mis + ii * bss, tp, mi_row + y_idx, mi_col + x_idx, subsize, &rt, &dt, @@ -1169,11 +1195,10 @@ static void rd_use_partition(VP9_COMP *cpi, ENTROPY_CONTEXT l[16 * MAX_MB_PLANE], a[16 * MAX_MB_PLANE]; PARTITION_CONTEXT sl[8], sa[8]; - if ((mi_row + y_idx >= cm->mi_rows) - || (mi_col + x_idx >= cm->mi_cols)) + if ((mi_row + y_idx >= cm->mi_rows) || (mi_col + x_idx >= cm->mi_cols)) continue; - *get_sb_index(xd, split_subsize) = i; + *get_sb_index(x, split_subsize) = i; *get_sb_partitioning(x, bsize) = split_subsize; *get_sb_partitioning(x, split_subsize) = split_subsize; @@ -1353,7 +1378,6 @@ static void rd_auto_partition_range(VP9_COMP *cpi, const TileInfo *const tile, static void compute_fast_motion_search_level(VP9_COMP *cpi, BLOCK_SIZE bsize) { VP9_COMMON *const cm = &cpi->common; MACROBLOCK *const x = &cpi->mb; - MACROBLOCKD *const xd = &x->e_mbd; // Only use 8x8 result for non HD videos. // int use_8x8 = (MIN(cpi->common.width, cpi->common.height) < 720) ? 1 : 0; @@ -1366,9 +1390,9 @@ static void compute_fast_motion_search_level(VP9_COMP *cpi, BLOCK_SIZE bsize) { PICK_MODE_CONTEXT *block_context = NULL; if (bsize == BLOCK_16X16) { - block_context = x->sb8x8_context[xd->sb_index][xd->mb_index]; + block_context = x->sb8x8_context[x->sb_index][x->mb_index]; } else if (bsize == BLOCK_32X32) { - block_context = x->mb_context[xd->sb_index]; + block_context = x->mb_context[x->sb_index]; } else if (bsize == BLOCK_64X64) { block_context = x->sb32_context; } @@ -1456,9 +1480,8 @@ static void rd_pick_partition(VP9_COMP *cpi, const TileInfo *const tile, TOKENEXTRA **tp, int mi_row, int mi_col, BLOCK_SIZE bsize, int *rate, int64_t *dist, int do_recon, int64_t best_rd) { - VP9_COMMON * const cm = &cpi->common; - MACROBLOCK * const x = &cpi->mb; - MACROBLOCKD * const xd = &x->e_mbd; + VP9_COMMON *const cm = &cpi->common; + MACROBLOCK *const x = &cpi->mb; const int ms = num_8x8_blocks_wide_lookup[bsize] / 2; ENTROPY_CONTEXT l[16 * MAX_MB_PLANE], a[16 * MAX_MB_PLANE]; PARTITION_CONTEXT sl[8], sa[8]; @@ -1484,7 +1507,7 @@ static void rd_pick_partition(VP9_COMP *cpi, const TileInfo *const tile, if (bsize < BLOCK_8X8) { // When ab_index = 0 all sub-blocks are handled, so for ab_index != 0 // there is nothing to be done. - if (xd->ab_index != 0) { + if (x->ab_index != 0) { *rate = 0; *dist = 0; return; @@ -1582,7 +1605,7 @@ static void rd_pick_partition(VP9_COMP *cpi, const TileInfo *const tile, if (mi_row + y_idx >= cm->mi_rows || mi_col + x_idx >= cm->mi_cols) continue; - *get_sb_index(xd, subsize) = i; + *get_sb_index(x, subsize) = i; if (cpi->sf.adaptive_motion_search) load_pred_mv(x, get_block_context(x, bsize)); rd_pick_partition(cpi, tile, tp, mi_row + y_idx, mi_col + x_idx, subsize, @@ -1629,7 +1652,7 @@ static void rd_pick_partition(VP9_COMP *cpi, const TileInfo *const tile, // PARTITION_HORZ if (partition_horz_allowed && do_rect) { subsize = get_subsize(bsize, PARTITION_HORZ); - *get_sb_index(xd, subsize) = 0; + *get_sb_index(x, subsize) = 0; if (cpi->sf.adaptive_motion_search) load_pred_mv(x, get_block_context(x, bsize)); pick_sb_modes(cpi, tile, mi_row, mi_col, &sum_rate, &sum_dist, subsize, @@ -1640,7 +1663,7 @@ static void rd_pick_partition(VP9_COMP *cpi, const TileInfo *const tile, update_state(cpi, get_block_context(x, subsize), subsize, 0); encode_superblock(cpi, tp, 0, mi_row, mi_col, subsize); - *get_sb_index(xd, subsize) = 1; + *get_sb_index(x, subsize) = 1; if (cpi->sf.adaptive_motion_search) load_pred_mv(x, get_block_context(x, bsize)); pick_sb_modes(cpi, tile, mi_row + ms, mi_col, &this_rate, @@ -1674,7 +1697,7 @@ static void rd_pick_partition(VP9_COMP *cpi, const TileInfo *const tile, if (partition_vert_allowed && do_rect) { subsize = get_subsize(bsize, PARTITION_VERT); - *get_sb_index(xd, subsize) = 0; + *get_sb_index(x, subsize) = 0; if (cpi->sf.adaptive_motion_search) load_pred_mv(x, get_block_context(x, bsize)); pick_sb_modes(cpi, tile, mi_row, mi_col, &sum_rate, &sum_dist, subsize, @@ -1684,7 +1707,7 @@ static void rd_pick_partition(VP9_COMP *cpi, const TileInfo *const tile, update_state(cpi, get_block_context(x, subsize), subsize, 0); encode_superblock(cpi, tp, 0, mi_row, mi_col, subsize); - *get_sb_index(xd, subsize) = 1; + *get_sb_index(x, subsize) = 1; if (cpi->sf.adaptive_motion_search) load_pred_mv(x, get_block_context(x, bsize)); pick_sb_modes(cpi, tile, mi_row, mi_col + ms, &this_rate, @@ -1765,7 +1788,7 @@ static void rd_pick_reference_frame(VP9_COMP *cpi, const TileInfo *const tile, } static void encode_sb_row(VP9_COMP *cpi, const TileInfo *const tile, - int mi_row, TOKENEXTRA **tp, int *totalrate) { + int mi_row, TOKENEXTRA **tp) { VP9_COMMON * const cm = &cpi->common; int mi_col; @@ -1910,7 +1933,6 @@ static void encode_frame_internal(VP9_COMP *cpi) { MACROBLOCK * const x = &cpi->mb; VP9_COMMON * const cm = &cpi->common; MACROBLOCKD * const xd = &x->e_mbd; - int totalrate; // fprintf(stderr, "encode_frame_internal frame %d (%d) type %d\n", // cpi->common.current_video_frame, cpi->common.show_frame, @@ -1926,8 +1948,6 @@ static void encode_frame_internal(VP9_COMP *cpi) { } #endif - totalrate = 0; - vp9_zero(cm->counts.switchable_interp); vp9_zero(cpi->tx_stepdown_count); @@ -1989,7 +2009,7 @@ static void encode_frame_internal(VP9_COMP *cpi) { vp9_tile_init(&tile, cm, tile_row, tile_col); for (mi_row = tile.mi_row_start; mi_row < tile.mi_row_end; mi_row += 8) - encode_sb_row(cpi, &tile, mi_row, &tp, &totalrate); + encode_sb_row(cpi, &tile, mi_row, &tp); cpi->tok_count[tile_row][tile_col] = (unsigned int)(tp - tp_old); assert(tp - cpi->tok <= get_token_alloc(cm->mb_rows, cm->mb_cols)); @@ -2015,10 +2035,6 @@ static void encode_frame_internal(VP9_COMP *cpi) { cpi->sf.skip_encode_frame = 0; } - // 256 rate units to the bit, - // projected_frame_size in units of BYTES - cpi->projected_frame_size = totalrate >> 8; - #if 0 // Keep record of the total distortion this time around for future use cpi->last_frame_distortion = cpi->frame_distortion; @@ -2395,13 +2411,17 @@ static void encode_superblock(VP9_COMP *cpi, TOKENEXTRA **t, int output_enabled, MODE_INFO **mi_8x8 = xd->mi_8x8; MODE_INFO *mi = mi_8x8[0]; MB_MODE_INFO *mbmi = &mi->mbmi; + PICK_MODE_CONTEXT *ctx = get_block_context(x, bsize); unsigned int segment_id = mbmi->segment_id; const int mis = cm->mode_info_stride; const int mi_width = num_8x8_blocks_wide_lookup[bsize]; const int mi_height = num_8x8_blocks_high_lookup[bsize]; + x->skip_recode = !x->select_txfm_size && mbmi->sb_type >= BLOCK_8X8; + x->skip_optimize = ctx->is_coded; + ctx->is_coded = 1; x->use_lp32x32fdct = cpi->sf.use_lp32x32fdct; x->skip_encode = (!output_enabled && cpi->sf.skip_encode_frame && - xd->q_index < QIDX_SKIP_THRESH); + x->q_index < QIDX_SKIP_THRESH); if (x->skip_encode) return; @@ -2487,7 +2507,8 @@ static void encode_superblock(VP9_COMP *cpi, TOKENEXTRA **t, int output_enabled, (mbmi->skip_coeff || vp9_segfeature_active(&cm->seg, segment_id, SEG_LVL_SKIP)))) { const uint8_t context = vp9_get_pred_context_tx_size(xd); - ++get_tx_counts(bsize, context, &cm->counts.tx)[mbmi->tx_size]; + ++get_tx_counts(max_txsize_lookup[bsize], + context, &cm->counts.tx)[mbmi->tx_size]; } else { int x, y; TX_SIZE sz = tx_mode_to_biggest_tx_size[cm->tx_mode]; |