Coverage Report

Created: 2026-01-16 07:04

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