Coverage Report

Created: 2026-10-17 06:56

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/work/svt-av1/Source/Lib/Globals/enc_settings.c
Line
Count
Source
1
/*
2
* Copyright(c) 2022 Intel Corporation
3
*
4
* This source code is subject to the terms of the BSD 3-Clause Clear License and
5
* the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear License
6
* was not distributed with this source code in the LICENSE file, you can
7
* obtain it at https://www.aomedia.org/license. 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 https://www.aomedia.org/license/patent-license.
10
*/
11
// SUMMARY
12
//   Contains the encoder settings API functions
13
14
/**************************************
15
 * Includes
16
 **************************************/
17
#include <stdbool.h>
18
#include <stdlib.h>
19
#include <stdio.h>
20
#include <stdint.h>
21
#include "EbVersion.h"
22
#include "definitions.h"
23
#include "EbSvtAv1Enc.h"
24
#include "EbSvtAv1Metadata.h"
25
#include "enc_settings.h"
26
#include "entropy_coding.h"
27
28
#include "svt_log.h"
29
#include "utility.h"
30
31
#ifdef _WIN32
32
#include <windows.h>
33
#else
34
#include <errno.h>
35
#include <pthread.h>
36
#include <unistd.h>
37
#endif
38
39
/******************************************
40
* Verify Settings
41
******************************************/
42
492
EbErrorType svt_av1_verify_settings(SequenceControlSet* scs) {
43
492
    EbErrorType               return_error = EB_ErrorNone;
44
492
    EbSvtAv1EncConfiguration* config       = &scs->static_config;
45
492
    if (config->enc_mode > MAX_ENC_PRESET || config->enc_mode < MIN_ENC_PRESET) {
46
0
        SVT_ERROR("EncoderMode must be in the range of [%d-%d]\n", MIN_ENC_PRESET, MAX_ENC_PRESET);
47
0
        return_error = EB_ErrorBadParameter;
48
0
    }
49
492
    if (scs->max_input_luma_width < 1) {
50
0
        SVT_ERROR("Source Width must be at least 1\n");
51
0
        return_error = EB_ErrorBadParameter;
52
0
    }
53
492
    if (scs->max_input_luma_height < 1) {
54
0
        SVT_ERROR("Source Height must be at least 1\n");
55
0
        return_error = EB_ErrorBadParameter;
56
0
    }
57
492
    if (config->pred_structure > RANDOM_ACCESS) {
58
0
        SVT_ERROR("Pred Structure must be [%d (ALL_INTRA), %d (LOW_DELAY), or %d (RANDOM_ACCESS)]\n",
59
0
                  ALL_INTRA,
60
0
                  LOW_DELAY,
61
0
                  RANDOM_ACCESS);
62
0
        return_error = EB_ErrorBadParameter;
63
0
    }
64
492
    if (config->pred_structure == LOW_DELAY && config->pass > 0) {
65
0
        SVT_ERROR("Multi-passes is not support with Low Delay mode \n");
66
0
        return_error = EB_ErrorBadParameter;
67
0
    }
68
492
    if (config->maximum_buffer_size_ms < 20 || config->maximum_buffer_size_ms > 10000) {
69
0
        SVT_ERROR("The maximum buffer size must be between [20, 10000]\n");
70
0
        return_error = EB_ErrorBadParameter;
71
0
    }
72
73
492
    if (config->starting_buffer_level_ms < 20 || config->starting_buffer_level_ms > 10000) {
74
0
        SVT_ERROR("The initial buffer size must be between [20, 10000] \n");
75
0
        return_error = EB_ErrorBadParameter;
76
492
    } else if (config->starting_buffer_level_ms >= config->maximum_buffer_size_ms) {
77
0
        SVT_WARN(
78
0
            "The initial buffer size must be less than maximum buffer size. Defaulting optimal "
79
0
            "buffer size to maximum buffer size - 1 (%u)\n",
80
0
            config->maximum_buffer_size_ms - 1);
81
0
        config->starting_buffer_level_ms = (config->maximum_buffer_size_ms - 1);
82
0
    }
83
84
492
    if (config->optimal_buffer_level_ms < 20 || config->optimal_buffer_level_ms > 10000) {
85
0
        SVT_ERROR("The optimal buffer size must be between [20, 10000]\n");
86
0
        return_error = EB_ErrorBadParameter;
87
492
    } else if (config->optimal_buffer_level_ms >= config->maximum_buffer_size_ms) {
88
0
        SVT_WARN(
89
0
            "The optimal buffer size must be less than maximum buffer size. Defaulting optimal "
90
0
            "buffer size to maximum buffer size - 1 (%u)\n",
91
0
            config->maximum_buffer_size_ms - 1);
92
0
        config->optimal_buffer_level_ms = (config->maximum_buffer_size_ms - 1);
93
0
    }
94
95
492
    if (config->over_shoot_pct > 100) {
96
0
        SVT_ERROR("The overshoot percentage must be between [0, 100] \n");
97
0
        return_error = EB_ErrorBadParameter;
98
0
    }
99
100
492
    if (config->mbr_over_shoot_pct > 100) {
101
0
        SVT_ERROR("The max bitrate overshoot percentage must be between [0, 100] \n");
102
0
        return_error = EB_ErrorBadParameter;
103
0
    }
104
105
492
    if (config->under_shoot_pct > 100) {
106
0
        SVT_ERROR("The undershoot percentage must be between [0, 100] \n");
107
0
        return_error = EB_ErrorBadParameter;
108
0
    }
109
110
492
    if (config->target_bit_rate > 100000000) {
111
0
        SVT_ERROR("The target bit rate must be between [0, 100000] kbps \n");
112
0
        return_error = EB_ErrorBadParameter;
113
0
    }
114
492
    if (config->max_bit_rate > 100000000) {
115
0
        SVT_ERROR("The maximum bit rate must be between [0, 100000] kbps \n");
116
0
        return_error = EB_ErrorBadParameter;
117
0
    }
118
492
    if (config->vbr_max_section_pct > 10000) {
119
0
        SVT_ERROR("The max section percentage must be between [0, 10000] \n");
120
0
        return_error = EB_ErrorBadParameter;
121
0
    }
122
123
492
    if (config->vbr_min_section_pct > 100) {
124
0
        SVT_ERROR("he min section percentage must be between [0, 100] \n");
125
0
        return_error = EB_ErrorBadParameter;
126
0
    }
127
492
    if (config->gop_constraint_rc &&
128
0
        ((config->rate_control_mode != SVT_AV1_RC_MODE_VBR) || config->intra_period_length < 119)) {
129
0
        SVT_ERROR(
130
0
            "Gop constraint rc is only supported with VBR mode when Gop size is "
131
0
            "greater than 119 \n");
132
0
        return_error = EB_ErrorBadParameter;
133
0
    }
134
492
    if (config->gop_constraint_rc) {
135
0
        SVT_WARN(
136
0
            "The GoP constraint RC mode is a work-in-progress project, and is only "
137
0
            "available for demos, experimentation, and further development uses and should not be "
138
0
            "used for benchmarking until fully implemented.\n");
139
0
    }
140
141
492
    if (config->force_key_frames &&
142
0
        (config->rate_control_mode == SVT_AV1_RC_MODE_CBR || config->pred_structure == LOW_DELAY)) {
143
0
        SVT_WARN(
144
0
            "Force key frames is now supported for lowdelay but the force_key_frames flag"
145
0
            " does not need to be set be on. Please follow the app samples shown by the FTR_KF_ON_FLY_SAMPLE"
146
0
            " macro on how to use it. force_key_frames will now be set to 0 \n");
147
0
        config->force_key_frames = 0;
148
0
    }
149
492
    if (config->force_key_frames && config->rate_control_mode == SVT_AV1_RC_MODE_VBR) {
150
0
        SVT_ERROR("Force key frames is not supported for VBR mode \n");
151
0
        return_error = EB_ErrorBadParameter;
152
0
    }
153
492
    if (config->rate_control_mode != SVT_AV1_RC_MODE_CQP_OR_CRF && (config->max_bit_rate != 0)) {
154
0
        SVT_ERROR("Max Bitrate only supported with CRF mode\n");
155
0
        return_error = EB_ErrorBadParameter;
156
0
    }
157
492
    if (config->rate_control_mode == SVT_AV1_RC_MODE_CBR && config->pred_structure != LOW_DELAY) {
158
0
        SVT_ERROR("CBR Rate control is currently not supported for RANDOM_ACCESS/ALL_INTRA, use VBR mode\n");
159
0
        return_error = EB_ErrorBadParameter;
160
0
    }
161
    // Ref-frame management validation: ABI cap + LD-CBR-only when enabled.
162
492
    if (config->max_managed_refs > 4) {
163
0
        SVT_ERROR("max_managed_refs must be in [0, 4] (got %u)\n", (unsigned)config->max_managed_refs);
164
0
        return_error = EB_ErrorBadParameter;
165
0
    }
166
492
    if (config->max_managed_refs > 0 && config->pred_structure != LOW_DELAY) {
167
0
        SVT_ERROR("max_managed_refs > 0 requires pred_structure == LOW_DELAY\n");
168
0
        return_error = EB_ErrorBadParameter;
169
0
    }
170
492
    if (config->max_managed_refs > 0 && config->rate_control_mode != SVT_AV1_RC_MODE_CBR) {
171
        // Only LD-CBR is implemented; LD-CRF's shifted lay1_offset would
172
        // collide with the STORE-safe slot pool. See pd_process.c.
173
0
        SVT_ERROR("max_managed_refs > 0 requires rate_control_mode == CBR (got %u)\n",
174
0
                  (unsigned)config->rate_control_mode);
175
0
        return_error = EB_ErrorBadParameter;
176
0
    }
177
492
    if (config->max_managed_refs > 0 && (config->sframe_dist > 0 || config->sframe_posi.sframe_posis)) {
178
        // An S-frame refreshes all 8 DPB slots and signals no refresh_frame_flags,
179
        // so a decoder unconditionally evicts every anchor. The encoder keeps them
180
        // (the STORE guard masks held slots out of the refresh), and the two DPB
181
        // views diverge from that point on.
182
0
        SVT_ERROR(
183
0
            "max_managed_refs > 0 is not supported with switch frames "
184
0
            "(sframe_dist=%d sframe_num=%u)\n",
185
0
            config->sframe_dist,
186
0
            (unsigned)config->sframe_posi.sframe_num);
187
0
        return_error = EB_ErrorBadParameter;
188
0
    }
189
    // Runtime MG-size change: ABI cap, restricted to where MG_SIZE_CHANGE_EVENT
190
    // is accepted, and never below the level count already configured.
191
492
    if (config->max_hierarchical_levels > 2) {
192
0
        SVT_ERROR("max_hierarchical_levels must be in [0, 2] (got %u)\n", (unsigned)config->max_hierarchical_levels);
193
0
        return_error = EB_ErrorBadParameter;
194
0
    }
195
492
    if (config->max_hierarchical_levels > 0 &&
196
0
        !(config->rtc && config->pred_structure == LOW_DELAY && config->rate_control_mode == SVT_AV1_RC_MODE_CBR)) {
197
0
        SVT_ERROR("max_hierarchical_levels > 0 requires RTC low-delay CBR\n");
198
0
        return_error = EB_ErrorBadParameter;
199
0
    }
200
492
    if (config->max_hierarchical_levels > 0 && config->max_hierarchical_levels < config->hierarchical_levels) {
201
0
        SVT_ERROR("max_hierarchical_levels (%u) must be >= hierarchical_levels (%u)\n",
202
0
                  (unsigned)config->max_hierarchical_levels,
203
0
                  (unsigned)config->hierarchical_levels);
204
0
        return_error = EB_ErrorBadParameter;
205
0
    }
206
492
    if (config->max_allowed_consecutive_frames_skips > 0 &&
207
0
        !(config->rtc && config->pred_structure == LOW_DELAY && config->rate_control_mode == SVT_AV1_RC_MODE_CBR)) {
208
0
        SVT_ERROR("max_allowed_consecutive_frames_skips > 0 requires RTC low-delay CBR\n");
209
0
        return_error = EB_ErrorBadParameter;
210
0
    }
211
492
    if (config->rate_control_mode == SVT_AV1_RC_MODE_VBR && config->pred_structure == LOW_DELAY) {
212
0
        SVT_ERROR("VBR Rate control is currently not supported for LOW_DELAY, use CBR mode\n");
213
0
        return_error = EB_ErrorBadParameter;
214
0
    }
215
492
    if (config->rate_control_mode == SVT_AV1_RC_MODE_CQP_OR_CRF && config->target_bit_rate != DEFAULT_TBR) {
216
0
        SVT_ERROR("Target Bitrate only supported when --rc is  1/2 (VBR/CBR). Current --rc: %d\n",
217
0
                  config->rate_control_mode);
218
0
        return_error = EB_ErrorBadParameter;
219
0
    }
220
221
492
    if (config->tier > 1) {
222
0
        SVT_ERROR("Tier must be 0 (Main tier) or 1 (High tier)\n");
223
0
        return_error = EB_ErrorBadParameter;
224
0
    }
225
226
492
    if (scs->max_input_luma_width > 16384) {
227
0
        SVT_ERROR("Source Width must be less than or equal to 16384\n");
228
0
        return_error = EB_ErrorBadParameter;
229
0
    }
230
231
492
    if (scs->max_input_luma_height > 8704) {
232
0
        SVT_ERROR("Source Height must be less than or equal to 8704)\n");
233
0
        return_error = EB_ErrorBadParameter;
234
0
    }
235
236
492
    if (scs->seq_header.max_frame_width < 1) {
237
0
        SVT_ERROR("Forced Max Width must be at least 1\n");
238
0
        return_error = EB_ErrorBadParameter;
239
0
    }
240
492
    if (scs->seq_header.max_frame_height < 1) {
241
0
        SVT_ERROR("Forced Max Height must be at least 1\n");
242
0
        return_error = EB_ErrorBadParameter;
243
0
    }
244
492
    if (scs->seq_header.max_frame_width > 16384) {
245
0
        SVT_ERROR("Forced Max Width must be less than or equal to 16384\n");
246
0
        return_error = EB_ErrorBadParameter;
247
0
    }
248
492
    if (scs->seq_header.max_frame_height > 8704) {
249
0
        SVT_ERROR("Forced Max Height must be less than or equal to 8704)\n");
250
0
        return_error = EB_ErrorBadParameter;
251
0
    }
252
253
    // This is not an AV1 spec limitation, but an implementation limitation in the encoder
254
    // This check will stay in place until restoration filtering can handle these dimensions
255
492
    if ((scs->max_input_luma_width >= 1 && scs->max_input_luma_width < 64) ||
256
492
        (scs->max_input_luma_height >= 1 && scs->max_input_luma_height < 64)) {
257
0
        if (config->aq_mode != 0) {
258
0
            SVT_WARN("AQ mode %i is unsupported with source dimensions (%i / %i), setting AQ mode to 0\n",
259
0
                     config->aq_mode,
260
0
                     scs->max_input_luma_width,
261
0
                     scs->max_input_luma_height);
262
0
            config->aq_mode = 0;
263
0
        }
264
0
        if (config->enable_restoration_filtering != 0) {
265
0
            SVT_WARN(
266
0
                "Restoration Filtering is unsupported with source dimensions (%i / %i), disabling "
267
0
                "Restoration Filtering\n",
268
0
                scs->max_input_luma_width,
269
0
                scs->max_input_luma_height);
270
0
            config->enable_restoration_filtering = 0;
271
0
        }
272
0
    }
273
274
492
    if ((scs->max_input_luma_width > scs->seq_header.max_frame_width) ||
275
492
        (scs->max_input_luma_height > scs->seq_header.max_frame_height)) {
276
0
        SVT_ERROR(
277
0
            "Source Width/Height must be less than or equal to Forced Max "
278
0
            "Width/Height\n");
279
0
        return_error = EB_ErrorBadParameter;
280
0
    }
281
282
492
    if (config->level != 0) {
283
0
        BitstreamLevel bl;
284
0
        bl.major = config->level / 10;
285
0
        bl.minor = config->level % 10;
286
        // Defined AV1 levels only have major versions 2-9 and minor versions 0-3
287
0
        if (bl.minor > LEVEL_MINOR_MAX || bl.major < LEVEL_MAJOR_MIN || bl.major > LEVEL_MAJOR_MAX) {
288
0
            SVT_ERROR("Invalid or undefined level specified: %d.%d. See AV1 spec Annex A for defined levels.\n",
289
0
                      bl.major,
290
0
                      bl.minor);
291
0
            return_error = EB_ErrorBadParameter;
292
0
        } else {
293
            // Some levels in the allowable range are undefined by the spec.
294
0
            const uint8_t seq_level_idx = major_minor_to_seq_level_idx(bl);
295
0
            if (!is_valid_seq_level_idx(seq_level_idx)) {
296
0
                SVT_ERROR("Invalid or undefined level specified: %d.%d. See AV1 spec Annex A for defined levels.\n",
297
0
                          bl.major,
298
0
                          bl.minor);
299
0
                return_error = EB_ErrorBadParameter;
300
0
            }
301
0
        }
302
0
    }
303
304
492
    if (config->qp > MAX_QP_VALUE) {
305
0
        SVT_ERROR("%s must be [0 - %d]\n", config->aq_mode ? "CRF" : "QP", MAX_QP_VALUE);
306
0
        return_error = EB_ErrorBadParameter;
307
0
    }
308
309
492
    if ((config->qp == MAX_QP_VALUE && config->extended_crf_qindex_offset > (7 * 4))) {
310
0
        SVT_ERROR("%s must be [0 - %d]\n", "CRF", 70);
311
0
        return_error = EB_ErrorBadParameter;
312
0
    }
313
314
492
    if (config->hierarchical_levels > 5) {
315
0
        SVT_ERROR("Hierarchical Levels supported: [0-5]\n");
316
0
        return_error = EB_ErrorBadParameter;
317
492
    } else {
318
1.96k
        for (uint8_t i = 0; i < config->hierarchical_levels + 1; ++i) {
319
1.47k
            if (config->qindex_offsets[i] < -64 || config->qindex_offsets[i] > 63) {
320
0
                SVT_ERROR(
321
0
                    "Invalid qindex_offsets for hierarchical level %d. Found %d, qindex_offsets must be [-64 - 63]\n",
322
0
                    i,
323
0
                    config->qindex_offsets[i]);
324
0
                return_error = EB_ErrorBadParameter;
325
0
            }
326
1.47k
        }
327
1.96k
        for (uint8_t i = 0; i < config->hierarchical_levels + 1; ++i) {
328
1.47k
            if (config->chroma_qindex_offsets[i] < -64 || config->chroma_qindex_offsets[i] > 63) {
329
0
                SVT_ERROR(
330
0
                    "Invalid chroma_qindex_offsets for hierarchical level %d. Found %d, chroma_qindex_offsets must be "
331
0
                    "[-64 - 63]\n",
332
0
                    i,
333
0
                    config->chroma_qindex_offsets[i]);
334
0
                return_error = EB_ErrorBadParameter;
335
0
            }
336
1.47k
        }
337
492
    }
338
492
    if ((config->intra_period_length < -2 || config->intra_period_length > 2 * ((1 << 30) - 1)) &&
339
0
        config->rate_control_mode == SVT_AV1_RC_MODE_CQP_OR_CRF) {
340
0
        SVT_ERROR("The intra period must be [-2, 2^31-2]\n");
341
0
        return_error = EB_ErrorBadParameter;
342
0
    }
343
492
    if ((config->intra_period_length < 0) && config->rate_control_mode == SVT_AV1_RC_MODE_VBR) {
344
0
        SVT_ERROR("The intra period must be > 0 for RateControlMode %d\n", config->rate_control_mode);
345
0
        return_error = EB_ErrorBadParameter;
346
0
    }
347
348
492
    if (config->intra_refresh_type > 2 || config->intra_refresh_type < 1) {
349
0
        SVT_ERROR("Invalid intra Refresh Type [1-2]\n");
350
0
        return_error = EB_ErrorBadParameter;
351
0
    }
352
353
492
    if (config->enable_dlf_flag > 2) {
354
0
        SVT_ERROR("Invalid LoopFilterEnable. LoopFilterEnable must be [0 - 2]\n");
355
0
        return_error = EB_ErrorBadParameter;
356
0
    }
357
358
492
    if (config->rate_control_mode > SVT_AV1_RC_MODE_CBR &&
359
0
        (config->pass == ENC_FIRST_PASS || config->rc_stats_buffer.buf)) {
360
0
        SVT_ERROR("Only rate control mode 0~2 are supported for 2-pass \n");
361
0
        return_error = EB_ErrorBadParameter;
362
0
    }
363
    // Stats file is checked by the app in handle_stats_file, but must be re-checked here since ffmpeg calls
364
    // the library but not the app
365
492
    if (config->rate_control_mode == SVT_AV1_RC_MODE_VBR && config->pass == ENC_SECOND_PASS) {
366
0
        if (!config->rc_stats_buffer.buf) {
367
0
            SVT_ERROR("RC stats buffer not available \n");
368
0
            return_error = EB_ErrorBadParameter;
369
0
        } else if (config->rc_stats_buffer.sz == 0) {
370
0
            SVT_ERROR("RC stats buffer size is 0 \n");
371
0
            return_error = EB_ErrorBadParameter;
372
0
        }
373
0
    }
374
492
    if (config->profile > 2) {
375
0
        SVT_ERROR("The maximum allowed profile value is 2 \n");
376
0
        return_error = EB_ErrorBadParameter;
377
0
    }
378
379
    // Check if the current input video is conformant with the Level constraint
380
492
    if (scs->frame_rate > 240) {
381
0
        SVT_ERROR("The maximum allowed frame rate is 240 fps\n");
382
0
        return_error = EB_ErrorBadParameter;
383
0
    }
384
    // Check that the frame_rate is non-zero
385
492
    if (!scs->frame_rate) {
386
0
        SVT_ERROR("The frame rate should be greater than 0 fps \n");
387
0
        return_error = EB_ErrorBadParameter;
388
0
    }
389
492
    if (scs->static_config.frame_rate_numerator == 0 || scs->static_config.frame_rate_denominator == 0) {
390
0
        SVT_ERROR("The frame_rate_numerator and frame_rate_denominator must be greater than 0\n");
391
0
        return_error = EB_ErrorBadParameter;
392
0
    }
393
492
    if (config->recode_loop > 4) {
394
0
        SVT_ERROR("The recode_loop must be [0 - 4] \n");
395
0
        return_error = EB_ErrorBadParameter;
396
0
    }
397
492
    if (config->rate_control_mode > SVT_AV1_RC_MODE_CBR) {
398
0
        SVT_ERROR("The rate control mode must be [0 - 2] \n");
399
0
        return_error = EB_ErrorBadParameter;
400
0
    }
401
492
    if (config->look_ahead_distance > MAX_LAD && config->look_ahead_distance != (uint32_t)~0) {
402
0
        SVT_ERROR("The lookahead distance must be [0 - %d] \n", MAX_LAD);
403
404
0
        return_error = EB_ErrorBadParameter;
405
0
    }
406
492
    if ((unsigned)config->tile_rows > 6 || (unsigned)config->tile_columns > 6) {
407
0
        SVT_ERROR("Log2Tile rows/cols must be [0 - 6] \n");
408
0
        return_error = EB_ErrorBadParameter;
409
0
    }
410
492
    if ((1u << config->tile_rows) * (1u << config->tile_columns) > 128 || config->tile_columns > 4) {
411
0
        SVT_ERROR("MaxTiles is 128 and MaxTileCols is 16 (Annex A.3) \n");
412
0
        return_error = EB_ErrorBadParameter;
413
0
    }
414
492
    if (config->max_qp_allowed > MAX_QP_VALUE) {
415
0
        SVT_ERROR("MaxQpAllowed must be [0 - %d]\n", MAX_QP_VALUE);
416
0
        return_error = EB_ErrorBadParameter;
417
492
    } else if (config->min_qp_allowed > MAX_QP_VALUE) {
418
0
        SVT_ERROR("MinQpAllowed must be [0 - %d]\n", MAX_QP_VALUE);
419
0
        return_error = EB_ErrorBadParameter;
420
492
    } else if (config->min_qp_allowed > config->max_qp_allowed) {
421
0
        SVT_ERROR("MinQpAllowed must be smaller than or equal to MaxQpAllowed\n");
422
0
        return_error = EB_ErrorBadParameter;
423
0
    }
424
492
    if (config->use_fixed_qindex_offsets > 2) {
425
0
        SVT_ERROR("The use_fixed_qindex_offsets must be [0 - 2] \n");
426
0
        return_error = EB_ErrorBadParameter;
427
0
    }
428
429
492
    if (config->key_frame_qindex_offset < -64 || config->key_frame_qindex_offset > 63) {
430
0
        SVT_ERROR("Invalid key_frame_qindex_offset. key_frame_qindex_offset must be [-64 - 63]\n");
431
0
        return_error = EB_ErrorBadParameter;
432
0
    }
433
434
492
    if (config->key_frame_chroma_qindex_offset < -64 || config->key_frame_chroma_qindex_offset > 63) {
435
0
        SVT_ERROR(
436
0
            "Invalid key_frame_chroma_qindex_offset. key_frame_chroma_qindex_offset "
437
0
            "must be [-64 - 63]\n");
438
0
        return_error = EB_ErrorBadParameter;
439
0
    }
440
492
    if (config->luma_y_dc_qindex_offset < -64 || config->luma_y_dc_qindex_offset > 63) {
441
0
        SVT_ERROR(
442
0
            "Invalid luma_y_dc_qindex_offset. luma_y_dc_qindex_offset "
443
0
            "must be [-64 - 63]\n");
444
0
        return_error = EB_ErrorBadParameter;
445
0
    }
446
492
    if (config->chroma_u_dc_qindex_offset < -64 || config->chroma_u_dc_qindex_offset > 63) {
447
0
        SVT_ERROR(
448
0
            "Invalid chroma_u_dc_qindex_offset. chroma_u_dc_qindex_offset "
449
0
            "must be [-64 - 63]\n");
450
0
        return_error = EB_ErrorBadParameter;
451
0
    }
452
492
    if (config->chroma_u_ac_qindex_offset < -64 || config->chroma_u_ac_qindex_offset > 63) {
453
0
        SVT_ERROR(
454
0
            "Invalid chroma_u_ac_qindex_offset. chroma_u_ac_qindex_offset "
455
0
            "must be [-64 - 63]\n");
456
0
        return_error = EB_ErrorBadParameter;
457
0
    }
458
492
    if (config->chroma_v_dc_qindex_offset < -64 || config->chroma_v_dc_qindex_offset > 63) {
459
0
        SVT_ERROR(
460
0
            "Invalid chroma_v_dc_qindex_offset. chroma_v_dc_qindex_offset "
461
0
            "must be [-64 - 63]\n");
462
0
        return_error = EB_ErrorBadParameter;
463
0
    }
464
492
    if (config->chroma_v_ac_qindex_offset < -64 || config->chroma_v_ac_qindex_offset > 63) {
465
0
        SVT_ERROR(
466
0
            "Invalid chroma_v_ac_qindex_offset. chroma_v_ac_qindex_offset "
467
0
            "must be [-64 - 63]\n");
468
0
        return_error = EB_ErrorBadParameter;
469
0
    }
470
471
492
    if (config->startup_qp_offset < -63 || config->startup_qp_offset > 63) {
472
0
        SVT_ERROR("Invalid startup_qp_offset. startup_qp_offset must be [-63 - 63]\n");
473
0
        return_error = EB_ErrorBadParameter;
474
0
    }
475
492
    if (config->stat_report == 1) {
476
0
        SVT_WARN("Enabling StatReport can decrease encoding speed\n");
477
0
    }
478
479
492
    if (config->stat_report > 1) {
480
0
        SVT_ERROR("Invalid StatReport. StatReport must be [0 - 1]\n");
481
0
        return_error = EB_ErrorBadParameter;
482
0
    }
483
492
    if (config->screen_content_mode > 3) {
484
0
        SVT_ERROR("Invalid screen_content_mode. screen_content_mode must be [0 - 3]\n");
485
0
        return_error = EB_ErrorBadParameter;
486
0
    }
487
488
492
    if (scs->static_config.aq_mode > 2) {
489
0
        SVT_ERROR("Invalid adaptive quantization (AQ) mode. AQ mode must be [0-2]\n");
490
0
        return_error = EB_ErrorBadParameter;
491
0
    }
492
493
492
    if ((SVT_EFFECTIVE_BIT_DEPTH(config->encoder_bit_depth) != 8) &&
494
0
        (SVT_EFFECTIVE_BIT_DEPTH(config->encoder_bit_depth) != 10)) {
495
0
        SVT_ERROR("Encoder Bit Depth shall be only 8 or 10 \n");
496
0
        return_error = EB_ErrorBadParameter;
497
0
    }
498
    // Check if the EncoderBitDepth is conformant with the Profile constraint
499
492
    if ((config->profile == 0 || config->profile == 1) && SVT_EFFECTIVE_BIT_DEPTH(config->encoder_bit_depth) > 10) {
500
0
        SVT_ERROR("The encoder bit depth shall be equal to 8 or 10 for Main/High Profile\n");
501
0
        return_error = EB_ErrorBadParameter;
502
0
    }
503
504
492
    if (config->encoder_color_format != EB_YUV420) {
505
0
        SVT_ERROR("Only support 420 now \n");
506
0
        return_error = EB_ErrorBadParameter;
507
0
    }
508
509
492
    if (config->profile == 0 && config->encoder_color_format > EB_YUV420) {
510
0
        SVT_ERROR("Non 420 color format requires profile 1 or 2\n");
511
0
        return_error = EB_ErrorBadParameter;
512
0
    }
513
514
492
    if (config->profile == 1 && config->encoder_color_format != EB_YUV444) {
515
0
        SVT_ERROR("Profile 1 requires 4:4:4 color format\n");
516
0
        return_error = EB_ErrorBadParameter;
517
0
    }
518
519
492
    if (config->profile == 2 && SVT_EFFECTIVE_BIT_DEPTH(config->encoder_bit_depth) <= 10 &&
520
0
        config->encoder_color_format != EB_YUV422) {
521
0
        SVT_ERROR("Profile 2 bit-depth < 10 requires 4:2:2 color format\n");
522
0
        return_error = EB_ErrorBadParameter;
523
0
    }
524
525
492
    if (config->use_cpu_flags & EB_CPU_FLAGS_INVALID) {
526
#ifdef ARCH_AARCH64
527
        SVT_ERROR(
528
            "param '--asm' have invalid value.\n"
529
            "Value should be [0 - 6] or [c, neon, crc32, neon_dotprod, neon_i8mm, sve, sve2, max]\n");
530
#else
531
0
        SVT_ERROR(
532
0
            "param '--asm' have invalid value.\n"
533
0
            "Value should be [0 - 11] or [c, mmx, sse, sse2, sse3, ssse3, sse4_1, sse4_2, avx, "
534
0
            "avx2, avx512, avx512icl, max]\n");
535
0
#endif
536
0
        return_error = EB_ErrorBadParameter;
537
0
    }
538
539
    // HBD mode decision
540
492
    if (scs->enable_hbd_mode_decision < (int8_t)(-1) || scs->enable_hbd_mode_decision > 2) {
541
0
        SVT_ERROR("Invalid HBD mode decision flag [-1 - 2], your input: %d\n", scs->enable_hbd_mode_decision);
542
0
        return_error = EB_ErrorBadParameter;
543
0
    }
544
545
    // CDEF
546
492
    if (config->cdef_level > 10 || config->cdef_level < -1) {
547
0
        SVT_ERROR("Invalid CDEF level [0 - 10, -1 for auto], your input: %d\n", config->cdef_level);
548
0
        return_error = EB_ErrorBadParameter;
549
0
    }
550
551
    // Restoration Filtering
552
492
    if (config->enable_restoration_filtering != 0 && config->enable_restoration_filtering != 1 &&
553
492
        config->enable_restoration_filtering != -1) {
554
0
        SVT_ERROR("Invalid restoration flag [0 - 1, -1 for auto], your input: %d\n",
555
0
                  config->enable_restoration_filtering);
556
0
        return_error = EB_ErrorBadParameter;
557
0
    }
558
559
492
    if (config->enable_mfmv != 0 && config->enable_mfmv != 1 && config->enable_mfmv != -1) {
560
0
        SVT_ERROR(
561
0
            "Invalid motion field motion vector flag [0/1 or -1 for auto], your "
562
0
            "input: %d\n",
563
0
            config->enable_mfmv);
564
0
        return_error = EB_ErrorBadParameter;
565
0
    }
566
492
    if (config->fast_decode > 2) {
567
0
        SVT_ERROR(
568
0
            "Invalid fast decode flag [0 - 2, 0 for no decoder-targeted optimization], your "
569
0
            "input: %d\n",
570
0
            config->fast_decode);
571
0
        return_error = EB_ErrorBadParameter;
572
0
    }
573
492
    if (config->tune > TUNE_VMAF) {
574
0
        SVT_ERROR(
575
0
            "Invalid tune flag [0 - 5, 0 for VQ, 1 for PSNR, 2 for SSIM, 3 for IQ, 4 for MS_SSIM, and 5 for VMAF], "
576
0
            "your input: "
577
0
            "%d\n",
578
0
            config->tune);
579
0
        return_error = EB_ErrorBadParameter;
580
0
    }
581
    // RC: SSIM, IQ, MS_SSIM, VMAF -> CRF only (VBR, CBR not supported)
582
492
    if (config->tune == TUNE_SSIM || config->tune == TUNE_IQ || config->tune == TUNE_MS_SSIM ||
583
492
        config->tune == TUNE_VMAF) {
584
0
        if (config->rate_control_mode != 0) {
585
0
            SVT_ERROR("Tune %s only supports CRF rate control mode\n",
586
0
                      config->tune == TUNE_SSIM       ? "SSIM"
587
0
                          : config->tune == TUNE_IQ   ? "IQ"
588
0
                          : config->tune == TUNE_VMAF ? "VMAF"
589
0
                                                      : "MS_SSIM");
590
0
            return_error = EB_ErrorBadParameter;
591
0
        }
592
0
    }
593
594
    // pred_struct: SSIM, MS_SSIM -> ALL_INTRA and RA only (LOW_DELAY not supported)
595
492
    if (config->tune == TUNE_SSIM || config->tune == TUNE_MS_SSIM) {
596
0
        if (config->pred_structure == LOW_DELAY) {
597
0
            SVT_ERROR("Tune %s only supports all-intra and random access prediction structures\n",
598
0
                      config->tune == TUNE_SSIM ? "SSIM" : "MS_SSIM");
599
0
            return_error = EB_ErrorBadParameter;
600
0
        }
601
0
    }
602
603
    // pred_struct: VMAF -> RA only (ALL_INTRA and LOW_DELAY not supported)
604
492
    if (config->tune == TUNE_VMAF && (config->pred_structure == ALL_INTRA || config->pred_structure == LOW_DELAY)) {
605
0
        SVT_ERROR("Tune VMAF only supports random access prediction structure\n");
606
0
        return_error = EB_ErrorBadParameter;
607
0
    }
608
609
    // pred_struct: IQ -> ALL_INTRA and LOW_DELAY only (RA not supported); LOW_DELAY is experimental
610
492
    if (config->tune == TUNE_IQ && config->pred_structure == RANDOM_ACCESS) {
611
0
        SVT_ERROR("Tune IQ only supports all-intra and low delay (experimental) prediction structures\n");
612
0
        return_error = EB_ErrorBadParameter;
613
0
    }
614
492
    if (config->tune == TUNE_IQ && config->pred_structure == LOW_DELAY) {
615
0
        SVT_WARN("Tune IQ with low delay prediction structure is experimental\n");
616
0
    }
617
618
492
    if (config->superres_mode > SUPERRES_AUTO) {
619
0
        SVT_ERROR("invalid superres-mode %d, should be in the range [%d - %d]\n",
620
0
                  config->superres_mode,
621
0
                  SUPERRES_NONE,
622
0
                  SUPERRES_AUTO);
623
0
        return_error = EB_ErrorBadParameter;
624
0
    }
625
492
    if (config->superres_mode > 0 && ((config->rc_stats_buffer.sz || config->pass == ENC_FIRST_PASS))) {
626
0
        SVT_ERROR("superres is not supported for 2-pass\n");
627
0
        return_error = EB_ErrorBadParameter;
628
0
    }
629
630
492
    if (config->superres_qthres > MAX_QP_VALUE) {
631
0
        SVT_ERROR("Invalid superres-qthres %d, should be in the range [%d - %d]\n",
632
0
                  config->superres_qthres,
633
0
                  MIN_QP_VALUE,
634
0
                  MAX_QP_VALUE);
635
0
        return_error = EB_ErrorBadParameter;
636
0
    }
637
638
492
    if (config->superres_kf_qthres > MAX_QP_VALUE) {
639
0
        SVT_ERROR("Invalid superres-kf-qthres %d, should be in the range [%d - %d]\n",
640
0
                  config->superres_kf_qthres,
641
0
                  MIN_QP_VALUE,
642
0
                  MAX_QP_VALUE);
643
0
        return_error = EB_ErrorBadParameter;
644
0
    }
645
646
492
    if (config->superres_kf_denom < MIN_SUPERRES_DENOM || config->superres_kf_denom > MAX_SUPERRES_DENOM) {
647
0
        SVT_ERROR("Invalid superres-kf-denom %d, should be in the range [%d - %d]\n",
648
0
                  config->superres_kf_denom,
649
0
                  MIN_SUPERRES_DENOM,
650
0
                  MAX_SUPERRES_DENOM);
651
0
        return_error = EB_ErrorBadParameter;
652
0
    }
653
654
492
    if (config->superres_denom < MIN_SUPERRES_DENOM || config->superres_denom > MAX_SUPERRES_DENOM) {
655
0
        SVT_ERROR("Invalid superres-denom %d, should be in the range [%d - %d]\n",
656
0
                  config->superres_denom,
657
0
                  MIN_SUPERRES_DENOM,
658
0
                  MAX_SUPERRES_DENOM);
659
0
        return_error = EB_ErrorBadParameter;
660
0
    }
661
662
492
    if (config->resize_mode > RESIZE_RANDOM_ACCESS) {
663
0
        SVT_ERROR("Invalid resize-mode %d, should be in the range [%d - %d]\n",
664
0
                  config->resize_mode,
665
0
                  RESIZE_NONE,
666
0
                  RESIZE_RANDOM_ACCESS);
667
0
        return_error = EB_ErrorBadParameter;
668
0
    }
669
670
492
    if (config->resize_kf_denom < MIN_RESIZE_DENOM || config->resize_kf_denom > MAX_RESIZE_DENOM) {
671
0
        SVT_ERROR("Invalid resize-kf-denom %d, should be in the range [%d - %d]\n",
672
0
                  config->resize_kf_denom,
673
0
                  MIN_RESIZE_DENOM,
674
0
                  MAX_RESIZE_DENOM);
675
0
        return_error = EB_ErrorBadParameter;
676
0
    }
677
678
492
    if (config->resize_denom < MIN_RESIZE_DENOM || config->resize_denom > MAX_RESIZE_DENOM) {
679
0
        SVT_ERROR("Invalid resize-denom %d, should be in the range [%d - %d]\n",
680
0
                  config->resize_denom,
681
0
                  MIN_RESIZE_DENOM,
682
0
                  MAX_RESIZE_DENOM);
683
0
        return_error = EB_ErrorBadParameter;
684
0
    }
685
686
492
    if (config->matrix_coefficients == 0 && config->encoder_color_format != EB_YUV444) {
687
0
        SVT_ERROR(
688
0
            "Identity matrix (matrix_coefficient = 0) may be used only with 4:4:4 "
689
0
            "color format.\n");
690
0
        return_error = EB_ErrorBadParameter;
691
0
    }
692
693
492
    if (config->rate_control_mode == SVT_AV1_RC_MODE_VBR && config->intra_period_length == -1) {
694
0
        SVT_ERROR(
695
0
            "keyint = -1 is not supported for modes other than CRF rate control "
696
0
            "encoding modes.\n");
697
0
        return_error = EB_ErrorBadParameter;
698
0
    }
699
    // Block the use of M4 or lower for resolutions higher than 4K, unless allintra coding is used (due to memory constraints)
700
492
    if (!scs->allintra && (uint64_t)(scs->max_input_luma_width * scs->max_input_luma_height) > INPUT_SIZE_4K_TH &&
701
0
        config->enc_mode <= ENC_M4) {
702
0
        SVT_ERROR("8k+ resolution support is limited to M5 and faster presets.\n");
703
0
        return_error = EB_ErrorBadParameter;
704
0
    }
705
492
    if (config->pass > 0 && scs->static_config.enable_overlays) {
706
0
        SVT_ERROR(
707
0
            "The overlay frames feature is currently not supported with multi-pass "
708
0
            "encoding\n");
709
0
        return_error = EB_ErrorBadParameter;
710
0
    }
711
492
    int pass = config->pass;
712
713
492
    if (pass < 0 || pass > 2) {
714
0
        SVT_ERROR("%d pass encode is not supported. --pass has a range of [0-2]\n", pass);
715
0
        return_error = EB_ErrorBadParameter;
716
0
    }
717
718
492
    if (config->intra_refresh_type != 2 && pass > 0) {
719
0
        SVT_ERROR("Multi-pass encode only supports closed-gop configurations.\n");
720
0
        return_error = EB_ErrorBadParameter;
721
0
    }
722
492
    if (config->pass > 1 && config->rate_control_mode == SVT_AV1_RC_MODE_CQP_OR_CRF) {
723
0
        SVT_ERROR("CRF does not support multi-pass. Use single pass.\n");
724
0
        return_error = EB_ErrorBadParameter;
725
0
    }
726
727
492
    if (config->aq_mode == 0 && config->rate_control_mode) {
728
0
        SVT_ERROR("Adaptive quantization can not be turned OFF when RC ON\n");
729
0
        return_error = EB_ErrorBadParameter;
730
0
    }
731
732
492
    if (config->sframe_dist < 0) {
733
0
        SVT_ERROR("Switch frame interval must be >= 0\n");
734
0
        return_error = EB_ErrorBadParameter;
735
0
    }
736
492
    if (config->sframe_dist > 0 && config->hierarchical_levels == 0) {
737
0
        SVT_ERROR("Switch frame feature does not support flat IPPP\n");
738
0
        return_error = EB_ErrorBadParameter;
739
0
    }
740
492
    if (config->sframe_dist > 0 &&
741
0
        (config->sframe_mode < SFRAME_STRICT_BASE || config->sframe_mode > SFRAME_DEC_POSI_BASE)) {
742
0
        SVT_ERROR("Invalid switch frame mode %d, should be in the range [%d - %d]\n",
743
0
                  config->sframe_mode,
744
0
                  SFRAME_STRICT_BASE,
745
0
                  SFRAME_DEC_POSI_BASE);
746
0
        return_error = EB_ErrorBadParameter;
747
0
    }
748
492
    if (config->sframe_posi.sframe_posis && !IS_SFRAME_FLEXIBLE_INSERT(config->sframe_mode)) {
749
0
        SVT_ERROR("S-Frame positions are only supported in S-Frame Flexible ARF mode\n");
750
0
        return_error = EB_ErrorBadParameter;
751
0
    }
752
492
    if (config->sframe_posi.sframe_qp_num && config->rate_control_mode != SVT_AV1_RC_MODE_CQP_OR_CRF) {
753
0
        SVT_ERROR("S-Frame QP feature only supports CRF/CQP rate control mode\n");
754
0
        return_error = EB_ErrorBadParameter;
755
0
    }
756
492
    if ((config->sframe_posi.sframe_qps && config->sframe_posi.sframe_qp_offsets) ||
757
492
        (config->sframe_qp > 0 && config->sframe_qp_offset != 0)) {
758
0
        SVT_ERROR("S-Frame QP feature cannot support QP value and QP offset at same time\n");
759
0
        return_error = EB_ErrorBadParameter;
760
0
    }
761
762
    /* Warnings about the use of features that are incomplete */
763
492
    if (config->aq_mode == 1) {
764
0
        SVT_WARN(
765
0
            "The adaptive quantization mode using segmentation is at a support level "
766
0
            "only to be available for demos, experimentation, and further development uses and "
767
0
            "should not be used for benchmarking until fully implemented.\n");
768
0
    }
769
770
    // color description
771
492
    if (config->color_primaries == 0 || config->color_primaries == 3 ||
772
492
        (config->color_primaries >= 13 && config->color_primaries <= 21) || config->color_primaries > 22) {
773
0
        SVT_WARN("Value %u for color_primaries is reserved and not recommended for usage.\n", config->color_primaries);
774
0
    }
775
492
    if (config->transfer_characteristics == 0 || config->transfer_characteristics == 3 ||
776
492
        config->transfer_characteristics > 18) {
777
0
        SVT_WARN("Value %u for transfer_characteristics is reserved and not recommended for usage.\n",
778
0
                 config->transfer_characteristics);
779
0
    }
780
781
492
    if (config->matrix_coefficients == 3 || config->matrix_coefficients > 14) {
782
0
        SVT_WARN("Value %u for matrix_coefficients is reserved and not recommended for usage.\n",
783
0
                 config->matrix_coefficients);
784
0
    }
785
786
492
    if (config->chroma_sample_position < EB_CSP_UNKNOWN || config->chroma_sample_position > EB_CSP_COLOCATED) {
787
0
        if (config->chroma_sample_position != EB_CSP_RESERVED) {
788
0
            SVT_ERROR("Chroma sample position %d is unknown.\n", config->chroma_sample_position);
789
0
            return_error = EB_ErrorBadParameter;
790
0
        } else {
791
0
            SVT_WARN(
792
0
                "Value %d for chroma_sample_position is reserved "
793
0
                "and not recommended for usage.\n",
794
0
                config->chroma_sample_position);
795
0
        }
796
0
    }
797
798
492
    if (config->film_grain_denoise_strength > 0 && config->enc_mode > 6) {
799
0
        SVT_WARN(
800
0
            "It is recommended to not use Film Grain for presets greater than 6 as it "
801
0
            "produces a significant compute overhead. This combination should only be used for "
802
0
            "debug purposes.\n");
803
0
    }
804
805
492
    if (config->film_grain_denoise_strength > 50) {
806
0
        SVT_ERROR(
807
0
            "Film grain denoise strength is only supported for values between "
808
0
            "[0,50]\n");
809
0
        return_error = EB_ErrorBadParameter;
810
0
    }
811
812
492
    if (config->film_grain_denoise_apply != 0 && config->film_grain_denoise_apply != 1) {
813
0
        SVT_ERROR("The film grain denoise apply signal can only have a value of 0 or 1\n");
814
0
        return_error = EB_ErrorBadParameter;
815
0
    }
816
817
    // Limit 8K & 16K support
818
492
    if ((uint64_t)(scs->max_input_luma_width * scs->max_input_luma_height) > INPUT_SIZE_4K_TH) {
819
0
        SVT_WARN(
820
0
            "8K and higher resolution support is currently a work-in-progress "
821
0
            "project, and is only available for demos, experimentation, and further development "
822
0
            "uses and should not be used for benchmarking until fully implemented.\n");
823
0
    }
824
825
492
    if (config->pred_structure == LOW_DELAY) {
826
0
        if (config->tune == TUNE_VQ) {
827
0
            SVT_WARN("Tune 0 is not applicable for low-delay, tune will be forced to 1.\n");
828
0
            config->tune = TUNE_PSNR;
829
0
        }
830
831
0
        if (config->superres_mode != 0) {
832
0
            SVT_ERROR("Superres is not supported for low-delay.\n");
833
0
            return_error = EB_ErrorBadParameter;
834
0
        }
835
836
0
        if (config->enable_overlays) {
837
0
            SVT_ERROR("Overlay is not supported for low-delay.\n");
838
0
            return_error = EB_ErrorBadParameter;
839
0
        }
840
0
    }
841
842
492
    if (!config->rtc && config->enc_mode >= ENC_M10) {
843
0
        SVT_WARN("Non-RTC M10+ are meant for automation tooling usage. Visual artifacts may occur otherwise.\n");
844
0
    }
845
846
492
    if (scs->static_config.scene_change_detection) {
847
0
        scs->static_config.scene_change_detection = 0;
848
0
        SVT_WARN(
849
0
            "SVT-AV1 has an integrated mode decision mechanism to handle scene changes and will "
850
0
            "not insert a key frame at scene changes\n");
851
0
    }
852
492
    if ((config->tile_columns > 0 || config->tile_rows > 0)) {
853
492
        SVT_WARN(
854
492
            "If you are using tiles with the intent of increasing the decoder speed, please also "
855
492
            "consider using --fast-decode 1 or 2, especially if the intended decoder is running with "
856
492
            "limited multi-threading capabilities.\n");
857
492
    }
858
492
    if (config->tune == TUNE_VQ && config->fast_decode > 0) {
859
0
        SVT_WARN(
860
0
            "--fast-decode has been developed and optimized with --tune 1. "
861
0
            "Please use it with caution when encoding with --tune 0. You can also consider using "
862
0
            "--tile-columns 1 if you are targeting a high quality encode and a multi-core "
863
0
            "high-performance decoder HW\n");
864
0
    }
865
492
    if (config->enable_qm && config->min_qm_level > config->max_qm_level) {
866
0
        SVT_ERROR("Min quant matrix level must not greater than max quant matrix level\n");
867
0
        return_error = EB_ErrorBadParameter;
868
0
    }
869
492
    if (config->enable_qm && config->min_chroma_qm_level > config->max_chroma_qm_level) {
870
0
        SVT_ERROR("Min chroma quant matrix level must not greater than max chroma quant matrix level\n");
871
0
        return_error = EB_ErrorBadParameter;
872
0
    }
873
492
    if (config->startup_mg_size != 0 && config->startup_mg_size != 2 && config->startup_mg_size != 3 &&
874
0
        config->startup_mg_size != 4) {
875
0
        SVT_ERROR("Startup MG size supported [0, 2, 3, 4]\n");
876
0
        return_error = EB_ErrorBadParameter;
877
0
    }
878
492
    if (config->startup_mg_size > config->hierarchical_levels) {
879
0
        SVT_ERROR("Startup MG size must less than or equal to hierarchical levels\n");
880
0
        return_error = EB_ErrorBadParameter;
881
0
    }
882
492
    if (config->startup_mg_size != 0 && config->rate_control_mode != SVT_AV1_RC_MODE_CQP_OR_CRF) {
883
0
        SVT_ERROR("Startup MG size feature only supports CRF/CQP rate control mode\n");
884
0
        return_error = EB_ErrorBadParameter;
885
0
    }
886
492
    if (config->startup_qp_offset != 0 && config->rate_control_mode != 0) {
887
0
        SVT_ERROR("Startup QP offset only supports CRF/CQP rate control mode\n");
888
0
        return_error = EB_ErrorBadParameter;
889
0
    }
890
891
492
    if (config->variance_boost_strength < 1 || config->variance_boost_strength > 4) {
892
0
        SVT_ERROR("Variance Boost strength must be between 1 and 4\n");
893
0
        return_error = EB_ErrorBadParameter;
894
0
    }
895
896
492
    if (config->variance_octile < 1 || config->variance_octile > 8) {
897
0
        SVT_ERROR("Variance Boost octile must be between 1 and 8\n");
898
0
        return_error = EB_ErrorBadParameter;
899
0
    }
900
901
492
    if (config->tf_strength > 4) {
902
0
        SVT_ERROR("Temporal filtering strength must be between 0 and 4\n");
903
0
        return_error = EB_ErrorBadParameter;
904
0
    }
905
906
492
    if (config->variance_boost_curve > 2) {
907
0
        SVT_ERROR("Variance Boost curve must be between 0 and 2\n");
908
0
        return_error = EB_ErrorBadParameter;
909
0
    }
910
911
492
    if (config->luminance_qp_bias > 100) {
912
0
        SVT_ERROR("Luminance-based QP bias value must be between 0 and 100\n");
913
0
        return_error = EB_ErrorBadParameter;
914
0
    }
915
916
492
    if (config->sharpness > 7 || config->sharpness < -7) {
917
0
        SVT_ERROR("Sharpness level must be between -7 and 7\n");
918
0
        return_error = EB_ErrorBadParameter;
919
0
    }
920
921
492
    if (config->qp_scale_compress_strength > 3) {
922
0
        SVT_ERROR("QP scale compress strength must be between 0 and 3\n");
923
0
        return_error = EB_ErrorBadParameter;
924
0
    }
925
926
492
    if (config->max_tx_size != 32 && config->max_tx_size != 64) {
927
0
        SVT_ERROR("Supported Max TX size values are 32 and 64\n");
928
0
        return_error = EB_ErrorBadParameter;
929
0
    }
930
931
492
    if (config->ac_bias > 8.0 || config->ac_bias < 0.0) {
932
0
        SVT_ERROR("AC bias strength must be between 0.0 and 8.0\n");
933
0
        return_error = EB_ErrorBadParameter;
934
0
    }
935
936
    //User configurable High Bit Depth Mode Decision Setting
937
492
    if (config->hbd_mds < -1 || config->hbd_mds > 2) {
938
0
        SVT_ERROR("hbd-mds must be -1 (preset default), 0, 1, or 2\n");
939
0
        return_error = EB_ErrorBadParameter;
940
0
    }
941
942
492
    if (SVT_EFFECTIVE_BIT_DEPTH(config->encoder_bit_depth) == 8 && (config->hbd_mds == 1 || config->hbd_mds == 2)) {
943
0
        SVT_WARN("Please use 10-bit encoding if you want to take advantage of hbd-mds 1 and 2.\n");
944
0
        SVT_ERROR("Full high bit depth and hybrid 8/10 mode decision are not supported when encoder bit depth is 8\n");
945
0
        return_error = EB_ErrorBadParameter;
946
0
    }
947
948
492
    return return_error;
949
492
}
950
951
/**********************************
952
Set Default Library Params
953
**********************************/
954
492
EbErrorType svt_av1_set_default_params(EbSvtAv1EncConfiguration* config_ptr) {
955
492
    EbErrorType return_error = EB_ErrorNone;
956
957
492
    if (!config_ptr) {
958
0
        SVT_ERROR("The EbSvtAv1EncConfiguration structure is empty!\n");
959
0
        return EB_ErrorBadParameter;
960
0
    }
961
492
    config_ptr->frame_rate_numerator     = 60000;
962
492
    config_ptr->frame_rate_denominator   = 1000;
963
492
    config_ptr->encoder_bit_depth        = 8;
964
492
    config_ptr->source_width             = 0;
965
492
    config_ptr->source_height            = 0;
966
492
    config_ptr->forced_max_frame_width   = 0;
967
492
    config_ptr->forced_max_frame_height  = 0;
968
492
    config_ptr->stat_report              = 0;
969
492
    config_ptr->tile_rows                = DEFAULT;
970
492
    config_ptr->tile_columns             = DEFAULT;
971
492
    config_ptr->qp                       = DEFAULT_QP;
972
492
    config_ptr->use_qp_file              = false;
973
492
    config_ptr->use_fixed_qindex_offsets = 0;
974
492
    memset(config_ptr->qindex_offsets, 0, sizeof(config_ptr->qindex_offsets));
975
492
    config_ptr->key_frame_chroma_qindex_offset = 0;
976
492
    config_ptr->key_frame_qindex_offset        = 0;
977
492
    memset(config_ptr->chroma_qindex_offsets, 0, sizeof(config_ptr->chroma_qindex_offsets));
978
492
    config_ptr->luma_y_dc_qindex_offset   = 0;
979
492
    config_ptr->chroma_u_dc_qindex_offset = 0;
980
492
    config_ptr->chroma_u_ac_qindex_offset = 0;
981
492
    config_ptr->chroma_v_dc_qindex_offset = 0;
982
492
    config_ptr->chroma_v_ac_qindex_offset = 0;
983
984
3.93k
    for (int i = 0; i < SVT_AV1_FRAME_UPDATE_TYPES; i++) {
985
3.44k
        config_ptr->lambda_scale_factors[i] = 128;
986
3.44k
    }
987
988
492
    config_ptr->scene_change_detection       = 0;
989
492
    config_ptr->rate_control_mode            = SVT_AV1_RC_MODE_CQP_OR_CRF;
990
492
    config_ptr->look_ahead_distance          = (uint32_t)~0;
991
492
    config_ptr->target_bit_rate              = DEFAULT_TBR;
992
492
    config_ptr->max_bit_rate                 = 0;
993
492
    config_ptr->max_qp_allowed               = 63;
994
492
    config_ptr->min_qp_allowed               = MIN_QP_AUTO;
995
492
    config_ptr->aq_mode                      = 2;
996
492
    config_ptr->enc_mode                     = ENC_M8;
997
492
    config_ptr->intra_period_length          = -2;
998
492
    config_ptr->multiply_keyint              = false;
999
492
    config_ptr->intra_refresh_type           = 2;
1000
492
    config_ptr->hierarchical_levels          = HIERARCHICAL_LEVELS_AUTO;
1001
492
    config_ptr->pred_structure               = RANDOM_ACCESS;
1002
492
    config_ptr->enable_dlf_flag              = 1;
1003
492
    config_ptr->cdef_level                   = DEFAULT;
1004
492
    config_ptr->enable_restoration_filtering = DEFAULT;
1005
492
    config_ptr->enable_mfmv                  = DEFAULT;
1006
492
    config_ptr->enable_dg                    = 1;
1007
492
    config_ptr->fast_decode                  = 0;
1008
492
    config_ptr->encoder_color_format         = EB_YUV420;
1009
492
    config_ptr->rtc                          = 0;
1010
    // Rate control options
1011
    // Set the default value toward more flexible rate allocation
1012
492
    config_ptr->vbr_min_section_pct      = 0;
1013
492
    config_ptr->vbr_max_section_pct      = 2000;
1014
492
    config_ptr->under_shoot_pct          = (uint32_t)DEFAULT;
1015
492
    config_ptr->over_shoot_pct           = (uint32_t)DEFAULT;
1016
492
    config_ptr->mbr_over_shoot_pct       = 50;
1017
492
    config_ptr->max_intra_bitrate_pct    = 300;
1018
492
    config_ptr->max_inter_bitrate_pct    = 0;
1019
492
    config_ptr->gop_constraint_rc        = 0;
1020
492
    config_ptr->maximum_buffer_size_ms   = 1000; // default settings for CBR
1021
492
    config_ptr->starting_buffer_level_ms = 600; // default settings for CBR
1022
492
    config_ptr->optimal_buffer_level_ms  = 600; // default settings for CBR
1023
492
    config_ptr->recode_loop              = ALLOW_RECODE_DEFAULT;
1024
492
    config_ptr->screen_content_mode      = 2;
1025
492
    config_ptr->enable_intrabc           = true;
1026
1027
    // Annex A parameters
1028
492
    config_ptr->profile = 0;
1029
492
    config_ptr->tier    = 0;
1030
492
    config_ptr->level   = 0;
1031
1032
    // Film grain denoising
1033
492
    config_ptr->film_grain_denoise_strength = 0;
1034
492
    config_ptr->film_grain_denoise_apply    = 0;
1035
1036
    // CPU Flags
1037
492
    config_ptr->use_cpu_flags = EB_CPU_FLAGS_ALL;
1038
1039
    // Channel info
1040
492
    config_ptr->level_of_parallelism = 0;
1041
1042
    // Debug info
1043
492
    config_ptr->recon_enabled = 0;
1044
1045
    // Alt-Ref default values
1046
492
    config_ptr->enable_tf       = 1;
1047
492
    config_ptr->enable_tf_key   = 1;
1048
492
    config_ptr->enable_overlays = false;
1049
492
    config_ptr->tune            = 1;
1050
    // Super-resolution default values
1051
492
    config_ptr->superres_mode      = SUPERRES_NONE;
1052
492
    config_ptr->superres_denom     = SCALE_NUMERATOR;
1053
492
    config_ptr->superres_kf_denom  = SCALE_NUMERATOR;
1054
492
    config_ptr->superres_qthres    = 43; // random threshold, change
1055
492
    config_ptr->superres_kf_qthres = 43; // random threshold, change
1056
1057
    // Reference Scaling default values
1058
492
    config_ptr->resize_mode     = RESIZE_NONE;
1059
492
    config_ptr->resize_denom    = SCALE_NUMERATOR;
1060
492
    config_ptr->resize_kf_denom = SCALE_NUMERATOR;
1061
1062
    // Color description default values
1063
492
    config_ptr->color_primaries          = 2;
1064
492
    config_ptr->transfer_characteristics = 2;
1065
492
    config_ptr->matrix_coefficients      = 2;
1066
492
    config_ptr->color_range              = EB_CR_STUDIO_RANGE;
1067
492
    config_ptr->chroma_sample_position   = EB_CSP_UNKNOWN;
1068
492
    config_ptr->pass                     = 0;
1069
492
    memset(&config_ptr->mastering_display, 0, sizeof(config_ptr->mastering_display));
1070
492
    memset(&config_ptr->content_light_level, 0, sizeof(config_ptr->content_light_level));
1071
1072
    // Switch frame default values
1073
492
    config_ptr->sframe_dist      = 0;
1074
492
    config_ptr->sframe_mode      = SFRAME_NEAREST_BASE;
1075
492
    config_ptr->force_key_frames = 0;
1076
1077
    // Quant Matrices (QM)
1078
492
    config_ptr->enable_qm           = 0;
1079
492
    config_ptr->min_qm_level        = 8;
1080
492
    config_ptr->max_qm_level        = 15;
1081
492
    config_ptr->min_chroma_qm_level = 8;
1082
492
    config_ptr->max_chroma_qm_level = 15;
1083
1084
492
    config_ptr->startup_mg_size                   = 0;
1085
492
    config_ptr->startup_qp_offset                 = 0;
1086
492
    config_ptr->frame_scale_evts.evt_num          = 0;
1087
492
    config_ptr->frame_scale_evts.resize_denoms    = NULL;
1088
492
    config_ptr->frame_scale_evts.resize_kf_denoms = NULL;
1089
492
    config_ptr->frame_scale_evts.start_frame_nums = NULL;
1090
492
    config_ptr->enable_roi_map                    = false;
1091
492
    config_ptr->fgs_table                         = NULL;
1092
492
    config_ptr->enable_variance_boost             = false;
1093
492
    config_ptr->variance_boost_strength           = 2;
1094
492
    config_ptr->variance_octile                   = 5;
1095
492
    config_ptr->tf_strength                       = 3;
1096
492
    config_ptr->variance_boost_curve              = 0;
1097
492
    config_ptr->luminance_qp_bias                 = 0;
1098
492
    config_ptr->sharpness                         = 0;
1099
492
    config_ptr->lossless                          = false;
1100
492
    config_ptr->avif                              = false;
1101
492
    config_ptr->qp_scale_compress_strength        = 0;
1102
492
    config_ptr->sframe_posi.sframe_num            = 0;
1103
492
    config_ptr->sframe_posi.sframe_posis          = NULL;
1104
492
    config_ptr->sframe_posi.sframe_qp_num         = 0;
1105
492
    config_ptr->sframe_posi.sframe_qps            = NULL;
1106
492
    config_ptr->sframe_posi.sframe_qp_offsets     = NULL;
1107
492
    config_ptr->sframe_qp                         = 0;
1108
492
    config_ptr->sframe_qp_offset                  = 0;
1109
492
    config_ptr->adaptive_film_grain               = true;
1110
492
    config_ptr->max_tx_size                       = 64;
1111
492
    config_ptr->extended_crf_qindex_offset        = 0;
1112
492
    config_ptr->ac_bias                           = 0.0;
1113
492
    config_ptr->hbd_mds                           = DEFAULT;
1114
1115
    // Ref-frame management disabled by default → legacy bit-exact behavior
1116
    // and no extra ref-buffer memory allocated.
1117
492
    config_ptr->max_managed_refs = 0;
1118
1119
    // MG size fixed for the session by default → legacy pool sizing.
1120
492
    config_ptr->max_hierarchical_levels = 0;
1121
1122
492
    config_ptr->max_allowed_consecutive_frames_skips = 0;
1123
1124
492
    return return_error;
1125
492
}
1126
1127
492
static const char* tier_to_str(unsigned in) {
1128
492
    switch (in) {
1129
492
    case 0:
1130
492
        return "Main";
1131
0
    case 1:
1132
0
        return "High";
1133
0
    default: {
1134
0
        static char ret[11];
1135
0
        snprintf(ret, sizeof(ret), "%u", in);
1136
0
        return ret;
1137
0
    }
1138
492
    }
1139
492
}
1140
1141
492
static const char* level_to_str(unsigned in) {
1142
492
    if (!in) {
1143
492
        return "(auto)";
1144
492
    }
1145
0
    static char ret[313];
1146
0
    snprintf(ret, 313, "%.1f", in / 10.0);
1147
0
    return ret;
1148
492
}
1149
1150
283
static double get_extended_crf(EbSvtAv1EncConfiguration* config_ptr) {
1151
283
    return (double)config_ptr->qp + (double)config_ptr->extended_crf_qindex_offset / 4;
1152
283
}
1153
1154
//#define DEBUG_BUFFERS
1155
492
void svt_av1_print_lib_params(SequenceControlSet* scs) {
1156
492
    EbSvtAv1EncConfiguration* config = &scs->static_config;
1157
1158
492
    SVT_INFO("-------------------------------------------\n");
1159
492
    if (config->pass == ENC_FIRST_PASS) {
1160
0
        SVT_INFO("SVT [config]: preset \t\t\t\t\t\t\t: Pass 1\n");
1161
492
    } else {
1162
492
        SVT_INFO("SVT [config]: %s\ttier %s\tlevel %s\n",
1163
492
                 config->profile == MAIN_PROFILE               ? "main profile"
1164
492
                     : config->profile == HIGH_PROFILE         ? "high profile"
1165
492
                     : config->profile == PROFESSIONAL_PROFILE ? "professional profile"
1166
492
                                                               : "Unknown profile",
1167
492
                 tier_to_str(config->tier),
1168
492
                 level_to_str(config->level));
1169
492
        SVT_INFO(
1170
492
            "SVT [config]: width / height / fps numerator / fps denominator \t\t: %d / %d / %d / "
1171
492
            "%d\n",
1172
492
            config->source_width,
1173
492
            config->source_height,
1174
492
            config->frame_rate_numerator,
1175
492
            config->frame_rate_denominator);
1176
492
        SVT_INFO(
1177
492
            "SVT [config]: bit-depth / color format \t\t\t\t\t: %d / "
1178
492
            "%s\n",
1179
492
            config->encoder_bit_depth,
1180
492
            config->encoder_color_format == EB_YUV400       ? "YUV400"
1181
492
                : config->encoder_color_format == EB_YUV420 ? "YUV420"
1182
492
                : config->encoder_color_format == EB_YUV422 ? "YUV422"
1183
492
                : config->encoder_color_format == EB_YUV444 ? "YUV444"
1184
492
                                                            : "Unknown color format");
1185
1186
492
        SVT_INFO("SVT [config]: preset / tune / pred struct \t\t\t\t\t: %d / %s / %s\n",
1187
492
                 config->enc_mode,
1188
492
                 config->tune == TUNE_VQ            ? "VQ"
1189
492
                     : config->tune == TUNE_PSNR    ? "PSNR"
1190
492
                     : config->tune == TUNE_SSIM    ? "SSIM"
1191
492
                     : config->tune == TUNE_MS_SSIM ? "MS_SSIM"
1192
492
                     : config->tune == TUNE_VMAF    ? "VMAF"
1193
492
                                                    : "IQ",
1194
492
                 config->pred_structure == LOW_DELAY           ? "low delay"
1195
492
                     : config->pred_structure == RANDOM_ACCESS ? "random access"
1196
492
                     : config->pred_structure == ALL_INTRA     ? "all intra"
1197
492
                                                               : "Unknown pred structure");
1198
492
        SVT_INFO(
1199
492
            "SVT [config]: gop size / mini-gop size / key-frame type \t\t\t: "
1200
492
            "%d / %d / %s\n",
1201
492
            config->intra_period_length + 1,
1202
492
            (1 << config->hierarchical_levels),
1203
492
            config->intra_refresh_type == SVT_AV1_FWDKF_REFRESH    ? "FWD key frame"
1204
492
                : config->intra_refresh_type == SVT_AV1_KF_REFRESH ? "key frame"
1205
492
                                                                   : "Unknown key frame type");
1206
492
        if (config->lossless) {
1207
209
            SVT_INFO("SVT [config]: BRC mode\t\t\t\t\t\t\t: Lossless Coding \n");
1208
283
        } else {
1209
283
            switch (config->rate_control_mode) {
1210
283
            case SVT_AV1_RC_MODE_CQP_OR_CRF:
1211
283
                if (config->max_bit_rate) {
1212
0
                    SVT_INFO(
1213
0
                        "SVT [config]: BRC mode / %s / max bitrate (kbps)\t\t\t: %s / %.2f / "
1214
0
                        "%d\n",
1215
0
                        scs->tpl || scs->static_config.enable_variance_boost ? "rate factor" : "CQP Assignment",
1216
0
                        scs->tpl || scs->static_config.enable_variance_boost ? "capped CRF" : "CQP",
1217
0
                        get_extended_crf(config),
1218
0
                        (int)config->max_bit_rate / 1000);
1219
283
                } else {
1220
283
                    SVT_INFO("SVT [config]: BRC mode / %s \t\t\t\t\t: %s / %.2f \n",
1221
283
                             scs->tpl || scs->static_config.enable_variance_boost ? "rate factor" : "CQP Assignment",
1222
283
                             scs->tpl || scs->static_config.enable_variance_boost ? "CRF" : "CQP",
1223
283
                             get_extended_crf(config));
1224
283
                }
1225
283
                break;
1226
0
            case SVT_AV1_RC_MODE_VBR:
1227
0
                SVT_INFO("SVT [config]: BRC mode / target bitrate (kbps)\t\t\t\t: VBR / %d \n",
1228
0
                         (int)config->target_bit_rate / 1000);
1229
0
                break;
1230
0
            case SVT_AV1_RC_MODE_CBR:
1231
0
                SVT_INFO(
1232
0
                    "SVT [config]: BRC mode / target bitrate (kbps)\t\t\t\t: CBR "
1233
0
                    "/ %d\n",
1234
0
                    (int)config->target_bit_rate / 1000);
1235
0
                break;
1236
283
            }
1237
283
        }
1238
492
        if (config->rate_control_mode != SVT_AV1_RC_MODE_CBR) {
1239
492
            if (!config->enable_variance_boost) {
1240
492
                SVT_INFO("SVT [config]: AQ mode / Variance Boost \t\t\t\t\t: %d / %d\n",
1241
492
                         config->aq_mode,
1242
492
                         config->enable_variance_boost);
1243
492
            } else {
1244
0
                SVT_INFO("SVT [config]: AQ mode / Variance Boost strength / octile / curve \t\t: %d / %d / %d / %d\n",
1245
0
                         config->aq_mode,
1246
0
                         config->variance_boost_strength,
1247
0
                         config->variance_octile,
1248
0
                         config->variance_boost_curve);
1249
0
            }
1250
492
        }
1251
1252
492
        if (config->film_grain_denoise_strength != 0) {
1253
0
            if (config->adaptive_film_grain) {
1254
0
                SVT_INFO(
1255
0
                    "SVT [config]: film grain synth / denoising / level / adaptive blocksize \t: %d / %d / %d / True\n",
1256
0
                    1,
1257
0
                    config->film_grain_denoise_apply,
1258
0
                    config->film_grain_denoise_strength);
1259
0
            } else {
1260
0
                SVT_INFO(
1261
0
                    "SVT [config]: film grain synth / denoising / level / adaptive blocksize \t: %d / %d / %d / "
1262
0
                    "False\n",
1263
0
                    1,
1264
0
                    config->film_grain_denoise_apply,
1265
0
                    config->film_grain_denoise_strength);
1266
0
            }
1267
0
        }
1268
492
        SVT_INFO("SVT [config]: sharpness / luminance-based QP bias \t\t\t\t: %d / %d\n",
1269
492
                 config->sharpness,
1270
492
                 config->luminance_qp_bias);
1271
1272
492
        switch (config->enable_tf) {
1273
0
        case 1:
1274
0
            if (config->tf_strength != 3) {
1275
0
                SVT_INFO("SVT [config]: temporal filtering strength \t\t\t\t\t: %d\n", config->tf_strength);
1276
0
            }
1277
0
            break;
1278
0
        case 2:
1279
0
            SVT_INFO("SVT [config]: temporal filtering strength \t\t\t\t\t: auto\n");
1280
0
            break;
1281
492
        default:
1282
492
            break;
1283
492
        }
1284
1285
492
        SVT_INFO("SVT [config]: QP scale compress strength \t\t\t\t\t: %d\n", config->qp_scale_compress_strength);
1286
1287
492
        if (config->ac_bias) {
1288
0
            SVT_INFO("SVT [config]: AC Bias Strength \t\t\t\t\t\t: %.2f\n", config->ac_bias);
1289
0
        }
1290
1291
492
        if (config->hbd_mds != DEFAULT) {
1292
0
            SVT_INFO("SVT [config]: High Bit Depth Mode Decision setting \t\t\t\t\t: %d\n", config->hbd_mds);
1293
0
        }
1294
492
    }
1295
#if DEBUG_BUFFERS
1296
    SVT_INFO("SVT [config]: INPUT / OUTPUT \t\t\t\t\t\t\t: %d / %d\n",
1297
             scs->input_buffer_fifo_init_count,
1298
             scs->output_stream_buffer_fifo_init_count);
1299
    SVT_INFO("SVT [config]: CPCS / PAREF / REF / ME\t\t\t\t\t\t: %d / %d / %d / %d\n",
1300
             scs->picture_control_set_pool_init_count_child,
1301
             scs->pa_reference_picture_buffer_init_count,
1302
             scs->reference_picture_buffer_init_count,
1303
             scs->me_pool_init_count);
1304
    SVT_INFO("SVT [config]: ME_SEG_W / ME_SEG_H \t\t\t: %u / %u\n",
1305
             scs->me_segment_col_count_array,
1306
             scs->me_segment_row_count_array);
1307
    SVT_INFO("SVT [config]: ENC_DEC_SEG_W / ENC_DEC_SEG_H \t\t\t: %u / %u\n",
1308
             scs->enc_dec_segment_col_count_array,
1309
             scs->enc_dec_segment_row_count_array);
1310
    SVT_INFO(
1311
        "SVT [config]: PA_P / ME_P / SBO_P / MDC_P / ED_P / EC_P \t\t\t: %d / %d / %d / %d / %d / "
1312
        "%d\n",
1313
        scs->picture_analysis_process_init_count,
1314
        scs->motion_estimation_process_init_count,
1315
        scs->source_based_operations_process_init_count,
1316
        scs->mode_decision_configuration_process_init_count,
1317
        scs->enc_dec_process_init_count,
1318
        scs->entropy_coding_process_init_count);
1319
    SVT_INFO("SVT [config]: DLF_P / CDEF_P / REST_P \t\t\t\t\t\t: %d / %d / %d\n",
1320
             scs->dlf_process_init_count,
1321
             scs->cdef_process_init_count,
1322
             scs->rest_process_init_count);
1323
#endif
1324
492
    SVT_INFO("-------------------------------------------\n");
1325
1326
492
    fflush(stdout);
1327
492
}
1328
1329
/**********************************
1330
* Parse Single Parameter
1331
**********************************/
1332
1333
0
static EbErrorType str_to_int64(const char* nptr, int64_t* out, char** nextptr) {
1334
0
    char*   endptr;
1335
0
    int64_t val;
1336
1337
0
    val = strtoll(nptr, &endptr, 0);
1338
1339
0
    if (endptr == nptr || (!nextptr && *endptr)) {
1340
0
        return EB_ErrorBadParameter;
1341
0
    }
1342
1343
0
    *out = val;
1344
0
    if (nextptr) {
1345
0
        *nextptr = endptr;
1346
0
    }
1347
0
    return EB_ErrorNone;
1348
0
}
1349
1350
0
static EbErrorType str_to_int(const char* nptr, int32_t* out, char** nextptr) {
1351
0
    char*   endptr;
1352
0
    int32_t val;
1353
1354
0
    val = strtol(nptr, &endptr, 0);
1355
1356
0
    if (endptr == nptr || (!nextptr && *endptr)) {
1357
0
        return EB_ErrorBadParameter;
1358
0
    }
1359
1360
0
    *out = val;
1361
0
    if (nextptr) {
1362
0
        *nextptr = endptr;
1363
0
    }
1364
0
    return EB_ErrorNone;
1365
0
}
1366
1367
0
static EbErrorType str_to_uint64(const char* nptr, uint64_t* out, char** nextptr) {
1368
0
    char*    endptr;
1369
0
    uint64_t val;
1370
1371
0
    if (strtoll(nptr, NULL, 0) < 0) {
1372
0
        return EB_ErrorBadParameter;
1373
0
    }
1374
1375
0
    val = strtoull(nptr, &endptr, 0);
1376
1377
0
    if (endptr == nptr || (!nextptr && *endptr)) {
1378
0
        return EB_ErrorBadParameter;
1379
0
    }
1380
1381
0
    *out = val;
1382
0
    if (nextptr) {
1383
0
        *nextptr = endptr;
1384
0
    }
1385
0
    return EB_ErrorNone;
1386
0
}
1387
1388
0
static EbErrorType str_to_uint(const char* nptr, uint32_t* out, char** nextptr) {
1389
0
    char*    endptr;
1390
0
    uint32_t val;
1391
1392
0
    if (strtol(nptr, NULL, 0) < 0) {
1393
0
        return EB_ErrorBadParameter;
1394
0
    }
1395
1396
0
    val = strtoul(nptr, &endptr, 0);
1397
1398
0
    if (endptr == nptr || (!nextptr && *endptr)) {
1399
0
        return EB_ErrorBadParameter;
1400
0
    }
1401
1402
0
    *out = val;
1403
0
    if (nextptr) {
1404
0
        *nextptr = endptr;
1405
0
    }
1406
0
    return EB_ErrorNone;
1407
0
}
1408
1409
0
static EbErrorType str_to_int8(const char* nptr, int8_t* out, char** nextptr) {
1410
0
    char*   endptr;
1411
0
    int32_t val;
1412
1413
0
    val = strtol(nptr, &endptr, 0);
1414
1415
0
    if (endptr == nptr || (!nextptr && *endptr)) {
1416
0
        return EB_ErrorBadParameter;
1417
0
    }
1418
1419
    // check for the range
1420
0
    if (val < INT8_MIN || val > INT8_MAX) {
1421
0
        return EB_ErrorBadParameter;
1422
0
    }
1423
1424
0
    *out = (int8_t)val;
1425
0
    if (nextptr) {
1426
0
        *nextptr = endptr;
1427
0
    }
1428
0
    return EB_ErrorNone;
1429
0
}
1430
1431
0
static EbErrorType str_to_uint8(const char* nptr, uint8_t* out, char** nextptr) {
1432
0
    char*    endptr;
1433
0
    uint32_t val;
1434
1435
0
    if (strtol(nptr, NULL, 0) < 0) {
1436
0
        return EB_ErrorBadParameter;
1437
0
    }
1438
1439
0
    val = strtoul(nptr, &endptr, 0);
1440
1441
0
    if (endptr == nptr || (!nextptr && *endptr)) {
1442
0
        return EB_ErrorBadParameter;
1443
0
    }
1444
1445
    // check for the range
1446
0
    if (val > UINT8_MAX) {
1447
0
        return EB_ErrorBadParameter;
1448
0
    }
1449
1450
0
    *out = (uint8_t)val;
1451
0
    if (nextptr) {
1452
0
        *nextptr = endptr;
1453
0
    }
1454
0
    return EB_ErrorNone;
1455
0
}
1456
1457
0
#define str_to_int32 str_to_int
1458
0
#define str_to_uint32 str_to_uint
1459
1460
0
static EbErrorType str_to_double(const char* nptr, double* out, char** nextptr) {
1461
0
    char*  endptr;
1462
0
    double val;
1463
1464
0
    val = strtod(nptr, &endptr);
1465
1466
0
    if (endptr == nptr || (!nextptr && *endptr)) {
1467
0
        return EB_ErrorBadParameter;
1468
0
    }
1469
1470
0
    *out = val;
1471
0
    if (nextptr) {
1472
0
        *nextptr = endptr;
1473
0
    }
1474
0
    return EB_ErrorNone;
1475
0
}
1476
1477
//assume the input list of values are in the format of "[v1,v2,v3,...]"
1478
#define PARSE_LIST(list_type)                                                                    \
1479
0
    static EbErrorType parse_list_##list_type(const char* nptr, list_type##_t* list, size_t n) { \
