OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved. | 2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 MACROBLOCK *x, MACROBLOCKD *xd, | 164 MACROBLOCK *x, MACROBLOCKD *xd, |
165 int *out_rate_sum, int64_t *out_dist_sum) { | 165 int *out_rate_sum, int64_t *out_dist_sum) { |
166 // Note our transform coeffs are 8 times an orthogonal transform. | 166 // Note our transform coeffs are 8 times an orthogonal transform. |
167 // Hence quantizer step is also 8 times. To get effective quantizer | 167 // Hence quantizer step is also 8 times. To get effective quantizer |
168 // we need to divide by 8 before sending to modeling function. | 168 // we need to divide by 8 before sending to modeling function. |
169 int i; | 169 int i; |
170 int64_t rate_sum = 0; | 170 int64_t rate_sum = 0; |
171 int64_t dist_sum = 0; | 171 int64_t dist_sum = 0; |
172 const int ref = xd->mi[0]->mbmi.ref_frame[0]; | 172 const int ref = xd->mi[0]->mbmi.ref_frame[0]; |
173 unsigned int sse; | 173 unsigned int sse; |
| 174 const int shift = 8; |
174 | 175 |
175 for (i = 0; i < MAX_MB_PLANE; ++i) { | 176 for (i = 0; i < MAX_MB_PLANE; ++i) { |
176 struct macroblock_plane *const p = &x->plane[i]; | 177 struct macroblock_plane *const p = &x->plane[i]; |
177 struct macroblockd_plane *const pd = &xd->plane[i]; | 178 struct macroblockd_plane *const pd = &xd->plane[i]; |
178 const BLOCK_SIZE bs = get_plane_block_size(bsize, pd); | 179 const BLOCK_SIZE bs = get_plane_block_size(bsize, pd); |
179 | 180 |
180 (void) cpi->fn_ptr[bs].vf(p->src.buf, p->src.stride, | 181 const unsigned int var = cpi->fn_ptr[bs].vf(p->src.buf, p->src.stride, |
181 pd->dst.buf, pd->dst.stride, &sse); | 182 pd->dst.buf, pd->dst.stride, |
| 183 &sse); |
182 | 184 |
| 185 if (!x->select_tx_size) { |
| 186 if (sse < p->quant_thred[0] >> shift) |
| 187 x->skip_txfm[i] = 1; |
| 188 else if (var < p->quant_thred[1] >> shift) |
| 189 x->skip_txfm[i] = 2; |
| 190 else |
| 191 x->skip_txfm[i] = 0; |
| 192 } |
| 193 |
| 194 x->bsse[i] = sse; |
183 if (i == 0) | 195 if (i == 0) |
184 x->pred_sse[ref] = sse; | 196 x->pred_sse[ref] = sse; |
185 | 197 |
186 // Fast approximate the modelling function. | 198 // Fast approximate the modelling function. |
187 if (cpi->oxcf.speed > 4) { | 199 if (cpi->oxcf.speed > 4) { |
188 int64_t rate; | 200 int64_t rate; |
189 int64_t dist; | 201 int64_t dist; |
190 int64_t square_error = sse; | 202 int64_t square_error = sse; |
191 int quantizer = (pd->dequant[1] >> 3); | 203 int quantizer = (pd->dequant[1] >> 3); |
192 | 204 |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 TX_SIZE tx_size, void *arg) { | 362 TX_SIZE tx_size, void *arg) { |
351 struct rdcost_block_args *args = arg; | 363 struct rdcost_block_args *args = arg; |
352 MACROBLOCK *const x = args->x; | 364 MACROBLOCK *const x = args->x; |
353 MACROBLOCKD *const xd = &x->e_mbd; | 365 MACROBLOCKD *const xd = &x->e_mbd; |
354 MB_MODE_INFO *const mbmi = &xd->mi[0]->mbmi; | 366 MB_MODE_INFO *const mbmi = &xd->mi[0]->mbmi; |
355 int64_t rd1, rd2, rd; | 367 int64_t rd1, rd2, rd; |
356 | 368 |
357 if (args->skip) | 369 if (args->skip) |
358 return; | 370 return; |
359 | 371 |
360 if (!is_inter_block(mbmi)) | 372 if (!is_inter_block(mbmi)) { |
361 vp9_encode_block_intra(x, plane, block, plane_bsize, tx_size, &mbmi->skip); | 373 vp9_encode_block_intra(x, plane, block, plane_bsize, tx_size, &mbmi->skip); |
362 else | 374 dist_block(plane, block, tx_size, args); |
363 vp9_xform_quant(x, plane, block, plane_bsize, tx_size); | 375 } else { |
| 376 if (x->skip_txfm[plane] == 0) { |
| 377 // full forward transform and quantization |
| 378 vp9_xform_quant(x, plane, block, plane_bsize, tx_size); |
| 379 dist_block(plane, block, tx_size, args); |
| 380 } else if (x->skip_txfm[plane] == 2) { |
| 381 // compute DC coefficient |
| 382 int16_t *const coeff = BLOCK_OFFSET(x->plane[plane].coeff, block); |
| 383 int16_t *const dqcoeff = BLOCK_OFFSET(xd->plane[plane].dqcoeff, block); |
| 384 vp9_xform_quant_dc(x, plane, block, plane_bsize, tx_size); |
| 385 args->sse = x->bsse[plane] << 4; |
| 386 args->dist = args->sse; |
| 387 if (!x->plane[plane].eobs[block]) |
| 388 args->dist = args->sse - ((coeff[0] * coeff[0] - |
| 389 (coeff[0] - dqcoeff[0]) * (coeff[0] - dqcoeff[0])) >> 2); |
| 390 } else { |
| 391 // skip forward transform |
| 392 x->plane[plane].eobs[block] = 0; |
| 393 args->sse = x->bsse[plane] << 4; |
| 394 args->dist = args->sse; |
| 395 } |
| 396 } |
364 | 397 |
365 dist_block(plane, block, tx_size, args); | |
366 rate_block(plane, block, plane_bsize, tx_size, args); | 398 rate_block(plane, block, plane_bsize, tx_size, args); |
367 rd1 = RDCOST(x->rdmult, x->rddiv, args->rate, args->dist); | 399 rd1 = RDCOST(x->rdmult, x->rddiv, args->rate, args->dist); |
368 rd2 = RDCOST(x->rdmult, x->rddiv, 0, args->sse); | 400 rd2 = RDCOST(x->rdmult, x->rddiv, 0, args->sse); |
369 | 401 |
370 // TODO(jingning): temporarily enabled only for luma component | 402 // TODO(jingning): temporarily enabled only for luma component |
371 rd = MIN(rd1, rd2); | 403 rd = MIN(rd1, rd2); |
372 if (plane == 0) | 404 if (plane == 0) |
373 x->zcoeff_blk[tx_size][block] = !x->plane[plane].eobs[block] || | 405 x->zcoeff_blk[tx_size][block] = !x->plane[plane].eobs[block] || |
374 (rd1 > rd2 && !xd->lossless); | 406 (rd1 > rd2 && !xd->lossless); |
375 | 407 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
427 BLOCK_SIZE bs) { | 459 BLOCK_SIZE bs) { |
428 const TX_SIZE max_tx_size = max_txsize_lookup[bs]; | 460 const TX_SIZE max_tx_size = max_txsize_lookup[bs]; |
429 VP9_COMMON *const cm = &cpi->common; | 461 VP9_COMMON *const cm = &cpi->common; |
430 const TX_SIZE largest_tx_size = tx_mode_to_biggest_tx_size[cm->tx_mode]; | 462 const TX_SIZE largest_tx_size = tx_mode_to_biggest_tx_size[cm->tx_mode]; |
431 MACROBLOCKD *const xd = &x->e_mbd; | 463 MACROBLOCKD *const xd = &x->e_mbd; |
432 MB_MODE_INFO *const mbmi = &xd->mi[0]->mbmi; | 464 MB_MODE_INFO *const mbmi = &xd->mi[0]->mbmi; |
433 | 465 |
434 mbmi->tx_size = MIN(max_tx_size, largest_tx_size); | 466 mbmi->tx_size = MIN(max_tx_size, largest_tx_size); |
435 | 467 |
436 txfm_rd_in_plane(x, rate, distortion, skip, | 468 txfm_rd_in_plane(x, rate, distortion, skip, |
437 &sse[mbmi->tx_size], ref_best_rd, 0, bs, | 469 sse, ref_best_rd, 0, bs, |
438 mbmi->tx_size, cpi->sf.use_fast_coef_costing); | 470 mbmi->tx_size, cpi->sf.use_fast_coef_costing); |
439 cpi->tx_stepdown_count[0]++; | 471 cpi->tx_stepdown_count[0]++; |
440 } | 472 } |
441 | 473 |
442 static void choose_tx_size_from_rd(VP9_COMP *cpi, MACROBLOCK *x, | 474 static void choose_tx_size_from_rd(VP9_COMP *cpi, MACROBLOCK *x, |
443 int (*r)[2], int *rate, | 475 int *rate, |
444 int64_t *d, int64_t *distortion, | 476 int64_t *distortion, |
445 int *s, int *skip, | 477 int *skip, |
| 478 int64_t *psse, |
446 int64_t tx_cache[TX_MODES], | 479 int64_t tx_cache[TX_MODES], |
| 480 int64_t ref_best_rd, |
447 BLOCK_SIZE bs) { | 481 BLOCK_SIZE bs) { |
448 const TX_SIZE max_tx_size = max_txsize_lookup[bs]; | 482 const TX_SIZE max_tx_size = max_txsize_lookup[bs]; |
449 VP9_COMMON *const cm = &cpi->common; | 483 VP9_COMMON *const cm = &cpi->common; |
450 MACROBLOCKD *const xd = &x->e_mbd; | 484 MACROBLOCKD *const xd = &x->e_mbd; |
451 MB_MODE_INFO *const mbmi = &xd->mi[0]->mbmi; | 485 MB_MODE_INFO *const mbmi = &xd->mi[0]->mbmi; |
452 vp9_prob skip_prob = vp9_get_skip_prob(cm, xd); | 486 vp9_prob skip_prob = vp9_get_skip_prob(cm, xd); |
| 487 int r[TX_SIZES][2], s[TX_SIZES]; |
| 488 int64_t d[TX_SIZES], sse[TX_SIZES]; |
453 int64_t rd[TX_SIZES][2] = {{INT64_MAX, INT64_MAX}, | 489 int64_t rd[TX_SIZES][2] = {{INT64_MAX, INT64_MAX}, |
454 {INT64_MAX, INT64_MAX}, | 490 {INT64_MAX, INT64_MAX}, |
455 {INT64_MAX, INT64_MAX}, | 491 {INT64_MAX, INT64_MAX}, |
456 {INT64_MAX, INT64_MAX}}; | 492 {INT64_MAX, INT64_MAX}}; |
457 TX_SIZE n, m; | 493 TX_SIZE n, m; |
458 int s0, s1; | 494 int s0, s1; |
459 const TX_SIZE max_mode_tx_size = tx_mode_to_biggest_tx_size[cm->tx_mode]; | 495 const TX_SIZE max_mode_tx_size = tx_mode_to_biggest_tx_size[cm->tx_mode]; |
460 int64_t best_rd = INT64_MAX; | 496 int64_t best_rd = INT64_MAX; |
461 TX_SIZE best_tx = TX_4X4; | 497 TX_SIZE best_tx = TX_4X4; |
462 | 498 |
463 const vp9_prob *tx_probs = get_tx_probs2(max_tx_size, xd, &cm->fc.tx_probs); | 499 const vp9_prob *tx_probs = get_tx_probs2(max_tx_size, xd, &cm->fc.tx_probs); |
464 assert(skip_prob > 0); | 500 assert(skip_prob > 0); |
465 s0 = vp9_cost_bit(skip_prob, 0); | 501 s0 = vp9_cost_bit(skip_prob, 0); |
466 s1 = vp9_cost_bit(skip_prob, 1); | 502 s1 = vp9_cost_bit(skip_prob, 1); |
467 | 503 |
468 for (n = TX_4X4; n <= max_tx_size; n++) { | 504 for (n = TX_4X4; n <= max_tx_size; n++) { |
| 505 txfm_rd_in_plane(x, &r[n][0], &d[n], &s[n], |
| 506 &sse[n], ref_best_rd, 0, bs, n, |
| 507 cpi->sf.use_fast_coef_costing); |
469 r[n][1] = r[n][0]; | 508 r[n][1] = r[n][0]; |
470 if (r[n][0] < INT_MAX) { | 509 if (r[n][0] < INT_MAX) { |
471 for (m = 0; m <= n - (n == max_tx_size); m++) { | 510 for (m = 0; m <= n - (n == max_tx_size); m++) { |
472 if (m == n) | 511 if (m == n) |
473 r[n][1] += vp9_cost_zero(tx_probs[m]); | 512 r[n][1] += vp9_cost_zero(tx_probs[m]); |
474 else | 513 else |
475 r[n][1] += vp9_cost_one(tx_probs[m]); | 514 r[n][1] += vp9_cost_one(tx_probs[m]); |
476 } | 515 } |
477 } | 516 } |
478 if (d[n] == INT64_MAX) { | 517 if (d[n] == INT64_MAX) { |
(...skipping 10 matching lines...) Expand all Loading... |
489 best_rd = rd[n][1]; | 528 best_rd = rd[n][1]; |
490 } | 529 } |
491 } | 530 } |
492 mbmi->tx_size = cm->tx_mode == TX_MODE_SELECT ? | 531 mbmi->tx_size = cm->tx_mode == TX_MODE_SELECT ? |
493 best_tx : MIN(max_tx_size, max_mode_tx_size); | 532 best_tx : MIN(max_tx_size, max_mode_tx_size); |
494 | 533 |
495 | 534 |
496 *distortion = d[mbmi->tx_size]; | 535 *distortion = d[mbmi->tx_size]; |
497 *rate = r[mbmi->tx_size][cm->tx_mode == TX_MODE_SELECT]; | 536 *rate = r[mbmi->tx_size][cm->tx_mode == TX_MODE_SELECT]; |
498 *skip = s[mbmi->tx_size]; | 537 *skip = s[mbmi->tx_size]; |
| 538 *psse = sse[mbmi->tx_size]; |
499 | 539 |
500 tx_cache[ONLY_4X4] = rd[TX_4X4][0]; | 540 tx_cache[ONLY_4X4] = rd[TX_4X4][0]; |
501 tx_cache[ALLOW_8X8] = rd[TX_8X8][0]; | 541 tx_cache[ALLOW_8X8] = rd[TX_8X8][0]; |
502 tx_cache[ALLOW_16X16] = rd[MIN(max_tx_size, TX_16X16)][0]; | 542 tx_cache[ALLOW_16X16] = rd[MIN(max_tx_size, TX_16X16)][0]; |
503 tx_cache[ALLOW_32X32] = rd[MIN(max_tx_size, TX_32X32)][0]; | 543 tx_cache[ALLOW_32X32] = rd[MIN(max_tx_size, TX_32X32)][0]; |
504 | 544 |
505 if (max_tx_size == TX_32X32 && best_tx == TX_32X32) { | 545 if (max_tx_size == TX_32X32 && best_tx == TX_32X32) { |
506 tx_cache[TX_MODE_SELECT] = rd[TX_32X32][1]; | 546 tx_cache[TX_MODE_SELECT] = rd[TX_32X32][1]; |
507 cpi->tx_stepdown_count[0]++; | 547 cpi->tx_stepdown_count[0]++; |
508 } else if (max_tx_size >= TX_16X16 && best_tx == TX_16X16) { | 548 } else if (max_tx_size >= TX_16X16 && best_tx == TX_16X16) { |
509 tx_cache[TX_MODE_SELECT] = rd[TX_16X16][1]; | 549 tx_cache[TX_MODE_SELECT] = rd[TX_16X16][1]; |
510 cpi->tx_stepdown_count[max_tx_size - TX_16X16]++; | 550 cpi->tx_stepdown_count[max_tx_size - TX_16X16]++; |
511 } else if (rd[TX_8X8][1] < rd[TX_4X4][1]) { | 551 } else if (rd[TX_8X8][1] < rd[TX_4X4][1]) { |
512 tx_cache[TX_MODE_SELECT] = rd[TX_8X8][1]; | 552 tx_cache[TX_MODE_SELECT] = rd[TX_8X8][1]; |
513 cpi->tx_stepdown_count[max_tx_size - TX_8X8]++; | 553 cpi->tx_stepdown_count[max_tx_size - TX_8X8]++; |
514 } else { | 554 } else { |
515 tx_cache[TX_MODE_SELECT] = rd[TX_4X4][1]; | 555 tx_cache[TX_MODE_SELECT] = rd[TX_4X4][1]; |
516 cpi->tx_stepdown_count[max_tx_size - TX_4X4]++; | 556 cpi->tx_stepdown_count[max_tx_size - TX_4X4]++; |
517 } | 557 } |
518 } | 558 } |
519 | 559 |
520 static void inter_super_block_yrd(VP9_COMP *cpi, MACROBLOCK *x, int *rate, | 560 static void inter_super_block_yrd(VP9_COMP *cpi, MACROBLOCK *x, int *rate, |
521 int64_t *distortion, int *skip, | 561 int64_t *distortion, int *skip, |
522 int64_t *psse, BLOCK_SIZE bs, | 562 int64_t *psse, BLOCK_SIZE bs, |
523 int64_t txfm_cache[TX_MODES], | 563 int64_t txfm_cache[TX_MODES], |
524 int64_t ref_best_rd) { | 564 int64_t ref_best_rd) { |
525 int r[TX_SIZES][2], s[TX_SIZES]; | |
526 int64_t d[TX_SIZES], sse[TX_SIZES]; | |
527 MACROBLOCKD *xd = &x->e_mbd; | 565 MACROBLOCKD *xd = &x->e_mbd; |
528 MB_MODE_INFO *const mbmi = &xd->mi[0]->mbmi; | |
529 const TX_SIZE max_tx_size = max_txsize_lookup[bs]; | |
530 TX_SIZE tx_size; | |
531 | 566 |
532 assert(bs == mbmi->sb_type); | 567 assert(bs == xd->mi[0]->mbmi.sb_type); |
533 | 568 |
534 vp9_subtract_plane(x, bs, 0); | 569 vp9_subtract_plane(x, bs, 0); |
535 | 570 |
536 if (cpi->sf.tx_size_search_method == USE_LARGESTALL || xd->lossless) { | 571 if (cpi->sf.tx_size_search_method == USE_LARGESTALL || xd->lossless) { |
537 vpx_memset(txfm_cache, 0, TX_MODES * sizeof(int64_t)); | 572 vpx_memset(txfm_cache, 0, TX_MODES * sizeof(int64_t)); |
538 choose_largest_tx_size(cpi, x, rate, distortion, skip, sse, ref_best_rd, | 573 choose_largest_tx_size(cpi, x, rate, distortion, skip, psse, ref_best_rd, |
539 bs); | 574 bs); |
540 if (psse) | 575 } else { |
541 *psse = sse[mbmi->tx_size]; | 576 choose_tx_size_from_rd(cpi, x, rate, distortion, skip, psse, |
542 return; | 577 txfm_cache, ref_best_rd, bs); |
543 } | 578 } |
544 | |
545 for (tx_size = TX_4X4; tx_size <= max_tx_size; ++tx_size) | |
546 txfm_rd_in_plane(x, &r[tx_size][0], &d[tx_size], &s[tx_size], | |
547 &sse[tx_size], ref_best_rd, 0, bs, tx_size, | |
548 cpi->sf.use_fast_coef_costing); | |
549 choose_tx_size_from_rd(cpi, x, r, rate, d, distortion, s, | |
550 skip, txfm_cache, bs); | |
551 | |
552 if (psse) | |
553 *psse = sse[mbmi->tx_size]; | |
554 } | 579 } |
555 | 580 |
556 static void intra_super_block_yrd(VP9_COMP *cpi, MACROBLOCK *x, int *rate, | 581 static void intra_super_block_yrd(VP9_COMP *cpi, MACROBLOCK *x, int *rate, |
557 int64_t *distortion, int *skip, | 582 int64_t *distortion, int *skip, |
558 int64_t *psse, BLOCK_SIZE bs, | 583 BLOCK_SIZE bs, |
559 int64_t txfm_cache[TX_MODES], | 584 int64_t txfm_cache[TX_MODES], |
560 int64_t ref_best_rd) { | 585 int64_t ref_best_rd) { |
561 int64_t sse[TX_SIZES]; | |
562 MACROBLOCKD *xd = &x->e_mbd; | 586 MACROBLOCKD *xd = &x->e_mbd; |
563 MB_MODE_INFO *const mbmi = &xd->mi[0]->mbmi; | 587 int64_t sse; |
564 | 588 |
565 assert(bs == mbmi->sb_type); | 589 assert(bs == xd->mi[0]->mbmi.sb_type); |
566 if (cpi->sf.tx_size_search_method != USE_FULL_RD || xd->lossless) { | 590 if (cpi->sf.tx_size_search_method != USE_FULL_RD || xd->lossless) { |
567 vpx_memset(txfm_cache, 0, TX_MODES * sizeof(int64_t)); | 591 vpx_memset(txfm_cache, 0, TX_MODES * sizeof(int64_t)); |
568 choose_largest_tx_size(cpi, x, rate, distortion, skip, sse, ref_best_rd, | 592 choose_largest_tx_size(cpi, x, rate, distortion, skip, &sse, ref_best_rd, |
569 bs); | 593 bs); |
570 } else { | 594 } else { |
571 int r[TX_SIZES][2], s[TX_SIZES]; | 595 choose_tx_size_from_rd(cpi, x, rate, distortion, skip, &sse, |
572 int64_t d[TX_SIZES]; | 596 txfm_cache, ref_best_rd, bs); |
573 TX_SIZE tx_size; | |
574 for (tx_size = TX_4X4; tx_size <= max_txsize_lookup[bs]; ++tx_size) | |
575 txfm_rd_in_plane(x, &r[tx_size][0], &d[tx_size], | |
576 &s[tx_size], &sse[tx_size], | |
577 ref_best_rd, 0, bs, tx_size, | |
578 cpi->sf.use_fast_coef_costing); | |
579 choose_tx_size_from_rd(cpi, x, r, rate, d, distortion, s, skip, txfm_cache, | |
580 bs); | |
581 } | 597 } |
582 if (psse) | |
583 *psse = sse[mbmi->tx_size]; | |
584 } | 598 } |
585 | 599 |
586 | 600 |
587 static int conditional_skipintra(PREDICTION_MODE mode, | 601 static int conditional_skipintra(PREDICTION_MODE mode, |
588 PREDICTION_MODE best_intra_mode) { | 602 PREDICTION_MODE best_intra_mode) { |
589 if (mode == D117_PRED && | 603 if (mode == D117_PRED && |
590 best_intra_mode != V_PRED && | 604 best_intra_mode != V_PRED && |
591 best_intra_mode != D135_PRED) | 605 best_intra_mode != D135_PRED) |
592 return 1; | 606 return 1; |
593 if (mode == D63_PRED && | 607 if (mode == D63_PRED && |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
827 | 841 |
828 if (cpi->common.frame_type == KEY_FRAME) { | 842 if (cpi->common.frame_type == KEY_FRAME) { |
829 const PREDICTION_MODE A = vp9_above_block_mode(mic, above_mi, 0); | 843 const PREDICTION_MODE A = vp9_above_block_mode(mic, above_mi, 0); |
830 const PREDICTION_MODE L = vp9_left_block_mode(mic, left_mi, 0); | 844 const PREDICTION_MODE L = vp9_left_block_mode(mic, left_mi, 0); |
831 | 845 |
832 bmode_costs = cpi->y_mode_costs[A][L]; | 846 bmode_costs = cpi->y_mode_costs[A][L]; |
833 } | 847 } |
834 mic->mbmi.mode = mode; | 848 mic->mbmi.mode = mode; |
835 | 849 |
836 intra_super_block_yrd(cpi, x, &this_rate_tokenonly, &this_distortion, | 850 intra_super_block_yrd(cpi, x, &this_rate_tokenonly, &this_distortion, |
837 &s, NULL, bsize, local_tx_cache, best_rd); | 851 &s, bsize, local_tx_cache, best_rd); |
838 | 852 |
839 if (this_rate_tokenonly == INT_MAX) | 853 if (this_rate_tokenonly == INT_MAX) |
840 continue; | 854 continue; |
841 | 855 |
842 this_rate = this_rate_tokenonly + bmode_costs[mode]; | 856 this_rate = this_rate_tokenonly + bmode_costs[mode]; |
843 this_rd = RDCOST(x->rdmult, x->rddiv, this_rate, this_distortion); | 857 this_rd = RDCOST(x->rdmult, x->rddiv, this_rate, this_distortion); |
844 | 858 |
845 if (this_rd < best_rd) { | 859 if (this_rd < best_rd) { |
846 mode_selected = mode; | 860 mode_selected = mode; |
847 best_rd = this_rd; | 861 best_rd = this_rd; |
(...skipping 1151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1999 static INLINE void restore_dst_buf(MACROBLOCKD *xd, | 2013 static INLINE void restore_dst_buf(MACROBLOCKD *xd, |
2000 uint8_t *orig_dst[MAX_MB_PLANE], | 2014 uint8_t *orig_dst[MAX_MB_PLANE], |
2001 int orig_dst_stride[MAX_MB_PLANE]) { | 2015 int orig_dst_stride[MAX_MB_PLANE]) { |
2002 int i; | 2016 int i; |
2003 for (i = 0; i < MAX_MB_PLANE; i++) { | 2017 for (i = 0; i < MAX_MB_PLANE; i++) { |
2004 xd->plane[i].dst.buf = orig_dst[i]; | 2018 xd->plane[i].dst.buf = orig_dst[i]; |
2005 xd->plane[i].dst.stride = orig_dst_stride[i]; | 2019 xd->plane[i].dst.stride = orig_dst_stride[i]; |
2006 } | 2020 } |
2007 } | 2021 } |
2008 | 2022 |
| 2023 static void rd_encode_breakout_test(VP9_COMP *cpi, MACROBLOCK *x, |
| 2024 BLOCK_SIZE bsize, int *rate2, |
| 2025 int64_t *distortion, int64_t *distortion_uv, |
| 2026 int *disable_skip) { |
| 2027 VP9_COMMON *cm = &cpi->common; |
| 2028 MACROBLOCKD *xd = &x->e_mbd; |
| 2029 const BLOCK_SIZE y_size = get_plane_block_size(bsize, &xd->plane[0]); |
| 2030 const BLOCK_SIZE uv_size = get_plane_block_size(bsize, &xd->plane[1]); |
| 2031 unsigned int var, sse; |
| 2032 // Skipping threshold for ac. |
| 2033 unsigned int thresh_ac; |
| 2034 // Skipping threshold for dc |
| 2035 unsigned int thresh_dc; |
| 2036 |
| 2037 var = cpi->fn_ptr[y_size].vf(x->plane[0].src.buf, x->plane[0].src.stride, |
| 2038 xd->plane[0].dst.buf, |
| 2039 xd->plane[0].dst.stride, &sse); |
| 2040 |
| 2041 if (x->encode_breakout > 0) { |
| 2042 // Set a maximum for threshold to avoid big PSNR loss in low bitrate |
| 2043 // case. Use extreme low threshold for static frames to limit skipping. |
| 2044 const unsigned int max_thresh = (cpi->allow_encode_breakout == |
| 2045 ENCODE_BREAKOUT_LIMITED) ? 128 : 36000; |
| 2046 // The encode_breakout input |
| 2047 const unsigned int min_thresh = |
| 2048 MIN(((unsigned int)x->encode_breakout << 4), max_thresh); |
| 2049 |
| 2050 // Calculate threshold according to dequant value. |
| 2051 thresh_ac = (xd->plane[0].dequant[1] * xd->plane[0].dequant[1]) / 9; |
| 2052 thresh_ac = clamp(thresh_ac, min_thresh, max_thresh); |
| 2053 |
| 2054 // Adjust threshold according to partition size. |
| 2055 thresh_ac >>= 8 - (b_width_log2(bsize) + |
| 2056 b_height_log2(bsize)); |
| 2057 thresh_dc = (xd->plane[0].dequant[0] * xd->plane[0].dequant[0] >> 6); |
| 2058 } else { |
| 2059 thresh_ac = 0; |
| 2060 thresh_dc = 0; |
| 2061 } |
| 2062 |
| 2063 // Y skipping condition checking |
| 2064 if (sse < thresh_ac || sse == 0) { |
| 2065 // dc skipping checking |
| 2066 if ((sse - var) < thresh_dc || sse == var) { |
| 2067 unsigned int sse_u, sse_v; |
| 2068 unsigned int var_u, var_v; |
| 2069 |
| 2070 var_u = cpi->fn_ptr[uv_size].vf(x->plane[1].src.buf, |
| 2071 x->plane[1].src.stride, |
| 2072 xd->plane[1].dst.buf, |
| 2073 xd->plane[1].dst.stride, &sse_u); |
| 2074 |
| 2075 // U skipping condition checking |
| 2076 if ((sse_u * 4 < thresh_ac || sse_u == 0) && |
| 2077 (sse_u - var_u < thresh_dc || sse_u == var_u)) { |
| 2078 var_v = cpi->fn_ptr[uv_size].vf(x->plane[2].src.buf, |
| 2079 x->plane[2].src.stride, |
| 2080 xd->plane[2].dst.buf, |
| 2081 xd->plane[2].dst.stride, &sse_v); |
| 2082 |
| 2083 // V skipping condition checking |
| 2084 if ((sse_v * 4 < thresh_ac || sse_v == 0) && |
| 2085 (sse_v - var_v < thresh_dc || sse_v == var_v)) { |
| 2086 x->skip = 1; |
| 2087 |
| 2088 // The cost of skip bit needs to be added. |
| 2089 *rate2 += vp9_cost_bit(vp9_get_skip_prob(cm, xd), 1); |
| 2090 |
| 2091 // Scaling factor for SSE from spatial domain to frequency domain |
| 2092 // is 16. Adjust distortion accordingly. |
| 2093 *distortion_uv = (sse_u + sse_v) << 4; |
| 2094 *distortion = (sse << 4) + *distortion_uv; |
| 2095 |
| 2096 *disable_skip = 1; |
| 2097 } |
| 2098 } |
| 2099 } |
| 2100 } |
| 2101 } |
| 2102 |
2009 static int64_t handle_inter_mode(VP9_COMP *cpi, MACROBLOCK *x, | 2103 static int64_t handle_inter_mode(VP9_COMP *cpi, MACROBLOCK *x, |
2010 BLOCK_SIZE bsize, | 2104 BLOCK_SIZE bsize, |
2011 int64_t txfm_cache[], | 2105 int64_t txfm_cache[], |
2012 int *rate2, int64_t *distortion, | 2106 int *rate2, int64_t *distortion, |
2013 int *skippable, | 2107 int *skippable, |
2014 int *rate_y, int64_t *distortion_y, | 2108 int *rate_y, int64_t *distortion_y, |
2015 int *rate_uv, int64_t *distortion_uv, | 2109 int *rate_uv, int64_t *distortion_uv, |
2016 int *disable_skip, | 2110 int *disable_skip, |
2017 int_mv (*mode_mv)[MAX_REF_FRAMES], | 2111 int_mv (*mode_mv)[MAX_REF_FRAMES], |
2018 int mi_row, int mi_col, | 2112 int mi_row, int mi_col, |
(...skipping 14 matching lines...) Expand all Loading... |
2033 int64_t this_rd = 0; | 2127 int64_t this_rd = 0; |
2034 DECLARE_ALIGNED_ARRAY(16, uint8_t, tmp_buf, MAX_MB_PLANE * 64 * 64); | 2128 DECLARE_ALIGNED_ARRAY(16, uint8_t, tmp_buf, MAX_MB_PLANE * 64 * 64); |
2035 int pred_exists = 0; | 2129 int pred_exists = 0; |
2036 int intpel_mv; | 2130 int intpel_mv; |
2037 int64_t rd, best_rd = INT64_MAX; | 2131 int64_t rd, best_rd = INT64_MAX; |
2038 int best_needs_copy = 0; | 2132 int best_needs_copy = 0; |
2039 uint8_t *orig_dst[MAX_MB_PLANE]; | 2133 uint8_t *orig_dst[MAX_MB_PLANE]; |
2040 int orig_dst_stride[MAX_MB_PLANE]; | 2134 int orig_dst_stride[MAX_MB_PLANE]; |
2041 int rs = 0; | 2135 int rs = 0; |
2042 INTERP_FILTER best_filter = SWITCHABLE; | 2136 INTERP_FILTER best_filter = SWITCHABLE; |
| 2137 int skip_txfm[MAX_MB_PLANE] = {0}; |
| 2138 int64_t bsse[MAX_MB_PLANE] = {0}; |
2043 | 2139 |
2044 int bsl = mi_width_log2_lookup[bsize]; | 2140 int bsl = mi_width_log2_lookup[bsize]; |
2045 int pred_filter_search = cpi->sf.cb_pred_filter_search ? | 2141 int pred_filter_search = cpi->sf.cb_pred_filter_search ? |
2046 (((mi_row + mi_col) >> bsl)) & 0x01 : 0; | 2142 (((mi_row + mi_col) >> bsl) + |
| 2143 get_chessboard_index(cm->current_video_frame)) & 0x1 : 0; |
2047 | 2144 |
2048 if (pred_filter_search) { | 2145 if (pred_filter_search) { |
2049 INTERP_FILTER af = SWITCHABLE, lf = SWITCHABLE; | 2146 INTERP_FILTER af = SWITCHABLE, lf = SWITCHABLE; |
2050 if (xd->up_available) | 2147 if (xd->up_available) |
2051 af = xd->mi[-xd->mi_stride]->mbmi.interp_filter; | 2148 af = xd->mi[-xd->mi_stride]->mbmi.interp_filter; |
2052 if (xd->left_available) | 2149 if (xd->left_available) |
2053 lf = xd->mi[-1]->mbmi.interp_filter; | 2150 lf = xd->mi[-1]->mbmi.interp_filter; |
2054 | 2151 |
2055 if ((this_mode != NEWMV) || (af == lf)) | 2152 if ((this_mode != NEWMV) || (af == lf)) |
2056 best_filter = af; | 2153 best_filter = af; |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2194 return INT64_MAX; | 2291 return INT64_MAX; |
2195 } | 2292 } |
2196 } | 2293 } |
2197 newbest = i == 0 || rd < best_rd; | 2294 newbest = i == 0 || rd < best_rd; |
2198 | 2295 |
2199 if (newbest) { | 2296 if (newbest) { |
2200 best_rd = rd; | 2297 best_rd = rd; |
2201 best_filter = mbmi->interp_filter; | 2298 best_filter = mbmi->interp_filter; |
2202 if (cm->interp_filter == SWITCHABLE && i && !intpel_mv) | 2299 if (cm->interp_filter == SWITCHABLE && i && !intpel_mv) |
2203 best_needs_copy = !best_needs_copy; | 2300 best_needs_copy = !best_needs_copy; |
| 2301 vpx_memcpy(skip_txfm, x->skip_txfm, sizeof(skip_txfm)); |
| 2302 vpx_memcpy(bsse, x->bsse, sizeof(bsse)); |
2204 } | 2303 } |
2205 | 2304 |
2206 if ((cm->interp_filter == SWITCHABLE && newbest) || | 2305 if ((cm->interp_filter == SWITCHABLE && newbest) || |
2207 (cm->interp_filter != SWITCHABLE && | 2306 (cm->interp_filter != SWITCHABLE && |
2208 cm->interp_filter == mbmi->interp_filter)) { | 2307 cm->interp_filter == mbmi->interp_filter)) { |
2209 pred_exists = 1; | 2308 pred_exists = 1; |
2210 } | 2309 } |
2211 } | 2310 } |
2212 restore_dst_buf(xd, orig_dst, orig_dst_stride); | 2311 restore_dst_buf(xd, orig_dst, orig_dst_stride); |
2213 } | 2312 } |
(...skipping 27 matching lines...) Expand all Loading... |
2241 if (rd / 2 > ref_best_rd) { | 2340 if (rd / 2 > ref_best_rd) { |
2242 restore_dst_buf(xd, orig_dst, orig_dst_stride); | 2341 restore_dst_buf(xd, orig_dst, orig_dst_stride); |
2243 return INT64_MAX; | 2342 return INT64_MAX; |
2244 } | 2343 } |
2245 } | 2344 } |
2246 | 2345 |
2247 if (cm->interp_filter == SWITCHABLE) | 2346 if (cm->interp_filter == SWITCHABLE) |
2248 *rate2 += vp9_get_switchable_rate(cpi); | 2347 *rate2 += vp9_get_switchable_rate(cpi); |
2249 | 2348 |
2250 if (!is_comp_pred) { | 2349 if (!is_comp_pred) { |
2251 if (cpi->allow_encode_breakout) { | 2350 if (cpi->allow_encode_breakout) |
2252 const BLOCK_SIZE y_size = get_plane_block_size(bsize, &xd->plane[0]); | 2351 rd_encode_breakout_test(cpi, x, bsize, rate2, distortion, distortion_uv, |
2253 const BLOCK_SIZE uv_size = get_plane_block_size(bsize, &xd->plane[1]); | 2352 disable_skip); |
2254 unsigned int var, sse; | 2353 } |
2255 // Skipping threshold for ac. | |
2256 unsigned int thresh_ac; | |
2257 // Skipping threshold for dc | |
2258 unsigned int thresh_dc; | |
2259 | 2354 |
2260 var = cpi->fn_ptr[y_size].vf(x->plane[0].src.buf, x->plane[0].src.stride, | 2355 vpx_memcpy(x->skip_txfm, skip_txfm, sizeof(skip_txfm)); |
2261 xd->plane[0].dst.buf, | 2356 vpx_memcpy(x->bsse, bsse, sizeof(bsse)); |
2262 xd->plane[0].dst.stride, &sse); | |
2263 | |
2264 if (x->encode_breakout > 0) { | |
2265 // Set a maximum for threshold to avoid big PSNR loss in low bitrate | |
2266 // case. Use extreme low threshold for static frames to limit skipping. | |
2267 const unsigned int max_thresh = (cpi->allow_encode_breakout == | |
2268 ENCODE_BREAKOUT_LIMITED) ? 128 : 36000; | |
2269 // The encode_breakout input | |
2270 const unsigned int min_thresh = | |
2271 MIN(((unsigned int)x->encode_breakout << 4), max_thresh); | |
2272 | |
2273 // Calculate threshold according to dequant value. | |
2274 thresh_ac = (xd->plane[0].dequant[1] * xd->plane[0].dequant[1]) / 9; | |
2275 thresh_ac = clamp(thresh_ac, min_thresh, max_thresh); | |
2276 | |
2277 // Adjust threshold according to partition size. | |
2278 thresh_ac >>= 8 - (b_width_log2(bsize) + | |
2279 b_height_log2(bsize)); | |
2280 thresh_dc = (xd->plane[0].dequant[0] * xd->plane[0].dequant[0] >> 6); | |
2281 } else { | |
2282 thresh_ac = 0; | |
2283 thresh_dc = 0; | |
2284 } | |
2285 | |
2286 // Y skipping condition checking | |
2287 if (sse < thresh_ac || sse == 0) { | |
2288 // dc skipping checking | |
2289 if ((sse - var) < thresh_dc || sse == var) { | |
2290 unsigned int sse_u, sse_v; | |
2291 unsigned int var_u, var_v; | |
2292 | |
2293 var_u = cpi->fn_ptr[uv_size].vf(x->plane[1].src.buf, | |
2294 x->plane[1].src.stride, | |
2295 xd->plane[1].dst.buf, | |
2296 xd->plane[1].dst.stride, &sse_u); | |
2297 | |
2298 // U skipping condition checking | |
2299 if ((sse_u * 4 < thresh_ac || sse_u == 0) && | |
2300 (sse_u - var_u < thresh_dc || sse_u == var_u)) { | |
2301 var_v = cpi->fn_ptr[uv_size].vf(x->plane[2].src.buf, | |
2302 x->plane[2].src.stride, | |
2303 xd->plane[2].dst.buf, | |
2304 xd->plane[2].dst.stride, &sse_v); | |
2305 | |
2306 // V skipping condition checking | |
2307 if ((sse_v * 4 < thresh_ac || sse_v == 0) && | |
2308 (sse_v - var_v < thresh_dc || sse_v == var_v)) { | |
2309 x->skip = 1; | |
2310 | |
2311 // The cost of skip bit needs to be added. | |
2312 *rate2 += vp9_cost_bit(vp9_get_skip_prob(cm, xd), 1); | |
2313 | |
2314 // Scaling factor for SSE from spatial domain to frequency domain | |
2315 // is 16. Adjust distortion accordingly. | |
2316 *distortion_uv = (sse_u + sse_v) << 4; | |
2317 *distortion = (sse << 4) + *distortion_uv; | |
2318 | |
2319 *disable_skip = 1; | |
2320 this_rd = RDCOST(x->rdmult, x->rddiv, *rate2, *distortion); | |
2321 } | |
2322 } | |
2323 } | |
2324 } | |
2325 } | |
2326 } | |
2327 | 2357 |
2328 if (!x->skip) { | 2358 if (!x->skip) { |
2329 int skippable_y, skippable_uv; | 2359 int skippable_y, skippable_uv; |
2330 int64_t sseuv = INT64_MAX; | 2360 int64_t sseuv = INT64_MAX; |
2331 int64_t rdcosty = INT64_MAX; | 2361 int64_t rdcosty = INT64_MAX; |
2332 | 2362 |
2333 // Y cost and distortion | 2363 // Y cost and distortion |
2334 inter_super_block_yrd(cpi, x, rate_y, distortion_y, &skippable_y, psse, | 2364 inter_super_block_yrd(cpi, x, rate_y, distortion_y, &skippable_y, psse, |
2335 bsize, txfm_cache, ref_best_rd); | 2365 bsize, txfm_cache, ref_best_rd); |
2336 | 2366 |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2521 for (i = 0; i < TX_SIZES; i++) | 2551 for (i = 0; i < TX_SIZES; i++) |
2522 rate_uv_intra[i] = INT_MAX; | 2552 rate_uv_intra[i] = INT_MAX; |
2523 for (i = 0; i < MAX_REF_FRAMES; ++i) | 2553 for (i = 0; i < MAX_REF_FRAMES; ++i) |
2524 x->pred_sse[i] = INT_MAX; | 2554 x->pred_sse[i] = INT_MAX; |
2525 | 2555 |
2526 *returnrate = INT_MAX; | 2556 *returnrate = INT_MAX; |
2527 | 2557 |
2528 for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) { | 2558 for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) { |
2529 x->pred_mv_sad[ref_frame] = INT_MAX; | 2559 x->pred_mv_sad[ref_frame] = INT_MAX; |
2530 if (cpi->ref_frame_flags & flag_list[ref_frame]) { | 2560 if (cpi->ref_frame_flags & flag_list[ref_frame]) { |
2531 setup_buffer_inter(cpi, x, tile, | 2561 setup_buffer_inter(cpi, x, tile, ref_frame, bsize, mi_row, mi_col, |
2532 ref_frame, bsize, mi_row, mi_col, | 2562 frame_mv[NEARESTMV], frame_mv[NEARMV], yv12_mb); |
2533 frame_mv[NEARESTMV], frame_mv[NEARMV], yv12_mb); | |
2534 } | 2563 } |
2535 frame_mv[NEWMV][ref_frame].as_int = INVALID_MV; | 2564 frame_mv[NEWMV][ref_frame].as_int = INVALID_MV; |
2536 frame_mv[ZEROMV][ref_frame].as_int = 0; | 2565 frame_mv[ZEROMV][ref_frame].as_int = 0; |
2537 } | 2566 } |
2538 | 2567 |
2539 for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) { | 2568 for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) { |
2540 // All modes from vp9_mode_order that use this frame as any ref | 2569 // All modes from vp9_mode_order that use this frame as any ref |
2541 static const int ref_frame_mask_all[] = { | 2570 static const int ref_frame_mask_all[] = { |
2542 0x0, 0x123291, 0x25c444, 0x39b722 | 2571 0x0, 0x123291, 0x25c444, 0x39b722 |
2543 }; | 2572 }; |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2629 break; | 2658 break; |
2630 case GOLDEN_FRAME: | 2659 case GOLDEN_FRAME: |
2631 mode_skip_mask |= GOLDEN_FRAME_MODE_MASK; | 2660 mode_skip_mask |= GOLDEN_FRAME_MODE_MASK; |
2632 break; | 2661 break; |
2633 case ALTREF_FRAME: | 2662 case ALTREF_FRAME: |
2634 mode_skip_mask |= ALT_REF_MODE_MASK; | 2663 mode_skip_mask |= ALT_REF_MODE_MASK; |
2635 break; | 2664 break; |
2636 case NONE: | 2665 case NONE: |
2637 case MAX_REF_FRAMES: | 2666 case MAX_REF_FRAMES: |
2638 assert(0 && "Invalid Reference frame"); | 2667 assert(0 && "Invalid Reference frame"); |
| 2668 break; |
2639 } | 2669 } |
2640 } | 2670 } |
2641 if (mode_skip_mask & (1 << mode_index)) | 2671 if (mode_skip_mask & (1 << mode_index)) |
2642 continue; | 2672 continue; |
2643 | 2673 |
2644 // Test best rd so far against threshold for trying this mode. | 2674 // Test best rd so far against threshold for trying this mode. |
2645 if (rd_less_than_thresh(best_rd, rd_threshes[mode_index], | 2675 if (rd_less_than_thresh(best_rd, rd_threshes[mode_index], |
2646 rd_thresh_freq_fact[mode_index])) | 2676 rd_thresh_freq_fact[mode_index])) |
2647 continue; | 2677 continue; |
2648 | 2678 |
2649 this_mode = vp9_mode_order[mode_index].mode; | 2679 this_mode = vp9_mode_order[mode_index].mode; |
2650 ref_frame = vp9_mode_order[mode_index].ref_frame[0]; | 2680 ref_frame = vp9_mode_order[mode_index].ref_frame[0]; |
2651 if (ref_frame != INTRA_FRAME && !(inter_mode_mask & (1 << this_mode))) | 2681 if (ref_frame != INTRA_FRAME && !(inter_mode_mask & (1 << this_mode))) |
2652 continue; | 2682 continue; |
2653 second_ref_frame = vp9_mode_order[mode_index].ref_frame[1]; | 2683 second_ref_frame = vp9_mode_order[mode_index].ref_frame[1]; |
2654 | 2684 |
| 2685 if (cpi->sf.motion_field_mode_search) { |
| 2686 const int mi_width = MIN(num_8x8_blocks_wide_lookup[bsize], |
| 2687 tile->mi_col_end - mi_col); |
| 2688 const int mi_height = MIN(num_8x8_blocks_high_lookup[bsize], |
| 2689 tile->mi_row_end - mi_row); |
| 2690 const int bsl = mi_width_log2(bsize); |
| 2691 int cb_partition_search_ctrl = (((mi_row + mi_col) >> bsl) |
| 2692 + get_chessboard_index(cm->current_video_frame)) & 0x1; |
| 2693 MB_MODE_INFO *ref_mbmi; |
| 2694 int const_motion = 1; |
| 2695 int skip_ref_frame = !cb_partition_search_ctrl; |
| 2696 MV_REFERENCE_FRAME rf = NONE; |
| 2697 int_mv ref_mv; |
| 2698 ref_mv.as_int = INVALID_MV; |
| 2699 |
| 2700 if ((mi_row - 1) >= tile->mi_row_start) { |
| 2701 ref_mv = xd->mi[-xd->mi_stride]->mbmi.mv[0]; |
| 2702 rf = xd->mi[-xd->mi_stride]->mbmi.ref_frame[0]; |
| 2703 for (i = 0; i < mi_width; ++i) { |
| 2704 ref_mbmi = &xd->mi[-xd->mi_stride + i]->mbmi; |
| 2705 const_motion &= (ref_mv.as_int == ref_mbmi->mv[0].as_int) && |
| 2706 (ref_frame == ref_mbmi->ref_frame[0]); |
| 2707 skip_ref_frame &= (rf == ref_mbmi->ref_frame[0]); |
| 2708 } |
| 2709 } |
| 2710 |
| 2711 if ((mi_col - 1) >= tile->mi_col_start) { |
| 2712 if (ref_mv.as_int == INVALID_MV) |
| 2713 ref_mv = xd->mi[-1]->mbmi.mv[0]; |
| 2714 if (rf == NONE) |
| 2715 rf = xd->mi[-1]->mbmi.ref_frame[0]; |
| 2716 for (i = 0; i < mi_height; ++i) { |
| 2717 ref_mbmi = &xd->mi[i * xd->mi_stride - 1]->mbmi; |
| 2718 const_motion &= (ref_mv.as_int == ref_mbmi->mv[0].as_int) && |
| 2719 (ref_frame == ref_mbmi->ref_frame[0]); |
| 2720 skip_ref_frame &= (rf == ref_mbmi->ref_frame[0]); |
| 2721 } |
| 2722 } |
| 2723 |
| 2724 if (skip_ref_frame && this_mode != NEARESTMV && this_mode != NEWMV) |
| 2725 if (rf > INTRA_FRAME) |
| 2726 if (ref_frame != rf) |
| 2727 continue; |
| 2728 |
| 2729 if (const_motion) |
| 2730 if (this_mode == NEARMV || this_mode == ZEROMV) |
| 2731 continue; |
| 2732 } |
| 2733 |
2655 comp_pred = second_ref_frame > INTRA_FRAME; | 2734 comp_pred = second_ref_frame > INTRA_FRAME; |
2656 if (comp_pred) { | 2735 if (comp_pred) { |
2657 if ((mode_search_skip_flags & FLAG_SKIP_COMP_BESTINTRA) && | 2736 if ((mode_search_skip_flags & FLAG_SKIP_COMP_BESTINTRA) && |
2658 best_mode_index >=0 && | 2737 best_mode_index >=0 && |
2659 vp9_mode_order[best_mode_index].ref_frame[0] == INTRA_FRAME) | 2738 vp9_mode_order[best_mode_index].ref_frame[0] == INTRA_FRAME) |
2660 continue; | 2739 continue; |
2661 if ((mode_search_skip_flags & FLAG_SKIP_COMP_REFMISMATCH) && | 2740 if ((mode_search_skip_flags & FLAG_SKIP_COMP_REFMISMATCH) && |
2662 ref_frame != best_inter_ref_frame && | 2741 ref_frame != best_inter_ref_frame && |
2663 second_ref_frame != best_inter_ref_frame) | 2742 second_ref_frame != best_inter_ref_frame) |
2664 continue; | 2743 continue; |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2715 xd->plane[i].pre[0] = yv12_mb[ref_frame][i]; | 2794 xd->plane[i].pre[0] = yv12_mb[ref_frame][i]; |
2716 if (comp_pred) | 2795 if (comp_pred) |
2717 xd->plane[i].pre[1] = yv12_mb[second_ref_frame][i]; | 2796 xd->plane[i].pre[1] = yv12_mb[second_ref_frame][i]; |
2718 } | 2797 } |
2719 | 2798 |
2720 for (i = 0; i < TX_MODES; ++i) | 2799 for (i = 0; i < TX_MODES; ++i) |
2721 tx_cache[i] = INT64_MAX; | 2800 tx_cache[i] = INT64_MAX; |
2722 | 2801 |
2723 if (ref_frame == INTRA_FRAME) { | 2802 if (ref_frame == INTRA_FRAME) { |
2724 TX_SIZE uv_tx; | 2803 TX_SIZE uv_tx; |
2725 intra_super_block_yrd(cpi, x, &rate_y, &distortion_y, &skippable, NULL, | 2804 intra_super_block_yrd(cpi, x, &rate_y, &distortion_y, &skippable, |
2726 bsize, tx_cache, best_rd); | 2805 bsize, tx_cache, best_rd); |
2727 | 2806 |
2728 if (rate_y == INT_MAX) | 2807 if (rate_y == INT_MAX) |
2729 continue; | 2808 continue; |
2730 | 2809 |
2731 uv_tx = get_uv_tx_size_impl(mbmi->tx_size, bsize, pd[1].subsampling_x, | 2810 uv_tx = get_uv_tx_size_impl(mbmi->tx_size, bsize, pd[1].subsampling_x, |
2732 pd[1].subsampling_y); | 2811 pd[1].subsampling_y); |
2733 if (rate_uv_intra[uv_tx] == INT_MAX) { | 2812 if (rate_uv_intra[uv_tx] == INT_MAX) { |
2734 choose_intra_uv_mode(cpi, ctx, bsize, uv_tx, | 2813 choose_intra_uv_mode(cpi, ctx, bsize, uv_tx, |
2735 &rate_uv_intra[uv_tx], &rate_uv_tokenonly[uv_tx], | 2814 &rate_uv_intra[uv_tx], &rate_uv_tokenonly[uv_tx], |
(...skipping 490 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3226 break; | 3305 break; |
3227 case GOLDEN_FRAME: | 3306 case GOLDEN_FRAME: |
3228 mode_skip_mask = 0x0008; | 3307 mode_skip_mask = 0x0008; |
3229 break; | 3308 break; |
3230 case ALTREF_FRAME: | 3309 case ALTREF_FRAME: |
3231 mode_skip_mask = 0x0000; | 3310 mode_skip_mask = 0x0000; |
3232 break; | 3311 break; |
3233 case NONE: | 3312 case NONE: |
3234 case MAX_REF_FRAMES: | 3313 case MAX_REF_FRAMES: |
3235 assert(0 && "Invalid Reference frame"); | 3314 assert(0 && "Invalid Reference frame"); |
| 3315 break; |
3236 } | 3316 } |
3237 } | 3317 } |
3238 if (mode_skip_mask & (1 << ref_index)) | 3318 if (mode_skip_mask & (1 << ref_index)) |
3239 continue; | 3319 continue; |
3240 } | 3320 } |
3241 | 3321 |
3242 // Test best rd so far against threshold for trying this mode. | 3322 // Test best rd so far against threshold for trying this mode. |
3243 if (rd_less_than_thresh(best_rd, | 3323 if (rd_less_than_thresh(best_rd, |
3244 rd_opt->threshes[segment_id][bsize][ref_index], | 3324 rd_opt->threshes[segment_id][bsize][ref_index], |
3245 rd_opt->thresh_freq_fact[bsize][ref_index])) | 3325 rd_opt->thresh_freq_fact[bsize][ref_index])) |
(...skipping 24 matching lines...) Expand all Loading... |
3270 // TODO(jingning, jkoleszar): scaling reference frame not supported for | 3350 // TODO(jingning, jkoleszar): scaling reference frame not supported for |
3271 // sub8x8 blocks. | 3351 // sub8x8 blocks. |
3272 if (ref_frame > INTRA_FRAME && | 3352 if (ref_frame > INTRA_FRAME && |
3273 vp9_is_scaled(&cm->frame_refs[ref_frame - 1].sf)) | 3353 vp9_is_scaled(&cm->frame_refs[ref_frame - 1].sf)) |
3274 continue; | 3354 continue; |
3275 | 3355 |
3276 if (second_ref_frame > INTRA_FRAME && | 3356 if (second_ref_frame > INTRA_FRAME && |
3277 vp9_is_scaled(&cm->frame_refs[second_ref_frame - 1].sf)) | 3357 vp9_is_scaled(&cm->frame_refs[second_ref_frame - 1].sf)) |
3278 continue; | 3358 continue; |
3279 | 3359 |
3280 if (comp_pred) { | 3360 if (comp_pred) |
3281 mode_excluded = mode_excluded ? mode_excluded | 3361 mode_excluded = cm->reference_mode == SINGLE_REFERENCE; |
3282 : cm->reference_mode == SINGLE_REFERENCE; | 3362 else if (ref_frame != INTRA_FRAME) |
3283 } else if (ref_frame != INTRA_FRAME) { | 3363 mode_excluded = cm->reference_mode == COMPOUND_REFERENCE; |
3284 mode_excluded = mode_excluded ? mode_excluded | |
3285 : cm->reference_mode == COMPOUND_REFERENCE; | |
3286 } | |
3287 | 3364 |
3288 // If the segment reference frame feature is enabled.... | 3365 // If the segment reference frame feature is enabled.... |
3289 // then do nothing if the current ref frame is not allowed.. | 3366 // then do nothing if the current ref frame is not allowed.. |
3290 if (vp9_segfeature_active(seg, segment_id, SEG_LVL_REF_FRAME) && | 3367 if (vp9_segfeature_active(seg, segment_id, SEG_LVL_REF_FRAME) && |
3291 vp9_get_segdata(seg, segment_id, SEG_LVL_REF_FRAME) != | 3368 vp9_get_segdata(seg, segment_id, SEG_LVL_REF_FRAME) != |
3292 (int)ref_frame) { | 3369 (int)ref_frame) { |
3293 continue; | 3370 continue; |
3294 // Disable this drop out case if the ref frame | 3371 // Disable this drop out case if the ref frame |
3295 // segment level feature is enabled for this segment. This is to | 3372 // segment level feature is enabled for this segment. This is to |
3296 // prevent the possibility that we end up unable to pick any mode. | 3373 // prevent the possibility that we end up unable to pick any mode. |
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3720 } else { | 3797 } else { |
3721 vp9_zero(best_filter_diff); | 3798 vp9_zero(best_filter_diff); |
3722 } | 3799 } |
3723 | 3800 |
3724 set_ref_ptrs(cm, xd, mbmi->ref_frame[0], mbmi->ref_frame[1]); | 3801 set_ref_ptrs(cm, xd, mbmi->ref_frame[0], mbmi->ref_frame[1]); |
3725 store_coding_context(x, ctx, best_ref_index, | 3802 store_coding_context(x, ctx, best_ref_index, |
3726 best_pred_diff, best_tx_diff, best_filter_diff); | 3803 best_pred_diff, best_tx_diff, best_filter_diff); |
3727 | 3804 |
3728 return best_rd; | 3805 return best_rd; |
3729 } | 3806 } |
OLD | NEW |