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 | 11 #include <assert.h> |
| 12 #include <limits.h> |
12 #include <stdio.h> | 13 #include <stdio.h> |
13 #include <assert.h> | |
14 | 14 |
15 #include "vp9/common/vp9_onyxc_int.h" | 15 #include "vp9/common/vp9_onyxc_int.h" |
16 #if CONFIG_POSTPROC | 16 #if CONFIG_POSTPROC |
17 #include "vp9/common/vp9_postproc.h" | 17 #include "vp9/common/vp9_postproc.h" |
18 #endif | 18 #endif |
19 #include "vp9/decoder/vp9_onyxd.h" | 19 #include "vp9/decoder/vp9_onyxd.h" |
20 #include "vp9/decoder/vp9_onyxd_int.h" | 20 #include "vp9/decoder/vp9_onyxd_int.h" |
21 #include "vpx_mem/vpx_mem.h" | 21 #include "vpx_mem/vpx_mem.h" |
22 #include "vp9/common/vp9_alloccommon.h" | 22 #include "vp9/common/vp9_alloccommon.h" |
23 #include "vp9/common/vp9_loopfilter.h" | 23 #include "vp9/common/vp9_loopfilter.h" |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 | 103 |
104 if (!init_done) { | 104 if (!init_done) { |
105 vp9_initialize_common(); | 105 vp9_initialize_common(); |
106 vp9_init_quant_tables(); | 106 vp9_init_quant_tables(); |
107 init_done = 1; | 107 init_done = 1; |
108 } | 108 } |
109 } | 109 } |
110 | 110 |
111 VP9D_PTR vp9_create_decompressor(VP9D_CONFIG *oxcf) { | 111 VP9D_PTR vp9_create_decompressor(VP9D_CONFIG *oxcf) { |
112 VP9D_COMP *const pbi = vpx_memalign(32, sizeof(VP9D_COMP)); | 112 VP9D_COMP *const pbi = vpx_memalign(32, sizeof(VP9D_COMP)); |
| 113 VP9_COMMON *const cm = pbi ? &pbi->common : NULL; |
113 | 114 |
114 if (!pbi) | 115 if (!cm) |
115 return NULL; | 116 return NULL; |
116 | 117 |
117 vpx_memset(pbi, 0, sizeof(VP9D_COMP)); | 118 vp9_zero(*pbi); |
118 | 119 |
119 if (setjmp(pbi->common.error.jmp)) { | 120 if (setjmp(cm->error.jmp)) { |
120 pbi->common.error.setjmp = 0; | 121 cm->error.setjmp = 0; |
121 vp9_remove_decompressor(pbi); | 122 vp9_remove_decompressor(pbi); |
122 return NULL; | 123 return NULL; |
123 } | 124 } |
124 | 125 |
125 pbi->common.error.setjmp = 1; | 126 cm->error.setjmp = 1; |
126 vp9_initialize_dec(); | 127 vp9_initialize_dec(); |
127 | 128 |
128 vp9_create_common(&pbi->common); | 129 vp9_create_common(cm); |
129 | 130 |
130 pbi->oxcf = *oxcf; | 131 pbi->oxcf = *oxcf; |
131 pbi->common.current_video_frame = 0; | |
132 pbi->ready_for_new_data = 1; | 132 pbi->ready_for_new_data = 1; |
| 133 cm->current_video_frame = 0; |
133 | 134 |
134 // vp9_init_dequantizer() is first called here. Add check in | 135 // vp9_init_dequantizer() is first called here. Add check in |
135 // frame_init_dequantizer() to avoid unnecessary calling of | 136 // frame_init_dequantizer() to avoid unnecessary calling of |
136 // vp9_init_dequantizer() for every frame. | 137 // vp9_init_dequantizer() for every frame. |
137 vp9_init_dequantizer(&pbi->common); | 138 vp9_init_dequantizer(cm); |
138 | 139 |
139 vp9_loop_filter_init(&pbi->common, &pbi->mb.lf); | 140 vp9_loop_filter_init(cm); |
140 | 141 |
141 pbi->common.error.setjmp = 0; | 142 cm->error.setjmp = 0; |
142 pbi->decoded_key_frame = 0; | 143 pbi->decoded_key_frame = 0; |
143 | 144 |
| 145 if (pbi->oxcf.max_threads > 1) { |
| 146 vp9_worker_init(&pbi->lf_worker); |
| 147 pbi->lf_worker.data1 = vpx_malloc(sizeof(LFWorkerData)); |
| 148 pbi->lf_worker.hook = (VP9WorkerHook)vp9_loop_filter_worker; |
| 149 if (pbi->lf_worker.data1 == NULL || !vp9_worker_reset(&pbi->lf_worker)) { |
| 150 vp9_remove_decompressor(pbi); |
| 151 return NULL; |
| 152 } |
| 153 } |
| 154 |
144 return pbi; | 155 return pbi; |
145 } | 156 } |
146 | 157 |
147 void vp9_remove_decompressor(VP9D_PTR ptr) { | 158 void vp9_remove_decompressor(VP9D_PTR ptr) { |
148 VP9D_COMP *const pbi = (VP9D_COMP *)ptr; | 159 VP9D_COMP *const pbi = (VP9D_COMP *)ptr; |
149 | 160 |
150 if (!pbi) | 161 if (!pbi) |
151 return; | 162 return; |
152 | 163 |
153 if (pbi->common.last_frame_seg_map) | |
154 vpx_free(pbi->common.last_frame_seg_map); | |
155 | |
156 vp9_remove_common(&pbi->common); | 164 vp9_remove_common(&pbi->common); |
| 165 vp9_worker_end(&pbi->lf_worker); |
| 166 vpx_free(pbi->lf_worker.data1); |
157 vpx_free(pbi); | 167 vpx_free(pbi); |
158 } | 168 } |
159 | 169 |
160 static int equal_dimensions(YV12_BUFFER_CONFIG *a, YV12_BUFFER_CONFIG *b) { | 170 static int equal_dimensions(YV12_BUFFER_CONFIG *a, YV12_BUFFER_CONFIG *b) { |
161 return a->y_height == b->y_height && a->y_width == b->y_width && | 171 return a->y_height == b->y_height && a->y_width == b->y_width && |
162 a->uv_height == b->uv_height && a->uv_width == b->uv_width; | 172 a->uv_height == b->uv_height && a->uv_width == b->uv_width; |
163 } | 173 } |
164 | 174 |
165 vpx_codec_err_t vp9_copy_reference_dec(VP9D_PTR ptr, | 175 vpx_codec_err_t vp9_copy_reference_dec(VP9D_PTR ptr, |
166 VP9_REFFRAME ref_frame_flag, | 176 VP9_REFFRAME ref_frame_flag, |
167 YV12_BUFFER_CONFIG *sd) { | 177 YV12_BUFFER_CONFIG *sd) { |
168 VP9D_COMP *pbi = (VP9D_COMP *) ptr; | 178 VP9D_COMP *pbi = (VP9D_COMP *) ptr; |
169 VP9_COMMON *cm = &pbi->common; | 179 VP9_COMMON *cm = &pbi->common; |
170 int ref_fb_idx; | 180 int ref_fb_idx; |
171 | 181 |
172 /* TODO(jkoleszar): The decoder doesn't have any real knowledge of what the | 182 /* TODO(jkoleszar): The decoder doesn't have any real knowledge of what the |
173 * encoder is using the frame buffers for. This is just a stub to keep the | 183 * encoder is using the frame buffers for. This is just a stub to keep the |
174 * vpxenc --test-decode functionality working, and will be replaced in a | 184 * vpxenc --test-decode functionality working, and will be replaced in a |
175 * later commit that adds VP9-specific controls for this functionality. | 185 * later commit that adds VP9-specific controls for this functionality. |
176 */ | 186 */ |
177 if (ref_frame_flag == VP9_LAST_FLAG) { | 187 if (ref_frame_flag == VP9_LAST_FLAG) { |
178 ref_fb_idx = pbi->common.ref_frame_map[0]; | 188 ref_fb_idx = cm->ref_frame_map[0]; |
179 } else { | 189 } else { |
180 vpx_internal_error(&pbi->common.error, VPX_CODEC_ERROR, | 190 vpx_internal_error(&cm->error, VPX_CODEC_ERROR, |
181 "Invalid reference frame"); | 191 "Invalid reference frame"); |
182 return pbi->common.error.error_code; | 192 return cm->error.error_code; |
183 } | 193 } |
184 | 194 |
185 if (!equal_dimensions(&cm->yv12_fb[ref_fb_idx], sd)) { | 195 if (!equal_dimensions(&cm->yv12_fb[ref_fb_idx], sd)) { |
186 vpx_internal_error(&pbi->common.error, VPX_CODEC_ERROR, | 196 vpx_internal_error(&cm->error, VPX_CODEC_ERROR, |
187 "Incorrect buffer dimensions"); | 197 "Incorrect buffer dimensions"); |
188 } else { | 198 } else { |
189 vp8_yv12_copy_frame(&cm->yv12_fb[ref_fb_idx], sd); | 199 vp8_yv12_copy_frame(&cm->yv12_fb[ref_fb_idx], sd); |
190 } | 200 } |
191 | 201 |
192 return pbi->common.error.error_code; | 202 return cm->error.error_code; |
193 } | 203 } |
194 | 204 |
195 | 205 |
196 vpx_codec_err_t vp9_set_reference_dec(VP9D_PTR ptr, VP9_REFFRAME ref_frame_flag, | 206 vpx_codec_err_t vp9_set_reference_dec(VP9D_PTR ptr, VP9_REFFRAME ref_frame_flag, |
197 YV12_BUFFER_CONFIG *sd) { | 207 YV12_BUFFER_CONFIG *sd) { |
198 VP9D_COMP *pbi = (VP9D_COMP *) ptr; | 208 VP9D_COMP *pbi = (VP9D_COMP *) ptr; |
199 VP9_COMMON *cm = &pbi->common; | 209 VP9_COMMON *cm = &pbi->common; |
200 int *ref_fb_ptr = NULL; | 210 int *ref_fb_ptr = NULL; |
201 | 211 |
202 /* TODO(jkoleszar): The decoder doesn't have any real knowledge of what the | 212 /* TODO(jkoleszar): The decoder doesn't have any real knowledge of what the |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 if (index < 0 || index >= NUM_REF_FRAMES) | 252 if (index < 0 || index >= NUM_REF_FRAMES) |
243 return -1; | 253 return -1; |
244 | 254 |
245 *fb = &cm->yv12_fb[cm->ref_frame_map[index]]; | 255 *fb = &cm->yv12_fb[cm->ref_frame_map[index]]; |
246 return 0; | 256 return 0; |
247 } | 257 } |
248 | 258 |
249 /* If any buffer updating is signaled it should be done here. */ | 259 /* If any buffer updating is signaled it should be done here. */ |
250 static void swap_frame_buffers(VP9D_COMP *pbi) { | 260 static void swap_frame_buffers(VP9D_COMP *pbi) { |
251 int ref_index = 0, mask; | 261 int ref_index = 0, mask; |
| 262 VP9_COMMON *const cm = &pbi->common; |
252 | 263 |
253 for (mask = pbi->refresh_frame_flags; mask; mask >>= 1) { | 264 for (mask = pbi->refresh_frame_flags; mask; mask >>= 1) { |
254 if (mask & 1) { | 265 if (mask & 1) |
255 ref_cnt_fb(pbi->common.fb_idx_ref_cnt, | 266 ref_cnt_fb(cm->fb_idx_ref_cnt, &cm->ref_frame_map[ref_index], |
256 &pbi->common.ref_frame_map[ref_index], | 267 cm->new_fb_idx); |
257 pbi->common.new_fb_idx); | |
258 } | |
259 ++ref_index; | 268 ++ref_index; |
260 } | 269 } |
261 | 270 |
262 pbi->common.frame_to_show = &pbi->common.yv12_fb[pbi->common.new_fb_idx]; | 271 cm->frame_to_show = &cm->yv12_fb[cm->new_fb_idx]; |
263 pbi->common.fb_idx_ref_cnt[pbi->common.new_fb_idx]--; | 272 cm->fb_idx_ref_cnt[cm->new_fb_idx]--; |
264 | 273 |
265 /* Invalidate these references until the next frame starts. */ | 274 // Invalidate these references until the next frame starts. |
266 for (ref_index = 0; ref_index < 3; ref_index++) | 275 for (ref_index = 0; ref_index < 3; ref_index++) |
267 pbi->common.active_ref_idx[ref_index] = INT_MAX; | 276 cm->active_ref_idx[ref_index] = INT_MAX; |
268 } | 277 } |
269 | 278 |
270 int vp9_receive_compressed_data(VP9D_PTR ptr, | 279 int vp9_receive_compressed_data(VP9D_PTR ptr, |
271 uint64_t size, const uint8_t **psource, | 280 uint64_t size, const uint8_t **psource, |
272 int64_t time_stamp) { | 281 int64_t time_stamp) { |
273 VP9D_COMP *pbi = (VP9D_COMP *) ptr; | 282 VP9D_COMP *pbi = (VP9D_COMP *) ptr; |
274 VP9_COMMON *cm = &pbi->common; | 283 VP9_COMMON *cm = &pbi->common; |
275 const uint8_t *source = *psource; | 284 const uint8_t *source = *psource; |
276 int retcode = 0; | 285 int retcode = 0; |
277 | 286 |
278 /*if(pbi->ready_for_new_data == 0) | 287 /*if(pbi->ready_for_new_data == 0) |
279 return -1;*/ | 288 return -1;*/ |
280 | 289 |
281 if (ptr == 0) | 290 if (ptr == 0) |
282 return -1; | 291 return -1; |
283 | 292 |
284 pbi->common.error.error_code = VPX_CODEC_OK; | 293 cm->error.error_code = VPX_CODEC_OK; |
285 | 294 |
286 pbi->source = source; | 295 pbi->source = source; |
287 pbi->source_sz = size; | 296 pbi->source_sz = size; |
288 | 297 |
289 if (pbi->source_sz == 0) { | 298 if (pbi->source_sz == 0) { |
290 /* This is used to signal that we are missing frames. | 299 /* This is used to signal that we are missing frames. |
291 * We do not know if the missing frame(s) was supposed to update | 300 * We do not know if the missing frame(s) was supposed to update |
292 * any of the reference buffers, but we act conservative and | 301 * any of the reference buffers, but we act conservative and |
293 * mark only the last buffer as corrupted. | 302 * mark only the last buffer as corrupted. |
294 * | 303 * |
295 * TODO(jkoleszar): Error concealment is undefined and non-normative | 304 * TODO(jkoleszar): Error concealment is undefined and non-normative |
296 * at this point, but if it becomes so, [0] may not always be the correct | 305 * at this point, but if it becomes so, [0] may not always be the correct |
297 * thing to do here. | 306 * thing to do here. |
298 */ | 307 */ |
299 if (cm->active_ref_idx[0] != INT_MAX) | 308 if (cm->active_ref_idx[0] != INT_MAX) |
300 cm->yv12_fb[cm->active_ref_idx[0]].corrupted = 1; | 309 cm->yv12_fb[cm->active_ref_idx[0]].corrupted = 1; |
301 } | 310 } |
302 | 311 |
303 cm->new_fb_idx = get_free_fb(cm); | 312 cm->new_fb_idx = get_free_fb(cm); |
304 | 313 |
305 if (setjmp(pbi->common.error.jmp)) { | 314 if (setjmp(cm->error.jmp)) { |
306 pbi->common.error.setjmp = 0; | 315 cm->error.setjmp = 0; |
307 | 316 |
308 /* We do not know if the missing frame(s) was supposed to update | 317 /* We do not know if the missing frame(s) was supposed to update |
309 * any of the reference buffers, but we act conservative and | 318 * any of the reference buffers, but we act conservative and |
310 * mark only the last buffer as corrupted. | 319 * mark only the last buffer as corrupted. |
311 * | 320 * |
312 * TODO(jkoleszar): Error concealment is undefined and non-normative | 321 * TODO(jkoleszar): Error concealment is undefined and non-normative |
313 * at this point, but if it becomes so, [0] may not always be the correct | 322 * at this point, but if it becomes so, [0] may not always be the correct |
314 * thing to do here. | 323 * thing to do here. |
315 */ | 324 */ |
316 if (cm->active_ref_idx[0] != INT_MAX) | 325 if (cm->active_ref_idx[0] != INT_MAX) |
317 cm->yv12_fb[cm->active_ref_idx[0]].corrupted = 1; | 326 cm->yv12_fb[cm->active_ref_idx[0]].corrupted = 1; |
318 | 327 |
319 if (cm->fb_idx_ref_cnt[cm->new_fb_idx] > 0) | 328 if (cm->fb_idx_ref_cnt[cm->new_fb_idx] > 0) |
320 cm->fb_idx_ref_cnt[cm->new_fb_idx]--; | 329 cm->fb_idx_ref_cnt[cm->new_fb_idx]--; |
321 | 330 |
322 return -1; | 331 return -1; |
323 } | 332 } |
324 | 333 |
325 pbi->common.error.setjmp = 1; | 334 cm->error.setjmp = 1; |
326 | 335 |
327 retcode = vp9_decode_frame(pbi, psource); | 336 retcode = vp9_decode_frame(pbi, psource); |
328 | 337 |
329 if (retcode < 0) { | 338 if (retcode < 0) { |
330 pbi->common.error.error_code = VPX_CODEC_ERROR; | 339 cm->error.error_code = VPX_CODEC_ERROR; |
331 pbi->common.error.setjmp = 0; | 340 cm->error.setjmp = 0; |
332 if (cm->fb_idx_ref_cnt[cm->new_fb_idx] > 0) | 341 if (cm->fb_idx_ref_cnt[cm->new_fb_idx] > 0) |
333 cm->fb_idx_ref_cnt[cm->new_fb_idx]--; | 342 cm->fb_idx_ref_cnt[cm->new_fb_idx]--; |
334 return retcode; | 343 return retcode; |
335 } | 344 } |
336 | 345 |
337 { | 346 { |
338 swap_frame_buffers(pbi); | 347 swap_frame_buffers(pbi); |
339 | 348 |
340 #if WRITE_RECON_BUFFER == 2 | 349 #if WRITE_RECON_BUFFER == 2 |
341 if (cm->show_frame) | 350 if (cm->show_frame) |
342 write_dx_frame_to_file(cm->frame_to_show, | 351 write_dx_frame_to_file(cm->frame_to_show, |
343 cm->current_video_frame); | 352 cm->current_video_frame); |
344 else | 353 else |
345 write_dx_frame_to_file(cm->frame_to_show, | 354 write_dx_frame_to_file(cm->frame_to_show, |
346 cm->current_video_frame + 1000); | 355 cm->current_video_frame + 1000); |
347 #endif | 356 #endif |
348 | 357 |
349 if (!pbi->do_loopfilter_inline) { | 358 if (!pbi->do_loopfilter_inline) { |
350 /* Apply the loop filter if appropriate. */ | 359 /* Apply the loop filter if appropriate. */ |
351 vp9_loop_filter_frame(cm, &pbi->mb, pbi->mb.lf.filter_level, 0); | 360 vp9_loop_filter_frame(cm, &pbi->mb, pbi->common.lf.filter_level, 0, 0); |
352 } | 361 } |
353 | 362 |
354 #if WRITE_RECON_BUFFER == 2 | 363 #if WRITE_RECON_BUFFER == 2 |
355 if (cm->show_frame) | 364 if (cm->show_frame) |
356 write_dx_frame_to_file(cm->frame_to_show, | 365 write_dx_frame_to_file(cm->frame_to_show, |
357 cm->current_video_frame + 2000); | 366 cm->current_video_frame + 2000); |
358 else | 367 else |
359 write_dx_frame_to_file(cm->frame_to_show, | 368 write_dx_frame_to_file(cm->frame_to_show, |
360 cm->current_video_frame + 3000); | 369 cm->current_video_frame + 3000); |
361 #endif | 370 #endif |
(...skipping 22 matching lines...) Expand all Loading... |
384 cm->mi = cm->mip + cm->mode_info_stride + 1; | 393 cm->mi = cm->mip + cm->mode_info_stride + 1; |
385 cm->prev_mi = cm->prev_mip + cm->mode_info_stride + 1; | 394 cm->prev_mi = cm->prev_mip + cm->mode_info_stride + 1; |
386 | 395 |
387 cm->current_video_frame++; | 396 cm->current_video_frame++; |
388 } | 397 } |
389 | 398 |
390 pbi->ready_for_new_data = 0; | 399 pbi->ready_for_new_data = 0; |
391 pbi->last_time_stamp = time_stamp; | 400 pbi->last_time_stamp = time_stamp; |
392 pbi->source_sz = 0; | 401 pbi->source_sz = 0; |
393 | 402 |
394 pbi->common.error.setjmp = 0; | 403 cm->error.setjmp = 0; |
395 return retcode; | 404 return retcode; |
396 } | 405 } |
397 | 406 |
398 int vp9_get_raw_frame(VP9D_PTR ptr, YV12_BUFFER_CONFIG *sd, | 407 int vp9_get_raw_frame(VP9D_PTR ptr, YV12_BUFFER_CONFIG *sd, |
399 int64_t *time_stamp, int64_t *time_end_stamp, | 408 int64_t *time_stamp, int64_t *time_end_stamp, |
400 vp9_ppflags_t *flags) { | 409 vp9_ppflags_t *flags) { |
401 int ret = -1; | 410 int ret = -1; |
402 VP9D_COMP *pbi = (VP9D_COMP *) ptr; | 411 VP9D_COMP *pbi = (VP9D_COMP *) ptr; |
403 | 412 |
404 if (pbi->ready_for_new_data == 1) | 413 if (pbi->ready_for_new_data == 1) |
405 return ret; | 414 return ret; |
406 | 415 |
407 /* ie no raw frame to show!!! */ | 416 /* ie no raw frame to show!!! */ |
408 if (pbi->common.show_frame == 0) | 417 if (pbi->common.show_frame == 0) |
409 return ret; | 418 return ret; |
410 | 419 |
411 pbi->ready_for_new_data = 1; | 420 pbi->ready_for_new_data = 1; |
412 *time_stamp = pbi->last_time_stamp; | 421 *time_stamp = pbi->last_time_stamp; |
413 *time_end_stamp = 0; | 422 *time_end_stamp = 0; |
414 | 423 |
415 #if CONFIG_POSTPROC | 424 #if CONFIG_POSTPROC |
416 ret = vp9_post_proc_frame(&pbi->common, &pbi->mb.lf, sd, flags); | 425 ret = vp9_post_proc_frame(&pbi->common, sd, flags); |
417 #else | 426 #else |
418 | 427 |
419 if (pbi->common.frame_to_show) { | 428 if (pbi->common.frame_to_show) { |
420 *sd = *pbi->common.frame_to_show; | 429 *sd = *pbi->common.frame_to_show; |
421 sd->y_width = pbi->common.width; | 430 sd->y_width = pbi->common.width; |
422 sd->y_height = pbi->common.height; | 431 sd->y_height = pbi->common.height; |
423 sd->uv_height = pbi->common.height / 2; | 432 sd->uv_height = pbi->common.height / 2; |
424 ret = 0; | 433 ret = 0; |
425 } else { | 434 } else { |
426 ret = -1; | 435 ret = -1; |
427 } | 436 } |
428 | 437 |
429 #endif /*!CONFIG_POSTPROC*/ | 438 #endif /*!CONFIG_POSTPROC*/ |
430 vp9_clear_system_state(); | 439 vp9_clear_system_state(); |
431 return ret; | 440 return ret; |
432 } | 441 } |
OLD | NEW |