OLD | NEW |
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 18 matching lines...) Expand all Loading... |
29 #include "vp9/common/vp9_seg_common.h" | 29 #include "vp9/common/vp9_seg_common.h" |
30 #include "vp9/common/vp9_systemdependent.h" | 30 #include "vp9/common/vp9_systemdependent.h" |
31 #include "vp9/common/vp9_tile_common.h" | 31 #include "vp9/common/vp9_tile_common.h" |
32 | 32 |
33 #include "vp9/encoder/vp9_aq_complexity.h" | 33 #include "vp9/encoder/vp9_aq_complexity.h" |
34 #include "vp9/encoder/vp9_aq_cyclicrefresh.h" | 34 #include "vp9/encoder/vp9_aq_cyclicrefresh.h" |
35 #include "vp9/encoder/vp9_aq_variance.h" | 35 #include "vp9/encoder/vp9_aq_variance.h" |
36 #include "vp9/encoder/vp9_encodeframe.h" | 36 #include "vp9/encoder/vp9_encodeframe.h" |
37 #include "vp9/encoder/vp9_encodemb.h" | 37 #include "vp9/encoder/vp9_encodemb.h" |
38 #include "vp9/encoder/vp9_encodemv.h" | 38 #include "vp9/encoder/vp9_encodemv.h" |
| 39 #include "vp9/encoder/vp9_ethread.h" |
39 #include "vp9/encoder/vp9_extend.h" | 40 #include "vp9/encoder/vp9_extend.h" |
40 #include "vp9/encoder/vp9_pickmode.h" | 41 #include "vp9/encoder/vp9_pickmode.h" |
41 #include "vp9/encoder/vp9_rd.h" | 42 #include "vp9/encoder/vp9_rd.h" |
42 #include "vp9/encoder/vp9_rdopt.h" | 43 #include "vp9/encoder/vp9_rdopt.h" |
43 #include "vp9/encoder/vp9_segmentation.h" | 44 #include "vp9/encoder/vp9_segmentation.h" |
44 #include "vp9/encoder/vp9_tokenize.h" | 45 #include "vp9/encoder/vp9_tokenize.h" |
45 | 46 |
46 #define GF_ZEROMV_ZBIN_BOOST 0 | 47 #define GF_ZEROMV_ZBIN_BOOST 0 |
47 #define LF_ZEROMV_ZBIN_BOOST 0 | 48 #define LF_ZEROMV_ZBIN_BOOST 0 |
48 #define MV_ZBIN_BOOST 0 | 49 #define MV_ZBIN_BOOST 0 |
49 #define SPLIT_MV_ZBIN_BOOST 0 | 50 #define SPLIT_MV_ZBIN_BOOST 0 |
50 #define INTRA_ZBIN_BOOST 0 | 51 #define INTRA_ZBIN_BOOST 0 |
51 | 52 |
52 static void encode_superblock(VP9_COMP *cpi, ThreadData * td, | 53 static void encode_superblock(VP9_COMP *cpi, ThreadData * td, |
53 TOKENEXTRA **t, int output_enabled, | 54 TOKENEXTRA **t, int output_enabled, |
54 int mi_row, int mi_col, BLOCK_SIZE bsize, | 55 int mi_row, int mi_col, BLOCK_SIZE bsize, |
55 PICK_MODE_CONTEXT *ctx); | 56 PICK_MODE_CONTEXT *ctx); |
56 | 57 |
57 // Motion vector component magnitude threshold for defining fast motion. | |
58 #define FAST_MOTION_MV_THRESH 24 | |
59 | |
60 // This is used as a reference when computing the source variance for the | 58 // This is used as a reference when computing the source variance for the |
61 // purposes of activity masking. | 59 // purposes of activity masking. |
62 // Eventually this should be replaced by custom no-reference routines, | 60 // Eventually this should be replaced by custom no-reference routines, |
63 // which will be faster. | 61 // which will be faster. |
64 static const uint8_t VP9_VAR_OFFS[64] = { | 62 static const uint8_t VP9_VAR_OFFS[64] = { |
65 128, 128, 128, 128, 128, 128, 128, 128, | 63 128, 128, 128, 128, 128, 128, 128, 128, |
66 128, 128, 128, 128, 128, 128, 128, 128, | 64 128, 128, 128, 128, 128, 128, 128, 128, |
67 128, 128, 128, 128, 128, 128, 128, 128, | 65 128, 128, 128, 128, 128, 128, 128, 128, |
68 128, 128, 128, 128, 128, 128, 128, 128, | 66 128, 128, 128, 128, 128, 128, 128, 128, |
69 128, 128, 128, 128, 128, 128, 128, 128, | 67 128, 128, 128, 128, 128, 128, 128, 128, |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 if (var < 4) | 179 if (var < 4) |
182 return BLOCK_64X64; | 180 return BLOCK_64X64; |
183 else if (var < 10) | 181 else if (var < 10) |
184 return BLOCK_32X32; | 182 return BLOCK_32X32; |
185 else | 183 else |
186 return BLOCK_16X16; | 184 return BLOCK_16X16; |
187 } | 185 } |
188 | 186 |
189 // Lighter version of set_offsets that only sets the mode info | 187 // Lighter version of set_offsets that only sets the mode info |
190 // pointers. | 188 // pointers. |
191 static INLINE void set_modeinfo_offsets(VP9_COMMON *const cm, | 189 static INLINE void set_mode_info_offsets(VP9_COMMON *const cm, |
192 MACROBLOCKD *const xd, | 190 MACROBLOCKD *const xd, |
193 int mi_row, | 191 int mi_row, |
194 int mi_col) { | 192 int mi_col) { |
195 const int idx_str = xd->mi_stride * mi_row + mi_col; | 193 const int idx_str = xd->mi_stride * mi_row + mi_col; |
196 xd->mi = cm->mi + idx_str; | 194 xd->mi = cm->mi + idx_str; |
197 xd->mi[0].src_mi = &xd->mi[0]; | 195 xd->mi[0].src_mi = &xd->mi[0]; |
198 } | 196 } |
199 | 197 |
200 static void set_offsets(VP9_COMP *cpi, const TileInfo *const tile, | 198 static void set_offsets(VP9_COMP *cpi, const TileInfo *const tile, |
201 MACROBLOCK *const x, int mi_row, int mi_col, | 199 MACROBLOCK *const x, int mi_row, int mi_col, |
202 BLOCK_SIZE bsize) { | 200 BLOCK_SIZE bsize) { |
203 VP9_COMMON *const cm = &cpi->common; | 201 VP9_COMMON *const cm = &cpi->common; |
204 MACROBLOCKD *const xd = &x->e_mbd; | 202 MACROBLOCKD *const xd = &x->e_mbd; |
205 MB_MODE_INFO *mbmi; | 203 MB_MODE_INFO *mbmi; |
206 const int mi_width = num_8x8_blocks_wide_lookup[bsize]; | 204 const int mi_width = num_8x8_blocks_wide_lookup[bsize]; |
207 const int mi_height = num_8x8_blocks_high_lookup[bsize]; | 205 const int mi_height = num_8x8_blocks_high_lookup[bsize]; |
208 const struct segmentation *const seg = &cm->seg; | 206 const struct segmentation *const seg = &cm->seg; |
209 | 207 |
210 set_skip_context(xd, mi_row, mi_col); | 208 set_skip_context(xd, mi_row, mi_col); |
211 | 209 |
212 set_modeinfo_offsets(cm, xd, mi_row, mi_col); | 210 set_mode_info_offsets(cm, xd, mi_row, mi_col); |
213 | 211 |
214 mbmi = &xd->mi[0].src_mi->mbmi; | 212 mbmi = &xd->mi[0].src_mi->mbmi; |
215 | 213 |
216 // Set up destination pointers. | 214 // Set up destination pointers. |
217 vp9_setup_dst_planes(xd->plane, get_frame_new_buffer(cm), mi_row, mi_col); | 215 vp9_setup_dst_planes(xd->plane, get_frame_new_buffer(cm), mi_row, mi_col); |
218 | 216 |
219 // Set up limit values for MV components. | 217 // Set up limit values for MV components. |
220 // Mv beyond the range do not produce new/different prediction block. | 218 // Mv beyond the range do not produce new/different prediction block. |
221 x->mv_row_min = -(((mi_row + mi_height) * MI_SIZE) + VP9_INTERP_EXTEND); | 219 x->mv_row_min = -(((mi_row + mi_height) * MI_SIZE) + VP9_INTERP_EXTEND); |
222 x->mv_col_min = -(((mi_col + mi_width) * MI_SIZE) + VP9_INTERP_EXTEND); | 220 x->mv_col_min = -(((mi_col + mi_width) * MI_SIZE) + VP9_INTERP_EXTEND); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 if (mi_row + j < cm->mi_rows && mi_col + i < cm->mi_cols) | 260 if (mi_row + j < cm->mi_rows && mi_col + i < cm->mi_cols) |
263 xd->mi[j * xd->mi_stride + i].src_mi = &xd->mi[0]; | 261 xd->mi[j * xd->mi_stride + i].src_mi = &xd->mi[0]; |
264 } | 262 } |
265 } | 263 } |
266 | 264 |
267 static void set_block_size(VP9_COMP * const cpi, | 265 static void set_block_size(VP9_COMP * const cpi, |
268 MACROBLOCKD *const xd, | 266 MACROBLOCKD *const xd, |
269 int mi_row, int mi_col, | 267 int mi_row, int mi_col, |
270 BLOCK_SIZE bsize) { | 268 BLOCK_SIZE bsize) { |
271 if (cpi->common.mi_cols > mi_col && cpi->common.mi_rows > mi_row) { | 269 if (cpi->common.mi_cols > mi_col && cpi->common.mi_rows > mi_row) { |
272 set_modeinfo_offsets(&cpi->common, xd, mi_row, mi_col); | 270 set_mode_info_offsets(&cpi->common, xd, mi_row, mi_col); |
273 xd->mi[0].src_mi->mbmi.sb_type = bsize; | 271 xd->mi[0].src_mi->mbmi.sb_type = bsize; |
274 duplicate_mode_info_in_sb(&cpi->common, xd, mi_row, mi_col, bsize); | |
275 } | 272 } |
276 } | 273 } |
277 | 274 |
278 typedef struct { | 275 typedef struct { |
279 int64_t sum_square_error; | 276 int64_t sum_square_error; |
280 int64_t sum_error; | 277 int64_t sum_error; |
281 int count; | 278 int log2_count; |
282 int variance; | 279 int variance; |
283 } var; | 280 } var; |
284 | 281 |
285 typedef struct { | 282 typedef struct { |
286 var none; | 283 var none; |
287 var horz[2]; | 284 var horz[2]; |
288 var vert[2]; | 285 var vert[2]; |
289 } partition_variance; | 286 } partition_variance; |
290 | 287 |
291 typedef struct { | 288 typedef struct { |
(...skipping 28 matching lines...) Expand all Loading... |
320 | 317 |
321 typedef enum { | 318 typedef enum { |
322 V16X16, | 319 V16X16, |
323 V32X32, | 320 V32X32, |
324 V64X64, | 321 V64X64, |
325 } TREE_LEVEL; | 322 } TREE_LEVEL; |
326 | 323 |
327 static void tree_to_node(void *data, BLOCK_SIZE bsize, variance_node *node) { | 324 static void tree_to_node(void *data, BLOCK_SIZE bsize, variance_node *node) { |
328 int i; | 325 int i; |
329 node->part_variances = NULL; | 326 node->part_variances = NULL; |
330 vpx_memset(node->split, 0, sizeof(node->split)); | |
331 switch (bsize) { | 327 switch (bsize) { |
332 case BLOCK_64X64: { | 328 case BLOCK_64X64: { |
333 v64x64 *vt = (v64x64 *) data; | 329 v64x64 *vt = (v64x64 *) data; |
334 node->part_variances = &vt->part_variances; | 330 node->part_variances = &vt->part_variances; |
335 for (i = 0; i < 4; i++) | 331 for (i = 0; i < 4; i++) |
336 node->split[i] = &vt->split[i].part_variances.none; | 332 node->split[i] = &vt->split[i].part_variances.none; |
337 break; | 333 break; |
338 } | 334 } |
339 case BLOCK_32X32: { | 335 case BLOCK_32X32: { |
340 v32x32 *vt = (v32x32 *) data; | 336 v32x32 *vt = (v32x32 *) data; |
(...skipping 27 matching lines...) Expand all Loading... |
368 assert(0); | 364 assert(0); |
369 break; | 365 break; |
370 } | 366 } |
371 } | 367 } |
372 } | 368 } |
373 | 369 |
374 // Set variance values given sum square error, sum error, count. | 370 // Set variance values given sum square error, sum error, count. |
375 static void fill_variance(int64_t s2, int64_t s, int c, var *v) { | 371 static void fill_variance(int64_t s2, int64_t s, int c, var *v) { |
376 v->sum_square_error = s2; | 372 v->sum_square_error = s2; |
377 v->sum_error = s; | 373 v->sum_error = s; |
378 v->count = c; | 374 v->log2_count = c; |
379 if (c > 0) | 375 } |
380 v->variance = (int)(256 * | 376 |
381 (v->sum_square_error - v->sum_error * v->sum_error / | 377 static void get_variance(var *v) { |
382 v->count) / v->count); | 378 v->variance = (int)(256 * (v->sum_square_error - |
383 else | 379 ((v->sum_error * v->sum_error) >> v->log2_count)) >> v->log2_count); |
384 v->variance = 0; | |
385 } | 380 } |
386 | 381 |
387 void sum_2_variances(const var *a, const var *b, var *r) { | 382 void sum_2_variances(const var *a, const var *b, var *r) { |
| 383 assert(a->log2_count == b->log2_count); |
388 fill_variance(a->sum_square_error + b->sum_square_error, | 384 fill_variance(a->sum_square_error + b->sum_square_error, |
389 a->sum_error + b->sum_error, a->count + b->count, r); | 385 a->sum_error + b->sum_error, a->log2_count + 1, r); |
390 } | 386 } |
391 | 387 |
392 static void fill_variance_tree(void *data, BLOCK_SIZE bsize) { | 388 static void fill_variance_tree(void *data, BLOCK_SIZE bsize) { |
393 variance_node node; | 389 variance_node node; |
394 tree_to_node(data, bsize, &node); | 390 tree_to_node(data, bsize, &node); |
395 sum_2_variances(node.split[0], node.split[1], &node.part_variances->horz[0]); | 391 sum_2_variances(node.split[0], node.split[1], &node.part_variances->horz[0]); |
396 sum_2_variances(node.split[2], node.split[3], &node.part_variances->horz[1]); | 392 sum_2_variances(node.split[2], node.split[3], &node.part_variances->horz[1]); |
397 sum_2_variances(node.split[0], node.split[2], &node.part_variances->vert[0]); | 393 sum_2_variances(node.split[0], node.split[2], &node.part_variances->vert[0]); |
398 sum_2_variances(node.split[1], node.split[3], &node.part_variances->vert[1]); | 394 sum_2_variances(node.split[1], node.split[3], &node.part_variances->vert[1]); |
399 sum_2_variances(&node.part_variances->vert[0], &node.part_variances->vert[1], | 395 sum_2_variances(&node.part_variances->vert[0], &node.part_variances->vert[1], |
(...skipping 17 matching lines...) Expand all Loading... |
417 vp9_convert_qindex_to_q(cm->base_qindex, cm->bit_depth)); | 413 vp9_convert_qindex_to_q(cm->base_qindex, cm->bit_depth)); |
418 int64_t threshold_bsize_ref = threshold << 6; | 414 int64_t threshold_bsize_ref = threshold << 6; |
419 int64_t threshold_low = threshold; | 415 int64_t threshold_low = threshold; |
420 BLOCK_SIZE bsize_ref = BLOCK_16X16; | 416 BLOCK_SIZE bsize_ref = BLOCK_16X16; |
421 | 417 |
422 assert(block_height == block_width); | 418 assert(block_height == block_width); |
423 tree_to_node(data, bsize, &vt); | 419 tree_to_node(data, bsize, &vt); |
424 | 420 |
425 if (cm->frame_type == KEY_FRAME) { | 421 if (cm->frame_type == KEY_FRAME) { |
426 bsize_ref = BLOCK_8X8; | 422 bsize_ref = BLOCK_8X8; |
427 // Choose lower thresholds for key frame variance to favor split. | 423 // Choose lower thresholds for key frame variance to favor split, but keep |
428 threshold_bsize_ref = threshold >> 1; | 424 // threshold for splitting to 4x4 block still fairly high for now. |
| 425 threshold_bsize_ref = threshold << 2; |
429 threshold_low = threshold >> 2; | 426 threshold_low = threshold >> 2; |
430 } | 427 } |
431 | 428 |
432 // For bsize=bsize_ref (16x16/8x8 for 8x8/4x4 downsampling), select if | 429 // For bsize=bsize_ref (16x16/8x8 for 8x8/4x4 downsampling), select if |
433 // variance is below threshold, otherwise split will be selected. | 430 // variance is below threshold, otherwise split will be selected. |
434 // No check for vert/horiz split as too few samples for variance. | 431 // No check for vert/horiz split as too few samples for variance. |
435 if (bsize == bsize_ref) { | 432 if (bsize == bsize_ref) { |
| 433 get_variance(&vt.part_variances->none); |
436 if (mi_col + block_width / 2 < cm->mi_cols && | 434 if (mi_col + block_width / 2 < cm->mi_cols && |
437 mi_row + block_height / 2 < cm->mi_rows && | 435 mi_row + block_height / 2 < cm->mi_rows && |
438 vt.part_variances->none.variance < threshold_bsize_ref) { | 436 vt.part_variances->none.variance < threshold_bsize_ref) { |
439 set_block_size(cpi, xd, mi_row, mi_col, bsize); | 437 set_block_size(cpi, xd, mi_row, mi_col, bsize); |
440 return 1; | 438 return 1; |
441 } | 439 } |
442 return 0; | 440 return 0; |
443 } else if (bsize > bsize_ref) { | 441 } else if (bsize > bsize_ref) { |
| 442 get_variance(&vt.part_variances->none); |
444 // For key frame, for bsize above 32X32, or very high variance, take split. | 443 // For key frame, for bsize above 32X32, or very high variance, take split. |
445 if (cm->frame_type == KEY_FRAME && | 444 if (cm->frame_type == KEY_FRAME && |
446 (bsize > BLOCK_32X32 || | 445 (bsize > BLOCK_32X32 || |
447 vt.part_variances->none.variance > (threshold << 2))) { | 446 vt.part_variances->none.variance > (threshold << 2))) { |
448 return 0; | 447 return 0; |
449 } | 448 } |
450 // If variance is low, take the bsize (no split). | 449 // If variance is low, take the bsize (no split). |
451 if (mi_col + block_width / 2 < cm->mi_cols && | 450 if (mi_col + block_width / 2 < cm->mi_cols && |
452 mi_row + block_height / 2 < cm->mi_rows && | 451 mi_row + block_height / 2 < cm->mi_rows && |
453 vt.part_variances->none.variance < threshold_low) { | 452 vt.part_variances->none.variance < threshold_low) { |
454 set_block_size(cpi, xd, mi_row, mi_col, bsize); | 453 set_block_size(cpi, xd, mi_row, mi_col, bsize); |
455 return 1; | 454 return 1; |
456 } | 455 } |
| 456 |
457 // Check vertical split. | 457 // Check vertical split. |
458 if (mi_row + block_height / 2 < cm->mi_rows && | 458 if (mi_row + block_height / 2 < cm->mi_rows) { |
459 vt.part_variances->vert[0].variance < threshold_low && | 459 get_variance(&vt.part_variances->vert[0]); |
460 vt.part_variances->vert[1].variance < threshold_low) { | 460 get_variance(&vt.part_variances->vert[1]); |
461 BLOCK_SIZE subsize = get_subsize(bsize, PARTITION_VERT); | 461 if (vt.part_variances->vert[0].variance < threshold_low && |
462 set_block_size(cpi, xd, mi_row, mi_col, subsize); | 462 vt.part_variances->vert[1].variance < threshold_low) { |
463 set_block_size(cpi, xd, mi_row, mi_col + block_width / 2, subsize); | 463 BLOCK_SIZE subsize = get_subsize(bsize, PARTITION_VERT); |
464 return 1; | 464 set_block_size(cpi, xd, mi_row, mi_col, subsize); |
| 465 set_block_size(cpi, xd, mi_row, mi_col + block_width / 2, subsize); |
| 466 return 1; |
| 467 } |
465 } | 468 } |
466 // Check horizontal split. | 469 // Check horizontal split. |
467 if (mi_col + block_width / 2 < cm->mi_cols && | 470 if (mi_col + block_width / 2 < cm->mi_cols) { |
468 vt.part_variances->horz[0].variance < threshold_low && | 471 get_variance(&vt.part_variances->horz[0]); |
469 vt.part_variances->horz[1].variance < threshold_low) { | 472 get_variance(&vt.part_variances->horz[1]); |
470 BLOCK_SIZE subsize = get_subsize(bsize, PARTITION_HORZ); | 473 if (vt.part_variances->horz[0].variance < threshold_low && |
471 set_block_size(cpi, xd, mi_row, mi_col, subsize); | 474 vt.part_variances->horz[1].variance < threshold_low) { |
472 set_block_size(cpi, xd, mi_row + block_height / 2, mi_col, subsize); | 475 BLOCK_SIZE subsize = get_subsize(bsize, PARTITION_HORZ); |
473 return 1; | 476 set_block_size(cpi, xd, mi_row, mi_col, subsize); |
| 477 set_block_size(cpi, xd, mi_row + block_height / 2, mi_col, subsize); |
| 478 return 1; |
| 479 } |
474 } | 480 } |
| 481 |
475 return 0; | 482 return 0; |
476 } | 483 } |
477 return 0; | 484 return 0; |
478 } | 485 } |
479 | 486 |
480 // This function chooses partitioning based on the variance between source and | 487 // This function chooses partitioning based on the variance between source and |
481 // reconstructed last, where variance is computed for downsampled inputs. | 488 // reconstructed last, where variance is computed for downsampled inputs. |
482 // Currently 8x8 downsampling is used for delta frames, 4x4 for key frames. | 489 // Currently 8x8 downsampling is used for delta frames, 4x4 for key frames. |
483 static void choose_partitioning(VP9_COMP *cpi, | 490 static void choose_partitioning(VP9_COMP *cpi, |
484 const TileInfo *const tile, | 491 const TileInfo *const tile, |
485 MACROBLOCK *x, | 492 MACROBLOCK *x, |
486 int mi_row, int mi_col) { | 493 int mi_row, int mi_col) { |
487 VP9_COMMON * const cm = &cpi->common; | 494 VP9_COMMON * const cm = &cpi->common; |
488 MACROBLOCKD *xd = &x->e_mbd; | 495 MACROBLOCKD *xd = &x->e_mbd; |
489 | 496 |
490 int i, j, k, m; | 497 int i, j, k, m; |
491 v64x64 vt; | 498 v64x64 vt; |
492 uint8_t *s; | 499 uint8_t *s; |
493 const uint8_t *d; | 500 const uint8_t *d; |
494 int sp; | 501 int sp; |
495 int dp; | 502 int dp; |
496 int pixels_wide = 64, pixels_high = 64; | 503 int pixels_wide = 64, pixels_high = 64; |
497 const YV12_BUFFER_CONFIG *yv12 = get_ref_frame_buffer(cpi, LAST_FRAME); | 504 const YV12_BUFFER_CONFIG *yv12 = get_ref_frame_buffer(cpi, LAST_FRAME); |
498 const struct scale_factors *const sf = &cm->frame_refs[LAST_FRAME - 1].sf; | 505 const struct scale_factors *const sf = &cm->frame_refs[LAST_FRAME - 1].sf; |
499 | 506 |
500 vp9_clear_system_state(); | 507 vp9_clear_system_state(); |
501 vp9_zero(vt); | |
502 set_offsets(cpi, tile, x, mi_row, mi_col, BLOCK_64X64); | 508 set_offsets(cpi, tile, x, mi_row, mi_col, BLOCK_64X64); |
503 | 509 |
504 if (xd->mb_to_right_edge < 0) | 510 if (xd->mb_to_right_edge < 0) |
505 pixels_wide += (xd->mb_to_right_edge >> 3); | 511 pixels_wide += (xd->mb_to_right_edge >> 3); |
506 if (xd->mb_to_bottom_edge < 0) | 512 if (xd->mb_to_bottom_edge < 0) |
507 pixels_high += (xd->mb_to_bottom_edge >> 3); | 513 pixels_high += (xd->mb_to_bottom_edge >> 3); |
508 | 514 |
509 s = x->plane[0].src.buf; | 515 s = x->plane[0].src.buf; |
510 sp = x->plane[0].src.stride; | 516 sp = x->plane[0].src.stride; |
511 | 517 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
567 #else | 573 #else |
568 s_avg = vp9_avg_8x8(s + y8_idx * sp + x8_idx, sp); | 574 s_avg = vp9_avg_8x8(s + y8_idx * sp + x8_idx, sp); |
569 d_avg = vp9_avg_8x8(d + y8_idx * dp + x8_idx, dp); | 575 d_avg = vp9_avg_8x8(d + y8_idx * dp + x8_idx, dp); |
570 #endif | 576 #endif |
571 sum = s_avg - d_avg; | 577 sum = s_avg - d_avg; |
572 sse = sum * sum; | 578 sse = sum * sum; |
573 } | 579 } |
574 // If variance is based on 8x8 downsampling, we stop here and have | 580 // If variance is based on 8x8 downsampling, we stop here and have |
575 // one sample for 8x8 block (so use 1 for count in fill_variance), | 581 // one sample for 8x8 block (so use 1 for count in fill_variance), |
576 // which of course means variance = 0 for 8x8 block. | 582 // which of course means variance = 0 for 8x8 block. |
577 fill_variance(sse, sum, 1, &vst->split[k].part_variances.none); | 583 fill_variance(sse, sum, 0, &vst->split[k].part_variances.none); |
578 } else { | 584 } else { |
579 // For key frame, go down to 4x4. | 585 // For key frame, go down to 4x4. |
580 v8x8 *vst2 = &vst->split[k]; | 586 v8x8 *vst2 = &vst->split[k]; |
581 for (m = 0; m < 4; m++) { | 587 for (m = 0; m < 4; m++) { |
582 int x4_idx = x8_idx + ((m & 1) << 2); | 588 int x4_idx = x8_idx + ((m & 1) << 2); |
583 int y4_idx = y8_idx + ((m >> 1) << 2); | 589 int y4_idx = y8_idx + ((m >> 1) << 2); |
584 unsigned int sse = 0; | 590 unsigned int sse = 0; |
585 int sum = 0; | 591 int sum = 0; |
586 if (x4_idx < pixels_wide && y4_idx < pixels_high) { | 592 if (x4_idx < pixels_wide && y4_idx < pixels_high) { |
| 593 #if CONFIG_VP9_HIGHBITDEPTH |
| 594 int s_avg; |
| 595 if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) { |
| 596 s_avg = vp9_highbd_avg_4x4(s + y4_idx * sp + x4_idx, sp); |
| 597 } else { |
| 598 s_avg = vp9_avg_4x4(s + y4_idx * sp + x4_idx, sp); |
| 599 } |
| 600 #else |
587 int s_avg = vp9_avg_4x4(s + y4_idx * sp + x4_idx, sp); | 601 int s_avg = vp9_avg_4x4(s + y4_idx * sp + x4_idx, sp); |
| 602 #endif |
588 // For key frame, reference is set to 128. | 603 // For key frame, reference is set to 128. |
589 sum = s_avg - 128; | 604 sum = s_avg - 128; |
590 sse = sum * sum; | 605 sse = sum * sum; |
591 } | 606 } |
592 // If variance is based on 4x4 downsampling, we stop here and have | 607 // If variance is based on 4x4 downsampling, we stop here and have |
593 // one sample for 4x4 block (so use 1 for count in fill_variance), | 608 // one sample for 4x4 block (so use 1 for count in fill_variance), |
594 // which of course means variance = 0 for 4x4 block. | 609 // which of course means variance = 0 for 4x4 block. |
595 fill_variance(sse, sum, 1, &vst2->split[m].part_variances.none); | 610 fill_variance(sse, sum, 0, &vst2->split[m].part_variances.none); |
596 } | 611 } |
597 } | 612 } |
598 } | 613 } |
599 } | 614 } |
600 } | 615 } |
601 // Fill the rest of the variance tree by summing split partition values. | 616 // Fill the rest of the variance tree by summing split partition values. |
602 for (i = 0; i < 4; i++) { | 617 for (i = 0; i < 4; i++) { |
603 for (j = 0; j < 4; j++) { | 618 for (j = 0; j < 4; j++) { |
604 if (cm->frame_type == KEY_FRAME) { | 619 if (cm->frame_type == KEY_FRAME) { |
605 for (m = 0; m < 4; m++) { | 620 for (m = 0; m < 4; m++) { |
(...skipping 25 matching lines...) Expand all Loading... |
631 // high. For key frames, 4x4 downsampling is used, so we can better | 646 // high. For key frames, 4x4 downsampling is used, so we can better |
632 // select 8x16/16x8 and 8x8. 4x4 partition can potentially be set | 647 // select 8x16/16x8 and 8x8. 4x4 partition can potentially be set |
633 // used here too, but for now 4x4 is not allowed. | 648 // used here too, but for now 4x4 is not allowed. |
634 if (!set_vt_partitioning(cpi, xd, &vt.split[i].split[j], | 649 if (!set_vt_partitioning(cpi, xd, &vt.split[i].split[j], |
635 BLOCK_16X16, | 650 BLOCK_16X16, |
636 mi_row + y32_idx + y16_idx, | 651 mi_row + y32_idx + y16_idx, |
637 mi_col + x32_idx + x16_idx)) { | 652 mi_col + x32_idx + x16_idx)) { |
638 for (k = 0; k < 4; ++k) { | 653 for (k = 0; k < 4; ++k) { |
639 const int x8_idx = (k & 1); | 654 const int x8_idx = (k & 1); |
640 const int y8_idx = (k >> 1); | 655 const int y8_idx = (k >> 1); |
641 // TODO(marpan): Allow for setting 4x4 partition on key frame. | |
642 /* | |
643 if (cm->frame_type == KEY_FRAME) { | 656 if (cm->frame_type == KEY_FRAME) { |
644 if (!set_vt_partitioning(cpi, xd, | 657 if (!set_vt_partitioning(cpi, xd, |
645 &vt.split[i].split[j].split[k], | 658 &vt.split[i].split[j].split[k], |
646 BLOCK_8X8, | 659 BLOCK_8X8, |
647 mi_row + y32_idx + y16_idx + y8_idx, | 660 mi_row + y32_idx + y16_idx + y8_idx, |
648 mi_col + x32_idx + x16_idx + x8_idx)) { | 661 mi_col + x32_idx + x16_idx + x8_idx)) { |
649 set_block_size(cpi, xd, | 662 set_block_size(cpi, xd, |
650 (mi_row + y32_idx + y16_idx + y8_idx), | 663 (mi_row + y32_idx + y16_idx + y8_idx), |
651 (mi_col + x32_idx + x16_idx + x8_idx), | 664 (mi_col + x32_idx + x16_idx + x8_idx), |
652 BLOCK_4X4); | 665 BLOCK_4X4); |
653 } | 666 } |
654 } else { | 667 } else { |
655 */ | |
656 set_block_size(cpi, xd, | 668 set_block_size(cpi, xd, |
657 (mi_row + y32_idx + y16_idx + y8_idx), | 669 (mi_row + y32_idx + y16_idx + y8_idx), |
658 (mi_col + x32_idx + x16_idx + x8_idx), | 670 (mi_col + x32_idx + x16_idx + x8_idx), |
659 BLOCK_8X8); | 671 BLOCK_8X8); |
660 // } | 672 } |
661 } | 673 } |
662 } | 674 } |
663 } | 675 } |
664 } | 676 } |
665 } | 677 } |
666 } | 678 } |
667 } | 679 } |
668 | 680 |
669 static void update_state(VP9_COMP *cpi, ThreadData *td, | 681 static void update_state(VP9_COMP *cpi, ThreadData *td, |
670 PICK_MODE_CONTEXT *ctx, | 682 PICK_MODE_CONTEXT *ctx, |
(...skipping 22 matching lines...) Expand all Loading... |
693 const int mi_width = num_8x8_blocks_wide_lookup[bsize]; | 705 const int mi_width = num_8x8_blocks_wide_lookup[bsize]; |
694 const int mi_height = num_8x8_blocks_high_lookup[bsize]; | 706 const int mi_height = num_8x8_blocks_high_lookup[bsize]; |
695 int max_plane; | 707 int max_plane; |
696 | 708 |
697 assert(mi->mbmi.sb_type == bsize); | 709 assert(mi->mbmi.sb_type == bsize); |
698 | 710 |
699 *mi_addr = *mi; | 711 *mi_addr = *mi; |
700 mi_addr->src_mi = mi_addr; | 712 mi_addr->src_mi = mi_addr; |
701 | 713 |
702 // If segmentation in use | 714 // If segmentation in use |
703 if (seg->enabled && output_enabled) { | 715 if (seg->enabled) { |
704 // For in frame complexity AQ copy the segment id from the segment map. | 716 // For in frame complexity AQ copy the segment id from the segment map. |
705 if (cpi->oxcf.aq_mode == COMPLEXITY_AQ) { | 717 if (cpi->oxcf.aq_mode == COMPLEXITY_AQ) { |
706 const uint8_t *const map = seg->update_map ? cpi->segmentation_map | 718 const uint8_t *const map = seg->update_map ? cpi->segmentation_map |
707 : cm->last_frame_seg_map; | 719 : cm->last_frame_seg_map; |
708 mi_addr->mbmi.segment_id = | 720 mi_addr->mbmi.segment_id = |
709 vp9_get_segment_id(cm, map, bsize, mi_row, mi_col); | 721 vp9_get_segment_id(cm, map, bsize, mi_row, mi_col); |
710 } | 722 } |
711 // Else for cyclic refresh mode update the segment map, set the segment id | 723 // Else for cyclic refresh mode update the segment map, set the segment id |
712 // and then update the quantizer. | 724 // and then update the quantizer. |
713 if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ) { | 725 if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ) { |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
856 mbmi->ref_frame[1] = NONE; | 868 mbmi->ref_frame[1] = NONE; |
857 mbmi->mv[0].as_int = 0; | 869 mbmi->mv[0].as_int = 0; |
858 mbmi->interp_filter = filter_ref; | 870 mbmi->interp_filter = filter_ref; |
859 | 871 |
860 xd->mi[0].src_mi->bmi[0].as_mv[0].as_int = 0; | 872 xd->mi[0].src_mi->bmi[0].as_mv[0].as_int = 0; |
861 x->skip = 1; | 873 x->skip = 1; |
862 | 874 |
863 vp9_rd_cost_init(rd_cost); | 875 vp9_rd_cost_init(rd_cost); |
864 } | 876 } |
865 | 877 |
| 878 static int set_segment_rdmult(VP9_COMP *const cpi, |
| 879 MACROBLOCK *const x, |
| 880 int8_t segment_id) { |
| 881 int segment_qindex; |
| 882 VP9_COMMON *const cm = &cpi->common; |
| 883 vp9_init_plane_quantizers(cpi, x); |
| 884 vp9_clear_system_state(); |
| 885 segment_qindex = vp9_get_qindex(&cm->seg, segment_id, |
| 886 cm->base_qindex); |
| 887 return vp9_compute_rd_mult(cpi, segment_qindex + cm->y_dc_delta_q); |
| 888 } |
| 889 |
866 static void rd_pick_sb_modes(VP9_COMP *cpi, | 890 static void rd_pick_sb_modes(VP9_COMP *cpi, |
867 TileDataEnc *tile_data, | 891 TileDataEnc *tile_data, |
868 MACROBLOCK *const x, | 892 MACROBLOCK *const x, |
869 int mi_row, int mi_col, RD_COST *rd_cost, | 893 int mi_row, int mi_col, RD_COST *rd_cost, |
870 BLOCK_SIZE bsize, PICK_MODE_CONTEXT *ctx, | 894 BLOCK_SIZE bsize, PICK_MODE_CONTEXT *ctx, |
871 int64_t best_rd) { | 895 int64_t best_rd) { |
872 VP9_COMMON *const cm = &cpi->common; | 896 VP9_COMMON *const cm = &cpi->common; |
873 TileInfo *const tile_info = &tile_data->tile_info; | 897 TileInfo *const tile_info = &tile_data->tile_info; |
874 MACROBLOCKD *const xd = &x->e_mbd; | 898 MACROBLOCKD *const xd = &x->e_mbd; |
875 MB_MODE_INFO *mbmi; | 899 MB_MODE_INFO *mbmi; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
912 #else | 936 #else |
913 x->source_variance = get_sby_perpixel_variance(cpi, &x->plane[0].src, bsize); | 937 x->source_variance = get_sby_perpixel_variance(cpi, &x->plane[0].src, bsize); |
914 #endif // CONFIG_VP9_HIGHBITDEPTH | 938 #endif // CONFIG_VP9_HIGHBITDEPTH |
915 | 939 |
916 // Save rdmult before it might be changed, so it can be restored later. | 940 // Save rdmult before it might be changed, so it can be restored later. |
917 orig_rdmult = x->rdmult; | 941 orig_rdmult = x->rdmult; |
918 | 942 |
919 if (aq_mode == VARIANCE_AQ) { | 943 if (aq_mode == VARIANCE_AQ) { |
920 const int energy = bsize <= BLOCK_16X16 ? x->mb_energy | 944 const int energy = bsize <= BLOCK_16X16 ? x->mb_energy |
921 : vp9_block_energy(cpi, x, bsize); | 945 : vp9_block_energy(cpi, x, bsize); |
922 int segment_qindex; | |
923 if (cm->frame_type == KEY_FRAME || | 946 if (cm->frame_type == KEY_FRAME || |
924 cpi->refresh_alt_ref_frame || | 947 cpi->refresh_alt_ref_frame || |
925 (cpi->refresh_golden_frame && !cpi->rc.is_src_frame_alt_ref)) { | 948 (cpi->refresh_golden_frame && !cpi->rc.is_src_frame_alt_ref)) { |
926 mbmi->segment_id = vp9_vaq_segment_id(energy); | 949 mbmi->segment_id = vp9_vaq_segment_id(energy); |
927 } else { | 950 } else { |
928 const uint8_t *const map = cm->seg.update_map ? cpi->segmentation_map | 951 const uint8_t *const map = cm->seg.update_map ? cpi->segmentation_map |
929 : cm->last_frame_seg_map; | 952 : cm->last_frame_seg_map; |
930 mbmi->segment_id = vp9_get_segment_id(cm, map, bsize, mi_row, mi_col); | 953 mbmi->segment_id = vp9_get_segment_id(cm, map, bsize, mi_row, mi_col); |
931 } | 954 } |
932 vp9_init_plane_quantizers(cpi, x); | 955 x->rdmult = set_segment_rdmult(cpi, x, mbmi->segment_id); |
933 vp9_clear_system_state(); | |
934 segment_qindex = vp9_get_qindex(&cm->seg, mbmi->segment_id, | |
935 cm->base_qindex); | |
936 x->rdmult = vp9_compute_rd_mult(cpi, segment_qindex + cm->y_dc_delta_q); | |
937 } else if (aq_mode == COMPLEXITY_AQ) { | 956 } else if (aq_mode == COMPLEXITY_AQ) { |
938 const int mi_offset = mi_row * cm->mi_cols + mi_col; | 957 x->rdmult = set_segment_rdmult(cpi, x, mbmi->segment_id); |
939 unsigned char complexity = cpi->complexity_map[mi_offset]; | |
940 const int is_edge = (mi_row <= 1) || (mi_row >= (cm->mi_rows - 2)) || | |
941 (mi_col <= 1) || (mi_col >= (cm->mi_cols - 2)); | |
942 if (!is_edge && (complexity > 128)) | |
943 x->rdmult += ((x->rdmult * (complexity - 128)) / 256); | |
944 } else if (aq_mode == CYCLIC_REFRESH_AQ) { | 958 } else if (aq_mode == CYCLIC_REFRESH_AQ) { |
945 const uint8_t *const map = cm->seg.update_map ? cpi->segmentation_map | 959 const uint8_t *const map = cm->seg.update_map ? cpi->segmentation_map |
946 : cm->last_frame_seg_map; | 960 : cm->last_frame_seg_map; |
947 // If segment 1, use rdmult for that segment. | 961 // If segment 1, use rdmult for that segment. |
948 if (vp9_get_segment_id(cm, map, bsize, mi_row, mi_col)) | 962 if (vp9_get_segment_id(cm, map, bsize, mi_row, mi_col)) |
949 x->rdmult = vp9_cyclic_refresh_get_rdmult(cpi->cyclic_refresh); | 963 x->rdmult = vp9_cyclic_refresh_get_rdmult(cpi->cyclic_refresh); |
950 } | 964 } |
951 | 965 |
952 // Find best coding mode & reconstruct the MB so it is available | 966 // Find best coding mode & reconstruct the MB so it is available |
953 // as a predictor for MBs that follow in the SB | 967 // as a predictor for MBs that follow in the SB |
954 if (frame_is_intra_only(cm)) { | 968 if (frame_is_intra_only(cm)) { |
955 vp9_rd_pick_intra_mode_sb(cpi, x, rd_cost, bsize, ctx, best_rd); | 969 vp9_rd_pick_intra_mode_sb(cpi, x, rd_cost, bsize, ctx, best_rd); |
956 } else { | 970 } else { |
957 if (bsize >= BLOCK_8X8) { | 971 if (bsize >= BLOCK_8X8) { |
958 if (vp9_segfeature_active(&cm->seg, mbmi->segment_id, SEG_LVL_SKIP)) | 972 if (vp9_segfeature_active(&cm->seg, mbmi->segment_id, SEG_LVL_SKIP)) |
959 vp9_rd_pick_inter_mode_sb_seg_skip(cpi, tile_data, x, rd_cost, bsize, | 973 vp9_rd_pick_inter_mode_sb_seg_skip(cpi, tile_data, x, rd_cost, bsize, |
960 ctx, best_rd); | 974 ctx, best_rd); |
961 else | 975 else |
962 vp9_rd_pick_inter_mode_sb(cpi, tile_data, x, mi_row, mi_col, | 976 vp9_rd_pick_inter_mode_sb(cpi, tile_data, x, mi_row, mi_col, |
963 rd_cost, bsize, ctx, best_rd); | 977 rd_cost, bsize, ctx, best_rd); |
964 } else { | 978 } else { |
965 vp9_rd_pick_inter_mode_sub8x8(cpi, tile_data, x, mi_row, mi_col, | 979 vp9_rd_pick_inter_mode_sub8x8(cpi, tile_data, x, mi_row, mi_col, |
966 rd_cost, bsize, ctx, best_rd); | 980 rd_cost, bsize, ctx, best_rd); |
967 } | 981 } |
968 } | 982 } |
969 | 983 |
| 984 |
| 985 // Examine the resulting rate and for AQ mode 2 make a segment choice. |
| 986 if ((rd_cost->rate != INT_MAX) && |
| 987 (aq_mode == COMPLEXITY_AQ) && (bsize >= BLOCK_16X16) && |
| 988 (cm->frame_type == KEY_FRAME || |
| 989 cpi->refresh_alt_ref_frame || |
| 990 (cpi->refresh_golden_frame && !cpi->rc.is_src_frame_alt_ref))) { |
| 991 vp9_caq_select_segment(cpi, x, bsize, mi_row, mi_col, rd_cost->rate); |
| 992 } |
| 993 |
970 x->rdmult = orig_rdmult; | 994 x->rdmult = orig_rdmult; |
971 | 995 |
972 // TODO(jingning) The rate-distortion optimization flow needs to be | 996 // TODO(jingning) The rate-distortion optimization flow needs to be |
973 // refactored to provide proper exit/return handle. | 997 // refactored to provide proper exit/return handle. |
974 if (rd_cost->rate == INT_MAX) | 998 if (rd_cost->rate == INT_MAX) |
975 rd_cost->rdcost = INT64_MAX; | 999 rd_cost->rdcost = INT64_MAX; |
976 | 1000 |
977 ctx->rate = rd_cost->rate; | 1001 ctx->rate = rd_cost->rate; |
978 ctx->dist = rd_cost->dist; | 1002 ctx->dist = rd_cost->dist; |
979 } | 1003 } |
980 | 1004 |
981 static void update_stats(VP9_COMMON *cm, ThreadData *td) { | 1005 static void update_stats(VP9_COMMON *cm, ThreadData *td) { |
982 const MACROBLOCK *x = &td->mb; | 1006 const MACROBLOCK *x = &td->mb; |
983 const MACROBLOCKD *const xd = &x->e_mbd; | 1007 const MACROBLOCKD *const xd = &x->e_mbd; |
984 const MODE_INFO *const mi = xd->mi[0].src_mi; | 1008 const MODE_INFO *const mi = xd->mi[0].src_mi; |
985 const MB_MODE_INFO *const mbmi = &mi->mbmi; | 1009 const MB_MODE_INFO *const mbmi = &mi->mbmi; |
| 1010 const BLOCK_SIZE bsize = mbmi->sb_type; |
986 | 1011 |
987 if (!frame_is_intra_only(cm)) { | 1012 if (!frame_is_intra_only(cm)) { |
| 1013 FRAME_COUNTS *const counts = td->counts; |
| 1014 const int inter_block = is_inter_block(mbmi); |
988 const int seg_ref_active = vp9_segfeature_active(&cm->seg, mbmi->segment_id, | 1015 const int seg_ref_active = vp9_segfeature_active(&cm->seg, mbmi->segment_id, |
989 SEG_LVL_REF_FRAME); | 1016 SEG_LVL_REF_FRAME); |
990 if (!seg_ref_active) { | 1017 if (!seg_ref_active) { |
991 FRAME_COUNTS *const counts = td->counts; | |
992 const int inter_block = is_inter_block(mbmi); | |
993 | |
994 counts->intra_inter[vp9_get_intra_inter_context(xd)][inter_block]++; | 1018 counts->intra_inter[vp9_get_intra_inter_context(xd)][inter_block]++; |
995 | |
996 // If the segment reference feature is enabled we have only a single | 1019 // If the segment reference feature is enabled we have only a single |
997 // reference frame allowed for the segment so exclude it from | 1020 // reference frame allowed for the segment so exclude it from |
998 // the reference frame counts used to work out probabilities. | 1021 // the reference frame counts used to work out probabilities. |
999 if (inter_block) { | 1022 if (inter_block) { |
1000 const MV_REFERENCE_FRAME ref0 = mbmi->ref_frame[0]; | 1023 const MV_REFERENCE_FRAME ref0 = mbmi->ref_frame[0]; |
1001 | |
1002 if (cm->reference_mode == REFERENCE_MODE_SELECT) | 1024 if (cm->reference_mode == REFERENCE_MODE_SELECT) |
1003 counts->comp_inter[vp9_get_reference_mode_context(cm, xd)] | 1025 counts->comp_inter[vp9_get_reference_mode_context(cm, xd)] |
1004 [has_second_ref(mbmi)]++; | 1026 [has_second_ref(mbmi)]++; |
1005 | 1027 |
1006 if (has_second_ref(mbmi)) { | 1028 if (has_second_ref(mbmi)) { |
1007 counts->comp_ref[vp9_get_pred_context_comp_ref_p(cm, xd)] | 1029 counts->comp_ref[vp9_get_pred_context_comp_ref_p(cm, xd)] |
1008 [ref0 == GOLDEN_FRAME]++; | 1030 [ref0 == GOLDEN_FRAME]++; |
1009 } else { | 1031 } else { |
1010 counts->single_ref[vp9_get_pred_context_single_ref_p1(xd)][0] | 1032 counts->single_ref[vp9_get_pred_context_single_ref_p1(xd)][0] |
1011 [ref0 != LAST_FRAME]++; | 1033 [ref0 != LAST_FRAME]++; |
1012 if (ref0 != LAST_FRAME) | 1034 if (ref0 != LAST_FRAME) |
1013 counts->single_ref[vp9_get_pred_context_single_ref_p2(xd)][1] | 1035 counts->single_ref[vp9_get_pred_context_single_ref_p2(xd)][1] |
1014 [ref0 != GOLDEN_FRAME]++; | 1036 [ref0 != GOLDEN_FRAME]++; |
1015 } | 1037 } |
1016 } | 1038 } |
1017 } | 1039 } |
| 1040 if (inter_block && |
| 1041 !vp9_segfeature_active(&cm->seg, mbmi->segment_id, SEG_LVL_SKIP)) { |
| 1042 const int mode_ctx = mbmi->mode_context[mbmi->ref_frame[0]]; |
| 1043 if (bsize >= BLOCK_8X8) { |
| 1044 const PREDICTION_MODE mode = mbmi->mode; |
| 1045 ++counts->inter_mode[mode_ctx][INTER_OFFSET(mode)]; |
| 1046 } else { |
| 1047 const int num_4x4_w = num_4x4_blocks_wide_lookup[bsize]; |
| 1048 const int num_4x4_h = num_4x4_blocks_high_lookup[bsize]; |
| 1049 int idx, idy; |
| 1050 for (idy = 0; idy < 2; idy += num_4x4_h) { |
| 1051 for (idx = 0; idx < 2; idx += num_4x4_w) { |
| 1052 const int j = idy * 2 + idx; |
| 1053 const PREDICTION_MODE b_mode = mi->bmi[j].as_mode; |
| 1054 ++counts->inter_mode[mode_ctx][INTER_OFFSET(b_mode)]; |
| 1055 } |
| 1056 } |
| 1057 } |
| 1058 } |
1018 } | 1059 } |
1019 } | 1060 } |
1020 | 1061 |
1021 static void restore_context(MACROBLOCK *const x, int mi_row, int mi_col, | 1062 static void restore_context(MACROBLOCK *const x, int mi_row, int mi_col, |
1022 ENTROPY_CONTEXT a[16 * MAX_MB_PLANE], | 1063 ENTROPY_CONTEXT a[16 * MAX_MB_PLANE], |
1023 ENTROPY_CONTEXT l[16 * MAX_MB_PLANE], | 1064 ENTROPY_CONTEXT l[16 * MAX_MB_PLANE], |
1024 PARTITION_CONTEXT sa[8], PARTITION_CONTEXT sl[8], | 1065 PARTITION_CONTEXT sa[8], PARTITION_CONTEXT sl[8], |
1025 BLOCK_SIZE bsize) { | 1066 BLOCK_SIZE bsize) { |
1026 MACROBLOCKD *const xd = &x->e_mbd; | 1067 MACROBLOCKD *const xd = &x->e_mbd; |
1027 int p; | 1068 int p; |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1157 pc_tree->split[0]); | 1198 pc_tree->split[0]); |
1158 encode_sb(cpi, td, tile, tp, mi_row, mi_col + hbs, output_enabled, | 1199 encode_sb(cpi, td, tile, tp, mi_row, mi_col + hbs, output_enabled, |
1159 subsize, pc_tree->split[1]); | 1200 subsize, pc_tree->split[1]); |
1160 encode_sb(cpi, td, tile, tp, mi_row + hbs, mi_col, output_enabled, | 1201 encode_sb(cpi, td, tile, tp, mi_row + hbs, mi_col, output_enabled, |
1161 subsize, pc_tree->split[2]); | 1202 subsize, pc_tree->split[2]); |
1162 encode_sb(cpi, td, tile, tp, mi_row + hbs, mi_col + hbs, output_enabled, | 1203 encode_sb(cpi, td, tile, tp, mi_row + hbs, mi_col + hbs, output_enabled, |
1163 subsize, pc_tree->split[3]); | 1204 subsize, pc_tree->split[3]); |
1164 } | 1205 } |
1165 break; | 1206 break; |
1166 default: | 1207 default: |
1167 assert("Invalid partition type."); | 1208 assert(0 && "Invalid partition type."); |
1168 break; | 1209 break; |
1169 } | 1210 } |
1170 | 1211 |
1171 if (partition != PARTITION_SPLIT || bsize == BLOCK_8X8) | 1212 if (partition != PARTITION_SPLIT || bsize == BLOCK_8X8) |
1172 update_partition_context(xd, mi_row, mi_col, subsize, bsize); | 1213 update_partition_context(xd, mi_row, mi_col, subsize, bsize); |
1173 } | 1214 } |
1174 | 1215 |
1175 // Check to see if the given partition size is allowed for a specified number | 1216 // Check to see if the given partition size is allowed for a specified number |
1176 // of 8x8 block rows and columns remaining in the image. | 1217 // of 8x8 block rows and columns remaining in the image. |
1177 // If not then return the largest allowed partition size | 1218 // If not then return the largest allowed partition size |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1350 VP9_COMMON *const cm = &cpi->common; | 1391 VP9_COMMON *const cm = &cpi->common; |
1351 MACROBLOCK *const x = &td->mb; | 1392 MACROBLOCK *const x = &td->mb; |
1352 MACROBLOCKD *const xd = &x->e_mbd; | 1393 MACROBLOCKD *const xd = &x->e_mbd; |
1353 MODE_INFO *const mi = xd->mi[0].src_mi; | 1394 MODE_INFO *const mi = xd->mi[0].src_mi; |
1354 MB_MODE_INFO *const mbmi = &xd->mi[0].src_mi->mbmi; | 1395 MB_MODE_INFO *const mbmi = &xd->mi[0].src_mi->mbmi; |
1355 const struct segmentation *const seg = &cm->seg; | 1396 const struct segmentation *const seg = &cm->seg; |
1356 const int bw = num_8x8_blocks_wide_lookup[mi->mbmi.sb_type]; | 1397 const int bw = num_8x8_blocks_wide_lookup[mi->mbmi.sb_type]; |
1357 const int bh = num_8x8_blocks_high_lookup[mi->mbmi.sb_type]; | 1398 const int bh = num_8x8_blocks_high_lookup[mi->mbmi.sb_type]; |
1358 const int x_mis = MIN(bw, cm->mi_cols - mi_col); | 1399 const int x_mis = MIN(bw, cm->mi_cols - mi_col); |
1359 const int y_mis = MIN(bh, cm->mi_rows - mi_row); | 1400 const int y_mis = MIN(bh, cm->mi_rows - mi_row); |
1360 MV_REF *const frame_mvs = | |
1361 cm->cur_frame->mvs + mi_row * cm->mi_cols + mi_col; | |
1362 int w, h; | |
1363 | 1401 |
1364 *(xd->mi[0].src_mi) = ctx->mic; | 1402 xd->mi[0] = ctx->mic; |
1365 xd->mi[0].src_mi = &xd->mi[0]; | 1403 xd->mi[0].src_mi = &xd->mi[0]; |
1366 | 1404 |
1367 if (seg->enabled && cpi->oxcf.aq_mode) { | 1405 if (seg->enabled && cpi->oxcf.aq_mode) { |
1368 // For in frame complexity AQ or variance AQ, copy segment_id from | 1406 // For in frame complexity AQ or variance AQ, copy segment_id from |
1369 // segmentation_map. | 1407 // segmentation_map. |
1370 if (cpi->oxcf.aq_mode == COMPLEXITY_AQ || | 1408 if (cpi->oxcf.aq_mode == COMPLEXITY_AQ || |
1371 cpi->oxcf.aq_mode == VARIANCE_AQ ) { | 1409 cpi->oxcf.aq_mode == VARIANCE_AQ ) { |
1372 const uint8_t *const map = seg->update_map ? cpi->segmentation_map | 1410 const uint8_t *const map = seg->update_map ? cpi->segmentation_map |
1373 : cm->last_frame_seg_map; | 1411 : cm->last_frame_seg_map; |
1374 mbmi->segment_id = vp9_get_segment_id(cm, map, bsize, mi_row, mi_col); | 1412 mbmi->segment_id = vp9_get_segment_id(cm, map, bsize, mi_row, mi_col); |
1375 } else { | 1413 } else { |
1376 // Setting segmentation map for cyclic_refresh | 1414 // Setting segmentation map for cyclic_refresh |
1377 vp9_cyclic_refresh_update_segment(cpi, mbmi, mi_row, mi_col, bsize, 1, | 1415 vp9_cyclic_refresh_update_segment(cpi, mbmi, mi_row, mi_col, bsize, 1, |
1378 ctx->rate); | 1416 ctx->rate); |
1379 } | 1417 } |
1380 vp9_init_plane_quantizers(cpi, x); | 1418 vp9_init_plane_quantizers(cpi, x); |
1381 } | 1419 } |
1382 | 1420 |
1383 if (is_inter_block(mbmi)) { | 1421 if (is_inter_block(mbmi)) { |
1384 vp9_update_mv_count(td); | 1422 vp9_update_mv_count(td); |
1385 | |
1386 if (cm->interp_filter == SWITCHABLE) { | 1423 if (cm->interp_filter == SWITCHABLE) { |
1387 const int pred_ctx = vp9_get_pred_context_switchable_interp(xd); | 1424 const int pred_ctx = vp9_get_pred_context_switchable_interp(xd); |
1388 ++td->counts->switchable_interp[pred_ctx][mbmi->interp_filter]; | 1425 ++td->counts->switchable_interp[pred_ctx][mbmi->interp_filter]; |
1389 } | 1426 } |
1390 } | |
1391 | 1427 |
1392 for (h = 0; h < y_mis; ++h) { | 1428 if (mbmi->sb_type < BLOCK_8X8) { |
1393 MV_REF *const frame_mv = frame_mvs + h * cm->mi_cols; | 1429 mbmi->mv[0].as_int = mi->bmi[3].as_mv[0].as_int; |
1394 for (w = 0; w < x_mis; ++w) { | 1430 mbmi->mv[1].as_int = mi->bmi[3].as_mv[1].as_int; |
1395 MV_REF *const mv = frame_mv + w; | |
1396 mv->ref_frame[0] = mi->src_mi->mbmi.ref_frame[0]; | |
1397 mv->ref_frame[1] = mi->src_mi->mbmi.ref_frame[1]; | |
1398 mv->mv[0].as_int = mi->src_mi->mbmi.mv[0].as_int; | |
1399 mv->mv[1].as_int = mi->src_mi->mbmi.mv[1].as_int; | |
1400 } | 1431 } |
1401 } | 1432 } |
1402 | 1433 |
| 1434 if (cm->use_prev_frame_mvs) { |
| 1435 MV_REF *const frame_mvs = |
| 1436 cm->cur_frame->mvs + mi_row * cm->mi_cols + mi_col; |
| 1437 int w, h; |
| 1438 |
| 1439 for (h = 0; h < y_mis; ++h) { |
| 1440 MV_REF *const frame_mv = frame_mvs + h * cm->mi_cols; |
| 1441 for (w = 0; w < x_mis; ++w) { |
| 1442 MV_REF *const mv = frame_mv + w; |
| 1443 mv->ref_frame[0] = mi->src_mi->mbmi.ref_frame[0]; |
| 1444 mv->ref_frame[1] = mi->src_mi->mbmi.ref_frame[1]; |
| 1445 mv->mv[0].as_int = mi->src_mi->mbmi.mv[0].as_int; |
| 1446 mv->mv[1].as_int = mi->src_mi->mbmi.mv[1].as_int; |
| 1447 } |
| 1448 } |
| 1449 } |
| 1450 |
1403 x->skip = ctx->skip; | 1451 x->skip = ctx->skip; |
1404 x->skip_txfm[0] = mbmi->segment_id ? 0 : ctx->skip_txfm[0]; | 1452 x->skip_txfm[0] = mbmi->segment_id ? 0 : ctx->skip_txfm[0]; |
1405 } | 1453 } |
1406 | 1454 |
1407 static void encode_b_rt(VP9_COMP *cpi, ThreadData *td, | 1455 static void encode_b_rt(VP9_COMP *cpi, ThreadData *td, |
1408 const TileInfo *const tile, | 1456 const TileInfo *const tile, |
1409 TOKENEXTRA **tp, int mi_row, int mi_col, | 1457 TOKENEXTRA **tp, int mi_row, int mi_col, |
1410 int output_enabled, BLOCK_SIZE bsize, | 1458 int output_enabled, BLOCK_SIZE bsize, |
1411 PICK_MODE_CONTEXT *ctx) { | 1459 PICK_MODE_CONTEXT *ctx) { |
1412 MACROBLOCK *const x = &td->mb; | 1460 MACROBLOCK *const x = &td->mb; |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1484 encode_sb_rt(cpi, td, tile, tp, mi_row, mi_col, output_enabled, subsize, | 1532 encode_sb_rt(cpi, td, tile, tp, mi_row, mi_col, output_enabled, subsize, |
1485 pc_tree->split[0]); | 1533 pc_tree->split[0]); |
1486 encode_sb_rt(cpi, td, tile, tp, mi_row, mi_col + hbs, output_enabled, | 1534 encode_sb_rt(cpi, td, tile, tp, mi_row, mi_col + hbs, output_enabled, |
1487 subsize, pc_tree->split[1]); | 1535 subsize, pc_tree->split[1]); |
1488 encode_sb_rt(cpi, td, tile, tp, mi_row + hbs, mi_col, output_enabled, | 1536 encode_sb_rt(cpi, td, tile, tp, mi_row + hbs, mi_col, output_enabled, |
1489 subsize, pc_tree->split[2]); | 1537 subsize, pc_tree->split[2]); |
1490 encode_sb_rt(cpi, td, tile, tp, mi_row + hbs, mi_col + hbs, | 1538 encode_sb_rt(cpi, td, tile, tp, mi_row + hbs, mi_col + hbs, |
1491 output_enabled, subsize, pc_tree->split[3]); | 1539 output_enabled, subsize, pc_tree->split[3]); |
1492 break; | 1540 break; |
1493 default: | 1541 default: |
1494 assert("Invalid partition type."); | 1542 assert(0 && "Invalid partition type."); |
1495 break; | 1543 break; |
1496 } | 1544 } |
1497 | 1545 |
1498 if (partition != PARTITION_SPLIT || bsize == BLOCK_8X8) | 1546 if (partition != PARTITION_SPLIT || bsize == BLOCK_8X8) |
1499 update_partition_context(xd, mi_row, mi_col, subsize, bsize); | 1547 update_partition_context(xd, mi_row, mi_col, subsize, bsize); |
1500 } | 1548 } |
1501 | 1549 |
1502 static void rd_use_partition(VP9_COMP *cpi, | 1550 static void rd_use_partition(VP9_COMP *cpi, |
1503 ThreadData *td, | 1551 ThreadData *td, |
1504 TileDataEnc *tile_data, | 1552 TileDataEnc *tile_data, |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1754 | 1802 |
1755 restore_context(x, mi_row, mi_col, a, l, sa, sl, bsize); | 1803 restore_context(x, mi_row, mi_col, a, l, sa, sl, bsize); |
1756 | 1804 |
1757 // We must have chosen a partitioning and encoding or we'll fail later on. | 1805 // We must have chosen a partitioning and encoding or we'll fail later on. |
1758 // No other opportunities for success. | 1806 // No other opportunities for success. |
1759 if (bsize == BLOCK_64X64) | 1807 if (bsize == BLOCK_64X64) |
1760 assert(chosen_rdc.rate < INT_MAX && chosen_rdc.dist < INT64_MAX); | 1808 assert(chosen_rdc.rate < INT_MAX && chosen_rdc.dist < INT64_MAX); |
1761 | 1809 |
1762 if (do_recon) { | 1810 if (do_recon) { |
1763 int output_enabled = (bsize == BLOCK_64X64); | 1811 int output_enabled = (bsize == BLOCK_64X64); |
1764 | |
1765 // Check the projected output rate for this SB against it's target | |
1766 // and and if necessary apply a Q delta using segmentation to get | |
1767 // closer to the target. | |
1768 if ((cpi->oxcf.aq_mode == COMPLEXITY_AQ) && cm->seg.update_map) { | |
1769 vp9_select_in_frame_q_segment(cpi, x, bsize, mi_row, mi_col, | |
1770 output_enabled, chosen_rdc.rate); | |
1771 } | |
1772 encode_sb(cpi, td, tile_info, tp, mi_row, mi_col, output_enabled, bsize, | 1812 encode_sb(cpi, td, tile_info, tp, mi_row, mi_col, output_enabled, bsize, |
1773 pc_tree); | 1813 pc_tree); |
1774 } | 1814 } |
1775 | 1815 |
1776 *rate = chosen_rdc.rate; | 1816 *rate = chosen_rdc.rate; |
1777 *dist = chosen_rdc.dist; | 1817 *dist = chosen_rdc.dist; |
1778 } | 1818 } |
1779 | 1819 |
1780 static const BLOCK_SIZE min_partition_size[BLOCK_SIZES] = { | 1820 static const BLOCK_SIZE min_partition_size[BLOCK_SIZES] = { |
1781 BLOCK_4X4, BLOCK_4X4, BLOCK_4X4, | 1821 BLOCK_4X4, BLOCK_4X4, BLOCK_4X4, |
(...skipping 711 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2493 // warning related to the fact that best_rd isn't used after this | 2533 // warning related to the fact that best_rd isn't used after this |
2494 // point. This code should be refactored so that the duplicate | 2534 // point. This code should be refactored so that the duplicate |
2495 // checks occur in some sub function and thus are used... | 2535 // checks occur in some sub function and thus are used... |
2496 (void) best_rd; | 2536 (void) best_rd; |
2497 *rd_cost = best_rdc; | 2537 *rd_cost = best_rdc; |
2498 | 2538 |
2499 | 2539 |
2500 if (best_rdc.rate < INT_MAX && best_rdc.dist < INT64_MAX && | 2540 if (best_rdc.rate < INT_MAX && best_rdc.dist < INT64_MAX && |
2501 pc_tree->index != 3) { | 2541 pc_tree->index != 3) { |
2502 int output_enabled = (bsize == BLOCK_64X64); | 2542 int output_enabled = (bsize == BLOCK_64X64); |
2503 | |
2504 // Check the projected output rate for this SB against it's target | |
2505 // and and if necessary apply a Q delta using segmentation to get | |
2506 // closer to the target. | |
2507 if ((cpi->oxcf.aq_mode == COMPLEXITY_AQ) && cm->seg.update_map) | |
2508 vp9_select_in_frame_q_segment(cpi, x, bsize, mi_row, mi_col, | |
2509 output_enabled, best_rdc.rate); | |
2510 encode_sb(cpi, td, tile_info, tp, mi_row, mi_col, output_enabled, | 2543 encode_sb(cpi, td, tile_info, tp, mi_row, mi_col, output_enabled, |
2511 bsize, pc_tree); | 2544 bsize, pc_tree); |
2512 } | 2545 } |
2513 | 2546 |
2514 if (bsize == BLOCK_64X64) { | 2547 if (bsize == BLOCK_64X64) { |
2515 assert(tp_orig < *tp); | 2548 assert(tp_orig < *tp); |
2516 assert(best_rdc.rate < INT_MAX); | 2549 assert(best_rdc.rate < INT_MAX); |
2517 assert(best_rdc.dist < INT64_MAX); | 2550 assert(best_rdc.dist < INT64_MAX); |
2518 } else { | 2551 } else { |
2519 assert(tp_orig == *tp); | 2552 assert(tp_orig == *tp); |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2655 return ONLY_4X4; | 2688 return ONLY_4X4; |
2656 if (cpi->sf.tx_size_search_method == USE_LARGESTALL) | 2689 if (cpi->sf.tx_size_search_method == USE_LARGESTALL) |
2657 return ALLOW_32X32; | 2690 return ALLOW_32X32; |
2658 else if (cpi->sf.tx_size_search_method == USE_FULL_RD|| | 2691 else if (cpi->sf.tx_size_search_method == USE_FULL_RD|| |
2659 cpi->sf.tx_size_search_method == USE_TX_8X8) | 2692 cpi->sf.tx_size_search_method == USE_TX_8X8) |
2660 return TX_MODE_SELECT; | 2693 return TX_MODE_SELECT; |
2661 else | 2694 else |
2662 return cpi->common.tx_mode; | 2695 return cpi->common.tx_mode; |
2663 } | 2696 } |
2664 | 2697 |
| 2698 static void hybrid_intra_mode_search(VP9_COMP *cpi, MACROBLOCK *const x, |
| 2699 RD_COST *rd_cost, BLOCK_SIZE bsize, |
| 2700 PICK_MODE_CONTEXT *ctx) { |
| 2701 if (bsize < BLOCK_16X16) |
| 2702 vp9_rd_pick_intra_mode_sb(cpi, x, rd_cost, bsize, ctx, INT64_MAX); |
| 2703 else |
| 2704 vp9_pick_intra_mode(cpi, x, rd_cost, bsize, ctx); |
| 2705 } |
| 2706 |
2665 static void nonrd_pick_sb_modes(VP9_COMP *cpi, | 2707 static void nonrd_pick_sb_modes(VP9_COMP *cpi, |
2666 TileDataEnc *tile_data, MACROBLOCK *const x, | 2708 TileDataEnc *tile_data, MACROBLOCK *const x, |
2667 int mi_row, int mi_col, RD_COST *rd_cost, | 2709 int mi_row, int mi_col, RD_COST *rd_cost, |
2668 BLOCK_SIZE bsize, PICK_MODE_CONTEXT *ctx) { | 2710 BLOCK_SIZE bsize, PICK_MODE_CONTEXT *ctx) { |
2669 VP9_COMMON *const cm = &cpi->common; | 2711 VP9_COMMON *const cm = &cpi->common; |
2670 TileInfo *const tile_info = &tile_data->tile_info; | 2712 TileInfo *const tile_info = &tile_data->tile_info; |
2671 MACROBLOCKD *const xd = &x->e_mbd; | 2713 MACROBLOCKD *const xd = &x->e_mbd; |
2672 MB_MODE_INFO *mbmi; | 2714 MB_MODE_INFO *mbmi; |
2673 set_offsets(cpi, tile_info, x, mi_row, mi_col, bsize); | 2715 set_offsets(cpi, tile_info, x, mi_row, mi_col, bsize); |
2674 mbmi = &xd->mi[0].src_mi->mbmi; | 2716 mbmi = &xd->mi[0].src_mi->mbmi; |
2675 mbmi->sb_type = bsize; | 2717 mbmi->sb_type = bsize; |
2676 | 2718 |
2677 if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ && cm->seg.enabled) | 2719 if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ && cm->seg.enabled) |
2678 if (mbmi->segment_id) | 2720 if (mbmi->segment_id) |
2679 x->rdmult = vp9_cyclic_refresh_get_rdmult(cpi->cyclic_refresh); | 2721 x->rdmult = vp9_cyclic_refresh_get_rdmult(cpi->cyclic_refresh); |
2680 | 2722 |
2681 if (cm->frame_type == KEY_FRAME) | 2723 if (cm->frame_type == KEY_FRAME) |
2682 vp9_pick_intra_mode(cpi, x, rd_cost, bsize, ctx); | 2724 hybrid_intra_mode_search(cpi, x, rd_cost, bsize, ctx); |
2683 else if (vp9_segfeature_active(&cm->seg, mbmi->segment_id, SEG_LVL_SKIP)) | 2725 else if (vp9_segfeature_active(&cm->seg, mbmi->segment_id, SEG_LVL_SKIP)) |
2684 set_mode_info_seg_skip(x, cm->tx_mode, rd_cost, bsize); | 2726 set_mode_info_seg_skip(x, cm->tx_mode, rd_cost, bsize); |
2685 else | 2727 else if (bsize >= BLOCK_8X8) |
2686 vp9_pick_inter_mode(cpi, x, tile_data, mi_row, mi_col, | 2728 vp9_pick_inter_mode(cpi, x, tile_data, mi_row, mi_col, |
2687 rd_cost, bsize, ctx); | 2729 rd_cost, bsize, ctx); |
| 2730 else |
| 2731 vp9_pick_inter_mode_sub8x8(cpi, x, tile_data, mi_row, mi_col, |
| 2732 rd_cost, bsize, ctx); |
2688 | 2733 |
2689 duplicate_mode_info_in_sb(cm, xd, mi_row, mi_col, bsize); | 2734 duplicate_mode_info_in_sb(cm, xd, mi_row, mi_col, bsize); |
2690 | 2735 |
2691 if (rd_cost->rate == INT_MAX) | 2736 if (rd_cost->rate == INT_MAX) |
2692 vp9_rd_cost_reset(rd_cost); | 2737 vp9_rd_cost_reset(rd_cost); |
2693 | 2738 |
2694 ctx->rate = rd_cost->rate; | 2739 ctx->rate = rd_cost->rate; |
2695 ctx->dist = rd_cost->dist; | 2740 ctx->dist = rd_cost->dist; |
2696 } | 2741 } |
2697 | 2742 |
2698 static void fill_mode_info_sb(VP9_COMMON *cm, MACROBLOCK *x, | 2743 static void fill_mode_info_sb(VP9_COMMON *cm, MACROBLOCK *x, |
2699 int mi_row, int mi_col, | 2744 int mi_row, int mi_col, |
2700 BLOCK_SIZE bsize, BLOCK_SIZE subsize, | 2745 BLOCK_SIZE bsize, BLOCK_SIZE subsize, |
2701 PC_TREE *pc_tree) { | 2746 PC_TREE *pc_tree) { |
2702 MACROBLOCKD *xd = &x->e_mbd; | 2747 MACROBLOCKD *xd = &x->e_mbd; |
2703 int bsl = b_width_log2_lookup[bsize], hbs = (1 << bsl) / 4; | 2748 int bsl = b_width_log2_lookup[bsize], hbs = (1 << bsl) / 4; |
2704 PARTITION_TYPE partition = pc_tree->partitioning; | 2749 PARTITION_TYPE partition = pc_tree->partitioning; |
2705 | 2750 |
2706 assert(bsize >= BLOCK_8X8); | 2751 assert(bsize >= BLOCK_8X8); |
2707 | 2752 |
2708 if (mi_row >= cm->mi_rows || mi_col >= cm->mi_cols) | 2753 if (mi_row >= cm->mi_rows || mi_col >= cm->mi_cols) |
2709 return; | 2754 return; |
2710 | 2755 |
2711 switch (partition) { | 2756 switch (partition) { |
2712 case PARTITION_NONE: | 2757 case PARTITION_NONE: |
2713 set_modeinfo_offsets(cm, xd, mi_row, mi_col); | 2758 set_mode_info_offsets(cm, xd, mi_row, mi_col); |
2714 *(xd->mi[0].src_mi) = pc_tree->none.mic; | 2759 *(xd->mi[0].src_mi) = pc_tree->none.mic; |
2715 duplicate_mode_info_in_sb(cm, xd, mi_row, mi_col, bsize); | 2760 duplicate_mode_info_in_sb(cm, xd, mi_row, mi_col, bsize); |
2716 break; | 2761 break; |
2717 case PARTITION_VERT: | 2762 case PARTITION_VERT: |
2718 set_modeinfo_offsets(cm, xd, mi_row, mi_col); | 2763 set_mode_info_offsets(cm, xd, mi_row, mi_col); |
2719 *(xd->mi[0].src_mi) = pc_tree->vertical[0].mic; | 2764 *(xd->mi[0].src_mi) = pc_tree->vertical[0].mic; |
2720 duplicate_mode_info_in_sb(cm, xd, mi_row, mi_col, bsize); | 2765 duplicate_mode_info_in_sb(cm, xd, mi_row, mi_col, bsize); |
2721 | 2766 |
2722 if (mi_col + hbs < cm->mi_cols) { | 2767 if (mi_col + hbs < cm->mi_cols) { |
2723 set_modeinfo_offsets(cm, xd, mi_row, mi_col + hbs); | 2768 set_mode_info_offsets(cm, xd, mi_row, mi_col + hbs); |
2724 *(xd->mi[0].src_mi) = pc_tree->vertical[1].mic; | 2769 *(xd->mi[0].src_mi) = pc_tree->vertical[1].mic; |
2725 duplicate_mode_info_in_sb(cm, xd, mi_row, mi_col + hbs, bsize); | 2770 duplicate_mode_info_in_sb(cm, xd, mi_row, mi_col + hbs, bsize); |
2726 } | 2771 } |
2727 break; | 2772 break; |
2728 case PARTITION_HORZ: | 2773 case PARTITION_HORZ: |
2729 set_modeinfo_offsets(cm, xd, mi_row, mi_col); | 2774 set_mode_info_offsets(cm, xd, mi_row, mi_col); |
2730 *(xd->mi[0].src_mi) = pc_tree->horizontal[0].mic; | 2775 *(xd->mi[0].src_mi) = pc_tree->horizontal[0].mic; |
2731 duplicate_mode_info_in_sb(cm, xd, mi_row, mi_col, bsize); | 2776 duplicate_mode_info_in_sb(cm, xd, mi_row, mi_col, bsize); |
2732 if (mi_row + hbs < cm->mi_rows) { | 2777 if (mi_row + hbs < cm->mi_rows) { |
2733 set_modeinfo_offsets(cm, xd, mi_row + hbs, mi_col); | 2778 set_mode_info_offsets(cm, xd, mi_row + hbs, mi_col); |
2734 *(xd->mi[0].src_mi) = pc_tree->horizontal[1].mic; | 2779 *(xd->mi[0].src_mi) = pc_tree->horizontal[1].mic; |
2735 duplicate_mode_info_in_sb(cm, xd, mi_row + hbs, mi_col, bsize); | 2780 duplicate_mode_info_in_sb(cm, xd, mi_row + hbs, mi_col, bsize); |
2736 } | 2781 } |
2737 break; | 2782 break; |
2738 case PARTITION_SPLIT: { | 2783 case PARTITION_SPLIT: { |
2739 BLOCK_SIZE subsubsize = get_subsize(subsize, PARTITION_SPLIT); | 2784 BLOCK_SIZE subsubsize = get_subsize(subsize, PARTITION_SPLIT); |
2740 fill_mode_info_sb(cm, x, mi_row, mi_col, subsize, | 2785 fill_mode_info_sb(cm, x, mi_row, mi_col, subsize, |
2741 subsubsize, pc_tree->split[0]); | 2786 subsubsize, pc_tree->split[0]); |
2742 fill_mode_info_sb(cm, x, mi_row, mi_col + hbs, subsize, | 2787 fill_mode_info_sb(cm, x, mi_row, mi_col + hbs, subsize, |
2743 subsubsize, pc_tree->split[1]); | 2788 subsubsize, pc_tree->split[1]); |
(...skipping 24 matching lines...) Expand all Loading... |
2768 } | 2813 } |
2769 } | 2814 } |
2770 | 2815 |
2771 static void nonrd_pick_partition(VP9_COMP *cpi, ThreadData *td, | 2816 static void nonrd_pick_partition(VP9_COMP *cpi, ThreadData *td, |
2772 TileDataEnc *tile_data, | 2817 TileDataEnc *tile_data, |
2773 TOKENEXTRA **tp, int mi_row, | 2818 TOKENEXTRA **tp, int mi_row, |
2774 int mi_col, BLOCK_SIZE bsize, RD_COST *rd_cost, | 2819 int mi_col, BLOCK_SIZE bsize, RD_COST *rd_cost, |
2775 int do_recon, int64_t best_rd, | 2820 int do_recon, int64_t best_rd, |
2776 PC_TREE *pc_tree) { | 2821 PC_TREE *pc_tree) { |
2777 const SPEED_FEATURES *const sf = &cpi->sf; | 2822 const SPEED_FEATURES *const sf = &cpi->sf; |
2778 const VP9EncoderConfig *const oxcf = &cpi->oxcf; | |
2779 VP9_COMMON *const cm = &cpi->common; | 2823 VP9_COMMON *const cm = &cpi->common; |
2780 TileInfo *const tile_info = &tile_data->tile_info; | 2824 TileInfo *const tile_info = &tile_data->tile_info; |
2781 MACROBLOCK *const x = &td->mb; | 2825 MACROBLOCK *const x = &td->mb; |
2782 MACROBLOCKD *const xd = &x->e_mbd; | 2826 MACROBLOCKD *const xd = &x->e_mbd; |
2783 const int ms = num_8x8_blocks_wide_lookup[bsize] / 2; | 2827 const int ms = num_8x8_blocks_wide_lookup[bsize] / 2; |
2784 TOKENEXTRA *tp_orig = *tp; | 2828 TOKENEXTRA *tp_orig = *tp; |
2785 PICK_MODE_CONTEXT *ctx = &pc_tree->none; | 2829 PICK_MODE_CONTEXT *ctx = &pc_tree->none; |
2786 int i; | 2830 int i; |
2787 BLOCK_SIZE subsize = bsize; | 2831 BLOCK_SIZE subsize = bsize; |
2788 RD_COST this_rdc, sum_rdc, best_rdc; | 2832 RD_COST this_rdc, sum_rdc, best_rdc; |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3000 return; | 3044 return; |
3001 } | 3045 } |
3002 | 3046 |
3003 // update mode info array | 3047 // update mode info array |
3004 subsize = get_subsize(bsize, pc_tree->partitioning); | 3048 subsize = get_subsize(bsize, pc_tree->partitioning); |
3005 fill_mode_info_sb(cm, x, mi_row, mi_col, bsize, subsize, | 3049 fill_mode_info_sb(cm, x, mi_row, mi_col, bsize, subsize, |
3006 pc_tree); | 3050 pc_tree); |
3007 | 3051 |
3008 if (best_rdc.rate < INT_MAX && best_rdc.dist < INT64_MAX && do_recon) { | 3052 if (best_rdc.rate < INT_MAX && best_rdc.dist < INT64_MAX && do_recon) { |
3009 int output_enabled = (bsize == BLOCK_64X64); | 3053 int output_enabled = (bsize == BLOCK_64X64); |
3010 | |
3011 // Check the projected output rate for this SB against it's target | |
3012 // and and if necessary apply a Q delta using segmentation to get | |
3013 // closer to the target. | |
3014 if ((oxcf->aq_mode == COMPLEXITY_AQ) && cm->seg.update_map) { | |
3015 vp9_select_in_frame_q_segment(cpi, x, bsize, mi_row, mi_col, | |
3016 output_enabled, best_rdc.rate); | |
3017 } | |
3018 encode_sb_rt(cpi, td, tile_info, tp, mi_row, mi_col, output_enabled, | 3054 encode_sb_rt(cpi, td, tile_info, tp, mi_row, mi_col, output_enabled, |
3019 bsize, pc_tree); | 3055 bsize, pc_tree); |
3020 } | 3056 } |
3021 | 3057 |
3022 if (bsize == BLOCK_64X64) { | 3058 if (bsize == BLOCK_64X64) { |
3023 assert(tp_orig < *tp); | 3059 assert(tp_orig < *tp); |
3024 assert(best_rdc.rate < INT_MAX); | 3060 assert(best_rdc.rate < INT_MAX); |
3025 assert(best_rdc.dist < INT64_MAX); | 3061 assert(best_rdc.dist < INT64_MAX); |
3026 } else { | 3062 } else { |
3027 assert(tp_orig == *tp); | 3063 assert(tp_orig == *tp); |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3098 case PARTITION_HORZ: | 3134 case PARTITION_HORZ: |
3099 pc_tree->horizontal[0].pred_pixel_ready = 1; | 3135 pc_tree->horizontal[0].pred_pixel_ready = 1; |
3100 nonrd_pick_sb_modes(cpi, tile_data, x, mi_row, mi_col, rd_cost, | 3136 nonrd_pick_sb_modes(cpi, tile_data, x, mi_row, mi_col, rd_cost, |
3101 subsize, &pc_tree->horizontal[0]); | 3137 subsize, &pc_tree->horizontal[0]); |
3102 pc_tree->horizontal[0].mic.mbmi = xd->mi[0].src_mi->mbmi; | 3138 pc_tree->horizontal[0].mic.mbmi = xd->mi[0].src_mi->mbmi; |
3103 pc_tree->horizontal[0].skip_txfm[0] = x->skip_txfm[0]; | 3139 pc_tree->horizontal[0].skip_txfm[0] = x->skip_txfm[0]; |
3104 pc_tree->horizontal[0].skip = x->skip; | 3140 pc_tree->horizontal[0].skip = x->skip; |
3105 if (mi_row + hbs < cm->mi_rows) { | 3141 if (mi_row + hbs < cm->mi_rows) { |
3106 pc_tree->horizontal[1].pred_pixel_ready = 1; | 3142 pc_tree->horizontal[1].pred_pixel_ready = 1; |
3107 nonrd_pick_sb_modes(cpi, tile_data, x, mi_row + hbs, mi_col, | 3143 nonrd_pick_sb_modes(cpi, tile_data, x, mi_row + hbs, mi_col, |
3108 &this_rdc, subsize, &pc_tree->horizontal[0]); | 3144 &this_rdc, subsize, &pc_tree->horizontal[1]); |
3109 pc_tree->horizontal[1].mic.mbmi = xd->mi[0].src_mi->mbmi; | 3145 pc_tree->horizontal[1].mic.mbmi = xd->mi[0].src_mi->mbmi; |
3110 pc_tree->horizontal[1].skip_txfm[0] = x->skip_txfm[0]; | 3146 pc_tree->horizontal[1].skip_txfm[0] = x->skip_txfm[0]; |
3111 pc_tree->horizontal[1].skip = x->skip; | 3147 pc_tree->horizontal[1].skip = x->skip; |
3112 if (this_rdc.rate != INT_MAX && this_rdc.dist != INT64_MAX && | 3148 if (this_rdc.rate != INT_MAX && this_rdc.dist != INT64_MAX && |
3113 rd_cost->rate != INT_MAX && rd_cost->dist != INT64_MAX) { | 3149 rd_cost->rate != INT_MAX && rd_cost->dist != INT64_MAX) { |
3114 rd_cost->rate += this_rdc.rate; | 3150 rd_cost->rate += this_rdc.rate; |
3115 rd_cost->dist += this_rdc.dist; | 3151 rd_cost->dist += this_rdc.dist; |
3116 } | 3152 } |
3117 } | 3153 } |
3118 break; | 3154 break; |
(...skipping 21 matching lines...) Expand all Loading... |
3140 nonrd_select_partition(cpi, td, tile_data, mi + hbs * mis + hbs, tp, | 3176 nonrd_select_partition(cpi, td, tile_data, mi + hbs * mis + hbs, tp, |
3141 mi_row + hbs, mi_col + hbs, subsize, | 3177 mi_row + hbs, mi_col + hbs, subsize, |
3142 output_enabled, &this_rdc, pc_tree->split[3]); | 3178 output_enabled, &this_rdc, pc_tree->split[3]); |
3143 if (this_rdc.rate != INT_MAX && this_rdc.dist != INT64_MAX && | 3179 if (this_rdc.rate != INT_MAX && this_rdc.dist != INT64_MAX && |
3144 rd_cost->rate != INT_MAX && rd_cost->dist != INT64_MAX) { | 3180 rd_cost->rate != INT_MAX && rd_cost->dist != INT64_MAX) { |
3145 rd_cost->rate += this_rdc.rate; | 3181 rd_cost->rate += this_rdc.rate; |
3146 rd_cost->dist += this_rdc.dist; | 3182 rd_cost->dist += this_rdc.dist; |
3147 } | 3183 } |
3148 break; | 3184 break; |
3149 default: | 3185 default: |
3150 assert("Invalid partition type."); | 3186 assert(0 && "Invalid partition type."); |
3151 break; | 3187 break; |
3152 } | 3188 } |
3153 } | 3189 } |
3154 | 3190 |
3155 if (bsize == BLOCK_64X64 && output_enabled) | 3191 if (bsize == BLOCK_64X64 && output_enabled) |
3156 encode_sb_rt(cpi, td, tile_info, tp, mi_row, mi_col, 1, bsize, pc_tree); | 3192 encode_sb_rt(cpi, td, tile_info, tp, mi_row, mi_col, 1, bsize, pc_tree); |
3157 } | 3193 } |
3158 | 3194 |
3159 | 3195 |
3160 static void nonrd_use_partition(VP9_COMP *cpi, | 3196 static void nonrd_use_partition(VP9_COMP *cpi, |
3161 ThreadData *td, | 3197 ThreadData *td, |
3162 TileDataEnc *tile_data, | 3198 TileDataEnc *tile_data, |
3163 MODE_INFO *mi, | 3199 MODE_INFO *mi, |
3164 TOKENEXTRA **tp, | 3200 TOKENEXTRA **tp, |
3165 int mi_row, int mi_col, | 3201 int mi_row, int mi_col, |
3166 BLOCK_SIZE bsize, int output_enabled, | 3202 BLOCK_SIZE bsize, int output_enabled, |
3167 RD_COST *rd_cost, PC_TREE *pc_tree) { | 3203 RD_COST *dummy_cost, PC_TREE *pc_tree) { |
3168 VP9_COMMON *const cm = &cpi->common; | 3204 VP9_COMMON *const cm = &cpi->common; |
3169 TileInfo *tile_info = &tile_data->tile_info; | 3205 TileInfo *tile_info = &tile_data->tile_info; |
3170 MACROBLOCK *const x = &td->mb; | 3206 MACROBLOCK *const x = &td->mb; |
3171 MACROBLOCKD *const xd = &x->e_mbd; | 3207 MACROBLOCKD *const xd = &x->e_mbd; |
3172 const int bsl = b_width_log2_lookup[bsize], hbs = (1 << bsl) / 4; | 3208 const int bsl = b_width_log2_lookup[bsize], hbs = (1 << bsl) / 4; |
3173 const int mis = cm->mi_stride; | 3209 const int mis = cm->mi_stride; |
3174 PARTITION_TYPE partition; | 3210 PARTITION_TYPE partition; |
3175 BLOCK_SIZE subsize; | 3211 BLOCK_SIZE subsize; |
3176 RD_COST this_rdc; | |
3177 | 3212 |
3178 vp9_rd_cost_reset(&this_rdc); | |
3179 if (mi_row >= cm->mi_rows || mi_col >= cm->mi_cols) | 3213 if (mi_row >= cm->mi_rows || mi_col >= cm->mi_cols) |
3180 return; | 3214 return; |
3181 | 3215 |
3182 subsize = (bsize >= BLOCK_8X8) ? mi[0].src_mi->mbmi.sb_type : BLOCK_4X4; | 3216 subsize = (bsize >= BLOCK_8X8) ? mi[0].src_mi->mbmi.sb_type : BLOCK_4X4; |
3183 partition = partition_lookup[bsl][subsize]; | 3217 partition = partition_lookup[bsl][subsize]; |
3184 | 3218 |
3185 if (output_enabled && bsize != BLOCK_4X4) { | 3219 if (output_enabled && bsize != BLOCK_4X4) { |
3186 int ctx = partition_plane_context(xd, mi_row, mi_col, bsize); | 3220 int ctx = partition_plane_context(xd, mi_row, mi_col, bsize); |
3187 td->counts->partition[ctx][partition]++; | 3221 td->counts->partition[ctx][partition]++; |
3188 } | 3222 } |
3189 | 3223 |
3190 switch (partition) { | 3224 switch (partition) { |
3191 case PARTITION_NONE: | 3225 case PARTITION_NONE: |
3192 pc_tree->none.pred_pixel_ready = 1; | 3226 pc_tree->none.pred_pixel_ready = 1; |
3193 nonrd_pick_sb_modes(cpi, tile_data, x, mi_row, mi_col, rd_cost, | 3227 nonrd_pick_sb_modes(cpi, tile_data, x, mi_row, mi_col, dummy_cost, |
3194 subsize, &pc_tree->none); | 3228 subsize, &pc_tree->none); |
3195 pc_tree->none.mic.mbmi = xd->mi[0].src_mi->mbmi; | 3229 pc_tree->none.mic.mbmi = xd->mi[0].src_mi->mbmi; |
3196 pc_tree->none.skip_txfm[0] = x->skip_txfm[0]; | 3230 pc_tree->none.skip_txfm[0] = x->skip_txfm[0]; |
3197 pc_tree->none.skip = x->skip; | 3231 pc_tree->none.skip = x->skip; |
3198 encode_b_rt(cpi, td, tile_info, tp, mi_row, mi_col, output_enabled, | 3232 encode_b_rt(cpi, td, tile_info, tp, mi_row, mi_col, output_enabled, |
3199 subsize, &pc_tree->none); | 3233 subsize, &pc_tree->none); |
3200 break; | 3234 break; |
3201 case PARTITION_VERT: | 3235 case PARTITION_VERT: |
3202 pc_tree->vertical[0].pred_pixel_ready = 1; | 3236 pc_tree->vertical[0].pred_pixel_ready = 1; |
3203 nonrd_pick_sb_modes(cpi, tile_data, x, mi_row, mi_col, rd_cost, | 3237 nonrd_pick_sb_modes(cpi, tile_data, x, mi_row, mi_col, dummy_cost, |
3204 subsize, &pc_tree->vertical[0]); | 3238 subsize, &pc_tree->vertical[0]); |
3205 pc_tree->vertical[0].mic.mbmi = xd->mi[0].src_mi->mbmi; | 3239 pc_tree->vertical[0].mic.mbmi = xd->mi[0].src_mi->mbmi; |
3206 pc_tree->vertical[0].skip_txfm[0] = x->skip_txfm[0]; | 3240 pc_tree->vertical[0].skip_txfm[0] = x->skip_txfm[0]; |
3207 pc_tree->vertical[0].skip = x->skip; | 3241 pc_tree->vertical[0].skip = x->skip; |
3208 encode_b_rt(cpi, td, tile_info, tp, mi_row, mi_col, output_enabled, | 3242 encode_b_rt(cpi, td, tile_info, tp, mi_row, mi_col, output_enabled, |
3209 subsize, &pc_tree->vertical[0]); | 3243 subsize, &pc_tree->vertical[0]); |
3210 if (mi_col + hbs < cm->mi_cols) { | 3244 if (mi_col + hbs < cm->mi_cols && bsize > BLOCK_8X8) { |
3211 pc_tree->vertical[1].pred_pixel_ready = 1; | 3245 pc_tree->vertical[1].pred_pixel_ready = 1; |
3212 nonrd_pick_sb_modes(cpi, tile_data, x, mi_row, mi_col + hbs, | 3246 nonrd_pick_sb_modes(cpi, tile_data, x, mi_row, mi_col + hbs, |
3213 &this_rdc, subsize, &pc_tree->vertical[1]); | 3247 dummy_cost, subsize, &pc_tree->vertical[1]); |
3214 pc_tree->vertical[1].mic.mbmi = xd->mi[0].src_mi->mbmi; | 3248 pc_tree->vertical[1].mic.mbmi = xd->mi[0].src_mi->mbmi; |
3215 pc_tree->vertical[1].skip_txfm[0] = x->skip_txfm[0]; | 3249 pc_tree->vertical[1].skip_txfm[0] = x->skip_txfm[0]; |
3216 pc_tree->vertical[1].skip = x->skip; | 3250 pc_tree->vertical[1].skip = x->skip; |
3217 encode_b_rt(cpi, td, tile_info, tp, mi_row, mi_col + hbs, | 3251 encode_b_rt(cpi, td, tile_info, tp, mi_row, mi_col + hbs, |
3218 output_enabled, subsize, &pc_tree->vertical[1]); | 3252 output_enabled, subsize, &pc_tree->vertical[1]); |
3219 | |
3220 if (this_rdc.rate != INT_MAX && this_rdc.dist != INT64_MAX && | |
3221 rd_cost->rate != INT_MAX && rd_cost->dist != INT64_MAX) { | |
3222 rd_cost->rate += this_rdc.rate; | |
3223 rd_cost->dist += this_rdc.dist; | |
3224 } | |
3225 } | 3253 } |
3226 break; | 3254 break; |
3227 case PARTITION_HORZ: | 3255 case PARTITION_HORZ: |
3228 pc_tree->horizontal[0].pred_pixel_ready = 1; | 3256 pc_tree->horizontal[0].pred_pixel_ready = 1; |
3229 nonrd_pick_sb_modes(cpi, tile_data, x, mi_row, mi_col, rd_cost, | 3257 nonrd_pick_sb_modes(cpi, tile_data, x, mi_row, mi_col, dummy_cost, |
3230 subsize, &pc_tree->horizontal[0]); | 3258 subsize, &pc_tree->horizontal[0]); |
3231 pc_tree->horizontal[0].mic.mbmi = xd->mi[0].src_mi->mbmi; | 3259 pc_tree->horizontal[0].mic.mbmi = xd->mi[0].src_mi->mbmi; |
3232 pc_tree->horizontal[0].skip_txfm[0] = x->skip_txfm[0]; | 3260 pc_tree->horizontal[0].skip_txfm[0] = x->skip_txfm[0]; |
3233 pc_tree->horizontal[0].skip = x->skip; | 3261 pc_tree->horizontal[0].skip = x->skip; |
3234 encode_b_rt(cpi, td, tile_info, tp, mi_row, mi_col, output_enabled, | 3262 encode_b_rt(cpi, td, tile_info, tp, mi_row, mi_col, output_enabled, |
3235 subsize, &pc_tree->horizontal[0]); | 3263 subsize, &pc_tree->horizontal[0]); |
3236 | 3264 |
3237 if (mi_row + hbs < cm->mi_rows) { | 3265 if (mi_row + hbs < cm->mi_rows && bsize > BLOCK_8X8) { |
3238 pc_tree->horizontal[1].pred_pixel_ready = 1; | 3266 pc_tree->horizontal[1].pred_pixel_ready = 1; |
3239 nonrd_pick_sb_modes(cpi, tile_data, x, mi_row + hbs, mi_col, | 3267 nonrd_pick_sb_modes(cpi, tile_data, x, mi_row + hbs, mi_col, |
3240 &this_rdc, subsize, &pc_tree->horizontal[0]); | 3268 dummy_cost, subsize, &pc_tree->horizontal[1]); |
3241 pc_tree->horizontal[1].mic.mbmi = xd->mi[0].src_mi->mbmi; | 3269 pc_tree->horizontal[1].mic.mbmi = xd->mi[0].src_mi->mbmi; |
3242 pc_tree->horizontal[1].skip_txfm[0] = x->skip_txfm[0]; | 3270 pc_tree->horizontal[1].skip_txfm[0] = x->skip_txfm[0]; |
3243 pc_tree->horizontal[1].skip = x->skip; | 3271 pc_tree->horizontal[1].skip = x->skip; |
3244 encode_b_rt(cpi, td, tile_info, tp, mi_row + hbs, mi_col, | 3272 encode_b_rt(cpi, td, tile_info, tp, mi_row + hbs, mi_col, |
3245 output_enabled, subsize, &pc_tree->horizontal[1]); | 3273 output_enabled, subsize, &pc_tree->horizontal[1]); |
3246 | |
3247 if (this_rdc.rate != INT_MAX && this_rdc.dist != INT64_MAX && | |
3248 rd_cost->rate != INT_MAX && rd_cost->dist != INT64_MAX) { | |
3249 rd_cost->rate += this_rdc.rate; | |
3250 rd_cost->dist += this_rdc.dist; | |
3251 } | |
3252 } | 3274 } |
3253 break; | 3275 break; |
3254 case PARTITION_SPLIT: | 3276 case PARTITION_SPLIT: |
3255 subsize = get_subsize(bsize, PARTITION_SPLIT); | 3277 subsize = get_subsize(bsize, PARTITION_SPLIT); |
3256 nonrd_use_partition(cpi, td, tile_data, mi, tp, mi_row, mi_col, | 3278 if (bsize == BLOCK_8X8) { |
3257 subsize, output_enabled, rd_cost, | 3279 nonrd_pick_sb_modes(cpi, tile_data, x, mi_row, mi_col, dummy_cost, |
3258 pc_tree->split[0]); | 3280 subsize, pc_tree->leaf_split[0]); |
3259 nonrd_use_partition(cpi, td, tile_data, mi + hbs, tp, | 3281 encode_b_rt(cpi, td, tile_info, tp, mi_row, mi_col, |
3260 mi_row, mi_col + hbs, subsize, output_enabled, | 3282 output_enabled, subsize, pc_tree->leaf_split[0]); |
3261 &this_rdc, pc_tree->split[1]); | 3283 } else { |
3262 if (this_rdc.rate != INT_MAX && this_rdc.dist != INT64_MAX && | 3284 nonrd_use_partition(cpi, td, tile_data, mi, tp, mi_row, mi_col, |
3263 rd_cost->rate != INT_MAX && rd_cost->dist != INT64_MAX) { | 3285 subsize, output_enabled, dummy_cost, |
3264 rd_cost->rate += this_rdc.rate; | 3286 pc_tree->split[0]); |
3265 rd_cost->dist += this_rdc.dist; | 3287 nonrd_use_partition(cpi, td, tile_data, mi + hbs, tp, |
3266 } | 3288 mi_row, mi_col + hbs, subsize, output_enabled, |
3267 nonrd_use_partition(cpi, td, tile_data, mi + hbs * mis, tp, | 3289 dummy_cost, pc_tree->split[1]); |
3268 mi_row + hbs, mi_col, subsize, output_enabled, | 3290 nonrd_use_partition(cpi, td, tile_data, mi + hbs * mis, tp, |
3269 &this_rdc, pc_tree->split[2]); | 3291 mi_row + hbs, mi_col, subsize, output_enabled, |
3270 if (this_rdc.rate != INT_MAX && this_rdc.dist != INT64_MAX && | 3292 dummy_cost, pc_tree->split[2]); |
3271 rd_cost->rate != INT_MAX && rd_cost->dist != INT64_MAX) { | 3293 nonrd_use_partition(cpi, td, tile_data, mi + hbs * mis + hbs, tp, |
3272 rd_cost->rate += this_rdc.rate; | 3294 mi_row + hbs, mi_col + hbs, subsize, output_enabled, |
3273 rd_cost->dist += this_rdc.dist; | 3295 dummy_cost, pc_tree->split[3]); |
3274 } | |
3275 nonrd_use_partition(cpi, td, tile_data, mi + hbs * mis + hbs, tp, | |
3276 mi_row + hbs, mi_col + hbs, subsize, output_enabled, | |
3277 &this_rdc, pc_tree->split[3]); | |
3278 if (this_rdc.rate != INT_MAX && this_rdc.dist != INT64_MAX && | |
3279 rd_cost->rate != INT_MAX && rd_cost->dist != INT64_MAX) { | |
3280 rd_cost->rate += this_rdc.rate; | |
3281 rd_cost->dist += this_rdc.dist; | |
3282 } | 3296 } |
3283 break; | 3297 break; |
3284 default: | 3298 default: |
3285 assert("Invalid partition type."); | 3299 assert(0 && "Invalid partition type."); |
3286 break; | 3300 break; |
3287 } | 3301 } |
3288 | 3302 |
3289 if (partition != PARTITION_SPLIT || bsize == BLOCK_8X8) | 3303 if (partition != PARTITION_SPLIT || bsize == BLOCK_8X8) |
3290 update_partition_context(xd, mi_row, mi_col, subsize, bsize); | 3304 update_partition_context(xd, mi_row, mi_col, subsize, bsize); |
3291 } | 3305 } |
3292 | 3306 |
3293 static void encode_nonrd_sb_row(VP9_COMP *cpi, | 3307 static void encode_nonrd_sb_row(VP9_COMP *cpi, |
3294 ThreadData *td, | 3308 ThreadData *td, |
3295 TileDataEnc *tile_data, | 3309 TileDataEnc *tile_data, |
(...skipping 17 matching lines...) Expand all Loading... |
3313 const int idx_str = cm->mi_stride * mi_row + mi_col; | 3327 const int idx_str = cm->mi_stride * mi_row + mi_col; |
3314 MODE_INFO *mi = cm->mi + idx_str; | 3328 MODE_INFO *mi = cm->mi + idx_str; |
3315 BLOCK_SIZE bsize; | 3329 BLOCK_SIZE bsize; |
3316 x->source_variance = UINT_MAX; | 3330 x->source_variance = UINT_MAX; |
3317 vp9_zero(x->pred_mv); | 3331 vp9_zero(x->pred_mv); |
3318 vp9_rd_cost_init(&dummy_rdc); | 3332 vp9_rd_cost_init(&dummy_rdc); |
3319 | 3333 |
3320 // Set the partition type of the 64X64 block | 3334 // Set the partition type of the 64X64 block |
3321 switch (sf->partition_search_type) { | 3335 switch (sf->partition_search_type) { |
3322 case VAR_BASED_PARTITION: | 3336 case VAR_BASED_PARTITION: |
| 3337 // TODO(jingning, marpan): The mode decision and encoding process |
| 3338 // support both intra and inter sub8x8 block coding for RTC mode. |
| 3339 // Tune the thresholds accordingly to use sub8x8 block coding for |
| 3340 // coding performance improvement. |
3323 choose_partitioning(cpi, tile_info, x, mi_row, mi_col); | 3341 choose_partitioning(cpi, tile_info, x, mi_row, mi_col); |
3324 nonrd_use_partition(cpi, td, tile_data, mi, tp, mi_row, mi_col, | 3342 nonrd_use_partition(cpi, td, tile_data, mi, tp, mi_row, mi_col, |
3325 BLOCK_64X64, 1, &dummy_rdc, td->pc_root); | 3343 BLOCK_64X64, 1, &dummy_rdc, td->pc_root); |
3326 break; | 3344 break; |
3327 case SOURCE_VAR_BASED_PARTITION: | 3345 case SOURCE_VAR_BASED_PARTITION: |
3328 set_source_var_based_partition(cpi, tile_info, x, mi, mi_row, mi_col); | 3346 set_source_var_based_partition(cpi, tile_info, x, mi, mi_row, mi_col); |
3329 nonrd_use_partition(cpi, td, tile_data, mi, tp, mi_row, mi_col, | 3347 nonrd_use_partition(cpi, td, tile_data, mi, tp, mi_row, mi_col, |
3330 BLOCK_64X64, 1, &dummy_rdc, td->pc_root); | 3348 BLOCK_64X64, 1, &dummy_rdc, td->pc_root); |
3331 break; | 3349 break; |
3332 case FIXED_PARTITION: | 3350 case FIXED_PARTITION: |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3481 for (j = 0; j < INTRA_INTER_CONTEXTS; ++j) { | 3499 for (j = 0; j < INTRA_INTER_CONTEXTS; ++j) { |
3482 intra_count += td->counts->intra_inter[j][0]; | 3500 intra_count += td->counts->intra_inter[j][0]; |
3483 inter_count += td->counts->intra_inter[j][1]; | 3501 inter_count += td->counts->intra_inter[j][1]; |
3484 } | 3502 } |
3485 | 3503 |
3486 return (intra_count << 2) < inter_count && | 3504 return (intra_count << 2) < inter_count && |
3487 cm->frame_type != KEY_FRAME && | 3505 cm->frame_type != KEY_FRAME && |
3488 cm->show_frame; | 3506 cm->show_frame; |
3489 } | 3507 } |
3490 | 3508 |
3491 static void init_tile_data(VP9_COMP *cpi) { | 3509 void vp9_init_tile_data(VP9_COMP *cpi) { |
3492 VP9_COMMON *const cm = &cpi->common; | 3510 VP9_COMMON *const cm = &cpi->common; |
3493 const int tile_cols = 1 << cm->log2_tile_cols; | 3511 const int tile_cols = 1 << cm->log2_tile_cols; |
3494 const int tile_rows = 1 << cm->log2_tile_rows; | 3512 const int tile_rows = 1 << cm->log2_tile_rows; |
3495 int tile_col, tile_row; | 3513 int tile_col, tile_row; |
3496 TOKENEXTRA *pre_tok = cpi->tile_tok[0][0]; | 3514 TOKENEXTRA *pre_tok = cpi->tile_tok[0][0]; |
3497 int tile_tok = 0; | 3515 int tile_tok = 0; |
3498 | 3516 |
3499 if (cpi->tile_data == NULL) { | 3517 if (cpi->tile_data == NULL) { |
3500 CHECK_MEM_ERROR(cm, cpi->tile_data, | 3518 CHECK_MEM_ERROR(cm, cpi->tile_data, |
3501 vpx_malloc(tile_cols * tile_rows * sizeof(*cpi->tile_data))); | 3519 vpx_malloc(tile_cols * tile_rows * sizeof(*cpi->tile_data))); |
(...skipping 17 matching lines...) Expand all Loading... |
3519 &cpi->tile_data[tile_row * tile_cols + tile_col].tile_info; | 3537 &cpi->tile_data[tile_row * tile_cols + tile_col].tile_info; |
3520 vp9_tile_init(tile_info, cm, tile_row, tile_col); | 3538 vp9_tile_init(tile_info, cm, tile_row, tile_col); |
3521 | 3539 |
3522 cpi->tile_tok[tile_row][tile_col] = pre_tok + tile_tok; | 3540 cpi->tile_tok[tile_row][tile_col] = pre_tok + tile_tok; |
3523 pre_tok = cpi->tile_tok[tile_row][tile_col]; | 3541 pre_tok = cpi->tile_tok[tile_row][tile_col]; |
3524 tile_tok = allocated_tokens(*tile_info); | 3542 tile_tok = allocated_tokens(*tile_info); |
3525 } | 3543 } |
3526 } | 3544 } |
3527 } | 3545 } |
3528 | 3546 |
| 3547 void vp9_encode_tile(VP9_COMP *cpi, ThreadData *td, |
| 3548 int tile_row, int tile_col) { |
| 3549 VP9_COMMON *const cm = &cpi->common; |
| 3550 const int tile_cols = 1 << cm->log2_tile_cols; |
| 3551 TileDataEnc *this_tile = |
| 3552 &cpi->tile_data[tile_row * tile_cols + tile_col]; |
| 3553 const TileInfo * const tile_info = &this_tile->tile_info; |
| 3554 TOKENEXTRA *tok = cpi->tile_tok[tile_row][tile_col]; |
| 3555 int mi_row; |
| 3556 |
| 3557 for (mi_row = tile_info->mi_row_start; mi_row < tile_info->mi_row_end; |
| 3558 mi_row += MI_BLOCK_SIZE) { |
| 3559 if (cpi->sf.use_nonrd_pick_mode) |
| 3560 encode_nonrd_sb_row(cpi, td, this_tile, mi_row, &tok); |
| 3561 else |
| 3562 encode_rd_sb_row(cpi, td, this_tile, mi_row, &tok); |
| 3563 } |
| 3564 cpi->tok_count[tile_row][tile_col] = |
| 3565 (unsigned int)(tok - cpi->tile_tok[tile_row][tile_col]); |
| 3566 assert(tok - cpi->tile_tok[tile_row][tile_col] <= |
| 3567 allocated_tokens(*tile_info)); |
| 3568 } |
| 3569 |
3529 static void encode_tiles(VP9_COMP *cpi) { | 3570 static void encode_tiles(VP9_COMP *cpi) { |
3530 VP9_COMMON *const cm = &cpi->common; | 3571 VP9_COMMON *const cm = &cpi->common; |
3531 const int tile_cols = 1 << cm->log2_tile_cols; | 3572 const int tile_cols = 1 << cm->log2_tile_cols; |
3532 const int tile_rows = 1 << cm->log2_tile_rows; | 3573 const int tile_rows = 1 << cm->log2_tile_rows; |
3533 int tile_col, tile_row; | 3574 int tile_col, tile_row; |
3534 | 3575 |
3535 init_tile_data(cpi); | 3576 vp9_init_tile_data(cpi); |
3536 | 3577 |
3537 for (tile_row = 0; tile_row < tile_rows; ++tile_row) { | 3578 for (tile_row = 0; tile_row < tile_rows; ++tile_row) |
3538 for (tile_col = 0; tile_col < tile_cols; ++tile_col) { | 3579 for (tile_col = 0; tile_col < tile_cols; ++tile_col) |
3539 const TileInfo * const tile_info = | 3580 vp9_encode_tile(cpi, &cpi->td, tile_row, tile_col); |
3540 &cpi->tile_data[tile_row * tile_cols + tile_col].tile_info; | |
3541 TOKENEXTRA *tok = cpi->tile_tok[tile_row][tile_col]; | |
3542 int mi_row; | |
3543 TileDataEnc *this_tile = | |
3544 &cpi->tile_data[tile_row * tile_cols + tile_col]; | |
3545 | |
3546 for (mi_row = tile_info->mi_row_start; mi_row < tile_info->mi_row_end; | |
3547 mi_row += MI_BLOCK_SIZE) { | |
3548 if (cpi->sf.use_nonrd_pick_mode) | |
3549 encode_nonrd_sb_row(cpi, &cpi->td, this_tile, mi_row, &tok); | |
3550 else | |
3551 encode_rd_sb_row(cpi, &cpi->td, this_tile, mi_row, &tok); | |
3552 } | |
3553 cpi->tok_count[tile_row][tile_col] = | |
3554 (unsigned int)(tok - cpi->tile_tok[tile_row][tile_col]); | |
3555 assert(tok - cpi->tile_tok[tile_row][tile_col] <= | |
3556 allocated_tokens(*tile_info)); | |
3557 } | |
3558 } | |
3559 } | 3581 } |
3560 | 3582 |
3561 #if CONFIG_FP_MB_STATS | 3583 #if CONFIG_FP_MB_STATS |
3562 static int input_fpmb_stats(FIRSTPASS_MB_STATS *firstpass_mb_stats, | 3584 static int input_fpmb_stats(FIRSTPASS_MB_STATS *firstpass_mb_stats, |
3563 VP9_COMMON *cm, uint8_t **this_frame_mb_stats) { | 3585 VP9_COMMON *cm, uint8_t **this_frame_mb_stats) { |
3564 uint8_t *mb_stats_in = firstpass_mb_stats->mb_stats_start + | 3586 uint8_t *mb_stats_in = firstpass_mb_stats->mb_stats_start + |
3565 cm->current_video_frame * cm->MBs * sizeof(uint8_t); | 3587 cm->current_video_frame * cm->MBs * sizeof(uint8_t); |
3566 | 3588 |
3567 if (mb_stats_in > firstpass_mb_stats->mb_stats_end) | 3589 if (mb_stats_in > firstpass_mb_stats->mb_stats_end) |
3568 return EOF; | 3590 return EOF; |
(...skipping 28 matching lines...) Expand all Loading... |
3597 cm->uv_dc_delta_q == 0 && | 3619 cm->uv_dc_delta_q == 0 && |
3598 cm->uv_ac_delta_q == 0; | 3620 cm->uv_ac_delta_q == 0; |
3599 | 3621 |
3600 cm->tx_mode = select_tx_mode(cpi, xd); | 3622 cm->tx_mode = select_tx_mode(cpi, xd); |
3601 if (cm->frame_type == KEY_FRAME && | 3623 if (cm->frame_type == KEY_FRAME && |
3602 cpi->sf.use_nonrd_pick_mode && | 3624 cpi->sf.use_nonrd_pick_mode && |
3603 cpi->sf.partition_search_type == VAR_BASED_PARTITION) { | 3625 cpi->sf.partition_search_type == VAR_BASED_PARTITION) { |
3604 cm->tx_mode = ALLOW_16X16; | 3626 cm->tx_mode = ALLOW_16X16; |
3605 } | 3627 } |
3606 | 3628 |
| 3629 |
3607 #if CONFIG_VP9_HIGHBITDEPTH | 3630 #if CONFIG_VP9_HIGHBITDEPTH |
3608 if (cm->use_highbitdepth) | 3631 if (cm->use_highbitdepth) |
3609 x->fwd_txm4x4 = xd->lossless ? vp9_highbd_fwht4x4 : vp9_highbd_fdct4x4; | 3632 x->fwd_txm4x4 = xd->lossless ? vp9_highbd_fwht4x4 : vp9_highbd_fdct4x4; |
3610 else | 3633 else |
3611 x->fwd_txm4x4 = xd->lossless ? vp9_fwht4x4 : vp9_fdct4x4; | 3634 x->fwd_txm4x4 = xd->lossless ? vp9_fwht4x4 : vp9_fdct4x4; |
3612 x->highbd_itxm_add = xd->lossless ? vp9_highbd_iwht4x4_add : | 3635 x->highbd_itxm_add = xd->lossless ? vp9_highbd_iwht4x4_add : |
3613 vp9_highbd_idct4x4_add; | 3636 vp9_highbd_idct4x4_add; |
3614 #else | 3637 #else |
3615 x->fwd_txm4x4 = xd->lossless ? vp9_fwht4x4 : vp9_fdct4x4; | 3638 x->fwd_txm4x4 = xd->lossless ? vp9_fwht4x4 : vp9_fdct4x4; |
3616 #endif // CONFIG_VP9_HIGHBITDEPTH | 3639 #endif // CONFIG_VP9_HIGHBITDEPTH |
3617 x->itxm_add = xd->lossless ? vp9_iwht4x4_add : vp9_idct4x4_add; | 3640 x->itxm_add = xd->lossless ? vp9_iwht4x4_add : vp9_idct4x4_add; |
3618 | 3641 |
3619 if (xd->lossless) { | 3642 if (xd->lossless) { |
3620 x->optimize = 0; | 3643 x->optimize = 0; |
3621 cm->lf.filter_level = 0; | 3644 cm->lf.filter_level = 0; |
3622 cpi->zbin_mode_boost_enabled = 0; | |
3623 } | 3645 } |
3624 | 3646 |
3625 vp9_frame_init_quantizer(cpi); | 3647 vp9_frame_init_quantizer(cpi); |
3626 | 3648 |
3627 vp9_initialize_rd_consts(cpi); | 3649 vp9_initialize_rd_consts(cpi); |
3628 vp9_initialize_me_consts(cpi, cm->base_qindex); | 3650 vp9_initialize_me_consts(cpi, cm->base_qindex); |
3629 init_encode_frame_mb_context(cpi); | 3651 init_encode_frame_mb_context(cpi); |
3630 set_prev_mi(cm); | |
3631 cm->use_prev_frame_mvs = !cm->error_resilient_mode && | 3652 cm->use_prev_frame_mvs = !cm->error_resilient_mode && |
3632 cm->width == cm->last_width && | 3653 cm->width == cm->last_width && |
3633 cm->height == cm->last_height && | 3654 cm->height == cm->last_height && |
3634 !cm->intra_only && | 3655 !cm->intra_only && |
3635 cm->last_show_frame; | 3656 cm->last_show_frame; |
| 3657 // Special case: set prev_mi to NULL when the previous mode info |
| 3658 // context cannot be used. |
| 3659 cm->prev_mi = cm->use_prev_frame_mvs ? |
| 3660 cm->prev_mip + cm->mi_stride + 1 : NULL; |
3636 | 3661 |
3637 x->quant_fp = cpi->sf.use_quant_fp; | 3662 x->quant_fp = cpi->sf.use_quant_fp; |
3638 vp9_zero(x->skip_txfm); | 3663 vp9_zero(x->skip_txfm); |
3639 if (sf->use_nonrd_pick_mode) { | 3664 if (sf->use_nonrd_pick_mode) { |
3640 // Initialize internal buffer pointers for rtc coding, where non-RD | 3665 // Initialize internal buffer pointers for rtc coding, where non-RD |
3641 // mode decision is used and hence no buffer pointer swap needed. | 3666 // mode decision is used and hence no buffer pointer swap needed. |
3642 int i; | 3667 int i; |
3643 struct macroblock_plane *const p = x->plane; | 3668 struct macroblock_plane *const p = x->plane; |
3644 struct macroblockd_plane *const pd = xd->plane; | 3669 struct macroblockd_plane *const pd = xd->plane; |
3645 PICK_MODE_CONTEXT *ctx = &cpi->td.pc_root->none; | 3670 PICK_MODE_CONTEXT *ctx = &cpi->td.pc_root->none; |
(...skipping 14 matching lines...) Expand all Loading... |
3660 struct vpx_usec_timer emr_timer; | 3685 struct vpx_usec_timer emr_timer; |
3661 vpx_usec_timer_start(&emr_timer); | 3686 vpx_usec_timer_start(&emr_timer); |
3662 | 3687 |
3663 #if CONFIG_FP_MB_STATS | 3688 #if CONFIG_FP_MB_STATS |
3664 if (cpi->use_fp_mb_stats) { | 3689 if (cpi->use_fp_mb_stats) { |
3665 input_fpmb_stats(&cpi->twopass.firstpass_mb_stats, cm, | 3690 input_fpmb_stats(&cpi->twopass.firstpass_mb_stats, cm, |
3666 &cpi->twopass.this_frame_mb_stats); | 3691 &cpi->twopass.this_frame_mb_stats); |
3667 } | 3692 } |
3668 #endif | 3693 #endif |
3669 | 3694 |
3670 encode_tiles(cpi); | 3695 // If allowed, encoding tiles in parallel with one thread handling one tile. |
| 3696 if (MIN(cpi->oxcf.max_threads, 1 << cm->log2_tile_cols) > 1) |
| 3697 vp9_encode_tiles_mt(cpi); |
| 3698 else |
| 3699 encode_tiles(cpi); |
3671 | 3700 |
3672 vpx_usec_timer_mark(&emr_timer); | 3701 vpx_usec_timer_mark(&emr_timer); |
3673 cpi->time_encode_sb_row += vpx_usec_timer_elapsed(&emr_timer); | 3702 cpi->time_encode_sb_row += vpx_usec_timer_elapsed(&emr_timer); |
3674 } | 3703 } |
3675 | 3704 |
3676 sf->skip_encode_frame = sf->skip_encode_sb ? | 3705 sf->skip_encode_frame = sf->skip_encode_sb ? |
3677 get_skip_encode_frame(cm, td) : 0; | 3706 get_skip_encode_frame(cm, td) : 0; |
3678 | 3707 |
3679 #if 0 | 3708 #if 0 |
3680 // Keep record of the total distortion this time around for future use | 3709 // Keep record of the total distortion this time around for future use |
(...skipping 28 matching lines...) Expand all Loading... |
3709 // decoder such that we allow compound where one of the 3 buffers has a | 3738 // decoder such that we allow compound where one of the 3 buffers has a |
3710 // different sign bias and that buffer is then the fixed ref. However, this | 3739 // different sign bias and that buffer is then the fixed ref. However, this |
3711 // requires further work in the rd loop. For now the only supported encoder | 3740 // requires further work in the rd loop. For now the only supported encoder |
3712 // side behavior is where the ALT ref buffer has opposite sign bias to | 3741 // side behavior is where the ALT ref buffer has opposite sign bias to |
3713 // the other two. | 3742 // the other two. |
3714 if (!frame_is_intra_only(cm)) { | 3743 if (!frame_is_intra_only(cm)) { |
3715 if ((cm->ref_frame_sign_bias[ALTREF_FRAME] == | 3744 if ((cm->ref_frame_sign_bias[ALTREF_FRAME] == |
3716 cm->ref_frame_sign_bias[GOLDEN_FRAME]) || | 3745 cm->ref_frame_sign_bias[GOLDEN_FRAME]) || |
3717 (cm->ref_frame_sign_bias[ALTREF_FRAME] == | 3746 (cm->ref_frame_sign_bias[ALTREF_FRAME] == |
3718 cm->ref_frame_sign_bias[LAST_FRAME])) { | 3747 cm->ref_frame_sign_bias[LAST_FRAME])) { |
3719 cm->allow_comp_inter_inter = 0; | 3748 cpi->allow_comp_inter_inter = 0; |
3720 } else { | 3749 } else { |
3721 cm->allow_comp_inter_inter = 1; | 3750 cpi->allow_comp_inter_inter = 1; |
3722 cm->comp_fixed_ref = ALTREF_FRAME; | 3751 cm->comp_fixed_ref = ALTREF_FRAME; |
3723 cm->comp_var_ref[0] = LAST_FRAME; | 3752 cm->comp_var_ref[0] = LAST_FRAME; |
3724 cm->comp_var_ref[1] = GOLDEN_FRAME; | 3753 cm->comp_var_ref[1] = GOLDEN_FRAME; |
3725 } | 3754 } |
3726 } | 3755 } |
3727 | 3756 |
3728 if (cpi->sf.frame_parameter_update) { | 3757 if (cpi->sf.frame_parameter_update) { |
3729 int i; | 3758 int i; |
3730 | 3759 |
3731 // This code does a single RD pass over the whole frame assuming | 3760 // This code does a single RD pass over the whole frame assuming |
3732 // either compound, single or hybrid prediction as per whatever has | 3761 // either compound, single or hybrid prediction as per whatever has |
3733 // worked best for that type of frame in the past. | 3762 // worked best for that type of frame in the past. |
3734 // It also predicts whether another coding mode would have worked | 3763 // It also predicts whether another coding mode would have worked |
3735 // better that this coding mode. If that is the case, it remembers | 3764 // better that this coding mode. If that is the case, it remembers |
3736 // that for subsequent frames. | 3765 // that for subsequent frames. |
3737 // It does the same analysis for transform size selection also. | 3766 // It does the same analysis for transform size selection also. |
3738 const MV_REFERENCE_FRAME frame_type = get_frame_type(cpi); | 3767 const MV_REFERENCE_FRAME frame_type = get_frame_type(cpi); |
3739 int64_t *const mode_thrs = rd_opt->prediction_type_threshes[frame_type]; | 3768 int64_t *const mode_thrs = rd_opt->prediction_type_threshes[frame_type]; |
3740 int64_t *const filter_thrs = rd_opt->filter_threshes[frame_type]; | 3769 int64_t *const filter_thrs = rd_opt->filter_threshes[frame_type]; |
3741 int *const tx_thrs = rd_opt->tx_select_threshes[frame_type]; | 3770 int *const tx_thrs = rd_opt->tx_select_threshes[frame_type]; |
3742 const int is_alt_ref = frame_type == ALTREF_FRAME; | 3771 const int is_alt_ref = frame_type == ALTREF_FRAME; |
3743 | 3772 |
3744 /* prediction (compound, single or hybrid) mode selection */ | 3773 /* prediction (compound, single or hybrid) mode selection */ |
3745 if (is_alt_ref || !cm->allow_comp_inter_inter) | 3774 if (is_alt_ref || !cpi->allow_comp_inter_inter) |
3746 cm->reference_mode = SINGLE_REFERENCE; | 3775 cm->reference_mode = SINGLE_REFERENCE; |
3747 else if (mode_thrs[COMPOUND_REFERENCE] > mode_thrs[SINGLE_REFERENCE] && | 3776 else if (mode_thrs[COMPOUND_REFERENCE] > mode_thrs[SINGLE_REFERENCE] && |
3748 mode_thrs[COMPOUND_REFERENCE] > | 3777 mode_thrs[COMPOUND_REFERENCE] > |
3749 mode_thrs[REFERENCE_MODE_SELECT] && | 3778 mode_thrs[REFERENCE_MODE_SELECT] && |
3750 check_dual_ref_flags(cpi) && | 3779 check_dual_ref_flags(cpi) && |
3751 cpi->static_mb_pct == 100) | 3780 cpi->static_mb_pct == 100) |
3752 cm->reference_mode = COMPOUND_REFERENCE; | 3781 cm->reference_mode = COMPOUND_REFERENCE; |
3753 else if (mode_thrs[SINGLE_REFERENCE] > mode_thrs[REFERENCE_MODE_SELECT]) | 3782 else if (mode_thrs[SINGLE_REFERENCE] > mode_thrs[REFERENCE_MODE_SELECT]) |
3754 cm->reference_mode = SINGLE_REFERENCE; | 3783 cm->reference_mode = SINGLE_REFERENCE; |
3755 else | 3784 else |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3845 for (idy = 0; idy < 2; idy += num_4x4_h) | 3874 for (idy = 0; idy < 2; idy += num_4x4_h) |
3846 for (idx = 0; idx < 2; idx += num_4x4_w) | 3875 for (idx = 0; idx < 2; idx += num_4x4_w) |
3847 ++counts->y_mode[0][mi->bmi[idy * 2 + idx].as_mode]; | 3876 ++counts->y_mode[0][mi->bmi[idy * 2 + idx].as_mode]; |
3848 } else { | 3877 } else { |
3849 ++counts->y_mode[size_group_lookup[bsize]][y_mode]; | 3878 ++counts->y_mode[size_group_lookup[bsize]][y_mode]; |
3850 } | 3879 } |
3851 | 3880 |
3852 ++counts->uv_mode[y_mode][uv_mode]; | 3881 ++counts->uv_mode[y_mode][uv_mode]; |
3853 } | 3882 } |
3854 | 3883 |
3855 static int get_zbin_mode_boost(const MB_MODE_INFO *mbmi, int enabled) { | |
3856 if (enabled) { | |
3857 if (is_inter_block(mbmi)) { | |
3858 if (mbmi->mode == ZEROMV) { | |
3859 return mbmi->ref_frame[0] != LAST_FRAME ? GF_ZEROMV_ZBIN_BOOST | |
3860 : LF_ZEROMV_ZBIN_BOOST; | |
3861 } else { | |
3862 return mbmi->sb_type < BLOCK_8X8 ? SPLIT_MV_ZBIN_BOOST | |
3863 : MV_ZBIN_BOOST; | |
3864 } | |
3865 } else { | |
3866 return INTRA_ZBIN_BOOST; | |
3867 } | |
3868 } else { | |
3869 return 0; | |
3870 } | |
3871 } | |
3872 | |
3873 static void encode_superblock(VP9_COMP *cpi, ThreadData *td, | 3884 static void encode_superblock(VP9_COMP *cpi, ThreadData *td, |
3874 TOKENEXTRA **t, int output_enabled, | 3885 TOKENEXTRA **t, int output_enabled, |
3875 int mi_row, int mi_col, BLOCK_SIZE bsize, | 3886 int mi_row, int mi_col, BLOCK_SIZE bsize, |
3876 PICK_MODE_CONTEXT *ctx) { | 3887 PICK_MODE_CONTEXT *ctx) { |
3877 VP9_COMMON *const cm = &cpi->common; | 3888 VP9_COMMON *const cm = &cpi->common; |
3878 MACROBLOCK *const x = &td->mb; | 3889 MACROBLOCK *const x = &td->mb; |
3879 MACROBLOCKD *const xd = &x->e_mbd; | 3890 MACROBLOCKD *const xd = &x->e_mbd; |
3880 MODE_INFO *mi_8x8 = xd->mi; | 3891 MODE_INFO *mi_8x8 = xd->mi; |
3881 MODE_INFO *mi = mi_8x8; | 3892 MODE_INFO *mi = mi_8x8; |
3882 MB_MODE_INFO *mbmi = &mi->mbmi; | 3893 MB_MODE_INFO *mbmi = &mi->mbmi; |
(...skipping 15 matching lines...) Expand all Loading... |
3898 ctx->is_coded = 1; | 3909 ctx->is_coded = 1; |
3899 x->use_lp32x32fdct = cpi->sf.use_lp32x32fdct; | 3910 x->use_lp32x32fdct = cpi->sf.use_lp32x32fdct; |
3900 x->skip_encode = (!output_enabled && cpi->sf.skip_encode_frame && | 3911 x->skip_encode = (!output_enabled && cpi->sf.skip_encode_frame && |
3901 x->q_index < QIDX_SKIP_THRESH); | 3912 x->q_index < QIDX_SKIP_THRESH); |
3902 | 3913 |
3903 if (x->skip_encode) | 3914 if (x->skip_encode) |
3904 return; | 3915 return; |
3905 | 3916 |
3906 set_ref_ptrs(cm, xd, mbmi->ref_frame[0], mbmi->ref_frame[1]); | 3917 set_ref_ptrs(cm, xd, mbmi->ref_frame[0], mbmi->ref_frame[1]); |
3907 | 3918 |
3908 // Experimental code. Special case for gf and arf zeromv modes. | |
3909 // Increase zbin size to suppress noise | |
3910 cpi->zbin_mode_boost = get_zbin_mode_boost(mbmi, | |
3911 cpi->zbin_mode_boost_enabled); | |
3912 vp9_update_zbin_extra(cpi, x); | |
3913 | |
3914 if (!is_inter_block(mbmi)) { | 3919 if (!is_inter_block(mbmi)) { |
3915 int plane; | 3920 int plane; |
3916 mbmi->skip = 1; | 3921 mbmi->skip = 1; |
3917 for (plane = 0; plane < MAX_MB_PLANE; ++plane) | 3922 for (plane = 0; plane < MAX_MB_PLANE; ++plane) |
3918 vp9_encode_intra_block_plane(x, MAX(bsize, BLOCK_8X8), plane); | 3923 vp9_encode_intra_block_plane(x, MAX(bsize, BLOCK_8X8), plane); |
3919 if (output_enabled) | 3924 if (output_enabled) |
3920 sum_intra_stats(td->counts, mi); | 3925 sum_intra_stats(td->counts, mi); |
3921 vp9_tokenize_sb(cpi, td, t, !output_enabled, MAX(bsize, BLOCK_8X8)); | 3926 vp9_tokenize_sb(cpi, td, t, !output_enabled, MAX(bsize, BLOCK_8X8)); |
3922 } else { | 3927 } else { |
3923 int ref; | 3928 int ref; |
(...skipping 30 matching lines...) Expand all Loading... |
3954 tx_size = (bsize >= BLOCK_8X8) ? mbmi->tx_size : TX_4X4; | 3959 tx_size = (bsize >= BLOCK_8X8) ? mbmi->tx_size : TX_4X4; |
3955 } | 3960 } |
3956 | 3961 |
3957 for (y = 0; y < mi_height; y++) | 3962 for (y = 0; y < mi_height; y++) |
3958 for (x = 0; x < mi_width; x++) | 3963 for (x = 0; x < mi_width; x++) |
3959 if (mi_col + x < cm->mi_cols && mi_row + y < cm->mi_rows) | 3964 if (mi_col + x < cm->mi_cols && mi_row + y < cm->mi_rows) |
3960 mi_8x8[mis * y + x].src_mi->mbmi.tx_size = tx_size; | 3965 mi_8x8[mis * y + x].src_mi->mbmi.tx_size = tx_size; |
3961 } | 3966 } |
3962 } | 3967 } |
3963 } | 3968 } |
OLD | NEW |