| 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 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 #include "vp9/common/vp9_common.h" | 21 #include "vp9/common/vp9_common.h" |
| 22 #include "vp9/common/vp9_mvref_common.h" | 22 #include "vp9/common/vp9_mvref_common.h" |
| 23 #include "vp9/common/vp9_reconinter.h" | 23 #include "vp9/common/vp9_reconinter.h" |
| 24 #include "vp9/common/vp9_reconintra.h" | 24 #include "vp9/common/vp9_reconintra.h" |
| 25 | 25 |
| 26 #include "vp9/encoder/vp9_encoder.h" | 26 #include "vp9/encoder/vp9_encoder.h" |
| 27 #include "vp9/encoder/vp9_pickmode.h" | 27 #include "vp9/encoder/vp9_pickmode.h" |
| 28 #include "vp9/encoder/vp9_ratectrl.h" | 28 #include "vp9/encoder/vp9_ratectrl.h" |
| 29 #include "vp9/encoder/vp9_rd.h" | 29 #include "vp9/encoder/vp9_rd.h" |
| 30 | 30 |
| 31 typedef struct { |
| 32 uint8_t *data; |
| 33 int stride; |
| 34 int in_use; |
| 35 } PRED_BUFFER; |
| 36 |
| 31 static int mv_refs_rt(const VP9_COMMON *cm, const MACROBLOCKD *xd, | 37 static int mv_refs_rt(const VP9_COMMON *cm, const MACROBLOCKD *xd, |
| 32 const TileInfo *const tile, | 38 const TileInfo *const tile, |
| 33 MODE_INFO *mi, MV_REFERENCE_FRAME ref_frame, | 39 MODE_INFO *mi, MV_REFERENCE_FRAME ref_frame, |
| 34 int_mv *mv_ref_list, | 40 int_mv *mv_ref_list, |
| 35 int mi_row, int mi_col) { | 41 int mi_row, int mi_col) { |
| 36 const int *ref_sign_bias = cm->ref_frame_sign_bias; | 42 const int *ref_sign_bias = cm->ref_frame_sign_bias; |
| 37 int i, refmv_count = 0; | 43 int i, refmv_count = 0; |
| 38 | 44 |
| 39 const POSITION *const mv_ref_search = mv_ref_blocks[mi->mbmi.sb_type]; | 45 const POSITION *const mv_ref_search = mv_ref_blocks[mi->mbmi.sb_type]; |
| 40 | 46 |
| 41 int different_ref_found = 0; | 47 int different_ref_found = 0; |
| 42 int context_counter = 0; | 48 int context_counter = 0; |
| 43 int const_motion = 0; | 49 int const_motion = 0; |
| 44 | 50 |
| 45 // Blank the reference vector list | 51 // Blank the reference vector list |
| 46 vpx_memset(mv_ref_list, 0, sizeof(*mv_ref_list) * MAX_MV_REF_CANDIDATES); | 52 vpx_memset(mv_ref_list, 0, sizeof(*mv_ref_list) * MAX_MV_REF_CANDIDATES); |
| 47 | 53 |
| 48 // The nearest 2 blocks are treated differently | 54 // The nearest 2 blocks are treated differently |
| 49 // if the size < 8x8 we get the mv from the bmi substructure, | 55 // if the size < 8x8 we get the mv from the bmi substructure, |
| 50 // and we also need to keep a mode count. | 56 // and we also need to keep a mode count. |
| 51 for (i = 0; i < 2; ++i) { | 57 for (i = 0; i < 2; ++i) { |
| 52 const POSITION *const mv_ref = &mv_ref_search[i]; | 58 const POSITION *const mv_ref = &mv_ref_search[i]; |
| 53 if (is_inside(tile, mi_col, mi_row, cm->mi_rows, mv_ref)) { | 59 if (is_inside(tile, mi_col, mi_row, cm->mi_rows, mv_ref)) { |
| 54 const MODE_INFO *const candidate_mi = xd->mi[mv_ref->col + mv_ref->row * | 60 const MODE_INFO *const candidate_mi = xd->mi[mv_ref->col + mv_ref->row * |
| 55 xd->mi_stride]; | 61 xd->mi_stride].src_mi; |
| 56 const MB_MODE_INFO *const candidate = &candidate_mi->mbmi; | 62 const MB_MODE_INFO *const candidate = &candidate_mi->mbmi; |
| 57 // Keep counts for entropy encoding. | 63 // Keep counts for entropy encoding. |
| 58 context_counter += mode_2_counter[candidate->mode]; | 64 context_counter += mode_2_counter[candidate->mode]; |
| 59 different_ref_found = 1; | 65 different_ref_found = 1; |
| 60 | 66 |
| 61 if (candidate->ref_frame[0] == ref_frame) | 67 if (candidate->ref_frame[0] == ref_frame) |
| 62 ADD_MV_REF_LIST(get_sub_block_mv(candidate_mi, 0, mv_ref->col, -1)); | 68 ADD_MV_REF_LIST(get_sub_block_mv(candidate_mi, 0, mv_ref->col, -1)); |
| 63 } | 69 } |
| 64 } | 70 } |
| 65 | 71 |
| 66 const_motion = 1; | 72 const_motion = 1; |
| 67 | 73 |
| 68 // Check the rest of the neighbors in much the same way | 74 // Check the rest of the neighbors in much the same way |
| 69 // as before except we don't need to keep track of sub blocks or | 75 // as before except we don't need to keep track of sub blocks or |
| 70 // mode counts. | 76 // mode counts. |
| 71 for (; i < MVREF_NEIGHBOURS && !refmv_count; ++i) { | 77 for (; i < MVREF_NEIGHBOURS && !refmv_count; ++i) { |
| 72 const POSITION *const mv_ref = &mv_ref_search[i]; | 78 const POSITION *const mv_ref = &mv_ref_search[i]; |
| 73 if (is_inside(tile, mi_col, mi_row, cm->mi_rows, mv_ref)) { | 79 if (is_inside(tile, mi_col, mi_row, cm->mi_rows, mv_ref)) { |
| 74 const MB_MODE_INFO *const candidate = &xd->mi[mv_ref->col + mv_ref->row * | 80 const MB_MODE_INFO *const candidate = &xd->mi[mv_ref->col + mv_ref->row * |
| 75 xd->mi_stride]->mbmi; | 81 xd->mi_stride].src_mi->mbmi; |
| 76 different_ref_found = 1; | 82 different_ref_found = 1; |
| 77 | 83 |
| 78 if (candidate->ref_frame[0] == ref_frame) | 84 if (candidate->ref_frame[0] == ref_frame) |
| 79 ADD_MV_REF_LIST(candidate->mv[0]); | 85 ADD_MV_REF_LIST(candidate->mv[0]); |
| 80 } | 86 } |
| 81 } | 87 } |
| 82 | 88 |
| 83 // Since we couldn't find 2 mvs from the same reference frame | 89 // Since we couldn't find 2 mvs from the same reference frame |
| 84 // go back through the neighbors and find motion vectors from | 90 // go back through the neighbors and find motion vectors from |
| 85 // different reference frames. | 91 // different reference frames. |
| 86 if (different_ref_found && !refmv_count) { | 92 if (different_ref_found && !refmv_count) { |
| 87 for (i = 0; i < MVREF_NEIGHBOURS; ++i) { | 93 for (i = 0; i < MVREF_NEIGHBOURS; ++i) { |
| 88 const POSITION *mv_ref = &mv_ref_search[i]; | 94 const POSITION *mv_ref = &mv_ref_search[i]; |
| 89 if (is_inside(tile, mi_col, mi_row, cm->mi_rows, mv_ref)) { | 95 if (is_inside(tile, mi_col, mi_row, cm->mi_rows, mv_ref)) { |
| 90 const MB_MODE_INFO *const candidate = &xd->mi[mv_ref->col + mv_ref->row | 96 const MB_MODE_INFO *const candidate = &xd->mi[mv_ref->col + mv_ref->row |
| 91 * xd->mi_stride]->mbmi; | 97 * xd->mi_stride].src_mi->mbmi; |
| 92 | 98 |
| 93 // If the candidate is INTRA we don't want to consider its mv. | 99 // If the candidate is INTRA we don't want to consider its mv. |
| 94 IF_DIFF_REF_FRAME_ADD_MV(candidate); | 100 IF_DIFF_REF_FRAME_ADD_MV(candidate); |
| 95 } | 101 } |
| 96 } | 102 } |
| 97 } | 103 } |
| 98 | 104 |
| 99 Done: | 105 Done: |
| 100 | 106 |
| 101 mi->mbmi.mode_context[ref_frame] = counter_to_context[context_counter]; | 107 mi->mbmi.mode_context[ref_frame] = counter_to_context[context_counter]; |
| 102 | 108 |
| 103 // Clamp vectors | 109 // Clamp vectors |
| 104 for (i = 0; i < MAX_MV_REF_CANDIDATES; ++i) | 110 for (i = 0; i < MAX_MV_REF_CANDIDATES; ++i) |
| 105 clamp_mv_ref(&mv_ref_list[i].as_mv, xd); | 111 clamp_mv_ref(&mv_ref_list[i].as_mv, xd); |
| 106 | 112 |
| 107 return const_motion; | 113 return const_motion; |
| 108 } | 114 } |
| 109 | 115 |
| 110 static int combined_motion_search(VP9_COMP *cpi, MACROBLOCK *x, | 116 static int combined_motion_search(VP9_COMP *cpi, MACROBLOCK *x, |
| 111 BLOCK_SIZE bsize, int mi_row, int mi_col, | 117 BLOCK_SIZE bsize, int mi_row, int mi_col, |
| 112 int_mv *tmp_mv, int *rate_mv, | 118 int_mv *tmp_mv, int *rate_mv, |
| 113 int64_t best_rd_sofar) { | 119 int64_t best_rd_sofar) { |
| 114 MACROBLOCKD *xd = &x->e_mbd; | 120 MACROBLOCKD *xd = &x->e_mbd; |
| 115 MB_MODE_INFO *mbmi = &xd->mi[0]->mbmi; | 121 MB_MODE_INFO *mbmi = &xd->mi[0].src_mi->mbmi; |
| 116 struct buf_2d backup_yv12[MAX_MB_PLANE] = {{0, 0}}; | 122 struct buf_2d backup_yv12[MAX_MB_PLANE] = {{0, 0}}; |
| 117 const int step_param = cpi->sf.mv.fullpel_search_step_param; | 123 const int step_param = cpi->sf.mv.fullpel_search_step_param; |
| 118 const int sadpb = x->sadperbit16; | 124 const int sadpb = x->sadperbit16; |
| 119 MV mvp_full; | 125 MV mvp_full; |
| 120 const int ref = mbmi->ref_frame[0]; | 126 const int ref = mbmi->ref_frame[0]; |
| 121 const MV ref_mv = mbmi->ref_mvs[ref][0].as_mv; | 127 const MV ref_mv = mbmi->ref_mvs[ref][0].as_mv; |
| 122 int dis; | 128 int dis; |
| 123 int rate_mode; | 129 int rate_mode; |
| 124 const int tmp_col_min = x->mv_col_min; | 130 const int tmp_col_min = x->mv_col_min; |
| 125 const int tmp_col_max = x->mv_col_max; | 131 const int tmp_col_max = x->mv_col_max; |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 | 223 |
| 218 if (sse < dc_quant * dc_quant >> 6) | 224 if (sse < dc_quant * dc_quant >> 6) |
| 219 x->skip_txfm[0] = 1; | 225 x->skip_txfm[0] = 1; |
| 220 else if (var < ac_quant * ac_quant >> 6) | 226 else if (var < ac_quant * ac_quant >> 6) |
| 221 x->skip_txfm[0] = 2; | 227 x->skip_txfm[0] = 2; |
| 222 else | 228 else |
| 223 x->skip_txfm[0] = 0; | 229 x->skip_txfm[0] = 0; |
| 224 | 230 |
| 225 if (cpi->common.tx_mode == TX_MODE_SELECT) { | 231 if (cpi->common.tx_mode == TX_MODE_SELECT) { |
| 226 if (sse > (var << 2)) | 232 if (sse > (var << 2)) |
| 227 xd->mi[0]->mbmi.tx_size = MIN(max_txsize_lookup[bsize], | 233 xd->mi[0].src_mi->mbmi.tx_size = |
| 228 tx_mode_to_biggest_tx_size[cpi->common.tx_mode]); | 234 MIN(max_txsize_lookup[bsize], |
| 235 tx_mode_to_biggest_tx_size[cpi->common.tx_mode]); |
| 229 else | 236 else |
| 230 xd->mi[0]->mbmi.tx_size = TX_8X8; | 237 xd->mi[0].src_mi->mbmi.tx_size = TX_8X8; |
| 231 } else { | 238 } else { |
| 232 xd->mi[0]->mbmi.tx_size = MIN(max_txsize_lookup[bsize], | 239 xd->mi[0].src_mi->mbmi.tx_size = |
| 233 tx_mode_to_biggest_tx_size[cpi->common.tx_mode]); | 240 MIN(max_txsize_lookup[bsize], |
| 241 tx_mode_to_biggest_tx_size[cpi->common.tx_mode]); |
| 234 } | 242 } |
| 235 | 243 |
| 236 vp9_model_rd_from_var_lapndz(sse - var, 1 << num_pels_log2_lookup[bsize], | 244 vp9_model_rd_from_var_lapndz(sse - var, 1 << num_pels_log2_lookup[bsize], |
| 237 dc_quant >> 3, &rate, &dist); | 245 dc_quant >> 3, &rate, &dist); |
| 238 *out_rate_sum = rate >> 1; | 246 *out_rate_sum = rate >> 1; |
| 239 *out_dist_sum = dist << 3; | 247 *out_dist_sum = dist << 3; |
| 240 | 248 |
| 241 vp9_model_rd_from_var_lapndz(var, 1 << num_pels_log2_lookup[bsize], | 249 vp9_model_rd_from_var_lapndz(var, 1 << num_pels_log2_lookup[bsize], |
| 242 ac_quant >> 3, &rate, &dist); | 250 ac_quant >> 3, &rate, &dist); |
| 243 *out_rate_sum += rate; | 251 *out_rate_sum += rate; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 262 } | 270 } |
| 263 | 271 |
| 264 static void encode_breakout_test(VP9_COMP *cpi, MACROBLOCK *x, | 272 static void encode_breakout_test(VP9_COMP *cpi, MACROBLOCK *x, |
| 265 BLOCK_SIZE bsize, int mi_row, int mi_col, | 273 BLOCK_SIZE bsize, int mi_row, int mi_col, |
| 266 MV_REFERENCE_FRAME ref_frame, | 274 MV_REFERENCE_FRAME ref_frame, |
| 267 PREDICTION_MODE this_mode, | 275 PREDICTION_MODE this_mode, |
| 268 unsigned int var_y, unsigned int sse_y, | 276 unsigned int var_y, unsigned int sse_y, |
| 269 struct buf_2d yv12_mb[][MAX_MB_PLANE], | 277 struct buf_2d yv12_mb[][MAX_MB_PLANE], |
| 270 int *rate, int64_t *dist) { | 278 int *rate, int64_t *dist) { |
| 271 MACROBLOCKD *xd = &x->e_mbd; | 279 MACROBLOCKD *xd = &x->e_mbd; |
| 272 MB_MODE_INFO *mbmi = &xd->mi[0]->mbmi; | 280 MB_MODE_INFO *mbmi = &xd->mi[0].src_mi->mbmi; |
| 273 | 281 |
| 274 const BLOCK_SIZE uv_size = get_plane_block_size(bsize, &xd->plane[1]); | 282 const BLOCK_SIZE uv_size = get_plane_block_size(bsize, &xd->plane[1]); |
| 275 unsigned int var = var_y, sse = sse_y; | 283 unsigned int var = var_y, sse = sse_y; |
| 276 // Skipping threshold for ac. | 284 // Skipping threshold for ac. |
| 277 unsigned int thresh_ac; | 285 unsigned int thresh_ac; |
| 278 // Skipping threshold for dc. | 286 // Skipping threshold for dc. |
| 279 unsigned int thresh_dc; | 287 unsigned int thresh_dc; |
| 280 if (x->encode_breakout > 0) { | 288 if (x->encode_breakout > 0) { |
| 281 // Set a maximum for threshold to avoid big PSNR loss in low bit rate | 289 // Set a maximum for threshold to avoid big PSNR loss in low bit rate |
| 282 // case. Use extreme low threshold for static frames to limit | 290 // case. Use extreme low threshold for static frames to limit |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 x->plane[2].src.stride, | 332 x->plane[2].src.stride, |
| 325 xd->plane[2].dst.buf, | 333 xd->plane[2].dst.buf, |
| 326 xd->plane[2].dst.stride, &sse_v); | 334 xd->plane[2].dst.stride, &sse_v); |
| 327 | 335 |
| 328 // V skipping condition checking | 336 // V skipping condition checking |
| 329 if ((var_v * 4 <= thresh_ac) && (sse_v - var_v <= thresh_dc)) { | 337 if ((var_v * 4 <= thresh_ac) && (sse_v - var_v <= thresh_dc)) { |
| 330 x->skip = 1; | 338 x->skip = 1; |
| 331 | 339 |
| 332 // The cost of skip bit needs to be added. | 340 // The cost of skip bit needs to be added. |
| 333 *rate = cpi->inter_mode_cost[mbmi->mode_context[ref_frame]] | 341 *rate = cpi->inter_mode_cost[mbmi->mode_context[ref_frame]] |
| 334 [INTER_OFFSET(this_mode)]; | 342 [INTER_OFFSET(this_mode)]; |
| 335 | 343 |
| 336 // More on this part of rate | 344 // More on this part of rate |
| 337 // rate += vp9_cost_bit(vp9_get_skip_prob(cm, xd), 1); | 345 // rate += vp9_cost_bit(vp9_get_skip_prob(cm, xd), 1); |
| 338 | 346 |
| 339 // Scaling factor for SSE from spatial domain to frequency | 347 // Scaling factor for SSE from spatial domain to frequency |
| 340 // domain is 16. Adjust distortion accordingly. | 348 // domain is 16. Adjust distortion accordingly. |
| 341 // TODO(yunqingwang): In this function, only y-plane dist is | 349 // TODO(yunqingwang): In this function, only y-plane dist is |
| 342 // calculated. | 350 // calculated. |
| 343 *dist = (sse << 4); // + ((sse_u + sse_v) << 4); | 351 *dist = (sse << 4); // + ((sse_u + sse_v) << 4); |
| 344 | 352 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 395 } | 403 } |
| 396 | 404 |
| 397 static const THR_MODES mode_idx[MAX_REF_FRAMES - 1][INTER_MODES] = { | 405 static const THR_MODES mode_idx[MAX_REF_FRAMES - 1][INTER_MODES] = { |
| 398 {THR_NEARESTMV, THR_NEARMV, THR_ZEROMV, THR_NEWMV}, | 406 {THR_NEARESTMV, THR_NEARMV, THR_ZEROMV, THR_NEWMV}, |
| 399 {THR_NEARESTG, THR_NEARG, THR_ZEROG, THR_NEWG}, | 407 {THR_NEARESTG, THR_NEARG, THR_ZEROG, THR_NEWG}, |
| 400 {THR_NEARESTA, THR_NEARA, THR_ZEROA, THR_NEWA}, | 408 {THR_NEARESTA, THR_NEARA, THR_ZEROA, THR_NEWA}, |
| 401 }; | 409 }; |
| 402 | 410 |
| 403 // TODO(jingning) placeholder for inter-frame non-RD mode decision. | 411 // TODO(jingning) placeholder for inter-frame non-RD mode decision. |
| 404 // this needs various further optimizations. to be continued.. | 412 // this needs various further optimizations. to be continued.. |
| 405 int64_t vp9_pick_inter_mode(VP9_COMP *cpi, MACROBLOCK *x, | 413 void vp9_pick_inter_mode(VP9_COMP *cpi, MACROBLOCK *x, |
| 406 const TileInfo *const tile, | 414 const TileInfo *const tile, |
| 407 int mi_row, int mi_col, | 415 int mi_row, int mi_col, |
| 408 int *returnrate, | 416 int *returnrate, |
| 409 int64_t *returndistortion, | 417 int64_t *returndistortion, |
| 410 BLOCK_SIZE bsize, | 418 BLOCK_SIZE bsize, |
| 411 PICK_MODE_CONTEXT *ctx) { | 419 PICK_MODE_CONTEXT *ctx) { |
| 412 MACROBLOCKD *xd = &x->e_mbd; | 420 VP9_COMMON *const cm = &cpi->common; |
| 413 MB_MODE_INFO *mbmi = &xd->mi[0]->mbmi; | 421 MACROBLOCKD *const xd = &x->e_mbd; |
| 422 MB_MODE_INFO *const mbmi = &xd->mi[0].src_mi->mbmi; |
| 414 struct macroblockd_plane *const pd = &xd->plane[0]; | 423 struct macroblockd_plane *const pd = &xd->plane[0]; |
| 415 PREDICTION_MODE this_mode, best_mode = ZEROMV; | 424 PREDICTION_MODE best_mode = ZEROMV; |
| 416 MV_REFERENCE_FRAME ref_frame, best_ref_frame = LAST_FRAME; | 425 MV_REFERENCE_FRAME ref_frame, best_ref_frame = LAST_FRAME; |
| 417 TX_SIZE best_tx_size = MIN(max_txsize_lookup[bsize], | 426 TX_SIZE best_tx_size = MIN(max_txsize_lookup[bsize], |
| 418 tx_mode_to_biggest_tx_size[cpi->common.tx_mode]); | 427 tx_mode_to_biggest_tx_size[cm->tx_mode]); |
| 419 INTERP_FILTER best_pred_filter = EIGHTTAP; | 428 INTERP_FILTER best_pred_filter = EIGHTTAP; |
| 420 int_mv frame_mv[MB_MODE_COUNT][MAX_REF_FRAMES]; | 429 int_mv frame_mv[MB_MODE_COUNT][MAX_REF_FRAMES]; |
| 421 struct buf_2d yv12_mb[4][MAX_MB_PLANE]; | 430 struct buf_2d yv12_mb[4][MAX_MB_PLANE]; |
| 422 static const int flag_list[4] = { 0, VP9_LAST_FLAG, VP9_GOLD_FLAG, | 431 static const int flag_list[4] = { 0, VP9_LAST_FLAG, VP9_GOLD_FLAG, |
| 423 VP9_ALT_FLAG }; | 432 VP9_ALT_FLAG }; |
| 424 int64_t best_rd = INT64_MAX; | 433 int64_t best_rd = INT64_MAX; |
| 425 int64_t this_rd = INT64_MAX; | 434 int64_t this_rd = INT64_MAX; |
| 426 uint8_t skip_txfm = 0; | 435 uint8_t skip_txfm = 0; |
| 427 int rate = INT_MAX; | 436 int rate = INT_MAX; |
| 428 int64_t dist = INT64_MAX; | 437 int64_t dist = INT64_MAX; |
| 429 // var_y and sse_y are saved to be used in skipping checking | 438 // var_y and sse_y are saved to be used in skipping checking |
| 430 unsigned int var_y = UINT_MAX; | 439 unsigned int var_y = UINT_MAX; |
| 431 unsigned int sse_y = UINT_MAX; | 440 unsigned int sse_y = UINT_MAX; |
| 432 | 441 |
| 433 VP9_COMMON *cm = &cpi->common; | 442 const int intra_cost_penalty = |
| 434 int intra_cost_penalty = 20 * vp9_dc_quant(cm->base_qindex, cm->y_dc_delta_q); | 443 20 * vp9_dc_quant(cm->base_qindex, cm->y_dc_delta_q, cm->bit_depth); |
| 435 | |
| 436 const int64_t inter_mode_thresh = RDCOST(x->rdmult, x->rddiv, | 444 const int64_t inter_mode_thresh = RDCOST(x->rdmult, x->rddiv, |
| 437 intra_cost_penalty, 0); | 445 intra_cost_penalty, 0); |
| 438 const int64_t intra_mode_cost = 50; | 446 const int intra_mode_cost = 50; |
| 439 | 447 |
| 440 unsigned char segment_id = mbmi->segment_id; | 448 const int8_t segment_id = mbmi->segment_id; |
| 441 const int *const rd_threshes = cpi->rd.threshes[segment_id][bsize]; | 449 const int *const rd_threshes = cpi->rd.threshes[segment_id][bsize]; |
| 442 const int *const rd_thresh_freq_fact = cpi->rd.thresh_freq_fact[bsize]; | 450 const int *const rd_thresh_freq_fact = cpi->rd.thresh_freq_fact[bsize]; |
| 443 // Mode index conversion form THR_MODES to PREDICTION_MODE for a ref frame. | |
| 444 INTERP_FILTER filter_ref = cm->interp_filter; | 451 INTERP_FILTER filter_ref = cm->interp_filter; |
| 445 int bsl = mi_width_log2(bsize); | 452 const int bsl = mi_width_log2(bsize); |
| 446 const int pred_filter_search = cm->interp_filter == SWITCHABLE ? | 453 const int pred_filter_search = cm->interp_filter == SWITCHABLE ? |
| 447 (((mi_row + mi_col) >> bsl) + | 454 (((mi_row + mi_col) >> bsl) + |
| 448 get_chessboard_index(cm->current_video_frame)) & 0x1 : 0; | 455 get_chessboard_index(cm->current_video_frame)) & 0x1 : 0; |
| 449 int const_motion[MAX_REF_FRAMES] = { 0 }; | 456 int const_motion[MAX_REF_FRAMES] = { 0 }; |
| 450 const int bh = num_4x4_blocks_high_lookup[bsize] << 2; | 457 const int bh = num_4x4_blocks_high_lookup[bsize] << 2; |
| 451 const int bw = num_4x4_blocks_wide_lookup[bsize] << 2; | 458 const int bw = num_4x4_blocks_wide_lookup[bsize] << 2; |
| 452 const int pixels_in_block = bh * bw; | |
| 453 // For speed 6, the result of interp filter is reused later in actual encoding | 459 // For speed 6, the result of interp filter is reused later in actual encoding |
| 454 // process. | 460 // process. |
| 455 // tmp[3] points to dst buffer, and the other 3 point to allocated buffers. | 461 // tmp[3] points to dst buffer, and the other 3 point to allocated buffers. |
| 456 PRED_BUFFER tmp[4]; | 462 PRED_BUFFER tmp[4]; |
| 457 DECLARE_ALIGNED_ARRAY(16, uint8_t, pred_buf, 3 * 64 * 64); | 463 DECLARE_ALIGNED_ARRAY(16, uint8_t, pred_buf, 3 * 64 * 64); |
| 458 struct buf_2d orig_dst = pd->dst; | 464 struct buf_2d orig_dst = pd->dst; |
| 459 PRED_BUFFER *best_pred = NULL; | 465 PRED_BUFFER *best_pred = NULL; |
| 460 PRED_BUFFER *this_mode_pred = NULL; | 466 PRED_BUFFER *this_mode_pred = NULL; |
| 461 int i; | |
| 462 | 467 |
| 463 // CTX is used by the temporal denoiser which is currently being developed. | |
| 464 // TODO(jbb): when temporal denoiser is finished and in the default build | |
| 465 // remove the following line; | |
| 466 (void) ctx; | |
| 467 if (cpi->sf.reuse_inter_pred_sby) { | 468 if (cpi->sf.reuse_inter_pred_sby) { |
| 469 int i; |
| 468 for (i = 0; i < 3; i++) { | 470 for (i = 0; i < 3; i++) { |
| 469 tmp[i].data = &pred_buf[pixels_in_block * i]; | 471 tmp[i].data = &pred_buf[bw * bh * i]; |
| 470 tmp[i].stride = bw; | 472 tmp[i].stride = bw; |
| 471 tmp[i].in_use = 0; | 473 tmp[i].in_use = 0; |
| 472 } | 474 } |
| 473 tmp[3].data = pd->dst.buf; | 475 tmp[3].data = pd->dst.buf; |
| 474 tmp[3].stride = pd->dst.stride; | 476 tmp[3].stride = pd->dst.stride; |
| 475 tmp[3].in_use = 0; | 477 tmp[3].in_use = 0; |
| 476 } | 478 } |
| 477 | 479 |
| 478 x->skip_encode = cpi->sf.skip_encode_frame && x->q_index < QIDX_SKIP_THRESH; | 480 x->skip_encode = cpi->sf.skip_encode_frame && x->q_index < QIDX_SKIP_THRESH; |
| 479 x->skip = 0; | 481 x->skip = 0; |
| 480 | 482 |
| 481 // initialize mode decisions | 483 // initialize mode decisions |
| 482 *returnrate = INT_MAX; | 484 *returnrate = INT_MAX; |
| 483 *returndistortion = INT64_MAX; | 485 *returndistortion = INT64_MAX; |
| 484 vpx_memset(mbmi, 0, sizeof(MB_MODE_INFO)); | 486 vpx_memset(mbmi, 0, sizeof(MB_MODE_INFO)); |
| 485 mbmi->sb_type = bsize; | 487 mbmi->sb_type = bsize; |
| 486 mbmi->ref_frame[0] = NONE; | 488 mbmi->ref_frame[0] = NONE; |
| 487 mbmi->ref_frame[1] = NONE; | 489 mbmi->ref_frame[1] = NONE; |
| 488 mbmi->tx_size = MIN(max_txsize_lookup[bsize], | 490 mbmi->tx_size = MIN(max_txsize_lookup[bsize], |
| 489 tx_mode_to_biggest_tx_size[cm->tx_mode]); | 491 tx_mode_to_biggest_tx_size[cm->tx_mode]); |
| 490 mbmi->interp_filter = cm->interp_filter == SWITCHABLE ? | 492 mbmi->interp_filter = cm->interp_filter == SWITCHABLE ? |
| 491 EIGHTTAP : cm->interp_filter; | 493 EIGHTTAP : cm->interp_filter; |
| 492 mbmi->segment_id = segment_id; | 494 mbmi->segment_id = segment_id; |
| 493 | 495 |
| 494 for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) { | 496 for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) { |
| 497 PREDICTION_MODE this_mode; |
| 495 x->pred_mv_sad[ref_frame] = INT_MAX; | 498 x->pred_mv_sad[ref_frame] = INT_MAX; |
| 496 frame_mv[NEWMV][ref_frame].as_int = INVALID_MV; | 499 frame_mv[NEWMV][ref_frame].as_int = INVALID_MV; |
| 497 frame_mv[ZEROMV][ref_frame].as_int = 0; | 500 frame_mv[ZEROMV][ref_frame].as_int = 0; |
| 498 | 501 |
| 499 if (xd->up_available) | 502 if (xd->up_available) |
| 500 filter_ref = xd->mi[-xd->mi_stride]->mbmi.interp_filter; | 503 filter_ref = xd->mi[-xd->mi_stride].src_mi->mbmi.interp_filter; |
| 501 else if (xd->left_available) | 504 else if (xd->left_available) |
| 502 filter_ref = xd->mi[-1]->mbmi.interp_filter; | 505 filter_ref = xd->mi[-1].src_mi->mbmi.interp_filter; |
| 503 | 506 |
| 504 if (cpi->ref_frame_flags & flag_list[ref_frame]) { | 507 if (cpi->ref_frame_flags & flag_list[ref_frame]) { |
| 505 const YV12_BUFFER_CONFIG *yv12 = get_ref_frame_buffer(cpi, ref_frame); | 508 const YV12_BUFFER_CONFIG *yv12 = get_ref_frame_buffer(cpi, ref_frame); |
| 506 int_mv *const candidates = mbmi->ref_mvs[ref_frame]; | 509 int_mv *const candidates = mbmi->ref_mvs[ref_frame]; |
| 507 const struct scale_factors *const sf = &cm->frame_refs[ref_frame - 1].sf; | 510 const struct scale_factors *const sf = &cm->frame_refs[ref_frame - 1].sf; |
| 508 vp9_setup_pred_block(xd, yv12_mb[ref_frame], yv12, mi_row, mi_col, | 511 vp9_setup_pred_block(xd, yv12_mb[ref_frame], yv12, mi_row, mi_col, |
| 509 sf, sf); | 512 sf, sf); |
| 510 | 513 |
| 511 if (!cm->error_resilient_mode) | 514 if (!cm->error_resilient_mode) |
| 512 vp9_find_mv_refs(cm, xd, tile, xd->mi[0], ref_frame, | 515 vp9_find_mv_refs(cm, xd, tile, xd->mi[0].src_mi, ref_frame, |
| 513 candidates, mi_row, mi_col); | 516 candidates, mi_row, mi_col); |
| 514 else | 517 else |
| 515 const_motion[ref_frame] = mv_refs_rt(cm, xd, tile, xd->mi[0], | 518 const_motion[ref_frame] = mv_refs_rt(cm, xd, tile, xd->mi[0].src_mi, |
| 516 ref_frame, candidates, | 519 ref_frame, candidates, |
| 517 mi_row, mi_col); | 520 mi_row, mi_col); |
| 518 | 521 |
| 519 vp9_find_best_ref_mvs(xd, cm->allow_high_precision_mv, candidates, | 522 vp9_find_best_ref_mvs(xd, cm->allow_high_precision_mv, candidates, |
| 520 &frame_mv[NEARESTMV][ref_frame], | 523 &frame_mv[NEARESTMV][ref_frame], |
| 521 &frame_mv[NEARMV][ref_frame]); | 524 &frame_mv[NEARMV][ref_frame]); |
| 522 | 525 |
| 523 if (!vp9_is_scaled(sf) && bsize >= BLOCK_8X8) | 526 if (!vp9_is_scaled(sf) && bsize >= BLOCK_8X8) |
| 524 vp9_mv_pred(cpi, x, yv12_mb[ref_frame][0].buf, yv12->y_stride, | 527 vp9_mv_pred(cpi, x, yv12_mb[ref_frame][0].buf, yv12->y_stride, |
| 525 ref_frame, bsize); | 528 ref_frame, bsize); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 539 int rate_mv = 0; | 542 int rate_mv = 0; |
| 540 int mode_rd_thresh; | 543 int mode_rd_thresh; |
| 541 | 544 |
| 542 if (const_motion[ref_frame] && | 545 if (const_motion[ref_frame] && |
| 543 (this_mode == NEARMV || this_mode == ZEROMV)) | 546 (this_mode == NEARMV || this_mode == ZEROMV)) |
| 544 continue; | 547 continue; |
| 545 | 548 |
| 546 if (!(cpi->sf.inter_mode_mask[bsize] & (1 << this_mode))) | 549 if (!(cpi->sf.inter_mode_mask[bsize] & (1 << this_mode))) |
| 547 continue; | 550 continue; |
| 548 | 551 |
| 549 mode_rd_thresh = rd_threshes[mode_idx[ref_frame - LAST_FRAME] | 552 mode_rd_thresh = |
| 550 [INTER_OFFSET(this_mode)]]; | 553 rd_threshes[mode_idx[ref_frame - |
| 554 LAST_FRAME][INTER_OFFSET(this_mode)]]; |
| 551 if (rd_less_than_thresh(best_rd, mode_rd_thresh, | 555 if (rd_less_than_thresh(best_rd, mode_rd_thresh, |
| 552 rd_thresh_freq_fact[this_mode])) | 556 rd_thresh_freq_fact[this_mode])) |
| 553 continue; | 557 continue; |
| 554 | 558 |
| 555 if (this_mode == NEWMV) { | 559 if (this_mode == NEWMV) { |
| 556 if (this_rd < (int64_t)(1 << num_pels_log2_lookup[bsize])) | 560 if (this_rd < (int64_t)(1 << num_pels_log2_lookup[bsize])) |
| 557 continue; | 561 continue; |
| 558 if (!combined_motion_search(cpi, x, bsize, mi_row, mi_col, | 562 if (!combined_motion_search(cpi, x, bsize, mi_row, mi_col, |
| 559 &frame_mv[NEWMV][ref_frame], | 563 &frame_mv[NEWMV][ref_frame], |
| 560 &rate_mv, best_rd)) | 564 &rate_mv, best_rd)) |
| 561 continue; | 565 continue; |
| 562 } | 566 } |
| 563 | 567 |
| 564 if (this_mode != NEARESTMV && | 568 if (this_mode != NEARESTMV && |
| 565 frame_mv[this_mode][ref_frame].as_int == | 569 frame_mv[this_mode][ref_frame].as_int == |
| 566 frame_mv[NEARESTMV][ref_frame].as_int) | 570 frame_mv[NEARESTMV][ref_frame].as_int) |
| 567 continue; | 571 continue; |
| 568 | 572 |
| 569 mbmi->mode = this_mode; | 573 mbmi->mode = this_mode; |
| 570 mbmi->mv[0].as_int = frame_mv[this_mode][ref_frame].as_int; | 574 mbmi->mv[0].as_int = frame_mv[this_mode][ref_frame].as_int; |
| 571 | 575 |
| 572 // Search for the best prediction filter type, when the resulting | 576 // Search for the best prediction filter type, when the resulting |
| 573 // motion vector is at sub-pixel accuracy level for luma component, i.e., | 577 // motion vector is at sub-pixel accuracy level for luma component, i.e., |
| 574 // the last three bits are all zeros. | 578 // the last three bits are all zeros. |
| 575 if (cpi->sf.reuse_inter_pred_sby) { | 579 if (cpi->sf.reuse_inter_pred_sby) { |
| 576 if (this_mode == NEARESTMV) { | 580 if (this_mode == NEARESTMV) { |
| 577 this_mode_pred = &tmp[3]; | 581 this_mode_pred = &tmp[3]; |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 636 sse_y = pf_sse[mbmi->interp_filter]; | 640 sse_y = pf_sse[mbmi->interp_filter]; |
| 637 x->skip_txfm[0] = skip_txfm; | 641 x->skip_txfm[0] = skip_txfm; |
| 638 } else { | 642 } else { |
| 639 mbmi->interp_filter = (filter_ref == SWITCHABLE) ? EIGHTTAP: filter_ref; | 643 mbmi->interp_filter = (filter_ref == SWITCHABLE) ? EIGHTTAP: filter_ref; |
| 640 vp9_build_inter_predictors_sby(xd, mi_row, mi_col, bsize); | 644 vp9_build_inter_predictors_sby(xd, mi_row, mi_col, bsize); |
| 641 model_rd_for_sb_y(cpi, bsize, x, xd, &rate, &dist, &var_y, &sse_y); | 645 model_rd_for_sb_y(cpi, bsize, x, xd, &rate, &dist, &var_y, &sse_y); |
| 642 } | 646 } |
| 643 | 647 |
| 644 rate += rate_mv; | 648 rate += rate_mv; |
| 645 rate += cpi->inter_mode_cost[mbmi->mode_context[ref_frame]] | 649 rate += cpi->inter_mode_cost[mbmi->mode_context[ref_frame]] |
| 646 [INTER_OFFSET(this_mode)]; | 650 [INTER_OFFSET(this_mode)]; |
| 647 this_rd = RDCOST(x->rdmult, x->rddiv, rate, dist); | 651 this_rd = RDCOST(x->rdmult, x->rddiv, rate, dist); |
| 648 | 652 |
| 649 // Skipping checking: test to see if this block can be reconstructed by | 653 // Skipping checking: test to see if this block can be reconstructed by |
| 650 // prediction only. | 654 // prediction only. |
| 651 if (cpi->allow_encode_breakout) { | 655 if (cpi->allow_encode_breakout) { |
| 652 encode_breakout_test(cpi, x, bsize, mi_row, mi_col, ref_frame, | 656 encode_breakout_test(cpi, x, bsize, mi_row, mi_col, ref_frame, |
| 653 this_mode, var_y, sse_y, yv12_mb, &rate, &dist); | 657 this_mode, var_y, sse_y, yv12_mb, &rate, &dist); |
| 654 if (x->skip) { | 658 if (x->skip) { |
| 655 rate += rate_mv; | 659 rate += rate_mv; |
| 656 this_rd = RDCOST(x->rdmult, x->rddiv, rate, dist); | 660 this_rd = RDCOST(x->rdmult, x->rddiv, rate, dist); |
| 657 } | 661 } |
| 658 } | 662 } |
| 659 | 663 |
| 660 #if CONFIG_VP9_TEMPORAL_DENOISING | 664 #if CONFIG_VP9_TEMPORAL_DENOISING |
| 661 if (cpi->oxcf.noise_sensitivity > 0) { | 665 if (cpi->oxcf.noise_sensitivity > 0) { |
| 662 vp9_denoiser_update_frame_stats(mbmi, sse_y, this_mode, ctx); | 666 vp9_denoiser_update_frame_stats(mbmi, sse_y, this_mode, ctx); |
| 663 } | 667 } |
| 668 #else |
| 669 (void)ctx; |
| 664 #endif | 670 #endif |
| 665 | 671 |
| 666 if (this_rd < best_rd || x->skip) { | 672 if (this_rd < best_rd || x->skip) { |
| 667 best_rd = this_rd; | 673 best_rd = this_rd; |
| 668 *returnrate = rate; | 674 *returnrate = rate; |
| 669 *returndistortion = dist; | 675 *returndistortion = dist; |
| 670 best_mode = this_mode; | 676 best_mode = this_mode; |
| 671 best_pred_filter = mbmi->interp_filter; | 677 best_pred_filter = mbmi->interp_filter; |
| 672 best_tx_size = mbmi->tx_size; | 678 best_tx_size = mbmi->tx_size; |
| 673 best_ref_frame = ref_frame; | 679 best_ref_frame = ref_frame; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 689 // If the current reference frame is valid and we found a usable mode, | 695 // If the current reference frame is valid and we found a usable mode, |
| 690 // we are done. | 696 // we are done. |
| 691 if (best_rd < INT64_MAX) | 697 if (best_rd < INT64_MAX) |
| 692 break; | 698 break; |
| 693 } | 699 } |
| 694 | 700 |
| 695 // If best prediction is not in dst buf, then copy the prediction block from | 701 // If best prediction is not in dst buf, then copy the prediction block from |
| 696 // temp buf to dst buf. | 702 // temp buf to dst buf. |
| 697 if (best_pred != NULL && cpi->sf.reuse_inter_pred_sby && | 703 if (best_pred != NULL && cpi->sf.reuse_inter_pred_sby && |
| 698 best_pred->data != orig_dst.buf) { | 704 best_pred->data != orig_dst.buf) { |
| 699 uint8_t *copy_from, *copy_to; | |
| 700 | |
| 701 pd->dst = orig_dst; | 705 pd->dst = orig_dst; |
| 702 copy_to = pd->dst.buf; | 706 vp9_convolve_copy(best_pred->data, bw, pd->dst.buf, pd->dst.stride, NULL, 0, |
| 703 | 707 NULL, 0, bw, bh); |
| 704 copy_from = best_pred->data; | |
| 705 | |
| 706 vp9_convolve_copy(copy_from, bw, copy_to, pd->dst.stride, NULL, 0, NULL, 0, | |
| 707 bw, bh); | |
| 708 } | 708 } |
| 709 | 709 |
| 710 mbmi->mode = best_mode; | 710 mbmi->mode = best_mode; |
| 711 mbmi->interp_filter = best_pred_filter; | 711 mbmi->interp_filter = best_pred_filter; |
| 712 mbmi->tx_size = best_tx_size; | 712 mbmi->tx_size = best_tx_size; |
| 713 mbmi->ref_frame[0] = best_ref_frame; | 713 mbmi->ref_frame[0] = best_ref_frame; |
| 714 mbmi->mv[0].as_int = frame_mv[best_mode][best_ref_frame].as_int; | 714 mbmi->mv[0].as_int = frame_mv[best_mode][best_ref_frame].as_int; |
| 715 xd->mi[0]->bmi[0].as_mv[0].as_int = mbmi->mv[0].as_int; | 715 xd->mi[0].src_mi->bmi[0].as_mv[0].as_int = mbmi->mv[0].as_int; |
| 716 x->skip_txfm[0] = skip_txfm; | 716 x->skip_txfm[0] = skip_txfm; |
| 717 | 717 |
| 718 // Perform intra prediction search, if the best SAD is above a certain | 718 // Perform intra prediction search, if the best SAD is above a certain |
| 719 // threshold. | 719 // threshold. |
| 720 if (!x->skip && best_rd > inter_mode_thresh && | 720 if (!x->skip && best_rd > inter_mode_thresh && |
| 721 bsize <= cpi->sf.max_intra_bsize) { | 721 bsize <= cpi->sf.max_intra_bsize) { |
| 722 PREDICTION_MODE this_mode; |
| 722 struct estimate_block_intra_args args = { cpi, x, DC_PRED, 0, 0 }; | 723 struct estimate_block_intra_args args = { cpi, x, DC_PRED, 0, 0 }; |
| 723 | |
| 724 const TX_SIZE intra_tx_size = | 724 const TX_SIZE intra_tx_size = |
| 725 MIN(max_txsize_lookup[bsize], | 725 MIN(max_txsize_lookup[bsize], |
| 726 tx_mode_to_biggest_tx_size[cpi->common.tx_mode]); | 726 tx_mode_to_biggest_tx_size[cpi->common.tx_mode]); |
| 727 | 727 |
| 728 if (cpi->sf.reuse_inter_pred_sby) { | 728 if (cpi->sf.reuse_inter_pred_sby) { |
| 729 pd->dst.buf = tmp[0].data; | 729 pd->dst.buf = tmp[0].data; |
| 730 pd->dst.stride = bw; | 730 pd->dst.stride = bw; |
| 731 } | 731 } |
| 732 | 732 |
| 733 for (this_mode = DC_PRED; this_mode <= DC_PRED; ++this_mode) { | 733 for (this_mode = DC_PRED; this_mode <= DC_PRED; ++this_mode) { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 754 mbmi->ref_frame[0] = INTRA_FRAME; | 754 mbmi->ref_frame[0] = INTRA_FRAME; |
| 755 mbmi->uv_mode = this_mode; | 755 mbmi->uv_mode = this_mode; |
| 756 mbmi->mv[0].as_int = INVALID_MV; | 756 mbmi->mv[0].as_int = INVALID_MV; |
| 757 } else { | 757 } else { |
| 758 x->skip_txfm[0] = skip_txfm; | 758 x->skip_txfm[0] = skip_txfm; |
| 759 } | 759 } |
| 760 } | 760 } |
| 761 if (cpi->sf.reuse_inter_pred_sby) | 761 if (cpi->sf.reuse_inter_pred_sby) |
| 762 pd->dst = orig_dst; | 762 pd->dst = orig_dst; |
| 763 } | 763 } |
| 764 | |
| 765 return INT64_MAX; | |
| 766 } | 764 } |
| OLD | NEW |