Line data Source code
1 : /*
2 : * Copyright (c) 2010 The WebM project authors. All Rights Reserved.
3 : *
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.
9 : */
10 :
11 : #ifndef VP9_DECODER_VP9_DECODER_H_
12 : #define VP9_DECODER_VP9_DECODER_H_
13 :
14 : #include "./vpx_config.h"
15 :
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"
20 :
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"
25 :
26 : #ifdef __cplusplus
27 : extern "C" {
28 : #endif
29 :
30 : typedef struct TileBuffer {
31 : const uint8_t *data;
32 : size_t size;
33 : int col; // only used with multi-threaded decoding
34 : } TileBuffer;
35 :
36 : typedef struct TileWorkerData {
37 : const uint8_t *data_end;
38 : int buf_start, buf_end; // pbi->tile_buffers to decode, inclusive
39 : vpx_reader bit_reader;
40 : FRAME_COUNTS counts;
41 : DECLARE_ALIGNED(16, MACROBLOCKD, xd);
42 : /* dqcoeff are shared by all the planes. So planes must be decoded serially */
43 : DECLARE_ALIGNED(16, tran_low_t, dqcoeff[32 * 32]);
44 : struct vpx_internal_error_info error_info;
45 : } TileWorkerData;
46 :
47 : typedef struct VP9Decoder {
48 : DECLARE_ALIGNED(16, MACROBLOCKD, mb);
49 :
50 : DECLARE_ALIGNED(16, VP9_COMMON, common);
51 :
52 : int ready_for_new_data;
53 :
54 : int refresh_frame_flags;
55 :
56 : int frame_parallel_decode; // frame-based threading.
57 :
58 : // TODO(hkuang): Combine this with cur_buf in macroblockd as they are
59 : // the same.
60 : RefCntBuffer *cur_buf; // Current decoding frame buffer.
61 :
62 : VPxWorker *frame_worker_owner; // frame_worker that owns this pbi.
63 : VPxWorker lf_worker;
64 : VPxWorker *tile_workers;
65 : TileWorkerData *tile_worker_data;
66 : TileBuffer tile_buffers[64];
67 : int num_tile_workers;
68 : int total_tiles;
69 :
70 : VP9LfSync lf_row_sync;
71 :
72 : vpx_decrypt_cb decrypt_cb;
73 : void *decrypt_state;
74 :
75 : int max_threads;
76 : int inv_tile_order;
77 : int need_resync; // wait for key/intra-only frame.
78 : int hold_ref_buf; // hold the reference buffer.
79 : } VP9Decoder;
80 :
81 : int vp9_receive_compressed_data(struct VP9Decoder *pbi, size_t size,
82 : const uint8_t **dest);
83 :
84 : int vp9_get_raw_frame(struct VP9Decoder *pbi, YV12_BUFFER_CONFIG *sd,
85 : vp9_ppflags_t *flags);
86 :
87 : vpx_codec_err_t vp9_copy_reference_dec(struct VP9Decoder *pbi,
88 : VP9_REFFRAME ref_frame_flag,
89 : YV12_BUFFER_CONFIG *sd);
90 :
91 : vpx_codec_err_t vp9_set_reference_dec(VP9_COMMON *cm,
92 : VP9_REFFRAME ref_frame_flag,
93 : YV12_BUFFER_CONFIG *sd);
94 :
95 0 : static INLINE uint8_t read_marker(vpx_decrypt_cb decrypt_cb,
96 : void *decrypt_state, const uint8_t *data) {
97 0 : if (decrypt_cb) {
98 : uint8_t marker;
99 0 : decrypt_cb(decrypt_state, data, &marker, 1);
100 0 : return marker;
101 : }
102 0 : return *data;
103 : }
104 :
105 : // This function is exposed for use in tests, as well as the inlined function
106 : // "read_marker".
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);
111 :
112 : struct VP9Decoder *vp9_decoder_create(BufferPool *const pool);
113 :
114 : void vp9_decoder_remove(struct VP9Decoder *pbi);
115 :
116 0 : static INLINE void decrease_ref_count(int idx, RefCntBuffer *const frame_bufs,
117 : BufferPool *const pool) {
118 0 : if (idx >= 0 && frame_bufs[idx].ref_count > 0) {
119 0 : --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 0 : if (frame_bufs[idx].ref_count == 0 &&
125 0 : frame_bufs[idx].raw_frame_buffer.priv) {
126 0 : pool->release_fb_cb(pool->cb_priv, &frame_bufs[idx].raw_frame_buffer);
127 : }
128 : }
129 0 : }
130 :
131 : #ifdef __cplusplus
132 : } // extern "C"
133 : #endif
134 :
135 : #endif // VP9_DECODER_VP9_DECODER_H_
|