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 #include <stdlib.h>
13 #include <string.h>
14
15 #include "config/aom_config.h"
16 #include "config/aom_version.h"
17
18 #include "aom/internal/aom_codec_internal.h"
19 #include "aom/internal/aom_image_internal.h"
20 #include "aom/aomdx.h"
21 #include "aom/aom_decoder.h"
22 #include "aom_dsp/bitreader_buffer.h"
23 #include "aom_dsp/aom_dsp_common.h"
24 #include "aom_ports/mem_ops.h"
25 #include "aom_util/aom_thread.h"
26
27 #include "av1/common/alloccommon.h"
28 #include "av1/common/frame_buffers.h"
29 #include "av1/common/enums.h"
30 #include "av1/common/obu_util.h"
31
32 #include "av1/decoder/decoder.h"
33 #include "av1/decoder/decodeframe.h"
34 #include "av1/decoder/obu.h"
35
36 #include "av1/av1_iface_common.h"
37
38 struct aom_codec_alg_priv {
39 aom_codec_priv_t base;
40 aom_codec_dec_cfg_t cfg;
41 aom_codec_stream_info_t si;
42 aom_image_t img;
43 int img_avail;
44 int flushed;
45 int invert_tile_order;
46 RefCntBuffer *last_show_frame; // Last output frame buffer
47 int byte_alignment;
48 int skip_loop_filter;
49 int skip_film_grain;
50 int decode_tile_row;
51 int decode_tile_col;
52 unsigned int tile_mode;
53 unsigned int ext_tile_debug;
54 unsigned int row_mt;
55 EXTERNAL_REFERENCES ext_refs;
56 unsigned int is_annexb;
57 int operating_point;
58 int output_all_layers;
59
60 AVxWorker *frame_worker;
61
62 aom_image_t image_with_grain;
63 aom_codec_frame_buffer_t grain_image_frame_buffers[MAX_NUM_SPATIAL_LAYERS];
64 size_t num_grain_image_frame_buffers;
65 int need_resync; // wait for key/intra-only frame
66 // BufferPool that holds all reference frames. Shared by all the FrameWorkers.
67 BufferPool *buffer_pool;
68
69 // External frame buffer info to save for AV1 common.
70 void *ext_priv; // Private data associated with the external frame buffers.
71 aom_get_frame_buffer_cb_fn_t get_ext_fb_cb;
72 aom_release_frame_buffer_cb_fn_t release_ext_fb_cb;
73
74 #if CONFIG_INSPECTION
75 aom_inspect_cb inspect_cb;
76 void *inspect_ctx;
77 #endif
78 };
79
decoder_init(aom_codec_ctx_t * ctx)80 static aom_codec_err_t decoder_init(aom_codec_ctx_t *ctx) {
81 // This function only allocates space for the aom_codec_alg_priv_t
82 // structure. More memory may be required at the time the stream
83 // information becomes known.
84 if (!ctx->priv) {
85 aom_codec_alg_priv_t *const priv =
86 (aom_codec_alg_priv_t *)aom_calloc(1, sizeof(*priv));
87 if (priv == NULL) return AOM_CODEC_MEM_ERROR;
88
89 ctx->priv = (aom_codec_priv_t *)priv;
90 ctx->priv->init_flags = ctx->init_flags;
91 priv->flushed = 0;
92
93 // TODO(tdaede): this should not be exposed to the API
94 priv->cfg.allow_lowbitdepth = !FORCE_HIGHBITDEPTH_DECODING;
95 if (ctx->config.dec) {
96 priv->cfg = *ctx->config.dec;
97 ctx->config.dec = &priv->cfg;
98 }
99 priv->num_grain_image_frame_buffers = 0;
100 // Turn row_mt on by default.
101 priv->row_mt = 1;
102
103 // Turn on normal tile coding mode by default.
104 // 0 is for normal tile coding mode, and 1 is for large scale tile coding
105 // mode(refer to lightfield example).
106 priv->tile_mode = 0;
107 priv->decode_tile_row = -1;
108 priv->decode_tile_col = -1;
109 }
110
111 return AOM_CODEC_OK;
112 }
113
decoder_destroy(aom_codec_alg_priv_t * ctx)114 static aom_codec_err_t decoder_destroy(aom_codec_alg_priv_t *ctx) {
115 if (ctx->frame_worker != NULL) {
116 AVxWorker *const worker = ctx->frame_worker;
117 FrameWorkerData *const frame_worker_data = (FrameWorkerData *)worker->data1;
118 aom_get_worker_interface()->end(worker);
119 aom_free(frame_worker_data->pbi->common.tpl_mvs);
120 frame_worker_data->pbi->common.tpl_mvs = NULL;
121 av1_remove_common(&frame_worker_data->pbi->common);
122 #if !CONFIG_REALTIME_ONLY
123 av1_free_restoration_buffers(&frame_worker_data->pbi->common);
124 #endif
125 av1_decoder_remove(frame_worker_data->pbi);
126 aom_free(frame_worker_data);
127 #if CONFIG_MULTITHREAD
128 pthread_mutex_destroy(&ctx->buffer_pool->pool_mutex);
129 #endif
130 }
131
132 if (ctx->buffer_pool) {
133 for (size_t i = 0; i < ctx->num_grain_image_frame_buffers; i++) {
134 ctx->buffer_pool->release_fb_cb(ctx->buffer_pool->cb_priv,
135 &ctx->grain_image_frame_buffers[i]);
136 }
137 av1_free_ref_frame_buffers(ctx->buffer_pool);
138 av1_free_internal_frame_buffers(&ctx->buffer_pool->int_frame_buffers);
139 }
140
141 aom_free(ctx->frame_worker);
142 aom_free(ctx->buffer_pool);
143 aom_img_free(&ctx->img);
144 aom_free(ctx);
145 return AOM_CODEC_OK;
146 }
147
parse_timing_info(struct aom_read_bit_buffer * rb)148 static aom_codec_err_t parse_timing_info(struct aom_read_bit_buffer *rb) {
149 const uint32_t num_units_in_display_tick =
150 aom_rb_read_unsigned_literal(rb, 32);
151 const uint32_t time_scale = aom_rb_read_unsigned_literal(rb, 32);
152 if (num_units_in_display_tick == 0 || time_scale == 0)
153 return AOM_CODEC_UNSUP_BITSTREAM;
154 const uint8_t equal_picture_interval = aom_rb_read_bit(rb);
155 if (equal_picture_interval) {
156 const uint32_t num_ticks_per_picture_minus_1 = aom_rb_read_uvlc(rb);
157 if (num_ticks_per_picture_minus_1 == UINT32_MAX) {
158 // num_ticks_per_picture_minus_1 cannot be (1 << 32) - 1.
159 return AOM_CODEC_UNSUP_BITSTREAM;
160 }
161 }
162 return AOM_CODEC_OK;
163 }
164
parse_decoder_model_info(struct aom_read_bit_buffer * rb,int * buffer_delay_length_minus_1)165 static aom_codec_err_t parse_decoder_model_info(
166 struct aom_read_bit_buffer *rb, int *buffer_delay_length_minus_1) {
167 *buffer_delay_length_minus_1 = aom_rb_read_literal(rb, 5);
168 const uint32_t num_units_in_decoding_tick =
169 aom_rb_read_unsigned_literal(rb, 32);
170 const uint8_t buffer_removal_time_length_minus_1 = aom_rb_read_literal(rb, 5);
171 const uint8_t frame_presentation_time_length_minus_1 =
172 aom_rb_read_literal(rb, 5);
173 (void)num_units_in_decoding_tick;
174 (void)buffer_removal_time_length_minus_1;
175 (void)frame_presentation_time_length_minus_1;
176 return AOM_CODEC_OK;
177 }
178
parse_op_parameters_info(struct aom_read_bit_buffer * rb,int buffer_delay_length_minus_1)179 static aom_codec_err_t parse_op_parameters_info(
180 struct aom_read_bit_buffer *rb, int buffer_delay_length_minus_1) {
181 const int n = buffer_delay_length_minus_1 + 1;
182 const uint32_t decoder_buffer_delay = aom_rb_read_unsigned_literal(rb, n);
183 const uint32_t encoder_buffer_delay = aom_rb_read_unsigned_literal(rb, n);
184 const uint8_t low_delay_mode_flag = aom_rb_read_bit(rb);
185 (void)decoder_buffer_delay;
186 (void)encoder_buffer_delay;
187 (void)low_delay_mode_flag;
188 return AOM_CODEC_OK;
189 }
190
191 // Parses the operating points (including operating_point_idc, seq_level_idx,
192 // and seq_tier) and then sets si->number_spatial_layers and
193 // si->number_temporal_layers based on operating_point_idc[0].
parse_operating_points(struct aom_read_bit_buffer * rb,int is_reduced_header,aom_codec_stream_info_t * si)194 static aom_codec_err_t parse_operating_points(struct aom_read_bit_buffer *rb,
195 int is_reduced_header,
196 aom_codec_stream_info_t *si) {
197 int operating_point_idc0 = 0;
198 if (is_reduced_header) {
199 aom_rb_read_literal(rb, LEVEL_BITS); // level
200 } else {
201 uint8_t decoder_model_info_present_flag = 0;
202 int buffer_delay_length_minus_1 = 0;
203 aom_codec_err_t status;
204 const uint8_t timing_info_present_flag = aom_rb_read_bit(rb);
205 if (timing_info_present_flag) {
206 if ((status = parse_timing_info(rb)) != AOM_CODEC_OK) return status;
207 decoder_model_info_present_flag = aom_rb_read_bit(rb);
208 if (decoder_model_info_present_flag) {
209 if ((status = parse_decoder_model_info(
210 rb, &buffer_delay_length_minus_1)) != AOM_CODEC_OK)
211 return status;
212 }
213 }
214 const uint8_t initial_display_delay_present_flag = aom_rb_read_bit(rb);
215 const uint8_t operating_points_cnt_minus_1 =
216 aom_rb_read_literal(rb, OP_POINTS_CNT_MINUS_1_BITS);
217 for (int i = 0; i < operating_points_cnt_minus_1 + 1; i++) {
218 int operating_point_idc;
219 operating_point_idc = aom_rb_read_literal(rb, OP_POINTS_IDC_BITS);
220 if (i == 0) operating_point_idc0 = operating_point_idc;
221 int seq_level_idx = aom_rb_read_literal(rb, LEVEL_BITS); // level
222 if (seq_level_idx > 7) aom_rb_read_bit(rb); // tier
223 if (decoder_model_info_present_flag) {
224 const uint8_t decoder_model_present_for_this_op = aom_rb_read_bit(rb);
225 if (decoder_model_present_for_this_op) {
226 if ((status = parse_op_parameters_info(
227 rb, buffer_delay_length_minus_1)) != AOM_CODEC_OK)
228 return status;
229 }
230 }
231 if (initial_display_delay_present_flag) {
232 const uint8_t initial_display_delay_present_for_this_op =
233 aom_rb_read_bit(rb);
234 if (initial_display_delay_present_for_this_op)
235 aom_rb_read_literal(rb, 4); // initial_display_delay_minus_1
236 }
237 }
238 }
239
240 if (aom_get_num_layers_from_operating_point_idc(
241 operating_point_idc0, &si->number_spatial_layers,
242 &si->number_temporal_layers) != AOM_CODEC_OK) {
243 return AOM_CODEC_ERROR;
244 }
245
246 return AOM_CODEC_OK;
247 }
248
decoder_peek_si_internal(const uint8_t * data,size_t data_sz,aom_codec_stream_info_t * si,int * is_intra_only)249 static aom_codec_err_t decoder_peek_si_internal(const uint8_t *data,
250 size_t data_sz,
251 aom_codec_stream_info_t *si,
252 int *is_intra_only) {
253 int intra_only_flag = 0;
254 int got_sequence_header = 0;
255 int found_keyframe = 0;
256
257 if (data + data_sz <= data || data_sz < 1) return AOM_CODEC_INVALID_PARAM;
258
259 si->w = 0;
260 si->h = 0;
261 si->is_kf = 0; // is_kf indicates whether the current packet contains a RAP
262
263 ObuHeader obu_header;
264 memset(&obu_header, 0, sizeof(obu_header));
265 size_t payload_size = 0;
266 size_t bytes_read = 0;
267 uint8_t reduced_still_picture_hdr = 0;
268 aom_codec_err_t status = aom_read_obu_header_and_size(
269 data, data_sz, si->is_annexb, &obu_header, &payload_size, &bytes_read);
270 if (status != AOM_CODEC_OK) return status;
271
272 // If the first OBU is a temporal delimiter, skip over it and look at the next
273 // OBU in the bitstream
274 if (obu_header.type == OBU_TEMPORAL_DELIMITER) {
275 // Skip any associated payload (there shouldn't be one, but just in case)
276 if (data_sz < bytes_read + payload_size) return AOM_CODEC_CORRUPT_FRAME;
277 data += bytes_read + payload_size;
278 data_sz -= bytes_read + payload_size;
279
280 status = aom_read_obu_header_and_size(
281 data, data_sz, si->is_annexb, &obu_header, &payload_size, &bytes_read);
282 if (status != AOM_CODEC_OK) return status;
283 }
284 while (1) {
285 data += bytes_read;
286 data_sz -= bytes_read;
287 if (data_sz < payload_size) return AOM_CODEC_CORRUPT_FRAME;
288 // Check that the selected OBU is a sequence header
289 if (obu_header.type == OBU_SEQUENCE_HEADER) {
290 // Sanity check on sequence header size
291 if (data_sz < 2) return AOM_CODEC_CORRUPT_FRAME;
292 // Read a few values from the sequence header payload
293 struct aom_read_bit_buffer rb = { data, data + data_sz, 0, NULL, NULL };
294
295 av1_read_profile(&rb); // profile
296 const uint8_t still_picture = aom_rb_read_bit(&rb);
297 reduced_still_picture_hdr = aom_rb_read_bit(&rb);
298
299 if (!still_picture && reduced_still_picture_hdr) {
300 return AOM_CODEC_UNSUP_BITSTREAM;
301 }
302
303 if (parse_operating_points(&rb, reduced_still_picture_hdr, si) !=
304 AOM_CODEC_OK) {
305 return AOM_CODEC_ERROR;
306 }
307
308 int num_bits_width = aom_rb_read_literal(&rb, 4) + 1;
309 int num_bits_height = aom_rb_read_literal(&rb, 4) + 1;
310 int max_frame_width = aom_rb_read_literal(&rb, num_bits_width) + 1;
311 int max_frame_height = aom_rb_read_literal(&rb, num_bits_height) + 1;
312 si->w = max_frame_width;
313 si->h = max_frame_height;
314 got_sequence_header = 1;
315 } else if (obu_header.type == OBU_FRAME_HEADER ||
316 obu_header.type == OBU_FRAME) {
317 if (got_sequence_header && reduced_still_picture_hdr) {
318 found_keyframe = 1;
319 break;
320 } else {
321 // make sure we have enough bits to get the frame type out
322 if (data_sz < 1) return AOM_CODEC_CORRUPT_FRAME;
323 struct aom_read_bit_buffer rb = { data, data + data_sz, 0, NULL, NULL };
324 const int show_existing_frame = aom_rb_read_bit(&rb);
325 if (!show_existing_frame) {
326 const FRAME_TYPE frame_type = (FRAME_TYPE)aom_rb_read_literal(&rb, 2);
327 if (frame_type == KEY_FRAME) {
328 found_keyframe = 1;
329 break; // Stop here as no further OBUs will change the outcome.
330 } else if (frame_type == INTRA_ONLY_FRAME) {
331 intra_only_flag = 1;
332 }
333 }
334 }
335 }
336 // skip past any unread OBU header data
337 data += payload_size;
338 data_sz -= payload_size;
339 if (data_sz == 0) break; // exit if we're out of OBUs
340 status = aom_read_obu_header_and_size(
341 data, data_sz, si->is_annexb, &obu_header, &payload_size, &bytes_read);
342 if (status != AOM_CODEC_OK) return status;
343 }
344 if (got_sequence_header && found_keyframe) si->is_kf = 1;
345 if (is_intra_only != NULL) *is_intra_only = intra_only_flag;
346 return AOM_CODEC_OK;
347 }
348
decoder_peek_si(const uint8_t * data,size_t data_sz,aom_codec_stream_info_t * si)349 static aom_codec_err_t decoder_peek_si(const uint8_t *data, size_t data_sz,
350 aom_codec_stream_info_t *si) {
351 return decoder_peek_si_internal(data, data_sz, si, NULL);
352 }
353
decoder_get_si(aom_codec_alg_priv_t * ctx,aom_codec_stream_info_t * si)354 static aom_codec_err_t decoder_get_si(aom_codec_alg_priv_t *ctx,
355 aom_codec_stream_info_t *si) {
356 memcpy(si, &ctx->si, sizeof(*si));
357
358 return AOM_CODEC_OK;
359 }
360
set_error_detail(aom_codec_alg_priv_t * ctx,const char * const error)361 static void set_error_detail(aom_codec_alg_priv_t *ctx,
362 const char *const error) {
363 ctx->base.err_detail = error;
364 }
365
update_error_state(aom_codec_alg_priv_t * ctx,const struct aom_internal_error_info * error)366 static aom_codec_err_t update_error_state(
367 aom_codec_alg_priv_t *ctx, const struct aom_internal_error_info *error) {
368 if (error->error_code)
369 set_error_detail(ctx, error->has_detail ? error->detail : NULL);
370
371 return error->error_code;
372 }
373
init_buffer_callbacks(aom_codec_alg_priv_t * ctx)374 static void init_buffer_callbacks(aom_codec_alg_priv_t *ctx) {
375 AVxWorker *const worker = ctx->frame_worker;
376 FrameWorkerData *const frame_worker_data = (FrameWorkerData *)worker->data1;
377 AV1Decoder *const pbi = frame_worker_data->pbi;
378 AV1_COMMON *const cm = &pbi->common;
379 BufferPool *const pool = cm->buffer_pool;
380
381 cm->cur_frame = NULL;
382 cm->features.byte_alignment = ctx->byte_alignment;
383 pbi->skip_loop_filter = ctx->skip_loop_filter;
384 pbi->skip_film_grain = ctx->skip_film_grain;
385
386 if (ctx->get_ext_fb_cb != NULL && ctx->release_ext_fb_cb != NULL) {
387 pool->get_fb_cb = ctx->get_ext_fb_cb;
388 pool->release_fb_cb = ctx->release_ext_fb_cb;
389 pool->cb_priv = ctx->ext_priv;
390 } else {
391 pool->get_fb_cb = av1_get_frame_buffer;
392 pool->release_fb_cb = av1_release_frame_buffer;
393
394 if (av1_alloc_internal_frame_buffers(&pool->int_frame_buffers))
395 aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR,
396 "Failed to initialize internal frame buffers");
397
398 pool->cb_priv = &pool->int_frame_buffers;
399 }
400 }
401
frame_worker_hook(void * arg1,void * arg2)402 static int frame_worker_hook(void *arg1, void *arg2) {
403 FrameWorkerData *const frame_worker_data = (FrameWorkerData *)arg1;
404 const uint8_t *data = frame_worker_data->data;
405 (void)arg2;
406
407 int result = av1_receive_compressed_data(frame_worker_data->pbi,
408 frame_worker_data->data_size, &data);
409 frame_worker_data->data_end = data;
410
411 if (result != 0) {
412 // Check decode result in serial decode.
413 frame_worker_data->pbi->need_resync = 1;
414 }
415 return !result;
416 }
417
init_decoder(aom_codec_alg_priv_t * ctx)418 static aom_codec_err_t init_decoder(aom_codec_alg_priv_t *ctx) {
419 const AVxWorkerInterface *const winterface = aom_get_worker_interface();
420
421 ctx->last_show_frame = NULL;
422 ctx->need_resync = 1;
423 ctx->flushed = 0;
424
425 ctx->buffer_pool = (BufferPool *)aom_calloc(1, sizeof(BufferPool));
426 if (ctx->buffer_pool == NULL) return AOM_CODEC_MEM_ERROR;
427
428 #if CONFIG_MULTITHREAD
429 if (pthread_mutex_init(&ctx->buffer_pool->pool_mutex, NULL)) {
430 set_error_detail(ctx, "Failed to allocate buffer pool mutex");
431 return AOM_CODEC_MEM_ERROR;
432 }
433 #endif
434
435 ctx->frame_worker = (AVxWorker *)aom_malloc(sizeof(*ctx->frame_worker));
436 if (ctx->frame_worker == NULL) {
437 set_error_detail(ctx, "Failed to allocate frame_worker");
438 return AOM_CODEC_MEM_ERROR;
439 }
440
441 AVxWorker *const worker = ctx->frame_worker;
442 FrameWorkerData *frame_worker_data = NULL;
443 winterface->init(worker);
444 worker->thread_name = "aom frameworker";
445 worker->data1 = aom_memalign(32, sizeof(FrameWorkerData));
446 if (worker->data1 == NULL) {
447 set_error_detail(ctx, "Failed to allocate frame_worker_data");
448 return AOM_CODEC_MEM_ERROR;
449 }
450 frame_worker_data = (FrameWorkerData *)worker->data1;
451 frame_worker_data->pbi = av1_decoder_create(ctx->buffer_pool);
452 if (frame_worker_data->pbi == NULL) {
453 set_error_detail(ctx, "Failed to allocate frame_worker_data");
454 return AOM_CODEC_MEM_ERROR;
455 }
456 frame_worker_data->frame_context_ready = 0;
457 frame_worker_data->received_frame = 0;
458 frame_worker_data->pbi->allow_lowbitdepth = ctx->cfg.allow_lowbitdepth;
459
460 // If decoding in serial mode, FrameWorker thread could create tile worker
461 // thread or loopfilter thread.
462 frame_worker_data->pbi->max_threads = ctx->cfg.threads;
463 frame_worker_data->pbi->inv_tile_order = ctx->invert_tile_order;
464 frame_worker_data->pbi->common.tiles.large_scale = ctx->tile_mode;
465 frame_worker_data->pbi->is_annexb = ctx->is_annexb;
466 frame_worker_data->pbi->dec_tile_row = ctx->decode_tile_row;
467 frame_worker_data->pbi->dec_tile_col = ctx->decode_tile_col;
468 frame_worker_data->pbi->operating_point = ctx->operating_point;
469 frame_worker_data->pbi->output_all_layers = ctx->output_all_layers;
470 frame_worker_data->pbi->ext_tile_debug = ctx->ext_tile_debug;
471 frame_worker_data->pbi->row_mt = ctx->row_mt;
472 frame_worker_data->pbi->is_fwd_kf_present = 0;
473 frame_worker_data->pbi->is_arf_frame_present = 0;
474 worker->hook = frame_worker_hook;
475
476 init_buffer_callbacks(ctx);
477
478 return AOM_CODEC_OK;
479 }
480
check_resync(aom_codec_alg_priv_t * const ctx,const AV1Decoder * const pbi)481 static INLINE void check_resync(aom_codec_alg_priv_t *const ctx,
482 const AV1Decoder *const pbi) {
483 // Clear resync flag if worker got a key frame or intra only frame.
484 if (ctx->need_resync == 1 && pbi->need_resync == 0 &&
485 frame_is_intra_only(&pbi->common))
486 ctx->need_resync = 0;
487 }
488
decode_one(aom_codec_alg_priv_t * ctx,const uint8_t ** data,size_t data_sz,void * user_priv)489 static aom_codec_err_t decode_one(aom_codec_alg_priv_t *ctx,
490 const uint8_t **data, size_t data_sz,
491 void *user_priv) {
492 const AVxWorkerInterface *const winterface = aom_get_worker_interface();
493
494 // Determine the stream parameters. Note that we rely on peek_si to
495 // validate that we have a buffer that does not wrap around the top
496 // of the heap.
497 if (!ctx->si.h) {
498 int is_intra_only = 0;
499 ctx->si.is_annexb = ctx->is_annexb;
500 const aom_codec_err_t res =
501 decoder_peek_si_internal(*data, data_sz, &ctx->si, &is_intra_only);
502 if (res != AOM_CODEC_OK) return res;
503
504 if (!ctx->si.is_kf && !is_intra_only) return AOM_CODEC_ERROR;
505 }
506
507 AVxWorker *const worker = ctx->frame_worker;
508 FrameWorkerData *const frame_worker_data = (FrameWorkerData *)worker->data1;
509 frame_worker_data->data = *data;
510 frame_worker_data->data_size = data_sz;
511 frame_worker_data->user_priv = user_priv;
512 frame_worker_data->received_frame = 1;
513
514 frame_worker_data->pbi->common.tiles.large_scale = ctx->tile_mode;
515 frame_worker_data->pbi->dec_tile_row = ctx->decode_tile_row;
516 frame_worker_data->pbi->dec_tile_col = ctx->decode_tile_col;
517 frame_worker_data->pbi->ext_tile_debug = ctx->ext_tile_debug;
518 frame_worker_data->pbi->row_mt = ctx->row_mt;
519 frame_worker_data->pbi->ext_refs = ctx->ext_refs;
520
521 frame_worker_data->pbi->is_annexb = ctx->is_annexb;
522
523 worker->had_error = 0;
524 winterface->execute(worker);
525
526 // Update data pointer after decode.
527 *data = frame_worker_data->data_end;
528
529 if (worker->had_error)
530 return update_error_state(ctx, &frame_worker_data->pbi->common.error);
531
532 check_resync(ctx, frame_worker_data->pbi);
533
534 return AOM_CODEC_OK;
535 }
536
537 #if CONFIG_INSPECTION
538 // This function enables the inspector to inspect non visible frames.
decoder_inspect(aom_codec_alg_priv_t * ctx,const uint8_t * data,size_t data_sz,void * user_priv)539 static aom_codec_err_t decoder_inspect(aom_codec_alg_priv_t *ctx,
540 const uint8_t *data, size_t data_sz,
541 void *user_priv) {
542 aom_codec_err_t res = AOM_CODEC_OK;
543
544 const uint8_t *const data_end = data + data_sz;
545 Av1DecodeReturn *data2 = (Av1DecodeReturn *)user_priv;
546
547 if (ctx->frame_worker == NULL) {
548 res = init_decoder(ctx);
549 if (res != AOM_CODEC_OK) return res;
550 }
551 FrameWorkerData *const frame_worker_data =
552 (FrameWorkerData *)ctx->frame_worker->data1;
553 AV1Decoder *const pbi = frame_worker_data->pbi;
554 AV1_COMMON *const cm = &pbi->common;
555 frame_worker_data->pbi->inspect_cb = ctx->inspect_cb;
556 frame_worker_data->pbi->inspect_ctx = ctx->inspect_ctx;
557 res = av1_receive_compressed_data(frame_worker_data->pbi, data_sz, &data);
558 check_resync(ctx, frame_worker_data->pbi);
559
560 if (ctx->frame_worker->had_error)
561 return update_error_state(ctx, &frame_worker_data->pbi->common.error);
562
563 // Allow extra zero bytes after the frame end
564 while (data < data_end) {
565 const uint8_t marker = data[0];
566 if (marker) break;
567 ++data;
568 }
569
570 data2->idx = -1;
571 for (int i = 0; i < REF_FRAMES; ++i)
572 if (cm->ref_frame_map[i] == cm->cur_frame) data2->idx = i;
573 data2->buf = data;
574 data2->show_existing = cm->show_existing_frame;
575 return res;
576 }
577 #endif
578
decoder_decode(aom_codec_alg_priv_t * ctx,const uint8_t * data,size_t data_sz,void * user_priv)579 static aom_codec_err_t decoder_decode(aom_codec_alg_priv_t *ctx,
580 const uint8_t *data, size_t data_sz,
581 void *user_priv) {
582 aom_codec_err_t res = AOM_CODEC_OK;
583
584 #if CONFIG_INSPECTION
585 if (user_priv != 0) {
586 return decoder_inspect(ctx, data, data_sz, user_priv);
587 }
588 #endif
589 // Release any pending output frames from the previous decoder_decode call.
590 // We need to do this even if the decoder is being flushed or the input
591 // arguments are invalid.
592 if (ctx->frame_worker) {
593 BufferPool *const pool = ctx->buffer_pool;
594 lock_buffer_pool(pool);
595 AVxWorker *const worker = ctx->frame_worker;
596 FrameWorkerData *const frame_worker_data = (FrameWorkerData *)worker->data1;
597 struct AV1Decoder *pbi = frame_worker_data->pbi;
598 for (size_t j = 0; j < pbi->num_output_frames; j++) {
599 decrease_ref_count(pbi->output_frames[j], pool);
600 }
601 pbi->num_output_frames = 0;
602 unlock_buffer_pool(pool);
603 for (size_t j = 0; j < ctx->num_grain_image_frame_buffers; j++) {
604 pool->release_fb_cb(pool->cb_priv, &ctx->grain_image_frame_buffers[j]);
605 ctx->grain_image_frame_buffers[j].data = NULL;
606 ctx->grain_image_frame_buffers[j].size = 0;
607 ctx->grain_image_frame_buffers[j].priv = NULL;
608 }
609 ctx->num_grain_image_frame_buffers = 0;
610 }
611
612 /* Sanity checks */
613 /* NULL data ptr allowed if data_sz is 0 too */
614 if (data == NULL && data_sz == 0) {
615 ctx->flushed = 1;
616 return AOM_CODEC_OK;
617 }
618 if (data == NULL || data_sz == 0) return AOM_CODEC_INVALID_PARAM;
619
620 // Reset flushed when receiving a valid frame.
621 ctx->flushed = 0;
622
623 // Initialize the decoder worker on the first frame.
624 if (ctx->frame_worker == NULL) {
625 res = init_decoder(ctx);
626 if (res != AOM_CODEC_OK) return res;
627 }
628
629 const uint8_t *data_start = data;
630 const uint8_t *data_end = data + data_sz;
631
632 if (ctx->is_annexb) {
633 // read the size of this temporal unit
634 size_t length_of_size;
635 uint64_t temporal_unit_size;
636 if (aom_uleb_decode(data_start, data_sz, &temporal_unit_size,
637 &length_of_size) != 0) {
638 return AOM_CODEC_CORRUPT_FRAME;
639 }
640 data_start += length_of_size;
641 if (temporal_unit_size > (size_t)(data_end - data_start))
642 return AOM_CODEC_CORRUPT_FRAME;
643 data_end = data_start + temporal_unit_size;
644 }
645
646 // Decode in serial mode.
647 while (data_start < data_end) {
648 uint64_t frame_size;
649 if (ctx->is_annexb) {
650 // read the size of this frame unit
651 size_t length_of_size;
652 if (aom_uleb_decode(data_start, (size_t)(data_end - data_start),
653 &frame_size, &length_of_size) != 0) {
654 return AOM_CODEC_CORRUPT_FRAME;
655 }
656 data_start += length_of_size;
657 if (frame_size > (size_t)(data_end - data_start))
658 return AOM_CODEC_CORRUPT_FRAME;
659 } else {
660 frame_size = (uint64_t)(data_end - data_start);
661 }
662
663 res = decode_one(ctx, &data_start, (size_t)frame_size, user_priv);
664 if (res != AOM_CODEC_OK) return res;
665
666 // Allow extra zero bytes after the frame end
667 while (data_start < data_end) {
668 const uint8_t marker = data_start[0];
669 if (marker) break;
670 ++data_start;
671 }
672 }
673
674 return res;
675 }
676
677 typedef struct {
678 BufferPool *pool;
679 aom_codec_frame_buffer_t *fb;
680 } AllocCbParam;
681
AllocWithGetFrameBufferCb(void * priv,size_t size)682 static void *AllocWithGetFrameBufferCb(void *priv, size_t size) {
683 AllocCbParam *param = (AllocCbParam *)priv;
684 if (param->pool->get_fb_cb(param->pool->cb_priv, size, param->fb) < 0)
685 return NULL;
686 if (param->fb->data == NULL || param->fb->size < size) return NULL;
687 return param->fb->data;
688 }
689
690 // If grain_params->apply_grain is false, returns img. Otherwise, adds film
691 // grain to img, saves the result in grain_img, and returns grain_img.
add_grain_if_needed(aom_codec_alg_priv_t * ctx,aom_image_t * img,aom_image_t * grain_img,aom_film_grain_t * grain_params)692 static aom_image_t *add_grain_if_needed(aom_codec_alg_priv_t *ctx,
693 aom_image_t *img,
694 aom_image_t *grain_img,
695 aom_film_grain_t *grain_params) {
696 if (!grain_params->apply_grain) return img;
697
698 const int w_even = ALIGN_POWER_OF_TWO(img->d_w, 1);
699 const int h_even = ALIGN_POWER_OF_TWO(img->d_h, 1);
700
701 BufferPool *const pool = ctx->buffer_pool;
702 aom_codec_frame_buffer_t *fb =
703 &ctx->grain_image_frame_buffers[ctx->num_grain_image_frame_buffers];
704 AllocCbParam param;
705 param.pool = pool;
706 param.fb = fb;
707 if (!aom_img_alloc_with_cb(grain_img, img->fmt, w_even, h_even, 16,
708 AllocWithGetFrameBufferCb, ¶m)) {
709 return NULL;
710 }
711
712 grain_img->user_priv = img->user_priv;
713 grain_img->fb_priv = fb->priv;
714 if (av1_add_film_grain(grain_params, img, grain_img)) {
715 pool->release_fb_cb(pool->cb_priv, fb);
716 return NULL;
717 }
718
719 ctx->num_grain_image_frame_buffers++;
720 return grain_img;
721 }
722
723 // Copies and clears the metadata from AV1Decoder.
move_decoder_metadata_to_img(AV1Decoder * pbi,aom_image_t * img)724 static void move_decoder_metadata_to_img(AV1Decoder *pbi, aom_image_t *img) {
725 if (pbi->metadata && img) {
726 assert(!img->metadata);
727 img->metadata = pbi->metadata;
728 pbi->metadata = NULL;
729 }
730 }
731
decoder_get_frame(aom_codec_alg_priv_t * ctx,aom_codec_iter_t * iter)732 static aom_image_t *decoder_get_frame(aom_codec_alg_priv_t *ctx,
733 aom_codec_iter_t *iter) {
734 aom_image_t *img = NULL;
735
736 if (!iter) {
737 return NULL;
738 }
739
740 // To avoid having to allocate any extra storage, treat 'iter' as
741 // simply a pointer to an integer index
742 uintptr_t *index = (uintptr_t *)iter;
743
744 if (ctx->frame_worker != NULL) {
745 const AVxWorkerInterface *const winterface = aom_get_worker_interface();
746 AVxWorker *const worker = ctx->frame_worker;
747 FrameWorkerData *const frame_worker_data = (FrameWorkerData *)worker->data1;
748 AV1Decoder *const pbi = frame_worker_data->pbi;
749 AV1_COMMON *const cm = &pbi->common;
750 CommonTileParams *const tiles = &cm->tiles;
751 // Wait for the frame from worker thread.
752 if (winterface->sync(worker)) {
753 // Check if worker has received any frames.
754 if (frame_worker_data->received_frame == 1) {
755 frame_worker_data->received_frame = 0;
756 check_resync(ctx, frame_worker_data->pbi);
757 }
758 YV12_BUFFER_CONFIG *sd;
759 aom_film_grain_t *grain_params;
760 if (av1_get_raw_frame(frame_worker_data->pbi, *index, &sd,
761 &grain_params) == 0) {
762 RefCntBuffer *const output_frame_buf = pbi->output_frames[*index];
763 ctx->last_show_frame = output_frame_buf;
764 if (ctx->need_resync) return NULL;
765 aom_img_remove_metadata(&ctx->img);
766 yuvconfig2image(&ctx->img, sd, frame_worker_data->user_priv);
767 move_decoder_metadata_to_img(pbi, &ctx->img);
768
769 if (!pbi->ext_tile_debug && tiles->large_scale) {
770 *index += 1; // Advance the iterator to point to the next image
771 aom_img_remove_metadata(&ctx->img);
772 yuvconfig2image(&ctx->img, &pbi->tile_list_outbuf, NULL);
773 move_decoder_metadata_to_img(pbi, &ctx->img);
774 img = &ctx->img;
775 return img;
776 }
777
778 const int num_planes = av1_num_planes(cm);
779 if (pbi->ext_tile_debug && tiles->single_tile_decoding &&
780 pbi->dec_tile_row >= 0) {
781 int tile_width, tile_height;
782 av1_get_uniform_tile_size(cm, &tile_width, &tile_height);
783 const int tile_row = AOMMIN(pbi->dec_tile_row, tiles->rows - 1);
784 const int mi_row = tile_row * tile_height;
785 const int ssy = ctx->img.y_chroma_shift;
786 int plane;
787 ctx->img.planes[0] += mi_row * MI_SIZE * ctx->img.stride[0];
788 if (num_planes > 1) {
789 for (plane = 1; plane < MAX_MB_PLANE; ++plane) {
790 ctx->img.planes[plane] +=
791 mi_row * (MI_SIZE >> ssy) * ctx->img.stride[plane];
792 }
793 }
794 ctx->img.d_h =
795 AOMMIN(tile_height, cm->mi_params.mi_rows - mi_row) * MI_SIZE;
796 }
797
798 if (pbi->ext_tile_debug && tiles->single_tile_decoding &&
799 pbi->dec_tile_col >= 0) {
800 int tile_width, tile_height;
801 av1_get_uniform_tile_size(cm, &tile_width, &tile_height);
802 const int tile_col = AOMMIN(pbi->dec_tile_col, tiles->cols - 1);
803 const int mi_col = tile_col * tile_width;
804 const int ssx = ctx->img.x_chroma_shift;
805 const int is_hbd = (ctx->img.fmt & AOM_IMG_FMT_HIGHBITDEPTH) ? 1 : 0;
806 int plane;
807 ctx->img.planes[0] += mi_col * MI_SIZE * (1 + is_hbd);
808 if (num_planes > 1) {
809 for (plane = 1; plane < MAX_MB_PLANE; ++plane) {
810 ctx->img.planes[plane] +=
811 mi_col * (MI_SIZE >> ssx) * (1 + is_hbd);
812 }
813 }
814 ctx->img.d_w =
815 AOMMIN(tile_width, cm->mi_params.mi_cols - mi_col) * MI_SIZE;
816 }
817
818 ctx->img.fb_priv = output_frame_buf->raw_frame_buffer.priv;
819 img = &ctx->img;
820 img->temporal_id = cm->temporal_layer_id;
821 img->spatial_id = cm->spatial_layer_id;
822 if (pbi->skip_film_grain) grain_params->apply_grain = 0;
823 aom_image_t *res =
824 add_grain_if_needed(ctx, img, &ctx->image_with_grain, grain_params);
825 if (!res) {
826 aom_internal_error(&pbi->common.error, AOM_CODEC_CORRUPT_FRAME,
827 "Grain systhesis failed\n");
828 }
829 *index += 1; // Advance the iterator to point to the next image
830 return res;
831 }
832 } else {
833 // Decoding failed. Release the worker thread.
834 frame_worker_data->received_frame = 0;
835 ctx->need_resync = 1;
836 if (ctx->flushed != 1) return NULL;
837 }
838 }
839 return NULL;
840 }
841
decoder_set_fb_fn(aom_codec_alg_priv_t * ctx,aom_get_frame_buffer_cb_fn_t cb_get,aom_release_frame_buffer_cb_fn_t cb_release,void * cb_priv)842 static aom_codec_err_t decoder_set_fb_fn(
843 aom_codec_alg_priv_t *ctx, aom_get_frame_buffer_cb_fn_t cb_get,
844 aom_release_frame_buffer_cb_fn_t cb_release, void *cb_priv) {
845 if (cb_get == NULL || cb_release == NULL) {
846 return AOM_CODEC_INVALID_PARAM;
847 } else if (ctx->frame_worker == NULL) {
848 // If the decoder has already been initialized, do not accept changes to
849 // the frame buffer functions.
850 ctx->get_ext_fb_cb = cb_get;
851 ctx->release_ext_fb_cb = cb_release;
852 ctx->ext_priv = cb_priv;
853 return AOM_CODEC_OK;
854 }
855
856 return AOM_CODEC_ERROR;
857 }
858
ctrl_set_reference(aom_codec_alg_priv_t * ctx,va_list args)859 static aom_codec_err_t ctrl_set_reference(aom_codec_alg_priv_t *ctx,
860 va_list args) {
861 av1_ref_frame_t *const data = va_arg(args, av1_ref_frame_t *);
862
863 if (data) {
864 av1_ref_frame_t *const frame = data;
865 YV12_BUFFER_CONFIG sd;
866 AVxWorker *const worker = ctx->frame_worker;
867 FrameWorkerData *const frame_worker_data = (FrameWorkerData *)worker->data1;
868 image2yuvconfig(&frame->img, &sd);
869 return av1_set_reference_dec(&frame_worker_data->pbi->common, frame->idx,
870 frame->use_external_ref, &sd);
871 } else {
872 return AOM_CODEC_INVALID_PARAM;
873 }
874 }
875
ctrl_copy_reference(aom_codec_alg_priv_t * ctx,va_list args)876 static aom_codec_err_t ctrl_copy_reference(aom_codec_alg_priv_t *ctx,
877 va_list args) {
878 const av1_ref_frame_t *const frame = va_arg(args, av1_ref_frame_t *);
879 if (frame) {
880 YV12_BUFFER_CONFIG sd;
881 AVxWorker *const worker = ctx->frame_worker;
882 FrameWorkerData *const frame_worker_data = (FrameWorkerData *)worker->data1;
883 image2yuvconfig(&frame->img, &sd);
884 return av1_copy_reference_dec(frame_worker_data->pbi, frame->idx, &sd);
885 } else {
886 return AOM_CODEC_INVALID_PARAM;
887 }
888 }
889
ctrl_get_reference(aom_codec_alg_priv_t * ctx,va_list args)890 static aom_codec_err_t ctrl_get_reference(aom_codec_alg_priv_t *ctx,
891 va_list args) {
892 av1_ref_frame_t *data = va_arg(args, av1_ref_frame_t *);
893 if (data) {
894 YV12_BUFFER_CONFIG *fb;
895 AVxWorker *const worker = ctx->frame_worker;
896 FrameWorkerData *const frame_worker_data = (FrameWorkerData *)worker->data1;
897 fb = get_ref_frame(&frame_worker_data->pbi->common, data->idx);
898 if (fb == NULL) return AOM_CODEC_ERROR;
899 yuvconfig2image(&data->img, fb, NULL);
900 return AOM_CODEC_OK;
901 } else {
902 return AOM_CODEC_INVALID_PARAM;
903 }
904 }
905
ctrl_get_new_frame_image(aom_codec_alg_priv_t * ctx,va_list args)906 static aom_codec_err_t ctrl_get_new_frame_image(aom_codec_alg_priv_t *ctx,
907 va_list args) {
908 aom_image_t *new_img = va_arg(args, aom_image_t *);
909 if (new_img) {
910 YV12_BUFFER_CONFIG new_frame;
911 AVxWorker *const worker = ctx->frame_worker;
912 FrameWorkerData *const frame_worker_data = (FrameWorkerData *)worker->data1;
913
914 if (av1_get_frame_to_show(frame_worker_data->pbi, &new_frame) == 0) {
915 yuvconfig2image(new_img, &new_frame, NULL);
916 return AOM_CODEC_OK;
917 } else {
918 return AOM_CODEC_ERROR;
919 }
920 } else {
921 return AOM_CODEC_INVALID_PARAM;
922 }
923 }
924
ctrl_copy_new_frame_image(aom_codec_alg_priv_t * ctx,va_list args)925 static aom_codec_err_t ctrl_copy_new_frame_image(aom_codec_alg_priv_t *ctx,
926 va_list args) {
927 aom_image_t *img = va_arg(args, aom_image_t *);
928 if (img) {
929 YV12_BUFFER_CONFIG new_frame;
930 AVxWorker *const worker = ctx->frame_worker;
931 FrameWorkerData *const frame_worker_data = (FrameWorkerData *)worker->data1;
932
933 if (av1_get_frame_to_show(frame_worker_data->pbi, &new_frame) == 0) {
934 YV12_BUFFER_CONFIG sd;
935 image2yuvconfig(img, &sd);
936 return av1_copy_new_frame_dec(&frame_worker_data->pbi->common, &new_frame,
937 &sd);
938 } else {
939 return AOM_CODEC_ERROR;
940 }
941 } else {
942 return AOM_CODEC_INVALID_PARAM;
943 }
944 }
945
ctrl_get_last_ref_updates(aom_codec_alg_priv_t * ctx,va_list args)946 static aom_codec_err_t ctrl_get_last_ref_updates(aom_codec_alg_priv_t *ctx,
947 va_list args) {
948 int *const update_info = va_arg(args, int *);
949
950 if (update_info) {
951 if (ctx->frame_worker) {
952 AVxWorker *const worker = ctx->frame_worker;
953 FrameWorkerData *const frame_worker_data =
954 (FrameWorkerData *)worker->data1;
955 *update_info =
956 frame_worker_data->pbi->common.current_frame.refresh_frame_flags;
957 return AOM_CODEC_OK;
958 } else {
959 return AOM_CODEC_ERROR;
960 }
961 }
962
963 return AOM_CODEC_INVALID_PARAM;
964 }
965
ctrl_get_last_quantizer(aom_codec_alg_priv_t * ctx,va_list args)966 static aom_codec_err_t ctrl_get_last_quantizer(aom_codec_alg_priv_t *ctx,
967 va_list args) {
968 int *const arg = va_arg(args, int *);
969 if (arg == NULL) return AOM_CODEC_INVALID_PARAM;
970 if (ctx->frame_worker == NULL) return AOM_CODEC_ERROR;
971 *arg = ((FrameWorkerData *)ctx->frame_worker->data1)
972 ->pbi->common.quant_params.base_qindex;
973 return AOM_CODEC_OK;
974 }
975
ctrl_get_fwd_kf_value(aom_codec_alg_priv_t * ctx,va_list args)976 static aom_codec_err_t ctrl_get_fwd_kf_value(aom_codec_alg_priv_t *ctx,
977 va_list args) {
978 int *const arg = va_arg(args, int *);
979 if (arg == NULL) return AOM_CODEC_INVALID_PARAM;
980 if (ctx->frame_worker == NULL) return AOM_CODEC_ERROR;
981 *arg = ((FrameWorkerData *)ctx->frame_worker->data1)->pbi->is_fwd_kf_present;
982 return AOM_CODEC_OK;
983 }
984
ctrl_get_altref_present(aom_codec_alg_priv_t * ctx,va_list args)985 static aom_codec_err_t ctrl_get_altref_present(aom_codec_alg_priv_t *ctx,
986 va_list args) {
987 int *const arg = va_arg(args, int *);
988 if (arg == NULL) return AOM_CODEC_INVALID_PARAM;
989 if (ctx->frame_worker == NULL) return AOM_CODEC_ERROR;
990 *arg =
991 ((FrameWorkerData *)ctx->frame_worker->data1)->pbi->is_arf_frame_present;
992 return AOM_CODEC_OK;
993 }
994
ctrl_get_frame_flags(aom_codec_alg_priv_t * ctx,va_list args)995 static aom_codec_err_t ctrl_get_frame_flags(aom_codec_alg_priv_t *ctx,
996 va_list args) {
997 int *const arg = va_arg(args, int *);
998 if (arg == NULL) return AOM_CODEC_INVALID_PARAM;
999 if (ctx->frame_worker == NULL) return AOM_CODEC_ERROR;
1000 AV1Decoder *pbi = ((FrameWorkerData *)ctx->frame_worker->data1)->pbi;
1001 *arg = 0;
1002 switch (pbi->common.current_frame.frame_type) {
1003 case KEY_FRAME:
1004 *arg |= AOM_FRAME_IS_KEY;
1005 *arg |= AOM_FRAME_IS_INTRAONLY;
1006 if (!pbi->common.show_frame) {
1007 *arg |= AOM_FRAME_IS_DELAYED_RANDOM_ACCESS_POINT;
1008 }
1009 break;
1010 case INTRA_ONLY_FRAME: *arg |= AOM_FRAME_IS_INTRAONLY; break;
1011 case S_FRAME: *arg |= AOM_FRAME_IS_SWITCH; break;
1012 }
1013 if (pbi->common.features.error_resilient_mode) {
1014 *arg |= AOM_FRAME_IS_ERROR_RESILIENT;
1015 }
1016 return AOM_CODEC_OK;
1017 }
1018
ctrl_get_tile_info(aom_codec_alg_priv_t * ctx,va_list args)1019 static aom_codec_err_t ctrl_get_tile_info(aom_codec_alg_priv_t *ctx,
1020 va_list args) {
1021 aom_tile_info *const tile_info = va_arg(args, aom_tile_info *);
1022
1023 if (tile_info) {
1024 if (ctx->frame_worker) {
1025 AVxWorker *const worker = ctx->frame_worker;
1026 FrameWorkerData *const frame_worker_data =
1027 (FrameWorkerData *)worker->data1;
1028 const AV1Decoder *pbi = frame_worker_data->pbi;
1029 const CommonTileParams *tiles = &pbi->common.tiles;
1030
1031 int tile_rows = tiles->rows;
1032 int tile_cols = tiles->cols;
1033
1034 if (tiles->uniform_spacing) {
1035 tile_info->tile_rows = 1 << tiles->log2_rows;
1036 tile_info->tile_columns = 1 << tiles->log2_cols;
1037 } else {
1038 tile_info->tile_rows = tile_rows;
1039 tile_info->tile_columns = tile_cols;
1040 }
1041
1042 for (int tile_col = 1; tile_col <= tile_cols; tile_col++) {
1043 tile_info->tile_widths[tile_col - 1] =
1044 tiles->col_start_sb[tile_col] - tiles->col_start_sb[tile_col - 1];
1045 }
1046
1047 for (int tile_row = 1; tile_row <= tile_rows; tile_row++) {
1048 tile_info->tile_heights[tile_row - 1] =
1049 tiles->row_start_sb[tile_row] - tiles->row_start_sb[tile_row - 1];
1050 }
1051 tile_info->num_tile_groups = pbi->num_tile_groups;
1052 return AOM_CODEC_OK;
1053 } else {
1054 return AOM_CODEC_ERROR;
1055 }
1056 }
1057
1058 return AOM_CODEC_INVALID_PARAM;
1059 }
1060
ctrl_get_screen_content_tools_info(aom_codec_alg_priv_t * ctx,va_list args)1061 static aom_codec_err_t ctrl_get_screen_content_tools_info(
1062 aom_codec_alg_priv_t *ctx, va_list args) {
1063 aom_screen_content_tools_info *const sc_info =
1064 va_arg(args, aom_screen_content_tools_info *);
1065 if (sc_info) {
1066 if (ctx->frame_worker) {
1067 AVxWorker *const worker = ctx->frame_worker;
1068 FrameWorkerData *const frame_worker_data =
1069 (FrameWorkerData *)worker->data1;
1070 const AV1Decoder *pbi = frame_worker_data->pbi;
1071 sc_info->allow_screen_content_tools =
1072 pbi->common.features.allow_screen_content_tools;
1073 sc_info->allow_intrabc = pbi->common.features.allow_intrabc;
1074 sc_info->force_integer_mv =
1075 (int)pbi->common.features.cur_frame_force_integer_mv;
1076 return AOM_CODEC_OK;
1077 } else {
1078 return AOM_CODEC_ERROR;
1079 }
1080 }
1081 return AOM_CODEC_INVALID_PARAM;
1082 }
1083
ctrl_get_still_picture(aom_codec_alg_priv_t * ctx,va_list args)1084 static aom_codec_err_t ctrl_get_still_picture(aom_codec_alg_priv_t *ctx,
1085 va_list args) {
1086 aom_still_picture_info *const still_picture_info =
1087 va_arg(args, aom_still_picture_info *);
1088 if (still_picture_info) {
1089 if (ctx->frame_worker) {
1090 AVxWorker *const worker = ctx->frame_worker;
1091 FrameWorkerData *const frame_worker_data =
1092 (FrameWorkerData *)worker->data1;
1093 const AV1Decoder *pbi = frame_worker_data->pbi;
1094 still_picture_info->is_still_picture =
1095 (int)pbi->common.seq_params.still_picture;
1096 still_picture_info->is_reduced_still_picture_hdr =
1097 (int)(pbi->common.seq_params.reduced_still_picture_hdr);
1098 return AOM_CODEC_OK;
1099 } else {
1100 return AOM_CODEC_ERROR;
1101 }
1102 }
1103 return AOM_CODEC_INVALID_PARAM;
1104 }
1105
ctrl_get_sb_size(aom_codec_alg_priv_t * ctx,va_list args)1106 static aom_codec_err_t ctrl_get_sb_size(aom_codec_alg_priv_t *ctx,
1107 va_list args) {
1108 aom_superblock_size_t *const sb_size = va_arg(args, aom_superblock_size_t *);
1109 if (sb_size) {
1110 if (ctx->frame_worker) {
1111 AVxWorker *const worker = ctx->frame_worker;
1112 FrameWorkerData *const frame_worker_data =
1113 (FrameWorkerData *)worker->data1;
1114 const AV1Decoder *pbi = frame_worker_data->pbi;
1115 if (pbi->common.seq_params.sb_size == BLOCK_128X128) {
1116 *sb_size = AOM_SUPERBLOCK_SIZE_128X128;
1117 } else {
1118 *sb_size = AOM_SUPERBLOCK_SIZE_64X64;
1119 }
1120 return AOM_CODEC_OK;
1121 } else {
1122 return AOM_CODEC_ERROR;
1123 }
1124 }
1125 return AOM_CODEC_INVALID_PARAM;
1126 }
1127
ctrl_get_show_existing_frame_flag(aom_codec_alg_priv_t * ctx,va_list args)1128 static aom_codec_err_t ctrl_get_show_existing_frame_flag(
1129 aom_codec_alg_priv_t *ctx, va_list args) {
1130 int *const arg = va_arg(args, int *);
1131 if (arg == NULL) return AOM_CODEC_INVALID_PARAM;
1132 if (ctx->frame_worker == NULL) return AOM_CODEC_ERROR;
1133 *arg = ((FrameWorkerData *)ctx->frame_worker->data1)
1134 ->pbi->common.show_existing_frame;
1135 return AOM_CODEC_OK;
1136 }
1137
ctrl_get_s_frame_info(aom_codec_alg_priv_t * ctx,va_list args)1138 static aom_codec_err_t ctrl_get_s_frame_info(aom_codec_alg_priv_t *ctx,
1139 va_list args) {
1140 aom_s_frame_info *const s_frame_info = va_arg(args, aom_s_frame_info *);
1141 if (s_frame_info) {
1142 if (ctx->frame_worker) {
1143 AVxWorker *const worker = ctx->frame_worker;
1144 FrameWorkerData *const frame_worker_data =
1145 (FrameWorkerData *)worker->data1;
1146 const AV1Decoder *pbi = frame_worker_data->pbi;
1147 s_frame_info->is_s_frame = pbi->sframe_info.is_s_frame;
1148 s_frame_info->is_s_frame_at_altref =
1149 pbi->sframe_info.is_s_frame_at_altref;
1150 return AOM_CODEC_OK;
1151 } else {
1152 return AOM_CODEC_ERROR;
1153 }
1154 }
1155 return AOM_CODEC_INVALID_PARAM;
1156 }
1157
ctrl_get_frame_corrupted(aom_codec_alg_priv_t * ctx,va_list args)1158 static aom_codec_err_t ctrl_get_frame_corrupted(aom_codec_alg_priv_t *ctx,
1159 va_list args) {
1160 int *corrupted = va_arg(args, int *);
1161
1162 if (corrupted) {
1163 if (ctx->frame_worker) {
1164 AVxWorker *const worker = ctx->frame_worker;
1165 FrameWorkerData *const frame_worker_data =
1166 (FrameWorkerData *)worker->data1;
1167 AV1Decoder *const pbi = frame_worker_data->pbi;
1168 if (pbi->seen_frame_header && pbi->num_output_frames == 0)
1169 return AOM_CODEC_ERROR;
1170 if (ctx->last_show_frame != NULL)
1171 *corrupted = ctx->last_show_frame->buf.corrupted;
1172 return AOM_CODEC_OK;
1173 } else {
1174 return AOM_CODEC_ERROR;
1175 }
1176 }
1177
1178 return AOM_CODEC_INVALID_PARAM;
1179 }
1180
ctrl_get_frame_size(aom_codec_alg_priv_t * ctx,va_list args)1181 static aom_codec_err_t ctrl_get_frame_size(aom_codec_alg_priv_t *ctx,
1182 va_list args) {
1183 int *const frame_size = va_arg(args, int *);
1184
1185 if (frame_size) {
1186 if (ctx->frame_worker) {
1187 AVxWorker *const worker = ctx->frame_worker;
1188 FrameWorkerData *const frame_worker_data =
1189 (FrameWorkerData *)worker->data1;
1190 const AV1_COMMON *const cm = &frame_worker_data->pbi->common;
1191 frame_size[0] = cm->width;
1192 frame_size[1] = cm->height;
1193 return AOM_CODEC_OK;
1194 } else {
1195 return AOM_CODEC_ERROR;
1196 }
1197 }
1198
1199 return AOM_CODEC_INVALID_PARAM;
1200 }
1201
ctrl_get_frame_header_info(aom_codec_alg_priv_t * ctx,va_list args)1202 static aom_codec_err_t ctrl_get_frame_header_info(aom_codec_alg_priv_t *ctx,
1203 va_list args) {
1204 aom_tile_data *const frame_header_info = va_arg(args, aom_tile_data *);
1205
1206 if (frame_header_info) {
1207 if (ctx->frame_worker) {
1208 AVxWorker *const worker = ctx->frame_worker;
1209 FrameWorkerData *const frame_worker_data =
1210 (FrameWorkerData *)worker->data1;
1211 const AV1Decoder *pbi = frame_worker_data->pbi;
1212 frame_header_info->coded_tile_data_size = pbi->obu_size_hdr.size;
1213 frame_header_info->coded_tile_data = pbi->obu_size_hdr.data;
1214 frame_header_info->extra_size = pbi->frame_header_size;
1215 return AOM_CODEC_OK;
1216 } else {
1217 return AOM_CODEC_ERROR;
1218 }
1219 }
1220
1221 return AOM_CODEC_INVALID_PARAM;
1222 }
1223
ctrl_get_tile_data(aom_codec_alg_priv_t * ctx,va_list args)1224 static aom_codec_err_t ctrl_get_tile_data(aom_codec_alg_priv_t *ctx,
1225 va_list args) {
1226 aom_tile_data *const tile_data = va_arg(args, aom_tile_data *);
1227
1228 if (tile_data) {
1229 if (ctx->frame_worker) {
1230 AVxWorker *const worker = ctx->frame_worker;
1231 FrameWorkerData *const frame_worker_data =
1232 (FrameWorkerData *)worker->data1;
1233 const AV1Decoder *pbi = frame_worker_data->pbi;
1234 tile_data->coded_tile_data_size =
1235 pbi->tile_buffers[pbi->dec_tile_row][pbi->dec_tile_col].size;
1236 tile_data->coded_tile_data =
1237 pbi->tile_buffers[pbi->dec_tile_row][pbi->dec_tile_col].data;
1238 return AOM_CODEC_OK;
1239 } else {
1240 return AOM_CODEC_ERROR;
1241 }
1242 }
1243
1244 return AOM_CODEC_INVALID_PARAM;
1245 }
1246
ctrl_set_ext_ref_ptr(aom_codec_alg_priv_t * ctx,va_list args)1247 static aom_codec_err_t ctrl_set_ext_ref_ptr(aom_codec_alg_priv_t *ctx,
1248 va_list args) {
1249 av1_ext_ref_frame_t *const data = va_arg(args, av1_ext_ref_frame_t *);
1250
1251 if (data) {
1252 av1_ext_ref_frame_t *const ext_frames = data;
1253 ctx->ext_refs.num = ext_frames->num;
1254 for (int i = 0; i < ctx->ext_refs.num; i++) {
1255 image2yuvconfig(ext_frames->img++, &ctx->ext_refs.refs[i]);
1256 }
1257 return AOM_CODEC_OK;
1258 } else {
1259 return AOM_CODEC_INVALID_PARAM;
1260 }
1261 }
1262
ctrl_get_render_size(aom_codec_alg_priv_t * ctx,va_list args)1263 static aom_codec_err_t ctrl_get_render_size(aom_codec_alg_priv_t *ctx,
1264 va_list args) {
1265 int *const render_size = va_arg(args, int *);
1266
1267 if (render_size) {
1268 if (ctx->frame_worker) {
1269 AVxWorker *const worker = ctx->frame_worker;
1270 FrameWorkerData *const frame_worker_data =
1271 (FrameWorkerData *)worker->data1;
1272 const AV1_COMMON *const cm = &frame_worker_data->pbi->common;
1273 render_size[0] = cm->render_width;
1274 render_size[1] = cm->render_height;
1275 return AOM_CODEC_OK;
1276 } else {
1277 return AOM_CODEC_ERROR;
1278 }
1279 }
1280
1281 return AOM_CODEC_INVALID_PARAM;
1282 }
1283
ctrl_get_bit_depth(aom_codec_alg_priv_t * ctx,va_list args)1284 static aom_codec_err_t ctrl_get_bit_depth(aom_codec_alg_priv_t *ctx,
1285 va_list args) {
1286 unsigned int *const bit_depth = va_arg(args, unsigned int *);
1287 AVxWorker *const worker = ctx->frame_worker;
1288
1289 if (bit_depth) {
1290 if (worker) {
1291 FrameWorkerData *const frame_worker_data =
1292 (FrameWorkerData *)worker->data1;
1293 const AV1_COMMON *const cm = &frame_worker_data->pbi->common;
1294 *bit_depth = cm->seq_params.bit_depth;
1295 return AOM_CODEC_OK;
1296 } else {
1297 return AOM_CODEC_ERROR;
1298 }
1299 }
1300
1301 return AOM_CODEC_INVALID_PARAM;
1302 }
1303
get_img_format(int subsampling_x,int subsampling_y,int use_highbitdepth)1304 static aom_img_fmt_t get_img_format(int subsampling_x, int subsampling_y,
1305 int use_highbitdepth) {
1306 aom_img_fmt_t fmt = 0;
1307
1308 if (subsampling_x == 0 && subsampling_y == 0)
1309 fmt = AOM_IMG_FMT_I444;
1310 else if (subsampling_x == 1 && subsampling_y == 0)
1311 fmt = AOM_IMG_FMT_I422;
1312 else if (subsampling_x == 1 && subsampling_y == 1)
1313 fmt = AOM_IMG_FMT_I420;
1314
1315 if (use_highbitdepth) fmt |= AOM_IMG_FMT_HIGHBITDEPTH;
1316 return fmt;
1317 }
1318
ctrl_get_img_format(aom_codec_alg_priv_t * ctx,va_list args)1319 static aom_codec_err_t ctrl_get_img_format(aom_codec_alg_priv_t *ctx,
1320 va_list args) {
1321 aom_img_fmt_t *const img_fmt = va_arg(args, aom_img_fmt_t *);
1322 AVxWorker *const worker = ctx->frame_worker;
1323
1324 if (img_fmt) {
1325 if (worker) {
1326 FrameWorkerData *const frame_worker_data =
1327 (FrameWorkerData *)worker->data1;
1328 const AV1_COMMON *const cm = &frame_worker_data->pbi->common;
1329
1330 *img_fmt = get_img_format(cm->seq_params.subsampling_x,
1331 cm->seq_params.subsampling_y,
1332 cm->seq_params.use_highbitdepth);
1333 return AOM_CODEC_OK;
1334 } else {
1335 return AOM_CODEC_ERROR;
1336 }
1337 }
1338
1339 return AOM_CODEC_INVALID_PARAM;
1340 }
1341
ctrl_get_tile_size(aom_codec_alg_priv_t * ctx,va_list args)1342 static aom_codec_err_t ctrl_get_tile_size(aom_codec_alg_priv_t *ctx,
1343 va_list args) {
1344 unsigned int *const tile_size = va_arg(args, unsigned int *);
1345 AVxWorker *const worker = ctx->frame_worker;
1346
1347 if (tile_size) {
1348 if (worker) {
1349 FrameWorkerData *const frame_worker_data =
1350 (FrameWorkerData *)worker->data1;
1351 const AV1_COMMON *const cm = &frame_worker_data->pbi->common;
1352 int tile_width, tile_height;
1353 av1_get_uniform_tile_size(cm, &tile_width, &tile_height);
1354 *tile_size = ((tile_width * MI_SIZE) << 16) + tile_height * MI_SIZE;
1355 return AOM_CODEC_OK;
1356 } else {
1357 return AOM_CODEC_ERROR;
1358 }
1359 }
1360 return AOM_CODEC_INVALID_PARAM;
1361 }
1362
ctrl_get_tile_count(aom_codec_alg_priv_t * ctx,va_list args)1363 static aom_codec_err_t ctrl_get_tile_count(aom_codec_alg_priv_t *ctx,
1364 va_list args) {
1365 unsigned int *const tile_count = va_arg(args, unsigned int *);
1366
1367 if (tile_count) {
1368 AVxWorker *const worker = ctx->frame_worker;
1369 if (worker) {
1370 FrameWorkerData *const frame_worker_data =
1371 (FrameWorkerData *)worker->data1;
1372 *tile_count = frame_worker_data->pbi->tile_count_minus_1 + 1;
1373 return AOM_CODEC_OK;
1374 } else {
1375 return AOM_CODEC_ERROR;
1376 }
1377 }
1378 return AOM_CODEC_INVALID_PARAM;
1379 }
1380
ctrl_set_invert_tile_order(aom_codec_alg_priv_t * ctx,va_list args)1381 static aom_codec_err_t ctrl_set_invert_tile_order(aom_codec_alg_priv_t *ctx,
1382 va_list args) {
1383 ctx->invert_tile_order = va_arg(args, int);
1384 return AOM_CODEC_OK;
1385 }
1386
ctrl_set_byte_alignment(aom_codec_alg_priv_t * ctx,va_list args)1387 static aom_codec_err_t ctrl_set_byte_alignment(aom_codec_alg_priv_t *ctx,
1388 va_list args) {
1389 const int legacy_byte_alignment = 0;
1390 const int min_byte_alignment = 32;
1391 const int max_byte_alignment = 1024;
1392 const int byte_alignment = va_arg(args, int);
1393
1394 if (byte_alignment != legacy_byte_alignment &&
1395 (byte_alignment < min_byte_alignment ||
1396 byte_alignment > max_byte_alignment ||
1397 (byte_alignment & (byte_alignment - 1)) != 0))
1398 return AOM_CODEC_INVALID_PARAM;
1399
1400 ctx->byte_alignment = byte_alignment;
1401 if (ctx->frame_worker) {
1402 AVxWorker *const worker = ctx->frame_worker;
1403 FrameWorkerData *const frame_worker_data = (FrameWorkerData *)worker->data1;
1404 frame_worker_data->pbi->common.features.byte_alignment = byte_alignment;
1405 }
1406 return AOM_CODEC_OK;
1407 }
1408
ctrl_set_skip_loop_filter(aom_codec_alg_priv_t * ctx,va_list args)1409 static aom_codec_err_t ctrl_set_skip_loop_filter(aom_codec_alg_priv_t *ctx,
1410 va_list args) {
1411 ctx->skip_loop_filter = va_arg(args, int);
1412
1413 if (ctx->frame_worker) {
1414 AVxWorker *const worker = ctx->frame_worker;
1415 FrameWorkerData *const frame_worker_data = (FrameWorkerData *)worker->data1;
1416 frame_worker_data->pbi->skip_loop_filter = ctx->skip_loop_filter;
1417 }
1418
1419 return AOM_CODEC_OK;
1420 }
1421
ctrl_set_skip_film_grain(aom_codec_alg_priv_t * ctx,va_list args)1422 static aom_codec_err_t ctrl_set_skip_film_grain(aom_codec_alg_priv_t *ctx,
1423 va_list args) {
1424 ctx->skip_film_grain = va_arg(args, int);
1425
1426 if (ctx->frame_worker) {
1427 AVxWorker *const worker = ctx->frame_worker;
1428 FrameWorkerData *const frame_worker_data = (FrameWorkerData *)worker->data1;
1429 frame_worker_data->pbi->skip_film_grain = ctx->skip_film_grain;
1430 }
1431
1432 return AOM_CODEC_OK;
1433 }
1434
ctrl_get_accounting(aom_codec_alg_priv_t * ctx,va_list args)1435 static aom_codec_err_t ctrl_get_accounting(aom_codec_alg_priv_t *ctx,
1436 va_list args) {
1437 #if !CONFIG_ACCOUNTING
1438 (void)ctx;
1439 (void)args;
1440 return AOM_CODEC_INCAPABLE;
1441 #else
1442 Accounting **acct = va_arg(args, Accounting **);
1443
1444 if (acct) {
1445 if (ctx->frame_worker) {
1446 AVxWorker *const worker = ctx->frame_worker;
1447 FrameWorkerData *const frame_worker_data =
1448 (FrameWorkerData *)worker->data1;
1449 AV1Decoder *pbi = frame_worker_data->pbi;
1450 *acct = &pbi->accounting;
1451 return AOM_CODEC_OK;
1452 } else {
1453 return AOM_CODEC_ERROR;
1454 }
1455 }
1456
1457 return AOM_CODEC_INVALID_PARAM;
1458 #endif
1459 }
1460
ctrl_set_decode_tile_row(aom_codec_alg_priv_t * ctx,va_list args)1461 static aom_codec_err_t ctrl_set_decode_tile_row(aom_codec_alg_priv_t *ctx,
1462 va_list args) {
1463 ctx->decode_tile_row = va_arg(args, int);
1464 return AOM_CODEC_OK;
1465 }
1466
ctrl_set_decode_tile_col(aom_codec_alg_priv_t * ctx,va_list args)1467 static aom_codec_err_t ctrl_set_decode_tile_col(aom_codec_alg_priv_t *ctx,
1468 va_list args) {
1469 ctx->decode_tile_col = va_arg(args, int);
1470 return AOM_CODEC_OK;
1471 }
1472
ctrl_set_tile_mode(aom_codec_alg_priv_t * ctx,va_list args)1473 static aom_codec_err_t ctrl_set_tile_mode(aom_codec_alg_priv_t *ctx,
1474 va_list args) {
1475 ctx->tile_mode = va_arg(args, unsigned int);
1476 return AOM_CODEC_OK;
1477 }
1478
ctrl_set_is_annexb(aom_codec_alg_priv_t * ctx,va_list args)1479 static aom_codec_err_t ctrl_set_is_annexb(aom_codec_alg_priv_t *ctx,
1480 va_list args) {
1481 ctx->is_annexb = va_arg(args, unsigned int);
1482 return AOM_CODEC_OK;
1483 }
1484
ctrl_set_operating_point(aom_codec_alg_priv_t * ctx,va_list args)1485 static aom_codec_err_t ctrl_set_operating_point(aom_codec_alg_priv_t *ctx,
1486 va_list args) {
1487 ctx->operating_point = va_arg(args, int);
1488 return AOM_CODEC_OK;
1489 }
1490
ctrl_set_output_all_layers(aom_codec_alg_priv_t * ctx,va_list args)1491 static aom_codec_err_t ctrl_set_output_all_layers(aom_codec_alg_priv_t *ctx,
1492 va_list args) {
1493 ctx->output_all_layers = va_arg(args, int);
1494 return AOM_CODEC_OK;
1495 }
1496
ctrl_set_inspection_callback(aom_codec_alg_priv_t * ctx,va_list args)1497 static aom_codec_err_t ctrl_set_inspection_callback(aom_codec_alg_priv_t *ctx,
1498 va_list args) {
1499 #if !CONFIG_INSPECTION
1500 (void)ctx;
1501 (void)args;
1502 return AOM_CODEC_INCAPABLE;
1503 #else
1504 aom_inspect_init *init = va_arg(args, aom_inspect_init *);
1505 ctx->inspect_cb = init->inspect_cb;
1506 ctx->inspect_ctx = init->inspect_ctx;
1507 return AOM_CODEC_OK;
1508 #endif
1509 }
1510
ctrl_ext_tile_debug(aom_codec_alg_priv_t * ctx,va_list args)1511 static aom_codec_err_t ctrl_ext_tile_debug(aom_codec_alg_priv_t *ctx,
1512 va_list args) {
1513 ctx->ext_tile_debug = va_arg(args, int);
1514 return AOM_CODEC_OK;
1515 }
1516
ctrl_set_row_mt(aom_codec_alg_priv_t * ctx,va_list args)1517 static aom_codec_err_t ctrl_set_row_mt(aom_codec_alg_priv_t *ctx,
1518 va_list args) {
1519 ctx->row_mt = va_arg(args, unsigned int);
1520 return AOM_CODEC_OK;
1521 }
1522
1523 static aom_codec_ctrl_fn_map_t decoder_ctrl_maps[] = {
1524 { AV1_COPY_REFERENCE, ctrl_copy_reference },
1525
1526 // Setters
1527 { AV1_SET_REFERENCE, ctrl_set_reference },
1528 { AV1_INVERT_TILE_DECODE_ORDER, ctrl_set_invert_tile_order },
1529 { AV1_SET_BYTE_ALIGNMENT, ctrl_set_byte_alignment },
1530 { AV1_SET_SKIP_LOOP_FILTER, ctrl_set_skip_loop_filter },
1531 { AV1_SET_DECODE_TILE_ROW, ctrl_set_decode_tile_row },
1532 { AV1_SET_DECODE_TILE_COL, ctrl_set_decode_tile_col },
1533 { AV1_SET_TILE_MODE, ctrl_set_tile_mode },
1534 { AV1D_SET_IS_ANNEXB, ctrl_set_is_annexb },
1535 { AV1D_SET_OPERATING_POINT, ctrl_set_operating_point },
1536 { AV1D_SET_OUTPUT_ALL_LAYERS, ctrl_set_output_all_layers },
1537 { AV1_SET_INSPECTION_CALLBACK, ctrl_set_inspection_callback },
1538 { AV1D_EXT_TILE_DEBUG, ctrl_ext_tile_debug },
1539 { AV1D_SET_ROW_MT, ctrl_set_row_mt },
1540 { AV1D_SET_EXT_REF_PTR, ctrl_set_ext_ref_ptr },
1541 { AV1D_SET_SKIP_FILM_GRAIN, ctrl_set_skip_film_grain },
1542
1543 // Getters
1544 { AOMD_GET_FRAME_CORRUPTED, ctrl_get_frame_corrupted },
1545 { AOMD_GET_LAST_QUANTIZER, ctrl_get_last_quantizer },
1546 { AOMD_GET_LAST_REF_UPDATES, ctrl_get_last_ref_updates },
1547 { AV1D_GET_BIT_DEPTH, ctrl_get_bit_depth },
1548 { AV1D_GET_IMG_FORMAT, ctrl_get_img_format },
1549 { AV1D_GET_TILE_SIZE, ctrl_get_tile_size },
1550 { AV1D_GET_TILE_COUNT, ctrl_get_tile_count },
1551 { AV1D_GET_DISPLAY_SIZE, ctrl_get_render_size },
1552 { AV1D_GET_FRAME_SIZE, ctrl_get_frame_size },
1553 { AV1_GET_ACCOUNTING, ctrl_get_accounting },
1554 { AV1_GET_NEW_FRAME_IMAGE, ctrl_get_new_frame_image },
1555 { AV1_COPY_NEW_FRAME_IMAGE, ctrl_copy_new_frame_image },
1556 { AV1_GET_REFERENCE, ctrl_get_reference },
1557 { AV1D_GET_FRAME_HEADER_INFO, ctrl_get_frame_header_info },
1558 { AV1D_GET_TILE_DATA, ctrl_get_tile_data },
1559 { AOMD_GET_FWD_KF_PRESENT, ctrl_get_fwd_kf_value },
1560 { AOMD_GET_ALTREF_PRESENT, ctrl_get_altref_present },
1561 { AOMD_GET_FRAME_FLAGS, ctrl_get_frame_flags },
1562 { AOMD_GET_TILE_INFO, ctrl_get_tile_info },
1563 { AOMD_GET_SCREEN_CONTENT_TOOLS_INFO, ctrl_get_screen_content_tools_info },
1564 { AOMD_GET_STILL_PICTURE, ctrl_get_still_picture },
1565 { AOMD_GET_SB_SIZE, ctrl_get_sb_size },
1566 { AOMD_GET_SHOW_EXISTING_FRAME_FLAG, ctrl_get_show_existing_frame_flag },
1567 { AOMD_GET_S_FRAME_INFO, ctrl_get_s_frame_info },
1568
1569 CTRL_MAP_END,
1570 };
1571
1572 // This data structure and function are exported in aom/aomdx.h
1573 #ifndef VERSION_STRING
1574 #define VERSION_STRING
1575 #endif
1576 aom_codec_iface_t aom_codec_av1_dx_algo = {
1577 "AOMedia Project AV1 Decoder" VERSION_STRING,
1578 AOM_CODEC_INTERNAL_ABI_VERSION,
1579 AOM_CODEC_CAP_DECODER |
1580 AOM_CODEC_CAP_EXTERNAL_FRAME_BUFFER, // aom_codec_caps_t
1581 decoder_init, // aom_codec_init_fn_t
1582 decoder_destroy, // aom_codec_destroy_fn_t
1583 decoder_ctrl_maps, // aom_codec_ctrl_fn_map_t
1584 {
1585 // NOLINT
1586 decoder_peek_si, // aom_codec_peek_si_fn_t
1587 decoder_get_si, // aom_codec_get_si_fn_t
1588 decoder_decode, // aom_codec_decode_fn_t
1589 decoder_get_frame, // aom_codec_get_frame_fn_t
1590 decoder_set_fb_fn, // aom_codec_set_fb_fn_t
1591 },
1592 {
1593 // NOLINT
1594 0,
1595 NULL, // aom_codec_enc_cfg_t
1596 NULL, // aom_codec_encode_fn_t
1597 NULL, // aom_codec_get_cx_data_fn_t
1598 NULL, // aom_codec_enc_config_set_fn_t
1599 NULL, // aom_codec_get_global_headers_fn_t
1600 NULL // aom_codec_get_preview_frame_fn_t
1601 },
1602 NULL // aom_codec_set_option_fn_t
1603 };
1604
aom_codec_av1_dx(void)1605 aom_codec_iface_t *aom_codec_av1_dx(void) { return &aom_codec_av1_dx_algo; }
1606