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