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 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 const int block_height = num_8x8_blocks_high_lookup[bsize]; | 247 const int block_height = num_8x8_blocks_high_lookup[bsize]; |
248 int i, j; | 248 int i, j; |
249 for (j = 0; j < block_height; ++j) | 249 for (j = 0; j < block_height; ++j) |
250 for (i = 0; i < block_width; ++i) { | 250 for (i = 0; i < block_width; ++i) { |
251 if (mi_row + j < cm->mi_rows && mi_col + i < cm->mi_cols) | 251 if (mi_row + j < cm->mi_rows && mi_col + i < cm->mi_cols) |
252 xd->mi[j * xd->mi_stride + i] = xd->mi[0]; | 252 xd->mi[j * xd->mi_stride + i] = xd->mi[0]; |
253 } | 253 } |
254 } | 254 } |
255 | 255 |
256 static void set_block_size(VP9_COMP * const cpi, | 256 static void set_block_size(VP9_COMP * const cpi, |
257 const TileInfo *const tile, | |
258 int mi_row, int mi_col, | 257 int mi_row, int mi_col, |
259 BLOCK_SIZE bsize) { | 258 BLOCK_SIZE bsize) { |
260 if (cpi->common.mi_cols > mi_col && cpi->common.mi_rows > mi_row) { | 259 if (cpi->common.mi_cols > mi_col && cpi->common.mi_rows > mi_row) { |
261 MACROBLOCKD *const xd = &cpi->mb.e_mbd; | 260 MACROBLOCKD *const xd = &cpi->mb.e_mbd; |
262 set_modeinfo_offsets(&cpi->common, xd, mi_row, mi_col); | 261 set_modeinfo_offsets(&cpi->common, xd, mi_row, mi_col); |
263 xd->mi[0]->mbmi.sb_type = bsize; | 262 xd->mi[0]->mbmi.sb_type = bsize; |
264 duplicate_mode_info_in_sb(&cpi->common, xd, mi_row, mi_col, bsize); | 263 duplicate_mode_info_in_sb(&cpi->common, xd, mi_row, mi_col, bsize); |
265 } | 264 } |
266 } | 265 } |
267 | 266 |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
370 sum_2_variances(node.split[0], node.split[1], &node.part_variances->horz[0]); | 369 sum_2_variances(node.split[0], node.split[1], &node.part_variances->horz[0]); |
371 sum_2_variances(node.split[2], node.split[3], &node.part_variances->horz[1]); | 370 sum_2_variances(node.split[2], node.split[3], &node.part_variances->horz[1]); |
372 sum_2_variances(node.split[0], node.split[2], &node.part_variances->vert[0]); | 371 sum_2_variances(node.split[0], node.split[2], &node.part_variances->vert[0]); |
373 sum_2_variances(node.split[1], node.split[3], &node.part_variances->vert[1]); | 372 sum_2_variances(node.split[1], node.split[3], &node.part_variances->vert[1]); |
374 sum_2_variances(&node.part_variances->vert[0], &node.part_variances->vert[1], | 373 sum_2_variances(&node.part_variances->vert[0], &node.part_variances->vert[1], |
375 &node.part_variances->none); | 374 &node.part_variances->none); |
376 } | 375 } |
377 | 376 |
378 static int set_vt_partitioning(VP9_COMP *cpi, | 377 static int set_vt_partitioning(VP9_COMP *cpi, |
379 void *data, | 378 void *data, |
380 const TileInfo *const tile, | |
381 BLOCK_SIZE bsize, | 379 BLOCK_SIZE bsize, |
382 int mi_row, | 380 int mi_row, |
383 int mi_col, | 381 int mi_col) { |
384 int mi_size) { | |
385 VP9_COMMON * const cm = &cpi->common; | 382 VP9_COMMON * const cm = &cpi->common; |
386 variance_node vt; | 383 variance_node vt; |
387 const int block_width = num_8x8_blocks_wide_lookup[bsize]; | 384 const int block_width = num_8x8_blocks_wide_lookup[bsize]; |
388 const int block_height = num_8x8_blocks_high_lookup[bsize]; | 385 const int block_height = num_8x8_blocks_high_lookup[bsize]; |
389 // TODO(debargha): Choose this more intelligently. | 386 // TODO(debargha): Choose this more intelligently. |
390 const int64_t threshold_multiplier = 25; | 387 const int64_t threshold_multiplier = 25; |
391 int64_t threshold = threshold_multiplier * cpi->common.base_qindex; | 388 int64_t threshold = threshold_multiplier * cpi->common.base_qindex; |
392 assert(block_height == block_width); | 389 assert(block_height == block_width); |
393 | 390 |
394 tree_to_node(data, bsize, &vt); | 391 tree_to_node(data, bsize, &vt); |
395 | 392 |
396 // Split none is available only if we have more than half a block size | 393 // Split none is available only if we have more than half a block size |
397 // in width and height inside the visible image. | 394 // in width and height inside the visible image. |
398 if (mi_col + block_width / 2 < cm->mi_cols && | 395 if (mi_col + block_width / 2 < cm->mi_cols && |
399 mi_row + block_height / 2 < cm->mi_rows && | 396 mi_row + block_height / 2 < cm->mi_rows && |
400 vt.part_variances->none.variance < threshold) { | 397 vt.part_variances->none.variance < threshold) { |
401 set_block_size(cpi, tile, mi_row, mi_col, bsize); | 398 set_block_size(cpi, mi_row, mi_col, bsize); |
402 return 1; | 399 return 1; |
403 } | 400 } |
404 | 401 |
405 // Vertical split is available on all but the bottom border. | 402 // Vertical split is available on all but the bottom border. |
406 if (mi_row + block_height / 2 < cm->mi_rows && | 403 if (mi_row + block_height / 2 < cm->mi_rows && |
407 vt.part_variances->vert[0].variance < threshold && | 404 vt.part_variances->vert[0].variance < threshold && |
408 vt.part_variances->vert[1].variance < threshold) { | 405 vt.part_variances->vert[1].variance < threshold) { |
409 BLOCK_SIZE subsize = get_subsize(bsize, PARTITION_VERT); | 406 BLOCK_SIZE subsize = get_subsize(bsize, PARTITION_VERT); |
410 set_block_size(cpi, tile, mi_row, mi_col, subsize); | 407 set_block_size(cpi, mi_row, mi_col, subsize); |
411 set_block_size(cpi, tile, mi_row, mi_col + block_width / 2, subsize); | 408 set_block_size(cpi, mi_row, mi_col + block_width / 2, subsize); |
412 return 1; | 409 return 1; |
413 } | 410 } |
414 | 411 |
415 // Horizontal split is available on all but the right border. | 412 // Horizontal split is available on all but the right border. |
416 if (mi_col + block_width / 2 < cm->mi_cols && | 413 if (mi_col + block_width / 2 < cm->mi_cols && |
417 vt.part_variances->horz[0].variance < threshold && | 414 vt.part_variances->horz[0].variance < threshold && |
418 vt.part_variances->horz[1].variance < threshold) { | 415 vt.part_variances->horz[1].variance < threshold) { |
419 BLOCK_SIZE subsize = get_subsize(bsize, PARTITION_HORZ); | 416 BLOCK_SIZE subsize = get_subsize(bsize, PARTITION_HORZ); |
420 set_block_size(cpi, tile, mi_row, mi_col, subsize); | 417 set_block_size(cpi, mi_row, mi_col, subsize); |
421 set_block_size(cpi, tile, mi_row + block_height / 2, mi_col, subsize); | 418 set_block_size(cpi, mi_row + block_height / 2, mi_col, subsize); |
422 return 1; | 419 return 1; |
423 } | 420 } |
424 return 0; | 421 return 0; |
425 } | 422 } |
426 | 423 |
427 // TODO(debargha): Fix this function and make it work as expected. | 424 // TODO(debargha): Fix this function and make it work as expected. |
428 static void choose_partitioning(VP9_COMP *cpi, | 425 static void choose_partitioning(VP9_COMP *cpi, |
429 const TileInfo *const tile, | 426 const TileInfo *const tile, |
430 int mi_row, int mi_col) { | 427 int mi_row, int mi_col) { |
431 VP9_COMMON * const cm = &cpi->common; | 428 VP9_COMMON * const cm = &cpi->common; |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
498 for (j = 0; j < 4; j++) { | 495 for (j = 0; j < 4; j++) { |
499 fill_variance_tree(&vt.split[i].split[j], BLOCK_16X16); | 496 fill_variance_tree(&vt.split[i].split[j], BLOCK_16X16); |
500 } | 497 } |
501 fill_variance_tree(&vt.split[i], BLOCK_32X32); | 498 fill_variance_tree(&vt.split[i], BLOCK_32X32); |
502 } | 499 } |
503 fill_variance_tree(&vt, BLOCK_64X64); | 500 fill_variance_tree(&vt, BLOCK_64X64); |
504 | 501 |
505 // Now go through the entire structure, splitting every block size until | 502 // Now go through the entire structure, splitting every block size until |
506 // we get to one that's got a variance lower than our threshold, or we | 503 // we get to one that's got a variance lower than our threshold, or we |
507 // hit 8x8. | 504 // hit 8x8. |
508 if (!set_vt_partitioning(cpi, &vt, tile, BLOCK_64X64, | 505 if (!set_vt_partitioning(cpi, &vt, BLOCK_64X64, |
509 mi_row, mi_col, 8)) { | 506 mi_row, mi_col)) { |
510 for (i = 0; i < 4; ++i) { | 507 for (i = 0; i < 4; ++i) { |
511 const int x32_idx = ((i & 1) << 2); | 508 const int x32_idx = ((i & 1) << 2); |
512 const int y32_idx = ((i >> 1) << 2); | 509 const int y32_idx = ((i >> 1) << 2); |
513 if (!set_vt_partitioning(cpi, &vt.split[i], tile, BLOCK_32X32, | 510 if (!set_vt_partitioning(cpi, &vt.split[i], BLOCK_32X32, |
514 (mi_row + y32_idx), (mi_col + x32_idx), 4)) { | 511 (mi_row + y32_idx), (mi_col + x32_idx))) { |
515 for (j = 0; j < 4; ++j) { | 512 for (j = 0; j < 4; ++j) { |
516 const int x16_idx = ((j & 1) << 1); | 513 const int x16_idx = ((j & 1) << 1); |
517 const int y16_idx = ((j >> 1) << 1); | 514 const int y16_idx = ((j >> 1) << 1); |
518 // NOTE: This is a temporary hack to disable 8x8 partitions, | 515 // NOTE: This is a temporary hack to disable 8x8 partitions, |
519 // since it works really bad - possibly due to a bug | 516 // since it works really bad - possibly due to a bug |
520 #define DISABLE_8X8_VAR_BASED_PARTITION | 517 #define DISABLE_8X8_VAR_BASED_PARTITION |
521 #ifdef DISABLE_8X8_VAR_BASED_PARTITION | 518 #ifdef DISABLE_8X8_VAR_BASED_PARTITION |
522 if (mi_row + y32_idx + y16_idx + 1 < cm->mi_rows && | 519 if (mi_row + y32_idx + y16_idx + 1 < cm->mi_rows && |
523 mi_row + x32_idx + x16_idx + 1 < cm->mi_cols) { | 520 mi_row + x32_idx + x16_idx + 1 < cm->mi_cols) { |
524 set_block_size(cpi, tile, | 521 set_block_size(cpi, |
525 (mi_row + y32_idx + y16_idx), | 522 (mi_row + y32_idx + y16_idx), |
526 (mi_col + x32_idx + x16_idx), | 523 (mi_col + x32_idx + x16_idx), |
527 BLOCK_16X16); | 524 BLOCK_16X16); |
528 } else { | 525 } else { |
529 for (k = 0; k < 4; ++k) { | 526 for (k = 0; k < 4; ++k) { |
530 const int x8_idx = (k & 1); | 527 const int x8_idx = (k & 1); |
531 const int y8_idx = (k >> 1); | 528 const int y8_idx = (k >> 1); |
532 set_block_size(cpi, tile, | 529 set_block_size(cpi, |
533 (mi_row + y32_idx + y16_idx + y8_idx), | 530 (mi_row + y32_idx + y16_idx + y8_idx), |
534 (mi_col + x32_idx + x16_idx + x8_idx), | 531 (mi_col + x32_idx + x16_idx + x8_idx), |
535 BLOCK_8X8); | 532 BLOCK_8X8); |
536 } | 533 } |
537 } | 534 } |
538 #else | 535 #else |
539 if (!set_vt_partitioning(cpi, &vt.split[i].split[j], tile, | 536 if (!set_vt_partitioning(cpi, &vt.split[i].split[j], tile, |
540 BLOCK_16X16, | 537 BLOCK_16X16, |
541 (mi_row + y32_idx + y16_idx), | 538 (mi_row + y32_idx + y16_idx), |
542 (mi_col + x32_idx + x16_idx), 2)) { | 539 (mi_col + x32_idx + x16_idx), 2)) { |
543 for (k = 0; k < 4; ++k) { | 540 for (k = 0; k < 4; ++k) { |
544 const int x8_idx = (k & 1); | 541 const int x8_idx = (k & 1); |
545 const int y8_idx = (k >> 1); | 542 const int y8_idx = (k >> 1); |
546 set_block_size(cpi, tile, | 543 set_block_size(cpi, |
547 (mi_row + y32_idx + y16_idx + y8_idx), | 544 (mi_row + y32_idx + y16_idx + y8_idx), |
548 (mi_col + x32_idx + x16_idx + x8_idx), | 545 (mi_col + x32_idx + x16_idx + x8_idx), |
549 BLOCK_8X8); | 546 BLOCK_8X8); |
550 } | 547 } |
551 } | 548 } |
552 #endif | 549 #endif |
553 } | 550 } |
554 } | 551 } |
555 } | 552 } |
556 } | 553 } |
(...skipping 892 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1449 | 1446 |
1450 if (partition != PARTITION_SPLIT || bsize == BLOCK_8X8) | 1447 if (partition != PARTITION_SPLIT || bsize == BLOCK_8X8) |
1451 update_partition_context(xd, mi_row, mi_col, subsize, bsize); | 1448 update_partition_context(xd, mi_row, mi_col, subsize, bsize); |
1452 } | 1449 } |
1453 | 1450 |
1454 static void rd_use_partition(VP9_COMP *cpi, | 1451 static void rd_use_partition(VP9_COMP *cpi, |
1455 const TileInfo *const tile, | 1452 const TileInfo *const tile, |
1456 MODE_INFO **mi_8x8, | 1453 MODE_INFO **mi_8x8, |
1457 TOKENEXTRA **tp, int mi_row, int mi_col, | 1454 TOKENEXTRA **tp, int mi_row, int mi_col, |
1458 BLOCK_SIZE bsize, int *rate, int64_t *dist, | 1455 BLOCK_SIZE bsize, int *rate, int64_t *dist, |
1459 int do_recon, PC_TREE *pc_tree, | 1456 int do_recon, PC_TREE *pc_tree) { |
1460 int block) { | |
1461 VP9_COMMON *const cm = &cpi->common; | 1457 VP9_COMMON *const cm = &cpi->common; |
1462 MACROBLOCK *const x = &cpi->mb; | 1458 MACROBLOCK *const x = &cpi->mb; |
1463 MACROBLOCKD *const xd = &x->e_mbd; | 1459 MACROBLOCKD *const xd = &x->e_mbd; |
1464 const int mis = cm->mi_stride; | 1460 const int mis = cm->mi_stride; |
1465 const int bsl = b_width_log2(bsize); | 1461 const int bsl = b_width_log2(bsize); |
1466 const int mi_step = num_4x4_blocks_wide_lookup[bsize] / 2; | 1462 const int mi_step = num_4x4_blocks_wide_lookup[bsize] / 2; |
1467 const int bss = (1 << bsl) / 4; | 1463 const int bss = (1 << bsl) / 4; |
1468 int i, pl; | 1464 int i, pl; |
1469 PARTITION_TYPE partition = PARTITION_NONE; | 1465 PARTITION_TYPE partition = PARTITION_NONE; |
1470 BLOCK_SIZE subsize; | 1466 BLOCK_SIZE subsize; |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1617 int y_idx = (i >> 1) * (mi_step >> 1); | 1613 int y_idx = (i >> 1) * (mi_step >> 1); |
1618 int jj = i >> 1, ii = i & 0x01; | 1614 int jj = i >> 1, ii = i & 0x01; |
1619 int rt; | 1615 int rt; |
1620 int64_t dt; | 1616 int64_t dt; |
1621 | 1617 |
1622 if ((mi_row + y_idx >= cm->mi_rows) || (mi_col + x_idx >= cm->mi_cols)) | 1618 if ((mi_row + y_idx >= cm->mi_rows) || (mi_col + x_idx >= cm->mi_cols)) |
1623 continue; | 1619 continue; |
1624 | 1620 |
1625 rd_use_partition(cpi, tile, mi_8x8 + jj * bss * mis + ii * bss, tp, | 1621 rd_use_partition(cpi, tile, mi_8x8 + jj * bss * mis + ii * bss, tp, |
1626 mi_row + y_idx, mi_col + x_idx, subsize, &rt, &dt, | 1622 mi_row + y_idx, mi_col + x_idx, subsize, &rt, &dt, |
1627 i != 3, pc_tree->split[i], i); | 1623 i != 3, pc_tree->split[i]); |
1628 if (rt == INT_MAX || dt == INT64_MAX) { | 1624 if (rt == INT_MAX || dt == INT64_MAX) { |
1629 last_part_rate = INT_MAX; | 1625 last_part_rate = INT_MAX; |
1630 last_part_dist = INT64_MAX; | 1626 last_part_dist = INT64_MAX; |
1631 break; | 1627 break; |
1632 } | 1628 } |
1633 last_part_rate += rt; | 1629 last_part_rate += rt; |
1634 last_part_dist += dt; | 1630 last_part_dist += dt; |
1635 } | 1631 } |
1636 break; | 1632 break; |
1637 default: | 1633 default: |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1802 }; | 1798 }; |
1803 | 1799 |
1804 // Look at neighboring blocks and set a min and max partition size based on | 1800 // Look at neighboring blocks and set a min and max partition size based on |
1805 // what they chose. | 1801 // what they chose. |
1806 static void rd_auto_partition_range(VP9_COMP *cpi, const TileInfo *const tile, | 1802 static void rd_auto_partition_range(VP9_COMP *cpi, const TileInfo *const tile, |
1807 int mi_row, int mi_col, | 1803 int mi_row, int mi_col, |
1808 BLOCK_SIZE *min_block_size, | 1804 BLOCK_SIZE *min_block_size, |
1809 BLOCK_SIZE *max_block_size) { | 1805 BLOCK_SIZE *max_block_size) { |
1810 VP9_COMMON *const cm = &cpi->common; | 1806 VP9_COMMON *const cm = &cpi->common; |
1811 MACROBLOCKD *const xd = &cpi->mb.e_mbd; | 1807 MACROBLOCKD *const xd = &cpi->mb.e_mbd; |
1812 MODE_INFO **mi_8x8 = xd->mi; | 1808 MODE_INFO **mi = xd->mi; |
1813 const int left_in_image = xd->left_available && mi_8x8[-1]; | 1809 const int left_in_image = xd->left_available && mi[-1]; |
1814 const int above_in_image = xd->up_available && | 1810 const int above_in_image = xd->up_available && mi[-xd->mi_stride]; |
1815 mi_8x8[-xd->mi_stride]; | 1811 const int row8x8_remaining = tile->mi_row_end - mi_row; |
1816 MODE_INFO **above_sb64_mi_8x8; | 1812 const int col8x8_remaining = tile->mi_col_end - mi_col; |
1817 MODE_INFO **left_sb64_mi_8x8; | |
1818 | |
1819 int row8x8_remaining = tile->mi_row_end - mi_row; | |
1820 int col8x8_remaining = tile->mi_col_end - mi_col; | |
1821 int bh, bw; | 1813 int bh, bw; |
1822 BLOCK_SIZE min_size = BLOCK_4X4; | 1814 BLOCK_SIZE min_size = BLOCK_4X4; |
1823 BLOCK_SIZE max_size = BLOCK_64X64; | 1815 BLOCK_SIZE max_size = BLOCK_64X64; |
1824 // Trap case where we do not have a prediction. | 1816 // Trap case where we do not have a prediction. |
1825 if (left_in_image || above_in_image || cm->frame_type != KEY_FRAME) { | 1817 if (left_in_image || above_in_image || cm->frame_type != KEY_FRAME) { |
1826 // Default "min to max" and "max to min" | 1818 // Default "min to max" and "max to min" |
1827 min_size = BLOCK_64X64; | 1819 min_size = BLOCK_64X64; |
1828 max_size = BLOCK_4X4; | 1820 max_size = BLOCK_4X4; |
1829 | 1821 |
1830 // NOTE: each call to get_sb_partition_size_range() uses the previous | 1822 // NOTE: each call to get_sb_partition_size_range() uses the previous |
1831 // passed in values for min and max as a starting point. | 1823 // passed in values for min and max as a starting point. |
1832 // Find the min and max partition used in previous frame at this location | 1824 // Find the min and max partition used in previous frame at this location |
1833 if (cm->frame_type != KEY_FRAME) { | 1825 if (cm->frame_type != KEY_FRAME) { |
1834 MODE_INFO **const prev_mi = | 1826 MODE_INFO **const prev_mi = |
1835 &cm->prev_mi_grid_visible[mi_row * xd->mi_stride + mi_col]; | 1827 &cm->prev_mi_grid_visible[mi_row * xd->mi_stride + mi_col]; |
1836 get_sb_partition_size_range(cpi, prev_mi, &min_size, &max_size); | 1828 get_sb_partition_size_range(cpi, prev_mi, &min_size, &max_size); |
1837 } | 1829 } |
1838 // Find the min and max partition sizes used in the left SB64 | 1830 // Find the min and max partition sizes used in the left SB64 |
1839 if (left_in_image) { | 1831 if (left_in_image) { |
1840 left_sb64_mi_8x8 = &mi_8x8[-MI_BLOCK_SIZE]; | 1832 MODE_INFO **left_sb64_mi = &mi[-MI_BLOCK_SIZE]; |
1841 get_sb_partition_size_range(cpi, left_sb64_mi_8x8, | 1833 get_sb_partition_size_range(cpi, left_sb64_mi, &min_size, &max_size); |
1842 &min_size, &max_size); | |
1843 } | 1834 } |
1844 // Find the min and max partition sizes used in the above SB64. | 1835 // Find the min and max partition sizes used in the above SB64. |
1845 if (above_in_image) { | 1836 if (above_in_image) { |
1846 above_sb64_mi_8x8 = &mi_8x8[-xd->mi_stride * MI_BLOCK_SIZE]; | 1837 MODE_INFO **above_sb64_mi = &mi[-xd->mi_stride * MI_BLOCK_SIZE]; |
1847 get_sb_partition_size_range(cpi, above_sb64_mi_8x8, | 1838 get_sb_partition_size_range(cpi, above_sb64_mi, &min_size, &max_size); |
1848 &min_size, &max_size); | |
1849 } | 1839 } |
1850 // adjust observed min and max | 1840 // adjust observed min and max |
1851 if (cpi->sf.auto_min_max_partition_size == RELAXED_NEIGHBORING_MIN_MAX) { | 1841 if (cpi->sf.auto_min_max_partition_size == RELAXED_NEIGHBORING_MIN_MAX) { |
1852 min_size = min_partition_size[min_size]; | 1842 min_size = min_partition_size[min_size]; |
1853 max_size = max_partition_size[max_size]; | 1843 max_size = max_partition_size[max_size]; |
1854 } | 1844 } |
1855 } | 1845 } |
1856 | 1846 |
1857 // Check border cases where max and min from neighbors may not be legal. | 1847 // Check border cases where max and min from neighbors may not be legal. |
1858 max_size = find_partition_size(max_size, | 1848 max_size = find_partition_size(max_size, |
1859 row8x8_remaining, col8x8_remaining, | 1849 row8x8_remaining, col8x8_remaining, |
1860 &bh, &bw); | 1850 &bh, &bw); |
1861 min_size = MIN(min_size, max_size); | 1851 min_size = MIN(min_size, max_size); |
1862 | 1852 |
1863 // When use_square_partition_only is true, make sure at least one square | 1853 // When use_square_partition_only is true, make sure at least one square |
1864 // partition is allowed by selecting the next smaller square size as | 1854 // partition is allowed by selecting the next smaller square size as |
1865 // *min_block_size. | 1855 // *min_block_size. |
1866 if (cpi->sf.use_square_partition_only && | 1856 if (cpi->sf.use_square_partition_only && |
1867 next_square_size[max_size] < min_size) { | 1857 next_square_size[max_size] < min_size) { |
1868 min_size = next_square_size[max_size]; | 1858 min_size = next_square_size[max_size]; |
1869 } | 1859 } |
1870 *min_block_size = min_size; | 1860 *min_block_size = min_size; |
1871 *max_block_size = max_size; | 1861 *max_block_size = max_size; |
1872 } | 1862 } |
1873 | 1863 |
| 1864 static void auto_partition_range(VP9_COMP *cpi, const TileInfo *const tile, |
| 1865 int mi_row, int mi_col, |
| 1866 BLOCK_SIZE *min_block_size, |
| 1867 BLOCK_SIZE *max_block_size) { |
| 1868 VP9_COMMON *const cm = &cpi->common; |
| 1869 MACROBLOCKD *const xd = &cpi->mb.e_mbd; |
| 1870 MODE_INFO **mi_8x8 = xd->mi; |
| 1871 const int left_in_image = xd->left_available && mi_8x8[-1]; |
| 1872 const int above_in_image = xd->up_available && |
| 1873 mi_8x8[-xd->mi_stride]; |
| 1874 int row8x8_remaining = tile->mi_row_end - mi_row; |
| 1875 int col8x8_remaining = tile->mi_col_end - mi_col; |
| 1876 int bh, bw; |
| 1877 BLOCK_SIZE min_size = BLOCK_32X32; |
| 1878 BLOCK_SIZE max_size = BLOCK_8X8; |
| 1879 int bsl = mi_width_log2_lookup[BLOCK_64X64]; |
| 1880 int search_range_ctrl = (((mi_row + mi_col) >> bsl) + |
| 1881 cpi->sf.chessboard_index) & 0x01; |
| 1882 // Trap case where we do not have a prediction. |
| 1883 if (search_range_ctrl && |
| 1884 (left_in_image || above_in_image || cm->frame_type != KEY_FRAME)) { |
| 1885 int block; |
| 1886 MODE_INFO **mi; |
| 1887 BLOCK_SIZE sb_type; |
| 1888 |
| 1889 // Find the min and max partition sizes used in the left SB64. |
| 1890 if (left_in_image) { |
| 1891 MODE_INFO *cur_mi; |
| 1892 mi = &mi_8x8[-1]; |
| 1893 for (block = 0; block < MI_BLOCK_SIZE; ++block) { |
| 1894 cur_mi = mi[block * xd->mi_stride]; |
| 1895 sb_type = cur_mi ? cur_mi->mbmi.sb_type : 0; |
| 1896 min_size = MIN(min_size, sb_type); |
| 1897 max_size = MAX(max_size, sb_type); |
| 1898 } |
| 1899 } |
| 1900 // Find the min and max partition sizes used in the above SB64. |
| 1901 if (above_in_image) { |
| 1902 mi = &mi_8x8[-xd->mi_stride * MI_BLOCK_SIZE]; |
| 1903 for (block = 0; block < MI_BLOCK_SIZE; ++block) { |
| 1904 sb_type = mi[block] ? mi[block]->mbmi.sb_type : 0; |
| 1905 min_size = MIN(min_size, sb_type); |
| 1906 max_size = MAX(max_size, sb_type); |
| 1907 } |
| 1908 } |
| 1909 |
| 1910 min_size = min_partition_size[min_size]; |
| 1911 max_size = find_partition_size(max_size, row8x8_remaining, col8x8_remaining, |
| 1912 &bh, &bw); |
| 1913 min_size = MIN(min_size, max_size); |
| 1914 min_size = MAX(min_size, BLOCK_8X8); |
| 1915 max_size = MIN(max_size, BLOCK_32X32); |
| 1916 } else { |
| 1917 min_size = BLOCK_8X8; |
| 1918 max_size = BLOCK_32X32; |
| 1919 } |
| 1920 |
| 1921 *min_block_size = min_size; |
| 1922 *max_block_size = max_size; |
| 1923 } |
| 1924 |
1874 static INLINE void store_pred_mv(MACROBLOCK *x, PICK_MODE_CONTEXT *ctx) { | 1925 static INLINE void store_pred_mv(MACROBLOCK *x, PICK_MODE_CONTEXT *ctx) { |
1875 vpx_memcpy(ctx->pred_mv, x->pred_mv, sizeof(x->pred_mv)); | 1926 vpx_memcpy(ctx->pred_mv, x->pred_mv, sizeof(x->pred_mv)); |
1876 } | 1927 } |
1877 | 1928 |
1878 static INLINE void load_pred_mv(MACROBLOCK *x, PICK_MODE_CONTEXT *ctx) { | 1929 static INLINE void load_pred_mv(MACROBLOCK *x, PICK_MODE_CONTEXT *ctx) { |
1879 vpx_memcpy(x->pred_mv, ctx->pred_mv, sizeof(x->pred_mv)); | 1930 vpx_memcpy(x->pred_mv, ctx->pred_mv, sizeof(x->pred_mv)); |
1880 } | 1931 } |
1881 | 1932 |
1882 // TODO(jingning,jimbankoski,rbultje): properly skip partition types that are | 1933 // TODO(jingning,jimbankoski,rbultje): properly skip partition types that are |
1883 // unlikely to be selected depending on previous rate-distortion optimization | 1934 // unlikely to be selected depending on previous rate-distortion optimization |
1884 // results, for encoding speed-up. | 1935 // results, for encoding speed-up. |
1885 static void rd_pick_partition(VP9_COMP *cpi, const TileInfo *const tile, | 1936 static void rd_pick_partition(VP9_COMP *cpi, const TileInfo *const tile, |
1886 TOKENEXTRA **tp, int mi_row, | 1937 TOKENEXTRA **tp, int mi_row, |
1887 int mi_col, BLOCK_SIZE bsize, int *rate, | 1938 int mi_col, BLOCK_SIZE bsize, int *rate, |
1888 int64_t *dist, int do_recon, int64_t best_rd, | 1939 int64_t *dist, int do_recon, int64_t best_rd, |
1889 PC_TREE *pc_tree, int block) { | 1940 PC_TREE *pc_tree) { |
1890 VP9_COMMON *const cm = &cpi->common; | 1941 VP9_COMMON *const cm = &cpi->common; |
1891 MACROBLOCK *const x = &cpi->mb; | 1942 MACROBLOCK *const x = &cpi->mb; |
1892 MACROBLOCKD *const xd = &x->e_mbd; | 1943 MACROBLOCKD *const xd = &x->e_mbd; |
1893 const int mi_step = num_8x8_blocks_wide_lookup[bsize] / 2; | 1944 const int mi_step = num_8x8_blocks_wide_lookup[bsize] / 2; |
1894 ENTROPY_CONTEXT l[16 * MAX_MB_PLANE], a[16 * MAX_MB_PLANE]; | 1945 ENTROPY_CONTEXT l[16 * MAX_MB_PLANE], a[16 * MAX_MB_PLANE]; |
1895 PARTITION_CONTEXT sl[8], sa[8]; | 1946 PARTITION_CONTEXT sl[8], sa[8]; |
1896 TOKENEXTRA *tp_orig = *tp; | 1947 TOKENEXTRA *tp_orig = *tp; |
1897 PICK_MODE_CONTEXT *ctx = &pc_tree->none; | 1948 PICK_MODE_CONTEXT *ctx = &pc_tree->none; |
1898 int i, pl; | 1949 int i, pl; |
1899 BLOCK_SIZE subsize; | 1950 BLOCK_SIZE subsize; |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2031 const int y_idx = (i >> 1) * mi_step; | 2082 const int y_idx = (i >> 1) * mi_step; |
2032 | 2083 |
2033 if (mi_row + y_idx >= cm->mi_rows || mi_col + x_idx >= cm->mi_cols) | 2084 if (mi_row + y_idx >= cm->mi_rows || mi_col + x_idx >= cm->mi_cols) |
2034 continue; | 2085 continue; |
2035 | 2086 |
2036 if (cpi->sf.adaptive_motion_search) | 2087 if (cpi->sf.adaptive_motion_search) |
2037 load_pred_mv(x, ctx); | 2088 load_pred_mv(x, ctx); |
2038 | 2089 |
2039 rd_pick_partition(cpi, tile, tp, mi_row + y_idx, mi_col + x_idx, | 2090 rd_pick_partition(cpi, tile, tp, mi_row + y_idx, mi_col + x_idx, |
2040 subsize, &this_rate, &this_dist, i != 3, | 2091 subsize, &this_rate, &this_dist, i != 3, |
2041 best_rd - sum_rd, pc_tree->split[i], i); | 2092 best_rd - sum_rd, pc_tree->split[i]); |
2042 | 2093 |
2043 if (this_rate == INT_MAX) { | 2094 if (this_rate == INT_MAX) { |
2044 sum_rd = INT64_MAX; | 2095 sum_rd = INT64_MAX; |
2045 } else { | 2096 } else { |
2046 sum_rate += this_rate; | 2097 sum_rate += this_rate; |
2047 sum_dist += this_dist; | 2098 sum_dist += this_dist; |
2048 sum_rd = RDCOST(x->rdmult, x->rddiv, sum_rate, sum_dist); | 2099 sum_rd = RDCOST(x->rdmult, x->rddiv, sum_rate, sum_dist); |
2049 } | 2100 } |
2050 } | 2101 } |
2051 } | 2102 } |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2232 } | 2283 } |
2233 | 2284 |
2234 vp9_zero(cpi->mb.pred_mv); | 2285 vp9_zero(cpi->mb.pred_mv); |
2235 | 2286 |
2236 if ((sf->partition_search_type == SEARCH_PARTITION && | 2287 if ((sf->partition_search_type == SEARCH_PARTITION && |
2237 sf->use_lastframe_partitioning) || | 2288 sf->use_lastframe_partitioning) || |
2238 sf->partition_search_type == FIXED_PARTITION || | 2289 sf->partition_search_type == FIXED_PARTITION || |
2239 sf->partition_search_type == VAR_BASED_PARTITION || | 2290 sf->partition_search_type == VAR_BASED_PARTITION || |
2240 sf->partition_search_type == VAR_BASED_FIXED_PARTITION) { | 2291 sf->partition_search_type == VAR_BASED_FIXED_PARTITION) { |
2241 const int idx_str = cm->mi_stride * mi_row + mi_col; | 2292 const int idx_str = cm->mi_stride * mi_row + mi_col; |
2242 MODE_INFO **mi_8x8 = cm->mi_grid_visible + idx_str; | 2293 MODE_INFO **mi = cm->mi_grid_visible + idx_str; |
2243 MODE_INFO **prev_mi_8x8 = cm->prev_mi_grid_visible + idx_str; | 2294 MODE_INFO **prev_mi = cm->prev_mi_grid_visible + idx_str; |
2244 cpi->mb.source_variance = UINT_MAX; | 2295 cpi->mb.source_variance = UINT_MAX; |
2245 if (sf->partition_search_type == FIXED_PARTITION) { | 2296 if (sf->partition_search_type == FIXED_PARTITION) { |
2246 set_offsets(cpi, tile, mi_row, mi_col, BLOCK_64X64); | 2297 set_offsets(cpi, tile, mi_row, mi_col, BLOCK_64X64); |
2247 set_fixed_partitioning(cpi, tile, mi_8x8, mi_row, mi_col, | 2298 set_fixed_partitioning(cpi, tile, mi, mi_row, mi_col, |
2248 sf->always_this_block_size); | 2299 sf->always_this_block_size); |
2249 rd_use_partition(cpi, tile, mi_8x8, tp, mi_row, mi_col, BLOCK_64X64, | 2300 rd_use_partition(cpi, tile, mi, tp, mi_row, mi_col, BLOCK_64X64, |
2250 &dummy_rate, &dummy_dist, 1, x->pc_root, 0); | 2301 &dummy_rate, &dummy_dist, 1, x->pc_root); |
2251 } else if (sf->partition_search_type == VAR_BASED_FIXED_PARTITION) { | 2302 } else if (sf->partition_search_type == VAR_BASED_FIXED_PARTITION) { |
2252 BLOCK_SIZE bsize; | 2303 BLOCK_SIZE bsize; |
2253 set_offsets(cpi, tile, mi_row, mi_col, BLOCK_64X64); | 2304 set_offsets(cpi, tile, mi_row, mi_col, BLOCK_64X64); |
2254 bsize = get_rd_var_based_fixed_partition(cpi, mi_row, mi_col); | 2305 bsize = get_rd_var_based_fixed_partition(cpi, mi_row, mi_col); |
2255 set_fixed_partitioning(cpi, tile, mi_8x8, mi_row, mi_col, bsize); | 2306 set_fixed_partitioning(cpi, tile, mi, mi_row, mi_col, bsize); |
2256 rd_use_partition(cpi, tile, mi_8x8, tp, mi_row, mi_col, BLOCK_64X64, | 2307 rd_use_partition(cpi, tile, mi, tp, mi_row, mi_col, BLOCK_64X64, |
2257 &dummy_rate, &dummy_dist, 1, x->pc_root, 0); | 2308 &dummy_rate, &dummy_dist, 1, x->pc_root); |
2258 } else if (sf->partition_search_type == VAR_BASED_PARTITION) { | 2309 } else if (sf->partition_search_type == VAR_BASED_PARTITION) { |
2259 choose_partitioning(cpi, tile, mi_row, mi_col); | 2310 choose_partitioning(cpi, tile, mi_row, mi_col); |
2260 rd_use_partition(cpi, tile, mi_8x8, tp, mi_row, mi_col, BLOCK_64X64, | 2311 rd_use_partition(cpi, tile, mi, tp, mi_row, mi_col, BLOCK_64X64, |
2261 &dummy_rate, &dummy_dist, 1, x->pc_root, 0); | 2312 &dummy_rate, &dummy_dist, 1, x->pc_root); |
2262 } else { | 2313 } else { |
2263 if ((cm->current_video_frame | 2314 if ((cm->current_video_frame |
2264 % sf->last_partitioning_redo_frequency) == 0 | 2315 % sf->last_partitioning_redo_frequency) == 0 |
2265 || cm->prev_mi == 0 | 2316 || cm->prev_mi == 0 |
2266 || cm->show_frame == 0 | 2317 || cm->show_frame == 0 |
2267 || cm->frame_type == KEY_FRAME | 2318 || cm->frame_type == KEY_FRAME |
2268 || cpi->rc.is_src_frame_alt_ref | 2319 || cpi->rc.is_src_frame_alt_ref |
2269 || ((sf->use_lastframe_partitioning == | 2320 || ((sf->use_lastframe_partitioning == |
2270 LAST_FRAME_PARTITION_LOW_MOTION) && | 2321 LAST_FRAME_PARTITION_LOW_MOTION) && |
2271 sb_has_motion(cm, prev_mi_8x8))) { | 2322 sb_has_motion(cm, prev_mi))) { |
2272 // If required set upper and lower partition size limits | 2323 // If required set upper and lower partition size limits |
2273 if (sf->auto_min_max_partition_size) { | 2324 if (sf->auto_min_max_partition_size) { |
2274 set_offsets(cpi, tile, mi_row, mi_col, BLOCK_64X64); | 2325 set_offsets(cpi, tile, mi_row, mi_col, BLOCK_64X64); |
2275 rd_auto_partition_range(cpi, tile, mi_row, mi_col, | 2326 rd_auto_partition_range(cpi, tile, mi_row, mi_col, |
2276 &sf->min_partition_size, | 2327 &sf->min_partition_size, |
2277 &sf->max_partition_size); | 2328 &sf->max_partition_size); |
2278 } | 2329 } |
2279 rd_pick_partition(cpi, tile, tp, mi_row, mi_col, BLOCK_64X64, | 2330 rd_pick_partition(cpi, tile, tp, mi_row, mi_col, BLOCK_64X64, |
2280 &dummy_rate, &dummy_dist, 1, INT64_MAX, x->pc_root, | 2331 &dummy_rate, &dummy_dist, 1, INT64_MAX, x->pc_root); |
2281 0); | |
2282 } else { | 2332 } else { |
2283 if (sf->constrain_copy_partition && | 2333 if (sf->constrain_copy_partition && |
2284 sb_has_motion(cm, prev_mi_8x8)) | 2334 sb_has_motion(cm, prev_mi)) |
2285 constrain_copy_partitioning(cpi, tile, mi_8x8, prev_mi_8x8, | 2335 constrain_copy_partitioning(cpi, tile, mi, prev_mi, |
2286 mi_row, mi_col, BLOCK_16X16); | 2336 mi_row, mi_col, BLOCK_16X16); |
2287 else | 2337 else |
2288 copy_partitioning(cm, mi_8x8, prev_mi_8x8); | 2338 copy_partitioning(cm, mi, prev_mi); |
2289 rd_use_partition(cpi, tile, mi_8x8, tp, mi_row, mi_col, BLOCK_64X64, | 2339 rd_use_partition(cpi, tile, mi, tp, mi_row, mi_col, BLOCK_64X64, |
2290 &dummy_rate, &dummy_dist, 1, x->pc_root, 0); | 2340 &dummy_rate, &dummy_dist, 1, x->pc_root); |
2291 } | 2341 } |
2292 } | 2342 } |
2293 } else { | 2343 } else { |
2294 // If required set upper and lower partition size limits | 2344 // If required set upper and lower partition size limits |
2295 if (sf->auto_min_max_partition_size) { | 2345 if (sf->auto_min_max_partition_size) { |
2296 set_offsets(cpi, tile, mi_row, mi_col, BLOCK_64X64); | 2346 set_offsets(cpi, tile, mi_row, mi_col, BLOCK_64X64); |
2297 rd_auto_partition_range(cpi, tile, mi_row, mi_col, | 2347 rd_auto_partition_range(cpi, tile, mi_row, mi_col, |
2298 &sf->min_partition_size, | 2348 &sf->min_partition_size, |
2299 &sf->max_partition_size); | 2349 &sf->max_partition_size); |
2300 } | 2350 } |
2301 rd_pick_partition(cpi, tile, tp, mi_row, mi_col, BLOCK_64X64, | 2351 rd_pick_partition(cpi, tile, tp, mi_row, mi_col, BLOCK_64X64, |
2302 &dummy_rate, &dummy_dist, 1, INT64_MAX, x->pc_root, 0); | 2352 &dummy_rate, &dummy_dist, 1, INT64_MAX, x->pc_root); |
2303 } | 2353 } |
2304 } | 2354 } |
2305 } | 2355 } |
2306 | 2356 |
2307 static void init_encode_frame_mb_context(VP9_COMP *cpi) { | 2357 static void init_encode_frame_mb_context(VP9_COMP *cpi) { |
2308 MACROBLOCK *const x = &cpi->mb; | 2358 MACROBLOCK *const x = &cpi->mb; |
2309 VP9_COMMON *const cm = &cpi->common; | 2359 VP9_COMMON *const cm = &cpi->common; |
2310 MACROBLOCKD *const xd = &x->e_mbd; | 2360 MACROBLOCKD *const xd = &x->e_mbd; |
2311 const int aligned_mi_cols = mi_cols_aligned_to_sb(cm->mi_cols); | 2361 const int aligned_mi_cols = mi_cols_aligned_to_sb(cm->mi_cols); |
2312 | 2362 |
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2616 if (do_split) { | 2666 if (do_split) { |
2617 int pl = partition_plane_context(xd, mi_row, mi_col, bsize); | 2667 int pl = partition_plane_context(xd, mi_row, mi_col, bsize); |
2618 sum_rate += x->partition_cost[pl][PARTITION_SPLIT]; | 2668 sum_rate += x->partition_cost[pl][PARTITION_SPLIT]; |
2619 subsize = get_subsize(bsize, PARTITION_SPLIT); | 2669 subsize = get_subsize(bsize, PARTITION_SPLIT); |
2620 for (i = 0; i < 4 && sum_rd < best_rd; ++i) { | 2670 for (i = 0; i < 4 && sum_rd < best_rd; ++i) { |
2621 const int x_idx = (i & 1) * ms; | 2671 const int x_idx = (i & 1) * ms; |
2622 const int y_idx = (i >> 1) * ms; | 2672 const int y_idx = (i >> 1) * ms; |
2623 | 2673 |
2624 if (mi_row + y_idx >= cm->mi_rows || mi_col + x_idx >= cm->mi_cols) | 2674 if (mi_row + y_idx >= cm->mi_rows || mi_col + x_idx >= cm->mi_cols) |
2625 continue; | 2675 continue; |
2626 | |
2627 load_pred_mv(x, ctx); | 2676 load_pred_mv(x, ctx); |
2628 | |
2629 nonrd_pick_partition(cpi, tile, tp, mi_row + y_idx, mi_col + x_idx, | 2677 nonrd_pick_partition(cpi, tile, tp, mi_row + y_idx, mi_col + x_idx, |
2630 subsize, &this_rate, &this_dist, 0, | 2678 subsize, &this_rate, &this_dist, 0, |
2631 best_rd - sum_rd, pc_tree->split[i]); | 2679 best_rd - sum_rd, pc_tree->split[i]); |
2632 | 2680 |
2633 if (this_rate == INT_MAX) { | 2681 if (this_rate == INT_MAX) { |
2634 sum_rd = INT64_MAX; | 2682 sum_rd = INT64_MAX; |
2635 } else { | 2683 } else { |
2636 sum_rate += this_rate; | 2684 sum_rate += this_rate; |
2637 sum_dist += this_dist; | 2685 sum_dist += this_dist; |
2638 sum_rd = RDCOST(x->rdmult, x->rddiv, sum_rate, sum_dist); | 2686 sum_rd = RDCOST(x->rdmult, x->rddiv, sum_rate, sum_dist); |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2761 assert(tp_orig < *tp); | 2809 assert(tp_orig < *tp); |
2762 assert(best_rate < INT_MAX); | 2810 assert(best_rate < INT_MAX); |
2763 assert(best_dist < INT64_MAX); | 2811 assert(best_dist < INT64_MAX); |
2764 } else { | 2812 } else { |
2765 assert(tp_orig == *tp); | 2813 assert(tp_orig == *tp); |
2766 } | 2814 } |
2767 } | 2815 } |
2768 | 2816 |
2769 static void nonrd_use_partition(VP9_COMP *cpi, | 2817 static void nonrd_use_partition(VP9_COMP *cpi, |
2770 const TileInfo *const tile, | 2818 const TileInfo *const tile, |
2771 MODE_INFO **mi_8x8, | 2819 MODE_INFO **mi, |
2772 TOKENEXTRA **tp, | 2820 TOKENEXTRA **tp, |
2773 int mi_row, int mi_col, | 2821 int mi_row, int mi_col, |
2774 BLOCK_SIZE bsize, int output_enabled, | 2822 BLOCK_SIZE bsize, int output_enabled, |
2775 int *totrate, int64_t *totdist, | 2823 int *totrate, int64_t *totdist, |
2776 PC_TREE *pc_tree) { | 2824 PC_TREE *pc_tree) { |
2777 VP9_COMMON *const cm = &cpi->common; | 2825 VP9_COMMON *const cm = &cpi->common; |
2778 MACROBLOCK *const x = &cpi->mb; | 2826 MACROBLOCK *const x = &cpi->mb; |
2779 MACROBLOCKD *const xd = &x->e_mbd; | 2827 MACROBLOCKD *const xd = &x->e_mbd; |
2780 const int bsl = b_width_log2(bsize), hbs = (1 << bsl) / 4; | 2828 const int bsl = b_width_log2(bsize), hbs = (1 << bsl) / 4; |
2781 const int mis = cm->mi_stride; | 2829 const int mis = cm->mi_stride; |
2782 PARTITION_TYPE partition; | 2830 PARTITION_TYPE partition; |
2783 BLOCK_SIZE subsize; | 2831 BLOCK_SIZE subsize; |
2784 int rate = INT_MAX; | 2832 int rate = INT_MAX; |
2785 int64_t dist = INT64_MAX; | 2833 int64_t dist = INT64_MAX; |
2786 | 2834 |
2787 if (mi_row >= cm->mi_rows || mi_col >= cm->mi_cols) | 2835 if (mi_row >= cm->mi_rows || mi_col >= cm->mi_cols) |
2788 return; | 2836 return; |
2789 | 2837 |
2790 subsize = (bsize >= BLOCK_8X8) ? mi_8x8[0]->mbmi.sb_type : BLOCK_4X4; | 2838 subsize = (bsize >= BLOCK_8X8) ? mi[0]->mbmi.sb_type : BLOCK_4X4; |
2791 partition = partition_lookup[bsl][subsize]; | 2839 partition = partition_lookup[bsl][subsize]; |
2792 | 2840 |
2793 switch (partition) { | 2841 switch (partition) { |
2794 case PARTITION_NONE: | 2842 case PARTITION_NONE: |
2795 nonrd_pick_sb_modes(cpi, tile, mi_row, mi_col, totrate, totdist, subsize); | 2843 nonrd_pick_sb_modes(cpi, tile, mi_row, mi_col, totrate, totdist, subsize); |
2796 pc_tree->none.mic.mbmi = xd->mi[0]->mbmi; | 2844 pc_tree->none.mic.mbmi = xd->mi[0]->mbmi; |
2797 break; | 2845 break; |
2798 case PARTITION_VERT: | 2846 case PARTITION_VERT: |
2799 nonrd_pick_sb_modes(cpi, tile, mi_row, mi_col, totrate, totdist, subsize); | 2847 nonrd_pick_sb_modes(cpi, tile, mi_row, mi_col, totrate, totdist, subsize); |
2800 pc_tree->vertical[0].mic.mbmi = xd->mi[0]->mbmi; | 2848 pc_tree->vertical[0].mic.mbmi = xd->mi[0]->mbmi; |
2801 if (mi_col + hbs < cm->mi_cols) { | 2849 if (mi_col + hbs < cm->mi_cols) { |
2802 nonrd_pick_sb_modes(cpi, tile, mi_row, mi_col + hbs, | 2850 nonrd_pick_sb_modes(cpi, tile, mi_row, mi_col + hbs, |
2803 &rate, &dist, subsize); | 2851 &rate, &dist, subsize); |
2804 pc_tree->vertical[1].mic.mbmi = xd->mi[0]->mbmi; | 2852 pc_tree->vertical[1].mic.mbmi = xd->mi[0]->mbmi; |
2805 if (rate != INT_MAX && dist != INT64_MAX && | 2853 if (rate != INT_MAX && dist != INT64_MAX && |
2806 *totrate != INT_MAX && *totdist != INT64_MAX) { | 2854 *totrate != INT_MAX && *totdist != INT64_MAX) { |
2807 *totrate += rate; | 2855 *totrate += rate; |
2808 *totdist += dist; | 2856 *totdist += dist; |
2809 } | 2857 } |
2810 } | 2858 } |
2811 break; | 2859 break; |
2812 case PARTITION_HORZ: | 2860 case PARTITION_HORZ: |
2813 nonrd_pick_sb_modes(cpi, tile, mi_row, mi_col, totrate, totdist, subsize); | 2861 nonrd_pick_sb_modes(cpi, tile, mi_row, mi_col, totrate, totdist, subsize); |
2814 pc_tree->horizontal[0].mic.mbmi = xd->mi[0]->mbmi; | 2862 pc_tree->horizontal[0].mic.mbmi = xd->mi[0]->mbmi; |
2815 if (mi_row + hbs < cm->mi_rows) { | 2863 if (mi_row + hbs < cm->mi_rows) { |
2816 nonrd_pick_sb_modes(cpi, tile, mi_row + hbs, mi_col, | 2864 nonrd_pick_sb_modes(cpi, tile, mi_row + hbs, mi_col, |
2817 &rate, &dist, subsize); | 2865 &rate, &dist, subsize); |
2818 pc_tree->horizontal[1].mic.mbmi = mi_8x8[0]->mbmi; | 2866 pc_tree->horizontal[1].mic.mbmi = mi[0]->mbmi; |
2819 if (rate != INT_MAX && dist != INT64_MAX && | 2867 if (rate != INT_MAX && dist != INT64_MAX && |
2820 *totrate != INT_MAX && *totdist != INT64_MAX) { | 2868 *totrate != INT_MAX && *totdist != INT64_MAX) { |
2821 *totrate += rate; | 2869 *totrate += rate; |
2822 *totdist += dist; | 2870 *totdist += dist; |
2823 } | 2871 } |
2824 } | 2872 } |
2825 break; | 2873 break; |
2826 case PARTITION_SPLIT: | 2874 case PARTITION_SPLIT: |
2827 subsize = get_subsize(bsize, PARTITION_SPLIT); | 2875 subsize = get_subsize(bsize, PARTITION_SPLIT); |
2828 nonrd_use_partition(cpi, tile, mi_8x8, tp, mi_row, mi_col, | 2876 nonrd_use_partition(cpi, tile, mi, tp, mi_row, mi_col, |
2829 subsize, output_enabled, totrate, totdist, | 2877 subsize, output_enabled, totrate, totdist, |
2830 pc_tree->split[0]); | 2878 pc_tree->split[0]); |
2831 nonrd_use_partition(cpi, tile, mi_8x8 + hbs, tp, | 2879 nonrd_use_partition(cpi, tile, mi + hbs, tp, |
2832 mi_row, mi_col + hbs, subsize, output_enabled, | 2880 mi_row, mi_col + hbs, subsize, output_enabled, |
2833 &rate, &dist, pc_tree->split[1]); | 2881 &rate, &dist, pc_tree->split[1]); |
2834 if (rate != INT_MAX && dist != INT64_MAX && | 2882 if (rate != INT_MAX && dist != INT64_MAX && |
2835 *totrate != INT_MAX && *totdist != INT64_MAX) { | 2883 *totrate != INT_MAX && *totdist != INT64_MAX) { |
2836 *totrate += rate; | 2884 *totrate += rate; |
2837 *totdist += dist; | 2885 *totdist += dist; |
2838 } | 2886 } |
2839 nonrd_use_partition(cpi, tile, mi_8x8 + hbs * mis, tp, | 2887 nonrd_use_partition(cpi, tile, mi + hbs * mis, tp, |
2840 mi_row + hbs, mi_col, subsize, output_enabled, | 2888 mi_row + hbs, mi_col, subsize, output_enabled, |
2841 &rate, &dist, pc_tree->split[2]); | 2889 &rate, &dist, pc_tree->split[2]); |
2842 if (rate != INT_MAX && dist != INT64_MAX && | 2890 if (rate != INT_MAX && dist != INT64_MAX && |
2843 *totrate != INT_MAX && *totdist != INT64_MAX) { | 2891 *totrate != INT_MAX && *totdist != INT64_MAX) { |
2844 *totrate += rate; | 2892 *totrate += rate; |
2845 *totdist += dist; | 2893 *totdist += dist; |
2846 } | 2894 } |
2847 nonrd_use_partition(cpi, tile, mi_8x8 + hbs * mis + hbs, tp, | 2895 nonrd_use_partition(cpi, tile, mi + hbs * mis + hbs, tp, |
2848 mi_row + hbs, mi_col + hbs, subsize, output_enabled, | 2896 mi_row + hbs, mi_col + hbs, subsize, output_enabled, |
2849 &rate, &dist, pc_tree->split[3]); | 2897 &rate, &dist, pc_tree->split[3]); |
2850 if (rate != INT_MAX && dist != INT64_MAX && | 2898 if (rate != INT_MAX && dist != INT64_MAX && |
2851 *totrate != INT_MAX && *totdist != INT64_MAX) { | 2899 *totrate != INT_MAX && *totdist != INT64_MAX) { |
2852 *totrate += rate; | 2900 *totrate += rate; |
2853 *totdist += dist; | 2901 *totdist += dist; |
2854 } | 2902 } |
2855 break; | 2903 break; |
2856 default: | 2904 default: |
2857 assert("Invalid partition type."); | 2905 assert("Invalid partition type."); |
(...skipping 18 matching lines...) Expand all Loading... |
2876 vpx_memset(&xd->left_context, 0, sizeof(xd->left_context)); | 2924 vpx_memset(&xd->left_context, 0, sizeof(xd->left_context)); |
2877 vpx_memset(xd->left_seg_context, 0, sizeof(xd->left_seg_context)); | 2925 vpx_memset(xd->left_seg_context, 0, sizeof(xd->left_seg_context)); |
2878 | 2926 |
2879 // Code each SB in the row | 2927 // Code each SB in the row |
2880 for (mi_col = tile->mi_col_start; mi_col < tile->mi_col_end; | 2928 for (mi_col = tile->mi_col_start; mi_col < tile->mi_col_end; |
2881 mi_col += MI_BLOCK_SIZE) { | 2929 mi_col += MI_BLOCK_SIZE) { |
2882 MACROBLOCK *x = &cpi->mb; | 2930 MACROBLOCK *x = &cpi->mb; |
2883 int dummy_rate = 0; | 2931 int dummy_rate = 0; |
2884 int64_t dummy_dist = 0; | 2932 int64_t dummy_dist = 0; |
2885 const int idx_str = cm->mi_stride * mi_row + mi_col; | 2933 const int idx_str = cm->mi_stride * mi_row + mi_col; |
2886 MODE_INFO **mi_8x8 = cm->mi_grid_visible + idx_str; | 2934 MODE_INFO **mi = cm->mi_grid_visible + idx_str; |
2887 MODE_INFO **prev_mi_8x8 = cm->prev_mi_grid_visible + idx_str; | 2935 MODE_INFO **prev_mi = cm->prev_mi_grid_visible + idx_str; |
2888 BLOCK_SIZE bsize; | 2936 BLOCK_SIZE bsize; |
2889 | 2937 |
2890 x->in_static_area = 0; | 2938 x->in_static_area = 0; |
2891 x->source_variance = UINT_MAX; | 2939 x->source_variance = UINT_MAX; |
2892 vp9_zero(x->pred_mv); | 2940 vp9_zero(x->pred_mv); |
2893 | 2941 |
2894 // Set the partition type of the 64X64 block | 2942 // Set the partition type of the 64X64 block |
2895 switch (cpi->sf.partition_search_type) { | 2943 switch (cpi->sf.partition_search_type) { |
2896 case VAR_BASED_PARTITION: | 2944 case VAR_BASED_PARTITION: |
2897 choose_partitioning(cpi, tile, mi_row, mi_col); | 2945 choose_partitioning(cpi, tile, mi_row, mi_col); |
2898 nonrd_use_partition(cpi, tile, mi_8x8, tp, mi_row, mi_col, BLOCK_64X64, | 2946 nonrd_use_partition(cpi, tile, mi, tp, mi_row, mi_col, BLOCK_64X64, |
2899 1, &dummy_rate, &dummy_dist, x->pc_root); | 2947 1, &dummy_rate, &dummy_dist, x->pc_root); |
2900 break; | 2948 break; |
2901 case SOURCE_VAR_BASED_PARTITION: | 2949 case SOURCE_VAR_BASED_PARTITION: |
2902 set_source_var_based_partition(cpi, tile, mi_8x8, mi_row, mi_col); | 2950 set_source_var_based_partition(cpi, tile, mi, mi_row, mi_col); |
2903 nonrd_use_partition(cpi, tile, mi_8x8, tp, mi_row, mi_col, BLOCK_64X64, | 2951 nonrd_use_partition(cpi, tile, mi, tp, mi_row, mi_col, BLOCK_64X64, |
2904 1, &dummy_rate, &dummy_dist, x->pc_root); | 2952 1, &dummy_rate, &dummy_dist, x->pc_root); |
2905 break; | 2953 break; |
2906 case VAR_BASED_FIXED_PARTITION: | 2954 case VAR_BASED_FIXED_PARTITION: |
2907 case FIXED_PARTITION: | 2955 case FIXED_PARTITION: |
2908 bsize = cpi->sf.partition_search_type == FIXED_PARTITION ? | 2956 bsize = cpi->sf.partition_search_type == FIXED_PARTITION ? |
2909 cpi->sf.always_this_block_size : | 2957 cpi->sf.always_this_block_size : |
2910 get_nonrd_var_based_fixed_partition(cpi, mi_row, mi_col); | 2958 get_nonrd_var_based_fixed_partition(cpi, mi_row, mi_col); |
2911 set_fixed_partitioning(cpi, tile, mi_8x8, mi_row, mi_col, bsize); | 2959 set_fixed_partitioning(cpi, tile, mi, mi_row, mi_col, bsize); |
2912 nonrd_use_partition(cpi, tile, mi_8x8, tp, mi_row, mi_col, BLOCK_64X64, | 2960 nonrd_use_partition(cpi, tile, mi, tp, mi_row, mi_col, BLOCK_64X64, |
2913 1, &dummy_rate, &dummy_dist, x->pc_root); | 2961 1, &dummy_rate, &dummy_dist, x->pc_root); |
2914 break; | 2962 break; |
2915 case REFERENCE_PARTITION: | 2963 case REFERENCE_PARTITION: |
2916 if (cpi->sf.partition_check || | 2964 if (cpi->sf.partition_check || |
2917 !is_background(cpi, tile, mi_row, mi_col)) { | 2965 !is_background(cpi, tile, mi_row, mi_col)) { |
| 2966 set_modeinfo_offsets(cm, xd, mi_row, mi_col); |
| 2967 auto_partition_range(cpi, tile, mi_row, mi_col, |
| 2968 &cpi->sf.min_partition_size, |
| 2969 &cpi->sf.max_partition_size); |
2918 nonrd_pick_partition(cpi, tile, tp, mi_row, mi_col, BLOCK_64X64, | 2970 nonrd_pick_partition(cpi, tile, tp, mi_row, mi_col, BLOCK_64X64, |
2919 &dummy_rate, &dummy_dist, 1, INT64_MAX, | 2971 &dummy_rate, &dummy_dist, 1, INT64_MAX, |
2920 x->pc_root); | 2972 x->pc_root); |
2921 } else { | 2973 } else { |
2922 copy_partitioning(cm, mi_8x8, prev_mi_8x8); | 2974 copy_partitioning(cm, mi, prev_mi); |
2923 nonrd_use_partition(cpi, tile, mi_8x8, tp, mi_row, mi_col, | 2975 nonrd_use_partition(cpi, tile, mi, tp, mi_row, mi_col, |
2924 BLOCK_64X64, 1, &dummy_rate, &dummy_dist, | 2976 BLOCK_64X64, 1, &dummy_rate, &dummy_dist, |
2925 x->pc_root); | 2977 x->pc_root); |
2926 } | 2978 } |
2927 break; | 2979 break; |
2928 default: | 2980 default: |
2929 assert(0); | 2981 assert(0); |
2930 } | 2982 } |
2931 } | 2983 } |
2932 } | 2984 } |
2933 // end RTC play code | 2985 // end RTC play code |
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3335 tx_size = (bsize >= BLOCK_8X8) ? mbmi->tx_size : TX_4X4; | 3387 tx_size = (bsize >= BLOCK_8X8) ? mbmi->tx_size : TX_4X4; |
3336 } | 3388 } |
3337 | 3389 |
3338 for (y = 0; y < mi_height; y++) | 3390 for (y = 0; y < mi_height; y++) |
3339 for (x = 0; x < mi_width; x++) | 3391 for (x = 0; x < mi_width; x++) |
3340 if (mi_col + x < cm->mi_cols && mi_row + y < cm->mi_rows) | 3392 if (mi_col + x < cm->mi_cols && mi_row + y < cm->mi_rows) |
3341 mi_8x8[mis * y + x]->mbmi.tx_size = tx_size; | 3393 mi_8x8[mis * y + x]->mbmi.tx_size = tx_size; |
3342 } | 3394 } |
3343 } | 3395 } |
3344 } | 3396 } |
OLD | NEW |