ref: f67e75a6f4a6972cabde2ffe80d386e9b06d8f60
parent: 8fff2db51e7daa14b24792d568b140d6244bd7ba
parent: f3a5de816da1ddd41029ed3b4b29f5adfdc4764e
author: Jingning Han <[email protected]>
date: Tue Oct 14 07:33:00 EDT 2014
Merge "Refactor super_block_uvrd function to remove goto statement"
--- a/vp9/encoder/vp9_rdopt.c
+++ b/vp9/encoder/vp9_rdopt.c
@@ -1112,10 +1112,12 @@
return best_rd;
}
-static void super_block_uvrd(const VP9_COMP *cpi, MACROBLOCK *x,
- int *rate, int64_t *distortion, int *skippable,
- int64_t *sse, BLOCK_SIZE bsize,
- int64_t ref_best_rd) {
+// Return value 0: early termination triggered, no valid rd cost available;
+// 1: rd cost values are valid.
+static int super_block_uvrd(const VP9_COMP *cpi, MACROBLOCK *x,
+ int *rate, int64_t *distortion, int *skippable,
+ int64_t *sse, BLOCK_SIZE bsize,
+ int64_t ref_best_rd) {
MACROBLOCKD *const xd = &x->e_mbd;
MB_MODE_INFO *const mbmi = &xd->mi[0].src_mi->mbmi;
const TX_SIZE uv_tx_size = get_uv_tx_size(mbmi, &xd->plane[1]);
@@ -1122,11 +1124,12 @@
int plane;
int pnrate = 0, pnskip = 1;
int64_t pndist = 0, pnsse = 0;
+ int is_cost_valid = 1;
if (ref_best_rd < 0)
- goto term;
+ is_cost_valid = 0;
- if (is_inter_block(mbmi)) {
+ if (is_inter_block(mbmi) && is_cost_valid) {
int plane;
for (plane = 1; plane < MAX_MB_PLANE; ++plane)
vp9_subtract_plane(x, bsize, plane);
@@ -1137,25 +1140,27 @@
*sse = 0;
*skippable = 1;
- for (plane = 1; plane < MAX_MB_PLANE; ++plane) {
+ for (plane = 1; plane < MAX_MB_PLANE && is_cost_valid; ++plane) {
txfm_rd_in_plane(x, &pnrate, &pndist, &pnskip, &pnsse,
ref_best_rd, plane, bsize, uv_tx_size,
cpi->sf.use_fast_coef_costing);
if (pnrate == INT_MAX)
- goto term;
+ is_cost_valid = 0;
*rate += pnrate;
*distortion += pndist;
*sse += pnsse;
*skippable &= pnskip;
}
- return;
- term:
- *rate = INT_MAX;
- *distortion = INT64_MAX;
- *sse = INT64_MAX;
- *skippable = 0;
- return;
+ if (!is_cost_valid) {
+ // reset cost value
+ *rate = INT_MAX;
+ *distortion = INT64_MAX;
+ *sse = INT64_MAX;
+ *skippable = 0;
+ }
+
+ return is_cost_valid;
}
static int64_t rd_pick_intra_sbuv_mode(VP9_COMP *cpi, MACROBLOCK *x,
@@ -1177,9 +1182,8 @@
xd->mi[0].src_mi->mbmi.uv_mode = mode;
- super_block_uvrd(cpi, x, &this_rate_tokenonly,
- &this_distortion, &s, &this_sse, bsize, best_rd);
- if (this_rate_tokenonly == INT_MAX)
+ if (!super_block_uvrd(cpi, x, &this_rate_tokenonly,
+ &this_distortion, &s, &this_sse, bsize, best_rd))
continue;
this_rate = this_rate_tokenonly +
cpi->intra_uv_mode_cost[cpi->common.frame_type][mode];
@@ -2671,9 +2675,8 @@
rdcosty = RDCOST(x->rdmult, x->rddiv, *rate2, *distortion);
rdcosty = MIN(rdcosty, RDCOST(x->rdmult, x->rddiv, 0, *psse));
- super_block_uvrd(cpi, x, rate_uv, &distortion_uv, &skippable_uv, &sseuv,
- bsize, ref_best_rd - rdcosty);
- if (*rate_uv == INT_MAX) {
+ if (!super_block_uvrd(cpi, x, rate_uv, &distortion_uv, &skippable_uv,
+ &sseuv, bsize, ref_best_rd - rdcosty)) {
*rate2 = INT_MAX;
*distortion = INT64_MAX;
restore_dst_buf(xd, orig_dst, orig_dst_stride);
@@ -3945,10 +3948,10 @@
vp9_build_inter_predictors_sbuv(&x->e_mbd, mi_row, mi_col,
BLOCK_8X8);
vpx_memset(x->skip_txfm, 0, sizeof(x->skip_txfm));
- super_block_uvrd(cpi, x, &rate_uv, &distortion_uv, &uv_skippable,
- &uv_sse, BLOCK_8X8, tmp_best_rdu);
- if (rate_uv == INT_MAX)
+ if (!super_block_uvrd(cpi, x, &rate_uv, &distortion_uv, &uv_skippable,
+ &uv_sse, BLOCK_8X8, tmp_best_rdu))
continue;
+
rate2 += rate_uv;
distortion2 += distortion_uv;
skippable = skippable && uv_skippable;