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 |
11 #include <assert.h> | 11 #include <assert.h> |
12 #include <stdlib.h> // qsort() | 12 #include <stdlib.h> // qsort() |
13 | 13 |
14 #include "./vp9_rtcd.h" | 14 #include "./vp9_rtcd.h" |
15 #include "./vpx_scale_rtcd.h" | 15 #include "./vpx_scale_rtcd.h" |
16 | 16 |
17 #include "vpx_mem/vpx_mem.h" | 17 #include "vpx_mem/vpx_mem.h" |
| 18 #include "vpx_ports/mem.h" |
18 #include "vpx_ports/mem_ops.h" | 19 #include "vpx_ports/mem_ops.h" |
19 #include "vpx_scale/vpx_scale.h" | 20 #include "vpx_scale/vpx_scale.h" |
20 | 21 |
21 #include "vp9/common/vp9_alloccommon.h" | 22 #include "vp9/common/vp9_alloccommon.h" |
22 #include "vp9/common/vp9_common.h" | 23 #include "vp9/common/vp9_common.h" |
23 #include "vp9/common/vp9_entropy.h" | 24 #include "vp9/common/vp9_entropy.h" |
24 #include "vp9/common/vp9_entropymode.h" | 25 #include "vp9/common/vp9_entropymode.h" |
25 #include "vp9/common/vp9_idct.h" | 26 #include "vp9/common/vp9_idct.h" |
26 #include "vp9/common/vp9_thread_common.h" | 27 #include "vp9/common/vp9_thread_common.h" |
27 #include "vp9/common/vp9_pred_common.h" | 28 #include "vp9/common/vp9_pred_common.h" |
(...skipping 663 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
691 cm->cur_frame->mi_rows = cm->mi_rows; | 692 cm->cur_frame->mi_rows = cm->mi_rows; |
692 cm->cur_frame->mi_cols = cm->mi_cols; | 693 cm->cur_frame->mi_cols = cm->mi_cols; |
693 cm->cur_frame->mvs = (MV_REF *)vpx_calloc(cm->mi_rows * cm->mi_cols, | 694 cm->cur_frame->mvs = (MV_REF *)vpx_calloc(cm->mi_rows * cm->mi_cols, |
694 sizeof(*cm->cur_frame->mvs)); | 695 sizeof(*cm->cur_frame->mvs)); |
695 } | 696 } |
696 | 697 |
697 static void resize_context_buffers(VP9_COMMON *cm, int width, int height) { | 698 static void resize_context_buffers(VP9_COMMON *cm, int width, int height) { |
698 #if CONFIG_SIZE_LIMIT | 699 #if CONFIG_SIZE_LIMIT |
699 if (width > DECODE_WIDTH_LIMIT || height > DECODE_HEIGHT_LIMIT) | 700 if (width > DECODE_WIDTH_LIMIT || height > DECODE_HEIGHT_LIMIT) |
700 vpx_internal_error(&cm->error, VPX_CODEC_CORRUPT_FRAME, | 701 vpx_internal_error(&cm->error, VPX_CODEC_CORRUPT_FRAME, |
701 "Width and height beyond allowed size."); | 702 "Dimensions of %dx%d beyond allowed size of %dx%d.", |
| 703 width, height, DECODE_WIDTH_LIMIT, DECODE_HEIGHT_LIMIT); |
702 #endif | 704 #endif |
703 if (cm->width != width || cm->height != height) { | 705 if (cm->width != width || cm->height != height) { |
704 const int new_mi_rows = | 706 const int new_mi_rows = |
705 ALIGN_POWER_OF_TWO(height, MI_SIZE_LOG2) >> MI_SIZE_LOG2; | 707 ALIGN_POWER_OF_TWO(height, MI_SIZE_LOG2) >> MI_SIZE_LOG2; |
706 const int new_mi_cols = | 708 const int new_mi_cols = |
707 ALIGN_POWER_OF_TWO(width, MI_SIZE_LOG2) >> MI_SIZE_LOG2; | 709 ALIGN_POWER_OF_TWO(width, MI_SIZE_LOG2) >> MI_SIZE_LOG2; |
708 | 710 |
709 // Allocations in vp9_alloc_context_buffers() depend on individual | 711 // Allocations in vp9_alloc_context_buffers() depend on individual |
710 // dimensions as well as the overall size. | 712 // dimensions as well as the overall size. |
711 if (new_mi_cols > cm->mi_cols || new_mi_rows > cm->mi_rows) { | 713 if (new_mi_cols > cm->mi_cols || new_mi_rows > cm->mi_rows) { |
(...skipping 592 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1304 } else { | 1306 } else { |
1305 vpx_internal_error(&cm->error, VPX_CODEC_UNSUP_BITSTREAM, | 1307 vpx_internal_error(&cm->error, VPX_CODEC_UNSUP_BITSTREAM, |
1306 "4:4:4 color not supported in profile 0 or 2"); | 1308 "4:4:4 color not supported in profile 0 or 2"); |
1307 } | 1309 } |
1308 } | 1310 } |
1309 } | 1311 } |
1310 | 1312 |
1311 static size_t read_uncompressed_header(VP9Decoder *pbi, | 1313 static size_t read_uncompressed_header(VP9Decoder *pbi, |
1312 struct vp9_read_bit_buffer *rb) { | 1314 struct vp9_read_bit_buffer *rb) { |
1313 VP9_COMMON *const cm = &pbi->common; | 1315 VP9_COMMON *const cm = &pbi->common; |
1314 RefCntBuffer *const frame_bufs = cm->buffer_pool->frame_bufs; | 1316 BufferPool *const pool = cm->buffer_pool; |
1315 BufferPool *const pool = pbi->common.buffer_pool; | 1317 RefCntBuffer *const frame_bufs = pool->frame_bufs; |
1316 int i, mask, ref_index = 0; | 1318 int i, mask, ref_index = 0; |
1317 size_t sz; | 1319 size_t sz; |
1318 | 1320 |
1319 cm->last_frame_type = cm->frame_type; | 1321 cm->last_frame_type = cm->frame_type; |
1320 | 1322 |
1321 if (vp9_rb_read_literal(rb, 2) != VP9_FRAME_MARKER) | 1323 if (vp9_rb_read_literal(rb, 2) != VP9_FRAME_MARKER) |
1322 vpx_internal_error(&cm->error, VPX_CODEC_UNSUP_BITSTREAM, | 1324 vpx_internal_error(&cm->error, VPX_CODEC_UNSUP_BITSTREAM, |
1323 "Invalid frame marker"); | 1325 "Invalid frame marker"); |
1324 | 1326 |
1325 cm->profile = vp9_read_profile(rb); | 1327 cm->profile = vp9_read_profile(rb); |
(...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1805 | 1807 |
1806 dst += dst_stride; | 1808 dst += dst_stride; |
1807 ++y; | 1809 ++y; |
1808 | 1810 |
1809 if (y > 0 && y < h) | 1811 if (y > 0 && y < h) |
1810 ref_row += src_stride; | 1812 ref_row += src_stride; |
1811 } while (--b_h); | 1813 } while (--b_h); |
1812 } | 1814 } |
1813 #endif // CONFIG_VP9_HIGHBITDEPTH | 1815 #endif // CONFIG_VP9_HIGHBITDEPTH |
1814 | 1816 |
1815 void dec_build_inter_predictors(VP9Decoder *const pbi, MACROBLOCKD *xd, | 1817 #if CONFIG_VP9_HIGHBITDEPTH |
1816 int plane, int bw, int bh, int x, | 1818 static void extend_and_predict(const uint8_t *buf_ptr1, int pre_buf_stride, |
1817 int y, int w, int h, int mi_x, int mi_y, | 1819 int x0, int y0, int b_w, int b_h, |
1818 const InterpKernel *kernel, | 1820 int frame_width, int frame_height, |
1819 const struct scale_factors *sf, | 1821 int border_offset, |
1820 struct buf_2d *pre_buf, struct buf_2d *dst_buf, | 1822 uint8_t *const dst, int dst_buf_stride, |
1821 const MV* mv, RefCntBuffer *ref_frame_buf, | 1823 int subpel_x, int subpel_y, |
1822 int is_scaled, int ref) { | 1824 const InterpKernel *kernel, |
| 1825 const struct scale_factors *sf, |
| 1826 MACROBLOCKD *xd, |
| 1827 int w, int h, int ref, int xs, int ys) { |
| 1828 DECLARE_ALIGNED(16, uint16_t, mc_buf_high[80 * 2 * 80 * 2]); |
| 1829 const uint8_t *buf_ptr; |
| 1830 |
| 1831 if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) { |
| 1832 high_build_mc_border(buf_ptr1, pre_buf_stride, mc_buf_high, b_w, |
| 1833 x0, y0, b_w, b_h, frame_width, frame_height); |
| 1834 buf_ptr = CONVERT_TO_BYTEPTR(mc_buf_high) + border_offset; |
| 1835 } else { |
| 1836 build_mc_border(buf_ptr1, pre_buf_stride, (uint8_t *)mc_buf_high, b_w, |
| 1837 x0, y0, b_w, b_h, frame_width, frame_height); |
| 1838 buf_ptr = ((uint8_t *)mc_buf_high) + border_offset; |
| 1839 } |
| 1840 |
| 1841 if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) { |
| 1842 high_inter_predictor(buf_ptr, b_w, dst, dst_buf_stride, subpel_x, |
| 1843 subpel_y, sf, w, h, ref, kernel, xs, ys, xd->bd); |
| 1844 } else { |
| 1845 inter_predictor(buf_ptr, b_w, dst, dst_buf_stride, subpel_x, |
| 1846 subpel_y, sf, w, h, ref, kernel, xs, ys); |
| 1847 } |
| 1848 } |
| 1849 #else |
| 1850 static void extend_and_predict(const uint8_t *buf_ptr1, int pre_buf_stride, |
| 1851 int x0, int y0, int b_w, int b_h, |
| 1852 int frame_width, int frame_height, |
| 1853 int border_offset, |
| 1854 uint8_t *const dst, int dst_buf_stride, |
| 1855 int subpel_x, int subpel_y, |
| 1856 const InterpKernel *kernel, |
| 1857 const struct scale_factors *sf, |
| 1858 int w, int h, int ref, int xs, int ys) { |
| 1859 DECLARE_ALIGNED(16, uint8_t, mc_buf[80 * 2 * 80 * 2]); |
| 1860 const uint8_t *buf_ptr; |
| 1861 |
| 1862 build_mc_border(buf_ptr1, pre_buf_stride, mc_buf, b_w, |
| 1863 x0, y0, b_w, b_h, frame_width, frame_height); |
| 1864 buf_ptr = mc_buf + border_offset; |
| 1865 |
| 1866 inter_predictor(buf_ptr, b_w, dst, dst_buf_stride, subpel_x, |
| 1867 subpel_y, sf, w, h, ref, kernel, xs, ys); |
| 1868 } |
| 1869 #endif // CONFIG_VP9_HIGHBITDEPTH |
| 1870 |
| 1871 static void dec_build_inter_predictors(VP9Decoder *const pbi, MACROBLOCKD *xd, |
| 1872 int plane, int bw, int bh, int x, |
| 1873 int y, int w, int h, int mi_x, int mi_y, |
| 1874 const InterpKernel *kernel, |
| 1875 const struct scale_factors *sf, |
| 1876 struct buf_2d *pre_buf, |
| 1877 struct buf_2d *dst_buf, const MV* mv, |
| 1878 RefCntBuffer *ref_frame_buf, |
| 1879 int is_scaled, int ref) { |
1823 struct macroblockd_plane *const pd = &xd->plane[plane]; | 1880 struct macroblockd_plane *const pd = &xd->plane[plane]; |
1824 uint8_t *const dst = dst_buf->buf + dst_buf->stride * y + x; | 1881 uint8_t *const dst = dst_buf->buf + dst_buf->stride * y + x; |
1825 MV32 scaled_mv; | 1882 MV32 scaled_mv; |
1826 int xs, ys, x0, y0, x0_16, y0_16, frame_width, frame_height, | 1883 int xs, ys, x0, y0, x0_16, y0_16, frame_width, frame_height, |
1827 buf_stride, subpel_x, subpel_y; | 1884 buf_stride, subpel_x, subpel_y; |
1828 uint8_t *ref_frame, *buf_ptr; | 1885 uint8_t *ref_frame, *buf_ptr; |
1829 | 1886 |
1830 // Get reference frame pointer, width and height. | 1887 // Get reference frame pointer, width and height. |
1831 if (plane == 0) { | 1888 if (plane == 0) { |
1832 frame_width = ref_frame_buf->buf.y_crop_width; | 1889 frame_width = ref_frame_buf->buf.y_crop_width; |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1916 | 1973 |
1917 // Wait until reference block is ready. Pad 7 more pixels as last 7 | 1974 // Wait until reference block is ready. Pad 7 more pixels as last 7 |
1918 // pixels of each superblock row can be changed by next superblock row. | 1975 // pixels of each superblock row can be changed by next superblock row. |
1919 if (pbi->frame_parallel_decode) | 1976 if (pbi->frame_parallel_decode) |
1920 vp9_frameworker_wait(pbi->frame_worker_owner, ref_frame_buf, | 1977 vp9_frameworker_wait(pbi->frame_worker_owner, ref_frame_buf, |
1921 MAX(0, (y1 + 7)) << (plane == 0 ? 0 : 1)); | 1978 MAX(0, (y1 + 7)) << (plane == 0 ? 0 : 1)); |
1922 | 1979 |
1923 // Skip border extension if block is inside the frame. | 1980 // Skip border extension if block is inside the frame. |
1924 if (x0 < 0 || x0 > frame_width - 1 || x1 < 0 || x1 > frame_width - 1 || | 1981 if (x0 < 0 || x0 > frame_width - 1 || x1 < 0 || x1 > frame_width - 1 || |
1925 y0 < 0 || y0 > frame_height - 1 || y1 < 0 || y1 > frame_height - 1) { | 1982 y0 < 0 || y0 > frame_height - 1 || y1 < 0 || y1 > frame_height - 1) { |
1926 uint8_t *buf_ptr1 = ref_frame + y0 * pre_buf->stride + x0; | |
1927 // Extend the border. | 1983 // Extend the border. |
| 1984 const uint8_t *const buf_ptr1 = ref_frame + y0 * buf_stride + x0; |
| 1985 const int b_w = x1 - x0 + 1; |
| 1986 const int b_h = y1 - y0 + 1; |
| 1987 const int border_offset = y_pad * 3 * b_w + x_pad * 3; |
| 1988 |
| 1989 extend_and_predict(buf_ptr1, buf_stride, x0, y0, b_w, b_h, |
| 1990 frame_width, frame_height, border_offset, |
| 1991 dst, dst_buf->stride, |
| 1992 subpel_x, subpel_y, |
| 1993 kernel, sf, |
1928 #if CONFIG_VP9_HIGHBITDEPTH | 1994 #if CONFIG_VP9_HIGHBITDEPTH |
1929 if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) { | 1995 xd, |
1930 high_build_mc_border(buf_ptr1, | 1996 #endif |
1931 pre_buf->stride, | 1997 w, h, ref, xs, ys); |
1932 xd->mc_buf_high, | 1998 return; |
1933 x1 - x0 + 1, | |
1934 x0, | |
1935 y0, | |
1936 x1 - x0 + 1, | |
1937 y1 - y0 + 1, | |
1938 frame_width, | |
1939 frame_height); | |
1940 buf_stride = x1 - x0 + 1; | |
1941 buf_ptr = CONVERT_TO_BYTEPTR(xd->mc_buf_high) + | |
1942 y_pad * 3 * buf_stride + x_pad * 3; | |
1943 } else { | |
1944 build_mc_border(buf_ptr1, | |
1945 pre_buf->stride, | |
1946 xd->mc_buf, | |
1947 x1 - x0 + 1, | |
1948 x0, | |
1949 y0, | |
1950 x1 - x0 + 1, | |
1951 y1 - y0 + 1, | |
1952 frame_width, | |
1953 frame_height); | |
1954 buf_stride = x1 - x0 + 1; | |
1955 buf_ptr = xd->mc_buf + y_pad * 3 * buf_stride + x_pad * 3; | |
1956 } | |
1957 #else | |
1958 build_mc_border(buf_ptr1, | |
1959 pre_buf->stride, | |
1960 xd->mc_buf, | |
1961 x1 - x0 + 1, | |
1962 x0, | |
1963 y0, | |
1964 x1 - x0 + 1, | |
1965 y1 - y0 + 1, | |
1966 frame_width, | |
1967 frame_height); | |
1968 buf_stride = x1 - x0 + 1; | |
1969 buf_ptr = xd->mc_buf + y_pad * 3 * buf_stride + x_pad * 3; | |
1970 #endif // CONFIG_VP9_HIGHBITDEPTH | |
1971 } | 1999 } |
1972 } else { | 2000 } else { |
1973 // Wait until reference block is ready. Pad 7 more pixels as last 7 | 2001 // Wait until reference block is ready. Pad 7 more pixels as last 7 |
1974 // pixels of each superblock row can be changed by next superblock row. | 2002 // pixels of each superblock row can be changed by next superblock row. |
1975 if (pbi->frame_parallel_decode) { | 2003 if (pbi->frame_parallel_decode) { |
1976 const int y1 = ((y0_16 + (h - 1) * ys) >> SUBPEL_BITS) + 1; | 2004 const int y1 = (y0_16 + (h - 1) * ys) >> SUBPEL_BITS; |
1977 vp9_frameworker_wait(pbi->frame_worker_owner, ref_frame_buf, | 2005 vp9_frameworker_wait(pbi->frame_worker_owner, ref_frame_buf, |
1978 MAX(0, (y1 + 7)) << (plane == 0 ? 0 : 1)); | 2006 MAX(0, (y1 + 7)) << (plane == 0 ? 0 : 1)); |
1979 } | 2007 } |
1980 } | 2008 } |
1981 #if CONFIG_VP9_HIGHBITDEPTH | 2009 #if CONFIG_VP9_HIGHBITDEPTH |
1982 if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) { | 2010 if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) { |
1983 high_inter_predictor(buf_ptr, buf_stride, dst, dst_buf->stride, subpel_x, | 2011 high_inter_predictor(buf_ptr, buf_stride, dst, dst_buf->stride, subpel_x, |
1984 subpel_y, sf, w, h, ref, kernel, xs, ys, xd->bd); | 2012 subpel_y, sf, w, h, ref, kernel, xs, ys, xd->bd); |
1985 } else { | 2013 } else { |
1986 inter_predictor(buf_ptr, buf_stride, dst, dst_buf->stride, subpel_x, | 2014 inter_predictor(buf_ptr, buf_stride, dst, dst_buf->stride, subpel_x, |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2038 } else { | 2066 } else { |
2039 const MV mv = mi->mbmi.mv[ref].as_mv; | 2067 const MV mv = mi->mbmi.mv[ref].as_mv; |
2040 dec_build_inter_predictors(pbi, xd, plane, bw, bh, | 2068 dec_build_inter_predictors(pbi, xd, plane, bw, bh, |
2041 0, 0, bw, bh, mi_x, mi_y, kernel, | 2069 0, 0, bw, bh, mi_x, mi_y, kernel, |
2042 sf, pre_buf, dst_buf, &mv, ref_frame_buf, | 2070 sf, pre_buf, dst_buf, &mv, ref_frame_buf, |
2043 is_scaled, ref); | 2071 is_scaled, ref); |
2044 } | 2072 } |
2045 } | 2073 } |
2046 } | 2074 } |
2047 } | 2075 } |
OLD | NEW |