| 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 14 matching lines...) Expand all Loading... |
| 25 #include "vp9/common/vp9_postproc.h" | 25 #include "vp9/common/vp9_postproc.h" |
| 26 #endif | 26 #endif |
| 27 #include "vp9/common/vp9_quant_common.h" | 27 #include "vp9/common/vp9_quant_common.h" |
| 28 #include "vp9/common/vp9_systemdependent.h" | 28 #include "vp9/common/vp9_systemdependent.h" |
| 29 | 29 |
| 30 #include "vp9/decoder/vp9_decodeframe.h" | 30 #include "vp9/decoder/vp9_decodeframe.h" |
| 31 #include "vp9/decoder/vp9_decoder.h" | 31 #include "vp9/decoder/vp9_decoder.h" |
| 32 #include "vp9/decoder/vp9_detokenize.h" | 32 #include "vp9/decoder/vp9_detokenize.h" |
| 33 #include "vp9/decoder/vp9_dthread.h" | 33 #include "vp9/decoder/vp9_dthread.h" |
| 34 | 34 |
| 35 void vp9_initialize_dec() { | 35 static void initialize_dec() { |
| 36 static int init_done = 0; | 36 static int init_done = 0; |
| 37 | 37 |
| 38 if (!init_done) { | 38 if (!init_done) { |
| 39 vp9_init_neighbors(); | 39 vp9_init_neighbors(); |
| 40 vp9_init_quant_tables(); | 40 vp9_init_quant_tables(); |
| 41 init_done = 1; | 41 init_done = 1; |
| 42 } | 42 } |
| 43 } | 43 } |
| 44 | 44 |
| 45 VP9Decoder *vp9_decoder_create() { | 45 VP9Decoder *vp9_decoder_create() { |
| 46 VP9Decoder *const pbi = vpx_memalign(32, sizeof(*pbi)); | 46 VP9Decoder *const pbi = vpx_memalign(32, sizeof(*pbi)); |
| 47 VP9_COMMON *const cm = pbi ? &pbi->common : NULL; | 47 VP9_COMMON *const cm = pbi ? &pbi->common : NULL; |
| 48 | 48 |
| 49 if (!cm) | 49 if (!cm) |
| 50 return NULL; | 50 return NULL; |
| 51 | 51 |
| 52 vp9_zero(*pbi); | 52 vp9_zero(*pbi); |
| 53 | 53 |
| 54 if (setjmp(cm->error.jmp)) { | 54 if (setjmp(cm->error.jmp)) { |
| 55 cm->error.setjmp = 0; | 55 cm->error.setjmp = 0; |
| 56 vp9_decoder_remove(pbi); | 56 vp9_decoder_remove(pbi); |
| 57 return NULL; | 57 return NULL; |
| 58 } | 58 } |
| 59 | 59 |
| 60 cm->error.setjmp = 1; | 60 cm->error.setjmp = 1; |
| 61 vp9_initialize_dec(); | 61 initialize_dec(); |
| 62 | 62 |
| 63 vp9_rtcd(); | 63 vp9_rtcd(); |
| 64 | 64 |
| 65 // Initialize the references to not point to any frame buffers. | 65 // Initialize the references to not point to any frame buffers. |
| 66 vpx_memset(&cm->ref_frame_map, -1, sizeof(cm->ref_frame_map)); | 66 vpx_memset(&cm->ref_frame_map, -1, sizeof(cm->ref_frame_map)); |
| 67 | 67 |
| 68 cm->current_video_frame = 0; | 68 cm->current_video_frame = 0; |
| 69 pbi->ready_for_new_data = 1; | 69 pbi->ready_for_new_data = 1; |
| 70 pbi->decoded_key_frame = 0; | |
| 71 | 70 |
| 72 // vp9_init_dequantizer() is first called here. Add check in | 71 // vp9_init_dequantizer() is first called here. Add check in |
| 73 // frame_init_dequantizer() to avoid unnecessary calling of | 72 // frame_init_dequantizer() to avoid unnecessary calling of |
| 74 // vp9_init_dequantizer() for every frame. | 73 // vp9_init_dequantizer() for every frame. |
| 75 vp9_init_dequantizer(cm); | 74 vp9_init_dequantizer(cm); |
| 76 | 75 |
| 77 vp9_loop_filter_init(cm); | 76 vp9_loop_filter_init(cm); |
| 78 | 77 |
| 79 cm->error.setjmp = 0; | 78 cm->error.setjmp = 0; |
| 80 | 79 |
| 81 vp9_worker_init(&pbi->lf_worker); | 80 vp9_worker_init(&pbi->lf_worker); |
| 82 | 81 |
| 83 return pbi; | 82 return pbi; |
| 84 } | 83 } |
| 85 | 84 |
| 86 void vp9_decoder_remove(VP9Decoder *pbi) { | 85 void vp9_decoder_remove(VP9Decoder *pbi) { |
| 87 VP9_COMMON *const cm = &pbi->common; | 86 VP9_COMMON *const cm = &pbi->common; |
| 88 int i; | 87 int i; |
| 89 | 88 |
| 90 vp9_remove_common(cm); | 89 vp9_remove_common(cm); |
| 91 vp9_worker_end(&pbi->lf_worker); | 90 vp9_worker_end(&pbi->lf_worker); |
| 92 vpx_free(pbi->lf_worker.data1); | 91 vpx_free(pbi->lf_worker.data1); |
| 92 vpx_free(pbi->tile_data); |
| 93 for (i = 0; i < pbi->num_tile_workers; ++i) { | 93 for (i = 0; i < pbi->num_tile_workers; ++i) { |
| 94 VP9Worker *const worker = &pbi->tile_workers[i]; | 94 VP9Worker *const worker = &pbi->tile_workers[i]; |
| 95 vp9_worker_end(worker); | 95 vp9_worker_end(worker); |
| 96 vpx_free(worker->data1); | 96 vpx_free(worker->data1); |
| 97 vpx_free(worker->data2); | 97 vpx_free(worker->data2); |
| 98 } | 98 } |
| 99 vpx_free(pbi->tile_workers); | 99 vpx_free(pbi->tile_workers); |
| 100 | 100 |
| 101 if (pbi->num_tile_workers) { | 101 if (pbi->num_tile_workers) { |
| 102 const int sb_rows = | 102 const int sb_rows = |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 ref_cnt_fb(cm->frame_bufs, &cm->ref_frame_map[ref_index], | 204 ref_cnt_fb(cm->frame_bufs, &cm->ref_frame_map[ref_index], |
| 205 cm->new_fb_idx); | 205 cm->new_fb_idx); |
| 206 if (old_idx >= 0 && cm->frame_bufs[old_idx].ref_count == 0) | 206 if (old_idx >= 0 && cm->frame_bufs[old_idx].ref_count == 0) |
| 207 cm->release_fb_cb(cm->cb_priv, | 207 cm->release_fb_cb(cm->cb_priv, |
| 208 &cm->frame_bufs[old_idx].raw_frame_buffer); | 208 &cm->frame_bufs[old_idx].raw_frame_buffer); |
| 209 } | 209 } |
| 210 ++ref_index; | 210 ++ref_index; |
| 211 } | 211 } |
| 212 | 212 |
| 213 cm->frame_to_show = get_frame_new_buffer(cm); | 213 cm->frame_to_show = get_frame_new_buffer(cm); |
| 214 cm->frame_bufs[cm->new_fb_idx].ref_count--; | 214 |
| 215 if (!pbi->frame_parallel_decode || !cm->show_frame) { |
| 216 --cm->frame_bufs[cm->new_fb_idx].ref_count; |
| 217 } |
| 215 | 218 |
| 216 // Invalidate these references until the next frame starts. | 219 // Invalidate these references until the next frame starts. |
| 217 for (ref_index = 0; ref_index < 3; ref_index++) | 220 for (ref_index = 0; ref_index < 3; ref_index++) |
| 218 cm->frame_refs[ref_index].idx = INT_MAX; | 221 cm->frame_refs[ref_index].idx = INT_MAX; |
| 219 } | 222 } |
| 220 | 223 |
| 221 int vp9_receive_compressed_data(VP9Decoder *pbi, | 224 int vp9_receive_compressed_data(VP9Decoder *pbi, |
| 222 size_t size, const uint8_t **psource, | 225 size_t size, const uint8_t **psource) { |
| 223 int64_t time_stamp) { | |
| 224 VP9_COMMON *const cm = &pbi->common; | 226 VP9_COMMON *const cm = &pbi->common; |
| 225 const uint8_t *source = *psource; | 227 const uint8_t *source = *psource; |
| 226 int retcode = 0; | 228 int retcode = 0; |
| 227 | 229 |
| 228 cm->error.error_code = VPX_CODEC_OK; | 230 cm->error.error_code = VPX_CODEC_OK; |
| 229 | 231 |
| 230 if (size == 0) { | 232 if (size == 0) { |
| 231 // This is used to signal that we are missing frames. | 233 // This is used to signal that we are missing frames. |
| 232 // We do not know if the missing frame(s) was supposed to update | 234 // We do not know if the missing frame(s) was supposed to update |
| 233 // any of the reference buffers, but we act conservative and | 235 // any of the reference buffers, but we act conservative and |
| 234 // mark only the last buffer as corrupted. | 236 // mark only the last buffer as corrupted. |
| 235 // | 237 // |
| 236 // TODO(jkoleszar): Error concealment is undefined and non-normative | 238 // TODO(jkoleszar): Error concealment is undefined and non-normative |
| 237 // at this point, but if it becomes so, [0] may not always be the correct | 239 // at this point, but if it becomes so, [0] may not always be the correct |
| 238 // thing to do here. | 240 // thing to do here. |
| 239 if (cm->frame_refs[0].idx != INT_MAX) | 241 if (cm->frame_refs[0].idx != INT_MAX) |
| 240 cm->frame_refs[0].buf->corrupted = 1; | 242 cm->frame_refs[0].buf->corrupted = 1; |
| 241 } | 243 } |
| 242 | 244 |
| 243 // Check if the previous frame was a frame without any references to it. | 245 // Check if the previous frame was a frame without any references to it. |
| 244 if (cm->new_fb_idx >= 0 && cm->frame_bufs[cm->new_fb_idx].ref_count == 0) | 246 // Release frame buffer if not decoding in frame parallel mode. |
| 247 if (!pbi->frame_parallel_decode && cm->new_fb_idx >= 0 && |
| 248 cm->frame_bufs[cm->new_fb_idx].ref_count == 0) |
| 245 cm->release_fb_cb(cm->cb_priv, | 249 cm->release_fb_cb(cm->cb_priv, |
| 246 &cm->frame_bufs[cm->new_fb_idx].raw_frame_buffer); | 250 &cm->frame_bufs[cm->new_fb_idx].raw_frame_buffer); |
| 247 cm->new_fb_idx = get_free_fb(cm); | 251 cm->new_fb_idx = get_free_fb(cm); |
| 248 | 252 |
| 249 if (setjmp(cm->error.jmp)) { | 253 if (setjmp(cm->error.jmp)) { |
| 250 cm->error.setjmp = 0; | 254 cm->error.setjmp = 0; |
| 251 | 255 |
| 252 // We do not know if the missing frame(s) was supposed to update | 256 // We do not know if the missing frame(s) was supposed to update |
| 253 // any of the reference buffers, but we act conservative and | 257 // any of the reference buffers, but we act conservative and |
| 254 // mark only the last buffer as corrupted. | 258 // mark only the last buffer as corrupted. |
| 255 // | 259 // |
| 256 // TODO(jkoleszar): Error concealment is undefined and non-normative | 260 // TODO(jkoleszar): Error concealment is undefined and non-normative |
| 257 // at this point, but if it becomes so, [0] may not always be the correct | 261 // at this point, but if it becomes so, [0] may not always be the correct |
| 258 // thing to do here. | 262 // thing to do here. |
| 259 if (cm->frame_refs[0].idx != INT_MAX) | 263 if (cm->frame_refs[0].idx != INT_MAX) |
| 260 cm->frame_refs[0].buf->corrupted = 1; | 264 cm->frame_refs[0].buf->corrupted = 1; |
| 261 | 265 |
| 262 if (cm->frame_bufs[cm->new_fb_idx].ref_count > 0) | 266 if (cm->frame_bufs[cm->new_fb_idx].ref_count > 0) |
| 263 cm->frame_bufs[cm->new_fb_idx].ref_count--; | 267 cm->frame_bufs[cm->new_fb_idx].ref_count--; |
| 264 | 268 |
| 265 return -1; | 269 return -1; |
| 266 } | 270 } |
| 267 | 271 |
| 268 cm->error.setjmp = 1; | 272 cm->error.setjmp = 1; |
| 269 | 273 |
| 270 retcode = vp9_decode_frame(pbi, source, source + size, psource); | 274 vp9_decode_frame(pbi, source, source + size, psource); |
| 271 | |
| 272 if (retcode < 0) { | |
| 273 cm->error.error_code = VPX_CODEC_ERROR; | |
| 274 cm->error.setjmp = 0; | |
| 275 if (cm->frame_bufs[cm->new_fb_idx].ref_count > 0) | |
| 276 cm->frame_bufs[cm->new_fb_idx].ref_count--; | |
| 277 return retcode; | |
| 278 } | |
| 279 | 275 |
| 280 swap_frame_buffers(pbi); | 276 swap_frame_buffers(pbi); |
| 281 | 277 |
| 282 vp9_clear_system_state(); | 278 vp9_clear_system_state(); |
| 283 | 279 |
| 284 cm->last_width = cm->width; | 280 cm->last_width = cm->width; |
| 285 cm->last_height = cm->height; | 281 cm->last_height = cm->height; |
| 286 | 282 |
| 287 if (!cm->show_existing_frame) | 283 if (!cm->show_existing_frame) |
| 288 cm->last_show_frame = cm->show_frame; | 284 cm->last_show_frame = cm->show_frame; |
| 289 if (cm->show_frame) { | 285 if (cm->show_frame) { |
| 290 if (!cm->show_existing_frame) | 286 if (!cm->show_existing_frame) |
| 291 vp9_swap_mi_and_prev_mi(cm); | 287 vp9_swap_mi_and_prev_mi(cm); |
| 292 | 288 |
| 293 cm->current_video_frame++; | 289 cm->current_video_frame++; |
| 294 } | 290 } |
| 295 | 291 |
| 296 pbi->ready_for_new_data = 0; | 292 pbi->ready_for_new_data = 0; |
| 297 pbi->last_time_stamp = time_stamp; | |
| 298 | 293 |
| 299 cm->error.setjmp = 0; | 294 cm->error.setjmp = 0; |
| 300 return retcode; | 295 return retcode; |
| 301 } | 296 } |
| 302 | 297 |
| 303 int vp9_get_raw_frame(VP9Decoder *pbi, YV12_BUFFER_CONFIG *sd, | 298 int vp9_get_raw_frame(VP9Decoder *pbi, YV12_BUFFER_CONFIG *sd, |
| 304 int64_t *time_stamp, int64_t *time_end_stamp, | |
| 305 vp9_ppflags_t *flags) { | 299 vp9_ppflags_t *flags) { |
| 306 int ret = -1; | 300 int ret = -1; |
| 307 #if !CONFIG_VP9_POSTPROC | 301 #if !CONFIG_VP9_POSTPROC |
| 308 (void)*flags; | 302 (void)*flags; |
| 309 #endif | 303 #endif |
| 310 | 304 |
| 311 if (pbi->ready_for_new_data == 1) | 305 if (pbi->ready_for_new_data == 1) |
| 312 return ret; | 306 return ret; |
| 313 | 307 |
| 314 /* no raw frame to show!!! */ | 308 /* no raw frame to show!!! */ |
| 315 if (pbi->common.show_frame == 0) | 309 if (pbi->common.show_frame == 0) |
| 316 return ret; | 310 return ret; |
| 317 | 311 |
| 318 pbi->ready_for_new_data = 1; | 312 pbi->ready_for_new_data = 1; |
| 319 *time_stamp = pbi->last_time_stamp; | |
| 320 *time_end_stamp = 0; | |
| 321 | 313 |
| 322 #if CONFIG_VP9_POSTPROC | 314 #if CONFIG_VP9_POSTPROC |
| 323 ret = vp9_post_proc_frame(&pbi->common, sd, flags); | 315 ret = vp9_post_proc_frame(&pbi->common, sd, flags); |
| 324 #else | 316 #else |
| 325 *sd = *pbi->common.frame_to_show; | 317 *sd = *pbi->common.frame_to_show; |
| 326 ret = 0; | 318 ret = 0; |
| 327 #endif /*!CONFIG_POSTPROC*/ | 319 #endif /*!CONFIG_POSTPROC*/ |
| 328 vp9_clear_system_state(); | 320 vp9_clear_system_state(); |
| 329 return ret; | 321 return ret; |
| 330 } | 322 } |
| OLD | NEW |