| 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 23 matching lines...) Expand all Loading... |
| 34 #include "vp9/encoder/vp9_mcomp.h" | 34 #include "vp9/encoder/vp9_mcomp.h" |
| 35 #include "vp9/encoder/vp9_quantize.h" | 35 #include "vp9/encoder/vp9_quantize.h" |
| 36 #include "vp9/encoder/vp9_ratectrl.h" | 36 #include "vp9/encoder/vp9_ratectrl.h" |
| 37 #include "vp9/encoder/vp9_rd.h" | 37 #include "vp9/encoder/vp9_rd.h" |
| 38 #include "vp9/encoder/vp9_rdopt.h" | 38 #include "vp9/encoder/vp9_rdopt.h" |
| 39 #include "vp9/encoder/vp9_variance.h" | 39 #include "vp9/encoder/vp9_variance.h" |
| 40 | 40 |
| 41 #define RD_THRESH_MAX_FACT 64 | 41 #define RD_THRESH_MAX_FACT 64 |
| 42 #define RD_THRESH_INC 1 | 42 #define RD_THRESH_INC 1 |
| 43 | 43 |
| 44 #define LAST_FRAME_MODE_MASK 0xFFEDCD60 | 44 #define LAST_FRAME_MODE_MASK ((1 << GOLDEN_FRAME) | (1 << ALTREF_FRAME) | \ |
| 45 #define GOLDEN_FRAME_MODE_MASK 0xFFDA3BB0 | 45 (1 << INTRA_FRAME)) |
| 46 #define ALT_REF_MODE_MASK 0xFFC648D0 | 46 #define GOLDEN_FRAME_MODE_MASK ((1 << LAST_FRAME) | (1 << ALTREF_FRAME) | \ |
| 47 (1 << INTRA_FRAME)) |
| 48 #define ALT_REF_MODE_MASK ((1 << LAST_FRAME) | (1 << GOLDEN_FRAME) | \ |
| 49 (1 << INTRA_FRAME)) |
| 50 |
| 51 #define SECOND_REF_FRAME_MASK ((1 << ALTREF_FRAME) | 0x01) |
| 47 | 52 |
| 48 #define MIN_EARLY_TERM_INDEX 3 | 53 #define MIN_EARLY_TERM_INDEX 3 |
| 49 | 54 |
| 50 typedef struct { | 55 typedef struct { |
| 51 PREDICTION_MODE mode; | 56 PREDICTION_MODE mode; |
| 52 MV_REFERENCE_FRAME ref_frame[2]; | 57 MV_REFERENCE_FRAME ref_frame[2]; |
| 53 } MODE_DEFINITION; | 58 } MODE_DEFINITION; |
| 54 | 59 |
| 55 typedef struct { | 60 typedef struct { |
| 56 MV_REFERENCE_FRAME ref_frame[2]; | 61 MV_REFERENCE_FRAME ref_frame[2]; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 79 {NEARESTMV, {GOLDEN_FRAME, NONE}}, | 84 {NEARESTMV, {GOLDEN_FRAME, NONE}}, |
| 80 | 85 |
| 81 {DC_PRED, {INTRA_FRAME, NONE}}, | 86 {DC_PRED, {INTRA_FRAME, NONE}}, |
| 82 | 87 |
| 83 {NEWMV, {LAST_FRAME, NONE}}, | 88 {NEWMV, {LAST_FRAME, NONE}}, |
| 84 {NEWMV, {ALTREF_FRAME, NONE}}, | 89 {NEWMV, {ALTREF_FRAME, NONE}}, |
| 85 {NEWMV, {GOLDEN_FRAME, NONE}}, | 90 {NEWMV, {GOLDEN_FRAME, NONE}}, |
| 86 | 91 |
| 87 {NEARMV, {LAST_FRAME, NONE}}, | 92 {NEARMV, {LAST_FRAME, NONE}}, |
| 88 {NEARMV, {ALTREF_FRAME, NONE}}, | 93 {NEARMV, {ALTREF_FRAME, NONE}}, |
| 94 {NEARMV, {GOLDEN_FRAME, NONE}}, |
| 95 |
| 96 {ZEROMV, {LAST_FRAME, NONE}}, |
| 97 {ZEROMV, {GOLDEN_FRAME, NONE}}, |
| 98 {ZEROMV, {ALTREF_FRAME, NONE}}, |
| 99 |
| 89 {NEARESTMV, {LAST_FRAME, ALTREF_FRAME}}, | 100 {NEARESTMV, {LAST_FRAME, ALTREF_FRAME}}, |
| 90 {NEARESTMV, {GOLDEN_FRAME, ALTREF_FRAME}}, | 101 {NEARESTMV, {GOLDEN_FRAME, ALTREF_FRAME}}, |
| 91 | 102 |
| 92 {TM_PRED, {INTRA_FRAME, NONE}}, | 103 {TM_PRED, {INTRA_FRAME, NONE}}, |
| 93 | 104 |
| 94 {NEARMV, {LAST_FRAME, ALTREF_FRAME}}, | 105 {NEARMV, {LAST_FRAME, ALTREF_FRAME}}, |
| 95 {NEWMV, {LAST_FRAME, ALTREF_FRAME}}, | 106 {NEWMV, {LAST_FRAME, ALTREF_FRAME}}, |
| 96 {NEARMV, {GOLDEN_FRAME, NONE}}, | |
| 97 {NEARMV, {GOLDEN_FRAME, ALTREF_FRAME}}, | 107 {NEARMV, {GOLDEN_FRAME, ALTREF_FRAME}}, |
| 98 {NEWMV, {GOLDEN_FRAME, ALTREF_FRAME}}, | 108 {NEWMV, {GOLDEN_FRAME, ALTREF_FRAME}}, |
| 99 | 109 |
| 100 {ZEROMV, {LAST_FRAME, NONE}}, | |
| 101 {ZEROMV, {GOLDEN_FRAME, NONE}}, | |
| 102 {ZEROMV, {ALTREF_FRAME, NONE}}, | |
| 103 {ZEROMV, {LAST_FRAME, ALTREF_FRAME}}, | 110 {ZEROMV, {LAST_FRAME, ALTREF_FRAME}}, |
| 104 {ZEROMV, {GOLDEN_FRAME, ALTREF_FRAME}}, | 111 {ZEROMV, {GOLDEN_FRAME, ALTREF_FRAME}}, |
| 105 | 112 |
| 106 {H_PRED, {INTRA_FRAME, NONE}}, | 113 {H_PRED, {INTRA_FRAME, NONE}}, |
| 107 {V_PRED, {INTRA_FRAME, NONE}}, | 114 {V_PRED, {INTRA_FRAME, NONE}}, |
| 108 {D135_PRED, {INTRA_FRAME, NONE}}, | 115 {D135_PRED, {INTRA_FRAME, NONE}}, |
| 109 {D207_PRED, {INTRA_FRAME, NONE}}, | 116 {D207_PRED, {INTRA_FRAME, NONE}}, |
| 110 {D153_PRED, {INTRA_FRAME, NONE}}, | 117 {D153_PRED, {INTRA_FRAME, NONE}}, |
| 111 {D63_PRED, {INTRA_FRAME, NONE}}, | 118 {D63_PRED, {INTRA_FRAME, NONE}}, |
| 112 {D117_PRED, {INTRA_FRAME, NONE}}, | 119 {D117_PRED, {INTRA_FRAME, NONE}}, |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 | 169 |
| 163 static void model_rd_for_sb(VP9_COMP *cpi, BLOCK_SIZE bsize, | 170 static void model_rd_for_sb(VP9_COMP *cpi, BLOCK_SIZE bsize, |
| 164 MACROBLOCK *x, MACROBLOCKD *xd, | 171 MACROBLOCK *x, MACROBLOCKD *xd, |
| 165 int *out_rate_sum, int64_t *out_dist_sum) { | 172 int *out_rate_sum, int64_t *out_dist_sum) { |
| 166 // Note our transform coeffs are 8 times an orthogonal transform. | 173 // Note our transform coeffs are 8 times an orthogonal transform. |
| 167 // Hence quantizer step is also 8 times. To get effective quantizer | 174 // Hence quantizer step is also 8 times. To get effective quantizer |
| 168 // we need to divide by 8 before sending to modeling function. | 175 // we need to divide by 8 before sending to modeling function. |
| 169 int i; | 176 int i; |
| 170 int64_t rate_sum = 0; | 177 int64_t rate_sum = 0; |
| 171 int64_t dist_sum = 0; | 178 int64_t dist_sum = 0; |
| 172 const int ref = xd->mi[0]->mbmi.ref_frame[0]; | 179 const int ref = xd->mi[0].src_mi->mbmi.ref_frame[0]; |
| 173 unsigned int sse; | 180 unsigned int sse; |
| 174 unsigned int var = 0; | 181 unsigned int var = 0; |
| 175 unsigned int sum_sse = 0; | 182 unsigned int sum_sse = 0; |
| 176 const int shift = 8; | 183 const int shift = 8; |
| 177 int rate; | 184 int rate; |
| 178 int64_t dist; | 185 int64_t dist; |
| 179 | 186 |
| 180 x->pred_sse[ref] = 0; | 187 x->pred_sse[ref] = 0; |
| 181 | 188 |
| 182 for (i = 0; i < MAX_MB_PLANE; ++i) { | 189 for (i = 0; i < MAX_MB_PLANE; ++i) { |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 pd->dequant[1] >> 3, &rate, &dist); | 244 pd->dequant[1] >> 3, &rate, &dist); |
| 238 rate_sum += rate; | 245 rate_sum += rate; |
| 239 dist_sum += dist; | 246 dist_sum += dist; |
| 240 } | 247 } |
| 241 } | 248 } |
| 242 | 249 |
| 243 *out_rate_sum = (int)rate_sum; | 250 *out_rate_sum = (int)rate_sum; |
| 244 *out_dist_sum = dist_sum << 4; | 251 *out_dist_sum = dist_sum << 4; |
| 245 } | 252 } |
| 246 | 253 |
| 247 int64_t vp9_block_error_c(const int16_t *coeff, const int16_t *dqcoeff, | 254 int64_t vp9_block_error_c(const tran_low_t *coeff, const tran_low_t *dqcoeff, |
| 248 intptr_t block_size, int64_t *ssz) { | 255 intptr_t block_size, int64_t *ssz) { |
| 249 int i; | 256 int i; |
| 250 int64_t error = 0, sqcoeff = 0; | 257 int64_t error = 0, sqcoeff = 0; |
| 251 | 258 |
| 252 for (i = 0; i < block_size; i++) { | 259 for (i = 0; i < block_size; i++) { |
| 253 const int diff = coeff[i] - dqcoeff[i]; | 260 const int diff = coeff[i] - dqcoeff[i]; |
| 254 error += diff * diff; | 261 error += diff * diff; |
| 255 sqcoeff += coeff[i] * coeff[i]; | 262 sqcoeff += coeff[i] * coeff[i]; |
| 256 } | 263 } |
| 257 | 264 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 270 { 1, 2, 3, 4, 11, 256 - 21, 0 }, | 277 { 1, 2, 3, 4, 11, 256 - 21, 0 }, |
| 271 { 1, 2, 3, 4, 11, 1024 - 21, 0 }, | 278 { 1, 2, 3, 4, 11, 1024 - 21, 0 }, |
| 272 }; | 279 }; |
| 273 static INLINE int cost_coeffs(MACROBLOCK *x, | 280 static INLINE int cost_coeffs(MACROBLOCK *x, |
| 274 int plane, int block, | 281 int plane, int block, |
| 275 ENTROPY_CONTEXT *A, ENTROPY_CONTEXT *L, | 282 ENTROPY_CONTEXT *A, ENTROPY_CONTEXT *L, |
| 276 TX_SIZE tx_size, | 283 TX_SIZE tx_size, |
| 277 const int16_t *scan, const int16_t *nb, | 284 const int16_t *scan, const int16_t *nb, |
| 278 int use_fast_coef_costing) { | 285 int use_fast_coef_costing) { |
| 279 MACROBLOCKD *const xd = &x->e_mbd; | 286 MACROBLOCKD *const xd = &x->e_mbd; |
| 280 MB_MODE_INFO *mbmi = &xd->mi[0]->mbmi; | 287 MB_MODE_INFO *mbmi = &xd->mi[0].src_mi->mbmi; |
| 281 const struct macroblock_plane *p = &x->plane[plane]; | 288 const struct macroblock_plane *p = &x->plane[plane]; |
| 282 const struct macroblockd_plane *pd = &xd->plane[plane]; | 289 const struct macroblockd_plane *pd = &xd->plane[plane]; |
| 283 const PLANE_TYPE type = pd->plane_type; | 290 const PLANE_TYPE type = pd->plane_type; |
| 284 const int16_t *band_count = &band_counts[tx_size][1]; | 291 const int16_t *band_count = &band_counts[tx_size][1]; |
| 285 const int eob = p->eobs[block]; | 292 const int eob = p->eobs[block]; |
| 286 const int16_t *const qcoeff = BLOCK_OFFSET(p->qcoeff, block); | 293 const tran_low_t *const qcoeff = BLOCK_OFFSET(p->qcoeff, block); |
| 287 unsigned int (*token_costs)[2][COEFF_CONTEXTS][ENTROPY_TOKENS] = | 294 unsigned int (*token_costs)[2][COEFF_CONTEXTS][ENTROPY_TOKENS] = |
| 288 x->token_costs[tx_size][type][is_inter_block(mbmi)]; | 295 x->token_costs[tx_size][type][is_inter_block(mbmi)]; |
| 289 uint8_t token_cache[32 * 32]; | 296 uint8_t token_cache[32 * 32]; |
| 290 int pt = combine_entropy_contexts(*A, *L); | 297 int pt = combine_entropy_contexts(*A, *L); |
| 291 int c, cost; | 298 int c, cost; |
| 292 // Check for consistency of tx_size with mode info | 299 // Check for consistency of tx_size with mode info |
| 293 assert(type == PLANE_TYPE_Y ? mbmi->tx_size == tx_size | 300 assert(type == PLANE_TYPE_Y ? mbmi->tx_size == tx_size |
| 294 : get_uv_tx_size(mbmi, pd) == tx_size); | 301 : get_uv_tx_size(mbmi, pd) == tx_size); |
| 295 | 302 |
| 296 if (eob == 0) { | 303 if (eob == 0) { |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 346 } | 353 } |
| 347 static void dist_block(int plane, int block, TX_SIZE tx_size, | 354 static void dist_block(int plane, int block, TX_SIZE tx_size, |
| 348 struct rdcost_block_args* args) { | 355 struct rdcost_block_args* args) { |
| 349 const int ss_txfrm_size = tx_size << 1; | 356 const int ss_txfrm_size = tx_size << 1; |
| 350 MACROBLOCK* const x = args->x; | 357 MACROBLOCK* const x = args->x; |
| 351 MACROBLOCKD* const xd = &x->e_mbd; | 358 MACROBLOCKD* const xd = &x->e_mbd; |
| 352 const struct macroblock_plane *const p = &x->plane[plane]; | 359 const struct macroblock_plane *const p = &x->plane[plane]; |
| 353 const struct macroblockd_plane *const pd = &xd->plane[plane]; | 360 const struct macroblockd_plane *const pd = &xd->plane[plane]; |
| 354 int64_t this_sse; | 361 int64_t this_sse; |
| 355 int shift = tx_size == TX_32X32 ? 0 : 2; | 362 int shift = tx_size == TX_32X32 ? 0 : 2; |
| 356 int16_t *const coeff = BLOCK_OFFSET(p->coeff, block); | 363 tran_low_t *const coeff = BLOCK_OFFSET(p->coeff, block); |
| 357 int16_t *const dqcoeff = BLOCK_OFFSET(pd->dqcoeff, block); | 364 tran_low_t *const dqcoeff = BLOCK_OFFSET(pd->dqcoeff, block); |
| 358 args->dist = vp9_block_error(coeff, dqcoeff, 16 << ss_txfrm_size, | 365 args->dist = vp9_block_error(coeff, dqcoeff, 16 << ss_txfrm_size, |
| 359 &this_sse) >> shift; | 366 &this_sse) >> shift; |
| 360 args->sse = this_sse >> shift; | 367 args->sse = this_sse >> shift; |
| 361 | 368 |
| 362 if (x->skip_encode && !is_inter_block(&xd->mi[0]->mbmi)) { | 369 if (x->skip_encode && !is_inter_block(&xd->mi[0].src_mi->mbmi)) { |
| 363 // TODO(jingning): tune the model to better capture the distortion. | 370 // TODO(jingning): tune the model to better capture the distortion. |
| 364 int64_t p = (pd->dequant[1] * pd->dequant[1] * | 371 int64_t p = (pd->dequant[1] * pd->dequant[1] * |
| 365 (1 << ss_txfrm_size)) >> (shift + 2); | 372 (1 << ss_txfrm_size)) >> (shift + 2); |
| 366 args->dist += (p >> 4); | 373 args->dist += (p >> 4); |
| 367 args->sse += p; | 374 args->sse += p; |
| 368 } | 375 } |
| 369 } | 376 } |
| 370 | 377 |
| 371 static void rate_block(int plane, int block, BLOCK_SIZE plane_bsize, | 378 static void rate_block(int plane, int block, BLOCK_SIZE plane_bsize, |
| 372 TX_SIZE tx_size, struct rdcost_block_args* args) { | 379 TX_SIZE tx_size, struct rdcost_block_args* args) { |
| 373 int x_idx, y_idx; | 380 int x_idx, y_idx; |
| 374 txfrm_block_to_raster_xy(plane_bsize, tx_size, block, &x_idx, &y_idx); | 381 txfrm_block_to_raster_xy(plane_bsize, tx_size, block, &x_idx, &y_idx); |
| 375 | 382 |
| 376 args->rate = cost_coeffs(args->x, plane, block, args->t_above + x_idx, | 383 args->rate = cost_coeffs(args->x, plane, block, args->t_above + x_idx, |
| 377 args->t_left + y_idx, tx_size, | 384 args->t_left + y_idx, tx_size, |
| 378 args->so->scan, args->so->neighbors, | 385 args->so->scan, args->so->neighbors, |
| 379 args->use_fast_coef_costing); | 386 args->use_fast_coef_costing); |
| 380 } | 387 } |
| 381 | 388 |
| 382 static void block_rd_txfm(int plane, int block, BLOCK_SIZE plane_bsize, | 389 static void block_rd_txfm(int plane, int block, BLOCK_SIZE plane_bsize, |
| 383 TX_SIZE tx_size, void *arg) { | 390 TX_SIZE tx_size, void *arg) { |
| 384 struct rdcost_block_args *args = arg; | 391 struct rdcost_block_args *args = arg; |
| 385 MACROBLOCK *const x = args->x; | 392 MACROBLOCK *const x = args->x; |
| 386 MACROBLOCKD *const xd = &x->e_mbd; | 393 MACROBLOCKD *const xd = &x->e_mbd; |
| 387 MB_MODE_INFO *const mbmi = &xd->mi[0]->mbmi; | 394 MB_MODE_INFO *const mbmi = &xd->mi[0].src_mi->mbmi; |
| 388 int64_t rd1, rd2, rd; | 395 int64_t rd1, rd2, rd; |
| 389 | 396 |
| 390 if (args->skip) | 397 if (args->skip) |
| 391 return; | 398 return; |
| 392 | 399 |
| 393 if (!is_inter_block(mbmi)) { | 400 if (!is_inter_block(mbmi)) { |
| 394 vp9_encode_block_intra(x, plane, block, plane_bsize, tx_size, &mbmi->skip); | 401 vp9_encode_block_intra(x, plane, block, plane_bsize, tx_size, &mbmi->skip); |
| 395 dist_block(plane, block, tx_size, args); | 402 dist_block(plane, block, tx_size, args); |
| 396 } else if (max_txsize_lookup[plane_bsize] == tx_size) { | 403 } else if (max_txsize_lookup[plane_bsize] == tx_size) { |
| 397 if (x->skip_txfm[(plane << 2) + (block >> (tx_size << 1))] == 0) { | 404 if (x->skip_txfm[(plane << 2) + (block >> (tx_size << 1))] == 0) { |
| 398 // full forward transform and quantization | 405 // full forward transform and quantization |
| 399 vp9_xform_quant(x, plane, block, plane_bsize, tx_size); | 406 vp9_xform_quant(x, plane, block, plane_bsize, tx_size); |
| 400 dist_block(plane, block, tx_size, args); | 407 dist_block(plane, block, tx_size, args); |
| 401 } else if (x->skip_txfm[(plane << 2) + (block >> (tx_size << 1))] == 2) { | 408 } else if (x->skip_txfm[(plane << 2) + (block >> (tx_size << 1))] == 2) { |
| 402 // compute DC coefficient | 409 // compute DC coefficient |
| 403 int16_t *const coeff = BLOCK_OFFSET(x->plane[plane].coeff, block); | 410 tran_low_t *const coeff = BLOCK_OFFSET(x->plane[plane].coeff, block); |
| 404 int16_t *const dqcoeff = BLOCK_OFFSET(xd->plane[plane].dqcoeff, block); | 411 tran_low_t *const dqcoeff = BLOCK_OFFSET(xd->plane[plane].dqcoeff, block); |
| 405 vp9_xform_quant_dc(x, plane, block, plane_bsize, tx_size); | 412 vp9_xform_quant_dc(x, plane, block, plane_bsize, tx_size); |
| 406 args->sse = x->bsse[(plane << 2) + (block >> (tx_size << 1))] << 4; | 413 args->sse = x->bsse[(plane << 2) + (block >> (tx_size << 1))] << 4; |
| 407 args->dist = args->sse; | 414 args->dist = args->sse; |
| 408 if (!x->plane[plane].eobs[block]) | 415 if (!x->plane[plane].eobs[block]) |
| 409 args->dist = args->sse - ((coeff[0] * coeff[0] - | 416 args->dist = args->sse - ((coeff[0] * coeff[0] - |
| 410 (coeff[0] - dqcoeff[0]) * (coeff[0] - dqcoeff[0])) >> 2); | 417 (coeff[0] - dqcoeff[0]) * (coeff[0] - dqcoeff[0])) >> 2); |
| 411 } else { | 418 } else { |
| 412 // skip forward transform | 419 // skip forward transform |
| 413 x->plane[plane].eobs[block] = 0; | 420 x->plane[plane].eobs[block] = 0; |
| 414 args->sse = x->bsse[(plane << 2) + (block >> (tx_size << 1))] << 4; | 421 args->sse = x->bsse[(plane << 2) + (block >> (tx_size << 1))] << 4; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 449 int use_fast_coef_casting) { | 456 int use_fast_coef_casting) { |
| 450 MACROBLOCKD *const xd = &x->e_mbd; | 457 MACROBLOCKD *const xd = &x->e_mbd; |
| 451 const struct macroblockd_plane *const pd = &xd->plane[plane]; | 458 const struct macroblockd_plane *const pd = &xd->plane[plane]; |
| 452 struct rdcost_block_args args; | 459 struct rdcost_block_args args; |
| 453 vp9_zero(args); | 460 vp9_zero(args); |
| 454 args.x = x; | 461 args.x = x; |
| 455 args.best_rd = ref_best_rd; | 462 args.best_rd = ref_best_rd; |
| 456 args.use_fast_coef_costing = use_fast_coef_casting; | 463 args.use_fast_coef_costing = use_fast_coef_casting; |
| 457 | 464 |
| 458 if (plane == 0) | 465 if (plane == 0) |
| 459 xd->mi[0]->mbmi.tx_size = tx_size; | 466 xd->mi[0].src_mi->mbmi.tx_size = tx_size; |
| 460 | 467 |
| 461 vp9_get_entropy_contexts(bsize, tx_size, pd, args.t_above, args.t_left); | 468 vp9_get_entropy_contexts(bsize, tx_size, pd, args.t_above, args.t_left); |
| 462 | 469 |
| 463 args.so = get_scan(xd, tx_size, pd->plane_type, 0); | 470 args.so = get_scan(xd, tx_size, pd->plane_type, 0); |
| 464 | 471 |
| 465 vp9_foreach_transformed_block_in_plane(xd, bsize, plane, | 472 vp9_foreach_transformed_block_in_plane(xd, bsize, plane, |
| 466 block_rd_txfm, &args); | 473 block_rd_txfm, &args); |
| 467 if (args.skip) { | 474 if (args.skip) { |
| 468 *rate = INT_MAX; | 475 *rate = INT_MAX; |
| 469 *distortion = INT64_MAX; | 476 *distortion = INT64_MAX; |
| 470 *sse = INT64_MAX; | 477 *sse = INT64_MAX; |
| 471 *skippable = 0; | 478 *skippable = 0; |
| 472 } else { | 479 } else { |
| 473 *distortion = args.this_dist; | 480 *distortion = args.this_dist; |
| 474 *rate = args.this_rate; | 481 *rate = args.this_rate; |
| 475 *sse = args.this_sse; | 482 *sse = args.this_sse; |
| 476 *skippable = vp9_is_skippable_in_plane(x, bsize, plane); | 483 *skippable = vp9_is_skippable_in_plane(x, bsize, plane); |
| 477 } | 484 } |
| 478 } | 485 } |
| 479 | 486 |
| 480 static void choose_largest_tx_size(VP9_COMP *cpi, MACROBLOCK *x, | 487 static void choose_largest_tx_size(VP9_COMP *cpi, MACROBLOCK *x, |
| 481 int *rate, int64_t *distortion, | 488 int *rate, int64_t *distortion, |
| 482 int *skip, int64_t *sse, | 489 int *skip, int64_t *sse, |
| 483 int64_t ref_best_rd, | 490 int64_t ref_best_rd, |
| 484 BLOCK_SIZE bs) { | 491 BLOCK_SIZE bs) { |
| 485 const TX_SIZE max_tx_size = max_txsize_lookup[bs]; | 492 const TX_SIZE max_tx_size = max_txsize_lookup[bs]; |
| 486 VP9_COMMON *const cm = &cpi->common; | 493 VP9_COMMON *const cm = &cpi->common; |
| 487 const TX_SIZE largest_tx_size = tx_mode_to_biggest_tx_size[cm->tx_mode]; | 494 const TX_SIZE largest_tx_size = tx_mode_to_biggest_tx_size[cm->tx_mode]; |
| 488 MACROBLOCKD *const xd = &x->e_mbd; | 495 MACROBLOCKD *const xd = &x->e_mbd; |
| 489 MB_MODE_INFO *const mbmi = &xd->mi[0]->mbmi; | 496 MB_MODE_INFO *const mbmi = &xd->mi[0].src_mi->mbmi; |
| 490 | 497 |
| 491 mbmi->tx_size = MIN(max_tx_size, largest_tx_size); | 498 mbmi->tx_size = MIN(max_tx_size, largest_tx_size); |
| 492 | 499 |
| 493 txfm_rd_in_plane(x, rate, distortion, skip, | 500 txfm_rd_in_plane(x, rate, distortion, skip, |
| 494 sse, ref_best_rd, 0, bs, | 501 sse, ref_best_rd, 0, bs, |
| 495 mbmi->tx_size, cpi->sf.use_fast_coef_costing); | 502 mbmi->tx_size, cpi->sf.use_fast_coef_costing); |
| 496 } | 503 } |
| 497 | 504 |
| 498 static void choose_tx_size_from_rd(VP9_COMP *cpi, MACROBLOCK *x, | 505 static void choose_tx_size_from_rd(VP9_COMP *cpi, MACROBLOCK *x, |
| 499 int *rate, | 506 int *rate, |
| 500 int64_t *distortion, | 507 int64_t *distortion, |
| 501 int *skip, | 508 int *skip, |
| 502 int64_t *psse, | 509 int64_t *psse, |
| 503 int64_t tx_cache[TX_MODES], | 510 int64_t tx_cache[TX_MODES], |
| 504 int64_t ref_best_rd, | 511 int64_t ref_best_rd, |
| 505 BLOCK_SIZE bs) { | 512 BLOCK_SIZE bs) { |
| 506 const TX_SIZE max_tx_size = max_txsize_lookup[bs]; | 513 const TX_SIZE max_tx_size = max_txsize_lookup[bs]; |
| 507 VP9_COMMON *const cm = &cpi->common; | 514 VP9_COMMON *const cm = &cpi->common; |
| 508 MACROBLOCKD *const xd = &x->e_mbd; | 515 MACROBLOCKD *const xd = &x->e_mbd; |
| 509 MB_MODE_INFO *const mbmi = &xd->mi[0]->mbmi; | 516 MB_MODE_INFO *const mbmi = &xd->mi[0].src_mi->mbmi; |
| 510 vp9_prob skip_prob = vp9_get_skip_prob(cm, xd); | 517 vp9_prob skip_prob = vp9_get_skip_prob(cm, xd); |
| 511 int r[TX_SIZES][2], s[TX_SIZES]; | 518 int r[TX_SIZES][2], s[TX_SIZES]; |
| 512 int64_t d[TX_SIZES], sse[TX_SIZES]; | 519 int64_t d[TX_SIZES], sse[TX_SIZES]; |
| 513 int64_t rd[TX_SIZES][2] = {{INT64_MAX, INT64_MAX}, | 520 int64_t rd[TX_SIZES][2] = {{INT64_MAX, INT64_MAX}, |
| 514 {INT64_MAX, INT64_MAX}, | 521 {INT64_MAX, INT64_MAX}, |
| 515 {INT64_MAX, INT64_MAX}, | 522 {INT64_MAX, INT64_MAX}, |
| 516 {INT64_MAX, INT64_MAX}}; | 523 {INT64_MAX, INT64_MAX}}; |
| 517 int n, m; | 524 int n, m; |
| 518 int s0, s1; | 525 int s0, s1; |
| 519 const TX_SIZE max_mode_tx_size = tx_mode_to_biggest_tx_size[cm->tx_mode]; | 526 const TX_SIZE max_mode_tx_size = tx_mode_to_biggest_tx_size[cm->tx_mode]; |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 586 | 593 |
| 587 static void super_block_yrd(VP9_COMP *cpi, MACROBLOCK *x, int *rate, | 594 static void super_block_yrd(VP9_COMP *cpi, MACROBLOCK *x, int *rate, |
| 588 int64_t *distortion, int *skip, | 595 int64_t *distortion, int *skip, |
| 589 int64_t *psse, BLOCK_SIZE bs, | 596 int64_t *psse, BLOCK_SIZE bs, |
| 590 int64_t txfm_cache[TX_MODES], | 597 int64_t txfm_cache[TX_MODES], |
| 591 int64_t ref_best_rd) { | 598 int64_t ref_best_rd) { |
| 592 MACROBLOCKD *xd = &x->e_mbd; | 599 MACROBLOCKD *xd = &x->e_mbd; |
| 593 int64_t sse; | 600 int64_t sse; |
| 594 int64_t *ret_sse = psse ? psse : &sse; | 601 int64_t *ret_sse = psse ? psse : &sse; |
| 595 | 602 |
| 596 assert(bs == xd->mi[0]->mbmi.sb_type); | 603 assert(bs == xd->mi[0].src_mi->mbmi.sb_type); |
| 597 | 604 |
| 598 if (cpi->sf.tx_size_search_method == USE_LARGESTALL || xd->lossless) { | 605 if (cpi->sf.tx_size_search_method == USE_LARGESTALL || xd->lossless) { |
| 599 vpx_memset(txfm_cache, 0, TX_MODES * sizeof(int64_t)); | 606 vpx_memset(txfm_cache, 0, TX_MODES * sizeof(int64_t)); |
| 600 choose_largest_tx_size(cpi, x, rate, distortion, skip, ret_sse, ref_best_rd, | 607 choose_largest_tx_size(cpi, x, rate, distortion, skip, ret_sse, ref_best_rd, |
| 601 bs); | 608 bs); |
| 602 } else { | 609 } else { |
| 603 choose_tx_size_from_rd(cpi, x, rate, distortion, skip, ret_sse, | 610 choose_tx_size_from_rd(cpi, x, rate, distortion, skip, ret_sse, |
| 604 txfm_cache, ref_best_rd, bs); | 611 txfm_cache, ref_best_rd, bs); |
| 605 } | 612 } |
| 606 } | 613 } |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 650 | 657 |
| 651 const int num_4x4_blocks_wide = num_4x4_blocks_wide_lookup[bsize]; | 658 const int num_4x4_blocks_wide = num_4x4_blocks_wide_lookup[bsize]; |
| 652 const int num_4x4_blocks_high = num_4x4_blocks_high_lookup[bsize]; | 659 const int num_4x4_blocks_high = num_4x4_blocks_high_lookup[bsize]; |
| 653 int idx, idy; | 660 int idx, idy; |
| 654 uint8_t best_dst[8 * 8]; | 661 uint8_t best_dst[8 * 8]; |
| 655 | 662 |
| 656 assert(ib < 4); | 663 assert(ib < 4); |
| 657 | 664 |
| 658 vpx_memcpy(ta, a, sizeof(ta)); | 665 vpx_memcpy(ta, a, sizeof(ta)); |
| 659 vpx_memcpy(tl, l, sizeof(tl)); | 666 vpx_memcpy(tl, l, sizeof(tl)); |
| 660 xd->mi[0]->mbmi.tx_size = TX_4X4; | 667 xd->mi[0].src_mi->mbmi.tx_size = TX_4X4; |
| 661 | 668 |
| 662 for (mode = DC_PRED; mode <= TM_PRED; ++mode) { | 669 for (mode = DC_PRED; mode <= TM_PRED; ++mode) { |
| 663 int64_t this_rd; | 670 int64_t this_rd; |
| 664 int ratey = 0; | 671 int ratey = 0; |
| 665 int64_t distortion = 0; | 672 int64_t distortion = 0; |
| 666 int rate = bmode_costs[mode]; | 673 int rate = bmode_costs[mode]; |
| 667 | 674 |
| 668 if (!(cpi->sf.intra_y_mode_mask[TX_4X4] & (1 << mode))) | 675 if (!(cpi->sf.intra_y_mode_mask[TX_4X4] & (1 << mode))) |
| 669 continue; | 676 continue; |
| 670 | 677 |
| 671 // Only do the oblique modes if the best so far is | 678 // Only do the oblique modes if the best so far is |
| 672 // one of the neighboring directional modes | 679 // one of the neighboring directional modes |
| 673 if (cpi->sf.mode_search_skip_flags & FLAG_SKIP_INTRA_DIRMISMATCH) { | 680 if (cpi->sf.mode_search_skip_flags & FLAG_SKIP_INTRA_DIRMISMATCH) { |
| 674 if (conditional_skipintra(mode, *best_mode)) | 681 if (conditional_skipintra(mode, *best_mode)) |
| 675 continue; | 682 continue; |
| 676 } | 683 } |
| 677 | 684 |
| 678 vpx_memcpy(tempa, ta, sizeof(ta)); | 685 vpx_memcpy(tempa, ta, sizeof(ta)); |
| 679 vpx_memcpy(templ, tl, sizeof(tl)); | 686 vpx_memcpy(templ, tl, sizeof(tl)); |
| 680 | 687 |
| 681 for (idy = 0; idy < num_4x4_blocks_high; ++idy) { | 688 for (idy = 0; idy < num_4x4_blocks_high; ++idy) { |
| 682 for (idx = 0; idx < num_4x4_blocks_wide; ++idx) { | 689 for (idx = 0; idx < num_4x4_blocks_wide; ++idx) { |
| 683 const int block = ib + idy * 2 + idx; | 690 const int block = ib + idy * 2 + idx; |
| 684 const uint8_t *const src = &src_init[idx * 4 + idy * 4 * src_stride]; | 691 const uint8_t *const src = &src_init[idx * 4 + idy * 4 * src_stride]; |
| 685 uint8_t *const dst = &dst_init[idx * 4 + idy * 4 * dst_stride]; | 692 uint8_t *const dst = &dst_init[idx * 4 + idy * 4 * dst_stride]; |
| 686 int16_t *const src_diff = raster_block_offset_int16(BLOCK_8X8, block, | 693 int16_t *const src_diff = raster_block_offset_int16(BLOCK_8X8, block, |
| 687 p->src_diff); | 694 p->src_diff); |
| 688 int16_t *const coeff = BLOCK_OFFSET(x->plane[0].coeff, block); | 695 tran_low_t *const coeff = BLOCK_OFFSET(x->plane[0].coeff, block); |
| 689 xd->mi[0]->bmi[block].as_mode = mode; | 696 xd->mi[0].src_mi->bmi[block].as_mode = mode; |
| 690 vp9_predict_intra_block(xd, block, 1, | 697 vp9_predict_intra_block(xd, block, 1, |
| 691 TX_4X4, mode, | 698 TX_4X4, mode, |
| 692 x->skip_encode ? src : dst, | 699 x->skip_encode ? src : dst, |
| 693 x->skip_encode ? src_stride : dst_stride, | 700 x->skip_encode ? src_stride : dst_stride, |
| 694 dst, dst_stride, idx, idy, 0); | 701 dst, dst_stride, idx, idy, 0); |
| 695 vp9_subtract_block(4, 4, src_diff, 8, src, src_stride, dst, dst_stride); | 702 vp9_subtract_block(4, 4, src_diff, 8, src, src_stride, dst, dst_stride); |
| 696 | 703 |
| 697 if (xd->lossless) { | 704 if (xd->lossless) { |
| 698 const scan_order *so = &vp9_default_scan_orders[TX_4X4]; | 705 const scan_order *so = &vp9_default_scan_orders[TX_4X4]; |
| 699 vp9_fwht4x4(src_diff, coeff, 8); | 706 vp9_fwht4x4(src_diff, coeff, 8); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 752 | 759 |
| 753 return best_rd; | 760 return best_rd; |
| 754 } | 761 } |
| 755 | 762 |
| 756 static int64_t rd_pick_intra_sub_8x8_y_mode(VP9_COMP *cpi, MACROBLOCK *mb, | 763 static int64_t rd_pick_intra_sub_8x8_y_mode(VP9_COMP *cpi, MACROBLOCK *mb, |
| 757 int *rate, int *rate_y, | 764 int *rate, int *rate_y, |
| 758 int64_t *distortion, | 765 int64_t *distortion, |
| 759 int64_t best_rd) { | 766 int64_t best_rd) { |
| 760 int i, j; | 767 int i, j; |
| 761 const MACROBLOCKD *const xd = &mb->e_mbd; | 768 const MACROBLOCKD *const xd = &mb->e_mbd; |
| 762 MODE_INFO *const mic = xd->mi[0]; | 769 MODE_INFO *const mic = xd->mi[0].src_mi; |
| 763 const MODE_INFO *above_mi = xd->mi[-xd->mi_stride]; | 770 const MODE_INFO *above_mi = xd->mi[-xd->mi_stride].src_mi; |
| 764 const MODE_INFO *left_mi = xd->left_available ? xd->mi[-1] : NULL; | 771 const MODE_INFO *left_mi = xd->left_available ? xd->mi[-1].src_mi : NULL; |
| 765 const BLOCK_SIZE bsize = xd->mi[0]->mbmi.sb_type; | 772 const BLOCK_SIZE bsize = xd->mi[0].src_mi->mbmi.sb_type; |
| 766 const int num_4x4_blocks_wide = num_4x4_blocks_wide_lookup[bsize]; | 773 const int num_4x4_blocks_wide = num_4x4_blocks_wide_lookup[bsize]; |
| 767 const int num_4x4_blocks_high = num_4x4_blocks_high_lookup[bsize]; | 774 const int num_4x4_blocks_high = num_4x4_blocks_high_lookup[bsize]; |
| 768 int idx, idy; | 775 int idx, idy; |
| 769 int cost = 0; | 776 int cost = 0; |
| 770 int64_t total_distortion = 0; | 777 int64_t total_distortion = 0; |
| 771 int tot_rate_y = 0; | 778 int tot_rate_y = 0; |
| 772 int64_t total_rd = 0; | 779 int64_t total_rd = 0; |
| 773 ENTROPY_CONTEXT t_above[4], t_left[4]; | 780 ENTROPY_CONTEXT t_above[4], t_left[4]; |
| 774 const int *bmode_costs = cpi->mbmode_cost; | 781 const int *bmode_costs = cpi->mbmode_cost; |
| 775 | 782 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 822 | 829 |
| 823 static int64_t rd_pick_intra_sby_mode(VP9_COMP *cpi, MACROBLOCK *x, | 830 static int64_t rd_pick_intra_sby_mode(VP9_COMP *cpi, MACROBLOCK *x, |
| 824 int *rate, int *rate_tokenonly, | 831 int *rate, int *rate_tokenonly, |
| 825 int64_t *distortion, int *skippable, | 832 int64_t *distortion, int *skippable, |
| 826 BLOCK_SIZE bsize, | 833 BLOCK_SIZE bsize, |
| 827 int64_t tx_cache[TX_MODES], | 834 int64_t tx_cache[TX_MODES], |
| 828 int64_t best_rd) { | 835 int64_t best_rd) { |
| 829 PREDICTION_MODE mode; | 836 PREDICTION_MODE mode; |
| 830 PREDICTION_MODE mode_selected = DC_PRED; | 837 PREDICTION_MODE mode_selected = DC_PRED; |
| 831 MACROBLOCKD *const xd = &x->e_mbd; | 838 MACROBLOCKD *const xd = &x->e_mbd; |
| 832 MODE_INFO *const mic = xd->mi[0]; | 839 MODE_INFO *const mic = xd->mi[0].src_mi; |
| 833 int this_rate, this_rate_tokenonly, s; | 840 int this_rate, this_rate_tokenonly, s; |
| 834 int64_t this_distortion, this_rd; | 841 int64_t this_distortion, this_rd; |
| 835 TX_SIZE best_tx = TX_4X4; | 842 TX_SIZE best_tx = TX_4X4; |
| 836 int i; | 843 int i; |
| 837 int *bmode_costs = cpi->mbmode_cost; | 844 int *bmode_costs = cpi->mbmode_cost; |
| 838 | 845 |
| 839 if (cpi->sf.tx_size_search_method == USE_FULL_RD) | 846 if (cpi->sf.tx_size_search_method == USE_FULL_RD) |
| 840 for (i = 0; i < TX_MODES; i++) | 847 for (i = 0; i < TX_MODES; i++) |
| 841 tx_cache[i] = INT64_MAX; | 848 tx_cache[i] = INT64_MAX; |
| 842 | 849 |
| 843 /* Y Search for intra prediction mode */ | 850 /* Y Search for intra prediction mode */ |
| 844 for (mode = DC_PRED; mode <= TM_PRED; mode++) { | 851 for (mode = DC_PRED; mode <= TM_PRED; mode++) { |
| 845 int64_t local_tx_cache[TX_MODES]; | 852 int64_t local_tx_cache[TX_MODES]; |
| 846 MODE_INFO *above_mi = xd->mi[-xd->mi_stride]; | 853 MODE_INFO *above_mi = xd->mi[-xd->mi_stride].src_mi; |
| 847 MODE_INFO *left_mi = xd->left_available ? xd->mi[-1] : NULL; | 854 MODE_INFO *left_mi = xd->left_available ? xd->mi[-1].src_mi : NULL; |
| 848 | 855 |
| 849 if (cpi->common.frame_type == KEY_FRAME) { | 856 if (cpi->common.frame_type == KEY_FRAME) { |
| 850 const PREDICTION_MODE A = vp9_above_block_mode(mic, above_mi, 0); | 857 const PREDICTION_MODE A = vp9_above_block_mode(mic, above_mi, 0); |
| 851 const PREDICTION_MODE L = vp9_left_block_mode(mic, left_mi, 0); | 858 const PREDICTION_MODE L = vp9_left_block_mode(mic, left_mi, 0); |
| 852 | 859 |
| 853 bmode_costs = cpi->y_mode_costs[A][L]; | 860 bmode_costs = cpi->y_mode_costs[A][L]; |
| 854 } | 861 } |
| 855 mic->mbmi.mode = mode; | 862 mic->mbmi.mode = mode; |
| 856 | 863 |
| 857 super_block_yrd(cpi, x, &this_rate_tokenonly, &this_distortion, | 864 super_block_yrd(cpi, x, &this_rate_tokenonly, &this_distortion, |
| (...skipping 30 matching lines...) Expand all Loading... |
| 888 mic->mbmi.tx_size = best_tx; | 895 mic->mbmi.tx_size = best_tx; |
| 889 | 896 |
| 890 return best_rd; | 897 return best_rd; |
| 891 } | 898 } |
| 892 | 899 |
| 893 static void super_block_uvrd(const VP9_COMP *cpi, MACROBLOCK *x, | 900 static void super_block_uvrd(const VP9_COMP *cpi, MACROBLOCK *x, |
| 894 int *rate, int64_t *distortion, int *skippable, | 901 int *rate, int64_t *distortion, int *skippable, |
| 895 int64_t *sse, BLOCK_SIZE bsize, | 902 int64_t *sse, BLOCK_SIZE bsize, |
| 896 int64_t ref_best_rd) { | 903 int64_t ref_best_rd) { |
| 897 MACROBLOCKD *const xd = &x->e_mbd; | 904 MACROBLOCKD *const xd = &x->e_mbd; |
| 898 MB_MODE_INFO *const mbmi = &xd->mi[0]->mbmi; | 905 MB_MODE_INFO *const mbmi = &xd->mi[0].src_mi->mbmi; |
| 899 const TX_SIZE uv_tx_size = get_uv_tx_size(mbmi, &xd->plane[1]); | 906 const TX_SIZE uv_tx_size = get_uv_tx_size(mbmi, &xd->plane[1]); |
| 900 int plane; | 907 int plane; |
| 901 int pnrate = 0, pnskip = 1; | 908 int pnrate = 0, pnskip = 1; |
| 902 int64_t pndist = 0, pnsse = 0; | 909 int64_t pndist = 0, pnsse = 0; |
| 903 | 910 |
| 904 if (ref_best_rd < 0) | 911 if (ref_best_rd < 0) |
| 905 goto term; | 912 goto term; |
| 906 | 913 |
| 907 if (is_inter_block(mbmi)) { | 914 if (is_inter_block(mbmi)) { |
| 908 int plane; | 915 int plane; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 945 PREDICTION_MODE mode; | 952 PREDICTION_MODE mode; |
| 946 PREDICTION_MODE mode_selected = DC_PRED; | 953 PREDICTION_MODE mode_selected = DC_PRED; |
| 947 int64_t best_rd = INT64_MAX, this_rd; | 954 int64_t best_rd = INT64_MAX, this_rd; |
| 948 int this_rate_tokenonly, this_rate, s; | 955 int this_rate_tokenonly, this_rate, s; |
| 949 int64_t this_distortion, this_sse; | 956 int64_t this_distortion, this_sse; |
| 950 | 957 |
| 951 for (mode = DC_PRED; mode <= TM_PRED; ++mode) { | 958 for (mode = DC_PRED; mode <= TM_PRED; ++mode) { |
| 952 if (!(cpi->sf.intra_uv_mode_mask[max_tx_size] & (1 << mode))) | 959 if (!(cpi->sf.intra_uv_mode_mask[max_tx_size] & (1 << mode))) |
| 953 continue; | 960 continue; |
| 954 | 961 |
| 955 xd->mi[0]->mbmi.uv_mode = mode; | 962 xd->mi[0].src_mi->mbmi.uv_mode = mode; |
| 956 | 963 |
| 957 super_block_uvrd(cpi, x, &this_rate_tokenonly, | 964 super_block_uvrd(cpi, x, &this_rate_tokenonly, |
| 958 &this_distortion, &s, &this_sse, bsize, best_rd); | 965 &this_distortion, &s, &this_sse, bsize, best_rd); |
| 959 if (this_rate_tokenonly == INT_MAX) | 966 if (this_rate_tokenonly == INT_MAX) |
| 960 continue; | 967 continue; |
| 961 this_rate = this_rate_tokenonly + | 968 this_rate = this_rate_tokenonly + |
| 962 cpi->intra_uv_mode_cost[cpi->common.frame_type][mode]; | 969 cpi->intra_uv_mode_cost[cpi->common.frame_type][mode]; |
| 963 this_rd = RDCOST(x->rdmult, x->rddiv, this_rate, this_distortion); | 970 this_rd = RDCOST(x->rdmult, x->rddiv, this_rate, this_distortion); |
| 964 | 971 |
| 965 if (this_rd < best_rd) { | 972 if (this_rd < best_rd) { |
| 966 mode_selected = mode; | 973 mode_selected = mode; |
| 967 best_rd = this_rd; | 974 best_rd = this_rd; |
| 968 *rate = this_rate; | 975 *rate = this_rate; |
| 969 *rate_tokenonly = this_rate_tokenonly; | 976 *rate_tokenonly = this_rate_tokenonly; |
| 970 *distortion = this_distortion; | 977 *distortion = this_distortion; |
| 971 *skippable = s; | 978 *skippable = s; |
| 972 if (!x->select_tx_size) | 979 if (!x->select_tx_size) |
| 973 swap_block_ptr(x, ctx, 2, 0, 1, MAX_MB_PLANE); | 980 swap_block_ptr(x, ctx, 2, 0, 1, MAX_MB_PLANE); |
| 974 } | 981 } |
| 975 } | 982 } |
| 976 | 983 |
| 977 xd->mi[0]->mbmi.uv_mode = mode_selected; | 984 xd->mi[0].src_mi->mbmi.uv_mode = mode_selected; |
| 978 return best_rd; | 985 return best_rd; |
| 979 } | 986 } |
| 980 | 987 |
| 981 static int64_t rd_sbuv_dcpred(const VP9_COMP *cpi, MACROBLOCK *x, | 988 static int64_t rd_sbuv_dcpred(const VP9_COMP *cpi, MACROBLOCK *x, |
| 982 int *rate, int *rate_tokenonly, | 989 int *rate, int *rate_tokenonly, |
| 983 int64_t *distortion, int *skippable, | 990 int64_t *distortion, int *skippable, |
| 984 BLOCK_SIZE bsize) { | 991 BLOCK_SIZE bsize) { |
| 985 const VP9_COMMON *cm = &cpi->common; | 992 const VP9_COMMON *cm = &cpi->common; |
| 986 int64_t unused; | 993 int64_t unused; |
| 987 | 994 |
| 988 x->e_mbd.mi[0]->mbmi.uv_mode = DC_PRED; | 995 x->e_mbd.mi[0].src_mi->mbmi.uv_mode = DC_PRED; |
| 989 super_block_uvrd(cpi, x, rate_tokenonly, distortion, | 996 super_block_uvrd(cpi, x, rate_tokenonly, distortion, |
| 990 skippable, &unused, bsize, INT64_MAX); | 997 skippable, &unused, bsize, INT64_MAX); |
| 991 *rate = *rate_tokenonly + cpi->intra_uv_mode_cost[cm->frame_type][DC_PRED]; | 998 *rate = *rate_tokenonly + cpi->intra_uv_mode_cost[cm->frame_type][DC_PRED]; |
| 992 return RDCOST(x->rdmult, x->rddiv, *rate, *distortion); | 999 return RDCOST(x->rdmult, x->rddiv, *rate, *distortion); |
| 993 } | 1000 } |
| 994 | 1001 |
| 995 static void choose_intra_uv_mode(VP9_COMP *cpi, PICK_MODE_CONTEXT *ctx, | 1002 static void choose_intra_uv_mode(VP9_COMP *cpi, PICK_MODE_CONTEXT *ctx, |
| 996 BLOCK_SIZE bsize, TX_SIZE max_tx_size, | 1003 BLOCK_SIZE bsize, TX_SIZE max_tx_size, |
| 997 int *rate_uv, int *rate_uv_tokenonly, | 1004 int *rate_uv, int *rate_uv_tokenonly, |
| 998 int64_t *dist_uv, int *skip_uv, | 1005 int64_t *dist_uv, int *skip_uv, |
| 999 PREDICTION_MODE *mode_uv) { | 1006 PREDICTION_MODE *mode_uv) { |
| 1000 MACROBLOCK *const x = &cpi->mb; | 1007 MACROBLOCK *const x = &cpi->mb; |
| 1001 | 1008 |
| 1002 // Use an estimated rd for uv_intra based on DC_PRED if the | 1009 // Use an estimated rd for uv_intra based on DC_PRED if the |
| 1003 // appropriate speed flag is set. | 1010 // appropriate speed flag is set. |
| 1004 if (cpi->sf.use_uv_intra_rd_estimate) { | 1011 if (cpi->sf.use_uv_intra_rd_estimate) { |
| 1005 rd_sbuv_dcpred(cpi, x, rate_uv, rate_uv_tokenonly, dist_uv, | 1012 rd_sbuv_dcpred(cpi, x, rate_uv, rate_uv_tokenonly, dist_uv, |
| 1006 skip_uv, bsize < BLOCK_8X8 ? BLOCK_8X8 : bsize); | 1013 skip_uv, bsize < BLOCK_8X8 ? BLOCK_8X8 : bsize); |
| 1007 // Else do a proper rd search for each possible transform size that may | 1014 // Else do a proper rd search for each possible transform size that may |
| 1008 // be considered in the main rd loop. | 1015 // be considered in the main rd loop. |
| 1009 } else { | 1016 } else { |
| 1010 rd_pick_intra_sbuv_mode(cpi, x, ctx, | 1017 rd_pick_intra_sbuv_mode(cpi, x, ctx, |
| 1011 rate_uv, rate_uv_tokenonly, dist_uv, skip_uv, | 1018 rate_uv, rate_uv_tokenonly, dist_uv, skip_uv, |
| 1012 bsize < BLOCK_8X8 ? BLOCK_8X8 : bsize, max_tx_size); | 1019 bsize < BLOCK_8X8 ? BLOCK_8X8 : bsize, max_tx_size); |
| 1013 } | 1020 } |
| 1014 *mode_uv = x->e_mbd.mi[0]->mbmi.uv_mode; | 1021 *mode_uv = x->e_mbd.mi[0].src_mi->mbmi.uv_mode; |
| 1015 } | 1022 } |
| 1016 | 1023 |
| 1017 static int cost_mv_ref(const VP9_COMP *cpi, PREDICTION_MODE mode, | 1024 static int cost_mv_ref(const VP9_COMP *cpi, PREDICTION_MODE mode, |
| 1018 int mode_context) { | 1025 int mode_context) { |
| 1019 assert(is_inter_mode(mode)); | 1026 assert(is_inter_mode(mode)); |
| 1020 return cpi->inter_mode_cost[mode_context][INTER_OFFSET(mode)]; | 1027 return cpi->inter_mode_cost[mode_context][INTER_OFFSET(mode)]; |
| 1021 } | 1028 } |
| 1022 | 1029 |
| 1023 static void joint_motion_search(VP9_COMP *cpi, MACROBLOCK *x, | 1030 static void joint_motion_search(VP9_COMP *cpi, MACROBLOCK *x, |
| 1024 BLOCK_SIZE bsize, | 1031 BLOCK_SIZE bsize, |
| 1025 int_mv *frame_mv, | 1032 int_mv *frame_mv, |
| 1026 int mi_row, int mi_col, | 1033 int mi_row, int mi_col, |
| 1027 int_mv single_newmv[MAX_REF_FRAMES], | 1034 int_mv single_newmv[MAX_REF_FRAMES], |
| 1028 int *rate_mv); | 1035 int *rate_mv); |
| 1029 | 1036 |
| 1030 static int set_and_cost_bmi_mvs(VP9_COMP *cpi, MACROBLOCKD *xd, int i, | 1037 static int set_and_cost_bmi_mvs(VP9_COMP *cpi, MACROBLOCKD *xd, int i, |
| 1031 PREDICTION_MODE mode, int_mv this_mv[2], | 1038 PREDICTION_MODE mode, int_mv this_mv[2], |
| 1032 int_mv frame_mv[MB_MODE_COUNT][MAX_REF_FRAMES], | 1039 int_mv frame_mv[MB_MODE_COUNT][MAX_REF_FRAMES], |
| 1033 int_mv seg_mvs[MAX_REF_FRAMES], | 1040 int_mv seg_mvs[MAX_REF_FRAMES], |
| 1034 int_mv *best_ref_mv[2], const int *mvjcost, | 1041 int_mv *best_ref_mv[2], const int *mvjcost, |
| 1035 int *mvcost[2]) { | 1042 int *mvcost[2]) { |
| 1036 MODE_INFO *const mic = xd->mi[0]; | 1043 MODE_INFO *const mic = xd->mi[0].src_mi; |
| 1037 const MB_MODE_INFO *const mbmi = &mic->mbmi; | 1044 const MB_MODE_INFO *const mbmi = &mic->mbmi; |
| 1038 int thismvcost = 0; | 1045 int thismvcost = 0; |
| 1039 int idx, idy; | 1046 int idx, idy; |
| 1040 const int num_4x4_blocks_wide = num_4x4_blocks_wide_lookup[mbmi->sb_type]; | 1047 const int num_4x4_blocks_wide = num_4x4_blocks_wide_lookup[mbmi->sb_type]; |
| 1041 const int num_4x4_blocks_high = num_4x4_blocks_high_lookup[mbmi->sb_type]; | 1048 const int num_4x4_blocks_high = num_4x4_blocks_high_lookup[mbmi->sb_type]; |
| 1042 const int is_compound = has_second_ref(mbmi); | 1049 const int is_compound = has_second_ref(mbmi); |
| 1043 | 1050 |
| 1044 switch (mode) { | 1051 switch (mode) { |
| 1045 case NEWMV: | 1052 case NEWMV: |
| 1046 this_mv[0].as_int = seg_mvs[mbmi->ref_frame[0]].as_int; | 1053 this_mv[0].as_int = seg_mvs[mbmi->ref_frame[0]].as_int; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1088 int i, | 1095 int i, |
| 1089 int *labelyrate, | 1096 int *labelyrate, |
| 1090 int64_t *distortion, int64_t *sse, | 1097 int64_t *distortion, int64_t *sse, |
| 1091 ENTROPY_CONTEXT *ta, | 1098 ENTROPY_CONTEXT *ta, |
| 1092 ENTROPY_CONTEXT *tl, | 1099 ENTROPY_CONTEXT *tl, |
| 1093 int mi_row, int mi_col) { | 1100 int mi_row, int mi_col) { |
| 1094 int k; | 1101 int k; |
| 1095 MACROBLOCKD *xd = &x->e_mbd; | 1102 MACROBLOCKD *xd = &x->e_mbd; |
| 1096 struct macroblockd_plane *const pd = &xd->plane[0]; | 1103 struct macroblockd_plane *const pd = &xd->plane[0]; |
| 1097 struct macroblock_plane *const p = &x->plane[0]; | 1104 struct macroblock_plane *const p = &x->plane[0]; |
| 1098 MODE_INFO *const mi = xd->mi[0]; | 1105 MODE_INFO *const mi = xd->mi[0].src_mi; |
| 1099 const BLOCK_SIZE plane_bsize = get_plane_block_size(mi->mbmi.sb_type, pd); | 1106 const BLOCK_SIZE plane_bsize = get_plane_block_size(mi->mbmi.sb_type, pd); |
| 1100 const int width = 4 * num_4x4_blocks_wide_lookup[plane_bsize]; | 1107 const int width = 4 * num_4x4_blocks_wide_lookup[plane_bsize]; |
| 1101 const int height = 4 * num_4x4_blocks_high_lookup[plane_bsize]; | 1108 const int height = 4 * num_4x4_blocks_high_lookup[plane_bsize]; |
| 1102 int idx, idy; | 1109 int idx, idy; |
| 1103 | 1110 |
| 1104 const uint8_t *const src = &p->src.buf[raster_block_offset(BLOCK_8X8, i, | 1111 const uint8_t *const src = &p->src.buf[raster_block_offset(BLOCK_8X8, i, |
| 1105 p->src.stride)]; | 1112 p->src.stride)]; |
| 1106 uint8_t *const dst = &pd->dst.buf[raster_block_offset(BLOCK_8X8, i, | 1113 uint8_t *const dst = &pd->dst.buf[raster_block_offset(BLOCK_8X8, i, |
| 1107 pd->dst.stride)]; | 1114 pd->dst.stride)]; |
| 1108 int64_t thisdistortion = 0, thissse = 0; | 1115 int64_t thisdistortion = 0, thissse = 0; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1125 | 1132 |
| 1126 vp9_subtract_block(height, width, | 1133 vp9_subtract_block(height, width, |
| 1127 raster_block_offset_int16(BLOCK_8X8, i, p->src_diff), 8, | 1134 raster_block_offset_int16(BLOCK_8X8, i, p->src_diff), 8, |
| 1128 src, p->src.stride, | 1135 src, p->src.stride, |
| 1129 dst, pd->dst.stride); | 1136 dst, pd->dst.stride); |
| 1130 | 1137 |
| 1131 k = i; | 1138 k = i; |
| 1132 for (idy = 0; idy < height / 4; ++idy) { | 1139 for (idy = 0; idy < height / 4; ++idy) { |
| 1133 for (idx = 0; idx < width / 4; ++idx) { | 1140 for (idx = 0; idx < width / 4; ++idx) { |
| 1134 int64_t ssz, rd, rd1, rd2; | 1141 int64_t ssz, rd, rd1, rd2; |
| 1135 int16_t* coeff; | 1142 tran_low_t* coeff; |
| 1136 | 1143 |
| 1137 k += (idy * 2 + idx); | 1144 k += (idy * 2 + idx); |
| 1138 coeff = BLOCK_OFFSET(p->coeff, k); | 1145 coeff = BLOCK_OFFSET(p->coeff, k); |
| 1139 x->fwd_txm4x4(raster_block_offset_int16(BLOCK_8X8, k, p->src_diff), | 1146 x->fwd_txm4x4(raster_block_offset_int16(BLOCK_8X8, k, p->src_diff), |
| 1140 coeff, 8); | 1147 coeff, 8); |
| 1141 vp9_regular_quantize_b_4x4(x, 0, k, so->scan, so->iscan); | 1148 vp9_regular_quantize_b_4x4(x, 0, k, so->scan, so->iscan); |
| 1142 thisdistortion += vp9_block_error(coeff, BLOCK_OFFSET(pd->dqcoeff, k), | 1149 thisdistortion += vp9_block_error(coeff, BLOCK_OFFSET(pd->dqcoeff, k), |
| 1143 16, &ssz); | 1150 16, &ssz); |
| 1144 thissse += ssz; | 1151 thissse += ssz; |
| 1145 thisrate += cost_coeffs(x, 0, k, ta + (k & 1), tl + (k >> 1), TX_4X4, | 1152 thisrate += cost_coeffs(x, 0, k, ta + (k & 1), tl + (k >> 1), TX_4X4, |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1187 } BEST_SEG_INFO; | 1194 } BEST_SEG_INFO; |
| 1188 | 1195 |
| 1189 static INLINE int mv_check_bounds(const MACROBLOCK *x, const MV *mv) { | 1196 static INLINE int mv_check_bounds(const MACROBLOCK *x, const MV *mv) { |
| 1190 return (mv->row >> 3) < x->mv_row_min || | 1197 return (mv->row >> 3) < x->mv_row_min || |
| 1191 (mv->row >> 3) > x->mv_row_max || | 1198 (mv->row >> 3) > x->mv_row_max || |
| 1192 (mv->col >> 3) < x->mv_col_min || | 1199 (mv->col >> 3) < x->mv_col_min || |
| 1193 (mv->col >> 3) > x->mv_col_max; | 1200 (mv->col >> 3) > x->mv_col_max; |
| 1194 } | 1201 } |
| 1195 | 1202 |
| 1196 static INLINE void mi_buf_shift(MACROBLOCK *x, int i) { | 1203 static INLINE void mi_buf_shift(MACROBLOCK *x, int i) { |
| 1197 MB_MODE_INFO *const mbmi = &x->e_mbd.mi[0]->mbmi; | 1204 MB_MODE_INFO *const mbmi = &x->e_mbd.mi[0].src_mi->mbmi; |
| 1198 struct macroblock_plane *const p = &x->plane[0]; | 1205 struct macroblock_plane *const p = &x->plane[0]; |
| 1199 struct macroblockd_plane *const pd = &x->e_mbd.plane[0]; | 1206 struct macroblockd_plane *const pd = &x->e_mbd.plane[0]; |
| 1200 | 1207 |
| 1201 p->src.buf = &p->src.buf[raster_block_offset(BLOCK_8X8, i, p->src.stride)]; | 1208 p->src.buf = &p->src.buf[raster_block_offset(BLOCK_8X8, i, p->src.stride)]; |
| 1202 assert(((intptr_t)pd->pre[0].buf & 0x7) == 0); | 1209 assert(((intptr_t)pd->pre[0].buf & 0x7) == 0); |
| 1203 pd->pre[0].buf = &pd->pre[0].buf[raster_block_offset(BLOCK_8X8, i, | 1210 pd->pre[0].buf = &pd->pre[0].buf[raster_block_offset(BLOCK_8X8, i, |
| 1204 pd->pre[0].stride)]; | 1211 pd->pre[0].stride)]; |
| 1205 if (has_second_ref(mbmi)) | 1212 if (has_second_ref(mbmi)) |
| 1206 pd->pre[1].buf = &pd->pre[1].buf[raster_block_offset(BLOCK_8X8, i, | 1213 pd->pre[1].buf = &pd->pre[1].buf[raster_block_offset(BLOCK_8X8, i, |
| 1207 pd->pre[1].stride)]; | 1214 pd->pre[1].stride)]; |
| 1208 } | 1215 } |
| 1209 | 1216 |
| 1210 static INLINE void mi_buf_restore(MACROBLOCK *x, struct buf_2d orig_src, | 1217 static INLINE void mi_buf_restore(MACROBLOCK *x, struct buf_2d orig_src, |
| 1211 struct buf_2d orig_pre[2]) { | 1218 struct buf_2d orig_pre[2]) { |
| 1212 MB_MODE_INFO *mbmi = &x->e_mbd.mi[0]->mbmi; | 1219 MB_MODE_INFO *mbmi = &x->e_mbd.mi[0].src_mi->mbmi; |
| 1213 x->plane[0].src = orig_src; | 1220 x->plane[0].src = orig_src; |
| 1214 x->e_mbd.plane[0].pre[0] = orig_pre[0]; | 1221 x->e_mbd.plane[0].pre[0] = orig_pre[0]; |
| 1215 if (has_second_ref(mbmi)) | 1222 if (has_second_ref(mbmi)) |
| 1216 x->e_mbd.plane[0].pre[1] = orig_pre[1]; | 1223 x->e_mbd.plane[0].pre[1] = orig_pre[1]; |
| 1217 } | 1224 } |
| 1218 | 1225 |
| 1219 static INLINE int mv_has_subpel(const MV *mv) { | 1226 static INLINE int mv_has_subpel(const MV *mv) { |
| 1220 return (mv->row & 0x0F) || (mv->col & 0x0F); | 1227 return (mv->row & 0x0F) || (mv->col & 0x0F); |
| 1221 } | 1228 } |
| 1222 | 1229 |
| 1223 // Check if NEARESTMV/NEARMV/ZEROMV is the cheapest way encode zero motion. | 1230 // Check if NEARESTMV/NEARMV/ZEROMV is the cheapest way encode zero motion. |
| 1224 // TODO(aconverse): Find out if this is still productive then clean up or remove | 1231 // TODO(aconverse): Find out if this is still productive then clean up or remove |
| 1225 static int check_best_zero_mv( | 1232 static int check_best_zero_mv( |
| 1226 const VP9_COMP *cpi, const uint8_t mode_context[MAX_REF_FRAMES], | 1233 const VP9_COMP *cpi, const uint8_t mode_context[MAX_REF_FRAMES], |
| 1227 int_mv frame_mv[MB_MODE_COUNT][MAX_REF_FRAMES], | 1234 int_mv frame_mv[MB_MODE_COUNT][MAX_REF_FRAMES], int this_mode, |
| 1228 int inter_mode_mask, int this_mode, | |
| 1229 const MV_REFERENCE_FRAME ref_frames[2]) { | 1235 const MV_REFERENCE_FRAME ref_frames[2]) { |
| 1230 if ((inter_mode_mask & (1 << ZEROMV)) && | 1236 if ((this_mode == NEARMV || this_mode == NEARESTMV || this_mode == ZEROMV) && |
| 1231 (this_mode == NEARMV || this_mode == NEARESTMV || this_mode == ZEROMV) && | |
| 1232 frame_mv[this_mode][ref_frames[0]].as_int == 0 && | 1237 frame_mv[this_mode][ref_frames[0]].as_int == 0 && |
| 1233 (ref_frames[1] == NONE || | 1238 (ref_frames[1] == NONE || |
| 1234 frame_mv[this_mode][ref_frames[1]].as_int == 0)) { | 1239 frame_mv[this_mode][ref_frames[1]].as_int == 0)) { |
| 1235 int rfc = mode_context[ref_frames[0]]; | 1240 int rfc = mode_context[ref_frames[0]]; |
| 1236 int c1 = cost_mv_ref(cpi, NEARMV, rfc); | 1241 int c1 = cost_mv_ref(cpi, NEARMV, rfc); |
| 1237 int c2 = cost_mv_ref(cpi, NEARESTMV, rfc); | 1242 int c2 = cost_mv_ref(cpi, NEARESTMV, rfc); |
| 1238 int c3 = cost_mv_ref(cpi, ZEROMV, rfc); | 1243 int c3 = cost_mv_ref(cpi, ZEROMV, rfc); |
| 1239 | 1244 |
| 1240 if (this_mode == NEARMV) { | 1245 if (this_mode == NEARMV) { |
| 1241 if (c1 > c3) return 0; | 1246 if (c1 > c3) return 0; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1267 int *returnyrate, | 1272 int *returnyrate, |
| 1268 int64_t *returndistortion, | 1273 int64_t *returndistortion, |
| 1269 int *skippable, int64_t *psse, | 1274 int *skippable, int64_t *psse, |
| 1270 int mvthresh, | 1275 int mvthresh, |
| 1271 int_mv seg_mvs[4][MAX_REF_FRAMES], | 1276 int_mv seg_mvs[4][MAX_REF_FRAMES], |
| 1272 BEST_SEG_INFO *bsi_buf, int filter_idx, | 1277 BEST_SEG_INFO *bsi_buf, int filter_idx, |
| 1273 int mi_row, int mi_col) { | 1278 int mi_row, int mi_col) { |
| 1274 int i; | 1279 int i; |
| 1275 BEST_SEG_INFO *bsi = bsi_buf + filter_idx; | 1280 BEST_SEG_INFO *bsi = bsi_buf + filter_idx; |
| 1276 MACROBLOCKD *xd = &x->e_mbd; | 1281 MACROBLOCKD *xd = &x->e_mbd; |
| 1277 MODE_INFO *mi = xd->mi[0]; | 1282 MODE_INFO *mi = xd->mi[0].src_mi; |
| 1278 MB_MODE_INFO *mbmi = &mi->mbmi; | 1283 MB_MODE_INFO *mbmi = &mi->mbmi; |
| 1279 int mode_idx; | 1284 int mode_idx; |
| 1280 int k, br = 0, idx, idy; | 1285 int k, br = 0, idx, idy; |
| 1281 int64_t bd = 0, block_sse = 0; | 1286 int64_t bd = 0, block_sse = 0; |
| 1282 PREDICTION_MODE this_mode; | 1287 PREDICTION_MODE this_mode; |
| 1283 VP9_COMMON *cm = &cpi->common; | 1288 VP9_COMMON *cm = &cpi->common; |
| 1284 struct macroblock_plane *const p = &x->plane[0]; | 1289 struct macroblock_plane *const p = &x->plane[0]; |
| 1285 struct macroblockd_plane *const pd = &xd->plane[0]; | 1290 struct macroblockd_plane *const pd = &xd->plane[0]; |
| 1286 const int label_count = 4; | 1291 const int label_count = 4; |
| 1287 int64_t this_segment_rd = 0; | 1292 int64_t this_segment_rd = 0; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1339 for (this_mode = NEARESTMV; this_mode <= NEWMV; ++this_mode) { | 1344 for (this_mode = NEARESTMV; this_mode <= NEWMV; ++this_mode) { |
| 1340 const struct buf_2d orig_src = x->plane[0].src; | 1345 const struct buf_2d orig_src = x->plane[0].src; |
| 1341 struct buf_2d orig_pre[2]; | 1346 struct buf_2d orig_pre[2]; |
| 1342 | 1347 |
| 1343 mode_idx = INTER_OFFSET(this_mode); | 1348 mode_idx = INTER_OFFSET(this_mode); |
| 1344 bsi->rdstat[i][mode_idx].brdcost = INT64_MAX; | 1349 bsi->rdstat[i][mode_idx].brdcost = INT64_MAX; |
| 1345 if (!(inter_mode_mask & (1 << this_mode))) | 1350 if (!(inter_mode_mask & (1 << this_mode))) |
| 1346 continue; | 1351 continue; |
| 1347 | 1352 |
| 1348 if (!check_best_zero_mv(cpi, mbmi->mode_context, frame_mv, | 1353 if (!check_best_zero_mv(cpi, mbmi->mode_context, frame_mv, |
| 1349 inter_mode_mask, | |
| 1350 this_mode, mbmi->ref_frame)) | 1354 this_mode, mbmi->ref_frame)) |
| 1351 continue; | 1355 continue; |
| 1352 | 1356 |
| 1353 vpx_memcpy(orig_pre, pd->pre, sizeof(orig_pre)); | 1357 vpx_memcpy(orig_pre, pd->pre, sizeof(orig_pre)); |
| 1354 vpx_memcpy(bsi->rdstat[i][mode_idx].ta, t_above, | 1358 vpx_memcpy(bsi->rdstat[i][mode_idx].ta, t_above, |
| 1355 sizeof(bsi->rdstat[i][mode_idx].ta)); | 1359 sizeof(bsi->rdstat[i][mode_idx].ta)); |
| 1356 vpx_memcpy(bsi->rdstat[i][mode_idx].tl, t_left, | 1360 vpx_memcpy(bsi->rdstat[i][mode_idx].tl, t_left, |
| 1357 sizeof(bsi->rdstat[i][mode_idx].tl)); | 1361 sizeof(bsi->rdstat[i][mode_idx].tl)); |
| 1358 | 1362 |
| 1359 // motion search for newmv (single predictor case only) | 1363 // motion search for newmv (single predictor case only) |
| (...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1709 const int64_t tx_size_diff[TX_MODES], | 1713 const int64_t tx_size_diff[TX_MODES], |
| 1710 int64_t best_filter_diff[SWITCHABLE_FILTER_CONTEXTS], | 1714 int64_t best_filter_diff[SWITCHABLE_FILTER_CONTEXTS], |
| 1711 int skippable) { | 1715 int skippable) { |
| 1712 MACROBLOCKD *const xd = &x->e_mbd; | 1716 MACROBLOCKD *const xd = &x->e_mbd; |
| 1713 | 1717 |
| 1714 // Take a snapshot of the coding context so it can be | 1718 // Take a snapshot of the coding context so it can be |
| 1715 // restored if we decide to encode this way | 1719 // restored if we decide to encode this way |
| 1716 ctx->skip = x->skip; | 1720 ctx->skip = x->skip; |
| 1717 ctx->skippable = skippable; | 1721 ctx->skippable = skippable; |
| 1718 ctx->best_mode_index = mode_index; | 1722 ctx->best_mode_index = mode_index; |
| 1719 ctx->mic = *xd->mi[0]; | 1723 ctx->mic = *xd->mi[0].src_mi; |
| 1720 ctx->single_pred_diff = (int)comp_pred_diff[SINGLE_REFERENCE]; | 1724 ctx->single_pred_diff = (int)comp_pred_diff[SINGLE_REFERENCE]; |
| 1721 ctx->comp_pred_diff = (int)comp_pred_diff[COMPOUND_REFERENCE]; | 1725 ctx->comp_pred_diff = (int)comp_pred_diff[COMPOUND_REFERENCE]; |
| 1722 ctx->hybrid_pred_diff = (int)comp_pred_diff[REFERENCE_MODE_SELECT]; | 1726 ctx->hybrid_pred_diff = (int)comp_pred_diff[REFERENCE_MODE_SELECT]; |
| 1723 | 1727 |
| 1724 vpx_memcpy(ctx->tx_rd_diff, tx_size_diff, sizeof(ctx->tx_rd_diff)); | 1728 vpx_memcpy(ctx->tx_rd_diff, tx_size_diff, sizeof(ctx->tx_rd_diff)); |
| 1725 vpx_memcpy(ctx->best_filter_diff, best_filter_diff, | 1729 vpx_memcpy(ctx->best_filter_diff, best_filter_diff, |
| 1726 sizeof(*best_filter_diff) * SWITCHABLE_FILTER_CONTEXTS); | 1730 sizeof(*best_filter_diff) * SWITCHABLE_FILTER_CONTEXTS); |
| 1727 } | 1731 } |
| 1728 | 1732 |
| 1729 static void setup_buffer_inter(VP9_COMP *cpi, MACROBLOCK *x, | 1733 static void setup_buffer_inter(VP9_COMP *cpi, MACROBLOCK *x, |
| 1730 const TileInfo *const tile, | 1734 const TileInfo *const tile, |
| 1731 MV_REFERENCE_FRAME ref_frame, | 1735 MV_REFERENCE_FRAME ref_frame, |
| 1732 BLOCK_SIZE block_size, | 1736 BLOCK_SIZE block_size, |
| 1733 int mi_row, int mi_col, | 1737 int mi_row, int mi_col, |
| 1734 int_mv frame_nearest_mv[MAX_REF_FRAMES], | 1738 int_mv frame_nearest_mv[MAX_REF_FRAMES], |
| 1735 int_mv frame_near_mv[MAX_REF_FRAMES], | 1739 int_mv frame_near_mv[MAX_REF_FRAMES], |
| 1736 struct buf_2d yv12_mb[4][MAX_MB_PLANE]) { | 1740 struct buf_2d yv12_mb[4][MAX_MB_PLANE]) { |
| 1737 const VP9_COMMON *cm = &cpi->common; | 1741 const VP9_COMMON *cm = &cpi->common; |
| 1738 const YV12_BUFFER_CONFIG *yv12 = get_ref_frame_buffer(cpi, ref_frame); | 1742 const YV12_BUFFER_CONFIG *yv12 = get_ref_frame_buffer(cpi, ref_frame); |
| 1739 MACROBLOCKD *const xd = &x->e_mbd; | 1743 MACROBLOCKD *const xd = &x->e_mbd; |
| 1740 MODE_INFO *const mi = xd->mi[0]; | 1744 MODE_INFO *const mi = xd->mi[0].src_mi; |
| 1741 int_mv *const candidates = mi->mbmi.ref_mvs[ref_frame]; | 1745 int_mv *const candidates = mi->mbmi.ref_mvs[ref_frame]; |
| 1742 const struct scale_factors *const sf = &cm->frame_refs[ref_frame - 1].sf; | 1746 const struct scale_factors *const sf = &cm->frame_refs[ref_frame - 1].sf; |
| 1743 | 1747 |
| 1744 // TODO(jkoleszar): Is the UV buffer ever used here? If so, need to make this | 1748 // TODO(jkoleszar): Is the UV buffer ever used here? If so, need to make this |
| 1745 // use the UV scaling factors. | 1749 // use the UV scaling factors. |
| 1746 vp9_setup_pred_block(xd, yv12_mb[ref_frame], yv12, mi_row, mi_col, sf, sf); | 1750 vp9_setup_pred_block(xd, yv12_mb[ref_frame], yv12, mi_row, mi_col, sf, sf); |
| 1747 | 1751 |
| 1748 // Gets an initial list of candidate vectors from neighbours and orders them | 1752 // Gets an initial list of candidate vectors from neighbours and orders them |
| 1749 vp9_find_mv_refs(cm, xd, tile, mi, ref_frame, candidates, mi_row, mi_col); | 1753 vp9_find_mv_refs(cm, xd, tile, mi, ref_frame, candidates, mi_row, mi_col); |
| 1750 | 1754 |
| 1751 // Candidate refinement carried out at encoder and decoder | 1755 // Candidate refinement carried out at encoder and decoder |
| 1752 vp9_find_best_ref_mvs(xd, cm->allow_high_precision_mv, candidates, | 1756 vp9_find_best_ref_mvs(xd, cm->allow_high_precision_mv, candidates, |
| 1753 &frame_nearest_mv[ref_frame], | 1757 &frame_nearest_mv[ref_frame], |
| 1754 &frame_near_mv[ref_frame]); | 1758 &frame_near_mv[ref_frame]); |
| 1755 | 1759 |
| 1756 // Further refinement that is encode side only to test the top few candidates | 1760 // Further refinement that is encode side only to test the top few candidates |
| 1757 // in full and choose the best as the centre point for subsequent searches. | 1761 // in full and choose the best as the centre point for subsequent searches. |
| 1758 // The current implementation doesn't support scaling. | 1762 // The current implementation doesn't support scaling. |
| 1759 if (!vp9_is_scaled(sf) && block_size >= BLOCK_8X8) | 1763 if (!vp9_is_scaled(sf) && block_size >= BLOCK_8X8) |
| 1760 vp9_mv_pred(cpi, x, yv12_mb[ref_frame][0].buf, yv12->y_stride, | 1764 vp9_mv_pred(cpi, x, yv12_mb[ref_frame][0].buf, yv12->y_stride, |
| 1761 ref_frame, block_size); | 1765 ref_frame, block_size); |
| 1762 } | 1766 } |
| 1763 | 1767 |
| 1764 static void single_motion_search(VP9_COMP *cpi, MACROBLOCK *x, | 1768 static void single_motion_search(VP9_COMP *cpi, MACROBLOCK *x, |
| 1765 BLOCK_SIZE bsize, | 1769 BLOCK_SIZE bsize, |
| 1766 int mi_row, int mi_col, | 1770 int mi_row, int mi_col, |
| 1767 int_mv *tmp_mv, int *rate_mv) { | 1771 int_mv *tmp_mv, int *rate_mv) { |
| 1768 MACROBLOCKD *xd = &x->e_mbd; | 1772 MACROBLOCKD *xd = &x->e_mbd; |
| 1769 const VP9_COMMON *cm = &cpi->common; | 1773 const VP9_COMMON *cm = &cpi->common; |
| 1770 MB_MODE_INFO *mbmi = &xd->mi[0]->mbmi; | 1774 MB_MODE_INFO *mbmi = &xd->mi[0].src_mi->mbmi; |
| 1771 struct buf_2d backup_yv12[MAX_MB_PLANE] = {{0, 0}}; | 1775 struct buf_2d backup_yv12[MAX_MB_PLANE] = {{0, 0}}; |
| 1772 int bestsme = INT_MAX; | 1776 int bestsme = INT_MAX; |
| 1773 int step_param; | 1777 int step_param; |
| 1774 int sadpb = x->sadperbit16; | 1778 int sadpb = x->sadperbit16; |
| 1775 MV mvp_full; | 1779 MV mvp_full; |
| 1776 int ref = mbmi->ref_frame[0]; | 1780 int ref = mbmi->ref_frame[0]; |
| 1777 MV ref_mv = mbmi->ref_mvs[ref][0].as_mv; | 1781 MV ref_mv = mbmi->ref_mvs[ref][0].as_mv; |
| 1778 | 1782 |
| 1779 int tmp_col_min = x->mv_col_min; | 1783 int tmp_col_min = x->mv_col_min; |
| 1780 int tmp_col_max = x->mv_col_max; | 1784 int tmp_col_max = x->mv_col_max; |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1887 | 1891 |
| 1888 static void joint_motion_search(VP9_COMP *cpi, MACROBLOCK *x, | 1892 static void joint_motion_search(VP9_COMP *cpi, MACROBLOCK *x, |
| 1889 BLOCK_SIZE bsize, | 1893 BLOCK_SIZE bsize, |
| 1890 int_mv *frame_mv, | 1894 int_mv *frame_mv, |
| 1891 int mi_row, int mi_col, | 1895 int mi_row, int mi_col, |
| 1892 int_mv single_newmv[MAX_REF_FRAMES], | 1896 int_mv single_newmv[MAX_REF_FRAMES], |
| 1893 int *rate_mv) { | 1897 int *rate_mv) { |
| 1894 const int pw = 4 * num_4x4_blocks_wide_lookup[bsize]; | 1898 const int pw = 4 * num_4x4_blocks_wide_lookup[bsize]; |
| 1895 const int ph = 4 * num_4x4_blocks_high_lookup[bsize]; | 1899 const int ph = 4 * num_4x4_blocks_high_lookup[bsize]; |
| 1896 MACROBLOCKD *xd = &x->e_mbd; | 1900 MACROBLOCKD *xd = &x->e_mbd; |
| 1897 MB_MODE_INFO *mbmi = &xd->mi[0]->mbmi; | 1901 MB_MODE_INFO *mbmi = &xd->mi[0].src_mi->mbmi; |
| 1898 const int refs[2] = { mbmi->ref_frame[0], | 1902 const int refs[2] = { mbmi->ref_frame[0], |
| 1899 mbmi->ref_frame[1] < 0 ? 0 : mbmi->ref_frame[1] }; | 1903 mbmi->ref_frame[1] < 0 ? 0 : mbmi->ref_frame[1] }; |
| 1900 int_mv ref_mv[2]; | 1904 int_mv ref_mv[2]; |
| 1901 int ite, ref; | 1905 int ite, ref; |
| 1902 // Prediction buffer from second frame. | 1906 // Prediction buffer from second frame. |
| 1903 uint8_t *second_pred = vpx_memalign(16, pw * ph * sizeof(uint8_t)); | 1907 uint8_t *second_pred = vpx_memalign(16, pw * ph * sizeof(uint8_t)); |
| 1904 const InterpKernel *kernel = vp9_get_interp_kernel(mbmi->interp_filter); | 1908 const InterpKernel *kernel = vp9_get_interp_kernel(mbmi->interp_filter); |
| 1905 | 1909 |
| 1906 // Do joint motion search in compound mode to get more accurate mv. | 1910 // Do joint motion search in compound mode to get more accurate mv. |
| 1907 struct buf_2d backup_yv12[2][MAX_MB_PLANE]; | 1911 struct buf_2d backup_yv12[2][MAX_MB_PLANE]; |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2129 int_mv (*mode_mv)[MAX_REF_FRAMES], | 2133 int_mv (*mode_mv)[MAX_REF_FRAMES], |
| 2130 int mi_row, int mi_col, | 2134 int mi_row, int mi_col, |
| 2131 int_mv single_newmv[MAX_REF_FRAMES], | 2135 int_mv single_newmv[MAX_REF_FRAMES], |
| 2132 INTERP_FILTER (*single_filter)[MAX_REF_FRAMES], | 2136 INTERP_FILTER (*single_filter)[MAX_REF_FRAMES], |
| 2133 int (*single_skippable)[MAX_REF_FRAMES], | 2137 int (*single_skippable)[MAX_REF_FRAMES], |
| 2134 int64_t *psse, | 2138 int64_t *psse, |
| 2135 const int64_t ref_best_rd) { | 2139 const int64_t ref_best_rd) { |
| 2136 VP9_COMMON *cm = &cpi->common; | 2140 VP9_COMMON *cm = &cpi->common; |
| 2137 RD_OPT *rd_opt = &cpi->rd; | 2141 RD_OPT *rd_opt = &cpi->rd; |
| 2138 MACROBLOCKD *xd = &x->e_mbd; | 2142 MACROBLOCKD *xd = &x->e_mbd; |
| 2139 MB_MODE_INFO *mbmi = &xd->mi[0]->mbmi; | 2143 MB_MODE_INFO *mbmi = &xd->mi[0].src_mi->mbmi; |
| 2140 const int is_comp_pred = has_second_ref(mbmi); | 2144 const int is_comp_pred = has_second_ref(mbmi); |
| 2141 const int this_mode = mbmi->mode; | 2145 const int this_mode = mbmi->mode; |
| 2142 int_mv *frame_mv = mode_mv[this_mode]; | 2146 int_mv *frame_mv = mode_mv[this_mode]; |
| 2143 int i; | 2147 int i; |
| 2144 int refs[2] = { mbmi->ref_frame[0], | 2148 int refs[2] = { mbmi->ref_frame[0], |
| 2145 (mbmi->ref_frame[1] < 0 ? 0 : mbmi->ref_frame[1]) }; | 2149 (mbmi->ref_frame[1] < 0 ? 0 : mbmi->ref_frame[1]) }; |
| 2146 int_mv cur_mv[2]; | 2150 int_mv cur_mv[2]; |
| 2147 int64_t this_rd = 0; | 2151 int64_t this_rd = 0; |
| 2148 DECLARE_ALIGNED_ARRAY(16, uint8_t, tmp_buf, MAX_MB_PLANE * 64 * 64); | 2152 DECLARE_ALIGNED_ARRAY(16, uint8_t, tmp_buf, MAX_MB_PLANE * 64 * 64); |
| 2149 int pred_exists = 0; | 2153 int pred_exists = 0; |
| 2150 int intpel_mv; | 2154 int intpel_mv; |
| 2151 int64_t rd, tmp_rd, best_rd = INT64_MAX; | 2155 int64_t rd, tmp_rd, best_rd = INT64_MAX; |
| 2152 int best_needs_copy = 0; | 2156 int best_needs_copy = 0; |
| 2153 uint8_t *orig_dst[MAX_MB_PLANE]; | 2157 uint8_t *orig_dst[MAX_MB_PLANE]; |
| 2154 int orig_dst_stride[MAX_MB_PLANE]; | 2158 int orig_dst_stride[MAX_MB_PLANE]; |
| 2155 int rs = 0; | 2159 int rs = 0; |
| 2156 INTERP_FILTER best_filter = SWITCHABLE; | 2160 INTERP_FILTER best_filter = SWITCHABLE; |
| 2157 uint8_t skip_txfm[MAX_MB_PLANE << 2] = {0}; | 2161 uint8_t skip_txfm[MAX_MB_PLANE << 2] = {0}; |
| 2158 int64_t bsse[MAX_MB_PLANE << 2] = {0}; | 2162 int64_t bsse[MAX_MB_PLANE << 2] = {0}; |
| 2159 | 2163 |
| 2160 int bsl = mi_width_log2_lookup[bsize]; | 2164 int bsl = mi_width_log2_lookup[bsize]; |
| 2161 int pred_filter_search = cpi->sf.cb_pred_filter_search ? | 2165 int pred_filter_search = cpi->sf.cb_pred_filter_search ? |
| 2162 (((mi_row + mi_col) >> bsl) + | 2166 (((mi_row + mi_col) >> bsl) + |
| 2163 get_chessboard_index(cm->current_video_frame)) & 0x1 : 0; | 2167 get_chessboard_index(cm->current_video_frame)) & 0x1 : 0; |
| 2164 | 2168 |
| 2165 if (pred_filter_search) { | 2169 if (pred_filter_search) { |
| 2166 INTERP_FILTER af = SWITCHABLE, lf = SWITCHABLE; | 2170 INTERP_FILTER af = SWITCHABLE, lf = SWITCHABLE; |
| 2167 if (xd->up_available) | 2171 if (xd->up_available) |
| 2168 af = xd->mi[-xd->mi_stride]->mbmi.interp_filter; | 2172 af = xd->mi[-xd->mi_stride].src_mi->mbmi.interp_filter; |
| 2169 if (xd->left_available) | 2173 if (xd->left_available) |
| 2170 lf = xd->mi[-1]->mbmi.interp_filter; | 2174 lf = xd->mi[-1].src_mi->mbmi.interp_filter; |
| 2171 | 2175 |
| 2172 if ((this_mode != NEWMV) || (af == lf)) | 2176 if ((this_mode != NEWMV) || (af == lf)) |
| 2173 best_filter = af; | 2177 best_filter = af; |
| 2174 } | 2178 } |
| 2175 | 2179 |
| 2176 if (is_comp_pred) { | 2180 if (is_comp_pred) { |
| 2177 if (frame_mv[refs[0]].as_int == INVALID_MV || | 2181 if (frame_mv[refs[0]].as_int == INVALID_MV || |
| 2178 frame_mv[refs[1]].as_int == INVALID_MV) | 2182 frame_mv[refs[1]].as_int == INVALID_MV) |
| 2179 return INT64_MAX; | 2183 return INT64_MAX; |
| 2180 | 2184 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 2205 } | 2209 } |
| 2206 *rate2 += rate_mv; | 2210 *rate2 += rate_mv; |
| 2207 } else { | 2211 } else { |
| 2208 int_mv tmp_mv; | 2212 int_mv tmp_mv; |
| 2209 single_motion_search(cpi, x, bsize, mi_row, mi_col, | 2213 single_motion_search(cpi, x, bsize, mi_row, mi_col, |
| 2210 &tmp_mv, &rate_mv); | 2214 &tmp_mv, &rate_mv); |
| 2211 if (tmp_mv.as_int == INVALID_MV) | 2215 if (tmp_mv.as_int == INVALID_MV) |
| 2212 return INT64_MAX; | 2216 return INT64_MAX; |
| 2213 *rate2 += rate_mv; | 2217 *rate2 += rate_mv; |
| 2214 frame_mv[refs[0]].as_int = | 2218 frame_mv[refs[0]].as_int = |
| 2215 xd->mi[0]->bmi[0].as_mv[0].as_int = tmp_mv.as_int; | 2219 xd->mi[0].src_mi->bmi[0].as_mv[0].as_int = tmp_mv.as_int; |
| 2216 single_newmv[refs[0]].as_int = tmp_mv.as_int; | 2220 single_newmv[refs[0]].as_int = tmp_mv.as_int; |
| 2217 } | 2221 } |
| 2218 } | 2222 } |
| 2219 | 2223 |
| 2220 for (i = 0; i < is_comp_pred + 1; ++i) { | 2224 for (i = 0; i < is_comp_pred + 1; ++i) { |
| 2221 cur_mv[i] = frame_mv[refs[i]]; | 2225 cur_mv[i] = frame_mv[refs[i]]; |
| 2222 // Clip "next_nearest" so that it does not extend to far out of image | 2226 // Clip "next_nearest" so that it does not extend to far out of image |
| 2223 if (this_mode != NEWMV) | 2227 if (this_mode != NEWMV) |
| 2224 clamp_mv2(&cur_mv[i].as_mv, xd); | 2228 clamp_mv2(&cur_mv[i].as_mv, xd); |
| 2225 | 2229 |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2457 PICK_MODE_CONTEXT *ctx, int64_t best_rd) { | 2461 PICK_MODE_CONTEXT *ctx, int64_t best_rd) { |
| 2458 VP9_COMMON *const cm = &cpi->common; | 2462 VP9_COMMON *const cm = &cpi->common; |
| 2459 MACROBLOCKD *const xd = &x->e_mbd; | 2463 MACROBLOCKD *const xd = &x->e_mbd; |
| 2460 struct macroblockd_plane *const pd = xd->plane; | 2464 struct macroblockd_plane *const pd = xd->plane; |
| 2461 int rate_y = 0, rate_uv = 0, rate_y_tokenonly = 0, rate_uv_tokenonly = 0; | 2465 int rate_y = 0, rate_uv = 0, rate_y_tokenonly = 0, rate_uv_tokenonly = 0; |
| 2462 int y_skip = 0, uv_skip = 0; | 2466 int y_skip = 0, uv_skip = 0; |
| 2463 int64_t dist_y = 0, dist_uv = 0, tx_cache[TX_MODES] = { 0 }; | 2467 int64_t dist_y = 0, dist_uv = 0, tx_cache[TX_MODES] = { 0 }; |
| 2464 TX_SIZE max_uv_tx_size; | 2468 TX_SIZE max_uv_tx_size; |
| 2465 x->skip_encode = 0; | 2469 x->skip_encode = 0; |
| 2466 ctx->skip = 0; | 2470 ctx->skip = 0; |
| 2467 xd->mi[0]->mbmi.ref_frame[0] = INTRA_FRAME; | 2471 xd->mi[0].src_mi->mbmi.ref_frame[0] = INTRA_FRAME; |
| 2468 | 2472 |
| 2469 if (bsize >= BLOCK_8X8) { | 2473 if (bsize >= BLOCK_8X8) { |
| 2470 if (rd_pick_intra_sby_mode(cpi, x, &rate_y, &rate_y_tokenonly, | 2474 if (rd_pick_intra_sby_mode(cpi, x, &rate_y, &rate_y_tokenonly, |
| 2471 &dist_y, &y_skip, bsize, tx_cache, | 2475 &dist_y, &y_skip, bsize, tx_cache, |
| 2472 best_rd) >= best_rd) { | 2476 best_rd) >= best_rd) { |
| 2473 *returnrate = INT_MAX; | 2477 *returnrate = INT_MAX; |
| 2474 return; | 2478 return; |
| 2475 } | 2479 } |
| 2476 max_uv_tx_size = get_uv_tx_size_impl(xd->mi[0]->mbmi.tx_size, bsize, | 2480 max_uv_tx_size = get_uv_tx_size_impl(xd->mi[0].src_mi->mbmi.tx_size, bsize, |
| 2477 pd[1].subsampling_x, | 2481 pd[1].subsampling_x, |
| 2478 pd[1].subsampling_y); | 2482 pd[1].subsampling_y); |
| 2479 rd_pick_intra_sbuv_mode(cpi, x, ctx, &rate_uv, &rate_uv_tokenonly, | 2483 rd_pick_intra_sbuv_mode(cpi, x, ctx, &rate_uv, &rate_uv_tokenonly, |
| 2480 &dist_uv, &uv_skip, bsize, max_uv_tx_size); | 2484 &dist_uv, &uv_skip, bsize, max_uv_tx_size); |
| 2481 } else { | 2485 } else { |
| 2482 y_skip = 0; | 2486 y_skip = 0; |
| 2483 if (rd_pick_intra_sub_8x8_y_mode(cpi, x, &rate_y, &rate_y_tokenonly, | 2487 if (rd_pick_intra_sub_8x8_y_mode(cpi, x, &rate_y, &rate_y_tokenonly, |
| 2484 &dist_y, best_rd) >= best_rd) { | 2488 &dist_y, best_rd) >= best_rd) { |
| 2485 *returnrate = INT_MAX; | 2489 *returnrate = INT_MAX; |
| 2486 return; | 2490 return; |
| 2487 } | 2491 } |
| 2488 max_uv_tx_size = get_uv_tx_size_impl(xd->mi[0]->mbmi.tx_size, bsize, | 2492 max_uv_tx_size = get_uv_tx_size_impl(xd->mi[0].src_mi->mbmi.tx_size, bsize, |
| 2489 pd[1].subsampling_x, | 2493 pd[1].subsampling_x, |
| 2490 pd[1].subsampling_y); | 2494 pd[1].subsampling_y); |
| 2491 rd_pick_intra_sbuv_mode(cpi, x, ctx, &rate_uv, &rate_uv_tokenonly, | 2495 rd_pick_intra_sbuv_mode(cpi, x, ctx, &rate_uv, &rate_uv_tokenonly, |
| 2492 &dist_uv, &uv_skip, BLOCK_8X8, max_uv_tx_size); | 2496 &dist_uv, &uv_skip, BLOCK_8X8, max_uv_tx_size); |
| 2493 } | 2497 } |
| 2494 | 2498 |
| 2495 if (y_skip && uv_skip) { | 2499 if (y_skip && uv_skip) { |
| 2496 *returnrate = rate_y + rate_uv - rate_y_tokenonly - rate_uv_tokenonly + | 2500 *returnrate = rate_y + rate_uv - rate_y_tokenonly - rate_uv_tokenonly + |
| 2497 vp9_cost_bit(vp9_get_skip_prob(cm, xd), 1); | 2501 vp9_cost_bit(vp9_get_skip_prob(cm, xd), 1); |
| 2498 *returndist = dist_y + dist_uv; | 2502 *returndist = dist_y + dist_uv; |
| 2499 vp9_zero(ctx->tx_rd_diff); | 2503 vp9_zero(ctx->tx_rd_diff); |
| 2500 } else { | 2504 } else { |
| 2501 int i; | 2505 int i; |
| 2502 *returnrate = rate_y + rate_uv + vp9_cost_bit(vp9_get_skip_prob(cm, xd), 0); | 2506 *returnrate = rate_y + rate_uv + vp9_cost_bit(vp9_get_skip_prob(cm, xd), 0); |
| 2503 *returndist = dist_y + dist_uv; | 2507 *returndist = dist_y + dist_uv; |
| 2504 if (cpi->sf.tx_size_search_method == USE_FULL_RD) | 2508 if (cpi->sf.tx_size_search_method == USE_FULL_RD) |
| 2505 for (i = 0; i < TX_MODES; i++) { | 2509 for (i = 0; i < TX_MODES; i++) { |
| 2506 if (tx_cache[i] < INT64_MAX && tx_cache[cm->tx_mode] < INT64_MAX) | 2510 if (tx_cache[i] < INT64_MAX && tx_cache[cm->tx_mode] < INT64_MAX) |
| 2507 ctx->tx_rd_diff[i] = tx_cache[i] - tx_cache[cm->tx_mode]; | 2511 ctx->tx_rd_diff[i] = tx_cache[i] - tx_cache[cm->tx_mode]; |
| 2508 else | 2512 else |
| 2509 ctx->tx_rd_diff[i] = 0; | 2513 ctx->tx_rd_diff[i] = 0; |
| 2510 } | 2514 } |
| 2511 } | 2515 } |
| 2512 | 2516 |
| 2513 ctx->mic = *xd->mi[0]; | 2517 ctx->mic = *xd->mi[0].src_mi; |
| 2514 } | 2518 } |
| 2515 | 2519 |
| 2516 // Updating rd_thresh_freq_fact[] here means that the different | 2520 // Updating rd_thresh_freq_fact[] here means that the different |
| 2517 // partition/block sizes are handled independently based on the best | 2521 // partition/block sizes are handled independently based on the best |
| 2518 // choice for the current partition. It may well be better to keep a scaled | 2522 // choice for the current partition. It may well be better to keep a scaled |
| 2519 // best rd so far value and update rd_thresh_freq_fact based on the mode/size | 2523 // best rd so far value and update rd_thresh_freq_fact based on the mode/size |
| 2520 // combination that wins out. | 2524 // combination that wins out. |
| 2521 static void update_rd_thresh_fact(VP9_COMP *cpi, int bsize, | 2525 static void update_rd_thresh_fact(VP9_COMP *cpi, int bsize, |
| 2522 int best_mode_index) { | 2526 int best_mode_index) { |
| 2523 if (cpi->sf.adaptive_rd_thresh > 0) { | 2527 if (cpi->sf.adaptive_rd_thresh > 0) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 2540 const TileInfo *const tile, | 2544 const TileInfo *const tile, |
| 2541 int mi_row, int mi_col, | 2545 int mi_row, int mi_col, |
| 2542 int *returnrate, | 2546 int *returnrate, |
| 2543 int64_t *returndistortion, | 2547 int64_t *returndistortion, |
| 2544 BLOCK_SIZE bsize, | 2548 BLOCK_SIZE bsize, |
| 2545 PICK_MODE_CONTEXT *ctx, | 2549 PICK_MODE_CONTEXT *ctx, |
| 2546 int64_t best_rd_so_far) { | 2550 int64_t best_rd_so_far) { |
| 2547 VP9_COMMON *const cm = &cpi->common; | 2551 VP9_COMMON *const cm = &cpi->common; |
| 2548 RD_OPT *const rd_opt = &cpi->rd; | 2552 RD_OPT *const rd_opt = &cpi->rd; |
| 2549 MACROBLOCKD *const xd = &x->e_mbd; | 2553 MACROBLOCKD *const xd = &x->e_mbd; |
| 2550 MB_MODE_INFO *const mbmi = &xd->mi[0]->mbmi; | 2554 MB_MODE_INFO *const mbmi = &xd->mi[0].src_mi->mbmi; |
| 2551 const struct segmentation *const seg = &cm->seg; | 2555 const struct segmentation *const seg = &cm->seg; |
| 2552 struct macroblockd_plane *const pd = xd->plane; | 2556 struct macroblockd_plane *const pd = xd->plane; |
| 2553 PREDICTION_MODE this_mode; | 2557 PREDICTION_MODE this_mode; |
| 2554 MV_REFERENCE_FRAME ref_frame, second_ref_frame; | 2558 MV_REFERENCE_FRAME ref_frame, second_ref_frame; |
| 2555 unsigned char segment_id = mbmi->segment_id; | 2559 unsigned char segment_id = mbmi->segment_id; |
| 2556 int comp_pred, i, k; | 2560 int comp_pred, i, k; |
| 2557 int_mv frame_mv[MB_MODE_COUNT][MAX_REF_FRAMES]; | 2561 int_mv frame_mv[MB_MODE_COUNT][MAX_REF_FRAMES]; |
| 2558 struct buf_2d yv12_mb[4][MAX_MB_PLANE]; | 2562 struct buf_2d yv12_mb[4][MAX_MB_PLANE]; |
| 2559 int_mv single_newmv[MAX_REF_FRAMES] = { { 0 } }; | 2563 int_mv single_newmv[MAX_REF_FRAMES] = { { 0 } }; |
| 2560 INTERP_FILTER single_inter_filter[MB_MODE_COUNT][MAX_REF_FRAMES]; | 2564 INTERP_FILTER single_inter_filter[MB_MODE_COUNT][MAX_REF_FRAMES]; |
| 2561 int single_skippable[MB_MODE_COUNT][MAX_REF_FRAMES]; | 2565 int single_skippable[MB_MODE_COUNT][MAX_REF_FRAMES]; |
| 2562 static const int flag_list[4] = { 0, VP9_LAST_FLAG, VP9_GOLD_FLAG, | 2566 static const int flag_list[4] = { 0, VP9_LAST_FLAG, VP9_GOLD_FLAG, |
| 2563 VP9_ALT_FLAG }; | 2567 VP9_ALT_FLAG }; |
| 2564 int64_t best_rd = best_rd_so_far; | 2568 int64_t best_rd = best_rd_so_far; |
| 2565 int64_t best_tx_rd[TX_MODES]; | 2569 int64_t best_tx_rd[TX_MODES]; |
| 2566 int64_t best_tx_diff[TX_MODES]; | 2570 int64_t best_tx_diff[TX_MODES]; |
| 2567 int64_t best_pred_diff[REFERENCE_MODES]; | 2571 int64_t best_pred_diff[REFERENCE_MODES]; |
| 2568 int64_t best_pred_rd[REFERENCE_MODES]; | 2572 int64_t best_pred_rd[REFERENCE_MODES]; |
| 2569 int64_t best_filter_rd[SWITCHABLE_FILTER_CONTEXTS]; | 2573 int64_t best_filter_rd[SWITCHABLE_FILTER_CONTEXTS]; |
| 2570 int64_t best_filter_diff[SWITCHABLE_FILTER_CONTEXTS]; | 2574 int64_t best_filter_diff[SWITCHABLE_FILTER_CONTEXTS]; |
| 2571 MB_MODE_INFO best_mbmode; | 2575 MB_MODE_INFO best_mbmode; |
| 2572 int best_mode_skippable = 0; | 2576 int best_mode_skippable = 0; |
| 2573 int mode_index, best_mode_index = -1; | 2577 int midx, best_mode_index = -1; |
| 2574 unsigned int ref_costs_single[MAX_REF_FRAMES], ref_costs_comp[MAX_REF_FRAMES]; | 2578 unsigned int ref_costs_single[MAX_REF_FRAMES], ref_costs_comp[MAX_REF_FRAMES]; |
| 2575 vp9_prob comp_mode_p; | 2579 vp9_prob comp_mode_p; |
| 2576 int64_t best_intra_rd = INT64_MAX; | 2580 int64_t best_intra_rd = INT64_MAX; |
| 2577 int64_t best_inter_rd = INT64_MAX; | 2581 unsigned int best_pred_sse = UINT_MAX; |
| 2578 PREDICTION_MODE best_intra_mode = DC_PRED; | 2582 PREDICTION_MODE best_intra_mode = DC_PRED; |
| 2579 MV_REFERENCE_FRAME best_inter_ref_frame = LAST_FRAME; | |
| 2580 int rate_uv_intra[TX_SIZES], rate_uv_tokenonly[TX_SIZES]; | 2583 int rate_uv_intra[TX_SIZES], rate_uv_tokenonly[TX_SIZES]; |
| 2581 int64_t dist_uv[TX_SIZES]; | 2584 int64_t dist_uv[TX_SIZES]; |
| 2582 int skip_uv[TX_SIZES]; | 2585 int skip_uv[TX_SIZES]; |
| 2583 PREDICTION_MODE mode_uv[TX_SIZES]; | 2586 PREDICTION_MODE mode_uv[TX_SIZES]; |
| 2584 int intra_cost_penalty = 20 * vp9_dc_quant(cm->base_qindex, cm->y_dc_delta_q); | 2587 const int intra_cost_penalty = |
| 2588 20 * vp9_dc_quant(cm->base_qindex, cm->y_dc_delta_q, cm->bit_depth); |
| 2585 int best_skip2 = 0; | 2589 int best_skip2 = 0; |
| 2586 int mode_skip_mask = 0; | 2590 uint8_t ref_frame_skip_mask[2] = { 0 }; |
| 2591 uint16_t mode_skip_mask[MAX_REF_FRAMES] = { 0 }; |
| 2587 int mode_skip_start = cpi->sf.mode_skip_start + 1; | 2592 int mode_skip_start = cpi->sf.mode_skip_start + 1; |
| 2588 const int *const rd_threshes = rd_opt->threshes[segment_id][bsize]; | 2593 const int *const rd_threshes = rd_opt->threshes[segment_id][bsize]; |
| 2589 const int *const rd_thresh_freq_fact = rd_opt->thresh_freq_fact[bsize]; | 2594 const int *const rd_thresh_freq_fact = rd_opt->thresh_freq_fact[bsize]; |
| 2595 int mode_threshold[MAX_MODES]; |
| 2596 int *mode_map = rd_opt->mode_map[bsize]; |
| 2590 const int mode_search_skip_flags = cpi->sf.mode_search_skip_flags; | 2597 const int mode_search_skip_flags = cpi->sf.mode_search_skip_flags; |
| 2591 const int intra_y_mode_mask = | |
| 2592 cpi->sf.intra_y_mode_mask[max_txsize_lookup[bsize]]; | |
| 2593 int inter_mode_mask = cpi->sf.inter_mode_mask[bsize]; | |
| 2594 vp9_zero(best_mbmode); | 2598 vp9_zero(best_mbmode); |
| 2599 |
| 2595 x->skip_encode = cpi->sf.skip_encode_frame && x->q_index < QIDX_SKIP_THRESH; | 2600 x->skip_encode = cpi->sf.skip_encode_frame && x->q_index < QIDX_SKIP_THRESH; |
| 2596 | 2601 |
| 2597 estimate_ref_frame_costs(cm, xd, segment_id, ref_costs_single, ref_costs_comp, | 2602 estimate_ref_frame_costs(cm, xd, segment_id, ref_costs_single, ref_costs_comp, |
| 2598 &comp_mode_p); | 2603 &comp_mode_p); |
| 2599 | 2604 |
| 2600 for (i = 0; i < REFERENCE_MODES; ++i) | 2605 for (i = 0; i < REFERENCE_MODES; ++i) |
| 2601 best_pred_rd[i] = INT64_MAX; | 2606 best_pred_rd[i] = INT64_MAX; |
| 2602 for (i = 0; i < TX_MODES; i++) | 2607 for (i = 0; i < TX_MODES; i++) |
| 2603 best_tx_rd[i] = INT64_MAX; | 2608 best_tx_rd[i] = INT64_MAX; |
| 2604 for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; i++) | 2609 for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; i++) |
| (...skipping 15 matching lines...) Expand all Loading... |
| 2620 x->pred_mv_sad[ref_frame] = INT_MAX; | 2625 x->pred_mv_sad[ref_frame] = INT_MAX; |
| 2621 if (cpi->ref_frame_flags & flag_list[ref_frame]) { | 2626 if (cpi->ref_frame_flags & flag_list[ref_frame]) { |
| 2622 setup_buffer_inter(cpi, x, tile, ref_frame, bsize, mi_row, mi_col, | 2627 setup_buffer_inter(cpi, x, tile, ref_frame, bsize, mi_row, mi_col, |
| 2623 frame_mv[NEARESTMV], frame_mv[NEARMV], yv12_mb); | 2628 frame_mv[NEARESTMV], frame_mv[NEARMV], yv12_mb); |
| 2624 } | 2629 } |
| 2625 frame_mv[NEWMV][ref_frame].as_int = INVALID_MV; | 2630 frame_mv[NEWMV][ref_frame].as_int = INVALID_MV; |
| 2626 frame_mv[ZEROMV][ref_frame].as_int = 0; | 2631 frame_mv[ZEROMV][ref_frame].as_int = 0; |
| 2627 } | 2632 } |
| 2628 | 2633 |
| 2629 for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) { | 2634 for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) { |
| 2630 // All modes from vp9_mode_order that use this frame as any ref | |
| 2631 static const int ref_frame_mask_all[] = { | |
| 2632 0x0, 0x123291, 0x25c444, 0x39b722 | |
| 2633 }; | |
| 2634 // Fixed mv modes (NEARESTMV, NEARMV, ZEROMV) from vp9_mode_order that use | |
| 2635 // this frame as their primary ref | |
| 2636 static const int ref_frame_mask_fixedmv[] = { | |
| 2637 0x0, 0x121281, 0x24c404, 0x080102 | |
| 2638 }; | |
| 2639 if (!(cpi->ref_frame_flags & flag_list[ref_frame])) { | 2635 if (!(cpi->ref_frame_flags & flag_list[ref_frame])) { |
| 2640 // Skip modes for missing references | 2636 // Skip checking missing references in both single and compound reference |
| 2641 mode_skip_mask |= ref_frame_mask_all[ref_frame]; | 2637 // modes. Note that a mode will be skipped iff both reference frames |
| 2638 // are masked out. |
| 2639 ref_frame_skip_mask[0] |= (1 << ref_frame); |
| 2640 ref_frame_skip_mask[1] |= SECOND_REF_FRAME_MASK; |
| 2642 } else if (cpi->sf.reference_masking) { | 2641 } else if (cpi->sf.reference_masking) { |
| 2643 for (i = LAST_FRAME; i <= ALTREF_FRAME; ++i) { | 2642 for (i = LAST_FRAME; i <= ALTREF_FRAME; ++i) { |
| 2644 // Skip fixed mv modes for poor references | 2643 // Skip fixed mv modes for poor references |
| 2645 if ((x->pred_mv_sad[ref_frame] >> 2) > x->pred_mv_sad[i]) { | 2644 if ((x->pred_mv_sad[ref_frame] >> 2) > x->pred_mv_sad[i]) { |
| 2646 mode_skip_mask |= ref_frame_mask_fixedmv[ref_frame]; | 2645 mode_skip_mask[ref_frame] |= INTER_NEAREST_NEAR_ZERO; |
| 2647 break; | 2646 break; |
| 2648 } | 2647 } |
| 2649 } | 2648 } |
| 2650 } | 2649 } |
| 2651 // If the segment reference frame feature is enabled.... | 2650 // If the segment reference frame feature is enabled.... |
| 2652 // then do nothing if the current ref frame is not allowed.. | 2651 // then do nothing if the current ref frame is not allowed.. |
| 2653 if (vp9_segfeature_active(seg, segment_id, SEG_LVL_REF_FRAME) && | 2652 if (vp9_segfeature_active(seg, segment_id, SEG_LVL_REF_FRAME) && |
| 2654 vp9_get_segdata(seg, segment_id, SEG_LVL_REF_FRAME) != (int)ref_frame) { | 2653 vp9_get_segdata(seg, segment_id, SEG_LVL_REF_FRAME) != (int)ref_frame) { |
| 2655 mode_skip_mask |= ref_frame_mask_all[ref_frame]; | 2654 ref_frame_skip_mask[0] |= (1 << ref_frame); |
| 2655 ref_frame_skip_mask[1] |= SECOND_REF_FRAME_MASK; |
| 2656 } | 2656 } |
| 2657 } | 2657 } |
| 2658 | 2658 |
| 2659 // Disable this drop out case if the ref frame | 2659 // Disable this drop out case if the ref frame |
| 2660 // segment level feature is enabled for this segment. This is to | 2660 // segment level feature is enabled for this segment. This is to |
| 2661 // prevent the possibility that we end up unable to pick any mode. | 2661 // prevent the possibility that we end up unable to pick any mode. |
| 2662 if (!vp9_segfeature_active(seg, segment_id, SEG_LVL_REF_FRAME)) { | 2662 if (!vp9_segfeature_active(seg, segment_id, SEG_LVL_REF_FRAME)) { |
| 2663 // Only consider ZEROMV/ALTREF_FRAME for alt ref frame, | 2663 // Only consider ZEROMV/ALTREF_FRAME for alt ref frame, |
| 2664 // unless ARNR filtering is enabled in which case we want | 2664 // unless ARNR filtering is enabled in which case we want |
| 2665 // an unfiltered alternative. We allow near/nearest as well | 2665 // an unfiltered alternative. We allow near/nearest as well |
| 2666 // because they may result in zero-zero MVs but be cheaper. | 2666 // because they may result in zero-zero MVs but be cheaper. |
| 2667 if (cpi->rc.is_src_frame_alt_ref && (cpi->oxcf.arnr_max_frames == 0)) { | 2667 if (cpi->rc.is_src_frame_alt_ref && (cpi->oxcf.arnr_max_frames == 0)) { |
| 2668 mode_skip_mask = | 2668 ref_frame_skip_mask[0] = (1 << LAST_FRAME) | (1 << GOLDEN_FRAME); |
| 2669 ~((1 << THR_NEARESTA) | (1 << THR_NEARA) | (1 << THR_ZEROA)); | 2669 ref_frame_skip_mask[1] = SECOND_REF_FRAME_MASK; |
| 2670 mode_skip_mask[ALTREF_FRAME] = ~INTER_NEAREST_NEAR_ZERO; |
| 2670 if (frame_mv[NEARMV][ALTREF_FRAME].as_int != 0) | 2671 if (frame_mv[NEARMV][ALTREF_FRAME].as_int != 0) |
| 2671 mode_skip_mask |= (1 << THR_NEARA); | 2672 mode_skip_mask[ALTREF_FRAME] |= (1 << NEARMV); |
| 2672 if (frame_mv[NEARESTMV][ALTREF_FRAME].as_int != 0) | 2673 if (frame_mv[NEARESTMV][ALTREF_FRAME].as_int != 0) |
| 2673 mode_skip_mask |= (1 << THR_NEARESTA); | 2674 mode_skip_mask[ALTREF_FRAME] |= (1 << NEARESTMV); |
| 2675 } |
| 2676 } |
| 2677 |
| 2678 if (cpi->rc.is_src_frame_alt_ref) { |
| 2679 if (cpi->sf.alt_ref_search_fp) { |
| 2680 mode_skip_mask[ALTREF_FRAME] = 0; |
| 2681 ref_frame_skip_mask[0] = ~(1 << ALTREF_FRAME); |
| 2682 ref_frame_skip_mask[1] = SECOND_REF_FRAME_MASK; |
| 2674 } | 2683 } |
| 2675 } | 2684 } |
| 2676 | 2685 |
| 2677 if (bsize > cpi->sf.max_intra_bsize) { | 2686 if (bsize > cpi->sf.max_intra_bsize) { |
| 2678 const int all_intra_modes = (1 << THR_DC) | (1 << THR_TM) | | 2687 ref_frame_skip_mask[0] |= (1 << INTRA_FRAME); |
| 2679 (1 << THR_H_PRED) | (1 << THR_V_PRED) | (1 << THR_D135_PRED) | | 2688 ref_frame_skip_mask[1] |= (1 << INTRA_FRAME); |
| 2680 (1 << THR_D207_PRED) | (1 << THR_D153_PRED) | (1 << THR_D63_PRED) | | |
| 2681 (1 << THR_D117_PRED) | (1 << THR_D45_PRED); | |
| 2682 mode_skip_mask |= all_intra_modes; | |
| 2683 } | 2689 } |
| 2684 | 2690 |
| 2685 for (mode_index = 0; mode_index < MAX_MODES; ++mode_index) { | 2691 mode_skip_mask[INTRA_FRAME] |= |
| 2692 ~(cpi->sf.intra_y_mode_mask[max_txsize_lookup[bsize]]); |
| 2693 |
| 2694 for (i = 0; i < MAX_MODES; ++i) |
| 2695 mode_threshold[i] = ((int64_t)rd_threshes[i] * rd_thresh_freq_fact[i]) >> 5; |
| 2696 |
| 2697 midx = cpi->sf.schedule_mode_search ? mode_skip_start : 0; |
| 2698 while (midx > 4) { |
| 2699 uint8_t end_pos = 0; |
| 2700 for (i = 5; i < midx; ++i) { |
| 2701 if (mode_threshold[mode_map[i - 1]] > mode_threshold[mode_map[i]]) { |
| 2702 uint8_t tmp = mode_map[i]; |
| 2703 mode_map[i] = mode_map[i - 1]; |
| 2704 mode_map[i - 1] = tmp; |
| 2705 end_pos = i; |
| 2706 } |
| 2707 } |
| 2708 midx = end_pos; |
| 2709 } |
| 2710 |
| 2711 for (midx = 0; midx < MAX_MODES; ++midx) { |
| 2712 int mode_index = mode_map[midx]; |
| 2686 int mode_excluded = 0; | 2713 int mode_excluded = 0; |
| 2687 int64_t this_rd = INT64_MAX; | 2714 int64_t this_rd = INT64_MAX; |
| 2688 int disable_skip = 0; | 2715 int disable_skip = 0; |
| 2689 int compmode_cost = 0; | 2716 int compmode_cost = 0; |
| 2690 int rate2 = 0, rate_y = 0, rate_uv = 0; | 2717 int rate2 = 0, rate_y = 0, rate_uv = 0; |
| 2691 int64_t distortion2 = 0, distortion_y = 0, distortion_uv = 0; | 2718 int64_t distortion2 = 0, distortion_y = 0, distortion_uv = 0; |
| 2692 int skippable = 0; | 2719 int skippable = 0; |
| 2693 int64_t tx_cache[TX_MODES]; | 2720 int64_t tx_cache[TX_MODES]; |
| 2694 int i; | |
| 2695 int this_skip2 = 0; | 2721 int this_skip2 = 0; |
| 2696 int64_t total_sse = INT64_MAX; | 2722 int64_t total_sse = INT64_MAX; |
| 2697 int early_term = 0; | 2723 int early_term = 0; |
| 2698 | 2724 |
| 2699 this_mode = vp9_mode_order[mode_index].mode; | 2725 this_mode = vp9_mode_order[mode_index].mode; |
| 2700 ref_frame = vp9_mode_order[mode_index].ref_frame[0]; | 2726 ref_frame = vp9_mode_order[mode_index].ref_frame[0]; |
| 2701 if (ref_frame != INTRA_FRAME && !(inter_mode_mask & (1 << this_mode))) | |
| 2702 continue; | |
| 2703 second_ref_frame = vp9_mode_order[mode_index].ref_frame[1]; | 2727 second_ref_frame = vp9_mode_order[mode_index].ref_frame[1]; |
| 2704 | 2728 |
| 2705 // Look at the reference frame of the best mode so far and set the | 2729 // Look at the reference frame of the best mode so far and set the |
| 2706 // skip mask to look at a subset of the remaining modes. | 2730 // skip mask to look at a subset of the remaining modes. |
| 2707 if (mode_index == mode_skip_start && best_mode_index >= 0) { | 2731 if (midx == mode_skip_start && best_mode_index >= 0) { |
| 2708 switch (vp9_mode_order[best_mode_index].ref_frame[0]) { | 2732 switch (best_mbmode.ref_frame[0]) { |
| 2709 case INTRA_FRAME: | 2733 case INTRA_FRAME: |
| 2710 break; | 2734 break; |
| 2711 case LAST_FRAME: | 2735 case LAST_FRAME: |
| 2712 mode_skip_mask |= LAST_FRAME_MODE_MASK; | 2736 ref_frame_skip_mask[0] |= LAST_FRAME_MODE_MASK; |
| 2737 ref_frame_skip_mask[1] |= SECOND_REF_FRAME_MASK; |
| 2713 break; | 2738 break; |
| 2714 case GOLDEN_FRAME: | 2739 case GOLDEN_FRAME: |
| 2715 mode_skip_mask |= GOLDEN_FRAME_MODE_MASK; | 2740 ref_frame_skip_mask[0] |= GOLDEN_FRAME_MODE_MASK; |
| 2741 ref_frame_skip_mask[1] |= SECOND_REF_FRAME_MASK; |
| 2716 break; | 2742 break; |
| 2717 case ALTREF_FRAME: | 2743 case ALTREF_FRAME: |
| 2718 mode_skip_mask |= ALT_REF_MODE_MASK; | 2744 ref_frame_skip_mask[0] |= ALT_REF_MODE_MASK; |
| 2719 break; | 2745 break; |
| 2720 case NONE: | 2746 case NONE: |
| 2721 case MAX_REF_FRAMES: | 2747 case MAX_REF_FRAMES: |
| 2722 assert(0 && "Invalid Reference frame"); | 2748 assert(0 && "Invalid Reference frame"); |
| 2723 break; | 2749 break; |
| 2724 } | 2750 } |
| 2725 } | 2751 } |
| 2726 | 2752 |
| 2727 if (cpi->sf.alt_ref_search_fp && cpi->rc.is_src_frame_alt_ref) { | 2753 if (ref_frame_skip_mask[0] & (1 << ref_frame) && |
| 2728 mode_skip_mask = 0; | 2754 ref_frame_skip_mask[1] & (1 << MAX(0, second_ref_frame))) |
| 2729 if (!(ref_frame == ALTREF_FRAME && second_ref_frame == NONE)) | 2755 continue; |
| 2730 continue; | |
| 2731 } | |
| 2732 | 2756 |
| 2733 if (mode_skip_mask & (1 << mode_index)) | 2757 if (mode_skip_mask[ref_frame] & (1 << this_mode)) |
| 2734 continue; | 2758 continue; |
| 2735 | 2759 |
| 2736 // Test best rd so far against threshold for trying this mode. | 2760 // Test best rd so far against threshold for trying this mode. |
| 2737 if (rd_less_than_thresh(best_rd, rd_threshes[mode_index], | 2761 if (best_mode_skippable && cpi->sf.schedule_mode_search) |
| 2738 rd_thresh_freq_fact[mode_index])) | 2762 mode_threshold[mode_index] <<= 1; |
| 2763 |
| 2764 if (best_rd < mode_threshold[mode_index]) |
| 2739 continue; | 2765 continue; |
| 2740 | 2766 |
| 2741 if (cpi->sf.motion_field_mode_search) { | 2767 if (cpi->sf.motion_field_mode_search) { |
| 2742 const int mi_width = MIN(num_8x8_blocks_wide_lookup[bsize], | 2768 const int mi_width = MIN(num_8x8_blocks_wide_lookup[bsize], |
| 2743 tile->mi_col_end - mi_col); | 2769 tile->mi_col_end - mi_col); |
| 2744 const int mi_height = MIN(num_8x8_blocks_high_lookup[bsize], | 2770 const int mi_height = MIN(num_8x8_blocks_high_lookup[bsize], |
| 2745 tile->mi_row_end - mi_row); | 2771 tile->mi_row_end - mi_row); |
| 2746 const int bsl = mi_width_log2(bsize); | 2772 const int bsl = mi_width_log2(bsize); |
| 2747 int cb_partition_search_ctrl = (((mi_row + mi_col) >> bsl) | 2773 int cb_partition_search_ctrl = (((mi_row + mi_col) >> bsl) |
| 2748 + get_chessboard_index(cm->current_video_frame)) & 0x1; | 2774 + get_chessboard_index(cm->current_video_frame)) & 0x1; |
| 2749 MB_MODE_INFO *ref_mbmi; | 2775 MB_MODE_INFO *ref_mbmi; |
| 2750 int const_motion = 1; | 2776 int const_motion = 1; |
| 2751 int skip_ref_frame = !cb_partition_search_ctrl; | 2777 int skip_ref_frame = !cb_partition_search_ctrl; |
| 2752 MV_REFERENCE_FRAME rf = NONE; | 2778 MV_REFERENCE_FRAME rf = NONE; |
| 2753 int_mv ref_mv; | 2779 int_mv ref_mv; |
| 2754 ref_mv.as_int = INVALID_MV; | 2780 ref_mv.as_int = INVALID_MV; |
| 2755 | 2781 |
| 2756 if ((mi_row - 1) >= tile->mi_row_start) { | 2782 if ((mi_row - 1) >= tile->mi_row_start) { |
| 2757 ref_mv = xd->mi[-xd->mi_stride]->mbmi.mv[0]; | 2783 ref_mv = xd->mi[-xd->mi_stride].src_mi->mbmi.mv[0]; |
| 2758 rf = xd->mi[-xd->mi_stride]->mbmi.ref_frame[0]; | 2784 rf = xd->mi[-xd->mi_stride].src_mi->mbmi.ref_frame[0]; |
| 2759 for (i = 0; i < mi_width; ++i) { | 2785 for (i = 0; i < mi_width; ++i) { |
| 2760 ref_mbmi = &xd->mi[-xd->mi_stride + i]->mbmi; | 2786 ref_mbmi = &xd->mi[-xd->mi_stride + i].src_mi->mbmi; |
| 2761 const_motion &= (ref_mv.as_int == ref_mbmi->mv[0].as_int) && | 2787 const_motion &= (ref_mv.as_int == ref_mbmi->mv[0].as_int) && |
| 2762 (ref_frame == ref_mbmi->ref_frame[0]); | 2788 (ref_frame == ref_mbmi->ref_frame[0]); |
| 2763 skip_ref_frame &= (rf == ref_mbmi->ref_frame[0]); | 2789 skip_ref_frame &= (rf == ref_mbmi->ref_frame[0]); |
| 2764 } | 2790 } |
| 2765 } | 2791 } |
| 2766 | 2792 |
| 2767 if ((mi_col - 1) >= tile->mi_col_start) { | 2793 if ((mi_col - 1) >= tile->mi_col_start) { |
| 2768 if (ref_mv.as_int == INVALID_MV) | 2794 if (ref_mv.as_int == INVALID_MV) |
| 2769 ref_mv = xd->mi[-1]->mbmi.mv[0]; | 2795 ref_mv = xd->mi[-1].src_mi->mbmi.mv[0]; |
| 2770 if (rf == NONE) | 2796 if (rf == NONE) |
| 2771 rf = xd->mi[-1]->mbmi.ref_frame[0]; | 2797 rf = xd->mi[-1].src_mi->mbmi.ref_frame[0]; |
| 2772 for (i = 0; i < mi_height; ++i) { | 2798 for (i = 0; i < mi_height; ++i) { |
| 2773 ref_mbmi = &xd->mi[i * xd->mi_stride - 1]->mbmi; | 2799 ref_mbmi = &xd->mi[i * xd->mi_stride - 1].src_mi->mbmi; |
| 2774 const_motion &= (ref_mv.as_int == ref_mbmi->mv[0].as_int) && | 2800 const_motion &= (ref_mv.as_int == ref_mbmi->mv[0].as_int) && |
| 2775 (ref_frame == ref_mbmi->ref_frame[0]); | 2801 (ref_frame == ref_mbmi->ref_frame[0]); |
| 2776 skip_ref_frame &= (rf == ref_mbmi->ref_frame[0]); | 2802 skip_ref_frame &= (rf == ref_mbmi->ref_frame[0]); |
| 2777 } | 2803 } |
| 2778 } | 2804 } |
| 2779 | 2805 |
| 2780 if (skip_ref_frame && this_mode != NEARESTMV && this_mode != NEWMV) | 2806 if (skip_ref_frame && this_mode != NEARESTMV && this_mode != NEWMV) |
| 2781 if (rf > INTRA_FRAME) | 2807 if (rf > INTRA_FRAME) |
| 2782 if (ref_frame != rf) | 2808 if (ref_frame != rf) |
| 2783 continue; | 2809 continue; |
| 2784 | 2810 |
| 2785 if (const_motion) | 2811 if (const_motion) |
| 2786 if (this_mode == NEARMV || this_mode == ZEROMV) | 2812 if (this_mode == NEARMV || this_mode == ZEROMV) |
| 2787 continue; | 2813 continue; |
| 2788 } | 2814 } |
| 2789 | 2815 |
| 2790 comp_pred = second_ref_frame > INTRA_FRAME; | 2816 comp_pred = second_ref_frame > INTRA_FRAME; |
| 2791 if (comp_pred) { | 2817 if (comp_pred) { |
| 2792 if (!cm->allow_comp_inter_inter) | 2818 if (!cm->allow_comp_inter_inter) |
| 2793 continue; | 2819 continue; |
| 2794 | 2820 |
| 2821 // Skip compound inter modes if ARF is not available. |
| 2822 if (!(cpi->ref_frame_flags & flag_list[second_ref_frame])) |
| 2823 continue; |
| 2824 |
| 2825 // Do not allow compound prediction if the segment level reference frame |
| 2826 // feature is in use as in this case there can only be one reference. |
| 2827 if (vp9_segfeature_active(seg, segment_id, SEG_LVL_REF_FRAME)) |
| 2828 continue; |
| 2829 |
| 2795 if ((mode_search_skip_flags & FLAG_SKIP_COMP_BESTINTRA) && | 2830 if ((mode_search_skip_flags & FLAG_SKIP_COMP_BESTINTRA) && |
| 2796 best_mode_index >=0 && | 2831 best_mode_index >= 0 && best_mbmode.ref_frame[0] == INTRA_FRAME) |
| 2797 vp9_mode_order[best_mode_index].ref_frame[0] == INTRA_FRAME) | |
| 2798 continue; | 2832 continue; |
| 2799 if ((mode_search_skip_flags & FLAG_SKIP_COMP_REFMISMATCH) && | 2833 |
| 2800 ref_frame != best_inter_ref_frame && | |
| 2801 second_ref_frame != best_inter_ref_frame) | |
| 2802 continue; | |
| 2803 mode_excluded = cm->reference_mode == SINGLE_REFERENCE; | 2834 mode_excluded = cm->reference_mode == SINGLE_REFERENCE; |
| 2804 } else { | 2835 } else { |
| 2805 if (ref_frame != INTRA_FRAME) | 2836 if (ref_frame != INTRA_FRAME) |
| 2806 mode_excluded = cm->reference_mode == COMPOUND_REFERENCE; | 2837 mode_excluded = cm->reference_mode == COMPOUND_REFERENCE; |
| 2807 } | 2838 } |
| 2808 | 2839 |
| 2809 if (ref_frame == INTRA_FRAME) { | 2840 if (ref_frame == INTRA_FRAME) { |
| 2810 if (cpi->sf.adaptive_mode_search) | 2841 if (cpi->sf.adaptive_mode_search) |
| 2811 if ((x->source_variance << num_pels_log2_lookup[bsize]) > best_intra_rd) | 2842 if ((x->source_variance << num_pels_log2_lookup[bsize]) > best_pred_sse) |
| 2812 continue; | 2843 continue; |
| 2813 | 2844 |
| 2814 if (!(intra_y_mode_mask & (1 << this_mode))) | |
| 2815 continue; | |
| 2816 if (this_mode != DC_PRED) { | 2845 if (this_mode != DC_PRED) { |
| 2817 // Disable intra modes other than DC_PRED for blocks with low variance | 2846 // Disable intra modes other than DC_PRED for blocks with low variance |
| 2818 // Threshold for intra skipping based on source variance | 2847 // Threshold for intra skipping based on source variance |
| 2819 // TODO(debargha): Specialize the threshold for super block sizes | 2848 // TODO(debargha): Specialize the threshold for super block sizes |
| 2820 const unsigned int skip_intra_var_thresh = 64; | 2849 const unsigned int skip_intra_var_thresh = 64; |
| 2821 if ((mode_search_skip_flags & FLAG_SKIP_INTRA_LOWVAR) && | 2850 if ((mode_search_skip_flags & FLAG_SKIP_INTRA_LOWVAR) && |
| 2822 x->source_variance < skip_intra_var_thresh) | 2851 x->source_variance < skip_intra_var_thresh) |
| 2823 continue; | 2852 continue; |
| 2824 // Only search the oblique modes if the best so far is | 2853 // Only search the oblique modes if the best so far is |
| 2825 // one of the neighboring directional modes | 2854 // one of the neighboring directional modes |
| 2826 if ((mode_search_skip_flags & FLAG_SKIP_INTRA_BESTINTER) && | 2855 if ((mode_search_skip_flags & FLAG_SKIP_INTRA_BESTINTER) && |
| 2827 (this_mode >= D45_PRED && this_mode <= TM_PRED)) { | 2856 (this_mode >= D45_PRED && this_mode <= TM_PRED)) { |
| 2828 if (best_mode_index >= 0 && | 2857 if (best_mode_index >= 0 && |
| 2829 vp9_mode_order[best_mode_index].ref_frame[0] > INTRA_FRAME) | 2858 best_mbmode.ref_frame[0] > INTRA_FRAME) |
| 2830 continue; | 2859 continue; |
| 2831 } | 2860 } |
| 2832 if (mode_search_skip_flags & FLAG_SKIP_INTRA_DIRMISMATCH) { | 2861 if (mode_search_skip_flags & FLAG_SKIP_INTRA_DIRMISMATCH) { |
| 2833 if (conditional_skipintra(this_mode, best_intra_mode)) | 2862 if (conditional_skipintra(this_mode, best_intra_mode)) |
| 2834 continue; | 2863 continue; |
| 2835 } | 2864 } |
| 2836 } | 2865 } |
| 2837 } else { | 2866 } else { |
| 2838 const MV_REFERENCE_FRAME ref_frames[2] = {ref_frame, second_ref_frame}; | 2867 const MV_REFERENCE_FRAME ref_frames[2] = {ref_frame, second_ref_frame}; |
| 2839 if (!check_best_zero_mv(cpi, mbmi->mode_context, frame_mv, | 2868 if (!check_best_zero_mv(cpi, mbmi->mode_context, frame_mv, |
| 2840 inter_mode_mask, this_mode, ref_frames)) | 2869 this_mode, ref_frames)) |
| 2841 continue; | 2870 continue; |
| 2842 } | 2871 } |
| 2843 | 2872 |
| 2844 mbmi->mode = this_mode; | 2873 mbmi->mode = this_mode; |
| 2845 mbmi->uv_mode = DC_PRED; | 2874 mbmi->uv_mode = DC_PRED; |
| 2846 mbmi->ref_frame[0] = ref_frame; | 2875 mbmi->ref_frame[0] = ref_frame; |
| 2847 mbmi->ref_frame[1] = second_ref_frame; | 2876 mbmi->ref_frame[1] = second_ref_frame; |
| 2848 // Evaluate all sub-pel filters irrespective of whether we can use | 2877 // Evaluate all sub-pel filters irrespective of whether we can use |
| 2849 // them for this frame. | 2878 // them for this frame. |
| 2850 mbmi->interp_filter = cm->interp_filter == SWITCHABLE ? EIGHTTAP | 2879 mbmi->interp_filter = cm->interp_filter == SWITCHABLE ? EIGHTTAP |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2911 // Estimate the reference frame signaling cost and add it | 2940 // Estimate the reference frame signaling cost and add it |
| 2912 // to the rolling cost variable. | 2941 // to the rolling cost variable. |
| 2913 if (comp_pred) { | 2942 if (comp_pred) { |
| 2914 rate2 += ref_costs_comp[ref_frame]; | 2943 rate2 += ref_costs_comp[ref_frame]; |
| 2915 } else { | 2944 } else { |
| 2916 rate2 += ref_costs_single[ref_frame]; | 2945 rate2 += ref_costs_single[ref_frame]; |
| 2917 } | 2946 } |
| 2918 | 2947 |
| 2919 if (!disable_skip) { | 2948 if (!disable_skip) { |
| 2920 if (skippable) { | 2949 if (skippable) { |
| 2921 vp9_prob skip_prob = vp9_get_skip_prob(cm, xd); | |
| 2922 | |
| 2923 // Back out the coefficient coding costs | 2950 // Back out the coefficient coding costs |
| 2924 rate2 -= (rate_y + rate_uv); | 2951 rate2 -= (rate_y + rate_uv); |
| 2925 // for best yrd calculation | |
| 2926 rate_uv = 0; | |
| 2927 | 2952 |
| 2928 // Cost the skip mb case | 2953 // Cost the skip mb case |
| 2929 if (skip_prob) { | 2954 rate2 += vp9_cost_bit(vp9_get_skip_prob(cm, xd), 1); |
| 2930 int prob_skip_cost = vp9_cost_bit(skip_prob, 1); | |
| 2931 rate2 += prob_skip_cost; | |
| 2932 } | |
| 2933 } else if (ref_frame != INTRA_FRAME && !xd->lossless) { | 2955 } else if (ref_frame != INTRA_FRAME && !xd->lossless) { |
| 2934 if (RDCOST(x->rdmult, x->rddiv, rate_y + rate_uv, distortion2) < | 2956 if (RDCOST(x->rdmult, x->rddiv, rate_y + rate_uv, distortion2) < |
| 2935 RDCOST(x->rdmult, x->rddiv, 0, total_sse)) { | 2957 RDCOST(x->rdmult, x->rddiv, 0, total_sse)) { |
| 2936 // Add in the cost of the no skip flag. | 2958 // Add in the cost of the no skip flag. |
| 2937 rate2 += vp9_cost_bit(vp9_get_skip_prob(cm, xd), 0); | 2959 rate2 += vp9_cost_bit(vp9_get_skip_prob(cm, xd), 0); |
| 2938 } else { | 2960 } else { |
| 2939 // FIXME(rbultje) make this work for splitmv also | 2961 // FIXME(rbultje) make this work for splitmv also |
| 2940 rate2 += vp9_cost_bit(vp9_get_skip_prob(cm, xd), 1); | 2962 rate2 += vp9_cost_bit(vp9_get_skip_prob(cm, xd), 1); |
| 2941 distortion2 = total_sse; | 2963 distortion2 = total_sse; |
| 2942 assert(total_sse >= 0); | 2964 assert(total_sse >= 0); |
| 2943 rate2 -= (rate_y + rate_uv); | 2965 rate2 -= (rate_y + rate_uv); |
| 2944 rate_y = 0; | |
| 2945 rate_uv = 0; | |
| 2946 this_skip2 = 1; | 2966 this_skip2 = 1; |
| 2947 } | 2967 } |
| 2948 } else { | 2968 } else { |
| 2949 // Add in the cost of the no skip flag. | 2969 // Add in the cost of the no skip flag. |
| 2950 rate2 += vp9_cost_bit(vp9_get_skip_prob(cm, xd), 0); | 2970 rate2 += vp9_cost_bit(vp9_get_skip_prob(cm, xd), 0); |
| 2951 } | 2971 } |
| 2952 | 2972 |
| 2953 // Calculate the final RD estimate for this mode. | 2973 // Calculate the final RD estimate for this mode. |
| 2954 this_rd = RDCOST(x->rdmult, x->rddiv, rate2, distortion2); | 2974 this_rd = RDCOST(x->rdmult, x->rddiv, rate2, distortion2); |
| 2955 } | 2975 } |
| 2956 | 2976 |
| 2957 if (ref_frame == INTRA_FRAME) { | 2977 if (ref_frame == INTRA_FRAME) { |
| 2958 // Keep record of best intra rd | 2978 // Keep record of best intra rd |
| 2959 if (this_rd < best_intra_rd) { | 2979 if (this_rd < best_intra_rd) { |
| 2960 best_intra_rd = this_rd; | 2980 best_intra_rd = this_rd; |
| 2961 best_intra_mode = mbmi->mode; | 2981 best_intra_mode = mbmi->mode; |
| 2962 } | 2982 } |
| 2963 } else { | |
| 2964 // Keep record of best inter rd with single reference | |
| 2965 if (!comp_pred && !mode_excluded && this_rd < best_inter_rd) { | |
| 2966 best_inter_rd = this_rd; | |
| 2967 best_inter_ref_frame = ref_frame; | |
| 2968 } | |
| 2969 } | 2983 } |
| 2970 | 2984 |
| 2971 if (!disable_skip && ref_frame == INTRA_FRAME) { | 2985 if (!disable_skip && ref_frame == INTRA_FRAME) { |
| 2972 for (i = 0; i < REFERENCE_MODES; ++i) | 2986 for (i = 0; i < REFERENCE_MODES; ++i) |
| 2973 best_pred_rd[i] = MIN(best_pred_rd[i], this_rd); | 2987 best_pred_rd[i] = MIN(best_pred_rd[i], this_rd); |
| 2974 for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; i++) | 2988 for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; i++) |
| 2975 best_filter_rd[i] = MIN(best_filter_rd[i], this_rd); | 2989 best_filter_rd[i] = MIN(best_filter_rd[i], this_rd); |
| 2976 } | 2990 } |
| 2977 | 2991 |
| 2978 // Did this mode help.. i.e. is it the new best mode | 2992 // Did this mode help.. i.e. is it the new best mode |
| 2979 if (this_rd < best_rd || x->skip) { | 2993 if (this_rd < best_rd || x->skip) { |
| 2980 int max_plane = MAX_MB_PLANE; | 2994 int max_plane = MAX_MB_PLANE; |
| 2981 if (!mode_excluded) { | 2995 if (!mode_excluded) { |
| 2982 // Note index of best mode so far | 2996 // Note index of best mode so far |
| 2983 best_mode_index = mode_index; | 2997 best_mode_index = mode_index; |
| 2984 | 2998 |
| 2985 if (ref_frame == INTRA_FRAME) { | 2999 if (ref_frame == INTRA_FRAME) { |
| 2986 /* required for left and above block mv */ | 3000 /* required for left and above block mv */ |
| 2987 mbmi->mv[0].as_int = 0; | 3001 mbmi->mv[0].as_int = 0; |
| 2988 max_plane = 1; | 3002 max_plane = 1; |
| 2989 } else { | 3003 } else { |
| 2990 best_intra_rd = x->pred_sse[ref_frame]; | 3004 best_pred_sse = x->pred_sse[ref_frame]; |
| 2991 } | 3005 } |
| 2992 | 3006 |
| 2993 *returnrate = rate2; | 3007 *returnrate = rate2; |
| 2994 *returndistortion = distortion2; | 3008 *returndistortion = distortion2; |
| 2995 best_rd = this_rd; | 3009 best_rd = this_rd; |
| 2996 best_mbmode = *mbmi; | 3010 best_mbmode = *mbmi; |
| 2997 best_skip2 = this_skip2; | 3011 best_skip2 = this_skip2; |
| 2998 best_mode_skippable = skippable; | 3012 best_mode_skippable = skippable; |
| 2999 | 3013 |
| 3000 if (!x->select_tx_size) | 3014 if (!x->select_tx_size) |
| (...skipping 29 matching lines...) Expand all Loading... |
| 3030 hybrid_rate = rate2; | 3044 hybrid_rate = rate2; |
| 3031 } else { | 3045 } else { |
| 3032 single_rate = rate2; | 3046 single_rate = rate2; |
| 3033 hybrid_rate = rate2 + compmode_cost; | 3047 hybrid_rate = rate2 + compmode_cost; |
| 3034 } | 3048 } |
| 3035 | 3049 |
| 3036 single_rd = RDCOST(x->rdmult, x->rddiv, single_rate, distortion2); | 3050 single_rd = RDCOST(x->rdmult, x->rddiv, single_rate, distortion2); |
| 3037 hybrid_rd = RDCOST(x->rdmult, x->rddiv, hybrid_rate, distortion2); | 3051 hybrid_rd = RDCOST(x->rdmult, x->rddiv, hybrid_rate, distortion2); |
| 3038 | 3052 |
| 3039 if (!comp_pred) { | 3053 if (!comp_pred) { |
| 3040 if (single_rd < best_pred_rd[SINGLE_REFERENCE]) { | 3054 if (single_rd < best_pred_rd[SINGLE_REFERENCE]) |
| 3041 best_pred_rd[SINGLE_REFERENCE] = single_rd; | 3055 best_pred_rd[SINGLE_REFERENCE] = single_rd; |
| 3042 } | |
| 3043 } else { | 3056 } else { |
| 3044 if (single_rd < best_pred_rd[COMPOUND_REFERENCE]) { | 3057 if (single_rd < best_pred_rd[COMPOUND_REFERENCE]) |
| 3045 best_pred_rd[COMPOUND_REFERENCE] = single_rd; | 3058 best_pred_rd[COMPOUND_REFERENCE] = single_rd; |
| 3046 } | |
| 3047 } | 3059 } |
| 3048 if (hybrid_rd < best_pred_rd[REFERENCE_MODE_SELECT]) | 3060 if (hybrid_rd < best_pred_rd[REFERENCE_MODE_SELECT]) |
| 3049 best_pred_rd[REFERENCE_MODE_SELECT] = hybrid_rd; | 3061 best_pred_rd[REFERENCE_MODE_SELECT] = hybrid_rd; |
| 3050 | 3062 |
| 3051 /* keep record of best filter type */ | 3063 /* keep record of best filter type */ |
| 3052 if (!mode_excluded && cm->interp_filter != BILINEAR) { | 3064 if (!mode_excluded && cm->interp_filter != BILINEAR) { |
| 3053 int64_t ref = rd_opt->filter_cache[cm->interp_filter == SWITCHABLE ? | 3065 int64_t ref = rd_opt->filter_cache[cm->interp_filter == SWITCHABLE ? |
| 3054 SWITCHABLE_FILTERS : cm->interp_filter]; | 3066 SWITCHABLE_FILTERS : cm->interp_filter]; |
| 3055 | 3067 |
| 3056 for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; i++) { | 3068 for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; i++) { |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3117 ((comp_pred_mode && best_mbmode.mv[1].as_int == 0) || !comp_pred_mode)) | 3129 ((comp_pred_mode && best_mbmode.mv[1].as_int == 0) || !comp_pred_mode)) |
| 3118 best_mbmode.mode = ZEROMV; | 3130 best_mbmode.mode = ZEROMV; |
| 3119 } | 3131 } |
| 3120 | 3132 |
| 3121 if (best_mode_index < 0 || best_rd >= best_rd_so_far) | 3133 if (best_mode_index < 0 || best_rd >= best_rd_so_far) |
| 3122 return INT64_MAX; | 3134 return INT64_MAX; |
| 3123 | 3135 |
| 3124 // If we used an estimate for the uv intra rd in the loop above... | 3136 // If we used an estimate for the uv intra rd in the loop above... |
| 3125 if (cpi->sf.use_uv_intra_rd_estimate) { | 3137 if (cpi->sf.use_uv_intra_rd_estimate) { |
| 3126 // Do Intra UV best rd mode selection if best mode choice above was intra. | 3138 // Do Intra UV best rd mode selection if best mode choice above was intra. |
| 3127 if (vp9_mode_order[best_mode_index].ref_frame[0] == INTRA_FRAME) { | 3139 if (best_mbmode.ref_frame[0] == INTRA_FRAME) { |
| 3128 TX_SIZE uv_tx_size; | 3140 TX_SIZE uv_tx_size; |
| 3129 *mbmi = best_mbmode; | 3141 *mbmi = best_mbmode; |
| 3130 uv_tx_size = get_uv_tx_size(mbmi, &xd->plane[1]); | 3142 uv_tx_size = get_uv_tx_size(mbmi, &xd->plane[1]); |
| 3131 rd_pick_intra_sbuv_mode(cpi, x, ctx, &rate_uv_intra[uv_tx_size], | 3143 rd_pick_intra_sbuv_mode(cpi, x, ctx, &rate_uv_intra[uv_tx_size], |
| 3132 &rate_uv_tokenonly[uv_tx_size], | 3144 &rate_uv_tokenonly[uv_tx_size], |
| 3133 &dist_uv[uv_tx_size], | 3145 &dist_uv[uv_tx_size], |
| 3134 &skip_uv[uv_tx_size], | 3146 &skip_uv[uv_tx_size], |
| 3135 bsize < BLOCK_8X8 ? BLOCK_8X8 : bsize, | 3147 bsize < BLOCK_8X8 ? BLOCK_8X8 : bsize, |
| 3136 uv_tx_size); | 3148 uv_tx_size); |
| 3137 } | 3149 } |
| 3138 } | 3150 } |
| 3139 | 3151 |
| 3140 assert((cm->interp_filter == SWITCHABLE) || | 3152 assert((cm->interp_filter == SWITCHABLE) || |
| 3141 (cm->interp_filter == best_mbmode.interp_filter) || | 3153 (cm->interp_filter == best_mbmode.interp_filter) || |
| 3142 !is_inter_block(&best_mbmode)); | 3154 !is_inter_block(&best_mbmode)); |
| 3143 | 3155 |
| 3144 update_rd_thresh_fact(cpi, bsize, best_mode_index); | 3156 if (!cpi->rc.is_src_frame_alt_ref) |
| 3157 update_rd_thresh_fact(cpi, bsize, best_mode_index); |
| 3145 | 3158 |
| 3146 // macroblock modes | 3159 // macroblock modes |
| 3147 *mbmi = best_mbmode; | 3160 *mbmi = best_mbmode; |
| 3148 x->skip |= best_skip2; | 3161 x->skip |= best_skip2; |
| 3149 | 3162 |
| 3150 for (i = 0; i < REFERENCE_MODES; ++i) { | 3163 for (i = 0; i < REFERENCE_MODES; ++i) { |
| 3151 if (best_pred_rd[i] == INT64_MAX) | 3164 if (best_pred_rd[i] == INT64_MAX) |
| 3152 best_pred_diff[i] = INT_MIN; | 3165 best_pred_diff[i] = INT_MIN; |
| 3153 else | 3166 else |
| 3154 best_pred_diff[i] = best_rd - best_pred_rd[i]; | 3167 best_pred_diff[i] = best_rd - best_pred_rd[i]; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 3167 if (best_tx_rd[i] == INT64_MAX) | 3180 if (best_tx_rd[i] == INT64_MAX) |
| 3168 best_tx_diff[i] = 0; | 3181 best_tx_diff[i] = 0; |
| 3169 else | 3182 else |
| 3170 best_tx_diff[i] = best_rd - best_tx_rd[i]; | 3183 best_tx_diff[i] = best_rd - best_tx_rd[i]; |
| 3171 } | 3184 } |
| 3172 } else { | 3185 } else { |
| 3173 vp9_zero(best_filter_diff); | 3186 vp9_zero(best_filter_diff); |
| 3174 vp9_zero(best_tx_diff); | 3187 vp9_zero(best_tx_diff); |
| 3175 } | 3188 } |
| 3176 | 3189 |
| 3177 set_ref_ptrs(cm, xd, mbmi->ref_frame[0], mbmi->ref_frame[1]); | 3190 // TODO(yunqingwang): Moving this line in front of the above best_filter_diff |
| 3191 // updating code causes PSNR loss. Need to figure out the confliction. |
| 3192 x->skip |= best_mode_skippable; |
| 3193 |
| 3178 store_coding_context(x, ctx, best_mode_index, best_pred_diff, | 3194 store_coding_context(x, ctx, best_mode_index, best_pred_diff, |
| 3179 best_tx_diff, best_filter_diff, best_mode_skippable); | 3195 best_tx_diff, best_filter_diff, best_mode_skippable); |
| 3180 | 3196 |
| 3181 return best_rd; | 3197 return best_rd; |
| 3182 } | 3198 } |
| 3183 | 3199 |
| 3184 int64_t vp9_rd_pick_inter_mode_sb_seg_skip(VP9_COMP *cpi, MACROBLOCK *x, | 3200 int64_t vp9_rd_pick_inter_mode_sb_seg_skip(VP9_COMP *cpi, MACROBLOCK *x, |
| 3185 int *returnrate, | 3201 int *returnrate, |
| 3186 int64_t *returndistortion, | 3202 int64_t *returndistortion, |
| 3187 BLOCK_SIZE bsize, | 3203 BLOCK_SIZE bsize, |
| 3188 PICK_MODE_CONTEXT *ctx, | 3204 PICK_MODE_CONTEXT *ctx, |
| 3189 int64_t best_rd_so_far) { | 3205 int64_t best_rd_so_far) { |
| 3190 VP9_COMMON *const cm = &cpi->common; | 3206 VP9_COMMON *const cm = &cpi->common; |
| 3191 RD_OPT *const rd_opt = &cpi->rd; | 3207 RD_OPT *const rd_opt = &cpi->rd; |
| 3192 MACROBLOCKD *const xd = &x->e_mbd; | 3208 MACROBLOCKD *const xd = &x->e_mbd; |
| 3193 MB_MODE_INFO *const mbmi = &xd->mi[0]->mbmi; | 3209 MB_MODE_INFO *const mbmi = &xd->mi[0].src_mi->mbmi; |
| 3194 unsigned char segment_id = mbmi->segment_id; | 3210 unsigned char segment_id = mbmi->segment_id; |
| 3195 const int comp_pred = 0; | 3211 const int comp_pred = 0; |
| 3196 int i; | 3212 int i; |
| 3197 int64_t best_tx_diff[TX_MODES]; | 3213 int64_t best_tx_diff[TX_MODES]; |
| 3198 int64_t best_pred_diff[REFERENCE_MODES]; | 3214 int64_t best_pred_diff[REFERENCE_MODES]; |
| 3199 int64_t best_filter_diff[SWITCHABLE_FILTER_CONTEXTS]; | 3215 int64_t best_filter_diff[SWITCHABLE_FILTER_CONTEXTS]; |
| 3200 unsigned int ref_costs_single[MAX_REF_FRAMES], ref_costs_comp[MAX_REF_FRAMES]; | 3216 unsigned int ref_costs_single[MAX_REF_FRAMES], ref_costs_comp[MAX_REF_FRAMES]; |
| 3201 vp9_prob comp_mode_p; | 3217 vp9_prob comp_mode_p; |
| 3202 INTERP_FILTER best_filter = SWITCHABLE; | 3218 INTERP_FILTER best_filter = SWITCHABLE; |
| 3203 int64_t this_rd = INT64_MAX; | 3219 int64_t this_rd = INT64_MAX; |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3290 const TileInfo *const tile, | 3306 const TileInfo *const tile, |
| 3291 int mi_row, int mi_col, | 3307 int mi_row, int mi_col, |
| 3292 int *returnrate, | 3308 int *returnrate, |
| 3293 int64_t *returndistortion, | 3309 int64_t *returndistortion, |
| 3294 BLOCK_SIZE bsize, | 3310 BLOCK_SIZE bsize, |
| 3295 PICK_MODE_CONTEXT *ctx, | 3311 PICK_MODE_CONTEXT *ctx, |
| 3296 int64_t best_rd_so_far) { | 3312 int64_t best_rd_so_far) { |
| 3297 VP9_COMMON *const cm = &cpi->common; | 3313 VP9_COMMON *const cm = &cpi->common; |
| 3298 RD_OPT *const rd_opt = &cpi->rd; | 3314 RD_OPT *const rd_opt = &cpi->rd; |
| 3299 MACROBLOCKD *const xd = &x->e_mbd; | 3315 MACROBLOCKD *const xd = &x->e_mbd; |
| 3300 MB_MODE_INFO *const mbmi = &xd->mi[0]->mbmi; | 3316 MB_MODE_INFO *const mbmi = &xd->mi[0].src_mi->mbmi; |
| 3301 const struct segmentation *const seg = &cm->seg; | 3317 const struct segmentation *const seg = &cm->seg; |
| 3302 MV_REFERENCE_FRAME ref_frame, second_ref_frame; | 3318 MV_REFERENCE_FRAME ref_frame, second_ref_frame; |
| 3303 unsigned char segment_id = mbmi->segment_id; | 3319 unsigned char segment_id = mbmi->segment_id; |
| 3304 int comp_pred, i; | 3320 int comp_pred, i; |
| 3305 int_mv frame_mv[MB_MODE_COUNT][MAX_REF_FRAMES]; | 3321 int_mv frame_mv[MB_MODE_COUNT][MAX_REF_FRAMES]; |
| 3306 struct buf_2d yv12_mb[4][MAX_MB_PLANE]; | 3322 struct buf_2d yv12_mb[4][MAX_MB_PLANE]; |
| 3307 static const int flag_list[4] = { 0, VP9_LAST_FLAG, VP9_GOLD_FLAG, | 3323 static const int flag_list[4] = { 0, VP9_LAST_FLAG, VP9_GOLD_FLAG, |
| 3308 VP9_ALT_FLAG }; | 3324 VP9_ALT_FLAG }; |
| 3309 int64_t best_rd = best_rd_so_far; | 3325 int64_t best_rd = best_rd_so_far; |
| 3310 int64_t best_yrd = best_rd_so_far; // FIXME(rbultje) more precise | 3326 int64_t best_yrd = best_rd_so_far; // FIXME(rbultje) more precise |
| 3311 static const int64_t best_tx_diff[TX_MODES] = { 0 }; | 3327 static const int64_t best_tx_diff[TX_MODES] = { 0 }; |
| 3312 int64_t best_pred_diff[REFERENCE_MODES]; | 3328 int64_t best_pred_diff[REFERENCE_MODES]; |
| 3313 int64_t best_pred_rd[REFERENCE_MODES]; | 3329 int64_t best_pred_rd[REFERENCE_MODES]; |
| 3314 int64_t best_filter_rd[SWITCHABLE_FILTER_CONTEXTS]; | 3330 int64_t best_filter_rd[SWITCHABLE_FILTER_CONTEXTS]; |
| 3315 int64_t best_filter_diff[SWITCHABLE_FILTER_CONTEXTS]; | 3331 int64_t best_filter_diff[SWITCHABLE_FILTER_CONTEXTS]; |
| 3316 MB_MODE_INFO best_mbmode; | 3332 MB_MODE_INFO best_mbmode; |
| 3317 int ref_index, best_ref_index = 0; | 3333 int ref_index, best_ref_index = 0; |
| 3318 unsigned int ref_costs_single[MAX_REF_FRAMES], ref_costs_comp[MAX_REF_FRAMES]; | 3334 unsigned int ref_costs_single[MAX_REF_FRAMES], ref_costs_comp[MAX_REF_FRAMES]; |
| 3319 vp9_prob comp_mode_p; | 3335 vp9_prob comp_mode_p; |
| 3320 int64_t best_inter_rd = INT64_MAX; | |
| 3321 MV_REFERENCE_FRAME best_inter_ref_frame = LAST_FRAME; | |
| 3322 INTERP_FILTER tmp_best_filter = SWITCHABLE; | 3336 INTERP_FILTER tmp_best_filter = SWITCHABLE; |
| 3323 int rate_uv_intra, rate_uv_tokenonly; | 3337 int rate_uv_intra, rate_uv_tokenonly; |
| 3324 int64_t dist_uv; | 3338 int64_t dist_uv; |
| 3325 int skip_uv; | 3339 int skip_uv; |
| 3326 PREDICTION_MODE mode_uv = DC_PRED; | 3340 PREDICTION_MODE mode_uv = DC_PRED; |
| 3327 int intra_cost_penalty = 20 * vp9_dc_quant(cm->base_qindex, cm->y_dc_delta_q); | 3341 const int intra_cost_penalty = |
| 3342 20 * vp9_dc_quant(cm->base_qindex, cm->y_dc_delta_q, cm->bit_depth); |
| 3328 int_mv seg_mvs[4][MAX_REF_FRAMES]; | 3343 int_mv seg_mvs[4][MAX_REF_FRAMES]; |
| 3329 b_mode_info best_bmodes[4]; | 3344 b_mode_info best_bmodes[4]; |
| 3330 int best_skip2 = 0; | 3345 int best_skip2 = 0; |
| 3331 int mode_skip_mask = 0; | 3346 int ref_frame_skip_mask[2] = { 0 }; |
| 3332 | 3347 |
| 3333 x->skip_encode = cpi->sf.skip_encode_frame && x->q_index < QIDX_SKIP_THRESH; | 3348 x->skip_encode = cpi->sf.skip_encode_frame && x->q_index < QIDX_SKIP_THRESH; |
| 3334 vpx_memset(x->zcoeff_blk[TX_4X4], 0, 4); | 3349 vpx_memset(x->zcoeff_blk[TX_4X4], 0, 4); |
| 3335 vp9_zero(best_mbmode); | 3350 vp9_zero(best_mbmode); |
| 3336 | 3351 |
| 3337 for (i = 0; i < 4; i++) { | 3352 for (i = 0; i < 4; i++) { |
| 3338 int j; | 3353 int j; |
| 3339 for (j = 0; j < MAX_REF_FRAMES; j++) | 3354 for (j = 0; j < MAX_REF_FRAMES; j++) |
| 3340 seg_mvs[i][j].as_int = INVALID_MV; | 3355 seg_mvs[i][j].as_int = INVALID_MV; |
| 3341 } | 3356 } |
| 3342 | 3357 |
| 3343 estimate_ref_frame_costs(cm, xd, segment_id, ref_costs_single, ref_costs_comp, | 3358 estimate_ref_frame_costs(cm, xd, segment_id, ref_costs_single, ref_costs_comp, |
| 3344 &comp_mode_p); | 3359 &comp_mode_p); |
| 3345 | 3360 |
| 3346 for (i = 0; i < REFERENCE_MODES; ++i) | 3361 for (i = 0; i < REFERENCE_MODES; ++i) |
| 3347 best_pred_rd[i] = INT64_MAX; | 3362 best_pred_rd[i] = INT64_MAX; |
| 3348 for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; i++) | 3363 for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; i++) |
| 3349 best_filter_rd[i] = INT64_MAX; | 3364 best_filter_rd[i] = INT64_MAX; |
| 3350 rate_uv_intra = INT_MAX; | 3365 rate_uv_intra = INT_MAX; |
| 3351 | 3366 |
| 3352 *returnrate = INT_MAX; | 3367 *returnrate = INT_MAX; |
| 3353 | 3368 |
| 3354 for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ref_frame++) { | 3369 for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ref_frame++) { |
| 3355 if (cpi->ref_frame_flags & flag_list[ref_frame]) { | 3370 if (cpi->ref_frame_flags & flag_list[ref_frame]) { |
| 3356 setup_buffer_inter(cpi, x, tile, | 3371 setup_buffer_inter(cpi, x, tile, |
| 3357 ref_frame, bsize, mi_row, mi_col, | 3372 ref_frame, bsize, mi_row, mi_col, |
| 3358 frame_mv[NEARESTMV], frame_mv[NEARMV], | 3373 frame_mv[NEARESTMV], frame_mv[NEARMV], |
| 3359 yv12_mb); | 3374 yv12_mb); |
| 3375 } else { |
| 3376 ref_frame_skip_mask[0] |= (1 << ref_frame); |
| 3377 ref_frame_skip_mask[1] |= SECOND_REF_FRAME_MASK; |
| 3360 } | 3378 } |
| 3361 frame_mv[NEWMV][ref_frame].as_int = INVALID_MV; | 3379 frame_mv[NEWMV][ref_frame].as_int = INVALID_MV; |
| 3362 frame_mv[ZEROMV][ref_frame].as_int = 0; | 3380 frame_mv[ZEROMV][ref_frame].as_int = 0; |
| 3363 } | 3381 } |
| 3364 | 3382 |
| 3365 for (ref_index = 0; ref_index < MAX_REFS; ++ref_index) { | 3383 for (ref_index = 0; ref_index < MAX_REFS; ++ref_index) { |
| 3366 int mode_excluded = 0; | 3384 int mode_excluded = 0; |
| 3367 int64_t this_rd = INT64_MAX; | 3385 int64_t this_rd = INT64_MAX; |
| 3368 int disable_skip = 0; | 3386 int disable_skip = 0; |
| 3369 int compmode_cost = 0; | 3387 int compmode_cost = 0; |
| 3370 int rate2 = 0, rate_y = 0, rate_uv = 0; | 3388 int rate2 = 0, rate_y = 0, rate_uv = 0; |
| 3371 int64_t distortion2 = 0, distortion_y = 0, distortion_uv = 0; | 3389 int64_t distortion2 = 0, distortion_y = 0, distortion_uv = 0; |
| 3372 int skippable = 0; | 3390 int skippable = 0; |
| 3373 int i; | 3391 int i; |
| 3374 int this_skip2 = 0; | 3392 int this_skip2 = 0; |
| 3375 int64_t total_sse = INT_MAX; | 3393 int64_t total_sse = INT_MAX; |
| 3376 int early_term = 0; | 3394 int early_term = 0; |
| 3377 | 3395 |
| 3378 ref_frame = vp9_ref_order[ref_index].ref_frame[0]; | 3396 ref_frame = vp9_ref_order[ref_index].ref_frame[0]; |
| 3379 second_ref_frame = vp9_ref_order[ref_index].ref_frame[1]; | 3397 second_ref_frame = vp9_ref_order[ref_index].ref_frame[1]; |
| 3380 | 3398 |
| 3381 // Look at the reference frame of the best mode so far and set the | 3399 // Look at the reference frame of the best mode so far and set the |
| 3382 // skip mask to look at a subset of the remaining modes. | 3400 // skip mask to look at a subset of the remaining modes. |
| 3383 if (ref_index > 2 && cpi->sf.mode_skip_start < MAX_MODES) { | 3401 if (ref_index > 2 && cpi->sf.mode_skip_start < MAX_MODES) { |
| 3384 if (ref_index == 3) { | 3402 if (ref_index == 3) { |
| 3385 switch (vp9_ref_order[best_ref_index].ref_frame[0]) { | 3403 switch (best_mbmode.ref_frame[0]) { |
| 3386 case INTRA_FRAME: | 3404 case INTRA_FRAME: |
| 3387 mode_skip_mask = 0; | |
| 3388 break; | 3405 break; |
| 3389 case LAST_FRAME: | 3406 case LAST_FRAME: |
| 3390 mode_skip_mask = 0x0010; | 3407 ref_frame_skip_mask[0] |= (1 << GOLDEN_FRAME) | (1 << ALTREF_FRAME); |
| 3408 ref_frame_skip_mask[1] |= SECOND_REF_FRAME_MASK; |
| 3391 break; | 3409 break; |
| 3392 case GOLDEN_FRAME: | 3410 case GOLDEN_FRAME: |
| 3393 mode_skip_mask = 0x0008; | 3411 ref_frame_skip_mask[0] |= (1 << LAST_FRAME) | (1 << ALTREF_FRAME); |
| 3412 ref_frame_skip_mask[1] |= SECOND_REF_FRAME_MASK; |
| 3394 break; | 3413 break; |
| 3395 case ALTREF_FRAME: | 3414 case ALTREF_FRAME: |
| 3396 mode_skip_mask = 0x0000; | 3415 ref_frame_skip_mask[0] |= (1 << GOLDEN_FRAME) | (1 << LAST_FRAME); |
| 3397 break; | 3416 break; |
| 3398 case NONE: | 3417 case NONE: |
| 3399 case MAX_REF_FRAMES: | 3418 case MAX_REF_FRAMES: |
| 3400 assert(0 && "Invalid Reference frame"); | 3419 assert(0 && "Invalid Reference frame"); |
| 3401 break; | 3420 break; |
| 3402 } | 3421 } |
| 3403 } | 3422 } |
| 3404 if (mode_skip_mask & (1 << ref_index)) | |
| 3405 continue; | |
| 3406 } | 3423 } |
| 3407 | 3424 |
| 3425 if (ref_frame_skip_mask[0] & (1 << ref_frame) && |
| 3426 ref_frame_skip_mask[1] & (1 << MAX(0, second_ref_frame))) |
| 3427 continue; |
| 3428 |
| 3408 // Test best rd so far against threshold for trying this mode. | 3429 // Test best rd so far against threshold for trying this mode. |
| 3409 if (rd_less_than_thresh(best_rd, | 3430 if (rd_less_than_thresh(best_rd, |
| 3410 rd_opt->threshes[segment_id][bsize][ref_index], | 3431 rd_opt->threshes[segment_id][bsize][ref_index], |
| 3411 rd_opt->thresh_freq_fact[bsize][ref_index])) | 3432 rd_opt->thresh_freq_fact[bsize][ref_index])) |
| 3412 continue; | 3433 continue; |
| 3413 | 3434 |
| 3414 if (ref_frame > INTRA_FRAME && | |
| 3415 !(cpi->ref_frame_flags & flag_list[ref_frame])) { | |
| 3416 continue; | |
| 3417 } | |
| 3418 | |
| 3419 comp_pred = second_ref_frame > INTRA_FRAME; | 3435 comp_pred = second_ref_frame > INTRA_FRAME; |
| 3420 if (comp_pred) { | 3436 if (comp_pred) { |
| 3421 if (!cm->allow_comp_inter_inter) | 3437 if (!cm->allow_comp_inter_inter) |
| 3422 continue; | 3438 continue; |
| 3423 | |
| 3424 if (!(cpi->ref_frame_flags & flag_list[second_ref_frame])) | 3439 if (!(cpi->ref_frame_flags & flag_list[second_ref_frame])) |
| 3425 continue; | 3440 continue; |
| 3426 // Do not allow compound prediction if the segment level reference frame | 3441 // Do not allow compound prediction if the segment level reference frame |
| 3427 // feature is in use as in this case there can only be one reference. | 3442 // feature is in use as in this case there can only be one reference. |
| 3428 if (vp9_segfeature_active(seg, segment_id, SEG_LVL_REF_FRAME)) | 3443 if (vp9_segfeature_active(seg, segment_id, SEG_LVL_REF_FRAME)) |
| 3429 continue; | 3444 continue; |
| 3445 |
| 3430 if ((cpi->sf.mode_search_skip_flags & FLAG_SKIP_COMP_BESTINTRA) && | 3446 if ((cpi->sf.mode_search_skip_flags & FLAG_SKIP_COMP_BESTINTRA) && |
| 3431 vp9_ref_order[best_ref_index].ref_frame[0] == INTRA_FRAME) | 3447 best_mbmode.ref_frame[0] == INTRA_FRAME) |
| 3432 continue; | |
| 3433 if ((cpi->sf.mode_search_skip_flags & FLAG_SKIP_COMP_REFMISMATCH) && | |
| 3434 ref_frame != best_inter_ref_frame && | |
| 3435 second_ref_frame != best_inter_ref_frame) | |
| 3436 continue; | 3448 continue; |
| 3437 } | 3449 } |
| 3438 | 3450 |
| 3439 // TODO(jingning, jkoleszar): scaling reference frame not supported for | 3451 // TODO(jingning, jkoleszar): scaling reference frame not supported for |
| 3440 // sub8x8 blocks. | 3452 // sub8x8 blocks. |
| 3441 if (ref_frame > INTRA_FRAME && | 3453 if (ref_frame > INTRA_FRAME && |
| 3442 vp9_is_scaled(&cm->frame_refs[ref_frame - 1].sf)) | 3454 vp9_is_scaled(&cm->frame_refs[ref_frame - 1].sf)) |
| 3443 continue; | 3455 continue; |
| 3444 | 3456 |
| 3445 if (second_ref_frame > INTRA_FRAME && | 3457 if (second_ref_frame > INTRA_FRAME && |
| 3446 vp9_is_scaled(&cm->frame_refs[second_ref_frame - 1].sf)) | 3458 vp9_is_scaled(&cm->frame_refs[second_ref_frame - 1].sf)) |
| 3447 continue; | 3459 continue; |
| 3448 | 3460 |
| 3449 if (comp_pred) | 3461 if (comp_pred) |
| 3450 mode_excluded = cm->reference_mode == SINGLE_REFERENCE; | 3462 mode_excluded = cm->reference_mode == SINGLE_REFERENCE; |
| 3451 else if (ref_frame != INTRA_FRAME) | 3463 else if (ref_frame != INTRA_FRAME) |
| 3452 mode_excluded = cm->reference_mode == COMPOUND_REFERENCE; | 3464 mode_excluded = cm->reference_mode == COMPOUND_REFERENCE; |
| 3453 | 3465 |
| 3454 // If the segment reference frame feature is enabled.... | 3466 // If the segment reference frame feature is enabled.... |
| 3455 // then do nothing if the current ref frame is not allowed.. | 3467 // then do nothing if the current ref frame is not allowed.. |
| 3456 if (vp9_segfeature_active(seg, segment_id, SEG_LVL_REF_FRAME) && | 3468 if (vp9_segfeature_active(seg, segment_id, SEG_LVL_REF_FRAME) && |
| 3457 vp9_get_segdata(seg, segment_id, SEG_LVL_REF_FRAME) != | 3469 vp9_get_segdata(seg, segment_id, SEG_LVL_REF_FRAME) != (int)ref_frame) { |
| 3458 (int)ref_frame) { | |
| 3459 continue; | 3470 continue; |
| 3460 // Disable this drop out case if the ref frame | 3471 // Disable this drop out case if the ref frame |
| 3461 // segment level feature is enabled for this segment. This is to | 3472 // segment level feature is enabled for this segment. This is to |
| 3462 // prevent the possibility that we end up unable to pick any mode. | 3473 // prevent the possibility that we end up unable to pick any mode. |
| 3463 } else if (!vp9_segfeature_active(seg, segment_id, | 3474 } else if (!vp9_segfeature_active(seg, segment_id, SEG_LVL_REF_FRAME)) { |
| 3464 SEG_LVL_REF_FRAME)) { | |
| 3465 // Only consider ZEROMV/ALTREF_FRAME for alt ref frame, | 3475 // Only consider ZEROMV/ALTREF_FRAME for alt ref frame, |
| 3466 // unless ARNR filtering is enabled in which case we want | 3476 // unless ARNR filtering is enabled in which case we want |
| 3467 // an unfiltered alternative. We allow near/nearest as well | 3477 // an unfiltered alternative. We allow near/nearest as well |
| 3468 // because they may result in zero-zero MVs but be cheaper. | 3478 // because they may result in zero-zero MVs but be cheaper. |
| 3469 if (cpi->rc.is_src_frame_alt_ref && (cpi->oxcf.arnr_max_frames == 0)) | 3479 if (cpi->rc.is_src_frame_alt_ref && (cpi->oxcf.arnr_max_frames == 0)) |
| 3470 continue; | 3480 continue; |
| 3471 } | 3481 } |
| 3472 | 3482 |
| 3473 mbmi->tx_size = TX_4X4; | 3483 mbmi->tx_size = TX_4X4; |
| 3474 mbmi->uv_mode = DC_PRED; | 3484 mbmi->uv_mode = DC_PRED; |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3583 (mbmi->interp_filter == cm->interp_filter && | 3593 (mbmi->interp_filter == cm->interp_filter && |
| 3584 cm->interp_filter != SWITCHABLE)) { | 3594 cm->interp_filter != SWITCHABLE)) { |
| 3585 tmp_best_rdu = tmp_rd; | 3595 tmp_best_rdu = tmp_rd; |
| 3586 tmp_best_rate = rate; | 3596 tmp_best_rate = rate; |
| 3587 tmp_best_ratey = rate_y; | 3597 tmp_best_ratey = rate_y; |
| 3588 tmp_best_distortion = distortion; | 3598 tmp_best_distortion = distortion; |
| 3589 tmp_best_sse = total_sse; | 3599 tmp_best_sse = total_sse; |
| 3590 tmp_best_skippable = skippable; | 3600 tmp_best_skippable = skippable; |
| 3591 tmp_best_mbmode = *mbmi; | 3601 tmp_best_mbmode = *mbmi; |
| 3592 for (i = 0; i < 4; i++) { | 3602 for (i = 0; i < 4; i++) { |
| 3593 tmp_best_bmodes[i] = xd->mi[0]->bmi[i]; | 3603 tmp_best_bmodes[i] = xd->mi[0].src_mi->bmi[i]; |
| 3594 x->zcoeff_blk[TX_4X4][i] = !x->plane[0].eobs[i]; | 3604 x->zcoeff_blk[TX_4X4][i] = !x->plane[0].eobs[i]; |
| 3595 } | 3605 } |
| 3596 pred_exists = 1; | 3606 pred_exists = 1; |
| 3597 if (switchable_filter_index == 0 && | 3607 if (switchable_filter_index == 0 && |
| 3598 cpi->sf.use_rd_breakout && | 3608 cpi->sf.use_rd_breakout && |
| 3599 best_rd < INT64_MAX) { | 3609 best_rd < INT64_MAX) { |
| 3600 if (tmp_best_rdu / 2 > best_rd) { | 3610 if (tmp_best_rdu / 2 > best_rd) { |
| 3601 // skip searching the other filters if the first is | 3611 // skip searching the other filters if the first is |
| 3602 // already substantially larger than the best so far | 3612 // already substantially larger than the best so far |
| 3603 tmp_best_filter = mbmi->interp_filter; | 3613 tmp_best_filter = mbmi->interp_filter; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 3627 if (tmp_rd == INT64_MAX) | 3637 if (tmp_rd == INT64_MAX) |
| 3628 continue; | 3638 continue; |
| 3629 } else { | 3639 } else { |
| 3630 total_sse = tmp_best_sse; | 3640 total_sse = tmp_best_sse; |
| 3631 rate = tmp_best_rate; | 3641 rate = tmp_best_rate; |
| 3632 rate_y = tmp_best_ratey; | 3642 rate_y = tmp_best_ratey; |
| 3633 distortion = tmp_best_distortion; | 3643 distortion = tmp_best_distortion; |
| 3634 skippable = tmp_best_skippable; | 3644 skippable = tmp_best_skippable; |
| 3635 *mbmi = tmp_best_mbmode; | 3645 *mbmi = tmp_best_mbmode; |
| 3636 for (i = 0; i < 4; i++) | 3646 for (i = 0; i < 4; i++) |
| 3637 xd->mi[0]->bmi[i] = tmp_best_bmodes[i]; | 3647 xd->mi[0].src_mi->bmi[i] = tmp_best_bmodes[i]; |
| 3638 } | 3648 } |
| 3639 | 3649 |
| 3640 rate2 += rate; | 3650 rate2 += rate; |
| 3641 distortion2 += distortion; | 3651 distortion2 += distortion; |
| 3642 | 3652 |
| 3643 if (cm->interp_filter == SWITCHABLE) | 3653 if (cm->interp_filter == SWITCHABLE) |
| 3644 rate2 += vp9_get_switchable_rate(cpi); | 3654 rate2 += vp9_get_switchable_rate(cpi); |
| 3645 | 3655 |
| 3646 if (!mode_excluded) | 3656 if (!mode_excluded) |
| 3647 mode_excluded = comp_pred ? cm->reference_mode == SINGLE_REFERENCE | 3657 mode_excluded = comp_pred ? cm->reference_mode == SINGLE_REFERENCE |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3701 } | 3711 } |
| 3702 } else { | 3712 } else { |
| 3703 // Add in the cost of the no skip flag. | 3713 // Add in the cost of the no skip flag. |
| 3704 rate2 += vp9_cost_bit(vp9_get_skip_prob(cm, xd), 0); | 3714 rate2 += vp9_cost_bit(vp9_get_skip_prob(cm, xd), 0); |
| 3705 } | 3715 } |
| 3706 | 3716 |
| 3707 // Calculate the final RD estimate for this mode. | 3717 // Calculate the final RD estimate for this mode. |
| 3708 this_rd = RDCOST(x->rdmult, x->rddiv, rate2, distortion2); | 3718 this_rd = RDCOST(x->rdmult, x->rddiv, rate2, distortion2); |
| 3709 } | 3719 } |
| 3710 | 3720 |
| 3711 // Keep record of best inter rd with single reference | |
| 3712 if (is_inter_block(mbmi) && | |
| 3713 !has_second_ref(mbmi) && | |
| 3714 !mode_excluded && | |
| 3715 this_rd < best_inter_rd) { | |
| 3716 best_inter_rd = this_rd; | |
| 3717 best_inter_ref_frame = ref_frame; | |
| 3718 } | |
| 3719 | |
| 3720 if (!disable_skip && ref_frame == INTRA_FRAME) { | 3721 if (!disable_skip && ref_frame == INTRA_FRAME) { |
| 3721 for (i = 0; i < REFERENCE_MODES; ++i) | 3722 for (i = 0; i < REFERENCE_MODES; ++i) |
| 3722 best_pred_rd[i] = MIN(best_pred_rd[i], this_rd); | 3723 best_pred_rd[i] = MIN(best_pred_rd[i], this_rd); |
| 3723 for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; i++) | 3724 for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; i++) |
| 3724 best_filter_rd[i] = MIN(best_filter_rd[i], this_rd); | 3725 best_filter_rd[i] = MIN(best_filter_rd[i], this_rd); |
| 3725 } | 3726 } |
| 3726 | 3727 |
| 3727 // Did this mode help.. i.e. is it the new best mode | 3728 // Did this mode help.. i.e. is it the new best mode |
| 3728 if (this_rd < best_rd || x->skip) { | 3729 if (this_rd < best_rd || x->skip) { |
| 3729 if (!mode_excluded) { | 3730 if (!mode_excluded) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 3743 best_yrd = best_rd - | 3744 best_yrd = best_rd - |
| 3744 RDCOST(x->rdmult, x->rddiv, rate_uv, distortion_uv); | 3745 RDCOST(x->rdmult, x->rddiv, rate_uv, distortion_uv); |
| 3745 best_mbmode = *mbmi; | 3746 best_mbmode = *mbmi; |
| 3746 best_skip2 = this_skip2; | 3747 best_skip2 = this_skip2; |
| 3747 if (!x->select_tx_size) | 3748 if (!x->select_tx_size) |
| 3748 swap_block_ptr(x, ctx, 1, 0, 0, max_plane); | 3749 swap_block_ptr(x, ctx, 1, 0, 0, max_plane); |
| 3749 vpx_memcpy(ctx->zcoeff_blk, x->zcoeff_blk[TX_4X4], | 3750 vpx_memcpy(ctx->zcoeff_blk, x->zcoeff_blk[TX_4X4], |
| 3750 sizeof(uint8_t) * ctx->num_4x4_blk); | 3751 sizeof(uint8_t) * ctx->num_4x4_blk); |
| 3751 | 3752 |
| 3752 for (i = 0; i < 4; i++) | 3753 for (i = 0; i < 4; i++) |
| 3753 best_bmodes[i] = xd->mi[0]->bmi[i]; | 3754 best_bmodes[i] = xd->mi[0].src_mi->bmi[i]; |
| 3754 | 3755 |
| 3755 // TODO(debargha): enhance this test with a better distortion prediction | 3756 // TODO(debargha): enhance this test with a better distortion prediction |
| 3756 // based on qp, activity mask and history | 3757 // based on qp, activity mask and history |
| 3757 if ((cpi->sf.mode_search_skip_flags & FLAG_EARLY_TERMINATE) && | 3758 if ((cpi->sf.mode_search_skip_flags & FLAG_EARLY_TERMINATE) && |
| 3758 (ref_index > MIN_EARLY_TERM_INDEX)) { | 3759 (ref_index > MIN_EARLY_TERM_INDEX)) { |
| 3759 const int qstep = xd->plane[0].dequant[1]; | 3760 const int qstep = xd->plane[0].dequant[1]; |
| 3760 // TODO(debargha): Enhance this by specializing for each mode_index | 3761 // TODO(debargha): Enhance this by specializing for each mode_index |
| 3761 int scale = 4; | 3762 int scale = 4; |
| 3762 if (x->source_variance < UINT_MAX) { | 3763 if (x->source_variance < UINT_MAX) { |
| 3763 const int var_adjust = (x->source_variance < 16); | 3764 const int var_adjust = (x->source_variance < 16); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 3779 single_rate = rate2 - compmode_cost; | 3780 single_rate = rate2 - compmode_cost; |
| 3780 hybrid_rate = rate2; | 3781 hybrid_rate = rate2; |
| 3781 } else { | 3782 } else { |
| 3782 single_rate = rate2; | 3783 single_rate = rate2; |
| 3783 hybrid_rate = rate2 + compmode_cost; | 3784 hybrid_rate = rate2 + compmode_cost; |
| 3784 } | 3785 } |
| 3785 | 3786 |
| 3786 single_rd = RDCOST(x->rdmult, x->rddiv, single_rate, distortion2); | 3787 single_rd = RDCOST(x->rdmult, x->rddiv, single_rate, distortion2); |
| 3787 hybrid_rd = RDCOST(x->rdmult, x->rddiv, hybrid_rate, distortion2); | 3788 hybrid_rd = RDCOST(x->rdmult, x->rddiv, hybrid_rate, distortion2); |
| 3788 | 3789 |
| 3789 if (!comp_pred && single_rd < best_pred_rd[SINGLE_REFERENCE]) { | 3790 if (!comp_pred && single_rd < best_pred_rd[SINGLE_REFERENCE]) |
| 3790 best_pred_rd[SINGLE_REFERENCE] = single_rd; | 3791 best_pred_rd[SINGLE_REFERENCE] = single_rd; |
| 3791 } else if (comp_pred && single_rd < best_pred_rd[COMPOUND_REFERENCE]) { | 3792 else if (comp_pred && single_rd < best_pred_rd[COMPOUND_REFERENCE]) |
| 3792 best_pred_rd[COMPOUND_REFERENCE] = single_rd; | 3793 best_pred_rd[COMPOUND_REFERENCE] = single_rd; |
| 3793 } | 3794 |
| 3794 if (hybrid_rd < best_pred_rd[REFERENCE_MODE_SELECT]) | 3795 if (hybrid_rd < best_pred_rd[REFERENCE_MODE_SELECT]) |
| 3795 best_pred_rd[REFERENCE_MODE_SELECT] = hybrid_rd; | 3796 best_pred_rd[REFERENCE_MODE_SELECT] = hybrid_rd; |
| 3796 } | 3797 } |
| 3797 | 3798 |
| 3798 /* keep record of best filter type */ | 3799 /* keep record of best filter type */ |
| 3799 if (!mode_excluded && !disable_skip && ref_frame != INTRA_FRAME && | 3800 if (!mode_excluded && !disable_skip && ref_frame != INTRA_FRAME && |
| 3800 cm->interp_filter != BILINEAR) { | 3801 cm->interp_filter != BILINEAR) { |
| 3801 int64_t ref = rd_opt->filter_cache[cm->interp_filter == SWITCHABLE ? | 3802 int64_t ref = rd_opt->filter_cache[cm->interp_filter == SWITCHABLE ? |
| 3802 SWITCHABLE_FILTERS : cm->interp_filter]; | 3803 SWITCHABLE_FILTERS : cm->interp_filter]; |
| 3803 int64_t adj_rd; | 3804 int64_t adj_rd; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 3824 if (x->skip && !comp_pred) | 3825 if (x->skip && !comp_pred) |
| 3825 break; | 3826 break; |
| 3826 } | 3827 } |
| 3827 | 3828 |
| 3828 if (best_rd >= best_rd_so_far) | 3829 if (best_rd >= best_rd_so_far) |
| 3829 return INT64_MAX; | 3830 return INT64_MAX; |
| 3830 | 3831 |
| 3831 // If we used an estimate for the uv intra rd in the loop above... | 3832 // If we used an estimate for the uv intra rd in the loop above... |
| 3832 if (cpi->sf.use_uv_intra_rd_estimate) { | 3833 if (cpi->sf.use_uv_intra_rd_estimate) { |
| 3833 // Do Intra UV best rd mode selection if best mode choice above was intra. | 3834 // Do Intra UV best rd mode selection if best mode choice above was intra. |
| 3834 if (vp9_ref_order[best_ref_index].ref_frame[0] == INTRA_FRAME) { | 3835 if (best_mbmode.ref_frame[0] == INTRA_FRAME) { |
| 3835 *mbmi = best_mbmode; | 3836 *mbmi = best_mbmode; |
| 3836 rd_pick_intra_sbuv_mode(cpi, x, ctx, &rate_uv_intra, | 3837 rd_pick_intra_sbuv_mode(cpi, x, ctx, &rate_uv_intra, |
| 3837 &rate_uv_tokenonly, | 3838 &rate_uv_tokenonly, |
| 3838 &dist_uv, | 3839 &dist_uv, |
| 3839 &skip_uv, | 3840 &skip_uv, |
| 3840 BLOCK_8X8, TX_4X4); | 3841 BLOCK_8X8, TX_4X4); |
| 3841 } | 3842 } |
| 3842 } | 3843 } |
| 3843 | 3844 |
| 3844 if (best_rd == INT64_MAX) { | 3845 if (best_rd == INT64_MAX) { |
| 3845 *returnrate = INT_MAX; | 3846 *returnrate = INT_MAX; |
| 3846 *returndistortion = INT64_MAX; | 3847 *returndistortion = INT64_MAX; |
| 3847 return best_rd; | 3848 return best_rd; |
| 3848 } | 3849 } |
| 3849 | 3850 |
| 3850 assert((cm->interp_filter == SWITCHABLE) || | 3851 assert((cm->interp_filter == SWITCHABLE) || |
| 3851 (cm->interp_filter == best_mbmode.interp_filter) || | 3852 (cm->interp_filter == best_mbmode.interp_filter) || |
| 3852 !is_inter_block(&best_mbmode)); | 3853 !is_inter_block(&best_mbmode)); |
| 3853 | 3854 |
| 3854 update_rd_thresh_fact(cpi, bsize, best_ref_index); | 3855 update_rd_thresh_fact(cpi, bsize, best_ref_index); |
| 3855 | 3856 |
| 3856 // macroblock modes | 3857 // macroblock modes |
| 3857 *mbmi = best_mbmode; | 3858 *mbmi = best_mbmode; |
| 3858 x->skip |= best_skip2; | 3859 x->skip |= best_skip2; |
| 3859 if (!is_inter_block(&best_mbmode)) { | 3860 if (!is_inter_block(&best_mbmode)) { |
| 3860 for (i = 0; i < 4; i++) | 3861 for (i = 0; i < 4; i++) |
| 3861 xd->mi[0]->bmi[i].as_mode = best_bmodes[i].as_mode; | 3862 xd->mi[0].src_mi->bmi[i].as_mode = best_bmodes[i].as_mode; |
| 3862 } else { | 3863 } else { |
| 3863 for (i = 0; i < 4; ++i) | 3864 for (i = 0; i < 4; ++i) |
| 3864 vpx_memcpy(&xd->mi[0]->bmi[i], &best_bmodes[i], sizeof(b_mode_info)); | 3865 vpx_memcpy(&xd->mi[0].src_mi->bmi[i], &best_bmodes[i], |
| 3866 sizeof(b_mode_info)); |
| 3865 | 3867 |
| 3866 mbmi->mv[0].as_int = xd->mi[0]->bmi[3].as_mv[0].as_int; | 3868 mbmi->mv[0].as_int = xd->mi[0].src_mi->bmi[3].as_mv[0].as_int; |
| 3867 mbmi->mv[1].as_int = xd->mi[0]->bmi[3].as_mv[1].as_int; | 3869 mbmi->mv[1].as_int = xd->mi[0].src_mi->bmi[3].as_mv[1].as_int; |
| 3868 } | 3870 } |
| 3869 | 3871 |
| 3870 for (i = 0; i < REFERENCE_MODES; ++i) { | 3872 for (i = 0; i < REFERENCE_MODES; ++i) { |
| 3871 if (best_pred_rd[i] == INT64_MAX) | 3873 if (best_pred_rd[i] == INT64_MAX) |
| 3872 best_pred_diff[i] = INT_MIN; | 3874 best_pred_diff[i] = INT_MIN; |
| 3873 else | 3875 else |
| 3874 best_pred_diff[i] = best_rd - best_pred_rd[i]; | 3876 best_pred_diff[i] = best_rd - best_pred_rd[i]; |
| 3875 } | 3877 } |
| 3876 | 3878 |
| 3877 if (!x->skip) { | 3879 if (!x->skip) { |
| 3878 for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; i++) { | 3880 for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; i++) { |
| 3879 if (best_filter_rd[i] == INT64_MAX) | 3881 if (best_filter_rd[i] == INT64_MAX) |
| 3880 best_filter_diff[i] = 0; | 3882 best_filter_diff[i] = 0; |
| 3881 else | 3883 else |
| 3882 best_filter_diff[i] = best_rd - best_filter_rd[i]; | 3884 best_filter_diff[i] = best_rd - best_filter_rd[i]; |
| 3883 } | 3885 } |
| 3884 if (cm->interp_filter == SWITCHABLE) | 3886 if (cm->interp_filter == SWITCHABLE) |
| 3885 assert(best_filter_diff[SWITCHABLE_FILTERS] == 0); | 3887 assert(best_filter_diff[SWITCHABLE_FILTERS] == 0); |
| 3886 } else { | 3888 } else { |
| 3887 vp9_zero(best_filter_diff); | 3889 vp9_zero(best_filter_diff); |
| 3888 } | 3890 } |
| 3889 | 3891 |
| 3890 set_ref_ptrs(cm, xd, mbmi->ref_frame[0], mbmi->ref_frame[1]); | |
| 3891 store_coding_context(x, ctx, best_ref_index, | 3892 store_coding_context(x, ctx, best_ref_index, |
| 3892 best_pred_diff, best_tx_diff, best_filter_diff, 0); | 3893 best_pred_diff, best_tx_diff, best_filter_diff, 0); |
| 3893 | 3894 |
| 3894 return best_rd; | 3895 return best_rd; |
| 3895 } | 3896 } |
| 3897 |
| OLD | NEW |