Merge "Add init and reset functions for RD_COST struct"

This commit is contained in:
Jingning Han 2014-10-17 11:15:19 -07:00 committed by Gerrit Code Review
commit 3bc94cd2eb
3 changed files with 39 additions and 24 deletions

View File

@ -1522,9 +1522,7 @@ static void rd_use_partition(VP9_COMP *cpi, const TileInfo *const tile,
BLOCK_SIZE subsize; BLOCK_SIZE subsize;
ENTROPY_CONTEXT l[16 * MAX_MB_PLANE], a[16 * MAX_MB_PLANE]; ENTROPY_CONTEXT l[16 * MAX_MB_PLANE], a[16 * MAX_MB_PLANE];
PARTITION_CONTEXT sl[8], sa[8]; PARTITION_CONTEXT sl[8], sa[8];
RD_COST last_part_rdc = {INT_MAX, INT64_MAX, INT64_MAX}; RD_COST last_part_rdc, none_rdc, chosen_rdc;
RD_COST none_rdc = {INT_MAX, INT64_MAX, INT64_MAX};
RD_COST chosen_rdc = {INT_MAX, INT64_MAX, INT64_MAX};
BLOCK_SIZE sub_subsize = BLOCK_4X4; BLOCK_SIZE sub_subsize = BLOCK_4X4;
int splits_below = 0; int splits_below = 0;
BLOCK_SIZE bs_type = mi_8x8[0].src_mi->mbmi.sb_type; BLOCK_SIZE bs_type = mi_8x8[0].src_mi->mbmi.sb_type;
@ -1537,6 +1535,10 @@ static void rd_use_partition(VP9_COMP *cpi, const TileInfo *const tile,
assert(num_4x4_blocks_wide_lookup[bsize] == assert(num_4x4_blocks_wide_lookup[bsize] ==
num_4x4_blocks_high_lookup[bsize]); num_4x4_blocks_high_lookup[bsize]);
vp9_rd_cost_reset(&last_part_rdc);
vp9_rd_cost_reset(&none_rdc);
vp9_rd_cost_reset(&chosen_rdc);
partition = partition_lookup[bsl][bs_type]; partition = partition_lookup[bsl][bs_type];
subsize = get_subsize(bsize, partition); subsize = get_subsize(bsize, partition);
@ -1598,16 +1600,15 @@ static void rd_use_partition(VP9_COMP *cpi, const TileInfo *const tile,
INT64_MAX); INT64_MAX);
if (last_part_rdc.rate != INT_MAX && if (last_part_rdc.rate != INT_MAX &&
bsize >= BLOCK_8X8 && mi_row + (mi_step >> 1) < cm->mi_rows) { bsize >= BLOCK_8X8 && mi_row + (mi_step >> 1) < cm->mi_rows) {
RD_COST tmp_rdc = {0, 0, 0}; RD_COST tmp_rdc;
PICK_MODE_CONTEXT *ctx = &pc_tree->horizontal[0]; PICK_MODE_CONTEXT *ctx = &pc_tree->horizontal[0];
vp9_rd_cost_init(&tmp_rdc);
update_state(cpi, ctx, mi_row, mi_col, subsize, 0); update_state(cpi, ctx, mi_row, mi_col, subsize, 0);
encode_superblock(cpi, tp, 0, mi_row, mi_col, subsize, ctx); encode_superblock(cpi, tp, 0, mi_row, mi_col, subsize, ctx);
rd_pick_sb_modes(cpi, tile, mi_row + (mi_step >> 1), mi_col, &tmp_rdc, rd_pick_sb_modes(cpi, tile, mi_row + (mi_step >> 1), mi_col, &tmp_rdc,
subsize, &pc_tree->horizontal[1], INT64_MAX); subsize, &pc_tree->horizontal[1], INT64_MAX);
if (tmp_rdc.rate == INT_MAX || tmp_rdc.dist == INT64_MAX) { if (tmp_rdc.rate == INT_MAX || tmp_rdc.dist == INT64_MAX) {
last_part_rdc.rate = INT_MAX; vp9_rd_cost_reset(&last_part_rdc);
last_part_rdc.dist = INT64_MAX;
last_part_rdc.rdcost = INT64_MAX;
break; break;
} }
last_part_rdc.rate += tmp_rdc.rate; last_part_rdc.rate += tmp_rdc.rate;
@ -1620,17 +1621,16 @@ static void rd_use_partition(VP9_COMP *cpi, const TileInfo *const tile,
subsize, &pc_tree->vertical[0], INT64_MAX); subsize, &pc_tree->vertical[0], INT64_MAX);
if (last_part_rdc.rate != INT_MAX && if (last_part_rdc.rate != INT_MAX &&
bsize >= BLOCK_8X8 && mi_col + (mi_step >> 1) < cm->mi_cols) { bsize >= BLOCK_8X8 && mi_col + (mi_step >> 1) < cm->mi_cols) {
RD_COST tmp_rdc = {0, 0, 0}; RD_COST tmp_rdc;
PICK_MODE_CONTEXT *ctx = &pc_tree->vertical[0]; PICK_MODE_CONTEXT *ctx = &pc_tree->vertical[0];
vp9_rd_cost_init(&tmp_rdc);
update_state(cpi, ctx, mi_row, mi_col, subsize, 0); update_state(cpi, ctx, mi_row, mi_col, subsize, 0);
encode_superblock(cpi, tp, 0, mi_row, mi_col, subsize, ctx); encode_superblock(cpi, tp, 0, mi_row, mi_col, subsize, ctx);
rd_pick_sb_modes(cpi, tile, mi_row, mi_col + (mi_step >> 1), &tmp_rdc, rd_pick_sb_modes(cpi, tile, mi_row, mi_col + (mi_step >> 1), &tmp_rdc,
subsize, &pc_tree->vertical[bsize > BLOCK_8X8], subsize, &pc_tree->vertical[bsize > BLOCK_8X8],
INT64_MAX); INT64_MAX);
if (tmp_rdc.rate == INT_MAX || tmp_rdc.dist == INT64_MAX) { if (tmp_rdc.rate == INT_MAX || tmp_rdc.dist == INT64_MAX) {
last_part_rdc.rate = INT_MAX; vp9_rd_cost_reset(&last_part_rdc);
last_part_rdc.dist = INT64_MAX;
last_part_rdc.rdcost = INT64_MAX;
break; break;
} }
last_part_rdc.rate += tmp_rdc.rate; last_part_rdc.rate += tmp_rdc.rate;
@ -1651,19 +1651,17 @@ static void rd_use_partition(VP9_COMP *cpi, const TileInfo *const tile,
int x_idx = (i & 1) * (mi_step >> 1); int x_idx = (i & 1) * (mi_step >> 1);
int y_idx = (i >> 1) * (mi_step >> 1); int y_idx = (i >> 1) * (mi_step >> 1);
int jj = i >> 1, ii = i & 0x01; int jj = i >> 1, ii = i & 0x01;
RD_COST tmp_rdc = {0, 0, 0}; RD_COST tmp_rdc;
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; continue;
vp9_rd_cost_init(&tmp_rdc);
rd_use_partition(cpi, tile, mi_8x8 + jj * bss * mis + ii * bss, tp, rd_use_partition(cpi, tile, mi_8x8 + jj * bss * mis + ii * bss, tp,
mi_row + y_idx, mi_col + x_idx, subsize, mi_row + y_idx, mi_col + x_idx, subsize,
&tmp_rdc.rate, &tmp_rdc.dist, &tmp_rdc.rate, &tmp_rdc.dist,
i != 3, pc_tree->split[i]); i != 3, pc_tree->split[i]);
if (tmp_rdc.rate == INT_MAX || tmp_rdc.dist == INT64_MAX) { if (tmp_rdc.rate == INT_MAX || tmp_rdc.dist == INT64_MAX) {
last_part_rdc.rate = INT_MAX; vp9_rd_cost_reset(&last_part_rdc);
last_part_rdc.dist = INT64_MAX;
last_part_rdc.rdcost = INT64_MAX;
break; break;
} }
last_part_rdc.rate += tmp_rdc.rate; last_part_rdc.rate += tmp_rdc.rate;
@ -1710,15 +1708,12 @@ static void rd_use_partition(VP9_COMP *cpi, const TileInfo *const tile,
save_context(cpi, mi_row, mi_col, a, l, sa, sl, bsize); save_context(cpi, mi_row, mi_col, a, l, sa, sl, bsize);
pc_tree->split[i]->partitioning = PARTITION_NONE; pc_tree->split[i]->partitioning = PARTITION_NONE;
rd_pick_sb_modes(cpi, tile, mi_row + y_idx, mi_col + x_idx, &tmp_rdc, rd_pick_sb_modes(cpi, tile, mi_row + y_idx, mi_col + x_idx, &tmp_rdc,
split_subsize, &pc_tree->split[i]->none, split_subsize, &pc_tree->split[i]->none, INT64_MAX);
INT64_MAX);
restore_context(cpi, mi_row, mi_col, a, l, sa, sl, bsize); restore_context(cpi, mi_row, mi_col, a, l, sa, sl, bsize);
if (tmp_rdc.rate == INT_MAX || tmp_rdc.dist == INT64_MAX) { if (tmp_rdc.rate == INT_MAX || tmp_rdc.dist == INT64_MAX) {
chosen_rdc.rate = INT_MAX; vp9_rd_cost_reset(&chosen_rdc);
chosen_rdc.dist = INT64_MAX;
chosen_rdc.rdcost = INT64_MAX;
break; break;
} }
@ -2123,9 +2118,7 @@ static void rd_pick_partition(VP9_COMP *cpi, const TileInfo *const tile,
PICK_MODE_CONTEXT *ctx = &pc_tree->none; PICK_MODE_CONTEXT *ctx = &pc_tree->none;
int i, pl; int i, pl;
BLOCK_SIZE subsize; BLOCK_SIZE subsize;
RD_COST this_rdc = {0, 0, 0}; RD_COST this_rdc, sum_rdc, best_rdc;
RD_COST sum_rdc = {0, 0, 0};
RD_COST best_rdc = {INT_MAX, INT64_MAX, best_rd};
int do_split = bsize >= BLOCK_8X8; int do_split = bsize >= BLOCK_8X8;
int do_rect = 1; int do_rect = 1;
@ -2153,6 +2146,11 @@ static void rd_pick_partition(VP9_COMP *cpi, const TileInfo *const tile,
assert(num_8x8_blocks_wide_lookup[bsize] == assert(num_8x8_blocks_wide_lookup[bsize] ==
num_8x8_blocks_high_lookup[bsize]); num_8x8_blocks_high_lookup[bsize]);
vp9_rd_cost_init(&this_rdc);
vp9_rd_cost_init(&sum_rdc);
vp9_rd_cost_reset(&best_rdc);
best_rdc.rdcost = best_rd;
set_offsets(cpi, tile, mi_row, mi_col, bsize); set_offsets(cpi, tile, mi_row, mi_col, bsize);
if (bsize == BLOCK_16X16 && cpi->oxcf.aq_mode) if (bsize == BLOCK_16X16 && cpi->oxcf.aq_mode)

View File

@ -44,6 +44,18 @@
// Factor to weigh the rate for switchable interp filters. // Factor to weigh the rate for switchable interp filters.
#define SWITCHABLE_INTERP_RATE_FACTOR 1 #define SWITCHABLE_INTERP_RATE_FACTOR 1
void vp9_rd_cost_reset(RD_COST *rd_cost) {
rd_cost->rate = INT_MAX;
rd_cost->dist = INT64_MAX;
rd_cost->rdcost = INT64_MAX;
}
void vp9_rd_cost_init(RD_COST *rd_cost) {
rd_cost->rate = 0;
rd_cost->dist = 0;
rd_cost->rdcost = 0;
}
// The baseline rd thresholds for breaking out of the rd loop for // The baseline rd thresholds for breaking out of the rd loop for
// certain modes are assumed to be based on 8x8 blocks. // certain modes are assumed to be based on 8x8 blocks.
// This table is used to correct for block size. // This table is used to correct for block size.

View File

@ -123,6 +123,11 @@ typedef struct RD_COST {
int64_t rdcost; int64_t rdcost;
} RD_COST; } RD_COST;
// Reset the rate distortion cost values to maximum (invalid) value.
void vp9_rd_cost_reset(RD_COST *rd_cost);
// Initialize the rate distortion cost values to zero.
void vp9_rd_cost_init(RD_COST *rd_cost);
struct TileInfo; struct TileInfo;
struct VP9_COMP; struct VP9_COMP;
struct macroblock; struct macroblock;