Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(65)

Side by Side Diff: source/libvpx/vp9/encoder/vp9_rdopt.c

Issue 111463005: libvpx: Pull from upstream (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/deps/third_party/libvpx/
Patch Set: Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « source/libvpx/vp9/encoder/vp9_rdopt.h ('k') | source/libvpx/vp9/encoder/vp9_sad_c.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <stdio.h> 11 #include <stdio.h>
12 #include <math.h> 12 #include <math.h>
13 #include <limits.h> 13 #include <limits.h>
14 #include <assert.h> 14 #include <assert.h>
15 15
16 #include "vp9/common/vp9_pragmas.h" 16 #include "vp9/common/vp9_pragmas.h"
17 #include "vp9/encoder/vp9_tokenize.h" 17 #include "vp9/encoder/vp9_tokenize.h"
18 #include "vp9/encoder/vp9_treewriter.h" 18 #include "vp9/encoder/vp9_treewriter.h"
19 #include "vp9/encoder/vp9_onyx_int.h" 19 #include "vp9/encoder/vp9_onyx_int.h"
20 #include "vp9/encoder/vp9_modecosts.h"
21 #include "vp9/encoder/vp9_encodeintra.h"
22 #include "vp9/common/vp9_entropymode.h" 20 #include "vp9/common/vp9_entropymode.h"
23 #include "vp9/common/vp9_reconinter.h" 21 #include "vp9/common/vp9_reconinter.h"
24 #include "vp9/common/vp9_reconintra.h" 22 #include "vp9/common/vp9_reconintra.h"
25 #include "vp9/common/vp9_findnearmv.h" 23 #include "vp9/common/vp9_findnearmv.h"
26 #include "vp9/common/vp9_quant_common.h" 24 #include "vp9/common/vp9_quant_common.h"
27 #include "vp9/encoder/vp9_encodemb.h" 25 #include "vp9/encoder/vp9_encodemb.h"
28 #include "vp9/encoder/vp9_quantize.h" 26 #include "vp9/encoder/vp9_quantize.h"
29 #include "vp9/encoder/vp9_variance.h" 27 #include "vp9/encoder/vp9_variance.h"
30 #include "vp9/encoder/vp9_mcomp.h" 28 #include "vp9/encoder/vp9_mcomp.h"
31 #include "vp9/encoder/vp9_rdopt.h" 29 #include "vp9/encoder/vp9_rdopt.h"
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 {2, 3, 3, 4, 6, 6, 8, 12, 12, 16, 24, 24, 32}; 106 {2, 3, 3, 4, 6, 6, 8, 12, 12, 16, 24, 24, 32};
109 107
110 #define RD_THRESH_MAX_FACT 64 108 #define RD_THRESH_MAX_FACT 64
111 #define RD_THRESH_INC 1 109 #define RD_THRESH_INC 1
112 #define RD_THRESH_POW 1.25 110 #define RD_THRESH_POW 1.25
113 #define RD_MULT_EPB_RATIO 64 111 #define RD_MULT_EPB_RATIO 64
114 112
115 #define MV_COST_WEIGHT 108 113 #define MV_COST_WEIGHT 108
116 #define MV_COST_WEIGHT_SUB 120 114 #define MV_COST_WEIGHT_SUB 120
117 115
116 static int raster_block_offset(BLOCK_SIZE plane_bsize,
117 int raster_block, int stride) {
118 const int bw = b_width_log2(plane_bsize);
119 const int y = 4 * (raster_block >> bw);
120 const int x = 4 * (raster_block & ((1 << bw) - 1));
121 return y * stride + x;
122 }
123 static int16_t* raster_block_offset_int16(BLOCK_SIZE plane_bsize,
124 int raster_block, int16_t *base) {
125 const int stride = 4 * num_4x4_blocks_wide_lookup[plane_bsize];
126 return base + raster_block_offset(plane_bsize, raster_block, stride);
127 }
128
129 static void fill_mode_costs(VP9_COMP *c) {
130 VP9_COMMON *const cm = &c->common;
131 int i, j;
132
133 for (i = 0; i < INTRA_MODES; i++)
134 for (j = 0; j < INTRA_MODES; j++)
135 vp9_cost_tokens((int *)c->mb.y_mode_costs[i][j], vp9_kf_y_mode_prob[i][j],
136 vp9_intra_mode_tree);
137
138 // TODO(rbultje) separate tables for superblock costing?
139 vp9_cost_tokens(c->mb.mbmode_cost, cm->fc.y_mode_prob[1],
140 vp9_intra_mode_tree);
141 vp9_cost_tokens(c->mb.intra_uv_mode_cost[1],
142 cm->fc.uv_mode_prob[INTRA_MODES - 1], vp9_intra_mode_tree);
143 vp9_cost_tokens(c->mb.intra_uv_mode_cost[0],
144 vp9_kf_uv_mode_prob[INTRA_MODES - 1],
145 vp9_intra_mode_tree);
146
147 for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; ++i)
148 vp9_cost_tokens((int *)c->mb.switchable_interp_costs[i],
149 cm->fc.switchable_interp_prob[i],
150 vp9_switchable_interp_tree);
151 }
152
118 static void fill_token_costs(vp9_coeff_cost *c, 153 static void fill_token_costs(vp9_coeff_cost *c,
119 vp9_coeff_probs_model (*p)[BLOCK_TYPES]) { 154 vp9_coeff_probs_model (*p)[PLANE_TYPES]) {
120 int i, j, k, l; 155 int i, j, k, l;
121 TX_SIZE t; 156 TX_SIZE t;
122 for (t = TX_4X4; t <= TX_32X32; t++) 157 for (t = TX_4X4; t <= TX_32X32; ++t)
123 for (i = 0; i < BLOCK_TYPES; i++) 158 for (i = 0; i < PLANE_TYPES; ++i)
124 for (j = 0; j < REF_TYPES; j++) 159 for (j = 0; j < REF_TYPES; ++j)
125 for (k = 0; k < COEF_BANDS; k++) 160 for (k = 0; k < COEF_BANDS; ++k)
126 for (l = 0; l < PREV_COEF_CONTEXTS; l++) { 161 for (l = 0; l < BAND_COEFF_CONTEXTS(k); ++l) {
127 vp9_prob probs[ENTROPY_NODES]; 162 vp9_prob probs[ENTROPY_NODES];
128 vp9_model_to_full_probs(p[t][i][j][k][l], probs); 163 vp9_model_to_full_probs(p[t][i][j][k][l], probs);
129 vp9_cost_tokens((int *)c[t][i][j][k][0][l], probs, 164 vp9_cost_tokens((int *)c[t][i][j][k][0][l], probs,
130 vp9_coef_tree); 165 vp9_coef_tree);
131 vp9_cost_tokens_skip((int *)c[t][i][j][k][1][l], probs, 166 vp9_cost_tokens_skip((int *)c[t][i][j][k][1][l], probs,
132 vp9_coef_tree); 167 vp9_coef_tree);
133 assert(c[t][i][j][k][0][l][DCT_EOB_TOKEN] == 168 assert(c[t][i][j][k][0][l][EOB_TOKEN] ==
134 c[t][i][j][k][1][l][DCT_EOB_TOKEN]); 169 c[t][i][j][k][1][l][EOB_TOKEN]);
135 } 170 }
136 } 171 }
137 172
138 static const int rd_iifactor[32] = { 173 static const int rd_iifactor[32] = {
139 4, 4, 3, 2, 1, 0, 0, 0, 174 4, 4, 3, 2, 1, 0, 0, 0,
140 0, 0, 0, 0, 0, 0, 0, 0, 175 0, 0, 0, 0, 0, 0, 0, 0,
141 0, 0, 0, 0, 0, 0, 0, 0, 176 0, 0, 0, 0, 0, 0, 0, 0,
142 0, 0, 0, 0, 0, 0, 0, 0, 177 0, 0, 0, 0, 0, 0, 0, 0,
143 }; 178 };
144 179
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 qindex = clamp(cm->base_qindex + cm->y_dc_delta_q, 0, MAXQ); 274 qindex = clamp(cm->base_qindex + cm->y_dc_delta_q, 0, MAXQ);
240 275
241 cpi->RDDIV = RDDIV_BITS; // in bits (to multiply D by 128) 276 cpi->RDDIV = RDDIV_BITS; // in bits (to multiply D by 128)
242 cpi->RDMULT = vp9_compute_rd_mult(cpi, qindex); 277 cpi->RDMULT = vp9_compute_rd_mult(cpi, qindex);
243 278
244 cpi->mb.errorperbit = cpi->RDMULT / RD_MULT_EPB_RATIO; 279 cpi->mb.errorperbit = cpi->RDMULT / RD_MULT_EPB_RATIO;
245 cpi->mb.errorperbit += (cpi->mb.errorperbit == 0); 280 cpi->mb.errorperbit += (cpi->mb.errorperbit == 0);
246 281
247 vp9_set_speed_features(cpi); 282 vp9_set_speed_features(cpi);
248 283
284 cpi->mb.select_txfm_size = (cpi->sf.tx_size_search_method == USE_LARGESTALL &&
285 cm->frame_type != KEY_FRAME) ?
286 0 : 1;
287
249 set_block_thresholds(cpi); 288 set_block_thresholds(cpi);
250 289
251 fill_token_costs(cpi->mb.token_costs, cm->fc.coef_probs); 290 fill_token_costs(cpi->mb.token_costs, cm->fc.coef_probs);
252 291
253 for (i = 0; i < PARTITION_CONTEXTS; i++) 292 for (i = 0; i < PARTITION_CONTEXTS; i++)
254 vp9_cost_tokens(cpi->mb.partition_cost[i], 293 vp9_cost_tokens(cpi->mb.partition_cost[i], get_partition_probs(cm, i),
255 cm->fc.partition_prob[cm->frame_type][i],
256 vp9_partition_tree); 294 vp9_partition_tree);
257 295
258 /*rough estimate for costing*/ 296 /*rough estimate for costing*/
259 vp9_init_mode_costs(cpi); 297 fill_mode_costs(cpi);
260 298
261 if (!frame_is_intra_only(cm)) { 299 if (!frame_is_intra_only(cm)) {
262 vp9_build_nmv_cost_table( 300 vp9_build_nmv_cost_table(
263 cpi->mb.nmvjointcost, 301 cpi->mb.nmvjointcost,
264 cm->allow_high_precision_mv ? cpi->mb.nmvcost_hp : cpi->mb.nmvcost, 302 cm->allow_high_precision_mv ? cpi->mb.nmvcost_hp : cpi->mb.nmvcost,
265 &cm->fc.nmvc, 303 &cm->fc.nmvc,
266 cm->allow_high_precision_mv, 1, 1); 304 cm->allow_high_precision_mv, 1, 1);
267 305
268 for (i = 0; i < INTER_MODE_CONTEXTS; i++) { 306 for (i = 0; i < INTER_MODE_CONTEXTS; ++i)
269 MB_PREDICTION_MODE m; 307 vp9_cost_tokens((int *)cpi->mb.inter_mode_cost[i],
270 308 cm->fc.inter_mode_probs[i], vp9_inter_mode_tree);
271 for (m = NEARESTMV; m < MB_MODE_COUNT; m++)
272 cpi->mb.inter_mode_cost[i][inter_mode_offset(m)] =
273 cost_token(vp9_inter_mode_tree,
274 cm->fc.inter_mode_probs[i],
275 &vp9_inter_mode_encodings[inter_mode_offset(m)]);
276 }
277 } 309 }
278 } 310 }
279 311
280 static INLINE void linear_interpolate2(double x, int ntab, int inv_step, 312 static INLINE void linear_interpolate2(double x, int ntab, int inv_step,
281 const double *tab1, const double *tab2, 313 const double *tab1, const double *tab2,
282 double *v1, double *v2) { 314 double *v1, double *v2) {
283 double y = x * inv_step; 315 double y = x * inv_step;
284 int d = (int) y; 316 int d = (int) y;
285 if (d >= ntab - 1) { 317 if (d >= ntab - 1) {
286 *v1 = tab1[ntab - 1]; 318 *v1 = tab1[ntab - 1];
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
482 { 1, 2, 3, 4, 11, 1024 - 21, 0 }, 514 { 1, 2, 3, 4, 11, 1024 - 21, 0 },
483 }; 515 };
484 516
485 static INLINE int cost_coeffs(MACROBLOCK *x, 517 static INLINE int cost_coeffs(MACROBLOCK *x,
486 int plane, int block, 518 int plane, int block,
487 ENTROPY_CONTEXT *A, ENTROPY_CONTEXT *L, 519 ENTROPY_CONTEXT *A, ENTROPY_CONTEXT *L,
488 TX_SIZE tx_size, 520 TX_SIZE tx_size,
489 const int16_t *scan, const int16_t *nb) { 521 const int16_t *scan, const int16_t *nb) {
490 MACROBLOCKD *const xd = &x->e_mbd; 522 MACROBLOCKD *const xd = &x->e_mbd;
491 MB_MODE_INFO *mbmi = &xd->mi_8x8[0]->mbmi; 523 MB_MODE_INFO *mbmi = &xd->mi_8x8[0]->mbmi;
524 struct macroblock_plane *p = &x->plane[plane];
492 struct macroblockd_plane *pd = &xd->plane[plane]; 525 struct macroblockd_plane *pd = &xd->plane[plane];
493 const PLANE_TYPE type = pd->plane_type; 526 const PLANE_TYPE type = pd->plane_type;
494 const int16_t *band_count = &band_counts[tx_size][1]; 527 const int16_t *band_count = &band_counts[tx_size][1];
495 const int eob = pd->eobs[block]; 528 const int eob = p->eobs[block];
496 const int16_t *const qcoeff_ptr = BLOCK_OFFSET(pd->qcoeff, block); 529 const int16_t *const qcoeff_ptr = BLOCK_OFFSET(p->qcoeff, block);
497 const int ref = mbmi->ref_frame[0] != INTRA_FRAME; 530 const int ref = mbmi->ref_frame[0] != INTRA_FRAME;
498 unsigned int (*token_costs)[2][PREV_COEF_CONTEXTS][MAX_ENTROPY_TOKENS] = 531 unsigned int (*token_costs)[2][COEFF_CONTEXTS][ENTROPY_TOKENS] =
499 x->token_costs[tx_size][type][ref]; 532 x->token_costs[tx_size][type][ref];
500 const ENTROPY_CONTEXT above_ec = !!*A, left_ec = !!*L; 533 const ENTROPY_CONTEXT above_ec = !!*A, left_ec = !!*L;
501 uint8_t *p_tok = x->token_cache; 534 uint8_t *p_tok = x->token_cache;
502 int pt = combine_entropy_contexts(above_ec, left_ec); 535 int pt = combine_entropy_contexts(above_ec, left_ec);
503 int c, cost; 536 int c, cost;
504 537
505 // Check for consistency of tx_size with mode info 538 // Check for consistency of tx_size with mode info
506 assert(type == PLANE_TYPE_Y_WITH_DC ? mbmi->tx_size == tx_size 539 assert(type == PLANE_TYPE_Y ? mbmi->tx_size == tx_size
507 : get_uv_tx_size(mbmi) == tx_size); 540 : get_uv_tx_size(mbmi) == tx_size);
508 541
509 if (eob == 0) { 542 if (eob == 0) {
510 // single eob token 543 // single eob token
511 cost = token_costs[0][0][pt][DCT_EOB_TOKEN]; 544 cost = token_costs[0][0][pt][EOB_TOKEN];
512 c = 0; 545 c = 0;
513 } else { 546 } else {
514 int band_left = *band_count++; 547 int band_left = *band_count++;
515 548
516 // dc token 549 // dc token
517 int v = qcoeff_ptr[0]; 550 int v = qcoeff_ptr[0];
518 int prev_t = vp9_dct_value_tokens_ptr[v].token; 551 int prev_t = vp9_dct_value_tokens_ptr[v].token;
519 cost = (*token_costs)[0][pt][prev_t] + vp9_dct_value_cost_ptr[v]; 552 cost = (*token_costs)[0][pt][prev_t] + vp9_dct_value_cost_ptr[v];
520 p_tok[0] = vp9_pt_energy_class[prev_t]; 553 p_tok[0] = vp9_pt_energy_class[prev_t];
521 ++token_costs; 554 ++token_costs;
(...skipping 11 matching lines...) Expand all
533 prev_t = t; 566 prev_t = t;
534 if (!--band_left) { 567 if (!--band_left) {
535 band_left = *band_count++; 568 band_left = *band_count++;
536 ++token_costs; 569 ++token_costs;
537 } 570 }
538 } 571 }
539 572
540 // eob token 573 // eob token
541 if (band_left) { 574 if (band_left) {
542 pt = get_coef_context(nb, p_tok, c); 575 pt = get_coef_context(nb, p_tok, c);
543 cost += (*token_costs)[0][pt][DCT_EOB_TOKEN]; 576 cost += (*token_costs)[0][pt][EOB_TOKEN];
544 } 577 }
545 } 578 }
546 579
547 // is eob first coefficient; 580 // is eob first coefficient;
548 *A = *L = (c > 0); 581 *A = *L = (c > 0);
549 582
550 return cost; 583 return cost;
551 } 584 }
552 585
553 static void dist_block(int plane, int block, TX_SIZE tx_size, void *arg) { 586 static void dist_block(int plane, int block, TX_SIZE tx_size, void *arg) {
554 const int ss_txfrm_size = tx_size << 1; 587 const int ss_txfrm_size = tx_size << 1;
555 struct rdcost_block_args* args = arg; 588 struct rdcost_block_args* args = arg;
556 MACROBLOCK* const x = args->x; 589 MACROBLOCK* const x = args->x;
557 MACROBLOCKD* const xd = &x->e_mbd; 590 MACROBLOCKD* const xd = &x->e_mbd;
558 struct macroblock_plane *const p = &x->plane[plane]; 591 struct macroblock_plane *const p = &x->plane[plane];
559 struct macroblockd_plane *const pd = &xd->plane[plane]; 592 struct macroblockd_plane *const pd = &xd->plane[plane];
560 int64_t this_sse; 593 int64_t this_sse;
561 int shift = args->tx_size == TX_32X32 ? 0 : 2; 594 int shift = args->tx_size == TX_32X32 ? 0 : 2;
562 int16_t *const coeff = BLOCK_OFFSET(p->coeff, block); 595 int16_t *const coeff = BLOCK_OFFSET(p->coeff, block);
563 int16_t *const dqcoeff = BLOCK_OFFSET(pd->dqcoeff, block); 596 int16_t *const dqcoeff = BLOCK_OFFSET(pd->dqcoeff, block);
564 args->dist = vp9_block_error(coeff, dqcoeff, 16 << ss_txfrm_size, 597 args->dist = vp9_block_error(coeff, dqcoeff, 16 << ss_txfrm_size,
565 &this_sse) >> shift; 598 &this_sse) >> shift;
566 args->sse = this_sse >> shift; 599 args->sse = this_sse >> shift;
567 600
568 if (x->skip_encode && 601 if (x->skip_encode && !is_inter_block(&xd->mi_8x8[0]->mbmi)) {
569 xd->mi_8x8[0]->mbmi.ref_frame[0] == INTRA_FRAME) {
570 // TODO(jingning): tune the model to better capture the distortion. 602 // TODO(jingning): tune the model to better capture the distortion.
571 int64_t p = (pd->dequant[1] * pd->dequant[1] * 603 int64_t p = (pd->dequant[1] * pd->dequant[1] *
572 (1 << ss_txfrm_size)) >> (shift + 2); 604 (1 << ss_txfrm_size)) >> (shift + 2);
573 args->dist += (p >> 4); 605 args->dist += (p >> 4);
574 args->sse += p; 606 args->sse += p;
575 } 607 }
576 } 608 }
577 609
578 static void rate_block(int plane, int block, BLOCK_SIZE plane_bsize, 610 static void rate_block(int plane, int block, BLOCK_SIZE plane_bsize,
579 TX_SIZE tx_size, void *arg) { 611 TX_SIZE tx_size, void *arg) {
580 struct rdcost_block_args* args = arg; 612 struct rdcost_block_args* args = arg;
581 613
582 int x_idx, y_idx; 614 int x_idx, y_idx;
583 txfrm_block_to_raster_xy(plane_bsize, args->tx_size, block, &x_idx, &y_idx); 615 txfrm_block_to_raster_xy(plane_bsize, args->tx_size, block, &x_idx, &y_idx);
584 616
585 args->rate = cost_coeffs(args->x, plane, block, args->t_above + x_idx, 617 args->rate = cost_coeffs(args->x, plane, block, args->t_above + x_idx,
586 args->t_left + y_idx, args->tx_size, 618 args->t_left + y_idx, args->tx_size,
587 args->scan, args->nb); 619 args->scan, args->nb);
588 } 620 }
589 621
590 static void block_yrd_txfm(int plane, int block, BLOCK_SIZE plane_bsize, 622 static void block_rd_txfm(int plane, int block, BLOCK_SIZE plane_bsize,
591 TX_SIZE tx_size, void *arg) { 623 TX_SIZE tx_size, void *arg) {
592 struct rdcost_block_args *args = arg; 624 struct rdcost_block_args *args = arg;
593 MACROBLOCK *const x = args->x; 625 MACROBLOCK *const x = args->x;
594 MACROBLOCKD *const xd = &x->e_mbd; 626 MACROBLOCKD *const xd = &x->e_mbd;
595 struct encode_b_args encode_args = {x, NULL}; 627 struct encode_b_args encode_args = {x, NULL};
596 int64_t rd1, rd2, rd; 628 int64_t rd1, rd2, rd;
597 629
598 if (args->skip) 630 if (args->skip)
599 return; 631 return;
600 632
601 if (!is_inter_block(&xd->mi_8x8[0]->mbmi)) 633 if (!is_inter_block(&xd->mi_8x8[0]->mbmi))
602 vp9_encode_block_intra(plane, block, plane_bsize, tx_size, &encode_args); 634 vp9_encode_block_intra(plane, block, plane_bsize, tx_size, &encode_args);
603 else 635 else
604 vp9_xform_quant(plane, block, plane_bsize, tx_size, &encode_args); 636 vp9_xform_quant(plane, block, plane_bsize, tx_size, &encode_args);
605 637
606 dist_block(plane, block, tx_size, args); 638 dist_block(plane, block, tx_size, args);
607 rate_block(plane, block, plane_bsize, tx_size, args); 639 rate_block(plane, block, plane_bsize, tx_size, args);
608 rd1 = RDCOST(x->rdmult, x->rddiv, args->rate, args->dist); 640 rd1 = RDCOST(x->rdmult, x->rddiv, args->rate, args->dist);
609 rd2 = RDCOST(x->rdmult, x->rddiv, 0, args->sse); 641 rd2 = RDCOST(x->rdmult, x->rddiv, 0, args->sse);
610 642
611 // TODO(jingning): temporarily enabled only for luma component 643 // TODO(jingning): temporarily enabled only for luma component
612 rd = MIN(rd1, rd2); 644 rd = MIN(rd1, rd2);
613 if (plane == 0) 645 if (plane == 0)
614 x->zcoeff_blk[tx_size][block] = rd1 > rd2 || !xd->plane[plane].eobs[block]; 646 x->zcoeff_blk[tx_size][block] = !x->plane[plane].eobs[block] ||
647 (rd1 > rd2 && !xd->lossless);
615 648
616 args->this_rate += args->rate; 649 args->this_rate += args->rate;
617 args->this_dist += args->dist; 650 args->this_dist += args->dist;
618 args->this_sse += args->sse; 651 args->this_sse += args->sse;
619 args->this_rd += rd; 652 args->this_rd += rd;
620 653
621 if (args->this_rd > args->best_rd) { 654 if (args->this_rd > args->best_rd) {
622 args->skip = 1; 655 args->skip = 1;
623 return; 656 return;
624 } 657 }
(...skipping 21 matching lines...) Expand all
646 for (i = 0; i < num_4x4_h; i += 4) 679 for (i = 0; i < num_4x4_h; i += 4)
647 t_left[i] = !!*(const uint32_t *)&left[i]; 680 t_left[i] = !!*(const uint32_t *)&left[i];
648 break; 681 break;
649 case TX_32X32: 682 case TX_32X32:
650 for (i = 0; i < num_4x4_w; i += 8) 683 for (i = 0; i < num_4x4_w; i += 8)
651 t_above[i] = !!*(const uint64_t *)&above[i]; 684 t_above[i] = !!*(const uint64_t *)&above[i];
652 for (i = 0; i < num_4x4_h; i += 8) 685 for (i = 0; i < num_4x4_h; i += 8)
653 t_left[i] = !!*(const uint64_t *)&left[i]; 686 t_left[i] = !!*(const uint64_t *)&left[i];
654 break; 687 break;
655 default: 688 default:
656 assert(!"Invalid transform size."); 689 assert(0 && "Invalid transform size.");
657 } 690 }
658 } 691 }
659 692
660 static void init_rdcost_stack(MACROBLOCK *x, TX_SIZE tx_size, 693 static void init_rdcost_stack(MACROBLOCK *x, TX_SIZE tx_size,
661 const int num_4x4_w, const int num_4x4_h, 694 const int num_4x4_w, const int num_4x4_h,
662 const int64_t ref_rdcost, 695 const int64_t ref_rdcost,
663 struct rdcost_block_args *arg) { 696 struct rdcost_block_args *arg) {
664 vpx_memset(arg, 0, sizeof(struct rdcost_block_args)); 697 vpx_memset(arg, 0, sizeof(struct rdcost_block_args));
665 arg->x = x; 698 arg->x = x;
666 arg->tx_size = tx_size; 699 arg->tx_size = tx_size;
667 arg->bw = num_4x4_w; 700 arg->bw = num_4x4_w;
668 arg->bh = num_4x4_h; 701 arg->bh = num_4x4_h;
669 arg->best_rd = ref_rdcost; 702 arg->best_rd = ref_rdcost;
670 } 703 }
671 704
672 static void txfm_rd_in_plane(MACROBLOCK *x, 705 static void txfm_rd_in_plane(MACROBLOCK *x,
673 struct rdcost_block_args *rd_stack, 706 struct rdcost_block_args *rd_stack,
674 int *rate, int64_t *distortion, 707 int *rate, int64_t *distortion,
675 int *skippable, int64_t *sse, 708 int *skippable, int64_t *sse,
676 int64_t ref_best_rd, int plane, 709 int64_t ref_best_rd, int plane,
677 BLOCK_SIZE bsize, TX_SIZE tx_size) { 710 BLOCK_SIZE bsize, TX_SIZE tx_size) {
678 MACROBLOCKD *const xd = &x->e_mbd; 711 MACROBLOCKD *const xd = &x->e_mbd;
679 struct macroblockd_plane *const pd = &xd->plane[plane]; 712 struct macroblockd_plane *const pd = &xd->plane[plane];
680 const BLOCK_SIZE bs = get_plane_block_size(bsize, pd); 713 const BLOCK_SIZE bs = get_plane_block_size(bsize, pd);
681 const int num_4x4_w = num_4x4_blocks_wide_lookup[bs]; 714 const int num_4x4_w = num_4x4_blocks_wide_lookup[bs];
682 const int num_4x4_h = num_4x4_blocks_high_lookup[bs]; 715 const int num_4x4_h = num_4x4_blocks_high_lookup[bs];
716 const scan_order *so;
683 717
684 init_rdcost_stack(x, tx_size, num_4x4_w, num_4x4_h, 718 init_rdcost_stack(x, tx_size, num_4x4_w, num_4x4_h,
685 ref_best_rd, rd_stack); 719 ref_best_rd, rd_stack);
686 if (plane == 0) 720 if (plane == 0)
687 xd->mi_8x8[0]->mbmi.tx_size = tx_size; 721 xd->mi_8x8[0]->mbmi.tx_size = tx_size;
688 722
689 vp9_get_entropy_contexts(tx_size, rd_stack->t_above, rd_stack->t_left, 723 vp9_get_entropy_contexts(tx_size, rd_stack->t_above, rd_stack->t_left,
690 pd->above_context, pd->left_context, 724 pd->above_context, pd->left_context,
691 num_4x4_w, num_4x4_h); 725 num_4x4_w, num_4x4_h);
692 726
693 get_scan(xd, tx_size, pd->plane_type, 0, &rd_stack->scan, &rd_stack->nb); 727 so = get_scan(xd, tx_size, pd->plane_type, 0);
728 rd_stack->scan = so->scan;
729 rd_stack->nb = so->neighbors;
694 730
695 foreach_transformed_block_in_plane(xd, bsize, plane, 731 foreach_transformed_block_in_plane(xd, bsize, plane,
696 block_yrd_txfm, rd_stack); 732 block_rd_txfm, rd_stack);
697 if (rd_stack->skip) { 733 if (rd_stack->skip) {
698 *rate = INT_MAX; 734 *rate = INT_MAX;
699 *distortion = INT64_MAX; 735 *distortion = INT64_MAX;
700 *sse = INT64_MAX; 736 *sse = INT64_MAX;
701 *skippable = 0; 737 *skippable = 0;
702 } else { 738 } else {
703 *distortion = rd_stack->this_dist; 739 *distortion = rd_stack->this_dist;
704 *rate = rd_stack->this_rate; 740 *rate = rd_stack->this_rate;
705 *sse = rd_stack->this_sse; 741 *sse = rd_stack->this_sse;
706 *skippable = vp9_is_skippable_in_plane(xd, bsize, plane); 742 *skippable = vp9_is_skippable_in_plane(x, bsize, plane);
707 } 743 }
708 } 744 }
709 745
710 static void choose_largest_txfm_size(VP9_COMP *cpi, MACROBLOCK *x, 746 static void choose_largest_txfm_size(VP9_COMP *cpi, MACROBLOCK *x,
711 int *rate, int64_t *distortion, 747 int *rate, int64_t *distortion,
712 int *skip, int64_t *sse, 748 int *skip, int64_t *sse,
713 int64_t ref_best_rd, 749 int64_t ref_best_rd,
714 BLOCK_SIZE bs) { 750 BLOCK_SIZE bs) {
715 const TX_SIZE max_tx_size = max_txsize_lookup[bs]; 751 const TX_SIZE max_tx_size = max_txsize_lookup[bs];
716 VP9_COMMON *const cm = &cpi->common; 752 VP9_COMMON *const cm = &cpi->common;
(...skipping 12 matching lines...) Expand all
729 static void choose_txfm_size_from_rd(VP9_COMP *cpi, MACROBLOCK *x, 765 static void choose_txfm_size_from_rd(VP9_COMP *cpi, MACROBLOCK *x,
730 int (*r)[2], int *rate, 766 int (*r)[2], int *rate,
731 int64_t *d, int64_t *distortion, 767 int64_t *d, int64_t *distortion,
732 int *s, int *skip, 768 int *s, int *skip,
733 int64_t tx_cache[TX_MODES], 769 int64_t tx_cache[TX_MODES],
734 BLOCK_SIZE bs) { 770 BLOCK_SIZE bs) {
735 const TX_SIZE max_tx_size = max_txsize_lookup[bs]; 771 const TX_SIZE max_tx_size = max_txsize_lookup[bs];
736 VP9_COMMON *const cm = &cpi->common; 772 VP9_COMMON *const cm = &cpi->common;
737 MACROBLOCKD *const xd = &x->e_mbd; 773 MACROBLOCKD *const xd = &x->e_mbd;
738 MB_MODE_INFO *const mbmi = &xd->mi_8x8[0]->mbmi; 774 MB_MODE_INFO *const mbmi = &xd->mi_8x8[0]->mbmi;
739 vp9_prob skip_prob = vp9_get_pred_prob_mbskip(cm, xd); 775 vp9_prob skip_prob = vp9_get_skip_prob(cm, xd);
740 int64_t rd[TX_SIZES][2]; 776 int64_t rd[TX_SIZES][2];
741 int n, m; 777 int n, m;
742 int s0, s1; 778 int s0, s1;
779 const TX_SIZE max_mode_tx_size = tx_mode_to_biggest_tx_size[cm->tx_mode];
780 int64_t best_rd = INT64_MAX;
781 TX_SIZE best_tx = TX_4X4;
743 782
744 const vp9_prob *tx_probs = get_tx_probs2(xd, &cm->fc.tx_probs, xd->mi_8x8[0]); 783 const vp9_prob *tx_probs = get_tx_probs2(max_tx_size, xd, &cm->fc.tx_probs);
745
746 for (n = TX_4X4; n <= max_tx_size; n++) {
747 r[n][1] = r[n][0];
748 if (r[n][0] == INT_MAX)
749 continue;
750 for (m = 0; m <= n - (n == max_tx_size); m++) {
751 if (m == n)
752 r[n][1] += vp9_cost_zero(tx_probs[m]);
753 else
754 r[n][1] += vp9_cost_one(tx_probs[m]);
755 }
756 }
757
758 assert(skip_prob > 0); 784 assert(skip_prob > 0);
759 s0 = vp9_cost_bit(skip_prob, 0); 785 s0 = vp9_cost_bit(skip_prob, 0);
760 s1 = vp9_cost_bit(skip_prob, 1); 786 s1 = vp9_cost_bit(skip_prob, 1);
761 787
762 for (n = TX_4X4; n <= max_tx_size; n++) { 788 for (n = TX_4X4; n <= max_tx_size; n++) {
789 r[n][1] = r[n][0];
790 if (r[n][0] < INT_MAX) {
791 for (m = 0; m <= n - (n == max_tx_size); m++) {
792 if (m == n)
793 r[n][1] += vp9_cost_zero(tx_probs[m]);
794 else
795 r[n][1] += vp9_cost_one(tx_probs[m]);
796 }
797 }
763 if (d[n] == INT64_MAX) { 798 if (d[n] == INT64_MAX) {
764 rd[n][0] = rd[n][1] = INT64_MAX; 799 rd[n][0] = rd[n][1] = INT64_MAX;
765 continue; 800 } else if (s[n]) {
766 }
767 if (s[n]) {
768 rd[n][0] = rd[n][1] = RDCOST(x->rdmult, x->rddiv, s1, d[n]); 801 rd[n][0] = rd[n][1] = RDCOST(x->rdmult, x->rddiv, s1, d[n]);
769 } else { 802 } else {
770 rd[n][0] = RDCOST(x->rdmult, x->rddiv, r[n][0] + s0, d[n]); 803 rd[n][0] = RDCOST(x->rdmult, x->rddiv, r[n][0] + s0, d[n]);
771 rd[n][1] = RDCOST(x->rdmult, x->rddiv, r[n][1] + s0, d[n]); 804 rd[n][1] = RDCOST(x->rdmult, x->rddiv, r[n][1] + s0, d[n]);
772 } 805 }
806
807 if (rd[n][1] < best_rd) {
808 best_tx = n;
809 best_rd = rd[n][1];
810 }
773 } 811 }
812 mbmi->tx_size = cm->tx_mode == TX_MODE_SELECT ?
813 best_tx : MIN(max_tx_size, max_mode_tx_size);
774 814
775 if (max_tx_size == TX_32X32 &&
776 (cm->tx_mode == ALLOW_32X32 ||
777 (cm->tx_mode == TX_MODE_SELECT &&
778 rd[TX_32X32][1] < rd[TX_16X16][1] && rd[TX_32X32][1] < rd[TX_8X8][1] &&
779 rd[TX_32X32][1] < rd[TX_4X4][1]))) {
780 mbmi->tx_size = TX_32X32;
781 } else if (max_tx_size >= TX_16X16 &&
782 (cm->tx_mode == ALLOW_16X16 ||
783 cm->tx_mode == ALLOW_32X32 ||
784 (cm->tx_mode == TX_MODE_SELECT &&
785 rd[TX_16X16][1] < rd[TX_8X8][1] &&
786 rd[TX_16X16][1] < rd[TX_4X4][1]))) {
787 mbmi->tx_size = TX_16X16;
788 } else if (cm->tx_mode == ALLOW_8X8 ||
789 cm->tx_mode == ALLOW_16X16 ||
790 cm->tx_mode == ALLOW_32X32 ||
791 (cm->tx_mode == TX_MODE_SELECT && rd[TX_8X8][1] < rd[TX_4X4][1])) {
792 mbmi->tx_size = TX_8X8;
793 } else {
794 mbmi->tx_size = TX_4X4;
795 }
796 815
797 *distortion = d[mbmi->tx_size]; 816 *distortion = d[mbmi->tx_size];
798 *rate = r[mbmi->tx_size][cm->tx_mode == TX_MODE_SELECT]; 817 *rate = r[mbmi->tx_size][cm->tx_mode == TX_MODE_SELECT];
799 *skip = s[mbmi->tx_size]; 818 *skip = s[mbmi->tx_size];
800 819
801 tx_cache[ONLY_4X4] = rd[TX_4X4][0]; 820 tx_cache[ONLY_4X4] = rd[TX_4X4][0];
802 tx_cache[ALLOW_8X8] = rd[TX_8X8][0]; 821 tx_cache[ALLOW_8X8] = rd[TX_8X8][0];
803 tx_cache[ALLOW_16X16] = rd[MIN(max_tx_size, TX_16X16)][0]; 822 tx_cache[ALLOW_16X16] = rd[MIN(max_tx_size, TX_16X16)][0];
804 tx_cache[ALLOW_32X32] = rd[MIN(max_tx_size, TX_32X32)][0]; 823 tx_cache[ALLOW_32X32] = rd[MIN(max_tx_size, TX_32X32)][0];
805 if (max_tx_size == TX_32X32 && 824
806 rd[TX_32X32][1] < rd[TX_16X16][1] && rd[TX_32X32][1] < rd[TX_8X8][1] && 825 if (max_tx_size == TX_32X32 && best_tx == TX_32X32) {
807 rd[TX_32X32][1] < rd[TX_4X4][1])
808 tx_cache[TX_MODE_SELECT] = rd[TX_32X32][1]; 826 tx_cache[TX_MODE_SELECT] = rd[TX_32X32][1];
809 else if (max_tx_size >= TX_16X16 && 827 cpi->tx_stepdown_count[0]++;
810 rd[TX_16X16][1] < rd[TX_8X8][1] && rd[TX_16X16][1] < rd[TX_4X4][1]) 828 } else if (max_tx_size >= TX_16X16 && best_tx == TX_16X16) {
811 tx_cache[TX_MODE_SELECT] = rd[TX_16X16][1]; 829 tx_cache[TX_MODE_SELECT] = rd[TX_16X16][1];
812 else
813 tx_cache[TX_MODE_SELECT] = rd[TX_4X4][1] < rd[TX_8X8][1] ?
814 rd[TX_4X4][1] : rd[TX_8X8][1];
815
816 if (max_tx_size == TX_32X32 &&
817 rd[TX_32X32][1] < rd[TX_16X16][1] &&
818 rd[TX_32X32][1] < rd[TX_8X8][1] &&
819 rd[TX_32X32][1] < rd[TX_4X4][1]) {
820 cpi->tx_stepdown_count[0]++;
821 } else if (max_tx_size >= TX_16X16 &&
822 rd[TX_16X16][1] < rd[TX_8X8][1] &&
823 rd[TX_16X16][1] < rd[TX_4X4][1]) {
824 cpi->tx_stepdown_count[max_tx_size - TX_16X16]++; 830 cpi->tx_stepdown_count[max_tx_size - TX_16X16]++;
825 } else if (rd[TX_8X8][1] < rd[TX_4X4][1]) { 831 } else if (rd[TX_8X8][1] < rd[TX_4X4][1]) {
832 tx_cache[TX_MODE_SELECT] = rd[TX_8X8][1];
826 cpi->tx_stepdown_count[max_tx_size - TX_8X8]++; 833 cpi->tx_stepdown_count[max_tx_size - TX_8X8]++;
827 } else { 834 } else {
835 tx_cache[TX_MODE_SELECT] = rd[TX_4X4][1];
828 cpi->tx_stepdown_count[max_tx_size - TX_4X4]++; 836 cpi->tx_stepdown_count[max_tx_size - TX_4X4]++;
829 } 837 }
830 } 838 }
831 839
832 static void choose_txfm_size_from_modelrd(VP9_COMP *cpi, MACROBLOCK *x, 840 static void choose_txfm_size_from_modelrd(VP9_COMP *cpi, MACROBLOCK *x,
833 int (*r)[2], int *rate, 841 int (*r)[2], int *rate,
834 int64_t *d, int64_t *distortion, 842 int64_t *d, int64_t *distortion,
835 int *s, int *skip, int64_t *sse, 843 int *s, int *skip, int64_t *sse,
836 int64_t ref_best_rd, 844 int64_t ref_best_rd,
837 BLOCK_SIZE bs) { 845 BLOCK_SIZE bs) {
838 const TX_SIZE max_tx_size = max_txsize_lookup[bs]; 846 const TX_SIZE max_tx_size = max_txsize_lookup[bs];
839 VP9_COMMON *const cm = &cpi->common; 847 VP9_COMMON *const cm = &cpi->common;
840 MACROBLOCKD *const xd = &x->e_mbd; 848 MACROBLOCKD *const xd = &x->e_mbd;
841 MB_MODE_INFO *const mbmi = &xd->mi_8x8[0]->mbmi; 849 MB_MODE_INFO *const mbmi = &xd->mi_8x8[0]->mbmi;
842 vp9_prob skip_prob = vp9_get_pred_prob_mbskip(cm, xd); 850 vp9_prob skip_prob = vp9_get_skip_prob(cm, xd);
843 int64_t rd[TX_SIZES][2]; 851 int64_t rd[TX_SIZES][2];
844 int n, m; 852 int n, m;
845 int s0, s1; 853 int s0, s1;
846 double scale_rd[TX_SIZES] = {1.73, 1.44, 1.20, 1.00}; 854 double scale_rd[TX_SIZES] = {1.73, 1.44, 1.20, 1.00};
847 // double scale_r[TX_SIZES] = {2.82, 2.00, 1.41, 1.00}; 855 const TX_SIZE max_mode_tx_size = tx_mode_to_biggest_tx_size[cm->tx_mode];
856 int64_t best_rd = INT64_MAX;
857 TX_SIZE best_tx = TX_4X4;
848 858
849 const vp9_prob *tx_probs = get_tx_probs2(xd, &cm->fc.tx_probs, xd->mi_8x8[0]); 859 const vp9_prob *tx_probs = get_tx_probs2(max_tx_size, xd, &cm->fc.tx_probs);
850 860 assert(skip_prob > 0);
851 // for (n = TX_4X4; n <= max_txfm_size; n++) 861 s0 = vp9_cost_bit(skip_prob, 0);
852 // r[n][0] = (r[n][0] * scale_r[n]); 862 s1 = vp9_cost_bit(skip_prob, 1);
853 863
854 for (n = TX_4X4; n <= max_tx_size; n++) { 864 for (n = TX_4X4; n <= max_tx_size; n++) {
865 double scale = scale_rd[n];
855 r[n][1] = r[n][0]; 866 r[n][1] = r[n][0];
856 for (m = 0; m <= n - (n == max_tx_size); m++) { 867 for (m = 0; m <= n - (n == max_tx_size); m++) {
857 if (m == n) 868 if (m == n)
858 r[n][1] += vp9_cost_zero(tx_probs[m]); 869 r[n][1] += vp9_cost_zero(tx_probs[m]);
859 else 870 else
860 r[n][1] += vp9_cost_one(tx_probs[m]); 871 r[n][1] += vp9_cost_one(tx_probs[m]);
861 } 872 }
873 if (s[n]) {
874 rd[n][0] = rd[n][1] = RDCOST(x->rdmult, x->rddiv, s1, d[n]) * scale;
875 } else {
876 rd[n][0] = RDCOST(x->rdmult, x->rddiv, r[n][0] + s0, d[n]) * scale;
877 rd[n][1] = RDCOST(x->rdmult, x->rddiv, r[n][1] + s0, d[n]) * scale;
878 }
879 if (rd[n][1] < best_rd) {
880 best_rd = rd[n][1];
881 best_tx = n;
882 }
862 } 883 }
863 884
864 assert(skip_prob > 0); 885 mbmi->tx_size = cm->tx_mode == TX_MODE_SELECT ?
865 s0 = vp9_cost_bit(skip_prob, 0); 886 best_tx : MIN(max_tx_size, max_mode_tx_size);
866 s1 = vp9_cost_bit(skip_prob, 1);
867
868 for (n = TX_4X4; n <= max_tx_size; n++) {
869 if (s[n]) {
870 rd[n][0] = rd[n][1] = RDCOST(x->rdmult, x->rddiv, s1, d[n]);
871 } else {
872 rd[n][0] = RDCOST(x->rdmult, x->rddiv, r[n][0] + s0, d[n]);
873 rd[n][1] = RDCOST(x->rdmult, x->rddiv, r[n][1] + s0, d[n]);
874 }
875 }
876 for (n = TX_4X4; n <= max_tx_size; n++) {
877 rd[n][0] = (int64_t)(scale_rd[n] * rd[n][0]);
878 rd[n][1] = (int64_t)(scale_rd[n] * rd[n][1]);
879 }
880
881 if (max_tx_size == TX_32X32 &&
882 (cm->tx_mode == ALLOW_32X32 ||
883 (cm->tx_mode == TX_MODE_SELECT &&
884 rd[TX_32X32][1] <= rd[TX_16X16][1] &&
885 rd[TX_32X32][1] <= rd[TX_8X8][1] &&
886 rd[TX_32X32][1] <= rd[TX_4X4][1]))) {
887 mbmi->tx_size = TX_32X32;
888 } else if (max_tx_size >= TX_16X16 &&
889 (cm->tx_mode == ALLOW_16X16 ||
890 cm->tx_mode == ALLOW_32X32 ||
891 (cm->tx_mode == TX_MODE_SELECT &&
892 rd[TX_16X16][1] <= rd[TX_8X8][1] &&
893 rd[TX_16X16][1] <= rd[TX_4X4][1]))) {
894 mbmi->tx_size = TX_16X16;
895 } else if (cm->tx_mode == ALLOW_8X8 ||
896 cm->tx_mode == ALLOW_16X16 ||
897 cm->tx_mode == ALLOW_32X32 ||
898 (cm->tx_mode == TX_MODE_SELECT &&
899 rd[TX_8X8][1] <= rd[TX_4X4][1])) {
900 mbmi->tx_size = TX_8X8;
901 } else {
902 mbmi->tx_size = TX_4X4;
903 }
904 887
905 // Actually encode using the chosen mode if a model was used, but do not 888 // Actually encode using the chosen mode if a model was used, but do not
906 // update the r, d costs 889 // update the r, d costs
907 txfm_rd_in_plane(x, &cpi->rdcost_stack, rate, distortion, skip, 890 txfm_rd_in_plane(x, &cpi->rdcost_stack, rate, distortion, skip,
908 &sse[mbmi->tx_size], ref_best_rd, 0, bs, mbmi->tx_size); 891 &sse[mbmi->tx_size], ref_best_rd, 0, bs, mbmi->tx_size);
909 892
910 if (max_tx_size == TX_32X32 && 893 if (max_tx_size == TX_32X32 && best_tx == TX_32X32) {
911 rd[TX_32X32][1] <= rd[TX_16X16][1] &&
912 rd[TX_32X32][1] <= rd[TX_8X8][1] &&
913 rd[TX_32X32][1] <= rd[TX_4X4][1]) {
914 cpi->tx_stepdown_count[0]++; 894 cpi->tx_stepdown_count[0]++;
915 } else if (max_tx_size >= TX_16X16 && 895 } else if (max_tx_size >= TX_16X16 && best_tx == TX_16X16) {
916 rd[TX_16X16][1] <= rd[TX_8X8][1] &&
917 rd[TX_16X16][1] <= rd[TX_4X4][1]) {
918 cpi->tx_stepdown_count[max_tx_size - TX_16X16]++; 896 cpi->tx_stepdown_count[max_tx_size - TX_16X16]++;
919 } else if (rd[TX_8X8][1] <= rd[TX_4X4][1]) { 897 } else if (rd[TX_8X8][1] <= rd[TX_4X4][1]) {
920 cpi->tx_stepdown_count[max_tx_size - TX_8X8]++; 898 cpi->tx_stepdown_count[max_tx_size - TX_8X8]++;
921 } else { 899 } else {
922 cpi->tx_stepdown_count[max_tx_size - TX_4X4]++; 900 cpi->tx_stepdown_count[max_tx_size - TX_4X4]++;
923 } 901 }
924 } 902 }
925 903
926 static void super_block_yrd(VP9_COMP *cpi, 904 static void super_block_yrd(VP9_COMP *cpi,
927 MACROBLOCK *x, int *rate, int64_t *distortion, 905 MACROBLOCK *x, int *rate, int64_t *distortion,
928 int *skip, int64_t *psse, BLOCK_SIZE bs, 906 int *skip, int64_t *psse, BLOCK_SIZE bs,
929 int64_t txfm_cache[TX_MODES], 907 int64_t txfm_cache[TX_MODES],
930 int64_t ref_best_rd) { 908 int64_t ref_best_rd) {
931 int r[TX_SIZES][2], s[TX_SIZES]; 909 int r[TX_SIZES][2], s[TX_SIZES];
932 int64_t d[TX_SIZES], sse[TX_SIZES]; 910 int64_t d[TX_SIZES], sse[TX_SIZES];
933 MACROBLOCKD *xd = &x->e_mbd; 911 MACROBLOCKD *xd = &x->e_mbd;
934 MB_MODE_INFO *const mbmi = &xd->mi_8x8[0]->mbmi; 912 MB_MODE_INFO *const mbmi = &xd->mi_8x8[0]->mbmi;
935 struct rdcost_block_args *rdcost_stack = &cpi->rdcost_stack; 913 struct rdcost_block_args *rdcost_stack = &cpi->rdcost_stack;
936 const int b_inter_mode = is_inter_block(mbmi); 914 const int b_inter_mode = is_inter_block(mbmi);
915 const TX_SIZE max_tx_size = max_txsize_lookup[bs];
916 TX_SIZE tx_size;
917
937 918
938 assert(bs == mbmi->sb_type); 919 assert(bs == mbmi->sb_type);
939 if (b_inter_mode) 920 if (b_inter_mode)
940 vp9_subtract_sby(x, bs); 921 vp9_subtract_sby(x, bs);
941 922
942 if (cpi->sf.tx_size_search_method == USE_LARGESTALL || 923 if (cpi->sf.tx_size_search_method == USE_LARGESTALL ||
943 (cpi->sf.tx_size_search_method != USE_FULL_RD && 924 (cpi->sf.tx_size_search_method != USE_FULL_RD &&
944 !b_inter_mode)) { 925 !b_inter_mode)) {
945 vpx_memset(txfm_cache, 0, TX_MODES * sizeof(int64_t)); 926 vpx_memset(txfm_cache, 0, TX_MODES * sizeof(int64_t));
946 choose_largest_txfm_size(cpi, x, rate, distortion, skip, sse, 927 choose_largest_txfm_size(cpi, x, rate, distortion, skip, sse,
947 ref_best_rd, bs); 928 ref_best_rd, bs);
948 if (psse) 929 if (psse)
949 *psse = sse[mbmi->tx_size]; 930 *psse = sse[mbmi->tx_size];
950 return; 931 return;
951 } 932 }
952 933
953 if (cpi->sf.tx_size_search_method == USE_LARGESTINTRA_MODELINTER && 934 if (cpi->sf.tx_size_search_method == USE_LARGESTINTRA_MODELINTER &&
954 b_inter_mode) { 935 b_inter_mode) {
955 if (bs >= BLOCK_32X32) 936 for (tx_size = TX_4X4; tx_size <= max_tx_size; ++tx_size)
956 model_rd_for_sb_y_tx(cpi, bs, TX_32X32, x, xd, 937 model_rd_for_sb_y_tx(cpi, bs, tx_size, x, xd,
957 &r[TX_32X32][0], &d[TX_32X32], &s[TX_32X32]); 938 &r[tx_size][0], &d[tx_size], &s[tx_size]);
958 if (bs >= BLOCK_16X16)
959 model_rd_for_sb_y_tx(cpi, bs, TX_16X16, x, xd,
960 &r[TX_16X16][0], &d[TX_16X16], &s[TX_16X16]);
961
962 model_rd_for_sb_y_tx(cpi, bs, TX_8X8, x, xd,
963 &r[TX_8X8][0], &d[TX_8X8], &s[TX_8X8]);
964
965 model_rd_for_sb_y_tx(cpi, bs, TX_4X4, x, xd,
966 &r[TX_4X4][0], &d[TX_4X4], &s[TX_4X4]);
967
968 choose_txfm_size_from_modelrd(cpi, x, r, rate, d, distortion, s, 939 choose_txfm_size_from_modelrd(cpi, x, r, rate, d, distortion, s,
969 skip, sse, ref_best_rd, bs); 940 skip, sse, ref_best_rd, bs);
970 } else { 941 } else {
971 if (bs >= BLOCK_32X32) 942 for (tx_size = TX_4X4; tx_size <= max_tx_size; ++tx_size)
972 txfm_rd_in_plane(x, rdcost_stack, &r[TX_32X32][0], &d[TX_32X32], 943 txfm_rd_in_plane(x, rdcost_stack, &r[tx_size][0], &d[tx_size],
973 &s[TX_32X32], &sse[TX_32X32], 944 &s[tx_size], &sse[tx_size],
974 ref_best_rd, 0, bs, TX_32X32); 945 ref_best_rd, 0, bs, tx_size);
975 if (bs >= BLOCK_16X16)
976 txfm_rd_in_plane(x, rdcost_stack, &r[TX_16X16][0], &d[TX_16X16],
977 &s[TX_16X16], &sse[TX_16X16],
978 ref_best_rd, 0, bs, TX_16X16);
979 txfm_rd_in_plane(x, rdcost_stack, &r[TX_8X8][0], &d[TX_8X8], &s[TX_8X8],
980 &sse[TX_8X8], ref_best_rd, 0, bs, TX_8X8);
981 txfm_rd_in_plane(x, rdcost_stack, &r[TX_4X4][0], &d[TX_4X4], &s[TX_4X4],
982 &sse[TX_4X4], ref_best_rd, 0, bs, TX_4X4);
983 choose_txfm_size_from_rd(cpi, x, r, rate, d, distortion, s, 946 choose_txfm_size_from_rd(cpi, x, r, rate, d, distortion, s,
984 skip, txfm_cache, bs); 947 skip, txfm_cache, bs);
985 } 948 }
986 if (psse) 949 if (psse)
987 *psse = sse[mbmi->tx_size]; 950 *psse = sse[mbmi->tx_size];
988 } 951 }
989 952
990 static int conditional_skipintra(MB_PREDICTION_MODE mode, 953 static int conditional_skipintra(MB_PREDICTION_MODE mode,
991 MB_PREDICTION_MODE best_intra_mode) { 954 MB_PREDICTION_MODE best_intra_mode) {
992 if (mode == D117_PRED && 955 if (mode == D117_PRED &&
(...skipping 24 matching lines...) Expand all
1017 BLOCK_SIZE bsize, int64_t rd_thresh) { 980 BLOCK_SIZE bsize, int64_t rd_thresh) {
1018 MB_PREDICTION_MODE mode; 981 MB_PREDICTION_MODE mode;
1019 MACROBLOCKD *xd = &x->e_mbd; 982 MACROBLOCKD *xd = &x->e_mbd;
1020 int64_t best_rd = rd_thresh; 983 int64_t best_rd = rd_thresh;
1021 int rate = 0; 984 int rate = 0;
1022 int64_t distortion; 985 int64_t distortion;
1023 struct macroblock_plane *p = &x->plane[0]; 986 struct macroblock_plane *p = &x->plane[0];
1024 struct macroblockd_plane *pd = &xd->plane[0]; 987 struct macroblockd_plane *pd = &xd->plane[0];
1025 const int src_stride = p->src.stride; 988 const int src_stride = p->src.stride;
1026 const int dst_stride = pd->dst.stride; 989 const int dst_stride = pd->dst.stride;
1027 uint8_t *src_init = raster_block_offset_uint8(BLOCK_8X8, ib, 990 const uint8_t *src_init = &p->src.buf[raster_block_offset(BLOCK_8X8, ib,
1028 p->src.buf, src_stride); 991 src_stride)];
1029 uint8_t *dst_init = raster_block_offset_uint8(BLOCK_8X8, ib, 992 uint8_t *dst_init = &pd->dst.buf[raster_block_offset(BLOCK_8X8, ib,
1030 pd->dst.buf, dst_stride); 993 dst_stride)];
1031 int16_t *src_diff, *coeff; 994 int16_t *src_diff, *coeff;
1032 995
1033 ENTROPY_CONTEXT ta[2], tempa[2]; 996 ENTROPY_CONTEXT ta[2], tempa[2];
1034 ENTROPY_CONTEXT tl[2], templ[2]; 997 ENTROPY_CONTEXT tl[2], templ[2];
1035 998
1036 const int num_4x4_blocks_wide = num_4x4_blocks_wide_lookup[bsize]; 999 const int num_4x4_blocks_wide = num_4x4_blocks_wide_lookup[bsize];
1037 const int num_4x4_blocks_high = num_4x4_blocks_high_lookup[bsize]; 1000 const int num_4x4_blocks_high = num_4x4_blocks_high_lookup[bsize];
1038 int idx, idy; 1001 int idx, idy;
1039 uint8_t best_dst[8 * 8]; 1002 uint8_t best_dst[8 * 8];
1040 1003
(...skipping 19 matching lines...) Expand all
1060 1023
1061 rate = bmode_costs[mode]; 1024 rate = bmode_costs[mode];
1062 distortion = 0; 1025 distortion = 0;
1063 1026
1064 vpx_memcpy(tempa, ta, sizeof(ta)); 1027 vpx_memcpy(tempa, ta, sizeof(ta));
1065 vpx_memcpy(templ, tl, sizeof(tl)); 1028 vpx_memcpy(templ, tl, sizeof(tl));
1066 1029
1067 for (idy = 0; idy < num_4x4_blocks_high; ++idy) { 1030 for (idy = 0; idy < num_4x4_blocks_high; ++idy) {
1068 for (idx = 0; idx < num_4x4_blocks_wide; ++idx) { 1031 for (idx = 0; idx < num_4x4_blocks_wide; ++idx) {
1069 int64_t ssz; 1032 int64_t ssz;
1070 const int16_t *scan; 1033 const scan_order *so;
1071 const int16_t *nb; 1034 const uint8_t *src = src_init + idx * 4 + idy * 4 * src_stride;
1072 uint8_t *src = src_init + idx * 4 + idy * 4 * src_stride;
1073 uint8_t *dst = dst_init + idx * 4 + idy * 4 * dst_stride; 1035 uint8_t *dst = dst_init + idx * 4 + idy * 4 * dst_stride;
1074 const int block = ib + idy * 2 + idx; 1036 const int block = ib + idy * 2 + idx;
1075 TX_TYPE tx_type; 1037 TX_TYPE tx_type;
1076 xd->mi_8x8[0]->bmi[block].as_mode = mode; 1038 xd->mi_8x8[0]->bmi[block].as_mode = mode;
1077 src_diff = raster_block_offset_int16(BLOCK_8X8, block, p->src_diff); 1039 src_diff = raster_block_offset_int16(BLOCK_8X8, block, p->src_diff);
1078 coeff = BLOCK_OFFSET(x->plane[0].coeff, block); 1040 coeff = BLOCK_OFFSET(x->plane[0].coeff, block);
1079 vp9_predict_intra_block(xd, block, 1, 1041 vp9_predict_intra_block(xd, block, 1,
1080 TX_4X4, mode, 1042 TX_4X4, mode,
1081 x->skip_encode ? src : dst, 1043 x->skip_encode ? src : dst,
1082 x->skip_encode ? src_stride : dst_stride, 1044 x->skip_encode ? src_stride : dst_stride,
1083 dst, dst_stride); 1045 dst, dst_stride);
1084 vp9_subtract_block(4, 4, src_diff, 8, 1046 vp9_subtract_block(4, 4, src_diff, 8,
1085 src, src_stride, 1047 src, src_stride,
1086 dst, dst_stride); 1048 dst, dst_stride);
1087 1049
1088 tx_type = get_tx_type_4x4(PLANE_TYPE_Y_WITH_DC, xd, block); 1050 tx_type = get_tx_type_4x4(PLANE_TYPE_Y, xd, block);
1089 get_scan_nb_4x4(tx_type, &scan, &nb); 1051 so = &vp9_scan_orders[TX_4X4][tx_type];
1090 1052
1091 if (tx_type != DCT_DCT) 1053 if (tx_type != DCT_DCT)
1092 vp9_short_fht4x4(src_diff, coeff, 8, tx_type); 1054 vp9_short_fht4x4(src_diff, coeff, 8, tx_type);
1093 else 1055 else
1094 x->fwd_txm4x4(src_diff, coeff, 8); 1056 x->fwd_txm4x4(src_diff, coeff, 8);
1095 1057
1096 vp9_regular_quantize_b_4x4(x, 16, block, scan, get_iscan_4x4(tx_type)); 1058 vp9_regular_quantize_b_4x4(x, 0, block, so->scan, so->iscan);
1097 1059
1098 ratey += cost_coeffs(x, 0, block, 1060 ratey += cost_coeffs(x, 0, block, tempa + idx, templ + idy, TX_4X4,
1099 tempa + idx, templ + idy, TX_4X4, scan, nb); 1061 so->scan, so->neighbors);
1100 distortion += vp9_block_error(coeff, BLOCK_OFFSET(pd->dqcoeff, block), 1062 distortion += vp9_block_error(coeff, BLOCK_OFFSET(pd->dqcoeff, block),
1101 16, &ssz) >> 2; 1063 16, &ssz) >> 2;
1102 if (RDCOST(x->rdmult, x->rddiv, ratey, distortion) >= best_rd) 1064 if (RDCOST(x->rdmult, x->rddiv, ratey, distortion) >= best_rd)
1103 goto next; 1065 goto next;
1104 1066
1105 if (tx_type != DCT_DCT) 1067 if (tx_type != DCT_DCT)
1106 vp9_iht4x4_16_add(BLOCK_OFFSET(pd->dqcoeff, block), 1068 vp9_iht4x4_16_add(BLOCK_OFFSET(pd->dqcoeff, block),
1107 dst, pd->dst.stride, tx_type); 1069 dst, pd->dst.stride, tx_type);
1108 else 1070 else
1109 xd->itxm_add(BLOCK_OFFSET(pd->dqcoeff, block), dst, pd->dst.stride, 1071 xd->itxm_add(BLOCK_OFFSET(pd->dqcoeff, block), dst, pd->dst.stride,
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
1320 1282
1321 term: 1283 term:
1322 *rate = INT_MAX; 1284 *rate = INT_MAX;
1323 *distortion = INT64_MAX; 1285 *distortion = INT64_MAX;
1324 *sse = INT64_MAX; 1286 *sse = INT64_MAX;
1325 *skippable = 0; 1287 *skippable = 0;
1326 return; 1288 return;
1327 } 1289 }
1328 1290
1329 static int64_t rd_pick_intra_sbuv_mode(VP9_COMP *cpi, MACROBLOCK *x, 1291 static int64_t rd_pick_intra_sbuv_mode(VP9_COMP *cpi, MACROBLOCK *x,
1292 PICK_MODE_CONTEXT *ctx,
1330 int *rate, int *rate_tokenonly, 1293 int *rate, int *rate_tokenonly,
1331 int64_t *distortion, int *skippable, 1294 int64_t *distortion, int *skippable,
1332 BLOCK_SIZE bsize) { 1295 BLOCK_SIZE bsize, TX_SIZE max_tx_size) {
1333 MB_PREDICTION_MODE mode; 1296 MB_PREDICTION_MODE mode;
1334 MB_PREDICTION_MODE mode_selected = DC_PRED; 1297 MB_PREDICTION_MODE mode_selected = DC_PRED;
1335 int64_t best_rd = INT64_MAX, this_rd; 1298 int64_t best_rd = INT64_MAX, this_rd;
1336 int this_rate_tokenonly, this_rate, s; 1299 int this_rate_tokenonly, this_rate, s;
1337 int64_t this_distortion, this_sse; 1300 int64_t this_distortion, this_sse;
1338 1301
1339 // int mode_mask = (bsize <= BLOCK_8X8) 1302 for (mode = DC_PRED; mode <= TM_PRED; ++mode) {
1340 // ? ALL_INTRA_MODES : cpi->sf.intra_uv_mode_mask; 1303 if (!(cpi->sf.intra_uv_mode_mask[max_tx_size] & (1 << mode)))
1341
1342 for (mode = DC_PRED; mode <= TM_PRED; mode ++) {
1343 // if (!(mode_mask & (1 << mode)))
1344 if (!(cpi->sf.intra_uv_mode_mask[max_uv_txsize_lookup[bsize]]
1345 & (1 << mode)))
1346 continue; 1304 continue;
1347 1305
1348 x->e_mbd.mi_8x8[0]->mbmi.uv_mode = mode; 1306 x->e_mbd.mi_8x8[0]->mbmi.uv_mode = mode;
1349 1307
1350 super_block_uvrd(cpi, x, &this_rate_tokenonly, 1308 super_block_uvrd(cpi, x, &this_rate_tokenonly,
1351 &this_distortion, &s, &this_sse, bsize, best_rd); 1309 &this_distortion, &s, &this_sse, bsize, best_rd);
1352 if (this_rate_tokenonly == INT_MAX) 1310 if (this_rate_tokenonly == INT_MAX)
1353 continue; 1311 continue;
1354 this_rate = this_rate_tokenonly + 1312 this_rate = this_rate_tokenonly +
1355 x->intra_uv_mode_cost[cpi->common.frame_type][mode]; 1313 x->intra_uv_mode_cost[cpi->common.frame_type][mode];
1356 this_rd = RDCOST(x->rdmult, x->rddiv, this_rate, this_distortion); 1314 this_rd = RDCOST(x->rdmult, x->rddiv, this_rate, this_distortion);
1357 1315
1358 if (this_rd < best_rd) { 1316 if (this_rd < best_rd) {
1359 mode_selected = mode; 1317 mode_selected = mode;
1360 best_rd = this_rd; 1318 best_rd = this_rd;
1361 *rate = this_rate; 1319 *rate = this_rate;
1362 *rate_tokenonly = this_rate_tokenonly; 1320 *rate_tokenonly = this_rate_tokenonly;
1363 *distortion = this_distortion; 1321 *distortion = this_distortion;
1364 *skippable = s; 1322 *skippable = s;
1323 if (!x->select_txfm_size) {
1324 int i;
1325 struct macroblock_plane *const p = x->plane;
1326 struct macroblockd_plane *const pd = x->e_mbd.plane;
1327 for (i = 1; i < MAX_MB_PLANE; ++i) {
1328 p[i].coeff = ctx->coeff_pbuf[i][2];
1329 p[i].qcoeff = ctx->qcoeff_pbuf[i][2];
1330 pd[i].dqcoeff = ctx->dqcoeff_pbuf[i][2];
1331 p[i].eobs = ctx->eobs_pbuf[i][2];
1332
1333 ctx->coeff_pbuf[i][2] = ctx->coeff_pbuf[i][0];
1334 ctx->qcoeff_pbuf[i][2] = ctx->qcoeff_pbuf[i][0];
1335 ctx->dqcoeff_pbuf[i][2] = ctx->dqcoeff_pbuf[i][0];
1336 ctx->eobs_pbuf[i][2] = ctx->eobs_pbuf[i][0];
1337
1338 ctx->coeff_pbuf[i][0] = p[i].coeff;
1339 ctx->qcoeff_pbuf[i][0] = p[i].qcoeff;
1340 ctx->dqcoeff_pbuf[i][0] = pd[i].dqcoeff;
1341 ctx->eobs_pbuf[i][0] = p[i].eobs;
1342 }
1343 }
1365 } 1344 }
1366 } 1345 }
1367 1346
1368 x->e_mbd.mi_8x8[0]->mbmi.uv_mode = mode_selected; 1347 x->e_mbd.mi_8x8[0]->mbmi.uv_mode = mode_selected;
1369
1370 return best_rd; 1348 return best_rd;
1371 } 1349 }
1372 1350
1373 static int64_t rd_sbuv_dcpred(VP9_COMP *cpi, MACROBLOCK *x, 1351 static int64_t rd_sbuv_dcpred(VP9_COMP *cpi, MACROBLOCK *x,
1374 int *rate, int *rate_tokenonly, 1352 int *rate, int *rate_tokenonly,
1375 int64_t *distortion, int *skippable, 1353 int64_t *distortion, int *skippable,
1376 BLOCK_SIZE bsize) { 1354 BLOCK_SIZE bsize) {
1377 int64_t this_rd; 1355 int64_t this_rd;
1378 int64_t this_sse; 1356 int64_t this_sse;
1379 1357
1380 x->e_mbd.mi_8x8[0]->mbmi.uv_mode = DC_PRED; 1358 x->e_mbd.mi_8x8[0]->mbmi.uv_mode = DC_PRED;
1381 super_block_uvrd(cpi, x, rate_tokenonly, distortion, 1359 super_block_uvrd(cpi, x, rate_tokenonly, distortion,
1382 skippable, &this_sse, bsize, INT64_MAX); 1360 skippable, &this_sse, bsize, INT64_MAX);
1383 *rate = *rate_tokenonly + 1361 *rate = *rate_tokenonly +
1384 x->intra_uv_mode_cost[cpi->common.frame_type][DC_PRED]; 1362 x->intra_uv_mode_cost[cpi->common.frame_type][DC_PRED];
1385 this_rd = RDCOST(x->rdmult, x->rddiv, *rate, *distortion); 1363 this_rd = RDCOST(x->rdmult, x->rddiv, *rate, *distortion);
1386 1364
1387 return this_rd; 1365 return this_rd;
1388 } 1366 }
1389 1367
1390 static void choose_intra_uv_mode(VP9_COMP *cpi, BLOCK_SIZE bsize, 1368 static void choose_intra_uv_mode(VP9_COMP *cpi, PICK_MODE_CONTEXT *ctx,
1369 BLOCK_SIZE bsize, TX_SIZE max_tx_size,
1391 int *rate_uv, int *rate_uv_tokenonly, 1370 int *rate_uv, int *rate_uv_tokenonly,
1392 int64_t *dist_uv, int *skip_uv, 1371 int64_t *dist_uv, int *skip_uv,
1393 MB_PREDICTION_MODE *mode_uv) { 1372 MB_PREDICTION_MODE *mode_uv) {
1394 MACROBLOCK *const x = &cpi->mb; 1373 MACROBLOCK *const x = &cpi->mb;
1395 1374
1396 // Use an estimated rd for uv_intra based on DC_PRED if the 1375 // Use an estimated rd for uv_intra based on DC_PRED if the
1397 // appropriate speed flag is set. 1376 // appropriate speed flag is set.
1398 if (cpi->sf.use_uv_intra_rd_estimate) { 1377 if (cpi->sf.use_uv_intra_rd_estimate) {
1399 rd_sbuv_dcpred(cpi, x, rate_uv, rate_uv_tokenonly, dist_uv, skip_uv, 1378 rd_sbuv_dcpred(cpi, x, rate_uv, rate_uv_tokenonly, dist_uv, skip_uv,
1400 bsize < BLOCK_8X8 ? BLOCK_8X8 : bsize); 1379 bsize < BLOCK_8X8 ? BLOCK_8X8 : bsize);
1401 // Else do a proper rd search for each possible transform size that may 1380 // Else do a proper rd search for each possible transform size that may
1402 // be considered in the main rd loop. 1381 // be considered in the main rd loop.
1403 } else { 1382 } else {
1404 rd_pick_intra_sbuv_mode(cpi, x, 1383 rd_pick_intra_sbuv_mode(cpi, x, ctx,
1405 rate_uv, rate_uv_tokenonly, dist_uv, skip_uv, 1384 rate_uv, rate_uv_tokenonly, dist_uv, skip_uv,
1406 bsize < BLOCK_8X8 ? BLOCK_8X8 : bsize); 1385 bsize < BLOCK_8X8 ? BLOCK_8X8 : bsize, max_tx_size);
1407 } 1386 }
1408 *mode_uv = x->e_mbd.mi_8x8[0]->mbmi.uv_mode; 1387 *mode_uv = x->e_mbd.mi_8x8[0]->mbmi.uv_mode;
1409 } 1388 }
1410 1389
1411 static int cost_mv_ref(VP9_COMP *cpi, MB_PREDICTION_MODE mode, 1390 static int cost_mv_ref(VP9_COMP *cpi, MB_PREDICTION_MODE mode,
1412 int mode_context) { 1391 int mode_context) {
1413 MACROBLOCK *const x = &cpi->mb; 1392 MACROBLOCK *const x = &cpi->mb;
1414 MACROBLOCKD *const xd = &x->e_mbd; 1393 MACROBLOCKD *const xd = &x->e_mbd;
1415 const int segment_id = xd->mi_8x8[0]->mbmi.segment_id; 1394 const int segment_id = xd->mi_8x8[0]->mbmi.segment_id;
1416 1395
1417 // Don't account for mode here if segment skip is enabled. 1396 // Don't account for mode here if segment skip is enabled.
1418 if (!vp9_segfeature_active(&cpi->common.seg, segment_id, SEG_LVL_SKIP)) { 1397 if (!vp9_segfeature_active(&cpi->common.seg, segment_id, SEG_LVL_SKIP)) {
1419 assert(is_inter_mode(mode)); 1398 assert(is_inter_mode(mode));
1420 return x->inter_mode_cost[mode_context][inter_mode_offset(mode)]; 1399 return x->inter_mode_cost[mode_context][INTER_OFFSET(mode)];
1421 } else { 1400 } else {
1422 return 0; 1401 return 0;
1423 } 1402 }
1424 } 1403 }
1425 1404
1426 void vp9_set_mbmode_and_mvs(MACROBLOCK *x, MB_PREDICTION_MODE mb, int_mv *mv) { 1405 void vp9_set_mbmode_and_mvs(MACROBLOCK *x, MB_PREDICTION_MODE mb, int_mv *mv) {
1427 x->e_mbd.mi_8x8[0]->mbmi.mode = mb; 1406 x->e_mbd.mi_8x8[0]->mbmi.mode = mb;
1428 x->e_mbd.mi_8x8[0]->mbmi.mv[0].as_int = mv->as_int; 1407 x->e_mbd.mi_8x8[0]->mbmi.mv[0].as_int = mv->as_int;
1429 } 1408 }
1430 1409
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
1516 int i, 1495 int i,
1517 int *labelyrate, 1496 int *labelyrate,
1518 int64_t *distortion, int64_t *sse, 1497 int64_t *distortion, int64_t *sse,
1519 ENTROPY_CONTEXT *ta, 1498 ENTROPY_CONTEXT *ta,
1520 ENTROPY_CONTEXT *tl) { 1499 ENTROPY_CONTEXT *tl) {
1521 int k; 1500 int k;
1522 MACROBLOCKD *xd = &x->e_mbd; 1501 MACROBLOCKD *xd = &x->e_mbd;
1523 struct macroblockd_plane *const pd = &xd->plane[0]; 1502 struct macroblockd_plane *const pd = &xd->plane[0];
1524 struct macroblock_plane *const p = &x->plane[0]; 1503 struct macroblock_plane *const p = &x->plane[0];
1525 MODE_INFO *const mi = xd->mi_8x8[0]; 1504 MODE_INFO *const mi = xd->mi_8x8[0];
1526 const BLOCK_SIZE bsize = mi->mbmi.sb_type; 1505 const BLOCK_SIZE plane_bsize = get_plane_block_size(mi->mbmi.sb_type, pd);
1527 const int width = plane_block_width(bsize, pd); 1506 const int width = 4 * num_4x4_blocks_wide_lookup[plane_bsize];
1528 const int height = plane_block_height(bsize, pd); 1507 const int height = 4 * num_4x4_blocks_high_lookup[plane_bsize];
1529 int idx, idy; 1508 int idx, idy;
1530 1509
1531 uint8_t *const src = raster_block_offset_uint8(BLOCK_8X8, i, 1510 const uint8_t *const src = &p->src.buf[raster_block_offset(BLOCK_8X8, i,
1532 p->src.buf, p->src.stride); 1511 p->src.stride)];
1533 uint8_t *const dst = raster_block_offset_uint8(BLOCK_8X8, i, 1512 uint8_t *const dst = &pd->dst.buf[raster_block_offset(BLOCK_8X8, i,
1534 pd->dst.buf, pd->dst.stride); 1513 pd->dst.stride)];
1535 int64_t thisdistortion = 0, thissse = 0; 1514 int64_t thisdistortion = 0, thissse = 0;
1536 int thisrate = 0, ref; 1515 int thisrate = 0, ref;
1516 const scan_order *so = &vp9_default_scan_orders[TX_4X4];
1537 const int is_compound = has_second_ref(&mi->mbmi); 1517 const int is_compound = has_second_ref(&mi->mbmi);
1538 for (ref = 0; ref < 1 + is_compound; ++ref) { 1518 for (ref = 0; ref < 1 + is_compound; ++ref) {
1539 const uint8_t *pre = raster_block_offset_uint8(BLOCK_8X8, i, 1519 const uint8_t *pre = &pd->pre[ref].buf[raster_block_offset(BLOCK_8X8, i,
1540 pd->pre[ref].buf, pd->pre[ref].stride); 1520 pd->pre[ref].stride)];
1541 vp9_build_inter_predictor(pre, pd->pre[ref].stride, 1521 vp9_build_inter_predictor(pre, pd->pre[ref].stride,
1542 dst, pd->dst.stride, 1522 dst, pd->dst.stride,
1543 &mi->bmi[i].as_mv[ref].as_mv, 1523 &mi->bmi[i].as_mv[ref].as_mv,
1544 &xd->scale_factor[ref], 1524 &xd->scale_factor[ref],
1545 width, height, ref, &xd->subpix, MV_PRECISION_Q3); 1525 width, height, ref, &xd->subpix, MV_PRECISION_Q3);
1546 } 1526 }
1547 1527
1548 vp9_subtract_block(height, width, 1528 vp9_subtract_block(height, width,
1549 raster_block_offset_int16(BLOCK_8X8, i, p->src_diff), 8, 1529 raster_block_offset_int16(BLOCK_8X8, i, p->src_diff), 8,
1550 src, p->src.stride, 1530 src, p->src.stride,
1551 dst, pd->dst.stride); 1531 dst, pd->dst.stride);
1552 1532
1553 k = i; 1533 k = i;
1554 for (idy = 0; idy < height / 4; ++idy) { 1534 for (idy = 0; idy < height / 4; ++idy) {
1555 for (idx = 0; idx < width / 4; ++idx) { 1535 for (idx = 0; idx < width / 4; ++idx) {
1556 int64_t ssz, rd, rd1, rd2; 1536 int64_t ssz, rd, rd1, rd2;
1557 int16_t* coeff; 1537 int16_t* coeff;
1558 1538
1559 k += (idy * 2 + idx); 1539 k += (idy * 2 + idx);
1560 coeff = BLOCK_OFFSET(p->coeff, k); 1540 coeff = BLOCK_OFFSET(p->coeff, k);
1561 x->fwd_txm4x4(raster_block_offset_int16(BLOCK_8X8, k, p->src_diff), 1541 x->fwd_txm4x4(raster_block_offset_int16(BLOCK_8X8, k, p->src_diff),
1562 coeff, 8); 1542 coeff, 8);
1563 vp9_regular_quantize_b_4x4(x, 16, k, get_scan_4x4(DCT_DCT), 1543 vp9_regular_quantize_b_4x4(x, 0, k, so->scan, so->iscan);
1564 get_iscan_4x4(DCT_DCT));
1565 thisdistortion += vp9_block_error(coeff, BLOCK_OFFSET(pd->dqcoeff, k), 1544 thisdistortion += vp9_block_error(coeff, BLOCK_OFFSET(pd->dqcoeff, k),
1566 16, &ssz); 1545 16, &ssz);
1567 thissse += ssz; 1546 thissse += ssz;
1568 thisrate += cost_coeffs(x, 0, k, 1547 thisrate += cost_coeffs(x, 0, k, ta + (k & 1), tl + (k >> 1), TX_4X4,
1569 ta + (k & 1), 1548 so->scan, so->neighbors);
1570 tl + (k >> 1), TX_4X4,
1571 vp9_default_scan_4x4,
1572 vp9_default_scan_4x4_neighbors);
1573 rd1 = RDCOST(x->rdmult, x->rddiv, thisrate, thisdistortion >> 2); 1549 rd1 = RDCOST(x->rdmult, x->rddiv, thisrate, thisdistortion >> 2);
1574 rd2 = RDCOST(x->rdmult, x->rddiv, 0, thissse >> 2); 1550 rd2 = RDCOST(x->rdmult, x->rddiv, 0, thissse >> 2);
1575 rd = MIN(rd1, rd2); 1551 rd = MIN(rd1, rd2);
1576 if (rd >= best_yrd) 1552 if (rd >= best_yrd)
1577 return INT64_MAX; 1553 return INT64_MAX;
1578 } 1554 }
1579 } 1555 }
1580 1556
1581 *distortion = thisdistortion >> 2; 1557 *distortion = thisdistortion >> 2;
1582 *labelyrate = thisrate; 1558 *labelyrate = thisrate;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1618 r |= (mv->as_mv.col >> 3) < x->mv_col_min; 1594 r |= (mv->as_mv.col >> 3) < x->mv_col_min;
1619 r |= (mv->as_mv.col >> 3) > x->mv_col_max; 1595 r |= (mv->as_mv.col >> 3) > x->mv_col_max;
1620 return r; 1596 return r;
1621 } 1597 }
1622 1598
1623 static INLINE void mi_buf_shift(MACROBLOCK *x, int i) { 1599 static INLINE void mi_buf_shift(MACROBLOCK *x, int i) {
1624 MB_MODE_INFO *const mbmi = &x->e_mbd.mi_8x8[0]->mbmi; 1600 MB_MODE_INFO *const mbmi = &x->e_mbd.mi_8x8[0]->mbmi;
1625 struct macroblock_plane *const p = &x->plane[0]; 1601 struct macroblock_plane *const p = &x->plane[0];
1626 struct macroblockd_plane *const pd = &x->e_mbd.plane[0]; 1602 struct macroblockd_plane *const pd = &x->e_mbd.plane[0];
1627 1603
1628 p->src.buf = raster_block_offset_uint8(BLOCK_8X8, i, p->src.buf, 1604 p->src.buf = &p->src.buf[raster_block_offset(BLOCK_8X8, i, p->src.stride)];
1629 p->src.stride);
1630 assert(((intptr_t)pd->pre[0].buf & 0x7) == 0); 1605 assert(((intptr_t)pd->pre[0].buf & 0x7) == 0);
1631 pd->pre[0].buf = raster_block_offset_uint8(BLOCK_8X8, i, pd->pre[0].buf, 1606 pd->pre[0].buf = &pd->pre[0].buf[raster_block_offset(BLOCK_8X8, i,
1632 pd->pre[0].stride); 1607 pd->pre[0].stride)];
1633 if (has_second_ref(mbmi)) 1608 if (has_second_ref(mbmi))
1634 pd->pre[1].buf = raster_block_offset_uint8(BLOCK_8X8, i, pd->pre[1].buf, 1609 pd->pre[1].buf = &pd->pre[1].buf[raster_block_offset(BLOCK_8X8, i,
1635 pd->pre[1].stride); 1610 pd->pre[1].stride)];
1636 } 1611 }
1637 1612
1638 static INLINE void mi_buf_restore(MACROBLOCK *x, struct buf_2d orig_src, 1613 static INLINE void mi_buf_restore(MACROBLOCK *x, struct buf_2d orig_src,
1639 struct buf_2d orig_pre[2]) { 1614 struct buf_2d orig_pre[2]) {
1640 MB_MODE_INFO *mbmi = &x->e_mbd.mi_8x8[0]->mbmi; 1615 MB_MODE_INFO *mbmi = &x->e_mbd.mi_8x8[0]->mbmi;
1641 x->plane[0].src = orig_src; 1616 x->plane[0].src = orig_src;
1642 x->e_mbd.plane[0].pre[0] = orig_pre[0]; 1617 x->e_mbd.plane[0].pre[0] = orig_pre[0];
1643 if (has_second_ref(mbmi)) 1618 if (has_second_ref(mbmi))
1644 x->e_mbd.plane[0].pre[1] = orig_pre[1]; 1619 x->e_mbd.plane[0].pre[1] = orig_pre[1];
1645 } 1620 }
1646 1621
1647 static void rd_check_segment_txsize(VP9_COMP *cpi, MACROBLOCK *x, 1622 static void rd_check_segment_txsize(VP9_COMP *cpi, MACROBLOCK *x,
1648 const TileInfo *const tile, 1623 const TileInfo *const tile,
1649 BEST_SEG_INFO *bsi_buf, int filter_idx, 1624 BEST_SEG_INFO *bsi_buf, int filter_idx,
1650 int_mv seg_mvs[4][MAX_REF_FRAMES], 1625 int_mv seg_mvs[4][MAX_REF_FRAMES],
1651 int mi_row, int mi_col) { 1626 int mi_row, int mi_col) {
1652 int i, br = 0, idx, idy; 1627 int i, br = 0, idx, idy;
1653 int64_t bd = 0, block_sse = 0; 1628 int64_t bd = 0, block_sse = 0;
1654 MB_PREDICTION_MODE this_mode; 1629 MB_PREDICTION_MODE this_mode;
1655 MODE_INFO *mi = x->e_mbd.mi_8x8[0]; 1630 MODE_INFO *mi = x->e_mbd.mi_8x8[0];
1656 MB_MODE_INFO *const mbmi = &mi->mbmi; 1631 MB_MODE_INFO *const mbmi = &mi->mbmi;
1632 struct macroblock_plane *const p = &x->plane[0];
1657 struct macroblockd_plane *const pd = &x->e_mbd.plane[0]; 1633 struct macroblockd_plane *const pd = &x->e_mbd.plane[0];
1658 const int label_count = 4; 1634 const int label_count = 4;
1659 int64_t this_segment_rd = 0; 1635 int64_t this_segment_rd = 0;
1660 int label_mv_thresh; 1636 int label_mv_thresh;
1661 int segmentyrate = 0; 1637 int segmentyrate = 0;
1662 const BLOCK_SIZE bsize = mbmi->sb_type; 1638 const BLOCK_SIZE bsize = mbmi->sb_type;
1663 const int num_4x4_blocks_wide = num_4x4_blocks_wide_lookup[bsize]; 1639 const int num_4x4_blocks_wide = num_4x4_blocks_wide_lookup[bsize];
1664 const int num_4x4_blocks_high = num_4x4_blocks_high_lookup[bsize]; 1640 const int num_4x4_blocks_high = num_4x4_blocks_high_lookup[bsize];
1665 vp9_variance_fn_ptr_t *v_fn_ptr; 1641 vp9_variance_fn_ptr_t *v_fn_ptr;
1666 ENTROPY_CONTEXT t_above[2], t_left[2]; 1642 ENTROPY_CONTEXT t_above[2], t_left[2];
(...skipping 19 matching lines...) Expand all
1686 // TODO(jingning,rbultje): rewrite the rate-distortion optimization 1662 // TODO(jingning,rbultje): rewrite the rate-distortion optimization
1687 // loop for 4x4/4x8/8x4 block coding. to be replaced with new rd loop 1663 // loop for 4x4/4x8/8x4 block coding. to be replaced with new rd loop
1688 int_mv mode_mv[MB_MODE_COUNT], second_mode_mv[MB_MODE_COUNT]; 1664 int_mv mode_mv[MB_MODE_COUNT], second_mode_mv[MB_MODE_COUNT];
1689 int_mv frame_mv[MB_MODE_COUNT][MAX_REF_FRAMES]; 1665 int_mv frame_mv[MB_MODE_COUNT][MAX_REF_FRAMES];
1690 MB_PREDICTION_MODE mode_selected = ZEROMV; 1666 MB_PREDICTION_MODE mode_selected = ZEROMV;
1691 int64_t best_rd = INT64_MAX; 1667 int64_t best_rd = INT64_MAX;
1692 i = idy * 2 + idx; 1668 i = idy * 2 + idx;
1693 1669
1694 frame_mv[ZEROMV][mbmi->ref_frame[0]].as_int = 0; 1670 frame_mv[ZEROMV][mbmi->ref_frame[0]].as_int = 0;
1695 vp9_append_sub8x8_mvs_for_idx(&cpi->common, &x->e_mbd, tile, 1671 vp9_append_sub8x8_mvs_for_idx(&cpi->common, &x->e_mbd, tile,
1672 i, 0, mi_row, mi_col,
1696 &frame_mv[NEARESTMV][mbmi->ref_frame[0]], 1673 &frame_mv[NEARESTMV][mbmi->ref_frame[0]],
1697 &frame_mv[NEARMV][mbmi->ref_frame[0]], 1674 &frame_mv[NEARMV][mbmi->ref_frame[0]]);
1698 i, 0, mi_row, mi_col);
1699 if (has_second_rf) { 1675 if (has_second_rf) {
1700 frame_mv[ZEROMV][mbmi->ref_frame[1]].as_int = 0; 1676 frame_mv[ZEROMV][mbmi->ref_frame[1]].as_int = 0;
1701 vp9_append_sub8x8_mvs_for_idx(&cpi->common, &x->e_mbd, tile, 1677 vp9_append_sub8x8_mvs_for_idx(&cpi->common, &x->e_mbd, tile,
1678 i, 1, mi_row, mi_col,
1702 &frame_mv[NEARESTMV][mbmi->ref_frame[1]], 1679 &frame_mv[NEARESTMV][mbmi->ref_frame[1]],
1703 &frame_mv[NEARMV][mbmi->ref_frame[1]], 1680 &frame_mv[NEARMV][mbmi->ref_frame[1]]);
1704 i, 1, mi_row, mi_col);
1705 } 1681 }
1706 // search for the best motion vector on this segment 1682 // search for the best motion vector on this segment
1707 for (this_mode = NEARESTMV; this_mode <= NEWMV; ++this_mode) { 1683 for (this_mode = NEARESTMV; this_mode <= NEWMV; ++this_mode) {
1708 const struct buf_2d orig_src = x->plane[0].src; 1684 const struct buf_2d orig_src = x->plane[0].src;
1709 struct buf_2d orig_pre[2]; 1685 struct buf_2d orig_pre[2];
1710 1686
1711 mode_idx = inter_mode_offset(this_mode); 1687 mode_idx = INTER_OFFSET(this_mode);
1712 bsi->rdstat[i][mode_idx].brdcost = INT64_MAX; 1688 bsi->rdstat[i][mode_idx].brdcost = INT64_MAX;
1713 1689
1714 // if we're near/nearest and mv == 0,0, compare to zeromv 1690 // if we're near/nearest and mv == 0,0, compare to zeromv
1715 if ((this_mode == NEARMV || this_mode == NEARESTMV || 1691 if ((this_mode == NEARMV || this_mode == NEARESTMV ||
1716 this_mode == ZEROMV) && 1692 this_mode == ZEROMV) &&
1717 frame_mv[this_mode][mbmi->ref_frame[0]].as_int == 0 && 1693 frame_mv[this_mode][mbmi->ref_frame[0]].as_int == 0 &&
1718 (!has_second_rf || 1694 (!has_second_rf ||
1719 frame_mv[this_mode][mbmi->ref_frame[1]].as_int == 0)) { 1695 frame_mv[this_mode][mbmi->ref_frame[1]].as_int == 0)) {
1720 int rfc = mbmi->mode_context[mbmi->ref_frame[0]]; 1696 int rfc = mbmi->mode_context[mbmi->ref_frame[0]];
1721 int c1 = cost_mv_ref(cpi, NEARMV, rfc); 1697 int c1 = cost_mv_ref(cpi, NEARMV, rfc);
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
1797 1773
1798 if (cpi->sf.adaptive_motion_search && cpi->common.show_frame) { 1774 if (cpi->sf.adaptive_motion_search && cpi->common.show_frame) {
1799 mvp_full.as_mv.row = x->pred_mv[mbmi->ref_frame[0]].as_mv.row >> 3; 1775 mvp_full.as_mv.row = x->pred_mv[mbmi->ref_frame[0]].as_mv.row >> 3;
1800 mvp_full.as_mv.col = x->pred_mv[mbmi->ref_frame[0]].as_mv.col >> 3; 1776 mvp_full.as_mv.col = x->pred_mv[mbmi->ref_frame[0]].as_mv.col >> 3;
1801 step_param = MAX(step_param, 8); 1777 step_param = MAX(step_param, 8);
1802 } 1778 }
1803 1779
1804 further_steps = (MAX_MVSEARCH_STEPS - 1) - step_param; 1780 further_steps = (MAX_MVSEARCH_STEPS - 1) - step_param;
1805 // adjust src pointer for this block 1781 // adjust src pointer for this block
1806 mi_buf_shift(x, i); 1782 mi_buf_shift(x, i);
1783
1784 vp9_set_mv_search_range(x, &bsi->ref_mv->as_mv);
1785
1807 if (cpi->sf.search_method == HEX) { 1786 if (cpi->sf.search_method == HEX) {
1808 bestsme = vp9_hex_search(x, &mvp_full.as_mv, 1787 bestsme = vp9_hex_search(x, &mvp_full.as_mv,
1809 step_param, 1788 step_param,
1810 sadpb, 1, v_fn_ptr, 1, 1789 sadpb, 1, v_fn_ptr, 1,
1811 &bsi->ref_mv->as_mv, 1790 &bsi->ref_mv->as_mv,
1812 &mode_mv[NEWMV].as_mv); 1791 &mode_mv[NEWMV].as_mv);
1813 } else if (cpi->sf.search_method == SQUARE) { 1792 } else if (cpi->sf.search_method == SQUARE) {
1814 bestsme = vp9_square_search(x, &mvp_full.as_mv, 1793 bestsme = vp9_square_search(x, &mvp_full.as_mv,
1815 step_param, 1794 step_param,
1816 sadpb, 1, v_fn_ptr, 1, 1795 sadpb, 1, v_fn_ptr, 1,
(...skipping 10 matching lines...) Expand all
1827 sadpb, further_steps, 0, v_fn_ptr, 1806 sadpb, further_steps, 0, v_fn_ptr,
1828 bsi->ref_mv, &mode_mv[NEWMV]); 1807 bsi->ref_mv, &mode_mv[NEWMV]);
1829 } 1808 }
1830 1809
1831 // Should we do a full search (best quality only) 1810 // Should we do a full search (best quality only)
1832 if (cpi->compressor_speed == 0) { 1811 if (cpi->compressor_speed == 0) {
1833 /* Check if mvp_full is within the range. */ 1812 /* Check if mvp_full is within the range. */
1834 clamp_mv(&mvp_full.as_mv, x->mv_col_min, x->mv_col_max, 1813 clamp_mv(&mvp_full.as_mv, x->mv_col_min, x->mv_col_max,
1835 x->mv_row_min, x->mv_row_max); 1814 x->mv_row_min, x->mv_row_max);
1836 1815
1837 thissme = cpi->full_search_sad(x, &mvp_full, 1816 thissme = cpi->full_search_sad(x, &mvp_full.as_mv,
1838 sadpb, 16, v_fn_ptr, 1817 sadpb, 16, v_fn_ptr,
1839 x->nmvjointcost, x->mvcost, 1818 x->nmvjointcost, x->mvcost,
1840 bsi->ref_mv, i); 1819 &bsi->ref_mv->as_mv, i);
1841 1820
1842 if (thissme < bestsme) { 1821 if (thissme < bestsme) {
1843 bestsme = thissme; 1822 bestsme = thissme;
1844 mode_mv[NEWMV].as_int = mi->bmi[i].as_mv[0].as_int; 1823 mode_mv[NEWMV].as_int = mi->bmi[i].as_mv[0].as_int;
1845 } else { 1824 } else {
1846 /* The full search result is actually worse so re-instate the 1825 /* The full search result is actually worse so re-instate the
1847 * previous best vector */ 1826 * previous best vector */
1848 mi->bmi[i].as_mv[0].as_int = mode_mv[NEWMV].as_int; 1827 mi->bmi[i].as_mv[0].as_int = mode_mv[NEWMV].as_int;
1849 } 1828 }
1850 } 1829 }
(...skipping 14 matching lines...) Expand all
1865 seg_mvs[i][mbmi->ref_frame[0]].as_int = mode_mv[NEWMV].as_int; 1844 seg_mvs[i][mbmi->ref_frame[0]].as_int = mode_mv[NEWMV].as_int;
1866 } 1845 }
1867 1846
1868 if (cpi->sf.adaptive_motion_search) 1847 if (cpi->sf.adaptive_motion_search)
1869 x->pred_mv[mbmi->ref_frame[0]].as_int = mode_mv[NEWMV].as_int; 1848 x->pred_mv[mbmi->ref_frame[0]].as_int = mode_mv[NEWMV].as_int;
1870 1849
1871 // restore src pointers 1850 // restore src pointers
1872 mi_buf_restore(x, orig_src, orig_pre); 1851 mi_buf_restore(x, orig_src, orig_pre);
1873 } 1852 }
1874 1853
1854 if (has_second_rf) {
1855 if (seg_mvs[i][mbmi->ref_frame[1]].as_int == INVALID_MV ||
1856 seg_mvs[i][mbmi->ref_frame[0]].as_int == INVALID_MV)
1857 continue;
1858 }
1859
1875 if (has_second_rf && this_mode == NEWMV && 1860 if (has_second_rf && this_mode == NEWMV &&
1876 mbmi->interp_filter == EIGHTTAP) { 1861 mbmi->interp_filter == EIGHTTAP) {
1877 if (seg_mvs[i][mbmi->ref_frame[1]].as_int == INVALID_MV ||
1878 seg_mvs[i][mbmi->ref_frame[0]].as_int == INVALID_MV)
1879 continue;
1880
1881 // adjust src pointers 1862 // adjust src pointers
1882 mi_buf_shift(x, i); 1863 mi_buf_shift(x, i);
1883 if (cpi->sf.comp_inter_joint_search_thresh <= bsize) { 1864 if (cpi->sf.comp_inter_joint_search_thresh <= bsize) {
1884 int rate_mv; 1865 int rate_mv;
1885 joint_motion_search(cpi, x, bsize, frame_mv[this_mode], 1866 joint_motion_search(cpi, x, bsize, frame_mv[this_mode],
1886 mi_row, mi_col, seg_mvs[i], 1867 mi_row, mi_col, seg_mvs[i],
1887 &rate_mv); 1868 &rate_mv);
1888 seg_mvs[i][mbmi->ref_frame[0]].as_int = 1869 seg_mvs[i][mbmi->ref_frame[0]].as_int =
1889 frame_mv[this_mode][mbmi->ref_frame[0]].as_int; 1870 frame_mv[this_mode][mbmi->ref_frame[0]].as_int;
1890 seg_mvs[i][mbmi->ref_frame[1]].as_int = 1871 seg_mvs[i][mbmi->ref_frame[1]].as_int =
1891 frame_mv[this_mode][mbmi->ref_frame[1]].as_int; 1872 frame_mv[this_mode][mbmi->ref_frame[1]].as_int;
1892 } 1873 }
1893 // restore src pointers 1874 // restore src pointers
1894 mi_buf_restore(x, orig_src, orig_pre); 1875 mi_buf_restore(x, orig_src, orig_pre);
1895 } 1876 }
1896 1877
1897 bsi->rdstat[i][mode_idx].brate = 1878 bsi->rdstat[i][mode_idx].brate =
1898 labels2mode(x, i, this_mode, &mode_mv[this_mode], 1879 labels2mode(x, i, this_mode, &mode_mv[this_mode],
1899 &second_mode_mv[this_mode], frame_mv, seg_mvs[i], 1880 &second_mode_mv[this_mode], frame_mv, seg_mvs[i],
1900 bsi->ref_mv, bsi->second_ref_mv, x->nmvjointcost, 1881 bsi->ref_mv, bsi->second_ref_mv, x->nmvjointcost,
1901 x->mvcost, cpi); 1882 x->mvcost, cpi);
1902 1883
1884
1903 bsi->rdstat[i][mode_idx].mvs[0].as_int = mode_mv[this_mode].as_int; 1885 bsi->rdstat[i][mode_idx].mvs[0].as_int = mode_mv[this_mode].as_int;
1904 if (num_4x4_blocks_wide > 1) 1886 if (num_4x4_blocks_wide > 1)
1905 bsi->rdstat[i + 1][mode_idx].mvs[0].as_int = 1887 bsi->rdstat[i + 1][mode_idx].mvs[0].as_int =
1906 mode_mv[this_mode].as_int; 1888 mode_mv[this_mode].as_int;
1907 if (num_4x4_blocks_high > 1) 1889 if (num_4x4_blocks_high > 1)
1908 bsi->rdstat[i + 2][mode_idx].mvs[0].as_int = 1890 bsi->rdstat[i + 2][mode_idx].mvs[0].as_int =
1909 mode_mv[this_mode].as_int; 1891 mode_mv[this_mode].as_int;
1910 if (has_second_rf) { 1892 if (has_second_rf) {
1911 bsi->rdstat[i][mode_idx].mvs[1].as_int = 1893 bsi->rdstat[i][mode_idx].mvs[1].as_int =
1912 second_mode_mv[this_mode].as_int; 1894 second_mode_mv[this_mode].as_int;
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
1972 bsi->segment_rd - this_segment_rd, i, 1954 bsi->segment_rd - this_segment_rd, i,
1973 &bsi->rdstat[i][mode_idx].byrate, 1955 &bsi->rdstat[i][mode_idx].byrate,
1974 &bsi->rdstat[i][mode_idx].bdist, 1956 &bsi->rdstat[i][mode_idx].bdist,
1975 &bsi->rdstat[i][mode_idx].bsse, 1957 &bsi->rdstat[i][mode_idx].bsse,
1976 bsi->rdstat[i][mode_idx].ta, 1958 bsi->rdstat[i][mode_idx].ta,
1977 bsi->rdstat[i][mode_idx].tl); 1959 bsi->rdstat[i][mode_idx].tl);
1978 if (bsi->rdstat[i][mode_idx].brdcost < INT64_MAX) { 1960 if (bsi->rdstat[i][mode_idx].brdcost < INT64_MAX) {
1979 bsi->rdstat[i][mode_idx].brdcost += RDCOST(x->rdmult, x->rddiv, 1961 bsi->rdstat[i][mode_idx].brdcost += RDCOST(x->rdmult, x->rddiv,
1980 bsi->rdstat[i][mode_idx].brate, 0); 1962 bsi->rdstat[i][mode_idx].brate, 0);
1981 bsi->rdstat[i][mode_idx].brate += bsi->rdstat[i][mode_idx].byrate; 1963 bsi->rdstat[i][mode_idx].brate += bsi->rdstat[i][mode_idx].byrate;
1982 bsi->rdstat[i][mode_idx].eobs = pd->eobs[i]; 1964 bsi->rdstat[i][mode_idx].eobs = p->eobs[i];
1983 if (num_4x4_blocks_wide > 1) 1965 if (num_4x4_blocks_wide > 1)
1984 bsi->rdstat[i + 1][mode_idx].eobs = pd->eobs[i + 1]; 1966 bsi->rdstat[i + 1][mode_idx].eobs = p->eobs[i + 1];
1985 if (num_4x4_blocks_high > 1) 1967 if (num_4x4_blocks_high > 1)
1986 bsi->rdstat[i + 2][mode_idx].eobs = pd->eobs[i + 2]; 1968 bsi->rdstat[i + 2][mode_idx].eobs = p->eobs[i + 2];
1987 } 1969 }
1988 1970
1989 if (bsi->rdstat[i][mode_idx].brdcost < best_rd) { 1971 if (bsi->rdstat[i][mode_idx].brdcost < best_rd) {
1990 mode_selected = this_mode; 1972 mode_selected = this_mode;
1991 best_rd = bsi->rdstat[i][mode_idx].brdcost; 1973 best_rd = bsi->rdstat[i][mode_idx].brdcost;
1992 } 1974 }
1993 } /*for each 4x4 mode*/ 1975 } /*for each 4x4 mode*/
1994 1976
1995 if (best_rd == INT64_MAX) { 1977 if (best_rd == INT64_MAX) {
1996 int iy, midx; 1978 int iy, midx;
1997 for (iy = i + 1; iy < 4; ++iy) 1979 for (iy = i + 1; iy < 4; ++iy)
1998 for (midx = 0; midx < INTER_MODES; ++midx) 1980 for (midx = 0; midx < INTER_MODES; ++midx)
1999 bsi->rdstat[iy][midx].brdcost = INT64_MAX; 1981 bsi->rdstat[iy][midx].brdcost = INT64_MAX;
2000 bsi->segment_rd = INT64_MAX; 1982 bsi->segment_rd = INT64_MAX;
2001 return; 1983 return;
2002 } 1984 }
2003 1985
2004 mode_idx = inter_mode_offset(mode_selected); 1986 mode_idx = INTER_OFFSET(mode_selected);
2005 vpx_memcpy(t_above, bsi->rdstat[i][mode_idx].ta, sizeof(t_above)); 1987 vpx_memcpy(t_above, bsi->rdstat[i][mode_idx].ta, sizeof(t_above));
2006 vpx_memcpy(t_left, bsi->rdstat[i][mode_idx].tl, sizeof(t_left)); 1988 vpx_memcpy(t_left, bsi->rdstat[i][mode_idx].tl, sizeof(t_left));
2007 1989
2008 labels2mode(x, i, mode_selected, &mode_mv[mode_selected], 1990 labels2mode(x, i, mode_selected, &mode_mv[mode_selected],
2009 &second_mode_mv[mode_selected], frame_mv, seg_mvs[i], 1991 &second_mode_mv[mode_selected], frame_mv, seg_mvs[i],
2010 bsi->ref_mv, bsi->second_ref_mv, x->nmvjointcost, 1992 bsi->ref_mv, bsi->second_ref_mv, x->nmvjointcost,
2011 x->mvcost, cpi); 1993 x->mvcost, cpi);
2012 1994
2013 br += bsi->rdstat[i][mode_idx].brate; 1995 br += bsi->rdstat[i][mode_idx].brate;
2014 bd += bsi->rdstat[i][mode_idx].bdist; 1996 bd += bsi->rdstat[i][mode_idx].bdist;
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
2070 for (i = 0; i < 4; i++) 2052 for (i = 0; i < 4; i++)
2071 bsi->modes[i] = ZEROMV; 2053 bsi->modes[i] = ZEROMV;
2072 2054
2073 rd_check_segment_txsize(cpi, x, tile, bsi_buf, filter_idx, seg_mvs, 2055 rd_check_segment_txsize(cpi, x, tile, bsi_buf, filter_idx, seg_mvs,
2074 mi_row, mi_col); 2056 mi_row, mi_col);
2075 2057
2076 if (bsi->segment_rd > best_rd) 2058 if (bsi->segment_rd > best_rd)
2077 return INT64_MAX; 2059 return INT64_MAX;
2078 /* set it to the best */ 2060 /* set it to the best */
2079 for (i = 0; i < 4; i++) { 2061 for (i = 0; i < 4; i++) {
2080 mode_idx = inter_mode_offset(bsi->modes[i]); 2062 mode_idx = INTER_OFFSET(bsi->modes[i]);
2081 mi->bmi[i].as_mv[0].as_int = bsi->rdstat[i][mode_idx].mvs[0].as_int; 2063 mi->bmi[i].as_mv[0].as_int = bsi->rdstat[i][mode_idx].mvs[0].as_int;
2082 if (has_second_ref(mbmi)) 2064 if (has_second_ref(mbmi))
2083 mi->bmi[i].as_mv[1].as_int = bsi->rdstat[i][mode_idx].mvs[1].as_int; 2065 mi->bmi[i].as_mv[1].as_int = bsi->rdstat[i][mode_idx].mvs[1].as_int;
2084 xd->plane[0].eobs[i] = bsi->rdstat[i][mode_idx].eobs; 2066 x->plane[0].eobs[i] = bsi->rdstat[i][mode_idx].eobs;
2085 mi->bmi[i].as_mode = bsi->modes[i]; 2067 mi->bmi[i].as_mode = bsi->modes[i];
2086 } 2068 }
2087 2069
2088 /* 2070 /*
2089 * used to set mbmi->mv.as_int 2071 * used to set mbmi->mv.as_int
2090 */ 2072 */
2091 *returntotrate = bsi->r; 2073 *returntotrate = bsi->r;
2092 *returndistortion = bsi->d; 2074 *returndistortion = bsi->d;
2093 *returnyrate = bsi->segment_yrate; 2075 *returnyrate = bsi->segment_yrate;
2094 *skippable = vp9_is_skippable_in_plane(&x->e_mbd, BLOCK_8X8, 0); 2076 *skippable = vp9_is_skippable_in_plane(x, BLOCK_8X8, 0);
2095 *psse = bsi->sse; 2077 *psse = bsi->sse;
2096 mbmi->mode = bsi->modes[3]; 2078 mbmi->mode = bsi->modes[3];
2097 2079
2098 return bsi->segment_rd; 2080 return bsi->segment_rd;
2099 } 2081 }
2100 2082
2101 static void mv_pred(VP9_COMP *cpi, MACROBLOCK *x, 2083 static void mv_pred(VP9_COMP *cpi, MACROBLOCK *x,
2102 uint8_t *ref_y_buffer, int ref_y_stride, 2084 uint8_t *ref_y_buffer, int ref_y_stride,
2103 int ref_frame, BLOCK_SIZE block_size ) { 2085 int ref_frame, BLOCK_SIZE block_size ) {
2104 MACROBLOCKD *xd = &x->e_mbd; 2086 MACROBLOCKD *xd = &x->e_mbd;
2105 MB_MODE_INFO *mbmi = &xd->mi_8x8[0]->mbmi; 2087 MB_MODE_INFO *mbmi = &xd->mi_8x8[0]->mbmi;
2106 int_mv this_mv; 2088 int_mv this_mv;
2107 int i; 2089 int i;
2108 int zero_seen = 0; 2090 int zero_seen = 0;
2109 int best_index = 0; 2091 int best_index = 0;
2110 int best_sad = INT_MAX; 2092 int best_sad = INT_MAX;
2111 int this_sad = INT_MAX; 2093 int this_sad = INT_MAX;
2112 unsigned int max_mv = 0; 2094 int max_mv = 0;
2113 2095
2114 uint8_t *src_y_ptr = x->plane[0].src.buf; 2096 uint8_t *src_y_ptr = x->plane[0].src.buf;
2115 uint8_t *ref_y_ptr; 2097 uint8_t *ref_y_ptr;
2116 int row_offset, col_offset; 2098 int row_offset, col_offset;
2117 int num_mv_refs = MAX_MV_REF_CANDIDATES + 2099 int num_mv_refs = MAX_MV_REF_CANDIDATES +
2118 (cpi->sf.adaptive_motion_search && 2100 (cpi->sf.adaptive_motion_search &&
2119 cpi->common.show_frame && 2101 cpi->common.show_frame &&
2120 block_size < cpi->sf.max_partition_size); 2102 block_size < cpi->sf.max_partition_size);
2121 2103
2122 // Get the sad for each candidate reference mv 2104 // Get the sad for each candidate reference mv
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
2158 vp9_prob *comp_mode_p) { 2140 vp9_prob *comp_mode_p) {
2159 VP9_COMMON *const cm = &cpi->common; 2141 VP9_COMMON *const cm = &cpi->common;
2160 MACROBLOCKD *const xd = &cpi->mb.e_mbd; 2142 MACROBLOCKD *const xd = &cpi->mb.e_mbd;
2161 int seg_ref_active = vp9_segfeature_active(&cm->seg, segment_id, 2143 int seg_ref_active = vp9_segfeature_active(&cm->seg, segment_id,
2162 SEG_LVL_REF_FRAME); 2144 SEG_LVL_REF_FRAME);
2163 if (seg_ref_active) { 2145 if (seg_ref_active) {
2164 vpx_memset(ref_costs_single, 0, MAX_REF_FRAMES * sizeof(*ref_costs_single)); 2146 vpx_memset(ref_costs_single, 0, MAX_REF_FRAMES * sizeof(*ref_costs_single));
2165 vpx_memset(ref_costs_comp, 0, MAX_REF_FRAMES * sizeof(*ref_costs_comp)); 2147 vpx_memset(ref_costs_comp, 0, MAX_REF_FRAMES * sizeof(*ref_costs_comp));
2166 *comp_mode_p = 128; 2148 *comp_mode_p = 128;
2167 } else { 2149 } else {
2168 vp9_prob intra_inter_p = vp9_get_pred_prob_intra_inter(cm, xd); 2150 vp9_prob intra_inter_p = vp9_get_intra_inter_prob(cm, xd);
2169 vp9_prob comp_inter_p = 128; 2151 vp9_prob comp_inter_p = 128;
2170 2152
2171 if (cm->comp_pred_mode == HYBRID_PREDICTION) { 2153 if (cm->reference_mode == REFERENCE_MODE_SELECT) {
2172 comp_inter_p = vp9_get_pred_prob_comp_inter_inter(cm, xd); 2154 comp_inter_p = vp9_get_reference_mode_prob(cm, xd);
2173 *comp_mode_p = comp_inter_p; 2155 *comp_mode_p = comp_inter_p;
2174 } else { 2156 } else {
2175 *comp_mode_p = 128; 2157 *comp_mode_p = 128;
2176 } 2158 }
2177 2159
2178 ref_costs_single[INTRA_FRAME] = vp9_cost_bit(intra_inter_p, 0); 2160 ref_costs_single[INTRA_FRAME] = vp9_cost_bit(intra_inter_p, 0);
2179 2161
2180 if (cm->comp_pred_mode != COMP_PREDICTION_ONLY) { 2162 if (cm->reference_mode != COMPOUND_REFERENCE) {
2181 vp9_prob ref_single_p1 = vp9_get_pred_prob_single_ref_p1(cm, xd); 2163 vp9_prob ref_single_p1 = vp9_get_pred_prob_single_ref_p1(cm, xd);
2182 vp9_prob ref_single_p2 = vp9_get_pred_prob_single_ref_p2(cm, xd); 2164 vp9_prob ref_single_p2 = vp9_get_pred_prob_single_ref_p2(cm, xd);
2183 unsigned int base_cost = vp9_cost_bit(intra_inter_p, 1); 2165 unsigned int base_cost = vp9_cost_bit(intra_inter_p, 1);
2184 2166
2185 if (cm->comp_pred_mode == HYBRID_PREDICTION) 2167 if (cm->reference_mode == REFERENCE_MODE_SELECT)
2186 base_cost += vp9_cost_bit(comp_inter_p, 0); 2168 base_cost += vp9_cost_bit(comp_inter_p, 0);
2187 2169
2188 ref_costs_single[LAST_FRAME] = ref_costs_single[GOLDEN_FRAME] = 2170 ref_costs_single[LAST_FRAME] = ref_costs_single[GOLDEN_FRAME] =
2189 ref_costs_single[ALTREF_FRAME] = base_cost; 2171 ref_costs_single[ALTREF_FRAME] = base_cost;
2190 ref_costs_single[LAST_FRAME] += vp9_cost_bit(ref_single_p1, 0); 2172 ref_costs_single[LAST_FRAME] += vp9_cost_bit(ref_single_p1, 0);
2191 ref_costs_single[GOLDEN_FRAME] += vp9_cost_bit(ref_single_p1, 1); 2173 ref_costs_single[GOLDEN_FRAME] += vp9_cost_bit(ref_single_p1, 1);
2192 ref_costs_single[ALTREF_FRAME] += vp9_cost_bit(ref_single_p1, 1); 2174 ref_costs_single[ALTREF_FRAME] += vp9_cost_bit(ref_single_p1, 1);
2193 ref_costs_single[GOLDEN_FRAME] += vp9_cost_bit(ref_single_p2, 0); 2175 ref_costs_single[GOLDEN_FRAME] += vp9_cost_bit(ref_single_p2, 0);
2194 ref_costs_single[ALTREF_FRAME] += vp9_cost_bit(ref_single_p2, 1); 2176 ref_costs_single[ALTREF_FRAME] += vp9_cost_bit(ref_single_p2, 1);
2195 } else { 2177 } else {
2196 ref_costs_single[LAST_FRAME] = 512; 2178 ref_costs_single[LAST_FRAME] = 512;
2197 ref_costs_single[GOLDEN_FRAME] = 512; 2179 ref_costs_single[GOLDEN_FRAME] = 512;
2198 ref_costs_single[ALTREF_FRAME] = 512; 2180 ref_costs_single[ALTREF_FRAME] = 512;
2199 } 2181 }
2200 if (cm->comp_pred_mode != SINGLE_PREDICTION_ONLY) { 2182 if (cm->reference_mode != SINGLE_REFERENCE) {
2201 vp9_prob ref_comp_p = vp9_get_pred_prob_comp_ref_p(cm, xd); 2183 vp9_prob ref_comp_p = vp9_get_pred_prob_comp_ref_p(cm, xd);
2202 unsigned int base_cost = vp9_cost_bit(intra_inter_p, 1); 2184 unsigned int base_cost = vp9_cost_bit(intra_inter_p, 1);
2203 2185
2204 if (cm->comp_pred_mode == HYBRID_PREDICTION) 2186 if (cm->reference_mode == REFERENCE_MODE_SELECT)
2205 base_cost += vp9_cost_bit(comp_inter_p, 1); 2187 base_cost += vp9_cost_bit(comp_inter_p, 1);
2206 2188
2207 ref_costs_comp[LAST_FRAME] = base_cost + vp9_cost_bit(ref_comp_p, 0); 2189 ref_costs_comp[LAST_FRAME] = base_cost + vp9_cost_bit(ref_comp_p, 0);
2208 ref_costs_comp[GOLDEN_FRAME] = base_cost + vp9_cost_bit(ref_comp_p, 1); 2190 ref_costs_comp[GOLDEN_FRAME] = base_cost + vp9_cost_bit(ref_comp_p, 1);
2209 } else { 2191 } else {
2210 ref_costs_comp[LAST_FRAME] = 512; 2192 ref_costs_comp[LAST_FRAME] = 512;
2211 ref_costs_comp[GOLDEN_FRAME] = 512; 2193 ref_costs_comp[GOLDEN_FRAME] = 512;
2212 } 2194 }
2213 } 2195 }
2214 } 2196 }
2215 2197
2216 static void store_coding_context(MACROBLOCK *x, PICK_MODE_CONTEXT *ctx, 2198 static void store_coding_context(MACROBLOCK *x, PICK_MODE_CONTEXT *ctx,
2217 int mode_index, 2199 int mode_index,
2218 int_mv *ref_mv, 2200 int_mv *ref_mv,
2219 int_mv *second_ref_mv, 2201 int_mv *second_ref_mv,
2220 int64_t comp_pred_diff[NB_PREDICTION_TYPES], 2202 int64_t comp_pred_diff[REFERENCE_MODES],
2221 int64_t tx_size_diff[TX_MODES], 2203 int64_t tx_size_diff[TX_MODES],
2222 int64_t best_filter_diff[SWITCHABLE_FILTER_CONTEXTS]) { 2204 int64_t best_filter_diff[SWITCHABLE_FILTER_CONTEXTS]) {
2223 MACROBLOCKD *const xd = &x->e_mbd; 2205 MACROBLOCKD *const xd = &x->e_mbd;
2224 2206
2225 // Take a snapshot of the coding context so it can be 2207 // Take a snapshot of the coding context so it can be
2226 // restored if we decide to encode this way 2208 // restored if we decide to encode this way
2227 ctx->skip = x->skip; 2209 ctx->skip = x->skip;
2228 ctx->best_mode_index = mode_index; 2210 ctx->best_mode_index = mode_index;
2229 ctx->mic = *xd->mi_8x8[0]; 2211 ctx->mic = *xd->mi_8x8[0];
2230 2212
2231 ctx->best_ref_mv.as_int = ref_mv->as_int; 2213 ctx->best_ref_mv.as_int = ref_mv->as_int;
2232 ctx->second_best_ref_mv.as_int = second_ref_mv->as_int; 2214 ctx->second_best_ref_mv.as_int = second_ref_mv->as_int;
2233 2215
2234 ctx->single_pred_diff = (int)comp_pred_diff[SINGLE_PREDICTION_ONLY]; 2216 ctx->single_pred_diff = (int)comp_pred_diff[SINGLE_REFERENCE];
2235 ctx->comp_pred_diff = (int)comp_pred_diff[COMP_PREDICTION_ONLY]; 2217 ctx->comp_pred_diff = (int)comp_pred_diff[COMPOUND_REFERENCE];
2236 ctx->hybrid_pred_diff = (int)comp_pred_diff[HYBRID_PREDICTION]; 2218 ctx->hybrid_pred_diff = (int)comp_pred_diff[REFERENCE_MODE_SELECT];
2237 2219
2238 vpx_memcpy(ctx->tx_rd_diff, tx_size_diff, sizeof(ctx->tx_rd_diff)); 2220 vpx_memcpy(ctx->tx_rd_diff, tx_size_diff, sizeof(ctx->tx_rd_diff));
2239 vpx_memcpy(ctx->best_filter_diff, best_filter_diff, 2221 vpx_memcpy(ctx->best_filter_diff, best_filter_diff,
2240 sizeof(*best_filter_diff) * SWITCHABLE_FILTER_CONTEXTS); 2222 sizeof(*best_filter_diff) * SWITCHABLE_FILTER_CONTEXTS);
2241 } 2223 }
2242 2224
2243 static void setup_pred_block(const MACROBLOCKD *xd, 2225 static void setup_pred_block(const MACROBLOCKD *xd,
2244 struct buf_2d dst[MAX_MB_PLANE], 2226 struct buf_2d dst[MAX_MB_PLANE],
2245 const YV12_BUFFER_CONFIG *src, 2227 const YV12_BUFFER_CONFIG *src,
2246 int mi_row, int mi_col, 2228 int mi_row, int mi_col,
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
2336 MACROBLOCKD *xd = &x->e_mbd; 2318 MACROBLOCKD *xd = &x->e_mbd;
2337 VP9_COMMON *cm = &cpi->common; 2319 VP9_COMMON *cm = &cpi->common;
2338 MB_MODE_INFO *mbmi = &xd->mi_8x8[0]->mbmi; 2320 MB_MODE_INFO *mbmi = &xd->mi_8x8[0]->mbmi;
2339 struct buf_2d backup_yv12[MAX_MB_PLANE] = {{0}}; 2321 struct buf_2d backup_yv12[MAX_MB_PLANE] = {{0}};
2340 int bestsme = INT_MAX; 2322 int bestsme = INT_MAX;
2341 int further_steps, step_param; 2323 int further_steps, step_param;
2342 int sadpb = x->sadperbit16; 2324 int sadpb = x->sadperbit16;
2343 int_mv mvp_full; 2325 int_mv mvp_full;
2344 int ref = mbmi->ref_frame[0]; 2326 int ref = mbmi->ref_frame[0];
2345 int_mv ref_mv = mbmi->ref_mvs[ref][0]; 2327 int_mv ref_mv = mbmi->ref_mvs[ref][0];
2346 const BLOCK_SIZE block_size = get_plane_block_size(bsize, &xd->plane[0]);
2347 2328
2348 int tmp_col_min = x->mv_col_min; 2329 int tmp_col_min = x->mv_col_min;
2349 int tmp_col_max = x->mv_col_max; 2330 int tmp_col_max = x->mv_col_max;
2350 int tmp_row_min = x->mv_row_min; 2331 int tmp_row_min = x->mv_row_min;
2351 int tmp_row_max = x->mv_row_max; 2332 int tmp_row_max = x->mv_row_max;
2352 2333
2353 YV12_BUFFER_CONFIG *scaled_ref_frame = get_scaled_ref_frame(cpi, ref); 2334 YV12_BUFFER_CONFIG *scaled_ref_frame = get_scaled_ref_frame(cpi, ref);
2354 2335
2355 if (scaled_ref_frame) { 2336 if (scaled_ref_frame) {
2356 int i; 2337 int i;
2357 // Swap out the reference frame for a version that's been scaled to 2338 // Swap out the reference frame for a version that's been scaled to
2358 // match the resolution of the current frame, allowing the existing 2339 // match the resolution of the current frame, allowing the existing
2359 // motion search code to be used without additional modifications. 2340 // motion search code to be used without additional modifications.
2360 for (i = 0; i < MAX_MB_PLANE; i++) 2341 for (i = 0; i < MAX_MB_PLANE; i++)
2361 backup_yv12[i] = xd->plane[i].pre[0]; 2342 backup_yv12[i] = xd->plane[i].pre[0];
2362 2343
2363 setup_pre_planes(xd, 0, scaled_ref_frame, mi_row, mi_col, NULL); 2344 setup_pre_planes(xd, 0, scaled_ref_frame, mi_row, mi_col, NULL);
2364 } 2345 }
2365 2346
2366 vp9_clamp_mv_min_max(x, &ref_mv.as_mv); 2347 vp9_set_mv_search_range(x, &ref_mv.as_mv);
2367 2348
2368 // Adjust search parameters based on small partitions' result. 2349 // Adjust search parameters based on small partitions' result.
2369 if (x->fast_ms) { 2350 if (x->fast_ms) {
2370 // && abs(mvp_full.as_mv.row - x->pred_mv.as_mv.row) < 24 && 2351 // && abs(mvp_full.as_mv.row - x->pred_mv.as_mv.row) < 24 &&
2371 // abs(mvp_full.as_mv.col - x->pred_mv.as_mv.col) < 24) { 2352 // abs(mvp_full.as_mv.col - x->pred_mv.as_mv.col) < 24) {
2372 // adjust search range 2353 // adjust search range
2373 step_param = 6; 2354 step_param = 6;
2374 if (x->fast_ms > 1) 2355 if (x->fast_ms > 1)
2375 step_param = 8; 2356 step_param = 8;
2376 2357
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
2410 mvp_full.as_mv.col >>= 3; 2391 mvp_full.as_mv.col >>= 3;
2411 mvp_full.as_mv.row >>= 3; 2392 mvp_full.as_mv.row >>= 3;
2412 2393
2413 // Further step/diamond searches as necessary 2394 // Further step/diamond searches as necessary
2414 further_steps = (cpi->sf.max_step_search_steps - 1) - step_param; 2395 further_steps = (cpi->sf.max_step_search_steps - 1) - step_param;
2415 2396
2416 if (cpi->sf.search_method == HEX) { 2397 if (cpi->sf.search_method == HEX) {
2417 bestsme = vp9_hex_search(x, &mvp_full.as_mv, 2398 bestsme = vp9_hex_search(x, &mvp_full.as_mv,
2418 step_param, 2399 step_param,
2419 sadpb, 1, 2400 sadpb, 1,
2420 &cpi->fn_ptr[block_size], 1, 2401 &cpi->fn_ptr[bsize], 1,
2421 &ref_mv.as_mv, &tmp_mv->as_mv); 2402 &ref_mv.as_mv, &tmp_mv->as_mv);
2422 } else if (cpi->sf.search_method == SQUARE) { 2403 } else if (cpi->sf.search_method == SQUARE) {
2423 bestsme = vp9_square_search(x, &mvp_full.as_mv, 2404 bestsme = vp9_square_search(x, &mvp_full.as_mv,
2424 step_param, 2405 step_param,
2425 sadpb, 1, 2406 sadpb, 1,
2426 &cpi->fn_ptr[block_size], 1, 2407 &cpi->fn_ptr[bsize], 1,
2427 &ref_mv.as_mv, &tmp_mv->as_mv); 2408 &ref_mv.as_mv, &tmp_mv->as_mv);
2428 } else if (cpi->sf.search_method == BIGDIA) { 2409 } else if (cpi->sf.search_method == BIGDIA) {
2429 bestsme = vp9_bigdia_search(x, &mvp_full.as_mv, 2410 bestsme = vp9_bigdia_search(x, &mvp_full.as_mv,
2430 step_param, 2411 step_param,
2431 sadpb, 1, 2412 sadpb, 1,
2432 &cpi->fn_ptr[block_size], 1, 2413 &cpi->fn_ptr[bsize], 1,
2433 &ref_mv.as_mv, &tmp_mv->as_mv); 2414 &ref_mv.as_mv, &tmp_mv->as_mv);
2434 } else { 2415 } else {
2435 bestsme = vp9_full_pixel_diamond(cpi, x, &mvp_full, step_param, 2416 bestsme = vp9_full_pixel_diamond(cpi, x, &mvp_full, step_param,
2436 sadpb, further_steps, 1, 2417 sadpb, further_steps, 1,
2437 &cpi->fn_ptr[block_size], 2418 &cpi->fn_ptr[bsize],
2438 &ref_mv, tmp_mv); 2419 &ref_mv, tmp_mv);
2439 } 2420 }
2440 2421
2441 x->mv_col_min = tmp_col_min; 2422 x->mv_col_min = tmp_col_min;
2442 x->mv_col_max = tmp_col_max; 2423 x->mv_col_max = tmp_col_max;
2443 x->mv_row_min = tmp_row_min; 2424 x->mv_row_min = tmp_row_min;
2444 x->mv_row_max = tmp_row_max; 2425 x->mv_row_max = tmp_row_max;
2445 2426
2446 if (bestsme < INT_MAX) { 2427 if (bestsme < INT_MAX) {
2447 int dis; /* TODO: use dis in distortion calculation later. */ 2428 int dis; /* TODO: use dis in distortion calculation later. */
2448 unsigned int sse; 2429 unsigned int sse;
2449 cpi->find_fractional_mv_step(x, &tmp_mv->as_mv, &ref_mv.as_mv, 2430 cpi->find_fractional_mv_step(x, &tmp_mv->as_mv, &ref_mv.as_mv,
2450 cm->allow_high_precision_mv, 2431 cm->allow_high_precision_mv,
2451 x->errorperbit, 2432 x->errorperbit,
2452 &cpi->fn_ptr[block_size], 2433 &cpi->fn_ptr[bsize],
2453 0, cpi->sf.subpel_iters_per_step, 2434 0, cpi->sf.subpel_iters_per_step,
2454 x->nmvjointcost, x->mvcost, 2435 x->nmvjointcost, x->mvcost,
2455 &dis, &sse); 2436 &dis, &sse);
2456 } 2437 }
2457 *rate_mv = vp9_mv_bit_cost(&tmp_mv->as_mv, &ref_mv.as_mv, 2438 *rate_mv = vp9_mv_bit_cost(&tmp_mv->as_mv, &ref_mv.as_mv,
2458 x->nmvjointcost, x->mvcost, MV_COST_WEIGHT); 2439 x->nmvjointcost, x->mvcost, MV_COST_WEIGHT);
2459 2440
2460 if (cpi->sf.adaptive_motion_search && cpi->common.show_frame) 2441 if (cpi->sf.adaptive_motion_search && cpi->common.show_frame)
2461 x->pred_mv[ref].as_int = tmp_mv->as_int; 2442 x->pred_mv[ref].as_int = tmp_mv->as_int;
2462 2443
2463 if (scaled_ref_frame) { 2444 if (scaled_ref_frame) {
2464 int i; 2445 int i;
2465 for (i = 0; i < MAX_MB_PLANE; i++) 2446 for (i = 0; i < MAX_MB_PLANE; i++)
2466 xd->plane[i].pre[0] = backup_yv12[i]; 2447 xd->plane[i].pre[0] = backup_yv12[i];
2467 } 2448 }
2468 } 2449 }
2469 2450
2470 static void joint_motion_search(VP9_COMP *cpi, MACROBLOCK *x, 2451 static void joint_motion_search(VP9_COMP *cpi, MACROBLOCK *x,
2471 BLOCK_SIZE bsize, 2452 BLOCK_SIZE bsize,
2472 int_mv *frame_mv, 2453 int_mv *frame_mv,
2473 int mi_row, int mi_col, 2454 int mi_row, int mi_col,
2474 int_mv single_newmv[MAX_REF_FRAMES], 2455 int_mv single_newmv[MAX_REF_FRAMES],
2475 int *rate_mv) { 2456 int *rate_mv) {
2476 int pw = 4 << b_width_log2(bsize), ph = 4 << b_height_log2(bsize); 2457 const int pw = 4 * num_4x4_blocks_wide_lookup[bsize];
2458 const int ph = 4 * num_4x4_blocks_high_lookup[bsize];
2477 MACROBLOCKD *xd = &x->e_mbd; 2459 MACROBLOCKD *xd = &x->e_mbd;
2478 MB_MODE_INFO *mbmi = &xd->mi_8x8[0]->mbmi; 2460 MB_MODE_INFO *mbmi = &xd->mi_8x8[0]->mbmi;
2479 int refs[2] = { mbmi->ref_frame[0], 2461 const int refs[2] = { mbmi->ref_frame[0],
2480 (mbmi->ref_frame[1] < 0 ? 0 : mbmi->ref_frame[1]) }; 2462 mbmi->ref_frame[1] < 0 ? 0 : mbmi->ref_frame[1] };
2481 int_mv ref_mv[2]; 2463 int_mv ref_mv[2];
2482 const BLOCK_SIZE block_size = get_plane_block_size(bsize, &xd->plane[0]); 2464 int ite, ref;
2483 int ite;
2484 // Prediction buffer from second frame. 2465 // Prediction buffer from second frame.
2485 uint8_t *second_pred = vpx_memalign(16, pw * ph * sizeof(uint8_t)); 2466 uint8_t *second_pred = vpx_memalign(16, pw * ph * sizeof(uint8_t));
2486 2467
2487 // Do joint motion search in compound mode to get more accurate mv. 2468 // Do joint motion search in compound mode to get more accurate mv.
2488 struct buf_2d backup_yv12[MAX_MB_PLANE] = {{0}}; 2469 struct buf_2d backup_yv12[2][MAX_MB_PLANE];
2489 struct buf_2d backup_second_yv12[MAX_MB_PLANE] = {{0}}; 2470 struct buf_2d scaled_first_yv12 = xd->plane[0].pre[0];
2490 struct buf_2d scaled_first_yv12;
2491 int last_besterr[2] = {INT_MAX, INT_MAX}; 2471 int last_besterr[2] = {INT_MAX, INT_MAX};
2492 YV12_BUFFER_CONFIG *scaled_ref_frame[2] = {NULL, NULL}; 2472 YV12_BUFFER_CONFIG *const scaled_ref_frame[2] = {
2493 scaled_ref_frame[0] = get_scaled_ref_frame(cpi, mbmi->ref_frame[0]); 2473 get_scaled_ref_frame(cpi, mbmi->ref_frame[0]),
2494 scaled_ref_frame[1] = get_scaled_ref_frame(cpi, mbmi->ref_frame[1]); 2474 get_scaled_ref_frame(cpi, mbmi->ref_frame[1])
2475 };
2495 2476
2496 ref_mv[0] = mbmi->ref_mvs[refs[0]][0]; 2477 for (ref = 0; ref < 2; ++ref) {
2497 ref_mv[1] = mbmi->ref_mvs[refs[1]][0]; 2478 ref_mv[ref] = mbmi->ref_mvs[refs[ref]][0];
2498 2479
2499 if (scaled_ref_frame[0]) { 2480 if (scaled_ref_frame[ref]) {
2500 int i; 2481 int i;
2501 // Swap out the reference frame for a version that's been scaled to 2482 // Swap out the reference frame for a version that's been scaled to
2502 // match the resolution of the current frame, allowing the existing 2483 // match the resolution of the current frame, allowing the existing
2503 // motion search code to be used without additional modifications. 2484 // motion search code to be used without additional modifications.
2504 for (i = 0; i < MAX_MB_PLANE; i++) 2485 for (i = 0; i < MAX_MB_PLANE; i++)
2505 backup_yv12[i] = xd->plane[i].pre[0]; 2486 backup_yv12[ref][i] = xd->plane[i].pre[ref];
2506 setup_pre_planes(xd, 0, scaled_ref_frame[0], mi_row, mi_col, NULL); 2487 setup_pre_planes(xd, ref, scaled_ref_frame[ref], mi_row, mi_col, NULL);
2488 }
2489
2490 xd->scale_factor[ref].sfc->set_scaled_offsets(&xd->scale_factor[ref],
2491 mi_row, mi_col);
2492 frame_mv[refs[ref]].as_int = single_newmv[refs[ref]].as_int;
2507 } 2493 }
2508 2494
2509 if (scaled_ref_frame[1]) {
2510 int i;
2511 for (i = 0; i < MAX_MB_PLANE; i++)
2512 backup_second_yv12[i] = xd->plane[i].pre[1];
2513
2514 setup_pre_planes(xd, 1, scaled_ref_frame[1], mi_row, mi_col, NULL);
2515 }
2516
2517 xd->scale_factor[0].sfc->set_scaled_offsets(&xd->scale_factor[0],
2518 mi_row, mi_col);
2519 xd->scale_factor[1].sfc->set_scaled_offsets(&xd->scale_factor[1],
2520 mi_row, mi_col);
2521 scaled_first_yv12 = xd->plane[0].pre[0];
2522
2523 // Initialize mv using single prediction mode result.
2524 frame_mv[refs[0]].as_int = single_newmv[refs[0]].as_int;
2525 frame_mv[refs[1]].as_int = single_newmv[refs[1]].as_int;
2526
2527 // Allow joint search multiple times iteratively for each ref frame 2495 // Allow joint search multiple times iteratively for each ref frame
2528 // and break out the search loop if it couldn't find better mv. 2496 // and break out the search loop if it couldn't find better mv.
2529 for (ite = 0; ite < 4; ite++) { 2497 for (ite = 0; ite < 4; ite++) {
2530 struct buf_2d ref_yv12[2]; 2498 struct buf_2d ref_yv12[2];
2531 int bestsme = INT_MAX; 2499 int bestsme = INT_MAX;
2532 int sadpb = x->sadperbit16; 2500 int sadpb = x->sadperbit16;
2533 int_mv tmp_mv; 2501 int_mv tmp_mv;
2534 int search_range = 3; 2502 int search_range = 3;
2535 2503
2536 int tmp_col_min = x->mv_col_min; 2504 int tmp_col_min = x->mv_col_min;
(...skipping 11 matching lines...) Expand all
2548 ref_yv12[!id].stride, 2516 ref_yv12[!id].stride,
2549 second_pred, pw, 2517 second_pred, pw,
2550 &frame_mv[refs[!id]].as_mv, 2518 &frame_mv[refs[!id]].as_mv,
2551 &xd->scale_factor[!id], 2519 &xd->scale_factor[!id],
2552 pw, ph, 0, 2520 pw, ph, 0,
2553 &xd->subpix, MV_PRECISION_Q3); 2521 &xd->subpix, MV_PRECISION_Q3);
2554 2522
2555 // Compound motion search on first ref frame. 2523 // Compound motion search on first ref frame.
2556 if (id) 2524 if (id)
2557 xd->plane[0].pre[0] = ref_yv12[id]; 2525 xd->plane[0].pre[0] = ref_yv12[id];
2558 vp9_clamp_mv_min_max(x, &ref_mv[id].as_mv); 2526 vp9_set_mv_search_range(x, &ref_mv[id].as_mv);
2559 2527
2560 // Use mv result from single mode as mvp. 2528 // Use mv result from single mode as mvp.
2561 tmp_mv.as_int = frame_mv[refs[id]].as_int; 2529 tmp_mv.as_int = frame_mv[refs[id]].as_int;
2562 2530
2563 tmp_mv.as_mv.col >>= 3; 2531 tmp_mv.as_mv.col >>= 3;
2564 tmp_mv.as_mv.row >>= 3; 2532 tmp_mv.as_mv.row >>= 3;
2565 2533
2566 // Small-range full-pixel motion search 2534 // Small-range full-pixel motion search
2567 bestsme = vp9_refining_search_8p_c(x, &tmp_mv, sadpb, 2535 bestsme = vp9_refining_search_8p_c(x, &tmp_mv, sadpb,
2568 search_range, 2536 search_range,
2569 &cpi->fn_ptr[block_size], 2537 &cpi->fn_ptr[bsize],
2570 x->nmvjointcost, x->mvcost, 2538 x->nmvjointcost, x->mvcost,
2571 &ref_mv[id], second_pred, 2539 &ref_mv[id], second_pred,
2572 pw, ph); 2540 pw, ph);
2573 2541
2574 x->mv_col_min = tmp_col_min; 2542 x->mv_col_min = tmp_col_min;
2575 x->mv_col_max = tmp_col_max; 2543 x->mv_col_max = tmp_col_max;
2576 x->mv_row_min = tmp_row_min; 2544 x->mv_row_min = tmp_row_min;
2577 x->mv_row_max = tmp_row_max; 2545 x->mv_row_max = tmp_row_max;
2578 2546
2579 if (bestsme < INT_MAX) { 2547 if (bestsme < INT_MAX) {
2580 int dis; /* TODO: use dis in distortion calculation later. */ 2548 int dis; /* TODO: use dis in distortion calculation later. */
2581 unsigned int sse; 2549 unsigned int sse;
2582 2550
2583 bestsme = cpi->find_fractional_mv_step_comp( 2551 bestsme = cpi->find_fractional_mv_step_comp(
2584 x, &tmp_mv.as_mv, 2552 x, &tmp_mv.as_mv,
2585 &ref_mv[id].as_mv, 2553 &ref_mv[id].as_mv,
2586 cpi->common.allow_high_precision_mv, 2554 cpi->common.allow_high_precision_mv,
2587 x->errorperbit, 2555 x->errorperbit,
2588 &cpi->fn_ptr[block_size], 2556 &cpi->fn_ptr[bsize],
2589 0, cpi->sf.subpel_iters_per_step, 2557 0, cpi->sf.subpel_iters_per_step,
2590 x->nmvjointcost, x->mvcost, 2558 x->nmvjointcost, x->mvcost,
2591 &dis, &sse, second_pred, 2559 &dis, &sse, second_pred,
2592 pw, ph); 2560 pw, ph);
2593 } 2561 }
2594 2562
2595 if (id) 2563 if (id)
2596 xd->plane[0].pre[0] = scaled_first_yv12; 2564 xd->plane[0].pre[0] = scaled_first_yv12;
2597 2565
2598 if (bestsme < last_besterr[id]) { 2566 if (bestsme < last_besterr[id]) {
2599 frame_mv[refs[id]].as_int = tmp_mv.as_int; 2567 frame_mv[refs[id]].as_int = tmp_mv.as_int;
2600 last_besterr[id] = bestsme; 2568 last_besterr[id] = bestsme;
2601 } else { 2569 } else {
2602 break; 2570 break;
2603 } 2571 }
2604 } 2572 }
2605 2573
2606 // restore the predictor 2574 *rate_mv = 0;
2607 if (scaled_ref_frame[0]) { 2575
2608 int i; 2576 for (ref = 0; ref < 2; ++ref) {
2609 for (i = 0; i < MAX_MB_PLANE; i++) 2577 if (scaled_ref_frame[ref]) {
2610 xd->plane[i].pre[0] = backup_yv12[i]; 2578 // restore the predictor
2579 int i;
2580 for (i = 0; i < MAX_MB_PLANE; i++)
2581 xd->plane[i].pre[ref] = backup_yv12[ref][i];
2582 }
2583
2584 *rate_mv += vp9_mv_bit_cost(&frame_mv[refs[ref]].as_mv,
2585 &mbmi->ref_mvs[refs[ref]][0].as_mv,
2586 x->nmvjointcost, x->mvcost, MV_COST_WEIGHT);
2611 } 2587 }
2612 2588
2613 if (scaled_ref_frame[1]) { 2589 vpx_free(second_pred);
2614 int i; 2590 }
2615 for (i = 0; i < MAX_MB_PLANE; i++) 2591
2616 xd->plane[i].pre[1] = backup_second_yv12[i]; 2592 static INLINE void restore_dst_buf(MACROBLOCKD *xd,
2593 uint8_t *orig_dst[MAX_MB_PLANE],
2594 int orig_dst_stride[MAX_MB_PLANE]) {
2595 int i;
2596 for (i = 0; i < MAX_MB_PLANE; i++) {
2597 xd->plane[i].dst.buf = orig_dst[i];
2598 xd->plane[i].dst.stride = orig_dst_stride[i];
2617 } 2599 }
2618 *rate_mv = vp9_mv_bit_cost(&frame_mv[refs[0]].as_mv,
2619 &mbmi->ref_mvs[refs[0]][0].as_mv,
2620 x->nmvjointcost, x->mvcost, MV_COST_WEIGHT);
2621 *rate_mv += vp9_mv_bit_cost(&frame_mv[refs[1]].as_mv,
2622 &mbmi->ref_mvs[refs[1]][0].as_mv,
2623 x->nmvjointcost, x->mvcost, MV_COST_WEIGHT);
2624
2625 vpx_free(second_pred);
2626 } 2600 }
2627 2601
2628 static int64_t handle_inter_mode(VP9_COMP *cpi, MACROBLOCK *x, 2602 static int64_t handle_inter_mode(VP9_COMP *cpi, MACROBLOCK *x,
2629 const TileInfo *const tile, 2603 const TileInfo *const tile,
2630 BLOCK_SIZE bsize, 2604 BLOCK_SIZE bsize,
2631 int64_t txfm_cache[], 2605 int64_t txfm_cache[],
2632 int *rate2, int64_t *distortion, 2606 int *rate2, int64_t *distortion,
2633 int *skippable, 2607 int *skippable,
2634 int *rate_y, int64_t *distortion_y, 2608 int *rate_y, int64_t *distortion_y,
2635 int *rate_uv, int64_t *distortion_uv, 2609 int *rate_uv, int64_t *distortion_uv,
(...skipping 18 matching lines...) Expand all
2654 int64_t this_rd = 0; 2628 int64_t this_rd = 0;
2655 DECLARE_ALIGNED_ARRAY(16, uint8_t, tmp_buf, MAX_MB_PLANE * 64 * 64); 2629 DECLARE_ALIGNED_ARRAY(16, uint8_t, tmp_buf, MAX_MB_PLANE * 64 * 64);
2656 int pred_exists = 0; 2630 int pred_exists = 0;
2657 int intpel_mv; 2631 int intpel_mv;
2658 int64_t rd, best_rd = INT64_MAX; 2632 int64_t rd, best_rd = INT64_MAX;
2659 int best_needs_copy = 0; 2633 int best_needs_copy = 0;
2660 uint8_t *orig_dst[MAX_MB_PLANE]; 2634 uint8_t *orig_dst[MAX_MB_PLANE];
2661 int orig_dst_stride[MAX_MB_PLANE]; 2635 int orig_dst_stride[MAX_MB_PLANE];
2662 int rs = 0; 2636 int rs = 0;
2663 2637
2638 if (is_comp_pred) {
2639 if (frame_mv[refs[0]].as_int == INVALID_MV ||
2640 frame_mv[refs[1]].as_int == INVALID_MV)
2641 return INT64_MAX;
2642 }
2643
2664 if (this_mode == NEWMV) { 2644 if (this_mode == NEWMV) {
2665 int rate_mv; 2645 int rate_mv;
2666 if (is_comp_pred) { 2646 if (is_comp_pred) {
2667 // Initialize mv using single prediction mode result. 2647 // Initialize mv using single prediction mode result.
2668 frame_mv[refs[0]].as_int = single_newmv[refs[0]].as_int; 2648 frame_mv[refs[0]].as_int = single_newmv[refs[0]].as_int;
2669 frame_mv[refs[1]].as_int = single_newmv[refs[1]].as_int; 2649 frame_mv[refs[1]].as_int = single_newmv[refs[1]].as_int;
2670 2650
2671 if (cpi->sf.comp_inter_joint_search_thresh <= bsize) { 2651 if (cpi->sf.comp_inter_joint_search_thresh <= bsize) {
2672 joint_motion_search(cpi, x, bsize, frame_mv, 2652 joint_motion_search(cpi, x, bsize, frame_mv,
2673 mi_row, mi_col, single_newmv, &rate_mv); 2653 mi_row, mi_col, single_newmv, &rate_mv);
2674 } else { 2654 } else {
2675 rate_mv = vp9_mv_bit_cost(&frame_mv[refs[0]].as_mv, 2655 rate_mv = vp9_mv_bit_cost(&frame_mv[refs[0]].as_mv,
2676 &mbmi->ref_mvs[refs[0]][0].as_mv, 2656 &mbmi->ref_mvs[refs[0]][0].as_mv,
2677 x->nmvjointcost, x->mvcost, MV_COST_WEIGHT); 2657 x->nmvjointcost, x->mvcost, MV_COST_WEIGHT);
2678 rate_mv += vp9_mv_bit_cost(&frame_mv[refs[1]].as_mv, 2658 rate_mv += vp9_mv_bit_cost(&frame_mv[refs[1]].as_mv,
2679 &mbmi->ref_mvs[refs[1]][0].as_mv, 2659 &mbmi->ref_mvs[refs[1]][0].as_mv,
2680 x->nmvjointcost, x->mvcost, MV_COST_WEIGHT); 2660 x->nmvjointcost, x->mvcost, MV_COST_WEIGHT);
2681 } 2661 }
2682 if (frame_mv[refs[0]].as_int == INVALID_MV ||
2683 frame_mv[refs[1]].as_int == INVALID_MV)
2684 return INT64_MAX;
2685 *rate2 += rate_mv; 2662 *rate2 += rate_mv;
2686 } else { 2663 } else {
2687 int_mv tmp_mv; 2664 int_mv tmp_mv;
2688 single_motion_search(cpi, x, tile, bsize, mi_row, mi_col, 2665 single_motion_search(cpi, x, tile, bsize, mi_row, mi_col,
2689 &tmp_mv, &rate_mv); 2666 &tmp_mv, &rate_mv);
2690 *rate2 += rate_mv; 2667 *rate2 += rate_mv;
2691 frame_mv[refs[0]].as_int = 2668 frame_mv[refs[0]].as_int =
2692 xd->mi_8x8[0]->bmi[0].as_mv[0].as_int = tmp_mv.as_int; 2669 xd->mi_8x8[0]->bmi[0].as_mv[0].as_int = tmp_mv.as_int;
2693 single_newmv[refs[0]].as_int = tmp_mv.as_int; 2670 single_newmv[refs[0]].as_int = tmp_mv.as_int;
2694 } 2671 }
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
2751 orig_dst_stride[i] = xd->plane[i].dst.stride; 2728 orig_dst_stride[i] = xd->plane[i].dst.stride;
2752 } 2729 }
2753 2730
2754 /* We don't include the cost of the second reference here, because there 2731 /* We don't include the cost of the second reference here, because there
2755 * are only three options: Last/Golden, ARF/Last or Golden/ARF, or in other 2732 * are only three options: Last/Golden, ARF/Last or Golden/ARF, or in other
2756 * words if you present them in that order, the second one is always known 2733 * words if you present them in that order, the second one is always known
2757 * if the first is known */ 2734 * if the first is known */
2758 *rate2 += cost_mv_ref(cpi, this_mode, 2735 *rate2 += cost_mv_ref(cpi, this_mode,
2759 mbmi->mode_context[mbmi->ref_frame[0]]); 2736 mbmi->mode_context[mbmi->ref_frame[0]]);
2760 2737
2761 if (!(*mode_excluded)) { 2738 if (!(*mode_excluded))
2762 if (is_comp_pred) { 2739 *mode_excluded = is_comp_pred
2763 *mode_excluded = (cpi->common.comp_pred_mode == SINGLE_PREDICTION_ONLY); 2740 ? cpi->common.reference_mode == SINGLE_REFERENCE
2764 } else { 2741 : cpi->common.reference_mode == COMPOUND_REFERENCE;
2765 *mode_excluded = (cpi->common.comp_pred_mode == COMP_PREDICTION_ONLY);
2766 }
2767 }
2768 2742
2769 pred_exists = 0; 2743 pred_exists = 0;
2770 // Are all MVs integer pel for Y and UV 2744 // Are all MVs integer pel for Y and UV
2771 intpel_mv = (mbmi->mv[0].as_mv.row & 15) == 0 && 2745 intpel_mv = (mbmi->mv[0].as_mv.row & 15) == 0 &&
2772 (mbmi->mv[0].as_mv.col & 15) == 0; 2746 (mbmi->mv[0].as_mv.col & 15) == 0;
2773 if (is_comp_pred) 2747 if (is_comp_pred)
2774 intpel_mv &= (mbmi->mv[1].as_mv.row & 15) == 0 && 2748 intpel_mv &= (mbmi->mv[1].as_mv.row & 15) == 0 &&
2775 (mbmi->mv[1].as_mv.col & 15) == 0; 2749 (mbmi->mv[1].as_mv.col & 15) == 0;
2750
2776 // Search for best switchable filter by checking the variance of 2751 // Search for best switchable filter by checking the variance of
2777 // pred error irrespective of whether the filter will be used 2752 // pred error irrespective of whether the filter will be used
2778 if (cm->mcomp_filter_type != BILINEAR) { 2753 if (cm->mcomp_filter_type != BILINEAR) {
2779 *best_filter = EIGHTTAP; 2754 *best_filter = EIGHTTAP;
2780 if (x->source_variance < 2755 if (x->source_variance <
2781 cpi->sf.disable_filter_search_var_thresh) { 2756 cpi->sf.disable_filter_search_var_thresh) {
2782 *best_filter = EIGHTTAP; 2757 *best_filter = EIGHTTAP;
2783 vp9_zero(cpi->rd_filter_cache); 2758 vp9_zero(cpi->rd_filter_cache);
2784 } else { 2759 } else {
2785 int i, newbest; 2760 int i, newbest;
(...skipping 19 matching lines...) Expand all
2805 if (cm->mcomp_filter_type == SWITCHABLE) 2780 if (cm->mcomp_filter_type == SWITCHABLE)
2806 rd += rs_rd; 2781 rd += rs_rd;
2807 } else { 2782 } else {
2808 int rate_sum = 0; 2783 int rate_sum = 0;
2809 int64_t dist_sum = 0; 2784 int64_t dist_sum = 0;
2810 if ((cm->mcomp_filter_type == SWITCHABLE && 2785 if ((cm->mcomp_filter_type == SWITCHABLE &&
2811 (!i || best_needs_copy)) || 2786 (!i || best_needs_copy)) ||
2812 (cm->mcomp_filter_type != SWITCHABLE && 2787 (cm->mcomp_filter_type != SWITCHABLE &&
2813 (cm->mcomp_filter_type == mbmi->interp_filter || 2788 (cm->mcomp_filter_type == mbmi->interp_filter ||
2814 (i == 0 && intpel_mv)))) { 2789 (i == 0 && intpel_mv)))) {
2815 for (j = 0; j < MAX_MB_PLANE; j++) { 2790 restore_dst_buf(xd, orig_dst, orig_dst_stride);
2816 xd->plane[j].dst.buf = orig_dst[j];
2817 xd->plane[j].dst.stride = orig_dst_stride[j];
2818 }
2819 } else { 2791 } else {
2820 for (j = 0; j < MAX_MB_PLANE; j++) { 2792 for (j = 0; j < MAX_MB_PLANE; j++) {
2821 xd->plane[j].dst.buf = tmp_buf + j * 64 * 64; 2793 xd->plane[j].dst.buf = tmp_buf + j * 64 * 64;
2822 xd->plane[j].dst.stride = 64; 2794 xd->plane[j].dst.stride = 64;
2823 } 2795 }
2824 } 2796 }
2825 vp9_build_inter_predictors_sb(xd, mi_row, mi_col, bsize); 2797 vp9_build_inter_predictors_sb(xd, mi_row, mi_col, bsize);
2826 model_rd_for_sb(cpi, bsize, x, xd, &rate_sum, &dist_sum); 2798 model_rd_for_sb(cpi, bsize, x, xd, &rate_sum, &dist_sum);
2827 cpi->rd_filter_cache[i] = RDCOST(x->rdmult, x->rddiv, 2799 cpi->rd_filter_cache[i] = RDCOST(x->rdmult, x->rddiv,
2828 rate_sum, dist_sum); 2800 rate_sum, dist_sum);
2829 cpi->rd_filter_cache[SWITCHABLE_FILTERS] = 2801 cpi->rd_filter_cache[SWITCHABLE_FILTERS] =
2830 MIN(cpi->rd_filter_cache[SWITCHABLE_FILTERS], 2802 MIN(cpi->rd_filter_cache[SWITCHABLE_FILTERS],
2831 cpi->rd_filter_cache[i] + rs_rd); 2803 cpi->rd_filter_cache[i] + rs_rd);
2832 rd = cpi->rd_filter_cache[i]; 2804 rd = cpi->rd_filter_cache[i];
2833 if (cm->mcomp_filter_type == SWITCHABLE) 2805 if (cm->mcomp_filter_type == SWITCHABLE)
2834 rd += rs_rd; 2806 rd += rs_rd;
2835 if (i == 0 && intpel_mv) { 2807 if (i == 0 && intpel_mv) {
2836 tmp_rate_sum = rate_sum; 2808 tmp_rate_sum = rate_sum;
2837 tmp_dist_sum = dist_sum; 2809 tmp_dist_sum = dist_sum;
2838 } 2810 }
2839 } 2811 }
2840 if (i == 0 && cpi->sf.use_rd_breakout && ref_best_rd < INT64_MAX) { 2812 if (i == 0 && cpi->sf.use_rd_breakout && ref_best_rd < INT64_MAX) {
2841 if (rd / 2 > ref_best_rd) { 2813 if (rd / 2 > ref_best_rd) {
2842 for (i = 0; i < MAX_MB_PLANE; i++) { 2814 restore_dst_buf(xd, orig_dst, orig_dst_stride);
2843 xd->plane[i].dst.buf = orig_dst[i];
2844 xd->plane[i].dst.stride = orig_dst_stride[i];
2845 }
2846 return INT64_MAX; 2815 return INT64_MAX;
2847 } 2816 }
2848 } 2817 }
2849 newbest = i == 0 || rd < best_rd; 2818 newbest = i == 0 || rd < best_rd;
2850 2819
2851 if (newbest) { 2820 if (newbest) {
2852 best_rd = rd; 2821 best_rd = rd;
2853 *best_filter = mbmi->interp_filter; 2822 *best_filter = mbmi->interp_filter;
2854 if (cm->mcomp_filter_type == SWITCHABLE && i && !intpel_mv) 2823 if (cm->mcomp_filter_type == SWITCHABLE && i && !intpel_mv)
2855 best_needs_copy = !best_needs_copy; 2824 best_needs_copy = !best_needs_copy;
2856 } 2825 }
2857 2826
2858 if ((cm->mcomp_filter_type == SWITCHABLE && newbest) || 2827 if ((cm->mcomp_filter_type == SWITCHABLE && newbest) ||
2859 (cm->mcomp_filter_type != SWITCHABLE && 2828 (cm->mcomp_filter_type != SWITCHABLE &&
2860 cm->mcomp_filter_type == mbmi->interp_filter)) { 2829 cm->mcomp_filter_type == mbmi->interp_filter)) {
2861 pred_exists = 1; 2830 pred_exists = 1;
2862 } 2831 }
2863 } 2832 }
2864 2833 restore_dst_buf(xd, orig_dst, orig_dst_stride);
2865 for (i = 0; i < MAX_MB_PLANE; i++) {
2866 xd->plane[i].dst.buf = orig_dst[i];
2867 xd->plane[i].dst.stride = orig_dst_stride[i];
2868 }
2869 } 2834 }
2870 } 2835 }
2871 // Set the appropriate filter 2836 // Set the appropriate filter
2872 mbmi->interp_filter = cm->mcomp_filter_type != SWITCHABLE ? 2837 mbmi->interp_filter = cm->mcomp_filter_type != SWITCHABLE ?
2873 cm->mcomp_filter_type : *best_filter; 2838 cm->mcomp_filter_type : *best_filter;
2874 vp9_setup_interp_filters(xd, mbmi->interp_filter, cm); 2839 vp9_setup_interp_filters(xd, mbmi->interp_filter, cm);
2875 rs = cm->mcomp_filter_type == SWITCHABLE ? get_switchable_rate(x) : 0; 2840 rs = cm->mcomp_filter_type == SWITCHABLE ? get_switchable_rate(x) : 0;
2876 2841
2877 if (pred_exists) { 2842 if (pred_exists) {
2878 if (best_needs_copy) { 2843 if (best_needs_copy) {
(...skipping 11 matching lines...) Expand all
2890 2855
2891 2856
2892 if (cpi->sf.use_rd_breakout && ref_best_rd < INT64_MAX) { 2857 if (cpi->sf.use_rd_breakout && ref_best_rd < INT64_MAX) {
2893 int tmp_rate; 2858 int tmp_rate;
2894 int64_t tmp_dist; 2859 int64_t tmp_dist;
2895 model_rd_for_sb(cpi, bsize, x, xd, &tmp_rate, &tmp_dist); 2860 model_rd_for_sb(cpi, bsize, x, xd, &tmp_rate, &tmp_dist);
2896 rd = RDCOST(x->rdmult, x->rddiv, rs + tmp_rate, tmp_dist); 2861 rd = RDCOST(x->rdmult, x->rddiv, rs + tmp_rate, tmp_dist);
2897 // if current pred_error modeled rd is substantially more than the best 2862 // if current pred_error modeled rd is substantially more than the best
2898 // so far, do not bother doing full rd 2863 // so far, do not bother doing full rd
2899 if (rd / 2 > ref_best_rd) { 2864 if (rd / 2 > ref_best_rd) {
2900 for (i = 0; i < MAX_MB_PLANE; i++) { 2865 restore_dst_buf(xd, orig_dst, orig_dst_stride);
2901 xd->plane[i].dst.buf = orig_dst[i];
2902 xd->plane[i].dst.stride = orig_dst_stride[i];
2903 }
2904 return INT64_MAX; 2866 return INT64_MAX;
2905 } 2867 }
2906 } 2868 }
2907 2869
2908 if (cpi->common.mcomp_filter_type == SWITCHABLE) 2870 if (cpi->common.mcomp_filter_type == SWITCHABLE)
2909 *rate2 += get_switchable_rate(x); 2871 *rate2 += get_switchable_rate(x);
2910 2872
2911 if (!is_comp_pred && cpi->enable_encode_breakout) { 2873 if (!is_comp_pred && cpi->enable_encode_breakout) {
2912 if (cpi->active_map_enabled && x->active_ptr[0] == 0) 2874 if (cpi->active_map_enabled && x->active_ptr[0] == 0)
2913 x->skip = 1; 2875 x->skip = 1;
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
2968 x->plane[2].src.stride, 2930 x->plane[2].src.stride,
2969 xd->plane[2].dst.buf, 2931 xd->plane[2].dst.buf,
2970 xd->plane[2].dst.stride, &sse_v); 2932 xd->plane[2].dst.stride, &sse_v);
2971 2933
2972 // V skipping condition checking 2934 // V skipping condition checking
2973 if ((sse_v * 4 < thresh_ac || sse_v == 0) && 2935 if ((sse_v * 4 < thresh_ac || sse_v == 0) &&
2974 (sse_v - var_v < thresh_dc || sse_v == var_v)) { 2936 (sse_v - var_v < thresh_dc || sse_v == var_v)) {
2975 x->skip = 1; 2937 x->skip = 1;
2976 2938
2977 // The cost of skip bit needs to be added. 2939 // The cost of skip bit needs to be added.
2978 *rate2 += vp9_cost_bit(vp9_get_pred_prob_mbskip(cm, xd), 1); 2940 *rate2 += vp9_cost_bit(vp9_get_skip_prob(cm, xd), 1);
2979 2941
2980 // Scaling factor for SSE from spatial domain to frequency domain 2942 // Scaling factor for SSE from spatial domain to frequency domain
2981 // is 16. Adjust distortion accordingly. 2943 // is 16. Adjust distortion accordingly.
2982 *distortion_uv = (sse_u + sse_v) << 4; 2944 *distortion_uv = (sse_u + sse_v) << 4;
2983 *distortion = (sse << 4) + *distortion_uv; 2945 *distortion = (sse << 4) + *distortion_uv;
2984 2946
2985 *disable_skip = 1; 2947 *disable_skip = 1;
2986 this_rd = RDCOST(x->rdmult, x->rddiv, *rate2, *distortion); 2948 this_rd = RDCOST(x->rdmult, x->rddiv, *rate2, *distortion);
2987 } 2949 }
2988 } 2950 }
2989 } 2951 }
2990 } 2952 }
2991 } 2953 }
2992 } 2954 }
2993 2955
2994 if (!x->skip) { 2956 if (!x->skip) {
2995 int skippable_y, skippable_uv; 2957 int skippable_y, skippable_uv;
2996 int64_t sseuv = INT64_MAX; 2958 int64_t sseuv = INT64_MAX;
2997 int64_t rdcosty = INT64_MAX; 2959 int64_t rdcosty = INT64_MAX;
2998 2960
2999 // Y cost and distortion 2961 // Y cost and distortion
3000 super_block_yrd(cpi, x, rate_y, distortion_y, &skippable_y, psse, 2962 super_block_yrd(cpi, x, rate_y, distortion_y, &skippable_y, psse,
3001 bsize, txfm_cache, ref_best_rd); 2963 bsize, txfm_cache, ref_best_rd);
3002 2964
3003 if (*rate_y == INT_MAX) { 2965 if (*rate_y == INT_MAX) {
3004 *rate2 = INT_MAX; 2966 *rate2 = INT_MAX;
3005 *distortion = INT64_MAX; 2967 *distortion = INT64_MAX;
3006 for (i = 0; i < MAX_MB_PLANE; i++) { 2968 restore_dst_buf(xd, orig_dst, orig_dst_stride);
3007 xd->plane[i].dst.buf = orig_dst[i];
3008 xd->plane[i].dst.stride = orig_dst_stride[i];
3009 }
3010 return INT64_MAX; 2969 return INT64_MAX;
3011 } 2970 }
3012 2971
3013 *rate2 += *rate_y; 2972 *rate2 += *rate_y;
3014 *distortion += *distortion_y; 2973 *distortion += *distortion_y;
3015 2974
3016 rdcosty = RDCOST(x->rdmult, x->rddiv, *rate2, *distortion); 2975 rdcosty = RDCOST(x->rdmult, x->rddiv, *rate2, *distortion);
3017 rdcosty = MIN(rdcosty, RDCOST(x->rdmult, x->rddiv, 0, *psse)); 2976 rdcosty = MIN(rdcosty, RDCOST(x->rdmult, x->rddiv, 0, *psse));
3018 2977
3019 super_block_uvrd(cpi, x, rate_uv, distortion_uv, &skippable_uv, &sseuv, 2978 super_block_uvrd(cpi, x, rate_uv, distortion_uv, &skippable_uv, &sseuv,
3020 bsize, ref_best_rd - rdcosty); 2979 bsize, ref_best_rd - rdcosty);
3021 if (*rate_uv == INT_MAX) { 2980 if (*rate_uv == INT_MAX) {
3022 *rate2 = INT_MAX; 2981 *rate2 = INT_MAX;
3023 *distortion = INT64_MAX; 2982 *distortion = INT64_MAX;
3024 for (i = 0; i < MAX_MB_PLANE; i++) { 2983 restore_dst_buf(xd, orig_dst, orig_dst_stride);
3025 xd->plane[i].dst.buf = orig_dst[i];
3026 xd->plane[i].dst.stride = orig_dst_stride[i];
3027 }
3028 return INT64_MAX; 2984 return INT64_MAX;
3029 } 2985 }
3030 2986
3031 *psse += sseuv; 2987 *psse += sseuv;
3032 *rate2 += *rate_uv; 2988 *rate2 += *rate_uv;
3033 *distortion += *distortion_uv; 2989 *distortion += *distortion_uv;
3034 *skippable = skippable_y && skippable_uv; 2990 *skippable = skippable_y && skippable_uv;
3035 } 2991 }
3036 2992
3037 for (i = 0; i < MAX_MB_PLANE; i++) { 2993 restore_dst_buf(xd, orig_dst, orig_dst_stride);
3038 xd->plane[i].dst.buf = orig_dst[i]; 2994 return this_rd; // if 0, this will be re-calculated by caller
3039 xd->plane[i].dst.stride = orig_dst_stride[i]; 2995 }
2996
2997 static void swap_block_ptr(MACROBLOCK *x, PICK_MODE_CONTEXT *ctx,
2998 int max_plane) {
2999 struct macroblock_plane *const p = x->plane;
3000 struct macroblockd_plane *const pd = x->e_mbd.plane;
3001 int i;
3002
3003 for (i = 0; i < max_plane; ++i) {
3004 p[i].coeff = ctx->coeff_pbuf[i][1];
3005 p[i].qcoeff = ctx->qcoeff_pbuf[i][1];
3006 pd[i].dqcoeff = ctx->dqcoeff_pbuf[i][1];
3007 p[i].eobs = ctx->eobs_pbuf[i][1];
3008
3009 ctx->coeff_pbuf[i][1] = ctx->coeff_pbuf[i][0];
3010 ctx->qcoeff_pbuf[i][1] = ctx->qcoeff_pbuf[i][0];
3011 ctx->dqcoeff_pbuf[i][1] = ctx->dqcoeff_pbuf[i][0];
3012 ctx->eobs_pbuf[i][1] = ctx->eobs_pbuf[i][0];
3013
3014 ctx->coeff_pbuf[i][0] = p[i].coeff;
3015 ctx->qcoeff_pbuf[i][0] = p[i].qcoeff;
3016 ctx->dqcoeff_pbuf[i][0] = pd[i].dqcoeff;
3017 ctx->eobs_pbuf[i][0] = p[i].eobs;
3040 } 3018 }
3041
3042 return this_rd; // if 0, this will be re-calculated by caller
3043 } 3019 }
3044 3020
3045 void vp9_rd_pick_intra_mode_sb(VP9_COMP *cpi, MACROBLOCK *x, 3021 void vp9_rd_pick_intra_mode_sb(VP9_COMP *cpi, MACROBLOCK *x,
3046 int *returnrate, int64_t *returndist, 3022 int *returnrate, int64_t *returndist,
3047 BLOCK_SIZE bsize, 3023 BLOCK_SIZE bsize,
3048 PICK_MODE_CONTEXT *ctx, int64_t best_rd) { 3024 PICK_MODE_CONTEXT *ctx, int64_t best_rd) {
3049 VP9_COMMON *const cm = &cpi->common; 3025 VP9_COMMON *const cm = &cpi->common;
3050 MACROBLOCKD *const xd = &x->e_mbd; 3026 MACROBLOCKD *const xd = &x->e_mbd;
3051 int rate_y = 0, rate_uv = 0, rate_y_tokenonly = 0, rate_uv_tokenonly = 0; 3027 int rate_y = 0, rate_uv = 0, rate_y_tokenonly = 0, rate_uv_tokenonly = 0;
3052 int y_skip = 0, uv_skip = 0; 3028 int y_skip = 0, uv_skip = 0;
3053 int64_t dist_y = 0, dist_uv = 0, tx_cache[TX_MODES] = { 0 }; 3029 int64_t dist_y = 0, dist_uv = 0, tx_cache[TX_MODES] = { 0 };
3030 TX_SIZE max_uv_tx_size;
3054 x->skip_encode = 0; 3031 x->skip_encode = 0;
3055 ctx->skip = 0; 3032 ctx->skip = 0;
3056 xd->mi_8x8[0]->mbmi.ref_frame[0] = INTRA_FRAME; 3033 xd->mi_8x8[0]->mbmi.ref_frame[0] = INTRA_FRAME;
3034
3057 if (bsize >= BLOCK_8X8) { 3035 if (bsize >= BLOCK_8X8) {
3058 if (rd_pick_intra_sby_mode(cpi, x, &rate_y, &rate_y_tokenonly, 3036 if (rd_pick_intra_sby_mode(cpi, x, &rate_y, &rate_y_tokenonly,
3059 &dist_y, &y_skip, bsize, tx_cache, 3037 &dist_y, &y_skip, bsize, tx_cache,
3060 best_rd) >= best_rd) { 3038 best_rd) >= best_rd) {
3061 *returnrate = INT_MAX; 3039 *returnrate = INT_MAX;
3062 return; 3040 return;
3063 } 3041 }
3064 rd_pick_intra_sbuv_mode(cpi, x, &rate_uv, &rate_uv_tokenonly, 3042 max_uv_tx_size = get_uv_tx_size_impl(xd->mi_8x8[0]->mbmi.tx_size, bsize);
3065 &dist_uv, &uv_skip, bsize); 3043 rd_pick_intra_sbuv_mode(cpi, x, ctx, &rate_uv, &rate_uv_tokenonly,
3044 &dist_uv, &uv_skip, bsize, max_uv_tx_size);
3066 } else { 3045 } else {
3067 y_skip = 0; 3046 y_skip = 0;
3068 if (rd_pick_intra_sub_8x8_y_mode(cpi, x, &rate_y, &rate_y_tokenonly, 3047 if (rd_pick_intra_sub_8x8_y_mode(cpi, x, &rate_y, &rate_y_tokenonly,
3069 &dist_y, best_rd) >= best_rd) { 3048 &dist_y, best_rd) >= best_rd) {
3070 *returnrate = INT_MAX; 3049 *returnrate = INT_MAX;
3071 return; 3050 return;
3072 } 3051 }
3073 rd_pick_intra_sbuv_mode(cpi, x, &rate_uv, &rate_uv_tokenonly, 3052 max_uv_tx_size = get_uv_tx_size_impl(xd->mi_8x8[0]->mbmi.tx_size, bsize);
3074 &dist_uv, &uv_skip, BLOCK_8X8); 3053 rd_pick_intra_sbuv_mode(cpi, x, ctx, &rate_uv, &rate_uv_tokenonly,
3054 &dist_uv, &uv_skip, BLOCK_8X8, max_uv_tx_size);
3075 } 3055 }
3076 3056
3077 if (y_skip && uv_skip) { 3057 if (y_skip && uv_skip) {
3078 *returnrate = rate_y + rate_uv - rate_y_tokenonly - rate_uv_tokenonly + 3058 *returnrate = rate_y + rate_uv - rate_y_tokenonly - rate_uv_tokenonly +
3079 vp9_cost_bit(vp9_get_pred_prob_mbskip(cm, xd), 1); 3059 vp9_cost_bit(vp9_get_skip_prob(cm, xd), 1);
3080 *returndist = dist_y + dist_uv; 3060 *returndist = dist_y + dist_uv;
3081 vp9_zero(ctx->tx_rd_diff); 3061 vp9_zero(ctx->tx_rd_diff);
3082 } else { 3062 } else {
3083 int i; 3063 int i;
3084 *returnrate = rate_y + rate_uv + 3064 *returnrate = rate_y + rate_uv + vp9_cost_bit(vp9_get_skip_prob(cm, xd), 0);
3085 vp9_cost_bit(vp9_get_pred_prob_mbskip(cm, xd), 0);
3086 *returndist = dist_y + dist_uv; 3065 *returndist = dist_y + dist_uv;
3087 if (cpi->sf.tx_size_search_method == USE_FULL_RD) 3066 if (cpi->sf.tx_size_search_method == USE_FULL_RD)
3088 for (i = 0; i < TX_MODES; i++) { 3067 for (i = 0; i < TX_MODES; i++) {
3089 if (tx_cache[i] < INT64_MAX && tx_cache[cm->tx_mode] < INT64_MAX) 3068 if (tx_cache[i] < INT64_MAX && tx_cache[cm->tx_mode] < INT64_MAX)
3090 ctx->tx_rd_diff[i] = tx_cache[i] - tx_cache[cm->tx_mode]; 3069 ctx->tx_rd_diff[i] = tx_cache[i] - tx_cache[cm->tx_mode];
3091 else 3070 else
3092 ctx->tx_rd_diff[i] = 0; 3071 ctx->tx_rd_diff[i] = 0;
3093 } 3072 }
3094 } 3073 }
3095 3074
(...skipping 22 matching lines...) Expand all
3118 int_mv single_newmv[MAX_REF_FRAMES] = { { 0 } }; 3097 int_mv single_newmv[MAX_REF_FRAMES] = { { 0 } };
3119 static const int flag_list[4] = { 0, VP9_LAST_FLAG, VP9_GOLD_FLAG, 3098 static const int flag_list[4] = { 0, VP9_LAST_FLAG, VP9_GOLD_FLAG,
3120 VP9_ALT_FLAG }; 3099 VP9_ALT_FLAG };
3121 int idx_list[4] = {0, 3100 int idx_list[4] = {0,
3122 cpi->lst_fb_idx, 3101 cpi->lst_fb_idx,
3123 cpi->gld_fb_idx, 3102 cpi->gld_fb_idx,
3124 cpi->alt_fb_idx}; 3103 cpi->alt_fb_idx};
3125 int64_t best_rd = best_rd_so_far; 3104 int64_t best_rd = best_rd_so_far;
3126 int64_t best_tx_rd[TX_MODES]; 3105 int64_t best_tx_rd[TX_MODES];
3127 int64_t best_tx_diff[TX_MODES]; 3106 int64_t best_tx_diff[TX_MODES];
3128 int64_t best_pred_diff[NB_PREDICTION_TYPES]; 3107 int64_t best_pred_diff[REFERENCE_MODES];
3129 int64_t best_pred_rd[NB_PREDICTION_TYPES]; 3108 int64_t best_pred_rd[REFERENCE_MODES];
3130 int64_t best_filter_rd[SWITCHABLE_FILTER_CONTEXTS]; 3109 int64_t best_filter_rd[SWITCHABLE_FILTER_CONTEXTS];
3131 int64_t best_filter_diff[SWITCHABLE_FILTER_CONTEXTS]; 3110 int64_t best_filter_diff[SWITCHABLE_FILTER_CONTEXTS];
3132 MB_MODE_INFO best_mbmode = { 0 }; 3111 MB_MODE_INFO best_mbmode = { 0 };
3133 int j; 3112 int j;
3134 int mode_index, best_mode_index = 0; 3113 int mode_index, best_mode_index = 0;
3135 unsigned int ref_costs_single[MAX_REF_FRAMES], ref_costs_comp[MAX_REF_FRAMES]; 3114 unsigned int ref_costs_single[MAX_REF_FRAMES], ref_costs_comp[MAX_REF_FRAMES];
3136 vp9_prob comp_mode_p; 3115 vp9_prob comp_mode_p;
3137 int64_t best_intra_rd = INT64_MAX; 3116 int64_t best_intra_rd = INT64_MAX;
3138 int64_t best_inter_rd = INT64_MAX; 3117 int64_t best_inter_rd = INT64_MAX;
3139 MB_PREDICTION_MODE best_intra_mode = DC_PRED; 3118 MB_PREDICTION_MODE best_intra_mode = DC_PRED;
3140 MV_REFERENCE_FRAME best_inter_ref_frame = LAST_FRAME; 3119 MV_REFERENCE_FRAME best_inter_ref_frame = LAST_FRAME;
3141 INTERPOLATION_TYPE tmp_best_filter = SWITCHABLE; 3120 INTERPOLATION_TYPE tmp_best_filter = SWITCHABLE;
3142 int rate_uv_intra[TX_SIZES], rate_uv_tokenonly[TX_SIZES]; 3121 int rate_uv_intra[TX_SIZES], rate_uv_tokenonly[TX_SIZES];
3143 int64_t dist_uv[TX_SIZES]; 3122 int64_t dist_uv[TX_SIZES];
3144 int skip_uv[TX_SIZES]; 3123 int skip_uv[TX_SIZES];
3145 MB_PREDICTION_MODE mode_uv[TX_SIZES]; 3124 MB_PREDICTION_MODE mode_uv[TX_SIZES];
3146 struct scale_factors scale_factor[4]; 3125 struct scale_factors scale_factor[4];
3147 unsigned int ref_frame_mask = 0; 3126 unsigned int ref_frame_mask = 0;
3148 unsigned int mode_mask = 0; 3127 unsigned int mode_mask = 0;
3149 int64_t mode_distortions[MB_MODE_COUNT] = {-1}; 3128 int64_t mode_distortions[MB_MODE_COUNT] = {-1};
3150 int64_t frame_distortions[MAX_REF_FRAMES] = {-1}; 3129 int64_t frame_distortions[MAX_REF_FRAMES] = {-1};
3151 int intra_cost_penalty = 20 * vp9_dc_quant(cm->base_qindex, cm->y_dc_delta_q); 3130 int intra_cost_penalty = 20 * vp9_dc_quant(cm->base_qindex, cm->y_dc_delta_q);
3152 const int bws = num_8x8_blocks_wide_lookup[bsize] / 2; 3131 const int bws = num_8x8_blocks_wide_lookup[bsize] / 2;
3153 const int bhs = num_8x8_blocks_high_lookup[bsize] / 2; 3132 const int bhs = num_8x8_blocks_high_lookup[bsize] / 2;
3154 int best_skip2 = 0; 3133 int best_skip2 = 0;
3155 3134
3156 x->skip_encode = cpi->sf.skip_encode_frame && xd->q_index < QIDX_SKIP_THRESH; 3135 x->skip_encode = cpi->sf.skip_encode_frame && x->q_index < QIDX_SKIP_THRESH;
3157 3136
3158 // Everywhere the flag is set the error is much higher than its neighbors. 3137 // Everywhere the flag is set the error is much higher than its neighbors.
3159 ctx->frames_with_high_error = 0; 3138 ctx->frames_with_high_error = 0;
3160 ctx->modes_with_high_error = 0; 3139 ctx->modes_with_high_error = 0;
3161 3140
3162 estimate_ref_frame_costs(cpi, segment_id, ref_costs_single, ref_costs_comp, 3141 estimate_ref_frame_costs(cpi, segment_id, ref_costs_single, ref_costs_comp,
3163 &comp_mode_p); 3142 &comp_mode_p);
3164 3143
3165 for (i = 0; i < NB_PREDICTION_TYPES; ++i) 3144 for (i = 0; i < REFERENCE_MODES; ++i)
3166 best_pred_rd[i] = INT64_MAX; 3145 best_pred_rd[i] = INT64_MAX;
3167 for (i = 0; i < TX_MODES; i++) 3146 for (i = 0; i < TX_MODES; i++)
3168 best_tx_rd[i] = INT64_MAX; 3147 best_tx_rd[i] = INT64_MAX;
3169 for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; i++) 3148 for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; i++)
3170 best_filter_rd[i] = INT64_MAX; 3149 best_filter_rd[i] = INT64_MAX;
3171 for (i = 0; i < TX_SIZES; i++) 3150 for (i = 0; i < TX_SIZES; i++)
3172 rate_uv_intra[i] = INT_MAX; 3151 rate_uv_intra[i] = INT_MAX;
3173 3152
3174 *returnrate = INT_MAX; 3153 *returnrate = INT_MAX;
3175 3154
3176 // Create a mask set to 1 for each reference frame used by a smaller 3155 // Create a mask set to 1 for each reference frame used by a smaller
3177 // resolution. 3156 // resolution.
3178 if (cpi->sf.use_avoid_tested_higherror) { 3157 if (cpi->sf.use_avoid_tested_higherror) {
3179 switch (block_size) { 3158 switch (block_size) {
3180 case BLOCK_64X64: 3159 case BLOCK_64X64:
3181 for (i = 0; i < 4; i++) { 3160 for (i = 0; i < 4; i++) {
3182 for (j = 0; j < 4; j++) { 3161 for (j = 0; j < 4; j++) {
3183 ref_frame_mask |= x->mb_context[i][j].frames_with_high_error; 3162 ref_frame_mask |= x->mb_context[i][j].frames_with_high_error;
3184 mode_mask |= x->mb_context[i][j].modes_with_high_error; 3163 mode_mask |= x->mb_context[i][j].modes_with_high_error;
3185 } 3164 }
3186 } 3165 }
3187 for (i = 0; i < 4; i++) { 3166 for (i = 0; i < 4; i++) {
3188 ref_frame_mask |= x->sb32_context[i].frames_with_high_error; 3167 ref_frame_mask |= x->sb32_context[i].frames_with_high_error;
3189 mode_mask |= x->sb32_context[i].modes_with_high_error; 3168 mode_mask |= x->sb32_context[i].modes_with_high_error;
3190 } 3169 }
3191 break; 3170 break;
3192 case BLOCK_32X32: 3171 case BLOCK_32X32:
3193 for (i = 0; i < 4; i++) { 3172 for (i = 0; i < 4; i++) {
3194 ref_frame_mask |= 3173 ref_frame_mask |=
3195 x->mb_context[xd->sb_index][i].frames_with_high_error; 3174 x->mb_context[x->sb_index][i].frames_with_high_error;
3196 mode_mask |= x->mb_context[xd->sb_index][i].modes_with_high_error; 3175 mode_mask |= x->mb_context[x->sb_index][i].modes_with_high_error;
3197 } 3176 }
3198 break; 3177 break;
3199 default: 3178 default:
3200 // Until we handle all block sizes set it to present; 3179 // Until we handle all block sizes set it to present;
3201 ref_frame_mask = 0; 3180 ref_frame_mask = 0;
3202 mode_mask = 0; 3181 mode_mask = 0;
3203 break; 3182 break;
3204 } 3183 }
3205 ref_frame_mask = ~ref_frame_mask; 3184 ref_frame_mask = ~ref_frame_mask;
3206 mode_mask = ~mode_mask; 3185 mode_mask = ~mode_mask;
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
3251 cpi->mode_skip_mask = LAST_FRAME_MODE_MASK; 3230 cpi->mode_skip_mask = LAST_FRAME_MODE_MASK;
3252 break; 3231 break;
3253 case GOLDEN_FRAME: 3232 case GOLDEN_FRAME:
3254 cpi->mode_skip_mask = GOLDEN_FRAME_MODE_MASK; 3233 cpi->mode_skip_mask = GOLDEN_FRAME_MODE_MASK;
3255 break; 3234 break;
3256 case ALTREF_FRAME: 3235 case ALTREF_FRAME:
3257 cpi->mode_skip_mask = ALT_REF_MODE_MASK; 3236 cpi->mode_skip_mask = ALT_REF_MODE_MASK;
3258 break; 3237 break;
3259 case NONE: 3238 case NONE:
3260 case MAX_REF_FRAMES: 3239 case MAX_REF_FRAMES:
3261 assert(!"Invalid Reference frame"); 3240 assert(0 && "Invalid Reference frame");
3262 } 3241 }
3263 } 3242 }
3264 if (cpi->mode_skip_mask & ((int64_t)1 << mode_index)) 3243 if (cpi->mode_skip_mask & ((int64_t)1 << mode_index))
3265 continue; 3244 continue;
3266 } 3245 }
3267 3246
3268 // Skip if the current reference frame has been masked off 3247 // Skip if the current reference frame has been masked off
3269 if (cpi->sf.reference_masking && !cpi->set_ref_frame_mask && 3248 if (cpi->sf.reference_masking && !cpi->set_ref_frame_mask &&
3270 (cpi->ref_frame_mask & (1 << ref_frame))) 3249 (cpi->ref_frame_mask & (1 << ref_frame)))
3271 continue; 3250 continue;
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
3328 mbmi->uv_mode = DC_PRED; 3307 mbmi->uv_mode = DC_PRED;
3329 3308
3330 // Evaluate all sub-pel filters irrespective of whether we can use 3309 // Evaluate all sub-pel filters irrespective of whether we can use
3331 // them for this frame. 3310 // them for this frame.
3332 mbmi->interp_filter = cm->mcomp_filter_type; 3311 mbmi->interp_filter = cm->mcomp_filter_type;
3333 vp9_setup_interp_filters(xd, mbmi->interp_filter, cm); 3312 vp9_setup_interp_filters(xd, mbmi->interp_filter, cm);
3334 3313
3335 if (comp_pred) { 3314 if (comp_pred) {
3336 if (!(cpi->ref_frame_flags & flag_list[second_ref_frame])) 3315 if (!(cpi->ref_frame_flags & flag_list[second_ref_frame]))
3337 continue; 3316 continue;
3317
3338 set_scale_factors(xd, ref_frame, second_ref_frame, scale_factor); 3318 set_scale_factors(xd, ref_frame, second_ref_frame, scale_factor);
3339 3319 mode_excluded = mode_excluded ? mode_excluded
3340 mode_excluded = mode_excluded 3320 : cm->reference_mode == SINGLE_REFERENCE;
3341 ? mode_excluded
3342 : cm->comp_pred_mode == SINGLE_PREDICTION_ONLY;
3343 } else { 3321 } else {
3344 if (ref_frame != INTRA_FRAME && second_ref_frame != INTRA_FRAME) { 3322 if (ref_frame != INTRA_FRAME && second_ref_frame != INTRA_FRAME)
3345 mode_excluded = 3323 mode_excluded = mode_excluded ?
3346 mode_excluded ? 3324 mode_excluded : cm->reference_mode == COMPOUND_REFERENCE;
3347 mode_excluded : cm->comp_pred_mode == COMP_PREDICTION_ONLY;
3348 }
3349 } 3325 }
3350 3326
3351 // Select prediction reference frames. 3327 // Select prediction reference frames.
3352 for (i = 0; i < MAX_MB_PLANE; i++) { 3328 for (i = 0; i < MAX_MB_PLANE; i++) {
3353 xd->plane[i].pre[0] = yv12_mb[ref_frame][i]; 3329 xd->plane[i].pre[0] = yv12_mb[ref_frame][i];
3354 if (comp_pred) 3330 if (comp_pred)
3355 xd->plane[i].pre[1] = yv12_mb[second_ref_frame][i]; 3331 xd->plane[i].pre[1] = yv12_mb[second_ref_frame][i];
3356 } 3332 }
3357 3333
3358 // If the segment reference frame feature is enabled.... 3334 // If the segment reference frame feature is enabled....
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
3427 if (conditional_skipintra(mbmi->mode, best_intra_mode)) 3403 if (conditional_skipintra(mbmi->mode, best_intra_mode))
3428 continue; 3404 continue;
3429 } 3405 }
3430 3406
3431 super_block_yrd(cpi, x, &rate_y, &distortion_y, &skippable, NULL, 3407 super_block_yrd(cpi, x, &rate_y, &distortion_y, &skippable, NULL,
3432 bsize, tx_cache, best_rd); 3408 bsize, tx_cache, best_rd);
3433 3409
3434 if (rate_y == INT_MAX) 3410 if (rate_y == INT_MAX)
3435 continue; 3411 continue;
3436 3412
3437 uv_tx = MIN(mbmi->tx_size, max_uv_txsize_lookup[bsize]); 3413 uv_tx = get_uv_tx_size_impl(mbmi->tx_size, bsize);
3438 if (rate_uv_intra[uv_tx] == INT_MAX) { 3414 if (rate_uv_intra[uv_tx] == INT_MAX) {
3439 choose_intra_uv_mode(cpi, bsize, &rate_uv_intra[uv_tx], 3415 choose_intra_uv_mode(cpi, ctx, bsize, uv_tx,
3440 &rate_uv_tokenonly[uv_tx], 3416 &rate_uv_intra[uv_tx], &rate_uv_tokenonly[uv_tx],
3441 &dist_uv[uv_tx], &skip_uv[uv_tx], 3417 &dist_uv[uv_tx], &skip_uv[uv_tx], &mode_uv[uv_tx]);
3442 &mode_uv[uv_tx]);
3443 } 3418 }
3444 3419
3445 rate_uv = rate_uv_tokenonly[uv_tx]; 3420 rate_uv = rate_uv_tokenonly[uv_tx];
3446 distortion_uv = dist_uv[uv_tx]; 3421 distortion_uv = dist_uv[uv_tx];
3447 skippable = skippable && skip_uv[uv_tx]; 3422 skippable = skippable && skip_uv[uv_tx];
3448 mbmi->uv_mode = mode_uv[uv_tx]; 3423 mbmi->uv_mode = mode_uv[uv_tx];
3449 3424
3450 rate2 = rate_y + x->mbmode_cost[mbmi->mode] + rate_uv_intra[uv_tx]; 3425 rate2 = rate_y + x->mbmode_cost[mbmi->mode] + rate_uv_intra[uv_tx];
3451 if (this_mode != DC_PRED && this_mode != TM_PRED) 3426 if (this_mode != DC_PRED && this_mode != TM_PRED)
3452 rate2 += intra_cost_penalty; 3427 rate2 += intra_cost_penalty;
3453 distortion2 = distortion_y + distortion_uv; 3428 distortion2 = distortion_y + distortion_uv;
3454 } else { 3429 } else {
3455 mbmi->mode = this_mode; 3430 mbmi->mode = this_mode;
3456 compmode_cost = vp9_cost_bit(comp_mode_p, second_ref_frame > INTRA_FRAME); 3431 compmode_cost = vp9_cost_bit(comp_mode_p, second_ref_frame > INTRA_FRAME);
3457 this_rd = handle_inter_mode(cpi, x, tile, bsize, 3432 this_rd = handle_inter_mode(cpi, x, tile, bsize,
3458 tx_cache, 3433 tx_cache,
3459 &rate2, &distortion2, &skippable, 3434 &rate2, &distortion2, &skippable,
3460 &rate_y, &distortion_y, 3435 &rate_y, &distortion_y,
3461 &rate_uv, &distortion_uv, 3436 &rate_uv, &distortion_uv,
3462 &mode_excluded, &disable_skip, 3437 &mode_excluded, &disable_skip,
3463 &tmp_best_filter, frame_mv, 3438 &tmp_best_filter, frame_mv,
3464 mi_row, mi_col, 3439 mi_row, mi_col,
3465 single_newmv, &total_sse, best_rd); 3440 single_newmv, &total_sse, best_rd);
3466 if (this_rd == INT64_MAX) 3441 if (this_rd == INT64_MAX)
3467 continue; 3442 continue;
3468 } 3443 }
3469 3444
3470 if (cm->comp_pred_mode == HYBRID_PREDICTION) { 3445 if (cm->reference_mode == REFERENCE_MODE_SELECT)
3471 rate2 += compmode_cost; 3446 rate2 += compmode_cost;
3472 }
3473 3447
3474 // Estimate the reference frame signaling cost and add it 3448 // Estimate the reference frame signaling cost and add it
3475 // to the rolling cost variable. 3449 // to the rolling cost variable.
3476 if (second_ref_frame > INTRA_FRAME) { 3450 if (second_ref_frame > INTRA_FRAME) {
3477 rate2 += ref_costs_comp[ref_frame]; 3451 rate2 += ref_costs_comp[ref_frame];
3478 } else { 3452 } else {
3479 rate2 += ref_costs_single[ref_frame]; 3453 rate2 += ref_costs_single[ref_frame];
3480 } 3454 }
3481 3455
3482 if (!disable_skip) { 3456 if (!disable_skip) {
3483 // Test for the condition where skip block will be activated 3457 // Test for the condition where skip block will be activated
3484 // because there are no non zero coefficients and make any 3458 // because there are no non zero coefficients and make any
3485 // necessary adjustment for rate. Ignore if skip is coded at 3459 // necessary adjustment for rate. Ignore if skip is coded at
3486 // segment level as the cost wont have been added in. 3460 // segment level as the cost wont have been added in.
3487 // Is Mb level skip allowed (i.e. not coded at segment level). 3461 // Is Mb level skip allowed (i.e. not coded at segment level).
3488 const int mb_skip_allowed = !vp9_segfeature_active(seg, segment_id, 3462 const int mb_skip_allowed = !vp9_segfeature_active(seg, segment_id,
3489 SEG_LVL_SKIP); 3463 SEG_LVL_SKIP);
3490 3464
3491 if (skippable) { 3465 if (skippable) {
3492 // Back out the coefficient coding costs 3466 // Back out the coefficient coding costs
3493 rate2 -= (rate_y + rate_uv); 3467 rate2 -= (rate_y + rate_uv);
3494 // for best yrd calculation 3468 // for best yrd calculation
3495 rate_uv = 0; 3469 rate_uv = 0;
3496 3470
3497 if (mb_skip_allowed) { 3471 if (mb_skip_allowed) {
3498 int prob_skip_cost; 3472 int prob_skip_cost;
3499 3473
3500 // Cost the skip mb case 3474 // Cost the skip mb case
3501 vp9_prob skip_prob = 3475 vp9_prob skip_prob = vp9_get_skip_prob(cm, xd);
3502 vp9_get_pred_prob_mbskip(cm, xd);
3503
3504 if (skip_prob) { 3476 if (skip_prob) {
3505 prob_skip_cost = vp9_cost_bit(skip_prob, 1); 3477 prob_skip_cost = vp9_cost_bit(skip_prob, 1);
3506 rate2 += prob_skip_cost; 3478 rate2 += prob_skip_cost;
3507 } 3479 }
3508 } 3480 }
3509 } else if (mb_skip_allowed && ref_frame != INTRA_FRAME && !xd->lossless) { 3481 } else if (mb_skip_allowed && ref_frame != INTRA_FRAME && !xd->lossless) {
3510 if (RDCOST(x->rdmult, x->rddiv, rate_y + rate_uv, distortion2) < 3482 if (RDCOST(x->rdmult, x->rddiv, rate_y + rate_uv, distortion2) <
3511 RDCOST(x->rdmult, x->rddiv, 0, total_sse)) { 3483 RDCOST(x->rdmult, x->rddiv, 0, total_sse)) {
3512 // Add in the cost of the no skip flag. 3484 // Add in the cost of the no skip flag.
3513 int prob_skip_cost = vp9_cost_bit(vp9_get_pred_prob_mbskip(cm, xd), 3485 rate2 += vp9_cost_bit(vp9_get_skip_prob(cm, xd), 0);
3514 0);
3515 rate2 += prob_skip_cost;
3516 } else { 3486 } else {
3517 // FIXME(rbultje) make this work for splitmv also 3487 // FIXME(rbultje) make this work for splitmv also
3518 int prob_skip_cost = vp9_cost_bit(vp9_get_pred_prob_mbskip(cm, xd), 3488 rate2 += vp9_cost_bit(vp9_get_skip_prob(cm, xd), 1);
3519 1);
3520 rate2 += prob_skip_cost;
3521 distortion2 = total_sse; 3489 distortion2 = total_sse;
3522 assert(total_sse >= 0); 3490 assert(total_sse >= 0);
3523 rate2 -= (rate_y + rate_uv); 3491 rate2 -= (rate_y + rate_uv);
3524 rate_y = 0; 3492 rate_y = 0;
3525 rate_uv = 0; 3493 rate_uv = 0;
3526 this_skip2 = 1; 3494 this_skip2 = 1;
3527 } 3495 }
3528 } else if (mb_skip_allowed) { 3496 } else if (mb_skip_allowed) {
3529 // Add in the cost of the no skip flag. 3497 // Add in the cost of the no skip flag.
3530 int prob_skip_cost = vp9_cost_bit(vp9_get_pred_prob_mbskip(cm, xd), 3498 rate2 += vp9_cost_bit(vp9_get_skip_prob(cm, xd), 0);
3531 0);
3532 rate2 += prob_skip_cost;
3533 } 3499 }
3534 3500
3535 // Calculate the final RD estimate for this mode. 3501 // Calculate the final RD estimate for this mode.
3536 this_rd = RDCOST(x->rdmult, x->rddiv, rate2, distortion2); 3502 this_rd = RDCOST(x->rdmult, x->rddiv, rate2, distortion2);
3537 } 3503 }
3538 3504
3539 // Keep record of best intra rd 3505 // Keep record of best intra rd
3540 if (xd->mi_8x8[0]->mbmi.ref_frame[0] == INTRA_FRAME && 3506 if (!is_inter_block(&xd->mi_8x8[0]->mbmi) &&
3541 is_intra_mode(xd->mi_8x8[0]->mbmi.mode) &&
3542 this_rd < best_intra_rd) { 3507 this_rd < best_intra_rd) {
3543 best_intra_rd = this_rd; 3508 best_intra_rd = this_rd;
3544 best_intra_mode = xd->mi_8x8[0]->mbmi.mode; 3509 best_intra_mode = xd->mi_8x8[0]->mbmi.mode;
3545 } 3510 }
3511
3546 // Keep record of best inter rd with single reference 3512 // Keep record of best inter rd with single reference
3547 if (xd->mi_8x8[0]->mbmi.ref_frame[0] > INTRA_FRAME && 3513 if (is_inter_block(&xd->mi_8x8[0]->mbmi) &&
3548 xd->mi_8x8[0]->mbmi.ref_frame[1] == NONE && 3514 !has_second_ref(&xd->mi_8x8[0]->mbmi) &&
3549 !mode_excluded && 3515 !mode_excluded && this_rd < best_inter_rd) {
3550 this_rd < best_inter_rd) {
3551 best_inter_rd = this_rd; 3516 best_inter_rd = this_rd;
3552 best_inter_ref_frame = ref_frame; 3517 best_inter_ref_frame = ref_frame;
3553 } 3518 }
3554 3519
3555 if (!disable_skip && ref_frame == INTRA_FRAME) { 3520 if (!disable_skip && ref_frame == INTRA_FRAME) {
3556 for (i = 0; i < NB_PREDICTION_TYPES; ++i) 3521 for (i = 0; i < REFERENCE_MODES; ++i)
3557 best_pred_rd[i] = MIN(best_pred_rd[i], this_rd); 3522 best_pred_rd[i] = MIN(best_pred_rd[i], this_rd);
3558 for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; i++) 3523 for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; i++)
3559 best_filter_rd[i] = MIN(best_filter_rd[i], this_rd); 3524 best_filter_rd[i] = MIN(best_filter_rd[i], this_rd);
3560 } 3525 }
3561 3526
3562 // Store the respective mode distortions for later use. 3527 // Store the respective mode distortions for later use.
3563 if (mode_distortions[this_mode] == -1 3528 if (mode_distortions[this_mode] == -1
3564 || distortion2 < mode_distortions[this_mode]) { 3529 || distortion2 < mode_distortions[this_mode]) {
3565 mode_distortions[this_mode] = distortion2; 3530 mode_distortions[this_mode] = distortion2;
3566 } 3531 }
3567 if (frame_distortions[ref_frame] == -1 3532 if (frame_distortions[ref_frame] == -1
3568 || distortion2 < frame_distortions[ref_frame]) { 3533 || distortion2 < frame_distortions[ref_frame]) {
3569 frame_distortions[ref_frame] = distortion2; 3534 frame_distortions[ref_frame] = distortion2;
3570 } 3535 }
3571 3536
3572 // Did this mode help.. i.e. is it the new best mode 3537 // Did this mode help.. i.e. is it the new best mode
3573 if (this_rd < best_rd || x->skip) { 3538 if (this_rd < best_rd || x->skip) {
3539 int max_plane = MAX_MB_PLANE;
3574 if (!mode_excluded) { 3540 if (!mode_excluded) {
3575 // Note index of best mode so far 3541 // Note index of best mode so far
3576 best_mode_index = mode_index; 3542 best_mode_index = mode_index;
3577 3543
3578 if (ref_frame == INTRA_FRAME) { 3544 if (ref_frame == INTRA_FRAME) {
3579 /* required for left and above block mv */ 3545 /* required for left and above block mv */
3580 mbmi->mv[0].as_int = 0; 3546 mbmi->mv[0].as_int = 0;
3547 max_plane = 1;
3581 } 3548 }
3582 3549
3583 *returnrate = rate2; 3550 *returnrate = rate2;
3584 *returndistortion = distortion2; 3551 *returndistortion = distortion2;
3585 best_rd = this_rd; 3552 best_rd = this_rd;
3586 best_mbmode = *mbmi; 3553 best_mbmode = *mbmi;
3587 best_skip2 = this_skip2; 3554 best_skip2 = this_skip2;
3555 if (!x->select_txfm_size)
3556 swap_block_ptr(x, ctx, max_plane);
3588 vpx_memcpy(ctx->zcoeff_blk, x->zcoeff_blk[mbmi->tx_size], 3557 vpx_memcpy(ctx->zcoeff_blk, x->zcoeff_blk[mbmi->tx_size],
3589 sizeof(uint8_t) * ctx->num_4x4_blk); 3558 sizeof(uint8_t) * ctx->num_4x4_blk);
3590 3559
3591 // TODO(debargha): enhance this test with a better distortion prediction 3560 // TODO(debargha): enhance this test with a better distortion prediction
3592 // based on qp, activity mask and history 3561 // based on qp, activity mask and history
3593 if ((cpi->sf.mode_search_skip_flags & FLAG_EARLY_TERMINATE) && 3562 if ((cpi->sf.mode_search_skip_flags & FLAG_EARLY_TERMINATE) &&
3594 (mode_index > MIN_EARLY_TERM_INDEX)) { 3563 (mode_index > MIN_EARLY_TERM_INDEX)) {
3595 const int qstep = xd->plane[0].dequant[1]; 3564 const int qstep = xd->plane[0].dequant[1];
3596 // TODO(debargha): Enhance this by specializing for each mode_index 3565 // TODO(debargha): Enhance this by specializing for each mode_index
3597 int scale = 4; 3566 int scale = 4;
3598 if (x->source_variance < UINT_MAX) { 3567 if (x->source_variance < UINT_MAX) {
3599 const int var_adjust = (x->source_variance < 16); 3568 const int var_adjust = (x->source_variance < 16);
3600 scale -= var_adjust; 3569 scale -= var_adjust;
3601 } 3570 }
3602 if (ref_frame > INTRA_FRAME && 3571 if (ref_frame > INTRA_FRAME &&
3603 distortion2 * scale < qstep * qstep) { 3572 distortion2 * scale < qstep * qstep) {
3604 early_term = 1; 3573 early_term = 1;
3605 } 3574 }
3606 } 3575 }
3607 } 3576 }
3608 } 3577 }
3609 3578
3610 /* keep record of best compound/single-only prediction */ 3579 /* keep record of best compound/single-only prediction */
3611 if (!disable_skip && ref_frame != INTRA_FRAME) { 3580 if (!disable_skip && ref_frame != INTRA_FRAME) {
3612 int single_rd, hybrid_rd, single_rate, hybrid_rate; 3581 int64_t single_rd, hybrid_rd, single_rate, hybrid_rate;
3613 3582
3614 if (cm->comp_pred_mode == HYBRID_PREDICTION) { 3583 if (cm->reference_mode == REFERENCE_MODE_SELECT) {
3615 single_rate = rate2 - compmode_cost; 3584 single_rate = rate2 - compmode_cost;
3616 hybrid_rate = rate2; 3585 hybrid_rate = rate2;
3617 } else { 3586 } else {
3618 single_rate = rate2; 3587 single_rate = rate2;
3619 hybrid_rate = rate2 + compmode_cost; 3588 hybrid_rate = rate2 + compmode_cost;
3620 } 3589 }
3621 3590
3622 single_rd = RDCOST(x->rdmult, x->rddiv, single_rate, distortion2); 3591 single_rd = RDCOST(x->rdmult, x->rddiv, single_rate, distortion2);
3623 hybrid_rd = RDCOST(x->rdmult, x->rddiv, hybrid_rate, distortion2); 3592 hybrid_rd = RDCOST(x->rdmult, x->rddiv, hybrid_rate, distortion2);
3624 3593
3625 if (second_ref_frame <= INTRA_FRAME && 3594 if (second_ref_frame <= INTRA_FRAME &&
3626 single_rd < best_pred_rd[SINGLE_PREDICTION_ONLY]) { 3595 single_rd < best_pred_rd[SINGLE_REFERENCE]) {
3627 best_pred_rd[SINGLE_PREDICTION_ONLY] = single_rd; 3596 best_pred_rd[SINGLE_REFERENCE] = single_rd;
3628 } else if (second_ref_frame > INTRA_FRAME && 3597 } else if (second_ref_frame > INTRA_FRAME &&
3629 single_rd < best_pred_rd[COMP_PREDICTION_ONLY]) { 3598 single_rd < best_pred_rd[COMPOUND_REFERENCE]) {
3630 best_pred_rd[COMP_PREDICTION_ONLY] = single_rd; 3599 best_pred_rd[COMPOUND_REFERENCE] = single_rd;
3631 } 3600 }
3632 if (hybrid_rd < best_pred_rd[HYBRID_PREDICTION]) 3601 if (hybrid_rd < best_pred_rd[REFERENCE_MODE_SELECT])
3633 best_pred_rd[HYBRID_PREDICTION] = hybrid_rd; 3602 best_pred_rd[REFERENCE_MODE_SELECT] = hybrid_rd;
3634 } 3603 }
3635 3604
3636 /* keep record of best filter type */ 3605 /* keep record of best filter type */
3637 if (!mode_excluded && !disable_skip && ref_frame != INTRA_FRAME && 3606 if (!mode_excluded && !disable_skip && ref_frame != INTRA_FRAME &&
3638 cm->mcomp_filter_type != BILINEAR) { 3607 cm->mcomp_filter_type != BILINEAR) {
3639 int64_t ref = cpi->rd_filter_cache[cm->mcomp_filter_type == SWITCHABLE ? 3608 int64_t ref = cpi->rd_filter_cache[cm->mcomp_filter_type == SWITCHABLE ?
3640 SWITCHABLE_FILTERS : cm->mcomp_filter_type]; 3609 SWITCHABLE_FILTERS : cm->mcomp_filter_type];
3641 for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; i++) { 3610 for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; i++) {
3642 int64_t adj_rd; 3611 int64_t adj_rd;
3643 // In cases of poor prediction, filter_cache[] can contain really big 3612 // In cases of poor prediction, filter_cache[] can contain really big
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
3683 break; 3652 break;
3684 } 3653 }
3685 3654
3686 if (best_rd >= best_rd_so_far) 3655 if (best_rd >= best_rd_so_far)
3687 return INT64_MAX; 3656 return INT64_MAX;
3688 3657
3689 // If we used an estimate for the uv intra rd in the loop above... 3658 // If we used an estimate for the uv intra rd in the loop above...
3690 if (cpi->sf.use_uv_intra_rd_estimate) { 3659 if (cpi->sf.use_uv_intra_rd_estimate) {
3691 // Do Intra UV best rd mode selection if best mode choice above was intra. 3660 // Do Intra UV best rd mode selection if best mode choice above was intra.
3692 if (vp9_mode_order[best_mode_index].ref_frame == INTRA_FRAME) { 3661 if (vp9_mode_order[best_mode_index].ref_frame == INTRA_FRAME) {
3693 TX_SIZE uv_tx_size = get_uv_tx_size(mbmi); 3662 TX_SIZE uv_tx_size;
3694 rd_pick_intra_sbuv_mode(cpi, x, &rate_uv_intra[uv_tx_size], 3663 *mbmi = best_mbmode;
3664 uv_tx_size = get_uv_tx_size(mbmi);
3665 rd_pick_intra_sbuv_mode(cpi, x, ctx, &rate_uv_intra[uv_tx_size],
3695 &rate_uv_tokenonly[uv_tx_size], 3666 &rate_uv_tokenonly[uv_tx_size],
3696 &dist_uv[uv_tx_size], 3667 &dist_uv[uv_tx_size],
3697 &skip_uv[uv_tx_size], 3668 &skip_uv[uv_tx_size],
3698 bsize < BLOCK_8X8 ? BLOCK_8X8 : bsize); 3669 bsize < BLOCK_8X8 ? BLOCK_8X8 : bsize,
3670 uv_tx_size);
3699 } 3671 }
3700 } 3672 }
3701 3673
3702 // If we are using reference masking and the set mask flag is set then 3674 // If we are using reference masking and the set mask flag is set then
3703 // create the reference frame mask. 3675 // create the reference frame mask.
3704 if (cpi->sf.reference_masking && cpi->set_ref_frame_mask) 3676 if (cpi->sf.reference_masking && cpi->set_ref_frame_mask)
3705 cpi->ref_frame_mask = ~(1 << vp9_mode_order[best_mode_index].ref_frame); 3677 cpi->ref_frame_mask = ~(1 << vp9_mode_order[best_mode_index].ref_frame);
3706 3678
3707 // Flag all modes that have a distortion thats > 2x the best we found at 3679 // Flag all modes that have a distortion thats > 2x the best we found at
3708 // this level. 3680 // this level.
3709 for (mode_index = 0; mode_index < MB_MODE_COUNT; ++mode_index) { 3681 for (mode_index = 0; mode_index < MB_MODE_COUNT; ++mode_index) {
3710 if (mode_index == NEARESTMV || mode_index == NEARMV || mode_index == NEWMV) 3682 if (mode_index == NEARESTMV || mode_index == NEARMV || mode_index == NEWMV)
3711 continue; 3683 continue;
3712 3684
3713 if (mode_distortions[mode_index] > 2 * *returndistortion) { 3685 if (mode_distortions[mode_index] > 2 * *returndistortion) {
3714 ctx->modes_with_high_error |= (1 << mode_index); 3686 ctx->modes_with_high_error |= (1 << mode_index);
3715 } 3687 }
3716 } 3688 }
3717 3689
3718 // Flag all ref frames that have a distortion thats > 2x the best we found at 3690 // Flag all ref frames that have a distortion thats > 2x the best we found at
3719 // this level. 3691 // this level.
3720 for (ref_frame = INTRA_FRAME; ref_frame <= ALTREF_FRAME; ref_frame++) { 3692 for (ref_frame = INTRA_FRAME; ref_frame <= ALTREF_FRAME; ref_frame++) {
3721 if (frame_distortions[ref_frame] > 2 * *returndistortion) { 3693 if (frame_distortions[ref_frame] > 2 * *returndistortion) {
3722 ctx->frames_with_high_error |= (1 << ref_frame); 3694 ctx->frames_with_high_error |= (1 << ref_frame);
3723 } 3695 }
3724 } 3696 }
3725 3697
3726 assert((cm->mcomp_filter_type == SWITCHABLE) || 3698 assert((cm->mcomp_filter_type == SWITCHABLE) ||
3727 (cm->mcomp_filter_type == best_mbmode.interp_filter) || 3699 (cm->mcomp_filter_type == best_mbmode.interp_filter) ||
3728 (best_mbmode.ref_frame[0] == INTRA_FRAME)); 3700 !is_inter_block(&best_mbmode));
3729 3701
3730 // Updating rd_thresh_freq_fact[] here means that the different 3702 // Updating rd_thresh_freq_fact[] here means that the different
3731 // partition/block sizes are handled independently based on the best 3703 // partition/block sizes are handled independently based on the best
3732 // choice for the current partition. It may well be better to keep a scaled 3704 // choice for the current partition. It may well be better to keep a scaled
3733 // best rd so far value and update rd_thresh_freq_fact based on the mode/size 3705 // best rd so far value and update rd_thresh_freq_fact based on the mode/size
3734 // combination that wins out. 3706 // combination that wins out.
3735 if (cpi->sf.adaptive_rd_thresh) { 3707 if (cpi->sf.adaptive_rd_thresh) {
3736 for (mode_index = 0; mode_index < MAX_MODES; ++mode_index) { 3708 for (mode_index = 0; mode_index < MAX_MODES; ++mode_index) {
3737 if (mode_index == best_mode_index) { 3709 if (mode_index == best_mode_index) {
3738 cpi->rd_thresh_freq_fact[bsize][mode_index] -= 3710 cpi->rd_thresh_freq_fact[bsize][mode_index] -=
3739 (cpi->rd_thresh_freq_fact[bsize][mode_index] >> 3); 3711 (cpi->rd_thresh_freq_fact[bsize][mode_index] >> 3);
3740 } else { 3712 } else {
3741 cpi->rd_thresh_freq_fact[bsize][mode_index] += RD_THRESH_INC; 3713 cpi->rd_thresh_freq_fact[bsize][mode_index] += RD_THRESH_INC;
3742 if (cpi->rd_thresh_freq_fact[bsize][mode_index] > 3714 if (cpi->rd_thresh_freq_fact[bsize][mode_index] >
3743 (cpi->sf.adaptive_rd_thresh * RD_THRESH_MAX_FACT)) { 3715 (cpi->sf.adaptive_rd_thresh * RD_THRESH_MAX_FACT)) {
3744 cpi->rd_thresh_freq_fact[bsize][mode_index] = 3716 cpi->rd_thresh_freq_fact[bsize][mode_index] =
3745 cpi->sf.adaptive_rd_thresh * RD_THRESH_MAX_FACT; 3717 cpi->sf.adaptive_rd_thresh * RD_THRESH_MAX_FACT;
3746 } 3718 }
3747 } 3719 }
3748 } 3720 }
3749 } 3721 }
3750 3722
3751 // macroblock modes 3723 // macroblock modes
3752 *mbmi = best_mbmode; 3724 *mbmi = best_mbmode;
3753 x->skip |= best_skip2; 3725 x->skip |= best_skip2;
3754 3726
3755 for (i = 0; i < NB_PREDICTION_TYPES; ++i) { 3727 for (i = 0; i < REFERENCE_MODES; ++i) {
3756 if (best_pred_rd[i] == INT64_MAX) 3728 if (best_pred_rd[i] == INT64_MAX)
3757 best_pred_diff[i] = INT_MIN; 3729 best_pred_diff[i] = INT_MIN;
3758 else 3730 else
3759 best_pred_diff[i] = best_rd - best_pred_rd[i]; 3731 best_pred_diff[i] = best_rd - best_pred_rd[i];
3760 } 3732 }
3761 3733
3762 if (!x->skip) { 3734 if (!x->skip) {
3763 for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; i++) { 3735 for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; i++) {
3764 if (best_filter_rd[i] == INT64_MAX) 3736 if (best_filter_rd[i] == INT64_MAX)
3765 best_filter_diff[i] = 0; 3737 best_filter_diff[i] = 0;
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
3816 static const int flag_list[4] = { 0, VP9_LAST_FLAG, VP9_GOLD_FLAG, 3788 static const int flag_list[4] = { 0, VP9_LAST_FLAG, VP9_GOLD_FLAG,
3817 VP9_ALT_FLAG }; 3789 VP9_ALT_FLAG };
3818 int idx_list[4] = {0, 3790 int idx_list[4] = {0,
3819 cpi->lst_fb_idx, 3791 cpi->lst_fb_idx,
3820 cpi->gld_fb_idx, 3792 cpi->gld_fb_idx,
3821 cpi->alt_fb_idx}; 3793 cpi->alt_fb_idx};
3822 int64_t best_rd = best_rd_so_far; 3794 int64_t best_rd = best_rd_so_far;
3823 int64_t best_yrd = best_rd_so_far; // FIXME(rbultje) more precise 3795 int64_t best_yrd = best_rd_so_far; // FIXME(rbultje) more precise
3824 int64_t best_tx_rd[TX_MODES]; 3796 int64_t best_tx_rd[TX_MODES];
3825 int64_t best_tx_diff[TX_MODES]; 3797 int64_t best_tx_diff[TX_MODES];
3826 int64_t best_pred_diff[NB_PREDICTION_TYPES]; 3798 int64_t best_pred_diff[REFERENCE_MODES];
3827 int64_t best_pred_rd[NB_PREDICTION_TYPES]; 3799 int64_t best_pred_rd[REFERENCE_MODES];
3828 int64_t best_filter_rd[SWITCHABLE_FILTER_CONTEXTS]; 3800 int64_t best_filter_rd[SWITCHABLE_FILTER_CONTEXTS];
3829 int64_t best_filter_diff[SWITCHABLE_FILTER_CONTEXTS]; 3801 int64_t best_filter_diff[SWITCHABLE_FILTER_CONTEXTS];
3830 MB_MODE_INFO best_mbmode = { 0 }; 3802 MB_MODE_INFO best_mbmode = { 0 };
3831 int mode_index, best_mode_index = 0; 3803 int mode_index, best_mode_index = 0;
3832 unsigned int ref_costs_single[MAX_REF_FRAMES], ref_costs_comp[MAX_REF_FRAMES]; 3804 unsigned int ref_costs_single[MAX_REF_FRAMES], ref_costs_comp[MAX_REF_FRAMES];
3833 vp9_prob comp_mode_p; 3805 vp9_prob comp_mode_p;
3834 int64_t best_inter_rd = INT64_MAX; 3806 int64_t best_inter_rd = INT64_MAX;
3835 MV_REFERENCE_FRAME best_inter_ref_frame = LAST_FRAME; 3807 MV_REFERENCE_FRAME best_inter_ref_frame = LAST_FRAME;
3836 INTERPOLATION_TYPE tmp_best_filter = SWITCHABLE; 3808 INTERPOLATION_TYPE tmp_best_filter = SWITCHABLE;
3837 int rate_uv_intra[TX_SIZES], rate_uv_tokenonly[TX_SIZES]; 3809 int rate_uv_intra[TX_SIZES], rate_uv_tokenonly[TX_SIZES];
3838 int64_t dist_uv[TX_SIZES]; 3810 int64_t dist_uv[TX_SIZES];
3839 int skip_uv[TX_SIZES]; 3811 int skip_uv[TX_SIZES];
3840 MB_PREDICTION_MODE mode_uv[TX_SIZES] = { 0 }; 3812 MB_PREDICTION_MODE mode_uv[TX_SIZES] = { 0 };
3841 struct scale_factors scale_factor[4]; 3813 struct scale_factors scale_factor[4];
3842 unsigned int ref_frame_mask = 0;
3843 unsigned int mode_mask = 0;
3844 int intra_cost_penalty = 20 * vp9_dc_quant(cpi->common.base_qindex, 3814 int intra_cost_penalty = 20 * vp9_dc_quant(cpi->common.base_qindex,
3845 cpi->common.y_dc_delta_q); 3815 cpi->common.y_dc_delta_q);
3846 int_mv seg_mvs[4][MAX_REF_FRAMES]; 3816 int_mv seg_mvs[4][MAX_REF_FRAMES];
3847 b_mode_info best_bmodes[4]; 3817 b_mode_info best_bmodes[4];
3848 int best_skip2 = 0; 3818 int best_skip2 = 0;
3849 3819
3850 x->skip_encode = cpi->sf.skip_encode_frame && xd->q_index < QIDX_SKIP_THRESH; 3820 x->skip_encode = cpi->sf.skip_encode_frame && x->q_index < QIDX_SKIP_THRESH;
3851 vpx_memset(x->zcoeff_blk[TX_4X4], 0, 4); 3821 vpx_memset(x->zcoeff_blk[TX_4X4], 0, 4);
3852 3822
3853 for (i = 0; i < 4; i++) { 3823 for (i = 0; i < 4; i++) {
3854 int j; 3824 int j;
3855 for (j = 0; j < MAX_REF_FRAMES; j++) 3825 for (j = 0; j < MAX_REF_FRAMES; j++)
3856 seg_mvs[i][j].as_int = INVALID_MV; 3826 seg_mvs[i][j].as_int = INVALID_MV;
3857 } 3827 }
3858 3828
3859 estimate_ref_frame_costs(cpi, segment_id, ref_costs_single, ref_costs_comp, 3829 estimate_ref_frame_costs(cpi, segment_id, ref_costs_single, ref_costs_comp,
3860 &comp_mode_p); 3830 &comp_mode_p);
3861 3831
3862 for (i = 0; i < NB_PREDICTION_TYPES; ++i) 3832 for (i = 0; i < REFERENCE_MODES; ++i)
3863 best_pred_rd[i] = INT64_MAX; 3833 best_pred_rd[i] = INT64_MAX;
3864 for (i = 0; i < TX_MODES; i++) 3834 for (i = 0; i < TX_MODES; i++)
3865 best_tx_rd[i] = INT64_MAX; 3835 best_tx_rd[i] = INT64_MAX;
3866 for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; i++) 3836 for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; i++)
3867 best_filter_rd[i] = INT64_MAX; 3837 best_filter_rd[i] = INT64_MAX;
3868 for (i = 0; i < TX_SIZES; i++) 3838 for (i = 0; i < TX_SIZES; i++)
3869 rate_uv_intra[i] = INT_MAX; 3839 rate_uv_intra[i] = INT_MAX;
3870 3840
3871 *returnrate = INT_MAX; 3841 *returnrate = INT_MAX;
3872 3842
3873 // Create a mask set to 1 for each reference frame used by a smaller
3874 // resolution.
3875 if (cpi->sf.use_avoid_tested_higherror) {
3876 ref_frame_mask = 0;
3877 mode_mask = 0;
3878 ref_frame_mask = ~ref_frame_mask;
3879 mode_mask = ~mode_mask;
3880 }
3881
3882 for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ref_frame++) { 3843 for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ref_frame++) {
3883 if (cpi->ref_frame_flags & flag_list[ref_frame]) { 3844 if (cpi->ref_frame_flags & flag_list[ref_frame]) {
3884 setup_buffer_inter(cpi, x, tile, idx_list[ref_frame], ref_frame, 3845 setup_buffer_inter(cpi, x, tile, idx_list[ref_frame], ref_frame,
3885 block_size, mi_row, mi_col, 3846 block_size, mi_row, mi_col,
3886 frame_mv[NEARESTMV], frame_mv[NEARMV], 3847 frame_mv[NEARESTMV], frame_mv[NEARMV],
3887 yv12_mb, scale_factor); 3848 yv12_mb, scale_factor);
3888 } 3849 }
3889 frame_mv[NEWMV][ref_frame].as_int = INVALID_MV; 3850 frame_mv[NEWMV][ref_frame].as_int = INVALID_MV;
3890 frame_mv[ZEROMV][ref_frame].as_int = 0; 3851 frame_mv[ZEROMV][ref_frame].as_int = 0;
3891 } 3852 }
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
3923 cpi->mode_skip_mask = 0x0010; 3884 cpi->mode_skip_mask = 0x0010;
3924 break; 3885 break;
3925 case GOLDEN_FRAME: 3886 case GOLDEN_FRAME:
3926 cpi->mode_skip_mask = 0x0008; 3887 cpi->mode_skip_mask = 0x0008;
3927 break; 3888 break;
3928 case ALTREF_FRAME: 3889 case ALTREF_FRAME:
3929 cpi->mode_skip_mask = 0x0000; 3890 cpi->mode_skip_mask = 0x0000;
3930 break; 3891 break;
3931 case NONE: 3892 case NONE:
3932 case MAX_REF_FRAMES: 3893 case MAX_REF_FRAMES:
3933 assert(!"Invalid Reference frame"); 3894 assert(0 && "Invalid Reference frame");
3934 } 3895 }
3935 } 3896 }
3936 if (cpi->mode_skip_mask & ((int64_t)1 << mode_index)) 3897 if (cpi->mode_skip_mask & ((int64_t)1 << mode_index))
3937 continue; 3898 continue;
3938 } 3899 }
3939 3900
3940 // Skip if the current reference frame has been masked off 3901 // Skip if the current reference frame has been masked off
3941 if (cpi->sf.reference_masking && !cpi->set_ref_frame_mask && 3902 if (cpi->sf.reference_masking && !cpi->set_ref_frame_mask &&
3942 (cpi->ref_frame_mask & (1 << ref_frame))) 3903 (cpi->ref_frame_mask & (1 << ref_frame)))
3943 continue; 3904 continue;
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
3994 // Evaluate all sub-pel filters irrespective of whether we can use 3955 // Evaluate all sub-pel filters irrespective of whether we can use
3995 // them for this frame. 3956 // them for this frame.
3996 mbmi->interp_filter = cm->mcomp_filter_type; 3957 mbmi->interp_filter = cm->mcomp_filter_type;
3997 vp9_setup_interp_filters(xd, mbmi->interp_filter, &cpi->common); 3958 vp9_setup_interp_filters(xd, mbmi->interp_filter, &cpi->common);
3998 3959
3999 if (comp_pred) { 3960 if (comp_pred) {
4000 if (!(cpi->ref_frame_flags & flag_list[second_ref_frame])) 3961 if (!(cpi->ref_frame_flags & flag_list[second_ref_frame]))
4001 continue; 3962 continue;
4002 set_scale_factors(xd, ref_frame, second_ref_frame, scale_factor); 3963 set_scale_factors(xd, ref_frame, second_ref_frame, scale_factor);
4003 3964
4004 mode_excluded = mode_excluded 3965 mode_excluded = mode_excluded ? mode_excluded
4005 ? mode_excluded 3966 : cm->reference_mode == SINGLE_REFERENCE;
4006 : cm->comp_pred_mode == SINGLE_PREDICTION_ONLY;
4007 } else { 3967 } else {
4008 if (ref_frame != INTRA_FRAME && second_ref_frame != INTRA_FRAME) { 3968 if (ref_frame != INTRA_FRAME && second_ref_frame != INTRA_FRAME) {
4009 mode_excluded = 3969 mode_excluded = mode_excluded ?
4010 mode_excluded ? 3970 mode_excluded : cm->reference_mode == COMPOUND_REFERENCE;
4011 mode_excluded : cm->comp_pred_mode == COMP_PREDICTION_ONLY;
4012 } 3971 }
4013 } 3972 }
4014 3973
4015 // Select prediction reference frames. 3974 // Select prediction reference frames.
4016 for (i = 0; i < MAX_MB_PLANE; i++) { 3975 for (i = 0; i < MAX_MB_PLANE; i++) {
4017 xd->plane[i].pre[0] = yv12_mb[ref_frame][i]; 3976 xd->plane[i].pre[0] = yv12_mb[ref_frame][i];
4018 if (comp_pred) 3977 if (comp_pred)
4019 xd->plane[i].pre[1] = yv12_mb[second_ref_frame][i]; 3978 xd->plane[i].pre[1] = yv12_mb[second_ref_frame][i];
4020 } 3979 }
4021 3980
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
4053 int rate; 4012 int rate;
4054 mbmi->tx_size = TX_4X4; 4013 mbmi->tx_size = TX_4X4;
4055 if (rd_pick_intra_sub_8x8_y_mode(cpi, x, &rate, &rate_y, 4014 if (rd_pick_intra_sub_8x8_y_mode(cpi, x, &rate, &rate_y,
4056 &distortion_y, best_rd) >= best_rd) 4015 &distortion_y, best_rd) >= best_rd)
4057 continue; 4016 continue;
4058 rate2 += rate; 4017 rate2 += rate;
4059 rate2 += intra_cost_penalty; 4018 rate2 += intra_cost_penalty;
4060 distortion2 += distortion_y; 4019 distortion2 += distortion_y;
4061 4020
4062 if (rate_uv_intra[TX_4X4] == INT_MAX) { 4021 if (rate_uv_intra[TX_4X4] == INT_MAX) {
4063 choose_intra_uv_mode(cpi, bsize, &rate_uv_intra[TX_4X4], 4022 choose_intra_uv_mode(cpi, ctx, bsize, TX_4X4,
4023 &rate_uv_intra[TX_4X4],
4064 &rate_uv_tokenonly[TX_4X4], 4024 &rate_uv_tokenonly[TX_4X4],
4065 &dist_uv[TX_4X4], &skip_uv[TX_4X4], 4025 &dist_uv[TX_4X4], &skip_uv[TX_4X4],
4066 &mode_uv[TX_4X4]); 4026 &mode_uv[TX_4X4]);
4067 } 4027 }
4068 rate2 += rate_uv_intra[TX_4X4]; 4028 rate2 += rate_uv_intra[TX_4X4];
4069 rate_uv = rate_uv_tokenonly[TX_4X4]; 4029 rate_uv = rate_uv_tokenonly[TX_4X4];
4070 distortion2 += dist_uv[TX_4X4]; 4030 distortion2 += dist_uv[TX_4X4];
4071 distortion_uv = dist_uv[TX_4X4]; 4031 distortion_uv = dist_uv[TX_4X4];
4072 mbmi->uv_mode = mode_uv[TX_4X4]; 4032 mbmi->uv_mode = mode_uv[TX_4X4];
4073 tx_cache[ONLY_4X4] = RDCOST(x->rdmult, x->rddiv, rate2, distortion2); 4033 tx_cache[ONLY_4X4] = RDCOST(x->rdmult, x->rddiv, rate2, distortion2);
(...skipping 23 matching lines...) Expand all
4097 cpi->rd_thresh_sub8x8[segment_id][bsize][THR_GOLD] : this_rd_thresh; 4057 cpi->rd_thresh_sub8x8[segment_id][bsize][THR_GOLD] : this_rd_thresh;
4098 xd->mi_8x8[0]->mbmi.tx_size = TX_4X4; 4058 xd->mi_8x8[0]->mbmi.tx_size = TX_4X4;
4099 4059
4100 cpi->rd_filter_cache[SWITCHABLE_FILTERS] = INT64_MAX; 4060 cpi->rd_filter_cache[SWITCHABLE_FILTERS] = INT64_MAX;
4101 if (cm->mcomp_filter_type != BILINEAR) { 4061 if (cm->mcomp_filter_type != BILINEAR) {
4102 tmp_best_filter = EIGHTTAP; 4062 tmp_best_filter = EIGHTTAP;
4103 if (x->source_variance < 4063 if (x->source_variance <
4104 cpi->sf.disable_filter_search_var_thresh) { 4064 cpi->sf.disable_filter_search_var_thresh) {
4105 tmp_best_filter = EIGHTTAP; 4065 tmp_best_filter = EIGHTTAP;
4106 vp9_zero(cpi->rd_filter_cache); 4066 vp9_zero(cpi->rd_filter_cache);
4067 } else if (cpi->sf.adaptive_pred_filter_type == 1 &&
4068 ctx->pred_filter_type < SWITCHABLE) {
4069 tmp_best_filter = ctx->pred_filter_type;
4070 vp9_zero(cpi->rd_filter_cache);
4071 } else if (cpi->sf.adaptive_pred_filter_type == 2) {
4072 tmp_best_filter = ctx->pred_filter_type < SWITCHABLE ?
4073 ctx->pred_filter_type : 0;
4074 vp9_zero(cpi->rd_filter_cache);
4107 } else { 4075 } else {
4108 for (switchable_filter_index = 0; 4076 for (switchable_filter_index = 0;
4109 switchable_filter_index < SWITCHABLE_FILTERS; 4077 switchable_filter_index < SWITCHABLE_FILTERS;
4110 ++switchable_filter_index) { 4078 ++switchable_filter_index) {
4111 int newbest, rs; 4079 int newbest, rs;
4112 int64_t rs_rd; 4080 int64_t rs_rd;
4113 mbmi->interp_filter = switchable_filter_index; 4081 mbmi->interp_filter = switchable_filter_index;
4114 vp9_setup_interp_filters(xd, mbmi->interp_filter, &cpi->common); 4082 vp9_setup_interp_filters(xd, mbmi->interp_filter, &cpi->common);
4115 4083
4116 tmp_rd = rd_pick_best_mbsegmentation(cpi, x, tile, 4084 tmp_rd = rd_pick_best_mbsegmentation(cpi, x, tile,
(...skipping 27 matching lines...) Expand all
4144 cm->mcomp_filter_type != SWITCHABLE)) { 4112 cm->mcomp_filter_type != SWITCHABLE)) {
4145 tmp_best_rdu = tmp_rd; 4113 tmp_best_rdu = tmp_rd;
4146 tmp_best_rate = rate; 4114 tmp_best_rate = rate;
4147 tmp_best_ratey = rate_y; 4115 tmp_best_ratey = rate_y;
4148 tmp_best_distortion = distortion; 4116 tmp_best_distortion = distortion;
4149 tmp_best_sse = total_sse; 4117 tmp_best_sse = total_sse;
4150 tmp_best_skippable = skippable; 4118 tmp_best_skippable = skippable;
4151 tmp_best_mbmode = *mbmi; 4119 tmp_best_mbmode = *mbmi;
4152 for (i = 0; i < 4; i++) { 4120 for (i = 0; i < 4; i++) {
4153 tmp_best_bmodes[i] = xd->mi_8x8[0]->bmi[i]; 4121 tmp_best_bmodes[i] = xd->mi_8x8[0]->bmi[i];
4154 x->zcoeff_blk[TX_4X4][i] = !xd->plane[0].eobs[i]; 4122 x->zcoeff_blk[TX_4X4][i] = !x->plane[0].eobs[i];
4155 } 4123 }
4156 pred_exists = 1; 4124 pred_exists = 1;
4157 if (switchable_filter_index == 0 && 4125 if (switchable_filter_index == 0 &&
4158 cpi->sf.use_rd_breakout && 4126 cpi->sf.use_rd_breakout &&
4159 best_rd < INT64_MAX) { 4127 best_rd < INT64_MAX) {
4160 if (tmp_best_rdu / 2 > best_rd) { 4128 if (tmp_best_rdu / 2 > best_rd) {
4161 // skip searching the other filters if the first is 4129 // skip searching the other filters if the first is
4162 // already substantially larger than the best so far 4130 // already substantially larger than the best so far
4163 tmp_best_filter = mbmi->interp_filter; 4131 tmp_best_filter = mbmi->interp_filter;
4164 tmp_best_rdu = INT64_MAX; 4132 tmp_best_rdu = INT64_MAX;
4165 break; 4133 break;
4166 } 4134 }
4167 } 4135 }
4168 } 4136 }
4169 } // switchable_filter_index loop 4137 } // switchable_filter_index loop
4170 } 4138 }
4171 } 4139 }
4172 4140
4173 if (tmp_best_rdu == INT64_MAX) 4141 if (tmp_best_rdu == INT64_MAX && pred_exists)
4174 continue; 4142 continue;
4175 4143
4176 mbmi->interp_filter = (cm->mcomp_filter_type == SWITCHABLE ? 4144 mbmi->interp_filter = (cm->mcomp_filter_type == SWITCHABLE ?
4177 tmp_best_filter : cm->mcomp_filter_type); 4145 tmp_best_filter : cm->mcomp_filter_type);
4178 vp9_setup_interp_filters(xd, mbmi->interp_filter, &cpi->common); 4146 vp9_setup_interp_filters(xd, mbmi->interp_filter, &cpi->common);
4179 if (!pred_exists) { 4147 if (!pred_exists) {
4180 // Handles the special case when a filter that is not in the 4148 // Handles the special case when a filter that is not in the
4181 // switchable list (bilinear, 6-tap) is indicated at the frame level 4149 // switchable list (bilinear, 6-tap) is indicated at the frame level
4182 tmp_rd = rd_pick_best_mbsegmentation(cpi, x, tile, 4150 tmp_rd = rd_pick_best_mbsegmentation(cpi, x, tile,
4183 &mbmi->ref_mvs[ref_frame][0], 4151 &mbmi->ref_mvs[ref_frame][0],
(...skipping 21 matching lines...) Expand all
4205 for (i = 0; i < 4; i++) 4173 for (i = 0; i < 4; i++)
4206 xd->mi_8x8[0]->bmi[i] = tmp_best_bmodes[i]; 4174 xd->mi_8x8[0]->bmi[i] = tmp_best_bmodes[i];
4207 } 4175 }
4208 4176
4209 rate2 += rate; 4177 rate2 += rate;
4210 distortion2 += distortion; 4178 distortion2 += distortion;
4211 4179
4212 if (cpi->common.mcomp_filter_type == SWITCHABLE) 4180 if (cpi->common.mcomp_filter_type == SWITCHABLE)
4213 rate2 += get_switchable_rate(x); 4181 rate2 += get_switchable_rate(x);
4214 4182
4215 if (!mode_excluded) { 4183 if (!mode_excluded)
4216 if (comp_pred) 4184 mode_excluded = comp_pred
4217 mode_excluded = cpi->common.comp_pred_mode == SINGLE_PREDICTION_ONLY; 4185 ? cpi->common.reference_mode == SINGLE_REFERENCE
4218 else 4186 : cpi->common.reference_mode == COMPOUND_REFERENCE;
4219 mode_excluded = cpi->common.comp_pred_mode == COMP_PREDICTION_ONLY; 4187
4220 }
4221 compmode_cost = vp9_cost_bit(comp_mode_p, comp_pred); 4188 compmode_cost = vp9_cost_bit(comp_mode_p, comp_pred);
4222 4189
4223 tmp_best_rdu = best_rd - 4190 tmp_best_rdu = best_rd -
4224 MIN(RDCOST(x->rdmult, x->rddiv, rate2, distortion2), 4191 MIN(RDCOST(x->rdmult, x->rddiv, rate2, distortion2),
4225 RDCOST(x->rdmult, x->rddiv, 0, total_sse)); 4192 RDCOST(x->rdmult, x->rddiv, 0, total_sse));
4226 4193
4227 if (tmp_best_rdu > 0) { 4194 if (tmp_best_rdu > 0) {
4228 // If even the 'Y' rd value of split is higher than best so far 4195 // If even the 'Y' rd value of split is higher than best so far
4229 // then dont bother looking at UV 4196 // then dont bother looking at UV
4230 vp9_build_inter_predictors_sbuv(&x->e_mbd, mi_row, mi_col, 4197 vp9_build_inter_predictors_sbuv(&x->e_mbd, mi_row, mi_col,
4231 BLOCK_8X8); 4198 BLOCK_8X8);
4232 super_block_uvrd(cpi, x, &rate_uv, &distortion_uv, &uv_skippable, 4199 super_block_uvrd(cpi, x, &rate_uv, &distortion_uv, &uv_skippable,
4233 &uv_sse, BLOCK_8X8, tmp_best_rdu); 4200 &uv_sse, BLOCK_8X8, tmp_best_rdu);
4234 if (rate_uv == INT_MAX) 4201 if (rate_uv == INT_MAX)
4235 continue; 4202 continue;
4236 rate2 += rate_uv; 4203 rate2 += rate_uv;
4237 distortion2 += distortion_uv; 4204 distortion2 += distortion_uv;
4238 skippable = skippable && uv_skippable; 4205 skippable = skippable && uv_skippable;
4239 total_sse += uv_sse; 4206 total_sse += uv_sse;
4240 4207
4241 tx_cache[ONLY_4X4] = RDCOST(x->rdmult, x->rddiv, rate2, distortion2); 4208 tx_cache[ONLY_4X4] = RDCOST(x->rdmult, x->rddiv, rate2, distortion2);
4242 for (i = 0; i < TX_MODES; ++i) 4209 for (i = 0; i < TX_MODES; ++i)
4243 tx_cache[i] = tx_cache[ONLY_4X4]; 4210 tx_cache[i] = tx_cache[ONLY_4X4];
4244 } 4211 }
4245 } 4212 }
4246 4213
4247 if (cpi->common.comp_pred_mode == HYBRID_PREDICTION) { 4214 if (cpi->common.reference_mode == REFERENCE_MODE_SELECT)
4248 rate2 += compmode_cost; 4215 rate2 += compmode_cost;
4249 }
4250 4216
4251 // Estimate the reference frame signaling cost and add it 4217 // Estimate the reference frame signaling cost and add it
4252 // to the rolling cost variable. 4218 // to the rolling cost variable.
4253 if (second_ref_frame > INTRA_FRAME) { 4219 if (second_ref_frame > INTRA_FRAME) {
4254 rate2 += ref_costs_comp[ref_frame]; 4220 rate2 += ref_costs_comp[ref_frame];
4255 } else { 4221 } else {
4256 rate2 += ref_costs_single[ref_frame]; 4222 rate2 += ref_costs_single[ref_frame];
4257 } 4223 }
4258 4224
4259 if (!disable_skip) { 4225 if (!disable_skip) {
4260 // Test for the condition where skip block will be activated 4226 // Test for the condition where skip block will be activated
4261 // because there are no non zero coefficients and make any 4227 // because there are no non zero coefficients and make any
4262 // necessary adjustment for rate. Ignore if skip is coded at 4228 // necessary adjustment for rate. Ignore if skip is coded at
4263 // segment level as the cost wont have been added in. 4229 // segment level as the cost wont have been added in.
4264 // Is Mb level skip allowed (i.e. not coded at segment level). 4230 // Is Mb level skip allowed (i.e. not coded at segment level).
4265 const int mb_skip_allowed = !vp9_segfeature_active(seg, segment_id, 4231 const int mb_skip_allowed = !vp9_segfeature_active(seg, segment_id,
4266 SEG_LVL_SKIP); 4232 SEG_LVL_SKIP);
4267 4233
4268 if (mb_skip_allowed && ref_frame != INTRA_FRAME && !xd->lossless) { 4234 if (mb_skip_allowed && ref_frame != INTRA_FRAME && !xd->lossless) {
4269 if (RDCOST(x->rdmult, x->rddiv, rate_y + rate_uv, distortion2) < 4235 if (RDCOST(x->rdmult, x->rddiv, rate_y + rate_uv, distortion2) <
4270 RDCOST(x->rdmult, x->rddiv, 0, total_sse)) { 4236 RDCOST(x->rdmult, x->rddiv, 0, total_sse)) {
4271 // Add in the cost of the no skip flag. 4237 // Add in the cost of the no skip flag.
4272 int prob_skip_cost = vp9_cost_bit(vp9_get_pred_prob_mbskip(cm, xd), 4238 rate2 += vp9_cost_bit(vp9_get_skip_prob(cm, xd), 0);
4273 0);
4274 rate2 += prob_skip_cost;
4275 } else { 4239 } else {
4276 // FIXME(rbultje) make this work for splitmv also 4240 // FIXME(rbultje) make this work for splitmv also
4277 int prob_skip_cost = vp9_cost_bit(vp9_get_pred_prob_mbskip(cm, xd), 4241 rate2 += vp9_cost_bit(vp9_get_skip_prob(cm, xd), 1);
4278 1);
4279 rate2 += prob_skip_cost;
4280 distortion2 = total_sse; 4242 distortion2 = total_sse;
4281 assert(total_sse >= 0); 4243 assert(total_sse >= 0);
4282 rate2 -= (rate_y + rate_uv); 4244 rate2 -= (rate_y + rate_uv);
4283 rate_y = 0; 4245 rate_y = 0;
4284 rate_uv = 0; 4246 rate_uv = 0;
4285 this_skip2 = 1; 4247 this_skip2 = 1;
4286 } 4248 }
4287 } else if (mb_skip_allowed) { 4249 } else if (mb_skip_allowed) {
4288 // Add in the cost of the no skip flag. 4250 // Add in the cost of the no skip flag.
4289 int prob_skip_cost = vp9_cost_bit(vp9_get_pred_prob_mbskip(cm, xd), 4251 rate2 += vp9_cost_bit(vp9_get_skip_prob(cm, xd), 0);
4290 0);
4291 rate2 += prob_skip_cost;
4292 } 4252 }
4293 4253
4294 // Calculate the final RD estimate for this mode. 4254 // Calculate the final RD estimate for this mode.
4295 this_rd = RDCOST(x->rdmult, x->rddiv, rate2, distortion2); 4255 this_rd = RDCOST(x->rdmult, x->rddiv, rate2, distortion2);
4296 } 4256 }
4297 4257
4298 // Keep record of best inter rd with single reference 4258 // Keep record of best inter rd with single reference
4299 if (xd->mi_8x8[0]->mbmi.ref_frame[0] > INTRA_FRAME && 4259 if (is_inter_block(&xd->mi_8x8[0]->mbmi) &&
4300 xd->mi_8x8[0]->mbmi.ref_frame[1] == NONE && 4260 !has_second_ref(&xd->mi_8x8[0]->mbmi) &&
4301 !mode_excluded && 4261 !mode_excluded &&
4302 this_rd < best_inter_rd) { 4262 this_rd < best_inter_rd) {
4303 best_inter_rd = this_rd; 4263 best_inter_rd = this_rd;
4304 best_inter_ref_frame = ref_frame; 4264 best_inter_ref_frame = ref_frame;
4305 } 4265 }
4306 4266
4307 if (!disable_skip && ref_frame == INTRA_FRAME) { 4267 if (!disable_skip && ref_frame == INTRA_FRAME) {
4308 for (i = 0; i < NB_PREDICTION_TYPES; ++i) 4268 for (i = 0; i < REFERENCE_MODES; ++i)
4309 best_pred_rd[i] = MIN(best_pred_rd[i], this_rd); 4269 best_pred_rd[i] = MIN(best_pred_rd[i], this_rd);
4310 for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; i++) 4270 for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; i++)
4311 best_filter_rd[i] = MIN(best_filter_rd[i], this_rd); 4271 best_filter_rd[i] = MIN(best_filter_rd[i], this_rd);
4312 } 4272 }
4313 4273
4314 // Did this mode help.. i.e. is it the new best mode 4274 // Did this mode help.. i.e. is it the new best mode
4315 if (this_rd < best_rd || x->skip) { 4275 if (this_rd < best_rd || x->skip) {
4316 if (!mode_excluded) { 4276 if (!mode_excluded) {
4277 int max_plane = MAX_MB_PLANE;
4317 // Note index of best mode so far 4278 // Note index of best mode so far
4318 best_mode_index = mode_index; 4279 best_mode_index = mode_index;
4319 4280
4320 if (ref_frame == INTRA_FRAME) { 4281 if (ref_frame == INTRA_FRAME) {
4321 /* required for left and above block mv */ 4282 /* required for left and above block mv */
4322 mbmi->mv[0].as_int = 0; 4283 mbmi->mv[0].as_int = 0;
4284 max_plane = 1;
4323 } 4285 }
4324 4286
4325 *returnrate = rate2; 4287 *returnrate = rate2;
4326 *returndistortion = distortion2; 4288 *returndistortion = distortion2;
4327 best_rd = this_rd; 4289 best_rd = this_rd;
4328 best_yrd = best_rd - 4290 best_yrd = best_rd -
4329 RDCOST(x->rdmult, x->rddiv, rate_uv, distortion_uv); 4291 RDCOST(x->rdmult, x->rddiv, rate_uv, distortion_uv);
4330 best_mbmode = *mbmi; 4292 best_mbmode = *mbmi;
4331 best_skip2 = this_skip2; 4293 best_skip2 = this_skip2;
4294 if (!x->select_txfm_size)
4295 swap_block_ptr(x, ctx, max_plane);
4332 vpx_memcpy(ctx->zcoeff_blk, x->zcoeff_blk[mbmi->tx_size], 4296 vpx_memcpy(ctx->zcoeff_blk, x->zcoeff_blk[mbmi->tx_size],
4333 sizeof(uint8_t) * ctx->num_4x4_blk); 4297 sizeof(uint8_t) * ctx->num_4x4_blk);
4334 4298
4335 for (i = 0; i < 4; i++) 4299 for (i = 0; i < 4; i++)
4336 best_bmodes[i] = xd->mi_8x8[0]->bmi[i]; 4300 best_bmodes[i] = xd->mi_8x8[0]->bmi[i];
4337 4301
4338 // TODO(debargha): enhance this test with a better distortion prediction 4302 // TODO(debargha): enhance this test with a better distortion prediction
4339 // based on qp, activity mask and history 4303 // based on qp, activity mask and history
4340 if ((cpi->sf.mode_search_skip_flags & FLAG_EARLY_TERMINATE) && 4304 if ((cpi->sf.mode_search_skip_flags & FLAG_EARLY_TERMINATE) &&
4341 (mode_index > MIN_EARLY_TERM_INDEX)) { 4305 (mode_index > MIN_EARLY_TERM_INDEX)) {
4342 const int qstep = xd->plane[0].dequant[1]; 4306 const int qstep = xd->plane[0].dequant[1];
4343 // TODO(debargha): Enhance this by specializing for each mode_index 4307 // TODO(debargha): Enhance this by specializing for each mode_index
4344 int scale = 4; 4308 int scale = 4;
4345 if (x->source_variance < UINT_MAX) { 4309 if (x->source_variance < UINT_MAX) {
4346 const int var_adjust = (x->source_variance < 16); 4310 const int var_adjust = (x->source_variance < 16);
4347 scale -= var_adjust; 4311 scale -= var_adjust;
4348 } 4312 }
4349 if (ref_frame > INTRA_FRAME && 4313 if (ref_frame > INTRA_FRAME &&
4350 distortion2 * scale < qstep * qstep) { 4314 distortion2 * scale < qstep * qstep) {
4351 early_term = 1; 4315 early_term = 1;
4352 } 4316 }
4353 } 4317 }
4354 } 4318 }
4355 } 4319 }
4356 4320
4357 /* keep record of best compound/single-only prediction */ 4321 /* keep record of best compound/single-only prediction */
4358 if (!disable_skip && ref_frame != INTRA_FRAME) { 4322 if (!disable_skip && ref_frame != INTRA_FRAME) {
4359 int single_rd, hybrid_rd, single_rate, hybrid_rate; 4323 int64_t single_rd, hybrid_rd, single_rate, hybrid_rate;
4360 4324
4361 if (cpi->common.comp_pred_mode == HYBRID_PREDICTION) { 4325 if (cpi->common.reference_mode == REFERENCE_MODE_SELECT) {
4362 single_rate = rate2 - compmode_cost; 4326 single_rate = rate2 - compmode_cost;
4363 hybrid_rate = rate2; 4327 hybrid_rate = rate2;
4364 } else { 4328 } else {
4365 single_rate = rate2; 4329 single_rate = rate2;
4366 hybrid_rate = rate2 + compmode_cost; 4330 hybrid_rate = rate2 + compmode_cost;
4367 } 4331 }
4368 4332
4369 single_rd = RDCOST(x->rdmult, x->rddiv, single_rate, distortion2); 4333 single_rd = RDCOST(x->rdmult, x->rddiv, single_rate, distortion2);
4370 hybrid_rd = RDCOST(x->rdmult, x->rddiv, hybrid_rate, distortion2); 4334 hybrid_rd = RDCOST(x->rdmult, x->rddiv, hybrid_rate, distortion2);
4371 4335
4372 if (second_ref_frame <= INTRA_FRAME && 4336 if (second_ref_frame <= INTRA_FRAME &&
4373 single_rd < best_pred_rd[SINGLE_PREDICTION_ONLY]) { 4337 single_rd < best_pred_rd[SINGLE_REFERENCE]) {
4374 best_pred_rd[SINGLE_PREDICTION_ONLY] = single_rd; 4338 best_pred_rd[SINGLE_REFERENCE] = single_rd;
4375 } else if (second_ref_frame > INTRA_FRAME && 4339 } else if (second_ref_frame > INTRA_FRAME &&
4376 single_rd < best_pred_rd[COMP_PREDICTION_ONLY]) { 4340 single_rd < best_pred_rd[COMPOUND_REFERENCE]) {
4377 best_pred_rd[COMP_PREDICTION_ONLY] = single_rd; 4341 best_pred_rd[COMPOUND_REFERENCE] = single_rd;
4378 } 4342 }
4379 if (hybrid_rd < best_pred_rd[HYBRID_PREDICTION]) 4343 if (hybrid_rd < best_pred_rd[REFERENCE_MODE_SELECT])
4380 best_pred_rd[HYBRID_PREDICTION] = hybrid_rd; 4344 best_pred_rd[REFERENCE_MODE_SELECT] = hybrid_rd;
4381 } 4345 }
4382 4346
4383 /* keep record of best filter type */ 4347 /* keep record of best filter type */
4384 if (!mode_excluded && !disable_skip && ref_frame != INTRA_FRAME && 4348 if (!mode_excluded && !disable_skip && ref_frame != INTRA_FRAME &&
4385 cm->mcomp_filter_type != BILINEAR) { 4349 cm->mcomp_filter_type != BILINEAR) {
4386 int64_t ref = cpi->rd_filter_cache[cm->mcomp_filter_type == SWITCHABLE ? 4350 int64_t ref = cpi->rd_filter_cache[cm->mcomp_filter_type == SWITCHABLE ?
4387 SWITCHABLE_FILTERS : cm->mcomp_filter_type]; 4351 SWITCHABLE_FILTERS : cm->mcomp_filter_type];
4388 for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; i++) { 4352 for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; i++) {
4389 int64_t adj_rd; 4353 int64_t adj_rd;
4390 // In cases of poor prediction, filter_cache[] can contain really big 4354 // In cases of poor prediction, filter_cache[] can contain really big
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
4427 break; 4391 break;
4428 } 4392 }
4429 4393
4430 if (best_rd >= best_rd_so_far) 4394 if (best_rd >= best_rd_so_far)
4431 return INT64_MAX; 4395 return INT64_MAX;
4432 4396
4433 // If we used an estimate for the uv intra rd in the loop above... 4397 // If we used an estimate for the uv intra rd in the loop above...
4434 if (cpi->sf.use_uv_intra_rd_estimate) { 4398 if (cpi->sf.use_uv_intra_rd_estimate) {
4435 // Do Intra UV best rd mode selection if best mode choice above was intra. 4399 // Do Intra UV best rd mode selection if best mode choice above was intra.
4436 if (vp9_ref_order[best_mode_index].ref_frame == INTRA_FRAME) { 4400 if (vp9_ref_order[best_mode_index].ref_frame == INTRA_FRAME) {
4437 TX_SIZE uv_tx_size = get_uv_tx_size(mbmi); 4401 TX_SIZE uv_tx_size;
4438 rd_pick_intra_sbuv_mode(cpi, x, &rate_uv_intra[uv_tx_size], 4402 *mbmi = best_mbmode;
4403 uv_tx_size = get_uv_tx_size(mbmi);
4404 rd_pick_intra_sbuv_mode(cpi, x, ctx, &rate_uv_intra[uv_tx_size],
4439 &rate_uv_tokenonly[uv_tx_size], 4405 &rate_uv_tokenonly[uv_tx_size],
4440 &dist_uv[uv_tx_size], 4406 &dist_uv[uv_tx_size],
4441 &skip_uv[uv_tx_size], 4407 &skip_uv[uv_tx_size],
4442 BLOCK_8X8); 4408 BLOCK_8X8, uv_tx_size);
4443 } 4409 }
4444 } 4410 }
4445 4411
4446 // If we are using reference masking and the set mask flag is set then 4412 // If we are using reference masking and the set mask flag is set then
4447 // create the reference frame mask. 4413 // create the reference frame mask.
4448 if (cpi->sf.reference_masking && cpi->set_ref_frame_mask) 4414 if (cpi->sf.reference_masking && cpi->set_ref_frame_mask)
4449 cpi->ref_frame_mask = ~(1 << vp9_ref_order[best_mode_index].ref_frame); 4415 cpi->ref_frame_mask = ~(1 << vp9_ref_order[best_mode_index].ref_frame);
4450 4416
4451 if (best_rd == INT64_MAX && bsize < BLOCK_8X8) { 4417 if (best_rd == INT64_MAX && bsize < BLOCK_8X8) {
4452 *returnrate = INT_MAX; 4418 *returnrate = INT_MAX;
4453 *returndistortion = INT_MAX; 4419 *returndistortion = INT_MAX;
4454 return best_rd; 4420 return best_rd;
4455 } 4421 }
4456 4422
4457 assert((cm->mcomp_filter_type == SWITCHABLE) || 4423 assert((cm->mcomp_filter_type == SWITCHABLE) ||
4458 (cm->mcomp_filter_type == best_mbmode.interp_filter) || 4424 (cm->mcomp_filter_type == best_mbmode.interp_filter) ||
4459 (best_mbmode.ref_frame[0] == INTRA_FRAME)); 4425 !is_inter_block(&best_mbmode));
4460 4426
4461 // Updating rd_thresh_freq_fact[] here means that the different 4427 // Updating rd_thresh_freq_fact[] here means that the different
4462 // partition/block sizes are handled independently based on the best 4428 // partition/block sizes are handled independently based on the best
4463 // choice for the current partition. It may well be better to keep a scaled 4429 // choice for the current partition. It may well be better to keep a scaled
4464 // best rd so far value and update rd_thresh_freq_fact based on the mode/size 4430 // best rd so far value and update rd_thresh_freq_fact based on the mode/size
4465 // combination that wins out. 4431 // combination that wins out.
4466 if (cpi->sf.adaptive_rd_thresh) { 4432 if (cpi->sf.adaptive_rd_thresh) {
4467 for (mode_index = 0; mode_index < MAX_REFS; ++mode_index) { 4433 for (mode_index = 0; mode_index < MAX_REFS; ++mode_index) {
4468 if (mode_index == best_mode_index) { 4434 if (mode_index == best_mode_index) {
4469 cpi->rd_thresh_freq_sub8x8[bsize][mode_index] -= 4435 cpi->rd_thresh_freq_sub8x8[bsize][mode_index] -=
4470 (cpi->rd_thresh_freq_sub8x8[bsize][mode_index] >> 3); 4436 (cpi->rd_thresh_freq_sub8x8[bsize][mode_index] >> 3);
4471 } else { 4437 } else {
4472 cpi->rd_thresh_freq_sub8x8[bsize][mode_index] += RD_THRESH_INC; 4438 cpi->rd_thresh_freq_sub8x8[bsize][mode_index] += RD_THRESH_INC;
4473 if (cpi->rd_thresh_freq_sub8x8[bsize][mode_index] > 4439 if (cpi->rd_thresh_freq_sub8x8[bsize][mode_index] >
4474 (cpi->sf.adaptive_rd_thresh * RD_THRESH_MAX_FACT)) { 4440 (cpi->sf.adaptive_rd_thresh * RD_THRESH_MAX_FACT)) {
4475 cpi->rd_thresh_freq_sub8x8[bsize][mode_index] = 4441 cpi->rd_thresh_freq_sub8x8[bsize][mode_index] =
4476 cpi->sf.adaptive_rd_thresh * RD_THRESH_MAX_FACT; 4442 cpi->sf.adaptive_rd_thresh * RD_THRESH_MAX_FACT;
4477 } 4443 }
4478 } 4444 }
4479 } 4445 }
4480 } 4446 }
4481 4447
4482 // macroblock modes 4448 // macroblock modes
4483 *mbmi = best_mbmode; 4449 *mbmi = best_mbmode;
4484 x->skip |= best_skip2; 4450 x->skip |= best_skip2;
4485 if (best_mbmode.ref_frame[0] == INTRA_FRAME) { 4451 if (!is_inter_block(&best_mbmode)) {
4486 for (i = 0; i < 4; i++) 4452 for (i = 0; i < 4; i++)
4487 xd->mi_8x8[0]->bmi[i].as_mode = best_bmodes[i].as_mode; 4453 xd->mi_8x8[0]->bmi[i].as_mode = best_bmodes[i].as_mode;
4488 } else { 4454 } else {
4489 for (i = 0; i < 4; ++i) 4455 for (i = 0; i < 4; ++i)
4490 vpx_memcpy(&xd->mi_8x8[0]->bmi[i], &best_bmodes[i], sizeof(b_mode_info)); 4456 vpx_memcpy(&xd->mi_8x8[0]->bmi[i], &best_bmodes[i], sizeof(b_mode_info));
4491 4457
4492 mbmi->mv[0].as_int = xd->mi_8x8[0]->bmi[3].as_mv[0].as_int; 4458 mbmi->mv[0].as_int = xd->mi_8x8[0]->bmi[3].as_mv[0].as_int;
4493 mbmi->mv[1].as_int = xd->mi_8x8[0]->bmi[3].as_mv[1].as_int; 4459 mbmi->mv[1].as_int = xd->mi_8x8[0]->bmi[3].as_mv[1].as_int;
4494 } 4460 }
4495 4461
4496 for (i = 0; i < NB_PREDICTION_TYPES; ++i) { 4462 for (i = 0; i < REFERENCE_MODES; ++i) {
4497 if (best_pred_rd[i] == INT64_MAX) 4463 if (best_pred_rd[i] == INT64_MAX)
4498 best_pred_diff[i] = INT_MIN; 4464 best_pred_diff[i] = INT_MIN;
4499 else 4465 else
4500 best_pred_diff[i] = best_rd - best_pred_rd[i]; 4466 best_pred_diff[i] = best_rd - best_pred_rd[i];
4501 } 4467 }
4502 4468
4503 if (!x->skip) { 4469 if (!x->skip) {
4504 for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; i++) { 4470 for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; i++) {
4505 if (best_filter_rd[i] == INT64_MAX) 4471 if (best_filter_rd[i] == INT64_MAX)
4506 best_filter_diff[i] = 0; 4472 best_filter_diff[i] = 0;
(...skipping 20 matching lines...) Expand all
4527 set_scale_factors(xd, mbmi->ref_frame[0], mbmi->ref_frame[1], 4493 set_scale_factors(xd, mbmi->ref_frame[0], mbmi->ref_frame[1],
4528 scale_factor); 4494 scale_factor);
4529 store_coding_context(x, ctx, best_mode_index, 4495 store_coding_context(x, ctx, best_mode_index,
4530 &mbmi->ref_mvs[mbmi->ref_frame[0]][0], 4496 &mbmi->ref_mvs[mbmi->ref_frame[0]][0],
4531 &mbmi->ref_mvs[mbmi->ref_frame[1] < 0 ? 0 : 4497 &mbmi->ref_mvs[mbmi->ref_frame[1] < 0 ? 0 :
4532 mbmi->ref_frame[1]][0], 4498 mbmi->ref_frame[1]][0],
4533 best_pred_diff, best_tx_diff, best_filter_diff); 4499 best_pred_diff, best_tx_diff, best_filter_diff);
4534 4500
4535 return best_rd; 4501 return best_rd;
4536 } 4502 }
OLDNEW
« no previous file with comments | « source/libvpx/vp9/encoder/vp9_rdopt.h ('k') | source/libvpx/vp9/encoder/vp9_sad_c.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698