/src/mozilla-central/third_party/aom/av1/decoder/decoder.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright (c) 2016, Alliance for Open Media. All rights reserved |
3 | | * |
4 | | * This source code is subject to the terms of the BSD 2 Clause License and |
5 | | * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License |
6 | | * was not distributed with this source code in the LICENSE file, you can |
7 | | * obtain it at www.aomedia.org/license/software. If the Alliance for Open |
8 | | * Media Patent License 1.0 was not distributed with this source code in the |
9 | | * PATENTS file, you can obtain it at www.aomedia.org/license/patent. |
10 | | */ |
11 | | |
12 | | #ifndef AOM_AV1_DECODER_DECODER_H_ |
13 | | #define AOM_AV1_DECODER_DECODER_H_ |
14 | | |
15 | | #include "config/aom_config.h" |
16 | | |
17 | | #include "aom/aom_codec.h" |
18 | | #include "aom_dsp/bitreader.h" |
19 | | #include "aom_scale/yv12config.h" |
20 | | #include "aom_util/aom_thread.h" |
21 | | |
22 | | #include "av1/common/thread_common.h" |
23 | | #include "av1/common/onyxc_int.h" |
24 | | #include "av1/decoder/dthread.h" |
25 | | #if CONFIG_ACCOUNTING |
26 | | #include "av1/decoder/accounting.h" |
27 | | #endif |
28 | | #if CONFIG_INSPECTION |
29 | | #include "av1/decoder/inspection.h" |
30 | | #endif |
31 | | |
32 | | #ifdef __cplusplus |
33 | | extern "C" { |
34 | | #endif |
35 | | |
36 | | typedef void (*decode_block_visitor_fn_t)(const AV1_COMMON *const cm, |
37 | | MACROBLOCKD *const xd, |
38 | | aom_reader *const r, const int plane, |
39 | | const int row, const int col, |
40 | | const TX_SIZE tx_size); |
41 | | |
42 | | typedef void (*predict_inter_block_visitor_fn_t)(AV1_COMMON *const cm, |
43 | | MACROBLOCKD *const xd, |
44 | | int mi_row, int mi_col, |
45 | | BLOCK_SIZE bsize); |
46 | | |
47 | | typedef void (*cfl_store_inter_block_visitor_fn_t)(AV1_COMMON *const cm, |
48 | | MACROBLOCKD *const xd); |
49 | | |
50 | | typedef struct ThreadData { |
51 | | aom_reader *bit_reader; |
52 | | DECLARE_ALIGNED(32, MACROBLOCKD, xd); |
53 | | /* dqcoeff are shared by all the planes. So planes must be decoded serially */ |
54 | | DECLARE_ALIGNED(32, tran_low_t, dqcoeff[MAX_TX_SQUARE]); |
55 | | CB_BUFFER cb_buffer_base; |
56 | | uint8_t *mc_buf[2]; |
57 | | int32_t mc_buf_size; |
58 | | int mc_buf_use_highbd; // Boolean: whether the byte pointers stored in |
59 | | // mc_buf were converted from highbd pointers. |
60 | | |
61 | | CONV_BUF_TYPE *tmp_conv_dst; |
62 | | uint8_t *tmp_obmc_bufs[2]; |
63 | | |
64 | | decode_block_visitor_fn_t read_coeffs_tx_intra_block_visit; |
65 | | decode_block_visitor_fn_t predict_and_recon_intra_block_visit; |
66 | | decode_block_visitor_fn_t read_coeffs_tx_inter_block_visit; |
67 | | decode_block_visitor_fn_t inverse_tx_inter_block_visit; |
68 | | predict_inter_block_visitor_fn_t predict_inter_block_visit; |
69 | | cfl_store_inter_block_visitor_fn_t cfl_store_inter_block_visit; |
70 | | } ThreadData; |
71 | | |
72 | | typedef struct AV1DecRowMTJobInfo { |
73 | | int tile_row; |
74 | | int tile_col; |
75 | | int mi_row; |
76 | | } AV1DecRowMTJobInfo; |
77 | | |
78 | | typedef struct AV1DecRowMTSyncData { |
79 | | #if CONFIG_MULTITHREAD |
80 | | pthread_mutex_t *mutex_; |
81 | | pthread_cond_t *cond_; |
82 | | #endif |
83 | | int allocated_sb_rows; |
84 | | int *cur_sb_col; |
85 | | int sync_range; |
86 | | int mi_rows; |
87 | | int mi_cols; |
88 | | int mi_rows_parse_done; |
89 | | int mi_rows_decode_started; |
90 | | int num_threads_working; |
91 | | } AV1DecRowMTSync; |
92 | | |
93 | | typedef struct AV1DecRowMTInfo { |
94 | | int tile_rows_start; |
95 | | int tile_rows_end; |
96 | | int tile_cols_start; |
97 | | int tile_cols_end; |
98 | | int start_tile; |
99 | | int end_tile; |
100 | | int mi_rows_parse_done; |
101 | | int mi_rows_decode_started; |
102 | | int mi_rows_to_decode; |
103 | | int row_mt_exit; |
104 | | } AV1DecRowMTInfo; |
105 | | |
106 | | typedef struct TileDataDec { |
107 | | TileInfo tile_info; |
108 | | aom_reader bit_reader; |
109 | | DECLARE_ALIGNED(16, FRAME_CONTEXT, tctx); |
110 | | AV1DecRowMTSync dec_row_mt_sync; |
111 | | } TileDataDec; |
112 | | |
113 | | typedef struct TileBufferDec { |
114 | | const uint8_t *data; |
115 | | size_t size; |
116 | | } TileBufferDec; |
117 | | |
118 | | typedef struct DataBuffer { |
119 | | const uint8_t *data; |
120 | | size_t size; |
121 | | } DataBuffer; |
122 | | |
123 | | typedef struct EXTERNAL_REFERENCES { |
124 | | YV12_BUFFER_CONFIG refs[MAX_EXTERNAL_REFERENCES]; |
125 | | int num; |
126 | | } EXTERNAL_REFERENCES; |
127 | | |
128 | | typedef struct TileJobsDec { |
129 | | TileBufferDec *tile_buffer; |
130 | | TileDataDec *tile_data; |
131 | | } TileJobsDec; |
132 | | |
133 | | typedef struct AV1DecTileMTData { |
134 | | #if CONFIG_MULTITHREAD |
135 | | pthread_mutex_t *job_mutex; |
136 | | #endif |
137 | | TileJobsDec *job_queue; |
138 | | int jobs_enqueued; |
139 | | int jobs_dequeued; |
140 | | int alloc_tile_rows; |
141 | | int alloc_tile_cols; |
142 | | } AV1DecTileMT; |
143 | | |
144 | | typedef struct AV1Decoder { |
145 | | DECLARE_ALIGNED(32, MACROBLOCKD, mb); |
146 | | |
147 | | DECLARE_ALIGNED(32, AV1_COMMON, common); |
148 | | |
149 | | int refresh_frame_flags; |
150 | | |
151 | | // TODO(hkuang): Combine this with cur_buf in macroblockd as they are |
152 | | // the same. |
153 | | RefCntBuffer *cur_buf; // Current decoding frame buffer. |
154 | | |
155 | | AVxWorker *frame_worker_owner; // frame_worker that owns this pbi. |
156 | | AVxWorker lf_worker; |
157 | | AV1LfSync lf_row_sync; |
158 | | AV1LrSync lr_row_sync; |
159 | | AV1LrStruct lr_ctxt; |
160 | | AVxWorker *tile_workers; |
161 | | int num_workers; |
162 | | DecWorkerData *thread_data; |
163 | | ThreadData td; |
164 | | TileDataDec *tile_data; |
165 | | int allocated_tiles; |
166 | | |
167 | | TileBufferDec tile_buffers[MAX_TILE_ROWS][MAX_TILE_COLS]; |
168 | | AV1DecTileMT tile_mt_info; |
169 | | |
170 | | // Each time the decoder is called, we expect to receive a full temporal unit. |
171 | | // This can contain up to one shown frame per spatial layer in the current |
172 | | // operating point (note that some layers may be entirely omitted). |
173 | | // If the 'output_all_layers' option is true, we save all of these shown |
174 | | // frames so that they can be returned to the application. If the |
175 | | // 'output_all_layers' option is false, then we only output one image per |
176 | | // temporal unit. |
177 | | // |
178 | | // Note: The saved buffers are released at the start of the next time the |
179 | | // application calls aom_codec_decode(). |
180 | | int output_all_layers; |
181 | | YV12_BUFFER_CONFIG *output_frames[MAX_NUM_SPATIAL_LAYERS]; |
182 | | size_t output_frame_index[MAX_NUM_SPATIAL_LAYERS]; // Buffer pool indices |
183 | | size_t num_output_frames; // How many frames are queued up so far? |
184 | | |
185 | | // In order to properly support random-access decoding, we need |
186 | | // to behave slightly differently for the very first frame we decode. |
187 | | // So we track whether this is the first frame or not. |
188 | | int decoding_first_frame; |
189 | | |
190 | | int allow_lowbitdepth; |
191 | | int max_threads; |
192 | | int inv_tile_order; |
193 | | int need_resync; // wait for key/intra-only frame. |
194 | | int hold_ref_buf; // hold the reference buffer. |
195 | | |
196 | | int tile_size_bytes; |
197 | | int tile_col_size_bytes; |
198 | | int dec_tile_row, dec_tile_col; // always -1 for non-VR tile encoding |
199 | | #if CONFIG_ACCOUNTING |
200 | | int acct_enabled; |
201 | | Accounting accounting; |
202 | | #endif |
203 | | int tg_size; // Number of tiles in the current tilegroup |
204 | | int tg_start; // First tile in the current tilegroup |
205 | | int tg_size_bit_offset; |
206 | | int sequence_header_ready; |
207 | | int sequence_header_changed; |
208 | | #if CONFIG_INSPECTION |
209 | | aom_inspect_cb inspect_cb; |
210 | | void *inspect_ctx; |
211 | | #endif |
212 | | int operating_point; |
213 | | int current_operating_point; |
214 | | int seen_frame_header; |
215 | | |
216 | | // State if the camera frame header is already decoded while |
217 | | // large_scale_tile = 1. |
218 | | int camera_frame_header_ready; |
219 | | size_t frame_header_size; |
220 | | DataBuffer obu_size_hdr; |
221 | | int output_frame_width_in_tiles_minus_1; |
222 | | int output_frame_height_in_tiles_minus_1; |
223 | | int tile_count_minus_1; |
224 | | uint32_t coded_tile_data_size; |
225 | | unsigned int ext_tile_debug; // for ext-tile software debug & testing |
226 | | unsigned int row_mt; |
227 | | EXTERNAL_REFERENCES ext_refs; |
228 | | size_t tile_list_size; |
229 | | uint8_t *tile_list_output; |
230 | | size_t buffer_sz; |
231 | | |
232 | | CB_BUFFER *cb_buffer_base; |
233 | | int cb_buffer_alloc_size; |
234 | | |
235 | | int allocated_row_mt_sync_rows; |
236 | | |
237 | | #if CONFIG_MULTITHREAD |
238 | | pthread_mutex_t *row_mt_mutex_; |
239 | | pthread_cond_t *row_mt_cond_; |
240 | | #endif |
241 | | |
242 | | AV1DecRowMTInfo frame_row_mt_info; |
243 | | } AV1Decoder; |
244 | | |
245 | | // Returns 0 on success. Sets pbi->common.error.error_code to a nonzero error |
246 | | // code and returns a nonzero value on failure. |
247 | | int av1_receive_compressed_data(struct AV1Decoder *pbi, size_t size, |
248 | | const uint8_t **dest); |
249 | | |
250 | | // Get the frame at a particular index in the output queue |
251 | | int av1_get_raw_frame(AV1Decoder *pbi, size_t index, YV12_BUFFER_CONFIG **sd, |
252 | | aom_film_grain_t **grain_params); |
253 | | |
254 | | int av1_get_frame_to_show(struct AV1Decoder *pbi, YV12_BUFFER_CONFIG *frame); |
255 | | |
256 | | aom_codec_err_t av1_copy_reference_dec(struct AV1Decoder *pbi, int idx, |
257 | | YV12_BUFFER_CONFIG *sd); |
258 | | |
259 | | aom_codec_err_t av1_set_reference_dec(AV1_COMMON *cm, int idx, |
260 | | int use_external_ref, |
261 | | YV12_BUFFER_CONFIG *sd); |
262 | | aom_codec_err_t av1_copy_new_frame_dec(AV1_COMMON *cm, |
263 | | YV12_BUFFER_CONFIG *new_frame, |
264 | | YV12_BUFFER_CONFIG *sd); |
265 | | |
266 | | struct AV1Decoder *av1_decoder_create(BufferPool *const pool); |
267 | | |
268 | | void av1_decoder_remove(struct AV1Decoder *pbi); |
269 | | void av1_dealloc_dec_jobs(struct AV1DecTileMTData *tile_jobs_sync); |
270 | | |
271 | | void av1_dec_row_mt_dealloc(AV1DecRowMTSync *dec_row_mt_sync); |
272 | | |
273 | | void av1_dec_free_cb_buf(AV1Decoder *pbi); |
274 | | |
275 | | static INLINE void decrease_ref_count(int idx, RefCntBuffer *const frame_bufs, |
276 | 0 | BufferPool *const pool) { |
277 | 0 | if (idx >= 0) { |
278 | 0 | --frame_bufs[idx].ref_count; |
279 | 0 | // A worker may only get a free framebuffer index when calling get_free_fb. |
280 | 0 | // But the private buffer is not set up until finish decoding header. |
281 | 0 | // So any error happens during decoding header, the frame_bufs will not |
282 | 0 | // have valid priv buffer. |
283 | 0 | if (frame_bufs[idx].ref_count == 0 && |
284 | 0 | frame_bufs[idx].raw_frame_buffer.priv) { |
285 | 0 | pool->release_fb_cb(pool->cb_priv, &frame_bufs[idx].raw_frame_buffer); |
286 | 0 | } |
287 | 0 | } |
288 | 0 | } Unexecuted instantiation: av1_dx_iface.c:decrease_ref_count Unexecuted instantiation: decodeframe.c:decrease_ref_count Unexecuted instantiation: decodemv.c:decrease_ref_count Unexecuted instantiation: decoder.c:decrease_ref_count Unexecuted instantiation: decodetxb.c:decrease_ref_count Unexecuted instantiation: detokenize.c:decrease_ref_count Unexecuted instantiation: dthread.c:decrease_ref_count Unexecuted instantiation: obu.c:decrease_ref_count |
289 | | |
290 | | #define ACCT_STR __func__ |
291 | 0 | static INLINE int av1_read_uniform(aom_reader *r, int n) { |
292 | 0 | const int l = get_unsigned_bits(n); |
293 | 0 | const int m = (1 << l) - n; |
294 | 0 | const int v = aom_read_literal(r, l - 1, ACCT_STR); |
295 | 0 | assert(l != 0); |
296 | 0 | if (v < m) |
297 | 0 | return v; |
298 | 0 | else |
299 | 0 | return (v << 1) - m + aom_read_literal(r, 1, ACCT_STR); |
300 | 0 | } Unexecuted instantiation: av1_dx_iface.c:av1_read_uniform Unexecuted instantiation: decodeframe.c:av1_read_uniform Unexecuted instantiation: decodemv.c:av1_read_uniform Unexecuted instantiation: decoder.c:av1_read_uniform Unexecuted instantiation: decodetxb.c:av1_read_uniform Unexecuted instantiation: detokenize.c:av1_read_uniform Unexecuted instantiation: dthread.c:av1_read_uniform Unexecuted instantiation: obu.c:av1_read_uniform |
301 | | |
302 | | typedef void (*palette_visitor_fn_t)(MACROBLOCKD *const xd, int plane, |
303 | | aom_reader *r); |
304 | | |
305 | | void av1_visit_palette(AV1Decoder *const pbi, MACROBLOCKD *const xd, int mi_row, |
306 | | int mi_col, aom_reader *r, BLOCK_SIZE bsize, |
307 | | palette_visitor_fn_t visit); |
308 | | |
309 | | typedef void (*block_visitor_fn_t)(AV1Decoder *const pbi, ThreadData *const td, |
310 | | int mi_row, int mi_col, aom_reader *r, |
311 | | PARTITION_TYPE partition, BLOCK_SIZE bsize); |
312 | | |
313 | | #ifdef __cplusplus |
314 | | } // extern "C" |
315 | | #endif |
316 | | |
317 | | #endif // AOM_AV1_DECODER_DECODER_H_ |