Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1 | /* |
Yaowu Xu | 9c01aa1 | 2016-09-01 14:32:49 -0700 | [diff] [blame] | 2 | * Copyright (c) 2016, Alliance for Open Media. All rights reserved |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3 | * |
Yaowu Xu | 9c01aa1 | 2016-09-01 14:32:49 -0700 | [diff] [blame] | 4 | * This source code is subject to the terms of the BSD 2 Clause License and |
| 5 | * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License |
| 6 | * was not distributed with this source code in the LICENSE file, you can |
| 7 | * obtain it at www.aomedia.org/license/software. If the Alliance for Open |
| 8 | * Media Patent License 1.0 was not distributed with this source code in the |
| 9 | * PATENTS file, you can obtain it at www.aomedia.org/license/patent. |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 10 | */ |
| 11 | |
| 12 | #include <stdlib.h> |
| 13 | #include <string.h> |
| 14 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 15 | #include "./aom_config.h" |
| 16 | #include "./aom_version.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 17 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 18 | #include "aom/internal/aom_codec_internal.h" |
| 19 | #include "aom/aomdx.h" |
| 20 | #include "aom/aom_decoder.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 21 | #include "aom_dsp/bitreader_buffer.h" |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 22 | #include "aom_dsp/aom_dsp_common.h" |
| 23 | #include "aom_util/aom_thread.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 24 | |
| 25 | #include "av1/common/alloccommon.h" |
| 26 | #include "av1/common/frame_buffers.h" |
| 27 | #include "av1/common/enums.h" |
| 28 | |
| 29 | #include "av1/decoder/decoder.h" |
| 30 | #include "av1/decoder/decodeframe.h" |
| 31 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 32 | #include "av1/av1_iface_common.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 33 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 34 | // This limit is due to framebuffer numbers. |
| 35 | // TODO(hkuang): Remove this limit after implementing ondemand framebuffers. |
| 36 | #define FRAME_CACHE_SIZE 6 // Cache maximum 6 decoded frames. |
| 37 | |
| 38 | typedef struct cache_frame { |
| 39 | int fb_idx; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 40 | aom_image_t img; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 41 | } cache_frame; |
| 42 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 43 | struct aom_codec_alg_priv { |
| 44 | aom_codec_priv_t base; |
| 45 | aom_codec_dec_cfg_t cfg; |
Ralph Giles | afe71d9 | 2017-05-03 13:18:57 -0700 | [diff] [blame] | 46 | aom_codec_stream_info_t si; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 47 | int postproc_cfg_set; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 48 | aom_postproc_cfg_t postproc_cfg; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 49 | aom_image_t img; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 50 | int img_avail; |
| 51 | int flushed; |
| 52 | int invert_tile_order; |
| 53 | int last_show_frame; // Index of last output frame. |
| 54 | int byte_alignment; |
| 55 | int skip_loop_filter; |
| 56 | int decode_tile_row; |
| 57 | int decode_tile_col; |
Yunqing Wang | 8ae64a9 | 2018-01-12 12:26:44 -0800 | [diff] [blame^] | 58 | unsigned int tile_mode; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 59 | |
| 60 | // Frame parallel related. |
| 61 | int frame_parallel_decode; // frame-based threading. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 62 | AVxWorker *frame_workers; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 63 | int num_frame_workers; |
| 64 | int next_submit_worker_id; |
| 65 | int last_submit_worker_id; |
| 66 | int next_output_worker_id; |
| 67 | int available_threads; |
| 68 | cache_frame frame_cache[FRAME_CACHE_SIZE]; |
| 69 | int frame_cache_write; |
| 70 | int frame_cache_read; |
| 71 | int num_cache_frames; |
| 72 | int need_resync; // wait for key/intra-only frame |
| 73 | // BufferPool that holds all reference frames. Shared by all the FrameWorkers. |
| 74 | BufferPool *buffer_pool; |
| 75 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 76 | // External frame buffer info to save for AV1 common. |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 77 | void *ext_priv; // Private data associated with the external frame buffers. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 78 | aom_get_frame_buffer_cb_fn_t get_ext_fb_cb; |
| 79 | aom_release_frame_buffer_cb_fn_t release_ext_fb_cb; |
Nathan E. Egge | 2cf03b1 | 2017-02-22 16:19:59 -0500 | [diff] [blame] | 80 | |
| 81 | #if CONFIG_INSPECTION |
| 82 | aom_inspect_cb inspect_cb; |
| 83 | void *inspect_ctx; |
| 84 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 85 | }; |
| 86 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 87 | static aom_codec_err_t decoder_init(aom_codec_ctx_t *ctx, |
| 88 | aom_codec_priv_enc_mr_cfg_t *data) { |
| 89 | // This function only allocates space for the aom_codec_alg_priv_t |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 90 | // structure. More memory may be required at the time the stream |
| 91 | // information becomes known. |
| 92 | (void)data; |
| 93 | |
| 94 | if (!ctx->priv) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 95 | aom_codec_alg_priv_t *const priv = |
| 96 | (aom_codec_alg_priv_t *)aom_calloc(1, sizeof(*priv)); |
| 97 | if (priv == NULL) return AOM_CODEC_MEM_ERROR; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 98 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 99 | ctx->priv = (aom_codec_priv_t *)priv; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 100 | ctx->priv->init_flags = ctx->init_flags; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 101 | priv->flushed = 0; |
| 102 | // Only do frame parallel decode when threads > 1. |
| 103 | priv->frame_parallel_decode = |
| 104 | (ctx->config.dec && (ctx->config.dec->threads > 1) && |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 105 | (ctx->init_flags & AOM_CODEC_USE_FRAME_THREADING)) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 106 | ? 1 |
| 107 | : 0; |
Thomas Daede | 85b4900 | 2017-07-10 17:43:06 -0700 | [diff] [blame] | 108 | // TODO(tdaede): this should not be exposed to the API |
| 109 | priv->cfg.allow_lowbitdepth = CONFIG_LOWBITDEPTH; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 110 | if (ctx->config.dec) { |
| 111 | priv->cfg = *ctx->config.dec; |
| 112 | ctx->config.dec = &priv->cfg; |
| 113 | } |
| 114 | } |
| 115 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 116 | return AOM_CODEC_OK; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 117 | } |
| 118 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 119 | static aom_codec_err_t decoder_destroy(aom_codec_alg_priv_t *ctx) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 120 | if (ctx->frame_workers != NULL) { |
| 121 | int i; |
| 122 | for (i = 0; i < ctx->num_frame_workers; ++i) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 123 | AVxWorker *const worker = &ctx->frame_workers[i]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 124 | FrameWorkerData *const frame_worker_data = |
| 125 | (FrameWorkerData *)worker->data1; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 126 | aom_get_worker_interface()->end(worker); |
Yaowu Xu | 568bf10 | 2017-10-17 12:43:27 -0700 | [diff] [blame] | 127 | #if CONFIG_MFMV |
| 128 | aom_free(frame_worker_data->pbi->common.tpl_mvs); |
| 129 | frame_worker_data->pbi->common.tpl_mvs = NULL; |
| 130 | #endif |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 131 | av1_remove_common(&frame_worker_data->pbi->common); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 132 | #if CONFIG_LOOP_RESTORATION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 133 | av1_free_restoration_buffers(&frame_worker_data->pbi->common); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 134 | #endif // CONFIG_LOOP_RESTORATION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 135 | av1_decoder_remove(frame_worker_data->pbi); |
| 136 | aom_free(frame_worker_data->scratch_buffer); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 137 | #if CONFIG_MULTITHREAD |
| 138 | pthread_mutex_destroy(&frame_worker_data->stats_mutex); |
| 139 | pthread_cond_destroy(&frame_worker_data->stats_cond); |
| 140 | #endif |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 141 | aom_free(frame_worker_data); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 142 | } |
| 143 | #if CONFIG_MULTITHREAD |
| 144 | pthread_mutex_destroy(&ctx->buffer_pool->pool_mutex); |
| 145 | #endif |
| 146 | } |
| 147 | |
| 148 | if (ctx->buffer_pool) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 149 | av1_free_ref_frame_buffers(ctx->buffer_pool); |
| 150 | av1_free_internal_frame_buffers(&ctx->buffer_pool->int_frame_buffers); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 151 | } |
| 152 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 153 | aom_free(ctx->frame_workers); |
| 154 | aom_free(ctx->buffer_pool); |
| 155 | aom_free(ctx); |
| 156 | return AOM_CODEC_OK; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 157 | } |
| 158 | |
Soo-Chul Han | 65c00ae1 | 2017-09-07 13:12:35 -0400 | [diff] [blame] | 159 | #if !CONFIG_OBU |
Debargha Mukherjee | f9a50ea | 2018-01-09 22:28:20 -0800 | [diff] [blame] | 160 | static aom_bit_depth_t parse_bitdepth(BITSTREAM_PROFILE profile, |
| 161 | struct aom_read_bit_buffer *rb) { |
| 162 | aom_bit_depth_t bit_depth = aom_rb_read_bit(rb) ? AOM_BITS_10 : AOM_BITS_8; |
| 163 | if (profile < PROFILE_2 || bit_depth == AOM_BITS_8) { |
| 164 | return bit_depth; |
| 165 | } |
| 166 | bit_depth = aom_rb_read_bit(rb) ? AOM_BITS_12 : AOM_BITS_10; |
| 167 | return bit_depth; |
| 168 | } |
| 169 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 170 | static int parse_bitdepth_colorspace_sampling(BITSTREAM_PROFILE profile, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 171 | struct aom_read_bit_buffer *rb) { |
Andrey Norkin | 9e69463 | 2017-12-21 18:50:57 -0800 | [diff] [blame] | 172 | #if CONFIG_CICP |
| 173 | aom_color_primaries_t color_primaries; |
| 174 | aom_transfer_characteristics_t transfer_characteristics; |
| 175 | aom_matrix_coefficients_t matrix_coefficients; |
Debargha Mukherjee | f340fec | 2018-01-10 18:12:22 -0800 | [diff] [blame] | 176 | #else |
| 177 | aom_color_space_t color_space = AOM_CS_UNKNOWN; |
Debargha Mukherjee | f9a50ea | 2018-01-09 22:28:20 -0800 | [diff] [blame] | 178 | #endif // CONFIG_CICP |
anorkin | 76fb126 | 2017-03-22 15:12:12 -0700 | [diff] [blame] | 179 | int subsampling_x = 0; |
| 180 | int subsampling_y = 0; |
Debargha Mukherjee | f340fec | 2018-01-10 18:12:22 -0800 | [diff] [blame] | 181 | (void)subsampling_x; |
| 182 | (void)subsampling_y; |
anorkin | 76fb126 | 2017-03-22 15:12:12 -0700 | [diff] [blame] | 183 | |
Debargha Mukherjee | f9a50ea | 2018-01-09 22:28:20 -0800 | [diff] [blame] | 184 | aom_bit_depth_t bit_depth = parse_bitdepth(profile, rb); |
Debargha Mukherjee | f9a50ea | 2018-01-09 22:28:20 -0800 | [diff] [blame] | 185 | #if CONFIG_MONO_VIDEO |
| 186 | // Monochrome bit |
| 187 | const int is_monochrome = profile != PROFILE_1 ? aom_rb_read_bit(rb) : 0; |
Debargha Mukherjee | f9a50ea | 2018-01-09 22:28:20 -0800 | [diff] [blame] | 188 | #else |
| 189 | const int is_monochrome = 0; |
| 190 | #endif // CONFIG_MONO_VIDEO |
| 191 | |
Andrey Norkin | 9e69463 | 2017-12-21 18:50:57 -0800 | [diff] [blame] | 192 | #if CONFIG_CICP |
| 193 | int color_description_present_flag = aom_rb_read_bit(rb); |
| 194 | if (color_description_present_flag) { |
| 195 | color_primaries = (aom_color_primaries_t)aom_rb_read_literal(rb, 8); |
| 196 | transfer_characteristics = |
| 197 | (aom_transfer_characteristics_t)aom_rb_read_literal(rb, 8); |
| 198 | matrix_coefficients = (aom_matrix_coefficients_t)aom_rb_read_literal(rb, 8); |
| 199 | } else { |
| 200 | color_primaries = AOM_CICP_CP_UNSPECIFIED; |
| 201 | transfer_characteristics = AOM_CICP_TC_UNSPECIFIED; |
| 202 | matrix_coefficients = AOM_CICP_MC_UNSPECIFIED; |
| 203 | } |
| 204 | #else |
anorkin | 76fb126 | 2017-03-22 15:12:12 -0700 | [diff] [blame] | 205 | #if CONFIG_COLORSPACE_HEADERS |
Debargha Mukherjee | f9a50ea | 2018-01-09 22:28:20 -0800 | [diff] [blame] | 206 | if (!is_monochrome) { |
| 207 | color_space = (aom_color_space_t)aom_rb_read_literal(rb, 5); |
| 208 | } |
anorkin | 76fb126 | 2017-03-22 15:12:12 -0700 | [diff] [blame] | 209 | rb->bit_offset += 5; // Transfer function |
| 210 | #else |
Debargha Mukherjee | f9a50ea | 2018-01-09 22:28:20 -0800 | [diff] [blame] | 211 | if (!is_monochrome) { |
| 212 | color_space = (aom_color_space_t)aom_rb_read_literal(rb, 4); |
| 213 | } |
| 214 | #endif // CONFIG_COLORSPACE_HEADERS |
| 215 | #endif // CONFIG_CICP |
Debargha Mukherjee | e526769 | 2018-01-16 09:41:15 -0800 | [diff] [blame] | 216 | #if CONFIG_MONO_VIDEO |
| 217 | if (is_monochrome) return 1; |
| 218 | #endif // CONFIG_MONO_VIDEO |
Andrey Norkin | 9e69463 | 2017-12-21 18:50:57 -0800 | [diff] [blame] | 219 | #if CONFIG_CICP |
| 220 | if (color_primaries == AOM_CICP_CP_BT_709 && |
| 221 | transfer_characteristics == AOM_CICP_TC_SRGB && |
| 222 | matrix_coefficients == AOM_CICP_MC_IDENTITY) { // it would be better to |
| 223 | // remove this dependency |
| 224 | // too |
| 225 | #else |
Imdad Sardharwalla | 317002f | 2017-12-05 16:24:56 +0000 | [diff] [blame] | 226 | if (color_space == AOM_CS_SRGB) { |
Debargha Mukherjee | f9a50ea | 2018-01-09 22:28:20 -0800 | [diff] [blame] | 227 | #endif // CONFIG_CICP |
| 228 | if (!(profile == PROFILE_1 || |
| 229 | (profile == PROFILE_2 && bit_depth == AOM_BITS_12))) { |
Imdad Sardharwalla | 317002f | 2017-12-05 16:24:56 +0000 | [diff] [blame] | 230 | return 0; |
| 231 | } |
Imdad Sardharwalla | 317002f | 2017-12-05 16:24:56 +0000 | [diff] [blame] | 232 | } else { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 233 | rb->bit_offset += 1; // [16,235] (including xvycc) vs [0,255] range. |
anorkin | 76fb126 | 2017-03-22 15:12:12 -0700 | [diff] [blame] | 234 | |
Debargha Mukherjee | f9a50ea | 2018-01-09 22:28:20 -0800 | [diff] [blame] | 235 | if (profile == PROFILE_0) { |
anorkin | 76fb126 | 2017-03-22 15:12:12 -0700 | [diff] [blame] | 236 | subsampling_x = 1; |
| 237 | subsampling_y = 1; |
Debargha Mukherjee | f9a50ea | 2018-01-09 22:28:20 -0800 | [diff] [blame] | 238 | } else if (profile == PROFILE_1) { |
| 239 | subsampling_x = 0; |
| 240 | subsampling_y = 0; |
| 241 | } else if (profile == PROFILE_2) { |
| 242 | if (bit_depth == AOM_BITS_12) { |
| 243 | subsampling_x = aom_rb_read_bit(rb); |
David Barker | 0c3545b | 2018-01-16 17:32:23 +0000 | [diff] [blame] | 244 | if (subsampling_x == 0) |
| 245 | subsampling_y = 0; |
| 246 | else |
| 247 | subsampling_y = aom_rb_read_bit(rb); |
Debargha Mukherjee | f9a50ea | 2018-01-09 22:28:20 -0800 | [diff] [blame] | 248 | } else { |
| 249 | subsampling_x = 1; |
| 250 | subsampling_y = 0; |
| 251 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 252 | } |
Debargha Mukherjee | f9a50ea | 2018-01-09 22:28:20 -0800 | [diff] [blame] | 253 | #if CONFIG_COLORSPACE_HEADERS |
anorkin | 76fb126 | 2017-03-22 15:12:12 -0700 | [diff] [blame] | 254 | if (subsampling_x == 1 && subsampling_y == 1) { |
Debargha Mukherjee | f9a50ea | 2018-01-09 22:28:20 -0800 | [diff] [blame] | 255 | rb->bit_offset += 2; // chroma_sample_position |
anorkin | 76fb126 | 2017-03-22 15:12:12 -0700 | [diff] [blame] | 256 | } |
Debargha Mukherjee | f9a50ea | 2018-01-09 22:28:20 -0800 | [diff] [blame] | 257 | #endif // CONFIG_COLORSPACE_HEADERS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 258 | } |
Debargha Mukherjee | f9a50ea | 2018-01-09 22:28:20 -0800 | [diff] [blame] | 259 | #if CONFIG_EXT_QM |
| 260 | rb->bit_offset += 1; // separate_uv_delta_q |
| 261 | #endif // CONFIG_EXT_QM |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 262 | return 1; |
| 263 | } |
Soo-Chul Han | 65c00ae1 | 2017-09-07 13:12:35 -0400 | [diff] [blame] | 264 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 265 | |
Sebastien Alaiwan | 2b1ec18 | 2017-12-21 09:38:27 +0100 | [diff] [blame] | 266 | static aom_codec_err_t decoder_peek_si_internal(const uint8_t *data, |
| 267 | unsigned int data_sz, |
| 268 | aom_codec_stream_info_t *si, |
| 269 | int *is_intra_only) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 270 | int intra_only_flag = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 271 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 272 | if (data + data_sz <= data) return AOM_CODEC_INVALID_PARAM; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 273 | |
| 274 | si->is_kf = 0; |
| 275 | si->w = si->h = 0; |
| 276 | |
Sebastien Alaiwan | 6bec6ec | 2017-08-07 09:37:52 +0200 | [diff] [blame] | 277 | // skip a potential superframe index |
| 278 | { |
| 279 | uint32_t frame_sizes[8]; |
| 280 | int frame_count; |
| 281 | int index_size = 0; |
Sebastien Alaiwan | 2b1ec18 | 2017-12-21 09:38:27 +0100 | [diff] [blame] | 282 | aom_codec_err_t res = av1_parse_superframe_index(data, data_sz, frame_sizes, |
| 283 | &frame_count, &index_size); |
Sebastien Alaiwan | 6bec6ec | 2017-08-07 09:37:52 +0200 | [diff] [blame] | 284 | if (res != AOM_CODEC_OK) return res; |
| 285 | |
| 286 | data += index_size; |
| 287 | data_sz -= index_size; |
Soo-Chul Han | 65c00ae1 | 2017-09-07 13:12:35 -0400 | [diff] [blame] | 288 | #if CONFIG_OBU |
| 289 | if (data + data_sz <= data) return AOM_CODEC_INVALID_PARAM; |
| 290 | #endif |
Sebastien Alaiwan | 6bec6ec | 2017-08-07 09:37:52 +0200 | [diff] [blame] | 291 | } |
| 292 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 293 | { |
Soo-Chul Han | 65c00ae1 | 2017-09-07 13:12:35 -0400 | [diff] [blame] | 294 | #if CONFIG_OBU |
| 295 | // Proper fix needed |
| 296 | si->is_kf = 1; |
| 297 | intra_only_flag = 1; |
| 298 | si->h = 1; |
Soo-Chul Han | 65c00ae1 | 2017-09-07 13:12:35 -0400 | [diff] [blame] | 299 | #else |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 300 | int show_frame; |
| 301 | int error_resilient; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 302 | struct aom_read_bit_buffer rb = { data, data + data_sz, 0, NULL, NULL }; |
| 303 | const int frame_marker = aom_rb_read_literal(&rb, 2); |
| 304 | const BITSTREAM_PROFILE profile = av1_read_profile(&rb); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 305 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 306 | if (frame_marker != AOM_FRAME_MARKER) return AOM_CODEC_UNSUP_BITSTREAM; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 307 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 308 | if (profile >= MAX_PROFILES) return AOM_CODEC_UNSUP_BITSTREAM; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 309 | |
| 310 | if ((profile >= 2 && data_sz <= 1) || data_sz < 1) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 311 | return AOM_CODEC_UNSUP_BITSTREAM; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 312 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 313 | if (aom_rb_read_bit(&rb)) { // show an existing frame |
| 314 | aom_rb_read_literal(&rb, 3); // Frame buffer to show. |
| 315 | return AOM_CODEC_OK; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 316 | } |
| 317 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 318 | if (data_sz <= 8) return AOM_CODEC_UNSUP_BITSTREAM; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 319 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 320 | si->is_kf = !aom_rb_read_bit(&rb); |
| 321 | show_frame = aom_rb_read_bit(&rb); |
Debargha Mukherjee | 778023d | 2017-09-26 17:50:27 -0700 | [diff] [blame] | 322 | if (!si->is_kf) { |
| 323 | if (!show_frame) intra_only_flag = show_frame ? 0 : aom_rb_read_bit(&rb); |
| 324 | } |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 325 | error_resilient = aom_rb_read_bit(&rb); |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 326 | #if CONFIG_REFERENCE_BUFFER |
Rupert Swarbrick | e0b1599 | 2017-11-09 15:04:32 +0000 | [diff] [blame] | 327 | SequenceHeader seq_params; |
| 328 | memset(&seq_params, 0, sizeof(seq_params)); |
Debargha Mukherjee | 778023d | 2017-09-26 17:50:27 -0700 | [diff] [blame] | 329 | if (si->is_kf) { |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 330 | /* TODO: Move outside frame loop or inside key-frame branch */ |
David Barker | 5e70a11 | 2017-10-03 14:28:17 +0100 | [diff] [blame] | 331 | read_sequence_header(&seq_params, &rb); |
Debargha Mukherjee | 778023d | 2017-09-26 17:50:27 -0700 | [diff] [blame] | 332 | } |
| 333 | #endif // CONFIG_REFERENCE_BUFFER |
Arild Fuldseth (arilfuld) | 7193f02 | 2017-10-30 12:24:57 +0100 | [diff] [blame] | 334 | |
Debargha Mukherjee | 778023d | 2017-09-26 17:50:27 -0700 | [diff] [blame] | 335 | #if CONFIG_REFERENCE_BUFFER |
David Barker | 5e70a11 | 2017-10-03 14:28:17 +0100 | [diff] [blame] | 336 | if (seq_params.frame_id_numbers_present_flag) { |
Frederic Barbier | e83fcfe | 2017-10-13 10:37:50 +0200 | [diff] [blame] | 337 | aom_rb_read_literal(&rb, seq_params.frame_id_length); |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 338 | } |
Debargha Mukherjee | 778023d | 2017-09-26 17:50:27 -0700 | [diff] [blame] | 339 | #endif // CONFIG_REFERENCE_BUFFER |
Arild Fuldseth (arilfuld) | 7193f02 | 2017-10-30 12:24:57 +0100 | [diff] [blame] | 340 | |
| 341 | #if CONFIG_FRAME_SIZE |
| 342 | int frame_size_override_flag = aom_rb_read_bit(&rb); |
| 343 | #endif |
| 344 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 345 | if (si->is_kf) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 346 | if (!parse_bitdepth_colorspace_sampling(profile, &rb)) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 347 | return AOM_CODEC_UNSUP_BITSTREAM; |
Arild Fuldseth (arilfuld) | 7193f02 | 2017-10-30 12:24:57 +0100 | [diff] [blame] | 348 | #if CONFIG_FRAME_SIZE |
| 349 | if (frame_size_override_flag) { |
| 350 | int num_bits_width = seq_params.num_bits_width; |
| 351 | int num_bits_height = seq_params.num_bits_height; |
| 352 | av1_read_frame_size(&rb, num_bits_width, num_bits_height, (int *)&si->w, |
| 353 | (int *)&si->h); |
| 354 | } else { |
| 355 | si->w = seq_params.max_frame_width; |
| 356 | si->h = seq_params.max_frame_height; |
| 357 | } |
| 358 | #else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 359 | av1_read_frame_size(&rb, (int *)&si->w, (int *)&si->h); |
Arild Fuldseth (arilfuld) | 7193f02 | 2017-10-30 12:24:57 +0100 | [diff] [blame] | 360 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 361 | } else { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 362 | rb.bit_offset += error_resilient ? 0 : 2; // reset_frame_context |
| 363 | |
| 364 | if (intra_only_flag) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 365 | if (profile > PROFILE_0) { |
| 366 | if (!parse_bitdepth_colorspace_sampling(profile, &rb)) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 367 | return AOM_CODEC_UNSUP_BITSTREAM; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 368 | } |
| 369 | rb.bit_offset += REF_FRAMES; // refresh_frame_flags |
Arild Fuldseth (arilfuld) | 7193f02 | 2017-10-30 12:24:57 +0100 | [diff] [blame] | 370 | #if CONFIG_FRAME_SIZE |
| 371 | if (frame_size_override_flag) { |
| 372 | int num_bits_width = seq_params.num_bits_width; |
| 373 | int num_bits_height = seq_params.num_bits_height; |
| 374 | av1_read_frame_size(&rb, num_bits_width, num_bits_height, |
| 375 | (int *)&si->w, (int *)&si->h); |
| 376 | } else { |
| 377 | si->w = seq_params.max_frame_width; |
| 378 | si->h = seq_params.max_frame_height; |
| 379 | } |
| 380 | #else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 381 | av1_read_frame_size(&rb, (int *)&si->w, (int *)&si->h); |
Arild Fuldseth (arilfuld) | 7193f02 | 2017-10-30 12:24:57 +0100 | [diff] [blame] | 382 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 383 | } |
| 384 | } |
Debargha Mukherjee | 778023d | 2017-09-26 17:50:27 -0700 | [diff] [blame] | 385 | #endif // CONFIG_OBU |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 386 | } |
| 387 | if (is_intra_only != NULL) *is_intra_only = intra_only_flag; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 388 | return AOM_CODEC_OK; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 389 | } |
| 390 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 391 | static aom_codec_err_t decoder_peek_si(const uint8_t *data, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 392 | unsigned int data_sz, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 393 | aom_codec_stream_info_t *si) { |
Sebastien Alaiwan | 2b1ec18 | 2017-12-21 09:38:27 +0100 | [diff] [blame] | 394 | return decoder_peek_si_internal(data, data_sz, si, NULL); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 395 | } |
| 396 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 397 | static aom_codec_err_t decoder_get_si(aom_codec_alg_priv_t *ctx, |
| 398 | aom_codec_stream_info_t *si) { |
Ralph Giles | afe71d9 | 2017-05-03 13:18:57 -0700 | [diff] [blame] | 399 | memcpy(si, &ctx->si, sizeof(*si)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 400 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 401 | return AOM_CODEC_OK; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 402 | } |
| 403 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 404 | static void set_error_detail(aom_codec_alg_priv_t *ctx, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 405 | const char *const error) { |
| 406 | ctx->base.err_detail = error; |
| 407 | } |
| 408 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 409 | static aom_codec_err_t update_error_state( |
| 410 | aom_codec_alg_priv_t *ctx, const struct aom_internal_error_info *error) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 411 | if (error->error_code) |
| 412 | set_error_detail(ctx, error->has_detail ? error->detail : NULL); |
| 413 | |
| 414 | return error->error_code; |
| 415 | } |
| 416 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 417 | static void init_buffer_callbacks(aom_codec_alg_priv_t *ctx) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 418 | int i; |
| 419 | |
| 420 | for (i = 0; i < ctx->num_frame_workers; ++i) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 421 | AVxWorker *const worker = &ctx->frame_workers[i]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 422 | FrameWorkerData *const frame_worker_data = (FrameWorkerData *)worker->data1; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 423 | AV1_COMMON *const cm = &frame_worker_data->pbi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 424 | BufferPool *const pool = cm->buffer_pool; |
| 425 | |
| 426 | cm->new_fb_idx = INVALID_IDX; |
| 427 | cm->byte_alignment = ctx->byte_alignment; |
| 428 | cm->skip_loop_filter = ctx->skip_loop_filter; |
| 429 | |
| 430 | if (ctx->get_ext_fb_cb != NULL && ctx->release_ext_fb_cb != NULL) { |
| 431 | pool->get_fb_cb = ctx->get_ext_fb_cb; |
| 432 | pool->release_fb_cb = ctx->release_ext_fb_cb; |
| 433 | pool->cb_priv = ctx->ext_priv; |
| 434 | } else { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 435 | pool->get_fb_cb = av1_get_frame_buffer; |
| 436 | pool->release_fb_cb = av1_release_frame_buffer; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 437 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 438 | if (av1_alloc_internal_frame_buffers(&pool->int_frame_buffers)) |
| 439 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 440 | "Failed to initialize internal frame buffers"); |
| 441 | |
| 442 | pool->cb_priv = &pool->int_frame_buffers; |
| 443 | } |
| 444 | } |
| 445 | } |
| 446 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 447 | static void set_default_ppflags(aom_postproc_cfg_t *cfg) { |
| 448 | cfg->post_proc_flag = AOM_DEBLOCK | AOM_DEMACROBLOCK; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 449 | cfg->deblocking_level = 4; |
| 450 | cfg->noise_level = 0; |
| 451 | } |
| 452 | |
| 453 | static int frame_worker_hook(void *arg1, void *arg2) { |
| 454 | FrameWorkerData *const frame_worker_data = (FrameWorkerData *)arg1; |
| 455 | const uint8_t *data = frame_worker_data->data; |
| 456 | (void)arg2; |
| 457 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 458 | frame_worker_data->result = av1_receive_compressed_data( |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 459 | frame_worker_data->pbi, frame_worker_data->data_size, &data); |
| 460 | frame_worker_data->data_end = data; |
| 461 | |
| 462 | if (frame_worker_data->pbi->common.frame_parallel_decode) { |
| 463 | // In frame parallel decoding, a worker thread must successfully decode all |
| 464 | // the compressed data. |
| 465 | if (frame_worker_data->result != 0 || |
| 466 | frame_worker_data->data + frame_worker_data->data_size - 1 > data) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 467 | AVxWorker *const worker = frame_worker_data->pbi->frame_worker_owner; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 468 | BufferPool *const pool = frame_worker_data->pbi->common.buffer_pool; |
| 469 | // Signal all the other threads that are waiting for this frame. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 470 | av1_frameworker_lock_stats(worker); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 471 | frame_worker_data->frame_context_ready = 1; |
| 472 | lock_buffer_pool(pool); |
| 473 | frame_worker_data->pbi->cur_buf->buf.corrupted = 1; |
| 474 | unlock_buffer_pool(pool); |
| 475 | frame_worker_data->pbi->need_resync = 1; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 476 | av1_frameworker_signal_stats(worker); |
| 477 | av1_frameworker_unlock_stats(worker); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 478 | return 0; |
| 479 | } |
| 480 | } else if (frame_worker_data->result != 0) { |
| 481 | // Check decode result in serial decode. |
| 482 | frame_worker_data->pbi->cur_buf->buf.corrupted = 1; |
| 483 | frame_worker_data->pbi->need_resync = 1; |
| 484 | } |
| 485 | return !frame_worker_data->result; |
| 486 | } |
| 487 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 488 | static aom_codec_err_t init_decoder(aom_codec_alg_priv_t *ctx) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 489 | int i; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 490 | const AVxWorkerInterface *const winterface = aom_get_worker_interface(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 491 | |
| 492 | ctx->last_show_frame = -1; |
| 493 | ctx->next_submit_worker_id = 0; |
| 494 | ctx->last_submit_worker_id = 0; |
| 495 | ctx->next_output_worker_id = 0; |
| 496 | ctx->frame_cache_read = 0; |
| 497 | ctx->frame_cache_write = 0; |
| 498 | ctx->num_cache_frames = 0; |
| 499 | ctx->need_resync = 1; |
| 500 | ctx->num_frame_workers = |
| 501 | (ctx->frame_parallel_decode == 1) ? ctx->cfg.threads : 1; |
| 502 | if (ctx->num_frame_workers > MAX_DECODE_THREADS) |
| 503 | ctx->num_frame_workers = MAX_DECODE_THREADS; |
| 504 | ctx->available_threads = ctx->num_frame_workers; |
| 505 | ctx->flushed = 0; |
| 506 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 507 | ctx->buffer_pool = (BufferPool *)aom_calloc(1, sizeof(BufferPool)); |
| 508 | if (ctx->buffer_pool == NULL) return AOM_CODEC_MEM_ERROR; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 509 | |
| 510 | #if CONFIG_MULTITHREAD |
| 511 | if (pthread_mutex_init(&ctx->buffer_pool->pool_mutex, NULL)) { |
| 512 | set_error_detail(ctx, "Failed to allocate buffer pool mutex"); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 513 | return AOM_CODEC_MEM_ERROR; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 514 | } |
| 515 | #endif |
| 516 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 517 | ctx->frame_workers = (AVxWorker *)aom_malloc(ctx->num_frame_workers * |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 518 | sizeof(*ctx->frame_workers)); |
| 519 | if (ctx->frame_workers == NULL) { |
| 520 | set_error_detail(ctx, "Failed to allocate frame_workers"); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 521 | return AOM_CODEC_MEM_ERROR; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 522 | } |
| 523 | |
| 524 | for (i = 0; i < ctx->num_frame_workers; ++i) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 525 | AVxWorker *const worker = &ctx->frame_workers[i]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 526 | FrameWorkerData *frame_worker_data = NULL; |
| 527 | winterface->init(worker); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 528 | worker->data1 = aom_memalign(32, sizeof(FrameWorkerData)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 529 | if (worker->data1 == NULL) { |
| 530 | set_error_detail(ctx, "Failed to allocate frame_worker_data"); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 531 | return AOM_CODEC_MEM_ERROR; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 532 | } |
| 533 | frame_worker_data = (FrameWorkerData *)worker->data1; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 534 | frame_worker_data->pbi = av1_decoder_create(ctx->buffer_pool); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 535 | if (frame_worker_data->pbi == NULL) { |
| 536 | set_error_detail(ctx, "Failed to allocate frame_worker_data"); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 537 | return AOM_CODEC_MEM_ERROR; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 538 | } |
| 539 | frame_worker_data->pbi->frame_worker_owner = worker; |
| 540 | frame_worker_data->worker_id = i; |
| 541 | frame_worker_data->scratch_buffer = NULL; |
| 542 | frame_worker_data->scratch_buffer_size = 0; |
| 543 | frame_worker_data->frame_context_ready = 0; |
| 544 | frame_worker_data->received_frame = 0; |
| 545 | #if CONFIG_MULTITHREAD |
| 546 | if (pthread_mutex_init(&frame_worker_data->stats_mutex, NULL)) { |
| 547 | set_error_detail(ctx, "Failed to allocate frame_worker_data mutex"); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 548 | return AOM_CODEC_MEM_ERROR; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 549 | } |
| 550 | |
| 551 | if (pthread_cond_init(&frame_worker_data->stats_cond, NULL)) { |
| 552 | set_error_detail(ctx, "Failed to allocate frame_worker_data cond"); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 553 | return AOM_CODEC_MEM_ERROR; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 554 | } |
| 555 | #endif |
Sebastien Alaiwan | 8b7a4e1 | 2017-06-13 11:25:57 +0200 | [diff] [blame] | 556 | frame_worker_data->pbi->allow_lowbitdepth = ctx->cfg.allow_lowbitdepth; |
| 557 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 558 | // If decoding in serial mode, FrameWorker thread could create tile worker |
| 559 | // thread or loopfilter thread. |
| 560 | frame_worker_data->pbi->max_threads = |
| 561 | (ctx->frame_parallel_decode == 0) ? ctx->cfg.threads : 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 562 | frame_worker_data->pbi->inv_tile_order = ctx->invert_tile_order; |
| 563 | frame_worker_data->pbi->common.frame_parallel_decode = |
| 564 | ctx->frame_parallel_decode; |
Yunqing Wang | 8ae64a9 | 2018-01-12 12:26:44 -0800 | [diff] [blame^] | 565 | #if CONFIG_EXT_TILE |
| 566 | frame_worker_data->pbi->common.large_scale_tile = ctx->tile_mode; |
| 567 | frame_worker_data->pbi->dec_tile_row = ctx->decode_tile_row; |
| 568 | frame_worker_data->pbi->dec_tile_col = ctx->decode_tile_col; |
| 569 | #endif // CONFIG_EXT_TILE |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 570 | worker->hook = (AVxWorkerHook)frame_worker_hook; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 571 | if (!winterface->reset(worker)) { |
| 572 | set_error_detail(ctx, "Frame Worker thread creation failed"); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 573 | return AOM_CODEC_MEM_ERROR; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 574 | } |
| 575 | } |
| 576 | |
| 577 | // If postprocessing was enabled by the application and a |
| 578 | // configuration has not been provided, default it. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 579 | if (!ctx->postproc_cfg_set && (ctx->base.init_flags & AOM_CODEC_USE_POSTPROC)) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 580 | set_default_ppflags(&ctx->postproc_cfg); |
| 581 | |
| 582 | init_buffer_callbacks(ctx); |
| 583 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 584 | return AOM_CODEC_OK; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 585 | } |
| 586 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 587 | static INLINE void check_resync(aom_codec_alg_priv_t *const ctx, |
| 588 | const AV1Decoder *const pbi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 589 | // Clear resync flag if worker got a key frame or intra only frame. |
| 590 | if (ctx->need_resync == 1 && pbi->need_resync == 0 && |
| 591 | (pbi->common.intra_only || pbi->common.frame_type == KEY_FRAME)) |
| 592 | ctx->need_resync = 0; |
| 593 | } |
| 594 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 595 | static aom_codec_err_t decode_one(aom_codec_alg_priv_t *ctx, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 596 | const uint8_t **data, unsigned int data_sz, |
| 597 | void *user_priv, int64_t deadline) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 598 | const AVxWorkerInterface *const winterface = aom_get_worker_interface(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 599 | (void)deadline; |
| 600 | |
| 601 | // Determine the stream parameters. Note that we rely on peek_si to |
| 602 | // validate that we have a buffer that does not wrap around the top |
| 603 | // of the heap. |
| 604 | if (!ctx->si.h) { |
| 605 | int is_intra_only = 0; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 606 | const aom_codec_err_t res = |
Sebastien Alaiwan | 2b1ec18 | 2017-12-21 09:38:27 +0100 | [diff] [blame] | 607 | decoder_peek_si_internal(*data, data_sz, &ctx->si, &is_intra_only); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 608 | if (res != AOM_CODEC_OK) return res; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 609 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 610 | if (!ctx->si.is_kf && !is_intra_only) return AOM_CODEC_ERROR; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 611 | } |
| 612 | |
| 613 | if (!ctx->frame_parallel_decode) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 614 | AVxWorker *const worker = ctx->frame_workers; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 615 | FrameWorkerData *const frame_worker_data = (FrameWorkerData *)worker->data1; |
| 616 | frame_worker_data->data = *data; |
| 617 | frame_worker_data->data_size = data_sz; |
| 618 | frame_worker_data->user_priv = user_priv; |
| 619 | frame_worker_data->received_frame = 1; |
| 620 | |
Nathan E. Egge | 2cf03b1 | 2017-02-22 16:19:59 -0500 | [diff] [blame] | 621 | #if CONFIG_INSPECTION |
| 622 | frame_worker_data->pbi->inspect_cb = ctx->inspect_cb; |
| 623 | frame_worker_data->pbi->inspect_ctx = ctx->inspect_ctx; |
| 624 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 625 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 626 | worker->had_error = 0; |
| 627 | winterface->execute(worker); |
| 628 | |
| 629 | // Update data pointer after decode. |
| 630 | *data = frame_worker_data->data_end; |
| 631 | |
| 632 | if (worker->had_error) |
| 633 | return update_error_state(ctx, &frame_worker_data->pbi->common.error); |
| 634 | |
| 635 | check_resync(ctx, frame_worker_data->pbi); |
| 636 | } else { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 637 | AVxWorker *const worker = &ctx->frame_workers[ctx->next_submit_worker_id]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 638 | FrameWorkerData *const frame_worker_data = (FrameWorkerData *)worker->data1; |
| 639 | // Copy context from last worker thread to next worker thread. |
| 640 | if (ctx->next_submit_worker_id != ctx->last_submit_worker_id) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 641 | av1_frameworker_copy_context( |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 642 | &ctx->frame_workers[ctx->next_submit_worker_id], |
| 643 | &ctx->frame_workers[ctx->last_submit_worker_id]); |
| 644 | |
| 645 | frame_worker_data->pbi->ready_for_new_data = 0; |
| 646 | // Copy the compressed data into worker's internal buffer. |
| 647 | // TODO(hkuang): Will all the workers allocate the same size |
| 648 | // as the size of the first intra frame be better? This will |
| 649 | // avoid too many deallocate and allocate. |
| 650 | if (frame_worker_data->scratch_buffer_size < data_sz) { |
Alex Converse | 7f094f1 | 2017-02-23 17:29:40 -0800 | [diff] [blame] | 651 | aom_free(frame_worker_data->scratch_buffer); |
| 652 | frame_worker_data->scratch_buffer = (uint8_t *)aom_malloc(data_sz); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 653 | if (frame_worker_data->scratch_buffer == NULL) { |
| 654 | set_error_detail(ctx, "Failed to reallocate scratch buffer"); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 655 | return AOM_CODEC_MEM_ERROR; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 656 | } |
| 657 | frame_worker_data->scratch_buffer_size = data_sz; |
| 658 | } |
| 659 | frame_worker_data->data_size = data_sz; |
| 660 | memcpy(frame_worker_data->scratch_buffer, *data, data_sz); |
| 661 | |
| 662 | frame_worker_data->frame_decoded = 0; |
| 663 | frame_worker_data->frame_context_ready = 0; |
| 664 | frame_worker_data->received_frame = 1; |
| 665 | frame_worker_data->data = frame_worker_data->scratch_buffer; |
| 666 | frame_worker_data->user_priv = user_priv; |
| 667 | |
| 668 | if (ctx->next_submit_worker_id != ctx->last_submit_worker_id) |
| 669 | ctx->last_submit_worker_id = |
| 670 | (ctx->last_submit_worker_id + 1) % ctx->num_frame_workers; |
| 671 | |
| 672 | ctx->next_submit_worker_id = |
| 673 | (ctx->next_submit_worker_id + 1) % ctx->num_frame_workers; |
| 674 | --ctx->available_threads; |
| 675 | worker->had_error = 0; |
| 676 | winterface->launch(worker); |
| 677 | } |
| 678 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 679 | return AOM_CODEC_OK; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 680 | } |
| 681 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 682 | static void wait_worker_and_cache_frame(aom_codec_alg_priv_t *ctx) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 683 | YV12_BUFFER_CONFIG sd; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 684 | const AVxWorkerInterface *const winterface = aom_get_worker_interface(); |
| 685 | AVxWorker *const worker = &ctx->frame_workers[ctx->next_output_worker_id]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 686 | FrameWorkerData *const frame_worker_data = (FrameWorkerData *)worker->data1; |
| 687 | ctx->next_output_worker_id = |
| 688 | (ctx->next_output_worker_id + 1) % ctx->num_frame_workers; |
| 689 | // TODO(hkuang): Add worker error handling here. |
| 690 | winterface->sync(worker); |
| 691 | frame_worker_data->received_frame = 0; |
| 692 | ++ctx->available_threads; |
| 693 | |
| 694 | check_resync(ctx, frame_worker_data->pbi); |
| 695 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 696 | if (av1_get_raw_frame(frame_worker_data->pbi, &sd) == 0) { |
| 697 | AV1_COMMON *const cm = &frame_worker_data->pbi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 698 | RefCntBuffer *const frame_bufs = cm->buffer_pool->frame_bufs; |
| 699 | ctx->frame_cache[ctx->frame_cache_write].fb_idx = cm->new_fb_idx; |
| 700 | yuvconfig2image(&ctx->frame_cache[ctx->frame_cache_write].img, &sd, |
| 701 | frame_worker_data->user_priv); |
| 702 | ctx->frame_cache[ctx->frame_cache_write].img.fb_priv = |
| 703 | frame_bufs[cm->new_fb_idx].raw_frame_buffer.priv; |
| 704 | ctx->frame_cache_write = (ctx->frame_cache_write + 1) % FRAME_CACHE_SIZE; |
| 705 | ++ctx->num_cache_frames; |
| 706 | } |
| 707 | } |
| 708 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 709 | static aom_codec_err_t decoder_decode(aom_codec_alg_priv_t *ctx, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 710 | const uint8_t *data, unsigned int data_sz, |
| 711 | void *user_priv, long deadline) { |
| 712 | const uint8_t *data_start = data; |
| 713 | const uint8_t *const data_end = data + data_sz; |
Yaowu Xu | b02d0b1 | 2017-12-15 01:32:34 +0000 | [diff] [blame] | 714 | aom_codec_err_t res = AOM_CODEC_OK; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 715 | uint32_t frame_sizes[8]; |
Soo-Chul Han | 38427e8 | 2017-09-27 15:06:13 -0400 | [diff] [blame] | 716 | int frame_count = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 717 | |
| 718 | if (data == NULL && data_sz == 0) { |
| 719 | ctx->flushed = 1; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 720 | return AOM_CODEC_OK; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 721 | } |
| 722 | |
| 723 | // Reset flushed when receiving a valid frame. |
| 724 | ctx->flushed = 0; |
| 725 | |
| 726 | // Initialize the decoder workers on the first frame. |
| 727 | if (ctx->frame_workers == NULL) { |
Urvang Joshi | 454280d | 2016-10-14 16:51:44 -0700 | [diff] [blame] | 728 | res = init_decoder(ctx); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 729 | if (res != AOM_CODEC_OK) return res; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 730 | } |
Soo-Chul Han | 38427e8 | 2017-09-27 15:06:13 -0400 | [diff] [blame] | 731 | #if !CONFIG_OBU |
Sebastien Alaiwan | e4c6fc1 | 2017-06-21 16:43:22 +0200 | [diff] [blame] | 732 | int index_size = 0; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 733 | res = av1_parse_superframe_index(data, data_sz, frame_sizes, &frame_count, |
Sebastien Alaiwan | 2b1ec18 | 2017-12-21 09:38:27 +0100 | [diff] [blame] | 734 | &index_size); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 735 | if (res != AOM_CODEC_OK) return res; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 736 | |
Sebastien Alaiwan | e4c6fc1 | 2017-06-21 16:43:22 +0200 | [diff] [blame] | 737 | data_start += index_size; |
Soo-Chul Han | 38427e8 | 2017-09-27 15:06:13 -0400 | [diff] [blame] | 738 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 739 | if (ctx->frame_parallel_decode) { |
| 740 | // Decode in frame parallel mode. When decoding in this mode, the frame |
| 741 | // passed to the decoder must be either a normal frame or a superframe with |
| 742 | // superframe index so the decoder could get each frame's start position |
| 743 | // in the superframe. |
| 744 | if (frame_count > 0) { |
| 745 | int i; |
| 746 | |
| 747 | for (i = 0; i < frame_count; ++i) { |
| 748 | const uint8_t *data_start_copy = data_start; |
| 749 | const uint32_t frame_size = frame_sizes[i]; |
| 750 | if (data_start < data || |
| 751 | frame_size > (uint32_t)(data_end - data_start)) { |
| 752 | set_error_detail(ctx, "Invalid frame size in index"); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 753 | return AOM_CODEC_CORRUPT_FRAME; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 754 | } |
| 755 | |
| 756 | if (ctx->available_threads == 0) { |
| 757 | // No more threads for decoding. Wait until the next output worker |
| 758 | // finishes decoding. Then copy the decoded frame into cache. |
| 759 | if (ctx->num_cache_frames < FRAME_CACHE_SIZE) { |
| 760 | wait_worker_and_cache_frame(ctx); |
| 761 | } else { |
| 762 | // TODO(hkuang): Add unit test to test this path. |
| 763 | set_error_detail(ctx, "Frame output cache is full."); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 764 | return AOM_CODEC_ERROR; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 765 | } |
| 766 | } |
| 767 | |
| 768 | res = |
| 769 | decode_one(ctx, &data_start_copy, frame_size, user_priv, deadline); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 770 | if (res != AOM_CODEC_OK) return res; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 771 | data_start += frame_size; |
| 772 | } |
| 773 | } else { |
| 774 | if (ctx->available_threads == 0) { |
| 775 | // No more threads for decoding. Wait until the next output worker |
| 776 | // finishes decoding. Then copy the decoded frame into cache. |
| 777 | if (ctx->num_cache_frames < FRAME_CACHE_SIZE) { |
| 778 | wait_worker_and_cache_frame(ctx); |
| 779 | } else { |
| 780 | // TODO(hkuang): Add unit test to test this path. |
| 781 | set_error_detail(ctx, "Frame output cache is full."); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 782 | return AOM_CODEC_ERROR; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 783 | } |
| 784 | } |
| 785 | |
| 786 | res = decode_one(ctx, &data, data_sz, user_priv, deadline); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 787 | if (res != AOM_CODEC_OK) return res; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 788 | } |
| 789 | } else { |
| 790 | // Decode in serial mode. |
| 791 | if (frame_count > 0) { |
| 792 | int i; |
| 793 | |
| 794 | for (i = 0; i < frame_count; ++i) { |
| 795 | const uint8_t *data_start_copy = data_start; |
| 796 | const uint32_t frame_size = frame_sizes[i]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 797 | if (data_start < data || |
| 798 | frame_size > (uint32_t)(data_end - data_start)) { |
| 799 | set_error_detail(ctx, "Invalid frame size in index"); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 800 | return AOM_CODEC_CORRUPT_FRAME; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 801 | } |
| 802 | |
| 803 | res = |
| 804 | decode_one(ctx, &data_start_copy, frame_size, user_priv, deadline); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 805 | if (res != AOM_CODEC_OK) return res; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 806 | |
| 807 | data_start += frame_size; |
| 808 | } |
| 809 | } else { |
| 810 | while (data_start < data_end) { |
| 811 | const uint32_t frame_size = (uint32_t)(data_end - data_start); |
Urvang Joshi | 454280d | 2016-10-14 16:51:44 -0700 | [diff] [blame] | 812 | res = decode_one(ctx, &data_start, frame_size, user_priv, deadline); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 813 | if (res != AOM_CODEC_OK) return res; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 814 | |
| 815 | // Account for suboptimal termination by the encoder. |
| 816 | while (data_start < data_end) { |
Sebastien Alaiwan | 64c2311 | 2017-12-21 09:49:23 +0100 | [diff] [blame] | 817 | const uint8_t marker = data_start[0]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 818 | if (marker) break; |
| 819 | ++data_start; |
| 820 | } |
| 821 | } |
| 822 | } |
| 823 | } |
| 824 | |
| 825 | return res; |
| 826 | } |
| 827 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 828 | static void release_last_output_frame(aom_codec_alg_priv_t *ctx) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 829 | RefCntBuffer *const frame_bufs = ctx->buffer_pool->frame_bufs; |
| 830 | // Decrease reference count of last output frame in frame parallel mode. |
| 831 | if (ctx->frame_parallel_decode && ctx->last_show_frame >= 0) { |
| 832 | BufferPool *const pool = ctx->buffer_pool; |
| 833 | lock_buffer_pool(pool); |
| 834 | decrease_ref_count(ctx->last_show_frame, frame_bufs, pool); |
| 835 | unlock_buffer_pool(pool); |
| 836 | } |
| 837 | } |
| 838 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 839 | static aom_image_t *decoder_get_frame(aom_codec_alg_priv_t *ctx, |
| 840 | aom_codec_iter_t *iter) { |
| 841 | aom_image_t *img = NULL; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 842 | |
| 843 | // Only return frame when all the cpu are busy or |
| 844 | // application fluhsed the decoder in frame parallel decode. |
| 845 | if (ctx->frame_parallel_decode && ctx->available_threads > 0 && |
| 846 | !ctx->flushed) { |
| 847 | return NULL; |
| 848 | } |
| 849 | |
| 850 | // Output the frames in the cache first. |
| 851 | if (ctx->num_cache_frames > 0) { |
| 852 | release_last_output_frame(ctx); |
| 853 | ctx->last_show_frame = ctx->frame_cache[ctx->frame_cache_read].fb_idx; |
| 854 | if (ctx->need_resync) return NULL; |
| 855 | img = &ctx->frame_cache[ctx->frame_cache_read].img; |
| 856 | ctx->frame_cache_read = (ctx->frame_cache_read + 1) % FRAME_CACHE_SIZE; |
| 857 | --ctx->num_cache_frames; |
| 858 | return img; |
| 859 | } |
| 860 | |
| 861 | // iter acts as a flip flop, so an image is only returned on the first |
| 862 | // call to get_frame. |
| 863 | if (*iter == NULL && ctx->frame_workers != NULL) { |
| 864 | do { |
| 865 | YV12_BUFFER_CONFIG sd; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 866 | const AVxWorkerInterface *const winterface = aom_get_worker_interface(); |
| 867 | AVxWorker *const worker = &ctx->frame_workers[ctx->next_output_worker_id]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 868 | FrameWorkerData *const frame_worker_data = |
| 869 | (FrameWorkerData *)worker->data1; |
| 870 | ctx->next_output_worker_id = |
| 871 | (ctx->next_output_worker_id + 1) % ctx->num_frame_workers; |
| 872 | // Wait for the frame from worker thread. |
| 873 | if (winterface->sync(worker)) { |
| 874 | // Check if worker has received any frames. |
| 875 | if (frame_worker_data->received_frame == 1) { |
| 876 | ++ctx->available_threads; |
| 877 | frame_worker_data->received_frame = 0; |
| 878 | check_resync(ctx, frame_worker_data->pbi); |
| 879 | } |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 880 | if (av1_get_raw_frame(frame_worker_data->pbi, &sd) == 0) { |
| 881 | AV1_COMMON *const cm = &frame_worker_data->pbi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 882 | RefCntBuffer *const frame_bufs = cm->buffer_pool->frame_bufs; |
| 883 | release_last_output_frame(ctx); |
| 884 | ctx->last_show_frame = frame_worker_data->pbi->common.new_fb_idx; |
| 885 | if (ctx->need_resync) return NULL; |
| 886 | yuvconfig2image(&ctx->img, &sd, frame_worker_data->user_priv); |
| 887 | |
| 888 | #if CONFIG_EXT_TILE |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 889 | if (cm->single_tile_decoding && |
Yunqing Wang | d8cd55f | 2017-02-27 12:16:00 -0800 | [diff] [blame] | 890 | frame_worker_data->pbi->dec_tile_row >= 0) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 891 | const int tile_row = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 892 | AOMMIN(frame_worker_data->pbi->dec_tile_row, cm->tile_rows - 1); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 893 | const int mi_row = tile_row * cm->tile_height; |
| 894 | const int ssy = ctx->img.y_chroma_shift; |
| 895 | int plane; |
| 896 | ctx->img.planes[0] += mi_row * MI_SIZE * ctx->img.stride[0]; |
| 897 | for (plane = 1; plane < MAX_MB_PLANE; ++plane) { |
| 898 | ctx->img.planes[plane] += |
| 899 | mi_row * (MI_SIZE >> ssy) * ctx->img.stride[plane]; |
| 900 | } |
| 901 | ctx->img.d_h = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 902 | AOMMIN(cm->tile_height, cm->mi_rows - mi_row) * MI_SIZE; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 903 | } |
| 904 | |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 905 | if (cm->single_tile_decoding && |
Yunqing Wang | d8cd55f | 2017-02-27 12:16:00 -0800 | [diff] [blame] | 906 | frame_worker_data->pbi->dec_tile_col >= 0) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 907 | const int tile_col = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 908 | AOMMIN(frame_worker_data->pbi->dec_tile_col, cm->tile_cols - 1); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 909 | const int mi_col = tile_col * cm->tile_width; |
| 910 | const int ssx = ctx->img.x_chroma_shift; |
| 911 | int plane; |
| 912 | ctx->img.planes[0] += mi_col * MI_SIZE; |
| 913 | for (plane = 1; plane < MAX_MB_PLANE; ++plane) { |
| 914 | ctx->img.planes[plane] += mi_col * (MI_SIZE >> ssx); |
| 915 | } |
| 916 | ctx->img.d_w = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 917 | AOMMIN(cm->tile_width, cm->mi_cols - mi_col) * MI_SIZE; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 918 | } |
| 919 | #endif // CONFIG_EXT_TILE |
| 920 | |
| 921 | ctx->img.fb_priv = frame_bufs[cm->new_fb_idx].raw_frame_buffer.priv; |
| 922 | img = &ctx->img; |
| 923 | return img; |
| 924 | } |
| 925 | } else { |
| 926 | // Decoding failed. Release the worker thread. |
| 927 | frame_worker_data->received_frame = 0; |
| 928 | ++ctx->available_threads; |
| 929 | ctx->need_resync = 1; |
| 930 | if (ctx->flushed != 1) return NULL; |
| 931 | } |
| 932 | } while (ctx->next_output_worker_id != ctx->next_submit_worker_id); |
| 933 | } |
| 934 | return NULL; |
| 935 | } |
| 936 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 937 | static aom_codec_err_t decoder_set_fb_fn( |
| 938 | aom_codec_alg_priv_t *ctx, aom_get_frame_buffer_cb_fn_t cb_get, |
| 939 | aom_release_frame_buffer_cb_fn_t cb_release, void *cb_priv) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 940 | if (cb_get == NULL || cb_release == NULL) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 941 | return AOM_CODEC_INVALID_PARAM; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 942 | } else if (ctx->frame_workers == NULL) { |
| 943 | // If the decoder has already been initialized, do not accept changes to |
| 944 | // the frame buffer functions. |
| 945 | ctx->get_ext_fb_cb = cb_get; |
| 946 | ctx->release_ext_fb_cb = cb_release; |
| 947 | ctx->ext_priv = cb_priv; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 948 | return AOM_CODEC_OK; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 949 | } |
| 950 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 951 | return AOM_CODEC_ERROR; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 952 | } |
| 953 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 954 | static aom_codec_err_t ctrl_set_reference(aom_codec_alg_priv_t *ctx, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 955 | va_list args) { |
Thomas Daede | 497d195 | 2017-08-08 17:33:06 -0700 | [diff] [blame] | 956 | av1_ref_frame_t *const data = va_arg(args, av1_ref_frame_t *); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 957 | |
| 958 | // Only support this function in serial decode. |
| 959 | if (ctx->frame_parallel_decode) { |
| 960 | set_error_detail(ctx, "Not supported in frame parallel decode"); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 961 | return AOM_CODEC_INCAPABLE; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 962 | } |
| 963 | |
| 964 | if (data) { |
Thomas Daede | 497d195 | 2017-08-08 17:33:06 -0700 | [diff] [blame] | 965 | av1_ref_frame_t *const frame = data; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 966 | YV12_BUFFER_CONFIG sd; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 967 | AVxWorker *const worker = ctx->frame_workers; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 968 | FrameWorkerData *const frame_worker_data = (FrameWorkerData *)worker->data1; |
| 969 | image2yuvconfig(&frame->img, &sd); |
Thomas Daede | 497d195 | 2017-08-08 17:33:06 -0700 | [diff] [blame] | 970 | return av1_set_reference_dec(&frame_worker_data->pbi->common, frame->idx, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 971 | &sd); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 972 | } else { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 973 | return AOM_CODEC_INVALID_PARAM; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 974 | } |
| 975 | } |
| 976 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 977 | static aom_codec_err_t ctrl_copy_reference(aom_codec_alg_priv_t *ctx, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 978 | va_list args) { |
Thomas Daede | 497d195 | 2017-08-08 17:33:06 -0700 | [diff] [blame] | 979 | const av1_ref_frame_t *const frame = va_arg(args, av1_ref_frame_t *); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 980 | |
| 981 | // Only support this function in serial decode. |
| 982 | if (ctx->frame_parallel_decode) { |
| 983 | set_error_detail(ctx, "Not supported in frame parallel decode"); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 984 | return AOM_CODEC_INCAPABLE; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 985 | } |
| 986 | |
Urvang Joshi | 77853e5 | 2016-07-15 12:47:01 -0700 | [diff] [blame] | 987 | if (frame) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 988 | YV12_BUFFER_CONFIG sd; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 989 | AVxWorker *const worker = ctx->frame_workers; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 990 | FrameWorkerData *const frame_worker_data = (FrameWorkerData *)worker->data1; |
| 991 | image2yuvconfig(&frame->img, &sd); |
Thomas Daede | 497d195 | 2017-08-08 17:33:06 -0700 | [diff] [blame] | 992 | return av1_copy_reference_dec(frame_worker_data->pbi, frame->idx, &sd); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 993 | } else { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 994 | return AOM_CODEC_INVALID_PARAM; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 995 | } |
| 996 | } |
| 997 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 998 | static aom_codec_err_t ctrl_get_reference(aom_codec_alg_priv_t *ctx, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 999 | va_list args) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1000 | av1_ref_frame_t *data = va_arg(args, av1_ref_frame_t *); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1001 | |
| 1002 | // Only support this function in serial decode. |
| 1003 | if (ctx->frame_parallel_decode) { |
| 1004 | set_error_detail(ctx, "Not supported in frame parallel decode"); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1005 | return AOM_CODEC_INCAPABLE; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1006 | } |
| 1007 | |
| 1008 | if (data) { |
| 1009 | YV12_BUFFER_CONFIG *fb; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1010 | AVxWorker *const worker = ctx->frame_workers; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1011 | FrameWorkerData *const frame_worker_data = (FrameWorkerData *)worker->data1; |
| 1012 | fb = get_ref_frame(&frame_worker_data->pbi->common, data->idx); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1013 | if (fb == NULL) return AOM_CODEC_ERROR; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1014 | yuvconfig2image(&data->img, fb, NULL); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1015 | return AOM_CODEC_OK; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1016 | } else { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1017 | return AOM_CODEC_INVALID_PARAM; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1018 | } |
| 1019 | } |
| 1020 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1021 | static aom_codec_err_t ctrl_get_new_frame_image(aom_codec_alg_priv_t *ctx, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1022 | va_list args) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1023 | aom_image_t *new_img = va_arg(args, aom_image_t *); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1024 | |
| 1025 | // Only support this function in serial decode. |
| 1026 | if (ctx->frame_parallel_decode) { |
| 1027 | set_error_detail(ctx, "Not supported in frame parallel decode"); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1028 | return AOM_CODEC_INCAPABLE; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1029 | } |
| 1030 | |
| 1031 | if (new_img) { |
| 1032 | YV12_BUFFER_CONFIG new_frame; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1033 | AVxWorker *const worker = ctx->frame_workers; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1034 | FrameWorkerData *const frame_worker_data = (FrameWorkerData *)worker->data1; |
| 1035 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1036 | if (av1_get_frame_to_show(frame_worker_data->pbi, &new_frame) == 0) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1037 | yuvconfig2image(new_img, &new_frame, NULL); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1038 | return AOM_CODEC_OK; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1039 | } else { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1040 | return AOM_CODEC_ERROR; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1041 | } |
| 1042 | } else { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1043 | return AOM_CODEC_INVALID_PARAM; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1044 | } |
| 1045 | } |
| 1046 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1047 | static aom_codec_err_t ctrl_set_postproc(aom_codec_alg_priv_t *ctx, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1048 | va_list args) { |
| 1049 | (void)ctx; |
| 1050 | (void)args; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1051 | return AOM_CODEC_INCAPABLE; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1052 | } |
| 1053 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1054 | static aom_codec_err_t ctrl_set_dbg_options(aom_codec_alg_priv_t *ctx, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1055 | va_list args) { |
| 1056 | (void)ctx; |
| 1057 | (void)args; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1058 | return AOM_CODEC_INCAPABLE; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1059 | } |
| 1060 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1061 | static aom_codec_err_t ctrl_get_last_ref_updates(aom_codec_alg_priv_t *ctx, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1062 | va_list args) { |
| 1063 | int *const update_info = va_arg(args, int *); |
| 1064 | |
| 1065 | // Only support this function in serial decode. |
| 1066 | if (ctx->frame_parallel_decode) { |
| 1067 | set_error_detail(ctx, "Not supported in frame parallel decode"); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1068 | return AOM_CODEC_INCAPABLE; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1069 | } |
| 1070 | |
| 1071 | if (update_info) { |
| 1072 | if (ctx->frame_workers) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1073 | AVxWorker *const worker = ctx->frame_workers; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1074 | FrameWorkerData *const frame_worker_data = |
| 1075 | (FrameWorkerData *)worker->data1; |
| 1076 | *update_info = frame_worker_data->pbi->refresh_frame_flags; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1077 | return AOM_CODEC_OK; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1078 | } else { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1079 | return AOM_CODEC_ERROR; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1080 | } |
| 1081 | } |
| 1082 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1083 | return AOM_CODEC_INVALID_PARAM; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1084 | } |
| 1085 | |
Peter Boström | a1f6432 | 2017-01-19 11:35:30 -0500 | [diff] [blame] | 1086 | static aom_codec_err_t ctrl_get_last_quantizer(aom_codec_alg_priv_t *ctx, |
| 1087 | va_list args) { |
| 1088 | int *const arg = va_arg(args, int *); |
| 1089 | if (arg == NULL) return AOM_CODEC_INVALID_PARAM; |
| 1090 | *arg = |
| 1091 | ((FrameWorkerData *)ctx->frame_workers[0].data1)->pbi->common.base_qindex; |
| 1092 | return AOM_CODEC_OK; |
| 1093 | } |
| 1094 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1095 | static aom_codec_err_t ctrl_get_frame_corrupted(aom_codec_alg_priv_t *ctx, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1096 | va_list args) { |
| 1097 | int *corrupted = va_arg(args, int *); |
| 1098 | |
| 1099 | if (corrupted) { |
| 1100 | if (ctx->frame_workers) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1101 | AVxWorker *const worker = ctx->frame_workers; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1102 | FrameWorkerData *const frame_worker_data = |
| 1103 | (FrameWorkerData *)worker->data1; |
| 1104 | RefCntBuffer *const frame_bufs = |
| 1105 | frame_worker_data->pbi->common.buffer_pool->frame_bufs; |
| 1106 | if (frame_worker_data->pbi->common.frame_to_show == NULL) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1107 | return AOM_CODEC_ERROR; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1108 | if (ctx->last_show_frame >= 0) |
| 1109 | *corrupted = frame_bufs[ctx->last_show_frame].buf.corrupted; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1110 | return AOM_CODEC_OK; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1111 | } else { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1112 | return AOM_CODEC_ERROR; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1113 | } |
| 1114 | } |
| 1115 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1116 | return AOM_CODEC_INVALID_PARAM; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1117 | } |
| 1118 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1119 | static aom_codec_err_t ctrl_get_frame_size(aom_codec_alg_priv_t *ctx, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1120 | va_list args) { |
| 1121 | int *const frame_size = va_arg(args, int *); |
| 1122 | |
| 1123 | // Only support this function in serial decode. |
| 1124 | if (ctx->frame_parallel_decode) { |
| 1125 | set_error_detail(ctx, "Not supported in frame parallel decode"); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1126 | return AOM_CODEC_INCAPABLE; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1127 | } |
| 1128 | |
| 1129 | if (frame_size) { |
| 1130 | if (ctx->frame_workers) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1131 | AVxWorker *const worker = ctx->frame_workers; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1132 | FrameWorkerData *const frame_worker_data = |
| 1133 | (FrameWorkerData *)worker->data1; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1134 | const AV1_COMMON *const cm = &frame_worker_data->pbi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1135 | frame_size[0] = cm->width; |
| 1136 | frame_size[1] = cm->height; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1137 | return AOM_CODEC_OK; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1138 | } else { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1139 | return AOM_CODEC_ERROR; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1140 | } |
| 1141 | } |
| 1142 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1143 | return AOM_CODEC_INVALID_PARAM; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1144 | } |
| 1145 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1146 | static aom_codec_err_t ctrl_get_render_size(aom_codec_alg_priv_t *ctx, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1147 | va_list args) { |
| 1148 | int *const render_size = va_arg(args, int *); |
| 1149 | |
| 1150 | // Only support this function in serial decode. |
| 1151 | if (ctx->frame_parallel_decode) { |
| 1152 | set_error_detail(ctx, "Not supported in frame parallel decode"); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1153 | return AOM_CODEC_INCAPABLE; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1154 | } |
| 1155 | |
| 1156 | if (render_size) { |
| 1157 | if (ctx->frame_workers) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1158 | AVxWorker *const worker = ctx->frame_workers; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1159 | FrameWorkerData *const frame_worker_data = |
| 1160 | (FrameWorkerData *)worker->data1; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1161 | const AV1_COMMON *const cm = &frame_worker_data->pbi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1162 | render_size[0] = cm->render_width; |
| 1163 | render_size[1] = cm->render_height; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1164 | return AOM_CODEC_OK; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1165 | } else { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1166 | return AOM_CODEC_ERROR; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1167 | } |
| 1168 | } |
| 1169 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1170 | return AOM_CODEC_INVALID_PARAM; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1171 | } |
| 1172 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1173 | static aom_codec_err_t ctrl_get_bit_depth(aom_codec_alg_priv_t *ctx, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1174 | va_list args) { |
| 1175 | unsigned int *const bit_depth = va_arg(args, unsigned int *); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1176 | AVxWorker *const worker = &ctx->frame_workers[ctx->next_output_worker_id]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1177 | |
| 1178 | if (bit_depth) { |
| 1179 | if (worker) { |
| 1180 | FrameWorkerData *const frame_worker_data = |
| 1181 | (FrameWorkerData *)worker->data1; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1182 | const AV1_COMMON *const cm = &frame_worker_data->pbi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1183 | *bit_depth = cm->bit_depth; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1184 | return AOM_CODEC_OK; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1185 | } else { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1186 | return AOM_CODEC_ERROR; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1187 | } |
| 1188 | } |
| 1189 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1190 | return AOM_CODEC_INVALID_PARAM; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1191 | } |
| 1192 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1193 | static aom_codec_err_t ctrl_set_invert_tile_order(aom_codec_alg_priv_t *ctx, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1194 | va_list args) { |
| 1195 | ctx->invert_tile_order = va_arg(args, int); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1196 | return AOM_CODEC_OK; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1197 | } |
| 1198 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1199 | static aom_codec_err_t ctrl_set_byte_alignment(aom_codec_alg_priv_t *ctx, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1200 | va_list args) { |
| 1201 | const int legacy_byte_alignment = 0; |
| 1202 | const int min_byte_alignment = 32; |
| 1203 | const int max_byte_alignment = 1024; |
| 1204 | const int byte_alignment = va_arg(args, int); |
| 1205 | |
| 1206 | if (byte_alignment != legacy_byte_alignment && |
| 1207 | (byte_alignment < min_byte_alignment || |
| 1208 | byte_alignment > max_byte_alignment || |
| 1209 | (byte_alignment & (byte_alignment - 1)) != 0)) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1210 | return AOM_CODEC_INVALID_PARAM; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1211 | |
| 1212 | ctx->byte_alignment = byte_alignment; |
| 1213 | if (ctx->frame_workers) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1214 | AVxWorker *const worker = ctx->frame_workers; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1215 | FrameWorkerData *const frame_worker_data = (FrameWorkerData *)worker->data1; |
| 1216 | frame_worker_data->pbi->common.byte_alignment = byte_alignment; |
| 1217 | } |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1218 | return AOM_CODEC_OK; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1219 | } |
| 1220 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1221 | static aom_codec_err_t ctrl_set_skip_loop_filter(aom_codec_alg_priv_t *ctx, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1222 | va_list args) { |
| 1223 | ctx->skip_loop_filter = va_arg(args, int); |
| 1224 | |
| 1225 | if (ctx->frame_workers) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1226 | AVxWorker *const worker = ctx->frame_workers; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1227 | FrameWorkerData *const frame_worker_data = (FrameWorkerData *)worker->data1; |
| 1228 | frame_worker_data->pbi->common.skip_loop_filter = ctx->skip_loop_filter; |
| 1229 | } |
| 1230 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1231 | return AOM_CODEC_OK; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1232 | } |
| 1233 | |
Nathan E. Egge | c9862e0 | 2016-10-05 21:28:36 -0400 | [diff] [blame] | 1234 | static aom_codec_err_t ctrl_get_accounting(aom_codec_alg_priv_t *ctx, |
| 1235 | va_list args) { |
| 1236 | #if !CONFIG_ACCOUNTING |
| 1237 | (void)ctx; |
| 1238 | (void)args; |
| 1239 | return AOM_CODEC_INCAPABLE; |
| 1240 | #else |
| 1241 | if (ctx->frame_workers) { |
| 1242 | AVxWorker *const worker = ctx->frame_workers; |
| 1243 | FrameWorkerData *const frame_worker_data = (FrameWorkerData *)worker->data1; |
| 1244 | AV1Decoder *pbi = frame_worker_data->pbi; |
| 1245 | Accounting **acct = va_arg(args, Accounting **); |
| 1246 | *acct = &pbi->accounting; |
| 1247 | return AOM_CODEC_OK; |
| 1248 | } |
| 1249 | return AOM_CODEC_ERROR; |
| 1250 | #endif |
| 1251 | } |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1252 | static aom_codec_err_t ctrl_set_decode_tile_row(aom_codec_alg_priv_t *ctx, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1253 | va_list args) { |
| 1254 | ctx->decode_tile_row = va_arg(args, int); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1255 | return AOM_CODEC_OK; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1256 | } |
| 1257 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1258 | static aom_codec_err_t ctrl_set_decode_tile_col(aom_codec_alg_priv_t *ctx, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1259 | va_list args) { |
| 1260 | ctx->decode_tile_col = va_arg(args, int); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1261 | return AOM_CODEC_OK; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1262 | } |
| 1263 | |
Yunqing Wang | 8ae64a9 | 2018-01-12 12:26:44 -0800 | [diff] [blame^] | 1264 | static aom_codec_err_t ctrl_set_tile_mode(aom_codec_alg_priv_t *ctx, |
| 1265 | va_list args) { |
| 1266 | ctx->tile_mode = va_arg(args, unsigned int); |
| 1267 | return AOM_CODEC_OK; |
| 1268 | } |
| 1269 | |
Nathan E. Egge | 2cf03b1 | 2017-02-22 16:19:59 -0500 | [diff] [blame] | 1270 | static aom_codec_err_t ctrl_set_inspection_callback(aom_codec_alg_priv_t *ctx, |
| 1271 | va_list args) { |
| 1272 | #if !CONFIG_INSPECTION |
| 1273 | (void)ctx; |
| 1274 | (void)args; |
| 1275 | return AOM_CODEC_INCAPABLE; |
| 1276 | #else |
| 1277 | aom_inspect_init *init = va_arg(args, aom_inspect_init *); |
| 1278 | ctx->inspect_cb = init->inspect_cb; |
| 1279 | ctx->inspect_ctx = init->inspect_ctx; |
| 1280 | return AOM_CODEC_OK; |
| 1281 | #endif |
| 1282 | } |
| 1283 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1284 | static aom_codec_ctrl_fn_map_t decoder_ctrl_maps[] = { |
Thomas Daede | 497d195 | 2017-08-08 17:33:06 -0700 | [diff] [blame] | 1285 | { AV1_COPY_REFERENCE, ctrl_copy_reference }, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1286 | |
| 1287 | // Setters |
Thomas Daede | 497d195 | 2017-08-08 17:33:06 -0700 | [diff] [blame] | 1288 | { AV1_SET_REFERENCE, ctrl_set_reference }, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1289 | { AOM_SET_POSTPROC, ctrl_set_postproc }, |
| 1290 | { AOM_SET_DBG_COLOR_REF_FRAME, ctrl_set_dbg_options }, |
| 1291 | { AOM_SET_DBG_COLOR_MB_MODES, ctrl_set_dbg_options }, |
| 1292 | { AOM_SET_DBG_COLOR_B_MODES, ctrl_set_dbg_options }, |
| 1293 | { AOM_SET_DBG_DISPLAY_MV, ctrl_set_dbg_options }, |
| 1294 | { AV1_INVERT_TILE_DECODE_ORDER, ctrl_set_invert_tile_order }, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1295 | { AV1_SET_BYTE_ALIGNMENT, ctrl_set_byte_alignment }, |
| 1296 | { AV1_SET_SKIP_LOOP_FILTER, ctrl_set_skip_loop_filter }, |
| 1297 | { AV1_SET_DECODE_TILE_ROW, ctrl_set_decode_tile_row }, |
| 1298 | { AV1_SET_DECODE_TILE_COL, ctrl_set_decode_tile_col }, |
Yunqing Wang | 8ae64a9 | 2018-01-12 12:26:44 -0800 | [diff] [blame^] | 1299 | { AV1_SET_TILE_MODE, ctrl_set_tile_mode }, |
Nathan E. Egge | 2cf03b1 | 2017-02-22 16:19:59 -0500 | [diff] [blame] | 1300 | { AV1_SET_INSPECTION_CALLBACK, ctrl_set_inspection_callback }, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1301 | |
| 1302 | // Getters |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1303 | { AOMD_GET_FRAME_CORRUPTED, ctrl_get_frame_corrupted }, |
Peter Boström | a1f6432 | 2017-01-19 11:35:30 -0500 | [diff] [blame] | 1304 | { AOMD_GET_LAST_QUANTIZER, ctrl_get_last_quantizer }, |
| 1305 | { AOMD_GET_LAST_REF_UPDATES, ctrl_get_last_ref_updates }, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1306 | { AV1D_GET_BIT_DEPTH, ctrl_get_bit_depth }, |
Peter Boström | a1f6432 | 2017-01-19 11:35:30 -0500 | [diff] [blame] | 1307 | { AV1D_GET_DISPLAY_SIZE, ctrl_get_render_size }, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1308 | { AV1D_GET_FRAME_SIZE, ctrl_get_frame_size }, |
Nathan E. Egge | c9862e0 | 2016-10-05 21:28:36 -0400 | [diff] [blame] | 1309 | { AV1_GET_ACCOUNTING, ctrl_get_accounting }, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1310 | { AV1_GET_NEW_FRAME_IMAGE, ctrl_get_new_frame_image }, |
Peter Boström | a1f6432 | 2017-01-19 11:35:30 -0500 | [diff] [blame] | 1311 | { AV1_GET_REFERENCE, ctrl_get_reference }, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1312 | |
| 1313 | { -1, NULL }, |
| 1314 | }; |
| 1315 | |
| 1316 | #ifndef VERSION_STRING |
| 1317 | #define VERSION_STRING |
| 1318 | #endif |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1319 | CODEC_INTERFACE(aom_codec_av1_dx) = { |
| 1320 | "AOMedia Project AV1 Decoder" VERSION_STRING, |
| 1321 | AOM_CODEC_INTERNAL_ABI_VERSION, |
| 1322 | AOM_CODEC_CAP_DECODER | |
| 1323 | AOM_CODEC_CAP_EXTERNAL_FRAME_BUFFER, // aom_codec_caps_t |
| 1324 | decoder_init, // aom_codec_init_fn_t |
| 1325 | decoder_destroy, // aom_codec_destroy_fn_t |
| 1326 | decoder_ctrl_maps, // aom_codec_ctrl_fn_map_t |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1327 | { |
| 1328 | // NOLINT |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1329 | decoder_peek_si, // aom_codec_peek_si_fn_t |
| 1330 | decoder_get_si, // aom_codec_get_si_fn_t |
| 1331 | decoder_decode, // aom_codec_decode_fn_t |
| 1332 | decoder_get_frame, // aom_codec_frame_get_fn_t |
| 1333 | decoder_set_fb_fn, // aom_codec_set_fb_fn_t |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1334 | }, |
| 1335 | { |
| 1336 | // NOLINT |
| 1337 | 0, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1338 | NULL, // aom_codec_enc_cfg_map_t |
| 1339 | NULL, // aom_codec_encode_fn_t |
| 1340 | NULL, // aom_codec_get_cx_data_fn_t |
| 1341 | NULL, // aom_codec_enc_config_set_fn_t |
| 1342 | NULL, // aom_codec_get_global_headers_fn_t |
| 1343 | NULL, // aom_codec_get_preview_frame_fn_t |
| 1344 | NULL // aom_codec_enc_mr_get_mem_loc_fn_t |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1345 | } |
| 1346 | }; |