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 <stdlib.h> | 11 #include <stdlib.h> |
12 #include <string.h> | 12 #include <string.h> |
13 | 13 |
14 #include "./vpx_config.h" | 14 #include "./vpx_config.h" |
15 #include "./vpx_version.h" | 15 #include "./vpx_version.h" |
16 | 16 |
17 #include "vpx/internal/vpx_codec_internal.h" | 17 #include "vpx/internal/vpx_codec_internal.h" |
18 #include "vpx/vp8dx.h" | 18 #include "vpx/vp8dx.h" |
19 #include "vpx/vpx_decoder.h" | 19 #include "vpx/vpx_decoder.h" |
20 | 20 |
| 21 #include "vp9/common/vp9_alloccommon.h" |
21 #include "vp9/common/vp9_frame_buffers.h" | 22 #include "vp9/common/vp9_frame_buffers.h" |
| 23 #include "vp9/common/vp9_thread.h" |
22 | 24 |
23 #include "vp9/decoder/vp9_decoder.h" | 25 #include "vp9/decoder/vp9_decoder.h" |
24 #include "vp9/decoder/vp9_decodeframe.h" | 26 #include "vp9/decoder/vp9_decodeframe.h" |
25 #include "vp9/decoder/vp9_read_bit_buffer.h" | 27 #include "vp9/decoder/vp9_read_bit_buffer.h" |
26 | 28 |
27 #include "vp9/vp9_iface_common.h" | 29 #include "vp9/vp9_iface_common.h" |
28 | 30 |
29 #define VP9_CAP_POSTPROC (CONFIG_VP9_POSTPROC ? VPX_CODEC_CAP_POSTPROC : 0) | 31 #define VP9_CAP_POSTPROC (CONFIG_VP9_POSTPROC ? VPX_CODEC_CAP_POSTPROC : 0) |
30 | 32 |
31 typedef vpx_codec_stream_info_t vp9_stream_info_t; | 33 typedef vpx_codec_stream_info_t vp9_stream_info_t; |
32 | 34 |
| 35 // This limit is due to framebuffer numbers. |
| 36 // TODO(hkuang): Remove this limit after implementing ondemand framebuffers. |
| 37 #define FRAME_CACHE_SIZE 6 // Cache maximum 6 decoded frames. |
| 38 |
| 39 typedef struct cache_frame { |
| 40 int fb_idx; |
| 41 vpx_image_t img; |
| 42 } cache_frame; |
| 43 |
33 struct vpx_codec_alg_priv { | 44 struct vpx_codec_alg_priv { |
34 vpx_codec_priv_t base; | 45 vpx_codec_priv_t base; |
35 vpx_codec_dec_cfg_t cfg; | 46 vpx_codec_dec_cfg_t cfg; |
36 vp9_stream_info_t si; | 47 vp9_stream_info_t si; |
37 struct VP9Decoder *pbi; | |
38 int postproc_cfg_set; | 48 int postproc_cfg_set; |
39 vp8_postproc_cfg_t postproc_cfg; | 49 vp8_postproc_cfg_t postproc_cfg; |
40 vpx_decrypt_cb decrypt_cb; | 50 vpx_decrypt_cb decrypt_cb; |
41 void *decrypt_state; | 51 void *decrypt_state; |
42 vpx_image_t img; | 52 vpx_image_t img; |
43 int img_avail; | 53 int img_avail; |
44 int flushed; | 54 int flushed; |
45 int invert_tile_order; | 55 int invert_tile_order; |
| 56 int last_show_frame; // Index of last output frame. |
| 57 int byte_alignment; |
| 58 |
| 59 // Frame parallel related. |
46 int frame_parallel_decode; // frame-based threading. | 60 int frame_parallel_decode; // frame-based threading. |
47 int byte_alignment; | 61 VP9Worker *frame_workers; |
| 62 int num_frame_workers; |
| 63 int next_submit_worker_id; |
| 64 int last_submit_worker_id; |
| 65 int next_output_worker_id; |
| 66 int available_threads; |
| 67 cache_frame frame_cache[FRAME_CACHE_SIZE]; |
| 68 int frame_cache_write; |
| 69 int frame_cache_read; |
| 70 int num_cache_frames; |
| 71 int need_resync; // wait for key/intra-only frame |
| 72 // BufferPool that holds all reference frames. Shared by all the FrameWorkers. |
| 73 BufferPool *buffer_pool; |
48 | 74 |
49 // External frame buffer info to save for VP9 common. | 75 // External frame buffer info to save for VP9 common. |
50 void *ext_priv; // Private data associated with the external frame buffers. | 76 void *ext_priv; // Private data associated with the external frame buffers. |
51 vpx_get_frame_buffer_cb_fn_t get_ext_fb_cb; | 77 vpx_get_frame_buffer_cb_fn_t get_ext_fb_cb; |
52 vpx_release_frame_buffer_cb_fn_t release_ext_fb_cb; | 78 vpx_release_frame_buffer_cb_fn_t release_ext_fb_cb; |
53 }; | 79 }; |
54 | 80 |
55 static vpx_codec_err_t decoder_init(vpx_codec_ctx_t *ctx, | 81 static vpx_codec_err_t decoder_init(vpx_codec_ctx_t *ctx, |
56 vpx_codec_priv_enc_mr_cfg_t *data) { | 82 vpx_codec_priv_enc_mr_cfg_t *data) { |
57 // This function only allocates space for the vpx_codec_alg_priv_t | 83 // This function only allocates space for the vpx_codec_alg_priv_t |
58 // structure. More memory may be required at the time the stream | 84 // structure. More memory may be required at the time the stream |
59 // information becomes known. | 85 // information becomes known. |
60 (void)data; | 86 (void)data; |
61 | 87 |
62 if (!ctx->priv) { | 88 if (!ctx->priv) { |
63 vpx_codec_alg_priv_t *const priv = vpx_calloc(1, sizeof(*priv)); | 89 vpx_codec_alg_priv_t *const priv = vpx_calloc(1, sizeof(*priv)); |
64 if (priv == NULL) | 90 if (priv == NULL) |
65 return VPX_CODEC_MEM_ERROR; | 91 return VPX_CODEC_MEM_ERROR; |
66 | 92 |
67 ctx->priv = (vpx_codec_priv_t *)priv; | 93 ctx->priv = (vpx_codec_priv_t *)priv; |
68 ctx->priv->init_flags = ctx->init_flags; | 94 ctx->priv->init_flags = ctx->init_flags; |
69 | |
70 priv->si.sz = sizeof(priv->si); | 95 priv->si.sz = sizeof(priv->si); |
71 priv->flushed = 0; | 96 priv->flushed = 0; |
| 97 // Only do frame parallel decode when threads > 1. |
72 priv->frame_parallel_decode = | 98 priv->frame_parallel_decode = |
73 (ctx->init_flags & VPX_CODEC_USE_FRAME_THREADING); | 99 (ctx->config.dec && (ctx->config.dec->threads > 1) && |
74 priv->frame_parallel_decode = 0; // Disable for now | 100 (ctx->init_flags & VPX_CODEC_USE_FRAME_THREADING)) ? 1 : 0; |
75 | |
76 if (ctx->config.dec) { | 101 if (ctx->config.dec) { |
77 priv->cfg = *ctx->config.dec; | 102 priv->cfg = *ctx->config.dec; |
78 ctx->config.dec = &priv->cfg; | 103 ctx->config.dec = &priv->cfg; |
79 } | 104 } |
80 } | 105 } |
81 | 106 |
82 return VPX_CODEC_OK; | 107 return VPX_CODEC_OK; |
83 } | 108 } |
84 | 109 |
85 static vpx_codec_err_t decoder_destroy(vpx_codec_alg_priv_t *ctx) { | 110 static vpx_codec_err_t decoder_destroy(vpx_codec_alg_priv_t *ctx) { |
86 if (ctx->pbi) { | 111 if (ctx->frame_workers != NULL) { |
87 vp9_decoder_remove(ctx->pbi); | 112 int i; |
88 ctx->pbi = NULL; | 113 for (i = 0; i < ctx->num_frame_workers; ++i) { |
| 114 VP9Worker *const worker = &ctx->frame_workers[i]; |
| 115 FrameWorkerData *const frame_worker_data = |
| 116 (FrameWorkerData *)worker->data1; |
| 117 vp9_get_worker_interface()->end(worker); |
| 118 vp9_remove_common(&frame_worker_data->pbi->common); |
| 119 vp9_decoder_remove(frame_worker_data->pbi); |
| 120 vpx_free(frame_worker_data->scratch_buffer); |
| 121 #if CONFIG_MULTITHREAD |
| 122 pthread_mutex_destroy(&frame_worker_data->stats_mutex); |
| 123 pthread_cond_destroy(&frame_worker_data->stats_cond); |
| 124 #endif |
| 125 vpx_free(frame_worker_data); |
| 126 } |
| 127 #if CONFIG_MULTITHREAD |
| 128 pthread_mutex_destroy(&ctx->buffer_pool->pool_mutex); |
| 129 #endif |
89 } | 130 } |
90 | 131 |
| 132 if (ctx->buffer_pool) |
| 133 vp9_free_internal_frame_buffers(&ctx->buffer_pool->int_frame_buffers); |
| 134 |
| 135 vpx_free(ctx->frame_workers); |
| 136 vpx_free(ctx->buffer_pool); |
91 vpx_free(ctx); | 137 vpx_free(ctx); |
92 | |
93 return VPX_CODEC_OK; | 138 return VPX_CODEC_OK; |
94 } | 139 } |
95 | 140 |
96 static int parse_bitdepth_colorspace_sampling( | 141 static int parse_bitdepth_colorspace_sampling( |
97 BITSTREAM_PROFILE profile, struct vp9_read_bit_buffer *rb) { | 142 BITSTREAM_PROFILE profile, struct vp9_read_bit_buffer *rb) { |
98 const int sRGB = 7; | 143 vpx_color_space_t color_space; |
99 int colorspace; | |
100 if (profile >= PROFILE_2) | 144 if (profile >= PROFILE_2) |
101 rb->bit_offset += 1; // Bit-depth 10 or 12. | 145 rb->bit_offset += 1; // Bit-depth 10 or 12. |
102 colorspace = vp9_rb_read_literal(rb, 3); | 146 color_space = (vpx_color_space_t)vp9_rb_read_literal(rb, 3); |
103 if (colorspace != sRGB) { | 147 if (color_space != VPX_CS_SRGB) { |
104 rb->bit_offset += 1; // [16,235] (including xvycc) vs [0,255] range. | 148 rb->bit_offset += 1; // [16,235] (including xvycc) vs [0,255] range. |
105 if (profile == PROFILE_1 || profile == PROFILE_3) { | 149 if (profile == PROFILE_1 || profile == PROFILE_3) { |
106 rb->bit_offset += 2; // subsampling x/y. | 150 rb->bit_offset += 2; // subsampling x/y. |
107 rb->bit_offset += 1; // unused. | 151 rb->bit_offset += 1; // unused. |
108 } | 152 } |
109 } else { | 153 } else { |
110 if (profile == PROFILE_1 || profile == PROFILE_3) { | 154 if (profile == PROFILE_1 || profile == PROFILE_3) { |
111 rb->bit_offset += 1; // unused | 155 rb->bit_offset += 1; // unused |
112 } else { | 156 } else { |
113 // RGB is only available in version 1. | 157 // RGB is only available in version 1. |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 vpx_codec_stream_info_t *si) { | 249 vpx_codec_stream_info_t *si) { |
206 const size_t sz = (si->sz >= sizeof(vp9_stream_info_t)) | 250 const size_t sz = (si->sz >= sizeof(vp9_stream_info_t)) |
207 ? sizeof(vp9_stream_info_t) | 251 ? sizeof(vp9_stream_info_t) |
208 : sizeof(vpx_codec_stream_info_t); | 252 : sizeof(vpx_codec_stream_info_t); |
209 memcpy(si, &ctx->si, sz); | 253 memcpy(si, &ctx->si, sz); |
210 si->sz = (unsigned int)sz; | 254 si->sz = (unsigned int)sz; |
211 | 255 |
212 return VPX_CODEC_OK; | 256 return VPX_CODEC_OK; |
213 } | 257 } |
214 | 258 |
| 259 static void set_error_detail(vpx_codec_alg_priv_t *ctx, |
| 260 const char *const error) { |
| 261 ctx->base.err_detail = error; |
| 262 } |
| 263 |
215 static vpx_codec_err_t update_error_state(vpx_codec_alg_priv_t *ctx, | 264 static vpx_codec_err_t update_error_state(vpx_codec_alg_priv_t *ctx, |
216 const struct vpx_internal_error_info *error) { | 265 const struct vpx_internal_error_info *error) { |
217 if (error->error_code) | 266 if (error->error_code) |
218 ctx->base.err_detail = error->has_detail ? error->detail : NULL; | 267 set_error_detail(ctx, error->has_detail ? error->detail : NULL); |
219 | 268 |
220 return error->error_code; | 269 return error->error_code; |
221 } | 270 } |
222 | 271 |
223 static void init_buffer_callbacks(vpx_codec_alg_priv_t *ctx) { | 272 static void init_buffer_callbacks(vpx_codec_alg_priv_t *ctx) { |
224 VP9_COMMON *const cm = &ctx->pbi->common; | 273 int i; |
225 | 274 |
226 cm->new_fb_idx = -1; | 275 for (i = 0; i < ctx->num_frame_workers; ++i) { |
227 cm->byte_alignment = ctx->byte_alignment; | 276 VP9Worker *const worker = &ctx->frame_workers[i]; |
| 277 FrameWorkerData *const frame_worker_data = (FrameWorkerData *)worker->data1; |
| 278 VP9_COMMON *const cm = &frame_worker_data->pbi->common; |
| 279 BufferPool *const pool = cm->buffer_pool; |
228 | 280 |
229 if (ctx->get_ext_fb_cb != NULL && ctx->release_ext_fb_cb != NULL) { | 281 cm->new_fb_idx = -1; |
230 cm->get_fb_cb = ctx->get_ext_fb_cb; | 282 cm->byte_alignment = ctx->byte_alignment; |
231 cm->release_fb_cb = ctx->release_ext_fb_cb; | |
232 cm->cb_priv = ctx->ext_priv; | |
233 } else { | |
234 cm->get_fb_cb = vp9_get_frame_buffer; | |
235 cm->release_fb_cb = vp9_release_frame_buffer; | |
236 | 283 |
237 if (vp9_alloc_internal_frame_buffers(&cm->int_frame_buffers)) | 284 if (ctx->get_ext_fb_cb != NULL && ctx->release_ext_fb_cb != NULL) { |
238 vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR, | 285 pool->get_fb_cb = ctx->get_ext_fb_cb; |
239 "Failed to initialize internal frame buffers"); | 286 pool->release_fb_cb = ctx->release_ext_fb_cb; |
| 287 pool->cb_priv = ctx->ext_priv; |
| 288 } else { |
| 289 pool->get_fb_cb = vp9_get_frame_buffer; |
| 290 pool->release_fb_cb = vp9_release_frame_buffer; |
240 | 291 |
241 cm->cb_priv = &cm->int_frame_buffers; | 292 if (vp9_alloc_internal_frame_buffers(&pool->int_frame_buffers)) |
| 293 vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR, |
| 294 "Failed to initialize internal frame buffers"); |
| 295 |
| 296 pool->cb_priv = &pool->int_frame_buffers; |
| 297 } |
242 } | 298 } |
243 } | 299 } |
244 | 300 |
245 static void set_default_ppflags(vp8_postproc_cfg_t *cfg) { | 301 static void set_default_ppflags(vp8_postproc_cfg_t *cfg) { |
246 cfg->post_proc_flag = VP8_DEBLOCK | VP8_DEMACROBLOCK; | 302 cfg->post_proc_flag = VP8_DEBLOCK | VP8_DEMACROBLOCK; |
247 cfg->deblocking_level = 4; | 303 cfg->deblocking_level = 4; |
248 cfg->noise_level = 0; | 304 cfg->noise_level = 0; |
249 } | 305 } |
250 | 306 |
251 static void set_ppflags(const vpx_codec_alg_priv_t *ctx, | 307 static void set_ppflags(const vpx_codec_alg_priv_t *ctx, |
252 vp9_ppflags_t *flags) { | 308 vp9_ppflags_t *flags) { |
253 flags->post_proc_flag = | 309 flags->post_proc_flag = |
254 ctx->postproc_cfg.post_proc_flag; | 310 ctx->postproc_cfg.post_proc_flag; |
255 | 311 |
256 flags->deblocking_level = ctx->postproc_cfg.deblocking_level; | 312 flags->deblocking_level = ctx->postproc_cfg.deblocking_level; |
257 flags->noise_level = ctx->postproc_cfg.noise_level; | 313 flags->noise_level = ctx->postproc_cfg.noise_level; |
258 } | 314 } |
259 | 315 |
260 static void init_decoder(vpx_codec_alg_priv_t *ctx) { | 316 static int frame_worker_hook(void *arg1, void *arg2) { |
261 ctx->pbi = vp9_decoder_create(); | 317 FrameWorkerData *const frame_worker_data = (FrameWorkerData *)arg1; |
262 if (ctx->pbi == NULL) | 318 const uint8_t *data = frame_worker_data->data; |
263 return; | 319 (void)arg2; |
264 | 320 |
265 ctx->pbi->max_threads = ctx->cfg.threads; | 321 frame_worker_data->result = |
266 ctx->pbi->inv_tile_order = ctx->invert_tile_order; | 322 vp9_receive_compressed_data(frame_worker_data->pbi, |
267 ctx->pbi->frame_parallel_decode = ctx->frame_parallel_decode; | 323 frame_worker_data->data_size, |
| 324 &data); |
| 325 frame_worker_data->data_end = data; |
| 326 |
| 327 if (frame_worker_data->pbi->frame_parallel_decode) { |
| 328 // In frame parallel decoding, a worker thread must successfully decode all |
| 329 // the compressed data. |
| 330 if (frame_worker_data->result != 0 || |
| 331 frame_worker_data->data + frame_worker_data->data_size - 1 > data) { |
| 332 VP9Worker *const worker = frame_worker_data->pbi->frame_worker_owner; |
| 333 BufferPool *const pool = frame_worker_data->pbi->common.buffer_pool; |
| 334 // Signal all the other threads that are waiting for this frame. |
| 335 vp9_frameworker_lock_stats(worker); |
| 336 frame_worker_data->frame_context_ready = 1; |
| 337 lock_buffer_pool(pool); |
| 338 frame_worker_data->pbi->cur_buf->buf.corrupted = 1; |
| 339 unlock_buffer_pool(pool); |
| 340 frame_worker_data->pbi->need_resync = 1; |
| 341 vp9_frameworker_signal_stats(worker); |
| 342 vp9_frameworker_unlock_stats(worker); |
| 343 return 0; |
| 344 } |
| 345 } else if (frame_worker_data->result != 0) { |
| 346 // Check decode result in serial decode. |
| 347 frame_worker_data->pbi->cur_buf->buf.corrupted = 1; |
| 348 frame_worker_data->pbi->need_resync = 1; |
| 349 } |
| 350 return !frame_worker_data->result; |
| 351 } |
| 352 |
| 353 static vpx_codec_err_t init_decoder(vpx_codec_alg_priv_t *ctx) { |
| 354 int i; |
| 355 const VP9WorkerInterface *const winterface = vp9_get_worker_interface(); |
| 356 |
| 357 ctx->last_show_frame = -1; |
| 358 ctx->next_submit_worker_id = 0; |
| 359 ctx->last_submit_worker_id = 0; |
| 360 ctx->next_output_worker_id = 0; |
| 361 ctx->frame_cache_read = 0; |
| 362 ctx->frame_cache_write = 0; |
| 363 ctx->num_cache_frames = 0; |
| 364 ctx->need_resync = 1; |
| 365 ctx->num_frame_workers = |
| 366 (ctx->frame_parallel_decode == 1) ? ctx->cfg.threads: 1; |
| 367 if (ctx->num_frame_workers > MAX_DECODE_THREADS) |
| 368 ctx->num_frame_workers = MAX_DECODE_THREADS; |
| 369 ctx->available_threads = ctx->num_frame_workers; |
| 370 ctx->flushed = 0; |
| 371 |
| 372 ctx->buffer_pool = (BufferPool *)vpx_calloc(1, sizeof(BufferPool)); |
| 373 if (ctx->buffer_pool == NULL) |
| 374 return VPX_CODEC_MEM_ERROR; |
| 375 |
| 376 #if CONFIG_MULTITHREAD |
| 377 if (pthread_mutex_init(&ctx->buffer_pool->pool_mutex, NULL)) { |
| 378 set_error_detail(ctx, "Failed to allocate buffer pool mutex"); |
| 379 return VPX_CODEC_MEM_ERROR; |
| 380 } |
| 381 #endif |
| 382 |
| 383 ctx->frame_workers = (VP9Worker *) |
| 384 vpx_malloc(ctx->num_frame_workers * sizeof(*ctx->frame_workers)); |
| 385 if (ctx->frame_workers == NULL) { |
| 386 set_error_detail(ctx, "Failed to allocate frame_workers"); |
| 387 return VPX_CODEC_MEM_ERROR; |
| 388 } |
| 389 |
| 390 for (i = 0; i < ctx->num_frame_workers; ++i) { |
| 391 VP9Worker *const worker = &ctx->frame_workers[i]; |
| 392 FrameWorkerData *frame_worker_data = NULL; |
| 393 winterface->init(worker); |
| 394 worker->data1 = vpx_memalign(32, sizeof(FrameWorkerData)); |
| 395 if (worker->data1 == NULL) { |
| 396 set_error_detail(ctx, "Failed to allocate frame_worker_data"); |
| 397 return VPX_CODEC_MEM_ERROR; |
| 398 } |
| 399 frame_worker_data = (FrameWorkerData *)worker->data1; |
| 400 frame_worker_data->pbi = vp9_decoder_create(ctx->buffer_pool); |
| 401 if (frame_worker_data->pbi == NULL) { |
| 402 set_error_detail(ctx, "Failed to allocate frame_worker_data"); |
| 403 return VPX_CODEC_MEM_ERROR; |
| 404 } |
| 405 frame_worker_data->pbi->frame_worker_owner = worker; |
| 406 frame_worker_data->worker_id = i; |
| 407 frame_worker_data->scratch_buffer = NULL; |
| 408 frame_worker_data->scratch_buffer_size = 0; |
| 409 frame_worker_data->frame_context_ready = 0; |
| 410 frame_worker_data->received_frame = 0; |
| 411 #if CONFIG_MULTITHREAD |
| 412 if (pthread_mutex_init(&frame_worker_data->stats_mutex, NULL)) { |
| 413 set_error_detail(ctx, "Failed to allocate frame_worker_data mutex"); |
| 414 return VPX_CODEC_MEM_ERROR; |
| 415 } |
| 416 |
| 417 if (pthread_cond_init(&frame_worker_data->stats_cond, NULL)) { |
| 418 set_error_detail(ctx, "Failed to allocate frame_worker_data cond"); |
| 419 return VPX_CODEC_MEM_ERROR; |
| 420 } |
| 421 #endif |
| 422 // If decoding in serial mode, FrameWorker thread could create tile worker |
| 423 // thread or loopfilter thread. |
| 424 frame_worker_data->pbi->max_threads = |
| 425 (ctx->frame_parallel_decode == 0) ? ctx->cfg.threads : 0; |
| 426 |
| 427 frame_worker_data->pbi->inv_tile_order = ctx->invert_tile_order; |
| 428 frame_worker_data->pbi->frame_parallel_decode = ctx->frame_parallel_decode; |
| 429 frame_worker_data->pbi->common.frame_parallel_decode = |
| 430 ctx->frame_parallel_decode; |
| 431 worker->hook = (VP9WorkerHook)frame_worker_hook; |
| 432 if (!winterface->reset(worker)) { |
| 433 set_error_detail(ctx, "Frame Worker thread creation failed"); |
| 434 return VPX_CODEC_MEM_ERROR; |
| 435 } |
| 436 } |
268 | 437 |
269 // If postprocessing was enabled by the application and a | 438 // If postprocessing was enabled by the application and a |
270 // configuration has not been provided, default it. | 439 // configuration has not been provided, default it. |
271 if (!ctx->postproc_cfg_set && | 440 if (!ctx->postproc_cfg_set && |
272 (ctx->base.init_flags & VPX_CODEC_USE_POSTPROC)) | 441 (ctx->base.init_flags & VPX_CODEC_USE_POSTPROC)) |
273 set_default_ppflags(&ctx->postproc_cfg); | 442 set_default_ppflags(&ctx->postproc_cfg); |
274 | 443 |
275 init_buffer_callbacks(ctx); | 444 init_buffer_callbacks(ctx); |
| 445 |
| 446 return VPX_CODEC_OK; |
| 447 } |
| 448 |
| 449 static INLINE void check_resync(vpx_codec_alg_priv_t *const ctx, |
| 450 const VP9Decoder *const pbi) { |
| 451 // Clear resync flag if worker got a key frame or intra only frame. |
| 452 if (ctx->need_resync == 1 && pbi->need_resync == 0 && |
| 453 (pbi->common.intra_only || pbi->common.frame_type == KEY_FRAME)) |
| 454 ctx->need_resync = 0; |
276 } | 455 } |
277 | 456 |
278 static vpx_codec_err_t decode_one(vpx_codec_alg_priv_t *ctx, | 457 static vpx_codec_err_t decode_one(vpx_codec_alg_priv_t *ctx, |
279 const uint8_t **data, unsigned int data_sz, | 458 const uint8_t **data, unsigned int data_sz, |
280 void *user_priv, int64_t deadline) { | 459 void *user_priv, int64_t deadline) { |
281 YV12_BUFFER_CONFIG sd; | |
282 vp9_ppflags_t flags = {0, 0, 0}; | 460 vp9_ppflags_t flags = {0, 0, 0}; |
283 VP9_COMMON *cm = NULL; | 461 const VP9WorkerInterface *const winterface = vp9_get_worker_interface(); |
284 | |
285 (void)deadline; | 462 (void)deadline; |
286 | 463 |
287 vp9_zero(sd); | |
288 ctx->img_avail = 0; | |
289 | |
290 // Determine the stream parameters. Note that we rely on peek_si to | 464 // Determine the stream parameters. Note that we rely on peek_si to |
291 // validate that we have a buffer that does not wrap around the top | 465 // validate that we have a buffer that does not wrap around the top |
292 // of the heap. | 466 // of the heap. |
293 if (!ctx->si.h) { | 467 if (!ctx->si.h) { |
294 int is_intra_only = 0; | 468 int is_intra_only = 0; |
295 const vpx_codec_err_t res = | 469 const vpx_codec_err_t res = |
296 decoder_peek_si_internal(*data, data_sz, &ctx->si, &is_intra_only, | 470 decoder_peek_si_internal(*data, data_sz, &ctx->si, &is_intra_only, |
297 ctx->decrypt_cb, ctx->decrypt_state); | 471 ctx->decrypt_cb, ctx->decrypt_state); |
298 if (res != VPX_CODEC_OK) | 472 if (res != VPX_CODEC_OK) |
299 return res; | 473 return res; |
300 | 474 |
301 if (!ctx->si.is_kf && !is_intra_only) | 475 if (!ctx->si.is_kf && !is_intra_only) |
302 return VPX_CODEC_ERROR; | 476 return VPX_CODEC_ERROR; |
303 } | 477 } |
304 | 478 |
305 // Initialize the decoder instance on the first frame | 479 if (!ctx->frame_parallel_decode) { |
306 if (ctx->pbi == NULL) { | 480 VP9Worker *const worker = ctx->frame_workers; |
307 init_decoder(ctx); | 481 FrameWorkerData *const frame_worker_data = (FrameWorkerData *)worker->data1; |
308 if (ctx->pbi == NULL) | 482 frame_worker_data->data = *data; |
309 return VPX_CODEC_ERROR; | 483 frame_worker_data->data_size = data_sz; |
| 484 frame_worker_data->user_priv = user_priv; |
| 485 frame_worker_data->received_frame = 1; |
| 486 |
| 487 // Set these even if already initialized. The caller may have changed the |
| 488 // decrypt config between frames. |
| 489 frame_worker_data->pbi->decrypt_cb = ctx->decrypt_cb; |
| 490 frame_worker_data->pbi->decrypt_state = ctx->decrypt_state; |
| 491 |
| 492 worker->had_error = 0; |
| 493 winterface->execute(worker); |
| 494 |
| 495 // Update data pointer after decode. |
| 496 *data = frame_worker_data->data_end; |
| 497 |
| 498 if (worker->had_error) |
| 499 return update_error_state(ctx, &frame_worker_data->pbi->common.error); |
| 500 |
| 501 check_resync(ctx, frame_worker_data->pbi); |
| 502 } else { |
| 503 const VP9WorkerInterface *const winterface = vp9_get_worker_interface(); |
| 504 VP9Worker *const worker = &ctx->frame_workers[ctx->next_submit_worker_id]; |
| 505 FrameWorkerData *const frame_worker_data = (FrameWorkerData *)worker->data1; |
| 506 // Copy context from last worker thread to next worker thread. |
| 507 if (ctx->next_submit_worker_id != ctx->last_submit_worker_id) |
| 508 vp9_frameworker_copy_context( |
| 509 &ctx->frame_workers[ctx->next_submit_worker_id], |
| 510 &ctx->frame_workers[ctx->last_submit_worker_id]); |
| 511 |
| 512 frame_worker_data->pbi->ready_for_new_data = 0; |
| 513 // Copy the compressed data into worker's internal buffer. |
| 514 // TODO(hkuang): Will all the workers allocate the same size |
| 515 // as the size of the first intra frame be better? This will |
| 516 // avoid too many deallocate and allocate. |
| 517 if (frame_worker_data->scratch_buffer_size < data_sz) { |
| 518 frame_worker_data->scratch_buffer = |
| 519 (uint8_t *)vpx_realloc(frame_worker_data->scratch_buffer, data_sz); |
| 520 if (frame_worker_data->scratch_buffer == NULL) { |
| 521 set_error_detail(ctx, "Failed to reallocate scratch buffer"); |
| 522 return VPX_CODEC_MEM_ERROR; |
| 523 } |
| 524 frame_worker_data->scratch_buffer_size = data_sz; |
| 525 } |
| 526 frame_worker_data->data_size = data_sz; |
| 527 vpx_memcpy(frame_worker_data->scratch_buffer, *data, data_sz); |
| 528 |
| 529 frame_worker_data->frame_decoded = 0; |
| 530 frame_worker_data->frame_context_ready = 0; |
| 531 frame_worker_data->received_frame = 1; |
| 532 frame_worker_data->data = frame_worker_data->scratch_buffer; |
| 533 frame_worker_data->user_priv = user_priv; |
| 534 |
| 535 if (ctx->next_submit_worker_id != ctx->last_submit_worker_id) |
| 536 ctx->last_submit_worker_id = |
| 537 (ctx->last_submit_worker_id + 1) % ctx->num_frame_workers; |
| 538 |
| 539 ctx->next_submit_worker_id = |
| 540 (ctx->next_submit_worker_id + 1) % ctx->num_frame_workers; |
| 541 --ctx->available_threads; |
| 542 worker->had_error = 0; |
| 543 winterface->launch(worker); |
310 } | 544 } |
311 | 545 |
312 // Set these even if already initialized. The caller may have changed the | |
313 // decrypt config between frames. | |
314 ctx->pbi->decrypt_cb = ctx->decrypt_cb; | |
315 ctx->pbi->decrypt_state = ctx->decrypt_state; | |
316 | |
317 cm = &ctx->pbi->common; | |
318 | |
319 if (vp9_receive_compressed_data(ctx->pbi, data_sz, data)) | |
320 return update_error_state(ctx, &cm->error); | |
321 | |
322 if (ctx->base.init_flags & VPX_CODEC_USE_POSTPROC) | 546 if (ctx->base.init_flags & VPX_CODEC_USE_POSTPROC) |
323 set_ppflags(ctx, &flags); | 547 set_ppflags(ctx, &flags); |
324 | 548 |
325 if (vp9_get_raw_frame(ctx->pbi, &sd, &flags)) | 549 return VPX_CODEC_OK; |
326 return update_error_state(ctx, &cm->error); | 550 } |
327 | 551 |
328 yuvconfig2image(&ctx->img, &sd, user_priv); | 552 static void wait_worker_and_cache_frame(vpx_codec_alg_priv_t *ctx) { |
329 ctx->img.fb_priv = cm->frame_bufs[cm->new_fb_idx].raw_frame_buffer.priv; | 553 YV12_BUFFER_CONFIG sd; |
330 ctx->img_avail = 1; | 554 vp9_ppflags_t flags = {0, 0, 0}; |
| 555 const VP9WorkerInterface *const winterface = vp9_get_worker_interface(); |
| 556 VP9Worker *const worker = &ctx->frame_workers[ctx->next_output_worker_id]; |
| 557 FrameWorkerData *const frame_worker_data = (FrameWorkerData *)worker->data1; |
| 558 ctx->next_output_worker_id = |
| 559 (ctx->next_output_worker_id + 1) % ctx->num_frame_workers; |
| 560 // TODO(hkuang): Add worker error handling here. |
| 561 winterface->sync(worker); |
| 562 frame_worker_data->received_frame = 0; |
| 563 ++ctx->available_threads; |
331 | 564 |
332 return VPX_CODEC_OK; | 565 check_resync(ctx, frame_worker_data->pbi); |
| 566 |
| 567 if (vp9_get_raw_frame(frame_worker_data->pbi, &sd, &flags) == 0) { |
| 568 VP9_COMMON *const cm = &frame_worker_data->pbi->common; |
| 569 RefCntBuffer *const frame_bufs = cm->buffer_pool->frame_bufs; |
| 570 ctx->frame_cache[ctx->frame_cache_write].fb_idx = cm->new_fb_idx; |
| 571 yuvconfig2image(&ctx->frame_cache[ctx->frame_cache_write].img, &sd, |
| 572 frame_worker_data->user_priv); |
| 573 ctx->frame_cache[ctx->frame_cache_write].img.fb_priv = |
| 574 frame_bufs[cm->new_fb_idx].raw_frame_buffer.priv; |
| 575 ctx->frame_cache_write = |
| 576 (ctx->frame_cache_write + 1) % FRAME_CACHE_SIZE; |
| 577 ++ctx->num_cache_frames; |
| 578 } |
333 } | 579 } |
334 | 580 |
335 static vpx_codec_err_t decoder_decode(vpx_codec_alg_priv_t *ctx, | 581 static vpx_codec_err_t decoder_decode(vpx_codec_alg_priv_t *ctx, |
336 const uint8_t *data, unsigned int data_sz, | 582 const uint8_t *data, unsigned int data_sz, |
337 void *user_priv, long deadline) { | 583 void *user_priv, long deadline) { |
338 const uint8_t *data_start = data; | 584 const uint8_t *data_start = data; |
339 const uint8_t * const data_end = data + data_sz; | 585 const uint8_t * const data_end = data + data_sz; |
340 vpx_codec_err_t res; | 586 vpx_codec_err_t res; |
341 uint32_t frame_sizes[8]; | 587 uint32_t frame_sizes[8]; |
342 int frame_count; | 588 int frame_count; |
343 | 589 |
344 if (data == NULL && data_sz == 0) { | 590 if (data == NULL && data_sz == 0) { |
345 ctx->flushed = 1; | 591 ctx->flushed = 1; |
346 return VPX_CODEC_OK; | 592 return VPX_CODEC_OK; |
347 } | 593 } |
348 | 594 |
349 // Reset flushed when receiving a valid frame. | 595 // Reset flushed when receiving a valid frame. |
350 ctx->flushed = 0; | 596 ctx->flushed = 0; |
351 | 597 |
| 598 // Initialize the decoder workers on the first frame. |
| 599 if (ctx->frame_workers == NULL) { |
| 600 const vpx_codec_err_t res = init_decoder(ctx); |
| 601 if (res != VPX_CODEC_OK) |
| 602 return res; |
| 603 } |
| 604 |
352 res = vp9_parse_superframe_index(data, data_sz, frame_sizes, &frame_count, | 605 res = vp9_parse_superframe_index(data, data_sz, frame_sizes, &frame_count, |
353 ctx->decrypt_cb, ctx->decrypt_state); | 606 ctx->decrypt_cb, ctx->decrypt_state); |
354 if (res != VPX_CODEC_OK) | 607 if (res != VPX_CODEC_OK) |
355 return res; | 608 return res; |
356 | 609 |
357 if (ctx->frame_parallel_decode) { | 610 if (ctx->frame_parallel_decode) { |
358 // Decode in frame parallel mode. When decoding in this mode, the frame | 611 // Decode in frame parallel mode. When decoding in this mode, the frame |
359 // passed to the decoder must be either a normal frame or a superframe with | 612 // passed to the decoder must be either a normal frame or a superframe with |
360 // superframe index so the decoder could get each frame's start position | 613 // superframe index so the decoder could get each frame's start position |
361 // in the superframe. | 614 // in the superframe. |
362 if (frame_count > 0) { | 615 if (frame_count > 0) { |
363 int i; | 616 int i; |
364 | 617 |
365 for (i = 0; i < frame_count; ++i) { | 618 for (i = 0; i < frame_count; ++i) { |
366 const uint8_t *data_start_copy = data_start; | 619 const uint8_t *data_start_copy = data_start; |
367 const uint32_t frame_size = frame_sizes[i]; | 620 const uint32_t frame_size = frame_sizes[i]; |
368 vpx_codec_err_t res; | |
369 if (data_start < data | 621 if (data_start < data |
370 || frame_size > (uint32_t) (data_end - data_start)) { | 622 || frame_size > (uint32_t) (data_end - data_start)) { |
371 ctx->base.err_detail = "Invalid frame size in index"; | 623 set_error_detail(ctx, "Invalid frame size in index"); |
372 return VPX_CODEC_CORRUPT_FRAME; | 624 return VPX_CODEC_CORRUPT_FRAME; |
373 } | 625 } |
374 | 626 |
| 627 if (ctx->available_threads == 0) { |
| 628 // No more threads for decoding. Wait until the next output worker |
| 629 // finishes decoding. Then copy the decoded frame into cache. |
| 630 if (ctx->num_cache_frames < FRAME_CACHE_SIZE) { |
| 631 wait_worker_and_cache_frame(ctx); |
| 632 } else { |
| 633 // TODO(hkuang): Add unit test to test this path. |
| 634 set_error_detail(ctx, "Frame output cache is full."); |
| 635 return VPX_CODEC_ERROR; |
| 636 } |
| 637 } |
| 638 |
375 res = decode_one(ctx, &data_start_copy, frame_size, user_priv, | 639 res = decode_one(ctx, &data_start_copy, frame_size, user_priv, |
376 deadline); | 640 deadline); |
377 if (res != VPX_CODEC_OK) | 641 if (res != VPX_CODEC_OK) |
378 return res; | 642 return res; |
379 | |
380 data_start += frame_size; | 643 data_start += frame_size; |
381 } | 644 } |
382 } else { | 645 } else { |
383 res = decode_one(ctx, &data_start, data_sz, user_priv, deadline); | 646 if (ctx->available_threads == 0) { |
| 647 // No more threads for decoding. Wait until the next output worker |
| 648 // finishes decoding. Then copy the decoded frame into cache. |
| 649 if (ctx->num_cache_frames < FRAME_CACHE_SIZE) { |
| 650 wait_worker_and_cache_frame(ctx); |
| 651 } else { |
| 652 // TODO(hkuang): Add unit test to test this path. |
| 653 set_error_detail(ctx, "Frame output cache is full."); |
| 654 return VPX_CODEC_ERROR; |
| 655 } |
| 656 } |
| 657 |
| 658 res = decode_one(ctx, &data, data_sz, user_priv, deadline); |
384 if (res != VPX_CODEC_OK) | 659 if (res != VPX_CODEC_OK) |
385 return res; | 660 return res; |
386 | |
387 // Extra data detected after the frame. | |
388 if (data_start < data_end - 1) { | |
389 ctx->base.err_detail = "Fail to decode frame in parallel mode"; | |
390 return VPX_CODEC_INCAPABLE; | |
391 } | |
392 } | 661 } |
393 } else { | 662 } else { |
394 // Decode in serial mode. | 663 // Decode in serial mode. |
395 if (frame_count > 0) { | 664 if (frame_count > 0) { |
396 int i; | 665 int i; |
397 | 666 |
398 for (i = 0; i < frame_count; ++i) { | 667 for (i = 0; i < frame_count; ++i) { |
399 const uint8_t *data_start_copy = data_start; | 668 const uint8_t *data_start_copy = data_start; |
400 const uint32_t frame_size = frame_sizes[i]; | 669 const uint32_t frame_size = frame_sizes[i]; |
401 vpx_codec_err_t res; | 670 vpx_codec_err_t res; |
402 if (data_start < data | 671 if (data_start < data |
403 || frame_size > (uint32_t) (data_end - data_start)) { | 672 || frame_size > (uint32_t) (data_end - data_start)) { |
404 ctx->base.err_detail = "Invalid frame size in index"; | 673 set_error_detail(ctx, "Invalid frame size in index"); |
405 return VPX_CODEC_CORRUPT_FRAME; | 674 return VPX_CODEC_CORRUPT_FRAME; |
406 } | 675 } |
407 | 676 |
408 res = decode_one(ctx, &data_start_copy, frame_size, user_priv, | 677 res = decode_one(ctx, &data_start_copy, frame_size, user_priv, |
409 deadline); | 678 deadline); |
410 if (res != VPX_CODEC_OK) | 679 if (res != VPX_CODEC_OK) |
411 return res; | 680 return res; |
412 | 681 |
413 data_start += frame_size; | 682 data_start += frame_size; |
414 } | 683 } |
(...skipping 10 matching lines...) Expand all Loading... |
425 const uint8_t marker = read_marker(ctx->decrypt_cb, | 694 const uint8_t marker = read_marker(ctx->decrypt_cb, |
426 ctx->decrypt_state, data_start); | 695 ctx->decrypt_state, data_start); |
427 if (marker) | 696 if (marker) |
428 break; | 697 break; |
429 ++data_start; | 698 ++data_start; |
430 } | 699 } |
431 } | 700 } |
432 } | 701 } |
433 } | 702 } |
434 | 703 |
435 return VPX_CODEC_OK; | 704 return res; |
| 705 } |
| 706 |
| 707 static void release_last_output_frame(vpx_codec_alg_priv_t *ctx) { |
| 708 RefCntBuffer *const frame_bufs = ctx->buffer_pool->frame_bufs; |
| 709 // Decrease reference count of last output frame in frame parallel mode. |
| 710 if (ctx->frame_parallel_decode && ctx->last_show_frame >= 0) { |
| 711 BufferPool *const pool = ctx->buffer_pool; |
| 712 lock_buffer_pool(pool); |
| 713 decrease_ref_count(ctx->last_show_frame, frame_bufs, pool); |
| 714 unlock_buffer_pool(pool); |
| 715 } |
436 } | 716 } |
437 | 717 |
438 static vpx_image_t *decoder_get_frame(vpx_codec_alg_priv_t *ctx, | 718 static vpx_image_t *decoder_get_frame(vpx_codec_alg_priv_t *ctx, |
439 vpx_codec_iter_t *iter) { | 719 vpx_codec_iter_t *iter) { |
440 vpx_image_t *img = NULL; | 720 vpx_image_t *img = NULL; |
441 | 721 |
442 if (ctx->img_avail) { | 722 // Only return frame when all the cpu are busy or |
443 // iter acts as a flip flop, so an image is only returned on the first | 723 // application fluhsed the decoder in frame parallel decode. |
444 // call to get_frame. | 724 if (ctx->frame_parallel_decode && ctx->available_threads > 0 && |
445 if (!(*iter)) { | 725 !ctx->flushed) { |
446 img = &ctx->img; | 726 return NULL; |
447 *iter = img; | |
448 } | |
449 } | 727 } |
450 ctx->img_avail = 0; | |
451 | 728 |
452 return img; | 729 // Output the frames in the cache first. |
| 730 if (ctx->num_cache_frames > 0) { |
| 731 release_last_output_frame(ctx); |
| 732 ctx->last_show_frame = ctx->frame_cache[ctx->frame_cache_read].fb_idx; |
| 733 if (ctx->need_resync) |
| 734 return NULL; |
| 735 img = &ctx->frame_cache[ctx->frame_cache_read].img; |
| 736 ctx->frame_cache_read = (ctx->frame_cache_read + 1) % FRAME_CACHE_SIZE; |
| 737 --ctx->num_cache_frames; |
| 738 return img; |
| 739 } |
| 740 |
| 741 // iter acts as a flip flop, so an image is only returned on the first |
| 742 // call to get_frame. |
| 743 if (*iter == NULL && ctx->frame_workers != NULL) { |
| 744 do { |
| 745 YV12_BUFFER_CONFIG sd; |
| 746 vp9_ppflags_t flags = {0, 0, 0}; |
| 747 const VP9WorkerInterface *const winterface = vp9_get_worker_interface(); |
| 748 VP9Worker *const worker = |
| 749 &ctx->frame_workers[ctx->next_output_worker_id]; |
| 750 FrameWorkerData *const frame_worker_data = |
| 751 (FrameWorkerData *)worker->data1; |
| 752 ctx->next_output_worker_id = |
| 753 (ctx->next_output_worker_id + 1) % ctx->num_frame_workers; |
| 754 // Wait for the frame from worker thread. |
| 755 if (winterface->sync(worker)) { |
| 756 // Check if worker has received any frames. |
| 757 if (frame_worker_data->received_frame == 1) { |
| 758 ++ctx->available_threads; |
| 759 frame_worker_data->received_frame = 0; |
| 760 check_resync(ctx, frame_worker_data->pbi); |
| 761 } |
| 762 if (vp9_get_raw_frame(frame_worker_data->pbi, &sd, &flags) == 0) { |
| 763 VP9_COMMON *const cm = &frame_worker_data->pbi->common; |
| 764 RefCntBuffer *const frame_bufs = cm->buffer_pool->frame_bufs; |
| 765 release_last_output_frame(ctx); |
| 766 ctx->last_show_frame = frame_worker_data->pbi->common.new_fb_idx; |
| 767 if (ctx->need_resync) |
| 768 return NULL; |
| 769 yuvconfig2image(&ctx->img, &sd, frame_worker_data->user_priv); |
| 770 ctx->img.fb_priv = frame_bufs[cm->new_fb_idx].raw_frame_buffer.priv; |
| 771 img = &ctx->img; |
| 772 return img; |
| 773 } |
| 774 } else { |
| 775 // Decoding failed. Release the worker thread. |
| 776 frame_worker_data->received_frame = 0; |
| 777 ++ctx->available_threads; |
| 778 ctx->need_resync = 1; |
| 779 if (ctx->flushed != 1) |
| 780 return NULL; |
| 781 } |
| 782 } while (ctx->next_output_worker_id != ctx->next_submit_worker_id); |
| 783 } |
| 784 return NULL; |
453 } | 785 } |
454 | 786 |
455 static vpx_codec_err_t decoder_set_fb_fn( | 787 static vpx_codec_err_t decoder_set_fb_fn( |
456 vpx_codec_alg_priv_t *ctx, | 788 vpx_codec_alg_priv_t *ctx, |
457 vpx_get_frame_buffer_cb_fn_t cb_get, | 789 vpx_get_frame_buffer_cb_fn_t cb_get, |
458 vpx_release_frame_buffer_cb_fn_t cb_release, void *cb_priv) { | 790 vpx_release_frame_buffer_cb_fn_t cb_release, void *cb_priv) { |
459 if (cb_get == NULL || cb_release == NULL) { | 791 if (cb_get == NULL || cb_release == NULL) { |
460 return VPX_CODEC_INVALID_PARAM; | 792 return VPX_CODEC_INVALID_PARAM; |
461 } else if (ctx->pbi == NULL) { | 793 } else if (ctx->frame_workers == NULL) { |
462 // If the decoder has already been initialized, do not accept changes to | 794 // If the decoder has already been initialized, do not accept changes to |
463 // the frame buffer functions. | 795 // the frame buffer functions. |
464 ctx->get_ext_fb_cb = cb_get; | 796 ctx->get_ext_fb_cb = cb_get; |
465 ctx->release_ext_fb_cb = cb_release; | 797 ctx->release_ext_fb_cb = cb_release; |
466 ctx->ext_priv = cb_priv; | 798 ctx->ext_priv = cb_priv; |
467 return VPX_CODEC_OK; | 799 return VPX_CODEC_OK; |
468 } | 800 } |
469 | 801 |
470 return VPX_CODEC_ERROR; | 802 return VPX_CODEC_ERROR; |
471 } | 803 } |
472 | 804 |
473 static vpx_codec_err_t ctrl_set_reference(vpx_codec_alg_priv_t *ctx, | 805 static vpx_codec_err_t ctrl_set_reference(vpx_codec_alg_priv_t *ctx, |
474 va_list args) { | 806 va_list args) { |
475 vpx_ref_frame_t *const data = va_arg(args, vpx_ref_frame_t *); | 807 vpx_ref_frame_t *const data = va_arg(args, vpx_ref_frame_t *); |
476 | 808 |
| 809 // Only support this function in serial decode. |
| 810 if (ctx->frame_parallel_decode) { |
| 811 set_error_detail(ctx, "Not supported in frame parallel decode"); |
| 812 return VPX_CODEC_INCAPABLE; |
| 813 } |
| 814 |
477 if (data) { | 815 if (data) { |
478 vpx_ref_frame_t *const frame = (vpx_ref_frame_t *)data; | 816 vpx_ref_frame_t *const frame = (vpx_ref_frame_t *)data; |
479 YV12_BUFFER_CONFIG sd; | 817 YV12_BUFFER_CONFIG sd; |
480 | 818 VP9Worker *const worker = ctx->frame_workers; |
| 819 FrameWorkerData *const frame_worker_data = (FrameWorkerData *)worker->data1; |
481 image2yuvconfig(&frame->img, &sd); | 820 image2yuvconfig(&frame->img, &sd); |
482 return vp9_set_reference_dec(&ctx->pbi->common, | 821 return vp9_set_reference_dec(&frame_worker_data->pbi->common, |
483 (VP9_REFFRAME)frame->frame_type, &sd); | 822 (VP9_REFFRAME)frame->frame_type, &sd); |
484 } else { | 823 } else { |
485 return VPX_CODEC_INVALID_PARAM; | 824 return VPX_CODEC_INVALID_PARAM; |
486 } | 825 } |
487 } | 826 } |
488 | 827 |
489 static vpx_codec_err_t ctrl_copy_reference(vpx_codec_alg_priv_t *ctx, | 828 static vpx_codec_err_t ctrl_copy_reference(vpx_codec_alg_priv_t *ctx, |
490 va_list args) { | 829 va_list args) { |
491 vpx_ref_frame_t *data = va_arg(args, vpx_ref_frame_t *); | 830 vpx_ref_frame_t *data = va_arg(args, vpx_ref_frame_t *); |
492 | 831 |
| 832 // Only support this function in serial decode. |
| 833 if (ctx->frame_parallel_decode) { |
| 834 set_error_detail(ctx, "Not supported in frame parallel decode"); |
| 835 return VPX_CODEC_INCAPABLE; |
| 836 } |
| 837 |
493 if (data) { | 838 if (data) { |
494 vpx_ref_frame_t *frame = (vpx_ref_frame_t *)data; | 839 vpx_ref_frame_t *frame = (vpx_ref_frame_t *) data; |
495 YV12_BUFFER_CONFIG sd; | 840 YV12_BUFFER_CONFIG sd; |
496 | 841 VP9Worker *const worker = ctx->frame_workers; |
| 842 FrameWorkerData *const frame_worker_data = (FrameWorkerData *)worker->data1; |
497 image2yuvconfig(&frame->img, &sd); | 843 image2yuvconfig(&frame->img, &sd); |
498 | 844 return vp9_copy_reference_dec(frame_worker_data->pbi, |
499 return vp9_copy_reference_dec(ctx->pbi, | |
500 (VP9_REFFRAME)frame->frame_type, &sd); | 845 (VP9_REFFRAME)frame->frame_type, &sd); |
501 } else { | 846 } else { |
502 return VPX_CODEC_INVALID_PARAM; | 847 return VPX_CODEC_INVALID_PARAM; |
503 } | 848 } |
504 } | 849 } |
505 | 850 |
506 static vpx_codec_err_t ctrl_get_reference(vpx_codec_alg_priv_t *ctx, | 851 static vpx_codec_err_t ctrl_get_reference(vpx_codec_alg_priv_t *ctx, |
507 va_list args) { | 852 va_list args) { |
508 vp9_ref_frame_t *data = va_arg(args, vp9_ref_frame_t *); | 853 vp9_ref_frame_t *data = va_arg(args, vp9_ref_frame_t *); |
509 | 854 |
| 855 // Only support this function in serial decode. |
| 856 if (ctx->frame_parallel_decode) { |
| 857 set_error_detail(ctx, "Not supported in frame parallel decode"); |
| 858 return VPX_CODEC_INCAPABLE; |
| 859 } |
| 860 |
510 if (data) { | 861 if (data) { |
511 YV12_BUFFER_CONFIG* fb = get_ref_frame(&ctx->pbi->common, data->idx); | 862 YV12_BUFFER_CONFIG* fb; |
| 863 VP9Worker *const worker = ctx->frame_workers; |
| 864 FrameWorkerData *const frame_worker_data = (FrameWorkerData *)worker->data1; |
| 865 fb = get_ref_frame(&frame_worker_data->pbi->common, data->idx); |
512 if (fb == NULL) return VPX_CODEC_ERROR; | 866 if (fb == NULL) return VPX_CODEC_ERROR; |
513 | |
514 yuvconfig2image(&data->img, fb, NULL); | 867 yuvconfig2image(&data->img, fb, NULL); |
515 return VPX_CODEC_OK; | 868 return VPX_CODEC_OK; |
516 } else { | 869 } else { |
517 return VPX_CODEC_INVALID_PARAM; | 870 return VPX_CODEC_INVALID_PARAM; |
518 } | 871 } |
519 } | 872 } |
520 | 873 |
521 static vpx_codec_err_t ctrl_set_postproc(vpx_codec_alg_priv_t *ctx, | 874 static vpx_codec_err_t ctrl_set_postproc(vpx_codec_alg_priv_t *ctx, |
522 va_list args) { | 875 va_list args) { |
523 #if CONFIG_VP9_POSTPROC | 876 #if CONFIG_VP9_POSTPROC |
(...skipping 17 matching lines...) Expand all Loading... |
541 va_list args) { | 894 va_list args) { |
542 (void)ctx; | 895 (void)ctx; |
543 (void)args; | 896 (void)args; |
544 return VPX_CODEC_INCAPABLE; | 897 return VPX_CODEC_INCAPABLE; |
545 } | 898 } |
546 | 899 |
547 static vpx_codec_err_t ctrl_get_last_ref_updates(vpx_codec_alg_priv_t *ctx, | 900 static vpx_codec_err_t ctrl_get_last_ref_updates(vpx_codec_alg_priv_t *ctx, |
548 va_list args) { | 901 va_list args) { |
549 int *const update_info = va_arg(args, int *); | 902 int *const update_info = va_arg(args, int *); |
550 | 903 |
| 904 // Only support this function in serial decode. |
| 905 if (ctx->frame_parallel_decode) { |
| 906 set_error_detail(ctx, "Not supported in frame parallel decode"); |
| 907 return VPX_CODEC_INCAPABLE; |
| 908 } |
| 909 |
551 if (update_info) { | 910 if (update_info) { |
552 if (ctx->pbi) | 911 if (ctx->frame_workers) { |
553 *update_info = ctx->pbi->refresh_frame_flags; | 912 VP9Worker *const worker = ctx->frame_workers; |
554 else | 913 FrameWorkerData *const frame_worker_data = |
| 914 (FrameWorkerData *)worker->data1; |
| 915 *update_info = frame_worker_data->pbi->refresh_frame_flags; |
| 916 return VPX_CODEC_OK; |
| 917 } else { |
555 return VPX_CODEC_ERROR; | 918 return VPX_CODEC_ERROR; |
556 return VPX_CODEC_OK; | 919 } |
557 } else { | |
558 return VPX_CODEC_INVALID_PARAM; | |
559 } | 920 } |
| 921 |
| 922 return VPX_CODEC_INVALID_PARAM; |
560 } | 923 } |
561 | 924 |
562 | |
563 static vpx_codec_err_t ctrl_get_frame_corrupted(vpx_codec_alg_priv_t *ctx, | 925 static vpx_codec_err_t ctrl_get_frame_corrupted(vpx_codec_alg_priv_t *ctx, |
564 va_list args) { | 926 va_list args) { |
565 int *corrupted = va_arg(args, int *); | 927 int *corrupted = va_arg(args, int *); |
566 | 928 |
567 if (corrupted != NULL && ctx->pbi != NULL) { | 929 if (corrupted) { |
568 const YV12_BUFFER_CONFIG *const frame = ctx->pbi->common.frame_to_show; | 930 if (ctx->frame_workers) { |
569 if (frame == NULL) return VPX_CODEC_ERROR; | 931 VP9Worker *const worker = ctx->frame_workers; |
570 *corrupted = frame->corrupted; | 932 FrameWorkerData *const frame_worker_data = |
571 return VPX_CODEC_OK; | 933 (FrameWorkerData *)worker->data1; |
572 } else { | 934 RefCntBuffer *const frame_bufs = |
573 return VPX_CODEC_INVALID_PARAM; | 935 frame_worker_data->pbi->common.buffer_pool->frame_bufs; |
| 936 if (frame_worker_data->pbi->common.frame_to_show == NULL) |
| 937 return VPX_CODEC_ERROR; |
| 938 *corrupted = frame_bufs[ctx->last_show_frame].buf.corrupted; |
| 939 return VPX_CODEC_OK; |
| 940 } else { |
| 941 return VPX_CODEC_ERROR; |
| 942 } |
574 } | 943 } |
| 944 |
| 945 return VPX_CODEC_INVALID_PARAM; |
| 946 } |
| 947 |
| 948 static vpx_codec_err_t ctrl_get_frame_size(vpx_codec_alg_priv_t *ctx, |
| 949 va_list args) { |
| 950 int *const frame_size = va_arg(args, int *); |
| 951 |
| 952 // Only support this function in serial decode. |
| 953 if (ctx->frame_parallel_decode) { |
| 954 set_error_detail(ctx, "Not supported in frame parallel decode"); |
| 955 return VPX_CODEC_INCAPABLE; |
| 956 } |
| 957 |
| 958 if (frame_size) { |
| 959 if (ctx->frame_workers) { |
| 960 VP9Worker *const worker = ctx->frame_workers; |
| 961 FrameWorkerData *const frame_worker_data = |
| 962 (FrameWorkerData *)worker->data1; |
| 963 const VP9_COMMON *const cm = &frame_worker_data->pbi->common; |
| 964 frame_size[0] = cm->width; |
| 965 frame_size[1] = cm->height; |
| 966 return VPX_CODEC_OK; |
| 967 } else { |
| 968 return VPX_CODEC_ERROR; |
| 969 } |
| 970 } |
| 971 |
| 972 return VPX_CODEC_INVALID_PARAM; |
575 } | 973 } |
576 | 974 |
577 static vpx_codec_err_t ctrl_get_display_size(vpx_codec_alg_priv_t *ctx, | 975 static vpx_codec_err_t ctrl_get_display_size(vpx_codec_alg_priv_t *ctx, |
578 va_list args) { | 976 va_list args) { |
579 int *const display_size = va_arg(args, int *); | 977 int *const display_size = va_arg(args, int *); |
580 | 978 |
| 979 // Only support this function in serial decode. |
| 980 if (ctx->frame_parallel_decode) { |
| 981 set_error_detail(ctx, "Not supported in frame parallel decode"); |
| 982 return VPX_CODEC_INCAPABLE; |
| 983 } |
| 984 |
581 if (display_size) { | 985 if (display_size) { |
582 if (ctx->pbi) { | 986 if (ctx->frame_workers) { |
583 const VP9_COMMON *const cm = &ctx->pbi->common; | 987 VP9Worker *const worker = ctx->frame_workers; |
| 988 FrameWorkerData *const frame_worker_data = |
| 989 (FrameWorkerData *)worker->data1; |
| 990 const VP9_COMMON *const cm = &frame_worker_data->pbi->common; |
584 display_size[0] = cm->display_width; | 991 display_size[0] = cm->display_width; |
585 display_size[1] = cm->display_height; | 992 display_size[1] = cm->display_height; |
| 993 return VPX_CODEC_OK; |
586 } else { | 994 } else { |
587 return VPX_CODEC_ERROR; | 995 return VPX_CODEC_ERROR; |
588 } | 996 } |
589 return VPX_CODEC_OK; | |
590 } else { | |
591 return VPX_CODEC_INVALID_PARAM; | |
592 } | 997 } |
| 998 |
| 999 return VPX_CODEC_INVALID_PARAM; |
593 } | 1000 } |
594 | 1001 |
595 static vpx_codec_err_t ctrl_get_bit_depth(vpx_codec_alg_priv_t *ctx, | 1002 static vpx_codec_err_t ctrl_get_bit_depth(vpx_codec_alg_priv_t *ctx, |
596 va_list args) { | 1003 va_list args) { |
597 unsigned int *const bit_depth = va_arg(args, unsigned int *); | 1004 unsigned int *const bit_depth = va_arg(args, unsigned int *); |
| 1005 VP9Worker *const worker = &ctx->frame_workers[ctx->next_output_worker_id]; |
598 | 1006 |
599 if (bit_depth) { | 1007 if (bit_depth) { |
600 if (ctx->pbi) { | 1008 if (worker) { |
601 const VP9_COMMON *const cm = &ctx->pbi->common; | 1009 FrameWorkerData *const frame_worker_data = |
| 1010 (FrameWorkerData *)worker->data1; |
| 1011 const VP9_COMMON *const cm = &frame_worker_data->pbi->common; |
602 *bit_depth = cm->bit_depth; | 1012 *bit_depth = cm->bit_depth; |
603 return VPX_CODEC_OK; | 1013 return VPX_CODEC_OK; |
604 } else { | 1014 } else { |
605 return VPX_CODEC_ERROR; | 1015 return VPX_CODEC_ERROR; |
606 } | 1016 } |
607 } else { | |
608 return VPX_CODEC_INVALID_PARAM; | |
609 } | 1017 } |
| 1018 |
| 1019 return VPX_CODEC_INVALID_PARAM; |
610 } | 1020 } |
611 | 1021 |
612 static vpx_codec_err_t ctrl_set_invert_tile_order(vpx_codec_alg_priv_t *ctx, | 1022 static vpx_codec_err_t ctrl_set_invert_tile_order(vpx_codec_alg_priv_t *ctx, |
613 va_list args) { | 1023 va_list args) { |
614 ctx->invert_tile_order = va_arg(args, int); | 1024 ctx->invert_tile_order = va_arg(args, int); |
615 return VPX_CODEC_OK; | 1025 return VPX_CODEC_OK; |
616 } | 1026 } |
617 | 1027 |
618 static vpx_codec_err_t ctrl_set_decryptor(vpx_codec_alg_priv_t *ctx, | 1028 static vpx_codec_err_t ctrl_set_decryptor(vpx_codec_alg_priv_t *ctx, |
619 va_list args) { | 1029 va_list args) { |
(...skipping 10 matching lines...) Expand all Loading... |
630 const int max_byte_alignment = 1024; | 1040 const int max_byte_alignment = 1024; |
631 const int byte_alignment = va_arg(args, int); | 1041 const int byte_alignment = va_arg(args, int); |
632 | 1042 |
633 if (byte_alignment != legacy_byte_alignment && | 1043 if (byte_alignment != legacy_byte_alignment && |
634 (byte_alignment < min_byte_alignment || | 1044 (byte_alignment < min_byte_alignment || |
635 byte_alignment > max_byte_alignment || | 1045 byte_alignment > max_byte_alignment || |
636 (byte_alignment & (byte_alignment - 1)) != 0)) | 1046 (byte_alignment & (byte_alignment - 1)) != 0)) |
637 return VPX_CODEC_INVALID_PARAM; | 1047 return VPX_CODEC_INVALID_PARAM; |
638 | 1048 |
639 ctx->byte_alignment = byte_alignment; | 1049 ctx->byte_alignment = byte_alignment; |
640 if (ctx->pbi != NULL) { | 1050 if (ctx->frame_workers) { |
641 VP9_COMMON *const cm = &ctx->pbi->common; | 1051 VP9Worker *const worker = ctx->frame_workers; |
642 cm->byte_alignment = byte_alignment; | 1052 FrameWorkerData *const frame_worker_data = |
| 1053 (FrameWorkerData *)worker->data1; |
| 1054 frame_worker_data->pbi->common.byte_alignment = byte_alignment; |
643 } | 1055 } |
644 return VPX_CODEC_OK; | 1056 return VPX_CODEC_OK; |
645 } | 1057 } |
646 | 1058 |
647 static vpx_codec_ctrl_fn_map_t decoder_ctrl_maps[] = { | 1059 static vpx_codec_ctrl_fn_map_t decoder_ctrl_maps[] = { |
648 {VP8_COPY_REFERENCE, ctrl_copy_reference}, | 1060 {VP8_COPY_REFERENCE, ctrl_copy_reference}, |
649 | 1061 |
650 // Setters | 1062 // Setters |
651 {VP8_SET_REFERENCE, ctrl_set_reference}, | 1063 {VP8_SET_REFERENCE, ctrl_set_reference}, |
652 {VP8_SET_POSTPROC, ctrl_set_postproc}, | 1064 {VP8_SET_POSTPROC, ctrl_set_postproc}, |
653 {VP8_SET_DBG_COLOR_REF_FRAME, ctrl_set_dbg_options}, | 1065 {VP8_SET_DBG_COLOR_REF_FRAME, ctrl_set_dbg_options}, |
654 {VP8_SET_DBG_COLOR_MB_MODES, ctrl_set_dbg_options}, | 1066 {VP8_SET_DBG_COLOR_MB_MODES, ctrl_set_dbg_options}, |
655 {VP8_SET_DBG_COLOR_B_MODES, ctrl_set_dbg_options}, | 1067 {VP8_SET_DBG_COLOR_B_MODES, ctrl_set_dbg_options}, |
656 {VP8_SET_DBG_DISPLAY_MV, ctrl_set_dbg_options}, | 1068 {VP8_SET_DBG_DISPLAY_MV, ctrl_set_dbg_options}, |
657 {VP9_INVERT_TILE_DECODE_ORDER, ctrl_set_invert_tile_order}, | 1069 {VP9_INVERT_TILE_DECODE_ORDER, ctrl_set_invert_tile_order}, |
658 {VPXD_SET_DECRYPTOR, ctrl_set_decryptor}, | 1070 {VPXD_SET_DECRYPTOR, ctrl_set_decryptor}, |
659 {VP9_SET_BYTE_ALIGNMENT, ctrl_set_byte_alignment}, | 1071 {VP9_SET_BYTE_ALIGNMENT, ctrl_set_byte_alignment}, |
660 | 1072 |
661 // Getters | 1073 // Getters |
662 {VP8D_GET_LAST_REF_UPDATES, ctrl_get_last_ref_updates}, | 1074 {VP8D_GET_LAST_REF_UPDATES, ctrl_get_last_ref_updates}, |
663 {VP8D_GET_FRAME_CORRUPTED, ctrl_get_frame_corrupted}, | 1075 {VP8D_GET_FRAME_CORRUPTED, ctrl_get_frame_corrupted}, |
664 {VP9_GET_REFERENCE, ctrl_get_reference}, | 1076 {VP9_GET_REFERENCE, ctrl_get_reference}, |
665 {VP9D_GET_DISPLAY_SIZE, ctrl_get_display_size}, | 1077 {VP9D_GET_DISPLAY_SIZE, ctrl_get_display_size}, |
666 {VP9D_GET_BIT_DEPTH, ctrl_get_bit_depth}, | 1078 {VP9D_GET_BIT_DEPTH, ctrl_get_bit_depth}, |
| 1079 {VP9D_GET_FRAME_SIZE, ctrl_get_frame_size}, |
667 | 1080 |
668 { -1, NULL}, | 1081 { -1, NULL}, |
669 }; | 1082 }; |
670 | 1083 |
671 #ifndef VERSION_STRING | 1084 #ifndef VERSION_STRING |
672 #define VERSION_STRING | 1085 #define VERSION_STRING |
673 #endif | 1086 #endif |
674 CODEC_INTERFACE(vpx_codec_vp9_dx) = { | 1087 CODEC_INTERFACE(vpx_codec_vp9_dx) = { |
675 "WebM Project VP9 Decoder" VERSION_STRING, | 1088 "WebM Project VP9 Decoder" VERSION_STRING, |
676 VPX_CODEC_INTERNAL_ABI_VERSION, | 1089 VPX_CODEC_INTERNAL_ABI_VERSION, |
(...skipping 13 matching lines...) Expand all Loading... |
690 0, | 1103 0, |
691 NULL, // vpx_codec_enc_cfg_map_t | 1104 NULL, // vpx_codec_enc_cfg_map_t |
692 NULL, // vpx_codec_encode_fn_t | 1105 NULL, // vpx_codec_encode_fn_t |
693 NULL, // vpx_codec_get_cx_data_fn_t | 1106 NULL, // vpx_codec_get_cx_data_fn_t |
694 NULL, // vpx_codec_enc_config_set_fn_t | 1107 NULL, // vpx_codec_enc_config_set_fn_t |
695 NULL, // vpx_codec_get_global_headers_fn_t | 1108 NULL, // vpx_codec_get_global_headers_fn_t |
696 NULL, // vpx_codec_get_preview_frame_fn_t | 1109 NULL, // vpx_codec_get_preview_frame_fn_t |
697 NULL // vpx_codec_enc_mr_get_mem_loc_fn_t | 1110 NULL // vpx_codec_enc_mr_get_mem_loc_fn_t |
698 } | 1111 } |
699 }; | 1112 }; |
OLD | NEW |