Coverage Report

Created: 2026-12-01 06:52

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