1480
0
        const char* ptr = nptr;                                                                  \
1481
0
        char*       endptr;                                                                      \
1482
0
        size_t      i = 0;                                                                       \
1483
0
        memset(list, 0, n * sizeof(*list));                                                      \
1484
0
        while (*ptr) {                                                                           \
1485
0
            if (*ptr == '[' || *ptr == ']') {                                                    \
1486
0
                ptr++;                                                                           \
1487
0
                continue;                                                                        \
1488
0
            }                                                                                    \
1489
0
            list_type##_t rawval;                                                                \
1490
0
            EbErrorType   err = str_to_##list_type(ptr, &rawval, &endptr);                       \
1491
0
            if (err != EB_ErrorNone)                                                             \
1492
0
                return err;                                                                      \
1493
0
            if (i >= n) {                                                                        \
1494
0
                return EB_ErrorBadParameter;                                                     \
1495
0
            } else if (*endptr == ',' || *endptr == ']') {                                       \
1496
0
                endptr++;                                                                        \
1497
0
            } else if (*endptr) {                                                                \
1498
0
                return EB_ErrorBadParameter;                                                     \
1499
0
            }                                                                                    \
1500
0
            list[i++] = rawval;                                                                  \
1501
0
            ptr       = endptr;                                                                  \
1502
0
        }                                                                                        \
