| 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 |
| 11 #include <assert.h> |
| 12 #include <limits.h> |
| 13 #include <math.h> |
| 11 #include <stdio.h> | 14 #include <stdio.h> |
| 12 #include <math.h> | |
| 13 #include <limits.h> | |
| 14 #include <assert.h> | |
| 15 | 15 |
| 16 #include "./vp9_rtcd.h" |
| 17 |
| 18 #include "vpx_mem/vpx_mem.h" |
| 19 |
| 20 #include "vp9/common/vp9_common.h" |
| 21 #include "vp9/common/vp9_entropy.h" |
| 22 #include "vp9/common/vp9_entropymode.h" |
| 23 #include "vp9/common/vp9_idct.h" |
| 24 #include "vp9/common/vp9_mvref_common.h" |
| 16 #include "vp9/common/vp9_pragmas.h" | 25 #include "vp9/common/vp9_pragmas.h" |
| 26 #include "vp9/common/vp9_pred_common.h" |
| 27 #include "vp9/common/vp9_quant_common.h" |
| 28 #include "vp9/common/vp9_reconinter.h" |
| 29 #include "vp9/common/vp9_reconintra.h" |
| 30 #include "vp9/common/vp9_seg_common.h" |
| 31 #include "vp9/common/vp9_systemdependent.h" |
| 32 |
| 33 #include "vp9/encoder/vp9_encodemb.h" |
| 34 #include "vp9/encoder/vp9_encodemv.h" |
| 35 #include "vp9/encoder/vp9_mcomp.h" |
| 36 #include "vp9/encoder/vp9_onyx_int.h" |
| 37 #include "vp9/encoder/vp9_quantize.h" |
| 38 #include "vp9/encoder/vp9_ratectrl.h" |
| 39 #include "vp9/encoder/vp9_rdopt.h" |
| 17 #include "vp9/encoder/vp9_tokenize.h" | 40 #include "vp9/encoder/vp9_tokenize.h" |
| 18 #include "vp9/encoder/vp9_treewriter.h" | 41 #include "vp9/encoder/vp9_treewriter.h" |
| 19 #include "vp9/encoder/vp9_onyx_int.h" | |
| 20 #include "vp9/common/vp9_entropymode.h" | |
| 21 #include "vp9/common/vp9_reconinter.h" | |
| 22 #include "vp9/common/vp9_reconintra.h" | |
| 23 #include "vp9/common/vp9_quant_common.h" | |
| 24 #include "vp9/encoder/vp9_encodemb.h" | |
| 25 #include "vp9/encoder/vp9_quantize.h" | |
| 26 #include "vp9/encoder/vp9_variance.h" | 42 #include "vp9/encoder/vp9_variance.h" |
| 27 #include "vp9/encoder/vp9_mcomp.h" | |
| 28 #include "vp9/encoder/vp9_rdopt.h" | |
| 29 #include "vp9/encoder/vp9_ratectrl.h" | |
| 30 #include "vpx_mem/vpx_mem.h" | |
| 31 #include "vp9/common/vp9_systemdependent.h" | |
| 32 #include "vp9/encoder/vp9_encodemv.h" | |
| 33 #include "vp9/common/vp9_seg_common.h" | |
| 34 #include "vp9/common/vp9_pred_common.h" | |
| 35 #include "vp9/common/vp9_entropy.h" | |
| 36 #include "./vp9_rtcd.h" | |
| 37 #include "vp9/common/vp9_mvref_common.h" | |
| 38 #include "vp9/common/vp9_common.h" | |
| 39 | 43 |
| 40 /* Factor to weigh the rate for switchable interp filters */ | 44 /* Factor to weigh the rate for switchable interp filters */ |
| 41 #define SWITCHABLE_INTERP_RATE_FACTOR 1 | 45 #define SWITCHABLE_INTERP_RATE_FACTOR 1 |
| 42 | 46 |
| 43 #define LAST_FRAME_MODE_MASK 0xFFEDCD60 | 47 #define LAST_FRAME_MODE_MASK 0xFFEDCD60 |
| 44 #define GOLDEN_FRAME_MODE_MASK 0xFFDA3BB0 | 48 #define GOLDEN_FRAME_MODE_MASK 0xFFDA3BB0 |
| 45 #define ALT_REF_MODE_MASK 0xFFC648D0 | 49 #define ALT_REF_MODE_MASK 0xFFC648D0 |
| 46 | 50 |
| 47 #define MIN_EARLY_TERM_INDEX 3 | 51 #define MIN_EARLY_TERM_INDEX 3 |
| 48 | 52 |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 ? sf->thresh_mult_sub8x8[i] * t / 4 | 269 ? sf->thresh_mult_sub8x8[i] * t / 4 |
| 266 : INT_MAX; | 270 : INT_MAX; |
| 267 } | 271 } |
| 268 } | 272 } |
| 269 } | 273 } |
| 270 } | 274 } |
| 271 | 275 |
| 272 void vp9_initialize_rd_consts(VP9_COMP *cpi) { | 276 void vp9_initialize_rd_consts(VP9_COMP *cpi) { |
| 273 VP9_COMMON *cm = &cpi->common; | 277 VP9_COMMON *cm = &cpi->common; |
| 274 MACROBLOCK *x = &cpi->mb; | 278 MACROBLOCK *x = &cpi->mb; |
| 275 int qindex, i; | 279 int i; |
| 276 | 280 |
| 277 vp9_clear_system_state(); // __asm emms; | 281 vp9_clear_system_state(); |
| 278 | |
| 279 // Further tests required to see if optimum is different | |
| 280 // for key frames, golden frames and arf frames. | |
| 281 // if (cpi->common.refresh_golden_frame || | |
| 282 // cpi->common.refresh_alt_ref_frame) | |
| 283 qindex = clamp(cm->base_qindex + cm->y_dc_delta_q, 0, MAXQ); | |
| 284 | 282 |
| 285 cpi->RDDIV = RDDIV_BITS; // in bits (to multiply D by 128) | 283 cpi->RDDIV = RDDIV_BITS; // in bits (to multiply D by 128) |
| 286 cpi->RDMULT = vp9_compute_rd_mult(cpi, qindex); | 284 cpi->RDMULT = vp9_compute_rd_mult(cpi, cm->base_qindex + cm->y_dc_delta_q); |
| 287 | 285 |
| 288 x->errorperbit = cpi->RDMULT / RD_MULT_EPB_RATIO; | 286 x->errorperbit = cpi->RDMULT / RD_MULT_EPB_RATIO; |
| 289 x->errorperbit += (x->errorperbit == 0); | 287 x->errorperbit += (x->errorperbit == 0); |
| 290 | 288 |
| 291 vp9_set_speed_features(cpi); | 289 vp9_set_speed_features(cpi); |
| 292 | 290 |
| 293 x->select_txfm_size = (cpi->sf.tx_size_search_method == USE_LARGESTALL && | 291 x->select_txfm_size = (cpi->sf.tx_size_search_method == USE_LARGESTALL && |
| 294 cm->frame_type != KEY_FRAME) ? 0 : 1; | 292 cm->frame_type != KEY_FRAME) ? 0 : 1; |
| 295 | 293 |
| 296 set_block_thresholds(cpi); | 294 set_block_thresholds(cpi); |
| 297 | 295 |
| 298 fill_token_costs(x->token_costs, cm->fc.coef_probs); | 296 if (!cpi->sf.use_nonrd_pick_mode) { |
| 297 fill_token_costs(x->token_costs, cm->fc.coef_probs); |
| 299 | 298 |
| 300 if (!cpi->sf.use_pick_mode) { | |
| 301 for (i = 0; i < PARTITION_CONTEXTS; i++) | 299 for (i = 0; i < PARTITION_CONTEXTS; i++) |
| 302 vp9_cost_tokens(x->partition_cost[i], get_partition_probs(cm, i), | 300 vp9_cost_tokens(x->partition_cost[i], get_partition_probs(cm, i), |
| 303 vp9_partition_tree); | 301 vp9_partition_tree); |
| 302 } |
| 304 | 303 |
| 304 if (!cpi->sf.use_nonrd_pick_mode || (cm->current_video_frame & 0x07) == 1) { |
| 305 fill_mode_costs(cpi); | 305 fill_mode_costs(cpi); |
| 306 | 306 |
| 307 if (!frame_is_intra_only(cm)) { | 307 if (!frame_is_intra_only(cm)) { |
| 308 vp9_build_nmv_cost_table(x->nmvjointcost, | 308 vp9_build_nmv_cost_table(x->nmvjointcost, |
| 309 cm->allow_high_precision_mv ? x->nmvcost_hp | 309 cm->allow_high_precision_mv ? x->nmvcost_hp |
| 310 : x->nmvcost, | 310 : x->nmvcost, |
| 311 &cm->fc.nmvc, | 311 &cm->fc.nmvc, cm->allow_high_precision_mv); |
| 312 cm->allow_high_precision_mv, 1, 1); | |
| 313 | 312 |
| 314 for (i = 0; i < INTER_MODE_CONTEXTS; ++i) | 313 for (i = 0; i < INTER_MODE_CONTEXTS; ++i) |
| 315 vp9_cost_tokens((int *)x->inter_mode_cost[i], | 314 vp9_cost_tokens((int *)x->inter_mode_cost[i], |
| 316 cm->fc.inter_mode_probs[i], vp9_inter_mode_tree); | 315 cm->fc.inter_mode_probs[i], vp9_inter_mode_tree); |
| 317 } | 316 } |
| 318 } | 317 } |
| 319 } | 318 } |
| 320 | 319 |
| 321 static const int MAX_XSQ_Q10 = 245727; | 320 static const int MAX_XSQ_Q10 = 245727; |
| 322 | 321 |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 408 // source with given variance when quantized with a uniform quantizer | 407 // source with given variance when quantized with a uniform quantizer |
| 409 // with given stepsize. The closed form expressions are in: | 408 // with given stepsize. The closed form expressions are in: |
| 410 // Hang and Chen, "Source Model for transform video coder and its | 409 // Hang and Chen, "Source Model for transform video coder and its |
| 411 // application - Part I: Fundamental Theory", IEEE Trans. Circ. | 410 // application - Part I: Fundamental Theory", IEEE Trans. Circ. |
| 412 // Sys. for Video Tech., April 1997. | 411 // Sys. for Video Tech., April 1997. |
| 413 if (var == 0) { | 412 if (var == 0) { |
| 414 *rate = 0; | 413 *rate = 0; |
| 415 *dist = 0; | 414 *dist = 0; |
| 416 } else { | 415 } else { |
| 417 int d_q10, r_q10; | 416 int d_q10, r_q10; |
| 418 uint64_t xsq_q10_64 = | 417 const uint64_t xsq_q10_64 = |
| 419 ((((uint64_t)qstep * qstep * n) << 10) + (var >> 1)) / var; | 418 ((((uint64_t)qstep * qstep * n) << 10) + (var >> 1)) / var; |
| 420 int xsq_q10 = xsq_q10_64 > MAX_XSQ_Q10 ? MAX_XSQ_Q10 : xsq_q10_64; | 419 const int xsq_q10 = xsq_q10_64 > MAX_XSQ_Q10 ? |
| 420 MAX_XSQ_Q10 : (int)xsq_q10_64; |
| 421 model_rd_norm(xsq_q10, &r_q10, &d_q10); | 421 model_rd_norm(xsq_q10, &r_q10, &d_q10); |
| 422 *rate = (n * r_q10 + 2) >> 2; | 422 *rate = (n * r_q10 + 2) >> 2; |
| 423 *dist = (var * (int64_t)d_q10 + 512) >> 10; | 423 *dist = (var * (int64_t)d_q10 + 512) >> 10; |
| 424 } | 424 } |
| 425 } | 425 } |
| 426 | 426 |
| 427 static void model_rd_for_sb(VP9_COMP *cpi, BLOCK_SIZE bsize, | 427 static void model_rd_for_sb(VP9_COMP *cpi, BLOCK_SIZE bsize, |
| 428 MACROBLOCK *x, MACROBLOCKD *xd, | 428 MACROBLOCK *x, MACROBLOCKD *xd, |
| 429 int *out_rate_sum, int64_t *out_dist_sum) { | 429 int *out_rate_sum, int64_t *out_dist_sum) { |
| 430 // Note our transform coeffs are 8 times an orthogonal transform. | 430 // Note our transform coeffs are 8 times an orthogonal transform. |
| 431 // Hence quantizer step is also 8 times. To get effective quantizer | 431 // Hence quantizer step is also 8 times. To get effective quantizer |
| 432 // we need to divide by 8 before sending to modeling function. | 432 // we need to divide by 8 before sending to modeling function. |
| 433 int i, rate_sum = 0, dist_sum = 0; | 433 int i; |
| 434 int64_t rate_sum = 0; |
| 435 int64_t dist_sum = 0; |
| 434 int ref = xd->mi_8x8[0]->mbmi.ref_frame[0]; | 436 int ref = xd->mi_8x8[0]->mbmi.ref_frame[0]; |
| 435 unsigned int sse; | 437 unsigned int sse; |
| 436 | 438 |
| 437 for (i = 0; i < MAX_MB_PLANE; ++i) { | 439 for (i = 0; i < MAX_MB_PLANE; ++i) { |
| 438 struct macroblock_plane *const p = &x->plane[i]; | 440 struct macroblock_plane *const p = &x->plane[i]; |
| 439 struct macroblockd_plane *const pd = &xd->plane[i]; | 441 struct macroblockd_plane *const pd = &xd->plane[i]; |
| 440 const BLOCK_SIZE bs = get_plane_block_size(bsize, pd); | 442 const BLOCK_SIZE bs = get_plane_block_size(bsize, pd); |
| 441 | 443 |
| 442 (void) cpi->fn_ptr[bs].vf(p->src.buf, p->src.stride, | 444 (void) cpi->fn_ptr[bs].vf(p->src.buf, p->src.stride, |
| 443 pd->dst.buf, pd->dst.stride, &sse); | 445 pd->dst.buf, pd->dst.stride, &sse); |
| 444 | 446 |
| 445 if (i == 0) | 447 if (i == 0) |
| 446 x->pred_sse[ref] = sse; | 448 x->pred_sse[ref] = sse; |
| 447 if (cpi->sf.use_pick_mode) { | 449 |
| 448 dist_sum += (int)sse; | 450 // Fast approximate the modelling function. |
| 451 if (cpi->speed > 4) { |
| 452 int64_t rate; |
| 453 int64_t dist; |
| 454 int64_t square_error = sse; |
| 455 int quantizer = (pd->dequant[1] >> 3); |
| 456 |
| 457 if (quantizer < 120) |
| 458 rate = (square_error * (280 - quantizer)) >> 8; |
| 459 else |
| 460 rate = 0; |
| 461 dist = (square_error * quantizer) >> 8; |
| 462 rate_sum += rate; |
| 463 dist_sum += dist; |
| 449 } else { | 464 } else { |
| 450 int rate; | 465 int rate; |
| 451 int64_t dist; | 466 int64_t dist; |
| 452 model_rd_from_var_lapndz(sse, 1 << num_pels_log2_lookup[bs], | 467 model_rd_from_var_lapndz(sse, 1 << num_pels_log2_lookup[bs], |
| 453 pd->dequant[1] >> 3, &rate, &dist); | 468 pd->dequant[1] >> 3, &rate, &dist); |
| 454 rate_sum += rate; | 469 rate_sum += rate; |
| 455 dist_sum += (int)dist; | 470 dist_sum += dist; |
| 456 } | 471 } |
| 457 } | 472 } |
| 458 | 473 |
| 459 *out_rate_sum = rate_sum; | 474 *out_rate_sum = (int)rate_sum; |
| 460 *out_dist_sum = (int64_t)dist_sum << 4; | 475 *out_dist_sum = dist_sum << 4; |
| 461 } | 476 } |
| 462 | 477 |
| 463 static void model_rd_for_sb_y_tx(VP9_COMP *cpi, BLOCK_SIZE bsize, | 478 static void model_rd_for_sb_y_tx(VP9_COMP *cpi, BLOCK_SIZE bsize, |
| 464 TX_SIZE tx_size, | 479 TX_SIZE tx_size, |
| 465 MACROBLOCK *x, MACROBLOCKD *xd, | 480 MACROBLOCK *x, MACROBLOCKD *xd, |
| 466 int *out_rate_sum, int64_t *out_dist_sum, | 481 int *out_rate_sum, int64_t *out_dist_sum, |
| 467 int *out_skip) { | 482 int *out_skip) { |
| 468 int j, k; | 483 int j, k; |
| 469 BLOCK_SIZE bs; | 484 BLOCK_SIZE bs; |
| 470 struct macroblock_plane *const p = &x->plane[0]; | 485 struct macroblock_plane *const p = &x->plane[0]; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 501 rate_sum += rate; | 516 rate_sum += rate; |
| 502 dist_sum += dist; | 517 dist_sum += dist; |
| 503 *out_skip &= (rate < 1024); | 518 *out_skip &= (rate < 1024); |
| 504 } | 519 } |
| 505 } | 520 } |
| 506 | 521 |
| 507 *out_rate_sum = rate_sum; | 522 *out_rate_sum = rate_sum; |
| 508 *out_dist_sum = dist_sum << 4; | 523 *out_dist_sum = dist_sum << 4; |
| 509 } | 524 } |
| 510 | 525 |
| 511 int64_t vp9_block_error_c(int16_t *coeff, int16_t *dqcoeff, | 526 int64_t vp9_block_error_c(const int16_t *coeff, const int16_t *dqcoeff, |
| 512 intptr_t block_size, int64_t *ssz) { | 527 intptr_t block_size, int64_t *ssz) { |
| 513 int i; | 528 int i; |
| 514 int64_t error = 0, sqcoeff = 0; | 529 int64_t error = 0, sqcoeff = 0; |
| 515 | 530 |
| 516 for (i = 0; i < block_size; i++) { | 531 for (i = 0; i < block_size; i++) { |
| 517 int this_diff = coeff[i] - dqcoeff[i]; | 532 const int diff = coeff[i] - dqcoeff[i]; |
| 518 error += (unsigned)this_diff * this_diff; | 533 error += diff * diff; |
| 519 sqcoeff += (unsigned) coeff[i] * coeff[i]; | 534 sqcoeff += coeff[i] * coeff[i]; |
| 520 } | 535 } |
| 521 | 536 |
| 522 *ssz = sqcoeff; | 537 *ssz = sqcoeff; |
| 523 return error; | 538 return error; |
| 524 } | 539 } |
| 525 | 540 |
| 526 /* The trailing '0' is a terminator which is used inside cost_coeffs() to | 541 /* The trailing '0' is a terminator which is used inside cost_coeffs() to |
| 527 * decide whether to include cost of a trailing EOB node or not (i.e. we | 542 * decide whether to include cost of a trailing EOB node or not (i.e. we |
| 528 * can skip this if the last coefficient in this transform block, e.g. the | 543 * can skip this if the last coefficient in this transform block, e.g. the |
| 529 * 16th coefficient in a 4x4 block or the 64th coefficient in a 8x8 block, | 544 * 16th coefficient in a 4x4 block or the 64th coefficient in a 8x8 block, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 540 ENTROPY_CONTEXT *A, ENTROPY_CONTEXT *L, | 555 ENTROPY_CONTEXT *A, ENTROPY_CONTEXT *L, |
| 541 TX_SIZE tx_size, | 556 TX_SIZE tx_size, |
| 542 const int16_t *scan, const int16_t *nb) { | 557 const int16_t *scan, const int16_t *nb) { |
| 543 MACROBLOCKD *const xd = &x->e_mbd; | 558 MACROBLOCKD *const xd = &x->e_mbd; |
| 544 MB_MODE_INFO *mbmi = &xd->mi_8x8[0]->mbmi; | 559 MB_MODE_INFO *mbmi = &xd->mi_8x8[0]->mbmi; |
| 545 struct macroblock_plane *p = &x->plane[plane]; | 560 struct macroblock_plane *p = &x->plane[plane]; |
| 546 struct macroblockd_plane *pd = &xd->plane[plane]; | 561 struct macroblockd_plane *pd = &xd->plane[plane]; |
| 547 const PLANE_TYPE type = pd->plane_type; | 562 const PLANE_TYPE type = pd->plane_type; |
| 548 const int16_t *band_count = &band_counts[tx_size][1]; | 563 const int16_t *band_count = &band_counts[tx_size][1]; |
| 549 const int eob = p->eobs[block]; | 564 const int eob = p->eobs[block]; |
| 550 const int16_t *const qcoeff_ptr = BLOCK_OFFSET(p->qcoeff, block); | 565 const int16_t *const qcoeff = BLOCK_OFFSET(p->qcoeff, block); |
| 551 const int ref = mbmi->ref_frame[0] != INTRA_FRAME; | |
| 552 unsigned int (*token_costs)[2][COEFF_CONTEXTS][ENTROPY_TOKENS] = | 566 unsigned int (*token_costs)[2][COEFF_CONTEXTS][ENTROPY_TOKENS] = |
| 553 x->token_costs[tx_size][type][ref]; | 567 x->token_costs[tx_size][type][is_inter_block(mbmi)]; |
| 554 const ENTROPY_CONTEXT above_ec = !!*A, left_ec = !!*L; | |
| 555 uint8_t *p_tok = x->token_cache; | 568 uint8_t *p_tok = x->token_cache; |
| 556 int pt = combine_entropy_contexts(above_ec, left_ec); | 569 int pt = combine_entropy_contexts(*A, *L); |
| 557 int c, cost; | 570 int c, cost; |
| 558 | 571 |
| 559 // Check for consistency of tx_size with mode info | 572 // Check for consistency of tx_size with mode info |
| 560 assert(type == PLANE_TYPE_Y ? mbmi->tx_size == tx_size | 573 assert(type == PLANE_TYPE_Y ? mbmi->tx_size == tx_size |
| 561 : get_uv_tx_size(mbmi) == tx_size); | 574 : get_uv_tx_size(mbmi) == tx_size); |
| 562 | 575 |
| 563 if (eob == 0) { | 576 if (eob == 0) { |
| 564 // single eob token | 577 // single eob token |
| 565 cost = token_costs[0][0][pt][EOB_TOKEN]; | 578 cost = token_costs[0][0][pt][EOB_TOKEN]; |
| 566 c = 0; | 579 c = 0; |
| 567 } else { | 580 } else { |
| 568 int band_left = *band_count++; | 581 int band_left = *band_count++; |
| 569 | 582 |
| 570 // dc token | 583 // dc token |
| 571 int v = qcoeff_ptr[0]; | 584 int v = qcoeff[0]; |
| 572 int prev_t = vp9_dct_value_tokens_ptr[v].token; | 585 int prev_t = vp9_dct_value_tokens_ptr[v].token; |
| 573 cost = (*token_costs)[0][pt][prev_t] + vp9_dct_value_cost_ptr[v]; | 586 cost = (*token_costs)[0][pt][prev_t] + vp9_dct_value_cost_ptr[v]; |
| 574 p_tok[0] = vp9_pt_energy_class[prev_t]; | 587 p_tok[0] = vp9_pt_energy_class[prev_t]; |
| 575 ++token_costs; | 588 ++token_costs; |
| 576 | 589 |
| 577 // ac tokens | 590 // ac tokens |
| 578 for (c = 1; c < eob; c++) { | 591 for (c = 1; c < eob; c++) { |
| 579 const int rc = scan[c]; | 592 const int rc = scan[c]; |
| 580 int t; | 593 int t; |
| 581 | 594 |
| 582 v = qcoeff_ptr[rc]; | 595 v = qcoeff[rc]; |
| 583 t = vp9_dct_value_tokens_ptr[v].token; | 596 t = vp9_dct_value_tokens_ptr[v].token; |
| 584 pt = get_coef_context(nb, p_tok, c); | 597 pt = get_coef_context(nb, p_tok, c); |
| 585 cost += (*token_costs)[!prev_t][pt][t] + vp9_dct_value_cost_ptr[v]; | 598 cost += (*token_costs)[!prev_t][pt][t] + vp9_dct_value_cost_ptr[v]; |
| 586 p_tok[rc] = vp9_pt_energy_class[t]; | 599 p_tok[rc] = vp9_pt_energy_class[t]; |
| 587 prev_t = t; | 600 prev_t = t; |
| 588 if (!--band_left) { | 601 if (!--band_left) { |
| 589 band_left = *band_count++; | 602 band_left = *band_count++; |
| 590 ++token_costs; | 603 ++token_costs; |
| 591 } | 604 } |
| 592 } | 605 } |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 669 args->this_dist += args->dist; | 682 args->this_dist += args->dist; |
| 670 args->this_sse += args->sse; | 683 args->this_sse += args->sse; |
| 671 args->this_rd += rd; | 684 args->this_rd += rd; |
| 672 | 685 |
| 673 if (args->this_rd > args->best_rd) { | 686 if (args->this_rd > args->best_rd) { |
| 674 args->skip = 1; | 687 args->skip = 1; |
| 675 return; | 688 return; |
| 676 } | 689 } |
| 677 } | 690 } |
| 678 | 691 |
| 679 void vp9_get_entropy_contexts(TX_SIZE tx_size, | 692 void vp9_get_entropy_contexts(BLOCK_SIZE bsize, TX_SIZE tx_size, |
| 680 ENTROPY_CONTEXT t_above[16], ENTROPY_CONTEXT t_left[16], | 693 const struct macroblockd_plane *pd, |
| 681 const ENTROPY_CONTEXT *above, const ENTROPY_CONTEXT *left, | 694 ENTROPY_CONTEXT t_above[16], |
| 682 int num_4x4_w, int num_4x4_h) { | 695 ENTROPY_CONTEXT t_left[16]) { |
| 696 const BLOCK_SIZE plane_bsize = get_plane_block_size(bsize, pd); |
| 697 const int num_4x4_w = num_4x4_blocks_wide_lookup[plane_bsize]; |
| 698 const int num_4x4_h = num_4x4_blocks_high_lookup[plane_bsize]; |
| 699 const ENTROPY_CONTEXT *const above = pd->above_context; |
| 700 const ENTROPY_CONTEXT *const left = pd->left_context; |
| 701 |
| 683 int i; | 702 int i; |
| 684 switch (tx_size) { | 703 switch (tx_size) { |
| 685 case TX_4X4: | 704 case TX_4X4: |
| 686 vpx_memcpy(t_above, above, sizeof(ENTROPY_CONTEXT) * num_4x4_w); | 705 vpx_memcpy(t_above, above, sizeof(ENTROPY_CONTEXT) * num_4x4_w); |
| 687 vpx_memcpy(t_left, left, sizeof(ENTROPY_CONTEXT) * num_4x4_h); | 706 vpx_memcpy(t_left, left, sizeof(ENTROPY_CONTEXT) * num_4x4_h); |
| 688 break; | 707 break; |
| 689 case TX_8X8: | 708 case TX_8X8: |
| 690 for (i = 0; i < num_4x4_w; i += 2) | 709 for (i = 0; i < num_4x4_w; i += 2) |
| 691 t_above[i] = !!*(const uint16_t *)&above[i]; | 710 t_above[i] = !!*(const uint16_t *)&above[i]; |
| 692 for (i = 0; i < num_4x4_h; i += 2) | 711 for (i = 0; i < num_4x4_h; i += 2) |
| (...skipping 16 matching lines...) Expand all Loading... |
| 709 } | 728 } |
| 710 } | 729 } |
| 711 | 730 |
| 712 static void txfm_rd_in_plane(MACROBLOCK *x, | 731 static void txfm_rd_in_plane(MACROBLOCK *x, |
| 713 int *rate, int64_t *distortion, | 732 int *rate, int64_t *distortion, |
| 714 int *skippable, int64_t *sse, | 733 int *skippable, int64_t *sse, |
| 715 int64_t ref_best_rd, int plane, | 734 int64_t ref_best_rd, int plane, |
| 716 BLOCK_SIZE bsize, TX_SIZE tx_size) { | 735 BLOCK_SIZE bsize, TX_SIZE tx_size) { |
| 717 MACROBLOCKD *const xd = &x->e_mbd; | 736 MACROBLOCKD *const xd = &x->e_mbd; |
| 718 struct macroblockd_plane *const pd = &xd->plane[plane]; | 737 struct macroblockd_plane *const pd = &xd->plane[plane]; |
| 719 const BLOCK_SIZE bs = get_plane_block_size(bsize, pd); | |
| 720 const int num_4x4_w = num_4x4_blocks_wide_lookup[bs]; | |
| 721 const int num_4x4_h = num_4x4_blocks_high_lookup[bs]; | |
| 722 struct rdcost_block_args args = { 0 }; | 738 struct rdcost_block_args args = { 0 }; |
| 723 args.x = x; | 739 args.x = x; |
| 724 args.best_rd = ref_best_rd; | 740 args.best_rd = ref_best_rd; |
| 725 | 741 |
| 726 if (plane == 0) | 742 if (plane == 0) |
| 727 xd->mi_8x8[0]->mbmi.tx_size = tx_size; | 743 xd->mi_8x8[0]->mbmi.tx_size = tx_size; |
| 728 | 744 |
| 729 vp9_get_entropy_contexts(tx_size, args.t_above, args.t_left, | 745 vp9_get_entropy_contexts(bsize, tx_size, pd, args.t_above, args.t_left); |
| 730 pd->above_context, pd->left_context, | |
| 731 num_4x4_w, num_4x4_h); | |
| 732 | 746 |
| 733 args.so = get_scan(xd, tx_size, pd->plane_type, 0); | 747 args.so = get_scan(xd, tx_size, pd->plane_type, 0); |
| 734 | 748 |
| 735 vp9_foreach_transformed_block_in_plane(xd, bsize, plane, | 749 vp9_foreach_transformed_block_in_plane(xd, bsize, plane, |
| 736 block_rd_txfm, &args); | 750 block_rd_txfm, &args); |
| 737 if (args.skip) { | 751 if (args.skip) { |
| 738 *rate = INT_MAX; | 752 *rate = INT_MAX; |
| 739 *distortion = INT64_MAX; | 753 *distortion = INT64_MAX; |
| 740 *sse = INT64_MAX; | 754 *sse = INT64_MAX; |
| 741 *skippable = 0; | 755 *skippable = 0; |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 837 cpi->tx_stepdown_count[max_tx_size - TX_16X16]++; | 851 cpi->tx_stepdown_count[max_tx_size - TX_16X16]++; |
| 838 } else if (rd[TX_8X8][1] < rd[TX_4X4][1]) { | 852 } else if (rd[TX_8X8][1] < rd[TX_4X4][1]) { |
| 839 tx_cache[TX_MODE_SELECT] = rd[TX_8X8][1]; | 853 tx_cache[TX_MODE_SELECT] = rd[TX_8X8][1]; |
| 840 cpi->tx_stepdown_count[max_tx_size - TX_8X8]++; | 854 cpi->tx_stepdown_count[max_tx_size - TX_8X8]++; |
| 841 } else { | 855 } else { |
| 842 tx_cache[TX_MODE_SELECT] = rd[TX_4X4][1]; | 856 tx_cache[TX_MODE_SELECT] = rd[TX_4X4][1]; |
| 843 cpi->tx_stepdown_count[max_tx_size - TX_4X4]++; | 857 cpi->tx_stepdown_count[max_tx_size - TX_4X4]++; |
| 844 } | 858 } |
| 845 } | 859 } |
| 846 | 860 |
| 861 static int64_t scaled_rd_cost(int rdmult, int rddiv, |
| 862 int rate, int64_t dist, double scale) { |
| 863 return (int64_t) (RDCOST(rdmult, rddiv, rate, dist) * scale); |
| 864 } |
| 865 |
| 847 static void choose_txfm_size_from_modelrd(VP9_COMP *cpi, MACROBLOCK *x, | 866 static void choose_txfm_size_from_modelrd(VP9_COMP *cpi, MACROBLOCK *x, |
| 848 int (*r)[2], int *rate, | 867 int (*r)[2], int *rate, |
| 849 int64_t *d, int64_t *distortion, | 868 int64_t *d, int64_t *distortion, |
| 850 int *s, int *skip, int64_t *sse, | 869 int *s, int *skip, int64_t *sse, |
| 851 int64_t ref_best_rd, | 870 int64_t ref_best_rd, |
| 852 BLOCK_SIZE bs) { | 871 BLOCK_SIZE bs) { |
| 853 const TX_SIZE max_tx_size = max_txsize_lookup[bs]; | 872 const TX_SIZE max_tx_size = max_txsize_lookup[bs]; |
| 854 VP9_COMMON *const cm = &cpi->common; | 873 VP9_COMMON *const cm = &cpi->common; |
| 855 MACROBLOCKD *const xd = &x->e_mbd; | 874 MACROBLOCKD *const xd = &x->e_mbd; |
| 856 MB_MODE_INFO *const mbmi = &xd->mi_8x8[0]->mbmi; | 875 MB_MODE_INFO *const mbmi = &xd->mi_8x8[0]->mbmi; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 874 for (n = TX_4X4; n <= max_tx_size; n++) { | 893 for (n = TX_4X4; n <= max_tx_size; n++) { |
| 875 double scale = scale_rd[n]; | 894 double scale = scale_rd[n]; |
| 876 r[n][1] = r[n][0]; | 895 r[n][1] = r[n][0]; |
| 877 for (m = 0; m <= n - (n == max_tx_size); m++) { | 896 for (m = 0; m <= n - (n == max_tx_size); m++) { |
| 878 if (m == n) | 897 if (m == n) |
| 879 r[n][1] += vp9_cost_zero(tx_probs[m]); | 898 r[n][1] += vp9_cost_zero(tx_probs[m]); |
| 880 else | 899 else |
| 881 r[n][1] += vp9_cost_one(tx_probs[m]); | 900 r[n][1] += vp9_cost_one(tx_probs[m]); |
| 882 } | 901 } |
| 883 if (s[n]) { | 902 if (s[n]) { |
| 884 rd[n][0] = rd[n][1] = RDCOST(x->rdmult, x->rddiv, s1, d[n]) * scale; | 903 rd[n][0] = rd[n][1] = scaled_rd_cost(x->rdmult, x->rddiv, s1, d[n], |
| 904 scale); |
| 885 } else { | 905 } else { |
| 886 rd[n][0] = RDCOST(x->rdmult, x->rddiv, r[n][0] + s0, d[n]) * scale; | 906 rd[n][0] = scaled_rd_cost(x->rdmult, x->rddiv, r[n][0] + s0, d[n], |
| 887 rd[n][1] = RDCOST(x->rdmult, x->rddiv, r[n][1] + s0, d[n]) * scale; | 907 scale); |
| 908 rd[n][1] = scaled_rd_cost(x->rdmult, x->rddiv, r[n][1] + s0, d[n], |
| 909 scale); |
| 888 } | 910 } |
| 889 if (rd[n][1] < best_rd) { | 911 if (rd[n][1] < best_rd) { |
| 890 best_rd = rd[n][1]; | 912 best_rd = rd[n][1]; |
| 891 best_tx = n; | 913 best_tx = n; |
| 892 } | 914 } |
| 893 } | 915 } |
| 894 | 916 |
| 895 mbmi->tx_size = cm->tx_mode == TX_MODE_SELECT ? | 917 mbmi->tx_size = cm->tx_mode == TX_MODE_SELECT ? |
| 896 best_tx : MIN(max_tx_size, max_mode_tx_size); | 918 best_tx : MIN(max_tx_size, max_mode_tx_size); |
| 897 | 919 |
| 898 // Actually encode using the chosen mode if a model was used, but do not | 920 // Actually encode using the chosen mode if a model was used, but do not |
| 899 // update the r, d costs | 921 // update the r, d costs |
| 900 txfm_rd_in_plane(x, rate, distortion, skip, | 922 txfm_rd_in_plane(x, rate, distortion, skip, |
| 901 &sse[mbmi->tx_size], ref_best_rd, 0, bs, mbmi->tx_size); | 923 &sse[mbmi->tx_size], ref_best_rd, 0, bs, mbmi->tx_size); |
| 902 | 924 |
| 903 if (max_tx_size == TX_32X32 && best_tx == TX_32X32) { | 925 if (max_tx_size == TX_32X32 && best_tx == TX_32X32) { |
| 904 cpi->tx_stepdown_count[0]++; | 926 cpi->tx_stepdown_count[0]++; |
| 905 } else if (max_tx_size >= TX_16X16 && best_tx == TX_16X16) { | 927 } else if (max_tx_size >= TX_16X16 && best_tx == TX_16X16) { |
| 906 cpi->tx_stepdown_count[max_tx_size - TX_16X16]++; | 928 cpi->tx_stepdown_count[max_tx_size - TX_16X16]++; |
| 907 } else if (rd[TX_8X8][1] <= rd[TX_4X4][1]) { | 929 } else if (rd[TX_8X8][1] <= rd[TX_4X4][1]) { |
| 908 cpi->tx_stepdown_count[max_tx_size - TX_8X8]++; | 930 cpi->tx_stepdown_count[max_tx_size - TX_8X8]++; |
| 909 } else { | 931 } else { |
| 910 cpi->tx_stepdown_count[max_tx_size - TX_4X4]++; | 932 cpi->tx_stepdown_count[max_tx_size - TX_4X4]++; |
| 911 } | 933 } |
| 912 } | 934 } |
| 913 | 935 |
| 914 static void super_block_yrd(VP9_COMP *cpi, | 936 static void inter_super_block_yrd(VP9_COMP *cpi, MACROBLOCK *x, int *rate, |
| 915 MACROBLOCK *x, int *rate, int64_t *distortion, | 937 int64_t *distortion, int *skip, |
| 916 int *skip, int64_t *psse, BLOCK_SIZE bs, | 938 int64_t *psse, BLOCK_SIZE bs, |
| 917 int64_t txfm_cache[TX_MODES], | 939 int64_t txfm_cache[TX_MODES], |
| 918 int64_t ref_best_rd) { | 940 int64_t ref_best_rd) { |
| 919 int r[TX_SIZES][2], s[TX_SIZES]; | 941 int r[TX_SIZES][2], s[TX_SIZES]; |
| 920 int64_t d[TX_SIZES], sse[TX_SIZES]; | 942 int64_t d[TX_SIZES], sse[TX_SIZES]; |
| 921 MACROBLOCKD *xd = &x->e_mbd; | 943 MACROBLOCKD *xd = &x->e_mbd; |
| 922 MB_MODE_INFO *const mbmi = &xd->mi_8x8[0]->mbmi; | 944 MB_MODE_INFO *const mbmi = &xd->mi_8x8[0]->mbmi; |
| 923 const int b_inter_mode = is_inter_block(mbmi); | |
| 924 const TX_SIZE max_tx_size = max_txsize_lookup[bs]; | 945 const TX_SIZE max_tx_size = max_txsize_lookup[bs]; |
| 925 TX_SIZE tx_size; | 946 TX_SIZE tx_size; |
| 926 | 947 |
| 948 assert(bs == mbmi->sb_type); |
| 927 | 949 |
| 928 assert(bs == mbmi->sb_type); | 950 vp9_subtract_plane(x, bs, 0); |
| 929 if (b_inter_mode) | |
| 930 vp9_subtract_sby(x, bs); | |
| 931 | 951 |
| 932 if (cpi->sf.tx_size_search_method == USE_LARGESTALL || | 952 if (cpi->sf.tx_size_search_method == USE_LARGESTALL) { |
| 933 (cpi->sf.tx_size_search_method != USE_FULL_RD && | |
| 934 !b_inter_mode)) { | |
| 935 vpx_memset(txfm_cache, 0, TX_MODES * sizeof(int64_t)); | 953 vpx_memset(txfm_cache, 0, TX_MODES * sizeof(int64_t)); |
| 936 choose_largest_txfm_size(cpi, x, rate, distortion, skip, sse, | 954 choose_largest_txfm_size(cpi, x, rate, distortion, skip, sse, |
| 937 ref_best_rd, bs); | 955 ref_best_rd, bs); |
| 938 if (psse) | 956 if (psse) |
| 939 *psse = sse[mbmi->tx_size]; | 957 *psse = sse[mbmi->tx_size]; |
| 940 return; | 958 return; |
| 941 } | 959 } |
| 942 | 960 |
| 943 if (cpi->sf.tx_size_search_method == USE_LARGESTINTRA_MODELINTER && | 961 if (cpi->sf.tx_size_search_method == USE_LARGESTINTRA_MODELINTER) { |
| 944 b_inter_mode) { | |
| 945 for (tx_size = TX_4X4; tx_size <= max_tx_size; ++tx_size) | 962 for (tx_size = TX_4X4; tx_size <= max_tx_size; ++tx_size) |
| 946 model_rd_for_sb_y_tx(cpi, bs, tx_size, x, xd, | 963 model_rd_for_sb_y_tx(cpi, bs, tx_size, x, xd, |
| 947 &r[tx_size][0], &d[tx_size], &s[tx_size]); | 964 &r[tx_size][0], &d[tx_size], &s[tx_size]); |
| 948 choose_txfm_size_from_modelrd(cpi, x, r, rate, d, distortion, s, | 965 choose_txfm_size_from_modelrd(cpi, x, r, rate, d, distortion, s, |
| 949 skip, sse, ref_best_rd, bs); | 966 skip, sse, ref_best_rd, bs); |
| 950 } else { | 967 } else { |
| 951 for (tx_size = TX_4X4; tx_size <= max_tx_size; ++tx_size) | 968 for (tx_size = TX_4X4; tx_size <= max_tx_size; ++tx_size) |
| 952 txfm_rd_in_plane(x, &r[tx_size][0], &d[tx_size], | 969 txfm_rd_in_plane(x, &r[tx_size][0], &d[tx_size], |
| 953 &s[tx_size], &sse[tx_size], | 970 &s[tx_size], &sse[tx_size], |
| 954 ref_best_rd, 0, bs, tx_size); | 971 ref_best_rd, 0, bs, tx_size); |
| 955 choose_txfm_size_from_rd(cpi, x, r, rate, d, distortion, s, | 972 choose_txfm_size_from_rd(cpi, x, r, rate, d, distortion, s, |
| 956 skip, txfm_cache, bs); | 973 skip, txfm_cache, bs); |
| 957 } | 974 } |
| 958 if (psse) | 975 if (psse) |
| 959 *psse = sse[mbmi->tx_size]; | 976 *psse = sse[mbmi->tx_size]; |
| 960 } | 977 } |
| 961 | 978 |
| 979 static void intra_super_block_yrd(VP9_COMP *cpi, MACROBLOCK *x, int *rate, |
| 980 int64_t *distortion, int *skip, |
| 981 int64_t *psse, BLOCK_SIZE bs, |
| 982 int64_t txfm_cache[TX_MODES], |
| 983 int64_t ref_best_rd) { |
| 984 int64_t sse[TX_SIZES]; |
| 985 MACROBLOCKD *xd = &x->e_mbd; |
| 986 MB_MODE_INFO *const mbmi = &xd->mi_8x8[0]->mbmi; |
| 987 |
| 988 assert(bs == mbmi->sb_type); |
| 989 if (cpi->sf.tx_size_search_method != USE_FULL_RD) { |
| 990 vpx_memset(txfm_cache, 0, TX_MODES * sizeof(int64_t)); |
| 991 choose_largest_txfm_size(cpi, x, rate, distortion, skip, sse, |
| 992 ref_best_rd, bs); |
| 993 } else { |
| 994 int r[TX_SIZES][2], s[TX_SIZES]; |
| 995 int64_t d[TX_SIZES]; |
| 996 TX_SIZE tx_size; |
| 997 for (tx_size = TX_4X4; tx_size <= max_txsize_lookup[bs]; ++tx_size) |
| 998 txfm_rd_in_plane(x, &r[tx_size][0], &d[tx_size], |
| 999 &s[tx_size], &sse[tx_size], |
| 1000 ref_best_rd, 0, bs, tx_size); |
| 1001 choose_txfm_size_from_rd(cpi, x, r, rate, d, distortion, s, |
| 1002 skip, txfm_cache, bs); |
| 1003 } |
| 1004 if (psse) |
| 1005 *psse = sse[mbmi->tx_size]; |
| 1006 } |
| 1007 |
| 1008 |
| 962 static int conditional_skipintra(MB_PREDICTION_MODE mode, | 1009 static int conditional_skipintra(MB_PREDICTION_MODE mode, |
| 963 MB_PREDICTION_MODE best_intra_mode) { | 1010 MB_PREDICTION_MODE best_intra_mode) { |
| 964 if (mode == D117_PRED && | 1011 if (mode == D117_PRED && |
| 965 best_intra_mode != V_PRED && | 1012 best_intra_mode != V_PRED && |
| 966 best_intra_mode != D135_PRED) | 1013 best_intra_mode != D135_PRED) |
| 967 return 1; | 1014 return 1; |
| 968 if (mode == D63_PRED && | 1015 if (mode == D63_PRED && |
| 969 best_intra_mode != V_PRED && | 1016 best_intra_mode != V_PRED && |
| 970 best_intra_mode != D45_PRED) | 1017 best_intra_mode != D45_PRED) |
| 971 return 1; | 1018 return 1; |
| 972 if (mode == D207_PRED && | 1019 if (mode == D207_PRED && |
| 973 best_intra_mode != H_PRED && | 1020 best_intra_mode != H_PRED && |
| 974 best_intra_mode != D45_PRED) | 1021 best_intra_mode != D45_PRED) |
| 975 return 1; | 1022 return 1; |
| 976 if (mode == D153_PRED && | 1023 if (mode == D153_PRED && |
| 977 best_intra_mode != H_PRED && | 1024 best_intra_mode != H_PRED && |
| 978 best_intra_mode != D135_PRED) | 1025 best_intra_mode != D135_PRED) |
| 979 return 1; | 1026 return 1; |
| 980 return 0; | 1027 return 0; |
| 981 } | 1028 } |
| 982 | 1029 |
| 983 static int64_t rd_pick_intra4x4block(VP9_COMP *cpi, MACROBLOCK *x, int ib, | 1030 static int64_t rd_pick_intra4x4block(VP9_COMP *cpi, MACROBLOCK *x, int ib, |
| 984 MB_PREDICTION_MODE *best_mode, | 1031 MB_PREDICTION_MODE *best_mode, |
| 985 int *bmode_costs, | 1032 int *bmode_costs, |
| 986 ENTROPY_CONTEXT *a, ENTROPY_CONTEXT *l, | 1033 ENTROPY_CONTEXT *a, ENTROPY_CONTEXT *l, |
| 987 int *bestrate, int *bestratey, | 1034 int *bestrate, int *bestratey, |
| 988 int64_t *bestdistortion, | 1035 int64_t *bestdistortion, |
| 989 BLOCK_SIZE bsize, int64_t rd_thresh) { | 1036 BLOCK_SIZE bsize, int64_t rd_thresh) { |
| 990 MB_PREDICTION_MODE mode; | 1037 MB_PREDICTION_MODE mode; |
| 991 MACROBLOCKD *xd = &x->e_mbd; | 1038 MACROBLOCKD *const xd = &x->e_mbd; |
| 992 int64_t best_rd = rd_thresh; | 1039 int64_t best_rd = rd_thresh; |
| 993 int rate = 0; | 1040 |
| 994 int64_t distortion; | |
| 995 struct macroblock_plane *p = &x->plane[0]; | 1041 struct macroblock_plane *p = &x->plane[0]; |
| 996 struct macroblockd_plane *pd = &xd->plane[0]; | 1042 struct macroblockd_plane *pd = &xd->plane[0]; |
| 997 const int src_stride = p->src.stride; | 1043 const int src_stride = p->src.stride; |
| 998 const int dst_stride = pd->dst.stride; | 1044 const int dst_stride = pd->dst.stride; |
| 999 const uint8_t *src_init = &p->src.buf[raster_block_offset(BLOCK_8X8, ib, | 1045 const uint8_t *src_init = &p->src.buf[raster_block_offset(BLOCK_8X8, ib, |
| 1000 src_stride)]; | 1046 src_stride)]; |
| 1001 uint8_t *dst_init = &pd->dst.buf[raster_block_offset(BLOCK_8X8, ib, | 1047 uint8_t *dst_init = &pd->dst.buf[raster_block_offset(BLOCK_8X8, ib, |
| 1002 dst_stride)]; | 1048 dst_stride)]; |
| 1003 int16_t *src_diff, *coeff; | |
| 1004 | |
| 1005 ENTROPY_CONTEXT ta[2], tempa[2]; | 1049 ENTROPY_CONTEXT ta[2], tempa[2]; |
| 1006 ENTROPY_CONTEXT tl[2], templ[2]; | 1050 ENTROPY_CONTEXT tl[2], templ[2]; |
| 1007 | 1051 |
| 1008 const int num_4x4_blocks_wide = num_4x4_blocks_wide_lookup[bsize]; | 1052 const int num_4x4_blocks_wide = num_4x4_blocks_wide_lookup[bsize]; |
| 1009 const int num_4x4_blocks_high = num_4x4_blocks_high_lookup[bsize]; | 1053 const int num_4x4_blocks_high = num_4x4_blocks_high_lookup[bsize]; |
| 1010 int idx, idy; | 1054 int idx, idy; |
| 1011 uint8_t best_dst[8 * 8]; | 1055 uint8_t best_dst[8 * 8]; |
| 1012 | 1056 |
| 1013 assert(ib < 4); | 1057 assert(ib < 4); |
| 1014 | 1058 |
| 1015 vpx_memcpy(ta, a, sizeof(ta)); | 1059 vpx_memcpy(ta, a, sizeof(ta)); |
| 1016 vpx_memcpy(tl, l, sizeof(tl)); | 1060 vpx_memcpy(tl, l, sizeof(tl)); |
| 1017 xd->mi_8x8[0]->mbmi.tx_size = TX_4X4; | 1061 xd->mi_8x8[0]->mbmi.tx_size = TX_4X4; |
| 1018 | 1062 |
| 1019 for (mode = DC_PRED; mode <= TM_PRED; ++mode) { | 1063 for (mode = DC_PRED; mode <= TM_PRED; ++mode) { |
| 1020 int64_t this_rd; | 1064 int64_t this_rd; |
| 1021 int ratey = 0; | 1065 int ratey = 0; |
| 1066 int64_t distortion = 0; |
| 1067 int rate = bmode_costs[mode]; |
| 1022 | 1068 |
| 1023 if (!(cpi->sf.intra_y_mode_mask[TX_4X4] & (1 << mode))) | 1069 if (!(cpi->sf.intra_y_mode_mask[TX_4X4] & (1 << mode))) |
| 1024 continue; | 1070 continue; |
| 1025 | 1071 |
| 1026 // Only do the oblique modes if the best so far is | 1072 // Only do the oblique modes if the best so far is |
| 1027 // one of the neighboring directional modes | 1073 // one of the neighboring directional modes |
| 1028 if (cpi->sf.mode_search_skip_flags & FLAG_SKIP_INTRA_DIRMISMATCH) { | 1074 if (cpi->sf.mode_search_skip_flags & FLAG_SKIP_INTRA_DIRMISMATCH) { |
| 1029 if (conditional_skipintra(mode, *best_mode)) | 1075 if (conditional_skipintra(mode, *best_mode)) |
| 1030 continue; | 1076 continue; |
| 1031 } | 1077 } |
| 1032 | 1078 |
| 1033 rate = bmode_costs[mode]; | |
| 1034 distortion = 0; | |
| 1035 | |
| 1036 vpx_memcpy(tempa, ta, sizeof(ta)); | 1079 vpx_memcpy(tempa, ta, sizeof(ta)); |
| 1037 vpx_memcpy(templ, tl, sizeof(tl)); | 1080 vpx_memcpy(templ, tl, sizeof(tl)); |
| 1038 | 1081 |
| 1039 for (idy = 0; idy < num_4x4_blocks_high; ++idy) { | 1082 for (idy = 0; idy < num_4x4_blocks_high; ++idy) { |
| 1040 for (idx = 0; idx < num_4x4_blocks_wide; ++idx) { | 1083 for (idx = 0; idx < num_4x4_blocks_wide; ++idx) { |
| 1041 int64_t ssz; | |
| 1042 const scan_order *so; | |
| 1043 const uint8_t *src = src_init + idx * 4 + idy * 4 * src_stride; | |
| 1044 uint8_t *dst = dst_init + idx * 4 + idy * 4 * dst_stride; | |
| 1045 const int block = ib + idy * 2 + idx; | 1084 const int block = ib + idy * 2 + idx; |
| 1046 TX_TYPE tx_type; | 1085 const uint8_t *const src = &src_init[idx * 4 + idy * 4 * src_stride]; |
| 1086 uint8_t *const dst = &dst_init[idx * 4 + idy * 4 * dst_stride]; |
| 1087 int16_t *const src_diff = raster_block_offset_int16(BLOCK_8X8, block, |
| 1088 p->src_diff); |
| 1089 int16_t *const coeff = BLOCK_OFFSET(x->plane[0].coeff, block); |
| 1047 xd->mi_8x8[0]->bmi[block].as_mode = mode; | 1090 xd->mi_8x8[0]->bmi[block].as_mode = mode; |
| 1048 src_diff = raster_block_offset_int16(BLOCK_8X8, block, p->src_diff); | |
| 1049 coeff = BLOCK_OFFSET(x->plane[0].coeff, block); | |
| 1050 vp9_predict_intra_block(xd, block, 1, | 1091 vp9_predict_intra_block(xd, block, 1, |
| 1051 TX_4X4, mode, | 1092 TX_4X4, mode, |
| 1052 x->skip_encode ? src : dst, | 1093 x->skip_encode ? src : dst, |
| 1053 x->skip_encode ? src_stride : dst_stride, | 1094 x->skip_encode ? src_stride : dst_stride, |
| 1054 dst, dst_stride, idx, idy, 0); | 1095 dst, dst_stride, idx, idy, 0); |
| 1055 vp9_subtract_block(4, 4, src_diff, 8, | 1096 vp9_subtract_block(4, 4, src_diff, 8, src, src_stride, dst, dst_stride); |
| 1056 src, src_stride, | |
| 1057 dst, dst_stride); | |
| 1058 | 1097 |
| 1059 tx_type = get_tx_type_4x4(PLANE_TYPE_Y, xd, block); | 1098 if (xd->lossless) { |
| 1060 so = &vp9_scan_orders[TX_4X4][tx_type]; | 1099 const scan_order *so = &vp9_default_scan_orders[TX_4X4]; |
| 1061 | 1100 vp9_fwht4x4(src_diff, coeff, 8); |
| 1062 if (tx_type != DCT_DCT) | 1101 vp9_regular_quantize_b_4x4(x, 0, block, so->scan, so->iscan); |
| 1102 ratey += cost_coeffs(x, 0, block, tempa + idx, templ + idy, TX_4X4, |
| 1103 so->scan, so->neighbors); |
| 1104 if (RDCOST(x->rdmult, x->rddiv, ratey, distortion) >= best_rd) |
| 1105 goto next; |
| 1106 vp9_iwht4x4_add(BLOCK_OFFSET(pd->dqcoeff, block), dst, dst_stride, |
| 1107 p->eobs[block]); |
| 1108 } else { |
| 1109 int64_t unused; |
| 1110 const TX_TYPE tx_type = get_tx_type_4x4(PLANE_TYPE_Y, xd, block); |
| 1111 const scan_order *so = &vp9_scan_orders[TX_4X4][tx_type]; |
| 1063 vp9_fht4x4(src_diff, coeff, 8, tx_type); | 1112 vp9_fht4x4(src_diff, coeff, 8, tx_type); |
| 1064 else | 1113 vp9_regular_quantize_b_4x4(x, 0, block, so->scan, so->iscan); |
| 1065 x->fwd_txm4x4(src_diff, coeff, 8); | 1114 ratey += cost_coeffs(x, 0, block, tempa + idx, templ + idy, TX_4X4, |
| 1066 | 1115 so->scan, so->neighbors); |
| 1067 vp9_regular_quantize_b_4x4(x, 0, block, so->scan, so->iscan); | 1116 distortion += vp9_block_error(coeff, BLOCK_OFFSET(pd->dqcoeff, block), |
| 1068 | 1117 16, &unused) >> 2; |
| 1069 ratey += cost_coeffs(x, 0, block, tempa + idx, templ + idy, TX_4X4, | 1118 if (RDCOST(x->rdmult, x->rddiv, ratey, distortion) >= best_rd) |
| 1070 so->scan, so->neighbors); | 1119 goto next; |
| 1071 distortion += vp9_block_error(coeff, BLOCK_OFFSET(pd->dqcoeff, block), | 1120 vp9_iht4x4_add(tx_type, BLOCK_OFFSET(pd->dqcoeff, block), |
| 1072 16, &ssz) >> 2; | 1121 dst, dst_stride, p->eobs[block]); |
| 1073 if (RDCOST(x->rdmult, x->rddiv, ratey, distortion) >= best_rd) | 1122 } |
| 1074 goto next; | |
| 1075 | |
| 1076 if (tx_type != DCT_DCT) | |
| 1077 vp9_iht4x4_16_add(BLOCK_OFFSET(pd->dqcoeff, block), | |
| 1078 dst, pd->dst.stride, tx_type); | |
| 1079 else | |
| 1080 xd->itxm_add(BLOCK_OFFSET(pd->dqcoeff, block), dst, pd->dst.stride, | |
| 1081 16); | |
| 1082 } | 1123 } |
| 1083 } | 1124 } |
| 1084 | 1125 |
| 1085 rate += ratey; | 1126 rate += ratey; |
| 1086 this_rd = RDCOST(x->rdmult, x->rddiv, rate, distortion); | 1127 this_rd = RDCOST(x->rdmult, x->rddiv, rate, distortion); |
| 1087 | 1128 |
| 1088 if (this_rd < best_rd) { | 1129 if (this_rd < best_rd) { |
| 1089 *bestrate = rate; | 1130 *bestrate = rate; |
| 1090 *bestratey = ratey; | 1131 *bestratey = ratey; |
| 1091 *bestdistortion = distortion; | 1132 *bestdistortion = distortion; |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1212 continue; | 1253 continue; |
| 1213 | 1254 |
| 1214 if (cpi->common.frame_type == KEY_FRAME) { | 1255 if (cpi->common.frame_type == KEY_FRAME) { |
| 1215 const MB_PREDICTION_MODE A = vp9_above_block_mode(mic, above_mi, 0); | 1256 const MB_PREDICTION_MODE A = vp9_above_block_mode(mic, above_mi, 0); |
| 1216 const MB_PREDICTION_MODE L = vp9_left_block_mode(mic, left_mi, 0); | 1257 const MB_PREDICTION_MODE L = vp9_left_block_mode(mic, left_mi, 0); |
| 1217 | 1258 |
| 1218 bmode_costs = x->y_mode_costs[A][L]; | 1259 bmode_costs = x->y_mode_costs[A][L]; |
| 1219 } | 1260 } |
| 1220 mic->mbmi.mode = mode; | 1261 mic->mbmi.mode = mode; |
| 1221 | 1262 |
| 1222 super_block_yrd(cpi, x, &this_rate_tokenonly, &this_distortion, &s, NULL, | 1263 intra_super_block_yrd(cpi, x, &this_rate_tokenonly, &this_distortion, |
| 1223 bsize, local_tx_cache, best_rd); | 1264 &s, NULL, bsize, local_tx_cache, best_rd); |
| 1224 | 1265 |
| 1225 if (this_rate_tokenonly == INT_MAX) | 1266 if (this_rate_tokenonly == INT_MAX) |
| 1226 continue; | 1267 continue; |
| 1227 | 1268 |
| 1228 this_rate = this_rate_tokenonly + bmode_costs[mode]; | 1269 this_rate = this_rate_tokenonly + bmode_costs[mode]; |
| 1229 this_rd = RDCOST(x->rdmult, x->rddiv, this_rate, this_distortion); | 1270 this_rd = RDCOST(x->rdmult, x->rddiv, this_rate, this_distortion); |
| 1230 | 1271 |
| 1231 if (this_rd < best_rd) { | 1272 if (this_rd < best_rd) { |
| 1232 mode_selected = mode; | 1273 mode_selected = mode; |
| 1233 best_rd = this_rd; | 1274 best_rd = this_rd; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1248 } | 1289 } |
| 1249 } | 1290 } |
| 1250 } | 1291 } |
| 1251 | 1292 |
| 1252 mic->mbmi.mode = mode_selected; | 1293 mic->mbmi.mode = mode_selected; |
| 1253 mic->mbmi.tx_size = best_tx; | 1294 mic->mbmi.tx_size = best_tx; |
| 1254 | 1295 |
| 1255 return best_rd; | 1296 return best_rd; |
| 1256 } | 1297 } |
| 1257 | 1298 |
| 1258 static void super_block_uvrd(VP9_COMP *const cpi, MACROBLOCK *x, | 1299 static void super_block_uvrd(MACROBLOCK *x, |
| 1259 int *rate, int64_t *distortion, int *skippable, | 1300 int *rate, int64_t *distortion, int *skippable, |
| 1260 int64_t *sse, BLOCK_SIZE bsize, | 1301 int64_t *sse, BLOCK_SIZE bsize, |
| 1261 int64_t ref_best_rd) { | 1302 int64_t ref_best_rd) { |
| 1262 MACROBLOCKD *const xd = &x->e_mbd; | 1303 MACROBLOCKD *const xd = &x->e_mbd; |
| 1263 MB_MODE_INFO *const mbmi = &xd->mi_8x8[0]->mbmi; | 1304 MB_MODE_INFO *const mbmi = &xd->mi_8x8[0]->mbmi; |
| 1264 TX_SIZE uv_txfm_size = get_uv_tx_size(mbmi); | 1305 TX_SIZE uv_txfm_size = get_uv_tx_size(mbmi); |
| 1265 int plane; | 1306 int plane; |
| 1266 int pnrate = 0, pnskip = 1; | 1307 int pnrate = 0, pnskip = 1; |
| 1267 int64_t pndist = 0, pnsse = 0; | 1308 int64_t pndist = 0, pnsse = 0; |
| 1268 | 1309 |
| 1269 if (ref_best_rd < 0) | 1310 if (ref_best_rd < 0) |
| 1270 goto term; | 1311 goto term; |
| 1271 | 1312 |
| 1272 if (is_inter_block(mbmi)) | 1313 if (is_inter_block(mbmi)) { |
| 1273 vp9_subtract_sbuv(x, bsize); | 1314 int plane; |
| 1315 for (plane = 1; plane < MAX_MB_PLANE; ++plane) |
| 1316 vp9_subtract_plane(x, bsize, plane); |
| 1317 } |
| 1274 | 1318 |
| 1275 *rate = 0; | 1319 *rate = 0; |
| 1276 *distortion = 0; | 1320 *distortion = 0; |
| 1277 *sse = 0; | 1321 *sse = 0; |
| 1278 *skippable = 1; | 1322 *skippable = 1; |
| 1279 | 1323 |
| 1280 for (plane = 1; plane < MAX_MB_PLANE; ++plane) { | 1324 for (plane = 1; plane < MAX_MB_PLANE; ++plane) { |
| 1281 txfm_rd_in_plane(x, &pnrate, &pndist, &pnskip, &pnsse, | 1325 txfm_rd_in_plane(x, &pnrate, &pndist, &pnskip, &pnsse, |
| 1282 ref_best_rd, plane, bsize, uv_txfm_size); | 1326 ref_best_rd, plane, bsize, uv_txfm_size); |
| 1283 if (pnrate == INT_MAX) | 1327 if (pnrate == INT_MAX) |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1295 *sse = INT64_MAX; | 1339 *sse = INT64_MAX; |
| 1296 *skippable = 0; | 1340 *skippable = 0; |
| 1297 return; | 1341 return; |
| 1298 } | 1342 } |
| 1299 | 1343 |
| 1300 static int64_t rd_pick_intra_sbuv_mode(VP9_COMP *cpi, MACROBLOCK *x, | 1344 static int64_t rd_pick_intra_sbuv_mode(VP9_COMP *cpi, MACROBLOCK *x, |
| 1301 PICK_MODE_CONTEXT *ctx, | 1345 PICK_MODE_CONTEXT *ctx, |
| 1302 int *rate, int *rate_tokenonly, | 1346 int *rate, int *rate_tokenonly, |
| 1303 int64_t *distortion, int *skippable, | 1347 int64_t *distortion, int *skippable, |
| 1304 BLOCK_SIZE bsize, TX_SIZE max_tx_size) { | 1348 BLOCK_SIZE bsize, TX_SIZE max_tx_size) { |
| 1349 MACROBLOCKD *xd = &x->e_mbd; |
| 1305 MB_PREDICTION_MODE mode; | 1350 MB_PREDICTION_MODE mode; |
| 1306 MB_PREDICTION_MODE mode_selected = DC_PRED; | 1351 MB_PREDICTION_MODE mode_selected = DC_PRED; |
| 1307 int64_t best_rd = INT64_MAX, this_rd; | 1352 int64_t best_rd = INT64_MAX, this_rd; |
| 1308 int this_rate_tokenonly, this_rate, s; | 1353 int this_rate_tokenonly, this_rate, s; |
| 1309 int64_t this_distortion, this_sse; | 1354 int64_t this_distortion, this_sse; |
| 1310 | 1355 |
| 1311 for (mode = DC_PRED; mode <= TM_PRED; ++mode) { | 1356 for (mode = DC_PRED; mode <= TM_PRED; ++mode) { |
| 1312 if (!(cpi->sf.intra_uv_mode_mask[max_tx_size] & (1 << mode))) | 1357 if (!(cpi->sf.intra_uv_mode_mask[max_tx_size] & (1 << mode))) |
| 1313 continue; | 1358 continue; |
| 1314 | 1359 |
| 1315 x->e_mbd.mi_8x8[0]->mbmi.uv_mode = mode; | 1360 xd->mi_8x8[0]->mbmi.uv_mode = mode; |
| 1316 | 1361 |
| 1317 super_block_uvrd(cpi, x, &this_rate_tokenonly, | 1362 super_block_uvrd(x, &this_rate_tokenonly, |
| 1318 &this_distortion, &s, &this_sse, bsize, best_rd); | 1363 &this_distortion, &s, &this_sse, bsize, best_rd); |
| 1319 if (this_rate_tokenonly == INT_MAX) | 1364 if (this_rate_tokenonly == INT_MAX) |
| 1320 continue; | 1365 continue; |
| 1321 this_rate = this_rate_tokenonly + | 1366 this_rate = this_rate_tokenonly + |
| 1322 x->intra_uv_mode_cost[cpi->common.frame_type][mode]; | 1367 x->intra_uv_mode_cost[cpi->common.frame_type][mode]; |
| 1323 this_rd = RDCOST(x->rdmult, x->rddiv, this_rate, this_distortion); | 1368 this_rd = RDCOST(x->rdmult, x->rddiv, this_rate, this_distortion); |
| 1324 | 1369 |
| 1325 if (this_rd < best_rd) { | 1370 if (this_rd < best_rd) { |
| 1326 mode_selected = mode; | 1371 mode_selected = mode; |
| 1327 best_rd = this_rd; | 1372 best_rd = this_rd; |
| 1328 *rate = this_rate; | 1373 *rate = this_rate; |
| 1329 *rate_tokenonly = this_rate_tokenonly; | 1374 *rate_tokenonly = this_rate_tokenonly; |
| 1330 *distortion = this_distortion; | 1375 *distortion = this_distortion; |
| 1331 *skippable = s; | 1376 *skippable = s; |
| 1332 if (!x->select_txfm_size) { | 1377 if (!x->select_txfm_size) { |
| 1333 int i; | 1378 int i; |
| 1334 struct macroblock_plane *const p = x->plane; | 1379 struct macroblock_plane *const p = x->plane; |
| 1335 struct macroblockd_plane *const pd = x->e_mbd.plane; | 1380 struct macroblockd_plane *const pd = xd->plane; |
| 1336 for (i = 1; i < MAX_MB_PLANE; ++i) { | 1381 for (i = 1; i < MAX_MB_PLANE; ++i) { |
| 1337 p[i].coeff = ctx->coeff_pbuf[i][2]; | 1382 p[i].coeff = ctx->coeff_pbuf[i][2]; |
| 1338 p[i].qcoeff = ctx->qcoeff_pbuf[i][2]; | 1383 p[i].qcoeff = ctx->qcoeff_pbuf[i][2]; |
| 1339 pd[i].dqcoeff = ctx->dqcoeff_pbuf[i][2]; | 1384 pd[i].dqcoeff = ctx->dqcoeff_pbuf[i][2]; |
| 1340 p[i].eobs = ctx->eobs_pbuf[i][2]; | 1385 p[i].eobs = ctx->eobs_pbuf[i][2]; |
| 1341 | 1386 |
| 1342 ctx->coeff_pbuf[i][2] = ctx->coeff_pbuf[i][0]; | 1387 ctx->coeff_pbuf[i][2] = ctx->coeff_pbuf[i][0]; |
| 1343 ctx->qcoeff_pbuf[i][2] = ctx->qcoeff_pbuf[i][0]; | 1388 ctx->qcoeff_pbuf[i][2] = ctx->qcoeff_pbuf[i][0]; |
| 1344 ctx->dqcoeff_pbuf[i][2] = ctx->dqcoeff_pbuf[i][0]; | 1389 ctx->dqcoeff_pbuf[i][2] = ctx->dqcoeff_pbuf[i][0]; |
| 1345 ctx->eobs_pbuf[i][2] = ctx->eobs_pbuf[i][0]; | 1390 ctx->eobs_pbuf[i][2] = ctx->eobs_pbuf[i][0]; |
| 1346 | 1391 |
| 1347 ctx->coeff_pbuf[i][0] = p[i].coeff; | 1392 ctx->coeff_pbuf[i][0] = p[i].coeff; |
| 1348 ctx->qcoeff_pbuf[i][0] = p[i].qcoeff; | 1393 ctx->qcoeff_pbuf[i][0] = p[i].qcoeff; |
| 1349 ctx->dqcoeff_pbuf[i][0] = pd[i].dqcoeff; | 1394 ctx->dqcoeff_pbuf[i][0] = pd[i].dqcoeff; |
| 1350 ctx->eobs_pbuf[i][0] = p[i].eobs; | 1395 ctx->eobs_pbuf[i][0] = p[i].eobs; |
| 1351 } | 1396 } |
| 1352 } | 1397 } |
| 1353 } | 1398 } |
| 1354 } | 1399 } |
| 1355 | 1400 |
| 1356 x->e_mbd.mi_8x8[0]->mbmi.uv_mode = mode_selected; | 1401 xd->mi_8x8[0]->mbmi.uv_mode = mode_selected; |
| 1357 return best_rd; | 1402 return best_rd; |
| 1358 } | 1403 } |
| 1359 | 1404 |
| 1360 static int64_t rd_sbuv_dcpred(VP9_COMP *cpi, MACROBLOCK *x, | 1405 static int64_t rd_sbuv_dcpred(const VP9_COMMON *cm, MACROBLOCK *x, |
| 1361 int *rate, int *rate_tokenonly, | 1406 int *rate, int *rate_tokenonly, |
| 1362 int64_t *distortion, int *skippable, | 1407 int64_t *distortion, int *skippable, |
| 1363 BLOCK_SIZE bsize) { | 1408 BLOCK_SIZE bsize) { |
| 1364 int64_t this_rd; | 1409 int64_t unused; |
| 1365 int64_t this_sse; | |
| 1366 | 1410 |
| 1367 x->e_mbd.mi_8x8[0]->mbmi.uv_mode = DC_PRED; | 1411 x->e_mbd.mi_8x8[0]->mbmi.uv_mode = DC_PRED; |
| 1368 super_block_uvrd(cpi, x, rate_tokenonly, distortion, | 1412 super_block_uvrd(x, rate_tokenonly, distortion, |
| 1369 skippable, &this_sse, bsize, INT64_MAX); | 1413 skippable, &unused, bsize, INT64_MAX); |
| 1370 *rate = *rate_tokenonly + | 1414 *rate = *rate_tokenonly + x->intra_uv_mode_cost[cm->frame_type][DC_PRED]; |
| 1371 x->intra_uv_mode_cost[cpi->common.frame_type][DC_PRED]; | 1415 return RDCOST(x->rdmult, x->rddiv, *rate, *distortion); |
| 1372 this_rd = RDCOST(x->rdmult, x->rddiv, *rate, *distortion); | |
| 1373 | |
| 1374 return this_rd; | |
| 1375 } | 1416 } |
| 1376 | 1417 |
| 1377 static void choose_intra_uv_mode(VP9_COMP *cpi, PICK_MODE_CONTEXT *ctx, | 1418 static void choose_intra_uv_mode(VP9_COMP *cpi, PICK_MODE_CONTEXT *ctx, |
| 1378 BLOCK_SIZE bsize, TX_SIZE max_tx_size, | 1419 BLOCK_SIZE bsize, TX_SIZE max_tx_size, |
| 1379 int *rate_uv, int *rate_uv_tokenonly, | 1420 int *rate_uv, int *rate_uv_tokenonly, |
| 1380 int64_t *dist_uv, int *skip_uv, | 1421 int64_t *dist_uv, int *skip_uv, |
| 1381 MB_PREDICTION_MODE *mode_uv) { | 1422 MB_PREDICTION_MODE *mode_uv) { |
| 1382 MACROBLOCK *const x = &cpi->mb; | 1423 MACROBLOCK *const x = &cpi->mb; |
| 1383 | 1424 |
| 1384 // Use an estimated rd for uv_intra based on DC_PRED if the | 1425 // Use an estimated rd for uv_intra based on DC_PRED if the |
| 1385 // appropriate speed flag is set. | 1426 // appropriate speed flag is set. |
| 1386 if (cpi->sf.use_uv_intra_rd_estimate) { | 1427 if (cpi->sf.use_uv_intra_rd_estimate) { |
| 1387 rd_sbuv_dcpred(cpi, x, rate_uv, rate_uv_tokenonly, dist_uv, skip_uv, | 1428 rd_sbuv_dcpred(&cpi->common, x, rate_uv, rate_uv_tokenonly, dist_uv, |
| 1388 bsize < BLOCK_8X8 ? BLOCK_8X8 : bsize); | 1429 skip_uv, bsize < BLOCK_8X8 ? BLOCK_8X8 : bsize); |
| 1389 // Else do a proper rd search for each possible transform size that may | 1430 // Else do a proper rd search for each possible transform size that may |
| 1390 // be considered in the main rd loop. | 1431 // be considered in the main rd loop. |
| 1391 } else { | 1432 } else { |
| 1392 rd_pick_intra_sbuv_mode(cpi, x, ctx, | 1433 rd_pick_intra_sbuv_mode(cpi, x, ctx, |
| 1393 rate_uv, rate_uv_tokenonly, dist_uv, skip_uv, | 1434 rate_uv, rate_uv_tokenonly, dist_uv, skip_uv, |
| 1394 bsize < BLOCK_8X8 ? BLOCK_8X8 : bsize, max_tx_size); | 1435 bsize < BLOCK_8X8 ? BLOCK_8X8 : bsize, max_tx_size); |
| 1395 } | 1436 } |
| 1396 *mode_uv = x->e_mbd.mi_8x8[0]->mbmi.uv_mode; | 1437 *mode_uv = x->e_mbd.mi_8x8[0]->mbmi.uv_mode; |
| 1397 } | 1438 } |
| 1398 | 1439 |
| 1399 static int cost_mv_ref(VP9_COMP *cpi, MB_PREDICTION_MODE mode, | 1440 static int cost_mv_ref(VP9_COMP *cpi, MB_PREDICTION_MODE mode, |
| 1400 int mode_context) { | 1441 int mode_context) { |
| 1401 MACROBLOCK *const x = &cpi->mb; | 1442 MACROBLOCK *const x = &cpi->mb; |
| 1402 MACROBLOCKD *const xd = &x->e_mbd; | 1443 const int segment_id = x->e_mbd.mi_8x8[0]->mbmi.segment_id; |
| 1403 const int segment_id = xd->mi_8x8[0]->mbmi.segment_id; | |
| 1404 | 1444 |
| 1405 // Don't account for mode here if segment skip is enabled. | 1445 // Don't account for mode here if segment skip is enabled. |
| 1406 if (!vp9_segfeature_active(&cpi->common.seg, segment_id, SEG_LVL_SKIP)) { | 1446 if (!vp9_segfeature_active(&cpi->common.seg, segment_id, SEG_LVL_SKIP)) { |
| 1407 assert(is_inter_mode(mode)); | 1447 assert(is_inter_mode(mode)); |
| 1408 return x->inter_mode_cost[mode_context][INTER_OFFSET(mode)]; | 1448 return x->inter_mode_cost[mode_context][INTER_OFFSET(mode)]; |
| 1409 } else { | 1449 } else { |
| 1410 return 0; | 1450 return 0; |
| 1411 } | 1451 } |
| 1412 } | 1452 } |
| 1413 | 1453 |
| 1414 void vp9_set_mbmode_and_mvs(MACROBLOCKD *xd, MB_PREDICTION_MODE mode, | 1454 void vp9_set_mbmode_and_mvs(MACROBLOCKD *xd, MB_PREDICTION_MODE mode, |
| 1415 const MV *mv) { | 1455 const MV *mv) { |
| 1416 xd->mi_8x8[0]->mbmi.mode = mode; | 1456 xd->mi_8x8[0]->mbmi.mode = mode; |
| 1417 xd->mi_8x8[0]->mbmi.mv[0].as_mv = *mv; | 1457 xd->mi_8x8[0]->mbmi.mv[0].as_mv = *mv; |
| 1418 } | 1458 } |
| 1419 | 1459 |
| 1420 static void joint_motion_search(VP9_COMP *cpi, MACROBLOCK *x, | 1460 static void joint_motion_search(VP9_COMP *cpi, MACROBLOCK *x, |
| 1421 BLOCK_SIZE bsize, | 1461 BLOCK_SIZE bsize, |
| 1422 int_mv *frame_mv, | 1462 int_mv *frame_mv, |
| 1423 int mi_row, int mi_col, | 1463 int mi_row, int mi_col, |
| 1424 int_mv single_newmv[MAX_REF_FRAMES], | 1464 int_mv single_newmv[MAX_REF_FRAMES], |
| 1425 int *rate_mv); | 1465 int *rate_mv); |
| 1426 | 1466 |
| 1427 static int labels2mode(MACROBLOCK *x, int i, | 1467 static int labels2mode(MACROBLOCK *x, int i, |
| 1428 MB_PREDICTION_MODE this_mode, | 1468 MB_PREDICTION_MODE mode, |
| 1429 int_mv *this_mv, int_mv *this_second_mv, | 1469 int_mv *this_mv, int_mv *this_second_mv, |
| 1430 int_mv frame_mv[MB_MODE_COUNT][MAX_REF_FRAMES], | 1470 int_mv frame_mv[MB_MODE_COUNT][MAX_REF_FRAMES], |
| 1431 int_mv seg_mvs[MAX_REF_FRAMES], | 1471 int_mv seg_mvs[MAX_REF_FRAMES], |
| 1432 int_mv *best_ref_mv, | 1472 int_mv *best_ref_mv, |
| 1433 int_mv *second_best_ref_mv, | 1473 int_mv *second_best_ref_mv, |
| 1434 int *mvjcost, int *mvcost[2], VP9_COMP *cpi) { | 1474 int *mvjcost, int *mvcost[2], VP9_COMP *cpi) { |
| 1435 MACROBLOCKD *const xd = &x->e_mbd; | 1475 MACROBLOCKD *const xd = &x->e_mbd; |
| 1436 MODE_INFO *const mic = xd->mi_8x8[0]; | 1476 MODE_INFO *const mic = xd->mi_8x8[0]; |
| 1437 MB_MODE_INFO *mbmi = &mic->mbmi; | 1477 MB_MODE_INFO *mbmi = &mic->mbmi; |
| 1438 int cost = 0, thismvcost = 0; | 1478 int thismvcost = 0; |
| 1439 int idx, idy; | 1479 int idx, idy; |
| 1440 const int num_4x4_blocks_wide = num_4x4_blocks_wide_lookup[mbmi->sb_type]; | 1480 const int num_4x4_blocks_wide = num_4x4_blocks_wide_lookup[mbmi->sb_type]; |
| 1441 const int num_4x4_blocks_high = num_4x4_blocks_high_lookup[mbmi->sb_type]; | 1481 const int num_4x4_blocks_high = num_4x4_blocks_high_lookup[mbmi->sb_type]; |
| 1442 const int has_second_rf = has_second_ref(mbmi); | 1482 const int has_second_rf = has_second_ref(mbmi); |
| 1443 | 1483 |
| 1444 /* We have to be careful retrieving previously-encoded motion vectors. | |
| 1445 Ones from this macroblock have to be pulled from the BLOCKD array | |
| 1446 as they have not yet made it to the bmi array in our MB_MODE_INFO. */ | |
| 1447 MB_PREDICTION_MODE m; | |
| 1448 | |
| 1449 // the only time we should do costing for new motion vector or mode | 1484 // the only time we should do costing for new motion vector or mode |
| 1450 // is when we are on a new label (jbb May 08, 2007) | 1485 // is when we are on a new label (jbb May 08, 2007) |
| 1451 switch (m = this_mode) { | 1486 switch (mode) { |
| 1452 case NEWMV: | 1487 case NEWMV: |
| 1453 this_mv->as_int = seg_mvs[mbmi->ref_frame[0]].as_int; | 1488 this_mv->as_int = seg_mvs[mbmi->ref_frame[0]].as_int; |
| 1454 thismvcost = vp9_mv_bit_cost(&this_mv->as_mv, &best_ref_mv->as_mv, | 1489 thismvcost += vp9_mv_bit_cost(&this_mv->as_mv, &best_ref_mv->as_mv, |
| 1455 mvjcost, mvcost, MV_COST_WEIGHT_SUB); | 1490 mvjcost, mvcost, MV_COST_WEIGHT_SUB); |
| 1456 if (has_second_rf) { | 1491 if (has_second_rf) { |
| 1457 this_second_mv->as_int = seg_mvs[mbmi->ref_frame[1]].as_int; | 1492 this_second_mv->as_int = seg_mvs[mbmi->ref_frame[1]].as_int; |
| 1458 thismvcost += vp9_mv_bit_cost(&this_second_mv->as_mv, | 1493 thismvcost += vp9_mv_bit_cost(&this_second_mv->as_mv, |
| 1459 &second_best_ref_mv->as_mv, | 1494 &second_best_ref_mv->as_mv, |
| 1460 mvjcost, mvcost, MV_COST_WEIGHT_SUB); | 1495 mvjcost, mvcost, MV_COST_WEIGHT_SUB); |
| 1461 } | 1496 } |
| 1462 break; | 1497 break; |
| 1463 case NEARESTMV: | 1498 case NEARESTMV: |
| 1464 this_mv->as_int = frame_mv[NEARESTMV][mbmi->ref_frame[0]].as_int; | 1499 this_mv->as_int = frame_mv[NEARESTMV][mbmi->ref_frame[0]].as_int; |
| 1465 if (has_second_rf) | 1500 if (has_second_rf) |
| 1466 this_second_mv->as_int = | 1501 this_second_mv->as_int = frame_mv[NEARESTMV][mbmi->ref_frame[1]].as_int; |
| 1467 frame_mv[NEARESTMV][mbmi->ref_frame[1]].as_int; | |
| 1468 break; | 1502 break; |
| 1469 case NEARMV: | 1503 case NEARMV: |
| 1470 this_mv->as_int = frame_mv[NEARMV][mbmi->ref_frame[0]].as_int; | 1504 this_mv->as_int = frame_mv[NEARMV][mbmi->ref_frame[0]].as_int; |
| 1471 if (has_second_rf) | 1505 if (has_second_rf) |
| 1472 this_second_mv->as_int = | 1506 this_second_mv->as_int = frame_mv[NEARMV][mbmi->ref_frame[1]].as_int; |
| 1473 frame_mv[NEARMV][mbmi->ref_frame[1]].as_int; | |
| 1474 break; | 1507 break; |
| 1475 case ZEROMV: | 1508 case ZEROMV: |
| 1476 this_mv->as_int = 0; | 1509 this_mv->as_int = 0; |
| 1477 if (has_second_rf) | 1510 if (has_second_rf) |
| 1478 this_second_mv->as_int = 0; | 1511 this_second_mv->as_int = 0; |
| 1479 break; | 1512 break; |
| 1480 default: | 1513 default: |
| 1481 break; | 1514 break; |
| 1482 } | 1515 } |
| 1483 | 1516 |
| 1484 cost = cost_mv_ref(cpi, this_mode, | |
| 1485 mbmi->mode_context[mbmi->ref_frame[0]]); | |
| 1486 | |
| 1487 mic->bmi[i].as_mv[0].as_int = this_mv->as_int; | 1517 mic->bmi[i].as_mv[0].as_int = this_mv->as_int; |
| 1488 if (has_second_rf) | 1518 if (has_second_rf) |
| 1489 mic->bmi[i].as_mv[1].as_int = this_second_mv->as_int; | 1519 mic->bmi[i].as_mv[1].as_int = this_second_mv->as_int; |
| 1490 | 1520 |
| 1491 mic->bmi[i].as_mode = m; | 1521 mic->bmi[i].as_mode = mode; |
| 1492 | 1522 |
| 1493 for (idy = 0; idy < num_4x4_blocks_high; ++idy) | 1523 for (idy = 0; idy < num_4x4_blocks_high; ++idy) |
| 1494 for (idx = 0; idx < num_4x4_blocks_wide; ++idx) | 1524 for (idx = 0; idx < num_4x4_blocks_wide; ++idx) |
| 1495 vpx_memcpy(&mic->bmi[i + idy * 2 + idx], | 1525 vpx_memcpy(&mic->bmi[i + idy * 2 + idx], |
| 1496 &mic->bmi[i], sizeof(mic->bmi[i])); | 1526 &mic->bmi[i], sizeof(mic->bmi[i])); |
| 1497 | 1527 |
| 1498 cost += thismvcost; | 1528 return cost_mv_ref(cpi, mode, mbmi->mode_context[mbmi->ref_frame[0]]) + |
| 1499 return cost; | 1529 thismvcost; |
| 1500 } | 1530 } |
| 1501 | 1531 |
| 1502 static int64_t encode_inter_mb_segment(VP9_COMP *cpi, | 1532 static int64_t encode_inter_mb_segment(VP9_COMP *cpi, |
| 1503 MACROBLOCK *x, | 1533 MACROBLOCK *x, |
| 1504 int64_t best_yrd, | 1534 int64_t best_yrd, |
| 1505 int i, | 1535 int i, |
| 1506 int *labelyrate, | 1536 int *labelyrate, |
| 1507 int64_t *distortion, int64_t *sse, | 1537 int64_t *distortion, int64_t *sse, |
| 1508 ENTROPY_CONTEXT *ta, | 1538 ENTROPY_CONTEXT *ta, |
| 1509 ENTROPY_CONTEXT *tl, | 1539 ENTROPY_CONTEXT *tl, |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1580 int byrate; | 1610 int byrate; |
| 1581 int64_t bdist; | 1611 int64_t bdist; |
| 1582 int64_t bsse; | 1612 int64_t bsse; |
| 1583 int64_t brdcost; | 1613 int64_t brdcost; |
| 1584 int_mv mvs[2]; | 1614 int_mv mvs[2]; |
| 1585 ENTROPY_CONTEXT ta[2]; | 1615 ENTROPY_CONTEXT ta[2]; |
| 1586 ENTROPY_CONTEXT tl[2]; | 1616 ENTROPY_CONTEXT tl[2]; |
| 1587 } SEG_RDSTAT; | 1617 } SEG_RDSTAT; |
| 1588 | 1618 |
| 1589 typedef struct { | 1619 typedef struct { |
| 1590 int_mv *ref_mv, *second_ref_mv; | 1620 int_mv *ref_mv[2]; |
| 1591 int_mv mvp; | 1621 int_mv mvp; |
| 1592 | 1622 |
| 1593 int64_t segment_rd; | 1623 int64_t segment_rd; |
| 1594 int r; | 1624 int r; |
| 1595 int64_t d; | 1625 int64_t d; |
| 1596 int64_t sse; | 1626 int64_t sse; |
| 1597 int segment_yrate; | 1627 int segment_yrate; |
| 1598 MB_PREDICTION_MODE modes[4]; | 1628 MB_PREDICTION_MODE modes[4]; |
| 1599 SEG_RDSTAT rdstat[4][INTER_MODES]; | 1629 SEG_RDSTAT rdstat[4][INTER_MODES]; |
| 1600 int mvthresh; | 1630 int mvthresh; |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1691 &frame_mv[NEARMV][frame]); | 1721 &frame_mv[NEARMV][frame]); |
| 1692 } | 1722 } |
| 1693 | 1723 |
| 1694 // search for the best motion vector on this segment | 1724 // search for the best motion vector on this segment |
| 1695 for (this_mode = NEARESTMV; this_mode <= NEWMV; ++this_mode) { | 1725 for (this_mode = NEARESTMV; this_mode <= NEWMV; ++this_mode) { |
| 1696 const struct buf_2d orig_src = x->plane[0].src; | 1726 const struct buf_2d orig_src = x->plane[0].src; |
| 1697 struct buf_2d orig_pre[2]; | 1727 struct buf_2d orig_pre[2]; |
| 1698 | 1728 |
| 1699 mode_idx = INTER_OFFSET(this_mode); | 1729 mode_idx = INTER_OFFSET(this_mode); |
| 1700 bsi->rdstat[i][mode_idx].brdcost = INT64_MAX; | 1730 bsi->rdstat[i][mode_idx].brdcost = INT64_MAX; |
| 1731 if (cpi->sf.disable_inter_mode_mask[bsize] & (1 << mode_idx)) |
| 1732 continue; |
| 1701 | 1733 |
| 1702 // if we're near/nearest and mv == 0,0, compare to zeromv | 1734 // if we're near/nearest and mv == 0,0, compare to zeromv |
| 1703 if ((this_mode == NEARMV || this_mode == NEARESTMV || | 1735 if ((this_mode == NEARMV || this_mode == NEARESTMV || |
| 1704 this_mode == ZEROMV) && | 1736 this_mode == ZEROMV) && |
| 1705 frame_mv[this_mode][mbmi->ref_frame[0]].as_int == 0 && | 1737 frame_mv[this_mode][mbmi->ref_frame[0]].as_int == 0 && |
| 1706 (!has_second_rf || | 1738 (!has_second_rf || |
| 1707 frame_mv[this_mode][mbmi->ref_frame[1]].as_int == 0)) { | 1739 frame_mv[this_mode][mbmi->ref_frame[1]].as_int == 0)) { |
| 1708 int rfc = mbmi->mode_context[mbmi->ref_frame[0]]; | 1740 int rfc = mbmi->mode_context[mbmi->ref_frame[0]]; |
| 1709 int c1 = cost_mv_ref(cpi, NEARMV, rfc); | 1741 int c1 = cost_mv_ref(cpi, NEARMV, rfc); |
| 1710 int c2 = cost_mv_ref(cpi, NEARESTMV, rfc); | 1742 int c2 = cost_mv_ref(cpi, NEARESTMV, rfc); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1788 if (cpi->sf.adaptive_motion_search && cm->show_frame) { | 1820 if (cpi->sf.adaptive_motion_search && cm->show_frame) { |
| 1789 mvp_full.row = x->pred_mv[mbmi->ref_frame[0]].as_mv.row >> 3; | 1821 mvp_full.row = x->pred_mv[mbmi->ref_frame[0]].as_mv.row >> 3; |
| 1790 mvp_full.col = x->pred_mv[mbmi->ref_frame[0]].as_mv.col >> 3; | 1822 mvp_full.col = x->pred_mv[mbmi->ref_frame[0]].as_mv.col >> 3; |
| 1791 step_param = MAX(step_param, 8); | 1823 step_param = MAX(step_param, 8); |
| 1792 } | 1824 } |
| 1793 | 1825 |
| 1794 further_steps = (MAX_MVSEARCH_STEPS - 1) - step_param; | 1826 further_steps = (MAX_MVSEARCH_STEPS - 1) - step_param; |
| 1795 // adjust src pointer for this block | 1827 // adjust src pointer for this block |
| 1796 mi_buf_shift(x, i); | 1828 mi_buf_shift(x, i); |
| 1797 | 1829 |
| 1798 vp9_set_mv_search_range(x, &bsi->ref_mv->as_mv); | 1830 vp9_set_mv_search_range(x, &bsi->ref_mv[0]->as_mv); |
| 1799 | 1831 |
| 1800 if (cpi->sf.search_method == HEX) { | 1832 if (cpi->sf.search_method == HEX) { |
| 1801 bestsme = vp9_hex_search(x, &mvp_full, | 1833 bestsme = vp9_hex_search(x, &mvp_full, |
| 1802 step_param, | 1834 step_param, |
| 1803 sadpb, 1, v_fn_ptr, 1, | 1835 sadpb, 1, v_fn_ptr, 1, |
| 1804 &bsi->ref_mv->as_mv, | 1836 &bsi->ref_mv[0]->as_mv, |
| 1805 &new_mv->as_mv); | 1837 &new_mv->as_mv); |
| 1806 } else if (cpi->sf.search_method == SQUARE) { | 1838 } else if (cpi->sf.search_method == SQUARE) { |
| 1807 bestsme = vp9_square_search(x, &mvp_full, | 1839 bestsme = vp9_square_search(x, &mvp_full, |
| 1808 step_param, | 1840 step_param, |
| 1809 sadpb, 1, v_fn_ptr, 1, | 1841 sadpb, 1, v_fn_ptr, 1, |
| 1810 &bsi->ref_mv->as_mv, | 1842 &bsi->ref_mv[0]->as_mv, |
| 1811 &new_mv->as_mv); | 1843 &new_mv->as_mv); |
| 1812 } else if (cpi->sf.search_method == BIGDIA) { | 1844 } else if (cpi->sf.search_method == BIGDIA) { |
| 1813 bestsme = vp9_bigdia_search(x, &mvp_full, | 1845 bestsme = vp9_bigdia_search(x, &mvp_full, |
| 1814 step_param, | 1846 step_param, |
| 1815 sadpb, 1, v_fn_ptr, 1, | 1847 sadpb, 1, v_fn_ptr, 1, |
| 1816 &bsi->ref_mv->as_mv, | 1848 &bsi->ref_mv[0]->as_mv, |
| 1817 &new_mv->as_mv); | 1849 &new_mv->as_mv); |
| 1818 } else { | 1850 } else { |
| 1819 bestsme = vp9_full_pixel_diamond(cpi, x, &mvp_full, step_param, | 1851 bestsme = vp9_full_pixel_diamond(cpi, x, &mvp_full, step_param, |
| 1820 sadpb, further_steps, 0, v_fn_ptr, | 1852 sadpb, further_steps, 0, v_fn_ptr, |
| 1821 &bsi->ref_mv->as_mv, | 1853 &bsi->ref_mv[0]->as_mv, |
| 1822 &new_mv->as_mv); | 1854 &new_mv->as_mv); |
| 1823 } | 1855 } |
| 1824 | 1856 |
| 1825 // Should we do a full search (best quality only) | 1857 // Should we do a full search (best quality only) |
| 1826 if (cpi->oxcf.mode == MODE_BESTQUALITY || | 1858 if (cpi->oxcf.mode == MODE_BESTQUALITY || |
| 1827 cpi->oxcf.mode == MODE_SECONDPASS_BEST) { | 1859 cpi->oxcf.mode == MODE_SECONDPASS_BEST) { |
| 1860 int_mv *const best_mv = &mi->bmi[i].as_mv[0]; |
| 1828 /* Check if mvp_full is within the range. */ | 1861 /* Check if mvp_full is within the range. */ |
| 1829 clamp_mv(&mvp_full, x->mv_col_min, x->mv_col_max, | 1862 clamp_mv(&mvp_full, x->mv_col_min, x->mv_col_max, |
| 1830 x->mv_row_min, x->mv_row_max); | 1863 x->mv_row_min, x->mv_row_max); |
| 1831 | |
| 1832 thissme = cpi->full_search_sad(x, &mvp_full, | 1864 thissme = cpi->full_search_sad(x, &mvp_full, |
| 1833 sadpb, 16, v_fn_ptr, | 1865 sadpb, 16, v_fn_ptr, |
| 1834 x->nmvjointcost, x->mvcost, | 1866 x->nmvjointcost, x->mvcost, |
| 1835 &bsi->ref_mv->as_mv, i); | 1867 &bsi->ref_mv[0]->as_mv, |
| 1836 | 1868 &best_mv->as_mv); |
| 1837 if (thissme < bestsme) { | 1869 if (thissme < bestsme) { |
| 1838 bestsme = thissme; | 1870 bestsme = thissme; |
| 1839 new_mv->as_int = mi->bmi[i].as_mv[0].as_int; | 1871 new_mv->as_int = best_mv->as_int; |
| 1840 } else { | 1872 } else { |
| 1841 /* The full search result is actually worse so re-instate the | 1873 // The full search result is actually worse so re-instate the |
| 1842 * previous best vector */ | 1874 // previous best vector |
| 1843 mi->bmi[i].as_mv[0].as_int = new_mv->as_int; | 1875 best_mv->as_int = new_mv->as_int; |
| 1844 } | 1876 } |
| 1845 } | 1877 } |
| 1846 | 1878 |
| 1847 if (bestsme < INT_MAX) { | 1879 if (bestsme < INT_MAX) { |
| 1848 int distortion; | 1880 int distortion; |
| 1849 cpi->find_fractional_mv_step(x, | 1881 cpi->find_fractional_mv_step(x, |
| 1850 &new_mv->as_mv, | 1882 &new_mv->as_mv, |
| 1851 &bsi->ref_mv->as_mv, | 1883 &bsi->ref_mv[0]->as_mv, |
| 1852 cm->allow_high_precision_mv, | 1884 cm->allow_high_precision_mv, |
| 1853 x->errorperbit, v_fn_ptr, | 1885 x->errorperbit, v_fn_ptr, |
| 1854 cpi->sf.subpel_force_stop, | 1886 cpi->sf.subpel_force_stop, |
| 1855 cpi->sf.subpel_iters_per_step, | 1887 cpi->sf.subpel_iters_per_step, |
| 1856 x->nmvjointcost, x->mvcost, | 1888 x->nmvjointcost, x->mvcost, |
| 1857 &distortion, | 1889 &distortion, |
| 1858 &x->pred_sse[mbmi->ref_frame[0]]); | 1890 &x->pred_sse[mbmi->ref_frame[0]]); |
| 1859 | 1891 |
| 1860 // save motion search result for use in compound prediction | 1892 // save motion search result for use in compound prediction |
| 1861 seg_mvs[i][mbmi->ref_frame[0]].as_int = new_mv->as_int; | 1893 seg_mvs[i][mbmi->ref_frame[0]].as_int = new_mv->as_int; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 1888 seg_mvs[i][mbmi->ref_frame[1]].as_int = | 1920 seg_mvs[i][mbmi->ref_frame[1]].as_int = |
| 1889 frame_mv[this_mode][mbmi->ref_frame[1]].as_int; | 1921 frame_mv[this_mode][mbmi->ref_frame[1]].as_int; |
| 1890 } | 1922 } |
| 1891 // restore src pointers | 1923 // restore src pointers |
| 1892 mi_buf_restore(x, orig_src, orig_pre); | 1924 mi_buf_restore(x, orig_src, orig_pre); |
| 1893 } | 1925 } |
| 1894 | 1926 |
| 1895 bsi->rdstat[i][mode_idx].brate = | 1927 bsi->rdstat[i][mode_idx].brate = |
| 1896 labels2mode(x, i, this_mode, &mode_mv[this_mode], | 1928 labels2mode(x, i, this_mode, &mode_mv[this_mode], |
| 1897 &second_mode_mv[this_mode], frame_mv, seg_mvs[i], | 1929 &second_mode_mv[this_mode], frame_mv, seg_mvs[i], |
| 1898 bsi->ref_mv, bsi->second_ref_mv, x->nmvjointcost, | 1930 bsi->ref_mv[0], bsi->ref_mv[1], x->nmvjointcost, |
| 1899 x->mvcost, cpi); | 1931 x->mvcost, cpi); |
| 1900 | 1932 |
| 1901 | 1933 |
| 1902 bsi->rdstat[i][mode_idx].mvs[0].as_int = mode_mv[this_mode].as_int; | 1934 bsi->rdstat[i][mode_idx].mvs[0].as_int = mode_mv[this_mode].as_int; |
| 1903 if (num_4x4_blocks_wide > 1) | 1935 if (num_4x4_blocks_wide > 1) |
| 1904 bsi->rdstat[i + 1][mode_idx].mvs[0].as_int = | 1936 bsi->rdstat[i + 1][mode_idx].mvs[0].as_int = |
| 1905 mode_mv[this_mode].as_int; | 1937 mode_mv[this_mode].as_int; |
| 1906 if (num_4x4_blocks_high > 1) | 1938 if (num_4x4_blocks_high > 1) |
| 1907 bsi->rdstat[i + 2][mode_idx].mvs[0].as_int = | 1939 bsi->rdstat[i + 2][mode_idx].mvs[0].as_int = |
| 1908 mode_mv[this_mode].as_int; | 1940 mode_mv[this_mode].as_int; |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1997 bsi->segment_rd = INT64_MAX; | 2029 bsi->segment_rd = INT64_MAX; |
| 1998 return; | 2030 return; |
| 1999 } | 2031 } |
| 2000 | 2032 |
| 2001 mode_idx = INTER_OFFSET(mode_selected); | 2033 mode_idx = INTER_OFFSET(mode_selected); |
| 2002 vpx_memcpy(t_above, bsi->rdstat[i][mode_idx].ta, sizeof(t_above)); | 2034 vpx_memcpy(t_above, bsi->rdstat[i][mode_idx].ta, sizeof(t_above)); |
| 2003 vpx_memcpy(t_left, bsi->rdstat[i][mode_idx].tl, sizeof(t_left)); | 2035 vpx_memcpy(t_left, bsi->rdstat[i][mode_idx].tl, sizeof(t_left)); |
| 2004 | 2036 |
| 2005 labels2mode(x, i, mode_selected, &mode_mv[mode_selected], | 2037 labels2mode(x, i, mode_selected, &mode_mv[mode_selected], |
| 2006 &second_mode_mv[mode_selected], frame_mv, seg_mvs[i], | 2038 &second_mode_mv[mode_selected], frame_mv, seg_mvs[i], |
| 2007 bsi->ref_mv, bsi->second_ref_mv, x->nmvjointcost, | 2039 bsi->ref_mv[0], bsi->ref_mv[1], x->nmvjointcost, |
| 2008 x->mvcost, cpi); | 2040 x->mvcost, cpi); |
| 2009 | 2041 |
| 2010 br += bsi->rdstat[i][mode_idx].brate; | 2042 br += bsi->rdstat[i][mode_idx].brate; |
| 2011 bd += bsi->rdstat[i][mode_idx].bdist; | 2043 bd += bsi->rdstat[i][mode_idx].bdist; |
| 2012 block_sse += bsi->rdstat[i][mode_idx].bsse; | 2044 block_sse += bsi->rdstat[i][mode_idx].bsse; |
| 2013 segmentyrate += bsi->rdstat[i][mode_idx].byrate; | 2045 segmentyrate += bsi->rdstat[i][mode_idx].byrate; |
| 2014 this_segment_rd += bsi->rdstat[i][mode_idx].brdcost; | 2046 this_segment_rd += bsi->rdstat[i][mode_idx].brdcost; |
| 2015 | 2047 |
| 2016 if (this_segment_rd > bsi->segment_rd) { | 2048 if (this_segment_rd > bsi->segment_rd) { |
| 2017 int iy, midx; | 2049 int iy, midx; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2052 int i; | 2084 int i; |
| 2053 BEST_SEG_INFO *bsi = bsi_buf + filter_idx; | 2085 BEST_SEG_INFO *bsi = bsi_buf + filter_idx; |
| 2054 MACROBLOCKD *xd = &x->e_mbd; | 2086 MACROBLOCKD *xd = &x->e_mbd; |
| 2055 MODE_INFO *mi = xd->mi_8x8[0]; | 2087 MODE_INFO *mi = xd->mi_8x8[0]; |
| 2056 MB_MODE_INFO *mbmi = &mi->mbmi; | 2088 MB_MODE_INFO *mbmi = &mi->mbmi; |
| 2057 int mode_idx; | 2089 int mode_idx; |
| 2058 | 2090 |
| 2059 vp9_zero(*bsi); | 2091 vp9_zero(*bsi); |
| 2060 | 2092 |
| 2061 bsi->segment_rd = best_rd; | 2093 bsi->segment_rd = best_rd; |
| 2062 bsi->ref_mv = best_ref_mv; | 2094 bsi->ref_mv[0] = best_ref_mv; |
| 2063 bsi->second_ref_mv = second_best_ref_mv; | 2095 bsi->ref_mv[1] = second_best_ref_mv; |
| 2064 bsi->mvp.as_int = best_ref_mv->as_int; | 2096 bsi->mvp.as_int = best_ref_mv->as_int; |
| 2065 bsi->mvthresh = mvthresh; | 2097 bsi->mvthresh = mvthresh; |
| 2066 | 2098 |
| 2067 for (i = 0; i < 4; i++) | 2099 for (i = 0; i < 4; i++) |
| 2068 bsi->modes[i] = ZEROMV; | 2100 bsi->modes[i] = ZEROMV; |
| 2069 | 2101 |
| 2070 rd_check_segment_txsize(cpi, x, tile, bsi_buf, filter_idx, seg_mvs, | 2102 rd_check_segment_txsize(cpi, x, tile, bsi_buf, filter_idx, seg_mvs, |
| 2071 mi_row, mi_col); | 2103 mi_row, mi_col); |
| 2072 | 2104 |
| 2073 if (bsi->segment_rd > best_rd) | 2105 if (bsi->segment_rd > best_rd) |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2338 int_mv *tmp_mv, int *rate_mv) { | 2370 int_mv *tmp_mv, int *rate_mv) { |
| 2339 MACROBLOCKD *xd = &x->e_mbd; | 2371 MACROBLOCKD *xd = &x->e_mbd; |
| 2340 VP9_COMMON *cm = &cpi->common; | 2372 VP9_COMMON *cm = &cpi->common; |
| 2341 MB_MODE_INFO *mbmi = &xd->mi_8x8[0]->mbmi; | 2373 MB_MODE_INFO *mbmi = &xd->mi_8x8[0]->mbmi; |
| 2342 struct buf_2d backup_yv12[MAX_MB_PLANE] = {{0}}; | 2374 struct buf_2d backup_yv12[MAX_MB_PLANE] = {{0}}; |
| 2343 int bestsme = INT_MAX; | 2375 int bestsme = INT_MAX; |
| 2344 int further_steps, step_param; | 2376 int further_steps, step_param; |
| 2345 int sadpb = x->sadperbit16; | 2377 int sadpb = x->sadperbit16; |
| 2346 MV mvp_full; | 2378 MV mvp_full; |
| 2347 int ref = mbmi->ref_frame[0]; | 2379 int ref = mbmi->ref_frame[0]; |
| 2348 int_mv ref_mv = mbmi->ref_mvs[ref][0]; | 2380 MV ref_mv = mbmi->ref_mvs[ref][0].as_mv; |
| 2349 | 2381 |
| 2350 int tmp_col_min = x->mv_col_min; | 2382 int tmp_col_min = x->mv_col_min; |
| 2351 int tmp_col_max = x->mv_col_max; | 2383 int tmp_col_max = x->mv_col_max; |
| 2352 int tmp_row_min = x->mv_row_min; | 2384 int tmp_row_min = x->mv_row_min; |
| 2353 int tmp_row_max = x->mv_row_max; | 2385 int tmp_row_max = x->mv_row_max; |
| 2354 | 2386 |
| 2355 const YV12_BUFFER_CONFIG *scaled_ref_frame = vp9_get_scaled_ref_frame(cpi, | 2387 const YV12_BUFFER_CONFIG *scaled_ref_frame = vp9_get_scaled_ref_frame(cpi, |
| 2356 ref); | 2388 ref); |
| 2357 | 2389 |
| 2358 int_mv pred_mv[3]; | 2390 MV pred_mv[3]; |
| 2359 pred_mv[0] = mbmi->ref_mvs[ref][0]; | 2391 pred_mv[0] = mbmi->ref_mvs[ref][0].as_mv; |
| 2360 pred_mv[1] = mbmi->ref_mvs[ref][1]; | 2392 pred_mv[1] = mbmi->ref_mvs[ref][1].as_mv; |
| 2361 pred_mv[2] = x->pred_mv[ref]; | 2393 pred_mv[2] = x->pred_mv[ref].as_mv; |
| 2362 | 2394 |
| 2363 if (scaled_ref_frame) { | 2395 if (scaled_ref_frame) { |
| 2364 int i; | 2396 int i; |
| 2365 // Swap out the reference frame for a version that's been scaled to | 2397 // Swap out the reference frame for a version that's been scaled to |
| 2366 // match the resolution of the current frame, allowing the existing | 2398 // match the resolution of the current frame, allowing the existing |
| 2367 // motion search code to be used without additional modifications. | 2399 // motion search code to be used without additional modifications. |
| 2368 for (i = 0; i < MAX_MB_PLANE; i++) | 2400 for (i = 0; i < MAX_MB_PLANE; i++) |
| 2369 backup_yv12[i] = xd->plane[i].pre[0]; | 2401 backup_yv12[i] = xd->plane[i].pre[0]; |
| 2370 | 2402 |
| 2371 setup_pre_planes(xd, 0, scaled_ref_frame, mi_row, mi_col, NULL); | 2403 setup_pre_planes(xd, 0, scaled_ref_frame, mi_row, mi_col, NULL); |
| 2372 } | 2404 } |
| 2373 | 2405 |
| 2374 vp9_set_mv_search_range(x, &ref_mv.as_mv); | 2406 vp9_set_mv_search_range(x, &ref_mv); |
| 2375 | 2407 |
| 2376 // Work out the size of the first step in the mv step search. | 2408 // Work out the size of the first step in the mv step search. |
| 2377 // 0 here is maximum length first step. 1 is MAX >> 1 etc. | 2409 // 0 here is maximum length first step. 1 is MAX >> 1 etc. |
| 2378 if (cpi->sf.auto_mv_step_size && cpi->common.show_frame) { | 2410 if (cpi->sf.auto_mv_step_size && cpi->common.show_frame) { |
| 2379 // Take wtd average of the step_params based on the last frame's | 2411 // Take wtd average of the step_params based on the last frame's |
| 2380 // max mv magnitude and that based on the best ref mvs of the current | 2412 // max mv magnitude and that based on the best ref mvs of the current |
| 2381 // block for the given reference. | 2413 // block for the given reference. |
| 2382 step_param = (vp9_init_search_range(cpi, x->max_mv_context[ref]) + | 2414 step_param = (vp9_init_search_range(cpi, x->max_mv_context[ref]) + |
| 2383 cpi->mv_step_param) >> 1; | 2415 cpi->mv_step_param) >> 1; |
| 2384 } else { | 2416 } else { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 2409 if (scaled_ref_frame) { | 2441 if (scaled_ref_frame) { |
| 2410 int i; | 2442 int i; |
| 2411 for (i = 0; i < MAX_MB_PLANE; i++) | 2443 for (i = 0; i < MAX_MB_PLANE; i++) |
| 2412 xd->plane[i].pre[0] = backup_yv12[i]; | 2444 xd->plane[i].pre[0] = backup_yv12[i]; |
| 2413 } | 2445 } |
| 2414 return; | 2446 return; |
| 2415 } | 2447 } |
| 2416 } | 2448 } |
| 2417 } | 2449 } |
| 2418 | 2450 |
| 2419 mvp_full = pred_mv[x->mv_best_ref_index[ref]].as_mv; | 2451 mvp_full = pred_mv[x->mv_best_ref_index[ref]]; |
| 2420 | 2452 |
| 2421 mvp_full.col >>= 3; | 2453 mvp_full.col >>= 3; |
| 2422 mvp_full.row >>= 3; | 2454 mvp_full.row >>= 3; |
| 2423 | 2455 |
| 2424 // Further step/diamond searches as necessary | 2456 // Further step/diamond searches as necessary |
| 2425 further_steps = (cpi->sf.max_step_search_steps - 1) - step_param; | 2457 further_steps = (cpi->sf.max_step_search_steps - 1) - step_param; |
| 2426 | 2458 |
| 2427 if (cpi->sf.search_method == HEX) { | 2459 if (cpi->sf.search_method == FAST_HEX) { |
| 2460 bestsme = vp9_fast_hex_search(x, &mvp_full, step_param, sadpb, |
| 2461 &cpi->fn_ptr[bsize], 1, |
| 2462 &ref_mv, &tmp_mv->as_mv); |
| 2463 } else if (cpi->sf.search_method == HEX) { |
| 2428 bestsme = vp9_hex_search(x, &mvp_full, step_param, sadpb, 1, | 2464 bestsme = vp9_hex_search(x, &mvp_full, step_param, sadpb, 1, |
| 2429 &cpi->fn_ptr[bsize], 1, | 2465 &cpi->fn_ptr[bsize], 1, |
| 2430 &ref_mv.as_mv, &tmp_mv->as_mv); | 2466 &ref_mv, &tmp_mv->as_mv); |
| 2431 } else if (cpi->sf.search_method == SQUARE) { | 2467 } else if (cpi->sf.search_method == SQUARE) { |
| 2432 bestsme = vp9_square_search(x, &mvp_full, step_param, sadpb, 1, | 2468 bestsme = vp9_square_search(x, &mvp_full, step_param, sadpb, 1, |
| 2433 &cpi->fn_ptr[bsize], 1, | 2469 &cpi->fn_ptr[bsize], 1, |
| 2434 &ref_mv.as_mv, &tmp_mv->as_mv); | 2470 &ref_mv, &tmp_mv->as_mv); |
| 2435 } else if (cpi->sf.search_method == BIGDIA) { | 2471 } else if (cpi->sf.search_method == BIGDIA) { |
| 2436 bestsme = vp9_bigdia_search(x, &mvp_full, step_param, sadpb, 1, | 2472 bestsme = vp9_bigdia_search(x, &mvp_full, step_param, sadpb, 1, |
| 2437 &cpi->fn_ptr[bsize], 1, | 2473 &cpi->fn_ptr[bsize], 1, |
| 2438 &ref_mv.as_mv, &tmp_mv->as_mv); | 2474 &ref_mv, &tmp_mv->as_mv); |
| 2439 } else { | 2475 } else { |
| 2440 bestsme = vp9_full_pixel_diamond(cpi, x, &mvp_full, step_param, | 2476 bestsme = vp9_full_pixel_diamond(cpi, x, &mvp_full, step_param, |
| 2441 sadpb, further_steps, 1, | 2477 sadpb, further_steps, 1, |
| 2442 &cpi->fn_ptr[bsize], | 2478 &cpi->fn_ptr[bsize], |
| 2443 &ref_mv.as_mv, &tmp_mv->as_mv); | 2479 &ref_mv, &tmp_mv->as_mv); |
| 2444 } | 2480 } |
| 2445 | 2481 |
| 2446 x->mv_col_min = tmp_col_min; | 2482 x->mv_col_min = tmp_col_min; |
| 2447 x->mv_col_max = tmp_col_max; | 2483 x->mv_col_max = tmp_col_max; |
| 2448 x->mv_row_min = tmp_row_min; | 2484 x->mv_row_min = tmp_row_min; |
| 2449 x->mv_row_max = tmp_row_max; | 2485 x->mv_row_max = tmp_row_max; |
| 2450 | 2486 |
| 2451 if (bestsme < INT_MAX) { | 2487 if (bestsme < INT_MAX) { |
| 2452 int dis; /* TODO: use dis in distortion calculation later. */ | 2488 int dis; /* TODO: use dis in distortion calculation later. */ |
| 2453 cpi->find_fractional_mv_step(x, &tmp_mv->as_mv, &ref_mv.as_mv, | 2489 cpi->find_fractional_mv_step(x, &tmp_mv->as_mv, &ref_mv, |
| 2454 cm->allow_high_precision_mv, | 2490 cm->allow_high_precision_mv, |
| 2455 x->errorperbit, | 2491 x->errorperbit, |
| 2456 &cpi->fn_ptr[bsize], | 2492 &cpi->fn_ptr[bsize], |
| 2457 cpi->sf.subpel_force_stop, | 2493 cpi->sf.subpel_force_stop, |
| 2458 cpi->sf.subpel_iters_per_step, | 2494 cpi->sf.subpel_iters_per_step, |
| 2459 x->nmvjointcost, x->mvcost, | 2495 x->nmvjointcost, x->mvcost, |
| 2460 &dis, &x->pred_sse[ref]); | 2496 &dis, &x->pred_sse[ref]); |
| 2461 } | 2497 } |
| 2462 *rate_mv = vp9_mv_bit_cost(&tmp_mv->as_mv, &ref_mv.as_mv, | 2498 *rate_mv = vp9_mv_bit_cost(&tmp_mv->as_mv, &ref_mv, |
| 2463 x->nmvjointcost, x->mvcost, MV_COST_WEIGHT); | 2499 x->nmvjointcost, x->mvcost, MV_COST_WEIGHT); |
| 2464 | 2500 |
| 2465 if (cpi->sf.adaptive_motion_search && cpi->common.show_frame) | 2501 if (cpi->sf.adaptive_motion_search && cpi->common.show_frame) |
| 2466 x->pred_mv[ref].as_int = tmp_mv->as_int; | 2502 x->pred_mv[ref].as_int = tmp_mv->as_int; |
| 2467 | 2503 |
| 2468 if (scaled_ref_frame) { | 2504 if (scaled_ref_frame) { |
| 2469 int i; | 2505 int i; |
| 2470 for (i = 0; i < MAX_MB_PLANE; i++) | 2506 for (i = 0; i < MAX_MB_PLANE; i++) |
| 2471 xd->plane[i].pre[0] = backup_yv12[i]; | 2507 xd->plane[i].pre[0] = backup_yv12[i]; |
| 2472 } | 2508 } |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2679 x->nmvjointcost, x->mvcost, MV_COST_WEIGHT); | 2715 x->nmvjointcost, x->mvcost, MV_COST_WEIGHT); |
| 2680 rate_mv += vp9_mv_bit_cost(&frame_mv[refs[1]].as_mv, | 2716 rate_mv += vp9_mv_bit_cost(&frame_mv[refs[1]].as_mv, |
| 2681 &mbmi->ref_mvs[refs[1]][0].as_mv, | 2717 &mbmi->ref_mvs[refs[1]][0].as_mv, |
| 2682 x->nmvjointcost, x->mvcost, MV_COST_WEIGHT); | 2718 x->nmvjointcost, x->mvcost, MV_COST_WEIGHT); |
| 2683 } | 2719 } |
| 2684 *rate2 += rate_mv; | 2720 *rate2 += rate_mv; |
| 2685 } else { | 2721 } else { |
| 2686 int_mv tmp_mv; | 2722 int_mv tmp_mv; |
| 2687 single_motion_search(cpi, x, tile, bsize, mi_row, mi_col, | 2723 single_motion_search(cpi, x, tile, bsize, mi_row, mi_col, |
| 2688 &tmp_mv, &rate_mv); | 2724 &tmp_mv, &rate_mv); |
| 2725 if (tmp_mv.as_int == INVALID_MV) |
| 2726 return INT64_MAX; |
| 2689 *rate2 += rate_mv; | 2727 *rate2 += rate_mv; |
| 2690 frame_mv[refs[0]].as_int = | 2728 frame_mv[refs[0]].as_int = |
| 2691 xd->mi_8x8[0]->bmi[0].as_mv[0].as_int = tmp_mv.as_int; | 2729 xd->mi_8x8[0]->bmi[0].as_mv[0].as_int = tmp_mv.as_int; |
| 2692 single_newmv[refs[0]].as_int = tmp_mv.as_int; | 2730 single_newmv[refs[0]].as_int = tmp_mv.as_int; |
| 2693 } | 2731 } |
| 2694 } | 2732 } |
| 2695 | 2733 |
| 2696 // if we're near/nearest and mv == 0,0, compare to zeromv | |
| 2697 if ((this_mode == NEARMV || this_mode == NEARESTMV || this_mode == ZEROMV) && | |
| 2698 frame_mv[refs[0]].as_int == 0 && | |
| 2699 !vp9_segfeature_active(&cm->seg, mbmi->segment_id, SEG_LVL_SKIP) && | |
| 2700 (num_refs == 1 || frame_mv[refs[1]].as_int == 0)) { | |
| 2701 int rfc = mbmi->mode_context[mbmi->ref_frame[0]]; | |
| 2702 int c1 = cost_mv_ref(cpi, NEARMV, rfc); | |
| 2703 int c2 = cost_mv_ref(cpi, NEARESTMV, rfc); | |
| 2704 int c3 = cost_mv_ref(cpi, ZEROMV, rfc); | |
| 2705 | |
| 2706 if (this_mode == NEARMV) { | |
| 2707 if (c1 > c3) | |
| 2708 return INT64_MAX; | |
| 2709 } else if (this_mode == NEARESTMV) { | |
| 2710 if (c2 > c3) | |
| 2711 return INT64_MAX; | |
| 2712 } else { | |
| 2713 assert(this_mode == ZEROMV); | |
| 2714 if (num_refs == 1) { | |
| 2715 if ((c3 >= c2 && | |
| 2716 mode_mv[NEARESTMV][mbmi->ref_frame[0]].as_int == 0) || | |
| 2717 (c3 >= c1 && | |
| 2718 mode_mv[NEARMV][mbmi->ref_frame[0]].as_int == 0)) | |
| 2719 return INT64_MAX; | |
| 2720 } else { | |
| 2721 if ((c3 >= c2 && | |
| 2722 mode_mv[NEARESTMV][mbmi->ref_frame[0]].as_int == 0 && | |
| 2723 mode_mv[NEARESTMV][mbmi->ref_frame[1]].as_int == 0) || | |
| 2724 (c3 >= c1 && | |
| 2725 mode_mv[NEARMV][mbmi->ref_frame[0]].as_int == 0 && | |
| 2726 mode_mv[NEARMV][mbmi->ref_frame[1]].as_int == 0)) | |
| 2727 return INT64_MAX; | |
| 2728 } | |
| 2729 } | |
| 2730 } | |
| 2731 | |
| 2732 for (i = 0; i < num_refs; ++i) { | 2734 for (i = 0; i < num_refs; ++i) { |
| 2733 cur_mv[i] = frame_mv[refs[i]]; | 2735 cur_mv[i] = frame_mv[refs[i]]; |
| 2734 // Clip "next_nearest" so that it does not extend to far out of image | 2736 // Clip "next_nearest" so that it does not extend to far out of image |
| 2735 if (this_mode != NEWMV) | 2737 if (this_mode != NEWMV) |
| 2736 clamp_mv2(&cur_mv[i].as_mv, xd); | 2738 clamp_mv2(&cur_mv[i].as_mv, xd); |
| 2737 | 2739 |
| 2738 if (mv_check_bounds(x, &cur_mv[i].as_mv)) | 2740 if (mv_check_bounds(x, &cur_mv[i].as_mv)) |
| 2739 return INT64_MAX; | 2741 return INT64_MAX; |
| 2740 mbmi->mv[i].as_int = cur_mv[i].as_int; | 2742 mbmi->mv[i].as_int = cur_mv[i].as_int; |
| 2741 } | 2743 } |
| 2742 | 2744 |
| 2743 // do first prediction into the destination buffer. Do the next | 2745 // do first prediction into the destination buffer. Do the next |
| 2744 // prediction into a temporary buffer. Then keep track of which one | 2746 // prediction into a temporary buffer. Then keep track of which one |
| 2745 // of these currently holds the best predictor, and use the other | 2747 // of these currently holds the best predictor, and use the other |
| 2746 // one for future predictions. In the end, copy from tmp_buf to | 2748 // one for future predictions. In the end, copy from tmp_buf to |
| 2747 // dst if necessary. | 2749 // dst if necessary. |
| 2748 for (i = 0; i < MAX_MB_PLANE; i++) { | 2750 for (i = 0; i < MAX_MB_PLANE; i++) { |
| 2749 orig_dst[i] = xd->plane[i].dst.buf; | 2751 orig_dst[i] = xd->plane[i].dst.buf; |
| 2750 orig_dst_stride[i] = xd->plane[i].dst.stride; | 2752 orig_dst_stride[i] = xd->plane[i].dst.stride; |
| 2751 } | 2753 } |
| 2752 | 2754 |
| 2753 /* We don't include the cost of the second reference here, because there | 2755 /* We don't include the cost of the second reference here, because there |
| 2754 * are only three options: Last/Golden, ARF/Last or Golden/ARF, or in other | 2756 * are only three options: Last/Golden, ARF/Last or Golden/ARF, or in other |
| 2755 * words if you present them in that order, the second one is always known | 2757 * words if you present them in that order, the second one is always known |
| 2756 * if the first is known */ | 2758 * if the first is known */ |
| 2757 *rate2 += cost_mv_ref(cpi, this_mode, | 2759 *rate2 += cost_mv_ref(cpi, this_mode, mbmi->mode_context[refs[0]]); |
| 2758 mbmi->mode_context[mbmi->ref_frame[0]]); | |
| 2759 | 2760 |
| 2760 if (!(*mode_excluded)) | 2761 if (!(*mode_excluded)) |
| 2761 *mode_excluded = is_comp_pred ? cm->reference_mode == SINGLE_REFERENCE | 2762 *mode_excluded = is_comp_pred ? cm->reference_mode == SINGLE_REFERENCE |
| 2762 : cm->reference_mode == COMPOUND_REFERENCE; | 2763 : cm->reference_mode == COMPOUND_REFERENCE; |
| 2763 | 2764 |
| 2764 pred_exists = 0; | 2765 pred_exists = 0; |
| 2765 // Are all MVs integer pel for Y and UV | 2766 // Are all MVs integer pel for Y and UV |
| 2766 intpel_mv = !mv_has_subpel(&mbmi->mv[0].as_mv); | 2767 intpel_mv = !mv_has_subpel(&mbmi->mv[0].as_mv); |
| 2767 if (is_comp_pred) | 2768 if (is_comp_pred) |
| 2768 intpel_mv &= !mv_has_subpel(&mbmi->mv[1].as_mv); | 2769 intpel_mv &= !mv_has_subpel(&mbmi->mv[1].as_mv); |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2898 const BLOCK_SIZE y_size = get_plane_block_size(bsize, &xd->plane[0]); | 2899 const BLOCK_SIZE y_size = get_plane_block_size(bsize, &xd->plane[0]); |
| 2899 const BLOCK_SIZE uv_size = get_plane_block_size(bsize, &xd->plane[1]); | 2900 const BLOCK_SIZE uv_size = get_plane_block_size(bsize, &xd->plane[1]); |
| 2900 unsigned int var, sse; | 2901 unsigned int var, sse; |
| 2901 // Skipping threshold for ac. | 2902 // Skipping threshold for ac. |
| 2902 unsigned int thresh_ac; | 2903 unsigned int thresh_ac; |
| 2903 // Set a maximum for threshold to avoid big PSNR loss in low bitrate case. | 2904 // Set a maximum for threshold to avoid big PSNR loss in low bitrate case. |
| 2904 // Use extreme low threshold for static frames to limit skipping. | 2905 // Use extreme low threshold for static frames to limit skipping. |
| 2905 const unsigned int max_thresh = (cpi->allow_encode_breakout == | 2906 const unsigned int max_thresh = (cpi->allow_encode_breakout == |
| 2906 ENCODE_BREAKOUT_LIMITED) ? 128 : 36000; | 2907 ENCODE_BREAKOUT_LIMITED) ? 128 : 36000; |
| 2907 // The encode_breakout input | 2908 // The encode_breakout input |
| 2908 const unsigned int min_thresh = ((x->encode_breakout << 4) > max_thresh) ? | 2909 const unsigned int min_thresh = |
| 2909 max_thresh : (x->encode_breakout << 4); | 2910 MIN(((unsigned int)x->encode_breakout << 4), max_thresh); |
| 2910 | 2911 |
| 2911 // Calculate threshold according to dequant value. | 2912 // Calculate threshold according to dequant value. |
| 2912 thresh_ac = (xd->plane[0].dequant[1] * xd->plane[0].dequant[1]) / 9; | 2913 thresh_ac = (xd->plane[0].dequant[1] * xd->plane[0].dequant[1]) / 9; |
| 2913 thresh_ac = clamp(thresh_ac, min_thresh, max_thresh); | 2914 thresh_ac = clamp(thresh_ac, min_thresh, max_thresh); |
| 2914 | 2915 |
| 2915 var = cpi->fn_ptr[y_size].vf(x->plane[0].src.buf, x->plane[0].src.stride, | 2916 var = cpi->fn_ptr[y_size].vf(x->plane[0].src.buf, x->plane[0].src.stride, |
| 2916 xd->plane[0].dst.buf, | 2917 xd->plane[0].dst.buf, |
| 2917 xd->plane[0].dst.stride, &sse); | 2918 xd->plane[0].dst.stride, &sse); |
| 2918 | 2919 |
| 2919 // Adjust threshold according to partition size. | 2920 // Adjust threshold according to partition size. |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2966 } | 2967 } |
| 2967 } | 2968 } |
| 2968 } | 2969 } |
| 2969 | 2970 |
| 2970 if (!x->skip) { | 2971 if (!x->skip) { |
| 2971 int skippable_y, skippable_uv; | 2972 int skippable_y, skippable_uv; |
| 2972 int64_t sseuv = INT64_MAX; | 2973 int64_t sseuv = INT64_MAX; |
| 2973 int64_t rdcosty = INT64_MAX; | 2974 int64_t rdcosty = INT64_MAX; |
| 2974 | 2975 |
| 2975 // Y cost and distortion | 2976 // Y cost and distortion |
| 2976 super_block_yrd(cpi, x, rate_y, distortion_y, &skippable_y, psse, | 2977 inter_super_block_yrd(cpi, x, rate_y, distortion_y, &skippable_y, psse, |
| 2977 bsize, txfm_cache, ref_best_rd); | 2978 bsize, txfm_cache, ref_best_rd); |
| 2978 | 2979 |
| 2979 if (*rate_y == INT_MAX) { | 2980 if (*rate_y == INT_MAX) { |
| 2980 *rate2 = INT_MAX; | 2981 *rate2 = INT_MAX; |
| 2981 *distortion = INT64_MAX; | 2982 *distortion = INT64_MAX; |
| 2982 restore_dst_buf(xd, orig_dst, orig_dst_stride); | 2983 restore_dst_buf(xd, orig_dst, orig_dst_stride); |
| 2983 return INT64_MAX; | 2984 return INT64_MAX; |
| 2984 } | 2985 } |
| 2985 | 2986 |
| 2986 *rate2 += *rate_y; | 2987 *rate2 += *rate_y; |
| 2987 *distortion += *distortion_y; | 2988 *distortion += *distortion_y; |
| 2988 | 2989 |
| 2989 rdcosty = RDCOST(x->rdmult, x->rddiv, *rate2, *distortion); | 2990 rdcosty = RDCOST(x->rdmult, x->rddiv, *rate2, *distortion); |
| 2990 rdcosty = MIN(rdcosty, RDCOST(x->rdmult, x->rddiv, 0, *psse)); | 2991 rdcosty = MIN(rdcosty, RDCOST(x->rdmult, x->rddiv, 0, *psse)); |
| 2991 | 2992 |
| 2992 super_block_uvrd(cpi, x, rate_uv, distortion_uv, &skippable_uv, &sseuv, | 2993 super_block_uvrd(x, rate_uv, distortion_uv, &skippable_uv, &sseuv, |
| 2993 bsize, ref_best_rd - rdcosty); | 2994 bsize, ref_best_rd - rdcosty); |
| 2994 if (*rate_uv == INT_MAX) { | 2995 if (*rate_uv == INT_MAX) { |
| 2995 *rate2 = INT_MAX; | 2996 *rate2 = INT_MAX; |
| 2996 *distortion = INT64_MAX; | 2997 *distortion = INT64_MAX; |
| 2997 restore_dst_buf(xd, orig_dst, orig_dst_stride); | 2998 restore_dst_buf(xd, orig_dst, orig_dst_stride); |
| 2998 return INT64_MAX; | 2999 return INT64_MAX; |
| 2999 } | 3000 } |
| 3000 | 3001 |
| 3001 *psse += sseuv; | 3002 *psse += sseuv; |
| 3002 *rate2 += *rate_uv; | 3003 *rate2 += *rate_uv; |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3090 } | 3091 } |
| 3091 | 3092 |
| 3092 int64_t vp9_rd_pick_inter_mode_sb(VP9_COMP *cpi, MACROBLOCK *x, | 3093 int64_t vp9_rd_pick_inter_mode_sb(VP9_COMP *cpi, MACROBLOCK *x, |
| 3093 const TileInfo *const tile, | 3094 const TileInfo *const tile, |
| 3094 int mi_row, int mi_col, | 3095 int mi_row, int mi_col, |
| 3095 int *returnrate, | 3096 int *returnrate, |
| 3096 int64_t *returndistortion, | 3097 int64_t *returndistortion, |
| 3097 BLOCK_SIZE bsize, | 3098 BLOCK_SIZE bsize, |
| 3098 PICK_MODE_CONTEXT *ctx, | 3099 PICK_MODE_CONTEXT *ctx, |
| 3099 int64_t best_rd_so_far) { | 3100 int64_t best_rd_so_far) { |
| 3100 VP9_COMMON *cm = &cpi->common; | 3101 VP9_COMMON *const cm = &cpi->common; |
| 3101 MACROBLOCKD *xd = &x->e_mbd; | 3102 MACROBLOCKD *const xd = &x->e_mbd; |
| 3102 MB_MODE_INFO *mbmi = &xd->mi_8x8[0]->mbmi; | 3103 MB_MODE_INFO *const mbmi = &xd->mi_8x8[0]->mbmi; |
| 3103 const struct segmentation *seg = &cm->seg; | 3104 const struct segmentation *const seg = &cm->seg; |
| 3104 const BLOCK_SIZE block_size = get_plane_block_size(bsize, &xd->plane[0]); | 3105 const BLOCK_SIZE block_size = get_plane_block_size(bsize, &xd->plane[0]); |
| 3105 MB_PREDICTION_MODE this_mode; | 3106 MB_PREDICTION_MODE this_mode; |
| 3106 MV_REFERENCE_FRAME ref_frame, second_ref_frame; | 3107 MV_REFERENCE_FRAME ref_frame, second_ref_frame; |
| 3107 unsigned char segment_id = mbmi->segment_id; | 3108 unsigned char segment_id = mbmi->segment_id; |
| 3108 int comp_pred, i; | 3109 int comp_pred, i; |
| 3109 int_mv frame_mv[MB_MODE_COUNT][MAX_REF_FRAMES]; | 3110 int_mv frame_mv[MB_MODE_COUNT][MAX_REF_FRAMES]; |
| 3110 struct buf_2d yv12_mb[4][MAX_MB_PLANE]; | 3111 struct buf_2d yv12_mb[4][MAX_MB_PLANE]; |
| 3111 int_mv single_newmv[MAX_REF_FRAMES] = { { 0 } }; | 3112 int_mv single_newmv[MAX_REF_FRAMES] = { { 0 } }; |
| 3112 static const int flag_list[4] = { 0, VP9_LAST_FLAG, VP9_GOLD_FLAG, | 3113 static const int flag_list[4] = { 0, VP9_LAST_FLAG, VP9_GOLD_FLAG, |
| 3113 VP9_ALT_FLAG }; | 3114 VP9_ALT_FLAG }; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 3129 INTERP_FILTER tmp_best_filter = SWITCHABLE; | 3130 INTERP_FILTER tmp_best_filter = SWITCHABLE; |
| 3130 int rate_uv_intra[TX_SIZES], rate_uv_tokenonly[TX_SIZES]; | 3131 int rate_uv_intra[TX_SIZES], rate_uv_tokenonly[TX_SIZES]; |
| 3131 int64_t dist_uv[TX_SIZES]; | 3132 int64_t dist_uv[TX_SIZES]; |
| 3132 int skip_uv[TX_SIZES]; | 3133 int skip_uv[TX_SIZES]; |
| 3133 MB_PREDICTION_MODE mode_uv[TX_SIZES]; | 3134 MB_PREDICTION_MODE mode_uv[TX_SIZES]; |
| 3134 int64_t mode_distortions[MB_MODE_COUNT] = {-1}; | 3135 int64_t mode_distortions[MB_MODE_COUNT] = {-1}; |
| 3135 int intra_cost_penalty = 20 * vp9_dc_quant(cm->base_qindex, cm->y_dc_delta_q); | 3136 int intra_cost_penalty = 20 * vp9_dc_quant(cm->base_qindex, cm->y_dc_delta_q); |
| 3136 const int bws = num_8x8_blocks_wide_lookup[bsize] / 2; | 3137 const int bws = num_8x8_blocks_wide_lookup[bsize] / 2; |
| 3137 const int bhs = num_8x8_blocks_high_lookup[bsize] / 2; | 3138 const int bhs = num_8x8_blocks_high_lookup[bsize] / 2; |
| 3138 int best_skip2 = 0; | 3139 int best_skip2 = 0; |
| 3140 int mode_skip_mask = 0; |
| 3141 const int mode_skip_start = cpi->sf.mode_skip_start + 1; |
| 3142 const int *const rd_threshes = cpi->rd_threshes[segment_id][bsize]; |
| 3143 const int *const rd_thresh_freq_fact = cpi->rd_thresh_freq_fact[bsize]; |
| 3144 const int mode_search_skip_flags = cpi->sf.mode_search_skip_flags; |
| 3145 const int intra_y_mode_mask = |
| 3146 cpi->sf.intra_y_mode_mask[max_txsize_lookup[bsize]]; |
| 3139 | 3147 |
| 3140 x->skip_encode = cpi->sf.skip_encode_frame && x->q_index < QIDX_SKIP_THRESH; | 3148 x->skip_encode = cpi->sf.skip_encode_frame && x->q_index < QIDX_SKIP_THRESH; |
| 3141 | 3149 |
| 3142 // Everywhere the flag is set the error is much higher than its neighbors. | |
| 3143 ctx->modes_with_high_error = 0; | |
| 3144 | |
| 3145 estimate_ref_frame_costs(cpi, segment_id, ref_costs_single, ref_costs_comp, | 3150 estimate_ref_frame_costs(cpi, segment_id, ref_costs_single, ref_costs_comp, |
| 3146 &comp_mode_p); | 3151 &comp_mode_p); |
| 3147 | 3152 |
| 3148 for (i = 0; i < REFERENCE_MODES; ++i) | 3153 for (i = 0; i < REFERENCE_MODES; ++i) |
| 3149 best_pred_rd[i] = INT64_MAX; | 3154 best_pred_rd[i] = INT64_MAX; |
| 3150 for (i = 0; i < TX_MODES; i++) | 3155 for (i = 0; i < TX_MODES; i++) |
| 3151 best_tx_rd[i] = INT64_MAX; | 3156 best_tx_rd[i] = INT64_MAX; |
| 3152 for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; i++) | 3157 for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; i++) |
| 3153 best_filter_rd[i] = INT64_MAX; | 3158 best_filter_rd[i] = INT64_MAX; |
| 3154 for (i = 0; i < TX_SIZES; i++) | 3159 for (i = 0; i < TX_SIZES; i++) |
| 3155 rate_uv_intra[i] = INT_MAX; | 3160 rate_uv_intra[i] = INT_MAX; |
| 3156 for (i = 0; i < MAX_REF_FRAMES; ++i) | 3161 for (i = 0; i < MAX_REF_FRAMES; ++i) |
| 3157 x->pred_sse[i] = INT_MAX; | 3162 x->pred_sse[i] = INT_MAX; |
| 3158 | 3163 |
| 3159 *returnrate = INT_MAX; | 3164 *returnrate = INT_MAX; |
| 3160 | 3165 |
| 3161 for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) { | 3166 for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) { |
| 3162 x->pred_mv_sad[ref_frame] = INT_MAX; | 3167 x->pred_mv_sad[ref_frame] = INT_MAX; |
| 3163 if (cpi->ref_frame_flags & flag_list[ref_frame]) { | 3168 if (cpi->ref_frame_flags & flag_list[ref_frame]) { |
| 3164 vp9_setup_buffer_inter(cpi, x, tile, | 3169 vp9_setup_buffer_inter(cpi, x, tile, |
| 3165 ref_frame, block_size, mi_row, mi_col, | 3170 ref_frame, block_size, mi_row, mi_col, |
| 3166 frame_mv[NEARESTMV], frame_mv[NEARMV], yv12_mb); | 3171 frame_mv[NEARESTMV], frame_mv[NEARMV], yv12_mb); |
| 3167 } | 3172 } |
| 3168 frame_mv[NEWMV][ref_frame].as_int = INVALID_MV; | 3173 frame_mv[NEWMV][ref_frame].as_int = INVALID_MV; |
| 3169 frame_mv[ZEROMV][ref_frame].as_int = 0; | 3174 frame_mv[ZEROMV][ref_frame].as_int = 0; |
| 3170 } | 3175 } |
| 3171 | 3176 |
| 3172 cpi->ref_frame_mask = 0; | 3177 for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) { |
| 3173 for (ref_frame = LAST_FRAME; | 3178 // All modes from vp9_mode_order that use this frame as any ref |
| 3174 ref_frame <= ALTREF_FRAME && cpi->sf.reference_masking; ++ref_frame) { | 3179 static const int ref_frame_mask_all[] = { |
| 3175 int i; | 3180 0x0, 0x123291, 0x25c444, 0x39b722 |
| 3176 for (i = LAST_FRAME; i <= ALTREF_FRAME; ++i) { | 3181 }; |
| 3177 if ((x->pred_mv_sad[ref_frame] >> 2) > x->pred_mv_sad[i]) { | 3182 // Fixed mv modes (NEARESTMV, NEARMV, ZEROMV) from vp9_mode_order that use |
| 3178 cpi->ref_frame_mask |= (1 << ref_frame); | 3183 // this frame as their primary ref |
| 3179 break; | 3184 static const int ref_frame_mask_fixedmv[] = { |
| 3185 0x0, 0x121281, 0x24c404, 0x080102 |
| 3186 }; |
| 3187 if (!(cpi->ref_frame_flags & flag_list[ref_frame])) { |
| 3188 // Skip modes for missing references |
| 3189 mode_skip_mask |= ref_frame_mask_all[ref_frame]; |
| 3190 } else if (cpi->sf.reference_masking) { |
| 3191 for (i = LAST_FRAME; i <= ALTREF_FRAME; ++i) { |
| 3192 // Skip fixed mv modes for poor references |
| 3193 if ((x->pred_mv_sad[ref_frame] >> 2) > x->pred_mv_sad[i]) { |
| 3194 mode_skip_mask |= ref_frame_mask_fixedmv[ref_frame]; |
| 3195 break; |
| 3196 } |
| 3180 } | 3197 } |
| 3181 } | 3198 } |
| 3199 // If the segment reference frame feature is enabled.... |
| 3200 // then do nothing if the current ref frame is not allowed.. |
| 3201 if (vp9_segfeature_active(seg, segment_id, SEG_LVL_REF_FRAME) && |
| 3202 vp9_get_segdata(seg, segment_id, SEG_LVL_REF_FRAME) != (int)ref_frame) { |
| 3203 mode_skip_mask |= ref_frame_mask_all[ref_frame]; |
| 3204 } |
| 3205 } |
| 3206 |
| 3207 // If the segment skip feature is enabled.... |
| 3208 // then do nothing if the current mode is not allowed.. |
| 3209 if (vp9_segfeature_active(seg, segment_id, SEG_LVL_SKIP)) { |
| 3210 const int inter_non_zero_mode_mask = 0x1F7F7; |
| 3211 mode_skip_mask |= inter_non_zero_mode_mask; |
| 3212 } |
| 3213 |
| 3214 // Disable this drop out case if the ref frame |
| 3215 // segment level feature is enabled for this segment. This is to |
| 3216 // prevent the possibility that we end up unable to pick any mode. |
| 3217 if (!vp9_segfeature_active(seg, segment_id, SEG_LVL_REF_FRAME)) { |
| 3218 // Only consider ZEROMV/ALTREF_FRAME for alt ref frame, |
| 3219 // unless ARNR filtering is enabled in which case we want |
| 3220 // an unfiltered alternative. We allow near/nearest as well |
| 3221 // because they may result in zero-zero MVs but be cheaper. |
| 3222 if (cpi->rc.is_src_frame_alt_ref && (cpi->oxcf.arnr_max_frames == 0)) { |
| 3223 const int altref_zero_mask = |
| 3224 ~((1 << THR_NEARESTA) | (1 << THR_NEARA) | (1 << THR_ZEROA)); |
| 3225 mode_skip_mask |= altref_zero_mask; |
| 3226 if (frame_mv[NEARMV][ALTREF_FRAME].as_int != 0) |
| 3227 mode_skip_mask |= (1 << THR_NEARA); |
| 3228 if (frame_mv[NEARESTMV][ALTREF_FRAME].as_int != 0) |
| 3229 mode_skip_mask |= (1 << THR_NEARESTA); |
| 3230 } |
| 3231 } |
| 3232 |
| 3233 // TODO(JBB): This is to make up for the fact that we don't have sad |
| 3234 // functions that work when the block size reads outside the umv. We |
| 3235 // should fix this either by making the motion search just work on |
| 3236 // a representative block in the boundary ( first ) and then implement a |
| 3237 // function that does sads when inside the border.. |
| 3238 if ((mi_row + bhs) > cm->mi_rows || (mi_col + bws) > cm->mi_cols) { |
| 3239 const int new_modes_mask = |
| 3240 (1 << THR_NEWMV) | (1 << THR_NEWG) | (1 << THR_NEWA) | |
| 3241 (1 << THR_COMP_NEWLA) | (1 << THR_COMP_NEWGA); |
| 3242 mode_skip_mask |= new_modes_mask; |
| 3182 } | 3243 } |
| 3183 | 3244 |
| 3184 for (mode_index = 0; mode_index < MAX_MODES; ++mode_index) { | 3245 for (mode_index = 0; mode_index < MAX_MODES; ++mode_index) { |
| 3185 int mode_excluded = 0; | 3246 int mode_excluded = 0; |
| 3186 int64_t this_rd = INT64_MAX; | 3247 int64_t this_rd = INT64_MAX; |
| 3187 int disable_skip = 0; | 3248 int disable_skip = 0; |
| 3188 int compmode_cost = 0; | 3249 int compmode_cost = 0; |
| 3189 int rate2 = 0, rate_y = 0, rate_uv = 0; | 3250 int rate2 = 0, rate_y = 0, rate_uv = 0; |
| 3190 int64_t distortion2 = 0, distortion_y = 0, distortion_uv = 0; | 3251 int64_t distortion2 = 0, distortion_y = 0, distortion_uv = 0; |
| 3191 int skippable = 0; | 3252 int skippable = 0; |
| 3192 int64_t tx_cache[TX_MODES]; | 3253 int64_t tx_cache[TX_MODES]; |
| 3193 int i; | 3254 int i; |
| 3194 int this_skip2 = 0; | 3255 int this_skip2 = 0; |
| 3195 int64_t total_sse = INT_MAX; | 3256 int64_t total_sse = INT64_MAX; |
| 3196 int early_term = 0; | 3257 int early_term = 0; |
| 3197 | 3258 |
| 3198 for (i = 0; i < TX_MODES; ++i) | |
| 3199 tx_cache[i] = INT64_MAX; | |
| 3200 | |
| 3201 x->skip = 0; | |
| 3202 this_mode = vp9_mode_order[mode_index].mode; | |
| 3203 ref_frame = vp9_mode_order[mode_index].ref_frame[0]; | |
| 3204 second_ref_frame = vp9_mode_order[mode_index].ref_frame[1]; | |
| 3205 | |
| 3206 // Look at the reference frame of the best mode so far and set the | 3259 // Look at the reference frame of the best mode so far and set the |
| 3207 // skip mask to look at a subset of the remaining modes. | 3260 // skip mask to look at a subset of the remaining modes. |
| 3208 if (mode_index > cpi->sf.mode_skip_start) { | 3261 if (mode_index == mode_skip_start) { |
| 3209 if (mode_index == (cpi->sf.mode_skip_start + 1)) { | 3262 switch (vp9_mode_order[best_mode_index].ref_frame[0]) { |
| 3210 switch (vp9_mode_order[best_mode_index].ref_frame[0]) { | 3263 case INTRA_FRAME: |
| 3211 case INTRA_FRAME: | 3264 break; |
| 3212 cpi->mode_skip_mask = 0; | 3265 case LAST_FRAME: |
| 3213 break; | 3266 mode_skip_mask |= LAST_FRAME_MODE_MASK; |
| 3214 case LAST_FRAME: | 3267 break; |
| 3215 cpi->mode_skip_mask = LAST_FRAME_MODE_MASK; | 3268 case GOLDEN_FRAME: |
| 3216 break; | 3269 mode_skip_mask |= GOLDEN_FRAME_MODE_MASK; |
| 3217 case GOLDEN_FRAME: | 3270 break; |
| 3218 cpi->mode_skip_mask = GOLDEN_FRAME_MODE_MASK; | 3271 case ALTREF_FRAME: |
| 3219 break; | 3272 mode_skip_mask |= ALT_REF_MODE_MASK; |
| 3220 case ALTREF_FRAME: | 3273 break; |
| 3221 cpi->mode_skip_mask = ALT_REF_MODE_MASK; | 3274 case NONE: |
| 3222 break; | 3275 case MAX_REF_FRAMES: |
| 3223 case NONE: | 3276 assert(0 && "Invalid Reference frame"); |
| 3224 case MAX_REF_FRAMES: | |
| 3225 assert(0 && "Invalid Reference frame"); | |
| 3226 } | |
| 3227 } | 3277 } |
| 3228 if (cpi->mode_skip_mask & ((int64_t)1 << mode_index)) | |
| 3229 continue; | |
| 3230 } | 3278 } |
| 3231 | 3279 if (mode_skip_mask & (1 << mode_index)) |
| 3232 // Skip if the current reference frame has been masked off | |
| 3233 if (cpi->ref_frame_mask & (1 << ref_frame) && this_mode != NEWMV) | |
| 3234 continue; | 3280 continue; |
| 3235 | 3281 |
| 3236 // Test best rd so far against threshold for trying this mode. | 3282 // Test best rd so far against threshold for trying this mode. |
| 3237 if ((best_rd < ((int64_t)cpi->rd_threshes[segment_id][bsize][mode_index] * | 3283 if (best_rd < ((int64_t)rd_threshes[mode_index] * |
| 3238 cpi->rd_thresh_freq_fact[bsize][mode_index] >> 5)) || | 3284 rd_thresh_freq_fact[mode_index] >> 5) || |
| 3239 cpi->rd_threshes[segment_id][bsize][mode_index] == INT_MAX) | 3285 rd_threshes[mode_index] == INT_MAX) |
| 3286 continue; |
| 3287 |
| 3288 this_mode = vp9_mode_order[mode_index].mode; |
| 3289 ref_frame = vp9_mode_order[mode_index].ref_frame[0]; |
| 3290 if (ref_frame != INTRA_FRAME && |
| 3291 cpi->sf.disable_inter_mode_mask[bsize] & (1 << INTER_OFFSET(this_mode))) |
| 3240 continue; | 3292 continue; |
| 3241 | 3293 second_ref_frame = vp9_mode_order[mode_index].ref_frame[1]; |
| 3242 // Do not allow compound prediction if the segment level reference | |
| 3243 // frame feature is in use as in this case there can only be one reference. | |
| 3244 if ((second_ref_frame > INTRA_FRAME) && | |
| 3245 vp9_segfeature_active(seg, segment_id, SEG_LVL_REF_FRAME)) | |
| 3246 continue; | |
| 3247 | |
| 3248 mbmi->ref_frame[0] = ref_frame; | |
| 3249 mbmi->ref_frame[1] = second_ref_frame; | |
| 3250 | |
| 3251 if (!(ref_frame == INTRA_FRAME | |
| 3252 || (cpi->ref_frame_flags & flag_list[ref_frame]))) { | |
| 3253 continue; | |
| 3254 } | |
| 3255 if (!(second_ref_frame == NONE | |
| 3256 || (cpi->ref_frame_flags & flag_list[second_ref_frame]))) { | |
| 3257 continue; | |
| 3258 } | |
| 3259 | 3294 |
| 3260 comp_pred = second_ref_frame > INTRA_FRAME; | 3295 comp_pred = second_ref_frame > INTRA_FRAME; |
| 3261 if (comp_pred) { | 3296 if (comp_pred) { |
| 3262 if (cpi->sf.mode_search_skip_flags & FLAG_SKIP_COMP_BESTINTRA) | 3297 if ((mode_search_skip_flags & FLAG_SKIP_COMP_BESTINTRA) && |
| 3263 if (vp9_mode_order[best_mode_index].ref_frame[0] == INTRA_FRAME) | 3298 vp9_mode_order[best_mode_index].ref_frame[0] == INTRA_FRAME) |
| 3264 continue; | 3299 continue; |
| 3265 if (cpi->sf.mode_search_skip_flags & FLAG_SKIP_COMP_REFMISMATCH) | 3300 if ((mode_search_skip_flags & FLAG_SKIP_COMP_REFMISMATCH) && |
| 3266 if (ref_frame != best_inter_ref_frame && | 3301 ref_frame != best_inter_ref_frame && |
| 3267 second_ref_frame != best_inter_ref_frame) | 3302 second_ref_frame != best_inter_ref_frame) |
| 3268 continue; | 3303 continue; |
| 3304 mode_excluded = cm->reference_mode == SINGLE_REFERENCE; |
| 3305 } else { |
| 3306 if (ref_frame != INTRA_FRAME) |
| 3307 mode_excluded = cm->reference_mode == COMPOUND_REFERENCE; |
| 3269 } | 3308 } |
| 3270 | 3309 |
| 3271 set_ref_ptrs(cm, xd, ref_frame, second_ref_frame); | 3310 if (ref_frame == INTRA_FRAME) { |
| 3311 if (!(intra_y_mode_mask & (1 << this_mode))) |
| 3312 continue; |
| 3313 if (this_mode != DC_PRED) { |
| 3314 // Disable intra modes other than DC_PRED for blocks with low variance |
| 3315 // Threshold for intra skipping based on source variance |
| 3316 // TODO(debargha): Specialize the threshold for super block sizes |
| 3317 const unsigned int skip_intra_var_thresh = 64; |
| 3318 if ((mode_search_skip_flags & FLAG_SKIP_INTRA_LOWVAR) && |
| 3319 x->source_variance < skip_intra_var_thresh) |
| 3320 continue; |
| 3321 // Only search the oblique modes if the best so far is |
| 3322 // one of the neighboring directional modes |
| 3323 if ((mode_search_skip_flags & FLAG_SKIP_INTRA_BESTINTER) && |
| 3324 (this_mode >= D45_PRED && this_mode <= TM_PRED)) { |
| 3325 if (vp9_mode_order[best_mode_index].ref_frame[0] > INTRA_FRAME) |
| 3326 continue; |
| 3327 } |
| 3328 if (mode_search_skip_flags & FLAG_SKIP_INTRA_DIRMISMATCH) { |
| 3329 if (conditional_skipintra(this_mode, best_intra_mode)) |
| 3330 continue; |
| 3331 } |
| 3332 } |
| 3333 } else { |
| 3334 // if we're near/nearest and mv == 0,0, compare to zeromv |
| 3335 if ((this_mode == NEARMV || this_mode == NEARESTMV || |
| 3336 this_mode == ZEROMV) && |
| 3337 frame_mv[this_mode][ref_frame].as_int == 0 && |
| 3338 !vp9_segfeature_active(&cm->seg, mbmi->segment_id, SEG_LVL_SKIP) && |
| 3339 (!comp_pred || frame_mv[this_mode][second_ref_frame].as_int == 0)) { |
| 3340 int rfc = mbmi->mode_context[ref_frame]; |
| 3341 int c1 = cost_mv_ref(cpi, NEARMV, rfc); |
| 3342 int c2 = cost_mv_ref(cpi, NEARESTMV, rfc); |
| 3343 int c3 = cost_mv_ref(cpi, ZEROMV, rfc); |
| 3344 |
| 3345 if (this_mode == NEARMV) { |
| 3346 if (c1 > c3) |
| 3347 continue; |
| 3348 } else if (this_mode == NEARESTMV) { |
| 3349 if (c2 > c3) |
| 3350 continue; |
| 3351 } else { |
| 3352 assert(this_mode == ZEROMV); |
| 3353 if (!comp_pred) { |
| 3354 if ((c3 >= c2 && |
| 3355 frame_mv[NEARESTMV][ref_frame].as_int == 0) || |
| 3356 (c3 >= c1 && |
| 3357 frame_mv[NEARMV][ref_frame].as_int == 0)) |
| 3358 continue; |
| 3359 } else { |
| 3360 if ((c3 >= c2 && |
| 3361 frame_mv[NEARESTMV][ref_frame].as_int == 0 && |
| 3362 frame_mv[NEARESTMV][second_ref_frame].as_int == 0) || |
| 3363 (c3 >= c1 && |
| 3364 frame_mv[NEARMV][ref_frame].as_int == 0 && |
| 3365 frame_mv[NEARMV][second_ref_frame].as_int == 0)) |
| 3366 continue; |
| 3367 } |
| 3368 } |
| 3369 } |
| 3370 } |
| 3371 |
| 3372 mbmi->mode = this_mode; |
| 3272 mbmi->uv_mode = DC_PRED; | 3373 mbmi->uv_mode = DC_PRED; |
| 3273 | 3374 mbmi->ref_frame[0] = ref_frame; |
| 3375 mbmi->ref_frame[1] = second_ref_frame; |
| 3274 // Evaluate all sub-pel filters irrespective of whether we can use | 3376 // Evaluate all sub-pel filters irrespective of whether we can use |
| 3275 // them for this frame. | 3377 // them for this frame. |
| 3276 mbmi->interp_filter = cm->interp_filter == SWITCHABLE ? EIGHTTAP | 3378 mbmi->interp_filter = cm->interp_filter == SWITCHABLE ? EIGHTTAP |
| 3277 : cm->interp_filter; | 3379 : cm->interp_filter; |
| 3380 x->skip = 0; |
| 3381 set_ref_ptrs(cm, xd, ref_frame, second_ref_frame); |
| 3278 xd->interp_kernel = vp9_get_interp_kernel(mbmi->interp_filter); | 3382 xd->interp_kernel = vp9_get_interp_kernel(mbmi->interp_filter); |
| 3279 | 3383 |
| 3280 if (comp_pred) { | |
| 3281 if (!(cpi->ref_frame_flags & flag_list[second_ref_frame])) | |
| 3282 continue; | |
| 3283 | |
| 3284 mode_excluded = mode_excluded ? mode_excluded | |
| 3285 : cm->reference_mode == SINGLE_REFERENCE; | |
| 3286 } else { | |
| 3287 if (ref_frame != INTRA_FRAME && second_ref_frame != INTRA_FRAME) | |
| 3288 mode_excluded = mode_excluded ? | |
| 3289 mode_excluded : cm->reference_mode == COMPOUND_REFERENCE; | |
| 3290 } | |
| 3291 | |
| 3292 // Select prediction reference frames. | 3384 // Select prediction reference frames. |
| 3293 for (i = 0; i < MAX_MB_PLANE; i++) { | 3385 for (i = 0; i < MAX_MB_PLANE; i++) { |
| 3294 xd->plane[i].pre[0] = yv12_mb[ref_frame][i]; | 3386 xd->plane[i].pre[0] = yv12_mb[ref_frame][i]; |
| 3295 if (comp_pred) | 3387 if (comp_pred) |
| 3296 xd->plane[i].pre[1] = yv12_mb[second_ref_frame][i]; | 3388 xd->plane[i].pre[1] = yv12_mb[second_ref_frame][i]; |
| 3297 } | 3389 } |
| 3298 | 3390 |
| 3299 // If the segment reference frame feature is enabled.... | 3391 for (i = 0; i < TX_MODES; ++i) |
| 3300 // then do nothing if the current ref frame is not allowed.. | 3392 tx_cache[i] = INT64_MAX; |
| 3301 if (vp9_segfeature_active(seg, segment_id, SEG_LVL_REF_FRAME) && | |
| 3302 vp9_get_segdata(seg, segment_id, SEG_LVL_REF_FRAME) != | |
| 3303 (int)ref_frame) { | |
| 3304 continue; | |
| 3305 // If the segment skip feature is enabled.... | |
| 3306 // then do nothing if the current mode is not allowed.. | |
| 3307 } else if (vp9_segfeature_active(seg, segment_id, SEG_LVL_SKIP) && | |
| 3308 (this_mode != ZEROMV && ref_frame != INTRA_FRAME)) { | |
| 3309 continue; | |
| 3310 // Disable this drop out case if the ref frame | |
| 3311 // segment level feature is enabled for this segment. This is to | |
| 3312 // prevent the possibility that we end up unable to pick any mode. | |
| 3313 } else if (!vp9_segfeature_active(seg, segment_id, | |
| 3314 SEG_LVL_REF_FRAME)) { | |
| 3315 // Only consider ZEROMV/ALTREF_FRAME for alt ref frame, | |
| 3316 // unless ARNR filtering is enabled in which case we want | |
| 3317 // an unfiltered alternative. We allow near/nearest as well | |
| 3318 // because they may result in zero-zero MVs but be cheaper. | |
| 3319 if (cpi->rc.is_src_frame_alt_ref && (cpi->oxcf.arnr_max_frames == 0)) { | |
| 3320 if ((this_mode != ZEROMV && | |
| 3321 !(this_mode == NEARMV && | |
| 3322 frame_mv[NEARMV][ALTREF_FRAME].as_int == 0) && | |
| 3323 !(this_mode == NEARESTMV && | |
| 3324 frame_mv[NEARESTMV][ALTREF_FRAME].as_int == 0)) || | |
| 3325 ref_frame != ALTREF_FRAME) { | |
| 3326 continue; | |
| 3327 } | |
| 3328 } | |
| 3329 } | |
| 3330 // TODO(JBB): This is to make up for the fact that we don't have sad | |
| 3331 // functions that work when the block size reads outside the umv. We | |
| 3332 // should fix this either by making the motion search just work on | |
| 3333 // a representative block in the boundary ( first ) and then implement a | |
| 3334 // function that does sads when inside the border.. | |
| 3335 if (((mi_row + bhs) > cm->mi_rows || (mi_col + bws) > cm->mi_cols) && | |
| 3336 this_mode == NEWMV) { | |
| 3337 continue; | |
| 3338 } | |
| 3339 | 3393 |
| 3340 #ifdef MODE_TEST_HIT_STATS | 3394 #ifdef MODE_TEST_HIT_STATS |
| 3341 // TEST/DEBUG CODE | 3395 // TEST/DEBUG CODE |
| 3342 // Keep a rcord of the number of test hits at each size | 3396 // Keep a rcord of the number of test hits at each size |
| 3343 cpi->mode_test_hits[bsize]++; | 3397 cpi->mode_test_hits[bsize]++; |
| 3344 #endif | 3398 #endif |
| 3345 | 3399 |
| 3346 | |
| 3347 if (ref_frame == INTRA_FRAME) { | 3400 if (ref_frame == INTRA_FRAME) { |
| 3348 TX_SIZE uv_tx; | 3401 TX_SIZE uv_tx; |
| 3349 // Disable intra modes other than DC_PRED for blocks with low variance | 3402 intra_super_block_yrd(cpi, x, &rate_y, &distortion_y, &skippable, NULL, |
| 3350 // Threshold for intra skipping based on source variance | 3403 bsize, tx_cache, best_rd); |
| 3351 // TODO(debargha): Specialize the threshold for super block sizes | |
| 3352 static const unsigned int skip_intra_var_thresh[BLOCK_SIZES] = { | |
| 3353 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, | |
| 3354 }; | |
| 3355 if ((cpi->sf.mode_search_skip_flags & FLAG_SKIP_INTRA_LOWVAR) && | |
| 3356 this_mode != DC_PRED && | |
| 3357 x->source_variance < skip_intra_var_thresh[mbmi->sb_type]) | |
| 3358 continue; | |
| 3359 // Only search the oblique modes if the best so far is | |
| 3360 // one of the neighboring directional modes | |
| 3361 if ((cpi->sf.mode_search_skip_flags & FLAG_SKIP_INTRA_BESTINTER) && | |
| 3362 (this_mode >= D45_PRED && this_mode <= TM_PRED)) { | |
| 3363 if (vp9_mode_order[best_mode_index].ref_frame[0] > INTRA_FRAME) | |
| 3364 continue; | |
| 3365 } | |
| 3366 mbmi->mode = this_mode; | |
| 3367 if (cpi->sf.mode_search_skip_flags & FLAG_SKIP_INTRA_DIRMISMATCH) { | |
| 3368 if (conditional_skipintra(mbmi->mode, best_intra_mode)) | |
| 3369 continue; | |
| 3370 } | |
| 3371 | |
| 3372 super_block_yrd(cpi, x, &rate_y, &distortion_y, &skippable, NULL, | |
| 3373 bsize, tx_cache, best_rd); | |
| 3374 | 3404 |
| 3375 if (rate_y == INT_MAX) | 3405 if (rate_y == INT_MAX) |
| 3376 continue; | 3406 continue; |
| 3377 | 3407 |
| 3378 uv_tx = get_uv_tx_size_impl(mbmi->tx_size, bsize); | 3408 uv_tx = get_uv_tx_size_impl(mbmi->tx_size, bsize); |
| 3379 if (rate_uv_intra[uv_tx] == INT_MAX) { | 3409 if (rate_uv_intra[uv_tx] == INT_MAX) { |
| 3380 choose_intra_uv_mode(cpi, ctx, bsize, uv_tx, | 3410 choose_intra_uv_mode(cpi, ctx, bsize, uv_tx, |
| 3381 &rate_uv_intra[uv_tx], &rate_uv_tokenonly[uv_tx], | 3411 &rate_uv_intra[uv_tx], &rate_uv_tokenonly[uv_tx], |
| 3382 &dist_uv[uv_tx], &skip_uv[uv_tx], &mode_uv[uv_tx]); | 3412 &dist_uv[uv_tx], &skip_uv[uv_tx], &mode_uv[uv_tx]); |
| 3383 } | 3413 } |
| 3384 | 3414 |
| 3385 rate_uv = rate_uv_tokenonly[uv_tx]; | 3415 rate_uv = rate_uv_tokenonly[uv_tx]; |
| 3386 distortion_uv = dist_uv[uv_tx]; | 3416 distortion_uv = dist_uv[uv_tx]; |
| 3387 skippable = skippable && skip_uv[uv_tx]; | 3417 skippable = skippable && skip_uv[uv_tx]; |
| 3388 mbmi->uv_mode = mode_uv[uv_tx]; | 3418 mbmi->uv_mode = mode_uv[uv_tx]; |
| 3389 | 3419 |
| 3390 rate2 = rate_y + x->mbmode_cost[mbmi->mode] + rate_uv_intra[uv_tx]; | 3420 rate2 = rate_y + x->mbmode_cost[mbmi->mode] + rate_uv_intra[uv_tx]; |
| 3391 if (this_mode != DC_PRED && this_mode != TM_PRED) | 3421 if (this_mode != DC_PRED && this_mode != TM_PRED) |
| 3392 rate2 += intra_cost_penalty; | 3422 rate2 += intra_cost_penalty; |
| 3393 distortion2 = distortion_y + distortion_uv; | 3423 distortion2 = distortion_y + distortion_uv; |
| 3394 } else { | 3424 } else { |
| 3395 mbmi->mode = this_mode; | |
| 3396 compmode_cost = vp9_cost_bit(comp_mode_p, second_ref_frame > INTRA_FRAME); | |
| 3397 this_rd = handle_inter_mode(cpi, x, tile, bsize, | 3425 this_rd = handle_inter_mode(cpi, x, tile, bsize, |
| 3398 tx_cache, | 3426 tx_cache, |
| 3399 &rate2, &distortion2, &skippable, | 3427 &rate2, &distortion2, &skippable, |
| 3400 &rate_y, &distortion_y, | 3428 &rate_y, &distortion_y, |
| 3401 &rate_uv, &distortion_uv, | 3429 &rate_uv, &distortion_uv, |
| 3402 &mode_excluded, &disable_skip, | 3430 &mode_excluded, &disable_skip, |
| 3403 &tmp_best_filter, frame_mv, | 3431 &tmp_best_filter, frame_mv, |
| 3404 mi_row, mi_col, | 3432 mi_row, mi_col, |
| 3405 single_newmv, &total_sse, best_rd); | 3433 single_newmv, &total_sse, best_rd); |
| 3406 if (this_rd == INT64_MAX) | 3434 if (this_rd == INT64_MAX) |
| 3407 continue; | 3435 continue; |
| 3436 |
| 3437 compmode_cost = vp9_cost_bit(comp_mode_p, comp_pred); |
| 3438 |
| 3439 if (cm->reference_mode == REFERENCE_MODE_SELECT) |
| 3440 rate2 += compmode_cost; |
| 3408 } | 3441 } |
| 3409 | 3442 |
| 3410 if (cm->reference_mode == REFERENCE_MODE_SELECT) | |
| 3411 rate2 += compmode_cost; | |
| 3412 | |
| 3413 // Estimate the reference frame signaling cost and add it | 3443 // Estimate the reference frame signaling cost and add it |
| 3414 // to the rolling cost variable. | 3444 // to the rolling cost variable. |
| 3415 if (second_ref_frame > INTRA_FRAME) { | 3445 if (comp_pred) { |
| 3416 rate2 += ref_costs_comp[ref_frame]; | 3446 rate2 += ref_costs_comp[ref_frame]; |
| 3417 } else { | 3447 } else { |
| 3418 rate2 += ref_costs_single[ref_frame]; | 3448 rate2 += ref_costs_single[ref_frame]; |
| 3419 } | 3449 } |
| 3420 | 3450 |
| 3421 if (!disable_skip) { | 3451 if (!disable_skip) { |
| 3422 // Test for the condition where skip block will be activated | 3452 // Test for the condition where skip block will be activated |
| 3423 // because there are no non zero coefficients and make any | 3453 // because there are no non zero coefficients and make any |
| 3424 // necessary adjustment for rate. Ignore if skip is coded at | 3454 // necessary adjustment for rate. Ignore if skip is coded at |
| 3425 // segment level as the cost wont have been added in. | 3455 // segment level as the cost wont have been added in. |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3460 } | 3490 } |
| 3461 } else if (mb_skip_allowed) { | 3491 } else if (mb_skip_allowed) { |
| 3462 // Add in the cost of the no skip flag. | 3492 // Add in the cost of the no skip flag. |
| 3463 rate2 += vp9_cost_bit(vp9_get_skip_prob(cm, xd), 0); | 3493 rate2 += vp9_cost_bit(vp9_get_skip_prob(cm, xd), 0); |
| 3464 } | 3494 } |
| 3465 | 3495 |
| 3466 // Calculate the final RD estimate for this mode. | 3496 // Calculate the final RD estimate for this mode. |
| 3467 this_rd = RDCOST(x->rdmult, x->rddiv, rate2, distortion2); | 3497 this_rd = RDCOST(x->rdmult, x->rddiv, rate2, distortion2); |
| 3468 } | 3498 } |
| 3469 | 3499 |
| 3500 if (ref_frame == INTRA_FRAME) { |
| 3470 // Keep record of best intra rd | 3501 // Keep record of best intra rd |
| 3471 if (!is_inter_block(&xd->mi_8x8[0]->mbmi) && | 3502 if (this_rd < best_intra_rd) { |
| 3472 this_rd < best_intra_rd) { | 3503 best_intra_rd = this_rd; |
| 3473 best_intra_rd = this_rd; | 3504 best_intra_mode = mbmi->mode; |
| 3474 best_intra_mode = xd->mi_8x8[0]->mbmi.mode; | 3505 } |
| 3475 } | 3506 } else { |
| 3476 | 3507 // Keep record of best inter rd with single reference |
| 3477 // Keep record of best inter rd with single reference | 3508 if (!comp_pred && !mode_excluded && this_rd < best_inter_rd) { |
| 3478 if (is_inter_block(&xd->mi_8x8[0]->mbmi) && | 3509 best_inter_rd = this_rd; |
| 3479 !has_second_ref(&xd->mi_8x8[0]->mbmi) && | 3510 best_inter_ref_frame = ref_frame; |
| 3480 !mode_excluded && this_rd < best_inter_rd) { | 3511 } |
| 3481 best_inter_rd = this_rd; | |
| 3482 best_inter_ref_frame = ref_frame; | |
| 3483 } | 3512 } |
| 3484 | 3513 |
| 3485 if (!disable_skip && ref_frame == INTRA_FRAME) { | 3514 if (!disable_skip && ref_frame == INTRA_FRAME) { |
| 3486 for (i = 0; i < REFERENCE_MODES; ++i) | 3515 for (i = 0; i < REFERENCE_MODES; ++i) |
| 3487 best_pred_rd[i] = MIN(best_pred_rd[i], this_rd); | 3516 best_pred_rd[i] = MIN(best_pred_rd[i], this_rd); |
| 3488 for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; i++) | 3517 for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; i++) |
| 3489 best_filter_rd[i] = MIN(best_filter_rd[i], this_rd); | 3518 best_filter_rd[i] = MIN(best_filter_rd[i], this_rd); |
| 3490 } | 3519 } |
| 3491 | 3520 |
| 3492 // Store the respective mode distortions for later use. | 3521 // Store the respective mode distortions for later use. |
| (...skipping 20 matching lines...) Expand all Loading... |
| 3513 best_rd = this_rd; | 3542 best_rd = this_rd; |
| 3514 best_mbmode = *mbmi; | 3543 best_mbmode = *mbmi; |
| 3515 best_skip2 = this_skip2; | 3544 best_skip2 = this_skip2; |
| 3516 if (!x->select_txfm_size) | 3545 if (!x->select_txfm_size) |
| 3517 swap_block_ptr(x, ctx, max_plane); | 3546 swap_block_ptr(x, ctx, max_plane); |
| 3518 vpx_memcpy(ctx->zcoeff_blk, x->zcoeff_blk[mbmi->tx_size], | 3547 vpx_memcpy(ctx->zcoeff_blk, x->zcoeff_blk[mbmi->tx_size], |
| 3519 sizeof(uint8_t) * ctx->num_4x4_blk); | 3548 sizeof(uint8_t) * ctx->num_4x4_blk); |
| 3520 | 3549 |
| 3521 // TODO(debargha): enhance this test with a better distortion prediction | 3550 // TODO(debargha): enhance this test with a better distortion prediction |
| 3522 // based on qp, activity mask and history | 3551 // based on qp, activity mask and history |
| 3523 if ((cpi->sf.mode_search_skip_flags & FLAG_EARLY_TERMINATE) && | 3552 if ((mode_search_skip_flags & FLAG_EARLY_TERMINATE) && |
| 3524 (mode_index > MIN_EARLY_TERM_INDEX)) { | 3553 (mode_index > MIN_EARLY_TERM_INDEX)) { |
| 3525 const int qstep = xd->plane[0].dequant[1]; | 3554 const int qstep = xd->plane[0].dequant[1]; |
| 3526 // TODO(debargha): Enhance this by specializing for each mode_index | 3555 // TODO(debargha): Enhance this by specializing for each mode_index |
| 3527 int scale = 4; | 3556 int scale = 4; |
| 3528 if (x->source_variance < UINT_MAX) { | 3557 if (x->source_variance < UINT_MAX) { |
| 3529 const int var_adjust = (x->source_variance < 16); | 3558 const int var_adjust = (x->source_variance < 16); |
| 3530 scale -= var_adjust; | 3559 scale -= var_adjust; |
| 3531 } | 3560 } |
| 3532 if (ref_frame > INTRA_FRAME && | 3561 if (ref_frame > INTRA_FRAME && |
| 3533 distortion2 * scale < qstep * qstep) { | 3562 distortion2 * scale < qstep * qstep) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 3545 single_rate = rate2 - compmode_cost; | 3574 single_rate = rate2 - compmode_cost; |
| 3546 hybrid_rate = rate2; | 3575 hybrid_rate = rate2; |
| 3547 } else { | 3576 } else { |
| 3548 single_rate = rate2; | 3577 single_rate = rate2; |
| 3549 hybrid_rate = rate2 + compmode_cost; | 3578 hybrid_rate = rate2 + compmode_cost; |
| 3550 } | 3579 } |
| 3551 | 3580 |
| 3552 single_rd = RDCOST(x->rdmult, x->rddiv, single_rate, distortion2); | 3581 single_rd = RDCOST(x->rdmult, x->rddiv, single_rate, distortion2); |
| 3553 hybrid_rd = RDCOST(x->rdmult, x->rddiv, hybrid_rate, distortion2); | 3582 hybrid_rd = RDCOST(x->rdmult, x->rddiv, hybrid_rate, distortion2); |
| 3554 | 3583 |
| 3555 if (second_ref_frame <= INTRA_FRAME && | 3584 if (!comp_pred) { |
| 3556 single_rd < best_pred_rd[SINGLE_REFERENCE]) { | 3585 if (single_rd < best_pred_rd[SINGLE_REFERENCE]) { |
| 3557 best_pred_rd[SINGLE_REFERENCE] = single_rd; | 3586 best_pred_rd[SINGLE_REFERENCE] = single_rd; |
| 3558 } else if (second_ref_frame > INTRA_FRAME && | 3587 } |
| 3559 single_rd < best_pred_rd[COMPOUND_REFERENCE]) { | 3588 } else { |
| 3560 best_pred_rd[COMPOUND_REFERENCE] = single_rd; | 3589 if (single_rd < best_pred_rd[COMPOUND_REFERENCE]) { |
| 3590 best_pred_rd[COMPOUND_REFERENCE] = single_rd; |
| 3591 } |
| 3561 } | 3592 } |
| 3562 if (hybrid_rd < best_pred_rd[REFERENCE_MODE_SELECT]) | 3593 if (hybrid_rd < best_pred_rd[REFERENCE_MODE_SELECT]) |
| 3563 best_pred_rd[REFERENCE_MODE_SELECT] = hybrid_rd; | 3594 best_pred_rd[REFERENCE_MODE_SELECT] = hybrid_rd; |
| 3564 } | |
| 3565 | 3595 |
| 3566 /* keep record of best filter type */ | 3596 /* keep record of best filter type */ |
| 3567 if (!mode_excluded && !disable_skip && ref_frame != INTRA_FRAME && | 3597 if (!mode_excluded && cm->interp_filter != BILINEAR) { |
| 3568 cm->interp_filter != BILINEAR) { | 3598 int64_t ref = cpi->rd_filter_cache[cm->interp_filter == SWITCHABLE ? |
| 3569 int64_t ref = cpi->rd_filter_cache[cm->interp_filter == SWITCHABLE ? | |
| 3570 SWITCHABLE_FILTERS : cm->interp_filter]; | 3599 SWITCHABLE_FILTERS : cm->interp_filter]; |
| 3571 | 3600 |
| 3572 for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; i++) { | 3601 for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; i++) { |
| 3573 int64_t adj_rd; | 3602 int64_t adj_rd; |
| 3574 if (ref == INT64_MAX) | 3603 if (ref == INT64_MAX) |
| 3575 adj_rd = 0; | 3604 adj_rd = 0; |
| 3576 else if (cpi->rd_filter_cache[i] == INT64_MAX) | 3605 else if (cpi->rd_filter_cache[i] == INT64_MAX) |
| 3577 // when early termination is triggered, the encoder does not have | 3606 // when early termination is triggered, the encoder does not have |
| 3578 // access to the rate-distortion cost. it only knows that the cost | 3607 // access to the rate-distortion cost. it only knows that the cost |
| 3579 // should be above the maximum valid value. hence it takes the known | 3608 // should be above the maximum valid value. hence it takes the known |
| 3580 // maximum plus an arbitrary constant as the rate-distortion cost. | 3609 // maximum plus an arbitrary constant as the rate-distortion cost. |
| 3581 adj_rd = cpi->mask_filter_rd - ref + 10; | 3610 adj_rd = cpi->mask_filter_rd - ref + 10; |
| 3582 else | 3611 else |
| 3583 adj_rd = cpi->rd_filter_cache[i] - ref; | 3612 adj_rd = cpi->rd_filter_cache[i] - ref; |
| 3584 | 3613 |
| 3585 adj_rd += this_rd; | 3614 adj_rd += this_rd; |
| 3586 best_filter_rd[i] = MIN(best_filter_rd[i], adj_rd); | 3615 best_filter_rd[i] = MIN(best_filter_rd[i], adj_rd); |
| 3616 } |
| 3587 } | 3617 } |
| 3588 } | 3618 } |
| 3589 | 3619 |
| 3590 /* keep record of best txfm size */ | 3620 /* keep record of best txfm size */ |
| 3591 if (bsize < BLOCK_32X32) { | 3621 if (bsize < BLOCK_32X32) { |
| 3592 if (bsize < BLOCK_16X16) | 3622 if (bsize < BLOCK_16X16) |
| 3593 tx_cache[ALLOW_16X16] = tx_cache[ALLOW_8X8]; | 3623 tx_cache[ALLOW_16X16] = tx_cache[ALLOW_8X8]; |
| 3594 | 3624 |
| 3595 tx_cache[ALLOW_32X32] = tx_cache[ALLOW_16X16]; | 3625 tx_cache[ALLOW_32X32] = tx_cache[ALLOW_16X16]; |
| 3596 } | 3626 } |
| (...skipping 26 matching lines...) Expand all Loading... |
| 3623 uv_tx_size = get_uv_tx_size(mbmi); | 3653 uv_tx_size = get_uv_tx_size(mbmi); |
| 3624 rd_pick_intra_sbuv_mode(cpi, x, ctx, &rate_uv_intra[uv_tx_size], | 3654 rd_pick_intra_sbuv_mode(cpi, x, ctx, &rate_uv_intra[uv_tx_size], |
| 3625 &rate_uv_tokenonly[uv_tx_size], | 3655 &rate_uv_tokenonly[uv_tx_size], |
| 3626 &dist_uv[uv_tx_size], | 3656 &dist_uv[uv_tx_size], |
| 3627 &skip_uv[uv_tx_size], | 3657 &skip_uv[uv_tx_size], |
| 3628 bsize < BLOCK_8X8 ? BLOCK_8X8 : bsize, | 3658 bsize < BLOCK_8X8 ? BLOCK_8X8 : bsize, |
| 3629 uv_tx_size); | 3659 uv_tx_size); |
| 3630 } | 3660 } |
| 3631 } | 3661 } |
| 3632 | 3662 |
| 3633 // Flag all modes that have a distortion thats > 2x the best we found at | |
| 3634 // this level. | |
| 3635 for (mode_index = 0; mode_index < MB_MODE_COUNT; ++mode_index) { | |
| 3636 if (mode_index == NEARESTMV || mode_index == NEARMV || mode_index == NEWMV) | |
| 3637 continue; | |
| 3638 | |
| 3639 if (mode_distortions[mode_index] > 2 * *returndistortion) { | |
| 3640 ctx->modes_with_high_error |= (1 << mode_index); | |
| 3641 } | |
| 3642 } | |
| 3643 | |
| 3644 assert((cm->interp_filter == SWITCHABLE) || | 3663 assert((cm->interp_filter == SWITCHABLE) || |
| 3645 (cm->interp_filter == best_mbmode.interp_filter) || | 3664 (cm->interp_filter == best_mbmode.interp_filter) || |
| 3646 !is_inter_block(&best_mbmode)); | 3665 !is_inter_block(&best_mbmode)); |
| 3647 | 3666 |
| 3648 // Updating rd_thresh_freq_fact[] here means that the different | 3667 // Updating rd_thresh_freq_fact[] here means that the different |
| 3649 // partition/block sizes are handled independently based on the best | 3668 // partition/block sizes are handled independently based on the best |
| 3650 // choice for the current partition. It may well be better to keep a scaled | 3669 // choice for the current partition. It may well be better to keep a scaled |
| 3651 // best rd so far value and update rd_thresh_freq_fact based on the mode/size | 3670 // best rd so far value and update rd_thresh_freq_fact based on the mode/size |
| 3652 // combination that wins out. | 3671 // combination that wins out. |
| 3653 if (cpi->sf.adaptive_rd_thresh) { | 3672 if (cpi->sf.adaptive_rd_thresh) { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 3679 | 3698 |
| 3680 if (!x->skip) { | 3699 if (!x->skip) { |
| 3681 for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; i++) { | 3700 for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; i++) { |
| 3682 if (best_filter_rd[i] == INT64_MAX) | 3701 if (best_filter_rd[i] == INT64_MAX) |
| 3683 best_filter_diff[i] = 0; | 3702 best_filter_diff[i] = 0; |
| 3684 else | 3703 else |
| 3685 best_filter_diff[i] = best_rd - best_filter_rd[i]; | 3704 best_filter_diff[i] = best_rd - best_filter_rd[i]; |
| 3686 } | 3705 } |
| 3687 if (cm->interp_filter == SWITCHABLE) | 3706 if (cm->interp_filter == SWITCHABLE) |
| 3688 assert(best_filter_diff[SWITCHABLE_FILTERS] == 0); | 3707 assert(best_filter_diff[SWITCHABLE_FILTERS] == 0); |
| 3689 } else { | |
| 3690 vp9_zero(best_filter_diff); | |
| 3691 } | |
| 3692 | |
| 3693 if (!x->skip) { | |
| 3694 for (i = 0; i < TX_MODES; i++) { | 3708 for (i = 0; i < TX_MODES; i++) { |
| 3695 if (best_tx_rd[i] == INT64_MAX) | 3709 if (best_tx_rd[i] == INT64_MAX) |
| 3696 best_tx_diff[i] = 0; | 3710 best_tx_diff[i] = 0; |
| 3697 else | 3711 else |
| 3698 best_tx_diff[i] = best_rd - best_tx_rd[i]; | 3712 best_tx_diff[i] = best_rd - best_tx_rd[i]; |
| 3699 } | 3713 } |
| 3700 } else { | 3714 } else { |
| 3715 vp9_zero(best_filter_diff); |
| 3701 vp9_zero(best_tx_diff); | 3716 vp9_zero(best_tx_diff); |
| 3702 } | 3717 } |
| 3703 | 3718 |
| 3704 set_ref_ptrs(cm, xd, mbmi->ref_frame[0], mbmi->ref_frame[1]); | 3719 set_ref_ptrs(cm, xd, mbmi->ref_frame[0], mbmi->ref_frame[1]); |
| 3705 store_coding_context(x, ctx, best_mode_index, | 3720 store_coding_context(x, ctx, best_mode_index, |
| 3706 &mbmi->ref_mvs[mbmi->ref_frame[0]][0], | 3721 &mbmi->ref_mvs[mbmi->ref_frame[0]][0], |
| 3707 &mbmi->ref_mvs[mbmi->ref_frame[1] < 0 ? 0 : | 3722 &mbmi->ref_mvs[mbmi->ref_frame[1] < 0 ? 0 : |
| 3708 mbmi->ref_frame[1]][0], | 3723 mbmi->ref_frame[1]][0], |
| 3709 best_pred_diff, best_tx_diff, best_filter_diff); | 3724 best_pred_diff, best_tx_diff, best_filter_diff); |
| 3710 | 3725 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3748 MV_REFERENCE_FRAME best_inter_ref_frame = LAST_FRAME; | 3763 MV_REFERENCE_FRAME best_inter_ref_frame = LAST_FRAME; |
| 3749 INTERP_FILTER tmp_best_filter = SWITCHABLE; | 3764 INTERP_FILTER tmp_best_filter = SWITCHABLE; |
| 3750 int rate_uv_intra[TX_SIZES], rate_uv_tokenonly[TX_SIZES]; | 3765 int rate_uv_intra[TX_SIZES], rate_uv_tokenonly[TX_SIZES]; |
| 3751 int64_t dist_uv[TX_SIZES]; | 3766 int64_t dist_uv[TX_SIZES]; |
| 3752 int skip_uv[TX_SIZES]; | 3767 int skip_uv[TX_SIZES]; |
| 3753 MB_PREDICTION_MODE mode_uv[TX_SIZES] = { 0 }; | 3768 MB_PREDICTION_MODE mode_uv[TX_SIZES] = { 0 }; |
| 3754 int intra_cost_penalty = 20 * vp9_dc_quant(cm->base_qindex, cm->y_dc_delta_q); | 3769 int intra_cost_penalty = 20 * vp9_dc_quant(cm->base_qindex, cm->y_dc_delta_q); |
| 3755 int_mv seg_mvs[4][MAX_REF_FRAMES]; | 3770 int_mv seg_mvs[4][MAX_REF_FRAMES]; |
| 3756 b_mode_info best_bmodes[4]; | 3771 b_mode_info best_bmodes[4]; |
| 3757 int best_skip2 = 0; | 3772 int best_skip2 = 0; |
| 3773 int ref_frame_mask = 0; |
| 3774 int mode_skip_mask = 0; |
| 3758 | 3775 |
| 3759 x->skip_encode = cpi->sf.skip_encode_frame && x->q_index < QIDX_SKIP_THRESH; | 3776 x->skip_encode = cpi->sf.skip_encode_frame && x->q_index < QIDX_SKIP_THRESH; |
| 3760 vpx_memset(x->zcoeff_blk[TX_4X4], 0, 4); | 3777 vpx_memset(x->zcoeff_blk[TX_4X4], 0, 4); |
| 3761 | 3778 |
| 3762 for (i = 0; i < 4; i++) { | 3779 for (i = 0; i < 4; i++) { |
| 3763 int j; | 3780 int j; |
| 3764 for (j = 0; j < MAX_REF_FRAMES; j++) | 3781 for (j = 0; j < MAX_REF_FRAMES; j++) |
| 3765 seg_mvs[i][j].as_int = INVALID_MV; | 3782 seg_mvs[i][j].as_int = INVALID_MV; |
| 3766 } | 3783 } |
| 3767 | 3784 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 3783 if (cpi->ref_frame_flags & flag_list[ref_frame]) { | 3800 if (cpi->ref_frame_flags & flag_list[ref_frame]) { |
| 3784 vp9_setup_buffer_inter(cpi, x, tile, | 3801 vp9_setup_buffer_inter(cpi, x, tile, |
| 3785 ref_frame, block_size, mi_row, mi_col, | 3802 ref_frame, block_size, mi_row, mi_col, |
| 3786 frame_mv[NEARESTMV], frame_mv[NEARMV], | 3803 frame_mv[NEARESTMV], frame_mv[NEARMV], |
| 3787 yv12_mb); | 3804 yv12_mb); |
| 3788 } | 3805 } |
| 3789 frame_mv[NEWMV][ref_frame].as_int = INVALID_MV; | 3806 frame_mv[NEWMV][ref_frame].as_int = INVALID_MV; |
| 3790 frame_mv[ZEROMV][ref_frame].as_int = 0; | 3807 frame_mv[ZEROMV][ref_frame].as_int = 0; |
| 3791 } | 3808 } |
| 3792 | 3809 |
| 3793 cpi->ref_frame_mask = 0; | |
| 3794 for (ref_frame = LAST_FRAME; | 3810 for (ref_frame = LAST_FRAME; |
| 3795 ref_frame <= ALTREF_FRAME && cpi->sf.reference_masking; ++ref_frame) { | 3811 ref_frame <= ALTREF_FRAME && cpi->sf.reference_masking; ++ref_frame) { |
| 3796 int i; | 3812 int i; |
| 3797 for (i = LAST_FRAME; i <= ALTREF_FRAME; ++i) { | 3813 for (i = LAST_FRAME; i <= ALTREF_FRAME; ++i) { |
| 3798 if ((x->pred_mv_sad[ref_frame] >> 1) > x->pred_mv_sad[i]) { | 3814 if ((x->pred_mv_sad[ref_frame] >> 1) > x->pred_mv_sad[i]) { |
| 3799 cpi->ref_frame_mask |= (1 << ref_frame); | 3815 ref_frame_mask |= (1 << ref_frame); |
| 3800 break; | 3816 break; |
| 3801 } | 3817 } |
| 3802 } | 3818 } |
| 3803 } | 3819 } |
| 3804 | 3820 |
| 3805 for (mode_index = 0; mode_index < MAX_REFS; ++mode_index) { | 3821 for (mode_index = 0; mode_index < MAX_REFS; ++mode_index) { |
| 3806 int mode_excluded = 0; | 3822 int mode_excluded = 0; |
| 3807 int64_t this_rd = INT64_MAX; | 3823 int64_t this_rd = INT64_MAX; |
| 3808 int disable_skip = 0; | 3824 int disable_skip = 0; |
| 3809 int compmode_cost = 0; | 3825 int compmode_cost = 0; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 3822 x->skip = 0; | 3838 x->skip = 0; |
| 3823 ref_frame = vp9_ref_order[mode_index].ref_frame[0]; | 3839 ref_frame = vp9_ref_order[mode_index].ref_frame[0]; |
| 3824 second_ref_frame = vp9_ref_order[mode_index].ref_frame[1]; | 3840 second_ref_frame = vp9_ref_order[mode_index].ref_frame[1]; |
| 3825 | 3841 |
| 3826 // Look at the reference frame of the best mode so far and set the | 3842 // Look at the reference frame of the best mode so far and set the |
| 3827 // skip mask to look at a subset of the remaining modes. | 3843 // skip mask to look at a subset of the remaining modes. |
| 3828 if (mode_index > 2 && cpi->sf.mode_skip_start < MAX_MODES) { | 3844 if (mode_index > 2 && cpi->sf.mode_skip_start < MAX_MODES) { |
| 3829 if (mode_index == 3) { | 3845 if (mode_index == 3) { |
| 3830 switch (vp9_ref_order[best_mode_index].ref_frame[0]) { | 3846 switch (vp9_ref_order[best_mode_index].ref_frame[0]) { |
| 3831 case INTRA_FRAME: | 3847 case INTRA_FRAME: |
| 3832 cpi->mode_skip_mask = 0; | 3848 mode_skip_mask = 0; |
| 3833 break; | 3849 break; |
| 3834 case LAST_FRAME: | 3850 case LAST_FRAME: |
| 3835 cpi->mode_skip_mask = 0x0010; | 3851 mode_skip_mask = 0x0010; |
| 3836 break; | 3852 break; |
| 3837 case GOLDEN_FRAME: | 3853 case GOLDEN_FRAME: |
| 3838 cpi->mode_skip_mask = 0x0008; | 3854 mode_skip_mask = 0x0008; |
| 3839 break; | 3855 break; |
| 3840 case ALTREF_FRAME: | 3856 case ALTREF_FRAME: |
| 3841 cpi->mode_skip_mask = 0x0000; | 3857 mode_skip_mask = 0x0000; |
| 3842 break; | 3858 break; |
| 3843 case NONE: | 3859 case NONE: |
| 3844 case MAX_REF_FRAMES: | 3860 case MAX_REF_FRAMES: |
| 3845 assert(0 && "Invalid Reference frame"); | 3861 assert(0 && "Invalid Reference frame"); |
| 3846 } | 3862 } |
| 3847 } | 3863 } |
| 3848 if (cpi->mode_skip_mask & ((int64_t)1 << mode_index)) | 3864 if (mode_skip_mask & (1 << mode_index)) |
| 3849 continue; | 3865 continue; |
| 3850 } | 3866 } |
| 3851 | 3867 |
| 3852 // Test best rd so far against threshold for trying this mode. | 3868 // Test best rd so far against threshold for trying this mode. |
| 3853 if ((best_rd < | 3869 if ((best_rd < |
| 3854 ((int64_t)cpi->rd_thresh_sub8x8[segment_id][bsize][mode_index] * | 3870 ((int64_t)cpi->rd_thresh_sub8x8[segment_id][bsize][mode_index] * |
| 3855 cpi->rd_thresh_freq_sub8x8[bsize][mode_index] >> 5)) || | 3871 cpi->rd_thresh_freq_sub8x8[bsize][mode_index] >> 5)) || |
| 3856 cpi->rd_thresh_sub8x8[segment_id][bsize][mode_index] == INT_MAX) | 3872 cpi->rd_thresh_sub8x8[segment_id][bsize][mode_index] == INT_MAX) |
| 3857 continue; | 3873 continue; |
| 3858 | 3874 |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4129 | 4145 |
| 4130 tmp_best_rdu = best_rd - | 4146 tmp_best_rdu = best_rd - |
| 4131 MIN(RDCOST(x->rdmult, x->rddiv, rate2, distortion2), | 4147 MIN(RDCOST(x->rdmult, x->rddiv, rate2, distortion2), |
| 4132 RDCOST(x->rdmult, x->rddiv, 0, total_sse)); | 4148 RDCOST(x->rdmult, x->rddiv, 0, total_sse)); |
| 4133 | 4149 |
| 4134 if (tmp_best_rdu > 0) { | 4150 if (tmp_best_rdu > 0) { |
| 4135 // If even the 'Y' rd value of split is higher than best so far | 4151 // If even the 'Y' rd value of split is higher than best so far |
| 4136 // then dont bother looking at UV | 4152 // then dont bother looking at UV |
| 4137 vp9_build_inter_predictors_sbuv(&x->e_mbd, mi_row, mi_col, | 4153 vp9_build_inter_predictors_sbuv(&x->e_mbd, mi_row, mi_col, |
| 4138 BLOCK_8X8); | 4154 BLOCK_8X8); |
| 4139 super_block_uvrd(cpi, x, &rate_uv, &distortion_uv, &uv_skippable, | 4155 super_block_uvrd(x, &rate_uv, &distortion_uv, &uv_skippable, |
| 4140 &uv_sse, BLOCK_8X8, tmp_best_rdu); | 4156 &uv_sse, BLOCK_8X8, tmp_best_rdu); |
| 4141 if (rate_uv == INT_MAX) | 4157 if (rate_uv == INT_MAX) |
| 4142 continue; | 4158 continue; |
| 4143 rate2 += rate_uv; | 4159 rate2 += rate_uv; |
| 4144 distortion2 += distortion_uv; | 4160 distortion2 += distortion_uv; |
| 4145 skippable = skippable && uv_skippable; | 4161 skippable = skippable && uv_skippable; |
| 4146 total_sse += uv_sse; | 4162 total_sse += uv_sse; |
| 4147 | 4163 |
| 4148 tx_cache[ONLY_4X4] = RDCOST(x->rdmult, x->rddiv, rate2, distortion2); | 4164 tx_cache[ONLY_4X4] = RDCOST(x->rdmult, x->rddiv, rate2, distortion2); |
| 4149 for (i = 0; i < TX_MODES; ++i) | 4165 for (i = 0; i < TX_MODES; ++i) |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4348 rd_pick_intra_sbuv_mode(cpi, x, ctx, &rate_uv_intra[uv_tx_size], | 4364 rd_pick_intra_sbuv_mode(cpi, x, ctx, &rate_uv_intra[uv_tx_size], |
| 4349 &rate_uv_tokenonly[uv_tx_size], | 4365 &rate_uv_tokenonly[uv_tx_size], |
| 4350 &dist_uv[uv_tx_size], | 4366 &dist_uv[uv_tx_size], |
| 4351 &skip_uv[uv_tx_size], | 4367 &skip_uv[uv_tx_size], |
| 4352 BLOCK_8X8, uv_tx_size); | 4368 BLOCK_8X8, uv_tx_size); |
| 4353 } | 4369 } |
| 4354 } | 4370 } |
| 4355 | 4371 |
| 4356 if (best_rd == INT64_MAX && bsize < BLOCK_8X8) { | 4372 if (best_rd == INT64_MAX && bsize < BLOCK_8X8) { |
| 4357 *returnrate = INT_MAX; | 4373 *returnrate = INT_MAX; |
| 4358 *returndistortion = INT_MAX; | 4374 *returndistortion = INT64_MAX; |
| 4359 return best_rd; | 4375 return best_rd; |
| 4360 } | 4376 } |
| 4361 | 4377 |
| 4362 assert((cm->interp_filter == SWITCHABLE) || | 4378 assert((cm->interp_filter == SWITCHABLE) || |
| 4363 (cm->interp_filter == best_mbmode.interp_filter) || | 4379 (cm->interp_filter == best_mbmode.interp_filter) || |
| 4364 !is_inter_block(&best_mbmode)); | 4380 !is_inter_block(&best_mbmode)); |
| 4365 | 4381 |
| 4366 // Updating rd_thresh_freq_fact[] here means that the different | 4382 // Updating rd_thresh_freq_fact[] here means that the different |
| 4367 // partition/block sizes are handled independently based on the best | 4383 // partition/block sizes are handled independently based on the best |
| 4368 // choice for the current partition. It may well be better to keep a scaled | 4384 // choice for the current partition. It may well be better to keep a scaled |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4431 | 4447 |
| 4432 set_ref_ptrs(cm, xd, mbmi->ref_frame[0], mbmi->ref_frame[1]); | 4448 set_ref_ptrs(cm, xd, mbmi->ref_frame[0], mbmi->ref_frame[1]); |
| 4433 store_coding_context(x, ctx, best_mode_index, | 4449 store_coding_context(x, ctx, best_mode_index, |
| 4434 &mbmi->ref_mvs[mbmi->ref_frame[0]][0], | 4450 &mbmi->ref_mvs[mbmi->ref_frame[0]][0], |
| 4435 &mbmi->ref_mvs[mbmi->ref_frame[1] < 0 ? 0 : | 4451 &mbmi->ref_mvs[mbmi->ref_frame[1] < 0 ? 0 : |
| 4436 mbmi->ref_frame[1]][0], | 4452 mbmi->ref_frame[1]][0], |
| 4437 best_pred_diff, best_tx_diff, best_filter_diff); | 4453 best_pred_diff, best_tx_diff, best_filter_diff); |
| 4438 | 4454 |
| 4439 return best_rd; | 4455 return best_rd; |
| 4440 } | 4456 } |
| OLD | NEW |