blob: e84c9e7086784ed2eb458faba32ba7c53ac32f32 [file] [log] [blame]
Yaowu Xuc27fc142016-08-22 16:08:15 -07001/*
Yaowu Xu9c01aa12016-09-01 14:32:49 -07002 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
Yaowu Xuc27fc142016-08-22 16:08:15 -07003 *
Yaowu Xu9c01aa12016-09-01 14:32:49 -07004 * This source code is subject to the terms of the BSD 2 Clause License and
5 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6 * was not distributed with this source code in the LICENSE file, you can
7 * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8 * Media Patent License 1.0 was not distributed with this source code in the
9 * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
Yaowu Xuc27fc142016-08-22 16:08:15 -070010 */
11
12#include <stdlib.h>
13#include <string.h>
14
Yaowu Xuf883b422016-08-30 14:01:10 -070015#include "./aom_config.h"
16#include "aom/aom_encoder.h"
17#include "aom_ports/aom_once.h"
Yaowu Xuc27fc142016-08-22 16:08:15 -070018#include "aom_ports/system_state.h"
Yaowu Xuf883b422016-08-30 14:01:10 -070019#include "aom/internal/aom_codec_internal.h"
20#include "./aom_version.h"
Yaowu Xuc27fc142016-08-22 16:08:15 -070021#include "av1/encoder/encoder.h"
Yaowu Xuf883b422016-08-30 14:01:10 -070022#include "aom/aomcx.h"
Yaowu Xuc27fc142016-08-22 16:08:15 -070023#include "av1/encoder/firstpass.h"
Yaowu Xuf883b422016-08-30 14:01:10 -070024#include "av1/av1_iface_common.h"
Yaowu Xuc27fc142016-08-22 16:08:15 -070025
Yaowu Xuf883b422016-08-30 14:01:10 -070026struct av1_extracfg {
Yaowu Xuc27fc142016-08-22 16:08:15 -070027 int cpu_used; // available cpu percentage in 1/16
28 unsigned int enable_auto_alt_ref;
29#if CONFIG_EXT_REFS
30 unsigned int enable_auto_bwd_ref;
31#endif // CONFIG_EXT_REFS
32 unsigned int noise_sensitivity;
33 unsigned int sharpness;
34 unsigned int static_thresh;
35 unsigned int tile_columns;
36 unsigned int tile_rows;
Fangwen Fu7b9f2b32017-01-17 14:01:52 -080037#if CONFIG_DEPENDENT_HORZTILES
38 unsigned int dependent_horz_tiles;
39#endif
Ryan Lei9b02b0e2017-01-30 15:52:20 -080040#if CONFIG_LOOPFILTERING_ACROSS_TILES
Ryan Lei7386eda2016-12-08 21:08:31 -080041 unsigned int loop_filter_across_tiles_enabled;
Ryan Lei9b02b0e2017-01-30 15:52:20 -080042#endif // CONFIG_LOOPFILTERING_ACROSS_TILES
Yaowu Xuc27fc142016-08-22 16:08:15 -070043 unsigned int arnr_max_frames;
44 unsigned int arnr_strength;
45 unsigned int min_gf_interval;
46 unsigned int max_gf_interval;
Yaowu Xuf883b422016-08-30 14:01:10 -070047 aom_tune_metric tuning;
Yaowu Xuc27fc142016-08-22 16:08:15 -070048 unsigned int cq_level; // constrained quality level
49 unsigned int rc_max_intra_bitrate_pct;
50 unsigned int rc_max_inter_bitrate_pct;
51 unsigned int gf_cbr_boost_pct;
52 unsigned int lossless;
53#if CONFIG_AOM_QM
54 unsigned int enable_qm;
55 unsigned int qm_min;
56 unsigned int qm_max;
57#endif
Thomas Daviesaf6df172016-11-09 14:04:18 +000058#if CONFIG_TILE_GROUPS
59 unsigned int num_tg;
60 unsigned int mtu_size;
61#endif
Fangwen Fu8d164de2016-12-14 13:40:54 -080062#if CONFIG_TEMPMV_SIGNALING
63 unsigned int disable_tempmv;
64#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -070065 unsigned int frame_parallel_decoding_mode;
66 AQ_MODE aq_mode;
Fangwen Fu6160df22017-04-24 09:45:51 -070067#if CONFIG_EXT_DELTA_Q
68 DELTAQ_MODE deltaq_mode;
69#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -070070 unsigned int frame_periodic_boost;
Yaowu Xuf883b422016-08-30 14:01:10 -070071 aom_bit_depth_t bit_depth;
72 aom_tune_content content;
73 aom_color_space_t color_space;
anorkin76fb1262017-03-22 15:12:12 -070074#if CONFIG_COLORSPACE_HEADERS
75 aom_transfer_function_t transfer_function;
76 aom_chroma_sample_position_t chroma_sample_position;
77#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -070078 int color_range;
79 int render_width;
80 int render_height;
Yaowu Xuf883b422016-08-30 14:01:10 -070081 aom_superblock_size_t superblock_size;
Alex Converseeb780e72016-12-13 12:46:41 -080082#if CONFIG_ANS && ANS_MAX_SYMBOLS
83 int ans_window_size_log2;
84#endif
Yunqing Wangd8cd55f2017-02-27 12:16:00 -080085#if CONFIG_EXT_TILE
86 unsigned int tile_encoding_mode;
87#endif // CONFIG_EXT_TILE
Yunqing Wangff4fa062017-04-21 10:56:08 -070088
89 unsigned int motion_vector_unit_test;
Yaowu Xuc27fc142016-08-22 16:08:15 -070090};
91
Yaowu Xuf883b422016-08-30 14:01:10 -070092static struct av1_extracfg default_extra_cfg = {
Yaowu Xuc27fc142016-08-22 16:08:15 -070093 0, // cpu_used
94 1, // enable_auto_alt_ref
95#if CONFIG_EXT_REFS
96 0, // enable_auto_bwd_ref
97#endif // CONFIG_EXT_REFS
98 0, // noise_sensitivity
99 0, // sharpness
100 0, // static_thresh
101#if CONFIG_EXT_TILE
102 UINT_MAX, // tile_columns
103 UINT_MAX, // tile_rows
104#else
105 0, // tile_columns
106 0, // tile_rows
Ryan Lei7386eda2016-12-08 21:08:31 -0800107#endif // CONFIG_EXT_TILE
Fangwen Fu7b9f2b32017-01-17 14:01:52 -0800108#if CONFIG_DEPENDENT_HORZTILES
anorkin76fb1262017-03-22 15:12:12 -0700109 0, // Dependent Horizontal tiles
Fangwen Fu7b9f2b32017-01-17 14:01:52 -0800110#endif
Ryan Lei9b02b0e2017-01-30 15:52:20 -0800111#if CONFIG_LOOPFILTERING_ACROSS_TILES
Ryan Leiad67d792017-02-02 17:53:19 -0800112 1, // loop_filter_across_tiles_enabled
Ryan Lei9b02b0e2017-01-30 15:52:20 -0800113#endif // CONFIG_LOOPFILTERING_ACROSS_TILES
Yaowu Xuc27fc142016-08-22 16:08:15 -0700114 7, // arnr_max_frames
115 5, // arnr_strength
116 0, // min_gf_interval; 0 -> default decision
117 0, // max_gf_interval; 0 -> default decision
Yaowu Xuf883b422016-08-30 14:01:10 -0700118 AOM_TUNE_PSNR, // tuning
Yaowu Xuc27fc142016-08-22 16:08:15 -0700119 10, // cq_level
120 0, // rc_max_intra_bitrate_pct
121 0, // rc_max_inter_bitrate_pct
122 0, // gf_cbr_boost_pct
123 0, // lossless
124#if CONFIG_AOM_QM
125 0, // enable_qm
126 DEFAULT_QM_FIRST, // qm_min
127 DEFAULT_QM_LAST, // qm_max
128#endif
Thomas Daviesaf6df172016-11-09 14:04:18 +0000129#if CONFIG_TILE_GROUPS
130 1, // max number of tile groups
131 0, // mtu_size
132#endif
Fangwen Fu8d164de2016-12-14 13:40:54 -0800133#if CONFIG_TEMPMV_SIGNALING
134 0, // disable temporal mv prediction
135#endif
Fangwen Fu6160df22017-04-24 09:45:51 -0700136 1, // frame_parallel_decoding_mode
137 NO_AQ, // aq_mode
138#if CONFIG_EXT_DELTA_Q
139 NO_DELTA_Q, // deltaq_mode
140#endif
anorkin76fb1262017-03-22 15:12:12 -0700141 CONFIG_XIPHRC, // frame_periodic_delta_q
142 AOM_BITS_8, // Bit depth
143 AOM_CONTENT_DEFAULT, // content
144 AOM_CS_UNKNOWN, // color space
145#if CONFIG_COLORSPACE_HEADERS
146 AOM_TF_UNKNOWN, // transfer function
147 AOM_CSP_UNKNOWN, // chroma sample position
148#endif
Alex Converseeb780e72016-12-13 12:46:41 -0800149 0, // color range
150 0, // render width
151 0, // render height
152 AOM_SUPERBLOCK_SIZE_DYNAMIC, // superblock_size
153#if CONFIG_ANS && ANS_MAX_SYMBOLS
154 23, // ans_window_size_log2
155#endif
Yunqing Wangd8cd55f2017-02-27 12:16:00 -0800156#if CONFIG_EXT_TILE
157 0, // Tile encoding mode is TILE_NORMAL by default.
158#endif // CONFIG_EXT_TILE
Yunqing Wangff4fa062017-04-21 10:56:08 -0700159
160 0, // motion_vector_unit_test
Yaowu Xuc27fc142016-08-22 16:08:15 -0700161};
162
Yaowu Xuf883b422016-08-30 14:01:10 -0700163struct aom_codec_alg_priv {
164 aom_codec_priv_t base;
165 aom_codec_enc_cfg_t cfg;
166 struct av1_extracfg extra_cfg;
167 AV1EncoderConfig oxcf;
168 AV1_COMP *cpi;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700169 unsigned char *cx_data;
170 size_t cx_data_sz;
171 unsigned char *pending_cx_data;
172 size_t pending_cx_data_sz;
173 int pending_frame_count;
174 size_t pending_frame_sizes[8];
Yaowu Xuf883b422016-08-30 14:01:10 -0700175 aom_image_t preview_img;
176 aom_enc_frame_flags_t next_frame_flags;
177 aom_postproc_cfg_t preview_ppcfg;
178 aom_codec_pkt_list_decl(256) pkt_list;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700179 unsigned int fixed_kf_cntr;
180 // BufferPool that holds all reference frames.
181 BufferPool *buffer_pool;
182};
183
Yaowu Xuf883b422016-08-30 14:01:10 -0700184static aom_codec_err_t update_error_state(
185 aom_codec_alg_priv_t *ctx, const struct aom_internal_error_info *error) {
186 const aom_codec_err_t res = error->error_code;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700187
Yaowu Xuf883b422016-08-30 14:01:10 -0700188 if (res != AOM_CODEC_OK)
Yaowu Xuc27fc142016-08-22 16:08:15 -0700189 ctx->base.err_detail = error->has_detail ? error->detail : NULL;
190
191 return res;
192}
193
194#undef ERROR
195#define ERROR(str) \
196 do { \
197 ctx->base.err_detail = str; \
Yaowu Xuf883b422016-08-30 14:01:10 -0700198 return AOM_CODEC_INVALID_PARAM; \
Yaowu Xuc27fc142016-08-22 16:08:15 -0700199 } while (0)
200
Urvang Joshicd8ab902016-10-28 12:32:06 -0700201#define RANGE_CHECK(p, memb, lo, hi) \
202 do { \
203 if (!((p)->memb >= (lo) && (p)->memb <= (hi))) \
204 ERROR(#memb " out of range [" #lo ".." #hi "]"); \
Yaowu Xuc27fc142016-08-22 16:08:15 -0700205 } while (0)
206
207#define RANGE_CHECK_HI(p, memb, hi) \
208 do { \
209 if (!((p)->memb <= (hi))) ERROR(#memb " out of range [.." #hi "]"); \
210 } while (0)
211
212#define RANGE_CHECK_LO(p, memb, lo) \
213 do { \
214 if (!((p)->memb >= (lo))) ERROR(#memb " out of range [" #lo "..]"); \
215 } while (0)
216
217#define RANGE_CHECK_BOOL(p, memb) \
218 do { \
219 if (!!((p)->memb) != (p)->memb) ERROR(#memb " expected boolean"); \
220 } while (0)
221
Yaowu Xuf883b422016-08-30 14:01:10 -0700222static aom_codec_err_t validate_config(aom_codec_alg_priv_t *ctx,
223 const aom_codec_enc_cfg_t *cfg,
224 const struct av1_extracfg *extra_cfg) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700225 RANGE_CHECK(cfg, g_w, 1, 65535); // 16 bits available
226 RANGE_CHECK(cfg, g_h, 1, 65535); // 16 bits available
227 RANGE_CHECK(cfg, g_timebase.den, 1, 1000000000);
228 RANGE_CHECK(cfg, g_timebase.num, 1, cfg->g_timebase.den);
229 RANGE_CHECK_HI(cfg, g_profile, 3);
230
231 RANGE_CHECK_HI(cfg, rc_max_quantizer, 63);
232 RANGE_CHECK_HI(cfg, rc_min_quantizer, cfg->rc_max_quantizer);
233 RANGE_CHECK_BOOL(extra_cfg, lossless);
234 RANGE_CHECK(extra_cfg, aq_mode, 0, AQ_MODE_COUNT - 1);
Fangwen Fu6160df22017-04-24 09:45:51 -0700235#if CONFIG_EXT_DELTA_Q
236 RANGE_CHECK(extra_cfg, deltaq_mode, 0, DELTAQ_MODE_COUNT - 1);
237#endif
Urvang Joshicd8ab902016-10-28 12:32:06 -0700238 RANGE_CHECK_HI(extra_cfg, frame_periodic_boost, 1);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700239 RANGE_CHECK_HI(cfg, g_threads, 64);
240 RANGE_CHECK_HI(cfg, g_lag_in_frames, MAX_LAG_BUFFERS);
Yaowu Xuf883b422016-08-30 14:01:10 -0700241 RANGE_CHECK(cfg, rc_end_usage, AOM_VBR, AOM_Q);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700242 RANGE_CHECK_HI(cfg, rc_undershoot_pct, 100);
243 RANGE_CHECK_HI(cfg, rc_overshoot_pct, 100);
244 RANGE_CHECK_HI(cfg, rc_2pass_vbr_bias_pct, 100);
Yaowu Xuf883b422016-08-30 14:01:10 -0700245 RANGE_CHECK(cfg, kf_mode, AOM_KF_DISABLED, AOM_KF_AUTO);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700246 RANGE_CHECK_HI(cfg, rc_dropframe_thresh, 100);
Yaowu Xuf883b422016-08-30 14:01:10 -0700247 RANGE_CHECK(cfg, g_pass, AOM_RC_ONE_PASS, AOM_RC_LAST_PASS);
Urvang Joshicd8ab902016-10-28 12:32:06 -0700248 RANGE_CHECK_HI(extra_cfg, min_gf_interval, MAX_LAG_BUFFERS - 1);
249 RANGE_CHECK_HI(extra_cfg, max_gf_interval, MAX_LAG_BUFFERS - 1);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700250 if (extra_cfg->max_gf_interval > 0) {
251 RANGE_CHECK(extra_cfg, max_gf_interval, 2, (MAX_LAG_BUFFERS - 1));
252 }
253 if (extra_cfg->min_gf_interval > 0 && extra_cfg->max_gf_interval > 0) {
254 RANGE_CHECK(extra_cfg, max_gf_interval, extra_cfg->min_gf_interval,
255 (MAX_LAG_BUFFERS - 1));
256 }
257
Debargha Mukherjee29e40a62017-06-14 09:37:12 -0700258 RANGE_CHECK_HI(cfg, rc_resize_mode, RESIZE_DYNAMIC);
Fergus Simpsonbfbf6a52017-06-14 23:13:12 -0700259 RANGE_CHECK(cfg, rc_resize_numerator, SCALE_DENOMINATOR / 2,
260 SCALE_DENOMINATOR);
Fergus Simpson87cf61b2017-06-15 00:50:34 -0700261 RANGE_CHECK(cfg, rc_resize_kf_numerator, SCALE_DENOMINATOR / 2,
262 SCALE_DENOMINATOR);
Fergus Simpsonc4e78942017-04-10 14:59:00 -0700263#if CONFIG_FRAME_SUPERRES
264 RANGE_CHECK_HI(cfg, rc_superres_mode, SUPERRES_DYNAMIC);
Fergus Simpsonbfbf6a52017-06-14 23:13:12 -0700265 RANGE_CHECK(cfg, rc_superres_numerator, SCALE_DENOMINATOR / 2,
266 SCALE_DENOMINATOR);
Fergus Simpson87cf61b2017-06-15 00:50:34 -0700267 RANGE_CHECK(cfg, rc_superres_kf_numerator, SCALE_DENOMINATOR / 2,
268 SCALE_DENOMINATOR);
Fergus Simpsonc4e78942017-04-10 14:59:00 -0700269#endif // CONFIG_FRAME_SUPERRES
270
Yaowu Xuf883b422016-08-30 14:01:10 -0700271 // AV1 does not support a lower bound on the keyframe interval in
Yaowu Xuc27fc142016-08-22 16:08:15 -0700272 // automatic keyframe placement mode.
Yaowu Xuf883b422016-08-30 14:01:10 -0700273 if (cfg->kf_mode != AOM_KF_DISABLED && cfg->kf_min_dist != cfg->kf_max_dist &&
Yaowu Xuc27fc142016-08-22 16:08:15 -0700274 cfg->kf_min_dist > 0)
275 ERROR(
276 "kf_min_dist not supported in auto mode, use 0 "
277 "or kf_max_dist instead.");
278
Yunqing Wangff4fa062017-04-21 10:56:08 -0700279 RANGE_CHECK_HI(extra_cfg, motion_vector_unit_test, 2);
Urvang Joshicd8ab902016-10-28 12:32:06 -0700280 RANGE_CHECK_HI(extra_cfg, enable_auto_alt_ref, 2);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700281#if CONFIG_EXT_REFS
Urvang Joshicd8ab902016-10-28 12:32:06 -0700282 RANGE_CHECK_HI(extra_cfg, enable_auto_bwd_ref, 2);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700283#endif // CONFIG_EXT_REFS
Alex Converse561d0af2017-03-23 12:58:04 -0700284 RANGE_CHECK(extra_cfg, cpu_used, 0, 8);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700285 RANGE_CHECK_HI(extra_cfg, noise_sensitivity, 6);
Yaowu Xuf883b422016-08-30 14:01:10 -0700286 RANGE_CHECK(extra_cfg, superblock_size, AOM_SUPERBLOCK_SIZE_64X64,
287 AOM_SUPERBLOCK_SIZE_DYNAMIC);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700288#if CONFIG_EXT_TILE
289// TODO(any): Waring. If CONFIG_EXT_TILE is true, tile_columns really
290// means tile_width, and tile_rows really means tile_hight. The interface
291// should be sanitized.
292#if CONFIG_EXT_PARTITION
Yaowu Xuf883b422016-08-30 14:01:10 -0700293 if (extra_cfg->superblock_size != AOM_SUPERBLOCK_SIZE_64X64) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700294 if (extra_cfg->tile_columns != UINT_MAX)
295 RANGE_CHECK(extra_cfg, tile_columns, 1, 32);
296 if (extra_cfg->tile_rows != UINT_MAX)
297 RANGE_CHECK(extra_cfg, tile_rows, 1, 32);
298 } else
299#endif // CONFIG_EXT_PARTITION
300 {
301 if (extra_cfg->tile_columns != UINT_MAX)
302 RANGE_CHECK(extra_cfg, tile_columns, 1, 64);
303 if (extra_cfg->tile_rows != UINT_MAX)
304 RANGE_CHECK(extra_cfg, tile_rows, 1, 64);
305 }
Yunqing Wangd8cd55f2017-02-27 12:16:00 -0800306 RANGE_CHECK_HI(extra_cfg, tile_encoding_mode, 1);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700307#else
Urvang Joshicd8ab902016-10-28 12:32:06 -0700308 RANGE_CHECK_HI(extra_cfg, tile_columns, 6);
309 RANGE_CHECK_HI(extra_cfg, tile_rows, 2);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700310#endif // CONFIG_EXT_TILE
Fangwen Fu7b9f2b32017-01-17 14:01:52 -0800311#if CONFIG_DEPENDENT_HORZTILES
312 RANGE_CHECK_HI(extra_cfg, dependent_horz_tiles, 1);
313#endif
Ryan Lei9b02b0e2017-01-30 15:52:20 -0800314#if CONFIG_LOOPFILTERING_ACROSS_TILES
Ryan Lei7386eda2016-12-08 21:08:31 -0800315 RANGE_CHECK_HI(extra_cfg, loop_filter_across_tiles_enabled, 1);
Ryan Lei9b02b0e2017-01-30 15:52:20 -0800316#endif // CONFIG_LOOPFILTERING_ACROSS_TILES
Yaowu Xuc27fc142016-08-22 16:08:15 -0700317 RANGE_CHECK_HI(extra_cfg, sharpness, 7);
Urvang Joshicd8ab902016-10-28 12:32:06 -0700318 RANGE_CHECK_HI(extra_cfg, arnr_max_frames, 15);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700319 RANGE_CHECK_HI(extra_cfg, arnr_strength, 6);
Urvang Joshicd8ab902016-10-28 12:32:06 -0700320 RANGE_CHECK_HI(extra_cfg, cq_level, 63);
Yaowu Xuf883b422016-08-30 14:01:10 -0700321 RANGE_CHECK(cfg, g_bit_depth, AOM_BITS_8, AOM_BITS_12);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700322 RANGE_CHECK(cfg, g_input_bit_depth, 8, 12);
Yaowu Xuf883b422016-08-30 14:01:10 -0700323 RANGE_CHECK(extra_cfg, content, AOM_CONTENT_DEFAULT, AOM_CONTENT_INVALID - 1);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700324
Yaowu Xuf883b422016-08-30 14:01:10 -0700325 // TODO(yaowu): remove this when ssim tuning is implemented for av1
326 if (extra_cfg->tuning == AOM_TUNE_SSIM)
327 ERROR("Option --tune=ssim is not currently supported in AV1.");
Yaowu Xuc27fc142016-08-22 16:08:15 -0700328
Yaowu Xuf883b422016-08-30 14:01:10 -0700329 if (cfg->g_pass == AOM_RC_LAST_PASS) {
Rostislav Pehlivanov74021a52017-03-09 09:05:29 +0000330#if !CONFIG_XIPHRC
Yaowu Xuc27fc142016-08-22 16:08:15 -0700331 const size_t packet_sz = sizeof(FIRSTPASS_STATS);
332 const int n_packets = (int)(cfg->rc_twopass_stats_in.sz / packet_sz);
333 const FIRSTPASS_STATS *stats;
Rostislav Pehlivanov74021a52017-03-09 09:05:29 +0000334#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -0700335
336 if (cfg->rc_twopass_stats_in.buf == NULL)
337 ERROR("rc_twopass_stats_in.buf not set.");
338
Rostislav Pehlivanov74021a52017-03-09 09:05:29 +0000339#if !CONFIG_XIPHRC
Yaowu Xuc27fc142016-08-22 16:08:15 -0700340 if (cfg->rc_twopass_stats_in.sz % packet_sz)
341 ERROR("rc_twopass_stats_in.sz indicates truncated packet.");
342
343 if (cfg->rc_twopass_stats_in.sz < 2 * packet_sz)
344 ERROR("rc_twopass_stats_in requires at least two packets.");
345
346 stats =
347 (const FIRSTPASS_STATS *)cfg->rc_twopass_stats_in.buf + n_packets - 1;
348
349 if ((int)(stats->count + 0.5) != n_packets - 1)
350 ERROR("rc_twopass_stats_in missing EOS stats packet");
Rostislav Pehlivanov74021a52017-03-09 09:05:29 +0000351#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -0700352 }
353
Sebastien Alaiwan71e87842017-04-12 16:03:28 +0200354#if !CONFIG_HIGHBITDEPTH
Yaowu Xuc27fc142016-08-22 16:08:15 -0700355 if (cfg->g_profile > (unsigned int)PROFILE_1) {
356 ERROR("Profile > 1 not supported in this build configuration");
357 }
358#endif
359 if (cfg->g_profile <= (unsigned int)PROFILE_1 &&
Yaowu Xuf883b422016-08-30 14:01:10 -0700360 cfg->g_bit_depth > AOM_BITS_8) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700361 ERROR("Codec high bit-depth not supported in profile < 2");
362 }
363 if (cfg->g_profile <= (unsigned int)PROFILE_1 && cfg->g_input_bit_depth > 8) {
364 ERROR("Source high bit-depth not supported in profile < 2");
365 }
366 if (cfg->g_profile > (unsigned int)PROFILE_1 &&
Yaowu Xuf883b422016-08-30 14:01:10 -0700367 cfg->g_bit_depth == AOM_BITS_8) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700368 ERROR("Codec bit-depth 8 not supported in profile > 1");
369 }
anorkin76fb1262017-03-22 15:12:12 -0700370#if CONFIG_COLORSPACE_HEADERS
371 RANGE_CHECK(extra_cfg, color_space, AOM_CS_UNKNOWN, AOM_CS_ICTCP);
372 RANGE_CHECK(extra_cfg, transfer_function, AOM_TF_UNKNOWN, AOM_TF_HLG);
373 RANGE_CHECK(extra_cfg, chroma_sample_position, AOM_CSP_UNKNOWN,
374 AOM_CSP_COLOCATED);
375#else
Yaowu Xuf883b422016-08-30 14:01:10 -0700376 RANGE_CHECK(extra_cfg, color_space, AOM_CS_UNKNOWN, AOM_CS_SRGB);
anorkin76fb1262017-03-22 15:12:12 -0700377#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -0700378 RANGE_CHECK(extra_cfg, color_range, 0, 1);
Alex Converseeb780e72016-12-13 12:46:41 -0800379#if CONFIG_ANS && ANS_MAX_SYMBOLS
380 RANGE_CHECK(extra_cfg, ans_window_size_log2, 8, 23);
381#endif
Yaowu Xuf883b422016-08-30 14:01:10 -0700382 return AOM_CODEC_OK;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700383}
384
Yaowu Xuf883b422016-08-30 14:01:10 -0700385static aom_codec_err_t validate_img(aom_codec_alg_priv_t *ctx,
386 const aom_image_t *img) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700387 switch (img->fmt) {
Yaowu Xuf883b422016-08-30 14:01:10 -0700388 case AOM_IMG_FMT_YV12:
389 case AOM_IMG_FMT_I420:
390 case AOM_IMG_FMT_I42016: break;
391 case AOM_IMG_FMT_I422:
392 case AOM_IMG_FMT_I444:
393 case AOM_IMG_FMT_I440:
Yaowu Xuc27fc142016-08-22 16:08:15 -0700394 if (ctx->cfg.g_profile != (unsigned int)PROFILE_1) {
395 ERROR(
396 "Invalid image format. I422, I444, I440 images are "
397 "not supported in profile.");
398 }
399 break;
Yaowu Xuf883b422016-08-30 14:01:10 -0700400 case AOM_IMG_FMT_I42216:
401 case AOM_IMG_FMT_I44416:
402 case AOM_IMG_FMT_I44016:
Yaowu Xuc27fc142016-08-22 16:08:15 -0700403 if (ctx->cfg.g_profile != (unsigned int)PROFILE_1 &&
404 ctx->cfg.g_profile != (unsigned int)PROFILE_3) {
405 ERROR(
406 "Invalid image format. 16-bit I422, I444, I440 images are "
407 "not supported in profile.");
408 }
409 break;
410 default:
411 ERROR(
412 "Invalid image format. Only YV12, I420, I422, I444 images are "
413 "supported.");
414 break;
415 }
416
417 if (img->d_w != ctx->cfg.g_w || img->d_h != ctx->cfg.g_h)
418 ERROR("Image size must match encoder init configuration size");
419
Yaowu Xuf883b422016-08-30 14:01:10 -0700420 return AOM_CODEC_OK;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700421}
422
Yaowu Xuf883b422016-08-30 14:01:10 -0700423static int get_image_bps(const aom_image_t *img) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700424 switch (img->fmt) {
Yaowu Xuf883b422016-08-30 14:01:10 -0700425 case AOM_IMG_FMT_YV12:
426 case AOM_IMG_FMT_I420: return 12;
427 case AOM_IMG_FMT_I422: return 16;
428 case AOM_IMG_FMT_I444: return 24;
429 case AOM_IMG_FMT_I440: return 16;
430 case AOM_IMG_FMT_I42016: return 24;
431 case AOM_IMG_FMT_I42216: return 32;
432 case AOM_IMG_FMT_I44416: return 48;
433 case AOM_IMG_FMT_I44016: return 32;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700434 default: assert(0 && "Invalid image format"); break;
435 }
436 return 0;
437}
438
Yaowu Xuf883b422016-08-30 14:01:10 -0700439static aom_codec_err_t set_encoder_config(
440 AV1EncoderConfig *oxcf, const aom_codec_enc_cfg_t *cfg,
441 const struct av1_extracfg *extra_cfg) {
442 const int is_vbr = cfg->rc_end_usage == AOM_VBR;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700443 oxcf->profile = cfg->g_profile;
444 oxcf->max_threads = (int)cfg->g_threads;
445 oxcf->width = cfg->g_w;
446 oxcf->height = cfg->g_h;
447 oxcf->bit_depth = cfg->g_bit_depth;
448 oxcf->input_bit_depth = cfg->g_input_bit_depth;
449 // guess a frame rate if out of whack, use 30
450 oxcf->init_framerate = (double)cfg->g_timebase.den / cfg->g_timebase.num;
451 if (oxcf->init_framerate > 180) oxcf->init_framerate = 30;
452
453 oxcf->mode = GOOD;
454
455 switch (cfg->g_pass) {
Yaowu Xuf883b422016-08-30 14:01:10 -0700456 case AOM_RC_ONE_PASS: oxcf->pass = 0; break;
457 case AOM_RC_FIRST_PASS: oxcf->pass = 1; break;
458 case AOM_RC_LAST_PASS: oxcf->pass = 2; break;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700459 }
460
461 oxcf->lag_in_frames =
Yaowu Xuf883b422016-08-30 14:01:10 -0700462 cfg->g_pass == AOM_RC_FIRST_PASS ? 0 : cfg->g_lag_in_frames;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700463 oxcf->rc_mode = cfg->rc_end_usage;
464
465 // Convert target bandwidth from Kbit/s to Bit/s
466 oxcf->target_bandwidth = 1000 * cfg->rc_target_bitrate;
467 oxcf->rc_max_intra_bitrate_pct = extra_cfg->rc_max_intra_bitrate_pct;
468 oxcf->rc_max_inter_bitrate_pct = extra_cfg->rc_max_inter_bitrate_pct;
469 oxcf->gf_cbr_boost_pct = extra_cfg->gf_cbr_boost_pct;
470
471 oxcf->best_allowed_q =
Yaowu Xuf883b422016-08-30 14:01:10 -0700472 extra_cfg->lossless ? 0 : av1_quantizer_to_qindex(cfg->rc_min_quantizer);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700473 oxcf->worst_allowed_q =
Yaowu Xuf883b422016-08-30 14:01:10 -0700474 extra_cfg->lossless ? 0 : av1_quantizer_to_qindex(cfg->rc_max_quantizer);
475 oxcf->cq_level = av1_quantizer_to_qindex(extra_cfg->cq_level);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700476 oxcf->fixed_q = -1;
477
478#if CONFIG_AOM_QM
479 oxcf->using_qm = extra_cfg->enable_qm;
480 oxcf->qm_minlevel = extra_cfg->qm_min;
481 oxcf->qm_maxlevel = extra_cfg->qm_max;
482#endif
483
Thomas Daviesaf6df172016-11-09 14:04:18 +0000484#if CONFIG_TILE_GROUPS
485 oxcf->num_tile_groups = extra_cfg->num_tg;
486 oxcf->mtu = extra_cfg->mtu_size;
487#endif
488
Fangwen Fu8d164de2016-12-14 13:40:54 -0800489#if CONFIG_TEMPMV_SIGNALING
490 oxcf->disable_tempmv = extra_cfg->disable_tempmv;
491#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -0700492 oxcf->under_shoot_pct = cfg->rc_undershoot_pct;
493 oxcf->over_shoot_pct = cfg->rc_overshoot_pct;
494
Debargha Mukherjee29e40a62017-06-14 09:37:12 -0700495 oxcf->resize_mode = (RESIZE_MODE)cfg->rc_resize_mode;
496 oxcf->resize_scale_numerator = (uint8_t)cfg->rc_resize_numerator;
Fergus Simpson87cf61b2017-06-15 00:50:34 -0700497 oxcf->resize_kf_scale_numerator = (uint8_t)cfg->rc_resize_kf_numerator;
Debargha Mukherjee29e40a62017-06-14 09:37:12 -0700498 if (oxcf->resize_mode == RESIZE_FIXED &&
Fergus Simpson87cf61b2017-06-15 00:50:34 -0700499 oxcf->resize_scale_numerator == SCALE_DENOMINATOR &&
500 oxcf->resize_kf_scale_numerator == SCALE_DENOMINATOR)
Yaowu Xuc27fc142016-08-22 16:08:15 -0700501 oxcf->resize_mode = RESIZE_NONE;
Fergus Simpson3502d082017-04-10 12:25:07 -0700502
503#if CONFIG_FRAME_SUPERRES
Fergus Simpsonc4e78942017-04-10 14:59:00 -0700504 oxcf->superres_mode = (SUPERRES_MODE)cfg->rc_superres_mode;
505 oxcf->superres_scale_numerator = (uint8_t)cfg->rc_superres_numerator;
Fergus Simpson87cf61b2017-06-15 00:50:34 -0700506 oxcf->superres_kf_scale_numerator = (uint8_t)cfg->rc_superres_kf_numerator;
Fergus Simpsonc4e78942017-04-10 14:59:00 -0700507 if (oxcf->superres_mode == SUPERRES_FIXED &&
Fergus Simpson87cf61b2017-06-15 00:50:34 -0700508 oxcf->superres_scale_numerator == SCALE_DENOMINATOR &&
509 oxcf->superres_kf_scale_numerator == SCALE_DENOMINATOR)
Fergus Simpsonc4e78942017-04-10 14:59:00 -0700510 oxcf->superres_mode = SUPERRES_NONE;
511#endif // CONFIG_FRAME_SUPERRES
Fergus Simpson3502d082017-04-10 12:25:07 -0700512
Yaowu Xuc27fc142016-08-22 16:08:15 -0700513 oxcf->maximum_buffer_size_ms = is_vbr ? 240000 : cfg->rc_buf_sz;
514 oxcf->starting_buffer_level_ms = is_vbr ? 60000 : cfg->rc_buf_initial_sz;
515 oxcf->optimal_buffer_level_ms = is_vbr ? 60000 : cfg->rc_buf_optimal_sz;
516
517 oxcf->drop_frames_water_mark = cfg->rc_dropframe_thresh;
518
519 oxcf->two_pass_vbrbias = cfg->rc_2pass_vbr_bias_pct;
520 oxcf->two_pass_vbrmin_section = cfg->rc_2pass_vbr_minsection_pct;
521 oxcf->two_pass_vbrmax_section = cfg->rc_2pass_vbr_maxsection_pct;
522
523 oxcf->auto_key =
Yaowu Xuf883b422016-08-30 14:01:10 -0700524 cfg->kf_mode == AOM_KF_AUTO && cfg->kf_min_dist != cfg->kf_max_dist;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700525
526 oxcf->key_freq = cfg->kf_max_dist;
527
Alex Converse561d0af2017-03-23 12:58:04 -0700528 oxcf->speed = extra_cfg->cpu_used;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700529 oxcf->enable_auto_arf = extra_cfg->enable_auto_alt_ref;
530#if CONFIG_EXT_REFS
531 oxcf->enable_auto_brf = extra_cfg->enable_auto_bwd_ref;
532#endif // CONFIG_EXT_REFS
533 oxcf->noise_sensitivity = extra_cfg->noise_sensitivity;
534 oxcf->sharpness = extra_cfg->sharpness;
535
536 oxcf->two_pass_stats_in = cfg->rc_twopass_stats_in;
537
538#if CONFIG_FP_MB_STATS
539 oxcf->firstpass_mb_stats_in = cfg->rc_firstpass_mb_stats_in;
540#endif
541
542 oxcf->color_space = extra_cfg->color_space;
anorkin76fb1262017-03-22 15:12:12 -0700543#if CONFIG_COLORSPACE_HEADERS
544 oxcf->transfer_function = extra_cfg->transfer_function;
545 oxcf->chroma_sample_position = extra_cfg->chroma_sample_position;
546#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -0700547 oxcf->color_range = extra_cfg->color_range;
548 oxcf->render_width = extra_cfg->render_width;
549 oxcf->render_height = extra_cfg->render_height;
550 oxcf->arnr_max_frames = extra_cfg->arnr_max_frames;
551 oxcf->arnr_strength = extra_cfg->arnr_strength;
552 oxcf->min_gf_interval = extra_cfg->min_gf_interval;
553 oxcf->max_gf_interval = extra_cfg->max_gf_interval;
554
555 oxcf->tuning = extra_cfg->tuning;
556 oxcf->content = extra_cfg->content;
557
558#if CONFIG_EXT_PARTITION
559 oxcf->superblock_size = extra_cfg->superblock_size;
560#endif // CONFIG_EXT_PARTITION
Alex Converseeb780e72016-12-13 12:46:41 -0800561#if CONFIG_ANS && ANS_MAX_SYMBOLS
562 oxcf->ans_window_size_log2 = extra_cfg->ans_window_size_log2;
563#endif // CONFIG_ANS && ANS_MAX_SYMBOLS
Yaowu Xuc27fc142016-08-22 16:08:15 -0700564
565#if CONFIG_EXT_TILE
566 {
567#if CONFIG_EXT_PARTITION
568 const unsigned int max =
Yaowu Xuf883b422016-08-30 14:01:10 -0700569 extra_cfg->superblock_size == AOM_SUPERBLOCK_SIZE_64X64 ? 64 : 32;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700570#else
571 const unsigned int max = 64;
572#endif // CONFIG_EXT_PARTITION
Yaowu Xuf883b422016-08-30 14:01:10 -0700573 oxcf->tile_columns = AOMMIN(extra_cfg->tile_columns, max);
574 oxcf->tile_rows = AOMMIN(extra_cfg->tile_rows, max);
Yunqing Wangd8cd55f2017-02-27 12:16:00 -0800575 oxcf->tile_encoding_mode = extra_cfg->tile_encoding_mode;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700576 }
577#else
578 oxcf->tile_columns = extra_cfg->tile_columns;
579 oxcf->tile_rows = extra_cfg->tile_rows;
580#endif // CONFIG_EXT_TILE
Fangwen Fu7b9f2b32017-01-17 14:01:52 -0800581#if CONFIG_DEPENDENT_HORZTILES
582 oxcf->dependent_horz_tiles = extra_cfg->dependent_horz_tiles;
583#endif
Ryan Lei9b02b0e2017-01-30 15:52:20 -0800584#if CONFIG_LOOPFILTERING_ACROSS_TILES
Ryan Lei7386eda2016-12-08 21:08:31 -0800585 oxcf->loop_filter_across_tiles_enabled =
586 extra_cfg->loop_filter_across_tiles_enabled;
Ryan Lei9b02b0e2017-01-30 15:52:20 -0800587#endif // CONFIG_LOOPFILTERING_ACROSS_TILES
Yaowu Xuc27fc142016-08-22 16:08:15 -0700588 oxcf->error_resilient_mode = cfg->g_error_resilient;
589 oxcf->frame_parallel_decoding_mode = extra_cfg->frame_parallel_decoding_mode;
590
591 oxcf->aq_mode = extra_cfg->aq_mode;
Fangwen Fu6160df22017-04-24 09:45:51 -0700592#if CONFIG_EXT_DELTA_Q
593 oxcf->deltaq_mode = extra_cfg->deltaq_mode;
594#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -0700595
596 oxcf->frame_periodic_boost = extra_cfg->frame_periodic_boost;
597
Yunqing Wangff4fa062017-04-21 10:56:08 -0700598 oxcf->motion_vector_unit_test = extra_cfg->motion_vector_unit_test;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700599 /*
Yaowu Xuf883b422016-08-30 14:01:10 -0700600 printf("Current AV1 Settings: \n");
Yaowu Xuc27fc142016-08-22 16:08:15 -0700601 printf("target_bandwidth: %d\n", oxcf->target_bandwidth);
602 printf("noise_sensitivity: %d\n", oxcf->noise_sensitivity);
603 printf("sharpness: %d\n", oxcf->sharpness);
604 printf("cpu_used: %d\n", oxcf->cpu_used);
605 printf("Mode: %d\n", oxcf->mode);
606 printf("auto_key: %d\n", oxcf->auto_key);
607 printf("key_freq: %d\n", oxcf->key_freq);
608 printf("end_usage: %d\n", oxcf->end_usage);
609 printf("under_shoot_pct: %d\n", oxcf->under_shoot_pct);
610 printf("over_shoot_pct: %d\n", oxcf->over_shoot_pct);
611 printf("starting_buffer_level: %d\n", oxcf->starting_buffer_level);
612 printf("optimal_buffer_level: %d\n", oxcf->optimal_buffer_level);
613 printf("maximum_buffer_size: %d\n", oxcf->maximum_buffer_size);
614 printf("fixed_q: %d\n", oxcf->fixed_q);
615 printf("worst_allowed_q: %d\n", oxcf->worst_allowed_q);
616 printf("best_allowed_q: %d\n", oxcf->best_allowed_q);
617 printf("allow_spatial_resampling: %d\n", oxcf->allow_spatial_resampling);
618 printf("scaled_frame_width: %d\n", oxcf->scaled_frame_width);
619 printf("scaled_frame_height: %d\n", oxcf->scaled_frame_height);
620 printf("two_pass_vbrbias: %d\n", oxcf->two_pass_vbrbias);
621 printf("two_pass_vbrmin_section: %d\n", oxcf->two_pass_vbrmin_section);
622 printf("two_pass_vbrmax_section: %d\n", oxcf->two_pass_vbrmax_section);
623 printf("lag_in_frames: %d\n", oxcf->lag_in_frames);
624 printf("enable_auto_arf: %d\n", oxcf->enable_auto_arf);
625 printf("Version: %d\n", oxcf->Version);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700626 printf("error resilient: %d\n", oxcf->error_resilient_mode);
627 printf("frame parallel detokenization: %d\n",
628 oxcf->frame_parallel_decoding_mode);
629 */
Yaowu Xuf883b422016-08-30 14:01:10 -0700630 return AOM_CODEC_OK;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700631}
632
Yaowu Xuf883b422016-08-30 14:01:10 -0700633static aom_codec_err_t encoder_set_config(aom_codec_alg_priv_t *ctx,
634 const aom_codec_enc_cfg_t *cfg) {
635 aom_codec_err_t res;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700636 int force_key = 0;
637
638 if (cfg->g_w != ctx->cfg.g_w || cfg->g_h != ctx->cfg.g_h) {
Yaowu Xuf883b422016-08-30 14:01:10 -0700639 if (cfg->g_lag_in_frames > 1 || cfg->g_pass != AOM_RC_ONE_PASS)
Yaowu Xuc27fc142016-08-22 16:08:15 -0700640 ERROR("Cannot change width or height after initialization");
641 if (!valid_ref_frame_size(ctx->cfg.g_w, ctx->cfg.g_h, cfg->g_w, cfg->g_h) ||
642 (ctx->cpi->initial_width && (int)cfg->g_w > ctx->cpi->initial_width) ||
643 (ctx->cpi->initial_height && (int)cfg->g_h > ctx->cpi->initial_height))
644 force_key = 1;
645 }
646
647 // Prevent increasing lag_in_frames. This check is stricter than it needs
648 // to be -- the limit is not increasing past the first lag_in_frames
649 // value, but we don't track the initial config, only the last successful
650 // config.
651 if (cfg->g_lag_in_frames > ctx->cfg.g_lag_in_frames)
652 ERROR("Cannot increase lag_in_frames");
653
654 res = validate_config(ctx, cfg, &ctx->extra_cfg);
655
Yaowu Xuf883b422016-08-30 14:01:10 -0700656 if (res == AOM_CODEC_OK) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700657 ctx->cfg = *cfg;
658 set_encoder_config(&ctx->oxcf, &ctx->cfg, &ctx->extra_cfg);
659 // On profile change, request a key frame
660 force_key |= ctx->cpi->common.profile != ctx->oxcf.profile;
Yaowu Xuf883b422016-08-30 14:01:10 -0700661 av1_change_config(ctx->cpi, &ctx->oxcf);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700662 }
663
Yaowu Xuf883b422016-08-30 14:01:10 -0700664 if (force_key) ctx->next_frame_flags |= AOM_EFLAG_FORCE_KF;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700665
666 return res;
667}
668
Yaowu Xuf883b422016-08-30 14:01:10 -0700669static aom_codec_err_t ctrl_get_quantizer(aom_codec_alg_priv_t *ctx,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700670 va_list args) {
671 int *const arg = va_arg(args, int *);
Yaowu Xuf883b422016-08-30 14:01:10 -0700672 if (arg == NULL) return AOM_CODEC_INVALID_PARAM;
673 *arg = av1_get_quantizer(ctx->cpi);
674 return AOM_CODEC_OK;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700675}
676
Yaowu Xuf883b422016-08-30 14:01:10 -0700677static aom_codec_err_t ctrl_get_quantizer64(aom_codec_alg_priv_t *ctx,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700678 va_list args) {
679 int *const arg = va_arg(args, int *);
Yaowu Xuf883b422016-08-30 14:01:10 -0700680 if (arg == NULL) return AOM_CODEC_INVALID_PARAM;
681 *arg = av1_qindex_to_quantizer(av1_get_quantizer(ctx->cpi));
682 return AOM_CODEC_OK;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700683}
684
Yaowu Xuf883b422016-08-30 14:01:10 -0700685static aom_codec_err_t update_extra_cfg(aom_codec_alg_priv_t *ctx,
686 const struct av1_extracfg *extra_cfg) {
687 const aom_codec_err_t res = validate_config(ctx, &ctx->cfg, extra_cfg);
688 if (res == AOM_CODEC_OK) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700689 ctx->extra_cfg = *extra_cfg;
690 set_encoder_config(&ctx->oxcf, &ctx->cfg, &ctx->extra_cfg);
Yaowu Xuf883b422016-08-30 14:01:10 -0700691 av1_change_config(ctx->cpi, &ctx->oxcf);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700692 }
693 return res;
694}
695
Yaowu Xuf883b422016-08-30 14:01:10 -0700696static aom_codec_err_t ctrl_set_cpuused(aom_codec_alg_priv_t *ctx,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700697 va_list args) {
Yaowu Xuf883b422016-08-30 14:01:10 -0700698 struct av1_extracfg extra_cfg = ctx->extra_cfg;
699 extra_cfg.cpu_used = CAST(AOME_SET_CPUUSED, args);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700700 return update_extra_cfg(ctx, &extra_cfg);
701}
702
Yaowu Xuf883b422016-08-30 14:01:10 -0700703static aom_codec_err_t ctrl_set_enable_auto_alt_ref(aom_codec_alg_priv_t *ctx,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700704 va_list args) {
Yaowu Xuf883b422016-08-30 14:01:10 -0700705 struct av1_extracfg extra_cfg = ctx->extra_cfg;
706 extra_cfg.enable_auto_alt_ref = CAST(AOME_SET_ENABLEAUTOALTREF, args);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700707 return update_extra_cfg(ctx, &extra_cfg);
708}
709
710#if CONFIG_EXT_REFS
Yaowu Xuf883b422016-08-30 14:01:10 -0700711static aom_codec_err_t ctrl_set_enable_auto_bwd_ref(aom_codec_alg_priv_t *ctx,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700712 va_list args) {
Yaowu Xuf883b422016-08-30 14:01:10 -0700713 struct av1_extracfg extra_cfg = ctx->extra_cfg;
714 extra_cfg.enable_auto_bwd_ref = CAST(AOME_SET_ENABLEAUTOBWDREF, args);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700715 return update_extra_cfg(ctx, &extra_cfg);
716}
717#endif // CONFIG_EXT_REFS
718
Yaowu Xuf883b422016-08-30 14:01:10 -0700719static aom_codec_err_t ctrl_set_noise_sensitivity(aom_codec_alg_priv_t *ctx,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700720 va_list args) {
Yaowu Xuf883b422016-08-30 14:01:10 -0700721 struct av1_extracfg extra_cfg = ctx->extra_cfg;
722 extra_cfg.noise_sensitivity = CAST(AV1E_SET_NOISE_SENSITIVITY, args);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700723 return update_extra_cfg(ctx, &extra_cfg);
724}
725
Yaowu Xuf883b422016-08-30 14:01:10 -0700726static aom_codec_err_t ctrl_set_sharpness(aom_codec_alg_priv_t *ctx,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700727 va_list args) {
Yaowu Xuf883b422016-08-30 14:01:10 -0700728 struct av1_extracfg extra_cfg = ctx->extra_cfg;
729 extra_cfg.sharpness = CAST(AOME_SET_SHARPNESS, args);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700730 return update_extra_cfg(ctx, &extra_cfg);
731}
732
Yaowu Xuf883b422016-08-30 14:01:10 -0700733static aom_codec_err_t ctrl_set_static_thresh(aom_codec_alg_priv_t *ctx,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700734 va_list args) {
Yaowu Xuf883b422016-08-30 14:01:10 -0700735 struct av1_extracfg extra_cfg = ctx->extra_cfg;
736 extra_cfg.static_thresh = CAST(AOME_SET_STATIC_THRESHOLD, args);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700737 return update_extra_cfg(ctx, &extra_cfg);
738}
739
Yaowu Xuf883b422016-08-30 14:01:10 -0700740static aom_codec_err_t ctrl_set_tile_columns(aom_codec_alg_priv_t *ctx,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700741 va_list args) {
Yaowu Xuf883b422016-08-30 14:01:10 -0700742 struct av1_extracfg extra_cfg = ctx->extra_cfg;
743 extra_cfg.tile_columns = CAST(AV1E_SET_TILE_COLUMNS, args);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700744 return update_extra_cfg(ctx, &extra_cfg);
745}
746
Yaowu Xuf883b422016-08-30 14:01:10 -0700747static aom_codec_err_t ctrl_set_tile_rows(aom_codec_alg_priv_t *ctx,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700748 va_list args) {
Yaowu Xuf883b422016-08-30 14:01:10 -0700749 struct av1_extracfg extra_cfg = ctx->extra_cfg;
750 extra_cfg.tile_rows = CAST(AV1E_SET_TILE_ROWS, args);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700751 return update_extra_cfg(ctx, &extra_cfg);
752}
Fangwen Fu7b9f2b32017-01-17 14:01:52 -0800753#if CONFIG_DEPENDENT_HORZTILES
754static aom_codec_err_t ctrl_set_tile_dependent_rows(aom_codec_alg_priv_t *ctx,
755 va_list args) {
756 struct av1_extracfg extra_cfg = ctx->extra_cfg;
757 extra_cfg.dependent_horz_tiles = CAST(AV1E_SET_TILE_DEPENDENT_ROWS, args);
758 return update_extra_cfg(ctx, &extra_cfg);
759}
760#endif
Ryan Lei9b02b0e2017-01-30 15:52:20 -0800761#if CONFIG_LOOPFILTERING_ACROSS_TILES
Ryan Lei7386eda2016-12-08 21:08:31 -0800762static aom_codec_err_t ctrl_set_tile_loopfilter(aom_codec_alg_priv_t *ctx,
763 va_list args) {
764 struct av1_extracfg extra_cfg = ctx->extra_cfg;
765 extra_cfg.loop_filter_across_tiles_enabled =
766 CAST(AV1E_SET_TILE_LOOPFILTER, args);
767 return update_extra_cfg(ctx, &extra_cfg);
768}
Ryan Lei9b02b0e2017-01-30 15:52:20 -0800769#endif // CONFIG_LOOPFILTERING_ACROSS_TILES
Ryan Lei7386eda2016-12-08 21:08:31 -0800770
Yaowu Xuf883b422016-08-30 14:01:10 -0700771static aom_codec_err_t ctrl_set_arnr_max_frames(aom_codec_alg_priv_t *ctx,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700772 va_list args) {
Yaowu Xuf883b422016-08-30 14:01:10 -0700773 struct av1_extracfg extra_cfg = ctx->extra_cfg;
774 extra_cfg.arnr_max_frames = CAST(AOME_SET_ARNR_MAXFRAMES, args);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700775 return update_extra_cfg(ctx, &extra_cfg);
776}
777
Yaowu Xuf883b422016-08-30 14:01:10 -0700778static aom_codec_err_t ctrl_set_arnr_strength(aom_codec_alg_priv_t *ctx,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700779 va_list args) {
Yaowu Xuf883b422016-08-30 14:01:10 -0700780 struct av1_extracfg extra_cfg = ctx->extra_cfg;
781 extra_cfg.arnr_strength = CAST(AOME_SET_ARNR_STRENGTH, args);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700782 return update_extra_cfg(ctx, &extra_cfg);
783}
784
Yaowu Xuf883b422016-08-30 14:01:10 -0700785static aom_codec_err_t ctrl_set_tuning(aom_codec_alg_priv_t *ctx,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700786 va_list args) {
Yaowu Xuf883b422016-08-30 14:01:10 -0700787 struct av1_extracfg extra_cfg = ctx->extra_cfg;
788 extra_cfg.tuning = CAST(AOME_SET_TUNING, args);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700789 return update_extra_cfg(ctx, &extra_cfg);
790}
791
Yaowu Xuf883b422016-08-30 14:01:10 -0700792static aom_codec_err_t ctrl_set_cq_level(aom_codec_alg_priv_t *ctx,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700793 va_list args) {
Yaowu Xuf883b422016-08-30 14:01:10 -0700794 struct av1_extracfg extra_cfg = ctx->extra_cfg;
795 extra_cfg.cq_level = CAST(AOME_SET_CQ_LEVEL, args);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700796 return update_extra_cfg(ctx, &extra_cfg);
797}
798
Yaowu Xuf883b422016-08-30 14:01:10 -0700799static aom_codec_err_t ctrl_set_rc_max_intra_bitrate_pct(
800 aom_codec_alg_priv_t *ctx, va_list args) {
801 struct av1_extracfg extra_cfg = ctx->extra_cfg;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700802 extra_cfg.rc_max_intra_bitrate_pct =
Yaowu Xuf883b422016-08-30 14:01:10 -0700803 CAST(AOME_SET_MAX_INTRA_BITRATE_PCT, args);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700804 return update_extra_cfg(ctx, &extra_cfg);
805}
806
Yaowu Xuf883b422016-08-30 14:01:10 -0700807static aom_codec_err_t ctrl_set_rc_max_inter_bitrate_pct(
808 aom_codec_alg_priv_t *ctx, va_list args) {
809 struct av1_extracfg extra_cfg = ctx->extra_cfg;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700810 extra_cfg.rc_max_inter_bitrate_pct =
Yaowu Xuf883b422016-08-30 14:01:10 -0700811 CAST(AOME_SET_MAX_INTER_BITRATE_PCT, args);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700812 return update_extra_cfg(ctx, &extra_cfg);
813}
814
Yaowu Xuf883b422016-08-30 14:01:10 -0700815static aom_codec_err_t ctrl_set_rc_gf_cbr_boost_pct(aom_codec_alg_priv_t *ctx,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700816 va_list args) {
Yaowu Xuf883b422016-08-30 14:01:10 -0700817 struct av1_extracfg extra_cfg = ctx->extra_cfg;
818 extra_cfg.gf_cbr_boost_pct = CAST(AV1E_SET_GF_CBR_BOOST_PCT, args);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700819 return update_extra_cfg(ctx, &extra_cfg);
820}
821
Yaowu Xuf883b422016-08-30 14:01:10 -0700822static aom_codec_err_t ctrl_set_lossless(aom_codec_alg_priv_t *ctx,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700823 va_list args) {
Yaowu Xuf883b422016-08-30 14:01:10 -0700824 struct av1_extracfg extra_cfg = ctx->extra_cfg;
825 extra_cfg.lossless = CAST(AV1E_SET_LOSSLESS, args);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700826 return update_extra_cfg(ctx, &extra_cfg);
827}
828
829#if CONFIG_AOM_QM
Yaowu Xuf883b422016-08-30 14:01:10 -0700830static aom_codec_err_t ctrl_set_enable_qm(aom_codec_alg_priv_t *ctx,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700831 va_list args) {
Yaowu Xuf883b422016-08-30 14:01:10 -0700832 struct av1_extracfg extra_cfg = ctx->extra_cfg;
833 extra_cfg.enable_qm = CAST(AV1E_SET_ENABLE_QM, args);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700834 return update_extra_cfg(ctx, &extra_cfg);
835}
836
Yaowu Xuf883b422016-08-30 14:01:10 -0700837static aom_codec_err_t ctrl_set_qm_min(aom_codec_alg_priv_t *ctx,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700838 va_list args) {
Yaowu Xuf883b422016-08-30 14:01:10 -0700839 struct av1_extracfg extra_cfg = ctx->extra_cfg;
840 extra_cfg.qm_min = CAST(AV1E_SET_QM_MIN, args);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700841 return update_extra_cfg(ctx, &extra_cfg);
842}
843
Yaowu Xuf883b422016-08-30 14:01:10 -0700844static aom_codec_err_t ctrl_set_qm_max(aom_codec_alg_priv_t *ctx,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700845 va_list args) {
Yaowu Xuf883b422016-08-30 14:01:10 -0700846 struct av1_extracfg extra_cfg = ctx->extra_cfg;
847 extra_cfg.qm_max = CAST(AV1E_SET_QM_MAX, args);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700848 return update_extra_cfg(ctx, &extra_cfg);
849}
850#endif
851
Thomas Daviesaf6df172016-11-09 14:04:18 +0000852#if CONFIG_TILE_GROUPS
853static aom_codec_err_t ctrl_set_num_tg(aom_codec_alg_priv_t *ctx,
854 va_list args) {
855 struct av1_extracfg extra_cfg = ctx->extra_cfg;
856 extra_cfg.num_tg = CAST(AV1E_SET_NUM_TG, args);
857 return update_extra_cfg(ctx, &extra_cfg);
858}
859
860static aom_codec_err_t ctrl_set_mtu(aom_codec_alg_priv_t *ctx, va_list args) {
861 struct av1_extracfg extra_cfg = ctx->extra_cfg;
862 extra_cfg.mtu_size = CAST(AV1E_SET_MTU, args);
863 return update_extra_cfg(ctx, &extra_cfg);
864}
865#endif
Fangwen Fu8d164de2016-12-14 13:40:54 -0800866#if CONFIG_TEMPMV_SIGNALING
867static aom_codec_err_t ctrl_set_disable_tempmv(aom_codec_alg_priv_t *ctx,
868 va_list args) {
869 struct av1_extracfg extra_cfg = ctx->extra_cfg;
870 extra_cfg.disable_tempmv = CAST(AV1E_SET_DISABLE_TEMPMV, args);
871 return update_extra_cfg(ctx, &extra_cfg);
872}
873#endif
Yaowu Xuf883b422016-08-30 14:01:10 -0700874static aom_codec_err_t ctrl_set_frame_parallel_decoding_mode(
875 aom_codec_alg_priv_t *ctx, va_list args) {
876 struct av1_extracfg extra_cfg = ctx->extra_cfg;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700877 extra_cfg.frame_parallel_decoding_mode =
Yaowu Xuf883b422016-08-30 14:01:10 -0700878 CAST(AV1E_SET_FRAME_PARALLEL_DECODING, args);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700879 return update_extra_cfg(ctx, &extra_cfg);
880}
881
Yunqing Wangd8cd55f2017-02-27 12:16:00 -0800882#if CONFIG_EXT_TILE
883static aom_codec_err_t ctrl_set_tile_encoding_mode(aom_codec_alg_priv_t *ctx,
884 va_list args) {
885 struct av1_extracfg extra_cfg = ctx->extra_cfg;
886 extra_cfg.tile_encoding_mode = CAST(AV1E_SET_TILE_ENCODING_MODE, args);
887 return update_extra_cfg(ctx, &extra_cfg);
888}
889#endif // CONFIG_EXT_TILE
890
Yaowu Xuf883b422016-08-30 14:01:10 -0700891static aom_codec_err_t ctrl_set_aq_mode(aom_codec_alg_priv_t *ctx,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700892 va_list args) {
Yaowu Xuf883b422016-08-30 14:01:10 -0700893 struct av1_extracfg extra_cfg = ctx->extra_cfg;
894 extra_cfg.aq_mode = CAST(AV1E_SET_AQ_MODE, args);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700895 return update_extra_cfg(ctx, &extra_cfg);
896}
897
Fangwen Fu6160df22017-04-24 09:45:51 -0700898#if CONFIG_EXT_DELTA_Q
899static aom_codec_err_t ctrl_set_deltaq_mode(aom_codec_alg_priv_t *ctx,
900 va_list args) {
901 struct av1_extracfg extra_cfg = ctx->extra_cfg;
902 extra_cfg.deltaq_mode = CAST(AV1E_SET_DELTAQ_MODE, args);
903 return update_extra_cfg(ctx, &extra_cfg);
904}
905#endif
Yaowu Xuf883b422016-08-30 14:01:10 -0700906static aom_codec_err_t ctrl_set_min_gf_interval(aom_codec_alg_priv_t *ctx,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700907 va_list args) {
Yaowu Xuf883b422016-08-30 14:01:10 -0700908 struct av1_extracfg extra_cfg = ctx->extra_cfg;
909 extra_cfg.min_gf_interval = CAST(AV1E_SET_MIN_GF_INTERVAL, args);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700910 return update_extra_cfg(ctx, &extra_cfg);
911}
912
Yaowu Xuf883b422016-08-30 14:01:10 -0700913static aom_codec_err_t ctrl_set_max_gf_interval(aom_codec_alg_priv_t *ctx,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700914 va_list args) {
Yaowu Xuf883b422016-08-30 14:01:10 -0700915 struct av1_extracfg extra_cfg = ctx->extra_cfg;
916 extra_cfg.max_gf_interval = CAST(AV1E_SET_MAX_GF_INTERVAL, args);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700917 return update_extra_cfg(ctx, &extra_cfg);
918}
919
Yaowu Xuf883b422016-08-30 14:01:10 -0700920static aom_codec_err_t ctrl_set_frame_periodic_boost(aom_codec_alg_priv_t *ctx,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700921 va_list args) {
Yaowu Xuf883b422016-08-30 14:01:10 -0700922 struct av1_extracfg extra_cfg = ctx->extra_cfg;
923 extra_cfg.frame_periodic_boost = CAST(AV1E_SET_FRAME_PERIODIC_BOOST, args);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700924 return update_extra_cfg(ctx, &extra_cfg);
925}
926
Yunqing Wangff4fa062017-04-21 10:56:08 -0700927static aom_codec_err_t ctrl_enable_motion_vector_unit_test(
928 aom_codec_alg_priv_t *ctx, va_list args) {
929 struct av1_extracfg extra_cfg = ctx->extra_cfg;
930 extra_cfg.motion_vector_unit_test =
931 CAST(AV1E_ENABLE_MOTION_VECTOR_UNIT_TEST, args);
932 return update_extra_cfg(ctx, &extra_cfg);
933}
934
Yaowu Xuf883b422016-08-30 14:01:10 -0700935static aom_codec_err_t encoder_init(aom_codec_ctx_t *ctx,
936 aom_codec_priv_enc_mr_cfg_t *data) {
937 aom_codec_err_t res = AOM_CODEC_OK;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700938 (void)data;
939
940 if (ctx->priv == NULL) {
Yaowu Xuf883b422016-08-30 14:01:10 -0700941 aom_codec_alg_priv_t *const priv = aom_calloc(1, sizeof(*priv));
942 if (priv == NULL) return AOM_CODEC_MEM_ERROR;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700943
Yaowu Xuf883b422016-08-30 14:01:10 -0700944 ctx->priv = (aom_codec_priv_t *)priv;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700945 ctx->priv->init_flags = ctx->init_flags;
946 ctx->priv->enc.total_encoders = 1;
Yaowu Xuf883b422016-08-30 14:01:10 -0700947 priv->buffer_pool = (BufferPool *)aom_calloc(1, sizeof(BufferPool));
948 if (priv->buffer_pool == NULL) return AOM_CODEC_MEM_ERROR;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700949
950#if CONFIG_MULTITHREAD
951 if (pthread_mutex_init(&priv->buffer_pool->pool_mutex, NULL)) {
Yaowu Xuf883b422016-08-30 14:01:10 -0700952 return AOM_CODEC_MEM_ERROR;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700953 }
954#endif
955
956 if (ctx->config.enc) {
957 // Update the reference to the config structure to an internal copy.
958 priv->cfg = *ctx->config.enc;
959 ctx->config.enc = &priv->cfg;
960 }
961
962 priv->extra_cfg = default_extra_cfg;
Yaowu Xuf883b422016-08-30 14:01:10 -0700963 once(av1_initialize_enc);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700964
965 res = validate_config(priv, &priv->cfg, &priv->extra_cfg);
966
Yaowu Xuf883b422016-08-30 14:01:10 -0700967 if (res == AOM_CODEC_OK) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700968 set_encoder_config(&priv->oxcf, &priv->cfg, &priv->extra_cfg);
Sebastien Alaiwan71e87842017-04-12 16:03:28 +0200969#if CONFIG_HIGHBITDEPTH
Yaowu Xuc27fc142016-08-22 16:08:15 -0700970 priv->oxcf.use_highbitdepth =
Yaowu Xuf883b422016-08-30 14:01:10 -0700971 (ctx->init_flags & AOM_CODEC_USE_HIGHBITDEPTH) ? 1 : 0;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700972#endif
Yaowu Xuf883b422016-08-30 14:01:10 -0700973 priv->cpi = av1_create_compressor(&priv->oxcf, priv->buffer_pool);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700974 if (priv->cpi == NULL)
Yaowu Xuf883b422016-08-30 14:01:10 -0700975 res = AOM_CODEC_MEM_ERROR;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700976 else
977 priv->cpi->output_pkt_list = &priv->pkt_list.head;
978 }
979 }
980
981 return res;
982}
983
Yaowu Xuf883b422016-08-30 14:01:10 -0700984static aom_codec_err_t encoder_destroy(aom_codec_alg_priv_t *ctx) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700985 free(ctx->cx_data);
Yaowu Xuf883b422016-08-30 14:01:10 -0700986 av1_remove_compressor(ctx->cpi);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700987#if CONFIG_MULTITHREAD
988 pthread_mutex_destroy(&ctx->buffer_pool->pool_mutex);
989#endif
Yaowu Xuf883b422016-08-30 14:01:10 -0700990 aom_free(ctx->buffer_pool);
991 aom_free(ctx);
992 return AOM_CODEC_OK;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700993}
994
Yaowu Xuf883b422016-08-30 14:01:10 -0700995static void pick_quickcompress_mode(aom_codec_alg_priv_t *ctx,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700996 unsigned long deadline) {
Thomas Daede6eca8352017-03-17 14:14:12 -0700997 MODE new_mode = GOOD;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700998
999 switch (ctx->cfg.g_pass) {
Yaowu Xuf883b422016-08-30 14:01:10 -07001000 case AOM_RC_ONE_PASS:
Thomas Daedeac0a3802016-03-01 14:29:47 -08001001 switch (deadline) {
Thomas Daedeac0a3802016-03-01 14:29:47 -08001002 default: new_mode = GOOD; break;
Yaowu Xuc27fc142016-08-22 16:08:15 -07001003 }
1004 break;
Yaowu Xuf883b422016-08-30 14:01:10 -07001005 case AOM_RC_FIRST_PASS: break;
Thomas Daede6eca8352017-03-17 14:14:12 -07001006 case AOM_RC_LAST_PASS: new_mode = GOOD;
Yaowu Xuc27fc142016-08-22 16:08:15 -07001007 }
1008
1009 if (ctx->oxcf.mode != new_mode) {
1010 ctx->oxcf.mode = new_mode;
Yaowu Xuf883b422016-08-30 14:01:10 -07001011 av1_change_config(ctx->cpi, &ctx->oxcf);
Yaowu Xuc27fc142016-08-22 16:08:15 -07001012 }
1013}
1014
1015// Turn on to test if supplemental superframe data breaks decoding
1016// #define TEST_SUPPLEMENTAL_SUPERFRAME_DATA
Yaowu Xuf883b422016-08-30 14:01:10 -07001017static int write_superframe_index(aom_codec_alg_priv_t *ctx) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07001018 uint8_t marker = 0xc0;
Yaowu Xuc27fc142016-08-22 16:08:15 -07001019 size_t max_frame_sz = 0;
1020
1021 assert(ctx->pending_frame_count);
1022 assert(ctx->pending_frame_count <= 8);
1023
1024 // Add the number of frames to the marker byte
1025 marker |= ctx->pending_frame_count - 1;
Sebastien Alaiwan62fc41a2017-06-19 11:02:20 +02001026 for (int i = 0; i < ctx->pending_frame_count - 1; i++) {
Sebastien Alaiwan0ba49a52017-06-19 11:58:18 +02001027 const size_t frame_sz = ctx->pending_frame_sizes[i] - 1;
1028 max_frame_sz = AOMMAX(frame_sz, max_frame_sz);
Yaowu Xuc27fc142016-08-22 16:08:15 -07001029 }
1030
1031 // Choose the magnitude
Sebastien Alaiwan62fc41a2017-06-19 11:02:20 +02001032 int mag;
1033 unsigned int mask;
Yaowu Xuc27fc142016-08-22 16:08:15 -07001034 for (mag = 0, mask = 0xff; mag < 4; mag++) {
1035 if (max_frame_sz <= mask) break;
1036 mask <<= 8;
1037 mask |= 0xff;
1038 }
1039 marker |= mag << 3;
1040
1041 // Write the index
Sebastien Alaiwan62fc41a2017-06-19 11:02:20 +02001042 const int index_sz = 2 + (mag + 1) * (ctx->pending_frame_count - 1);
Yaowu Xuc27fc142016-08-22 16:08:15 -07001043 if (ctx->pending_cx_data_sz + index_sz < ctx->cx_data_sz) {
1044 uint8_t *x = ctx->pending_cx_data + ctx->pending_cx_data_sz;
Yaowu Xuc27fc142016-08-22 16:08:15 -07001045#ifdef TEST_SUPPLEMENTAL_SUPERFRAME_DATA
1046 uint8_t marker_test = 0xc0;
1047 int mag_test = 2; // 1 - 4
1048 int frames_test = 4; // 1 - 8
1049 int index_sz_test = 2 + mag_test * frames_test;
1050 marker_test |= frames_test - 1;
1051 marker_test |= (mag_test - 1) << 3;
1052 *x++ = marker_test;
Sebastien Alaiwan62fc41a2017-06-19 11:02:20 +02001053 for (int i = 0; i < mag_test * frames_test; ++i)
Yaowu Xuc27fc142016-08-22 16:08:15 -07001054 *x++ = 0; // fill up with arbitrary data
1055 *x++ = marker_test;
1056 ctx->pending_cx_data_sz += index_sz_test;
1057 printf("Added supplemental superframe data\n");
1058#endif
1059
1060 *x++ = marker;
Sebastien Alaiwan62fc41a2017-06-19 11:02:20 +02001061 for (int i = 0; i < ctx->pending_frame_count - 1; i++) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07001062 assert(ctx->pending_frame_sizes[i] > 0);
Sebastien Alaiwan62fc41a2017-06-19 11:02:20 +02001063 unsigned int this_sz = (unsigned int)ctx->pending_frame_sizes[i] - 1;
1064 for (int j = 0; j <= mag; j++) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07001065 *x++ = this_sz & 0xff;
1066 this_sz >>= 8;
1067 }
1068 }
1069 *x++ = marker;
1070 ctx->pending_cx_data_sz += index_sz;
1071#ifdef TEST_SUPPLEMENTAL_SUPERFRAME_DATA
1072 index_sz += index_sz_test;
1073#endif
1074 }
1075 return index_sz;
1076}
1077
Yaowu Xuf883b422016-08-30 14:01:10 -07001078// av1 uses 10,000,000 ticks/second as time stamp
Yaowu Xuc27fc142016-08-22 16:08:15 -07001079#define TICKS_PER_SEC 10000000LL
1080
Yaowu Xuf883b422016-08-30 14:01:10 -07001081static int64_t timebase_units_to_ticks(const aom_rational_t *timebase,
Yaowu Xuc27fc142016-08-22 16:08:15 -07001082 int64_t n) {
1083 return n * TICKS_PER_SEC * timebase->num / timebase->den;
1084}
1085
Yaowu Xuf883b422016-08-30 14:01:10 -07001086static int64_t ticks_to_timebase_units(const aom_rational_t *timebase,
Yaowu Xuc27fc142016-08-22 16:08:15 -07001087 int64_t n) {
1088 const int64_t round = TICKS_PER_SEC * timebase->num / 2 - 1;
1089 return (n * timebase->den + round) / timebase->num / TICKS_PER_SEC;
1090}
1091
Yaowu Xuf883b422016-08-30 14:01:10 -07001092static aom_codec_frame_flags_t get_frame_pkt_flags(const AV1_COMP *cpi,
Yaowu Xuc27fc142016-08-22 16:08:15 -07001093 unsigned int lib_flags) {
Yaowu Xuf883b422016-08-30 14:01:10 -07001094 aom_codec_frame_flags_t flags = lib_flags << 16;
Yaowu Xuc27fc142016-08-22 16:08:15 -07001095
Yaowu Xuf883b422016-08-30 14:01:10 -07001096 if (lib_flags & FRAMEFLAGS_KEY) flags |= AOM_FRAME_IS_KEY;
Yaowu Xuc27fc142016-08-22 16:08:15 -07001097
Yaowu Xuf883b422016-08-30 14:01:10 -07001098 if (cpi->droppable) flags |= AOM_FRAME_IS_DROPPABLE;
Yaowu Xuc27fc142016-08-22 16:08:15 -07001099
1100 return flags;
1101}
1102
Yaowu Xuf883b422016-08-30 14:01:10 -07001103static aom_codec_err_t encoder_encode(aom_codec_alg_priv_t *ctx,
1104 const aom_image_t *img,
1105 aom_codec_pts_t pts,
Yaowu Xuc27fc142016-08-22 16:08:15 -07001106 unsigned long duration,
Yaowu Xuf883b422016-08-30 14:01:10 -07001107 aom_enc_frame_flags_t enc_flags,
Yaowu Xuc27fc142016-08-22 16:08:15 -07001108 unsigned long deadline) {
Ralph Giles19944292017-04-18 13:46:56 -07001109 const size_t kMinCompressedSize = 8192;
Yaowu Xuf883b422016-08-30 14:01:10 -07001110 volatile aom_codec_err_t res = AOM_CODEC_OK;
Yaowu Xuf883b422016-08-30 14:01:10 -07001111 AV1_COMP *const cpi = ctx->cpi;
1112 const aom_rational_t *const timebase = &ctx->cfg.g_timebase;
Yaowu Xuc27fc142016-08-22 16:08:15 -07001113
Yaowu Xuf883b422016-08-30 14:01:10 -07001114 if (cpi == NULL) return AOM_CODEC_INVALID_PARAM;
Yaowu Xuc27fc142016-08-22 16:08:15 -07001115
1116 if (img != NULL) {
1117 res = validate_img(ctx, img);
1118 // TODO(jzern) the checks related to cpi's validity should be treated as a
1119 // failure condition, encoder setup is done fully in init() currently.
Yaowu Xuf883b422016-08-30 14:01:10 -07001120 if (res == AOM_CODEC_OK) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07001121#if CONFIG_EXT_REFS
Sebastien Alaiwan62fc41a2017-06-19 11:02:20 +02001122 size_t data_sz = ALIGN_POWER_OF_TWO(ctx->cfg.g_w, 5) *
1123 ALIGN_POWER_OF_TWO(ctx->cfg.g_h, 5) * get_image_bps(img);
Yaowu Xuc27fc142016-08-22 16:08:15 -07001124#else
1125 // There's no codec control for multiple alt-refs so check the encoder
1126 // instance for its status to determine the compressed data size.
Sebastien Alaiwan62fc41a2017-06-19 11:02:20 +02001127 size_t data_sz = ALIGN_POWER_OF_TWO(ctx->cfg.g_w, 5) *
1128 ALIGN_POWER_OF_TWO(ctx->cfg.g_h, 5) *
1129 get_image_bps(img) / 8 *
1130 (cpi->multi_arf_allowed ? 8 : 2);
Yaowu Xuc27fc142016-08-22 16:08:15 -07001131#endif // CONFIG_EXT_REFS
Yaowu Xu416b0d92016-07-11 11:38:53 -07001132 if (data_sz < kMinCompressedSize) data_sz = kMinCompressedSize;
Yaowu Xuc27fc142016-08-22 16:08:15 -07001133 if (ctx->cx_data == NULL || ctx->cx_data_sz < data_sz) {
1134 ctx->cx_data_sz = data_sz;
1135 free(ctx->cx_data);
1136 ctx->cx_data = (unsigned char *)malloc(ctx->cx_data_sz);
1137 if (ctx->cx_data == NULL) {
Yaowu Xuf883b422016-08-30 14:01:10 -07001138 return AOM_CODEC_MEM_ERROR;
Yaowu Xuc27fc142016-08-22 16:08:15 -07001139 }
1140 }
1141 }
1142 }
1143
Thomas Daedeac0a3802016-03-01 14:29:47 -08001144 pick_quickcompress_mode(ctx, deadline);
Yaowu Xuf883b422016-08-30 14:01:10 -07001145 aom_codec_pkt_list_init(&ctx->pkt_list);
Yaowu Xuc27fc142016-08-22 16:08:15 -07001146
Sebastien Alaiwan62fc41a2017-06-19 11:02:20 +02001147 volatile aom_enc_frame_flags_t flags = enc_flags;
1148
Yaowu Xuc27fc142016-08-22 16:08:15 -07001149 // Handle Flags
Yaowu Xuf883b422016-08-30 14:01:10 -07001150 if (((flags & AOM_EFLAG_NO_UPD_GF) && (flags & AOM_EFLAG_FORCE_GF)) ||
1151 ((flags & AOM_EFLAG_NO_UPD_ARF) && (flags & AOM_EFLAG_FORCE_ARF))) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07001152 ctx->base.err_detail = "Conflicting flags.";
Yaowu Xuf883b422016-08-30 14:01:10 -07001153 return AOM_CODEC_INVALID_PARAM;
Yaowu Xuc27fc142016-08-22 16:08:15 -07001154 }
1155
1156 if (setjmp(cpi->common.error.jmp)) {
1157 cpi->common.error.setjmp = 0;
1158 res = update_error_state(ctx, &cpi->common.error);
Yaowu Xuf883b422016-08-30 14:01:10 -07001159 aom_clear_system_state();
Yaowu Xuc27fc142016-08-22 16:08:15 -07001160 return res;
1161 }
1162 cpi->common.error.setjmp = 1;
1163
Yaowu Xuf883b422016-08-30 14:01:10 -07001164 av1_apply_encoding_flags(cpi, flags);
Yaowu Xuc27fc142016-08-22 16:08:15 -07001165
1166 // Handle fixed keyframe intervals
Yaowu Xuf883b422016-08-30 14:01:10 -07001167 if (ctx->cfg.kf_mode == AOM_KF_AUTO &&
Yaowu Xuc27fc142016-08-22 16:08:15 -07001168 ctx->cfg.kf_min_dist == ctx->cfg.kf_max_dist) {
1169 if (++ctx->fixed_kf_cntr > ctx->cfg.kf_min_dist) {
Yaowu Xuf883b422016-08-30 14:01:10 -07001170 flags |= AOM_EFLAG_FORCE_KF;
Yaowu Xuc27fc142016-08-22 16:08:15 -07001171 ctx->fixed_kf_cntr = 1;
1172 }
1173 }
1174
Yaowu Xuf883b422016-08-30 14:01:10 -07001175 if (res == AOM_CODEC_OK) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07001176 int64_t dst_time_stamp = timebase_units_to_ticks(timebase, pts);
1177 int64_t dst_end_time_stamp =
1178 timebase_units_to_ticks(timebase, pts + duration);
Yaowu Xuc27fc142016-08-22 16:08:15 -07001179
1180 // Set up internal flags
Yaowu Xuf883b422016-08-30 14:01:10 -07001181 if (ctx->base.init_flags & AOM_CODEC_USE_PSNR) cpi->b_calculate_psnr = 1;
Yaowu Xuc27fc142016-08-22 16:08:15 -07001182
1183 if (img != NULL) {
Sebastien Alaiwan62fc41a2017-06-19 11:02:20 +02001184 YV12_BUFFER_CONFIG sd;
Yaowu Xuc27fc142016-08-22 16:08:15 -07001185 res = image2yuvconfig(img, &sd);
1186
1187 // Store the original flags in to the frame buffer. Will extract the
1188 // key frame flag when we actually encode this frame.
Yaowu Xuf883b422016-08-30 14:01:10 -07001189 if (av1_receive_raw_frame(cpi, flags | ctx->next_frame_flags, &sd,
1190 dst_time_stamp, dst_end_time_stamp)) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07001191 res = update_error_state(ctx, &cpi->common.error);
1192 }
1193 ctx->next_frame_flags = 0;
1194 }
1195
Sebastien Alaiwan62fc41a2017-06-19 11:02:20 +02001196 unsigned char *cx_data = ctx->cx_data;
1197 size_t cx_data_sz = ctx->cx_data_sz;
Yaowu Xuc27fc142016-08-22 16:08:15 -07001198
1199 /* Any pending invisible frames? */
1200 if (ctx->pending_cx_data) {
1201 memmove(cx_data, ctx->pending_cx_data, ctx->pending_cx_data_sz);
1202 ctx->pending_cx_data = cx_data;
1203 cx_data += ctx->pending_cx_data_sz;
1204 cx_data_sz -= ctx->pending_cx_data_sz;
1205
1206 /* TODO: this is a minimal check, the underlying codec doesn't respect
1207 * the buffer size anyway.
1208 */
1209 if (cx_data_sz < ctx->cx_data_sz / 2) {
Yaowu Xuf883b422016-08-30 14:01:10 -07001210 aom_internal_error(&cpi->common.error, AOM_CODEC_ERROR,
Yaowu Xuc27fc142016-08-22 16:08:15 -07001211 "Compressed data buffer too small");
Yaowu Xuf883b422016-08-30 14:01:10 -07001212 return AOM_CODEC_ERROR;
Yaowu Xuc27fc142016-08-22 16:08:15 -07001213 }
1214 }
1215
Sebastien Alaiwan918c3c12017-06-19 11:32:10 +02001216 size_t frame_size;
Sebastien Alaiwan62fc41a2017-06-19 11:02:20 +02001217 unsigned int lib_flags = 0;
Yaowu Xuc27fc142016-08-22 16:08:15 -07001218 while (cx_data_sz >= ctx->cx_data_sz / 2 &&
Sebastien Alaiwan918c3c12017-06-19 11:32:10 +02001219 -1 != av1_get_compressed_data(cpi, &lib_flags, &frame_size, cx_data,
Yaowu Xuf883b422016-08-30 14:01:10 -07001220 &dst_time_stamp, &dst_end_time_stamp,
1221 !img)) {
Arild Fuldseth (arilfuld)5114b7b2016-11-09 13:32:54 +01001222#if CONFIG_REFERENCE_BUFFER
1223 if (cpi->common.invalid_delta_frame_id_minus1) {
1224 ctx->base.err_detail = "Invalid delta_frame_id_minus1";
1225 return AOM_CODEC_ERROR;
1226 }
1227#endif
Sebastien Alaiwan918c3c12017-06-19 11:32:10 +02001228 if (frame_size) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07001229 // Pack invisible frames with the next visible frame
1230 if (!cpi->common.show_frame) {
1231 if (ctx->pending_cx_data == 0) ctx->pending_cx_data = cx_data;
Sebastien Alaiwan918c3c12017-06-19 11:32:10 +02001232 ctx->pending_cx_data_sz += frame_size;
1233 ctx->pending_frame_sizes[ctx->pending_frame_count++] = frame_size;
1234 cx_data += frame_size;
1235 cx_data_sz -= frame_size;
Yaowu Xuc27fc142016-08-22 16:08:15 -07001236
1237 continue;
1238 }
1239
1240 // Add the frame packet to the list of returned packets.
Sebastien Alaiwan62fc41a2017-06-19 11:02:20 +02001241 aom_codec_cx_pkt_t pkt;
1242
Yaowu Xuf883b422016-08-30 14:01:10 -07001243 pkt.kind = AOM_CODEC_CX_FRAME_PKT;
Yaowu Xuc27fc142016-08-22 16:08:15 -07001244 pkt.data.frame.pts = ticks_to_timebase_units(timebase, dst_time_stamp);
1245 pkt.data.frame.duration = (unsigned long)ticks_to_timebase_units(
1246 timebase, dst_end_time_stamp - dst_time_stamp);
1247 pkt.data.frame.flags = get_frame_pkt_flags(cpi, lib_flags);
1248
1249 if (ctx->pending_cx_data) {
Sebastien Alaiwan918c3c12017-06-19 11:32:10 +02001250 ctx->pending_frame_sizes[ctx->pending_frame_count++] = frame_size;
1251 ctx->pending_cx_data_sz += frame_size;
1252 frame_size += write_superframe_index(ctx);
Yaowu Xuc27fc142016-08-22 16:08:15 -07001253 pkt.data.frame.buf = ctx->pending_cx_data;
1254 pkt.data.frame.sz = ctx->pending_cx_data_sz;
1255 ctx->pending_cx_data = NULL;
1256 ctx->pending_cx_data_sz = 0;
1257 ctx->pending_frame_count = 0;
1258 } else {
1259 pkt.data.frame.buf = cx_data;
Sebastien Alaiwan918c3c12017-06-19 11:32:10 +02001260 pkt.data.frame.sz = frame_size;
Yaowu Xuc27fc142016-08-22 16:08:15 -07001261 }
1262 pkt.data.frame.partition_id = -1;
1263
Yaowu Xuf883b422016-08-30 14:01:10 -07001264 aom_codec_pkt_list_add(&ctx->pkt_list.head, &pkt);
Yaowu Xuc27fc142016-08-22 16:08:15 -07001265
Sebastien Alaiwan918c3c12017-06-19 11:32:10 +02001266 cx_data += frame_size;
1267 cx_data_sz -= frame_size;
Yaowu Xuc27fc142016-08-22 16:08:15 -07001268 }
1269 }
1270 }
1271
1272 cpi->common.error.setjmp = 0;
1273 return res;
1274}
1275
Yaowu Xuf883b422016-08-30 14:01:10 -07001276static const aom_codec_cx_pkt_t *encoder_get_cxdata(aom_codec_alg_priv_t *ctx,
1277 aom_codec_iter_t *iter) {
1278 return aom_codec_pkt_list_get(&ctx->pkt_list.head, iter);
Yaowu Xuc27fc142016-08-22 16:08:15 -07001279}
1280
Yaowu Xuf883b422016-08-30 14:01:10 -07001281static aom_codec_err_t ctrl_set_reference(aom_codec_alg_priv_t *ctx,
Yaowu Xuc27fc142016-08-22 16:08:15 -07001282 va_list args) {
Yaowu Xuf883b422016-08-30 14:01:10 -07001283 aom_ref_frame_t *const frame = va_arg(args, aom_ref_frame_t *);
Yaowu Xuc27fc142016-08-22 16:08:15 -07001284
1285 if (frame != NULL) {
1286 YV12_BUFFER_CONFIG sd;
1287
1288 image2yuvconfig(&frame->img, &sd);
Yaowu Xuf883b422016-08-30 14:01:10 -07001289 av1_set_reference_enc(ctx->cpi, ref_frame_to_av1_reframe(frame->frame_type),
1290 &sd);
1291 return AOM_CODEC_OK;
Yaowu Xuc27fc142016-08-22 16:08:15 -07001292 } else {
Yaowu Xuf883b422016-08-30 14:01:10 -07001293 return AOM_CODEC_INVALID_PARAM;
Yaowu Xuc27fc142016-08-22 16:08:15 -07001294 }
1295}
1296
Yaowu Xuf883b422016-08-30 14:01:10 -07001297static aom_codec_err_t ctrl_copy_reference(aom_codec_alg_priv_t *ctx,
Yaowu Xuc27fc142016-08-22 16:08:15 -07001298 va_list args) {
Yaowu Xuf883b422016-08-30 14:01:10 -07001299 aom_ref_frame_t *const frame = va_arg(args, aom_ref_frame_t *);
Yaowu Xuc27fc142016-08-22 16:08:15 -07001300
1301 if (frame != NULL) {
1302 YV12_BUFFER_CONFIG sd;
1303
1304 image2yuvconfig(&frame->img, &sd);
Yaowu Xuf883b422016-08-30 14:01:10 -07001305 av1_copy_reference_enc(ctx->cpi,
1306 ref_frame_to_av1_reframe(frame->frame_type), &sd);
1307 return AOM_CODEC_OK;
Yaowu Xuc27fc142016-08-22 16:08:15 -07001308 } else {
Yaowu Xuf883b422016-08-30 14:01:10 -07001309 return AOM_CODEC_INVALID_PARAM;
Yaowu Xuc27fc142016-08-22 16:08:15 -07001310 }
1311}
1312
Yaowu Xuf883b422016-08-30 14:01:10 -07001313static aom_codec_err_t ctrl_get_reference(aom_codec_alg_priv_t *ctx,
Yaowu Xuc27fc142016-08-22 16:08:15 -07001314 va_list args) {
Yaowu Xuf883b422016-08-30 14:01:10 -07001315 av1_ref_frame_t *const frame = va_arg(args, av1_ref_frame_t *);
Yaowu Xuc27fc142016-08-22 16:08:15 -07001316
1317 if (frame != NULL) {
1318 YV12_BUFFER_CONFIG *fb = get_ref_frame(&ctx->cpi->common, frame->idx);
Yaowu Xuf883b422016-08-30 14:01:10 -07001319 if (fb == NULL) return AOM_CODEC_ERROR;
Yaowu Xuc27fc142016-08-22 16:08:15 -07001320
1321 yuvconfig2image(&frame->img, fb, NULL);
Yaowu Xuf883b422016-08-30 14:01:10 -07001322 return AOM_CODEC_OK;
Yaowu Xuc27fc142016-08-22 16:08:15 -07001323 } else {
Yaowu Xuf883b422016-08-30 14:01:10 -07001324 return AOM_CODEC_INVALID_PARAM;
Yaowu Xuc27fc142016-08-22 16:08:15 -07001325 }
1326}
1327
Yaowu Xuf883b422016-08-30 14:01:10 -07001328static aom_codec_err_t ctrl_get_new_frame_image(aom_codec_alg_priv_t *ctx,
Yaowu Xuc27fc142016-08-22 16:08:15 -07001329 va_list args) {
Yaowu Xuf883b422016-08-30 14:01:10 -07001330 aom_image_t *const new_img = va_arg(args, aom_image_t *);
Yaowu Xuc27fc142016-08-22 16:08:15 -07001331
1332 if (new_img != NULL) {
1333 YV12_BUFFER_CONFIG new_frame;
1334
Yaowu Xuf883b422016-08-30 14:01:10 -07001335 if (av1_get_last_show_frame(ctx->cpi, &new_frame) == 0) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07001336 yuvconfig2image(new_img, &new_frame, NULL);
Yaowu Xuf883b422016-08-30 14:01:10 -07001337 return AOM_CODEC_OK;
Yaowu Xuc27fc142016-08-22 16:08:15 -07001338 } else {
Yaowu Xuf883b422016-08-30 14:01:10 -07001339 return AOM_CODEC_ERROR;
Yaowu Xuc27fc142016-08-22 16:08:15 -07001340 }
1341 } else {
Yaowu Xuf883b422016-08-30 14:01:10 -07001342 return AOM_CODEC_INVALID_PARAM;
Yaowu Xuc27fc142016-08-22 16:08:15 -07001343 }
1344}
1345
Yaowu Xuf883b422016-08-30 14:01:10 -07001346static aom_codec_err_t ctrl_set_previewpp(aom_codec_alg_priv_t *ctx,
Yaowu Xuc27fc142016-08-22 16:08:15 -07001347 va_list args) {
1348 (void)ctx;
1349 (void)args;
Yaowu Xuf883b422016-08-30 14:01:10 -07001350 return AOM_CODEC_INCAPABLE;
Yaowu Xuc27fc142016-08-22 16:08:15 -07001351}
1352
Yaowu Xuf883b422016-08-30 14:01:10 -07001353static aom_image_t *encoder_get_preview(aom_codec_alg_priv_t *ctx) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07001354 YV12_BUFFER_CONFIG sd;
1355
Yaowu Xuf883b422016-08-30 14:01:10 -07001356 if (av1_get_preview_raw_frame(ctx->cpi, &sd) == 0) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07001357 yuvconfig2image(&ctx->preview_img, &sd, NULL);
1358 return &ctx->preview_img;
1359 } else {
1360 return NULL;
1361 }
1362}
1363
Yaowu Xuf883b422016-08-30 14:01:10 -07001364static aom_codec_err_t ctrl_use_reference(aom_codec_alg_priv_t *ctx,
Yaowu Xuc27fc142016-08-22 16:08:15 -07001365 va_list args) {
1366 const int reference_flag = va_arg(args, int);
1367
Yaowu Xuf883b422016-08-30 14:01:10 -07001368 av1_use_as_reference(ctx->cpi, reference_flag);
1369 return AOM_CODEC_OK;
Yaowu Xuc27fc142016-08-22 16:08:15 -07001370}
1371
Yaowu Xuf883b422016-08-30 14:01:10 -07001372static aom_codec_err_t ctrl_set_roi_map(aom_codec_alg_priv_t *ctx,
Yaowu Xuc27fc142016-08-22 16:08:15 -07001373 va_list args) {
1374 (void)ctx;
1375 (void)args;
1376
Yaowu Xuf883b422016-08-30 14:01:10 -07001377 // TODO(yaowu): Need to re-implement and test for AV1.
1378 return AOM_CODEC_INVALID_PARAM;
Yaowu Xuc27fc142016-08-22 16:08:15 -07001379}
1380
Yaowu Xuf883b422016-08-30 14:01:10 -07001381static aom_codec_err_t ctrl_set_active_map(aom_codec_alg_priv_t *ctx,
Yaowu Xuc27fc142016-08-22 16:08:15 -07001382 va_list args) {
Yaowu Xuf883b422016-08-30 14:01:10 -07001383 aom_active_map_t *const map = va_arg(args, aom_active_map_t *);
Yaowu Xuc27fc142016-08-22 16:08:15 -07001384
1385 if (map) {
Yaowu Xuf883b422016-08-30 14:01:10 -07001386 if (!av1_set_active_map(ctx->cpi, map->active_map, (int)map->rows,
1387 (int)map->cols))
1388 return AOM_CODEC_OK;
Yaowu Xuc27fc142016-08-22 16:08:15 -07001389 else
Yaowu Xuf883b422016-08-30 14:01:10 -07001390 return AOM_CODEC_INVALID_PARAM;
Yaowu Xuc27fc142016-08-22 16:08:15 -07001391 } else {
Yaowu Xuf883b422016-08-30 14:01:10 -07001392 return AOM_CODEC_INVALID_PARAM;
Yaowu Xuc27fc142016-08-22 16:08:15 -07001393 }
1394}
1395
Yaowu Xuf883b422016-08-30 14:01:10 -07001396static aom_codec_err_t ctrl_get_active_map(aom_codec_alg_priv_t *ctx,
Yaowu Xuc27fc142016-08-22 16:08:15 -07001397 va_list args) {
Yaowu Xuf883b422016-08-30 14:01:10 -07001398 aom_active_map_t *const map = va_arg(args, aom_active_map_t *);
Yaowu Xuc27fc142016-08-22 16:08:15 -07001399
1400 if (map) {
Yaowu Xuf883b422016-08-30 14:01:10 -07001401 if (!av1_get_active_map(ctx->cpi, map->active_map, (int)map->rows,
1402 (int)map->cols))
1403 return AOM_CODEC_OK;
Yaowu Xuc27fc142016-08-22 16:08:15 -07001404 else
Yaowu Xuf883b422016-08-30 14:01:10 -07001405 return AOM_CODEC_INVALID_PARAM;
Yaowu Xuc27fc142016-08-22 16:08:15 -07001406 } else {
Yaowu Xuf883b422016-08-30 14:01:10 -07001407 return AOM_CODEC_INVALID_PARAM;
Yaowu Xuc27fc142016-08-22 16:08:15 -07001408 }
1409}
1410
Yaowu Xuf883b422016-08-30 14:01:10 -07001411static aom_codec_err_t ctrl_set_scale_mode(aom_codec_alg_priv_t *ctx,
Yaowu Xuc27fc142016-08-22 16:08:15 -07001412 va_list args) {
Yaowu Xuf883b422016-08-30 14:01:10 -07001413 aom_scaling_mode_t *const mode = va_arg(args, aom_scaling_mode_t *);
Yaowu Xuc27fc142016-08-22 16:08:15 -07001414
1415 if (mode) {
1416 const int res =
Yaowu Xuf883b422016-08-30 14:01:10 -07001417 av1_set_internal_size(ctx->cpi, (AOM_SCALING)mode->h_scaling_mode,
1418 (AOM_SCALING)mode->v_scaling_mode);
1419 return (res == 0) ? AOM_CODEC_OK : AOM_CODEC_INVALID_PARAM;
Yaowu Xuc27fc142016-08-22 16:08:15 -07001420 } else {
Yaowu Xuf883b422016-08-30 14:01:10 -07001421 return AOM_CODEC_INVALID_PARAM;
Yaowu Xuc27fc142016-08-22 16:08:15 -07001422 }
1423}
1424
Yaowu Xuf883b422016-08-30 14:01:10 -07001425static aom_codec_err_t ctrl_set_tune_content(aom_codec_alg_priv_t *ctx,
Yaowu Xuc27fc142016-08-22 16:08:15 -07001426 va_list args) {
Yaowu Xuf883b422016-08-30 14:01:10 -07001427 struct av1_extracfg extra_cfg = ctx->extra_cfg;
1428 extra_cfg.content = CAST(AV1E_SET_TUNE_CONTENT, args);
Yaowu Xuc27fc142016-08-22 16:08:15 -07001429 return update_extra_cfg(ctx, &extra_cfg);
1430}
1431
Yaowu Xuf883b422016-08-30 14:01:10 -07001432static aom_codec_err_t ctrl_set_color_space(aom_codec_alg_priv_t *ctx,
Yaowu Xuc27fc142016-08-22 16:08:15 -07001433 va_list args) {
Yaowu Xuf883b422016-08-30 14:01:10 -07001434 struct av1_extracfg extra_cfg = ctx->extra_cfg;
1435 extra_cfg.color_space = CAST(AV1E_SET_COLOR_SPACE, args);
Yaowu Xuc27fc142016-08-22 16:08:15 -07001436 return update_extra_cfg(ctx, &extra_cfg);
1437}
1438
anorkin76fb1262017-03-22 15:12:12 -07001439#if CONFIG_COLORSPACE_HEADERS
1440static aom_codec_err_t ctrl_set_transfer_function(aom_codec_alg_priv_t *ctx,
1441 va_list args) {
1442 struct av1_extracfg extra_cfg = ctx->extra_cfg;
1443 extra_cfg.transfer_function = CAST(AV1E_SET_TRANSFER_FUNCTION, args);
1444 return update_extra_cfg(ctx, &extra_cfg);
1445}
1446
1447static aom_codec_err_t ctrl_set_chroma_sample_position(
1448 aom_codec_alg_priv_t *ctx, va_list args) {
1449 struct av1_extracfg extra_cfg = ctx->extra_cfg;
1450 extra_cfg.chroma_sample_position =
1451 CAST(AV1E_SET_CHROMA_SAMPLE_POSITION, args);
1452 return update_extra_cfg(ctx, &extra_cfg);
1453}
1454#endif
1455
Yaowu Xuf883b422016-08-30 14:01:10 -07001456static aom_codec_err_t ctrl_set_color_range(aom_codec_alg_priv_t *ctx,
Yaowu Xuc27fc142016-08-22 16:08:15 -07001457 va_list args) {
Yaowu Xuf883b422016-08-30 14:01:10 -07001458 struct av1_extracfg extra_cfg = ctx->extra_cfg;
1459 extra_cfg.color_range = CAST(AV1E_SET_COLOR_RANGE, args);
Yaowu Xuc27fc142016-08-22 16:08:15 -07001460 return update_extra_cfg(ctx, &extra_cfg);
1461}
1462
Yaowu Xuf883b422016-08-30 14:01:10 -07001463static aom_codec_err_t ctrl_set_render_size(aom_codec_alg_priv_t *ctx,
Yaowu Xuc27fc142016-08-22 16:08:15 -07001464 va_list args) {
Yaowu Xuf883b422016-08-30 14:01:10 -07001465 struct av1_extracfg extra_cfg = ctx->extra_cfg;
Yaowu Xuc27fc142016-08-22 16:08:15 -07001466 int *const render_size = va_arg(args, int *);
1467 extra_cfg.render_width = render_size[0];
1468 extra_cfg.render_height = render_size[1];
1469 return update_extra_cfg(ctx, &extra_cfg);
1470}
1471
Yaowu Xuf883b422016-08-30 14:01:10 -07001472static aom_codec_err_t ctrl_set_superblock_size(aom_codec_alg_priv_t *ctx,
Yaowu Xuc27fc142016-08-22 16:08:15 -07001473 va_list args) {
Yaowu Xuf883b422016-08-30 14:01:10 -07001474 struct av1_extracfg extra_cfg = ctx->extra_cfg;
1475 extra_cfg.superblock_size = CAST(AV1E_SET_SUPERBLOCK_SIZE, args);
Yaowu Xuc27fc142016-08-22 16:08:15 -07001476 return update_extra_cfg(ctx, &extra_cfg);
1477}
1478
Alex Converseeb780e72016-12-13 12:46:41 -08001479#if CONFIG_ANS && ANS_MAX_SYMBOLS
1480static aom_codec_err_t ctrl_set_ans_window_size_log2(aom_codec_alg_priv_t *ctx,
1481 va_list args) {
1482 struct av1_extracfg extra_cfg = ctx->extra_cfg;
1483 extra_cfg.ans_window_size_log2 = CAST(AV1E_SET_ANS_WINDOW_SIZE_LOG2, args);
1484 return update_extra_cfg(ctx, &extra_cfg);
1485}
1486#endif
1487
Yaowu Xuf883b422016-08-30 14:01:10 -07001488static aom_codec_ctrl_fn_map_t encoder_ctrl_maps[] = {
1489 { AOM_COPY_REFERENCE, ctrl_copy_reference },
1490 { AOME_USE_REFERENCE, ctrl_use_reference },
Yaowu Xuc27fc142016-08-22 16:08:15 -07001491
1492 // Setters
Yaowu Xuf883b422016-08-30 14:01:10 -07001493 { AOM_SET_REFERENCE, ctrl_set_reference },
1494 { AOM_SET_POSTPROC, ctrl_set_previewpp },
1495 { AOME_SET_ROI_MAP, ctrl_set_roi_map },
1496 { AOME_SET_ACTIVEMAP, ctrl_set_active_map },
1497 { AOME_SET_SCALEMODE, ctrl_set_scale_mode },
1498 { AOME_SET_CPUUSED, ctrl_set_cpuused },
1499 { AOME_SET_ENABLEAUTOALTREF, ctrl_set_enable_auto_alt_ref },
Yaowu Xuc27fc142016-08-22 16:08:15 -07001500#if CONFIG_EXT_REFS
Yaowu Xuf883b422016-08-30 14:01:10 -07001501 { AOME_SET_ENABLEAUTOBWDREF, ctrl_set_enable_auto_bwd_ref },
Yaowu Xuc27fc142016-08-22 16:08:15 -07001502#endif // CONFIG_EXT_REFS
Yaowu Xuf883b422016-08-30 14:01:10 -07001503 { AOME_SET_SHARPNESS, ctrl_set_sharpness },
1504 { AOME_SET_STATIC_THRESHOLD, ctrl_set_static_thresh },
1505 { AV1E_SET_TILE_COLUMNS, ctrl_set_tile_columns },
1506 { AV1E_SET_TILE_ROWS, ctrl_set_tile_rows },
Fangwen Fu7b9f2b32017-01-17 14:01:52 -08001507#if CONFIG_DEPENDENT_HORZTILES
1508 { AV1E_SET_TILE_DEPENDENT_ROWS, ctrl_set_tile_dependent_rows },
1509#endif
Ryan Lei9b02b0e2017-01-30 15:52:20 -08001510#if CONFIG_LOOPFILTERING_ACROSS_TILES
Ryan Lei7386eda2016-12-08 21:08:31 -08001511 { AV1E_SET_TILE_LOOPFILTER, ctrl_set_tile_loopfilter },
Ryan Lei9b02b0e2017-01-30 15:52:20 -08001512#endif // CONFIG_LOOPFILTERING_ACROSS_TILES
Yaowu Xuf883b422016-08-30 14:01:10 -07001513 { AOME_SET_ARNR_MAXFRAMES, ctrl_set_arnr_max_frames },
1514 { AOME_SET_ARNR_STRENGTH, ctrl_set_arnr_strength },
Yaowu Xuf883b422016-08-30 14:01:10 -07001515 { AOME_SET_TUNING, ctrl_set_tuning },
1516 { AOME_SET_CQ_LEVEL, ctrl_set_cq_level },
1517 { AOME_SET_MAX_INTRA_BITRATE_PCT, ctrl_set_rc_max_intra_bitrate_pct },
1518 { AV1E_SET_MAX_INTER_BITRATE_PCT, ctrl_set_rc_max_inter_bitrate_pct },
1519 { AV1E_SET_GF_CBR_BOOST_PCT, ctrl_set_rc_gf_cbr_boost_pct },
1520 { AV1E_SET_LOSSLESS, ctrl_set_lossless },
Yaowu Xuc27fc142016-08-22 16:08:15 -07001521#if CONFIG_AOM_QM
Yaowu Xuf883b422016-08-30 14:01:10 -07001522 { AV1E_SET_ENABLE_QM, ctrl_set_enable_qm },
1523 { AV1E_SET_QM_MIN, ctrl_set_qm_min },
1524 { AV1E_SET_QM_MAX, ctrl_set_qm_max },
Yaowu Xuc27fc142016-08-22 16:08:15 -07001525#endif
Thomas Daviesaf6df172016-11-09 14:04:18 +00001526#if CONFIG_TILE_GROUPS
1527 { AV1E_SET_NUM_TG, ctrl_set_num_tg },
1528 { AV1E_SET_MTU, ctrl_set_mtu },
1529#endif
Fangwen Fu8d164de2016-12-14 13:40:54 -08001530#if CONFIG_TEMPMV_SIGNALING
1531 { AV1E_SET_DISABLE_TEMPMV, ctrl_set_disable_tempmv },
1532#endif
Yaowu Xuf883b422016-08-30 14:01:10 -07001533 { AV1E_SET_FRAME_PARALLEL_DECODING, ctrl_set_frame_parallel_decoding_mode },
1534 { AV1E_SET_AQ_MODE, ctrl_set_aq_mode },
Fangwen Fu6160df22017-04-24 09:45:51 -07001535#if CONFIG_EXT_DELTA_Q
1536 { AV1E_SET_DELTAQ_MODE, ctrl_set_deltaq_mode },
1537#endif
Yaowu Xuf883b422016-08-30 14:01:10 -07001538 { AV1E_SET_FRAME_PERIODIC_BOOST, ctrl_set_frame_periodic_boost },
1539 { AV1E_SET_TUNE_CONTENT, ctrl_set_tune_content },
1540 { AV1E_SET_COLOR_SPACE, ctrl_set_color_space },
anorkin76fb1262017-03-22 15:12:12 -07001541#if CONFIG_COLORSPACE_HEADERS
1542 { AV1E_SET_TRANSFER_FUNCTION, ctrl_set_transfer_function },
1543 { AV1E_SET_CHROMA_SAMPLE_POSITION, ctrl_set_chroma_sample_position },
1544#endif
Yaowu Xuf883b422016-08-30 14:01:10 -07001545 { AV1E_SET_COLOR_RANGE, ctrl_set_color_range },
1546 { AV1E_SET_NOISE_SENSITIVITY, ctrl_set_noise_sensitivity },
1547 { AV1E_SET_MIN_GF_INTERVAL, ctrl_set_min_gf_interval },
1548 { AV1E_SET_MAX_GF_INTERVAL, ctrl_set_max_gf_interval },
1549 { AV1E_SET_RENDER_SIZE, ctrl_set_render_size },
1550 { AV1E_SET_SUPERBLOCK_SIZE, ctrl_set_superblock_size },
Alex Converseeb780e72016-12-13 12:46:41 -08001551#if CONFIG_ANS && ANS_MAX_SYMBOLS
1552 { AV1E_SET_ANS_WINDOW_SIZE_LOG2, ctrl_set_ans_window_size_log2 },
1553#endif
Yunqing Wangd8cd55f2017-02-27 12:16:00 -08001554#if CONFIG_EXT_TILE
1555 { AV1E_SET_TILE_ENCODING_MODE, ctrl_set_tile_encoding_mode },
1556#endif // CONFIG_EXT_TILE
Yunqing Wangff4fa062017-04-21 10:56:08 -07001557 { AV1E_ENABLE_MOTION_VECTOR_UNIT_TEST, ctrl_enable_motion_vector_unit_test },
Yaowu Xuc27fc142016-08-22 16:08:15 -07001558
1559 // Getters
Yaowu Xuf883b422016-08-30 14:01:10 -07001560 { AOME_GET_LAST_QUANTIZER, ctrl_get_quantizer },
1561 { AOME_GET_LAST_QUANTIZER_64, ctrl_get_quantizer64 },
1562 { AV1_GET_REFERENCE, ctrl_get_reference },
1563 { AV1E_GET_ACTIVEMAP, ctrl_get_active_map },
1564 { AV1_GET_NEW_FRAME_IMAGE, ctrl_get_new_frame_image },
Yaowu Xuc27fc142016-08-22 16:08:15 -07001565
1566 { -1, NULL },
1567};
1568
Yaowu Xuf883b422016-08-30 14:01:10 -07001569static aom_codec_enc_cfg_map_t encoder_usage_cfg_map[] = {
Yaowu Xuc27fc142016-08-22 16:08:15 -07001570 { 0,
1571 {
1572 // NOLINT
1573 0, // g_usage
1574 8, // g_threads
1575 0, // g_profile
1576
1577 320, // g_width
1578 240, // g_height
Yaowu Xuf883b422016-08-30 14:01:10 -07001579 AOM_BITS_8, // g_bit_depth
Yaowu Xuc27fc142016-08-22 16:08:15 -07001580 8, // g_input_bit_depth
1581
1582 { 1, 30 }, // g_timebase
1583
1584 0, // g_error_resilient
1585
Yaowu Xuf883b422016-08-30 14:01:10 -07001586 AOM_RC_ONE_PASS, // g_pass
Yaowu Xuc27fc142016-08-22 16:08:15 -07001587
1588 25, // g_lag_in_frames
1589
Fergus Simpsonbfbf6a52017-06-14 23:13:12 -07001590 0, // rc_dropframe_thresh
1591 RESIZE_NONE, // rc_resize_mode
1592 SCALE_DENOMINATOR, // rc_resize_numerator
Fergus Simpson87cf61b2017-06-15 00:50:34 -07001593 SCALE_DENOMINATOR, // rc_resize_kf_numerator
Yaowu Xuc27fc142016-08-22 16:08:15 -07001594
Fergus Simpsonbfbf6a52017-06-14 23:13:12 -07001595 0, // rc_superres_mode
1596 SCALE_DENOMINATOR, // rc_superres_numerator
Fergus Simpson87cf61b2017-06-15 00:50:34 -07001597 SCALE_DENOMINATOR, // rc_superres_kf_numerator
Fergus Simpsonc4e78942017-04-10 14:59:00 -07001598
Yaowu Xuf883b422016-08-30 14:01:10 -07001599 AOM_VBR, // rc_end_usage
Yaowu Xuc27fc142016-08-22 16:08:15 -07001600 { NULL, 0 }, // rc_twopass_stats_in
1601 { NULL, 0 }, // rc_firstpass_mb_stats_in
1602 256, // rc_target_bandwidth
1603 0, // rc_min_quantizer
1604 63, // rc_max_quantizer
1605 25, // rc_undershoot_pct
1606 25, // rc_overshoot_pct
1607
1608 6000, // rc_max_buffer_size
1609 4000, // rc_buffer_initial_size
1610 5000, // rc_buffer_optimal_size
1611
1612 50, // rc_two_pass_vbrbias
1613 0, // rc_two_pass_vbrmin_section
1614 2000, // rc_two_pass_vbrmax_section
1615
1616 // keyframing settings (kf)
Yaowu Xuf883b422016-08-30 14:01:10 -07001617 AOM_KF_AUTO, // g_kfmode
Yaowu Xuc27fc142016-08-22 16:08:15 -07001618 0, // kf_min_dist
1619 9999, // kf_max_dist
1620 } },
1621};
1622
1623#ifndef VERSION_STRING
1624#define VERSION_STRING
1625#endif
Yaowu Xuf883b422016-08-30 14:01:10 -07001626CODEC_INTERFACE(aom_codec_av1_cx) = {
1627 "AOMedia Project AV1 Encoder" VERSION_STRING,
1628 AOM_CODEC_INTERNAL_ABI_VERSION,
Sebastien Alaiwan71e87842017-04-12 16:03:28 +02001629#if CONFIG_HIGHBITDEPTH
Yaowu Xuf883b422016-08-30 14:01:10 -07001630 AOM_CODEC_CAP_HIGHBITDEPTH |
Yaowu Xuc27fc142016-08-22 16:08:15 -07001631#endif
Yaowu Xuf883b422016-08-30 14:01:10 -07001632 AOM_CODEC_CAP_ENCODER | AOM_CODEC_CAP_PSNR, // aom_codec_caps_t
1633 encoder_init, // aom_codec_init_fn_t
1634 encoder_destroy, // aom_codec_destroy_fn_t
1635 encoder_ctrl_maps, // aom_codec_ctrl_fn_map_t
Yaowu Xuc27fc142016-08-22 16:08:15 -07001636 {
1637 // NOLINT
Yaowu Xuf883b422016-08-30 14:01:10 -07001638 NULL, // aom_codec_peek_si_fn_t
1639 NULL, // aom_codec_get_si_fn_t
1640 NULL, // aom_codec_decode_fn_t
1641 NULL, // aom_codec_frame_get_fn_t
1642 NULL // aom_codec_set_fb_fn_t
Yaowu Xuc27fc142016-08-22 16:08:15 -07001643 },
1644 {
1645 // NOLINT
1646 1, // 1 cfg map
Yaowu Xuf883b422016-08-30 14:01:10 -07001647 encoder_usage_cfg_map, // aom_codec_enc_cfg_map_t
1648 encoder_encode, // aom_codec_encode_fn_t
1649 encoder_get_cxdata, // aom_codec_get_cx_data_fn_t
1650 encoder_set_config, // aom_codec_enc_config_set_fn_t
1651 NULL, // aom_codec_get_global_headers_fn_t
1652 encoder_get_preview, // aom_codec_get_preview_frame_fn_t
1653 NULL // aom_codec_enc_mr_get_mem_loc_fn_t
Yaowu Xuc27fc142016-08-22 16:08:15 -07001654 }
1655};