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 | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 34 | typedef aom_codec_stream_info_t av1_stream_info_t; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 35 | |
| 36 | // This limit is due to framebuffer numbers. |
| 37 | // TODO(hkuang): Remove this limit after implementing ondemand framebuffers. |
| 38 | #define FRAME_CACHE_SIZE 6 // Cache maximum 6 decoded frames. |
| 39 | |
| 40 | typedef struct cache_frame { |
| 41 | int fb_idx; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 42 | aom_image_t img; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 43 | } cache_frame; |
| 44 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 45 | struct aom_codec_alg_priv { |
| 46 | aom_codec_priv_t base; |
| 47 | aom_codec_dec_cfg_t cfg; |
| 48 | av1_stream_info_t si; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 49 | int postproc_cfg_set; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 50 | aom_postproc_cfg_t postproc_cfg; |
| 51 | aom_decrypt_cb decrypt_cb; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 52 | void *decrypt_state; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 53 | aom_image_t img; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 54 | int img_avail; |
| 55 | int flushed; |
| 56 | int invert_tile_order; |
| 57 | int last_show_frame; // Index of last output frame. |
| 58 | int byte_alignment; |
| 59 | int skip_loop_filter; |
| 60 | int decode_tile_row; |
| 61 | int decode_tile_col; |
| 62 | |
| 63 | // Frame parallel related. |
| 64 | int frame_parallel_decode; // frame-based threading. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 65 | AVxWorker *frame_workers; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 66 | int num_frame_workers; |
| 67 | int next_submit_worker_id; |
| 68 | int last_submit_worker_id; |
| 69 | int next_output_worker_id; |
| 70 | int available_threads; |
| 71 | cache_frame frame_cache[FRAME_CACHE_SIZE]; |
| 72 | int frame_cache_write; |
| 73 | int frame_cache_read; |
| 74 | int num_cache_frames; |
| 75 | int need_resync; // wait for key/intra-only frame |
| 76 | // BufferPool that holds all reference frames. Shared by all the FrameWorkers. |
| 77 | BufferPool *buffer_pool; |
| 78 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 79 | // External frame buffer info to save for AV1 common. |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 80 | void *ext_priv; // Private data associated with the external frame buffers. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 81 | aom_get_frame_buffer_cb_fn_t get_ext_fb_cb; |
| 82 | aom_release_frame_buffer_cb_fn_t release_ext_fb_cb; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 83 | }; |
| 84 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 85 | static aom_codec_err_t decoder_init(aom_codec_ctx_t *ctx, |
| 86 | aom_codec_priv_enc_mr_cfg_t *data) { |
| 87 | // This function only allocates space for the aom_codec_alg_priv_t |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 88 | // structure. More memory may be required at the time the stream |
| 89 | // information becomes known. |
| 90 | (void)data; |
| 91 | |
| 92 | if (!ctx->priv) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 93 | aom_codec_alg_priv_t *const priv = |
| 94 | (aom_codec_alg_priv_t *)aom_calloc(1, sizeof(*priv)); |
| 95 | if (priv == NULL) return AOM_CODEC_MEM_ERROR; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 96 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 97 | ctx->priv = (aom_codec_priv_t *)priv; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 98 | ctx->priv->init_flags = ctx->init_flags; |
| 99 | priv->si.sz = sizeof(priv->si); |
| 100 | priv->flushed = 0; |
| 101 | // Only do frame parallel decode when threads > 1. |
| 102 | priv->frame_parallel_decode = |
| 103 | (ctx->config.dec && (ctx->config.dec->threads > 1) && |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 104 | (ctx->init_flags & AOM_CODEC_USE_FRAME_THREADING)) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 105 | ? 1 |
| 106 | : 0; |
| 107 | if (ctx->config.dec) { |
| 108 | priv->cfg = *ctx->config.dec; |
| 109 | ctx->config.dec = &priv->cfg; |
| 110 | } |
| 111 | } |
| 112 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 113 | return AOM_CODEC_OK; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 114 | } |
| 115 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 116 | 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] | 117 | if (ctx->frame_workers != NULL) { |
| 118 | int i; |
| 119 | for (i = 0; i < ctx->num_frame_workers; ++i) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 120 | AVxWorker *const worker = &ctx->frame_workers[i]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 121 | FrameWorkerData *const frame_worker_data = |
| 122 | (FrameWorkerData *)worker->data1; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 123 | aom_get_worker_interface()->end(worker); |
| 124 | av1_remove_common(&frame_worker_data->pbi->common); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 125 | #if CONFIG_LOOP_RESTORATION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 126 | av1_free_restoration_buffers(&frame_worker_data->pbi->common); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 127 | #endif // CONFIG_LOOP_RESTORATION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 128 | av1_decoder_remove(frame_worker_data->pbi); |
| 129 | aom_free(frame_worker_data->scratch_buffer); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 130 | #if CONFIG_MULTITHREAD |
| 131 | pthread_mutex_destroy(&frame_worker_data->stats_mutex); |
| 132 | pthread_cond_destroy(&frame_worker_data->stats_cond); |
| 133 | #endif |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 134 | aom_free(frame_worker_data); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 135 | } |
| 136 | #if CONFIG_MULTITHREAD |
| 137 | pthread_mutex_destroy(&ctx->buffer_pool->pool_mutex); |
| 138 | #endif |
| 139 | } |
| 140 | |
| 141 | if (ctx->buffer_pool) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 142 | av1_free_ref_frame_buffers(ctx->buffer_pool); |
| 143 | av1_free_internal_frame_buffers(&ctx->buffer_pool->int_frame_buffers); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 144 | } |
| 145 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 146 | aom_free(ctx->frame_workers); |
| 147 | aom_free(ctx->buffer_pool); |
| 148 | aom_free(ctx); |
| 149 | return AOM_CODEC_OK; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 150 | } |
| 151 | |
| 152 | static int parse_bitdepth_colorspace_sampling(BITSTREAM_PROFILE profile, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 153 | struct aom_read_bit_buffer *rb) { |
| 154 | aom_color_space_t color_space; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 155 | if (profile >= PROFILE_2) rb->bit_offset += 1; // Bit-depth 10 or 12. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 156 | color_space = (aom_color_space_t)aom_rb_read_literal(rb, 3); |
| 157 | if (color_space != AOM_CS_SRGB) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 158 | rb->bit_offset += 1; // [16,235] (including xvycc) vs [0,255] range. |
| 159 | if (profile == PROFILE_1 || profile == PROFILE_3) { |
| 160 | rb->bit_offset += 2; // subsampling x/y. |
| 161 | rb->bit_offset += 1; // unused. |
| 162 | } |
| 163 | } else { |
| 164 | if (profile == PROFILE_1 || profile == PROFILE_3) { |
| 165 | rb->bit_offset += 1; // unused |
| 166 | } else { |
| 167 | // RGB is only available in version 1. |
| 168 | return 0; |
| 169 | } |
| 170 | } |
| 171 | return 1; |
| 172 | } |
| 173 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 174 | static aom_codec_err_t decoder_peek_si_internal( |
| 175 | const uint8_t *data, unsigned int data_sz, aom_codec_stream_info_t *si, |
| 176 | int *is_intra_only, aom_decrypt_cb decrypt_cb, void *decrypt_state) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 177 | int intra_only_flag = 0; |
| 178 | uint8_t clear_buffer[9]; |
| 179 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 180 | if (data + data_sz <= data) return AOM_CODEC_INVALID_PARAM; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 181 | |
| 182 | si->is_kf = 0; |
| 183 | si->w = si->h = 0; |
| 184 | |
| 185 | if (decrypt_cb) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 186 | data_sz = AOMMIN(sizeof(clear_buffer), data_sz); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 187 | decrypt_cb(decrypt_state, data, clear_buffer, data_sz); |
| 188 | data = clear_buffer; |
| 189 | } |
| 190 | |
| 191 | { |
| 192 | int show_frame; |
| 193 | int error_resilient; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 194 | struct aom_read_bit_buffer rb = { data, data + data_sz, 0, NULL, NULL }; |
| 195 | const int frame_marker = aom_rb_read_literal(&rb, 2); |
| 196 | const BITSTREAM_PROFILE profile = av1_read_profile(&rb); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 197 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 198 | if (frame_marker != AOM_FRAME_MARKER) return AOM_CODEC_UNSUP_BITSTREAM; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 199 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 200 | if (profile >= MAX_PROFILES) return AOM_CODEC_UNSUP_BITSTREAM; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 201 | |
| 202 | if ((profile >= 2 && data_sz <= 1) || data_sz < 1) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 203 | return AOM_CODEC_UNSUP_BITSTREAM; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 204 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 205 | if (aom_rb_read_bit(&rb)) { // show an existing frame |
| 206 | aom_rb_read_literal(&rb, 3); // Frame buffer to show. |
| 207 | return AOM_CODEC_OK; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 208 | } |
| 209 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 210 | if (data_sz <= 8) return AOM_CODEC_UNSUP_BITSTREAM; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 211 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 212 | si->is_kf = !aom_rb_read_bit(&rb); |
| 213 | show_frame = aom_rb_read_bit(&rb); |
| 214 | error_resilient = aom_rb_read_bit(&rb); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 215 | |
| 216 | if (si->is_kf) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 217 | if (!av1_read_sync_code(&rb)) return AOM_CODEC_UNSUP_BITSTREAM; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 218 | |
| 219 | if (!parse_bitdepth_colorspace_sampling(profile, &rb)) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 220 | return AOM_CODEC_UNSUP_BITSTREAM; |
| 221 | av1_read_frame_size(&rb, (int *)&si->w, (int *)&si->h); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 222 | } else { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 223 | intra_only_flag = show_frame ? 0 : aom_rb_read_bit(&rb); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 224 | |
| 225 | rb.bit_offset += error_resilient ? 0 : 2; // reset_frame_context |
| 226 | |
| 227 | if (intra_only_flag) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 228 | if (!av1_read_sync_code(&rb)) return AOM_CODEC_UNSUP_BITSTREAM; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 229 | if (profile > PROFILE_0) { |
| 230 | if (!parse_bitdepth_colorspace_sampling(profile, &rb)) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 231 | return AOM_CODEC_UNSUP_BITSTREAM; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 232 | } |
| 233 | rb.bit_offset += REF_FRAMES; // refresh_frame_flags |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 234 | av1_read_frame_size(&rb, (int *)&si->w, (int *)&si->h); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 235 | } |
| 236 | } |
| 237 | } |
| 238 | if (is_intra_only != NULL) *is_intra_only = intra_only_flag; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 239 | return AOM_CODEC_OK; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 240 | } |
| 241 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 242 | static aom_codec_err_t decoder_peek_si(const uint8_t *data, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 243 | unsigned int data_sz, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 244 | aom_codec_stream_info_t *si) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 245 | return decoder_peek_si_internal(data, data_sz, si, NULL, NULL, NULL); |
| 246 | } |
| 247 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 248 | static aom_codec_err_t decoder_get_si(aom_codec_alg_priv_t *ctx, |
| 249 | aom_codec_stream_info_t *si) { |
| 250 | const size_t sz = (si->sz >= sizeof(av1_stream_info_t)) |
| 251 | ? sizeof(av1_stream_info_t) |
| 252 | : sizeof(aom_codec_stream_info_t); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 253 | memcpy(si, &ctx->si, sz); |
| 254 | si->sz = (unsigned int)sz; |
| 255 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 256 | return AOM_CODEC_OK; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 257 | } |
| 258 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 259 | static void set_error_detail(aom_codec_alg_priv_t *ctx, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 260 | const char *const error) { |
| 261 | ctx->base.err_detail = error; |
| 262 | } |
| 263 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 264 | static aom_codec_err_t update_error_state( |
| 265 | 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] | 266 | if (error->error_code) |
| 267 | set_error_detail(ctx, error->has_detail ? error->detail : NULL); |
| 268 | |
| 269 | return error->error_code; |
| 270 | } |
| 271 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 272 | static void init_buffer_callbacks(aom_codec_alg_priv_t *ctx) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 273 | int i; |
| 274 | |
| 275 | for (i = 0; i < ctx->num_frame_workers; ++i) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 276 | AVxWorker *const worker = &ctx->frame_workers[i]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 277 | FrameWorkerData *const frame_worker_data = (FrameWorkerData *)worker->data1; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 278 | AV1_COMMON *const cm = &frame_worker_data->pbi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 279 | BufferPool *const pool = cm->buffer_pool; |
| 280 | |
| 281 | cm->new_fb_idx = INVALID_IDX; |
| 282 | cm->byte_alignment = ctx->byte_alignment; |
| 283 | cm->skip_loop_filter = ctx->skip_loop_filter; |
| 284 | |
| 285 | if (ctx->get_ext_fb_cb != NULL && ctx->release_ext_fb_cb != NULL) { |
| 286 | pool->get_fb_cb = ctx->get_ext_fb_cb; |
| 287 | pool->release_fb_cb = ctx->release_ext_fb_cb; |
| 288 | pool->cb_priv = ctx->ext_priv; |
| 289 | } else { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 290 | pool->get_fb_cb = av1_get_frame_buffer; |
| 291 | pool->release_fb_cb = av1_release_frame_buffer; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 292 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 293 | if (av1_alloc_internal_frame_buffers(&pool->int_frame_buffers)) |
| 294 | aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 295 | "Failed to initialize internal frame buffers"); |
| 296 | |
| 297 | pool->cb_priv = &pool->int_frame_buffers; |
| 298 | } |
| 299 | } |
| 300 | } |
| 301 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 302 | static void set_default_ppflags(aom_postproc_cfg_t *cfg) { |
| 303 | cfg->post_proc_flag = AOM_DEBLOCK | AOM_DEMACROBLOCK; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 304 | cfg->deblocking_level = 4; |
| 305 | cfg->noise_level = 0; |
| 306 | } |
| 307 | |
| 308 | static int frame_worker_hook(void *arg1, void *arg2) { |
| 309 | FrameWorkerData *const frame_worker_data = (FrameWorkerData *)arg1; |
| 310 | const uint8_t *data = frame_worker_data->data; |
| 311 | (void)arg2; |
| 312 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 313 | frame_worker_data->result = av1_receive_compressed_data( |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 314 | frame_worker_data->pbi, frame_worker_data->data_size, &data); |
| 315 | frame_worker_data->data_end = data; |
| 316 | |
| 317 | if (frame_worker_data->pbi->common.frame_parallel_decode) { |
| 318 | // In frame parallel decoding, a worker thread must successfully decode all |
| 319 | // the compressed data. |
| 320 | if (frame_worker_data->result != 0 || |
| 321 | frame_worker_data->data + frame_worker_data->data_size - 1 > data) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 322 | AVxWorker *const worker = frame_worker_data->pbi->frame_worker_owner; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 323 | BufferPool *const pool = frame_worker_data->pbi->common.buffer_pool; |
| 324 | // Signal all the other threads that are waiting for this frame. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 325 | av1_frameworker_lock_stats(worker); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 326 | frame_worker_data->frame_context_ready = 1; |
| 327 | lock_buffer_pool(pool); |
| 328 | frame_worker_data->pbi->cur_buf->buf.corrupted = 1; |
| 329 | unlock_buffer_pool(pool); |
| 330 | frame_worker_data->pbi->need_resync = 1; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 331 | av1_frameworker_signal_stats(worker); |
| 332 | av1_frameworker_unlock_stats(worker); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 333 | return 0; |
| 334 | } |
| 335 | } else if (frame_worker_data->result != 0) { |
| 336 | // Check decode result in serial decode. |
| 337 | frame_worker_data->pbi->cur_buf->buf.corrupted = 1; |
| 338 | frame_worker_data->pbi->need_resync = 1; |
| 339 | } |
| 340 | return !frame_worker_data->result; |
| 341 | } |
| 342 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 343 | 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] | 344 | int i; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 345 | const AVxWorkerInterface *const winterface = aom_get_worker_interface(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 346 | |
| 347 | ctx->last_show_frame = -1; |
| 348 | ctx->next_submit_worker_id = 0; |
| 349 | ctx->last_submit_worker_id = 0; |
| 350 | ctx->next_output_worker_id = 0; |
| 351 | ctx->frame_cache_read = 0; |
| 352 | ctx->frame_cache_write = 0; |
| 353 | ctx->num_cache_frames = 0; |
| 354 | ctx->need_resync = 1; |
| 355 | ctx->num_frame_workers = |
| 356 | (ctx->frame_parallel_decode == 1) ? ctx->cfg.threads : 1; |
| 357 | if (ctx->num_frame_workers > MAX_DECODE_THREADS) |
| 358 | ctx->num_frame_workers = MAX_DECODE_THREADS; |
| 359 | ctx->available_threads = ctx->num_frame_workers; |
| 360 | ctx->flushed = 0; |
| 361 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 362 | ctx->buffer_pool = (BufferPool *)aom_calloc(1, sizeof(BufferPool)); |
| 363 | if (ctx->buffer_pool == NULL) return AOM_CODEC_MEM_ERROR; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 364 | |
| 365 | #if CONFIG_MULTITHREAD |
| 366 | if (pthread_mutex_init(&ctx->buffer_pool->pool_mutex, NULL)) { |
| 367 | set_error_detail(ctx, "Failed to allocate buffer pool mutex"); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 368 | return AOM_CODEC_MEM_ERROR; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 369 | } |
| 370 | #endif |
| 371 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 372 | ctx->frame_workers = (AVxWorker *)aom_malloc(ctx->num_frame_workers * |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 373 | sizeof(*ctx->frame_workers)); |
| 374 | if (ctx->frame_workers == NULL) { |
| 375 | set_error_detail(ctx, "Failed to allocate frame_workers"); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 376 | return AOM_CODEC_MEM_ERROR; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 377 | } |
| 378 | |
| 379 | for (i = 0; i < ctx->num_frame_workers; ++i) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 380 | AVxWorker *const worker = &ctx->frame_workers[i]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 381 | FrameWorkerData *frame_worker_data = NULL; |
| 382 | winterface->init(worker); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 383 | worker->data1 = aom_memalign(32, sizeof(FrameWorkerData)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 384 | if (worker->data1 == NULL) { |
| 385 | set_error_detail(ctx, "Failed to allocate frame_worker_data"); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 386 | return AOM_CODEC_MEM_ERROR; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 387 | } |
| 388 | frame_worker_data = (FrameWorkerData *)worker->data1; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 389 | frame_worker_data->pbi = av1_decoder_create(ctx->buffer_pool); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 390 | if (frame_worker_data->pbi == NULL) { |
| 391 | set_error_detail(ctx, "Failed to allocate frame_worker_data"); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 392 | return AOM_CODEC_MEM_ERROR; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 393 | } |
| 394 | frame_worker_data->pbi->frame_worker_owner = worker; |
| 395 | frame_worker_data->worker_id = i; |
| 396 | frame_worker_data->scratch_buffer = NULL; |
| 397 | frame_worker_data->scratch_buffer_size = 0; |
| 398 | frame_worker_data->frame_context_ready = 0; |
| 399 | frame_worker_data->received_frame = 0; |
| 400 | #if CONFIG_MULTITHREAD |
| 401 | if (pthread_mutex_init(&frame_worker_data->stats_mutex, NULL)) { |
| 402 | set_error_detail(ctx, "Failed to allocate frame_worker_data mutex"); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 403 | return AOM_CODEC_MEM_ERROR; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 404 | } |
| 405 | |
| 406 | if (pthread_cond_init(&frame_worker_data->stats_cond, NULL)) { |
| 407 | set_error_detail(ctx, "Failed to allocate frame_worker_data cond"); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 408 | return AOM_CODEC_MEM_ERROR; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 409 | } |
| 410 | #endif |
| 411 | // If decoding in serial mode, FrameWorker thread could create tile worker |
| 412 | // thread or loopfilter thread. |
| 413 | frame_worker_data->pbi->max_threads = |
| 414 | (ctx->frame_parallel_decode == 0) ? ctx->cfg.threads : 0; |
| 415 | |
| 416 | frame_worker_data->pbi->inv_tile_order = ctx->invert_tile_order; |
| 417 | frame_worker_data->pbi->common.frame_parallel_decode = |
| 418 | ctx->frame_parallel_decode; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 419 | worker->hook = (AVxWorkerHook)frame_worker_hook; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 420 | if (!winterface->reset(worker)) { |
| 421 | set_error_detail(ctx, "Frame Worker thread creation failed"); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 422 | return AOM_CODEC_MEM_ERROR; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 423 | } |
| 424 | } |
| 425 | |
| 426 | // If postprocessing was enabled by the application and a |
| 427 | // configuration has not been provided, default it. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 428 | 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] | 429 | set_default_ppflags(&ctx->postproc_cfg); |
| 430 | |
| 431 | init_buffer_callbacks(ctx); |
| 432 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 433 | return AOM_CODEC_OK; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 434 | } |
| 435 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 436 | static INLINE void check_resync(aom_codec_alg_priv_t *const ctx, |
| 437 | const AV1Decoder *const pbi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 438 | // Clear resync flag if worker got a key frame or intra only frame. |
| 439 | if (ctx->need_resync == 1 && pbi->need_resync == 0 && |
| 440 | (pbi->common.intra_only || pbi->common.frame_type == KEY_FRAME)) |
| 441 | ctx->need_resync = 0; |
| 442 | } |
| 443 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 444 | 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] | 445 | const uint8_t **data, unsigned int data_sz, |
| 446 | void *user_priv, int64_t deadline) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 447 | const AVxWorkerInterface *const winterface = aom_get_worker_interface(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 448 | (void)deadline; |
| 449 | |
| 450 | // Determine the stream parameters. Note that we rely on peek_si to |
| 451 | // validate that we have a buffer that does not wrap around the top |
| 452 | // of the heap. |
| 453 | if (!ctx->si.h) { |
| 454 | int is_intra_only = 0; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 455 | const aom_codec_err_t res = |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 456 | decoder_peek_si_internal(*data, data_sz, &ctx->si, &is_intra_only, |
| 457 | ctx->decrypt_cb, ctx->decrypt_state); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 458 | if (res != AOM_CODEC_OK) return res; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 459 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 460 | if (!ctx->si.is_kf && !is_intra_only) return AOM_CODEC_ERROR; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 461 | } |
| 462 | |
| 463 | if (!ctx->frame_parallel_decode) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 464 | AVxWorker *const worker = ctx->frame_workers; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 465 | FrameWorkerData *const frame_worker_data = (FrameWorkerData *)worker->data1; |
| 466 | frame_worker_data->data = *data; |
| 467 | frame_worker_data->data_size = data_sz; |
| 468 | frame_worker_data->user_priv = user_priv; |
| 469 | frame_worker_data->received_frame = 1; |
| 470 | |
| 471 | // Set these even if already initialized. The caller may have changed the |
| 472 | // decrypt config between frames. |
| 473 | frame_worker_data->pbi->decrypt_cb = ctx->decrypt_cb; |
| 474 | frame_worker_data->pbi->decrypt_state = ctx->decrypt_state; |
| 475 | |
| 476 | #if CONFIG_EXT_TILE |
| 477 | frame_worker_data->pbi->dec_tile_row = ctx->decode_tile_row; |
| 478 | frame_worker_data->pbi->dec_tile_col = ctx->decode_tile_col; |
| 479 | #endif // CONFIG_EXT_TILE |
| 480 | |
| 481 | worker->had_error = 0; |
| 482 | winterface->execute(worker); |
| 483 | |
| 484 | // Update data pointer after decode. |
| 485 | *data = frame_worker_data->data_end; |
| 486 | |
| 487 | if (worker->had_error) |
| 488 | return update_error_state(ctx, &frame_worker_data->pbi->common.error); |
| 489 | |
| 490 | check_resync(ctx, frame_worker_data->pbi); |
| 491 | } else { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 492 | AVxWorker *const worker = &ctx->frame_workers[ctx->next_submit_worker_id]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 493 | FrameWorkerData *const frame_worker_data = (FrameWorkerData *)worker->data1; |
| 494 | // Copy context from last worker thread to next worker thread. |
| 495 | if (ctx->next_submit_worker_id != ctx->last_submit_worker_id) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 496 | av1_frameworker_copy_context( |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 497 | &ctx->frame_workers[ctx->next_submit_worker_id], |
| 498 | &ctx->frame_workers[ctx->last_submit_worker_id]); |
| 499 | |
| 500 | frame_worker_data->pbi->ready_for_new_data = 0; |
| 501 | // Copy the compressed data into worker's internal buffer. |
| 502 | // TODO(hkuang): Will all the workers allocate the same size |
| 503 | // as the size of the first intra frame be better? This will |
| 504 | // avoid too many deallocate and allocate. |
| 505 | if (frame_worker_data->scratch_buffer_size < data_sz) { |
| 506 | frame_worker_data->scratch_buffer = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 507 | (uint8_t *)aom_realloc(frame_worker_data->scratch_buffer, data_sz); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 508 | if (frame_worker_data->scratch_buffer == NULL) { |
| 509 | set_error_detail(ctx, "Failed to reallocate scratch buffer"); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 510 | return AOM_CODEC_MEM_ERROR; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 511 | } |
| 512 | frame_worker_data->scratch_buffer_size = data_sz; |
| 513 | } |
| 514 | frame_worker_data->data_size = data_sz; |
| 515 | memcpy(frame_worker_data->scratch_buffer, *data, data_sz); |
| 516 | |
| 517 | frame_worker_data->frame_decoded = 0; |
| 518 | frame_worker_data->frame_context_ready = 0; |
| 519 | frame_worker_data->received_frame = 1; |
| 520 | frame_worker_data->data = frame_worker_data->scratch_buffer; |
| 521 | frame_worker_data->user_priv = user_priv; |
| 522 | |
| 523 | if (ctx->next_submit_worker_id != ctx->last_submit_worker_id) |
| 524 | ctx->last_submit_worker_id = |
| 525 | (ctx->last_submit_worker_id + 1) % ctx->num_frame_workers; |
| 526 | |
| 527 | ctx->next_submit_worker_id = |
| 528 | (ctx->next_submit_worker_id + 1) % ctx->num_frame_workers; |
| 529 | --ctx->available_threads; |
| 530 | worker->had_error = 0; |
| 531 | winterface->launch(worker); |
| 532 | } |
| 533 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 534 | return AOM_CODEC_OK; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 535 | } |
| 536 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 537 | 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] | 538 | YV12_BUFFER_CONFIG sd; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 539 | const AVxWorkerInterface *const winterface = aom_get_worker_interface(); |
| 540 | AVxWorker *const worker = &ctx->frame_workers[ctx->next_output_worker_id]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 541 | FrameWorkerData *const frame_worker_data = (FrameWorkerData *)worker->data1; |
| 542 | ctx->next_output_worker_id = |
| 543 | (ctx->next_output_worker_id + 1) % ctx->num_frame_workers; |
| 544 | // TODO(hkuang): Add worker error handling here. |
| 545 | winterface->sync(worker); |
| 546 | frame_worker_data->received_frame = 0; |
| 547 | ++ctx->available_threads; |
| 548 | |
| 549 | check_resync(ctx, frame_worker_data->pbi); |
| 550 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 551 | if (av1_get_raw_frame(frame_worker_data->pbi, &sd) == 0) { |
| 552 | AV1_COMMON *const cm = &frame_worker_data->pbi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 553 | RefCntBuffer *const frame_bufs = cm->buffer_pool->frame_bufs; |
| 554 | ctx->frame_cache[ctx->frame_cache_write].fb_idx = cm->new_fb_idx; |
| 555 | yuvconfig2image(&ctx->frame_cache[ctx->frame_cache_write].img, &sd, |
| 556 | frame_worker_data->user_priv); |
| 557 | ctx->frame_cache[ctx->frame_cache_write].img.fb_priv = |
| 558 | frame_bufs[cm->new_fb_idx].raw_frame_buffer.priv; |
| 559 | ctx->frame_cache_write = (ctx->frame_cache_write + 1) % FRAME_CACHE_SIZE; |
| 560 | ++ctx->num_cache_frames; |
| 561 | } |
| 562 | } |
| 563 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 564 | 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] | 565 | const uint8_t *data, unsigned int data_sz, |
| 566 | void *user_priv, long deadline) { |
| 567 | const uint8_t *data_start = data; |
| 568 | const uint8_t *const data_end = data + data_sz; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 569 | aom_codec_err_t res; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 570 | uint32_t frame_sizes[8]; |
| 571 | int frame_count; |
| 572 | |
| 573 | if (data == NULL && data_sz == 0) { |
| 574 | ctx->flushed = 1; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 575 | return AOM_CODEC_OK; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 576 | } |
| 577 | |
| 578 | // Reset flushed when receiving a valid frame. |
| 579 | ctx->flushed = 0; |
| 580 | |
| 581 | // Initialize the decoder workers on the first frame. |
| 582 | if (ctx->frame_workers == NULL) { |
Urvang Joshi | 454280d | 2016-10-14 16:51:44 -0700 | [diff] [blame] | 583 | res = init_decoder(ctx); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 584 | if (res != AOM_CODEC_OK) return res; |
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 | res = av1_parse_superframe_index(data, data_sz, frame_sizes, &frame_count, |
| 588 | ctx->decrypt_cb, ctx->decrypt_state); |
| 589 | if (res != AOM_CODEC_OK) return res; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 590 | |
| 591 | if (ctx->frame_parallel_decode) { |
| 592 | // Decode in frame parallel mode. When decoding in this mode, the frame |
| 593 | // passed to the decoder must be either a normal frame or a superframe with |
| 594 | // superframe index so the decoder could get each frame's start position |
| 595 | // in the superframe. |
| 596 | if (frame_count > 0) { |
| 597 | int i; |
| 598 | |
| 599 | for (i = 0; i < frame_count; ++i) { |
| 600 | const uint8_t *data_start_copy = data_start; |
| 601 | const uint32_t frame_size = frame_sizes[i]; |
| 602 | if (data_start < data || |
| 603 | frame_size > (uint32_t)(data_end - data_start)) { |
| 604 | set_error_detail(ctx, "Invalid frame size in index"); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 605 | return AOM_CODEC_CORRUPT_FRAME; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 606 | } |
| 607 | |
| 608 | if (ctx->available_threads == 0) { |
| 609 | // No more threads for decoding. Wait until the next output worker |
| 610 | // finishes decoding. Then copy the decoded frame into cache. |
| 611 | if (ctx->num_cache_frames < FRAME_CACHE_SIZE) { |
| 612 | wait_worker_and_cache_frame(ctx); |
| 613 | } else { |
| 614 | // TODO(hkuang): Add unit test to test this path. |
| 615 | set_error_detail(ctx, "Frame output cache is full."); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 616 | return AOM_CODEC_ERROR; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 617 | } |
| 618 | } |
| 619 | |
| 620 | res = |
| 621 | decode_one(ctx, &data_start_copy, frame_size, user_priv, deadline); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 622 | if (res != AOM_CODEC_OK) return res; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 623 | data_start += frame_size; |
| 624 | } |
| 625 | } else { |
| 626 | if (ctx->available_threads == 0) { |
| 627 | // No more threads for decoding. Wait until the next output worker |
| 628 | // finishes decoding. Then copy the decoded frame into cache. |
| 629 | if (ctx->num_cache_frames < FRAME_CACHE_SIZE) { |
| 630 | wait_worker_and_cache_frame(ctx); |
| 631 | } else { |
| 632 | // TODO(hkuang): Add unit test to test this path. |
| 633 | set_error_detail(ctx, "Frame output cache is full."); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 634 | return AOM_CODEC_ERROR; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 635 | } |
| 636 | } |
| 637 | |
| 638 | res = decode_one(ctx, &data, data_sz, user_priv, deadline); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 639 | if (res != AOM_CODEC_OK) return res; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 640 | } |
| 641 | } else { |
| 642 | // Decode in serial mode. |
| 643 | if (frame_count > 0) { |
| 644 | int i; |
| 645 | |
| 646 | for (i = 0; i < frame_count; ++i) { |
| 647 | const uint8_t *data_start_copy = data_start; |
| 648 | const uint32_t frame_size = frame_sizes[i]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 649 | if (data_start < data || |
| 650 | frame_size > (uint32_t)(data_end - data_start)) { |
| 651 | set_error_detail(ctx, "Invalid frame size in index"); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 652 | return AOM_CODEC_CORRUPT_FRAME; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 653 | } |
| 654 | |
| 655 | res = |
| 656 | decode_one(ctx, &data_start_copy, frame_size, user_priv, deadline); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 657 | if (res != AOM_CODEC_OK) return res; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 658 | |
| 659 | data_start += frame_size; |
| 660 | } |
| 661 | } else { |
| 662 | while (data_start < data_end) { |
| 663 | const uint32_t frame_size = (uint32_t)(data_end - data_start); |
Urvang Joshi | 454280d | 2016-10-14 16:51:44 -0700 | [diff] [blame] | 664 | res = decode_one(ctx, &data_start, frame_size, user_priv, deadline); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 665 | if (res != AOM_CODEC_OK) return res; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 666 | |
| 667 | // Account for suboptimal termination by the encoder. |
| 668 | while (data_start < data_end) { |
| 669 | const uint8_t marker = |
| 670 | read_marker(ctx->decrypt_cb, ctx->decrypt_state, data_start); |
| 671 | if (marker) break; |
| 672 | ++data_start; |
| 673 | } |
| 674 | } |
| 675 | } |
| 676 | } |
| 677 | |
| 678 | return res; |
| 679 | } |
| 680 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 681 | static void release_last_output_frame(aom_codec_alg_priv_t *ctx) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 682 | RefCntBuffer *const frame_bufs = ctx->buffer_pool->frame_bufs; |
| 683 | // Decrease reference count of last output frame in frame parallel mode. |
| 684 | if (ctx->frame_parallel_decode && ctx->last_show_frame >= 0) { |
| 685 | BufferPool *const pool = ctx->buffer_pool; |
| 686 | lock_buffer_pool(pool); |
| 687 | decrease_ref_count(ctx->last_show_frame, frame_bufs, pool); |
| 688 | unlock_buffer_pool(pool); |
| 689 | } |
| 690 | } |
| 691 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 692 | static aom_image_t *decoder_get_frame(aom_codec_alg_priv_t *ctx, |
| 693 | aom_codec_iter_t *iter) { |
| 694 | aom_image_t *img = NULL; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 695 | |
| 696 | // Only return frame when all the cpu are busy or |
| 697 | // application fluhsed the decoder in frame parallel decode. |
| 698 | if (ctx->frame_parallel_decode && ctx->available_threads > 0 && |
| 699 | !ctx->flushed) { |
| 700 | return NULL; |
| 701 | } |
| 702 | |
| 703 | // Output the frames in the cache first. |
| 704 | if (ctx->num_cache_frames > 0) { |
| 705 | release_last_output_frame(ctx); |
| 706 | ctx->last_show_frame = ctx->frame_cache[ctx->frame_cache_read].fb_idx; |
| 707 | if (ctx->need_resync) return NULL; |
| 708 | img = &ctx->frame_cache[ctx->frame_cache_read].img; |
| 709 | ctx->frame_cache_read = (ctx->frame_cache_read + 1) % FRAME_CACHE_SIZE; |
| 710 | --ctx->num_cache_frames; |
| 711 | return img; |
| 712 | } |
| 713 | |
| 714 | // iter acts as a flip flop, so an image is only returned on the first |
| 715 | // call to get_frame. |
| 716 | if (*iter == NULL && ctx->frame_workers != NULL) { |
| 717 | do { |
| 718 | YV12_BUFFER_CONFIG sd; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 719 | const AVxWorkerInterface *const winterface = aom_get_worker_interface(); |
| 720 | AVxWorker *const worker = &ctx->frame_workers[ctx->next_output_worker_id]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 721 | FrameWorkerData *const frame_worker_data = |
| 722 | (FrameWorkerData *)worker->data1; |
| 723 | ctx->next_output_worker_id = |
| 724 | (ctx->next_output_worker_id + 1) % ctx->num_frame_workers; |
| 725 | // Wait for the frame from worker thread. |
| 726 | if (winterface->sync(worker)) { |
| 727 | // Check if worker has received any frames. |
| 728 | if (frame_worker_data->received_frame == 1) { |
| 729 | ++ctx->available_threads; |
| 730 | frame_worker_data->received_frame = 0; |
| 731 | check_resync(ctx, frame_worker_data->pbi); |
| 732 | } |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 733 | if (av1_get_raw_frame(frame_worker_data->pbi, &sd) == 0) { |
| 734 | AV1_COMMON *const cm = &frame_worker_data->pbi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 735 | RefCntBuffer *const frame_bufs = cm->buffer_pool->frame_bufs; |
| 736 | release_last_output_frame(ctx); |
| 737 | ctx->last_show_frame = frame_worker_data->pbi->common.new_fb_idx; |
| 738 | if (ctx->need_resync) return NULL; |
| 739 | yuvconfig2image(&ctx->img, &sd, frame_worker_data->user_priv); |
| 740 | |
| 741 | #if CONFIG_EXT_TILE |
| 742 | if (frame_worker_data->pbi->dec_tile_row >= 0) { |
| 743 | const int tile_row = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 744 | AOMMIN(frame_worker_data->pbi->dec_tile_row, cm->tile_rows - 1); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 745 | const int mi_row = tile_row * cm->tile_height; |
| 746 | const int ssy = ctx->img.y_chroma_shift; |
| 747 | int plane; |
| 748 | ctx->img.planes[0] += mi_row * MI_SIZE * ctx->img.stride[0]; |
| 749 | for (plane = 1; plane < MAX_MB_PLANE; ++plane) { |
| 750 | ctx->img.planes[plane] += |
| 751 | mi_row * (MI_SIZE >> ssy) * ctx->img.stride[plane]; |
| 752 | } |
| 753 | ctx->img.d_h = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 754 | AOMMIN(cm->tile_height, cm->mi_rows - mi_row) * MI_SIZE; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 755 | } |
| 756 | |
| 757 | if (frame_worker_data->pbi->dec_tile_col >= 0) { |
| 758 | const int tile_col = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 759 | AOMMIN(frame_worker_data->pbi->dec_tile_col, cm->tile_cols - 1); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 760 | const int mi_col = tile_col * cm->tile_width; |
| 761 | const int ssx = ctx->img.x_chroma_shift; |
| 762 | int plane; |
| 763 | ctx->img.planes[0] += mi_col * MI_SIZE; |
| 764 | for (plane = 1; plane < MAX_MB_PLANE; ++plane) { |
| 765 | ctx->img.planes[plane] += mi_col * (MI_SIZE >> ssx); |
| 766 | } |
| 767 | ctx->img.d_w = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 768 | AOMMIN(cm->tile_width, cm->mi_cols - mi_col) * MI_SIZE; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 769 | } |
| 770 | #endif // CONFIG_EXT_TILE |
| 771 | |
| 772 | ctx->img.fb_priv = frame_bufs[cm->new_fb_idx].raw_frame_buffer.priv; |
| 773 | img = &ctx->img; |
| 774 | return img; |
| 775 | } |
| 776 | } else { |
| 777 | // Decoding failed. Release the worker thread. |
| 778 | frame_worker_data->received_frame = 0; |
| 779 | ++ctx->available_threads; |
| 780 | ctx->need_resync = 1; |
| 781 | if (ctx->flushed != 1) return NULL; |
| 782 | } |
| 783 | } while (ctx->next_output_worker_id != ctx->next_submit_worker_id); |
| 784 | } |
| 785 | return NULL; |
| 786 | } |
| 787 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 788 | static aom_codec_err_t decoder_set_fb_fn( |
| 789 | aom_codec_alg_priv_t *ctx, aom_get_frame_buffer_cb_fn_t cb_get, |
| 790 | aom_release_frame_buffer_cb_fn_t cb_release, void *cb_priv) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 791 | if (cb_get == NULL || cb_release == NULL) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 792 | return AOM_CODEC_INVALID_PARAM; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 793 | } else if (ctx->frame_workers == NULL) { |
| 794 | // If the decoder has already been initialized, do not accept changes to |
| 795 | // the frame buffer functions. |
| 796 | ctx->get_ext_fb_cb = cb_get; |
| 797 | ctx->release_ext_fb_cb = cb_release; |
| 798 | ctx->ext_priv = cb_priv; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 799 | return AOM_CODEC_OK; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 800 | } |
| 801 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 802 | return AOM_CODEC_ERROR; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 803 | } |
| 804 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 805 | 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] | 806 | va_list args) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 807 | aom_ref_frame_t *const data = va_arg(args, aom_ref_frame_t *); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 808 | |
| 809 | // Only support this function in serial decode. |
| 810 | if (ctx->frame_parallel_decode) { |
| 811 | set_error_detail(ctx, "Not supported in frame parallel decode"); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 812 | return AOM_CODEC_INCAPABLE; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 813 | } |
| 814 | |
| 815 | if (data) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 816 | aom_ref_frame_t *const frame = (aom_ref_frame_t *)data; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 817 | YV12_BUFFER_CONFIG sd; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 818 | AVxWorker *const worker = ctx->frame_workers; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 819 | FrameWorkerData *const frame_worker_data = (FrameWorkerData *)worker->data1; |
| 820 | image2yuvconfig(&frame->img, &sd); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 821 | return av1_set_reference_dec(&frame_worker_data->pbi->common, |
| 822 | ref_frame_to_av1_reframe(frame->frame_type), |
| 823 | &sd); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 824 | } else { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 825 | return AOM_CODEC_INVALID_PARAM; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 826 | } |
| 827 | } |
| 828 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 829 | 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] | 830 | va_list args) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 831 | aom_ref_frame_t *data = va_arg(args, aom_ref_frame_t *); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 832 | |
| 833 | // Only support this function in serial decode. |
| 834 | if (ctx->frame_parallel_decode) { |
| 835 | set_error_detail(ctx, "Not supported in frame parallel decode"); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 836 | return AOM_CODEC_INCAPABLE; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 837 | } |
| 838 | |
| 839 | if (data) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 840 | aom_ref_frame_t *frame = (aom_ref_frame_t *)data; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 841 | YV12_BUFFER_CONFIG sd; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 842 | AVxWorker *const worker = ctx->frame_workers; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 843 | FrameWorkerData *const frame_worker_data = (FrameWorkerData *)worker->data1; |
| 844 | image2yuvconfig(&frame->img, &sd); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 845 | return av1_copy_reference_dec(frame_worker_data->pbi, |
| 846 | (AOM_REFFRAME)frame->frame_type, &sd); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 847 | } else { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 848 | return AOM_CODEC_INVALID_PARAM; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 849 | } |
| 850 | } |
| 851 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 852 | 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] | 853 | va_list args) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 854 | av1_ref_frame_t *data = va_arg(args, av1_ref_frame_t *); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 855 | |
| 856 | // Only support this function in serial decode. |
| 857 | if (ctx->frame_parallel_decode) { |
| 858 | set_error_detail(ctx, "Not supported in frame parallel decode"); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 859 | return AOM_CODEC_INCAPABLE; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 860 | } |
| 861 | |
| 862 | if (data) { |
| 863 | YV12_BUFFER_CONFIG *fb; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 864 | AVxWorker *const worker = ctx->frame_workers; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 865 | FrameWorkerData *const frame_worker_data = (FrameWorkerData *)worker->data1; |
| 866 | fb = get_ref_frame(&frame_worker_data->pbi->common, data->idx); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 867 | if (fb == NULL) return AOM_CODEC_ERROR; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 868 | yuvconfig2image(&data->img, fb, NULL); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 869 | return AOM_CODEC_OK; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 870 | } else { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 871 | return AOM_CODEC_INVALID_PARAM; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 872 | } |
| 873 | } |
| 874 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 875 | 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] | 876 | va_list args) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 877 | aom_image_t *new_img = va_arg(args, aom_image_t *); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 878 | |
| 879 | // Only support this function in serial decode. |
| 880 | if (ctx->frame_parallel_decode) { |
| 881 | set_error_detail(ctx, "Not supported in frame parallel decode"); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 882 | return AOM_CODEC_INCAPABLE; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 883 | } |
| 884 | |
| 885 | if (new_img) { |
| 886 | YV12_BUFFER_CONFIG new_frame; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 887 | AVxWorker *const worker = ctx->frame_workers; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 888 | FrameWorkerData *const frame_worker_data = (FrameWorkerData *)worker->data1; |
| 889 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 890 | 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] | 891 | yuvconfig2image(new_img, &new_frame, NULL); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 892 | return AOM_CODEC_OK; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 893 | } else { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 894 | return AOM_CODEC_ERROR; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 895 | } |
| 896 | } else { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 897 | return AOM_CODEC_INVALID_PARAM; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 898 | } |
| 899 | } |
| 900 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 901 | 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] | 902 | va_list args) { |
| 903 | (void)ctx; |
| 904 | (void)args; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 905 | return AOM_CODEC_INCAPABLE; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 906 | } |
| 907 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 908 | 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] | 909 | va_list args) { |
| 910 | (void)ctx; |
| 911 | (void)args; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 912 | return AOM_CODEC_INCAPABLE; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 913 | } |
| 914 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 915 | 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] | 916 | va_list args) { |
| 917 | int *const update_info = va_arg(args, int *); |
| 918 | |
| 919 | // Only support this function in serial decode. |
| 920 | if (ctx->frame_parallel_decode) { |
| 921 | set_error_detail(ctx, "Not supported in frame parallel decode"); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 922 | return AOM_CODEC_INCAPABLE; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 923 | } |
| 924 | |
| 925 | if (update_info) { |
| 926 | if (ctx->frame_workers) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 927 | AVxWorker *const worker = ctx->frame_workers; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 928 | FrameWorkerData *const frame_worker_data = |
| 929 | (FrameWorkerData *)worker->data1; |
| 930 | *update_info = frame_worker_data->pbi->refresh_frame_flags; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 931 | return AOM_CODEC_OK; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 932 | } else { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 933 | return AOM_CODEC_ERROR; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 934 | } |
| 935 | } |
| 936 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 937 | return AOM_CODEC_INVALID_PARAM; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 938 | } |
| 939 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 940 | 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] | 941 | va_list args) { |
| 942 | int *corrupted = va_arg(args, int *); |
| 943 | |
| 944 | if (corrupted) { |
| 945 | if (ctx->frame_workers) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 946 | AVxWorker *const worker = ctx->frame_workers; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 947 | FrameWorkerData *const frame_worker_data = |
| 948 | (FrameWorkerData *)worker->data1; |
| 949 | RefCntBuffer *const frame_bufs = |
| 950 | frame_worker_data->pbi->common.buffer_pool->frame_bufs; |
| 951 | if (frame_worker_data->pbi->common.frame_to_show == NULL) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 952 | return AOM_CODEC_ERROR; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 953 | if (ctx->last_show_frame >= 0) |
| 954 | *corrupted = frame_bufs[ctx->last_show_frame].buf.corrupted; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 955 | return AOM_CODEC_OK; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 956 | } else { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 957 | return AOM_CODEC_ERROR; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 958 | } |
| 959 | } |
| 960 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 961 | return AOM_CODEC_INVALID_PARAM; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 962 | } |
| 963 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 964 | 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] | 965 | va_list args) { |
| 966 | int *const frame_size = va_arg(args, int *); |
| 967 | |
| 968 | // Only support this function in serial decode. |
| 969 | if (ctx->frame_parallel_decode) { |
| 970 | set_error_detail(ctx, "Not supported in frame parallel decode"); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 971 | return AOM_CODEC_INCAPABLE; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 972 | } |
| 973 | |
| 974 | if (frame_size) { |
| 975 | if (ctx->frame_workers) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 976 | AVxWorker *const worker = ctx->frame_workers; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 977 | FrameWorkerData *const frame_worker_data = |
| 978 | (FrameWorkerData *)worker->data1; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 979 | const AV1_COMMON *const cm = &frame_worker_data->pbi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 980 | frame_size[0] = cm->width; |
| 981 | frame_size[1] = cm->height; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 982 | return AOM_CODEC_OK; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 983 | } else { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 984 | return AOM_CODEC_ERROR; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 985 | } |
| 986 | } |
| 987 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 988 | return AOM_CODEC_INVALID_PARAM; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 989 | } |
| 990 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 991 | 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] | 992 | va_list args) { |
| 993 | int *const render_size = va_arg(args, int *); |
| 994 | |
| 995 | // Only support this function in serial decode. |
| 996 | if (ctx->frame_parallel_decode) { |
| 997 | set_error_detail(ctx, "Not supported in frame parallel decode"); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 998 | return AOM_CODEC_INCAPABLE; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 999 | } |
| 1000 | |
| 1001 | if (render_size) { |
| 1002 | if (ctx->frame_workers) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1003 | AVxWorker *const worker = ctx->frame_workers; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1004 | FrameWorkerData *const frame_worker_data = |
| 1005 | (FrameWorkerData *)worker->data1; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1006 | const AV1_COMMON *const cm = &frame_worker_data->pbi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1007 | render_size[0] = cm->render_width; |
| 1008 | render_size[1] = cm->render_height; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1009 | return AOM_CODEC_OK; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1010 | } else { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1011 | return AOM_CODEC_ERROR; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1012 | } |
| 1013 | } |
| 1014 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1015 | return AOM_CODEC_INVALID_PARAM; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1016 | } |
| 1017 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1018 | 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] | 1019 | va_list args) { |
| 1020 | unsigned int *const bit_depth = va_arg(args, unsigned int *); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1021 | AVxWorker *const worker = &ctx->frame_workers[ctx->next_output_worker_id]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1022 | |
| 1023 | if (bit_depth) { |
| 1024 | if (worker) { |
| 1025 | FrameWorkerData *const frame_worker_data = |
| 1026 | (FrameWorkerData *)worker->data1; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1027 | const AV1_COMMON *const cm = &frame_worker_data->pbi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1028 | *bit_depth = cm->bit_depth; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1029 | return AOM_CODEC_OK; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1030 | } else { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1031 | return AOM_CODEC_ERROR; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1032 | } |
| 1033 | } |
| 1034 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1035 | return AOM_CODEC_INVALID_PARAM; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1036 | } |
| 1037 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1038 | 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] | 1039 | va_list args) { |
| 1040 | ctx->invert_tile_order = va_arg(args, int); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1041 | return AOM_CODEC_OK; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1042 | } |
| 1043 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1044 | static aom_codec_err_t ctrl_set_decryptor(aom_codec_alg_priv_t *ctx, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1045 | va_list args) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1046 | aom_decrypt_init *init = va_arg(args, aom_decrypt_init *); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1047 | ctx->decrypt_cb = init ? init->decrypt_cb : NULL; |
| 1048 | ctx->decrypt_state = init ? init->decrypt_state : NULL; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1049 | return AOM_CODEC_OK; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1050 | } |
| 1051 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1052 | 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] | 1053 | va_list args) { |
| 1054 | const int legacy_byte_alignment = 0; |
| 1055 | const int min_byte_alignment = 32; |
| 1056 | const int max_byte_alignment = 1024; |
| 1057 | const int byte_alignment = va_arg(args, int); |
| 1058 | |
| 1059 | if (byte_alignment != legacy_byte_alignment && |
| 1060 | (byte_alignment < min_byte_alignment || |
| 1061 | byte_alignment > max_byte_alignment || |
| 1062 | (byte_alignment & (byte_alignment - 1)) != 0)) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1063 | return AOM_CODEC_INVALID_PARAM; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1064 | |
| 1065 | ctx->byte_alignment = byte_alignment; |
| 1066 | if (ctx->frame_workers) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1067 | AVxWorker *const worker = ctx->frame_workers; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1068 | FrameWorkerData *const frame_worker_data = (FrameWorkerData *)worker->data1; |
| 1069 | frame_worker_data->pbi->common.byte_alignment = byte_alignment; |
| 1070 | } |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1071 | return AOM_CODEC_OK; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1072 | } |
| 1073 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1074 | 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] | 1075 | va_list args) { |
| 1076 | ctx->skip_loop_filter = va_arg(args, int); |
| 1077 | |
| 1078 | if (ctx->frame_workers) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1079 | AVxWorker *const worker = ctx->frame_workers; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1080 | FrameWorkerData *const frame_worker_data = (FrameWorkerData *)worker->data1; |
| 1081 | frame_worker_data->pbi->common.skip_loop_filter = ctx->skip_loop_filter; |
| 1082 | } |
| 1083 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1084 | return AOM_CODEC_OK; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1085 | } |
| 1086 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1087 | 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] | 1088 | va_list args) { |
| 1089 | ctx->decode_tile_row = va_arg(args, int); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1090 | return AOM_CODEC_OK; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1091 | } |
| 1092 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1093 | 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] | 1094 | va_list args) { |
| 1095 | ctx->decode_tile_col = va_arg(args, int); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1096 | return AOM_CODEC_OK; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1097 | } |
| 1098 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1099 | static aom_codec_ctrl_fn_map_t decoder_ctrl_maps[] = { |
| 1100 | { AOM_COPY_REFERENCE, ctrl_copy_reference }, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1101 | |
| 1102 | // Setters |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1103 | { AOM_SET_REFERENCE, ctrl_set_reference }, |
| 1104 | { AOM_SET_POSTPROC, ctrl_set_postproc }, |
| 1105 | { AOM_SET_DBG_COLOR_REF_FRAME, ctrl_set_dbg_options }, |
| 1106 | { AOM_SET_DBG_COLOR_MB_MODES, ctrl_set_dbg_options }, |
| 1107 | { AOM_SET_DBG_COLOR_B_MODES, ctrl_set_dbg_options }, |
| 1108 | { AOM_SET_DBG_DISPLAY_MV, ctrl_set_dbg_options }, |
| 1109 | { AV1_INVERT_TILE_DECODE_ORDER, ctrl_set_invert_tile_order }, |
| 1110 | { AOMD_SET_DECRYPTOR, ctrl_set_decryptor }, |
| 1111 | { AV1_SET_BYTE_ALIGNMENT, ctrl_set_byte_alignment }, |
| 1112 | { AV1_SET_SKIP_LOOP_FILTER, ctrl_set_skip_loop_filter }, |
| 1113 | { AV1_SET_DECODE_TILE_ROW, ctrl_set_decode_tile_row }, |
| 1114 | { AV1_SET_DECODE_TILE_COL, ctrl_set_decode_tile_col }, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1115 | |
| 1116 | // Getters |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1117 | { AOMD_GET_LAST_REF_UPDATES, ctrl_get_last_ref_updates }, |
| 1118 | { AOMD_GET_FRAME_CORRUPTED, ctrl_get_frame_corrupted }, |
| 1119 | { AV1_GET_REFERENCE, ctrl_get_reference }, |
| 1120 | { AV1D_GET_DISPLAY_SIZE, ctrl_get_render_size }, |
| 1121 | { AV1D_GET_BIT_DEPTH, ctrl_get_bit_depth }, |
| 1122 | { AV1D_GET_FRAME_SIZE, ctrl_get_frame_size }, |
| 1123 | { AV1_GET_NEW_FRAME_IMAGE, ctrl_get_new_frame_image }, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1124 | |
| 1125 | { -1, NULL }, |
| 1126 | }; |
| 1127 | |
| 1128 | #ifndef VERSION_STRING |
| 1129 | #define VERSION_STRING |
| 1130 | #endif |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1131 | CODEC_INTERFACE(aom_codec_av1_dx) = { |
| 1132 | "AOMedia Project AV1 Decoder" VERSION_STRING, |
| 1133 | AOM_CODEC_INTERNAL_ABI_VERSION, |
| 1134 | AOM_CODEC_CAP_DECODER | |
| 1135 | AOM_CODEC_CAP_EXTERNAL_FRAME_BUFFER, // aom_codec_caps_t |
| 1136 | decoder_init, // aom_codec_init_fn_t |
| 1137 | decoder_destroy, // aom_codec_destroy_fn_t |
| 1138 | decoder_ctrl_maps, // aom_codec_ctrl_fn_map_t |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1139 | { |
| 1140 | // NOLINT |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1141 | decoder_peek_si, // aom_codec_peek_si_fn_t |
| 1142 | decoder_get_si, // aom_codec_get_si_fn_t |
| 1143 | decoder_decode, // aom_codec_decode_fn_t |
| 1144 | decoder_get_frame, // aom_codec_frame_get_fn_t |
| 1145 | decoder_set_fb_fn, // aom_codec_set_fb_fn_t |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1146 | }, |
| 1147 | { |
| 1148 | // NOLINT |
| 1149 | 0, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1150 | NULL, // aom_codec_enc_cfg_map_t |
| 1151 | NULL, // aom_codec_encode_fn_t |
| 1152 | NULL, // aom_codec_get_cx_data_fn_t |
| 1153 | NULL, // aom_codec_enc_config_set_fn_t |
| 1154 | NULL, // aom_codec_get_global_headers_fn_t |
| 1155 | NULL, // aom_codec_get_preview_frame_fn_t |
| 1156 | NULL // aom_codec_enc_mr_get_mem_loc_fn_t |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1157 | } |
| 1158 | }; |