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 VPX_VP9_DECODER_VP9_DECODER_H_
12 #define VPX_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"
29 typedef struct TileBuffer {
32 int col; // only used with multi-threaded decoding
35 typedef struct TileWorkerData {
36 const uint8_t *data_end;
37 int buf_start, buf_end; // pbi->tile_buffers to decode, inclusive
38 vpx_reader bit_reader;
40 LFWorkerData *lf_data;
42 DECLARE_ALIGNED(16, MACROBLOCKD, xd);
43 /* dqcoeff are shared by all the planes. So planes must be decoded serially */
44 DECLARE_ALIGNED(16, tran_low_t, dqcoeff[32 * 32]);
45 struct vpx_internal_error_info error_info;
48 typedef struct VP9Decoder {
49 DECLARE_ALIGNED(16, MACROBLOCKD, mb);
51 DECLARE_ALIGNED(16, VP9_COMMON, common);
53 int ready_for_new_data;
55 int refresh_frame_flags;
57 // TODO(hkuang): Combine this with cur_buf in macroblockd as they are
59 RefCntBuffer *cur_buf; // Current decoding frame buffer.
62 VPxWorker *tile_workers;
63 TileWorkerData *tile_worker_data;
64 TileBuffer tile_buffers[64];
68 VP9LfSync lf_row_sync;
70 vpx_decrypt_cb decrypt_cb;
75 int need_resync; // wait for key/intra-only frame.
76 int hold_ref_buf; // hold the reference buffer.
81 int vp9_receive_compressed_data(struct VP9Decoder *pbi, size_t size,
82 const uint8_t **dest);
84 int vp9_get_raw_frame(struct VP9Decoder *pbi, YV12_BUFFER_CONFIG *sd,
85 vp9_ppflags_t *flags);
87 vpx_codec_err_t vp9_copy_reference_dec(struct VP9Decoder *pbi,
88 VP9_REFFRAME ref_frame_flag,
89 YV12_BUFFER_CONFIG *sd);
91 vpx_codec_err_t vp9_set_reference_dec(VP9_COMMON *cm,
92 VP9_REFFRAME ref_frame_flag,
93 YV12_BUFFER_CONFIG *sd);
95 static INLINE uint8_t read_marker(vpx_decrypt_cb decrypt_cb,
96 void *decrypt_state, const uint8_t *data) {
99 decrypt_cb(decrypt_state, data, &marker, 1);
105 // This function is exposed for use in tests, as well as the inlined function
107 vpx_codec_err_t vp9_parse_superframe_index(const uint8_t *data, size_t data_sz,
108 uint32_t sizes[8], int *count,
109 vpx_decrypt_cb decrypt_cb,
110 void *decrypt_state);
112 struct VP9Decoder *vp9_decoder_create(BufferPool *const pool);
114 void vp9_decoder_remove(struct VP9Decoder *pbi);
116 static INLINE void decrease_ref_count(int idx, RefCntBuffer *const frame_bufs,
117 BufferPool *const pool) {
118 if (idx >= 0 && frame_bufs[idx].ref_count > 0) {
119 --frame_bufs[idx].ref_count;
120 // A worker may only get a free framebuffer index when calling get_free_fb.
121 // But the private buffer is not set up until finish decoding header.
122 // So any error happens during decoding header, the frame_bufs will not
123 // have valid priv buffer.
124 if (!frame_bufs[idx].released && frame_bufs[idx].ref_count == 0 &&
125 frame_bufs[idx].raw_frame_buffer.priv) {
126 pool->release_fb_cb(pool->cb_priv, &frame_bufs[idx].raw_frame_buffer);
127 frame_bufs[idx].released = 1;
136 #endif // VPX_VP9_DECODER_VP9_DECODER_H_