blob: febb6586c4fb6948b68a697db40ac037a6dd2255 [file] [log] [blame]
Yaowu Xuc27fc142016-08-22 16:08:15 -07001/*
Yaowu Xu9c01aa12016-09-01 14:32:49 -07002 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
Yaowu Xuc27fc142016-08-22 16:08:15 -07003 *
Yaowu Xu9c01aa12016-09-01 14:32:49 -07004 * 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.
Yaowu Xuc27fc142016-08-22 16:08:15 -070010 */
11
12#include <stdlib.h>
13#include <string.h>
14
Yaowu Xuf883b422016-08-30 14:01:10 -070015#include "./aom_config.h"
16#include "./aom_version.h"
Yaowu Xuc27fc142016-08-22 16:08:15 -070017
Yaowu Xuf883b422016-08-30 14:01:10 -070018#include "aom/internal/aom_codec_internal.h"
19#include "aom/aomdx.h"
20#include "aom/aom_decoder.h"
Yaowu Xuc27fc142016-08-22 16:08:15 -070021#include "aom_dsp/bitreader_buffer.h"
Yaowu Xuf883b422016-08-30 14:01:10 -070022#include "aom_dsp/aom_dsp_common.h"
Soo-Chul Hanf8589862018-01-24 03:13:14 +000023#include "aom_ports/mem_ops.h"
Yaowu Xuf883b422016-08-30 14:01:10 -070024#include "aom_util/aom_thread.h"
Yaowu Xuc27fc142016-08-22 16:08:15 -070025
26#include "av1/common/alloccommon.h"
27#include "av1/common/frame_buffers.h"
28#include "av1/common/enums.h"
29
30#include "av1/decoder/decoder.h"
31#include "av1/decoder/decodeframe.h"
Tom Finegan13ee28c2018-02-26 19:37:41 -080032#include "av1/decoder/obu.h"
Yaowu Xuc27fc142016-08-22 16:08:15 -070033
Yaowu Xuf883b422016-08-30 14:01:10 -070034#include "av1/av1_iface_common.h"
Yaowu Xuc27fc142016-08-22 16:08:15 -070035
Yaowu Xuc27fc142016-08-22 16:08:15 -070036// This limit is due to framebuffer numbers.
37// TODO(hkuang): Remove this limit after implementing ondemand framebuffers.
38#define FRAME_CACHE_SIZE 6 // Cache maximum 6 decoded frames.
39
40typedef struct cache_frame {
41 int fb_idx;
Yaowu Xuf883b422016-08-30 14:01:10 -070042 aom_image_t img;
Andrey Norkin6f1c2f72018-01-15 20:08:52 -080043 aom_film_grain_t film_grain_params;
Yaowu Xuc27fc142016-08-22 16:08:15 -070044} cache_frame;
45
Yaowu Xuf883b422016-08-30 14:01:10 -070046struct aom_codec_alg_priv {
47 aom_codec_priv_t base;
48 aom_codec_dec_cfg_t cfg;
Ralph Gilesafe71d92017-05-03 13:18:57 -070049 aom_codec_stream_info_t si;
Yaowu Xuc27fc142016-08-22 16:08:15 -070050 int postproc_cfg_set;
Yaowu Xuf883b422016-08-30 14:01:10 -070051 aom_postproc_cfg_t postproc_cfg;
Yaowu Xuf883b422016-08-30 14:01:10 -070052 aom_image_t img;
Yaowu Xuc27fc142016-08-22 16:08:15 -070053 int img_avail;
54 int flushed;
55 int invert_tile_order;
56 int last_show_frame; // Index of last output frame.
57 int byte_alignment;
58 int skip_loop_filter;
59 int decode_tile_row;
60 int decode_tile_col;
Yunqing Wang8ae64a92018-01-12 12:26:44 -080061 unsigned int tile_mode;
Soo-Chul Han29c46fb2018-03-23 16:02:00 -040062 unsigned int is_annexb;
Yaowu Xuc27fc142016-08-22 16:08:15 -070063
Yaowu Xuf883b422016-08-30 14:01:10 -070064 AVxWorker *frame_workers;
Yaowu Xuc27fc142016-08-22 16:08:15 -070065 int num_frame_workers;
66 int next_submit_worker_id;
67 int last_submit_worker_id;
68 int next_output_worker_id;
69 int available_threads;
70 cache_frame frame_cache[FRAME_CACHE_SIZE];
Andrey Norkin6f1c2f72018-01-15 20:08:52 -080071 aom_image_t *image_with_grain;
Yaowu Xuc27fc142016-08-22 16:08:15 -070072 int frame_cache_write;
73 int frame_cache_read;
74 int num_cache_frames;
75 int need_resync; // wait for key/intra-only frame
76 // BufferPool that holds all reference frames. Shared by all the FrameWorkers.
77 BufferPool *buffer_pool;
78
Yaowu Xuf883b422016-08-30 14:01:10 -070079 // External frame buffer info to save for AV1 common.
Yaowu Xuc27fc142016-08-22 16:08:15 -070080 void *ext_priv; // Private data associated with the external frame buffers.
Yaowu Xuf883b422016-08-30 14:01:10 -070081 aom_get_frame_buffer_cb_fn_t get_ext_fb_cb;
82 aom_release_frame_buffer_cb_fn_t release_ext_fb_cb;
Nathan E. Egge2cf03b12017-02-22 16:19:59 -050083
84#if CONFIG_INSPECTION
85 aom_inspect_cb inspect_cb;
86 void *inspect_ctx;
87#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -070088};
89
Yaowu Xuf883b422016-08-30 14:01:10 -070090static aom_codec_err_t decoder_init(aom_codec_ctx_t *ctx,
91 aom_codec_priv_enc_mr_cfg_t *data) {
92 // This function only allocates space for the aom_codec_alg_priv_t
Yaowu Xuc27fc142016-08-22 16:08:15 -070093 // structure. More memory may be required at the time the stream
94 // information becomes known.
95 (void)data;
96
97 if (!ctx->priv) {
Yaowu Xuf883b422016-08-30 14:01:10 -070098 aom_codec_alg_priv_t *const priv =
99 (aom_codec_alg_priv_t *)aom_calloc(1, sizeof(*priv));
100 if (priv == NULL) return AOM_CODEC_MEM_ERROR;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700101
Yaowu Xuf883b422016-08-30 14:01:10 -0700102 ctx->priv = (aom_codec_priv_t *)priv;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700103 ctx->priv->init_flags = ctx->init_flags;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700104 priv->flushed = 0;
Debargha Mukherjee5521a182018-03-06 12:29:01 -0800105
Thomas Daede85b49002017-07-10 17:43:06 -0700106 // TODO(tdaede): this should not be exposed to the API
107 priv->cfg.allow_lowbitdepth = CONFIG_LOWBITDEPTH;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700108 if (ctx->config.dec) {
109 priv->cfg = *ctx->config.dec;
110 ctx->config.dec = &priv->cfg;
Maxym Dmytrychenkocc6e0e12018-02-05 16:35:37 +0100111 // default values
Debargha Mukherjee2ccf4b92018-02-27 17:30:46 -0800112 priv->cfg.cfg.ext_partition = 1;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700113 }
Andrey Norkin6f1c2f72018-01-15 20:08:52 -0800114 priv->image_with_grain = NULL;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700115 }
116
Yaowu Xuf883b422016-08-30 14:01:10 -0700117 return AOM_CODEC_OK;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700118}
119
Yaowu Xuf883b422016-08-30 14:01:10 -0700120static aom_codec_err_t decoder_destroy(aom_codec_alg_priv_t *ctx) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700121 if (ctx->frame_workers != NULL) {
122 int i;
123 for (i = 0; i < ctx->num_frame_workers; ++i) {
Yaowu Xuf883b422016-08-30 14:01:10 -0700124 AVxWorker *const worker = &ctx->frame_workers[i];
Yaowu Xuc27fc142016-08-22 16:08:15 -0700125 FrameWorkerData *const frame_worker_data =
126 (FrameWorkerData *)worker->data1;
Yaowu Xuf883b422016-08-30 14:01:10 -0700127 aom_get_worker_interface()->end(worker);
Yaowu Xu568bf102017-10-17 12:43:27 -0700128 aom_free(frame_worker_data->pbi->common.tpl_mvs);
129 frame_worker_data->pbi->common.tpl_mvs = NULL;
Yaowu Xuf883b422016-08-30 14:01:10 -0700130 av1_remove_common(&frame_worker_data->pbi->common);
Yaowu Xuf883b422016-08-30 14:01:10 -0700131 av1_free_restoration_buffers(&frame_worker_data->pbi->common);
Yaowu Xuf883b422016-08-30 14:01:10 -0700132 av1_decoder_remove(frame_worker_data->pbi);
133 aom_free(frame_worker_data->scratch_buffer);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700134#if CONFIG_MULTITHREAD
135 pthread_mutex_destroy(&frame_worker_data->stats_mutex);
136 pthread_cond_destroy(&frame_worker_data->stats_cond);
137#endif
Yaowu Xuf883b422016-08-30 14:01:10 -0700138 aom_free(frame_worker_data);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700139 }
140#if CONFIG_MULTITHREAD
141 pthread_mutex_destroy(&ctx->buffer_pool->pool_mutex);
142#endif
143 }
144
145 if (ctx->buffer_pool) {
Yaowu Xuf883b422016-08-30 14:01:10 -0700146 av1_free_ref_frame_buffers(ctx->buffer_pool);
147 av1_free_internal_frame_buffers(&ctx->buffer_pool->int_frame_buffers);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700148 }
149
Yaowu Xuf883b422016-08-30 14:01:10 -0700150 aom_free(ctx->frame_workers);
151 aom_free(ctx->buffer_pool);
Andrey Norkin6f1c2f72018-01-15 20:08:52 -0800152 if (ctx->image_with_grain) aom_img_free(ctx->image_with_grain);
Yaowu Xuf883b422016-08-30 14:01:10 -0700153 aom_free(ctx);
154 return AOM_CODEC_OK;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700155}
156
Hui Sudf5b2912018-03-16 15:34:01 -0700157static size_t get_obu_length_field_size(const uint8_t *data, size_t data_sz) {
158 const size_t max_bytes = AOMMIN(sizeof(uint64_t), data_sz);
Vignesh Venkatasubramanian03391a22018-03-09 12:25:55 -0800159 size_t length_field_size = 1;
Hui Sudf5b2912018-03-16 15:34:01 -0700160 for (size_t i = 0; i < max_bytes && (data[i] & 0x80); ++i) {
Vignesh Venkatasubramanian03391a22018-03-09 12:25:55 -0800161 ++length_field_size;
162 }
163 return length_field_size;
164}
165
Debargha Mukherjeeacd41f92018-04-11 07:58:34 -0700166static void parse_operating_points(struct aom_read_bit_buffer *rb,
167 int red_hdr) {
168 if (red_hdr) {
169 aom_rb_read_literal(rb, LEVEL_BITS); // level
170 } else {
171 const uint8_t operating_points_minus1_cnt =
172 aom_rb_read_literal(rb, OP_POINTS_MINUS1_BITS);
173 for (int i = 0; i < operating_points_minus1_cnt + 1; i++) {
174 aom_rb_read_literal(rb, OP_POINTS_IDC_BITS); // idc
175 aom_rb_read_literal(rb, LEVEL_BITS); // level
176#if !CONFIG_BUFFER_MODEL
177 if (aom_rb_read_literal(rb,
178 1)) { // decoder_rate_model_param_present_flag
179 aom_rb_read_literal(rb, 12); // decode_to_display_rate_ratio
180 aom_rb_read_literal(rb, 24); // initial_display_delay
181 aom_rb_read_literal(rb, 4); // extra_frame_buffers
182 }
183#endif // !CONFIG_BUFFER_MODEL
Debargha Mukherjee112c5822018-04-09 09:42:29 -0700184 }
185 }
186}
187
Sebastien Alaiwan2b1ec182017-12-21 09:38:27 +0100188static aom_codec_err_t decoder_peek_si_internal(const uint8_t *data,
189 unsigned int data_sz,
190 aom_codec_stream_info_t *si,
191 int *is_intra_only) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700192 int intra_only_flag = 0;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700193
Hui Sudf5b2912018-03-16 15:34:01 -0700194 if (data + data_sz <= data || data_sz < 1) return AOM_CODEC_INVALID_PARAM;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700195
Tom Fineganf277ca32018-02-26 12:09:52 -0800196 si->w = 0;
Tom Finegan13ee28c2018-02-26 19:37:41 -0800197 si->h = 0;
198 si->is_kf = 0;
199
200 // TODO(tomfinegan): This function needs Sequence and Frame Header OBUs to
201 // operate properly. At present it hard codes the values to 1 for the keyframe
202 // and intra only flags, and assumes the data being parsed is a Sequence
203 // Header OBU.
David Barker5c0e80e2018-04-17 12:54:29 +0100204 // NOTE(david.barker): In addition, this code currently requires the video
205 // stream to begin with an optional OBU_TEMPORAL_DELIMITER followed by an
206 // OBU_SEQUENCE_HEADER.
Tom Fineganf277ca32018-02-26 12:09:52 -0800207 intra_only_flag = 1;
Tom Finegan13ee28c2018-02-26 19:37:41 -0800208 si->is_kf = 1;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700209
David Barker5c0e80e2018-04-17 12:54:29 +0100210 ObuHeader obu_header;
211 memset(&obu_header, 0, sizeof(obu_header));
212 size_t payload_size = 0;
213 size_t bytes_read = 0;
214 aom_codec_err_t status = aom_read_obu_header_and_size(
215 data, data_sz, si->is_annexb, &obu_header, &payload_size, &bytes_read);
216 if (status != AOM_CODEC_OK) return status;
Soo-Chul Han29c46fb2018-03-23 16:02:00 -0400217
David Barker5c0e80e2018-04-17 12:54:29 +0100218 // If the first OBU is a temporal delimiter, skip over it and look at the next
219 // OBU in the bitstream
220 if (obu_header.type == OBU_TEMPORAL_DELIMITER) {
221 // Skip any associated payload (there shouldn't be one, but just in case)
222 data += bytes_read + payload_size;
223 data_sz -= bytes_read + payload_size;
Tom Finegan13ee28c2018-02-26 19:37:41 -0800224
David Barker5c0e80e2018-04-17 12:54:29 +0100225 status = aom_read_obu_header_and_size(
226 data, data_sz, si->is_annexb, &obu_header, &payload_size, &bytes_read);
227 if (status != AOM_CODEC_OK) return status;
Soo-Chul Han29c46fb2018-03-23 16:02:00 -0400228 }
Vignesh Venkatasubramanian03391a22018-03-09 12:25:55 -0800229
David Barker5c0e80e2018-04-17 12:54:29 +0100230 // Check that the selected OBU is a sequence header
231 if (obu_header.type != OBU_SEQUENCE_HEADER) return AOM_CODEC_UNSUP_BITSTREAM;
232
233 // Read a few values from the sequence header payload
234 data += bytes_read;
235 data_sz -= bytes_read;
236 struct aom_read_bit_buffer rb = { data, data + data_sz, 0, NULL, NULL };
Tom Finegan13ee28c2018-02-26 19:37:41 -0800237
Debargha Mukherjee112c5822018-04-09 09:42:29 -0700238 av1_read_profile(&rb); // profile
239 const int still_picture = aom_rb_read_bit(&rb);
240 const int reduced_still_picture_hdr = aom_rb_read_bit(&rb);
241
242 if (!still_picture && reduced_still_picture_hdr) {
243 return AOM_CODEC_UNSUP_BITSTREAM;
244 }
245
Debargha Mukherjeeacd41f92018-04-11 07:58:34 -0700246 parse_operating_points(&rb, reduced_still_picture_hdr);
Soo-Chul Hanf8589862018-01-24 03:13:14 +0000247
Tom Fineganf277ca32018-02-26 12:09:52 -0800248 int num_bits_width = aom_rb_read_literal(&rb, 4) + 1;
249 int num_bits_height = aom_rb_read_literal(&rb, 4) + 1;
250 int max_frame_width = aom_rb_read_literal(&rb, num_bits_width) + 1;
251 int max_frame_height = aom_rb_read_literal(&rb, num_bits_height) + 1;
252 si->w = max_frame_width;
253 si->h = max_frame_height;
Tom Fineganf277ca32018-02-26 12:09:52 -0800254
Yaowu Xuc27fc142016-08-22 16:08:15 -0700255 if (is_intra_only != NULL) *is_intra_only = intra_only_flag;
Yaowu Xuf883b422016-08-30 14:01:10 -0700256 return AOM_CODEC_OK;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700257}
258
Yaowu Xuf883b422016-08-30 14:01:10 -0700259static aom_codec_err_t decoder_peek_si(const uint8_t *data,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700260 unsigned int data_sz,
Yaowu Xuf883b422016-08-30 14:01:10 -0700261 aom_codec_stream_info_t *si) {
Sebastien Alaiwan2b1ec182017-12-21 09:38:27 +0100262 return decoder_peek_si_internal(data, data_sz, si, NULL);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700263}
264
Yaowu Xuf883b422016-08-30 14:01:10 -0700265static aom_codec_err_t decoder_get_si(aom_codec_alg_priv_t *ctx,
266 aom_codec_stream_info_t *si) {
Ralph Gilesafe71d92017-05-03 13:18:57 -0700267 memcpy(si, &ctx->si, sizeof(*si));
Yaowu Xuc27fc142016-08-22 16:08:15 -0700268
Yaowu Xuf883b422016-08-30 14:01:10 -0700269 return AOM_CODEC_OK;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700270}
271
Yaowu Xuf883b422016-08-30 14:01:10 -0700272static void set_error_detail(aom_codec_alg_priv_t *ctx,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700273 const char *const error) {
274 ctx->base.err_detail = error;
275}
276
Yaowu Xuf883b422016-08-30 14:01:10 -0700277static aom_codec_err_t update_error_state(
278 aom_codec_alg_priv_t *ctx, const struct aom_internal_error_info *error) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700279 if (error->error_code)
280 set_error_detail(ctx, error->has_detail ? error->detail : NULL);
281
282 return error->error_code;
283}
284
Yaowu Xuf883b422016-08-30 14:01:10 -0700285static void init_buffer_callbacks(aom_codec_alg_priv_t *ctx) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700286 int i;
287
288 for (i = 0; i < ctx->num_frame_workers; ++i) {
Yaowu Xuf883b422016-08-30 14:01:10 -0700289 AVxWorker *const worker = &ctx->frame_workers[i];
Yaowu Xuc27fc142016-08-22 16:08:15 -0700290 FrameWorkerData *const frame_worker_data = (FrameWorkerData *)worker->data1;
Yaowu Xuf883b422016-08-30 14:01:10 -0700291 AV1_COMMON *const cm = &frame_worker_data->pbi->common;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700292 BufferPool *const pool = cm->buffer_pool;
293
294 cm->new_fb_idx = INVALID_IDX;
295 cm->byte_alignment = ctx->byte_alignment;
296 cm->skip_loop_filter = ctx->skip_loop_filter;
297
298 if (ctx->get_ext_fb_cb != NULL && ctx->release_ext_fb_cb != NULL) {
299 pool->get_fb_cb = ctx->get_ext_fb_cb;
300 pool->release_fb_cb = ctx->release_ext_fb_cb;
301 pool->cb_priv = ctx->ext_priv;
302 } else {
Yaowu Xuf883b422016-08-30 14:01:10 -0700303 pool->get_fb_cb = av1_get_frame_buffer;
304 pool->release_fb_cb = av1_release_frame_buffer;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700305
Yaowu Xuf883b422016-08-30 14:01:10 -0700306 if (av1_alloc_internal_frame_buffers(&pool->int_frame_buffers))
307 aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700308 "Failed to initialize internal frame buffers");
309
310 pool->cb_priv = &pool->int_frame_buffers;
311 }
312 }
313}
314
Yaowu Xuf883b422016-08-30 14:01:10 -0700315static void set_default_ppflags(aom_postproc_cfg_t *cfg) {
316 cfg->post_proc_flag = AOM_DEBLOCK | AOM_DEMACROBLOCK;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700317 cfg->deblocking_level = 4;
318 cfg->noise_level = 0;
319}
320
321static int frame_worker_hook(void *arg1, void *arg2) {
322 FrameWorkerData *const frame_worker_data = (FrameWorkerData *)arg1;
323 const uint8_t *data = frame_worker_data->data;
324 (void)arg2;
325
Yaowu Xuf883b422016-08-30 14:01:10 -0700326 frame_worker_data->result = av1_receive_compressed_data(
Yaowu Xuc27fc142016-08-22 16:08:15 -0700327 frame_worker_data->pbi, frame_worker_data->data_size, &data);
328 frame_worker_data->data_end = data;
329
Debargha Mukherjee5521a182018-03-06 12:29:01 -0800330 if (frame_worker_data->result != 0) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700331 // Check decode result in serial decode.
332 frame_worker_data->pbi->cur_buf->buf.corrupted = 1;
333 frame_worker_data->pbi->need_resync = 1;
334 }
335 return !frame_worker_data->result;
336}
337
Yaowu Xuf883b422016-08-30 14:01:10 -0700338static aom_codec_err_t init_decoder(aom_codec_alg_priv_t *ctx) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700339 int i;
Yaowu Xuf883b422016-08-30 14:01:10 -0700340 const AVxWorkerInterface *const winterface = aom_get_worker_interface();
Yaowu Xuc27fc142016-08-22 16:08:15 -0700341
342 ctx->last_show_frame = -1;
343 ctx->next_submit_worker_id = 0;
344 ctx->last_submit_worker_id = 0;
345 ctx->next_output_worker_id = 0;
346 ctx->frame_cache_read = 0;
347 ctx->frame_cache_write = 0;
348 ctx->num_cache_frames = 0;
349 ctx->need_resync = 1;
Debargha Mukherjee5521a182018-03-06 12:29:01 -0800350 ctx->num_frame_workers = 1;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700351 if (ctx->num_frame_workers > MAX_DECODE_THREADS)
352 ctx->num_frame_workers = MAX_DECODE_THREADS;
353 ctx->available_threads = ctx->num_frame_workers;
354 ctx->flushed = 0;
355
Yaowu Xuf883b422016-08-30 14:01:10 -0700356 ctx->buffer_pool = (BufferPool *)aom_calloc(1, sizeof(BufferPool));
357 if (ctx->buffer_pool == NULL) return AOM_CODEC_MEM_ERROR;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700358
359#if CONFIG_MULTITHREAD
360 if (pthread_mutex_init(&ctx->buffer_pool->pool_mutex, NULL)) {
361 set_error_detail(ctx, "Failed to allocate buffer pool mutex");
Yaowu Xuf883b422016-08-30 14:01:10 -0700362 return AOM_CODEC_MEM_ERROR;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700363 }
364#endif
365
Yaowu Xuf883b422016-08-30 14:01:10 -0700366 ctx->frame_workers = (AVxWorker *)aom_malloc(ctx->num_frame_workers *
Yaowu Xuc27fc142016-08-22 16:08:15 -0700367 sizeof(*ctx->frame_workers));
368 if (ctx->frame_workers == NULL) {
369 set_error_detail(ctx, "Failed to allocate frame_workers");
Yaowu Xuf883b422016-08-30 14:01:10 -0700370 return AOM_CODEC_MEM_ERROR;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700371 }
372
373 for (i = 0; i < ctx->num_frame_workers; ++i) {
Yaowu Xuf883b422016-08-30 14:01:10 -0700374 AVxWorker *const worker = &ctx->frame_workers[i];
Yaowu Xuc27fc142016-08-22 16:08:15 -0700375 FrameWorkerData *frame_worker_data = NULL;
376 winterface->init(worker);
Yaowu Xuf883b422016-08-30 14:01:10 -0700377 worker->data1 = aom_memalign(32, sizeof(FrameWorkerData));
Yaowu Xuc27fc142016-08-22 16:08:15 -0700378 if (worker->data1 == NULL) {
379 set_error_detail(ctx, "Failed to allocate frame_worker_data");
Yaowu Xuf883b422016-08-30 14:01:10 -0700380 return AOM_CODEC_MEM_ERROR;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700381 }
382 frame_worker_data = (FrameWorkerData *)worker->data1;
Yaowu Xuf883b422016-08-30 14:01:10 -0700383 frame_worker_data->pbi = av1_decoder_create(ctx->buffer_pool);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700384 if (frame_worker_data->pbi == NULL) {
385 set_error_detail(ctx, "Failed to allocate frame_worker_data");
Yaowu Xuf883b422016-08-30 14:01:10 -0700386 return AOM_CODEC_MEM_ERROR;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700387 }
Maxym Dmytrychenkocc6e0e12018-02-05 16:35:37 +0100388 frame_worker_data->pbi->common.options = &ctx->cfg.cfg;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700389 frame_worker_data->pbi->frame_worker_owner = worker;
390 frame_worker_data->worker_id = i;
391 frame_worker_data->scratch_buffer = NULL;
392 frame_worker_data->scratch_buffer_size = 0;
393 frame_worker_data->frame_context_ready = 0;
394 frame_worker_data->received_frame = 0;
395#if CONFIG_MULTITHREAD
396 if (pthread_mutex_init(&frame_worker_data->stats_mutex, NULL)) {
397 set_error_detail(ctx, "Failed to allocate frame_worker_data mutex");
Yaowu Xuf883b422016-08-30 14:01:10 -0700398 return AOM_CODEC_MEM_ERROR;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700399 }
400
401 if (pthread_cond_init(&frame_worker_data->stats_cond, NULL)) {
402 set_error_detail(ctx, "Failed to allocate frame_worker_data cond");
Yaowu Xuf883b422016-08-30 14:01:10 -0700403 return AOM_CODEC_MEM_ERROR;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700404 }
405#endif
Sebastien Alaiwan8b7a4e12017-06-13 11:25:57 +0200406 frame_worker_data->pbi->allow_lowbitdepth = ctx->cfg.allow_lowbitdepth;
407
Yaowu Xuc27fc142016-08-22 16:08:15 -0700408 // If decoding in serial mode, FrameWorker thread could create tile worker
409 // thread or loopfilter thread.
Debargha Mukherjee5521a182018-03-06 12:29:01 -0800410 frame_worker_data->pbi->max_threads = ctx->cfg.threads;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700411 frame_worker_data->pbi->inv_tile_order = ctx->invert_tile_order;
Yunqing Wang8ae64a92018-01-12 12:26:44 -0800412 frame_worker_data->pbi->common.large_scale_tile = ctx->tile_mode;
Soo-Chul Han29c46fb2018-03-23 16:02:00 -0400413 frame_worker_data->pbi->common.is_annexb = ctx->is_annexb;
Yunqing Wang8ae64a92018-01-12 12:26:44 -0800414 frame_worker_data->pbi->dec_tile_row = ctx->decode_tile_row;
415 frame_worker_data->pbi->dec_tile_col = ctx->decode_tile_col;
Yaowu Xuf883b422016-08-30 14:01:10 -0700416 worker->hook = (AVxWorkerHook)frame_worker_hook;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700417 if (!winterface->reset(worker)) {
418 set_error_detail(ctx, "Frame Worker thread creation failed");
Yaowu Xuf883b422016-08-30 14:01:10 -0700419 return AOM_CODEC_MEM_ERROR;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700420 }
421 }
422
423 // If postprocessing was enabled by the application and a
424 // configuration has not been provided, default it.
Yaowu Xuf883b422016-08-30 14:01:10 -0700425 if (!ctx->postproc_cfg_set && (ctx->base.init_flags & AOM_CODEC_USE_POSTPROC))
Yaowu Xuc27fc142016-08-22 16:08:15 -0700426 set_default_ppflags(&ctx->postproc_cfg);
427
428 init_buffer_callbacks(ctx);
429
Yaowu Xuf883b422016-08-30 14:01:10 -0700430 return AOM_CODEC_OK;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700431}
432
Yaowu Xuf883b422016-08-30 14:01:10 -0700433static INLINE void check_resync(aom_codec_alg_priv_t *const ctx,
434 const AV1Decoder *const pbi) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700435 // Clear resync flag if worker got a key frame or intra only frame.
436 if (ctx->need_resync == 1 && pbi->need_resync == 0 &&
437 (pbi->common.intra_only || pbi->common.frame_type == KEY_FRAME))
438 ctx->need_resync = 0;
439}
440
Yaowu Xuf883b422016-08-30 14:01:10 -0700441static aom_codec_err_t decode_one(aom_codec_alg_priv_t *ctx,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700442 const uint8_t **data, unsigned int data_sz,
Sean DuBois47cc2552018-01-23 07:44:16 +0000443 void *user_priv) {
Yaowu Xuf883b422016-08-30 14:01:10 -0700444 const AVxWorkerInterface *const winterface = aom_get_worker_interface();
Yaowu Xuc27fc142016-08-22 16:08:15 -0700445
446 // Determine the stream parameters. Note that we rely on peek_si to
447 // validate that we have a buffer that does not wrap around the top
448 // of the heap.
449 if (!ctx->si.h) {
450 int is_intra_only = 0;
Soo-Chul Han29c46fb2018-03-23 16:02:00 -0400451 ctx->si.is_annexb = ctx->is_annexb;
Yaowu Xuf883b422016-08-30 14:01:10 -0700452 const aom_codec_err_t res =
Sebastien Alaiwan2b1ec182017-12-21 09:38:27 +0100453 decoder_peek_si_internal(*data, data_sz, &ctx->si, &is_intra_only);
Yaowu Xuf883b422016-08-30 14:01:10 -0700454 if (res != AOM_CODEC_OK) return res;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700455
Yaowu Xuf883b422016-08-30 14:01:10 -0700456 if (!ctx->si.is_kf && !is_intra_only) return AOM_CODEC_ERROR;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700457 }
458
Debargha Mukherjee5521a182018-03-06 12:29:01 -0800459 AVxWorker *const worker = ctx->frame_workers;
460 FrameWorkerData *const frame_worker_data = (FrameWorkerData *)worker->data1;
461 frame_worker_data->data = *data;
462 frame_worker_data->data_size = data_sz;
463 frame_worker_data->user_priv = user_priv;
464 frame_worker_data->received_frame = 1;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700465
Nathan E. Egge2cf03b12017-02-22 16:19:59 -0500466#if CONFIG_INSPECTION
Debargha Mukherjee5521a182018-03-06 12:29:01 -0800467 frame_worker_data->pbi->inspect_cb = ctx->inspect_cb;
468 frame_worker_data->pbi->inspect_ctx = ctx->inspect_ctx;
Nathan E. Egge2cf03b12017-02-22 16:19:59 -0500469#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -0700470
Debargha Mukherjee5521a182018-03-06 12:29:01 -0800471 frame_worker_data->pbi->common.large_scale_tile = ctx->tile_mode;
472 frame_worker_data->pbi->dec_tile_row = ctx->decode_tile_row;
473 frame_worker_data->pbi->dec_tile_col = ctx->decode_tile_col;
Yunqing Wang2a5575e2018-02-23 16:02:18 -0800474
Soo-Chul Han29c46fb2018-03-23 16:02:00 -0400475 frame_worker_data->pbi->common.is_annexb = ctx->is_annexb;
476
Debargha Mukherjee5521a182018-03-06 12:29:01 -0800477 worker->had_error = 0;
478 winterface->execute(worker);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700479
Debargha Mukherjee5521a182018-03-06 12:29:01 -0800480 // Update data pointer after decode.
481 *data = frame_worker_data->data_end;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700482
Debargha Mukherjee5521a182018-03-06 12:29:01 -0800483 if (worker->had_error)
484 return update_error_state(ctx, &frame_worker_data->pbi->common.error);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700485
Debargha Mukherjee5521a182018-03-06 12:29:01 -0800486 check_resync(ctx, frame_worker_data->pbi);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700487
Yaowu Xuf883b422016-08-30 14:01:10 -0700488 return AOM_CODEC_OK;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700489}
490
Yaowu Xuf883b422016-08-30 14:01:10 -0700491static aom_codec_err_t decoder_decode(aom_codec_alg_priv_t *ctx,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700492 const uint8_t *data, unsigned int data_sz,
Sean DuBois47cc2552018-01-23 07:44:16 +0000493 void *user_priv) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700494 const uint8_t *data_start = data;
495 const uint8_t *const data_end = data + data_sz;
Yaowu Xub02d0b12017-12-15 01:32:34 +0000496 aom_codec_err_t res = AOM_CODEC_OK;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700497 uint32_t frame_sizes[8];
Soo-Chul Han38427e82017-09-27 15:06:13 -0400498 int frame_count = 0;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700499
500 if (data == NULL && data_sz == 0) {
501 ctx->flushed = 1;
Yaowu Xuf883b422016-08-30 14:01:10 -0700502 return AOM_CODEC_OK;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700503 }
504
505 // Reset flushed when receiving a valid frame.
506 ctx->flushed = 0;
507
508 // Initialize the decoder workers on the first frame.
509 if (ctx->frame_workers == NULL) {
Urvang Joshi454280d2016-10-14 16:51:44 -0700510 res = init_decoder(ctx);
Yaowu Xuf883b422016-08-30 14:01:10 -0700511 if (res != AOM_CODEC_OK) return res;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700512 }
Soo-Chul Han29c46fb2018-03-23 16:02:00 -0400513
Soo-Chul Han8acdbfc2018-04-02 12:55:33 -0400514 if (ctx->is_annexb) {
515 // read the size of this temporal unit
516 size_t length_of_size;
517 uint64_t size_of_unit;
518 if (aom_uleb_decode(data_start, data_sz, &size_of_unit, &length_of_size) !=
519 0) {
520 return AOM_CODEC_CORRUPT_FRAME;
521 }
522 data_start += length_of_size;
523 }
524
Debargha Mukherjee5521a182018-03-06 12:29:01 -0800525 // Decode in serial mode.
526 if (frame_count > 0) {
527 int i;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700528
Debargha Mukherjee5521a182018-03-06 12:29:01 -0800529 for (i = 0; i < frame_count; ++i) {
530 const uint8_t *data_start_copy = data_start;
531 const uint32_t frame_size = frame_sizes[i];
532 if (data_start < data || frame_size > (uint32_t)(data_end - data_start)) {
533 set_error_detail(ctx, "Invalid frame size in index");
534 return AOM_CODEC_CORRUPT_FRAME;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700535 }
536
Debargha Mukherjee5521a182018-03-06 12:29:01 -0800537 res = decode_one(ctx, &data_start_copy, frame_size, user_priv);
Yaowu Xuf883b422016-08-30 14:01:10 -0700538 if (res != AOM_CODEC_OK) return res;
Debargha Mukherjee5521a182018-03-06 12:29:01 -0800539
540 data_start += frame_size;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700541 }
542 } else {
Debargha Mukherjee5521a182018-03-06 12:29:01 -0800543 while (data_start < data_end) {
Soo-Chul Han8acdbfc2018-04-02 12:55:33 -0400544 if (ctx->is_annexb) {
545 // read the size of this frame unit
546 size_t length_of_size;
547 uint64_t size_of_frame_unit;
548 if (aom_uleb_decode(data_start, (uint32_t)(data_end - data_start),
549 &size_of_frame_unit, &length_of_size) != 0) {
550 return AOM_CODEC_CORRUPT_FRAME;
551 }
552 data_start += length_of_size;
553 }
554
Debargha Mukherjee5521a182018-03-06 12:29:01 -0800555 const uint32_t frame_size = (uint32_t)(data_end - data_start);
556 res = decode_one(ctx, &data_start, frame_size, user_priv);
557 if (res != AOM_CODEC_OK) return res;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700558
Debargha Mukherjee5521a182018-03-06 12:29:01 -0800559 // Account for suboptimal termination by the encoder.
Yaowu Xuc27fc142016-08-22 16:08:15 -0700560 while (data_start < data_end) {
Debargha Mukherjee5521a182018-03-06 12:29:01 -0800561 const uint8_t marker = data_start[0];
562 if (marker) break;
563 ++data_start;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700564 }
565 }
566 }
567
568 return res;
569}
570
Andrey Norkin6f1c2f72018-01-15 20:08:52 -0800571aom_image_t *add_grain_if_needed(aom_image_t *img, aom_image_t *grain_img_buf,
572 aom_film_grain_t *grain_params) {
573 if (!grain_params->apply_grain) return img;
574
575 if (grain_img_buf &&
576 (img->d_w != grain_img_buf->d_w || img->d_h != grain_img_buf->d_h ||
Andrey Norkin4352fed2018-03-01 17:01:49 -0800577 img->fmt != grain_img_buf->fmt || !(img->d_h % 2) || !(img->d_w % 2))) {
Andrey Norkin6f1c2f72018-01-15 20:08:52 -0800578 aom_img_free(grain_img_buf);
579 grain_img_buf = NULL;
580 }
581 if (!grain_img_buf) {
Andrey Norkin4352fed2018-03-01 17:01:49 -0800582 int w_even = img->d_w % 2 ? img->d_w + 1 : img->d_w;
583 int h_even = img->d_h % 2 ? img->d_h + 1 : img->d_h;
584 grain_img_buf = aom_img_alloc(NULL, img->fmt, w_even, h_even, 16);
Andrey Norkin6f1c2f72018-01-15 20:08:52 -0800585 grain_img_buf->bit_depth = img->bit_depth;
586 }
587
588 av1_add_film_grain(grain_params, img, grain_img_buf);
589
590 return grain_img_buf;
591}
Andrey Norkin6f1c2f72018-01-15 20:08:52 -0800592
Yaowu Xuf883b422016-08-30 14:01:10 -0700593static aom_image_t *decoder_get_frame(aom_codec_alg_priv_t *ctx,
594 aom_codec_iter_t *iter) {
595 aom_image_t *img = NULL;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700596
Yaowu Xuc27fc142016-08-22 16:08:15 -0700597 // Output the frames in the cache first.
598 if (ctx->num_cache_frames > 0) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700599 ctx->last_show_frame = ctx->frame_cache[ctx->frame_cache_read].fb_idx;
600 if (ctx->need_resync) return NULL;
601 img = &ctx->frame_cache[ctx->frame_cache_read].img;
602 ctx->frame_cache_read = (ctx->frame_cache_read + 1) % FRAME_CACHE_SIZE;
603 --ctx->num_cache_frames;
Andrey Norkin6f1c2f72018-01-15 20:08:52 -0800604 return add_grain_if_needed(
605 img, ctx->image_with_grain,
606 &ctx->frame_cache[ctx->frame_cache_read].film_grain_params);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700607 }
608
609 // iter acts as a flip flop, so an image is only returned on the first
610 // call to get_frame.
611 if (*iter == NULL && ctx->frame_workers != NULL) {
612 do {
613 YV12_BUFFER_CONFIG sd;
Yaowu Xuf883b422016-08-30 14:01:10 -0700614 const AVxWorkerInterface *const winterface = aom_get_worker_interface();
615 AVxWorker *const worker = &ctx->frame_workers[ctx->next_output_worker_id];
Yaowu Xuc27fc142016-08-22 16:08:15 -0700616 FrameWorkerData *const frame_worker_data =
617 (FrameWorkerData *)worker->data1;
618 ctx->next_output_worker_id =
619 (ctx->next_output_worker_id + 1) % ctx->num_frame_workers;
620 // Wait for the frame from worker thread.
621 if (winterface->sync(worker)) {
622 // Check if worker has received any frames.
623 if (frame_worker_data->received_frame == 1) {
624 ++ctx->available_threads;
625 frame_worker_data->received_frame = 0;
626 check_resync(ctx, frame_worker_data->pbi);
627 }
Yaowu Xuf883b422016-08-30 14:01:10 -0700628 if (av1_get_raw_frame(frame_worker_data->pbi, &sd) == 0) {
629 AV1_COMMON *const cm = &frame_worker_data->pbi->common;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700630 RefCntBuffer *const frame_bufs = cm->buffer_pool->frame_bufs;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700631 ctx->last_show_frame = frame_worker_data->pbi->common.new_fb_idx;
632 if (ctx->need_resync) return NULL;
633 yuvconfig2image(&ctx->img, &sd, frame_worker_data->user_priv);
634
Imdad Sardharwallaaf8e2642018-01-19 11:46:34 +0000635 const int num_planes = av1_num_planes(cm);
Yunqing Wangeeb08a92017-07-07 21:25:18 -0700636 if (cm->single_tile_decoding &&
Yunqing Wangd8cd55f2017-02-27 12:16:00 -0800637 frame_worker_data->pbi->dec_tile_row >= 0) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700638 const int tile_row =
Yaowu Xuf883b422016-08-30 14:01:10 -0700639 AOMMIN(frame_worker_data->pbi->dec_tile_row, cm->tile_rows - 1);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700640 const int mi_row = tile_row * cm->tile_height;
641 const int ssy = ctx->img.y_chroma_shift;
642 int plane;
643 ctx->img.planes[0] += mi_row * MI_SIZE * ctx->img.stride[0];
Imdad Sardharwallaaf8e2642018-01-19 11:46:34 +0000644 if (num_planes > 1) {
645 for (plane = 1; plane < MAX_MB_PLANE; ++plane) {
646 ctx->img.planes[plane] +=
647 mi_row * (MI_SIZE >> ssy) * ctx->img.stride[plane];
648 }
Yaowu Xuc27fc142016-08-22 16:08:15 -0700649 }
650 ctx->img.d_h =
Yaowu Xuf883b422016-08-30 14:01:10 -0700651 AOMMIN(cm->tile_height, cm->mi_rows - mi_row) * MI_SIZE;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700652 }
653
Yunqing Wangeeb08a92017-07-07 21:25:18 -0700654 if (cm->single_tile_decoding &&
Yunqing Wangd8cd55f2017-02-27 12:16:00 -0800655 frame_worker_data->pbi->dec_tile_col >= 0) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700656 const int tile_col =
Yaowu Xuf883b422016-08-30 14:01:10 -0700657 AOMMIN(frame_worker_data->pbi->dec_tile_col, cm->tile_cols - 1);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700658 const int mi_col = tile_col * cm->tile_width;
659 const int ssx = ctx->img.x_chroma_shift;
660 int plane;
661 ctx->img.planes[0] += mi_col * MI_SIZE;
Imdad Sardharwallaaf8e2642018-01-19 11:46:34 +0000662 if (num_planes > 1) {
663 for (plane = 1; plane < MAX_MB_PLANE; ++plane) {
664 ctx->img.planes[plane] += mi_col * (MI_SIZE >> ssx);
665 }
Yaowu Xuc27fc142016-08-22 16:08:15 -0700666 }
667 ctx->img.d_w =
Yaowu Xuf883b422016-08-30 14:01:10 -0700668 AOMMIN(cm->tile_width, cm->mi_cols - mi_col) * MI_SIZE;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700669 }
Yaowu Xuc27fc142016-08-22 16:08:15 -0700670
671 ctx->img.fb_priv = frame_bufs[cm->new_fb_idx].raw_frame_buffer.priv;
672 img = &ctx->img;
Soo-Chul Hanf8589862018-01-24 03:13:14 +0000673 img->temporal_id = cm->temporal_layer_id;
674 img->enhancement_id = cm->enhancement_layer_id;
Andrey Norkin6f1c2f72018-01-15 20:08:52 -0800675 return add_grain_if_needed(
676 img, ctx->image_with_grain,
677 &frame_worker_data->pbi->common.film_grain_params);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700678 }
679 } else {
680 // Decoding failed. Release the worker thread.
681 frame_worker_data->received_frame = 0;
682 ++ctx->available_threads;
683 ctx->need_resync = 1;
684 if (ctx->flushed != 1) return NULL;
685 }
686 } while (ctx->next_output_worker_id != ctx->next_submit_worker_id);
687 }
688 return NULL;
689}
690
Yaowu Xuf883b422016-08-30 14:01:10 -0700691static aom_codec_err_t decoder_set_fb_fn(
692 aom_codec_alg_priv_t *ctx, aom_get_frame_buffer_cb_fn_t cb_get,
693 aom_release_frame_buffer_cb_fn_t cb_release, void *cb_priv) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700694 if (cb_get == NULL || cb_release == NULL) {
Yaowu Xuf883b422016-08-30 14:01:10 -0700695 return AOM_CODEC_INVALID_PARAM;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700696 } else if (ctx->frame_workers == NULL) {
697 // If the decoder has already been initialized, do not accept changes to
698 // the frame buffer functions.
699 ctx->get_ext_fb_cb = cb_get;
700 ctx->release_ext_fb_cb = cb_release;
701 ctx->ext_priv = cb_priv;
Yaowu Xuf883b422016-08-30 14:01:10 -0700702 return AOM_CODEC_OK;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700703 }
704
Yaowu Xuf883b422016-08-30 14:01:10 -0700705 return AOM_CODEC_ERROR;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700706}
707
Yaowu Xuf883b422016-08-30 14:01:10 -0700708static aom_codec_err_t ctrl_set_reference(aom_codec_alg_priv_t *ctx,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700709 va_list args) {
Thomas Daede497d1952017-08-08 17:33:06 -0700710 av1_ref_frame_t *const data = va_arg(args, av1_ref_frame_t *);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700711
Yaowu Xuc27fc142016-08-22 16:08:15 -0700712 if (data) {
Thomas Daede497d1952017-08-08 17:33:06 -0700713 av1_ref_frame_t *const frame = data;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700714 YV12_BUFFER_CONFIG sd;
Yaowu Xuf883b422016-08-30 14:01:10 -0700715 AVxWorker *const worker = ctx->frame_workers;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700716 FrameWorkerData *const frame_worker_data = (FrameWorkerData *)worker->data1;
717 image2yuvconfig(&frame->img, &sd);
Thomas Daede497d1952017-08-08 17:33:06 -0700718 return av1_set_reference_dec(&frame_worker_data->pbi->common, frame->idx,
Yaowu Xuf883b422016-08-30 14:01:10 -0700719 &sd);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700720 } else {
Yaowu Xuf883b422016-08-30 14:01:10 -0700721 return AOM_CODEC_INVALID_PARAM;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700722 }
723}
724
Yaowu Xuf883b422016-08-30 14:01:10 -0700725static aom_codec_err_t ctrl_copy_reference(aom_codec_alg_priv_t *ctx,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700726 va_list args) {
Thomas Daede497d1952017-08-08 17:33:06 -0700727 const av1_ref_frame_t *const frame = va_arg(args, av1_ref_frame_t *);
Urvang Joshi77853e52016-07-15 12:47:01 -0700728 if (frame) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700729 YV12_BUFFER_CONFIG sd;
Yaowu Xuf883b422016-08-30 14:01:10 -0700730 AVxWorker *const worker = ctx->frame_workers;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700731 FrameWorkerData *const frame_worker_data = (FrameWorkerData *)worker->data1;
732 image2yuvconfig(&frame->img, &sd);
Thomas Daede497d1952017-08-08 17:33:06 -0700733 return av1_copy_reference_dec(frame_worker_data->pbi, frame->idx, &sd);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700734 } else {
Yaowu Xuf883b422016-08-30 14:01:10 -0700735 return AOM_CODEC_INVALID_PARAM;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700736 }
737}
738
Yaowu Xuf883b422016-08-30 14:01:10 -0700739static aom_codec_err_t ctrl_get_reference(aom_codec_alg_priv_t *ctx,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700740 va_list args) {
Yaowu Xuf883b422016-08-30 14:01:10 -0700741 av1_ref_frame_t *data = va_arg(args, av1_ref_frame_t *);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700742 if (data) {
743 YV12_BUFFER_CONFIG *fb;
Yaowu Xuf883b422016-08-30 14:01:10 -0700744 AVxWorker *const worker = ctx->frame_workers;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700745 FrameWorkerData *const frame_worker_data = (FrameWorkerData *)worker->data1;
746 fb = get_ref_frame(&frame_worker_data->pbi->common, data->idx);
Yaowu Xuf883b422016-08-30 14:01:10 -0700747 if (fb == NULL) return AOM_CODEC_ERROR;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700748 yuvconfig2image(&data->img, fb, NULL);
Yaowu Xuf883b422016-08-30 14:01:10 -0700749 return AOM_CODEC_OK;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700750 } else {
Yaowu Xuf883b422016-08-30 14:01:10 -0700751 return AOM_CODEC_INVALID_PARAM;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700752 }
753}
754
Yaowu Xuf883b422016-08-30 14:01:10 -0700755static aom_codec_err_t ctrl_get_new_frame_image(aom_codec_alg_priv_t *ctx,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700756 va_list args) {
Yaowu Xuf883b422016-08-30 14:01:10 -0700757 aom_image_t *new_img = va_arg(args, aom_image_t *);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700758 if (new_img) {
759 YV12_BUFFER_CONFIG new_frame;
Yaowu Xuf883b422016-08-30 14:01:10 -0700760 AVxWorker *const worker = ctx->frame_workers;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700761 FrameWorkerData *const frame_worker_data = (FrameWorkerData *)worker->data1;
762
Yaowu Xuf883b422016-08-30 14:01:10 -0700763 if (av1_get_frame_to_show(frame_worker_data->pbi, &new_frame) == 0) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700764 yuvconfig2image(new_img, &new_frame, NULL);
Yaowu Xuf883b422016-08-30 14:01:10 -0700765 return AOM_CODEC_OK;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700766 } else {
Yaowu Xuf883b422016-08-30 14:01:10 -0700767 return AOM_CODEC_ERROR;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700768 }
769 } else {
Yaowu Xuf883b422016-08-30 14:01:10 -0700770 return AOM_CODEC_INVALID_PARAM;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700771 }
772}
773
Yaowu Xuf883b422016-08-30 14:01:10 -0700774static aom_codec_err_t ctrl_set_postproc(aom_codec_alg_priv_t *ctx,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700775 va_list args) {
776 (void)ctx;
777 (void)args;
Yaowu Xuf883b422016-08-30 14:01:10 -0700778 return AOM_CODEC_INCAPABLE;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700779}
780
Yaowu Xuf883b422016-08-30 14:01:10 -0700781static aom_codec_err_t ctrl_set_dbg_options(aom_codec_alg_priv_t *ctx,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700782 va_list args) {
783 (void)ctx;
784 (void)args;
Yaowu Xuf883b422016-08-30 14:01:10 -0700785 return AOM_CODEC_INCAPABLE;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700786}
787
Yaowu Xuf883b422016-08-30 14:01:10 -0700788static aom_codec_err_t ctrl_get_last_ref_updates(aom_codec_alg_priv_t *ctx,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700789 va_list args) {
790 int *const update_info = va_arg(args, int *);
791
Yaowu Xuc27fc142016-08-22 16:08:15 -0700792 if (update_info) {
793 if (ctx->frame_workers) {
Yaowu Xuf883b422016-08-30 14:01:10 -0700794 AVxWorker *const worker = ctx->frame_workers;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700795 FrameWorkerData *const frame_worker_data =
796 (FrameWorkerData *)worker->data1;
797 *update_info = frame_worker_data->pbi->refresh_frame_flags;
Yaowu Xuf883b422016-08-30 14:01:10 -0700798 return AOM_CODEC_OK;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700799 } else {
Yaowu Xuf883b422016-08-30 14:01:10 -0700800 return AOM_CODEC_ERROR;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700801 }
802 }
803
Yaowu Xuf883b422016-08-30 14:01:10 -0700804 return AOM_CODEC_INVALID_PARAM;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700805}
806
Peter Boströma1f64322017-01-19 11:35:30 -0500807static aom_codec_err_t ctrl_get_last_quantizer(aom_codec_alg_priv_t *ctx,
808 va_list args) {
809 int *const arg = va_arg(args, int *);
810 if (arg == NULL) return AOM_CODEC_INVALID_PARAM;
811 *arg =
812 ((FrameWorkerData *)ctx->frame_workers[0].data1)->pbi->common.base_qindex;
813 return AOM_CODEC_OK;
814}
815
Yaowu Xuf883b422016-08-30 14:01:10 -0700816static aom_codec_err_t ctrl_get_frame_corrupted(aom_codec_alg_priv_t *ctx,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700817 va_list args) {
818 int *corrupted = va_arg(args, int *);
819
820 if (corrupted) {
821 if (ctx->frame_workers) {
Yaowu Xuf883b422016-08-30 14:01:10 -0700822 AVxWorker *const worker = ctx->frame_workers;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700823 FrameWorkerData *const frame_worker_data =
824 (FrameWorkerData *)worker->data1;
825 RefCntBuffer *const frame_bufs =
826 frame_worker_data->pbi->common.buffer_pool->frame_bufs;
827 if (frame_worker_data->pbi->common.frame_to_show == NULL)
Yaowu Xuf883b422016-08-30 14:01:10 -0700828 return AOM_CODEC_ERROR;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700829 if (ctx->last_show_frame >= 0)
830 *corrupted = frame_bufs[ctx->last_show_frame].buf.corrupted;
Yaowu Xuf883b422016-08-30 14:01:10 -0700831 return AOM_CODEC_OK;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700832 } else {
Yaowu Xuf883b422016-08-30 14:01:10 -0700833 return AOM_CODEC_ERROR;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700834 }
835 }
836
Yaowu Xuf883b422016-08-30 14:01:10 -0700837 return AOM_CODEC_INVALID_PARAM;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700838}
839
Yaowu Xuf883b422016-08-30 14:01:10 -0700840static aom_codec_err_t ctrl_get_frame_size(aom_codec_alg_priv_t *ctx,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700841 va_list args) {
842 int *const frame_size = va_arg(args, int *);
843
Yaowu Xuc27fc142016-08-22 16:08:15 -0700844 if (frame_size) {
845 if (ctx->frame_workers) {
Yaowu Xuf883b422016-08-30 14:01:10 -0700846 AVxWorker *const worker = ctx->frame_workers;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700847 FrameWorkerData *const frame_worker_data =
848 (FrameWorkerData *)worker->data1;
Yaowu Xuf883b422016-08-30 14:01:10 -0700849 const AV1_COMMON *const cm = &frame_worker_data->pbi->common;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700850 frame_size[0] = cm->width;
851 frame_size[1] = cm->height;
Yaowu Xuf883b422016-08-30 14:01:10 -0700852 return AOM_CODEC_OK;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700853 } else {
Yaowu Xuf883b422016-08-30 14:01:10 -0700854 return AOM_CODEC_ERROR;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700855 }
856 }
857
Yaowu Xuf883b422016-08-30 14:01:10 -0700858 return AOM_CODEC_INVALID_PARAM;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700859}
860
Yaowu Xuf883b422016-08-30 14:01:10 -0700861static aom_codec_err_t ctrl_get_render_size(aom_codec_alg_priv_t *ctx,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700862 va_list args) {
863 int *const render_size = va_arg(args, int *);
864
Yaowu Xuc27fc142016-08-22 16:08:15 -0700865 if (render_size) {
866 if (ctx->frame_workers) {
Yaowu Xuf883b422016-08-30 14:01:10 -0700867 AVxWorker *const worker = ctx->frame_workers;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700868 FrameWorkerData *const frame_worker_data =
869 (FrameWorkerData *)worker->data1;
Yaowu Xuf883b422016-08-30 14:01:10 -0700870 const AV1_COMMON *const cm = &frame_worker_data->pbi->common;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700871 render_size[0] = cm->render_width;
872 render_size[1] = cm->render_height;
Yaowu Xuf883b422016-08-30 14:01:10 -0700873 return AOM_CODEC_OK;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700874 } else {
Yaowu Xuf883b422016-08-30 14:01:10 -0700875 return AOM_CODEC_ERROR;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700876 }
877 }
878
Yaowu Xuf883b422016-08-30 14:01:10 -0700879 return AOM_CODEC_INVALID_PARAM;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700880}
881
Yaowu Xuf883b422016-08-30 14:01:10 -0700882static aom_codec_err_t ctrl_get_bit_depth(aom_codec_alg_priv_t *ctx,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700883 va_list args) {
884 unsigned int *const bit_depth = va_arg(args, unsigned int *);
Yaowu Xuf883b422016-08-30 14:01:10 -0700885 AVxWorker *const worker = &ctx->frame_workers[ctx->next_output_worker_id];
Yaowu Xuc27fc142016-08-22 16:08:15 -0700886
887 if (bit_depth) {
888 if (worker) {
889 FrameWorkerData *const frame_worker_data =
890 (FrameWorkerData *)worker->data1;
Yaowu Xuf883b422016-08-30 14:01:10 -0700891 const AV1_COMMON *const cm = &frame_worker_data->pbi->common;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700892 *bit_depth = cm->bit_depth;
Yaowu Xuf883b422016-08-30 14:01:10 -0700893 return AOM_CODEC_OK;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700894 } else {
Yaowu Xuf883b422016-08-30 14:01:10 -0700895 return AOM_CODEC_ERROR;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700896 }
897 }
898
Yaowu Xuf883b422016-08-30 14:01:10 -0700899 return AOM_CODEC_INVALID_PARAM;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700900}
901
Yaowu Xuf883b422016-08-30 14:01:10 -0700902static aom_codec_err_t ctrl_set_invert_tile_order(aom_codec_alg_priv_t *ctx,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700903 va_list args) {
904 ctx->invert_tile_order = va_arg(args, int);
Yaowu Xuf883b422016-08-30 14:01:10 -0700905 return AOM_CODEC_OK;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700906}
907
Yaowu Xuf883b422016-08-30 14:01:10 -0700908static aom_codec_err_t ctrl_set_byte_alignment(aom_codec_alg_priv_t *ctx,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700909 va_list args) {
910 const int legacy_byte_alignment = 0;
911 const int min_byte_alignment = 32;
912 const int max_byte_alignment = 1024;
913 const int byte_alignment = va_arg(args, int);
914
915 if (byte_alignment != legacy_byte_alignment &&
916 (byte_alignment < min_byte_alignment ||
917 byte_alignment > max_byte_alignment ||
918 (byte_alignment & (byte_alignment - 1)) != 0))
Yaowu Xuf883b422016-08-30 14:01:10 -0700919 return AOM_CODEC_INVALID_PARAM;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700920
921 ctx->byte_alignment = byte_alignment;
922 if (ctx->frame_workers) {
Yaowu Xuf883b422016-08-30 14:01:10 -0700923 AVxWorker *const worker = ctx->frame_workers;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700924 FrameWorkerData *const frame_worker_data = (FrameWorkerData *)worker->data1;
925 frame_worker_data->pbi->common.byte_alignment = byte_alignment;
926 }
Yaowu Xuf883b422016-08-30 14:01:10 -0700927 return AOM_CODEC_OK;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700928}
929
Yaowu Xuf883b422016-08-30 14:01:10 -0700930static aom_codec_err_t ctrl_set_skip_loop_filter(aom_codec_alg_priv_t *ctx,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700931 va_list args) {
932 ctx->skip_loop_filter = va_arg(args, int);
933
934 if (ctx->frame_workers) {
Yaowu Xuf883b422016-08-30 14:01:10 -0700935 AVxWorker *const worker = ctx->frame_workers;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700936 FrameWorkerData *const frame_worker_data = (FrameWorkerData *)worker->data1;
937 frame_worker_data->pbi->common.skip_loop_filter = ctx->skip_loop_filter;
938 }
939
Yaowu Xuf883b422016-08-30 14:01:10 -0700940 return AOM_CODEC_OK;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700941}
942
Nathan E. Eggec9862e02016-10-05 21:28:36 -0400943static aom_codec_err_t ctrl_get_accounting(aom_codec_alg_priv_t *ctx,
944 va_list args) {
945#if !CONFIG_ACCOUNTING
946 (void)ctx;
947 (void)args;
948 return AOM_CODEC_INCAPABLE;
949#else
950 if (ctx->frame_workers) {
951 AVxWorker *const worker = ctx->frame_workers;
952 FrameWorkerData *const frame_worker_data = (FrameWorkerData *)worker->data1;
953 AV1Decoder *pbi = frame_worker_data->pbi;
954 Accounting **acct = va_arg(args, Accounting **);
955 *acct = &pbi->accounting;
956 return AOM_CODEC_OK;
957 }
958 return AOM_CODEC_ERROR;
959#endif
960}
Yaowu Xuf883b422016-08-30 14:01:10 -0700961static aom_codec_err_t ctrl_set_decode_tile_row(aom_codec_alg_priv_t *ctx,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700962 va_list args) {
963 ctx->decode_tile_row = va_arg(args, int);
Yaowu Xuf883b422016-08-30 14:01:10 -0700964 return AOM_CODEC_OK;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700965}
966
Yaowu Xuf883b422016-08-30 14:01:10 -0700967static aom_codec_err_t ctrl_set_decode_tile_col(aom_codec_alg_priv_t *ctx,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700968 va_list args) {
969 ctx->decode_tile_col = va_arg(args, int);
Yaowu Xuf883b422016-08-30 14:01:10 -0700970 return AOM_CODEC_OK;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700971}
972
Yunqing Wang8ae64a92018-01-12 12:26:44 -0800973static aom_codec_err_t ctrl_set_tile_mode(aom_codec_alg_priv_t *ctx,
974 va_list args) {
975 ctx->tile_mode = va_arg(args, unsigned int);
976 return AOM_CODEC_OK;
977}
978
Soo-Chul Han29c46fb2018-03-23 16:02:00 -0400979static aom_codec_err_t ctrl_set_is_annexb(aom_codec_alg_priv_t *ctx,
980 va_list args) {
981 ctx->is_annexb = va_arg(args, unsigned int);
982 return AOM_CODEC_OK;
983}
984
Nathan E. Egge2cf03b12017-02-22 16:19:59 -0500985static aom_codec_err_t ctrl_set_inspection_callback(aom_codec_alg_priv_t *ctx,
986 va_list args) {
987#if !CONFIG_INSPECTION
988 (void)ctx;
989 (void)args;
990 return AOM_CODEC_INCAPABLE;
991#else
992 aom_inspect_init *init = va_arg(args, aom_inspect_init *);
993 ctx->inspect_cb = init->inspect_cb;
994 ctx->inspect_ctx = init->inspect_ctx;
995 return AOM_CODEC_OK;
996#endif
997}
998
Yaowu Xuf883b422016-08-30 14:01:10 -0700999static aom_codec_ctrl_fn_map_t decoder_ctrl_maps[] = {
Thomas Daede497d1952017-08-08 17:33:06 -07001000 { AV1_COPY_REFERENCE, ctrl_copy_reference },
Yaowu Xuc27fc142016-08-22 16:08:15 -07001001
1002 // Setters
Thomas Daede497d1952017-08-08 17:33:06 -07001003 { AV1_SET_REFERENCE, ctrl_set_reference },
Yaowu Xuf883b422016-08-30 14:01:10 -07001004 { AOM_SET_POSTPROC, ctrl_set_postproc },
1005 { AOM_SET_DBG_COLOR_REF_FRAME, ctrl_set_dbg_options },
1006 { AOM_SET_DBG_COLOR_MB_MODES, ctrl_set_dbg_options },
1007 { AOM_SET_DBG_COLOR_B_MODES, ctrl_set_dbg_options },
1008 { AOM_SET_DBG_DISPLAY_MV, ctrl_set_dbg_options },
1009 { AV1_INVERT_TILE_DECODE_ORDER, ctrl_set_invert_tile_order },
Yaowu Xuf883b422016-08-30 14:01:10 -07001010 { AV1_SET_BYTE_ALIGNMENT, ctrl_set_byte_alignment },
1011 { AV1_SET_SKIP_LOOP_FILTER, ctrl_set_skip_loop_filter },
1012 { AV1_SET_DECODE_TILE_ROW, ctrl_set_decode_tile_row },
1013 { AV1_SET_DECODE_TILE_COL, ctrl_set_decode_tile_col },
Yunqing Wang8ae64a92018-01-12 12:26:44 -08001014 { AV1_SET_TILE_MODE, ctrl_set_tile_mode },
Soo-Chul Han29c46fb2018-03-23 16:02:00 -04001015 { AV1D_SET_IS_ANNEXB, ctrl_set_is_annexb },
Nathan E. Egge2cf03b12017-02-22 16:19:59 -05001016 { AV1_SET_INSPECTION_CALLBACK, ctrl_set_inspection_callback },
Yaowu Xuc27fc142016-08-22 16:08:15 -07001017
1018 // Getters
Yaowu Xuf883b422016-08-30 14:01:10 -07001019 { AOMD_GET_FRAME_CORRUPTED, ctrl_get_frame_corrupted },
Peter Boströma1f64322017-01-19 11:35:30 -05001020 { AOMD_GET_LAST_QUANTIZER, ctrl_get_last_quantizer },
1021 { AOMD_GET_LAST_REF_UPDATES, ctrl_get_last_ref_updates },
Yaowu Xuf883b422016-08-30 14:01:10 -07001022 { AV1D_GET_BIT_DEPTH, ctrl_get_bit_depth },
Peter Boströma1f64322017-01-19 11:35:30 -05001023 { AV1D_GET_DISPLAY_SIZE, ctrl_get_render_size },
Yaowu Xuf883b422016-08-30 14:01:10 -07001024 { AV1D_GET_FRAME_SIZE, ctrl_get_frame_size },
Nathan E. Eggec9862e02016-10-05 21:28:36 -04001025 { AV1_GET_ACCOUNTING, ctrl_get_accounting },
Yaowu Xuf883b422016-08-30 14:01:10 -07001026 { AV1_GET_NEW_FRAME_IMAGE, ctrl_get_new_frame_image },
Peter Boströma1f64322017-01-19 11:35:30 -05001027 { AV1_GET_REFERENCE, ctrl_get_reference },
Yaowu Xuc27fc142016-08-22 16:08:15 -07001028
1029 { -1, NULL },
1030};
1031
1032#ifndef VERSION_STRING
1033#define VERSION_STRING
1034#endif
Yaowu Xuf883b422016-08-30 14:01:10 -07001035CODEC_INTERFACE(aom_codec_av1_dx) = {
1036 "AOMedia Project AV1 Decoder" VERSION_STRING,
1037 AOM_CODEC_INTERNAL_ABI_VERSION,
1038 AOM_CODEC_CAP_DECODER |
1039 AOM_CODEC_CAP_EXTERNAL_FRAME_BUFFER, // aom_codec_caps_t
1040 decoder_init, // aom_codec_init_fn_t
1041 decoder_destroy, // aom_codec_destroy_fn_t
1042 decoder_ctrl_maps, // aom_codec_ctrl_fn_map_t
Yaowu Xuc27fc142016-08-22 16:08:15 -07001043 {
1044 // NOLINT
Yaowu Xuf883b422016-08-30 14:01:10 -07001045 decoder_peek_si, // aom_codec_peek_si_fn_t
1046 decoder_get_si, // aom_codec_get_si_fn_t
1047 decoder_decode, // aom_codec_decode_fn_t
1048 decoder_get_frame, // aom_codec_frame_get_fn_t
1049 decoder_set_fb_fn, // aom_codec_set_fb_fn_t
Yaowu Xuc27fc142016-08-22 16:08:15 -07001050 },
1051 {
1052 // NOLINT
1053 0,
Yaowu Xuf883b422016-08-30 14:01:10 -07001054 NULL, // aom_codec_enc_cfg_map_t
1055 NULL, // aom_codec_encode_fn_t
1056 NULL, // aom_codec_get_cx_data_fn_t
1057 NULL, // aom_codec_enc_config_set_fn_t
1058 NULL, // aom_codec_get_global_headers_fn_t
1059 NULL, // aom_codec_get_preview_frame_fn_t
1060 NULL // aom_codec_enc_mr_get_mem_loc_fn_t
Yaowu Xuc27fc142016-08-22 16:08:15 -07001061 }
1062};