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/aom_encoder.h" |
| 17 | #include "aom_ports/aom_once.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 18 | #include "aom_ports/system_state.h" |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 19 | #include "aom/internal/aom_codec_internal.h" |
| 20 | #include "./aom_version.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 21 | #include "av1/encoder/encoder.h" |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 22 | #include "aom/aomcx.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 23 | #include "av1/encoder/firstpass.h" |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 24 | #include "av1/av1_iface_common.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 25 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 26 | struct av1_extracfg { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 27 | 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 Fu | 7b9f2b3 | 2017-01-17 14:01:52 -0800 | [diff] [blame] | 37 | #if CONFIG_DEPENDENT_HORZTILES |
| 38 | unsigned int dependent_horz_tiles; |
| 39 | #endif |
Ryan Lei | 9b02b0e | 2017-01-30 15:52:20 -0800 | [diff] [blame] | 40 | #if CONFIG_LOOPFILTERING_ACROSS_TILES |
Ryan Lei | 7386eda | 2016-12-08 21:08:31 -0800 | [diff] [blame] | 41 | unsigned int loop_filter_across_tiles_enabled; |
Ryan Lei | 9b02b0e | 2017-01-30 15:52:20 -0800 | [diff] [blame] | 42 | #endif // CONFIG_LOOPFILTERING_ACROSS_TILES |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 43 | unsigned int arnr_max_frames; |
| 44 | unsigned int arnr_strength; |
| 45 | unsigned int min_gf_interval; |
| 46 | unsigned int max_gf_interval; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 47 | aom_tune_metric tuning; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 48 | 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 Davies | af6df17 | 2016-11-09 14:04:18 +0000 | [diff] [blame] | 58 | #if CONFIG_TILE_GROUPS |
| 59 | unsigned int num_tg; |
| 60 | unsigned int mtu_size; |
| 61 | #endif |
Fangwen Fu | 8d164de | 2016-12-14 13:40:54 -0800 | [diff] [blame] | 62 | #if CONFIG_TEMPMV_SIGNALING |
| 63 | unsigned int disable_tempmv; |
| 64 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 65 | unsigned int frame_parallel_decoding_mode; |
| 66 | AQ_MODE aq_mode; |
Fangwen Fu | 6160df2 | 2017-04-24 09:45:51 -0700 | [diff] [blame] | 67 | #if CONFIG_EXT_DELTA_Q |
| 68 | DELTAQ_MODE deltaq_mode; |
| 69 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 70 | unsigned int frame_periodic_boost; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 71 | aom_bit_depth_t bit_depth; |
| 72 | aom_tune_content content; |
| 73 | aom_color_space_t color_space; |
anorkin | 76fb126 | 2017-03-22 15:12:12 -0700 | [diff] [blame^] | 74 | #if CONFIG_COLORSPACE_HEADERS |
| 75 | aom_transfer_function_t transfer_function; |
| 76 | aom_chroma_sample_position_t chroma_sample_position; |
| 77 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 78 | int color_range; |
| 79 | int render_width; |
| 80 | int render_height; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 81 | aom_superblock_size_t superblock_size; |
Alex Converse | eb780e7 | 2016-12-13 12:46:41 -0800 | [diff] [blame] | 82 | #if CONFIG_ANS && ANS_MAX_SYMBOLS |
| 83 | int ans_window_size_log2; |
| 84 | #endif |
Yunqing Wang | d8cd55f | 2017-02-27 12:16:00 -0800 | [diff] [blame] | 85 | #if CONFIG_EXT_TILE |
| 86 | unsigned int tile_encoding_mode; |
| 87 | #endif // CONFIG_EXT_TILE |
Yunqing Wang | ff4fa06 | 2017-04-21 10:56:08 -0700 | [diff] [blame] | 88 | |
| 89 | unsigned int motion_vector_unit_test; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 90 | }; |
| 91 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 92 | static struct av1_extracfg default_extra_cfg = { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 93 | 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 Lei | 7386eda | 2016-12-08 21:08:31 -0800 | [diff] [blame] | 107 | #endif // CONFIG_EXT_TILE |
Fangwen Fu | 7b9f2b3 | 2017-01-17 14:01:52 -0800 | [diff] [blame] | 108 | #if CONFIG_DEPENDENT_HORZTILES |
anorkin | 76fb126 | 2017-03-22 15:12:12 -0700 | [diff] [blame^] | 109 | 0, // Dependent Horizontal tiles |
Fangwen Fu | 7b9f2b3 | 2017-01-17 14:01:52 -0800 | [diff] [blame] | 110 | #endif |
Ryan Lei | 9b02b0e | 2017-01-30 15:52:20 -0800 | [diff] [blame] | 111 | #if CONFIG_LOOPFILTERING_ACROSS_TILES |
Ryan Lei | ad67d79 | 2017-02-02 17:53:19 -0800 | [diff] [blame] | 112 | 1, // loop_filter_across_tiles_enabled |
Ryan Lei | 9b02b0e | 2017-01-30 15:52:20 -0800 | [diff] [blame] | 113 | #endif // CONFIG_LOOPFILTERING_ACROSS_TILES |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 114 | 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 Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 118 | AOM_TUNE_PSNR, // tuning |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 119 | 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 Davies | af6df17 | 2016-11-09 14:04:18 +0000 | [diff] [blame] | 129 | #if CONFIG_TILE_GROUPS |
| 130 | 1, // max number of tile groups |
| 131 | 0, // mtu_size |
| 132 | #endif |
Fangwen Fu | 8d164de | 2016-12-14 13:40:54 -0800 | [diff] [blame] | 133 | #if CONFIG_TEMPMV_SIGNALING |
| 134 | 0, // disable temporal mv prediction |
| 135 | #endif |
Fangwen Fu | 6160df2 | 2017-04-24 09:45:51 -0700 | [diff] [blame] | 136 | 1, // frame_parallel_decoding_mode |
| 137 | NO_AQ, // aq_mode |
| 138 | #if CONFIG_EXT_DELTA_Q |
| 139 | NO_DELTA_Q, // deltaq_mode |
| 140 | #endif |
anorkin | 76fb126 | 2017-03-22 15:12:12 -0700 | [diff] [blame^] | 141 | 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 Converse | eb780e7 | 2016-12-13 12:46:41 -0800 | [diff] [blame] | 149 | 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 Wang | d8cd55f | 2017-02-27 12:16:00 -0800 | [diff] [blame] | 156 | #if CONFIG_EXT_TILE |
| 157 | 0, // Tile encoding mode is TILE_NORMAL by default. |
| 158 | #endif // CONFIG_EXT_TILE |
Yunqing Wang | ff4fa06 | 2017-04-21 10:56:08 -0700 | [diff] [blame] | 159 | |
| 160 | 0, // motion_vector_unit_test |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 161 | }; |
| 162 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 163 | struct 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 Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 169 | 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 Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 175 | 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 Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 179 | unsigned int fixed_kf_cntr; |
| 180 | // BufferPool that holds all reference frames. |
| 181 | BufferPool *buffer_pool; |
| 182 | }; |
| 183 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 184 | static 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 Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 187 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 188 | if (res != AOM_CODEC_OK) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 189 | 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 Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 198 | return AOM_CODEC_INVALID_PARAM; \ |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 199 | } while (0) |
| 200 | |
Urvang Joshi | cd8ab90 | 2016-10-28 12:32:06 -0700 | [diff] [blame] | 201 | #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 Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 205 | } 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 Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 222 | static 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 Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 225 | 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 Fu | 6160df2 | 2017-04-24 09:45:51 -0700 | [diff] [blame] | 235 | #if CONFIG_EXT_DELTA_Q |
| 236 | RANGE_CHECK(extra_cfg, deltaq_mode, 0, DELTAQ_MODE_COUNT - 1); |
| 237 | #endif |
Urvang Joshi | cd8ab90 | 2016-10-28 12:32:06 -0700 | [diff] [blame] | 238 | RANGE_CHECK_HI(extra_cfg, frame_periodic_boost, 1); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 239 | RANGE_CHECK_HI(cfg, g_threads, 64); |
| 240 | RANGE_CHECK_HI(cfg, g_lag_in_frames, MAX_LAG_BUFFERS); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 241 | RANGE_CHECK(cfg, rc_end_usage, AOM_VBR, AOM_Q); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 242 | 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 Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 245 | RANGE_CHECK(cfg, kf_mode, AOM_KF_DISABLED, AOM_KF_AUTO); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 246 | RANGE_CHECK_BOOL(cfg, rc_resize_allowed); |
| 247 | RANGE_CHECK_HI(cfg, rc_dropframe_thresh, 100); |
| 248 | RANGE_CHECK_HI(cfg, rc_resize_up_thresh, 100); |
| 249 | RANGE_CHECK_HI(cfg, rc_resize_down_thresh, 100); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 250 | RANGE_CHECK(cfg, g_pass, AOM_RC_ONE_PASS, AOM_RC_LAST_PASS); |
Urvang Joshi | cd8ab90 | 2016-10-28 12:32:06 -0700 | [diff] [blame] | 251 | RANGE_CHECK_HI(extra_cfg, min_gf_interval, MAX_LAG_BUFFERS - 1); |
| 252 | RANGE_CHECK_HI(extra_cfg, max_gf_interval, MAX_LAG_BUFFERS - 1); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 253 | if (extra_cfg->max_gf_interval > 0) { |
| 254 | RANGE_CHECK(extra_cfg, max_gf_interval, 2, (MAX_LAG_BUFFERS - 1)); |
| 255 | } |
| 256 | if (extra_cfg->min_gf_interval > 0 && extra_cfg->max_gf_interval > 0) { |
| 257 | RANGE_CHECK(extra_cfg, max_gf_interval, extra_cfg->min_gf_interval, |
| 258 | (MAX_LAG_BUFFERS - 1)); |
| 259 | } |
| 260 | |
| 261 | if (cfg->rc_resize_allowed == 1) { |
Urvang Joshi | cd8ab90 | 2016-10-28 12:32:06 -0700 | [diff] [blame] | 262 | RANGE_CHECK_HI(cfg, rc_scaled_width, cfg->g_w); |
| 263 | RANGE_CHECK_HI(cfg, rc_scaled_height, cfg->g_h); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 264 | } |
| 265 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 266 | // AV1 does not support a lower bound on the keyframe interval in |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 267 | // automatic keyframe placement mode. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 268 | if (cfg->kf_mode != AOM_KF_DISABLED && cfg->kf_min_dist != cfg->kf_max_dist && |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 269 | cfg->kf_min_dist > 0) |
| 270 | ERROR( |
| 271 | "kf_min_dist not supported in auto mode, use 0 " |
| 272 | "or kf_max_dist instead."); |
| 273 | |
Yunqing Wang | ff4fa06 | 2017-04-21 10:56:08 -0700 | [diff] [blame] | 274 | RANGE_CHECK_HI(extra_cfg, motion_vector_unit_test, 2); |
Urvang Joshi | cd8ab90 | 2016-10-28 12:32:06 -0700 | [diff] [blame] | 275 | RANGE_CHECK_HI(extra_cfg, enable_auto_alt_ref, 2); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 276 | #if CONFIG_EXT_REFS |
Urvang Joshi | cd8ab90 | 2016-10-28 12:32:06 -0700 | [diff] [blame] | 277 | RANGE_CHECK_HI(extra_cfg, enable_auto_bwd_ref, 2); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 278 | #endif // CONFIG_EXT_REFS |
Alex Converse | 561d0af | 2017-03-23 12:58:04 -0700 | [diff] [blame] | 279 | RANGE_CHECK(extra_cfg, cpu_used, 0, 8); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 280 | RANGE_CHECK_HI(extra_cfg, noise_sensitivity, 6); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 281 | RANGE_CHECK(extra_cfg, superblock_size, AOM_SUPERBLOCK_SIZE_64X64, |
| 282 | AOM_SUPERBLOCK_SIZE_DYNAMIC); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 283 | #if CONFIG_EXT_TILE |
| 284 | // TODO(any): Waring. If CONFIG_EXT_TILE is true, tile_columns really |
| 285 | // means tile_width, and tile_rows really means tile_hight. The interface |
| 286 | // should be sanitized. |
| 287 | #if CONFIG_EXT_PARTITION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 288 | if (extra_cfg->superblock_size != AOM_SUPERBLOCK_SIZE_64X64) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 289 | if (extra_cfg->tile_columns != UINT_MAX) |
| 290 | RANGE_CHECK(extra_cfg, tile_columns, 1, 32); |
| 291 | if (extra_cfg->tile_rows != UINT_MAX) |
| 292 | RANGE_CHECK(extra_cfg, tile_rows, 1, 32); |
| 293 | } else |
| 294 | #endif // CONFIG_EXT_PARTITION |
| 295 | { |
| 296 | if (extra_cfg->tile_columns != UINT_MAX) |
| 297 | RANGE_CHECK(extra_cfg, tile_columns, 1, 64); |
| 298 | if (extra_cfg->tile_rows != UINT_MAX) |
| 299 | RANGE_CHECK(extra_cfg, tile_rows, 1, 64); |
| 300 | } |
Yunqing Wang | d8cd55f | 2017-02-27 12:16:00 -0800 | [diff] [blame] | 301 | RANGE_CHECK_HI(extra_cfg, tile_encoding_mode, 1); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 302 | #else |
Urvang Joshi | cd8ab90 | 2016-10-28 12:32:06 -0700 | [diff] [blame] | 303 | RANGE_CHECK_HI(extra_cfg, tile_columns, 6); |
| 304 | RANGE_CHECK_HI(extra_cfg, tile_rows, 2); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 305 | #endif // CONFIG_EXT_TILE |
Fangwen Fu | 7b9f2b3 | 2017-01-17 14:01:52 -0800 | [diff] [blame] | 306 | #if CONFIG_DEPENDENT_HORZTILES |
| 307 | RANGE_CHECK_HI(extra_cfg, dependent_horz_tiles, 1); |
| 308 | #endif |
Ryan Lei | 9b02b0e | 2017-01-30 15:52:20 -0800 | [diff] [blame] | 309 | #if CONFIG_LOOPFILTERING_ACROSS_TILES |
Ryan Lei | 7386eda | 2016-12-08 21:08:31 -0800 | [diff] [blame] | 310 | RANGE_CHECK_HI(extra_cfg, loop_filter_across_tiles_enabled, 1); |
Ryan Lei | 9b02b0e | 2017-01-30 15:52:20 -0800 | [diff] [blame] | 311 | #endif // CONFIG_LOOPFILTERING_ACROSS_TILES |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 312 | RANGE_CHECK_HI(extra_cfg, sharpness, 7); |
Urvang Joshi | cd8ab90 | 2016-10-28 12:32:06 -0700 | [diff] [blame] | 313 | RANGE_CHECK_HI(extra_cfg, arnr_max_frames, 15); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 314 | RANGE_CHECK_HI(extra_cfg, arnr_strength, 6); |
Urvang Joshi | cd8ab90 | 2016-10-28 12:32:06 -0700 | [diff] [blame] | 315 | RANGE_CHECK_HI(extra_cfg, cq_level, 63); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 316 | RANGE_CHECK(cfg, g_bit_depth, AOM_BITS_8, AOM_BITS_12); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 317 | RANGE_CHECK(cfg, g_input_bit_depth, 8, 12); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 318 | RANGE_CHECK(extra_cfg, content, AOM_CONTENT_DEFAULT, AOM_CONTENT_INVALID - 1); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 319 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 320 | // TODO(yaowu): remove this when ssim tuning is implemented for av1 |
| 321 | if (extra_cfg->tuning == AOM_TUNE_SSIM) |
| 322 | ERROR("Option --tune=ssim is not currently supported in AV1."); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 323 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 324 | if (cfg->g_pass == AOM_RC_LAST_PASS) { |
Rostislav Pehlivanov | 74021a5 | 2017-03-09 09:05:29 +0000 | [diff] [blame] | 325 | #if !CONFIG_XIPHRC |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 326 | const size_t packet_sz = sizeof(FIRSTPASS_STATS); |
| 327 | const int n_packets = (int)(cfg->rc_twopass_stats_in.sz / packet_sz); |
| 328 | const FIRSTPASS_STATS *stats; |
Rostislav Pehlivanov | 74021a5 | 2017-03-09 09:05:29 +0000 | [diff] [blame] | 329 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 330 | |
| 331 | if (cfg->rc_twopass_stats_in.buf == NULL) |
| 332 | ERROR("rc_twopass_stats_in.buf not set."); |
| 333 | |
Rostislav Pehlivanov | 74021a5 | 2017-03-09 09:05:29 +0000 | [diff] [blame] | 334 | #if !CONFIG_XIPHRC |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 335 | if (cfg->rc_twopass_stats_in.sz % packet_sz) |
| 336 | ERROR("rc_twopass_stats_in.sz indicates truncated packet."); |
| 337 | |
| 338 | if (cfg->rc_twopass_stats_in.sz < 2 * packet_sz) |
| 339 | ERROR("rc_twopass_stats_in requires at least two packets."); |
| 340 | |
| 341 | stats = |
| 342 | (const FIRSTPASS_STATS *)cfg->rc_twopass_stats_in.buf + n_packets - 1; |
| 343 | |
| 344 | if ((int)(stats->count + 0.5) != n_packets - 1) |
| 345 | ERROR("rc_twopass_stats_in missing EOS stats packet"); |
Rostislav Pehlivanov | 74021a5 | 2017-03-09 09:05:29 +0000 | [diff] [blame] | 346 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 347 | } |
| 348 | |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 349 | #if !CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 350 | if (cfg->g_profile > (unsigned int)PROFILE_1) { |
| 351 | ERROR("Profile > 1 not supported in this build configuration"); |
| 352 | } |
| 353 | #endif |
| 354 | if (cfg->g_profile <= (unsigned int)PROFILE_1 && |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 355 | cfg->g_bit_depth > AOM_BITS_8) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 356 | ERROR("Codec high bit-depth not supported in profile < 2"); |
| 357 | } |
| 358 | if (cfg->g_profile <= (unsigned int)PROFILE_1 && cfg->g_input_bit_depth > 8) { |
| 359 | ERROR("Source high bit-depth not supported in profile < 2"); |
| 360 | } |
| 361 | if (cfg->g_profile > (unsigned int)PROFILE_1 && |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 362 | cfg->g_bit_depth == AOM_BITS_8) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 363 | ERROR("Codec bit-depth 8 not supported in profile > 1"); |
| 364 | } |
anorkin | 76fb126 | 2017-03-22 15:12:12 -0700 | [diff] [blame^] | 365 | #if CONFIG_COLORSPACE_HEADERS |
| 366 | RANGE_CHECK(extra_cfg, color_space, AOM_CS_UNKNOWN, AOM_CS_ICTCP); |
| 367 | RANGE_CHECK(extra_cfg, transfer_function, AOM_TF_UNKNOWN, AOM_TF_HLG); |
| 368 | RANGE_CHECK(extra_cfg, chroma_sample_position, AOM_CSP_UNKNOWN, |
| 369 | AOM_CSP_COLOCATED); |
| 370 | #else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 371 | RANGE_CHECK(extra_cfg, color_space, AOM_CS_UNKNOWN, AOM_CS_SRGB); |
anorkin | 76fb126 | 2017-03-22 15:12:12 -0700 | [diff] [blame^] | 372 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 373 | RANGE_CHECK(extra_cfg, color_range, 0, 1); |
Alex Converse | eb780e7 | 2016-12-13 12:46:41 -0800 | [diff] [blame] | 374 | #if CONFIG_ANS && ANS_MAX_SYMBOLS |
| 375 | RANGE_CHECK(extra_cfg, ans_window_size_log2, 8, 23); |
| 376 | #endif |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 377 | return AOM_CODEC_OK; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 378 | } |
| 379 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 380 | static aom_codec_err_t validate_img(aom_codec_alg_priv_t *ctx, |
| 381 | const aom_image_t *img) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 382 | switch (img->fmt) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 383 | case AOM_IMG_FMT_YV12: |
| 384 | case AOM_IMG_FMT_I420: |
| 385 | case AOM_IMG_FMT_I42016: break; |
| 386 | case AOM_IMG_FMT_I422: |
| 387 | case AOM_IMG_FMT_I444: |
| 388 | case AOM_IMG_FMT_I440: |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 389 | if (ctx->cfg.g_profile != (unsigned int)PROFILE_1) { |
| 390 | ERROR( |
| 391 | "Invalid image format. I422, I444, I440 images are " |
| 392 | "not supported in profile."); |
| 393 | } |
| 394 | break; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 395 | case AOM_IMG_FMT_I42216: |
| 396 | case AOM_IMG_FMT_I44416: |
| 397 | case AOM_IMG_FMT_I44016: |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 398 | if (ctx->cfg.g_profile != (unsigned int)PROFILE_1 && |
| 399 | ctx->cfg.g_profile != (unsigned int)PROFILE_3) { |
| 400 | ERROR( |
| 401 | "Invalid image format. 16-bit I422, I444, I440 images are " |
| 402 | "not supported in profile."); |
| 403 | } |
| 404 | break; |
| 405 | default: |
| 406 | ERROR( |
| 407 | "Invalid image format. Only YV12, I420, I422, I444 images are " |
| 408 | "supported."); |
| 409 | break; |
| 410 | } |
| 411 | |
| 412 | if (img->d_w != ctx->cfg.g_w || img->d_h != ctx->cfg.g_h) |
| 413 | ERROR("Image size must match encoder init configuration size"); |
| 414 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 415 | return AOM_CODEC_OK; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 416 | } |
| 417 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 418 | static int get_image_bps(const aom_image_t *img) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 419 | switch (img->fmt) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 420 | case AOM_IMG_FMT_YV12: |
| 421 | case AOM_IMG_FMT_I420: return 12; |
| 422 | case AOM_IMG_FMT_I422: return 16; |
| 423 | case AOM_IMG_FMT_I444: return 24; |
| 424 | case AOM_IMG_FMT_I440: return 16; |
| 425 | case AOM_IMG_FMT_I42016: return 24; |
| 426 | case AOM_IMG_FMT_I42216: return 32; |
| 427 | case AOM_IMG_FMT_I44416: return 48; |
| 428 | case AOM_IMG_FMT_I44016: return 32; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 429 | default: assert(0 && "Invalid image format"); break; |
| 430 | } |
| 431 | return 0; |
| 432 | } |
| 433 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 434 | static aom_codec_err_t set_encoder_config( |
| 435 | AV1EncoderConfig *oxcf, const aom_codec_enc_cfg_t *cfg, |
| 436 | const struct av1_extracfg *extra_cfg) { |
| 437 | const int is_vbr = cfg->rc_end_usage == AOM_VBR; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 438 | oxcf->profile = cfg->g_profile; |
| 439 | oxcf->max_threads = (int)cfg->g_threads; |
| 440 | oxcf->width = cfg->g_w; |
| 441 | oxcf->height = cfg->g_h; |
| 442 | oxcf->bit_depth = cfg->g_bit_depth; |
| 443 | oxcf->input_bit_depth = cfg->g_input_bit_depth; |
| 444 | // guess a frame rate if out of whack, use 30 |
| 445 | oxcf->init_framerate = (double)cfg->g_timebase.den / cfg->g_timebase.num; |
| 446 | if (oxcf->init_framerate > 180) oxcf->init_framerate = 30; |
| 447 | |
| 448 | oxcf->mode = GOOD; |
| 449 | |
| 450 | switch (cfg->g_pass) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 451 | case AOM_RC_ONE_PASS: oxcf->pass = 0; break; |
| 452 | case AOM_RC_FIRST_PASS: oxcf->pass = 1; break; |
| 453 | case AOM_RC_LAST_PASS: oxcf->pass = 2; break; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 454 | } |
| 455 | |
| 456 | oxcf->lag_in_frames = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 457 | cfg->g_pass == AOM_RC_FIRST_PASS ? 0 : cfg->g_lag_in_frames; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 458 | oxcf->rc_mode = cfg->rc_end_usage; |
| 459 | |
| 460 | // Convert target bandwidth from Kbit/s to Bit/s |
| 461 | oxcf->target_bandwidth = 1000 * cfg->rc_target_bitrate; |
| 462 | oxcf->rc_max_intra_bitrate_pct = extra_cfg->rc_max_intra_bitrate_pct; |
| 463 | oxcf->rc_max_inter_bitrate_pct = extra_cfg->rc_max_inter_bitrate_pct; |
| 464 | oxcf->gf_cbr_boost_pct = extra_cfg->gf_cbr_boost_pct; |
| 465 | |
| 466 | oxcf->best_allowed_q = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 467 | extra_cfg->lossless ? 0 : av1_quantizer_to_qindex(cfg->rc_min_quantizer); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 468 | oxcf->worst_allowed_q = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 469 | extra_cfg->lossless ? 0 : av1_quantizer_to_qindex(cfg->rc_max_quantizer); |
| 470 | oxcf->cq_level = av1_quantizer_to_qindex(extra_cfg->cq_level); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 471 | oxcf->fixed_q = -1; |
| 472 | |
| 473 | #if CONFIG_AOM_QM |
| 474 | oxcf->using_qm = extra_cfg->enable_qm; |
| 475 | oxcf->qm_minlevel = extra_cfg->qm_min; |
| 476 | oxcf->qm_maxlevel = extra_cfg->qm_max; |
| 477 | #endif |
| 478 | |
Thomas Davies | af6df17 | 2016-11-09 14:04:18 +0000 | [diff] [blame] | 479 | #if CONFIG_TILE_GROUPS |
| 480 | oxcf->num_tile_groups = extra_cfg->num_tg; |
| 481 | oxcf->mtu = extra_cfg->mtu_size; |
| 482 | #endif |
| 483 | |
Fangwen Fu | 8d164de | 2016-12-14 13:40:54 -0800 | [diff] [blame] | 484 | #if CONFIG_TEMPMV_SIGNALING |
| 485 | oxcf->disable_tempmv = extra_cfg->disable_tempmv; |
| 486 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 487 | oxcf->under_shoot_pct = cfg->rc_undershoot_pct; |
| 488 | oxcf->over_shoot_pct = cfg->rc_overshoot_pct; |
| 489 | |
| 490 | oxcf->scaled_frame_width = cfg->rc_scaled_width; |
| 491 | oxcf->scaled_frame_height = cfg->rc_scaled_height; |
| 492 | if (cfg->rc_resize_allowed == 1) { |
| 493 | oxcf->resize_mode = |
| 494 | (oxcf->scaled_frame_width == 0 || oxcf->scaled_frame_height == 0) |
| 495 | ? RESIZE_DYNAMIC |
| 496 | : RESIZE_FIXED; |
| 497 | } else { |
| 498 | oxcf->resize_mode = RESIZE_NONE; |
| 499 | } |
| 500 | |
Fergus Simpson | 3502d08 | 2017-04-10 12:25:07 -0700 | [diff] [blame] | 501 | // Initialize to input resolution if not specified. |
| 502 | if (oxcf->resize_mode != RESIZE_FIXED) { |
| 503 | oxcf->scaled_frame_width = oxcf->width; |
| 504 | oxcf->scaled_frame_height = oxcf->height; |
| 505 | } |
| 506 | |
| 507 | #if CONFIG_FRAME_SUPERRES |
| 508 | oxcf->superres_enabled = 1; // TODO(afergs): Check the config |
| 509 | #endif // CONFIG_FRAME_SUPERRES |
| 510 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 511 | oxcf->maximum_buffer_size_ms = is_vbr ? 240000 : cfg->rc_buf_sz; |
| 512 | oxcf->starting_buffer_level_ms = is_vbr ? 60000 : cfg->rc_buf_initial_sz; |
| 513 | oxcf->optimal_buffer_level_ms = is_vbr ? 60000 : cfg->rc_buf_optimal_sz; |
| 514 | |
| 515 | oxcf->drop_frames_water_mark = cfg->rc_dropframe_thresh; |
| 516 | |
| 517 | oxcf->two_pass_vbrbias = cfg->rc_2pass_vbr_bias_pct; |
| 518 | oxcf->two_pass_vbrmin_section = cfg->rc_2pass_vbr_minsection_pct; |
| 519 | oxcf->two_pass_vbrmax_section = cfg->rc_2pass_vbr_maxsection_pct; |
| 520 | |
| 521 | oxcf->auto_key = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 522 | cfg->kf_mode == AOM_KF_AUTO && cfg->kf_min_dist != cfg->kf_max_dist; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 523 | |
| 524 | oxcf->key_freq = cfg->kf_max_dist; |
| 525 | |
Alex Converse | 561d0af | 2017-03-23 12:58:04 -0700 | [diff] [blame] | 526 | oxcf->speed = extra_cfg->cpu_used; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 527 | oxcf->enable_auto_arf = extra_cfg->enable_auto_alt_ref; |
| 528 | #if CONFIG_EXT_REFS |
| 529 | oxcf->enable_auto_brf = extra_cfg->enable_auto_bwd_ref; |
| 530 | #endif // CONFIG_EXT_REFS |
| 531 | oxcf->noise_sensitivity = extra_cfg->noise_sensitivity; |
| 532 | oxcf->sharpness = extra_cfg->sharpness; |
| 533 | |
| 534 | oxcf->two_pass_stats_in = cfg->rc_twopass_stats_in; |
| 535 | |
| 536 | #if CONFIG_FP_MB_STATS |
| 537 | oxcf->firstpass_mb_stats_in = cfg->rc_firstpass_mb_stats_in; |
| 538 | #endif |
| 539 | |
| 540 | oxcf->color_space = extra_cfg->color_space; |
anorkin | 76fb126 | 2017-03-22 15:12:12 -0700 | [diff] [blame^] | 541 | #if CONFIG_COLORSPACE_HEADERS |
| 542 | oxcf->transfer_function = extra_cfg->transfer_function; |
| 543 | oxcf->chroma_sample_position = extra_cfg->chroma_sample_position; |
| 544 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 545 | oxcf->color_range = extra_cfg->color_range; |
| 546 | oxcf->render_width = extra_cfg->render_width; |
| 547 | oxcf->render_height = extra_cfg->render_height; |
| 548 | oxcf->arnr_max_frames = extra_cfg->arnr_max_frames; |
| 549 | oxcf->arnr_strength = extra_cfg->arnr_strength; |
| 550 | oxcf->min_gf_interval = extra_cfg->min_gf_interval; |
| 551 | oxcf->max_gf_interval = extra_cfg->max_gf_interval; |
| 552 | |
| 553 | oxcf->tuning = extra_cfg->tuning; |
| 554 | oxcf->content = extra_cfg->content; |
| 555 | |
| 556 | #if CONFIG_EXT_PARTITION |
| 557 | oxcf->superblock_size = extra_cfg->superblock_size; |
| 558 | #endif // CONFIG_EXT_PARTITION |
Alex Converse | eb780e7 | 2016-12-13 12:46:41 -0800 | [diff] [blame] | 559 | #if CONFIG_ANS && ANS_MAX_SYMBOLS |
| 560 | oxcf->ans_window_size_log2 = extra_cfg->ans_window_size_log2; |
| 561 | #endif // CONFIG_ANS && ANS_MAX_SYMBOLS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 562 | |
| 563 | #if CONFIG_EXT_TILE |
| 564 | { |
| 565 | #if CONFIG_EXT_PARTITION |
| 566 | const unsigned int max = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 567 | extra_cfg->superblock_size == AOM_SUPERBLOCK_SIZE_64X64 ? 64 : 32; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 568 | #else |
| 569 | const unsigned int max = 64; |
| 570 | #endif // CONFIG_EXT_PARTITION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 571 | oxcf->tile_columns = AOMMIN(extra_cfg->tile_columns, max); |
| 572 | oxcf->tile_rows = AOMMIN(extra_cfg->tile_rows, max); |
Yunqing Wang | d8cd55f | 2017-02-27 12:16:00 -0800 | [diff] [blame] | 573 | oxcf->tile_encoding_mode = extra_cfg->tile_encoding_mode; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 574 | } |
| 575 | #else |
| 576 | oxcf->tile_columns = extra_cfg->tile_columns; |
| 577 | oxcf->tile_rows = extra_cfg->tile_rows; |
| 578 | #endif // CONFIG_EXT_TILE |
Fangwen Fu | 7b9f2b3 | 2017-01-17 14:01:52 -0800 | [diff] [blame] | 579 | #if CONFIG_DEPENDENT_HORZTILES |
| 580 | oxcf->dependent_horz_tiles = extra_cfg->dependent_horz_tiles; |
| 581 | #endif |
Ryan Lei | 9b02b0e | 2017-01-30 15:52:20 -0800 | [diff] [blame] | 582 | #if CONFIG_LOOPFILTERING_ACROSS_TILES |
Ryan Lei | 7386eda | 2016-12-08 21:08:31 -0800 | [diff] [blame] | 583 | oxcf->loop_filter_across_tiles_enabled = |
| 584 | extra_cfg->loop_filter_across_tiles_enabled; |
Ryan Lei | 9b02b0e | 2017-01-30 15:52:20 -0800 | [diff] [blame] | 585 | #endif // CONFIG_LOOPFILTERING_ACROSS_TILES |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 586 | oxcf->error_resilient_mode = cfg->g_error_resilient; |
| 587 | oxcf->frame_parallel_decoding_mode = extra_cfg->frame_parallel_decoding_mode; |
| 588 | |
| 589 | oxcf->aq_mode = extra_cfg->aq_mode; |
Fangwen Fu | 6160df2 | 2017-04-24 09:45:51 -0700 | [diff] [blame] | 590 | #if CONFIG_EXT_DELTA_Q |
| 591 | oxcf->deltaq_mode = extra_cfg->deltaq_mode; |
| 592 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 593 | |
| 594 | oxcf->frame_periodic_boost = extra_cfg->frame_periodic_boost; |
| 595 | |
Yunqing Wang | ff4fa06 | 2017-04-21 10:56:08 -0700 | [diff] [blame] | 596 | oxcf->motion_vector_unit_test = extra_cfg->motion_vector_unit_test; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 597 | /* |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 598 | printf("Current AV1 Settings: \n"); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 599 | printf("target_bandwidth: %d\n", oxcf->target_bandwidth); |
| 600 | printf("noise_sensitivity: %d\n", oxcf->noise_sensitivity); |
| 601 | printf("sharpness: %d\n", oxcf->sharpness); |
| 602 | printf("cpu_used: %d\n", oxcf->cpu_used); |
| 603 | printf("Mode: %d\n", oxcf->mode); |
| 604 | printf("auto_key: %d\n", oxcf->auto_key); |
| 605 | printf("key_freq: %d\n", oxcf->key_freq); |
| 606 | printf("end_usage: %d\n", oxcf->end_usage); |
| 607 | printf("under_shoot_pct: %d\n", oxcf->under_shoot_pct); |
| 608 | printf("over_shoot_pct: %d\n", oxcf->over_shoot_pct); |
| 609 | printf("starting_buffer_level: %d\n", oxcf->starting_buffer_level); |
| 610 | printf("optimal_buffer_level: %d\n", oxcf->optimal_buffer_level); |
| 611 | printf("maximum_buffer_size: %d\n", oxcf->maximum_buffer_size); |
| 612 | printf("fixed_q: %d\n", oxcf->fixed_q); |
| 613 | printf("worst_allowed_q: %d\n", oxcf->worst_allowed_q); |
| 614 | printf("best_allowed_q: %d\n", oxcf->best_allowed_q); |
| 615 | printf("allow_spatial_resampling: %d\n", oxcf->allow_spatial_resampling); |
| 616 | printf("scaled_frame_width: %d\n", oxcf->scaled_frame_width); |
| 617 | printf("scaled_frame_height: %d\n", oxcf->scaled_frame_height); |
| 618 | printf("two_pass_vbrbias: %d\n", oxcf->two_pass_vbrbias); |
| 619 | printf("two_pass_vbrmin_section: %d\n", oxcf->two_pass_vbrmin_section); |
| 620 | printf("two_pass_vbrmax_section: %d\n", oxcf->two_pass_vbrmax_section); |
| 621 | printf("lag_in_frames: %d\n", oxcf->lag_in_frames); |
| 622 | printf("enable_auto_arf: %d\n", oxcf->enable_auto_arf); |
| 623 | printf("Version: %d\n", oxcf->Version); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 624 | printf("error resilient: %d\n", oxcf->error_resilient_mode); |
| 625 | printf("frame parallel detokenization: %d\n", |
| 626 | oxcf->frame_parallel_decoding_mode); |
| 627 | */ |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 628 | return AOM_CODEC_OK; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 629 | } |
| 630 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 631 | static aom_codec_err_t encoder_set_config(aom_codec_alg_priv_t *ctx, |
| 632 | const aom_codec_enc_cfg_t *cfg) { |
| 633 | aom_codec_err_t res; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 634 | int force_key = 0; |
| 635 | |
| 636 | if (cfg->g_w != ctx->cfg.g_w || cfg->g_h != ctx->cfg.g_h) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 637 | if (cfg->g_lag_in_frames > 1 || cfg->g_pass != AOM_RC_ONE_PASS) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 638 | ERROR("Cannot change width or height after initialization"); |
| 639 | if (!valid_ref_frame_size(ctx->cfg.g_w, ctx->cfg.g_h, cfg->g_w, cfg->g_h) || |
| 640 | (ctx->cpi->initial_width && (int)cfg->g_w > ctx->cpi->initial_width) || |
| 641 | (ctx->cpi->initial_height && (int)cfg->g_h > ctx->cpi->initial_height)) |
| 642 | force_key = 1; |
| 643 | } |
| 644 | |
| 645 | // Prevent increasing lag_in_frames. This check is stricter than it needs |
| 646 | // to be -- the limit is not increasing past the first lag_in_frames |
| 647 | // value, but we don't track the initial config, only the last successful |
| 648 | // config. |
| 649 | if (cfg->g_lag_in_frames > ctx->cfg.g_lag_in_frames) |
| 650 | ERROR("Cannot increase lag_in_frames"); |
| 651 | |
| 652 | res = validate_config(ctx, cfg, &ctx->extra_cfg); |
| 653 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 654 | if (res == AOM_CODEC_OK) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 655 | ctx->cfg = *cfg; |
| 656 | set_encoder_config(&ctx->oxcf, &ctx->cfg, &ctx->extra_cfg); |
| 657 | // On profile change, request a key frame |
| 658 | force_key |= ctx->cpi->common.profile != ctx->oxcf.profile; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 659 | av1_change_config(ctx->cpi, &ctx->oxcf); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 660 | } |
| 661 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 662 | if (force_key) ctx->next_frame_flags |= AOM_EFLAG_FORCE_KF; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 663 | |
| 664 | return res; |
| 665 | } |
| 666 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 667 | static aom_codec_err_t ctrl_get_quantizer(aom_codec_alg_priv_t *ctx, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 668 | va_list args) { |
| 669 | int *const arg = va_arg(args, int *); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 670 | if (arg == NULL) return AOM_CODEC_INVALID_PARAM; |
| 671 | *arg = av1_get_quantizer(ctx->cpi); |
| 672 | return AOM_CODEC_OK; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 673 | } |
| 674 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 675 | static aom_codec_err_t ctrl_get_quantizer64(aom_codec_alg_priv_t *ctx, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 676 | va_list args) { |
| 677 | int *const arg = va_arg(args, int *); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 678 | if (arg == NULL) return AOM_CODEC_INVALID_PARAM; |
| 679 | *arg = av1_qindex_to_quantizer(av1_get_quantizer(ctx->cpi)); |
| 680 | return AOM_CODEC_OK; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 681 | } |
| 682 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 683 | static aom_codec_err_t update_extra_cfg(aom_codec_alg_priv_t *ctx, |
| 684 | const struct av1_extracfg *extra_cfg) { |
| 685 | const aom_codec_err_t res = validate_config(ctx, &ctx->cfg, extra_cfg); |
| 686 | if (res == AOM_CODEC_OK) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 687 | ctx->extra_cfg = *extra_cfg; |
| 688 | set_encoder_config(&ctx->oxcf, &ctx->cfg, &ctx->extra_cfg); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 689 | av1_change_config(ctx->cpi, &ctx->oxcf); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 690 | } |
| 691 | return res; |
| 692 | } |
| 693 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 694 | static aom_codec_err_t ctrl_set_cpuused(aom_codec_alg_priv_t *ctx, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 695 | va_list args) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 696 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
| 697 | extra_cfg.cpu_used = CAST(AOME_SET_CPUUSED, args); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 698 | return update_extra_cfg(ctx, &extra_cfg); |
| 699 | } |
| 700 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 701 | static aom_codec_err_t ctrl_set_enable_auto_alt_ref(aom_codec_alg_priv_t *ctx, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 702 | va_list args) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 703 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
| 704 | extra_cfg.enable_auto_alt_ref = CAST(AOME_SET_ENABLEAUTOALTREF, args); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 705 | return update_extra_cfg(ctx, &extra_cfg); |
| 706 | } |
| 707 | |
| 708 | #if CONFIG_EXT_REFS |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 709 | static aom_codec_err_t ctrl_set_enable_auto_bwd_ref(aom_codec_alg_priv_t *ctx, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 710 | va_list args) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 711 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
| 712 | extra_cfg.enable_auto_bwd_ref = CAST(AOME_SET_ENABLEAUTOBWDREF, args); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 713 | return update_extra_cfg(ctx, &extra_cfg); |
| 714 | } |
| 715 | #endif // CONFIG_EXT_REFS |
| 716 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 717 | static aom_codec_err_t ctrl_set_noise_sensitivity(aom_codec_alg_priv_t *ctx, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 718 | va_list args) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 719 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
| 720 | extra_cfg.noise_sensitivity = CAST(AV1E_SET_NOISE_SENSITIVITY, args); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 721 | return update_extra_cfg(ctx, &extra_cfg); |
| 722 | } |
| 723 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 724 | static aom_codec_err_t ctrl_set_sharpness(aom_codec_alg_priv_t *ctx, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 725 | va_list args) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 726 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
| 727 | extra_cfg.sharpness = CAST(AOME_SET_SHARPNESS, args); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 728 | return update_extra_cfg(ctx, &extra_cfg); |
| 729 | } |
| 730 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 731 | static aom_codec_err_t ctrl_set_static_thresh(aom_codec_alg_priv_t *ctx, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 732 | va_list args) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 733 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
| 734 | extra_cfg.static_thresh = CAST(AOME_SET_STATIC_THRESHOLD, args); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 735 | return update_extra_cfg(ctx, &extra_cfg); |
| 736 | } |
| 737 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 738 | static aom_codec_err_t ctrl_set_tile_columns(aom_codec_alg_priv_t *ctx, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 739 | va_list args) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 740 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
| 741 | extra_cfg.tile_columns = CAST(AV1E_SET_TILE_COLUMNS, args); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 742 | return update_extra_cfg(ctx, &extra_cfg); |
| 743 | } |
| 744 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 745 | static aom_codec_err_t ctrl_set_tile_rows(aom_codec_alg_priv_t *ctx, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 746 | va_list args) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 747 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
| 748 | extra_cfg.tile_rows = CAST(AV1E_SET_TILE_ROWS, args); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 749 | return update_extra_cfg(ctx, &extra_cfg); |
| 750 | } |
Fangwen Fu | 7b9f2b3 | 2017-01-17 14:01:52 -0800 | [diff] [blame] | 751 | #if CONFIG_DEPENDENT_HORZTILES |
| 752 | static aom_codec_err_t ctrl_set_tile_dependent_rows(aom_codec_alg_priv_t *ctx, |
| 753 | va_list args) { |
| 754 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
| 755 | extra_cfg.dependent_horz_tiles = CAST(AV1E_SET_TILE_DEPENDENT_ROWS, args); |
| 756 | return update_extra_cfg(ctx, &extra_cfg); |
| 757 | } |
| 758 | #endif |
Ryan Lei | 9b02b0e | 2017-01-30 15:52:20 -0800 | [diff] [blame] | 759 | #if CONFIG_LOOPFILTERING_ACROSS_TILES |
Ryan Lei | 7386eda | 2016-12-08 21:08:31 -0800 | [diff] [blame] | 760 | static aom_codec_err_t ctrl_set_tile_loopfilter(aom_codec_alg_priv_t *ctx, |
| 761 | va_list args) { |
| 762 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
| 763 | extra_cfg.loop_filter_across_tiles_enabled = |
| 764 | CAST(AV1E_SET_TILE_LOOPFILTER, args); |
| 765 | return update_extra_cfg(ctx, &extra_cfg); |
| 766 | } |
Ryan Lei | 9b02b0e | 2017-01-30 15:52:20 -0800 | [diff] [blame] | 767 | #endif // CONFIG_LOOPFILTERING_ACROSS_TILES |
Ryan Lei | 7386eda | 2016-12-08 21:08:31 -0800 | [diff] [blame] | 768 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 769 | static aom_codec_err_t ctrl_set_arnr_max_frames(aom_codec_alg_priv_t *ctx, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 770 | va_list args) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 771 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
| 772 | extra_cfg.arnr_max_frames = CAST(AOME_SET_ARNR_MAXFRAMES, args); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 773 | return update_extra_cfg(ctx, &extra_cfg); |
| 774 | } |
| 775 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 776 | static aom_codec_err_t ctrl_set_arnr_strength(aom_codec_alg_priv_t *ctx, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 777 | va_list args) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 778 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
| 779 | extra_cfg.arnr_strength = CAST(AOME_SET_ARNR_STRENGTH, args); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 780 | return update_extra_cfg(ctx, &extra_cfg); |
| 781 | } |
| 782 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 783 | static aom_codec_err_t ctrl_set_tuning(aom_codec_alg_priv_t *ctx, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 784 | va_list args) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 785 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
| 786 | extra_cfg.tuning = CAST(AOME_SET_TUNING, args); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 787 | return update_extra_cfg(ctx, &extra_cfg); |
| 788 | } |
| 789 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 790 | static aom_codec_err_t ctrl_set_cq_level(aom_codec_alg_priv_t *ctx, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 791 | va_list args) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 792 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
| 793 | extra_cfg.cq_level = CAST(AOME_SET_CQ_LEVEL, args); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 794 | return update_extra_cfg(ctx, &extra_cfg); |
| 795 | } |
| 796 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 797 | static aom_codec_err_t ctrl_set_rc_max_intra_bitrate_pct( |
| 798 | aom_codec_alg_priv_t *ctx, va_list args) { |
| 799 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 800 | extra_cfg.rc_max_intra_bitrate_pct = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 801 | CAST(AOME_SET_MAX_INTRA_BITRATE_PCT, args); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 802 | return update_extra_cfg(ctx, &extra_cfg); |
| 803 | } |
| 804 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 805 | static aom_codec_err_t ctrl_set_rc_max_inter_bitrate_pct( |
| 806 | aom_codec_alg_priv_t *ctx, va_list args) { |
| 807 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 808 | extra_cfg.rc_max_inter_bitrate_pct = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 809 | CAST(AOME_SET_MAX_INTER_BITRATE_PCT, args); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 810 | return update_extra_cfg(ctx, &extra_cfg); |
| 811 | } |
| 812 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 813 | static aom_codec_err_t ctrl_set_rc_gf_cbr_boost_pct(aom_codec_alg_priv_t *ctx, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 814 | va_list args) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 815 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
| 816 | extra_cfg.gf_cbr_boost_pct = CAST(AV1E_SET_GF_CBR_BOOST_PCT, args); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 817 | return update_extra_cfg(ctx, &extra_cfg); |
| 818 | } |
| 819 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 820 | static aom_codec_err_t ctrl_set_lossless(aom_codec_alg_priv_t *ctx, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 821 | va_list args) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 822 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
| 823 | extra_cfg.lossless = CAST(AV1E_SET_LOSSLESS, args); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 824 | return update_extra_cfg(ctx, &extra_cfg); |
| 825 | } |
| 826 | |
| 827 | #if CONFIG_AOM_QM |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 828 | static aom_codec_err_t ctrl_set_enable_qm(aom_codec_alg_priv_t *ctx, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 829 | va_list args) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 830 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
| 831 | extra_cfg.enable_qm = CAST(AV1E_SET_ENABLE_QM, args); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 832 | return update_extra_cfg(ctx, &extra_cfg); |
| 833 | } |
| 834 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 835 | static aom_codec_err_t ctrl_set_qm_min(aom_codec_alg_priv_t *ctx, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 836 | va_list args) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 837 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
| 838 | extra_cfg.qm_min = CAST(AV1E_SET_QM_MIN, args); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 839 | return update_extra_cfg(ctx, &extra_cfg); |
| 840 | } |
| 841 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 842 | static aom_codec_err_t ctrl_set_qm_max(aom_codec_alg_priv_t *ctx, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 843 | va_list args) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 844 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
| 845 | extra_cfg.qm_max = CAST(AV1E_SET_QM_MAX, args); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 846 | return update_extra_cfg(ctx, &extra_cfg); |
| 847 | } |
| 848 | #endif |
| 849 | |
Thomas Davies | af6df17 | 2016-11-09 14:04:18 +0000 | [diff] [blame] | 850 | #if CONFIG_TILE_GROUPS |
| 851 | static aom_codec_err_t ctrl_set_num_tg(aom_codec_alg_priv_t *ctx, |
| 852 | va_list args) { |
| 853 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
| 854 | extra_cfg.num_tg = CAST(AV1E_SET_NUM_TG, args); |
| 855 | return update_extra_cfg(ctx, &extra_cfg); |
| 856 | } |
| 857 | |
| 858 | static aom_codec_err_t ctrl_set_mtu(aom_codec_alg_priv_t *ctx, va_list args) { |
| 859 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
| 860 | extra_cfg.mtu_size = CAST(AV1E_SET_MTU, args); |
| 861 | return update_extra_cfg(ctx, &extra_cfg); |
| 862 | } |
| 863 | #endif |
Fangwen Fu | 8d164de | 2016-12-14 13:40:54 -0800 | [diff] [blame] | 864 | #if CONFIG_TEMPMV_SIGNALING |
| 865 | static aom_codec_err_t ctrl_set_disable_tempmv(aom_codec_alg_priv_t *ctx, |
| 866 | va_list args) { |
| 867 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
| 868 | extra_cfg.disable_tempmv = CAST(AV1E_SET_DISABLE_TEMPMV, args); |
| 869 | return update_extra_cfg(ctx, &extra_cfg); |
| 870 | } |
| 871 | #endif |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 872 | static aom_codec_err_t ctrl_set_frame_parallel_decoding_mode( |
| 873 | aom_codec_alg_priv_t *ctx, va_list args) { |
| 874 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 875 | extra_cfg.frame_parallel_decoding_mode = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 876 | CAST(AV1E_SET_FRAME_PARALLEL_DECODING, args); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 877 | return update_extra_cfg(ctx, &extra_cfg); |
| 878 | } |
| 879 | |
Yunqing Wang | d8cd55f | 2017-02-27 12:16:00 -0800 | [diff] [blame] | 880 | #if CONFIG_EXT_TILE |
| 881 | static aom_codec_err_t ctrl_set_tile_encoding_mode(aom_codec_alg_priv_t *ctx, |
| 882 | va_list args) { |
| 883 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
| 884 | extra_cfg.tile_encoding_mode = CAST(AV1E_SET_TILE_ENCODING_MODE, args); |
| 885 | return update_extra_cfg(ctx, &extra_cfg); |
| 886 | } |
| 887 | #endif // CONFIG_EXT_TILE |
| 888 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 889 | static aom_codec_err_t ctrl_set_aq_mode(aom_codec_alg_priv_t *ctx, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 890 | va_list args) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 891 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
| 892 | extra_cfg.aq_mode = CAST(AV1E_SET_AQ_MODE, args); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 893 | return update_extra_cfg(ctx, &extra_cfg); |
| 894 | } |
| 895 | |
Fangwen Fu | 6160df2 | 2017-04-24 09:45:51 -0700 | [diff] [blame] | 896 | #if CONFIG_EXT_DELTA_Q |
| 897 | static aom_codec_err_t ctrl_set_deltaq_mode(aom_codec_alg_priv_t *ctx, |
| 898 | va_list args) { |
| 899 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
| 900 | extra_cfg.deltaq_mode = CAST(AV1E_SET_DELTAQ_MODE, args); |
| 901 | return update_extra_cfg(ctx, &extra_cfg); |
| 902 | } |
| 903 | #endif |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 904 | static aom_codec_err_t ctrl_set_min_gf_interval(aom_codec_alg_priv_t *ctx, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 905 | va_list args) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 906 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
| 907 | extra_cfg.min_gf_interval = CAST(AV1E_SET_MIN_GF_INTERVAL, args); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 908 | return update_extra_cfg(ctx, &extra_cfg); |
| 909 | } |
| 910 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 911 | static aom_codec_err_t ctrl_set_max_gf_interval(aom_codec_alg_priv_t *ctx, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 912 | va_list args) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 913 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
| 914 | extra_cfg.max_gf_interval = CAST(AV1E_SET_MAX_GF_INTERVAL, args); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 915 | return update_extra_cfg(ctx, &extra_cfg); |
| 916 | } |
| 917 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 918 | static aom_codec_err_t ctrl_set_frame_periodic_boost(aom_codec_alg_priv_t *ctx, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 919 | va_list args) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 920 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
| 921 | extra_cfg.frame_periodic_boost = CAST(AV1E_SET_FRAME_PERIODIC_BOOST, args); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 922 | return update_extra_cfg(ctx, &extra_cfg); |
| 923 | } |
| 924 | |
Yunqing Wang | ff4fa06 | 2017-04-21 10:56:08 -0700 | [diff] [blame] | 925 | static aom_codec_err_t ctrl_enable_motion_vector_unit_test( |
| 926 | aom_codec_alg_priv_t *ctx, va_list args) { |
| 927 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
| 928 | extra_cfg.motion_vector_unit_test = |
| 929 | CAST(AV1E_ENABLE_MOTION_VECTOR_UNIT_TEST, args); |
| 930 | return update_extra_cfg(ctx, &extra_cfg); |
| 931 | } |
| 932 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 933 | static aom_codec_err_t encoder_init(aom_codec_ctx_t *ctx, |
| 934 | aom_codec_priv_enc_mr_cfg_t *data) { |
| 935 | aom_codec_err_t res = AOM_CODEC_OK; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 936 | (void)data; |
| 937 | |
| 938 | if (ctx->priv == NULL) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 939 | aom_codec_alg_priv_t *const priv = aom_calloc(1, sizeof(*priv)); |
| 940 | if (priv == NULL) return AOM_CODEC_MEM_ERROR; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 941 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 942 | ctx->priv = (aom_codec_priv_t *)priv; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 943 | ctx->priv->init_flags = ctx->init_flags; |
| 944 | ctx->priv->enc.total_encoders = 1; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 945 | priv->buffer_pool = (BufferPool *)aom_calloc(1, sizeof(BufferPool)); |
| 946 | if (priv->buffer_pool == NULL) return AOM_CODEC_MEM_ERROR; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 947 | |
| 948 | #if CONFIG_MULTITHREAD |
| 949 | if (pthread_mutex_init(&priv->buffer_pool->pool_mutex, NULL)) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 950 | return AOM_CODEC_MEM_ERROR; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 951 | } |
| 952 | #endif |
| 953 | |
| 954 | if (ctx->config.enc) { |
| 955 | // Update the reference to the config structure to an internal copy. |
| 956 | priv->cfg = *ctx->config.enc; |
| 957 | ctx->config.enc = &priv->cfg; |
| 958 | } |
| 959 | |
| 960 | priv->extra_cfg = default_extra_cfg; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 961 | once(av1_initialize_enc); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 962 | |
| 963 | res = validate_config(priv, &priv->cfg, &priv->extra_cfg); |
| 964 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 965 | if (res == AOM_CODEC_OK) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 966 | set_encoder_config(&priv->oxcf, &priv->cfg, &priv->extra_cfg); |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 967 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 968 | priv->oxcf.use_highbitdepth = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 969 | (ctx->init_flags & AOM_CODEC_USE_HIGHBITDEPTH) ? 1 : 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 970 | #endif |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 971 | priv->cpi = av1_create_compressor(&priv->oxcf, priv->buffer_pool); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 972 | if (priv->cpi == NULL) |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 973 | res = AOM_CODEC_MEM_ERROR; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 974 | else |
| 975 | priv->cpi->output_pkt_list = &priv->pkt_list.head; |
| 976 | } |
| 977 | } |
| 978 | |
| 979 | return res; |
| 980 | } |
| 981 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 982 | static aom_codec_err_t encoder_destroy(aom_codec_alg_priv_t *ctx) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 983 | free(ctx->cx_data); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 984 | av1_remove_compressor(ctx->cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 985 | #if CONFIG_MULTITHREAD |
| 986 | pthread_mutex_destroy(&ctx->buffer_pool->pool_mutex); |
| 987 | #endif |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 988 | aom_free(ctx->buffer_pool); |
| 989 | aom_free(ctx); |
| 990 | return AOM_CODEC_OK; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 991 | } |
| 992 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 993 | static void pick_quickcompress_mode(aom_codec_alg_priv_t *ctx, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 994 | unsigned long deadline) { |
Thomas Daede | 6eca835 | 2017-03-17 14:14:12 -0700 | [diff] [blame] | 995 | MODE new_mode = GOOD; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 996 | |
| 997 | switch (ctx->cfg.g_pass) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 998 | case AOM_RC_ONE_PASS: |
Thomas Daede | ac0a380 | 2016-03-01 14:29:47 -0800 | [diff] [blame] | 999 | switch (deadline) { |
Thomas Daede | ac0a380 | 2016-03-01 14:29:47 -0800 | [diff] [blame] | 1000 | default: new_mode = GOOD; break; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1001 | } |
| 1002 | break; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1003 | case AOM_RC_FIRST_PASS: break; |
Thomas Daede | 6eca835 | 2017-03-17 14:14:12 -0700 | [diff] [blame] | 1004 | case AOM_RC_LAST_PASS: new_mode = GOOD; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1005 | } |
| 1006 | |
| 1007 | if (ctx->oxcf.mode != new_mode) { |
| 1008 | ctx->oxcf.mode = new_mode; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1009 | av1_change_config(ctx->cpi, &ctx->oxcf); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1010 | } |
| 1011 | } |
| 1012 | |
| 1013 | // Turn on to test if supplemental superframe data breaks decoding |
| 1014 | // #define TEST_SUPPLEMENTAL_SUPERFRAME_DATA |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1015 | static int write_superframe_index(aom_codec_alg_priv_t *ctx) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1016 | uint8_t marker = 0xc0; |
| 1017 | unsigned int mask; |
| 1018 | int mag, index_sz; |
| 1019 | int i; |
| 1020 | size_t max_frame_sz = 0; |
| 1021 | |
| 1022 | assert(ctx->pending_frame_count); |
| 1023 | assert(ctx->pending_frame_count <= 8); |
| 1024 | |
| 1025 | // Add the number of frames to the marker byte |
| 1026 | marker |= ctx->pending_frame_count - 1; |
| 1027 | for (i = 0; i < ctx->pending_frame_count - 1; i++) { |
| 1028 | const size_t frame_sz = (unsigned int)ctx->pending_frame_sizes[i] - 1; |
| 1029 | max_frame_sz = frame_sz > max_frame_sz ? frame_sz : max_frame_sz; |
| 1030 | } |
| 1031 | |
| 1032 | // Choose the magnitude |
| 1033 | for (mag = 0, mask = 0xff; mag < 4; mag++) { |
| 1034 | if (max_frame_sz <= mask) break; |
| 1035 | mask <<= 8; |
| 1036 | mask |= 0xff; |
| 1037 | } |
| 1038 | marker |= mag << 3; |
| 1039 | |
| 1040 | // Write the index |
| 1041 | index_sz = 2 + (mag + 1) * (ctx->pending_frame_count - 1); |
| 1042 | if (ctx->pending_cx_data_sz + index_sz < ctx->cx_data_sz) { |
| 1043 | uint8_t *x = ctx->pending_cx_data + ctx->pending_cx_data_sz; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1044 | #ifdef TEST_SUPPLEMENTAL_SUPERFRAME_DATA |
| 1045 | uint8_t marker_test = 0xc0; |
| 1046 | int mag_test = 2; // 1 - 4 |
| 1047 | int frames_test = 4; // 1 - 8 |
| 1048 | int index_sz_test = 2 + mag_test * frames_test; |
| 1049 | marker_test |= frames_test - 1; |
| 1050 | marker_test |= (mag_test - 1) << 3; |
| 1051 | *x++ = marker_test; |
| 1052 | for (i = 0; i < mag_test * frames_test; ++i) |
| 1053 | *x++ = 0; // fill up with arbitrary data |
| 1054 | *x++ = marker_test; |
| 1055 | ctx->pending_cx_data_sz += index_sz_test; |
| 1056 | printf("Added supplemental superframe data\n"); |
| 1057 | #endif |
| 1058 | |
| 1059 | *x++ = marker; |
| 1060 | for (i = 0; i < ctx->pending_frame_count - 1; i++) { |
| 1061 | unsigned int this_sz; |
Urvang Joshi | 368fbc9 | 2016-10-17 16:31:34 -0700 | [diff] [blame] | 1062 | int j; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1063 | |
| 1064 | assert(ctx->pending_frame_sizes[i] > 0); |
| 1065 | this_sz = (unsigned int)ctx->pending_frame_sizes[i] - 1; |
| 1066 | for (j = 0; j <= mag; j++) { |
| 1067 | *x++ = this_sz & 0xff; |
| 1068 | this_sz >>= 8; |
| 1069 | } |
| 1070 | } |
| 1071 | *x++ = marker; |
| 1072 | ctx->pending_cx_data_sz += index_sz; |
| 1073 | #ifdef TEST_SUPPLEMENTAL_SUPERFRAME_DATA |
| 1074 | index_sz += index_sz_test; |
| 1075 | #endif |
| 1076 | } |
| 1077 | return index_sz; |
| 1078 | } |
| 1079 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1080 | // av1 uses 10,000,000 ticks/second as time stamp |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1081 | #define TICKS_PER_SEC 10000000LL |
| 1082 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1083 | static int64_t timebase_units_to_ticks(const aom_rational_t *timebase, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1084 | int64_t n) { |
| 1085 | return n * TICKS_PER_SEC * timebase->num / timebase->den; |
| 1086 | } |
| 1087 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1088 | static int64_t ticks_to_timebase_units(const aom_rational_t *timebase, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1089 | int64_t n) { |
| 1090 | const int64_t round = TICKS_PER_SEC * timebase->num / 2 - 1; |
| 1091 | return (n * timebase->den + round) / timebase->num / TICKS_PER_SEC; |
| 1092 | } |
| 1093 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1094 | static aom_codec_frame_flags_t get_frame_pkt_flags(const AV1_COMP *cpi, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1095 | unsigned int lib_flags) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1096 | aom_codec_frame_flags_t flags = lib_flags << 16; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1097 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1098 | if (lib_flags & FRAMEFLAGS_KEY) flags |= AOM_FRAME_IS_KEY; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1099 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1100 | if (cpi->droppable) flags |= AOM_FRAME_IS_DROPPABLE; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1101 | |
| 1102 | return flags; |
| 1103 | } |
| 1104 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1105 | static aom_codec_err_t encoder_encode(aom_codec_alg_priv_t *ctx, |
| 1106 | const aom_image_t *img, |
| 1107 | aom_codec_pts_t pts, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1108 | unsigned long duration, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1109 | aom_enc_frame_flags_t enc_flags, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1110 | unsigned long deadline) { |
Ralph Giles | 1994429 | 2017-04-18 13:46:56 -0700 | [diff] [blame] | 1111 | const size_t kMinCompressedSize = 8192; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1112 | volatile aom_codec_err_t res = AOM_CODEC_OK; |
| 1113 | volatile aom_enc_frame_flags_t flags = enc_flags; |
| 1114 | AV1_COMP *const cpi = ctx->cpi; |
| 1115 | const aom_rational_t *const timebase = &ctx->cfg.g_timebase; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1116 | size_t data_sz; |
| 1117 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1118 | if (cpi == NULL) return AOM_CODEC_INVALID_PARAM; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1119 | |
| 1120 | if (img != NULL) { |
| 1121 | res = validate_img(ctx, img); |
| 1122 | // TODO(jzern) the checks related to cpi's validity should be treated as a |
| 1123 | // failure condition, encoder setup is done fully in init() currently. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1124 | if (res == AOM_CODEC_OK) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1125 | #if CONFIG_EXT_REFS |
Yaowu Xu | abc7d81 | 2016-07-12 11:57:51 -0700 | [diff] [blame] | 1126 | data_sz = ALIGN_POWER_OF_TWO(ctx->cfg.g_w, 5) * |
| 1127 | ALIGN_POWER_OF_TWO(ctx->cfg.g_h, 5) * get_image_bps(img); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1128 | #else |
| 1129 | // There's no codec control for multiple alt-refs so check the encoder |
| 1130 | // instance for its status to determine the compressed data size. |
Yaowu Xu | abc7d81 | 2016-07-12 11:57:51 -0700 | [diff] [blame] | 1131 | data_sz = ALIGN_POWER_OF_TWO(ctx->cfg.g_w, 5) * |
| 1132 | ALIGN_POWER_OF_TWO(ctx->cfg.g_h, 5) * get_image_bps(img) / 8 * |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1133 | (cpi->multi_arf_allowed ? 8 : 2); |
| 1134 | #endif // CONFIG_EXT_REFS |
Yaowu Xu | 416b0d9 | 2016-07-11 11:38:53 -0700 | [diff] [blame] | 1135 | if (data_sz < kMinCompressedSize) data_sz = kMinCompressedSize; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1136 | if (ctx->cx_data == NULL || ctx->cx_data_sz < data_sz) { |
| 1137 | ctx->cx_data_sz = data_sz; |
| 1138 | free(ctx->cx_data); |
| 1139 | ctx->cx_data = (unsigned char *)malloc(ctx->cx_data_sz); |
| 1140 | if (ctx->cx_data == NULL) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1141 | return AOM_CODEC_MEM_ERROR; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1142 | } |
| 1143 | } |
| 1144 | } |
| 1145 | } |
| 1146 | |
Thomas Daede | ac0a380 | 2016-03-01 14:29:47 -0800 | [diff] [blame] | 1147 | pick_quickcompress_mode(ctx, deadline); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1148 | aom_codec_pkt_list_init(&ctx->pkt_list); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1149 | |
| 1150 | // Handle Flags |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1151 | if (((flags & AOM_EFLAG_NO_UPD_GF) && (flags & AOM_EFLAG_FORCE_GF)) || |
| 1152 | ((flags & AOM_EFLAG_NO_UPD_ARF) && (flags & AOM_EFLAG_FORCE_ARF))) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1153 | ctx->base.err_detail = "Conflicting flags."; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1154 | return AOM_CODEC_INVALID_PARAM; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1155 | } |
| 1156 | |
| 1157 | if (setjmp(cpi->common.error.jmp)) { |
| 1158 | cpi->common.error.setjmp = 0; |
| 1159 | res = update_error_state(ctx, &cpi->common.error); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1160 | aom_clear_system_state(); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1161 | return res; |
| 1162 | } |
| 1163 | cpi->common.error.setjmp = 1; |
| 1164 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1165 | av1_apply_encoding_flags(cpi, flags); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1166 | |
| 1167 | // Handle fixed keyframe intervals |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1168 | if (ctx->cfg.kf_mode == AOM_KF_AUTO && |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1169 | ctx->cfg.kf_min_dist == ctx->cfg.kf_max_dist) { |
| 1170 | if (++ctx->fixed_kf_cntr > ctx->cfg.kf_min_dist) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1171 | flags |= AOM_EFLAG_FORCE_KF; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1172 | ctx->fixed_kf_cntr = 1; |
| 1173 | } |
| 1174 | } |
| 1175 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1176 | if (res == AOM_CODEC_OK) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1177 | unsigned int lib_flags = 0; |
| 1178 | YV12_BUFFER_CONFIG sd; |
| 1179 | int64_t dst_time_stamp = timebase_units_to_ticks(timebase, pts); |
| 1180 | int64_t dst_end_time_stamp = |
| 1181 | timebase_units_to_ticks(timebase, pts + duration); |
| 1182 | size_t size, cx_data_sz; |
| 1183 | unsigned char *cx_data; |
| 1184 | |
| 1185 | // Set up internal flags |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1186 | if (ctx->base.init_flags & AOM_CODEC_USE_PSNR) cpi->b_calculate_psnr = 1; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1187 | |
| 1188 | if (img != NULL) { |
| 1189 | res = image2yuvconfig(img, &sd); |
| 1190 | |
| 1191 | // Store the original flags in to the frame buffer. Will extract the |
| 1192 | // key frame flag when we actually encode this frame. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1193 | if (av1_receive_raw_frame(cpi, flags | ctx->next_frame_flags, &sd, |
| 1194 | dst_time_stamp, dst_end_time_stamp)) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1195 | res = update_error_state(ctx, &cpi->common.error); |
| 1196 | } |
| 1197 | ctx->next_frame_flags = 0; |
| 1198 | } |
| 1199 | |
| 1200 | cx_data = ctx->cx_data; |
| 1201 | cx_data_sz = ctx->cx_data_sz; |
| 1202 | |
| 1203 | /* Any pending invisible frames? */ |
| 1204 | if (ctx->pending_cx_data) { |
| 1205 | memmove(cx_data, ctx->pending_cx_data, ctx->pending_cx_data_sz); |
| 1206 | ctx->pending_cx_data = cx_data; |
| 1207 | cx_data += ctx->pending_cx_data_sz; |
| 1208 | cx_data_sz -= ctx->pending_cx_data_sz; |
| 1209 | |
| 1210 | /* TODO: this is a minimal check, the underlying codec doesn't respect |
| 1211 | * the buffer size anyway. |
| 1212 | */ |
| 1213 | if (cx_data_sz < ctx->cx_data_sz / 2) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1214 | aom_internal_error(&cpi->common.error, AOM_CODEC_ERROR, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1215 | "Compressed data buffer too small"); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1216 | return AOM_CODEC_ERROR; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1217 | } |
| 1218 | } |
| 1219 | |
| 1220 | while (cx_data_sz >= ctx->cx_data_sz / 2 && |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1221 | -1 != av1_get_compressed_data(cpi, &lib_flags, &size, cx_data, |
| 1222 | &dst_time_stamp, &dst_end_time_stamp, |
| 1223 | !img)) { |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame] | 1224 | #if CONFIG_REFERENCE_BUFFER |
| 1225 | if (cpi->common.invalid_delta_frame_id_minus1) { |
| 1226 | ctx->base.err_detail = "Invalid delta_frame_id_minus1"; |
| 1227 | return AOM_CODEC_ERROR; |
| 1228 | } |
| 1229 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1230 | if (size) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1231 | aom_codec_cx_pkt_t pkt; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1232 | |
| 1233 | // Pack invisible frames with the next visible frame |
| 1234 | if (!cpi->common.show_frame) { |
| 1235 | if (ctx->pending_cx_data == 0) ctx->pending_cx_data = cx_data; |
| 1236 | ctx->pending_cx_data_sz += size; |
| 1237 | ctx->pending_frame_sizes[ctx->pending_frame_count++] = size; |
| 1238 | cx_data += size; |
| 1239 | cx_data_sz -= size; |
| 1240 | |
| 1241 | continue; |
| 1242 | } |
| 1243 | |
| 1244 | // Add the frame packet to the list of returned packets. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1245 | pkt.kind = AOM_CODEC_CX_FRAME_PKT; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1246 | pkt.data.frame.pts = ticks_to_timebase_units(timebase, dst_time_stamp); |
| 1247 | pkt.data.frame.duration = (unsigned long)ticks_to_timebase_units( |
| 1248 | timebase, dst_end_time_stamp - dst_time_stamp); |
| 1249 | pkt.data.frame.flags = get_frame_pkt_flags(cpi, lib_flags); |
| 1250 | |
| 1251 | if (ctx->pending_cx_data) { |
| 1252 | ctx->pending_frame_sizes[ctx->pending_frame_count++] = size; |
| 1253 | ctx->pending_cx_data_sz += size; |
| 1254 | size += write_superframe_index(ctx); |
| 1255 | pkt.data.frame.buf = ctx->pending_cx_data; |
| 1256 | pkt.data.frame.sz = ctx->pending_cx_data_sz; |
| 1257 | ctx->pending_cx_data = NULL; |
| 1258 | ctx->pending_cx_data_sz = 0; |
| 1259 | ctx->pending_frame_count = 0; |
| 1260 | } else { |
| 1261 | pkt.data.frame.buf = cx_data; |
| 1262 | pkt.data.frame.sz = size; |
| 1263 | } |
| 1264 | pkt.data.frame.partition_id = -1; |
| 1265 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1266 | aom_codec_pkt_list_add(&ctx->pkt_list.head, &pkt); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1267 | |
| 1268 | cx_data += size; |
| 1269 | cx_data_sz -= size; |
| 1270 | } |
| 1271 | } |
| 1272 | } |
| 1273 | |
| 1274 | cpi->common.error.setjmp = 0; |
| 1275 | return res; |
| 1276 | } |
| 1277 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1278 | static const aom_codec_cx_pkt_t *encoder_get_cxdata(aom_codec_alg_priv_t *ctx, |
| 1279 | aom_codec_iter_t *iter) { |
| 1280 | return aom_codec_pkt_list_get(&ctx->pkt_list.head, iter); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1281 | } |
| 1282 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1283 | 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] | 1284 | va_list args) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1285 | aom_ref_frame_t *const frame = va_arg(args, aom_ref_frame_t *); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1286 | |
| 1287 | if (frame != NULL) { |
| 1288 | YV12_BUFFER_CONFIG sd; |
| 1289 | |
| 1290 | image2yuvconfig(&frame->img, &sd); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1291 | av1_set_reference_enc(ctx->cpi, ref_frame_to_av1_reframe(frame->frame_type), |
| 1292 | &sd); |
| 1293 | return AOM_CODEC_OK; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1294 | } else { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1295 | return AOM_CODEC_INVALID_PARAM; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1296 | } |
| 1297 | } |
| 1298 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1299 | 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] | 1300 | va_list args) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1301 | aom_ref_frame_t *const frame = va_arg(args, aom_ref_frame_t *); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1302 | |
| 1303 | if (frame != NULL) { |
| 1304 | YV12_BUFFER_CONFIG sd; |
| 1305 | |
| 1306 | image2yuvconfig(&frame->img, &sd); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1307 | av1_copy_reference_enc(ctx->cpi, |
| 1308 | ref_frame_to_av1_reframe(frame->frame_type), &sd); |
| 1309 | return AOM_CODEC_OK; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1310 | } else { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1311 | return AOM_CODEC_INVALID_PARAM; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1312 | } |
| 1313 | } |
| 1314 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1315 | 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] | 1316 | va_list args) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1317 | av1_ref_frame_t *const frame = va_arg(args, av1_ref_frame_t *); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1318 | |
| 1319 | if (frame != NULL) { |
| 1320 | YV12_BUFFER_CONFIG *fb = get_ref_frame(&ctx->cpi->common, frame->idx); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1321 | if (fb == NULL) return AOM_CODEC_ERROR; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1322 | |
| 1323 | yuvconfig2image(&frame->img, fb, NULL); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1324 | return AOM_CODEC_OK; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1325 | } else { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1326 | return AOM_CODEC_INVALID_PARAM; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1327 | } |
| 1328 | } |
| 1329 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1330 | 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] | 1331 | va_list args) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1332 | aom_image_t *const new_img = va_arg(args, aom_image_t *); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1333 | |
| 1334 | if (new_img != NULL) { |
| 1335 | YV12_BUFFER_CONFIG new_frame; |
| 1336 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1337 | if (av1_get_last_show_frame(ctx->cpi, &new_frame) == 0) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1338 | yuvconfig2image(new_img, &new_frame, NULL); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1339 | return AOM_CODEC_OK; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1340 | } else { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1341 | return AOM_CODEC_ERROR; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1342 | } |
| 1343 | } else { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1344 | return AOM_CODEC_INVALID_PARAM; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1345 | } |
| 1346 | } |
| 1347 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1348 | static aom_codec_err_t ctrl_set_previewpp(aom_codec_alg_priv_t *ctx, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1349 | va_list args) { |
| 1350 | (void)ctx; |
| 1351 | (void)args; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1352 | return AOM_CODEC_INCAPABLE; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1353 | } |
| 1354 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1355 | static aom_image_t *encoder_get_preview(aom_codec_alg_priv_t *ctx) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1356 | YV12_BUFFER_CONFIG sd; |
| 1357 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1358 | if (av1_get_preview_raw_frame(ctx->cpi, &sd) == 0) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1359 | yuvconfig2image(&ctx->preview_img, &sd, NULL); |
| 1360 | return &ctx->preview_img; |
| 1361 | } else { |
| 1362 | return NULL; |
| 1363 | } |
| 1364 | } |
| 1365 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1366 | static aom_codec_err_t ctrl_use_reference(aom_codec_alg_priv_t *ctx, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1367 | va_list args) { |
| 1368 | const int reference_flag = va_arg(args, int); |
| 1369 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1370 | av1_use_as_reference(ctx->cpi, reference_flag); |
| 1371 | return AOM_CODEC_OK; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1372 | } |
| 1373 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1374 | static aom_codec_err_t ctrl_set_roi_map(aom_codec_alg_priv_t *ctx, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1375 | va_list args) { |
| 1376 | (void)ctx; |
| 1377 | (void)args; |
| 1378 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1379 | // TODO(yaowu): Need to re-implement and test for AV1. |
| 1380 | return AOM_CODEC_INVALID_PARAM; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1381 | } |
| 1382 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1383 | static aom_codec_err_t ctrl_set_active_map(aom_codec_alg_priv_t *ctx, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1384 | va_list args) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1385 | aom_active_map_t *const map = va_arg(args, aom_active_map_t *); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1386 | |
| 1387 | if (map) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1388 | if (!av1_set_active_map(ctx->cpi, map->active_map, (int)map->rows, |
| 1389 | (int)map->cols)) |
| 1390 | return AOM_CODEC_OK; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1391 | else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1392 | return AOM_CODEC_INVALID_PARAM; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1393 | } else { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1394 | return AOM_CODEC_INVALID_PARAM; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1395 | } |
| 1396 | } |
| 1397 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1398 | static aom_codec_err_t ctrl_get_active_map(aom_codec_alg_priv_t *ctx, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1399 | va_list args) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1400 | aom_active_map_t *const map = va_arg(args, aom_active_map_t *); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1401 | |
| 1402 | if (map) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1403 | if (!av1_get_active_map(ctx->cpi, map->active_map, (int)map->rows, |
| 1404 | (int)map->cols)) |
| 1405 | return AOM_CODEC_OK; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1406 | else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1407 | return AOM_CODEC_INVALID_PARAM; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1408 | } else { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1409 | return AOM_CODEC_INVALID_PARAM; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1410 | } |
| 1411 | } |
| 1412 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1413 | static aom_codec_err_t ctrl_set_scale_mode(aom_codec_alg_priv_t *ctx, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1414 | va_list args) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1415 | aom_scaling_mode_t *const mode = va_arg(args, aom_scaling_mode_t *); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1416 | |
| 1417 | if (mode) { |
| 1418 | const int res = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1419 | av1_set_internal_size(ctx->cpi, (AOM_SCALING)mode->h_scaling_mode, |
| 1420 | (AOM_SCALING)mode->v_scaling_mode); |
| 1421 | return (res == 0) ? AOM_CODEC_OK : AOM_CODEC_INVALID_PARAM; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1422 | } else { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1423 | return AOM_CODEC_INVALID_PARAM; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1424 | } |
| 1425 | } |
| 1426 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1427 | static aom_codec_err_t ctrl_set_tune_content(aom_codec_alg_priv_t *ctx, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1428 | va_list args) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1429 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
| 1430 | extra_cfg.content = CAST(AV1E_SET_TUNE_CONTENT, args); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1431 | return update_extra_cfg(ctx, &extra_cfg); |
| 1432 | } |
| 1433 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1434 | static aom_codec_err_t ctrl_set_color_space(aom_codec_alg_priv_t *ctx, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1435 | va_list args) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1436 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
| 1437 | extra_cfg.color_space = CAST(AV1E_SET_COLOR_SPACE, args); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1438 | return update_extra_cfg(ctx, &extra_cfg); |
| 1439 | } |
| 1440 | |
anorkin | 76fb126 | 2017-03-22 15:12:12 -0700 | [diff] [blame^] | 1441 | #if CONFIG_COLORSPACE_HEADERS |
| 1442 | static aom_codec_err_t ctrl_set_transfer_function(aom_codec_alg_priv_t *ctx, |
| 1443 | va_list args) { |
| 1444 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
| 1445 | extra_cfg.transfer_function = CAST(AV1E_SET_TRANSFER_FUNCTION, args); |
| 1446 | return update_extra_cfg(ctx, &extra_cfg); |
| 1447 | } |
| 1448 | |
| 1449 | static aom_codec_err_t ctrl_set_chroma_sample_position( |
| 1450 | aom_codec_alg_priv_t *ctx, va_list args) { |
| 1451 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
| 1452 | extra_cfg.chroma_sample_position = |
| 1453 | CAST(AV1E_SET_CHROMA_SAMPLE_POSITION, args); |
| 1454 | return update_extra_cfg(ctx, &extra_cfg); |
| 1455 | } |
| 1456 | #endif |
| 1457 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1458 | static aom_codec_err_t ctrl_set_color_range(aom_codec_alg_priv_t *ctx, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1459 | va_list args) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1460 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
| 1461 | extra_cfg.color_range = CAST(AV1E_SET_COLOR_RANGE, args); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1462 | return update_extra_cfg(ctx, &extra_cfg); |
| 1463 | } |
| 1464 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1465 | static aom_codec_err_t ctrl_set_render_size(aom_codec_alg_priv_t *ctx, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1466 | va_list args) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1467 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1468 | int *const render_size = va_arg(args, int *); |
| 1469 | extra_cfg.render_width = render_size[0]; |
| 1470 | extra_cfg.render_height = render_size[1]; |
| 1471 | return update_extra_cfg(ctx, &extra_cfg); |
| 1472 | } |
| 1473 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1474 | static aom_codec_err_t ctrl_set_superblock_size(aom_codec_alg_priv_t *ctx, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1475 | va_list args) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1476 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
| 1477 | extra_cfg.superblock_size = CAST(AV1E_SET_SUPERBLOCK_SIZE, args); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1478 | return update_extra_cfg(ctx, &extra_cfg); |
| 1479 | } |
| 1480 | |
Alex Converse | eb780e7 | 2016-12-13 12:46:41 -0800 | [diff] [blame] | 1481 | #if CONFIG_ANS && ANS_MAX_SYMBOLS |
| 1482 | static aom_codec_err_t ctrl_set_ans_window_size_log2(aom_codec_alg_priv_t *ctx, |
| 1483 | va_list args) { |
| 1484 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
| 1485 | extra_cfg.ans_window_size_log2 = CAST(AV1E_SET_ANS_WINDOW_SIZE_LOG2, args); |
| 1486 | return update_extra_cfg(ctx, &extra_cfg); |
| 1487 | } |
| 1488 | #endif |
| 1489 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1490 | static aom_codec_ctrl_fn_map_t encoder_ctrl_maps[] = { |
| 1491 | { AOM_COPY_REFERENCE, ctrl_copy_reference }, |
| 1492 | { AOME_USE_REFERENCE, ctrl_use_reference }, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1493 | |
| 1494 | // Setters |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1495 | { AOM_SET_REFERENCE, ctrl_set_reference }, |
| 1496 | { AOM_SET_POSTPROC, ctrl_set_previewpp }, |
| 1497 | { AOME_SET_ROI_MAP, ctrl_set_roi_map }, |
| 1498 | { AOME_SET_ACTIVEMAP, ctrl_set_active_map }, |
| 1499 | { AOME_SET_SCALEMODE, ctrl_set_scale_mode }, |
| 1500 | { AOME_SET_CPUUSED, ctrl_set_cpuused }, |
| 1501 | { AOME_SET_ENABLEAUTOALTREF, ctrl_set_enable_auto_alt_ref }, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1502 | #if CONFIG_EXT_REFS |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1503 | { AOME_SET_ENABLEAUTOBWDREF, ctrl_set_enable_auto_bwd_ref }, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1504 | #endif // CONFIG_EXT_REFS |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1505 | { AOME_SET_SHARPNESS, ctrl_set_sharpness }, |
| 1506 | { AOME_SET_STATIC_THRESHOLD, ctrl_set_static_thresh }, |
| 1507 | { AV1E_SET_TILE_COLUMNS, ctrl_set_tile_columns }, |
| 1508 | { AV1E_SET_TILE_ROWS, ctrl_set_tile_rows }, |
Fangwen Fu | 7b9f2b3 | 2017-01-17 14:01:52 -0800 | [diff] [blame] | 1509 | #if CONFIG_DEPENDENT_HORZTILES |
| 1510 | { AV1E_SET_TILE_DEPENDENT_ROWS, ctrl_set_tile_dependent_rows }, |
| 1511 | #endif |
Ryan Lei | 9b02b0e | 2017-01-30 15:52:20 -0800 | [diff] [blame] | 1512 | #if CONFIG_LOOPFILTERING_ACROSS_TILES |
Ryan Lei | 7386eda | 2016-12-08 21:08:31 -0800 | [diff] [blame] | 1513 | { AV1E_SET_TILE_LOOPFILTER, ctrl_set_tile_loopfilter }, |
Ryan Lei | 9b02b0e | 2017-01-30 15:52:20 -0800 | [diff] [blame] | 1514 | #endif // CONFIG_LOOPFILTERING_ACROSS_TILES |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1515 | { AOME_SET_ARNR_MAXFRAMES, ctrl_set_arnr_max_frames }, |
| 1516 | { AOME_SET_ARNR_STRENGTH, ctrl_set_arnr_strength }, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1517 | { AOME_SET_TUNING, ctrl_set_tuning }, |
| 1518 | { AOME_SET_CQ_LEVEL, ctrl_set_cq_level }, |
| 1519 | { AOME_SET_MAX_INTRA_BITRATE_PCT, ctrl_set_rc_max_intra_bitrate_pct }, |
| 1520 | { AV1E_SET_MAX_INTER_BITRATE_PCT, ctrl_set_rc_max_inter_bitrate_pct }, |
| 1521 | { AV1E_SET_GF_CBR_BOOST_PCT, ctrl_set_rc_gf_cbr_boost_pct }, |
| 1522 | { AV1E_SET_LOSSLESS, ctrl_set_lossless }, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1523 | #if CONFIG_AOM_QM |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1524 | { AV1E_SET_ENABLE_QM, ctrl_set_enable_qm }, |
| 1525 | { AV1E_SET_QM_MIN, ctrl_set_qm_min }, |
| 1526 | { AV1E_SET_QM_MAX, ctrl_set_qm_max }, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1527 | #endif |
Thomas Davies | af6df17 | 2016-11-09 14:04:18 +0000 | [diff] [blame] | 1528 | #if CONFIG_TILE_GROUPS |
| 1529 | { AV1E_SET_NUM_TG, ctrl_set_num_tg }, |
| 1530 | { AV1E_SET_MTU, ctrl_set_mtu }, |
| 1531 | #endif |
Fangwen Fu | 8d164de | 2016-12-14 13:40:54 -0800 | [diff] [blame] | 1532 | #if CONFIG_TEMPMV_SIGNALING |
| 1533 | { AV1E_SET_DISABLE_TEMPMV, ctrl_set_disable_tempmv }, |
| 1534 | #endif |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1535 | { AV1E_SET_FRAME_PARALLEL_DECODING, ctrl_set_frame_parallel_decoding_mode }, |
| 1536 | { AV1E_SET_AQ_MODE, ctrl_set_aq_mode }, |
Fangwen Fu | 6160df2 | 2017-04-24 09:45:51 -0700 | [diff] [blame] | 1537 | #if CONFIG_EXT_DELTA_Q |
| 1538 | { AV1E_SET_DELTAQ_MODE, ctrl_set_deltaq_mode }, |
| 1539 | #endif |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1540 | { AV1E_SET_FRAME_PERIODIC_BOOST, ctrl_set_frame_periodic_boost }, |
| 1541 | { AV1E_SET_TUNE_CONTENT, ctrl_set_tune_content }, |
| 1542 | { AV1E_SET_COLOR_SPACE, ctrl_set_color_space }, |
anorkin | 76fb126 | 2017-03-22 15:12:12 -0700 | [diff] [blame^] | 1543 | #if CONFIG_COLORSPACE_HEADERS |
| 1544 | { AV1E_SET_TRANSFER_FUNCTION, ctrl_set_transfer_function }, |
| 1545 | { AV1E_SET_CHROMA_SAMPLE_POSITION, ctrl_set_chroma_sample_position }, |
| 1546 | #endif |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1547 | { AV1E_SET_COLOR_RANGE, ctrl_set_color_range }, |
| 1548 | { AV1E_SET_NOISE_SENSITIVITY, ctrl_set_noise_sensitivity }, |
| 1549 | { AV1E_SET_MIN_GF_INTERVAL, ctrl_set_min_gf_interval }, |
| 1550 | { AV1E_SET_MAX_GF_INTERVAL, ctrl_set_max_gf_interval }, |
| 1551 | { AV1E_SET_RENDER_SIZE, ctrl_set_render_size }, |
| 1552 | { AV1E_SET_SUPERBLOCK_SIZE, ctrl_set_superblock_size }, |
Alex Converse | eb780e7 | 2016-12-13 12:46:41 -0800 | [diff] [blame] | 1553 | #if CONFIG_ANS && ANS_MAX_SYMBOLS |
| 1554 | { AV1E_SET_ANS_WINDOW_SIZE_LOG2, ctrl_set_ans_window_size_log2 }, |
| 1555 | #endif |
Yunqing Wang | d8cd55f | 2017-02-27 12:16:00 -0800 | [diff] [blame] | 1556 | #if CONFIG_EXT_TILE |
| 1557 | { AV1E_SET_TILE_ENCODING_MODE, ctrl_set_tile_encoding_mode }, |
| 1558 | #endif // CONFIG_EXT_TILE |
Yunqing Wang | ff4fa06 | 2017-04-21 10:56:08 -0700 | [diff] [blame] | 1559 | { AV1E_ENABLE_MOTION_VECTOR_UNIT_TEST, ctrl_enable_motion_vector_unit_test }, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1560 | |
| 1561 | // Getters |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1562 | { AOME_GET_LAST_QUANTIZER, ctrl_get_quantizer }, |
| 1563 | { AOME_GET_LAST_QUANTIZER_64, ctrl_get_quantizer64 }, |
| 1564 | { AV1_GET_REFERENCE, ctrl_get_reference }, |
| 1565 | { AV1E_GET_ACTIVEMAP, ctrl_get_active_map }, |
| 1566 | { AV1_GET_NEW_FRAME_IMAGE, ctrl_get_new_frame_image }, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1567 | |
| 1568 | { -1, NULL }, |
| 1569 | }; |
| 1570 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1571 | static aom_codec_enc_cfg_map_t encoder_usage_cfg_map[] = { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1572 | { 0, |
| 1573 | { |
| 1574 | // NOLINT |
| 1575 | 0, // g_usage |
| 1576 | 8, // g_threads |
| 1577 | 0, // g_profile |
| 1578 | |
| 1579 | 320, // g_width |
| 1580 | 240, // g_height |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1581 | AOM_BITS_8, // g_bit_depth |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1582 | 8, // g_input_bit_depth |
| 1583 | |
| 1584 | { 1, 30 }, // g_timebase |
| 1585 | |
| 1586 | 0, // g_error_resilient |
| 1587 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1588 | AOM_RC_ONE_PASS, // g_pass |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1589 | |
| 1590 | 25, // g_lag_in_frames |
| 1591 | |
| 1592 | 0, // rc_dropframe_thresh |
| 1593 | 0, // rc_resize_allowed |
| 1594 | 0, // rc_scaled_width |
| 1595 | 0, // rc_scaled_height |
| 1596 | 60, // rc_resize_down_thresold |
| 1597 | 30, // rc_resize_up_thresold |
| 1598 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1599 | AOM_VBR, // rc_end_usage |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1600 | { 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 Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1617 | AOM_KF_AUTO, // g_kfmode |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1618 | 0, // kf_min_dist |
| 1619 | 9999, // kf_max_dist |
| 1620 | } }, |
| 1621 | }; |
| 1622 | |
| 1623 | #ifndef VERSION_STRING |
| 1624 | #define VERSION_STRING |
| 1625 | #endif |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1626 | CODEC_INTERFACE(aom_codec_av1_cx) = { |
| 1627 | "AOMedia Project AV1 Encoder" VERSION_STRING, |
| 1628 | AOM_CODEC_INTERNAL_ABI_VERSION, |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 1629 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1630 | AOM_CODEC_CAP_HIGHBITDEPTH | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1631 | #endif |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1632 | 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 Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1636 | { |
| 1637 | // NOLINT |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1638 | 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 Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1643 | }, |
| 1644 | { |
| 1645 | // NOLINT |
| 1646 | 1, // 1 cfg map |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1647 | 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 Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1654 | } |
| 1655 | }; |