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

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

Issue 1124333011: libvpx: Pull from upstream (Closed) Base URL: https://chromium.googlesource.com/chromium/deps/libvpx.git@master
Patch Set: only update to last nights LKGR Created 5 years, 7 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
« no previous file with comments | « source/libvpx/vp9/encoder/vp9_encodeframe.h ('k') | source/libvpx/vp9/encoder/vp9_encodemb.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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 128*16, 128*16, 128*16, 128*16, 128*16, 128*16, 128*16, 128*16, 92 128*16, 128*16, 128*16, 128*16, 128*16, 128*16, 128*16, 128*16,
93 128*16, 128*16, 128*16, 128*16, 128*16, 128*16, 128*16, 128*16, 93 128*16, 128*16, 128*16, 128*16, 128*16, 128*16, 128*16, 128*16,
94 128*16, 128*16, 128*16, 128*16, 128*16, 128*16, 128*16, 128*16, 94 128*16, 128*16, 128*16, 128*16, 128*16, 128*16, 128*16, 128*16,
95 128*16, 128*16, 128*16, 128*16, 128*16, 128*16, 128*16, 128*16, 95 128*16, 128*16, 128*16, 128*16, 128*16, 128*16, 128*16, 128*16,
96 128*16, 128*16, 128*16, 128*16, 128*16, 128*16, 128*16, 128*16, 96 128*16, 128*16, 128*16, 128*16, 128*16, 128*16, 128*16, 128*16,
97 128*16, 128*16, 128*16, 128*16, 128*16, 128*16, 128*16, 128*16, 97 128*16, 128*16, 128*16, 128*16, 128*16, 128*16, 128*16, 128*16,
98 128*16, 128*16, 128*16, 128*16, 128*16, 128*16, 128*16, 128*16 98 128*16, 128*16, 128*16, 128*16, 128*16, 128*16, 128*16, 128*16
99 }; 99 };
100 #endif // CONFIG_VP9_HIGHBITDEPTH 100 #endif // CONFIG_VP9_HIGHBITDEPTH
101 101
102 static unsigned int get_sby_perpixel_variance(VP9_COMP *cpi, 102 unsigned int vp9_get_sby_perpixel_variance(VP9_COMP *cpi,
103 const struct buf_2d *ref, 103 const struct buf_2d *ref,
104 BLOCK_SIZE bs) { 104 BLOCK_SIZE bs) {
105 unsigned int sse; 105 unsigned int sse;
106 const unsigned int var = cpi->fn_ptr[bs].vf(ref->buf, ref->stride, 106 const unsigned int var = cpi->fn_ptr[bs].vf(ref->buf, ref->stride,
107 VP9_VAR_OFFS, 0, &sse); 107 VP9_VAR_OFFS, 0, &sse);
108 return ROUND_POWER_OF_TWO(var, num_pels_log2_lookup[bs]); 108 return ROUND_POWER_OF_TWO(var, num_pels_log2_lookup[bs]);
109 } 109 }
110 110
111 #if CONFIG_VP9_HIGHBITDEPTH 111 #if CONFIG_VP9_HIGHBITDEPTH
112 static unsigned int high_get_sby_perpixel_variance( 112 unsigned int vp9_high_get_sby_perpixel_variance(
113 VP9_COMP *cpi, const struct buf_2d *ref, BLOCK_SIZE bs, int bd) { 113 VP9_COMP *cpi, const struct buf_2d *ref, BLOCK_SIZE bs, int bd) {
114 unsigned int var, sse; 114 unsigned int var, sse;
115 switch (bd) { 115 switch (bd) {
116 case 10: 116 case 10:
117 var = cpi->fn_ptr[bs].vf(ref->buf, ref->stride, 117 var = cpi->fn_ptr[bs].vf(ref->buf, ref->stride,
118 CONVERT_TO_BYTEPTR(VP9_HIGH_VAR_OFFS_10), 118 CONVERT_TO_BYTEPTR(VP9_HIGH_VAR_OFFS_10),
119 0, &sse); 119 0, &sse);
120 break; 120 break;
121 case 12: 121 case 12:
122 var = cpi->fn_ptr[bs].vf(ref->buf, ref->stride, 122 var = cpi->fn_ptr[bs].vf(ref->buf, ref->stride,
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 if (var < 8) 158 if (var < 8)
159 return BLOCK_64X64; 159 return BLOCK_64X64;
160 else if (var < 128) 160 else if (var < 128)
161 return BLOCK_32X32; 161 return BLOCK_32X32;
162 else if (var < 2048) 162 else if (var < 2048)
163 return BLOCK_16X16; 163 return BLOCK_16X16;
164 else 164 else
165 return BLOCK_8X8; 165 return BLOCK_8X8;
166 } 166 }
167 167
168 static BLOCK_SIZE get_nonrd_var_based_fixed_partition(VP9_COMP *cpi,
169 MACROBLOCK *x,
170 int mi_row,
171 int mi_col) {
172 unsigned int var = get_sby_perpixel_diff_variance(cpi, &x->plane[0].src,
173 mi_row, mi_col,
174 BLOCK_64X64);
175 if (var < 4)
176 return BLOCK_64X64;
177 else if (var < 10)
178 return BLOCK_32X32;
179 else
180 return BLOCK_16X16;
181 }
182
183 // Lighter version of set_offsets that only sets the mode info 168 // Lighter version of set_offsets that only sets the mode info
184 // pointers. 169 // pointers.
185 static INLINE void set_mode_info_offsets(VP9_COMMON *const cm, 170 static INLINE void set_mode_info_offsets(VP9_COMMON *const cm,
186 MACROBLOCKD *const xd, 171 MACROBLOCKD *const xd,
187 int mi_row, 172 int mi_row,
188 int mi_col) { 173 int mi_col) {
189 const int idx_str = xd->mi_stride * mi_row + mi_col; 174 const int idx_str = xd->mi_stride * mi_row + mi_col;
190 xd->mi = cm->mi + idx_str; 175 xd->mi = cm->mi_grid_visible + idx_str;
191 xd->mi[0].src_mi = &xd->mi[0]; 176 xd->mi[0] = cm->mi + idx_str;
192 } 177 }
193 178
194 static void set_offsets(VP9_COMP *cpi, const TileInfo *const tile, 179 static void set_offsets(VP9_COMP *cpi, const TileInfo *const tile,
195 MACROBLOCK *const x, int mi_row, int mi_col, 180 MACROBLOCK *const x, int mi_row, int mi_col,
196 BLOCK_SIZE bsize) { 181 BLOCK_SIZE bsize) {
197 VP9_COMMON *const cm = &cpi->common; 182 VP9_COMMON *const cm = &cpi->common;
198 MACROBLOCKD *const xd = &x->e_mbd; 183 MACROBLOCKD *const xd = &x->e_mbd;
199 MB_MODE_INFO *mbmi; 184 MB_MODE_INFO *mbmi;
200 const int mi_width = num_8x8_blocks_wide_lookup[bsize]; 185 const int mi_width = num_8x8_blocks_wide_lookup[bsize];
201 const int mi_height = num_8x8_blocks_high_lookup[bsize]; 186 const int mi_height = num_8x8_blocks_high_lookup[bsize];
202 const struct segmentation *const seg = &cm->seg; 187 const struct segmentation *const seg = &cm->seg;
203 188
204 set_skip_context(xd, mi_row, mi_col); 189 set_skip_context(xd, mi_row, mi_col);
205 190
206 set_mode_info_offsets(cm, xd, mi_row, mi_col); 191 set_mode_info_offsets(cm, xd, mi_row, mi_col);
207 192
208 mbmi = &xd->mi[0].src_mi->mbmi; 193 mbmi = &xd->mi[0]->mbmi;
209 194
210 // Set up destination pointers. 195 // Set up destination pointers.
211 vp9_setup_dst_planes(xd->plane, get_frame_new_buffer(cm), mi_row, mi_col); 196 vp9_setup_dst_planes(xd->plane, get_frame_new_buffer(cm), mi_row, mi_col);
212 197
213 // Set up limit values for MV components. 198 // Set up limit values for MV components.
214 // Mv beyond the range do not produce new/different prediction block. 199 // Mv beyond the range do not produce new/different prediction block.
215 x->mv_row_min = -(((mi_row + mi_height) * MI_SIZE) + VP9_INTERP_EXTEND); 200 x->mv_row_min = -(((mi_row + mi_height) * MI_SIZE) + VP9_INTERP_EXTEND);
216 x->mv_col_min = -(((mi_col + mi_width) * MI_SIZE) + VP9_INTERP_EXTEND); 201 x->mv_col_min = -(((mi_col + mi_width) * MI_SIZE) + VP9_INTERP_EXTEND);
217 x->mv_row_max = (cm->mi_rows - mi_row) * MI_SIZE + VP9_INTERP_EXTEND; 202 x->mv_row_max = (cm->mi_rows - mi_row) * MI_SIZE + VP9_INTERP_EXTEND;
218 x->mv_col_max = (cm->mi_cols - mi_col) * MI_SIZE + VP9_INTERP_EXTEND; 203 x->mv_col_max = (cm->mi_cols - mi_col) * MI_SIZE + VP9_INTERP_EXTEND;
(...skipping 28 matching lines...) Expand all
247 232
248 static void duplicate_mode_info_in_sb(VP9_COMMON *cm, MACROBLOCKD *xd, 233 static void duplicate_mode_info_in_sb(VP9_COMMON *cm, MACROBLOCKD *xd,
249 int mi_row, int mi_col, 234 int mi_row, int mi_col,
250 BLOCK_SIZE bsize) { 235 BLOCK_SIZE bsize) {
251 const int block_width = num_8x8_blocks_wide_lookup[bsize]; 236 const int block_width = num_8x8_blocks_wide_lookup[bsize];
252 const int block_height = num_8x8_blocks_high_lookup[bsize]; 237 const int block_height = num_8x8_blocks_high_lookup[bsize];
253 int i, j; 238 int i, j;
254 for (j = 0; j < block_height; ++j) 239 for (j = 0; j < block_height; ++j)
255 for (i = 0; i < block_width; ++i) { 240 for (i = 0; i < block_width; ++i) {
256 if (mi_row + j < cm->mi_rows && mi_col + i < cm->mi_cols) 241 if (mi_row + j < cm->mi_rows && mi_col + i < cm->mi_cols)
257 xd->mi[j * xd->mi_stride + i].src_mi = &xd->mi[0]; 242 xd->mi[j * xd->mi_stride + i] = xd->mi[0];
258 } 243 }
259 } 244 }
260 245
261 static void set_block_size(VP9_COMP * const cpi, 246 static void set_block_size(VP9_COMP * const cpi,
262 MACROBLOCKD *const xd, 247 MACROBLOCKD *const xd,
263 int mi_row, int mi_col, 248 int mi_row, int mi_col,
264 BLOCK_SIZE bsize) { 249 BLOCK_SIZE bsize) {
265 if (cpi->common.mi_cols > mi_col && cpi->common.mi_rows > mi_row) { 250 if (cpi->common.mi_cols > mi_col && cpi->common.mi_rows > mi_row) {
266 set_mode_info_offsets(&cpi->common, xd, mi_row, mi_col); 251 set_mode_info_offsets(&cpi->common, xd, mi_row, mi_col);
267 xd->mi[0].src_mi->mbmi.sb_type = bsize; 252 xd->mi[0]->mbmi.sb_type = bsize;
268 } 253 }
269 } 254 }
270 255
271 typedef struct { 256 typedef struct {
272 int64_t sum_square_error; 257 int64_t sum_square_error;
273 int64_t sum_error; 258 int64_t sum_error;
274 int log2_count; 259 int log2_count;
275 int variance; 260 int variance;
276 } var; 261 } var;
277 262
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
398 BLOCK_SIZE bsize, 383 BLOCK_SIZE bsize,
399 int mi_row, 384 int mi_row,
400 int mi_col, 385 int mi_col,
401 int64_t threshold, 386 int64_t threshold,
402 BLOCK_SIZE bsize_min, 387 BLOCK_SIZE bsize_min,
403 int force_split) { 388 int force_split) {
404 VP9_COMMON * const cm = &cpi->common; 389 VP9_COMMON * const cm = &cpi->common;
405 variance_node vt; 390 variance_node vt;
406 const int block_width = num_8x8_blocks_wide_lookup[bsize]; 391 const int block_width = num_8x8_blocks_wide_lookup[bsize];
407 const int block_height = num_8x8_blocks_high_lookup[bsize]; 392 const int block_height = num_8x8_blocks_high_lookup[bsize];
393 const int low_res = (cm->width <= 352 && cm->height <= 288);
408 394
409 assert(block_height == block_width); 395 assert(block_height == block_width);
410 tree_to_node(data, bsize, &vt); 396 tree_to_node(data, bsize, &vt);
411 397
412 if (force_split) 398 if (force_split == 1)
413 return 0; 399 return 0;
414 400
415 // For bsize=bsize_min (16x16/8x8 for 8x8/4x4 downsampling), select if 401 // For bsize=bsize_min (16x16/8x8 for 8x8/4x4 downsampling), select if
416 // variance is below threshold, otherwise split will be selected. 402 // variance is below threshold, otherwise split will be selected.
417 // No check for vert/horiz split as too few samples for variance. 403 // No check for vert/horiz split as too few samples for variance.
418 if (bsize == bsize_min) { 404 if (bsize == bsize_min) {
419 get_variance(&vt.part_variances->none); 405 // Variance already computed to set the force_split.
406 if (low_res || cm->frame_type == KEY_FRAME)
407 get_variance(&vt.part_variances->none);
420 if (mi_col + block_width / 2 < cm->mi_cols && 408 if (mi_col + block_width / 2 < cm->mi_cols &&
421 mi_row + block_height / 2 < cm->mi_rows && 409 mi_row + block_height / 2 < cm->mi_rows &&
422 vt.part_variances->none.variance < threshold) { 410 vt.part_variances->none.variance < threshold) {
423 set_block_size(cpi, xd, mi_row, mi_col, bsize); 411 set_block_size(cpi, xd, mi_row, mi_col, bsize);
424 return 1; 412 return 1;
425 } 413 }
426 return 0; 414 return 0;
427 } else if (bsize > bsize_min) { 415 } else if (bsize > bsize_min) {
428 // Variance is already computed for 32x32 blocks to set the force_split. 416 // Variance already computed to set the force_split.
429 if (bsize != BLOCK_32X32) 417 if (low_res || cm->frame_type == KEY_FRAME)
430 get_variance(&vt.part_variances->none); 418 get_variance(&vt.part_variances->none);
431 // For key frame or low_res: for bsize above 32X32 or very high variance, 419 // For key frame: take split for bsize above 32X32 or very high variance.
432 // take split.
433 if (cm->frame_type == KEY_FRAME && 420 if (cm->frame_type == KEY_FRAME &&
434 (bsize > BLOCK_32X32 || 421 (bsize > BLOCK_32X32 ||
435 vt.part_variances->none.variance > (threshold << 4))) { 422 vt.part_variances->none.variance > (threshold << 4))) {
436 return 0; 423 return 0;
437 } 424 }
438 // If variance is low, take the bsize (no split). 425 // If variance is low, take the bsize (no split).
439 if (mi_col + block_width / 2 < cm->mi_cols && 426 if (mi_col + block_width / 2 < cm->mi_cols &&
440 mi_row + block_height / 2 < cm->mi_rows && 427 mi_row + block_height / 2 < cm->mi_rows &&
441 vt.part_variances->none.variance < threshold) { 428 vt.part_variances->none.variance < threshold) {
442 set_block_size(cpi, xd, mi_row, mi_col, bsize); 429 set_block_size(cpi, xd, mi_row, mi_col, bsize);
443 return 1; 430 return 1;
444 } 431 }
445 432
446 // Check vertical split. 433 // Check vertical split.
447 if (mi_row + block_height / 2 < cm->mi_rows) { 434 if (mi_row + block_height / 2 < cm->mi_rows) {
435 BLOCK_SIZE subsize = get_subsize(bsize, PARTITION_VERT);
448 get_variance(&vt.part_variances->vert[0]); 436 get_variance(&vt.part_variances->vert[0]);
449 get_variance(&vt.part_variances->vert[1]); 437 get_variance(&vt.part_variances->vert[1]);
450 if (vt.part_variances->vert[0].variance < threshold && 438 if (vt.part_variances->vert[0].variance < threshold &&
451 vt.part_variances->vert[1].variance < threshold) { 439 vt.part_variances->vert[1].variance < threshold &&
452 BLOCK_SIZE subsize = get_subsize(bsize, PARTITION_VERT); 440 get_plane_block_size(subsize, &xd->plane[1]) < BLOCK_INVALID) {
453 set_block_size(cpi, xd, mi_row, mi_col, subsize); 441 set_block_size(cpi, xd, mi_row, mi_col, subsize);
454 set_block_size(cpi, xd, mi_row, mi_col + block_width / 2, subsize); 442 set_block_size(cpi, xd, mi_row, mi_col + block_width / 2, subsize);
455 return 1; 443 return 1;
456 } 444 }
457 } 445 }
458 // Check horizontal split. 446 // Check horizontal split.
459 if (mi_col + block_width / 2 < cm->mi_cols) { 447 if (mi_col + block_width / 2 < cm->mi_cols) {
448 BLOCK_SIZE subsize = get_subsize(bsize, PARTITION_HORZ);
460 get_variance(&vt.part_variances->horz[0]); 449 get_variance(&vt.part_variances->horz[0]);
461 get_variance(&vt.part_variances->horz[1]); 450 get_variance(&vt.part_variances->horz[1]);
462 if (vt.part_variances->horz[0].variance < threshold && 451 if (vt.part_variances->horz[0].variance < threshold &&
463 vt.part_variances->horz[1].variance < threshold) { 452 vt.part_variances->horz[1].variance < threshold &&
464 BLOCK_SIZE subsize = get_subsize(bsize, PARTITION_HORZ); 453 get_plane_block_size(subsize, &xd->plane[1]) < BLOCK_INVALID) {
465 set_block_size(cpi, xd, mi_row, mi_col, subsize); 454 set_block_size(cpi, xd, mi_row, mi_col, subsize);
466 set_block_size(cpi, xd, mi_row + block_height / 2, mi_col, subsize); 455 set_block_size(cpi, xd, mi_row + block_height / 2, mi_col, subsize);
467 return 1; 456 return 1;
468 } 457 }
469 } 458 }
470 459
471 return 0; 460 return 0;
472 } 461 }
473 return 0; 462 return 0;
474 } 463 }
475 464
476
477 void vp9_set_vbp_thresholds(VP9_COMP *cpi, int q) { 465 void vp9_set_vbp_thresholds(VP9_COMP *cpi, int q) {
478 SPEED_FEATURES *const sf = &cpi->sf; 466 SPEED_FEATURES *const sf = &cpi->sf;
479 if (sf->partition_search_type != VAR_BASED_PARTITION && 467 if (sf->partition_search_type != VAR_BASED_PARTITION &&
480 sf->partition_search_type != REFERENCE_PARTITION) { 468 sf->partition_search_type != REFERENCE_PARTITION) {
481 return; 469 return;
482 } else { 470 } else {
483 VP9_COMMON *const cm = &cpi->common; 471 VP9_COMMON *const cm = &cpi->common;
484 const int is_key_frame = (cm->frame_type == KEY_FRAME); 472 const int is_key_frame = (cm->frame_type == KEY_FRAME);
485 const int threshold_multiplier = is_key_frame ? 80 : 4; 473 const int threshold_multiplier = is_key_frame ? 20 : 1;
486 const int64_t threshold_base = (int64_t)(threshold_multiplier * 474 const int64_t threshold_base = (int64_t)(threshold_multiplier *
487 vp9_convert_qindex_to_q(q, cm->bit_depth)); 475 cpi->y_dequant[q][1]);
488 476
489 // TODO(marpan): Allow 4x4 partitions for inter-frames. 477 // TODO(marpan): Allow 4x4 partitions for inter-frames.
490 // use_4x4_partition = (variance4x4downsample[i2 + j] == 1); 478 // use_4x4_partition = (variance4x4downsample[i2 + j] == 1);
491 // If 4x4 partition is not used, then 8x8 partition will be selected 479 // If 4x4 partition is not used, then 8x8 partition will be selected
492 // if variance of 16x16 block is very high, so use larger threshold 480 // if variance of 16x16 block is very high, so use larger threshold
493 // for 16x16 (threshold_bsize_min) in that case. 481 // for 16x16 (threshold_bsize_min) in that case.
482
483 // Array index: 0 - threshold_64x64; 1 - threshold_32x32;
484 // 2 - threshold_16x16; 3 - vbp_threshold_8x8;
494 if (is_key_frame) { 485 if (is_key_frame) {
495 cpi->vbp_threshold = threshold_base >> 2; 486 cpi->vbp_thresholds[0] = threshold_base;
496 cpi->vbp_threshold_bsize_max = threshold_base; 487 cpi->vbp_thresholds[1] = threshold_base >> 2;
497 cpi->vbp_threshold_bsize_min = threshold_base << 2; 488 cpi->vbp_thresholds[2] = threshold_base >> 2;
498 cpi->vbp_threshold_16x16 = cpi->vbp_threshold; 489 cpi->vbp_thresholds[3] = threshold_base << 2;
490 cpi->vbp_threshold_sad = 0;
499 cpi->vbp_bsize_min = BLOCK_8X8; 491 cpi->vbp_bsize_min = BLOCK_8X8;
500 } else { 492 } else {
501 cpi->vbp_threshold = threshold_base; 493 cpi->vbp_thresholds[1] = threshold_base;
502 if (cm->width <= 352 && cm->height <= 288) { 494 if (cm->width <= 352 && cm->height <= 288) {
503 cpi->vbp_threshold_bsize_max = threshold_base >> 2; 495 cpi->vbp_thresholds[0] = threshold_base >> 2;
504 cpi->vbp_threshold_bsize_min = threshold_base << 3; 496 cpi->vbp_thresholds[2] = threshold_base << 3;
497 cpi->vbp_threshold_sad = 100;
505 } else { 498 } else {
506 cpi->vbp_threshold_bsize_max = threshold_base; 499 cpi->vbp_thresholds[0] = threshold_base;
507 cpi->vbp_threshold_bsize_min = threshold_base << cpi->oxcf.speed; 500 cpi->vbp_thresholds[1] = (5 * threshold_base) >> 2;
501 cpi->vbp_thresholds[2] = threshold_base << cpi->oxcf.speed;
502 cpi->vbp_threshold_sad = (cpi->y_dequant[q][1] << 1) > 1000 ?
503 (cpi->y_dequant[q][1] << 1) : 1000;
508 } 504 }
509 cpi->vbp_threshold_16x16 = cpi->vbp_threshold_bsize_min;
510 cpi->vbp_bsize_min = BLOCK_16X16; 505 cpi->vbp_bsize_min = BLOCK_16X16;
511 } 506 }
507 cpi->vbp_threshold_minmax = 15 + (q >> 3);
508 }
509 }
510
511 // Compute the minmax over the 8x8 subblocks.
512 static int compute_minmax_8x8(const uint8_t *s, int sp, const uint8_t *d,
513 int dp, int x16_idx, int y16_idx,
514 #if CONFIG_VP9_HIGHBITDEPTH
515 int highbd_flag,
516 #endif
517 int pixels_wide,
518 int pixels_high) {
519 int k;
520 int minmax_max = 0;
521 int minmax_min = 255;
522 // Loop over the 4 8x8 subblocks.
523 for (k = 0; k < 4; k++) {
524 int x8_idx = x16_idx + ((k & 1) << 3);
525 int y8_idx = y16_idx + ((k >> 1) << 3);
526 int min = 0;
527 int max = 0;
528 if (x8_idx < pixels_wide && y8_idx < pixels_high) {
529 #if CONFIG_VP9_HIGHBITDEPTH
530 if (highbd_flag & YV12_FLAG_HIGHBITDEPTH) {
531 vp9_highbd_minmax_8x8(s + y8_idx * sp + x8_idx, sp,
532 d + y8_idx * dp + x8_idx, dp,
533 &min, &max);
534 } else {
535 vp9_minmax_8x8(s + y8_idx * sp + x8_idx, sp,
536 d + y8_idx * dp + x8_idx, dp,
537 &min, &max);
538 }
539 #else
540 vp9_minmax_8x8(s + y8_idx * sp + x8_idx, sp,
541 d + y8_idx * dp + x8_idx, dp,
542 &min, &max);
543 #endif
544 if ((max - min) > minmax_max)
545 minmax_max = (max - min);
546 if ((max - min) < minmax_min)
547 minmax_min = (max - min);
548 }
549 }
550 return (minmax_max - minmax_min);
551 }
552
553 static void modify_vbp_thresholds(VP9_COMP *cpi, int64_t thresholds[], int q) {
554 VP9_COMMON *const cm = &cpi->common;
555 const int64_t threshold_base = (int64_t)(cpi->y_dequant[q][1]);
556
557 // Array index: 0 - threshold_64x64; 1 - threshold_32x32;
558 // 2 - threshold_16x16; 3 - vbp_threshold_8x8;
559 thresholds[1] = threshold_base;
560 if (cm->width <= 352 && cm->height <= 288) {
561 thresholds[0] = threshold_base >> 2;
562 thresholds[2] = threshold_base << 3;
563 } else {
564 thresholds[0] = threshold_base;
565 thresholds[1] = (5 * threshold_base) >> 2;
566 thresholds[2] = threshold_base << cpi->oxcf.speed;
567 }
568 }
569
570 static void fill_variance_4x4avg(const uint8_t *s, int sp, const uint8_t *d,
571 int dp, int x8_idx, int y8_idx, v8x8 *vst,
572 #if CONFIG_VP9_HIGHBITDEPTH
573 int highbd_flag,
574 #endif
575 int pixels_wide,
576 int pixels_high,
577 int is_key_frame) {
578 int k;
579 for (k = 0; k < 4; k++) {
580 int x4_idx = x8_idx + ((k & 1) << 2);
581 int y4_idx = y8_idx + ((k >> 1) << 2);
582 unsigned int sse = 0;
583 int sum = 0;
584 if (x4_idx < pixels_wide && y4_idx < pixels_high) {
585 int s_avg;
586 int d_avg = 128;
587 #if CONFIG_VP9_HIGHBITDEPTH
588 if (highbd_flag & YV12_FLAG_HIGHBITDEPTH) {
589 s_avg = vp9_highbd_avg_4x4(s + y4_idx * sp + x4_idx, sp);
590 if (!is_key_frame)
591 d_avg = vp9_highbd_avg_4x4(d + y4_idx * dp + x4_idx, dp);
592 } else {
593 s_avg = vp9_avg_4x4(s + y4_idx * sp + x4_idx, sp);
594 if (!is_key_frame)
595 d_avg = vp9_avg_4x4(d + y4_idx * dp + x4_idx, dp);
596 }
597 #else
598 s_avg = vp9_avg_4x4(s + y4_idx * sp + x4_idx, sp);
599 if (!is_key_frame)
600 d_avg = vp9_avg_4x4(d + y4_idx * dp + x4_idx, dp);
601 #endif
602 sum = s_avg - d_avg;
603 sse = sum * sum;
604 }
605 fill_variance(sse, sum, 0, &vst->split[k].part_variances.none);
606 }
607 }
608
609 static void fill_variance_8x8avg(const uint8_t *s, int sp, const uint8_t *d,
610 int dp, int x16_idx, int y16_idx, v16x16 *vst,
611 #if CONFIG_VP9_HIGHBITDEPTH
612 int highbd_flag,
613 #endif
614 int pixels_wide,
615 int pixels_high,
616 int is_key_frame) {
617 int k;
618 for (k = 0; k < 4; k++) {
619 int x8_idx = x16_idx + ((k & 1) << 3);
620 int y8_idx = y16_idx + ((k >> 1) << 3);
621 unsigned int sse = 0;
622 int sum = 0;
623 if (x8_idx < pixels_wide && y8_idx < pixels_high) {
624 int s_avg;
625 int d_avg = 128;
626 #if CONFIG_VP9_HIGHBITDEPTH
627 if (highbd_flag & YV12_FLAG_HIGHBITDEPTH) {
628 s_avg = vp9_highbd_avg_8x8(s + y8_idx * sp + x8_idx, sp);
629 if (!is_key_frame)
630 d_avg = vp9_highbd_avg_8x8(d + y8_idx * dp + x8_idx, dp);
631 } else {
632 s_avg = vp9_avg_8x8(s + y8_idx * sp + x8_idx, sp);
633 if (!is_key_frame)
634 d_avg = vp9_avg_8x8(d + y8_idx * dp + x8_idx, dp);
635 }
636 #else
637 s_avg = vp9_avg_8x8(s + y8_idx * sp + x8_idx, sp);
638 if (!is_key_frame)
639 d_avg = vp9_avg_8x8(d + y8_idx * dp + x8_idx, dp);
640 #endif
641 sum = s_avg - d_avg;
642 sse = sum * sum;
643 }
644 fill_variance(sse, sum, 0, &vst->split[k].part_variances.none);
512 } 645 }
513 } 646 }
514 647
515 // This function chooses partitioning based on the variance between source and 648 // This function chooses partitioning based on the variance between source and
516 // reconstructed last, where variance is computed for down-sampled inputs. 649 // reconstructed last, where variance is computed for down-sampled inputs.
517 static void choose_partitioning(VP9_COMP *cpi, 650 static int choose_partitioning(VP9_COMP *cpi,
518 const TileInfo *const tile, 651 const TileInfo *const tile,
519 MACROBLOCK *x, 652 MACROBLOCK *x,
520 int mi_row, int mi_col) { 653 int mi_row, int mi_col) {
521 VP9_COMMON * const cm = &cpi->common; 654 VP9_COMMON * const cm = &cpi->common;
522 MACROBLOCKD *xd = &x->e_mbd; 655 MACROBLOCKD *xd = &x->e_mbd;
523 int i, j, k, m; 656 int i, j, k, m;
524 v64x64 vt; 657 v64x64 vt;
525 v16x16 vt2[16]; 658 v16x16 vt2[16];
526 int force_split[5]; 659 int force_split[21];
527 uint8_t *s; 660 uint8_t *s;
528 const uint8_t *d; 661 const uint8_t *d;
529 int sp; 662 int sp;
530 int dp; 663 int dp;
531 int pixels_wide = 64, pixels_high = 64; 664 int pixels_wide = 64, pixels_high = 64;
665 int64_t thresholds[4] = {cpi->vbp_thresholds[0], cpi->vbp_thresholds[1],
666 cpi->vbp_thresholds[2], cpi->vbp_thresholds[3]};
532 667
533 // Always use 4x4 partition for key frame. 668 // Always use 4x4 partition for key frame.
534 const int is_key_frame = (cm->frame_type == KEY_FRAME); 669 const int is_key_frame = (cm->frame_type == KEY_FRAME);
535 const int use_4x4_partition = is_key_frame; 670 const int use_4x4_partition = is_key_frame;
536 const int low_res = (cm->width <= 352 && cm->height <= 288); 671 const int low_res = (cm->width <= 352 && cm->height <= 288);
537 int variance4x4downsample[16]; 672 int variance4x4downsample[16];
538 673
539 int segment_id = CR_SEGMENT_ID_BASE; 674 int segment_id = CR_SEGMENT_ID_BASE;
540 if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ && cm->seg.enabled) { 675 if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ && cm->seg.enabled) {
541 const uint8_t *const map = cm->seg.update_map ? cpi->segmentation_map : 676 const uint8_t *const map = cm->seg.update_map ? cpi->segmentation_map :
542 cm->last_frame_seg_map; 677 cm->last_frame_seg_map;
543 segment_id = vp9_get_segment_id(cm, map, BLOCK_64X64, mi_row, mi_col); 678 segment_id = vp9_get_segment_id(cm, map, BLOCK_64X64, mi_row, mi_col);
679
680 if (cyclic_refresh_segment_id_boosted(segment_id)) {
681 int q = vp9_get_qindex(&cm->seg, segment_id, cm->base_qindex);
682 modify_vbp_thresholds(cpi, thresholds, q);
683 }
544 } 684 }
545 685
546 set_offsets(cpi, tile, x, mi_row, mi_col, BLOCK_64X64); 686 set_offsets(cpi, tile, x, mi_row, mi_col, BLOCK_64X64);
547 687
548 if (xd->mb_to_right_edge < 0) 688 if (xd->mb_to_right_edge < 0)
549 pixels_wide += (xd->mb_to_right_edge >> 3); 689 pixels_wide += (xd->mb_to_right_edge >> 3);
550 if (xd->mb_to_bottom_edge < 0) 690 if (xd->mb_to_bottom_edge < 0)
551 pixels_high += (xd->mb_to_bottom_edge >> 3); 691 pixels_high += (xd->mb_to_bottom_edge >> 3);
552 692
553 s = x->plane[0].src.buf; 693 s = x->plane[0].src.buf;
554 sp = x->plane[0].src.stride; 694 sp = x->plane[0].src.stride;
555 695
556 if (!is_key_frame) { 696 if (!is_key_frame) {
557 MB_MODE_INFO *mbmi = &xd->mi[0].src_mi->mbmi; 697 MB_MODE_INFO *mbmi = &xd->mi[0]->mbmi;
558 unsigned int uv_sad; 698 unsigned int uv_sad;
559 const YV12_BUFFER_CONFIG *yv12 = get_ref_frame_buffer(cpi, LAST_FRAME); 699 const YV12_BUFFER_CONFIG *yv12 = get_ref_frame_buffer(cpi, LAST_FRAME);
560 700
561 const YV12_BUFFER_CONFIG *yv12_g = get_ref_frame_buffer(cpi, GOLDEN_FRAME); 701 const YV12_BUFFER_CONFIG *yv12_g = get_ref_frame_buffer(cpi, GOLDEN_FRAME);
562 unsigned int y_sad, y_sad_g; 702 unsigned int y_sad, y_sad_g;
563 BLOCK_SIZE bsize; 703 const BLOCK_SIZE bsize = BLOCK_32X32
564 if (mi_row + 4 < cm->mi_rows && mi_col + 4 < cm->mi_cols) 704 + (mi_col + 4 < cm->mi_cols) * 2 + (mi_row + 4 < cm->mi_rows);
565 bsize = BLOCK_64X64;
566 else if (mi_row + 4 < cm->mi_rows && mi_col + 4 >= cm->mi_cols)
567 bsize = BLOCK_32X64;
568 else if (mi_row + 4 >= cm->mi_rows && mi_col + 4 < cm->mi_cols)
569 bsize = BLOCK_64X32;
570 else
571 bsize = BLOCK_32X32;
572 705
573 assert(yv12 != NULL); 706 assert(yv12 != NULL);
574
575 if (yv12_g && yv12_g != yv12) { 707 if (yv12_g && yv12_g != yv12) {
576 vp9_setup_pre_planes(xd, 0, yv12_g, mi_row, mi_col, 708 vp9_setup_pre_planes(xd, 0, yv12_g, mi_row, mi_col,
577 &cm->frame_refs[GOLDEN_FRAME - 1].sf); 709 &cm->frame_refs[GOLDEN_FRAME - 1].sf);
578 y_sad_g = cpi->fn_ptr[bsize].sdf(x->plane[0].src.buf, 710 y_sad_g = cpi->fn_ptr[bsize].sdf(x->plane[0].src.buf,
579 x->plane[0].src.stride, 711 x->plane[0].src.stride,
580 xd->plane[0].pre[0].buf, 712 xd->plane[0].pre[0].buf,
581 xd->plane[0].pre[0].stride); 713 xd->plane[0].pre[0].stride);
582 } else { 714 } else {
583 y_sad_g = UINT_MAX; 715 y_sad_g = UINT_MAX;
584 } 716 }
(...skipping 28 matching lines...) Expand all
613 uv_sad = UINT_MAX; 745 uv_sad = UINT_MAX;
614 else 746 else
615 uv_sad = cpi->fn_ptr[bs].sdf(p->src.buf, p->src.stride, 747 uv_sad = cpi->fn_ptr[bs].sdf(p->src.buf, p->src.stride,
616 pd->dst.buf, pd->dst.stride); 748 pd->dst.buf, pd->dst.stride);
617 749
618 x->color_sensitivity[i - 1] = uv_sad > (y_sad >> 2); 750 x->color_sensitivity[i - 1] = uv_sad > (y_sad >> 2);
619 } 751 }
620 752
621 d = xd->plane[0].dst.buf; 753 d = xd->plane[0].dst.buf;
622 dp = xd->plane[0].dst.stride; 754 dp = xd->plane[0].dst.stride;
755
756 // If the y_sad is very small, take 64x64 as partition and exit.
757 // Don't check on boosted segment for now, as 64x64 is suppressed there.
758 if (segment_id == CR_SEGMENT_ID_BASE &&
759 y_sad < cpi->vbp_threshold_sad) {
760 const int block_width = num_8x8_blocks_wide_lookup[BLOCK_64X64];
761 const int block_height = num_8x8_blocks_high_lookup[BLOCK_64X64];
762 if (mi_col + block_width / 2 < cm->mi_cols &&
763 mi_row + block_height / 2 < cm->mi_rows) {
764 set_block_size(cpi, xd, mi_row, mi_col, BLOCK_64X64);
765 return 0;
766 }
767 }
623 } else { 768 } else {
624 d = VP9_VAR_OFFS; 769 d = VP9_VAR_OFFS;
625 dp = 0; 770 dp = 0;
626 #if CONFIG_VP9_HIGHBITDEPTH 771 #if CONFIG_VP9_HIGHBITDEPTH
627 if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) { 772 if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
628 switch (xd->bd) { 773 switch (xd->bd) {
629 case 10: 774 case 10:
630 d = CONVERT_TO_BYTEPTR(VP9_HIGH_VAR_OFFS_10); 775 d = CONVERT_TO_BYTEPTR(VP9_HIGH_VAR_OFFS_10);
631 break; 776 break;
632 case 12: 777 case 12:
633 d = CONVERT_TO_BYTEPTR(VP9_HIGH_VAR_OFFS_12); 778 d = CONVERT_TO_BYTEPTR(VP9_HIGH_VAR_OFFS_12);
634 break; 779 break;
635 case 8: 780 case 8:
636 default: 781 default:
637 d = CONVERT_TO_BYTEPTR(VP9_HIGH_VAR_OFFS_8); 782 d = CONVERT_TO_BYTEPTR(VP9_HIGH_VAR_OFFS_8);
638 break; 783 break;
639 } 784 }
640 } 785 }
641 #endif // CONFIG_VP9_HIGHBITDEPTH 786 #endif // CONFIG_VP9_HIGHBITDEPTH
642 } 787 }
643 788
644 // Index for force_split: 0 for 64x64, 1-4 for 32x32 blocks, 789 // Index for force_split: 0 for 64x64, 1-4 for 32x32 blocks,
790 // 5-20 for the 16x16 blocks.
645 force_split[0] = 0; 791 force_split[0] = 0;
646 // Fill in the entire tree of 8x8 (or 4x4 under some conditions) variances 792 // Fill in the entire tree of 8x8 (or 4x4 under some conditions) variances
647 // for splits. 793 // for splits.
648 for (i = 0; i < 4; i++) { 794 for (i = 0; i < 4; i++) {
649 const int x32_idx = ((i & 1) << 5); 795 const int x32_idx = ((i & 1) << 5);
650 const int y32_idx = ((i >> 1) << 5); 796 const int y32_idx = ((i >> 1) << 5);
651 const int i2 = i << 2; 797 const int i2 = i << 2;
652 force_split[i + 1] = 0; 798 force_split[i + 1] = 0;
653 for (j = 0; j < 4; j++) { 799 for (j = 0; j < 4; j++) {
654 const int x16_idx = x32_idx + ((j & 1) << 4); 800 const int x16_idx = x32_idx + ((j & 1) << 4);
655 const int y16_idx = y32_idx + ((j >> 1) << 4); 801 const int y16_idx = y32_idx + ((j >> 1) << 4);
802 const int split_index = 5 + i2 + j;
656 v16x16 *vst = &vt.split[i].split[j]; 803 v16x16 *vst = &vt.split[i].split[j];
804 force_split[split_index] = 0;
657 variance4x4downsample[i2 + j] = 0; 805 variance4x4downsample[i2 + j] = 0;
658 if (!is_key_frame) { 806 if (!is_key_frame) {
659 for (k = 0; k < 4; k++) { 807 fill_variance_8x8avg(s, sp, d, dp, x16_idx, y16_idx, vst,
660 int x8_idx = x16_idx + ((k & 1) << 3);
661 int y8_idx = y16_idx + ((k >> 1) << 3);
662 unsigned int sse = 0;
663 int sum = 0;
664 if (x8_idx < pixels_wide && y8_idx < pixels_high) {
665 int s_avg, d_avg;
666 #if CONFIG_VP9_HIGHBITDEPTH 808 #if CONFIG_VP9_HIGHBITDEPTH
667 if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) { 809 xd->cur_buf->flags,
668 s_avg = vp9_highbd_avg_8x8(s + y8_idx * sp + x8_idx, sp);
669 d_avg = vp9_highbd_avg_8x8(d + y8_idx * dp + x8_idx, dp);
670 } else {
671 s_avg = vp9_avg_8x8(s + y8_idx * sp + x8_idx, sp);
672 d_avg = vp9_avg_8x8(d + y8_idx * dp + x8_idx, dp);
673 }
674 #else
675 s_avg = vp9_avg_8x8(s + y8_idx * sp + x8_idx, sp);
676 d_avg = vp9_avg_8x8(d + y8_idx * dp + x8_idx, dp);
677 #endif 810 #endif
678 sum = s_avg - d_avg; 811 pixels_wide,
679 sse = sum * sum; 812 pixels_high,
813 is_key_frame);
814 fill_variance_tree(&vt.split[i].split[j], BLOCK_16X16);
815 get_variance(&vt.split[i].split[j].part_variances.none);
816 if (vt.split[i].split[j].part_variances.none.variance >
817 thresholds[2]) {
818 // 16X16 variance is above threshold for split, so force split to 8x8
819 // for this 16x16 block (this also forces splits for upper levels).
820 force_split[split_index] = 1;
821 force_split[i + 1] = 1;
822 force_split[0] = 1;
823 } else if (vt.split[i].split[j].part_variances.none.variance >
824 thresholds[1] &&
825 !cyclic_refresh_segment_id_boosted(segment_id)) {
826 // We have some nominal amount of 16x16 variance (based on average),
827 // compute the minmax over the 8x8 sub-blocks, and if above threshold,
828 // force split to 8x8 block for this 16x16 block.
829 int minmax = compute_minmax_8x8(s, sp, d, dp, x16_idx, y16_idx,
830 #if CONFIG_VP9_HIGHBITDEPTH
831 xd->cur_buf->flags,
832 #endif
833 pixels_wide, pixels_high);
834 if (minmax > cpi->vbp_threshold_minmax) {
835 force_split[split_index] = 1;
836 force_split[i + 1] = 1;
837 force_split[0] = 1;
680 } 838 }
681 // If variance is based on 8x8 downsampling, we stop here and have
682 // one sample for 8x8 block (so use 1 for count in fill_variance),
683 // which of course means variance = 0 for 8x8 block.
684 fill_variance(sse, sum, 0, &vst->split[k].part_variances.none);
685 } 839 }
686 fill_variance_tree(&vt.split[i].split[j], BLOCK_16X16);
687 // For low-resolution, compute the variance based on 8x8 down-sampling,
688 // and if it is large (above the threshold) we go down for 4x4.
689 // For key frame we always go down to 4x4.
690 if (low_res)
691 get_variance(&vt.split[i].split[j].part_variances.none);
692 } 840 }
693 if (is_key_frame || (low_res && 841 if (is_key_frame || (low_res &&
694 vt.split[i].split[j].part_variances.none.variance > 842 vt.split[i].split[j].part_variances.none.variance >
695 (cpi->vbp_threshold << 1))) { 843 (thresholds[1] << 1))) {
844 force_split[split_index] = 0;
696 // Go down to 4x4 down-sampling for variance. 845 // Go down to 4x4 down-sampling for variance.
697 variance4x4downsample[i2 + j] = 1; 846 variance4x4downsample[i2 + j] = 1;
698 for (k = 0; k < 4; k++) { 847 for (k = 0; k < 4; k++) {
699 int x8_idx = x16_idx + ((k & 1) << 3); 848 int x8_idx = x16_idx + ((k & 1) << 3);
700 int y8_idx = y16_idx + ((k >> 1) << 3); 849 int y8_idx = y16_idx + ((k >> 1) << 3);
701 v8x8 *vst2 = is_key_frame ? &vst->split[k] : 850 v8x8 *vst2 = is_key_frame ? &vst->split[k] :
702 &vt2[i2 + j].split[k]; 851 &vt2[i2 + j].split[k];
703 for (m = 0; m < 4; m++) { 852 fill_variance_4x4avg(s, sp, d, dp, x8_idx, y8_idx, vst2,
704 int x4_idx = x8_idx + ((m & 1) << 2);
705 int y4_idx = y8_idx + ((m >> 1) << 2);
706 unsigned int sse = 0;
707 int sum = 0;
708 if (x4_idx < pixels_wide && y4_idx < pixels_high) {
709 int d_avg = 128;
710 #if CONFIG_VP9_HIGHBITDEPTH 853 #if CONFIG_VP9_HIGHBITDEPTH
711 int s_avg; 854 xd->cur_buf->flags,
712 if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
713 s_avg = vp9_highbd_avg_4x4(s + y4_idx * sp + x4_idx, sp);
714 if (cm->frame_type != KEY_FRAME)
715 d_avg = vp9_highbd_avg_4x4(d + y4_idx * dp + x4_idx, dp);
716 } else {
717 s_avg = vp9_avg_4x4(s + y4_idx * sp + x4_idx, sp);
718 if (cm->frame_type != KEY_FRAME)
719 d_avg = vp9_avg_4x4(d + y4_idx * dp + x4_idx, dp);
720 }
721 #else
722 int s_avg = vp9_avg_4x4(s + y4_idx * sp + x4_idx, sp);
723 if (!is_key_frame)
724 d_avg = vp9_avg_4x4(d + y4_idx * dp + x4_idx, dp);
725 #endif 855 #endif
726 sum = s_avg - d_avg; 856 pixels_wide,
727 sse = sum * sum; 857 pixels_high,
728 } 858 is_key_frame);
729 // If variance is based on 4x4 down-sampling, we stop here and have
730 // one sample for 4x4 block (so use 1 for count in fill_variance),
731 // which of course means variance = 0 for 4x4 block.
732 fill_variance(sse, sum, 0, &vst2->split[m].part_variances.none);
733 }
734 } 859 }
735 } 860 }
736 } 861 }
737 } 862 }
738 863
739 // No 64x64 blocks on segments other than base (un-boosted) segment,
740 // so force split.
741 if (cyclic_refresh_segment_id_boosted(segment_id))
742 force_split[0] = 1;
743
744 // Fill the rest of the variance tree by summing split partition values. 864 // Fill the rest of the variance tree by summing split partition values.
745 for (i = 0; i < 4; i++) { 865 for (i = 0; i < 4; i++) {
746 const int i2 = i << 2; 866 const int i2 = i << 2;
747 for (j = 0; j < 4; j++) { 867 for (j = 0; j < 4; j++) {
748 if (variance4x4downsample[i2 + j] == 1) { 868 if (variance4x4downsample[i2 + j] == 1) {
749 v16x16 *vtemp = (!is_key_frame) ? &vt2[i2 + j] : 869 v16x16 *vtemp = (!is_key_frame) ? &vt2[i2 + j] :
750 &vt.split[i].split[j]; 870 &vt.split[i].split[j];
751 for (m = 0; m < 4; m++) 871 for (m = 0; m < 4; m++)
752 fill_variance_tree(&vtemp->split[m], BLOCK_8X8); 872 fill_variance_tree(&vtemp->split[m], BLOCK_8X8);
753 fill_variance_tree(vtemp, BLOCK_16X16); 873 fill_variance_tree(vtemp, BLOCK_16X16);
754 } 874 }
755 } 875 }
756 fill_variance_tree(&vt.split[i], BLOCK_32X32); 876 fill_variance_tree(&vt.split[i], BLOCK_32X32);
757 // If variance of this 32x32 block is above the threshold, force the block 877 // If variance of this 32x32 block is above the threshold, force the block
758 // to split. This also forces a split on the upper (64x64) level. 878 // to split. This also forces a split on the upper (64x64) level.
759 get_variance(&vt.split[i].part_variances.none); 879 if (!force_split[i + 1]) {
760 if (vt.split[i].part_variances.none.variance > cpi->vbp_threshold) { 880 get_variance(&vt.split[i].part_variances.none);
761 force_split[i + 1] = 1; 881 if (vt.split[i].part_variances.none.variance > thresholds[1]) {
762 force_split[0] = 1; 882 force_split[i + 1] = 1;
883 force_split[0] = 1;
884 }
763 } 885 }
764 } 886 }
765 if (!force_split[0]) 887 if (!force_split[0]) {
766 fill_variance_tree(&vt, BLOCK_64X64); 888 fill_variance_tree(&vt, BLOCK_64X64);
889 get_variance(&vt.part_variances.none);
890 }
767 891
768 // Now go through the entire structure, splitting every block size until 892 // Now go through the entire structure, splitting every block size until
769 // we get to one that's got a variance lower than our threshold. 893 // we get to one that's got a variance lower than our threshold.
770 if ( mi_col + 8 > cm->mi_cols || mi_row + 8 > cm->mi_rows || 894 if ( mi_col + 8 > cm->mi_cols || mi_row + 8 > cm->mi_rows ||
771 !set_vt_partitioning(cpi, xd, &vt, BLOCK_64X64, mi_row, mi_col, 895 !set_vt_partitioning(cpi, xd, &vt, BLOCK_64X64, mi_row, mi_col,
772 cpi->vbp_threshold_bsize_max, BLOCK_16X16, 896 thresholds[0], BLOCK_16X16, force_split[0])) {
773 force_split[0])) {
774 for (i = 0; i < 4; ++i) { 897 for (i = 0; i < 4; ++i) {
775 const int x32_idx = ((i & 1) << 2); 898 const int x32_idx = ((i & 1) << 2);
776 const int y32_idx = ((i >> 1) << 2); 899 const int y32_idx = ((i >> 1) << 2);
777 const int i2 = i << 2; 900 const int i2 = i << 2;
778 if (!set_vt_partitioning(cpi, xd, &vt.split[i], BLOCK_32X32, 901 if (!set_vt_partitioning(cpi, xd, &vt.split[i], BLOCK_32X32,
779 (mi_row + y32_idx), (mi_col + x32_idx), 902 (mi_row + y32_idx), (mi_col + x32_idx),
780 cpi->vbp_threshold, 903 thresholds[1], BLOCK_16X16,
781 BLOCK_16X16, force_split[i + 1])) { 904 force_split[i + 1])) {
782 for (j = 0; j < 4; ++j) { 905 for (j = 0; j < 4; ++j) {
783 const int x16_idx = ((j & 1) << 1); 906 const int x16_idx = ((j & 1) << 1);
784 const int y16_idx = ((j >> 1) << 1); 907 const int y16_idx = ((j >> 1) << 1);
785 // For inter frames: if variance4x4downsample[] == 1 for this 16x16 908 // For inter frames: if variance4x4downsample[] == 1 for this 16x16
786 // block, then the variance is based on 4x4 down-sampling, so use vt2 909 // block, then the variance is based on 4x4 down-sampling, so use vt2
787 // in set_vt_partioning(), otherwise use vt. 910 // in set_vt_partioning(), otherwise use vt.
788 v16x16 *vtemp = (!is_key_frame && 911 v16x16 *vtemp = (!is_key_frame &&
789 variance4x4downsample[i2 + j] == 1) ? 912 variance4x4downsample[i2 + j] == 1) ?
790 &vt2[i2 + j] : &vt.split[i].split[j]; 913 &vt2[i2 + j] : &vt.split[i].split[j];
791 if (!set_vt_partitioning(cpi, xd, vtemp, BLOCK_16X16, 914 if (!set_vt_partitioning(cpi, xd, vtemp, BLOCK_16X16,
792 mi_row + y32_idx + y16_idx, 915 mi_row + y32_idx + y16_idx,
793 mi_col + x32_idx + x16_idx, 916 mi_col + x32_idx + x16_idx,
794 cpi->vbp_threshold_16x16, 917 thresholds[2],
795 cpi->vbp_bsize_min, 0)) { 918 cpi->vbp_bsize_min,
919 force_split[5 + i2 + j])) {
796 for (k = 0; k < 4; ++k) { 920 for (k = 0; k < 4; ++k) {
797 const int x8_idx = (k & 1); 921 const int x8_idx = (k & 1);
798 const int y8_idx = (k >> 1); 922 const int y8_idx = (k >> 1);
799 if (use_4x4_partition) { 923 if (use_4x4_partition) {
800 if (!set_vt_partitioning(cpi, xd, &vtemp->split[k], 924 if (!set_vt_partitioning(cpi, xd, &vtemp->split[k],
801 BLOCK_8X8, 925 BLOCK_8X8,
802 mi_row + y32_idx + y16_idx + y8_idx, 926 mi_row + y32_idx + y16_idx + y8_idx,
803 mi_col + x32_idx + x16_idx + x8_idx, 927 mi_col + x32_idx + x16_idx + x8_idx,
804 cpi->vbp_threshold_bsize_min, 928 thresholds[3], BLOCK_8X8, 0)) {
805 BLOCK_8X8, 0)) {
806 set_block_size(cpi, xd, 929 set_block_size(cpi, xd,
807 (mi_row + y32_idx + y16_idx + y8_idx), 930 (mi_row + y32_idx + y16_idx + y8_idx),
808 (mi_col + x32_idx + x16_idx + x8_idx), 931 (mi_col + x32_idx + x16_idx + x8_idx),
809 BLOCK_4X4); 932 BLOCK_4X4);
810 } 933 }
811 } else { 934 } else {
812 set_block_size(cpi, xd, 935 set_block_size(cpi, xd,
813 (mi_row + y32_idx + y16_idx + y8_idx), 936 (mi_row + y32_idx + y16_idx + y8_idx),
814 (mi_col + x32_idx + x16_idx + x8_idx), 937 (mi_col + x32_idx + x16_idx + x8_idx),
815 BLOCK_8X8); 938 BLOCK_8X8);
816 } 939 }
817 } 940 }
818 } 941 }
819 } 942 }
820 } 943 }
821 } 944 }
822 } 945 }
946 return 0;
823 } 947 }
824 948
825 static void update_state(VP9_COMP *cpi, ThreadData *td, 949 static void update_state(VP9_COMP *cpi, ThreadData *td,
826 PICK_MODE_CONTEXT *ctx, 950 PICK_MODE_CONTEXT *ctx,
827 int mi_row, int mi_col, BLOCK_SIZE bsize, 951 int mi_row, int mi_col, BLOCK_SIZE bsize,
828 int output_enabled) { 952 int output_enabled) {
829 int i, x_idx, y; 953 int i, x_idx, y;
830 VP9_COMMON *const cm = &cpi->common; 954 VP9_COMMON *const cm = &cpi->common;
831 RD_COUNTS *const rdc = &td->rd_counts; 955 RD_COUNTS *const rdc = &td->rd_counts;
832 MACROBLOCK *const x = &td->mb; 956 MACROBLOCK *const x = &td->mb;
833 MACROBLOCKD *const xd = &x->e_mbd; 957 MACROBLOCKD *const xd = &x->e_mbd;
834 struct macroblock_plane *const p = x->plane; 958 struct macroblock_plane *const p = x->plane;
835 struct macroblockd_plane *const pd = xd->plane; 959 struct macroblockd_plane *const pd = xd->plane;
836 MODE_INFO *mi = &ctx->mic; 960 MODE_INFO *mi = &ctx->mic;
837 MB_MODE_INFO *const mbmi = &xd->mi[0].src_mi->mbmi; 961 MB_MODE_INFO *const mbmi = &xd->mi[0]->mbmi;
838 MODE_INFO *mi_addr = &xd->mi[0]; 962 MODE_INFO *mi_addr = xd->mi[0];
839 const struct segmentation *const seg = &cm->seg; 963 const struct segmentation *const seg = &cm->seg;
840 const int bw = num_8x8_blocks_wide_lookup[mi->mbmi.sb_type]; 964 const int bw = num_8x8_blocks_wide_lookup[mi->mbmi.sb_type];
841 const int bh = num_8x8_blocks_high_lookup[mi->mbmi.sb_type]; 965 const int bh = num_8x8_blocks_high_lookup[mi->mbmi.sb_type];
842 const int x_mis = MIN(bw, cm->mi_cols - mi_col); 966 const int x_mis = MIN(bw, cm->mi_cols - mi_col);
843 const int y_mis = MIN(bh, cm->mi_rows - mi_row); 967 const int y_mis = MIN(bh, cm->mi_rows - mi_row);
844 MV_REF *const frame_mvs = 968 MV_REF *const frame_mvs =
845 cm->cur_frame->mvs + mi_row * cm->mi_cols + mi_col; 969 cm->cur_frame->mvs + mi_row * cm->mi_cols + mi_col;
846 int w, h; 970 int w, h;
847 971
848 const int mis = cm->mi_stride; 972 const int mis = cm->mi_stride;
849 const int mi_width = num_8x8_blocks_wide_lookup[bsize]; 973 const int mi_width = num_8x8_blocks_wide_lookup[bsize];
850 const int mi_height = num_8x8_blocks_high_lookup[bsize]; 974 const int mi_height = num_8x8_blocks_high_lookup[bsize];
851 int max_plane; 975 int max_plane;
852 976
853 assert(mi->mbmi.sb_type == bsize); 977 assert(mi->mbmi.sb_type == bsize);
854 978
855 *mi_addr = *mi; 979 *mi_addr = *mi;
856 mi_addr->src_mi = mi_addr;
857 980
858 // If segmentation in use 981 // If segmentation in use
859 if (seg->enabled) { 982 if (seg->enabled) {
860 // For in frame complexity AQ copy the segment id from the segment map. 983 // For in frame complexity AQ copy the segment id from the segment map.
861 if (cpi->oxcf.aq_mode == COMPLEXITY_AQ) { 984 if (cpi->oxcf.aq_mode == COMPLEXITY_AQ) {
862 const uint8_t *const map = seg->update_map ? cpi->segmentation_map 985 const uint8_t *const map = seg->update_map ? cpi->segmentation_map
863 : cm->last_frame_seg_map; 986 : cm->last_frame_seg_map;
864 mi_addr->mbmi.segment_id = 987 mi_addr->mbmi.segment_id =
865 vp9_get_segment_id(cm, map, bsize, mi_row, mi_col); 988 vp9_get_segment_id(cm, map, bsize, mi_row, mi_col);
866 } 989 }
867 // Else for cyclic refresh mode update the segment map, set the segment id 990 // Else for cyclic refresh mode update the segment map, set the segment id
868 // and then update the quantizer. 991 // and then update the quantizer.
869 if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ) { 992 if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ) {
870 vp9_cyclic_refresh_update_segment(cpi, &xd->mi[0].src_mi->mbmi, mi_row, 993 vp9_cyclic_refresh_update_segment(cpi, &xd->mi[0]->mbmi, mi_row,
871 mi_col, bsize, ctx->rate, ctx->dist, 994 mi_col, bsize, ctx->rate, ctx->dist,
872 x->skip); 995 x->skip);
873 } 996 }
874 } 997 }
875 998
876 max_plane = is_inter_block(mbmi) ? MAX_MB_PLANE : 1; 999 max_plane = is_inter_block(mbmi) ? MAX_MB_PLANE : 1;
877 for (i = 0; i < max_plane; ++i) { 1000 for (i = 0; i < max_plane; ++i) {
878 p[i].coeff = ctx->coeff_pbuf[i][1]; 1001 p[i].coeff = ctx->coeff_pbuf[i][1];
879 p[i].qcoeff = ctx->qcoeff_pbuf[i][1]; 1002 p[i].qcoeff = ctx->qcoeff_pbuf[i][1];
880 pd[i].dqcoeff = ctx->dqcoeff_pbuf[i][1]; 1003 pd[i].dqcoeff = ctx->dqcoeff_pbuf[i][1];
881 p[i].eobs = ctx->eobs_pbuf[i][1]; 1004 p[i].eobs = ctx->eobs_pbuf[i][1];
882 } 1005 }
883 1006
884 for (i = max_plane; i < MAX_MB_PLANE; ++i) { 1007 for (i = max_plane; i < MAX_MB_PLANE; ++i) {
885 p[i].coeff = ctx->coeff_pbuf[i][2]; 1008 p[i].coeff = ctx->coeff_pbuf[i][2];
886 p[i].qcoeff = ctx->qcoeff_pbuf[i][2]; 1009 p[i].qcoeff = ctx->qcoeff_pbuf[i][2];
887 pd[i].dqcoeff = ctx->dqcoeff_pbuf[i][2]; 1010 pd[i].dqcoeff = ctx->dqcoeff_pbuf[i][2];
888 p[i].eobs = ctx->eobs_pbuf[i][2]; 1011 p[i].eobs = ctx->eobs_pbuf[i][2];
889 } 1012 }
890 1013
891 // Restore the coding context of the MB to that that was in place 1014 // Restore the coding context of the MB to that that was in place
892 // when the mode was picked for it 1015 // when the mode was picked for it
893 for (y = 0; y < mi_height; y++) 1016 for (y = 0; y < mi_height; y++)
894 for (x_idx = 0; x_idx < mi_width; x_idx++) 1017 for (x_idx = 0; x_idx < mi_width; x_idx++)
895 if ((xd->mb_to_right_edge >> (3 + MI_SIZE_LOG2)) + mi_width > x_idx 1018 if ((xd->mb_to_right_edge >> (3 + MI_SIZE_LOG2)) + mi_width > x_idx
896 && (xd->mb_to_bottom_edge >> (3 + MI_SIZE_LOG2)) + mi_height > y) { 1019 && (xd->mb_to_bottom_edge >> (3 + MI_SIZE_LOG2)) + mi_height > y) {
897 xd->mi[x_idx + y * mis].src_mi = mi_addr; 1020 xd->mi[x_idx + y * mis] = mi_addr;
898 } 1021 }
899 1022
900 if (cpi->oxcf.aq_mode) 1023 if (cpi->oxcf.aq_mode)
901 vp9_init_plane_quantizers(cpi, x); 1024 vp9_init_plane_quantizers(cpi, x);
902 1025
903 // FIXME(rbultje) I'm pretty sure this should go to the end of this block 1026 // FIXME(rbultje) I'm pretty sure this should go to the end of this block
904 // (i.e. after the output_enabled) 1027 // (i.e. after the output_enabled)
905 if (bsize < BLOCK_32X32) { 1028 if (bsize < BLOCK_32X32) {
906 if (bsize < BLOCK_16X16) 1029 if (bsize < BLOCK_16X16)
907 ctx->tx_rd_diff[ALLOW_16X16] = ctx->tx_rd_diff[ALLOW_8X8]; 1030 ctx->tx_rd_diff[ALLOW_16X16] = ctx->tx_rd_diff[ALLOW_8X8];
908 ctx->tx_rd_diff[ALLOW_32X32] = ctx->tx_rd_diff[ALLOW_16X16]; 1031 ctx->tx_rd_diff[ALLOW_32X32] = ctx->tx_rd_diff[ALLOW_16X16];
909 } 1032 }
910 1033
911 if (is_inter_block(mbmi) && mbmi->sb_type < BLOCK_8X8) { 1034 if (is_inter_block(mbmi) && mbmi->sb_type < BLOCK_8X8) {
912 mbmi->mv[0].as_int = mi->bmi[3].as_mv[0].as_int; 1035 mbmi->mv[0].as_int = mi->bmi[3].as_mv[0].as_int;
913 mbmi->mv[1].as_int = mi->bmi[3].as_mv[1].as_int; 1036 mbmi->mv[1].as_int = mi->bmi[3].as_mv[1].as_int;
914 } 1037 }
915 1038
916 x->skip = ctx->skip; 1039 x->skip = ctx->skip;
917 vpx_memcpy(x->zcoeff_blk[mbmi->tx_size], ctx->zcoeff_blk, 1040 memcpy(x->zcoeff_blk[mbmi->tx_size], ctx->zcoeff_blk,
918 sizeof(uint8_t) * ctx->num_4x4_blk); 1041 sizeof(uint8_t) * ctx->num_4x4_blk);
919 1042
920 if (!output_enabled) 1043 if (!output_enabled)
921 return; 1044 return;
922 1045
923 if (!vp9_segfeature_active(&cm->seg, mbmi->segment_id, SEG_LVL_SKIP)) { 1046 if (!vp9_segfeature_active(&cm->seg, mbmi->segment_id, SEG_LVL_SKIP)) {
924 for (i = 0; i < TX_MODES; i++) 1047 for (i = 0; i < TX_MODES; i++)
925 rdc->tx_select_diff[i] += ctx->tx_rd_diff[i]; 1048 rdc->tx_select_diff[i] += ctx->tx_rd_diff[i];
926 } 1049 }
927 1050
928 #if CONFIG_INTERNAL_STATS 1051 #if CONFIG_INTERNAL_STATS
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
960 rdc->comp_pred_diff[REFERENCE_MODE_SELECT] += ctx->hybrid_pred_diff; 1083 rdc->comp_pred_diff[REFERENCE_MODE_SELECT] += ctx->hybrid_pred_diff;
961 1084
962 for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; ++i) 1085 for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; ++i)
963 rdc->filter_diff[i] += ctx->best_filter_diff[i]; 1086 rdc->filter_diff[i] += ctx->best_filter_diff[i];
964 } 1087 }
965 1088
966 for (h = 0; h < y_mis; ++h) { 1089 for (h = 0; h < y_mis; ++h) {
967 MV_REF *const frame_mv = frame_mvs + h * cm->mi_cols; 1090 MV_REF *const frame_mv = frame_mvs + h * cm->mi_cols;
968 for (w = 0; w < x_mis; ++w) { 1091 for (w = 0; w < x_mis; ++w) {
969 MV_REF *const mv = frame_mv + w; 1092 MV_REF *const mv = frame_mv + w;
970 mv->ref_frame[0] = mi->src_mi->mbmi.ref_frame[0]; 1093 mv->ref_frame[0] = mi->mbmi.ref_frame[0];
971 mv->ref_frame[1] = mi->src_mi->mbmi.ref_frame[1]; 1094 mv->ref_frame[1] = mi->mbmi.ref_frame[1];
972 mv->mv[0].as_int = mi->src_mi->mbmi.mv[0].as_int; 1095 mv->mv[0].as_int = mi->mbmi.mv[0].as_int;
973 mv->mv[1].as_int = mi->src_mi->mbmi.mv[1].as_int; 1096 mv->mv[1].as_int = mi->mbmi.mv[1].as_int;
974 } 1097 }
975 } 1098 }
976 } 1099 }
977 1100
978 void vp9_setup_src_planes(MACROBLOCK *x, const YV12_BUFFER_CONFIG *src, 1101 void vp9_setup_src_planes(MACROBLOCK *x, const YV12_BUFFER_CONFIG *src,
979 int mi_row, int mi_col) { 1102 int mi_row, int mi_col) {
980 uint8_t *const buffers[3] = {src->y_buffer, src->u_buffer, src->v_buffer }; 1103 uint8_t *const buffers[3] = {src->y_buffer, src->u_buffer, src->v_buffer };
981 const int strides[3] = {src->y_stride, src->uv_stride, src->uv_stride }; 1104 const int strides[3] = {src->y_stride, src->uv_stride, src->uv_stride };
982 int i; 1105 int i;
983 1106
984 // Set current frame pointer. 1107 // Set current frame pointer.
985 x->e_mbd.cur_buf = src; 1108 x->e_mbd.cur_buf = src;
986 1109
987 for (i = 0; i < MAX_MB_PLANE; i++) 1110 for (i = 0; i < MAX_MB_PLANE; i++)
988 setup_pred_plane(&x->plane[i].src, buffers[i], strides[i], mi_row, mi_col, 1111 setup_pred_plane(&x->plane[i].src, buffers[i], strides[i], mi_row, mi_col,
989 NULL, x->e_mbd.plane[i].subsampling_x, 1112 NULL, x->e_mbd.plane[i].subsampling_x,
990 x->e_mbd.plane[i].subsampling_y); 1113 x->e_mbd.plane[i].subsampling_y);
991 } 1114 }
992 1115
993 static void set_mode_info_seg_skip(MACROBLOCK *x, TX_MODE tx_mode, 1116 static void set_mode_info_seg_skip(MACROBLOCK *x, TX_MODE tx_mode,
994 RD_COST *rd_cost, BLOCK_SIZE bsize) { 1117 RD_COST *rd_cost, BLOCK_SIZE bsize) {
995 MACROBLOCKD *const xd = &x->e_mbd; 1118 MACROBLOCKD *const xd = &x->e_mbd;
996 MB_MODE_INFO *const mbmi = &xd->mi[0].src_mi->mbmi; 1119 MB_MODE_INFO *const mbmi = &xd->mi[0]->mbmi;
997 INTERP_FILTER filter_ref; 1120 INTERP_FILTER filter_ref;
998 1121
999 if (xd->up_available) 1122 if (xd->up_available)
1000 filter_ref = xd->mi[-xd->mi_stride].src_mi->mbmi.interp_filter; 1123 filter_ref = xd->mi[-xd->mi_stride]->mbmi.interp_filter;
1001 else if (xd->left_available) 1124 else if (xd->left_available)
1002 filter_ref = xd->mi[-1].src_mi->mbmi.interp_filter; 1125 filter_ref = xd->mi[-1]->mbmi.interp_filter;
1003 else 1126 else
1004 filter_ref = EIGHTTAP; 1127 filter_ref = EIGHTTAP;
1005 1128
1006 mbmi->sb_type = bsize; 1129 mbmi->sb_type = bsize;
1007 mbmi->mode = ZEROMV; 1130 mbmi->mode = ZEROMV;
1008 mbmi->tx_size = MIN(max_txsize_lookup[bsize], 1131 mbmi->tx_size = MIN(max_txsize_lookup[bsize],
1009 tx_mode_to_biggest_tx_size[tx_mode]); 1132 tx_mode_to_biggest_tx_size[tx_mode]);
1010 mbmi->skip = 1; 1133 mbmi->skip = 1;
1011 mbmi->uv_mode = DC_PRED; 1134 mbmi->uv_mode = DC_PRED;
1012 mbmi->ref_frame[0] = LAST_FRAME; 1135 mbmi->ref_frame[0] = LAST_FRAME;
1013 mbmi->ref_frame[1] = NONE; 1136 mbmi->ref_frame[1] = NONE;
1014 mbmi->mv[0].as_int = 0; 1137 mbmi->mv[0].as_int = 0;
1015 mbmi->interp_filter = filter_ref; 1138 mbmi->interp_filter = filter_ref;
1016 1139
1017 xd->mi[0].src_mi->bmi[0].as_mv[0].as_int = 0; 1140 xd->mi[0]->bmi[0].as_mv[0].as_int = 0;
1018 x->skip = 1; 1141 x->skip = 1;
1019 1142
1020 vp9_rd_cost_init(rd_cost); 1143 vp9_rd_cost_init(rd_cost);
1021 } 1144 }
1022 1145
1023 static int set_segment_rdmult(VP9_COMP *const cpi, 1146 static int set_segment_rdmult(VP9_COMP *const cpi,
1024 MACROBLOCK *const x, 1147 MACROBLOCK *const x,
1025 int8_t segment_id) { 1148 int8_t segment_id) {
1026 int segment_qindex; 1149 int segment_qindex;
1027 VP9_COMMON *const cm = &cpi->common; 1150 VP9_COMMON *const cm = &cpi->common;
(...skipping 18 matching lines...) Expand all
1046 struct macroblockd_plane *const pd = xd->plane; 1169 struct macroblockd_plane *const pd = xd->plane;
1047 const AQ_MODE aq_mode = cpi->oxcf.aq_mode; 1170 const AQ_MODE aq_mode = cpi->oxcf.aq_mode;
1048 int i, orig_rdmult; 1171 int i, orig_rdmult;
1049 1172
1050 vp9_clear_system_state(); 1173 vp9_clear_system_state();
1051 1174
1052 // Use the lower precision, but faster, 32x32 fdct for mode selection. 1175 // Use the lower precision, but faster, 32x32 fdct for mode selection.
1053 x->use_lp32x32fdct = 1; 1176 x->use_lp32x32fdct = 1;
1054 1177
1055 set_offsets(cpi, tile_info, x, mi_row, mi_col, bsize); 1178 set_offsets(cpi, tile_info, x, mi_row, mi_col, bsize);
1056 mbmi = &xd->mi[0].src_mi->mbmi; 1179 mbmi = &xd->mi[0]->mbmi;
1057 mbmi->sb_type = bsize; 1180 mbmi->sb_type = bsize;
1058 1181
1059 for (i = 0; i < MAX_MB_PLANE; ++i) { 1182 for (i = 0; i < MAX_MB_PLANE; ++i) {
1060 p[i].coeff = ctx->coeff_pbuf[i][0]; 1183 p[i].coeff = ctx->coeff_pbuf[i][0];
1061 p[i].qcoeff = ctx->qcoeff_pbuf[i][0]; 1184 p[i].qcoeff = ctx->qcoeff_pbuf[i][0];
1062 pd[i].dqcoeff = ctx->dqcoeff_pbuf[i][0]; 1185 pd[i].dqcoeff = ctx->dqcoeff_pbuf[i][0];
1063 p[i].eobs = ctx->eobs_pbuf[i][0]; 1186 p[i].eobs = ctx->eobs_pbuf[i][0];
1064 } 1187 }
1065 ctx->is_coded = 0; 1188 ctx->is_coded = 0;
1066 ctx->skippable = 0; 1189 ctx->skippable = 0;
1067 ctx->pred_pixel_ready = 0; 1190 ctx->pred_pixel_ready = 0;
1068 x->skip_recode = 0; 1191 x->skip_recode = 0;
1069 1192
1070 // Set to zero to make sure we do not use the previous encoded frame stats 1193 // Set to zero to make sure we do not use the previous encoded frame stats
1071 mbmi->skip = 0; 1194 mbmi->skip = 0;
1072 1195
1073 #if CONFIG_VP9_HIGHBITDEPTH 1196 #if CONFIG_VP9_HIGHBITDEPTH
1074 if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) { 1197 if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
1075 x->source_variance = 1198 x->source_variance =
1076 high_get_sby_perpixel_variance(cpi, &x->plane[0].src, bsize, xd->bd); 1199 vp9_high_get_sby_perpixel_variance(cpi, &x->plane[0].src,
1200 bsize, xd->bd);
1077 } else { 1201 } else {
1078 x->source_variance = 1202 x->source_variance =
1079 get_sby_perpixel_variance(cpi, &x->plane[0].src, bsize); 1203 vp9_get_sby_perpixel_variance(cpi, &x->plane[0].src, bsize);
1080 } 1204 }
1081 #else 1205 #else
1082 x->source_variance = get_sby_perpixel_variance(cpi, &x->plane[0].src, bsize); 1206 x->source_variance =
1207 vp9_get_sby_perpixel_variance(cpi, &x->plane[0].src, bsize);
1083 #endif // CONFIG_VP9_HIGHBITDEPTH 1208 #endif // CONFIG_VP9_HIGHBITDEPTH
1084 1209
1085 // Save rdmult before it might be changed, so it can be restored later. 1210 // Save rdmult before it might be changed, so it can be restored later.
1086 orig_rdmult = x->rdmult; 1211 orig_rdmult = x->rdmult;
1087 1212
1088 if (aq_mode == VARIANCE_AQ) { 1213 if (aq_mode == VARIANCE_AQ) {
1089 const int energy = bsize <= BLOCK_16X16 ? x->mb_energy 1214 const int energy = bsize <= BLOCK_16X16 ? x->mb_energy
1090 : vp9_block_energy(cpi, x, bsize); 1215 : vp9_block_energy(cpi, x, bsize);
1091 if (cm->frame_type == KEY_FRAME || 1216 if (cm->frame_type == KEY_FRAME ||
1092 cpi->refresh_alt_ref_frame || 1217 cpi->refresh_alt_ref_frame ||
1093 (cpi->refresh_golden_frame && !cpi->rc.is_src_frame_alt_ref)) { 1218 (cpi->refresh_golden_frame && !cpi->rc.is_src_frame_alt_ref)) {
1094 mbmi->segment_id = vp9_vaq_segment_id(energy); 1219 mbmi->segment_id = vp9_vaq_segment_id(energy);
1095 } else { 1220 } else {
1096 const uint8_t *const map = cm->seg.update_map ? cpi->segmentation_map 1221 const uint8_t *const map = cm->seg.update_map ? cpi->segmentation_map
1097 : cm->last_frame_seg_map; 1222 : cm->last_frame_seg_map;
1098 mbmi->segment_id = vp9_get_segment_id(cm, map, bsize, mi_row, mi_col); 1223 mbmi->segment_id = vp9_get_segment_id(cm, map, bsize, mi_row, mi_col);
1099 } 1224 }
1100 x->rdmult = set_segment_rdmult(cpi, x, mbmi->segment_id); 1225 x->rdmult = set_segment_rdmult(cpi, x, mbmi->segment_id);
1101 } else if (aq_mode == COMPLEXITY_AQ) { 1226 } else if (aq_mode == COMPLEXITY_AQ) {
1102 x->rdmult = set_segment_rdmult(cpi, x, mbmi->segment_id); 1227 x->rdmult = set_segment_rdmult(cpi, x, mbmi->segment_id);
1103 } else if (aq_mode == CYCLIC_REFRESH_AQ) { 1228 } else if (aq_mode == CYCLIC_REFRESH_AQ) {
1104 const uint8_t *const map = cm->seg.update_map ? cpi->segmentation_map 1229 const uint8_t *const map = cm->seg.update_map ? cpi->segmentation_map
1105 : cm->last_frame_seg_map; 1230 : cm->last_frame_seg_map;
1106 // If segment 1, use rdmult for that segment. 1231 // If segment is boosted, use rdmult for that segment.
1107 if (vp9_get_segment_id(cm, map, bsize, mi_row, mi_col)) 1232 if (cyclic_refresh_segment_id_boosted(
1233 vp9_get_segment_id(cm, map, bsize, mi_row, mi_col)))
1108 x->rdmult = vp9_cyclic_refresh_get_rdmult(cpi->cyclic_refresh); 1234 x->rdmult = vp9_cyclic_refresh_get_rdmult(cpi->cyclic_refresh);
1109 } 1235 }
1110 1236
1111 // Find best coding mode & reconstruct the MB so it is available 1237 // Find best coding mode & reconstruct the MB so it is available
1112 // as a predictor for MBs that follow in the SB 1238 // as a predictor for MBs that follow in the SB
1113 if (frame_is_intra_only(cm)) { 1239 if (frame_is_intra_only(cm)) {
1114 vp9_rd_pick_intra_mode_sb(cpi, x, rd_cost, bsize, ctx, best_rd); 1240 vp9_rd_pick_intra_mode_sb(cpi, x, rd_cost, bsize, ctx, best_rd);
1115 } else { 1241 } else {
1116 if (bsize >= BLOCK_8X8) { 1242 if (bsize >= BLOCK_8X8) {
1117 if (vp9_segfeature_active(&cm->seg, mbmi->segment_id, SEG_LVL_SKIP)) 1243 if (vp9_segfeature_active(&cm->seg, mbmi->segment_id, SEG_LVL_SKIP))
(...skipping 25 matching lines...) Expand all
1143 if (rd_cost->rate == INT_MAX) 1269 if (rd_cost->rate == INT_MAX)
1144 rd_cost->rdcost = INT64_MAX; 1270 rd_cost->rdcost = INT64_MAX;
1145 1271
1146 ctx->rate = rd_cost->rate; 1272 ctx->rate = rd_cost->rate;
1147 ctx->dist = rd_cost->dist; 1273 ctx->dist = rd_cost->dist;
1148 } 1274 }
1149 1275
1150 static void update_stats(VP9_COMMON *cm, ThreadData *td) { 1276 static void update_stats(VP9_COMMON *cm, ThreadData *td) {
1151 const MACROBLOCK *x = &td->mb; 1277 const MACROBLOCK *x = &td->mb;
1152 const MACROBLOCKD *const xd = &x->e_mbd; 1278 const MACROBLOCKD *const xd = &x->e_mbd;
1153 const MODE_INFO *const mi = xd->mi[0].src_mi; 1279 const MODE_INFO *const mi = xd->mi[0];
1154 const MB_MODE_INFO *const mbmi = &mi->mbmi; 1280 const MB_MODE_INFO *const mbmi = &mi->mbmi;
1155 const BLOCK_SIZE bsize = mbmi->sb_type; 1281 const BLOCK_SIZE bsize = mbmi->sb_type;
1156 1282
1157 if (!frame_is_intra_only(cm)) { 1283 if (!frame_is_intra_only(cm)) {
1158 FRAME_COUNTS *const counts = td->counts; 1284 FRAME_COUNTS *const counts = td->counts;
1159 const int inter_block = is_inter_block(mbmi); 1285 const int inter_block = is_inter_block(mbmi);
1160 const int seg_ref_active = vp9_segfeature_active(&cm->seg, mbmi->segment_id, 1286 const int seg_ref_active = vp9_segfeature_active(&cm->seg, mbmi->segment_id,
1161 SEG_LVL_REF_FRAME); 1287 SEG_LVL_REF_FRAME);
1162 if (!seg_ref_active) { 1288 if (!seg_ref_active) {
1163 counts->intra_inter[vp9_get_intra_inter_context(xd)][inter_block]++; 1289 counts->intra_inter[vp9_get_intra_inter_context(xd)][inter_block]++;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1209 ENTROPY_CONTEXT l[16 * MAX_MB_PLANE], 1335 ENTROPY_CONTEXT l[16 * MAX_MB_PLANE],
1210 PARTITION_CONTEXT sa[8], PARTITION_CONTEXT sl[8], 1336 PARTITION_CONTEXT sa[8], PARTITION_CONTEXT sl[8],
1211 BLOCK_SIZE bsize) { 1337 BLOCK_SIZE bsize) {
1212 MACROBLOCKD *const xd = &x->e_mbd; 1338 MACROBLOCKD *const xd = &x->e_mbd;
1213 int p; 1339 int p;
1214 const int num_4x4_blocks_wide = num_4x4_blocks_wide_lookup[bsize]; 1340 const int num_4x4_blocks_wide = num_4x4_blocks_wide_lookup[bsize];
1215 const int num_4x4_blocks_high = num_4x4_blocks_high_lookup[bsize]; 1341 const int num_4x4_blocks_high = num_4x4_blocks_high_lookup[bsize];
1216 int mi_width = num_8x8_blocks_wide_lookup[bsize]; 1342 int mi_width = num_8x8_blocks_wide_lookup[bsize];
1217 int mi_height = num_8x8_blocks_high_lookup[bsize]; 1343 int mi_height = num_8x8_blocks_high_lookup[bsize];
1218 for (p = 0; p < MAX_MB_PLANE; p++) { 1344 for (p = 0; p < MAX_MB_PLANE; p++) {
1219 vpx_memcpy( 1345 memcpy(
1220 xd->above_context[p] + ((mi_col * 2) >> xd->plane[p].subsampling_x), 1346 xd->above_context[p] + ((mi_col * 2) >> xd->plane[p].subsampling_x),
1221 a + num_4x4_blocks_wide * p, 1347 a + num_4x4_blocks_wide * p,
1222 (sizeof(ENTROPY_CONTEXT) * num_4x4_blocks_wide) >> 1348 (sizeof(ENTROPY_CONTEXT) * num_4x4_blocks_wide) >>
1223 xd->plane[p].subsampling_x); 1349 xd->plane[p].subsampling_x);
1224 vpx_memcpy( 1350 memcpy(
1225 xd->left_context[p] 1351 xd->left_context[p]
1226 + ((mi_row & MI_MASK) * 2 >> xd->plane[p].subsampling_y), 1352 + ((mi_row & MI_MASK) * 2 >> xd->plane[p].subsampling_y),
1227 l + num_4x4_blocks_high * p, 1353 l + num_4x4_blocks_high * p,
1228 (sizeof(ENTROPY_CONTEXT) * num_4x4_blocks_high) >> 1354 (sizeof(ENTROPY_CONTEXT) * num_4x4_blocks_high) >>
1229 xd->plane[p].subsampling_y); 1355 xd->plane[p].subsampling_y);
1230 } 1356 }
1231 vpx_memcpy(xd->above_seg_context + mi_col, sa, 1357 memcpy(xd->above_seg_context + mi_col, sa,
1232 sizeof(*xd->above_seg_context) * mi_width); 1358 sizeof(*xd->above_seg_context) * mi_width);
1233 vpx_memcpy(xd->left_seg_context + (mi_row & MI_MASK), sl, 1359 memcpy(xd->left_seg_context + (mi_row & MI_MASK), sl,
1234 sizeof(xd->left_seg_context[0]) * mi_height); 1360 sizeof(xd->left_seg_context[0]) * mi_height);
1235 } 1361 }
1236 1362
1237 static void save_context(MACROBLOCK *const x, int mi_row, int mi_col, 1363 static void save_context(MACROBLOCK *const x, int mi_row, int mi_col,
1238 ENTROPY_CONTEXT a[16 * MAX_MB_PLANE], 1364 ENTROPY_CONTEXT a[16 * MAX_MB_PLANE],
1239 ENTROPY_CONTEXT l[16 * MAX_MB_PLANE], 1365 ENTROPY_CONTEXT l[16 * MAX_MB_PLANE],
1240 PARTITION_CONTEXT sa[8], PARTITION_CONTEXT sl[8], 1366 PARTITION_CONTEXT sa[8], PARTITION_CONTEXT sl[8],
1241 BLOCK_SIZE bsize) { 1367 BLOCK_SIZE bsize) {
1242 const MACROBLOCKD *const xd = &x->e_mbd; 1368 const MACROBLOCKD *const xd = &x->e_mbd;
1243 int p; 1369 int p;
1244 const int num_4x4_blocks_wide = num_4x4_blocks_wide_lookup[bsize]; 1370 const int num_4x4_blocks_wide = num_4x4_blocks_wide_lookup[bsize];
1245 const int num_4x4_blocks_high = num_4x4_blocks_high_lookup[bsize]; 1371 const int num_4x4_blocks_high = num_4x4_blocks_high_lookup[bsize];
1246 int mi_width = num_8x8_blocks_wide_lookup[bsize]; 1372 int mi_width = num_8x8_blocks_wide_lookup[bsize];
1247 int mi_height = num_8x8_blocks_high_lookup[bsize]; 1373 int mi_height = num_8x8_blocks_high_lookup[bsize];
1248 1374
1249 // buffer the above/left context information of the block in search. 1375 // buffer the above/left context information of the block in search.
1250 for (p = 0; p < MAX_MB_PLANE; ++p) { 1376 for (p = 0; p < MAX_MB_PLANE; ++p) {
1251 vpx_memcpy( 1377 memcpy(
1252 a + num_4x4_blocks_wide * p, 1378 a + num_4x4_blocks_wide * p,
1253 xd->above_context[p] + (mi_col * 2 >> xd->plane[p].subsampling_x), 1379 xd->above_context[p] + (mi_col * 2 >> xd->plane[p].subsampling_x),
1254 (sizeof(ENTROPY_CONTEXT) * num_4x4_blocks_wide) >> 1380 (sizeof(ENTROPY_CONTEXT) * num_4x4_blocks_wide) >>
1255 xd->plane[p].subsampling_x); 1381 xd->plane[p].subsampling_x);
1256 vpx_memcpy( 1382 memcpy(
1257 l + num_4x4_blocks_high * p, 1383 l + num_4x4_blocks_high * p,
1258 xd->left_context[p] 1384 xd->left_context[p]
1259 + ((mi_row & MI_MASK) * 2 >> xd->plane[p].subsampling_y), 1385 + ((mi_row & MI_MASK) * 2 >> xd->plane[p].subsampling_y),
1260 (sizeof(ENTROPY_CONTEXT) * num_4x4_blocks_high) >> 1386 (sizeof(ENTROPY_CONTEXT) * num_4x4_blocks_high) >>
1261 xd->plane[p].subsampling_y); 1387 xd->plane[p].subsampling_y);
1262 } 1388 }
1263 vpx_memcpy(sa, xd->above_seg_context + mi_col, 1389 memcpy(sa, xd->above_seg_context + mi_col,
1264 sizeof(*xd->above_seg_context) * mi_width); 1390 sizeof(*xd->above_seg_context) * mi_width);
1265 vpx_memcpy(sl, xd->left_seg_context + (mi_row & MI_MASK), 1391 memcpy(sl, xd->left_seg_context + (mi_row & MI_MASK),
1266 sizeof(xd->left_seg_context[0]) * mi_height); 1392 sizeof(xd->left_seg_context[0]) * mi_height);
1267 } 1393 }
1268 1394
1269 static void encode_b(VP9_COMP *cpi, const TileInfo *const tile, 1395 static void encode_b(VP9_COMP *cpi, const TileInfo *const tile,
1270 ThreadData *td, 1396 ThreadData *td,
1271 TOKENEXTRA **tp, int mi_row, int mi_col, 1397 TOKENEXTRA **tp, int mi_row, int mi_col,
1272 int output_enabled, BLOCK_SIZE bsize, 1398 int output_enabled, BLOCK_SIZE bsize,
1273 PICK_MODE_CONTEXT *ctx) { 1399 PICK_MODE_CONTEXT *ctx) {
1274 MACROBLOCK *const x = &td->mb; 1400 MACROBLOCK *const x = &td->mb;
1275 set_offsets(cpi, tile, x, mi_row, mi_col, bsize); 1401 set_offsets(cpi, tile, x, mi_row, mi_col, bsize);
1276 update_state(cpi, td, ctx, mi_row, mi_col, bsize, output_enabled); 1402 update_state(cpi, td, ctx, mi_row, mi_col, bsize, output_enabled);
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
1373 if ((*bh <= rows_left) && (*bw <= cols_left)) { 1499 if ((*bh <= rows_left) && (*bw <= cols_left)) {
1374 break; 1500 break;
1375 } 1501 }
1376 } 1502 }
1377 } 1503 }
1378 return bsize; 1504 return bsize;
1379 } 1505 }
1380 1506
1381 static void set_partial_b64x64_partition(MODE_INFO *mi, int mis, 1507 static void set_partial_b64x64_partition(MODE_INFO *mi, int mis,
1382 int bh_in, int bw_in, int row8x8_remaining, int col8x8_remaining, 1508 int bh_in, int bw_in, int row8x8_remaining, int col8x8_remaining,
1383 BLOCK_SIZE bsize, MODE_INFO *mi_8x8) { 1509 BLOCK_SIZE bsize, MODE_INFO **mi_8x8) {
1384 int bh = bh_in; 1510 int bh = bh_in;
1385 int r, c; 1511 int r, c;
1386 for (r = 0; r < MI_BLOCK_SIZE; r += bh) { 1512 for (r = 0; r < MI_BLOCK_SIZE; r += bh) {
1387 int bw = bw_in; 1513 int bw = bw_in;
1388 for (c = 0; c < MI_BLOCK_SIZE; c += bw) { 1514 for (c = 0; c < MI_BLOCK_SIZE; c += bw) {
1389 const int index = r * mis + c; 1515 const int index = r * mis + c;
1390 mi_8x8[index].src_mi = mi + index; 1516 mi_8x8[index] = mi + index;
1391 mi_8x8[index].src_mi->mbmi.sb_type = find_partition_size(bsize, 1517 mi_8x8[index]->mbmi.sb_type = find_partition_size(bsize,
1392 row8x8_remaining - r, col8x8_remaining - c, &bh, &bw); 1518 row8x8_remaining - r, col8x8_remaining - c, &bh, &bw);
1393 } 1519 }
1394 } 1520 }
1395 } 1521 }
1396 1522
1397 // This function attempts to set all mode info entries in a given SB64 1523 // This function attempts to set all mode info entries in a given SB64
1398 // to the same block partition size. 1524 // to the same block partition size.
1399 // However, at the bottom and right borders of the image the requested size 1525 // However, at the bottom and right borders of the image the requested size
1400 // may not be allowed in which case this code attempts to choose the largest 1526 // may not be allowed in which case this code attempts to choose the largest
1401 // allowable partition. 1527 // allowable partition.
1402 static void set_fixed_partitioning(VP9_COMP *cpi, const TileInfo *const tile, 1528 static void set_fixed_partitioning(VP9_COMP *cpi, const TileInfo *const tile,
1403 MODE_INFO *mi_8x8, int mi_row, int mi_col, 1529 MODE_INFO **mi_8x8, int mi_row, int mi_col,
1404 BLOCK_SIZE bsize) { 1530 BLOCK_SIZE bsize) {
1405 VP9_COMMON *const cm = &cpi->common; 1531 VP9_COMMON *const cm = &cpi->common;
1406 const int mis = cm->mi_stride; 1532 const int mis = cm->mi_stride;
1407 const int row8x8_remaining = tile->mi_row_end - mi_row; 1533 const int row8x8_remaining = tile->mi_row_end - mi_row;
1408 const int col8x8_remaining = tile->mi_col_end - mi_col; 1534 const int col8x8_remaining = tile->mi_col_end - mi_col;
1409 int block_row, block_col; 1535 int block_row, block_col;
1410 MODE_INFO *mi_upper_left = cm->mi + mi_row * mis + mi_col; 1536 MODE_INFO *mi_upper_left = cm->mi + mi_row * mis + mi_col;
1411 int bh = num_8x8_blocks_high_lookup[bsize]; 1537 int bh = num_8x8_blocks_high_lookup[bsize];
1412 int bw = num_8x8_blocks_wide_lookup[bsize]; 1538 int bw = num_8x8_blocks_wide_lookup[bsize];
1413 1539
1414 assert((row8x8_remaining > 0) && (col8x8_remaining > 0)); 1540 assert((row8x8_remaining > 0) && (col8x8_remaining > 0));
1415 1541
1416 // Apply the requested partition size to the SB64 if it is all "in image" 1542 // Apply the requested partition size to the SB64 if it is all "in image"
1417 if ((col8x8_remaining >= MI_BLOCK_SIZE) && 1543 if ((col8x8_remaining >= MI_BLOCK_SIZE) &&
1418 (row8x8_remaining >= MI_BLOCK_SIZE)) { 1544 (row8x8_remaining >= MI_BLOCK_SIZE)) {
1419 for (block_row = 0; block_row < MI_BLOCK_SIZE; block_row += bh) { 1545 for (block_row = 0; block_row < MI_BLOCK_SIZE; block_row += bh) {
1420 for (block_col = 0; block_col < MI_BLOCK_SIZE; block_col += bw) { 1546 for (block_col = 0; block_col < MI_BLOCK_SIZE; block_col += bw) {
1421 int index = block_row * mis + block_col; 1547 int index = block_row * mis + block_col;
1422 mi_8x8[index].src_mi = mi_upper_left + index; 1548 mi_8x8[index] = mi_upper_left + index;
1423 mi_8x8[index].src_mi->mbmi.sb_type = bsize; 1549 mi_8x8[index]->mbmi.sb_type = bsize;
1424 } 1550 }
1425 } 1551 }
1426 } else { 1552 } else {
1427 // Else this is a partial SB64. 1553 // Else this is a partial SB64.
1428 set_partial_b64x64_partition(mi_upper_left, mis, bh, bw, row8x8_remaining, 1554 set_partial_b64x64_partition(mi_upper_left, mis, bh, bw, row8x8_remaining,
1429 col8x8_remaining, bsize, mi_8x8); 1555 col8x8_remaining, bsize, mi_8x8);
1430 } 1556 }
1431 } 1557 }
1432 1558
1433 const struct { 1559 const struct {
1434 int row; 1560 int row;
1435 int col; 1561 int col;
1436 } coord_lookup[16] = { 1562 } coord_lookup[16] = {
1437 // 32x32 index = 0 1563 // 32x32 index = 0
1438 {0, 0}, {0, 2}, {2, 0}, {2, 2}, 1564 {0, 0}, {0, 2}, {2, 0}, {2, 2},
1439 // 32x32 index = 1 1565 // 32x32 index = 1
1440 {0, 4}, {0, 6}, {2, 4}, {2, 6}, 1566 {0, 4}, {0, 6}, {2, 4}, {2, 6},
1441 // 32x32 index = 2 1567 // 32x32 index = 2
1442 {4, 0}, {4, 2}, {6, 0}, {6, 2}, 1568 {4, 0}, {4, 2}, {6, 0}, {6, 2},
1443 // 32x32 index = 3 1569 // 32x32 index = 3
1444 {4, 4}, {4, 6}, {6, 4}, {6, 6}, 1570 {4, 4}, {4, 6}, {6, 4}, {6, 6},
1445 }; 1571 };
1446 1572
1447 static void set_source_var_based_partition(VP9_COMP *cpi, 1573 static void set_source_var_based_partition(VP9_COMP *cpi,
1448 const TileInfo *const tile, 1574 const TileInfo *const tile,
1449 MACROBLOCK *const x, 1575 MACROBLOCK *const x,
1450 MODE_INFO *mi_8x8, 1576 MODE_INFO **mi_8x8,
1451 int mi_row, int mi_col) { 1577 int mi_row, int mi_col) {
1452 VP9_COMMON *const cm = &cpi->common; 1578 VP9_COMMON *const cm = &cpi->common;
1453 const int mis = cm->mi_stride; 1579 const int mis = cm->mi_stride;
1454 const int row8x8_remaining = tile->mi_row_end - mi_row; 1580 const int row8x8_remaining = tile->mi_row_end - mi_row;
1455 const int col8x8_remaining = tile->mi_col_end - mi_col; 1581 const int col8x8_remaining = tile->mi_col_end - mi_col;
1456 MODE_INFO *mi_upper_left = cm->mi + mi_row * mis + mi_col; 1582 MODE_INFO *mi_upper_left = cm->mi + mi_row * mis + mi_col;
1457 1583
1458 vp9_setup_src_planes(x, cpi->Source, mi_row, mi_col); 1584 vp9_setup_src_planes(x, cpi->Source, mi_row, mi_col);
1459 1585
1460 assert((row8x8_remaining > 0) && (col8x8_remaining > 0)); 1586 assert((row8x8_remaining > 0) && (col8x8_remaining > 0));
1461 1587
1462 // In-image SB64 1588 // In-image SB64
1463 if ((col8x8_remaining >= MI_BLOCK_SIZE) && 1589 if ((col8x8_remaining >= MI_BLOCK_SIZE) &&
1464 (row8x8_remaining >= MI_BLOCK_SIZE)) { 1590 (row8x8_remaining >= MI_BLOCK_SIZE)) {
1465 int i, j; 1591 int i, j;
1466 int index; 1592 int index;
1467 diff d32[4]; 1593 diff d32[4];
1468 const int offset = (mi_row >> 1) * cm->mb_cols + (mi_col >> 1); 1594 const int offset = (mi_row >> 1) * cm->mb_cols + (mi_col >> 1);
1469 int is_larger_better = 0; 1595 int is_larger_better = 0;
1470 int use32x32 = 0; 1596 int use32x32 = 0;
1471 unsigned int thr = cpi->source_var_thresh; 1597 unsigned int thr = cpi->source_var_thresh;
1472 1598
1473 vpx_memset(d32, 0, 4 * sizeof(diff)); 1599 memset(d32, 0, 4 * sizeof(diff));
1474 1600
1475 for (i = 0; i < 4; i++) { 1601 for (i = 0; i < 4; i++) {
1476 diff *d16[4]; 1602 diff *d16[4];
1477 1603
1478 for (j = 0; j < 4; j++) { 1604 for (j = 0; j < 4; j++) {
1479 int b_mi_row = coord_lookup[i * 4 + j].row; 1605 int b_mi_row = coord_lookup[i * 4 + j].row;
1480 int b_mi_col = coord_lookup[i * 4 + j].col; 1606 int b_mi_col = coord_lookup[i * 4 + j].col;
1481 int boffset = b_mi_row / 2 * cm->mb_cols + 1607 int boffset = b_mi_row / 2 * cm->mb_cols +
1482 b_mi_col / 2; 1608 b_mi_col / 2;
1483 1609
1484 d16[j] = cpi->source_diff_var + offset + boffset; 1610 d16[j] = cpi->source_diff_var + offset + boffset;
1485 1611
1486 index = b_mi_row * mis + b_mi_col; 1612 index = b_mi_row * mis + b_mi_col;
1487 mi_8x8[index].src_mi = mi_upper_left + index; 1613 mi_8x8[index] = mi_upper_left + index;
1488 mi_8x8[index].src_mi->mbmi.sb_type = BLOCK_16X16; 1614 mi_8x8[index]->mbmi.sb_type = BLOCK_16X16;
1489 1615
1490 // TODO(yunqingwang): If d16[j].var is very large, use 8x8 partition 1616 // TODO(yunqingwang): If d16[j].var is very large, use 8x8 partition
1491 // size to further improve quality. 1617 // size to further improve quality.
1492 } 1618 }
1493 1619
1494 is_larger_better = (d16[0]->var < thr) && (d16[1]->var < thr) && 1620 is_larger_better = (d16[0]->var < thr) && (d16[1]->var < thr) &&
1495 (d16[2]->var < thr) && (d16[3]->var < thr); 1621 (d16[2]->var < thr) && (d16[3]->var < thr);
1496 1622
1497 // Use 32x32 partition 1623 // Use 32x32 partition
1498 if (is_larger_better) { 1624 if (is_larger_better) {
1499 use32x32 += 1; 1625 use32x32 += 1;
1500 1626
1501 for (j = 0; j < 4; j++) { 1627 for (j = 0; j < 4; j++) {
1502 d32[i].sse += d16[j]->sse; 1628 d32[i].sse += d16[j]->sse;
1503 d32[i].sum += d16[j]->sum; 1629 d32[i].sum += d16[j]->sum;
1504 } 1630 }
1505 1631
1506 d32[i].var = d32[i].sse - (((int64_t)d32[i].sum * d32[i].sum) >> 10); 1632 d32[i].var = d32[i].sse - (((int64_t)d32[i].sum * d32[i].sum) >> 10);
1507 1633
1508 index = coord_lookup[i*4].row * mis + coord_lookup[i*4].col; 1634 index = coord_lookup[i*4].row * mis + coord_lookup[i*4].col;
1509 mi_8x8[index].src_mi = mi_upper_left + index; 1635 mi_8x8[index] = mi_upper_left + index;
1510 mi_8x8[index].src_mi->mbmi.sb_type = BLOCK_32X32; 1636 mi_8x8[index]->mbmi.sb_type = BLOCK_32X32;
1511 } 1637 }
1512 } 1638 }
1513 1639
1514 if (use32x32 == 4) { 1640 if (use32x32 == 4) {
1515 thr <<= 1; 1641 thr <<= 1;
1516 is_larger_better = (d32[0].var < thr) && (d32[1].var < thr) && 1642 is_larger_better = (d32[0].var < thr) && (d32[1].var < thr) &&
1517 (d32[2].var < thr) && (d32[3].var < thr); 1643 (d32[2].var < thr) && (d32[3].var < thr);
1518 1644
1519 // Use 64x64 partition 1645 // Use 64x64 partition
1520 if (is_larger_better) { 1646 if (is_larger_better) {
1521 mi_8x8[0].src_mi = mi_upper_left; 1647 mi_8x8[0] = mi_upper_left;
1522 mi_8x8[0].src_mi->mbmi.sb_type = BLOCK_64X64; 1648 mi_8x8[0]->mbmi.sb_type = BLOCK_64X64;
1523 } 1649 }
1524 } 1650 }
1525 } else { // partial in-image SB64 1651 } else { // partial in-image SB64
1526 int bh = num_8x8_blocks_high_lookup[BLOCK_16X16]; 1652 int bh = num_8x8_blocks_high_lookup[BLOCK_16X16];
1527 int bw = num_8x8_blocks_wide_lookup[BLOCK_16X16]; 1653 int bw = num_8x8_blocks_wide_lookup[BLOCK_16X16];
1528 set_partial_b64x64_partition(mi_upper_left, mis, bh, bw, 1654 set_partial_b64x64_partition(mi_upper_left, mis, bh, bw,
1529 row8x8_remaining, col8x8_remaining, BLOCK_16X16, mi_8x8); 1655 row8x8_remaining, col8x8_remaining, BLOCK_16X16, mi_8x8);
1530 } 1656 }
1531 } 1657 }
1532 1658
1533 static void update_state_rt(VP9_COMP *cpi, ThreadData *td, 1659 static void update_state_rt(VP9_COMP *cpi, ThreadData *td,
1534 PICK_MODE_CONTEXT *ctx, 1660 PICK_MODE_CONTEXT *ctx,
1535 int mi_row, int mi_col, int bsize) { 1661 int mi_row, int mi_col, int bsize) {
1536 VP9_COMMON *const cm = &cpi->common; 1662 VP9_COMMON *const cm = &cpi->common;
1537 MACROBLOCK *const x = &td->mb; 1663 MACROBLOCK *const x = &td->mb;
1538 MACROBLOCKD *const xd = &x->e_mbd; 1664 MACROBLOCKD *const xd = &x->e_mbd;
1539 MODE_INFO *const mi = xd->mi[0].src_mi; 1665 MODE_INFO *const mi = xd->mi[0];
1540 MB_MODE_INFO *const mbmi = &xd->mi[0].src_mi->mbmi; 1666 MB_MODE_INFO *const mbmi = &xd->mi[0]->mbmi;
1541 const struct segmentation *const seg = &cm->seg; 1667 const struct segmentation *const seg = &cm->seg;
1542 const int bw = num_8x8_blocks_wide_lookup[mi->mbmi.sb_type]; 1668 const int bw = num_8x8_blocks_wide_lookup[mi->mbmi.sb_type];
1543 const int bh = num_8x8_blocks_high_lookup[mi->mbmi.sb_type]; 1669 const int bh = num_8x8_blocks_high_lookup[mi->mbmi.sb_type];
1544 const int x_mis = MIN(bw, cm->mi_cols - mi_col); 1670 const int x_mis = MIN(bw, cm->mi_cols - mi_col);
1545 const int y_mis = MIN(bh, cm->mi_rows - mi_row); 1671 const int y_mis = MIN(bh, cm->mi_rows - mi_row);
1546 1672
1547 xd->mi[0] = ctx->mic; 1673 *(xd->mi[0]) = ctx->mic;
1548 xd->mi[0].src_mi = &xd->mi[0];
1549 1674
1550 if (seg->enabled && cpi->oxcf.aq_mode) { 1675 if (seg->enabled && cpi->oxcf.aq_mode) {
1551 // For in frame complexity AQ or variance AQ, copy segment_id from 1676 // For in frame complexity AQ or variance AQ, copy segment_id from
1552 // segmentation_map. 1677 // segmentation_map.
1553 if (cpi->oxcf.aq_mode == COMPLEXITY_AQ || 1678 if (cpi->oxcf.aq_mode == COMPLEXITY_AQ ||
1554 cpi->oxcf.aq_mode == VARIANCE_AQ ) { 1679 cpi->oxcf.aq_mode == VARIANCE_AQ ) {
1555 const uint8_t *const map = seg->update_map ? cpi->segmentation_map 1680 const uint8_t *const map = seg->update_map ? cpi->segmentation_map
1556 : cm->last_frame_seg_map; 1681 : cm->last_frame_seg_map;
1557 mbmi->segment_id = vp9_get_segment_id(cm, map, bsize, mi_row, mi_col); 1682 mbmi->segment_id = vp9_get_segment_id(cm, map, bsize, mi_row, mi_col);
1558 } else { 1683 } else {
(...skipping 19 matching lines...) Expand all
1578 1703
1579 if (cm->use_prev_frame_mvs) { 1704 if (cm->use_prev_frame_mvs) {
1580 MV_REF *const frame_mvs = 1705 MV_REF *const frame_mvs =
1581 cm->cur_frame->mvs + mi_row * cm->mi_cols + mi_col; 1706 cm->cur_frame->mvs + mi_row * cm->mi_cols + mi_col;
1582 int w, h; 1707 int w, h;
1583 1708
1584 for (h = 0; h < y_mis; ++h) { 1709 for (h = 0; h < y_mis; ++h) {
1585 MV_REF *const frame_mv = frame_mvs + h * cm->mi_cols; 1710 MV_REF *const frame_mv = frame_mvs + h * cm->mi_cols;
1586 for (w = 0; w < x_mis; ++w) { 1711 for (w = 0; w < x_mis; ++w) {
1587 MV_REF *const mv = frame_mv + w; 1712 MV_REF *const mv = frame_mv + w;
1588 mv->ref_frame[0] = mi->src_mi->mbmi.ref_frame[0]; 1713 mv->ref_frame[0] = mi->mbmi.ref_frame[0];
1589 mv->ref_frame[1] = mi->src_mi->mbmi.ref_frame[1]; 1714 mv->ref_frame[1] = mi->mbmi.ref_frame[1];
1590 mv->mv[0].as_int = mi->src_mi->mbmi.mv[0].as_int; 1715 mv->mv[0].as_int = mi->mbmi.mv[0].as_int;
1591 mv->mv[1].as_int = mi->src_mi->mbmi.mv[1].as_int; 1716 mv->mv[1].as_int = mi->mbmi.mv[1].as_int;
1592 } 1717 }
1593 } 1718 }
1594 } 1719 }
1595 1720
1596 x->skip = ctx->skip; 1721 x->skip = ctx->skip;
1597 x->skip_txfm[0] = mbmi->segment_id ? 0 : ctx->skip_txfm[0]; 1722 x->skip_txfm[0] = mbmi->segment_id ? 0 : ctx->skip_txfm[0];
1598 } 1723 }
1599 1724
1600 static void encode_b_rt(VP9_COMP *cpi, ThreadData *td, 1725 static void encode_b_rt(VP9_COMP *cpi, ThreadData *td,
1601 const TileInfo *const tile, 1726 const TileInfo *const tile,
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1633 const int bsl = b_width_log2_lookup[bsize], hbs = (1 << bsl) / 4; 1758 const int bsl = b_width_log2_lookup[bsize], hbs = (1 << bsl) / 4;
1634 int ctx; 1759 int ctx;
1635 PARTITION_TYPE partition; 1760 PARTITION_TYPE partition;
1636 BLOCK_SIZE subsize; 1761 BLOCK_SIZE subsize;
1637 1762
1638 if (mi_row >= cm->mi_rows || mi_col >= cm->mi_cols) 1763 if (mi_row >= cm->mi_rows || mi_col >= cm->mi_cols)
1639 return; 1764 return;
1640 1765
1641 if (bsize >= BLOCK_8X8) { 1766 if (bsize >= BLOCK_8X8) {
1642 const int idx_str = xd->mi_stride * mi_row + mi_col; 1767 const int idx_str = xd->mi_stride * mi_row + mi_col;
1643 MODE_INFO *mi_8x8 = cm->mi[idx_str].src_mi; 1768 MODE_INFO ** mi_8x8 = cm->mi_grid_visible + idx_str;
1644 ctx = partition_plane_context(xd, mi_row, mi_col, bsize); 1769 ctx = partition_plane_context(xd, mi_row, mi_col, bsize);
1645 subsize = mi_8x8[0].src_mi->mbmi.sb_type; 1770 subsize = mi_8x8[0]->mbmi.sb_type;
1646 } else { 1771 } else {
1647 ctx = 0; 1772 ctx = 0;
1648 subsize = BLOCK_4X4; 1773 subsize = BLOCK_4X4;
1649 } 1774 }
1650 1775
1651 partition = partition_lookup[bsl][subsize]; 1776 partition = partition_lookup[bsl][subsize];
1652 if (output_enabled && bsize != BLOCK_4X4) 1777 if (output_enabled && bsize != BLOCK_4X4)
1653 td->counts->partition[ctx][partition]++; 1778 td->counts->partition[ctx][partition]++;
1654 1779
1655 switch (partition) { 1780 switch (partition) {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1689 break; 1814 break;
1690 } 1815 }
1691 1816
1692 if (partition != PARTITION_SPLIT || bsize == BLOCK_8X8) 1817 if (partition != PARTITION_SPLIT || bsize == BLOCK_8X8)
1693 update_partition_context(xd, mi_row, mi_col, subsize, bsize); 1818 update_partition_context(xd, mi_row, mi_col, subsize, bsize);
1694 } 1819 }
1695 1820
1696 static void rd_use_partition(VP9_COMP *cpi, 1821 static void rd_use_partition(VP9_COMP *cpi,
1697 ThreadData *td, 1822 ThreadData *td,
1698 TileDataEnc *tile_data, 1823 TileDataEnc *tile_data,
1699 MODE_INFO *mi_8x8, TOKENEXTRA **tp, 1824 MODE_INFO **mi_8x8, TOKENEXTRA **tp,
1700 int mi_row, int mi_col, 1825 int mi_row, int mi_col,
1701 BLOCK_SIZE bsize, 1826 BLOCK_SIZE bsize,
1702 int *rate, int64_t *dist, 1827 int *rate, int64_t *dist,
1703 int do_recon, PC_TREE *pc_tree) { 1828 int do_recon, PC_TREE *pc_tree) {
1704 VP9_COMMON *const cm = &cpi->common; 1829 VP9_COMMON *const cm = &cpi->common;
1705 TileInfo *const tile_info = &tile_data->tile_info; 1830 TileInfo *const tile_info = &tile_data->tile_info;
1706 MACROBLOCK *const x = &td->mb; 1831 MACROBLOCK *const x = &td->mb;
1707 MACROBLOCKD *const xd = &x->e_mbd; 1832 MACROBLOCKD *const xd = &x->e_mbd;
1708 const int mis = cm->mi_stride; 1833 const int mis = cm->mi_stride;
1709 const int bsl = b_width_log2_lookup[bsize]; 1834 const int bsl = b_width_log2_lookup[bsize];
1710 const int mi_step = num_4x4_blocks_wide_lookup[bsize] / 2; 1835 const int mi_step = num_4x4_blocks_wide_lookup[bsize] / 2;
1711 const int bss = (1 << bsl) / 4; 1836 const int bss = (1 << bsl) / 4;
1712 int i, pl; 1837 int i, pl;
1713 PARTITION_TYPE partition = PARTITION_NONE; 1838 PARTITION_TYPE partition = PARTITION_NONE;
1714 BLOCK_SIZE subsize; 1839 BLOCK_SIZE subsize;
1715 ENTROPY_CONTEXT l[16 * MAX_MB_PLANE], a[16 * MAX_MB_PLANE]; 1840 ENTROPY_CONTEXT l[16 * MAX_MB_PLANE], a[16 * MAX_MB_PLANE];
1716 PARTITION_CONTEXT sl[8], sa[8]; 1841 PARTITION_CONTEXT sl[8], sa[8];
1717 RD_COST last_part_rdc, none_rdc, chosen_rdc; 1842 RD_COST last_part_rdc, none_rdc, chosen_rdc;
1718 BLOCK_SIZE sub_subsize = BLOCK_4X4; 1843 BLOCK_SIZE sub_subsize = BLOCK_4X4;
1719 int splits_below = 0; 1844 int splits_below = 0;
1720 BLOCK_SIZE bs_type = mi_8x8[0].src_mi->mbmi.sb_type; 1845 BLOCK_SIZE bs_type = mi_8x8[0]->mbmi.sb_type;
1721 int do_partition_search = 1; 1846 int do_partition_search = 1;
1722 PICK_MODE_CONTEXT *ctx = &pc_tree->none; 1847 PICK_MODE_CONTEXT *ctx = &pc_tree->none;
1723 1848
1724 if (mi_row >= cm->mi_rows || mi_col >= cm->mi_cols) 1849 if (mi_row >= cm->mi_rows || mi_col >= cm->mi_cols)
1725 return; 1850 return;
1726 1851
1727 assert(num_4x4_blocks_wide_lookup[bsize] == 1852 assert(num_4x4_blocks_wide_lookup[bsize] ==
1728 num_4x4_blocks_high_lookup[bsize]); 1853 num_4x4_blocks_high_lookup[bsize]);
1729 1854
1730 vp9_rd_cost_reset(&last_part_rdc); 1855 vp9_rd_cost_reset(&last_part_rdc);
(...skipping 13 matching lines...) Expand all
1744 1869
1745 if (do_partition_search && 1870 if (do_partition_search &&
1746 cpi->sf.partition_search_type == SEARCH_PARTITION && 1871 cpi->sf.partition_search_type == SEARCH_PARTITION &&
1747 cpi->sf.adjust_partitioning_from_last_frame) { 1872 cpi->sf.adjust_partitioning_from_last_frame) {
1748 // Check if any of the sub blocks are further split. 1873 // Check if any of the sub blocks are further split.
1749 if (partition == PARTITION_SPLIT && subsize > BLOCK_8X8) { 1874 if (partition == PARTITION_SPLIT && subsize > BLOCK_8X8) {
1750 sub_subsize = get_subsize(subsize, PARTITION_SPLIT); 1875 sub_subsize = get_subsize(subsize, PARTITION_SPLIT);
1751 splits_below = 1; 1876 splits_below = 1;
1752 for (i = 0; i < 4; i++) { 1877 for (i = 0; i < 4; i++) {
1753 int jj = i >> 1, ii = i & 0x01; 1878 int jj = i >> 1, ii = i & 0x01;
1754 MODE_INFO *this_mi = mi_8x8[jj * bss * mis + ii * bss].src_mi; 1879 MODE_INFO *this_mi = mi_8x8[jj * bss * mis + ii * bss];
1755 if (this_mi && this_mi->mbmi.sb_type >= sub_subsize) { 1880 if (this_mi && this_mi->mbmi.sb_type >= sub_subsize) {
1756 splits_below = 0; 1881 splits_below = 0;
1757 } 1882 }
1758 } 1883 }
1759 } 1884 }
1760 1885
1761 // If partition is not none try none unless each of the 4 splits are split 1886 // If partition is not none try none unless each of the 4 splits are split
1762 // even further.. 1887 // even further..
1763 if (partition != PARTITION_NONE && !splits_below && 1888 if (partition != PARTITION_NONE && !splits_below &&
1764 mi_row + (mi_step >> 1) < cm->mi_rows && 1889 mi_row + (mi_step >> 1) < cm->mi_rows &&
1765 mi_col + (mi_step >> 1) < cm->mi_cols) { 1890 mi_col + (mi_step >> 1) < cm->mi_cols) {
1766 pc_tree->partitioning = PARTITION_NONE; 1891 pc_tree->partitioning = PARTITION_NONE;
1767 rd_pick_sb_modes(cpi, tile_data, x, mi_row, mi_col, &none_rdc, bsize, 1892 rd_pick_sb_modes(cpi, tile_data, x, mi_row, mi_col, &none_rdc, bsize,
1768 ctx, INT64_MAX); 1893 ctx, INT64_MAX);
1769 1894
1770 pl = partition_plane_context(xd, mi_row, mi_col, bsize); 1895 pl = partition_plane_context(xd, mi_row, mi_col, bsize);
1771 1896
1772 if (none_rdc.rate < INT_MAX) { 1897 if (none_rdc.rate < INT_MAX) {
1773 none_rdc.rate += cpi->partition_cost[pl][PARTITION_NONE]; 1898 none_rdc.rate += cpi->partition_cost[pl][PARTITION_NONE];
1774 none_rdc.rdcost = RDCOST(x->rdmult, x->rddiv, none_rdc.rate, 1899 none_rdc.rdcost = RDCOST(x->rdmult, x->rddiv, none_rdc.rate,
1775 none_rdc.dist); 1900 none_rdc.dist);
1776 } 1901 }
1777 1902
1778 restore_context(x, mi_row, mi_col, a, l, sa, sl, bsize); 1903 restore_context(x, mi_row, mi_col, a, l, sa, sl, bsize);
1779 mi_8x8[0].src_mi->mbmi.sb_type = bs_type; 1904 mi_8x8[0]->mbmi.sb_type = bs_type;
1780 pc_tree->partitioning = partition; 1905 pc_tree->partitioning = partition;
1781 } 1906 }
1782 } 1907 }
1783 1908
1784 switch (partition) { 1909 switch (partition) {
1785 case PARTITION_NONE: 1910 case PARTITION_NONE:
1786 rd_pick_sb_modes(cpi, tile_data, x, mi_row, mi_col, &last_part_rdc, 1911 rd_pick_sb_modes(cpi, tile_data, x, mi_row, mi_col, &last_part_rdc,
1787 bsize, ctx, INT64_MAX); 1912 bsize, ctx, INT64_MAX);
1788 break; 1913 break;
1789 case PARTITION_HORZ: 1914 case PARTITION_HORZ:
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
1927 pl = partition_plane_context(xd, mi_row, mi_col, bsize); 2052 pl = partition_plane_context(xd, mi_row, mi_col, bsize);
1928 if (chosen_rdc.rate < INT_MAX) { 2053 if (chosen_rdc.rate < INT_MAX) {
1929 chosen_rdc.rate += cpi->partition_cost[pl][PARTITION_SPLIT]; 2054 chosen_rdc.rate += cpi->partition_cost[pl][PARTITION_SPLIT];
1930 chosen_rdc.rdcost = RDCOST(x->rdmult, x->rddiv, 2055 chosen_rdc.rdcost = RDCOST(x->rdmult, x->rddiv,
1931 chosen_rdc.rate, chosen_rdc.dist); 2056 chosen_rdc.rate, chosen_rdc.dist);
1932 } 2057 }
1933 } 2058 }
1934 2059
1935 // If last_part is better set the partitioning to that. 2060 // If last_part is better set the partitioning to that.
1936 if (last_part_rdc.rdcost < chosen_rdc.rdcost) { 2061 if (last_part_rdc.rdcost < chosen_rdc.rdcost) {
1937 mi_8x8[0].src_mi->mbmi.sb_type = bsize; 2062 mi_8x8[0]->mbmi.sb_type = bsize;
1938 if (bsize >= BLOCK_8X8) 2063 if (bsize >= BLOCK_8X8)
1939 pc_tree->partitioning = partition; 2064 pc_tree->partitioning = partition;
1940 chosen_rdc = last_part_rdc; 2065 chosen_rdc = last_part_rdc;
1941 } 2066 }
1942 // If none was better set the partitioning to that. 2067 // If none was better set the partitioning to that.
1943 if (none_rdc.rdcost < chosen_rdc.rdcost) { 2068 if (none_rdc.rdcost < chosen_rdc.rdcost) {
1944 if (bsize >= BLOCK_8X8) 2069 if (bsize >= BLOCK_8X8)
1945 pc_tree->partitioning = PARTITION_NONE; 2070 pc_tree->partitioning = PARTITION_NONE;
1946 chosen_rdc = none_rdc; 2071 chosen_rdc = none_rdc;
1947 } 2072 }
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1979 BLOCK_64X64 2104 BLOCK_64X64
1980 }; 2105 };
1981 2106
1982 // Look at all the mode_info entries for blocks that are part of this 2107 // Look at all the mode_info entries for blocks that are part of this
1983 // partition and find the min and max values for sb_type. 2108 // partition and find the min and max values for sb_type.
1984 // At the moment this is designed to work on a 64x64 SB but could be 2109 // At the moment this is designed to work on a 64x64 SB but could be
1985 // adjusted to use a size parameter. 2110 // adjusted to use a size parameter.
1986 // 2111 //
1987 // The min and max are assumed to have been initialized prior to calling this 2112 // The min and max are assumed to have been initialized prior to calling this
1988 // function so repeat calls can accumulate a min and max of more than one sb64. 2113 // function so repeat calls can accumulate a min and max of more than one sb64.
1989 static void get_sb_partition_size_range(MACROBLOCKD *xd, MODE_INFO *mi_8x8, 2114 static void get_sb_partition_size_range(MACROBLOCKD *xd, MODE_INFO **mi_8x8,
1990 BLOCK_SIZE *min_block_size, 2115 BLOCK_SIZE *min_block_size,
1991 BLOCK_SIZE *max_block_size, 2116 BLOCK_SIZE *max_block_size,
1992 int bs_hist[BLOCK_SIZES]) { 2117 int bs_hist[BLOCK_SIZES]) {
1993 int sb_width_in_blocks = MI_BLOCK_SIZE; 2118 int sb_width_in_blocks = MI_BLOCK_SIZE;
1994 int sb_height_in_blocks = MI_BLOCK_SIZE; 2119 int sb_height_in_blocks = MI_BLOCK_SIZE;
1995 int i, j; 2120 int i, j;
1996 int index = 0; 2121 int index = 0;
1997 2122
1998 // Check the sb_type for each block that belongs to this region. 2123 // Check the sb_type for each block that belongs to this region.
1999 for (i = 0; i < sb_height_in_blocks; ++i) { 2124 for (i = 0; i < sb_height_in_blocks; ++i) {
2000 for (j = 0; j < sb_width_in_blocks; ++j) { 2125 for (j = 0; j < sb_width_in_blocks; ++j) {
2001 MODE_INFO *mi = mi_8x8[index+j].src_mi; 2126 MODE_INFO *mi = mi_8x8[index+j];
2002 BLOCK_SIZE sb_type = mi ? mi->mbmi.sb_type : 0; 2127 BLOCK_SIZE sb_type = mi ? mi->mbmi.sb_type : 0;
2003 bs_hist[sb_type]++; 2128 bs_hist[sb_type]++;
2004 *min_block_size = MIN(*min_block_size, sb_type); 2129 *min_block_size = MIN(*min_block_size, sb_type);
2005 *max_block_size = MAX(*max_block_size, sb_type); 2130 *max_block_size = MAX(*max_block_size, sb_type);
2006 } 2131 }
2007 index += xd->mi_stride; 2132 index += xd->mi_stride;
2008 } 2133 }
2009 } 2134 }
2010 2135
2011 // Next square block size less or equal than current block size. 2136 // Next square block size less or equal than current block size.
2012 static const BLOCK_SIZE next_square_size[BLOCK_SIZES] = { 2137 static const BLOCK_SIZE next_square_size[BLOCK_SIZES] = {
2013 BLOCK_4X4, BLOCK_4X4, BLOCK_4X4, 2138 BLOCK_4X4, BLOCK_4X4, BLOCK_4X4,
2014 BLOCK_8X8, BLOCK_8X8, BLOCK_8X8, 2139 BLOCK_8X8, BLOCK_8X8, BLOCK_8X8,
2015 BLOCK_16X16, BLOCK_16X16, BLOCK_16X16, 2140 BLOCK_16X16, BLOCK_16X16, BLOCK_16X16,
2016 BLOCK_32X32, BLOCK_32X32, BLOCK_32X32, 2141 BLOCK_32X32, BLOCK_32X32, BLOCK_32X32,
2017 BLOCK_64X64 2142 BLOCK_64X64
2018 }; 2143 };
2019 2144
2020 // Look at neighboring blocks and set a min and max partition size based on 2145 // Look at neighboring blocks and set a min and max partition size based on
2021 // what they chose. 2146 // what they chose.
2022 static void rd_auto_partition_range(VP9_COMP *cpi, const TileInfo *const tile, 2147 static void rd_auto_partition_range(VP9_COMP *cpi, const TileInfo *const tile,
2023 MACROBLOCKD *const xd, 2148 MACROBLOCKD *const xd,
2024 int mi_row, int mi_col, 2149 int mi_row, int mi_col,
2025 BLOCK_SIZE *min_block_size, 2150 BLOCK_SIZE *min_block_size,
2026 BLOCK_SIZE *max_block_size) { 2151 BLOCK_SIZE *max_block_size) {
2027 VP9_COMMON *const cm = &cpi->common; 2152 VP9_COMMON *const cm = &cpi->common;
2028 MODE_INFO *mi = xd->mi[0].src_mi; 2153 MODE_INFO **mi = xd->mi;
2029 const int left_in_image = xd->left_available && mi[-1].src_mi; 2154 const int left_in_image = xd->left_available && mi[-1];
2030 const int above_in_image = xd->up_available && mi[-xd->mi_stride].src_mi; 2155 const int above_in_image = xd->up_available && mi[-xd->mi_stride];
2031 const int row8x8_remaining = tile->mi_row_end - mi_row; 2156 const int row8x8_remaining = tile->mi_row_end - mi_row;
2032 const int col8x8_remaining = tile->mi_col_end - mi_col; 2157 const int col8x8_remaining = tile->mi_col_end - mi_col;
2033 int bh, bw; 2158 int bh, bw;
2034 BLOCK_SIZE min_size = BLOCK_4X4; 2159 BLOCK_SIZE min_size = BLOCK_4X4;
2035 BLOCK_SIZE max_size = BLOCK_64X64; 2160 BLOCK_SIZE max_size = BLOCK_64X64;
2036 int i = 0;
2037 int bs_hist[BLOCK_SIZES] = {0}; 2161 int bs_hist[BLOCK_SIZES] = {0};
2038 2162
2039 // Trap case where we do not have a prediction. 2163 // Trap case where we do not have a prediction.
2040 if (left_in_image || above_in_image || cm->frame_type != KEY_FRAME) { 2164 if (left_in_image || above_in_image || cm->frame_type != KEY_FRAME) {
2041 // Default "min to max" and "max to min" 2165 // Default "min to max" and "max to min"
2042 min_size = BLOCK_64X64; 2166 min_size = BLOCK_64X64;
2043 max_size = BLOCK_4X4; 2167 max_size = BLOCK_4X4;
2044 2168
2045 // NOTE: each call to get_sb_partition_size_range() uses the previous 2169 // NOTE: each call to get_sb_partition_size_range() uses the previous
2046 // passed in values for min and max as a starting point. 2170 // passed in values for min and max as a starting point.
2047 // Find the min and max partition used in previous frame at this location 2171 // Find the min and max partition used in previous frame at this location
2048 if (cm->frame_type != KEY_FRAME) { 2172 if (cm->frame_type != KEY_FRAME) {
2049 MODE_INFO *prev_mi = 2173 MODE_INFO **prev_mi =
2050 cm->prev_mip + cm->mi_stride + 1 + mi_row * xd->mi_stride + mi_col; 2174 &cm->prev_mi_grid_visible[mi_row * xd->mi_stride + mi_col];
2051
2052 get_sb_partition_size_range(xd, prev_mi, &min_size, &max_size, bs_hist); 2175 get_sb_partition_size_range(xd, prev_mi, &min_size, &max_size, bs_hist);
2053 } 2176 }
2054 // Find the min and max partition sizes used in the left SB64 2177 // Find the min and max partition sizes used in the left SB64
2055 if (left_in_image) { 2178 if (left_in_image) {
2056 MODE_INFO *left_sb64_mi = mi[-MI_BLOCK_SIZE].src_mi; 2179 MODE_INFO **left_sb64_mi = &mi[-MI_BLOCK_SIZE];
2057 get_sb_partition_size_range(xd, left_sb64_mi, &min_size, &max_size, 2180 get_sb_partition_size_range(xd, left_sb64_mi, &min_size, &max_size,
2058 bs_hist); 2181 bs_hist);
2059 } 2182 }
2060 // Find the min and max partition sizes used in the above SB64. 2183 // Find the min and max partition sizes used in the above SB64.
2061 if (above_in_image) { 2184 if (above_in_image) {
2062 MODE_INFO *above_sb64_mi = mi[-xd->mi_stride * MI_BLOCK_SIZE].src_mi; 2185 MODE_INFO **above_sb64_mi = &mi[-xd->mi_stride * MI_BLOCK_SIZE];
2063 get_sb_partition_size_range(xd, above_sb64_mi, &min_size, &max_size, 2186 get_sb_partition_size_range(xd, above_sb64_mi, &min_size, &max_size,
2064 bs_hist); 2187 bs_hist);
2065 } 2188 }
2066 2189
2067 // adjust observed min and max 2190 // Adjust observed min and max for "relaxed" auto partition case.
2068 if (cpi->sf.auto_min_max_partition_size == RELAXED_NEIGHBORING_MIN_MAX) { 2191 if (cpi->sf.auto_min_max_partition_size == RELAXED_NEIGHBORING_MIN_MAX) {
2069 min_size = min_partition_size[min_size]; 2192 min_size = min_partition_size[min_size];
2070 max_size = max_partition_size[max_size]; 2193 max_size = max_partition_size[max_size];
2071 } else if (cpi->sf.auto_min_max_partition_size ==
2072 CONSTRAIN_NEIGHBORING_MIN_MAX) {
2073 // adjust the search range based on the histogram of the observed
2074 // partition sizes from left, above the previous co-located blocks
2075 int sum = 0;
2076 int first_moment = 0;
2077 int second_moment = 0;
2078 int var_unnormalized = 0;
2079
2080 for (i = 0; i < BLOCK_SIZES; i++) {
2081 sum += bs_hist[i];
2082 first_moment += bs_hist[i] * i;
2083 second_moment += bs_hist[i] * i * i;
2084 }
2085
2086 // if variance is small enough,
2087 // adjust the range around its mean size, which gives a tighter range
2088 var_unnormalized = second_moment - first_moment * first_moment / sum;
2089 if (var_unnormalized <= 4 * sum) {
2090 int mean = first_moment / sum;
2091 min_size = min_partition_size[mean];
2092 max_size = max_partition_size[mean];
2093 } else {
2094 min_size = min_partition_size[min_size];
2095 max_size = max_partition_size[max_size];
2096 }
2097 } 2194 }
2098 } 2195 }
2099 2196
2100 // Check border cases where max and min from neighbors may not be legal. 2197 // Check border cases where max and min from neighbors may not be legal.
2101 max_size = find_partition_size(max_size, 2198 max_size = find_partition_size(max_size,
2102 row8x8_remaining, col8x8_remaining, 2199 row8x8_remaining, col8x8_remaining,
2103 &bh, &bw); 2200 &bh, &bw);
2104 min_size = MIN(min_size, max_size); 2201 min_size = MIN(cpi->sf.rd_auto_partition_min_limit, MIN(min_size, max_size));
2105 2202
2106 // When use_square_partition_only is true, make sure at least one square 2203 // When use_square_partition_only is true, make sure at least one square
2107 // partition is allowed by selecting the next smaller square size as 2204 // partition is allowed by selecting the next smaller square size as
2108 // *min_block_size. 2205 // *min_block_size.
2109 if (cpi->sf.use_square_partition_only && 2206 if (cpi->sf.use_square_partition_only &&
2110 next_square_size[max_size] < min_size) { 2207 next_square_size[max_size] < min_size) {
2111 min_size = next_square_size[max_size]; 2208 min_size = next_square_size[max_size];
2112 } 2209 }
2113 2210
2114 *min_block_size = min_size; 2211 *min_block_size = min_size;
2115 *max_block_size = max_size; 2212 *max_block_size = max_size;
2116 } 2213 }
2117 2214
2118 static void auto_partition_range(VP9_COMP *cpi, const TileInfo *const tile, 2215 static void auto_partition_range(VP9_COMP *cpi, const TileInfo *const tile,
2119 MACROBLOCKD *const xd, 2216 MACROBLOCKD *const xd,
2120 int mi_row, int mi_col, 2217 int mi_row, int mi_col,
2121 BLOCK_SIZE *min_block_size, 2218 BLOCK_SIZE *min_block_size,
2122 BLOCK_SIZE *max_block_size) { 2219 BLOCK_SIZE *max_block_size) {
2123 VP9_COMMON *const cm = &cpi->common; 2220 VP9_COMMON *const cm = &cpi->common;
2124 MODE_INFO *mi_8x8 = xd->mi; 2221 MODE_INFO **mi_8x8 = xd->mi;
2125 const int left_in_image = xd->left_available && mi_8x8[-1].src_mi; 2222 const int left_in_image = xd->left_available && mi_8x8[-1];
2126 const int above_in_image = xd->up_available && 2223 const int above_in_image = xd->up_available && mi_8x8[-xd->mi_stride];
2127 mi_8x8[-xd->mi_stride].src_mi;
2128 int row8x8_remaining = tile->mi_row_end - mi_row; 2224 int row8x8_remaining = tile->mi_row_end - mi_row;
2129 int col8x8_remaining = tile->mi_col_end - mi_col; 2225 int col8x8_remaining = tile->mi_col_end - mi_col;
2130 int bh, bw; 2226 int bh, bw;
2131 BLOCK_SIZE min_size = BLOCK_32X32; 2227 BLOCK_SIZE min_size = BLOCK_32X32;
2132 BLOCK_SIZE max_size = BLOCK_8X8; 2228 BLOCK_SIZE max_size = BLOCK_8X8;
2133 int bsl = mi_width_log2_lookup[BLOCK_64X64]; 2229 int bsl = mi_width_log2_lookup[BLOCK_64X64];
2134 const int search_range_ctrl = (((mi_row + mi_col) >> bsl) + 2230 const int search_range_ctrl = (((mi_row + mi_col) >> bsl) +
2135 get_chessboard_index(cm->current_video_frame)) & 0x1; 2231 get_chessboard_index(cm->current_video_frame)) & 0x1;
2136 // Trap case where we do not have a prediction. 2232 // Trap case where we do not have a prediction.
2137 if (search_range_ctrl && 2233 if (search_range_ctrl &&
2138 (left_in_image || above_in_image || cm->frame_type != KEY_FRAME)) { 2234 (left_in_image || above_in_image || cm->frame_type != KEY_FRAME)) {
2139 int block; 2235 int block;
2140 MODE_INFO *mi; 2236 MODE_INFO **mi;
2141 BLOCK_SIZE sb_type; 2237 BLOCK_SIZE sb_type;
2142 2238
2143 // Find the min and max partition sizes used in the left SB64. 2239 // Find the min and max partition sizes used in the left SB64.
2144 if (left_in_image) { 2240 if (left_in_image) {
2145 MODE_INFO *cur_mi; 2241 MODE_INFO *cur_mi;
2146 mi = mi_8x8[-1].src_mi; 2242 mi = &mi_8x8[-1];
2147 for (block = 0; block < MI_BLOCK_SIZE; ++block) { 2243 for (block = 0; block < MI_BLOCK_SIZE; ++block) {
2148 cur_mi = mi[block * xd->mi_stride].src_mi; 2244 cur_mi = mi[block * xd->mi_stride];
2149 sb_type = cur_mi ? cur_mi->mbmi.sb_type : 0; 2245 sb_type = cur_mi ? cur_mi->mbmi.sb_type : 0;
2150 min_size = MIN(min_size, sb_type); 2246 min_size = MIN(min_size, sb_type);
2151 max_size = MAX(max_size, sb_type); 2247 max_size = MAX(max_size, sb_type);
2152 } 2248 }
2153 } 2249 }
2154 // Find the min and max partition sizes used in the above SB64. 2250 // Find the min and max partition sizes used in the above SB64.
2155 if (above_in_image) { 2251 if (above_in_image) {
2156 mi = mi_8x8[-xd->mi_stride * MI_BLOCK_SIZE].src_mi; 2252 mi = &mi_8x8[-xd->mi_stride * MI_BLOCK_SIZE];
2157 for (block = 0; block < MI_BLOCK_SIZE; ++block) { 2253 for (block = 0; block < MI_BLOCK_SIZE; ++block) {
2158 sb_type = mi[block].src_mi ? mi[block].src_mi->mbmi.sb_type : 0; 2254 sb_type = mi[block] ? mi[block]->mbmi.sb_type : 0;
2159 min_size = MIN(min_size, sb_type); 2255 min_size = MIN(min_size, sb_type);
2160 max_size = MAX(max_size, sb_type); 2256 max_size = MAX(max_size, sb_type);
2161 } 2257 }
2162 } 2258 }
2163 2259
2164 min_size = min_partition_size[min_size]; 2260 min_size = min_partition_size[min_size];
2165 max_size = find_partition_size(max_size, row8x8_remaining, col8x8_remaining, 2261 max_size = find_partition_size(max_size, row8x8_remaining, col8x8_remaining,
2166 &bh, &bw); 2262 &bh, &bw);
2167 min_size = MIN(min_size, max_size); 2263 min_size = MIN(min_size, max_size);
2168 min_size = MAX(min_size, BLOCK_8X8); 2264 min_size = MAX(min_size, BLOCK_8X8);
(...skipping 10 matching lines...) Expand all
2179 // TODO(jingning) refactor functions setting partition search range 2275 // TODO(jingning) refactor functions setting partition search range
2180 static void set_partition_range(VP9_COMMON *cm, MACROBLOCKD *xd, 2276 static void set_partition_range(VP9_COMMON *cm, MACROBLOCKD *xd,
2181 int mi_row, int mi_col, BLOCK_SIZE bsize, 2277 int mi_row, int mi_col, BLOCK_SIZE bsize,
2182 BLOCK_SIZE *min_bs, BLOCK_SIZE *max_bs) { 2278 BLOCK_SIZE *min_bs, BLOCK_SIZE *max_bs) {
2183 int mi_width = num_8x8_blocks_wide_lookup[bsize]; 2279 int mi_width = num_8x8_blocks_wide_lookup[bsize];
2184 int mi_height = num_8x8_blocks_high_lookup[bsize]; 2280 int mi_height = num_8x8_blocks_high_lookup[bsize];
2185 int idx, idy; 2281 int idx, idy;
2186 2282
2187 MODE_INFO *mi; 2283 MODE_INFO *mi;
2188 const int idx_str = cm->mi_stride * mi_row + mi_col; 2284 const int idx_str = cm->mi_stride * mi_row + mi_col;
2189 MODE_INFO *prev_mi = (cm->prev_mip + cm->mi_stride + 1 + idx_str)->src_mi; 2285 MODE_INFO **prev_mi = &cm->prev_mi_grid_visible[idx_str];
2190
2191
2192 BLOCK_SIZE bs, min_size, max_size; 2286 BLOCK_SIZE bs, min_size, max_size;
2193 2287
2194 min_size = BLOCK_64X64; 2288 min_size = BLOCK_64X64;
2195 max_size = BLOCK_4X4; 2289 max_size = BLOCK_4X4;
2196 2290
2197 if (prev_mi) { 2291 if (prev_mi) {
2198 for (idy = 0; idy < mi_height; ++idy) { 2292 for (idy = 0; idy < mi_height; ++idy) {
2199 for (idx = 0; idx < mi_width; ++idx) { 2293 for (idx = 0; idx < mi_width; ++idx) {
2200 mi = prev_mi[idy * cm->mi_stride + idx].src_mi; 2294 mi = prev_mi[idy * cm->mi_stride + idx];
2201 bs = mi ? mi->mbmi.sb_type : bsize; 2295 bs = mi ? mi->mbmi.sb_type : bsize;
2202 min_size = MIN(min_size, bs); 2296 min_size = MIN(min_size, bs);
2203 max_size = MAX(max_size, bs); 2297 max_size = MAX(max_size, bs);
2204 } 2298 }
2205 } 2299 }
2206 } 2300 }
2207 2301
2208 if (xd->left_available) { 2302 if (xd->left_available) {
2209 for (idy = 0; idy < mi_height; ++idy) { 2303 for (idy = 0; idy < mi_height; ++idy) {
2210 mi = xd->mi[idy * cm->mi_stride - 1].src_mi; 2304 mi = xd->mi[idy * cm->mi_stride - 1];
2211 bs = mi ? mi->mbmi.sb_type : bsize; 2305 bs = mi ? mi->mbmi.sb_type : bsize;
2212 min_size = MIN(min_size, bs); 2306 min_size = MIN(min_size, bs);
2213 max_size = MAX(max_size, bs); 2307 max_size = MAX(max_size, bs);
2214 } 2308 }
2215 } 2309 }
2216 2310
2217 if (xd->up_available) { 2311 if (xd->up_available) {
2218 for (idx = 0; idx < mi_width; ++idx) { 2312 for (idx = 0; idx < mi_width; ++idx) {
2219 mi = xd->mi[idx - cm->mi_stride].src_mi; 2313 mi = xd->mi[idx - cm->mi_stride];
2220 bs = mi ? mi->mbmi.sb_type : bsize; 2314 bs = mi ? mi->mbmi.sb_type : bsize;
2221 min_size = MIN(min_size, bs); 2315 min_size = MIN(min_size, bs);
2222 max_size = MAX(max_size, bs); 2316 max_size = MAX(max_size, bs);
2223 } 2317 }
2224 } 2318 }
2225 2319
2226 if (min_size == max_size) { 2320 if (min_size == max_size) {
2227 min_size = min_partition_size[min_size]; 2321 min_size = min_partition_size[min_size];
2228 max_size = max_partition_size[max_size]; 2322 max_size = max_partition_size[max_size];
2229 } 2323 }
2230 2324
2231 *min_bs = min_size; 2325 *min_bs = min_size;
2232 *max_bs = max_size; 2326 *max_bs = max_size;
2233 } 2327 }
2234 2328
2235 static INLINE void store_pred_mv(MACROBLOCK *x, PICK_MODE_CONTEXT *ctx) { 2329 static INLINE void store_pred_mv(MACROBLOCK *x, PICK_MODE_CONTEXT *ctx) {
2236 vpx_memcpy(ctx->pred_mv, x->pred_mv, sizeof(x->pred_mv)); 2330 memcpy(ctx->pred_mv, x->pred_mv, sizeof(x->pred_mv));
2237 } 2331 }
2238 2332
2239 static INLINE void load_pred_mv(MACROBLOCK *x, PICK_MODE_CONTEXT *ctx) { 2333 static INLINE void load_pred_mv(MACROBLOCK *x, PICK_MODE_CONTEXT *ctx) {
2240 vpx_memcpy(x->pred_mv, ctx->pred_mv, sizeof(x->pred_mv)); 2334 memcpy(x->pred_mv, ctx->pred_mv, sizeof(x->pred_mv));
2241 } 2335 }
2242 2336
2243 #if CONFIG_FP_MB_STATS 2337 #if CONFIG_FP_MB_STATS
2244 const int num_16x16_blocks_wide_lookup[BLOCK_SIZES] = 2338 const int num_16x16_blocks_wide_lookup[BLOCK_SIZES] =
2245 {1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 4, 4}; 2339 {1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 4, 4};
2246 const int num_16x16_blocks_high_lookup[BLOCK_SIZES] = 2340 const int num_16x16_blocks_high_lookup[BLOCK_SIZES] =
2247 {1, 1, 1, 1, 1, 1, 1, 2, 1, 2, 4, 2, 4}; 2341 {1, 1, 1, 1, 1, 1, 1, 2, 1, 2, 4, 2, 4};
2248 const int qindex_skip_threshold_lookup[BLOCK_SIZES] = 2342 const int qindex_skip_threshold_lookup[BLOCK_SIZES] =
2249 {0, 10, 10, 30, 40, 40, 60, 80, 80, 90, 100, 100, 120}; 2343 {0, 10, 10, 30, 40, 40, 60, 80, 80, 90, 100, 100, 120};
2250 const int qindex_split_threshold_lookup[BLOCK_SIZES] = 2344 const int qindex_split_threshold_lookup[BLOCK_SIZES] =
(...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after
2705 int mi_row, 2799 int mi_row,
2706 TOKENEXTRA **tp) { 2800 TOKENEXTRA **tp) {
2707 VP9_COMMON *const cm = &cpi->common; 2801 VP9_COMMON *const cm = &cpi->common;
2708 TileInfo *const tile_info = &tile_data->tile_info; 2802 TileInfo *const tile_info = &tile_data->tile_info;
2709 MACROBLOCK *const x = &td->mb; 2803 MACROBLOCK *const x = &td->mb;
2710 MACROBLOCKD *const xd = &x->e_mbd; 2804 MACROBLOCKD *const xd = &x->e_mbd;
2711 SPEED_FEATURES *const sf = &cpi->sf; 2805 SPEED_FEATURES *const sf = &cpi->sf;
2712 int mi_col; 2806 int mi_col;
2713 2807
2714 // Initialize the left context for the new SB row 2808 // Initialize the left context for the new SB row
2715 vpx_memset(&xd->left_context, 0, sizeof(xd->left_context)); 2809 memset(&xd->left_context, 0, sizeof(xd->left_context));
2716 vpx_memset(xd->left_seg_context, 0, sizeof(xd->left_seg_context)); 2810 memset(xd->left_seg_context, 0, sizeof(xd->left_seg_context));
2717 2811
2718 // Code each SB in the row 2812 // Code each SB in the row
2719 for (mi_col = tile_info->mi_col_start; mi_col < tile_info->mi_col_end; 2813 for (mi_col = tile_info->mi_col_start; mi_col < tile_info->mi_col_end;
2720 mi_col += MI_BLOCK_SIZE) { 2814 mi_col += MI_BLOCK_SIZE) {
2721 const struct segmentation *const seg = &cm->seg; 2815 const struct segmentation *const seg = &cm->seg;
2722 int dummy_rate; 2816 int dummy_rate;
2723 int64_t dummy_dist; 2817 int64_t dummy_dist;
2724 RD_COST dummy_rdc; 2818 RD_COST dummy_rdc;
2725 int i; 2819 int i;
2726 int seg_skip = 0; 2820 int seg_skip = 0;
2727 2821
2728 const int idx_str = cm->mi_stride * mi_row + mi_col; 2822 const int idx_str = cm->mi_stride * mi_row + mi_col;
2729 MODE_INFO *mi = cm->mi + idx_str; 2823 MODE_INFO **mi = cm->mi_grid_visible + idx_str;
2730 2824
2731 if (sf->adaptive_pred_interp_filter) { 2825 if (sf->adaptive_pred_interp_filter) {
2732 for (i = 0; i < 64; ++i) 2826 for (i = 0; i < 64; ++i)
2733 td->leaf_tree[i].pred_interp_filter = SWITCHABLE; 2827 td->leaf_tree[i].pred_interp_filter = SWITCHABLE;
2734 2828
2735 for (i = 0; i < 64; ++i) { 2829 for (i = 0; i < 64; ++i) {
2736 td->pc_tree[i].vertical[0].pred_interp_filter = SWITCHABLE; 2830 td->pc_tree[i].vertical[0].pred_interp_filter = SWITCHABLE;
2737 td->pc_tree[i].vertical[1].pred_interp_filter = SWITCHABLE; 2831 td->pc_tree[i].vertical[1].pred_interp_filter = SWITCHABLE;
2738 td->pc_tree[i].horizontal[0].pred_interp_filter = SWITCHABLE; 2832 td->pc_tree[i].horizontal[0].pred_interp_filter = SWITCHABLE;
2739 td->pc_tree[i].horizontal[1].pred_interp_filter = SWITCHABLE; 2833 td->pc_tree[i].horizontal[1].pred_interp_filter = SWITCHABLE;
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
2790 MACROBLOCKD *const xd = &x->e_mbd; 2884 MACROBLOCKD *const xd = &x->e_mbd;
2791 const int aligned_mi_cols = mi_cols_aligned_to_sb(cm->mi_cols); 2885 const int aligned_mi_cols = mi_cols_aligned_to_sb(cm->mi_cols);
2792 2886
2793 // Copy data over into macro block data structures. 2887 // Copy data over into macro block data structures.
2794 vp9_setup_src_planes(x, cpi->Source, 0, 0); 2888 vp9_setup_src_planes(x, cpi->Source, 0, 0);
2795 2889
2796 vp9_setup_block_planes(&x->e_mbd, cm->subsampling_x, cm->subsampling_y); 2890 vp9_setup_block_planes(&x->e_mbd, cm->subsampling_x, cm->subsampling_y);
2797 2891
2798 // Note: this memset assumes above_context[0], [1] and [2] 2892 // Note: this memset assumes above_context[0], [1] and [2]
2799 // are allocated as part of the same buffer. 2893 // are allocated as part of the same buffer.
2800 vpx_memset(xd->above_context[0], 0, 2894 memset(xd->above_context[0], 0,
2801 sizeof(*xd->above_context[0]) * 2895 sizeof(*xd->above_context[0]) *
2802 2 * aligned_mi_cols * MAX_MB_PLANE); 2896 2 * aligned_mi_cols * MAX_MB_PLANE);
2803 vpx_memset(xd->above_seg_context, 0, 2897 memset(xd->above_seg_context, 0,
2804 sizeof(*xd->above_seg_context) * aligned_mi_cols); 2898 sizeof(*xd->above_seg_context) * aligned_mi_cols);
2805 } 2899 }
2806 2900
2807 static int check_dual_ref_flags(VP9_COMP *cpi) { 2901 static int check_dual_ref_flags(VP9_COMP *cpi) {
2808 const int ref_flags = cpi->ref_frame_flags; 2902 const int ref_flags = cpi->ref_frame_flags;
2809 2903
2810 if (vp9_segfeature_active(&cpi->common.seg, 1, SEG_LVL_REF_FRAME)) { 2904 if (vp9_segfeature_active(&cpi->common.seg, 1, SEG_LVL_REF_FRAME)) {
2811 return 0; 2905 return 0;
2812 } else { 2906 } else {
2813 return (!!(ref_flags & VP9_GOLD_FLAG) + !!(ref_flags & VP9_LAST_FLAG) 2907 return (!!(ref_flags & VP9_GOLD_FLAG) + !!(ref_flags & VP9_LAST_FLAG)
2814 + !!(ref_flags & VP9_ALT_FLAG)) >= 2; 2908 + !!(ref_flags & VP9_ALT_FLAG)) >= 2;
2815 } 2909 }
2816 } 2910 }
2817 2911
2818 static void reset_skip_tx_size(VP9_COMMON *cm, TX_SIZE max_tx_size) { 2912 static void reset_skip_tx_size(VP9_COMMON *cm, TX_SIZE max_tx_size) {
2819 int mi_row, mi_col; 2913 int mi_row, mi_col;
2820 const int mis = cm->mi_stride; 2914 const int mis = cm->mi_stride;
2821 MODE_INFO *mi_ptr = cm->mi; 2915 MODE_INFO **mi_ptr = cm->mi_grid_visible;
2822 2916
2823 for (mi_row = 0; mi_row < cm->mi_rows; ++mi_row, mi_ptr += mis) { 2917 for (mi_row = 0; mi_row < cm->mi_rows; ++mi_row, mi_ptr += mis) {
2824 for (mi_col = 0; mi_col < cm->mi_cols; ++mi_col) { 2918 for (mi_col = 0; mi_col < cm->mi_cols; ++mi_col) {
2825 if (mi_ptr[mi_col].src_mi->mbmi.tx_size > max_tx_size) 2919 if (mi_ptr[mi_col]->mbmi.tx_size > max_tx_size)
2826 mi_ptr[mi_col].src_mi->mbmi.tx_size = max_tx_size; 2920 mi_ptr[mi_col]->mbmi.tx_size = max_tx_size;
2827 } 2921 }
2828 } 2922 }
2829 } 2923 }
2830 2924
2831 static MV_REFERENCE_FRAME get_frame_type(const VP9_COMP *cpi) { 2925 static MV_REFERENCE_FRAME get_frame_type(const VP9_COMP *cpi) {
2832 if (frame_is_intra_only(&cpi->common)) 2926 if (frame_is_intra_only(&cpi->common))
2833 return INTRA_FRAME; 2927 return INTRA_FRAME;
2834 else if (cpi->rc.is_src_frame_alt_ref && cpi->refresh_golden_frame) 2928 else if (cpi->rc.is_src_frame_alt_ref && cpi->refresh_golden_frame)
2835 return ALTREF_FRAME; 2929 return ALTREF_FRAME;
2836 else if (cpi->refresh_golden_frame || cpi->refresh_alt_ref_frame) 2930 else if (cpi->refresh_golden_frame || cpi->refresh_alt_ref_frame)
(...skipping 29 matching lines...) Expand all
2866 2960
2867 static void nonrd_pick_sb_modes(VP9_COMP *cpi, 2961 static void nonrd_pick_sb_modes(VP9_COMP *cpi,
2868 TileDataEnc *tile_data, MACROBLOCK *const x, 2962 TileDataEnc *tile_data, MACROBLOCK *const x,
2869 int mi_row, int mi_col, RD_COST *rd_cost, 2963 int mi_row, int mi_col, RD_COST *rd_cost,
2870 BLOCK_SIZE bsize, PICK_MODE_CONTEXT *ctx) { 2964 BLOCK_SIZE bsize, PICK_MODE_CONTEXT *ctx) {
2871 VP9_COMMON *const cm = &cpi->common; 2965 VP9_COMMON *const cm = &cpi->common;
2872 TileInfo *const tile_info = &tile_data->tile_info; 2966 TileInfo *const tile_info = &tile_data->tile_info;
2873 MACROBLOCKD *const xd = &x->e_mbd; 2967 MACROBLOCKD *const xd = &x->e_mbd;
2874 MB_MODE_INFO *mbmi; 2968 MB_MODE_INFO *mbmi;
2875 set_offsets(cpi, tile_info, x, mi_row, mi_col, bsize); 2969 set_offsets(cpi, tile_info, x, mi_row, mi_col, bsize);
2876 mbmi = &xd->mi[0].src_mi->mbmi; 2970 mbmi = &xd->mi[0]->mbmi;
2877 mbmi->sb_type = bsize; 2971 mbmi->sb_type = bsize;
2878 2972
2879 if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ && cm->seg.enabled) 2973 if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ && cm->seg.enabled)
2880 if (mbmi->segment_id) 2974 if (cyclic_refresh_segment_id_boosted(mbmi->segment_id))
2881 x->rdmult = vp9_cyclic_refresh_get_rdmult(cpi->cyclic_refresh); 2975 x->rdmult = vp9_cyclic_refresh_get_rdmult(cpi->cyclic_refresh);
2882 2976
2883 if (cm->frame_type == KEY_FRAME) 2977 if (cm->frame_type == KEY_FRAME)
2884 hybrid_intra_mode_search(cpi, x, rd_cost, bsize, ctx); 2978 hybrid_intra_mode_search(cpi, x, rd_cost, bsize, ctx);
2885 else if (vp9_segfeature_active(&cm->seg, mbmi->segment_id, SEG_LVL_SKIP)) 2979 else if (vp9_segfeature_active(&cm->seg, mbmi->segment_id, SEG_LVL_SKIP))
2886 set_mode_info_seg_skip(x, cm->tx_mode, rd_cost, bsize); 2980 set_mode_info_seg_skip(x, cm->tx_mode, rd_cost, bsize);
2887 else if (bsize >= BLOCK_8X8) 2981 else if (bsize >= BLOCK_8X8)
2888 vp9_pick_inter_mode(cpi, x, tile_data, mi_row, mi_col, 2982 vp9_pick_inter_mode(cpi, x, tile_data, mi_row, mi_col,
2889 rd_cost, bsize, ctx); 2983 rd_cost, bsize, ctx);
2890 else 2984 else
(...skipping 19 matching lines...) Expand all
2910 BLOCK_SIZE subsize = get_subsize(bsize, partition); 3004 BLOCK_SIZE subsize = get_subsize(bsize, partition);
2911 3005
2912 assert(bsize >= BLOCK_8X8); 3006 assert(bsize >= BLOCK_8X8);
2913 3007
2914 if (mi_row >= cm->mi_rows || mi_col >= cm->mi_cols) 3008 if (mi_row >= cm->mi_rows || mi_col >= cm->mi_cols)
2915 return; 3009 return;
2916 3010
2917 switch (partition) { 3011 switch (partition) {
2918 case PARTITION_NONE: 3012 case PARTITION_NONE:
2919 set_mode_info_offsets(cm, xd, mi_row, mi_col); 3013 set_mode_info_offsets(cm, xd, mi_row, mi_col);
2920 *(xd->mi[0].src_mi) = pc_tree->none.mic; 3014 *(xd->mi[0]) = pc_tree->none.mic;
2921 duplicate_mode_info_in_sb(cm, xd, mi_row, mi_col, bsize); 3015 duplicate_mode_info_in_sb(cm, xd, mi_row, mi_col, bsize);
2922 break; 3016 break;
2923 case PARTITION_VERT: 3017 case PARTITION_VERT:
2924 set_mode_info_offsets(cm, xd, mi_row, mi_col); 3018 set_mode_info_offsets(cm, xd, mi_row, mi_col);
2925 *(xd->mi[0].src_mi) = pc_tree->vertical[0].mic; 3019 *(xd->mi[0]) = pc_tree->vertical[0].mic;
2926 duplicate_mode_info_in_sb(cm, xd, mi_row, mi_col, subsize); 3020 duplicate_mode_info_in_sb(cm, xd, mi_row, mi_col, subsize);
2927 3021
2928 if (mi_col + hbs < cm->mi_cols) { 3022 if (mi_col + hbs < cm->mi_cols) {
2929 set_mode_info_offsets(cm, xd, mi_row, mi_col + hbs); 3023 set_mode_info_offsets(cm, xd, mi_row, mi_col + hbs);
2930 *(xd->mi[0].src_mi) = pc_tree->vertical[1].mic; 3024 *(xd->mi[0]) = pc_tree->vertical[1].mic;
2931 duplicate_mode_info_in_sb(cm, xd, mi_row, mi_col + hbs, subsize); 3025 duplicate_mode_info_in_sb(cm, xd, mi_row, mi_col + hbs, subsize);
2932 } 3026 }
2933 break; 3027 break;
2934 case PARTITION_HORZ: 3028 case PARTITION_HORZ:
2935 set_mode_info_offsets(cm, xd, mi_row, mi_col); 3029 set_mode_info_offsets(cm, xd, mi_row, mi_col);
2936 *(xd->mi[0].src_mi) = pc_tree->horizontal[0].mic; 3030 *(xd->mi[0]) = pc_tree->horizontal[0].mic;
2937 duplicate_mode_info_in_sb(cm, xd, mi_row, mi_col, subsize); 3031 duplicate_mode_info_in_sb(cm, xd, mi_row, mi_col, subsize);
2938 if (mi_row + hbs < cm->mi_rows) { 3032 if (mi_row + hbs < cm->mi_rows) {
2939 set_mode_info_offsets(cm, xd, mi_row + hbs, mi_col); 3033 set_mode_info_offsets(cm, xd, mi_row + hbs, mi_col);
2940 *(xd->mi[0].src_mi) = pc_tree->horizontal[1].mic; 3034 *(xd->mi[0]) = pc_tree->horizontal[1].mic;
2941 duplicate_mode_info_in_sb(cm, xd, mi_row + hbs, mi_col, subsize); 3035 duplicate_mode_info_in_sb(cm, xd, mi_row + hbs, mi_col, subsize);
2942 } 3036 }
2943 break; 3037 break;
2944 case PARTITION_SPLIT: { 3038 case PARTITION_SPLIT: {
2945 fill_mode_info_sb(cm, x, mi_row, mi_col, subsize, pc_tree->split[0]); 3039 fill_mode_info_sb(cm, x, mi_row, mi_col, subsize, pc_tree->split[0]);
2946 fill_mode_info_sb(cm, x, mi_row, mi_col + hbs, subsize, 3040 fill_mode_info_sb(cm, x, mi_row, mi_col + hbs, subsize,
2947 pc_tree->split[1]); 3041 pc_tree->split[1]);
2948 fill_mode_info_sb(cm, x, mi_row + hbs, mi_col, subsize, 3042 fill_mode_info_sb(cm, x, mi_row + hbs, mi_col, subsize,
2949 pc_tree->split[2]); 3043 pc_tree->split[2]);
2950 fill_mode_info_sb(cm, x, mi_row + hbs, mi_col + hbs, subsize, 3044 fill_mode_info_sb(cm, x, mi_row + hbs, mi_col + hbs, subsize,
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
3030 } 3124 }
3031 3125
3032 ctx->pred_pixel_ready = !(partition_vert_allowed || 3126 ctx->pred_pixel_ready = !(partition_vert_allowed ||
3033 partition_horz_allowed || 3127 partition_horz_allowed ||
3034 do_split); 3128 do_split);
3035 3129
3036 // PARTITION_NONE 3130 // PARTITION_NONE
3037 if (partition_none_allowed) { 3131 if (partition_none_allowed) {
3038 nonrd_pick_sb_modes(cpi, tile_data, x, mi_row, mi_col, 3132 nonrd_pick_sb_modes(cpi, tile_data, x, mi_row, mi_col,
3039 &this_rdc, bsize, ctx); 3133 &this_rdc, bsize, ctx);
3040 ctx->mic.mbmi = xd->mi[0].src_mi->mbmi; 3134 ctx->mic.mbmi = xd->mi[0]->mbmi;
3041 ctx->skip_txfm[0] = x->skip_txfm[0]; 3135 ctx->skip_txfm[0] = x->skip_txfm[0];
3042 ctx->skip = x->skip; 3136 ctx->skip = x->skip;
3043 3137
3044 if (this_rdc.rate != INT_MAX) { 3138 if (this_rdc.rate != INT_MAX) {
3045 int pl = partition_plane_context(xd, mi_row, mi_col, bsize); 3139 int pl = partition_plane_context(xd, mi_row, mi_col, bsize);
3046 this_rdc.rate += cpi->partition_cost[pl][PARTITION_NONE]; 3140 this_rdc.rate += cpi->partition_cost[pl][PARTITION_NONE];
3047 this_rdc.rdcost = RDCOST(x->rdmult, x->rddiv, 3141 this_rdc.rdcost = RDCOST(x->rdmult, x->rddiv,
3048 this_rdc.rate, this_rdc.dist); 3142 this_rdc.rate, this_rdc.dist);
3049 if (this_rdc.rdcost < best_rdc.rdcost) { 3143 if (this_rdc.rdcost < best_rdc.rdcost) {
3050 int64_t dist_breakout_thr = sf->partition_search_breakout_dist_thr; 3144 int64_t dist_breakout_thr = sf->partition_search_breakout_dist_thr;
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
3112 3206
3113 // PARTITION_HORZ 3207 // PARTITION_HORZ
3114 if (partition_horz_allowed && do_rect) { 3208 if (partition_horz_allowed && do_rect) {
3115 subsize = get_subsize(bsize, PARTITION_HORZ); 3209 subsize = get_subsize(bsize, PARTITION_HORZ);
3116 if (sf->adaptive_motion_search) 3210 if (sf->adaptive_motion_search)
3117 load_pred_mv(x, ctx); 3211 load_pred_mv(x, ctx);
3118 pc_tree->horizontal[0].pred_pixel_ready = 1; 3212 pc_tree->horizontal[0].pred_pixel_ready = 1;
3119 nonrd_pick_sb_modes(cpi, tile_data, x, mi_row, mi_col, &sum_rdc, subsize, 3213 nonrd_pick_sb_modes(cpi, tile_data, x, mi_row, mi_col, &sum_rdc, subsize,
3120 &pc_tree->horizontal[0]); 3214 &pc_tree->horizontal[0]);
3121 3215
3122 pc_tree->horizontal[0].mic.mbmi = xd->mi[0].src_mi->mbmi; 3216 pc_tree->horizontal[0].mic.mbmi = xd->mi[0]->mbmi;
3123 pc_tree->horizontal[0].skip_txfm[0] = x->skip_txfm[0]; 3217 pc_tree->horizontal[0].skip_txfm[0] = x->skip_txfm[0];
3124 pc_tree->horizontal[0].skip = x->skip; 3218 pc_tree->horizontal[0].skip = x->skip;
3125 3219
3126 if (sum_rdc.rdcost < best_rdc.rdcost && mi_row + ms < cm->mi_rows) { 3220 if (sum_rdc.rdcost < best_rdc.rdcost && mi_row + ms < cm->mi_rows) {
3127 load_pred_mv(x, ctx); 3221 load_pred_mv(x, ctx);
3128 pc_tree->horizontal[1].pred_pixel_ready = 1; 3222 pc_tree->horizontal[1].pred_pixel_ready = 1;
3129 nonrd_pick_sb_modes(cpi, tile_data, x, mi_row + ms, mi_col, 3223 nonrd_pick_sb_modes(cpi, tile_data, x, mi_row + ms, mi_col,
3130 &this_rdc, subsize, 3224 &this_rdc, subsize,
3131 &pc_tree->horizontal[1]); 3225 &pc_tree->horizontal[1]);
3132 3226
3133 pc_tree->horizontal[1].mic.mbmi = xd->mi[0].src_mi->mbmi; 3227 pc_tree->horizontal[1].mic.mbmi = xd->mi[0]->mbmi;
3134 pc_tree->horizontal[1].skip_txfm[0] = x->skip_txfm[0]; 3228 pc_tree->horizontal[1].skip_txfm[0] = x->skip_txfm[0];
3135 pc_tree->horizontal[1].skip = x->skip; 3229 pc_tree->horizontal[1].skip = x->skip;
3136 3230
3137 if (this_rdc.rate == INT_MAX) { 3231 if (this_rdc.rate == INT_MAX) {
3138 vp9_rd_cost_reset(&sum_rdc); 3232 vp9_rd_cost_reset(&sum_rdc);
3139 } else { 3233 } else {
3140 int pl = partition_plane_context(xd, mi_row, mi_col, bsize); 3234 int pl = partition_plane_context(xd, mi_row, mi_col, bsize);
3141 this_rdc.rate += cpi->partition_cost[pl][PARTITION_HORZ]; 3235 this_rdc.rate += cpi->partition_cost[pl][PARTITION_HORZ];
3142 sum_rdc.rate += this_rdc.rate; 3236 sum_rdc.rate += this_rdc.rate;
3143 sum_rdc.dist += this_rdc.dist; 3237 sum_rdc.dist += this_rdc.dist;
(...skipping 11 matching lines...) Expand all
3155 } 3249 }
3156 3250
3157 // PARTITION_VERT 3251 // PARTITION_VERT
3158 if (partition_vert_allowed && do_rect) { 3252 if (partition_vert_allowed && do_rect) {
3159 subsize = get_subsize(bsize, PARTITION_VERT); 3253 subsize = get_subsize(bsize, PARTITION_VERT);
3160 if (sf->adaptive_motion_search) 3254 if (sf->adaptive_motion_search)
3161 load_pred_mv(x, ctx); 3255 load_pred_mv(x, ctx);
3162 pc_tree->vertical[0].pred_pixel_ready = 1; 3256 pc_tree->vertical[0].pred_pixel_ready = 1;
3163 nonrd_pick_sb_modes(cpi, tile_data, x, mi_row, mi_col, &sum_rdc, subsize, 3257 nonrd_pick_sb_modes(cpi, tile_data, x, mi_row, mi_col, &sum_rdc, subsize,
3164 &pc_tree->vertical[0]); 3258 &pc_tree->vertical[0]);
3165 pc_tree->vertical[0].mic.mbmi = xd->mi[0].src_mi->mbmi; 3259 pc_tree->vertical[0].mic.mbmi = xd->mi[0]->mbmi;
3166 pc_tree->vertical[0].skip_txfm[0] = x->skip_txfm[0]; 3260 pc_tree->vertical[0].skip_txfm[0] = x->skip_txfm[0];
3167 pc_tree->vertical[0].skip = x->skip; 3261 pc_tree->vertical[0].skip = x->skip;
3168 3262
3169 if (sum_rdc.rdcost < best_rdc.rdcost && mi_col + ms < cm->mi_cols) { 3263 if (sum_rdc.rdcost < best_rdc.rdcost && mi_col + ms < cm->mi_cols) {
3170 load_pred_mv(x, ctx); 3264 load_pred_mv(x, ctx);
3171 pc_tree->vertical[1].pred_pixel_ready = 1; 3265 pc_tree->vertical[1].pred_pixel_ready = 1;
3172 nonrd_pick_sb_modes(cpi, tile_data, x, mi_row, mi_col + ms, 3266 nonrd_pick_sb_modes(cpi, tile_data, x, mi_row, mi_col + ms,
3173 &this_rdc, subsize, 3267 &this_rdc, subsize,
3174 &pc_tree->vertical[1]); 3268 &pc_tree->vertical[1]);
3175 pc_tree->vertical[1].mic.mbmi = xd->mi[0].src_mi->mbmi; 3269 pc_tree->vertical[1].mic.mbmi = xd->mi[0]->mbmi;
3176 pc_tree->vertical[1].skip_txfm[0] = x->skip_txfm[0]; 3270 pc_tree->vertical[1].skip_txfm[0] = x->skip_txfm[0];
3177 pc_tree->vertical[1].skip = x->skip; 3271 pc_tree->vertical[1].skip = x->skip;
3178 3272
3179 if (this_rdc.rate == INT_MAX) { 3273 if (this_rdc.rate == INT_MAX) {
3180 vp9_rd_cost_reset(&sum_rdc); 3274 vp9_rd_cost_reset(&sum_rdc);
3181 } else { 3275 } else {
3182 int pl = partition_plane_context(xd, mi_row, mi_col, bsize); 3276 int pl = partition_plane_context(xd, mi_row, mi_col, bsize);
3183 sum_rdc.rate += cpi->partition_cost[pl][PARTITION_VERT]; 3277 sum_rdc.rate += cpi->partition_cost[pl][PARTITION_VERT];
3184 sum_rdc.rate += this_rdc.rate; 3278 sum_rdc.rate += this_rdc.rate;
3185 sum_rdc.dist += this_rdc.dist; 3279 sum_rdc.dist += this_rdc.dist;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
3217 assert(best_rdc.rate < INT_MAX); 3311 assert(best_rdc.rate < INT_MAX);
3218 assert(best_rdc.dist < INT64_MAX); 3312 assert(best_rdc.dist < INT64_MAX);
3219 } else { 3313 } else {
3220 assert(tp_orig == *tp); 3314 assert(tp_orig == *tp);
3221 } 3315 }
3222 } 3316 }
3223 3317
3224 static void nonrd_select_partition(VP9_COMP *cpi, 3318 static void nonrd_select_partition(VP9_COMP *cpi,
3225 ThreadData *td, 3319 ThreadData *td,
3226 TileDataEnc *tile_data, 3320 TileDataEnc *tile_data,
3227 MODE_INFO *mi, 3321 MODE_INFO **mi,
3228 TOKENEXTRA **tp, 3322 TOKENEXTRA **tp,
3229 int mi_row, int mi_col, 3323 int mi_row, int mi_col,
3230 BLOCK_SIZE bsize, int output_enabled, 3324 BLOCK_SIZE bsize, int output_enabled,
3231 RD_COST *rd_cost, PC_TREE *pc_tree) { 3325 RD_COST *rd_cost, PC_TREE *pc_tree) {
3232 VP9_COMMON *const cm = &cpi->common; 3326 VP9_COMMON *const cm = &cpi->common;
3233 TileInfo *const tile_info = &tile_data->tile_info; 3327 TileInfo *const tile_info = &tile_data->tile_info;
3234 MACROBLOCK *const x = &td->mb; 3328 MACROBLOCK *const x = &td->mb;
3235 MACROBLOCKD *const xd = &x->e_mbd; 3329 MACROBLOCKD *const xd = &x->e_mbd;
3236 const int bsl = b_width_log2_lookup[bsize], hbs = (1 << bsl) / 4; 3330 const int bsl = b_width_log2_lookup[bsize], hbs = (1 << bsl) / 4;
3237 const int mis = cm->mi_stride; 3331 const int mis = cm->mi_stride;
3238 PARTITION_TYPE partition; 3332 PARTITION_TYPE partition;
3239 BLOCK_SIZE subsize; 3333 BLOCK_SIZE subsize;
3240 RD_COST this_rdc; 3334 RD_COST this_rdc;
3241 3335
3242 vp9_rd_cost_reset(&this_rdc); 3336 vp9_rd_cost_reset(&this_rdc);
3243 if (mi_row >= cm->mi_rows || mi_col >= cm->mi_cols) 3337 if (mi_row >= cm->mi_rows || mi_col >= cm->mi_cols)
3244 return; 3338 return;
3245 3339
3246 subsize = (bsize >= BLOCK_8X8) ? mi[0].src_mi->mbmi.sb_type : BLOCK_4X4; 3340 subsize = (bsize >= BLOCK_8X8) ? mi[0]->mbmi.sb_type : BLOCK_4X4;
3247 partition = partition_lookup[bsl][subsize]; 3341 partition = partition_lookup[bsl][subsize];
3248 3342
3249 if (bsize == BLOCK_32X32 && partition != PARTITION_NONE && 3343 if (bsize == BLOCK_32X32 && partition != PARTITION_NONE &&
3250 subsize >= BLOCK_16X16) { 3344 subsize >= BLOCK_16X16) {
3251 x->max_partition_size = BLOCK_32X32; 3345 x->max_partition_size = BLOCK_32X32;
3252 x->min_partition_size = BLOCK_8X8; 3346 x->min_partition_size = BLOCK_8X8;
3253 nonrd_pick_partition(cpi, td, tile_data, tp, mi_row, mi_col, bsize, 3347 nonrd_pick_partition(cpi, td, tile_data, tp, mi_row, mi_col, bsize,
3254 rd_cost, 0, INT64_MAX, pc_tree); 3348 rd_cost, 0, INT64_MAX, pc_tree);
3255 } else if (bsize == BLOCK_16X16 && partition != PARTITION_NONE) { 3349 } else if (bsize == BLOCK_16X16 && partition != PARTITION_NONE) {
3256 x->max_partition_size = BLOCK_16X16; 3350 x->max_partition_size = BLOCK_16X16;
3257 x->min_partition_size = BLOCK_8X8; 3351 x->min_partition_size = BLOCK_8X8;
3258 nonrd_pick_partition(cpi, td, tile_data, tp, mi_row, mi_col, bsize, 3352 nonrd_pick_partition(cpi, td, tile_data, tp, mi_row, mi_col, bsize,
3259 rd_cost, 0, INT64_MAX, pc_tree); 3353 rd_cost, 0, INT64_MAX, pc_tree);
3260 } else { 3354 } else {
3261 switch (partition) { 3355 switch (partition) {
3262 case PARTITION_NONE: 3356 case PARTITION_NONE:
3263 pc_tree->none.pred_pixel_ready = 1; 3357 pc_tree->none.pred_pixel_ready = 1;
3264 nonrd_pick_sb_modes(cpi, tile_data, x, mi_row, mi_col, rd_cost, 3358 nonrd_pick_sb_modes(cpi, tile_data, x, mi_row, mi_col, rd_cost,
3265 subsize, &pc_tree->none); 3359 subsize, &pc_tree->none);
3266 pc_tree->none.mic.mbmi = xd->mi[0].src_mi->mbmi; 3360 pc_tree->none.mic.mbmi = xd->mi[0]->mbmi;
3267 pc_tree->none.skip_txfm[0] = x->skip_txfm[0]; 3361 pc_tree->none.skip_txfm[0] = x->skip_txfm[0];
3268 pc_tree->none.skip = x->skip; 3362 pc_tree->none.skip = x->skip;
3269 break; 3363 break;
3270 case PARTITION_VERT: 3364 case PARTITION_VERT:
3271 pc_tree->vertical[0].pred_pixel_ready = 1; 3365 pc_tree->vertical[0].pred_pixel_ready = 1;
3272 nonrd_pick_sb_modes(cpi, tile_data, x, mi_row, mi_col, rd_cost, 3366 nonrd_pick_sb_modes(cpi, tile_data, x, mi_row, mi_col, rd_cost,
3273 subsize, &pc_tree->vertical[0]); 3367 subsize, &pc_tree->vertical[0]);
3274 pc_tree->vertical[0].mic.mbmi = xd->mi[0].src_mi->mbmi; 3368 pc_tree->vertical[0].mic.mbmi = xd->mi[0]->mbmi;
3275 pc_tree->vertical[0].skip_txfm[0] = x->skip_txfm[0]; 3369 pc_tree->vertical[0].skip_txfm[0] = x->skip_txfm[0];
3276 pc_tree->vertical[0].skip = x->skip; 3370 pc_tree->vertical[0].skip = x->skip;
3277 if (mi_col + hbs < cm->mi_cols) { 3371 if (mi_col + hbs < cm->mi_cols) {
3278 pc_tree->vertical[1].pred_pixel_ready = 1; 3372 pc_tree->vertical[1].pred_pixel_ready = 1;
3279 nonrd_pick_sb_modes(cpi, tile_data, x, mi_row, mi_col + hbs, 3373 nonrd_pick_sb_modes(cpi, tile_data, x, mi_row, mi_col + hbs,
3280 &this_rdc, subsize, &pc_tree->vertical[1]); 3374 &this_rdc, subsize, &pc_tree->vertical[1]);
3281 pc_tree->vertical[1].mic.mbmi = xd->mi[0].src_mi->mbmi; 3375 pc_tree->vertical[1].mic.mbmi = xd->mi[0]->mbmi;
3282 pc_tree->vertical[1].skip_txfm[0] = x->skip_txfm[0]; 3376 pc_tree->vertical[1].skip_txfm[0] = x->skip_txfm[0];
3283 pc_tree->vertical[1].skip = x->skip; 3377 pc_tree->vertical[1].skip = x->skip;
3284 if (this_rdc.rate != INT_MAX && this_rdc.dist != INT64_MAX && 3378 if (this_rdc.rate != INT_MAX && this_rdc.dist != INT64_MAX &&
3285 rd_cost->rate != INT_MAX && rd_cost->dist != INT64_MAX) { 3379 rd_cost->rate != INT_MAX && rd_cost->dist != INT64_MAX) {
3286 rd_cost->rate += this_rdc.rate; 3380 rd_cost->rate += this_rdc.rate;
3287 rd_cost->dist += this_rdc.dist; 3381 rd_cost->dist += this_rdc.dist;
3288 } 3382 }
3289 } 3383 }
3290 break; 3384 break;
3291 case PARTITION_HORZ: 3385 case PARTITION_HORZ:
3292 pc_tree->horizontal[0].pred_pixel_ready = 1; 3386 pc_tree->horizontal[0].pred_pixel_ready = 1;
3293 nonrd_pick_sb_modes(cpi, tile_data, x, mi_row, mi_col, rd_cost, 3387 nonrd_pick_sb_modes(cpi, tile_data, x, mi_row, mi_col, rd_cost,
3294 subsize, &pc_tree->horizontal[0]); 3388 subsize, &pc_tree->horizontal[0]);
3295 pc_tree->horizontal[0].mic.mbmi = xd->mi[0].src_mi->mbmi; 3389 pc_tree->horizontal[0].mic.mbmi = xd->mi[0]->mbmi;
3296 pc_tree->horizontal[0].skip_txfm[0] = x->skip_txfm[0]; 3390 pc_tree->horizontal[0].skip_txfm[0] = x->skip_txfm[0];
3297 pc_tree->horizontal[0].skip = x->skip; 3391 pc_tree->horizontal[0].skip = x->skip;
3298 if (mi_row + hbs < cm->mi_rows) { 3392 if (mi_row + hbs < cm->mi_rows) {
3299 pc_tree->horizontal[1].pred_pixel_ready = 1; 3393 pc_tree->horizontal[1].pred_pixel_ready = 1;
3300 nonrd_pick_sb_modes(cpi, tile_data, x, mi_row + hbs, mi_col, 3394 nonrd_pick_sb_modes(cpi, tile_data, x, mi_row + hbs, mi_col,
3301 &this_rdc, subsize, &pc_tree->horizontal[1]); 3395 &this_rdc, subsize, &pc_tree->horizontal[1]);
3302 pc_tree->horizontal[1].mic.mbmi = xd->mi[0].src_mi->mbmi; 3396 pc_tree->horizontal[1].mic.mbmi = xd->mi[0]->mbmi;
3303 pc_tree->horizontal[1].skip_txfm[0] = x->skip_txfm[0]; 3397 pc_tree->horizontal[1].skip_txfm[0] = x->skip_txfm[0];
3304 pc_tree->horizontal[1].skip = x->skip; 3398 pc_tree->horizontal[1].skip = x->skip;
3305 if (this_rdc.rate != INT_MAX && this_rdc.dist != INT64_MAX && 3399 if (this_rdc.rate != INT_MAX && this_rdc.dist != INT64_MAX &&
3306 rd_cost->rate != INT_MAX && rd_cost->dist != INT64_MAX) { 3400 rd_cost->rate != INT_MAX && rd_cost->dist != INT64_MAX) {
3307 rd_cost->rate += this_rdc.rate; 3401 rd_cost->rate += this_rdc.rate;
3308 rd_cost->dist += this_rdc.dist; 3402 rd_cost->dist += this_rdc.dist;
3309 } 3403 }
3310 } 3404 }
3311 break; 3405 break;
3312 case PARTITION_SPLIT: 3406 case PARTITION_SPLIT:
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
3346 } 3440 }
3347 3441
3348 if (bsize == BLOCK_64X64 && output_enabled) 3442 if (bsize == BLOCK_64X64 && output_enabled)
3349 encode_sb_rt(cpi, td, tile_info, tp, mi_row, mi_col, 1, bsize, pc_tree); 3443 encode_sb_rt(cpi, td, tile_info, tp, mi_row, mi_col, 1, bsize, pc_tree);
3350 } 3444 }
3351 3445
3352 3446
3353 static void nonrd_use_partition(VP9_COMP *cpi, 3447 static void nonrd_use_partition(VP9_COMP *cpi,
3354 ThreadData *td, 3448 ThreadData *td,
3355 TileDataEnc *tile_data, 3449 TileDataEnc *tile_data,
3356 MODE_INFO *mi, 3450 MODE_INFO **mi,
3357 TOKENEXTRA **tp, 3451 TOKENEXTRA **tp,
3358 int mi_row, int mi_col, 3452 int mi_row, int mi_col,
3359 BLOCK_SIZE bsize, int output_enabled, 3453 BLOCK_SIZE bsize, int output_enabled,
3360 RD_COST *dummy_cost, PC_TREE *pc_tree) { 3454 RD_COST *dummy_cost, PC_TREE *pc_tree) {
3361 VP9_COMMON *const cm = &cpi->common; 3455 VP9_COMMON *const cm = &cpi->common;
3362 TileInfo *tile_info = &tile_data->tile_info; 3456 TileInfo *tile_info = &tile_data->tile_info;
3363 MACROBLOCK *const x = &td->mb; 3457 MACROBLOCK *const x = &td->mb;
3364 MACROBLOCKD *const xd = &x->e_mbd; 3458 MACROBLOCKD *const xd = &x->e_mbd;
3365 const int bsl = b_width_log2_lookup[bsize], hbs = (1 << bsl) / 4; 3459 const int bsl = b_width_log2_lookup[bsize], hbs = (1 << bsl) / 4;
3366 const int mis = cm->mi_stride; 3460 const int mis = cm->mi_stride;
3367 PARTITION_TYPE partition; 3461 PARTITION_TYPE partition;
3368 BLOCK_SIZE subsize; 3462 BLOCK_SIZE subsize;
3369 3463
3370 if (mi_row >= cm->mi_rows || mi_col >= cm->mi_cols) 3464 if (mi_row >= cm->mi_rows || mi_col >= cm->mi_cols)
3371 return; 3465 return;
3372 3466
3373 subsize = (bsize >= BLOCK_8X8) ? mi[0].src_mi->mbmi.sb_type : BLOCK_4X4; 3467 subsize = (bsize >= BLOCK_8X8) ? mi[0]->mbmi.sb_type : BLOCK_4X4;
3374 partition = partition_lookup[bsl][subsize]; 3468 partition = partition_lookup[bsl][subsize];
3375 3469
3376 if (output_enabled && bsize != BLOCK_4X4) { 3470 if (output_enabled && bsize != BLOCK_4X4) {
3377 int ctx = partition_plane_context(xd, mi_row, mi_col, bsize); 3471 int ctx = partition_plane_context(xd, mi_row, mi_col, bsize);
3378 td->counts->partition[ctx][partition]++; 3472 td->counts->partition[ctx][partition]++;
3379 } 3473 }
3380 3474
3381 switch (partition) { 3475 switch (partition) {
3382 case PARTITION_NONE: 3476 case PARTITION_NONE:
3383 pc_tree->none.pred_pixel_ready = 1; 3477 pc_tree->none.pred_pixel_ready = 1;
3384 nonrd_pick_sb_modes(cpi, tile_data, x, mi_row, mi_col, dummy_cost, 3478 nonrd_pick_sb_modes(cpi, tile_data, x, mi_row, mi_col, dummy_cost,
3385 subsize, &pc_tree->none); 3479 subsize, &pc_tree->none);
3386 pc_tree->none.mic.mbmi = xd->mi[0].src_mi->mbmi; 3480 pc_tree->none.mic.mbmi = xd->mi[0]->mbmi;
3387 pc_tree->none.skip_txfm[0] = x->skip_txfm[0]; 3481 pc_tree->none.skip_txfm[0] = x->skip_txfm[0];
3388 pc_tree->none.skip = x->skip; 3482 pc_tree->none.skip = x->skip;
3389 encode_b_rt(cpi, td, tile_info, tp, mi_row, mi_col, output_enabled, 3483 encode_b_rt(cpi, td, tile_info, tp, mi_row, mi_col, output_enabled,
3390 subsize, &pc_tree->none); 3484 subsize, &pc_tree->none);
3391 break; 3485 break;
3392 case PARTITION_VERT: 3486 case PARTITION_VERT:
3393 pc_tree->vertical[0].pred_pixel_ready = 1; 3487 pc_tree->vertical[0].pred_pixel_ready = 1;
3394 nonrd_pick_sb_modes(cpi, tile_data, x, mi_row, mi_col, dummy_cost, 3488 nonrd_pick_sb_modes(cpi, tile_data, x, mi_row, mi_col, dummy_cost,
3395 subsize, &pc_tree->vertical[0]); 3489 subsize, &pc_tree->vertical[0]);
3396 pc_tree->vertical[0].mic.mbmi = xd->mi[0].src_mi->mbmi; 3490 pc_tree->vertical[0].mic.mbmi = xd->mi[0]->mbmi;
3397 pc_tree->vertical[0].skip_txfm[0] = x->skip_txfm[0]; 3491 pc_tree->vertical[0].skip_txfm[0] = x->skip_txfm[0];
3398 pc_tree->vertical[0].skip = x->skip; 3492 pc_tree->vertical[0].skip = x->skip;
3399 encode_b_rt(cpi, td, tile_info, tp, mi_row, mi_col, output_enabled, 3493 encode_b_rt(cpi, td, tile_info, tp, mi_row, mi_col, output_enabled,
3400 subsize, &pc_tree->vertical[0]); 3494 subsize, &pc_tree->vertical[0]);
3401 if (mi_col + hbs < cm->mi_cols && bsize > BLOCK_8X8) { 3495 if (mi_col + hbs < cm->mi_cols && bsize > BLOCK_8X8) {
3402 pc_tree->vertical[1].pred_pixel_ready = 1; 3496 pc_tree->vertical[1].pred_pixel_ready = 1;
3403 nonrd_pick_sb_modes(cpi, tile_data, x, mi_row, mi_col + hbs, 3497 nonrd_pick_sb_modes(cpi, tile_data, x, mi_row, mi_col + hbs,
3404 dummy_cost, subsize, &pc_tree->vertical[1]); 3498 dummy_cost, subsize, &pc_tree->vertical[1]);
3405 pc_tree->vertical[1].mic.mbmi = xd->mi[0].src_mi->mbmi; 3499 pc_tree->vertical[1].mic.mbmi = xd->mi[0]->mbmi;
3406 pc_tree->vertical[1].skip_txfm[0] = x->skip_txfm[0]; 3500 pc_tree->vertical[1].skip_txfm[0] = x->skip_txfm[0];
3407 pc_tree->vertical[1].skip = x->skip; 3501 pc_tree->vertical[1].skip = x->skip;
3408 encode_b_rt(cpi, td, tile_info, tp, mi_row, mi_col + hbs, 3502 encode_b_rt(cpi, td, tile_info, tp, mi_row, mi_col + hbs,
3409 output_enabled, subsize, &pc_tree->vertical[1]); 3503 output_enabled, subsize, &pc_tree->vertical[1]);
3410 } 3504 }
3411 break; 3505 break;
3412 case PARTITION_HORZ: 3506 case PARTITION_HORZ:
3413 pc_tree->horizontal[0].pred_pixel_ready = 1; 3507 pc_tree->horizontal[0].pred_pixel_ready = 1;
3414 nonrd_pick_sb_modes(cpi, tile_data, x, mi_row, mi_col, dummy_cost, 3508 nonrd_pick_sb_modes(cpi, tile_data, x, mi_row, mi_col, dummy_cost,
3415 subsize, &pc_tree->horizontal[0]); 3509 subsize, &pc_tree->horizontal[0]);
3416 pc_tree->horizontal[0].mic.mbmi = xd->mi[0].src_mi->mbmi; 3510 pc_tree->horizontal[0].mic.mbmi = xd->mi[0]->mbmi;
3417 pc_tree->horizontal[0].skip_txfm[0] = x->skip_txfm[0]; 3511 pc_tree->horizontal[0].skip_txfm[0] = x->skip_txfm[0];
3418 pc_tree->horizontal[0].skip = x->skip; 3512 pc_tree->horizontal[0].skip = x->skip;
3419 encode_b_rt(cpi, td, tile_info, tp, mi_row, mi_col, output_enabled, 3513 encode_b_rt(cpi, td, tile_info, tp, mi_row, mi_col, output_enabled,
3420 subsize, &pc_tree->horizontal[0]); 3514 subsize, &pc_tree->horizontal[0]);
3421 3515
3422 if (mi_row + hbs < cm->mi_rows && bsize > BLOCK_8X8) { 3516 if (mi_row + hbs < cm->mi_rows && bsize > BLOCK_8X8) {
3423 pc_tree->horizontal[1].pred_pixel_ready = 1; 3517 pc_tree->horizontal[1].pred_pixel_ready = 1;
3424 nonrd_pick_sb_modes(cpi, tile_data, x, mi_row + hbs, mi_col, 3518 nonrd_pick_sb_modes(cpi, tile_data, x, mi_row + hbs, mi_col,
3425 dummy_cost, subsize, &pc_tree->horizontal[1]); 3519 dummy_cost, subsize, &pc_tree->horizontal[1]);
3426 pc_tree->horizontal[1].mic.mbmi = xd->mi[0].src_mi->mbmi; 3520 pc_tree->horizontal[1].mic.mbmi = xd->mi[0]->mbmi;
3427 pc_tree->horizontal[1].skip_txfm[0] = x->skip_txfm[0]; 3521 pc_tree->horizontal[1].skip_txfm[0] = x->skip_txfm[0];
3428 pc_tree->horizontal[1].skip = x->skip; 3522 pc_tree->horizontal[1].skip = x->skip;
3429 encode_b_rt(cpi, td, tile_info, tp, mi_row + hbs, mi_col, 3523 encode_b_rt(cpi, td, tile_info, tp, mi_row + hbs, mi_col,
3430 output_enabled, subsize, &pc_tree->horizontal[1]); 3524 output_enabled, subsize, &pc_tree->horizontal[1]);
3431 } 3525 }
3432 break; 3526 break;
3433 case PARTITION_SPLIT: 3527 case PARTITION_SPLIT:
3434 subsize = get_subsize(bsize, PARTITION_SPLIT); 3528 subsize = get_subsize(bsize, PARTITION_SPLIT);
3435 if (bsize == BLOCK_8X8) { 3529 if (bsize == BLOCK_8X8) {
3436 nonrd_pick_sb_modes(cpi, tile_data, x, mi_row, mi_col, dummy_cost, 3530 nonrd_pick_sb_modes(cpi, tile_data, x, mi_row, mi_col, dummy_cost,
(...skipping 30 matching lines...) Expand all
3467 int mi_row, 3561 int mi_row,
3468 TOKENEXTRA **tp) { 3562 TOKENEXTRA **tp) {
3469 SPEED_FEATURES *const sf = &cpi->sf; 3563 SPEED_FEATURES *const sf = &cpi->sf;
3470 VP9_COMMON *const cm = &cpi->common; 3564 VP9_COMMON *const cm = &cpi->common;
3471 TileInfo *const tile_info = &tile_data->tile_info; 3565 TileInfo *const tile_info = &tile_data->tile_info;
3472 MACROBLOCK *const x = &td->mb; 3566 MACROBLOCK *const x = &td->mb;
3473 MACROBLOCKD *const xd = &x->e_mbd; 3567 MACROBLOCKD *const xd = &x->e_mbd;
3474 int mi_col; 3568 int mi_col;
3475 3569
3476 // Initialize the left context for the new SB row 3570 // Initialize the left context for the new SB row
3477 vpx_memset(&xd->left_context, 0, sizeof(xd->left_context)); 3571 memset(&xd->left_context, 0, sizeof(xd->left_context));
3478 vpx_memset(xd->left_seg_context, 0, sizeof(xd->left_seg_context)); 3572 memset(xd->left_seg_context, 0, sizeof(xd->left_seg_context));
3479 3573
3480 // Code each SB in the row 3574 // Code each SB in the row
3481 for (mi_col = tile_info->mi_col_start; mi_col < tile_info->mi_col_end; 3575 for (mi_col = tile_info->mi_col_start; mi_col < tile_info->mi_col_end;
3482 mi_col += MI_BLOCK_SIZE) { 3576 mi_col += MI_BLOCK_SIZE) {
3483 const struct segmentation *const seg = &cm->seg; 3577 const struct segmentation *const seg = &cm->seg;
3484 RD_COST dummy_rdc; 3578 RD_COST dummy_rdc;
3485 const int idx_str = cm->mi_stride * mi_row + mi_col; 3579 const int idx_str = cm->mi_stride * mi_row + mi_col;
3486 MODE_INFO *mi = cm->mi + idx_str; 3580 MODE_INFO **mi = cm->mi_grid_visible + idx_str;
3487 PARTITION_SEARCH_TYPE partition_search_type = sf->partition_search_type; 3581 PARTITION_SEARCH_TYPE partition_search_type = sf->partition_search_type;
3488 BLOCK_SIZE bsize = BLOCK_64X64; 3582 BLOCK_SIZE bsize = BLOCK_64X64;
3489 int seg_skip = 0; 3583 int seg_skip = 0;
3490 x->source_variance = UINT_MAX; 3584 x->source_variance = UINT_MAX;
3491 vp9_zero(x->pred_mv); 3585 vp9_zero(x->pred_mv);
3492 vp9_rd_cost_init(&dummy_rdc); 3586 vp9_rd_cost_init(&dummy_rdc);
3493 x->color_sensitivity[0] = 0; 3587 x->color_sensitivity[0] = 0;
3494 x->color_sensitivity[1] = 0; 3588 x->color_sensitivity[1] = 0;
3495 3589
3496 if (seg->enabled) { 3590 if (seg->enabled) {
(...skipping 25 matching lines...) Expand all
3522 case FIXED_PARTITION: 3616 case FIXED_PARTITION:
3523 if (!seg_skip) 3617 if (!seg_skip)
3524 bsize = sf->always_this_block_size; 3618 bsize = sf->always_this_block_size;
3525 set_fixed_partitioning(cpi, tile_info, mi, mi_row, mi_col, bsize); 3619 set_fixed_partitioning(cpi, tile_info, mi, mi_row, mi_col, bsize);
3526 nonrd_use_partition(cpi, td, tile_data, mi, tp, mi_row, mi_col, 3620 nonrd_use_partition(cpi, td, tile_data, mi, tp, mi_row, mi_col,
3527 BLOCK_64X64, 1, &dummy_rdc, td->pc_root); 3621 BLOCK_64X64, 1, &dummy_rdc, td->pc_root);
3528 break; 3622 break;
3529 case REFERENCE_PARTITION: 3623 case REFERENCE_PARTITION:
3530 set_offsets(cpi, tile_info, x, mi_row, mi_col, BLOCK_64X64); 3624 set_offsets(cpi, tile_info, x, mi_row, mi_col, BLOCK_64X64);
3531 if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ && cm->seg.enabled && 3625 if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ && cm->seg.enabled &&
3532 xd->mi[0].src_mi->mbmi.segment_id) { 3626 xd->mi[0]->mbmi.segment_id) {
3533 x->max_partition_size = BLOCK_64X64; 3627 x->max_partition_size = BLOCK_64X64;
3534 x->min_partition_size = BLOCK_8X8; 3628 x->min_partition_size = BLOCK_8X8;
3535 nonrd_pick_partition(cpi, td, tile_data, tp, mi_row, mi_col, 3629 nonrd_pick_partition(cpi, td, tile_data, tp, mi_row, mi_col,
3536 BLOCK_64X64, &dummy_rdc, 1, 3630 BLOCK_64X64, &dummy_rdc, 1,
3537 INT64_MAX, td->pc_root); 3631 INT64_MAX, td->pc_root);
3538 } else { 3632 } else {
3539 choose_partitioning(cpi, tile_info, x, mi_row, mi_col); 3633 choose_partitioning(cpi, tile_info, x, mi_row, mi_col);
3540 nonrd_select_partition(cpi, td, tile_data, mi, tp, mi_row, mi_col, 3634 nonrd_select_partition(cpi, td, tile_data, mi, tp, mi_row, mi_col,
3541 BLOCK_64X64, 1, &dummy_rdc, td->pc_root); 3635 BLOCK_64X64, 1, &dummy_rdc, td->pc_root);
3542 } 3636 }
(...skipping 13 matching lines...) Expand all
3556 3650
3557 const uint8_t *src = cpi->Source->y_buffer; 3651 const uint8_t *src = cpi->Source->y_buffer;
3558 const uint8_t *last_src = cpi->Last_Source->y_buffer; 3652 const uint8_t *last_src = cpi->Last_Source->y_buffer;
3559 const int src_stride = cpi->Source->y_stride; 3653 const int src_stride = cpi->Source->y_stride;
3560 const int last_stride = cpi->Last_Source->y_stride; 3654 const int last_stride = cpi->Last_Source->y_stride;
3561 3655
3562 // Pick cutoff threshold 3656 // Pick cutoff threshold
3563 const int cutoff = (MIN(cm->width, cm->height) >= 720) ? 3657 const int cutoff = (MIN(cm->width, cm->height) >= 720) ?
3564 (cm->MBs * VAR_HIST_LARGE_CUT_OFF / 100) : 3658 (cm->MBs * VAR_HIST_LARGE_CUT_OFF / 100) :
3565 (cm->MBs * VAR_HIST_SMALL_CUT_OFF / 100); 3659 (cm->MBs * VAR_HIST_SMALL_CUT_OFF / 100);
3566 DECLARE_ALIGNED_ARRAY(16, int, hist, VAR_HIST_BINS); 3660 DECLARE_ALIGNED(16, int, hist[VAR_HIST_BINS]);
3567 diff *var16 = cpi->source_diff_var; 3661 diff *var16 = cpi->source_diff_var;
3568 3662
3569 int sum = 0; 3663 int sum = 0;
3570 int i, j; 3664 int i, j;
3571 3665
3572 vpx_memset(hist, 0, VAR_HIST_BINS * sizeof(hist[0])); 3666 memset(hist, 0, VAR_HIST_BINS * sizeof(hist[0]));
3573 3667
3574 for (i = 0; i < cm->mb_rows; i++) { 3668 for (i = 0; i < cm->mb_rows; i++) {
3575 for (j = 0; j < cm->mb_cols; j++) { 3669 for (j = 0; j < cm->mb_cols; j++) {
3576 #if CONFIG_VP9_HIGHBITDEPTH 3670 #if CONFIG_VP9_HIGHBITDEPTH
3577 if (cm->use_highbitdepth) { 3671 if (cm->use_highbitdepth) {
3578 switch (cm->bit_depth) { 3672 switch (cm->bit_depth) {
3579 case VPX_BITS_8: 3673 case VPX_BITS_8:
3580 vp9_highbd_get16x16var(src, src_stride, last_src, last_stride, 3674 vp9_highbd_get16x16var(src, src_stride, last_src, last_stride,
3581 &var16->sse, &var16->sum); 3675 &var16->sse, &var16->sum);
3582 break; 3676 break;
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
3767 3861
3768 static void encode_frame_internal(VP9_COMP *cpi) { 3862 static void encode_frame_internal(VP9_COMP *cpi) {
3769 SPEED_FEATURES *const sf = &cpi->sf; 3863 SPEED_FEATURES *const sf = &cpi->sf;
3770 RD_OPT *const rd_opt = &cpi->rd; 3864 RD_OPT *const rd_opt = &cpi->rd;
3771 ThreadData *const td = &cpi->td; 3865 ThreadData *const td = &cpi->td;
3772 MACROBLOCK *const x = &td->mb; 3866 MACROBLOCK *const x = &td->mb;
3773 VP9_COMMON *const cm = &cpi->common; 3867 VP9_COMMON *const cm = &cpi->common;
3774 MACROBLOCKD *const xd = &x->e_mbd; 3868 MACROBLOCKD *const xd = &x->e_mbd;
3775 RD_COUNTS *const rdc = &cpi->td.rd_counts; 3869 RD_COUNTS *const rdc = &cpi->td.rd_counts;
3776 3870
3777 xd->mi = cm->mi; 3871 xd->mi = cm->mi_grid_visible;
3778 xd->mi[0].src_mi = &xd->mi[0]; 3872 xd->mi[0] = cm->mi;
3779 3873
3780 vp9_zero(*td->counts); 3874 vp9_zero(*td->counts);
3781 vp9_zero(rdc->coef_counts); 3875 vp9_zero(rdc->coef_counts);
3782 vp9_zero(rdc->comp_pred_diff); 3876 vp9_zero(rdc->comp_pred_diff);
3783 vp9_zero(rdc->filter_diff); 3877 vp9_zero(rdc->filter_diff);
3784 vp9_zero(rdc->tx_select_diff); 3878 vp9_zero(rdc->tx_select_diff);
3785 vp9_zero(rd_opt->tx_select_threshes); 3879 vp9_zero(rd_opt->tx_select_threshes);
3786 3880
3787 xd->lossless = cm->base_qindex == 0 && 3881 xd->lossless = cm->base_qindex == 0 &&
3788 cm->y_dc_delta_q == 0 && 3882 cm->y_dc_delta_q == 0 &&
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
3832 PICK_MODE_CONTEXT *ctx = &cpi->td.pc_root->none; 3926 PICK_MODE_CONTEXT *ctx = &cpi->td.pc_root->none;
3833 3927
3834 for (i = 0; i < MAX_MB_PLANE; ++i) { 3928 for (i = 0; i < MAX_MB_PLANE; ++i) {
3835 p[i].coeff = ctx->coeff_pbuf[i][0]; 3929 p[i].coeff = ctx->coeff_pbuf[i][0];
3836 p[i].qcoeff = ctx->qcoeff_pbuf[i][0]; 3930 p[i].qcoeff = ctx->qcoeff_pbuf[i][0];
3837 pd[i].dqcoeff = ctx->dqcoeff_pbuf[i][0]; 3931 pd[i].dqcoeff = ctx->dqcoeff_pbuf[i][0];
3838 p[i].eobs = ctx->eobs_pbuf[i][0]; 3932 p[i].eobs = ctx->eobs_pbuf[i][0];
3839 } 3933 }
3840 vp9_zero(x->zcoeff_blk); 3934 vp9_zero(x->zcoeff_blk);
3841 3935
3936 if (cm->frame_type != KEY_FRAME && cpi->rc.frames_since_golden == 0)
3937 cpi->ref_frame_flags &= (~VP9_GOLD_FLAG);
3938
3842 if (sf->partition_search_type == SOURCE_VAR_BASED_PARTITION) 3939 if (sf->partition_search_type == SOURCE_VAR_BASED_PARTITION)
3843 source_var_based_partition_search_method(cpi); 3940 source_var_based_partition_search_method(cpi);
3844 } 3941 }
3845 3942
3846 { 3943 {
3847 struct vpx_usec_timer emr_timer; 3944 struct vpx_usec_timer emr_timer;
3848 vpx_usec_timer_start(&emr_timer); 3945 vpx_usec_timer_start(&emr_timer);
3849 3946
3850 #if CONFIG_FP_MB_STATS 3947 #if CONFIG_FP_MB_STATS
3851 if (cpi->use_fp_mb_stats) { 3948 if (cpi->use_fp_mb_stats) {
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
4042 ++counts->uv_mode[y_mode][uv_mode]; 4139 ++counts->uv_mode[y_mode][uv_mode];
4043 } 4140 }
4044 4141
4045 static void encode_superblock(VP9_COMP *cpi, ThreadData *td, 4142 static void encode_superblock(VP9_COMP *cpi, ThreadData *td,
4046 TOKENEXTRA **t, int output_enabled, 4143 TOKENEXTRA **t, int output_enabled,
4047 int mi_row, int mi_col, BLOCK_SIZE bsize, 4144 int mi_row, int mi_col, BLOCK_SIZE bsize,
4048 PICK_MODE_CONTEXT *ctx) { 4145 PICK_MODE_CONTEXT *ctx) {
4049 VP9_COMMON *const cm = &cpi->common; 4146 VP9_COMMON *const cm = &cpi->common;
4050 MACROBLOCK *const x = &td->mb; 4147 MACROBLOCK *const x = &td->mb;
4051 MACROBLOCKD *const xd = &x->e_mbd; 4148 MACROBLOCKD *const xd = &x->e_mbd;
4052 MODE_INFO *mi_8x8 = xd->mi; 4149 MODE_INFO **mi_8x8 = xd->mi;
4053 MODE_INFO *mi = mi_8x8; 4150 MODE_INFO *mi = mi_8x8[0];
4054 MB_MODE_INFO *mbmi = &mi->mbmi; 4151 MB_MODE_INFO *mbmi = &mi->mbmi;
4055 const int seg_skip = vp9_segfeature_active(&cm->seg, mbmi->segment_id, 4152 const int seg_skip = vp9_segfeature_active(&cm->seg, mbmi->segment_id,
4056 SEG_LVL_SKIP); 4153 SEG_LVL_SKIP);
4057 const int mis = cm->mi_stride; 4154 const int mis = cm->mi_stride;
4058 const int mi_width = num_8x8_blocks_wide_lookup[bsize]; 4155 const int mi_width = num_8x8_blocks_wide_lookup[bsize];
4059 const int mi_height = num_8x8_blocks_high_lookup[bsize]; 4156 const int mi_height = num_8x8_blocks_high_lookup[bsize];
4060 4157
4061 x->skip_recode = !x->select_tx_size && mbmi->sb_type >= BLOCK_8X8 && 4158 x->skip_recode = !x->select_tx_size && mbmi->sb_type >= BLOCK_8X8 &&
4062 cpi->oxcf.aq_mode != COMPLEXITY_AQ && 4159 cpi->oxcf.aq_mode != COMPLEXITY_AQ &&
4063 cpi->oxcf.aq_mode != CYCLIC_REFRESH_AQ && 4160 cpi->oxcf.aq_mode != CYCLIC_REFRESH_AQ &&
4064 cpi->sf.allow_skip_recode; 4161 cpi->sf.allow_skip_recode;
4065 4162
4066 if (!x->skip_recode && !cpi->sf.use_nonrd_pick_mode) 4163 if (!x->skip_recode && !cpi->sf.use_nonrd_pick_mode)
4067 vpx_memset(x->skip_txfm, 0, sizeof(x->skip_txfm)); 4164 memset(x->skip_txfm, 0, sizeof(x->skip_txfm));
4068 4165
4069 x->skip_optimize = ctx->is_coded; 4166 x->skip_optimize = ctx->is_coded;
4070 ctx->is_coded = 1; 4167 ctx->is_coded = 1;
4071 x->use_lp32x32fdct = cpi->sf.use_lp32x32fdct; 4168 x->use_lp32x32fdct = cpi->sf.use_lp32x32fdct;
4072 x->skip_encode = (!output_enabled && cpi->sf.skip_encode_frame && 4169 x->skip_encode = (!output_enabled && cpi->sf.skip_encode_frame &&
4073 x->q_index < QIDX_SKIP_THRESH); 4170 x->q_index < QIDX_SKIP_THRESH);
4074 4171
4075 if (x->skip_encode) 4172 if (x->skip_encode)
4076 return; 4173 return;
4077 4174
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
4117 if (is_inter_block(&mi->mbmi)) { 4214 if (is_inter_block(&mi->mbmi)) {
4118 tx_size = MIN(tx_mode_to_biggest_tx_size[cm->tx_mode], 4215 tx_size = MIN(tx_mode_to_biggest_tx_size[cm->tx_mode],
4119 max_txsize_lookup[bsize]); 4216 max_txsize_lookup[bsize]);
4120 } else { 4217 } else {
4121 tx_size = (bsize >= BLOCK_8X8) ? mbmi->tx_size : TX_4X4; 4218 tx_size = (bsize >= BLOCK_8X8) ? mbmi->tx_size : TX_4X4;
4122 } 4219 }
4123 4220
4124 for (y = 0; y < mi_height; y++) 4221 for (y = 0; y < mi_height; y++)
4125 for (x = 0; x < mi_width; x++) 4222 for (x = 0; x < mi_width; x++)
4126 if (mi_col + x < cm->mi_cols && mi_row + y < cm->mi_rows) 4223 if (mi_col + x < cm->mi_cols && mi_row + y < cm->mi_rows)
4127 mi_8x8[mis * y + x].src_mi->mbmi.tx_size = tx_size; 4224 mi_8x8[mis * y + x]->mbmi.tx_size = tx_size;
4128 } 4225 }
4129 ++td->counts->tx.tx_totals[mbmi->tx_size]; 4226 ++td->counts->tx.tx_totals[mbmi->tx_size];
4130 ++td->counts->tx.tx_totals[get_uv_tx_size(mbmi, &xd->plane[1])]; 4227 ++td->counts->tx.tx_totals[get_uv_tx_size(mbmi, &xd->plane[1])];
4131 } 4228 }
4132 } 4229 }
OLDNEW
« no previous file with comments | « source/libvpx/vp9/encoder/vp9_encodeframe.h ('k') | source/libvpx/vp9/encoder/vp9_encodemb.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698