1503
0
        return EB_ErrorNone;                                                                     \
1504
0
    }
Unexecuted instantiation: enc_settings.c:parse_list_int32
Unexecuted instantiation: enc_settings.c:parse_list_uint64
Unexecuted instantiation: enc_settings.c:parse_list_uint32
Unexecuted instantiation: enc_settings.c:parse_list_uint8
Unexecuted instantiation: enc_settings.c:parse_list_int8
1505
PARSE_LIST(int8)
1506
PARSE_LIST(uint8)
1507
PARSE_LIST(int32)
1508
PARSE_LIST(uint32)
1509
PARSE_LIST(uint64)
1510
1511
0
static uint32_t count_params(const char* nptr) {
1512
0
    const char* ptr = nptr;
1513
0
    char*       endptr;
1514
0
    uint32_t    i = 0;
1515
0
    while (*ptr) {
1516
0
        if (*ptr == '[' || *ptr == ']') {
1517
0
            ptr++;
1518
0
            continue;
1519
0
        }
1520
1521
0
        strtoll(ptr, &endptr, 10);
1522
0
        if (*endptr == ',' || *endptr == ']') {
1523
0
            endptr++;
1524
0
        } else if (*endptr) {
1525
0
            return i;
1526
0
        }
1527
0
        i++;
1528
0
        ptr = endptr;
1529
0
    }
1530
0
    return i;
1531
0
}
1532
1533
#ifdef _MSC_VER
1534
#define strcasecmp _stricmp
1535
#endif
1536
0
static EbErrorType str_to_bool(const char* nptr, bool* out) {
1537
0
    bool val;
1538
0
    if (!strcmp(nptr, "1") || !strcasecmp(nptr, "true") || !strcasecmp(nptr, "yes")) {
1539
0
        val = true;
1540
0
    } else if (!strcmp(nptr, "0") || !strcasecmp(nptr, "false") || !strcasecmp(nptr, "no")) {
1541
0
        val = false;
1542
0
    } else {
1543
0
        return EB_ErrorBadParameter;
1544
0
    }
1545
1546
0
    *out = val;
1547
0
    return EB_ErrorNone;
1548
0
}
1549
1550
0
static EbErrorType str_to_crf(const char* nptr, EbSvtAv1EncConfiguration* config_struct) {
1551
0
    double      crf;
1552
0
    EbErrorType return_error;
1553
1554
0
    return_error = str_to_double(nptr, &crf, NULL);
1555
1556
0
    if (return_error == EB_ErrorBadParameter) {
1557
0
        return return_error;
1558
0
    }
1559
0
    if (crf < 0) {
1560
0
        return EB_ErrorBadParameter;
1561
0
    }
1562
1563
0
    uint32_t extended_q_index           = (uint32_t)(crf * 4);
1564
0
    uint32_t qp                         = AOMMIN(MAX_QP_VALUE, (uint32_t)crf);
1565
0
    uint32_t extended_crf_qindex_offset = extended_q_index - qp * 4;
1566
1567
0
    config_struct->qp                         = qp;
1568
0
    config_struct->rate_control_mode          = SVT_AV1_RC_MODE_CQP_OR_CRF;
1569
0
    config_struct->aq_mode                    = 2;
1570
0
    config_struct->extended_crf_qindex_offset = extended_crf_qindex_offset;
1571
1572
0
    return EB_ErrorNone;
1573
0
}
1574
1575
0
static EbErrorType str_to_cqp(const char* nptr, EbSvtAv1EncConfiguration* config_struct) {
1576
0
    double      cqp;
1577
0
    EbErrorType return_error;
1578
1579
0
    return_error = str_to_double(nptr, &cqp, NULL);
1580
1581
0
    if (return_error == EB_ErrorBadParameter) {
1582
0
        return return_error;
1583
0
    }
1584
0
    if (cqp < 0) {
1585
0
        return EB_ErrorBadParameter;
1586
0
    }
1587
1588
0
    uint32_t extended_q_index           = (uint32_t)(cqp * 4);
1589
0
    uint32_t qp                         = AOMMIN(MAX_QP_VALUE, (uint32_t)cqp);
1590
0
    uint32_t extended_crf_qindex_offset = extended_q_index - qp * 4;
1591
1592
0
    config_struct->qp                         = qp;
1593
0
    config_struct->rate_control_mode          = SVT_AV1_RC_MODE_CQP_OR_CRF;
1594
0
    config_struct->aq_mode                    = 0;
1595
0
    config_struct->extended_crf_qindex_offset = extended_crf_qindex_offset;
1596
1597
0
    return EB_ErrorNone;
1598
0
}
1599
1600
0
static EbErrorType str_to_keyint(const char* nptr, int32_t* out, bool* multi) {
1601
0
    char*      suff;
1602
0
    const long keyint = strtol(nptr, &suff, 0);
1603
1604
0
    if (keyint > INT32_MAX || keyint < -2) {
1605
0
        return EB_ErrorBadParameter;
1606
0
    }
1607
1608
0
    switch (*suff) {
1609
0
    case 's':
1610
        // signal we need to multiply keyint * frame_rate
1611
0
        *multi = true;
1612
0
        *out   = keyint;
1613
0
        break;
1614
0
    case '\0':
1615
0
        *multi = false;
1616
0
        *out   = keyint < 0 ? keyint : keyint - 1;
1617
0
        break;
1618
0
    default:
1619
        // else leave as untouched, we have an invalid keyint
1620
0
        SVT_ERROR("Invalid keyint value: %s\n", nptr);
1621
0
        return EB_ErrorBadParameter;
1622
0
    }
1623
1624
0
    return EB_ErrorNone;
1625
0
}
1626
1627
0
static EbErrorType str_to_bitrate(const char* nptr, uint32_t* out) {
1628
0
    char*        suff;
1629
0
    const double bitrate = strtod(nptr, &suff);
1630
1631
0
    if (bitrate < 0 || bitrate > UINT32_MAX) {
1632
0
        SVT_ERROR("Invalid bitrate value: %s\n", nptr);
1633
0
        return EB_ErrorBadParameter;
1634
0
    }
1635
1636
0
    switch (*suff) {
1637
0
    case 'b':
1638
0
    case 'B':
1639
0
        *out = (uint32_t)bitrate;
1640
0
        break;
1641
0
    case '\0':
1642
0
    case 'k':
1643
0
    case 'K':
1644
0
        *out = (uint32_t)(1000 * bitrate);
1645
0
        break;
1646
0
    case 'm':
1647
0
    case 'M':
1648
0
        *out = (uint32_t)(1000000 * bitrate);
1649
0
        break;
1650
0
    default:
1651
0
        return EB_ErrorBadParameter;
1652
0
    }
1653
0
    if (*out > 100000000) {
1654
0
        *out = 100000000;
1655
0
        SVT_WARN("Bitrate value: %s has been set to 100000000\n", nptr);
1656
0
    }
1657
0
    return EB_ErrorNone;
1658
0
}
1659
1660
0
static EbErrorType str_to_profile(const char* nptr, EbAv1SeqProfile* out) {
1661
0
    const struct {
1662
0
        const char*     name;
1663
0
        EbAv1SeqProfile profile;
1664
0
    } profiles[] = {
1665
0
        {"main", MAIN_PROFILE},
1666
0
        {"high", HIGH_PROFILE},
1667
0
        {"professional", PROFESSIONAL_PROFILE},
1668
0
    };
1669
1670
0
    const size_t profiles_size = sizeof(profiles) / sizeof(profiles[0]);
1671
1672
0
    for (size_t i = 0; i < profiles_size; i++) {
1673
0
        if (!strcmp(nptr, profiles[i].name)) {
1674
0
            *out = profiles[i].profile;
1675
0
            return EB_ErrorNone;
1676
0
        }
1677
0
    }
1678
1679
0
    return EB_ErrorBadParameter;
1680
0
}
1681
1682
0
static EbErrorType str_to_color_fmt(const char* nptr, EbColorFormat* out) {
1683
0
    const struct {
1684
0
        const char*   name;
1685
0
        EbColorFormat fmt;
1686
0
    } color_formats[] = {
1687
0
        {"mono", EB_YUV400},
1688
0
        {"400", EB_YUV400},
1689
0
        {"420", EB_YUV420},
1690
0
        {"422", EB_YUV422},
1691
0
        {"444", EB_YUV444},
1692
0
    };
1693
1694
0
    const size_t color_format_size = sizeof(color_formats) / sizeof(color_formats[0]);
1695
1696
0
    for (size_t i = 0; i < color_format_size; i++) {
1697
0
        if (!strcmp(nptr, color_formats[i].name)) {
1698
0
            *out = color_formats[i].fmt;
1699
0
            return EB_ErrorNone;
1700
0
        }
1701
0
    }
1702
1703
0
    return EB_ErrorBadParameter;
1704
0
}
1705
1706
0
static EbErrorType str_to_intra_rt(const char* nptr, SvtAv1IntraRefreshType* out) {
1707
0
    const struct {
1708
0
        const char*            name;
1709
0
        SvtAv1IntraRefreshType type;
1710
0
    } refresh_types[] = {
1711
0
        {"cra", SVT_AV1_FWDKF_REFRESH},
1712
0
        {"fwdkf", SVT_AV1_FWDKF_REFRESH},
1713
0
        {"idr", SVT_AV1_KF_REFRESH},
1714
0
        {"kf", SVT_AV1_KF_REFRESH},
1715
0
    };
1716
1717
0
    const size_t refresh_type_size = sizeof(refresh_types) / sizeof(refresh_types[0]);
1718
1719
0
    for (size_t i = 0; i < refresh_type_size; i++) {
1720
0
        if (!strcmp(nptr, refresh_types[i].name)) {
1721
0
            *out = refresh_types[i].type;
1722
0
            return EB_ErrorNone;
1723
0
        }
1724
0
    }
1725
1726
0
    return EB_ErrorBadParameter;
1727
0
}
1728
1729
0
static EbErrorType str_to_asm(const char* nptr, EbCpuFlags* out) {
1730
    // need to handle numbers in here since the numbers to no match the
1731
    // internal representation
1732
0
    const struct {
1733
0
        const char* name;
1734
0
        EbCpuFlags  flag;
1735
0
    } simds[] = {
1736
0
        {"c", 0},
1737
0
        {"0", 0},
1738
#ifdef ARCH_X86_64
1739
        {"mmx", (EB_CPU_FLAGS_MMX << 1) - 1},
1740
        {"1", (EB_CPU_FLAGS_MMX << 1) - 1},
1741
        {"sse", (EB_CPU_FLAGS_SSE << 1) - 1},
1742
        {"2", (EB_CPU_FLAGS_SSE << 1) - 1},
1743
        {"sse2", (EB_CPU_FLAGS_SSE2 << 1) - 1},
1744
        {"3", (EB_CPU_FLAGS_SSE2 << 1) - 1},
1745
        {"sse3", (EB_CPU_FLAGS_SSE3 << 1) - 1},
1746
        {"4", (EB_CPU_FLAGS_SSE3 << 1) - 1},
1747
        {"ssse3", (EB_CPU_FLAGS_SSSE3 << 1) - 1},
1748
        {"5", (EB_CPU_FLAGS_SSSE3 << 1) - 1},
1749
        {"sse4_1", (EB_CPU_FLAGS_SSE4_1 << 1) - 1},
1750
        {"6", (EB_CPU_FLAGS_SSE4_1 << 1) - 1},
1751
        {"sse4_2", (EB_CPU_FLAGS_SSE4_2 << 1) - 1},
1752
        {"7", (EB_CPU_FLAGS_SSE4_2 << 1) - 1},
1753
        {"avx", (EB_CPU_FLAGS_AVX << 1) - 1},
1754
        {"8", (EB_CPU_FLAGS_AVX << 1) - 1},
1755
        {"avx2", (EB_CPU_FLAGS_AVX2 << 1) - 1},
1756
        {"9", (EB_CPU_FLAGS_AVX2 << 1) - 1},
1757
        {"avx512", (EB_CPU_FLAGS_AVX512VL << 1) - 1},
1758
        {"10", (EB_CPU_FLAGS_AVX512VL << 1) - 1},
1759
        {"avx512icl", (EB_CPU_FLAGS_AVX512ICL << 1) - 1},
1760
        {"11", (EB_CPU_FLAGS_AVX512ICL << 1) - 1},
1761
#elif defined(ARCH_AARCH64)
1762
        {"neon", (EB_CPU_FLAGS_NEON << 1) - 1},
1763
        {"1", (EB_CPU_FLAGS_NEON << 1) - 1},
1764
        {"crc32", (EB_CPU_FLAGS_ARM_CRC32 << 1) - 1},
1765
        {"2", (EB_CPU_FLAGS_ARM_CRC32 << 1) - 1},
1766
        {"neon_dotprod", (EB_CPU_FLAGS_NEON_DOTPROD << 1) - 1},
1767
        {"3", (EB_CPU_FLAGS_NEON_DOTPROD << 1) - 1},
1768
        {"neon_i8mm", (EB_CPU_FLAGS_NEON_I8MM << 1) - 1},
1769
        {"4", (EB_CPU_FLAGS_NEON_I8MM << 1) - 1},
1770
        {"sve", (EB_CPU_FLAGS_SVE << 1) - 1},
1771
        {"5", (EB_CPU_FLAGS_SVE << 1) - 1},
1772
        {"sve2", (EB_CPU_FLAGS_SVE2 << 1) - 1},
1773
        {"6", (EB_CPU_FLAGS_SVE2 << 1) - 1},
1774
#endif
1775
0
        {"max", EB_CPU_FLAGS_ALL},
1776
0
        {"100", EB_CPU_FLAGS_ALL},
1777
0
    };
1778
0
    const size_t simds_size = sizeof(simds) / sizeof(simds[0]);
1779
1780
0
    for (size_t i = 0; i < simds_size; i++) {
1781
0
        if (!strcmp(nptr, simds[i].name)) {
1782
0
            *out = simds[i].flag;
1783
0
            return EB_ErrorNone;
1784
0
        }
1785
0
    }
1786
1787
0
    *out = EB_CPU_FLAGS_INVALID;
1788
1789
0
    return EB_ErrorBadParameter;
1790
0
}
1791
1792
0
static EbErrorType str_to_color_primaries(const char* nptr, EbColorPrimaries* out) {
1793
0
    const struct {
1794
0
        const char*      name;
1795
0
        EbColorPrimaries primaries;
1796
0
    } color_primaries[] = {
1797
0
        {"bt709", EB_CICP_CP_BT_709},
1798
0
        {"bt470m", EB_CICP_CP_BT_470_M},
1799
0
        {"bt470bg", EB_CICP_CP_BT_470_B_G},
1800
0
        {"bt601", EB_CICP_CP_BT_601},
1801
0
        {"smpte240", EB_CICP_CP_SMPTE_240},
1802
0
        {"film", EB_CICP_CP_GENERIC_FILM},
1803
0
        {"bt2020", EB_CICP_CP_BT_2020},
1804
0
        {"xyz", EB_CICP_CP_XYZ},
1805
0
        {"smpte431", EB_CICP_CP_SMPTE_431},
1806
0
        {"smpte432", EB_CICP_CP_SMPTE_432},
1807
0
        {"ebu3213", EB_CICP_CP_EBU_3213},
1808
0
    };
1809
1810
0
    const size_t color_primaries_size = sizeof(color_primaries) / sizeof(color_primaries[0]);
1811
1812
0
    for (size_t i = 0; i < color_primaries_size; i++) {
1813
0
        if (!strcmp(nptr, color_primaries[i].name)) {
1814
0
            *out = color_primaries[i].primaries;
1815
0
            return EB_ErrorNone;
1816
0
        }
1817
0
    }
1818
1819
0
    return EB_ErrorBadParameter;
1820
0
}
1821
1822
0
static EbErrorType str_to_transfer_characteristics(const char* nptr, EbTransferCharacteristics* out) {
1823
0
    const struct {
1824
0
        const char*               name;
1825
0
        EbTransferCharacteristics tfc;
1826
0
    } transfer_characteristics[] = {
1827
0
        {"bt709", EB_CICP_TC_BT_709},
1828
0
        {"bt470m", EB_CICP_TC_BT_470_M},
1829
0
        {"bt470bg", EB_CICP_TC_BT_470_B_G},
1830
0
        {"bt601", EB_CICP_TC_BT_601},
1831
0
        {"smpte240", EB_CICP_TC_SMPTE_240},
1832
0
        {"linear", EB_CICP_TC_LINEAR},
1833
0
        {"log100", EB_CICP_TC_LOG_100},
1834
0
        {"log100-sqrt10", EB_CICP_TC_LOG_100_SQRT10},
1835
0
        {"iec61966", EB_CICP_TC_IEC_61966},
1836
0
        {"bt1361", EB_CICP_TC_BT_1361},
1837
0
        {"srgb", EB_CICP_TC_SRGB},
1838
0
        {"bt2020-10", EB_CICP_TC_BT_2020_10_BIT},
1839
0
        {"bt2020-12", EB_CICP_TC_BT_2020_12_BIT},
1840
0
        {"smpte2084", EB_CICP_TC_SMPTE_2084},
1841
0
        {"smpte428", EB_CICP_TC_SMPTE_428},
1842
0
        {"hlg", EB_CICP_TC_HLG},
1843
0
    };
1844
1845
0
    const size_t transfer_characteristics_size = sizeof(transfer_characteristics) / sizeof(transfer_characteristics[0]);
1846
1847
0
    for (size_t i = 0; i < transfer_characteristics_size; i++) {
1848
0
        if (!strcmp(nptr, transfer_characteristics[i].name)) {
1849
0
            *out = transfer_characteristics[i].tfc;
1850
0
            return EB_ErrorNone;
1851
0
        }
1852
0
    }
1853
1854
0
    return EB_ErrorBadParameter;
1855
0
}
1856
1857
0
static EbErrorType str_to_matrix_coefficients(const char* nptr, EbMatrixCoefficients* out) {
1858
0
    const struct {
1859
0
        const char*          name;
1860
0
        EbMatrixCoefficients coeff;
1861
0
    } matrix_coefficients[] = {
1862
0
        {"identity", EB_CICP_MC_IDENTITY},
1863
0
        {"bt709", EB_CICP_MC_BT_709},
1864
0
        {"fcc", EB_CICP_MC_FCC},
1865
0
        {"bt470bg", EB_CICP_MC_BT_470_B_G},
1866
0
        {"bt601", EB_CICP_MC_BT_601},
1867
0
        {"smpte240", EB_CICP_MC_SMPTE_240},
1868
0
        {"ycgco", EB_CICP_MC_SMPTE_YCGCO},
1869
0
        {"bt2020-ncl", EB_CICP_MC_BT_2020_NCL},
1870
0
        {"bt2020-cl", EB_CICP_MC_BT_2020_CL},
1871
0
        {"smpte2085", EB_CICP_MC_SMPTE_2085},
1872
0
        {"chroma-ncl", EB_CICP_MC_CHROMAT_NCL},
1873
0
        {"chroma-cl", EB_CICP_MC_CHROMAT_CL},
1874
0
        {"ictcp", EB_CICP_MC_ICTCP},
1875
0
    };
1876
1877
0
    const size_t matrix_coefficients_size = sizeof(matrix_coefficients) / sizeof(matrix_coefficients[0]);
1878
1879
0
    for (size_t i = 0; i < matrix_coefficients_size; i++) {
1880
0
        if (!strcmp(nptr, matrix_coefficients[i].name)) {
1881
0
            *out = matrix_coefficients[i].coeff;
1882
0
            return EB_ErrorNone;
1883
0
        }
1884
0
    }
1885
1886
0
    return EB_ErrorBadParameter;
1887
0
}
1888
1889
0
static EbErrorType str_to_color_range(const char* nptr, EbColorRange* out) {
1890
0
    const struct {
1891
0
        const char*  name;
1892
0
        EbColorRange range;
1893
0
    } color_range[] = {
1894
0
        {"studio", EB_CR_STUDIO_RANGE},
1895
0
        {"full", EB_CR_FULL_RANGE},
1896
0
    };
1897
1898
0
    const size_t color_range_size = sizeof(color_range) / sizeof(color_range[0]);
1899
1900
0
    for (size_t i = 0; i < color_range_size; i++) {
1901
0
        if (!strcmp(nptr, color_range[i].name)) {
1902
0
            *out = color_range[i].range;
1903
0
            return EB_ErrorNone;
1904
0
        }
1905
0
    }
1906
1907
0
    return EB_ErrorBadParameter;
1908
0
}
1909
1910
0
static EbErrorType str_to_chroma_sample_position(const char* nptr, EbChromaSamplePosition* out) {
1911
0
    const struct {
1912
0
        const char*            name;
1913
0
        EbChromaSamplePosition pos;
1914
0
    } chroma_sample_positions[] = {
1915
0
        {"unknown", EB_CSP_UNKNOWN},
1916
0
        {"vertical", EB_CSP_VERTICAL},
1917
0
        {"left", EB_CSP_VERTICAL},
1918
0
        {"colocated", EB_CSP_COLOCATED},
1919
0
        {"topleft", EB_CSP_COLOCATED},
1920
0
    };
1921
1922
0
    const size_t chroma_sample_positions_size = sizeof(chroma_sample_positions) / sizeof(chroma_sample_positions[0]);
1923
1924
0
    for (size_t i = 0; i < chroma_sample_positions_size; i++) {
1925
0
        if (!strcmp(nptr, chroma_sample_positions[i].name)) {
1926
0
            *out = chroma_sample_positions[i].pos;
1927
0
            return EB_ErrorNone;
1928
0
        }
1929
0
    }
1930
1931
0
    return EB_ErrorBadParameter;
1932
0
}
1933
1934
0
static EbErrorType str_to_sframe_mode(const char* nptr, EbSFrameMode* out) {
1935
0
    const struct {
1936
0
        const char*  name;
1937
0
        EbSFrameMode mode;
1938
0
    } sframe_mode[] = {
1939
0
        {"strict", SFRAME_STRICT_BASE},
1940
0
        {"nearest", SFRAME_NEAREST_BASE},
1941
0
        {"flexible", SFRAME_FLEXIBLE_BASE},
1942
0
        {"decposi", SFRAME_DEC_POSI_BASE},
1943
0
    };
1944
1945
0
    const size_t sframe_mode_size = sizeof(sframe_mode) / sizeof(sframe_mode[0]);
1946
1947
0
    for (size_t i = 0; i < sframe_mode_size; i++) {
1948
0
        if (!strcmp(nptr, sframe_mode[i].name)) {
1949
0
            *out = sframe_mode[i].mode;
1950
0
            return EB_ErrorNone;
1951
0
        }
1952
0
    }
1953
1954
0
    return EB_ErrorBadParameter;
1955
0
}
1956
1957
0
static EbErrorType str_to_rc_mode(const char* nptr, uint8_t* out, uint8_t* aq_mode) {
1958
    // separate rc mode enum to distinguish between cqp and crf modes
1959
0
    enum rc_modes {
1960
0
        RC_MODE_ZERO = 0, // unique mode in case user passes a literal 0
1961
0
        RC_MODE_CQP,
1962
0
        RC_MODE_CRF,
1963
0
        RC_MODE_VBR,
1964
0
        RC_MODE_CBR,
1965
0
        RC_MODE_INVALID,
1966
0
    };
1967
1968
0
    const struct {
1969
0
        const char* name;
1970
0
        uint32_t    mode;
1971
0
    } rc_mode[] = {
1972
0
        {"0", RC_MODE_ZERO},
1973
0
        {"1", RC_MODE_VBR},
1974
0
        {"2", RC_MODE_CBR},
1975
0
        {"cqp", RC_MODE_CQP},
1976
0
        {"crf", RC_MODE_CRF},
1977
0
        {"vbr", RC_MODE_VBR},
1978
0
        {"cbr", RC_MODE_CBR},
1979
0
    };
1980
1981
0
    const size_t rc_mode_size = sizeof(rc_mode) / sizeof(rc_mode[0]);
1982
1983
0
    enum rc_modes mode = RC_MODE_INVALID;
1984
1985
0
    for (size_t i = 0; i < rc_mode_size; i++) {
1986
0
        if (!strcmp(nptr, rc_mode[i].name)) {
1987
0
            mode = rc_mode[i].mode;
1988
0
            break;
1989
0
        }
1990
0
    }
1991
1992
0
    switch (mode) {
1993
0
    case RC_MODE_ZERO:
1994
0
        *out = 0;
1995
0
        break;
1996
0
    case RC_MODE_CQP:
1997
0
        *out     = SVT_AV1_RC_MODE_CQP_OR_CRF;
1998
0
        *aq_mode = 0;
1999
0
        break;
2000
0
    case RC_MODE_CRF:
2001
0
        *out     = SVT_AV1_RC_MODE_CQP_OR_CRF;
2002
0
        *aq_mode = 2;
2003
0
        break;
2004
0
    case RC_MODE_VBR:
2005
0
        *out = SVT_AV1_RC_MODE_VBR;
2006
0
        break;
2007
0
    case RC_MODE_CBR:
2008
0
        *out = SVT_AV1_RC_MODE_CBR;
2009
0
        break;
2010
0
    default:
2011
0
        SVT_ERROR("Invalid rc mode: %s\n", nptr);
2012
0
        return EB_ErrorBadParameter;
2013
0
    }
2014
0
    return EB_ErrorNone;
2015
0
}
2016
2017
0
static EbErrorType str_to_pred_struct(const char* nptr, PredStructure* pred_structure) {
2018
0
    const struct {
2019
0
        const char*   name;
2020
0
        PredStructure mode;
2021
0
    } pred_structs[] = {{"0", ALL_INTRA},
2022
0
                        {"all-intra", ALL_INTRA},
2023
0
                        {"ai", ALL_INTRA},
2024
0
                        {"1", LOW_DELAY},
2025
0
                        {"low-delay", LOW_DELAY},
2026
0
                        {"ld", LOW_DELAY},
2027
0
                        {"2", RANDOM_ACCESS},
2028
0
                        {"random-access", RANDOM_ACCESS},
2029
0
                        {"ra", RANDOM_ACCESS}};
2030
2031
0
    const size_t pred_structs_size = sizeof(pred_structs) / sizeof(pred_structs[0]);
2032
2033
0
    for (size_t i = 0; i < pred_structs_size; i++) {
2034
0
        if (!strcmp(nptr, pred_structs[i].name)) {
2035
0
            *pred_structure = pred_structs[i].mode;
2036
0
            return EB_ErrorNone;
2037
0
        }
2038
0
    }
2039
2040
0
    SVT_ERROR("Invalid pred struct: %s\n", nptr);
2041
0
    return EB_ErrorBadParameter;
2042
0
}
2043
2044
0
static EbErrorType str_to_frm_resz_evts(const char* nptr, SvtAv1FrameScaleEvts* evts) {
2045
0
    const uint32_t param_count = count_params(nptr);
2046
0
    if ((evts->evt_num != 0 && evts->evt_num != param_count) || param_count == 0) {
2047
0
        SVT_ERROR("Error: Size for the list passed to %s doesn't match %u\n", "frame-resz-events", evts->evt_num);
2048
0
        return EB_ErrorBadParameter;
2049
0
    }
2050
0
    if (evts->start_frame_nums) {
2051
0
        EB_FREE(evts->start_frame_nums);
2052
0
    }
2053
0
    EB_MALLOC(evts->start_frame_nums, param_count * sizeof(uint64_t));
2054
0
    evts->evt_num = param_count;
2055
0
    return parse_list_uint64(nptr, evts->start_frame_nums, param_count);
2056
0
}
2057
2058
0
static EbErrorType str_to_resz_kf_denoms(const char* nptr, SvtAv1FrameScaleEvts* evts) {
2059
0
    const uint32_t param_count = count_params(nptr);
2060
0
    if ((evts->evt_num != 0 && evts->evt_num != param_count) || param_count == 0) {
2061
0
        SVT_ERROR("Error: Size for the list passed to %s doesn't match %u\n", "frame-resz-kf-denoms", evts->evt_num);
2062
0
        return EB_ErrorBadParameter;
2063
0
    }
2064
0
    if (evts->resize_kf_denoms) {
2065
0
        EB_FREE(evts->resize_kf_denoms);
2066
0
    }
2067
0
    EB_MALLOC(evts->resize_kf_denoms, param_count * sizeof(uint32_t));
2068
0
    evts->evt_num = param_count;
2069
0
    return parse_list_uint32(nptr, evts->resize_kf_denoms, param_count);
2070
0
}
2071
2072
0
static EbErrorType str_to_resz_denoms(const char* nptr, SvtAv1FrameScaleEvts* evts) {
2073
0
    const uint32_t param_count = count_params(nptr);
2074
0
    if ((evts->evt_num != 0 && evts->evt_num != param_count) || param_count == 0) {
2075
0
        SVT_ERROR("Error: Size for the list passed to %s doesn't match %u\n", "frame-resz-denoms", evts->evt_num);
2076
0
        return EB_ErrorBadParameter;
2077
0
    }
2078
0
    if (evts->resize_denoms) {
2079
0
        EB_FREE(evts->resize_denoms);
2080
0
    }
2081
0
    EB_MALLOC(evts->resize_denoms, param_count * sizeof(uint32_t));
2082
0
    evts->evt_num = param_count;
2083
0
    return parse_list_uint32(nptr, evts->resize_denoms, param_count);
2084
0
}
2085
2086
0
static EbErrorType str_to_sframe_posi(const char* nptr, SvtAv1SFramePositions* posis) {
2087
0
    const uint32_t param_count = count_params(nptr);
2088
0
    if ((posis->sframe_num != 0 && posis->sframe_num != param_count) || param_count == 0) {
2089
0
        SVT_ERROR("Error: Size for the list passed to %s doesn't match %u\n", "sframe-posi", posis->sframe_num);
2090
0
        return EB_ErrorBadParameter;
2091
0
    }
2092
0
    if (posis->sframe_posis) {
2093
0
        EB_FREE(posis->sframe_posis);
2094
0
    }
2095
0
    EB_MALLOC(posis->sframe_posis, param_count * sizeof(uint64_t));
2096
0
    posis->sframe_num = param_count;
2097
0
    return parse_list_uint64(nptr, posis->sframe_posis, param_count);
2098
0
}
2099
2100
0
static EbErrorType str_to_sframe_qp(const char* nptr, SvtAv1SFramePositions* posis, uint8_t* qp) {
2101
0
    const uint32_t param_count = count_params(nptr);
2102
0
    if ((posis->sframe_num != 0 && posis->sframe_num != param_count && param_count != 1) || param_count == 0) {
2103
0
        SVT_ERROR("Error: Size for the list passed to %s doesn't match %u\n", "sframe-qp", posis->sframe_num);
2104
0
        return EB_ErrorBadParameter;
2105
0
    }
2106
0
    if (posis->sframe_qps) {
2107
0
        EB_FREE(posis->sframe_qps);
2108
0
    }
2109
0
    EB_MALLOC(posis->sframe_qps, param_count * sizeof(uint8_t));
2110
0
    posis->sframe_qp_num = param_count;
2111
0
    EbErrorType err      = parse_list_uint8(nptr, posis->sframe_qps, param_count);
2112
    // check if the QP values are valid
2113
0
    for (uint32_t i = 0; i < posis->sframe_qp_num; ++i) {
2114
0
        if (posis->sframe_qps[i] < 1 || posis->sframe_qps[i] > 63) {
2115
0
            SVT_ERROR("Error: Invalid S-Frame QP value. QPs must be [1 - 63]\n");
2116
0
            EB_FREE(posis->sframe_qps);
2117
0
            posis->sframe_qp_num = 0;
2118
0
            err                  = EB_ErrorBadParameter;
2119
0
        }
2120
0
    }
2121
    // If sframe-qp parameter contains only one value, apply it to all S-frames
2122
0
    if (err == EB_ErrorNone && param_count == 1) {
2123
0
        *qp = posis->sframe_qps[0];
2124
0
    }
2125
0
    return err;
2126
0
}
2127
2128
0
static EbErrorType str_to_sframe_qp_offset(const char* nptr, SvtAv1SFramePositions* posis, int8_t* qp_offset) {
2129
0
    const uint32_t param_count = count_params(nptr);
2130
0
    if ((posis->sframe_num != 0 && posis->sframe_num != param_count && param_count != 1) || param_count == 0) {
2131
0
        SVT_ERROR("Error: Size for the list passed to %s doesn't match %u\n", "sframe-qp-offset", posis->sframe_num);
2132
0
        return EB_ErrorBadParameter;
2133
0
    }
2134
0
    if (posis->sframe_qp_offsets) {
2135
0
        EB_FREE(posis->sframe_qp_offsets);
2136
0
    }
2137
0
    EB_MALLOC(posis->sframe_qp_offsets, param_count * sizeof(int8_t));
2138
0
    posis->sframe_qp_num = param_count;
2139
0
    EbErrorType err      = parse_list_int8(nptr, posis->sframe_qp_offsets, param_count);
2140
    // check if the QP offset values are valid
2141
0
    for (uint32_t i = 0; i < posis->sframe_qp_num; ++i) {
2142
0
        if (posis->sframe_qp_offsets[i] < -63 || posis->sframe_qp_offsets[i] > 63) {
2143
0
            SVT_ERROR("Error: Invalid S-Frame QP offset value. QP offsets must be [-63 - 63]\n");
2144
0
            EB_FREE(posis->sframe_qp_offsets);
2145
0
            posis->sframe_qp_num = 0;
2146
0
            err                  = EB_ErrorBadParameter;
2147
0
        }
2148
0
    }
2149
    // If sframe-qp-offset parameter contains only one value, apply it to all S-frames
2150
0
    if (err == EB_ErrorNone && param_count == 1) {
2151
0
        *qp_offset = posis->sframe_qp_offsets[0];
2152
0
    }
2153
0
    return err;
2154
0
}
2155
2156
#define COLOR_OPT(par, opt)                                          \
2157
0
    do {                                                             \
2158
0
        if (!strcmp(name, par)) {                                    \
2159
0
            return_error = str_to_##opt(value, &config_struct->opt); \
2160
0
            if (return_error == EB_ErrorNone)                        \
2161
0
                return return_error;                                 \
2162
0
            uint32_t val;                                            \
2163
0
            return_error = str_to_uint(value, &val, NULL);           \
2164
0
            if (return_error == EB_ErrorNone)                        \
2165
0
                config_struct->opt = val;                            \
2166
0
            return return_error;                                     \
2167
0
        }                                                            \
2168
0
    } while (0)
