blob: e361eb5c1652c749825eb91d654312a4a9c3579c [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;
Frank Bossend8f457a2018-04-30 21:44:12 -040063 int operating_point;
Yaowu Xuc27fc142016-08-22 16:08:15 -070064
Yaowu Xuf883b422016-08-30 14:01:10 -070065 AVxWorker *frame_workers;
Yaowu Xuc27fc142016-08-22 16:08:15 -070066 int num_frame_workers;
67 int next_submit_worker_id;
68 int last_submit_worker_id;
69 int next_output_worker_id;
70 int available_threads;
71 cache_frame frame_cache[FRAME_CACHE_SIZE];
Andrey Norkin6f1c2f72018-01-15 20:08:52 -080072 aom_image_t *image_with_grain;
Yaowu Xuc27fc142016-08-22 16:08:15 -070073 int frame_cache_write;
74 int frame_cache_read;
75 int num_cache_frames;
76 int need_resync; // wait for key/intra-only frame
77 // BufferPool that holds all reference frames. Shared by all the FrameWorkers.
78 BufferPool *buffer_pool;
79
Yaowu Xuf883b422016-08-30 14:01:10 -070080 // External frame buffer info to save for AV1 common.
Yaowu Xuc27fc142016-08-22 16:08:15 -070081 void *ext_priv; // Private data associated with the external frame buffers.
Yaowu Xuf883b422016-08-30 14:01:10 -070082 aom_get_frame_buffer_cb_fn_t get_ext_fb_cb;
83 aom_release_frame_buffer_cb_fn_t release_ext_fb_cb;
Nathan E. Egge2cf03b12017-02-22 16:19:59 -050084
85#if CONFIG_INSPECTION
86 aom_inspect_cb inspect_cb;
87 void *inspect_ctx;
88#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -070089};
90
Yaowu Xuf883b422016-08-30 14:01:10 -070091static aom_codec_err_t decoder_init(aom_codec_ctx_t *ctx,
92 aom_codec_priv_enc_mr_cfg_t *data) {
93 // This function only allocates space for the aom_codec_alg_priv_t
Yaowu Xuc27fc142016-08-22 16:08:15 -070094 // structure. More memory may be required at the time the stream
95 // information becomes known.
96 (void)data;
97
98 if (!ctx->priv) {
Yaowu Xuf883b422016-08-30 14:01:10 -070099 aom_codec_alg_priv_t *const priv =
100 (aom_codec_alg_priv_t *)aom_calloc(1, sizeof(*priv));
101 if (priv == NULL) return AOM_CODEC_MEM_ERROR;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700102
Yaowu Xuf883b422016-08-30 14:01:10 -0700103 ctx->priv = (aom_codec_priv_t *)priv;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700104 ctx->priv->init_flags = ctx->init_flags;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700105 priv->flushed = 0;
Debargha Mukherjee5521a182018-03-06 12:29:01 -0800106
Thomas Daede85b49002017-07-10 17:43:06 -0700107 // TODO(tdaede): this should not be exposed to the API
108 priv->cfg.allow_lowbitdepth = CONFIG_LOWBITDEPTH;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700109 if (ctx->config.dec) {
110 priv->cfg = *ctx->config.dec;
111 ctx->config.dec = &priv->cfg;
Maxym Dmytrychenkocc6e0e12018-02-05 16:35:37 +0100112 // default values
Debargha Mukherjee2ccf4b92018-02-27 17:30:46 -0800113 priv->cfg.cfg.ext_partition = 1;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700114 }
Andrey Norkin6f1c2f72018-01-15 20:08:52 -0800115 priv->image_with_grain = NULL;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700116 }
117
Yaowu Xuf883b422016-08-30 14:01:10 -0700118 return AOM_CODEC_OK;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700119}
120
Yaowu Xuf883b422016-08-30 14:01:10 -0700121static aom_codec_err_t decoder_destroy(aom_codec_alg_priv_t *ctx) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700122 if (ctx->frame_workers != NULL) {
123 int i;
124 for (i = 0; i < ctx->num_frame_workers; ++i) {
Yaowu Xuf883b422016-08-30 14:01:10 -0700125 AVxWorker *const worker = &ctx->frame_workers[i];
Yaowu Xuc27fc142016-08-22 16:08:15 -0700126 FrameWorkerData *const frame_worker_data =
127 (FrameWorkerData *)worker->data1;
Yaowu Xuf883b422016-08-30 14:01:10 -0700128 aom_get_worker_interface()->end(worker);
Yaowu Xu568bf102017-10-17 12:43:27 -0700129 aom_free(frame_worker_data->pbi->common.tpl_mvs);
130 frame_worker_data->pbi->common.tpl_mvs = NULL;
Yaowu Xuf883b422016-08-30 14:01:10 -0700131 av1_remove_common(&frame_worker_data->pbi->common);
Yaowu Xuf883b422016-08-30 14:01:10 -0700132 av1_free_restoration_buffers(&frame_worker_data->pbi->common);
Yaowu Xuf883b422016-08-30 14:01:10 -0700133 av1_decoder_remove(frame_worker_data->pbi);
134 aom_free(frame_worker_data->scratch_buffer);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700135#if CONFIG_MULTITHREAD
136 pthread_mutex_destroy(&frame_worker_data->stats_mutex);
137 pthread_cond_destroy(&frame_worker_data->stats_cond);
138#endif
Yaowu Xuf883b422016-08-30 14:01:10 -0700139 aom_free(frame_worker_data);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700140 }
141#if CONFIG_MULTITHREAD
142 pthread_mutex_destroy(&ctx->buffer_pool->pool_mutex);
143#endif
144 }
145
146 if (ctx->buffer_pool) {
Yaowu Xuf883b422016-08-30 14:01:10 -0700147 av1_free_ref_frame_buffers(ctx->buffer_pool);
148 av1_free_internal_frame_buffers(&ctx->buffer_pool->int_frame_buffers);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700149 }
150
Yaowu Xuf883b422016-08-30 14:01:10 -0700151 aom_free(ctx->frame_workers);
152 aom_free(ctx->buffer_pool);
Andrey Norkin6f1c2f72018-01-15 20:08:52 -0800153 if (ctx->image_with_grain) aom_img_free(ctx->image_with_grain);
Yaowu Xuf883b422016-08-30 14:01:10 -0700154 aom_free(ctx);
155 return AOM_CODEC_OK;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700156}
157
Tom Finegan7ecf8152018-04-26 11:48:47 -0700158static void parse_operating_points(struct aom_read_bit_buffer *rb,
159 int is_reduced_header,
Soo-Chul Han4ea3c5e2018-04-06 10:18:32 -0400160 aom_codec_stream_info_t *si) {
Tom Finegan7ecf8152018-04-26 11:48:47 -0700161 if (is_reduced_header) {
Debargha Mukherjeeacd41f92018-04-11 07:58:34 -0700162 aom_rb_read_literal(rb, LEVEL_BITS); // level
163 } else {
Wan-Teh Chang69582972018-05-15 13:18:52 -0700164 const uint8_t operating_points_cnt_minus_1 =
165 aom_rb_read_literal(rb, OP_POINTS_CNT_MINUS_1_BITS);
Soo-Chul Hand2f317c2018-05-08 14:21:24 -0400166 int operating_point_idc0 = 0;
Wan-Teh Chang69582972018-05-15 13:18:52 -0700167 for (int i = 0; i < operating_points_cnt_minus_1 + 1; i++) {
Soo-Chul Hand2f317c2018-05-08 14:21:24 -0400168 int operating_point_idc;
169 operating_point_idc = aom_rb_read_literal(rb, OP_POINTS_IDC_BITS);
170 if (i == 0) operating_point_idc0 = operating_point_idc;
171 aom_rb_read_literal(rb, LEVEL_BITS); // level
Debargha Mukherjeeacd41f92018-04-11 07:58:34 -0700172#if !CONFIG_BUFFER_MODEL
173 if (aom_rb_read_literal(rb,
174 1)) { // decoder_rate_model_param_present_flag
175 aom_rb_read_literal(rb, 12); // decode_to_display_rate_ratio
176 aom_rb_read_literal(rb, 24); // initial_display_delay
177 aom_rb_read_literal(rb, 4); // extra_frame_buffers
178 }
179#endif // !CONFIG_BUFFER_MODEL
Debargha Mukherjee112c5822018-04-09 09:42:29 -0700180 }
Soo-Chul Hand2f317c2018-05-08 14:21:24 -0400181
182 // derive number of spatial/temporal layers from operating_point_idc0
183 if (operating_point_idc0 == 0) {
184 si->number_temporal_layers = 1;
185 si->number_spatial_layers = 1;
186 } else {
187 si->number_spatial_layers = 0;
188 si->number_temporal_layers = 0;
189 for (int j = 0; j < 8; j++) {
190 si->number_spatial_layers += (operating_point_idc0 >> (j + 8)) & 0x1;
191 si->number_temporal_layers += (operating_point_idc0 >> j) & 0x1;
192 }
193 }
Debargha Mukherjee112c5822018-04-09 09:42:29 -0700194 }
195}
196
Sebastien Alaiwan2b1ec182017-12-21 09:38:27 +0100197static aom_codec_err_t decoder_peek_si_internal(const uint8_t *data,
Tom Finegan21f48252018-05-15 11:31:04 -0700198 size_t data_sz,
Sebastien Alaiwan2b1ec182017-12-21 09:38:27 +0100199 aom_codec_stream_info_t *si,
200 int *is_intra_only) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700201 int intra_only_flag = 0;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700202
Hui Sudf5b2912018-03-16 15:34:01 -0700203 if (data + data_sz <= data || data_sz < 1) return AOM_CODEC_INVALID_PARAM;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700204
Tom Fineganf277ca32018-02-26 12:09:52 -0800205 si->w = 0;
Tom Finegan13ee28c2018-02-26 19:37:41 -0800206 si->h = 0;
207 si->is_kf = 0;
208
209 // TODO(tomfinegan): This function needs Sequence and Frame Header OBUs to
210 // operate properly. At present it hard codes the values to 1 for the keyframe
211 // and intra only flags, and assumes the data being parsed is a Sequence
212 // Header OBU.
David Barker5c0e80e2018-04-17 12:54:29 +0100213 // NOTE(david.barker): In addition, this code currently requires the video
214 // stream to begin with an optional OBU_TEMPORAL_DELIMITER followed by an
215 // OBU_SEQUENCE_HEADER.
Tom Fineganf277ca32018-02-26 12:09:52 -0800216 intra_only_flag = 1;
Tom Finegan13ee28c2018-02-26 19:37:41 -0800217 si->is_kf = 1;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700218
David Barker5c0e80e2018-04-17 12:54:29 +0100219 ObuHeader obu_header;
220 memset(&obu_header, 0, sizeof(obu_header));
221 size_t payload_size = 0;
222 size_t bytes_read = 0;
223 aom_codec_err_t status = aom_read_obu_header_and_size(
224 data, data_sz, si->is_annexb, &obu_header, &payload_size, &bytes_read);
225 if (status != AOM_CODEC_OK) return status;
Soo-Chul Han29c46fb2018-03-23 16:02:00 -0400226
David Barker5c0e80e2018-04-17 12:54:29 +0100227 // If the first OBU is a temporal delimiter, skip over it and look at the next
228 // OBU in the bitstream
229 if (obu_header.type == OBU_TEMPORAL_DELIMITER) {
230 // Skip any associated payload (there shouldn't be one, but just in case)
Wan-Teh Changbe668042018-04-24 11:58:21 -0700231 if (data_sz < bytes_read + payload_size) return AOM_CODEC_CORRUPT_FRAME;
David Barker5c0e80e2018-04-17 12:54:29 +0100232 data += bytes_read + payload_size;
Wan-Teh Chang84b22b82018-05-16 14:56:28 -0700233 data_sz -= bytes_read + payload_size;
Tom Finegan13ee28c2018-02-26 19:37:41 -0800234
David Barker5c0e80e2018-04-17 12:54:29 +0100235 status = aom_read_obu_header_and_size(
236 data, data_sz, si->is_annexb, &obu_header, &payload_size, &bytes_read);
237 if (status != AOM_CODEC_OK) return status;
Soo-Chul Han29c46fb2018-03-23 16:02:00 -0400238 }
Vignesh Venkatasubramanian03391a22018-03-09 12:25:55 -0800239
David Barker5c0e80e2018-04-17 12:54:29 +0100240 // Check that the selected OBU is a sequence header
241 if (obu_header.type != OBU_SEQUENCE_HEADER) return AOM_CODEC_UNSUP_BITSTREAM;
242
243 // Read a few values from the sequence header payload
244 data += bytes_read;
Wan-Teh Chang84b22b82018-05-16 14:56:28 -0700245 data_sz -= bytes_read;
David Barker5c0e80e2018-04-17 12:54:29 +0100246 struct aom_read_bit_buffer rb = { data, data + data_sz, 0, NULL, NULL };
Tom Finegan13ee28c2018-02-26 19:37:41 -0800247
Debargha Mukherjee112c5822018-04-09 09:42:29 -0700248 av1_read_profile(&rb); // profile
249 const int still_picture = aom_rb_read_bit(&rb);
250 const int reduced_still_picture_hdr = aom_rb_read_bit(&rb);
251
252 if (!still_picture && reduced_still_picture_hdr) {
253 return AOM_CODEC_UNSUP_BITSTREAM;
254 }
255
Soo-Chul Han4ea3c5e2018-04-06 10:18:32 -0400256 parse_operating_points(&rb, reduced_still_picture_hdr, si);
Soo-Chul Hanf8589862018-01-24 03:13:14 +0000257
Tom Fineganf277ca32018-02-26 12:09:52 -0800258 int num_bits_width = aom_rb_read_literal(&rb, 4) + 1;
259 int num_bits_height = aom_rb_read_literal(&rb, 4) + 1;
260 int max_frame_width = aom_rb_read_literal(&rb, num_bits_width) + 1;
261 int max_frame_height = aom_rb_read_literal(&rb, num_bits_height) + 1;
262 si->w = max_frame_width;
263 si->h = max_frame_height;
Tom Fineganf277ca32018-02-26 12:09:52 -0800264
Yaowu Xuc27fc142016-08-22 16:08:15 -0700265 if (is_intra_only != NULL) *is_intra_only = intra_only_flag;
Yaowu Xuf883b422016-08-30 14:01:10 -0700266 return AOM_CODEC_OK;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700267}
268
Tom Finegan21f48252018-05-15 11:31:04 -0700269static aom_codec_err_t decoder_peek_si(const uint8_t *data, size_t data_sz,
Yaowu Xuf883b422016-08-30 14:01:10 -0700270 aom_codec_stream_info_t *si) {
Sebastien Alaiwan2b1ec182017-12-21 09:38:27 +0100271 return decoder_peek_si_internal(data, data_sz, si, NULL);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700272}
273
Yaowu Xuf883b422016-08-30 14:01:10 -0700274static aom_codec_err_t decoder_get_si(aom_codec_alg_priv_t *ctx,
275 aom_codec_stream_info_t *si) {
Ralph Gilesafe71d92017-05-03 13:18:57 -0700276 memcpy(si, &ctx->si, sizeof(*si));
Yaowu Xuc27fc142016-08-22 16:08:15 -0700277
Yaowu Xuf883b422016-08-30 14:01:10 -0700278 return AOM_CODEC_OK;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700279}
280
Yaowu Xuf883b422016-08-30 14:01:10 -0700281static void set_error_detail(aom_codec_alg_priv_t *ctx,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700282 const char *const error) {
283 ctx->base.err_detail = error;
284}
285
Yaowu Xuf883b422016-08-30 14:01:10 -0700286static aom_codec_err_t update_error_state(
287 aom_codec_alg_priv_t *ctx, const struct aom_internal_error_info *error) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700288 if (error->error_code)
289 set_error_detail(ctx, error->has_detail ? error->detail : NULL);
290
291 return error->error_code;
292}
293
Yaowu Xuf883b422016-08-30 14:01:10 -0700294static void init_buffer_callbacks(aom_codec_alg_priv_t *ctx) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700295 int i;
296
297 for (i = 0; i < ctx->num_frame_workers; ++i) {
Yaowu Xuf883b422016-08-30 14:01:10 -0700298 AVxWorker *const worker = &ctx->frame_workers[i];
Yaowu Xuc27fc142016-08-22 16:08:15 -0700299 FrameWorkerData *const frame_worker_data = (FrameWorkerData *)worker->data1;
Yaowu Xuf883b422016-08-30 14:01:10 -0700300 AV1_COMMON *const cm = &frame_worker_data->pbi->common;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700301 BufferPool *const pool = cm->buffer_pool;
302
303 cm->new_fb_idx = INVALID_IDX;
304 cm->byte_alignment = ctx->byte_alignment;
305 cm->skip_loop_filter = ctx->skip_loop_filter;
306
307 if (ctx->get_ext_fb_cb != NULL && ctx->release_ext_fb_cb != NULL) {
308 pool->get_fb_cb = ctx->get_ext_fb_cb;
309 pool->release_fb_cb = ctx->release_ext_fb_cb;
310 pool->cb_priv = ctx->ext_priv;
311 } else {
Yaowu Xuf883b422016-08-30 14:01:10 -0700312 pool->get_fb_cb = av1_get_frame_buffer;
313 pool->release_fb_cb = av1_release_frame_buffer;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700314
Yaowu Xuf883b422016-08-30 14:01:10 -0700315 if (av1_alloc_internal_frame_buffers(&pool->int_frame_buffers))
316 aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700317 "Failed to initialize internal frame buffers");
318
319 pool->cb_priv = &pool->int_frame_buffers;
320 }
321 }
322}
323
Yaowu Xuf883b422016-08-30 14:01:10 -0700324static void set_default_ppflags(aom_postproc_cfg_t *cfg) {
325 cfg->post_proc_flag = AOM_DEBLOCK | AOM_DEMACROBLOCK;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700326 cfg->deblocking_level = 4;
327 cfg->noise_level = 0;
328}
329
330static int frame_worker_hook(void *arg1, void *arg2) {
331 FrameWorkerData *const frame_worker_data = (FrameWorkerData *)arg1;
332 const uint8_t *data = frame_worker_data->data;
333 (void)arg2;
334
Yaowu Xuf883b422016-08-30 14:01:10 -0700335 frame_worker_data->result = av1_receive_compressed_data(
Yaowu Xuc27fc142016-08-22 16:08:15 -0700336 frame_worker_data->pbi, frame_worker_data->data_size, &data);
337 frame_worker_data->data_end = data;
338
Debargha Mukherjee5521a182018-03-06 12:29:01 -0800339 if (frame_worker_data->result != 0) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700340 // Check decode result in serial decode.
341 frame_worker_data->pbi->cur_buf->buf.corrupted = 1;
342 frame_worker_data->pbi->need_resync = 1;
343 }
344 return !frame_worker_data->result;
345}
346
Yaowu Xuf883b422016-08-30 14:01:10 -0700347static aom_codec_err_t init_decoder(aom_codec_alg_priv_t *ctx) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700348 int i;
Yaowu Xuf883b422016-08-30 14:01:10 -0700349 const AVxWorkerInterface *const winterface = aom_get_worker_interface();
Yaowu Xuc27fc142016-08-22 16:08:15 -0700350
351 ctx->last_show_frame = -1;
352 ctx->next_submit_worker_id = 0;
353 ctx->last_submit_worker_id = 0;
354 ctx->next_output_worker_id = 0;
355 ctx->frame_cache_read = 0;
356 ctx->frame_cache_write = 0;
357 ctx->num_cache_frames = 0;
358 ctx->need_resync = 1;
Debargha Mukherjee5521a182018-03-06 12:29:01 -0800359 ctx->num_frame_workers = 1;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700360 if (ctx->num_frame_workers > MAX_DECODE_THREADS)
361 ctx->num_frame_workers = MAX_DECODE_THREADS;
362 ctx->available_threads = ctx->num_frame_workers;
363 ctx->flushed = 0;
364
Yaowu Xuf883b422016-08-30 14:01:10 -0700365 ctx->buffer_pool = (BufferPool *)aom_calloc(1, sizeof(BufferPool));
366 if (ctx->buffer_pool == NULL) return AOM_CODEC_MEM_ERROR;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700367
368#if CONFIG_MULTITHREAD
369 if (pthread_mutex_init(&ctx->buffer_pool->pool_mutex, NULL)) {
370 set_error_detail(ctx, "Failed to allocate buffer pool mutex");
Yaowu Xuf883b422016-08-30 14:01:10 -0700371 return AOM_CODEC_MEM_ERROR;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700372 }
373#endif
374
Yaowu Xuf883b422016-08-30 14:01:10 -0700375 ctx->frame_workers = (AVxWorker *)aom_malloc(ctx->num_frame_workers *
Yaowu Xuc27fc142016-08-22 16:08:15 -0700376 sizeof(*ctx->frame_workers));
377 if (ctx->frame_workers == NULL) {
378 set_error_detail(ctx, "Failed to allocate frame_workers");
Yaowu Xuf883b422016-08-30 14:01:10 -0700379 return AOM_CODEC_MEM_ERROR;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700380 }
381
382 for (i = 0; i < ctx->num_frame_workers; ++i) {
Yaowu Xuf883b422016-08-30 14:01:10 -0700383 AVxWorker *const worker = &ctx->frame_workers[i];
Yaowu Xuc27fc142016-08-22 16:08:15 -0700384 FrameWorkerData *frame_worker_data = NULL;
385 winterface->init(worker);
Yaowu Xuf883b422016-08-30 14:01:10 -0700386 worker->data1 = aom_memalign(32, sizeof(FrameWorkerData));
Yaowu Xuc27fc142016-08-22 16:08:15 -0700387 if (worker->data1 == NULL) {
388 set_error_detail(ctx, "Failed to allocate frame_worker_data");
Yaowu Xuf883b422016-08-30 14:01:10 -0700389 return AOM_CODEC_MEM_ERROR;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700390 }
391 frame_worker_data = (FrameWorkerData *)worker->data1;
Yaowu Xuf883b422016-08-30 14:01:10 -0700392 frame_worker_data->pbi = av1_decoder_create(ctx->buffer_pool);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700393 if (frame_worker_data->pbi == NULL) {
394 set_error_detail(ctx, "Failed to allocate frame_worker_data");
Yaowu Xuf883b422016-08-30 14:01:10 -0700395 return AOM_CODEC_MEM_ERROR;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700396 }
Maxym Dmytrychenkocc6e0e12018-02-05 16:35:37 +0100397 frame_worker_data->pbi->common.options = &ctx->cfg.cfg;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700398 frame_worker_data->pbi->frame_worker_owner = worker;
399 frame_worker_data->worker_id = i;
400 frame_worker_data->scratch_buffer = NULL;
401 frame_worker_data->scratch_buffer_size = 0;
402 frame_worker_data->frame_context_ready = 0;
403 frame_worker_data->received_frame = 0;
404#if CONFIG_MULTITHREAD
405 if (pthread_mutex_init(&frame_worker_data->stats_mutex, NULL)) {
406 set_error_detail(ctx, "Failed to allocate frame_worker_data mutex");
Yaowu Xuf883b422016-08-30 14:01:10 -0700407 return AOM_CODEC_MEM_ERROR;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700408 }
409
410 if (pthread_cond_init(&frame_worker_data->stats_cond, NULL)) {
411 set_error_detail(ctx, "Failed to allocate frame_worker_data cond");
Yaowu Xuf883b422016-08-30 14:01:10 -0700412 return AOM_CODEC_MEM_ERROR;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700413 }
414#endif
Sebastien Alaiwan8b7a4e12017-06-13 11:25:57 +0200415 frame_worker_data->pbi->allow_lowbitdepth = ctx->cfg.allow_lowbitdepth;
416
Yaowu Xuc27fc142016-08-22 16:08:15 -0700417 // If decoding in serial mode, FrameWorker thread could create tile worker
418 // thread or loopfilter thread.
Debargha Mukherjee5521a182018-03-06 12:29:01 -0800419 frame_worker_data->pbi->max_threads = ctx->cfg.threads;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700420 frame_worker_data->pbi->inv_tile_order = ctx->invert_tile_order;
Yunqing Wang8ae64a92018-01-12 12:26:44 -0800421 frame_worker_data->pbi->common.large_scale_tile = ctx->tile_mode;
Soo-Chul Han29c46fb2018-03-23 16:02:00 -0400422 frame_worker_data->pbi->common.is_annexb = ctx->is_annexb;
Yunqing Wang8ae64a92018-01-12 12:26:44 -0800423 frame_worker_data->pbi->dec_tile_row = ctx->decode_tile_row;
424 frame_worker_data->pbi->dec_tile_col = ctx->decode_tile_col;
Frank Bossend8f457a2018-04-30 21:44:12 -0400425 frame_worker_data->pbi->operating_point = ctx->operating_point;
Yaowu Xuf883b422016-08-30 14:01:10 -0700426 worker->hook = (AVxWorkerHook)frame_worker_hook;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700427 if (!winterface->reset(worker)) {
428 set_error_detail(ctx, "Frame Worker thread creation failed");
Yaowu Xuf883b422016-08-30 14:01:10 -0700429 return AOM_CODEC_MEM_ERROR;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700430 }
431 }
432
433 // If postprocessing was enabled by the application and a
434 // configuration has not been provided, default it.
Yaowu Xuf883b422016-08-30 14:01:10 -0700435 if (!ctx->postproc_cfg_set && (ctx->base.init_flags & AOM_CODEC_USE_POSTPROC))
Yaowu Xuc27fc142016-08-22 16:08:15 -0700436 set_default_ppflags(&ctx->postproc_cfg);
437
438 init_buffer_callbacks(ctx);
439
Yaowu Xuf883b422016-08-30 14:01:10 -0700440 return AOM_CODEC_OK;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700441}
442
Yaowu Xuf883b422016-08-30 14:01:10 -0700443static INLINE void check_resync(aom_codec_alg_priv_t *const ctx,
444 const AV1Decoder *const pbi) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700445 // Clear resync flag if worker got a key frame or intra only frame.
446 if (ctx->need_resync == 1 && pbi->need_resync == 0 &&
447 (pbi->common.intra_only || pbi->common.frame_type == KEY_FRAME))
448 ctx->need_resync = 0;
449}
450
Yaowu Xuf883b422016-08-30 14:01:10 -0700451static aom_codec_err_t decode_one(aom_codec_alg_priv_t *ctx,
Tom Finegan21f48252018-05-15 11:31:04 -0700452 const uint8_t **data, size_t data_sz,
Sean DuBois47cc2552018-01-23 07:44:16 +0000453 void *user_priv) {
Yaowu Xuf883b422016-08-30 14:01:10 -0700454 const AVxWorkerInterface *const winterface = aom_get_worker_interface();
Yaowu Xuc27fc142016-08-22 16:08:15 -0700455
456 // Determine the stream parameters. Note that we rely on peek_si to
457 // validate that we have a buffer that does not wrap around the top
458 // of the heap.
459 if (!ctx->si.h) {
460 int is_intra_only = 0;
Soo-Chul Han29c46fb2018-03-23 16:02:00 -0400461 ctx->si.is_annexb = ctx->is_annexb;
Tom Finegan21f48252018-05-15 11:31:04 -0700462 const aom_codec_err_t res =
463 decoder_peek_si_internal(*data, data_sz, &ctx->si, &is_intra_only);
Yaowu Xuf883b422016-08-30 14:01:10 -0700464 if (res != AOM_CODEC_OK) return res;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700465
Yaowu Xuf883b422016-08-30 14:01:10 -0700466 if (!ctx->si.is_kf && !is_intra_only) return AOM_CODEC_ERROR;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700467 }
468
Debargha Mukherjee5521a182018-03-06 12:29:01 -0800469 AVxWorker *const worker = ctx->frame_workers;
470 FrameWorkerData *const frame_worker_data = (FrameWorkerData *)worker->data1;
471 frame_worker_data->data = *data;
472 frame_worker_data->data_size = data_sz;
473 frame_worker_data->user_priv = user_priv;
474 frame_worker_data->received_frame = 1;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700475
Nathan E. Egge2cf03b12017-02-22 16:19:59 -0500476#if CONFIG_INSPECTION
Debargha Mukherjee5521a182018-03-06 12:29:01 -0800477 frame_worker_data->pbi->inspect_cb = ctx->inspect_cb;
478 frame_worker_data->pbi->inspect_ctx = ctx->inspect_ctx;
Nathan E. Egge2cf03b12017-02-22 16:19:59 -0500479#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -0700480
Debargha Mukherjee5521a182018-03-06 12:29:01 -0800481 frame_worker_data->pbi->common.large_scale_tile = ctx->tile_mode;
482 frame_worker_data->pbi->dec_tile_row = ctx->decode_tile_row;
483 frame_worker_data->pbi->dec_tile_col = ctx->decode_tile_col;
Yunqing Wang2a5575e2018-02-23 16:02:18 -0800484
Soo-Chul Han29c46fb2018-03-23 16:02:00 -0400485 frame_worker_data->pbi->common.is_annexb = ctx->is_annexb;
486
Debargha Mukherjee5521a182018-03-06 12:29:01 -0800487 worker->had_error = 0;
488 winterface->execute(worker);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700489
Debargha Mukherjee5521a182018-03-06 12:29:01 -0800490 // Update data pointer after decode.
491 *data = frame_worker_data->data_end;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700492
Debargha Mukherjee5521a182018-03-06 12:29:01 -0800493 if (worker->had_error)
494 return update_error_state(ctx, &frame_worker_data->pbi->common.error);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700495
Debargha Mukherjee5521a182018-03-06 12:29:01 -0800496 check_resync(ctx, frame_worker_data->pbi);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700497
Yaowu Xuf883b422016-08-30 14:01:10 -0700498 return AOM_CODEC_OK;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700499}
500
Yaowu Xuf883b422016-08-30 14:01:10 -0700501static aom_codec_err_t decoder_decode(aom_codec_alg_priv_t *ctx,
Tom Finegan21f48252018-05-15 11:31:04 -0700502 const uint8_t *data, size_t data_sz,
Sean DuBois47cc2552018-01-23 07:44:16 +0000503 void *user_priv) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700504 const uint8_t *data_start = data;
Wan-Teh Chang6e870902018-05-16 09:55:52 -0700505 const uint8_t *data_end = data + data_sz;
Yaowu Xub02d0b12017-12-15 01:32:34 +0000506 aom_codec_err_t res = AOM_CODEC_OK;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700507
508 if (data == NULL && data_sz == 0) {
509 ctx->flushed = 1;
Yaowu Xuf883b422016-08-30 14:01:10 -0700510 return AOM_CODEC_OK;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700511 }
512
513 // Reset flushed when receiving a valid frame.
514 ctx->flushed = 0;
515
516 // Initialize the decoder workers on the first frame.
517 if (ctx->frame_workers == NULL) {
Urvang Joshi454280d2016-10-14 16:51:44 -0700518 res = init_decoder(ctx);
Yaowu Xuf883b422016-08-30 14:01:10 -0700519 if (res != AOM_CODEC_OK) return res;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700520 }
Soo-Chul Han29c46fb2018-03-23 16:02:00 -0400521
Soo-Chul Han8acdbfc2018-04-02 12:55:33 -0400522 if (ctx->is_annexb) {
523 // read the size of this temporal unit
524 size_t length_of_size;
Wan-Teh Chang6e870902018-05-16 09:55:52 -0700525 uint64_t temporal_unit_size;
526 if (aom_uleb_decode(data_start, data_sz, &temporal_unit_size,
527 &length_of_size) != 0) {
Soo-Chul Han8acdbfc2018-04-02 12:55:33 -0400528 return AOM_CODEC_CORRUPT_FRAME;
529 }
530 data_start += length_of_size;
Wan-Teh Chang6e870902018-05-16 09:55:52 -0700531 if (temporal_unit_size > (size_t)(data_end - data_start))
532 return AOM_CODEC_CORRUPT_FRAME;
533 data_end = data_start + temporal_unit_size;
Soo-Chul Han8acdbfc2018-04-02 12:55:33 -0400534 }
535
Debargha Mukherjee5521a182018-03-06 12:29:01 -0800536 // Decode in serial mode.
David Barker0bae60c2018-05-10 14:37:45 +0100537 while (data_start < data_end) {
538 uint64_t frame_size;
539 if (ctx->is_annexb) {
540 // read the size of this frame unit
541 size_t length_of_size;
542 if (aom_uleb_decode(data_start, (size_t)(data_end - data_start),
543 &frame_size, &length_of_size) != 0) {
Debargha Mukherjee5521a182018-03-06 12:29:01 -0800544 return AOM_CODEC_CORRUPT_FRAME;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700545 }
David Barker0bae60c2018-05-10 14:37:45 +0100546 data_start += length_of_size;
Wan-Teh Chang6e870902018-05-16 09:55:52 -0700547 if (frame_size > (size_t)(data_end - data_start))
548 return AOM_CODEC_CORRUPT_FRAME;
David Barker0bae60c2018-05-10 14:37:45 +0100549 } else {
550 frame_size = (uint64_t)(data_end - data_start);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700551 }
David Barker0bae60c2018-05-10 14:37:45 +0100552
Tom Finegan21f48252018-05-15 11:31:04 -0700553 res = decode_one(ctx, &data_start, (size_t)frame_size, user_priv);
David Barker0bae60c2018-05-10 14:37:45 +0100554 if (res != AOM_CODEC_OK) return res;
555
556 // Allow extra zero bytes after the frame end
Debargha Mukherjee5521a182018-03-06 12:29:01 -0800557 while (data_start < data_end) {
David Barker0bae60c2018-05-10 14:37:45 +0100558 const uint8_t marker = data_start[0];
559 if (marker) break;
560 ++data_start;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700561 }
562 }
563
564 return res;
565}
566
Andrey Norkin6f1c2f72018-01-15 20:08:52 -0800567aom_image_t *add_grain_if_needed(aom_image_t *img, aom_image_t *grain_img_buf,
568 aom_film_grain_t *grain_params) {
569 if (!grain_params->apply_grain) return img;
570
571 if (grain_img_buf &&
572 (img->d_w != grain_img_buf->d_w || img->d_h != grain_img_buf->d_h ||
Andrey Norkin4352fed2018-03-01 17:01:49 -0800573 img->fmt != grain_img_buf->fmt || !(img->d_h % 2) || !(img->d_w % 2))) {
Andrey Norkin6f1c2f72018-01-15 20:08:52 -0800574 aom_img_free(grain_img_buf);
575 grain_img_buf = NULL;
576 }
577 if (!grain_img_buf) {
Andrey Norkin4352fed2018-03-01 17:01:49 -0800578 int w_even = img->d_w % 2 ? img->d_w + 1 : img->d_w;
579 int h_even = img->d_h % 2 ? img->d_h + 1 : img->d_h;
580 grain_img_buf = aom_img_alloc(NULL, img->fmt, w_even, h_even, 16);
Andrey Norkin6f1c2f72018-01-15 20:08:52 -0800581 grain_img_buf->bit_depth = img->bit_depth;
582 }
583
584 av1_add_film_grain(grain_params, img, grain_img_buf);
585
586 return grain_img_buf;
587}
Andrey Norkin6f1c2f72018-01-15 20:08:52 -0800588
Yaowu Xuf883b422016-08-30 14:01:10 -0700589static aom_image_t *decoder_get_frame(aom_codec_alg_priv_t *ctx,
590 aom_codec_iter_t *iter) {
591 aom_image_t *img = NULL;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700592
Yaowu Xuc27fc142016-08-22 16:08:15 -0700593 // Output the frames in the cache first.
594 if (ctx->num_cache_frames > 0) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700595 ctx->last_show_frame = ctx->frame_cache[ctx->frame_cache_read].fb_idx;
596 if (ctx->need_resync) return NULL;
597 img = &ctx->frame_cache[ctx->frame_cache_read].img;
598 ctx->frame_cache_read = (ctx->frame_cache_read + 1) % FRAME_CACHE_SIZE;
599 --ctx->num_cache_frames;
Andrey Norkin6f1c2f72018-01-15 20:08:52 -0800600 return add_grain_if_needed(
601 img, ctx->image_with_grain,
602 &ctx->frame_cache[ctx->frame_cache_read].film_grain_params);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700603 }
604
605 // iter acts as a flip flop, so an image is only returned on the first
606 // call to get_frame.
607 if (*iter == NULL && ctx->frame_workers != NULL) {
608 do {
609 YV12_BUFFER_CONFIG sd;
Yaowu Xuf883b422016-08-30 14:01:10 -0700610 const AVxWorkerInterface *const winterface = aom_get_worker_interface();
611 AVxWorker *const worker = &ctx->frame_workers[ctx->next_output_worker_id];
Yaowu Xuc27fc142016-08-22 16:08:15 -0700612 FrameWorkerData *const frame_worker_data =
613 (FrameWorkerData *)worker->data1;
614 ctx->next_output_worker_id =
615 (ctx->next_output_worker_id + 1) % ctx->num_frame_workers;
616 // Wait for the frame from worker thread.
617 if (winterface->sync(worker)) {
618 // Check if worker has received any frames.
619 if (frame_worker_data->received_frame == 1) {
620 ++ctx->available_threads;
621 frame_worker_data->received_frame = 0;
622 check_resync(ctx, frame_worker_data->pbi);
623 }
Yaowu Xuf883b422016-08-30 14:01:10 -0700624 if (av1_get_raw_frame(frame_worker_data->pbi, &sd) == 0) {
625 AV1_COMMON *const cm = &frame_worker_data->pbi->common;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700626 RefCntBuffer *const frame_bufs = cm->buffer_pool->frame_bufs;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700627 ctx->last_show_frame = frame_worker_data->pbi->common.new_fb_idx;
628 if (ctx->need_resync) return NULL;
629 yuvconfig2image(&ctx->img, &sd, frame_worker_data->user_priv);
630
Imdad Sardharwallaaf8e2642018-01-19 11:46:34 +0000631 const int num_planes = av1_num_planes(cm);
Yunqing Wangeeb08a92017-07-07 21:25:18 -0700632 if (cm->single_tile_decoding &&
Yunqing Wangd8cd55f2017-02-27 12:16:00 -0800633 frame_worker_data->pbi->dec_tile_row >= 0) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700634 const int tile_row =
Yaowu Xuf883b422016-08-30 14:01:10 -0700635 AOMMIN(frame_worker_data->pbi->dec_tile_row, cm->tile_rows - 1);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700636 const int mi_row = tile_row * cm->tile_height;
637 const int ssy = ctx->img.y_chroma_shift;
638 int plane;
639 ctx->img.planes[0] += mi_row * MI_SIZE * ctx->img.stride[0];
Imdad Sardharwallaaf8e2642018-01-19 11:46:34 +0000640 if (num_planes > 1) {
641 for (plane = 1; plane < MAX_MB_PLANE; ++plane) {
642 ctx->img.planes[plane] +=
643 mi_row * (MI_SIZE >> ssy) * ctx->img.stride[plane];
644 }
Yaowu Xuc27fc142016-08-22 16:08:15 -0700645 }
646 ctx->img.d_h =
Yaowu Xuf883b422016-08-30 14:01:10 -0700647 AOMMIN(cm->tile_height, cm->mi_rows - mi_row) * MI_SIZE;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700648 }
649
Yunqing Wangeeb08a92017-07-07 21:25:18 -0700650 if (cm->single_tile_decoding &&
Yunqing Wangd8cd55f2017-02-27 12:16:00 -0800651 frame_worker_data->pbi->dec_tile_col >= 0) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700652 const int tile_col =
Yaowu Xuf883b422016-08-30 14:01:10 -0700653 AOMMIN(frame_worker_data->pbi->dec_tile_col, cm->tile_cols - 1);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700654 const int mi_col = tile_col * cm->tile_width;
655 const int ssx = ctx->img.x_chroma_shift;
656 int plane;
657 ctx->img.planes[0] += mi_col * MI_SIZE;
Imdad Sardharwallaaf8e2642018-01-19 11:46:34 +0000658 if (num_planes > 1) {
659 for (plane = 1; plane < MAX_MB_PLANE; ++plane) {
660 ctx->img.planes[plane] += mi_col * (MI_SIZE >> ssx);
661 }
Yaowu Xuc27fc142016-08-22 16:08:15 -0700662 }
663 ctx->img.d_w =
Yaowu Xuf883b422016-08-30 14:01:10 -0700664 AOMMIN(cm->tile_width, cm->mi_cols - mi_col) * MI_SIZE;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700665 }
Yaowu Xuc27fc142016-08-22 16:08:15 -0700666
667 ctx->img.fb_priv = frame_bufs[cm->new_fb_idx].raw_frame_buffer.priv;
668 img = &ctx->img;
Soo-Chul Hanf8589862018-01-24 03:13:14 +0000669 img->temporal_id = cm->temporal_layer_id;
Soo-Chul Hand2f317c2018-05-08 14:21:24 -0400670 img->spatial_id = cm->spatial_layer_id;
Andrey Norkin6f1c2f72018-01-15 20:08:52 -0800671 return add_grain_if_needed(
672 img, ctx->image_with_grain,
673 &frame_worker_data->pbi->common.film_grain_params);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700674 }
675 } else {
676 // Decoding failed. Release the worker thread.
677 frame_worker_data->received_frame = 0;
678 ++ctx->available_threads;
679 ctx->need_resync = 1;
680 if (ctx->flushed != 1) return NULL;
681 }
682 } while (ctx->next_output_worker_id != ctx->next_submit_worker_id);
683 }
684 return NULL;
685}
686
Yaowu Xuf883b422016-08-30 14:01:10 -0700687static aom_codec_err_t decoder_set_fb_fn(
688 aom_codec_alg_priv_t *ctx, aom_get_frame_buffer_cb_fn_t cb_get,
689 aom_release_frame_buffer_cb_fn_t cb_release, void *cb_priv) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700690 if (cb_get == NULL || cb_release == NULL) {
Yaowu Xuf883b422016-08-30 14:01:10 -0700691 return AOM_CODEC_INVALID_PARAM;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700692 } else if (ctx->frame_workers == NULL) {
693 // If the decoder has already been initialized, do not accept changes to
694 // the frame buffer functions.
695 ctx->get_ext_fb_cb = cb_get;
696 ctx->release_ext_fb_cb = cb_release;
697 ctx->ext_priv = cb_priv;
Yaowu Xuf883b422016-08-30 14:01:10 -0700698 return AOM_CODEC_OK;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700699 }
700
Yaowu Xuf883b422016-08-30 14:01:10 -0700701 return AOM_CODEC_ERROR;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700702}
703
Yaowu Xuf883b422016-08-30 14:01:10 -0700704static aom_codec_err_t ctrl_set_reference(aom_codec_alg_priv_t *ctx,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700705 va_list args) {
Thomas Daede497d1952017-08-08 17:33:06 -0700706 av1_ref_frame_t *const data = va_arg(args, av1_ref_frame_t *);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700707
Yaowu Xuc27fc142016-08-22 16:08:15 -0700708 if (data) {
Thomas Daede497d1952017-08-08 17:33:06 -0700709 av1_ref_frame_t *const frame = data;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700710 YV12_BUFFER_CONFIG sd;
Yaowu Xuf883b422016-08-30 14:01:10 -0700711 AVxWorker *const worker = ctx->frame_workers;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700712 FrameWorkerData *const frame_worker_data = (FrameWorkerData *)worker->data1;
713 image2yuvconfig(&frame->img, &sd);
Thomas Daede497d1952017-08-08 17:33:06 -0700714 return av1_set_reference_dec(&frame_worker_data->pbi->common, frame->idx,
Yunqing Wang4450c762018-04-24 13:49:25 -0700715 frame->use_external_ref, &sd);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700716 } else {
Yaowu Xuf883b422016-08-30 14:01:10 -0700717 return AOM_CODEC_INVALID_PARAM;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700718 }
719}
720
Yaowu Xuf883b422016-08-30 14:01:10 -0700721static aom_codec_err_t ctrl_copy_reference(aom_codec_alg_priv_t *ctx,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700722 va_list args) {
Thomas Daede497d1952017-08-08 17:33:06 -0700723 const av1_ref_frame_t *const frame = va_arg(args, av1_ref_frame_t *);
Urvang Joshi77853e52016-07-15 12:47:01 -0700724 if (frame) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700725 YV12_BUFFER_CONFIG sd;
Yaowu Xuf883b422016-08-30 14:01:10 -0700726 AVxWorker *const worker = ctx->frame_workers;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700727 FrameWorkerData *const frame_worker_data = (FrameWorkerData *)worker->data1;
728 image2yuvconfig(&frame->img, &sd);
Thomas Daede497d1952017-08-08 17:33:06 -0700729 return av1_copy_reference_dec(frame_worker_data->pbi, frame->idx, &sd);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700730 } else {
Yaowu Xuf883b422016-08-30 14:01:10 -0700731 return AOM_CODEC_INVALID_PARAM;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700732 }
733}
734
Yaowu Xuf883b422016-08-30 14:01:10 -0700735static aom_codec_err_t ctrl_get_reference(aom_codec_alg_priv_t *ctx,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700736 va_list args) {
Yaowu Xuf883b422016-08-30 14:01:10 -0700737 av1_ref_frame_t *data = va_arg(args, av1_ref_frame_t *);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700738 if (data) {
739 YV12_BUFFER_CONFIG *fb;
Yaowu Xuf883b422016-08-30 14:01:10 -0700740 AVxWorker *const worker = ctx->frame_workers;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700741 FrameWorkerData *const frame_worker_data = (FrameWorkerData *)worker->data1;
742 fb = get_ref_frame(&frame_worker_data->pbi->common, data->idx);
Yaowu Xuf883b422016-08-30 14:01:10 -0700743 if (fb == NULL) return AOM_CODEC_ERROR;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700744 yuvconfig2image(&data->img, fb, NULL);
Yaowu Xuf883b422016-08-30 14:01:10 -0700745 return AOM_CODEC_OK;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700746 } else {
Yaowu Xuf883b422016-08-30 14:01:10 -0700747 return AOM_CODEC_INVALID_PARAM;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700748 }
749}
750
Yaowu Xuf883b422016-08-30 14:01:10 -0700751static aom_codec_err_t ctrl_get_new_frame_image(aom_codec_alg_priv_t *ctx,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700752 va_list args) {
Yaowu Xuf883b422016-08-30 14:01:10 -0700753 aom_image_t *new_img = va_arg(args, aom_image_t *);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700754 if (new_img) {
755 YV12_BUFFER_CONFIG new_frame;
Yaowu Xuf883b422016-08-30 14:01:10 -0700756 AVxWorker *const worker = ctx->frame_workers;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700757 FrameWorkerData *const frame_worker_data = (FrameWorkerData *)worker->data1;
758
Yaowu Xuf883b422016-08-30 14:01:10 -0700759 if (av1_get_frame_to_show(frame_worker_data->pbi, &new_frame) == 0) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700760 yuvconfig2image(new_img, &new_frame, NULL);
Yaowu Xuf883b422016-08-30 14:01:10 -0700761 return AOM_CODEC_OK;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700762 } else {
Yaowu Xuf883b422016-08-30 14:01:10 -0700763 return AOM_CODEC_ERROR;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700764 }
765 } else {
Yaowu Xuf883b422016-08-30 14:01:10 -0700766 return AOM_CODEC_INVALID_PARAM;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700767 }
768}
769
Yunqing Wang20a336d2018-04-25 10:19:53 -0700770static aom_codec_err_t ctrl_copy_new_frame_image(aom_codec_alg_priv_t *ctx,
771 va_list args) {
772 aom_image_t *img = va_arg(args, aom_image_t *);
773 if (img) {
774 YV12_BUFFER_CONFIG new_frame;
775 AVxWorker *const worker = ctx->frame_workers;
776 FrameWorkerData *const frame_worker_data = (FrameWorkerData *)worker->data1;
777
778 if (av1_get_frame_to_show(frame_worker_data->pbi, &new_frame) == 0) {
779 YV12_BUFFER_CONFIG sd;
780 image2yuvconfig(img, &sd);
781 return av1_copy_new_frame_dec(&frame_worker_data->pbi->common, &new_frame,
782 &sd);
783 } else {
784 return AOM_CODEC_ERROR;
785 }
786 } else {
787 return AOM_CODEC_INVALID_PARAM;
788 }
789}
790
Yaowu Xuf883b422016-08-30 14:01:10 -0700791static aom_codec_err_t ctrl_set_postproc(aom_codec_alg_priv_t *ctx,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700792 va_list args) {
793 (void)ctx;
794 (void)args;
Yaowu Xuf883b422016-08-30 14:01:10 -0700795 return AOM_CODEC_INCAPABLE;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700796}
797
Yaowu Xuf883b422016-08-30 14:01:10 -0700798static aom_codec_err_t ctrl_set_dbg_options(aom_codec_alg_priv_t *ctx,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700799 va_list args) {
800 (void)ctx;
801 (void)args;
Yaowu Xuf883b422016-08-30 14:01:10 -0700802 return AOM_CODEC_INCAPABLE;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700803}
804
Yaowu Xuf883b422016-08-30 14:01:10 -0700805static aom_codec_err_t ctrl_get_last_ref_updates(aom_codec_alg_priv_t *ctx,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700806 va_list args) {
807 int *const update_info = va_arg(args, int *);
808
Yaowu Xuc27fc142016-08-22 16:08:15 -0700809 if (update_info) {
810 if (ctx->frame_workers) {
Yaowu Xuf883b422016-08-30 14:01:10 -0700811 AVxWorker *const worker = ctx->frame_workers;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700812 FrameWorkerData *const frame_worker_data =
813 (FrameWorkerData *)worker->data1;
814 *update_info = frame_worker_data->pbi->refresh_frame_flags;
Yaowu Xuf883b422016-08-30 14:01:10 -0700815 return AOM_CODEC_OK;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700816 } else {
Yaowu Xuf883b422016-08-30 14:01:10 -0700817 return AOM_CODEC_ERROR;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700818 }
819 }
820
Yaowu Xuf883b422016-08-30 14:01:10 -0700821 return AOM_CODEC_INVALID_PARAM;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700822}
823
Peter Boströma1f64322017-01-19 11:35:30 -0500824static aom_codec_err_t ctrl_get_last_quantizer(aom_codec_alg_priv_t *ctx,
825 va_list args) {
826 int *const arg = va_arg(args, int *);
827 if (arg == NULL) return AOM_CODEC_INVALID_PARAM;
828 *arg =
829 ((FrameWorkerData *)ctx->frame_workers[0].data1)->pbi->common.base_qindex;
830 return AOM_CODEC_OK;
831}
832
Yaowu Xuf883b422016-08-30 14:01:10 -0700833static aom_codec_err_t ctrl_get_frame_corrupted(aom_codec_alg_priv_t *ctx,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700834 va_list args) {
835 int *corrupted = va_arg(args, int *);
836
837 if (corrupted) {
838 if (ctx->frame_workers) {
Yaowu Xuf883b422016-08-30 14:01:10 -0700839 AVxWorker *const worker = ctx->frame_workers;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700840 FrameWorkerData *const frame_worker_data =
841 (FrameWorkerData *)worker->data1;
842 RefCntBuffer *const frame_bufs =
843 frame_worker_data->pbi->common.buffer_pool->frame_bufs;
844 if (frame_worker_data->pbi->common.frame_to_show == NULL)
Yaowu Xuf883b422016-08-30 14:01:10 -0700845 return AOM_CODEC_ERROR;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700846 if (ctx->last_show_frame >= 0)
847 *corrupted = frame_bufs[ctx->last_show_frame].buf.corrupted;
Yaowu Xuf883b422016-08-30 14:01:10 -0700848 return AOM_CODEC_OK;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700849 } else {
Yaowu Xuf883b422016-08-30 14:01:10 -0700850 return AOM_CODEC_ERROR;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700851 }
852 }
853
Yaowu Xuf883b422016-08-30 14:01:10 -0700854 return AOM_CODEC_INVALID_PARAM;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700855}
856
Yaowu Xuf883b422016-08-30 14:01:10 -0700857static aom_codec_err_t ctrl_get_frame_size(aom_codec_alg_priv_t *ctx,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700858 va_list args) {
859 int *const frame_size = va_arg(args, int *);
860
Yaowu Xuc27fc142016-08-22 16:08:15 -0700861 if (frame_size) {
862 if (ctx->frame_workers) {
Yaowu Xuf883b422016-08-30 14:01:10 -0700863 AVxWorker *const worker = ctx->frame_workers;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700864 FrameWorkerData *const frame_worker_data =
865 (FrameWorkerData *)worker->data1;
Yaowu Xuf883b422016-08-30 14:01:10 -0700866 const AV1_COMMON *const cm = &frame_worker_data->pbi->common;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700867 frame_size[0] = cm->width;
868 frame_size[1] = cm->height;
Yaowu Xuf883b422016-08-30 14:01:10 -0700869 return AOM_CODEC_OK;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700870 } else {
Yaowu Xuf883b422016-08-30 14:01:10 -0700871 return AOM_CODEC_ERROR;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700872 }
873 }
874
Yaowu Xuf883b422016-08-30 14:01:10 -0700875 return AOM_CODEC_INVALID_PARAM;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700876}
877
Yaowu Xuf883b422016-08-30 14:01:10 -0700878static aom_codec_err_t ctrl_get_render_size(aom_codec_alg_priv_t *ctx,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700879 va_list args) {
880 int *const render_size = va_arg(args, int *);
881
Yaowu Xuc27fc142016-08-22 16:08:15 -0700882 if (render_size) {
883 if (ctx->frame_workers) {
Yaowu Xuf883b422016-08-30 14:01:10 -0700884 AVxWorker *const worker = ctx->frame_workers;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700885 FrameWorkerData *const frame_worker_data =
886 (FrameWorkerData *)worker->data1;
Yaowu Xuf883b422016-08-30 14:01:10 -0700887 const AV1_COMMON *const cm = &frame_worker_data->pbi->common;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700888 render_size[0] = cm->render_width;
889 render_size[1] = cm->render_height;
Yaowu Xuf883b422016-08-30 14:01:10 -0700890 return AOM_CODEC_OK;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700891 } else {
Yaowu Xuf883b422016-08-30 14:01:10 -0700892 return AOM_CODEC_ERROR;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700893 }
894 }
895
Yaowu Xuf883b422016-08-30 14:01:10 -0700896 return AOM_CODEC_INVALID_PARAM;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700897}
898
Yaowu Xuf883b422016-08-30 14:01:10 -0700899static aom_codec_err_t ctrl_get_bit_depth(aom_codec_alg_priv_t *ctx,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700900 va_list args) {
901 unsigned int *const bit_depth = va_arg(args, unsigned int *);
Yaowu Xuf883b422016-08-30 14:01:10 -0700902 AVxWorker *const worker = &ctx->frame_workers[ctx->next_output_worker_id];
Yaowu Xuc27fc142016-08-22 16:08:15 -0700903
904 if (bit_depth) {
905 if (worker) {
906 FrameWorkerData *const frame_worker_data =
907 (FrameWorkerData *)worker->data1;
Yaowu Xuf883b422016-08-30 14:01:10 -0700908 const AV1_COMMON *const cm = &frame_worker_data->pbi->common;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700909 *bit_depth = cm->bit_depth;
Yaowu Xuf883b422016-08-30 14:01:10 -0700910 return AOM_CODEC_OK;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700911 } else {
Yaowu Xuf883b422016-08-30 14:01:10 -0700912 return AOM_CODEC_ERROR;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700913 }
914 }
915
Yaowu Xuf883b422016-08-30 14:01:10 -0700916 return AOM_CODEC_INVALID_PARAM;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700917}
918
Yaowu Xuf883b422016-08-30 14:01:10 -0700919static aom_codec_err_t ctrl_set_invert_tile_order(aom_codec_alg_priv_t *ctx,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700920 va_list args) {
921 ctx->invert_tile_order = va_arg(args, int);
Yaowu Xuf883b422016-08-30 14:01:10 -0700922 return AOM_CODEC_OK;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700923}
924
Yaowu Xuf883b422016-08-30 14:01:10 -0700925static aom_codec_err_t ctrl_set_byte_alignment(aom_codec_alg_priv_t *ctx,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700926 va_list args) {
927 const int legacy_byte_alignment = 0;
928 const int min_byte_alignment = 32;
929 const int max_byte_alignment = 1024;
930 const int byte_alignment = va_arg(args, int);
931
932 if (byte_alignment != legacy_byte_alignment &&
933 (byte_alignment < min_byte_alignment ||
934 byte_alignment > max_byte_alignment ||
935 (byte_alignment & (byte_alignment - 1)) != 0))
Yaowu Xuf883b422016-08-30 14:01:10 -0700936 return AOM_CODEC_INVALID_PARAM;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700937
938 ctx->byte_alignment = byte_alignment;
939 if (ctx->frame_workers) {
Yaowu Xuf883b422016-08-30 14:01:10 -0700940 AVxWorker *const worker = ctx->frame_workers;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700941 FrameWorkerData *const frame_worker_data = (FrameWorkerData *)worker->data1;
942 frame_worker_data->pbi->common.byte_alignment = byte_alignment;
943 }
Yaowu Xuf883b422016-08-30 14:01:10 -0700944 return AOM_CODEC_OK;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700945}
946
Yaowu Xuf883b422016-08-30 14:01:10 -0700947static aom_codec_err_t ctrl_set_skip_loop_filter(aom_codec_alg_priv_t *ctx,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700948 va_list args) {
949 ctx->skip_loop_filter = va_arg(args, int);
950
951 if (ctx->frame_workers) {
Yaowu Xuf883b422016-08-30 14:01:10 -0700952 AVxWorker *const worker = ctx->frame_workers;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700953 FrameWorkerData *const frame_worker_data = (FrameWorkerData *)worker->data1;
954 frame_worker_data->pbi->common.skip_loop_filter = ctx->skip_loop_filter;
955 }
956
Yaowu Xuf883b422016-08-30 14:01:10 -0700957 return AOM_CODEC_OK;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700958}
959
Nathan E. Eggec9862e02016-10-05 21:28:36 -0400960static aom_codec_err_t ctrl_get_accounting(aom_codec_alg_priv_t *ctx,
961 va_list args) {
962#if !CONFIG_ACCOUNTING
963 (void)ctx;
964 (void)args;
965 return AOM_CODEC_INCAPABLE;
966#else
967 if (ctx->frame_workers) {
968 AVxWorker *const worker = ctx->frame_workers;
969 FrameWorkerData *const frame_worker_data = (FrameWorkerData *)worker->data1;
970 AV1Decoder *pbi = frame_worker_data->pbi;
971 Accounting **acct = va_arg(args, Accounting **);
972 *acct = &pbi->accounting;
973 return AOM_CODEC_OK;
974 }
975 return AOM_CODEC_ERROR;
976#endif
977}
Yaowu Xuf883b422016-08-30 14:01:10 -0700978static aom_codec_err_t ctrl_set_decode_tile_row(aom_codec_alg_priv_t *ctx,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700979 va_list args) {
980 ctx->decode_tile_row = va_arg(args, int);
Yaowu Xuf883b422016-08-30 14:01:10 -0700981 return AOM_CODEC_OK;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700982}
983
Yaowu Xuf883b422016-08-30 14:01:10 -0700984static aom_codec_err_t ctrl_set_decode_tile_col(aom_codec_alg_priv_t *ctx,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700985 va_list args) {
986 ctx->decode_tile_col = va_arg(args, int);
Yaowu Xuf883b422016-08-30 14:01:10 -0700987 return AOM_CODEC_OK;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700988}
989
Yunqing Wang8ae64a92018-01-12 12:26:44 -0800990static aom_codec_err_t ctrl_set_tile_mode(aom_codec_alg_priv_t *ctx,
991 va_list args) {
992 ctx->tile_mode = va_arg(args, unsigned int);
993 return AOM_CODEC_OK;
994}
995
Soo-Chul Han29c46fb2018-03-23 16:02:00 -0400996static aom_codec_err_t ctrl_set_is_annexb(aom_codec_alg_priv_t *ctx,
997 va_list args) {
998 ctx->is_annexb = va_arg(args, unsigned int);
999 return AOM_CODEC_OK;
1000}
1001
Frank Bossend8f457a2018-04-30 21:44:12 -04001002static aom_codec_err_t ctrl_set_operating_point(aom_codec_alg_priv_t *ctx,
1003 va_list args) {
1004 ctx->operating_point = va_arg(args, int);
1005 return AOM_CODEC_OK;
1006}
1007
Nathan E. Egge2cf03b12017-02-22 16:19:59 -05001008static aom_codec_err_t ctrl_set_inspection_callback(aom_codec_alg_priv_t *ctx,
1009 va_list args) {
1010#if !CONFIG_INSPECTION
1011 (void)ctx;
1012 (void)args;
1013 return AOM_CODEC_INCAPABLE;
1014#else
1015 aom_inspect_init *init = va_arg(args, aom_inspect_init *);
1016 ctx->inspect_cb = init->inspect_cb;
1017 ctx->inspect_ctx = init->inspect_ctx;
1018 return AOM_CODEC_OK;
1019#endif
1020}
1021
Yaowu Xuf883b422016-08-30 14:01:10 -07001022static aom_codec_ctrl_fn_map_t decoder_ctrl_maps[] = {
Thomas Daede497d1952017-08-08 17:33:06 -07001023 { AV1_COPY_REFERENCE, ctrl_copy_reference },
Yaowu Xuc27fc142016-08-22 16:08:15 -07001024
1025 // Setters
Thomas Daede497d1952017-08-08 17:33:06 -07001026 { AV1_SET_REFERENCE, ctrl_set_reference },
Yaowu Xuf883b422016-08-30 14:01:10 -07001027 { AOM_SET_POSTPROC, ctrl_set_postproc },
1028 { AOM_SET_DBG_COLOR_REF_FRAME, ctrl_set_dbg_options },
1029 { AOM_SET_DBG_COLOR_MB_MODES, ctrl_set_dbg_options },
1030 { AOM_SET_DBG_COLOR_B_MODES, ctrl_set_dbg_options },
1031 { AOM_SET_DBG_DISPLAY_MV, ctrl_set_dbg_options },
1032 { AV1_INVERT_TILE_DECODE_ORDER, ctrl_set_invert_tile_order },
Yaowu Xuf883b422016-08-30 14:01:10 -07001033 { AV1_SET_BYTE_ALIGNMENT, ctrl_set_byte_alignment },
1034 { AV1_SET_SKIP_LOOP_FILTER, ctrl_set_skip_loop_filter },
1035 { AV1_SET_DECODE_TILE_ROW, ctrl_set_decode_tile_row },
1036 { AV1_SET_DECODE_TILE_COL, ctrl_set_decode_tile_col },
Yunqing Wang8ae64a92018-01-12 12:26:44 -08001037 { AV1_SET_TILE_MODE, ctrl_set_tile_mode },
Soo-Chul Han29c46fb2018-03-23 16:02:00 -04001038 { AV1D_SET_IS_ANNEXB, ctrl_set_is_annexb },
Frank Bossend8f457a2018-04-30 21:44:12 -04001039 { AV1D_SET_OPERATING_POINT, ctrl_set_operating_point },
Nathan E. Egge2cf03b12017-02-22 16:19:59 -05001040 { AV1_SET_INSPECTION_CALLBACK, ctrl_set_inspection_callback },
Yaowu Xuc27fc142016-08-22 16:08:15 -07001041
1042 // Getters
Yaowu Xuf883b422016-08-30 14:01:10 -07001043 { AOMD_GET_FRAME_CORRUPTED, ctrl_get_frame_corrupted },
Peter Boströma1f64322017-01-19 11:35:30 -05001044 { AOMD_GET_LAST_QUANTIZER, ctrl_get_last_quantizer },
1045 { AOMD_GET_LAST_REF_UPDATES, ctrl_get_last_ref_updates },
Yaowu Xuf883b422016-08-30 14:01:10 -07001046 { AV1D_GET_BIT_DEPTH, ctrl_get_bit_depth },
Peter Boströma1f64322017-01-19 11:35:30 -05001047 { AV1D_GET_DISPLAY_SIZE, ctrl_get_render_size },
Yaowu Xuf883b422016-08-30 14:01:10 -07001048 { AV1D_GET_FRAME_SIZE, ctrl_get_frame_size },
Nathan E. Eggec9862e02016-10-05 21:28:36 -04001049 { AV1_GET_ACCOUNTING, ctrl_get_accounting },
Yaowu Xuf883b422016-08-30 14:01:10 -07001050 { AV1_GET_NEW_FRAME_IMAGE, ctrl_get_new_frame_image },
Yunqing Wang20a336d2018-04-25 10:19:53 -07001051 { AV1_COPY_NEW_FRAME_IMAGE, ctrl_copy_new_frame_image },
Peter Boströma1f64322017-01-19 11:35:30 -05001052 { AV1_GET_REFERENCE, ctrl_get_reference },
Yaowu Xuc27fc142016-08-22 16:08:15 -07001053
1054 { -1, NULL },
1055};
1056
1057#ifndef VERSION_STRING
1058#define VERSION_STRING
1059#endif
Yaowu Xuf883b422016-08-30 14:01:10 -07001060CODEC_INTERFACE(aom_codec_av1_dx) = {
1061 "AOMedia Project AV1 Decoder" VERSION_STRING,
1062 AOM_CODEC_INTERNAL_ABI_VERSION,
1063 AOM_CODEC_CAP_DECODER |
1064 AOM_CODEC_CAP_EXTERNAL_FRAME_BUFFER, // aom_codec_caps_t
1065 decoder_init, // aom_codec_init_fn_t
1066 decoder_destroy, // aom_codec_destroy_fn_t
1067 decoder_ctrl_maps, // aom_codec_ctrl_fn_map_t
Yaowu Xuc27fc142016-08-22 16:08:15 -07001068 {
1069 // NOLINT
Yaowu Xuf883b422016-08-30 14:01:10 -07001070 decoder_peek_si, // aom_codec_peek_si_fn_t
1071 decoder_get_si, // aom_codec_get_si_fn_t
1072 decoder_decode, // aom_codec_decode_fn_t
1073 decoder_get_frame, // aom_codec_frame_get_fn_t
1074 decoder_set_fb_fn, // aom_codec_set_fb_fn_t
Yaowu Xuc27fc142016-08-22 16:08:15 -07001075 },
1076 {
1077 // NOLINT
1078 0,
Yaowu Xuf883b422016-08-30 14:01:10 -07001079 NULL, // aom_codec_enc_cfg_map_t
1080 NULL, // aom_codec_encode_fn_t
1081 NULL, // aom_codec_get_cx_data_fn_t
1082 NULL, // aom_codec_enc_config_set_fn_t
1083 NULL, // aom_codec_get_global_headers_fn_t
1084 NULL, // aom_codec_get_preview_frame_fn_t
1085 NULL // aom_codec_enc_mr_get_mem_loc_fn_t
Yaowu Xuc27fc142016-08-22 16:08:15 -07001086 }
1087};