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

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

Issue 232133009: libvpx: Pull from upstream (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/deps/third_party/libvpx/
Patch Set: Created 6 years, 8 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 » ('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 12 matching lines...) Expand all
23 #include "vp9/common/vp9_idct.h" 23 #include "vp9/common/vp9_idct.h"
24 #include "vp9/common/vp9_mvref_common.h" 24 #include "vp9/common/vp9_mvref_common.h"
25 #include "vp9/common/vp9_pragmas.h" 25 #include "vp9/common/vp9_pragmas.h"
26 #include "vp9/common/vp9_pred_common.h" 26 #include "vp9/common/vp9_pred_common.h"
27 #include "vp9/common/vp9_quant_common.h" 27 #include "vp9/common/vp9_quant_common.h"
28 #include "vp9/common/vp9_reconinter.h" 28 #include "vp9/common/vp9_reconinter.h"
29 #include "vp9/common/vp9_reconintra.h" 29 #include "vp9/common/vp9_reconintra.h"
30 #include "vp9/common/vp9_seg_common.h" 30 #include "vp9/common/vp9_seg_common.h"
31 #include "vp9/common/vp9_systemdependent.h" 31 #include "vp9/common/vp9_systemdependent.h"
32 32
33 #include "vp9/encoder/vp9_cost.h"
33 #include "vp9/encoder/vp9_encodemb.h" 34 #include "vp9/encoder/vp9_encodemb.h"
34 #include "vp9/encoder/vp9_encodemv.h" 35 #include "vp9/encoder/vp9_encodemv.h"
35 #include "vp9/encoder/vp9_mcomp.h" 36 #include "vp9/encoder/vp9_mcomp.h"
36 #include "vp9/encoder/vp9_onyx_int.h" 37 #include "vp9/encoder/vp9_onyx_int.h"
37 #include "vp9/encoder/vp9_quantize.h" 38 #include "vp9/encoder/vp9_quantize.h"
38 #include "vp9/encoder/vp9_ratectrl.h" 39 #include "vp9/encoder/vp9_ratectrl.h"
39 #include "vp9/encoder/vp9_rdopt.h" 40 #include "vp9/encoder/vp9_rdopt.h"
40 #include "vp9/encoder/vp9_tokenize.h" 41 #include "vp9/encoder/vp9_tokenize.h"
41 #include "vp9/encoder/vp9_treewriter.h"
42 #include "vp9/encoder/vp9_variance.h" 42 #include "vp9/encoder/vp9_variance.h"
43 43
44 #define RD_THRESH_MAX_FACT 64
45 #define RD_THRESH_INC 1
46 #define RD_THRESH_POW 1.25
47 #define RD_MULT_EPB_RATIO 64
48
44 /* Factor to weigh the rate for switchable interp filters */ 49 /* Factor to weigh the rate for switchable interp filters */
45 #define SWITCHABLE_INTERP_RATE_FACTOR 1 50 #define SWITCHABLE_INTERP_RATE_FACTOR 1
46 51
47 #define LAST_FRAME_MODE_MASK 0xFFEDCD60 52 #define LAST_FRAME_MODE_MASK 0xFFEDCD60
48 #define GOLDEN_FRAME_MODE_MASK 0xFFDA3BB0 53 #define GOLDEN_FRAME_MODE_MASK 0xFFDA3BB0
49 #define ALT_REF_MODE_MASK 0xFFC648D0 54 #define ALT_REF_MODE_MASK 0xFFC648D0
50 55
51 #define MIN_EARLY_TERM_INDEX 3 56 #define MIN_EARLY_TERM_INDEX 3
52 57
53 typedef struct { 58 typedef struct {
(...skipping 11 matching lines...) Expand all
65 ENTROPY_CONTEXT t_left[16]; 70 ENTROPY_CONTEXT t_left[16];
66 int rate; 71 int rate;
67 int64_t dist; 72 int64_t dist;
68 int64_t sse; 73 int64_t sse;
69 int this_rate; 74 int this_rate;
70 int64_t this_dist; 75 int64_t this_dist;
71 int64_t this_sse; 76 int64_t this_sse;
72 int64_t this_rd; 77 int64_t this_rd;
73 int64_t best_rd; 78 int64_t best_rd;
74 int skip; 79 int skip;
80 int use_fast_coef_costing;
75 const scan_order *so; 81 const scan_order *so;
76 }; 82 };
77 83
78 const MODE_DEFINITION vp9_mode_order[MAX_MODES] = { 84 const MODE_DEFINITION vp9_mode_order[MAX_MODES] = {
79 {NEARESTMV, {LAST_FRAME, NONE}}, 85 {NEARESTMV, {LAST_FRAME, NONE}},
80 {NEARESTMV, {ALTREF_FRAME, NONE}}, 86 {NEARESTMV, {ALTREF_FRAME, NONE}},
81 {NEARESTMV, {GOLDEN_FRAME, NONE}}, 87 {NEARESTMV, {GOLDEN_FRAME, NONE}},
82 88
83 {DC_PRED, {INTRA_FRAME, NONE}}, 89 {DC_PRED, {INTRA_FRAME, NONE}},
84 90
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 const int x = 4 * (raster_block & ((1 << bw) - 1)); 144 const int x = 4 * (raster_block & ((1 << bw) - 1));
139 return y * stride + x; 145 return y * stride + x;
140 } 146 }
141 static int16_t* raster_block_offset_int16(BLOCK_SIZE plane_bsize, 147 static int16_t* raster_block_offset_int16(BLOCK_SIZE plane_bsize,
142 int raster_block, int16_t *base) { 148 int raster_block, int16_t *base) {
143 const int stride = 4 * num_4x4_blocks_wide_lookup[plane_bsize]; 149 const int stride = 4 * num_4x4_blocks_wide_lookup[plane_bsize];
144 return base + raster_block_offset(plane_bsize, raster_block, stride); 150 return base + raster_block_offset(plane_bsize, raster_block, stride);
145 } 151 }
146 152
147 static void fill_mode_costs(VP9_COMP *cpi) { 153 static void fill_mode_costs(VP9_COMP *cpi) {
148 VP9_COMMON *const cm = &cpi->common;
149 MACROBLOCK *const x = &cpi->mb; 154 MACROBLOCK *const x = &cpi->mb;
150 FRAME_CONTEXT *const fc = &cm->fc; 155 const FRAME_CONTEXT *const fc = &cpi->common.fc;
151 int i, j; 156 int i, j;
152 157
153 for (i = 0; i < INTRA_MODES; i++) 158 for (i = 0; i < INTRA_MODES; i++)
154 for (j = 0; j < INTRA_MODES; j++) 159 for (j = 0; j < INTRA_MODES; j++)
155 vp9_cost_tokens((int *)x->y_mode_costs[i][j], vp9_kf_y_mode_prob[i][j], 160 vp9_cost_tokens((int *)x->y_mode_costs[i][j], vp9_kf_y_mode_prob[i][j],
156 vp9_intra_mode_tree); 161 vp9_intra_mode_tree);
157 162
158 // TODO(rbultje) separate tables for superblock costing? 163 // TODO(rbultje) separate tables for superblock costing?
159 vp9_cost_tokens(x->mbmode_cost, fc->y_mode_prob[1], vp9_intra_mode_tree); 164 vp9_cost_tokens(x->mbmode_cost, fc->y_mode_prob[1], vp9_intra_mode_tree);
160 vp9_cost_tokens(x->intra_uv_mode_cost[1], 165 vp9_cost_tokens(x->intra_uv_mode_cost[KEY_FRAME],
161 fc->uv_mode_prob[INTRA_MODES - 1], vp9_intra_mode_tree); 166 vp9_kf_uv_mode_prob[TM_PRED], vp9_intra_mode_tree);
162 vp9_cost_tokens(x->intra_uv_mode_cost[0], 167 vp9_cost_tokens(x->intra_uv_mode_cost[INTER_FRAME],
163 vp9_kf_uv_mode_prob[INTRA_MODES - 1], vp9_intra_mode_tree); 168 fc->uv_mode_prob[TM_PRED], vp9_intra_mode_tree);
164 169
165 for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; ++i) 170 for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; ++i)
166 vp9_cost_tokens((int *)x->switchable_interp_costs[i], 171 vp9_cost_tokens((int *)x->switchable_interp_costs[i],
167 fc->switchable_interp_prob[i], 172 fc->switchable_interp_prob[i], vp9_switchable_interp_tree);
168 vp9_switchable_interp_tree);
169 } 173 }
170 174
171 static void fill_token_costs(vp9_coeff_cost *c, 175 static void fill_token_costs(vp9_coeff_cost *c,
172 vp9_coeff_probs_model (*p)[PLANE_TYPES]) { 176 vp9_coeff_probs_model (*p)[PLANE_TYPES]) {
173 int i, j, k, l; 177 int i, j, k, l;
174 TX_SIZE t; 178 TX_SIZE t;
175 for (t = TX_4X4; t <= TX_32X32; ++t) 179 for (t = TX_4X4; t <= TX_32X32; ++t)
176 for (i = 0; i < PLANE_TYPES; ++i) 180 for (i = 0; i < PLANE_TYPES; ++i)
177 for (j = 0; j < REF_TYPES; ++j) 181 for (j = 0; j < REF_TYPES; ++j)
178 for (k = 0; k < COEF_BANDS; ++k) 182 for (k = 0; k < COEF_BANDS; ++k)
(...skipping 28 matching lines...) Expand all
207 // Initialize the sad lut tables using a formulaic calculation for now 211 // Initialize the sad lut tables using a formulaic calculation for now
208 // This is to make it easier to resolve the impact of experimental changes 212 // This is to make it easier to resolve the impact of experimental changes
209 // to the quantizer tables. 213 // to the quantizer tables.
210 for (i = 0; i < QINDEX_RANGE; i++) { 214 for (i = 0; i < QINDEX_RANGE; i++) {
211 const double q = vp9_convert_qindex_to_q(i); 215 const double q = vp9_convert_qindex_to_q(i);
212 sad_per_bit16lut[i] = (int)(0.0418 * q + 2.4107); 216 sad_per_bit16lut[i] = (int)(0.0418 * q + 2.4107);
213 sad_per_bit4lut[i] = (int)(0.063 * q + 2.742); 217 sad_per_bit4lut[i] = (int)(0.063 * q + 2.742);
214 } 218 }
215 } 219 }
216 220
217 int vp9_compute_rd_mult(VP9_COMP *cpi, int qindex) { 221 int vp9_compute_rd_mult(const VP9_COMP *cpi, int qindex) {
218 const int q = vp9_dc_quant(qindex, 0); 222 const int q = vp9_dc_quant(qindex, 0);
219 // TODO(debargha): Adjust the function below 223 // TODO(debargha): Adjust the function below
220 int rdmult = 88 * q * q / 25; 224 int rdmult = 88 * q * q / 25;
221 if (cpi->pass == 2 && (cpi->common.frame_type != KEY_FRAME)) { 225 if (cpi->pass == 2 && (cpi->common.frame_type != KEY_FRAME)) {
222 if (cpi->twopass.next_iiratio > 31) 226 if (cpi->twopass.next_iiratio > 31)
223 rdmult += (rdmult * rd_iifactor[31]) >> 4; 227 rdmult += (rdmult * rd_iifactor[31]) >> 4;
224 else 228 else
225 rdmult += (rdmult * rd_iifactor[cpi->twopass.next_iiratio]) >> 4; 229 rdmult += (rdmult * rd_iifactor[cpi->twopass.next_iiratio]) >> 4;
226 } 230 }
227 return rdmult; 231 return rdmult;
228 } 232 }
229 233
230 static int compute_rd_thresh_factor(int qindex) { 234 static int compute_rd_thresh_factor(int qindex) {
231 int q;
232 // TODO(debargha): Adjust the function below 235 // TODO(debargha): Adjust the function below
233 q = (int)(pow(vp9_dc_quant(qindex, 0) / 4.0, RD_THRESH_POW) * 5.12); 236 const int q = (int)(pow(vp9_dc_quant(qindex, 0) / 4.0, RD_THRESH_POW) * 5.12);
234 if (q < 8) 237 return MAX(q, 8);
235 q = 8;
236 return q;
237 } 238 }
238 239
239 void vp9_initialize_me_consts(VP9_COMP *cpi, int qindex) { 240 void vp9_initialize_me_consts(VP9_COMP *cpi, int qindex) {
240 cpi->mb.sadperbit16 = sad_per_bit16lut[qindex]; 241 cpi->mb.sadperbit16 = sad_per_bit16lut[qindex];
241 cpi->mb.sadperbit4 = sad_per_bit4lut[qindex]; 242 cpi->mb.sadperbit4 = sad_per_bit4lut[qindex];
242 } 243 }
243 244
244 static void set_block_thresholds(VP9_COMP *cpi) { 245 static void set_block_thresholds(VP9_COMP *cpi) {
246 const VP9_COMMON *const cm = &cpi->common;
245 int i, bsize, segment_id; 247 int i, bsize, segment_id;
246 VP9_COMMON *cm = &cpi->common;
247 SPEED_FEATURES *sf = &cpi->sf;
248 248
249 for (segment_id = 0; segment_id < MAX_SEGMENTS; ++segment_id) { 249 for (segment_id = 0; segment_id < MAX_SEGMENTS; ++segment_id) {
250 const int qindex = clamp(vp9_get_qindex(&cm->seg, segment_id, 250 const int qindex = clamp(vp9_get_qindex(&cm->seg, segment_id,
251 cm->base_qindex) + cm->y_dc_delta_q, 251 cm->base_qindex) + cm->y_dc_delta_q,
252 0, MAXQ); 252 0, MAXQ);
253 const int q = compute_rd_thresh_factor(qindex); 253 const int q = compute_rd_thresh_factor(qindex);
254 254
255 for (bsize = 0; bsize < BLOCK_SIZES; ++bsize) { 255 for (bsize = 0; bsize < BLOCK_SIZES; ++bsize) {
256 // Threshold here seems unnecessarily harsh but fine given actual 256 // Threshold here seems unnecessarily harsh but fine given actual
257 // range of values used for cpi->sf.thresh_mult[]. 257 // range of values used for cpi->sf.thresh_mult[].
258 const int t = q * rd_thresh_block_size_factor[bsize]; 258 const int t = q * rd_thresh_block_size_factor[bsize];
259 const int thresh_max = INT_MAX / t; 259 const int thresh_max = INT_MAX / t;
260 260
261 for (i = 0; i < MAX_MODES; ++i) 261 for (i = 0; i < MAX_MODES; ++i)
262 cpi->rd_threshes[segment_id][bsize][i] = 262 cpi->rd_threshes[segment_id][bsize][i] =
263 sf->thresh_mult[i] < thresh_max ? sf->thresh_mult[i] * t / 4 263 cpi->rd_thresh_mult[i] < thresh_max ? cpi->rd_thresh_mult[i] * t / 4
264 : INT_MAX; 264 : INT_MAX;
265 265
266 for (i = 0; i < MAX_REFS; ++i) { 266 for (i = 0; i < MAX_REFS; ++i) {
267 cpi->rd_thresh_sub8x8[segment_id][bsize][i] = 267 cpi->rd_thresh_sub8x8[segment_id][bsize][i] =
268 sf->thresh_mult_sub8x8[i] < thresh_max 268 cpi->rd_thresh_mult_sub8x8[i] < thresh_max
269 ? sf->thresh_mult_sub8x8[i] * t / 4 269 ? cpi->rd_thresh_mult_sub8x8[i] * t / 4
270 : INT_MAX; 270 : INT_MAX;
271 } 271 }
272 } 272 }
273 } 273 }
274 } 274 }
275 275
276 void vp9_initialize_rd_consts(VP9_COMP *cpi) { 276 void vp9_initialize_rd_consts(VP9_COMP *cpi) {
277 VP9_COMMON *cm = &cpi->common; 277 VP9_COMMON *const cm = &cpi->common;
278 MACROBLOCK *x = &cpi->mb; 278 MACROBLOCK *const x = &cpi->mb;
279 int i; 279 int i;
280 280
281 vp9_clear_system_state(); 281 vp9_clear_system_state();
282 282
283 cpi->RDDIV = RDDIV_BITS; // in bits (to multiply D by 128) 283 cpi->RDDIV = RDDIV_BITS; // in bits (to multiply D by 128)
284 cpi->RDMULT = vp9_compute_rd_mult(cpi, cm->base_qindex + cm->y_dc_delta_q); 284 cpi->RDMULT = vp9_compute_rd_mult(cpi, cm->base_qindex + cm->y_dc_delta_q);
285 285
286 x->errorperbit = cpi->RDMULT / RD_MULT_EPB_RATIO; 286 x->errorperbit = cpi->RDMULT / RD_MULT_EPB_RATIO;
287 x->errorperbit += (x->errorperbit == 0); 287 x->errorperbit += (x->errorperbit == 0);
288 288
289 vp9_set_speed_features(cpi);
290
291 x->select_txfm_size = (cpi->sf.tx_size_search_method == USE_LARGESTALL && 289 x->select_txfm_size = (cpi->sf.tx_size_search_method == USE_LARGESTALL &&
292 cm->frame_type != KEY_FRAME) ? 0 : 1; 290 cm->frame_type != KEY_FRAME) ? 0 : 1;
293 291
294 set_block_thresholds(cpi); 292 set_block_thresholds(cpi);
295 293
296 if (!cpi->sf.use_nonrd_pick_mode) { 294 if (!cpi->sf.use_nonrd_pick_mode || cm->frame_type == KEY_FRAME) {
297 fill_token_costs(x->token_costs, cm->fc.coef_probs); 295 fill_token_costs(x->token_costs, cm->fc.coef_probs);
298 296
299 for (i = 0; i < PARTITION_CONTEXTS; i++) 297 for (i = 0; i < PARTITION_CONTEXTS; i++)
300 vp9_cost_tokens(x->partition_cost[i], get_partition_probs(cm, i), 298 vp9_cost_tokens(x->partition_cost[i], get_partition_probs(cm, i),
301 vp9_partition_tree); 299 vp9_partition_tree);
302 } 300 }
303 301
304 if (!cpi->sf.use_nonrd_pick_mode || (cm->current_video_frame & 0x07) == 1) { 302 if (!cpi->sf.use_nonrd_pick_mode || (cm->current_video_frame & 0x07) == 1 ||
303 cm->frame_type == KEY_FRAME) {
305 fill_mode_costs(cpi); 304 fill_mode_costs(cpi);
306 305
307 if (!frame_is_intra_only(cm)) { 306 if (!frame_is_intra_only(cm)) {
308 vp9_build_nmv_cost_table(x->nmvjointcost, 307 vp9_build_nmv_cost_table(x->nmvjointcost,
309 cm->allow_high_precision_mv ? x->nmvcost_hp 308 cm->allow_high_precision_mv ? x->nmvcost_hp
310 : x->nmvcost, 309 : x->nmvcost,
311 &cm->fc.nmvc, cm->allow_high_precision_mv); 310 &cm->fc.nmvc, cm->allow_high_precision_mv);
312 311
313 for (i = 0; i < INTER_MODE_CONTEXTS; ++i) 312 for (i = 0; i < INTER_MODE_CONTEXTS; ++i)
314 vp9_cost_tokens((int *)x->inter_mode_cost[i], 313 vp9_cost_tokens((int *)x->inter_mode_cost[i],
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 int tmp = (xsq_q10 >> 2) + 8; 392 int tmp = (xsq_q10 >> 2) + 8;
394 int k = get_msb(tmp) - 3; 393 int k = get_msb(tmp) - 3;
395 int xq = (k << 3) + ((tmp >> k) & 0x7); 394 int xq = (k << 3) + ((tmp >> k) & 0x7);
396 const int one_q10 = 1 << 10; 395 const int one_q10 = 1 << 10;
397 const int a_q10 = ((xsq_q10 - xsq_iq_q10[xq]) << 10) >> (2 + k); 396 const int a_q10 = ((xsq_q10 - xsq_iq_q10[xq]) << 10) >> (2 + k);
398 const int b_q10 = one_q10 - a_q10; 397 const int b_q10 = one_q10 - a_q10;
399 *r_q10 = (rate_tab_q10[xq] * b_q10 + rate_tab_q10[xq + 1] * a_q10) >> 10; 398 *r_q10 = (rate_tab_q10[xq] * b_q10 + rate_tab_q10[xq + 1] * a_q10) >> 10;
400 *d_q10 = (dist_tab_q10[xq] * b_q10 + dist_tab_q10[xq + 1] * a_q10) >> 10; 399 *d_q10 = (dist_tab_q10[xq] * b_q10 + dist_tab_q10[xq + 1] * a_q10) >> 10;
401 } 400 }
402 401
403 static void model_rd_from_var_lapndz(unsigned int var, unsigned int n, 402 void vp9_model_rd_from_var_lapndz(unsigned int var, unsigned int n,
404 unsigned int qstep, int *rate, 403 unsigned int qstep, int *rate,
405 int64_t *dist) { 404 int64_t *dist) {
406 // This function models the rate and distortion for a Laplacian 405 // This function models the rate and distortion for a Laplacian
407 // source with given variance when quantized with a uniform quantizer 406 // source with given variance when quantized with a uniform quantizer
408 // with given stepsize. The closed form expressions are in: 407 // with given stepsize. The closed form expressions are in:
409 // Hang and Chen, "Source Model for transform video coder and its 408 // Hang and Chen, "Source Model for transform video coder and its
410 // application - Part I: Fundamental Theory", IEEE Trans. Circ. 409 // application - Part I: Fundamental Theory", IEEE Trans. Circ.
411 // Sys. for Video Tech., April 1997. 410 // Sys. for Video Tech., April 1997.
412 if (var == 0) { 411 if (var == 0) {
413 *rate = 0; 412 *rate = 0;
414 *dist = 0; 413 *dist = 0;
415 } else { 414 } else {
(...skipping 10 matching lines...) Expand all
426 425
427 static void model_rd_for_sb(VP9_COMP *cpi, BLOCK_SIZE bsize, 426 static void model_rd_for_sb(VP9_COMP *cpi, BLOCK_SIZE bsize,
428 MACROBLOCK *x, MACROBLOCKD *xd, 427 MACROBLOCK *x, MACROBLOCKD *xd,
429 int *out_rate_sum, int64_t *out_dist_sum) { 428 int *out_rate_sum, int64_t *out_dist_sum) {
430 // Note our transform coeffs are 8 times an orthogonal transform. 429 // Note our transform coeffs are 8 times an orthogonal transform.
431 // Hence quantizer step is also 8 times. To get effective quantizer 430 // Hence quantizer step is also 8 times. To get effective quantizer
432 // we need to divide by 8 before sending to modeling function. 431 // we need to divide by 8 before sending to modeling function.
433 int i; 432 int i;
434 int64_t rate_sum = 0; 433 int64_t rate_sum = 0;
435 int64_t dist_sum = 0; 434 int64_t dist_sum = 0;
436 int ref = xd->mi_8x8[0]->mbmi.ref_frame[0]; 435 const int ref = xd->mi[0]->mbmi.ref_frame[0];
437 unsigned int sse; 436 unsigned int sse;
438 437
439 for (i = 0; i < MAX_MB_PLANE; ++i) { 438 for (i = 0; i < MAX_MB_PLANE; ++i) {
440 struct macroblock_plane *const p = &x->plane[i]; 439 struct macroblock_plane *const p = &x->plane[i];
441 struct macroblockd_plane *const pd = &xd->plane[i]; 440 struct macroblockd_plane *const pd = &xd->plane[i];
442 const BLOCK_SIZE bs = get_plane_block_size(bsize, pd); 441 const BLOCK_SIZE bs = get_plane_block_size(bsize, pd);
443 442
444 (void) cpi->fn_ptr[bs].vf(p->src.buf, p->src.stride, 443 (void) cpi->fn_ptr[bs].vf(p->src.buf, p->src.stride,
445 pd->dst.buf, pd->dst.stride, &sse); 444 pd->dst.buf, pd->dst.stride, &sse);
446 445
(...skipping 10 matching lines...) Expand all
457 if (quantizer < 120) 456 if (quantizer < 120)
458 rate = (square_error * (280 - quantizer)) >> 8; 457 rate = (square_error * (280 - quantizer)) >> 8;
459 else 458 else
460 rate = 0; 459 rate = 0;
461 dist = (square_error * quantizer) >> 8; 460 dist = (square_error * quantizer) >> 8;
462 rate_sum += rate; 461 rate_sum += rate;
463 dist_sum += dist; 462 dist_sum += dist;
464 } else { 463 } else {
465 int rate; 464 int rate;
466 int64_t dist; 465 int64_t dist;
467 model_rd_from_var_lapndz(sse, 1 << num_pels_log2_lookup[bs], 466 vp9_model_rd_from_var_lapndz(sse, 1 << num_pels_log2_lookup[bs],
468 pd->dequant[1] >> 3, &rate, &dist); 467 pd->dequant[1] >> 3, &rate, &dist);
469 rate_sum += rate; 468 rate_sum += rate;
470 dist_sum += dist; 469 dist_sum += dist;
471 } 470 }
472 } 471 }
473 472
474 *out_rate_sum = (int)rate_sum; 473 *out_rate_sum = (int)rate_sum;
475 *out_dist_sum = dist_sum << 4; 474 *out_dist_sum = dist_sum << 4;
476 } 475 }
477 476
478 static void model_rd_for_sb_y_tx(VP9_COMP *cpi, BLOCK_SIZE bsize, 477 static void model_rd_for_sb_y_tx(VP9_COMP *cpi, BLOCK_SIZE bsize,
479 TX_SIZE tx_size, 478 TX_SIZE tx_size,
480 MACROBLOCK *x, MACROBLOCKD *xd, 479 MACROBLOCK *x, MACROBLOCKD *xd,
481 int *out_rate_sum, int64_t *out_dist_sum, 480 int *out_rate_sum, int64_t *out_dist_sum,
482 int *out_skip) { 481 int *out_skip) {
483 int j, k; 482 int j, k;
484 BLOCK_SIZE bs; 483 BLOCK_SIZE bs;
485 struct macroblock_plane *const p = &x->plane[0]; 484 const struct macroblock_plane *const p = &x->plane[0];
486 struct macroblockd_plane *const pd = &xd->plane[0]; 485 const struct macroblockd_plane *const pd = &xd->plane[0];
487 const int width = 4 * num_4x4_blocks_wide_lookup[bsize]; 486 const int width = 4 * num_4x4_blocks_wide_lookup[bsize];
488 const int height = 4 * num_4x4_blocks_high_lookup[bsize]; 487 const int height = 4 * num_4x4_blocks_high_lookup[bsize];
489 int rate_sum = 0; 488 int rate_sum = 0;
490 int64_t dist_sum = 0; 489 int64_t dist_sum = 0;
491 const int t = 4 << tx_size; 490 const int t = 4 << tx_size;
492 491
493 if (tx_size == TX_4X4) { 492 if (tx_size == TX_4X4) {
494 bs = BLOCK_4X4; 493 bs = BLOCK_4X4;
495 } else if (tx_size == TX_8X8) { 494 } else if (tx_size == TX_8X8) {
496 bs = BLOCK_8X8; 495 bs = BLOCK_8X8;
497 } else if (tx_size == TX_16X16) { 496 } else if (tx_size == TX_16X16) {
498 bs = BLOCK_16X16; 497 bs = BLOCK_16X16;
499 } else if (tx_size == TX_32X32) { 498 } else if (tx_size == TX_32X32) {
500 bs = BLOCK_32X32; 499 bs = BLOCK_32X32;
501 } else { 500 } else {
502 assert(0); 501 assert(0);
503 } 502 }
504 503
505 *out_skip = 1; 504 *out_skip = 1;
506 for (j = 0; j < height; j += t) { 505 for (j = 0; j < height; j += t) {
507 for (k = 0; k < width; k += t) { 506 for (k = 0; k < width; k += t) {
508 int rate; 507 int rate;
509 int64_t dist; 508 int64_t dist;
510 unsigned int sse; 509 unsigned int sse;
511 cpi->fn_ptr[bs].vf(&p->src.buf[j * p->src.stride + k], p->src.stride, 510 cpi->fn_ptr[bs].vf(&p->src.buf[j * p->src.stride + k], p->src.stride,
512 &pd->dst.buf[j * pd->dst.stride + k], pd->dst.stride, 511 &pd->dst.buf[j * pd->dst.stride + k], pd->dst.stride,
513 &sse); 512 &sse);
514 // sse works better than var, since there is no dc prediction used 513 // sse works better than var, since there is no dc prediction used
515 model_rd_from_var_lapndz(sse, t * t, pd->dequant[1] >> 3, &rate, &dist); 514 vp9_model_rd_from_var_lapndz(sse, t * t, pd->dequant[1] >> 3,
515 &rate, &dist);
516 rate_sum += rate; 516 rate_sum += rate;
517 dist_sum += dist; 517 dist_sum += dist;
518 *out_skip &= (rate < 1024); 518 *out_skip &= (rate < 1024);
519 } 519 }
520 } 520 }
521 521
522 *out_rate_sum = rate_sum; 522 *out_rate_sum = rate_sum;
523 *out_dist_sum = dist_sum << 4; 523 *out_dist_sum = dist_sum << 4;
524 } 524 }
525 525
(...skipping 16 matching lines...) Expand all
542 * decide whether to include cost of a trailing EOB node or not (i.e. we 542 * decide whether to include cost of a trailing EOB node or not (i.e. we
543 * can skip this if the last coefficient in this transform block, e.g. the 543 * can skip this if the last coefficient in this transform block, e.g. the
544 * 16th coefficient in a 4x4 block or the 64th coefficient in a 8x8 block, 544 * 16th coefficient in a 4x4 block or the 64th coefficient in a 8x8 block,
545 * were non-zero). */ 545 * were non-zero). */
546 static const int16_t band_counts[TX_SIZES][8] = { 546 static const int16_t band_counts[TX_SIZES][8] = {
547 { 1, 2, 3, 4, 3, 16 - 13, 0 }, 547 { 1, 2, 3, 4, 3, 16 - 13, 0 },
548 { 1, 2, 3, 4, 11, 64 - 21, 0 }, 548 { 1, 2, 3, 4, 11, 64 - 21, 0 },
549 { 1, 2, 3, 4, 11, 256 - 21, 0 }, 549 { 1, 2, 3, 4, 11, 256 - 21, 0 },
550 { 1, 2, 3, 4, 11, 1024 - 21, 0 }, 550 { 1, 2, 3, 4, 11, 1024 - 21, 0 },
551 }; 551 };
552
553 static INLINE int cost_coeffs(MACROBLOCK *x, 552 static INLINE int cost_coeffs(MACROBLOCK *x,
554 int plane, int block, 553 int plane, int block,
555 ENTROPY_CONTEXT *A, ENTROPY_CONTEXT *L, 554 ENTROPY_CONTEXT *A, ENTROPY_CONTEXT *L,
556 TX_SIZE tx_size, 555 TX_SIZE tx_size,
557 const int16_t *scan, const int16_t *nb) { 556 const int16_t *scan, const int16_t *nb,
557 int use_fast_coef_costing) {
558 MACROBLOCKD *const xd = &x->e_mbd; 558 MACROBLOCKD *const xd = &x->e_mbd;
559 MB_MODE_INFO *mbmi = &xd->mi_8x8[0]->mbmi; 559 MB_MODE_INFO *mbmi = &xd->mi[0]->mbmi;
560 struct macroblock_plane *p = &x->plane[plane]; 560 const struct macroblock_plane *p = &x->plane[plane];
561 struct macroblockd_plane *pd = &xd->plane[plane]; 561 const struct macroblockd_plane *pd = &xd->plane[plane];
562 const PLANE_TYPE type = pd->plane_type; 562 const PLANE_TYPE type = pd->plane_type;
563 const int16_t *band_count = &band_counts[tx_size][1]; 563 const int16_t *band_count = &band_counts[tx_size][1];
564 const int eob = p->eobs[block]; 564 const int eob = p->eobs[block];
565 const int16_t *const qcoeff = BLOCK_OFFSET(p->qcoeff, block); 565 const int16_t *const qcoeff = BLOCK_OFFSET(p->qcoeff, block);
566 unsigned int (*token_costs)[2][COEFF_CONTEXTS][ENTROPY_TOKENS] = 566 unsigned int (*token_costs)[2][COEFF_CONTEXTS][ENTROPY_TOKENS] =
567 x->token_costs[tx_size][type][is_inter_block(mbmi)]; 567 x->token_costs[tx_size][type][is_inter_block(mbmi)];
568 uint8_t *p_tok = x->token_cache; 568 uint8_t token_cache[32 * 32];
569 int pt = combine_entropy_contexts(*A, *L); 569 int pt = combine_entropy_contexts(*A, *L);
570 int c, cost; 570 int c, cost;
571
572 // Check for consistency of tx_size with mode info 571 // Check for consistency of tx_size with mode info
573 assert(type == PLANE_TYPE_Y ? mbmi->tx_size == tx_size 572 assert(type == PLANE_TYPE_Y ? mbmi->tx_size == tx_size
574 : get_uv_tx_size(mbmi) == tx_size); 573 : get_uv_tx_size(mbmi) == tx_size);
575 574
576 if (eob == 0) { 575 if (eob == 0) {
577 // single eob token 576 // single eob token
578 cost = token_costs[0][0][pt][EOB_TOKEN]; 577 cost = token_costs[0][0][pt][EOB_TOKEN];
579 c = 0; 578 c = 0;
580 } else { 579 } else {
581 int band_left = *band_count++; 580 int band_left = *band_count++;
582 581
583 // dc token 582 // dc token
584 int v = qcoeff[0]; 583 int v = qcoeff[0];
585 int prev_t = vp9_dct_value_tokens_ptr[v].token; 584 int prev_t = vp9_dct_value_tokens_ptr[v].token;
586 cost = (*token_costs)[0][pt][prev_t] + vp9_dct_value_cost_ptr[v]; 585 cost = (*token_costs)[0][pt][prev_t] + vp9_dct_value_cost_ptr[v];
587 p_tok[0] = vp9_pt_energy_class[prev_t]; 586 token_cache[0] = vp9_pt_energy_class[prev_t];
588 ++token_costs; 587 ++token_costs;
589 588
590 // ac tokens 589 // ac tokens
591 for (c = 1; c < eob; c++) { 590 for (c = 1; c < eob; c++) {
592 const int rc = scan[c]; 591 const int rc = scan[c];
593 int t; 592 int t;
594 593
595 v = qcoeff[rc]; 594 v = qcoeff[rc];
596 t = vp9_dct_value_tokens_ptr[v].token; 595 t = vp9_dct_value_tokens_ptr[v].token;
597 pt = get_coef_context(nb, p_tok, c); 596 if (use_fast_coef_costing) {
598 cost += (*token_costs)[!prev_t][pt][t] + vp9_dct_value_cost_ptr[v]; 597 cost += (*token_costs)[!prev_t][!prev_t][t] + vp9_dct_value_cost_ptr[v];
599 p_tok[rc] = vp9_pt_energy_class[t]; 598 } else {
599 pt = get_coef_context(nb, token_cache, c);
600 cost += (*token_costs)[!prev_t][pt][t] + vp9_dct_value_cost_ptr[v];
601 token_cache[rc] = vp9_pt_energy_class[t];
602 }
600 prev_t = t; 603 prev_t = t;
601 if (!--band_left) { 604 if (!--band_left) {
602 band_left = *band_count++; 605 band_left = *band_count++;
603 ++token_costs; 606 ++token_costs;
604 } 607 }
605 } 608 }
606 609
607 // eob token 610 // eob token
608 if (band_left) { 611 if (band_left) {
609 pt = get_coef_context(nb, p_tok, c); 612 if (use_fast_coef_costing) {
610 cost += (*token_costs)[0][pt][EOB_TOKEN]; 613 cost += (*token_costs)[0][!prev_t][EOB_TOKEN];
614 } else {
615 pt = get_coef_context(nb, token_cache, c);
616 cost += (*token_costs)[0][pt][EOB_TOKEN];
617 }
611 } 618 }
612 } 619 }
613 620
614 // is eob first coefficient; 621 // is eob first coefficient;
615 *A = *L = (c > 0); 622 *A = *L = (c > 0);
616 623
617 return cost; 624 return cost;
618 } 625 }
619
620 static void dist_block(int plane, int block, TX_SIZE tx_size, 626 static void dist_block(int plane, int block, TX_SIZE tx_size,
621 struct rdcost_block_args* args) { 627 struct rdcost_block_args* args) {
622 const int ss_txfrm_size = tx_size << 1; 628 const int ss_txfrm_size = tx_size << 1;
623 MACROBLOCK* const x = args->x; 629 MACROBLOCK* const x = args->x;
624 MACROBLOCKD* const xd = &x->e_mbd; 630 MACROBLOCKD* const xd = &x->e_mbd;
625 struct macroblock_plane *const p = &x->plane[plane]; 631 const struct macroblock_plane *const p = &x->plane[plane];
626 struct macroblockd_plane *const pd = &xd->plane[plane]; 632 const struct macroblockd_plane *const pd = &xd->plane[plane];
627 int64_t this_sse; 633 int64_t this_sse;
628 int shift = tx_size == TX_32X32 ? 0 : 2; 634 int shift = tx_size == TX_32X32 ? 0 : 2;
629 int16_t *const coeff = BLOCK_OFFSET(p->coeff, block); 635 int16_t *const coeff = BLOCK_OFFSET(p->coeff, block);
630 int16_t *const dqcoeff = BLOCK_OFFSET(pd->dqcoeff, block); 636 int16_t *const dqcoeff = BLOCK_OFFSET(pd->dqcoeff, block);
631 args->dist = vp9_block_error(coeff, dqcoeff, 16 << ss_txfrm_size, 637 args->dist = vp9_block_error(coeff, dqcoeff, 16 << ss_txfrm_size,
632 &this_sse) >> shift; 638 &this_sse) >> shift;
633 args->sse = this_sse >> shift; 639 args->sse = this_sse >> shift;
634 640
635 if (x->skip_encode && !is_inter_block(&xd->mi_8x8[0]->mbmi)) { 641 if (x->skip_encode && !is_inter_block(&xd->mi[0]->mbmi)) {
636 // TODO(jingning): tune the model to better capture the distortion. 642 // TODO(jingning): tune the model to better capture the distortion.
637 int64_t p = (pd->dequant[1] * pd->dequant[1] * 643 int64_t p = (pd->dequant[1] * pd->dequant[1] *
638 (1 << ss_txfrm_size)) >> (shift + 2); 644 (1 << ss_txfrm_size)) >> (shift + 2);
639 args->dist += (p >> 4); 645 args->dist += (p >> 4);
640 args->sse += p; 646 args->sse += p;
641 } 647 }
642 } 648 }
643 649
644 static void rate_block(int plane, int block, BLOCK_SIZE plane_bsize, 650 static void rate_block(int plane, int block, BLOCK_SIZE plane_bsize,
645 TX_SIZE tx_size, struct rdcost_block_args* args) { 651 TX_SIZE tx_size, struct rdcost_block_args* args) {
646 int x_idx, y_idx; 652 int x_idx, y_idx;
647 txfrm_block_to_raster_xy(plane_bsize, tx_size, block, &x_idx, &y_idx); 653 txfrm_block_to_raster_xy(plane_bsize, tx_size, block, &x_idx, &y_idx);
648 654
649 args->rate = cost_coeffs(args->x, plane, block, args->t_above + x_idx, 655 args->rate = cost_coeffs(args->x, plane, block, args->t_above + x_idx,
650 args->t_left + y_idx, tx_size, 656 args->t_left + y_idx, tx_size,
651 args->so->scan, args->so->neighbors); 657 args->so->scan, args->so->neighbors,
658 args->use_fast_coef_costing);
652 } 659 }
653 660
654 static void block_rd_txfm(int plane, int block, BLOCK_SIZE plane_bsize, 661 static void block_rd_txfm(int plane, int block, BLOCK_SIZE plane_bsize,
655 TX_SIZE tx_size, void *arg) { 662 TX_SIZE tx_size, void *arg) {
656 struct rdcost_block_args *args = arg; 663 struct rdcost_block_args *args = arg;
657 MACROBLOCK *const x = args->x; 664 MACROBLOCK *const x = args->x;
658 MACROBLOCKD *const xd = &x->e_mbd; 665 MACROBLOCKD *const xd = &x->e_mbd;
659 MB_MODE_INFO *mbmi = &xd->mi_8x8[0]->mbmi; 666 MB_MODE_INFO *const mbmi = &xd->mi[0]->mbmi;
660 int64_t rd1, rd2, rd; 667 int64_t rd1, rd2, rd;
661 668
662 if (args->skip) 669 if (args->skip)
663 return; 670 return;
664 671
665 if (!is_inter_block(mbmi)) 672 if (!is_inter_block(mbmi))
666 vp9_encode_block_intra(x, plane, block, plane_bsize, tx_size, &mbmi->skip); 673 vp9_encode_block_intra(x, plane, block, plane_bsize, tx_size, &mbmi->skip);
667 else 674 else
668 vp9_xform_quant(x, plane, block, plane_bsize, tx_size); 675 vp9_xform_quant(x, plane, block, plane_bsize, tx_size);
669 676
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
725 break; 732 break;
726 default: 733 default:
727 assert(0 && "Invalid transform size."); 734 assert(0 && "Invalid transform size.");
728 } 735 }
729 } 736 }
730 737
731 static void txfm_rd_in_plane(MACROBLOCK *x, 738 static void txfm_rd_in_plane(MACROBLOCK *x,
732 int *rate, int64_t *distortion, 739 int *rate, int64_t *distortion,
733 int *skippable, int64_t *sse, 740 int *skippable, int64_t *sse,
734 int64_t ref_best_rd, int plane, 741 int64_t ref_best_rd, int plane,
735 BLOCK_SIZE bsize, TX_SIZE tx_size) { 742 BLOCK_SIZE bsize, TX_SIZE tx_size,
743 int use_fast_coef_casting) {
736 MACROBLOCKD *const xd = &x->e_mbd; 744 MACROBLOCKD *const xd = &x->e_mbd;
737 struct macroblockd_plane *const pd = &xd->plane[plane]; 745 const struct macroblockd_plane *const pd = &xd->plane[plane];
738 struct rdcost_block_args args = { 0 }; 746 struct rdcost_block_args args = { 0 };
739 args.x = x; 747 args.x = x;
740 args.best_rd = ref_best_rd; 748 args.best_rd = ref_best_rd;
749 args.use_fast_coef_costing = use_fast_coef_casting;
741 750
742 if (plane == 0) 751 if (plane == 0)
743 xd->mi_8x8[0]->mbmi.tx_size = tx_size; 752 xd->mi[0]->mbmi.tx_size = tx_size;
744 753
745 vp9_get_entropy_contexts(bsize, tx_size, pd, args.t_above, args.t_left); 754 vp9_get_entropy_contexts(bsize, tx_size, pd, args.t_above, args.t_left);
746 755
747 args.so = get_scan(xd, tx_size, pd->plane_type, 0); 756 args.so = get_scan(xd, tx_size, pd->plane_type, 0);
748 757
749 vp9_foreach_transformed_block_in_plane(xd, bsize, plane, 758 vp9_foreach_transformed_block_in_plane(xd, bsize, plane,
750 block_rd_txfm, &args); 759 block_rd_txfm, &args);
751 if (args.skip) { 760 if (args.skip) {
752 *rate = INT_MAX; 761 *rate = INT_MAX;
753 *distortion = INT64_MAX; 762 *distortion = INT64_MAX;
754 *sse = INT64_MAX; 763 *sse = INT64_MAX;
755 *skippable = 0; 764 *skippable = 0;
756 } else { 765 } else {
757 *distortion = args.this_dist; 766 *distortion = args.this_dist;
758 *rate = args.this_rate; 767 *rate = args.this_rate;
759 *sse = args.this_sse; 768 *sse = args.this_sse;
760 *skippable = vp9_is_skippable_in_plane(x, bsize, plane); 769 *skippable = vp9_is_skippable_in_plane(x, bsize, plane);
761 } 770 }
762 } 771 }
763 772
764 static void choose_largest_txfm_size(VP9_COMP *cpi, MACROBLOCK *x, 773 static void choose_largest_txfm_size(VP9_COMP *cpi, MACROBLOCK *x,
765 int *rate, int64_t *distortion, 774 int *rate, int64_t *distortion,
766 int *skip, int64_t *sse, 775 int *skip, int64_t *sse,
767 int64_t ref_best_rd, 776 int64_t ref_best_rd,
768 BLOCK_SIZE bs) { 777 BLOCK_SIZE bs) {
769 const TX_SIZE max_tx_size = max_txsize_lookup[bs]; 778 const TX_SIZE max_tx_size = max_txsize_lookup[bs];
770 VP9_COMMON *const cm = &cpi->common; 779 VP9_COMMON *const cm = &cpi->common;
771 const TX_SIZE largest_tx_size = tx_mode_to_biggest_tx_size[cm->tx_mode]; 780 const TX_SIZE largest_tx_size = tx_mode_to_biggest_tx_size[cm->tx_mode];
772 MACROBLOCKD *const xd = &x->e_mbd; 781 MACROBLOCKD *const xd = &x->e_mbd;
773 MB_MODE_INFO *const mbmi = &xd->mi_8x8[0]->mbmi; 782 MB_MODE_INFO *const mbmi = &xd->mi[0]->mbmi;
774 783
775 mbmi->tx_size = MIN(max_tx_size, largest_tx_size); 784 mbmi->tx_size = MIN(max_tx_size, largest_tx_size);
776 785
777 txfm_rd_in_plane(x, rate, distortion, skip, 786 txfm_rd_in_plane(x, rate, distortion, skip,
778 &sse[mbmi->tx_size], ref_best_rd, 0, bs, 787 &sse[mbmi->tx_size], ref_best_rd, 0, bs,
779 mbmi->tx_size); 788 mbmi->tx_size, cpi->sf.use_fast_coef_costing);
780 cpi->tx_stepdown_count[0]++; 789 cpi->tx_stepdown_count[0]++;
781 } 790 }
782 791
783 static void choose_txfm_size_from_rd(VP9_COMP *cpi, MACROBLOCK *x, 792 static void choose_txfm_size_from_rd(VP9_COMP *cpi, MACROBLOCK *x,
784 int (*r)[2], int *rate, 793 int (*r)[2], int *rate,
785 int64_t *d, int64_t *distortion, 794 int64_t *d, int64_t *distortion,
786 int *s, int *skip, 795 int *s, int *skip,
787 int64_t tx_cache[TX_MODES], 796 int64_t tx_cache[TX_MODES],
788 BLOCK_SIZE bs) { 797 BLOCK_SIZE bs) {
789 const TX_SIZE max_tx_size = max_txsize_lookup[bs]; 798 const TX_SIZE max_tx_size = max_txsize_lookup[bs];
790 VP9_COMMON *const cm = &cpi->common; 799 VP9_COMMON *const cm = &cpi->common;
791 MACROBLOCKD *const xd = &x->e_mbd; 800 MACROBLOCKD *const xd = &x->e_mbd;
792 MB_MODE_INFO *const mbmi = &xd->mi_8x8[0]->mbmi; 801 MB_MODE_INFO *const mbmi = &xd->mi[0]->mbmi;
793 vp9_prob skip_prob = vp9_get_skip_prob(cm, xd); 802 vp9_prob skip_prob = vp9_get_skip_prob(cm, xd);
794 int64_t rd[TX_SIZES][2] = {{INT64_MAX, INT64_MAX}, 803 int64_t rd[TX_SIZES][2] = {{INT64_MAX, INT64_MAX},
795 {INT64_MAX, INT64_MAX}, 804 {INT64_MAX, INT64_MAX},
796 {INT64_MAX, INT64_MAX}, 805 {INT64_MAX, INT64_MAX},
797 {INT64_MAX, INT64_MAX}}; 806 {INT64_MAX, INT64_MAX}};
798 int n, m; 807 int n, m;
799 int s0, s1; 808 int s0, s1;
800 const TX_SIZE max_mode_tx_size = tx_mode_to_biggest_tx_size[cm->tx_mode]; 809 const TX_SIZE max_mode_tx_size = tx_mode_to_biggest_tx_size[cm->tx_mode];
801 int64_t best_rd = INT64_MAX; 810 int64_t best_rd = INT64_MAX;
802 TX_SIZE best_tx = TX_4X4; 811 TX_SIZE best_tx = TX_4X4;
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
865 874
866 static void choose_txfm_size_from_modelrd(VP9_COMP *cpi, MACROBLOCK *x, 875 static void choose_txfm_size_from_modelrd(VP9_COMP *cpi, MACROBLOCK *x,
867 int (*r)[2], int *rate, 876 int (*r)[2], int *rate,
868 int64_t *d, int64_t *distortion, 877 int64_t *d, int64_t *distortion,
869 int *s, int *skip, int64_t *sse, 878 int *s, int *skip, int64_t *sse,
870 int64_t ref_best_rd, 879 int64_t ref_best_rd,
871 BLOCK_SIZE bs) { 880 BLOCK_SIZE bs) {
872 const TX_SIZE max_tx_size = max_txsize_lookup[bs]; 881 const TX_SIZE max_tx_size = max_txsize_lookup[bs];
873 VP9_COMMON *const cm = &cpi->common; 882 VP9_COMMON *const cm = &cpi->common;
874 MACROBLOCKD *const xd = &x->e_mbd; 883 MACROBLOCKD *const xd = &x->e_mbd;
875 MB_MODE_INFO *const mbmi = &xd->mi_8x8[0]->mbmi; 884 MB_MODE_INFO *const mbmi = &xd->mi[0]->mbmi;
876 vp9_prob skip_prob = vp9_get_skip_prob(cm, xd); 885 vp9_prob skip_prob = vp9_get_skip_prob(cm, xd);
877 int64_t rd[TX_SIZES][2] = {{INT64_MAX, INT64_MAX}, 886 int64_t rd[TX_SIZES][2] = {{INT64_MAX, INT64_MAX},
878 {INT64_MAX, INT64_MAX}, 887 {INT64_MAX, INT64_MAX},
879 {INT64_MAX, INT64_MAX}, 888 {INT64_MAX, INT64_MAX},
880 {INT64_MAX, INT64_MAX}}; 889 {INT64_MAX, INT64_MAX}};
881 int n, m; 890 int n, m;
882 int s0, s1; 891 int s0, s1;
883 double scale_rd[TX_SIZES] = {1.73, 1.44, 1.20, 1.00}; 892 double scale_rd[TX_SIZES] = {1.73, 1.44, 1.20, 1.00};
884 const TX_SIZE max_mode_tx_size = tx_mode_to_biggest_tx_size[cm->tx_mode]; 893 const TX_SIZE max_mode_tx_size = tx_mode_to_biggest_tx_size[cm->tx_mode];
885 int64_t best_rd = INT64_MAX; 894 int64_t best_rd = INT64_MAX;
(...skipping 27 matching lines...) Expand all
913 best_tx = n; 922 best_tx = n;
914 } 923 }
915 } 924 }
916 925
917 mbmi->tx_size = cm->tx_mode == TX_MODE_SELECT ? 926 mbmi->tx_size = cm->tx_mode == TX_MODE_SELECT ?
918 best_tx : MIN(max_tx_size, max_mode_tx_size); 927 best_tx : MIN(max_tx_size, max_mode_tx_size);
919 928
920 // Actually encode using the chosen mode if a model was used, but do not 929 // Actually encode using the chosen mode if a model was used, but do not
921 // update the r, d costs 930 // update the r, d costs
922 txfm_rd_in_plane(x, rate, distortion, skip, 931 txfm_rd_in_plane(x, rate, distortion, skip,
923 &sse[mbmi->tx_size], ref_best_rd, 0, bs, mbmi->tx_size); 932 &sse[mbmi->tx_size], ref_best_rd, 0, bs, mbmi->tx_size,
933 cpi->sf.use_fast_coef_costing);
924 934
925 if (max_tx_size == TX_32X32 && best_tx == TX_32X32) { 935 if (max_tx_size == TX_32X32 && best_tx == TX_32X32) {
926 cpi->tx_stepdown_count[0]++; 936 cpi->tx_stepdown_count[0]++;
927 } else if (max_tx_size >= TX_16X16 && best_tx == TX_16X16) { 937 } else if (max_tx_size >= TX_16X16 && best_tx == TX_16X16) {
928 cpi->tx_stepdown_count[max_tx_size - TX_16X16]++; 938 cpi->tx_stepdown_count[max_tx_size - TX_16X16]++;
929 } else if (rd[TX_8X8][1] <= rd[TX_4X4][1]) { 939 } else if (rd[TX_8X8][1] <= rd[TX_4X4][1]) {
930 cpi->tx_stepdown_count[max_tx_size - TX_8X8]++; 940 cpi->tx_stepdown_count[max_tx_size - TX_8X8]++;
931 } else { 941 } else {
932 cpi->tx_stepdown_count[max_tx_size - TX_4X4]++; 942 cpi->tx_stepdown_count[max_tx_size - TX_4X4]++;
933 } 943 }
934 } 944 }
935 945
936 static void inter_super_block_yrd(VP9_COMP *cpi, MACROBLOCK *x, int *rate, 946 static void inter_super_block_yrd(VP9_COMP *cpi, MACROBLOCK *x, int *rate,
937 int64_t *distortion, int *skip, 947 int64_t *distortion, int *skip,
938 int64_t *psse, BLOCK_SIZE bs, 948 int64_t *psse, BLOCK_SIZE bs,
939 int64_t txfm_cache[TX_MODES], 949 int64_t txfm_cache[TX_MODES],
940 int64_t ref_best_rd) { 950 int64_t ref_best_rd) {
941 int r[TX_SIZES][2], s[TX_SIZES]; 951 int r[TX_SIZES][2], s[TX_SIZES];
942 int64_t d[TX_SIZES], sse[TX_SIZES]; 952 int64_t d[TX_SIZES], sse[TX_SIZES];
943 MACROBLOCKD *xd = &x->e_mbd; 953 MACROBLOCKD *xd = &x->e_mbd;
944 MB_MODE_INFO *const mbmi = &xd->mi_8x8[0]->mbmi; 954 MB_MODE_INFO *const mbmi = &xd->mi[0]->mbmi;
945 const TX_SIZE max_tx_size = max_txsize_lookup[bs]; 955 const TX_SIZE max_tx_size = max_txsize_lookup[bs];
946 TX_SIZE tx_size; 956 TX_SIZE tx_size;
947 957
948 assert(bs == mbmi->sb_type); 958 assert(bs == mbmi->sb_type);
949 959
950 vp9_subtract_plane(x, bs, 0); 960 vp9_subtract_plane(x, bs, 0);
951 961
952 if (cpi->sf.tx_size_search_method == USE_LARGESTALL) { 962 if (cpi->sf.tx_size_search_method == USE_LARGESTALL) {
953 vpx_memset(txfm_cache, 0, TX_MODES * sizeof(int64_t)); 963 vpx_memset(txfm_cache, 0, TX_MODES * sizeof(int64_t));
954 choose_largest_txfm_size(cpi, x, rate, distortion, skip, sse, 964 choose_largest_txfm_size(cpi, x, rate, distortion, skip, sse,
955 ref_best_rd, bs); 965 ref_best_rd, bs);
956 if (psse) 966 if (psse)
957 *psse = sse[mbmi->tx_size]; 967 *psse = sse[mbmi->tx_size];
958 return; 968 return;
959 } 969 }
960 970
961 if (cpi->sf.tx_size_search_method == USE_LARGESTINTRA_MODELINTER) { 971 if (cpi->sf.tx_size_search_method == USE_LARGESTINTRA_MODELINTER) {
962 for (tx_size = TX_4X4; tx_size <= max_tx_size; ++tx_size) 972 for (tx_size = TX_4X4; tx_size <= max_tx_size; ++tx_size)
963 model_rd_for_sb_y_tx(cpi, bs, tx_size, x, xd, 973 model_rd_for_sb_y_tx(cpi, bs, tx_size, x, xd,
964 &r[tx_size][0], &d[tx_size], &s[tx_size]); 974 &r[tx_size][0], &d[tx_size], &s[tx_size]);
965 choose_txfm_size_from_modelrd(cpi, x, r, rate, d, distortion, s, 975 choose_txfm_size_from_modelrd(cpi, x, r, rate, d, distortion, s,
966 skip, sse, ref_best_rd, bs); 976 skip, sse, ref_best_rd, bs);
967 } else { 977 } else {
968 for (tx_size = TX_4X4; tx_size <= max_tx_size; ++tx_size) 978 for (tx_size = TX_4X4; tx_size <= max_tx_size; ++tx_size)
969 txfm_rd_in_plane(x, &r[tx_size][0], &d[tx_size], 979 txfm_rd_in_plane(x, &r[tx_size][0], &d[tx_size],
970 &s[tx_size], &sse[tx_size], 980 &s[tx_size], &sse[tx_size],
971 ref_best_rd, 0, bs, tx_size); 981 ref_best_rd, 0, bs, tx_size,
982 cpi->sf.use_fast_coef_costing);
972 choose_txfm_size_from_rd(cpi, x, r, rate, d, distortion, s, 983 choose_txfm_size_from_rd(cpi, x, r, rate, d, distortion, s,
973 skip, txfm_cache, bs); 984 skip, txfm_cache, bs);
974 } 985 }
975 if (psse) 986 if (psse)
976 *psse = sse[mbmi->tx_size]; 987 *psse = sse[mbmi->tx_size];
977 } 988 }
978 989
979 static void intra_super_block_yrd(VP9_COMP *cpi, MACROBLOCK *x, int *rate, 990 static void intra_super_block_yrd(VP9_COMP *cpi, MACROBLOCK *x, int *rate,
980 int64_t *distortion, int *skip, 991 int64_t *distortion, int *skip,
981 int64_t *psse, BLOCK_SIZE bs, 992 int64_t *psse, BLOCK_SIZE bs,
982 int64_t txfm_cache[TX_MODES], 993 int64_t txfm_cache[TX_MODES],
983 int64_t ref_best_rd) { 994 int64_t ref_best_rd) {
984 int64_t sse[TX_SIZES]; 995 int64_t sse[TX_SIZES];
985 MACROBLOCKD *xd = &x->e_mbd; 996 MACROBLOCKD *xd = &x->e_mbd;
986 MB_MODE_INFO *const mbmi = &xd->mi_8x8[0]->mbmi; 997 MB_MODE_INFO *const mbmi = &xd->mi[0]->mbmi;
987 998
988 assert(bs == mbmi->sb_type); 999 assert(bs == mbmi->sb_type);
989 if (cpi->sf.tx_size_search_method != USE_FULL_RD) { 1000 if (cpi->sf.tx_size_search_method != USE_FULL_RD) {
990 vpx_memset(txfm_cache, 0, TX_MODES * sizeof(int64_t)); 1001 vpx_memset(txfm_cache, 0, TX_MODES * sizeof(int64_t));
991 choose_largest_txfm_size(cpi, x, rate, distortion, skip, sse, 1002 choose_largest_txfm_size(cpi, x, rate, distortion, skip, sse,
992 ref_best_rd, bs); 1003 ref_best_rd, bs);
993 } else { 1004 } else {
994 int r[TX_SIZES][2], s[TX_SIZES]; 1005 int r[TX_SIZES][2], s[TX_SIZES];
995 int64_t d[TX_SIZES]; 1006 int64_t d[TX_SIZES];
996 TX_SIZE tx_size; 1007 TX_SIZE tx_size;
997 for (tx_size = TX_4X4; tx_size <= max_txsize_lookup[bs]; ++tx_size) 1008 for (tx_size = TX_4X4; tx_size <= max_txsize_lookup[bs]; ++tx_size)
998 txfm_rd_in_plane(x, &r[tx_size][0], &d[tx_size], 1009 txfm_rd_in_plane(x, &r[tx_size][0], &d[tx_size],
999 &s[tx_size], &sse[tx_size], 1010 &s[tx_size], &sse[tx_size],
1000 ref_best_rd, 0, bs, tx_size); 1011 ref_best_rd, 0, bs, tx_size,
1012 cpi->sf.use_fast_coef_costing);
1001 choose_txfm_size_from_rd(cpi, x, r, rate, d, distortion, s, 1013 choose_txfm_size_from_rd(cpi, x, r, rate, d, distortion, s,
1002 skip, txfm_cache, bs); 1014 skip, txfm_cache, bs);
1003 } 1015 }
1004 if (psse) 1016 if (psse)
1005 *psse = sse[mbmi->tx_size]; 1017 *psse = sse[mbmi->tx_size];
1006 } 1018 }
1007 1019
1008 1020
1009 static int conditional_skipintra(MB_PREDICTION_MODE mode, 1021 static int conditional_skipintra(MB_PREDICTION_MODE mode,
1010 MB_PREDICTION_MODE best_intra_mode) { 1022 MB_PREDICTION_MODE best_intra_mode) {
(...skipping 11 matching lines...) Expand all
1022 return 1; 1034 return 1;
1023 if (mode == D153_PRED && 1035 if (mode == D153_PRED &&
1024 best_intra_mode != H_PRED && 1036 best_intra_mode != H_PRED &&
1025 best_intra_mode != D135_PRED) 1037 best_intra_mode != D135_PRED)
1026 return 1; 1038 return 1;
1027 return 0; 1039 return 0;
1028 } 1040 }
1029 1041
1030 static int64_t rd_pick_intra4x4block(VP9_COMP *cpi, MACROBLOCK *x, int ib, 1042 static int64_t rd_pick_intra4x4block(VP9_COMP *cpi, MACROBLOCK *x, int ib,
1031 MB_PREDICTION_MODE *best_mode, 1043 MB_PREDICTION_MODE *best_mode,
1032 int *bmode_costs, 1044 const int *bmode_costs,
1033 ENTROPY_CONTEXT *a, ENTROPY_CONTEXT *l, 1045 ENTROPY_CONTEXT *a, ENTROPY_CONTEXT *l,
1034 int *bestrate, int *bestratey, 1046 int *bestrate, int *bestratey,
1035 int64_t *bestdistortion, 1047 int64_t *bestdistortion,
1036 BLOCK_SIZE bsize, int64_t rd_thresh) { 1048 BLOCK_SIZE bsize, int64_t rd_thresh) {
1037 MB_PREDICTION_MODE mode; 1049 MB_PREDICTION_MODE mode;
1038 MACROBLOCKD *const xd = &x->e_mbd; 1050 MACROBLOCKD *const xd = &x->e_mbd;
1039 int64_t best_rd = rd_thresh; 1051 int64_t best_rd = rd_thresh;
1040 1052
1041 struct macroblock_plane *p = &x->plane[0]; 1053 struct macroblock_plane *p = &x->plane[0];
1042 struct macroblockd_plane *pd = &xd->plane[0]; 1054 struct macroblockd_plane *pd = &xd->plane[0];
1043 const int src_stride = p->src.stride; 1055 const int src_stride = p->src.stride;
1044 const int dst_stride = pd->dst.stride; 1056 const int dst_stride = pd->dst.stride;
1045 const uint8_t *src_init = &p->src.buf[raster_block_offset(BLOCK_8X8, ib, 1057 const uint8_t *src_init = &p->src.buf[raster_block_offset(BLOCK_8X8, ib,
1046 src_stride)]; 1058 src_stride)];
1047 uint8_t *dst_init = &pd->dst.buf[raster_block_offset(BLOCK_8X8, ib, 1059 uint8_t *dst_init = &pd->dst.buf[raster_block_offset(BLOCK_8X8, ib,
1048 dst_stride)]; 1060 dst_stride)];
1049 ENTROPY_CONTEXT ta[2], tempa[2]; 1061 ENTROPY_CONTEXT ta[2], tempa[2];
1050 ENTROPY_CONTEXT tl[2], templ[2]; 1062 ENTROPY_CONTEXT tl[2], templ[2];
1051 1063
1052 const int num_4x4_blocks_wide = num_4x4_blocks_wide_lookup[bsize]; 1064 const int num_4x4_blocks_wide = num_4x4_blocks_wide_lookup[bsize];
1053 const int num_4x4_blocks_high = num_4x4_blocks_high_lookup[bsize]; 1065 const int num_4x4_blocks_high = num_4x4_blocks_high_lookup[bsize];
1054 int idx, idy; 1066 int idx, idy;
1055 uint8_t best_dst[8 * 8]; 1067 uint8_t best_dst[8 * 8];
1056 1068
1057 assert(ib < 4); 1069 assert(ib < 4);
1058 1070
1059 vpx_memcpy(ta, a, sizeof(ta)); 1071 vpx_memcpy(ta, a, sizeof(ta));
1060 vpx_memcpy(tl, l, sizeof(tl)); 1072 vpx_memcpy(tl, l, sizeof(tl));
1061 xd->mi_8x8[0]->mbmi.tx_size = TX_4X4; 1073 xd->mi[0]->mbmi.tx_size = TX_4X4;
1062 1074
1063 for (mode = DC_PRED; mode <= TM_PRED; ++mode) { 1075 for (mode = DC_PRED; mode <= TM_PRED; ++mode) {
1064 int64_t this_rd; 1076 int64_t this_rd;
1065 int ratey = 0; 1077 int ratey = 0;
1066 int64_t distortion = 0; 1078 int64_t distortion = 0;
1067 int rate = bmode_costs[mode]; 1079 int rate = bmode_costs[mode];
1068 1080
1069 if (!(cpi->sf.intra_y_mode_mask[TX_4X4] & (1 << mode))) 1081 if (!(cpi->sf.intra_y_mode_mask[TX_4X4] & (1 << mode)))
1070 continue; 1082 continue;
1071 1083
1072 // Only do the oblique modes if the best so far is 1084 // Only do the oblique modes if the best so far is
1073 // one of the neighboring directional modes 1085 // one of the neighboring directional modes
1074 if (cpi->sf.mode_search_skip_flags & FLAG_SKIP_INTRA_DIRMISMATCH) { 1086 if (cpi->sf.mode_search_skip_flags & FLAG_SKIP_INTRA_DIRMISMATCH) {
1075 if (conditional_skipintra(mode, *best_mode)) 1087 if (conditional_skipintra(mode, *best_mode))
1076 continue; 1088 continue;
1077 } 1089 }
1078 1090
1079 vpx_memcpy(tempa, ta, sizeof(ta)); 1091 vpx_memcpy(tempa, ta, sizeof(ta));
1080 vpx_memcpy(templ, tl, sizeof(tl)); 1092 vpx_memcpy(templ, tl, sizeof(tl));
1081 1093
1082 for (idy = 0; idy < num_4x4_blocks_high; ++idy) { 1094 for (idy = 0; idy < num_4x4_blocks_high; ++idy) {
1083 for (idx = 0; idx < num_4x4_blocks_wide; ++idx) { 1095 for (idx = 0; idx < num_4x4_blocks_wide; ++idx) {
1084 const int block = ib + idy * 2 + idx; 1096 const int block = ib + idy * 2 + idx;
1085 const uint8_t *const src = &src_init[idx * 4 + idy * 4 * src_stride]; 1097 const uint8_t *const src = &src_init[idx * 4 + idy * 4 * src_stride];
1086 uint8_t *const dst = &dst_init[idx * 4 + idy * 4 * dst_stride]; 1098 uint8_t *const dst = &dst_init[idx * 4 + idy * 4 * dst_stride];
1087 int16_t *const src_diff = raster_block_offset_int16(BLOCK_8X8, block, 1099 int16_t *const src_diff = raster_block_offset_int16(BLOCK_8X8, block,
1088 p->src_diff); 1100 p->src_diff);
1089 int16_t *const coeff = BLOCK_OFFSET(x->plane[0].coeff, block); 1101 int16_t *const coeff = BLOCK_OFFSET(x->plane[0].coeff, block);
1090 xd->mi_8x8[0]->bmi[block].as_mode = mode; 1102 xd->mi[0]->bmi[block].as_mode = mode;
1091 vp9_predict_intra_block(xd, block, 1, 1103 vp9_predict_intra_block(xd, block, 1,
1092 TX_4X4, mode, 1104 TX_4X4, mode,
1093 x->skip_encode ? src : dst, 1105 x->skip_encode ? src : dst,
1094 x->skip_encode ? src_stride : dst_stride, 1106 x->skip_encode ? src_stride : dst_stride,
1095 dst, dst_stride, idx, idy, 0); 1107 dst, dst_stride, idx, idy, 0);
1096 vp9_subtract_block(4, 4, src_diff, 8, src, src_stride, dst, dst_stride); 1108 vp9_subtract_block(4, 4, src_diff, 8, src, src_stride, dst, dst_stride);
1097 1109
1098 if (xd->lossless) { 1110 if (xd->lossless) {
1099 const scan_order *so = &vp9_default_scan_orders[TX_4X4]; 1111 const scan_order *so = &vp9_default_scan_orders[TX_4X4];
1100 vp9_fwht4x4(src_diff, coeff, 8); 1112 vp9_fwht4x4(src_diff, coeff, 8);
1101 vp9_regular_quantize_b_4x4(x, 0, block, so->scan, so->iscan); 1113 vp9_regular_quantize_b_4x4(x, 0, block, so->scan, so->iscan);
1102 ratey += cost_coeffs(x, 0, block, tempa + idx, templ + idy, TX_4X4, 1114 ratey += cost_coeffs(x, 0, block, tempa + idx, templ + idy, TX_4X4,
1103 so->scan, so->neighbors); 1115 so->scan, so->neighbors,
1116 cpi->sf.use_fast_coef_costing);
1104 if (RDCOST(x->rdmult, x->rddiv, ratey, distortion) >= best_rd) 1117 if (RDCOST(x->rdmult, x->rddiv, ratey, distortion) >= best_rd)
1105 goto next; 1118 goto next;
1106 vp9_iwht4x4_add(BLOCK_OFFSET(pd->dqcoeff, block), dst, dst_stride, 1119 vp9_iwht4x4_add(BLOCK_OFFSET(pd->dqcoeff, block), dst, dst_stride,
1107 p->eobs[block]); 1120 p->eobs[block]);
1108 } else { 1121 } else {
1109 int64_t unused; 1122 int64_t unused;
1110 const TX_TYPE tx_type = get_tx_type_4x4(PLANE_TYPE_Y, xd, block); 1123 const TX_TYPE tx_type = get_tx_type_4x4(PLANE_TYPE_Y, xd, block);
1111 const scan_order *so = &vp9_scan_orders[TX_4X4][tx_type]; 1124 const scan_order *so = &vp9_scan_orders[TX_4X4][tx_type];
1112 vp9_fht4x4(src_diff, coeff, 8, tx_type); 1125 vp9_fht4x4(src_diff, coeff, 8, tx_type);
1113 vp9_regular_quantize_b_4x4(x, 0, block, so->scan, so->iscan); 1126 vp9_regular_quantize_b_4x4(x, 0, block, so->scan, so->iscan);
1114 ratey += cost_coeffs(x, 0, block, tempa + idx, templ + idy, TX_4X4, 1127 ratey += cost_coeffs(x, 0, block, tempa + idx, templ + idy, TX_4X4,
1115 so->scan, so->neighbors); 1128 so->scan, so->neighbors,
1129 cpi->sf.use_fast_coef_costing);
1116 distortion += vp9_block_error(coeff, BLOCK_OFFSET(pd->dqcoeff, block), 1130 distortion += vp9_block_error(coeff, BLOCK_OFFSET(pd->dqcoeff, block),
1117 16, &unused) >> 2; 1131 16, &unused) >> 2;
1118 if (RDCOST(x->rdmult, x->rddiv, ratey, distortion) >= best_rd) 1132 if (RDCOST(x->rdmult, x->rddiv, ratey, distortion) >= best_rd)
1119 goto next; 1133 goto next;
1120 vp9_iht4x4_add(tx_type, BLOCK_OFFSET(pd->dqcoeff, block), 1134 vp9_iht4x4_add(tx_type, BLOCK_OFFSET(pd->dqcoeff, block),
1121 dst, dst_stride, p->eobs[block]); 1135 dst, dst_stride, p->eobs[block]);
1122 } 1136 }
1123 } 1137 }
1124 } 1138 }
1125 1139
(...skipping 19 matching lines...) Expand all
1145 if (best_rd >= rd_thresh || x->skip_encode) 1159 if (best_rd >= rd_thresh || x->skip_encode)
1146 return best_rd; 1160 return best_rd;
1147 1161
1148 for (idy = 0; idy < num_4x4_blocks_high * 4; ++idy) 1162 for (idy = 0; idy < num_4x4_blocks_high * 4; ++idy)
1149 vpx_memcpy(dst_init + idy * dst_stride, best_dst + idy * 8, 1163 vpx_memcpy(dst_init + idy * dst_stride, best_dst + idy * 8,
1150 num_4x4_blocks_wide * 4); 1164 num_4x4_blocks_wide * 4);
1151 1165
1152 return best_rd; 1166 return best_rd;
1153 } 1167 }
1154 1168
1155 static int64_t rd_pick_intra_sub_8x8_y_mode(VP9_COMP * const cpi, 1169 static int64_t rd_pick_intra_sub_8x8_y_mode(VP9_COMP *cpi, MACROBLOCK *mb,
1156 MACROBLOCK * const mb, 1170 int *rate, int *rate_y,
1157 int * const rate, 1171 int64_t *distortion,
1158 int * const rate_y,
1159 int64_t * const distortion,
1160 int64_t best_rd) { 1172 int64_t best_rd) {
1161 int i, j; 1173 int i, j;
1162 MACROBLOCKD *const xd = &mb->e_mbd; 1174 const MACROBLOCKD *const xd = &mb->e_mbd;
1163 MODE_INFO *const mic = xd->mi_8x8[0]; 1175 MODE_INFO *const mic = xd->mi[0];
1164 const MODE_INFO *above_mi = xd->mi_8x8[-xd->mode_info_stride]; 1176 const MODE_INFO *above_mi = xd->mi[-xd->mi_stride];
1165 const MODE_INFO *left_mi = xd->left_available ? xd->mi_8x8[-1] : NULL; 1177 const MODE_INFO *left_mi = xd->left_available ? xd->mi[-1] : NULL;
1166 const BLOCK_SIZE bsize = xd->mi_8x8[0]->mbmi.sb_type; 1178 const BLOCK_SIZE bsize = xd->mi[0]->mbmi.sb_type;
1167 const int num_4x4_blocks_wide = num_4x4_blocks_wide_lookup[bsize]; 1179 const int num_4x4_blocks_wide = num_4x4_blocks_wide_lookup[bsize];
1168 const int num_4x4_blocks_high = num_4x4_blocks_high_lookup[bsize]; 1180 const int num_4x4_blocks_high = num_4x4_blocks_high_lookup[bsize];
1169 int idx, idy; 1181 int idx, idy;
1170 int cost = 0; 1182 int cost = 0;
1171 int64_t total_distortion = 0; 1183 int64_t total_distortion = 0;
1172 int tot_rate_y = 0; 1184 int tot_rate_y = 0;
1173 int64_t total_rd = 0; 1185 int64_t total_rd = 0;
1174 ENTROPY_CONTEXT t_above[4], t_left[4]; 1186 ENTROPY_CONTEXT t_above[4], t_left[4];
1175 int *bmode_costs; 1187 const int *bmode_costs = mb->mbmode_cost;
1176 1188
1177 vpx_memcpy(t_above, xd->plane[0].above_context, sizeof(t_above)); 1189 vpx_memcpy(t_above, xd->plane[0].above_context, sizeof(t_above));
1178 vpx_memcpy(t_left, xd->plane[0].left_context, sizeof(t_left)); 1190 vpx_memcpy(t_left, xd->plane[0].left_context, sizeof(t_left));
1179 1191
1180 bmode_costs = mb->mbmode_cost;
1181
1182 // Pick modes for each sub-block (of size 4x4, 4x8, or 8x4) in an 8x8 block. 1192 // Pick modes for each sub-block (of size 4x4, 4x8, or 8x4) in an 8x8 block.
1183 for (idy = 0; idy < 2; idy += num_4x4_blocks_high) { 1193 for (idy = 0; idy < 2; idy += num_4x4_blocks_high) {
1184 for (idx = 0; idx < 2; idx += num_4x4_blocks_wide) { 1194 for (idx = 0; idx < 2; idx += num_4x4_blocks_wide) {
1185 MB_PREDICTION_MODE best_mode = DC_PRED; 1195 MB_PREDICTION_MODE best_mode = DC_PRED;
1186 int r = INT_MAX, ry = INT_MAX; 1196 int r = INT_MAX, ry = INT_MAX;
1187 int64_t d = INT64_MAX, this_rd = INT64_MAX; 1197 int64_t d = INT64_MAX, this_rd = INT64_MAX;
1188 i = idy * 2 + idx; 1198 i = idy * 2 + idx;
1189 if (cpi->common.frame_type == KEY_FRAME) { 1199 if (cpi->common.frame_type == KEY_FRAME) {
1190 const MB_PREDICTION_MODE A = vp9_above_block_mode(mic, above_mi, i); 1200 const MB_PREDICTION_MODE A = vp9_above_block_mode(mic, above_mi, i);
1191 const MB_PREDICTION_MODE L = vp9_left_block_mode(mic, left_mi, i); 1201 const MB_PREDICTION_MODE L = vp9_left_block_mode(mic, left_mi, i);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1225 1235
1226 static int64_t rd_pick_intra_sby_mode(VP9_COMP *cpi, MACROBLOCK *x, 1236 static int64_t rd_pick_intra_sby_mode(VP9_COMP *cpi, MACROBLOCK *x,
1227 int *rate, int *rate_tokenonly, 1237 int *rate, int *rate_tokenonly,
1228 int64_t *distortion, int *skippable, 1238 int64_t *distortion, int *skippable,
1229 BLOCK_SIZE bsize, 1239 BLOCK_SIZE bsize,
1230 int64_t tx_cache[TX_MODES], 1240 int64_t tx_cache[TX_MODES],
1231 int64_t best_rd) { 1241 int64_t best_rd) {
1232 MB_PREDICTION_MODE mode; 1242 MB_PREDICTION_MODE mode;
1233 MB_PREDICTION_MODE mode_selected = DC_PRED; 1243 MB_PREDICTION_MODE mode_selected = DC_PRED;
1234 MACROBLOCKD *const xd = &x->e_mbd; 1244 MACROBLOCKD *const xd = &x->e_mbd;
1235 MODE_INFO *const mic = xd->mi_8x8[0]; 1245 MODE_INFO *const mic = xd->mi[0];
1236 int this_rate, this_rate_tokenonly, s; 1246 int this_rate, this_rate_tokenonly, s;
1237 int64_t this_distortion, this_rd; 1247 int64_t this_distortion, this_rd;
1238 TX_SIZE best_tx = TX_4X4; 1248 TX_SIZE best_tx = TX_4X4;
1239 int i; 1249 int i;
1240 int *bmode_costs = x->mbmode_cost; 1250 int *bmode_costs = x->mbmode_cost;
1241 1251
1242 if (cpi->sf.tx_size_search_method == USE_FULL_RD) 1252 if (cpi->sf.tx_size_search_method == USE_FULL_RD)
1243 for (i = 0; i < TX_MODES; i++) 1253 for (i = 0; i < TX_MODES; i++)
1244 tx_cache[i] = INT64_MAX; 1254 tx_cache[i] = INT64_MAX;
1245 1255
1246 /* Y Search for intra prediction mode */ 1256 /* Y Search for intra prediction mode */
1247 for (mode = DC_PRED; mode <= TM_PRED; mode++) { 1257 for (mode = DC_PRED; mode <= TM_PRED; mode++) {
1248 int64_t local_tx_cache[TX_MODES]; 1258 int64_t local_tx_cache[TX_MODES];
1249 MODE_INFO *above_mi = xd->mi_8x8[-xd->mode_info_stride]; 1259 MODE_INFO *above_mi = xd->mi[-xd->mi_stride];
1250 MODE_INFO *left_mi = xd->left_available ? xd->mi_8x8[-1] : NULL; 1260 MODE_INFO *left_mi = xd->left_available ? xd->mi[-1] : NULL;
1251 1261
1252 if (!(cpi->sf.intra_y_mode_mask[max_txsize_lookup[bsize]] & (1 << mode))) 1262 if (!(cpi->sf.intra_y_mode_mask[max_txsize_lookup[bsize]] & (1 << mode)))
1253 continue; 1263 continue;
1254 1264
1255 if (cpi->common.frame_type == KEY_FRAME) { 1265 if (cpi->common.frame_type == KEY_FRAME) {
1256 const MB_PREDICTION_MODE A = vp9_above_block_mode(mic, above_mi, 0); 1266 const MB_PREDICTION_MODE A = vp9_above_block_mode(mic, above_mi, 0);
1257 const MB_PREDICTION_MODE L = vp9_left_block_mode(mic, left_mi, 0); 1267 const MB_PREDICTION_MODE L = vp9_left_block_mode(mic, left_mi, 0);
1258 1268
1259 bmode_costs = x->y_mode_costs[A][L]; 1269 bmode_costs = x->y_mode_costs[A][L];
1260 } 1270 }
(...skipping 28 matching lines...) Expand all
1289 } 1299 }
1290 } 1300 }
1291 } 1301 }
1292 1302
1293 mic->mbmi.mode = mode_selected; 1303 mic->mbmi.mode = mode_selected;
1294 mic->mbmi.tx_size = best_tx; 1304 mic->mbmi.tx_size = best_tx;
1295 1305
1296 return best_rd; 1306 return best_rd;
1297 } 1307 }
1298 1308
1299 static void super_block_uvrd(MACROBLOCK *x, 1309 static void super_block_uvrd(const VP9_COMP *cpi, MACROBLOCK *x,
1300 int *rate, int64_t *distortion, int *skippable, 1310 int *rate, int64_t *distortion, int *skippable,
1301 int64_t *sse, BLOCK_SIZE bsize, 1311 int64_t *sse, BLOCK_SIZE bsize,
1302 int64_t ref_best_rd) { 1312 int64_t ref_best_rd) {
1303 MACROBLOCKD *const xd = &x->e_mbd; 1313 MACROBLOCKD *const xd = &x->e_mbd;
1304 MB_MODE_INFO *const mbmi = &xd->mi_8x8[0]->mbmi; 1314 MB_MODE_INFO *const mbmi = &xd->mi[0]->mbmi;
1305 TX_SIZE uv_txfm_size = get_uv_tx_size(mbmi); 1315 TX_SIZE uv_txfm_size = get_uv_tx_size(mbmi);
1306 int plane; 1316 int plane;
1307 int pnrate = 0, pnskip = 1; 1317 int pnrate = 0, pnskip = 1;
1308 int64_t pndist = 0, pnsse = 0; 1318 int64_t pndist = 0, pnsse = 0;
1309 1319
1310 if (ref_best_rd < 0) 1320 if (ref_best_rd < 0)
1311 goto term; 1321 goto term;
1312 1322
1313 if (is_inter_block(mbmi)) { 1323 if (is_inter_block(mbmi)) {
1314 int plane; 1324 int plane;
1315 for (plane = 1; plane < MAX_MB_PLANE; ++plane) 1325 for (plane = 1; plane < MAX_MB_PLANE; ++plane)
1316 vp9_subtract_plane(x, bsize, plane); 1326 vp9_subtract_plane(x, bsize, plane);
1317 } 1327 }
1318 1328
1319 *rate = 0; 1329 *rate = 0;
1320 *distortion = 0; 1330 *distortion = 0;
1321 *sse = 0; 1331 *sse = 0;
1322 *skippable = 1; 1332 *skippable = 1;
1323 1333
1324 for (plane = 1; plane < MAX_MB_PLANE; ++plane) { 1334 for (plane = 1; plane < MAX_MB_PLANE; ++plane) {
1325 txfm_rd_in_plane(x, &pnrate, &pndist, &pnskip, &pnsse, 1335 txfm_rd_in_plane(x, &pnrate, &pndist, &pnskip, &pnsse,
1326 ref_best_rd, plane, bsize, uv_txfm_size); 1336 ref_best_rd, plane, bsize, uv_txfm_size,
1337 cpi->sf.use_fast_coef_costing);
1327 if (pnrate == INT_MAX) 1338 if (pnrate == INT_MAX)
1328 goto term; 1339 goto term;
1329 *rate += pnrate; 1340 *rate += pnrate;
1330 *distortion += pndist; 1341 *distortion += pndist;
1331 *sse += pnsse; 1342 *sse += pnsse;
1332 *skippable &= pnskip; 1343 *skippable &= pnskip;
1333 } 1344 }
1334 return; 1345 return;
1335 1346
1336 term: 1347 term:
(...skipping 13 matching lines...) Expand all
1350 MB_PREDICTION_MODE mode; 1361 MB_PREDICTION_MODE mode;
1351 MB_PREDICTION_MODE mode_selected = DC_PRED; 1362 MB_PREDICTION_MODE mode_selected = DC_PRED;
1352 int64_t best_rd = INT64_MAX, this_rd; 1363 int64_t best_rd = INT64_MAX, this_rd;
1353 int this_rate_tokenonly, this_rate, s; 1364 int this_rate_tokenonly, this_rate, s;
1354 int64_t this_distortion, this_sse; 1365 int64_t this_distortion, this_sse;
1355 1366
1356 for (mode = DC_PRED; mode <= TM_PRED; ++mode) { 1367 for (mode = DC_PRED; mode <= TM_PRED; ++mode) {
1357 if (!(cpi->sf.intra_uv_mode_mask[max_tx_size] & (1 << mode))) 1368 if (!(cpi->sf.intra_uv_mode_mask[max_tx_size] & (1 << mode)))
1358 continue; 1369 continue;
1359 1370
1360 xd->mi_8x8[0]->mbmi.uv_mode = mode; 1371 xd->mi[0]->mbmi.uv_mode = mode;
1361 1372
1362 super_block_uvrd(x, &this_rate_tokenonly, 1373 super_block_uvrd(cpi, x, &this_rate_tokenonly,
1363 &this_distortion, &s, &this_sse, bsize, best_rd); 1374 &this_distortion, &s, &this_sse, bsize, best_rd);
1364 if (this_rate_tokenonly == INT_MAX) 1375 if (this_rate_tokenonly == INT_MAX)
1365 continue; 1376 continue;
1366 this_rate = this_rate_tokenonly + 1377 this_rate = this_rate_tokenonly +
1367 x->intra_uv_mode_cost[cpi->common.frame_type][mode]; 1378 x->intra_uv_mode_cost[cpi->common.frame_type][mode];
1368 this_rd = RDCOST(x->rdmult, x->rddiv, this_rate, this_distortion); 1379 this_rd = RDCOST(x->rdmult, x->rddiv, this_rate, this_distortion);
1369 1380
1370 if (this_rd < best_rd) { 1381 if (this_rd < best_rd) {
1371 mode_selected = mode; 1382 mode_selected = mode;
1372 best_rd = this_rd; 1383 best_rd = this_rd;
(...skipping 18 matching lines...) Expand all
1391 1402
1392 ctx->coeff_pbuf[i][0] = p[i].coeff; 1403 ctx->coeff_pbuf[i][0] = p[i].coeff;
1393 ctx->qcoeff_pbuf[i][0] = p[i].qcoeff; 1404 ctx->qcoeff_pbuf[i][0] = p[i].qcoeff;
1394 ctx->dqcoeff_pbuf[i][0] = pd[i].dqcoeff; 1405 ctx->dqcoeff_pbuf[i][0] = pd[i].dqcoeff;
1395 ctx->eobs_pbuf[i][0] = p[i].eobs; 1406 ctx->eobs_pbuf[i][0] = p[i].eobs;
1396 } 1407 }
1397 } 1408 }
1398 } 1409 }
1399 } 1410 }
1400 1411
1401 xd->mi_8x8[0]->mbmi.uv_mode = mode_selected; 1412 xd->mi[0]->mbmi.uv_mode = mode_selected;
1402 return best_rd; 1413 return best_rd;
1403 } 1414 }
1404 1415
1405 static int64_t rd_sbuv_dcpred(const VP9_COMMON *cm, MACROBLOCK *x, 1416 static int64_t rd_sbuv_dcpred(const VP9_COMP *cpi, MACROBLOCK *x,
1406 int *rate, int *rate_tokenonly, 1417 int *rate, int *rate_tokenonly,
1407 int64_t *distortion, int *skippable, 1418 int64_t *distortion, int *skippable,
1408 BLOCK_SIZE bsize) { 1419 BLOCK_SIZE bsize) {
1420 const VP9_COMMON *cm = &cpi->common;
1409 int64_t unused; 1421 int64_t unused;
1410 1422
1411 x->e_mbd.mi_8x8[0]->mbmi.uv_mode = DC_PRED; 1423 x->e_mbd.mi[0]->mbmi.uv_mode = DC_PRED;
1412 super_block_uvrd(x, rate_tokenonly, distortion, 1424 super_block_uvrd(cpi, x, rate_tokenonly, distortion,
1413 skippable, &unused, bsize, INT64_MAX); 1425 skippable, &unused, bsize, INT64_MAX);
1414 *rate = *rate_tokenonly + x->intra_uv_mode_cost[cm->frame_type][DC_PRED]; 1426 *rate = *rate_tokenonly + x->intra_uv_mode_cost[cm->frame_type][DC_PRED];
1415 return RDCOST(x->rdmult, x->rddiv, *rate, *distortion); 1427 return RDCOST(x->rdmult, x->rddiv, *rate, *distortion);
1416 } 1428 }
1417 1429
1418 static void choose_intra_uv_mode(VP9_COMP *cpi, PICK_MODE_CONTEXT *ctx, 1430 static void choose_intra_uv_mode(VP9_COMP *cpi, PICK_MODE_CONTEXT *ctx,
1419 BLOCK_SIZE bsize, TX_SIZE max_tx_size, 1431 BLOCK_SIZE bsize, TX_SIZE max_tx_size,
1420 int *rate_uv, int *rate_uv_tokenonly, 1432 int *rate_uv, int *rate_uv_tokenonly,
1421 int64_t *dist_uv, int *skip_uv, 1433 int64_t *dist_uv, int *skip_uv,
1422 MB_PREDICTION_MODE *mode_uv) { 1434 MB_PREDICTION_MODE *mode_uv) {
1423 MACROBLOCK *const x = &cpi->mb; 1435 MACROBLOCK *const x = &cpi->mb;
1424 1436
1425 // Use an estimated rd for uv_intra based on DC_PRED if the 1437 // Use an estimated rd for uv_intra based on DC_PRED if the
1426 // appropriate speed flag is set. 1438 // appropriate speed flag is set.
1427 if (cpi->sf.use_uv_intra_rd_estimate) { 1439 if (cpi->sf.use_uv_intra_rd_estimate) {
1428 rd_sbuv_dcpred(&cpi->common, x, rate_uv, rate_uv_tokenonly, dist_uv, 1440 rd_sbuv_dcpred(cpi, x, rate_uv, rate_uv_tokenonly, dist_uv,
1429 skip_uv, bsize < BLOCK_8X8 ? BLOCK_8X8 : bsize); 1441 skip_uv, bsize < BLOCK_8X8 ? BLOCK_8X8 : bsize);
1430 // Else do a proper rd search for each possible transform size that may 1442 // Else do a proper rd search for each possible transform size that may
1431 // be considered in the main rd loop. 1443 // be considered in the main rd loop.
1432 } else { 1444 } else {
1433 rd_pick_intra_sbuv_mode(cpi, x, ctx, 1445 rd_pick_intra_sbuv_mode(cpi, x, ctx,
1434 rate_uv, rate_uv_tokenonly, dist_uv, skip_uv, 1446 rate_uv, rate_uv_tokenonly, dist_uv, skip_uv,
1435 bsize < BLOCK_8X8 ? BLOCK_8X8 : bsize, max_tx_size); 1447 bsize < BLOCK_8X8 ? BLOCK_8X8 : bsize, max_tx_size);
1436 } 1448 }
1437 *mode_uv = x->e_mbd.mi_8x8[0]->mbmi.uv_mode; 1449 *mode_uv = x->e_mbd.mi[0]->mbmi.uv_mode;
1438 } 1450 }
1439 1451
1440 static int cost_mv_ref(VP9_COMP *cpi, MB_PREDICTION_MODE mode, 1452 static int cost_mv_ref(const VP9_COMP *cpi, MB_PREDICTION_MODE mode,
1441 int mode_context) { 1453 int mode_context) {
1442 MACROBLOCK *const x = &cpi->mb; 1454 const MACROBLOCK *const x = &cpi->mb;
1443 const int segment_id = x->e_mbd.mi_8x8[0]->mbmi.segment_id; 1455 const int segment_id = x->e_mbd.mi[0]->mbmi.segment_id;
1444 1456
1445 // Don't account for mode here if segment skip is enabled. 1457 // Don't account for mode here if segment skip is enabled.
1446 if (!vp9_segfeature_active(&cpi->common.seg, segment_id, SEG_LVL_SKIP)) { 1458 if (!vp9_segfeature_active(&cpi->common.seg, segment_id, SEG_LVL_SKIP)) {
1447 assert(is_inter_mode(mode)); 1459 assert(is_inter_mode(mode));
1448 return x->inter_mode_cost[mode_context][INTER_OFFSET(mode)]; 1460 return x->inter_mode_cost[mode_context][INTER_OFFSET(mode)];
1449 } else { 1461 } else {
1450 return 0; 1462 return 0;
1451 } 1463 }
1452 } 1464 }
1453 1465
1454 void vp9_set_mbmode_and_mvs(MACROBLOCKD *xd, MB_PREDICTION_MODE mode,
1455 const MV *mv) {
1456 xd->mi_8x8[0]->mbmi.mode = mode;
1457 xd->mi_8x8[0]->mbmi.mv[0].as_mv = *mv;
1458 }
1459
1460 static void joint_motion_search(VP9_COMP *cpi, MACROBLOCK *x, 1466 static void joint_motion_search(VP9_COMP *cpi, MACROBLOCK *x,
1461 BLOCK_SIZE bsize, 1467 BLOCK_SIZE bsize,
1462 int_mv *frame_mv, 1468 int_mv *frame_mv,
1463 int mi_row, int mi_col, 1469 int mi_row, int mi_col,
1464 int_mv single_newmv[MAX_REF_FRAMES], 1470 int_mv single_newmv[MAX_REF_FRAMES],
1465 int *rate_mv); 1471 int *rate_mv);
1466 1472
1467 static int labels2mode(MACROBLOCK *x, int i, 1473 static int labels2mode(VP9_COMP *cpi, MACROBLOCKD *xd, int i,
1468 MB_PREDICTION_MODE mode, 1474 MB_PREDICTION_MODE mode,
1469 int_mv *this_mv, int_mv *this_second_mv, 1475 int_mv this_mv[2],
1470 int_mv frame_mv[MB_MODE_COUNT][MAX_REF_FRAMES], 1476 int_mv frame_mv[MB_MODE_COUNT][MAX_REF_FRAMES],
1471 int_mv seg_mvs[MAX_REF_FRAMES], 1477 int_mv seg_mvs[MAX_REF_FRAMES],
1472 int_mv *best_ref_mv, 1478 int_mv *best_ref_mv[2],
1473 int_mv *second_best_ref_mv, 1479 const int *mvjcost, int *mvcost[2]) {
1474 int *mvjcost, int *mvcost[2], VP9_COMP *cpi) { 1480 MODE_INFO *const mic = xd->mi[0];
1475 MACROBLOCKD *const xd = &x->e_mbd; 1481 const MB_MODE_INFO *const mbmi = &mic->mbmi;
1476 MODE_INFO *const mic = xd->mi_8x8[0];
1477 MB_MODE_INFO *mbmi = &mic->mbmi;
1478 int thismvcost = 0; 1482 int thismvcost = 0;
1479 int idx, idy; 1483 int idx, idy;
1480 const int num_4x4_blocks_wide = num_4x4_blocks_wide_lookup[mbmi->sb_type]; 1484 const int num_4x4_blocks_wide = num_4x4_blocks_wide_lookup[mbmi->sb_type];
1481 const int num_4x4_blocks_high = num_4x4_blocks_high_lookup[mbmi->sb_type]; 1485 const int num_4x4_blocks_high = num_4x4_blocks_high_lookup[mbmi->sb_type];
1482 const int has_second_rf = has_second_ref(mbmi); 1486 const int is_compound = has_second_ref(mbmi);
1483 1487
1484 // the only time we should do costing for new motion vector or mode 1488 // the only time we should do costing for new motion vector or mode
1485 // is when we are on a new label (jbb May 08, 2007) 1489 // is when we are on a new label (jbb May 08, 2007)
1486 switch (mode) { 1490 switch (mode) {
1487 case NEWMV: 1491 case NEWMV:
1488 this_mv->as_int = seg_mvs[mbmi->ref_frame[0]].as_int; 1492 this_mv[0].as_int = seg_mvs[mbmi->ref_frame[0]].as_int;
1489 thismvcost += vp9_mv_bit_cost(&this_mv->as_mv, &best_ref_mv->as_mv, 1493 thismvcost += vp9_mv_bit_cost(&this_mv[0].as_mv, &best_ref_mv[0]->as_mv,
1490 mvjcost, mvcost, MV_COST_WEIGHT_SUB); 1494 mvjcost, mvcost, MV_COST_WEIGHT_SUB);
1491 if (has_second_rf) { 1495 if (is_compound) {
1492 this_second_mv->as_int = seg_mvs[mbmi->ref_frame[1]].as_int; 1496 this_mv[1].as_int = seg_mvs[mbmi->ref_frame[1]].as_int;
1493 thismvcost += vp9_mv_bit_cost(&this_second_mv->as_mv, 1497 thismvcost += vp9_mv_bit_cost(&this_mv[1].as_mv, &best_ref_mv[1]->as_mv,
1494 &second_best_ref_mv->as_mv,
1495 mvjcost, mvcost, MV_COST_WEIGHT_SUB); 1498 mvjcost, mvcost, MV_COST_WEIGHT_SUB);
1496 } 1499 }
1497 break; 1500 break;
1498 case NEARESTMV: 1501 case NEARESTMV:
1499 this_mv->as_int = frame_mv[NEARESTMV][mbmi->ref_frame[0]].as_int; 1502 this_mv[0].as_int = frame_mv[NEARESTMV][mbmi->ref_frame[0]].as_int;
1500 if (has_second_rf) 1503 if (is_compound)
1501 this_second_mv->as_int = frame_mv[NEARESTMV][mbmi->ref_frame[1]].as_int; 1504 this_mv[1].as_int = frame_mv[NEARESTMV][mbmi->ref_frame[1]].as_int;
1502 break; 1505 break;
1503 case NEARMV: 1506 case NEARMV:
1504 this_mv->as_int = frame_mv[NEARMV][mbmi->ref_frame[0]].as_int; 1507 this_mv[0].as_int = frame_mv[NEARMV][mbmi->ref_frame[0]].as_int;
1505 if (has_second_rf) 1508 if (is_compound)
1506 this_second_mv->as_int = frame_mv[NEARMV][mbmi->ref_frame[1]].as_int; 1509 this_mv[1].as_int = frame_mv[NEARMV][mbmi->ref_frame[1]].as_int;
1507 break; 1510 break;
1508 case ZEROMV: 1511 case ZEROMV:
1509 this_mv->as_int = 0; 1512 this_mv[0].as_int = 0;
1510 if (has_second_rf) 1513 if (is_compound)
1511 this_second_mv->as_int = 0; 1514 this_mv[1].as_int = 0;
1512 break; 1515 break;
1513 default: 1516 default:
1514 break; 1517 break;
1515 } 1518 }
1516 1519
1517 mic->bmi[i].as_mv[0].as_int = this_mv->as_int; 1520 mic->bmi[i].as_mv[0].as_int = this_mv[0].as_int;
1518 if (has_second_rf) 1521 if (is_compound)
1519 mic->bmi[i].as_mv[1].as_int = this_second_mv->as_int; 1522 mic->bmi[i].as_mv[1].as_int = this_mv[1].as_int;
1520 1523
1521 mic->bmi[i].as_mode = mode; 1524 mic->bmi[i].as_mode = mode;
1522 1525
1523 for (idy = 0; idy < num_4x4_blocks_high; ++idy) 1526 for (idy = 0; idy < num_4x4_blocks_high; ++idy)
1524 for (idx = 0; idx < num_4x4_blocks_wide; ++idx) 1527 for (idx = 0; idx < num_4x4_blocks_wide; ++idx)
1525 vpx_memcpy(&mic->bmi[i + idy * 2 + idx], 1528 vpx_memcpy(&mic->bmi[i + idy * 2 + idx],
1526 &mic->bmi[i], sizeof(mic->bmi[i])); 1529 &mic->bmi[i], sizeof(mic->bmi[i]));
1527 1530
1528 return cost_mv_ref(cpi, mode, mbmi->mode_context[mbmi->ref_frame[0]]) + 1531 return cost_mv_ref(cpi, mode, mbmi->mode_context[mbmi->ref_frame[0]]) +
1529 thismvcost; 1532 thismvcost;
1530 } 1533 }
1531 1534
1532 static int64_t encode_inter_mb_segment(VP9_COMP *cpi, 1535 static int64_t encode_inter_mb_segment(VP9_COMP *cpi,
1533 MACROBLOCK *x, 1536 MACROBLOCK *x,
1534 int64_t best_yrd, 1537 int64_t best_yrd,
1535 int i, 1538 int i,
1536 int *labelyrate, 1539 int *labelyrate,
1537 int64_t *distortion, int64_t *sse, 1540 int64_t *distortion, int64_t *sse,
1538 ENTROPY_CONTEXT *ta, 1541 ENTROPY_CONTEXT *ta,
1539 ENTROPY_CONTEXT *tl, 1542 ENTROPY_CONTEXT *tl,
1540 int mi_row, int mi_col) { 1543 int mi_row, int mi_col) {
1541 int k; 1544 int k;
1542 MACROBLOCKD *xd = &x->e_mbd; 1545 MACROBLOCKD *xd = &x->e_mbd;
1543 struct macroblockd_plane *const pd = &xd->plane[0]; 1546 struct macroblockd_plane *const pd = &xd->plane[0];
1544 struct macroblock_plane *const p = &x->plane[0]; 1547 struct macroblock_plane *const p = &x->plane[0];
1545 MODE_INFO *const mi = xd->mi_8x8[0]; 1548 MODE_INFO *const mi = xd->mi[0];
1546 const BLOCK_SIZE plane_bsize = get_plane_block_size(mi->mbmi.sb_type, pd); 1549 const BLOCK_SIZE plane_bsize = get_plane_block_size(mi->mbmi.sb_type, pd);
1547 const int width = 4 * num_4x4_blocks_wide_lookup[plane_bsize]; 1550 const int width = 4 * num_4x4_blocks_wide_lookup[plane_bsize];
1548 const int height = 4 * num_4x4_blocks_high_lookup[plane_bsize]; 1551 const int height = 4 * num_4x4_blocks_high_lookup[plane_bsize];
1549 int idx, idy; 1552 int idx, idy;
1550 1553
1551 const uint8_t *const src = &p->src.buf[raster_block_offset(BLOCK_8X8, i, 1554 const uint8_t *const src = &p->src.buf[raster_block_offset(BLOCK_8X8, i,
1552 p->src.stride)]; 1555 p->src.stride)];
1553 uint8_t *const dst = &pd->dst.buf[raster_block_offset(BLOCK_8X8, i, 1556 uint8_t *const dst = &pd->dst.buf[raster_block_offset(BLOCK_8X8, i,
1554 pd->dst.stride)]; 1557 pd->dst.stride)];
1555 int64_t thisdistortion = 0, thissse = 0; 1558 int64_t thisdistortion = 0, thissse = 0;
1556 int thisrate = 0, ref; 1559 int thisrate = 0, ref;
1557 const scan_order *so = &vp9_default_scan_orders[TX_4X4]; 1560 const scan_order *so = &vp9_default_scan_orders[TX_4X4];
1558 const int is_compound = has_second_ref(&mi->mbmi); 1561 const int is_compound = has_second_ref(&mi->mbmi);
1562 const InterpKernel *kernel = vp9_get_interp_kernel(mi->mbmi.interp_filter);
1563
1559 for (ref = 0; ref < 1 + is_compound; ++ref) { 1564 for (ref = 0; ref < 1 + is_compound; ++ref) {
1560 const uint8_t *pre = &pd->pre[ref].buf[raster_block_offset(BLOCK_8X8, i, 1565 const uint8_t *pre = &pd->pre[ref].buf[raster_block_offset(BLOCK_8X8, i,
1561 pd->pre[ref].stride)]; 1566 pd->pre[ref].stride)];
1562 vp9_build_inter_predictor(pre, pd->pre[ref].stride, 1567 vp9_build_inter_predictor(pre, pd->pre[ref].stride,
1563 dst, pd->dst.stride, 1568 dst, pd->dst.stride,
1564 &mi->bmi[i].as_mv[ref].as_mv, 1569 &mi->bmi[i].as_mv[ref].as_mv,
1565 &xd->block_refs[ref]->sf, width, height, ref, 1570 &xd->block_refs[ref]->sf, width, height, ref,
1566 xd->interp_kernel, MV_PRECISION_Q3, 1571 kernel, MV_PRECISION_Q3,
1567 mi_col * MI_SIZE + 4 * (i % 2), 1572 mi_col * MI_SIZE + 4 * (i % 2),
1568 mi_row * MI_SIZE + 4 * (i / 2)); 1573 mi_row * MI_SIZE + 4 * (i / 2));
1569 } 1574 }
1570 1575
1571 vp9_subtract_block(height, width, 1576 vp9_subtract_block(height, width,
1572 raster_block_offset_int16(BLOCK_8X8, i, p->src_diff), 8, 1577 raster_block_offset_int16(BLOCK_8X8, i, p->src_diff), 8,
1573 src, p->src.stride, 1578 src, p->src.stride,
1574 dst, pd->dst.stride); 1579 dst, pd->dst.stride);
1575 1580
1576 k = i; 1581 k = i;
1577 for (idy = 0; idy < height / 4; ++idy) { 1582 for (idy = 0; idy < height / 4; ++idy) {
1578 for (idx = 0; idx < width / 4; ++idx) { 1583 for (idx = 0; idx < width / 4; ++idx) {
1579 int64_t ssz, rd, rd1, rd2; 1584 int64_t ssz, rd, rd1, rd2;
1580 int16_t* coeff; 1585 int16_t* coeff;
1581 1586
1582 k += (idy * 2 + idx); 1587 k += (idy * 2 + idx);
1583 coeff = BLOCK_OFFSET(p->coeff, k); 1588 coeff = BLOCK_OFFSET(p->coeff, k);
1584 x->fwd_txm4x4(raster_block_offset_int16(BLOCK_8X8, k, p->src_diff), 1589 x->fwd_txm4x4(raster_block_offset_int16(BLOCK_8X8, k, p->src_diff),
1585 coeff, 8); 1590 coeff, 8);
1586 vp9_regular_quantize_b_4x4(x, 0, k, so->scan, so->iscan); 1591 vp9_regular_quantize_b_4x4(x, 0, k, so->scan, so->iscan);
1587 thisdistortion += vp9_block_error(coeff, BLOCK_OFFSET(pd->dqcoeff, k), 1592 thisdistortion += vp9_block_error(coeff, BLOCK_OFFSET(pd->dqcoeff, k),
1588 16, &ssz); 1593 16, &ssz);
1589 thissse += ssz; 1594 thissse += ssz;
1590 thisrate += cost_coeffs(x, 0, k, ta + (k & 1), tl + (k >> 1), TX_4X4, 1595 thisrate += cost_coeffs(x, 0, k, ta + (k & 1), tl + (k >> 1), TX_4X4,
1591 so->scan, so->neighbors); 1596 so->scan, so->neighbors,
1597 cpi->sf.use_fast_coef_costing);
1592 rd1 = RDCOST(x->rdmult, x->rddiv, thisrate, thisdistortion >> 2); 1598 rd1 = RDCOST(x->rdmult, x->rddiv, thisrate, thisdistortion >> 2);
1593 rd2 = RDCOST(x->rdmult, x->rddiv, 0, thissse >> 2); 1599 rd2 = RDCOST(x->rdmult, x->rddiv, 0, thissse >> 2);
1594 rd = MIN(rd1, rd2); 1600 rd = MIN(rd1, rd2);
1595 if (rd >= best_yrd) 1601 if (rd >= best_yrd)
1596 return INT64_MAX; 1602 return INT64_MAX;
1597 } 1603 }
1598 } 1604 }
1599 1605
1600 *distortion = thisdistortion >> 2; 1606 *distortion = thisdistortion >> 2;
1601 *labelyrate = thisrate; 1607 *labelyrate = thisrate;
(...skipping 29 matching lines...) Expand all
1631 } BEST_SEG_INFO; 1637 } BEST_SEG_INFO;
1632 1638
1633 static INLINE int mv_check_bounds(const MACROBLOCK *x, const MV *mv) { 1639 static INLINE int mv_check_bounds(const MACROBLOCK *x, const MV *mv) {
1634 return (mv->row >> 3) < x->mv_row_min || 1640 return (mv->row >> 3) < x->mv_row_min ||
1635 (mv->row >> 3) > x->mv_row_max || 1641 (mv->row >> 3) > x->mv_row_max ||
1636 (mv->col >> 3) < x->mv_col_min || 1642 (mv->col >> 3) < x->mv_col_min ||
1637 (mv->col >> 3) > x->mv_col_max; 1643 (mv->col >> 3) > x->mv_col_max;
1638 } 1644 }
1639 1645
1640 static INLINE void mi_buf_shift(MACROBLOCK *x, int i) { 1646 static INLINE void mi_buf_shift(MACROBLOCK *x, int i) {
1641 MB_MODE_INFO *const mbmi = &x->e_mbd.mi_8x8[0]->mbmi; 1647 MB_MODE_INFO *const mbmi = &x->e_mbd.mi[0]->mbmi;
1642 struct macroblock_plane *const p = &x->plane[0]; 1648 struct macroblock_plane *const p = &x->plane[0];
1643 struct macroblockd_plane *const pd = &x->e_mbd.plane[0]; 1649 struct macroblockd_plane *const pd = &x->e_mbd.plane[0];
1644 1650
1645 p->src.buf = &p->src.buf[raster_block_offset(BLOCK_8X8, i, p->src.stride)]; 1651 p->src.buf = &p->src.buf[raster_block_offset(BLOCK_8X8, i, p->src.stride)];
1646 assert(((intptr_t)pd->pre[0].buf & 0x7) == 0); 1652 assert(((intptr_t)pd->pre[0].buf & 0x7) == 0);
1647 pd->pre[0].buf = &pd->pre[0].buf[raster_block_offset(BLOCK_8X8, i, 1653 pd->pre[0].buf = &pd->pre[0].buf[raster_block_offset(BLOCK_8X8, i,
1648 pd->pre[0].stride)]; 1654 pd->pre[0].stride)];
1649 if (has_second_ref(mbmi)) 1655 if (has_second_ref(mbmi))
1650 pd->pre[1].buf = &pd->pre[1].buf[raster_block_offset(BLOCK_8X8, i, 1656 pd->pre[1].buf = &pd->pre[1].buf[raster_block_offset(BLOCK_8X8, i,
1651 pd->pre[1].stride)]; 1657 pd->pre[1].stride)];
1652 } 1658 }
1653 1659
1654 static INLINE void mi_buf_restore(MACROBLOCK *x, struct buf_2d orig_src, 1660 static INLINE void mi_buf_restore(MACROBLOCK *x, struct buf_2d orig_src,
1655 struct buf_2d orig_pre[2]) { 1661 struct buf_2d orig_pre[2]) {
1656 MB_MODE_INFO *mbmi = &x->e_mbd.mi_8x8[0]->mbmi; 1662 MB_MODE_INFO *mbmi = &x->e_mbd.mi[0]->mbmi;
1657 x->plane[0].src = orig_src; 1663 x->plane[0].src = orig_src;
1658 x->e_mbd.plane[0].pre[0] = orig_pre[0]; 1664 x->e_mbd.plane[0].pre[0] = orig_pre[0];
1659 if (has_second_ref(mbmi)) 1665 if (has_second_ref(mbmi))
1660 x->e_mbd.plane[0].pre[1] = orig_pre[1]; 1666 x->e_mbd.plane[0].pre[1] = orig_pre[1];
1661 } 1667 }
1662 1668
1663 static INLINE int mv_has_subpel(const MV *mv) { 1669 static INLINE int mv_has_subpel(const MV *mv) {
1664 return (mv->row & 0x0F) || (mv->col & 0x0F); 1670 return (mv->row & 0x0F) || (mv->col & 0x0F);
1665 } 1671 }
1666 1672
1673 // Check if NEARESTMV/NEARMV/ZEROMV is the cheapest way encode zero motion.
1674 // TODO(aconverse): Find out if this is still productive then clean up or remove
1675 static int check_best_zero_mv(
1676 const VP9_COMP *cpi, const uint8_t mode_context[MAX_REF_FRAMES],
1677 int_mv frame_mv[MB_MODE_COUNT][MAX_REF_FRAMES],
1678 int disable_inter_mode_mask, int this_mode, int ref_frame,
1679 int second_ref_frame) {
1680 if (!(disable_inter_mode_mask & (1 << INTER_OFFSET(ZEROMV))) &&
1681 (this_mode == NEARMV || this_mode == NEARESTMV || this_mode == ZEROMV) &&
1682 frame_mv[this_mode][ref_frame].as_int == 0 &&
1683 (second_ref_frame == NONE ||
1684 frame_mv[this_mode][second_ref_frame].as_int == 0)) {
1685 int rfc = mode_context[ref_frame];
1686 int c1 = cost_mv_ref(cpi, NEARMV, rfc);
1687 int c2 = cost_mv_ref(cpi, NEARESTMV, rfc);
1688 int c3 = cost_mv_ref(cpi, ZEROMV, rfc);
1689
1690 if (this_mode == NEARMV) {
1691 if (c1 > c3) return 0;
1692 } else if (this_mode == NEARESTMV) {
1693 if (c2 > c3) return 0;
1694 } else {
1695 assert(this_mode == ZEROMV);
1696 if (second_ref_frame == NONE) {
1697 if ((c3 >= c2 && frame_mv[NEARESTMV][ref_frame].as_int == 0) ||
1698 (c3 >= c1 && frame_mv[NEARMV][ref_frame].as_int == 0))
1699 return 0;
1700 } else {
1701 if ((c3 >= c2 && frame_mv[NEARESTMV][ref_frame].as_int == 0 &&
1702 frame_mv[NEARESTMV][second_ref_frame].as_int == 0) ||
1703 (c3 >= c1 && frame_mv[NEARMV][ref_frame].as_int == 0 &&
1704 frame_mv[NEARMV][second_ref_frame].as_int == 0))
1705 return 0;
1706 }
1707 }
1708 }
1709 return 1;
1710 }
1711
1667 static void rd_check_segment_txsize(VP9_COMP *cpi, MACROBLOCK *x, 1712 static void rd_check_segment_txsize(VP9_COMP *cpi, MACROBLOCK *x,
1668 const TileInfo *const tile, 1713 const TileInfo *const tile,
1669 BEST_SEG_INFO *bsi_buf, int filter_idx, 1714 BEST_SEG_INFO *bsi_buf, int filter_idx,
1670 int_mv seg_mvs[4][MAX_REF_FRAMES], 1715 int_mv seg_mvs[4][MAX_REF_FRAMES],
1671 int mi_row, int mi_col) { 1716 int mi_row, int mi_col) {
1672 int k, br = 0, idx, idy; 1717 int k, br = 0, idx, idy;
1673 int64_t bd = 0, block_sse = 0; 1718 int64_t bd = 0, block_sse = 0;
1674 MB_PREDICTION_MODE this_mode; 1719 MB_PREDICTION_MODE this_mode;
1675 MACROBLOCKD *xd = &x->e_mbd; 1720 MACROBLOCKD *xd = &x->e_mbd;
1676 VP9_COMMON *cm = &cpi->common; 1721 VP9_COMMON *cm = &cpi->common;
1677 MODE_INFO *mi = xd->mi_8x8[0]; 1722 MODE_INFO *mi = xd->mi[0];
1678 MB_MODE_INFO *const mbmi = &mi->mbmi; 1723 MB_MODE_INFO *const mbmi = &mi->mbmi;
1679 struct macroblock_plane *const p = &x->plane[0]; 1724 struct macroblock_plane *const p = &x->plane[0];
1680 struct macroblockd_plane *const pd = &xd->plane[0]; 1725 struct macroblockd_plane *const pd = &xd->plane[0];
1681 const int label_count = 4; 1726 const int label_count = 4;
1682 int64_t this_segment_rd = 0; 1727 int64_t this_segment_rd = 0;
1683 int label_mv_thresh; 1728 int label_mv_thresh;
1684 int segmentyrate = 0; 1729 int segmentyrate = 0;
1685 const BLOCK_SIZE bsize = mbmi->sb_type; 1730 const BLOCK_SIZE bsize = mbmi->sb_type;
1686 const int num_4x4_blocks_wide = num_4x4_blocks_wide_lookup[bsize]; 1731 const int num_4x4_blocks_wide = num_4x4_blocks_wide_lookup[bsize];
1687 const int num_4x4_blocks_high = num_4x4_blocks_high_lookup[bsize]; 1732 const int num_4x4_blocks_high = num_4x4_blocks_high_lookup[bsize];
1688 vp9_variance_fn_ptr_t *v_fn_ptr = &cpi->fn_ptr[bsize]; 1733 vp9_variance_fn_ptr_t *v_fn_ptr = &cpi->fn_ptr[bsize];
1689 ENTROPY_CONTEXT t_above[2], t_left[2]; 1734 ENTROPY_CONTEXT t_above[2], t_left[2];
1690 BEST_SEG_INFO *bsi = bsi_buf + filter_idx; 1735 BEST_SEG_INFO *bsi = bsi_buf + filter_idx;
1691 int mode_idx; 1736 int mode_idx;
1692 int subpelmv = 1, have_ref = 0; 1737 int subpelmv = 1, have_ref = 0;
1693 const int has_second_rf = has_second_ref(mbmi); 1738 const int has_second_rf = has_second_ref(mbmi);
1739 const int disable_inter_mode_mask = cpi->sf.disable_inter_mode_mask[bsize];
1694 1740
1695 vpx_memcpy(t_above, pd->above_context, sizeof(t_above)); 1741 vpx_memcpy(t_above, pd->above_context, sizeof(t_above));
1696 vpx_memcpy(t_left, pd->left_context, sizeof(t_left)); 1742 vpx_memcpy(t_left, pd->left_context, sizeof(t_left));
1697 1743
1698 // 64 makes this threshold really big effectively 1744 // 64 makes this threshold really big effectively
1699 // making it so that we very rarely check mvs on 1745 // making it so that we very rarely check mvs on
1700 // segments. setting this to 1 would make mv thresh 1746 // segments. setting this to 1 would make mv thresh
1701 // roughly equal to what it is for macroblocks 1747 // roughly equal to what it is for macroblocks
1702 label_mv_thresh = 1 * bsi->mvthresh / label_count; 1748 label_mv_thresh = 1 * bsi->mvthresh / label_count;
1703 1749
1704 // Segmentation method overheads 1750 // Segmentation method overheads
1705 for (idy = 0; idy < 2; idy += num_4x4_blocks_high) { 1751 for (idy = 0; idy < 2; idy += num_4x4_blocks_high) {
1706 for (idx = 0; idx < 2; idx += num_4x4_blocks_wide) { 1752 for (idx = 0; idx < 2; idx += num_4x4_blocks_wide) {
1707 // TODO(jingning,rbultje): rewrite the rate-distortion optimization 1753 // TODO(jingning,rbultje): rewrite the rate-distortion optimization
1708 // loop for 4x4/4x8/8x4 block coding. to be replaced with new rd loop 1754 // loop for 4x4/4x8/8x4 block coding. to be replaced with new rd loop
1709 int_mv mode_mv[MB_MODE_COUNT], second_mode_mv[MB_MODE_COUNT]; 1755 int_mv mode_mv[MB_MODE_COUNT][2];
1710 int_mv frame_mv[MB_MODE_COUNT][MAX_REF_FRAMES]; 1756 int_mv frame_mv[MB_MODE_COUNT][MAX_REF_FRAMES];
1711 MB_PREDICTION_MODE mode_selected = ZEROMV; 1757 MB_PREDICTION_MODE mode_selected = ZEROMV;
1712 int64_t best_rd = INT64_MAX; 1758 int64_t best_rd = INT64_MAX;
1713 const int i = idy * 2 + idx; 1759 const int i = idy * 2 + idx;
1714 int ref; 1760 int ref;
1715 1761
1716 for (ref = 0; ref < 1 + has_second_rf; ++ref) { 1762 for (ref = 0; ref < 1 + has_second_rf; ++ref) {
1717 const MV_REFERENCE_FRAME frame = mbmi->ref_frame[ref]; 1763 const MV_REFERENCE_FRAME frame = mbmi->ref_frame[ref];
1718 frame_mv[ZEROMV][frame].as_int = 0; 1764 frame_mv[ZEROMV][frame].as_int = 0;
1719 vp9_append_sub8x8_mvs_for_idx(cm, xd, tile, i, ref, mi_row, mi_col, 1765 vp9_append_sub8x8_mvs_for_idx(cm, xd, tile, i, ref, mi_row, mi_col,
1720 &frame_mv[NEARESTMV][frame], 1766 &frame_mv[NEARESTMV][frame],
1721 &frame_mv[NEARMV][frame]); 1767 &frame_mv[NEARMV][frame]);
1722 } 1768 }
1723 1769
1724 // search for the best motion vector on this segment 1770 // search for the best motion vector on this segment
1725 for (this_mode = NEARESTMV; this_mode <= NEWMV; ++this_mode) { 1771 for (this_mode = NEARESTMV; this_mode <= NEWMV; ++this_mode) {
1726 const struct buf_2d orig_src = x->plane[0].src; 1772 const struct buf_2d orig_src = x->plane[0].src;
1727 struct buf_2d orig_pre[2]; 1773 struct buf_2d orig_pre[2];
1728 1774
1729 mode_idx = INTER_OFFSET(this_mode); 1775 mode_idx = INTER_OFFSET(this_mode);
1730 bsi->rdstat[i][mode_idx].brdcost = INT64_MAX; 1776 bsi->rdstat[i][mode_idx].brdcost = INT64_MAX;
1731 if (cpi->sf.disable_inter_mode_mask[bsize] & (1 << mode_idx)) 1777 if (disable_inter_mode_mask & (1 << mode_idx))
1732 continue; 1778 continue;
1733 1779
1734 // if we're near/nearest and mv == 0,0, compare to zeromv 1780 if (!check_best_zero_mv(cpi, mbmi->mode_context, frame_mv,
1735 if ((this_mode == NEARMV || this_mode == NEARESTMV || 1781 disable_inter_mode_mask,
1736 this_mode == ZEROMV) && 1782 this_mode, mbmi->ref_frame[0],
1737 frame_mv[this_mode][mbmi->ref_frame[0]].as_int == 0 && 1783 mbmi->ref_frame[1]))
1738 (!has_second_rf || 1784 continue;
1739 frame_mv[this_mode][mbmi->ref_frame[1]].as_int == 0)) {
1740 int rfc = mbmi->mode_context[mbmi->ref_frame[0]];
1741 int c1 = cost_mv_ref(cpi, NEARMV, rfc);
1742 int c2 = cost_mv_ref(cpi, NEARESTMV, rfc);
1743 int c3 = cost_mv_ref(cpi, ZEROMV, rfc);
1744
1745 if (this_mode == NEARMV) {
1746 if (c1 > c3)
1747 continue;
1748 } else if (this_mode == NEARESTMV) {
1749 if (c2 > c3)
1750 continue;
1751 } else {
1752 assert(this_mode == ZEROMV);
1753 if (!has_second_rf) {
1754 if ((c3 >= c2 &&
1755 frame_mv[NEARESTMV][mbmi->ref_frame[0]].as_int == 0) ||
1756 (c3 >= c1 &&
1757 frame_mv[NEARMV][mbmi->ref_frame[0]].as_int == 0))
1758 continue;
1759 } else {
1760 if ((c3 >= c2 &&
1761 frame_mv[NEARESTMV][mbmi->ref_frame[0]].as_int == 0 &&
1762 frame_mv[NEARESTMV][mbmi->ref_frame[1]].as_int == 0) ||
1763 (c3 >= c1 &&
1764 frame_mv[NEARMV][mbmi->ref_frame[0]].as_int == 0 &&
1765 frame_mv[NEARMV][mbmi->ref_frame[1]].as_int == 0))
1766 continue;
1767 }
1768 }
1769 }
1770 1785
1771 vpx_memcpy(orig_pre, pd->pre, sizeof(orig_pre)); 1786 vpx_memcpy(orig_pre, pd->pre, sizeof(orig_pre));
1772 vpx_memcpy(bsi->rdstat[i][mode_idx].ta, t_above, 1787 vpx_memcpy(bsi->rdstat[i][mode_idx].ta, t_above,
1773 sizeof(bsi->rdstat[i][mode_idx].ta)); 1788 sizeof(bsi->rdstat[i][mode_idx].ta));
1774 vpx_memcpy(bsi->rdstat[i][mode_idx].tl, t_left, 1789 vpx_memcpy(bsi->rdstat[i][mode_idx].tl, t_left,
1775 sizeof(bsi->rdstat[i][mode_idx].tl)); 1790 sizeof(bsi->rdstat[i][mode_idx].tl));
1776 1791
1777 // motion search for newmv (single predictor case only) 1792 // motion search for newmv (single predictor case only)
1778 if (!has_second_rf && this_mode == NEWMV && 1793 if (!has_second_rf && this_mode == NEWMV &&
1779 seg_mvs[i][mbmi->ref_frame[0]].as_int == INVALID_MV) { 1794 seg_mvs[i][mbmi->ref_frame[0]].as_int == INVALID_MV) {
1780 int_mv *const new_mv = &mode_mv[NEWMV]; 1795 int_mv *const new_mv = &mode_mv[NEWMV][0];
1781 int step_param = 0; 1796 int step_param = 0;
1782 int further_steps; 1797 int further_steps;
1783 int thissme, bestsme = INT_MAX; 1798 int thissme, bestsme = INT_MAX;
1784 int sadpb = x->sadperbit4; 1799 int sadpb = x->sadperbit4;
1785 MV mvp_full; 1800 MV mvp_full;
1786 int max_mv; 1801 int max_mv;
1787 1802
1788 /* Is the best so far sufficiently good that we cant justify doing 1803 /* Is the best so far sufficiently good that we cant justify doing
1789 * and new motion search. */ 1804 * and new motion search. */
1790 if (best_rd < label_mv_thresh) 1805 if (best_rd < label_mv_thresh)
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1828 mi_buf_shift(x, i); 1843 mi_buf_shift(x, i);
1829 1844
1830 vp9_set_mv_search_range(x, &bsi->ref_mv[0]->as_mv); 1845 vp9_set_mv_search_range(x, &bsi->ref_mv[0]->as_mv);
1831 1846
1832 if (cpi->sf.search_method == HEX) { 1847 if (cpi->sf.search_method == HEX) {
1833 bestsme = vp9_hex_search(x, &mvp_full, 1848 bestsme = vp9_hex_search(x, &mvp_full,
1834 step_param, 1849 step_param,
1835 sadpb, 1, v_fn_ptr, 1, 1850 sadpb, 1, v_fn_ptr, 1,
1836 &bsi->ref_mv[0]->as_mv, 1851 &bsi->ref_mv[0]->as_mv,
1837 &new_mv->as_mv); 1852 &new_mv->as_mv);
1853 if (bestsme < INT_MAX)
1854 bestsme = vp9_get_mvpred_var(x, &new_mv->as_mv,
1855 &bsi->ref_mv[0]->as_mv,
1856 v_fn_ptr, 1);
1838 } else if (cpi->sf.search_method == SQUARE) { 1857 } else if (cpi->sf.search_method == SQUARE) {
1839 bestsme = vp9_square_search(x, &mvp_full, 1858 bestsme = vp9_square_search(x, &mvp_full,
1840 step_param, 1859 step_param,
1841 sadpb, 1, v_fn_ptr, 1, 1860 sadpb, 1, v_fn_ptr, 1,
1842 &bsi->ref_mv[0]->as_mv, 1861 &bsi->ref_mv[0]->as_mv,
1843 &new_mv->as_mv); 1862 &new_mv->as_mv);
1863 if (bestsme < INT_MAX)
1864 bestsme = vp9_get_mvpred_var(x, &new_mv->as_mv,
1865 &bsi->ref_mv[0]->as_mv,
1866 v_fn_ptr, 1);
1844 } else if (cpi->sf.search_method == BIGDIA) { 1867 } else if (cpi->sf.search_method == BIGDIA) {
1845 bestsme = vp9_bigdia_search(x, &mvp_full, 1868 bestsme = vp9_bigdia_search(x, &mvp_full,
1846 step_param, 1869 step_param,
1847 sadpb, 1, v_fn_ptr, 1, 1870 sadpb, 1, v_fn_ptr, 1,
1848 &bsi->ref_mv[0]->as_mv, 1871 &bsi->ref_mv[0]->as_mv,
1849 &new_mv->as_mv); 1872 &new_mv->as_mv);
1873 if (bestsme < INT_MAX)
1874 bestsme = vp9_get_mvpred_var(x, &new_mv->as_mv,
1875 &bsi->ref_mv[0]->as_mv,
1876 v_fn_ptr, 1);
1850 } else { 1877 } else {
1851 bestsme = vp9_full_pixel_diamond(cpi, x, &mvp_full, step_param, 1878 bestsme = vp9_full_pixel_diamond(cpi, x, &mvp_full, step_param,
1852 sadpb, further_steps, 0, v_fn_ptr, 1879 sadpb, further_steps, 0, v_fn_ptr,
1853 &bsi->ref_mv[0]->as_mv, 1880 &bsi->ref_mv[0]->as_mv,
1854 &new_mv->as_mv); 1881 &new_mv->as_mv);
1855 } 1882 }
1856 1883
1857 // Should we do a full search (best quality only) 1884 // Should we do a full search (best quality only)
1858 if (cpi->oxcf.mode == MODE_BESTQUALITY || 1885 if (cpi->oxcf.mode == MODE_BESTQUALITY ||
1859 cpi->oxcf.mode == MODE_SECONDPASS_BEST) { 1886 cpi->oxcf.mode == MODE_SECONDPASS_BEST) {
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
1918 seg_mvs[i][mbmi->ref_frame[0]].as_int = 1945 seg_mvs[i][mbmi->ref_frame[0]].as_int =
1919 frame_mv[this_mode][mbmi->ref_frame[0]].as_int; 1946 frame_mv[this_mode][mbmi->ref_frame[0]].as_int;
1920 seg_mvs[i][mbmi->ref_frame[1]].as_int = 1947 seg_mvs[i][mbmi->ref_frame[1]].as_int =
1921 frame_mv[this_mode][mbmi->ref_frame[1]].as_int; 1948 frame_mv[this_mode][mbmi->ref_frame[1]].as_int;
1922 } 1949 }
1923 // restore src pointers 1950 // restore src pointers
1924 mi_buf_restore(x, orig_src, orig_pre); 1951 mi_buf_restore(x, orig_src, orig_pre);
1925 } 1952 }
1926 1953
1927 bsi->rdstat[i][mode_idx].brate = 1954 bsi->rdstat[i][mode_idx].brate =
1928 labels2mode(x, i, this_mode, &mode_mv[this_mode], 1955 labels2mode(cpi, xd, i, this_mode, mode_mv[this_mode], frame_mv,
1929 &second_mode_mv[this_mode], frame_mv, seg_mvs[i], 1956 seg_mvs[i], bsi->ref_mv, x->nmvjointcost, x->mvcost);
1930 bsi->ref_mv[0], bsi->ref_mv[1], x->nmvjointcost,
1931 x->mvcost, cpi);
1932 1957
1933 1958 for (ref = 0; ref < 1 + has_second_rf; ++ref) {
1934 bsi->rdstat[i][mode_idx].mvs[0].as_int = mode_mv[this_mode].as_int; 1959 bsi->rdstat[i][mode_idx].mvs[ref].as_int =
1935 if (num_4x4_blocks_wide > 1) 1960 mode_mv[this_mode][ref].as_int;
1936 bsi->rdstat[i + 1][mode_idx].mvs[0].as_int =
1937 mode_mv[this_mode].as_int;
1938 if (num_4x4_blocks_high > 1)
1939 bsi->rdstat[i + 2][mode_idx].mvs[0].as_int =
1940 mode_mv[this_mode].as_int;
1941 if (has_second_rf) {
1942 bsi->rdstat[i][mode_idx].mvs[1].as_int =
1943 second_mode_mv[this_mode].as_int;
1944 if (num_4x4_blocks_wide > 1) 1961 if (num_4x4_blocks_wide > 1)
1945 bsi->rdstat[i + 1][mode_idx].mvs[1].as_int = 1962 bsi->rdstat[i + 1][mode_idx].mvs[ref].as_int =
1946 second_mode_mv[this_mode].as_int; 1963 mode_mv[this_mode][ref].as_int;
1947 if (num_4x4_blocks_high > 1) 1964 if (num_4x4_blocks_high > 1)
1948 bsi->rdstat[i + 2][mode_idx].mvs[1].as_int = 1965 bsi->rdstat[i + 2][mode_idx].mvs[ref].as_int =
1949 second_mode_mv[this_mode].as_int; 1966 mode_mv[this_mode][ref].as_int;
1950 } 1967 }
1951 1968
1952 // Trap vectors that reach beyond the UMV borders 1969 // Trap vectors that reach beyond the UMV borders
1953 if (mv_check_bounds(x, &mode_mv[this_mode].as_mv) || 1970 if (mv_check_bounds(x, &mode_mv[this_mode][0].as_mv) ||
1954 (has_second_rf && 1971 (has_second_rf &&
1955 mv_check_bounds(x, &second_mode_mv[this_mode].as_mv))) 1972 mv_check_bounds(x, &mode_mv[this_mode][1].as_mv)))
1956 continue; 1973 continue;
1957 1974
1958 if (filter_idx > 0) { 1975 if (filter_idx > 0) {
1959 BEST_SEG_INFO *ref_bsi = bsi_buf; 1976 BEST_SEG_INFO *ref_bsi = bsi_buf;
1960 subpelmv = mv_has_subpel(&mode_mv[this_mode].as_mv); 1977 subpelmv = 0;
1961 have_ref = mode_mv[this_mode].as_int == 1978 have_ref = 1;
1962 ref_bsi->rdstat[i][mode_idx].mvs[0].as_int; 1979
1963 if (has_second_rf) { 1980 for (ref = 0; ref < 1 + has_second_rf; ++ref) {
1964 subpelmv |= mv_has_subpel(&second_mode_mv[this_mode].as_mv); 1981 subpelmv |= mv_has_subpel(&mode_mv[this_mode][ref].as_mv);
1965 have_ref &= second_mode_mv[this_mode].as_int == 1982 have_ref &= mode_mv[this_mode][ref].as_int ==
1966 ref_bsi->rdstat[i][mode_idx].mvs[1].as_int; 1983 ref_bsi->rdstat[i][mode_idx].mvs[ref].as_int;
1967 } 1984 }
1968 1985
1969 if (filter_idx > 1 && !subpelmv && !have_ref) { 1986 if (filter_idx > 1 && !subpelmv && !have_ref) {
1970 ref_bsi = bsi_buf + 1; 1987 ref_bsi = bsi_buf + 1;
1971 have_ref = mode_mv[this_mode].as_int == 1988 have_ref = 1;
1972 ref_bsi->rdstat[i][mode_idx].mvs[0].as_int; 1989 for (ref = 0; ref < 1 + has_second_rf; ++ref)
1973 if (has_second_rf) { 1990 have_ref &= mode_mv[this_mode][ref].as_int ==
1974 have_ref &= second_mode_mv[this_mode].as_int == 1991 ref_bsi->rdstat[i][mode_idx].mvs[ref].as_int;
1975 ref_bsi->rdstat[i][mode_idx].mvs[1].as_int;
1976 }
1977 } 1992 }
1978 1993
1979 if (!subpelmv && have_ref && 1994 if (!subpelmv && have_ref &&
1980 ref_bsi->rdstat[i][mode_idx].brdcost < INT64_MAX) { 1995 ref_bsi->rdstat[i][mode_idx].brdcost < INT64_MAX) {
1981 vpx_memcpy(&bsi->rdstat[i][mode_idx], &ref_bsi->rdstat[i][mode_idx], 1996 vpx_memcpy(&bsi->rdstat[i][mode_idx], &ref_bsi->rdstat[i][mode_idx],
1982 sizeof(SEG_RDSTAT)); 1997 sizeof(SEG_RDSTAT));
1983 if (num_4x4_blocks_wide > 1) 1998 if (num_4x4_blocks_wide > 1)
1984 bsi->rdstat[i + 1][mode_idx].eobs = 1999 bsi->rdstat[i + 1][mode_idx].eobs =
1985 ref_bsi->rdstat[i + 1][mode_idx].eobs; 2000 ref_bsi->rdstat[i + 1][mode_idx].eobs;
1986 if (num_4x4_blocks_high > 1) 2001 if (num_4x4_blocks_high > 1)
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
2027 for (midx = 0; midx < INTER_MODES; ++midx) 2042 for (midx = 0; midx < INTER_MODES; ++midx)
2028 bsi->rdstat[iy][midx].brdcost = INT64_MAX; 2043 bsi->rdstat[iy][midx].brdcost = INT64_MAX;
2029 bsi->segment_rd = INT64_MAX; 2044 bsi->segment_rd = INT64_MAX;
2030 return; 2045 return;
2031 } 2046 }
2032 2047
2033 mode_idx = INTER_OFFSET(mode_selected); 2048 mode_idx = INTER_OFFSET(mode_selected);
2034 vpx_memcpy(t_above, bsi->rdstat[i][mode_idx].ta, sizeof(t_above)); 2049 vpx_memcpy(t_above, bsi->rdstat[i][mode_idx].ta, sizeof(t_above));
2035 vpx_memcpy(t_left, bsi->rdstat[i][mode_idx].tl, sizeof(t_left)); 2050 vpx_memcpy(t_left, bsi->rdstat[i][mode_idx].tl, sizeof(t_left));
2036 2051
2037 labels2mode(x, i, mode_selected, &mode_mv[mode_selected], 2052 labels2mode(cpi, xd, i, mode_selected, mode_mv[mode_selected],
2038 &second_mode_mv[mode_selected], frame_mv, seg_mvs[i], 2053 frame_mv, seg_mvs[i], bsi->ref_mv, x->nmvjointcost,
2039 bsi->ref_mv[0], bsi->ref_mv[1], x->nmvjointcost, 2054 x->mvcost);
2040 x->mvcost, cpi);
2041 2055
2042 br += bsi->rdstat[i][mode_idx].brate; 2056 br += bsi->rdstat[i][mode_idx].brate;
2043 bd += bsi->rdstat[i][mode_idx].bdist; 2057 bd += bsi->rdstat[i][mode_idx].bdist;
2044 block_sse += bsi->rdstat[i][mode_idx].bsse; 2058 block_sse += bsi->rdstat[i][mode_idx].bsse;
2045 segmentyrate += bsi->rdstat[i][mode_idx].byrate; 2059 segmentyrate += bsi->rdstat[i][mode_idx].byrate;
2046 this_segment_rd += bsi->rdstat[i][mode_idx].brdcost; 2060 this_segment_rd += bsi->rdstat[i][mode_idx].brdcost;
2047 2061
2048 if (this_segment_rd > bsi->segment_rd) { 2062 if (this_segment_rd > bsi->segment_rd) {
2049 int iy, midx; 2063 int iy, midx;
2050 for (iy = i + 1; iy < 4; ++iy) 2064 for (iy = i + 1; iy < 4; ++iy)
(...skipping 26 matching lines...) Expand all
2077 int64_t *returndistortion, 2091 int64_t *returndistortion,
2078 int *skippable, int64_t *psse, 2092 int *skippable, int64_t *psse,
2079 int mvthresh, 2093 int mvthresh,
2080 int_mv seg_mvs[4][MAX_REF_FRAMES], 2094 int_mv seg_mvs[4][MAX_REF_FRAMES],
2081 BEST_SEG_INFO *bsi_buf, 2095 BEST_SEG_INFO *bsi_buf,
2082 int filter_idx, 2096 int filter_idx,
2083 int mi_row, int mi_col) { 2097 int mi_row, int mi_col) {
2084 int i; 2098 int i;
2085 BEST_SEG_INFO *bsi = bsi_buf + filter_idx; 2099 BEST_SEG_INFO *bsi = bsi_buf + filter_idx;
2086 MACROBLOCKD *xd = &x->e_mbd; 2100 MACROBLOCKD *xd = &x->e_mbd;
2087 MODE_INFO *mi = xd->mi_8x8[0]; 2101 MODE_INFO *mi = xd->mi[0];
2088 MB_MODE_INFO *mbmi = &mi->mbmi; 2102 MB_MODE_INFO *mbmi = &mi->mbmi;
2089 int mode_idx; 2103 int mode_idx;
2090 2104
2091 vp9_zero(*bsi); 2105 vp9_zero(*bsi);
2092 2106
2093 bsi->segment_rd = best_rd; 2107 bsi->segment_rd = best_rd;
2094 bsi->ref_mv[0] = best_ref_mv; 2108 bsi->ref_mv[0] = best_ref_mv;
2095 bsi->ref_mv[1] = second_best_ref_mv; 2109 bsi->ref_mv[1] = second_best_ref_mv;
2096 bsi->mvp.as_int = best_ref_mv->as_int; 2110 bsi->mvp.as_int = best_ref_mv->as_int;
2097 bsi->mvthresh = mvthresh; 2111 bsi->mvthresh = mvthresh;
(...skipping 26 matching lines...) Expand all
2124 *psse = bsi->sse; 2138 *psse = bsi->sse;
2125 mbmi->mode = bsi->modes[3]; 2139 mbmi->mode = bsi->modes[3];
2126 2140
2127 return bsi->segment_rd; 2141 return bsi->segment_rd;
2128 } 2142 }
2129 2143
2130 static void mv_pred(VP9_COMP *cpi, MACROBLOCK *x, 2144 static void mv_pred(VP9_COMP *cpi, MACROBLOCK *x,
2131 uint8_t *ref_y_buffer, int ref_y_stride, 2145 uint8_t *ref_y_buffer, int ref_y_stride,
2132 int ref_frame, BLOCK_SIZE block_size ) { 2146 int ref_frame, BLOCK_SIZE block_size ) {
2133 MACROBLOCKD *xd = &x->e_mbd; 2147 MACROBLOCKD *xd = &x->e_mbd;
2134 MB_MODE_INFO *mbmi = &xd->mi_8x8[0]->mbmi; 2148 MB_MODE_INFO *mbmi = &xd->mi[0]->mbmi;
2135 int_mv this_mv; 2149 int_mv this_mv;
2136 int i; 2150 int i;
2137 int zero_seen = 0; 2151 int zero_seen = 0;
2138 int best_index = 0; 2152 int best_index = 0;
2139 int best_sad = INT_MAX; 2153 int best_sad = INT_MAX;
2140 int this_sad = INT_MAX; 2154 int this_sad = INT_MAX;
2141 int max_mv = 0; 2155 int max_mv = 0;
2142 2156
2143 uint8_t *src_y_ptr = x->plane[0].src.buf; 2157 uint8_t *src_y_ptr = x->plane[0].src.buf;
2144 uint8_t *ref_y_ptr; 2158 uint8_t *ref_y_ptr;
2145 int row_offset, col_offset; 2159 int row_offset, col_offset;
2146 int num_mv_refs = MAX_MV_REF_CANDIDATES + 2160 int num_mv_refs = MAX_MV_REF_CANDIDATES +
2147 (cpi->sf.adaptive_motion_search && 2161 (cpi->sf.adaptive_motion_search &&
2148 cpi->common.show_frame && 2162 cpi->common.show_frame &&
2149 block_size < cpi->sf.max_partition_size); 2163 block_size < cpi->sf.max_partition_size);
2150 2164
2151 int_mv pred_mv[3]; 2165 int_mv pred_mv[3];
2152 pred_mv[0] = mbmi->ref_mvs[ref_frame][0]; 2166 pred_mv[0] = mbmi->ref_mvs[ref_frame][0];
2153 pred_mv[1] = mbmi->ref_mvs[ref_frame][1]; 2167 pred_mv[1] = mbmi->ref_mvs[ref_frame][1];
2154 pred_mv[2] = x->pred_mv[ref_frame]; 2168 pred_mv[2] = x->pred_mv[ref_frame];
2155 2169
2156 // Get the sad for each candidate reference mv 2170 // Get the sad for each candidate reference mv
2157 for (i = 0; i < num_mv_refs; i++) { 2171 for (i = 0; i < num_mv_refs; i++) {
2158 this_mv.as_int = pred_mv[i].as_int; 2172 this_mv.as_int = pred_mv[i].as_int;
2159 2173
2160 max_mv = MAX(max_mv, 2174 max_mv = MAX(max_mv,
2161 MAX(abs(this_mv.as_mv.row), abs(this_mv.as_mv.col)) >> 3); 2175 MAX(abs(this_mv.as_mv.row), abs(this_mv.as_mv.col)) >> 3);
2162 // only need to check zero mv once 2176 // only need to check zero mv once
2163 if (!this_mv.as_int && zero_seen) { 2177 if (!this_mv.as_int && zero_seen)
2164 x->mode_sad[ref_frame][i] = x->mode_sad[ref_frame][INTER_OFFSET(ZEROMV)];
2165 continue; 2178 continue;
2166 } 2179
2167 zero_seen = zero_seen || !this_mv.as_int; 2180 zero_seen = zero_seen || !this_mv.as_int;
2168 2181
2169 row_offset = this_mv.as_mv.row >> 3; 2182 row_offset = this_mv.as_mv.row >> 3;
2170 col_offset = this_mv.as_mv.col >> 3; 2183 col_offset = this_mv.as_mv.col >> 3;
2171 ref_y_ptr = ref_y_buffer + (ref_y_stride * row_offset) + col_offset; 2184 ref_y_ptr = ref_y_buffer + (ref_y_stride * row_offset) + col_offset;
2172 2185
2173 // Find sad for current vector. 2186 // Find sad for current vector.
2174 this_sad = cpi->fn_ptr[block_size].sdf(src_y_ptr, x->plane[0].src.stride, 2187 this_sad = cpi->fn_ptr[block_size].sdf(src_y_ptr, x->plane[0].src.stride,
2175 ref_y_ptr, ref_y_stride, 2188 ref_y_ptr, ref_y_stride,
2176 0x7fffffff); 2189 0x7fffffff);
2177 x->mode_sad[ref_frame][i] = this_sad;
2178 if (this_mv.as_int == 0)
2179 x->mode_sad[ref_frame][INTER_OFFSET(ZEROMV)] = this_sad;
2180 2190
2181 // Note if it is the best so far. 2191 // Note if it is the best so far.
2182 if (this_sad < best_sad) { 2192 if (this_sad < best_sad) {
2183 best_sad = this_sad; 2193 best_sad = this_sad;
2184 best_index = i; 2194 best_index = i;
2185 } 2195 }
2186 } 2196 }
2187 2197
2188 if (!zero_seen)
2189 x->mode_sad[ref_frame][INTER_OFFSET(ZEROMV)] =
2190 cpi->fn_ptr[block_size].sdf(src_y_ptr, x->plane[0].src.stride,
2191 ref_y_buffer, ref_y_stride,
2192 0x7fffffff);
2193
2194 // Note the index of the mv that worked best in the reference list. 2198 // Note the index of the mv that worked best in the reference list.
2195 x->mv_best_ref_index[ref_frame] = best_index; 2199 x->mv_best_ref_index[ref_frame] = best_index;
2196 x->max_mv_context[ref_frame] = max_mv; 2200 x->max_mv_context[ref_frame] = max_mv;
2197 x->pred_mv_sad[ref_frame] = best_sad; 2201 x->pred_mv_sad[ref_frame] = best_sad;
2198 } 2202 }
2199 2203
2200 static void estimate_ref_frame_costs(VP9_COMP *cpi, int segment_id, 2204 static void estimate_ref_frame_costs(VP9_COMP *cpi, int segment_id,
2201 unsigned int *ref_costs_single, 2205 unsigned int *ref_costs_single,
2202 unsigned int *ref_costs_comp, 2206 unsigned int *ref_costs_comp,
2203 vp9_prob *comp_mode_p) { 2207 vp9_prob *comp_mode_p) {
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
2264 int_mv *second_ref_mv, 2268 int_mv *second_ref_mv,
2265 int64_t comp_pred_diff[REFERENCE_MODES], 2269 int64_t comp_pred_diff[REFERENCE_MODES],
2266 int64_t tx_size_diff[TX_MODES], 2270 int64_t tx_size_diff[TX_MODES],
2267 int64_t best_filter_diff[SWITCHABLE_FILTER_CONTEXTS]) { 2271 int64_t best_filter_diff[SWITCHABLE_FILTER_CONTEXTS]) {
2268 MACROBLOCKD *const xd = &x->e_mbd; 2272 MACROBLOCKD *const xd = &x->e_mbd;
2269 2273
2270 // Take a snapshot of the coding context so it can be 2274 // Take a snapshot of the coding context so it can be
2271 // restored if we decide to encode this way 2275 // restored if we decide to encode this way
2272 ctx->skip = x->skip; 2276 ctx->skip = x->skip;
2273 ctx->best_mode_index = mode_index; 2277 ctx->best_mode_index = mode_index;
2274 ctx->mic = *xd->mi_8x8[0]; 2278 ctx->mic = *xd->mi[0];
2275 2279
2276 ctx->best_ref_mv[0].as_int = ref_mv->as_int; 2280 ctx->best_ref_mv[0].as_int = ref_mv->as_int;
2277 ctx->best_ref_mv[1].as_int = second_ref_mv->as_int; 2281 ctx->best_ref_mv[1].as_int = second_ref_mv->as_int;
2278 2282
2279 ctx->single_pred_diff = (int)comp_pred_diff[SINGLE_REFERENCE]; 2283 ctx->single_pred_diff = (int)comp_pred_diff[SINGLE_REFERENCE];
2280 ctx->comp_pred_diff = (int)comp_pred_diff[COMPOUND_REFERENCE]; 2284 ctx->comp_pred_diff = (int)comp_pred_diff[COMPOUND_REFERENCE];
2281 ctx->hybrid_pred_diff = (int)comp_pred_diff[REFERENCE_MODE_SELECT]; 2285 ctx->hybrid_pred_diff = (int)comp_pred_diff[REFERENCE_MODE_SELECT];
2282 2286
2283 vpx_memcpy(ctx->tx_rd_diff, tx_size_diff, sizeof(ctx->tx_rd_diff)); 2287 vpx_memcpy(ctx->tx_rd_diff, tx_size_diff, sizeof(ctx->tx_rd_diff));
2284 vpx_memcpy(ctx->best_filter_diff, best_filter_diff, 2288 vpx_memcpy(ctx->best_filter_diff, best_filter_diff,
(...skipping 30 matching lines...) Expand all
2315 const TileInfo *const tile, 2319 const TileInfo *const tile,
2316 MV_REFERENCE_FRAME ref_frame, 2320 MV_REFERENCE_FRAME ref_frame,
2317 BLOCK_SIZE block_size, 2321 BLOCK_SIZE block_size,
2318 int mi_row, int mi_col, 2322 int mi_row, int mi_col,
2319 int_mv frame_nearest_mv[MAX_REF_FRAMES], 2323 int_mv frame_nearest_mv[MAX_REF_FRAMES],
2320 int_mv frame_near_mv[MAX_REF_FRAMES], 2324 int_mv frame_near_mv[MAX_REF_FRAMES],
2321 struct buf_2d yv12_mb[4][MAX_MB_PLANE]) { 2325 struct buf_2d yv12_mb[4][MAX_MB_PLANE]) {
2322 const VP9_COMMON *cm = &cpi->common; 2326 const VP9_COMMON *cm = &cpi->common;
2323 const YV12_BUFFER_CONFIG *yv12 = get_ref_frame_buffer(cpi, ref_frame); 2327 const YV12_BUFFER_CONFIG *yv12 = get_ref_frame_buffer(cpi, ref_frame);
2324 MACROBLOCKD *const xd = &x->e_mbd; 2328 MACROBLOCKD *const xd = &x->e_mbd;
2325 MODE_INFO *const mi = xd->mi_8x8[0]; 2329 MODE_INFO *const mi = xd->mi[0];
2326 int_mv *const candidates = mi->mbmi.ref_mvs[ref_frame]; 2330 int_mv *const candidates = mi->mbmi.ref_mvs[ref_frame];
2327 const struct scale_factors *const sf = &cm->frame_refs[ref_frame - 1].sf; 2331 const struct scale_factors *const sf = &cm->frame_refs[ref_frame - 1].sf;
2328 2332
2329 // TODO(jkoleszar): Is the UV buffer ever used here? If so, need to make this 2333 // TODO(jkoleszar): Is the UV buffer ever used here? If so, need to make this
2330 // use the UV scaling factors. 2334 // use the UV scaling factors.
2331 setup_pred_block(xd, yv12_mb[ref_frame], yv12, mi_row, mi_col, sf, sf); 2335 setup_pred_block(xd, yv12_mb[ref_frame], yv12, mi_row, mi_col, sf, sf);
2332 2336
2333 // Gets an initial list of candidate vectors from neighbours and orders them 2337 // Gets an initial list of candidate vectors from neighbours and orders them
2334 vp9_find_mv_refs(cm, xd, tile, mi, xd->last_mi, ref_frame, candidates, 2338 vp9_find_mv_refs(cm, xd, tile, mi, ref_frame, candidates, mi_row, mi_col);
2335 mi_row, mi_col);
2336 2339
2337 // Candidate refinement carried out at encoder and decoder 2340 // Candidate refinement carried out at encoder and decoder
2338 vp9_find_best_ref_mvs(xd, cm->allow_high_precision_mv, candidates, 2341 vp9_find_best_ref_mvs(xd, cm->allow_high_precision_mv, candidates,
2339 &frame_nearest_mv[ref_frame], 2342 &frame_nearest_mv[ref_frame],
2340 &frame_near_mv[ref_frame]); 2343 &frame_near_mv[ref_frame]);
2341 2344
2342 // Further refinement that is encode side only to test the top few candidates 2345 // Further refinement that is encode side only to test the top few candidates
2343 // in full and choose the best as the centre point for subsequent searches. 2346 // in full and choose the best as the centre point for subsequent searches.
2344 // The current implementation doesn't support scaling. 2347 // The current implementation doesn't support scaling.
2345 if (!vp9_is_scaled(sf) && block_size >= BLOCK_8X8) 2348 if (!vp9_is_scaled(sf) && block_size >= BLOCK_8X8)
2346 mv_pred(cpi, x, yv12_mb[ref_frame][0].buf, yv12->y_stride, 2349 mv_pred(cpi, x, yv12_mb[ref_frame][0].buf, yv12->y_stride,
2347 ref_frame, block_size); 2350 ref_frame, block_size);
2348 } 2351 }
2349 2352
2350 const YV12_BUFFER_CONFIG *vp9_get_scaled_ref_frame(const VP9_COMP *cpi, 2353 const YV12_BUFFER_CONFIG *vp9_get_scaled_ref_frame(const VP9_COMP *cpi,
2351 int ref_frame) { 2354 int ref_frame) {
2352 const VP9_COMMON *const cm = &cpi->common; 2355 const VP9_COMMON *const cm = &cpi->common;
2353 const int ref_idx = cm->ref_frame_map[get_ref_frame_idx(cpi, ref_frame)]; 2356 const int ref_idx = cm->ref_frame_map[get_ref_frame_idx(cpi, ref_frame)];
2354 const int scaled_idx = cpi->scaled_ref_idx[ref_frame - 1]; 2357 const int scaled_idx = cpi->scaled_ref_idx[ref_frame - 1];
2355 return (scaled_idx != ref_idx) ? &cm->frame_bufs[scaled_idx].buf : NULL; 2358 return (scaled_idx != ref_idx) ? &cm->frame_bufs[scaled_idx].buf : NULL;
2356 } 2359 }
2357 2360
2358 static INLINE int get_switchable_rate(const MACROBLOCK *x) { 2361 int vp9_get_switchable_rate(const MACROBLOCK *x) {
2359 const MACROBLOCKD *const xd = &x->e_mbd; 2362 const MACROBLOCKD *const xd = &x->e_mbd;
2360 const MB_MODE_INFO *const mbmi = &xd->mi_8x8[0]->mbmi; 2363 const MB_MODE_INFO *const mbmi = &xd->mi[0]->mbmi;
2361 const int ctx = vp9_get_pred_context_switchable_interp(xd); 2364 const int ctx = vp9_get_pred_context_switchable_interp(xd);
2362 return SWITCHABLE_INTERP_RATE_FACTOR * 2365 return SWITCHABLE_INTERP_RATE_FACTOR *
2363 x->switchable_interp_costs[ctx][mbmi->interp_filter]; 2366 x->switchable_interp_costs[ctx][mbmi->interp_filter];
2364 } 2367 }
2365 2368
2366 static void single_motion_search(VP9_COMP *cpi, MACROBLOCK *x, 2369 static void single_motion_search(VP9_COMP *cpi, MACROBLOCK *x,
2367 const TileInfo *const tile,
2368 BLOCK_SIZE bsize, 2370 BLOCK_SIZE bsize,
2369 int mi_row, int mi_col, 2371 int mi_row, int mi_col,
2370 int_mv *tmp_mv, int *rate_mv) { 2372 int_mv *tmp_mv, int *rate_mv) {
2371 MACROBLOCKD *xd = &x->e_mbd; 2373 MACROBLOCKD *xd = &x->e_mbd;
2372 VP9_COMMON *cm = &cpi->common; 2374 VP9_COMMON *cm = &cpi->common;
2373 MB_MODE_INFO *mbmi = &xd->mi_8x8[0]->mbmi; 2375 MB_MODE_INFO *mbmi = &xd->mi[0]->mbmi;
2374 struct buf_2d backup_yv12[MAX_MB_PLANE] = {{0}}; 2376 struct buf_2d backup_yv12[MAX_MB_PLANE] = {{0}};
2375 int bestsme = INT_MAX; 2377 int bestsme = INT_MAX;
2376 int further_steps, step_param; 2378 int further_steps, step_param;
2377 int sadpb = x->sadperbit16; 2379 int sadpb = x->sadperbit16;
2378 MV mvp_full; 2380 MV mvp_full;
2379 int ref = mbmi->ref_frame[0]; 2381 int ref = mbmi->ref_frame[0];
2380 MV ref_mv = mbmi->ref_mvs[ref][0].as_mv; 2382 MV ref_mv = mbmi->ref_mvs[ref][0].as_mv;
2381 2383
2382 int tmp_col_min = x->mv_col_min; 2384 int tmp_col_min = x->mv_col_min;
2383 int tmp_col_max = x->mv_col_max; 2385 int tmp_col_max = x->mv_col_max;
2384 int tmp_row_min = x->mv_row_min; 2386 int tmp_row_min = x->mv_row_min;
2385 int tmp_row_max = x->mv_row_max; 2387 int tmp_row_max = x->mv_row_max;
2386 2388
2387 const YV12_BUFFER_CONFIG *scaled_ref_frame = vp9_get_scaled_ref_frame(cpi, 2389 const YV12_BUFFER_CONFIG *scaled_ref_frame = vp9_get_scaled_ref_frame(cpi,
2388 ref); 2390 ref);
2389 2391
2390 MV pred_mv[3]; 2392 MV pred_mv[3];
2391 pred_mv[0] = mbmi->ref_mvs[ref][0].as_mv; 2393 pred_mv[0] = mbmi->ref_mvs[ref][0].as_mv;
2392 pred_mv[1] = mbmi->ref_mvs[ref][1].as_mv; 2394 pred_mv[1] = mbmi->ref_mvs[ref][1].as_mv;
2393 pred_mv[2] = x->pred_mv[ref].as_mv; 2395 pred_mv[2] = x->pred_mv[ref].as_mv;
2394 2396
2395 if (scaled_ref_frame) { 2397 if (scaled_ref_frame) {
2396 int i; 2398 int i;
2397 // Swap out the reference frame for a version that's been scaled to 2399 // Swap out the reference frame for a version that's been scaled to
2398 // match the resolution of the current frame, allowing the existing 2400 // match the resolution of the current frame, allowing the existing
2399 // motion search code to be used without additional modifications. 2401 // motion search code to be used without additional modifications.
2400 for (i = 0; i < MAX_MB_PLANE; i++) 2402 for (i = 0; i < MAX_MB_PLANE; i++)
2401 backup_yv12[i] = xd->plane[i].pre[0]; 2403 backup_yv12[i] = xd->plane[i].pre[0];
2402 2404
2403 setup_pre_planes(xd, 0, scaled_ref_frame, mi_row, mi_col, NULL); 2405 vp9_setup_pre_planes(xd, 0, scaled_ref_frame, mi_row, mi_col, NULL);
2404 } 2406 }
2405 2407
2406 vp9_set_mv_search_range(x, &ref_mv); 2408 vp9_set_mv_search_range(x, &ref_mv);
2407 2409
2408 // Work out the size of the first step in the mv step search. 2410 // Work out the size of the first step in the mv step search.
2409 // 0 here is maximum length first step. 1 is MAX >> 1 etc. 2411 // 0 here is maximum length first step. 1 is MAX >> 1 etc.
2410 if (cpi->sf.auto_mv_step_size && cpi->common.show_frame) { 2412 if (cpi->sf.auto_mv_step_size && cpi->common.show_frame) {
2411 // Take wtd average of the step_params based on the last frame's 2413 // Take wtd average of the step_params based on the last frame's
2412 // max mv magnitude and that based on the best ref mvs of the current 2414 // max mv magnitude and that based on the best ref mvs of the current
2413 // block for the given reference. 2415 // block for the given reference.
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
2449 } 2451 }
2450 2452
2451 mvp_full = pred_mv[x->mv_best_ref_index[ref]]; 2453 mvp_full = pred_mv[x->mv_best_ref_index[ref]];
2452 2454
2453 mvp_full.col >>= 3; 2455 mvp_full.col >>= 3;
2454 mvp_full.row >>= 3; 2456 mvp_full.row >>= 3;
2455 2457
2456 // Further step/diamond searches as necessary 2458 // Further step/diamond searches as necessary
2457 further_steps = (cpi->sf.max_step_search_steps - 1) - step_param; 2459 further_steps = (cpi->sf.max_step_search_steps - 1) - step_param;
2458 2460
2459 if (cpi->sf.search_method == FAST_HEX) { 2461 if (cpi->sf.search_method == FAST_DIAMOND) {
2460 bestsme = vp9_fast_hex_search(x, &mvp_full, step_param, sadpb, 2462 bestsme = vp9_fast_dia_search(x, &mvp_full, step_param, sadpb, 0,
2461 &cpi->fn_ptr[bsize], 1, 2463 &cpi->fn_ptr[bsize], 1,
2462 &ref_mv, &tmp_mv->as_mv); 2464 &ref_mv, &tmp_mv->as_mv);
2465 if (bestsme < INT_MAX)
2466 bestsme = vp9_get_mvpred_var(x, &tmp_mv->as_mv, &ref_mv,
2467 &cpi->fn_ptr[bsize], 1);
2468 } else if (cpi->sf.search_method == FAST_HEX) {
2469 bestsme = vp9_fast_hex_search(x, &mvp_full, step_param, sadpb, 0,
2470 &cpi->fn_ptr[bsize], 1,
2471 &ref_mv, &tmp_mv->as_mv);
2472 if (bestsme < INT_MAX)
2473 bestsme = vp9_get_mvpred_var(x, &tmp_mv->as_mv, &ref_mv,
2474 &cpi->fn_ptr[bsize], 1);
2463 } else if (cpi->sf.search_method == HEX) { 2475 } else if (cpi->sf.search_method == HEX) {
2464 bestsme = vp9_hex_search(x, &mvp_full, step_param, sadpb, 1, 2476 bestsme = vp9_hex_search(x, &mvp_full, step_param, sadpb, 1,
2465 &cpi->fn_ptr[bsize], 1, 2477 &cpi->fn_ptr[bsize], 1,
2466 &ref_mv, &tmp_mv->as_mv); 2478 &ref_mv, &tmp_mv->as_mv);
2479 if (bestsme < INT_MAX)
2480 bestsme = vp9_get_mvpred_var(x, &tmp_mv->as_mv, &ref_mv,
2481 &cpi->fn_ptr[bsize], 1);
2467 } else if (cpi->sf.search_method == SQUARE) { 2482 } else if (cpi->sf.search_method == SQUARE) {
2468 bestsme = vp9_square_search(x, &mvp_full, step_param, sadpb, 1, 2483 bestsme = vp9_square_search(x, &mvp_full, step_param, sadpb, 1,
2469 &cpi->fn_ptr[bsize], 1, 2484 &cpi->fn_ptr[bsize], 1,
2470 &ref_mv, &tmp_mv->as_mv); 2485 &ref_mv, &tmp_mv->as_mv);
2486 if (bestsme < INT_MAX)
2487 bestsme = vp9_get_mvpred_var(x, &tmp_mv->as_mv, &ref_mv,
2488 &cpi->fn_ptr[bsize], 1);
2471 } else if (cpi->sf.search_method == BIGDIA) { 2489 } else if (cpi->sf.search_method == BIGDIA) {
2472 bestsme = vp9_bigdia_search(x, &mvp_full, step_param, sadpb, 1, 2490 bestsme = vp9_bigdia_search(x, &mvp_full, step_param, sadpb, 1,
2473 &cpi->fn_ptr[bsize], 1, 2491 &cpi->fn_ptr[bsize], 1,
2474 &ref_mv, &tmp_mv->as_mv); 2492 &ref_mv, &tmp_mv->as_mv);
2493 if (bestsme < INT_MAX)
2494 bestsme = vp9_get_mvpred_var(x, &tmp_mv->as_mv, &ref_mv,
2495 &cpi->fn_ptr[bsize], 1);
2475 } else { 2496 } else {
2476 bestsme = vp9_full_pixel_diamond(cpi, x, &mvp_full, step_param, 2497 bestsme = vp9_full_pixel_diamond(cpi, x, &mvp_full, step_param,
2477 sadpb, further_steps, 1, 2498 sadpb, further_steps, 1,
2478 &cpi->fn_ptr[bsize], 2499 &cpi->fn_ptr[bsize],
2479 &ref_mv, &tmp_mv->as_mv); 2500 &ref_mv, &tmp_mv->as_mv);
2480 } 2501 }
2481 2502
2482 x->mv_col_min = tmp_col_min; 2503 x->mv_col_min = tmp_col_min;
2483 x->mv_col_max = tmp_col_max; 2504 x->mv_col_max = tmp_col_max;
2484 x->mv_row_min = tmp_row_min; 2505 x->mv_row_min = tmp_row_min;
(...skipping 25 matching lines...) Expand all
2510 2531
2511 static void joint_motion_search(VP9_COMP *cpi, MACROBLOCK *x, 2532 static void joint_motion_search(VP9_COMP *cpi, MACROBLOCK *x,
2512 BLOCK_SIZE bsize, 2533 BLOCK_SIZE bsize,
2513 int_mv *frame_mv, 2534 int_mv *frame_mv,
2514 int mi_row, int mi_col, 2535 int mi_row, int mi_col,
2515 int_mv single_newmv[MAX_REF_FRAMES], 2536 int_mv single_newmv[MAX_REF_FRAMES],
2516 int *rate_mv) { 2537 int *rate_mv) {
2517 const int pw = 4 * num_4x4_blocks_wide_lookup[bsize]; 2538 const int pw = 4 * num_4x4_blocks_wide_lookup[bsize];
2518 const int ph = 4 * num_4x4_blocks_high_lookup[bsize]; 2539 const int ph = 4 * num_4x4_blocks_high_lookup[bsize];
2519 MACROBLOCKD *xd = &x->e_mbd; 2540 MACROBLOCKD *xd = &x->e_mbd;
2520 MB_MODE_INFO *mbmi = &xd->mi_8x8[0]->mbmi; 2541 MB_MODE_INFO *mbmi = &xd->mi[0]->mbmi;
2521 const int refs[2] = { mbmi->ref_frame[0], 2542 const int refs[2] = { mbmi->ref_frame[0],
2522 mbmi->ref_frame[1] < 0 ? 0 : mbmi->ref_frame[1] }; 2543 mbmi->ref_frame[1] < 0 ? 0 : mbmi->ref_frame[1] };
2523 int_mv ref_mv[2]; 2544 int_mv ref_mv[2];
2524 int ite, ref; 2545 int ite, ref;
2525 // Prediction buffer from second frame. 2546 // Prediction buffer from second frame.
2526 uint8_t *second_pred = vpx_memalign(16, pw * ph * sizeof(uint8_t)); 2547 uint8_t *second_pred = vpx_memalign(16, pw * ph * sizeof(uint8_t));
2548 const InterpKernel *kernel = vp9_get_interp_kernel(mbmi->interp_filter);
2527 2549
2528 // Do joint motion search in compound mode to get more accurate mv. 2550 // Do joint motion search in compound mode to get more accurate mv.
2529 struct buf_2d backup_yv12[2][MAX_MB_PLANE]; 2551 struct buf_2d backup_yv12[2][MAX_MB_PLANE];
2530 struct buf_2d scaled_first_yv12 = xd->plane[0].pre[0]; 2552 struct buf_2d scaled_first_yv12 = xd->plane[0].pre[0];
2531 int last_besterr[2] = {INT_MAX, INT_MAX}; 2553 int last_besterr[2] = {INT_MAX, INT_MAX};
2532 const YV12_BUFFER_CONFIG *const scaled_ref_frame[2] = { 2554 const YV12_BUFFER_CONFIG *const scaled_ref_frame[2] = {
2533 vp9_get_scaled_ref_frame(cpi, mbmi->ref_frame[0]), 2555 vp9_get_scaled_ref_frame(cpi, mbmi->ref_frame[0]),
2534 vp9_get_scaled_ref_frame(cpi, mbmi->ref_frame[1]) 2556 vp9_get_scaled_ref_frame(cpi, mbmi->ref_frame[1])
2535 }; 2557 };
2536 2558
2537 for (ref = 0; ref < 2; ++ref) { 2559 for (ref = 0; ref < 2; ++ref) {
2538 ref_mv[ref] = mbmi->ref_mvs[refs[ref]][0]; 2560 ref_mv[ref] = mbmi->ref_mvs[refs[ref]][0];
2539 2561
2540 if (scaled_ref_frame[ref]) { 2562 if (scaled_ref_frame[ref]) {
2541 int i; 2563 int i;
2542 // Swap out the reference frame for a version that's been scaled to 2564 // Swap out the reference frame for a version that's been scaled to
2543 // match the resolution of the current frame, allowing the existing 2565 // match the resolution of the current frame, allowing the existing
2544 // motion search code to be used without additional modifications. 2566 // motion search code to be used without additional modifications.
2545 for (i = 0; i < MAX_MB_PLANE; i++) 2567 for (i = 0; i < MAX_MB_PLANE; i++)
2546 backup_yv12[ref][i] = xd->plane[i].pre[ref]; 2568 backup_yv12[ref][i] = xd->plane[i].pre[ref];
2547 setup_pre_planes(xd, ref, scaled_ref_frame[ref], mi_row, mi_col, NULL); 2569 vp9_setup_pre_planes(xd, ref, scaled_ref_frame[ref], mi_row, mi_col,
2570 NULL);
2548 } 2571 }
2549 2572
2550 frame_mv[refs[ref]].as_int = single_newmv[refs[ref]].as_int; 2573 frame_mv[refs[ref]].as_int = single_newmv[refs[ref]].as_int;
2551 } 2574 }
2552 2575
2553 // Allow joint search multiple times iteratively for each ref frame 2576 // Allow joint search multiple times iteratively for each ref frame
2554 // and break out the search loop if it couldn't find better mv. 2577 // and break out the search loop if it couldn't find better mv.
2555 for (ite = 0; ite < 4; ite++) { 2578 for (ite = 0; ite < 4; ite++) {
2556 struct buf_2d ref_yv12[2]; 2579 struct buf_2d ref_yv12[2];
2557 int bestsme = INT_MAX; 2580 int bestsme = INT_MAX;
(...skipping 11 matching lines...) Expand all
2569 ref_yv12[0] = xd->plane[0].pre[0]; 2592 ref_yv12[0] = xd->plane[0].pre[0];
2570 ref_yv12[1] = xd->plane[0].pre[1]; 2593 ref_yv12[1] = xd->plane[0].pre[1];
2571 2594
2572 // Get pred block from second frame. 2595 // Get pred block from second frame.
2573 vp9_build_inter_predictor(ref_yv12[!id].buf, 2596 vp9_build_inter_predictor(ref_yv12[!id].buf,
2574 ref_yv12[!id].stride, 2597 ref_yv12[!id].stride,
2575 second_pred, pw, 2598 second_pred, pw,
2576 &frame_mv[refs[!id]].as_mv, 2599 &frame_mv[refs[!id]].as_mv,
2577 &xd->block_refs[!id]->sf, 2600 &xd->block_refs[!id]->sf,
2578 pw, ph, 0, 2601 pw, ph, 0,
2579 xd->interp_kernel, MV_PRECISION_Q3, 2602 kernel, MV_PRECISION_Q3,
2580 mi_col * MI_SIZE, mi_row * MI_SIZE); 2603 mi_col * MI_SIZE, mi_row * MI_SIZE);
2581 2604
2582 // Compound motion search on first ref frame. 2605 // Compound motion search on first ref frame.
2583 if (id) 2606 if (id)
2584 xd->plane[0].pre[0] = ref_yv12[id]; 2607 xd->plane[0].pre[0] = ref_yv12[id];
2585 vp9_set_mv_search_range(x, &ref_mv[id].as_mv); 2608 vp9_set_mv_search_range(x, &ref_mv[id].as_mv);
2586 2609
2587 // Use mv result from single mode as mvp. 2610 // Use mv result from single mode as mvp.
2588 tmp_mv.as_int = frame_mv[refs[id]].as_int; 2611 tmp_mv.as_int = frame_mv[refs[id]].as_int;
2589 2612
2590 tmp_mv.as_mv.col >>= 3; 2613 tmp_mv.as_mv.col >>= 3;
2591 tmp_mv.as_mv.row >>= 3; 2614 tmp_mv.as_mv.row >>= 3;
2592 2615
2593 // Small-range full-pixel motion search 2616 // Small-range full-pixel motion search
2594 bestsme = vp9_refining_search_8p_c(x, &tmp_mv.as_mv, sadpb, 2617 bestsme = vp9_refining_search_8p_c(x, &tmp_mv.as_mv, sadpb,
2595 search_range, 2618 search_range,
2596 &cpi->fn_ptr[bsize], 2619 &cpi->fn_ptr[bsize],
2597 x->nmvjointcost, x->mvcost, 2620 x->nmvjointcost, x->mvcost,
2598 &ref_mv[id].as_mv, second_pred, 2621 &ref_mv[id].as_mv, second_pred,
2599 pw, ph); 2622 pw, ph);
2623 if (bestsme < INT_MAX)
2624 bestsme = vp9_get_mvpred_av_var(x, &tmp_mv.as_mv, &ref_mv[id].as_mv,
2625 second_pred, &cpi->fn_ptr[bsize], 1);
2600 2626
2601 x->mv_col_min = tmp_col_min; 2627 x->mv_col_min = tmp_col_min;
2602 x->mv_col_max = tmp_col_max; 2628 x->mv_col_max = tmp_col_max;
2603 x->mv_row_min = tmp_row_min; 2629 x->mv_row_min = tmp_row_min;
2604 x->mv_row_max = tmp_row_max; 2630 x->mv_row_max = tmp_row_max;
2605 2631
2606 if (bestsme < INT_MAX) { 2632 if (bestsme < INT_MAX) {
2607 int dis; /* TODO: use dis in distortion calculation later. */ 2633 int dis; /* TODO: use dis in distortion calculation later. */
2608 unsigned int sse; 2634 unsigned int sse;
2609 bestsme = cpi->find_fractional_mv_step_comp( 2635 bestsme = cpi->find_fractional_mv_step_comp(
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
2651 uint8_t *orig_dst[MAX_MB_PLANE], 2677 uint8_t *orig_dst[MAX_MB_PLANE],
2652 int orig_dst_stride[MAX_MB_PLANE]) { 2678 int orig_dst_stride[MAX_MB_PLANE]) {
2653 int i; 2679 int i;
2654 for (i = 0; i < MAX_MB_PLANE; i++) { 2680 for (i = 0; i < MAX_MB_PLANE; i++) {
2655 xd->plane[i].dst.buf = orig_dst[i]; 2681 xd->plane[i].dst.buf = orig_dst[i];
2656 xd->plane[i].dst.stride = orig_dst_stride[i]; 2682 xd->plane[i].dst.stride = orig_dst_stride[i];
2657 } 2683 }
2658 } 2684 }
2659 2685
2660 static int64_t handle_inter_mode(VP9_COMP *cpi, MACROBLOCK *x, 2686 static int64_t handle_inter_mode(VP9_COMP *cpi, MACROBLOCK *x,
2661 const TileInfo *const tile,
2662 BLOCK_SIZE bsize, 2687 BLOCK_SIZE bsize,
2663 int64_t txfm_cache[], 2688 int64_t txfm_cache[],
2664 int *rate2, int64_t *distortion, 2689 int *rate2, int64_t *distortion,
2665 int *skippable, 2690 int *skippable,
2666 int *rate_y, int64_t *distortion_y, 2691 int *rate_y, int64_t *distortion_y,
2667 int *rate_uv, int64_t *distortion_uv, 2692 int *rate_uv, int64_t *distortion_uv,
2668 int *mode_excluded, int *disable_skip, 2693 int *mode_excluded, int *disable_skip,
2669 INTERP_FILTER *best_filter, 2694 INTERP_FILTER *best_filter,
2670 int_mv (*mode_mv)[MAX_REF_FRAMES], 2695 int_mv (*mode_mv)[MAX_REF_FRAMES],
2671 int mi_row, int mi_col, 2696 int mi_row, int mi_col,
2672 int_mv single_newmv[MAX_REF_FRAMES], 2697 int_mv single_newmv[MAX_REF_FRAMES],
2673 int64_t *psse, 2698 int64_t *psse,
2674 const int64_t ref_best_rd) { 2699 const int64_t ref_best_rd) {
2675 VP9_COMMON *cm = &cpi->common; 2700 VP9_COMMON *cm = &cpi->common;
2676 MACROBLOCKD *xd = &x->e_mbd; 2701 MACROBLOCKD *xd = &x->e_mbd;
2677 MB_MODE_INFO *mbmi = &xd->mi_8x8[0]->mbmi; 2702 MB_MODE_INFO *mbmi = &xd->mi[0]->mbmi;
2678 const int is_comp_pred = has_second_ref(mbmi); 2703 const int is_comp_pred = has_second_ref(mbmi);
2679 const int num_refs = is_comp_pred ? 2 : 1; 2704 const int num_refs = is_comp_pred ? 2 : 1;
2680 const int this_mode = mbmi->mode; 2705 const int this_mode = mbmi->mode;
2681 int_mv *frame_mv = mode_mv[this_mode]; 2706 int_mv *frame_mv = mode_mv[this_mode];
2682 int i; 2707 int i;
2683 int refs[2] = { mbmi->ref_frame[0], 2708 int refs[2] = { mbmi->ref_frame[0],
2684 (mbmi->ref_frame[1] < 0 ? 0 : mbmi->ref_frame[1]) }; 2709 (mbmi->ref_frame[1] < 0 ? 0 : mbmi->ref_frame[1]) };
2685 int_mv cur_mv[2]; 2710 int_mv cur_mv[2];
2686 int64_t this_rd = 0; 2711 int64_t this_rd = 0;
2687 DECLARE_ALIGNED_ARRAY(16, uint8_t, tmp_buf, MAX_MB_PLANE * 64 * 64); 2712 DECLARE_ALIGNED_ARRAY(16, uint8_t, tmp_buf, MAX_MB_PLANE * 64 * 64);
(...skipping 25 matching lines...) Expand all
2713 rate_mv = vp9_mv_bit_cost(&frame_mv[refs[0]].as_mv, 2738 rate_mv = vp9_mv_bit_cost(&frame_mv[refs[0]].as_mv,
2714 &mbmi->ref_mvs[refs[0]][0].as_mv, 2739 &mbmi->ref_mvs[refs[0]][0].as_mv,
2715 x->nmvjointcost, x->mvcost, MV_COST_WEIGHT); 2740 x->nmvjointcost, x->mvcost, MV_COST_WEIGHT);
2716 rate_mv += vp9_mv_bit_cost(&frame_mv[refs[1]].as_mv, 2741 rate_mv += vp9_mv_bit_cost(&frame_mv[refs[1]].as_mv,
2717 &mbmi->ref_mvs[refs[1]][0].as_mv, 2742 &mbmi->ref_mvs[refs[1]][0].as_mv,
2718 x->nmvjointcost, x->mvcost, MV_COST_WEIGHT); 2743 x->nmvjointcost, x->mvcost, MV_COST_WEIGHT);
2719 } 2744 }
2720 *rate2 += rate_mv; 2745 *rate2 += rate_mv;
2721 } else { 2746 } else {
2722 int_mv tmp_mv; 2747 int_mv tmp_mv;
2723 single_motion_search(cpi, x, tile, bsize, mi_row, mi_col, 2748 single_motion_search(cpi, x, bsize, mi_row, mi_col,
2724 &tmp_mv, &rate_mv); 2749 &tmp_mv, &rate_mv);
2725 if (tmp_mv.as_int == INVALID_MV) 2750 if (tmp_mv.as_int == INVALID_MV)
2726 return INT64_MAX; 2751 return INT64_MAX;
2727 *rate2 += rate_mv; 2752 *rate2 += rate_mv;
2728 frame_mv[refs[0]].as_int = 2753 frame_mv[refs[0]].as_int =
2729 xd->mi_8x8[0]->bmi[0].as_mv[0].as_int = tmp_mv.as_int; 2754 xd->mi[0]->bmi[0].as_mv[0].as_int = tmp_mv.as_int;
2730 single_newmv[refs[0]].as_int = tmp_mv.as_int; 2755 single_newmv[refs[0]].as_int = tmp_mv.as_int;
2731 } 2756 }
2732 } 2757 }
2733 2758
2734 for (i = 0; i < num_refs; ++i) { 2759 for (i = 0; i < num_refs; ++i) {
2735 cur_mv[i] = frame_mv[refs[i]]; 2760 cur_mv[i] = frame_mv[refs[i]];
2736 // Clip "next_nearest" so that it does not extend to far out of image 2761 // Clip "next_nearest" so that it does not extend to far out of image
2737 if (this_mode != NEWMV) 2762 if (this_mode != NEWMV)
2738 clamp_mv2(&cur_mv[i].as_mv, xd); 2763 clamp_mv2(&cur_mv[i].as_mv, xd);
2739 2764
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
2781 *best_filter = EIGHTTAP; 2806 *best_filter = EIGHTTAP;
2782 } else { 2807 } else {
2783 int newbest; 2808 int newbest;
2784 int tmp_rate_sum = 0; 2809 int tmp_rate_sum = 0;
2785 int64_t tmp_dist_sum = 0; 2810 int64_t tmp_dist_sum = 0;
2786 2811
2787 for (i = 0; i < SWITCHABLE_FILTERS; ++i) { 2812 for (i = 0; i < SWITCHABLE_FILTERS; ++i) {
2788 int j; 2813 int j;
2789 int64_t rs_rd; 2814 int64_t rs_rd;
2790 mbmi->interp_filter = i; 2815 mbmi->interp_filter = i;
2791 xd->interp_kernel = vp9_get_interp_kernel(mbmi->interp_filter); 2816 rs = vp9_get_switchable_rate(x);
2792 rs = get_switchable_rate(x);
2793 rs_rd = RDCOST(x->rdmult, x->rddiv, rs, 0); 2817 rs_rd = RDCOST(x->rdmult, x->rddiv, rs, 0);
2794 2818
2795 if (i > 0 && intpel_mv) { 2819 if (i > 0 && intpel_mv) {
2796 rd = RDCOST(x->rdmult, x->rddiv, tmp_rate_sum, tmp_dist_sum); 2820 rd = RDCOST(x->rdmult, x->rddiv, tmp_rate_sum, tmp_dist_sum);
2797 cpi->rd_filter_cache[i] = rd; 2821 cpi->rd_filter_cache[i] = rd;
2798 cpi->rd_filter_cache[SWITCHABLE_FILTERS] = 2822 cpi->rd_filter_cache[SWITCHABLE_FILTERS] =
2799 MIN(cpi->rd_filter_cache[SWITCHABLE_FILTERS], rd + rs_rd); 2823 MIN(cpi->rd_filter_cache[SWITCHABLE_FILTERS], rd + rs_rd);
2800 if (cm->interp_filter == SWITCHABLE) 2824 if (cm->interp_filter == SWITCHABLE)
2801 rd += rs_rd; 2825 rd += rs_rd;
2802 cpi->mask_filter_rd = MAX(cpi->mask_filter_rd, rd); 2826 cpi->mask_filter_rd = MAX(cpi->mask_filter_rd, rd);
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
2852 cm->interp_filter == mbmi->interp_filter)) { 2876 cm->interp_filter == mbmi->interp_filter)) {
2853 pred_exists = 1; 2877 pred_exists = 1;
2854 } 2878 }
2855 } 2879 }
2856 restore_dst_buf(xd, orig_dst, orig_dst_stride); 2880 restore_dst_buf(xd, orig_dst, orig_dst_stride);
2857 } 2881 }
2858 } 2882 }
2859 // Set the appropriate filter 2883 // Set the appropriate filter
2860 mbmi->interp_filter = cm->interp_filter != SWITCHABLE ? 2884 mbmi->interp_filter = cm->interp_filter != SWITCHABLE ?
2861 cm->interp_filter : *best_filter; 2885 cm->interp_filter : *best_filter;
2862 xd->interp_kernel = vp9_get_interp_kernel(mbmi->interp_filter); 2886 rs = cm->interp_filter == SWITCHABLE ? vp9_get_switchable_rate(x) : 0;
2863 rs = cm->interp_filter == SWITCHABLE ? get_switchable_rate(x) : 0;
2864 2887
2865 if (pred_exists) { 2888 if (pred_exists) {
2866 if (best_needs_copy) { 2889 if (best_needs_copy) {
2867 // again temporarily set the buffers to local memory to prevent a memcpy 2890 // again temporarily set the buffers to local memory to prevent a memcpy
2868 for (i = 0; i < MAX_MB_PLANE; i++) { 2891 for (i = 0; i < MAX_MB_PLANE; i++) {
2869 xd->plane[i].dst.buf = tmp_buf + i * 64 * 64; 2892 xd->plane[i].dst.buf = tmp_buf + i * 64 * 64;
2870 xd->plane[i].dst.stride = 64; 2893 xd->plane[i].dst.stride = 64;
2871 } 2894 }
2872 } 2895 }
2873 } else { 2896 } else {
2874 // Handles the special case when a filter that is not in the 2897 // Handles the special case when a filter that is not in the
2875 // switchable list (ex. bilinear, 6-tap) is indicated at the frame level 2898 // switchable list (ex. bilinear, 6-tap) is indicated at the frame level
2876 vp9_build_inter_predictors_sb(xd, mi_row, mi_col, bsize); 2899 vp9_build_inter_predictors_sb(xd, mi_row, mi_col, bsize);
2877 } 2900 }
2878 2901
2879 if (cpi->sf.use_rd_breakout && ref_best_rd < INT64_MAX) { 2902 if (cpi->sf.use_rd_breakout && ref_best_rd < INT64_MAX) {
2880 int tmp_rate; 2903 int tmp_rate;
2881 int64_t tmp_dist; 2904 int64_t tmp_dist;
2882 model_rd_for_sb(cpi, bsize, x, xd, &tmp_rate, &tmp_dist); 2905 model_rd_for_sb(cpi, bsize, x, xd, &tmp_rate, &tmp_dist);
2883 rd = RDCOST(x->rdmult, x->rddiv, rs + tmp_rate, tmp_dist); 2906 rd = RDCOST(x->rdmult, x->rddiv, rs + tmp_rate, tmp_dist);
2884 // if current pred_error modeled rd is substantially more than the best 2907 // if current pred_error modeled rd is substantially more than the best
2885 // so far, do not bother doing full rd 2908 // so far, do not bother doing full rd
2886 if (rd / 2 > ref_best_rd) { 2909 if (rd / 2 > ref_best_rd) {
2887 restore_dst_buf(xd, orig_dst, orig_dst_stride); 2910 restore_dst_buf(xd, orig_dst, orig_dst_stride);
2888 return INT64_MAX; 2911 return INT64_MAX;
2889 } 2912 }
2890 } 2913 }
2891 2914
2892 if (cm->interp_filter == SWITCHABLE) 2915 if (cm->interp_filter == SWITCHABLE)
2893 *rate2 += get_switchable_rate(x); 2916 *rate2 += vp9_get_switchable_rate(x);
2894 2917
2895 if (!is_comp_pred) { 2918 if (!is_comp_pred) {
2896 if (cpi->active_map_enabled && x->active_ptr[0] == 0) 2919 if (!x->in_active_map) {
2920 if (psse)
2921 *psse = 0;
2922 *distortion = 0;
2897 x->skip = 1; 2923 x->skip = 1;
2898 else if (cpi->allow_encode_breakout && x->encode_breakout) { 2924 } else if (cpi->allow_encode_breakout && x->encode_breakout) {
2899 const BLOCK_SIZE y_size = get_plane_block_size(bsize, &xd->plane[0]); 2925 const BLOCK_SIZE y_size = get_plane_block_size(bsize, &xd->plane[0]);
2900 const BLOCK_SIZE uv_size = get_plane_block_size(bsize, &xd->plane[1]); 2926 const BLOCK_SIZE uv_size = get_plane_block_size(bsize, &xd->plane[1]);
2901 unsigned int var, sse; 2927 unsigned int var, sse;
2902 // Skipping threshold for ac. 2928 // Skipping threshold for ac.
2903 unsigned int thresh_ac; 2929 unsigned int thresh_ac;
2904 // Set a maximum for threshold to avoid big PSNR loss in low bitrate case. 2930 // Set a maximum for threshold to avoid big PSNR loss in low bitrate case.
2905 // Use extreme low threshold for static frames to limit skipping. 2931 // Use extreme low threshold for static frames to limit skipping.
2906 const unsigned int max_thresh = (cpi->allow_encode_breakout == 2932 const unsigned int max_thresh = (cpi->allow_encode_breakout ==
2907 ENCODE_BREAKOUT_LIMITED) ? 128 : 36000; 2933 ENCODE_BREAKOUT_LIMITED) ? 128 : 36000;
2908 // The encode_breakout input 2934 // The encode_breakout input
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
2983 restore_dst_buf(xd, orig_dst, orig_dst_stride); 3009 restore_dst_buf(xd, orig_dst, orig_dst_stride);
2984 return INT64_MAX; 3010 return INT64_MAX;
2985 } 3011 }
2986 3012
2987 *rate2 += *rate_y; 3013 *rate2 += *rate_y;
2988 *distortion += *distortion_y; 3014 *distortion += *distortion_y;
2989 3015
2990 rdcosty = RDCOST(x->rdmult, x->rddiv, *rate2, *distortion); 3016 rdcosty = RDCOST(x->rdmult, x->rddiv, *rate2, *distortion);
2991 rdcosty = MIN(rdcosty, RDCOST(x->rdmult, x->rddiv, 0, *psse)); 3017 rdcosty = MIN(rdcosty, RDCOST(x->rdmult, x->rddiv, 0, *psse));
2992 3018
2993 super_block_uvrd(x, rate_uv, distortion_uv, &skippable_uv, &sseuv, 3019 super_block_uvrd(cpi, x, rate_uv, distortion_uv, &skippable_uv, &sseuv,
2994 bsize, ref_best_rd - rdcosty); 3020 bsize, ref_best_rd - rdcosty);
2995 if (*rate_uv == INT_MAX) { 3021 if (*rate_uv == INT_MAX) {
2996 *rate2 = INT_MAX; 3022 *rate2 = INT_MAX;
2997 *distortion = INT64_MAX; 3023 *distortion = INT64_MAX;
2998 restore_dst_buf(xd, orig_dst, orig_dst_stride); 3024 restore_dst_buf(xd, orig_dst, orig_dst_stride);
2999 return INT64_MAX; 3025 return INT64_MAX;
3000 } 3026 }
3001 3027
3002 *psse += sseuv; 3028 *psse += sseuv;
3003 *rate2 += *rate_uv; 3029 *rate2 += *rate_uv;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
3038 BLOCK_SIZE bsize, 3064 BLOCK_SIZE bsize,
3039 PICK_MODE_CONTEXT *ctx, int64_t best_rd) { 3065 PICK_MODE_CONTEXT *ctx, int64_t best_rd) {
3040 VP9_COMMON *const cm = &cpi->common; 3066 VP9_COMMON *const cm = &cpi->common;
3041 MACROBLOCKD *const xd = &x->e_mbd; 3067 MACROBLOCKD *const xd = &x->e_mbd;
3042 int rate_y = 0, rate_uv = 0, rate_y_tokenonly = 0, rate_uv_tokenonly = 0; 3068 int rate_y = 0, rate_uv = 0, rate_y_tokenonly = 0, rate_uv_tokenonly = 0;
3043 int y_skip = 0, uv_skip = 0; 3069 int y_skip = 0, uv_skip = 0;
3044 int64_t dist_y = 0, dist_uv = 0, tx_cache[TX_MODES] = { 0 }; 3070 int64_t dist_y = 0, dist_uv = 0, tx_cache[TX_MODES] = { 0 };
3045 TX_SIZE max_uv_tx_size; 3071 TX_SIZE max_uv_tx_size;
3046 x->skip_encode = 0; 3072 x->skip_encode = 0;
3047 ctx->skip = 0; 3073 ctx->skip = 0;
3048 xd->mi_8x8[0]->mbmi.ref_frame[0] = INTRA_FRAME; 3074 xd->mi[0]->mbmi.ref_frame[0] = INTRA_FRAME;
3049 3075
3050 if (bsize >= BLOCK_8X8) { 3076 if (bsize >= BLOCK_8X8) {
3051 if (rd_pick_intra_sby_mode(cpi, x, &rate_y, &rate_y_tokenonly, 3077 if (rd_pick_intra_sby_mode(cpi, x, &rate_y, &rate_y_tokenonly,
3052 &dist_y, &y_skip, bsize, tx_cache, 3078 &dist_y, &y_skip, bsize, tx_cache,
3053 best_rd) >= best_rd) { 3079 best_rd) >= best_rd) {
3054 *returnrate = INT_MAX; 3080 *returnrate = INT_MAX;
3055 return; 3081 return;
3056 } 3082 }
3057 max_uv_tx_size = get_uv_tx_size_impl(xd->mi_8x8[0]->mbmi.tx_size, bsize); 3083 max_uv_tx_size = get_uv_tx_size_impl(xd->mi[0]->mbmi.tx_size, bsize);
3058 rd_pick_intra_sbuv_mode(cpi, x, ctx, &rate_uv, &rate_uv_tokenonly, 3084 rd_pick_intra_sbuv_mode(cpi, x, ctx, &rate_uv, &rate_uv_tokenonly,
3059 &dist_uv, &uv_skip, bsize, max_uv_tx_size); 3085 &dist_uv, &uv_skip, bsize, max_uv_tx_size);
3060 } else { 3086 } else {
3061 y_skip = 0; 3087 y_skip = 0;
3062 if (rd_pick_intra_sub_8x8_y_mode(cpi, x, &rate_y, &rate_y_tokenonly, 3088 if (rd_pick_intra_sub_8x8_y_mode(cpi, x, &rate_y, &rate_y_tokenonly,
3063 &dist_y, best_rd) >= best_rd) { 3089 &dist_y, best_rd) >= best_rd) {
3064 *returnrate = INT_MAX; 3090 *returnrate = INT_MAX;
3065 return; 3091 return;
3066 } 3092 }
3067 max_uv_tx_size = get_uv_tx_size_impl(xd->mi_8x8[0]->mbmi.tx_size, bsize); 3093 max_uv_tx_size = get_uv_tx_size_impl(xd->mi[0]->mbmi.tx_size, bsize);
3068 rd_pick_intra_sbuv_mode(cpi, x, ctx, &rate_uv, &rate_uv_tokenonly, 3094 rd_pick_intra_sbuv_mode(cpi, x, ctx, &rate_uv, &rate_uv_tokenonly,
3069 &dist_uv, &uv_skip, BLOCK_8X8, max_uv_tx_size); 3095 &dist_uv, &uv_skip, BLOCK_8X8, max_uv_tx_size);
3070 } 3096 }
3071 3097
3072 if (y_skip && uv_skip) { 3098 if (y_skip && uv_skip) {
3073 *returnrate = rate_y + rate_uv - rate_y_tokenonly - rate_uv_tokenonly + 3099 *returnrate = rate_y + rate_uv - rate_y_tokenonly - rate_uv_tokenonly +
3074 vp9_cost_bit(vp9_get_skip_prob(cm, xd), 1); 3100 vp9_cost_bit(vp9_get_skip_prob(cm, xd), 1);
3075 *returndist = dist_y + dist_uv; 3101 *returndist = dist_y + dist_uv;
3076 vp9_zero(ctx->tx_rd_diff); 3102 vp9_zero(ctx->tx_rd_diff);
3077 } else { 3103 } else {
3078 int i; 3104 int i;
3079 *returnrate = rate_y + rate_uv + vp9_cost_bit(vp9_get_skip_prob(cm, xd), 0); 3105 *returnrate = rate_y + rate_uv + vp9_cost_bit(vp9_get_skip_prob(cm, xd), 0);
3080 *returndist = dist_y + dist_uv; 3106 *returndist = dist_y + dist_uv;
3081 if (cpi->sf.tx_size_search_method == USE_FULL_RD) 3107 if (cpi->sf.tx_size_search_method == USE_FULL_RD)
3082 for (i = 0; i < TX_MODES; i++) { 3108 for (i = 0; i < TX_MODES; i++) {
3083 if (tx_cache[i] < INT64_MAX && tx_cache[cm->tx_mode] < INT64_MAX) 3109 if (tx_cache[i] < INT64_MAX && tx_cache[cm->tx_mode] < INT64_MAX)
3084 ctx->tx_rd_diff[i] = tx_cache[i] - tx_cache[cm->tx_mode]; 3110 ctx->tx_rd_diff[i] = tx_cache[i] - tx_cache[cm->tx_mode];
3085 else 3111 else
3086 ctx->tx_rd_diff[i] = 0; 3112 ctx->tx_rd_diff[i] = 0;
3087 } 3113 }
3088 } 3114 }
3089 3115
3090 ctx->mic = *xd->mi_8x8[0]; 3116 ctx->mic = *xd->mi[0];
3091 } 3117 }
3092 3118
3093 int64_t vp9_rd_pick_inter_mode_sb(VP9_COMP *cpi, MACROBLOCK *x, 3119 int64_t vp9_rd_pick_inter_mode_sb(VP9_COMP *cpi, MACROBLOCK *x,
3094 const TileInfo *const tile, 3120 const TileInfo *const tile,
3095 int mi_row, int mi_col, 3121 int mi_row, int mi_col,
3096 int *returnrate, 3122 int *returnrate,
3097 int64_t *returndistortion, 3123 int64_t *returndistortion,
3098 BLOCK_SIZE bsize, 3124 BLOCK_SIZE bsize,
3099 PICK_MODE_CONTEXT *ctx, 3125 PICK_MODE_CONTEXT *ctx,
3100 int64_t best_rd_so_far) { 3126 int64_t best_rd_so_far) {
3101 VP9_COMMON *const cm = &cpi->common; 3127 VP9_COMMON *const cm = &cpi->common;
3102 MACROBLOCKD *const xd = &x->e_mbd; 3128 MACROBLOCKD *const xd = &x->e_mbd;
3103 MB_MODE_INFO *const mbmi = &xd->mi_8x8[0]->mbmi; 3129 MB_MODE_INFO *const mbmi = &xd->mi[0]->mbmi;
3104 const struct segmentation *const seg = &cm->seg; 3130 const struct segmentation *const seg = &cm->seg;
3105 const BLOCK_SIZE block_size = get_plane_block_size(bsize, &xd->plane[0]);
3106 MB_PREDICTION_MODE this_mode; 3131 MB_PREDICTION_MODE this_mode;
3107 MV_REFERENCE_FRAME ref_frame, second_ref_frame; 3132 MV_REFERENCE_FRAME ref_frame, second_ref_frame;
3108 unsigned char segment_id = mbmi->segment_id; 3133 unsigned char segment_id = mbmi->segment_id;
3109 int comp_pred, i; 3134 int comp_pred, i;
3110 int_mv frame_mv[MB_MODE_COUNT][MAX_REF_FRAMES]; 3135 int_mv frame_mv[MB_MODE_COUNT][MAX_REF_FRAMES];
3111 struct buf_2d yv12_mb[4][MAX_MB_PLANE]; 3136 struct buf_2d yv12_mb[4][MAX_MB_PLANE];
3112 int_mv single_newmv[MAX_REF_FRAMES] = { { 0 } }; 3137 int_mv single_newmv[MAX_REF_FRAMES] = { { 0 } };
3113 static const int flag_list[4] = { 0, VP9_LAST_FLAG, VP9_GOLD_FLAG, 3138 static const int flag_list[4] = { 0, VP9_LAST_FLAG, VP9_GOLD_FLAG,
3114 VP9_ALT_FLAG }; 3139 VP9_ALT_FLAG };
3115 int64_t best_rd = best_rd_so_far; 3140 int64_t best_rd = best_rd_so_far;
3116 int64_t best_tx_rd[TX_MODES]; 3141 int64_t best_tx_rd[TX_MODES];
3117 int64_t best_tx_diff[TX_MODES]; 3142 int64_t best_tx_diff[TX_MODES];
3118 int64_t best_pred_diff[REFERENCE_MODES]; 3143 int64_t best_pred_diff[REFERENCE_MODES];
3119 int64_t best_pred_rd[REFERENCE_MODES]; 3144 int64_t best_pred_rd[REFERENCE_MODES];
3120 int64_t best_filter_rd[SWITCHABLE_FILTER_CONTEXTS]; 3145 int64_t best_filter_rd[SWITCHABLE_FILTER_CONTEXTS];
3121 int64_t best_filter_diff[SWITCHABLE_FILTER_CONTEXTS]; 3146 int64_t best_filter_diff[SWITCHABLE_FILTER_CONTEXTS];
3122 MB_MODE_INFO best_mbmode = { 0 }; 3147 MB_MODE_INFO best_mbmode = { 0 };
3123 int mode_index, best_mode_index = 0; 3148 int mode_index, best_mode_index = -1;
3124 unsigned int ref_costs_single[MAX_REF_FRAMES], ref_costs_comp[MAX_REF_FRAMES]; 3149 unsigned int ref_costs_single[MAX_REF_FRAMES], ref_costs_comp[MAX_REF_FRAMES];
3125 vp9_prob comp_mode_p; 3150 vp9_prob comp_mode_p;
3126 int64_t best_intra_rd = INT64_MAX; 3151 int64_t best_intra_rd = INT64_MAX;
3127 int64_t best_inter_rd = INT64_MAX; 3152 int64_t best_inter_rd = INT64_MAX;
3128 MB_PREDICTION_MODE best_intra_mode = DC_PRED; 3153 MB_PREDICTION_MODE best_intra_mode = DC_PRED;
3129 MV_REFERENCE_FRAME best_inter_ref_frame = LAST_FRAME; 3154 MV_REFERENCE_FRAME best_inter_ref_frame = LAST_FRAME;
3130 INTERP_FILTER tmp_best_filter = SWITCHABLE; 3155 INTERP_FILTER tmp_best_filter = SWITCHABLE;
3131 int rate_uv_intra[TX_SIZES], rate_uv_tokenonly[TX_SIZES]; 3156 int rate_uv_intra[TX_SIZES], rate_uv_tokenonly[TX_SIZES];
3132 int64_t dist_uv[TX_SIZES]; 3157 int64_t dist_uv[TX_SIZES];
3133 int skip_uv[TX_SIZES]; 3158 int skip_uv[TX_SIZES];
3134 MB_PREDICTION_MODE mode_uv[TX_SIZES]; 3159 MB_PREDICTION_MODE mode_uv[TX_SIZES];
3135 int64_t mode_distortions[MB_MODE_COUNT] = {-1}; 3160 int64_t mode_distortions[MB_MODE_COUNT] = {-1};
3136 int intra_cost_penalty = 20 * vp9_dc_quant(cm->base_qindex, cm->y_dc_delta_q); 3161 int intra_cost_penalty = 20 * vp9_dc_quant(cm->base_qindex, cm->y_dc_delta_q);
3137 const int bws = num_8x8_blocks_wide_lookup[bsize] / 2; 3162 const int bws = num_8x8_blocks_wide_lookup[bsize] / 2;
3138 const int bhs = num_8x8_blocks_high_lookup[bsize] / 2; 3163 const int bhs = num_8x8_blocks_high_lookup[bsize] / 2;
3139 int best_skip2 = 0; 3164 int best_skip2 = 0;
3140 int mode_skip_mask = 0; 3165 int mode_skip_mask = 0;
3141 const int mode_skip_start = cpi->sf.mode_skip_start + 1; 3166 int mode_skip_start = cpi->sf.mode_skip_start + 1;
3142 const int *const rd_threshes = cpi->rd_threshes[segment_id][bsize]; 3167 const int *const rd_threshes = cpi->rd_threshes[segment_id][bsize];
3143 const int *const rd_thresh_freq_fact = cpi->rd_thresh_freq_fact[bsize]; 3168 const int *const rd_thresh_freq_fact = cpi->rd_thresh_freq_fact[bsize];
3144 const int mode_search_skip_flags = cpi->sf.mode_search_skip_flags; 3169 const int mode_search_skip_flags = cpi->sf.mode_search_skip_flags;
3145 const int intra_y_mode_mask = 3170 const int intra_y_mode_mask =
3146 cpi->sf.intra_y_mode_mask[max_txsize_lookup[bsize]]; 3171 cpi->sf.intra_y_mode_mask[max_txsize_lookup[bsize]];
3172 int disable_inter_mode_mask = cpi->sf.disable_inter_mode_mask[bsize];
3147 3173
3148 x->skip_encode = cpi->sf.skip_encode_frame && x->q_index < QIDX_SKIP_THRESH; 3174 x->skip_encode = cpi->sf.skip_encode_frame && x->q_index < QIDX_SKIP_THRESH;
3149 3175
3150 estimate_ref_frame_costs(cpi, segment_id, ref_costs_single, ref_costs_comp, 3176 estimate_ref_frame_costs(cpi, segment_id, ref_costs_single, ref_costs_comp,
3151 &comp_mode_p); 3177 &comp_mode_p);
3152 3178
3153 for (i = 0; i < REFERENCE_MODES; ++i) 3179 for (i = 0; i < REFERENCE_MODES; ++i)
3154 best_pred_rd[i] = INT64_MAX; 3180 best_pred_rd[i] = INT64_MAX;
3155 for (i = 0; i < TX_MODES; i++) 3181 for (i = 0; i < TX_MODES; i++)
3156 best_tx_rd[i] = INT64_MAX; 3182 best_tx_rd[i] = INT64_MAX;
3157 for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; i++) 3183 for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; i++)
3158 best_filter_rd[i] = INT64_MAX; 3184 best_filter_rd[i] = INT64_MAX;
3159 for (i = 0; i < TX_SIZES; i++) 3185 for (i = 0; i < TX_SIZES; i++)
3160 rate_uv_intra[i] = INT_MAX; 3186 rate_uv_intra[i] = INT_MAX;
3161 for (i = 0; i < MAX_REF_FRAMES; ++i) 3187 for (i = 0; i < MAX_REF_FRAMES; ++i)
3162 x->pred_sse[i] = INT_MAX; 3188 x->pred_sse[i] = INT_MAX;
3163 3189
3164 *returnrate = INT_MAX; 3190 *returnrate = INT_MAX;
3165 3191
3166 for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) { 3192 for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) {
3167 x->pred_mv_sad[ref_frame] = INT_MAX; 3193 x->pred_mv_sad[ref_frame] = INT_MAX;
3168 if (cpi->ref_frame_flags & flag_list[ref_frame]) { 3194 if (cpi->ref_frame_flags & flag_list[ref_frame]) {
3169 vp9_setup_buffer_inter(cpi, x, tile, 3195 vp9_setup_buffer_inter(cpi, x, tile,
3170 ref_frame, block_size, mi_row, mi_col, 3196 ref_frame, bsize, mi_row, mi_col,
3171 frame_mv[NEARESTMV], frame_mv[NEARMV], yv12_mb); 3197 frame_mv[NEARESTMV], frame_mv[NEARMV], yv12_mb);
3172 } 3198 }
3173 frame_mv[NEWMV][ref_frame].as_int = INVALID_MV; 3199 frame_mv[NEWMV][ref_frame].as_int = INVALID_MV;
3174 frame_mv[ZEROMV][ref_frame].as_int = 0; 3200 frame_mv[ZEROMV][ref_frame].as_int = 0;
3175 } 3201 }
3176 3202
3177 for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) { 3203 for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) {
3178 // All modes from vp9_mode_order that use this frame as any ref 3204 // All modes from vp9_mode_order that use this frame as any ref
3179 static const int ref_frame_mask_all[] = { 3205 static const int ref_frame_mask_all[] = {
3180 0x0, 0x123291, 0x25c444, 0x39b722 3206 0x0, 0x123291, 0x25c444, 0x39b722
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
3235 // should fix this either by making the motion search just work on 3261 // should fix this either by making the motion search just work on
3236 // a representative block in the boundary ( first ) and then implement a 3262 // a representative block in the boundary ( first ) and then implement a
3237 // function that does sads when inside the border.. 3263 // function that does sads when inside the border..
3238 if ((mi_row + bhs) > cm->mi_rows || (mi_col + bws) > cm->mi_cols) { 3264 if ((mi_row + bhs) > cm->mi_rows || (mi_col + bws) > cm->mi_cols) {
3239 const int new_modes_mask = 3265 const int new_modes_mask =
3240 (1 << THR_NEWMV) | (1 << THR_NEWG) | (1 << THR_NEWA) | 3266 (1 << THR_NEWMV) | (1 << THR_NEWG) | (1 << THR_NEWA) |
3241 (1 << THR_COMP_NEWLA) | (1 << THR_COMP_NEWGA); 3267 (1 << THR_COMP_NEWLA) | (1 << THR_COMP_NEWGA);
3242 mode_skip_mask |= new_modes_mask; 3268 mode_skip_mask |= new_modes_mask;
3243 } 3269 }
3244 3270
3271 if (bsize > cpi->sf.max_intra_bsize) {
3272 mode_skip_mask |= 0xFF30808;
3273 }
3274
3275 if (!x->in_active_map) {
3276 int mode_index;
3277 assert(cpi->ref_frame_flags & VP9_LAST_FLAG);
3278 if (frame_mv[NEARESTMV][LAST_FRAME].as_int == 0)
3279 mode_index = THR_NEARESTMV;
3280 else if (frame_mv[NEARMV][LAST_FRAME].as_int == 0)
3281 mode_index = THR_NEARMV;
3282 else
3283 mode_index = THR_ZEROMV;
3284 mode_skip_mask = ~(1 << mode_index);
3285 mode_skip_start = MAX_MODES;
3286 disable_inter_mode_mask = 0;
3287 }
3288
3245 for (mode_index = 0; mode_index < MAX_MODES; ++mode_index) { 3289 for (mode_index = 0; mode_index < MAX_MODES; ++mode_index) {
3246 int mode_excluded = 0; 3290 int mode_excluded = 0;
3247 int64_t this_rd = INT64_MAX; 3291 int64_t this_rd = INT64_MAX;
3248 int disable_skip = 0; 3292 int disable_skip = 0;
3249 int compmode_cost = 0; 3293 int compmode_cost = 0;
3250 int rate2 = 0, rate_y = 0, rate_uv = 0; 3294 int rate2 = 0, rate_y = 0, rate_uv = 0;
3251 int64_t distortion2 = 0, distortion_y = 0, distortion_uv = 0; 3295 int64_t distortion2 = 0, distortion_y = 0, distortion_uv = 0;
3252 int skippable = 0; 3296 int skippable = 0;
3253 int64_t tx_cache[TX_MODES]; 3297 int64_t tx_cache[TX_MODES];
3254 int i; 3298 int i;
3255 int this_skip2 = 0; 3299 int this_skip2 = 0;
3256 int64_t total_sse = INT64_MAX; 3300 int64_t total_sse = INT64_MAX;
3257 int early_term = 0; 3301 int early_term = 0;
3258 3302
3259 // Look at the reference frame of the best mode so far and set the 3303 // Look at the reference frame of the best mode so far and set the
3260 // skip mask to look at a subset of the remaining modes. 3304 // skip mask to look at a subset of the remaining modes.
3261 if (mode_index == mode_skip_start) { 3305 if (mode_index == mode_skip_start && best_mode_index >= 0) {
3262 switch (vp9_mode_order[best_mode_index].ref_frame[0]) { 3306 switch (vp9_mode_order[best_mode_index].ref_frame[0]) {
3263 case INTRA_FRAME: 3307 case INTRA_FRAME:
3264 break; 3308 break;
3265 case LAST_FRAME: 3309 case LAST_FRAME:
3266 mode_skip_mask |= LAST_FRAME_MODE_MASK; 3310 mode_skip_mask |= LAST_FRAME_MODE_MASK;
3267 break; 3311 break;
3268 case GOLDEN_FRAME: 3312 case GOLDEN_FRAME:
3269 mode_skip_mask |= GOLDEN_FRAME_MODE_MASK; 3313 mode_skip_mask |= GOLDEN_FRAME_MODE_MASK;
3270 break; 3314 break;
3271 case ALTREF_FRAME: 3315 case ALTREF_FRAME:
3272 mode_skip_mask |= ALT_REF_MODE_MASK; 3316 mode_skip_mask |= ALT_REF_MODE_MASK;
3273 break; 3317 break;
3274 case NONE: 3318 case NONE:
3275 case MAX_REF_FRAMES: 3319 case MAX_REF_FRAMES:
3276 assert(0 && "Invalid Reference frame"); 3320 assert(0 && "Invalid Reference frame");
3277 } 3321 }
3278 } 3322 }
3279 if (mode_skip_mask & (1 << mode_index)) 3323 if (mode_skip_mask & (1 << mode_index))
3280 continue; 3324 continue;
3281 3325
3282 // Test best rd so far against threshold for trying this mode. 3326 // Test best rd so far against threshold for trying this mode.
3283 if (best_rd < ((int64_t)rd_threshes[mode_index] * 3327 if (best_rd < ((int64_t)rd_threshes[mode_index] *
3284 rd_thresh_freq_fact[mode_index] >> 5) || 3328 rd_thresh_freq_fact[mode_index] >> 5) ||
3285 rd_threshes[mode_index] == INT_MAX) 3329 rd_threshes[mode_index] == INT_MAX)
3286 continue; 3330 continue;
3287 3331
3288 this_mode = vp9_mode_order[mode_index].mode; 3332 this_mode = vp9_mode_order[mode_index].mode;
3289 ref_frame = vp9_mode_order[mode_index].ref_frame[0]; 3333 ref_frame = vp9_mode_order[mode_index].ref_frame[0];
3290 if (ref_frame != INTRA_FRAME && 3334 if (ref_frame != INTRA_FRAME &&
3291 cpi->sf.disable_inter_mode_mask[bsize] & (1 << INTER_OFFSET(this_mode))) 3335 disable_inter_mode_mask & (1 << INTER_OFFSET(this_mode)))
3292 continue; 3336 continue;
3293 second_ref_frame = vp9_mode_order[mode_index].ref_frame[1]; 3337 second_ref_frame = vp9_mode_order[mode_index].ref_frame[1];
3294 3338
3295 comp_pred = second_ref_frame > INTRA_FRAME; 3339 comp_pred = second_ref_frame > INTRA_FRAME;
3296 if (comp_pred) { 3340 if (comp_pred) {
3297 if ((mode_search_skip_flags & FLAG_SKIP_COMP_BESTINTRA) && 3341 if ((mode_search_skip_flags & FLAG_SKIP_COMP_BESTINTRA) &&
3342 best_mode_index >=0 &&
3298 vp9_mode_order[best_mode_index].ref_frame[0] == INTRA_FRAME) 3343 vp9_mode_order[best_mode_index].ref_frame[0] == INTRA_FRAME)
3299 continue; 3344 continue;
3300 if ((mode_search_skip_flags & FLAG_SKIP_COMP_REFMISMATCH) && 3345 if ((mode_search_skip_flags & FLAG_SKIP_COMP_REFMISMATCH) &&
3301 ref_frame != best_inter_ref_frame && 3346 ref_frame != best_inter_ref_frame &&
3302 second_ref_frame != best_inter_ref_frame) 3347 second_ref_frame != best_inter_ref_frame)
3303 continue; 3348 continue;
3304 mode_excluded = cm->reference_mode == SINGLE_REFERENCE; 3349 mode_excluded = cm->reference_mode == SINGLE_REFERENCE;
3305 } else { 3350 } else {
3306 if (ref_frame != INTRA_FRAME) 3351 if (ref_frame != INTRA_FRAME)
3307 mode_excluded = cm->reference_mode == COMPOUND_REFERENCE; 3352 mode_excluded = cm->reference_mode == COMPOUND_REFERENCE;
3308 } 3353 }
3309 3354
3310 if (ref_frame == INTRA_FRAME) { 3355 if (ref_frame == INTRA_FRAME) {
3311 if (!(intra_y_mode_mask & (1 << this_mode))) 3356 if (!(intra_y_mode_mask & (1 << this_mode)))
3312 continue; 3357 continue;
3313 if (this_mode != DC_PRED) { 3358 if (this_mode != DC_PRED) {
3314 // Disable intra modes other than DC_PRED for blocks with low variance 3359 // Disable intra modes other than DC_PRED for blocks with low variance
3315 // Threshold for intra skipping based on source variance 3360 // Threshold for intra skipping based on source variance
3316 // TODO(debargha): Specialize the threshold for super block sizes 3361 // TODO(debargha): Specialize the threshold for super block sizes
3317 const unsigned int skip_intra_var_thresh = 64; 3362 const unsigned int skip_intra_var_thresh = 64;
3318 if ((mode_search_skip_flags & FLAG_SKIP_INTRA_LOWVAR) && 3363 if ((mode_search_skip_flags & FLAG_SKIP_INTRA_LOWVAR) &&
3319 x->source_variance < skip_intra_var_thresh) 3364 x->source_variance < skip_intra_var_thresh)
3320 continue; 3365 continue;
3321 // Only search the oblique modes if the best so far is 3366 // Only search the oblique modes if the best so far is
3322 // one of the neighboring directional modes 3367 // one of the neighboring directional modes
3323 if ((mode_search_skip_flags & FLAG_SKIP_INTRA_BESTINTER) && 3368 if ((mode_search_skip_flags & FLAG_SKIP_INTRA_BESTINTER) &&
3324 (this_mode >= D45_PRED && this_mode <= TM_PRED)) { 3369 (this_mode >= D45_PRED && this_mode <= TM_PRED)) {
3325 if (vp9_mode_order[best_mode_index].ref_frame[0] > INTRA_FRAME) 3370 if (best_mode_index >= 0 &&
3371 vp9_mode_order[best_mode_index].ref_frame[0] > INTRA_FRAME)
3326 continue; 3372 continue;
3327 } 3373 }
3328 if (mode_search_skip_flags & FLAG_SKIP_INTRA_DIRMISMATCH) { 3374 if (mode_search_skip_flags & FLAG_SKIP_INTRA_DIRMISMATCH) {
3329 if (conditional_skipintra(this_mode, best_intra_mode)) 3375 if (conditional_skipintra(this_mode, best_intra_mode))
3330 continue; 3376 continue;
3331 } 3377 }
3332 } 3378 }
3333 } else { 3379 } else {
3334 // if we're near/nearest and mv == 0,0, compare to zeromv 3380 if (x->in_active_map &&
3335 if ((this_mode == NEARMV || this_mode == NEARESTMV || 3381 !vp9_segfeature_active(&cm->seg, mbmi->segment_id, SEG_LVL_SKIP))
3336 this_mode == ZEROMV) && 3382 if (!check_best_zero_mv(cpi, mbmi->mode_context, frame_mv,
3337 frame_mv[this_mode][ref_frame].as_int == 0 && 3383 disable_inter_mode_mask, this_mode, ref_frame,
3338 !vp9_segfeature_active(&cm->seg, mbmi->segment_id, SEG_LVL_SKIP) && 3384 second_ref_frame))
3339 (!comp_pred || frame_mv[this_mode][second_ref_frame].as_int == 0)) { 3385 continue;
3340 int rfc = mbmi->mode_context[ref_frame];
3341 int c1 = cost_mv_ref(cpi, NEARMV, rfc);
3342 int c2 = cost_mv_ref(cpi, NEARESTMV, rfc);
3343 int c3 = cost_mv_ref(cpi, ZEROMV, rfc);
3344
3345 if (this_mode == NEARMV) {
3346 if (c1 > c3)
3347 continue;
3348 } else if (this_mode == NEARESTMV) {
3349 if (c2 > c3)
3350 continue;
3351 } else {
3352 assert(this_mode == ZEROMV);
3353 if (!comp_pred) {
3354 if ((c3 >= c2 &&
3355 frame_mv[NEARESTMV][ref_frame].as_int == 0) ||
3356 (c3 >= c1 &&
3357 frame_mv[NEARMV][ref_frame].as_int == 0))
3358 continue;
3359 } else {
3360 if ((c3 >= c2 &&
3361 frame_mv[NEARESTMV][ref_frame].as_int == 0 &&
3362 frame_mv[NEARESTMV][second_ref_frame].as_int == 0) ||
3363 (c3 >= c1 &&
3364 frame_mv[NEARMV][ref_frame].as_int == 0 &&
3365 frame_mv[NEARMV][second_ref_frame].as_int == 0))
3366 continue;
3367 }
3368 }
3369 }
3370 } 3386 }
3371 3387
3372 mbmi->mode = this_mode; 3388 mbmi->mode = this_mode;
3373 mbmi->uv_mode = DC_PRED; 3389 mbmi->uv_mode = x->in_active_map ? DC_PRED : this_mode;
3374 mbmi->ref_frame[0] = ref_frame; 3390 mbmi->ref_frame[0] = ref_frame;
3375 mbmi->ref_frame[1] = second_ref_frame; 3391 mbmi->ref_frame[1] = second_ref_frame;
3376 // Evaluate all sub-pel filters irrespective of whether we can use 3392 // Evaluate all sub-pel filters irrespective of whether we can use
3377 // them for this frame. 3393 // them for this frame.
3378 mbmi->interp_filter = cm->interp_filter == SWITCHABLE ? EIGHTTAP 3394 mbmi->interp_filter = cm->interp_filter == SWITCHABLE ? EIGHTTAP
3379 : cm->interp_filter; 3395 : cm->interp_filter;
3380 x->skip = 0; 3396 x->skip = 0;
3381 set_ref_ptrs(cm, xd, ref_frame, second_ref_frame); 3397 set_ref_ptrs(cm, xd, ref_frame, second_ref_frame);
3382 xd->interp_kernel = vp9_get_interp_kernel(mbmi->interp_filter);
3383 3398
3384 // Select prediction reference frames. 3399 // Select prediction reference frames.
3385 for (i = 0; i < MAX_MB_PLANE; i++) { 3400 for (i = 0; i < MAX_MB_PLANE; i++) {
3386 xd->plane[i].pre[0] = yv12_mb[ref_frame][i]; 3401 xd->plane[i].pre[0] = yv12_mb[ref_frame][i];
3387 if (comp_pred) 3402 if (comp_pred)
3388 xd->plane[i].pre[1] = yv12_mb[second_ref_frame][i]; 3403 xd->plane[i].pre[1] = yv12_mb[second_ref_frame][i];
3389 } 3404 }
3390 3405
3391 for (i = 0; i < TX_MODES; ++i) 3406 for (i = 0; i < TX_MODES; ++i)
3392 tx_cache[i] = INT64_MAX; 3407 tx_cache[i] = INT64_MAX;
(...skipping 22 matching lines...) Expand all
3415 rate_uv = rate_uv_tokenonly[uv_tx]; 3430 rate_uv = rate_uv_tokenonly[uv_tx];
3416 distortion_uv = dist_uv[uv_tx]; 3431 distortion_uv = dist_uv[uv_tx];
3417 skippable = skippable && skip_uv[uv_tx]; 3432 skippable = skippable && skip_uv[uv_tx];
3418 mbmi->uv_mode = mode_uv[uv_tx]; 3433 mbmi->uv_mode = mode_uv[uv_tx];
3419 3434
3420 rate2 = rate_y + x->mbmode_cost[mbmi->mode] + rate_uv_intra[uv_tx]; 3435 rate2 = rate_y + x->mbmode_cost[mbmi->mode] + rate_uv_intra[uv_tx];
3421 if (this_mode != DC_PRED && this_mode != TM_PRED) 3436 if (this_mode != DC_PRED && this_mode != TM_PRED)
3422 rate2 += intra_cost_penalty; 3437 rate2 += intra_cost_penalty;
3423 distortion2 = distortion_y + distortion_uv; 3438 distortion2 = distortion_y + distortion_uv;
3424 } else { 3439 } else {
3425 this_rd = handle_inter_mode(cpi, x, tile, bsize, 3440 this_rd = handle_inter_mode(cpi, x, bsize,
3426 tx_cache, 3441 tx_cache,
3427 &rate2, &distortion2, &skippable, 3442 &rate2, &distortion2, &skippable,
3428 &rate_y, &distortion_y, 3443 &rate_y, &distortion_y,
3429 &rate_uv, &distortion_uv, 3444 &rate_uv, &distortion_uv,
3430 &mode_excluded, &disable_skip, 3445 &mode_excluded, &disable_skip,
3431 &tmp_best_filter, frame_mv, 3446 &tmp_best_filter, frame_mv,
3432 mi_row, mi_col, 3447 mi_row, mi_col,
3433 single_newmv, &total_sse, best_rd); 3448 single_newmv, &total_sse, best_rd);
3434 if (this_rd == INT64_MAX) 3449 if (this_rd == INT64_MAX)
3435 continue; 3450 continue;
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
3634 } 3649 }
3635 } 3650 }
3636 3651
3637 if (early_term) 3652 if (early_term)
3638 break; 3653 break;
3639 3654
3640 if (x->skip && !comp_pred) 3655 if (x->skip && !comp_pred)
3641 break; 3656 break;
3642 } 3657 }
3643 3658
3644 if (best_rd >= best_rd_so_far) 3659 if (best_mode_index < 0 || best_rd >= best_rd_so_far)
3645 return INT64_MAX; 3660 return INT64_MAX;
3646 3661
3647 // If we used an estimate for the uv intra rd in the loop above... 3662 // If we used an estimate for the uv intra rd in the loop above...
3648 if (cpi->sf.use_uv_intra_rd_estimate) { 3663 if (cpi->sf.use_uv_intra_rd_estimate) {
3649 // Do Intra UV best rd mode selection if best mode choice above was intra. 3664 // Do Intra UV best rd mode selection if best mode choice above was intra.
3650 if (vp9_mode_order[best_mode_index].ref_frame[0] == INTRA_FRAME) { 3665 if (vp9_mode_order[best_mode_index].ref_frame[0] == INTRA_FRAME) {
3651 TX_SIZE uv_tx_size; 3666 TX_SIZE uv_tx_size;
3652 *mbmi = best_mbmode; 3667 *mbmi = best_mbmode;
3653 uv_tx_size = get_uv_tx_size(mbmi); 3668 uv_tx_size = get_uv_tx_size(mbmi);
3654 rd_pick_intra_sbuv_mode(cpi, x, ctx, &rate_uv_intra[uv_tx_size], 3669 rd_pick_intra_sbuv_mode(cpi, x, ctx, &rate_uv_intra[uv_tx_size],
3655 &rate_uv_tokenonly[uv_tx_size], 3670 &rate_uv_tokenonly[uv_tx_size],
3656 &dist_uv[uv_tx_size], 3671 &dist_uv[uv_tx_size],
3657 &skip_uv[uv_tx_size], 3672 &skip_uv[uv_tx_size],
3658 bsize < BLOCK_8X8 ? BLOCK_8X8 : bsize, 3673 bsize < BLOCK_8X8 ? BLOCK_8X8 : bsize,
3659 uv_tx_size); 3674 uv_tx_size);
3660 } 3675 }
3661 } 3676 }
3662 3677
3663 assert((cm->interp_filter == SWITCHABLE) || 3678 assert((cm->interp_filter == SWITCHABLE) ||
3664 (cm->interp_filter == best_mbmode.interp_filter) || 3679 (cm->interp_filter == best_mbmode.interp_filter) ||
3665 !is_inter_block(&best_mbmode)); 3680 !is_inter_block(&best_mbmode));
3666 3681
3667 // Updating rd_thresh_freq_fact[] here means that the different 3682 // Updating rd_thresh_freq_fact[] here means that the different
3668 // partition/block sizes are handled independently based on the best 3683 // partition/block sizes are handled independently based on the best
3669 // choice for the current partition. It may well be better to keep a scaled 3684 // choice for the current partition. It may well be better to keep a scaled
3670 // best rd so far value and update rd_thresh_freq_fact based on the mode/size 3685 // best rd so far value and update rd_thresh_freq_fact based on the mode/size
3671 // combination that wins out. 3686 // combination that wins out.
3672 if (cpi->sf.adaptive_rd_thresh) { 3687 if (cpi->sf.adaptive_rd_thresh) {
3673 for (mode_index = 0; mode_index < MAX_MODES; ++mode_index) { 3688 for (mode_index = 0; mode_index < MAX_MODES; ++mode_index) {
3689 int *const fact = &cpi->rd_thresh_freq_fact[bsize][mode_index];
3690
3674 if (mode_index == best_mode_index) { 3691 if (mode_index == best_mode_index) {
3675 cpi->rd_thresh_freq_fact[bsize][mode_index] -= 3692 *fact -= (*fact >> 3);
3676 (cpi->rd_thresh_freq_fact[bsize][mode_index] >> 3);
3677 } else { 3693 } else {
3678 cpi->rd_thresh_freq_fact[bsize][mode_index] += RD_THRESH_INC; 3694 *fact = MIN(*fact + RD_THRESH_INC,
3679 if (cpi->rd_thresh_freq_fact[bsize][mode_index] > 3695 cpi->sf.adaptive_rd_thresh * RD_THRESH_MAX_FACT);
3680 (cpi->sf.adaptive_rd_thresh * RD_THRESH_MAX_FACT)) {
3681 cpi->rd_thresh_freq_fact[bsize][mode_index] =
3682 cpi->sf.adaptive_rd_thresh * RD_THRESH_MAX_FACT;
3683 }
3684 } 3696 }
3685 } 3697 }
3686 } 3698 }
3687 3699
3688 // macroblock modes 3700 // macroblock modes
3689 *mbmi = best_mbmode; 3701 *mbmi = best_mbmode;
3690 x->skip |= best_skip2; 3702 x->skip |= best_skip2;
3691 3703
3692 for (i = 0; i < REFERENCE_MODES; ++i) { 3704 for (i = 0; i < REFERENCE_MODES; ++i) {
3693 if (best_pred_rd[i] == INT64_MAX) 3705 if (best_pred_rd[i] == INT64_MAX)
(...skipping 15 matching lines...) Expand all
3709 if (best_tx_rd[i] == INT64_MAX) 3721 if (best_tx_rd[i] == INT64_MAX)
3710 best_tx_diff[i] = 0; 3722 best_tx_diff[i] = 0;
3711 else 3723 else
3712 best_tx_diff[i] = best_rd - best_tx_rd[i]; 3724 best_tx_diff[i] = best_rd - best_tx_rd[i];
3713 } 3725 }
3714 } else { 3726 } else {
3715 vp9_zero(best_filter_diff); 3727 vp9_zero(best_filter_diff);
3716 vp9_zero(best_tx_diff); 3728 vp9_zero(best_tx_diff);
3717 } 3729 }
3718 3730
3731 if (!x->in_active_map) {
3732 assert(mbmi->ref_frame[0] == LAST_FRAME);
3733 assert(mbmi->ref_frame[1] == NONE);
3734 assert(mbmi->mode == NEARESTMV ||
3735 mbmi->mode == NEARMV ||
3736 mbmi->mode == ZEROMV);
3737 assert(frame_mv[mbmi->mode][LAST_FRAME].as_int == 0);
3738 assert(mbmi->mode == mbmi->uv_mode);
3739 }
3740
3719 set_ref_ptrs(cm, xd, mbmi->ref_frame[0], mbmi->ref_frame[1]); 3741 set_ref_ptrs(cm, xd, mbmi->ref_frame[0], mbmi->ref_frame[1]);
3720 store_coding_context(x, ctx, best_mode_index, 3742 store_coding_context(x, ctx, best_mode_index,
3721 &mbmi->ref_mvs[mbmi->ref_frame[0]][0], 3743 &mbmi->ref_mvs[mbmi->ref_frame[0]][0],
3722 &mbmi->ref_mvs[mbmi->ref_frame[1] < 0 ? 0 : 3744 &mbmi->ref_mvs[mbmi->ref_frame[1] < 0 ? 0 :
3723 mbmi->ref_frame[1]][0], 3745 mbmi->ref_frame[1]][0],
3724 best_pred_diff, best_tx_diff, best_filter_diff); 3746 best_pred_diff, best_tx_diff, best_filter_diff);
3725 3747
3726 return best_rd; 3748 return best_rd;
3727 } 3749 }
3728 3750
3729 3751
3730 int64_t vp9_rd_pick_inter_mode_sub8x8(VP9_COMP *cpi, MACROBLOCK *x, 3752 int64_t vp9_rd_pick_inter_mode_sub8x8(VP9_COMP *cpi, MACROBLOCK *x,
3731 const TileInfo *const tile, 3753 const TileInfo *const tile,
3732 int mi_row, int mi_col, 3754 int mi_row, int mi_col,
3733 int *returnrate, 3755 int *returnrate,
3734 int64_t *returndistortion, 3756 int64_t *returndistortion,
3735 BLOCK_SIZE bsize, 3757 BLOCK_SIZE bsize,
3736 PICK_MODE_CONTEXT *ctx, 3758 PICK_MODE_CONTEXT *ctx,
3737 int64_t best_rd_so_far) { 3759 int64_t best_rd_so_far) {
3738 VP9_COMMON *cm = &cpi->common; 3760 VP9_COMMON *const cm = &cpi->common;
3739 MACROBLOCKD *xd = &x->e_mbd; 3761 MACROBLOCKD *const xd = &x->e_mbd;
3740 MB_MODE_INFO *mbmi = &xd->mi_8x8[0]->mbmi; 3762 MB_MODE_INFO *const mbmi = &xd->mi[0]->mbmi;
3741 const struct segmentation *seg = &cm->seg; 3763 const struct segmentation *const seg = &cm->seg;
3742 const BLOCK_SIZE block_size = get_plane_block_size(bsize, &xd->plane[0]);
3743 MV_REFERENCE_FRAME ref_frame, second_ref_frame; 3764 MV_REFERENCE_FRAME ref_frame, second_ref_frame;
3744 unsigned char segment_id = mbmi->segment_id; 3765 unsigned char segment_id = mbmi->segment_id;
3745 int comp_pred, i; 3766 int comp_pred, i;
3746 int_mv frame_mv[MB_MODE_COUNT][MAX_REF_FRAMES]; 3767 int_mv frame_mv[MB_MODE_COUNT][MAX_REF_FRAMES];
3747 struct buf_2d yv12_mb[4][MAX_MB_PLANE]; 3768 struct buf_2d yv12_mb[4][MAX_MB_PLANE];
3748 static const int flag_list[4] = { 0, VP9_LAST_FLAG, VP9_GOLD_FLAG, 3769 static const int flag_list[4] = { 0, VP9_LAST_FLAG, VP9_GOLD_FLAG,
3749 VP9_ALT_FLAG }; 3770 VP9_ALT_FLAG };
3750 int64_t best_rd = best_rd_so_far; 3771 int64_t best_rd = best_rd_so_far;
3751 int64_t best_yrd = best_rd_so_far; // FIXME(rbultje) more precise 3772 int64_t best_yrd = best_rd_so_far; // FIXME(rbultje) more precise
3752 int64_t best_tx_rd[TX_MODES]; 3773 int64_t best_tx_rd[TX_MODES];
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
3792 for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; i++) 3813 for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; i++)
3793 best_filter_rd[i] = INT64_MAX; 3814 best_filter_rd[i] = INT64_MAX;
3794 for (i = 0; i < TX_SIZES; i++) 3815 for (i = 0; i < TX_SIZES; i++)
3795 rate_uv_intra[i] = INT_MAX; 3816 rate_uv_intra[i] = INT_MAX;
3796 3817
3797 *returnrate = INT_MAX; 3818 *returnrate = INT_MAX;
3798 3819
3799 for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ref_frame++) { 3820 for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ref_frame++) {
3800 if (cpi->ref_frame_flags & flag_list[ref_frame]) { 3821 if (cpi->ref_frame_flags & flag_list[ref_frame]) {
3801 vp9_setup_buffer_inter(cpi, x, tile, 3822 vp9_setup_buffer_inter(cpi, x, tile,
3802 ref_frame, block_size, mi_row, mi_col, 3823 ref_frame, bsize, mi_row, mi_col,
3803 frame_mv[NEARESTMV], frame_mv[NEARMV], 3824 frame_mv[NEARESTMV], frame_mv[NEARMV],
3804 yv12_mb); 3825 yv12_mb);
3805 } 3826 }
3806 frame_mv[NEWMV][ref_frame].as_int = INVALID_MV; 3827 frame_mv[NEWMV][ref_frame].as_int = INVALID_MV;
3807 frame_mv[ZEROMV][ref_frame].as_int = 0; 3828 frame_mv[ZEROMV][ref_frame].as_int = 0;
3808 } 3829 }
3809 3830
3810 for (ref_frame = LAST_FRAME; 3831 for (ref_frame = LAST_FRAME;
3811 ref_frame <= ALTREF_FRAME && cpi->sf.reference_masking; ++ref_frame) { 3832 ref_frame <= ALTREF_FRAME && cpi->sf.reference_masking; ++ref_frame) {
3812 int i; 3833 int i;
(...skipping 12 matching lines...) Expand all
3825 int compmode_cost = 0; 3846 int compmode_cost = 0;
3826 int rate2 = 0, rate_y = 0, rate_uv = 0; 3847 int rate2 = 0, rate_y = 0, rate_uv = 0;
3827 int64_t distortion2 = 0, distortion_y = 0, distortion_uv = 0; 3848 int64_t distortion2 = 0, distortion_y = 0, distortion_uv = 0;
3828 int skippable = 0; 3849 int skippable = 0;
3829 int64_t tx_cache[TX_MODES]; 3850 int64_t tx_cache[TX_MODES];
3830 int i; 3851 int i;
3831 int this_skip2 = 0; 3852 int this_skip2 = 0;
3832 int64_t total_sse = INT_MAX; 3853 int64_t total_sse = INT_MAX;
3833 int early_term = 0; 3854 int early_term = 0;
3834 3855
3835 for (i = 0; i < TX_MODES; ++i)
3836 tx_cache[i] = INT64_MAX;
3837
3838 x->skip = 0;
3839 ref_frame = vp9_ref_order[mode_index].ref_frame[0]; 3856 ref_frame = vp9_ref_order[mode_index].ref_frame[0];
3840 second_ref_frame = vp9_ref_order[mode_index].ref_frame[1]; 3857 second_ref_frame = vp9_ref_order[mode_index].ref_frame[1];
3841 3858
3842 // Look at the reference frame of the best mode so far and set the 3859 // Look at the reference frame of the best mode so far and set the
3843 // skip mask to look at a subset of the remaining modes. 3860 // skip mask to look at a subset of the remaining modes.
3844 if (mode_index > 2 && cpi->sf.mode_skip_start < MAX_MODES) { 3861 if (mode_index > 2 && cpi->sf.mode_skip_start < MAX_MODES) {
3845 if (mode_index == 3) { 3862 if (mode_index == 3) {
3846 switch (vp9_ref_order[best_mode_index].ref_frame[0]) { 3863 switch (vp9_ref_order[best_mode_index].ref_frame[0]) {
3847 case INTRA_FRAME: 3864 case INTRA_FRAME:
3848 mode_skip_mask = 0; 3865 mode_skip_mask = 0;
(...skipping 16 matching lines...) Expand all
3865 continue; 3882 continue;
3866 } 3883 }
3867 3884
3868 // Test best rd so far against threshold for trying this mode. 3885 // Test best rd so far against threshold for trying this mode.
3869 if ((best_rd < 3886 if ((best_rd <
3870 ((int64_t)cpi->rd_thresh_sub8x8[segment_id][bsize][mode_index] * 3887 ((int64_t)cpi->rd_thresh_sub8x8[segment_id][bsize][mode_index] *
3871 cpi->rd_thresh_freq_sub8x8[bsize][mode_index] >> 5)) || 3888 cpi->rd_thresh_freq_sub8x8[bsize][mode_index] >> 5)) ||
3872 cpi->rd_thresh_sub8x8[segment_id][bsize][mode_index] == INT_MAX) 3889 cpi->rd_thresh_sub8x8[segment_id][bsize][mode_index] == INT_MAX)
3873 continue; 3890 continue;
3874 3891
3875 // Do not allow compound prediction if the segment level reference 3892 if (ref_frame > INTRA_FRAME &&
3876 // frame feature is in use as in this case there can only be one reference. 3893 !(cpi->ref_frame_flags & flag_list[ref_frame])) {
3877 if ((second_ref_frame > INTRA_FRAME) &&
3878 vp9_segfeature_active(seg, segment_id, SEG_LVL_REF_FRAME))
3879 continue;
3880
3881 mbmi->ref_frame[0] = ref_frame;
3882 mbmi->ref_frame[1] = second_ref_frame;
3883
3884 if (!(ref_frame == INTRA_FRAME
3885 || (cpi->ref_frame_flags & flag_list[ref_frame]))) {
3886 continue;
3887 }
3888 if (!(second_ref_frame == NONE
3889 || (cpi->ref_frame_flags & flag_list[second_ref_frame]))) {
3890 continue; 3894 continue;
3891 } 3895 }
3892 3896
3893 comp_pred = second_ref_frame > INTRA_FRAME; 3897 comp_pred = second_ref_frame > INTRA_FRAME;
3894 if (comp_pred) { 3898 if (comp_pred) {
3895 if (cpi->sf.mode_search_skip_flags & FLAG_SKIP_COMP_BESTINTRA) 3899 if (!(cpi->ref_frame_flags & flag_list[second_ref_frame]))
3896 if (vp9_ref_order[best_mode_index].ref_frame[0] == INTRA_FRAME) 3900 continue;
3897 continue; 3901 // Do not allow compound prediction if the segment level reference frame
3898 if (cpi->sf.mode_search_skip_flags & FLAG_SKIP_COMP_REFMISMATCH) 3902 // feature is in use as in this case there can only be one reference.
3899 if (ref_frame != best_inter_ref_frame && 3903 if (vp9_segfeature_active(seg, segment_id, SEG_LVL_REF_FRAME))
3900 second_ref_frame != best_inter_ref_frame) 3904 continue;
3901 continue; 3905 if ((cpi->sf.mode_search_skip_flags & FLAG_SKIP_COMP_BESTINTRA) &&
3906 vp9_ref_order[best_mode_index].ref_frame[0] == INTRA_FRAME)
3907 continue;
3908 if ((cpi->sf.mode_search_skip_flags & FLAG_SKIP_COMP_REFMISMATCH) &&
3909 ref_frame != best_inter_ref_frame &&
3910 second_ref_frame != best_inter_ref_frame)
3911 continue;
3902 } 3912 }
3903 3913
3904 // TODO(jingning, jkoleszar): scaling reference frame not supported for 3914 // TODO(jingning, jkoleszar): scaling reference frame not supported for
3905 // sub8x8 blocks. 3915 // sub8x8 blocks.
3906 if (ref_frame > 0 && vp9_is_scaled(&cm->frame_refs[ref_frame - 1].sf)) 3916 if (ref_frame > NONE && vp9_is_scaled(&cm->frame_refs[ref_frame - 1].sf))
3907 continue; 3917 continue;
3908 3918
3909 if (second_ref_frame > 0 && 3919 if (second_ref_frame > NONE &&
3910 vp9_is_scaled(&cm->frame_refs[second_ref_frame - 1].sf)) 3920 vp9_is_scaled(&cm->frame_refs[second_ref_frame - 1].sf))
3911 continue; 3921 continue;
3912 3922
3913 set_ref_ptrs(cm, xd, ref_frame, second_ref_frame);
3914 mbmi->uv_mode = DC_PRED;
3915
3916 // Evaluate all sub-pel filters irrespective of whether we can use
3917 // them for this frame.
3918 mbmi->interp_filter = cm->interp_filter == SWITCHABLE ? EIGHTTAP
3919 : cm->interp_filter;
3920 xd->interp_kernel = vp9_get_interp_kernel(mbmi->interp_filter);
3921
3922 if (comp_pred) { 3923 if (comp_pred) {
3923 if (!(cpi->ref_frame_flags & flag_list[second_ref_frame]))
3924 continue;
3925
3926 mode_excluded = mode_excluded ? mode_excluded 3924 mode_excluded = mode_excluded ? mode_excluded
3927 : cm->reference_mode == SINGLE_REFERENCE; 3925 : cm->reference_mode == SINGLE_REFERENCE;
3928 } else { 3926 } else if (ref_frame != INTRA_FRAME) {
3929 if (ref_frame != INTRA_FRAME && second_ref_frame != INTRA_FRAME) { 3927 mode_excluded = mode_excluded ? mode_excluded
3930 mode_excluded = mode_excluded ? 3928 : cm->reference_mode == COMPOUND_REFERENCE;
3931 mode_excluded : cm->reference_mode == COMPOUND_REFERENCE;
3932 }
3933 }
3934
3935 // Select prediction reference frames.
3936 for (i = 0; i < MAX_MB_PLANE; i++) {
3937 xd->plane[i].pre[0] = yv12_mb[ref_frame][i];
3938 if (comp_pred)
3939 xd->plane[i].pre[1] = yv12_mb[second_ref_frame][i];
3940 } 3929 }
3941 3930
3942 // If the segment reference frame feature is enabled.... 3931 // If the segment reference frame feature is enabled....
3943 // then do nothing if the current ref frame is not allowed.. 3932 // then do nothing if the current ref frame is not allowed..
3944 if (vp9_segfeature_active(seg, segment_id, SEG_LVL_REF_FRAME) && 3933 if (vp9_segfeature_active(seg, segment_id, SEG_LVL_REF_FRAME) &&
3945 vp9_get_segdata(seg, segment_id, SEG_LVL_REF_FRAME) != 3934 vp9_get_segdata(seg, segment_id, SEG_LVL_REF_FRAME) !=
3946 (int)ref_frame) { 3935 (int)ref_frame) {
3947 continue; 3936 continue;
3948 // If the segment skip feature is enabled.... 3937 // If the segment skip feature is enabled....
3949 // then do nothing if the current mode is not allowed.. 3938 // then do nothing if the current mode is not allowed..
3950 } else if (vp9_segfeature_active(seg, segment_id, SEG_LVL_SKIP) && 3939 } else if (vp9_segfeature_active(seg, segment_id, SEG_LVL_SKIP) &&
3951 ref_frame != INTRA_FRAME) { 3940 ref_frame != INTRA_FRAME) {
3952 continue; 3941 continue;
3953 // Disable this drop out case if the ref frame 3942 // Disable this drop out case if the ref frame
3954 // segment level feature is enabled for this segment. This is to 3943 // segment level feature is enabled for this segment. This is to
3955 // prevent the possibility that we end up unable to pick any mode. 3944 // prevent the possibility that we end up unable to pick any mode.
3956 } else if (!vp9_segfeature_active(seg, segment_id, 3945 } else if (!vp9_segfeature_active(seg, segment_id,
3957 SEG_LVL_REF_FRAME)) { 3946 SEG_LVL_REF_FRAME)) {
3958 // Only consider ZEROMV/ALTREF_FRAME for alt ref frame, 3947 // Only consider ZEROMV/ALTREF_FRAME for alt ref frame,
3959 // unless ARNR filtering is enabled in which case we want 3948 // unless ARNR filtering is enabled in which case we want
3960 // an unfiltered alternative. We allow near/nearest as well 3949 // an unfiltered alternative. We allow near/nearest as well
3961 // because they may result in zero-zero MVs but be cheaper. 3950 // because they may result in zero-zero MVs but be cheaper.
3962 if (cpi->rc.is_src_frame_alt_ref && (cpi->oxcf.arnr_max_frames == 0)) 3951 if (cpi->rc.is_src_frame_alt_ref && (cpi->oxcf.arnr_max_frames == 0))
3963 continue; 3952 continue;
3964 } 3953 }
3965 3954
3955 mbmi->tx_size = TX_4X4;
3956 mbmi->uv_mode = DC_PRED;
3957 mbmi->ref_frame[0] = ref_frame;
3958 mbmi->ref_frame[1] = second_ref_frame;
3959 // Evaluate all sub-pel filters irrespective of whether we can use
3960 // them for this frame.
3961 mbmi->interp_filter = cm->interp_filter == SWITCHABLE ? EIGHTTAP
3962 : cm->interp_filter;
3963 x->skip = 0;
3964 set_ref_ptrs(cm, xd, ref_frame, second_ref_frame);
3965
3966 // Select prediction reference frames.
3967 for (i = 0; i < MAX_MB_PLANE; i++) {
3968 xd->plane[i].pre[0] = yv12_mb[ref_frame][i];
3969 if (comp_pred)
3970 xd->plane[i].pre[1] = yv12_mb[second_ref_frame][i];
3971 }
3972
3973 for (i = 0; i < TX_MODES; ++i)
3974 tx_cache[i] = INT64_MAX;
3975
3966 #ifdef MODE_TEST_HIT_STATS 3976 #ifdef MODE_TEST_HIT_STATS
3967 // TEST/DEBUG CODE 3977 // TEST/DEBUG CODE
3968 // Keep a rcord of the number of test hits at each size 3978 // Keep a rcord of the number of test hits at each size
3969 cpi->mode_test_hits[bsize]++; 3979 cpi->mode_test_hits[bsize]++;
3970 #endif 3980 #endif
3971 3981
3972 if (ref_frame == INTRA_FRAME) { 3982 if (ref_frame == INTRA_FRAME) {
3973 int rate; 3983 int rate;
3974 mbmi->tx_size = TX_4X4;
3975 if (rd_pick_intra_sub_8x8_y_mode(cpi, x, &rate, &rate_y, 3984 if (rd_pick_intra_sub_8x8_y_mode(cpi, x, &rate, &rate_y,
3976 &distortion_y, best_rd) >= best_rd) 3985 &distortion_y, best_rd) >= best_rd)
3977 continue; 3986 continue;
3978 rate2 += rate; 3987 rate2 += rate;
3979 rate2 += intra_cost_penalty; 3988 rate2 += intra_cost_penalty;
3980 distortion2 += distortion_y; 3989 distortion2 += distortion_y;
3981 3990
3982 if (rate_uv_intra[TX_4X4] == INT_MAX) { 3991 if (rate_uv_intra[TX_4X4] == INT_MAX) {
3983 choose_intra_uv_mode(cpi, ctx, bsize, TX_4X4, 3992 choose_intra_uv_mode(cpi, ctx, bsize, TX_4X4,
3984 &rate_uv_intra[TX_4X4], 3993 &rate_uv_intra[TX_4X4],
(...skipping 24 matching lines...) Expand all
4009 MB_MODE_INFO tmp_best_mbmode; 4018 MB_MODE_INFO tmp_best_mbmode;
4010 BEST_SEG_INFO bsi[SWITCHABLE_FILTERS]; 4019 BEST_SEG_INFO bsi[SWITCHABLE_FILTERS];
4011 int pred_exists = 0; 4020 int pred_exists = 0;
4012 int uv_skippable; 4021 int uv_skippable;
4013 4022
4014 this_rd_thresh = (ref_frame == LAST_FRAME) ? 4023 this_rd_thresh = (ref_frame == LAST_FRAME) ?
4015 cpi->rd_thresh_sub8x8[segment_id][bsize][THR_LAST] : 4024 cpi->rd_thresh_sub8x8[segment_id][bsize][THR_LAST] :
4016 cpi->rd_thresh_sub8x8[segment_id][bsize][THR_ALTR]; 4025 cpi->rd_thresh_sub8x8[segment_id][bsize][THR_ALTR];
4017 this_rd_thresh = (ref_frame == GOLDEN_FRAME) ? 4026 this_rd_thresh = (ref_frame == GOLDEN_FRAME) ?
4018 cpi->rd_thresh_sub8x8[segment_id][bsize][THR_GOLD] : this_rd_thresh; 4027 cpi->rd_thresh_sub8x8[segment_id][bsize][THR_GOLD] : this_rd_thresh;
4019 xd->mi_8x8[0]->mbmi.tx_size = TX_4X4;
4020 4028
4021 cpi->mask_filter_rd = 0; 4029 cpi->mask_filter_rd = 0;
4022 for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; ++i) 4030 for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; ++i)
4023 cpi->rd_filter_cache[i] = INT64_MAX; 4031 cpi->rd_filter_cache[i] = INT64_MAX;
4024 4032
4025 if (cm->interp_filter != BILINEAR) { 4033 if (cm->interp_filter != BILINEAR) {
4026 tmp_best_filter = EIGHTTAP; 4034 tmp_best_filter = EIGHTTAP;
4027 if (x->source_variance < 4035 if (x->source_variance < cpi->sf.disable_filter_search_var_thresh) {
4028 cpi->sf.disable_filter_search_var_thresh) {
4029 tmp_best_filter = EIGHTTAP; 4036 tmp_best_filter = EIGHTTAP;
4030 } else if (cpi->sf.adaptive_pred_interp_filter == 1 && 4037 } else if (cpi->sf.adaptive_pred_interp_filter == 1 &&
4031 ctx->pred_interp_filter < SWITCHABLE) { 4038 ctx->pred_interp_filter < SWITCHABLE) {
4032 tmp_best_filter = ctx->pred_interp_filter; 4039 tmp_best_filter = ctx->pred_interp_filter;
4033 } else if (cpi->sf.adaptive_pred_interp_filter == 2) { 4040 } else if (cpi->sf.adaptive_pred_interp_filter == 2) {
4034 tmp_best_filter = ctx->pred_interp_filter < SWITCHABLE ? 4041 tmp_best_filter = ctx->pred_interp_filter < SWITCHABLE ?
4035 ctx->pred_interp_filter : 0; 4042 ctx->pred_interp_filter : 0;
4036 } else { 4043 } else {
4037 for (switchable_filter_index = 0; 4044 for (switchable_filter_index = 0;
4038 switchable_filter_index < SWITCHABLE_FILTERS; 4045 switchable_filter_index < SWITCHABLE_FILTERS;
4039 ++switchable_filter_index) { 4046 ++switchable_filter_index) {
4040 int newbest, rs; 4047 int newbest, rs;
4041 int64_t rs_rd; 4048 int64_t rs_rd;
4042 mbmi->interp_filter = switchable_filter_index; 4049 mbmi->interp_filter = switchable_filter_index;
4043 xd->interp_kernel = vp9_get_interp_kernel(mbmi->interp_filter);
4044 tmp_rd = rd_pick_best_mbsegmentation(cpi, x, tile, 4050 tmp_rd = rd_pick_best_mbsegmentation(cpi, x, tile,
4045 &mbmi->ref_mvs[ref_frame][0], 4051 &mbmi->ref_mvs[ref_frame][0],
4046 second_ref, 4052 second_ref,
4047 best_yrd, 4053 best_yrd,
4048 &rate, &rate_y, &distortion, 4054 &rate, &rate_y, &distortion,
4049 &skippable, &total_sse, 4055 &skippable, &total_sse,
4050 (int)this_rd_thresh, seg_mvs, 4056 (int)this_rd_thresh, seg_mvs,
4051 bsi, switchable_filter_index, 4057 bsi, switchable_filter_index,
4052 mi_row, mi_col); 4058 mi_row, mi_col);
4053 4059
4054 if (tmp_rd == INT64_MAX) 4060 if (tmp_rd == INT64_MAX)
4055 continue; 4061 continue;
4056 rs = get_switchable_rate(x); 4062 rs = vp9_get_switchable_rate(x);
4057 rs_rd = RDCOST(x->rdmult, x->rddiv, rs, 0); 4063 rs_rd = RDCOST(x->rdmult, x->rddiv, rs, 0);
4058 cpi->rd_filter_cache[switchable_filter_index] = tmp_rd; 4064 cpi->rd_filter_cache[switchable_filter_index] = tmp_rd;
4059 cpi->rd_filter_cache[SWITCHABLE_FILTERS] = 4065 cpi->rd_filter_cache[SWITCHABLE_FILTERS] =
4060 MIN(cpi->rd_filter_cache[SWITCHABLE_FILTERS], 4066 MIN(cpi->rd_filter_cache[SWITCHABLE_FILTERS],
4061 tmp_rd + rs_rd); 4067 tmp_rd + rs_rd);
4062 if (cm->interp_filter == SWITCHABLE) 4068 if (cm->interp_filter == SWITCHABLE)
4063 tmp_rd += rs_rd; 4069 tmp_rd += rs_rd;
4064 4070
4065 cpi->mask_filter_rd = MAX(cpi->mask_filter_rd, tmp_rd); 4071 cpi->mask_filter_rd = MAX(cpi->mask_filter_rd, tmp_rd);
4066 4072
4067 newbest = (tmp_rd < tmp_best_rd); 4073 newbest = (tmp_rd < tmp_best_rd);
4068 if (newbest) { 4074 if (newbest) {
4069 tmp_best_filter = mbmi->interp_filter; 4075 tmp_best_filter = mbmi->interp_filter;
4070 tmp_best_rd = tmp_rd; 4076 tmp_best_rd = tmp_rd;
4071 } 4077 }
4072 if ((newbest && cm->interp_filter == SWITCHABLE) || 4078 if ((newbest && cm->interp_filter == SWITCHABLE) ||
4073 (mbmi->interp_filter == cm->interp_filter && 4079 (mbmi->interp_filter == cm->interp_filter &&
4074 cm->interp_filter != SWITCHABLE)) { 4080 cm->interp_filter != SWITCHABLE)) {
4075 tmp_best_rdu = tmp_rd; 4081 tmp_best_rdu = tmp_rd;
4076 tmp_best_rate = rate; 4082 tmp_best_rate = rate;
4077 tmp_best_ratey = rate_y; 4083 tmp_best_ratey = rate_y;
4078 tmp_best_distortion = distortion; 4084 tmp_best_distortion = distortion;
4079 tmp_best_sse = total_sse; 4085 tmp_best_sse = total_sse;
4080 tmp_best_skippable = skippable; 4086 tmp_best_skippable = skippable;
4081 tmp_best_mbmode = *mbmi; 4087 tmp_best_mbmode = *mbmi;
4082 for (i = 0; i < 4; i++) { 4088 for (i = 0; i < 4; i++) {
4083 tmp_best_bmodes[i] = xd->mi_8x8[0]->bmi[i]; 4089 tmp_best_bmodes[i] = xd->mi[0]->bmi[i];
4084 x->zcoeff_blk[TX_4X4][i] = !x->plane[0].eobs[i]; 4090 x->zcoeff_blk[TX_4X4][i] = !x->plane[0].eobs[i];
4085 } 4091 }
4086 pred_exists = 1; 4092 pred_exists = 1;
4087 if (switchable_filter_index == 0 && 4093 if (switchable_filter_index == 0 &&
4088 cpi->sf.use_rd_breakout && 4094 cpi->sf.use_rd_breakout &&
4089 best_rd < INT64_MAX) { 4095 best_rd < INT64_MAX) {
4090 if (tmp_best_rdu / 2 > best_rd) { 4096 if (tmp_best_rdu / 2 > best_rd) {
4091 // skip searching the other filters if the first is 4097 // skip searching the other filters if the first is
4092 // already substantially larger than the best so far 4098 // already substantially larger than the best so far
4093 tmp_best_filter = mbmi->interp_filter; 4099 tmp_best_filter = mbmi->interp_filter;
4094 tmp_best_rdu = INT64_MAX; 4100 tmp_best_rdu = INT64_MAX;
4095 break; 4101 break;
4096 } 4102 }
4097 } 4103 }
4098 } 4104 }
4099 } // switchable_filter_index loop 4105 } // switchable_filter_index loop
4100 } 4106 }
4101 } 4107 }
4102 4108
4103 if (tmp_best_rdu == INT64_MAX && pred_exists) 4109 if (tmp_best_rdu == INT64_MAX && pred_exists)
4104 continue; 4110 continue;
4105 4111
4106 mbmi->interp_filter = (cm->interp_filter == SWITCHABLE ? 4112 mbmi->interp_filter = (cm->interp_filter == SWITCHABLE ?
4107 tmp_best_filter : cm->interp_filter); 4113 tmp_best_filter : cm->interp_filter);
4108 xd->interp_kernel = vp9_get_interp_kernel(mbmi->interp_filter);
4109 if (!pred_exists) { 4114 if (!pred_exists) {
4110 // Handles the special case when a filter that is not in the 4115 // Handles the special case when a filter that is not in the
4111 // switchable list (bilinear, 6-tap) is indicated at the frame level 4116 // switchable list (bilinear, 6-tap) is indicated at the frame level
4112 tmp_rd = rd_pick_best_mbsegmentation(cpi, x, tile, 4117 tmp_rd = rd_pick_best_mbsegmentation(cpi, x, tile,
4113 &mbmi->ref_mvs[ref_frame][0], 4118 &mbmi->ref_mvs[ref_frame][0],
4114 second_ref, 4119 second_ref,
4115 best_yrd, 4120 best_yrd,
4116 &rate, &rate_y, &distortion, 4121 &rate, &rate_y, &distortion,
4117 &skippable, &total_sse, 4122 &skippable, &total_sse,
4118 (int)this_rd_thresh, seg_mvs, 4123 (int)this_rd_thresh, seg_mvs,
4119 bsi, 0, 4124 bsi, 0,
4120 mi_row, mi_col); 4125 mi_row, mi_col);
4121 if (tmp_rd == INT64_MAX) 4126 if (tmp_rd == INT64_MAX)
4122 continue; 4127 continue;
4123 } else { 4128 } else {
4124 total_sse = tmp_best_sse; 4129 total_sse = tmp_best_sse;
4125 rate = tmp_best_rate; 4130 rate = tmp_best_rate;
4126 rate_y = tmp_best_ratey; 4131 rate_y = tmp_best_ratey;
4127 distortion = tmp_best_distortion; 4132 distortion = tmp_best_distortion;
4128 skippable = tmp_best_skippable; 4133 skippable = tmp_best_skippable;
4129 *mbmi = tmp_best_mbmode; 4134 *mbmi = tmp_best_mbmode;
4130 for (i = 0; i < 4; i++) 4135 for (i = 0; i < 4; i++)
4131 xd->mi_8x8[0]->bmi[i] = tmp_best_bmodes[i]; 4136 xd->mi[0]->bmi[i] = tmp_best_bmodes[i];
4132 } 4137 }
4133 4138
4134 rate2 += rate; 4139 rate2 += rate;
4135 distortion2 += distortion; 4140 distortion2 += distortion;
4136 4141
4137 if (cm->interp_filter == SWITCHABLE) 4142 if (cm->interp_filter == SWITCHABLE)
4138 rate2 += get_switchable_rate(x); 4143 rate2 += vp9_get_switchable_rate(x);
4139 4144
4140 if (!mode_excluded) 4145 if (!mode_excluded)
4141 mode_excluded = comp_pred ? cm->reference_mode == SINGLE_REFERENCE 4146 mode_excluded = comp_pred ? cm->reference_mode == SINGLE_REFERENCE
4142 : cm->reference_mode == COMPOUND_REFERENCE; 4147 : cm->reference_mode == COMPOUND_REFERENCE;
4143 4148
4144 compmode_cost = vp9_cost_bit(comp_mode_p, comp_pred); 4149 compmode_cost = vp9_cost_bit(comp_mode_p, comp_pred);
4145 4150
4146 tmp_best_rdu = best_rd - 4151 tmp_best_rdu = best_rd -
4147 MIN(RDCOST(x->rdmult, x->rddiv, rate2, distortion2), 4152 MIN(RDCOST(x->rdmult, x->rddiv, rate2, distortion2),
4148 RDCOST(x->rdmult, x->rddiv, 0, total_sse)); 4153 RDCOST(x->rdmult, x->rddiv, 0, total_sse));
4149 4154
4150 if (tmp_best_rdu > 0) { 4155 if (tmp_best_rdu > 0) {
4151 // If even the 'Y' rd value of split is higher than best so far 4156 // If even the 'Y' rd value of split is higher than best so far
4152 // then dont bother looking at UV 4157 // then dont bother looking at UV
4153 vp9_build_inter_predictors_sbuv(&x->e_mbd, mi_row, mi_col, 4158 vp9_build_inter_predictors_sbuv(&x->e_mbd, mi_row, mi_col,
4154 BLOCK_8X8); 4159 BLOCK_8X8);
4155 super_block_uvrd(x, &rate_uv, &distortion_uv, &uv_skippable, 4160 super_block_uvrd(cpi, x, &rate_uv, &distortion_uv, &uv_skippable,
4156 &uv_sse, BLOCK_8X8, tmp_best_rdu); 4161 &uv_sse, BLOCK_8X8, tmp_best_rdu);
4157 if (rate_uv == INT_MAX) 4162 if (rate_uv == INT_MAX)
4158 continue; 4163 continue;
4159 rate2 += rate_uv; 4164 rate2 += rate_uv;
4160 distortion2 += distortion_uv; 4165 distortion2 += distortion_uv;
4161 skippable = skippable && uv_skippable; 4166 skippable = skippable && uv_skippable;
4162 total_sse += uv_sse; 4167 total_sse += uv_sse;
4163 4168
4164 tx_cache[ONLY_4X4] = RDCOST(x->rdmult, x->rddiv, rate2, distortion2); 4169 tx_cache[ONLY_4X4] = RDCOST(x->rdmult, x->rddiv, rate2, distortion2);
4165 for (i = 0; i < TX_MODES; ++i) 4170 for (i = 0; i < TX_MODES; ++i)
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
4205 } else if (mb_skip_allowed) { 4210 } else if (mb_skip_allowed) {
4206 // Add in the cost of the no skip flag. 4211 // Add in the cost of the no skip flag.
4207 rate2 += vp9_cost_bit(vp9_get_skip_prob(cm, xd), 0); 4212 rate2 += vp9_cost_bit(vp9_get_skip_prob(cm, xd), 0);
4208 } 4213 }
4209 4214
4210 // Calculate the final RD estimate for this mode. 4215 // Calculate the final RD estimate for this mode.
4211 this_rd = RDCOST(x->rdmult, x->rddiv, rate2, distortion2); 4216 this_rd = RDCOST(x->rdmult, x->rddiv, rate2, distortion2);
4212 } 4217 }
4213 4218
4214 // Keep record of best inter rd with single reference 4219 // Keep record of best inter rd with single reference
4215 if (is_inter_block(&xd->mi_8x8[0]->mbmi) && 4220 if (is_inter_block(mbmi) &&
4216 !has_second_ref(&xd->mi_8x8[0]->mbmi) && 4221 !has_second_ref(mbmi) &&
4217 !mode_excluded && 4222 !mode_excluded &&
4218 this_rd < best_inter_rd) { 4223 this_rd < best_inter_rd) {
4219 best_inter_rd = this_rd; 4224 best_inter_rd = this_rd;
4220 best_inter_ref_frame = ref_frame; 4225 best_inter_ref_frame = ref_frame;
4221 } 4226 }
4222 4227
4223 if (!disable_skip && ref_frame == INTRA_FRAME) { 4228 if (!disable_skip && ref_frame == INTRA_FRAME) {
4224 for (i = 0; i < REFERENCE_MODES; ++i) 4229 for (i = 0; i < REFERENCE_MODES; ++i)
4225 best_pred_rd[i] = MIN(best_pred_rd[i], this_rd); 4230 best_pred_rd[i] = MIN(best_pred_rd[i], this_rd);
4226 for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; i++) 4231 for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; i++)
(...skipping 15 matching lines...) Expand all
4242 4247
4243 *returnrate = rate2; 4248 *returnrate = rate2;
4244 *returndistortion = distortion2; 4249 *returndistortion = distortion2;
4245 best_rd = this_rd; 4250 best_rd = this_rd;
4246 best_yrd = best_rd - 4251 best_yrd = best_rd -
4247 RDCOST(x->rdmult, x->rddiv, rate_uv, distortion_uv); 4252 RDCOST(x->rdmult, x->rddiv, rate_uv, distortion_uv);
4248 best_mbmode = *mbmi; 4253 best_mbmode = *mbmi;
4249 best_skip2 = this_skip2; 4254 best_skip2 = this_skip2;
4250 if (!x->select_txfm_size) 4255 if (!x->select_txfm_size)
4251 swap_block_ptr(x, ctx, max_plane); 4256 swap_block_ptr(x, ctx, max_plane);
4252 vpx_memcpy(ctx->zcoeff_blk, x->zcoeff_blk[mbmi->tx_size], 4257 vpx_memcpy(ctx->zcoeff_blk, x->zcoeff_blk[TX_4X4],
4253 sizeof(uint8_t) * ctx->num_4x4_blk); 4258 sizeof(uint8_t) * ctx->num_4x4_blk);
4254 4259
4255 for (i = 0; i < 4; i++) 4260 for (i = 0; i < 4; i++)
4256 best_bmodes[i] = xd->mi_8x8[0]->bmi[i]; 4261 best_bmodes[i] = xd->mi[0]->bmi[i];
4257 4262
4258 // TODO(debargha): enhance this test with a better distortion prediction 4263 // TODO(debargha): enhance this test with a better distortion prediction
4259 // based on qp, activity mask and history 4264 // based on qp, activity mask and history
4260 if ((cpi->sf.mode_search_skip_flags & FLAG_EARLY_TERMINATE) && 4265 if ((cpi->sf.mode_search_skip_flags & FLAG_EARLY_TERMINATE) &&
4261 (mode_index > MIN_EARLY_TERM_INDEX)) { 4266 (mode_index > MIN_EARLY_TERM_INDEX)) {
4262 const int qstep = xd->plane[0].dequant[1]; 4267 const int qstep = xd->plane[0].dequant[1];
4263 // TODO(debargha): Enhance this by specializing for each mode_index 4268 // TODO(debargha): Enhance this by specializing for each mode_index
4264 int scale = 4; 4269 int scale = 4;
4265 if (x->source_variance < UINT_MAX) { 4270 if (x->source_variance < UINT_MAX) {
4266 const int var_adjust = (x->source_variance < 16); 4271 const int var_adjust = (x->source_variance < 16);
(...skipping 15 matching lines...) Expand all
4282 single_rate = rate2 - compmode_cost; 4287 single_rate = rate2 - compmode_cost;
4283 hybrid_rate = rate2; 4288 hybrid_rate = rate2;
4284 } else { 4289 } else {
4285 single_rate = rate2; 4290 single_rate = rate2;
4286 hybrid_rate = rate2 + compmode_cost; 4291 hybrid_rate = rate2 + compmode_cost;
4287 } 4292 }
4288 4293
4289 single_rd = RDCOST(x->rdmult, x->rddiv, single_rate, distortion2); 4294 single_rd = RDCOST(x->rdmult, x->rddiv, single_rate, distortion2);
4290 hybrid_rd = RDCOST(x->rdmult, x->rddiv, hybrid_rate, distortion2); 4295 hybrid_rd = RDCOST(x->rdmult, x->rddiv, hybrid_rate, distortion2);
4291 4296
4292 if (second_ref_frame <= INTRA_FRAME && 4297 if (!comp_pred && single_rd < best_pred_rd[SINGLE_REFERENCE]) {
4293 single_rd < best_pred_rd[SINGLE_REFERENCE]) {
4294 best_pred_rd[SINGLE_REFERENCE] = single_rd; 4298 best_pred_rd[SINGLE_REFERENCE] = single_rd;
4295 } else if (second_ref_frame > INTRA_FRAME && 4299 } else if (comp_pred && single_rd < best_pred_rd[COMPOUND_REFERENCE]) {
4296 single_rd < best_pred_rd[COMPOUND_REFERENCE]) {
4297 best_pred_rd[COMPOUND_REFERENCE] = single_rd; 4300 best_pred_rd[COMPOUND_REFERENCE] = single_rd;
4298 } 4301 }
4299 if (hybrid_rd < best_pred_rd[REFERENCE_MODE_SELECT]) 4302 if (hybrid_rd < best_pred_rd[REFERENCE_MODE_SELECT])
4300 best_pred_rd[REFERENCE_MODE_SELECT] = hybrid_rd; 4303 best_pred_rd[REFERENCE_MODE_SELECT] = hybrid_rd;
4301 } 4304 }
4302 4305
4303 /* keep record of best filter type */ 4306 /* keep record of best filter type */
4304 if (!mode_excluded && !disable_skip && ref_frame != INTRA_FRAME && 4307 if (!mode_excluded && !disable_skip && ref_frame != INTRA_FRAME &&
4305 cm->interp_filter != BILINEAR) { 4308 cm->interp_filter != BILINEAR) {
4306 int64_t ref = cpi->rd_filter_cache[cm->interp_filter == SWITCHABLE ? 4309 int64_t ref = cpi->rd_filter_cache[cm->interp_filter == SWITCHABLE ?
(...skipping 10 matching lines...) Expand all
4317 adj_rd = cpi->mask_filter_rd - ref + 10; 4320 adj_rd = cpi->mask_filter_rd - ref + 10;
4318 else 4321 else
4319 adj_rd = cpi->rd_filter_cache[i] - ref; 4322 adj_rd = cpi->rd_filter_cache[i] - ref;
4320 4323
4321 adj_rd += this_rd; 4324 adj_rd += this_rd;
4322 best_filter_rd[i] = MIN(best_filter_rd[i], adj_rd); 4325 best_filter_rd[i] = MIN(best_filter_rd[i], adj_rd);
4323 } 4326 }
4324 } 4327 }
4325 4328
4326 /* keep record of best txfm size */ 4329 /* keep record of best txfm size */
4327 if (bsize < BLOCK_32X32) { 4330 tx_cache[ALLOW_8X8] = tx_cache[ONLY_4X4];
4328 if (bsize < BLOCK_16X16) { 4331 tx_cache[ALLOW_16X16] = tx_cache[ALLOW_8X8];
4329 tx_cache[ALLOW_8X8] = tx_cache[ONLY_4X4]; 4332 tx_cache[ALLOW_32X32] = tx_cache[ALLOW_16X16];
4330 tx_cache[ALLOW_16X16] = tx_cache[ALLOW_8X8];
4331 }
4332 tx_cache[ALLOW_32X32] = tx_cache[ALLOW_16X16];
4333 }
4334 if (!mode_excluded && this_rd != INT64_MAX) { 4333 if (!mode_excluded && this_rd != INT64_MAX) {
4335 for (i = 0; i < TX_MODES && tx_cache[i] < INT64_MAX; i++) { 4334 for (i = 0; i < TX_MODES && tx_cache[i] < INT64_MAX; i++) {
4336 int64_t adj_rd = INT64_MAX; 4335 int64_t adj_rd = INT64_MAX;
4337 if (ref_frame > INTRA_FRAME) 4336 if (ref_frame > INTRA_FRAME)
4338 adj_rd = this_rd + tx_cache[i] - tx_cache[cm->tx_mode]; 4337 adj_rd = this_rd + tx_cache[i] - tx_cache[cm->tx_mode];
4339 else 4338 else
4340 adj_rd = this_rd; 4339 adj_rd = this_rd;
4341 4340
4342 if (adj_rd < best_tx_rd[i]) 4341 if (adj_rd < best_tx_rd[i])
4343 best_tx_rd[i] = adj_rd; 4342 best_tx_rd[i] = adj_rd;
(...skipping 18 matching lines...) Expand all
4362 *mbmi = best_mbmode; 4361 *mbmi = best_mbmode;
4363 uv_tx_size = get_uv_tx_size(mbmi); 4362 uv_tx_size = get_uv_tx_size(mbmi);
4364 rd_pick_intra_sbuv_mode(cpi, x, ctx, &rate_uv_intra[uv_tx_size], 4363 rd_pick_intra_sbuv_mode(cpi, x, ctx, &rate_uv_intra[uv_tx_size],
4365 &rate_uv_tokenonly[uv_tx_size], 4364 &rate_uv_tokenonly[uv_tx_size],
4366 &dist_uv[uv_tx_size], 4365 &dist_uv[uv_tx_size],
4367 &skip_uv[uv_tx_size], 4366 &skip_uv[uv_tx_size],
4368 BLOCK_8X8, uv_tx_size); 4367 BLOCK_8X8, uv_tx_size);
4369 } 4368 }
4370 } 4369 }
4371 4370
4372 if (best_rd == INT64_MAX && bsize < BLOCK_8X8) { 4371 if (best_rd == INT64_MAX) {
4373 *returnrate = INT_MAX; 4372 *returnrate = INT_MAX;
4374 *returndistortion = INT64_MAX; 4373 *returndistortion = INT64_MAX;
4375 return best_rd; 4374 return best_rd;
4376 } 4375 }
4377 4376
4378 assert((cm->interp_filter == SWITCHABLE) || 4377 assert((cm->interp_filter == SWITCHABLE) ||
4379 (cm->interp_filter == best_mbmode.interp_filter) || 4378 (cm->interp_filter == best_mbmode.interp_filter) ||
4380 !is_inter_block(&best_mbmode)); 4379 !is_inter_block(&best_mbmode));
4381 4380
4382 // Updating rd_thresh_freq_fact[] here means that the different 4381 // Updating rd_thresh_freq_fact[] here means that the different
4383 // partition/block sizes are handled independently based on the best 4382 // partition/block sizes are handled independently based on the best
4384 // choice for the current partition. It may well be better to keep a scaled 4383 // choice for the current partition. It may well be better to keep a scaled
4385 // best rd so far value and update rd_thresh_freq_fact based on the mode/size 4384 // best rd so far value and update rd_thresh_freq_fact based on the mode/size
4386 // combination that wins out. 4385 // combination that wins out.
4387 if (cpi->sf.adaptive_rd_thresh) { 4386 if (cpi->sf.adaptive_rd_thresh) {
4388 for (mode_index = 0; mode_index < MAX_REFS; ++mode_index) { 4387 for (mode_index = 0; mode_index < MAX_REFS; ++mode_index) {
4388 int *const fact = &cpi->rd_thresh_freq_sub8x8[bsize][mode_index];
4389
4389 if (mode_index == best_mode_index) { 4390 if (mode_index == best_mode_index) {
4390 cpi->rd_thresh_freq_sub8x8[bsize][mode_index] -= 4391 *fact -= (*fact >> 3);
4391 (cpi->rd_thresh_freq_sub8x8[bsize][mode_index] >> 3);
4392 } else { 4392 } else {
4393 cpi->rd_thresh_freq_sub8x8[bsize][mode_index] += RD_THRESH_INC; 4393 *fact = MIN(*fact + RD_THRESH_INC,
4394 if (cpi->rd_thresh_freq_sub8x8[bsize][mode_index] > 4394 cpi->sf.adaptive_rd_thresh * RD_THRESH_MAX_FACT);
4395 (cpi->sf.adaptive_rd_thresh * RD_THRESH_MAX_FACT)) {
4396 cpi->rd_thresh_freq_sub8x8[bsize][mode_index] =
4397 cpi->sf.adaptive_rd_thresh * RD_THRESH_MAX_FACT;
4398 }
4399 } 4395 }
4400 } 4396 }
4401 } 4397 }
4402 4398
4403 // macroblock modes 4399 // macroblock modes
4404 *mbmi = best_mbmode; 4400 *mbmi = best_mbmode;
4405 x->skip |= best_skip2; 4401 x->skip |= best_skip2;
4406 if (!is_inter_block(&best_mbmode)) { 4402 if (!is_inter_block(&best_mbmode)) {
4407 for (i = 0; i < 4; i++) 4403 for (i = 0; i < 4; i++)
4408 xd->mi_8x8[0]->bmi[i].as_mode = best_bmodes[i].as_mode; 4404 xd->mi[0]->bmi[i].as_mode = best_bmodes[i].as_mode;
4409 } else { 4405 } else {
4410 for (i = 0; i < 4; ++i) 4406 for (i = 0; i < 4; ++i)
4411 vpx_memcpy(&xd->mi_8x8[0]->bmi[i], &best_bmodes[i], sizeof(b_mode_info)); 4407 vpx_memcpy(&xd->mi[0]->bmi[i], &best_bmodes[i], sizeof(b_mode_info));
4412 4408
4413 mbmi->mv[0].as_int = xd->mi_8x8[0]->bmi[3].as_mv[0].as_int; 4409 mbmi->mv[0].as_int = xd->mi[0]->bmi[3].as_mv[0].as_int;
4414 mbmi->mv[1].as_int = xd->mi_8x8[0]->bmi[3].as_mv[1].as_int; 4410 mbmi->mv[1].as_int = xd->mi[0]->bmi[3].as_mv[1].as_int;
4415 } 4411 }
4416 4412
4417 for (i = 0; i < REFERENCE_MODES; ++i) { 4413 for (i = 0; i < REFERENCE_MODES; ++i) {
4418 if (best_pred_rd[i] == INT64_MAX) 4414 if (best_pred_rd[i] == INT64_MAX)
4419 best_pred_diff[i] = INT_MIN; 4415 best_pred_diff[i] = INT_MIN;
4420 else 4416 else
4421 best_pred_diff[i] = best_rd - best_pred_rd[i]; 4417 best_pred_diff[i] = best_rd - best_pred_rd[i];
4422 } 4418 }
4423 4419
4424 if (!x->skip) { 4420 if (!x->skip) {
4425 for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; i++) { 4421 for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; i++) {
4426 if (best_filter_rd[i] == INT64_MAX) 4422 if (best_filter_rd[i] == INT64_MAX)
4427 best_filter_diff[i] = 0; 4423 best_filter_diff[i] = 0;
4428 else 4424 else
4429 best_filter_diff[i] = best_rd - best_filter_rd[i]; 4425 best_filter_diff[i] = best_rd - best_filter_rd[i];
4430 } 4426 }
4431 if (cm->interp_filter == SWITCHABLE) 4427 if (cm->interp_filter == SWITCHABLE)
4432 assert(best_filter_diff[SWITCHABLE_FILTERS] == 0); 4428 assert(best_filter_diff[SWITCHABLE_FILTERS] == 0);
4433 } else {
4434 vp9_zero(best_filter_diff);
4435 }
4436
4437 if (!x->skip) {
4438 for (i = 0; i < TX_MODES; i++) { 4429 for (i = 0; i < TX_MODES; i++) {
4439 if (best_tx_rd[i] == INT64_MAX) 4430 if (best_tx_rd[i] == INT64_MAX)
4440 best_tx_diff[i] = 0; 4431 best_tx_diff[i] = 0;
4441 else 4432 else
4442 best_tx_diff[i] = best_rd - best_tx_rd[i]; 4433 best_tx_diff[i] = best_rd - best_tx_rd[i];
4443 } 4434 }
4444 } else { 4435 } else {
4436 vp9_zero(best_filter_diff);
4445 vp9_zero(best_tx_diff); 4437 vp9_zero(best_tx_diff);
4446 } 4438 }
4447 4439
4448 set_ref_ptrs(cm, xd, mbmi->ref_frame[0], mbmi->ref_frame[1]); 4440 set_ref_ptrs(cm, xd, mbmi->ref_frame[0], mbmi->ref_frame[1]);
4449 store_coding_context(x, ctx, best_mode_index, 4441 store_coding_context(x, ctx, best_mode_index,
4450 &mbmi->ref_mvs[mbmi->ref_frame[0]][0], 4442 &mbmi->ref_mvs[mbmi->ref_frame[0]][0],
4451 &mbmi->ref_mvs[mbmi->ref_frame[1] < 0 ? 0 : 4443 &mbmi->ref_mvs[mbmi->ref_frame[1] < 0 ? 0 :
4452 mbmi->ref_frame[1]][0], 4444 mbmi->ref_frame[1]][0],
4453 best_pred_diff, best_tx_diff, best_filter_diff); 4445 best_pred_diff, best_tx_diff, best_filter_diff);
4454 4446
4455 return best_rd; 4447 return best_rd;
4456 } 4448 }
OLDNEW
« no previous file with comments | « source/libvpx/vp9/encoder/vp9_rdopt.h ('k') | source/libvpx/vp9/encoder/vp9_sad.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698