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