2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved.
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
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
11 #ifndef VP9_DECODER_VP9_DECODER_H_
12 #define VP9_DECODER_VP9_DECODER_H_
14 #include "./vpx_config.h"
16 #include "vpx/vpx_codec.h"
17 #include "vpx_dsp/bitreader.h"
18 #include "vpx_scale/yv12config.h"
19 #include "vpx_util/vpx_thread.h"
21 #include "vp9/common/vp9_thread_common.h"
22 #include "vp9/common/vp9_onyxc_int.h"
23 #include "vp9/common/vp9_ppflags.h"
24 #include "vp9/decoder/vp9_dthread.h"
30 // TODO(hkuang): combine this with TileWorkerData.
31 typedef struct TileData {
33 vpx_reader bit_reader;
34 DECLARE_ALIGNED(16, MACROBLOCKD, xd);
35 /* dqcoeff are shared by all the planes. So planes must be decoded serially */
36 DECLARE_ALIGNED(16, tran_low_t, dqcoeff[32 * 32]);
39 typedef struct TileWorkerData {
40 struct VP9Decoder *pbi;
41 vpx_reader bit_reader;
43 DECLARE_ALIGNED(16, MACROBLOCKD, xd);
44 /* dqcoeff are shared by all the planes. So planes must be decoded serially */
45 DECLARE_ALIGNED(16, tran_low_t, dqcoeff[32 * 32]);
46 struct vpx_internal_error_info error_info;
49 typedef struct VP9Decoder {
50 DECLARE_ALIGNED(16, MACROBLOCKD, mb);
52 DECLARE_ALIGNED(16, VP9_COMMON, common);
54 int ready_for_new_data;
56 int refresh_frame_flags;
58 int frame_parallel_decode; // frame-based threading.
60 // TODO(hkuang): Combine this with cur_buf in macroblockd as they are
62 RefCntBuffer *cur_buf; // Current decoding frame buffer.
64 VPxWorker *frame_worker_owner; // frame_worker that owns this pbi.
66 VPxWorker *tile_workers;
67 TileWorkerData *tile_worker_data;
73 VP9LfSync lf_row_sync;
75 vpx_decrypt_cb decrypt_cb;
80 int need_resync; // wait for key/intra-only frame.
81 int hold_ref_buf; // hold the reference buffer.
84 int vp9_receive_compressed_data(struct VP9Decoder *pbi,
85 size_t size, const uint8_t **dest);
87 int vp9_get_raw_frame(struct VP9Decoder *pbi, YV12_BUFFER_CONFIG *sd,
88 vp9_ppflags_t *flags);
90 vpx_codec_err_t vp9_copy_reference_dec(struct VP9Decoder *pbi,
91 VP9_REFFRAME ref_frame_flag,
92 YV12_BUFFER_CONFIG *sd);
94 vpx_codec_err_t vp9_set_reference_dec(VP9_COMMON *cm,
95 VP9_REFFRAME ref_frame_flag,
96 YV12_BUFFER_CONFIG *sd);
98 static INLINE uint8_t read_marker(vpx_decrypt_cb decrypt_cb,
100 const uint8_t *data) {
103 decrypt_cb(decrypt_state, data, &marker, 1);
109 // This function is exposed for use in tests, as well as the inlined function
111 vpx_codec_err_t vp9_parse_superframe_index(const uint8_t *data,
113 uint32_t sizes[8], int *count,
114 vpx_decrypt_cb decrypt_cb,
115 void *decrypt_state);
117 struct VP9Decoder *vp9_decoder_create(BufferPool *const pool);
119 void vp9_decoder_remove(struct VP9Decoder *pbi);
121 static INLINE void decrease_ref_count(int idx, RefCntBuffer *const frame_bufs,
122 BufferPool *const pool) {
124 --frame_bufs[idx].ref_count;
125 // A worker may only get a free framebuffer index when calling get_free_fb.
126 // But the private buffer is not set up until finish decoding header.
127 // So any error happens during decoding header, the frame_bufs will not
128 // have valid priv buffer.
129 if (frame_bufs[idx].ref_count == 0 &&
130 frame_bufs[idx].raw_frame_buffer.priv) {
131 pool->release_fb_cb(pool->cb_priv, &frame_bufs[idx].raw_frame_buffer);
140 #endif // VP9_DECODER_VP9_DECODER_H_