OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved. | 2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 709 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
720 mbmi = &xd->mi[0]->mbmi; | 720 mbmi = &xd->mi[0]->mbmi; |
721 mbmi->sb_type = bsize; | 721 mbmi->sb_type = bsize; |
722 | 722 |
723 for (i = 0; i < MAX_MB_PLANE; ++i) { | 723 for (i = 0; i < MAX_MB_PLANE; ++i) { |
724 p[i].coeff = ctx->coeff_pbuf[i][0]; | 724 p[i].coeff = ctx->coeff_pbuf[i][0]; |
725 p[i].qcoeff = ctx->qcoeff_pbuf[i][0]; | 725 p[i].qcoeff = ctx->qcoeff_pbuf[i][0]; |
726 pd[i].dqcoeff = ctx->dqcoeff_pbuf[i][0]; | 726 pd[i].dqcoeff = ctx->dqcoeff_pbuf[i][0]; |
727 p[i].eobs = ctx->eobs_pbuf[i][0]; | 727 p[i].eobs = ctx->eobs_pbuf[i][0]; |
728 } | 728 } |
729 ctx->is_coded = 0; | 729 ctx->is_coded = 0; |
| 730 ctx->skippable = 0; |
730 x->skip_recode = 0; | 731 x->skip_recode = 0; |
731 | 732 |
732 // Set to zero to make sure we do not use the previous encoded frame stats | 733 // Set to zero to make sure we do not use the previous encoded frame stats |
733 mbmi->skip = 0; | 734 mbmi->skip = 0; |
734 | 735 |
735 x->source_variance = get_sby_perpixel_variance(cpi, &x->plane[0].src, bsize); | 736 x->source_variance = get_sby_perpixel_variance(cpi, &x->plane[0].src, bsize); |
736 | 737 |
737 // Save rdmult before it might be changed, so it can be restored later. | 738 // Save rdmult before it might be changed, so it can be restored later. |
738 orig_rdmult = x->rdmult; | 739 orig_rdmult = x->rdmult; |
739 | 740 |
(...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1225 } | 1226 } |
1226 } | 1227 } |
1227 } else { // partial in-image SB64 | 1228 } else { // partial in-image SB64 |
1228 int bh = num_8x8_blocks_high_lookup[BLOCK_16X16]; | 1229 int bh = num_8x8_blocks_high_lookup[BLOCK_16X16]; |
1229 int bw = num_8x8_blocks_wide_lookup[BLOCK_16X16]; | 1230 int bw = num_8x8_blocks_wide_lookup[BLOCK_16X16]; |
1230 set_partial_b64x64_partition(mi_upper_left, mis, bh, bw, | 1231 set_partial_b64x64_partition(mi_upper_left, mis, bh, bw, |
1231 row8x8_remaining, col8x8_remaining, BLOCK_16X16, mi_8x8); | 1232 row8x8_remaining, col8x8_remaining, BLOCK_16X16, mi_8x8); |
1232 } | 1233 } |
1233 } | 1234 } |
1234 | 1235 |
1235 static int is_background(VP9_COMP *cpi, const TileInfo *const tile, | 1236 static int is_background(const VP9_COMP *cpi, const TileInfo *const tile, |
1236 int mi_row, int mi_col) { | 1237 int mi_row, int mi_col) { |
1237 MACROBLOCK *x = &cpi->mb; | 1238 // This assumes the input source frames are of the same dimension. |
1238 uint8_t *src, *pre; | |
1239 int src_stride, pre_stride; | |
1240 | |
1241 const int row8x8_remaining = tile->mi_row_end - mi_row; | 1239 const int row8x8_remaining = tile->mi_row_end - mi_row; |
1242 const int col8x8_remaining = tile->mi_col_end - mi_col; | 1240 const int col8x8_remaining = tile->mi_col_end - mi_col; |
1243 | 1241 const int x = mi_col * MI_SIZE; |
| 1242 const int y = mi_row * MI_SIZE; |
| 1243 const int src_stride = cpi->Source->y_stride; |
| 1244 const uint8_t *const src = &cpi->Source->y_buffer[y * src_stride + x]; |
| 1245 const int pre_stride = cpi->Last_Source->y_stride; |
| 1246 const uint8_t *const pre = &cpi->Last_Source->y_buffer[y * pre_stride + x]; |
1244 int this_sad = 0; | 1247 int this_sad = 0; |
1245 int threshold = 0; | 1248 int threshold = 0; |
1246 | 1249 |
1247 // This assumes the input source frames are of the same dimension. | |
1248 src_stride = cpi->Source->y_stride; | |
1249 src = cpi->Source->y_buffer + (mi_row * MI_SIZE) * src_stride + | |
1250 (mi_col * MI_SIZE); | |
1251 pre_stride = cpi->Last_Source->y_stride; | |
1252 pre = cpi->Last_Source->y_buffer + (mi_row * MI_SIZE) * pre_stride + | |
1253 (mi_col * MI_SIZE); | |
1254 | |
1255 if (row8x8_remaining >= MI_BLOCK_SIZE && | 1250 if (row8x8_remaining >= MI_BLOCK_SIZE && |
1256 col8x8_remaining >= MI_BLOCK_SIZE) { | 1251 col8x8_remaining >= MI_BLOCK_SIZE) { |
1257 this_sad = cpi->fn_ptr[BLOCK_64X64].sdf(src, src_stride, | 1252 this_sad = cpi->fn_ptr[BLOCK_64X64].sdf(src, src_stride, pre, pre_stride); |
1258 pre, pre_stride); | |
1259 threshold = (1 << 12); | 1253 threshold = (1 << 12); |
1260 } else { | 1254 } else { |
1261 int r, c; | 1255 int r, c; |
1262 for (r = 0; r < row8x8_remaining; r += 2) | 1256 for (r = 0; r < row8x8_remaining; r += 2) |
1263 for (c = 0; c < col8x8_remaining; c += 2) | 1257 for (c = 0; c < col8x8_remaining; c += 2) |
1264 this_sad += cpi->fn_ptr[BLOCK_16X16].sdf(src, src_stride, | 1258 this_sad += cpi->fn_ptr[BLOCK_16X16].sdf(src, src_stride, |
1265 pre, pre_stride); | 1259 pre, pre_stride); |
1266 threshold = (row8x8_remaining * col8x8_remaining) << 6; | 1260 threshold = (row8x8_remaining * col8x8_remaining) << 6; |
1267 } | 1261 } |
1268 | 1262 |
1269 x->in_static_area = (this_sad < 2 * threshold); | 1263 return this_sad < 2 * threshold; |
1270 return x->in_static_area; | |
1271 } | 1264 } |
1272 | 1265 |
1273 static int sb_has_motion(const VP9_COMMON *cm, MODE_INFO **prev_mi_8x8, | 1266 static int sb_has_motion(const VP9_COMMON *cm, MODE_INFO **prev_mi_8x8, |
1274 const int motion_thresh) { | 1267 const int motion_thresh) { |
1275 const int mis = cm->mi_stride; | 1268 const int mis = cm->mi_stride; |
1276 int block_row, block_col; | 1269 int block_row, block_col; |
1277 | 1270 |
1278 if (cm->prev_mi) { | 1271 if (cm->prev_mi) { |
1279 for (block_row = 0; block_row < 8; ++block_row) { | 1272 for (block_row = 0; block_row < 8; ++block_row) { |
1280 for (block_col = 0; block_col < 8; ++block_col) { | 1273 for (block_col = 0; block_col < 8; ++block_col) { |
(...skipping 878 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2159 rd_pick_sb_modes(cpi, tile, mi_row, mi_col, &this_rate, &this_dist, bsize, | 2152 rd_pick_sb_modes(cpi, tile, mi_row, mi_col, &this_rate, &this_dist, bsize, |
2160 ctx, best_rd, 0); | 2153 ctx, best_rd, 0); |
2161 if (this_rate != INT_MAX) { | 2154 if (this_rate != INT_MAX) { |
2162 if (bsize >= BLOCK_8X8) { | 2155 if (bsize >= BLOCK_8X8) { |
2163 pl = partition_plane_context(xd, mi_row, mi_col, bsize); | 2156 pl = partition_plane_context(xd, mi_row, mi_col, bsize); |
2164 this_rate += cpi->partition_cost[pl][PARTITION_NONE]; | 2157 this_rate += cpi->partition_cost[pl][PARTITION_NONE]; |
2165 } | 2158 } |
2166 sum_rd = RDCOST(x->rdmult, x->rddiv, this_rate, this_dist); | 2159 sum_rd = RDCOST(x->rdmult, x->rddiv, this_rate, this_dist); |
2167 | 2160 |
2168 if (sum_rd < best_rd) { | 2161 if (sum_rd < best_rd) { |
2169 int64_t stop_thresh = 4096; | 2162 int64_t dist_breakout_thr = cpi->sf.partition_search_breakout_dist_thr; |
2170 int64_t stop_thresh_rd; | 2163 int rate_breakout_thr = cpi->sf.partition_search_breakout_rate_thr; |
2171 | 2164 |
2172 best_rate = this_rate; | 2165 best_rate = this_rate; |
2173 best_dist = this_dist; | 2166 best_dist = this_dist; |
2174 best_rd = sum_rd; | 2167 best_rd = sum_rd; |
2175 if (bsize >= BLOCK_8X8) | 2168 if (bsize >= BLOCK_8X8) |
2176 pc_tree->partitioning = PARTITION_NONE; | 2169 pc_tree->partitioning = PARTITION_NONE; |
2177 | 2170 |
2178 // Adjust threshold according to partition size. | 2171 // Adjust dist breakout threshold according to the partition size. |
2179 stop_thresh >>= 8 - (b_width_log2(bsize) + | 2172 dist_breakout_thr >>= 8 - (b_width_log2(bsize) + |
2180 b_height_log2(bsize)); | 2173 b_height_log2(bsize)); |
2181 | 2174 |
2182 stop_thresh_rd = RDCOST(x->rdmult, x->rddiv, 0, stop_thresh); | 2175 // If all y, u, v transform blocks in this partition are skippable, and |
2183 // If obtained distortion is very small, choose current partition | 2176 // the dist & rate are within the thresholds, the partition search is |
2184 // and stop splitting. | 2177 // terminated for current branch of the partition search tree. |
2185 if (!x->e_mbd.lossless && best_rd < stop_thresh_rd) { | 2178 // The dist & rate thresholds are set to 0 at speed 0 to disable the |
| 2179 // early termination at that speed. |
| 2180 if (!x->e_mbd.lossless && |
| 2181 (ctx->skippable && best_dist < dist_breakout_thr && |
| 2182 best_rate < rate_breakout_thr)) { |
2186 do_split = 0; | 2183 do_split = 0; |
2187 do_rect = 0; | 2184 do_rect = 0; |
2188 } | 2185 } |
2189 | 2186 |
2190 #if CONFIG_FP_MB_STATS | 2187 #if CONFIG_FP_MB_STATS |
2191 // Check if every 16x16 first pass block statistics has zero | 2188 // Check if every 16x16 first pass block statistics has zero |
2192 // motion and the corresponding first pass residue is small enough. | 2189 // motion and the corresponding first pass residue is small enough. |
2193 // If that is the case, check the difference variance between the | 2190 // If that is the case, check the difference variance between the |
2194 // current frame and the last frame. If the variance is small enough, | 2191 // current frame and the last frame. If the variance is small enough, |
2195 // stop further splitting in RD optimization | 2192 // stop further splitting in RD optimization |
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2599 return ALTREF_FRAME; | 2596 return ALTREF_FRAME; |
2600 else if (cpi->refresh_golden_frame || cpi->refresh_alt_ref_frame) | 2597 else if (cpi->refresh_golden_frame || cpi->refresh_alt_ref_frame) |
2601 return GOLDEN_FRAME; | 2598 return GOLDEN_FRAME; |
2602 else | 2599 else |
2603 return LAST_FRAME; | 2600 return LAST_FRAME; |
2604 } | 2601 } |
2605 | 2602 |
2606 static TX_MODE select_tx_mode(const VP9_COMP *cpi) { | 2603 static TX_MODE select_tx_mode(const VP9_COMP *cpi) { |
2607 if (cpi->mb.e_mbd.lossless) | 2604 if (cpi->mb.e_mbd.lossless) |
2608 return ONLY_4X4; | 2605 return ONLY_4X4; |
2609 if (cpi->common.frame_type == KEY_FRAME) | |
2610 return TX_MODE_SELECT; | |
2611 if (cpi->sf.tx_size_search_method == USE_LARGESTALL) | 2606 if (cpi->sf.tx_size_search_method == USE_LARGESTALL) |
2612 return ALLOW_32X32; | 2607 return ALLOW_32X32; |
2613 else if (cpi->sf.tx_size_search_method == USE_FULL_RD|| | 2608 else if (cpi->sf.tx_size_search_method == USE_FULL_RD|| |
2614 cpi->sf.tx_size_search_method == USE_TX_8X8) | 2609 cpi->sf.tx_size_search_method == USE_TX_8X8) |
2615 return TX_MODE_SELECT; | 2610 return TX_MODE_SELECT; |
2616 else | 2611 else |
2617 return cpi->common.tx_mode; | 2612 return cpi->common.tx_mode; |
2618 } | 2613 } |
2619 | 2614 |
2620 static void nonrd_pick_sb_modes(VP9_COMP *cpi, const TileInfo *const tile, | 2615 static void nonrd_pick_sb_modes(VP9_COMP *cpi, const TileInfo *const tile, |
(...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3112 case FIXED_PARTITION: | 3107 case FIXED_PARTITION: |
3113 bsize = sf->partition_search_type == FIXED_PARTITION ? | 3108 bsize = sf->partition_search_type == FIXED_PARTITION ? |
3114 sf->always_this_block_size : | 3109 sf->always_this_block_size : |
3115 get_nonrd_var_based_fixed_partition(cpi, mi_row, mi_col); | 3110 get_nonrd_var_based_fixed_partition(cpi, mi_row, mi_col); |
3116 set_fixed_partitioning(cpi, tile, mi, mi_row, mi_col, bsize); | 3111 set_fixed_partitioning(cpi, tile, mi, mi_row, mi_col, bsize); |
3117 nonrd_use_partition(cpi, tile, mi, tp, mi_row, mi_col, BLOCK_64X64, | 3112 nonrd_use_partition(cpi, tile, mi, tp, mi_row, mi_col, BLOCK_64X64, |
3118 1, &dummy_rate, &dummy_dist, cpi->pc_root); | 3113 1, &dummy_rate, &dummy_dist, cpi->pc_root); |
3119 break; | 3114 break; |
3120 case REFERENCE_PARTITION: | 3115 case REFERENCE_PARTITION: |
3121 if (sf->partition_check || | 3116 if (sf->partition_check || |
3122 !is_background(cpi, tile, mi_row, mi_col)) { | 3117 !(x->in_static_area = is_background(cpi, tile, mi_row, mi_col))) { |
3123 set_modeinfo_offsets(cm, xd, mi_row, mi_col); | 3118 set_modeinfo_offsets(cm, xd, mi_row, mi_col); |
3124 auto_partition_range(cpi, tile, mi_row, mi_col, | 3119 auto_partition_range(cpi, tile, mi_row, mi_col, |
3125 &sf->min_partition_size, | 3120 &sf->min_partition_size, |
3126 &sf->max_partition_size); | 3121 &sf->max_partition_size); |
3127 nonrd_pick_partition(cpi, tile, tp, mi_row, mi_col, BLOCK_64X64, | 3122 nonrd_pick_partition(cpi, tile, tp, mi_row, mi_col, BLOCK_64X64, |
3128 &dummy_rate, &dummy_dist, 1, INT64_MAX, | 3123 &dummy_rate, &dummy_dist, 1, INT64_MAX, |
3129 cpi->pc_root); | 3124 cpi->pc_root); |
3130 } else { | 3125 } else { |
3131 copy_partitioning(cm, mi, prev_mi); | 3126 copy_partitioning(cm, mi, prev_mi); |
3132 nonrd_use_partition(cpi, tile, mi, tp, mi_row, mi_col, | 3127 nonrd_use_partition(cpi, tile, mi, tp, mi_row, mi_col, |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3290 RD_OPT *const rd_opt = &cpi->rd; | 3285 RD_OPT *const rd_opt = &cpi->rd; |
3291 MACROBLOCK *const x = &cpi->mb; | 3286 MACROBLOCK *const x = &cpi->mb; |
3292 VP9_COMMON *const cm = &cpi->common; | 3287 VP9_COMMON *const cm = &cpi->common; |
3293 MACROBLOCKD *const xd = &x->e_mbd; | 3288 MACROBLOCKD *const xd = &x->e_mbd; |
3294 | 3289 |
3295 xd->mi = cm->mi_grid_visible; | 3290 xd->mi = cm->mi_grid_visible; |
3296 xd->mi[0] = cm->mi; | 3291 xd->mi[0] = cm->mi; |
3297 | 3292 |
3298 vp9_zero(cm->counts); | 3293 vp9_zero(cm->counts); |
3299 vp9_zero(cpi->coef_counts); | 3294 vp9_zero(cpi->coef_counts); |
3300 vp9_zero(cpi->tx_stepdown_count); | |
3301 vp9_zero(rd_opt->comp_pred_diff); | 3295 vp9_zero(rd_opt->comp_pred_diff); |
3302 vp9_zero(rd_opt->filter_diff); | 3296 vp9_zero(rd_opt->filter_diff); |
3303 vp9_zero(rd_opt->tx_select_diff); | 3297 vp9_zero(rd_opt->tx_select_diff); |
3304 vp9_zero(rd_opt->tx_select_threshes); | 3298 vp9_zero(rd_opt->tx_select_threshes); |
3305 | 3299 |
3306 xd->lossless = cm->base_qindex == 0 && | 3300 xd->lossless = cm->base_qindex == 0 && |
3307 cm->y_dc_delta_q == 0 && | 3301 cm->y_dc_delta_q == 0 && |
3308 cm->uv_dc_delta_q == 0 && | 3302 cm->uv_dc_delta_q == 0 && |
3309 cm->uv_ac_delta_q == 0; | 3303 cm->uv_ac_delta_q == 0; |
3310 | 3304 |
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3649 tx_size = (bsize >= BLOCK_8X8) ? mbmi->tx_size : TX_4X4; | 3643 tx_size = (bsize >= BLOCK_8X8) ? mbmi->tx_size : TX_4X4; |
3650 } | 3644 } |
3651 | 3645 |
3652 for (y = 0; y < mi_height; y++) | 3646 for (y = 0; y < mi_height; y++) |
3653 for (x = 0; x < mi_width; x++) | 3647 for (x = 0; x < mi_width; x++) |
3654 if (mi_col + x < cm->mi_cols && mi_row + y < cm->mi_rows) | 3648 if (mi_col + x < cm->mi_cols && mi_row + y < cm->mi_rows) |
3655 mi_8x8[mis * y + x]->mbmi.tx_size = tx_size; | 3649 mi_8x8[mis * y + x]->mbmi.tx_size = tx_size; |
3656 } | 3650 } |
3657 } | 3651 } |
3658 } | 3652 } |
OLD | NEW |