Coverage Report

Created: 2024-06-18 06:44

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