Coverage Report

Created: 2026-09-01 06:57

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