| 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 1298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1309 *rate = 0; | 1309 *rate = 0; |
| 1310 *dist = 0; | 1310 *dist = 0; |
| 1311 return; | 1311 return; |
| 1312 } | 1312 } |
| 1313 } else { | 1313 } else { |
| 1314 *(get_sb_partitioning(x, bsize)) = subsize; | 1314 *(get_sb_partitioning(x, bsize)) = subsize; |
| 1315 } | 1315 } |
| 1316 save_context(cpi, mi_row, mi_col, a, l, sa, sl, bsize); | 1316 save_context(cpi, mi_row, mi_col, a, l, sa, sl, bsize); |
| 1317 | 1317 |
| 1318 x->fast_ms = 0; | 1318 x->fast_ms = 0; |
| 1319 x->pred_mv.as_int = 0; | |
| 1320 x->subblock_ref = 0; | 1319 x->subblock_ref = 0; |
| 1321 | 1320 |
| 1322 if (cpi->sf.adjust_partitioning_from_last_frame) { | 1321 if (cpi->sf.adjust_partitioning_from_last_frame) { |
| 1323 // Check if any of the sub blocks are further split. | 1322 // Check if any of the sub blocks are further split. |
| 1324 if (partition == PARTITION_SPLIT && subsize > BLOCK_8X8) { | 1323 if (partition == PARTITION_SPLIT && subsize > BLOCK_8X8) { |
| 1325 sub_subsize = get_subsize(subsize, PARTITION_SPLIT); | 1324 sub_subsize = get_subsize(subsize, PARTITION_SPLIT); |
| 1326 splits_below = 1; | 1325 splits_below = 1; |
| 1327 for (i = 0; i < 4; i++) { | 1326 for (i = 0; i < 4; i++) { |
| 1328 int jj = i >> 1, ii = i & 0x01; | 1327 int jj = i >> 1, ii = i & 0x01; |
| 1329 MODE_INFO * this_mi = mi_8x8[jj * bss * mis + ii * bss]; | 1328 MODE_INFO * this_mi = mi_8x8[jj * bss * mis + ii * bss]; |
| (...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1703 d01 = MAX(abs(mvr0 - mvr1), abs(mvc0 - mvc1)); | 1702 d01 = MAX(abs(mvr0 - mvr1), abs(mvc0 - mvc1)); |
| 1704 d23 = MAX(abs(mvr2 - mvr3), abs(mvc2 - mvc3)); | 1703 d23 = MAX(abs(mvr2 - mvr3), abs(mvc2 - mvc3)); |
| 1705 d02 = MAX(abs(mvr0 - mvr2), abs(mvc0 - mvc2)); | 1704 d02 = MAX(abs(mvr0 - mvr2), abs(mvc0 - mvc2)); |
| 1706 d13 = MAX(abs(mvr1 - mvr3), abs(mvc1 - mvc3)); | 1705 d13 = MAX(abs(mvr1 - mvr3), abs(mvc1 - mvc3)); |
| 1707 | 1706 |
| 1708 if (d01 < FAST_MOTION_MV_THRESH && d23 < FAST_MOTION_MV_THRESH && | 1707 if (d01 < FAST_MOTION_MV_THRESH && d23 < FAST_MOTION_MV_THRESH && |
| 1709 d02 < FAST_MOTION_MV_THRESH && d13 < FAST_MOTION_MV_THRESH) { | 1708 d02 < FAST_MOTION_MV_THRESH && d13 < FAST_MOTION_MV_THRESH) { |
| 1710 // Set fast motion search level. | 1709 // Set fast motion search level. |
| 1711 x->fast_ms = 1; | 1710 x->fast_ms = 1; |
| 1712 | 1711 |
| 1713 // Calculate prediction MV. | |
| 1714 x->pred_mv.as_mv.row = (mvr0 + mvr1 + mvr2 + mvr3) >> 2; | |
| 1715 x->pred_mv.as_mv.col = (mvc0 + mvc1 + mvc2 + mvc3) >> 2; | |
| 1716 | |
| 1717 if (ref0 == ref1 && ref1 == ref2 && ref2 == ref3 && | 1712 if (ref0 == ref1 && ref1 == ref2 && ref2 == ref3 && |
| 1718 d01 < 2 && d23 < 2 && d02 < 2 && d13 < 2) { | 1713 d01 < 2 && d23 < 2 && d02 < 2 && d13 < 2) { |
| 1719 // Set fast motion search level. | 1714 // Set fast motion search level. |
| 1720 x->fast_ms = 2; | 1715 x->fast_ms = 2; |
| 1721 | 1716 |
| 1722 if (!d01 && !d23 && !d02 && !d13) { | 1717 if (!d01 && !d23 && !d02 && !d13) { |
| 1723 x->fast_ms = 3; | 1718 x->fast_ms = 3; |
| 1724 x->subblock_ref = ref0; | 1719 x->subblock_ref = ref0; |
| 1725 } | 1720 } |
| 1726 } | 1721 } |
| 1727 } | 1722 } |
| 1728 } | 1723 } |
| 1729 } | 1724 } |
| 1730 } | 1725 } |
| 1731 | 1726 |
| 1727 static INLINE void store_pred_mv(MACROBLOCK *x, PICK_MODE_CONTEXT *ctx) { |
| 1728 vpx_memcpy(ctx->pred_mv, x->pred_mv, sizeof(x->pred_mv)); |
| 1729 } |
| 1730 |
| 1731 static INLINE void load_pred_mv(MACROBLOCK *x, PICK_MODE_CONTEXT *ctx) { |
| 1732 vpx_memcpy(x->pred_mv, ctx->pred_mv, sizeof(x->pred_mv)); |
| 1733 } |
| 1734 |
| 1732 // TODO(jingning,jimbankoski,rbultje): properly skip partition types that are | 1735 // TODO(jingning,jimbankoski,rbultje): properly skip partition types that are |
| 1733 // unlikely to be selected depending on previous rate-distortion optimization | 1736 // unlikely to be selected depending on previous rate-distortion optimization |
| 1734 // results, for encoding speed-up. | 1737 // results, for encoding speed-up. |
| 1735 static void rd_pick_partition(VP9_COMP *cpi, TOKENEXTRA **tp, int mi_row, | 1738 static void rd_pick_partition(VP9_COMP *cpi, TOKENEXTRA **tp, int mi_row, |
| 1736 int mi_col, BLOCK_SIZE bsize, int *rate, | 1739 int mi_col, BLOCK_SIZE bsize, int *rate, |
| 1737 int64_t *dist, int do_recon, int64_t best_rd) { | 1740 int64_t *dist, int do_recon, int64_t best_rd) { |
| 1738 VP9_COMMON * const cm = &cpi->common; | 1741 VP9_COMMON * const cm = &cpi->common; |
| 1739 MACROBLOCK * const x = &cpi->mb; | 1742 MACROBLOCK * const x = &cpi->mb; |
| 1740 MACROBLOCKD * const xd = &x->e_mbd; | 1743 MACROBLOCKD * const xd = &x->e_mbd; |
| 1741 const int ms = num_8x8_blocks_wide_lookup[bsize] / 2; | 1744 const int ms = num_8x8_blocks_wide_lookup[bsize] / 2; |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1830 // and stop splitting. | 1833 // and stop splitting. |
| 1831 if (this_dist < stop_thresh) { | 1834 if (this_dist < stop_thresh) { |
| 1832 do_split = 0; | 1835 do_split = 0; |
| 1833 do_rect = 0; | 1836 do_rect = 0; |
| 1834 } | 1837 } |
| 1835 } | 1838 } |
| 1836 } | 1839 } |
| 1837 restore_context(cpi, mi_row, mi_col, a, l, sa, sl, bsize); | 1840 restore_context(cpi, mi_row, mi_col, a, l, sa, sl, bsize); |
| 1838 } | 1841 } |
| 1839 | 1842 |
| 1843 // store estimated motion vector |
| 1844 if (cpi->sf.adaptive_motion_search) |
| 1845 store_pred_mv(x, get_block_context(x, bsize)); |
| 1846 |
| 1840 // PARTITION_SPLIT | 1847 // PARTITION_SPLIT |
| 1841 sum_rd = 0; | 1848 sum_rd = 0; |
| 1842 // TODO(jingning): use the motion vectors given by the above search as | 1849 // TODO(jingning): use the motion vectors given by the above search as |
| 1843 // the starting point of motion search in the following partition type check. | 1850 // the starting point of motion search in the following partition type check. |
| 1844 if (do_split) { | 1851 if (do_split) { |
| 1845 subsize = get_subsize(bsize, PARTITION_SPLIT); | 1852 subsize = get_subsize(bsize, PARTITION_SPLIT); |
| 1846 for (i = 0; i < 4 && sum_rd < best_rd; ++i) { | 1853 for (i = 0; i < 4 && sum_rd < best_rd; ++i) { |
| 1847 const int x_idx = (i & 1) * ms; | 1854 const int x_idx = (i & 1) * ms; |
| 1848 const int y_idx = (i >> 1) * ms; | 1855 const int y_idx = (i >> 1) * ms; |
| 1849 | 1856 |
| 1850 if (mi_row + y_idx >= cm->mi_rows || mi_col + x_idx >= cm->mi_cols) | 1857 if (mi_row + y_idx >= cm->mi_rows || mi_col + x_idx >= cm->mi_cols) |
| 1851 continue; | 1858 continue; |
| 1852 | 1859 |
| 1853 *get_sb_index(xd, subsize) = i; | 1860 *get_sb_index(xd, subsize) = i; |
| 1854 | 1861 if (cpi->sf.adaptive_motion_search) |
| 1862 load_pred_mv(x, get_block_context(x, bsize)); |
| 1855 rd_pick_partition(cpi, tp, mi_row + y_idx, mi_col + x_idx, subsize, | 1863 rd_pick_partition(cpi, tp, mi_row + y_idx, mi_col + x_idx, subsize, |
| 1856 &this_rate, &this_dist, i != 3, best_rd - sum_rd); | 1864 &this_rate, &this_dist, i != 3, best_rd - sum_rd); |
| 1857 | 1865 |
| 1858 if (this_rate == INT_MAX) { | 1866 if (this_rate == INT_MAX) { |
| 1859 sum_rd = INT64_MAX; | 1867 sum_rd = INT64_MAX; |
| 1860 } else { | 1868 } else { |
| 1861 sum_rate += this_rate; | 1869 sum_rate += this_rate; |
| 1862 sum_dist += this_dist; | 1870 sum_dist += this_dist; |
| 1863 sum_rd = RDCOST(x->rdmult, x->rddiv, sum_rate, sum_dist); | 1871 sum_rd = RDCOST(x->rdmult, x->rddiv, sum_rate, sum_dist); |
| 1864 } | 1872 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1878 // gives better rd cost | 1886 // gives better rd cost |
| 1879 if (cpi->sf.less_rectangular_check) | 1887 if (cpi->sf.less_rectangular_check) |
| 1880 do_rect &= !partition_none_allowed; | 1888 do_rect &= !partition_none_allowed; |
| 1881 } | 1889 } |
| 1882 } | 1890 } |
| 1883 partition_split_done = 1; | 1891 partition_split_done = 1; |
| 1884 restore_context(cpi, mi_row, mi_col, a, l, sa, sl, bsize); | 1892 restore_context(cpi, mi_row, mi_col, a, l, sa, sl, bsize); |
| 1885 } | 1893 } |
| 1886 | 1894 |
| 1887 x->fast_ms = 0; | 1895 x->fast_ms = 0; |
| 1888 x->pred_mv.as_int = 0; | |
| 1889 x->subblock_ref = 0; | 1896 x->subblock_ref = 0; |
| 1890 | 1897 |
| 1891 if (partition_split_done && | 1898 if (partition_split_done && |
| 1892 cpi->sf.using_small_partition_info) { | 1899 cpi->sf.using_small_partition_info) { |
| 1893 compute_fast_motion_search_level(cpi, bsize); | 1900 compute_fast_motion_search_level(cpi, bsize); |
| 1894 } | 1901 } |
| 1895 | 1902 |
| 1896 // PARTITION_HORZ | 1903 // PARTITION_HORZ |
| 1897 if (partition_horz_allowed && do_rect) { | 1904 if (partition_horz_allowed && do_rect) { |
| 1898 subsize = get_subsize(bsize, PARTITION_HORZ); | 1905 subsize = get_subsize(bsize, PARTITION_HORZ); |
| 1899 *get_sb_index(xd, subsize) = 0; | 1906 *get_sb_index(xd, subsize) = 0; |
| 1907 if (cpi->sf.adaptive_motion_search) |
| 1908 load_pred_mv(x, get_block_context(x, bsize)); |
| 1900 pick_sb_modes(cpi, mi_row, mi_col, &sum_rate, &sum_dist, subsize, | 1909 pick_sb_modes(cpi, mi_row, mi_col, &sum_rate, &sum_dist, subsize, |
| 1901 get_block_context(x, subsize), best_rd); | 1910 get_block_context(x, subsize), best_rd); |
| 1902 sum_rd = RDCOST(x->rdmult, x->rddiv, sum_rate, sum_dist); | 1911 sum_rd = RDCOST(x->rdmult, x->rddiv, sum_rate, sum_dist); |
| 1903 | 1912 |
| 1904 if (sum_rd < best_rd && mi_row + ms < cm->mi_rows) { | 1913 if (sum_rd < best_rd && mi_row + ms < cm->mi_rows) { |
| 1905 update_state(cpi, get_block_context(x, subsize), subsize, 0); | 1914 update_state(cpi, get_block_context(x, subsize), subsize, 0); |
| 1906 encode_superblock(cpi, tp, 0, mi_row, mi_col, subsize); | 1915 encode_superblock(cpi, tp, 0, mi_row, mi_col, subsize); |
| 1907 | 1916 |
| 1908 *get_sb_index(xd, subsize) = 1; | 1917 *get_sb_index(xd, subsize) = 1; |
| 1918 if (cpi->sf.adaptive_motion_search) |
| 1919 load_pred_mv(x, get_block_context(x, bsize)); |
| 1909 pick_sb_modes(cpi, mi_row + ms, mi_col, &this_rate, | 1920 pick_sb_modes(cpi, mi_row + ms, mi_col, &this_rate, |
| 1910 &this_dist, subsize, get_block_context(x, subsize), | 1921 &this_dist, subsize, get_block_context(x, subsize), |
| 1911 best_rd - sum_rd); | 1922 best_rd - sum_rd); |
| 1912 if (this_rate == INT_MAX) { | 1923 if (this_rate == INT_MAX) { |
| 1913 sum_rd = INT64_MAX; | 1924 sum_rd = INT64_MAX; |
| 1914 } else { | 1925 } else { |
| 1915 sum_rate += this_rate; | 1926 sum_rate += this_rate; |
| 1916 sum_dist += this_dist; | 1927 sum_dist += this_dist; |
| 1917 sum_rd = RDCOST(x->rdmult, x->rddiv, sum_rate, sum_dist); | 1928 sum_rd = RDCOST(x->rdmult, x->rddiv, sum_rate, sum_dist); |
| 1918 } | 1929 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1930 } | 1941 } |
| 1931 } | 1942 } |
| 1932 restore_context(cpi, mi_row, mi_col, a, l, sa, sl, bsize); | 1943 restore_context(cpi, mi_row, mi_col, a, l, sa, sl, bsize); |
| 1933 } | 1944 } |
| 1934 | 1945 |
| 1935 // PARTITION_VERT | 1946 // PARTITION_VERT |
| 1936 if (partition_vert_allowed && do_rect) { | 1947 if (partition_vert_allowed && do_rect) { |
| 1937 subsize = get_subsize(bsize, PARTITION_VERT); | 1948 subsize = get_subsize(bsize, PARTITION_VERT); |
| 1938 | 1949 |
| 1939 *get_sb_index(xd, subsize) = 0; | 1950 *get_sb_index(xd, subsize) = 0; |
| 1951 if (cpi->sf.adaptive_motion_search) |
| 1952 load_pred_mv(x, get_block_context(x, bsize)); |
| 1940 pick_sb_modes(cpi, mi_row, mi_col, &sum_rate, &sum_dist, subsize, | 1953 pick_sb_modes(cpi, mi_row, mi_col, &sum_rate, &sum_dist, subsize, |
| 1941 get_block_context(x, subsize), best_rd); | 1954 get_block_context(x, subsize), best_rd); |
| 1942 sum_rd = RDCOST(x->rdmult, x->rddiv, sum_rate, sum_dist); | 1955 sum_rd = RDCOST(x->rdmult, x->rddiv, sum_rate, sum_dist); |
| 1943 if (sum_rd < best_rd && mi_col + ms < cm->mi_cols) { | 1956 if (sum_rd < best_rd && mi_col + ms < cm->mi_cols) { |
| 1944 update_state(cpi, get_block_context(x, subsize), subsize, 0); | 1957 update_state(cpi, get_block_context(x, subsize), subsize, 0); |
| 1945 encode_superblock(cpi, tp, 0, mi_row, mi_col, subsize); | 1958 encode_superblock(cpi, tp, 0, mi_row, mi_col, subsize); |
| 1946 | 1959 |
| 1947 *get_sb_index(xd, subsize) = 1; | 1960 *get_sb_index(xd, subsize) = 1; |
| 1961 if (cpi->sf.adaptive_motion_search) |
| 1962 load_pred_mv(x, get_block_context(x, bsize)); |
| 1948 pick_sb_modes(cpi, mi_row, mi_col + ms, &this_rate, | 1963 pick_sb_modes(cpi, mi_row, mi_col + ms, &this_rate, |
| 1949 &this_dist, subsize, get_block_context(x, subsize), | 1964 &this_dist, subsize, get_block_context(x, subsize), |
| 1950 best_rd - sum_rd); | 1965 best_rd - sum_rd); |
| 1951 if (this_rate == INT_MAX) { | 1966 if (this_rate == INT_MAX) { |
| 1952 sum_rd = INT64_MAX; | 1967 sum_rd = INT64_MAX; |
| 1953 } else { | 1968 } else { |
| 1954 sum_rate += this_rate; | 1969 sum_rate += this_rate; |
| 1955 sum_dist += this_dist; | 1970 sum_dist += this_dist; |
| 1956 sum_rd = RDCOST(x->rdmult, x->rddiv, sum_rate, sum_dist); | 1971 sum_rd = RDCOST(x->rdmult, x->rddiv, sum_rate, sum_dist); |
| 1957 } | 1972 } |
| (...skipping 815 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2773 sz = TX_4X4; | 2788 sz = TX_4X4; |
| 2774 } | 2789 } |
| 2775 | 2790 |
| 2776 for (y = 0; y < mi_height; y++) | 2791 for (y = 0; y < mi_height; y++) |
| 2777 for (x = 0; x < mi_width; x++) | 2792 for (x = 0; x < mi_width; x++) |
| 2778 if (mi_col + x < cm->mi_cols && mi_row + y < cm->mi_rows) | 2793 if (mi_col + x < cm->mi_cols && mi_row + y < cm->mi_rows) |
| 2779 mi_8x8[mis * y + x]->mbmi.tx_size = sz; | 2794 mi_8x8[mis * y + x]->mbmi.tx_size = sz; |
| 2780 } | 2795 } |
| 2781 } | 2796 } |
| 2782 } | 2797 } |
| OLD | NEW |