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

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

Issue 484923003: libvpx: Pull from upstream (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/deps/third_party/libvpx/
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved. 2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 1705 matching lines...) Expand 10 before | Expand all | Expand 10 after
1716 1716
1717 // Look at all the mode_info entries for blocks that are part of this 1717 // Look at all the mode_info entries for blocks that are part of this
1718 // partition and find the min and max values for sb_type. 1718 // partition and find the min and max values for sb_type.
1719 // At the moment this is designed to work on a 64x64 SB but could be 1719 // At the moment this is designed to work on a 64x64 SB but could be
1720 // adjusted to use a size parameter. 1720 // adjusted to use a size parameter.
1721 // 1721 //
1722 // The min and max are assumed to have been initialized prior to calling this 1722 // The min and max are assumed to have been initialized prior to calling this
1723 // function so repeat calls can accumulate a min and max of more than one sb64. 1723 // function so repeat calls can accumulate a min and max of more than one sb64.
1724 static void get_sb_partition_size_range(MACROBLOCKD *xd, MODE_INFO **mi_8x8, 1724 static void get_sb_partition_size_range(MACROBLOCKD *xd, MODE_INFO **mi_8x8,
1725 BLOCK_SIZE *min_block_size, 1725 BLOCK_SIZE *min_block_size,
1726 BLOCK_SIZE *max_block_size ) { 1726 BLOCK_SIZE *max_block_size,
1727 int bs_hist[BLOCK_SIZES]) {
1727 int sb_width_in_blocks = MI_BLOCK_SIZE; 1728 int sb_width_in_blocks = MI_BLOCK_SIZE;
1728 int sb_height_in_blocks = MI_BLOCK_SIZE; 1729 int sb_height_in_blocks = MI_BLOCK_SIZE;
1729 int i, j; 1730 int i, j;
1730 int index = 0; 1731 int index = 0;
1731 1732
1732 // Check the sb_type for each block that belongs to this region. 1733 // Check the sb_type for each block that belongs to this region.
1733 for (i = 0; i < sb_height_in_blocks; ++i) { 1734 for (i = 0; i < sb_height_in_blocks; ++i) {
1734 for (j = 0; j < sb_width_in_blocks; ++j) { 1735 for (j = 0; j < sb_width_in_blocks; ++j) {
1735 MODE_INFO * mi = mi_8x8[index+j]; 1736 MODE_INFO * mi = mi_8x8[index+j];
1736 BLOCK_SIZE sb_type = mi ? mi->mbmi.sb_type : 0; 1737 BLOCK_SIZE sb_type = mi ? mi->mbmi.sb_type : 0;
1738 bs_hist[sb_type]++;
1737 *min_block_size = MIN(*min_block_size, sb_type); 1739 *min_block_size = MIN(*min_block_size, sb_type);
1738 *max_block_size = MAX(*max_block_size, sb_type); 1740 *max_block_size = MAX(*max_block_size, sb_type);
1739 } 1741 }
1740 index += xd->mi_stride; 1742 index += xd->mi_stride;
1741 } 1743 }
1742 } 1744 }
1743 1745
1744 // Next square block size less or equal than current block size. 1746 // Next square block size less or equal than current block size.
1745 static const BLOCK_SIZE next_square_size[BLOCK_SIZES] = { 1747 static const BLOCK_SIZE next_square_size[BLOCK_SIZES] = {
1746 BLOCK_4X4, BLOCK_4X4, BLOCK_4X4, 1748 BLOCK_4X4, BLOCK_4X4, BLOCK_4X4,
(...skipping 12 matching lines...) Expand all
1759 VP9_COMMON *const cm = &cpi->common; 1761 VP9_COMMON *const cm = &cpi->common;
1760 MACROBLOCKD *const xd = &cpi->mb.e_mbd; 1762 MACROBLOCKD *const xd = &cpi->mb.e_mbd;
1761 MODE_INFO **mi = xd->mi; 1763 MODE_INFO **mi = xd->mi;
1762 const int left_in_image = xd->left_available && mi[-1]; 1764 const int left_in_image = xd->left_available && mi[-1];
1763 const int above_in_image = xd->up_available && mi[-xd->mi_stride]; 1765 const int above_in_image = xd->up_available && mi[-xd->mi_stride];
1764 const int row8x8_remaining = tile->mi_row_end - mi_row; 1766 const int row8x8_remaining = tile->mi_row_end - mi_row;
1765 const int col8x8_remaining = tile->mi_col_end - mi_col; 1767 const int col8x8_remaining = tile->mi_col_end - mi_col;
1766 int bh, bw; 1768 int bh, bw;
1767 BLOCK_SIZE min_size = BLOCK_4X4; 1769 BLOCK_SIZE min_size = BLOCK_4X4;
1768 BLOCK_SIZE max_size = BLOCK_64X64; 1770 BLOCK_SIZE max_size = BLOCK_64X64;
1771 int i = 0;
1772 int bs_hist[BLOCK_SIZES] = {0};
1773
1769 // Trap case where we do not have a prediction. 1774 // Trap case where we do not have a prediction.
1770 if (left_in_image || above_in_image || cm->frame_type != KEY_FRAME) { 1775 if (left_in_image || above_in_image || cm->frame_type != KEY_FRAME) {
1771 // Default "min to max" and "max to min" 1776 // Default "min to max" and "max to min"
1772 min_size = BLOCK_64X64; 1777 min_size = BLOCK_64X64;
1773 max_size = BLOCK_4X4; 1778 max_size = BLOCK_4X4;
1774 1779
1775 // NOTE: each call to get_sb_partition_size_range() uses the previous 1780 // NOTE: each call to get_sb_partition_size_range() uses the previous
1776 // passed in values for min and max as a starting point. 1781 // passed in values for min and max as a starting point.
1777 // Find the min and max partition used in previous frame at this location 1782 // Find the min and max partition used in previous frame at this location
1778 if (cm->frame_type != KEY_FRAME) { 1783 if (cm->frame_type != KEY_FRAME) {
1779 MODE_INFO **const prev_mi = 1784 MODE_INFO **const prev_mi =
1780 &cm->prev_mi_grid_visible[mi_row * xd->mi_stride + mi_col]; 1785 &cm->prev_mi_grid_visible[mi_row * xd->mi_stride + mi_col];
1781 get_sb_partition_size_range(xd, prev_mi, &min_size, &max_size); 1786 get_sb_partition_size_range(xd, prev_mi, &min_size, &max_size, bs_hist);
1782 } 1787 }
1783 // Find the min and max partition sizes used in the left SB64 1788 // Find the min and max partition sizes used in the left SB64
1784 if (left_in_image) { 1789 if (left_in_image) {
1785 MODE_INFO **left_sb64_mi = &mi[-MI_BLOCK_SIZE]; 1790 MODE_INFO **left_sb64_mi = &mi[-MI_BLOCK_SIZE];
1786 get_sb_partition_size_range(xd, left_sb64_mi, &min_size, &max_size); 1791 get_sb_partition_size_range(xd, left_sb64_mi, &min_size, &max_size,
1792 bs_hist);
1787 } 1793 }
1788 // Find the min and max partition sizes used in the above SB64. 1794 // Find the min and max partition sizes used in the above SB64.
1789 if (above_in_image) { 1795 if (above_in_image) {
1790 MODE_INFO **above_sb64_mi = &mi[-xd->mi_stride * MI_BLOCK_SIZE]; 1796 MODE_INFO **above_sb64_mi = &mi[-xd->mi_stride * MI_BLOCK_SIZE];
1791 get_sb_partition_size_range(xd, above_sb64_mi, &min_size, &max_size); 1797 get_sb_partition_size_range(xd, above_sb64_mi, &min_size, &max_size,
1798 bs_hist);
1792 } 1799 }
1800
1793 // adjust observed min and max 1801 // adjust observed min and max
1794 if (cpi->sf.auto_min_max_partition_size == RELAXED_NEIGHBORING_MIN_MAX) { 1802 if (cpi->sf.auto_min_max_partition_size == RELAXED_NEIGHBORING_MIN_MAX) {
1795 min_size = min_partition_size[min_size]; 1803 min_size = min_partition_size[min_size];
1796 max_size = max_partition_size[max_size]; 1804 max_size = max_partition_size[max_size];
1805 } else if (cpi->sf.auto_min_max_partition_size ==
1806 CONSTRAIN_NEIGHBORING_MIN_MAX) {
1807 // adjust the search range based on the histogram of the observed
1808 // partition sizes from left, above the previous co-located blocks
1809 int sum = 0;
1810 int first_moment = 0;
1811 int second_moment = 0;
1812 int var_unnormalized = 0;
1813
1814 for (i = 0; i < BLOCK_SIZES; i++) {
1815 sum += bs_hist[i];
1816 first_moment += bs_hist[i] * i;
1817 second_moment += bs_hist[i] * i * i;
1818 }
1819
1820 // if variance is small enough,
1821 // adjust the range around its mean size, which gives a tighter range
1822 var_unnormalized = second_moment - first_moment * first_moment / sum;
1823 if (var_unnormalized <= 4 * sum) {
1824 int mean = first_moment / sum;
1825 min_size = min_partition_size[mean];
1826 max_size = max_partition_size[mean];
1827 } else {
1828 min_size = min_partition_size[min_size];
1829 max_size = max_partition_size[max_size];
1830 }
1797 } 1831 }
1798 } 1832 }
1799 1833
1800 // Check border cases where max and min from neighbors may not be legal. 1834 // Check border cases where max and min from neighbors may not be legal.
1801 max_size = find_partition_size(max_size, 1835 max_size = find_partition_size(max_size,
1802 row8x8_remaining, col8x8_remaining, 1836 row8x8_remaining, col8x8_remaining,
1803 &bh, &bw); 1837 &bh, &bw);
1804 min_size = MIN(min_size, max_size); 1838 min_size = MIN(min_size, max_size);
1805 1839
1806 // When use_square_partition_only is true, make sure at least one square 1840 // When use_square_partition_only is true, make sure at least one square
1807 // partition is allowed by selecting the next smaller square size as 1841 // partition is allowed by selecting the next smaller square size as
1808 // *min_block_size. 1842 // *min_block_size.
1809 if (cpi->sf.use_square_partition_only && 1843 if (cpi->sf.use_square_partition_only &&
1810 next_square_size[max_size] < min_size) { 1844 next_square_size[max_size] < min_size) {
1811 min_size = next_square_size[max_size]; 1845 min_size = next_square_size[max_size];
1812 } 1846 }
1847
1813 *min_block_size = min_size; 1848 *min_block_size = min_size;
1814 *max_block_size = max_size; 1849 *max_block_size = max_size;
1815 } 1850 }
1816 1851
1817 static void auto_partition_range(VP9_COMP *cpi, const TileInfo *const tile, 1852 static void auto_partition_range(VP9_COMP *cpi, const TileInfo *const tile,
1818 int mi_row, int mi_col, 1853 int mi_row, int mi_col,
1819 BLOCK_SIZE *min_block_size, 1854 BLOCK_SIZE *min_block_size,
1820 BLOCK_SIZE *max_block_size) { 1855 BLOCK_SIZE *max_block_size) {
1821 VP9_COMMON *const cm = &cpi->common; 1856 VP9_COMMON *const cm = &cpi->common;
1822 MACROBLOCKD *const xd = &cpi->mb.e_mbd; 1857 MACROBLOCKD *const xd = &cpi->mb.e_mbd;
(...skipping 1791 matching lines...) Expand 10 before | Expand all | Expand 10 after
3614 tx_size = (bsize >= BLOCK_8X8) ? mbmi->tx_size : TX_4X4; 3649 tx_size = (bsize >= BLOCK_8X8) ? mbmi->tx_size : TX_4X4;
3615 } 3650 }
3616 3651
3617 for (y = 0; y < mi_height; y++) 3652 for (y = 0; y < mi_height; y++)
3618 for (x = 0; x < mi_width; x++) 3653 for (x = 0; x < mi_width; x++)
3619 if (mi_col + x < cm->mi_cols && mi_row + y < cm->mi_rows) 3654 if (mi_col + x < cm->mi_cols && mi_row + y < cm->mi_rows)
3620 mi_8x8[mis * y + x]->mbmi.tx_size = tx_size; 3655 mi_8x8[mis * y + x]->mbmi.tx_size = tx_size;
3621 } 3656 }
3622 } 3657 }
3623 } 3658 }
OLDNEW
« no previous file with comments | « source/libvpx/vp9/encoder/arm/neon/vp9_quantize_neon.c ('k') | source/libvpx/vp9/encoder/vp9_encoder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698