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 #ifndef VP9_COMMON_VP9_ONYXC_INT_H_ | 11 #ifndef VP9_COMMON_VP9_ONYXC_INT_H_ |
12 #define VP9_COMMON_VP9_ONYXC_INT_H_ | 12 #define VP9_COMMON_VP9_ONYXC_INT_H_ |
13 | 13 |
14 #include "./vpx_config.h" | 14 #include "./vpx_config.h" |
15 #include "vpx/internal/vpx_codec_internal.h" | 15 #include "vpx/internal/vpx_codec_internal.h" |
16 #include "./vp9_rtcd.h" | 16 #include "./vp9_rtcd.h" |
17 #include "vp9/common/vp9_loopfilter.h" | 17 #include "vp9/common/vp9_loopfilter.h" |
18 #include "vp9/common/vp9_entropymv.h" | 18 #include "vp9/common/vp9_entropymv.h" |
19 #include "vp9/common/vp9_entropy.h" | 19 #include "vp9/common/vp9_entropy.h" |
20 #include "vp9/common/vp9_entropymode.h" | 20 #include "vp9/common/vp9_entropymode.h" |
21 #include "vp9/common/vp9_frame_buffers.h" | 21 #include "vp9/common/vp9_frame_buffers.h" |
22 #include "vp9/common/vp9_quant_common.h" | 22 #include "vp9/common/vp9_quant_common.h" |
| 23 #include "vp9/common/vp9_thread.h" |
23 #include "vp9/common/vp9_tile_common.h" | 24 #include "vp9/common/vp9_tile_common.h" |
24 | 25 |
25 #if CONFIG_VP9_POSTPROC | 26 #if CONFIG_VP9_POSTPROC |
26 #include "vp9/common/vp9_postproc.h" | 27 #include "vp9/common/vp9_postproc.h" |
27 #endif | 28 #endif |
28 | 29 |
29 #ifdef __cplusplus | 30 #ifdef __cplusplus |
30 extern "C" { | 31 extern "C" { |
31 #endif | 32 #endif |
32 | 33 |
33 #define REFS_PER_FRAME 3 | 34 #define REFS_PER_FRAME 3 |
34 | 35 |
35 #define REF_FRAMES_LOG2 3 | 36 #define REF_FRAMES_LOG2 3 |
36 #define REF_FRAMES (1 << REF_FRAMES_LOG2) | 37 #define REF_FRAMES (1 << REF_FRAMES_LOG2) |
37 | 38 |
38 // 1 scratch frame for the new frame, 3 for scaled references on the encoder | 39 // 4 scratch frames for the new frames to support a maximum of 4 cores decoding |
| 40 // in parallel, 3 for scaled references on the encoder. |
| 41 // TODO(hkuang): Add ondemand frame buffers instead of hardcoding the number |
| 42 // of framebuffers. |
39 // TODO(jkoleszar): These 3 extra references could probably come from the | 43 // TODO(jkoleszar): These 3 extra references could probably come from the |
40 // normal reference pool. | 44 // normal reference pool. |
41 #define FRAME_BUFFERS (REF_FRAMES + 4) | 45 #define FRAME_BUFFERS (REF_FRAMES + 7) |
42 | 46 |
43 #define FRAME_CONTEXTS_LOG2 2 | 47 #define FRAME_CONTEXTS_LOG2 2 |
44 #define FRAME_CONTEXTS (1 << FRAME_CONTEXTS_LOG2) | 48 #define FRAME_CONTEXTS (1 << FRAME_CONTEXTS_LOG2) |
45 | 49 |
| 50 #define NUM_PING_PONG_BUFFERS 2 |
| 51 |
46 extern const struct { | 52 extern const struct { |
47 PARTITION_CONTEXT above; | 53 PARTITION_CONTEXT above; |
48 PARTITION_CONTEXT left; | 54 PARTITION_CONTEXT left; |
49 } partition_context_lookup[BLOCK_SIZES]; | 55 } partition_context_lookup[BLOCK_SIZES]; |
50 | 56 |
51 | 57 |
52 typedef enum { | 58 typedef enum { |
53 SINGLE_REFERENCE = 0, | 59 SINGLE_REFERENCE = 0, |
54 COMPOUND_REFERENCE = 1, | 60 COMPOUND_REFERENCE = 1, |
55 REFERENCE_MODE_SELECT = 2, | 61 REFERENCE_MODE_SELECT = 2, |
56 REFERENCE_MODES = 3, | 62 REFERENCE_MODES = 3, |
57 } REFERENCE_MODE; | 63 } REFERENCE_MODE; |
58 | 64 |
59 typedef struct { | 65 typedef struct { |
60 int_mv mv[2]; | 66 int_mv mv[2]; |
61 MV_REFERENCE_FRAME ref_frame[2]; | 67 MV_REFERENCE_FRAME ref_frame[2]; |
62 } MV_REF; | 68 } MV_REF; |
63 | 69 |
64 typedef struct { | 70 typedef struct { |
65 int ref_count; | 71 int ref_count; |
66 MV_REF *mvs; | 72 MV_REF *mvs; |
67 int mi_rows; | 73 int mi_rows; |
68 int mi_cols; | 74 int mi_cols; |
69 vpx_codec_frame_buffer_t raw_frame_buffer; | 75 vpx_codec_frame_buffer_t raw_frame_buffer; |
70 YV12_BUFFER_CONFIG buf; | 76 YV12_BUFFER_CONFIG buf; |
| 77 |
| 78 // The Following variables will only be used in frame parallel decode. |
| 79 |
| 80 // frame_worker_owner indicates which FrameWorker owns this buffer. NULL means |
| 81 // that no FrameWorker owns, or is decoding, this buffer. |
| 82 VP9Worker *frame_worker_owner; |
| 83 |
| 84 // row and col indicate which position frame has been decoded to in real |
| 85 // pixel unit. They are reset to -1 when decoding begins and set to INT_MAX |
| 86 // when the frame is fully decoded. |
| 87 int row; |
| 88 int col; |
71 } RefCntBuffer; | 89 } RefCntBuffer; |
72 | 90 |
| 91 typedef struct { |
| 92 // Protect BufferPool from being accessed by several FrameWorkers at |
| 93 // the same time during frame parallel decode. |
| 94 // TODO(hkuang): Try to use atomic variable instead of locking the whole pool. |
| 95 #if CONFIG_MULTITHREAD |
| 96 pthread_mutex_t pool_mutex; |
| 97 #endif |
| 98 |
| 99 // Private data associated with the frame buffer callbacks. |
| 100 void *cb_priv; |
| 101 |
| 102 vpx_get_frame_buffer_cb_fn_t get_fb_cb; |
| 103 vpx_release_frame_buffer_cb_fn_t release_fb_cb; |
| 104 |
| 105 RefCntBuffer frame_bufs[FRAME_BUFFERS]; |
| 106 |
| 107 // Frame buffers allocated internally by the codec. |
| 108 InternalFrameBufferList int_frame_buffers; |
| 109 } BufferPool; |
| 110 |
73 typedef struct VP9Common { | 111 typedef struct VP9Common { |
74 struct vpx_internal_error_info error; | 112 struct vpx_internal_error_info error; |
75 | |
76 DECLARE_ALIGNED(16, int16_t, y_dequant[QINDEX_RANGE][8]); | |
77 DECLARE_ALIGNED(16, int16_t, uv_dequant[QINDEX_RANGE][8]); | |
78 | |
79 vpx_color_space_t color_space; | 113 vpx_color_space_t color_space; |
80 | |
81 int width; | 114 int width; |
82 int height; | 115 int height; |
83 int display_width; | 116 int display_width; |
84 int display_height; | 117 int display_height; |
85 int last_width; | 118 int last_width; |
86 int last_height; | 119 int last_height; |
87 | 120 |
88 // TODO(jkoleszar): this implies chroma ss right now, but could vary per | 121 // TODO(jkoleszar): this implies chroma ss right now, but could vary per |
89 // plane. Revisit as part of the future change to YV12_BUFFER_CONFIG to | 122 // plane. Revisit as part of the future change to YV12_BUFFER_CONFIG to |
90 // support additional planes. | 123 // support additional planes. |
91 int subsampling_x; | 124 int subsampling_x; |
92 int subsampling_y; | 125 int subsampling_y; |
93 | 126 |
94 #if CONFIG_VP9_HIGHBITDEPTH | 127 #if CONFIG_VP9_HIGHBITDEPTH |
95 int use_highbitdepth; // Marks if we need to use 16bit frame buffers. | 128 int use_highbitdepth; // Marks if we need to use 16bit frame buffers. |
96 #endif | 129 #endif |
97 | 130 |
98 YV12_BUFFER_CONFIG *frame_to_show; | 131 YV12_BUFFER_CONFIG *frame_to_show; |
99 RefCntBuffer frame_bufs[FRAME_BUFFERS]; | |
100 RefCntBuffer *prev_frame; | 132 RefCntBuffer *prev_frame; |
101 | 133 |
102 // TODO(hkuang): Combine this with cur_buf in macroblockd. | 134 // TODO(hkuang): Combine this with cur_buf in macroblockd. |
103 RefCntBuffer *cur_frame; | 135 RefCntBuffer *cur_frame; |
104 | 136 |
105 int ref_frame_map[REF_FRAMES]; /* maps fb_idx to reference slot */ | 137 int ref_frame_map[REF_FRAMES]; /* maps fb_idx to reference slot */ |
106 | 138 |
| 139 // Prepare ref_frame_map for the next frame. |
| 140 // Only used in frame parallel decode. |
| 141 int next_ref_frame_map[REF_FRAMES]; |
| 142 |
107 // TODO(jkoleszar): could expand active_ref_idx to 4, with 0 as intra, and | 143 // TODO(jkoleszar): could expand active_ref_idx to 4, with 0 as intra, and |
108 // roll new_fb_idx into it. | 144 // roll new_fb_idx into it. |
109 | 145 |
110 // Each frame can reference REFS_PER_FRAME buffers | 146 // Each frame can reference REFS_PER_FRAME buffers |
111 RefBuffer frame_refs[REFS_PER_FRAME]; | 147 RefBuffer frame_refs[REFS_PER_FRAME]; |
112 | 148 |
113 int new_fb_idx; | 149 int new_fb_idx; |
114 | 150 |
115 #if CONFIG_VP9_POSTPROC | 151 #if CONFIG_VP9_POSTPROC |
116 YV12_BUFFER_CONFIG post_proc_buffer; | 152 YV12_BUFFER_CONFIG post_proc_buffer; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 // Separate mi functions between encoder and decoder. | 199 // Separate mi functions between encoder and decoder. |
164 int (*alloc_mi)(struct VP9Common *cm, int mi_size); | 200 int (*alloc_mi)(struct VP9Common *cm, int mi_size); |
165 void (*free_mi)(struct VP9Common *cm); | 201 void (*free_mi)(struct VP9Common *cm); |
166 void (*setup_mi)(struct VP9Common *cm); | 202 void (*setup_mi)(struct VP9Common *cm); |
167 | 203 |
168 | 204 |
169 // Whether to use previous frame's motion vectors for prediction. | 205 // Whether to use previous frame's motion vectors for prediction. |
170 int use_prev_frame_mvs; | 206 int use_prev_frame_mvs; |
171 | 207 |
172 // Persistent mb segment id map used in prediction. | 208 // Persistent mb segment id map used in prediction. |
173 unsigned char *last_frame_seg_map; | 209 int seg_map_idx; |
| 210 int prev_seg_map_idx; |
| 211 |
| 212 uint8_t *seg_map_array[NUM_PING_PONG_BUFFERS]; |
| 213 uint8_t *last_frame_seg_map; |
| 214 uint8_t *current_frame_seg_map; |
174 | 215 |
175 INTERP_FILTER interp_filter; | 216 INTERP_FILTER interp_filter; |
176 | 217 |
177 loop_filter_info_n lf_info; | 218 loop_filter_info_n lf_info; |
178 | 219 |
179 int refresh_frame_context; /* Two state 0 = NO, 1 = YES */ | 220 int refresh_frame_context; /* Two state 0 = NO, 1 = YES */ |
180 | 221 |
181 int ref_frame_sign_bias[MAX_REF_FRAMES]; /* Two state 0, 1 */ | 222 int ref_frame_sign_bias[MAX_REF_FRAMES]; /* Two state 0, 1 */ |
182 | 223 |
183 struct loopfilter lf; | 224 struct loopfilter lf; |
184 struct segmentation seg; | 225 struct segmentation seg; |
185 | 226 |
| 227 // TODO(hkuang): Remove this as it is the same as frame_parallel_decode |
| 228 // in pbi. |
| 229 int frame_parallel_decode; // frame-based threading. |
| 230 |
186 // Context probabilities for reference frame prediction | 231 // Context probabilities for reference frame prediction |
187 MV_REFERENCE_FRAME comp_fixed_ref; | 232 MV_REFERENCE_FRAME comp_fixed_ref; |
188 MV_REFERENCE_FRAME comp_var_ref[2]; | 233 MV_REFERENCE_FRAME comp_var_ref[2]; |
189 REFERENCE_MODE reference_mode; | 234 REFERENCE_MODE reference_mode; |
190 | 235 |
191 FRAME_CONTEXT *fc; /* this frame entropy */ | 236 FRAME_CONTEXT *fc; /* this frame entropy */ |
192 FRAME_CONTEXT *frame_contexts; // FRAME_CONTEXTS | 237 FRAME_CONTEXT *frame_contexts; // FRAME_CONTEXTS |
193 unsigned int frame_context_idx; /* Context to use/update */ | 238 unsigned int frame_context_idx; /* Context to use/update */ |
194 FRAME_COUNTS counts; | 239 FRAME_COUNTS counts; |
195 | 240 |
(...skipping 15 matching lines...) Expand all Loading... |
211 int byte_alignment; | 256 int byte_alignment; |
212 | 257 |
213 // Private data associated with the frame buffer callbacks. | 258 // Private data associated with the frame buffer callbacks. |
214 void *cb_priv; | 259 void *cb_priv; |
215 vpx_get_frame_buffer_cb_fn_t get_fb_cb; | 260 vpx_get_frame_buffer_cb_fn_t get_fb_cb; |
216 vpx_release_frame_buffer_cb_fn_t release_fb_cb; | 261 vpx_release_frame_buffer_cb_fn_t release_fb_cb; |
217 | 262 |
218 // Handles memory for the codec. | 263 // Handles memory for the codec. |
219 InternalFrameBufferList int_frame_buffers; | 264 InternalFrameBufferList int_frame_buffers; |
220 | 265 |
| 266 // External BufferPool passed from outside. |
| 267 BufferPool *buffer_pool; |
| 268 |
221 PARTITION_CONTEXT *above_seg_context; | 269 PARTITION_CONTEXT *above_seg_context; |
222 ENTROPY_CONTEXT *above_context; | 270 ENTROPY_CONTEXT *above_context; |
223 } VP9_COMMON; | 271 } VP9_COMMON; |
224 | 272 |
| 273 // TODO(hkuang): Don't need to lock the whole pool after implementing atomic |
| 274 // frame reference count. |
| 275 void lock_buffer_pool(BufferPool *const pool); |
| 276 void unlock_buffer_pool(BufferPool *const pool); |
| 277 |
225 static INLINE YV12_BUFFER_CONFIG *get_ref_frame(VP9_COMMON *cm, int index) { | 278 static INLINE YV12_BUFFER_CONFIG *get_ref_frame(VP9_COMMON *cm, int index) { |
226 if (index < 0 || index >= REF_FRAMES) | 279 if (index < 0 || index >= REF_FRAMES) |
227 return NULL; | 280 return NULL; |
228 if (cm->ref_frame_map[index] < 0) | 281 if (cm->ref_frame_map[index] < 0) |
229 return NULL; | 282 return NULL; |
230 assert(cm->ref_frame_map[index] < FRAME_BUFFERS); | 283 assert(cm->ref_frame_map[index] < FRAME_BUFFERS); |
231 return &cm->frame_bufs[cm->ref_frame_map[index]].buf; | 284 return &cm->buffer_pool->frame_bufs[cm->ref_frame_map[index]].buf; |
232 } | 285 } |
233 | 286 |
234 static INLINE YV12_BUFFER_CONFIG *get_frame_new_buffer(VP9_COMMON *cm) { | 287 static INLINE YV12_BUFFER_CONFIG *get_frame_new_buffer(VP9_COMMON *cm) { |
235 return &cm->frame_bufs[cm->new_fb_idx].buf; | 288 return &cm->buffer_pool->frame_bufs[cm->new_fb_idx].buf; |
236 } | 289 } |
237 | 290 |
238 static INLINE int get_free_fb(VP9_COMMON *cm) { | 291 static INLINE int get_free_fb(VP9_COMMON *cm) { |
| 292 RefCntBuffer *const frame_bufs = cm->buffer_pool->frame_bufs; |
239 int i; | 293 int i; |
240 for (i = 0; i < FRAME_BUFFERS; i++) | 294 |
241 if (cm->frame_bufs[i].ref_count == 0) | 295 lock_buffer_pool(cm->buffer_pool); |
| 296 for (i = 0; i < FRAME_BUFFERS; ++i) |
| 297 if (frame_bufs[i].ref_count == 0) |
242 break; | 298 break; |
243 | 299 |
244 assert(i < FRAME_BUFFERS); | 300 assert(i < FRAME_BUFFERS); |
245 cm->frame_bufs[i].ref_count = 1; | 301 frame_bufs[i].ref_count = 1; |
| 302 unlock_buffer_pool(cm->buffer_pool); |
246 return i; | 303 return i; |
247 } | 304 } |
248 | 305 |
249 static INLINE void ref_cnt_fb(RefCntBuffer *bufs, int *idx, int new_idx) { | 306 static INLINE void ref_cnt_fb(RefCntBuffer *bufs, int *idx, int new_idx) { |
250 const int ref_index = *idx; | 307 const int ref_index = *idx; |
251 | 308 |
252 if (ref_index >= 0 && bufs[ref_index].ref_count > 0) | 309 if (ref_index >= 0 && bufs[ref_index].ref_count > 0) |
253 bufs[ref_index].ref_count--; | 310 bufs[ref_index].ref_count--; |
254 | 311 |
255 *idx = new_idx; | 312 *idx = new_idx; |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
368 left = (left & bs) > 0; | 425 left = (left & bs) > 0; |
369 | 426 |
370 return (left * 2 + above) + bsl * PARTITION_PLOFFSET; | 427 return (left * 2 + above) + bsl * PARTITION_PLOFFSET; |
371 } | 428 } |
372 | 429 |
373 #ifdef __cplusplus | 430 #ifdef __cplusplus |
374 } // extern "C" | 431 } // extern "C" |
375 #endif | 432 #endif |
376 | 433 |
377 #endif // VP9_COMMON_VP9_ONYXC_INT_H_ | 434 #endif // VP9_COMMON_VP9_ONYXC_INT_H_ |
OLD | NEW |