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

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

Issue 11974002: libvpx: Pull from upstream (Closed) Base URL: svn://chrome-svn/chrome/trunk/deps/third_party/libvpx/
Patch Set: Created 7 years, 11 months 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
(...skipping 23 matching lines...) Expand all
34 #include "vp9/encoder/vp9_ratectrl.h" 34 #include "vp9/encoder/vp9_ratectrl.h"
35 #include "vpx_mem/vpx_mem.h" 35 #include "vpx_mem/vpx_mem.h"
36 #include "vp9/common/vp9_systemdependent.h" 36 #include "vp9/common/vp9_systemdependent.h"
37 #include "vp9/encoder/vp9_encodemv.h" 37 #include "vp9/encoder/vp9_encodemv.h"
38 38
39 #include "vp9/common/vp9_seg_common.h" 39 #include "vp9/common/vp9_seg_common.h"
40 #include "vp9/common/vp9_pred_common.h" 40 #include "vp9/common/vp9_pred_common.h"
41 #include "vp9/common/vp9_entropy.h" 41 #include "vp9/common/vp9_entropy.h"
42 #include "vp9_rtcd.h" 42 #include "vp9_rtcd.h"
43 #include "vp9/common/vp9_mvref_common.h" 43 #include "vp9/common/vp9_mvref_common.h"
44 #include "vp9/common/vp9_common.h"
44 45
45 #define MAXF(a,b) (((a) > (b)) ? (a) : (b)) 46 #define MAXF(a,b) (((a) > (b)) ? (a) : (b))
46 47
47 #define INVALID_MV 0x80008000 48 #define INVALID_MV 0x80008000
48 49
49 /* Factor to weigh the rate for switchable interp filters */ 50 /* Factor to weigh the rate for switchable interp filters */
50 #define SWITCHABLE_INTERP_RATE_FACTOR 1 51 #define SWITCHABLE_INTERP_RATE_FACTOR 1
51 52
52 static const int auto_speed_thresh[17] = { 53 static const int auto_speed_thresh[17] = {
53 1000, 54 1000,
54 200, 55 200,
55 150, 56 150,
56 130, 57 130,
57 150, 58 150,
58 125, 59 125,
59 120, 60 120,
60 115, 61 115,
61 115, 62 115,
62 115, 63 115,
63 115, 64 115,
64 115, 65 115,
65 115, 66 115,
66 115, 67 115,
67 115, 68 115,
68 115, 69 115,
69 105 70 105
70 }; 71 };
71 72
72 #if CONFIG_PRED_FILTER
73 const MODE_DEFINITION vp9_mode_order[MAX_MODES] = {
74 {ZEROMV, LAST_FRAME, NONE, 0},
75 {ZEROMV, LAST_FRAME, NONE, 1},
76 {DC_PRED, INTRA_FRAME, NONE, 0},
77
78 {NEARESTMV, LAST_FRAME, NONE, 0},
79 {NEARESTMV, LAST_FRAME, NONE, 1},
80 {NEARMV, LAST_FRAME, NONE, 0},
81 {NEARMV, LAST_FRAME, NONE, 1},
82
83 {ZEROMV, GOLDEN_FRAME, NONE, 0},
84 {ZEROMV, GOLDEN_FRAME, NONE, 1},
85 {NEARESTMV, GOLDEN_FRAME, NONE, 0},
86 {NEARESTMV, GOLDEN_FRAME, NONE, 1},
87
88 {ZEROMV, ALTREF_FRAME, NONE, 0},
89 {ZEROMV, ALTREF_FRAME, NONE, 1},
90 {NEARESTMV, ALTREF_FRAME, NONE, 0},
91 {NEARESTMV, ALTREF_FRAME, NONE, 1},
92
93 {NEARMV, GOLDEN_FRAME, NONE, 0},
94 {NEARMV, GOLDEN_FRAME, NONE, 1},
95 {NEARMV, ALTREF_FRAME, NONE, 0},
96 {NEARMV, ALTREF_FRAME, NONE, 1},
97
98 {V_PRED, INTRA_FRAME, NONE, 0},
99 {H_PRED, INTRA_FRAME, NONE, 0},
100 {D45_PRED, INTRA_FRAME, NONE, 0},
101 {D135_PRED, INTRA_FRAME, NONE, 0},
102 {D117_PRED, INTRA_FRAME, NONE, 0},
103 {D153_PRED, INTRA_FRAME, NONE, 0},
104 {D27_PRED, INTRA_FRAME, NONE, 0},
105 {D63_PRED, INTRA_FRAME, NONE, 0},
106
107 {TM_PRED, INTRA_FRAME, NONE, 0},
108
109 {NEWMV, LAST_FRAME, NONE, 0},
110 {NEWMV, LAST_FRAME, NONE, 1},
111 {NEWMV, GOLDEN_FRAME, NONE, 0},
112 {NEWMV, GOLDEN_FRAME, NONE, 1},
113 {NEWMV, ALTREF_FRAME, NONE, 0},
114 {NEWMV, ALTREF_FRAME, NONE, 1},
115
116 {SPLITMV, LAST_FRAME, NONE, 0},
117 {SPLITMV, GOLDEN_FRAME, NONE, 0},
118 {SPLITMV, ALTREF_FRAME, NONE, 0},
119
120 {B_PRED, INTRA_FRAME, NONE, 0},
121 {I8X8_PRED, INTRA_FRAME, NONE, 0},
122
123 /* compound prediction modes */
124 {ZEROMV, LAST_FRAME, GOLDEN_FRAME, 0},
125 {NEARESTMV, LAST_FRAME, GOLDEN_FRAME, 0},
126 {NEARMV, LAST_FRAME, GOLDEN_FRAME, 0},
127
128 {ZEROMV, ALTREF_FRAME, LAST_FRAME, 0},
129 {NEARESTMV, ALTREF_FRAME, LAST_FRAME, 0},
130 {NEARMV, ALTREF_FRAME, LAST_FRAME, 0},
131
132 {ZEROMV, GOLDEN_FRAME, ALTREF_FRAME, 0},
133 {NEARESTMV, GOLDEN_FRAME, ALTREF_FRAME, 0},
134 {NEARMV, GOLDEN_FRAME, ALTREF_FRAME, 0},
135
136 {NEWMV, LAST_FRAME, GOLDEN_FRAME, 0},
137 {NEWMV, ALTREF_FRAME, LAST_FRAME, 0},
138 {NEWMV, GOLDEN_FRAME, ALTREF_FRAME, 0},
139
140 {SPLITMV, LAST_FRAME, GOLDEN_FRAME, 0},
141 {SPLITMV, ALTREF_FRAME, LAST_FRAME, 0},
142 {SPLITMV, GOLDEN_FRAME, ALTREF_FRAME, 0},
143
144 #if CONFIG_COMP_INTERINTRA_PRED
145 /* compound inter-intra prediction */
146 {ZEROMV, LAST_FRAME, INTRA_FRAME, 0},
147 {NEARESTMV, LAST_FRAME, INTRA_FRAME, 0},
148 {NEARMV, LAST_FRAME, INTRA_FRAME, 0},
149 {NEWMV, LAST_FRAME, INTRA_FRAME, 0},
150
151 {ZEROMV, GOLDEN_FRAME, INTRA_FRAME, 0},
152 {NEARESTMV, GOLDEN_FRAME, INTRA_FRAME, 0},
153 {NEARMV, GOLDEN_FRAME, INTRA_FRAME, 0},
154 {NEWMV, GOLDEN_FRAME, INTRA_FRAME, 0},
155
156 {ZEROMV, ALTREF_FRAME, INTRA_FRAME, 0},
157 {NEARESTMV, ALTREF_FRAME, INTRA_FRAME, 0},
158 {NEARMV, ALTREF_FRAME, INTRA_FRAME, 0},
159 {NEWMV, ALTREF_FRAME, INTRA_FRAME, 0},
160 #endif
161 };
162 #else
163 const MODE_DEFINITION vp9_mode_order[MAX_MODES] = { 73 const MODE_DEFINITION vp9_mode_order[MAX_MODES] = {
164 {ZEROMV, LAST_FRAME, NONE}, 74 {ZEROMV, LAST_FRAME, NONE},
165 {DC_PRED, INTRA_FRAME, NONE}, 75 {DC_PRED, INTRA_FRAME, NONE},
166 76
167 {NEARESTMV, LAST_FRAME, NONE}, 77 {NEARESTMV, LAST_FRAME, NONE},
168 {NEARMV, LAST_FRAME, NONE}, 78 {NEARMV, LAST_FRAME, NONE},
169 79
170 {ZEROMV, GOLDEN_FRAME, NONE}, 80 {ZEROMV, GOLDEN_FRAME, NONE},
171 {NEARESTMV, GOLDEN_FRAME, NONE}, 81 {NEARESTMV, GOLDEN_FRAME, NONE},
172 82
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 {NEARESTMV, GOLDEN_FRAME, INTRA_FRAME}, 140 {NEARESTMV, GOLDEN_FRAME, INTRA_FRAME},
231 {NEARMV, GOLDEN_FRAME, INTRA_FRAME}, 141 {NEARMV, GOLDEN_FRAME, INTRA_FRAME},
232 {NEWMV, GOLDEN_FRAME, INTRA_FRAME}, 142 {NEWMV, GOLDEN_FRAME, INTRA_FRAME},
233 143
234 {ZEROMV, ALTREF_FRAME, INTRA_FRAME}, 144 {ZEROMV, ALTREF_FRAME, INTRA_FRAME},
235 {NEARESTMV, ALTREF_FRAME, INTRA_FRAME}, 145 {NEARESTMV, ALTREF_FRAME, INTRA_FRAME},
236 {NEARMV, ALTREF_FRAME, INTRA_FRAME}, 146 {NEARMV, ALTREF_FRAME, INTRA_FRAME},
237 {NEWMV, ALTREF_FRAME, INTRA_FRAME}, 147 {NEWMV, ALTREF_FRAME, INTRA_FRAME},
238 #endif 148 #endif
239 }; 149 };
240 #endif
241 150
242 static void fill_token_costs( 151 static void fill_token_costs(vp9_coeff_count *c,
243 unsigned int (*c)[COEF_BANDS][PREV_COEF_CONTEXTS][MAX_ENTROPY_TOKENS], 152 vp9_coeff_probs *p,
244 const vp9_prob(*p)[COEF_BANDS][PREV_COEF_CONTEXTS][ENTROPY_NODES], 153 int block_type_counts) {
245 int block_type_counts) {
246 int i, j, k; 154 int i, j, k;
247 155
248 for (i = 0; i < block_type_counts; i++) 156 for (i = 0; i < block_type_counts; i++)
249 for (j = 0; j < COEF_BANDS; j++) 157 for (j = 0; j < COEF_BANDS; j++)
250 for (k = 0; k < PREV_COEF_CONTEXTS; k++) { 158 for (k = 0; k < PREV_COEF_CONTEXTS; k++) {
251 if (k == 0 && ((j > 0 && i > 0) || (j > 1 && i == 0))) 159 if (k == 0 && ((j > 0 && i > 0) || (j > 1 && i == 0)))
252 vp9_cost_tokens_skip((int *)(c[i][j][k]), 160 vp9_cost_tokens_skip((int *)(c[i][j][k]),
253 p[i][j][k], 161 p[i][j][k],
254 vp9_coef_tree); 162 vp9_coef_tree);
255 else 163 else
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 if (cpi->sf.thresh_mult[i] < (INT_MAX / q)) { 271 if (cpi->sf.thresh_mult[i] < (INT_MAX / q)) {
364 cpi->rd_threshes[i] = cpi->sf.thresh_mult[i] * q; 272 cpi->rd_threshes[i] = cpi->sf.thresh_mult[i] * q;
365 } else { 273 } else {
366 cpi->rd_threshes[i] = INT_MAX; 274 cpi->rd_threshes[i] = INT_MAX;
367 } 275 }
368 276
369 cpi->rd_baseline_thresh[i] = cpi->rd_threshes[i]; 277 cpi->rd_baseline_thresh[i] = cpi->rd_threshes[i];
370 } 278 }
371 } 279 }
372 280
373 fill_token_costs( 281 fill_token_costs(cpi->mb.token_costs[TX_4X4],
374 cpi->mb.token_costs[TX_4X4], 282 cpi->common.fc.coef_probs_4x4, BLOCK_TYPES_4X4);
375 (const vp9_prob( *)[8][PREV_COEF_CONTEXTS][11]) cpi->common.fc.coef_probs, 283 fill_token_costs(cpi->mb.hybrid_token_costs[TX_4X4],
376 BLOCK_TYPES); 284 cpi->common.fc.hybrid_coef_probs_4x4, BLOCK_TYPES_4X4);
377 fill_token_costs(
378 cpi->mb.hybrid_token_costs[TX_4X4],
379 (const vp9_prob( *)[8][PREV_COEF_CONTEXTS][11])
380 cpi->common.fc.hybrid_coef_probs,
381 BLOCK_TYPES);
382 285
383 fill_token_costs( 286 fill_token_costs(cpi->mb.token_costs[TX_8X8],
384 cpi->mb.token_costs[TX_8X8], 287 cpi->common.fc.coef_probs_8x8, BLOCK_TYPES_8X8);
385 (const vp9_prob( *)[8][PREV_COEF_CONTEXTS][11]) cpi->common.fc.coef_probs_8x 8, 288 fill_token_costs(cpi->mb.hybrid_token_costs[TX_8X8],
386 BLOCK_TYPES_8X8); 289 cpi->common.fc.hybrid_coef_probs_8x8, BLOCK_TYPES_8X8);
387 fill_token_costs(
388 cpi->mb.hybrid_token_costs[TX_8X8],
389 (const vp9_prob( *)[8][PREV_COEF_CONTEXTS][11])
390 cpi->common.fc.hybrid_coef_probs_8x8,
391 BLOCK_TYPES_8X8);
392 290
393 fill_token_costs( 291 fill_token_costs(cpi->mb.token_costs[TX_16X16],
394 cpi->mb.token_costs[TX_16X16], 292 cpi->common.fc.coef_probs_16x16, BLOCK_TYPES_16X16);
395 (const vp9_prob(*)[8][PREV_COEF_CONTEXTS][11]) cpi->common.fc.coef_probs_16x 16, 293 fill_token_costs(cpi->mb.hybrid_token_costs[TX_16X16],
396 BLOCK_TYPES_16X16); 294 cpi->common.fc.hybrid_coef_probs_16x16, BLOCK_TYPES_16X16);
397 fill_token_costs( 295
398 cpi->mb.hybrid_token_costs[TX_16X16], 296 fill_token_costs(cpi->mb.token_costs[TX_32X32],
399 (const vp9_prob(*)[8][PREV_COEF_CONTEXTS][11]) 297 cpi->common.fc.coef_probs_32x32, BLOCK_TYPES_32X32);
400 cpi->common.fc.hybrid_coef_probs_16x16,
401 BLOCK_TYPES_16X16);
402 298
403 /*rough estimate for costing*/ 299 /*rough estimate for costing*/
404 cpi->common.kf_ymode_probs_index = cpi->common.base_qindex >> 4; 300 cpi->common.kf_ymode_probs_index = cpi->common.base_qindex >> 4;
405 vp9_init_mode_costs(cpi); 301 vp9_init_mode_costs(cpi);
406 302
407 if (cpi->common.frame_type != KEY_FRAME) 303 if (cpi->common.frame_type != KEY_FRAME) {
408 {
409 vp9_build_nmv_cost_table( 304 vp9_build_nmv_cost_table(
410 cpi->mb.nmvjointcost, 305 cpi->mb.nmvjointcost,
411 cpi->mb.e_mbd.allow_high_precision_mv ? 306 cpi->mb.e_mbd.allow_high_precision_mv ?
412 cpi->mb.nmvcost_hp : cpi->mb.nmvcost, 307 cpi->mb.nmvcost_hp : cpi->mb.nmvcost,
413 &cpi->common.fc.nmvc, 308 &cpi->common.fc.nmvc,
414 cpi->mb.e_mbd.allow_high_precision_mv, 1, 1); 309 cpi->mb.e_mbd.allow_high_precision_mv, 1, 1);
415 } 310 }
416 } 311 }
417 312
418 int vp9_block_error_c(short *coeff, short *dqcoeff, int block_size) { 313 int vp9_block_error_c(int16_t *coeff, int16_t *dqcoeff, int block_size) {
419 int i, error = 0; 314 int i, error = 0;
420 315
421 for (i = 0; i < block_size; i++) { 316 for (i = 0; i < block_size; i++) {
422 int this_diff = coeff[i] - dqcoeff[i]; 317 int this_diff = coeff[i] - dqcoeff[i];
423 error += this_diff * this_diff; 318 error += this_diff * this_diff;
424 } 319 }
425 320
426 return error; 321 return error;
427 } 322 }
428 323
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 be = &mb->block[i]; 369 be = &mb->block[i];
475 bd = &mb->e_mbd.block[i]; 370 bd = &mb->e_mbd.block[i];
476 371
477 error += vp9_block_error_c(be->coeff, bd->dqcoeff, 16); 372 error += vp9_block_error_c(be->coeff, bd->dqcoeff, 16);
478 } 373 }
479 374
480 return error; 375 return error;
481 } 376 }
482 377
483 int vp9_uvsse(MACROBLOCK *x) { 378 int vp9_uvsse(MACROBLOCK *x) {
484 unsigned char *uptr, *vptr; 379 uint8_t *uptr, *vptr;
485 unsigned char *upred_ptr = (*(x->block[16].base_src) + x->block[16].src); 380 uint8_t *upred_ptr = (*(x->block[16].base_src) + x->block[16].src);
486 unsigned char *vpred_ptr = (*(x->block[20].base_src) + x->block[20].src); 381 uint8_t *vpred_ptr = (*(x->block[20].base_src) + x->block[20].src);
487 int uv_stride = x->block[16].src_stride; 382 int uv_stride = x->block[16].src_stride;
488 383
489 unsigned int sse1 = 0; 384 unsigned int sse1 = 0;
490 unsigned int sse2 = 0; 385 unsigned int sse2 = 0;
491 int mv_row = x->e_mbd.mode_info_context->mbmi.mv[0].as_mv.row; 386 int mv_row = x->e_mbd.mode_info_context->mbmi.mv[0].as_mv.row;
492 int mv_col = x->e_mbd.mode_info_context->mbmi.mv[0].as_mv.col; 387 int mv_col = x->e_mbd.mode_info_context->mbmi.mv[0].as_mv.col;
493 int offset; 388 int offset;
494 int pre_stride = x->e_mbd.block[16].pre_stride; 389 int pre_stride = x->e_mbd.block[16].pre_stride;
495 390
496 if (mv_row < 0) 391 if (mv_row < 0)
(...skipping 21 matching lines...) Expand all
518 sse2 += sse1; 413 sse2 += sse1;
519 } else { 414 } else {
520 vp9_variance8x8(uptr, pre_stride, upred_ptr, uv_stride, &sse2); 415 vp9_variance8x8(uptr, pre_stride, upred_ptr, uv_stride, &sse2);
521 vp9_variance8x8(vptr, pre_stride, vpred_ptr, uv_stride, &sse1); 416 vp9_variance8x8(vptr, pre_stride, vpred_ptr, uv_stride, &sse1);
522 sse2 += sse1; 417 sse2 += sse1;
523 } 418 }
524 return sse2; 419 return sse2;
525 420
526 } 421 }
527 422
528 static int cost_coeffs_2x2(MACROBLOCK *mb, 423 #if CONFIG_NEWCOEFCONTEXT
529 BLOCKD *b, PLANE_TYPE type, 424 #define PT pn
530 ENTROPY_CONTEXT *a, ENTROPY_CONTEXT *l) { 425 #else
531 int c = (type == PLANE_TYPE_Y_NO_DC); /* start at coef 0, unless Y with Y2 */ 426 #define PT pt
532 int eob = b->eob; 427 #endif
533 int pt; /* surrounding block/prev coef predictor */ 428 static int cost_coeffs(MACROBLOCK *mb,
534 int cost = 0; 429 BLOCKD *b, PLANE_TYPE type,
535 short *qcoeff_ptr = b->qcoeff; 430 ENTROPY_CONTEXT *a,
431 ENTROPY_CONTEXT *l,
432 TX_SIZE tx_size) {
433 int pt;
434 const int eob = b->eob;
435 MACROBLOCKD *xd = &mb->e_mbd;
436 const int ib = (int)(b - xd->block);
437 int c = (type == PLANE_TYPE_Y_NO_DC) ? 1 : 0;
438 int cost = 0, seg_eob;
439 const int segment_id = xd->mode_info_context->mbmi.segment_id;
440 const int *scan, *band;
441 int16_t *qcoeff_ptr = b->qcoeff;
442 const TX_TYPE tx_type = (type == PLANE_TYPE_Y_WITH_DC) ?
443 get_tx_type(xd, b) : DCT_DCT;
444 #if CONFIG_NEWCOEFCONTEXT
445 const int *neighbors;
446 int pn;
447 #endif
536 448
537 VP9_COMBINEENTROPYCONTEXTS(pt, *a, *l); 449 ENTROPY_CONTEXT a_ec = *a, l_ec = *l;
538 assert(eob <= 4);
539
540 for (; c < eob; c++) {
541 int v = qcoeff_ptr[vp9_default_zig_zag1d[c]];
542 int t = vp9_dct_value_tokens_ptr[v].Token;
543 cost += mb->token_costs[TX_8X8][type][vp9_coef_bands[c]][pt][t];
544 cost += vp9_dct_value_cost_ptr[v];
545 pt = vp9_prev_token_class[t];
546 }
547
548 if (c < 4)
549 cost += mb->token_costs[TX_8X8][type][vp9_coef_bands[c]]
550 [pt] [DCT_EOB_TOKEN];
551 // is eob first coefficient;
552 pt = (c > !type);
553 *a = *l = pt;
554 return cost;
555 }
556
557 static int cost_coeffs(MACROBLOCK *mb, BLOCKD *b, PLANE_TYPE type,
558 ENTROPY_CONTEXT *a, ENTROPY_CONTEXT *l,
559 int tx_size) {
560 const int eob = b->eob;
561 int c = (type == PLANE_TYPE_Y_NO_DC); /* start at coef 0, unless Y with Y2 */
562 int cost = 0, default_eob, seg_eob;
563 int pt; /* surrounding block/prev coef predictor */
564 int const *scan, *band;
565 short *qcoeff_ptr = b->qcoeff;
566 MACROBLOCKD *xd = &mb->e_mbd;
567 MB_MODE_INFO *mbmi = &mb->e_mbd.mode_info_context->mbmi;
568 TX_TYPE tx_type = DCT_DCT;
569 int segment_id = mbmi->segment_id;
570 scan = vp9_default_zig_zag1d;
571 band = vp9_coef_bands;
572 default_eob = 16;
573 450
574 switch (tx_size) { 451 switch (tx_size) {
575 case TX_4X4: 452 case TX_4X4:
453 scan = vp9_default_zig_zag1d_4x4;
454 band = vp9_coef_bands_4x4;
455 seg_eob = 16;
576 if (type == PLANE_TYPE_Y_WITH_DC) { 456 if (type == PLANE_TYPE_Y_WITH_DC) {
577 tx_type = get_tx_type_4x4(xd, b); 457 if (tx_type == ADST_DCT) {
578 if (tx_type != DCT_DCT) { 458 scan = vp9_row_scan_4x4;
579 switch (tx_type) { 459 } else if (tx_type == DCT_ADST) {
580 case ADST_DCT: 460 scan = vp9_col_scan_4x4;
581 scan = vp9_row_scan;
582 break;
583
584 case DCT_ADST:
585 scan = vp9_col_scan;
586 break;
587
588 default:
589 scan = vp9_default_zig_zag1d;
590 break;
591 }
592 } 461 }
593 } 462 }
594
595 break; 463 break;
596 case TX_8X8: 464 case TX_8X8:
597 scan = vp9_default_zig_zag1d_8x8; 465 if (type == PLANE_TYPE_Y2) {
598 band = vp9_coef_bands_8x8; 466 scan = vp9_default_zig_zag1d_4x4;
599 default_eob = 64; 467 band = vp9_coef_bands_4x4;
600 if (type == PLANE_TYPE_Y_WITH_DC) { 468 seg_eob = 4;
601 BLOCKD *bb; 469 } else {
602 int ib = (int)(b - xd->block); 470 scan = vp9_default_zig_zag1d_8x8;
603 if (ib < 16) { 471 band = vp9_coef_bands_8x8;
604 ib = (ib & 8) + ((ib & 4) >> 1); 472 seg_eob = 64;
605 bb = xd->block + ib;
606 tx_type = get_tx_type_8x8(xd, bb);
607 }
608 } 473 }
609 break; 474 break;
610 case TX_16X16: 475 case TX_16X16:
611 scan = vp9_default_zig_zag1d_16x16; 476 scan = vp9_default_zig_zag1d_16x16;
612 band = vp9_coef_bands_16x16; 477 band = vp9_coef_bands_16x16;
613 default_eob = 256; 478 seg_eob = 256;
614 if (type == PLANE_TYPE_Y_WITH_DC) { 479 if (type == PLANE_TYPE_UV) {
615 tx_type = get_tx_type_16x16(xd, b); 480 const int uv_idx = ib - 16;
481 qcoeff_ptr = xd->sb_coeff_data.qcoeff + 1024 + 64 * uv_idx;
616 } 482 }
617 break; 483 break;
484 case TX_32X32:
485 scan = vp9_default_zig_zag1d_32x32;
486 band = vp9_coef_bands_32x32;
487 seg_eob = 1024;
488 qcoeff_ptr = xd->sb_coeff_data.qcoeff;
489 break;
618 default: 490 default:
491 abort();
619 break; 492 break;
620 } 493 }
621 if (vp9_segfeature_active(&mb->e_mbd, segment_id, SEG_LVL_EOB))
622 seg_eob = vp9_get_segdata(&mb->e_mbd, segment_id, SEG_LVL_EOB);
623 else
624 seg_eob = default_eob;
625 494
626 VP9_COMBINEENTROPYCONTEXTS(pt, *a, *l); 495 VP9_COMBINEENTROPYCONTEXTS(pt, a_ec, l_ec);
496 #if CONFIG_NEWCOEFCONTEXT
497 neighbors = vp9_get_coef_neighbors_handle(scan);
498 pn = pt;
499 #endif
500
501 if (vp9_segfeature_active(xd, segment_id, SEG_LVL_EOB))
502 seg_eob = vp9_get_segdata(xd, segment_id, SEG_LVL_EOB);
627 503
628 if (tx_type != DCT_DCT) { 504 if (tx_type != DCT_DCT) {
629 for (; c < eob; c++) { 505 for (; c < eob; c++) {
630 int v = qcoeff_ptr[scan[c]]; 506 int v = qcoeff_ptr[scan[c]];
631 int t = vp9_dct_value_tokens_ptr[v].Token; 507 int t = vp9_dct_value_tokens_ptr[v].Token;
632 cost += mb->hybrid_token_costs[tx_size][type][band[c]][pt][t]; 508 cost += mb->hybrid_token_costs[tx_size][type][band[c]][PT][t];
633 cost += vp9_dct_value_cost_ptr[v]; 509 cost += vp9_dct_value_cost_ptr[v];
634 pt = vp9_prev_token_class[t]; 510 pt = vp9_prev_token_class[t];
511 #if CONFIG_NEWCOEFCONTEXT
512 if (c < seg_eob - 1 && NEWCOEFCONTEXT_BAND_COND(band[c + 1]))
513 pn = vp9_get_coef_neighbor_context(
514 qcoeff_ptr, (type == PLANE_TYPE_Y_NO_DC), neighbors, scan[c + 1]);
515 else
516 pn = pt;
517 #endif
635 } 518 }
636 if (c < seg_eob) 519 if (c < seg_eob)
637 cost += mb->hybrid_token_costs[tx_size][type][band[c]] 520 cost += mb->hybrid_token_costs[tx_size][type][band[c]]
638 [pt][DCT_EOB_TOKEN]; 521 [PT][DCT_EOB_TOKEN];
639 } else { 522 } else {
640 for (; c < eob; c++) { 523 for (; c < eob; c++) {
641 int v = qcoeff_ptr[scan[c]]; 524 int v = qcoeff_ptr[scan[c]];
642 int t = vp9_dct_value_tokens_ptr[v].Token; 525 int t = vp9_dct_value_tokens_ptr[v].Token;
643 cost += mb->token_costs[tx_size][type][band[c]][pt][t]; 526 cost += mb->token_costs[tx_size][type][band[c]][pt][t];
644 cost += vp9_dct_value_cost_ptr[v]; 527 cost += vp9_dct_value_cost_ptr[v];
645 pt = vp9_prev_token_class[t]; 528 pt = vp9_prev_token_class[t];
529 #if CONFIG_NEWCOEFCONTEXT
530 if (c < seg_eob - 1 && NEWCOEFCONTEXT_BAND_COND(band[c + 1]))
531 pn = vp9_get_coef_neighbor_context(
532 qcoeff_ptr, (type == PLANE_TYPE_Y_NO_DC), neighbors, scan[c + 1]);
533 else
534 pn = pt;
535 #endif
646 } 536 }
647 if (c < seg_eob) 537 if (c < seg_eob)
648 cost += mb->token_costs[tx_size][type][band[c]] 538 cost += mb->token_costs[tx_size][type][band[c]]
649 [pt][DCT_EOB_TOKEN]; 539 [PT][DCT_EOB_TOKEN];
650 } 540 }
651 541
652 // is eob first coefficient; 542 // is eob first coefficient;
653 pt = (c > !type); 543 pt = (c > !type);
654 *a = *l = pt; 544 *a = *l = pt;
655 return cost; 545 return cost;
656 } 546 }
657 547
658 static int rdcost_mby_4x4(MACROBLOCK *mb, int has_2nd_order, int backup) { 548 static int rdcost_mby_4x4(MACROBLOCK *mb, int has_2nd_order, int backup) {
659 int cost = 0; 549 int cost = 0;
(...skipping 11 matching lines...) Expand all
671 tl = (ENTROPY_CONTEXT *)&t_left; 561 tl = (ENTROPY_CONTEXT *)&t_left;
672 } else { 562 } else {
673 ta = (ENTROPY_CONTEXT *)xd->above_context; 563 ta = (ENTROPY_CONTEXT *)xd->above_context;
674 tl = (ENTROPY_CONTEXT *)xd->left_context; 564 tl = (ENTROPY_CONTEXT *)xd->left_context;
675 } 565 }
676 566
677 for (b = 0; b < 16; b++) 567 for (b = 0; b < 16; b++)
678 cost += cost_coeffs(mb, xd->block + b, 568 cost += cost_coeffs(mb, xd->block + b,
679 (has_2nd_order ? 569 (has_2nd_order ?
680 PLANE_TYPE_Y_NO_DC : PLANE_TYPE_Y_WITH_DC), 570 PLANE_TYPE_Y_NO_DC : PLANE_TYPE_Y_WITH_DC),
681 ta + vp9_block2above[b], tl + vp9_block2left[b], 571 ta + vp9_block2above[TX_4X4][b],
572 tl + vp9_block2left[TX_4X4][b],
682 TX_4X4); 573 TX_4X4);
683 574
684 if (has_2nd_order) 575 if (has_2nd_order)
685 cost += cost_coeffs(mb, xd->block + 24, PLANE_TYPE_Y2, 576 cost += cost_coeffs(mb, xd->block + 24, PLANE_TYPE_Y2,
686 ta + vp9_block2above[24], tl + vp9_block2left[24], 577 ta + vp9_block2above[TX_4X4][24],
578 tl + vp9_block2left[TX_4X4][24],
687 TX_4X4); 579 TX_4X4);
688 580
689 return cost; 581 return cost;
690 } 582 }
691 583
692 static void macro_block_yrd_4x4(MACROBLOCK *mb, 584 static void macro_block_yrd_4x4(MACROBLOCK *mb,
693 int *Rate, 585 int *Rate,
694 int *Distortion, 586 int *Distortion,
695 int *skippable, int backup) { 587 int *skippable, int backup) {
696 MACROBLOCKD *const xd = &mb->e_mbd; 588 MACROBLOCKD *const xd = &mb->e_mbd;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
729 tl = (ENTROPY_CONTEXT *)&t_left; 621 tl = (ENTROPY_CONTEXT *)&t_left;
730 } else { 622 } else {
731 ta = (ENTROPY_CONTEXT *)mb->e_mbd.above_context; 623 ta = (ENTROPY_CONTEXT *)mb->e_mbd.above_context;
732 tl = (ENTROPY_CONTEXT *)mb->e_mbd.left_context; 624 tl = (ENTROPY_CONTEXT *)mb->e_mbd.left_context;
733 } 625 }
734 626
735 for (b = 0; b < 16; b += 4) 627 for (b = 0; b < 16; b += 4)
736 cost += cost_coeffs(mb, xd->block + b, 628 cost += cost_coeffs(mb, xd->block + b,
737 (has_2nd_order ? 629 (has_2nd_order ?
738 PLANE_TYPE_Y_NO_DC : PLANE_TYPE_Y_WITH_DC), 630 PLANE_TYPE_Y_NO_DC : PLANE_TYPE_Y_WITH_DC),
739 ta + vp9_block2above_8x8[b], tl + vp9_block2left_8x8[b], 631 ta + vp9_block2above[TX_8X8][b],
632 tl + vp9_block2left[TX_8X8][b],
740 TX_8X8); 633 TX_8X8);
741 634
742 if (has_2nd_order) 635 if (has_2nd_order)
743 cost += cost_coeffs_2x2(mb, xd->block + 24, PLANE_TYPE_Y2, 636 cost += cost_coeffs(mb, xd->block + 24, PLANE_TYPE_Y2,
744 ta + vp9_block2above[24], tl + vp9_block2left[24]); 637 ta + vp9_block2above[TX_8X8][24],
638 tl + vp9_block2left[TX_8X8][24],
639 TX_8X8);
745 return cost; 640 return cost;
746 } 641 }
747 642
748 static void macro_block_yrd_8x8(MACROBLOCK *mb, 643 static void macro_block_yrd_8x8(MACROBLOCK *mb,
749 int *Rate, 644 int *Rate,
750 int *Distortion, 645 int *Distortion,
751 int *skippable, int backup) { 646 int *skippable, int backup) {
752 MACROBLOCKD *const xd = &mb->e_mbd; 647 MACROBLOCKD *const xd = &mb->e_mbd;
753 BLOCK *const mb_y2 = mb->block + 24; 648 BLOCK *const mb_y2 = mb->block + 24;
754 BLOCKD *const x_y2 = xd->block + 24; 649 BLOCKD *const x_y2 = xd->block + 24;
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
806 701
807 d = vp9_mbblock_error(mb, 0); 702 d = vp9_mbblock_error(mb, 0);
808 703
809 *Distortion = (d >> 2); 704 *Distortion = (d >> 2);
810 // rate 705 // rate
811 *Rate = rdcost_mby_16x16(mb, backup); 706 *Rate = rdcost_mby_16x16(mb, backup);
812 *skippable = vp9_mby_is_skippable_16x16(&mb->e_mbd); 707 *skippable = vp9_mby_is_skippable_16x16(&mb->e_mbd);
813 } 708 }
814 709
815 static void choose_txfm_size_from_rd(VP9_COMP *cpi, MACROBLOCK *x, 710 static void choose_txfm_size_from_rd(VP9_COMP *cpi, MACROBLOCK *x,
816 int r[2][TX_SIZE_MAX], int *rate, 711 int (*r)[2], int *rate,
817 int d[TX_SIZE_MAX], int *distortion, 712 int *d, int *distortion,
818 int s[TX_SIZE_MAX], int *skip, 713 int *s, int *skip,
819 int64_t txfm_cache[NB_TXFM_MODES]) { 714 int64_t txfm_cache[NB_TXFM_MODES],
715 TX_SIZE max_txfm_size) {
820 VP9_COMMON *const cm = &cpi->common; 716 VP9_COMMON *const cm = &cpi->common;
821 MACROBLOCKD *const xd = &x->e_mbd; 717 MACROBLOCKD *const xd = &x->e_mbd;
822 MB_MODE_INFO *const mbmi = &xd->mode_info_context->mbmi; 718 MB_MODE_INFO *const mbmi = &xd->mode_info_context->mbmi;
823 vp9_prob skip_prob = cm->mb_no_coeff_skip ? 719 vp9_prob skip_prob = cm->mb_no_coeff_skip ?
824 vp9_get_pred_prob(cm, xd, PRED_MBSKIP) : 128; 720 vp9_get_pred_prob(cm, xd, PRED_MBSKIP) : 128;
825 int64_t rd[2][TX_SIZE_MAX]; 721 int64_t rd[TX_SIZE_MAX_SB][2];
826 int n; 722 int n, m;
827 723
828 r[1][TX_16X16] = r[0][TX_16X16] + vp9_cost_one(cm->prob_tx[0]) + 724 for (n = TX_4X4; n <= max_txfm_size; n++) {
829 vp9_cost_one(cm->prob_tx[1]); 725 r[n][1] = r[n][0];
830 r[1][TX_8X8] = r[0][TX_8X8] + vp9_cost_one(cm->prob_tx[0]) + 726 for (m = 0; m <= n - (n == max_txfm_size); m++) {
831 vp9_cost_zero(cm->prob_tx[1]); 727 if (m == n)
832 r[1][TX_4X4] = r[0][TX_4X4] + vp9_cost_zero(cm->prob_tx[0]); 728 r[n][1] += vp9_cost_zero(cm->prob_tx[m]);
729 else
730 r[n][1] += vp9_cost_one(cm->prob_tx[m]);
731 }
732 }
833 733
834 if (cm->mb_no_coeff_skip) { 734 if (cm->mb_no_coeff_skip) {
835 int s0, s1; 735 int s0, s1;
836 736
837 assert(skip_prob > 0); 737 assert(skip_prob > 0);
838 s0 = vp9_cost_bit(skip_prob, 0); 738 s0 = vp9_cost_bit(skip_prob, 0);
839 s1 = vp9_cost_bit(skip_prob, 1); 739 s1 = vp9_cost_bit(skip_prob, 1);
840 740
841 for (n = TX_4X4; n <= TX_16X16; n++) { 741 for (n = TX_4X4; n <= max_txfm_size; n++) {
842 if (s[n]) { 742 if (s[n]) {
843 rd[0][n] = rd[1][n] = RDCOST(x->rdmult, x->rddiv, s1, d[n]); 743 rd[n][0] = rd[n][1] = RDCOST(x->rdmult, x->rddiv, s1, d[n]);
844 } else { 744 } else {
845 rd[0][n] = RDCOST(x->rdmult, x->rddiv, r[0][n] + s0, d[n]); 745 rd[n][0] = RDCOST(x->rdmult, x->rddiv, r[n][0] + s0, d[n]);
846 rd[1][n] = RDCOST(x->rdmult, x->rddiv, r[1][n] + s0, d[n]); 746 rd[n][1] = RDCOST(x->rdmult, x->rddiv, r[n][1] + s0, d[n]);
847 } 747 }
848 } 748 }
849 } else { 749 } else {
850 for (n = TX_4X4; n <= TX_16X16; n++) { 750 for (n = TX_4X4; n <= max_txfm_size; n++) {
851 rd[0][n] = RDCOST(x->rdmult, x->rddiv, r[0][n], d[n]); 751 rd[n][0] = RDCOST(x->rdmult, x->rddiv, r[n][0], d[n]);
852 rd[1][n] = RDCOST(x->rdmult, x->rddiv, r[1][n], d[n]); 752 rd[n][1] = RDCOST(x->rdmult, x->rddiv, r[n][1], d[n]);
853 } 753 }
854 } 754 }
855 755
856 if ( cm->txfm_mode == ALLOW_16X16 || 756 if (max_txfm_size == TX_32X32 &&
857 (cm->txfm_mode == TX_MODE_SELECT && 757 (cm->txfm_mode == ALLOW_32X32 ||
858 rd[1][TX_16X16] < rd[1][TX_8X8] && rd[1][TX_16X16] < rd[1][TX_4X4])) { 758 (cm->txfm_mode == TX_MODE_SELECT &&
759 rd[TX_32X32][1] < rd[TX_16X16][1] && rd[TX_32X32][1] < rd[TX_8X8][1] &&
760 rd[TX_32X32][1] < rd[TX_4X4][1]))) {
761 mbmi->txfm_size = TX_32X32;
762 } else if ( cm->txfm_mode == ALLOW_16X16 ||
763 (max_txfm_size == TX_16X16 && cm->txfm_mode == ALLOW_32X32) ||
764 (cm->txfm_mode == TX_MODE_SELECT &&
765 rd[TX_16X16][1] < rd[TX_8X8][1] &&
766 rd[TX_16X16][1] < rd[TX_4X4][1])) {
859 mbmi->txfm_size = TX_16X16; 767 mbmi->txfm_size = TX_16X16;
860 } else if (cm->txfm_mode == ALLOW_8X8 || 768 } else if (cm->txfm_mode == ALLOW_8X8 ||
861 (cm->txfm_mode == TX_MODE_SELECT && rd[1][TX_8X8] < rd[1][TX_4X4])) { 769 (cm->txfm_mode == TX_MODE_SELECT && rd[TX_8X8][1] < rd[TX_4X4][1])) {
862 mbmi->txfm_size = TX_8X8; 770 mbmi->txfm_size = TX_8X8;
863 } else { 771 } else {
864 assert(cm->txfm_mode == ONLY_4X4 || 772 assert(cm->txfm_mode == ONLY_4X4 || cm->txfm_mode == TX_MODE_SELECT);
865 (cm->txfm_mode == TX_MODE_SELECT && rd[1][TX_4X4] <= rd[1][TX_8X8]));
866 mbmi->txfm_size = TX_4X4; 773 mbmi->txfm_size = TX_4X4;
867 } 774 }
868 775
869 *distortion = d[mbmi->txfm_size]; 776 *distortion = d[mbmi->txfm_size];
870 *rate = r[cm->txfm_mode == TX_MODE_SELECT][mbmi->txfm_size]; 777 *rate = r[mbmi->txfm_size][cm->txfm_mode == TX_MODE_SELECT];
871 *skip = s[mbmi->txfm_size]; 778 *skip = s[mbmi->txfm_size];
872 779
873 txfm_cache[ONLY_4X4] = rd[0][TX_4X4]; 780 txfm_cache[ONLY_4X4] = rd[TX_4X4][0];
874 txfm_cache[ALLOW_8X8] = rd[0][TX_8X8]; 781 txfm_cache[ALLOW_8X8] = rd[TX_8X8][0];
875 txfm_cache[ALLOW_16X16] = rd[0][TX_16X16]; 782 txfm_cache[ALLOW_16X16] = rd[TX_16X16][0];
876 if (rd[1][TX_16X16] < rd[1][TX_8X8] && rd[1][TX_16X16] < rd[1][TX_4X4]) 783 txfm_cache[ALLOW_32X32] = rd[max_txfm_size][0];
877 txfm_cache[TX_MODE_SELECT] = rd[1][TX_16X16]; 784 if (max_txfm_size == TX_32X32 &&
785 rd[TX_32X32][1] < rd[TX_16X16][1] && rd[TX_32X32][1] < rd[TX_8X8][1] &&
786 rd[TX_32X32][1] < rd[TX_4X4][1])
787 txfm_cache[TX_MODE_SELECT] = rd[TX_32X32][1];
788 else if (rd[TX_16X16][1] < rd[TX_8X8][1] && rd[TX_16X16][1] < rd[TX_4X4][1])
789 txfm_cache[TX_MODE_SELECT] = rd[TX_16X16][1];
878 else 790 else
879 txfm_cache[TX_MODE_SELECT] = rd[1][TX_4X4] < rd[1][TX_8X8] ? 791 txfm_cache[TX_MODE_SELECT] = rd[TX_4X4][1] < rd[TX_8X8][1] ?
880 rd[1][TX_4X4] : rd[1][TX_8X8]; 792 rd[TX_4X4][1] : rd[TX_8X8][1];
881 } 793 }
882 794
883 static void macro_block_yrd(VP9_COMP *cpi, MACROBLOCK *x, int *rate, 795 static void macro_block_yrd(VP9_COMP *cpi, MACROBLOCK *x, int *rate,
884 int *distortion, int *skippable, 796 int *distortion, int *skippable,
885 int64_t txfm_cache[NB_TXFM_MODES]) { 797 int64_t txfm_cache[NB_TXFM_MODES]) {
886 MACROBLOCKD *const xd = &x->e_mbd; 798 MACROBLOCKD *const xd = &x->e_mbd;
887 int r[2][TX_SIZE_MAX], d[TX_SIZE_MAX], s[TX_SIZE_MAX]; 799 int r[TX_SIZE_MAX_MB][2], d[TX_SIZE_MAX_MB], s[TX_SIZE_MAX_MB];
888 800
889 vp9_subtract_mby(x->src_diff, *(x->block[0].base_src), xd->predictor, 801 vp9_subtract_mby(x->src_diff, *(x->block[0].base_src), xd->predictor,
890 x->block[0].src_stride); 802 x->block[0].src_stride);
891 803
892 macro_block_yrd_16x16(x, &r[0][TX_16X16], &d[TX_16X16], 804 macro_block_yrd_16x16(x, &r[TX_16X16][0], &d[TX_16X16], &s[TX_16X16], 1);
893 &s[TX_16X16], 1); 805 macro_block_yrd_8x8(x, &r[TX_8X8][0], &d[TX_8X8], &s[TX_8X8], 1);
894 macro_block_yrd_8x8(x, &r[0][TX_8X8], &d[TX_8X8], &s[TX_8X8], 1); 806 macro_block_yrd_4x4(x, &r[TX_4X4][0], &d[TX_4X4], &s[TX_4X4], 1);
895 macro_block_yrd_4x4(x, &r[0][TX_4X4], &d[TX_4X4], &s[TX_4X4], 1);
896 807
897 choose_txfm_size_from_rd(cpi, x, r, rate, d, distortion, s, skippable, 808 choose_txfm_size_from_rd(cpi, x, r, rate, d, distortion, s, skippable,
898 txfm_cache); 809 txfm_cache, TX_16X16);
899 } 810 }
900 811
901 static void copy_predictor(unsigned char *dst, const unsigned char *predictor) { 812 static void copy_predictor(uint8_t *dst, const uint8_t *predictor) {
902 const unsigned int *p = (const unsigned int *)predictor; 813 const unsigned int *p = (const unsigned int *)predictor;
903 unsigned int *d = (unsigned int *)dst; 814 unsigned int *d = (unsigned int *)dst;
904 d[0] = p[0]; 815 d[0] = p[0];
905 d[4] = p[4]; 816 d[4] = p[4];
906 d[8] = p[8]; 817 d[8] = p[8];
907 d[12] = p[12]; 818 d[12] = p[12];
908 } 819 }
909 820
910 #if CONFIG_SUPERBLOCKS 821 static int rdcost_sby_32x32(MACROBLOCK *x, int backup) {
822 MACROBLOCKD * const xd = &x->e_mbd;
823 ENTROPY_CONTEXT_PLANES t_above, t_left;
824 ENTROPY_CONTEXT *ta, *tl;
825
826 if (backup) {
827 ta = (ENTROPY_CONTEXT *) &t_above,
828 tl = (ENTROPY_CONTEXT *) &t_left;
829
830 vpx_memcpy(&t_above, xd->above_context, sizeof(ENTROPY_CONTEXT_PLANES));
831 vpx_memcpy(&t_left, xd->left_context, sizeof(ENTROPY_CONTEXT_PLANES));
832 } else {
833 ta = (ENTROPY_CONTEXT *) xd->above_context;
834 tl = (ENTROPY_CONTEXT *) xd->left_context;
835 }
836
837 return cost_coeffs(x, xd->block, PLANE_TYPE_Y_WITH_DC, ta, tl, TX_32X32);
838 }
839
840 static int vp9_sb_block_error_c(int16_t *coeff, int16_t *dqcoeff,
841 int block_size) {
842 int i;
843 int64_t error = 0;
844
845 for (i = 0; i < block_size; i++) {
846 unsigned int this_diff = coeff[i] - dqcoeff[i];
847 error += this_diff * this_diff;
848 }
849
850 return error > INT_MAX ? INT_MAX : error;
851 }
852
853 #define DEBUG_ERROR 0
854 static void super_block_yrd_32x32(MACROBLOCK *x,
855 int *rate, int *distortion, int *skippable,
856 int backup) {
857 SUPERBLOCK * const x_sb = &x->sb_coeff_data;
858 MACROBLOCKD * const xd = &x->e_mbd;
859 SUPERBLOCKD * const xd_sb = &xd->sb_coeff_data;
860 #if DEBUG_ERROR || CONFIG_DWTDCTHYBRID
861 int16_t out[1024];
862 #endif
863
864 vp9_transform_sby_32x32(x);
865 vp9_quantize_sby_32x32(x);
866 #if DEBUG_ERROR || CONFIG_DWTDCTHYBRID
867 vp9_short_idct32x32(xd_sb->dqcoeff, out, 64);
868 #endif
869
870 #if !CONFIG_DWTDCTHYBRID
871 *distortion = vp9_sb_block_error_c(x_sb->coeff, xd_sb->dqcoeff, 1024);
872 #else
873 *distortion = vp9_block_error_c(x_sb->src_diff, out, 1024) << 4;
874 #endif
875 #if DEBUG_ERROR
876 printf("IDCT/FDCT error 32x32: %d (d: %d)\n",
877 vp9_block_error_c(x_sb->src_diff, out, 1024), *distortion);
878 #endif
879 *rate = rdcost_sby_32x32(x, backup);
880 *skippable = vp9_sby_is_skippable_32x32(&x->e_mbd);
881 }
882
911 static void super_block_yrd(VP9_COMP *cpi, 883 static void super_block_yrd(VP9_COMP *cpi,
912 MACROBLOCK *x, int *rate, int *distortion, 884 MACROBLOCK *x, int *rate, int *distortion,
913 int *skip, 885 int *skip,
914 int64_t txfm_cache[NB_TXFM_MODES]) { 886 int64_t txfm_cache[NB_TXFM_MODES]) {
915 MACROBLOCKD *const xd = &x->e_mbd; 887 MACROBLOCKD *const xd = &x->e_mbd;
916 int r[2][TX_SIZE_MAX], d[TX_SIZE_MAX], s[TX_SIZE_MAX], n; 888 int r[TX_SIZE_MAX_SB][2], d[TX_SIZE_MAX_SB], s[TX_SIZE_MAX_SB], n;
917 const uint8_t *src = x->src.y_buffer, *dst = xd->dst.y_buffer; 889 const uint8_t *src = x->src.y_buffer, *dst = xd->dst.y_buffer;
918 int src_y_stride = x->src.y_stride, dst_y_stride = xd->dst.y_stride; 890 int src_y_stride = x->src.y_stride, dst_y_stride = xd->dst.y_stride;
919 ENTROPY_CONTEXT_PLANES t_above[3][2], *orig_above = xd->above_context; 891 ENTROPY_CONTEXT_PLANES t_above[TX_SIZE_MAX_MB][2],
920 ENTROPY_CONTEXT_PLANES t_left[3][2], *orig_left = xd->left_context; 892 *orig_above = xd->above_context;
893 ENTROPY_CONTEXT_PLANES t_left[TX_SIZE_MAX_MB][2],
894 *orig_left = xd->left_context;
921 895
922 for (n = TX_4X4; n <= TX_16X16; n++) { 896 for (n = TX_4X4; n < TX_SIZE_MAX_MB; n++) {
923 vpx_memcpy(t_above[n], xd->above_context, sizeof(t_above[n])); 897 vpx_memcpy(t_above[n], xd->above_context, sizeof(t_above[n]));
924 vpx_memcpy(t_left[n], xd->left_context, sizeof(t_left[n])); 898 vpx_memcpy(t_left[n], xd->left_context, sizeof(t_left[n]));
925 r[0][n] = 0; 899 r[n][0] = 0;
926 d[n] = 0; 900 d[n] = 0;
927 s[n] = 1; 901 s[n] = 1;
928 } 902 }
929 903
904 vp9_subtract_sby_s_c(x->sb_coeff_data.src_diff, src, src_y_stride,
905 dst, dst_y_stride);
906 super_block_yrd_32x32(x, &r[TX_32X32][0], &d[TX_32X32], &s[TX_32X32], 1);
907
908 #if DEBUG_ERROR
909 int err[3] = { 0, 0, 0 };
910 #endif
930 for (n = 0; n < 4; n++) { 911 for (n = 0; n < 4; n++) {
931 int x_idx = n & 1, y_idx = n >> 1; 912 int x_idx = n & 1, y_idx = n >> 1;
932 int r_tmp, d_tmp, s_tmp; 913 int r_tmp, d_tmp, s_tmp;
933 914
934 vp9_subtract_mby_s_c(x->src_diff, 915 vp9_subtract_mby_s_c(x->src_diff,
935 src + x_idx * 16 + y_idx * 16 * src_y_stride, 916 src + x_idx * 16 + y_idx * 16 * src_y_stride,
936 src_y_stride, 917 src_y_stride,
937 dst + x_idx * 16 + y_idx * 16 * dst_y_stride, 918 dst + x_idx * 16 + y_idx * 16 * dst_y_stride,
938 dst_y_stride); 919 dst_y_stride);
939 920
940 xd->above_context = &t_above[TX_16X16][x_idx]; 921 xd->above_context = &t_above[TX_16X16][x_idx];
941 xd->left_context = &t_left[TX_16X16][y_idx]; 922 xd->left_context = &t_left[TX_16X16][y_idx];
942 macro_block_yrd_16x16(x, &r_tmp, &d_tmp, &s_tmp, 0); 923 macro_block_yrd_16x16(x, &r_tmp, &d_tmp, &s_tmp, 0);
943 d[TX_16X16] += d_tmp; 924 d[TX_16X16] += d_tmp;
944 r[0][TX_16X16] += r_tmp; 925 r[TX_16X16][0] += r_tmp;
945 s[TX_16X16] = s[TX_16X16] && s_tmp; 926 s[TX_16X16] = s[TX_16X16] && s_tmp;
927 #if DEBUG_ERROR
928 vp9_inverse_transform_mby_16x16(xd);
929 err[2] += vp9_block_error_c(xd->diff, x->src_diff, 256);
930 #endif
946 931
947 xd->above_context = &t_above[TX_4X4][x_idx]; 932 xd->above_context = &t_above[TX_4X4][x_idx];
948 xd->left_context = &t_left[TX_4X4][y_idx]; 933 xd->left_context = &t_left[TX_4X4][y_idx];
949 macro_block_yrd_4x4(x, &r_tmp, &d_tmp, &s_tmp, 0); 934 macro_block_yrd_4x4(x, &r_tmp, &d_tmp, &s_tmp, 0);
950 d[TX_4X4] += d_tmp; 935 d[TX_4X4] += d_tmp;
951 r[0][TX_4X4] += r_tmp; 936 r[TX_4X4][0] += r_tmp;
952 s[TX_4X4] = s[TX_4X4] && s_tmp; 937 s[TX_4X4] = s[TX_4X4] && s_tmp;
938 #if DEBUG_ERROR
939 vp9_inverse_transform_mby_4x4(xd);
940 err[0] += vp9_block_error_c(xd->diff, x->src_diff, 256);
941 #endif
953 942
954 xd->above_context = &t_above[TX_8X8][x_idx]; 943 xd->above_context = &t_above[TX_8X8][x_idx];
955 xd->left_context = &t_left[TX_8X8][y_idx]; 944 xd->left_context = &t_left[TX_8X8][y_idx];
956 macro_block_yrd_8x8(x, &r_tmp, &d_tmp, &s_tmp, 0); 945 macro_block_yrd_8x8(x, &r_tmp, &d_tmp, &s_tmp, 0);
957 d[TX_8X8] += d_tmp; 946 d[TX_8X8] += d_tmp;
958 r[0][TX_8X8] += r_tmp; 947 r[TX_8X8][0] += r_tmp;
959 s[TX_8X8] = s[TX_8X8] && s_tmp; 948 s[TX_8X8] = s[TX_8X8] && s_tmp;
949 #if DEBUG_ERROR
950 vp9_inverse_transform_mby_8x8(xd);
951 err[1] += vp9_block_error_c(xd->diff, x->src_diff, 256);
952 #endif
960 } 953 }
961 954 #if DEBUG_ERROR
962 choose_txfm_size_from_rd(cpi, x, r, rate, d, distortion, s, skip, txfm_cache); 955 printf("IDCT/FDCT error 16x16: %d (d: %d)\n", err[2], d[2]);
956 printf("IDCT/FDCT error 8x8: %d (d: %d)\n", err[1], d[1]);
957 printf("IDCT/FDCT error 4x4: %d (d: %d)\n", err[0], d[0]);
958 #endif
959 choose_txfm_size_from_rd(cpi, x, r, rate, d, distortion, s, skip, txfm_cache,
960 TX_SIZE_MAX_SB - 1);
963 961
964 xd->above_context = orig_above; 962 xd->above_context = orig_above;
965 xd->left_context = orig_left; 963 xd->left_context = orig_left;
966 } 964 }
965
966 static void super_block_64_yrd(VP9_COMP *cpi,
967 MACROBLOCK *x, int *rate, int *distortion,
968 int *skip,
969 int64_t txfm_cache[NB_TXFM_MODES]) {
970 MACROBLOCKD *const xd = &x->e_mbd;
971 int r[TX_SIZE_MAX_SB][2], d[TX_SIZE_MAX_SB], s[TX_SIZE_MAX_SB], n;
972 const uint8_t *src = x->src.y_buffer, *dst = xd->dst.y_buffer;
973 int src_y_stride = x->src.y_stride, dst_y_stride = xd->dst.y_stride;
974 ENTROPY_CONTEXT_PLANES t_above[TX_SIZE_MAX_SB][4],
975 *orig_above = xd->above_context;
976 ENTROPY_CONTEXT_PLANES t_left[TX_SIZE_MAX_SB][4],
977 *orig_left = xd->left_context;
978
979 for (n = TX_4X4; n < TX_SIZE_MAX_SB; n++) {
980 vpx_memcpy(t_above[n], xd->above_context, sizeof(t_above[n]));
981 vpx_memcpy(t_left[n], xd->left_context, sizeof(t_left[n]));
982 r[n][0] = 0;
983 d[n] = 0;
984 s[n] = 1;
985 }
986
987 for (n = 0; n < 4; n++) {
988 int x_idx = n & 1, y_idx = n >> 1;
989 int r_tmp, d_tmp, s_tmp;
990
991 xd->above_context = &t_above[TX_32X32][x_idx << 1];
992 xd->left_context = &t_left[TX_32X32][y_idx << 1];
993 vp9_subtract_sby_s_c(x->sb_coeff_data.src_diff,
994 src + 32 * x_idx + 32 * y_idx * src_y_stride,
995 src_y_stride,
996 dst + 32 * x_idx + 32 * y_idx * dst_y_stride,
997 dst_y_stride);
998 super_block_yrd_32x32(x, &r_tmp, &d_tmp, &s_tmp, 0);
999 r[TX_32X32][0] += r_tmp;
1000 d[TX_32X32] += d_tmp;
1001 s[TX_32X32] = s[TX_32X32] && s_tmp;
1002 }
1003
1004 #if DEBUG_ERROR
1005 int err[3] = { 0, 0, 0 };
1006 #endif
1007 for (n = 0; n < 16; n++) {
1008 int x_idx = n & 3, y_idx = n >> 2;
1009 int r_tmp, d_tmp, s_tmp;
1010
1011 vp9_subtract_mby_s_c(x->src_diff,
1012 src + x_idx * 16 + y_idx * 16 * src_y_stride,
1013 src_y_stride,
1014 dst + x_idx * 16 + y_idx * 16 * dst_y_stride,
1015 dst_y_stride);
1016
1017 xd->above_context = &t_above[TX_16X16][x_idx];
1018 xd->left_context = &t_left[TX_16X16][y_idx];
1019 macro_block_yrd_16x16(x, &r_tmp, &d_tmp, &s_tmp, 0);
1020 d[TX_16X16] += d_tmp;
1021 r[TX_16X16][0] += r_tmp;
1022 s[TX_16X16] = s[TX_16X16] && s_tmp;
1023 #if DEBUG_ERROR
1024 vp9_inverse_transform_mby_16x16(xd);
1025 err[2] += vp9_block_error_c(xd->diff, x->src_diff, 256);
967 #endif 1026 #endif
968 1027
969 static void copy_predictor_8x8(unsigned char *dst, const unsigned char *predicto r) { 1028 xd->above_context = &t_above[TX_4X4][x_idx];
1029 xd->left_context = &t_left[TX_4X4][y_idx];
1030 macro_block_yrd_4x4(x, &r_tmp, &d_tmp, &s_tmp, 0);
1031 d[TX_4X4] += d_tmp;
1032 r[TX_4X4][0] += r_tmp;
1033 s[TX_4X4] = s[TX_4X4] && s_tmp;
1034 #if DEBUG_ERROR
1035 vp9_inverse_transform_mby_4x4(xd);
1036 err[0] += vp9_block_error_c(xd->diff, x->src_diff, 256);
1037 #endif
1038
1039 xd->above_context = &t_above[TX_8X8][x_idx];
1040 xd->left_context = &t_left[TX_8X8][y_idx];
1041 macro_block_yrd_8x8(x, &r_tmp, &d_tmp, &s_tmp, 0);
1042 d[TX_8X8] += d_tmp;
1043 r[TX_8X8][0] += r_tmp;
1044 s[TX_8X8] = s[TX_8X8] && s_tmp;
1045 #if DEBUG_ERROR
1046 vp9_inverse_transform_mby_8x8(xd);
1047 err[1] += vp9_block_error_c(xd->diff, x->src_diff, 256);
1048 #endif
1049 }
1050 #if DEBUG_ERROR
1051 printf("IDCT/FDCT error 16x16: %d (d: %d)\n", err[2], d[2]);
1052 printf("IDCT/FDCT error 8x8: %d (d: %d)\n", err[1], d[1]);
1053 printf("IDCT/FDCT error 4x4: %d (d: %d)\n", err[0], d[0]);
1054 #endif
1055 choose_txfm_size_from_rd(cpi, x, r, rate, d, distortion, s, skip, txfm_cache,
1056 TX_SIZE_MAX_SB - 1);
1057
1058 xd->above_context = orig_above;
1059 xd->left_context = orig_left;
1060 }
1061
1062 static void copy_predictor_8x8(uint8_t *dst, const uint8_t *predictor) {
970 const unsigned int *p = (const unsigned int *)predictor; 1063 const unsigned int *p = (const unsigned int *)predictor;
971 unsigned int *d = (unsigned int *)dst; 1064 unsigned int *d = (unsigned int *)dst;
972 d[0] = p[0]; 1065 d[0] = p[0];
973 d[1] = p[1]; 1066 d[1] = p[1];
974 d[4] = p[4]; 1067 d[4] = p[4];
975 d[5] = p[5]; 1068 d[5] = p[5];
976 d[8] = p[8]; 1069 d[8] = p[8];
977 d[9] = p[9]; 1070 d[9] = p[9];
978 d[12] = p[12]; 1071 d[12] = p[12];
979 d[13] = p[13]; 1072 d[13] = p[13];
980 d[16] = p[16]; 1073 d[16] = p[16];
981 d[17] = p[17]; 1074 d[17] = p[17];
982 d[20] = p[20]; 1075 d[20] = p[20];
983 d[21] = p[21]; 1076 d[21] = p[21];
984 d[24] = p[24]; 1077 d[24] = p[24];
985 d[25] = p[25]; 1078 d[25] = p[25];
986 d[28] = p[28]; 1079 d[28] = p[28];
987 d[29] = p[29]; 1080 d[29] = p[29];
988 } 1081 }
989 1082
990 static int64_t rd_pick_intra4x4block(VP9_COMP *cpi, MACROBLOCK *x, BLOCK *be, 1083 static int64_t rd_pick_intra4x4block(VP9_COMP *cpi, MACROBLOCK *x, BLOCK *be,
991 BLOCKD *b, B_PREDICTION_MODE *best_mode, 1084 BLOCKD *b, B_PREDICTION_MODE *best_mode,
992 #if CONFIG_COMP_INTRA_PRED
993 B_PREDICTION_MODE *best_second_mode,
994 int allow_comp,
995 #endif
996 int *bmode_costs, 1085 int *bmode_costs,
997 ENTROPY_CONTEXT *a, ENTROPY_CONTEXT *l, 1086 ENTROPY_CONTEXT *a, ENTROPY_CONTEXT *l,
998 int *bestrate, int *bestratey, 1087 int *bestrate, int *bestratey,
999 int *bestdistortion) { 1088 int *bestdistortion) {
1000 B_PREDICTION_MODE mode; 1089 B_PREDICTION_MODE mode;
1001 MACROBLOCKD *xd = &x->e_mbd; 1090 MACROBLOCKD *xd = &x->e_mbd;
1002
1003 #if CONFIG_COMP_INTRA_PRED
1004 B_PREDICTION_MODE mode2;
1005 #endif
1006 int64_t best_rd = INT64_MAX; 1091 int64_t best_rd = INT64_MAX;
1007 int rate = 0; 1092 int rate = 0;
1008 int distortion; 1093 int distortion;
1009 1094
1010 ENTROPY_CONTEXT ta = *a, tempa = *a; 1095 ENTROPY_CONTEXT ta = *a, tempa = *a;
1011 ENTROPY_CONTEXT tl = *l, templ = *l; 1096 ENTROPY_CONTEXT tl = *l, templ = *l;
1012 TX_TYPE tx_type = DCT_DCT; 1097 TX_TYPE tx_type = DCT_DCT;
1013 TX_TYPE best_tx_type = DCT_DCT; 1098 TX_TYPE best_tx_type = DCT_DCT;
1014 /* 1099 /*
1015 * The predictor buffer is a 2d buffer with a stride of 16. Create 1100 * The predictor buffer is a 2d buffer with a stride of 16. Create
1016 * a temp buffer that meets the stride requirements, but we are only 1101 * a temp buffer that meets the stride requirements, but we are only
1017 * interested in the left 4x4 block 1102 * interested in the left 4x4 block
1018 * */ 1103 * */
1019 DECLARE_ALIGNED_ARRAY(16, unsigned char, best_predictor, 16 * 4); 1104 DECLARE_ALIGNED_ARRAY(16, uint8_t, best_predictor, 16 * 4);
1020 DECLARE_ALIGNED_ARRAY(16, short, best_dqcoeff, 16); 1105 DECLARE_ALIGNED_ARRAY(16, int16_t, best_dqcoeff, 16);
1021 1106
1022 #if CONFIG_NEWBINTRAMODES 1107 #if CONFIG_NEWBINTRAMODES
1023 b->bmi.as_mode.context = vp9_find_bpred_context(b); 1108 b->bmi.as_mode.context = vp9_find_bpred_context(b);
1024 #endif 1109 #endif
1025 for (mode = B_DC_PRED; mode < LEFT4X4; mode++) { 1110 for (mode = B_DC_PRED; mode < LEFT4X4; mode++) {
1026 #if CONFIG_COMP_INTRA_PRED 1111 int64_t this_rd;
1027 for (mode2 = (allow_comp ? 0 : (B_DC_PRED - 1)); 1112 int ratey;
1028 mode2 != (allow_comp ? (mode + 1) : 0); mode2++) {
1029 #endif
1030 int64_t this_rd;
1031 int ratey;
1032 1113
1033 #if CONFIG_NEWBINTRAMODES 1114 #if CONFIG_NEWBINTRAMODES
1034 if (xd->frame_type == KEY_FRAME) { 1115 if (xd->frame_type == KEY_FRAME) {
1035 if (mode == B_CONTEXT_PRED) continue; 1116 if (mode == B_CONTEXT_PRED) continue;
1036 #if CONFIG_COMP_INTRA_PRED 1117 } else {
1037 if (mode2 == B_CONTEXT_PRED) continue; 1118 if (mode >= B_CONTEXT_PRED - CONTEXT_PRED_REPLACEMENTS &&
1038 #endif 1119 mode < B_CONTEXT_PRED)
1039 } else { 1120 continue;
1040 if (mode >= B_CONTEXT_PRED - CONTEXT_PRED_REPLACEMENTS && 1121 }
1041 mode < B_CONTEXT_PRED)
1042 continue;
1043 #if CONFIG_COMP_INTRA_PRED
1044 if (mode2 >= B_CONTEXT_PRED - CONTEXT_PRED_REPLACEMENTS &&
1045 mode2 < B_CONTEXT_PRED)
1046 continue;
1047 #endif
1048 }
1049 #endif 1122 #endif
1050 1123
1051 b->bmi.as_mode.first = mode; 1124 b->bmi.as_mode.first = mode;
1052 #if CONFIG_NEWBINTRAMODES 1125 #if CONFIG_NEWBINTRAMODES
1053 rate = bmode_costs[ 1126 rate = bmode_costs[
1054 mode == B_CONTEXT_PRED ? mode - CONTEXT_PRED_REPLACEMENTS : mode]; 1127 mode == B_CONTEXT_PRED ? mode - CONTEXT_PRED_REPLACEMENTS : mode];
1055 #else 1128 #else
1056 rate = bmode_costs[mode]; 1129 rate = bmode_costs[mode];
1057 #endif 1130 #endif
1058 1131
1059 #if CONFIG_COMP_INTRA_PRED 1132 vp9_intra4x4_predict(b, mode, b->predictor);
1060 if (mode2 == (B_PREDICTION_MODE)(B_DC_PRED - 1)) { 1133 vp9_subtract_b(be, b, 16);
1061 #endif
1062 vp9_intra4x4_predict(b, mode, b->predictor);
1063 #if CONFIG_COMP_INTRA_PRED
1064 } else {
1065 vp9_comp_intra4x4_predict(b, mode, mode2, b->predictor);
1066 #if CONFIG_NEWBINTRAMODES
1067 rate += bmode_costs[
1068 mode2 == B_CONTEXT_PRED ?
1069 mode2 - CONTEXT_PRED_REPLACEMENTS : mode2];
1070 #else
1071 rate += bmode_costs[mode2];
1072 #endif
1073 }
1074 #endif
1075 vp9_subtract_b(be, b, 16);
1076 1134
1077 b->bmi.as_mode.first = mode; 1135 b->bmi.as_mode.first = mode;
1078 tx_type = get_tx_type_4x4(xd, b); 1136 tx_type = get_tx_type_4x4(xd, b);
1079 if (tx_type != DCT_DCT) { 1137 if (tx_type != DCT_DCT) {
1080 vp9_fht(be->src_diff, 32, be->coeff, tx_type, 4); 1138 vp9_fht(be->src_diff, 32, be->coeff, tx_type, 4);
1081 vp9_ht_quantize_b_4x4(be, b, tx_type); 1139 vp9_ht_quantize_b_4x4(be, b, tx_type);
1082 } else { 1140 } else {
1083 x->vp9_short_fdct4x4(be->src_diff, be->coeff, 32); 1141 x->vp9_short_fdct4x4(be->src_diff, be->coeff, 32);
1084 x->quantize_b_4x4(be, b); 1142 x->quantize_b_4x4(be, b);
1085 } 1143 }
1086 1144
1087 tempa = ta; 1145 tempa = ta;
1088 templ = tl; 1146 templ = tl;
1089 1147
1090 ratey = cost_coeffs(x, b, PLANE_TYPE_Y_WITH_DC, &tempa, &templ, TX_4X4); 1148 ratey = cost_coeffs(x, b, PLANE_TYPE_Y_WITH_DC, &tempa, &templ, TX_4X4);
1091 rate += ratey; 1149 rate += ratey;
1092 distortion = vp9_block_error(be->coeff, b->dqcoeff, 16) >> 2; 1150 distortion = vp9_block_error(be->coeff, b->dqcoeff, 16) >> 2;
1093 1151
1094 this_rd = RDCOST(x->rdmult, x->rddiv, rate, distortion); 1152 this_rd = RDCOST(x->rdmult, x->rddiv, rate, distortion);
1095 1153
1096 if (this_rd < best_rd) { 1154 if (this_rd < best_rd) {
1097 *bestrate = rate; 1155 *bestrate = rate;
1098 *bestratey = ratey; 1156 *bestratey = ratey;
1099 *bestdistortion = distortion; 1157 *bestdistortion = distortion;
1100 best_rd = this_rd; 1158 best_rd = this_rd;
1101 *best_mode = mode; 1159 *best_mode = mode;
1102 best_tx_type = tx_type; 1160 best_tx_type = tx_type;
1103 1161 *a = tempa;
1104 #if CONFIG_COMP_INTRA_PRED 1162 *l = templ;
1105 *best_second_mode = mode2; 1163 copy_predictor(best_predictor, b->predictor);
1106 #endif 1164 vpx_memcpy(best_dqcoeff, b->dqcoeff, 32);
1107 *a = tempa;
1108 *l = templ;
1109 copy_predictor(best_predictor, b->predictor);
1110 vpx_memcpy(best_dqcoeff, b->dqcoeff, 32);
1111 }
1112 #if CONFIG_COMP_INTRA_PRED
1113 } 1165 }
1114 #endif
1115 } 1166 }
1116 b->bmi.as_mode.first = (B_PREDICTION_MODE)(*best_mode); 1167 b->bmi.as_mode.first = (B_PREDICTION_MODE)(*best_mode);
1117 #if CONFIG_COMP_INTRA_PRED
1118 b->bmi.as_mode.second = (B_PREDICTION_MODE)(*best_second_mode);
1119 #endif
1120 1168
1121 // inverse transform 1169 // inverse transform
1122 if (best_tx_type != DCT_DCT) 1170 if (best_tx_type != DCT_DCT)
1123 vp9_ihtllm(best_dqcoeff, b->diff, 32, best_tx_type, 4, b->eob); 1171 vp9_ihtllm(best_dqcoeff, b->diff, 32, best_tx_type, 4, b->eob);
1124 else 1172 else
1125 xd->inv_xform4x4_x8(best_dqcoeff, b->diff, 32); 1173 xd->inv_xform4x4_x8(best_dqcoeff, b->diff, 32);
1126 1174
1127 vp9_recon_b(best_predictor, b->diff, *(b->base_dst) + b->dst, b->dst_stride); 1175 vp9_recon_b(best_predictor, b->diff, *(b->base_dst) + b->dst, b->dst_stride);
1128 1176
1129 return best_rd; 1177 return best_rd;
1130 } 1178 }
1131 1179
1132 static int64_t rd_pick_intra4x4mby_modes(VP9_COMP *cpi, MACROBLOCK *mb, int *Rat e, 1180 static int64_t rd_pick_intra4x4mby_modes(VP9_COMP *cpi, MACROBLOCK *mb,
1133 int *rate_y, int *Distortion, int64_t best_ rd, 1181 int *Rate, int *rate_y,
1134 #if CONFIG_COMP_INTRA_PRED 1182 int *Distortion, int64_t best_rd,
1135 int allow_comp, 1183 int update_contexts) {
1136 #endif
1137 int update_contexts) {
1138 int i; 1184 int i;
1139 MACROBLOCKD *const xd = &mb->e_mbd; 1185 MACROBLOCKD *const xd = &mb->e_mbd;
1140 int cost = mb->mbmode_cost [xd->frame_type] [B_PRED]; 1186 int cost = mb->mbmode_cost [xd->frame_type] [B_PRED];
1141 int distortion = 0; 1187 int distortion = 0;
1142 int tot_rate_y = 0; 1188 int tot_rate_y = 0;
1143 int64_t total_rd = 0; 1189 int64_t total_rd = 0;
1144 ENTROPY_CONTEXT_PLANES t_above, t_left; 1190 ENTROPY_CONTEXT_PLANES t_above, t_left;
1145 ENTROPY_CONTEXT *ta, *tl; 1191 ENTROPY_CONTEXT *ta, *tl;
1146 int *bmode_costs; 1192 int *bmode_costs;
1147 1193
(...skipping 10 matching lines...) Expand all
1158 tl = (ENTROPY_CONTEXT *)&t_left; 1204 tl = (ENTROPY_CONTEXT *)&t_left;
1159 } 1205 }
1160 1206
1161 xd->mode_info_context->mbmi.mode = B_PRED; 1207 xd->mode_info_context->mbmi.mode = B_PRED;
1162 bmode_costs = mb->inter_bmode_costs; 1208 bmode_costs = mb->inter_bmode_costs;
1163 1209
1164 for (i = 0; i < 16; i++) { 1210 for (i = 0; i < 16; i++) {
1165 MODE_INFO *const mic = xd->mode_info_context; 1211 MODE_INFO *const mic = xd->mode_info_context;
1166 const int mis = xd->mode_info_stride; 1212 const int mis = xd->mode_info_stride;
1167 B_PREDICTION_MODE UNINITIALIZED_IS_SAFE(best_mode); 1213 B_PREDICTION_MODE UNINITIALIZED_IS_SAFE(best_mode);
1168 #if CONFIG_COMP_INTRA_PRED
1169 B_PREDICTION_MODE UNINITIALIZED_IS_SAFE(best_second_mode);
1170 #endif
1171 int UNINITIALIZED_IS_SAFE(r), UNINITIALIZED_IS_SAFE(ry), UNINITIALIZED_IS_SA FE(d); 1214 int UNINITIALIZED_IS_SAFE(r), UNINITIALIZED_IS_SAFE(ry), UNINITIALIZED_IS_SA FE(d);
1172 1215
1173 if (xd->frame_type == KEY_FRAME) { 1216 if (xd->frame_type == KEY_FRAME) {
1174 const B_PREDICTION_MODE A = above_block_mode(mic, i, mis); 1217 const B_PREDICTION_MODE A = above_block_mode(mic, i, mis);
1175 const B_PREDICTION_MODE L = left_block_mode(mic, i); 1218 const B_PREDICTION_MODE L = left_block_mode(mic, i);
1176 1219
1177 bmode_costs = mb->bmode_costs[A][L]; 1220 bmode_costs = mb->bmode_costs[A][L];
1178 } 1221 }
1179 #if CONFIG_NEWBINTRAMODES 1222 #if CONFIG_NEWBINTRAMODES
1180 mic->bmi[i].as_mode.context = vp9_find_bpred_context(xd->block + i); 1223 mic->bmi[i].as_mode.context = vp9_find_bpred_context(xd->block + i);
1181 #endif 1224 #endif
1182 1225
1183 total_rd += rd_pick_intra4x4block( 1226 total_rd += rd_pick_intra4x4block(
1184 cpi, mb, mb->block + i, xd->block + i, &best_mode, 1227 cpi, mb, mb->block + i, xd->block + i, &best_mode,
1185 #if CONFIG_COMP_INTRA_PRED 1228 bmode_costs, ta + vp9_block2above[TX_4X4][i],
1186 & best_second_mode, allow_comp, 1229 tl + vp9_block2left[TX_4X4][i], &r, &ry, &d);
1187 #endif
1188 bmode_costs, ta + vp9_block2above[i],
1189 tl + vp9_block2left[i], &r, &ry, &d);
1190 1230
1191 cost += r; 1231 cost += r;
1192 distortion += d; 1232 distortion += d;
1193 tot_rate_y += ry; 1233 tot_rate_y += ry;
1194 1234
1195 mic->bmi[i].as_mode.first = best_mode; 1235 mic->bmi[i].as_mode.first = best_mode;
1196 #if CONFIG_COMP_INTRA_PRED
1197 mic->bmi[i].as_mode.second = best_second_mode;
1198 #endif
1199 1236
1200 #if 0 // CONFIG_NEWBINTRAMODES 1237 #if 0 // CONFIG_NEWBINTRAMODES
1201 printf("%d %d\n", mic->bmi[i].as_mode.first, mic->bmi[i].as_mode.context); 1238 printf("%d %d\n", mic->bmi[i].as_mode.first, mic->bmi[i].as_mode.context);
1202 #endif 1239 #endif
1203 1240
1204 if (total_rd >= best_rd) 1241 if (total_rd >= best_rd)
1205 break; 1242 break;
1206 } 1243 }
1207 1244
1208 if (total_rd >= best_rd) 1245 if (total_rd >= best_rd)
1209 return INT64_MAX; 1246 return INT64_MAX;
1210 1247
1211 #if CONFIG_COMP_INTRA_PRED
1212 cost += vp9_cost_bit(128, allow_comp);
1213 #endif
1214 *Rate = cost; 1248 *Rate = cost;
1215 *rate_y = tot_rate_y; 1249 *rate_y = tot_rate_y;
1216 *Distortion = distortion; 1250 *Distortion = distortion;
1217 1251
1218 return RDCOST(mb->rdmult, mb->rddiv, cost, distortion); 1252 return RDCOST(mb->rdmult, mb->rddiv, cost, distortion);
1219 } 1253 }
1220 1254
1221 #if CONFIG_SUPERBLOCKS
1222 static int64_t rd_pick_intra_sby_mode(VP9_COMP *cpi, 1255 static int64_t rd_pick_intra_sby_mode(VP9_COMP *cpi,
1223 MACROBLOCK *x, 1256 MACROBLOCK *x,
1224 int *rate, 1257 int *rate,
1225 int *rate_tokenonly, 1258 int *rate_tokenonly,
1226 int *distortion, 1259 int *distortion,
1227 int *skippable, 1260 int *skippable,
1228 int64_t txfm_cache[NB_TXFM_MODES]) { 1261 int64_t txfm_cache[NB_TXFM_MODES]) {
1229 MB_PREDICTION_MODE mode; 1262 MB_PREDICTION_MODE mode;
1230 MB_PREDICTION_MODE UNINITIALIZED_IS_SAFE(mode_selected); 1263 MB_PREDICTION_MODE UNINITIALIZED_IS_SAFE(mode_selected);
1231 int this_rate, this_rate_tokenonly; 1264 int this_rate, this_rate_tokenonly;
(...skipping 19 matching lines...) Expand all
1251 *rate_tokenonly = this_rate_tokenonly; 1284 *rate_tokenonly = this_rate_tokenonly;
1252 *distortion = this_distortion; 1285 *distortion = this_distortion;
1253 *skippable = s; 1286 *skippable = s;
1254 } 1287 }
1255 } 1288 }
1256 1289
1257 x->e_mbd.mode_info_context->mbmi.mode = mode_selected; 1290 x->e_mbd.mode_info_context->mbmi.mode = mode_selected;
1258 1291
1259 return best_rd; 1292 return best_rd;
1260 } 1293 }
1261 #endif 1294
1295 static int64_t rd_pick_intra_sb64y_mode(VP9_COMP *cpi,
1296 MACROBLOCK *x,
1297 int *rate,
1298 int *rate_tokenonly,
1299 int *distortion,
1300 int *skippable,
1301 int64_t txfm_cache[NB_TXFM_MODES]) {
1302 MB_PREDICTION_MODE mode;
1303 MB_PREDICTION_MODE UNINITIALIZED_IS_SAFE(mode_selected);
1304 int this_rate, this_rate_tokenonly;
1305 int this_distortion, s;
1306 int64_t best_rd = INT64_MAX, this_rd;
1307
1308 /* Y Search for 32x32 intra prediction mode */
1309 for (mode = DC_PRED; mode <= TM_PRED; mode++) {
1310 x->e_mbd.mode_info_context->mbmi.mode = mode;
1311 vp9_build_intra_predictors_sb64y_s(&x->e_mbd);
1312
1313 super_block_64_yrd(cpi, x, &this_rate_tokenonly,
1314 &this_distortion, &s, txfm_cache);
1315 this_rate = this_rate_tokenonly +
1316 x->mbmode_cost[x->e_mbd.frame_type]
1317 [x->e_mbd.mode_info_context->mbmi.mode];
1318 this_rd = RDCOST(x->rdmult, x->rddiv, this_rate, this_distortion);
1319
1320 if (this_rd < best_rd) {
1321 mode_selected = mode;
1322 best_rd = this_rd;
1323 *rate = this_rate;
1324 *rate_tokenonly = this_rate_tokenonly;
1325 *distortion = this_distortion;
1326 *skippable = s;
1327 }
1328 }
1329
1330 x->e_mbd.mode_info_context->mbmi.mode = mode_selected;
1331
1332 return best_rd;
1333 }
1262 1334
1263 static int64_t rd_pick_intra16x16mby_mode(VP9_COMP *cpi, 1335 static int64_t rd_pick_intra16x16mby_mode(VP9_COMP *cpi,
1264 MACROBLOCK *x, 1336 MACROBLOCK *x,
1265 int *Rate, 1337 int *Rate,
1266 int *rate_y, 1338 int *rate_y,
1267 int *Distortion, 1339 int *Distortion,
1268 int *skippable, 1340 int *skippable,
1269 int64_t txfm_cache[NB_TXFM_MODES]) { 1341 int64_t txfm_cache[NB_TXFM_MODES]) {
1270 MB_PREDICTION_MODE mode; 1342 MB_PREDICTION_MODE mode;
1271 TX_SIZE txfm_size; 1343 TX_SIZE txfm_size = 0;
1272 MB_PREDICTION_MODE UNINITIALIZED_IS_SAFE(mode_selected); 1344 MB_PREDICTION_MODE UNINITIALIZED_IS_SAFE(mode_selected);
1273 #if CONFIG_COMP_INTRA_PRED
1274 MB_PREDICTION_MODE mode2;
1275 MB_PREDICTION_MODE UNINITIALIZED_IS_SAFE(mode2_selected);
1276 #endif
1277 MACROBLOCKD *const xd = &x->e_mbd; 1345 MACROBLOCKD *const xd = &x->e_mbd;
1278 MB_MODE_INFO *const mbmi = &xd->mode_info_context->mbmi; 1346 MB_MODE_INFO *const mbmi = &xd->mode_info_context->mbmi;
1279 int rate, ratey; 1347 int rate, ratey;
1280 int distortion, skip; 1348 int distortion, skip;
1281 int64_t best_rd = INT64_MAX; 1349 int64_t best_rd = INT64_MAX;
1282 int64_t this_rd; 1350 int64_t this_rd;
1283 1351
1284 int i; 1352 int i;
1285 for (i = 0; i < NB_TXFM_MODES; i++) 1353 for (i = 0; i < NB_TXFM_MODES; i++)
1286 txfm_cache[i] = INT64_MAX; 1354 txfm_cache[i] = INT64_MAX;
1287 1355
1288 // Y Search for 16x16 intra prediction mode 1356 // Y Search for 16x16 intra prediction mode
1289 for (mode = DC_PRED; mode <= TM_PRED; mode++) { 1357 for (mode = DC_PRED; mode <= TM_PRED; mode++) {
1290 int64_t local_txfm_cache[NB_TXFM_MODES]; 1358 int64_t local_txfm_cache[NB_TXFM_MODES];
1291 1359
1292 mbmi->mode = mode; 1360 mbmi->mode = mode;
1293 1361
1294 #if CONFIG_COMP_INTRA_PRED 1362 vp9_build_intra_predictors_mby(xd);
1295 for (mode2 = DC_PRED - 1; mode2 != TM_PRED + 1; mode2++) { 1363
1296 mbmi->second_mode = mode2; 1364 macro_block_yrd(cpi, x, &ratey, &distortion, &skip, local_txfm_cache);
1297 if (mode2 == (MB_PREDICTION_MODE)(DC_PRED - 1)) { 1365
1298 #endif 1366 // FIXME add compoundmode cost
1299 vp9_build_intra_predictors_mby(xd); 1367 // FIXME add rate for mode2
1300 #if CONFIG_COMP_INTRA_PRED 1368 rate = ratey + x->mbmode_cost[xd->frame_type][mbmi->mode];
1301 } else { 1369
1302 continue; // i.e. disable for now 1370 this_rd = RDCOST(x->rdmult, x->rddiv, rate, distortion);
1303 vp9_build_comp_intra_predictors_mby(xd); 1371
1372 if (this_rd < best_rd) {
1373 mode_selected = mode;
1374 txfm_size = mbmi->txfm_size;
1375 best_rd = this_rd;
1376 *Rate = rate;
1377 *rate_y = ratey;
1378 *Distortion = distortion;
1379 *skippable = skip;
1380 }
1381
1382 for (i = 0; i < NB_TXFM_MODES; i++) {
1383 int64_t adj_rd = this_rd + local_txfm_cache[i] -
1384 local_txfm_cache[cpi->common.txfm_mode];
1385 if (adj_rd < txfm_cache[i]) {
1386 txfm_cache[i] = adj_rd;
1304 } 1387 }
1305 #endif
1306
1307 macro_block_yrd(cpi, x, &ratey, &distortion, &skip, local_txfm_cache);
1308
1309 // FIXME add compoundmode cost
1310 // FIXME add rate for mode2
1311 rate = ratey + x->mbmode_cost[xd->frame_type][mbmi->mode];
1312
1313 this_rd = RDCOST(x->rdmult, x->rddiv, rate, distortion);
1314
1315 if (this_rd < best_rd) {
1316 mode_selected = mode;
1317 txfm_size = mbmi->txfm_size;
1318 #if CONFIG_COMP_INTRA_PRED
1319 mode2_selected = mode2;
1320 #endif
1321 best_rd = this_rd;
1322 *Rate = rate;
1323 *rate_y = ratey;
1324 *Distortion = distortion;
1325 *skippable = skip;
1326 }
1327
1328 for (i = 0; i < NB_TXFM_MODES; i++) {
1329 int64_t adj_rd = this_rd + local_txfm_cache[i] -
1330 local_txfm_cache[cpi->common.txfm_mode];
1331 if (adj_rd < txfm_cache[i]) {
1332 txfm_cache[i] = adj_rd;
1333 }
1334 }
1335
1336 #if CONFIG_COMP_INTRA_PRED
1337 } 1388 }
1338 #endif
1339 } 1389 }
1340 1390
1341 mbmi->txfm_size = txfm_size; 1391 mbmi->txfm_size = txfm_size;
1342 mbmi->mode = mode_selected; 1392 mbmi->mode = mode_selected;
1343 1393
1344 #if CONFIG_COMP_INTRA_PRED
1345 mbmi->second_mode = mode2_selected;
1346 #endif
1347 return best_rd; 1394 return best_rd;
1348 } 1395 }
1349 1396
1350 1397
1351 static int64_t rd_pick_intra8x8block(VP9_COMP *cpi, MACROBLOCK *x, int ib, 1398 static int64_t rd_pick_intra8x8block(VP9_COMP *cpi, MACROBLOCK *x, int ib,
1352 B_PREDICTION_MODE *best_mode, 1399 B_PREDICTION_MODE *best_mode,
1353 #if CONFIG_COMP_INTRA_PRED
1354 B_PREDICTION_MODE *best_second_mode,
1355 #endif
1356 int *mode_costs, 1400 int *mode_costs,
1357 ENTROPY_CONTEXT *a, ENTROPY_CONTEXT *l, 1401 ENTROPY_CONTEXT *a, ENTROPY_CONTEXT *l,
1358 int *bestrate, int *bestratey, 1402 int *bestrate, int *bestratey,
1359 int *bestdistortion) { 1403 int *bestdistortion) {
1360 MB_PREDICTION_MODE mode; 1404 MB_PREDICTION_MODE mode;
1361 #if CONFIG_COMP_INTRA_PRED
1362 MB_PREDICTION_MODE mode2;
1363 #endif
1364 MACROBLOCKD *xd = &x->e_mbd; 1405 MACROBLOCKD *xd = &x->e_mbd;
1365 int64_t best_rd = INT64_MAX; 1406 int64_t best_rd = INT64_MAX;
1366 int distortion = 0, rate = 0; 1407 int distortion = 0, rate = 0;
1367 BLOCK *be = x->block + ib; 1408 BLOCK *be = x->block + ib;
1368 BLOCKD *b = xd->block + ib; 1409 BLOCKD *b = xd->block + ib;
1369 ENTROPY_CONTEXT ta0, ta1, besta0 = 0, besta1 = 0; 1410 ENTROPY_CONTEXT ta0, ta1, besta0 = 0, besta1 = 0;
1370 ENTROPY_CONTEXT tl0, tl1, bestl0 = 0, bestl1 = 0; 1411 ENTROPY_CONTEXT tl0, tl1, bestl0 = 0, bestl1 = 0;
1371 1412
1372 /* 1413 /*
1373 * The predictor buffer is a 2d buffer with a stride of 16. Create 1414 * The predictor buffer is a 2d buffer with a stride of 16. Create
1374 * a temp buffer that meets the stride requirements, but we are only 1415 * a temp buffer that meets the stride requirements, but we are only
1375 * interested in the left 8x8 block 1416 * interested in the left 8x8 block
1376 * */ 1417 * */
1377 DECLARE_ALIGNED_ARRAY(16, unsigned char, best_predictor, 16 * 8); 1418 DECLARE_ALIGNED_ARRAY(16, uint8_t, best_predictor, 16 * 8);
1378 DECLARE_ALIGNED_ARRAY(16, short, best_dqcoeff, 16 * 4); 1419 DECLARE_ALIGNED_ARRAY(16, int16_t, best_dqcoeff, 16 * 4);
1379 1420
1380 // perform transformation of dimension 8x8 1421 // perform transformation of dimension 8x8
1381 // note the input and output index mapping 1422 // note the input and output index mapping
1382 int idx = (ib & 0x02) ? (ib + 2) : ib; 1423 int idx = (ib & 0x02) ? (ib + 2) : ib;
1383 1424
1384 for (mode = DC_PRED; mode <= TM_PRED; mode++) { 1425 for (mode = DC_PRED; mode <= TM_PRED; mode++) {
1385 #if CONFIG_COMP_INTRA_PRED 1426 int64_t this_rd;
1386 for (mode2 = DC_PRED - 1; mode2 != TM_PRED + 1; mode2++) { 1427 int rate_t = 0;
1387 #endif
1388 int64_t this_rd;
1389 int rate_t = 0;
1390 1428
1391 // FIXME rate for compound mode and second intrapred mode 1429 // FIXME rate for compound mode and second intrapred mode
1392 rate = mode_costs[mode]; 1430 rate = mode_costs[mode];
1393 b->bmi.as_mode.first = mode; 1431 b->bmi.as_mode.first = mode;
1394 1432
1395 #if CONFIG_COMP_INTRA_PRED 1433 vp9_intra8x8_predict(b, mode, b->predictor);
1396 if (mode2 == (MB_PREDICTION_MODE)(DC_PRED - 1)) { 1434
1397 #endif 1435 vp9_subtract_4b_c(be, b, 16);
1398 vp9_intra8x8_predict(b, mode, b->predictor); 1436
1399 #if CONFIG_COMP_INTRA_PRED 1437 assert(get_2nd_order_usage(xd) == 0);
1400 } else { 1438 if (xd->mode_info_context->mbmi.txfm_size == TX_8X8) {
1401 continue; // i.e. disable for now 1439 TX_TYPE tx_type = get_tx_type_8x8(xd, b);
1402 vp9_comp_intra8x8_predict(b, mode, mode2, b->predictor); 1440 if (tx_type != DCT_DCT)
1441 vp9_fht(be->src_diff, 32, (x->block + idx)->coeff, tx_type, 8);
1442 else
1443 x->vp9_short_fdct8x8(be->src_diff, (x->block + idx)->coeff, 32);
1444 x->quantize_b_8x8(x->block + idx, xd->block + idx);
1445
1446 // compute quantization mse of 8x8 block
1447 distortion = vp9_block_error_c((x->block + idx)->coeff,
1448 (xd->block + idx)->dqcoeff, 64);
1449 ta0 = a[vp9_block2above[TX_8X8][idx]];
1450 tl0 = l[vp9_block2left[TX_8X8][idx]];
1451
1452 rate_t = cost_coeffs(x, xd->block + idx, PLANE_TYPE_Y_WITH_DC,
1453 &ta0, &tl0, TX_8X8);
1454
1455 rate += rate_t;
1456 ta1 = ta0;
1457 tl1 = tl0;
1458 } else {
1459 static const int iblock[4] = {0, 1, 4, 5};
1460 TX_TYPE tx_type;
1461 int i;
1462 ta0 = a[vp9_block2above[TX_4X4][ib]];
1463 ta1 = a[vp9_block2above[TX_4X4][ib + 1]];
1464 tl0 = l[vp9_block2left[TX_4X4][ib]];
1465 tl1 = l[vp9_block2left[TX_4X4][ib + 4]];
1466 distortion = 0;
1467 rate_t = 0;
1468 for (i = 0; i < 4; ++i) {
1469 b = &xd->block[ib + iblock[i]];
1470 be = &x->block[ib + iblock[i]];
1471 tx_type = get_tx_type_4x4(xd, b);
1472 if (tx_type != DCT_DCT) {
1473 vp9_fht_c(be->src_diff, 32, be->coeff, tx_type, 4);
1474 vp9_ht_quantize_b_4x4(be, b, tx_type);
1475 } else {
1476 x->vp9_short_fdct4x4(be->src_diff, be->coeff, 32);
1477 x->quantize_b_4x4(be, b);
1478 }
1479 distortion += vp9_block_error_c(be->coeff, b->dqcoeff, 16);
1480 rate_t += cost_coeffs(x, b, PLANE_TYPE_Y_WITH_DC,
1481 // i&1 ? &ta1 : &ta0, i&2 ? &tl1 : &tl0,
1482 &ta0, &tl0,
1483 TX_4X4);
1403 } 1484 }
1404 #endif 1485 rate += rate_t;
1486 }
1405 1487
1406 vp9_subtract_4b_c(be, b, 16); 1488 distortion >>= 2;
1407 1489 this_rd = RDCOST(x->rdmult, x->rddiv, rate, distortion);
1408 assert(get_2nd_order_usage(xd) == 0); 1490 if (this_rd < best_rd) {
1409 if (xd->mode_info_context->mbmi.txfm_size == TX_8X8) { 1491 *bestrate = rate;
1410 TX_TYPE tx_type = get_tx_type_8x8(xd, b); 1492 *bestratey = rate_t;
1411 if (tx_type != DCT_DCT) 1493 *bestdistortion = distortion;
1412 vp9_fht(be->src_diff, 32, (x->block + idx)->coeff, tx_type, 8); 1494 besta0 = ta0;
1413 else 1495 besta1 = ta1;
1414 x->vp9_short_fdct8x8(be->src_diff, (x->block + idx)->coeff, 32); 1496 bestl0 = tl0;
1415 x->quantize_b_8x8(x->block + idx, xd->block + idx); 1497 bestl1 = tl1;
1416 1498 best_rd = this_rd;
1417 // compute quantization mse of 8x8 block 1499 *best_mode = mode;
1418 distortion = vp9_block_error_c((x->block + idx)->coeff, 1500 copy_predictor_8x8(best_predictor, b->predictor);
1419 (xd->block + idx)->dqcoeff, 64); 1501 vpx_memcpy(best_dqcoeff, b->dqcoeff, 64);
1420 ta0 = a[vp9_block2above_8x8[idx]]; 1502 vpx_memcpy(best_dqcoeff + 32, b->dqcoeff + 64, 64);
1421 tl0 = l[vp9_block2left_8x8[idx]];
1422
1423 rate_t = cost_coeffs(x, xd->block + idx, PLANE_TYPE_Y_WITH_DC,
1424 &ta0, &tl0, TX_8X8);
1425
1426 rate += rate_t;
1427 ta1 = ta0;
1428 tl1 = tl0;
1429 } else {
1430 static const int iblock[4] = {0, 1, 4, 5};
1431 TX_TYPE tx_type;
1432 int i;
1433 ta0 = a[vp9_block2above[ib]];
1434 ta1 = a[vp9_block2above[ib + 1]];
1435 tl0 = l[vp9_block2left[ib]];
1436 tl1 = l[vp9_block2left[ib + 4]];
1437 distortion = 0;
1438 rate_t = 0;
1439 for (i = 0; i < 4; ++i) {
1440 b = &xd->block[ib + iblock[i]];
1441 be = &x->block[ib + iblock[i]];
1442 tx_type = get_tx_type_4x4(xd, b);
1443 if (tx_type != DCT_DCT) {
1444 vp9_fht_c(be->src_diff, 32, be->coeff, tx_type, 4);
1445 vp9_ht_quantize_b_4x4(be, b, tx_type);
1446 } else {
1447 x->vp9_short_fdct4x4(be->src_diff, be->coeff, 32);
1448 x->quantize_b_4x4(be, b);
1449 }
1450 distortion += vp9_block_error_c(be->coeff, b->dqcoeff, 16);
1451 rate_t += cost_coeffs(x, b, PLANE_TYPE_Y_WITH_DC,
1452 // i&1 ? &ta1 : &ta0, i&2 ? &tl1 : &tl0,
1453 &ta0, &tl0,
1454 TX_4X4);
1455 }
1456 rate += rate_t;
1457 }
1458
1459 distortion >>= 2;
1460 this_rd = RDCOST(x->rdmult, x->rddiv, rate, distortion);
1461 if (this_rd < best_rd) {
1462 *bestrate = rate;
1463 *bestratey = rate_t;
1464 *bestdistortion = distortion;
1465 besta0 = ta0;
1466 besta1 = ta1;
1467 bestl0 = tl0;
1468 bestl1 = tl1;
1469 best_rd = this_rd;
1470 *best_mode = mode;
1471 #if CONFIG_COMP_INTRA_PRED
1472 *best_second_mode = mode2;
1473 #endif
1474 copy_predictor_8x8(best_predictor, b->predictor);
1475 vpx_memcpy(best_dqcoeff, b->dqcoeff, 64);
1476 vpx_memcpy(best_dqcoeff + 32, b->dqcoeff + 64, 64);
1477 #if CONFIG_COMP_INTRA_PRED
1478 }
1479 #endif
1480 } 1503 }
1481 } 1504 }
1482 b->bmi.as_mode.first = (*best_mode); 1505 b->bmi.as_mode.first = (*best_mode);
1483 #if CONFIG_COMP_INTRA_PRED
1484 b->bmi.as_mode.second = (*best_second_mode);
1485 #endif
1486 vp9_encode_intra8x8(x, ib); 1506 vp9_encode_intra8x8(x, ib);
1487 1507
1488 if (xd->mode_info_context->mbmi.txfm_size == TX_8X8) { 1508 if (xd->mode_info_context->mbmi.txfm_size == TX_8X8) {
1489 a[vp9_block2above_8x8[idx]] = besta0; 1509 a[vp9_block2above[TX_8X8][idx]] = besta0;
1490 a[vp9_block2above_8x8[idx] + 1] = besta1; 1510 a[vp9_block2above[TX_8X8][idx] + 1] = besta1;
1491 l[vp9_block2left_8x8[idx]] = bestl0; 1511 l[vp9_block2left[TX_8X8][idx]] = bestl0;
1492 l[vp9_block2left_8x8[idx] + 1] = bestl1; 1512 l[vp9_block2left[TX_8X8][idx] + 1] = bestl1;
1493 } else { 1513 } else {
1494 a[vp9_block2above[ib]] = besta0; 1514 a[vp9_block2above[TX_4X4][ib]] = besta0;
1495 a[vp9_block2above[ib + 1]] = besta1; 1515 a[vp9_block2above[TX_4X4][ib + 1]] = besta1;
1496 l[vp9_block2left[ib]] = bestl0; 1516 l[vp9_block2left[TX_4X4][ib]] = bestl0;
1497 l[vp9_block2left[ib + 4]] = bestl1; 1517 l[vp9_block2left[TX_4X4][ib + 4]] = bestl1;
1498 } 1518 }
1499 1519
1500 return best_rd; 1520 return best_rd;
1501 } 1521 }
1502 1522
1503 static int64_t rd_pick_intra8x8mby_modes(VP9_COMP *cpi, MACROBLOCK *mb, 1523 static int64_t rd_pick_intra8x8mby_modes(VP9_COMP *cpi, MACROBLOCK *mb,
1504 int *Rate, int *rate_y, 1524 int *Rate, int *rate_y,
1505 int *Distortion, int64_t best_rd) { 1525 int *Distortion, int64_t best_rd) {
1506 MACROBLOCKD *const xd = &mb->e_mbd; 1526 MACROBLOCKD *const xd = &mb->e_mbd;
1507 int i, ib; 1527 int i, ib;
1508 int cost = mb->mbmode_cost [xd->frame_type] [I8X8_PRED]; 1528 int cost = mb->mbmode_cost [xd->frame_type] [I8X8_PRED];
1509 int distortion = 0; 1529 int distortion = 0;
1510 int tot_rate_y = 0; 1530 int tot_rate_y = 0;
1511 long long total_rd = 0; 1531 int64_t total_rd = 0;
1512 ENTROPY_CONTEXT_PLANES t_above, t_left; 1532 ENTROPY_CONTEXT_PLANES t_above, t_left;
1513 ENTROPY_CONTEXT *ta, *tl; 1533 ENTROPY_CONTEXT *ta, *tl;
1514 int *i8x8mode_costs; 1534 int *i8x8mode_costs;
1515 1535
1516 vpx_memcpy(&t_above, xd->above_context, sizeof(ENTROPY_CONTEXT_PLANES)); 1536 vpx_memcpy(&t_above, xd->above_context, sizeof(ENTROPY_CONTEXT_PLANES));
1517 vpx_memcpy(&t_left, xd->left_context, sizeof(ENTROPY_CONTEXT_PLANES)); 1537 vpx_memcpy(&t_left, xd->left_context, sizeof(ENTROPY_CONTEXT_PLANES));
1518 1538
1519 ta = (ENTROPY_CONTEXT *)&t_above; 1539 ta = (ENTROPY_CONTEXT *)&t_above;
1520 tl = (ENTROPY_CONTEXT *)&t_left; 1540 tl = (ENTROPY_CONTEXT *)&t_left;
1521 1541
1522 xd->mode_info_context->mbmi.mode = I8X8_PRED; 1542 xd->mode_info_context->mbmi.mode = I8X8_PRED;
1523 i8x8mode_costs = mb->i8x8_mode_costs; 1543 i8x8mode_costs = mb->i8x8_mode_costs;
1524 1544
1525 for (i = 0; i < 4; i++) { 1545 for (i = 0; i < 4; i++) {
1526 MODE_INFO *const mic = xd->mode_info_context; 1546 MODE_INFO *const mic = xd->mode_info_context;
1527 B_PREDICTION_MODE UNINITIALIZED_IS_SAFE(best_mode); 1547 B_PREDICTION_MODE UNINITIALIZED_IS_SAFE(best_mode);
1528 #if CONFIG_COMP_INTRA_PRED
1529 B_PREDICTION_MODE UNINITIALIZED_IS_SAFE(best_second_mode);
1530 #endif
1531 int UNINITIALIZED_IS_SAFE(r), UNINITIALIZED_IS_SAFE(ry), UNINITIALIZED_IS_SA FE(d); 1548 int UNINITIALIZED_IS_SAFE(r), UNINITIALIZED_IS_SAFE(ry), UNINITIALIZED_IS_SA FE(d);
1532 1549
1533 ib = vp9_i8x8_block[i]; 1550 ib = vp9_i8x8_block[i];
1534 total_rd += rd_pick_intra8x8block( 1551 total_rd += rd_pick_intra8x8block(
1535 cpi, mb, ib, &best_mode, 1552 cpi, mb, ib, &best_mode,
1536 #if CONFIG_COMP_INTRA_PRED
1537 & best_second_mode,
1538 #endif
1539 i8x8mode_costs, ta, tl, &r, &ry, &d); 1553 i8x8mode_costs, ta, tl, &r, &ry, &d);
1540 cost += r; 1554 cost += r;
1541 distortion += d; 1555 distortion += d;
1542 tot_rate_y += ry; 1556 tot_rate_y += ry;
1543 mic->bmi[ib].as_mode.first = best_mode; 1557 mic->bmi[ib].as_mode.first = best_mode;
1544 #if CONFIG_COMP_INTRA_PRED
1545 mic->bmi[ib].as_mode.second = best_second_mode;
1546 #endif
1547 } 1558 }
1548 1559
1549 *Rate = cost; 1560 *Rate = cost;
1550 *rate_y = tot_rate_y; 1561 *rate_y = tot_rate_y;
1551 *Distortion = distortion; 1562 *Distortion = distortion;
1552 return RDCOST(mb->rdmult, mb->rddiv, cost, distortion); 1563 return RDCOST(mb->rdmult, mb->rddiv, cost, distortion);
1553 } 1564 }
1554 1565
1555 static int rd_cost_mbuv_4x4(MACROBLOCK *mb, int backup) { 1566 static int rd_cost_mbuv_4x4(MACROBLOCK *mb, int backup) {
1556 int b; 1567 int b;
1557 int cost = 0; 1568 int cost = 0;
1558 MACROBLOCKD *xd = &mb->e_mbd; 1569 MACROBLOCKD *xd = &mb->e_mbd;
1559 ENTROPY_CONTEXT_PLANES t_above, t_left; 1570 ENTROPY_CONTEXT_PLANES t_above, t_left;
1560 ENTROPY_CONTEXT *ta, *tl; 1571 ENTROPY_CONTEXT *ta, *tl;
1561 1572
1562 if (backup) { 1573 if (backup) {
1563 vpx_memcpy(&t_above, xd->above_context, sizeof(ENTROPY_CONTEXT_PLANES)); 1574 vpx_memcpy(&t_above, xd->above_context, sizeof(ENTROPY_CONTEXT_PLANES));
1564 vpx_memcpy(&t_left, xd->left_context, sizeof(ENTROPY_CONTEXT_PLANES)); 1575 vpx_memcpy(&t_left, xd->left_context, sizeof(ENTROPY_CONTEXT_PLANES));
1565 1576
1566 ta = (ENTROPY_CONTEXT *)&t_above; 1577 ta = (ENTROPY_CONTEXT *)&t_above;
1567 tl = (ENTROPY_CONTEXT *)&t_left; 1578 tl = (ENTROPY_CONTEXT *)&t_left;
1568 } else { 1579 } else {
1569 ta = (ENTROPY_CONTEXT *)xd->above_context; 1580 ta = (ENTROPY_CONTEXT *)xd->above_context;
1570 tl = (ENTROPY_CONTEXT *)xd->left_context; 1581 tl = (ENTROPY_CONTEXT *)xd->left_context;
1571 } 1582 }
1572 1583
1573 for (b = 16; b < 24; b++) 1584 for (b = 16; b < 24; b++)
1574 cost += cost_coeffs(mb, xd->block + b, PLANE_TYPE_UV, 1585 cost += cost_coeffs(mb, xd->block + b, PLANE_TYPE_UV,
1575 ta + vp9_block2above[b], tl + vp9_block2left[b], 1586 ta + vp9_block2above[TX_4X4][b],
1587 tl + vp9_block2left[TX_4X4][b],
1576 TX_4X4); 1588 TX_4X4);
1577 1589
1578 return cost; 1590 return cost;
1579 } 1591 }
1580 1592
1581 1593
1582 static int64_t rd_inter16x16_uv_4x4(VP9_COMP *cpi, MACROBLOCK *x, int *rate, 1594 static int64_t rd_inter16x16_uv_4x4(VP9_COMP *cpi, MACROBLOCK *x, int *rate,
1583 int *distortion, int fullpixel, int *skip, 1595 int *distortion, int fullpixel, int *skip,
1584 int do_ctx_backup) { 1596 int do_ctx_backup) {
1585 vp9_transform_mbuv_4x4(x); 1597 vp9_transform_mbuv_4x4(x);
(...skipping 19 matching lines...) Expand all
1605 1617
1606 ta = (ENTROPY_CONTEXT *)&t_above; 1618 ta = (ENTROPY_CONTEXT *)&t_above;
1607 tl = (ENTROPY_CONTEXT *)&t_left; 1619 tl = (ENTROPY_CONTEXT *)&t_left;
1608 } else { 1620 } else {
1609 ta = (ENTROPY_CONTEXT *)mb->e_mbd.above_context; 1621 ta = (ENTROPY_CONTEXT *)mb->e_mbd.above_context;
1610 tl = (ENTROPY_CONTEXT *)mb->e_mbd.left_context; 1622 tl = (ENTROPY_CONTEXT *)mb->e_mbd.left_context;
1611 } 1623 }
1612 1624
1613 for (b = 16; b < 24; b += 4) 1625 for (b = 16; b < 24; b += 4)
1614 cost += cost_coeffs(mb, xd->block + b, PLANE_TYPE_UV, 1626 cost += cost_coeffs(mb, xd->block + b, PLANE_TYPE_UV,
1615 ta + vp9_block2above_8x8[b], 1627 ta + vp9_block2above[TX_8X8][b],
1616 tl + vp9_block2left_8x8[b], TX_8X8); 1628 tl + vp9_block2left[TX_8X8][b], TX_8X8);
1617 1629
1618 return cost; 1630 return cost;
1619 } 1631 }
1620 1632
1621 static int64_t rd_inter16x16_uv_8x8(VP9_COMP *cpi, MACROBLOCK *x, int *rate, 1633 static int64_t rd_inter16x16_uv_8x8(VP9_COMP *cpi, MACROBLOCK *x, int *rate,
1622 int *distortion, int fullpixel, int *skip, 1634 int *distortion, int fullpixel, int *skip,
1623 int do_ctx_backup) { 1635 int do_ctx_backup) {
1624 vp9_transform_mbuv_8x8(x); 1636 vp9_transform_mbuv_8x8(x);
1625 vp9_quantize_mbuv_8x8(x); 1637 vp9_quantize_mbuv_8x8(x);
1626 1638
1627 *rate = rd_cost_mbuv_8x8(x, do_ctx_backup); 1639 *rate = rd_cost_mbuv_8x8(x, do_ctx_backup);
1628 *distortion = vp9_mbuverror(x) / 4; 1640 *distortion = vp9_mbuverror(x) / 4;
1629 *skip = vp9_mbuv_is_skippable_8x8(&x->e_mbd); 1641 *skip = vp9_mbuv_is_skippable_8x8(&x->e_mbd);
1630 1642
1631 return RDCOST(x->rdmult, x->rddiv, *rate, *distortion); 1643 return RDCOST(x->rdmult, x->rddiv, *rate, *distortion);
1632 } 1644 }
1633 1645
1634 #if CONFIG_SUPERBLOCKS 1646 static int rd_cost_sbuv_16x16(MACROBLOCK *x, int backup) {
1647 int b;
1648 int cost = 0;
1649 MACROBLOCKD *const xd = &x->e_mbd;
1650 ENTROPY_CONTEXT_PLANES t_above, t_left;
1651 ENTROPY_CONTEXT *ta, *tl;
1652
1653 if (backup) {
1654 vpx_memcpy(&t_above, xd->above_context, sizeof(ENTROPY_CONTEXT_PLANES));
1655 vpx_memcpy(&t_left, xd->left_context, sizeof(ENTROPY_CONTEXT_PLANES));
1656
1657 ta = (ENTROPY_CONTEXT *) &t_above;
1658 tl = (ENTROPY_CONTEXT *) &t_left;
1659 } else {
1660 ta = (ENTROPY_CONTEXT *)xd->above_context;
1661 tl = (ENTROPY_CONTEXT *)xd->left_context;
1662 }
1663
1664 for (b = 16; b < 24; b += 4)
1665 cost += cost_coeffs(x, xd->block + b, PLANE_TYPE_UV,
1666 ta + vp9_block2above[TX_8X8][b],
1667 tl + vp9_block2left[TX_8X8][b], TX_16X16);
1668
1669 return cost;
1670 }
1671
1672 static void rd_inter32x32_uv_16x16(MACROBLOCK *x, int *rate,
1673 int *distortion, int *skip,
1674 int backup) {
1675 MACROBLOCKD *const xd = &x->e_mbd;
1676
1677 vp9_transform_sbuv_16x16(x);
1678 vp9_quantize_sbuv_16x16(x);
1679
1680 *rate = rd_cost_sbuv_16x16(x, backup);
1681 *distortion = vp9_block_error_c(x->sb_coeff_data.coeff + 1024,
1682 xd->sb_coeff_data.dqcoeff + 1024, 512) >> 2;
1683 *skip = vp9_sbuv_is_skippable_16x16(xd);
1684 }
1685
1635 static int64_t rd_inter32x32_uv(VP9_COMP *cpi, MACROBLOCK *x, int *rate, 1686 static int64_t rd_inter32x32_uv(VP9_COMP *cpi, MACROBLOCK *x, int *rate,
1636 int *distortion, int fullpixel, int *skip) { 1687 int *distortion, int fullpixel, int *skip) {
1637 MACROBLOCKD *xd = &x->e_mbd; 1688 MACROBLOCKD *xd = &x->e_mbd;
1638 MB_MODE_INFO *const mbmi = &xd->mode_info_context->mbmi; 1689 MB_MODE_INFO *const mbmi = &xd->mode_info_context->mbmi;
1639 int n, r = 0, d = 0;
1640 const uint8_t *usrc = x->src.u_buffer, *udst = xd->dst.u_buffer; 1690 const uint8_t *usrc = x->src.u_buffer, *udst = xd->dst.u_buffer;
1641 const uint8_t *vsrc = x->src.v_buffer, *vdst = xd->dst.v_buffer; 1691 const uint8_t *vsrc = x->src.v_buffer, *vdst = xd->dst.v_buffer;
1642 int src_uv_stride = x->src.uv_stride, dst_uv_stride = xd->dst.uv_stride; 1692 int src_uv_stride = x->src.uv_stride, dst_uv_stride = xd->dst.uv_stride;
1643 int skippable = 1;
1644 ENTROPY_CONTEXT_PLANES t_above[2], t_left[2];
1645 ENTROPY_CONTEXT_PLANES *ta = xd->above_context;
1646 ENTROPY_CONTEXT_PLANES *tl = xd->left_context;
1647 1693
1648 memcpy(t_above, xd->above_context, sizeof(t_above)); 1694 if (mbmi->txfm_size == TX_32X32) {
1649 memcpy(t_left, xd->left_context, sizeof(t_left)); 1695 vp9_subtract_sbuv_s_c(x->sb_coeff_data.src_diff,
1696 usrc, vsrc, src_uv_stride,
1697 udst, vdst, dst_uv_stride);
1698 rd_inter32x32_uv_16x16(x, rate, distortion, skip, 1);
1699 } else {
1700 int n, r = 0, d = 0;
1701 int skippable = 1;
1702 ENTROPY_CONTEXT_PLANES t_above[2], t_left[2];
1703 ENTROPY_CONTEXT_PLANES *ta = xd->above_context;
1704 ENTROPY_CONTEXT_PLANES *tl = xd->left_context;
1650 1705
1651 for (n = 0; n < 4; n++) { 1706 memcpy(t_above, xd->above_context, sizeof(t_above));
1652 int x_idx = n & 1, y_idx = n >> 1; 1707 memcpy(t_left, xd->left_context, sizeof(t_left));
1653 int d_tmp, s_tmp, r_tmp;
1654 1708
1655 xd->above_context = ta + x_idx; 1709 for (n = 0; n < 4; n++) {
1656 xd->left_context = tl + y_idx; 1710 int x_idx = n & 1, y_idx = n >> 1;
1657 vp9_subtract_mbuv_s_c(x->src_diff, 1711 int d_tmp, s_tmp, r_tmp;
1658 usrc + x_idx * 8 + y_idx * 8 * src_uv_stride,
1659 vsrc + x_idx * 8 + y_idx * 8 * src_uv_stride,
1660 src_uv_stride,
1661 udst + x_idx * 8 + y_idx * 8 * dst_uv_stride,
1662 vdst + x_idx * 8 + y_idx * 8 * dst_uv_stride,
1663 dst_uv_stride);
1664 1712
1665 if (mbmi->txfm_size == TX_4X4) { 1713 xd->above_context = ta + x_idx;
1666 rd_inter16x16_uv_4x4(cpi, x, &r_tmp, &d_tmp, fullpixel, &s_tmp, 0); 1714 xd->left_context = tl + y_idx;
1667 } else { 1715 vp9_subtract_mbuv_s_c(x->src_diff,
1668 rd_inter16x16_uv_8x8(cpi, x, &r_tmp, &d_tmp, fullpixel, &s_tmp, 0); 1716 usrc + x_idx * 8 + y_idx * 8 * src_uv_stride,
1717 vsrc + x_idx * 8 + y_idx * 8 * src_uv_stride,
1718 src_uv_stride,
1719 udst + x_idx * 8 + y_idx * 8 * dst_uv_stride,
1720 vdst + x_idx * 8 + y_idx * 8 * dst_uv_stride,
1721 dst_uv_stride);
1722
1723 if (mbmi->txfm_size == TX_4X4) {
1724 rd_inter16x16_uv_4x4(cpi, x, &r_tmp, &d_tmp, fullpixel, &s_tmp, 0);
1725 } else {
1726 rd_inter16x16_uv_8x8(cpi, x, &r_tmp, &d_tmp, fullpixel, &s_tmp, 0);
1727 }
1728
1729 r += r_tmp;
1730 d += d_tmp;
1731 skippable = skippable && s_tmp;
1669 } 1732 }
1670 1733
1671 r += r_tmp; 1734 *rate = r;
1672 d += d_tmp; 1735 *distortion = d;
1673 skippable = skippable && s_tmp; 1736 *skip = skippable;
1737 xd->left_context = tl;
1738 xd->above_context = ta;
1739 memcpy(xd->above_context, t_above, sizeof(t_above));
1740 memcpy(xd->left_context, t_left, sizeof(t_left));
1674 } 1741 }
1675 1742
1676 *rate = r; 1743 return RDCOST(x->rdmult, x->rddiv, *rate, *distortion);
1677 *distortion = d; 1744 }
1678 *skip = skippable;
1679 xd->left_context = tl;
1680 xd->above_context = ta;
1681 memcpy(xd->above_context, t_above, sizeof(t_above));
1682 memcpy(xd->left_context, t_left, sizeof(t_left));
1683 1745
1684 return RDCOST(x->rdmult, x->rddiv, r, d); 1746 static void super_block_64_uvrd(MACROBLOCK *x, int *rate,
1747 int *distortion, int *skip);
1748 static int64_t rd_inter64x64_uv(VP9_COMP *cpi, MACROBLOCK *x, int *rate,
1749 int *distortion, int fullpixel, int *skip) {
1750 super_block_64_uvrd(x, rate, distortion, skip);
1751 return RDCOST(x->rdmult, x->rddiv, *rate, *distortion);
1685 } 1752 }
1686 #endif
1687 1753
1688 static int64_t rd_inter4x4_uv(VP9_COMP *cpi, MACROBLOCK *x, int *rate, 1754 static int64_t rd_inter4x4_uv(VP9_COMP *cpi, MACROBLOCK *x, int *rate,
1689 int *distortion, int *skip, int fullpixel) { 1755 int *distortion, int *skip, int fullpixel) {
1690 vp9_build_inter4x4_predictors_mbuv(&x->e_mbd); 1756 vp9_build_inter4x4_predictors_mbuv(&x->e_mbd);
1691 vp9_subtract_mbuv(x->src_diff, x->src.u_buffer, x->src.v_buffer, 1757 vp9_subtract_mbuv(x->src_diff, x->src.u_buffer, x->src.v_buffer,
1692 x->e_mbd.predictor, x->src.uv_stride); 1758 x->e_mbd.predictor, x->src.uv_stride);
1693 return rd_inter16x16_uv_4x4(cpi, x, rate, distortion, fullpixel, skip, 1); 1759 return rd_inter16x16_uv_4x4(cpi, x, rate, distortion, fullpixel, skip, 1);
1694 } 1760 }
1695 1761
1696 static void rd_pick_intra_mbuv_mode(VP9_COMP *cpi, 1762 static void rd_pick_intra_mbuv_mode(VP9_COMP *cpi,
1697 MACROBLOCK *x, 1763 MACROBLOCK *x,
1698 int *rate, 1764 int *rate,
1699 int *rate_tokenonly, 1765 int *rate_tokenonly,
1700 int *distortion, 1766 int *distortion,
1701 int *skippable) { 1767 int *skippable) {
1702 MB_PREDICTION_MODE mode; 1768 MB_PREDICTION_MODE mode;
1703 MB_PREDICTION_MODE UNINITIALIZED_IS_SAFE(mode_selected); 1769 MB_PREDICTION_MODE UNINITIALIZED_IS_SAFE(mode_selected);
1704 #if CONFIG_COMP_INTRA_PRED
1705 MB_PREDICTION_MODE mode2;
1706 MB_PREDICTION_MODE UNINITIALIZED_IS_SAFE(mode2_selected);
1707 #endif
1708 MACROBLOCKD *xd = &x->e_mbd; 1770 MACROBLOCKD *xd = &x->e_mbd;
1709 MB_MODE_INFO * mbmi = &x->e_mbd.mode_info_context->mbmi; 1771 MB_MODE_INFO * mbmi = &x->e_mbd.mode_info_context->mbmi;
1710 int64_t best_rd = INT64_MAX; 1772 int64_t best_rd = INT64_MAX;
1711 int UNINITIALIZED_IS_SAFE(d), UNINITIALIZED_IS_SAFE(r); 1773 int UNINITIALIZED_IS_SAFE(d), UNINITIALIZED_IS_SAFE(r);
1712 int rate_to, UNINITIALIZED_IS_SAFE(skip); 1774 int rate_to, UNINITIALIZED_IS_SAFE(skip);
1713 1775
1714 for (mode = DC_PRED; mode <= TM_PRED; mode++) { 1776 for (mode = DC_PRED; mode <= TM_PRED; mode++) {
1715 #if CONFIG_COMP_INTRA_PRED 1777 int rate;
1716 for (mode2 = DC_PRED - 1; mode2 != TM_PRED + 1; mode2++) { 1778 int distortion;
1717 #endif 1779 int64_t this_rd;
1718 int rate;
1719 int distortion;
1720 int64_t this_rd;
1721 1780
1722 mbmi->uv_mode = mode; 1781 mbmi->uv_mode = mode;
1723 #if CONFIG_COMP_INTRA_PRED 1782 vp9_build_intra_predictors_mbuv(&x->e_mbd);
1724 mbmi->second_uv_mode = mode2;
1725 if (mode2 == (MB_PREDICTION_MODE)(DC_PRED - 1)) {
1726 #endif
1727 vp9_build_intra_predictors_mbuv(&x->e_mbd);
1728 #if CONFIG_COMP_INTRA_PRED
1729 } else {
1730 continue;
1731 vp9_build_comp_intra_predictors_mbuv(&x->e_mbd);
1732 }
1733 #endif
1734 1783
1735 vp9_subtract_mbuv(x->src_diff, x->src.u_buffer, x->src.v_buffer, 1784 vp9_subtract_mbuv(x->src_diff, x->src.u_buffer, x->src.v_buffer,
1736 x->e_mbd.predictor, x->src.uv_stride); 1785 x->e_mbd.predictor, x->src.uv_stride);
1737 vp9_transform_mbuv_4x4(x); 1786 vp9_transform_mbuv_4x4(x);
1738 vp9_quantize_mbuv_4x4(x); 1787 vp9_quantize_mbuv_4x4(x);
1739 1788
1740 rate_to = rd_cost_mbuv_4x4(x, 1); 1789 rate_to = rd_cost_mbuv_4x4(x, 1);
1741 rate = rate_to 1790 rate = rate_to
1742 + x->intra_uv_mode_cost[x->e_mbd.frame_type][mbmi->uv_mode]; 1791 + x->intra_uv_mode_cost[x->e_mbd.frame_type][mbmi->uv_mode];
1743 1792
1744 distortion = vp9_mbuverror(x) / 4; 1793 distortion = vp9_mbuverror(x) / 4;
1745 1794
1746 this_rd = RDCOST(x->rdmult, x->rddiv, rate, distortion); 1795 this_rd = RDCOST(x->rdmult, x->rddiv, rate, distortion);
1747 1796
1748 if (this_rd < best_rd) { 1797 if (this_rd < best_rd) {
1749 skip = vp9_mbuv_is_skippable_4x4(xd); 1798 skip = vp9_mbuv_is_skippable_4x4(xd);
1750 best_rd = this_rd; 1799 best_rd = this_rd;
1751 d = distortion; 1800 d = distortion;
1752 r = rate; 1801 r = rate;
1753 *rate_tokenonly = rate_to; 1802 *rate_tokenonly = rate_to;
1754 mode_selected = mode; 1803 mode_selected = mode;
1755 #if CONFIG_COMP_INTRA_PRED
1756 mode2_selected = mode2;
1757 }
1758 #endif
1759 } 1804 }
1760 } 1805 }
1761 1806
1762 *rate = r; 1807 *rate = r;
1763 *distortion = d; 1808 *distortion = d;
1764 *skippable = skip; 1809 *skippable = skip;
1765 1810
1766 mbmi->uv_mode = mode_selected; 1811 mbmi->uv_mode = mode_selected;
1767 #if CONFIG_COMP_INTRA_PRED
1768 mbmi->second_uv_mode = mode2_selected;
1769 #endif
1770 } 1812 }
1771 1813
1772 static void rd_pick_intra_mbuv_mode_8x8(VP9_COMP *cpi, 1814 static void rd_pick_intra_mbuv_mode_8x8(VP9_COMP *cpi,
1773 MACROBLOCK *x, 1815 MACROBLOCK *x,
1774 int *rate, 1816 int *rate,
1775 int *rate_tokenonly, 1817 int *rate_tokenonly,
1776 int *distortion, 1818 int *distortion,
1777 int *skippable) { 1819 int *skippable) {
1778 MACROBLOCKD *xd = &x->e_mbd; 1820 MACROBLOCKD *xd = &x->e_mbd;
1779 MB_PREDICTION_MODE mode; 1821 MB_PREDICTION_MODE mode;
(...skipping 30 matching lines...) Expand all
1810 *rate_tokenonly = rate_to; 1852 *rate_tokenonly = rate_to;
1811 mode_selected = mode; 1853 mode_selected = mode;
1812 } 1854 }
1813 } 1855 }
1814 *rate = r; 1856 *rate = r;
1815 *distortion = d; 1857 *distortion = d;
1816 *skippable = skip; 1858 *skippable = skip;
1817 mbmi->uv_mode = mode_selected; 1859 mbmi->uv_mode = mode_selected;
1818 } 1860 }
1819 1861
1820 #if CONFIG_SUPERBLOCKS 1862 // TODO(rbultje) very similar to rd_inter32x32_uv(), merge?
1821 static void super_block_uvrd_8x8(MACROBLOCK *x, 1863 static void super_block_uvrd(MACROBLOCK *x,
1822 int *rate, 1864 int *rate,
1823 int *distortion, 1865 int *distortion,
1824 int *skippable) { 1866 int *skippable) {
1825 MACROBLOCKD *const xd = &x->e_mbd; 1867 MACROBLOCKD *const xd = &x->e_mbd;
1826 int d = 0, r = 0, n, s = 1; 1868 MB_MODE_INFO *const mbmi = &xd->mode_info_context->mbmi;
1827 const uint8_t *usrc = x->src.u_buffer, *udst = xd->dst.u_buffer; 1869 const uint8_t *usrc = x->src.u_buffer, *udst = xd->dst.u_buffer;
1828 const uint8_t *vsrc = x->src.v_buffer, *vdst = xd->dst.v_buffer; 1870 const uint8_t *vsrc = x->src.v_buffer, *vdst = xd->dst.v_buffer;
1829 int src_uv_stride = x->src.uv_stride, dst_uv_stride = xd->dst.uv_stride; 1871 int src_uv_stride = x->src.uv_stride, dst_uv_stride = xd->dst.uv_stride;
1830 ENTROPY_CONTEXT_PLANES t_above[2], t_left[2]; 1872
1831 ENTROPY_CONTEXT_PLANES *ta = xd->above_context; 1873 if (mbmi->txfm_size == TX_32X32) {
1832 ENTROPY_CONTEXT_PLANES *tl = xd->left_context; 1874 vp9_subtract_sbuv_s_c(x->sb_coeff_data.src_diff,
1875 usrc, vsrc, src_uv_stride,
1876 udst, vdst, dst_uv_stride);
1877 rd_inter32x32_uv_16x16(x, rate, distortion, skippable, 1);
1878 } else {
1879 int d = 0, r = 0, n, s = 1;
1880 ENTROPY_CONTEXT_PLANES t_above[2], t_left[2];
1881 ENTROPY_CONTEXT_PLANES *ta_orig = xd->above_context;
1882 ENTROPY_CONTEXT_PLANES *tl_orig = xd->left_context;
1883
1884 memcpy(t_above, xd->above_context, sizeof(t_above));
1885 memcpy(t_left, xd->left_context, sizeof(t_left));
1886
1887 for (n = 0; n < 4; n++) {
1888 int x_idx = n & 1, y_idx = n >> 1;
1889
1890 vp9_subtract_mbuv_s_c(x->src_diff,
1891 usrc + x_idx * 8 + y_idx * 8 * src_uv_stride,
1892 vsrc + x_idx * 8 + y_idx * 8 * src_uv_stride,
1893 src_uv_stride,
1894 udst + x_idx * 8 + y_idx * 8 * dst_uv_stride,
1895 vdst + x_idx * 8 + y_idx * 8 * dst_uv_stride,
1896 dst_uv_stride);
1897 if (mbmi->txfm_size == TX_4X4) {
1898 vp9_transform_mbuv_4x4(x);
1899 vp9_quantize_mbuv_4x4(x);
1900 s &= vp9_mbuv_is_skippable_4x4(xd);
1901 } else {
1902 vp9_transform_mbuv_8x8(x);
1903 vp9_quantize_mbuv_8x8(x);
1904 s &= vp9_mbuv_is_skippable_8x8(xd);
1905 }
1906
1907 d += vp9_mbuverror(x) >> 2;
1908 xd->above_context = t_above + x_idx;
1909 xd->left_context = t_left + y_idx;
1910 if (mbmi->txfm_size == TX_4X4) {
1911 r += rd_cost_mbuv_4x4(x, 0);
1912 } else {
1913 r += rd_cost_mbuv_8x8(x, 0);
1914 }
1915 }
1916
1917 xd->above_context = ta_orig;
1918 xd->left_context = tl_orig;
1919
1920 *distortion = d;
1921 *rate = r;
1922 *skippable = s;
1923 }
1924 }
1925
1926 static void super_block_64_uvrd(MACROBLOCK *x,
1927 int *rate,
1928 int *distortion,
1929 int *skippable) {
1930 MACROBLOCKD *const xd = &x->e_mbd;
1931 MB_MODE_INFO *const mbmi = &xd->mode_info_context->mbmi;
1932 const uint8_t *usrc = x->src.u_buffer, *udst = xd->dst.u_buffer;
1933 const uint8_t *vsrc = x->src.v_buffer, *vdst = xd->dst.v_buffer;
1934 int src_uv_stride = x->src.uv_stride, dst_uv_stride = xd->dst.uv_stride;
1935 ENTROPY_CONTEXT_PLANES t_above[4], t_left[4];
1936 ENTROPY_CONTEXT_PLANES *ta_orig = xd->above_context;
1937 ENTROPY_CONTEXT_PLANES *tl_orig = xd->left_context;
1938 int d = 0, r = 0, n, s = 1;
1833 1939
1834 memcpy(t_above, xd->above_context, sizeof(t_above)); 1940 memcpy(t_above, xd->above_context, sizeof(t_above));
1835 memcpy(t_left, xd->left_context, sizeof(t_left)); 1941 memcpy(t_left, xd->left_context, sizeof(t_left));
1836 1942
1837 for (n = 0; n < 4; n++) { 1943 if (mbmi->txfm_size == TX_32X32) {
1838 int x_idx = n & 1, y_idx = n >> 1; 1944 int n;
1839 1945
1840 vp9_subtract_mbuv_s_c(x->src_diff, 1946 *rate = 0;
1841 usrc + x_idx * 8 + y_idx * 8 * src_uv_stride, 1947 for (n = 0; n < 4; n++) {
1842 vsrc + x_idx * 8 + y_idx * 8 * src_uv_stride, 1948 int x_idx = n & 1, y_idx = n >> 1;
1843 src_uv_stride, 1949 int r_tmp, d_tmp, s_tmp;
1844 udst + x_idx * 8 + y_idx * 8 * dst_uv_stride,
1845 vdst + x_idx * 8 + y_idx * 8 * dst_uv_stride,
1846 dst_uv_stride);
1847 vp9_transform_mbuv_8x8(x);
1848 vp9_quantize_mbuv_8x8(x);
1849 s &= vp9_mbuv_is_skippable_8x8(xd);
1850 1950
1851 d += vp9_mbuverror(x) >> 2; 1951 vp9_subtract_sbuv_s_c(x->sb_coeff_data.src_diff,
1852 xd->above_context = ta + x_idx; 1952 usrc + x_idx * 16 + y_idx * 16 * src_uv_stride,
1853 xd->left_context = tl + y_idx; 1953 vsrc + x_idx * 16 + y_idx * 16 * src_uv_stride,
1854 r += rd_cost_mbuv_8x8(x, 0); 1954 src_uv_stride,
1955 udst + x_idx * 16 + y_idx * 16 * dst_uv_stride,
1956 vdst + x_idx * 16 + y_idx * 16 * dst_uv_stride,
1957 dst_uv_stride);
1958 xd->above_context = t_above + x_idx * 2;
1959 xd->left_context = t_left + y_idx * 2;
1960 rd_inter32x32_uv_16x16(x, &r_tmp, &d_tmp, &s_tmp, 0);
1961 r += r_tmp;
1962 d += d_tmp;
1963 s = s && s_tmp;
1964 }
1965 } else {
1966 for (n = 0; n < 16; n++) {
1967 int x_idx = n & 3, y_idx = n >> 2;
1968
1969 vp9_subtract_mbuv_s_c(x->src_diff,
1970 usrc + x_idx * 8 + y_idx * 8 * src_uv_stride,
1971 vsrc + x_idx * 8 + y_idx * 8 * src_uv_stride,
1972 src_uv_stride,
1973 udst + x_idx * 8 + y_idx * 8 * dst_uv_stride,
1974 vdst + x_idx * 8 + y_idx * 8 * dst_uv_stride,
1975 dst_uv_stride);
1976 if (mbmi->txfm_size == TX_4X4) {
1977 vp9_transform_mbuv_4x4(x);
1978 vp9_quantize_mbuv_4x4(x);
1979 s &= vp9_mbuv_is_skippable_4x4(xd);
1980 } else {
1981 vp9_transform_mbuv_8x8(x);
1982 vp9_quantize_mbuv_8x8(x);
1983 s &= vp9_mbuv_is_skippable_8x8(xd);
1984 }
1985
1986 xd->above_context = t_above + x_idx;
1987 xd->left_context = t_left + y_idx;
1988 d += vp9_mbuverror(x) >> 2;
1989 if (mbmi->txfm_size == TX_4X4) {
1990 r += rd_cost_mbuv_4x4(x, 0);
1991 } else {
1992 r += rd_cost_mbuv_8x8(x, 0);
1993 }
1994 }
1855 } 1995 }
1856 1996
1857 xd->above_context = ta;
1858 xd->left_context = tl;
1859 *distortion = d; 1997 *distortion = d;
1860 *rate = r; 1998 *rate = r;
1861 *skippable = s; 1999 *skippable = s;
1862 2000
1863 xd->left_context = tl; 2001 xd->left_context = tl_orig;
1864 xd->above_context = ta; 2002 xd->above_context = ta_orig;
1865 memcpy(xd->above_context, t_above, sizeof(t_above));
1866 memcpy(xd->left_context, t_left, sizeof(t_left));
1867 } 2003 }
1868 2004
1869 static int64_t rd_pick_intra_sbuv_mode(VP9_COMP *cpi, 2005 static int64_t rd_pick_intra_sbuv_mode(VP9_COMP *cpi,
1870 MACROBLOCK *x, 2006 MACROBLOCK *x,
1871 int *rate, 2007 int *rate,
1872 int *rate_tokenonly, 2008 int *rate_tokenonly,
1873 int *distortion, 2009 int *distortion,
1874 int *skippable) { 2010 int *skippable) {
1875 MB_PREDICTION_MODE mode; 2011 MB_PREDICTION_MODE mode;
1876 MB_PREDICTION_MODE UNINITIALIZED_IS_SAFE(mode_selected); 2012 MB_PREDICTION_MODE UNINITIALIZED_IS_SAFE(mode_selected);
1877 int64_t best_rd = INT64_MAX, this_rd; 2013 int64_t best_rd = INT64_MAX, this_rd;
1878 int this_rate_tokenonly, this_rate; 2014 int this_rate_tokenonly, this_rate;
1879 int this_distortion, s; 2015 int this_distortion, s;
1880 2016
1881 for (mode = DC_PRED; mode <= TM_PRED; mode++) { 2017 for (mode = DC_PRED; mode <= TM_PRED; mode++) {
1882 x->e_mbd.mode_info_context->mbmi.uv_mode = mode; 2018 x->e_mbd.mode_info_context->mbmi.uv_mode = mode;
1883 vp9_build_intra_predictors_sbuv_s(&x->e_mbd); 2019 vp9_build_intra_predictors_sbuv_s(&x->e_mbd);
1884 2020
1885 super_block_uvrd_8x8(x, &this_rate_tokenonly, 2021 super_block_uvrd(x, &this_rate_tokenonly,
1886 &this_distortion, &s); 2022 &this_distortion, &s);
1887 this_rate = this_rate_tokenonly + 2023 this_rate = this_rate_tokenonly +
1888 x->intra_uv_mode_cost[x->e_mbd.frame_type][mode]; 2024 x->intra_uv_mode_cost[x->e_mbd.frame_type][mode];
1889 this_rd = RDCOST(x->rdmult, x->rddiv, this_rate, this_distortion); 2025 this_rd = RDCOST(x->rdmult, x->rddiv, this_rate, this_distortion);
1890 2026
1891 if (this_rd < best_rd) { 2027 if (this_rd < best_rd) {
1892 mode_selected = mode; 2028 mode_selected = mode;
1893 best_rd = this_rd; 2029 best_rd = this_rd;
1894 *rate = this_rate; 2030 *rate = this_rate;
1895 *rate_tokenonly = this_rate_tokenonly; 2031 *rate_tokenonly = this_rate_tokenonly;
1896 *distortion = this_distortion; 2032 *distortion = this_distortion;
1897 *skippable = s; 2033 *skippable = s;
1898 } 2034 }
1899 } 2035 }
1900 2036
1901 x->e_mbd.mode_info_context->mbmi.uv_mode = mode_selected; 2037 x->e_mbd.mode_info_context->mbmi.uv_mode = mode_selected;
1902 2038
1903 return best_rd; 2039 return best_rd;
1904 } 2040 }
1905 #endif 2041
2042 static int64_t rd_pick_intra_sb64uv_mode(VP9_COMP *cpi,
2043 MACROBLOCK *x,
2044 int *rate,
2045 int *rate_tokenonly,
2046 int *distortion,
2047 int *skippable) {
2048 MB_PREDICTION_MODE mode;
2049 MB_PREDICTION_MODE UNINITIALIZED_IS_SAFE(mode_selected);
2050 int64_t best_rd = INT64_MAX, this_rd;
2051 int this_rate_tokenonly, this_rate;
2052 int this_distortion, s;
2053
2054 for (mode = DC_PRED; mode <= TM_PRED; mode++) {
2055 x->e_mbd.mode_info_context->mbmi.uv_mode = mode;
2056 vp9_build_intra_predictors_sb64uv_s(&x->e_mbd);
2057
2058 super_block_64_uvrd(x, &this_rate_tokenonly,
2059 &this_distortion, &s);
2060 this_rate = this_rate_tokenonly +
2061 x->intra_uv_mode_cost[x->e_mbd.frame_type][mode];
2062 this_rd = RDCOST(x->rdmult, x->rddiv, this_rate, this_distortion);
2063
2064 if (this_rd < best_rd) {
2065 mode_selected = mode;
2066 best_rd = this_rd;
2067 *rate = this_rate;
2068 *rate_tokenonly = this_rate_tokenonly;
2069 *distortion = this_distortion;
2070 *skippable = s;
2071 }
2072 }
2073
2074 x->e_mbd.mode_info_context->mbmi.uv_mode = mode_selected;
2075
2076 return best_rd;
2077 }
1906 2078
1907 int vp9_cost_mv_ref(VP9_COMP *cpi, 2079 int vp9_cost_mv_ref(VP9_COMP *cpi,
1908 MB_PREDICTION_MODE m, 2080 MB_PREDICTION_MODE m,
1909 const int mode_context) { 2081 const int mode_context) {
1910 MACROBLOCKD *xd = &cpi->mb.e_mbd; 2082 MACROBLOCKD *xd = &cpi->mb.e_mbd;
1911 int segment_id = xd->mode_info_context->mbmi.segment_id; 2083 int segment_id = xd->mode_info_context->mbmi.segment_id;
1912 2084
1913 // If the mode coding is done entirely at the segment level 2085 // If the mode coding is done entirely at the segment level
1914 // we should not account for it at the per mb level in rd code. 2086 // we should not account for it at the per mb level in rd code.
1915 // Note that if the segment level coding is expanded from single mode 2087 // Note that if the segment level coding is expanded from single mode
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
2051 MACROBLOCKD *xd = &x->e_mbd; 2223 MACROBLOCKD *xd = &x->e_mbd;
2052 2224
2053 *labelyrate = 0; 2225 *labelyrate = 0;
2054 *distortion = 0; 2226 *distortion = 0;
2055 for (i = 0; i < 16; i++) { 2227 for (i = 0; i < 16; i++) {
2056 if (labels[i] == which_label) { 2228 if (labels[i] == which_label) {
2057 BLOCKD *bd = &x->e_mbd.block[i]; 2229 BLOCKD *bd = &x->e_mbd.block[i];
2058 BLOCK *be = &x->block[i]; 2230 BLOCK *be = &x->block[i];
2059 int thisdistortion; 2231 int thisdistortion;
2060 2232
2061 vp9_build_inter_predictors_b(bd, 16, xd->subpixel_predict); 2233 vp9_build_inter_predictors_b(bd, 16, xd->subpixel_predict4x4);
2062 if (xd->mode_info_context->mbmi.second_ref_frame > 0) 2234 if (xd->mode_info_context->mbmi.second_ref_frame > 0)
2063 vp9_build_2nd_inter_predictors_b(bd, 16, xd->subpixel_predict_avg); 2235 vp9_build_2nd_inter_predictors_b(bd, 16, xd->subpixel_predict_avg4x4);
2064 vp9_subtract_b(be, bd, 16); 2236 vp9_subtract_b(be, bd, 16);
2065 x->vp9_short_fdct4x4(be->src_diff, be->coeff, 32); 2237 x->vp9_short_fdct4x4(be->src_diff, be->coeff, 32);
2066 x->quantize_b_4x4(be, bd); 2238 x->quantize_b_4x4(be, bd);
2067 thisdistortion = vp9_block_error(be->coeff, bd->dqcoeff, 16); 2239 thisdistortion = vp9_block_error(be->coeff, bd->dqcoeff, 16);
2068 *distortion += thisdistortion; 2240 *distortion += thisdistortion;
2069 *labelyrate += cost_coeffs(x, bd, PLANE_TYPE_Y_WITH_DC, 2241 *labelyrate += cost_coeffs(x, bd, PLANE_TYPE_Y_WITH_DC,
2070 ta + vp9_block2above[i], 2242 ta + vp9_block2above[TX_4X4][i],
2071 tl + vp9_block2left[i], TX_4X4); 2243 tl + vp9_block2left[TX_4X4][i], TX_4X4);
2072 } 2244 }
2073 } 2245 }
2074 *distortion >>= 2; 2246 *distortion >>= 2;
2075 return RDCOST(x->rdmult, x->rddiv, *labelyrate, *distortion); 2247 return RDCOST(x->rdmult, x->rddiv, *labelyrate, *distortion);
2076 } 2248 }
2077 2249
2078 static int64_t encode_inter_mb_segment_8x8(MACROBLOCK *x, 2250 static int64_t encode_inter_mb_segment_8x8(MACROBLOCK *x,
2079 int const *labels, 2251 int const *labels,
2080 int which_label, 2252 int which_label,
2081 int *labelyrate, 2253 int *labelyrate,
(...skipping 30 matching lines...) Expand all
2112 vp9_build_2nd_inter_predictors4b(xd, bd, 16); 2284 vp9_build_2nd_inter_predictors4b(xd, bd, 16);
2113 vp9_subtract_4b_c(be, bd, 16); 2285 vp9_subtract_4b_c(be, bd, 16);
2114 2286
2115 if (xd->mode_info_context->mbmi.txfm_size == TX_4X4) { 2287 if (xd->mode_info_context->mbmi.txfm_size == TX_4X4) {
2116 if (otherrd) { 2288 if (otherrd) {
2117 x->vp9_short_fdct8x8(be->src_diff, be2->coeff, 32); 2289 x->vp9_short_fdct8x8(be->src_diff, be2->coeff, 32);
2118 x->quantize_b_8x8(be2, bd2); 2290 x->quantize_b_8x8(be2, bd2);
2119 thisdistortion = vp9_block_error_c(be2->coeff, bd2->dqcoeff, 64); 2291 thisdistortion = vp9_block_error_c(be2->coeff, bd2->dqcoeff, 64);
2120 otherdist += thisdistortion; 2292 otherdist += thisdistortion;
2121 othercost += cost_coeffs(x, bd2, PLANE_TYPE_Y_WITH_DC, 2293 othercost += cost_coeffs(x, bd2, PLANE_TYPE_Y_WITH_DC,
2122 tacp + vp9_block2above_8x8[idx], 2294 tacp + vp9_block2above[TX_8X8][idx],
2123 tlcp + vp9_block2left_8x8[idx], TX_8X8); 2295 tlcp + vp9_block2left[TX_8X8][idx],
2296 TX_8X8);
2124 } 2297 }
2125 for (j = 0; j < 4; j += 2) { 2298 for (j = 0; j < 4; j += 2) {
2126 bd = &xd->block[ib + iblock[j]]; 2299 bd = &xd->block[ib + iblock[j]];
2127 be = &x->block[ib + iblock[j]]; 2300 be = &x->block[ib + iblock[j]];
2128 x->vp9_short_fdct8x4(be->src_diff, be->coeff, 32); 2301 x->vp9_short_fdct8x4(be->src_diff, be->coeff, 32);
2129 x->quantize_b_4x4_pair(be, be + 1, bd, bd + 1); 2302 x->quantize_b_4x4_pair(be, be + 1, bd, bd + 1);
2130 thisdistortion = vp9_block_error_c(be->coeff, bd->dqcoeff, 32); 2303 thisdistortion = vp9_block_error_c(be->coeff, bd->dqcoeff, 32);
2131 *distortion += thisdistortion; 2304 *distortion += thisdistortion;
2132 *labelyrate += cost_coeffs(x, bd, PLANE_TYPE_Y_WITH_DC, 2305 *labelyrate += cost_coeffs(x, bd, PLANE_TYPE_Y_WITH_DC,
2133 ta + vp9_block2above[ib + iblock[j]], 2306 ta + vp9_block2above[TX_4X4][ib + iblock[j]],
2134 tl + vp9_block2left[ib + iblock[j]], 2307 tl + vp9_block2left[TX_4X4][ib + iblock[j]],
2135 TX_4X4); 2308 TX_4X4);
2136 *labelyrate += cost_coeffs(x, bd + 1, PLANE_TYPE_Y_WITH_DC, 2309 *labelyrate += cost_coeffs(x, bd + 1, PLANE_TYPE_Y_WITH_DC,
2137 ta + vp9_block2above[ib + iblock[j] + 1], 2310 ta + vp9_block2above[TX_4X4][ib + iblock[j] + 1],
2138 tl + vp9_block2left[ib + iblock[j]], 2311 tl + vp9_block2left[TX_4X4][ib + iblock[j]],
2139 TX_4X4); 2312 TX_4X4);
2140 } 2313 }
2141 } else /* 8x8 */ { 2314 } else /* 8x8 */ {
2142 if (otherrd) { 2315 if (otherrd) {
2143 for (j = 0; j < 4; j += 2) { 2316 for (j = 0; j < 4; j += 2) {
2144 BLOCKD *bd = &xd->block[ib + iblock[j]]; 2317 BLOCKD *bd = &xd->block[ib + iblock[j]];
2145 BLOCK *be = &x->block[ib + iblock[j]]; 2318 BLOCK *be = &x->block[ib + iblock[j]];
2146 x->vp9_short_fdct8x4(be->src_diff, be->coeff, 32); 2319 x->vp9_short_fdct8x4(be->src_diff, be->coeff, 32);
2147 x->quantize_b_4x4_pair(be, be + 1, bd, bd + 1); 2320 x->quantize_b_4x4_pair(be, be + 1, bd, bd + 1);
2148 thisdistortion = vp9_block_error_c(be->coeff, bd->dqcoeff, 32); 2321 thisdistortion = vp9_block_error_c(be->coeff, bd->dqcoeff, 32);
2149 otherdist += thisdistortion; 2322 otherdist += thisdistortion;
2150 othercost += cost_coeffs(x, bd, PLANE_TYPE_Y_WITH_DC, 2323 othercost += cost_coeffs(x, bd, PLANE_TYPE_Y_WITH_DC,
2151 tacp + vp9_block2above[ib + iblock[j]], 2324 tacp + vp9_block2above[TX_4X4][ib + iblock[j]],
2152 tlcp + vp9_block2left[ib + iblock[j]], 2325 tlcp + vp9_block2left[TX_4X4][ib + iblock[j]],
2153 TX_4X4); 2326 TX_4X4);
2154 othercost += cost_coeffs(x, bd + 1, PLANE_TYPE_Y_WITH_DC, 2327 othercost += cost_coeffs(x, bd + 1, PLANE_TYPE_Y_WITH_DC,
2155 tacp + vp9_block2above[ib + iblock[j] + 1], 2328 tacp + vp9_block2above[TX_4X4][ib + iblock[j] + 1],
2156 tlcp + vp9_block2left[ib + iblock[j]], 2329 tlcp + vp9_block2left[TX_4X4][ib + iblock[j]],
2157 TX_4X4); 2330 TX_4X4);
2158 } 2331 }
2159 } 2332 }
2160 x->vp9_short_fdct8x8(be->src_diff, be2->coeff, 32); 2333 x->vp9_short_fdct8x8(be->src_diff, be2->coeff, 32);
2161 x->quantize_b_8x8(be2, bd2); 2334 x->quantize_b_8x8(be2, bd2);
2162 thisdistortion = vp9_block_error_c(be2->coeff, bd2->dqcoeff, 64); 2335 thisdistortion = vp9_block_error_c(be2->coeff, bd2->dqcoeff, 64);
2163 *distortion += thisdistortion; 2336 *distortion += thisdistortion;
2164 *labelyrate += cost_coeffs(x, bd2, PLANE_TYPE_Y_WITH_DC, 2337 *labelyrate += cost_coeffs(x, bd2, PLANE_TYPE_Y_WITH_DC,
2165 ta + vp9_block2above_8x8[idx], 2338 ta + vp9_block2above[TX_8X8][idx],
2166 tl + vp9_block2left_8x8[idx], TX_8X8); 2339 tl + vp9_block2left[TX_8X8][idx], TX_8X8);
2167 } 2340 }
2168 } 2341 }
2169 } 2342 }
2170 *distortion >>= 2; 2343 *distortion >>= 2;
2171 if (otherrd) { 2344 if (otherrd) {
2172 otherdist >>= 2; 2345 otherdist >>= 2;
2173 *otherrd = RDCOST(x->rdmult, x->rddiv, othercost, otherdist); 2346 *otherrd = RDCOST(x->rdmult, x->rddiv, othercost, otherdist);
2174 } 2347 }
2175 return RDCOST(x->rdmult, x->rddiv, *labelyrate, *distortion); 2348 return RDCOST(x->rdmult, x->rddiv, *labelyrate, *distortion);
2176 } 2349 }
(...skipping 554 matching lines...) Expand 10 before | Expand all | Expand 10 after
2731 * used to set mbmi->mv.as_int 2904 * used to set mbmi->mv.as_int
2732 */ 2905 */
2733 x->partition_info->bmi[15].mv.as_int = bsi.mvs[15].as_int; 2906 x->partition_info->bmi[15].mv.as_int = bsi.mvs[15].as_int;
2734 if (mbmi->second_ref_frame > 0) 2907 if (mbmi->second_ref_frame > 0)
2735 x->partition_info->bmi[15].second_mv.as_int = bsi.second_mvs[15].as_int; 2908 x->partition_info->bmi[15].second_mv.as_int = bsi.second_mvs[15].as_int;
2736 2909
2737 return (int)(bsi.segment_rd); 2910 return (int)(bsi.segment_rd);
2738 } 2911 }
2739 2912
2740 static void mv_pred(VP9_COMP *cpi, MACROBLOCK *x, 2913 static void mv_pred(VP9_COMP *cpi, MACROBLOCK *x,
2741 unsigned char *ref_y_buffer, int ref_y_stride, 2914 uint8_t *ref_y_buffer, int ref_y_stride,
2742 int_mv *mvp, int ref_frame, enum BlockSize block_size ) { 2915 int ref_frame, enum BlockSize block_size ) {
2743 MACROBLOCKD *xd = &x->e_mbd; 2916 MACROBLOCKD *xd = &x->e_mbd;
2744 MB_MODE_INFO *mbmi = &xd->mode_info_context->mbmi; 2917 MB_MODE_INFO *mbmi = &xd->mode_info_context->mbmi;
2745 int_mv this_mv; 2918 int_mv this_mv;
2746 int i; 2919 int i;
2747 int zero_seen = FALSE; 2920 int zero_seen = FALSE;
2748 int best_index = 0; 2921 int best_index = 0;
2749 int best_sad = INT_MAX; 2922 int best_sad = INT_MAX;
2750 int this_sad = INT_MAX; 2923 int this_sad = INT_MAX;
2751 2924
2752 BLOCK *b = &x->block[0]; 2925 BLOCK *b = &x->block[0];
2753 unsigned char *src_y_ptr = *(b->base_src); 2926 uint8_t *src_y_ptr = *(b->base_src);
2754 unsigned char *ref_y_ptr; 2927 uint8_t *ref_y_ptr;
2755 int row_offset, col_offset; 2928 int row_offset, col_offset;
2756 2929
2757 // Get the sad for each candidate reference mv 2930 // Get the sad for each candidate reference mv
2758 for (i = 0; i < 4; i++) { 2931 for (i = 0; i < 4; i++) {
2759 this_mv.as_int = mbmi->ref_mvs[ref_frame][i].as_int; 2932 this_mv.as_int = mbmi->ref_mvs[ref_frame][i].as_int;
2760 2933
2761 // The list is at an end if we see 0 for a second time. 2934 // The list is at an end if we see 0 for a second time.
2762 if (!this_mv.as_int && zero_seen) 2935 if (!this_mv.as_int && zero_seen)
2763 break; 2936 break;
2764 zero_seen = zero_seen || !this_mv.as_int; 2937 zero_seen = zero_seen || !this_mv.as_int;
2765 2938
2766 row_offset = this_mv.as_mv.row >> 3; 2939 row_offset = this_mv.as_mv.row >> 3;
2767 col_offset = this_mv.as_mv.col >> 3; 2940 col_offset = this_mv.as_mv.col >> 3;
2768 ref_y_ptr = ref_y_buffer + (ref_y_stride * row_offset) + col_offset; 2941 ref_y_ptr = ref_y_buffer + (ref_y_stride * row_offset) + col_offset;
2769 2942
2770 // Find sad for current vector. 2943 // Find sad for current vector.
2771 this_sad = cpi->fn_ptr[block_size].sdf(src_y_ptr, b->src_stride, 2944 this_sad = cpi->fn_ptr[block_size].sdf(src_y_ptr, b->src_stride,
2772 ref_y_ptr, ref_y_stride, 2945 ref_y_ptr, ref_y_stride,
2773 0x7fffffff); 2946 0x7fffffff);
2774 2947
2775 // Note if it is the best so far. 2948 // Note if it is the best so far.
2776 if (this_sad < best_sad) { 2949 if (this_sad < best_sad) {
2777 best_sad = this_sad; 2950 best_sad = this_sad;
2778 best_index = i; 2951 best_index = i;
2779 } 2952 }
2780 } 2953 }
2781 2954
2782 // Return the mv that had the best sad for use in the motion search. 2955 // Note the index of the mv that worked best in the reference list.
2783 mvp->as_int = mbmi->ref_mvs[ref_frame][best_index].as_int; 2956 x->mv_best_ref_index[ref_frame] = best_index;
2784 clamp_mv2(mvp, xd);
2785 } 2957 }
2786 2958
2787 static void set_i8x8_block_modes(MACROBLOCK *x, int modes[2][4]) { 2959 static void set_i8x8_block_modes(MACROBLOCK *x, int modes[4]) {
2788 int i; 2960 int i;
2789 MACROBLOCKD *xd = &x->e_mbd; 2961 MACROBLOCKD *xd = &x->e_mbd;
2790 for (i = 0; i < 4; i++) { 2962 for (i = 0; i < 4; i++) {
2791 int ib = vp9_i8x8_block[i]; 2963 int ib = vp9_i8x8_block[i];
2792 xd->mode_info_context->bmi[ib + 0].as_mode.first = modes[0][i]; 2964 xd->mode_info_context->bmi[ib + 0].as_mode.first = modes[i];
2793 xd->mode_info_context->bmi[ib + 1].as_mode.first = modes[0][i]; 2965 xd->mode_info_context->bmi[ib + 1].as_mode.first = modes[i];
2794 xd->mode_info_context->bmi[ib + 4].as_mode.first = modes[0][i]; 2966 xd->mode_info_context->bmi[ib + 4].as_mode.first = modes[i];
2795 xd->mode_info_context->bmi[ib + 5].as_mode.first = modes[0][i]; 2967 xd->mode_info_context->bmi[ib + 5].as_mode.first = modes[i];
2796 #if CONFIG_COMP_INTRA_PRED 2968 // printf("%d,%d,%d,%d\n",
2797 xd->mode_info_context->bmi[ib + 0].as_mode.second = modes[1][i]; 2969 // modes[0], modes[1], modes[2], modes[3]);
2798 xd->mode_info_context->bmi[ib + 1].as_mode.second = modes[1][i];
2799 xd->mode_info_context->bmi[ib + 4].as_mode.second = modes[1][i];
2800 xd->mode_info_context->bmi[ib + 5].as_mode.second = modes[1][i];
2801 #endif
2802 // printf("%d,%d,%d,%d %d,%d,%d,%d\n",
2803 // modes[0][0], modes[0][1], modes[0][2], modes[0][3],
2804 // modes[1][0], modes[1][1], modes[1][2], modes[1][3]);
2805 } 2970 }
2806 2971
2807 for (i = 0; i < 16; i++) { 2972 for (i = 0; i < 16; i++) {
2808 xd->block[i].bmi = xd->mode_info_context->bmi[i]; 2973 xd->block[i].bmi = xd->mode_info_context->bmi[i];
2809 } 2974 }
2810 } 2975 }
2811 2976
2812 extern void vp9_calc_ref_probs(int *count, vp9_prob *probs); 2977 extern void vp9_calc_ref_probs(int *count, vp9_prob *probs);
2813 static void estimate_curframe_refprobs(VP9_COMP *cpi, vp9_prob mod_refprobs[3], int pred_ref) { 2978 static void estimate_curframe_refprobs(VP9_COMP *cpi, vp9_prob mod_refprobs[3], int pred_ref) {
2814 int norm_cnt[MAX_REF_FRAMES]; 2979 int norm_cnt[MAX_REF_FRAMES];
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
2862 static void estimate_ref_frame_costs(VP9_COMP *cpi, int segment_id, unsigned int *ref_costs) { 3027 static void estimate_ref_frame_costs(VP9_COMP *cpi, int segment_id, unsigned int *ref_costs) {
2863 VP9_COMMON *cm = &cpi->common; 3028 VP9_COMMON *cm = &cpi->common;
2864 MACROBLOCKD *xd = &cpi->mb.e_mbd; 3029 MACROBLOCKD *xd = &cpi->mb.e_mbd;
2865 vp9_prob *mod_refprobs; 3030 vp9_prob *mod_refprobs;
2866 3031
2867 unsigned int cost; 3032 unsigned int cost;
2868 int pred_ref; 3033 int pred_ref;
2869 int pred_flag; 3034 int pred_flag;
2870 int pred_ctx; 3035 int pred_ctx;
2871 int i; 3036 int i;
2872 int tot_count;
2873 3037
2874 vp9_prob pred_prob, new_pred_prob; 3038 vp9_prob pred_prob, new_pred_prob;
2875 int seg_ref_active; 3039 int seg_ref_active;
2876 int seg_ref_count = 0; 3040 int seg_ref_count = 0;
2877 seg_ref_active = vp9_segfeature_active(xd, 3041 seg_ref_active = vp9_segfeature_active(xd,
2878 segment_id, 3042 segment_id,
2879 SEG_LVL_REF_FRAME); 3043 SEG_LVL_REF_FRAME);
2880 3044
2881 if (seg_ref_active) { 3045 if (seg_ref_active) {
2882 seg_ref_count = vp9_check_segref(xd, segment_id, INTRA_FRAME) + 3046 seg_ref_count = vp9_check_segref(xd, segment_id, INTRA_FRAME) +
2883 vp9_check_segref(xd, segment_id, LAST_FRAME) + 3047 vp9_check_segref(xd, segment_id, LAST_FRAME) +
2884 vp9_check_segref(xd, segment_id, GOLDEN_FRAME) + 3048 vp9_check_segref(xd, segment_id, GOLDEN_FRAME) +
2885 vp9_check_segref(xd, segment_id, ALTREF_FRAME); 3049 vp9_check_segref(xd, segment_id, ALTREF_FRAME);
2886 } 3050 }
2887 3051
2888 // Get the predicted reference for this mb 3052 // Get the predicted reference for this mb
2889 pred_ref = vp9_get_pred_ref(cm, xd); 3053 pred_ref = vp9_get_pred_ref(cm, xd);
2890 3054
2891 // Get the context probability for the prediction flag (based on last frame) 3055 // Get the context probability for the prediction flag (based on last frame)
2892 pred_prob = vp9_get_pred_prob(cm, xd, PRED_REF); 3056 pred_prob = vp9_get_pred_prob(cm, xd, PRED_REF);
2893 3057
2894 // Predict probability for current frame based on stats so far 3058 // Predict probability for current frame based on stats so far
2895 pred_ctx = vp9_get_pred_context(cm, xd, PRED_REF); 3059 pred_ctx = vp9_get_pred_context(cm, xd, PRED_REF);
2896 tot_count = cpi->ref_pred_count[pred_ctx][0] + cpi->ref_pred_count[pred_ctx][1 ]; 3060 new_pred_prob = get_binary_prob(cpi->ref_pred_count[pred_ctx][0],
2897 if (tot_count) { 3061 cpi->ref_pred_count[pred_ctx][1]);
2898 new_pred_prob =
2899 (cpi->ref_pred_count[pred_ctx][0] * 255 + (tot_count >> 1)) / tot_count;
2900 new_pred_prob += !new_pred_prob;
2901 } else
2902 new_pred_prob = 128;
2903 3062
2904 // Get the set of probabilities to use if prediction fails 3063 // Get the set of probabilities to use if prediction fails
2905 mod_refprobs = cm->mod_refprobs[pred_ref]; 3064 mod_refprobs = cm->mod_refprobs[pred_ref];
2906 3065
2907 // For each possible selected reference frame work out a cost. 3066 // For each possible selected reference frame work out a cost.
2908 for (i = 0; i < MAX_REF_FRAMES; i++) { 3067 for (i = 0; i < MAX_REF_FRAMES; i++) {
2909 if (seg_ref_active && seg_ref_count == 1) { 3068 if (seg_ref_active && seg_ref_count == 1) {
2910 cost = 0; 3069 cost = 0;
2911 } else { 3070 } else {
2912 pred_flag = (i == pred_ref); 3071 pred_flag = (i == pred_ref);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
2947 int mode_index, 3106 int mode_index,
2948 PARTITION_INFO *partition, 3107 PARTITION_INFO *partition,
2949 int_mv *ref_mv, 3108 int_mv *ref_mv,
2950 int_mv *second_ref_mv, 3109 int_mv *second_ref_mv,
2951 int64_t comp_pred_diff[NB_PREDICTION_TYPES], 3110 int64_t comp_pred_diff[NB_PREDICTION_TYPES],
2952 int64_t txfm_size_diff[NB_TXFM_MODES]) { 3111 int64_t txfm_size_diff[NB_TXFM_MODES]) {
2953 MACROBLOCKD *const xd = &x->e_mbd; 3112 MACROBLOCKD *const xd = &x->e_mbd;
2954 3113
2955 // Take a snapshot of the coding context so it can be 3114 // Take a snapshot of the coding context so it can be
2956 // restored if we decide to encode this way 3115 // restored if we decide to encode this way
3116 ctx->skip = x->skip;
2957 ctx->best_mode_index = mode_index; 3117 ctx->best_mode_index = mode_index;
2958 vpx_memcpy(&ctx->mic, xd->mode_info_context, 3118 vpx_memcpy(&ctx->mic, xd->mode_info_context,
2959 sizeof(MODE_INFO)); 3119 sizeof(MODE_INFO));
2960 if (partition) 3120 if (partition)
2961 vpx_memcpy(&ctx->partition_info, partition, 3121 vpx_memcpy(&ctx->partition_info, partition,
2962 sizeof(PARTITION_INFO)); 3122 sizeof(PARTITION_INFO));
2963 ctx->best_ref_mv.as_int = ref_mv->as_int; 3123 ctx->best_ref_mv.as_int = ref_mv->as_int;
2964 ctx->second_best_ref_mv.as_int = second_ref_mv->as_int; 3124 ctx->second_best_ref_mv.as_int = second_ref_mv->as_int;
2965 3125
2966 // ctx[mb_index].rddiv = x->rddiv;
2967 // ctx[mb_index].rdmult = x->rdmult;
2968
2969 ctx->single_pred_diff = comp_pred_diff[SINGLE_PREDICTION_ONLY]; 3126 ctx->single_pred_diff = comp_pred_diff[SINGLE_PREDICTION_ONLY];
2970 ctx->comp_pred_diff = comp_pred_diff[COMP_PREDICTION_ONLY]; 3127 ctx->comp_pred_diff = comp_pred_diff[COMP_PREDICTION_ONLY];
2971 ctx->hybrid_pred_diff = comp_pred_diff[HYBRID_PREDICTION]; 3128 ctx->hybrid_pred_diff = comp_pred_diff[HYBRID_PREDICTION];
2972 3129
2973 memcpy(ctx->txfm_rd_diff, txfm_size_diff, sizeof(ctx->txfm_rd_diff)); 3130 memcpy(ctx->txfm_rd_diff, txfm_size_diff, sizeof(ctx->txfm_rd_diff));
2974 } 3131 }
2975 3132
2976 static void inter_mode_cost(VP9_COMP *cpi, MACROBLOCK *x, 3133 static void inter_mode_cost(VP9_COMP *cpi, MACROBLOCK *x,
2977 int *rate2, int *distortion2, int *rate_y, 3134 int *rate2, int *distortion2, int *rate_y,
2978 int *distortion, int* rate_uv, int *distortion_uv, 3135 int *distortion, int* rate_uv, int *distortion_uv,
(...skipping 14 matching lines...) Expand all
2993 cpi->common.full_pixel, &uv_skippable, 1); 3150 cpi->common.full_pixel, &uv_skippable, 1);
2994 else 3151 else
2995 rd_inter16x16_uv_4x4(cpi, x, rate_uv, distortion_uv, 3152 rd_inter16x16_uv_4x4(cpi, x, rate_uv, distortion_uv,
2996 cpi->common.full_pixel, &uv_skippable, 1); 3153 cpi->common.full_pixel, &uv_skippable, 1);
2997 3154
2998 *rate2 += *rate_uv; 3155 *rate2 += *rate_uv;
2999 *distortion2 += *distortion_uv; 3156 *distortion2 += *distortion_uv;
3000 *skippable = y_skippable && uv_skippable; 3157 *skippable = y_skippable && uv_skippable;
3001 } 3158 }
3002 3159
3003 #define MIN(x,y) (((x)<(y))?(x):(y))
3004 #define MAX(x,y) (((x)>(y))?(x):(y))
3005 static void setup_buffer_inter(VP9_COMP *cpi, MACROBLOCK *x, 3160 static void setup_buffer_inter(VP9_COMP *cpi, MACROBLOCK *x,
3006 int idx, MV_REFERENCE_FRAME frame_type, 3161 int idx, MV_REFERENCE_FRAME frame_type,
3007 int block_size, 3162 int block_size,
3008 int recon_yoffset, int recon_uvoffset, 3163 int recon_yoffset, int recon_uvoffset,
3009 int_mv frame_nearest_mv[MAX_REF_FRAMES], 3164 int_mv frame_nearest_mv[MAX_REF_FRAMES],
3010 int_mv frame_near_mv[MAX_REF_FRAMES], 3165 int_mv frame_near_mv[MAX_REF_FRAMES],
3011 int_mv frame_best_ref_mv[MAX_REF_FRAMES],
3012 int_mv mv_search_ref[MAX_REF_FRAMES],
3013 int frame_mdcounts[4][4], 3166 int frame_mdcounts[4][4],
3014 unsigned char *y_buffer[4], 3167 uint8_t *y_buffer[4],
3015 unsigned char *u_buffer[4], 3168 uint8_t *u_buffer[4],
3016 unsigned char *v_buffer[4]) { 3169 uint8_t *v_buffer[4]) {
3017 YV12_BUFFER_CONFIG *yv12 = &cpi->common.yv12_fb[idx]; 3170 YV12_BUFFER_CONFIG *yv12 = &cpi->common.yv12_fb[idx];
3018 MACROBLOCKD *const xd = &x->e_mbd; 3171 MACROBLOCKD *const xd = &x->e_mbd;
3019 MB_MODE_INFO *const mbmi = &xd->mode_info_context->mbmi; 3172 MB_MODE_INFO *const mbmi = &xd->mode_info_context->mbmi;
3020 3173
3021 y_buffer[frame_type] = yv12->y_buffer + recon_yoffset; 3174 y_buffer[frame_type] = yv12->y_buffer + recon_yoffset;
3022 u_buffer[frame_type] = yv12->u_buffer + recon_uvoffset; 3175 u_buffer[frame_type] = yv12->u_buffer + recon_uvoffset;
3023 v_buffer[frame_type] = yv12->v_buffer + recon_uvoffset; 3176 v_buffer[frame_type] = yv12->v_buffer + recon_uvoffset;
3024 3177
3025 // Gets an initial list of candidate vectors from neighbours and orders them 3178 // Gets an initial list of candidate vectors from neighbours and orders them
3026 vp9_find_mv_refs(xd, xd->mode_info_context, 3179 vp9_find_mv_refs(xd, xd->mode_info_context,
3027 xd->prev_mode_info_context, 3180 xd->prev_mode_info_context,
3028 frame_type, 3181 frame_type,
3029 mbmi->ref_mvs[frame_type], 3182 mbmi->ref_mvs[frame_type],
3030 cpi->common.ref_frame_sign_bias); 3183 cpi->common.ref_frame_sign_bias);
3031 3184
3032 // Candidate refinement carried out at encoder and decoder 3185 // Candidate refinement carried out at encoder and decoder
3033 vp9_find_best_ref_mvs(xd, y_buffer[frame_type], 3186 vp9_find_best_ref_mvs(xd, y_buffer[frame_type],
3034 yv12->y_stride, 3187 yv12->y_stride,
3035 mbmi->ref_mvs[frame_type], 3188 mbmi->ref_mvs[frame_type],
3036 &frame_best_ref_mv[frame_type],
3037 &frame_nearest_mv[frame_type], 3189 &frame_nearest_mv[frame_type],
3038 &frame_near_mv[frame_type]); 3190 &frame_near_mv[frame_type]);
3039 3191
3040 3192
3041 // Further refinement that is encode side only to test the top few candidates 3193 // Further refinement that is encode side only to test the top few candidates
3042 // in full and choose the best as the centre point for subsequent searches. 3194 // in full and choose the best as the centre point for subsequent searches.
3043 mv_pred(cpi, x, y_buffer[frame_type], yv12->y_stride, 3195 mv_pred(cpi, x, y_buffer[frame_type], yv12->y_stride,
3044 &mv_search_ref[frame_type], frame_type, block_size); 3196 frame_type, block_size);
3045 3197
3046 #if CONFIG_NEW_MVREF
3047 // TODO(paulwilkins): Final choice of which of the best 4 candidates from
3048 // above gives lowest error score when used in isolation. This stage encoder
3049 // and sets the reference MV
3050 #endif
3051 } 3198 }
3052 3199
3053 static int64_t handle_inter_mode(VP9_COMP *cpi, MACROBLOCK *x, 3200 static int64_t handle_inter_mode(VP9_COMP *cpi, MACROBLOCK *x,
3054 enum BlockSize block_size, 3201 enum BlockSize block_size,
3055 int *saddone, int near_sadidx[], 3202 int *saddone, int near_sadidx[],
3056 int mdcounts[4], int64_t txfm_cache[], 3203 int mdcounts[4], int64_t txfm_cache[],
3057 int *rate2, int *distortion, int *skippable, 3204 int *rate2, int *distortion, int *skippable,
3058 int *compmode_cost, 3205 int *compmode_cost,
3059 #if CONFIG_COMP_INTERINTRA_PRED 3206 #if CONFIG_COMP_INTERINTRA_PRED
3060 int *compmode_interintra_cost, 3207 int *compmode_interintra_cost,
3061 #endif 3208 #endif
3062 int *rate_y, int *distortion_y, 3209 int *rate_y, int *distortion_y,
3063 int *rate_uv, int *distortion_uv, 3210 int *rate_uv, int *distortion_uv,
3064 int *mode_excluded, int *disable_skip, 3211 int *mode_excluded, int *disable_skip,
3065 int recon_yoffset, int mode_index, 3212 int recon_yoffset, int mode_index,
3066 int_mv frame_mv[MB_MODE_COUNT][MAX_REF_FRAMES], 3213 int_mv frame_mv[MB_MODE_COUNT]
3067 int_mv frame_best_ref_mv[MAX_REF_FRAMES], 3214 [MAX_REF_FRAMES]) {
3068 int_mv mv_search_ref[MAX_REF_FRAMES]) {
3069 VP9_COMMON *cm = &cpi->common; 3215 VP9_COMMON *cm = &cpi->common;
3070 MACROBLOCKD *xd = &x->e_mbd; 3216 MACROBLOCKD *xd = &x->e_mbd;
3071 MB_MODE_INFO *mbmi = &xd->mode_info_context->mbmi; 3217 MB_MODE_INFO *mbmi = &xd->mode_info_context->mbmi;
3072 BLOCK *b = &x->block[0]; 3218 BLOCK *b = &x->block[0];
3073 BLOCKD *d = &xd->block[0]; 3219 BLOCKD *d = &xd->block[0];
3074 const int is_comp_pred = (mbmi->second_ref_frame > 0); 3220 const int is_comp_pred = (mbmi->second_ref_frame > 0);
3075 #if CONFIG_COMP_INTERINTRA_PRED 3221 #if CONFIG_COMP_INTERINTRA_PRED
3076 const int is_comp_interintra_pred = (mbmi->second_ref_frame == INTRA_FRAME); 3222 const int is_comp_interintra_pred = (mbmi->second_ref_frame == INTRA_FRAME);
3077 #endif 3223 #endif
3078 const int num_refs = is_comp_pred ? 2 : 1; 3224 const int num_refs = is_comp_pred ? 2 : 1;
3079 const int this_mode = mbmi->mode; 3225 const int this_mode = mbmi->mode;
3080 int i; 3226 int i;
3081 int refs[2] = { mbmi->ref_frame, 3227 int refs[2] = { mbmi->ref_frame,
3082 (mbmi->second_ref_frame < 0 ? 0 : mbmi->second_ref_frame) }; 3228 (mbmi->second_ref_frame < 0 ? 0 : mbmi->second_ref_frame) };
3083 int_mv cur_mv[2]; 3229 int_mv cur_mv[2];
3230 int_mv ref_mv[2];
3084 int64_t this_rd = 0; 3231 int64_t this_rd = 0;
3085 3232
3086 switch (this_mode) { 3233 switch (this_mode) {
3087 case NEWMV: 3234 case NEWMV:
3235 ref_mv[0] = mbmi->ref_mvs[refs[0]][0];
3236 ref_mv[1] = mbmi->ref_mvs[refs[1]][0];
3237
3088 if (is_comp_pred) { 3238 if (is_comp_pred) {
3089 if (frame_mv[NEWMV][refs[0]].as_int == INVALID_MV || 3239 if (frame_mv[NEWMV][refs[0]].as_int == INVALID_MV ||
3090 frame_mv[NEWMV][refs[1]].as_int == INVALID_MV) 3240 frame_mv[NEWMV][refs[1]].as_int == INVALID_MV)
3091 return INT64_MAX; 3241 return INT64_MAX;
3092 *rate2 += vp9_mv_bit_cost(&frame_mv[NEWMV][refs[0]], 3242 *rate2 += vp9_mv_bit_cost(&frame_mv[NEWMV][refs[0]],
3093 &frame_best_ref_mv[refs[0]], 3243 &ref_mv[0],
3094 x->nmvjointcost, x->mvcost, 96, 3244 x->nmvjointcost, x->mvcost, 96,
3095 x->e_mbd.allow_high_precision_mv); 3245 x->e_mbd.allow_high_precision_mv);
3096 *rate2 += vp9_mv_bit_cost(&frame_mv[NEWMV][refs[1]], 3246 *rate2 += vp9_mv_bit_cost(&frame_mv[NEWMV][refs[1]],
3097 &frame_best_ref_mv[refs[1]], 3247 &ref_mv[1],
3098 x->nmvjointcost, x->mvcost, 96, 3248 x->nmvjointcost, x->mvcost, 96,
3099 x->e_mbd.allow_high_precision_mv); 3249 x->e_mbd.allow_high_precision_mv);
3100 } else { 3250 } else {
3101 int bestsme = INT_MAX; 3251 int bestsme = INT_MAX;
3102 int further_steps, step_param = cpi->sf.first_step; 3252 int further_steps, step_param = cpi->sf.first_step;
3103 int sadpb = x->sadperbit16; 3253 int sadpb = x->sadperbit16;
3104 int_mv mvp_full, tmp_mv; 3254 int_mv mvp_full, tmp_mv;
3105 int sr = 0; 3255 int sr = 0;
3106 3256
3107 int tmp_col_min = x->mv_col_min; 3257 int tmp_col_min = x->mv_col_min;
3108 int tmp_col_max = x->mv_col_max; 3258 int tmp_col_max = x->mv_col_max;
3109 int tmp_row_min = x->mv_row_min; 3259 int tmp_row_min = x->mv_row_min;
3110 int tmp_row_max = x->mv_row_max; 3260 int tmp_row_max = x->mv_row_max;
3111 3261
3112 vp9_clamp_mv_min_max(x, &frame_best_ref_mv[refs[0]]); 3262 vp9_clamp_mv_min_max(x, &ref_mv[0]);
3113 3263
3114 mvp_full.as_mv.col = mv_search_ref[mbmi->ref_frame].as_mv.col >> 3; 3264 // mvp_full.as_int = ref_mv[0].as_int;
3115 mvp_full.as_mv.row = mv_search_ref[mbmi->ref_frame].as_mv.row >> 3; 3265 mvp_full.as_int =
3266 mbmi->ref_mvs[refs[0]][x->mv_best_ref_index[refs[0]]].as_int;
3267
3268 mvp_full.as_mv.col >>= 3;
3269 mvp_full.as_mv.row >>= 3;
3270 if (mvp_full.as_int != mvp_full.as_int) {
3271 mvp_full.as_int = mvp_full.as_int;
3272 }
3116 3273
3117 // adjust search range according to sr from mv prediction 3274 // adjust search range according to sr from mv prediction
3118 step_param = MAX(step_param, sr); 3275 step_param = MAX(step_param, sr);
3119 3276
3120 // Further step/diamond searches as necessary 3277 // Further step/diamond searches as necessary
3121 further_steps = (cpi->sf.max_step_search_steps - 1) - step_param; 3278 further_steps = (cpi->sf.max_step_search_steps - 1) - step_param;
3122 3279
3123 bestsme = vp9_full_pixel_diamond(cpi, x, b, d, &mvp_full, step_param, 3280 bestsme = vp9_full_pixel_diamond(cpi, x, b, d, &mvp_full, step_param,
3124 sadpb, further_steps, 1, 3281 sadpb, further_steps, 1,
3125 &cpi->fn_ptr[block_size], 3282 &cpi->fn_ptr[block_size],
3126 &frame_best_ref_mv[refs[0]], &tmp_mv); 3283 &ref_mv[0], &tmp_mv);
3127 3284
3128 x->mv_col_min = tmp_col_min; 3285 x->mv_col_min = tmp_col_min;
3129 x->mv_col_max = tmp_col_max; 3286 x->mv_col_max = tmp_col_max;
3130 x->mv_row_min = tmp_row_min; 3287 x->mv_row_min = tmp_row_min;
3131 x->mv_row_max = tmp_row_max; 3288 x->mv_row_max = tmp_row_max;
3132 3289
3133 if (bestsme < INT_MAX) { 3290 if (bestsme < INT_MAX) {
3134 int dis; /* TODO: use dis in distortion calculation later. */ 3291 int dis; /* TODO: use dis in distortion calculation later. */
3135 unsigned int sse; 3292 unsigned int sse;
3136 cpi->find_fractional_mv_step(x, b, d, &tmp_mv, 3293 cpi->find_fractional_mv_step(x, b, d, &tmp_mv,
3137 &frame_best_ref_mv[refs[0]], 3294 &ref_mv[0],
3138 x->errorperbit, 3295 x->errorperbit,
3139 &cpi->fn_ptr[block_size], 3296 &cpi->fn_ptr[block_size],
3140 x->nmvjointcost, x->mvcost, 3297 x->nmvjointcost, x->mvcost,
3141 &dis, &sse); 3298 &dis, &sse);
3142 } 3299 }
3143 d->bmi.as_mv.first.as_int = tmp_mv.as_int; 3300 d->bmi.as_mv.first.as_int = tmp_mv.as_int;
3144 frame_mv[NEWMV][refs[0]].as_int = d->bmi.as_mv.first.as_int; 3301 frame_mv[NEWMV][refs[0]].as_int = d->bmi.as_mv.first.as_int;
3145 3302
3146 // Add the new motion vector cost to our rolling cost variable 3303 // Add the new motion vector cost to our rolling cost variable
3147 *rate2 += vp9_mv_bit_cost(&tmp_mv, &frame_best_ref_mv[refs[0]], 3304 *rate2 += vp9_mv_bit_cost(&tmp_mv, &ref_mv[0],
3148 x->nmvjointcost, x->mvcost, 3305 x->nmvjointcost, x->mvcost,
3149 96, xd->allow_high_precision_mv); 3306 96, xd->allow_high_precision_mv);
3150 } 3307 }
3151 break; 3308 break;
3152 case NEARESTMV: 3309 case NEARESTMV:
3153 case NEARMV: 3310 case NEARMV:
3154 // Do not bother proceeding if the vector (from newmv, nearest or 3311 // Do not bother proceeding if the vector (from newmv, nearest or
3155 // near) is 0,0 as this should then be coded using the zeromv mode. 3312 // near) is 0,0 as this should then be coded using the zeromv mode.
3156 for (i = 0; i < num_refs; ++i) 3313 for (i = 0; i < num_refs; ++i)
3157 if (frame_mv[this_mode][refs[i]].as_int == 0) 3314 if (frame_mv[this_mode][refs[i]].as_int == 0)
3158 return INT64_MAX; 3315 return INT64_MAX;
3159 case ZEROMV: 3316 case ZEROMV:
3160 default: 3317 default:
3161 break; 3318 break;
3162 } 3319 }
3163 for (i = 0; i < num_refs; ++i) { 3320 for (i = 0; i < num_refs; ++i) {
3164 cur_mv[i] = frame_mv[this_mode][refs[i]]; 3321 cur_mv[i] = frame_mv[this_mode][refs[i]];
3165 // Clip "next_nearest" so that it does not extend to far out of image 3322 // Clip "next_nearest" so that it does not extend to far out of image
3166 clamp_mv2(&cur_mv[i], xd); 3323 clamp_mv2(&cur_mv[i], xd);
3167 if (mv_check_bounds(x, &cur_mv[i])) 3324 if (mv_check_bounds(x, &cur_mv[i]))
3168 return INT64_MAX; 3325 return INT64_MAX;
3169 mbmi->mv[i].as_int = cur_mv[i].as_int; 3326 mbmi->mv[i].as_int = cur_mv[i].as_int;
3170 } 3327 }
3171 3328
3172 #if CONFIG_PRED_FILTER
3173 // Filtered prediction:
3174 mbmi->pred_filter_enabled = vp9_mode_order[mode_index].pred_filter_flag;
3175 *rate2 += vp9_cost_bit(cpi->common.prob_pred_filter_off,
3176 mbmi->pred_filter_enabled);
3177 #endif
3178 if (cpi->common.mcomp_filter_type == SWITCHABLE) { 3329 if (cpi->common.mcomp_filter_type == SWITCHABLE) {
3179 const int c = vp9_get_pred_context(cm, xd, PRED_SWITCHABLE_INTERP); 3330 const int c = vp9_get_pred_context(cm, xd, PRED_SWITCHABLE_INTERP);
3180 const int m = vp9_switchable_interp_map[mbmi->interp_filter]; 3331 const int m = vp9_switchable_interp_map[mbmi->interp_filter];
3181 *rate2 += SWITCHABLE_INTERP_RATE_FACTOR * x->switchable_interp_costs[c][m]; 3332 *rate2 += SWITCHABLE_INTERP_RATE_FACTOR * x->switchable_interp_costs[c][m];
3182 } 3333 }
3183 3334
3184 /* We don't include the cost of the second reference here, because there 3335 /* We don't include the cost of the second reference here, because there
3185 * are only three options: Last/Golden, ARF/Last or Golden/ARF, or in other 3336 * are only three options: Last/Golden, ARF/Last or Golden/ARF, or in other
3186 * words if you present them in that order, the second one is always known 3337 * words if you present them in that order, the second one is always known
3187 * if the first is known */ 3338 * if the first is known */
3188 *compmode_cost = vp9_cost_bit(vp9_get_pred_prob(cm, xd, PRED_COMP), 3339 *compmode_cost = vp9_cost_bit(vp9_get_pred_prob(cm, xd, PRED_COMP),
3189 is_comp_pred); 3340 is_comp_pred);
3190 *rate2 += vp9_cost_mv_ref(cpi, this_mode, 3341 *rate2 += vp9_cost_mv_ref(cpi, this_mode,
3191 mbmi->mb_mode_context[mbmi->ref_frame]); 3342 mbmi->mb_mode_context[mbmi->ref_frame]);
3192 #if CONFIG_COMP_INTERINTRA_PRED 3343 #if CONFIG_COMP_INTERINTRA_PRED
3193 if (!is_comp_pred) { 3344 if (!is_comp_pred) {
3194 *compmode_interintra_cost = vp9_cost_bit(cm->fc.interintra_prob, 3345 *compmode_interintra_cost = vp9_cost_bit(cm->fc.interintra_prob,
3195 is_comp_interintra_pred); 3346 is_comp_interintra_pred);
3196 if (is_comp_interintra_pred) { 3347 if (is_comp_interintra_pred) {
3197 *compmode_interintra_cost += 3348 *compmode_interintra_cost +=
3198 x->mbmode_cost[xd->frame_type][mbmi->interintra_mode]; 3349 x->mbmode_cost[xd->frame_type][mbmi->interintra_mode];
3199 #if SEPARATE_INTERINTRA_UV 3350 #if SEPARATE_INTERINTRA_UV
3200 *compmode_interintra_cost += 3351 *compmode_interintra_cost +=
3201 x->intra_uv_mode_cost[xd->frame_type][mbmi->interintra_uv_mode]; 3352 x->intra_uv_mode_cost[xd->frame_type][mbmi->interintra_uv_mode];
3202 #endif 3353 #endif
3203 } 3354 }
3204 } 3355 }
3205 #endif 3356 #endif
3206 3357
3207 if (block_size == BLOCK_16X16) { 3358 if (block_size == BLOCK_64X64) {
3359 vp9_build_inter64x64_predictors_sb(xd,
3360 xd->dst.y_buffer,
3361 xd->dst.u_buffer,
3362 xd->dst.v_buffer,
3363 xd->dst.y_stride,
3364 xd->dst.uv_stride);
3365 } else if (block_size == BLOCK_32X32) {
3366 vp9_build_inter32x32_predictors_sb(xd,
3367 xd->dst.y_buffer,
3368 xd->dst.u_buffer,
3369 xd->dst.v_buffer,
3370 xd->dst.y_stride,
3371 xd->dst.uv_stride);
3372 } else {
3373 assert(block_size == BLOCK_16X16);
3208 vp9_build_1st_inter16x16_predictors_mby(xd, xd->predictor, 16, 0); 3374 vp9_build_1st_inter16x16_predictors_mby(xd, xd->predictor, 16, 0);
3209 if (is_comp_pred) 3375 if (is_comp_pred)
3210 vp9_build_2nd_inter16x16_predictors_mby(xd, xd->predictor, 16); 3376 vp9_build_2nd_inter16x16_predictors_mby(xd, xd->predictor, 16);
3211 #if CONFIG_COMP_INTERINTRA_PRED 3377 #if CONFIG_COMP_INTERINTRA_PRED
3212 if (is_comp_interintra_pred) { 3378 if (is_comp_interintra_pred) {
3213 vp9_build_interintra_16x16_predictors_mby(xd, xd->predictor, 16); 3379 vp9_build_interintra_16x16_predictors_mby(xd, xd->predictor, 16);
3214 } 3380 }
3215 #endif 3381 #endif
3216 } else {
3217 #if CONFIG_SUPERBLOCKS
3218 vp9_build_inter32x32_predictors_sb(xd,
3219 xd->dst.y_buffer,
3220 xd->dst.u_buffer,
3221 xd->dst.v_buffer,
3222 xd->dst.y_stride,
3223 xd->dst.uv_stride);
3224 #endif
3225 } 3382 }
3226 3383
3227 if (cpi->active_map_enabled && x->active_ptr[0] == 0) 3384 if (cpi->active_map_enabled && x->active_ptr[0] == 0)
3228 x->skip = 1; 3385 x->skip = 1;
3229 else if (x->encode_breakout) { 3386 else if (x->encode_breakout) {
3230 unsigned int sse, var; 3387 unsigned int sse, var;
3231 int threshold = (xd->block[0].dequant[1] 3388 int threshold = (xd->block[0].dequant[1]
3232 * xd->block[0].dequant[1] >> 4); 3389 * xd->block[0].dequant[1] >> 4);
3233 3390
3234 if (threshold < x->encode_breakout) 3391 if (threshold < x->encode_breakout)
3235 threshold = x->encode_breakout; 3392 threshold = x->encode_breakout;
3236 3393
3237 if (block_size == BLOCK_16X16) { 3394 if (block_size == BLOCK_64X64) {
3395 var = vp9_variance64x64(*(b->base_src), b->src_stride,
3396 xd->dst.y_buffer, xd->dst.y_stride, &sse);
3397 } else if (block_size == BLOCK_32X32) {
3398 var = vp9_variance32x32(*(b->base_src), b->src_stride,
3399 xd->dst.y_buffer, xd->dst.y_stride, &sse);
3400 } else {
3401 assert(block_size == BLOCK_16X16);
3238 var = vp9_variance16x16(*(b->base_src), b->src_stride, 3402 var = vp9_variance16x16(*(b->base_src), b->src_stride,
3239 xd->predictor, 16, &sse); 3403 xd->predictor, 16, &sse);
3240 } else {
3241 #if CONFIG_SUPERBLOCKS
3242 var = vp9_variance32x32(*(b->base_src), b->src_stride,
3243 xd->dst.y_buffer, xd->dst.y_stride, &sse);
3244 #endif
3245 } 3404 }
3246 3405
3247 if ((int)sse < threshold) { 3406 if ((int)sse < threshold) {
3248 unsigned int q2dc = xd->block[24].dequant[0]; 3407 unsigned int q2dc = xd->block[24].dequant[0];
3249 /* If there is no codeable 2nd order dc 3408 /* If there is no codeable 2nd order dc
3250 or a very small uniform pixel change change */ 3409 or a very small uniform pixel change change */
3251 if ((sse - var < q2dc * q2dc >> 4) || 3410 if ((sse - var < q2dc * q2dc >> 4) ||
3252 (sse / 2 > var && sse - var < 64)) { 3411 (sse / 2 > var && sse - var < 64)) {
3253 // Check u and v to make sure skip is ok 3412 // Check u and v to make sure skip is ok
3254 int sse2; 3413 int sse2;
3255 3414
3256 if (block_size == BLOCK_16X16) { 3415 if (block_size == BLOCK_64X64) {
3257 sse2 = vp9_uvsse(x); 3416 unsigned int sse2u, sse2v;
3258 } else { 3417 var = vp9_variance32x32(x->src.u_buffer, x->src.uv_stride,
3418 xd->dst.u_buffer, xd->dst.uv_stride, &sse2u);
3419 var = vp9_variance32x32(x->src.v_buffer, x->src.uv_stride,
3420 xd->dst.v_buffer, xd->dst.uv_stride, &sse2v);
3421 sse2 = sse2u + sse2v;
3422 } else if (block_size == BLOCK_32X32) {
3259 unsigned int sse2u, sse2v; 3423 unsigned int sse2u, sse2v;
3260 var = vp9_variance16x16(x->src.u_buffer, x->src.uv_stride, 3424 var = vp9_variance16x16(x->src.u_buffer, x->src.uv_stride,
3261 xd->dst.u_buffer, xd->dst.uv_stride, &sse2u); 3425 xd->dst.u_buffer, xd->dst.uv_stride, &sse2u);
3262 var = vp9_variance16x16(x->src.v_buffer, x->src.uv_stride, 3426 var = vp9_variance16x16(x->src.v_buffer, x->src.uv_stride,
3263 xd->dst.v_buffer, xd->dst.uv_stride, &sse2v); 3427 xd->dst.v_buffer, xd->dst.uv_stride, &sse2v);
3264 sse2 = sse2u + sse2v; 3428 sse2 = sse2u + sse2v;
3429 } else {
3430 assert(block_size == BLOCK_16X16);
3431 sse2 = vp9_uvsse(x);
3265 } 3432 }
3266 3433
3267 if (sse2 * 2 < threshold) { 3434 if (sse2 * 2 < threshold) {
3268 x->skip = 1; 3435 x->skip = 1;
3269 *distortion = sse + sse2; 3436 *distortion = sse + sse2;
3270 *rate2 = 500; 3437 *rate2 = 500;
3271 3438
3272 /* for best_yrd calculation */ 3439 /* for best_yrd calculation */
3273 *rate_uv = 0; 3440 *rate_uv = 0;
3274 *distortion_uv = sse2; 3441 *distortion_uv = sse2;
3275 3442
3276 *disable_skip = 1; 3443 *disable_skip = 1;
3277 this_rd = RDCOST(x->rdmult, x->rddiv, *rate2, *distortion); 3444 this_rd = RDCOST(x->rdmult, x->rddiv, *rate2, *distortion);
3278 } 3445 }
3279 } 3446 }
3280 } 3447 }
3281 } 3448 }
3282 3449
3283 if (is_comp_pred) { 3450 if (!(*mode_excluded)) {
3284 *mode_excluded = (cpi->common.comp_pred_mode == SINGLE_PREDICTION_ONLY); 3451 if (is_comp_pred) {
3285 } else { 3452 *mode_excluded = (cpi->common.comp_pred_mode == SINGLE_PREDICTION_ONLY);
3286 *mode_excluded = (cpi->common.comp_pred_mode == COMP_PREDICTION_ONLY); 3453 } else {
3454 *mode_excluded = (cpi->common.comp_pred_mode == COMP_PREDICTION_ONLY);
3455 }
3456 #if CONFIG_COMP_INTERINTRA_PRED
3457 if (is_comp_interintra_pred && !cm->use_interintra) *mode_excluded = 1;
3458 #endif
3287 } 3459 }
3288 #if CONFIG_COMP_INTERINTRA_PRED
3289 if (is_comp_interintra_pred && !cm->use_interintra) *mode_excluded = 1;
3290 #endif
3291 3460
3292 if (!x->skip) { 3461 if (!x->skip) {
3293 if (block_size == BLOCK_16X16) { 3462 if (block_size == BLOCK_64X64) {
3294 vp9_build_1st_inter16x16_predictors_mbuv(xd, &xd->predictor[256], 3463 int skippable_y, skippable_uv;
3295 &xd->predictor[320], 8); 3464
3296 if (is_comp_pred) 3465 // Y cost and distortion
3297 vp9_build_2nd_inter16x16_predictors_mbuv(xd, &xd->predictor[256], 3466 super_block_64_yrd(cpi, x, rate_y, distortion_y,
3298 &xd->predictor[320], 8); 3467 &skippable_y, txfm_cache);
3299 #if CONFIG_COMP_INTERINTRA_PRED 3468 *rate2 += *rate_y;
3300 if (is_comp_interintra_pred) { 3469 *distortion += *distortion_y;
3301 vp9_build_interintra_16x16_predictors_mbuv(xd, &xd->predictor[256], 3470
3302 &xd->predictor[320], 8); 3471 rd_inter64x64_uv(cpi, x, rate_uv, distortion_uv,
3303 } 3472 cm->full_pixel, &skippable_uv);
3304 #endif 3473
3305 inter_mode_cost(cpi, x, rate2, distortion, 3474 *rate2 += *rate_uv;
3306 rate_y, distortion_y, rate_uv, distortion_uv, 3475 *distortion += *distortion_uv;
3307 skippable, txfm_cache); 3476 *skippable = skippable_y && skippable_uv;
3308 } else { 3477 } else if (block_size == BLOCK_32X32) {
3309 #if CONFIG_SUPERBLOCKS
3310 int skippable_y, skippable_uv; 3478 int skippable_y, skippable_uv;
3311 3479
3312 // Y cost and distortion 3480 // Y cost and distortion
3313 super_block_yrd(cpi, x, rate_y, distortion_y, 3481 super_block_yrd(cpi, x, rate_y, distortion_y,
3314 &skippable_y, txfm_cache); 3482 &skippable_y, txfm_cache);
3315 *rate2 += *rate_y; 3483 *rate2 += *rate_y;
3316 *distortion += *distortion_y; 3484 *distortion += *distortion_y;
3317 3485
3318 rd_inter32x32_uv(cpi, x, rate_uv, distortion_uv, 3486 rd_inter32x32_uv(cpi, x, rate_uv, distortion_uv,
3319 cm->full_pixel, &skippable_uv); 3487 cm->full_pixel, &skippable_uv);
3320 3488
3321 *rate2 += *rate_uv; 3489 *rate2 += *rate_uv;
3322 *distortion += *distortion_uv; 3490 *distortion += *distortion_uv;
3323 *skippable = skippable_y && skippable_uv; 3491 *skippable = skippable_y && skippable_uv;
3492 } else {
3493 assert(block_size == BLOCK_16X16);
3494
3495 vp9_build_1st_inter16x16_predictors_mbuv(xd, &xd->predictor[256],
3496 &xd->predictor[320], 8);
3497 if (is_comp_pred)
3498 vp9_build_2nd_inter16x16_predictors_mbuv(xd, &xd->predictor[256],
3499 &xd->predictor[320], 8);
3500 #if CONFIG_COMP_INTERINTRA_PRED
3501 if (is_comp_interintra_pred) {
3502 vp9_build_interintra_16x16_predictors_mbuv(xd, &xd->predictor[256],
3503 &xd->predictor[320], 8);
3504 }
3324 #endif 3505 #endif
3506 inter_mode_cost(cpi, x, rate2, distortion,
3507 rate_y, distortion_y, rate_uv, distortion_uv,
3508 skippable, txfm_cache);
3325 } 3509 }
3326 } 3510 }
3327 return this_rd; // if 0, this will be re-calculated by caller 3511 return this_rd; // if 0, this will be re-calculated by caller
3328 } 3512 }
3329 3513
3330 static void rd_pick_inter_mode(VP9_COMP *cpi, MACROBLOCK *x, 3514 static void rd_pick_inter_mode(VP9_COMP *cpi, MACROBLOCK *x,
3331 int recon_yoffset, int recon_uvoffset, 3515 int recon_yoffset, int recon_uvoffset,
3332 int *returnrate, int *returndistortion, 3516 int *returnrate, int *returndistortion,
3333 int64_t *returnintra) { 3517 int64_t *returnintra) {
3334 VP9_COMMON *cm = &cpi->common; 3518 VP9_COMMON *cm = &cpi->common;
3335 MACROBLOCKD *xd = &x->e_mbd; 3519 MACROBLOCKD *xd = &x->e_mbd;
3336 union b_mode_info best_bmodes[16]; 3520 union b_mode_info best_bmodes[16];
3337 MB_MODE_INFO best_mbmode; 3521 MB_MODE_INFO best_mbmode;
3338 PARTITION_INFO best_partition; 3522 PARTITION_INFO best_partition;
3339 int_mv best_ref_mv, second_best_ref_mv; 3523 int_mv best_ref_mv, second_best_ref_mv;
3340 MB_PREDICTION_MODE this_mode; 3524 MB_PREDICTION_MODE this_mode;
3525 MB_PREDICTION_MODE best_mode = DC_PRED;
3341 MB_MODE_INFO * mbmi = &xd->mode_info_context->mbmi; 3526 MB_MODE_INFO * mbmi = &xd->mode_info_context->mbmi;
3342 int i, best_mode_index = 0; 3527 int i, best_mode_index = 0;
3343 int mode8x8[2][4]; 3528 int mode8x8[4];
3344 unsigned char segment_id = mbmi->segment_id; 3529 unsigned char segment_id = mbmi->segment_id;
3345 3530
3346 int mode_index; 3531 int mode_index;
3347 int mdcounts[4]; 3532 int mdcounts[4];
3348 int rate, distortion; 3533 int rate, distortion;
3349 int rate2, distortion2; 3534 int rate2, distortion2;
3350 int64_t best_txfm_rd[NB_TXFM_MODES]; 3535 int64_t best_txfm_rd[NB_TXFM_MODES];
3351 int64_t best_txfm_diff[NB_TXFM_MODES]; 3536 int64_t best_txfm_diff[NB_TXFM_MODES];
3352 int64_t best_pred_diff[NB_PREDICTION_TYPES]; 3537 int64_t best_pred_diff[NB_PREDICTION_TYPES];
3353 int64_t best_pred_rd[NB_PREDICTION_TYPES]; 3538 int64_t best_pred_rd[NB_PREDICTION_TYPES];
3354 int64_t best_rd = INT64_MAX, best_intra_rd = INT64_MAX; 3539 int64_t best_rd = INT64_MAX, best_intra_rd = INT64_MAX;
3355 #if CONFIG_COMP_INTERINTRA_PRED 3540 #if CONFIG_COMP_INTERINTRA_PRED
3356 int is_best_interintra = 0; 3541 int is_best_interintra = 0;
3357 int64_t best_intra16_rd = INT64_MAX; 3542 int64_t best_intra16_rd = INT64_MAX;
3358 int best_intra16_mode = DC_PRED, best_intra16_uv_mode = DC_PRED; 3543 int best_intra16_mode = DC_PRED, best_intra16_uv_mode = DC_PRED;
3359 #endif 3544 #endif
3360 int64_t best_overall_rd = INT64_MAX; 3545 int64_t best_overall_rd = INT64_MAX;
3546 INTERPOLATIONFILTERTYPE best_filter = SWITCHABLE;
3361 int uv_intra_rate, uv_intra_distortion, uv_intra_rate_tokenonly; 3547 int uv_intra_rate, uv_intra_distortion, uv_intra_rate_tokenonly;
3362 int uv_intra_skippable = 0; 3548 int uv_intra_skippable = 0;
3363 int uv_intra_rate_8x8 = 0, uv_intra_distortion_8x8 = 0, uv_intra_rate_tokenonl y_8x8 = 0; 3549 int uv_intra_rate_8x8 = 0, uv_intra_distortion_8x8 = 0, uv_intra_rate_tokenonl y_8x8 = 0;
3364 int uv_intra_skippable_8x8 = 0; 3550 int uv_intra_skippable_8x8 = 0;
3365 int rate_y, UNINITIALIZED_IS_SAFE(rate_uv); 3551 int rate_y, UNINITIALIZED_IS_SAFE(rate_uv);
3366 int distortion_uv = INT_MAX; 3552 int distortion_uv = INT_MAX;
3367 int64_t best_yrd = INT64_MAX; 3553 int64_t best_yrd = INT64_MAX;
3368 #if CONFIG_PRED_FILTER
3369 int best_filter_state = 0;
3370 #endif
3371 int switchable_filter_index = 0; 3554 int switchable_filter_index = 0;
3372 3555
3373 MB_PREDICTION_MODE uv_intra_mode; 3556 MB_PREDICTION_MODE uv_intra_mode;
3374 MB_PREDICTION_MODE uv_intra_mode_8x8 = 0; 3557 MB_PREDICTION_MODE uv_intra_mode_8x8 = 0;
3375 3558
3376 int near_sadidx[8] = {0, 1, 2, 3, 4, 5, 6, 7}; 3559 int near_sadidx[8] = {0, 1, 2, 3, 4, 5, 6, 7};
3377 int saddone = 0; 3560 int saddone = 0;
3378 3561
3379 int_mv frame_mv[MB_MODE_COUNT][MAX_REF_FRAMES]; 3562 int_mv frame_mv[MB_MODE_COUNT][MAX_REF_FRAMES];
3380 int_mv frame_best_ref_mv[MAX_REF_FRAMES];
3381 int_mv mv_search_ref[MAX_REF_FRAMES];
3382 int frame_mdcounts[4][4]; 3563 int frame_mdcounts[4][4];
3383 unsigned char *y_buffer[4], *u_buffer[4], *v_buffer[4]; 3564 uint8_t *y_buffer[4], *u_buffer[4], *v_buffer[4];
3384 3565
3385 unsigned int ref_costs[MAX_REF_FRAMES]; 3566 unsigned int ref_costs[MAX_REF_FRAMES];
3386 int_mv seg_mvs[NB_PARTITIONINGS][16 /* n_blocks */][MAX_REF_FRAMES - 1]; 3567 int_mv seg_mvs[NB_PARTITIONINGS][16 /* n_blocks */][MAX_REF_FRAMES - 1];
3387 3568
3388 int intra_cost_penalty = 20 * vp9_dc_quant(cpi->common.base_qindex, 3569 int intra_cost_penalty = 20 * vp9_dc_quant(cpi->common.base_qindex,
3389 cpi->common.y1dc_delta_q); 3570 cpi->common.y1dc_delta_q);
3390 3571
3391 vpx_memset(mode8x8, 0, sizeof(mode8x8)); 3572 vpx_memset(mode8x8, 0, sizeof(mode8x8));
3392 vpx_memset(&frame_mv, 0, sizeof(frame_mv)); 3573 vpx_memset(&frame_mv, 0, sizeof(frame_mv));
3393 vpx_memset(&best_mbmode, 0, sizeof(best_mbmode)); 3574 vpx_memset(&best_mbmode, 0, sizeof(best_mbmode));
3394 vpx_memset(&best_bmodes, 0, sizeof(best_bmodes)); 3575 vpx_memset(&best_bmodes, 0, sizeof(best_bmodes));
3395 vpx_memset(&x->mb_context[xd->mb_index], 0, sizeof(PICK_MODE_CONTEXT)); 3576 vpx_memset(&x->mb_context[xd->sb_index][xd->mb_index], 0,
3577 sizeof(PICK_MODE_CONTEXT));
3396 3578
3397 for (i = 0; i < MAX_REF_FRAMES; i++) 3579 for (i = 0; i < MAX_REF_FRAMES; i++)
3398 frame_mv[NEWMV][i].as_int = INVALID_MV; 3580 frame_mv[NEWMV][i].as_int = INVALID_MV;
3399 for (i = 0; i < NB_PREDICTION_TYPES; ++i) 3581 for (i = 0; i < NB_PREDICTION_TYPES; ++i)
3400 best_pred_rd[i] = INT64_MAX; 3582 best_pred_rd[i] = INT64_MAX;
3401 for (i = 0; i < NB_TXFM_MODES; i++) 3583 for (i = 0; i < NB_TXFM_MODES; i++)
3402 best_txfm_rd[i] = INT64_MAX; 3584 best_txfm_rd[i] = INT64_MAX;
3403 3585
3404 for (i = 0; i < NB_PARTITIONINGS; i++) { 3586 for (i = 0; i < NB_PARTITIONINGS; i++) {
3405 int j, k; 3587 int j, k;
3406 3588
3407 for (j = 0; j < 16; j++) 3589 for (j = 0; j < 16; j++)
3408 for (k = 0; k < MAX_REF_FRAMES - 1; k++) 3590 for (k = 0; k < MAX_REF_FRAMES - 1; k++)
3409 seg_mvs[i][j][k].as_int = INVALID_MV; 3591 seg_mvs[i][j][k].as_int = INVALID_MV;
3410 } 3592 }
3411 3593
3412 if (cpi->ref_frame_flags & VP9_LAST_FLAG) { 3594 if (cpi->ref_frame_flags & VP9_LAST_FLAG) {
3413 setup_buffer_inter(cpi, x, cpi->common.lst_fb_idx, LAST_FRAME, 3595 setup_buffer_inter(cpi, x, cpi->common.lst_fb_idx, LAST_FRAME,
3414 BLOCK_16X16, recon_yoffset, recon_uvoffset, 3596 BLOCK_16X16, recon_yoffset, recon_uvoffset,
3415 frame_mv[NEARESTMV], frame_mv[NEARMV], frame_best_ref_mv, 3597 frame_mv[NEARESTMV], frame_mv[NEARMV],
3416 mv_search_ref, frame_mdcounts, 3598 frame_mdcounts, y_buffer, u_buffer, v_buffer);
3417 y_buffer, u_buffer, v_buffer);
3418 } 3599 }
3419 3600
3420 if (cpi->ref_frame_flags & VP9_GOLD_FLAG) { 3601 if (cpi->ref_frame_flags & VP9_GOLD_FLAG) {
3421 setup_buffer_inter(cpi, x, cpi->common.gld_fb_idx, GOLDEN_FRAME, 3602 setup_buffer_inter(cpi, x, cpi->common.gld_fb_idx, GOLDEN_FRAME,
3422 BLOCK_16X16, recon_yoffset, recon_uvoffset, 3603 BLOCK_16X16, recon_yoffset, recon_uvoffset,
3423 frame_mv[NEARESTMV], frame_mv[NEARMV], frame_best_ref_mv, 3604 frame_mv[NEARESTMV], frame_mv[NEARMV],
3424 mv_search_ref, frame_mdcounts, 3605 frame_mdcounts, y_buffer, u_buffer, v_buffer);
3425 y_buffer, u_buffer, v_buffer);
3426 } 3606 }
3427 3607
3428 if (cpi->ref_frame_flags & VP9_ALT_FLAG) { 3608 if (cpi->ref_frame_flags & VP9_ALT_FLAG) {
3429 setup_buffer_inter(cpi, x, cpi->common.alt_fb_idx, ALTREF_FRAME, 3609 setup_buffer_inter(cpi, x, cpi->common.alt_fb_idx, ALTREF_FRAME,
3430 BLOCK_16X16, recon_yoffset, recon_uvoffset, 3610 BLOCK_16X16, recon_yoffset, recon_uvoffset,
3431 frame_mv[NEARESTMV], frame_mv[NEARMV], frame_best_ref_mv, 3611 frame_mv[NEARESTMV], frame_mv[NEARMV],
3432 mv_search_ref, frame_mdcounts, 3612 frame_mdcounts, y_buffer, u_buffer, v_buffer);
3433 y_buffer, u_buffer, v_buffer);
3434 } 3613 }
3435 3614
3436 *returnintra = INT64_MAX; 3615 *returnintra = INT64_MAX;
3437 3616
3438 x->skip = 0;
3439
3440 mbmi->ref_frame = INTRA_FRAME; 3617 mbmi->ref_frame = INTRA_FRAME;
3441 3618
3442 /* Initialize zbin mode boost for uv costing */ 3619 /* Initialize zbin mode boost for uv costing */
3443 cpi->zbin_mode_boost = 0; 3620 cpi->zbin_mode_boost = 0;
3444 vp9_update_zbin_extra(cpi, x); 3621 vp9_update_zbin_extra(cpi, x);
3445 3622
3446 rd_pick_intra_mbuv_mode(cpi, x, &uv_intra_rate, 3623 rd_pick_intra_mbuv_mode(cpi, x, &uv_intra_rate,
3447 &uv_intra_rate_tokenonly, &uv_intra_distortion, 3624 &uv_intra_rate_tokenonly, &uv_intra_distortion,
3448 &uv_intra_skippable); 3625 &uv_intra_skippable);
3449 uv_intra_mode = mbmi->uv_mode; 3626 uv_intra_mode = mbmi->uv_mode;
(...skipping 22 matching lines...) Expand all
3472 #endif 3649 #endif
3473 int mode_excluded = 0; 3650 int mode_excluded = 0;
3474 int64_t txfm_cache[NB_TXFM_MODES] = { 0 }; 3651 int64_t txfm_cache[NB_TXFM_MODES] = { 0 };
3475 3652
3476 // These variables hold are rolling total cost and distortion for this mode 3653 // These variables hold are rolling total cost and distortion for this mode
3477 rate2 = 0; 3654 rate2 = 0;
3478 distortion2 = 0; 3655 distortion2 = 0;
3479 rate_y = 0; 3656 rate_y = 0;
3480 rate_uv = 0; 3657 rate_uv = 0;
3481 3658
3659 x->skip = 0;
3660
3482 this_mode = vp9_mode_order[mode_index].mode; 3661 this_mode = vp9_mode_order[mode_index].mode;
3483 mbmi->mode = this_mode; 3662 mbmi->mode = this_mode;
3484 mbmi->uv_mode = DC_PRED; 3663 mbmi->uv_mode = DC_PRED;
3485 mbmi->ref_frame = vp9_mode_order[mode_index].ref_frame; 3664 mbmi->ref_frame = vp9_mode_order[mode_index].ref_frame;
3486 mbmi->second_ref_frame = vp9_mode_order[mode_index].second_ref_frame; 3665 mbmi->second_ref_frame = vp9_mode_order[mode_index].second_ref_frame;
3487 #if CONFIG_PRED_FILTER 3666
3488 mbmi->pred_filter_enabled = 0; 3667 // Evaluate all sub-pel filters irrespective of whether we can use
3489 #endif 3668 // them for this frame.
3490 if (cpi->common.mcomp_filter_type == SWITCHABLE && 3669 if (this_mode >= NEARESTMV && this_mode <= SPLITMV) {
3491 this_mode >= NEARESTMV && this_mode <= SPLITMV) {
3492 mbmi->interp_filter = 3670 mbmi->interp_filter =
3493 vp9_switchable_interp[switchable_filter_index++]; 3671 vp9_switchable_interp[switchable_filter_index++];
3494 if (switchable_filter_index == VP9_SWITCHABLE_FILTERS) 3672 if (switchable_filter_index == VP9_SWITCHABLE_FILTERS)
3495 switchable_filter_index = 0; 3673 switchable_filter_index = 0;
3496 } else { 3674 if ((cm->mcomp_filter_type != SWITCHABLE) &&
3497 mbmi->interp_filter = cpi->common.mcomp_filter_type; 3675 (cm->mcomp_filter_type != mbmi->interp_filter)) {
3676 mode_excluded = 1;
3677 }
3678 vp9_setup_interp_filters(xd, mbmi->interp_filter, &cpi->common);
3498 } 3679 }
3499 vp9_setup_interp_filters(xd, mbmi->interp_filter, &cpi->common);
3500 3680
3501 // Test best rd so far against threshold for trying this mode. 3681 // Test best rd so far against threshold for trying this mode.
3502 if (best_rd <= cpi->rd_threshes[mode_index]) 3682 if (best_rd <= cpi->rd_threshes[mode_index])
3503 continue; 3683 continue;
3504 3684
3505 // current coding mode under rate-distortion optimization test loop 3685 // current coding mode under rate-distortion optimization test loop
3506 #if CONFIG_COMP_INTRA_PRED
3507 mbmi->second_mode = (MB_PREDICTION_MODE)(DC_PRED - 1);
3508 mbmi->second_uv_mode = (MB_PREDICTION_MODE)(DC_PRED - 1);
3509 #endif
3510 #if CONFIG_COMP_INTERINTRA_PRED 3686 #if CONFIG_COMP_INTERINTRA_PRED
3511 mbmi->interintra_mode = (MB_PREDICTION_MODE)(DC_PRED - 1); 3687 mbmi->interintra_mode = (MB_PREDICTION_MODE)(DC_PRED - 1);
3512 mbmi->interintra_uv_mode = (MB_PREDICTION_MODE)(DC_PRED - 1); 3688 mbmi->interintra_uv_mode = (MB_PREDICTION_MODE)(DC_PRED - 1);
3513 #endif 3689 #endif
3514 3690
3515 // If the segment reference frame feature is enabled.... 3691 // If the segment reference frame feature is enabled....
3516 // then do nothing if the current ref frame is not allowed.. 3692 // then do nothing if the current ref frame is not allowed..
3517 if (vp9_segfeature_active(xd, segment_id, SEG_LVL_REF_FRAME) && 3693 if (vp9_segfeature_active(xd, segment_id, SEG_LVL_REF_FRAME) &&
3518 !vp9_check_segref(xd, segment_id, mbmi->ref_frame)) { 3694 !vp9_check_segref(xd, segment_id, mbmi->ref_frame)) {
3519 continue; 3695 continue;
(...skipping 19 matching lines...) Expand all
3539 } 3715 }
3540 } 3716 }
3541 3717
3542 /* everything but intra */ 3718 /* everything but intra */
3543 if (mbmi->ref_frame) { 3719 if (mbmi->ref_frame) {
3544 int ref = mbmi->ref_frame; 3720 int ref = mbmi->ref_frame;
3545 3721
3546 xd->pre.y_buffer = y_buffer[ref]; 3722 xd->pre.y_buffer = y_buffer[ref];
3547 xd->pre.u_buffer = u_buffer[ref]; 3723 xd->pre.u_buffer = u_buffer[ref];
3548 xd->pre.v_buffer = v_buffer[ref]; 3724 xd->pre.v_buffer = v_buffer[ref];
3549 best_ref_mv = frame_best_ref_mv[ref]; 3725 best_ref_mv = mbmi->ref_mvs[ref][0];
3550 vpx_memcpy(mdcounts, frame_mdcounts[ref], sizeof(mdcounts)); 3726 vpx_memcpy(mdcounts, frame_mdcounts[ref], sizeof(mdcounts));
3551 } 3727 }
3552 3728
3553 if (mbmi->second_ref_frame > 0) { 3729 if (mbmi->second_ref_frame > 0) {
3554 int ref = mbmi->second_ref_frame; 3730 int ref = mbmi->second_ref_frame;
3555 3731
3556 xd->second_pre.y_buffer = y_buffer[ref]; 3732 xd->second_pre.y_buffer = y_buffer[ref];
3557 xd->second_pre.u_buffer = u_buffer[ref]; 3733 xd->second_pre.u_buffer = u_buffer[ref];
3558 xd->second_pre.v_buffer = v_buffer[ref]; 3734 xd->second_pre.v_buffer = v_buffer[ref];
3559 second_best_ref_mv = frame_best_ref_mv[ref]; 3735 second_best_ref_mv = mbmi->ref_mvs[ref][0];
3560 } 3736 }
3561 3737
3562 // Experimental code. Special case for gf and arf zeromv modes. 3738 // Experimental code. Special case for gf and arf zeromv modes.
3563 // Increase zbin size to suppress noise 3739 // Increase zbin size to suppress noise
3564 if (cpi->zbin_mode_boost_enabled) { 3740 if (cpi->zbin_mode_boost_enabled) {
3565 if (vp9_mode_order[mode_index].ref_frame == INTRA_FRAME) 3741 if (vp9_mode_order[mode_index].ref_frame == INTRA_FRAME)
3566 cpi->zbin_mode_boost = 0; 3742 cpi->zbin_mode_boost = 0;
3567 else { 3743 else {
3568 if (vp9_mode_order[mode_index].mode == ZEROMV) { 3744 if (vp9_mode_order[mode_index].mode == ZEROMV) {
3569 if (vp9_mode_order[mode_index].ref_frame != LAST_FRAME) 3745 if (vp9_mode_order[mode_index].ref_frame != LAST_FRAME)
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
3614 distortion_uv = uv_intra_distortion; 3790 distortion_uv = uv_intra_distortion;
3615 skippable = skippable && uv_intra_skippable; 3791 skippable = skippable && uv_intra_skippable;
3616 } 3792 }
3617 break; 3793 break;
3618 case B_PRED: { 3794 case B_PRED: {
3619 int64_t tmp_rd; 3795 int64_t tmp_rd;
3620 3796
3621 // Note the rate value returned here includes the cost of coding 3797 // Note the rate value returned here includes the cost of coding
3622 // the BPRED mode : x->mbmode_cost[xd->frame_type][BPRED]; 3798 // the BPRED mode : x->mbmode_cost[xd->frame_type][BPRED];
3623 mbmi->txfm_size = TX_4X4; 3799 mbmi->txfm_size = TX_4X4;
3624 tmp_rd = rd_pick_intra4x4mby_modes(cpi, x, &rate, &rate_y, &distortion , best_yrd, 3800 tmp_rd = rd_pick_intra4x4mby_modes(cpi, x, &rate, &rate_y,
3625 #if CONFIG_COMP_INTRA_PRED 3801 &distortion, best_yrd,
3626 0, 3802 cpi->update_context);
3627 #endif
3628 0);
3629 rate2 += rate; 3803 rate2 += rate;
3630 rate2 += intra_cost_penalty; 3804 rate2 += intra_cost_penalty;
3631 distortion2 += distortion; 3805 distortion2 += distortion;
3632 3806
3633 if (tmp_rd < best_yrd) { 3807 if (tmp_rd < best_yrd) {
3634 rate2 += uv_intra_rate; 3808 rate2 += uv_intra_rate;
3635 rate_uv = uv_intra_rate_tokenonly; 3809 rate_uv = uv_intra_rate_tokenonly;
3636 distortion2 += uv_intra_distortion; 3810 distortion2 += uv_intra_distortion;
3637 distortion_uv = uv_intra_distortion; 3811 distortion_uv = uv_intra_distortion;
3638 } else { 3812 } else {
3639 this_rd = INT64_MAX; 3813 this_rd = INT64_MAX;
3640 disable_skip = 1; 3814 disable_skip = 1;
3641 } 3815 }
3642 } 3816 }
3643 break; 3817 break;
3644 case I8X8_PRED: { 3818 case I8X8_PRED: {
3645 int cost0 = vp9_cost_bit(cm->prob_tx[0], 0); 3819 int cost0 = vp9_cost_bit(cm->prob_tx[0], 0);
3646 int cost1 = vp9_cost_bit(cm->prob_tx[0], 1); 3820 int cost1 = vp9_cost_bit(cm->prob_tx[0], 1);
3647 int64_t tmp_rd_4x4s, tmp_rd_8x8s; 3821 int64_t tmp_rd_4x4s, tmp_rd_8x8s;
3648 int64_t tmp_rd_4x4, tmp_rd_8x8, tmp_rd; 3822 int64_t tmp_rd_4x4, tmp_rd_8x8, tmp_rd;
3649 int r4x4, tok4x4, d4x4, r8x8, tok8x8, d8x8; 3823 int r4x4, tok4x4, d4x4, r8x8, tok8x8, d8x8;
3650 mbmi->txfm_size = TX_4X4; 3824 mbmi->txfm_size = TX_4X4;
3651 tmp_rd_4x4 = rd_pick_intra8x8mby_modes(cpi, x, &r4x4, &tok4x4, 3825 tmp_rd_4x4 = rd_pick_intra8x8mby_modes(cpi, x, &r4x4, &tok4x4,
3652 &d4x4, best_yrd); 3826 &d4x4, best_yrd);
3653 mode8x8[0][0] = xd->mode_info_context->bmi[0].as_mode.first; 3827 mode8x8[0] = xd->mode_info_context->bmi[0].as_mode.first;
3654 mode8x8[0][1] = xd->mode_info_context->bmi[2].as_mode.first; 3828 mode8x8[1] = xd->mode_info_context->bmi[2].as_mode.first;
3655 mode8x8[0][2] = xd->mode_info_context->bmi[8].as_mode.first; 3829 mode8x8[2] = xd->mode_info_context->bmi[8].as_mode.first;
3656 mode8x8[0][3] = xd->mode_info_context->bmi[10].as_mode.first; 3830 mode8x8[3] = xd->mode_info_context->bmi[10].as_mode.first;
3657 #if CONFIG_COMP_INTRA_PRED
3658 mode8x8[1][0] = xd->mode_info_context->bmi[0].as_mode.second;
3659 mode8x8[1][1] = xd->mode_info_context->bmi[2].as_mode.second;
3660 mode8x8[1][2] = xd->mode_info_context->bmi[8].as_mode.second;
3661 mode8x8[1][3] = xd->mode_info_context->bmi[10].as_mode.second;
3662 #endif
3663 mbmi->txfm_size = TX_8X8; 3831 mbmi->txfm_size = TX_8X8;
3664 tmp_rd_8x8 = rd_pick_intra8x8mby_modes(cpi, x, &r8x8, &tok8x8, 3832 tmp_rd_8x8 = rd_pick_intra8x8mby_modes(cpi, x, &r8x8, &tok8x8,
3665 &d8x8, best_yrd); 3833 &d8x8, best_yrd);
3666 txfm_cache[ONLY_4X4] = tmp_rd_4x4; 3834 txfm_cache[ONLY_4X4] = tmp_rd_4x4;
3667 txfm_cache[ALLOW_8X8] = tmp_rd_8x8; 3835 txfm_cache[ALLOW_8X8] = tmp_rd_8x8;
3668 txfm_cache[ALLOW_16X16] = tmp_rd_8x8; 3836 txfm_cache[ALLOW_16X16] = tmp_rd_8x8;
3669 tmp_rd_4x4s = tmp_rd_4x4 + RDCOST(x->rdmult, x->rddiv, cost0, 0); 3837 tmp_rd_4x4s = tmp_rd_4x4 + RDCOST(x->rdmult, x->rddiv, cost0, 0);
3670 tmp_rd_8x8s = tmp_rd_8x8 + RDCOST(x->rdmult, x->rddiv, cost1, 0); 3838 tmp_rd_8x8s = tmp_rd_8x8 + RDCOST(x->rdmult, x->rddiv, cost1, 0);
3671 txfm_cache[TX_MODE_SELECT] = tmp_rd_4x4s < tmp_rd_8x8s ? tmp_rd_4x4s : tmp_rd_8x8s; 3839 txfm_cache[TX_MODE_SELECT] = tmp_rd_4x4s < tmp_rd_8x8s ? tmp_rd_4x4s : tmp_rd_8x8s;
3672 if (cm->txfm_mode == TX_MODE_SELECT) { 3840 if (cm->txfm_mode == TX_MODE_SELECT) {
3673 if (tmp_rd_4x4s < tmp_rd_8x8s) { 3841 if (tmp_rd_4x4s < tmp_rd_8x8s) {
3674 rate = r4x4 + cost0; 3842 rate = r4x4 + cost0;
3675 rate_y = tok4x4 + cost0; 3843 rate_y = tok4x4 + cost0;
3676 distortion = d4x4; 3844 distortion = d4x4;
3677 mbmi->txfm_size = TX_4X4; 3845 mbmi->txfm_size = TX_4X4;
3678 tmp_rd = tmp_rd_4x4s; 3846 tmp_rd = tmp_rd_4x4s;
3679 } else { 3847 } else {
3680 rate = r8x8 + cost1; 3848 rate = r8x8 + cost1;
3681 rate_y = tok8x8 + cost1; 3849 rate_y = tok8x8 + cost1;
3682 distortion = d8x8; 3850 distortion = d8x8;
3683 mbmi->txfm_size = TX_8X8; 3851 mbmi->txfm_size = TX_8X8;
3684 tmp_rd = tmp_rd_8x8s; 3852 tmp_rd = tmp_rd_8x8s;
3685 3853
3686 mode8x8[0][0] = xd->mode_info_context->bmi[0].as_mode.first; 3854 mode8x8[0] = xd->mode_info_context->bmi[0].as_mode.first;
3687 mode8x8[0][1] = xd->mode_info_context->bmi[2].as_mode.first; 3855 mode8x8[1] = xd->mode_info_context->bmi[2].as_mode.first;
3688 mode8x8[0][2] = xd->mode_info_context->bmi[8].as_mode.first; 3856 mode8x8[2] = xd->mode_info_context->bmi[8].as_mode.first;
3689 mode8x8[0][3] = xd->mode_info_context->bmi[10].as_mode.first; 3857 mode8x8[3] = xd->mode_info_context->bmi[10].as_mode.first;
3690 #if CONFIG_COMP_INTRA_PRED
3691 mode8x8[1][0] = xd->mode_info_context->bmi[0].as_mode.second;
3692 mode8x8[1][1] = xd->mode_info_context->bmi[2].as_mode.second;
3693 mode8x8[1][2] = xd->mode_info_context->bmi[8].as_mode.second;
3694 mode8x8[1][3] = xd->mode_info_context->bmi[10].as_mode.second;
3695 #endif
3696 } 3858 }
3697 } else if (cm->txfm_mode == ONLY_4X4) { 3859 } else if (cm->txfm_mode == ONLY_4X4) {
3698 rate = r4x4; 3860 rate = r4x4;
3699 rate_y = tok4x4; 3861 rate_y = tok4x4;
3700 distortion = d4x4; 3862 distortion = d4x4;
3701 mbmi->txfm_size = TX_4X4; 3863 mbmi->txfm_size = TX_4X4;
3702 tmp_rd = tmp_rd_4x4; 3864 tmp_rd = tmp_rd_4x4;
3703 } else { 3865 } else {
3704 rate = r8x8; 3866 rate = r8x8;
3705 rate_y = tok8x8; 3867 rate_y = tok8x8;
3706 distortion = d8x8; 3868 distortion = d8x8;
3707 mbmi->txfm_size = TX_8X8; 3869 mbmi->txfm_size = TX_8X8;
3708 tmp_rd = tmp_rd_8x8; 3870 tmp_rd = tmp_rd_8x8;
3709 3871
3710 mode8x8[0][0] = xd->mode_info_context->bmi[0].as_mode.first; 3872 mode8x8[0] = xd->mode_info_context->bmi[0].as_mode.first;
3711 mode8x8[0][1] = xd->mode_info_context->bmi[2].as_mode.first; 3873 mode8x8[1] = xd->mode_info_context->bmi[2].as_mode.first;
3712 mode8x8[0][2] = xd->mode_info_context->bmi[8].as_mode.first; 3874 mode8x8[2] = xd->mode_info_context->bmi[8].as_mode.first;
3713 mode8x8[0][3] = xd->mode_info_context->bmi[10].as_mode.first; 3875 mode8x8[3] = xd->mode_info_context->bmi[10].as_mode.first;
3714 #if CONFIG_COMP_INTRA_PRED
3715 mode8x8[1][0] = xd->mode_info_context->bmi[0].as_mode.second;
3716 mode8x8[1][1] = xd->mode_info_context->bmi[2].as_mode.second;
3717 mode8x8[1][2] = xd->mode_info_context->bmi[8].as_mode.second;
3718 mode8x8[1][3] = xd->mode_info_context->bmi[10].as_mode.second;
3719 #endif
3720 } 3876 }
3721 3877
3722 rate2 += rate; 3878 rate2 += rate;
3723 rate2 += intra_cost_penalty; 3879 rate2 += intra_cost_penalty;
3724 distortion2 += distortion; 3880 distortion2 += distortion;
3725 3881
3726 /* TODO: uv rate maybe over-estimated here since there is UV intra 3882 /* TODO: uv rate maybe over-estimated here since there is UV intra
3727 mode coded in I8X8_PRED prediction */ 3883 mode coded in I8X8_PRED prediction */
3728 if (tmp_rd < best_yrd) { 3884 if (tmp_rd < best_yrd) {
3729 rate2 += uv_intra_rate; 3885 rate2 += uv_intra_rate;
(...skipping 28 matching lines...) Expand all
3758 &skippable, 3914 &skippable,
3759 (int)this_rd_thresh, seg_mvs, 3915 (int)this_rd_thresh, seg_mvs,
3760 txfm_cache); 3916 txfm_cache);
3761 rate2 += rate; 3917 rate2 += rate;
3762 distortion2 += distortion; 3918 distortion2 += distortion;
3763 3919
3764 if (cpi->common.mcomp_filter_type == SWITCHABLE) 3920 if (cpi->common.mcomp_filter_type == SWITCHABLE)
3765 rate2 += SWITCHABLE_INTERP_RATE_FACTOR * x->switchable_interp_costs 3921 rate2 += SWITCHABLE_INTERP_RATE_FACTOR * x->switchable_interp_costs
3766 [vp9_get_pred_context(&cpi->common, xd, PRED_SWITCHABLE_INTERP)] 3922 [vp9_get_pred_context(&cpi->common, xd, PRED_SWITCHABLE_INTERP)]
3767 [vp9_switchable_interp_map[mbmi->interp_filter]]; 3923 [vp9_switchable_interp_map[mbmi->interp_filter]];
3924
3768 // If even the 'Y' rd value of split is higher than best so far 3925 // If even the 'Y' rd value of split is higher than best so far
3769 // then dont bother looking at UV 3926 // then dont bother looking at UV
3770 if (tmp_rd < best_yrd) { 3927 if (tmp_rd < best_yrd) {
3771 int uv_skippable; 3928 int uv_skippable;
3772 3929
3773 rd_inter4x4_uv(cpi, x, &rate_uv, &distortion_uv, &uv_skippable, 3930 rd_inter4x4_uv(cpi, x, &rate_uv, &distortion_uv, &uv_skippable,
3774 cpi->common.full_pixel); 3931 cpi->common.full_pixel);
3775 rate2 += rate_uv; 3932 rate2 += rate_uv;
3776 distortion2 += distortion_uv; 3933 distortion2 += distortion_uv;
3777 skippable = skippable && uv_skippable; 3934 skippable = skippable && uv_skippable;
3778 } else { 3935 } else {
3779 this_rd = INT64_MAX; 3936 this_rd = INT64_MAX;
3780 disable_skip = 1; 3937 disable_skip = 1;
3781 } 3938 }
3782 3939
3783 if (is_comp_pred) 3940 if (!mode_excluded) {
3784 mode_excluded = cpi->common.comp_pred_mode == SINGLE_PREDICTION_ONLY; 3941 if (is_comp_pred)
3785 else 3942 mode_excluded = cpi->common.comp_pred_mode == SINGLE_PREDICTION_ONLY;
3786 mode_excluded = cpi->common.comp_pred_mode == COMP_PREDICTION_ONLY; 3943 else
3944 mode_excluded = cpi->common.comp_pred_mode == COMP_PREDICTION_ONLY;
3945 }
3787 3946
3788 compmode_cost = 3947 compmode_cost =
3789 vp9_cost_bit(vp9_get_pred_prob(cm, xd, PRED_COMP), is_comp_pred); 3948 vp9_cost_bit(vp9_get_pred_prob(cm, xd, PRED_COMP), is_comp_pred);
3790 mbmi->mode = this_mode; 3949 mbmi->mode = this_mode;
3791 } 3950 }
3792 else { 3951 else {
3793 #if CONFIG_COMP_INTERINTRA_PRED 3952 #if CONFIG_COMP_INTERINTRA_PRED
3794 if (mbmi->second_ref_frame == INTRA_FRAME) { 3953 if (mbmi->second_ref_frame == INTRA_FRAME) {
3795 if (best_intra16_mode == DC_PRED - 1) continue; 3954 if (best_intra16_mode == DC_PRED - 1) continue;
3796 mbmi->interintra_mode = best_intra16_mode; 3955 mbmi->interintra_mode = best_intra16_mode;
3797 #if SEPARATE_INTERINTRA_UV 3956 #if SEPARATE_INTERINTRA_UV
3798 mbmi->interintra_uv_mode = best_intra16_uv_mode; 3957 mbmi->interintra_uv_mode = best_intra16_uv_mode;
3799 #else 3958 #else
3800 mbmi->interintra_uv_mode = best_intra16_mode; 3959 mbmi->interintra_uv_mode = best_intra16_mode;
3801 #endif 3960 #endif
3802 } 3961 }
3803 #endif 3962 #endif
3804 this_rd = handle_inter_mode(cpi, x, BLOCK_16X16, 3963 this_rd = handle_inter_mode(cpi, x, BLOCK_16X16,
3805 &saddone, near_sadidx, mdcounts, txfm_cache, 3964 &saddone, near_sadidx, mdcounts, txfm_cache,
3806 &rate2, &distortion2, &skippable, 3965 &rate2, &distortion2, &skippable,
3807 &compmode_cost, 3966 &compmode_cost,
3808 #if CONFIG_COMP_INTERINTRA_PRED 3967 #if CONFIG_COMP_INTERINTRA_PRED
3809 &compmode_interintra_cost, 3968 &compmode_interintra_cost,
3810 #endif 3969 #endif
3811 &rate_y, &distortion, 3970 &rate_y, &distortion,
3812 &rate_uv, &distortion_uv, 3971 &rate_uv, &distortion_uv,
3813 &mode_excluded, &disable_skip, recon_yoffset, 3972 &mode_excluded, &disable_skip, recon_yoffset,
3814 mode_index, frame_mv, frame_best_ref_mv, 3973 mode_index, frame_mv);
3815 mv_search_ref);
3816 if (this_rd == INT64_MAX) 3974 if (this_rd == INT64_MAX)
3817 continue; 3975 continue;
3818 } 3976 }
3819 3977
3820 #if CONFIG_COMP_INTERINTRA_PRED 3978 #if CONFIG_COMP_INTERINTRA_PRED
3821 if (cpi->common.use_interintra) 3979 if (cpi->common.use_interintra)
3822 rate2 += compmode_interintra_cost; 3980 rate2 += compmode_interintra_cost;
3823 #endif 3981 #endif
3824 3982
3825 if (cpi->common.comp_pred_mode == HYBRID_PREDICTION) 3983 if (cpi->common.comp_pred_mode == HYBRID_PREDICTION)
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
3890 if ((mbmi->ref_frame == INTRA_FRAME) && 4048 if ((mbmi->ref_frame == INTRA_FRAME) &&
3891 (this_mode <= TM_PRED) && 4049 (this_mode <= TM_PRED) &&
3892 (this_rd < best_intra16_rd)) { 4050 (this_rd < best_intra16_rd)) {
3893 best_intra16_rd = this_rd; 4051 best_intra16_rd = this_rd;
3894 best_intra16_mode = this_mode; 4052 best_intra16_mode = this_mode;
3895 best_intra16_uv_mode = (mbmi->txfm_size != TX_4X4 ? 4053 best_intra16_uv_mode = (mbmi->txfm_size != TX_4X4 ?
3896 uv_intra_mode_8x8 : uv_intra_mode); 4054 uv_intra_mode_8x8 : uv_intra_mode);
3897 } 4055 }
3898 #endif 4056 #endif
3899 4057
3900
3901 if (!disable_skip && mbmi->ref_frame == INTRA_FRAME) 4058 if (!disable_skip && mbmi->ref_frame == INTRA_FRAME)
3902 for (i = 0; i < NB_PREDICTION_TYPES; ++i) 4059 for (i = 0; i < NB_PREDICTION_TYPES; ++i)
3903 best_pred_rd[i] = MIN(best_pred_rd[i], this_rd); 4060 best_pred_rd[i] = MIN(best_pred_rd[i], this_rd);
3904 4061
3905 if (this_rd < best_overall_rd) { 4062 if (this_rd < best_overall_rd) {
3906 best_overall_rd = this_rd; 4063 best_overall_rd = this_rd;
3907 #if CONFIG_PRED_FILTER 4064 best_filter = mbmi->interp_filter;
3908 best_filter_state = mbmi->pred_filter_enabled; 4065 best_mode = this_mode;
3909 #endif
3910 #if CONFIG_COMP_INTERINTRA_PRED 4066 #if CONFIG_COMP_INTERINTRA_PRED
3911 is_best_interintra = (mbmi->second_ref_frame == INTRA_FRAME); 4067 is_best_interintra = (mbmi->second_ref_frame == INTRA_FRAME);
3912 #endif 4068 #endif
3913 } 4069 }
3914 4070
3915 #if CONFIG_PRED_FILTER 4071 // Did this mode help.. i.e. is it the new best mode
3916 // Ignore modes where the prediction filter state doesn't 4072 if (this_rd < best_rd || x->skip) {
3917 // match the state signaled at the frame level 4073 if (!mode_excluded) {
3918 if ((cm->pred_filter_mode == 2) || 4074 /*
3919 (cm->pred_filter_mode == 4075 if (mbmi->second_ref_frame == INTRA_FRAME) {
3920 mbmi->pred_filter_enabled)) { 4076 printf("rd %d best %d bestintra16 %d\n", this_rd, best_rd, best_intra1 6_rd);
3921 #endif 4077 }
3922 // Did this mode help.. i.e. is it the new best mode 4078 */
3923 if (this_rd < best_rd || x->skip) { 4079 // Note index of best mode so far
3924 if (!mode_excluded) { 4080 best_mode_index = mode_index;
3925 /*
3926 if (mbmi->second_ref_frame == INTRA_FRAME) {
3927 printf("rd %d best %d bestintra16 %d\n", this_rd, best_rd, best_intr a16_rd);
3928 }
3929 */
3930 // Note index of best mode so far
3931 best_mode_index = mode_index;
3932 4081
3933 if (this_mode <= B_PRED) { 4082 if (this_mode <= B_PRED) {
3934 if (mbmi->txfm_size != TX_4X4 4083 if (mbmi->txfm_size != TX_4X4
3935 && this_mode != B_PRED 4084 && this_mode != B_PRED
3936 && this_mode != I8X8_PRED) 4085 && this_mode != I8X8_PRED)
3937 mbmi->uv_mode = uv_intra_mode_8x8; 4086 mbmi->uv_mode = uv_intra_mode_8x8;
3938 else 4087 else
3939 mbmi->uv_mode = uv_intra_mode; 4088 mbmi->uv_mode = uv_intra_mode;
3940 /* required for left and above block mv */ 4089 /* required for left and above block mv */
3941 mbmi->mv[0].as_int = 0; 4090 mbmi->mv[0].as_int = 0;
3942 }
3943
3944 other_cost += ref_costs[mbmi->ref_frame];
3945
3946 /* Calculate the final y RD estimate for this mode */
3947 best_yrd = RDCOST(x->rdmult, x->rddiv, (rate2 - rate_uv - other_cost),
3948 (distortion2 - distortion_uv));
3949
3950 *returnrate = rate2;
3951 *returndistortion = distortion2;
3952 best_rd = this_rd;
3953 vpx_memcpy(&best_mbmode, mbmi, sizeof(MB_MODE_INFO));
3954 vpx_memcpy(&best_partition, x->partition_info, sizeof(PARTITION_INFO)) ;
3955
3956 if ((this_mode == B_PRED)
3957 || (this_mode == I8X8_PRED)
3958 || (this_mode == SPLITMV))
3959 for (i = 0; i < 16; i++) {
3960 best_bmodes[i] = xd->block[i].bmi;
3961 }
3962 } 4091 }
3963 4092
3964 // Testing this mode gave rise to an improvement in best error score. 4093 other_cost += ref_costs[mbmi->ref_frame];
3965 // Lower threshold a bit for next time 4094
3966 cpi->rd_thresh_mult[mode_index] = 4095 /* Calculate the final y RD estimate for this mode */
3967 (cpi->rd_thresh_mult[mode_index] >= (MIN_THRESHMULT + 2)) ? 4096 best_yrd = RDCOST(x->rdmult, x->rddiv, (rate2 - rate_uv - other_cost),
3968 cpi->rd_thresh_mult[mode_index] - 2 : MIN_THRESHMULT; 4097 (distortion2 - distortion_uv));
3969 cpi->rd_threshes[mode_index] = 4098
3970 (cpi->rd_baseline_thresh[mode_index] >> 7) * 4099 *returnrate = rate2;
3971 cpi->rd_thresh_mult[mode_index]; 4100 *returndistortion = distortion2;
4101 best_rd = this_rd;
4102 vpx_memcpy(&best_mbmode, mbmi, sizeof(MB_MODE_INFO));
4103 vpx_memcpy(&best_partition, x->partition_info, sizeof(PARTITION_INFO));
4104
4105 if ((this_mode == B_PRED)
4106 || (this_mode == I8X8_PRED)
4107 || (this_mode == SPLITMV))
4108 for (i = 0; i < 16; i++) {
4109 best_bmodes[i] = xd->block[i].bmi;
4110 }
3972 } 4111 }
4112
4113 // Testing this mode gave rise to an improvement in best error score.
4114 // Lower threshold a bit for next time
4115 cpi->rd_thresh_mult[mode_index] =
4116 (cpi->rd_thresh_mult[mode_index] >= (MIN_THRESHMULT + 2)) ?
4117 cpi->rd_thresh_mult[mode_index] - 2 : MIN_THRESHMULT;
4118 cpi->rd_threshes[mode_index] =
4119 (cpi->rd_baseline_thresh[mode_index] >> 7) *
4120 cpi->rd_thresh_mult[mode_index];
4121 } else {
3973 // If the mode did not help improve the best error case then raise the 4122 // If the mode did not help improve the best error case then raise the
3974 // threshold for testing that mode next time around. 4123 // threshold for testing that mode next time around.
3975 else { 4124 cpi->rd_thresh_mult[mode_index] += 4;
3976 cpi->rd_thresh_mult[mode_index] += 4;
3977 4125
3978 if (cpi->rd_thresh_mult[mode_index] > MAX_THRESHMULT) 4126 if (cpi->rd_thresh_mult[mode_index] > MAX_THRESHMULT)
3979 cpi->rd_thresh_mult[mode_index] = MAX_THRESHMULT; 4127 cpi->rd_thresh_mult[mode_index] = MAX_THRESHMULT;
3980 4128
3981 cpi->rd_threshes[mode_index] = (cpi->rd_baseline_thresh[mode_index] >> 7 ) * cpi->rd_thresh_mult[mode_index]; 4129 cpi->rd_threshes[mode_index] = (cpi->rd_baseline_thresh[mode_index] >> 7)
4130 * cpi->rd_thresh_mult[mode_index];
4131 }
4132
4133 /* keep record of best compound/single-only prediction */
4134 if (!disable_skip && mbmi->ref_frame != INTRA_FRAME) {
4135 int64_t single_rd, hybrid_rd;
4136 int single_rate, hybrid_rate;
4137
4138 if (cpi->common.comp_pred_mode == HYBRID_PREDICTION) {
4139 single_rate = rate2 - compmode_cost;
4140 hybrid_rate = rate2;
4141 } else {
4142 single_rate = rate2;
4143 hybrid_rate = rate2 + compmode_cost;
3982 } 4144 }
3983 4145
3984 /* keep record of best compound/single-only prediction */ 4146 single_rd = RDCOST(x->rdmult, x->rddiv, single_rate, distortion2);
3985 if (!disable_skip && mbmi->ref_frame != INTRA_FRAME) { 4147 hybrid_rd = RDCOST(x->rdmult, x->rddiv, hybrid_rate, distortion2);
3986 int64_t single_rd, hybrid_rd;
3987 int single_rate, hybrid_rate;
3988 4148
3989 if (cpi->common.comp_pred_mode == HYBRID_PREDICTION) { 4149 if (mbmi->second_ref_frame <= INTRA_FRAME &&
3990 single_rate = rate2 - compmode_cost; 4150 single_rd < best_pred_rd[SINGLE_PREDICTION_ONLY]) {
3991 hybrid_rate = rate2; 4151 best_pred_rd[SINGLE_PREDICTION_ONLY] = single_rd;
4152 } else if (mbmi->second_ref_frame > INTRA_FRAME &&
4153 single_rd < best_pred_rd[COMP_PREDICTION_ONLY]) {
4154 best_pred_rd[COMP_PREDICTION_ONLY] = single_rd;
4155 }
4156 if (hybrid_rd < best_pred_rd[HYBRID_PREDICTION])
4157 best_pred_rd[HYBRID_PREDICTION] = hybrid_rd;
4158 }
4159
4160 /* keep record of best txfm size */
4161 if (!mode_excluded && this_rd != INT64_MAX) {
4162 for (i = 0; i < NB_TXFM_MODES; i++) {
4163 int64_t adj_rd;
4164 if (this_mode != B_PRED) {
4165 const int64_t txfm_mode_diff =
4166 txfm_cache[i] - txfm_cache[cm->txfm_mode];
4167 adj_rd = this_rd + txfm_mode_diff;
3992 } else { 4168 } else {
3993 single_rate = rate2; 4169 adj_rd = this_rd;
3994 hybrid_rate = rate2 + compmode_cost;
3995 } 4170 }
3996 4171 if (adj_rd < best_txfm_rd[i])
3997 single_rd = RDCOST(x->rdmult, x->rddiv, single_rate, distortion2); 4172 best_txfm_rd[i] = adj_rd;
3998 hybrid_rd = RDCOST(x->rdmult, x->rddiv, hybrid_rate, distortion2);
3999
4000 if (mbmi->second_ref_frame <= INTRA_FRAME &&
4001 single_rd < best_pred_rd[SINGLE_PREDICTION_ONLY]) {
4002 best_pred_rd[SINGLE_PREDICTION_ONLY] = single_rd;
4003 } else if (mbmi->second_ref_frame > INTRA_FRAME &&
4004 single_rd < best_pred_rd[COMP_PREDICTION_ONLY]) {
4005 best_pred_rd[COMP_PREDICTION_ONLY] = single_rd;
4006 }
4007 if (hybrid_rd < best_pred_rd[HYBRID_PREDICTION])
4008 best_pred_rd[HYBRID_PREDICTION] = hybrid_rd;
4009 } 4173 }
4010
4011 /* keep record of best txfm size */
4012 if (!mode_excluded && this_rd != INT64_MAX) {
4013 for (i = 0; i < NB_TXFM_MODES; i++) {
4014 int64_t adj_rd;
4015 if (this_mode != B_PRED) {
4016 const int64_t txfm_mode_diff =
4017 txfm_cache[i] - txfm_cache[cm->txfm_mode];
4018 adj_rd = this_rd + txfm_mode_diff;
4019 } else {
4020 adj_rd = this_rd;
4021 }
4022 if (adj_rd < best_txfm_rd[i])
4023 best_txfm_rd[i] = adj_rd;
4024 }
4025 }
4026 #if CONFIG_PRED_FILTER
4027 } 4174 }
4028 #endif
4029 4175
4030 if (x->skip && !mode_excluded) 4176 if (x->skip && !mode_excluded)
4031 break; 4177 break;
4032 } 4178 }
4033 4179
4034 #if CONFIG_PRED_FILTER 4180 assert((cm->mcomp_filter_type == SWITCHABLE) ||
4035 // Update counts for prediction filter usage 4181 (cm->mcomp_filter_type == best_mbmode.interp_filter) ||
4036 if (best_filter_state != 0) 4182 (best_mbmode.mode <= B_PRED));
4037 ++cpi->pred_filter_on_count; 4183
4038 else
4039 ++cpi->pred_filter_off_count;
4040 #endif
4041 #if CONFIG_COMP_INTERINTRA_PRED 4184 #if CONFIG_COMP_INTERINTRA_PRED
4042 ++cpi->interintra_select_count[is_best_interintra]; 4185 ++cpi->interintra_select_count[is_best_interintra];
4043 #endif 4186 #endif
4044 4187
4188 // Accumulate filter usage stats
4189 // TODO(agrange): Use RD criteria to select interpolation filter mode.
4190 if ((best_mode >= NEARESTMV) && (best_mode <= SPLITMV))
4191 ++cpi->best_switchable_interp_count[vp9_switchable_interp_map[best_filter]];
4192
4045 // Reduce the activation RD thresholds for the best choice mode 4193 // Reduce the activation RD thresholds for the best choice mode
4046 if ((cpi->rd_baseline_thresh[best_mode_index] > 0) && 4194 if ((cpi->rd_baseline_thresh[best_mode_index] > 0) &&
4047 (cpi->rd_baseline_thresh[best_mode_index] < (INT_MAX >> 2))) { 4195 (cpi->rd_baseline_thresh[best_mode_index] < (INT_MAX >> 2))) {
4048 int best_adjustment = (cpi->rd_thresh_mult[best_mode_index] >> 2); 4196 int best_adjustment = (cpi->rd_thresh_mult[best_mode_index] >> 2);
4049 4197
4050 cpi->rd_thresh_mult[best_mode_index] = 4198 cpi->rd_thresh_mult[best_mode_index] =
4051 (cpi->rd_thresh_mult[best_mode_index] >= 4199 (cpi->rd_thresh_mult[best_mode_index] >=
4052 (MIN_THRESHMULT + best_adjustment)) ? 4200 (MIN_THRESHMULT + best_adjustment)) ?
4053 cpi->rd_thresh_mult[best_mode_index] - best_adjustment : MIN_THRESHMULT; 4201 cpi->rd_thresh_mult[best_mode_index] - best_adjustment : MIN_THRESHMULT;
4054 cpi->rd_threshes[best_mode_index] = 4202 cpi->rd_threshes[best_mode_index] =
4055 (cpi->rd_baseline_thresh[best_mode_index] >> 7) * 4203 (cpi->rd_baseline_thresh[best_mode_index] >> 7) *
4056 cpi->rd_thresh_mult[best_mode_index]; 4204 cpi->rd_thresh_mult[best_mode_index];
4057 } 4205 }
4058 4206
4059 // This code force Altref,0,0 and skip for the frame that overlays a 4207 // This code force Altref,0,0 and skip for the frame that overlays a
4060 // an alrtef unless Altref is filtered. However, this is unsafe if 4208 // an alrtef unless Altref is filtered. However, this is unsafe if
4061 // segment level coding of ref frame or mode is enabled for this 4209 // segment level coding of ref frame or mode is enabled for this
4062 // segment. 4210 // segment.
4063 if (!vp9_segfeature_active(xd, segment_id, SEG_LVL_REF_FRAME) && 4211 if (!vp9_segfeature_active(xd, segment_id, SEG_LVL_REF_FRAME) &&
4064 !vp9_segfeature_active(xd, segment_id, SEG_LVL_MODE) && 4212 !vp9_segfeature_active(xd, segment_id, SEG_LVL_MODE) &&
4065 cpi->is_src_frame_alt_ref && 4213 cpi->is_src_frame_alt_ref &&
4066 (cpi->oxcf.arnr_max_frames == 0) && 4214 (cpi->oxcf.arnr_max_frames == 0) &&
4067 (best_mbmode.mode != ZEROMV || best_mbmode.ref_frame != ALTREF_FRAME)) { 4215 (best_mbmode.mode != ZEROMV || best_mbmode.ref_frame != ALTREF_FRAME)) {
4068 mbmi->mode = ZEROMV; 4216 mbmi->mode = ZEROMV;
4069 if (cm->txfm_mode != TX_MODE_SELECT) 4217 if (cm->txfm_mode <= ALLOW_8X8)
4070 mbmi->txfm_size = cm->txfm_mode; 4218 mbmi->txfm_size = cm->txfm_mode;
4071 else 4219 else
4072 mbmi->txfm_size = TX_16X16; 4220 mbmi->txfm_size = TX_16X16;
4073 mbmi->ref_frame = ALTREF_FRAME; 4221 mbmi->ref_frame = ALTREF_FRAME;
4074 mbmi->mv[0].as_int = 0; 4222 mbmi->mv[0].as_int = 0;
4075 mbmi->uv_mode = DC_PRED; 4223 mbmi->uv_mode = DC_PRED;
4076 mbmi->mb_skip_coeff = 4224 mbmi->mb_skip_coeff =
4077 (cpi->common.mb_no_coeff_skip) ? 1 : 0; 4225 (cpi->common.mb_no_coeff_skip) ? 1 : 0;
4078 mbmi->partitioning = 0; 4226 mbmi->partitioning = 0;
4079 4227
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
4119 if (best_txfm_rd[i] == INT64_MAX) 4267 if (best_txfm_rd[i] == INT64_MAX)
4120 best_txfm_diff[i] = INT_MIN; 4268 best_txfm_diff[i] = INT_MIN;
4121 else 4269 else
4122 best_txfm_diff[i] = best_rd - best_txfm_rd[i]; 4270 best_txfm_diff[i] = best_rd - best_txfm_rd[i];
4123 } 4271 }
4124 } else { 4272 } else {
4125 vpx_memset(best_txfm_diff, 0, sizeof(best_txfm_diff)); 4273 vpx_memset(best_txfm_diff, 0, sizeof(best_txfm_diff));
4126 } 4274 }
4127 4275
4128 end: 4276 end:
4129 store_coding_context( 4277 store_coding_context(x, &x->mb_context[xd->sb_index][xd->mb_index],
4130 x, &x->mb_context[xd->mb_index], best_mode_index, &best_partition, 4278 best_mode_index, &best_partition,
4131 &frame_best_ref_mv[xd->mode_info_context->mbmi.ref_frame], 4279 &mbmi->ref_mvs[mbmi->ref_frame][0],
4132 &frame_best_ref_mv[xd->mode_info_context->mbmi.second_ref_frame < 0 ? 4280 &mbmi->ref_mvs[mbmi->second_ref_frame < 0 ? 0 :
4133 0 : xd->mode_info_context->mbmi.second_ref_frame], 4281 mbmi->second_ref_frame][0],
4134 best_pred_diff, best_txfm_diff); 4282 best_pred_diff, best_txfm_diff);
4135 } 4283 }
4136 4284
4137 #if CONFIG_SUPERBLOCKS 4285 void vp9_rd_pick_intra_mode_sb32(VP9_COMP *cpi, MACROBLOCK *x,
4138 void vp9_rd_pick_intra_mode_sb(VP9_COMP *cpi, MACROBLOCK *x, 4286 int *returnrate,
4139 int *returnrate, 4287 int *returndist) {
4140 int *returndist) {
4141 VP9_COMMON *cm = &cpi->common; 4288 VP9_COMMON *cm = &cpi->common;
4142 MACROBLOCKD *xd = &x->e_mbd; 4289 MACROBLOCKD *xd = &x->e_mbd;
4143 int rate_y, rate_uv; 4290 int rate_y = 0, rate_uv;
4144 int rate_y_tokenonly, rate_uv_tokenonly; 4291 int rate_y_tokenonly = 0, rate_uv_tokenonly;
4145 int error_y, error_uv; 4292 int dist_y = 0, dist_uv;
4146 int dist_y, dist_uv; 4293 int y_skip = 0, uv_skip;
4147 int y_skip, uv_skip;
4148 int64_t txfm_cache[NB_TXFM_MODES]; 4294 int64_t txfm_cache[NB_TXFM_MODES];
4149 4295
4150 xd->mode_info_context->mbmi.txfm_size = TX_8X8; 4296 rd_pick_intra_sby_mode(cpi, x, &rate_y, &rate_y_tokenonly,
4151
4152 error_y = rd_pick_intra_sby_mode(cpi, x, &rate_y, &rate_y_tokenonly,
4153 &dist_y, &y_skip, txfm_cache); 4297 &dist_y, &y_skip, txfm_cache);
4154 error_uv = rd_pick_intra_sbuv_mode(cpi, x, &rate_uv, &rate_uv_tokenonly, 4298 rd_pick_intra_sbuv_mode(cpi, x, &rate_uv, &rate_uv_tokenonly,
4155 &dist_uv, &uv_skip); 4299 &dist_uv, &uv_skip);
4156 4300
4157 if (cpi->common.mb_no_coeff_skip && y_skip && uv_skip) { 4301 if (cpi->common.mb_no_coeff_skip && y_skip && uv_skip) {
4158 *returnrate = rate_y + rate_uv - rate_y_tokenonly - rate_uv_tokenonly + 4302 *returnrate = rate_y + rate_uv - rate_y_tokenonly - rate_uv_tokenonly +
4159 vp9_cost_bit(vp9_get_pred_prob(cm, xd, PRED_MBSKIP), 1); 4303 vp9_cost_bit(vp9_get_pred_prob(cm, xd, PRED_MBSKIP), 1);
4160 *returndist = dist_y + (dist_uv >> 2); 4304 *returndist = dist_y + (dist_uv >> 2);
4161 } else { 4305 } else {
4162 *returnrate = rate_y + rate_uv; 4306 *returnrate = rate_y + rate_uv;
4163 if (cpi->common.mb_no_coeff_skip) 4307 if (cpi->common.mb_no_coeff_skip)
4164 *returnrate += vp9_cost_bit(vp9_get_pred_prob(cm, xd, PRED_MBSKIP), 0); 4308 *returnrate += vp9_cost_bit(vp9_get_pred_prob(cm, xd, PRED_MBSKIP), 0);
4165 *returndist = dist_y + (dist_uv >> 2); 4309 *returndist = dist_y + (dist_uv >> 2);
4166 } 4310 }
4167 } 4311 }
4168 #endif 4312
4313 void vp9_rd_pick_intra_mode_sb64(VP9_COMP *cpi, MACROBLOCK *x,
4314 int *returnrate,
4315 int *returndist) {
4316 VP9_COMMON *cm = &cpi->common;
4317 MACROBLOCKD *xd = &x->e_mbd;
4318 int rate_y = 0, rate_uv;
4319 int rate_y_tokenonly = 0, rate_uv_tokenonly;
4320 int dist_y = 0, dist_uv;
4321 int y_skip = 0, uv_skip;
4322 int64_t txfm_cache[NB_TXFM_MODES];
4323
4324 rd_pick_intra_sb64y_mode(cpi, x, &rate_y, &rate_y_tokenonly,
4325 &dist_y, &y_skip, txfm_cache);
4326 rd_pick_intra_sb64uv_mode(cpi, x, &rate_uv, &rate_uv_tokenonly,
4327 &dist_uv, &uv_skip);
4328
4329 if (cpi->common.mb_no_coeff_skip && y_skip && uv_skip) {
4330 *returnrate = rate_y + rate_uv - rate_y_tokenonly - rate_uv_tokenonly +
4331 vp9_cost_bit(vp9_get_pred_prob(cm, xd, PRED_MBSKIP), 1);
4332 *returndist = dist_y + (dist_uv >> 2);
4333 } else {
4334 *returnrate = rate_y + rate_uv;
4335 if (cm->mb_no_coeff_skip)
4336 *returnrate += vp9_cost_bit(vp9_get_pred_prob(cm, xd, PRED_MBSKIP), 0);
4337 *returndist = dist_y + (dist_uv >> 2);
4338 }
4339 }
4169 4340
4170 void vp9_rd_pick_intra_mode(VP9_COMP *cpi, MACROBLOCK *x, 4341 void vp9_rd_pick_intra_mode(VP9_COMP *cpi, MACROBLOCK *x,
4171 int *returnrate, int *returndist) { 4342 int *returnrate, int *returndist) {
4172 VP9_COMMON *cm = &cpi->common; 4343 VP9_COMMON *cm = &cpi->common;
4173 MACROBLOCKD *xd = &x->e_mbd; 4344 MACROBLOCKD *xd = &x->e_mbd;
4174 MB_MODE_INFO * mbmi = &x->e_mbd.mode_info_context->mbmi; 4345 MB_MODE_INFO * mbmi = &x->e_mbd.mode_info_context->mbmi;
4175 int64_t error4x4, error16x16; 4346 int64_t error4x4, error16x16;
4176 #if CONFIG_COMP_INTRA_PRED
4177 int64_t error4x4d;
4178 int rate4x4d, dist4x4d;
4179 #endif
4180 int rate4x4, rate16x16 = 0, rateuv, rateuv8x8; 4347 int rate4x4, rate16x16 = 0, rateuv, rateuv8x8;
4181 int dist4x4 = 0, dist16x16 = 0, distuv = 0, distuv8x8 = 0; 4348 int dist4x4 = 0, dist16x16 = 0, distuv = 0, distuv8x8 = 0;
4182 int rate; 4349 int rate;
4183 int rate4x4_tokenonly = 0; 4350 int rate4x4_tokenonly = 0;
4184 int rate16x16_tokenonly = 0; 4351 int rate16x16_tokenonly = 0;
4185 int rateuv_tokenonly = 0, rateuv8x8_tokenonly = 0; 4352 int rateuv_tokenonly = 0, rateuv8x8_tokenonly = 0;
4186 int64_t error8x8; 4353 int64_t error8x8;
4187 int rate8x8_tokenonly=0; 4354 int rate8x8_tokenonly=0;
4188 int rate8x8, dist8x8; 4355 int rate8x8, dist8x8;
4189 int mode16x16; 4356 int mode16x16;
4190 int mode8x8[2][4]; 4357 int mode8x8[4];
4191 int dist; 4358 int dist;
4192 int modeuv, modeuv8x8, uv_intra_skippable, uv_intra_skippable_8x8; 4359 int modeuv, uv_intra_skippable, uv_intra_skippable_8x8;
4193 int y_intra16x16_skippable = 0; 4360 int y_intra16x16_skippable = 0;
4194 int64_t txfm_cache[NB_TXFM_MODES]; 4361 int64_t txfm_cache[NB_TXFM_MODES];
4195 TX_SIZE txfm_size_16x16; 4362 TX_SIZE txfm_size_16x16;
4196 int i; 4363 int i;
4197 4364
4198 mbmi->ref_frame = INTRA_FRAME; 4365 mbmi->ref_frame = INTRA_FRAME;
4199 rd_pick_intra_mbuv_mode(cpi, x, &rateuv, &rateuv_tokenonly, &distuv, 4366 rd_pick_intra_mbuv_mode(cpi, x, &rateuv, &rateuv_tokenonly, &distuv,
4200 &uv_intra_skippable); 4367 &uv_intra_skippable);
4201 modeuv = mbmi->uv_mode; 4368 modeuv = mbmi->uv_mode;
4202 if (cpi->common.txfm_mode != ONLY_4X4) { 4369 if (cpi->common.txfm_mode != ONLY_4X4) {
4203 rd_pick_intra_mbuv_mode_8x8(cpi, x, &rateuv8x8, &rateuv8x8_tokenonly, 4370 rd_pick_intra_mbuv_mode_8x8(cpi, x, &rateuv8x8, &rateuv8x8_tokenonly,
4204 &distuv8x8, &uv_intra_skippable_8x8); 4371 &distuv8x8, &uv_intra_skippable_8x8);
4205 modeuv8x8 = mbmi->uv_mode;
4206 } else { 4372 } else {
4207 uv_intra_skippable_8x8 = uv_intra_skippable; 4373 uv_intra_skippable_8x8 = uv_intra_skippable;
4208 rateuv8x8 = rateuv; 4374 rateuv8x8 = rateuv;
4209 distuv8x8 = distuv; 4375 distuv8x8 = distuv;
4210 rateuv8x8_tokenonly = rateuv_tokenonly; 4376 rateuv8x8_tokenonly = rateuv_tokenonly;
4211 modeuv8x8 = modeuv;
4212 } 4377 }
4213 4378
4214 // current macroblock under rate-distortion optimization test loop 4379 // current macroblock under rate-distortion optimization test loop
4215 error16x16 = rd_pick_intra16x16mby_mode(cpi, x, &rate16x16, 4380 error16x16 = rd_pick_intra16x16mby_mode(cpi, x, &rate16x16,
4216 &rate16x16_tokenonly, &dist16x16, 4381 &rate16x16_tokenonly, &dist16x16,
4217 &y_intra16x16_skippable, txfm_cache); 4382 &y_intra16x16_skippable, txfm_cache);
4218 mode16x16 = mbmi->mode; 4383 mode16x16 = mbmi->mode;
4219 txfm_size_16x16 = mbmi->txfm_size; 4384 txfm_size_16x16 = mbmi->txfm_size;
4220 4385
4221 // FIXME(rbultje) support transform-size selection 4386 // FIXME(rbultje) support transform-size selection
4222 mbmi->txfm_size = (cm->txfm_mode == ONLY_4X4) ? TX_4X4 : TX_8X8; 4387 mbmi->txfm_size = (cm->txfm_mode == ONLY_4X4) ? TX_4X4 : TX_8X8;
4223 error8x8 = rd_pick_intra8x8mby_modes(cpi, x, &rate8x8, &rate8x8_tokenonly, 4388 error8x8 = rd_pick_intra8x8mby_modes(cpi, x, &rate8x8, &rate8x8_tokenonly,
4224 &dist8x8, error16x16); 4389 &dist8x8, error16x16);
4225 mode8x8[0][0]= xd->mode_info_context->bmi[0].as_mode.first; 4390 mode8x8[0]= xd->mode_info_context->bmi[0].as_mode.first;
4226 mode8x8[0][1]= xd->mode_info_context->bmi[2].as_mode.first; 4391 mode8x8[1]= xd->mode_info_context->bmi[2].as_mode.first;
4227 mode8x8[0][2]= xd->mode_info_context->bmi[8].as_mode.first; 4392 mode8x8[2]= xd->mode_info_context->bmi[8].as_mode.first;
4228 mode8x8[0][3]= xd->mode_info_context->bmi[10].as_mode.first; 4393 mode8x8[3]= xd->mode_info_context->bmi[10].as_mode.first;
4229 #if CONFIG_COMP_INTRA_PRED
4230 mode8x8[1][0] = xd->mode_info_context->bmi[0].as_mode.second;
4231 mode8x8[1][1] = xd->mode_info_context->bmi[2].as_mode.second;
4232 mode8x8[1][2] = xd->mode_info_context->bmi[8].as_mode.second;
4233 mode8x8[1][3] = xd->mode_info_context->bmi[10].as_mode.second;
4234 #endif
4235 4394
4236 error4x4 = rd_pick_intra4x4mby_modes(cpi, x, 4395 error4x4 = rd_pick_intra4x4mby_modes(cpi, x,
4237 &rate4x4, &rate4x4_tokenonly, 4396 &rate4x4, &rate4x4_tokenonly,
4238 &dist4x4, error16x16, 4397 &dist4x4, error16x16,
4239 #if CONFIG_COMP_INTRA_PRED 4398 cpi->update_context);
4240 0,
4241 #endif
4242 0);
4243 #if CONFIG_COMP_INTRA_PRED
4244 error4x4d = rd_pick_intra4x4mby_modes(cpi, x,
4245 &rate4x4d, &rate4x4_tokenonly,
4246 &dist4x4d, error16x16, 1, 0);
4247 #endif
4248 4399
4249 mbmi->mb_skip_coeff = 0; 4400 mbmi->mb_skip_coeff = 0;
4250 if (cpi->common.mb_no_coeff_skip && 4401 if (cpi->common.mb_no_coeff_skip &&
4251 y_intra16x16_skippable && uv_intra_skippable_8x8) { 4402 y_intra16x16_skippable && uv_intra_skippable_8x8) {
4252 mbmi->mb_skip_coeff = 1; 4403 mbmi->mb_skip_coeff = 1;
4253 mbmi->mode = mode16x16; 4404 mbmi->mode = mode16x16;
4254 mbmi->uv_mode = modeuv; 4405 mbmi->uv_mode = modeuv;
4255 rate = rateuv8x8 + rate16x16 - rateuv8x8_tokenonly - rate16x16_tokenonly + 4406 rate = rateuv8x8 + rate16x16 - rateuv8x8_tokenonly - rate16x16_tokenonly +
4256 vp9_cost_bit(vp9_get_pred_prob(cm, xd, PRED_MBSKIP), 1); 4407 vp9_cost_bit(vp9_get_pred_prob(cm, xd, PRED_MBSKIP), 1);
4257 dist = dist16x16 + (distuv8x8 >> 2); 4408 dist = dist16x16 + (distuv8x8 >> 2);
4409
4258 mbmi->txfm_size = txfm_size_16x16; 4410 mbmi->txfm_size = txfm_size_16x16;
4259 memset(x->mb_context[xd->mb_index].txfm_rd_diff, 0, 4411 memset(x->mb_context[xd->sb_index][xd->mb_index].txfm_rd_diff, 0,
4260 sizeof(x->mb_context[xd->mb_index].txfm_rd_diff)); 4412 sizeof(x->mb_context[xd->sb_index][xd->mb_index].txfm_rd_diff));
4261 } else if (error8x8 > error16x16) { 4413 } else if (error8x8 > error16x16) {
4262 if (error4x4 < error16x16) { 4414 if (error4x4 < error16x16) {
4263 rate = rateuv; 4415 rate = rateuv + rate4x4;
4264 #if CONFIG_COMP_INTRA_PRED
4265 rate += (error4x4d < error4x4) ? rate4x4d : rate4x4;
4266 if (error4x4d >= error4x4) // FIXME save original modes etc.
4267 error4x4 = rd_pick_intra4x4mby_modes(cpi, x, &rate4x4,
4268 &rate4x4_tokenonly,
4269 &dist4x4, error16x16, 0,
4270 cpi->update_context);
4271 #else
4272 rate += rate4x4;
4273 #endif
4274 mbmi->mode = B_PRED; 4416 mbmi->mode = B_PRED;
4275 mbmi->txfm_size = TX_4X4; 4417 mbmi->txfm_size = TX_4X4;
4276 dist = dist4x4 + (distuv >> 2); 4418 dist = dist4x4 + (distuv >> 2);
4277 memset(x->mb_context[xd->mb_index].txfm_rd_diff, 0, 4419 memset(x->mb_context[xd->sb_index][xd->mb_index].txfm_rd_diff, 0,
4278 sizeof(x->mb_context[xd->mb_index].txfm_rd_diff)); 4420 sizeof(x->mb_context[xd->sb_index][xd->mb_index].txfm_rd_diff));
4279 } else { 4421 } else {
4280 mbmi->txfm_size = txfm_size_16x16; 4422 mbmi->txfm_size = txfm_size_16x16;
4281 mbmi->mode = mode16x16; 4423 mbmi->mode = mode16x16;
4282 rate = rate16x16 + rateuv8x8; 4424 rate = rate16x16 + rateuv8x8;
4283 dist = dist16x16 + (distuv8x8 >> 2); 4425 dist = dist16x16 + (distuv8x8 >> 2);
4284 for (i = 0; i < NB_TXFM_MODES; i++) { 4426 for (i = 0; i < NB_TXFM_MODES; i++) {
4285 x->mb_context[xd->mb_index].txfm_rd_diff[i] = error16x16 - txfm_cache[i] ; 4427 x->mb_context[xd->sb_index][xd->mb_index].txfm_rd_diff[i] =
4428 error16x16 - txfm_cache[i];
4286 } 4429 }
4287 } 4430 }
4288 if (cpi->common.mb_no_coeff_skip) 4431 if (cpi->common.mb_no_coeff_skip)
4289 rate += vp9_cost_bit(vp9_get_pred_prob(cm, xd, PRED_MBSKIP), 0); 4432 rate += vp9_cost_bit(vp9_get_pred_prob(cm, xd, PRED_MBSKIP), 0);
4290 } else { 4433 } else {
4291 if (error4x4 < error8x8) { 4434 if (error4x4 < error8x8) {
4292 rate = rateuv; 4435 rate = rateuv + rate4x4;
4293 #if CONFIG_COMP_INTRA_PRED
4294 rate += (error4x4d < error4x4) ? rate4x4d : rate4x4;
4295 if (error4x4d >= error4x4) // FIXME save original modes etc.
4296 error4x4 = rd_pick_intra4x4mby_modes(cpi, x, &rate4x4,
4297 &rate4x4_tokenonly,
4298 &dist4x4, error16x16, 0,
4299 cpi->update_context);
4300 #else
4301 rate += rate4x4;
4302 #endif
4303 mbmi->mode = B_PRED; 4436 mbmi->mode = B_PRED;
4304 mbmi->txfm_size = TX_4X4; 4437 mbmi->txfm_size = TX_4X4;
4305 dist = dist4x4 + (distuv >> 2); 4438 dist = dist4x4 + (distuv >> 2);
4306 memset(x->mb_context[xd->mb_index].txfm_rd_diff, 0, 4439 memset(x->mb_context[xd->sb_index][xd->mb_index].txfm_rd_diff, 0,
4307 sizeof(x->mb_context[xd->mb_index].txfm_rd_diff)); 4440 sizeof(x->mb_context[xd->sb_index][xd->mb_index].txfm_rd_diff));
4308 } else { 4441 } else {
4309 // FIXME(rbultje) support transform-size selection 4442 // FIXME(rbultje) support transform-size selection
4310 mbmi->mode = I8X8_PRED; 4443 mbmi->mode = I8X8_PRED;
4311 mbmi->txfm_size = (cm->txfm_mode == ONLY_4X4) ? TX_4X4 : TX_8X8; 4444 mbmi->txfm_size = (cm->txfm_mode == ONLY_4X4) ? TX_4X4 : TX_8X8;
4312 set_i8x8_block_modes(x, mode8x8); 4445 set_i8x8_block_modes(x, mode8x8);
4313 rate = rate8x8 + rateuv; 4446 rate = rate8x8 + rateuv;
4314 dist = dist8x8 + (distuv >> 2); 4447 dist = dist8x8 + (distuv >> 2);
4315 memset(x->mb_context[xd->mb_index].txfm_rd_diff, 0, 4448 memset(x->mb_context[xd->sb_index][xd->mb_index].txfm_rd_diff, 0,
4316 sizeof(x->mb_context[xd->mb_index].txfm_rd_diff)); 4449 sizeof(x->mb_context[xd->sb_index][xd->mb_index].txfm_rd_diff));
4317 } 4450 }
4318 if (cpi->common.mb_no_coeff_skip) 4451 if (cpi->common.mb_no_coeff_skip)
4319 rate += vp9_cost_bit(vp9_get_pred_prob(cm, xd, PRED_MBSKIP), 0); 4452 rate += vp9_cost_bit(vp9_get_pred_prob(cm, xd, PRED_MBSKIP), 0);
4320 } 4453 }
4321 4454
4322 *returnrate = rate; 4455 *returnrate = rate;
4323 *returndist = dist; 4456 *returndist = dist;
4324 } 4457 }
4325 4458
4326 #if CONFIG_SUPERBLOCKS 4459 static int64_t vp9_rd_pick_inter_mode_sb(VP9_COMP *cpi, MACROBLOCK *x,
4327 int64_t vp9_rd_pick_inter_mode_sb(VP9_COMP *cpi, MACROBLOCK *x, 4460 int recon_yoffset, int recon_uvoffset,
4328 int recon_yoffset, int recon_uvoffset, 4461 int *returnrate,
4329 int *returnrate, int *returndistortion) { 4462 int *returndistortion,
4463 int block_size) {
4330 VP9_COMMON *cm = &cpi->common; 4464 VP9_COMMON *cm = &cpi->common;
4331 MACROBLOCKD *xd = &x->e_mbd; 4465 MACROBLOCKD *xd = &x->e_mbd;
4332 MB_MODE_INFO *mbmi = &xd->mode_info_context->mbmi; 4466 MB_MODE_INFO *mbmi = &xd->mode_info_context->mbmi;
4333 MB_PREDICTION_MODE this_mode; 4467 MB_PREDICTION_MODE this_mode;
4468 MB_PREDICTION_MODE best_mode = DC_PRED;
4334 MV_REFERENCE_FRAME ref_frame; 4469 MV_REFERENCE_FRAME ref_frame;
4335 unsigned char segment_id = xd->mode_info_context->mbmi.segment_id; 4470 unsigned char segment_id = xd->mode_info_context->mbmi.segment_id;
4336 int comp_pred, i; 4471 int comp_pred, i;
4337 int_mv frame_mv[MB_MODE_COUNT][MAX_REF_FRAMES]; 4472 int_mv frame_mv[MB_MODE_COUNT][MAX_REF_FRAMES];
4338 int_mv frame_best_ref_mv[MAX_REF_FRAMES];
4339 int_mv mv_search_ref[MAX_REF_FRAMES];
4340 int frame_mdcounts[4][4]; 4473 int frame_mdcounts[4][4];
4341 unsigned char *y_buffer[4]; 4474 uint8_t *y_buffer[4];
4342 unsigned char *u_buffer[4]; 4475 uint8_t *u_buffer[4];
4343 unsigned char *v_buffer[4]; 4476 uint8_t *v_buffer[4];
4344 static const int flag_list[4] = { 0, VP9_LAST_FLAG, VP9_GOLD_FLAG, 4477 static const int flag_list[4] = { 0, VP9_LAST_FLAG, VP9_GOLD_FLAG,
4345 VP9_ALT_FLAG }; 4478 VP9_ALT_FLAG };
4346 int idx_list[4] = { 0, cpi->common.lst_fb_idx, cpi->common.gld_fb_idx, 4479 int idx_list[4] = { 0, cpi->common.lst_fb_idx, cpi->common.gld_fb_idx,
4347 cpi->common.alt_fb_idx }; 4480 cpi->common.alt_fb_idx };
4348 int mdcounts[4]; 4481 int mdcounts[4];
4349 int near_sadidx[8] = { 0, 1, 2, 3, 4, 5, 6, 7 }; 4482 int near_sadidx[8] = { 0, 1, 2, 3, 4, 5, 6, 7 };
4350 int saddone = 0; 4483 int saddone = 0;
4351 int64_t best_rd = INT64_MAX; 4484 int64_t best_rd = INT64_MAX;
4352 int64_t best_yrd = INT64_MAX;
4353 int64_t best_txfm_rd[NB_TXFM_MODES]; 4485 int64_t best_txfm_rd[NB_TXFM_MODES];
4354 int64_t best_txfm_diff[NB_TXFM_MODES]; 4486 int64_t best_txfm_diff[NB_TXFM_MODES];
4355 int64_t best_pred_diff[NB_PREDICTION_TYPES]; 4487 int64_t best_pred_diff[NB_PREDICTION_TYPES];
4356 int64_t best_pred_rd[NB_PREDICTION_TYPES]; 4488 int64_t best_pred_rd[NB_PREDICTION_TYPES];
4357 MB_MODE_INFO best_mbmode; 4489 MB_MODE_INFO best_mbmode;
4358 int mode_index, best_mode_index = 0; 4490 int mode_index, best_mode_index = 0;
4359 unsigned int ref_costs[MAX_REF_FRAMES]; 4491 unsigned int ref_costs[MAX_REF_FRAMES];
4360 #if CONFIG_COMP_INTERINTRA_PRED 4492 #if CONFIG_COMP_INTERINTRA_PRED
4361 int is_best_interintra = 0; 4493 int is_best_interintra = 0;
4362 int64_t best_intra16_rd = INT64_MAX; 4494 int64_t best_intra16_rd = INT64_MAX;
4363 int best_intra16_mode = DC_PRED, best_intra16_uv_mode = DC_PRED; 4495 int best_intra16_mode = DC_PRED, best_intra16_uv_mode = DC_PRED;
4364 #endif 4496 #endif
4365 int64_t best_overall_rd = INT64_MAX; 4497 int64_t best_overall_rd = INT64_MAX;
4498 INTERPOLATIONFILTERTYPE best_filter = SWITCHABLE;
4366 int rate_uv_4x4 = 0, rate_uv_8x8 = 0, rate_uv_tokenonly_4x4 = 0, 4499 int rate_uv_4x4 = 0, rate_uv_8x8 = 0, rate_uv_tokenonly_4x4 = 0,
4367 rate_uv_tokenonly_8x8 = 0; 4500 rate_uv_tokenonly_8x8 = 0;
4368 int dist_uv_4x4 = 0, dist_uv_8x8 = 0, uv_skip_4x4 = 0, uv_skip_8x8 = 0; 4501 int dist_uv_4x4 = 0, dist_uv_8x8 = 0, uv_skip_4x4 = 0, uv_skip_8x8 = 0;
4369 MB_PREDICTION_MODE mode_uv_4x4 = NEARESTMV, mode_uv_8x8 = NEARESTMV; 4502 MB_PREDICTION_MODE mode_uv_4x4 = NEARESTMV, mode_uv_8x8 = NEARESTMV;
4370 int switchable_filter_index = 0; 4503 int switchable_filter_index = 0;
4504 int rate_uv_16x16 = 0, rate_uv_tokenonly_16x16 = 0;
4505 int dist_uv_16x16 = 0, uv_skip_16x16 = 0;
4506 MB_PREDICTION_MODE mode_uv_16x16 = NEARESTMV;
4371 4507
4372 x->skip = 0; 4508 x->skip = 0;
4373 xd->mode_info_context->mbmi.segment_id = segment_id; 4509 xd->mode_info_context->mbmi.segment_id = segment_id;
4374 estimate_ref_frame_costs(cpi, segment_id, ref_costs); 4510 estimate_ref_frame_costs(cpi, segment_id, ref_costs);
4375 vpx_memset(&best_mbmode, 0, sizeof(best_mbmode)); 4511 vpx_memset(&best_mbmode, 0, sizeof(best_mbmode));
4376 4512
4377 for (i = 0; i < NB_PREDICTION_TYPES; ++i) 4513 for (i = 0; i < NB_PREDICTION_TYPES; ++i)
4378 best_pred_rd[i] = INT64_MAX; 4514 best_pred_rd[i] = INT64_MAX;
4379 for (i = 0; i < NB_TXFM_MODES; i++) 4515 for (i = 0; i < NB_TXFM_MODES; i++)
4380 best_txfm_rd[i] = INT64_MAX; 4516 best_txfm_rd[i] = INT64_MAX;
4381 4517
4382 for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ref_frame++) { 4518 for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ref_frame++) {
4383 if (cpi->ref_frame_flags & flag_list[ref_frame]) { 4519 if (cpi->ref_frame_flags & flag_list[ref_frame]) {
4384 setup_buffer_inter(cpi, x, idx_list[ref_frame], ref_frame, BLOCK_32X32, 4520 setup_buffer_inter(cpi, x, idx_list[ref_frame], ref_frame, block_size,
4385 recon_yoffset, recon_uvoffset, frame_mv[NEARESTMV], 4521 recon_yoffset, recon_uvoffset, frame_mv[NEARESTMV],
4386 frame_mv[NEARMV], frame_best_ref_mv, mv_search_ref, 4522 frame_mv[NEARMV], frame_mdcounts,
4387 frame_mdcounts, y_buffer, u_buffer, v_buffer); 4523 y_buffer, u_buffer, v_buffer);
4388 } 4524 }
4389 frame_mv[NEWMV][ref_frame].as_int = INVALID_MV; 4525 frame_mv[NEWMV][ref_frame].as_int = INVALID_MV;
4390 frame_mv[ZEROMV][ref_frame].as_int = 0; 4526 frame_mv[ZEROMV][ref_frame].as_int = 0;
4391 } 4527 }
4392 4528
4393 mbmi->mode = DC_PRED; 4529 if (block_size == BLOCK_64X64) {
4394 if (cm->txfm_mode == ONLY_4X4 || cm->txfm_mode == TX_MODE_SELECT) { 4530 mbmi->mode = DC_PRED;
4395 mbmi->txfm_size = TX_4X4; 4531 if (cm->txfm_mode == ONLY_4X4 || cm->txfm_mode == TX_MODE_SELECT) {
4396 rd_pick_intra_sbuv_mode(cpi, x, &rate_uv_4x4, &rate_uv_tokenonly_4x4, 4532 mbmi->txfm_size = TX_4X4;
4397 &dist_uv_4x4, &uv_skip_4x4); 4533 rd_pick_intra_sb64uv_mode(cpi, x, &rate_uv_4x4, &rate_uv_tokenonly_4x4,
4398 mode_uv_4x4 = mbmi->uv_mode; 4534 &dist_uv_4x4, &uv_skip_4x4);
4399 } 4535 mode_uv_4x4 = mbmi->uv_mode;
4400 if (cm->txfm_mode != ONLY_4X4) { 4536 }
4401 mbmi->txfm_size = TX_8X8; 4537 if (cm->txfm_mode != ONLY_4X4) {
4402 rd_pick_intra_sbuv_mode(cpi, x, &rate_uv_8x8, &rate_uv_tokenonly_8x8, 4538 mbmi->txfm_size = TX_8X8;
4403 &dist_uv_8x8, &uv_skip_8x8); 4539 rd_pick_intra_sb64uv_mode(cpi, x, &rate_uv_8x8, &rate_uv_tokenonly_8x8,
4404 mode_uv_8x8 = mbmi->uv_mode; 4540 &dist_uv_8x8, &uv_skip_8x8);
4541 mode_uv_8x8 = mbmi->uv_mode;
4542 }
4543 if (cm->txfm_mode >= ALLOW_32X32) {
4544 mbmi->txfm_size = TX_32X32;
4545 rd_pick_intra_sb64uv_mode(cpi, x, &rate_uv_16x16,
4546 &rate_uv_tokenonly_16x16,
4547 &dist_uv_16x16, &uv_skip_16x16);
4548 mode_uv_16x16 = mbmi->uv_mode;
4549 }
4550 } else {
4551 assert(block_size == BLOCK_32X32);
4552 mbmi->mode = DC_PRED;
4553 if (cm->txfm_mode == ONLY_4X4 || cm->txfm_mode == TX_MODE_SELECT) {
4554 mbmi->txfm_size = TX_4X4;
4555 rd_pick_intra_sbuv_mode(cpi, x, &rate_uv_4x4, &rate_uv_tokenonly_4x4,
4556 &dist_uv_4x4, &uv_skip_4x4);
4557 mode_uv_4x4 = mbmi->uv_mode;
4558 }
4559 if (cm->txfm_mode != ONLY_4X4) {
4560 mbmi->txfm_size = TX_8X8;
4561 rd_pick_intra_sbuv_mode(cpi, x, &rate_uv_8x8, &rate_uv_tokenonly_8x8,
4562 &dist_uv_8x8, &uv_skip_8x8);
4563 mode_uv_8x8 = mbmi->uv_mode;
4564 }
4565 if (cm->txfm_mode >= ALLOW_32X32) {
4566 mbmi->txfm_size = TX_32X32;
4567 rd_pick_intra_sbuv_mode(cpi, x, &rate_uv_16x16, &rate_uv_tokenonly_16x16,
4568 &dist_uv_16x16, &uv_skip_16x16);
4569 mode_uv_16x16 = mbmi->uv_mode;
4570 }
4405 } 4571 }
4406 4572
4407 for (mode_index = 0; mode_index < MAX_MODES; 4573 for (mode_index = 0; mode_index < MAX_MODES;
4408 mode_index += (!switchable_filter_index)) { 4574 mode_index += (!switchable_filter_index)) {
4409 int mode_excluded = 0; 4575 int mode_excluded = 0;
4410 int64_t this_rd = INT64_MAX; 4576 int64_t this_rd = INT64_MAX;
4411 int disable_skip = 0; 4577 int disable_skip = 0;
4412 int other_cost = 0; 4578 int other_cost = 0;
4413 int compmode_cost = 0; 4579 int compmode_cost = 0;
4414 int rate2 = 0, rate_y = 0, rate_uv = 0; 4580 int rate2 = 0, rate_y = 0, rate_uv = 0;
4415 int distortion2 = 0, distortion_y = 0, distortion_uv = 0; 4581 int distortion2 = 0, distortion_y = 0, distortion_uv = 0;
4416 int skippable; 4582 int skippable;
4417 int64_t txfm_cache[NB_TXFM_MODES]; 4583 int64_t txfm_cache[NB_TXFM_MODES];
4418 #if CONFIG_COMP_INTERINTRA_PRED 4584 #if CONFIG_COMP_INTERINTRA_PRED
4419 int compmode_interintra_cost = 0; 4585 int compmode_interintra_cost = 0;
4420 #endif 4586 #endif
4421 4587
4422 // Test best rd so far against threshold for trying this mode. 4588 // Test best rd so far against threshold for trying this mode.
4423 if (best_rd <= cpi->rd_threshes[mode_index] || 4589 if (best_rd <= cpi->rd_threshes[mode_index] ||
4424 cpi->rd_threshes[mode_index] == INT_MAX) { 4590 cpi->rd_threshes[mode_index] == INT_MAX) {
4591 switchable_filter_index = 0;
4425 continue; 4592 continue;
4426 } 4593 }
4427 4594
4428 this_mode = vp9_mode_order[mode_index].mode; 4595 this_mode = vp9_mode_order[mode_index].mode;
4429 ref_frame = vp9_mode_order[mode_index].ref_frame; 4596 ref_frame = vp9_mode_order[mode_index].ref_frame;
4430 if (!(ref_frame == INTRA_FRAME || 4597 if (!(ref_frame == INTRA_FRAME ||
4431 (cpi->ref_frame_flags & flag_list[ref_frame]))) { 4598 (cpi->ref_frame_flags & flag_list[ref_frame]))) {
4432 continue; 4599 continue;
4433 } 4600 }
4434 mbmi->ref_frame = ref_frame; 4601 mbmi->ref_frame = ref_frame;
4435 mbmi->second_ref_frame = vp9_mode_order[mode_index].second_ref_frame; 4602 mbmi->second_ref_frame = vp9_mode_order[mode_index].second_ref_frame;
4436 comp_pred = mbmi->second_ref_frame > INTRA_FRAME; 4603 comp_pred = mbmi->second_ref_frame > INTRA_FRAME;
4437 mbmi->mode = this_mode; 4604 mbmi->mode = this_mode;
4438 mbmi->uv_mode = DC_PRED; 4605 mbmi->uv_mode = DC_PRED;
4439 #if CONFIG_COMP_INTRA_PRED
4440 mbmi->second_mode = (MB_PREDICTION_MODE)(DC_PRED - 1);
4441 mbmi->second_uv_mode = (MB_PREDICTION_MODE)(DC_PRED - 1);
4442 #endif
4443 #if CONFIG_COMP_INTERINTRA_PRED 4606 #if CONFIG_COMP_INTERINTRA_PRED
4444 mbmi->interintra_mode = (MB_PREDICTION_MODE)(DC_PRED - 1); 4607 mbmi->interintra_mode = (MB_PREDICTION_MODE)(DC_PRED - 1);
4445 mbmi->interintra_uv_mode = (MB_PREDICTION_MODE)(DC_PRED - 1); 4608 mbmi->interintra_uv_mode = (MB_PREDICTION_MODE)(DC_PRED - 1);
4446 #endif 4609 #endif
4447 if (cpi->common.mcomp_filter_type == SWITCHABLE && 4610 // Evaluate all sub-pel filters irrespective of whether we can use
4448 this_mode >= NEARESTMV && this_mode <= SPLITMV) { 4611 // them for this frame.
4612 if (this_mode >= NEARESTMV && this_mode <= SPLITMV) {
4449 mbmi->interp_filter = 4613 mbmi->interp_filter =
4450 vp9_switchable_interp[switchable_filter_index++]; 4614 vp9_switchable_interp[switchable_filter_index++];
4451 if (switchable_filter_index == VP9_SWITCHABLE_FILTERS) 4615 if (switchable_filter_index == VP9_SWITCHABLE_FILTERS)
4452 switchable_filter_index = 0; 4616 switchable_filter_index = 0;
4453 } else { 4617 if ((cm->mcomp_filter_type != SWITCHABLE) &&
4454 mbmi->interp_filter = cpi->common.mcomp_filter_type; 4618 (cm->mcomp_filter_type != mbmi->interp_filter)) {
4619 mode_excluded = 1;
4620 }
4621 vp9_setup_interp_filters(xd, mbmi->interp_filter, &cpi->common);
4455 } 4622 }
4456 vp9_setup_interp_filters(xd, mbmi->interp_filter, &cpi->common);
4457 4623
4458 // if (!(cpi->ref_frame_flags & flag_list[ref_frame])) 4624 // if (!(cpi->ref_frame_flags & flag_list[ref_frame]))
4459 // continue; 4625 // continue;
4460 4626
4461 if (this_mode == I8X8_PRED || this_mode == B_PRED || this_mode == SPLITMV) 4627 if (this_mode == I8X8_PRED || this_mode == B_PRED || this_mode == SPLITMV)
4462 continue; 4628 continue;
4463 // if (vp9_mode_order[mode_index].second_ref_frame == INTRA_FRAME) 4629 // if (vp9_mode_order[mode_index].second_ref_frame == INTRA_FRAME)
4464 // continue; 4630 // continue;
4465 4631
4466 if (comp_pred) { 4632 if (comp_pred) {
4467 int second_ref; 4633 int second_ref;
4468 4634
4469 if (ref_frame == ALTREF_FRAME) { 4635 if (ref_frame == ALTREF_FRAME) {
4470 second_ref = LAST_FRAME; 4636 second_ref = LAST_FRAME;
4471 } else { 4637 } else {
4472 second_ref = ref_frame + 1; 4638 second_ref = ref_frame + 1;
4473 } 4639 }
4474 if (!(cpi->ref_frame_flags & flag_list[second_ref])) 4640 if (!(cpi->ref_frame_flags & flag_list[second_ref]))
4475 continue; 4641 continue;
4476 mbmi->second_ref_frame = second_ref; 4642 mbmi->second_ref_frame = second_ref;
4477 4643
4478 xd->second_pre.y_buffer = y_buffer[second_ref]; 4644 xd->second_pre.y_buffer = y_buffer[second_ref];
4479 xd->second_pre.u_buffer = u_buffer[second_ref]; 4645 xd->second_pre.u_buffer = u_buffer[second_ref];
4480 xd->second_pre.v_buffer = v_buffer[second_ref]; 4646 xd->second_pre.v_buffer = v_buffer[second_ref];
4481 mode_excluded = cm->comp_pred_mode == SINGLE_PREDICTION_ONLY; 4647 mode_excluded =
4648 mode_excluded ?
4649 mode_excluded : cm->comp_pred_mode == SINGLE_PREDICTION_ONLY;
4482 } else { 4650 } else {
4483 // mbmi->second_ref_frame = vp9_mode_order[mode_index].second_ref_frame; 4651 // mbmi->second_ref_frame = vp9_mode_order[mode_index].second_ref_frame;
4484 if (ref_frame != INTRA_FRAME) { 4652 if (ref_frame != INTRA_FRAME) {
4485 if (mbmi->second_ref_frame != INTRA_FRAME) 4653 if (mbmi->second_ref_frame != INTRA_FRAME)
4486 mode_excluded = cm->comp_pred_mode == COMP_PREDICTION_ONLY; 4654 mode_excluded =
4655 mode_excluded ?
4656 mode_excluded : cm->comp_pred_mode == COMP_PREDICTION_ONLY;
4487 #if CONFIG_COMP_INTERINTRA_PRED 4657 #if CONFIG_COMP_INTERINTRA_PRED
4488 else 4658 else
4489 mode_excluded = !cm->use_interintra; 4659 mode_excluded = mode_excluded ? mode_excluded : !cm->use_interintra;
4490 #endif 4660 #endif
4491 } 4661 }
4492 } 4662 }
4493 4663
4494 xd->pre.y_buffer = y_buffer[ref_frame]; 4664 xd->pre.y_buffer = y_buffer[ref_frame];
4495 xd->pre.u_buffer = u_buffer[ref_frame]; 4665 xd->pre.u_buffer = u_buffer[ref_frame];
4496 xd->pre.v_buffer = v_buffer[ref_frame]; 4666 xd->pre.v_buffer = v_buffer[ref_frame];
4497 vpx_memcpy(mdcounts, frame_mdcounts[ref_frame], sizeof(mdcounts)); 4667 vpx_memcpy(mdcounts, frame_mdcounts[ref_frame], sizeof(mdcounts));
4498 4668
4499 // If the segment reference frame feature is enabled.... 4669 // If the segment reference frame feature is enabled....
(...skipping 15 matching lines...) Expand all
4515 // unless ARNR filtering is enabled in which case we want 4685 // unless ARNR filtering is enabled in which case we want
4516 // an unfiltered alternative 4686 // an unfiltered alternative
4517 if (cpi->is_src_frame_alt_ref && (cpi->oxcf.arnr_max_frames == 0)) { 4687 if (cpi->is_src_frame_alt_ref && (cpi->oxcf.arnr_max_frames == 0)) {
4518 if (this_mode != ZEROMV || ref_frame != ALTREF_FRAME) { 4688 if (this_mode != ZEROMV || ref_frame != ALTREF_FRAME) {
4519 continue; 4689 continue;
4520 } 4690 }
4521 } 4691 }
4522 } 4692 }
4523 4693
4524 if (ref_frame == INTRA_FRAME) { 4694 if (ref_frame == INTRA_FRAME) {
4525 vp9_build_intra_predictors_sby_s(xd); 4695 if (block_size == BLOCK_64X64) {
4526 super_block_yrd(cpi, x, &rate_y, &distortion_y, 4696 vp9_build_intra_predictors_sb64y_s(xd);
4527 &skippable, txfm_cache); 4697 super_block_64_yrd(cpi, x, &rate_y, &distortion_y,
4698 &skippable, txfm_cache);
4699 } else {
4700 assert(block_size == BLOCK_32X32);
4701 vp9_build_intra_predictors_sby_s(xd);
4702 super_block_yrd(cpi, x, &rate_y, &distortion_y,
4703 &skippable, txfm_cache);
4704 }
4528 if (mbmi->txfm_size == TX_4X4) { 4705 if (mbmi->txfm_size == TX_4X4) {
4529 rate_uv = rate_uv_4x4; 4706 rate_uv = rate_uv_4x4;
4530 distortion_uv = dist_uv_4x4; 4707 distortion_uv = dist_uv_4x4;
4531 skippable = skippable && uv_skip_4x4; 4708 skippable = skippable && uv_skip_4x4;
4532 mbmi->uv_mode = mode_uv_4x4; 4709 mbmi->uv_mode = mode_uv_4x4;
4710 } else if (mbmi->txfm_size == TX_32X32) {
4711 rate_uv = rate_uv_16x16;
4712 distortion_uv = dist_uv_16x16;
4713 skippable = skippable && uv_skip_16x16;
4714 mbmi->uv_mode = mode_uv_16x16;
4533 } else { 4715 } else {
4534 rate_uv = rate_uv_8x8; 4716 rate_uv = rate_uv_8x8;
4535 distortion_uv = dist_uv_8x8; 4717 distortion_uv = dist_uv_8x8;
4536 skippable = skippable && uv_skip_8x8; 4718 skippable = skippable && uv_skip_8x8;
4537 mbmi->uv_mode = mode_uv_8x8; 4719 mbmi->uv_mode = mode_uv_8x8;
4538 } 4720 }
4539 4721
4540 rate2 = rate_y + x->mbmode_cost[cm->frame_type][mbmi->mode] + rate_uv; 4722 rate2 = rate_y + x->mbmode_cost[cm->frame_type][mbmi->mode] + rate_uv;
4541 distortion2 = distortion_y + distortion_uv; 4723 distortion2 = distortion_y + distortion_uv;
4542 } else { 4724 } else {
4543 #if CONFIG_COMP_INTERINTRA_PRED 4725 #if CONFIG_COMP_INTERINTRA_PRED
4544 if (mbmi->second_ref_frame == INTRA_FRAME) { 4726 if (mbmi->second_ref_frame == INTRA_FRAME) {
4545 if (best_intra16_mode == DC_PRED - 1) continue; 4727 if (best_intra16_mode == DC_PRED - 1) continue;
4546 mbmi->interintra_mode = best_intra16_mode; 4728 mbmi->interintra_mode = best_intra16_mode;
4547 #if SEPARATE_INTERINTRA_UV 4729 #if SEPARATE_INTERINTRA_UV
4548 mbmi->interintra_uv_mode = best_intra16_uv_mode; 4730 mbmi->interintra_uv_mode = best_intra16_uv_mode;
4549 #else 4731 #else
4550 mbmi->interintra_uv_mode = best_intra16_mode; 4732 mbmi->interintra_uv_mode = best_intra16_mode;
4551 #endif 4733 #endif
4552 } 4734 }
4553 #endif 4735 #endif
4554 this_rd = handle_inter_mode(cpi, x, BLOCK_32X32, 4736 this_rd = handle_inter_mode(cpi, x, block_size,
4555 &saddone, near_sadidx, mdcounts, txfm_cache, 4737 &saddone, near_sadidx, mdcounts, txfm_cache,
4556 &rate2, &distortion2, &skippable, 4738 &rate2, &distortion2, &skippable,
4557 &compmode_cost, 4739 &compmode_cost,
4558 #if CONFIG_COMP_INTERINTRA_PRED 4740 #if CONFIG_COMP_INTERINTRA_PRED
4559 &compmode_interintra_cost, 4741 &compmode_interintra_cost,
4560 #endif 4742 #endif
4561 &rate_y, &distortion_y, 4743 &rate_y, &distortion_y,
4562 &rate_uv, &distortion_uv, 4744 &rate_uv, &distortion_uv,
4563 &mode_excluded, &disable_skip, recon_yoffset, 4745 &mode_excluded, &disable_skip, recon_yoffset,
4564 mode_index, frame_mv, frame_best_ref_mv, 4746 mode_index, frame_mv);
4565 mv_search_ref);
4566 if (this_rd == INT64_MAX) 4747 if (this_rd == INT64_MAX)
4567 continue; 4748 continue;
4568 } 4749 }
4569 4750
4570 #if CONFIG_COMP_INTERINTRA_PRED 4751 #if CONFIG_COMP_INTERINTRA_PRED
4571 if (cpi->common.use_interintra) { 4752 if (cpi->common.use_interintra) {
4572 rate2 += compmode_interintra_cost; 4753 rate2 += compmode_interintra_cost;
4573 } 4754 }
4574 #endif 4755 #endif
4575 if (cpi->common.comp_pred_mode == HYBRID_PREDICTION) { 4756 if (cpi->common.comp_pred_mode == HYBRID_PREDICTION) {
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
4644 mode_uv_8x8 : mode_uv_4x4); 4825 mode_uv_8x8 : mode_uv_4x4);
4645 } 4826 }
4646 #endif 4827 #endif
4647 4828
4648 if (!disable_skip && mbmi->ref_frame == INTRA_FRAME) 4829 if (!disable_skip && mbmi->ref_frame == INTRA_FRAME)
4649 for (i = 0; i < NB_PREDICTION_TYPES; ++i) 4830 for (i = 0; i < NB_PREDICTION_TYPES; ++i)
4650 best_pred_rd[i] = MIN(best_pred_rd[i], this_rd); 4831 best_pred_rd[i] = MIN(best_pred_rd[i], this_rd);
4651 4832
4652 if (this_rd < best_overall_rd) { 4833 if (this_rd < best_overall_rd) {
4653 best_overall_rd = this_rd; 4834 best_overall_rd = this_rd;
4835 best_filter = mbmi->interp_filter;
4836 best_mode = this_mode;
4654 #if CONFIG_COMP_INTERINTRA_PRED 4837 #if CONFIG_COMP_INTERINTRA_PRED
4655 is_best_interintra = (mbmi->second_ref_frame == INTRA_FRAME); 4838 is_best_interintra = (mbmi->second_ref_frame == INTRA_FRAME);
4656 #endif 4839 #endif
4657 } 4840 }
4658 4841
4659 // Did this mode help.. i.e. is it the new best mode 4842 // Did this mode help.. i.e. is it the new best mode
4660 if (this_rd < best_rd || x->skip) { 4843 if (this_rd < best_rd || x->skip) {
4661 if (!mode_excluded) { 4844 if (!mode_excluded) {
4662 // Note index of best mode so far 4845 // Note index of best mode so far
4663 best_mode_index = mode_index; 4846 best_mode_index = mode_index;
4664 4847
4665 if (this_mode <= B_PRED) { 4848 if (this_mode <= B_PRED) {
4666 /* required for left and above block mv */ 4849 /* required for left and above block mv */
4667 mbmi->mv[0].as_int = 0; 4850 mbmi->mv[0].as_int = 0;
4668 } 4851 }
4669 4852
4670 other_cost += ref_costs[xd->mode_info_context->mbmi.ref_frame]; 4853 other_cost += ref_costs[xd->mode_info_context->mbmi.ref_frame];
4671
4672 /* Calculate the final y RD estimate for this mode */
4673 best_yrd = RDCOST(x->rdmult, x->rddiv, (rate2 - rate_uv - other_cost),
4674 (distortion2 - distortion_uv));
4675
4676 *returnrate = rate2; 4854 *returnrate = rate2;
4677 *returndistortion = distortion2; 4855 *returndistortion = distortion2;
4678 best_rd = this_rd; 4856 best_rd = this_rd;
4679 vpx_memcpy(&best_mbmode, mbmi, sizeof(MB_MODE_INFO)); 4857 vpx_memcpy(&best_mbmode, mbmi, sizeof(MB_MODE_INFO));
4680 } 4858 }
4681 #if 0 4859 #if 0
4682 // Testing this mode gave rise to an improvement in best error score. Lowe r threshold a bit for next time 4860 // Testing this mode gave rise to an improvement in best error score.
4683 cpi->rd_thresh_mult[mode_index] = (cpi->rd_thresh_mult[mode_index] >= (MIN _THRESHMULT + 2)) ? cpi->rd_thresh_mult[mode_index] - 2 : MIN_THRESHMULT; 4861 // Lower threshold a bit for next time
4684 cpi->rd_threshes[mode_index] = (cpi->rd_baseline_thresh[mode_index] >> 7) * cpi->rd_thresh_mult[mode_index]; 4862 cpi->rd_thresh_mult[mode_index] =
4863 (cpi->rd_thresh_mult[mode_index] >= (MIN_THRESHMULT + 2)) ?
4864 cpi->rd_thresh_mult[mode_index] - 2 : MIN_THRESHMULT;
4865 cpi->rd_threshes[mode_index] =
4866 (cpi->rd_baseline_thresh[mode_index] >> 7)
4867 * cpi->rd_thresh_mult[mode_index];
4685 #endif 4868 #endif
4686 } 4869 } else {
4687 // If the mode did not help improve the best error case then raise the thres hold for testing that mode next time around. 4870 // If the mode did not help improve the best error case then
4688 else { 4871 // raise the threshold for testing that mode next time around.
4689 #if 0 4872 #if 0
4690 cpi->rd_thresh_mult[mode_index] += 4; 4873 cpi->rd_thresh_mult[mode_index] += 4;
4691 4874
4692 if (cpi->rd_thresh_mult[mode_index] > MAX_THRESHMULT) 4875 if (cpi->rd_thresh_mult[mode_index] > MAX_THRESHMULT)
4693 cpi->rd_thresh_mult[mode_index] = MAX_THRESHMULT; 4876 cpi->rd_thresh_mult[mode_index] = MAX_THRESHMULT;
4694 4877
4695 cpi->rd_threshes[mode_index] = (cpi->rd_baseline_thresh[mode_index] >> 7) * cpi->rd_thresh_mult[mode_index]; 4878 cpi->rd_threshes[mode_index] =
4879 (cpi->rd_baseline_thresh[mode_index] >> 7)
4880 * cpi->rd_thresh_mult[mode_index];
4696 #endif 4881 #endif
4697 } 4882 }
4698 4883
4699 /* keep record of best compound/single-only prediction */ 4884 /* keep record of best compound/single-only prediction */
4700 if (!disable_skip && mbmi->ref_frame != INTRA_FRAME) { 4885 if (!disable_skip && mbmi->ref_frame != INTRA_FRAME) {
4701 int single_rd, hybrid_rd, single_rate, hybrid_rate; 4886 int single_rd, hybrid_rd, single_rate, hybrid_rate;
4702 4887
4703 if (cpi->common.comp_pred_mode == HYBRID_PREDICTION) { 4888 if (cpi->common.comp_pred_mode == HYBRID_PREDICTION) {
4704 single_rate = rate2 - compmode_cost; 4889 single_rate = rate2 - compmode_cost;
4705 hybrid_rate = rate2; 4890 hybrid_rate = rate2;
(...skipping 27 matching lines...) Expand all
4733 } 4918 }
4734 if (adj_rd < best_txfm_rd[i]) 4919 if (adj_rd < best_txfm_rd[i])
4735 best_txfm_rd[i] = adj_rd; 4920 best_txfm_rd[i] = adj_rd;
4736 } 4921 }
4737 } 4922 }
4738 4923
4739 if (x->skip && !mode_excluded) 4924 if (x->skip && !mode_excluded)
4740 break; 4925 break;
4741 } 4926 }
4742 4927
4928 assert((cm->mcomp_filter_type == SWITCHABLE) ||
4929 (cm->mcomp_filter_type == best_mbmode.interp_filter) ||
4930 (best_mbmode.mode <= B_PRED));
4931
4743 #if CONFIG_COMP_INTERINTRA_PRED 4932 #if CONFIG_COMP_INTERINTRA_PRED
4744 ++cpi->interintra_select_count[is_best_interintra]; 4933 ++cpi->interintra_select_count[is_best_interintra];
4745 // if (is_best_interintra) printf("best_interintra\n"); 4934 // if (is_best_interintra) printf("best_interintra\n");
4746 #endif 4935 #endif
4747 4936
4937 // Accumulate filter usage stats
4938 // TODO(agrange): Use RD criteria to select interpolation filter mode.
4939 if ((best_mode >= NEARESTMV) && (best_mode <= SPLITMV))
4940 ++cpi->best_switchable_interp_count[vp9_switchable_interp_map[best_filter]];
4941
4748 // TODO(rbultje) integrate with RD thresholding 4942 // TODO(rbultje) integrate with RD thresholding
4749 #if 0 4943 #if 0
4750 // Reduce the activation RD thresholds for the best choice mode 4944 // Reduce the activation RD thresholds for the best choice mode
4751 if ((cpi->rd_baseline_thresh[best_mode_index] > 0) && 4945 if ((cpi->rd_baseline_thresh[best_mode_index] > 0) &&
4752 (cpi->rd_baseline_thresh[best_mode_index] < (INT_MAX >> 2))) { 4946 (cpi->rd_baseline_thresh[best_mode_index] < (INT_MAX >> 2))) {
4753 int best_adjustment = (cpi->rd_thresh_mult[best_mode_index] >> 2); 4947 int best_adjustment = (cpi->rd_thresh_mult[best_mode_index] >> 2);
4754 4948
4755 cpi->rd_thresh_mult[best_mode_index] = 4949 cpi->rd_thresh_mult[best_mode_index] =
4756 (cpi->rd_thresh_mult[best_mode_index] >= (MIN_THRESHMULT + best_adjustment )) ? 4950 (cpi->rd_thresh_mult[best_mode_index] >= (MIN_THRESHMULT + best_adjustment )) ?
4757 cpi->rd_thresh_mult[best_mode_index] - best_adjustment : MIN_THRESHMULT; 4951 cpi->rd_thresh_mult[best_mode_index] - best_adjustment : MIN_THRESHMULT;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
4799 if (best_txfm_rd[i] == INT64_MAX) 4993 if (best_txfm_rd[i] == INT64_MAX)
4800 best_txfm_diff[i] = INT_MIN; 4994 best_txfm_diff[i] = INT_MIN;
4801 else 4995 else
4802 best_txfm_diff[i] = best_rd - best_txfm_rd[i]; 4996 best_txfm_diff[i] = best_rd - best_txfm_rd[i];
4803 } 4997 }
4804 } else { 4998 } else {
4805 vpx_memset(best_txfm_diff, 0, sizeof(best_txfm_diff)); 4999 vpx_memset(best_txfm_diff, 0, sizeof(best_txfm_diff));
4806 } 5000 }
4807 5001
4808 end: 5002 end:
4809 store_coding_context(x, &x->sb_context[0], best_mode_index, NULL, 5003 {
4810 &frame_best_ref_mv[mbmi->ref_frame], 5004 PICK_MODE_CONTEXT *p = (block_size == BLOCK_32X32) ?
4811 &frame_best_ref_mv[mbmi->second_ref_frame < 0 ? 5005 &x->sb32_context[xd->sb_index] :
4812 0 : mbmi->second_ref_frame], 5006 &x->sb64_context;
4813 best_pred_diff, best_txfm_diff); 5007 store_coding_context(x, p, best_mode_index, NULL,
5008 &mbmi->ref_mvs[mbmi->ref_frame][0],
5009 &mbmi->ref_mvs[mbmi->second_ref_frame < 0 ? 0 :
5010 mbmi->second_ref_frame][0],
5011 best_pred_diff, best_txfm_diff);
5012 }
4814 5013
4815 return best_rd; 5014 return best_rd;
4816 } 5015 }
4817 #endif 5016
5017 int64_t vp9_rd_pick_inter_mode_sb32(VP9_COMP *cpi, MACROBLOCK *x,
5018 int recon_yoffset, int recon_uvoffset,
5019 int *returnrate,
5020 int *returndistortion) {
5021 return vp9_rd_pick_inter_mode_sb(cpi, x, recon_yoffset, recon_uvoffset,
5022 returnrate, returndistortion, BLOCK_32X32);
5023 }
5024
5025 int64_t vp9_rd_pick_inter_mode_sb64(VP9_COMP *cpi, MACROBLOCK *x,
5026 int recon_yoffset, int recon_uvoffset,
5027 int *returnrate,
5028 int *returndistortion) {
5029 return vp9_rd_pick_inter_mode_sb(cpi, x, recon_yoffset, recon_uvoffset,
5030 returnrate, returndistortion, BLOCK_64X64);
5031 }
4818 5032
4819 void vp9_pick_mode_inter_macroblock(VP9_COMP *cpi, MACROBLOCK *x, 5033 void vp9_pick_mode_inter_macroblock(VP9_COMP *cpi, MACROBLOCK *x,
4820 int recon_yoffset, 5034 int recon_yoffset,
4821 int recon_uvoffset, 5035 int recon_uvoffset,
4822 int *totalrate, int *totaldist) { 5036 int *totalrate, int *totaldist) {
4823 MACROBLOCKD *const xd = &x->e_mbd; 5037 MACROBLOCKD *const xd = &x->e_mbd;
4824 MB_MODE_INFO * mbmi = &x->e_mbd.mode_info_context->mbmi; 5038 MB_MODE_INFO * mbmi = &x->e_mbd.mode_info_context->mbmi;
4825 int rate, distortion; 5039 int rate, distortion;
4826 int64_t intra_error = 0; 5040 int64_t intra_error = 0;
4827 unsigned char *segment_id = &mbmi->segment_id; 5041 unsigned char *segment_id = &mbmi->segment_id;
(...skipping 13 matching lines...) Expand all
4841 5055
4842 /* restore cpi->zbin_mode_boost_enabled */ 5056 /* restore cpi->zbin_mode_boost_enabled */
4843 cpi->zbin_mode_boost_enabled = zbin_mode_boost_enabled; 5057 cpi->zbin_mode_boost_enabled = zbin_mode_boost_enabled;
4844 } 5058 }
4845 // else 5059 // else
4846 // The non rd encode path has been deleted from this code base 5060 // The non rd encode path has been deleted from this code base
4847 // to simplify development 5061 // to simplify development
4848 // vp9_pick_inter_mode 5062 // vp9_pick_inter_mode
4849 5063
4850 // Store metrics so they can be added in to totals if this mode is picked 5064 // Store metrics so they can be added in to totals if this mode is picked
4851 x->mb_context[xd->mb_index].distortion = distortion; 5065 x->mb_context[xd->sb_index][xd->mb_index].distortion = distortion;
4852 x->mb_context[xd->mb_index].intra_error = intra_error; 5066 x->mb_context[xd->sb_index][xd->mb_index].intra_error = intra_error;
4853 5067
4854 *totalrate = rate; 5068 *totalrate = rate;
4855 *totaldist = distortion; 5069 *totaldist = distortion;
4856 } 5070 }
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