/src/aom/av1/av1_cx_iface.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright (c) 2016, Alliance for Open Media. All rights reserved. |
3 | | * |
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. |
10 | | */ |
11 | | #include <limits.h> |
12 | | #include <math.h> |
13 | | #include <stdbool.h> |
14 | | #include <stdint.h> |
15 | | #include <stdlib.h> |
16 | | #include <string.h> |
17 | | |
18 | | #include "config/aom_config.h" |
19 | | #include "config/aom_version.h" |
20 | | |
21 | | #include "aom/aomcx.h" |
22 | | #include "aom/aom_encoder.h" |
23 | | #include "aom/aom_external_partition.h" |
24 | | #include "aom/aom_image.h" |
25 | | #include "aom/internal/aom_codec_internal.h" |
26 | | #include "aom_dsp/flow_estimation/flow_estimation.h" |
27 | | #include "aom_mem/aom_mem.h" |
28 | | #include "aom_scale/yv12config.h" |
29 | | #include "aom_util/aom_pthread.h" |
30 | | |
31 | | #include "av1/av1_cx_iface.h" |
32 | | #include "av1/av1_iface_common.h" |
33 | | #include "av1/common/av1_common_int.h" |
34 | | #include "av1/common/enums.h" |
35 | | #include "av1/common/scale.h" |
36 | | #include "av1/encoder/bitstream.h" |
37 | | #include "av1/encoder/enc_enums.h" |
38 | | #include "av1/encoder/encoder.h" |
39 | | #include "av1/encoder/encoder_alloc.h" |
40 | | #include "av1/encoder/encoder_utils.h" |
41 | | #include "av1/encoder/ethread.h" |
42 | | #include "av1/encoder/external_partition.h" |
43 | | #include "av1/encoder/firstpass.h" |
44 | | #include "av1/encoder/lookahead.h" |
45 | | #include "av1/encoder/rc_utils.h" |
46 | | #include "av1/arg_defs.h" |
47 | | |
48 | | #include "common/args_helper.h" |
49 | | |
50 | | struct av1_extracfg { |
51 | | int cpu_used; |
52 | | unsigned int enable_auto_alt_ref; |
53 | | unsigned int enable_auto_bwd_ref; |
54 | | unsigned int noise_sensitivity; |
55 | | unsigned int sharpness; |
56 | | unsigned int static_thresh; |
57 | | unsigned int row_mt; |
58 | | unsigned int fp_mt; |
59 | | unsigned int tile_columns; // log2 number of tile columns |
60 | | unsigned int tile_rows; // log2 number of tile rows |
61 | | unsigned int auto_tiles; |
62 | | unsigned int enable_tpl_model; |
63 | | unsigned int enable_keyframe_filtering; |
64 | | unsigned int arnr_max_frames; |
65 | | unsigned int arnr_strength; |
66 | | unsigned int min_gf_interval; |
67 | | unsigned int max_gf_interval; |
68 | | unsigned int gf_min_pyr_height; |
69 | | unsigned int gf_max_pyr_height; |
70 | | aom_tune_metric tuning; |
71 | | const char *vmaf_model_path; |
72 | | const char *partition_info_path; |
73 | | unsigned int enable_rate_guide_deltaq; |
74 | | const char *rate_distribution_info; |
75 | | aom_dist_metric dist_metric; |
76 | | unsigned int cq_level; // constrained quality level |
77 | | unsigned int rc_max_intra_bitrate_pct; |
78 | | unsigned int rc_max_inter_bitrate_pct; |
79 | | unsigned int gf_cbr_boost_pct; |
80 | | unsigned int lossless; |
81 | | unsigned int enable_cdef; |
82 | | unsigned int enable_restoration; |
83 | | unsigned int force_video_mode; |
84 | | unsigned int enable_obmc; |
85 | | unsigned int disable_trellis_quant; |
86 | | unsigned int enable_qm; |
87 | | unsigned int qm_y; |
88 | | unsigned int qm_u; |
89 | | unsigned int qm_v; |
90 | | unsigned int qm_min; |
91 | | unsigned int qm_max; |
92 | | unsigned int num_tg; |
93 | | unsigned int mtu_size; |
94 | | |
95 | | aom_timing_info_type_t timing_info_type; |
96 | | unsigned int frame_parallel_decoding_mode; |
97 | | int enable_dual_filter; |
98 | | unsigned int enable_chroma_deltaq; |
99 | | AQ_MODE aq_mode; |
100 | | DELTAQ_MODE deltaq_mode; |
101 | | int deltaq_strength; |
102 | | int deltalf_mode; |
103 | | unsigned int frame_periodic_boost; |
104 | | aom_tune_content content; |
105 | | aom_color_primaries_t color_primaries; |
106 | | aom_transfer_characteristics_t transfer_characteristics; |
107 | | aom_matrix_coefficients_t matrix_coefficients; |
108 | | aom_chroma_sample_position_t chroma_sample_position; |
109 | | int color_range; |
110 | | int render_width; |
111 | | int render_height; |
112 | | aom_superblock_size_t superblock_size; |
113 | | unsigned int single_tile_decoding; |
114 | | int error_resilient_mode; |
115 | | int s_frame_mode; |
116 | | |
117 | | int film_grain_test_vector; |
118 | | const char *film_grain_table_filename; |
119 | | unsigned int motion_vector_unit_test; |
120 | | #if CONFIG_FPMT_TEST |
121 | | unsigned int fpmt_unit_test; |
122 | | #endif |
123 | | unsigned int cdf_update_mode; |
124 | | int enable_rect_partitions; // enable rectangular partitions for sequence |
125 | | int enable_ab_partitions; // enable AB partitions for sequence |
126 | | int enable_1to4_partitions; // enable 1:4 and 4:1 partitions for sequence |
127 | | int min_partition_size; // min partition size [4,8,16,32,64,128] |
128 | | int max_partition_size; // max partition size [4,8,16,32,64,128] |
129 | | int enable_intra_edge_filter; // enable intra-edge filter for sequence |
130 | | int enable_order_hint; // enable order hint for sequence |
131 | | int enable_tx64; // enable 64-pt transform usage for sequence |
132 | | int enable_flip_idtx; // enable flip and identity transform types |
133 | | int enable_rect_tx; // enable rectangular transform usage for sequence |
134 | | int enable_dist_wtd_comp; // enable dist wtd compound for sequence |
135 | | int max_reference_frames; // maximum number of references per frame |
136 | | int enable_reduced_reference_set; // enable reduced set of references |
137 | | int enable_ref_frame_mvs; // sequence level |
138 | | int allow_ref_frame_mvs; // frame level |
139 | | int enable_masked_comp; // enable masked compound for sequence |
140 | | int enable_onesided_comp; // enable one sided compound for sequence |
141 | | int enable_interintra_comp; // enable interintra compound for sequence |
142 | | int enable_smooth_interintra; // enable smooth interintra mode usage |
143 | | int enable_diff_wtd_comp; // enable diff-wtd compound usage |
144 | | int enable_interinter_wedge; // enable interinter-wedge compound usage |
145 | | int enable_interintra_wedge; // enable interintra-wedge compound usage |
146 | | int enable_global_motion; // enable global motion usage for sequence |
147 | | int enable_warped_motion; // sequence level |
148 | | int allow_warped_motion; // frame level |
149 | | int enable_filter_intra; // enable filter intra for sequence |
150 | | int enable_smooth_intra; // enable smooth intra modes for sequence |
151 | | int enable_paeth_intra; // enable Paeth intra mode for sequence |
152 | | int enable_cfl_intra; // enable CFL uv intra mode for sequence |
153 | | int enable_directional_intra; // enable directional modes for sequence |
154 | | int enable_diagonal_intra; // enable D45 to D203 intra modes for sequence |
155 | | int enable_superres; |
156 | | int enable_overlay; // enable overlay for filtered arf frames |
157 | | int enable_palette; |
158 | | int enable_intrabc; |
159 | | int enable_angle_delta; |
160 | | #if CONFIG_DENOISE |
161 | | float noise_level; |
162 | | int noise_block_size; |
163 | | int enable_dnl_denoising; |
164 | | #endif |
165 | | |
166 | | unsigned int chroma_subsampling_x; |
167 | | unsigned int chroma_subsampling_y; |
168 | | int reduced_tx_type_set; |
169 | | int use_intra_dct_only; |
170 | | int use_inter_dct_only; |
171 | | int use_intra_default_tx_only; |
172 | | int enable_tx_size_search; |
173 | | int quant_b_adapt; |
174 | | unsigned int vbr_corpus_complexity_lap; |
175 | | AV1_LEVEL target_seq_level_idx[MAX_NUM_OPERATING_POINTS]; |
176 | | // Bit mask to specify which tier each of the 32 possible operating points |
177 | | // conforms to. |
178 | | unsigned int tier_mask; |
179 | | // min_cr / 100 is the target minimum compression ratio for each frame. |
180 | | unsigned int min_cr; |
181 | | COST_UPDATE_TYPE coeff_cost_upd_freq; |
182 | | COST_UPDATE_TYPE mode_cost_upd_freq; |
183 | | COST_UPDATE_TYPE mv_cost_upd_freq; |
184 | | COST_UPDATE_TYPE dv_cost_upd_freq; |
185 | | unsigned int ext_tile_debug; |
186 | | unsigned int sb_multipass_unit_test; |
187 | | // Total number of passes. If this number is -1, then we assume passes = 1 or |
188 | | // 2 (passes = 1 if pass == AOM_RC_ONE_PASS and passes = 2 otherwise). |
189 | | int passes; |
190 | | int fwd_kf_dist; |
191 | | |
192 | | LOOPFILTER_CONTROL loopfilter_control; |
193 | | // Indicates if the application of post-processing filters should be skipped |
194 | | // on reconstructed frame. |
195 | | unsigned int skip_postproc_filtering; |
196 | | // the name of the second pass output file when passes > 2 |
197 | | const char *two_pass_output; |
198 | | const char *second_pass_log; |
199 | | // Automatically determine whether to disable several intra tools |
200 | | // when "--deltaq-mode=3" is true. |
201 | | // Default as 0. |
202 | | // When set to 1, the encoder will analyze the reconstruction quality |
203 | | // as compared to the source image in the preprocessing pass. |
204 | | // If the recontruction quality is considered high enough, we disable |
205 | | // the following intra coding tools, for better encoding speed: |
206 | | // "--enable_smooth_intra", |
207 | | // "--enable_paeth_intra", |
208 | | // "--enable_cfl_intra", |
209 | | // "--enable_diagonal_intra". |
210 | | int auto_intra_tools_off; |
211 | | int strict_level_conformance; |
212 | | int kf_max_pyr_height; |
213 | | int sb_qp_sweep; |
214 | | }; |
215 | | |
216 | | #if !CONFIG_REALTIME_ONLY |
217 | | static const struct av1_extracfg default_extra_cfg = { |
218 | | 0, // cpu_used |
219 | | 1, // enable_auto_alt_ref |
220 | | 0, // enable_auto_bwd_ref |
221 | | 0, // noise_sensitivity |
222 | | 0, // sharpness |
223 | | 0, // static_thresh |
224 | | 1, // row_mt |
225 | | 0, // fp_mt |
226 | | 0, // tile_columns |
227 | | 0, // tile_rows |
228 | | 0, // auto_tiles |
229 | | 1, // enable_tpl_model |
230 | | 1, // enable_keyframe_filtering |
231 | | 7, // arnr_max_frames |
232 | | 5, // arnr_strength |
233 | | 0, // min_gf_interval; 0 -> default decision |
234 | | 0, // max_gf_interval; 0 -> default decision |
235 | | 0, // gf_min_pyr_height |
236 | | 5, // gf_max_pyr_height |
237 | | AOM_TUNE_PSNR, // tuning |
238 | | "/usr/local/share/model/vmaf_v0.6.1.json", // VMAF model path |
239 | | ".", // partition info path |
240 | | 0, // enable rate guide deltaq |
241 | | "./rate_map.txt", // rate distribution input |
242 | | AOM_DIST_METRIC_PSNR, // dist_metric |
243 | | 10, // cq_level |
244 | | 0, // rc_max_intra_bitrate_pct |
245 | | 0, // rc_max_inter_bitrate_pct |
246 | | 0, // gf_cbr_boost_pct |
247 | | 0, // lossless |
248 | | 1, // enable_cdef |
249 | | 1, // enable_restoration |
250 | | 0, // force_video_mode |
251 | | 1, // enable_obmc |
252 | | 3, // disable_trellis_quant |
253 | | 0, // enable_qm |
254 | | DEFAULT_QM_Y, // qm_y |
255 | | DEFAULT_QM_U, // qm_u |
256 | | DEFAULT_QM_V, // qm_v |
257 | | DEFAULT_QM_FIRST, // qm_min |
258 | | DEFAULT_QM_LAST, // qm_max |
259 | | 1, // max number of tile groups |
260 | | 0, // mtu_size |
261 | | AOM_TIMING_UNSPECIFIED, // No picture timing signaling in bitstream |
262 | | 0, // frame_parallel_decoding_mode |
263 | | 1, // enable dual filter |
264 | | 0, // enable delta quant in chroma planes |
265 | | NO_AQ, // aq_mode |
266 | | DELTA_Q_OBJECTIVE, // deltaq_mode |
267 | | 100, // deltaq_strength |
268 | | 0, // delta lf mode |
269 | | 0, // frame_periodic_boost |
270 | | AOM_CONTENT_DEFAULT, // content |
271 | | AOM_CICP_CP_UNSPECIFIED, // CICP color primaries |
272 | | AOM_CICP_TC_UNSPECIFIED, // CICP transfer characteristics |
273 | | AOM_CICP_MC_UNSPECIFIED, // CICP matrix coefficients |
274 | | AOM_CSP_UNKNOWN, // chroma sample position |
275 | | 0, // color range |
276 | | 0, // render width |
277 | | 0, // render height |
278 | | AOM_SUPERBLOCK_SIZE_DYNAMIC, // superblock_size |
279 | | 1, // this depends on large_scale_tile. |
280 | | 0, // error_resilient_mode off by default. |
281 | | 0, // s_frame_mode off by default. |
282 | | 0, // film_grain_test_vector |
283 | | NULL, // film_grain_table_filename |
284 | | 0, // motion_vector_unit_test |
285 | | #if CONFIG_FPMT_TEST |
286 | | 0, // fpmt_unit_test |
287 | | #endif |
288 | | 1, // CDF update mode |
289 | | 1, // enable rectangular partitions |
290 | | 1, // enable ab shape partitions |
291 | | 1, // enable 1:4 and 4:1 partitions |
292 | | 4, // min_partition_size |
293 | | 128, // max_partition_size |
294 | | 1, // enable intra edge filter |
295 | | 1, // frame order hint |
296 | | 1, // enable 64-pt transform usage |
297 | | 1, // enable flip and identity transform |
298 | | 1, // enable rectangular transform usage |
299 | | 1, // dist-wtd compound |
300 | | 7, // max_reference_frames |
301 | | 0, // enable_reduced_reference_set |
302 | | 1, // enable_ref_frame_mvs sequence level |
303 | | 1, // allow ref_frame_mvs frame level |
304 | | 1, // enable masked compound at sequence level |
305 | | 1, // enable one sided compound at sequence level |
306 | | 1, // enable interintra compound at sequence level |
307 | | 1, // enable smooth interintra mode |
308 | | 1, // enable difference-weighted compound |
309 | | 1, // enable interinter wedge compound |
310 | | 1, // enable interintra wedge compound |
311 | | 1, // enable_global_motion usage |
312 | | 1, // enable_warped_motion at sequence level |
313 | | 1, // allow_warped_motion at frame level |
314 | | 1, // enable filter intra at sequence level |
315 | | 1, // enable smooth intra modes usage for sequence |
316 | | 1, // enable Paeth intra mode usage for sequence |
317 | | 1, // enable CFL uv intra mode usage for sequence |
318 | | 1, // enable directional intra mode usage for sequence |
319 | | 1, // enable D45 to D203 intra mode usage for sequence |
320 | | 1, // superres |
321 | | 1, // enable overlay |
322 | | 1, // enable palette |
323 | | 1, // enable intrabc |
324 | | 1, // enable angle delta |
325 | | #if CONFIG_DENOISE |
326 | | 0, // noise_level |
327 | | 32, // noise_block_size |
328 | | 1, // enable_dnl_denoising |
329 | | #endif |
330 | | 0, // chroma_subsampling_x |
331 | | 0, // chroma_subsampling_y |
332 | | 0, // reduced_tx_type_set |
333 | | 0, // use_intra_dct_only |
334 | | 0, // use_inter_dct_only |
335 | | 0, // use_intra_default_tx_only |
336 | | 1, // enable_tx_size_search |
337 | | 0, // quant_b_adapt |
338 | | 0, // vbr_corpus_complexity_lap |
339 | | { |
340 | | SEQ_LEVEL_MAX, SEQ_LEVEL_MAX, SEQ_LEVEL_MAX, SEQ_LEVEL_MAX, SEQ_LEVEL_MAX, |
341 | | SEQ_LEVEL_MAX, SEQ_LEVEL_MAX, SEQ_LEVEL_MAX, SEQ_LEVEL_MAX, SEQ_LEVEL_MAX, |
342 | | SEQ_LEVEL_MAX, SEQ_LEVEL_MAX, SEQ_LEVEL_MAX, SEQ_LEVEL_MAX, SEQ_LEVEL_MAX, |
343 | | SEQ_LEVEL_MAX, SEQ_LEVEL_MAX, SEQ_LEVEL_MAX, SEQ_LEVEL_MAX, SEQ_LEVEL_MAX, |
344 | | SEQ_LEVEL_MAX, SEQ_LEVEL_MAX, SEQ_LEVEL_MAX, SEQ_LEVEL_MAX, SEQ_LEVEL_MAX, |
345 | | SEQ_LEVEL_MAX, SEQ_LEVEL_MAX, SEQ_LEVEL_MAX, SEQ_LEVEL_MAX, SEQ_LEVEL_MAX, |
346 | | SEQ_LEVEL_MAX, SEQ_LEVEL_MAX, |
347 | | }, // target_seq_level_idx |
348 | | 0, // tier_mask |
349 | | 0, // min_cr |
350 | | COST_UPD_SB, // coeff_cost_upd_freq |
351 | | COST_UPD_SB, // mode_cost_upd_freq |
352 | | COST_UPD_SB, // mv_cost_upd_freq |
353 | | COST_UPD_SB, // dv_cost_upd_freq |
354 | | 0, // ext_tile_debug |
355 | | 0, // sb_multipass_unit_test |
356 | | -1, // passes |
357 | | -1, // fwd_kf_dist |
358 | | LOOPFILTER_ALL, // loopfilter_control |
359 | | 0, // skip_postproc_filtering |
360 | | NULL, // two_pass_output |
361 | | NULL, // second_pass_log |
362 | | 0, // auto_intra_tools_off |
363 | | 0, // strict_level_conformance |
364 | | -1, // kf_max_pyr_height |
365 | | 0, // sb_qp_sweep |
366 | | }; |
367 | | #else |
368 | | // Some settings are changed for realtime only build. |
369 | | static const struct av1_extracfg default_extra_cfg = { |
370 | | 10, // cpu_used |
371 | | 1, // enable_auto_alt_ref |
372 | | 0, // enable_auto_bwd_ref |
373 | | 0, // noise_sensitivity |
374 | | 0, // sharpness |
375 | | 0, // static_thresh |
376 | | 1, // row_mt |
377 | | 0, // fp_mt |
378 | | 0, // tile_columns |
379 | | 0, // tile_rows |
380 | | 0, // auto_tiles |
381 | | 0, // enable_tpl_model |
382 | | 0, // enable_keyframe_filtering |
383 | | 7, // arnr_max_frames |
384 | | 5, // arnr_strength |
385 | | 0, // min_gf_interval; 0 -> default decision |
386 | | 0, // max_gf_interval; 0 -> default decision |
387 | | 0, // gf_min_pyr_height |
388 | | 5, // gf_max_pyr_height |
389 | | AOM_TUNE_PSNR, // tuning |
390 | | "/usr/local/share/model/vmaf_v0.6.1.json", // VMAF model path |
391 | | ".", // partition info path |
392 | | 0, // enable rate guide deltaq |
393 | | "./rate_map.txt", // rate distribution input |
394 | | AOM_DIST_METRIC_PSNR, // dist_metric |
395 | | 10, // cq_level |
396 | | 300, // rc_max_intra_bitrate_pct |
397 | | 0, // rc_max_inter_bitrate_pct |
398 | | 0, // gf_cbr_boost_pct |
399 | | 0, // lossless |
400 | | 1, // enable_cdef |
401 | | 0, // enable_restoration |
402 | | 0, // force_video_mode |
403 | | 0, // enable_obmc |
404 | | 3, // disable_trellis_quant |
405 | | 0, // enable_qm |
406 | | DEFAULT_QM_Y, // qm_y |
407 | | DEFAULT_QM_U, // qm_u |
408 | | DEFAULT_QM_V, // qm_v |
409 | | DEFAULT_QM_FIRST, // qm_min |
410 | | DEFAULT_QM_LAST, // qm_max |
411 | | 1, // max number of tile groups |
412 | | 0, // mtu_size |
413 | | AOM_TIMING_UNSPECIFIED, // No picture timing signaling in bitstream |
414 | | 0, // frame_parallel_decoding_mode |
415 | | 0, // enable dual filter |
416 | | 0, // enable delta quant in chroma planes |
417 | | CYCLIC_REFRESH_AQ, // aq_mode |
418 | | NO_DELTA_Q, // deltaq_mode |
419 | | 100, // deltaq_strength |
420 | | 0, // delta lf mode |
421 | | 0, // frame_periodic_boost |
422 | | AOM_CONTENT_DEFAULT, // content |
423 | | AOM_CICP_CP_UNSPECIFIED, // CICP color primaries |
424 | | AOM_CICP_TC_UNSPECIFIED, // CICP transfer characteristics |
425 | | AOM_CICP_MC_UNSPECIFIED, // CICP matrix coefficients |
426 | | AOM_CSP_UNKNOWN, // chroma sample position |
427 | | 0, // color range |
428 | | 0, // render width |
429 | | 0, // render height |
430 | | AOM_SUPERBLOCK_SIZE_DYNAMIC, // superblock_size |
431 | | 1, // this depends on large_scale_tile. |
432 | | 0, // error_resilient_mode off by default. |
433 | | 0, // s_frame_mode off by default. |
434 | | 0, // film_grain_test_vector |
435 | | NULL, // film_grain_table_filename |
436 | | 0, // motion_vector_unit_test |
437 | | #if CONFIG_FPMT_TEST |
438 | | 0, // fpmt_unit_test |
439 | | #endif |
440 | | 1, // CDF update mode |
441 | | 0, // enable rectangular partitions |
442 | | 0, // enable ab shape partitions |
443 | | 0, // enable 1:4 and 4:1 partitions |
444 | | 4, // min_partition_size |
445 | | 128, // max_partition_size |
446 | | 0, // enable intra edge filter |
447 | | 0, // frame order hint |
448 | | 0, // enable 64-pt transform usage |
449 | | 1, // enable flip and identity transform |
450 | | 1, // enable rectangular transform usage |
451 | | 0, // dist-wtd compound |
452 | | 3, // max_reference_frames |
453 | | 0, // enable_reduced_reference_set |
454 | | 0, // enable_ref_frame_mvs sequence level |
455 | | 0, // allow ref_frame_mvs frame level |
456 | | 0, // enable masked compound at sequence level |
457 | | 0, // enable one sided compound at sequence level |
458 | | 0, // enable interintra compound at sequence level |
459 | | 0, // enable smooth interintra mode |
460 | | 0, // enable difference-weighted compound |
461 | | 0, // enable interinter wedge compound |
462 | | 0, // enable interintra wedge compound |
463 | | 0, // enable_global_motion usage |
464 | | 0, // enable_warped_motion at sequence level |
465 | | 0, // allow_warped_motion at frame level |
466 | | 0, // enable filter intra at sequence level |
467 | | 0, // enable smooth intra modes usage for sequence |
468 | | 0, // enable Paeth intra mode usage for sequence |
469 | | 0, // enable CFL uv intra mode usage for sequence |
470 | | 1, // enable directional intra mode usage for sequence |
471 | | 1, // enable D45 to D203 intra mode usage for sequence |
472 | | 0, // superres |
473 | | 0, // enable overlay |
474 | | 1, // enable palette |
475 | | 0, // enable intrabc |
476 | | 0, // enable angle delta |
477 | | #if CONFIG_DENOISE |
478 | | 0, // noise_level |
479 | | 32, // noise_block_size |
480 | | 1, // enable_dnl_denoising |
481 | | #endif |
482 | | 0, // chroma_subsampling_x |
483 | | 0, // chroma_subsampling_y |
484 | | 0, // reduced_tx_type_set |
485 | | 0, // use_intra_dct_only |
486 | | 0, // use_inter_dct_only |
487 | | 1, // use_intra_default_tx_only |
488 | | 1, // enable_tx_size_search |
489 | | 0, // quant_b_adapt |
490 | | 0, // vbr_corpus_complexity_lap |
491 | | { |
492 | | SEQ_LEVEL_MAX, SEQ_LEVEL_MAX, SEQ_LEVEL_MAX, SEQ_LEVEL_MAX, SEQ_LEVEL_MAX, |
493 | | SEQ_LEVEL_MAX, SEQ_LEVEL_MAX, SEQ_LEVEL_MAX, SEQ_LEVEL_MAX, SEQ_LEVEL_MAX, |
494 | | SEQ_LEVEL_MAX, SEQ_LEVEL_MAX, SEQ_LEVEL_MAX, SEQ_LEVEL_MAX, SEQ_LEVEL_MAX, |
495 | | SEQ_LEVEL_MAX, SEQ_LEVEL_MAX, SEQ_LEVEL_MAX, SEQ_LEVEL_MAX, SEQ_LEVEL_MAX, |
496 | | SEQ_LEVEL_MAX, SEQ_LEVEL_MAX, SEQ_LEVEL_MAX, SEQ_LEVEL_MAX, SEQ_LEVEL_MAX, |
497 | | SEQ_LEVEL_MAX, SEQ_LEVEL_MAX, SEQ_LEVEL_MAX, SEQ_LEVEL_MAX, SEQ_LEVEL_MAX, |
498 | | SEQ_LEVEL_MAX, SEQ_LEVEL_MAX, |
499 | | }, // target_seq_level_idx |
500 | | 0, // tier_mask |
501 | | 0, // min_cr |
502 | | COST_UPD_OFF, // coeff_cost_upd_freq |
503 | | COST_UPD_OFF, // mode_cost_upd_freq |
504 | | COST_UPD_OFF, // mv_cost_upd_freq |
505 | | COST_UPD_OFF, // dv_cost_upd_freq |
506 | | 0, // ext_tile_debug |
507 | | 0, // sb_multipass_unit_test |
508 | | -1, // passes |
509 | | -1, // fwd_kf_dist |
510 | | LOOPFILTER_ALL, // loopfilter_control |
511 | | 0, // skip_postproc_filtering |
512 | | NULL, // two_pass_output |
513 | | NULL, // second_pass_log |
514 | | 0, // auto_intra_tools_off |
515 | | 0, // strict_level_conformance |
516 | | -1, // kf_max_pyr_height |
517 | | 0, // sb_qp_sweep |
518 | | }; |
519 | | #endif |
520 | | |
521 | | struct aom_codec_alg_priv { |
522 | | aom_codec_priv_t base; |
523 | | aom_codec_enc_cfg_t cfg; |
524 | | struct av1_extracfg extra_cfg; |
525 | | aom_rational64_t timestamp_ratio; |
526 | | aom_codec_pts_t pts_offset; |
527 | | unsigned char pts_offset_initialized; |
528 | | AV1EncoderConfig oxcf; |
529 | | AV1_PRIMARY *ppi; |
530 | | unsigned char *cx_data; |
531 | | size_t cx_data_sz; |
532 | | size_t pending_cx_data_sz; |
533 | | aom_image_t preview_img; |
534 | | aom_enc_frame_flags_t next_frame_flags; |
535 | | aom_codec_pkt_list_decl(256) pkt_list; |
536 | | unsigned int fixed_kf_cntr; |
537 | | // BufferPool that holds all reference frames. |
538 | | BufferPool *buffer_pool; |
539 | | |
540 | | // lookahead instance variables |
541 | | BufferPool *buffer_pool_lap; |
542 | | FIRSTPASS_STATS *frame_stats_buffer; |
543 | | // Number of stats buffers required for look ahead |
544 | | int num_lap_buffers; |
545 | | STATS_BUFFER_CTX stats_buf_context; |
546 | | bool monochrome_on_init; |
547 | | }; |
548 | | |
549 | 0 | static inline int gcd(int64_t a, int b) { |
550 | 0 | int remainder; |
551 | 0 | while (b > 0) { |
552 | 0 | remainder = (int)(a % b); |
553 | 0 | a = b; |
554 | 0 | b = remainder; |
555 | 0 | } |
556 | |
|
557 | 0 | return (int)a; |
558 | 0 | } |
559 | | |
560 | 0 | static void reduce_ratio(aom_rational64_t *ratio) { |
561 | 0 | const int denom = gcd(ratio->num, ratio->den); |
562 | 0 | ratio->num /= denom; |
563 | 0 | ratio->den /= denom; |
564 | 0 | } |
565 | | |
566 | | // Called by encoder_encode() only. Must not be called by encoder_init() |
567 | | // because the `error` paramerer will be destroyed by aom_codec_enc_init_ver() |
568 | | // after encoder_init() returns an error. See the "IMPORTANT" comment in |
569 | | // aom_codec_enc_init_ver(). |
570 | | static aom_codec_err_t update_error_state( |
571 | 0 | aom_codec_alg_priv_t *ctx, const struct aom_internal_error_info *error) { |
572 | 0 | const aom_codec_err_t res = error->error_code; |
573 | |
|
574 | 0 | if (res != AOM_CODEC_OK) |
575 | 0 | ctx->base.err_detail = error->has_detail ? error->detail : NULL; |
576 | |
|
577 | 0 | return res; |
578 | 0 | } |
579 | | |
580 | | // This function deep copies a string src to *dst. For default string we will |
581 | | // use a string literal, and otherwise we will allocate memory for the string. |
582 | | static aom_codec_err_t allocate_and_set_string(const char *src, |
583 | | const char *default_src, |
584 | | const char **dst, |
585 | 0 | char *err_detail) { |
586 | 0 | if (!src) { |
587 | 0 | snprintf(err_detail, ARG_ERR_MSG_MAX_LEN, |
588 | 0 | "Null pointer given to a string parameter."); |
589 | 0 | return AOM_CODEC_INVALID_PARAM; |
590 | 0 | } |
591 | 0 | if (*dst && strcmp(src, *dst) == 0) return AOM_CODEC_OK; |
592 | | // If the input is exactly the same as default, we will use the string |
593 | | // literal, so do not free here. |
594 | 0 | if (*dst != default_src) { |
595 | 0 | aom_free((void *)*dst); |
596 | 0 | } |
597 | |
|
598 | 0 | if (default_src && strcmp(src, default_src) == 0) { |
599 | | // default_src should be a string literal |
600 | 0 | *dst = default_src; |
601 | 0 | } else { |
602 | 0 | size_t len = strlen(src) + 1; |
603 | 0 | char *tmp = aom_malloc(len * sizeof(*tmp)); |
604 | 0 | if (!tmp) { |
605 | 0 | snprintf(err_detail, ARG_ERR_MSG_MAX_LEN, |
606 | 0 | "Failed to allocate memory for copying parameters."); |
607 | 0 | return AOM_CODEC_MEM_ERROR; |
608 | 0 | } |
609 | 0 | memcpy(tmp, src, len); |
610 | 0 | *dst = tmp; |
611 | 0 | } |
612 | 0 | return 0; |
613 | 0 | } |
614 | | |
615 | | #undef ERROR |
616 | | #define ERROR(str) \ |
617 | 0 | do { \ |
618 | 0 | ctx->base.err_detail = str; \ |
619 | 0 | return AOM_CODEC_INVALID_PARAM; \ |
620 | 0 | } while (0) |
621 | | |
622 | | #define RANGE_CHECK(p, memb, lo, hi) \ |
623 | 0 | do { \ |
624 | 0 | if (!((p)->memb >= (lo) && (p)->memb <= (hi))) \ |
625 | 0 | ERROR(#memb " out of range [" #lo ".." #hi "]"); \ |
626 | 0 | } while (0) |
627 | | |
628 | | #define RANGE_CHECK_HI(p, memb, hi) \ |
629 | 0 | do { \ |
630 | 0 | if (!((p)->memb <= (hi))) ERROR(#memb " out of range [.." #hi "]"); \ |
631 | 0 | } while (0) |
632 | | |
633 | | #define RANGE_CHECK_BOOL(p, memb) \ |
634 | 0 | do { \ |
635 | 0 | if (!!((p)->memb) != (p)->memb) ERROR(#memb " expected boolean"); \ |
636 | 0 | } while (0) |
637 | | |
638 | | static aom_codec_err_t validate_config(aom_codec_alg_priv_t *ctx, |
639 | | const aom_codec_enc_cfg_t *cfg, |
640 | 0 | const struct av1_extracfg *extra_cfg) { |
641 | 0 | RANGE_CHECK(cfg, g_w, 1, 65536); // 16 bits available |
642 | 0 | RANGE_CHECK(cfg, g_h, 1, 65536); // 16 bits available |
643 | 0 | RANGE_CHECK_HI(cfg, g_forced_max_frame_width, 65536); // 16 bits available |
644 | 0 | RANGE_CHECK_HI(cfg, g_forced_max_frame_height, 65536); // 16 bits available |
645 | 0 | if (cfg->g_forced_max_frame_width) { |
646 | 0 | RANGE_CHECK_HI(cfg, g_w, cfg->g_forced_max_frame_width); |
647 | 0 | } |
648 | 0 | if (cfg->g_forced_max_frame_height) { |
649 | 0 | RANGE_CHECK_HI(cfg, g_h, cfg->g_forced_max_frame_height); |
650 | 0 | } |
651 | | // To avoid integer overflows when multiplying width by height (or values |
652 | | // derived from width and height) using the int type, impose a maximum frame |
653 | | // area (width * height) of 2^30. |
654 | 0 | const unsigned int max_frame_width = |
655 | 0 | cfg->g_forced_max_frame_width ? cfg->g_forced_max_frame_width : cfg->g_w; |
656 | 0 | const unsigned int max_frame_height = cfg->g_forced_max_frame_height |
657 | 0 | ? cfg->g_forced_max_frame_height |
658 | 0 | : cfg->g_h; |
659 | 0 | const int64_t max_frame_area = (int64_t)max_frame_width * max_frame_height; |
660 | 0 | if (max_frame_area > (1 << 30)) { |
661 | 0 | ERROR("max_frame_area out of range [..2^30]"); |
662 | 0 | } |
663 | 0 | RANGE_CHECK(cfg, g_timebase.den, 1, 1000000000); |
664 | 0 | RANGE_CHECK(cfg, g_timebase.num, 1, 1000000000); |
665 | 0 | RANGE_CHECK_HI(cfg, g_profile, MAX_PROFILES - 1); |
666 | | |
667 | 0 | RANGE_CHECK_HI(cfg, rc_target_bitrate, 2000000); |
668 | 0 | RANGE_CHECK_HI(cfg, rc_max_quantizer, 63); |
669 | 0 | RANGE_CHECK_HI(cfg, rc_min_quantizer, cfg->rc_max_quantizer); |
670 | 0 | RANGE_CHECK_BOOL(extra_cfg, lossless); |
671 | 0 | RANGE_CHECK_HI(extra_cfg, aq_mode, AQ_MODE_COUNT - 1); |
672 | 0 | RANGE_CHECK_HI(extra_cfg, deltaq_mode, DELTA_Q_MODE_COUNT - 1); |
673 | | |
674 | 0 | if (cfg->g_usage != ALLINTRA && |
675 | 0 | extra_cfg->deltaq_mode == DELTA_Q_VARIANCE_BOOST) { |
676 | 0 | ERROR("Variance Boost (deltaq_mode = 6) can only be set in all intra mode"); |
677 | 0 | } |
678 | | |
679 | 0 | RANGE_CHECK_HI(extra_cfg, deltalf_mode, 1); |
680 | 0 | RANGE_CHECK_HI(extra_cfg, frame_periodic_boost, 1); |
681 | | #if CONFIG_REALTIME_ONLY |
682 | | RANGE_CHECK(cfg, g_usage, AOM_USAGE_REALTIME, AOM_USAGE_REALTIME); |
683 | | #else |
684 | 0 | RANGE_CHECK_HI(cfg, g_usage, AOM_USAGE_ALL_INTRA); |
685 | 0 | #endif |
686 | 0 | RANGE_CHECK_HI(cfg, g_threads, MAX_NUM_THREADS); |
687 | 0 | RANGE_CHECK(cfg, rc_end_usage, AOM_VBR, AOM_Q); |
688 | 0 | RANGE_CHECK_HI(cfg, rc_undershoot_pct, 100); |
689 | 0 | RANGE_CHECK_HI(cfg, rc_overshoot_pct, 100); |
690 | 0 | RANGE_CHECK_HI(cfg, rc_2pass_vbr_bias_pct, 100); |
691 | 0 | RANGE_CHECK(cfg, kf_mode, AOM_KF_DISABLED, AOM_KF_AUTO); |
692 | 0 | RANGE_CHECK_HI(cfg, rc_dropframe_thresh, 100); |
693 | 0 | RANGE_CHECK(cfg, g_pass, AOM_RC_ONE_PASS, AOM_RC_THIRD_PASS); |
694 | 0 | RANGE_CHECK_HI(cfg, g_lag_in_frames, MAX_LAG_BUFFERS); |
695 | 0 | if (cfg->g_usage == AOM_USAGE_ALL_INTRA) { |
696 | 0 | RANGE_CHECK_HI(cfg, g_lag_in_frames, 0); |
697 | 0 | RANGE_CHECK_HI(cfg, kf_max_dist, 0); |
698 | 0 | } |
699 | 0 | RANGE_CHECK_HI(extra_cfg, min_gf_interval, MAX_LAG_BUFFERS - 1); |
700 | 0 | RANGE_CHECK_HI(extra_cfg, max_gf_interval, MAX_LAG_BUFFERS - 1); |
701 | 0 | if (extra_cfg->max_gf_interval > 0) { |
702 | 0 | RANGE_CHECK(extra_cfg, max_gf_interval, |
703 | 0 | AOMMAX(2, extra_cfg->min_gf_interval), (MAX_LAG_BUFFERS - 1)); |
704 | 0 | } |
705 | 0 | RANGE_CHECK_HI(extra_cfg, gf_min_pyr_height, 5); |
706 | 0 | RANGE_CHECK_HI(extra_cfg, gf_max_pyr_height, 5); |
707 | 0 | if (extra_cfg->gf_min_pyr_height > extra_cfg->gf_max_pyr_height) { |
708 | 0 | ERROR( |
709 | 0 | "gf_min_pyr_height must be less than or equal to " |
710 | 0 | "gf_max_pyramid_height"); |
711 | 0 | } |
712 | | |
713 | 0 | RANGE_CHECK_HI(cfg, rc_resize_mode, RESIZE_MODES - 1); |
714 | 0 | RANGE_CHECK(cfg, rc_resize_denominator, SCALE_NUMERATOR, |
715 | 0 | SCALE_NUMERATOR << 1); |
716 | 0 | RANGE_CHECK(cfg, rc_resize_kf_denominator, SCALE_NUMERATOR, |
717 | 0 | SCALE_NUMERATOR << 1); |
718 | 0 | RANGE_CHECK_HI(cfg, rc_superres_mode, AOM_SUPERRES_AUTO); |
719 | 0 | RANGE_CHECK(cfg, rc_superres_denominator, SCALE_NUMERATOR, |
720 | 0 | SCALE_NUMERATOR << 1); |
721 | 0 | RANGE_CHECK(cfg, rc_superres_kf_denominator, SCALE_NUMERATOR, |
722 | 0 | SCALE_NUMERATOR << 1); |
723 | 0 | RANGE_CHECK(cfg, rc_superres_qthresh, 1, 63); |
724 | 0 | RANGE_CHECK(cfg, rc_superres_kf_qthresh, 1, 63); |
725 | 0 | RANGE_CHECK_HI(extra_cfg, cdf_update_mode, 2); |
726 | | |
727 | 0 | RANGE_CHECK_HI(extra_cfg, motion_vector_unit_test, 2); |
728 | | #if CONFIG_FPMT_TEST |
729 | | RANGE_CHECK_HI(extra_cfg, fpmt_unit_test, 1); |
730 | | #endif |
731 | 0 | RANGE_CHECK_HI(extra_cfg, sb_multipass_unit_test, 1); |
732 | 0 | RANGE_CHECK_HI(extra_cfg, ext_tile_debug, 1); |
733 | 0 | RANGE_CHECK_HI(extra_cfg, enable_auto_alt_ref, 1); |
734 | 0 | RANGE_CHECK_HI(extra_cfg, enable_auto_bwd_ref, 2); |
735 | 0 | RANGE_CHECK(extra_cfg, cpu_used, 0, |
736 | 0 | (cfg->g_usage == AOM_USAGE_REALTIME) ? 11 : 9); |
737 | 0 | RANGE_CHECK_HI(extra_cfg, noise_sensitivity, 6); |
738 | 0 | RANGE_CHECK(extra_cfg, superblock_size, AOM_SUPERBLOCK_SIZE_64X64, |
739 | 0 | AOM_SUPERBLOCK_SIZE_DYNAMIC); |
740 | 0 | RANGE_CHECK_HI(cfg, large_scale_tile, 1); |
741 | 0 | RANGE_CHECK_HI(extra_cfg, single_tile_decoding, 1); |
742 | 0 | RANGE_CHECK_HI(extra_cfg, enable_rate_guide_deltaq, 1); |
743 | | |
744 | 0 | RANGE_CHECK_HI(extra_cfg, row_mt, 1); |
745 | 0 | RANGE_CHECK_HI(extra_cfg, fp_mt, 1); |
746 | | |
747 | 0 | RANGE_CHECK_HI(extra_cfg, tile_columns, 6); |
748 | 0 | RANGE_CHECK_HI(extra_cfg, tile_rows, 6); |
749 | 0 | RANGE_CHECK_HI(extra_cfg, auto_tiles, 1); |
750 | | |
751 | 0 | RANGE_CHECK_HI(cfg, monochrome, 1); |
752 | | |
753 | 0 | if (cfg->large_scale_tile && extra_cfg->aq_mode) |
754 | 0 | ERROR( |
755 | 0 | "Adaptive quantization are not supported in large scale tile " |
756 | 0 | "coding."); |
757 | | |
758 | 0 | RANGE_CHECK_HI(extra_cfg, sharpness, 7); |
759 | 0 | RANGE_CHECK_HI(extra_cfg, arnr_max_frames, 15); |
760 | 0 | RANGE_CHECK_HI(extra_cfg, arnr_strength, 6); |
761 | 0 | RANGE_CHECK_HI(extra_cfg, cq_level, 63); |
762 | 0 | RANGE_CHECK(cfg, g_bit_depth, AOM_BITS_8, AOM_BITS_12); |
763 | 0 | RANGE_CHECK(cfg, g_input_bit_depth, 8, 12); |
764 | 0 | RANGE_CHECK(extra_cfg, content, AOM_CONTENT_DEFAULT, AOM_CONTENT_INVALID - 1); |
765 | | |
766 | 0 | if (cfg->g_pass >= AOM_RC_SECOND_PASS) { |
767 | 0 | const size_t packet_sz = sizeof(FIRSTPASS_STATS); |
768 | 0 | const int n_packets = (int)(cfg->rc_twopass_stats_in.sz / packet_sz); |
769 | 0 | const FIRSTPASS_STATS *stats; |
770 | |
|
771 | 0 | if (cfg->rc_twopass_stats_in.buf == NULL) |
772 | 0 | ERROR("rc_twopass_stats_in.buf not set."); |
773 | | |
774 | 0 | if (cfg->rc_twopass_stats_in.sz % packet_sz) |
775 | 0 | ERROR("rc_twopass_stats_in.sz indicates truncated packet."); |
776 | | |
777 | 0 | if (cfg->rc_twopass_stats_in.sz < 2 * packet_sz) |
778 | 0 | ERROR("rc_twopass_stats_in requires at least two packets."); |
779 | | |
780 | 0 | stats = |
781 | 0 | (const FIRSTPASS_STATS *)cfg->rc_twopass_stats_in.buf + n_packets - 1; |
782 | |
|
783 | 0 | if ((int)(stats->count + 0.5) != n_packets - 1) |
784 | 0 | ERROR("rc_twopass_stats_in missing EOS stats packet"); |
785 | 0 | } |
786 | | |
787 | 0 | if (extra_cfg->passes != -1 && cfg->g_pass == AOM_RC_ONE_PASS && |
788 | 0 | extra_cfg->passes != 1) { |
789 | 0 | ERROR("One pass encoding but passes != 1."); |
790 | 0 | } |
791 | | |
792 | 0 | if (extra_cfg->passes != -1 && (int)cfg->g_pass > extra_cfg->passes) { |
793 | 0 | ERROR("Current pass is larger than total number of passes."); |
794 | 0 | } |
795 | | |
796 | 0 | if (cfg->g_profile == (unsigned int)PROFILE_1 && cfg->monochrome) { |
797 | 0 | ERROR("Monochrome is not supported in profile 1"); |
798 | 0 | } |
799 | | |
800 | 0 | if (cfg->g_profile <= (unsigned int)PROFILE_1 && |
801 | 0 | cfg->g_bit_depth > AOM_BITS_10) { |
802 | 0 | ERROR("Codec bit-depth 12 not supported in profile < 2"); |
803 | 0 | } |
804 | 0 | if (cfg->g_profile <= (unsigned int)PROFILE_1 && |
805 | 0 | cfg->g_input_bit_depth > 10) { |
806 | 0 | ERROR("Source bit-depth 12 not supported in profile < 2"); |
807 | 0 | } |
808 | | |
809 | 0 | if (cfg->rc_end_usage == AOM_Q) { |
810 | 0 | RANGE_CHECK_HI(cfg, use_fixed_qp_offsets, 1); |
811 | 0 | } else { |
812 | 0 | if (cfg->use_fixed_qp_offsets > 0) { |
813 | 0 | ERROR("--use_fixed_qp_offsets can only be used with --end-usage=q"); |
814 | 0 | } |
815 | 0 | } |
816 | | |
817 | 0 | RANGE_CHECK(extra_cfg, color_primaries, AOM_CICP_CP_BT_709, |
818 | 0 | AOM_CICP_CP_EBU_3213); // Need to check range more precisely to |
819 | | // check for reserved values? |
820 | 0 | RANGE_CHECK(extra_cfg, transfer_characteristics, AOM_CICP_TC_BT_709, |
821 | 0 | AOM_CICP_TC_HLG); |
822 | 0 | RANGE_CHECK(extra_cfg, matrix_coefficients, AOM_CICP_MC_IDENTITY, |
823 | 0 | AOM_CICP_MC_ICTCP); |
824 | 0 | RANGE_CHECK(extra_cfg, color_range, 0, 1); |
825 | | |
826 | | /* Average corpus complexity is supported only in the case of single pass |
827 | | * VBR*/ |
828 | 0 | if (cfg->g_pass == AOM_RC_ONE_PASS && cfg->rc_end_usage == AOM_VBR) |
829 | 0 | RANGE_CHECK_HI(extra_cfg, vbr_corpus_complexity_lap, |
830 | 0 | MAX_VBR_CORPUS_COMPLEXITY); |
831 | 0 | else if (extra_cfg->vbr_corpus_complexity_lap != 0) |
832 | 0 | ERROR( |
833 | 0 | "VBR corpus complexity is supported only in the case of single pass " |
834 | 0 | "VBR mode."); |
835 | | |
836 | 0 | #if !CONFIG_TUNE_BUTTERAUGLI |
837 | 0 | if (extra_cfg->tuning == AOM_TUNE_BUTTERAUGLI) { |
838 | 0 | ERROR( |
839 | 0 | "This error may be related to the wrong configuration options: try to " |
840 | 0 | "set -DCONFIG_TUNE_BUTTERAUGLI=1 at the time CMake is run."); |
841 | 0 | } |
842 | 0 | #endif |
843 | | |
844 | 0 | #if !CONFIG_TUNE_VMAF |
845 | 0 | if (extra_cfg->tuning >= AOM_TUNE_VMAF_WITH_PREPROCESSING && |
846 | 0 | extra_cfg->tuning <= AOM_TUNE_VMAF_NEG_MAX_GAIN) { |
847 | 0 | ERROR( |
848 | 0 | "This error may be related to the wrong configuration options: try to " |
849 | 0 | "set -DCONFIG_TUNE_VMAF=1 at the time CMake is run."); |
850 | 0 | } |
851 | 0 | #endif |
852 | | |
853 | 0 | RANGE_CHECK(extra_cfg, tuning, AOM_TUNE_PSNR, AOM_TUNE_IQ); |
854 | | |
855 | 0 | RANGE_CHECK(extra_cfg, dist_metric, AOM_DIST_METRIC_PSNR, |
856 | 0 | AOM_DIST_METRIC_QM_PSNR); |
857 | | |
858 | 0 | RANGE_CHECK(extra_cfg, timing_info_type, AOM_TIMING_UNSPECIFIED, |
859 | 0 | AOM_TIMING_DEC_MODEL); |
860 | | |
861 | 0 | RANGE_CHECK(extra_cfg, film_grain_test_vector, 0, 16); |
862 | | |
863 | 0 | if (extra_cfg->lossless) { |
864 | 0 | if (extra_cfg->aq_mode != 0) |
865 | 0 | ERROR("Only --aq_mode=0 can be used with --lossless=1."); |
866 | 0 | if (extra_cfg->enable_chroma_deltaq) |
867 | 0 | ERROR("Only --enable_chroma_deltaq=0 can be used with --lossless=1."); |
868 | 0 | } |
869 | | |
870 | 0 | RANGE_CHECK(extra_cfg, max_reference_frames, 3, 7); |
871 | 0 | RANGE_CHECK(extra_cfg, enable_reduced_reference_set, 0, 1); |
872 | 0 | RANGE_CHECK_HI(extra_cfg, chroma_subsampling_x, 1); |
873 | 0 | RANGE_CHECK_HI(extra_cfg, chroma_subsampling_y, 1); |
874 | | |
875 | 0 | RANGE_CHECK_HI(extra_cfg, disable_trellis_quant, 3); |
876 | 0 | RANGE_CHECK(extra_cfg, coeff_cost_upd_freq, 0, 3); |
877 | 0 | RANGE_CHECK(extra_cfg, mode_cost_upd_freq, 0, 3); |
878 | 0 | RANGE_CHECK(extra_cfg, mv_cost_upd_freq, 0, 3); |
879 | 0 | RANGE_CHECK(extra_cfg, dv_cost_upd_freq, 0, 3); |
880 | | |
881 | 0 | RANGE_CHECK(extra_cfg, min_partition_size, 4, 128); |
882 | 0 | RANGE_CHECK(extra_cfg, max_partition_size, 4, 128); |
883 | 0 | RANGE_CHECK_HI(extra_cfg, min_partition_size, extra_cfg->max_partition_size); |
884 | | |
885 | 0 | for (int i = 0; i < MAX_NUM_OPERATING_POINTS; ++i) { |
886 | 0 | const int level_idx = extra_cfg->target_seq_level_idx[i]; |
887 | 0 | if (!is_valid_seq_level_idx(level_idx) && |
888 | 0 | level_idx != SEQ_LEVEL_KEEP_STATS) { |
889 | 0 | ERROR("Target sequence level index is invalid"); |
890 | 0 | } |
891 | 0 | } |
892 | | |
893 | 0 | RANGE_CHECK(extra_cfg, deltaq_strength, 0, 1000); |
894 | 0 | RANGE_CHECK_HI(extra_cfg, loopfilter_control, 3); |
895 | 0 | RANGE_CHECK_BOOL(extra_cfg, skip_postproc_filtering); |
896 | 0 | RANGE_CHECK_HI(extra_cfg, enable_cdef, 3); |
897 | 0 | RANGE_CHECK_BOOL(extra_cfg, auto_intra_tools_off); |
898 | 0 | RANGE_CHECK_BOOL(extra_cfg, strict_level_conformance); |
899 | 0 | RANGE_CHECK_BOOL(extra_cfg, sb_qp_sweep); |
900 | | |
901 | 0 | RANGE_CHECK(extra_cfg, kf_max_pyr_height, -1, 5); |
902 | 0 | if (extra_cfg->kf_max_pyr_height != -1 && |
903 | 0 | extra_cfg->kf_max_pyr_height < (int)extra_cfg->gf_min_pyr_height) { |
904 | 0 | ERROR( |
905 | 0 | "The value of kf-max-pyr-height should not be smaller than " |
906 | 0 | "gf-min-pyr-height"); |
907 | 0 | } |
908 | | |
909 | 0 | return AOM_CODEC_OK; |
910 | 0 | } |
911 | | |
912 | | static aom_codec_err_t validate_img(aom_codec_alg_priv_t *ctx, |
913 | 0 | const aom_image_t *img) { |
914 | 0 | switch (img->fmt) { |
915 | 0 | case AOM_IMG_FMT_YV12: |
916 | 0 | case AOM_IMG_FMT_NV12: |
917 | 0 | case AOM_IMG_FMT_I420: |
918 | 0 | case AOM_IMG_FMT_YV1216: |
919 | 0 | case AOM_IMG_FMT_I42016: break; |
920 | 0 | case AOM_IMG_FMT_I444: |
921 | 0 | case AOM_IMG_FMT_I44416: |
922 | 0 | if (ctx->cfg.g_profile == (unsigned int)PROFILE_0 && |
923 | 0 | !ctx->cfg.monochrome) { |
924 | 0 | ERROR("Invalid image format. I444 images not supported in profile."); |
925 | 0 | } |
926 | 0 | break; |
927 | 0 | case AOM_IMG_FMT_I422: |
928 | 0 | case AOM_IMG_FMT_I42216: |
929 | 0 | if (ctx->cfg.g_profile != (unsigned int)PROFILE_2) { |
930 | 0 | ERROR("Invalid image format. I422 images not supported in profile."); |
931 | 0 | } |
932 | 0 | break; |
933 | 0 | default: |
934 | 0 | ERROR( |
935 | 0 | "Invalid image format. Only YV12, NV12, I420, I422, I444 images are " |
936 | 0 | "supported."); |
937 | 0 | break; |
938 | 0 | } |
939 | | |
940 | 0 | if (img->d_w != ctx->cfg.g_w || img->d_h != ctx->cfg.g_h) |
941 | 0 | ERROR("Image size must match encoder init configuration size"); |
942 | | |
943 | | #if CONFIG_TUNE_BUTTERAUGLI |
944 | | if (ctx->extra_cfg.tuning == AOM_TUNE_BUTTERAUGLI) { |
945 | | if (img->bit_depth > 8) { |
946 | | ERROR("Only 8 bit depth images supported in tune=butteraugli mode."); |
947 | | } |
948 | | if (img->mc != 0 && img->mc != AOM_CICP_MC_BT_709 && |
949 | | img->mc != AOM_CICP_MC_BT_601 && img->mc != AOM_CICP_MC_BT_470_B_G) { |
950 | | ERROR( |
951 | | "Only BT.709 and BT.601 matrix coefficients supported in " |
952 | | "tune=butteraugli mode. Identity matrix is treated as BT.601."); |
953 | | } |
954 | | } |
955 | | #endif |
956 | | |
957 | 0 | return AOM_CODEC_OK; |
958 | 0 | } |
959 | | |
960 | 0 | static int get_image_bps(const aom_image_t *img) { |
961 | 0 | switch (img->fmt) { |
962 | 0 | case AOM_IMG_FMT_YV12: |
963 | 0 | case AOM_IMG_FMT_NV12: |
964 | 0 | case AOM_IMG_FMT_I420: return 12; |
965 | 0 | case AOM_IMG_FMT_I422: return 16; |
966 | 0 | case AOM_IMG_FMT_I444: return 24; |
967 | 0 | case AOM_IMG_FMT_YV1216: |
968 | 0 | case AOM_IMG_FMT_I42016: return 24; |
969 | 0 | case AOM_IMG_FMT_I42216: return 32; |
970 | 0 | case AOM_IMG_FMT_I44416: return 48; |
971 | 0 | default: assert(0 && "Invalid image format"); break; |
972 | 0 | } |
973 | 0 | return 0; |
974 | 0 | } |
975 | | |
976 | | // Set appropriate options to disable frame super-resolution. |
977 | 0 | static void disable_superres(SuperResCfg *const superres_cfg) { |
978 | 0 | superres_cfg->superres_mode = AOM_SUPERRES_NONE; |
979 | 0 | superres_cfg->superres_scale_denominator = SCALE_NUMERATOR; |
980 | 0 | superres_cfg->superres_kf_scale_denominator = SCALE_NUMERATOR; |
981 | 0 | superres_cfg->superres_qthresh = 255; |
982 | 0 | superres_cfg->superres_kf_qthresh = 255; |
983 | 0 | } |
984 | | |
985 | | static void set_auto_tiles(TileConfig *const tile_cfg, unsigned int width, |
986 | 0 | unsigned int height, unsigned int threads) { |
987 | 0 | int tile_cols_log2 = 0; |
988 | 0 | int tile_rows_log2 = 0; |
989 | 0 | if (threads < 2) return; |
990 | | // Avoid small tiles because they are particularly bad for coding. |
991 | | // Use no more tiles than the number of threads. Aim for one tile per |
992 | | // thread. Using more than one thread inside one tile could be less |
993 | | // efficient. Using more tiles than the number of threads would result |
994 | | // in a compression penalty without much benefit. |
995 | 0 | const uint32_t kMinTileArea = 128 * 128; |
996 | 0 | const uint32_t kMaxTiles = 32; |
997 | 0 | uint32_t frame_area = width * height; |
998 | 0 | uint32_t tiles = (frame_area + kMinTileArea - 1) / kMinTileArea; |
999 | 0 | if (tiles > kMaxTiles) { |
1000 | 0 | tiles = kMaxTiles; |
1001 | 0 | } |
1002 | 0 | if (tiles > threads) { |
1003 | 0 | tiles = threads; |
1004 | 0 | } |
1005 | 0 | int tiles_log2 = (int)log2(tiles); |
1006 | | // If the frame width is equal or greater than the height, use more tile |
1007 | | // columns than tile rows. |
1008 | 0 | if (width >= height) { |
1009 | 0 | tile_cols_log2 = (tiles_log2 + 1) / 2; |
1010 | 0 | tile_rows_log2 = tiles_log2 - tile_cols_log2; |
1011 | 0 | } else { |
1012 | 0 | tile_rows_log2 = (tiles_log2 + 1) / 2; |
1013 | 0 | tile_cols_log2 = tiles_log2 - tile_rows_log2; |
1014 | 0 | } |
1015 | 0 | tile_cfg->tile_columns = tile_cols_log2; |
1016 | 0 | tile_cfg->tile_rows = tile_rows_log2; |
1017 | 0 | } |
1018 | | |
1019 | | static void update_default_encoder_config(const cfg_options_t *cfg, |
1020 | 0 | struct av1_extracfg *extra_cfg) { |
1021 | 0 | extra_cfg->enable_cdef = (cfg->disable_cdef == 0) ? 1 : 0; |
1022 | 0 | extra_cfg->enable_restoration = (cfg->disable_lr == 0); |
1023 | 0 | extra_cfg->superblock_size = |
1024 | 0 | (cfg->super_block_size == 64) ? AOM_SUPERBLOCK_SIZE_64X64 |
1025 | 0 | : (cfg->super_block_size == 128) ? AOM_SUPERBLOCK_SIZE_128X128 |
1026 | 0 | : AOM_SUPERBLOCK_SIZE_DYNAMIC; |
1027 | 0 | extra_cfg->enable_warped_motion = (cfg->disable_warp_motion == 0); |
1028 | 0 | extra_cfg->enable_dist_wtd_comp = (cfg->disable_dist_wtd_comp == 0); |
1029 | 0 | extra_cfg->enable_diff_wtd_comp = (cfg->disable_diff_wtd_comp == 0); |
1030 | 0 | extra_cfg->enable_dual_filter = (cfg->disable_dual_filter == 0); |
1031 | 0 | extra_cfg->enable_angle_delta = (cfg->disable_intra_angle_delta == 0); |
1032 | 0 | extra_cfg->enable_rect_partitions = (cfg->disable_rect_partition_type == 0); |
1033 | 0 | extra_cfg->enable_ab_partitions = (cfg->disable_ab_partition_type == 0); |
1034 | 0 | extra_cfg->enable_1to4_partitions = (cfg->disable_1to4_partition_type == 0); |
1035 | 0 | extra_cfg->max_partition_size = cfg->max_partition_size; |
1036 | 0 | extra_cfg->min_partition_size = cfg->min_partition_size; |
1037 | 0 | extra_cfg->enable_intra_edge_filter = (cfg->disable_intra_edge_filter == 0); |
1038 | 0 | extra_cfg->enable_tx64 = (cfg->disable_tx_64x64 == 0); |
1039 | 0 | extra_cfg->enable_flip_idtx = (cfg->disable_flip_idtx == 0); |
1040 | 0 | extra_cfg->enable_masked_comp = (cfg->disable_masked_comp == 0); |
1041 | 0 | extra_cfg->enable_interintra_comp = (cfg->disable_inter_intra_comp == 0); |
1042 | 0 | extra_cfg->enable_smooth_interintra = (cfg->disable_smooth_inter_intra == 0); |
1043 | 0 | extra_cfg->enable_interinter_wedge = (cfg->disable_inter_inter_wedge == 0); |
1044 | 0 | extra_cfg->enable_interintra_wedge = (cfg->disable_inter_intra_wedge == 0); |
1045 | 0 | extra_cfg->enable_global_motion = (cfg->disable_global_motion == 0); |
1046 | 0 | extra_cfg->enable_filter_intra = (cfg->disable_filter_intra == 0); |
1047 | 0 | extra_cfg->enable_smooth_intra = (cfg->disable_smooth_intra == 0); |
1048 | 0 | extra_cfg->enable_paeth_intra = (cfg->disable_paeth_intra == 0); |
1049 | 0 | extra_cfg->enable_cfl_intra = (cfg->disable_cfl == 0); |
1050 | 0 | extra_cfg->enable_obmc = (cfg->disable_obmc == 0); |
1051 | 0 | extra_cfg->enable_palette = (cfg->disable_palette == 0); |
1052 | 0 | extra_cfg->enable_intrabc = (cfg->disable_intrabc == 0); |
1053 | 0 | extra_cfg->disable_trellis_quant = cfg->disable_trellis_quant; |
1054 | 0 | extra_cfg->allow_ref_frame_mvs = (cfg->disable_ref_frame_mv == 0); |
1055 | 0 | extra_cfg->enable_ref_frame_mvs = (cfg->disable_ref_frame_mv == 0); |
1056 | 0 | extra_cfg->enable_onesided_comp = (cfg->disable_one_sided_comp == 0); |
1057 | 0 | extra_cfg->enable_reduced_reference_set = cfg->reduced_reference_set; |
1058 | 0 | extra_cfg->reduced_tx_type_set = cfg->reduced_tx_type_set; |
1059 | 0 | } |
1060 | | |
1061 | | static void set_encoder_config(AV1EncoderConfig *oxcf, |
1062 | | const aom_codec_enc_cfg_t *cfg, |
1063 | 0 | struct av1_extracfg *extra_cfg) { |
1064 | 0 | if (cfg->encoder_cfg.init_by_cfg_file) { |
1065 | 0 | update_default_encoder_config(&cfg->encoder_cfg, extra_cfg); |
1066 | 0 | } |
1067 | |
|
1068 | 0 | TuneCfg *const tune_cfg = &oxcf->tune_cfg; |
1069 | 0 | FrameDimensionCfg *const frm_dim_cfg = &oxcf->frm_dim_cfg; |
1070 | 0 | TileConfig *const tile_cfg = &oxcf->tile_cfg; |
1071 | 0 | ResizeCfg *const resize_cfg = &oxcf->resize_cfg; |
1072 | 0 | GFConfig *const gf_cfg = &oxcf->gf_cfg; |
1073 | 0 | PartitionCfg *const part_cfg = &oxcf->part_cfg; |
1074 | 0 | IntraModeCfg *const intra_mode_cfg = &oxcf->intra_mode_cfg; |
1075 | 0 | TxfmSizeTypeCfg *const txfm_cfg = &oxcf->txfm_cfg; |
1076 | 0 | CompoundTypeCfg *const comp_type_cfg = &oxcf->comp_type_cfg; |
1077 | 0 | SuperResCfg *const superres_cfg = &oxcf->superres_cfg; |
1078 | 0 | KeyFrameCfg *const kf_cfg = &oxcf->kf_cfg; |
1079 | 0 | DecoderModelCfg *const dec_model_cfg = &oxcf->dec_model_cfg; |
1080 | 0 | RateControlCfg *const rc_cfg = &oxcf->rc_cfg; |
1081 | 0 | QuantizationCfg *const q_cfg = &oxcf->q_cfg; |
1082 | 0 | ColorCfg *const color_cfg = &oxcf->color_cfg; |
1083 | 0 | InputCfg *const input_cfg = &oxcf->input_cfg; |
1084 | 0 | AlgoCfg *const algo_cfg = &oxcf->algo_cfg; |
1085 | 0 | ToolCfg *const tool_cfg = &oxcf->tool_cfg; |
1086 | |
|
1087 | 0 | oxcf->profile = cfg->g_profile; |
1088 | 0 | oxcf->max_threads = (int)cfg->g_threads; |
1089 | |
|
1090 | 0 | switch (cfg->g_usage) { |
1091 | 0 | case AOM_USAGE_REALTIME: oxcf->mode = REALTIME; break; |
1092 | 0 | case AOM_USAGE_ALL_INTRA: oxcf->mode = ALLINTRA; break; |
1093 | 0 | default: oxcf->mode = GOOD; break; |
1094 | 0 | } |
1095 | | |
1096 | | // Set frame-dimension related configuration. |
1097 | 0 | frm_dim_cfg->width = cfg->g_w; |
1098 | 0 | frm_dim_cfg->height = cfg->g_h; |
1099 | 0 | frm_dim_cfg->forced_max_frame_width = cfg->g_forced_max_frame_width; |
1100 | 0 | frm_dim_cfg->forced_max_frame_height = cfg->g_forced_max_frame_height; |
1101 | 0 | frm_dim_cfg->render_width = extra_cfg->render_width; |
1102 | 0 | frm_dim_cfg->render_height = extra_cfg->render_height; |
1103 | | |
1104 | | // Set input video related configuration. |
1105 | 0 | input_cfg->input_bit_depth = cfg->g_input_bit_depth; |
1106 | | // guess a frame rate if out of whack, use 30 |
1107 | 0 | input_cfg->init_framerate = (double)cfg->g_timebase.den / cfg->g_timebase.num; |
1108 | 0 | if (cfg->g_pass >= AOM_RC_SECOND_PASS) { |
1109 | 0 | const size_t packet_sz = sizeof(FIRSTPASS_STATS); |
1110 | 0 | const int n_packets = (int)(cfg->rc_twopass_stats_in.sz / packet_sz); |
1111 | 0 | input_cfg->limit = n_packets - 1; |
1112 | 0 | } else { |
1113 | 0 | input_cfg->limit = cfg->g_limit; |
1114 | 0 | } |
1115 | 0 | input_cfg->chroma_subsampling_x = extra_cfg->chroma_subsampling_x; |
1116 | 0 | input_cfg->chroma_subsampling_y = extra_cfg->chroma_subsampling_y; |
1117 | 0 | if (input_cfg->init_framerate > 180) { |
1118 | 0 | input_cfg->init_framerate = 30; |
1119 | 0 | dec_model_cfg->timing_info_present = 0; |
1120 | 0 | } |
1121 | | |
1122 | | // Set Decoder model configuration. |
1123 | 0 | if (extra_cfg->timing_info_type == AOM_TIMING_EQUAL || |
1124 | 0 | extra_cfg->timing_info_type == AOM_TIMING_DEC_MODEL) { |
1125 | 0 | dec_model_cfg->timing_info_present = 1; |
1126 | 0 | dec_model_cfg->timing_info.num_units_in_display_tick = cfg->g_timebase.num; |
1127 | 0 | dec_model_cfg->timing_info.time_scale = cfg->g_timebase.den; |
1128 | 0 | dec_model_cfg->timing_info.num_ticks_per_picture = 1; |
1129 | 0 | } else { |
1130 | 0 | dec_model_cfg->timing_info_present = 0; |
1131 | 0 | } |
1132 | 0 | if (extra_cfg->timing_info_type == AOM_TIMING_EQUAL) { |
1133 | 0 | dec_model_cfg->timing_info.equal_picture_interval = 1; |
1134 | 0 | dec_model_cfg->decoder_model_info_present_flag = 0; |
1135 | 0 | dec_model_cfg->display_model_info_present_flag = 1; |
1136 | 0 | } else if (extra_cfg->timing_info_type == AOM_TIMING_DEC_MODEL) { |
1137 | 0 | dec_model_cfg->num_units_in_decoding_tick = cfg->g_timebase.num; |
1138 | 0 | dec_model_cfg->timing_info.equal_picture_interval = 0; |
1139 | 0 | dec_model_cfg->decoder_model_info_present_flag = 1; |
1140 | 0 | dec_model_cfg->display_model_info_present_flag = 1; |
1141 | 0 | } |
1142 | |
|
1143 | 0 | oxcf->pass = cfg->g_pass; |
1144 | | // For backward compatibility, assume that if extra_cfg->passes==-1, then |
1145 | | // passes = 1 or 2. |
1146 | 0 | if (extra_cfg->passes == -1) { |
1147 | 0 | if (cfg->g_pass == AOM_RC_ONE_PASS) { |
1148 | 0 | oxcf->passes = 1; |
1149 | 0 | } else { |
1150 | 0 | oxcf->passes = 2; |
1151 | 0 | } |
1152 | 0 | } else { |
1153 | 0 | oxcf->passes = extra_cfg->passes; |
1154 | 0 | } |
1155 | | |
1156 | | // Set Rate Control configuration. |
1157 | 0 | rc_cfg->max_intra_bitrate_pct = extra_cfg->rc_max_intra_bitrate_pct; |
1158 | 0 | rc_cfg->max_inter_bitrate_pct = extra_cfg->rc_max_inter_bitrate_pct; |
1159 | 0 | rc_cfg->gf_cbr_boost_pct = extra_cfg->gf_cbr_boost_pct; |
1160 | 0 | rc_cfg->mode = cfg->rc_end_usage; |
1161 | 0 | rc_cfg->min_cr = extra_cfg->min_cr; |
1162 | 0 | rc_cfg->best_allowed_q = |
1163 | 0 | extra_cfg->lossless ? 0 : av1_quantizer_to_qindex(cfg->rc_min_quantizer); |
1164 | 0 | rc_cfg->worst_allowed_q = |
1165 | 0 | extra_cfg->lossless ? 0 : av1_quantizer_to_qindex(cfg->rc_max_quantizer); |
1166 | 0 | rc_cfg->cq_level = av1_quantizer_to_qindex(extra_cfg->cq_level); |
1167 | 0 | rc_cfg->under_shoot_pct = cfg->rc_undershoot_pct; |
1168 | 0 | rc_cfg->over_shoot_pct = cfg->rc_overshoot_pct; |
1169 | 0 | rc_cfg->maximum_buffer_size_ms = cfg->rc_buf_sz; |
1170 | 0 | rc_cfg->starting_buffer_level_ms = cfg->rc_buf_initial_sz; |
1171 | 0 | rc_cfg->optimal_buffer_level_ms = cfg->rc_buf_optimal_sz; |
1172 | | // Convert target bandwidth from Kbit/s to Bit/s |
1173 | 0 | rc_cfg->target_bandwidth = 1000 * cfg->rc_target_bitrate; |
1174 | 0 | rc_cfg->drop_frames_water_mark = cfg->rc_dropframe_thresh; |
1175 | 0 | rc_cfg->vbr_corpus_complexity_lap = extra_cfg->vbr_corpus_complexity_lap; |
1176 | 0 | rc_cfg->vbrbias = cfg->rc_2pass_vbr_bias_pct; |
1177 | 0 | rc_cfg->vbrmin_section = cfg->rc_2pass_vbr_minsection_pct; |
1178 | 0 | rc_cfg->vbrmax_section = cfg->rc_2pass_vbr_maxsection_pct; |
1179 | | |
1180 | | // Set Toolset related configuration. |
1181 | 0 | tool_cfg->bit_depth = cfg->g_bit_depth; |
1182 | 0 | tool_cfg->cdef_control = (CDEF_CONTROL)extra_cfg->enable_cdef; |
1183 | 0 | tool_cfg->enable_restoration = |
1184 | 0 | (cfg->g_usage == AOM_USAGE_REALTIME) ? 0 : extra_cfg->enable_restoration; |
1185 | 0 | tool_cfg->force_video_mode = extra_cfg->force_video_mode; |
1186 | 0 | tool_cfg->enable_palette = extra_cfg->enable_palette; |
1187 | | // FIXME(debargha): Should this be: |
1188 | | // tool_cfg->enable_ref_frame_mvs = extra_cfg->allow_ref_frame_mvs & |
1189 | | // extra_cfg->enable_order_hint ? |
1190 | | // Disallow using temporal MVs while large_scale_tile = 1. |
1191 | 0 | tool_cfg->enable_ref_frame_mvs = |
1192 | 0 | extra_cfg->allow_ref_frame_mvs && !cfg->large_scale_tile; |
1193 | 0 | tool_cfg->superblock_size = extra_cfg->superblock_size; |
1194 | 0 | tool_cfg->enable_monochrome = cfg->monochrome; |
1195 | 0 | tool_cfg->full_still_picture_hdr = cfg->full_still_picture_hdr != 0; |
1196 | 0 | tool_cfg->enable_dual_filter = extra_cfg->enable_dual_filter; |
1197 | 0 | tool_cfg->enable_order_hint = extra_cfg->enable_order_hint; |
1198 | 0 | tool_cfg->enable_interintra_comp = extra_cfg->enable_interintra_comp; |
1199 | 0 | tool_cfg->ref_frame_mvs_present = |
1200 | 0 | extra_cfg->enable_ref_frame_mvs & extra_cfg->enable_order_hint; |
1201 | | |
1202 | | // Explicitly disable global motion in a few cases: |
1203 | | // * For realtime mode, we never search global motion, and disabling |
1204 | | // it here prevents later code from allocating buffers we don't need |
1205 | | // * For large scale tile mode, some of the intended use cases expect |
1206 | | // all frame headers to be identical. This breaks if global motion is |
1207 | | // used, since global motion data is stored in the frame header. |
1208 | | // eg, see test/lightfield_test.sh, which checks that all frame headers |
1209 | | // are the same. |
1210 | 0 | tool_cfg->enable_global_motion = extra_cfg->enable_global_motion && |
1211 | 0 | cfg->g_usage != AOM_USAGE_REALTIME && |
1212 | 0 | !cfg->large_scale_tile; |
1213 | |
|
1214 | 0 | tool_cfg->error_resilient_mode = |
1215 | 0 | cfg->g_error_resilient | extra_cfg->error_resilient_mode; |
1216 | 0 | tool_cfg->frame_parallel_decoding_mode = |
1217 | 0 | extra_cfg->frame_parallel_decoding_mode; |
1218 | | |
1219 | | // Set Quantization related configuration. |
1220 | 0 | q_cfg->using_qm = extra_cfg->enable_qm; |
1221 | 0 | q_cfg->qm_minlevel = extra_cfg->qm_min; |
1222 | 0 | q_cfg->qm_maxlevel = extra_cfg->qm_max; |
1223 | 0 | q_cfg->quant_b_adapt = extra_cfg->quant_b_adapt; |
1224 | 0 | q_cfg->enable_chroma_deltaq = extra_cfg->enable_chroma_deltaq; |
1225 | 0 | q_cfg->aq_mode = extra_cfg->aq_mode; |
1226 | 0 | q_cfg->deltaq_mode = extra_cfg->deltaq_mode; |
1227 | 0 | q_cfg->deltaq_strength = extra_cfg->deltaq_strength; |
1228 | 0 | q_cfg->use_fixed_qp_offsets = |
1229 | 0 | cfg->use_fixed_qp_offsets && (rc_cfg->mode == AOM_Q); |
1230 | 0 | q_cfg->enable_hdr_deltaq = |
1231 | 0 | (q_cfg->deltaq_mode == DELTA_Q_HDR) && |
1232 | 0 | (cfg->g_bit_depth == AOM_BITS_10) && |
1233 | 0 | (extra_cfg->color_primaries == AOM_CICP_CP_BT_2020); |
1234 | |
|
1235 | 0 | tool_cfg->enable_deltalf_mode = |
1236 | 0 | (q_cfg->deltaq_mode != NO_DELTA_Q) && extra_cfg->deltalf_mode; |
1237 | | |
1238 | | // Set cost update frequency configuration. |
1239 | 0 | oxcf->cost_upd_freq.coeff = (COST_UPDATE_TYPE)extra_cfg->coeff_cost_upd_freq; |
1240 | 0 | oxcf->cost_upd_freq.mode = (COST_UPDATE_TYPE)extra_cfg->mode_cost_upd_freq; |
1241 | | // Avoid MV cost update for allintra encoding mode. |
1242 | 0 | oxcf->cost_upd_freq.mv = (cfg->kf_max_dist != 0) |
1243 | 0 | ? (COST_UPDATE_TYPE)extra_cfg->mv_cost_upd_freq |
1244 | 0 | : COST_UPD_OFF; |
1245 | 0 | oxcf->cost_upd_freq.dv = (COST_UPDATE_TYPE)extra_cfg->dv_cost_upd_freq; |
1246 | | |
1247 | | // Set frame resize mode configuration. |
1248 | 0 | resize_cfg->resize_mode = (RESIZE_MODE)cfg->rc_resize_mode; |
1249 | 0 | resize_cfg->resize_scale_denominator = (uint8_t)cfg->rc_resize_denominator; |
1250 | 0 | resize_cfg->resize_kf_scale_denominator = |
1251 | 0 | (uint8_t)cfg->rc_resize_kf_denominator; |
1252 | 0 | if (resize_cfg->resize_mode == RESIZE_FIXED && |
1253 | 0 | resize_cfg->resize_scale_denominator == SCALE_NUMERATOR && |
1254 | 0 | resize_cfg->resize_kf_scale_denominator == SCALE_NUMERATOR) |
1255 | 0 | resize_cfg->resize_mode = RESIZE_NONE; |
1256 | | |
1257 | | // Set encoder algorithm related configuration. |
1258 | 0 | algo_cfg->enable_overlay = extra_cfg->enable_overlay; |
1259 | 0 | algo_cfg->disable_trellis_quant = extra_cfg->disable_trellis_quant; |
1260 | 0 | algo_cfg->sharpness = extra_cfg->sharpness; |
1261 | 0 | algo_cfg->arnr_max_frames = extra_cfg->arnr_max_frames; |
1262 | 0 | algo_cfg->arnr_strength = extra_cfg->arnr_strength; |
1263 | 0 | algo_cfg->cdf_update_mode = (uint8_t)extra_cfg->cdf_update_mode; |
1264 | | // TODO(any): Fix and Enable TPL for resize-mode > 0 |
1265 | 0 | algo_cfg->enable_tpl_model = |
1266 | 0 | resize_cfg->resize_mode ? 0 : extra_cfg->enable_tpl_model; |
1267 | 0 | algo_cfg->loopfilter_control = extra_cfg->loopfilter_control; |
1268 | 0 | algo_cfg->skip_postproc_filtering = extra_cfg->skip_postproc_filtering; |
1269 | | |
1270 | | // Set two-pass stats configuration. |
1271 | 0 | oxcf->twopass_stats_in = cfg->rc_twopass_stats_in; |
1272 | |
|
1273 | 0 | if (extra_cfg->two_pass_output) |
1274 | 0 | oxcf->two_pass_output = extra_cfg->two_pass_output; |
1275 | |
|
1276 | 0 | oxcf->second_pass_log = extra_cfg->second_pass_log; |
1277 | | |
1278 | | // Set Key frame configuration. |
1279 | 0 | kf_cfg->fwd_kf_enabled = cfg->fwd_kf_enabled; |
1280 | 0 | kf_cfg->auto_key = |
1281 | 0 | cfg->kf_mode == AOM_KF_AUTO && cfg->kf_min_dist != cfg->kf_max_dist; |
1282 | 0 | kf_cfg->key_freq_min = cfg->kf_min_dist; |
1283 | 0 | kf_cfg->key_freq_max = cfg->kf_max_dist; |
1284 | 0 | kf_cfg->sframe_dist = cfg->sframe_dist; |
1285 | 0 | kf_cfg->sframe_mode = cfg->sframe_mode; |
1286 | 0 | kf_cfg->enable_sframe = extra_cfg->s_frame_mode; |
1287 | 0 | kf_cfg->enable_keyframe_filtering = extra_cfg->enable_keyframe_filtering; |
1288 | 0 | kf_cfg->fwd_kf_dist = extra_cfg->fwd_kf_dist; |
1289 | | // Disable key frame filtering in all intra mode. |
1290 | 0 | if (cfg->kf_max_dist == 0) { |
1291 | 0 | kf_cfg->enable_keyframe_filtering = 0; |
1292 | 0 | } |
1293 | 0 | kf_cfg->enable_intrabc = extra_cfg->enable_intrabc; |
1294 | |
|
1295 | 0 | oxcf->speed = extra_cfg->cpu_used; |
1296 | | // TODO(yunqingwang, any) In REALTIME mode, 1080p performance at speed 5 & 6 |
1297 | | // is quite bad. Force to use speed 7 for now. Will investigate it when we |
1298 | | // work on rd path optimization later. |
1299 | 0 | if (oxcf->mode == REALTIME && AOMMIN(cfg->g_w, cfg->g_h) >= 1080 && |
1300 | 0 | oxcf->speed < 7) |
1301 | 0 | oxcf->speed = 7; |
1302 | | |
1303 | | // Set Color related configuration. |
1304 | 0 | color_cfg->color_primaries = extra_cfg->color_primaries; |
1305 | 0 | color_cfg->transfer_characteristics = extra_cfg->transfer_characteristics; |
1306 | 0 | color_cfg->matrix_coefficients = extra_cfg->matrix_coefficients; |
1307 | 0 | color_cfg->color_range = extra_cfg->color_range; |
1308 | 0 | color_cfg->chroma_sample_position = extra_cfg->chroma_sample_position; |
1309 | | |
1310 | | // Set Group of frames configuration. |
1311 | | // Force lag_in_frames to 0 for REALTIME mode |
1312 | 0 | gf_cfg->lag_in_frames = (oxcf->mode == REALTIME) |
1313 | 0 | ? 0 |
1314 | 0 | : clamp(cfg->g_lag_in_frames, 0, MAX_LAG_BUFFERS); |
1315 | 0 | gf_cfg->enable_auto_arf = extra_cfg->enable_auto_alt_ref; |
1316 | 0 | gf_cfg->enable_auto_brf = extra_cfg->enable_auto_bwd_ref; |
1317 | 0 | gf_cfg->min_gf_interval = extra_cfg->min_gf_interval; |
1318 | 0 | gf_cfg->max_gf_interval = extra_cfg->max_gf_interval; |
1319 | 0 | gf_cfg->gf_min_pyr_height = extra_cfg->gf_min_pyr_height; |
1320 | 0 | gf_cfg->gf_max_pyr_height = extra_cfg->gf_max_pyr_height; |
1321 | | |
1322 | | // Set tune related configuration. |
1323 | 0 | tune_cfg->tuning = extra_cfg->tuning; |
1324 | 0 | tune_cfg->vmaf_model_path = extra_cfg->vmaf_model_path; |
1325 | 0 | tune_cfg->content = extra_cfg->content; |
1326 | 0 | if (cfg->large_scale_tile) { |
1327 | 0 | tune_cfg->film_grain_test_vector = 0; |
1328 | 0 | tune_cfg->film_grain_table_filename = NULL; |
1329 | 0 | } else { |
1330 | 0 | tune_cfg->film_grain_test_vector = extra_cfg->film_grain_test_vector; |
1331 | 0 | tune_cfg->film_grain_table_filename = extra_cfg->film_grain_table_filename; |
1332 | 0 | } |
1333 | 0 | tune_cfg->dist_metric = extra_cfg->dist_metric; |
1334 | 0 | #if CONFIG_DENOISE |
1335 | 0 | oxcf->noise_level = extra_cfg->noise_level; |
1336 | 0 | oxcf->noise_block_size = extra_cfg->noise_block_size; |
1337 | 0 | oxcf->enable_dnl_denoising = extra_cfg->enable_dnl_denoising; |
1338 | 0 | #endif |
1339 | |
|
1340 | | #if CONFIG_AV1_TEMPORAL_DENOISING |
1341 | | // Temporal denoiser is for nonrd pickmode so disable it for speed < 7. |
1342 | | // Also disable it for speed 7 for now since it needs to be modified for |
1343 | | // the check_partition_merge_mode feature. |
1344 | | if (cfg->g_bit_depth == AOM_BITS_8 && oxcf->speed > 7) { |
1345 | | oxcf->noise_sensitivity = extra_cfg->noise_sensitivity; |
1346 | | } else { |
1347 | | oxcf->noise_sensitivity = 0; |
1348 | | } |
1349 | | #endif |
1350 | | // Set Tile related configuration. |
1351 | 0 | tile_cfg->num_tile_groups = extra_cfg->num_tg; |
1352 | | // In large-scale tile encoding mode, num_tile_groups is always 1. |
1353 | 0 | if (cfg->large_scale_tile) tile_cfg->num_tile_groups = 1; |
1354 | 0 | tile_cfg->mtu = extra_cfg->mtu_size; |
1355 | 0 | tile_cfg->enable_large_scale_tile = cfg->large_scale_tile; |
1356 | 0 | tile_cfg->enable_single_tile_decoding = |
1357 | 0 | (tile_cfg->enable_large_scale_tile) ? extra_cfg->single_tile_decoding : 0; |
1358 | 0 | if (extra_cfg->auto_tiles) { |
1359 | 0 | set_auto_tiles(tile_cfg, cfg->g_w, cfg->g_h, cfg->g_threads); |
1360 | 0 | extra_cfg->tile_columns = tile_cfg->tile_columns; |
1361 | 0 | extra_cfg->tile_rows = tile_cfg->tile_rows; |
1362 | 0 | } else { |
1363 | 0 | tile_cfg->tile_columns = extra_cfg->tile_columns; |
1364 | 0 | tile_cfg->tile_rows = extra_cfg->tile_rows; |
1365 | 0 | } |
1366 | 0 | tile_cfg->tile_width_count = AOMMIN(cfg->tile_width_count, MAX_TILE_COLS); |
1367 | 0 | tile_cfg->tile_height_count = AOMMIN(cfg->tile_height_count, MAX_TILE_ROWS); |
1368 | 0 | for (int i = 0; i < tile_cfg->tile_width_count; i++) { |
1369 | 0 | tile_cfg->tile_widths[i] = cfg->tile_widths[i]; |
1370 | 0 | } |
1371 | 0 | for (int i = 0; i < tile_cfg->tile_height_count; i++) { |
1372 | 0 | tile_cfg->tile_heights[i] = cfg->tile_heights[i]; |
1373 | 0 | } |
1374 | 0 | tile_cfg->enable_ext_tile_debug = extra_cfg->ext_tile_debug; |
1375 | |
|
1376 | 0 | if (tile_cfg->enable_large_scale_tile) { |
1377 | | // The superblock_size can only be AOM_SUPERBLOCK_SIZE_64X64 or |
1378 | | // AOM_SUPERBLOCK_SIZE_128X128 while tile_cfg->enable_large_scale_tile = 1. |
1379 | | // If superblock_size = AOM_SUPERBLOCK_SIZE_DYNAMIC, hard set it to |
1380 | | // AOM_SUPERBLOCK_SIZE_64X64(default value in large_scale_tile). |
1381 | 0 | if (extra_cfg->superblock_size != AOM_SUPERBLOCK_SIZE_64X64 && |
1382 | 0 | extra_cfg->superblock_size != AOM_SUPERBLOCK_SIZE_128X128) |
1383 | 0 | tool_cfg->superblock_size = AOM_SUPERBLOCK_SIZE_64X64; |
1384 | 0 | } |
1385 | | |
1386 | | // Set reference frame related configuration. |
1387 | 0 | oxcf->ref_frm_cfg.max_reference_frames = extra_cfg->max_reference_frames; |
1388 | 0 | oxcf->ref_frm_cfg.enable_reduced_reference_set = |
1389 | 0 | extra_cfg->enable_reduced_reference_set; |
1390 | 0 | oxcf->ref_frm_cfg.enable_onesided_comp = extra_cfg->enable_onesided_comp; |
1391 | |
|
1392 | 0 | oxcf->row_mt = extra_cfg->row_mt; |
1393 | 0 | oxcf->fp_mt = extra_cfg->fp_mt; |
1394 | | |
1395 | | // Set motion mode related configuration. |
1396 | 0 | oxcf->motion_mode_cfg.enable_obmc = extra_cfg->enable_obmc; |
1397 | 0 | oxcf->motion_mode_cfg.enable_warped_motion = extra_cfg->enable_warped_motion; |
1398 | 0 | #if !CONFIG_REALTIME_ONLY |
1399 | 0 | if (cfg->g_usage == AOM_USAGE_REALTIME && oxcf->speed >= 7 && |
1400 | 0 | oxcf->tune_cfg.content == AOM_CONTENT_SCREEN) { |
1401 | | // TODO(marpan): warped motion is causing a crash for RT mode with screen |
1402 | | // in nonrd (speed >= 7), for non-realtime build. |
1403 | | // Re-enable/allow when the issue is fixed. |
1404 | 0 | oxcf->motion_mode_cfg.enable_warped_motion = 0; |
1405 | 0 | oxcf->motion_mode_cfg.allow_warped_motion = 0; |
1406 | 0 | } else { |
1407 | 0 | oxcf->motion_mode_cfg.allow_warped_motion = |
1408 | 0 | (extra_cfg->allow_warped_motion & extra_cfg->enable_warped_motion); |
1409 | 0 | } |
1410 | | #else |
1411 | | oxcf->motion_mode_cfg.allow_warped_motion = |
1412 | | (cfg->g_usage == AOM_USAGE_REALTIME && oxcf->speed >= 7) |
1413 | | ? false |
1414 | | : (extra_cfg->allow_warped_motion & extra_cfg->enable_warped_motion); |
1415 | | #endif |
1416 | | |
1417 | | // Set partition related configuration. |
1418 | 0 | part_cfg->enable_rect_partitions = extra_cfg->enable_rect_partitions; |
1419 | 0 | part_cfg->enable_ab_partitions = extra_cfg->enable_ab_partitions; |
1420 | 0 | part_cfg->enable_1to4_partitions = extra_cfg->enable_1to4_partitions; |
1421 | 0 | part_cfg->min_partition_size = extra_cfg->min_partition_size; |
1422 | 0 | part_cfg->max_partition_size = extra_cfg->max_partition_size; |
1423 | | |
1424 | | // Set intra mode configuration. |
1425 | 0 | intra_mode_cfg->enable_angle_delta = extra_cfg->enable_angle_delta; |
1426 | 0 | intra_mode_cfg->enable_intra_edge_filter = |
1427 | 0 | extra_cfg->enable_intra_edge_filter; |
1428 | 0 | intra_mode_cfg->enable_filter_intra = extra_cfg->enable_filter_intra; |
1429 | 0 | intra_mode_cfg->enable_smooth_intra = extra_cfg->enable_smooth_intra; |
1430 | 0 | intra_mode_cfg->enable_paeth_intra = extra_cfg->enable_paeth_intra; |
1431 | 0 | intra_mode_cfg->enable_cfl_intra = extra_cfg->enable_cfl_intra; |
1432 | 0 | intra_mode_cfg->enable_directional_intra = |
1433 | 0 | extra_cfg->enable_directional_intra; |
1434 | 0 | intra_mode_cfg->enable_diagonal_intra = extra_cfg->enable_diagonal_intra; |
1435 | 0 | intra_mode_cfg->auto_intra_tools_off = extra_cfg->auto_intra_tools_off; |
1436 | | |
1437 | | // Set transform size/type configuration. |
1438 | 0 | txfm_cfg->enable_tx64 = extra_cfg->enable_tx64; |
1439 | 0 | txfm_cfg->enable_flip_idtx = extra_cfg->enable_flip_idtx; |
1440 | 0 | txfm_cfg->enable_rect_tx = extra_cfg->enable_rect_tx; |
1441 | 0 | txfm_cfg->reduced_tx_type_set = extra_cfg->reduced_tx_type_set; |
1442 | 0 | txfm_cfg->use_intra_dct_only = extra_cfg->use_intra_dct_only; |
1443 | 0 | txfm_cfg->use_inter_dct_only = extra_cfg->use_inter_dct_only; |
1444 | 0 | txfm_cfg->use_intra_default_tx_only = extra_cfg->use_intra_default_tx_only; |
1445 | 0 | txfm_cfg->enable_tx_size_search = extra_cfg->enable_tx_size_search; |
1446 | | |
1447 | | // Set compound type configuration. |
1448 | 0 | comp_type_cfg->enable_dist_wtd_comp = |
1449 | 0 | extra_cfg->enable_dist_wtd_comp & extra_cfg->enable_order_hint; |
1450 | 0 | comp_type_cfg->enable_masked_comp = extra_cfg->enable_masked_comp; |
1451 | 0 | comp_type_cfg->enable_diff_wtd_comp = |
1452 | 0 | extra_cfg->enable_masked_comp & extra_cfg->enable_diff_wtd_comp; |
1453 | 0 | comp_type_cfg->enable_interinter_wedge = |
1454 | 0 | extra_cfg->enable_masked_comp & extra_cfg->enable_interinter_wedge; |
1455 | 0 | comp_type_cfg->enable_smooth_interintra = |
1456 | 0 | extra_cfg->enable_interintra_comp && extra_cfg->enable_smooth_interintra; |
1457 | 0 | comp_type_cfg->enable_interintra_wedge = |
1458 | 0 | extra_cfg->enable_interintra_comp & extra_cfg->enable_interintra_wedge; |
1459 | | |
1460 | | // Set Super-resolution mode configuration. |
1461 | 0 | if (extra_cfg->lossless || cfg->large_scale_tile) { |
1462 | 0 | disable_superres(superres_cfg); |
1463 | 0 | } else { |
1464 | 0 | superres_cfg->superres_mode = cfg->rc_superres_mode; |
1465 | 0 | superres_cfg->superres_scale_denominator = |
1466 | 0 | (uint8_t)cfg->rc_superres_denominator; |
1467 | 0 | superres_cfg->superres_kf_scale_denominator = |
1468 | 0 | (uint8_t)cfg->rc_superres_kf_denominator; |
1469 | 0 | superres_cfg->superres_qthresh = |
1470 | 0 | av1_quantizer_to_qindex(cfg->rc_superres_qthresh); |
1471 | 0 | superres_cfg->superres_kf_qthresh = |
1472 | 0 | av1_quantizer_to_qindex(cfg->rc_superres_kf_qthresh); |
1473 | 0 | if (superres_cfg->superres_mode == AOM_SUPERRES_FIXED && |
1474 | 0 | superres_cfg->superres_scale_denominator == SCALE_NUMERATOR && |
1475 | 0 | superres_cfg->superres_kf_scale_denominator == SCALE_NUMERATOR) { |
1476 | 0 | disable_superres(superres_cfg); |
1477 | 0 | } |
1478 | 0 | if (superres_cfg->superres_mode == AOM_SUPERRES_QTHRESH && |
1479 | 0 | superres_cfg->superres_qthresh == 255 && |
1480 | 0 | superres_cfg->superres_kf_qthresh == 255) { |
1481 | 0 | disable_superres(superres_cfg); |
1482 | 0 | } |
1483 | 0 | } |
1484 | |
|
1485 | 0 | superres_cfg->enable_superres = |
1486 | 0 | (superres_cfg->superres_mode != AOM_SUPERRES_NONE) && |
1487 | 0 | extra_cfg->enable_superres; |
1488 | 0 | if (!superres_cfg->enable_superres) { |
1489 | 0 | disable_superres(superres_cfg); |
1490 | 0 | } |
1491 | |
|
1492 | 0 | if (input_cfg->limit == 1) { |
1493 | | // still picture mode, display model and timing is meaningless |
1494 | 0 | dec_model_cfg->display_model_info_present_flag = 0; |
1495 | 0 | dec_model_cfg->timing_info_present = 0; |
1496 | 0 | } |
1497 | |
|
1498 | 0 | oxcf->save_as_annexb = cfg->save_as_annexb; |
1499 | | |
1500 | | // Set unit test related configuration. |
1501 | 0 | oxcf->unit_test_cfg.motion_vector_unit_test = |
1502 | 0 | extra_cfg->motion_vector_unit_test; |
1503 | 0 | oxcf->unit_test_cfg.sb_multipass_unit_test = |
1504 | 0 | extra_cfg->sb_multipass_unit_test; |
1505 | |
|
1506 | 0 | oxcf->border_in_pixels = |
1507 | 0 | av1_get_enc_border_size(av1_is_resize_needed(oxcf), |
1508 | 0 | (oxcf->kf_cfg.key_freq_max == 0), BLOCK_128X128); |
1509 | 0 | memcpy(oxcf->target_seq_level_idx, extra_cfg->target_seq_level_idx, |
1510 | 0 | sizeof(oxcf->target_seq_level_idx)); |
1511 | 0 | oxcf->tier_mask = extra_cfg->tier_mask; |
1512 | |
|
1513 | 0 | oxcf->partition_info_path = extra_cfg->partition_info_path; |
1514 | |
|
1515 | 0 | oxcf->enable_rate_guide_deltaq = extra_cfg->enable_rate_guide_deltaq; |
1516 | 0 | oxcf->rate_distribution_info = extra_cfg->rate_distribution_info; |
1517 | |
|
1518 | 0 | oxcf->strict_level_conformance = extra_cfg->strict_level_conformance; |
1519 | |
|
1520 | 0 | oxcf->kf_max_pyr_height = extra_cfg->kf_max_pyr_height; |
1521 | |
|
1522 | 0 | oxcf->sb_qp_sweep = extra_cfg->sb_qp_sweep; |
1523 | 0 | } |
1524 | | |
1525 | 0 | AV1EncoderConfig av1_get_encoder_config(const aom_codec_enc_cfg_t *cfg) { |
1526 | 0 | AV1EncoderConfig oxcf; |
1527 | 0 | struct av1_extracfg extra_cfg = default_extra_cfg; |
1528 | 0 | set_encoder_config(&oxcf, cfg, &extra_cfg); |
1529 | 0 | return oxcf; |
1530 | 0 | } |
1531 | | |
1532 | | static aom_codec_err_t encoder_set_config(aom_codec_alg_priv_t *ctx, |
1533 | 0 | const aom_codec_enc_cfg_t *cfg) { |
1534 | 0 | aom_codec_err_t res; |
1535 | 0 | int force_key = 0; |
1536 | |
|
1537 | 0 | if (cfg->g_w != ctx->cfg.g_w || cfg->g_h != ctx->cfg.g_h) { |
1538 | 0 | if (cfg->g_lag_in_frames > 1 || cfg->g_pass != AOM_RC_ONE_PASS) |
1539 | 0 | ERROR("Cannot change width or height after initialization"); |
1540 | | // Note: function encoder_set_config() is allowed to be called multiple |
1541 | | // times. However, when the original frame width or height is less than two |
1542 | | // times of the new frame width or height, a forced key frame should be |
1543 | | // used. To make sure the correct detection of a forced key frame, we need |
1544 | | // to update the frame width and height only when the actual encoding is |
1545 | | // performed. cpi->last_coded_width and cpi->last_coded_height are used to |
1546 | | // track the actual coded frame size. |
1547 | 0 | if (ctx->ppi->cpi->last_coded_width && ctx->ppi->cpi->last_coded_height && |
1548 | 0 | (!valid_ref_frame_size(ctx->ppi->cpi->last_coded_width, |
1549 | 0 | ctx->ppi->cpi->last_coded_height, cfg->g_w, |
1550 | 0 | cfg->g_h) || |
1551 | 0 | ((int)cfg->g_w > ctx->ppi->cpi->last_coded_width) || |
1552 | 0 | ((int)cfg->g_h > ctx->ppi->cpi->last_coded_height))) { |
1553 | 0 | force_key = 1; |
1554 | 0 | } |
1555 | 0 | } |
1556 | | |
1557 | 0 | if (ctx->monochrome_on_init && cfg->monochrome == 0) { |
1558 | | // TODO(aomedia:3465): Allow this case to work without requiring re-init |
1559 | | // of encoder. |
1560 | 0 | ERROR("Cannot change to monochrome = 0 after init with monochrome"); |
1561 | 0 | } |
1562 | | |
1563 | | // Prevent increasing lag_in_frames. This check is stricter than it needs |
1564 | | // to be -- the limit is not increasing past the first lag_in_frames |
1565 | | // value, but we don't track the initial config, only the last successful |
1566 | | // config. |
1567 | 0 | if (cfg->g_lag_in_frames > ctx->cfg.g_lag_in_frames) |
1568 | 0 | ERROR("Cannot increase lag_in_frames"); |
1569 | | // Prevent changing lag_in_frames if Lookahead Processing is enabled |
1570 | 0 | if (cfg->g_lag_in_frames != ctx->cfg.g_lag_in_frames && |
1571 | 0 | ctx->num_lap_buffers > 0) |
1572 | 0 | ERROR("Cannot change lag_in_frames if LAP is enabled"); |
1573 | | |
1574 | 0 | res = validate_config(ctx, cfg, &ctx->extra_cfg); |
1575 | |
|
1576 | 0 | if (res == AOM_CODEC_OK) { |
1577 | 0 | ctx->cfg = *cfg; |
1578 | 0 | set_encoder_config(&ctx->oxcf, &ctx->cfg, &ctx->extra_cfg); |
1579 | | // On profile change, request a key frame |
1580 | 0 | force_key |= ctx->ppi->seq_params.profile != ctx->oxcf.profile; |
1581 | 0 | bool is_sb_size_changed = false; |
1582 | 0 | av1_change_config_seq(ctx->ppi, &ctx->oxcf, &is_sb_size_changed); |
1583 | 0 | for (int i = 0; i < ctx->ppi->num_fp_contexts; i++) { |
1584 | 0 | av1_change_config(ctx->ppi->parallel_cpi[i], &ctx->oxcf, |
1585 | 0 | is_sb_size_changed); |
1586 | 0 | } |
1587 | 0 | if (ctx->ppi->cpi_lap != NULL) { |
1588 | 0 | av1_change_config(ctx->ppi->cpi_lap, &ctx->oxcf, is_sb_size_changed); |
1589 | 0 | } |
1590 | 0 | } |
1591 | |
|
1592 | 0 | if (force_key) ctx->next_frame_flags |= AOM_EFLAG_FORCE_KF; |
1593 | |
|
1594 | 0 | return res; |
1595 | 0 | } |
1596 | | |
1597 | 0 | static aom_fixed_buf_t *encoder_get_global_headers(aom_codec_alg_priv_t *ctx) { |
1598 | 0 | return av1_get_global_headers(ctx->ppi); |
1599 | 0 | } |
1600 | | |
1601 | | static aom_codec_err_t ctrl_get_quantizer(aom_codec_alg_priv_t *ctx, |
1602 | 0 | va_list args) { |
1603 | 0 | int *const arg = va_arg(args, int *); |
1604 | 0 | if (arg == NULL) return AOM_CODEC_INVALID_PARAM; |
1605 | 0 | *arg = av1_get_quantizer(ctx->ppi->cpi); |
1606 | 0 | return AOM_CODEC_OK; |
1607 | 0 | } |
1608 | | |
1609 | | static aom_codec_err_t ctrl_get_quantizer64(aom_codec_alg_priv_t *ctx, |
1610 | 0 | va_list args) { |
1611 | 0 | int *const arg = va_arg(args, int *); |
1612 | 0 | if (arg == NULL) return AOM_CODEC_INVALID_PARAM; |
1613 | 0 | *arg = av1_qindex_to_quantizer(av1_get_quantizer(ctx->ppi->cpi)); |
1614 | 0 | return AOM_CODEC_OK; |
1615 | 0 | } |
1616 | | |
1617 | | static aom_codec_err_t ctrl_get_loopfilter_level(aom_codec_alg_priv_t *ctx, |
1618 | 0 | va_list args) { |
1619 | 0 | int *const arg = va_arg(args, int *); |
1620 | 0 | if (arg == NULL) return AOM_CODEC_INVALID_PARAM; |
1621 | 0 | *arg = ctx->ppi->cpi->common.lf.filter_level[0]; |
1622 | 0 | return AOM_CODEC_OK; |
1623 | 0 | } |
1624 | | |
1625 | | static aom_codec_err_t ctrl_get_baseline_gf_interval(aom_codec_alg_priv_t *ctx, |
1626 | 0 | va_list args) { |
1627 | 0 | int *const arg = va_arg(args, int *); |
1628 | 0 | if (arg == NULL) return AOM_CODEC_INVALID_PARAM; |
1629 | 0 | *arg = ctx->ppi->p_rc.baseline_gf_interval; |
1630 | 0 | return AOM_CODEC_OK; |
1631 | 0 | } |
1632 | | |
1633 | 0 | static aom_codec_err_t update_encoder_cfg(aom_codec_alg_priv_t *ctx) { |
1634 | 0 | set_encoder_config(&ctx->oxcf, &ctx->cfg, &ctx->extra_cfg); |
1635 | 0 | av1_check_fpmt_config(ctx->ppi, &ctx->oxcf); |
1636 | 0 | bool is_sb_size_changed = false; |
1637 | 0 | av1_change_config_seq(ctx->ppi, &ctx->oxcf, &is_sb_size_changed); |
1638 | 0 | for (int i = 0; i < ctx->ppi->num_fp_contexts; i++) { |
1639 | 0 | AV1_COMP *const cpi = ctx->ppi->parallel_cpi[i]; |
1640 | 0 | struct aom_internal_error_info *const error = cpi->common.error; |
1641 | 0 | if (setjmp(error->jmp)) { |
1642 | 0 | error->setjmp = 0; |
1643 | 0 | return error->error_code; |
1644 | 0 | } |
1645 | 0 | error->setjmp = 1; |
1646 | 0 | av1_change_config(cpi, &ctx->oxcf, is_sb_size_changed); |
1647 | 0 | error->setjmp = 0; |
1648 | 0 | } |
1649 | 0 | if (ctx->ppi->cpi_lap != NULL) { |
1650 | 0 | AV1_COMP *const cpi_lap = ctx->ppi->cpi_lap; |
1651 | 0 | struct aom_internal_error_info *const error = cpi_lap->common.error; |
1652 | 0 | if (setjmp(error->jmp)) { |
1653 | 0 | error->setjmp = 0; |
1654 | 0 | return error->error_code; |
1655 | 0 | } |
1656 | 0 | error->setjmp = 1; |
1657 | 0 | av1_change_config(cpi_lap, &ctx->oxcf, is_sb_size_changed); |
1658 | 0 | error->setjmp = 0; |
1659 | 0 | } |
1660 | 0 | return AOM_CODEC_OK; |
1661 | 0 | } |
1662 | | |
1663 | | static aom_codec_err_t update_extra_cfg(aom_codec_alg_priv_t *ctx, |
1664 | 0 | const struct av1_extracfg *extra_cfg) { |
1665 | 0 | const aom_codec_err_t res = validate_config(ctx, &ctx->cfg, extra_cfg); |
1666 | 0 | if (res == AOM_CODEC_OK) { |
1667 | 0 | ctx->extra_cfg = *extra_cfg; |
1668 | 0 | return update_encoder_cfg(ctx); |
1669 | 0 | } |
1670 | 0 | return res; |
1671 | 0 | } |
1672 | | |
1673 | | static aom_codec_err_t ctrl_set_cpuused(aom_codec_alg_priv_t *ctx, |
1674 | 0 | va_list args) { |
1675 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
1676 | 0 | extra_cfg.cpu_used = CAST(AOME_SET_CPUUSED, args); |
1677 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
1678 | 0 | } |
1679 | | |
1680 | | static aom_codec_err_t ctrl_set_enable_auto_alt_ref(aom_codec_alg_priv_t *ctx, |
1681 | 0 | va_list args) { |
1682 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
1683 | 0 | extra_cfg.enable_auto_alt_ref = CAST(AOME_SET_ENABLEAUTOALTREF, args); |
1684 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
1685 | 0 | } |
1686 | | |
1687 | | static aom_codec_err_t ctrl_set_enable_auto_bwd_ref(aom_codec_alg_priv_t *ctx, |
1688 | 0 | va_list args) { |
1689 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
1690 | 0 | extra_cfg.enable_auto_bwd_ref = CAST(AOME_SET_ENABLEAUTOBWDREF, args); |
1691 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
1692 | 0 | } |
1693 | | |
1694 | | static aom_codec_err_t ctrl_set_noise_sensitivity(aom_codec_alg_priv_t *ctx, |
1695 | 0 | va_list args) { |
1696 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
1697 | 0 | extra_cfg.noise_sensitivity = CAST(AV1E_SET_NOISE_SENSITIVITY, args); |
1698 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
1699 | 0 | } |
1700 | | |
1701 | | static aom_codec_err_t ctrl_set_sharpness(aom_codec_alg_priv_t *ctx, |
1702 | 0 | va_list args) { |
1703 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
1704 | 0 | extra_cfg.sharpness = CAST(AOME_SET_SHARPNESS, args); |
1705 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
1706 | 0 | } |
1707 | | |
1708 | | static aom_codec_err_t ctrl_set_static_thresh(aom_codec_alg_priv_t *ctx, |
1709 | 0 | va_list args) { |
1710 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
1711 | 0 | extra_cfg.static_thresh = CAST(AOME_SET_STATIC_THRESHOLD, args); |
1712 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
1713 | 0 | } |
1714 | | |
1715 | | static aom_codec_err_t ctrl_set_row_mt(aom_codec_alg_priv_t *ctx, |
1716 | 0 | va_list args) { |
1717 | 0 | unsigned int row_mt = CAST(AV1E_SET_ROW_MT, args); |
1718 | 0 | if (row_mt == ctx->extra_cfg.row_mt) return AOM_CODEC_OK; |
1719 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
1720 | 0 | extra_cfg.row_mt = row_mt; |
1721 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
1722 | 0 | } |
1723 | | |
1724 | | static aom_codec_err_t ctrl_set_tile_columns(aom_codec_alg_priv_t *ctx, |
1725 | 0 | va_list args) { |
1726 | | // If the control AUTO_TILES is used (set to 1) then don't override |
1727 | | // the tile_columns set via the AUTO_TILES control. |
1728 | 0 | if (ctx->extra_cfg.auto_tiles) { |
1729 | 0 | ERROR("AUTO_TILES is set so AV1E_SET_TILE_COLUMNS should not be called."); |
1730 | 0 | } |
1731 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
1732 | 0 | unsigned int tile_columns = CAST(AV1E_SET_TILE_COLUMNS, args); |
1733 | 0 | if (tile_columns == extra_cfg.tile_columns) return AOM_CODEC_OK; |
1734 | 0 | extra_cfg.tile_columns = tile_columns; |
1735 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
1736 | 0 | } |
1737 | | |
1738 | | static aom_codec_err_t ctrl_set_tile_rows(aom_codec_alg_priv_t *ctx, |
1739 | 0 | va_list args) { |
1740 | | // If the control AUTO_TILES is used (set to 1) then don't override |
1741 | | // the tile_rows set via the AUTO_TILES control. |
1742 | 0 | if (ctx->extra_cfg.auto_tiles) { |
1743 | 0 | ERROR("AUTO_TILES is set so AV1E_SET_TILE_ROWS should not be called."); |
1744 | 0 | } |
1745 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
1746 | 0 | unsigned int tile_rows = CAST(AV1E_SET_TILE_ROWS, args); |
1747 | 0 | if (tile_rows == extra_cfg.tile_rows) return AOM_CODEC_OK; |
1748 | 0 | extra_cfg.tile_rows = tile_rows; |
1749 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
1750 | 0 | } |
1751 | | |
1752 | | static aom_codec_err_t ctrl_set_enable_tpl_model(aom_codec_alg_priv_t *ctx, |
1753 | 0 | va_list args) { |
1754 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
1755 | 0 | const unsigned int tpl_model_arg = CAST(AV1E_SET_ENABLE_TPL_MODEL, args); |
1756 | | #if CONFIG_REALTIME_ONLY |
1757 | | if (tpl_model_arg) { |
1758 | | ERROR("TPL model can't be turned on in realtime only build."); |
1759 | | } |
1760 | | #endif |
1761 | 0 | extra_cfg.enable_tpl_model = tpl_model_arg; |
1762 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
1763 | 0 | } |
1764 | | |
1765 | | static aom_codec_err_t ctrl_set_enable_keyframe_filtering( |
1766 | 0 | aom_codec_alg_priv_t *ctx, va_list args) { |
1767 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
1768 | 0 | extra_cfg.enable_keyframe_filtering = |
1769 | 0 | CAST(AV1E_SET_ENABLE_KEYFRAME_FILTERING, args); |
1770 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
1771 | 0 | } |
1772 | | |
1773 | | static aom_codec_err_t ctrl_set_arnr_max_frames(aom_codec_alg_priv_t *ctx, |
1774 | 0 | va_list args) { |
1775 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
1776 | 0 | extra_cfg.arnr_max_frames = CAST(AOME_SET_ARNR_MAXFRAMES, args); |
1777 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
1778 | 0 | } |
1779 | | |
1780 | | static aom_codec_err_t ctrl_set_arnr_strength(aom_codec_alg_priv_t *ctx, |
1781 | 0 | va_list args) { |
1782 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
1783 | 0 | extra_cfg.arnr_strength = CAST(AOME_SET_ARNR_STRENGTH, args); |
1784 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
1785 | 0 | } |
1786 | | |
1787 | | static aom_codec_err_t handle_tuning(aom_codec_alg_priv_t *ctx, |
1788 | 0 | struct av1_extracfg *extra_cfg) { |
1789 | 0 | if (extra_cfg->tuning == AOM_TUNE_IQ) { |
1790 | 0 | if (ctx->cfg.g_usage != AOM_USAGE_ALL_INTRA) return AOM_CODEC_INCAPABLE; |
1791 | | // Enable QMs as they've been found to be beneficial for images, when used |
1792 | | // with alternative QM formulas: |
1793 | | // - aom_get_qmlevel_allintra() |
1794 | | // - aom_get_qmlevel_luma_iq() |
1795 | | // - aom_get_qmlevel_444_chroma_iq() |
1796 | 0 | extra_cfg->enable_qm = 1; |
1797 | 0 | extra_cfg->qm_min = QM_FIRST_IQ; |
1798 | 0 | extra_cfg->qm_max = QM_LAST_IQ; |
1799 | | // We can turn on loop filter sharpness, as frames do not have to serve as |
1800 | | // references to others. |
1801 | 0 | extra_cfg->sharpness = 7; |
1802 | | // Using the QM-PSNR metric was found to be beneficial for images (over the |
1803 | | // default PSNR metric), as it correlates better with subjective image |
1804 | | // quality consistency and better SSIMULACRA 2 scores. |
1805 | 0 | extra_cfg->dist_metric = AOM_DIST_METRIC_QM_PSNR; |
1806 | | // CDEF_ALL has been found to blur images at medium and high quality |
1807 | | // qindexes, so let's use a version that adapts CDEF strength on frame |
1808 | | // qindexes. CDEF_ADAPTIVE strengths look like this for varying qindexes: |
1809 | | // - CDEF off: 0 - 32 |
1810 | | // - Reduced strength: 33 - 220 |
1811 | | // - Full strength: 221 - 255 |
1812 | 0 | extra_cfg->enable_cdef = CDEF_ADAPTIVE; |
1813 | | // Enable chroma deltaq so the encoder can factor in chroma subsampling and |
1814 | | // adjust chroma quality when necessary. |
1815 | 0 | extra_cfg->enable_chroma_deltaq = 1; |
1816 | | // Enable "Variance Boost" deltaq mode, optimized for images. |
1817 | 0 | extra_cfg->deltaq_mode = DELTA_Q_VARIANCE_BOOST; |
1818 | 0 | } |
1819 | 0 | return AOM_CODEC_OK; |
1820 | 0 | } |
1821 | | |
1822 | | static aom_codec_err_t ctrl_set_tuning(aom_codec_alg_priv_t *ctx, |
1823 | 0 | va_list args) { |
1824 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
1825 | 0 | extra_cfg.tuning = CAST(AOME_SET_TUNING, args); |
1826 | 0 | aom_codec_err_t err = handle_tuning(ctx, &extra_cfg); |
1827 | 0 | if (err != AOM_CODEC_OK) return err; |
1828 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
1829 | 0 | } |
1830 | | |
1831 | | static aom_codec_err_t ctrl_set_cq_level(aom_codec_alg_priv_t *ctx, |
1832 | 0 | va_list args) { |
1833 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
1834 | 0 | extra_cfg.cq_level = CAST(AOME_SET_CQ_LEVEL, args); |
1835 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
1836 | 0 | } |
1837 | | |
1838 | | static aom_codec_err_t ctrl_set_rc_max_intra_bitrate_pct( |
1839 | 0 | aom_codec_alg_priv_t *ctx, va_list args) { |
1840 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
1841 | 0 | extra_cfg.rc_max_intra_bitrate_pct = |
1842 | 0 | CAST(AOME_SET_MAX_INTRA_BITRATE_PCT, args); |
1843 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
1844 | 0 | } |
1845 | | |
1846 | | static aom_codec_err_t ctrl_set_rc_max_inter_bitrate_pct( |
1847 | 0 | aom_codec_alg_priv_t *ctx, va_list args) { |
1848 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
1849 | 0 | extra_cfg.rc_max_inter_bitrate_pct = |
1850 | 0 | CAST(AOME_SET_MAX_INTER_BITRATE_PCT, args); |
1851 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
1852 | 0 | } |
1853 | | |
1854 | | static aom_codec_err_t ctrl_set_rc_gf_cbr_boost_pct(aom_codec_alg_priv_t *ctx, |
1855 | 0 | va_list args) { |
1856 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
1857 | 0 | extra_cfg.gf_cbr_boost_pct = CAST(AV1E_SET_GF_CBR_BOOST_PCT, args); |
1858 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
1859 | 0 | } |
1860 | | |
1861 | | static aom_codec_err_t ctrl_set_lossless(aom_codec_alg_priv_t *ctx, |
1862 | 0 | va_list args) { |
1863 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
1864 | 0 | extra_cfg.lossless = CAST(AV1E_SET_LOSSLESS, args); |
1865 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
1866 | 0 | } |
1867 | | |
1868 | | static aom_codec_err_t ctrl_set_enable_cdef(aom_codec_alg_priv_t *ctx, |
1869 | 0 | va_list args) { |
1870 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
1871 | 0 | extra_cfg.enable_cdef = CAST(AV1E_SET_ENABLE_CDEF, args); |
1872 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
1873 | 0 | } |
1874 | | |
1875 | | static aom_codec_err_t ctrl_set_enable_restoration(aom_codec_alg_priv_t *ctx, |
1876 | 0 | va_list args) { |
1877 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
1878 | 0 | const unsigned int restoration_arg = CAST(AV1E_SET_ENABLE_RESTORATION, args); |
1879 | | #if CONFIG_REALTIME_ONLY |
1880 | | if (restoration_arg) { |
1881 | | ERROR("Restoration can't be turned on in realtime only build."); |
1882 | | } |
1883 | | #endif |
1884 | 0 | extra_cfg.enable_restoration = restoration_arg; |
1885 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
1886 | 0 | } |
1887 | | |
1888 | | static aom_codec_err_t ctrl_set_force_video_mode(aom_codec_alg_priv_t *ctx, |
1889 | 0 | va_list args) { |
1890 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
1891 | 0 | extra_cfg.force_video_mode = CAST(AV1E_SET_FORCE_VIDEO_MODE, args); |
1892 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
1893 | 0 | } |
1894 | | |
1895 | | static aom_codec_err_t ctrl_set_enable_obmc(aom_codec_alg_priv_t *ctx, |
1896 | 0 | va_list args) { |
1897 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
1898 | 0 | const unsigned int obmc_arg = CAST(AV1E_SET_ENABLE_OBMC, args); |
1899 | | #if CONFIG_REALTIME_ONLY |
1900 | | if (obmc_arg) { |
1901 | | ERROR("OBMC can't be enabled in realtime only build."); |
1902 | | } |
1903 | | #endif |
1904 | 0 | extra_cfg.enable_obmc = obmc_arg; |
1905 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
1906 | 0 | } |
1907 | | |
1908 | | static aom_codec_err_t ctrl_set_disable_trellis_quant(aom_codec_alg_priv_t *ctx, |
1909 | 0 | va_list args) { |
1910 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
1911 | 0 | extra_cfg.disable_trellis_quant = CAST(AV1E_SET_DISABLE_TRELLIS_QUANT, args); |
1912 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
1913 | 0 | } |
1914 | | |
1915 | | static aom_codec_err_t ctrl_set_enable_qm(aom_codec_alg_priv_t *ctx, |
1916 | 0 | va_list args) { |
1917 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
1918 | 0 | extra_cfg.enable_qm = CAST(AV1E_SET_ENABLE_QM, args); |
1919 | | #if !CONFIG_QUANT_MATRIX |
1920 | | if (extra_cfg.enable_qm) { |
1921 | | ERROR("QM can't be enabled with CONFIG_QUANT_MATRIX=0."); |
1922 | | } |
1923 | | #endif |
1924 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
1925 | 0 | } |
1926 | 0 | static aom_codec_err_t ctrl_set_qm_y(aom_codec_alg_priv_t *ctx, va_list args) { |
1927 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
1928 | 0 | extra_cfg.qm_y = CAST(AV1E_SET_QM_Y, args); |
1929 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
1930 | 0 | } |
1931 | 0 | static aom_codec_err_t ctrl_set_qm_u(aom_codec_alg_priv_t *ctx, va_list args) { |
1932 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
1933 | 0 | extra_cfg.qm_u = CAST(AV1E_SET_QM_U, args); |
1934 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
1935 | 0 | } |
1936 | 0 | static aom_codec_err_t ctrl_set_qm_v(aom_codec_alg_priv_t *ctx, va_list args) { |
1937 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
1938 | 0 | extra_cfg.qm_v = CAST(AV1E_SET_QM_V, args); |
1939 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
1940 | 0 | } |
1941 | | static aom_codec_err_t ctrl_set_qm_min(aom_codec_alg_priv_t *ctx, |
1942 | 0 | va_list args) { |
1943 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
1944 | 0 | extra_cfg.qm_min = CAST(AV1E_SET_QM_MIN, args); |
1945 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
1946 | 0 | } |
1947 | | |
1948 | | static aom_codec_err_t ctrl_set_qm_max(aom_codec_alg_priv_t *ctx, |
1949 | 0 | va_list args) { |
1950 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
1951 | 0 | extra_cfg.qm_max = CAST(AV1E_SET_QM_MAX, args); |
1952 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
1953 | 0 | } |
1954 | | |
1955 | | static aom_codec_err_t ctrl_set_num_tg(aom_codec_alg_priv_t *ctx, |
1956 | 0 | va_list args) { |
1957 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
1958 | 0 | extra_cfg.num_tg = CAST(AV1E_SET_NUM_TG, args); |
1959 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
1960 | 0 | } |
1961 | | |
1962 | 0 | static aom_codec_err_t ctrl_set_mtu(aom_codec_alg_priv_t *ctx, va_list args) { |
1963 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
1964 | 0 | extra_cfg.mtu_size = CAST(AV1E_SET_MTU, args); |
1965 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
1966 | 0 | } |
1967 | | static aom_codec_err_t ctrl_set_timing_info_type(aom_codec_alg_priv_t *ctx, |
1968 | 0 | va_list args) { |
1969 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
1970 | 0 | extra_cfg.timing_info_type = CAST(AV1E_SET_TIMING_INFO_TYPE, args); |
1971 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
1972 | 0 | } |
1973 | | |
1974 | | static aom_codec_err_t ctrl_set_enable_dual_filter(aom_codec_alg_priv_t *ctx, |
1975 | 0 | va_list args) { |
1976 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
1977 | 0 | extra_cfg.enable_dual_filter = CAST(AV1E_SET_ENABLE_DUAL_FILTER, args); |
1978 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
1979 | 0 | } |
1980 | | |
1981 | | static aom_codec_err_t ctrl_set_enable_chroma_deltaq(aom_codec_alg_priv_t *ctx, |
1982 | 0 | va_list args) { |
1983 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
1984 | 0 | extra_cfg.enable_chroma_deltaq = CAST(AV1E_SET_ENABLE_CHROMA_DELTAQ, args); |
1985 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
1986 | 0 | } |
1987 | | |
1988 | | static aom_codec_err_t ctrl_set_enable_rect_partitions( |
1989 | 0 | aom_codec_alg_priv_t *ctx, va_list args) { |
1990 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
1991 | 0 | extra_cfg.enable_rect_partitions = |
1992 | 0 | CAST(AV1E_SET_ENABLE_RECT_PARTITIONS, args); |
1993 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
1994 | 0 | } |
1995 | | |
1996 | | static aom_codec_err_t ctrl_set_enable_ab_partitions(aom_codec_alg_priv_t *ctx, |
1997 | 0 | va_list args) { |
1998 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
1999 | 0 | extra_cfg.enable_ab_partitions = CAST(AV1E_SET_ENABLE_AB_PARTITIONS, args); |
2000 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
2001 | 0 | } |
2002 | | |
2003 | | static aom_codec_err_t ctrl_set_enable_1to4_partitions( |
2004 | 0 | aom_codec_alg_priv_t *ctx, va_list args) { |
2005 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
2006 | 0 | extra_cfg.enable_1to4_partitions = |
2007 | 0 | CAST(AV1E_SET_ENABLE_1TO4_PARTITIONS, args); |
2008 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
2009 | 0 | } |
2010 | | |
2011 | | static aom_codec_err_t ctrl_set_min_partition_size(aom_codec_alg_priv_t *ctx, |
2012 | 0 | va_list args) { |
2013 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
2014 | 0 | extra_cfg.min_partition_size = CAST(AV1E_SET_MIN_PARTITION_SIZE, args); |
2015 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
2016 | 0 | } |
2017 | | |
2018 | | static aom_codec_err_t ctrl_set_max_partition_size(aom_codec_alg_priv_t *ctx, |
2019 | 0 | va_list args) { |
2020 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
2021 | 0 | extra_cfg.max_partition_size = CAST(AV1E_SET_MAX_PARTITION_SIZE, args); |
2022 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
2023 | 0 | } |
2024 | | |
2025 | | static aom_codec_err_t ctrl_set_enable_intra_edge_filter( |
2026 | 0 | aom_codec_alg_priv_t *ctx, va_list args) { |
2027 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
2028 | 0 | extra_cfg.enable_intra_edge_filter = |
2029 | 0 | CAST(AV1E_SET_ENABLE_INTRA_EDGE_FILTER, args); |
2030 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
2031 | 0 | } |
2032 | | |
2033 | | static aom_codec_err_t ctrl_set_enable_order_hint(aom_codec_alg_priv_t *ctx, |
2034 | 0 | va_list args) { |
2035 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
2036 | 0 | extra_cfg.enable_order_hint = CAST(AV1E_SET_ENABLE_ORDER_HINT, args); |
2037 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
2038 | 0 | } |
2039 | | |
2040 | | static aom_codec_err_t ctrl_set_enable_tx64(aom_codec_alg_priv_t *ctx, |
2041 | 0 | va_list args) { |
2042 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
2043 | 0 | extra_cfg.enable_tx64 = CAST(AV1E_SET_ENABLE_TX64, args); |
2044 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
2045 | 0 | } |
2046 | | |
2047 | | static aom_codec_err_t ctrl_set_enable_flip_idtx(aom_codec_alg_priv_t *ctx, |
2048 | 0 | va_list args) { |
2049 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
2050 | 0 | extra_cfg.enable_flip_idtx = CAST(AV1E_SET_ENABLE_FLIP_IDTX, args); |
2051 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
2052 | 0 | } |
2053 | | |
2054 | | static aom_codec_err_t ctrl_set_enable_rect_tx(aom_codec_alg_priv_t *ctx, |
2055 | 0 | va_list args) { |
2056 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
2057 | 0 | extra_cfg.enable_rect_tx = CAST(AV1E_SET_ENABLE_RECT_TX, args); |
2058 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
2059 | 0 | } |
2060 | | |
2061 | | static aom_codec_err_t ctrl_set_enable_dist_wtd_comp(aom_codec_alg_priv_t *ctx, |
2062 | 0 | va_list args) { |
2063 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
2064 | 0 | extra_cfg.enable_dist_wtd_comp = CAST(AV1E_SET_ENABLE_DIST_WTD_COMP, args); |
2065 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
2066 | 0 | } |
2067 | | |
2068 | | static aom_codec_err_t ctrl_set_max_reference_frames(aom_codec_alg_priv_t *ctx, |
2069 | 0 | va_list args) { |
2070 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
2071 | 0 | extra_cfg.max_reference_frames = CAST(AV1E_SET_MAX_REFERENCE_FRAMES, args); |
2072 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
2073 | 0 | } |
2074 | | |
2075 | | static aom_codec_err_t ctrl_set_enable_reduced_reference_set( |
2076 | 0 | aom_codec_alg_priv_t *ctx, va_list args) { |
2077 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
2078 | 0 | extra_cfg.enable_reduced_reference_set = |
2079 | 0 | CAST(AV1E_SET_REDUCED_REFERENCE_SET, args); |
2080 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
2081 | 0 | } |
2082 | | |
2083 | | static aom_codec_err_t ctrl_set_enable_ref_frame_mvs(aom_codec_alg_priv_t *ctx, |
2084 | 0 | va_list args) { |
2085 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
2086 | 0 | extra_cfg.enable_ref_frame_mvs = CAST(AV1E_SET_ENABLE_REF_FRAME_MVS, args); |
2087 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
2088 | 0 | } |
2089 | | |
2090 | | static aom_codec_err_t ctrl_set_allow_ref_frame_mvs(aom_codec_alg_priv_t *ctx, |
2091 | 0 | va_list args) { |
2092 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
2093 | 0 | extra_cfg.allow_ref_frame_mvs = CAST(AV1E_SET_ALLOW_REF_FRAME_MVS, args); |
2094 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
2095 | 0 | } |
2096 | | |
2097 | | static aom_codec_err_t ctrl_set_enable_masked_comp(aom_codec_alg_priv_t *ctx, |
2098 | 0 | va_list args) { |
2099 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
2100 | 0 | extra_cfg.enable_masked_comp = CAST(AV1E_SET_ENABLE_MASKED_COMP, args); |
2101 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
2102 | 0 | } |
2103 | | |
2104 | | static aom_codec_err_t ctrl_set_enable_onesided_comp(aom_codec_alg_priv_t *ctx, |
2105 | 0 | va_list args) { |
2106 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
2107 | 0 | extra_cfg.enable_onesided_comp = CAST(AV1E_SET_ENABLE_ONESIDED_COMP, args); |
2108 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
2109 | 0 | } |
2110 | | |
2111 | | static aom_codec_err_t ctrl_set_enable_interintra_comp( |
2112 | 0 | aom_codec_alg_priv_t *ctx, va_list args) { |
2113 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
2114 | 0 | extra_cfg.enable_interintra_comp = |
2115 | 0 | CAST(AV1E_SET_ENABLE_INTERINTRA_COMP, args); |
2116 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
2117 | 0 | } |
2118 | | |
2119 | | static aom_codec_err_t ctrl_set_enable_smooth_interintra( |
2120 | 0 | aom_codec_alg_priv_t *ctx, va_list args) { |
2121 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
2122 | 0 | extra_cfg.enable_smooth_interintra = |
2123 | 0 | CAST(AV1E_SET_ENABLE_SMOOTH_INTERINTRA, args); |
2124 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
2125 | 0 | } |
2126 | | |
2127 | | static aom_codec_err_t ctrl_set_enable_diff_wtd_comp(aom_codec_alg_priv_t *ctx, |
2128 | 0 | va_list args) { |
2129 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
2130 | 0 | extra_cfg.enable_diff_wtd_comp = CAST(AV1E_SET_ENABLE_DIFF_WTD_COMP, args); |
2131 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
2132 | 0 | } |
2133 | | |
2134 | | static aom_codec_err_t ctrl_set_enable_interinter_wedge( |
2135 | 0 | aom_codec_alg_priv_t *ctx, va_list args) { |
2136 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
2137 | 0 | extra_cfg.enable_interinter_wedge = |
2138 | 0 | CAST(AV1E_SET_ENABLE_INTERINTER_WEDGE, args); |
2139 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
2140 | 0 | } |
2141 | | |
2142 | | static aom_codec_err_t ctrl_set_enable_interintra_wedge( |
2143 | 0 | aom_codec_alg_priv_t *ctx, va_list args) { |
2144 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
2145 | 0 | extra_cfg.enable_interintra_wedge = |
2146 | 0 | CAST(AV1E_SET_ENABLE_INTERINTRA_WEDGE, args); |
2147 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
2148 | 0 | } |
2149 | | |
2150 | | static aom_codec_err_t ctrl_set_enable_global_motion(aom_codec_alg_priv_t *ctx, |
2151 | 0 | va_list args) { |
2152 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
2153 | 0 | const int global_motion_arg = CAST(AV1E_SET_ENABLE_GLOBAL_MOTION, args); |
2154 | | #if CONFIG_REALTIME_ONLY |
2155 | | if (global_motion_arg) { |
2156 | | ERROR("Global motion can't be enabled in realtime only build."); |
2157 | | } |
2158 | | #endif |
2159 | 0 | extra_cfg.enable_global_motion = global_motion_arg; |
2160 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
2161 | 0 | } |
2162 | | |
2163 | | static aom_codec_err_t ctrl_set_enable_warped_motion(aom_codec_alg_priv_t *ctx, |
2164 | 0 | va_list args) { |
2165 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
2166 | 0 | const int warped_motion_arg = CAST(AV1E_SET_ENABLE_WARPED_MOTION, args); |
2167 | | #if CONFIG_REALTIME_ONLY |
2168 | | if (warped_motion_arg) { |
2169 | | ERROR("Warped motion can't be enabled in realtime only build."); |
2170 | | } |
2171 | | #endif |
2172 | 0 | extra_cfg.enable_warped_motion = warped_motion_arg; |
2173 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
2174 | 0 | } |
2175 | | |
2176 | | static aom_codec_err_t ctrl_set_allow_warped_motion(aom_codec_alg_priv_t *ctx, |
2177 | 0 | va_list args) { |
2178 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
2179 | 0 | extra_cfg.allow_warped_motion = CAST(AV1E_SET_ALLOW_WARPED_MOTION, args); |
2180 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
2181 | 0 | } |
2182 | | |
2183 | | static aom_codec_err_t ctrl_set_enable_filter_intra(aom_codec_alg_priv_t *ctx, |
2184 | 0 | va_list args) { |
2185 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
2186 | 0 | extra_cfg.enable_filter_intra = CAST(AV1E_SET_ENABLE_FILTER_INTRA, args); |
2187 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
2188 | 0 | } |
2189 | | |
2190 | | static aom_codec_err_t ctrl_set_enable_smooth_intra(aom_codec_alg_priv_t *ctx, |
2191 | 0 | va_list args) { |
2192 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
2193 | 0 | extra_cfg.enable_smooth_intra = CAST(AV1E_SET_ENABLE_SMOOTH_INTRA, args); |
2194 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
2195 | 0 | } |
2196 | | |
2197 | | static aom_codec_err_t ctrl_set_enable_directional_intra( |
2198 | 0 | aom_codec_alg_priv_t *ctx, va_list args) { |
2199 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
2200 | 0 | extra_cfg.enable_directional_intra = |
2201 | 0 | CAST(AV1E_SET_ENABLE_DIRECTIONAL_INTRA, args); |
2202 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
2203 | 0 | } |
2204 | | |
2205 | | static aom_codec_err_t ctrl_set_enable_diagonal_intra(aom_codec_alg_priv_t *ctx, |
2206 | 0 | va_list args) { |
2207 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
2208 | 0 | extra_cfg.enable_diagonal_intra = CAST(AV1E_SET_ENABLE_DIAGONAL_INTRA, args); |
2209 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
2210 | 0 | } |
2211 | | |
2212 | | static aom_codec_err_t ctrl_set_enable_paeth_intra(aom_codec_alg_priv_t *ctx, |
2213 | 0 | va_list args) { |
2214 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
2215 | 0 | extra_cfg.enable_paeth_intra = CAST(AV1E_SET_ENABLE_PAETH_INTRA, args); |
2216 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
2217 | 0 | } |
2218 | | |
2219 | | static aom_codec_err_t ctrl_set_enable_cfl_intra(aom_codec_alg_priv_t *ctx, |
2220 | 0 | va_list args) { |
2221 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
2222 | 0 | extra_cfg.enable_cfl_intra = CAST(AV1E_SET_ENABLE_CFL_INTRA, args); |
2223 | | #if CONFIG_REALTIME_ONLY |
2224 | | if (extra_cfg.enable_cfl_intra) { |
2225 | | ERROR("cfl can't be turned on in realtime only build."); |
2226 | | } |
2227 | | #endif |
2228 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
2229 | 0 | } |
2230 | | |
2231 | | static aom_codec_err_t ctrl_set_enable_superres(aom_codec_alg_priv_t *ctx, |
2232 | 0 | va_list args) { |
2233 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
2234 | 0 | extra_cfg.enable_superres = CAST(AV1E_SET_ENABLE_SUPERRES, args); |
2235 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
2236 | 0 | } |
2237 | | |
2238 | | static aom_codec_err_t ctrl_set_enable_overlay(aom_codec_alg_priv_t *ctx, |
2239 | 0 | va_list args) { |
2240 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
2241 | 0 | extra_cfg.enable_overlay = CAST(AV1E_SET_ENABLE_OVERLAY, args); |
2242 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
2243 | 0 | } |
2244 | | |
2245 | | static aom_codec_err_t ctrl_set_enable_palette(aom_codec_alg_priv_t *ctx, |
2246 | 0 | va_list args) { |
2247 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
2248 | 0 | extra_cfg.enable_palette = CAST(AV1E_SET_ENABLE_PALETTE, args); |
2249 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
2250 | 0 | } |
2251 | | |
2252 | | static aom_codec_err_t ctrl_set_enable_intrabc(aom_codec_alg_priv_t *ctx, |
2253 | 0 | va_list args) { |
2254 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
2255 | 0 | extra_cfg.enable_intrabc = CAST(AV1E_SET_ENABLE_INTRABC, args); |
2256 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
2257 | 0 | } |
2258 | | |
2259 | | static aom_codec_err_t ctrl_set_enable_angle_delta(aom_codec_alg_priv_t *ctx, |
2260 | 0 | va_list args) { |
2261 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
2262 | 0 | extra_cfg.enable_angle_delta = CAST(AV1E_SET_ENABLE_ANGLE_DELTA, args); |
2263 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
2264 | 0 | } |
2265 | | |
2266 | | static aom_codec_err_t ctrl_set_error_resilient_mode(aom_codec_alg_priv_t *ctx, |
2267 | 0 | va_list args) { |
2268 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
2269 | 0 | extra_cfg.error_resilient_mode = CAST(AV1E_SET_ERROR_RESILIENT_MODE, args); |
2270 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
2271 | 0 | } |
2272 | | |
2273 | | static aom_codec_err_t ctrl_set_s_frame_mode(aom_codec_alg_priv_t *ctx, |
2274 | 0 | va_list args) { |
2275 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
2276 | 0 | extra_cfg.s_frame_mode = CAST(AV1E_SET_S_FRAME_MODE, args); |
2277 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
2278 | 0 | } |
2279 | | |
2280 | | static aom_codec_err_t ctrl_set_frame_parallel_decoding_mode( |
2281 | 0 | aom_codec_alg_priv_t *ctx, va_list args) { |
2282 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
2283 | 0 | extra_cfg.frame_parallel_decoding_mode = |
2284 | 0 | CAST(AV1E_SET_FRAME_PARALLEL_DECODING, args); |
2285 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
2286 | 0 | } |
2287 | | |
2288 | | static aom_codec_err_t ctrl_set_single_tile_decoding(aom_codec_alg_priv_t *ctx, |
2289 | 0 | va_list args) { |
2290 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
2291 | 0 | extra_cfg.single_tile_decoding = CAST(AV1E_SET_SINGLE_TILE_DECODING, args); |
2292 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
2293 | 0 | } |
2294 | | |
2295 | | static aom_codec_err_t ctrl_set_aq_mode(aom_codec_alg_priv_t *ctx, |
2296 | 0 | va_list args) { |
2297 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
2298 | 0 | extra_cfg.aq_mode = CAST(AV1E_SET_AQ_MODE, args); |
2299 | | |
2300 | | // Skip AQ mode if using fixed QP for current frame. |
2301 | 0 | if (ctx->ppi->cpi->rc.use_external_qp_one_pass) extra_cfg.aq_mode = 0; |
2302 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
2303 | 0 | } |
2304 | | |
2305 | | static aom_codec_err_t ctrl_set_reduced_tx_type_set(aom_codec_alg_priv_t *ctx, |
2306 | 0 | va_list args) { |
2307 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
2308 | 0 | extra_cfg.reduced_tx_type_set = CAST(AV1E_SET_REDUCED_TX_TYPE_SET, args); |
2309 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
2310 | 0 | } |
2311 | | |
2312 | | static aom_codec_err_t ctrl_set_intra_dct_only(aom_codec_alg_priv_t *ctx, |
2313 | 0 | va_list args) { |
2314 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
2315 | 0 | extra_cfg.use_intra_dct_only = CAST(AV1E_SET_INTRA_DCT_ONLY, args); |
2316 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
2317 | 0 | } |
2318 | | |
2319 | | static aom_codec_err_t ctrl_set_inter_dct_only(aom_codec_alg_priv_t *ctx, |
2320 | 0 | va_list args) { |
2321 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
2322 | 0 | extra_cfg.use_inter_dct_only = CAST(AV1E_SET_INTER_DCT_ONLY, args); |
2323 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
2324 | 0 | } |
2325 | | |
2326 | | static aom_codec_err_t ctrl_set_intra_default_tx_only(aom_codec_alg_priv_t *ctx, |
2327 | 0 | va_list args) { |
2328 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
2329 | 0 | extra_cfg.use_intra_default_tx_only = |
2330 | 0 | CAST(AV1E_SET_INTRA_DEFAULT_TX_ONLY, args); |
2331 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
2332 | 0 | } |
2333 | | |
2334 | | static aom_codec_err_t ctrl_set_enable_tx_size_search(aom_codec_alg_priv_t *ctx, |
2335 | 0 | va_list args) { |
2336 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
2337 | 0 | extra_cfg.enable_tx_size_search = CAST(AV1E_SET_ENABLE_TX_SIZE_SEARCH, args); |
2338 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
2339 | 0 | } |
2340 | | |
2341 | | static aom_codec_err_t ctrl_set_quant_b_adapt(aom_codec_alg_priv_t *ctx, |
2342 | 0 | va_list args) { |
2343 | | #if CONFIG_REALTIME_ONLY |
2344 | | (void)ctx; |
2345 | | (void)args; |
2346 | | return AOM_CODEC_INCAPABLE; |
2347 | | #else |
2348 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
2349 | 0 | extra_cfg.quant_b_adapt = CAST(AV1E_SET_QUANT_B_ADAPT, args); |
2350 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
2351 | 0 | #endif |
2352 | 0 | } |
2353 | | |
2354 | | static aom_codec_err_t ctrl_set_vbr_corpus_complexity_lap( |
2355 | 0 | aom_codec_alg_priv_t *ctx, va_list args) { |
2356 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
2357 | 0 | extra_cfg.vbr_corpus_complexity_lap = |
2358 | 0 | CAST(AV1E_SET_VBR_CORPUS_COMPLEXITY_LAP, args); |
2359 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
2360 | 0 | } |
2361 | | static aom_codec_err_t ctrl_set_coeff_cost_upd_freq(aom_codec_alg_priv_t *ctx, |
2362 | 0 | va_list args) { |
2363 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
2364 | 0 | extra_cfg.coeff_cost_upd_freq = CAST(AV1E_SET_COEFF_COST_UPD_FREQ, args); |
2365 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
2366 | 0 | } |
2367 | | |
2368 | | static aom_codec_err_t ctrl_set_mode_cost_upd_freq(aom_codec_alg_priv_t *ctx, |
2369 | 0 | va_list args) { |
2370 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
2371 | 0 | extra_cfg.mode_cost_upd_freq = CAST(AV1E_SET_MODE_COST_UPD_FREQ, args); |
2372 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
2373 | 0 | } |
2374 | | |
2375 | | static aom_codec_err_t ctrl_set_mv_cost_upd_freq(aom_codec_alg_priv_t *ctx, |
2376 | 0 | va_list args) { |
2377 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
2378 | 0 | extra_cfg.mv_cost_upd_freq = CAST(AV1E_SET_MV_COST_UPD_FREQ, args); |
2379 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
2380 | 0 | } |
2381 | | |
2382 | | static aom_codec_err_t ctrl_set_dv_cost_upd_freq(aom_codec_alg_priv_t *ctx, |
2383 | 0 | va_list args) { |
2384 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
2385 | 0 | extra_cfg.dv_cost_upd_freq = CAST(AV1E_SET_DV_COST_UPD_FREQ, args); |
2386 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
2387 | 0 | } |
2388 | | |
2389 | | static aom_codec_err_t ctrl_set_vmaf_model_path(aom_codec_alg_priv_t *ctx, |
2390 | 0 | va_list args) { |
2391 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
2392 | 0 | const char *str = CAST(AV1E_SET_VMAF_MODEL_PATH, args); |
2393 | 0 | const aom_codec_err_t ret = allocate_and_set_string( |
2394 | 0 | str, default_extra_cfg.vmaf_model_path, &extra_cfg.vmaf_model_path, |
2395 | 0 | ctx->ppi->error.detail); |
2396 | 0 | if (ret != AOM_CODEC_OK) return ret; |
2397 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
2398 | 0 | } |
2399 | | |
2400 | | static aom_codec_err_t ctrl_set_partition_info_path(aom_codec_alg_priv_t *ctx, |
2401 | 0 | va_list args) { |
2402 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
2403 | 0 | const char *str = CAST(AV1E_SET_PARTITION_INFO_PATH, args); |
2404 | 0 | const aom_codec_err_t ret = allocate_and_set_string( |
2405 | 0 | str, default_extra_cfg.partition_info_path, |
2406 | 0 | &extra_cfg.partition_info_path, ctx->ppi->error.detail); |
2407 | 0 | if (ret != AOM_CODEC_OK) return ret; |
2408 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
2409 | 0 | } |
2410 | | |
2411 | | static aom_codec_err_t ctrl_enable_rate_guide_deltaq(aom_codec_alg_priv_t *ctx, |
2412 | 0 | va_list args) { |
2413 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
2414 | 0 | extra_cfg.enable_rate_guide_deltaq = |
2415 | 0 | CAST(AV1E_ENABLE_RATE_GUIDE_DELTAQ, args); |
2416 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
2417 | 0 | } |
2418 | | |
2419 | | static aom_codec_err_t ctrl_set_rate_distribution_info( |
2420 | 0 | aom_codec_alg_priv_t *ctx, va_list args) { |
2421 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
2422 | 0 | const char *str = CAST(AV1E_SET_RATE_DISTRIBUTION_INFO, args); |
2423 | 0 | const aom_codec_err_t ret = allocate_and_set_string( |
2424 | 0 | str, default_extra_cfg.rate_distribution_info, |
2425 | 0 | &extra_cfg.rate_distribution_info, ctx->ppi->error.detail); |
2426 | 0 | if (ret != AOM_CODEC_OK) return ret; |
2427 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
2428 | 0 | } |
2429 | | |
2430 | | static aom_codec_err_t ctrl_set_film_grain_test_vector( |
2431 | 0 | aom_codec_alg_priv_t *ctx, va_list args) { |
2432 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
2433 | 0 | extra_cfg.film_grain_test_vector = |
2434 | 0 | CAST(AV1E_SET_FILM_GRAIN_TEST_VECTOR, args); |
2435 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
2436 | 0 | } |
2437 | | |
2438 | | static aom_codec_err_t ctrl_set_film_grain_table(aom_codec_alg_priv_t *ctx, |
2439 | 0 | va_list args) { |
2440 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
2441 | 0 | const char *str = CAST(AV1E_SET_FILM_GRAIN_TABLE, args); |
2442 | 0 | if (str == NULL) { |
2443 | | // this parameter allows NULL as its value |
2444 | 0 | extra_cfg.film_grain_table_filename = str; |
2445 | 0 | } else { |
2446 | | #if CONFIG_REALTIME_ONLY |
2447 | | ERROR("film_grain removed from realtime only build."); |
2448 | | #endif |
2449 | 0 | const aom_codec_err_t ret = allocate_and_set_string( |
2450 | 0 | str, default_extra_cfg.film_grain_table_filename, |
2451 | 0 | &extra_cfg.film_grain_table_filename, ctx->ppi->error.detail); |
2452 | 0 | if (ret != AOM_CODEC_OK) return ret; |
2453 | 0 | } |
2454 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
2455 | 0 | } |
2456 | | |
2457 | | static aom_codec_err_t ctrl_set_denoise_noise_level(aom_codec_alg_priv_t *ctx, |
2458 | 0 | va_list args) { |
2459 | | #if !CONFIG_DENOISE |
2460 | | (void)ctx; |
2461 | | (void)args; |
2462 | | return AOM_CODEC_INCAPABLE; |
2463 | | #else |
2464 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
2465 | 0 | extra_cfg.noise_level = |
2466 | 0 | ((float)CAST(AV1E_SET_DENOISE_NOISE_LEVEL, args)) / 10.0f; |
2467 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
2468 | 0 | #endif |
2469 | 0 | } |
2470 | | |
2471 | | static aom_codec_err_t ctrl_set_denoise_block_size(aom_codec_alg_priv_t *ctx, |
2472 | 0 | va_list args) { |
2473 | | #if !CONFIG_DENOISE |
2474 | | (void)ctx; |
2475 | | (void)args; |
2476 | | return AOM_CODEC_INCAPABLE; |
2477 | | #else |
2478 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
2479 | 0 | extra_cfg.noise_block_size = CAST(AV1E_SET_DENOISE_BLOCK_SIZE, args); |
2480 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
2481 | 0 | #endif |
2482 | 0 | } |
2483 | | |
2484 | | static aom_codec_err_t ctrl_set_enable_dnl_denoising(aom_codec_alg_priv_t *ctx, |
2485 | 0 | va_list args) { |
2486 | | #if !CONFIG_DENOISE |
2487 | | (void)ctx; |
2488 | | (void)args; |
2489 | | return AOM_CODEC_INCAPABLE; |
2490 | | #else |
2491 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
2492 | 0 | extra_cfg.enable_dnl_denoising = CAST(AV1E_SET_ENABLE_DNL_DENOISING, args); |
2493 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
2494 | 0 | #endif |
2495 | 0 | } |
2496 | | |
2497 | | static aom_codec_err_t ctrl_set_deltaq_mode(aom_codec_alg_priv_t *ctx, |
2498 | 0 | va_list args) { |
2499 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
2500 | 0 | const DELTAQ_MODE deltaq_arg = CAST(AV1E_SET_DELTAQ_MODE, args); |
2501 | | #if CONFIG_REALTIME_ONLY |
2502 | | if (deltaq_arg > NO_DELTA_Q) { |
2503 | | ERROR("Delta Q mode can't be enabled in realtime only build."); |
2504 | | } |
2505 | | #endif |
2506 | 0 | extra_cfg.deltaq_mode = deltaq_arg; |
2507 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
2508 | 0 | } |
2509 | | |
2510 | | static aom_codec_err_t ctrl_set_deltaq_strength(aom_codec_alg_priv_t *ctx, |
2511 | 0 | va_list args) { |
2512 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
2513 | 0 | extra_cfg.deltaq_strength = CAST(AV1E_SET_DELTAQ_STRENGTH, args); |
2514 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
2515 | 0 | } |
2516 | | |
2517 | | static aom_codec_err_t ctrl_set_deltalf_mode(aom_codec_alg_priv_t *ctx, |
2518 | 0 | va_list args) { |
2519 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
2520 | 0 | extra_cfg.deltalf_mode = CAST(AV1E_SET_DELTALF_MODE, args); |
2521 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
2522 | 0 | } |
2523 | | |
2524 | | static aom_codec_err_t ctrl_set_min_gf_interval(aom_codec_alg_priv_t *ctx, |
2525 | 0 | va_list args) { |
2526 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
2527 | 0 | extra_cfg.min_gf_interval = CAST(AV1E_SET_MIN_GF_INTERVAL, args); |
2528 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
2529 | 0 | } |
2530 | | |
2531 | | static aom_codec_err_t ctrl_set_max_gf_interval(aom_codec_alg_priv_t *ctx, |
2532 | 0 | va_list args) { |
2533 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
2534 | 0 | extra_cfg.max_gf_interval = CAST(AV1E_SET_MAX_GF_INTERVAL, args); |
2535 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
2536 | 0 | } |
2537 | | |
2538 | | static aom_codec_err_t ctrl_set_gf_min_pyr_height(aom_codec_alg_priv_t *ctx, |
2539 | 0 | va_list args) { |
2540 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
2541 | 0 | extra_cfg.gf_min_pyr_height = CAST(AV1E_SET_GF_MIN_PYRAMID_HEIGHT, args); |
2542 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
2543 | 0 | } |
2544 | | |
2545 | | static aom_codec_err_t ctrl_set_gf_max_pyr_height(aom_codec_alg_priv_t *ctx, |
2546 | 0 | va_list args) { |
2547 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
2548 | 0 | extra_cfg.gf_max_pyr_height = CAST(AV1E_SET_GF_MAX_PYRAMID_HEIGHT, args); |
2549 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
2550 | 0 | } |
2551 | | |
2552 | | static aom_codec_err_t ctrl_set_frame_periodic_boost(aom_codec_alg_priv_t *ctx, |
2553 | 0 | va_list args) { |
2554 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
2555 | 0 | extra_cfg.frame_periodic_boost = CAST(AV1E_SET_FRAME_PERIODIC_BOOST, args); |
2556 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
2557 | 0 | } |
2558 | | |
2559 | | static aom_codec_err_t ctrl_enable_motion_vector_unit_test( |
2560 | 0 | aom_codec_alg_priv_t *ctx, va_list args) { |
2561 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
2562 | 0 | extra_cfg.motion_vector_unit_test = |
2563 | 0 | CAST(AV1E_ENABLE_MOTION_VECTOR_UNIT_TEST, args); |
2564 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
2565 | 0 | } |
2566 | | |
2567 | | static aom_codec_err_t ctrl_enable_fpmt_unit_test(aom_codec_alg_priv_t *ctx, |
2568 | 0 | va_list args) { |
2569 | 0 | #if !CONFIG_FPMT_TEST |
2570 | 0 | (void)args; |
2571 | 0 | (void)ctx; |
2572 | 0 | return AOM_CODEC_INCAPABLE; |
2573 | | #else |
2574 | | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
2575 | | extra_cfg.fpmt_unit_test = CAST(AV1E_SET_FP_MT_UNIT_TEST, args); |
2576 | | ctx->ppi->fpmt_unit_test_cfg = (extra_cfg.fpmt_unit_test == 1) |
2577 | | ? PARALLEL_ENCODE |
2578 | | : PARALLEL_SIMULATION_ENCODE; |
2579 | | return update_extra_cfg(ctx, &extra_cfg); |
2580 | | #endif |
2581 | 0 | } |
2582 | | |
2583 | | static aom_codec_err_t ctrl_enable_ext_tile_debug(aom_codec_alg_priv_t *ctx, |
2584 | 0 | va_list args) { |
2585 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
2586 | 0 | extra_cfg.ext_tile_debug = CAST(AV1E_ENABLE_EXT_TILE_DEBUG, args); |
2587 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
2588 | 0 | } |
2589 | | |
2590 | | static aom_codec_err_t ctrl_set_target_seq_level_idx(aom_codec_alg_priv_t *ctx, |
2591 | 0 | va_list args) { |
2592 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
2593 | 0 | const int val = CAST(AV1E_SET_TARGET_SEQ_LEVEL_IDX, args); |
2594 | 0 | const int level = val % 100; |
2595 | 0 | const int operating_point_idx = val / 100; |
2596 | 0 | if (operating_point_idx < 0 || |
2597 | 0 | operating_point_idx >= MAX_NUM_OPERATING_POINTS) { |
2598 | 0 | char *const err_string = ctx->ppi->error.detail; |
2599 | 0 | snprintf(err_string, ARG_ERR_MSG_MAX_LEN, |
2600 | 0 | "Invalid operating point index: %d", operating_point_idx); |
2601 | 0 | ctx->base.err_detail = err_string; |
2602 | 0 | return AOM_CODEC_INVALID_PARAM; |
2603 | 0 | } |
2604 | 0 | extra_cfg.target_seq_level_idx[operating_point_idx] = (AV1_LEVEL)level; |
2605 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
2606 | 0 | } |
2607 | | |
2608 | | static aom_codec_err_t ctrl_set_tier_mask(aom_codec_alg_priv_t *ctx, |
2609 | 0 | va_list args) { |
2610 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
2611 | 0 | extra_cfg.tier_mask = CAST(AV1E_SET_TIER_MASK, args); |
2612 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
2613 | 0 | } |
2614 | | |
2615 | | static aom_codec_err_t ctrl_set_min_cr(aom_codec_alg_priv_t *ctx, |
2616 | 0 | va_list args) { |
2617 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
2618 | 0 | extra_cfg.min_cr = CAST(AV1E_SET_MIN_CR, args); |
2619 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
2620 | 0 | } |
2621 | | |
2622 | | static aom_codec_err_t ctrl_enable_sb_multipass_unit_test( |
2623 | 0 | aom_codec_alg_priv_t *ctx, va_list args) { |
2624 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
2625 | 0 | extra_cfg.sb_multipass_unit_test = |
2626 | 0 | CAST(AV1E_ENABLE_SB_MULTIPASS_UNIT_TEST, args); |
2627 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
2628 | 0 | } |
2629 | | |
2630 | | static aom_codec_err_t ctrl_enable_sb_qp_sweep(aom_codec_alg_priv_t *ctx, |
2631 | 0 | va_list args) { |
2632 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
2633 | 0 | extra_cfg.sb_qp_sweep = CAST(AV1E_ENABLE_SB_QP_SWEEP, args); |
2634 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
2635 | 0 | } |
2636 | | |
2637 | | static aom_codec_err_t ctrl_set_external_partition(aom_codec_alg_priv_t *ctx, |
2638 | 0 | va_list args) { |
2639 | 0 | AV1_COMP *const cpi = ctx->ppi->cpi; |
2640 | 0 | aom_ext_part_funcs_t funcs = *CAST(AV1E_SET_EXTERNAL_PARTITION, args); |
2641 | 0 | aom_ext_part_config_t config; |
2642 | | // TODO(chengchen): verify the sb_size has been set at this point. |
2643 | 0 | config.superblock_size = cpi->common.seq_params->sb_size; |
2644 | 0 | const aom_codec_err_t status = |
2645 | 0 | av1_ext_part_create(funcs, config, &cpi->ext_part_controller); |
2646 | 0 | return status; |
2647 | 0 | } |
2648 | | |
2649 | | static aom_codec_err_t ctrl_set_loopfilter_control(aom_codec_alg_priv_t *ctx, |
2650 | 0 | va_list args) { |
2651 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
2652 | 0 | extra_cfg.loopfilter_control = CAST(AV1E_SET_LOOPFILTER_CONTROL, args); |
2653 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
2654 | 0 | } |
2655 | | |
2656 | | static aom_codec_err_t ctrl_set_skip_postproc_filtering( |
2657 | 0 | aom_codec_alg_priv_t *ctx, va_list args) { |
2658 | | // Skipping the application of post-processing filters is allowed only |
2659 | | // for ALLINTRA mode. |
2660 | 0 | if (ctx->cfg.g_usage != AOM_USAGE_ALL_INTRA) return AOM_CODEC_INCAPABLE; |
2661 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
2662 | 0 | extra_cfg.skip_postproc_filtering = |
2663 | 0 | CAST(AV1E_SET_SKIP_POSTPROC_FILTERING, args); |
2664 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
2665 | 0 | } |
2666 | | |
2667 | | static aom_codec_err_t ctrl_set_rtc_external_rc(aom_codec_alg_priv_t *ctx, |
2668 | 0 | va_list args) { |
2669 | 0 | ctx->ppi->cpi->rc.rtc_external_ratectrl = |
2670 | 0 | CAST(AV1E_SET_RTC_EXTERNAL_RC, args); |
2671 | 0 | return AOM_CODEC_OK; |
2672 | 0 | } |
2673 | | |
2674 | | static aom_codec_err_t ctrl_set_quantizer_one_pass(aom_codec_alg_priv_t *ctx, |
2675 | 0 | va_list args) { |
2676 | 0 | const int qp = CAST(AV1E_SET_QUANTIZER_ONE_PASS, args); |
2677 | |
|
2678 | 0 | if (qp < 0 || qp > 63) return AOM_CODEC_INVALID_PARAM; |
2679 | | |
2680 | 0 | aom_codec_enc_cfg_t *cfg = &ctx->cfg; |
2681 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
2682 | 0 | cfg->rc_min_quantizer = cfg->rc_max_quantizer = qp; |
2683 | 0 | extra_cfg.aq_mode = 0; |
2684 | 0 | ctx->ppi->cpi->rc.use_external_qp_one_pass = 1; |
2685 | |
|
2686 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
2687 | 0 | } |
2688 | | |
2689 | | static aom_codec_err_t ctrl_set_bitrate_one_pass_cbr(aom_codec_alg_priv_t *ctx, |
2690 | 0 | va_list args) { |
2691 | 0 | AV1_PRIMARY *const ppi = ctx->ppi; |
2692 | 0 | AV1_COMP *const cpi = ppi->cpi; |
2693 | 0 | AV1EncoderConfig *oxcf = &cpi->oxcf; |
2694 | 0 | if (!is_one_pass_rt_params(cpi) || oxcf->rc_cfg.mode != AOM_CBR || |
2695 | 0 | cpi->ppi->use_svc || ppi->num_fp_contexts != 1 || ppi->cpi_lap != NULL) { |
2696 | 0 | return AOM_CODEC_INVALID_PARAM; |
2697 | 0 | } |
2698 | 0 | const int new_bitrate = CAST(AV1E_SET_BITRATE_ONE_PASS_CBR, args); |
2699 | 0 | ctx->cfg.rc_target_bitrate = new_bitrate; |
2700 | 0 | oxcf->rc_cfg.target_bandwidth = new_bitrate * 1000; |
2701 | 0 | set_primary_rc_buffer_sizes(oxcf, ppi); |
2702 | 0 | av1_new_framerate(cpi, cpi->framerate); |
2703 | 0 | check_reset_rc_flag(cpi); |
2704 | 0 | return AOM_CODEC_OK; |
2705 | 0 | } |
2706 | | |
2707 | | static aom_codec_err_t ctrl_set_max_consec_frame_drop_cbr( |
2708 | 0 | aom_codec_alg_priv_t *ctx, va_list args) { |
2709 | 0 | AV1_PRIMARY *const ppi = ctx->ppi; |
2710 | 0 | AV1_COMP *const cpi = ppi->cpi; |
2711 | 0 | const int max_consec_drop = CAST(AV1E_SET_MAX_CONSEC_FRAME_DROP_CBR, args); |
2712 | 0 | if (max_consec_drop < 0) return AOM_CODEC_INVALID_PARAM; |
2713 | 0 | cpi->rc.max_consec_drop = max_consec_drop; |
2714 | 0 | cpi->rc.drop_count_consec = 0; |
2715 | 0 | return AOM_CODEC_OK; |
2716 | 0 | } |
2717 | | |
2718 | | static aom_codec_err_t ctrl_set_max_consec_frame_drop_ms_cbr( |
2719 | 0 | aom_codec_alg_priv_t *ctx, va_list args) { |
2720 | 0 | AV1_PRIMARY *const ppi = ctx->ppi; |
2721 | 0 | AV1_COMP *const cpi = ppi->cpi; |
2722 | 0 | const int max_consec_drop_ms = |
2723 | 0 | CAST(AV1E_SET_MAX_CONSEC_FRAME_DROP_MS_CBR, args); |
2724 | 0 | if (max_consec_drop_ms < 0) return AOM_CODEC_INVALID_PARAM; |
2725 | | // max_consec_drop_ms will be converted to frame units inside encoder |
2726 | | // based on framerate (which can change dynamically). |
2727 | 0 | ctx->oxcf.rc_cfg.max_consec_drop_ms = max_consec_drop_ms; |
2728 | 0 | cpi->rc.drop_count_consec = 0; |
2729 | 0 | return AOM_CODEC_OK; |
2730 | 0 | } |
2731 | | |
2732 | | static aom_codec_err_t ctrl_set_svc_frame_drop_mode(aom_codec_alg_priv_t *ctx, |
2733 | 0 | va_list args) { |
2734 | 0 | AV1_PRIMARY *const ppi = ctx->ppi; |
2735 | 0 | AV1_COMP *const cpi = ppi->cpi; |
2736 | 0 | cpi->svc.framedrop_mode = CAST(AV1E_SET_SVC_FRAME_DROP_MODE, args); |
2737 | 0 | if (cpi->svc.framedrop_mode != AOM_LAYER_DROP && |
2738 | 0 | cpi->svc.framedrop_mode != AOM_FULL_SUPERFRAME_DROP) |
2739 | 0 | return AOM_CODEC_INVALID_PARAM; |
2740 | 0 | else |
2741 | 0 | return AOM_CODEC_OK; |
2742 | 0 | } |
2743 | | |
2744 | | static aom_codec_err_t ctrl_set_auto_tiles(aom_codec_alg_priv_t *ctx, |
2745 | 0 | va_list args) { |
2746 | 0 | unsigned int auto_tiles = CAST(AV1E_SET_AUTO_TILES, args); |
2747 | 0 | if (auto_tiles == ctx->extra_cfg.auto_tiles) return AOM_CODEC_OK; |
2748 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
2749 | 0 | extra_cfg.auto_tiles = auto_tiles; |
2750 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
2751 | 0 | } |
2752 | | |
2753 | | static aom_codec_err_t ctrl_set_postencode_drop_rtc(aom_codec_alg_priv_t *ctx, |
2754 | 0 | va_list args) { |
2755 | 0 | AV1_PRIMARY *const ppi = ctx->ppi; |
2756 | 0 | AV1_COMP *const cpi = ppi->cpi; |
2757 | 0 | int enable_postencode_drop = CAST(AV1E_SET_POSTENCODE_DROP_RTC, args); |
2758 | 0 | if (enable_postencode_drop > 1 || enable_postencode_drop < 0) |
2759 | 0 | return AOM_CODEC_INVALID_PARAM; |
2760 | 0 | cpi->rc.postencode_drop = enable_postencode_drop; |
2761 | 0 | return AOM_CODEC_OK; |
2762 | 0 | } |
2763 | | |
2764 | | #if !CONFIG_REALTIME_ONLY |
2765 | | static aom_codec_err_t create_stats_buffer(FIRSTPASS_STATS **frame_stats_buffer, |
2766 | | STATS_BUFFER_CTX *stats_buf_context, |
2767 | 0 | int num_lap_buffers) { |
2768 | 0 | aom_codec_err_t res = AOM_CODEC_OK; |
2769 | |
|
2770 | 0 | int size = get_stats_buf_size(num_lap_buffers, MAX_LAG_BUFFERS); |
2771 | 0 | *frame_stats_buffer = |
2772 | 0 | (FIRSTPASS_STATS *)aom_calloc(size, sizeof(FIRSTPASS_STATS)); |
2773 | 0 | if (*frame_stats_buffer == NULL) return AOM_CODEC_MEM_ERROR; |
2774 | | |
2775 | 0 | stats_buf_context->stats_in_start = *frame_stats_buffer; |
2776 | 0 | stats_buf_context->stats_in_end = stats_buf_context->stats_in_start; |
2777 | 0 | stats_buf_context->stats_in_buf_end = |
2778 | 0 | stats_buf_context->stats_in_start + size; |
2779 | |
|
2780 | 0 | stats_buf_context->total_left_stats = aom_calloc(1, sizeof(FIRSTPASS_STATS)); |
2781 | 0 | if (stats_buf_context->total_left_stats == NULL) return AOM_CODEC_MEM_ERROR; |
2782 | 0 | av1_twopass_zero_stats(stats_buf_context->total_left_stats); |
2783 | 0 | stats_buf_context->total_stats = aom_calloc(1, sizeof(FIRSTPASS_STATS)); |
2784 | 0 | if (stats_buf_context->total_stats == NULL) return AOM_CODEC_MEM_ERROR; |
2785 | 0 | av1_twopass_zero_stats(stats_buf_context->total_stats); |
2786 | 0 | return res; |
2787 | 0 | } |
2788 | | #endif |
2789 | | |
2790 | | aom_codec_err_t av1_create_context_and_bufferpool(AV1_PRIMARY *ppi, |
2791 | | AV1_COMP **p_cpi, |
2792 | | BufferPool **p_buffer_pool, |
2793 | | const AV1EncoderConfig *oxcf, |
2794 | | COMPRESSOR_STAGE stage, |
2795 | 0 | int lap_lag_in_frames) { |
2796 | 0 | aom_codec_err_t res = AOM_CODEC_OK; |
2797 | 0 | BufferPool *buffer_pool = *p_buffer_pool; |
2798 | |
|
2799 | 0 | if (buffer_pool == NULL) { |
2800 | 0 | buffer_pool = (BufferPool *)aom_calloc(1, sizeof(BufferPool)); |
2801 | 0 | if (buffer_pool == NULL) return AOM_CODEC_MEM_ERROR; |
2802 | 0 | buffer_pool->num_frame_bufs = |
2803 | 0 | (oxcf->mode == ALLINTRA) ? FRAME_BUFFERS_ALLINTRA : FRAME_BUFFERS; |
2804 | 0 | buffer_pool->frame_bufs = (RefCntBuffer *)aom_calloc( |
2805 | 0 | buffer_pool->num_frame_bufs, sizeof(*buffer_pool->frame_bufs)); |
2806 | 0 | if (buffer_pool->frame_bufs == NULL) { |
2807 | 0 | buffer_pool->num_frame_bufs = 0; |
2808 | 0 | aom_free(buffer_pool); |
2809 | 0 | return AOM_CODEC_MEM_ERROR; |
2810 | 0 | } |
2811 | 0 | #if CONFIG_MULTITHREAD |
2812 | 0 | if (pthread_mutex_init(&buffer_pool->pool_mutex, NULL)) { |
2813 | 0 | aom_free(buffer_pool->frame_bufs); |
2814 | 0 | buffer_pool->frame_bufs = NULL; |
2815 | 0 | buffer_pool->num_frame_bufs = 0; |
2816 | 0 | aom_free(buffer_pool); |
2817 | 0 | return AOM_CODEC_MEM_ERROR; |
2818 | 0 | } |
2819 | 0 | #endif |
2820 | 0 | *p_buffer_pool = buffer_pool; |
2821 | 0 | } |
2822 | 0 | *p_cpi = |
2823 | 0 | av1_create_compressor(ppi, oxcf, buffer_pool, stage, lap_lag_in_frames); |
2824 | 0 | if (*p_cpi == NULL) res = AOM_CODEC_MEM_ERROR; |
2825 | |
|
2826 | 0 | return res; |
2827 | 0 | } |
2828 | | |
2829 | 0 | static aom_codec_err_t ctrl_set_fp_mt(aom_codec_alg_priv_t *ctx, va_list args) { |
2830 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
2831 | 0 | extra_cfg.fp_mt = CAST(AV1E_SET_FP_MT, args); |
2832 | 0 | const aom_codec_err_t result = update_extra_cfg(ctx, &extra_cfg); |
2833 | 0 | int num_fp_contexts = 1; |
2834 | 0 | if (ctx->ppi->num_fp_contexts == 1) { |
2835 | 0 | num_fp_contexts = |
2836 | 0 | av1_compute_num_fp_contexts(ctx->ppi, &ctx->ppi->parallel_cpi[0]->oxcf); |
2837 | 0 | if (num_fp_contexts > 1) { |
2838 | 0 | int i; |
2839 | 0 | for (i = 1; i < num_fp_contexts; i++) { |
2840 | 0 | int res = av1_create_context_and_bufferpool( |
2841 | 0 | ctx->ppi, &ctx->ppi->parallel_cpi[i], &ctx->buffer_pool, &ctx->oxcf, |
2842 | 0 | ENCODE_STAGE, -1); |
2843 | 0 | if (res != AOM_CODEC_OK) { |
2844 | 0 | return res; |
2845 | 0 | } |
2846 | 0 | #if !CONFIG_REALTIME_ONLY |
2847 | 0 | ctx->ppi->parallel_cpi[i]->twopass_frame.stats_in = |
2848 | 0 | ctx->ppi->twopass.stats_buf_ctx->stats_in_start; |
2849 | 0 | #endif |
2850 | 0 | } |
2851 | 0 | } |
2852 | 0 | } |
2853 | 0 | ctx->ppi->num_fp_contexts = num_fp_contexts; |
2854 | 0 | return result; |
2855 | 0 | } |
2856 | | |
2857 | | static aom_codec_err_t ctrl_set_auto_intra_tools_off(aom_codec_alg_priv_t *ctx, |
2858 | 0 | va_list args) { |
2859 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
2860 | 0 | extra_cfg.auto_intra_tools_off = CAST(AV1E_SET_AUTO_INTRA_TOOLS_OFF, args); |
2861 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
2862 | 0 | } |
2863 | | |
2864 | 0 | static aom_codec_err_t encoder_init(aom_codec_ctx_t *ctx) { |
2865 | 0 | aom_codec_err_t res = AOM_CODEC_OK; |
2866 | |
|
2867 | 0 | if (ctx->priv == NULL) { |
2868 | 0 | aom_codec_alg_priv_t *const priv = aom_calloc(1, sizeof(*priv)); |
2869 | 0 | if (priv == NULL) return AOM_CODEC_MEM_ERROR; |
2870 | | |
2871 | 0 | ctx->priv = (aom_codec_priv_t *)priv; |
2872 | 0 | ctx->priv->init_flags = ctx->init_flags; |
2873 | | |
2874 | | // Update the reference to the config structure to an internal copy. |
2875 | 0 | assert(ctx->config.enc); |
2876 | 0 | priv->cfg = *ctx->config.enc; |
2877 | 0 | ctx->config.enc = &priv->cfg; |
2878 | |
|
2879 | 0 | priv->extra_cfg = default_extra_cfg; |
2880 | | // Special handling: |
2881 | | // By default, if omitted: --enable-cdef=1, --qm-min=5, and --qm-max=9 |
2882 | | // Here we set its default values to 0, 4, and 10 respectively when |
2883 | | // --allintra is turned on. |
2884 | | // However, if users set --enable-cdef, --qm-min, or --qm-max, either from |
2885 | | // the command line or aom_codec_control(), the encoder still respects it. |
2886 | 0 | if (priv->cfg.g_usage == AOM_USAGE_ALL_INTRA) { |
2887 | | // CDEF has been found to blur images, so it's disabled in all-intra mode |
2888 | 0 | priv->extra_cfg.enable_cdef = 0; |
2889 | | // These QM min/max values have been found to be beneficial for images, |
2890 | | // when used with an alternative QM formula (see |
2891 | | // aom_get_qmlevel_allintra()). |
2892 | | // These values could also be beneficial for other usage modes, but |
2893 | | // further testing is required. |
2894 | 0 | priv->extra_cfg.qm_min = DEFAULT_QM_FIRST_ALLINTRA; |
2895 | 0 | priv->extra_cfg.qm_max = DEFAULT_QM_LAST_ALLINTRA; |
2896 | 0 | } |
2897 | 0 | av1_initialize_enc(priv->cfg.g_usage, priv->cfg.rc_end_usage); |
2898 | |
|
2899 | 0 | res = validate_config(priv, &priv->cfg, &priv->extra_cfg); |
2900 | |
|
2901 | 0 | if (res == AOM_CODEC_OK) { |
2902 | 0 | int *num_lap_buffers = &priv->num_lap_buffers; |
2903 | 0 | int lap_lag_in_frames = 0; |
2904 | 0 | *num_lap_buffers = 0; |
2905 | 0 | priv->timestamp_ratio.den = priv->cfg.g_timebase.den; |
2906 | 0 | priv->timestamp_ratio.num = |
2907 | 0 | (int64_t)priv->cfg.g_timebase.num * TICKS_PER_SEC; |
2908 | 0 | reduce_ratio(&priv->timestamp_ratio); |
2909 | |
|
2910 | 0 | set_encoder_config(&priv->oxcf, &priv->cfg, &priv->extra_cfg); |
2911 | 0 | if (priv->oxcf.rc_cfg.mode != AOM_CBR && |
2912 | 0 | priv->oxcf.pass == AOM_RC_ONE_PASS && priv->oxcf.mode == GOOD) { |
2913 | | // Enable look ahead - enabled for AOM_Q, AOM_CQ, AOM_VBR |
2914 | 0 | *num_lap_buffers = |
2915 | 0 | AOMMIN((int)priv->cfg.g_lag_in_frames, |
2916 | 0 | AOMMIN(MAX_LAP_BUFFERS, priv->oxcf.kf_cfg.key_freq_max + |
2917 | 0 | SCENE_CUT_KEY_TEST_INTERVAL)); |
2918 | 0 | if ((int)priv->cfg.g_lag_in_frames - (*num_lap_buffers) >= |
2919 | 0 | LAP_LAG_IN_FRAMES) { |
2920 | 0 | lap_lag_in_frames = LAP_LAG_IN_FRAMES; |
2921 | 0 | } |
2922 | 0 | } |
2923 | 0 | priv->oxcf.use_highbitdepth = |
2924 | 0 | (ctx->init_flags & AOM_CODEC_USE_HIGHBITDEPTH) ? 1 : 0; |
2925 | |
|
2926 | 0 | priv->monochrome_on_init = priv->cfg.monochrome; |
2927 | |
|
2928 | 0 | priv->ppi = av1_create_primary_compressor(&priv->pkt_list.head, |
2929 | 0 | *num_lap_buffers, &priv->oxcf); |
2930 | 0 | if (!priv->ppi) return AOM_CODEC_MEM_ERROR; |
2931 | | |
2932 | 0 | #if !CONFIG_REALTIME_ONLY |
2933 | 0 | res = create_stats_buffer(&priv->frame_stats_buffer, |
2934 | 0 | &priv->stats_buf_context, *num_lap_buffers); |
2935 | 0 | if (res != AOM_CODEC_OK) return res; |
2936 | | |
2937 | 0 | assert(MAX_LAP_BUFFERS >= MAX_LAG_BUFFERS); |
2938 | 0 | int size = get_stats_buf_size(*num_lap_buffers, MAX_LAG_BUFFERS); |
2939 | 0 | for (int i = 0; i < size; i++) |
2940 | 0 | priv->ppi->twopass.frame_stats_arr[i] = &priv->frame_stats_buffer[i]; |
2941 | |
|
2942 | 0 | priv->ppi->twopass.stats_buf_ctx = &priv->stats_buf_context; |
2943 | 0 | #endif |
2944 | |
|
2945 | 0 | assert(priv->ppi->num_fp_contexts >= 1); |
2946 | 0 | res = av1_create_context_and_bufferpool( |
2947 | 0 | priv->ppi, &priv->ppi->parallel_cpi[0], &priv->buffer_pool, |
2948 | 0 | &priv->oxcf, ENCODE_STAGE, -1); |
2949 | 0 | if (res != AOM_CODEC_OK) { |
2950 | 0 | priv->base.err_detail = "av1_create_context_and_bufferpool() failed"; |
2951 | 0 | return res; |
2952 | 0 | } |
2953 | 0 | #if !CONFIG_REALTIME_ONLY |
2954 | 0 | priv->ppi->parallel_cpi[0]->twopass_frame.stats_in = |
2955 | 0 | priv->ppi->twopass.stats_buf_ctx->stats_in_start; |
2956 | 0 | #endif |
2957 | 0 | priv->ppi->cpi = priv->ppi->parallel_cpi[0]; |
2958 | | |
2959 | | // Create another compressor if look ahead is enabled |
2960 | 0 | if (res == AOM_CODEC_OK && *num_lap_buffers) { |
2961 | 0 | res = av1_create_context_and_bufferpool( |
2962 | 0 | priv->ppi, &priv->ppi->cpi_lap, &priv->buffer_pool_lap, &priv->oxcf, |
2963 | 0 | LAP_STAGE, clamp(lap_lag_in_frames, 0, MAX_LAG_BUFFERS)); |
2964 | 0 | } |
2965 | 0 | } |
2966 | 0 | } |
2967 | | |
2968 | 0 | return res; |
2969 | 0 | } |
2970 | | |
2971 | | void av1_destroy_context_and_bufferpool(AV1_COMP *cpi, |
2972 | 0 | BufferPool **p_buffer_pool) { |
2973 | 0 | av1_remove_compressor(cpi); |
2974 | 0 | if (*p_buffer_pool) { |
2975 | 0 | av1_free_ref_frame_buffers(*p_buffer_pool); |
2976 | 0 | #if CONFIG_MULTITHREAD |
2977 | 0 | pthread_mutex_destroy(&(*p_buffer_pool)->pool_mutex); |
2978 | 0 | #endif |
2979 | 0 | aom_free(*p_buffer_pool); |
2980 | 0 | *p_buffer_pool = NULL; |
2981 | 0 | } |
2982 | 0 | } |
2983 | | |
2984 | | static void destroy_stats_buffer(STATS_BUFFER_CTX *stats_buf_context, |
2985 | 0 | FIRSTPASS_STATS *frame_stats_buffer) { |
2986 | 0 | aom_free(stats_buf_context->total_left_stats); |
2987 | 0 | aom_free(stats_buf_context->total_stats); |
2988 | 0 | aom_free(frame_stats_buffer); |
2989 | 0 | } |
2990 | | |
2991 | 0 | static void check_and_free_string(const char *default_str, const char **ptr) { |
2992 | 0 | if (*ptr == default_str) { |
2993 | | // Default should be a literal. Do not free. |
2994 | 0 | return; |
2995 | 0 | } |
2996 | 0 | aom_free((void *)*ptr); |
2997 | 0 | *ptr = NULL; |
2998 | 0 | } |
2999 | | |
3000 | 0 | static void destroy_extra_config(struct av1_extracfg *extra_cfg) { |
3001 | | #if CONFIG_TUNE_VMAF |
3002 | | check_and_free_string(default_extra_cfg.vmaf_model_path, |
3003 | | &extra_cfg->vmaf_model_path); |
3004 | | #endif |
3005 | 0 | check_and_free_string(default_extra_cfg.two_pass_output, |
3006 | 0 | &extra_cfg->two_pass_output); |
3007 | 0 | check_and_free_string(default_extra_cfg.two_pass_output, |
3008 | 0 | &extra_cfg->second_pass_log); |
3009 | 0 | check_and_free_string(default_extra_cfg.partition_info_path, |
3010 | 0 | &extra_cfg->partition_info_path); |
3011 | 0 | check_and_free_string(default_extra_cfg.rate_distribution_info, |
3012 | 0 | &extra_cfg->rate_distribution_info); |
3013 | 0 | check_and_free_string(default_extra_cfg.film_grain_table_filename, |
3014 | 0 | &extra_cfg->film_grain_table_filename); |
3015 | 0 | } |
3016 | | |
3017 | 0 | static aom_codec_err_t encoder_destroy(aom_codec_alg_priv_t *ctx) { |
3018 | 0 | free(ctx->cx_data); |
3019 | 0 | destroy_extra_config(&ctx->extra_cfg); |
3020 | |
|
3021 | 0 | if (ctx->ppi) { |
3022 | 0 | AV1_PRIMARY *ppi = ctx->ppi; |
3023 | 0 | for (int i = 0; i < MAX_PARALLEL_FRAMES - 1; i++) { |
3024 | 0 | if (ppi->parallel_frames_data[i].cx_data) { |
3025 | 0 | free(ppi->parallel_frames_data[i].cx_data); |
3026 | 0 | } |
3027 | 0 | } |
3028 | | #if CONFIG_ENTROPY_STATS |
3029 | | print_entropy_stats(ppi); |
3030 | | #endif |
3031 | | #if CONFIG_INTERNAL_STATS |
3032 | | print_internal_stats(ppi); |
3033 | | #endif |
3034 | |
|
3035 | 0 | for (int i = 0; i < MAX_PARALLEL_FRAMES; i++) { |
3036 | 0 | av1_destroy_context_and_bufferpool(ppi->parallel_cpi[i], |
3037 | 0 | &ctx->buffer_pool); |
3038 | 0 | } |
3039 | 0 | ppi->cpi = NULL; |
3040 | |
|
3041 | 0 | if (ppi->cpi_lap) { |
3042 | 0 | av1_destroy_context_and_bufferpool(ppi->cpi_lap, &ctx->buffer_pool_lap); |
3043 | 0 | } |
3044 | 0 | av1_remove_primary_compressor(ppi); |
3045 | 0 | } |
3046 | 0 | destroy_stats_buffer(&ctx->stats_buf_context, ctx->frame_stats_buffer); |
3047 | 0 | aom_free(ctx); |
3048 | 0 | return AOM_CODEC_OK; |
3049 | 0 | } |
3050 | | |
3051 | | static aom_codec_frame_flags_t get_frame_pkt_flags(const AV1_COMP *cpi, |
3052 | 0 | unsigned int lib_flags) { |
3053 | 0 | aom_codec_frame_flags_t flags = lib_flags << 16; |
3054 | 0 | if (lib_flags & FRAMEFLAGS_KEY) flags |= AOM_FRAME_IS_KEY; |
3055 | 0 | if (lib_flags & FRAMEFLAGS_INTRAONLY) flags |= AOM_FRAME_IS_INTRAONLY; |
3056 | 0 | if (lib_flags & FRAMEFLAGS_SWITCH) flags |= AOM_FRAME_IS_SWITCH; |
3057 | 0 | if (lib_flags & FRAMEFLAGS_ERROR_RESILIENT) |
3058 | 0 | flags |= AOM_FRAME_IS_ERROR_RESILIENT; |
3059 | 0 | if (cpi->droppable) flags |= AOM_FRAME_IS_DROPPABLE; |
3060 | |
|
3061 | 0 | return flags; |
3062 | 0 | } |
3063 | | |
3064 | 0 | static inline int get_src_border_in_pixels(AV1_COMP *cpi, BLOCK_SIZE sb_size) { |
3065 | 0 | if (cpi->oxcf.mode != REALTIME || av1_is_resize_needed(&cpi->oxcf)) |
3066 | 0 | return cpi->oxcf.border_in_pixels; |
3067 | | |
3068 | 0 | const int sb_size_in_pixels_log2 = mi_size_wide_log2[sb_size] + MI_SIZE_LOG2; |
3069 | 0 | const int sb_aligned_width = |
3070 | 0 | ALIGN_POWER_OF_TWO(cpi->oxcf.frm_dim_cfg.width, sb_size_in_pixels_log2); |
3071 | 0 | const int sb_aligned_height = |
3072 | 0 | ALIGN_POWER_OF_TWO(cpi->oxcf.frm_dim_cfg.height, sb_size_in_pixels_log2); |
3073 | | // Align the border pixels to a multiple of 32. |
3074 | 0 | const int border_pixels_width = |
3075 | 0 | ALIGN_POWER_OF_TWO(sb_aligned_width - cpi->oxcf.frm_dim_cfg.width, 5); |
3076 | 0 | const int border_pixels_height = |
3077 | 0 | ALIGN_POWER_OF_TWO(sb_aligned_height - cpi->oxcf.frm_dim_cfg.height, 5); |
3078 | 0 | const int border_in_pixels = |
3079 | 0 | AOMMAX(AOMMAX(border_pixels_width, border_pixels_height), 32); |
3080 | 0 | return border_in_pixels; |
3081 | 0 | } |
3082 | | |
3083 | | // TODO(Mufaddal): Check feasibility of abstracting functions related to LAP |
3084 | | // into a separate function. |
3085 | | static aom_codec_err_t encoder_encode(aom_codec_alg_priv_t *ctx, |
3086 | | const aom_image_t *img, |
3087 | | aom_codec_pts_t pts, |
3088 | | unsigned long duration, |
3089 | 0 | aom_enc_frame_flags_t enc_flags) { |
3090 | 0 | const size_t kMinCompressedSize = 8192; |
3091 | 0 | volatile aom_codec_err_t res = AOM_CODEC_OK; |
3092 | 0 | AV1_PRIMARY *const ppi = ctx->ppi; |
3093 | 0 | volatile aom_codec_pts_t ptsvol = pts; |
3094 | 0 | AV1_COMP_DATA cpi_data = { 0 }; |
3095 | |
|
3096 | 0 | cpi_data.timestamp_ratio = &ctx->timestamp_ratio; |
3097 | 0 | cpi_data.flush = !img; |
3098 | | // LAP context |
3099 | 0 | AV1_COMP *cpi_lap = ppi->cpi_lap; |
3100 | 0 | if (ppi->cpi == NULL) return AOM_CODEC_INVALID_PARAM; |
3101 | | |
3102 | 0 | ppi->cpi->last_coded_width = ppi->cpi->oxcf.frm_dim_cfg.width; |
3103 | 0 | ppi->cpi->last_coded_height = ppi->cpi->oxcf.frm_dim_cfg.height; |
3104 | |
|
3105 | 0 | if (ppi->lap_enabled && cpi_lap == NULL && |
3106 | 0 | ppi->cpi->oxcf.pass == AOM_RC_ONE_PASS) |
3107 | 0 | return AOM_CODEC_INVALID_PARAM; |
3108 | | |
3109 | 0 | if (img != NULL) { |
3110 | 0 | res = validate_img(ctx, img); |
3111 | 0 | if (res == AOM_CODEC_OK) { |
3112 | 0 | const uint64_t uncompressed_frame_sz64 = |
3113 | 0 | (uint64_t)ALIGN_POWER_OF_TWO_UNSIGNED(ctx->cfg.g_w, 5) * |
3114 | 0 | ALIGN_POWER_OF_TWO_UNSIGNED(ctx->cfg.g_h, 5) * get_image_bps(img) / 8; |
3115 | | #if UINT64_MAX > SIZE_MAX |
3116 | | if (uncompressed_frame_sz64 > SIZE_MAX) return AOM_CODEC_MEM_ERROR; |
3117 | | #endif |
3118 | 0 | const size_t uncompressed_frame_sz = (size_t)uncompressed_frame_sz64; |
3119 | | |
3120 | | // Due to the presence of no-show frames, the ctx->cx_data buffer holds |
3121 | | // compressed data corresponding to multiple frames. As no-show frames are |
3122 | | // not possible for all intra frame encoding with no forward key frames, |
3123 | | // the buffer is allocated with a smaller size in this case. |
3124 | | // |
3125 | | // For pseudo random input, the compressed frame size is seen to exceed |
3126 | | // the uncompressed frame size, but is less than 2 times the uncompressed |
3127 | | // frame size. Hence the size of the buffer is chosen as 2 times the |
3128 | | // uncompressed frame size. |
3129 | 0 | int multiplier = 8; |
3130 | 0 | if (ppi->cpi->oxcf.kf_cfg.key_freq_max == 0 && |
3131 | 0 | !ppi->cpi->oxcf.kf_cfg.fwd_kf_enabled) |
3132 | 0 | multiplier = 2; |
3133 | 0 | if (uncompressed_frame_sz > SIZE_MAX / multiplier) |
3134 | 0 | return AOM_CODEC_MEM_ERROR; |
3135 | 0 | size_t data_sz = uncompressed_frame_sz * multiplier; |
3136 | 0 | if (data_sz < kMinCompressedSize) data_sz = kMinCompressedSize; |
3137 | 0 | if (ctx->cx_data == NULL || ctx->cx_data_sz < data_sz) { |
3138 | 0 | ctx->cx_data_sz = data_sz; |
3139 | 0 | free(ctx->cx_data); |
3140 | 0 | ctx->cx_data = (unsigned char *)malloc(ctx->cx_data_sz); |
3141 | 0 | if (ctx->cx_data == NULL) { |
3142 | 0 | ctx->cx_data_sz = 0; |
3143 | 0 | return AOM_CODEC_MEM_ERROR; |
3144 | 0 | } |
3145 | 0 | } |
3146 | 0 | for (int i = 0; i < ppi->num_fp_contexts - 1; i++) { |
3147 | 0 | if (ppi->parallel_frames_data[i].cx_data == NULL || |
3148 | 0 | ppi->parallel_frames_data[i].cx_data_sz < data_sz) { |
3149 | 0 | ppi->parallel_frames_data[i].cx_data_sz = data_sz; |
3150 | 0 | free(ppi->parallel_frames_data[i].cx_data); |
3151 | 0 | ppi->parallel_frames_data[i].frame_size = 0; |
3152 | 0 | ppi->parallel_frames_data[i].cx_data = |
3153 | 0 | (unsigned char *)malloc(ppi->parallel_frames_data[i].cx_data_sz); |
3154 | 0 | if (ppi->parallel_frames_data[i].cx_data == NULL) { |
3155 | 0 | ppi->parallel_frames_data[i].cx_data_sz = 0; |
3156 | 0 | return AOM_CODEC_MEM_ERROR; |
3157 | 0 | } |
3158 | 0 | } |
3159 | 0 | } |
3160 | 0 | } |
3161 | 0 | } |
3162 | | |
3163 | 0 | aom_codec_pkt_list_init(&ctx->pkt_list); |
3164 | |
|
3165 | 0 | volatile aom_enc_frame_flags_t flags = enc_flags; |
3166 | | |
3167 | | // The jmp_buf is valid only for the duration of the function that calls |
3168 | | // setjmp(). Therefore, this function must reset the 'setjmp' field to 0 |
3169 | | // before it returns. |
3170 | 0 | if (setjmp(ppi->error.jmp)) { |
3171 | 0 | ppi->error.setjmp = 0; |
3172 | 0 | res = update_error_state(ctx, &ppi->error); |
3173 | 0 | return res; |
3174 | 0 | } |
3175 | 0 | ppi->error.setjmp = 1; |
3176 | |
|
3177 | 0 | if (ppi->use_svc && ppi->cpi->svc.use_flexible_mode == 0 && flags == 0) |
3178 | 0 | av1_set_svc_fixed_mode(ppi->cpi); |
3179 | | |
3180 | | // Note(yunqing): While applying encoding flags, always start from enabling |
3181 | | // all, and then modifying according to the flags. Previous frame's flags are |
3182 | | // overwritten. |
3183 | 0 | av1_apply_encoding_flags(ppi->cpi, flags); |
3184 | 0 | if (cpi_lap != NULL) { |
3185 | 0 | av1_apply_encoding_flags(cpi_lap, flags); |
3186 | 0 | } |
3187 | |
|
3188 | | #if CONFIG_TUNE_VMAF |
3189 | | if (ctx->extra_cfg.tuning >= AOM_TUNE_VMAF_WITH_PREPROCESSING && |
3190 | | ctx->extra_cfg.tuning <= AOM_TUNE_VMAF_NEG_MAX_GAIN) { |
3191 | | aom_init_vmaf_model(&ppi->cpi->vmaf_info.vmaf_model, |
3192 | | ppi->cpi->oxcf.tune_cfg.vmaf_model_path); |
3193 | | } |
3194 | | #endif |
3195 | | |
3196 | | // Handle fixed keyframe intervals |
3197 | 0 | if (is_stat_generation_stage(ppi->cpi) || is_one_pass_rt_params(ppi->cpi)) { |
3198 | 0 | if (ctx->cfg.kf_mode == AOM_KF_AUTO && |
3199 | 0 | ctx->cfg.kf_min_dist == ctx->cfg.kf_max_dist) { |
3200 | 0 | if (ppi->cpi->common.spatial_layer_id == 0 && |
3201 | 0 | ++ctx->fixed_kf_cntr > ctx->cfg.kf_min_dist) { |
3202 | 0 | flags |= AOM_EFLAG_FORCE_KF; |
3203 | 0 | ctx->fixed_kf_cntr = 1; |
3204 | 0 | } |
3205 | 0 | } |
3206 | 0 | } |
3207 | |
|
3208 | 0 | if (res == AOM_CODEC_OK) { |
3209 | 0 | AV1_COMP *cpi = ppi->cpi; |
3210 | | |
3211 | | // Set up internal flags |
3212 | 0 | if (ctx->base.init_flags & AOM_CODEC_USE_PSNR) ppi->b_calculate_psnr = 1; |
3213 | |
|
3214 | 0 | if (img != NULL) { |
3215 | 0 | if (!ctx->pts_offset_initialized) { |
3216 | 0 | ctx->pts_offset = ptsvol; |
3217 | 0 | ctx->pts_offset_initialized = 1; |
3218 | 0 | } |
3219 | 0 | if (ptsvol < ctx->pts_offset) { |
3220 | 0 | aom_internal_error(&ppi->error, AOM_CODEC_INVALID_PARAM, |
3221 | 0 | "pts is smaller than initial pts"); |
3222 | 0 | } |
3223 | 0 | ptsvol -= ctx->pts_offset; |
3224 | 0 | if (ptsvol > INT64_MAX / cpi_data.timestamp_ratio->num) { |
3225 | 0 | aom_internal_error( |
3226 | 0 | &ppi->error, AOM_CODEC_INVALID_PARAM, |
3227 | 0 | "conversion of relative pts to ticks would overflow"); |
3228 | 0 | } |
3229 | 0 | int64_t src_time_stamp = |
3230 | 0 | timebase_units_to_ticks(cpi_data.timestamp_ratio, ptsvol); |
3231 | 0 | #if ULONG_MAX > INT64_MAX |
3232 | 0 | if (duration > INT64_MAX) { |
3233 | 0 | aom_internal_error(&ppi->error, AOM_CODEC_INVALID_PARAM, |
3234 | 0 | "duration is too big"); |
3235 | 0 | } |
3236 | 0 | #endif |
3237 | 0 | if (ptsvol > INT64_MAX - (int64_t)duration) { |
3238 | 0 | aom_internal_error(&ppi->error, AOM_CODEC_INVALID_PARAM, |
3239 | 0 | "relative pts + duration is too big"); |
3240 | 0 | } |
3241 | 0 | aom_codec_pts_t pts_end = ptsvol + (int64_t)duration; |
3242 | 0 | if (pts_end > INT64_MAX / cpi_data.timestamp_ratio->num) { |
3243 | 0 | aom_internal_error( |
3244 | 0 | &ppi->error, AOM_CODEC_INVALID_PARAM, |
3245 | 0 | "conversion of relative pts + duration to ticks would overflow"); |
3246 | 0 | } |
3247 | 0 | int64_t src_end_time_stamp = |
3248 | 0 | timebase_units_to_ticks(cpi_data.timestamp_ratio, pts_end); |
3249 | |
|
3250 | 0 | YV12_BUFFER_CONFIG sd; |
3251 | 0 | res = image2yuvconfig(img, &sd); |
3252 | | // When generating a monochrome stream, make |sd| a monochrome image. |
3253 | 0 | if (ctx->cfg.monochrome) { |
3254 | 0 | sd.u_buffer = sd.v_buffer = NULL; |
3255 | 0 | sd.uv_stride = 0; |
3256 | 0 | sd.monochrome = 1; |
3257 | 0 | } |
3258 | 0 | int use_highbitdepth = (sd.flags & YV12_FLAG_HIGHBITDEPTH) != 0; |
3259 | 0 | int subsampling_x = sd.subsampling_x; |
3260 | 0 | int subsampling_y = sd.subsampling_y; |
3261 | |
|
3262 | 0 | if (!ppi->lookahead) { |
3263 | 0 | int lag_in_frames = cpi_lap != NULL ? cpi_lap->oxcf.gf_cfg.lag_in_frames |
3264 | 0 | : cpi->oxcf.gf_cfg.lag_in_frames; |
3265 | 0 | AV1EncoderConfig *oxcf = &cpi->oxcf; |
3266 | 0 | const BLOCK_SIZE sb_size = av1_select_sb_size( |
3267 | 0 | oxcf, oxcf->frm_dim_cfg.width, oxcf->frm_dim_cfg.height, |
3268 | 0 | ppi->number_spatial_layers); |
3269 | 0 | oxcf->border_in_pixels = |
3270 | 0 | av1_get_enc_border_size(av1_is_resize_needed(oxcf), |
3271 | 0 | oxcf->kf_cfg.key_freq_max == 0, sb_size); |
3272 | 0 | for (int i = 0; i < ppi->num_fp_contexts; i++) { |
3273 | 0 | ppi->parallel_cpi[i]->oxcf.border_in_pixels = oxcf->border_in_pixels; |
3274 | 0 | } |
3275 | |
|
3276 | 0 | const int src_border_in_pixels = get_src_border_in_pixels(cpi, sb_size); |
3277 | 0 | ppi->lookahead = av1_lookahead_init( |
3278 | 0 | cpi->oxcf.frm_dim_cfg.width, cpi->oxcf.frm_dim_cfg.height, |
3279 | 0 | subsampling_x, subsampling_y, use_highbitdepth, lag_in_frames, |
3280 | 0 | src_border_in_pixels, cpi->common.features.byte_alignment, |
3281 | 0 | ctx->num_lap_buffers, (cpi->oxcf.kf_cfg.key_freq_max == 0), |
3282 | 0 | cpi->alloc_pyramid); |
3283 | 0 | } |
3284 | 0 | if (!ppi->lookahead) |
3285 | 0 | aom_internal_error(&ppi->error, AOM_CODEC_MEM_ERROR, |
3286 | 0 | "Failed to allocate lag buffers"); |
3287 | 0 | for (int i = 0; i < ppi->num_fp_contexts; i++) { |
3288 | 0 | aom_codec_err_t err = |
3289 | 0 | av1_check_initial_width(ppi->parallel_cpi[i], use_highbitdepth, |
3290 | 0 | subsampling_x, subsampling_y); |
3291 | 0 | if (err != AOM_CODEC_OK) { |
3292 | 0 | aom_internal_error(&ppi->error, err, |
3293 | 0 | "av1_check_initial_width() failed"); |
3294 | 0 | } |
3295 | 0 | } |
3296 | 0 | if (cpi_lap != NULL) { |
3297 | 0 | aom_codec_err_t err = av1_check_initial_width( |
3298 | 0 | cpi_lap, use_highbitdepth, subsampling_x, subsampling_y); |
3299 | 0 | if (err != AOM_CODEC_OK) { |
3300 | 0 | aom_internal_error(&ppi->error, err, |
3301 | 0 | "av1_check_initial_width() failed"); |
3302 | 0 | } |
3303 | 0 | } |
3304 | | |
3305 | | // Store the original flags in to the frame buffer. Will extract the |
3306 | | // key frame flag when we actually encode this frame. |
3307 | 0 | if (av1_receive_raw_frame(cpi, flags | ctx->next_frame_flags, &sd, |
3308 | 0 | src_time_stamp, src_end_time_stamp)) { |
3309 | 0 | res = update_error_state(ctx, cpi->common.error); |
3310 | 0 | } |
3311 | 0 | ctx->next_frame_flags = 0; |
3312 | 0 | } |
3313 | |
|
3314 | 0 | cpi_data.cx_data = ctx->cx_data; |
3315 | 0 | cpi_data.cx_data_sz = ctx->cx_data_sz; |
3316 | | |
3317 | | /* Any pending invisible frames? */ |
3318 | 0 | if (ctx->pending_cx_data_sz) { |
3319 | 0 | cpi_data.cx_data += ctx->pending_cx_data_sz; |
3320 | 0 | cpi_data.cx_data_sz -= ctx->pending_cx_data_sz; |
3321 | | |
3322 | | /* TODO: this is a minimal check, the underlying codec doesn't respect |
3323 | | * the buffer size anyway. |
3324 | | */ |
3325 | 0 | if (cpi_data.cx_data_sz < ctx->cx_data_sz / 2) { |
3326 | 0 | aom_internal_error(&ppi->error, AOM_CODEC_ERROR, |
3327 | 0 | "Compressed data buffer too small"); |
3328 | 0 | } |
3329 | 0 | } |
3330 | |
|
3331 | 0 | int is_frame_visible = 0; |
3332 | 0 | int has_no_show_keyframe = 0; |
3333 | 0 | int num_workers = 0; |
3334 | |
|
3335 | 0 | if (cpi->oxcf.pass == AOM_RC_FIRST_PASS) { |
3336 | 0 | #if !CONFIG_REALTIME_ONLY |
3337 | 0 | num_workers = ppi->p_mt_info.num_mod_workers[MOD_FP] = |
3338 | 0 | av1_fp_compute_num_enc_workers(cpi); |
3339 | 0 | #endif |
3340 | 0 | } else { |
3341 | 0 | av1_compute_num_workers_for_mt(cpi); |
3342 | 0 | num_workers = av1_get_max_num_workers(cpi); |
3343 | 0 | } |
3344 | 0 | if (num_workers > 1 && ppi->p_mt_info.num_workers < num_workers) { |
3345 | | // Obtain the maximum no. of frames that can be supported in a parallel |
3346 | | // encode set. |
3347 | 0 | if (is_stat_consumption_stage(cpi)) { |
3348 | 0 | ppi->num_fp_contexts = av1_compute_num_fp_contexts(ppi, &cpi->oxcf); |
3349 | 0 | } |
3350 | 0 | if (ppi->p_mt_info.num_workers > 0) { |
3351 | 0 | av1_terminate_workers(ppi); |
3352 | 0 | free_thread_data(ppi); |
3353 | 0 | aom_free(ppi->p_mt_info.tile_thr_data); |
3354 | 0 | ppi->p_mt_info.tile_thr_data = NULL; |
3355 | 0 | aom_free(ppi->p_mt_info.workers); |
3356 | 0 | ppi->p_mt_info.workers = NULL; |
3357 | 0 | ppi->p_mt_info.num_workers = 0; |
3358 | 0 | for (int j = 0; j < ppi->num_fp_contexts; j++) { |
3359 | 0 | aom_free(ppi->parallel_cpi[j]->td.tctx); |
3360 | 0 | ppi->parallel_cpi[j]->td.tctx = NULL; |
3361 | 0 | } |
3362 | 0 | } |
3363 | 0 | av1_create_workers(ppi, num_workers); |
3364 | 0 | av1_init_tile_thread_data(ppi, cpi->oxcf.pass == AOM_RC_FIRST_PASS); |
3365 | 0 | } |
3366 | | |
3367 | | // Re-allocate thread data if workers for encoder multi-threading stage |
3368 | | // exceeds prev_num_enc_workers. |
3369 | 0 | const int num_enc_workers = |
3370 | 0 | av1_get_num_mod_workers_for_alloc(&ppi->p_mt_info, MOD_ENC); |
3371 | 0 | if (ppi->p_mt_info.prev_num_enc_workers < num_enc_workers && |
3372 | 0 | num_enc_workers <= ppi->p_mt_info.num_workers) { |
3373 | 0 | free_thread_data(ppi); |
3374 | 0 | for (int j = 0; j < ppi->num_fp_contexts; j++) { |
3375 | 0 | aom_free(ppi->parallel_cpi[j]->td.tctx); |
3376 | 0 | ppi->parallel_cpi[j]->td.tctx = NULL; |
3377 | 0 | } |
3378 | 0 | av1_init_tile_thread_data(ppi, cpi->oxcf.pass == AOM_RC_FIRST_PASS); |
3379 | 0 | } |
3380 | |
|
3381 | 0 | for (int i = 0; i < ppi->num_fp_contexts; i++) { |
3382 | 0 | av1_init_frame_mt(ppi, ppi->parallel_cpi[i]); |
3383 | 0 | } |
3384 | 0 | if (cpi_lap != NULL) { |
3385 | 0 | av1_init_frame_mt(ppi, cpi_lap); |
3386 | 0 | } |
3387 | 0 | #if CONFIG_MULTITHREAD |
3388 | 0 | if (ppi->p_mt_info.num_workers > 1) { |
3389 | 0 | for (int i = 0; i < ppi->num_fp_contexts; i++) { |
3390 | 0 | av1_init_mt_sync(ppi->parallel_cpi[i], |
3391 | 0 | ppi->parallel_cpi[i]->oxcf.pass == AOM_RC_FIRST_PASS); |
3392 | 0 | } |
3393 | 0 | if (cpi_lap != NULL) { |
3394 | 0 | av1_init_mt_sync(cpi_lap, 1); |
3395 | 0 | } |
3396 | 0 | } |
3397 | 0 | #endif // CONFIG_MULTITHREAD |
3398 | | |
3399 | | // Call for LAP stage |
3400 | 0 | if (cpi_lap != NULL) { |
3401 | 0 | AV1_COMP_DATA cpi_lap_data = { 0 }; |
3402 | 0 | cpi_lap_data.flush = !img; |
3403 | 0 | cpi_lap_data.timestamp_ratio = &ctx->timestamp_ratio; |
3404 | 0 | const int status = av1_get_compressed_data(cpi_lap, &cpi_lap_data); |
3405 | 0 | if (status > AOM_CODEC_OK) { |
3406 | 0 | aom_internal_error_copy(&ppi->error, cpi_lap->common.error); |
3407 | 0 | } |
3408 | 0 | av1_post_encode_updates(cpi_lap, &cpi_lap_data); |
3409 | 0 | } |
3410 | | |
3411 | | // Recalculate the maximum number of frames that can be encoded in |
3412 | | // parallel at the beginning of sub gop. |
3413 | 0 | if (is_stat_consumption_stage(cpi) && ppi->gf_group.size > 0 && |
3414 | 0 | cpi->gf_frame_index == ppi->gf_group.size) { |
3415 | 0 | ppi->num_fp_contexts = av1_compute_num_fp_contexts(ppi, &cpi->oxcf); |
3416 | 0 | } |
3417 | | |
3418 | | // Get the next visible frame. Invisible frames get packed with the next |
3419 | | // visible frame. |
3420 | 0 | while (cpi_data.cx_data_sz >= ctx->cx_data_sz / 2 && !is_frame_visible) { |
3421 | 0 | int simulate_parallel_frame = 0; |
3422 | 0 | int status = -1; |
3423 | 0 | cpi->do_frame_data_update = true; |
3424 | 0 | cpi->ref_idx_to_skip = INVALID_IDX; |
3425 | 0 | cpi->ref_refresh_index = INVALID_IDX; |
3426 | 0 | cpi->refresh_idx_available = false; |
3427 | |
|
3428 | | #if CONFIG_FPMT_TEST |
3429 | | simulate_parallel_frame = |
3430 | | cpi->ppi->fpmt_unit_test_cfg == PARALLEL_SIMULATION_ENCODE ? 1 : 0; |
3431 | | if (simulate_parallel_frame) { |
3432 | | if (ppi->num_fp_contexts > 1 && ppi->gf_group.size > 1) { |
3433 | | if (cpi->gf_frame_index < ppi->gf_group.size) { |
3434 | | calc_frame_data_update_flag(&ppi->gf_group, cpi->gf_frame_index, |
3435 | | &cpi->do_frame_data_update); |
3436 | | } |
3437 | | } |
3438 | | status = av1_get_compressed_data(cpi, &cpi_data); |
3439 | | } |
3440 | | |
3441 | | #endif // CONFIG_FPMT_TEST |
3442 | 0 | if (!simulate_parallel_frame) { |
3443 | 0 | if (ppi->gf_group.frame_parallel_level[cpi->gf_frame_index] == 0) { |
3444 | 0 | status = av1_get_compressed_data(cpi, &cpi_data); |
3445 | 0 | } else if (ppi->gf_group.frame_parallel_level[cpi->gf_frame_index] == |
3446 | 0 | 1) { |
3447 | | // In case of an error, longjmp() would be invoked and hence "status" |
3448 | | // is set to AOM_CODEC_OK here. |
3449 | 0 | av1_compress_parallel_frames(ppi, &cpi_data); |
3450 | 0 | status = AOM_CODEC_OK; |
3451 | 0 | } else { |
3452 | | // No possibility of failures from this function and hence "status" is |
3453 | | // set to AOM_CODEC_OK here. |
3454 | 0 | cpi = av1_get_parallel_frame_enc_data(ppi, &cpi_data); |
3455 | 0 | status = AOM_CODEC_OK; |
3456 | 0 | } |
3457 | 0 | } |
3458 | 0 | if (status == -1) break; |
3459 | 0 | if (status != AOM_CODEC_OK) { |
3460 | 0 | aom_internal_error_copy(&ppi->error, cpi->common.error); |
3461 | 0 | } |
3462 | 0 | if (ppi->num_fp_contexts > 0 && frame_is_intra_only(&cpi->common)) { |
3463 | 0 | av1_init_sc_decisions(ppi); |
3464 | 0 | } |
3465 | |
|
3466 | 0 | ppi->seq_params_locked = 1; |
3467 | 0 | av1_post_encode_updates(cpi, &cpi_data); |
3468 | |
|
3469 | | #if CONFIG_ENTROPY_STATS |
3470 | | if (ppi->cpi->oxcf.pass != 1 && !cpi->common.show_existing_frame) |
3471 | | av1_accumulate_frame_counts(&ppi->aggregate_fc, &cpi->counts); |
3472 | | #endif |
3473 | | #if CONFIG_INTERNAL_STATS |
3474 | | if (ppi->cpi->oxcf.pass != 1) { |
3475 | | ppi->total_time_compress_data += cpi->time_compress_data; |
3476 | | ppi->total_recode_hits += cpi->frame_recode_hits; |
3477 | | ppi->total_bytes += (uint64_t)cpi->bytes; |
3478 | | for (int i = 0; i < MAX_MODES; i++) { |
3479 | | ppi->total_mode_chosen_counts[i] += cpi->mode_chosen_counts[i]; |
3480 | | } |
3481 | | } |
3482 | | #endif // CONFIG_INTERNAL_STATS |
3483 | |
|
3484 | 0 | if (!cpi_data.frame_size) continue; |
3485 | 0 | assert(cpi_data.cx_data != NULL && cpi_data.cx_data_sz != 0); |
3486 | 0 | if (cpi_data.frame_size > cpi_data.cx_data_sz) { |
3487 | 0 | aom_internal_error(&ppi->error, AOM_CODEC_ERROR, |
3488 | 0 | "cpi_data.cx_data buffer overflow"); |
3489 | 0 | } |
3490 | 0 | const int write_temporal_delimiter = |
3491 | 0 | !cpi->common.spatial_layer_id && !ctx->pending_cx_data_sz; |
3492 | |
|
3493 | 0 | if (write_temporal_delimiter) { |
3494 | 0 | uint32_t obu_header_size = 1; |
3495 | 0 | const uint32_t obu_payload_size = 0; |
3496 | 0 | const size_t length_field_size = |
3497 | 0 | aom_uleb_size_in_bytes(obu_payload_size); |
3498 | |
|
3499 | 0 | const size_t move_offset = obu_header_size + length_field_size; |
3500 | 0 | assert(ctx->cx_data_sz == cpi_data.cx_data_sz); |
3501 | 0 | if (move_offset > ctx->cx_data_sz - cpi_data.frame_size) { |
3502 | 0 | aom_internal_error(&ppi->error, AOM_CODEC_ERROR, |
3503 | 0 | "ctx->cx_data buffer full"); |
3504 | 0 | } |
3505 | 0 | memmove(ctx->cx_data + move_offset, ctx->cx_data, cpi_data.frame_size); |
3506 | 0 | obu_header_size = av1_write_obu_header( |
3507 | 0 | &ppi->level_params, &cpi->frame_header_count, |
3508 | 0 | OBU_TEMPORAL_DELIMITER, |
3509 | 0 | ppi->seq_params.has_nonzero_operating_point_idc, |
3510 | | /*is_layer_specific_obu=*/false, 0, ctx->cx_data); |
3511 | 0 | if (obu_header_size != 1) { |
3512 | 0 | aom_internal_error(&ppi->error, AOM_CODEC_ERROR, NULL); |
3513 | 0 | } |
3514 | | |
3515 | | // OBUs are preceded/succeeded by an unsigned leb128 coded integer. |
3516 | 0 | if (av1_write_uleb_obu_size(obu_payload_size, |
3517 | 0 | ctx->cx_data + obu_header_size, |
3518 | 0 | length_field_size) != AOM_CODEC_OK) { |
3519 | 0 | aom_internal_error(&ppi->error, AOM_CODEC_ERROR, NULL); |
3520 | 0 | } |
3521 | |
|
3522 | 0 | cpi_data.frame_size += move_offset; |
3523 | 0 | } |
3524 | |
|
3525 | 0 | if (ctx->oxcf.save_as_annexb) { |
3526 | 0 | if (av1_convert_sect5obus_to_annexb( |
3527 | 0 | cpi_data.cx_data, cpi_data.cx_data_sz, &cpi_data.frame_size) != |
3528 | 0 | AOM_CODEC_OK) { |
3529 | 0 | aom_internal_error(&ppi->error, AOM_CODEC_ERROR, NULL); |
3530 | 0 | } |
3531 | | |
3532 | | // B_PRIME (add frame size) |
3533 | 0 | const size_t length_field_size = |
3534 | 0 | aom_uleb_size_in_bytes(cpi_data.frame_size); |
3535 | 0 | if (length_field_size > cpi_data.cx_data_sz - cpi_data.frame_size) { |
3536 | 0 | aom_internal_error(&ppi->error, AOM_CODEC_ERROR, |
3537 | 0 | "cpi_data.cx_data buffer full"); |
3538 | 0 | } |
3539 | 0 | memmove(cpi_data.cx_data + length_field_size, cpi_data.cx_data, |
3540 | 0 | cpi_data.frame_size); |
3541 | 0 | if (av1_write_uleb_obu_size(cpi_data.frame_size, cpi_data.cx_data, |
3542 | 0 | length_field_size) != AOM_CODEC_OK) { |
3543 | 0 | aom_internal_error(&ppi->error, AOM_CODEC_ERROR, NULL); |
3544 | 0 | } |
3545 | 0 | cpi_data.frame_size += length_field_size; |
3546 | 0 | } |
3547 | |
|
3548 | 0 | ctx->pending_cx_data_sz += cpi_data.frame_size; |
3549 | |
|
3550 | 0 | cpi_data.cx_data += cpi_data.frame_size; |
3551 | 0 | cpi_data.cx_data_sz -= cpi_data.frame_size; |
3552 | |
|
3553 | 0 | is_frame_visible = cpi->common.show_frame; |
3554 | |
|
3555 | 0 | has_no_show_keyframe |= |
3556 | 0 | (!is_frame_visible && |
3557 | 0 | cpi->common.current_frame.frame_type == KEY_FRAME); |
3558 | 0 | } |
3559 | 0 | if (is_frame_visible) { |
3560 | | // Add the frame packet to the list of returned packets. |
3561 | 0 | aom_codec_cx_pkt_t pkt; |
3562 | | |
3563 | | // decrement frames_left counter |
3564 | 0 | ppi->frames_left = AOMMAX(0, ppi->frames_left - 1); |
3565 | 0 | if (ctx->oxcf.save_as_annexb) { |
3566 | | // B_PRIME (add TU size) |
3567 | 0 | size_t tu_size = ctx->pending_cx_data_sz; |
3568 | 0 | const size_t length_field_size = aom_uleb_size_in_bytes(tu_size); |
3569 | 0 | if (tu_size > ctx->cx_data_sz) { |
3570 | 0 | aom_internal_error(&ppi->error, AOM_CODEC_ERROR, |
3571 | 0 | "ctx->cx_data buffer overflow"); |
3572 | 0 | } |
3573 | 0 | if (length_field_size > ctx->cx_data_sz - tu_size) { |
3574 | 0 | aom_internal_error(&ppi->error, AOM_CODEC_ERROR, |
3575 | 0 | "ctx->cx_data buffer full"); |
3576 | 0 | } |
3577 | 0 | memmove(ctx->cx_data + length_field_size, ctx->cx_data, tu_size); |
3578 | 0 | if (av1_write_uleb_obu_size(tu_size, ctx->cx_data, length_field_size) != |
3579 | 0 | AOM_CODEC_OK) { |
3580 | 0 | aom_internal_error(&ppi->error, AOM_CODEC_ERROR, NULL); |
3581 | 0 | } |
3582 | 0 | ctx->pending_cx_data_sz += length_field_size; |
3583 | 0 | } |
3584 | |
|
3585 | 0 | pkt.kind = AOM_CODEC_CX_FRAME_PKT; |
3586 | |
|
3587 | 0 | pkt.data.frame.buf = ctx->cx_data; |
3588 | 0 | pkt.data.frame.sz = ctx->pending_cx_data_sz; |
3589 | 0 | pkt.data.frame.partition_id = -1; |
3590 | 0 | pkt.data.frame.vis_frame_size = cpi_data.frame_size; |
3591 | |
|
3592 | 0 | pkt.data.frame.pts = ticks_to_timebase_units(cpi_data.timestamp_ratio, |
3593 | 0 | cpi_data.ts_frame_start) + |
3594 | 0 | ctx->pts_offset; |
3595 | 0 | pkt.data.frame.flags = get_frame_pkt_flags(cpi, cpi_data.lib_flags); |
3596 | 0 | if (has_no_show_keyframe) { |
3597 | | // If one of the invisible frames in the packet is a keyframe, set |
3598 | | // the delayed random access point flag. |
3599 | 0 | pkt.data.frame.flags |= AOM_FRAME_IS_DELAYED_RANDOM_ACCESS_POINT; |
3600 | 0 | } |
3601 | 0 | const int64_t duration64 = ticks_to_timebase_units( |
3602 | 0 | cpi_data.timestamp_ratio, |
3603 | 0 | cpi_data.ts_frame_end - cpi_data.ts_frame_start); |
3604 | 0 | if (duration64 > UINT32_MAX) { |
3605 | 0 | aom_internal_error(&ppi->error, AOM_CODEC_ERROR, NULL); |
3606 | 0 | } |
3607 | 0 | pkt.data.frame.duration = (uint32_t)duration64; |
3608 | |
|
3609 | 0 | aom_codec_pkt_list_add(&ctx->pkt_list.head, &pkt); |
3610 | |
|
3611 | 0 | ctx->pending_cx_data_sz = 0; |
3612 | 0 | } |
3613 | 0 | } |
3614 | |
|
3615 | 0 | ppi->error.setjmp = 0; |
3616 | 0 | return res; |
3617 | 0 | } |
3618 | | |
3619 | | static const aom_codec_cx_pkt_t *encoder_get_cxdata(aom_codec_alg_priv_t *ctx, |
3620 | 0 | aom_codec_iter_t *iter) { |
3621 | 0 | return aom_codec_pkt_list_get(&ctx->pkt_list.head, iter); |
3622 | 0 | } |
3623 | | |
3624 | | static aom_codec_err_t ctrl_set_reference(aom_codec_alg_priv_t *ctx, |
3625 | 0 | va_list args) { |
3626 | 0 | av1_ref_frame_t *const frame = va_arg(args, av1_ref_frame_t *); |
3627 | |
|
3628 | 0 | if (frame != NULL) { |
3629 | 0 | YV12_BUFFER_CONFIG sd; |
3630 | |
|
3631 | 0 | image2yuvconfig(&frame->img, &sd); |
3632 | 0 | av1_set_reference_enc(ctx->ppi->cpi, frame->idx, &sd); |
3633 | 0 | return AOM_CODEC_OK; |
3634 | 0 | } else { |
3635 | 0 | return AOM_CODEC_INVALID_PARAM; |
3636 | 0 | } |
3637 | 0 | } |
3638 | | |
3639 | | static aom_codec_err_t ctrl_copy_reference(aom_codec_alg_priv_t *ctx, |
3640 | 0 | va_list args) { |
3641 | 0 | if (ctx->ppi->cpi->oxcf.algo_cfg.skip_postproc_filtering) |
3642 | 0 | return AOM_CODEC_INCAPABLE; |
3643 | 0 | av1_ref_frame_t *const frame = va_arg(args, av1_ref_frame_t *); |
3644 | |
|
3645 | 0 | if (frame != NULL) { |
3646 | 0 | YV12_BUFFER_CONFIG sd; |
3647 | |
|
3648 | 0 | image2yuvconfig(&frame->img, &sd); |
3649 | 0 | av1_copy_reference_enc(ctx->ppi->cpi, frame->idx, &sd); |
3650 | 0 | return AOM_CODEC_OK; |
3651 | 0 | } else { |
3652 | 0 | return AOM_CODEC_INVALID_PARAM; |
3653 | 0 | } |
3654 | 0 | } |
3655 | | |
3656 | | static aom_codec_err_t ctrl_get_reference(aom_codec_alg_priv_t *ctx, |
3657 | 0 | va_list args) { |
3658 | 0 | if (ctx->ppi->cpi->oxcf.algo_cfg.skip_postproc_filtering) |
3659 | 0 | return AOM_CODEC_INCAPABLE; |
3660 | 0 | av1_ref_frame_t *const frame = va_arg(args, av1_ref_frame_t *); |
3661 | |
|
3662 | 0 | if (frame != NULL) { |
3663 | 0 | YV12_BUFFER_CONFIG *fb = get_ref_frame(&ctx->ppi->cpi->common, frame->idx); |
3664 | 0 | if (fb == NULL) return AOM_CODEC_ERROR; |
3665 | | |
3666 | 0 | yuvconfig2image(&frame->img, fb, NULL); |
3667 | 0 | return AOM_CODEC_OK; |
3668 | 0 | } else { |
3669 | 0 | return AOM_CODEC_INVALID_PARAM; |
3670 | 0 | } |
3671 | 0 | } |
3672 | | |
3673 | | static aom_codec_err_t ctrl_get_new_frame_image(aom_codec_alg_priv_t *ctx, |
3674 | 0 | va_list args) { |
3675 | 0 | aom_image_t *const new_img = va_arg(args, aom_image_t *); |
3676 | |
|
3677 | 0 | if (new_img != NULL) { |
3678 | 0 | YV12_BUFFER_CONFIG new_frame; |
3679 | |
|
3680 | 0 | if (av1_get_last_show_frame(ctx->ppi->cpi, &new_frame) == 0) { |
3681 | 0 | yuvconfig2image(new_img, &new_frame, NULL); |
3682 | 0 | return AOM_CODEC_OK; |
3683 | 0 | } else { |
3684 | 0 | return AOM_CODEC_ERROR; |
3685 | 0 | } |
3686 | 0 | } else { |
3687 | 0 | return AOM_CODEC_INVALID_PARAM; |
3688 | 0 | } |
3689 | 0 | } |
3690 | | |
3691 | | static aom_codec_err_t ctrl_copy_new_frame_image(aom_codec_alg_priv_t *ctx, |
3692 | 0 | va_list args) { |
3693 | 0 | aom_image_t *const new_img = va_arg(args, aom_image_t *); |
3694 | |
|
3695 | 0 | if (new_img != NULL) { |
3696 | 0 | YV12_BUFFER_CONFIG new_frame; |
3697 | |
|
3698 | 0 | if (av1_get_last_show_frame(ctx->ppi->cpi, &new_frame) == 0) { |
3699 | 0 | YV12_BUFFER_CONFIG sd; |
3700 | 0 | image2yuvconfig(new_img, &sd); |
3701 | 0 | return av1_copy_new_frame_enc(&ctx->ppi->cpi->common, &new_frame, &sd); |
3702 | 0 | } else { |
3703 | 0 | return AOM_CODEC_ERROR; |
3704 | 0 | } |
3705 | 0 | } else { |
3706 | 0 | return AOM_CODEC_INVALID_PARAM; |
3707 | 0 | } |
3708 | 0 | } |
3709 | | |
3710 | 0 | static aom_image_t *encoder_get_preview(aom_codec_alg_priv_t *ctx) { |
3711 | 0 | YV12_BUFFER_CONFIG sd; |
3712 | |
|
3713 | 0 | if (av1_get_preview_raw_frame(ctx->ppi->cpi, &sd) == 0) { |
3714 | 0 | yuvconfig2image(&ctx->preview_img, &sd, NULL); |
3715 | 0 | return &ctx->preview_img; |
3716 | 0 | } else { |
3717 | 0 | return NULL; |
3718 | 0 | } |
3719 | 0 | } |
3720 | | |
3721 | | static aom_codec_err_t ctrl_use_reference(aom_codec_alg_priv_t *ctx, |
3722 | 0 | va_list args) { |
3723 | 0 | const int reference_flag = va_arg(args, int); |
3724 | |
|
3725 | 0 | av1_use_as_reference(&ctx->ppi->cpi->ext_flags.ref_frame_flags, |
3726 | 0 | reference_flag); |
3727 | 0 | return AOM_CODEC_OK; |
3728 | 0 | } |
3729 | | |
3730 | | static aom_codec_err_t ctrl_set_roi_map(aom_codec_alg_priv_t *ctx, |
3731 | 0 | va_list args) { |
3732 | 0 | (void)ctx; |
3733 | 0 | (void)args; |
3734 | | |
3735 | | // TODO(yaowu): Need to re-implement and test for AV1. |
3736 | 0 | return AOM_CODEC_INVALID_PARAM; |
3737 | 0 | } |
3738 | | |
3739 | | static aom_codec_err_t ctrl_set_active_map(aom_codec_alg_priv_t *ctx, |
3740 | 0 | va_list args) { |
3741 | 0 | aom_active_map_t *const map = va_arg(args, aom_active_map_t *); |
3742 | |
|
3743 | 0 | if (map) { |
3744 | 0 | if (!av1_set_active_map(ctx->ppi->cpi, map->active_map, (int)map->rows, |
3745 | 0 | (int)map->cols)) |
3746 | 0 | return AOM_CODEC_OK; |
3747 | 0 | else |
3748 | 0 | return AOM_CODEC_INVALID_PARAM; |
3749 | 0 | } else { |
3750 | 0 | return AOM_CODEC_INVALID_PARAM; |
3751 | 0 | } |
3752 | 0 | } |
3753 | | |
3754 | | static aom_codec_err_t ctrl_get_active_map(aom_codec_alg_priv_t *ctx, |
3755 | 0 | va_list args) { |
3756 | 0 | aom_active_map_t *const map = va_arg(args, aom_active_map_t *); |
3757 | |
|
3758 | 0 | if (map) { |
3759 | 0 | if (!av1_get_active_map(ctx->ppi->cpi, map->active_map, (int)map->rows, |
3760 | 0 | (int)map->cols)) |
3761 | 0 | return AOM_CODEC_OK; |
3762 | 0 | else |
3763 | 0 | return AOM_CODEC_INVALID_PARAM; |
3764 | 0 | } else { |
3765 | 0 | return AOM_CODEC_INVALID_PARAM; |
3766 | 0 | } |
3767 | 0 | } |
3768 | | |
3769 | | static aom_codec_err_t ctrl_set_scale_mode(aom_codec_alg_priv_t *ctx, |
3770 | 0 | va_list args) { |
3771 | 0 | aom_scaling_mode_t *const mode = va_arg(args, aom_scaling_mode_t *); |
3772 | |
|
3773 | 0 | if (mode) { |
3774 | 0 | AV1EncoderConfig *const oxcf = |
3775 | 0 | ctx->ppi->seq_params_locked ? &ctx->ppi->cpi->oxcf : &ctx->oxcf; |
3776 | 0 | const int res = |
3777 | 0 | av1_set_internal_size(oxcf, &ctx->ppi->cpi->resize_pending_params, |
3778 | 0 | mode->h_scaling_mode, mode->v_scaling_mode); |
3779 | 0 | if (res == 0) { |
3780 | | // update_encoder_cfg() is somewhat costly and this control may be called |
3781 | | // multiple times, so update_encoder_cfg() is only called to ensure frame |
3782 | | // and superblock sizes are updated before they're fixed by the first |
3783 | | // encode call. |
3784 | 0 | if (ctx->ppi->seq_params_locked) { |
3785 | 0 | av1_check_fpmt_config(ctx->ppi, &ctx->ppi->cpi->oxcf); |
3786 | 0 | return AOM_CODEC_OK; |
3787 | 0 | } |
3788 | 0 | return update_encoder_cfg(ctx); |
3789 | 0 | } |
3790 | 0 | return AOM_CODEC_INVALID_PARAM; |
3791 | 0 | } else { |
3792 | 0 | return AOM_CODEC_INVALID_PARAM; |
3793 | 0 | } |
3794 | 0 | } |
3795 | | |
3796 | | static aom_codec_err_t ctrl_set_spatial_layer_id(aom_codec_alg_priv_t *ctx, |
3797 | 0 | va_list args) { |
3798 | 0 | const int spatial_layer_id = va_arg(args, int); |
3799 | 0 | if (spatial_layer_id >= MAX_NUM_SPATIAL_LAYERS) |
3800 | 0 | return AOM_CODEC_INVALID_PARAM; |
3801 | 0 | ctx->ppi->cpi->common.spatial_layer_id = spatial_layer_id; |
3802 | 0 | return AOM_CODEC_OK; |
3803 | 0 | } |
3804 | | |
3805 | | static aom_codec_err_t ctrl_set_number_spatial_layers(aom_codec_alg_priv_t *ctx, |
3806 | 0 | va_list args) { |
3807 | 0 | const int number_spatial_layers = va_arg(args, int); |
3808 | 0 | if (number_spatial_layers > MAX_NUM_SPATIAL_LAYERS) |
3809 | 0 | return AOM_CODEC_INVALID_PARAM; |
3810 | 0 | ctx->ppi->number_spatial_layers = number_spatial_layers; |
3811 | | // update_encoder_cfg() is somewhat costly and this control may be called |
3812 | | // multiple times, so update_encoder_cfg() is only called to ensure frame and |
3813 | | // superblock sizes are updated before they're fixed by the first encode |
3814 | | // call. |
3815 | 0 | if (!ctx->ppi->seq_params_locked) { |
3816 | 0 | return update_encoder_cfg(ctx); |
3817 | 0 | } |
3818 | 0 | return AOM_CODEC_OK; |
3819 | 0 | } |
3820 | | |
3821 | | static aom_codec_err_t ctrl_set_layer_id(aom_codec_alg_priv_t *ctx, |
3822 | 0 | va_list args) { |
3823 | 0 | aom_svc_layer_id_t *const data = va_arg(args, aom_svc_layer_id_t *); |
3824 | 0 | ctx->ppi->cpi->common.spatial_layer_id = data->spatial_layer_id; |
3825 | 0 | ctx->ppi->cpi->common.temporal_layer_id = data->temporal_layer_id; |
3826 | 0 | ctx->ppi->cpi->svc.spatial_layer_id = data->spatial_layer_id; |
3827 | 0 | ctx->ppi->cpi->svc.temporal_layer_id = data->temporal_layer_id; |
3828 | 0 | return AOM_CODEC_OK; |
3829 | 0 | } |
3830 | | |
3831 | | static aom_codec_err_t ctrl_set_svc_params(aom_codec_alg_priv_t *ctx, |
3832 | 0 | va_list args) { |
3833 | 0 | AV1_PRIMARY *const ppi = ctx->ppi; |
3834 | 0 | AV1_COMP *const cpi = ppi->cpi; |
3835 | 0 | aom_svc_params_t *const params = va_arg(args, aom_svc_params_t *); |
3836 | 0 | int64_t target_bandwidth = 0; |
3837 | 0 | ppi->number_spatial_layers = params->number_spatial_layers; |
3838 | 0 | ppi->number_temporal_layers = params->number_temporal_layers; |
3839 | 0 | cpi->svc.number_spatial_layers = params->number_spatial_layers; |
3840 | 0 | cpi->svc.number_temporal_layers = params->number_temporal_layers; |
3841 | 0 | if (ppi->number_spatial_layers > 1 || ppi->number_temporal_layers > 1) { |
3842 | 0 | unsigned int sl, tl; |
3843 | 0 | ctx->ppi->use_svc = 1; |
3844 | 0 | const int num_layers = |
3845 | 0 | ppi->number_spatial_layers * ppi->number_temporal_layers; |
3846 | 0 | for (int layer = 0; layer < num_layers; ++layer) { |
3847 | 0 | if (params->max_quantizers[layer] > 63 || |
3848 | 0 | params->min_quantizers[layer] < 0 || |
3849 | 0 | params->min_quantizers[layer] > params->max_quantizers[layer]) { |
3850 | 0 | return AOM_CODEC_INVALID_PARAM; |
3851 | 0 | } |
3852 | 0 | } |
3853 | 0 | if (!av1_alloc_layer_context(cpi, num_layers)) return AOM_CODEC_MEM_ERROR; |
3854 | | |
3855 | 0 | for (sl = 0; sl < ppi->number_spatial_layers; ++sl) { |
3856 | 0 | for (tl = 0; tl < ppi->number_temporal_layers; ++tl) { |
3857 | 0 | const int layer = LAYER_IDS_TO_IDX(sl, tl, ppi->number_temporal_layers); |
3858 | 0 | LAYER_CONTEXT *lc = &cpi->svc.layer_context[layer]; |
3859 | 0 | lc->max_q = params->max_quantizers[layer]; |
3860 | 0 | lc->min_q = params->min_quantizers[layer]; |
3861 | 0 | lc->scaling_factor_num = AOMMAX(1, params->scaling_factor_num[sl]); |
3862 | 0 | lc->scaling_factor_den = AOMMAX(1, params->scaling_factor_den[sl]); |
3863 | 0 | const int layer_target_bitrate = params->layer_target_bitrate[layer]; |
3864 | 0 | if (layer_target_bitrate > INT_MAX / 1000) { |
3865 | 0 | lc->layer_target_bitrate = INT_MAX; |
3866 | 0 | } else { |
3867 | 0 | lc->layer_target_bitrate = 1000 * layer_target_bitrate; |
3868 | 0 | } |
3869 | 0 | lc->framerate_factor = params->framerate_factor[tl]; |
3870 | 0 | if (tl == ppi->number_temporal_layers - 1) |
3871 | 0 | target_bandwidth += lc->layer_target_bitrate; |
3872 | 0 | } |
3873 | 0 | } |
3874 | |
|
3875 | 0 | if (ppi->seq_params_locked) { |
3876 | 0 | AV1EncoderConfig *const oxcf = &cpi->oxcf; |
3877 | | // Keep ctx->oxcf in sync in case further codec controls are made prior |
3878 | | // to encoding. |
3879 | 0 | ctx->oxcf.rc_cfg.target_bandwidth = oxcf->rc_cfg.target_bandwidth = |
3880 | 0 | target_bandwidth; |
3881 | 0 | set_primary_rc_buffer_sizes(oxcf, ppi); |
3882 | 0 | av1_update_layer_context_change_config(cpi, target_bandwidth); |
3883 | 0 | check_reset_rc_flag(cpi); |
3884 | 0 | } else { |
3885 | | // Note av1_init_layer_context() relies on cpi->oxcf. The order of that |
3886 | | // call and the ones in the other half of this block (which |
3887 | | // update_encoder_cfg() transitively makes) is important. So we keep |
3888 | | // ctx->oxcf and cpi->oxcf in sync here as update_encoder_cfg() will |
3889 | | // overwrite cpi->oxcf with ctx->oxcf. |
3890 | 0 | ctx->oxcf.rc_cfg.target_bandwidth = cpi->oxcf.rc_cfg.target_bandwidth = |
3891 | 0 | target_bandwidth; |
3892 | 0 | SequenceHeader *const seq_params = &ppi->seq_params; |
3893 | 0 | seq_params->operating_points_cnt_minus_1 = |
3894 | 0 | ppi->number_spatial_layers * ppi->number_temporal_layers - 1; |
3895 | |
|
3896 | 0 | av1_init_layer_context(cpi); |
3897 | | // update_encoder_cfg() is somewhat costly and this control may be called |
3898 | | // multiple times, so update_encoder_cfg() is only called to ensure frame |
3899 | | // and superblock sizes are updated before they're fixed by the first |
3900 | | // encode call. |
3901 | 0 | return update_encoder_cfg(ctx); |
3902 | 0 | } |
3903 | 0 | } else if (!ppi->seq_params_locked) { |
3904 | | // Ensure frame and superblock sizes are updated. |
3905 | 0 | return update_encoder_cfg(ctx); |
3906 | 0 | } |
3907 | 0 | av1_check_fpmt_config(ctx->ppi, &ctx->ppi->cpi->oxcf); |
3908 | 0 | return AOM_CODEC_OK; |
3909 | 0 | } |
3910 | | |
3911 | | static aom_codec_err_t ctrl_set_svc_ref_frame_config(aom_codec_alg_priv_t *ctx, |
3912 | 0 | va_list args) { |
3913 | 0 | AV1_COMP *const cpi = ctx->ppi->cpi; |
3914 | 0 | aom_svc_ref_frame_config_t *const data = |
3915 | 0 | va_arg(args, aom_svc_ref_frame_config_t *); |
3916 | 0 | cpi->ppi->rtc_ref.set_ref_frame_config = 1; |
3917 | 0 | for (unsigned int i = 0; i < INTER_REFS_PER_FRAME; ++i) { |
3918 | 0 | if (data->reference[i] != 0 && data->reference[i] != 1) |
3919 | 0 | return AOM_CODEC_INVALID_PARAM; |
3920 | 0 | if (data->ref_idx[i] > 7 || data->ref_idx[i] < 0) |
3921 | 0 | return AOM_CODEC_INVALID_PARAM; |
3922 | 0 | cpi->ppi->rtc_ref.reference[i] = data->reference[i]; |
3923 | 0 | cpi->ppi->rtc_ref.ref_idx[i] = data->ref_idx[i]; |
3924 | 0 | } |
3925 | 0 | for (unsigned int i = 0; i < REF_FRAMES; ++i) { |
3926 | 0 | if (data->refresh[i] != 0 && data->refresh[i] != 1) |
3927 | 0 | return AOM_CODEC_INVALID_PARAM; |
3928 | 0 | cpi->ppi->rtc_ref.refresh[i] = data->refresh[i]; |
3929 | 0 | } |
3930 | 0 | cpi->svc.use_flexible_mode = 1; |
3931 | 0 | cpi->svc.ksvc_fixed_mode = 0; |
3932 | 0 | return AOM_CODEC_OK; |
3933 | 0 | } |
3934 | | |
3935 | | static aom_codec_err_t ctrl_set_svc_ref_frame_comp_pred( |
3936 | 0 | aom_codec_alg_priv_t *ctx, va_list args) { |
3937 | 0 | AV1_COMP *const cpi = ctx->ppi->cpi; |
3938 | 0 | aom_svc_ref_frame_comp_pred_t *const data = |
3939 | 0 | va_arg(args, aom_svc_ref_frame_comp_pred_t *); |
3940 | 0 | cpi->ppi->rtc_ref.ref_frame_comp[0] = data->use_comp_pred[0]; |
3941 | 0 | cpi->ppi->rtc_ref.ref_frame_comp[1] = data->use_comp_pred[1]; |
3942 | 0 | cpi->ppi->rtc_ref.ref_frame_comp[2] = data->use_comp_pred[2]; |
3943 | 0 | return AOM_CODEC_OK; |
3944 | 0 | } |
3945 | | |
3946 | | static aom_codec_err_t ctrl_set_tune_content(aom_codec_alg_priv_t *ctx, |
3947 | 0 | va_list args) { |
3948 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
3949 | 0 | extra_cfg.content = CAST(AV1E_SET_TUNE_CONTENT, args); |
3950 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
3951 | 0 | } |
3952 | | |
3953 | | static aom_codec_err_t ctrl_set_cdf_update_mode(aom_codec_alg_priv_t *ctx, |
3954 | 0 | va_list args) { |
3955 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
3956 | 0 | extra_cfg.cdf_update_mode = CAST(AV1E_SET_CDF_UPDATE_MODE, args); |
3957 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
3958 | 0 | } |
3959 | | |
3960 | | static aom_codec_err_t ctrl_set_color_primaries(aom_codec_alg_priv_t *ctx, |
3961 | 0 | va_list args) { |
3962 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
3963 | 0 | extra_cfg.color_primaries = CAST(AV1E_SET_COLOR_PRIMARIES, args); |
3964 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
3965 | 0 | } |
3966 | | |
3967 | | static aom_codec_err_t ctrl_set_transfer_characteristics( |
3968 | 0 | aom_codec_alg_priv_t *ctx, va_list args) { |
3969 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
3970 | 0 | extra_cfg.transfer_characteristics = |
3971 | 0 | CAST(AV1E_SET_TRANSFER_CHARACTERISTICS, args); |
3972 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
3973 | 0 | } |
3974 | | |
3975 | | static aom_codec_err_t ctrl_set_matrix_coefficients(aom_codec_alg_priv_t *ctx, |
3976 | 0 | va_list args) { |
3977 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
3978 | 0 | extra_cfg.matrix_coefficients = CAST(AV1E_SET_MATRIX_COEFFICIENTS, args); |
3979 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
3980 | 0 | } |
3981 | | |
3982 | | static aom_codec_err_t ctrl_set_chroma_sample_position( |
3983 | 0 | aom_codec_alg_priv_t *ctx, va_list args) { |
3984 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
3985 | 0 | extra_cfg.chroma_sample_position = |
3986 | 0 | CAST(AV1E_SET_CHROMA_SAMPLE_POSITION, args); |
3987 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
3988 | 0 | } |
3989 | | |
3990 | | static aom_codec_err_t ctrl_set_color_range(aom_codec_alg_priv_t *ctx, |
3991 | 0 | va_list args) { |
3992 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
3993 | 0 | extra_cfg.color_range = CAST(AV1E_SET_COLOR_RANGE, args); |
3994 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
3995 | 0 | } |
3996 | | |
3997 | | static aom_codec_err_t ctrl_set_render_size(aom_codec_alg_priv_t *ctx, |
3998 | 0 | va_list args) { |
3999 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
4000 | 0 | int *const render_size = va_arg(args, int *); |
4001 | 0 | extra_cfg.render_width = render_size[0]; |
4002 | 0 | extra_cfg.render_height = render_size[1]; |
4003 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
4004 | 0 | } |
4005 | | |
4006 | | static aom_codec_err_t ctrl_set_superblock_size(aom_codec_alg_priv_t *ctx, |
4007 | 0 | va_list args) { |
4008 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
4009 | 0 | extra_cfg.superblock_size = CAST(AV1E_SET_SUPERBLOCK_SIZE, args); |
4010 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
4011 | 0 | } |
4012 | | |
4013 | | static aom_codec_err_t ctrl_set_chroma_subsampling_x(aom_codec_alg_priv_t *ctx, |
4014 | 0 | va_list args) { |
4015 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
4016 | 0 | extra_cfg.chroma_subsampling_x = CAST(AV1E_SET_CHROMA_SUBSAMPLING_X, args); |
4017 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
4018 | 0 | } |
4019 | | |
4020 | | static aom_codec_err_t ctrl_set_chroma_subsampling_y(aom_codec_alg_priv_t *ctx, |
4021 | 0 | va_list args) { |
4022 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
4023 | 0 | extra_cfg.chroma_subsampling_y = CAST(AV1E_SET_CHROMA_SUBSAMPLING_Y, args); |
4024 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
4025 | 0 | } |
4026 | | |
4027 | | static aom_codec_err_t encoder_set_option(aom_codec_alg_priv_t *ctx, |
4028 | 0 | const char *name, const char *value) { |
4029 | 0 | if (ctx == NULL || name == NULL || value == NULL) |
4030 | 0 | return AOM_CODEC_INVALID_PARAM; |
4031 | 0 | struct av1_extracfg extra_cfg = ctx->extra_cfg; |
4032 | | // Used to mock the argv with just one string "--{name}={value}" |
4033 | 0 | char *argv[2] = { NULL, "" }; |
4034 | 0 | size_t len = strlen(name) + strlen(value) + 4; |
4035 | 0 | char *const err_string = ctx->ppi->error.detail; |
4036 | |
|
4037 | | #if __STDC_VERSION__ >= 201112L |
4038 | | // We use the keyword _Static_assert because clang-cl does not allow the |
4039 | | // convenience macro static_assert to be used in function scope. See |
4040 | | // https://bugs.llvm.org/show_bug.cgi?id=48904. |
4041 | | _Static_assert(sizeof(ctx->ppi->error.detail) >= ARG_ERR_MSG_MAX_LEN, |
4042 | | "The size of the err_msg buffer for arg_match_helper must be " |
4043 | | "at least ARG_ERR_MSG_MAX_LEN"); |
4044 | | #else |
4045 | 0 | assert(sizeof(ctx->ppi->error.detail) >= ARG_ERR_MSG_MAX_LEN); |
4046 | 0 | #endif |
4047 | |
|
4048 | 0 | argv[0] = aom_malloc(len * sizeof(argv[1][0])); |
4049 | 0 | if (!argv[0]) return AOM_CODEC_MEM_ERROR; |
4050 | 0 | snprintf(argv[0], len, "--%s=%s", name, value); |
4051 | 0 | struct arg arg; |
4052 | 0 | aom_codec_err_t err = AOM_CODEC_OK; |
4053 | |
|
4054 | 0 | int match = 1; |
4055 | 0 | if (arg_match_helper(&arg, &g_av1_codec_arg_defs.enable_keyframe_filtering, |
4056 | 0 | argv, err_string)) { |
4057 | 0 | extra_cfg.enable_keyframe_filtering = |
4058 | 0 | arg_parse_uint_helper(&arg, err_string); |
4059 | 0 | } else if (arg_match_helper(&arg, &g_av1_codec_arg_defs.min_gf_interval, argv, |
4060 | 0 | err_string)) { |
4061 | 0 | extra_cfg.min_gf_interval = arg_parse_uint_helper(&arg, err_string); |
4062 | 0 | } else if (arg_match_helper(&arg, &g_av1_codec_arg_defs.max_gf_interval, argv, |
4063 | 0 | err_string)) { |
4064 | 0 | extra_cfg.max_gf_interval = arg_parse_uint_helper(&arg, err_string); |
4065 | 0 | } else if (arg_match_helper(&arg, &g_av1_codec_arg_defs.gf_min_pyr_height, |
4066 | 0 | argv, err_string)) { |
4067 | 0 | extra_cfg.gf_min_pyr_height = arg_parse_uint_helper(&arg, err_string); |
4068 | 0 | } else if (arg_match_helper(&arg, &g_av1_codec_arg_defs.gf_max_pyr_height, |
4069 | 0 | argv, err_string)) { |
4070 | 0 | extra_cfg.gf_max_pyr_height = arg_parse_uint_helper(&arg, err_string); |
4071 | 0 | } else if (arg_match_helper(&arg, &g_av1_codec_arg_defs.cpu_used_av1, argv, |
4072 | 0 | err_string)) { |
4073 | 0 | extra_cfg.cpu_used = arg_parse_uint_helper(&arg, err_string); |
4074 | 0 | } else if (arg_match_helper(&arg, &g_av1_codec_arg_defs.auto_altref, argv, |
4075 | 0 | err_string)) { |
4076 | 0 | extra_cfg.enable_auto_alt_ref = arg_parse_uint_helper(&arg, err_string); |
4077 | 0 | } else if (arg_match_helper(&arg, &g_av1_codec_arg_defs.noise_sens, argv, |
4078 | 0 | err_string)) { |
4079 | 0 | extra_cfg.noise_sensitivity = arg_parse_uint_helper(&arg, err_string); |
4080 | 0 | } else if (arg_match_helper(&arg, &g_av1_codec_arg_defs.sharpness, argv, |
4081 | 0 | err_string)) { |
4082 | 0 | extra_cfg.sharpness = arg_parse_uint_helper(&arg, err_string); |
4083 | 0 | } else if (arg_match_helper(&arg, &g_av1_codec_arg_defs.static_thresh, argv, |
4084 | 0 | err_string)) { |
4085 | 0 | extra_cfg.static_thresh = arg_parse_uint_helper(&arg, err_string); |
4086 | 0 | } else if (arg_match_helper(&arg, &g_av1_codec_arg_defs.rowmtarg, argv, |
4087 | 0 | err_string)) { |
4088 | 0 | extra_cfg.row_mt = arg_parse_uint_helper(&arg, err_string); |
4089 | 0 | } else if (arg_match_helper(&arg, &g_av1_codec_arg_defs.fpmtarg, argv, |
4090 | 0 | err_string)) { |
4091 | 0 | extra_cfg.fp_mt = arg_parse_uint_helper(&arg, err_string); |
4092 | 0 | } else if (arg_match_helper(&arg, &g_av1_codec_arg_defs.tile_cols, argv, |
4093 | 0 | err_string)) { |
4094 | 0 | extra_cfg.tile_columns = arg_parse_uint_helper(&arg, err_string); |
4095 | 0 | if (extra_cfg.auto_tiles) { |
4096 | 0 | snprintf(err_string, ARG_ERR_MSG_MAX_LEN, |
4097 | 0 | "Cannot set tile-cols because auto-tiles is already set."); |
4098 | 0 | err = AOM_CODEC_INVALID_PARAM; |
4099 | 0 | } |
4100 | 0 | } else if (arg_match_helper(&arg, &g_av1_codec_arg_defs.tile_rows, argv, |
4101 | 0 | err_string)) { |
4102 | 0 | extra_cfg.tile_rows = arg_parse_uint_helper(&arg, err_string); |
4103 | 0 | if (extra_cfg.auto_tiles) { |
4104 | 0 | snprintf(err_string, ARG_ERR_MSG_MAX_LEN, |
4105 | 0 | "Cannot set tile-rows because auto-tiles is already set."); |
4106 | 0 | err = AOM_CODEC_INVALID_PARAM; |
4107 | 0 | } |
4108 | 0 | } else if (arg_match_helper(&arg, &g_av1_codec_arg_defs.auto_tiles, argv, |
4109 | 0 | err_string)) { |
4110 | 0 | extra_cfg.auto_tiles = arg_parse_uint_helper(&arg, err_string); |
4111 | 0 | } else if (arg_match_helper(&arg, &g_av1_codec_arg_defs.enable_tpl_model, |
4112 | 0 | argv, err_string)) { |
4113 | 0 | extra_cfg.enable_tpl_model = arg_parse_uint_helper(&arg, err_string); |
4114 | 0 | } else if (arg_match_helper(&arg, &g_av1_codec_arg_defs.arnr_maxframes, argv, |
4115 | 0 | err_string)) { |
4116 | 0 | extra_cfg.arnr_max_frames = arg_parse_uint_helper(&arg, err_string); |
4117 | 0 | } else if (arg_match_helper(&arg, &g_av1_codec_arg_defs.arnr_strength, argv, |
4118 | 0 | err_string)) { |
4119 | 0 | extra_cfg.arnr_strength = arg_parse_uint_helper(&arg, err_string); |
4120 | 0 | } else if (arg_match_helper(&arg, &g_av1_codec_arg_defs.tune_metric, argv, |
4121 | 0 | err_string)) { |
4122 | 0 | extra_cfg.tuning = arg_parse_enum_helper(&arg, err_string); |
4123 | 0 | err = handle_tuning(ctx, &extra_cfg); |
4124 | 0 | } |
4125 | | #if CONFIG_TUNE_VMAF |
4126 | | else if (arg_match_helper(&arg, &g_av1_codec_arg_defs.vmaf_model_path, argv, |
4127 | | err_string)) { |
4128 | | err = allocate_and_set_string(value, default_extra_cfg.vmaf_model_path, |
4129 | | &extra_cfg.vmaf_model_path, err_string); |
4130 | | } |
4131 | | #endif |
4132 | 0 | else if (arg_match_helper(&arg, &g_av1_codec_arg_defs.partition_info_path, |
4133 | 0 | argv, err_string)) { |
4134 | 0 | err = allocate_and_set_string(value, default_extra_cfg.partition_info_path, |
4135 | 0 | &extra_cfg.partition_info_path, err_string); |
4136 | 0 | } else if (arg_match_helper(&arg, |
4137 | 0 | &g_av1_codec_arg_defs.enable_rate_guide_deltaq, |
4138 | 0 | argv, err_string)) { |
4139 | 0 | extra_cfg.enable_rate_guide_deltaq = |
4140 | 0 | arg_parse_uint_helper(&arg, err_string); |
4141 | 0 | } else if (arg_match_helper(&arg, |
4142 | 0 | &g_av1_codec_arg_defs.rate_distribution_info, |
4143 | 0 | argv, err_string)) { |
4144 | 0 | err = |
4145 | 0 | allocate_and_set_string(value, default_extra_cfg.rate_distribution_info, |
4146 | 0 | &extra_cfg.rate_distribution_info, err_string); |
4147 | 0 | } else if (arg_match_helper(&arg, &g_av1_codec_arg_defs.dist_metric, argv, |
4148 | 0 | err_string)) { |
4149 | 0 | extra_cfg.dist_metric = arg_parse_enum_helper(&arg, err_string); |
4150 | 0 | } else if (arg_match_helper(&arg, &g_av1_codec_arg_defs.cq_level, argv, |
4151 | 0 | err_string)) { |
4152 | 0 | extra_cfg.cq_level = arg_parse_uint_helper(&arg, err_string); |
4153 | 0 | } else if (arg_match_helper(&arg, &g_av1_codec_arg_defs.max_intra_rate_pct, |
4154 | 0 | argv, err_string)) { |
4155 | 0 | extra_cfg.rc_max_intra_bitrate_pct = |
4156 | 0 | arg_parse_uint_helper(&arg, err_string); |
4157 | 0 | } else if (arg_match_helper(&arg, &g_av1_codec_arg_defs.max_inter_rate_pct, |
4158 | 0 | argv, err_string)) { |
4159 | 0 | extra_cfg.rc_max_inter_bitrate_pct = |
4160 | 0 | arg_parse_uint_helper(&arg, err_string); |
4161 | 0 | } else if (arg_match_helper(&arg, &g_av1_codec_arg_defs.gf_cbr_boost_pct, |
4162 | 0 | argv, err_string)) { |
4163 | 0 | extra_cfg.gf_cbr_boost_pct = arg_parse_uint_helper(&arg, err_string); |
4164 | 0 | } else if (arg_match_helper(&arg, &g_av1_codec_arg_defs.lossless, argv, |
4165 | 0 | err_string)) { |
4166 | 0 | extra_cfg.lossless = arg_parse_uint_helper(&arg, err_string); |
4167 | 0 | } else if (arg_match_helper(&arg, &g_av1_codec_arg_defs.enable_cdef, argv, |
4168 | 0 | err_string)) { |
4169 | 0 | extra_cfg.enable_cdef = arg_parse_uint_helper(&arg, err_string); |
4170 | 0 | } else if (arg_match_helper(&arg, &g_av1_codec_arg_defs.enable_restoration, |
4171 | 0 | argv, err_string)) { |
4172 | 0 | extra_cfg.enable_restoration = arg_parse_uint_helper(&arg, err_string); |
4173 | 0 | } else if (arg_match_helper(&arg, &g_av1_codec_arg_defs.force_video_mode, |
4174 | 0 | argv, err_string)) { |
4175 | 0 | extra_cfg.force_video_mode = arg_parse_uint_helper(&arg, err_string); |
4176 | 0 | } else if (arg_match_helper(&arg, &g_av1_codec_arg_defs.enable_obmc, argv, |
4177 | 0 | err_string)) { |
4178 | 0 | extra_cfg.enable_obmc = arg_parse_uint_helper(&arg, err_string); |
4179 | 0 | } else if (arg_match_helper(&arg, &g_av1_codec_arg_defs.disable_trellis_quant, |
4180 | 0 | argv, err_string)) { |
4181 | 0 | extra_cfg.disable_trellis_quant = arg_parse_uint_helper(&arg, err_string); |
4182 | 0 | } else if (arg_match_helper(&arg, &g_av1_codec_arg_defs.enable_qm, argv, |
4183 | 0 | err_string)) { |
4184 | 0 | extra_cfg.enable_qm = arg_parse_uint_helper(&arg, err_string); |
4185 | 0 | } else if (arg_match_helper(&arg, &g_av1_codec_arg_defs.qm_max, argv, |
4186 | 0 | err_string)) { |
4187 | 0 | extra_cfg.qm_max = arg_parse_uint_helper(&arg, err_string); |
4188 | 0 | } else if (arg_match_helper(&arg, &g_av1_codec_arg_defs.qm_min, argv, |
4189 | 0 | err_string)) { |
4190 | 0 | extra_cfg.qm_min = arg_parse_uint_helper(&arg, err_string); |
4191 | 0 | } else if (arg_match_helper(&arg, &g_av1_codec_arg_defs.num_tg, argv, |
4192 | 0 | err_string)) { |
4193 | 0 | extra_cfg.num_tg = arg_parse_uint_helper(&arg, err_string); |
4194 | 0 | } else if (arg_match_helper(&arg, &g_av1_codec_arg_defs.mtu_size, argv, |
4195 | 0 | err_string)) { |
4196 | 0 | extra_cfg.mtu_size = arg_parse_uint_helper(&arg, err_string); |
4197 | 0 | } else if (arg_match_helper(&arg, &g_av1_codec_arg_defs.timing_info, argv, |
4198 | 0 | err_string)) { |
4199 | 0 | extra_cfg.timing_info_type = arg_parse_enum_helper(&arg, err_string); |
4200 | 0 | } else if (arg_match_helper(&arg, |
4201 | 0 | &g_av1_codec_arg_defs.frame_parallel_decoding, |
4202 | 0 | argv, err_string)) { |
4203 | 0 | extra_cfg.frame_parallel_decoding_mode = |
4204 | 0 | arg_parse_uint_helper(&arg, err_string); |
4205 | 0 | } else if (arg_match_helper(&arg, &g_av1_codec_arg_defs.enable_dual_filter, |
4206 | 0 | argv, err_string)) { |
4207 | 0 | extra_cfg.enable_dual_filter = arg_parse_uint_helper(&arg, err_string); |
4208 | 0 | } else if (arg_match_helper(&arg, &g_av1_codec_arg_defs.enable_chroma_deltaq, |
4209 | 0 | argv, err_string)) { |
4210 | 0 | extra_cfg.enable_chroma_deltaq = arg_parse_uint_helper(&arg, err_string); |
4211 | 0 | } else if (arg_match_helper(&arg, &g_av1_codec_arg_defs.aq_mode, argv, |
4212 | 0 | err_string)) { |
4213 | 0 | extra_cfg.aq_mode = arg_parse_uint_helper(&arg, err_string); |
4214 | 0 | } else if (arg_match_helper(&arg, &g_av1_codec_arg_defs.deltaq_mode, argv, |
4215 | 0 | err_string)) { |
4216 | 0 | extra_cfg.deltaq_mode = arg_parse_uint_helper(&arg, err_string); |
4217 | 0 | } else if (arg_match_helper(&arg, &g_av1_codec_arg_defs.deltaq_strength, argv, |
4218 | 0 | err_string)) { |
4219 | 0 | extra_cfg.deltaq_strength = arg_parse_uint_helper(&arg, err_string); |
4220 | 0 | } else if (arg_match_helper(&arg, &g_av1_codec_arg_defs.deltalf_mode, argv, |
4221 | 0 | err_string)) { |
4222 | 0 | extra_cfg.deltalf_mode = arg_parse_uint_helper(&arg, err_string); |
4223 | 0 | } else if (arg_match_helper(&arg, &g_av1_codec_arg_defs.frame_periodic_boost, |
4224 | 0 | argv, err_string)) { |
4225 | 0 | extra_cfg.frame_periodic_boost = arg_parse_uint_helper(&arg, err_string); |
4226 | 0 | } else if (arg_match_helper(&arg, &g_av1_codec_arg_defs.tune_content, argv, |
4227 | 0 | err_string)) { |
4228 | 0 | extra_cfg.content = arg_parse_enum_helper(&arg, err_string); |
4229 | 0 | } else if (arg_match_helper(&arg, &g_av1_codec_arg_defs.input_color_primaries, |
4230 | 0 | argv, err_string)) { |
4231 | 0 | extra_cfg.color_primaries = arg_parse_enum_helper(&arg, err_string); |
4232 | 0 | } else if (arg_match_helper( |
4233 | 0 | &arg, &g_av1_codec_arg_defs.input_transfer_characteristics, |
4234 | 0 | argv, err_string)) { |
4235 | 0 | extra_cfg.transfer_characteristics = |
4236 | 0 | arg_parse_enum_helper(&arg, err_string); |
4237 | 0 | } else if (arg_match_helper(&arg, |
4238 | 0 | &g_av1_codec_arg_defs.input_matrix_coefficients, |
4239 | 0 | argv, err_string)) { |
4240 | 0 | extra_cfg.matrix_coefficients = arg_parse_enum_helper(&arg, err_string); |
4241 | 0 | } else if (arg_match_helper( |
4242 | 0 | &arg, &g_av1_codec_arg_defs.input_chroma_sample_position, argv, |
4243 | 0 | err_string)) { |
4244 | 0 | extra_cfg.chroma_sample_position = arg_parse_enum_helper(&arg, err_string); |
4245 | 0 | } else if (arg_match_helper(&arg, &g_av1_codec_arg_defs.superblock_size, argv, |
4246 | 0 | err_string)) { |
4247 | 0 | extra_cfg.superblock_size = arg_parse_enum_helper(&arg, err_string); |
4248 | 0 | } else if (arg_match_helper(&arg, &g_av1_codec_arg_defs.error_resilient_mode, |
4249 | 0 | argv, err_string)) { |
4250 | 0 | extra_cfg.error_resilient_mode = arg_parse_int_helper(&arg, err_string); |
4251 | 0 | } else if (arg_match_helper(&arg, &g_av1_codec_arg_defs.sframe_mode, argv, |
4252 | 0 | err_string)) { |
4253 | 0 | extra_cfg.s_frame_mode = arg_parse_int_helper(&arg, err_string); |
4254 | 0 | } else if (arg_match_helper(&arg, &g_av1_codec_arg_defs.film_grain_test, argv, |
4255 | 0 | err_string)) { |
4256 | 0 | extra_cfg.film_grain_test_vector = arg_parse_int_helper(&arg, err_string); |
4257 | 0 | } else if (arg_match_helper(&arg, &g_av1_codec_arg_defs.film_grain_table, |
4258 | 0 | argv, err_string)) { |
4259 | 0 | if (value == NULL) { |
4260 | | // this parameter allows NULL as its value |
4261 | 0 | extra_cfg.film_grain_table_filename = value; |
4262 | 0 | } else { |
4263 | 0 | err = allocate_and_set_string( |
4264 | 0 | value, default_extra_cfg.film_grain_table_filename, |
4265 | 0 | &extra_cfg.film_grain_table_filename, err_string); |
4266 | 0 | } |
4267 | 0 | } else if (arg_match_helper(&arg, &g_av1_codec_arg_defs.cdf_update_mode, argv, |
4268 | 0 | err_string)) { |
4269 | 0 | extra_cfg.cdf_update_mode = arg_parse_int_helper(&arg, err_string); |
4270 | 0 | } else if (arg_match_helper(&arg, |
4271 | 0 | &g_av1_codec_arg_defs.enable_rect_partitions, |
4272 | 0 | argv, err_string)) { |
4273 | 0 | extra_cfg.enable_rect_partitions = arg_parse_int_helper(&arg, err_string); |
4274 | 0 | } else if (arg_match_helper(&arg, &g_av1_codec_arg_defs.enable_ab_partitions, |
4275 | 0 | argv, err_string)) { |
4276 | 0 | extra_cfg.enable_ab_partitions = arg_parse_int_helper(&arg, err_string); |
4277 | 0 | } else if (arg_match_helper(&arg, |
4278 | 0 | &g_av1_codec_arg_defs.enable_1to4_partitions, |
4279 | 0 | argv, err_string)) { |
4280 | 0 | extra_cfg.enable_1to4_partitions = arg_parse_int_helper(&arg, err_string); |
4281 | 0 | } else if (arg_match_helper(&arg, &g_av1_codec_arg_defs.min_partition_size, |
4282 | 0 | argv, err_string)) { |
4283 | 0 | extra_cfg.min_partition_size = arg_parse_int_helper(&arg, err_string); |
4284 | 0 | } else if (arg_match_helper(&arg, &g_av1_codec_arg_defs.max_partition_size, |
4285 | 0 | argv, err_string)) { |
4286 | 0 | extra_cfg.max_partition_size = arg_parse_int_helper(&arg, err_string); |
4287 | 0 | } else if (arg_match_helper(&arg, |
4288 | 0 | &g_av1_codec_arg_defs.enable_intra_edge_filter, |
4289 | 0 | argv, err_string)) { |
4290 | 0 | extra_cfg.enable_intra_edge_filter = |
4291 | 0 | arg_parse_uint_helper(&arg, err_string); |
4292 | 0 | } else if (arg_match_helper(&arg, &g_av1_codec_arg_defs.enable_order_hint, |
4293 | 0 | argv, err_string)) { |
4294 | 0 | extra_cfg.enable_order_hint = arg_parse_int_helper(&arg, err_string); |
4295 | 0 | } else if (arg_match_helper(&arg, &g_av1_codec_arg_defs.enable_tx64, argv, |
4296 | 0 | err_string)) { |
4297 | 0 | extra_cfg.enable_tx64 = arg_parse_int_helper(&arg, err_string); |
4298 | 0 | } else if (arg_match_helper(&arg, &g_av1_codec_arg_defs.enable_flip_idtx, |
4299 | 0 | argv, err_string)) { |
4300 | 0 | extra_cfg.enable_flip_idtx = arg_parse_int_helper(&arg, err_string); |
4301 | 0 | } else if (arg_match_helper(&arg, &g_av1_codec_arg_defs.enable_rect_tx, argv, |
4302 | 0 | err_string)) { |
4303 | 0 | extra_cfg.enable_rect_tx = arg_parse_int_helper(&arg, err_string); |
4304 | 0 | } else if (arg_match_helper(&arg, &g_av1_codec_arg_defs.enable_dist_wtd_comp, |
4305 | 0 | argv, err_string)) { |
4306 | 0 | extra_cfg.enable_dist_wtd_comp = arg_parse_int_helper(&arg, err_string); |
4307 | 0 | } else if (arg_match_helper(&arg, &g_av1_codec_arg_defs.max_reference_frames, |
4308 | 0 | argv, err_string)) { |
4309 | 0 | extra_cfg.max_reference_frames = arg_parse_int_helper(&arg, err_string); |
4310 | 0 | } else if (arg_match_helper(&arg, &g_av1_codec_arg_defs.reduced_reference_set, |
4311 | 0 | argv, err_string)) { |
4312 | 0 | extra_cfg.enable_reduced_reference_set = |
4313 | 0 | arg_parse_int_helper(&arg, err_string); |
4314 | 0 | } else if (arg_match_helper(&arg, &g_av1_codec_arg_defs.enable_ref_frame_mvs, |
4315 | 0 | argv, err_string)) { |
4316 | 0 | extra_cfg.enable_ref_frame_mvs = arg_parse_int_helper(&arg, err_string); |
4317 | 0 | } else if (arg_match_helper(&arg, &g_av1_codec_arg_defs.enable_masked_comp, |
4318 | 0 | argv, err_string)) { |
4319 | 0 | extra_cfg.enable_masked_comp = arg_parse_int_helper(&arg, err_string); |
4320 | 0 | } else if (arg_match_helper(&arg, &g_av1_codec_arg_defs.enable_onesided_comp, |
4321 | 0 | argv, err_string)) { |
4322 | 0 | extra_cfg.enable_onesided_comp = arg_parse_int_helper(&arg, err_string); |
4323 | 0 | } else if (arg_match_helper(&arg, |
4324 | 0 | &g_av1_codec_arg_defs.enable_interintra_comp, |
4325 | 0 | argv, err_string)) { |
4326 | 0 | extra_cfg.enable_interintra_comp = arg_parse_int_helper(&arg, err_string); |
4327 | 0 | } else if (arg_match_helper(&arg, |
4328 | 0 | &g_av1_codec_arg_defs.enable_smooth_interintra, |
4329 | 0 | argv, err_string)) { |
4330 | 0 | extra_cfg.enable_smooth_interintra = arg_parse_int_helper(&arg, err_string); |
4331 | 0 | } else if (arg_match_helper(&arg, &g_av1_codec_arg_defs.enable_diff_wtd_comp, |
4332 | 0 | argv, err_string)) { |
4333 | 0 | extra_cfg.enable_diff_wtd_comp = arg_parse_int_helper(&arg, err_string); |
4334 | 0 | } else if (arg_match_helper(&arg, |
4335 | 0 | &g_av1_codec_arg_defs.enable_interinter_wedge, |
4336 | 0 | argv, err_string)) { |
4337 | 0 | extra_cfg.enable_interinter_wedge = arg_parse_int_helper(&arg, err_string); |
4338 | 0 | } else if (arg_match_helper(&arg, |
4339 | 0 | &g_av1_codec_arg_defs.enable_interintra_wedge, |
4340 | 0 | argv, err_string)) { |
4341 | 0 | extra_cfg.enable_interintra_wedge = arg_parse_int_helper(&arg, err_string); |
4342 | 0 | } else if (arg_match_helper(&arg, &g_av1_codec_arg_defs.enable_global_motion, |
4343 | 0 | argv, err_string)) { |
4344 | 0 | extra_cfg.enable_global_motion = arg_parse_int_helper(&arg, err_string); |
4345 | 0 | } else if (arg_match_helper(&arg, &g_av1_codec_arg_defs.enable_warped_motion, |
4346 | 0 | argv, err_string)) { |
4347 | 0 | extra_cfg.enable_warped_motion = arg_parse_int_helper(&arg, err_string); |
4348 | 0 | } else if (arg_match_helper(&arg, &g_av1_codec_arg_defs.enable_filter_intra, |
4349 | 0 | argv, err_string)) { |
4350 | 0 | extra_cfg.enable_filter_intra = arg_parse_int_helper(&arg, err_string); |
4351 | 0 | } else if (arg_match_helper(&arg, &g_av1_codec_arg_defs.enable_smooth_intra, |
4352 | 0 | argv, err_string)) { |
4353 | 0 | extra_cfg.enable_smooth_intra = arg_parse_int_helper(&arg, err_string); |
4354 | 0 | } else if (arg_match_helper(&arg, &g_av1_codec_arg_defs.enable_paeth_intra, |
4355 | 0 | argv, err_string)) { |
4356 | 0 | extra_cfg.enable_paeth_intra = arg_parse_int_helper(&arg, err_string); |
4357 | 0 | } else if (arg_match_helper(&arg, &g_av1_codec_arg_defs.enable_cfl_intra, |
4358 | 0 | argv, err_string)) { |
4359 | 0 | extra_cfg.enable_cfl_intra = arg_parse_int_helper(&arg, err_string); |
4360 | 0 | } else if (arg_match_helper(&arg, |
4361 | 0 | &g_av1_codec_arg_defs.enable_directional_intra, |
4362 | 0 | argv, err_string)) { |
4363 | 0 | extra_cfg.enable_directional_intra = arg_parse_int_helper(&arg, err_string); |
4364 | 0 | } else if (arg_match_helper(&arg, &g_av1_codec_arg_defs.enable_diagonal_intra, |
4365 | 0 | argv, err_string)) { |
4366 | 0 | extra_cfg.enable_diagonal_intra = arg_parse_int_helper(&arg, err_string); |
4367 | 0 | } else if (arg_match_helper(&arg, &g_av1_codec_arg_defs.enable_overlay, argv, |
4368 | 0 | err_string)) { |
4369 | 0 | extra_cfg.enable_overlay = arg_parse_int_helper(&arg, err_string); |
4370 | 0 | } else if (arg_match_helper(&arg, &g_av1_codec_arg_defs.enable_palette, argv, |
4371 | 0 | err_string)) { |
4372 | 0 | extra_cfg.enable_palette = arg_parse_int_helper(&arg, err_string); |
4373 | 0 | } else if (arg_match_helper(&arg, &g_av1_codec_arg_defs.enable_intrabc, argv, |
4374 | 0 | err_string)) { |
4375 | 0 | extra_cfg.enable_intrabc = arg_parse_int_helper(&arg, err_string); |
4376 | 0 | } else if (arg_match_helper(&arg, &g_av1_codec_arg_defs.enable_angle_delta, |
4377 | 0 | argv, err_string)) { |
4378 | 0 | extra_cfg.enable_angle_delta = arg_parse_int_helper(&arg, err_string); |
4379 | 0 | } else if (arg_match_helper(&arg, &g_av1_codec_arg_defs.reduced_tx_type_set, |
4380 | 0 | argv, err_string)) { |
4381 | 0 | extra_cfg.reduced_tx_type_set = arg_parse_int_helper(&arg, err_string); |
4382 | 0 | } else if (arg_match_helper(&arg, &g_av1_codec_arg_defs.use_intra_dct_only, |
4383 | 0 | argv, err_string)) { |
4384 | 0 | extra_cfg.use_intra_dct_only = arg_parse_int_helper(&arg, err_string); |
4385 | 0 | } else if (arg_match_helper(&arg, &g_av1_codec_arg_defs.use_inter_dct_only, |
4386 | 0 | argv, err_string)) { |
4387 | 0 | extra_cfg.use_inter_dct_only = arg_parse_int_helper(&arg, err_string); |
4388 | 0 | } else if (arg_match_helper(&arg, |
4389 | 0 | &g_av1_codec_arg_defs.use_intra_default_tx_only, |
4390 | 0 | argv, err_string)) { |
4391 | 0 | extra_cfg.use_intra_default_tx_only = |
4392 | 0 | arg_parse_int_helper(&arg, err_string); |
4393 | 0 | } else if (arg_match_helper(&arg, &g_av1_codec_arg_defs.quant_b_adapt, argv, |
4394 | 0 | err_string)) { |
4395 | 0 | extra_cfg.quant_b_adapt = arg_parse_int_helper(&arg, err_string); |
4396 | 0 | } else if (arg_match_helper(&arg, |
4397 | 0 | &g_av1_codec_arg_defs.vbr_corpus_complexity_lap, |
4398 | 0 | argv, err_string)) { |
4399 | 0 | extra_cfg.vbr_corpus_complexity_lap = |
4400 | 0 | arg_parse_uint_helper(&arg, err_string); |
4401 | 0 | } else if (arg_match_helper(&arg, &g_av1_codec_arg_defs.set_tier_mask, argv, |
4402 | 0 | err_string)) { |
4403 | 0 | extra_cfg.tier_mask = arg_parse_uint_helper(&arg, err_string); |
4404 | 0 | } else if (arg_match_helper(&arg, &g_av1_codec_arg_defs.set_min_cr, argv, |
4405 | 0 | err_string)) { |
4406 | 0 | extra_cfg.min_cr = arg_parse_uint_helper(&arg, err_string); |
4407 | 0 | } else if (arg_match_helper(&arg, &g_av1_codec_arg_defs.coeff_cost_upd_freq, |
4408 | 0 | argv, err_string)) { |
4409 | 0 | extra_cfg.coeff_cost_upd_freq = arg_parse_uint_helper(&arg, err_string); |
4410 | 0 | } else if (arg_match_helper(&arg, &g_av1_codec_arg_defs.mode_cost_upd_freq, |
4411 | 0 | argv, err_string)) { |
4412 | 0 | extra_cfg.mode_cost_upd_freq = arg_parse_uint_helper(&arg, err_string); |
4413 | 0 | } else if (arg_match_helper(&arg, &g_av1_codec_arg_defs.mv_cost_upd_freq, |
4414 | 0 | argv, err_string)) { |
4415 | 0 | extra_cfg.mv_cost_upd_freq = arg_parse_uint_helper(&arg, err_string); |
4416 | 0 | } else if (arg_match_helper(&arg, &g_av1_codec_arg_defs.dv_cost_upd_freq, |
4417 | 0 | argv, err_string)) { |
4418 | 0 | extra_cfg.dv_cost_upd_freq = arg_parse_uint_helper(&arg, err_string); |
4419 | 0 | } |
4420 | 0 | #if CONFIG_DENOISE |
4421 | 0 | else if (arg_match_helper(&arg, &g_av1_codec_arg_defs.denoise_noise_level, |
4422 | 0 | argv, err_string)) { |
4423 | 0 | extra_cfg.noise_level = |
4424 | 0 | (float)arg_parse_int_helper(&arg, err_string) / 10.0f; |
4425 | 0 | } else if (arg_match_helper(&arg, &g_av1_codec_arg_defs.denoise_block_size, |
4426 | 0 | argv, err_string)) { |
4427 | 0 | extra_cfg.noise_block_size = arg_parse_uint_helper(&arg, err_string); |
4428 | 0 | } else if (arg_match_helper(&arg, &g_av1_codec_arg_defs.enable_dnl_denoising, |
4429 | 0 | argv, err_string)) { |
4430 | 0 | extra_cfg.enable_dnl_denoising = arg_parse_uint_helper(&arg, err_string); |
4431 | 0 | } |
4432 | 0 | #endif |
4433 | 0 | else if (arg_match_helper(&arg, &g_av1_codec_arg_defs.target_seq_level_idx, |
4434 | 0 | argv, err_string)) { |
4435 | 0 | const int val = arg_parse_int_helper(&arg, err_string); |
4436 | 0 | const int level = val % 100; |
4437 | 0 | const int operating_point_idx = val / 100; |
4438 | 0 | if (operating_point_idx < 0 || |
4439 | 0 | operating_point_idx >= MAX_NUM_OPERATING_POINTS) { |
4440 | 0 | snprintf(err_string, ARG_ERR_MSG_MAX_LEN, |
4441 | 0 | "Invalid operating point index: %d", operating_point_idx); |
4442 | 0 | err = AOM_CODEC_INVALID_PARAM; |
4443 | 0 | } else { |
4444 | 0 | extra_cfg.target_seq_level_idx[operating_point_idx] = (AV1_LEVEL)level; |
4445 | 0 | } |
4446 | 0 | } else if (arg_match_helper(&arg, |
4447 | 0 | &g_av1_codec_arg_defs.input_chroma_subsampling_x, |
4448 | 0 | argv, err_string)) { |
4449 | 0 | extra_cfg.chroma_subsampling_x = arg_parse_uint_helper(&arg, err_string); |
4450 | 0 | } else if (arg_match_helper(&arg, |
4451 | 0 | &g_av1_codec_arg_defs.input_chroma_subsampling_y, |
4452 | 0 | argv, err_string)) { |
4453 | 0 | extra_cfg.chroma_subsampling_y = arg_parse_uint_helper(&arg, err_string); |
4454 | 0 | } else if (arg_match_helper(&arg, &g_av1_codec_arg_defs.passes, argv, |
4455 | 0 | err_string)) { |
4456 | 0 | extra_cfg.passes = arg_parse_int_helper(&arg, err_string); |
4457 | 0 | } else if (arg_match_helper(&arg, &g_av1_codec_arg_defs.fwd_kf_dist, argv, |
4458 | 0 | err_string)) { |
4459 | 0 | extra_cfg.fwd_kf_dist = arg_parse_int_helper(&arg, err_string); |
4460 | 0 | } else if (arg_match_helper(&arg, &g_av1_codec_arg_defs.two_pass_output, argv, |
4461 | 0 | err_string)) { |
4462 | 0 | err = allocate_and_set_string(value, default_extra_cfg.two_pass_output, |
4463 | 0 | &extra_cfg.two_pass_output, err_string); |
4464 | 0 | } else if (arg_match_helper(&arg, &g_av1_codec_arg_defs.second_pass_log, argv, |
4465 | 0 | err_string)) { |
4466 | 0 | err = allocate_and_set_string(value, default_extra_cfg.second_pass_log, |
4467 | 0 | &extra_cfg.second_pass_log, err_string); |
4468 | 0 | } else if (arg_match_helper(&arg, &g_av1_codec_arg_defs.loopfilter_control, |
4469 | 0 | argv, err_string)) { |
4470 | 0 | extra_cfg.loopfilter_control = arg_parse_int_helper(&arg, err_string); |
4471 | 0 | } else if (arg_match_helper(&arg, &g_av1_codec_arg_defs.auto_intra_tools_off, |
4472 | 0 | argv, err_string)) { |
4473 | 0 | extra_cfg.auto_intra_tools_off = arg_parse_uint_helper(&arg, err_string); |
4474 | 0 | } else if (arg_match_helper(&arg, |
4475 | 0 | &g_av1_codec_arg_defs.strict_level_conformance, |
4476 | 0 | argv, err_string)) { |
4477 | 0 | extra_cfg.strict_level_conformance = arg_parse_int_helper(&arg, err_string); |
4478 | 0 | } else if (arg_match_helper(&arg, &g_av1_codec_arg_defs.sb_qp_sweep, argv, |
4479 | 0 | err_string)) { |
4480 | 0 | extra_cfg.sb_qp_sweep = arg_parse_int_helper(&arg, err_string); |
4481 | 0 | } else if (arg_match_helper(&arg, &g_av1_codec_arg_defs.kf_max_pyr_height, |
4482 | 0 | argv, err_string)) { |
4483 | 0 | extra_cfg.kf_max_pyr_height = arg_parse_int_helper(&arg, err_string); |
4484 | 0 | } else if (arg_match_helper(&arg, &g_av1_codec_arg_defs.tile_width, argv, |
4485 | 0 | err_string)) { |
4486 | 0 | ctx->cfg.tile_width_count = arg_parse_list_helper( |
4487 | 0 | &arg, ctx->cfg.tile_widths, MAX_TILE_WIDTHS, err_string); |
4488 | 0 | } else if (arg_match_helper(&arg, &g_av1_codec_arg_defs.tile_height, argv, |
4489 | 0 | err_string)) { |
4490 | 0 | ctx->cfg.tile_height_count = arg_parse_list_helper( |
4491 | 0 | &arg, ctx->cfg.tile_heights, MAX_TILE_HEIGHTS, err_string); |
4492 | 0 | } else { |
4493 | 0 | match = 0; |
4494 | 0 | snprintf(err_string, ARG_ERR_MSG_MAX_LEN, "Cannot find aom option %s", |
4495 | 0 | name); |
4496 | 0 | } |
4497 | 0 | aom_free(argv[0]); |
4498 | |
|
4499 | 0 | if (err != AOM_CODEC_OK) { |
4500 | 0 | ctx->base.err_detail = err_string; |
4501 | 0 | return err; |
4502 | 0 | } |
4503 | | |
4504 | 0 | if (strlen(err_string) != 0) { |
4505 | 0 | ctx->base.err_detail = err_string; |
4506 | 0 | return AOM_CODEC_INVALID_PARAM; |
4507 | 0 | } |
4508 | | |
4509 | 0 | ctx->base.err_detail = NULL; |
4510 | |
|
4511 | 0 | if (!match) { |
4512 | 0 | return AOM_CODEC_INVALID_PARAM; |
4513 | 0 | } |
4514 | 0 | return update_extra_cfg(ctx, &extra_cfg); |
4515 | 0 | } |
4516 | | |
4517 | | static aom_codec_err_t ctrl_get_seq_level_idx(aom_codec_alg_priv_t *ctx, |
4518 | 0 | va_list args) { |
4519 | 0 | int *const arg = va_arg(args, int *); |
4520 | 0 | if (arg == NULL) return AOM_CODEC_INVALID_PARAM; |
4521 | 0 | return av1_get_seq_level_idx(&ctx->ppi->seq_params, &ctx->ppi->level_params, |
4522 | 0 | arg); |
4523 | 0 | } |
4524 | | |
4525 | | static aom_codec_err_t ctrl_get_target_seq_level_idx(aom_codec_alg_priv_t *ctx, |
4526 | 0 | va_list args) { |
4527 | 0 | int *const arg = va_arg(args, int *); |
4528 | 0 | if (arg == NULL) return AOM_CODEC_INVALID_PARAM; |
4529 | 0 | return av1_get_target_seq_level_idx(&ctx->ppi->seq_params, |
4530 | 0 | &ctx->ppi->level_params, arg); |
4531 | 0 | } |
4532 | | |
4533 | | static aom_codec_err_t ctrl_get_num_operating_points(aom_codec_alg_priv_t *ctx, |
4534 | 0 | va_list args) { |
4535 | 0 | int *const arg = va_arg(args, int *); |
4536 | 0 | if (arg == NULL) return AOM_CODEC_INVALID_PARAM; |
4537 | 0 | *arg = ctx->ppi->seq_params.operating_points_cnt_minus_1 + 1; |
4538 | 0 | return AOM_CODEC_OK; |
4539 | 0 | } |
4540 | | |
4541 | | static aom_codec_err_t ctrl_get_luma_cdef_strength(aom_codec_alg_priv_t *ctx, |
4542 | 0 | va_list args) { |
4543 | 0 | int *arg = va_arg(args, int *); |
4544 | 0 | AV1_COMMON const *cm = &ctx->ppi->cpi->common; |
4545 | 0 | if (arg == NULL) return AOM_CODEC_INVALID_PARAM; |
4546 | 0 | memcpy(arg, cm->cdef_info.cdef_strengths, CDEF_MAX_STRENGTHS * sizeof(*arg)); |
4547 | |
|
4548 | 0 | return AOM_CODEC_OK; |
4549 | 0 | } |
4550 | | |
4551 | | static aom_codec_err_t ctrl_get_high_motion_content_screen_rtc( |
4552 | 0 | aom_codec_alg_priv_t *ctx, va_list args) { |
4553 | 0 | int *arg = va_arg(args, int *); |
4554 | 0 | AV1_COMP *const cpi = ctx->ppi->cpi; |
4555 | 0 | if (arg == NULL) return AOM_CODEC_INVALID_PARAM; |
4556 | 0 | *arg = cpi->rc.high_motion_content_screen_rtc; |
4557 | 0 | return AOM_CODEC_OK; |
4558 | 0 | } |
4559 | | |
4560 | | static aom_codec_ctrl_fn_map_t encoder_ctrl_maps[] = { |
4561 | | { AV1_COPY_REFERENCE, ctrl_copy_reference }, |
4562 | | { AOME_USE_REFERENCE, ctrl_use_reference }, |
4563 | | |
4564 | | // Setters |
4565 | | { AV1_SET_REFERENCE, ctrl_set_reference }, |
4566 | | { AOME_SET_ROI_MAP, ctrl_set_roi_map }, |
4567 | | { AOME_SET_ACTIVEMAP, ctrl_set_active_map }, |
4568 | | { AOME_SET_SCALEMODE, ctrl_set_scale_mode }, |
4569 | | { AOME_SET_SPATIAL_LAYER_ID, ctrl_set_spatial_layer_id }, |
4570 | | { AOME_SET_CPUUSED, ctrl_set_cpuused }, |
4571 | | { AOME_SET_ENABLEAUTOALTREF, ctrl_set_enable_auto_alt_ref }, |
4572 | | { AOME_SET_ENABLEAUTOBWDREF, ctrl_set_enable_auto_bwd_ref }, |
4573 | | { AOME_SET_SHARPNESS, ctrl_set_sharpness }, |
4574 | | { AOME_SET_STATIC_THRESHOLD, ctrl_set_static_thresh }, |
4575 | | { AV1E_SET_ROW_MT, ctrl_set_row_mt }, |
4576 | | { AV1E_SET_FP_MT, ctrl_set_fp_mt }, |
4577 | | { AV1E_SET_TILE_COLUMNS, ctrl_set_tile_columns }, |
4578 | | { AV1E_SET_TILE_ROWS, ctrl_set_tile_rows }, |
4579 | | { AV1E_SET_ENABLE_TPL_MODEL, ctrl_set_enable_tpl_model }, |
4580 | | { AV1E_SET_ENABLE_KEYFRAME_FILTERING, ctrl_set_enable_keyframe_filtering }, |
4581 | | { AOME_SET_ARNR_MAXFRAMES, ctrl_set_arnr_max_frames }, |
4582 | | { AOME_SET_ARNR_STRENGTH, ctrl_set_arnr_strength }, |
4583 | | { AOME_SET_TUNING, ctrl_set_tuning }, |
4584 | | { AOME_SET_CQ_LEVEL, ctrl_set_cq_level }, |
4585 | | { AOME_SET_MAX_INTRA_BITRATE_PCT, ctrl_set_rc_max_intra_bitrate_pct }, |
4586 | | { AOME_SET_NUMBER_SPATIAL_LAYERS, ctrl_set_number_spatial_layers }, |
4587 | | { AV1E_SET_MAX_INTER_BITRATE_PCT, ctrl_set_rc_max_inter_bitrate_pct }, |
4588 | | { AV1E_SET_GF_CBR_BOOST_PCT, ctrl_set_rc_gf_cbr_boost_pct }, |
4589 | | { AV1E_SET_LOSSLESS, ctrl_set_lossless }, |
4590 | | { AV1E_SET_ENABLE_CDEF, ctrl_set_enable_cdef }, |
4591 | | { AV1E_SET_ENABLE_RESTORATION, ctrl_set_enable_restoration }, |
4592 | | { AV1E_SET_FORCE_VIDEO_MODE, ctrl_set_force_video_mode }, |
4593 | | { AV1E_SET_ENABLE_OBMC, ctrl_set_enable_obmc }, |
4594 | | { AV1E_SET_DISABLE_TRELLIS_QUANT, ctrl_set_disable_trellis_quant }, |
4595 | | { AV1E_SET_ENABLE_QM, ctrl_set_enable_qm }, |
4596 | | { AV1E_SET_QM_Y, ctrl_set_qm_y }, |
4597 | | { AV1E_SET_QM_U, ctrl_set_qm_u }, |
4598 | | { AV1E_SET_QM_V, ctrl_set_qm_v }, |
4599 | | { AV1E_SET_QM_MIN, ctrl_set_qm_min }, |
4600 | | { AV1E_SET_QM_MAX, ctrl_set_qm_max }, |
4601 | | { AV1E_SET_NUM_TG, ctrl_set_num_tg }, |
4602 | | { AV1E_SET_MTU, ctrl_set_mtu }, |
4603 | | { AV1E_SET_TIMING_INFO_TYPE, ctrl_set_timing_info_type }, |
4604 | | { AV1E_SET_FRAME_PARALLEL_DECODING, ctrl_set_frame_parallel_decoding_mode }, |
4605 | | { AV1E_SET_ERROR_RESILIENT_MODE, ctrl_set_error_resilient_mode }, |
4606 | | { AV1E_SET_S_FRAME_MODE, ctrl_set_s_frame_mode }, |
4607 | | { AV1E_SET_ENABLE_RECT_PARTITIONS, ctrl_set_enable_rect_partitions }, |
4608 | | { AV1E_SET_ENABLE_AB_PARTITIONS, ctrl_set_enable_ab_partitions }, |
4609 | | { AV1E_SET_ENABLE_1TO4_PARTITIONS, ctrl_set_enable_1to4_partitions }, |
4610 | | { AV1E_SET_MIN_PARTITION_SIZE, ctrl_set_min_partition_size }, |
4611 | | { AV1E_SET_MAX_PARTITION_SIZE, ctrl_set_max_partition_size }, |
4612 | | { AV1E_SET_ENABLE_DUAL_FILTER, ctrl_set_enable_dual_filter }, |
4613 | | { AV1E_SET_ENABLE_CHROMA_DELTAQ, ctrl_set_enable_chroma_deltaq }, |
4614 | | { AV1E_SET_ENABLE_INTRA_EDGE_FILTER, ctrl_set_enable_intra_edge_filter }, |
4615 | | { AV1E_SET_ENABLE_ORDER_HINT, ctrl_set_enable_order_hint }, |
4616 | | { AV1E_SET_ENABLE_TX64, ctrl_set_enable_tx64 }, |
4617 | | { AV1E_SET_ENABLE_FLIP_IDTX, ctrl_set_enable_flip_idtx }, |
4618 | | { AV1E_SET_ENABLE_RECT_TX, ctrl_set_enable_rect_tx }, |
4619 | | { AV1E_SET_ENABLE_DIST_WTD_COMP, ctrl_set_enable_dist_wtd_comp }, |
4620 | | { AV1E_SET_MAX_REFERENCE_FRAMES, ctrl_set_max_reference_frames }, |
4621 | | { AV1E_SET_REDUCED_REFERENCE_SET, ctrl_set_enable_reduced_reference_set }, |
4622 | | { AV1E_SET_ENABLE_REF_FRAME_MVS, ctrl_set_enable_ref_frame_mvs }, |
4623 | | { AV1E_SET_ALLOW_REF_FRAME_MVS, ctrl_set_allow_ref_frame_mvs }, |
4624 | | { AV1E_SET_ENABLE_MASKED_COMP, ctrl_set_enable_masked_comp }, |
4625 | | { AV1E_SET_ENABLE_ONESIDED_COMP, ctrl_set_enable_onesided_comp }, |
4626 | | { AV1E_SET_ENABLE_INTERINTRA_COMP, ctrl_set_enable_interintra_comp }, |
4627 | | { AV1E_SET_ENABLE_SMOOTH_INTERINTRA, ctrl_set_enable_smooth_interintra }, |
4628 | | { AV1E_SET_ENABLE_DIFF_WTD_COMP, ctrl_set_enable_diff_wtd_comp }, |
4629 | | { AV1E_SET_ENABLE_INTERINTER_WEDGE, ctrl_set_enable_interinter_wedge }, |
4630 | | { AV1E_SET_ENABLE_INTERINTRA_WEDGE, ctrl_set_enable_interintra_wedge }, |
4631 | | { AV1E_SET_ENABLE_GLOBAL_MOTION, ctrl_set_enable_global_motion }, |
4632 | | { AV1E_SET_ENABLE_WARPED_MOTION, ctrl_set_enable_warped_motion }, |
4633 | | { AV1E_SET_ALLOW_WARPED_MOTION, ctrl_set_allow_warped_motion }, |
4634 | | { AV1E_SET_ENABLE_FILTER_INTRA, ctrl_set_enable_filter_intra }, |
4635 | | { AV1E_SET_ENABLE_SMOOTH_INTRA, ctrl_set_enable_smooth_intra }, |
4636 | | { AV1E_SET_ENABLE_PAETH_INTRA, ctrl_set_enable_paeth_intra }, |
4637 | | { AV1E_SET_ENABLE_CFL_INTRA, ctrl_set_enable_cfl_intra }, |
4638 | | { AV1E_SET_ENABLE_DIRECTIONAL_INTRA, ctrl_set_enable_directional_intra }, |
4639 | | { AV1E_SET_ENABLE_DIAGONAL_INTRA, ctrl_set_enable_diagonal_intra }, |
4640 | | { AV1E_SET_ENABLE_SUPERRES, ctrl_set_enable_superres }, |
4641 | | { AV1E_SET_ENABLE_OVERLAY, ctrl_set_enable_overlay }, |
4642 | | { AV1E_SET_ENABLE_PALETTE, ctrl_set_enable_palette }, |
4643 | | { AV1E_SET_ENABLE_INTRABC, ctrl_set_enable_intrabc }, |
4644 | | { AV1E_SET_ENABLE_ANGLE_DELTA, ctrl_set_enable_angle_delta }, |
4645 | | { AV1E_SET_AQ_MODE, ctrl_set_aq_mode }, |
4646 | | { AV1E_SET_REDUCED_TX_TYPE_SET, ctrl_set_reduced_tx_type_set }, |
4647 | | { AV1E_SET_INTRA_DCT_ONLY, ctrl_set_intra_dct_only }, |
4648 | | { AV1E_SET_INTER_DCT_ONLY, ctrl_set_inter_dct_only }, |
4649 | | { AV1E_SET_INTRA_DEFAULT_TX_ONLY, ctrl_set_intra_default_tx_only }, |
4650 | | { AV1E_SET_QUANT_B_ADAPT, ctrl_set_quant_b_adapt }, |
4651 | | { AV1E_SET_COEFF_COST_UPD_FREQ, ctrl_set_coeff_cost_upd_freq }, |
4652 | | { AV1E_SET_MODE_COST_UPD_FREQ, ctrl_set_mode_cost_upd_freq }, |
4653 | | { AV1E_SET_MV_COST_UPD_FREQ, ctrl_set_mv_cost_upd_freq }, |
4654 | | { AV1E_SET_DELTAQ_MODE, ctrl_set_deltaq_mode }, |
4655 | | { AV1E_SET_DELTAQ_STRENGTH, ctrl_set_deltaq_strength }, |
4656 | | { AV1E_SET_DELTALF_MODE, ctrl_set_deltalf_mode }, |
4657 | | { AV1E_SET_FRAME_PERIODIC_BOOST, ctrl_set_frame_periodic_boost }, |
4658 | | { AV1E_SET_TUNE_CONTENT, ctrl_set_tune_content }, |
4659 | | { AV1E_SET_CDF_UPDATE_MODE, ctrl_set_cdf_update_mode }, |
4660 | | { AV1E_SET_COLOR_PRIMARIES, ctrl_set_color_primaries }, |
4661 | | { AV1E_SET_TRANSFER_CHARACTERISTICS, ctrl_set_transfer_characteristics }, |
4662 | | { AV1E_SET_MATRIX_COEFFICIENTS, ctrl_set_matrix_coefficients }, |
4663 | | { AV1E_SET_CHROMA_SAMPLE_POSITION, ctrl_set_chroma_sample_position }, |
4664 | | { AV1E_SET_COLOR_RANGE, ctrl_set_color_range }, |
4665 | | { AV1E_SET_NOISE_SENSITIVITY, ctrl_set_noise_sensitivity }, |
4666 | | { AV1E_SET_MIN_GF_INTERVAL, ctrl_set_min_gf_interval }, |
4667 | | { AV1E_SET_MAX_GF_INTERVAL, ctrl_set_max_gf_interval }, |
4668 | | { AV1E_SET_GF_MIN_PYRAMID_HEIGHT, ctrl_set_gf_min_pyr_height }, |
4669 | | { AV1E_SET_GF_MAX_PYRAMID_HEIGHT, ctrl_set_gf_max_pyr_height }, |
4670 | | { AV1E_SET_RENDER_SIZE, ctrl_set_render_size }, |
4671 | | { AV1E_SET_SUPERBLOCK_SIZE, ctrl_set_superblock_size }, |
4672 | | { AV1E_SET_SINGLE_TILE_DECODING, ctrl_set_single_tile_decoding }, |
4673 | | { AV1E_SET_VMAF_MODEL_PATH, ctrl_set_vmaf_model_path }, |
4674 | | { AV1E_SET_PARTITION_INFO_PATH, ctrl_set_partition_info_path }, |
4675 | | { AV1E_ENABLE_RATE_GUIDE_DELTAQ, ctrl_enable_rate_guide_deltaq }, |
4676 | | { AV1E_SET_RATE_DISTRIBUTION_INFO, ctrl_set_rate_distribution_info }, |
4677 | | { AV1E_SET_FILM_GRAIN_TEST_VECTOR, ctrl_set_film_grain_test_vector }, |
4678 | | { AV1E_SET_FILM_GRAIN_TABLE, ctrl_set_film_grain_table }, |
4679 | | { AV1E_SET_DENOISE_NOISE_LEVEL, ctrl_set_denoise_noise_level }, |
4680 | | { AV1E_SET_DENOISE_BLOCK_SIZE, ctrl_set_denoise_block_size }, |
4681 | | { AV1E_SET_ENABLE_DNL_DENOISING, ctrl_set_enable_dnl_denoising }, |
4682 | | { AV1E_ENABLE_MOTION_VECTOR_UNIT_TEST, ctrl_enable_motion_vector_unit_test }, |
4683 | | { AV1E_SET_FP_MT_UNIT_TEST, ctrl_enable_fpmt_unit_test }, |
4684 | | { AV1E_ENABLE_EXT_TILE_DEBUG, ctrl_enable_ext_tile_debug }, |
4685 | | { AV1E_SET_TARGET_SEQ_LEVEL_IDX, ctrl_set_target_seq_level_idx }, |
4686 | | { AV1E_SET_TIER_MASK, ctrl_set_tier_mask }, |
4687 | | { AV1E_SET_MIN_CR, ctrl_set_min_cr }, |
4688 | | { AV1E_SET_SVC_LAYER_ID, ctrl_set_layer_id }, |
4689 | | { AV1E_SET_SVC_PARAMS, ctrl_set_svc_params }, |
4690 | | { AV1E_SET_SVC_REF_FRAME_CONFIG, ctrl_set_svc_ref_frame_config }, |
4691 | | { AV1E_SET_SVC_REF_FRAME_COMP_PRED, ctrl_set_svc_ref_frame_comp_pred }, |
4692 | | { AV1E_SET_VBR_CORPUS_COMPLEXITY_LAP, ctrl_set_vbr_corpus_complexity_lap }, |
4693 | | { AV1E_ENABLE_SB_MULTIPASS_UNIT_TEST, ctrl_enable_sb_multipass_unit_test }, |
4694 | | { AV1E_ENABLE_SB_QP_SWEEP, ctrl_enable_sb_qp_sweep }, |
4695 | | { AV1E_SET_DV_COST_UPD_FREQ, ctrl_set_dv_cost_upd_freq }, |
4696 | | { AV1E_SET_EXTERNAL_PARTITION, ctrl_set_external_partition }, |
4697 | | { AV1E_SET_ENABLE_TX_SIZE_SEARCH, ctrl_set_enable_tx_size_search }, |
4698 | | { AV1E_SET_LOOPFILTER_CONTROL, ctrl_set_loopfilter_control }, |
4699 | | { AV1E_SET_SKIP_POSTPROC_FILTERING, ctrl_set_skip_postproc_filtering }, |
4700 | | { AV1E_SET_AUTO_INTRA_TOOLS_OFF, ctrl_set_auto_intra_tools_off }, |
4701 | | { AV1E_SET_RTC_EXTERNAL_RC, ctrl_set_rtc_external_rc }, |
4702 | | { AV1E_SET_QUANTIZER_ONE_PASS, ctrl_set_quantizer_one_pass }, |
4703 | | { AV1E_SET_BITRATE_ONE_PASS_CBR, ctrl_set_bitrate_one_pass_cbr }, |
4704 | | { AV1E_SET_MAX_CONSEC_FRAME_DROP_CBR, ctrl_set_max_consec_frame_drop_cbr }, |
4705 | | { AV1E_SET_SVC_FRAME_DROP_MODE, ctrl_set_svc_frame_drop_mode }, |
4706 | | { AV1E_SET_AUTO_TILES, ctrl_set_auto_tiles }, |
4707 | | { AV1E_SET_POSTENCODE_DROP_RTC, ctrl_set_postencode_drop_rtc }, |
4708 | | { AV1E_SET_MAX_CONSEC_FRAME_DROP_MS_CBR, |
4709 | | ctrl_set_max_consec_frame_drop_ms_cbr }, |
4710 | | |
4711 | | // Getters |
4712 | | { AOME_GET_LAST_QUANTIZER, ctrl_get_quantizer }, |
4713 | | { AOME_GET_LAST_QUANTIZER_64, ctrl_get_quantizer64 }, |
4714 | | { AOME_GET_LOOPFILTER_LEVEL, ctrl_get_loopfilter_level }, |
4715 | | { AV1_GET_REFERENCE, ctrl_get_reference }, |
4716 | | { AV1E_GET_ACTIVEMAP, ctrl_get_active_map }, |
4717 | | { AV1_GET_NEW_FRAME_IMAGE, ctrl_get_new_frame_image }, |
4718 | | { AV1_COPY_NEW_FRAME_IMAGE, ctrl_copy_new_frame_image }, |
4719 | | { AV1E_SET_CHROMA_SUBSAMPLING_X, ctrl_set_chroma_subsampling_x }, |
4720 | | { AV1E_SET_CHROMA_SUBSAMPLING_Y, ctrl_set_chroma_subsampling_y }, |
4721 | | { AV1E_GET_SEQ_LEVEL_IDX, ctrl_get_seq_level_idx }, |
4722 | | { AV1E_GET_BASELINE_GF_INTERVAL, ctrl_get_baseline_gf_interval }, |
4723 | | { AV1E_GET_TARGET_SEQ_LEVEL_IDX, ctrl_get_target_seq_level_idx }, |
4724 | | { AV1E_GET_NUM_OPERATING_POINTS, ctrl_get_num_operating_points }, |
4725 | | { AV1E_GET_LUMA_CDEF_STRENGTH, ctrl_get_luma_cdef_strength }, |
4726 | | { AV1E_GET_HIGH_MOTION_CONTENT_SCREEN_RTC, |
4727 | | ctrl_get_high_motion_content_screen_rtc }, |
4728 | | |
4729 | | CTRL_MAP_END, |
4730 | | }; |
4731 | | |
4732 | | static const aom_codec_enc_cfg_t encoder_usage_cfg[] = { |
4733 | | #if !CONFIG_REALTIME_ONLY |
4734 | | { |
4735 | | // NOLINT |
4736 | | AOM_USAGE_GOOD_QUALITY, // g_usage - non-realtime usage |
4737 | | 0, // g_threads |
4738 | | 0, // g_profile |
4739 | | |
4740 | | 320, // g_w |
4741 | | 240, // g_h |
4742 | | 0, // g_limit |
4743 | | 0, // g_forced_max_frame_width |
4744 | | 0, // g_forced_max_frame_height |
4745 | | AOM_BITS_8, // g_bit_depth |
4746 | | 8, // g_input_bit_depth |
4747 | | |
4748 | | { 1, 30 }, // g_timebase |
4749 | | |
4750 | | 0, // g_error_resilient |
4751 | | |
4752 | | AOM_RC_ONE_PASS, // g_pass |
4753 | | |
4754 | | 35, // g_lag_in_frames |
4755 | | |
4756 | | 0, // rc_dropframe_thresh |
4757 | | RESIZE_NONE, // rc_resize_mode |
4758 | | SCALE_NUMERATOR, // rc_resize_denominator |
4759 | | SCALE_NUMERATOR, // rc_resize_kf_denominator |
4760 | | |
4761 | | AOM_SUPERRES_NONE, // rc_superres_mode |
4762 | | SCALE_NUMERATOR, // rc_superres_denominator |
4763 | | SCALE_NUMERATOR, // rc_superres_kf_denominator |
4764 | | 63, // rc_superres_qthresh |
4765 | | 32, // rc_superres_kf_qthresh |
4766 | | |
4767 | | AOM_VBR, // rc_end_usage |
4768 | | { NULL, 0 }, // rc_twopass_stats_in |
4769 | | { NULL, 0 }, // rc_firstpass_mb_stats_in |
4770 | | 256, // rc_target_bitrate |
4771 | | 0, // rc_min_quantizer |
4772 | | 63, // rc_max_quantizer |
4773 | | 25, // rc_undershoot_pct |
4774 | | 25, // rc_overshoot_pct |
4775 | | |
4776 | | 6000, // rc_buf_sz |
4777 | | 4000, // rc_buf_initial_sz |
4778 | | 5000, // rc_buf_optimal_sz |
4779 | | |
4780 | | 50, // rc_2pass_vbr_bias_pct |
4781 | | 0, // rc_2pass_vbr_minsection_pct |
4782 | | 2000, // rc_2pass_vbr_maxsection_pct |
4783 | | |
4784 | | // keyframing settings (kf) |
4785 | | 0, // fwd_kf_enabled |
4786 | | AOM_KF_AUTO, // kf_mode |
4787 | | 0, // kf_min_dist |
4788 | | 9999, // kf_max_dist |
4789 | | 0, // sframe_dist |
4790 | | 1, // sframe_mode |
4791 | | 0, // large_scale_tile |
4792 | | 0, // monochrome |
4793 | | 0, // full_still_picture_hdr |
4794 | | 0, // save_as_annexb |
4795 | | 0, // tile_width_count |
4796 | | 0, // tile_height_count |
4797 | | { 0 }, // tile_widths |
4798 | | { 0 }, // tile_heights |
4799 | | 0, // use_fixed_qp_offsets |
4800 | | { -1, -1, -1, -1, -1 }, // fixed_qp_offsets |
4801 | | { 0, 128, 128, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
4802 | | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, // encoder_cfg |
4803 | | }, |
4804 | | #endif // !CONFIG_REALTIME_ONLY |
4805 | | { |
4806 | | // NOLINT |
4807 | | AOM_USAGE_REALTIME, // g_usage - real-time usage |
4808 | | 0, // g_threads |
4809 | | 0, // g_profile |
4810 | | |
4811 | | 320, // g_w |
4812 | | 240, // g_h |
4813 | | 0, // g_limit |
4814 | | 0, // g_forced_max_frame_width |
4815 | | 0, // g_forced_max_frame_height |
4816 | | AOM_BITS_8, // g_bit_depth |
4817 | | 8, // g_input_bit_depth |
4818 | | |
4819 | | { 1, 30 }, // g_timebase |
4820 | | |
4821 | | 0, // g_error_resilient |
4822 | | |
4823 | | AOM_RC_ONE_PASS, // g_pass |
4824 | | |
4825 | | 0, // g_lag_in_frames |
4826 | | |
4827 | | 0, // rc_dropframe_thresh |
4828 | | RESIZE_NONE, // rc_resize_mode |
4829 | | SCALE_NUMERATOR, // rc_resize_denominator |
4830 | | SCALE_NUMERATOR, // rc_resize_kf_denominator |
4831 | | |
4832 | | AOM_SUPERRES_NONE, // rc_superres_mode |
4833 | | SCALE_NUMERATOR, // rc_superres_denominator |
4834 | | SCALE_NUMERATOR, // rc_superres_kf_denominator |
4835 | | 63, // rc_superres_qthresh |
4836 | | 32, // rc_superres_kf_qthresh |
4837 | | |
4838 | | AOM_CBR, // rc_end_usage |
4839 | | { NULL, 0 }, // rc_twopass_stats_in |
4840 | | { NULL, 0 }, // rc_firstpass_mb_stats_in |
4841 | | 256, // rc_target_bitrate |
4842 | | 0, // rc_min_quantizer |
4843 | | 63, // rc_max_quantizer |
4844 | | 50, // rc_undershoot_pct |
4845 | | 50, // rc_overshoot_pct |
4846 | | |
4847 | | 1000, // rc_buf_sz |
4848 | | 600, // rc_buf_initial_sz |
4849 | | 600, // rc_buf_optimal_sz |
4850 | | |
4851 | | 50, // rc_2pass_vbr_bias_pct |
4852 | | 0, // rc_2pass_vbr_minsection_pct |
4853 | | 2000, // rc_2pass_vbr_maxsection_pct |
4854 | | |
4855 | | // keyframing settings (kf) |
4856 | | 0, // fwd_kf_enabled |
4857 | | AOM_KF_AUTO, // kf_mode |
4858 | | 0, // kf_min_dist |
4859 | | 9999, // kf_max_dist |
4860 | | 0, // sframe_dist |
4861 | | 1, // sframe_mode |
4862 | | 0, // large_scale_tile |
4863 | | 0, // monochrome |
4864 | | 0, // full_still_picture_hdr |
4865 | | 0, // save_as_annexb |
4866 | | 0, // tile_width_count |
4867 | | 0, // tile_height_count |
4868 | | { 0 }, // tile_widths |
4869 | | { 0 }, // tile_heights |
4870 | | 0, // use_fixed_qp_offsets |
4871 | | { -1, -1, -1, -1, -1 }, // fixed_qp_offsets |
4872 | | { 0, 128, 128, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
4873 | | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, // encoder_cfg |
4874 | | }, |
4875 | | #if !CONFIG_REALTIME_ONLY |
4876 | | { |
4877 | | // NOLINT |
4878 | | AOM_USAGE_ALL_INTRA, // g_usage - all intra usage |
4879 | | 0, // g_threads |
4880 | | 0, // g_profile |
4881 | | |
4882 | | 320, // g_w |
4883 | | 240, // g_h |
4884 | | 0, // g_limit |
4885 | | 0, // g_forced_max_frame_width |
4886 | | 0, // g_forced_max_frame_height |
4887 | | AOM_BITS_8, // g_bit_depth |
4888 | | 8, // g_input_bit_depth |
4889 | | |
4890 | | { 1, 30 }, // g_timebase |
4891 | | |
4892 | | 0, // g_error_resilient |
4893 | | |
4894 | | AOM_RC_ONE_PASS, // g_pass |
4895 | | |
4896 | | 0, // g_lag_in_frames |
4897 | | |
4898 | | 0, // rc_dropframe_thresh |
4899 | | RESIZE_NONE, // rc_resize_mode |
4900 | | SCALE_NUMERATOR, // rc_resize_denominator |
4901 | | SCALE_NUMERATOR, // rc_resize_kf_denominator |
4902 | | |
4903 | | AOM_SUPERRES_NONE, // rc_superres_mode |
4904 | | SCALE_NUMERATOR, // rc_superres_denominator |
4905 | | SCALE_NUMERATOR, // rc_superres_kf_denominator |
4906 | | 63, // rc_superres_qthresh |
4907 | | 32, // rc_superres_kf_qthresh |
4908 | | |
4909 | | AOM_Q, // rc_end_usage |
4910 | | { NULL, 0 }, // rc_twopass_stats_in |
4911 | | { NULL, 0 }, // rc_firstpass_mb_stats_in |
4912 | | 256, // rc_target_bitrate |
4913 | | 0, // rc_min_quantizer |
4914 | | 63, // rc_max_quantizer |
4915 | | 25, // rc_undershoot_pct |
4916 | | 25, // rc_overshoot_pct |
4917 | | |
4918 | | 6000, // rc_buf_sz |
4919 | | 4000, // rc_buf_initial_sz |
4920 | | 5000, // rc_buf_optimal_sz |
4921 | | |
4922 | | 50, // rc_2pass_vbr_bias_pct |
4923 | | 0, // rc_2pass_vbr_minsection_pct |
4924 | | 2000, // rc_2pass_vbr_maxsection_pct |
4925 | | |
4926 | | // keyframing settings (kf) |
4927 | | 0, // fwd_kf_enabled |
4928 | | AOM_KF_DISABLED, // kf_mode |
4929 | | 0, // kf_min_dist |
4930 | | 0, // kf_max_dist |
4931 | | 0, // sframe_dist |
4932 | | 1, // sframe_mode |
4933 | | 0, // large_scale_tile |
4934 | | 0, // monochrome |
4935 | | 0, // full_still_picture_hdr |
4936 | | 0, // save_as_annexb |
4937 | | 0, // tile_width_count |
4938 | | 0, // tile_height_count |
4939 | | { 0 }, // tile_widths |
4940 | | { 0 }, // tile_heights |
4941 | | 0, // use_fixed_qp_offsets |
4942 | | { -1, -1, -1, -1, -1 }, // fixed_qp_offsets |
4943 | | { 0, 128, 128, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
4944 | | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, // encoder_cfg |
4945 | | }, |
4946 | | #endif // !CONFIG_REALTIME_ONLY |
4947 | | }; |
4948 | | |
4949 | | // This data structure and function are exported in aom/aomcx.h |
4950 | | #ifndef VERSION_STRING |
4951 | | #define VERSION_STRING |
4952 | | #endif |
4953 | | aom_codec_iface_t aom_codec_av1_cx_algo = { |
4954 | | "AOMedia Project AV1 Encoder" VERSION_STRING, |
4955 | | AOM_CODEC_INTERNAL_ABI_VERSION, |
4956 | | (CONFIG_AV1_HIGHBITDEPTH ? AOM_CODEC_CAP_HIGHBITDEPTH : 0) | |
4957 | | AOM_CODEC_CAP_ENCODER | AOM_CODEC_CAP_PSNR, // aom_codec_caps_t |
4958 | | encoder_init, // aom_codec_init_fn_t |
4959 | | encoder_destroy, // aom_codec_destroy_fn_t |
4960 | | encoder_ctrl_maps, // aom_codec_ctrl_fn_map_t |
4961 | | { |
4962 | | // NOLINT |
4963 | | NULL, // aom_codec_peek_si_fn_t |
4964 | | NULL, // aom_codec_get_si_fn_t |
4965 | | NULL, // aom_codec_decode_fn_t |
4966 | | NULL, // aom_codec_get_frame_fn_t |
4967 | | NULL // aom_codec_set_fb_fn_t |
4968 | | }, |
4969 | | { |
4970 | | // NOLINT |
4971 | | NELEMENTS(encoder_usage_cfg), // cfg_count |
4972 | | encoder_usage_cfg, // aom_codec_enc_cfg_t |
4973 | | encoder_encode, // aom_codec_encode_fn_t |
4974 | | encoder_get_cxdata, // aom_codec_get_cx_data_fn_t |
4975 | | encoder_set_config, // aom_codec_enc_config_set_fn_t |
4976 | | encoder_get_global_headers, // aom_codec_get_global_headers_fn_t |
4977 | | encoder_get_preview // aom_codec_get_preview_frame_fn_t |
4978 | | }, |
4979 | | encoder_set_option // aom_codec_set_option_fn_t |
4980 | | }; |
4981 | | |
4982 | 0 | aom_codec_iface_t *aom_codec_av1_cx(void) { return &aom_codec_av1_cx_algo; } |