| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2014 The WebM project authors. All Rights Reserved. | 2 * Copyright (c) 2014 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 |
| 11 #include <assert.h> | 11 #include <assert.h> |
| 12 #include <limits.h> | 12 #include <limits.h> |
| 13 #include <math.h> | 13 #include <math.h> |
| 14 #include <stdio.h> | 14 #include <stdio.h> |
| 15 | 15 |
| 16 #include "./vp9_rtcd.h" | 16 #include "./vp9_rtcd.h" |
| 17 #include "./vpx_dsp_rtcd.h" |
| 17 | 18 |
| 18 #include "vpx_mem/vpx_mem.h" | 19 #include "vpx_mem/vpx_mem.h" |
| 20 #include "vpx_ports/mem.h" |
| 19 | 21 |
| 20 #include "vp9/common/vp9_blockd.h" | 22 #include "vp9/common/vp9_blockd.h" |
| 21 #include "vp9/common/vp9_common.h" | 23 #include "vp9/common/vp9_common.h" |
| 22 #include "vp9/common/vp9_mvref_common.h" | 24 #include "vp9/common/vp9_mvref_common.h" |
| 23 #include "vp9/common/vp9_pred_common.h" | 25 #include "vp9/common/vp9_pred_common.h" |
| 24 #include "vp9/common/vp9_reconinter.h" | 26 #include "vp9/common/vp9_reconinter.h" |
| 25 #include "vp9/common/vp9_reconintra.h" | 27 #include "vp9/common/vp9_reconintra.h" |
| 28 #include "vp9/common/vp9_scan.h" |
| 26 | 29 |
| 27 #include "vp9/encoder/vp9_cost.h" | 30 #include "vp9/encoder/vp9_cost.h" |
| 28 #include "vp9/encoder/vp9_encoder.h" | 31 #include "vp9/encoder/vp9_encoder.h" |
| 29 #include "vp9/encoder/vp9_pickmode.h" | 32 #include "vp9/encoder/vp9_pickmode.h" |
| 30 #include "vp9/encoder/vp9_ratectrl.h" | 33 #include "vp9/encoder/vp9_ratectrl.h" |
| 31 #include "vp9/encoder/vp9_rd.h" | 34 #include "vp9/encoder/vp9_rd.h" |
| 32 | 35 |
| 33 typedef struct { | 36 typedef struct { |
| 34 uint8_t *data; | 37 uint8_t *data; |
| 35 int stride; | 38 int stride; |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 int w, int h, unsigned int *sse, int *sum, | 210 int w, int h, unsigned int *sse, int *sum, |
| 208 int block_size, unsigned int *sse8x8, | 211 int block_size, unsigned int *sse8x8, |
| 209 int *sum8x8, unsigned int *var8x8) { | 212 int *sum8x8, unsigned int *var8x8) { |
| 210 int i, j, k = 0; | 213 int i, j, k = 0; |
| 211 | 214 |
| 212 *sse = 0; | 215 *sse = 0; |
| 213 *sum = 0; | 216 *sum = 0; |
| 214 | 217 |
| 215 for (i = 0; i < h; i += block_size) { | 218 for (i = 0; i < h; i += block_size) { |
| 216 for (j = 0; j < w; j += block_size) { | 219 for (j = 0; j < w; j += block_size) { |
| 217 vp9_get8x8var(src + src_stride * i + j, src_stride, | 220 vpx_get8x8var(src + src_stride * i + j, src_stride, |
| 218 ref + ref_stride * i + j, ref_stride, | 221 ref + ref_stride * i + j, ref_stride, |
| 219 &sse8x8[k], &sum8x8[k]); | 222 &sse8x8[k], &sum8x8[k]); |
| 220 *sse += sse8x8[k]; | 223 *sse += sse8x8[k]; |
| 221 *sum += sum8x8[k]; | 224 *sum += sum8x8[k]; |
| 222 var8x8[k] = sse8x8[k] - (((unsigned int)sum8x8[k] * sum8x8[k]) >> 6); | 225 var8x8[k] = sse8x8[k] - (((unsigned int)sum8x8[k] * sum8x8[k]) >> 6); |
| 223 k++; | 226 k++; |
| 224 } | 227 } |
| 225 } | 228 } |
| 226 } | 229 } |
| 227 | 230 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 *var_y = var; | 290 *var_y = var; |
| 288 *sse_y = sse; | 291 *sse_y = sse; |
| 289 | 292 |
| 290 if (cpi->common.tx_mode == TX_MODE_SELECT) { | 293 if (cpi->common.tx_mode == TX_MODE_SELECT) { |
| 291 if (sse > (var << 2)) | 294 if (sse > (var << 2)) |
| 292 tx_size = MIN(max_txsize_lookup[bsize], | 295 tx_size = MIN(max_txsize_lookup[bsize], |
| 293 tx_mode_to_biggest_tx_size[cpi->common.tx_mode]); | 296 tx_mode_to_biggest_tx_size[cpi->common.tx_mode]); |
| 294 else | 297 else |
| 295 tx_size = TX_8X8; | 298 tx_size = TX_8X8; |
| 296 | 299 |
| 297 if (cpi->sf.partition_search_type == VAR_BASED_PARTITION) { | 300 if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ && |
| 298 if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ && | 301 cyclic_refresh_segment_id_boosted(xd->mi[0]->mbmi.segment_id)) |
| 299 cyclic_refresh_segment_id_boosted(xd->mi[0]->mbmi.segment_id)) | 302 tx_size = TX_8X8; |
| 300 tx_size = TX_8X8; | 303 else if (tx_size > TX_16X16) |
| 301 else if (tx_size > TX_16X16) | 304 tx_size = TX_16X16; |
| 302 tx_size = TX_16X16; | |
| 303 } | |
| 304 } else { | 305 } else { |
| 305 tx_size = MIN(max_txsize_lookup[bsize], | 306 tx_size = MIN(max_txsize_lookup[bsize], |
| 306 tx_mode_to_biggest_tx_size[cpi->common.tx_mode]); | 307 tx_mode_to_biggest_tx_size[cpi->common.tx_mode]); |
| 307 } | 308 } |
| 308 | 309 |
| 309 assert(tx_size >= TX_8X8); | 310 assert(tx_size >= TX_8X8); |
| 310 xd->mi[0]->mbmi.tx_size = tx_size; | 311 xd->mi[0]->mbmi.tx_size = tx_size; |
| 311 | 312 |
| 312 // Evaluate if the partition block is a skippable block in Y plane. | 313 // Evaluate if the partition block is a skippable block in Y plane. |
| 313 { | 314 { |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 471 *sse_y = sse; | 472 *sse_y = sse; |
| 472 | 473 |
| 473 if (cpi->common.tx_mode == TX_MODE_SELECT) { | 474 if (cpi->common.tx_mode == TX_MODE_SELECT) { |
| 474 if (sse > (var << 2)) | 475 if (sse > (var << 2)) |
| 475 xd->mi[0]->mbmi.tx_size = | 476 xd->mi[0]->mbmi.tx_size = |
| 476 MIN(max_txsize_lookup[bsize], | 477 MIN(max_txsize_lookup[bsize], |
| 477 tx_mode_to_biggest_tx_size[cpi->common.tx_mode]); | 478 tx_mode_to_biggest_tx_size[cpi->common.tx_mode]); |
| 478 else | 479 else |
| 479 xd->mi[0]->mbmi.tx_size = TX_8X8; | 480 xd->mi[0]->mbmi.tx_size = TX_8X8; |
| 480 | 481 |
| 481 if (cpi->sf.partition_search_type == VAR_BASED_PARTITION) { | 482 if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ && |
| 482 if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ && | 483 cyclic_refresh_segment_id_boosted(xd->mi[0]->mbmi.segment_id)) |
| 483 cyclic_refresh_segment_id_boosted(xd->mi[0]->mbmi.segment_id)) | 484 xd->mi[0]->mbmi.tx_size = TX_8X8; |
| 484 xd->mi[0]->mbmi.tx_size = TX_8X8; | 485 else if (xd->mi[0]->mbmi.tx_size > TX_16X16) |
| 485 else if (xd->mi[0]->mbmi.tx_size > TX_16X16) | 486 xd->mi[0]->mbmi.tx_size = TX_16X16; |
| 486 xd->mi[0]->mbmi.tx_size = TX_16X16; | |
| 487 } | |
| 488 } else { | 487 } else { |
| 489 xd->mi[0]->mbmi.tx_size = | 488 xd->mi[0]->mbmi.tx_size = |
| 490 MIN(max_txsize_lookup[bsize], | 489 MIN(max_txsize_lookup[bsize], |
| 491 tx_mode_to_biggest_tx_size[cpi->common.tx_mode]); | 490 tx_mode_to_biggest_tx_size[cpi->common.tx_mode]); |
| 492 } | 491 } |
| 493 | 492 |
| 494 // Evaluate if the partition block is a skippable block in Y plane. | 493 // Evaluate if the partition block is a skippable block in Y plane. |
| 495 { | 494 { |
| 496 const BLOCK_SIZE unit_size = | 495 const BLOCK_SIZE unit_size = |
| 497 txsize_to_bsize[xd->mi[0]->mbmi.tx_size]; | 496 txsize_to_bsize[xd->mi[0]->mbmi.tx_size]; |
| (...skipping 573 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1071 int_mv frame_mv[MB_MODE_COUNT][MAX_REF_FRAMES]; | 1070 int_mv frame_mv[MB_MODE_COUNT][MAX_REF_FRAMES]; |
| 1072 struct buf_2d yv12_mb[4][MAX_MB_PLANE]; | 1071 struct buf_2d yv12_mb[4][MAX_MB_PLANE]; |
| 1073 static const int flag_list[4] = { 0, VP9_LAST_FLAG, VP9_GOLD_FLAG, | 1072 static const int flag_list[4] = { 0, VP9_LAST_FLAG, VP9_GOLD_FLAG, |
| 1074 VP9_ALT_FLAG }; | 1073 VP9_ALT_FLAG }; |
| 1075 RD_COST this_rdc, best_rdc; | 1074 RD_COST this_rdc, best_rdc; |
| 1076 uint8_t skip_txfm = 0, best_mode_skip_txfm = 0; | 1075 uint8_t skip_txfm = 0, best_mode_skip_txfm = 0; |
| 1077 // var_y and sse_y are saved to be used in skipping checking | 1076 // var_y and sse_y are saved to be used in skipping checking |
| 1078 unsigned int var_y = UINT_MAX; | 1077 unsigned int var_y = UINT_MAX; |
| 1079 unsigned int sse_y = UINT_MAX; | 1078 unsigned int sse_y = UINT_MAX; |
| 1080 // Reduce the intra cost penalty for small blocks (<=16x16). | 1079 // Reduce the intra cost penalty for small blocks (<=16x16). |
| 1081 const int reduction_fac = | 1080 const int reduction_fac = (bsize <= BLOCK_16X16) ? |
| 1082 (cpi->sf.partition_search_type == VAR_BASED_PARTITION && | 1081 ((bsize <= BLOCK_8X8) ? 4 : 2) : 0; |
| 1083 bsize <= BLOCK_16X16) ? ((bsize <= BLOCK_8X8) ? 4 : 2) : 0; | |
| 1084 const int intra_cost_penalty = vp9_get_intra_cost_penalty( | 1082 const int intra_cost_penalty = vp9_get_intra_cost_penalty( |
| 1085 cm->base_qindex, cm->y_dc_delta_q, cm->bit_depth) >> reduction_fac; | 1083 cm->base_qindex, cm->y_dc_delta_q, cm->bit_depth) >> reduction_fac; |
| 1086 const int64_t inter_mode_thresh = RDCOST(x->rdmult, x->rddiv, | 1084 const int64_t inter_mode_thresh = RDCOST(x->rdmult, x->rddiv, |
| 1087 intra_cost_penalty, 0); | 1085 intra_cost_penalty, 0); |
| 1088 const int *const rd_threshes = cpi->rd.threshes[mbmi->segment_id][bsize]; | 1086 const int *const rd_threshes = cpi->rd.threshes[mbmi->segment_id][bsize]; |
| 1089 const int *const rd_thresh_freq_fact = tile_data->thresh_freq_fact[bsize]; | 1087 const int *const rd_thresh_freq_fact = tile_data->thresh_freq_fact[bsize]; |
| 1090 INTERP_FILTER filter_ref; | 1088 INTERP_FILTER filter_ref; |
| 1091 const int bsl = mi_width_log2_lookup[bsize]; | 1089 const int bsl = mi_width_log2_lookup[bsize]; |
| 1092 const int pred_filter_search = cm->interp_filter == SWITCHABLE ? | 1090 const int pred_filter_search = cm->interp_filter == SWITCHABLE ? |
| 1093 (((mi_row + mi_col) >> bsl) + | 1091 (((mi_row + mi_col) >> bsl) + |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1240 continue; | 1238 continue; |
| 1241 | 1239 |
| 1242 if (this_mode == NEWMV) { | 1240 if (this_mode == NEWMV) { |
| 1243 if (ref_frame > LAST_FRAME) { | 1241 if (ref_frame > LAST_FRAME) { |
| 1244 int tmp_sad; | 1242 int tmp_sad; |
| 1245 int dis, cost_list[5]; | 1243 int dis, cost_list[5]; |
| 1246 | 1244 |
| 1247 if (bsize < BLOCK_16X16) | 1245 if (bsize < BLOCK_16X16) |
| 1248 continue; | 1246 continue; |
| 1249 | 1247 |
| 1250 tmp_sad = vp9_int_pro_motion_estimation(cpi, x, bsize); | 1248 tmp_sad = vp9_int_pro_motion_estimation(cpi, x, bsize, mi_row, mi_col); |
| 1251 | 1249 |
| 1252 if (tmp_sad > x->pred_mv_sad[LAST_FRAME]) | 1250 if (tmp_sad > x->pred_mv_sad[LAST_FRAME]) |
| 1253 continue; | 1251 continue; |
| 1254 if (tmp_sad + (num_pels_log2_lookup[bsize] << 4) > best_pred_sad) | 1252 if (tmp_sad + (num_pels_log2_lookup[bsize] << 4) > best_pred_sad) |
| 1255 continue; | 1253 continue; |
| 1256 | 1254 |
| 1257 frame_mv[NEWMV][ref_frame].as_int = mbmi->mv[0].as_int; | 1255 frame_mv[NEWMV][ref_frame].as_int = mbmi->mv[0].as_int; |
| 1258 rate_mv = vp9_mv_bit_cost(&frame_mv[NEWMV][ref_frame].as_mv, | 1256 rate_mv = vp9_mv_bit_cost(&frame_mv[NEWMV][ref_frame].as_mv, |
| 1259 &mbmi->ref_mvs[ref_frame][0].as_mv, | 1257 &mbmi->ref_mvs[ref_frame][0].as_mv, |
| 1260 x->nmvjointcost, x->mvcost, MV_COST_WEIGHT); | 1258 x->nmvjointcost, x->mvcost, MV_COST_WEIGHT); |
| (...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1587 #else | 1585 #else |
| 1588 vp9_convolve_copy(best_pred->data, best_pred->stride, | 1586 vp9_convolve_copy(best_pred->data, best_pred->stride, |
| 1589 pd->dst.buf, pd->dst.stride, NULL, 0, | 1587 pd->dst.buf, pd->dst.stride, NULL, 0, |
| 1590 NULL, 0, bw, bh); | 1588 NULL, 0, bw, bh); |
| 1591 #endif // CONFIG_VP9_HIGHBITDEPTH | 1589 #endif // CONFIG_VP9_HIGHBITDEPTH |
| 1592 } | 1590 } |
| 1593 } | 1591 } |
| 1594 | 1592 |
| 1595 if (cpi->sf.adaptive_rd_thresh) { | 1593 if (cpi->sf.adaptive_rd_thresh) { |
| 1596 THR_MODES best_mode_idx = mode_idx[best_ref_frame][mode_offset(mbmi->mode)]; | 1594 THR_MODES best_mode_idx = mode_idx[best_ref_frame][mode_offset(mbmi->mode)]; |
| 1597 PREDICTION_MODE this_mode; | |
| 1598 | 1595 |
| 1599 if (best_ref_frame == INTRA_FRAME) { | 1596 if (best_ref_frame == INTRA_FRAME) { |
| 1600 // Only consider the modes that are included in the intra_mode_list. | 1597 // Only consider the modes that are included in the intra_mode_list. |
| 1601 int intra_modes = sizeof(intra_mode_list)/sizeof(PREDICTION_MODE); | 1598 int intra_modes = sizeof(intra_mode_list)/sizeof(PREDICTION_MODE); |
| 1602 int i; | 1599 int i; |
| 1603 | 1600 |
| 1604 // TODO(yunqingwang): Check intra mode mask and only update freq_fact | 1601 // TODO(yunqingwang): Check intra mode mask and only update freq_fact |
| 1605 // for those valid modes. | 1602 // for those valid modes. |
| 1606 for (i = 0; i < intra_modes; i++) { | 1603 for (i = 0; i < intra_modes; i++) { |
| 1607 PREDICTION_MODE this_mode = intra_mode_list[i]; | |
| 1608 update_thresh_freq_fact(cpi, tile_data, bsize, INTRA_FRAME, | 1604 update_thresh_freq_fact(cpi, tile_data, bsize, INTRA_FRAME, |
| 1609 best_mode_idx, this_mode); | 1605 best_mode_idx, intra_mode_list[i]); |
| 1610 } | 1606 } |
| 1611 } else { | 1607 } else { |
| 1612 for (ref_frame = LAST_FRAME; ref_frame <= GOLDEN_FRAME; ++ref_frame) { | 1608 for (ref_frame = LAST_FRAME; ref_frame <= GOLDEN_FRAME; ++ref_frame) { |
| 1609 PREDICTION_MODE this_mode; |
| 1613 if (best_ref_frame != ref_frame) continue; | 1610 if (best_ref_frame != ref_frame) continue; |
| 1614 for (this_mode = NEARESTMV; this_mode <= NEWMV; ++this_mode) { | 1611 for (this_mode = NEARESTMV; this_mode <= NEWMV; ++this_mode) { |
| 1615 update_thresh_freq_fact(cpi, tile_data, bsize, ref_frame, | 1612 update_thresh_freq_fact(cpi, tile_data, bsize, ref_frame, |
| 1616 best_mode_idx, this_mode); | 1613 best_mode_idx, this_mode); |
| 1617 } | 1614 } |
| 1618 } | 1615 } |
| 1619 } | 1616 } |
| 1620 } | 1617 } |
| 1621 | 1618 |
| 1622 *rd_cost = best_rdc; | 1619 *rd_cost = best_rdc; |
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1878 xd->mi[0]->bmi[block + 2] = bsi[best_ref_frame][block]; | 1875 xd->mi[0]->bmi[block + 2] = bsi[best_ref_frame][block]; |
| 1879 } | 1876 } |
| 1880 } | 1877 } |
| 1881 mbmi->mode = xd->mi[0]->bmi[3].as_mode; | 1878 mbmi->mode = xd->mi[0]->bmi[3].as_mode; |
| 1882 ctx->mic = *(xd->mi[0]); | 1879 ctx->mic = *(xd->mi[0]); |
| 1883 ctx->skip_txfm[0] = 0; | 1880 ctx->skip_txfm[0] = 0; |
| 1884 ctx->skip = 0; | 1881 ctx->skip = 0; |
| 1885 // Dummy assignment for speed -5. No effect in speed -6. | 1882 // Dummy assignment for speed -5. No effect in speed -6. |
| 1886 rd_cost->rdcost = best_rd; | 1883 rd_cost->rdcost = best_rd; |
| 1887 } | 1884 } |
| OLD | NEW |