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

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

Issue 812033011: libvpx: Pull from upstream (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/deps/third_party/libvpx/
Patch Set: Created 5 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_rd.c ('k') | source/libvpx/vp9/encoder/vp9_speed_features.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 19 matching lines...) Expand all
30 #include "vp9/encoder/vp9_cost.h" 30 #include "vp9/encoder/vp9_cost.h"
31 #include "vp9/encoder/vp9_encodemb.h" 31 #include "vp9/encoder/vp9_encodemb.h"
32 #include "vp9/encoder/vp9_encodemv.h" 32 #include "vp9/encoder/vp9_encodemv.h"
33 #include "vp9/encoder/vp9_encoder.h" 33 #include "vp9/encoder/vp9_encoder.h"
34 #include "vp9/encoder/vp9_mcomp.h" 34 #include "vp9/encoder/vp9_mcomp.h"
35 #include "vp9/encoder/vp9_quantize.h" 35 #include "vp9/encoder/vp9_quantize.h"
36 #include "vp9/encoder/vp9_ratectrl.h" 36 #include "vp9/encoder/vp9_ratectrl.h"
37 #include "vp9/encoder/vp9_rd.h" 37 #include "vp9/encoder/vp9_rd.h"
38 #include "vp9/encoder/vp9_rdopt.h" 38 #include "vp9/encoder/vp9_rdopt.h"
39 #include "vp9/encoder/vp9_variance.h" 39 #include "vp9/encoder/vp9_variance.h"
40 #include "vp9/encoder/vp9_aq_variance.h"
40 41
41 #define LAST_FRAME_MODE_MASK ((1 << GOLDEN_FRAME) | (1 << ALTREF_FRAME) | \ 42 #define LAST_FRAME_MODE_MASK ((1 << GOLDEN_FRAME) | (1 << ALTREF_FRAME) | \
42 (1 << INTRA_FRAME)) 43 (1 << INTRA_FRAME))
43 #define GOLDEN_FRAME_MODE_MASK ((1 << LAST_FRAME) | (1 << ALTREF_FRAME) | \ 44 #define GOLDEN_FRAME_MODE_MASK ((1 << LAST_FRAME) | (1 << ALTREF_FRAME) | \
44 (1 << INTRA_FRAME)) 45 (1 << INTRA_FRAME))
45 #define ALT_REF_MODE_MASK ((1 << LAST_FRAME) | (1 << GOLDEN_FRAME) | \ 46 #define ALT_REF_MODE_MASK ((1 << LAST_FRAME) | (1 << GOLDEN_FRAME) | \
46 (1 << INTRA_FRAME)) 47 (1 << INTRA_FRAME))
47 48
48 #define SECOND_REF_FRAME_MASK ((1 << ALTREF_FRAME) | 0x01) 49 #define SECOND_REF_FRAME_MASK ((1 << ALTREF_FRAME) | 0x01)
49 50
50 #define MIN_EARLY_TERM_INDEX 3 51 #define MIN_EARLY_TERM_INDEX 3
52 #define NEW_MV_DISCOUNT_FACTOR 8
51 53
52 typedef struct { 54 typedef struct {
53 PREDICTION_MODE mode; 55 PREDICTION_MODE mode;
54 MV_REFERENCE_FRAME ref_frame[2]; 56 MV_REFERENCE_FRAME ref_frame[2];
55 } MODE_DEFINITION; 57 } MODE_DEFINITION;
56 58
57 typedef struct { 59 typedef struct {
58 MV_REFERENCE_FRAME ref_frame[2]; 60 MV_REFERENCE_FRAME ref_frame[2];
59 } REF_DEFINITION; 61 } REF_DEFINITION;
60 62
61 struct rdcost_block_args { 63 struct rdcost_block_args {
62 MACROBLOCK *x; 64 MACROBLOCK *x;
63 ENTROPY_CONTEXT t_above[16]; 65 ENTROPY_CONTEXT t_above[16];
64 ENTROPY_CONTEXT t_left[16]; 66 ENTROPY_CONTEXT t_left[16];
65 int rate; 67 int rate;
66 int64_t dist; 68 int64_t dist;
67 int64_t sse; 69 int64_t sse;
68 int this_rate; 70 int this_rate;
69 int64_t this_dist; 71 int64_t this_dist;
70 int64_t this_sse; 72 int64_t this_sse;
71 int64_t this_rd; 73 int64_t this_rd;
72 int64_t best_rd; 74 int64_t best_rd;
73 int skip; 75 int skip;
74 int use_fast_coef_costing; 76 int use_fast_coef_costing;
75 const scan_order *so; 77 const scan_order *so;
76 }; 78 };
77 79
80 #define LAST_NEW_MV_INDEX 6
78 static const MODE_DEFINITION vp9_mode_order[MAX_MODES] = { 81 static const MODE_DEFINITION vp9_mode_order[MAX_MODES] = {
79 {NEARESTMV, {LAST_FRAME, NONE}}, 82 {NEARESTMV, {LAST_FRAME, NONE}},
80 {NEARESTMV, {ALTREF_FRAME, NONE}}, 83 {NEARESTMV, {ALTREF_FRAME, NONE}},
81 {NEARESTMV, {GOLDEN_FRAME, NONE}}, 84 {NEARESTMV, {GOLDEN_FRAME, NONE}},
82 85
83 {DC_PRED, {INTRA_FRAME, NONE}}, 86 {DC_PRED, {INTRA_FRAME, NONE}},
84 87
85 {NEWMV, {LAST_FRAME, NONE}}, 88 {NEWMV, {LAST_FRAME, NONE}},
86 {NEWMV, {ALTREF_FRAME, NONE}}, 89 {NEWMV, {ALTREF_FRAME, NONE}},
87 {NEWMV, {GOLDEN_FRAME, NONE}}, 90 {NEWMV, {GOLDEN_FRAME, NONE}},
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 122
120 static const REF_DEFINITION vp9_ref_order[MAX_REFS] = { 123 static const REF_DEFINITION vp9_ref_order[MAX_REFS] = {
121 {{LAST_FRAME, NONE}}, 124 {{LAST_FRAME, NONE}},
122 {{GOLDEN_FRAME, NONE}}, 125 {{GOLDEN_FRAME, NONE}},
123 {{ALTREF_FRAME, NONE}}, 126 {{ALTREF_FRAME, NONE}},
124 {{LAST_FRAME, ALTREF_FRAME}}, 127 {{LAST_FRAME, ALTREF_FRAME}},
125 {{GOLDEN_FRAME, ALTREF_FRAME}}, 128 {{GOLDEN_FRAME, ALTREF_FRAME}},
126 {{INTRA_FRAME, NONE}}, 129 {{INTRA_FRAME, NONE}},
127 }; 130 };
128 131
129 static int raster_block_offset(BLOCK_SIZE plane_bsize,
130 int raster_block, int stride) {
131 const int bw = b_width_log2_lookup[plane_bsize];
132 const int y = 4 * (raster_block >> bw);
133 const int x = 4 * (raster_block & ((1 << bw) - 1));
134 return y * stride + x;
135 }
136 static int16_t* raster_block_offset_int16(BLOCK_SIZE plane_bsize,
137 int raster_block, int16_t *base) {
138 const int stride = 4 * num_4x4_blocks_wide_lookup[plane_bsize];
139 return base + raster_block_offset(plane_bsize, raster_block, stride);
140 }
141
142 static void swap_block_ptr(MACROBLOCK *x, PICK_MODE_CONTEXT *ctx, 132 static void swap_block_ptr(MACROBLOCK *x, PICK_MODE_CONTEXT *ctx,
143 int m, int n, int min_plane, int max_plane) { 133 int m, int n, int min_plane, int max_plane) {
144 int i; 134 int i;
145 135
146 for (i = min_plane; i < max_plane; ++i) { 136 for (i = min_plane; i < max_plane; ++i) {
147 struct macroblock_plane *const p = &x->plane[i]; 137 struct macroblock_plane *const p = &x->plane[i];
148 struct macroblockd_plane *const pd = &x->e_mbd.plane[i]; 138 struct macroblockd_plane *const pd = &x->e_mbd.plane[i];
149 139
150 p->coeff = ctx->coeff_pbuf[i][m]; 140 p->coeff = ctx->coeff_pbuf[i][m];
151 p->qcoeff = ctx->qcoeff_pbuf[i][m]; 141 p->qcoeff = ctx->qcoeff_pbuf[i][m];
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 if (quantizer < 120) 248 if (quantizer < 120)
259 rate = (square_error * (280 - quantizer)) >> 8; 249 rate = (square_error * (280 - quantizer)) >> 8;
260 else 250 else
261 rate = 0; 251 rate = 0;
262 dist = (square_error * quantizer) >> 8; 252 dist = (square_error * quantizer) >> 8;
263 rate_sum += rate; 253 rate_sum += rate;
264 dist_sum += dist; 254 dist_sum += dist;
265 } else { 255 } else {
266 #if CONFIG_VP9_HIGHBITDEPTH 256 #if CONFIG_VP9_HIGHBITDEPTH
267 if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) { 257 if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
268 vp9_model_rd_from_var_lapndz(sum_sse, 1 << num_pels_log2_lookup[bs], 258 vp9_model_rd_from_var_lapndz(sum_sse, num_pels_log2_lookup[bs],
269 pd->dequant[1] >> (xd->bd - 5), 259 pd->dequant[1] >> (xd->bd - 5),
270 &rate, &dist); 260 &rate, &dist);
271 } else { 261 } else {
272 vp9_model_rd_from_var_lapndz(sum_sse, 1 << num_pels_log2_lookup[bs], 262 vp9_model_rd_from_var_lapndz(sum_sse, num_pels_log2_lookup[bs],
273 pd->dequant[1] >> 3, &rate, &dist); 263 pd->dequant[1] >> 3, &rate, &dist);
274 } 264 }
275 #else 265 #else
276 vp9_model_rd_from_var_lapndz(sum_sse, 1 << num_pels_log2_lookup[bs], 266 vp9_model_rd_from_var_lapndz(sum_sse, num_pels_log2_lookup[bs],
277 pd->dequant[1] >> 3, &rate, &dist); 267 pd->dequant[1] >> 3, &rate, &dist);
278 #endif // CONFIG_VP9_HIGHBITDEPTH 268 #endif // CONFIG_VP9_HIGHBITDEPTH
279 rate_sum += rate; 269 rate_sum += rate;
280 dist_sum += dist; 270 dist_sum += dist;
281 } 271 }
282 } 272 }
283 273
284 *skip_txfm_sb = skip_flag; 274 *skip_txfm_sb = skip_flag;
285 *skip_sse_sb = total_sse << 4; 275 *skip_sse_sb = total_sse << 4;
286 *out_rate_sum = (int)rate_sum; 276 *out_rate_sum = (int)rate_sum;
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 const struct macroblockd_plane *pd = &xd->plane[plane]; 340 const struct macroblockd_plane *pd = &xd->plane[plane];
351 const PLANE_TYPE type = pd->plane_type; 341 const PLANE_TYPE type = pd->plane_type;
352 const int16_t *band_count = &band_counts[tx_size][1]; 342 const int16_t *band_count = &band_counts[tx_size][1];
353 const int eob = p->eobs[block]; 343 const int eob = p->eobs[block];
354 const tran_low_t *const qcoeff = BLOCK_OFFSET(p->qcoeff, block); 344 const tran_low_t *const qcoeff = BLOCK_OFFSET(p->qcoeff, block);
355 unsigned int (*token_costs)[2][COEFF_CONTEXTS][ENTROPY_TOKENS] = 345 unsigned int (*token_costs)[2][COEFF_CONTEXTS][ENTROPY_TOKENS] =
356 x->token_costs[tx_size][type][is_inter_block(mbmi)]; 346 x->token_costs[tx_size][type][is_inter_block(mbmi)];
357 uint8_t token_cache[32 * 32]; 347 uint8_t token_cache[32 * 32];
358 int pt = combine_entropy_contexts(*A, *L); 348 int pt = combine_entropy_contexts(*A, *L);
359 int c, cost; 349 int c, cost;
350 #if CONFIG_VP9_HIGHBITDEPTH
351 const int16_t *cat6_high_cost = vp9_get_high_cost_table(xd->bd);
352 #else
353 const int16_t *cat6_high_cost = vp9_get_high_cost_table(8);
354 #endif
355
360 // Check for consistency of tx_size with mode info 356 // Check for consistency of tx_size with mode info
361 assert(type == PLANE_TYPE_Y ? mbmi->tx_size == tx_size 357 assert(type == PLANE_TYPE_Y ? mbmi->tx_size == tx_size
362 : get_uv_tx_size(mbmi, pd) == tx_size); 358 : get_uv_tx_size(mbmi, pd) == tx_size);
363 359
364 if (eob == 0) { 360 if (eob == 0) {
365 // single eob token 361 // single eob token
366 cost = token_costs[0][0][pt][EOB_TOKEN]; 362 cost = token_costs[0][0][pt][EOB_TOKEN];
367 c = 0; 363 c = 0;
368 } else { 364 } else {
369 int band_left = *band_count++; 365 int band_left = *band_count++;
370 366
371 // dc token 367 // dc token
372 int v = qcoeff[0]; 368 int v = qcoeff[0];
373 int prev_t = vp9_dct_value_tokens_ptr[v].token; 369 int16_t prev_t;
374 cost = (*token_costs)[0][pt][prev_t] + vp9_dct_value_cost_ptr[v]; 370 EXTRABIT e;
371 vp9_get_token_extra(v, &prev_t, &e);
372 cost = (*token_costs)[0][pt][prev_t] +
373 vp9_get_cost(prev_t, e, cat6_high_cost);
374
375 token_cache[0] = vp9_pt_energy_class[prev_t]; 375 token_cache[0] = vp9_pt_energy_class[prev_t];
376 ++token_costs; 376 ++token_costs;
377 377
378 // ac tokens 378 // ac tokens
379 for (c = 1; c < eob; c++) { 379 for (c = 1; c < eob; c++) {
380 const int rc = scan[c]; 380 const int rc = scan[c];
381 int t; 381 int16_t t;
382 382
383 v = qcoeff[rc]; 383 v = qcoeff[rc];
384 t = vp9_dct_value_tokens_ptr[v].token; 384 vp9_get_token_extra(v, &t, &e);
385 if (use_fast_coef_costing) { 385 if (use_fast_coef_costing) {
386 cost += (*token_costs)[!prev_t][!prev_t][t] + vp9_dct_value_cost_ptr[v]; 386 cost += (*token_costs)[!prev_t][!prev_t][t] +
387 vp9_get_cost(t, e, cat6_high_cost);
387 } else { 388 } else {
388 pt = get_coef_context(nb, token_cache, c); 389 pt = get_coef_context(nb, token_cache, c);
389 cost += (*token_costs)[!prev_t][pt][t] + vp9_dct_value_cost_ptr[v]; 390 cost += (*token_costs)[!prev_t][pt][t] +
391 vp9_get_cost(t, e, cat6_high_cost);
390 token_cache[rc] = vp9_pt_energy_class[t]; 392 token_cache[rc] = vp9_pt_energy_class[t];
391 } 393 }
392 prev_t = t; 394 prev_t = t;
393 if (!--band_left) { 395 if (!--band_left) {
394 band_left = *band_count++; 396 band_left = *band_count++;
395 ++token_costs; 397 ++token_costs;
396 } 398 }
397 } 399 }
398 400
399 // eob token 401 // eob token
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after
751 int64_t *bestdistortion, 753 int64_t *bestdistortion,
752 BLOCK_SIZE bsize, int64_t rd_thresh) { 754 BLOCK_SIZE bsize, int64_t rd_thresh) {
753 PREDICTION_MODE mode; 755 PREDICTION_MODE mode;
754 MACROBLOCKD *const xd = &x->e_mbd; 756 MACROBLOCKD *const xd = &x->e_mbd;
755 int64_t best_rd = rd_thresh; 757 int64_t best_rd = rd_thresh;
756 758
757 struct macroblock_plane *p = &x->plane[0]; 759 struct macroblock_plane *p = &x->plane[0];
758 struct macroblockd_plane *pd = &xd->plane[0]; 760 struct macroblockd_plane *pd = &xd->plane[0];
759 const int src_stride = p->src.stride; 761 const int src_stride = p->src.stride;
760 const int dst_stride = pd->dst.stride; 762 const int dst_stride = pd->dst.stride;
761 const uint8_t *src_init = &p->src.buf[raster_block_offset(BLOCK_8X8, ib, 763 const uint8_t *src_init = &p->src.buf[vp9_raster_block_offset(BLOCK_8X8, ib,
762 src_stride)]; 764 src_stride)];
763 uint8_t *dst_init = &pd->dst.buf[raster_block_offset(BLOCK_8X8, ib, 765 uint8_t *dst_init = &pd->dst.buf[vp9_raster_block_offset(BLOCK_8X8, ib,
764 dst_stride)]; 766 dst_stride)];
765 ENTROPY_CONTEXT ta[2], tempa[2]; 767 ENTROPY_CONTEXT ta[2], tempa[2];
766 ENTROPY_CONTEXT tl[2], templ[2]; 768 ENTROPY_CONTEXT tl[2], templ[2];
767 769
768 const int num_4x4_blocks_wide = num_4x4_blocks_wide_lookup[bsize]; 770 const int num_4x4_blocks_wide = num_4x4_blocks_wide_lookup[bsize];
769 const int num_4x4_blocks_high = num_4x4_blocks_high_lookup[bsize]; 771 const int num_4x4_blocks_high = num_4x4_blocks_high_lookup[bsize];
770 int idx, idy; 772 int idx, idy;
771 uint8_t best_dst[8 * 8]; 773 uint8_t best_dst[8 * 8];
772 #if CONFIG_VP9_HIGHBITDEPTH 774 #if CONFIG_VP9_HIGHBITDEPTH
773 uint16_t best_dst16[8 * 8]; 775 uint16_t best_dst16[8 * 8];
774 #endif 776 #endif
(...skipping 23 matching lines...) Expand all
798 } 800 }
799 801
800 vpx_memcpy(tempa, ta, sizeof(ta)); 802 vpx_memcpy(tempa, ta, sizeof(ta));
801 vpx_memcpy(templ, tl, sizeof(tl)); 803 vpx_memcpy(templ, tl, sizeof(tl));
802 804
803 for (idy = 0; idy < num_4x4_blocks_high; ++idy) { 805 for (idy = 0; idy < num_4x4_blocks_high; ++idy) {
804 for (idx = 0; idx < num_4x4_blocks_wide; ++idx) { 806 for (idx = 0; idx < num_4x4_blocks_wide; ++idx) {
805 const int block = ib + idy * 2 + idx; 807 const int block = ib + idy * 2 + idx;
806 const uint8_t *const src = &src_init[idx * 4 + idy * 4 * src_stride]; 808 const uint8_t *const src = &src_init[idx * 4 + idy * 4 * src_stride];
807 uint8_t *const dst = &dst_init[idx * 4 + idy * 4 * dst_stride]; 809 uint8_t *const dst = &dst_init[idx * 4 + idy * 4 * dst_stride];
808 int16_t *const src_diff = raster_block_offset_int16(BLOCK_8X8, block, 810 int16_t *const src_diff = vp9_raster_block_offset_int16(BLOCK_8X8,
809 p->src_diff); 811 block,
812 p->src_diff);
810 tran_low_t *const coeff = BLOCK_OFFSET(x->plane[0].coeff, block); 813 tran_low_t *const coeff = BLOCK_OFFSET(x->plane[0].coeff, block);
811 xd->mi[0].src_mi->bmi[block].as_mode = mode; 814 xd->mi[0].src_mi->bmi[block].as_mode = mode;
812 vp9_predict_intra_block(xd, block, 1, 815 vp9_predict_intra_block(xd, block, 1,
813 TX_4X4, mode, 816 TX_4X4, mode,
814 x->skip_encode ? src : dst, 817 x->skip_encode ? src : dst,
815 x->skip_encode ? src_stride : dst_stride, 818 x->skip_encode ? src_stride : dst_stride,
816 dst, dst_stride, idx, idy, 0); 819 dst, dst_stride, idx, idy, 0);
817 vp9_highbd_subtract_block(4, 4, src_diff, 8, src, src_stride, 820 vp9_highbd_subtract_block(4, 4, src_diff, 8, src, src_stride,
818 dst, dst_stride, xd->bd); 821 dst, dst_stride, xd->bd);
819 if (xd->lossless) { 822 if (xd->lossless) {
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
898 } 901 }
899 902
900 vpx_memcpy(tempa, ta, sizeof(ta)); 903 vpx_memcpy(tempa, ta, sizeof(ta));
901 vpx_memcpy(templ, tl, sizeof(tl)); 904 vpx_memcpy(templ, tl, sizeof(tl));
902 905
903 for (idy = 0; idy < num_4x4_blocks_high; ++idy) { 906 for (idy = 0; idy < num_4x4_blocks_high; ++idy) {
904 for (idx = 0; idx < num_4x4_blocks_wide; ++idx) { 907 for (idx = 0; idx < num_4x4_blocks_wide; ++idx) {
905 const int block = ib + idy * 2 + idx; 908 const int block = ib + idy * 2 + idx;
906 const uint8_t *const src = &src_init[idx * 4 + idy * 4 * src_stride]; 909 const uint8_t *const src = &src_init[idx * 4 + idy * 4 * src_stride];
907 uint8_t *const dst = &dst_init[idx * 4 + idy * 4 * dst_stride]; 910 uint8_t *const dst = &dst_init[idx * 4 + idy * 4 * dst_stride];
908 int16_t *const src_diff = raster_block_offset_int16(BLOCK_8X8, block, 911 int16_t *const src_diff =
909 p->src_diff); 912 vp9_raster_block_offset_int16(BLOCK_8X8, block, p->src_diff);
910 tran_low_t *const coeff = BLOCK_OFFSET(x->plane[0].coeff, block); 913 tran_low_t *const coeff = BLOCK_OFFSET(x->plane[0].coeff, block);
911 xd->mi[0].src_mi->bmi[block].as_mode = mode; 914 xd->mi[0].src_mi->bmi[block].as_mode = mode;
912 vp9_predict_intra_block(xd, block, 1, 915 vp9_predict_intra_block(xd, block, 1,
913 TX_4X4, mode, 916 TX_4X4, mode,
914 x->skip_encode ? src : dst, 917 x->skip_encode ? src : dst,
915 x->skip_encode ? src_stride : dst_stride, 918 x->skip_encode ? src_stride : dst_stride,
916 dst, dst_stride, idx, idy, 0); 919 dst, dst_stride, idx, idy, 0);
917 vp9_subtract_block(4, 4, src_diff, 8, src, src_stride, dst, dst_stride); 920 vp9_subtract_block(4, 4, src_diff, 8, src, src_stride, dst, dst_stride);
918 921
919 if (xd->lossless) { 922 if (xd->lossless) {
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
975 return best_rd; 978 return best_rd;
976 } 979 }
977 980
978 static int64_t rd_pick_intra_sub_8x8_y_mode(VP9_COMP *cpi, MACROBLOCK *mb, 981 static int64_t rd_pick_intra_sub_8x8_y_mode(VP9_COMP *cpi, MACROBLOCK *mb,
979 int *rate, int *rate_y, 982 int *rate, int *rate_y,
980 int64_t *distortion, 983 int64_t *distortion,
981 int64_t best_rd) { 984 int64_t best_rd) {
982 int i, j; 985 int i, j;
983 const MACROBLOCKD *const xd = &mb->e_mbd; 986 const MACROBLOCKD *const xd = &mb->e_mbd;
984 MODE_INFO *const mic = xd->mi[0].src_mi; 987 MODE_INFO *const mic = xd->mi[0].src_mi;
985 const MODE_INFO *above_mi = xd->mi[-xd->mi_stride].src_mi; 988 const MODE_INFO *above_mi = xd->above_mi;
986 const MODE_INFO *left_mi = xd->left_available ? xd->mi[-1].src_mi : NULL; 989 const MODE_INFO *left_mi = xd->left_mi;
987 const BLOCK_SIZE bsize = xd->mi[0].src_mi->mbmi.sb_type; 990 const BLOCK_SIZE bsize = xd->mi[0].src_mi->mbmi.sb_type;
988 const int num_4x4_blocks_wide = num_4x4_blocks_wide_lookup[bsize]; 991 const int num_4x4_blocks_wide = num_4x4_blocks_wide_lookup[bsize];
989 const int num_4x4_blocks_high = num_4x4_blocks_high_lookup[bsize]; 992 const int num_4x4_blocks_high = num_4x4_blocks_high_lookup[bsize];
990 int idx, idy; 993 int idx, idy;
991 int cost = 0; 994 int cost = 0;
992 int64_t total_distortion = 0; 995 int64_t total_distortion = 0;
993 int tot_rate_y = 0; 996 int tot_rate_y = 0;
994 int64_t total_rd = 0; 997 int64_t total_rd = 0;
995 ENTROPY_CONTEXT t_above[4], t_left[4]; 998 ENTROPY_CONTEXT t_above[4], t_left[4];
996 const int *bmode_costs = cpi->mbmode_cost; 999 const int *bmode_costs = cpi->mbmode_cost;
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
1051 int64_t best_rd) { 1054 int64_t best_rd) {
1052 PREDICTION_MODE mode; 1055 PREDICTION_MODE mode;
1053 PREDICTION_MODE mode_selected = DC_PRED; 1056 PREDICTION_MODE mode_selected = DC_PRED;
1054 MACROBLOCKD *const xd = &x->e_mbd; 1057 MACROBLOCKD *const xd = &x->e_mbd;
1055 MODE_INFO *const mic = xd->mi[0].src_mi; 1058 MODE_INFO *const mic = xd->mi[0].src_mi;
1056 int this_rate, this_rate_tokenonly, s; 1059 int this_rate, this_rate_tokenonly, s;
1057 int64_t this_distortion, this_rd; 1060 int64_t this_distortion, this_rd;
1058 TX_SIZE best_tx = TX_4X4; 1061 TX_SIZE best_tx = TX_4X4;
1059 int i; 1062 int i;
1060 int *bmode_costs; 1063 int *bmode_costs;
1061 const MODE_INFO *above_mi = xd->mi[-xd->mi_stride].src_mi; 1064 const MODE_INFO *above_mi = xd->above_mi;
1062 const MODE_INFO *left_mi = xd->left_available ? xd->mi[-1].src_mi : NULL; 1065 const MODE_INFO *left_mi = xd->left_mi;
1063 const PREDICTION_MODE A = vp9_above_block_mode(mic, above_mi, 0); 1066 const PREDICTION_MODE A = vp9_above_block_mode(mic, above_mi, 0);
1064 const PREDICTION_MODE L = vp9_left_block_mode(mic, left_mi, 0); 1067 const PREDICTION_MODE L = vp9_left_block_mode(mic, left_mi, 0);
1065 bmode_costs = cpi->y_mode_costs[A][L]; 1068 bmode_costs = cpi->y_mode_costs[A][L];
1066 1069
1067 if (cpi->sf.tx_size_search_method == USE_FULL_RD) 1070 if (cpi->sf.tx_size_search_method == USE_FULL_RD)
1068 for (i = 0; i < TX_MODES; i++) 1071 for (i = 0; i < TX_MODES; i++)
1069 tx_cache[i] = INT64_MAX; 1072 tx_cache[i] = INT64_MAX;
1070 1073
1071 vpx_memset(x->skip_txfm, 0, sizeof(x->skip_txfm)); 1074 vpx_memset(x->skip_txfm, 0, sizeof(x->skip_txfm));
1072 /* Y Search for intra prediction mode */ 1075 /* Y Search for intra prediction mode */
1073 for (mode = DC_PRED; mode <= TM_PRED; mode++) { 1076 for (mode = DC_PRED; mode <= TM_PRED; mode++) {
1074 int64_t local_tx_cache[TX_MODES]; 1077 int64_t local_tx_cache[TX_MODES];
1078
1079 if (cpi->sf.use_nonrd_pick_mode) {
1080 // These speed features are turned on in hybrid non-RD and RD mode
1081 // for key frame coding in the context of real-time setting.
1082 if (conditional_skipintra(mode, mode_selected))
1083 continue;
1084 if (*skippable)
1085 break;
1086 }
1087
1075 mic->mbmi.mode = mode; 1088 mic->mbmi.mode = mode;
1076 1089
1077 super_block_yrd(cpi, x, &this_rate_tokenonly, &this_distortion, 1090 super_block_yrd(cpi, x, &this_rate_tokenonly, &this_distortion,
1078 &s, NULL, bsize, local_tx_cache, best_rd); 1091 &s, NULL, bsize, local_tx_cache, best_rd);
1079 1092
1080 if (this_rate_tokenonly == INT_MAX) 1093 if (this_rate_tokenonly == INT_MAX)
1081 continue; 1094 continue;
1082 1095
1083 this_rate = this_rate_tokenonly + bmode_costs[mode]; 1096 this_rate = this_rate_tokenonly + bmode_costs[mode];
1084 this_rd = RDCOST(x->rdmult, x->rddiv, this_rate, this_distortion); 1097 this_rd = RDCOST(x->rdmult, x->rddiv, this_rate, this_distortion);
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
1321 int k; 1334 int k;
1322 MACROBLOCKD *xd = &x->e_mbd; 1335 MACROBLOCKD *xd = &x->e_mbd;
1323 struct macroblockd_plane *const pd = &xd->plane[0]; 1336 struct macroblockd_plane *const pd = &xd->plane[0];
1324 struct macroblock_plane *const p = &x->plane[0]; 1337 struct macroblock_plane *const p = &x->plane[0];
1325 MODE_INFO *const mi = xd->mi[0].src_mi; 1338 MODE_INFO *const mi = xd->mi[0].src_mi;
1326 const BLOCK_SIZE plane_bsize = get_plane_block_size(mi->mbmi.sb_type, pd); 1339 const BLOCK_SIZE plane_bsize = get_plane_block_size(mi->mbmi.sb_type, pd);
1327 const int width = 4 * num_4x4_blocks_wide_lookup[plane_bsize]; 1340 const int width = 4 * num_4x4_blocks_wide_lookup[plane_bsize];
1328 const int height = 4 * num_4x4_blocks_high_lookup[plane_bsize]; 1341 const int height = 4 * num_4x4_blocks_high_lookup[plane_bsize];
1329 int idx, idy; 1342 int idx, idy;
1330 1343
1331 const uint8_t *const src = &p->src.buf[raster_block_offset(BLOCK_8X8, i, 1344 const uint8_t *const src =
1332 p->src.stride)]; 1345 &p->src.buf[vp9_raster_block_offset(BLOCK_8X8, i, p->src.stride)];
1333 uint8_t *const dst = &pd->dst.buf[raster_block_offset(BLOCK_8X8, i, 1346 uint8_t *const dst = &pd->dst.buf[vp9_raster_block_offset(BLOCK_8X8, i,
1334 pd->dst.stride)]; 1347 pd->dst.stride)];
1335 int64_t thisdistortion = 0, thissse = 0; 1348 int64_t thisdistortion = 0, thissse = 0;
1336 int thisrate = 0, ref; 1349 int thisrate = 0, ref;
1337 const scan_order *so = &vp9_default_scan_orders[TX_4X4]; 1350 const scan_order *so = &vp9_default_scan_orders[TX_4X4];
1338 const int is_compound = has_second_ref(&mi->mbmi); 1351 const int is_compound = has_second_ref(&mi->mbmi);
1339 const InterpKernel *kernel = vp9_get_interp_kernel(mi->mbmi.interp_filter); 1352 const InterpKernel *kernel = vp9_get_interp_kernel(mi->mbmi.interp_filter);
1340 1353
1341 for (ref = 0; ref < 1 + is_compound; ++ref) { 1354 for (ref = 0; ref < 1 + is_compound; ++ref) {
1342 const uint8_t *pre = &pd->pre[ref].buf[raster_block_offset(BLOCK_8X8, i, 1355 const uint8_t *pre = &pd->pre[ref].buf[vp9_raster_block_offset(BLOCK_8X8, i,
1343 pd->pre[ref].stride)]; 1356 pd->pre[ref].stride)];
1344 #if CONFIG_VP9_HIGHBITDEPTH 1357 #if CONFIG_VP9_HIGHBITDEPTH
1345 if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) { 1358 if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
1346 vp9_highbd_build_inter_predictor(pre, pd->pre[ref].stride, 1359 vp9_highbd_build_inter_predictor(pre, pd->pre[ref].stride,
1347 dst, pd->dst.stride, 1360 dst, pd->dst.stride,
1348 &mi->bmi[i].as_mv[ref].as_mv, 1361 &mi->bmi[i].as_mv[ref].as_mv,
1349 &xd->block_refs[ref]->sf, width, height, 1362 &xd->block_refs[ref]->sf, width, height,
1350 ref, kernel, MV_PRECISION_Q3, 1363 ref, kernel, MV_PRECISION_Q3,
1351 mi_col * MI_SIZE + 4 * (i % 2), 1364 mi_col * MI_SIZE + 4 * (i % 2),
1352 mi_row * MI_SIZE + 4 * (i / 2), xd->bd); 1365 mi_row * MI_SIZE + 4 * (i / 2), xd->bd);
(...skipping 13 matching lines...) Expand all
1366 &xd->block_refs[ref]->sf, width, height, ref, 1379 &xd->block_refs[ref]->sf, width, height, ref,
1367 kernel, MV_PRECISION_Q3, 1380 kernel, MV_PRECISION_Q3,
1368 mi_col * MI_SIZE + 4 * (i % 2), 1381 mi_col * MI_SIZE + 4 * (i % 2),
1369 mi_row * MI_SIZE + 4 * (i / 2)); 1382 mi_row * MI_SIZE + 4 * (i / 2));
1370 #endif // CONFIG_VP9_HIGHBITDEPTH 1383 #endif // CONFIG_VP9_HIGHBITDEPTH
1371 } 1384 }
1372 1385
1373 #if CONFIG_VP9_HIGHBITDEPTH 1386 #if CONFIG_VP9_HIGHBITDEPTH
1374 if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) { 1387 if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
1375 vp9_highbd_subtract_block( 1388 vp9_highbd_subtract_block(
1376 height, width, raster_block_offset_int16(BLOCK_8X8, i, p->src_diff), 8, 1389 height, width, vp9_raster_block_offset_int16(BLOCK_8X8, i, p->src_diff),
1377 src, p->src.stride, dst, pd->dst.stride, xd->bd); 1390 8, src, p->src.stride, dst, pd->dst.stride, xd->bd);
1378 } else { 1391 } else {
1379 vp9_subtract_block( 1392 vp9_subtract_block(
1380 height, width, raster_block_offset_int16(BLOCK_8X8, i, p->src_diff), 8, 1393 height, width, vp9_raster_block_offset_int16(BLOCK_8X8, i, p->src_diff),
1381 src, p->src.stride, dst, pd->dst.stride); 1394 8, src, p->src.stride, dst, pd->dst.stride);
1382 } 1395 }
1383 #else 1396 #else
1384 vp9_subtract_block(height, width, 1397 vp9_subtract_block(height, width,
1385 raster_block_offset_int16(BLOCK_8X8, i, p->src_diff), 8, 1398 vp9_raster_block_offset_int16(BLOCK_8X8, i, p->src_diff),
1386 src, p->src.stride, dst, pd->dst.stride); 1399 8, src, p->src.stride, dst, pd->dst.stride);
1387 #endif // CONFIG_VP9_HIGHBITDEPTH 1400 #endif // CONFIG_VP9_HIGHBITDEPTH
1388 1401
1389 k = i; 1402 k = i;
1390 for (idy = 0; idy < height / 4; ++idy) { 1403 for (idy = 0; idy < height / 4; ++idy) {
1391 for (idx = 0; idx < width / 4; ++idx) { 1404 for (idx = 0; idx < width / 4; ++idx) {
1392 int64_t ssz, rd, rd1, rd2; 1405 int64_t ssz, rd, rd1, rd2;
1393 tran_low_t* coeff; 1406 tran_low_t* coeff;
1394 1407
1395 k += (idy * 2 + idx); 1408 k += (idy * 2 + idx);
1396 coeff = BLOCK_OFFSET(p->coeff, k); 1409 coeff = BLOCK_OFFSET(p->coeff, k);
1397 x->fwd_txm4x4(raster_block_offset_int16(BLOCK_8X8, k, p->src_diff), 1410 x->fwd_txm4x4(vp9_raster_block_offset_int16(BLOCK_8X8, k, p->src_diff),
1398 coeff, 8); 1411 coeff, 8);
1399 vp9_regular_quantize_b_4x4(x, 0, k, so->scan, so->iscan); 1412 vp9_regular_quantize_b_4x4(x, 0, k, so->scan, so->iscan);
1400 #if CONFIG_VP9_HIGHBITDEPTH 1413 #if CONFIG_VP9_HIGHBITDEPTH
1401 if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) { 1414 if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
1402 thisdistortion += vp9_highbd_block_error(coeff, 1415 thisdistortion += vp9_highbd_block_error(coeff,
1403 BLOCK_OFFSET(pd->dqcoeff, k), 1416 BLOCK_OFFSET(pd->dqcoeff, k),
1404 16, &ssz, xd->bd); 1417 16, &ssz, xd->bd);
1405 } else { 1418 } else {
1406 thisdistortion += vp9_block_error(coeff, BLOCK_OFFSET(pd->dqcoeff, k), 1419 thisdistortion += vp9_block_error(coeff, BLOCK_OFFSET(pd->dqcoeff, k),
1407 16, &ssz); 1420 16, &ssz);
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
1460 (mv->row >> 3) > x->mv_row_max || 1473 (mv->row >> 3) > x->mv_row_max ||
1461 (mv->col >> 3) < x->mv_col_min || 1474 (mv->col >> 3) < x->mv_col_min ||
1462 (mv->col >> 3) > x->mv_col_max; 1475 (mv->col >> 3) > x->mv_col_max;
1463 } 1476 }
1464 1477
1465 static INLINE void mi_buf_shift(MACROBLOCK *x, int i) { 1478 static INLINE void mi_buf_shift(MACROBLOCK *x, int i) {
1466 MB_MODE_INFO *const mbmi = &x->e_mbd.mi[0].src_mi->mbmi; 1479 MB_MODE_INFO *const mbmi = &x->e_mbd.mi[0].src_mi->mbmi;
1467 struct macroblock_plane *const p = &x->plane[0]; 1480 struct macroblock_plane *const p = &x->plane[0];
1468 struct macroblockd_plane *const pd = &x->e_mbd.plane[0]; 1481 struct macroblockd_plane *const pd = &x->e_mbd.plane[0];
1469 1482
1470 p->src.buf = &p->src.buf[raster_block_offset(BLOCK_8X8, i, p->src.stride)]; 1483 p->src.buf = &p->src.buf[vp9_raster_block_offset(BLOCK_8X8, i,
1484 p->src.stride)];
1471 assert(((intptr_t)pd->pre[0].buf & 0x7) == 0); 1485 assert(((intptr_t)pd->pre[0].buf & 0x7) == 0);
1472 pd->pre[0].buf = &pd->pre[0].buf[raster_block_offset(BLOCK_8X8, i, 1486 pd->pre[0].buf = &pd->pre[0].buf[vp9_raster_block_offset(BLOCK_8X8, i,
1473 pd->pre[0].stride)]; 1487 pd->pre[0].stride)];
1474 if (has_second_ref(mbmi)) 1488 if (has_second_ref(mbmi))
1475 pd->pre[1].buf = &pd->pre[1].buf[raster_block_offset(BLOCK_8X8, i, 1489 pd->pre[1].buf = &pd->pre[1].buf[vp9_raster_block_offset(BLOCK_8X8, i,
1476 pd->pre[1].stride)]; 1490 pd->pre[1].stride)];
1477 } 1491 }
1478 1492
1479 static INLINE void mi_buf_restore(MACROBLOCK *x, struct buf_2d orig_src, 1493 static INLINE void mi_buf_restore(MACROBLOCK *x, struct buf_2d orig_src,
1480 struct buf_2d orig_pre[2]) { 1494 struct buf_2d orig_pre[2]) {
1481 MB_MODE_INFO *mbmi = &x->e_mbd.mi[0].src_mi->mbmi; 1495 MB_MODE_INFO *mbmi = &x->e_mbd.mi[0].src_mi->mbmi;
1482 x->plane[0].src = orig_src; 1496 x->plane[0].src = orig_src;
1483 x->e_mbd.plane[0].pre[0] = orig_pre[0]; 1497 x->e_mbd.plane[0].pre[0] = orig_pre[0];
1484 if (has_second_ref(mbmi)) 1498 if (has_second_ref(mbmi))
1485 x->e_mbd.plane[0].pre[1] = orig_pre[1]; 1499 x->e_mbd.plane[0].pre[1] = orig_pre[1];
1486 } 1500 }
(...skipping 851 matching lines...) Expand 10 before | Expand all | Expand 10 after
2338 static INLINE void restore_dst_buf(MACROBLOCKD *xd, 2352 static INLINE void restore_dst_buf(MACROBLOCKD *xd,
2339 uint8_t *orig_dst[MAX_MB_PLANE], 2353 uint8_t *orig_dst[MAX_MB_PLANE],
2340 int orig_dst_stride[MAX_MB_PLANE]) { 2354 int orig_dst_stride[MAX_MB_PLANE]) {
2341 int i; 2355 int i;
2342 for (i = 0; i < MAX_MB_PLANE; i++) { 2356 for (i = 0; i < MAX_MB_PLANE; i++) {
2343 xd->plane[i].dst.buf = orig_dst[i]; 2357 xd->plane[i].dst.buf = orig_dst[i];
2344 xd->plane[i].dst.stride = orig_dst_stride[i]; 2358 xd->plane[i].dst.stride = orig_dst_stride[i];
2345 } 2359 }
2346 } 2360 }
2347 2361
2362 // In some situations we want to discount tha pparent cost of a new motion
2363 // vector. Where there is a subtle motion field and especially where there is
2364 // low spatial complexity then it can be hard to cover the cost of a new motion
2365 // vector in a single block, even if that motion vector reduces distortion.
2366 // However, once established that vector may be usable through the nearest and
2367 // near mv modes to reduce distortion in subsequent blocks and also improve
2368 // visual quality.
2369 static int discount_newmv_test(const VP9_COMP *cpi,
2370 int this_mode,
2371 int_mv this_mv,
2372 int_mv (*mode_mv)[MAX_REF_FRAMES],
2373 int ref_frame) {
2374 return (!cpi->rc.is_src_frame_alt_ref &&
2375 (this_mode == NEWMV) &&
2376 (this_mv.as_int != 0) &&
2377 ((mode_mv[NEARESTMV][ref_frame].as_int == 0) ||
2378 (mode_mv[NEARESTMV][ref_frame].as_int == INVALID_MV)) &&
2379 ((mode_mv[NEARMV][ref_frame].as_int == 0) ||
2380 (mode_mv[NEARMV][ref_frame].as_int == INVALID_MV)));
2381 }
2382
2348 static int64_t handle_inter_mode(VP9_COMP *cpi, MACROBLOCK *x, 2383 static int64_t handle_inter_mode(VP9_COMP *cpi, MACROBLOCK *x,
2349 BLOCK_SIZE bsize, 2384 BLOCK_SIZE bsize,
2350 int64_t txfm_cache[], 2385 int64_t txfm_cache[],
2351 int *rate2, int64_t *distortion, 2386 int *rate2, int64_t *distortion,
2352 int *skippable, 2387 int *skippable,
2353 int *rate_y, int *rate_uv, 2388 int *rate_y, int *rate_uv,
2354 int *disable_skip, 2389 int *disable_skip,
2355 int_mv (*mode_mv)[MAX_REF_FRAMES], 2390 int_mv (*mode_mv)[MAX_REF_FRAMES],
2356 int mi_row, int mi_col, 2391 int mi_row, int mi_col,
2357 int_mv single_newmv[MAX_REF_FRAMES], 2392 int_mv single_newmv[MAX_REF_FRAMES],
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
2447 &mbmi->ref_mvs[refs[1]][0].as_mv, 2482 &mbmi->ref_mvs[refs[1]][0].as_mv,
2448 x->nmvjointcost, x->mvcost, MV_COST_WEIGHT); 2483 x->nmvjointcost, x->mvcost, MV_COST_WEIGHT);
2449 } 2484 }
2450 *rate2 += rate_mv; 2485 *rate2 += rate_mv;
2451 } else { 2486 } else {
2452 int_mv tmp_mv; 2487 int_mv tmp_mv;
2453 single_motion_search(cpi, x, bsize, mi_row, mi_col, 2488 single_motion_search(cpi, x, bsize, mi_row, mi_col,
2454 &tmp_mv, &rate_mv); 2489 &tmp_mv, &rate_mv);
2455 if (tmp_mv.as_int == INVALID_MV) 2490 if (tmp_mv.as_int == INVALID_MV)
2456 return INT64_MAX; 2491 return INT64_MAX;
2457 *rate2 += rate_mv; 2492
2458 frame_mv[refs[0]].as_int = 2493 frame_mv[refs[0]].as_int =
2459 xd->mi[0].src_mi->bmi[0].as_mv[0].as_int = tmp_mv.as_int; 2494 xd->mi[0].src_mi->bmi[0].as_mv[0].as_int = tmp_mv.as_int;
2460 single_newmv[refs[0]].as_int = tmp_mv.as_int; 2495 single_newmv[refs[0]].as_int = tmp_mv.as_int;
2496
2497 // Estimate the rate implications of a new mv but discount this
2498 // under certain circumstances where we want to help initiate a weak
2499 // motion field, where the distortion gain for a single block may not
2500 // be enough to overcome the cost of a new mv.
2501 if (discount_newmv_test(cpi, this_mode, tmp_mv, mode_mv, refs[0])) {
2502 *rate2 += MAX((rate_mv / NEW_MV_DISCOUNT_FACTOR), 1);
2503 } else {
2504 *rate2 += rate_mv;
2505 }
2461 } 2506 }
2462 } 2507 }
2463 2508
2464 for (i = 0; i < is_comp_pred + 1; ++i) { 2509 for (i = 0; i < is_comp_pred + 1; ++i) {
2465 cur_mv[i] = frame_mv[refs[i]]; 2510 cur_mv[i] = frame_mv[refs[i]];
2466 // Clip "next_nearest" so that it does not extend to far out of image 2511 // Clip "next_nearest" so that it does not extend to far out of image
2467 if (this_mode != NEWMV) 2512 if (this_mode != NEWMV)
2468 clamp_mv2(&cur_mv[i].as_mv, xd); 2513 clamp_mv2(&cur_mv[i].as_mv, xd);
2469 2514
2470 if (mv_check_bounds(x, &cur_mv[i].as_mv)) 2515 if (mv_check_bounds(x, &cur_mv[i].as_mv))
2471 return INT64_MAX; 2516 return INT64_MAX;
2472 mbmi->mv[i].as_int = cur_mv[i].as_int; 2517 mbmi->mv[i].as_int = cur_mv[i].as_int;
2473 } 2518 }
2474 2519
2475 // do first prediction into the destination buffer. Do the next 2520 // do first prediction into the destination buffer. Do the next
2476 // prediction into a temporary buffer. Then keep track of which one 2521 // prediction into a temporary buffer. Then keep track of which one
2477 // of these currently holds the best predictor, and use the other 2522 // of these currently holds the best predictor, and use the other
2478 // one for future predictions. In the end, copy from tmp_buf to 2523 // one for future predictions. In the end, copy from tmp_buf to
2479 // dst if necessary. 2524 // dst if necessary.
2480 for (i = 0; i < MAX_MB_PLANE; i++) { 2525 for (i = 0; i < MAX_MB_PLANE; i++) {
2481 orig_dst[i] = xd->plane[i].dst.buf; 2526 orig_dst[i] = xd->plane[i].dst.buf;
2482 orig_dst_stride[i] = xd->plane[i].dst.stride; 2527 orig_dst_stride[i] = xd->plane[i].dst.stride;
2483 } 2528 }
2484 2529
2485 /* We don't include the cost of the second reference here, because there 2530 // We don't include the cost of the second reference here, because there
2486 * are only three options: Last/Golden, ARF/Last or Golden/ARF, or in other 2531 // are only three options: Last/Golden, ARF/Last or Golden/ARF, or in other
2487 * words if you present them in that order, the second one is always known 2532 // words if you present them in that order, the second one is always known
2488 * if the first is known */ 2533 // if the first is known.
2489 *rate2 += cost_mv_ref(cpi, this_mode, mbmi->mode_context[refs[0]]); 2534 //
2535 // Under some circumstances we discount the cost of new mv mode to encourage
2536 // initiation of a motion field.
2537 if (discount_newmv_test(cpi, this_mode, frame_mv[refs[0]],
2538 mode_mv, refs[0])) {
2539 *rate2 += MIN(cost_mv_ref(cpi, this_mode, mbmi->mode_context[refs[0]]),
2540 cost_mv_ref(cpi, NEARESTMV, mbmi->mode_context[refs[0]]));
2541 } else {
2542 *rate2 += cost_mv_ref(cpi, this_mode, mbmi->mode_context[refs[0]]);
2543 }
2490 2544
2491 if (RDCOST(x->rdmult, x->rddiv, *rate2, 0) > ref_best_rd && 2545 if (RDCOST(x->rdmult, x->rddiv, *rate2, 0) > ref_best_rd &&
2492 mbmi->mode != NEARESTMV) 2546 mbmi->mode != NEARESTMV)
2493 return INT64_MAX; 2547 return INT64_MAX;
2494 2548
2495 pred_exists = 0; 2549 pred_exists = 0;
2496 // Are all MVs integer pel for Y and UV 2550 // Are all MVs integer pel for Y and UV
2497 intpel_mv = !mv_has_subpel(&mbmi->mv[0].as_mv); 2551 intpel_mv = !mv_has_subpel(&mbmi->mv[0].as_mv);
2498 if (is_comp_pred) 2552 if (is_comp_pred)
2499 intpel_mv &= !mv_has_subpel(&mbmi->mv[1].as_mv); 2553 intpel_mv &= !mv_has_subpel(&mbmi->mv[1].as_mv);
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
2709 VP9_COMMON *const cm = &cpi->common; 2763 VP9_COMMON *const cm = &cpi->common;
2710 MACROBLOCKD *const xd = &x->e_mbd; 2764 MACROBLOCKD *const xd = &x->e_mbd;
2711 struct macroblockd_plane *const pd = xd->plane; 2765 struct macroblockd_plane *const pd = xd->plane;
2712 int rate_y = 0, rate_uv = 0, rate_y_tokenonly = 0, rate_uv_tokenonly = 0; 2766 int rate_y = 0, rate_uv = 0, rate_y_tokenonly = 0, rate_uv_tokenonly = 0;
2713 int y_skip = 0, uv_skip = 0; 2767 int y_skip = 0, uv_skip = 0;
2714 int64_t dist_y = 0, dist_uv = 0, tx_cache[TX_MODES] = { 0 }; 2768 int64_t dist_y = 0, dist_uv = 0, tx_cache[TX_MODES] = { 0 };
2715 TX_SIZE max_uv_tx_size; 2769 TX_SIZE max_uv_tx_size;
2716 x->skip_encode = 0; 2770 x->skip_encode = 0;
2717 ctx->skip = 0; 2771 ctx->skip = 0;
2718 xd->mi[0].src_mi->mbmi.ref_frame[0] = INTRA_FRAME; 2772 xd->mi[0].src_mi->mbmi.ref_frame[0] = INTRA_FRAME;
2773 xd->mi[0].src_mi->mbmi.ref_frame[1] = NONE;
2719 2774
2720 if (bsize >= BLOCK_8X8) { 2775 if (bsize >= BLOCK_8X8) {
2721 if (rd_pick_intra_sby_mode(cpi, x, &rate_y, &rate_y_tokenonly, 2776 if (rd_pick_intra_sby_mode(cpi, x, &rate_y, &rate_y_tokenonly,
2722 &dist_y, &y_skip, bsize, tx_cache, 2777 &dist_y, &y_skip, bsize, tx_cache,
2723 best_rd) >= best_rd) { 2778 best_rd) >= best_rd) {
2724 rd_cost->rate = INT_MAX; 2779 rd_cost->rate = INT_MAX;
2725 return; 2780 return;
2726 } 2781 }
2727 } else { 2782 } else {
2728 y_skip = 0; 2783 y_skip = 0;
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
2924 } 2979 }
2925 2980
2926 if (bsize > sf->max_intra_bsize) { 2981 if (bsize > sf->max_intra_bsize) {
2927 ref_frame_skip_mask[0] |= (1 << INTRA_FRAME); 2982 ref_frame_skip_mask[0] |= (1 << INTRA_FRAME);
2928 ref_frame_skip_mask[1] |= (1 << INTRA_FRAME); 2983 ref_frame_skip_mask[1] |= (1 << INTRA_FRAME);
2929 } 2984 }
2930 2985
2931 mode_skip_mask[INTRA_FRAME] |= 2986 mode_skip_mask[INTRA_FRAME] |=
2932 ~(sf->intra_y_mode_mask[max_txsize_lookup[bsize]]); 2987 ~(sf->intra_y_mode_mask[max_txsize_lookup[bsize]]);
2933 2988
2934 for (i = 0; i < MAX_MODES; ++i) 2989 for (i = 0; i <= LAST_NEW_MV_INDEX; ++i)
2990 mode_threshold[i] = 0;
2991 for (i = LAST_NEW_MV_INDEX + 1; i < MAX_MODES; ++i)
2935 mode_threshold[i] = ((int64_t)rd_threshes[i] * rd_thresh_freq_fact[i]) >> 5; 2992 mode_threshold[i] = ((int64_t)rd_threshes[i] * rd_thresh_freq_fact[i]) >> 5;
2936 2993
2937 midx = sf->schedule_mode_search ? mode_skip_start : 0; 2994 midx = sf->schedule_mode_search ? mode_skip_start : 0;
2938 while (midx > 4) { 2995 while (midx > 4) {
2939 uint8_t end_pos = 0; 2996 uint8_t end_pos = 0;
2940 for (i = 5; i < midx; ++i) { 2997 for (i = 5; i < midx; ++i) {
2941 if (mode_threshold[mode_map[i - 1]] > mode_threshold[mode_map[i]]) { 2998 if (mode_threshold[mode_map[i - 1]] > mode_threshold[mode_map[i]]) {
2942 uint8_t tmp = mode_map[i]; 2999 uint8_t tmp = mode_map[i];
2943 mode_map[i] = mode_map[i - 1]; 3000 mode_map[i] = mode_map[i - 1];
2944 mode_map[i - 1] = tmp; 3001 mode_map[i - 1] = tmp;
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
3048 if (ref_frame != rf) 3105 if (ref_frame != rf)
3049 continue; 3106 continue;
3050 3107
3051 if (const_motion) 3108 if (const_motion)
3052 if (this_mode == NEARMV || this_mode == ZEROMV) 3109 if (this_mode == NEARMV || this_mode == ZEROMV)
3053 continue; 3110 continue;
3054 } 3111 }
3055 3112
3056 comp_pred = second_ref_frame > INTRA_FRAME; 3113 comp_pred = second_ref_frame > INTRA_FRAME;
3057 if (comp_pred) { 3114 if (comp_pred) {
3058 if (!cm->allow_comp_inter_inter) 3115 if (!cpi->allow_comp_inter_inter)
3059 continue; 3116 continue;
3060 3117
3061 // Skip compound inter modes if ARF is not available. 3118 // Skip compound inter modes if ARF is not available.
3062 if (!(cpi->ref_frame_flags & flag_list[second_ref_frame])) 3119 if (!(cpi->ref_frame_flags & flag_list[second_ref_frame]))
3063 continue; 3120 continue;
3064 3121
3065 // Do not allow compound prediction if the segment level reference frame 3122 // Do not allow compound prediction if the segment level reference frame
3066 // feature is in use as in this case there can only be one reference. 3123 // feature is in use as in this case there can only be one reference.
3067 if (vp9_segfeature_active(seg, segment_id, SEG_LVL_REF_FRAME)) 3124 if (vp9_segfeature_active(seg, segment_id, SEG_LVL_REF_FRAME))
3068 continue; 3125 continue;
(...skipping 629 matching lines...) Expand 10 before | Expand all | Expand 10 after
3698 continue; 3755 continue;
3699 3756
3700 // Test best rd so far against threshold for trying this mode. 3757 // Test best rd so far against threshold for trying this mode.
3701 if (rd_less_than_thresh(best_rd, 3758 if (rd_less_than_thresh(best_rd,
3702 rd_opt->threshes[segment_id][bsize][ref_index], 3759 rd_opt->threshes[segment_id][bsize][ref_index],
3703 tile_data->thresh_freq_fact[bsize][ref_index])) 3760 tile_data->thresh_freq_fact[bsize][ref_index]))
3704 continue; 3761 continue;
3705 3762
3706 comp_pred = second_ref_frame > INTRA_FRAME; 3763 comp_pred = second_ref_frame > INTRA_FRAME;
3707 if (comp_pred) { 3764 if (comp_pred) {
3708 if (!cm->allow_comp_inter_inter) 3765 if (!cpi->allow_comp_inter_inter)
3709 continue; 3766 continue;
3710 if (!(cpi->ref_frame_flags & flag_list[second_ref_frame])) 3767 if (!(cpi->ref_frame_flags & flag_list[second_ref_frame]))
3711 continue; 3768 continue;
3712 // Do not allow compound prediction if the segment level reference frame 3769 // Do not allow compound prediction if the segment level reference frame
3713 // feature is in use as in this case there can only be one reference. 3770 // feature is in use as in this case there can only be one reference.
3714 if (vp9_segfeature_active(seg, segment_id, SEG_LVL_REF_FRAME)) 3771 if (vp9_segfeature_active(seg, segment_id, SEG_LVL_REF_FRAME))
3715 continue; 3772 continue;
3716 3773
3717 if ((sf->mode_search_skip_flags & FLAG_SKIP_COMP_BESTINTRA) && 3774 if ((sf->mode_search_skip_flags & FLAG_SKIP_COMP_BESTINTRA) &&
3718 best_mbmode.ref_frame[0] == INTRA_FRAME) 3775 best_mbmode.ref_frame[0] == INTRA_FRAME)
(...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after
4168 if (cm->interp_filter == SWITCHABLE) 4225 if (cm->interp_filter == SWITCHABLE)
4169 assert(best_filter_diff[SWITCHABLE_FILTERS] == 0); 4226 assert(best_filter_diff[SWITCHABLE_FILTERS] == 0);
4170 } else { 4227 } else {
4171 vp9_zero(best_filter_diff); 4228 vp9_zero(best_filter_diff);
4172 } 4229 }
4173 4230
4174 store_coding_context(x, ctx, best_ref_index, 4231 store_coding_context(x, ctx, best_ref_index,
4175 best_pred_diff, best_tx_diff, best_filter_diff, 0); 4232 best_pred_diff, best_tx_diff, best_filter_diff, 0);
4176 } 4233 }
4177 4234
OLDNEW
« no previous file with comments | « source/libvpx/vp9/encoder/vp9_rd.c ('k') | source/libvpx/vp9/encoder/vp9_speed_features.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698