blob: a3e2f2b118e94f71cb7bace7622df8332ef9760d [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
Hui Sudf5b2912018-03-16 15:34:01 -0700158static size_t get_obu_length_field_size(const uint8_t *data, size_t data_sz) {
159 const size_t max_bytes = AOMMIN(sizeof(uint64_t), data_sz);
Vignesh Venkatasubramanian03391a22018-03-09 12:25:55 -0800160 size_t length_field_size = 1;
Hui Sudf5b2912018-03-16 15:34:01 -0700161 for (size_t i = 0; i < max_bytes && (data[i] & 0x80); ++i) {
Vignesh Venkatasubramanian03391a22018-03-09 12:25:55 -0800162 ++length_field_size;
163 }
164 return length_field_size;
165}
166
Tom Finegan7ecf8152018-04-26 11:48:47 -0700167static void parse_operating_points(struct aom_read_bit_buffer *rb,
168 int is_reduced_header,
Soo-Chul Han4ea3c5e2018-04-06 10:18:32 -0400169 aom_codec_stream_info_t *si) {
Tom Finegan7ecf8152018-04-26 11:48:47 -0700170 if (is_reduced_header) {
Debargha Mukherjeeacd41f92018-04-11 07:58:34 -0700171 aom_rb_read_literal(rb, LEVEL_BITS); // level
172 } else {
Wan-Teh Chang69582972018-05-15 13:18:52 -0700173 const uint8_t operating_points_cnt_minus_1 =
174 aom_rb_read_literal(rb, OP_POINTS_CNT_MINUS_1_BITS);
Soo-Chul Hand2f317c2018-05-08 14:21:24 -0400175 int operating_point_idc0 = 0;
Wan-Teh Chang69582972018-05-15 13:18:52 -0700176 for (int i = 0; i < operating_points_cnt_minus_1 + 1; i++) {
Soo-Chul Hand2f317c2018-05-08 14:21:24 -0400177 int operating_point_idc;
178 operating_point_idc = aom_rb_read_literal(rb, OP_POINTS_IDC_BITS);
179 if (i == 0) operating_point_idc0 = operating_point_idc;
180 aom_rb_read_literal(rb, LEVEL_BITS); // level
Debargha Mukherjeeacd41f92018-04-11 07:58:34 -0700181#if !CONFIG_BUFFER_MODEL
182 if (aom_rb_read_literal(rb,
183 1)) { // decoder_rate_model_param_present_flag
184 aom_rb_read_literal(rb, 12); // decode_to_display_rate_ratio
185 aom_rb_read_literal(rb, 24); // initial_display_delay
186 aom_rb_read_literal(rb, 4); // extra_frame_buffers
187 }
188#endif // !CONFIG_BUFFER_MODEL
Debargha Mukherjee112c5822018-04-09 09:42:29 -0700189 }
Soo-Chul Hand2f317c2018-05-08 14:21:24 -0400190
191 // derive number of spatial/temporal layers from operating_point_idc0
192 if (operating_point_idc0 == 0) {
193 si->number_temporal_layers = 1;
194 si->number_spatial_layers = 1;
195 } else {
196 si->number_spatial_layers = 0;
197 si->number_temporal_layers = 0;
198 for (int j = 0; j < 8; j++) {
199 si->number_spatial_layers += (operating_point_idc0 >> (j + 8)) & 0x1;
200 si->number_temporal_layers += (operating_point_idc0 >> j) & 0x1;
201 }
202 }
Debargha Mukherjee112c5822018-04-09 09:42:29 -0700203 }
204}
205
Sebastien Alaiwan2b1ec182017-12-21 09:38:27 +0100206static aom_codec_err_t decoder_peek_si_internal(const uint8_t *data,
Tom Finegan21f48252018-05-15 11:31:04 -0700207 size_t data_sz,
Sebastien Alaiwan2b1ec182017-12-21 09:38:27 +0100208 aom_codec_stream_info_t *si,
209 int *is_intra_only) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700210 int intra_only_flag = 0;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700211
Hui Sudf5b2912018-03-16 15:34:01 -0700212 if (data + data_sz <= data || data_sz < 1) return AOM_CODEC_INVALID_PARAM;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700213
Tom Fineganf277ca32018-02-26 12:09:52 -0800214 si->w = 0;
Tom Finegan13ee28c2018-02-26 19:37:41 -0800215 si->h = 0;
216 si->is_kf = 0;
217
218 // TODO(tomfinegan): This function needs Sequence and Frame Header OBUs to
219 // operate properly. At present it hard codes the values to 1 for the keyframe
220 // and intra only flags, and assumes the data being parsed is a Sequence
221 // Header OBU.
David Barker5c0e80e2018-04-17 12:54:29 +0100222 // NOTE(david.barker): In addition, this code currently requires the video
223 // stream to begin with an optional OBU_TEMPORAL_DELIMITER followed by an
224 // OBU_SEQUENCE_HEADER.
Tom Fineganf277ca32018-02-26 12:09:52 -0800225 intra_only_flag = 1;
Tom Finegan13ee28c2018-02-26 19:37:41 -0800226 si->is_kf = 1;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700227
David Barker5c0e80e2018-04-17 12:54:29 +0100228 ObuHeader obu_header;
229 memset(&obu_header, 0, sizeof(obu_header));
230 size_t payload_size = 0;
231 size_t bytes_read = 0;
232 aom_codec_err_t status = aom_read_obu_header_and_size(
233 data, data_sz, si->is_annexb, &obu_header, &payload_size, &bytes_read);
234 if (status != AOM_CODEC_OK) return status;
Soo-Chul Han29c46fb2018-03-23 16:02:00 -0400235
David Barker5c0e80e2018-04-17 12:54:29 +0100236 // If the first OBU is a temporal delimiter, skip over it and look at the next
237 // OBU in the bitstream
238 if (obu_header.type == OBU_TEMPORAL_DELIMITER) {
239 // Skip any associated payload (there shouldn't be one, but just in case)
Wan-Teh Changbe668042018-04-24 11:58:21 -0700240 if (data_sz < bytes_read + payload_size) return AOM_CODEC_CORRUPT_FRAME;
David Barker5c0e80e2018-04-17 12:54:29 +0100241 data += bytes_read + payload_size;
Yaowu Xuf7ca9382018-04-29 19:43:32 -0700242 data_sz -= (uint32_t)(bytes_read + payload_size);
Tom Finegan13ee28c2018-02-26 19:37:41 -0800243
David Barker5c0e80e2018-04-17 12:54:29 +0100244 status = aom_read_obu_header_and_size(
245 data, data_sz, si->is_annexb, &obu_header, &payload_size, &bytes_read);
246 if (status != AOM_CODEC_OK) return status;
Soo-Chul Han29c46fb2018-03-23 16:02:00 -0400247 }
Vignesh Venkatasubramanian03391a22018-03-09 12:25:55 -0800248
David Barker5c0e80e2018-04-17 12:54:29 +0100249 // Check that the selected OBU is a sequence header
250 if (obu_header.type != OBU_SEQUENCE_HEADER) return AOM_CODEC_UNSUP_BITSTREAM;
251
252 // Read a few values from the sequence header payload
253 data += bytes_read;
Yaowu Xuf7ca9382018-04-29 19:43:32 -0700254 data_sz -= (uint32_t)bytes_read;
David Barker5c0e80e2018-04-17 12:54:29 +0100255 struct aom_read_bit_buffer rb = { data, data + data_sz, 0, NULL, NULL };
Tom Finegan13ee28c2018-02-26 19:37:41 -0800256
Debargha Mukherjee112c5822018-04-09 09:42:29 -0700257 av1_read_profile(&rb); // profile
258 const int still_picture = aom_rb_read_bit(&rb);
259 const int reduced_still_picture_hdr = aom_rb_read_bit(&rb);
260
261 if (!still_picture && reduced_still_picture_hdr) {
262 return AOM_CODEC_UNSUP_BITSTREAM;
263 }
264
Soo-Chul Han4ea3c5e2018-04-06 10:18:32 -0400265 parse_operating_points(&rb, reduced_still_picture_hdr, si);
Soo-Chul Hanf8589862018-01-24 03:13:14 +0000266
Tom Fineganf277ca32018-02-26 12:09:52 -0800267 int num_bits_width = aom_rb_read_literal(&rb, 4) + 1;
268 int num_bits_height = aom_rb_read_literal(&rb, 4) + 1;
269 int max_frame_width = aom_rb_read_literal(&rb, num_bits_width) + 1;
270 int max_frame_height = aom_rb_read_literal(&rb, num_bits_height) + 1;
271 si->w = max_frame_width;
272 si->h = max_frame_height;
Tom Fineganf277ca32018-02-26 12:09:52 -0800273
Yaowu Xuc27fc142016-08-22 16:08:15 -0700274 if (is_intra_only != NULL) *is_intra_only = intra_only_flag;
Yaowu Xuf883b422016-08-30 14:01:10 -0700275 return AOM_CODEC_OK;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700276}
277
Tom Finegan21f48252018-05-15 11:31:04 -0700278static aom_codec_err_t decoder_peek_si(const uint8_t *data, size_t data_sz,
Yaowu Xuf883b422016-08-30 14:01:10 -0700279 aom_codec_stream_info_t *si) {
Sebastien Alaiwan2b1ec182017-12-21 09:38:27 +0100280 return decoder_peek_si_internal(data, data_sz, si, NULL);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700281}
282
Yaowu Xuf883b422016-08-30 14:01:10 -0700283static aom_codec_err_t decoder_get_si(aom_codec_alg_priv_t *ctx,
284 aom_codec_stream_info_t *si) {
Ralph Gilesafe71d92017-05-03 13:18:57 -0700285 memcpy(si, &ctx->si, sizeof(*si));
Yaowu Xuc27fc142016-08-22 16:08:15 -0700286
Yaowu Xuf883b422016-08-30 14:01:10 -0700287 return AOM_CODEC_OK;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700288}
289
Yaowu Xuf883b422016-08-30 14:01:10 -0700290static void set_error_detail(aom_codec_alg_priv_t *ctx,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700291 const char *const error) {
292 ctx->base.err_detail = error;
293}
294
Yaowu Xuf883b422016-08-30 14:01:10 -0700295static aom_codec_err_t update_error_state(
296 aom_codec_alg_priv_t *ctx, const struct aom_internal_error_info *error) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700297 if (error->error_code)
298 set_error_detail(ctx, error->has_detail ? error->detail : NULL);
299
300 return error->error_code;
301}
302
Yaowu Xuf883b422016-08-30 14:01:10 -0700303static void init_buffer_callbacks(aom_codec_alg_priv_t *ctx) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700304 int i;
305
306 for (i = 0; i < ctx->num_frame_workers; ++i) {
Yaowu Xuf883b422016-08-30 14:01:10 -0700307 AVxWorker *const worker = &ctx->frame_workers[i];
Yaowu Xuc27fc142016-08-22 16:08:15 -0700308 FrameWorkerData *const frame_worker_data = (FrameWorkerData *)worker->data1;
Yaowu Xuf883b422016-08-30 14:01:10 -0700309 AV1_COMMON *const cm = &frame_worker_data->pbi->common;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700310 BufferPool *const pool = cm->buffer_pool;
311
312 cm->new_fb_idx = INVALID_IDX;
313 cm->byte_alignment = ctx->byte_alignment;
314 cm->skip_loop_filter = ctx->skip_loop_filter;
315
316 if (ctx->get_ext_fb_cb != NULL && ctx->release_ext_fb_cb != NULL) {
317 pool->get_fb_cb = ctx->get_ext_fb_cb;
318 pool->release_fb_cb = ctx->release_ext_fb_cb;
319 pool->cb_priv = ctx->ext_priv;
320 } else {
Yaowu Xuf883b422016-08-30 14:01:10 -0700321 pool->get_fb_cb = av1_get_frame_buffer;
322 pool->release_fb_cb = av1_release_frame_buffer;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700323
Yaowu Xuf883b422016-08-30 14:01:10 -0700324 if (av1_alloc_internal_frame_buffers(&pool->int_frame_buffers))
325 aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700326 "Failed to initialize internal frame buffers");
327
328 pool->cb_priv = &pool->int_frame_buffers;
329 }
330 }
331}
332
Yaowu Xuf883b422016-08-30 14:01:10 -0700333static void set_default_ppflags(aom_postproc_cfg_t *cfg) {
334 cfg->post_proc_flag = AOM_DEBLOCK | AOM_DEMACROBLOCK;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700335 cfg->deblocking_level = 4;
336 cfg->noise_level = 0;
337}
338
339static int frame_worker_hook(void *arg1, void *arg2) {
340 FrameWorkerData *const frame_worker_data = (FrameWorkerData *)arg1;
341 const uint8_t *data = frame_worker_data->data;
342 (void)arg2;
343
Yaowu Xuf883b422016-08-30 14:01:10 -0700344 frame_worker_data->result = av1_receive_compressed_data(
Yaowu Xuc27fc142016-08-22 16:08:15 -0700345 frame_worker_data->pbi, frame_worker_data->data_size, &data);
346 frame_worker_data->data_end = data;
347
Debargha Mukherjee5521a182018-03-06 12:29:01 -0800348 if (frame_worker_data->result != 0) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700349 // Check decode result in serial decode.
350 frame_worker_data->pbi->cur_buf->buf.corrupted = 1;
351 frame_worker_data->pbi->need_resync = 1;
352 }
353 return !frame_worker_data->result;
354}
355
Yaowu Xuf883b422016-08-30 14:01:10 -0700356static aom_codec_err_t init_decoder(aom_codec_alg_priv_t *ctx) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700357 int i;
Yaowu Xuf883b422016-08-30 14:01:10 -0700358 const AVxWorkerInterface *const winterface = aom_get_worker_interface();
Yaowu Xuc27fc142016-08-22 16:08:15 -0700359
360 ctx->last_show_frame = -1;
361 ctx->next_submit_worker_id = 0;
362 ctx->last_submit_worker_id = 0;
363 ctx->next_output_worker_id = 0;
364 ctx->frame_cache_read = 0;
365 ctx->frame_cache_write = 0;
366 ctx->num_cache_frames = 0;
367 ctx->need_resync = 1;
Debargha Mukherjee5521a182018-03-06 12:29:01 -0800368 ctx->num_frame_workers = 1;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700369 if (ctx->num_frame_workers > MAX_DECODE_THREADS)
370 ctx->num_frame_workers = MAX_DECODE_THREADS;
371 ctx->available_threads = ctx->num_frame_workers;
372 ctx->flushed = 0;
373
Yaowu Xuf883b422016-08-30 14:01:10 -0700374 ctx->buffer_pool = (BufferPool *)aom_calloc(1, sizeof(BufferPool));
375 if (ctx->buffer_pool == NULL) return AOM_CODEC_MEM_ERROR;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700376
377#if CONFIG_MULTITHREAD
378 if (pthread_mutex_init(&ctx->buffer_pool->pool_mutex, NULL)) {
379 set_error_detail(ctx, "Failed to allocate buffer pool mutex");
Yaowu Xuf883b422016-08-30 14:01:10 -0700380 return AOM_CODEC_MEM_ERROR;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700381 }
382#endif
383
Yaowu Xuf883b422016-08-30 14:01:10 -0700384 ctx->frame_workers = (AVxWorker *)aom_malloc(ctx->num_frame_workers *
Yaowu Xuc27fc142016-08-22 16:08:15 -0700385 sizeof(*ctx->frame_workers));
386 if (ctx->frame_workers == NULL) {
387 set_error_detail(ctx, "Failed to allocate frame_workers");
Yaowu Xuf883b422016-08-30 14:01:10 -0700388 return AOM_CODEC_MEM_ERROR;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700389 }
390
391 for (i = 0; i < ctx->num_frame_workers; ++i) {
Yaowu Xuf883b422016-08-30 14:01:10 -0700392 AVxWorker *const worker = &ctx->frame_workers[i];
Yaowu Xuc27fc142016-08-22 16:08:15 -0700393 FrameWorkerData *frame_worker_data = NULL;
394 winterface->init(worker);
Yaowu Xuf883b422016-08-30 14:01:10 -0700395 worker->data1 = aom_memalign(32, sizeof(FrameWorkerData));
Yaowu Xuc27fc142016-08-22 16:08:15 -0700396 if (worker->data1 == NULL) {
397 set_error_detail(ctx, "Failed to allocate frame_worker_data");
Yaowu Xuf883b422016-08-30 14:01:10 -0700398 return AOM_CODEC_MEM_ERROR;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700399 }
400 frame_worker_data = (FrameWorkerData *)worker->data1;
Yaowu Xuf883b422016-08-30 14:01:10 -0700401 frame_worker_data->pbi = av1_decoder_create(ctx->buffer_pool);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700402 if (frame_worker_data->pbi == NULL) {
403 set_error_detail(ctx, "Failed to allocate frame_worker_data");
Yaowu Xuf883b422016-08-30 14:01:10 -0700404 return AOM_CODEC_MEM_ERROR;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700405 }
Maxym Dmytrychenkocc6e0e12018-02-05 16:35:37 +0100406 frame_worker_data->pbi->common.options = &ctx->cfg.cfg;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700407 frame_worker_data->pbi->frame_worker_owner = worker;
408 frame_worker_data->worker_id = i;
409 frame_worker_data->scratch_buffer = NULL;
410 frame_worker_data->scratch_buffer_size = 0;
411 frame_worker_data->frame_context_ready = 0;
412 frame_worker_data->received_frame = 0;
413#if CONFIG_MULTITHREAD
414 if (pthread_mutex_init(&frame_worker_data->stats_mutex, NULL)) {
415 set_error_detail(ctx, "Failed to allocate frame_worker_data mutex");
Yaowu Xuf883b422016-08-30 14:01:10 -0700416 return AOM_CODEC_MEM_ERROR;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700417 }
418
419 if (pthread_cond_init(&frame_worker_data->stats_cond, NULL)) {
420 set_error_detail(ctx, "Failed to allocate frame_worker_data cond");
Yaowu Xuf883b422016-08-30 14:01:10 -0700421 return AOM_CODEC_MEM_ERROR;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700422 }
423#endif
Sebastien Alaiwan8b7a4e12017-06-13 11:25:57 +0200424 frame_worker_data->pbi->allow_lowbitdepth = ctx->cfg.allow_lowbitdepth;
425
Yaowu Xuc27fc142016-08-22 16:08:15 -0700426 // If decoding in serial mode, FrameWorker thread could create tile worker
427 // thread or loopfilter thread.
Debargha Mukherjee5521a182018-03-06 12:29:01 -0800428 frame_worker_data->pbi->max_threads = ctx->cfg.threads;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700429 frame_worker_data->pbi->inv_tile_order = ctx->invert_tile_order;
Yunqing Wang8ae64a92018-01-12 12:26:44 -0800430 frame_worker_data->pbi->common.large_scale_tile = ctx->tile_mode;
Soo-Chul Han29c46fb2018-03-23 16:02:00 -0400431 frame_worker_data->pbi->common.is_annexb = ctx->is_annexb;
Yunqing Wang8ae64a92018-01-12 12:26:44 -0800432 frame_worker_data->pbi->dec_tile_row = ctx->decode_tile_row;
433 frame_worker_data->pbi->dec_tile_col = ctx->decode_tile_col;
Frank Bossend8f457a2018-04-30 21:44:12 -0400434 frame_worker_data->pbi->operating_point = ctx->operating_point;
Yaowu Xuf883b422016-08-30 14:01:10 -0700435 worker->hook = (AVxWorkerHook)frame_worker_hook;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700436 if (!winterface->reset(worker)) {
437 set_error_detail(ctx, "Frame Worker thread creation failed");
Yaowu Xuf883b422016-08-30 14:01:10 -0700438 return AOM_CODEC_MEM_ERROR;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700439 }
440 }
441
442 // If postprocessing was enabled by the application and a
443 // configuration has not been provided, default it.
Yaowu Xuf883b422016-08-30 14:01:10 -0700444 if (!ctx->postproc_cfg_set && (ctx->base.init_flags & AOM_CODEC_USE_POSTPROC))
Yaowu Xuc27fc142016-08-22 16:08:15 -0700445 set_default_ppflags(&ctx->postproc_cfg);
446
447 init_buffer_callbacks(ctx);
448
Yaowu Xuf883b422016-08-30 14:01:10 -0700449 return AOM_CODEC_OK;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700450}
451
Yaowu Xuf883b422016-08-30 14:01:10 -0700452static INLINE void check_resync(aom_codec_alg_priv_t *const ctx,
453 const AV1Decoder *const pbi) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700454 // Clear resync flag if worker got a key frame or intra only frame.
455 if (ctx->need_resync == 1 && pbi->need_resync == 0 &&
456 (pbi->common.intra_only || pbi->common.frame_type == KEY_FRAME))
457 ctx->need_resync = 0;
458}
459
Yaowu Xuf883b422016-08-30 14:01:10 -0700460static aom_codec_err_t decode_one(aom_codec_alg_priv_t *ctx,
Tom Finegan21f48252018-05-15 11:31:04 -0700461 const uint8_t **data, size_t data_sz,
Sean DuBois47cc2552018-01-23 07:44:16 +0000462 void *user_priv) {
Yaowu Xuf883b422016-08-30 14:01:10 -0700463 const AVxWorkerInterface *const winterface = aom_get_worker_interface();
Yaowu Xuc27fc142016-08-22 16:08:15 -0700464
465 // Determine the stream parameters. Note that we rely on peek_si to
466 // validate that we have a buffer that does not wrap around the top
467 // of the heap.
468 if (!ctx->si.h) {
469 int is_intra_only = 0;
Soo-Chul Han29c46fb2018-03-23 16:02:00 -0400470 ctx->si.is_annexb = ctx->is_annexb;
Tom Finegan21f48252018-05-15 11:31:04 -0700471 const aom_codec_err_t res =
472 decoder_peek_si_internal(*data, data_sz, &ctx->si, &is_intra_only);
Yaowu Xuf883b422016-08-30 14:01:10 -0700473 if (res != AOM_CODEC_OK) return res;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700474
Yaowu Xuf883b422016-08-30 14:01:10 -0700475 if (!ctx->si.is_kf && !is_intra_only) return AOM_CODEC_ERROR;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700476 }
477
Debargha Mukherjee5521a182018-03-06 12:29:01 -0800478 AVxWorker *const worker = ctx->frame_workers;
479 FrameWorkerData *const frame_worker_data = (FrameWorkerData *)worker->data1;
480 frame_worker_data->data = *data;
481 frame_worker_data->data_size = data_sz;
482 frame_worker_data->user_priv = user_priv;
483 frame_worker_data->received_frame = 1;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700484
Nathan E. Egge2cf03b12017-02-22 16:19:59 -0500485#if CONFIG_INSPECTION
Debargha Mukherjee5521a182018-03-06 12:29:01 -0800486 frame_worker_data->pbi->inspect_cb = ctx->inspect_cb;
487 frame_worker_data->pbi->inspect_ctx = ctx->inspect_ctx;
Nathan E. Egge2cf03b12017-02-22 16:19:59 -0500488#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -0700489
Debargha Mukherjee5521a182018-03-06 12:29:01 -0800490 frame_worker_data->pbi->common.large_scale_tile = ctx->tile_mode;
491 frame_worker_data->pbi->dec_tile_row = ctx->decode_tile_row;
492 frame_worker_data->pbi->dec_tile_col = ctx->decode_tile_col;
Yunqing Wang2a5575e2018-02-23 16:02:18 -0800493
Soo-Chul Han29c46fb2018-03-23 16:02:00 -0400494 frame_worker_data->pbi->common.is_annexb = ctx->is_annexb;
495
Debargha Mukherjee5521a182018-03-06 12:29:01 -0800496 worker->had_error = 0;
497 winterface->execute(worker);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700498
Debargha Mukherjee5521a182018-03-06 12:29:01 -0800499 // Update data pointer after decode.
500 *data = frame_worker_data->data_end;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700501
Debargha Mukherjee5521a182018-03-06 12:29:01 -0800502 if (worker->had_error)
503 return update_error_state(ctx, &frame_worker_data->pbi->common.error);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700504
Debargha Mukherjee5521a182018-03-06 12:29:01 -0800505 check_resync(ctx, frame_worker_data->pbi);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700506
Yaowu Xuf883b422016-08-30 14:01:10 -0700507 return AOM_CODEC_OK;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700508}
509
Yaowu Xuf883b422016-08-30 14:01:10 -0700510static aom_codec_err_t decoder_decode(aom_codec_alg_priv_t *ctx,
Tom Finegan21f48252018-05-15 11:31:04 -0700511 const uint8_t *data, size_t data_sz,
Sean DuBois47cc2552018-01-23 07:44:16 +0000512 void *user_priv) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700513 const uint8_t *data_start = data;
514 const uint8_t *const data_end = data + data_sz;
Yaowu Xub02d0b12017-12-15 01:32:34 +0000515 aom_codec_err_t res = AOM_CODEC_OK;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700516
517 if (data == NULL && data_sz == 0) {
518 ctx->flushed = 1;
Yaowu Xuf883b422016-08-30 14:01:10 -0700519 return AOM_CODEC_OK;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700520 }
521
522 // Reset flushed when receiving a valid frame.
523 ctx->flushed = 0;
524
525 // Initialize the decoder workers on the first frame.
526 if (ctx->frame_workers == NULL) {
Urvang Joshi454280d2016-10-14 16:51:44 -0700527 res = init_decoder(ctx);
Yaowu Xuf883b422016-08-30 14:01:10 -0700528 if (res != AOM_CODEC_OK) return res;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700529 }
Soo-Chul Han29c46fb2018-03-23 16:02:00 -0400530
Soo-Chul Han8acdbfc2018-04-02 12:55:33 -0400531 if (ctx->is_annexb) {
532 // read the size of this temporal unit
533 size_t length_of_size;
534 uint64_t size_of_unit;
535 if (aom_uleb_decode(data_start, data_sz, &size_of_unit, &length_of_size) !=
536 0) {
537 return AOM_CODEC_CORRUPT_FRAME;
538 }
539 data_start += length_of_size;
540 }
541
Debargha Mukherjee5521a182018-03-06 12:29:01 -0800542 // Decode in serial mode.
David Barker0bae60c2018-05-10 14:37:45 +0100543 while (data_start < data_end) {
544 uint64_t frame_size;
545 if (ctx->is_annexb) {
546 // read the size of this frame unit
547 size_t length_of_size;
548 if (aom_uleb_decode(data_start, (size_t)(data_end - data_start),
549 &frame_size, &length_of_size) != 0) {
Debargha Mukherjee5521a182018-03-06 12:29:01 -0800550 return AOM_CODEC_CORRUPT_FRAME;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700551 }
David Barker0bae60c2018-05-10 14:37:45 +0100552 data_start += length_of_size;
553 } else {
554 frame_size = (uint64_t)(data_end - data_start);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700555 }
David Barker0bae60c2018-05-10 14:37:45 +0100556
Tom Finegan21f48252018-05-15 11:31:04 -0700557 if (frame_size > UINT32_MAX) return AOM_CODEC_CORRUPT_FRAME;
558
559 res = decode_one(ctx, &data_start, (size_t)frame_size, user_priv);
David Barker0bae60c2018-05-10 14:37:45 +0100560 if (res != AOM_CODEC_OK) return res;
561
562 // Allow extra zero bytes after the frame end
Debargha Mukherjee5521a182018-03-06 12:29:01 -0800563 while (data_start < data_end) {
David Barker0bae60c2018-05-10 14:37:45 +0100564 const uint8_t marker = data_start[0];
565 if (marker) break;
566 ++data_start;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700567 }
568 }
569
570 return res;
571}
572
Andrey Norkin6f1c2f72018-01-15 20:08:52 -0800573aom_image_t *add_grain_if_needed(aom_image_t *img, aom_image_t *grain_img_buf,
574 aom_film_grain_t *grain_params) {
575 if (!grain_params->apply_grain) return img;
576
577 if (grain_img_buf &&
578 (img->d_w != grain_img_buf->d_w || img->d_h != grain_img_buf->d_h ||
Andrey Norkin4352fed2018-03-01 17:01:49 -0800579 img->fmt != grain_img_buf->fmt || !(img->d_h % 2) || !(img->d_w % 2))) {
Andrey Norkin6f1c2f72018-01-15 20:08:52 -0800580 aom_img_free(grain_img_buf);
581 grain_img_buf = NULL;
582 }
583 if (!grain_img_buf) {
Andrey Norkin4352fed2018-03-01 17:01:49 -0800584 int w_even = img->d_w % 2 ? img->d_w + 1 : img->d_w;
585 int h_even = img->d_h % 2 ? img->d_h + 1 : img->d_h;
586 grain_img_buf = aom_img_alloc(NULL, img->fmt, w_even, h_even, 16);
Andrey Norkin6f1c2f72018-01-15 20:08:52 -0800587 grain_img_buf->bit_depth = img->bit_depth;
588 }
589
590 av1_add_film_grain(grain_params, img, grain_img_buf);
591
592 return grain_img_buf;
593}
Andrey Norkin6f1c2f72018-01-15 20:08:52 -0800594
Yaowu Xuf883b422016-08-30 14:01:10 -0700595static aom_image_t *decoder_get_frame(aom_codec_alg_priv_t *ctx,
596 aom_codec_iter_t *iter) {
597 aom_image_t *img = NULL;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700598
Yaowu Xuc27fc142016-08-22 16:08:15 -0700599 // Output the frames in the cache first.
600 if (ctx->num_cache_frames > 0) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700601 ctx->last_show_frame = ctx->frame_cache[ctx->frame_cache_read].fb_idx;
602 if (ctx->need_resync) return NULL;
603 img = &ctx->frame_cache[ctx->frame_cache_read].img;
604 ctx->frame_cache_read = (ctx->frame_cache_read + 1) % FRAME_CACHE_SIZE;
605 --ctx->num_cache_frames;
Andrey Norkin6f1c2f72018-01-15 20:08:52 -0800606 return add_grain_if_needed(
607 img, ctx->image_with_grain,
608 &ctx->frame_cache[ctx->frame_cache_read].film_grain_params);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700609 }
610
611 // iter acts as a flip flop, so an image is only returned on the first
612 // call to get_frame.
613 if (*iter == NULL && ctx->frame_workers != NULL) {
614 do {
615 YV12_BUFFER_CONFIG sd;
Yaowu Xuf883b422016-08-30 14:01:10 -0700616 const AVxWorkerInterface *const winterface = aom_get_worker_interface();
617 AVxWorker *const worker = &ctx->frame_workers[ctx->next_output_worker_id];
Yaowu Xuc27fc142016-08-22 16:08:15 -0700618 FrameWorkerData *const frame_worker_data =
619 (FrameWorkerData *)worker->data1;
620 ctx->next_output_worker_id =
621 (ctx->next_output_worker_id + 1) % ctx->num_frame_workers;
622 // Wait for the frame from worker thread.
623 if (winterface->sync(worker)) {
624 // Check if worker has received any frames.
625 if (frame_worker_data->received_frame == 1) {
626 ++ctx->available_threads;
627 frame_worker_data->received_frame = 0;
628 check_resync(ctx, frame_worker_data->pbi);
629 }
Yaowu Xuf883b422016-08-30 14:01:10 -0700630 if (av1_get_raw_frame(frame_worker_data->pbi, &sd) == 0) {
631 AV1_COMMON *const cm = &frame_worker_data->pbi->common;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700632 RefCntBuffer *const frame_bufs = cm->buffer_pool->frame_bufs;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700633 ctx->last_show_frame = frame_worker_data->pbi->common.new_fb_idx;
634 if (ctx->need_resync) return NULL;
635 yuvconfig2image(&ctx->img, &sd, frame_worker_data->user_priv);
636
Imdad Sardharwallaaf8e2642018-01-19 11:46:34 +0000637 const int num_planes = av1_num_planes(cm);
Yunqing Wangeeb08a92017-07-07 21:25:18 -0700638 if (cm->single_tile_decoding &&
Yunqing Wangd8cd55f2017-02-27 12:16:00 -0800639 frame_worker_data->pbi->dec_tile_row >= 0) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700640 const int tile_row =
Yaowu Xuf883b422016-08-30 14:01:10 -0700641 AOMMIN(frame_worker_data->pbi->dec_tile_row, cm->tile_rows - 1);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700642 const int mi_row = tile_row * cm->tile_height;
643 const int ssy = ctx->img.y_chroma_shift;
644 int plane;
645 ctx->img.planes[0] += mi_row * MI_SIZE * ctx->img.stride[0];
Imdad Sardharwallaaf8e2642018-01-19 11:46:34 +0000646 if (num_planes > 1) {
647 for (plane = 1; plane < MAX_MB_PLANE; ++plane) {
648 ctx->img.planes[plane] +=
649 mi_row * (MI_SIZE >> ssy) * ctx->img.stride[plane];
650 }
Yaowu Xuc27fc142016-08-22 16:08:15 -0700651 }
652 ctx->img.d_h =
Yaowu Xuf883b422016-08-30 14:01:10 -0700653 AOMMIN(cm->tile_height, cm->mi_rows - mi_row) * MI_SIZE;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700654 }
655
Yunqing Wangeeb08a92017-07-07 21:25:18 -0700656 if (cm->single_tile_decoding &&
Yunqing Wangd8cd55f2017-02-27 12:16:00 -0800657 frame_worker_data->pbi->dec_tile_col >= 0) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700658 const int tile_col =
Yaowu Xuf883b422016-08-30 14:01:10 -0700659 AOMMIN(frame_worker_data->pbi->dec_tile_col, cm->tile_cols - 1);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700660 const int mi_col = tile_col * cm->tile_width;
661 const int ssx = ctx->img.x_chroma_shift;
662 int plane;
663 ctx->img.planes[0] += mi_col * MI_SIZE;
Imdad Sardharwallaaf8e2642018-01-19 11:46:34 +0000664 if (num_planes > 1) {
665 for (plane = 1; plane < MAX_MB_PLANE; ++plane) {
666 ctx->img.planes[plane] += mi_col * (MI_SIZE >> ssx);
667 }
Yaowu Xuc27fc142016-08-22 16:08:15 -0700668 }
669 ctx->img.d_w =
Yaowu Xuf883b422016-08-30 14:01:10 -0700670 AOMMIN(cm->tile_width, cm->mi_cols - mi_col) * MI_SIZE;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700671 }
Yaowu Xuc27fc142016-08-22 16:08:15 -0700672
673 ctx->img.fb_priv = frame_bufs[cm->new_fb_idx].raw_frame_buffer.priv;
674 img = &ctx->img;
Soo-Chul Hanf8589862018-01-24 03:13:14 +0000675 img->temporal_id = cm->temporal_layer_id;
Soo-Chul Hand2f317c2018-05-08 14:21:24 -0400676 img->spatial_id = cm->spatial_layer_id;
Andrey Norkin6f1c2f72018-01-15 20:08:52 -0800677 return add_grain_if_needed(
678 img, ctx->image_with_grain,
679 &frame_worker_data->pbi->common.film_grain_params);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700680 }
681 } else {
682 // Decoding failed. Release the worker thread.
683 frame_worker_data->received_frame = 0;
684 ++ctx->available_threads;
685 ctx->need_resync = 1;
686 if (ctx->flushed != 1) return NULL;
687 }
688 } while (ctx->next_output_worker_id != ctx->next_submit_worker_id);
689 }
690 return NULL;
691}
692
Yaowu Xuf883b422016-08-30 14:01:10 -0700693static aom_codec_err_t decoder_set_fb_fn(
694 aom_codec_alg_priv_t *ctx, aom_get_frame_buffer_cb_fn_t cb_get,
695 aom_release_frame_buffer_cb_fn_t cb_release, void *cb_priv) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700696 if (cb_get == NULL || cb_release == NULL) {
Yaowu Xuf883b422016-08-30 14:01:10 -0700697 return AOM_CODEC_INVALID_PARAM;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700698 } else if (ctx->frame_workers == NULL) {
699 // If the decoder has already been initialized, do not accept changes to
700 // the frame buffer functions.
701 ctx->get_ext_fb_cb = cb_get;
702 ctx->release_ext_fb_cb = cb_release;
703 ctx->ext_priv = cb_priv;
Yaowu Xuf883b422016-08-30 14:01:10 -0700704 return AOM_CODEC_OK;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700705 }
706
Yaowu Xuf883b422016-08-30 14:01:10 -0700707 return AOM_CODEC_ERROR;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700708}
709
Yaowu Xuf883b422016-08-30 14:01:10 -0700710static aom_codec_err_t ctrl_set_reference(aom_codec_alg_priv_t *ctx,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700711 va_list args) {
Thomas Daede497d1952017-08-08 17:33:06 -0700712 av1_ref_frame_t *const data = va_arg(args, av1_ref_frame_t *);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700713
Yaowu Xuc27fc142016-08-22 16:08:15 -0700714 if (data) {
Thomas Daede497d1952017-08-08 17:33:06 -0700715 av1_ref_frame_t *const frame = data;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700716 YV12_BUFFER_CONFIG sd;
Yaowu Xuf883b422016-08-30 14:01:10 -0700717 AVxWorker *const worker = ctx->frame_workers;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700718 FrameWorkerData *const frame_worker_data = (FrameWorkerData *)worker->data1;
719 image2yuvconfig(&frame->img, &sd);
Thomas Daede497d1952017-08-08 17:33:06 -0700720 return av1_set_reference_dec(&frame_worker_data->pbi->common, frame->idx,
Yunqing Wang4450c762018-04-24 13:49:25 -0700721 frame->use_external_ref, &sd);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700722 } else {
Yaowu Xuf883b422016-08-30 14:01:10 -0700723 return AOM_CODEC_INVALID_PARAM;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700724 }
725}
726
Yaowu Xuf883b422016-08-30 14:01:10 -0700727static aom_codec_err_t ctrl_copy_reference(aom_codec_alg_priv_t *ctx,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700728 va_list args) {
Thomas Daede497d1952017-08-08 17:33:06 -0700729 const av1_ref_frame_t *const frame = va_arg(args, av1_ref_frame_t *);
Urvang Joshi77853e52016-07-15 12:47:01 -0700730 if (frame) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700731 YV12_BUFFER_CONFIG sd;
Yaowu Xuf883b422016-08-30 14:01:10 -0700732 AVxWorker *const worker = ctx->frame_workers;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700733 FrameWorkerData *const frame_worker_data = (FrameWorkerData *)worker->data1;
734 image2yuvconfig(&frame->img, &sd);
Thomas Daede497d1952017-08-08 17:33:06 -0700735 return av1_copy_reference_dec(frame_worker_data->pbi, frame->idx, &sd);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700736 } else {
Yaowu Xuf883b422016-08-30 14:01:10 -0700737 return AOM_CODEC_INVALID_PARAM;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700738 }
739}
740
Yaowu Xuf883b422016-08-30 14:01:10 -0700741static aom_codec_err_t ctrl_get_reference(aom_codec_alg_priv_t *ctx,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700742 va_list args) {
Yaowu Xuf883b422016-08-30 14:01:10 -0700743 av1_ref_frame_t *data = va_arg(args, av1_ref_frame_t *);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700744 if (data) {
745 YV12_BUFFER_CONFIG *fb;
Yaowu Xuf883b422016-08-30 14:01:10 -0700746 AVxWorker *const worker = ctx->frame_workers;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700747 FrameWorkerData *const frame_worker_data = (FrameWorkerData *)worker->data1;
748 fb = get_ref_frame(&frame_worker_data->pbi->common, data->idx);
Yaowu Xuf883b422016-08-30 14:01:10 -0700749 if (fb == NULL) return AOM_CODEC_ERROR;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700750 yuvconfig2image(&data->img, fb, NULL);
Yaowu Xuf883b422016-08-30 14:01:10 -0700751 return AOM_CODEC_OK;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700752 } else {
Yaowu Xuf883b422016-08-30 14:01:10 -0700753 return AOM_CODEC_INVALID_PARAM;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700754 }
755}
756
Yaowu Xuf883b422016-08-30 14:01:10 -0700757static aom_codec_err_t ctrl_get_new_frame_image(aom_codec_alg_priv_t *ctx,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700758 va_list args) {
Yaowu Xuf883b422016-08-30 14:01:10 -0700759 aom_image_t *new_img = va_arg(args, aom_image_t *);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700760 if (new_img) {
761 YV12_BUFFER_CONFIG new_frame;
Yaowu Xuf883b422016-08-30 14:01:10 -0700762 AVxWorker *const worker = ctx->frame_workers;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700763 FrameWorkerData *const frame_worker_data = (FrameWorkerData *)worker->data1;
764
Yaowu Xuf883b422016-08-30 14:01:10 -0700765 if (av1_get_frame_to_show(frame_worker_data->pbi, &new_frame) == 0) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700766 yuvconfig2image(new_img, &new_frame, NULL);
Yaowu Xuf883b422016-08-30 14:01:10 -0700767 return AOM_CODEC_OK;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700768 } else {
Yaowu Xuf883b422016-08-30 14:01:10 -0700769 return AOM_CODEC_ERROR;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700770 }
771 } else {
Yaowu Xuf883b422016-08-30 14:01:10 -0700772 return AOM_CODEC_INVALID_PARAM;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700773 }
774}
775
Yunqing Wang20a336d2018-04-25 10:19:53 -0700776static aom_codec_err_t ctrl_copy_new_frame_image(aom_codec_alg_priv_t *ctx,
777 va_list args) {
778 aom_image_t *img = va_arg(args, aom_image_t *);
779 if (img) {
780 YV12_BUFFER_CONFIG new_frame;
781 AVxWorker *const worker = ctx->frame_workers;
782 FrameWorkerData *const frame_worker_data = (FrameWorkerData *)worker->data1;
783
784 if (av1_get_frame_to_show(frame_worker_data->pbi, &new_frame) == 0) {
785 YV12_BUFFER_CONFIG sd;
786 image2yuvconfig(img, &sd);
787 return av1_copy_new_frame_dec(&frame_worker_data->pbi->common, &new_frame,
788 &sd);
789 } else {
790 return AOM_CODEC_ERROR;
791 }
792 } else {
793 return AOM_CODEC_INVALID_PARAM;
794 }
795}
796
Yaowu Xuf883b422016-08-30 14:01:10 -0700797static aom_codec_err_t ctrl_set_postproc(aom_codec_alg_priv_t *ctx,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700798 va_list args) {
799 (void)ctx;
800 (void)args;
Yaowu Xuf883b422016-08-30 14:01:10 -0700801 return AOM_CODEC_INCAPABLE;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700802}
803
Yaowu Xuf883b422016-08-30 14:01:10 -0700804static aom_codec_err_t ctrl_set_dbg_options(aom_codec_alg_priv_t *ctx,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700805 va_list args) {
806 (void)ctx;
807 (void)args;
Yaowu Xuf883b422016-08-30 14:01:10 -0700808 return AOM_CODEC_INCAPABLE;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700809}
810
Yaowu Xuf883b422016-08-30 14:01:10 -0700811static aom_codec_err_t ctrl_get_last_ref_updates(aom_codec_alg_priv_t *ctx,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700812 va_list args) {
813 int *const update_info = va_arg(args, int *);
814
Yaowu Xuc27fc142016-08-22 16:08:15 -0700815 if (update_info) {
816 if (ctx->frame_workers) {
Yaowu Xuf883b422016-08-30 14:01:10 -0700817 AVxWorker *const worker = ctx->frame_workers;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700818 FrameWorkerData *const frame_worker_data =
819 (FrameWorkerData *)worker->data1;
820 *update_info = frame_worker_data->pbi->refresh_frame_flags;
Yaowu Xuf883b422016-08-30 14:01:10 -0700821 return AOM_CODEC_OK;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700822 } else {
Yaowu Xuf883b422016-08-30 14:01:10 -0700823 return AOM_CODEC_ERROR;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700824 }
825 }
826
Yaowu Xuf883b422016-08-30 14:01:10 -0700827 return AOM_CODEC_INVALID_PARAM;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700828}
829
Peter Boströma1f64322017-01-19 11:35:30 -0500830static aom_codec_err_t ctrl_get_last_quantizer(aom_codec_alg_priv_t *ctx,
831 va_list args) {
832 int *const arg = va_arg(args, int *);
833 if (arg == NULL) return AOM_CODEC_INVALID_PARAM;
834 *arg =
835 ((FrameWorkerData *)ctx->frame_workers[0].data1)->pbi->common.base_qindex;
836 return AOM_CODEC_OK;
837}
838
Yaowu Xuf883b422016-08-30 14:01:10 -0700839static aom_codec_err_t ctrl_get_frame_corrupted(aom_codec_alg_priv_t *ctx,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700840 va_list args) {
841 int *corrupted = va_arg(args, int *);
842
843 if (corrupted) {
844 if (ctx->frame_workers) {
Yaowu Xuf883b422016-08-30 14:01:10 -0700845 AVxWorker *const worker = ctx->frame_workers;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700846 FrameWorkerData *const frame_worker_data =
847 (FrameWorkerData *)worker->data1;
848 RefCntBuffer *const frame_bufs =
849 frame_worker_data->pbi->common.buffer_pool->frame_bufs;
850 if (frame_worker_data->pbi->common.frame_to_show == NULL)
Yaowu Xuf883b422016-08-30 14:01:10 -0700851 return AOM_CODEC_ERROR;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700852 if (ctx->last_show_frame >= 0)
853 *corrupted = frame_bufs[ctx->last_show_frame].buf.corrupted;
Yaowu Xuf883b422016-08-30 14:01:10 -0700854 return AOM_CODEC_OK;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700855 } else {
Yaowu Xuf883b422016-08-30 14:01:10 -0700856 return AOM_CODEC_ERROR;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700857 }
858 }
859
Yaowu Xuf883b422016-08-30 14:01:10 -0700860 return AOM_CODEC_INVALID_PARAM;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700861}
862
Yaowu Xuf883b422016-08-30 14:01:10 -0700863static aom_codec_err_t ctrl_get_frame_size(aom_codec_alg_priv_t *ctx,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700864 va_list args) {
865 int *const frame_size = va_arg(args, int *);
866
Yaowu Xuc27fc142016-08-22 16:08:15 -0700867 if (frame_size) {
868 if (ctx->frame_workers) {
Yaowu Xuf883b422016-08-30 14:01:10 -0700869 AVxWorker *const worker = ctx->frame_workers;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700870 FrameWorkerData *const frame_worker_data =
871 (FrameWorkerData *)worker->data1;
Yaowu Xuf883b422016-08-30 14:01:10 -0700872 const AV1_COMMON *const cm = &frame_worker_data->pbi->common;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700873 frame_size[0] = cm->width;
874 frame_size[1] = cm->height;
Yaowu Xuf883b422016-08-30 14:01:10 -0700875 return AOM_CODEC_OK;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700876 } else {
Yaowu Xuf883b422016-08-30 14:01:10 -0700877 return AOM_CODEC_ERROR;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700878 }
879 }
880
Yaowu Xuf883b422016-08-30 14:01:10 -0700881 return AOM_CODEC_INVALID_PARAM;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700882}
883
Yaowu Xuf883b422016-08-30 14:01:10 -0700884static aom_codec_err_t ctrl_get_render_size(aom_codec_alg_priv_t *ctx,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700885 va_list args) {
886 int *const render_size = va_arg(args, int *);
887
Yaowu Xuc27fc142016-08-22 16:08:15 -0700888 if (render_size) {
889 if (ctx->frame_workers) {
Yaowu Xuf883b422016-08-30 14:01:10 -0700890 AVxWorker *const worker = ctx->frame_workers;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700891 FrameWorkerData *const frame_worker_data =
892 (FrameWorkerData *)worker->data1;
Yaowu Xuf883b422016-08-30 14:01:10 -0700893 const AV1_COMMON *const cm = &frame_worker_data->pbi->common;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700894 render_size[0] = cm->render_width;
895 render_size[1] = cm->render_height;
Yaowu Xuf883b422016-08-30 14:01:10 -0700896 return AOM_CODEC_OK;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700897 } else {
Yaowu Xuf883b422016-08-30 14:01:10 -0700898 return AOM_CODEC_ERROR;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700899 }
900 }
901
Yaowu Xuf883b422016-08-30 14:01:10 -0700902 return AOM_CODEC_INVALID_PARAM;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700903}
904
Yaowu Xuf883b422016-08-30 14:01:10 -0700905static aom_codec_err_t ctrl_get_bit_depth(aom_codec_alg_priv_t *ctx,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700906 va_list args) {
907 unsigned int *const bit_depth = va_arg(args, unsigned int *);
Yaowu Xuf883b422016-08-30 14:01:10 -0700908 AVxWorker *const worker = &ctx->frame_workers[ctx->next_output_worker_id];
Yaowu Xuc27fc142016-08-22 16:08:15 -0700909
910 if (bit_depth) {
911 if (worker) {
912 FrameWorkerData *const frame_worker_data =
913 (FrameWorkerData *)worker->data1;
Yaowu Xuf883b422016-08-30 14:01:10 -0700914 const AV1_COMMON *const cm = &frame_worker_data->pbi->common;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700915 *bit_depth = cm->bit_depth;
Yaowu Xuf883b422016-08-30 14:01:10 -0700916 return AOM_CODEC_OK;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700917 } else {
Yaowu Xuf883b422016-08-30 14:01:10 -0700918 return AOM_CODEC_ERROR;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700919 }
920 }
921
Yaowu Xuf883b422016-08-30 14:01:10 -0700922 return AOM_CODEC_INVALID_PARAM;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700923}
924
Yaowu Xuf883b422016-08-30 14:01:10 -0700925static aom_codec_err_t ctrl_set_invert_tile_order(aom_codec_alg_priv_t *ctx,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700926 va_list args) {
927 ctx->invert_tile_order = va_arg(args, int);
Yaowu Xuf883b422016-08-30 14:01:10 -0700928 return AOM_CODEC_OK;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700929}
930
Yaowu Xuf883b422016-08-30 14:01:10 -0700931static aom_codec_err_t ctrl_set_byte_alignment(aom_codec_alg_priv_t *ctx,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700932 va_list args) {
933 const int legacy_byte_alignment = 0;
934 const int min_byte_alignment = 32;
935 const int max_byte_alignment = 1024;
936 const int byte_alignment = va_arg(args, int);
937
938 if (byte_alignment != legacy_byte_alignment &&
939 (byte_alignment < min_byte_alignment ||
940 byte_alignment > max_byte_alignment ||
941 (byte_alignment & (byte_alignment - 1)) != 0))
Yaowu Xuf883b422016-08-30 14:01:10 -0700942 return AOM_CODEC_INVALID_PARAM;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700943
944 ctx->byte_alignment = byte_alignment;
945 if (ctx->frame_workers) {
Yaowu Xuf883b422016-08-30 14:01:10 -0700946 AVxWorker *const worker = ctx->frame_workers;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700947 FrameWorkerData *const frame_worker_data = (FrameWorkerData *)worker->data1;
948 frame_worker_data->pbi->common.byte_alignment = byte_alignment;
949 }
Yaowu Xuf883b422016-08-30 14:01:10 -0700950 return AOM_CODEC_OK;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700951}
952
Yaowu Xuf883b422016-08-30 14:01:10 -0700953static aom_codec_err_t ctrl_set_skip_loop_filter(aom_codec_alg_priv_t *ctx,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700954 va_list args) {
955 ctx->skip_loop_filter = va_arg(args, int);
956
957 if (ctx->frame_workers) {
Yaowu Xuf883b422016-08-30 14:01:10 -0700958 AVxWorker *const worker = ctx->frame_workers;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700959 FrameWorkerData *const frame_worker_data = (FrameWorkerData *)worker->data1;
960 frame_worker_data->pbi->common.skip_loop_filter = ctx->skip_loop_filter;
961 }
962
Yaowu Xuf883b422016-08-30 14:01:10 -0700963 return AOM_CODEC_OK;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700964}
965
Nathan E. Eggec9862e02016-10-05 21:28:36 -0400966static aom_codec_err_t ctrl_get_accounting(aom_codec_alg_priv_t *ctx,
967 va_list args) {
968#if !CONFIG_ACCOUNTING
969 (void)ctx;
970 (void)args;
971 return AOM_CODEC_INCAPABLE;
972#else
973 if (ctx->frame_workers) {
974 AVxWorker *const worker = ctx->frame_workers;
975 FrameWorkerData *const frame_worker_data = (FrameWorkerData *)worker->data1;
976 AV1Decoder *pbi = frame_worker_data->pbi;
977 Accounting **acct = va_arg(args, Accounting **);
978 *acct = &pbi->accounting;
979 return AOM_CODEC_OK;
980 }
981 return AOM_CODEC_ERROR;
982#endif
983}
Yaowu Xuf883b422016-08-30 14:01:10 -0700984static aom_codec_err_t ctrl_set_decode_tile_row(aom_codec_alg_priv_t *ctx,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700985 va_list args) {
986 ctx->decode_tile_row = 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
Yaowu Xuf883b422016-08-30 14:01:10 -0700990static aom_codec_err_t ctrl_set_decode_tile_col(aom_codec_alg_priv_t *ctx,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700991 va_list args) {
992 ctx->decode_tile_col = va_arg(args, int);
Yaowu Xuf883b422016-08-30 14:01:10 -0700993 return AOM_CODEC_OK;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700994}
995
Yunqing Wang8ae64a92018-01-12 12:26:44 -0800996static aom_codec_err_t ctrl_set_tile_mode(aom_codec_alg_priv_t *ctx,
997 va_list args) {
998 ctx->tile_mode = va_arg(args, unsigned int);
999 return AOM_CODEC_OK;
1000}
1001
Soo-Chul Han29c46fb2018-03-23 16:02:00 -04001002static aom_codec_err_t ctrl_set_is_annexb(aom_codec_alg_priv_t *ctx,
1003 va_list args) {
1004 ctx->is_annexb = va_arg(args, unsigned int);
1005 return AOM_CODEC_OK;
1006}
1007
Frank Bossend8f457a2018-04-30 21:44:12 -04001008static aom_codec_err_t ctrl_set_operating_point(aom_codec_alg_priv_t *ctx,
1009 va_list args) {
1010 ctx->operating_point = va_arg(args, int);
1011 return AOM_CODEC_OK;
1012}
1013
Nathan E. Egge2cf03b12017-02-22 16:19:59 -05001014static aom_codec_err_t ctrl_set_inspection_callback(aom_codec_alg_priv_t *ctx,
1015 va_list args) {
1016#if !CONFIG_INSPECTION
1017 (void)ctx;
1018 (void)args;
1019 return AOM_CODEC_INCAPABLE;
1020#else
1021 aom_inspect_init *init = va_arg(args, aom_inspect_init *);
1022 ctx->inspect_cb = init->inspect_cb;
1023 ctx->inspect_ctx = init->inspect_ctx;
1024 return AOM_CODEC_OK;
1025#endif
1026}
1027
Yaowu Xuf883b422016-08-30 14:01:10 -07001028static aom_codec_ctrl_fn_map_t decoder_ctrl_maps[] = {
Thomas Daede497d1952017-08-08 17:33:06 -07001029 { AV1_COPY_REFERENCE, ctrl_copy_reference },
Yaowu Xuc27fc142016-08-22 16:08:15 -07001030
1031 // Setters
Thomas Daede497d1952017-08-08 17:33:06 -07001032 { AV1_SET_REFERENCE, ctrl_set_reference },
Yaowu Xuf883b422016-08-30 14:01:10 -07001033 { AOM_SET_POSTPROC, ctrl_set_postproc },
1034 { AOM_SET_DBG_COLOR_REF_FRAME, ctrl_set_dbg_options },
1035 { AOM_SET_DBG_COLOR_MB_MODES, ctrl_set_dbg_options },
1036 { AOM_SET_DBG_COLOR_B_MODES, ctrl_set_dbg_options },
1037 { AOM_SET_DBG_DISPLAY_MV, ctrl_set_dbg_options },
1038 { AV1_INVERT_TILE_DECODE_ORDER, ctrl_set_invert_tile_order },
Yaowu Xuf883b422016-08-30 14:01:10 -07001039 { AV1_SET_BYTE_ALIGNMENT, ctrl_set_byte_alignment },
1040 { AV1_SET_SKIP_LOOP_FILTER, ctrl_set_skip_loop_filter },
1041 { AV1_SET_DECODE_TILE_ROW, ctrl_set_decode_tile_row },
1042 { AV1_SET_DECODE_TILE_COL, ctrl_set_decode_tile_col },
Yunqing Wang8ae64a92018-01-12 12:26:44 -08001043 { AV1_SET_TILE_MODE, ctrl_set_tile_mode },
Soo-Chul Han29c46fb2018-03-23 16:02:00 -04001044 { AV1D_SET_IS_ANNEXB, ctrl_set_is_annexb },
Frank Bossend8f457a2018-04-30 21:44:12 -04001045 { AV1D_SET_OPERATING_POINT, ctrl_set_operating_point },
Nathan E. Egge2cf03b12017-02-22 16:19:59 -05001046 { AV1_SET_INSPECTION_CALLBACK, ctrl_set_inspection_callback },
Yaowu Xuc27fc142016-08-22 16:08:15 -07001047
1048 // Getters
Yaowu Xuf883b422016-08-30 14:01:10 -07001049 { AOMD_GET_FRAME_CORRUPTED, ctrl_get_frame_corrupted },
Peter Boströma1f64322017-01-19 11:35:30 -05001050 { AOMD_GET_LAST_QUANTIZER, ctrl_get_last_quantizer },
1051 { AOMD_GET_LAST_REF_UPDATES, ctrl_get_last_ref_updates },
Yaowu Xuf883b422016-08-30 14:01:10 -07001052 { AV1D_GET_BIT_DEPTH, ctrl_get_bit_depth },
Peter Boströma1f64322017-01-19 11:35:30 -05001053 { AV1D_GET_DISPLAY_SIZE, ctrl_get_render_size },
Yaowu Xuf883b422016-08-30 14:01:10 -07001054 { AV1D_GET_FRAME_SIZE, ctrl_get_frame_size },
Nathan E. Eggec9862e02016-10-05 21:28:36 -04001055 { AV1_GET_ACCOUNTING, ctrl_get_accounting },
Yaowu Xuf883b422016-08-30 14:01:10 -07001056 { AV1_GET_NEW_FRAME_IMAGE, ctrl_get_new_frame_image },
Yunqing Wang20a336d2018-04-25 10:19:53 -07001057 { AV1_COPY_NEW_FRAME_IMAGE, ctrl_copy_new_frame_image },
Peter Boströma1f64322017-01-19 11:35:30 -05001058 { AV1_GET_REFERENCE, ctrl_get_reference },
Yaowu Xuc27fc142016-08-22 16:08:15 -07001059
1060 { -1, NULL },
1061};
1062
1063#ifndef VERSION_STRING
1064#define VERSION_STRING
1065#endif
Yaowu Xuf883b422016-08-30 14:01:10 -07001066CODEC_INTERFACE(aom_codec_av1_dx) = {
1067 "AOMedia Project AV1 Decoder" VERSION_STRING,
1068 AOM_CODEC_INTERNAL_ABI_VERSION,
1069 AOM_CODEC_CAP_DECODER |
1070 AOM_CODEC_CAP_EXTERNAL_FRAME_BUFFER, // aom_codec_caps_t
1071 decoder_init, // aom_codec_init_fn_t
1072 decoder_destroy, // aom_codec_destroy_fn_t
1073 decoder_ctrl_maps, // aom_codec_ctrl_fn_map_t
Yaowu Xuc27fc142016-08-22 16:08:15 -07001074 {
1075 // NOLINT
Yaowu Xuf883b422016-08-30 14:01:10 -07001076 decoder_peek_si, // aom_codec_peek_si_fn_t
1077 decoder_get_si, // aom_codec_get_si_fn_t
1078 decoder_decode, // aom_codec_decode_fn_t
1079 decoder_get_frame, // aom_codec_frame_get_fn_t
1080 decoder_set_fb_fn, // aom_codec_set_fb_fn_t
Yaowu Xuc27fc142016-08-22 16:08:15 -07001081 },
1082 {
1083 // NOLINT
1084 0,
Yaowu Xuf883b422016-08-30 14:01:10 -07001085 NULL, // aom_codec_enc_cfg_map_t
1086 NULL, // aom_codec_encode_fn_t
1087 NULL, // aom_codec_get_cx_data_fn_t
1088 NULL, // aom_codec_enc_config_set_fn_t
1089 NULL, // aom_codec_get_global_headers_fn_t
1090 NULL, // aom_codec_get_preview_frame_fn_t
1091 NULL // aom_codec_enc_mr_get_mem_loc_fn_t
Yaowu Xuc27fc142016-08-22 16:08:15 -07001092 }
1093};