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