diff options
Diffstat (limited to 'vp9/encoder/vp9_encodeframe.c')
-rw-r--r-- | vp9/encoder/vp9_encodeframe.c | 101 |
1 files changed, 72 insertions, 29 deletions
diff --git a/vp9/encoder/vp9_encodeframe.c b/vp9/encoder/vp9_encodeframe.c index f529c9336..a9b51e0d4 100644 --- a/vp9/encoder/vp9_encodeframe.c +++ b/vp9/encoder/vp9_encodeframe.c @@ -102,6 +102,24 @@ static unsigned int get_sby_perpixel_variance(VP9_COMP *cpi, MACROBLOCK *x, return ROUND_POWER_OF_TWO(var, num_pels_log2_lookup[bs]); } +static BLOCK_SIZE get_rd_var_based_fixed_partition(VP9_COMP *cpi) { + unsigned int var = get_sby_perpixel_variance(cpi, &cpi->mb, BLOCK_64X64); + if (var < 256) + return BLOCK_64X64; + else + return BLOCK_32X32; +} + +static BLOCK_SIZE get_nonrd_var_based_fixed_partition(VP9_COMP *cpi) { + unsigned int var = get_sby_perpixel_variance(cpi, &cpi->mb, BLOCK_64X64); + if (var < 1024) + return BLOCK_32X32; + else if (var < 4096) + return BLOCK_16X16; + else + return BLOCK_8X8; +} + // Original activity measure from Tim T's code. static unsigned int tt_activity_measure(MACROBLOCK *x) { unsigned int sse; @@ -994,7 +1012,7 @@ static void set_partitioning(VP9_COMP *cpi, const TileInfo *const tile, for (block_col = 0; block_col < MI_BLOCK_SIZE; block_col += bw) { int index = block_row * mis + block_col; // Find a partition size that fits - bsize = find_partition_size(cpi->sf.always_this_block_size, + bsize = find_partition_size(bsize, (row8x8_remaining - block_row), (col8x8_remaining - block_col), &bh, &bw); mi_8x8[index] = mi_upper_left + index; @@ -1914,8 +1932,8 @@ static void rd_pick_partition(VP9_COMP *cpi, const TileInfo *const tile, } } -static void encode_sb_row(VP9_COMP *cpi, const TileInfo *const tile, - int mi_row, TOKENEXTRA **tp) { +static void encode_rd_sb_row(VP9_COMP *cpi, const TileInfo *const tile, + int mi_row, TOKENEXTRA **tp) { VP9_COMMON *const cm = &cpi->common; int mi_col; @@ -1946,19 +1964,32 @@ static void encode_sb_row(VP9_COMP *cpi, const TileInfo *const tile, vp9_zero(cpi->mb.pred_mv); - if (cpi->sf.use_lastframe_partitioning || - cpi->sf.use_one_partition_size_always ) { + if ((cpi->sf.partition_search_type == SEARCH_PARTITION && + cpi->sf.use_lastframe_partitioning) || + cpi->sf.partition_search_type == FIXED_PARTITION || + cpi->sf.partition_search_type == VAR_BASED_FIXED_PARTITION) { const int idx_str = cm->mode_info_stride * mi_row + mi_col; MODE_INFO **mi_8x8 = cm->mi_grid_visible + idx_str; MODE_INFO **prev_mi_8x8 = cm->prev_mi_grid_visible + idx_str; cpi->mb.source_variance = UINT_MAX; - if (cpi->sf.use_one_partition_size_always) { + if (cpi->sf.partition_search_type == FIXED_PARTITION) { set_offsets(cpi, tile, mi_row, mi_col, BLOCK_64X64); set_partitioning(cpi, tile, mi_8x8, mi_row, mi_col, cpi->sf.always_this_block_size); rd_use_partition(cpi, tile, mi_8x8, tp, mi_row, mi_col, BLOCK_64X64, &dummy_rate, &dummy_dist, 1); + } else if (cpi->sf.partition_search_type == VAR_BASED_FIXED_PARTITION || + cpi->sf.partition_search_type == VAR_BASED_PARTITION) { + // TODO(debargha): Implement VAR_BASED_PARTITION as a separate case. + // Currently both VAR_BASED_FIXED_PARTITION/VAR_BASED_PARTITION + // map to the same thing. + BLOCK_SIZE bsize; + set_offsets(cpi, tile, mi_row, mi_col, BLOCK_64X64); + bsize = get_rd_var_based_fixed_partition(cpi); + set_partitioning(cpi, tile, mi_8x8, mi_row, mi_col, bsize); + rd_use_partition(cpi, tile, mi_8x8, tp, mi_row, mi_col, BLOCK_64X64, + &dummy_rate, &dummy_dist, 1); } else { if ((cm->current_video_frame % cpi->sf.last_partitioning_redo_frequency) == 0 @@ -2252,12 +2283,12 @@ static INLINE int get_block_col(int b32i, int b16i, int b8i) { return ((b32i & 1) << 2) + ((b16i & 1) << 1) + (b8i & 1); } -static void rtc_use_partition(VP9_COMP *cpi, - const TileInfo *const tile, - MODE_INFO **mi_8x8, - TOKENEXTRA **tp, int mi_row, int mi_col, - BLOCK_SIZE bsize, int *rate, int64_t *dist, - int do_recon) { +static void nonrd_use_partition(VP9_COMP *cpi, + const TileInfo *const tile, + MODE_INFO **mi_8x8, + 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 *const xd = &cpi->mb.e_mbd; @@ -2270,8 +2301,8 @@ static void rtc_use_partition(VP9_COMP *cpi, int rows = MIN(MI_BLOCK_SIZE, tile->mi_row_end - mi_row); int cols = MIN(MI_BLOCK_SIZE, tile->mi_col_end - mi_col); - int mi_8x8_width = num_8x8_blocks_wide_lookup[bsize]; - int mi_8x8_hight = num_8x8_blocks_high_lookup[bsize]; + int bw = num_8x8_blocks_wide_lookup[bsize]; + int bh = num_8x8_blocks_high_lookup[bsize]; int brate; int64_t bdist; @@ -2279,14 +2310,13 @@ static void rtc_use_partition(VP9_COMP *cpi, *dist = 0; // find prediction mode for each 8x8 block - for (br = 0; br < rows; br += mi_8x8_hight) { - for (bc = 0; bc < cols; bc += mi_8x8_width) { + for (br = 0; br < rows; br += bh) { + for (bc = 0; bc < cols; bc += bw) { int row = mi_row + br; int col = mi_col + bc; - int bh = 0, bw = 0; + BLOCK_SIZE bs = find_partition_size(bsize, rows - br, cols - bc, &bh, &bw); - set_offsets(cpi, tile, row, col, bs); if (cm->frame_type != KEY_FRAME) @@ -2298,8 +2328,9 @@ static void rtc_use_partition(VP9_COMP *cpi, *dist += bdist; for (j = 0; j < bh; ++j) - for (i = 0; i < bw; ++i) + for (i = 0; i < bw; ++i) { xd->mi_8x8[j * mis + i] = xd->mi_8x8[0]; + } } } @@ -2309,8 +2340,8 @@ static void rtc_use_partition(VP9_COMP *cpi, *dist = chosen_dist; } -static void encode_rtc_sb_row(VP9_COMP *cpi, const TileInfo *const tile, - int mi_row, TOKENEXTRA **tp) { +static void encode_nonrd_sb_row(VP9_COMP *cpi, const TileInfo *const tile, + int mi_row, TOKENEXTRA **tp) { VP9_COMMON * const cm = &cpi->common; int mi_col; @@ -2328,9 +2359,21 @@ static void encode_rtc_sb_row(VP9_COMP *cpi, const TileInfo *const tile, MODE_INFO **mi_8x8 = cm->mi_grid_visible + idx_str; cpi->mb.source_variance = UINT_MAX; - rtc_use_partition(cpi, tile, mi_8x8, tp, mi_row, mi_col, - cpi->sf.always_this_block_size, - &dummy_rate, &dummy_dist, 1); + if (cpi->sf.partition_search_type == FIXED_PARTITION) { + nonrd_use_partition(cpi, tile, mi_8x8, tp, mi_row, mi_col, + cpi->sf.always_this_block_size, + &dummy_rate, &dummy_dist, 1); + } else if (cpi->sf.partition_search_type == VAR_BASED_FIXED_PARTITION || + cpi->sf.partition_search_type == VAR_BASED_PARTITION) { + // TODO(debargha): Implement VAR_BASED_PARTITION as a separate case. + // Currently both VAR_BASED_FIXED_PARTITION/VAR_BASED_PARTITION + // map to the same thing. + BLOCK_SIZE bsize = get_nonrd_var_based_fixed_partition(cpi); + nonrd_use_partition(cpi, tile, mi_8x8, tp, mi_row, mi_col, + bsize, &dummy_rate, &dummy_dist, 1); + } else { + assert(0); + } } } // end RTC play code @@ -2386,7 +2429,7 @@ static void encode_frame_internal(VP9_COMP *cpi) { set_prev_mi(cm); - if (cpi->sf.use_pick_mode) { + if (cpi->sf.use_nonrd_pick_mode) { // Initialize internal buffer pointers for rtc coding, where non-RD // mode decision is used and hence no buffer pointer swap needed. int i; @@ -2422,10 +2465,10 @@ 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 += MI_BLOCK_SIZE) { - if (cpi->sf.use_pick_mode) - encode_rtc_sb_row(cpi, &tile, mi_row, &tp); + if (cpi->sf.use_nonrd_pick_mode) + encode_nonrd_sb_row(cpi, &tile, mi_row, &tp); else - encode_sb_row(cpi, &tile, mi_row, &tp); + encode_rd_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)); @@ -2688,7 +2731,7 @@ static void encode_superblock(VP9_COMP *cpi, TOKENEXTRA **t, int output_enabled, x->skip_recode = !x->select_txfm_size && mbmi->sb_type >= BLOCK_8X8 && (cpi->oxcf.aq_mode != COMPLEXITY_AQ) && - !cpi->sf.use_pick_mode; + !cpi->sf.use_nonrd_pick_mode; x->skip_optimize = ctx->is_coded; ctx->is_coded = 1; x->use_lp32x32fdct = cpi->sf.use_lp32x32fdct; |