2169
2170
#define COLOR_METADATA_OPT(par, opt)                                                                      \
2171
0
    do {                                                                                                  \
2172
0
        if (!strcmp(name, par))                                                                           \
2173
0
            return svt_aom_parse_##opt(&config_struct->opt, value) ? EB_ErrorNone : EB_ErrorBadParameter; \
2174
0
    } while (0)
2175
2176
EB_API EbErrorType svt_av1_enc_parse_parameter(EbSvtAv1EncConfiguration* config_struct, const char* name,
2177
0
                                               const char* value) {
2178
0
    if (config_struct == NULL || name == NULL || value == NULL) {
2179
0
        return EB_ErrorBadParameter;
2180
0
    }
2181
2182
0
    EbErrorType return_error = EB_ErrorBadParameter;
2183
2184
0
    if (!strcmp(name, "keyint")) {
2185
0
        return str_to_keyint(value, &config_struct->intra_period_length, &config_struct->multiply_keyint);
2186
0
    }
2187
2188
0
    if (!strcmp(name, "tbr")) {
2189
0
        return str_to_bitrate(value, &config_struct->target_bit_rate);
2190
0
    }
2191
2192
0
    if (!strcmp(name, "mbr")) {
2193
0
        return str_to_bitrate(value, &config_struct->max_bit_rate);
2194
0
    }
2195
2196
    // options updating more than one field
2197
0
    if (!strcmp(name, "crf")) {
2198
0
        return str_to_crf(value, config_struct);
2199
0
    }
2200
2201
0
    if (!strcmp(name, "cqp")) {
2202
0
        return str_to_cqp(value, config_struct);
2203
0
    }
2204
2205
0
    if (!strcmp(name, "rc")) {
2206
0
        return str_to_rc_mode(value, &config_struct->rate_control_mode, &config_struct->aq_mode);
2207
0
    }
2208
2209
    // custom enum fields
2210
0
    if (!strcmp(name, "profile")) {
2211
0
        return str_to_profile(value, &config_struct->profile) == EB_ErrorBadParameter
2212
0
            ? str_to_uint(value, (uint32_t*)&config_struct->profile, NULL)
2213
0
            : EB_ErrorNone;
2214
0
    }
2215
2216
0
    if (!strcmp(name, "color-format")) {
2217
0
        return str_to_color_fmt(value, &config_struct->encoder_color_format) == EB_ErrorBadParameter
2218
0
            ? str_to_uint(value, (uint32_t*)&config_struct->encoder_color_format, NULL)
2219
0
            : EB_ErrorNone;
2220
0
    }
2221
2222
0
    if (!strcmp(name, "irefresh-type")) {
2223
0
        return str_to_intra_rt(value, &config_struct->intra_refresh_type) == EB_ErrorBadParameter
2224
0
            ? str_to_uint(value, (uint32_t*)&config_struct->intra_refresh_type, NULL)
2225
0
            : EB_ErrorNone;
2226
0
    }
2227
2228
0
    if (!strcmp(name, "sframe-mode")) {
2229
0
        return str_to_sframe_mode(value, &config_struct->sframe_mode) == EB_ErrorBadParameter
2230
0
            ? str_to_uint(value, (uint32_t*)&config_struct->sframe_mode, NULL)
2231
0
            : EB_ErrorNone;
2232
0
    }
2233
2234
0
    if (!strcmp(name, "asm")) {
2235
0
        return str_to_asm(value, &config_struct->use_cpu_flags);
2236
0
    }
2237
2238
0
    if (!strcmp(name, "pred-struct")) {
2239
0
        return str_to_pred_struct(value, &config_struct->pred_structure);
2240
0
    }
2241
2242
0
    COLOR_OPT("color-primaries", color_primaries);
2243
0
    COLOR_OPT("transfer-characteristics", transfer_characteristics);
2244
0
    COLOR_OPT("matrix-coefficients", matrix_coefficients);
2245
0
    COLOR_OPT("color-range", color_range);
2246
0
    COLOR_OPT("chroma-sample-position", chroma_sample_position);
2247
2248
    // custom struct fields
2249
0
    COLOR_METADATA_OPT("mastering-display", mastering_display);
2250
0
    COLOR_METADATA_OPT("content-light", content_light_level);
2251
2252
    // arrays
2253
0
    if (!strcmp(name, "qindex-offsets")) {
2254
0
        return parse_list_int32(value, config_struct->qindex_offsets, EB_MAX_TEMPORAL_LAYERS);
2255
0
    }
2256
2257
0
    if (!strcmp(name, "chroma-qindex-offsets")) {
2258
0
        return parse_list_int32(value, config_struct->chroma_qindex_offsets, EB_MAX_TEMPORAL_LAYERS);
2259
0
    }
2260
2261
0
    if (!strcmp(name, "lambda-scale-factors")) {
2262
0
        return parse_list_int32(value, config_struct->lambda_scale_factors, SVT_AV1_FRAME_UPDATE_TYPES);
2263
0
    }
2264
2265
0
    if (!strcmp(name, "frame-resz-events")) {
2266
0
        return str_to_frm_resz_evts(value, &config_struct->frame_scale_evts);
2267
0
    }
2268
2269
0
    if (!strcmp(name, "frame-resz-kf-denoms")) {
2270
0
        return str_to_resz_kf_denoms(value, &config_struct->frame_scale_evts);
2271
0
    }
2272
2273
0
    if (!strcmp(name, "frame-resz-denoms")) {
2274
0
        return str_to_resz_denoms(value, &config_struct->frame_scale_evts);
2275
0
    }
2276
2277
0
    if (!strcmp(name, "sframe-posi")) {
2278
0
        return str_to_sframe_posi(value, &config_struct->sframe_posi);
2279
0
    }
2280
2281
0
    if (!strcmp(name, "sframe-qp")) {
2282
0
        return str_to_sframe_qp(value, &config_struct->sframe_posi, &config_struct->sframe_qp);
2283
0
    }
2284
2285
0
    if (!strcmp(name, "sframe-qp-offset")) {
2286
0
        return str_to_sframe_qp_offset(value, &config_struct->sframe_posi, &config_struct->sframe_qp_offset);
2287
0
    }
2288
2289
    // uint32_t fields
2290
0
    const struct {
2291
0
        const char* name;
2292
0
        uint32_t*   out;
2293
0
    } uint_opts[] = {
2294
0
        {"w", &config_struct->source_width},
2295
0
        {"width", &config_struct->source_width},
2296
0
        {"h", &config_struct->source_height},
2297
0
        {"height", &config_struct->source_height},
2298
0
        {"q", &config_struct->qp},
2299
0
        {"qp", &config_struct->qp},
2300
0
        {"film-grain", &config_struct->film_grain_denoise_strength},
2301
0
        {"hierarchical-levels", &config_struct->hierarchical_levels},
2302
0
        {"tier", &config_struct->tier},
2303
0
        {"level", &config_struct->level},
2304
0
        {"lp", &config_struct->level_of_parallelism},
2305
0
        {"fps-num", &config_struct->frame_rate_numerator},
2306
0
        {"fps-denom", &config_struct->frame_rate_denominator},
2307
0
        {"lookahead", &config_struct->look_ahead_distance},
2308
0
        {"scd", &config_struct->scene_change_detection},
2309
0
        {"max-qp", &config_struct->max_qp_allowed},
2310
0
        {"min-qp", &config_struct->min_qp_allowed},
2311
0
        {"minsection-pct", &config_struct->vbr_min_section_pct},
2312
0
        {"maxsection-pct", &config_struct->vbr_max_section_pct},
2313
0
        {"undershoot-pct", &config_struct->under_shoot_pct},
2314
0
        {"overshoot-pct", &config_struct->over_shoot_pct},
2315
0
        {"mbr-overshoot-pct", &config_struct->mbr_over_shoot_pct},
2316
0
        {"max-intra-bitrate-pct", &config_struct->max_intra_bitrate_pct},
2317
0
        {"max-inter-bitrate-pct", &config_struct->max_inter_bitrate_pct},
2318
0
        {"recode-loop", &config_struct->recode_loop},
2319
0
        {"enable-stat-report", &config_struct->stat_report},
2320
0
        {"scm", &config_struct->screen_content_mode},
2321
0
        {"input-depth", &config_struct->encoder_bit_depth},
2322
0
        {"forced-max-frame-width", &config_struct->forced_max_frame_width},
2323
0
        {"forced-max-frame-height", &config_struct->forced_max_frame_height},
2324
0
    };
2325
2326
0
    const size_t uint_opts_size = sizeof(uint_opts) / sizeof(uint_opts[0]);
2327
2328
0
    for (size_t i = 0; i < uint_opts_size; i++) {
2329
0
        if (!strcmp(name, uint_opts[i].name)) {
2330
0
            return str_to_uint(value, uint_opts[i].out, NULL);
2331
0
        }
2332
0
    }
2333
2334
    // uint8_t fields
2335
0
    const struct {
2336
0
        const char* name;
2337
0
        uint8_t*    out;
2338
0
    } uint8_opts[] = {
2339
0
        {"aq-mode", &config_struct->aq_mode},
2340
0
        {"superres-mode", &config_struct->superres_mode},
2341
0
        {"superres-qthres", &config_struct->superres_qthres},
2342
0
        {"superres-kf-qthres", &config_struct->superres_kf_qthres},
2343
0
        {"superres-denom", &config_struct->superres_denom},
2344
0
        {"superres-kf-denom", &config_struct->superres_kf_denom},
2345
0
        {"tune", &config_struct->tune},
2346
0
        {"film-grain-denoise", &config_struct->film_grain_denoise_apply},
2347
0
        {"enable-dlf", &config_struct->enable_dlf_flag},
2348
0
        {"resize-mode", &config_struct->resize_mode},
2349
0
        {"resize-denom", &config_struct->resize_denom},
2350
0
        {"resize-kf-denom", &config_struct->resize_kf_denom},
2351
0
        {"qm-min", &config_struct->min_qm_level},
2352
0
        {"qm-max", &config_struct->max_qm_level},
2353
0
        {"chroma-qm-min", &config_struct->min_chroma_qm_level},
2354
0
        {"chroma-qm-max", &config_struct->max_chroma_qm_level},
2355
0
        {"use-fixed-qindex-offsets", &config_struct->use_fixed_qindex_offsets},
2356
0
        {"startup-mg-size", &config_struct->startup_mg_size},
2357
0
        {"variance-boost-strength", &config_struct->variance_boost_strength},
2358
0
        {"variance-octile", &config_struct->variance_octile},
2359
0
        {"variance-boost-curve", &config_struct->variance_boost_curve},
2360
0
        {"qp-scale-compress-strength", &config_struct->qp_scale_compress_strength},
2361
0
        {"fast-decode", &config_struct->fast_decode},
2362
0
        {"luminance-qp-bias", &config_struct->luminance_qp_bias},
2363
0
        {"enable-tf", &config_struct->enable_tf},
2364
0
        {"tf-strength", &config_struct->tf_strength},
2365
0
        {"max-tx-size", &config_struct->max_tx_size},
2366
0
    };
2367
2368
0
    const size_t uint8_opts_size = sizeof(uint8_opts) / sizeof(uint8_opts[0]);
2369
2370
0
    for (size_t i = 0; i < uint8_opts_size; i++) {
2371
0
        if (!strcmp(name, uint8_opts[i].name)) {
2372
0
            uint32_t val;
2373
0
            return_error = str_to_uint(value, &val, NULL);
2374
0
            if (return_error == EB_ErrorNone) {
2375
                // add protection if the input param is roll-over
2376
0
                if (val > 255) {
2377
0
                    return EB_ErrorBadParameter;
2378
0
                }
2379
0
                *uint8_opts[i].out = val;
2380
0
            }
2381
0
            return return_error;
2382
0
        }
2383
0
    }
2384
2385
    // int64_t fields
2386
0
    const struct {
2387
0
        const char* name;
2388
0
        int64_t*    out;
2389
0
    } int64_opts[] = {
2390
0
        {"buf-initial-sz", &config_struct->starting_buffer_level_ms},
2391
0
        {"buf-optimal-sz", &config_struct->optimal_buffer_level_ms},
2392
0
        {"buf-sz", &config_struct->maximum_buffer_size_ms},
2393
0
    };
2394
2395
0
    const size_t int64_opts_size = sizeof(int64_opts) / sizeof(int64_opts[0]);
2396
2397
0
    for (size_t i = 0; i < int64_opts_size; i++) {
2398
0
        if (!strcmp(name, int64_opts[i].name)) {
2399
0
            return str_to_int64(value, int64_opts[i].out, NULL);
2400
0
        }
2401
0
    }
2402
2403
    // double fields
2404
0
    const struct {
2405
0
        const char* name;
2406
0
        double*     out;
2407
0
    } double_opts[] = {
2408
0
        {"ac-bias", &config_struct->ac_bias},
2409
0
    };
2410
2411
0
    const size_t double_opts_size = sizeof(double_opts) / sizeof(double_opts[0]);
2412
2413
0
    for (size_t i = 0; i < double_opts_size; i++) {
2414
0
        if (!strcmp(name, double_opts[i].name)) {
2415
0
            return str_to_double(value, double_opts[i].out, NULL);
2416
0
        }
2417
0
    }
2418
2419
    // int32_t fields
2420
0
    const struct {
2421
0
        const char* name;
2422
0
        int32_t*    out;
2423
0
    } int_opts[] = {
2424
0
        {"key-frame-chroma-qindex-offset", &config_struct->key_frame_chroma_qindex_offset},
2425
0
        {"key-frame-qindex-offset", &config_struct->key_frame_qindex_offset},
2426
0
        {"luma-y-dc-qindex-offset", &config_struct->luma_y_dc_qindex_offset},
2427
0
        {"chroma-u-dc-qindex-offset", &config_struct->chroma_u_dc_qindex_offset},
2428
0
        {"chroma-u-ac-qindex-offset", &config_struct->chroma_u_ac_qindex_offset},
2429
0
        {"chroma-v-dc-qindex-offset", &config_struct->chroma_v_dc_qindex_offset},
2430
0
        {"chroma-v-ac-qindex-offset", &config_struct->chroma_v_ac_qindex_offset},
2431
0
        {"pass", &config_struct->pass},
2432
0
        {"enable-cdef", &config_struct->cdef_level},
2433
0
        {"enable-restoration", &config_struct->enable_restoration_filtering},
2434
0
        {"enable-mfmv", &config_struct->enable_mfmv},
2435
0
        {"intra-period", &config_struct->intra_period_length},
2436
0
        {"tile-rows", &config_struct->tile_rows},
2437
0
        {"tile-columns", &config_struct->tile_columns},
2438
0
        {"sframe-dist", &config_struct->sframe_dist},
2439
0
        {"hbd-mds", &config_struct->hbd_mds},
2440
0
    };
2441
2442
0
    const size_t int_opts_size = sizeof(int_opts) / sizeof(int_opts[0]);
2443
2444
0
    for (size_t i = 0; i < int_opts_size; i++) {
2445
0
        if (!strcmp(name, int_opts[i].name)) {
2446
0
            return str_to_int(value, int_opts[i].out, NULL);
2447
0
        }
2448
0
    }
2449
2450
    // int8_t fields
2451
0
    const struct {
2452
0
        const char* name;
2453
0
        int8_t*     out;
2454
0
    } int8_opts[] = {
2455
0
        {"preset", &config_struct->enc_mode},
2456
0
        {"sharpness", &config_struct->sharpness},
2457
0
        {"startup-qp-offset", &config_struct->startup_qp_offset},
2458
0
    };
2459
2460
0
    const size_t int8_opts_size = sizeof(int8_opts) / sizeof(int8_opts[0]);
2461
2462
0
    for (size_t i = 0; i < int8_opts_size; i++) {
2463
0
        if (!strcmp(name, int8_opts[i].name)) {
2464
0
            int32_t val;
2465
0
            return_error = str_to_int(value, &val, NULL);
2466
0
            if (return_error == EB_ErrorNone) {
2467
                // add protection if the input param is roll-over
2468
0
                if (val > 127 || val < -128) {
2469
0
                    return EB_ErrorBadParameter;
2470
0
                }
2471
0
                *int8_opts[i].out = val;
2472
0
            }
2473
0
            return return_error;
2474
0
        }
2475
0
    }
2476
2477
    // bool fields
2478
0
    const struct {
2479
0
        const char* name;
2480
0
        bool*       out;
2481
0
    } bool_opts[] = {
2482
0
        {"use-q-file", &config_struct->use_qp_file},
2483
0
        {"enable-overlays", &config_struct->enable_overlays},
2484
0
        {"enable-force-key-frames", &config_struct->force_key_frames},
2485
0
#if CONFIG_ENABLE_QUANT_MATRIX
2486
0
        {"enable-qm", &config_struct->enable_qm},
2487
0
#endif
2488
0
        {"enable-dg", &config_struct->enable_dg},
2489
0
        {"gop-constraint-rc", &config_struct->gop_constraint_rc},
2490
0
        {"enable-variance-boost", &config_struct->enable_variance_boost},
2491
0
        {"lossless", &config_struct->lossless},
2492
0
        {"avif", &config_struct->avif},
2493
0
        {"rtc", &config_struct->rtc},
2494
0
        {"adaptive-film-grain", &config_struct->adaptive_film_grain},
2495
0
        {"enable-kf-tf", &config_struct->enable_tf_key},
2496
0
        {"enable-intrabc", &config_struct->enable_intrabc},
2497
0
    };
2498
0
    const size_t bool_opts_size = sizeof(bool_opts) / sizeof(bool_opts[0]);
2499
2500
0
    for (size_t i = 0; i < bool_opts_size; i++) {
2501
0
        if (!strcmp(name, bool_opts[i].name)) {
2502
0
            return str_to_bool(value, bool_opts[i].out);
2503
0
        }
2504
0
    }
2505
2506
0
    return return_error;
2507
0
}