Line data Source code
1 : /*
2 : * Copyright(c) 2019 Intel Corporation
3 : * SPDX - License - Identifier: BSD - 2 - Clause - Patent
4 : */
5 : // SUMMARY
6 : // Contains the API component functions
7 :
8 : /**************************************
9 : * Includes
10 : **************************************/
11 : #include <stdlib.h>
12 : #include <stdio.h>
13 : #include <stdint.h>
14 : #include <immintrin.h>
15 :
16 : #include "EbDefinitions.h"
17 : #include "EbSvtAv1Enc.h"
18 : #include "EbThreads.h"
19 : #include "EbUtility.h"
20 : #include "EbString.h"
21 : #include "EbEncHandle.h"
22 : #include "EbSystemResourceManager.h"
23 : #include "EbPictureControlSet.h"
24 : #include "EbPictureOperators.h"
25 : #include "EbSequenceControlSet.h"
26 : #include "EbPictureBufferDesc.h"
27 : #include "EbReferenceObject.h"
28 : #include "EbPictureDecisionProcess.h"
29 : #include "EbMotionEstimationProcess.h"
30 : #include "EbInitialRateControlProcess.h"
31 : #include "EbSourceBasedOperationsProcess.h"
32 : #include "EbPictureManagerProcess.h"
33 : #include "EbRateControlProcess.h"
34 : #include "EbModeDecisionConfigurationProcess.h"
35 : #include "EbEncDecProcess.h"
36 : #include "EbEntropyCodingProcess.h"
37 : #include "EbPacketizationProcess.h"
38 : #include "EbResourceCoordinationResults.h"
39 : #include "EbPictureAnalysisResults.h"
40 : #include "EbPictureDecisionResults.h"
41 : #include "EbMotionEstimationResults.h"
42 : #include "EbInitialRateControlResults.h"
43 : #include "EbPictureDemuxResults.h"
44 : #include "EbRateControlTasks.h"
45 : #include "EbRateControlResults.h"
46 : #include "EbEncDecTasks.h"
47 : #include "EbEncDecResults.h"
48 : #include "EbEntropyCodingResults.h"
49 : #include "EbPredictionStructure.h"
50 : #include "EbDlfProcess.h"
51 : #include "EbCdefProcess.h"
52 : #include "EbRestProcess.h"
53 : #include "EbObject.h"
54 :
55 : #ifdef _WIN32
56 : #include <windows.h>
57 : #else
58 : #include <errno.h>
59 : #include <pthread.h>
60 : #include <unistd.h>
61 : #endif
62 :
63 : #include "aom_dsp_rtcd.h"
64 :
65 : /**************************************
66 : * Defines
67 : **************************************/
68 : #define EB_EncodeInstancesTotalCount 1
69 : #define EB_ComputeSegmentInitCount 1
70 :
71 : // Config Set Initial Count
72 : #define EB_SequenceControlSetPoolInitCount 3
73 :
74 : // Process Instantiation Initial Counts
75 : #define EB_ResourceCoordinationProcessInitCount 1
76 : #define EB_PictureDecisionProcessInitCount 1
77 : #define EB_InitialRateControlProcessInitCount 1
78 : #define EB_PictureManagerProcessInitCount 1
79 : #define EB_RateControlProcessInitCount 1
80 : #define EB_PacketizationProcessInitCount 1
81 :
82 : // Output Buffer Transfer Parameters
83 : #define EB_OUTPUTSTREAMBUFFERSIZE 0x2DC6C0 //0x7D00 // match MTU Size
84 : #define EB_OUTPUTRECONBUFFERSIZE (MAX_PICTURE_WIDTH_SIZE*MAX_PICTURE_HEIGHT_SIZE*2) // Recon Slice Size
85 : #define EB_OUTPUTSTATISTICSBUFFERSIZE 0x30 // 6X8 (8 Bytes for Y, U, V, number of bits, picture number, QP)
86 : #define EOS_NAL_BUFFER_SIZE 0x0010 // Bitstream used to code EOS NAL
87 : #define EB_OUTPUTSTREAMBUFFERSIZE_MACRO(ResolutionSize) ((ResolutionSize) < (INPUT_SIZE_1080i_TH) ? 0x1E8480 : (ResolutionSize) < (INPUT_SIZE_1080p_TH) ? 0x2DC6C0 : (ResolutionSize) < (INPUT_SIZE_4K_TH) ? 0x2DC6C0 : 0x2DC6C0 )
88 :
89 : #define ENCDEC_INPUT_PORT_MDC 0
90 : #define ENCDEC_INPUT_PORT_ENCDEC 1
91 : #define ENCDEC_INPUT_PORT_INVALID -1
92 :
93 : #define SCD_LAD 6
94 :
95 : /**************************************
96 : * Globals
97 : **************************************/
98 :
99 : uint8_t num_groups = 0;
100 : #ifdef _WIN32
101 : GROUP_AFFINITY group_affinity;
102 : EbBool alternate_groups = 0;
103 : #elif defined(__linux__)
104 : cpu_set_t group_affinity;
105 : typedef struct logicalProcessorGroup {
106 : uint32_t num;
107 : uint32_t group[1024];
108 : }processorGroup;
109 : #define INITIAL_PROCESSOR_GROUP 16
110 : processorGroup *lp_group = NULL;
111 : #endif
112 2 : static int32_t CanUseIntelCore4thGenFeatures()
113 : {
114 : static int32_t the_4th_gen_features_available = -1;
115 : /* test is performed once */
116 2 : if (the_4th_gen_features_available < 0)
117 2 : the_4th_gen_features_available = Check4thGenIntelCoreFeatures();
118 2 : return the_4th_gen_features_available;
119 : }
120 2 : EbAsm GetCpuAsmType()
121 : {
122 2 : EbAsm asm_type = ASM_NON_AVX2;
123 :
124 2 : if (CanUseIntelCore4thGenFeatures() == 1)
125 2 : asm_type = ASM_AVX2;
126 : else
127 : // Need to change to support lower CPU Technologies
128 0 : asm_type = ASM_NON_AVX2;
129 2 : return asm_type;
130 : }
131 :
132 : //Get Number of logical processors
133 4 : uint32_t GetNumProcessors() {
134 : #ifdef _WIN32
135 : SYSTEM_INFO sysinfo;
136 : GetSystemInfo(&sysinfo);
137 : return num_groups == 1 ? sysinfo.dwNumberOfProcessors : sysinfo.dwNumberOfProcessors << 1;
138 : #else
139 4 : return sysconf(_SC_NPROCESSORS_ONLN);
140 : #endif
141 : }
142 :
143 2 : EbErrorType InitThreadManagmentParams() {
144 : #ifdef _WIN32
145 : // Initialize group_affinity structure with Current thread info
146 : GetThreadGroupAffinity(GetCurrentThread(), &group_affinity);
147 : num_groups = (uint8_t)GetActiveProcessorGroupCount();
148 : #elif defined(__linux__)
149 2 : const char* PROCESSORID = "processor";
150 2 : const char* PHYSICALID = "physical id";
151 2 : int processor_id_len = EB_STRLEN(PROCESSORID, 128);
152 2 : int physical_id_len = EB_STRLEN(PHYSICALID, 128);
153 2 : int maxSize = INITIAL_PROCESSOR_GROUP;
154 2 : if (processor_id_len < 0 || processor_id_len >= 128)
155 0 : return EB_ErrorInsufficientResources;
156 2 : if (physical_id_len < 0 || physical_id_len >= 128)
157 0 : return EB_ErrorInsufficientResources;
158 2 : memset(lp_group, 0, INITIAL_PROCESSOR_GROUP * sizeof(processorGroup));
159 :
160 2 : FILE *fin = fopen("/proc/cpuinfo", "r");
161 2 : if (fin) {
162 2 : int processor_id = 0, socket_id = 0;
163 : char line[1024];
164 434 : while (fgets(line, sizeof(line), fin)) {
165 432 : if(strncmp(line, PROCESSORID, processor_id_len) == 0) {
166 16 : char* p = line + processor_id_len;
167 64 : while(*p < '0' || *p > '9') p++;
168 16 : processor_id = strtol(p, NULL, 0);
169 : }
170 432 : if(strncmp(line, PHYSICALID, physical_id_len) == 0) {
171 16 : char* p = line + physical_id_len;
172 64 : while(*p < '0' || *p > '9') p++;
173 16 : socket_id = strtol(p, NULL, 0);
174 16 : if (socket_id < 0) {
175 0 : fclose(fin);
176 0 : return EB_ErrorInsufficientResources;
177 : }
178 16 : if (socket_id + 1 > num_groups)
179 2 : num_groups = socket_id + 1;
180 16 : if (socket_id >= maxSize) {
181 0 : maxSize = maxSize * 2;
182 0 : lp_group = realloc(lp_group, maxSize * sizeof(processorGroup));
183 0 : if (lp_group == NULL)
184 0 : return EB_ErrorInsufficientResources;
185 : }
186 16 : lp_group[socket_id].group[lp_group[socket_id].num++] = processor_id;
187 : }
188 : }
189 2 : fclose(fin);
190 : }
191 : #endif
192 2 : return EB_ErrorNone;
193 : }
194 :
195 : #ifdef _WIN32
196 : uint64_t GetAffinityMask(uint32_t lpnum) {
197 : uint64_t mask = 0x1;
198 : for (uint32_t i = lpnum - 1; i > 0; i--)
199 : mask += (uint64_t)1 << i;
200 : return mask;
201 : }
202 : #endif
203 :
204 2 : void EbSetThreadManagementParameters(EbSvtAv1EncConfiguration *config_ptr)
205 : {
206 : #ifdef _WIN32
207 : uint32_t num_logical_processors = GetNumProcessors();
208 : // For system with a single processor group(no more than 64 logic processors all together)
209 : // Affinity of the thread can be set to one or more logical processors
210 : if (num_groups == 1) {
211 : uint32_t lps = config_ptr->logical_processors == 0 ? num_logical_processors :
212 : config_ptr->logical_processors < num_logical_processors ? config_ptr->logical_processors : num_logical_processors;
213 : group_affinity.Mask = GetAffinityMask(lps);
214 : }
215 : else if (num_groups > 1) { // For system with multiple processor group
216 : if (config_ptr->logical_processors == 0) {
217 : if (config_ptr->target_socket != -1)
218 : group_affinity.Group = config_ptr->target_socket;
219 : }
220 : else {
221 : uint32_t num_lp_per_group = num_logical_processors / num_groups;
222 : if (config_ptr->target_socket == -1) {
223 : if (config_ptr->logical_processors > num_lp_per_group) {
224 : alternate_groups = EB_TRUE;
225 : SVT_LOG("SVT [WARNING]: -lp(logical processors) setting is ignored. Run on both sockets. \n");
226 : }
227 : else
228 : group_affinity.Mask = GetAffinityMask(config_ptr->logical_processors);
229 : }
230 : else {
231 : uint32_t lps = config_ptr->logical_processors == 0 ? num_lp_per_group :
232 : config_ptr->logical_processors < num_lp_per_group ? config_ptr->logical_processors : num_lp_per_group;
233 : group_affinity.Mask = GetAffinityMask(lps);
234 : group_affinity.Group = config_ptr->target_socket;
235 : }
236 : }
237 : }
238 : #elif defined(__linux__)
239 2 : uint32_t num_logical_processors = GetNumProcessors();
240 2 : CPU_ZERO(&group_affinity);
241 :
242 2 : if (num_groups == 1) {
243 2 : uint32_t lps = config_ptr->logical_processors == 0 ? num_logical_processors :
244 0 : config_ptr->logical_processors < num_logical_processors ? config_ptr->logical_processors : num_logical_processors;
245 18 : for (uint32_t i = 0; i < lps; i++)
246 16 : CPU_SET(lp_group[0].group[i], &group_affinity);
247 : }
248 0 : else if (num_groups > 1) {
249 0 : uint32_t num_lp_per_group = num_logical_processors / num_groups;
250 0 : if (config_ptr->logical_processors == 0) {
251 0 : if (config_ptr->target_socket != -1) {
252 0 : for (uint32_t i = 0; i < lp_group[config_ptr->target_socket].num; i++)
253 0 : CPU_SET(lp_group[config_ptr->target_socket].group[i], &group_affinity);
254 : }
255 : }
256 : else {
257 0 : if (config_ptr->target_socket == -1) {
258 0 : uint32_t lps = config_ptr->logical_processors == 0 ? num_logical_processors :
259 0 : config_ptr->logical_processors < num_logical_processors ? config_ptr->logical_processors : num_logical_processors;
260 0 : if (lps > num_lp_per_group) {
261 0 : for (uint32_t i = 0; i < lp_group[0].num; i++)
262 0 : CPU_SET(lp_group[0].group[i], &group_affinity);
263 0 : for (uint32_t i = 0; i < (lps - lp_group[0].num); i++)
264 0 : CPU_SET(lp_group[1].group[i], &group_affinity);
265 : }
266 : else {
267 0 : for (uint32_t i = 0; i < lps; i++)
268 0 : CPU_SET(lp_group[0].group[i], &group_affinity);
269 : }
270 : }
271 : else {
272 0 : uint32_t lps = config_ptr->logical_processors == 0 ? num_lp_per_group :
273 0 : config_ptr->logical_processors < num_lp_per_group ? config_ptr->logical_processors : num_lp_per_group;
274 0 : for (uint32_t i = 0; i < lps; i++)
275 0 : CPU_SET(lp_group[config_ptr->target_socket].group[i], &group_affinity);
276 : }
277 : }
278 : }
279 : #else
280 : UNUSED(config_ptr);
281 : #endif
282 2 : }
283 :
284 : void asmSetConvolveAsmTable(void);
285 : void asmSetConvolveHbdAsmTable(void);
286 : void init_intra_dc_predictors_c_internal(void);
287 : void init_intra_predictors_internal(void);
288 : void eb_av1_init_me_luts(void);
289 :
290 2 : void SwitchToRealTime(){
291 : #ifndef _WIN32
292 :
293 2 : struct sched_param schedParam = {
294 : .sched_priority = 99
295 : };
296 :
297 2 : int32_t retValue = pthread_setschedparam(pthread_self(), SCHED_FIFO, &schedParam);
298 : UNUSED(retValue);
299 : #endif
300 2 : }
301 : #define SINGLE_CORE_COUNT 1
302 : #define CONS_CORE_COUNT 16
303 : #define LOW_SERVER_CORE_COUNT 48
304 : #define MED_SERVER_CORE_COUNT 128
305 : #define HIGH_SERVER_CORE_COUNT 224
306 :
307 2 : int32_t set_parent_pcs(EbSvtAv1EncConfiguration* config, uint32_t core_count, EbInputResolution res_class) {
308 2 : if (config){
309 2 : uint32_t fps = (uint32_t)((config->frame_rate > 1000) ?
310 2 : config->frame_rate >> 16 :
311 : config->frame_rate);
312 2 : uint32_t ppcs_count = fps;
313 2 : uint32_t min_ppcs_count = (2 << config->hierarchical_levels) + 1; // min picture count to start encoding
314 2 : fps = fps > 120 ? 120 : fps;
315 2 : fps = fps < 24 ? 24 : fps;
316 :
317 2 : ppcs_count = MAX(min_ppcs_count, fps);
318 2 : if (core_count <= SINGLE_CORE_COUNT)
319 0 : ppcs_count = min_ppcs_count;
320 : else{
321 2 : if (res_class < INPUT_SIZE_1080i_RANGE){
322 2 : if (core_count < CONS_CORE_COUNT)
323 2 : ppcs_count = ppcs_count * 1; // 1 sec
324 0 : else if (core_count < LOW_SERVER_CORE_COUNT)
325 0 : ppcs_count = (ppcs_count * 3) >> 1; // 1.5 sec
326 0 : else if (core_count < MED_SERVER_CORE_COUNT)
327 0 : ppcs_count = ppcs_count << 1; // 2 sec
328 : else
329 0 : ppcs_count = ppcs_count * 3; // 3 sec
330 0 : } else if (res_class <= INPUT_SIZE_1080p_RANGE) {
331 0 : if (core_count < CONS_CORE_COUNT)
332 0 : ppcs_count = min_ppcs_count;
333 0 : else if (core_count < LOW_SERVER_CORE_COUNT)
334 0 : ppcs_count = (ppcs_count * 3) >> 1; // 1.5 sec
335 0 : else if (core_count < MED_SERVER_CORE_COUNT)
336 0 : ppcs_count = ppcs_count << 1; // 2 sec
337 : else
338 0 : ppcs_count = ppcs_count * 3; // 3 sec
339 : }
340 : else { // 4k res and higher
341 0 : if (core_count < CONS_CORE_COUNT)
342 0 : ppcs_count = min_ppcs_count;
343 0 : else if (core_count < LOW_SERVER_CORE_COUNT)
344 0 : ppcs_count = ppcs_count * 1; // 1 sec
345 0 : else if (core_count < MED_SERVER_CORE_COUNT)
346 0 : ppcs_count = ppcs_count * 1; // 1 sec
347 : else
348 0 : ppcs_count = ppcs_count * 3; // 3 sec
349 : }
350 : }
351 2 : return (int32_t) ppcs_count;
352 : }
353 : else{
354 0 : SVT_LOG("SVT[error]: Configuration struct is corrupted\n");
355 0 : return -1;
356 : }
357 : }
358 2 : EbErrorType load_default_buffer_configuration_settings(
359 : SequenceControlSet *sequence_control_set_ptr){
360 2 : EbErrorType return_error = EB_ErrorNone;
361 4 : uint32_t encDecSegH = (sequence_control_set_ptr->static_config.super_block_size == 128) ?
362 2 : ((sequence_control_set_ptr->max_input_luma_height + 64) / 128) :
363 2 : ((sequence_control_set_ptr->max_input_luma_height + 32) / 64);
364 4 : uint32_t encDecSegW = (sequence_control_set_ptr->static_config.super_block_size == 128) ?
365 2 : ((sequence_control_set_ptr->max_input_luma_width + 64) / 128) :
366 2 : ((sequence_control_set_ptr->max_input_luma_width + 32) / 64);
367 :
368 : #if CABAC_SERIAL
369 : encDecSegH = 1;
370 : encDecSegW = 1;
371 : #endif
372 :
373 2 : uint32_t meSegH = (((sequence_control_set_ptr->max_input_luma_height + 32) / BLOCK_SIZE_64) < 6) ? 1 : 6;
374 2 : uint32_t meSegW = (((sequence_control_set_ptr->max_input_luma_width + 32) / BLOCK_SIZE_64) < 10) ? 1 : 10;
375 :
376 2 : unsigned int lp_count = GetNumProcessors();
377 2 : unsigned int core_count = lp_count;
378 : #if defined(_WIN32) || defined(__linux__)
379 2 : if (sequence_control_set_ptr->static_config.target_socket != -1)
380 0 : core_count /= num_groups;
381 : #endif
382 2 : if (sequence_control_set_ptr->static_config.logical_processors != 0)
383 0 : core_count = sequence_control_set_ptr->static_config.logical_processors < core_count ?
384 : sequence_control_set_ptr->static_config.logical_processors: core_count;
385 :
386 : #ifdef _WIN32
387 : //Handle special case on Windows
388 : //By default, on Windows an application is constrained to a single group
389 : if (sequence_control_set_ptr->static_config.target_socket == -1 &&
390 : sequence_control_set_ptr->static_config.logical_processors == 0)
391 : core_count /= num_groups;
392 :
393 : //Affininty can only be set by group on Windows.
394 : //Run on both sockets if -lp is larger than logical processor per group.
395 : if (sequence_control_set_ptr->static_config.target_socket == -1 &&
396 : sequence_control_set_ptr->static_config.logical_processors > lp_count / num_groups)
397 : core_count = lp_count;
398 : #endif
399 2 : int32_t return_ppcs = set_parent_pcs(&sequence_control_set_ptr->static_config,
400 2 : core_count, sequence_control_set_ptr->input_resolution);
401 2 : if (return_ppcs == -1)
402 0 : return EB_ErrorInsufficientResources;
403 2 : uint32_t input_pic = (uint32_t)return_ppcs;
404 2 : sequence_control_set_ptr->input_buffer_fifo_init_count = input_pic + SCD_LAD + sequence_control_set_ptr->static_config.look_ahead_distance;
405 2 : sequence_control_set_ptr->output_stream_buffer_fifo_init_count =
406 2 : sequence_control_set_ptr->input_buffer_fifo_init_count + 4;
407 :
408 : // ME segments
409 2 : sequence_control_set_ptr->me_segment_row_count_array[0] = meSegH;
410 2 : sequence_control_set_ptr->me_segment_row_count_array[1] = meSegH;
411 2 : sequence_control_set_ptr->me_segment_row_count_array[2] = meSegH;
412 2 : sequence_control_set_ptr->me_segment_row_count_array[3] = meSegH;
413 2 : sequence_control_set_ptr->me_segment_row_count_array[4] = meSegH;
414 2 : sequence_control_set_ptr->me_segment_row_count_array[5] = meSegH;
415 :
416 2 : sequence_control_set_ptr->me_segment_column_count_array[0] = meSegW;
417 2 : sequence_control_set_ptr->me_segment_column_count_array[1] = meSegW;
418 2 : sequence_control_set_ptr->me_segment_column_count_array[2] = meSegW;
419 2 : sequence_control_set_ptr->me_segment_column_count_array[3] = meSegW;
420 2 : sequence_control_set_ptr->me_segment_column_count_array[4] = meSegW;
421 2 : sequence_control_set_ptr->me_segment_column_count_array[5] = meSegW;
422 :
423 : // EncDec segments
424 2 : sequence_control_set_ptr->enc_dec_segment_row_count_array[0] = encDecSegH;
425 2 : sequence_control_set_ptr->enc_dec_segment_row_count_array[1] = encDecSegH;
426 2 : sequence_control_set_ptr->enc_dec_segment_row_count_array[2] = encDecSegH;
427 2 : sequence_control_set_ptr->enc_dec_segment_row_count_array[3] = encDecSegH;
428 2 : sequence_control_set_ptr->enc_dec_segment_row_count_array[4] = encDecSegH;
429 2 : sequence_control_set_ptr->enc_dec_segment_row_count_array[5] = encDecSegH;
430 :
431 2 : sequence_control_set_ptr->enc_dec_segment_col_count_array[0] = encDecSegW;
432 2 : sequence_control_set_ptr->enc_dec_segment_col_count_array[1] = encDecSegW;
433 2 : sequence_control_set_ptr->enc_dec_segment_col_count_array[2] = encDecSegW;
434 2 : sequence_control_set_ptr->enc_dec_segment_col_count_array[3] = encDecSegW;
435 2 : sequence_control_set_ptr->enc_dec_segment_col_count_array[4] = encDecSegW;
436 2 : sequence_control_set_ptr->enc_dec_segment_col_count_array[5] = encDecSegW;
437 :
438 2 : sequence_control_set_ptr->cdef_segment_column_count = meSegW;
439 2 : sequence_control_set_ptr->cdef_segment_row_count = meSegH;
440 :
441 : //since restoration unit size is same for Luma and Chroma, Luma segments and chroma segments do not correspond to the same area!
442 : //to keep proper processing, segments have to be configured based on chroma resolution.
443 2 : uint32_t unit_size = 256;
444 2 : uint32_t rest_seg_w = MAX((sequence_control_set_ptr->max_input_luma_width /2 + (unit_size >> 1)) / unit_size, 1);
445 2 : uint32_t rest_seg_h = MAX((sequence_control_set_ptr->max_input_luma_height/2 + (unit_size >> 1)) / unit_size, 1);
446 2 : sequence_control_set_ptr->rest_segment_column_count = MIN(rest_seg_w,6);
447 2 : sequence_control_set_ptr->rest_segment_row_count = MIN(rest_seg_h,4);
448 :
449 2 : sequence_control_set_ptr->tf_segment_column_count = meSegW;//1;//
450 2 : sequence_control_set_ptr->tf_segment_row_count = meSegH;//1;//
451 : //#====================== Data Structures and Picture Buffers ======================
452 2 : sequence_control_set_ptr->picture_control_set_pool_init_count = input_pic + SCD_LAD + sequence_control_set_ptr->static_config.look_ahead_distance;
453 2 : if (sequence_control_set_ptr->static_config.enable_overlays)
454 0 : sequence_control_set_ptr->picture_control_set_pool_init_count = MAX(sequence_control_set_ptr->picture_control_set_pool_init_count,
455 : sequence_control_set_ptr->static_config.look_ahead_distance + // frames in the LAD
456 : sequence_control_set_ptr->static_config.look_ahead_distance / (1 << sequence_control_set_ptr->static_config.hierarchical_levels) + 1 + // number of overlayes in the LAD
457 : ((1 << sequence_control_set_ptr->static_config.hierarchical_levels) + SCD_LAD) * 2 +// minigop formation in PD + SCD_LAD *(normal pictures + potential pictures )
458 : (1 << sequence_control_set_ptr->static_config.hierarchical_levels)); // minigop in PM
459 2 : sequence_control_set_ptr->picture_control_set_pool_init_count_child = MAX(MAX(MIN(3, core_count/2), core_count / 6), 1);
460 2 : sequence_control_set_ptr->reference_picture_buffer_init_count = MAX((uint32_t)(input_pic >> 1),
461 2 : (uint32_t)((1 << sequence_control_set_ptr->static_config.hierarchical_levels) + 2)) +
462 2 : sequence_control_set_ptr->static_config.look_ahead_distance + SCD_LAD;
463 2 : sequence_control_set_ptr->pa_reference_picture_buffer_init_count = MAX((uint32_t)(input_pic >> 1),
464 2 : (uint32_t)((1 << sequence_control_set_ptr->static_config.hierarchical_levels) + 2)) +
465 2 : sequence_control_set_ptr->static_config.look_ahead_distance + SCD_LAD;
466 2 : sequence_control_set_ptr->output_recon_buffer_fifo_init_count = sequence_control_set_ptr->reference_picture_buffer_init_count;
467 4 : sequence_control_set_ptr->overlay_input_picture_buffer_init_count = sequence_control_set_ptr->static_config.enable_overlays ?
468 2 : (2 << sequence_control_set_ptr->static_config.hierarchical_levels) + SCD_LAD : 1;
469 :
470 : //#====================== Inter process Fifos ======================
471 2 : sequence_control_set_ptr->resource_coordination_fifo_init_count = 300;
472 2 : sequence_control_set_ptr->picture_analysis_fifo_init_count = 300;
473 2 : sequence_control_set_ptr->picture_decision_fifo_init_count = 300;
474 2 : sequence_control_set_ptr->initial_rate_control_fifo_init_count = 300;
475 2 : sequence_control_set_ptr->picture_demux_fifo_init_count = 300;
476 2 : sequence_control_set_ptr->rate_control_tasks_fifo_init_count = 300;
477 2 : sequence_control_set_ptr->rate_control_fifo_init_count = 301;
478 2 : sequence_control_set_ptr->mode_decision_configuration_fifo_init_count = 300;
479 2 : sequence_control_set_ptr->motion_estimation_fifo_init_count = 300;
480 2 : sequence_control_set_ptr->entropy_coding_fifo_init_count = 300;
481 2 : sequence_control_set_ptr->enc_dec_fifo_init_count = 300;
482 2 : sequence_control_set_ptr->dlf_fifo_init_count = 300;
483 2 : sequence_control_set_ptr->cdef_fifo_init_count = 300;
484 2 : sequence_control_set_ptr->rest_fifo_init_count = 300;
485 : //#====================== Processes number ======================
486 2 : sequence_control_set_ptr->total_process_init_count = 0;
487 2 : if (core_count > 1){
488 2 : sequence_control_set_ptr->total_process_init_count += (sequence_control_set_ptr->picture_analysis_process_init_count = MAX(MIN(15, core_count >> 1), core_count / 6));
489 2 : sequence_control_set_ptr->total_process_init_count += (sequence_control_set_ptr->motion_estimation_process_init_count = MAX(MIN(20, core_count >> 1), core_count / 3));//1);//
490 2 : sequence_control_set_ptr->total_process_init_count += (sequence_control_set_ptr->source_based_operations_process_init_count = MAX(MIN(3, core_count >> 1), core_count / 12));
491 2 : sequence_control_set_ptr->total_process_init_count += (sequence_control_set_ptr->mode_decision_configuration_process_init_count = MAX(MIN(3, core_count >> 1), core_count / 12));
492 2 : sequence_control_set_ptr->total_process_init_count += (sequence_control_set_ptr->enc_dec_process_init_count = MAX(MIN(40, core_count >> 1), core_count));
493 2 : sequence_control_set_ptr->total_process_init_count += (sequence_control_set_ptr->entropy_coding_process_init_count = MAX(MIN(3, core_count >> 1), core_count / 12));
494 2 : sequence_control_set_ptr->total_process_init_count += (sequence_control_set_ptr->dlf_process_init_count = MAX(MIN(40, core_count >> 1), core_count));
495 2 : sequence_control_set_ptr->total_process_init_count += (sequence_control_set_ptr->cdef_process_init_count = MAX(MIN(40, core_count >> 1), core_count));
496 2 : sequence_control_set_ptr->total_process_init_count += (sequence_control_set_ptr->rest_process_init_count = MAX(MIN(40, core_count >> 1), core_count));
497 : }else{
498 0 : sequence_control_set_ptr->total_process_init_count += (sequence_control_set_ptr->picture_analysis_process_init_count = 1);
499 0 : sequence_control_set_ptr->total_process_init_count += (sequence_control_set_ptr->motion_estimation_process_init_count = 1);
500 0 : sequence_control_set_ptr->total_process_init_count += (sequence_control_set_ptr->source_based_operations_process_init_count = 1);
501 0 : sequence_control_set_ptr->total_process_init_count += (sequence_control_set_ptr->mode_decision_configuration_process_init_count = 1);
502 0 : sequence_control_set_ptr->total_process_init_count += (sequence_control_set_ptr->enc_dec_process_init_count = 1);
503 0 : sequence_control_set_ptr->total_process_init_count += (sequence_control_set_ptr->entropy_coding_process_init_count = 1);
504 0 : sequence_control_set_ptr->total_process_init_count += (sequence_control_set_ptr->dlf_process_init_count = 1);
505 0 : sequence_control_set_ptr->total_process_init_count += (sequence_control_set_ptr->cdef_process_init_count = 1);
506 0 : sequence_control_set_ptr->total_process_init_count += (sequence_control_set_ptr->rest_process_init_count = 1);
507 : }
508 :
509 2 : sequence_control_set_ptr->total_process_init_count += 6; // single processes count
510 2 : printf("Number of logical cores available: %u\nNumber of PPCS %u\n", core_count, sequence_control_set_ptr->picture_control_set_pool_init_count);
511 :
512 2 : return return_error;
513 : }
514 : // Rate Control
515 : static RateControlPorts rateControlPorts[] = {
516 : {RATE_CONTROL_INPUT_PORT_PICTURE_MANAGER, 0},
517 : {RATE_CONTROL_INPUT_PORT_PACKETIZATION, 0},
518 : {RATE_CONTROL_INPUT_PORT_ENTROPY_CODING, 0},
519 : {RATE_CONTROL_INPUT_PORT_INVALID, 0}
520 : };
521 : // Rate Control
522 10 : static uint32_t RateControlPortLookup(
523 : RateControlInputPortTypes type,
524 : uint32_t portTypeIndex){
525 10 : uint32_t portIndex = 0;
526 10 : uint32_t portCount = 0;
527 :
528 24 : while ((type != rateControlPorts[portIndex].type) && (type != RATE_CONTROL_INPUT_PORT_INVALID))
529 14 : portCount += rateControlPorts[portIndex++].count;
530 10 : return (portCount + portTypeIndex);
531 : }
532 : // Rate Control
533 2 : static uint32_t RateControlPortTotalCount(void){
534 2 : uint32_t portIndex = 0;
535 2 : uint32_t total_count = 0;
536 :
537 8 : while (rateControlPorts[portIndex].type != RATE_CONTROL_INPUT_PORT_INVALID)
538 6 : total_count += rateControlPorts[portIndex++].count;
539 2 : return total_count;
540 : }
541 :
542 : // EncDec
543 : typedef struct {
544 : int32_t type;
545 : uint32_t count;
546 : } EncDecPorts_t;
547 : static EncDecPorts_t encDecPorts[] = {
548 : {ENCDEC_INPUT_PORT_MDC, 0},
549 : {ENCDEC_INPUT_PORT_ENCDEC, 0},
550 : {ENCDEC_INPUT_PORT_INVALID, 0}
551 : };
552 :
553 : /*****************************************
554 : * Input Port Lookup
555 : *****************************************/
556 : // EncDec
557 22 : static uint32_t EncDecPortLookup(
558 : int32_t type,
559 : uint32_t portTypeIndex)
560 : {
561 22 : uint32_t portIndex = 0;
562 22 : uint32_t portCount = 0;
563 :
564 38 : while ((type != encDecPorts[portIndex].type) && (type != ENCDEC_INPUT_PORT_INVALID))
565 16 : portCount += encDecPorts[portIndex++].count;
566 22 : return (portCount + portTypeIndex);
567 : }
568 : // EncDec
569 2 : static uint32_t EncDecPortTotalCount(void){
570 2 : uint32_t portIndex = 0;
571 2 : uint32_t total_count = 0;
572 :
573 6 : while (encDecPorts[portIndex].type != ENCDEC_INPUT_PORT_INVALID)
574 4 : total_count += encDecPorts[portIndex++].count;
575 2 : return total_count;
576 : }
577 : /*****************************************
578 : * Input Port Total Count
579 : *****************************************/
580 :
581 : void lib_svt_encoder_send_error_exit(
582 : EbPtr hComponent,
583 : uint32_t error_code);
584 :
585 2 : static void eb_enc_handle_stop_threads(EbEncHandle *enc_handle_ptr)
586 : {
587 2 : SequenceControlSet* control_set_ptr = enc_handle_ptr->sequence_control_set_instance_array[0]->sequence_control_set_ptr;
588 : // Resource Coordination
589 2 : EB_DESTROY_THREAD(enc_handle_ptr->resource_coordination_thread_handle);
590 18 : EB_DESTROY_THREAD_ARRAY(enc_handle_ptr->picture_analysis_thread_handle_array,control_set_ptr->picture_analysis_process_init_count);
591 :
592 : // Picture Decision
593 2 : EB_DESTROY_THREAD(enc_handle_ptr->picture_decision_thread_handle);
594 :
595 : // Motion Estimation
596 18 : EB_DESTROY_THREAD_ARRAY(enc_handle_ptr->motion_estimation_thread_handle_array, control_set_ptr->motion_estimation_process_init_count);
597 :
598 : // Initial Rate Control
599 2 : EB_DESTROY_THREAD(enc_handle_ptr->initial_rate_control_thread_handle);
600 :
601 : // Source Based Oprations
602 14 : EB_DESTROY_THREAD_ARRAY(enc_handle_ptr->source_based_operations_thread_handle_array, control_set_ptr->source_based_operations_process_init_count);
603 :
604 : // Picture Manager
605 2 : EB_DESTROY_THREAD(enc_handle_ptr->picture_manager_thread_handle);
606 :
607 : // Rate Control
608 2 : EB_DESTROY_THREAD(enc_handle_ptr->rate_control_thread_handle);
609 :
610 : // Mode Decision Configuration Process
611 14 : EB_DESTROY_THREAD_ARRAY(enc_handle_ptr->mode_decision_configuration_thread_handle_array, control_set_ptr->mode_decision_configuration_process_init_count);
612 :
613 : // EncDec Process
614 34 : EB_DESTROY_THREAD_ARRAY(enc_handle_ptr->enc_dec_thread_handle_array, control_set_ptr->enc_dec_process_init_count);
615 :
616 : // Dlf Process
617 34 : EB_DESTROY_THREAD_ARRAY(enc_handle_ptr->dlf_thread_handle_array, control_set_ptr->dlf_process_init_count);
618 :
619 : // Cdef Process
620 34 : EB_DESTROY_THREAD_ARRAY(enc_handle_ptr->cdef_thread_handle_array, control_set_ptr->cdef_process_init_count);
621 :
622 : // Rest Process
623 34 : EB_DESTROY_THREAD_ARRAY(enc_handle_ptr->rest_thread_handle_array, control_set_ptr->rest_process_init_count);
624 :
625 : // Entropy Coding Process
626 14 : EB_DESTROY_THREAD_ARRAY(enc_handle_ptr->entropy_coding_thread_handle_array, control_set_ptr->entropy_coding_process_init_count);
627 :
628 : // Packetization
629 2 : EB_DESTROY_THREAD(enc_handle_ptr->packetization_thread_handle);
630 2 : }
631 : /**********************************
632 : * Encoder Library Handle Deonstructor
633 : **********************************/
634 2 : static void eb_enc_handle_dctor(EbPtr p)
635 : {
636 2 : EbEncHandle *enc_handle_ptr = (EbEncHandle *)p;
637 :
638 2 : eb_enc_handle_stop_threads(enc_handle_ptr);
639 4 : EB_FREE_PTR_ARRAY(enc_handle_ptr->app_callback_ptr_array, enc_handle_ptr->encode_instance_total_count);
640 2 : EB_DELETE(enc_handle_ptr->sequence_control_set_pool_ptr);
641 4 : EB_DELETE_PTR_ARRAY(enc_handle_ptr->picture_parent_control_set_pool_ptr_array, enc_handle_ptr->encode_instance_total_count);
642 :
643 4 : EB_DELETE_PTR_ARRAY(enc_handle_ptr->picture_control_set_pool_ptr_array, enc_handle_ptr->encode_instance_total_count);
644 4 : EB_DELETE_PTR_ARRAY(enc_handle_ptr->pa_reference_picture_pool_ptr_array, enc_handle_ptr->encode_instance_total_count);
645 4 : EB_DELETE_PTR_ARRAY(enc_handle_ptr->overlay_input_picture_pool_ptr_array, enc_handle_ptr->encode_instance_total_count);
646 2 : EB_DELETE(enc_handle_ptr->input_buffer_resource_ptr);
647 4 : EB_DELETE_PTR_ARRAY(enc_handle_ptr->output_stream_buffer_resource_ptr_array, enc_handle_ptr->encode_instance_total_count);
648 2 : EB_DELETE_PTR_ARRAY(enc_handle_ptr->output_recon_buffer_resource_ptr_array, enc_handle_ptr->encode_instance_total_count);
649 2 : EB_DELETE(enc_handle_ptr->resource_coordination_results_resource_ptr);
650 2 : EB_DELETE(enc_handle_ptr->picture_analysis_results_resource_ptr);
651 2 : EB_DELETE(enc_handle_ptr->picture_decision_results_resource_ptr);
652 2 : EB_DELETE(enc_handle_ptr->motion_estimation_results_resource_ptr);
653 2 : EB_DELETE(enc_handle_ptr->initial_rate_control_results_resource_ptr);
654 2 : EB_DELETE(enc_handle_ptr->picture_demux_results_resource_ptr);
655 2 : EB_DELETE(enc_handle_ptr->rate_control_tasks_resource_ptr);
656 2 : EB_DELETE(enc_handle_ptr->rate_control_results_resource_ptr);
657 2 : EB_DELETE(enc_handle_ptr->enc_dec_tasks_resource_ptr);
658 2 : EB_DELETE(enc_handle_ptr->enc_dec_results_resource_ptr);
659 2 : EB_DELETE(enc_handle_ptr->dlf_results_resource_ptr);
660 2 : EB_DELETE(enc_handle_ptr->cdef_results_resource_ptr);
661 2 : EB_DELETE(enc_handle_ptr->rest_results_resource_ptr);
662 2 : EB_DELETE(enc_handle_ptr->entropy_coding_results_resource_ptr);
663 :
664 2 : EB_DELETE(enc_handle_ptr->resource_coordination_context_ptr);
665 10 : EB_DELETE_PTR_ARRAY(enc_handle_ptr->picture_analysis_context_ptr_array, enc_handle_ptr->sequence_control_set_instance_array[0]->sequence_control_set_ptr->picture_analysis_process_init_count);
666 10 : EB_DELETE_PTR_ARRAY(enc_handle_ptr->motion_estimation_context_ptr_array, enc_handle_ptr->sequence_control_set_instance_array[0]->sequence_control_set_ptr->motion_estimation_process_init_count);
667 8 : EB_DELETE_PTR_ARRAY(enc_handle_ptr->source_based_operations_context_ptr_array, enc_handle_ptr->sequence_control_set_instance_array[0]->sequence_control_set_ptr->source_based_operations_process_init_count);
668 8 : EB_DELETE_PTR_ARRAY(enc_handle_ptr->mode_decision_configuration_context_ptr_array, enc_handle_ptr->sequence_control_set_instance_array[0]->sequence_control_set_ptr->mode_decision_configuration_process_init_count);
669 18 : EB_DELETE_PTR_ARRAY(enc_handle_ptr->enc_dec_context_ptr_array, enc_handle_ptr->sequence_control_set_instance_array[0]->sequence_control_set_ptr->enc_dec_process_init_count);
670 18 : EB_DELETE_PTR_ARRAY(enc_handle_ptr->dlf_context_ptr_array, enc_handle_ptr->sequence_control_set_instance_array[0]->sequence_control_set_ptr->dlf_process_init_count);
671 18 : EB_DELETE_PTR_ARRAY(enc_handle_ptr->cdef_context_ptr_array, enc_handle_ptr->sequence_control_set_instance_array[0]->sequence_control_set_ptr->cdef_process_init_count);
672 18 : EB_DELETE_PTR_ARRAY(enc_handle_ptr->rest_context_ptr_array, enc_handle_ptr->sequence_control_set_instance_array[0]->sequence_control_set_ptr->rest_process_init_count);
673 8 : EB_DELETE_PTR_ARRAY(enc_handle_ptr->entropy_coding_context_ptr_array, enc_handle_ptr->sequence_control_set_instance_array[0]->sequence_control_set_ptr->entropy_coding_process_init_count);
674 4 : EB_DELETE_PTR_ARRAY(enc_handle_ptr->sequence_control_set_instance_array, enc_handle_ptr->encode_instance_total_count);
675 2 : EB_DELETE(enc_handle_ptr->picture_decision_context_ptr);
676 2 : EB_DELETE(enc_handle_ptr->initial_rate_control_context_ptr);
677 2 : EB_DELETE(enc_handle_ptr->picture_manager_context_ptr);
678 2 : EB_DELETE(enc_handle_ptr->rate_control_context_ptr);
679 2 : EB_DELETE(enc_handle_ptr->packetization_context_ptr);
680 4 : EB_DELETE_PTR_ARRAY(enc_handle_ptr->reference_picture_pool_ptr_array, enc_handle_ptr->encode_instance_total_count);
681 :
682 2 : EB_FREE_ARRAY(enc_handle_ptr->picture_parent_control_set_pool_producer_fifo_ptr_dbl_array);
683 2 : EB_FREE_ARRAY(enc_handle_ptr->picture_control_set_pool_producer_fifo_ptr_dbl_array);
684 2 : EB_FREE_ARRAY(enc_handle_ptr->overlay_input_picture_pool_producer_fifo_ptr_dbl_array);
685 2 : EB_FREE_ARRAY(enc_handle_ptr->reference_picture_pool_producer_fifo_ptr_dbl_array);
686 2 : EB_FREE_ARRAY(enc_handle_ptr->pa_reference_picture_pool_producer_fifo_ptr_dbl_array);
687 2 : EB_FREE_ARRAY(enc_handle_ptr->output_stream_buffer_producer_fifo_ptr_dbl_array);
688 2 : EB_FREE_ARRAY(enc_handle_ptr->output_stream_buffer_consumer_fifo_ptr_dbl_array);
689 2 : EB_FREE_ARRAY(enc_handle_ptr->output_recon_buffer_producer_fifo_ptr_dbl_array);
690 2 : EB_FREE_ARRAY(enc_handle_ptr->output_recon_buffer_consumer_fifo_ptr_dbl_array);
691 :
692 2 : }
693 :
694 : /**********************************
695 : * Encoder Library Handle Constructor
696 : **********************************/
697 2 : static EbErrorType eb_enc_handle_ctor(
698 : EbEncHandle *enc_handle_ptr,
699 : EbComponentType * ebHandlePtr)
700 : {
701 2 : EbErrorType return_error = EB_ErrorNone;
702 :
703 2 : enc_handle_ptr->dctor = eb_enc_handle_dctor;
704 :
705 2 : return_error = InitThreadManagmentParams();
706 :
707 2 : if (return_error == EB_ErrorInsufficientResources)
708 0 : return EB_ErrorInsufficientResources;
709 2 : enc_handle_ptr->encode_instance_total_count = EB_EncodeInstancesTotalCount;
710 2 : enc_handle_ptr->compute_segments_total_count_array = EB_ComputeSegmentInitCount;
711 : // Config Set Count
712 2 : enc_handle_ptr->sequence_control_set_pool_total_count = EB_SequenceControlSetPoolInitCount;
713 :
714 : // Initialize Callbacks
715 2 : EB_ALLOC_PTR_ARRAY(enc_handle_ptr->app_callback_ptr_array, enc_handle_ptr->encode_instance_total_count);
716 2 : EB_MALLOC(enc_handle_ptr->app_callback_ptr_array[0], sizeof(EbCallback));
717 2 : enc_handle_ptr->app_callback_ptr_array[0]->ErrorHandler = lib_svt_encoder_send_error_exit;
718 2 : enc_handle_ptr->app_callback_ptr_array[0]->handle = ebHandlePtr;
719 :
720 : // Initialize Sequence Control Set Instance Array
721 2 : EB_ALLOC_PTR_ARRAY(enc_handle_ptr->sequence_control_set_instance_array, enc_handle_ptr->encode_instance_total_count);
722 2 : EB_NEW(enc_handle_ptr->sequence_control_set_instance_array[0], eb_sequence_control_set_instance_ctor);
723 2 : return EB_ErrorNone;
724 : }
725 :
726 : EbErrorType EbInputBufferHeaderCreator(
727 : EbPtr *objectDblPtr,
728 : EbPtr objectInitDataPtr);
729 :
730 : EbErrorType EbOutputReconBufferHeaderCreator(
731 : EbPtr *objectDblPtr,
732 : EbPtr objectInitDataPtr);
733 :
734 : EbErrorType EbOutputBufferHeaderCreator(
735 : EbPtr *objectDblPtr,
736 : EbPtr objectInitDataPtr);
737 :
738 : void EbInputBufferHeaderDestoryer( EbPtr p);
739 : void EbOutputReconBufferHeaderDestoryer( EbPtr p);
740 : void EbOutputBufferHeaderDestoryer( EbPtr p);
741 :
742 :
743 600 : EbErrorType DlfResultsCtor(
744 : DlfResults *context_ptr,
745 : EbPtr object_init_data_ptr)
746 : {
747 : (void)context_ptr;
748 : (void)object_init_data_ptr;
749 :
750 600 : return EB_ErrorNone;
751 : }
752 :
753 600 : EbErrorType DlfResultsCreator(
754 : EbPtr *object_dbl_ptr,
755 : EbPtr object_init_data_ptr)
756 : {
757 : DlfResults* obj;
758 :
759 600 : *object_dbl_ptr = NULL;
760 600 : EB_NEW(obj, DlfResultsCtor, object_init_data_ptr);
761 600 : *object_dbl_ptr = obj;
762 :
763 600 : return EB_ErrorNone;
764 : }
765 :
766 600 : EbErrorType CdefResultsCtor(
767 : CdefResults *context_ptr,
768 : EbPtr object_init_data_ptr)
769 : {
770 : (void)context_ptr;
771 : (void)object_init_data_ptr;
772 :
773 600 : return EB_ErrorNone;
774 : }
775 :
776 600 : EbErrorType CdefResultsCreator(
777 : EbPtr *object_dbl_ptr,
778 : EbPtr object_init_data_ptr)
779 : {
780 : CdefResults* obj;
781 :
782 600 : *object_dbl_ptr = NULL;
783 600 : EB_NEW(obj, CdefResultsCtor, object_init_data_ptr);
784 600 : *object_dbl_ptr = obj;
785 :
786 600 : return EB_ErrorNone;
787 : }
788 :
789 600 : EbErrorType RestResultsCtor(
790 : RestResults *context_ptr,
791 : EbPtr object_init_data_ptr)
792 : {
793 : (void)context_ptr;
794 : (void)object_init_data_ptr;
795 :
796 600 : return EB_ErrorNone;
797 : }
798 :
799 600 : EbErrorType RestResultsCreator(
800 : EbPtr *object_dbl_ptr,
801 : EbPtr object_init_data_ptr)
802 : {
803 : RestResults* obj;
804 :
805 600 : *object_dbl_ptr = NULL;
806 600 : EB_NEW(obj, RestResultsCtor, object_init_data_ptr);
807 600 : *object_dbl_ptr = obj;
808 :
809 600 : return EB_ErrorNone;
810 : }
811 :
812 : void init_fn_ptr(void);
813 : extern void av1_init_wedge_masks(void);
814 : /**********************************
815 : * Initialize Encoder Library
816 : **********************************/
817 : #ifdef __GNUC__
818 : __attribute__((visibility("default")))
819 : #endif
820 2 : EB_API EbErrorType eb_init_encoder(EbComponentType *svt_enc_component)
821 : {
822 2 : if(svt_enc_component == NULL)
823 0 : return EB_ErrorBadParameter;
824 2 : EbEncHandle *enc_handle_ptr = (EbEncHandle*)svt_enc_component->p_component_private;
825 2 : EbErrorType return_error = EB_ErrorNone;
826 : uint32_t instance_index;
827 : uint32_t processIndex;
828 : uint32_t max_picture_width;
829 2 : EbBool is16bit = (EbBool)(enc_handle_ptr->sequence_control_set_instance_array[0]->sequence_control_set_ptr->static_config.encoder_bit_depth > EB_8BIT);
830 2 : EbColorFormat color_format = enc_handle_ptr->sequence_control_set_instance_array[0]->sequence_control_set_ptr->static_config.encoder_color_format;
831 : SequenceControlSet* control_set_ptr;
832 :
833 : /************************************
834 : * Plateform detection
835 : ************************************/
836 2 : if (enc_handle_ptr->sequence_control_set_instance_array[0]->sequence_control_set_ptr->static_config.asm_type == 1)
837 2 : enc_handle_ptr->sequence_control_set_instance_array[0]->encode_context_ptr->asm_type = GetCpuAsmType();
838 : else
839 0 : enc_handle_ptr->sequence_control_set_instance_array[0]->encode_context_ptr->asm_type = enc_handle_ptr->sequence_control_set_instance_array[0]->sequence_control_set_ptr->static_config.asm_type;
840 2 : setup_rtcd_internal(enc_handle_ptr->sequence_control_set_instance_array[0]->encode_context_ptr->asm_type);
841 2 : asmSetConvolveAsmTable();
842 :
843 2 : init_intra_dc_predictors_c_internal();
844 :
845 2 : asmSetConvolveHbdAsmTable();
846 :
847 2 : init_intra_predictors_internal();
848 : EbSequenceControlSetInitData scs_init;
849 2 : scs_init.sb_size = enc_handle_ptr->sequence_control_set_instance_array[0]->sequence_control_set_ptr->static_config.super_block_size;
850 :
851 2 : build_blk_geom(scs_init.sb_size == 128);
852 :
853 2 : eb_av1_init_me_luts();
854 2 : init_fn_ptr();
855 2 : av1_init_wedge_masks();
856 : /************************************
857 : * Sequence Control Set
858 : ************************************/
859 2 : EB_NEW(enc_handle_ptr->sequence_control_set_pool_ptr,
860 : eb_system_resource_ctor,
861 : enc_handle_ptr->sequence_control_set_pool_total_count,
862 : 1,
863 : 0,
864 : &enc_handle_ptr->sequence_control_set_pool_producer_fifo_ptr_array,
865 : (EbFifo ***)EB_NULL,
866 : EB_FALSE,
867 : eb_sequence_control_set_creator,
868 : &scs_init,
869 : NULL);
870 :
871 : /************************************
872 : * Picture Control Set: Parent
873 : ************************************/
874 2 : EB_ALLOC_PTR_ARRAY(enc_handle_ptr->picture_parent_control_set_pool_ptr_array, enc_handle_ptr->encode_instance_total_count);
875 :
876 2 : EB_MALLOC_ARRAY(enc_handle_ptr->picture_parent_control_set_pool_producer_fifo_ptr_dbl_array, enc_handle_ptr->encode_instance_total_count);
877 :
878 4 : for (instance_index = 0; instance_index < enc_handle_ptr->encode_instance_total_count; ++instance_index) {
879 : // The segment Width & Height Arrays are in units of LCUs, not samples
880 : PictureControlSetInitData inputData;
881 :
882 2 : inputData.picture_width = enc_handle_ptr->sequence_control_set_instance_array[instance_index]->sequence_control_set_ptr->max_input_luma_width;
883 2 : inputData.picture_height = enc_handle_ptr->sequence_control_set_instance_array[instance_index]->sequence_control_set_ptr->max_input_luma_height;
884 2 : inputData.left_padding = enc_handle_ptr->sequence_control_set_instance_array[instance_index]->sequence_control_set_ptr->left_padding;
885 2 : inputData.right_padding = enc_handle_ptr->sequence_control_set_instance_array[instance_index]->sequence_control_set_ptr->right_padding;
886 2 : inputData.top_padding = enc_handle_ptr->sequence_control_set_instance_array[instance_index]->sequence_control_set_ptr->top_padding;
887 2 : inputData.bot_padding = enc_handle_ptr->sequence_control_set_instance_array[instance_index]->sequence_control_set_ptr->bot_padding;
888 2 : inputData.bit_depth = enc_handle_ptr->sequence_control_set_instance_array[instance_index]->sequence_control_set_ptr->encoder_bit_depth;
889 2 : inputData.color_format = color_format;
890 2 : inputData.sb_sz = enc_handle_ptr->sequence_control_set_instance_array[instance_index]->sequence_control_set_ptr->sb_sz;
891 2 : inputData.max_depth = enc_handle_ptr->sequence_control_set_instance_array[instance_index]->sequence_control_set_ptr->max_sb_depth;
892 2 : inputData.ten_bit_format = enc_handle_ptr->sequence_control_set_instance_array[instance_index]->sequence_control_set_ptr->static_config.ten_bit_format;
893 2 : inputData.compressed_ten_bit_format = enc_handle_ptr->sequence_control_set_instance_array[instance_index]->sequence_control_set_ptr->static_config.compressed_ten_bit_format;
894 2 : inputData.enc_mode = enc_handle_ptr->sequence_control_set_instance_array[instance_index]->sequence_control_set_ptr->static_config.enc_mode;
895 2 : inputData.speed_control = (uint8_t)enc_handle_ptr->sequence_control_set_instance_array[instance_index]->sequence_control_set_ptr->static_config.speed_control_flag;
896 2 : inputData.hbd_mode_decision = enc_handle_ptr->sequence_control_set_instance_array[instance_index]->sequence_control_set_ptr->static_config.enable_hbd_mode_decision;
897 2 : inputData.film_grain_noise_level = enc_handle_ptr->sequence_control_set_instance_array[0]->sequence_control_set_ptr->static_config.film_grain_denoise_strength;
898 2 : inputData.bit_depth = enc_handle_ptr->sequence_control_set_instance_array[instance_index]->sequence_control_set_ptr->static_config.encoder_bit_depth;
899 :
900 2 : inputData.ext_block_flag = (uint8_t)enc_handle_ptr->sequence_control_set_instance_array[instance_index]->sequence_control_set_ptr->static_config.ext_block_flag;
901 :
902 2 : inputData.in_loop_me_flag = (uint8_t)enc_handle_ptr->sequence_control_set_instance_array[instance_index]->sequence_control_set_ptr->static_config.in_loop_me_flag;
903 2 : inputData.mrp_mode = enc_handle_ptr->sequence_control_set_instance_array[instance_index]->sequence_control_set_ptr->mrp_mode;
904 2 : inputData.nsq_present = enc_handle_ptr->sequence_control_set_instance_array[instance_index]->sequence_control_set_ptr->nsq_present;
905 2 : EB_NEW(
906 : enc_handle_ptr->picture_parent_control_set_pool_ptr_array[instance_index],
907 : eb_system_resource_ctor,
908 : enc_handle_ptr->sequence_control_set_instance_array[instance_index]->sequence_control_set_ptr->picture_control_set_pool_init_count,//enc_handle_ptr->picture_control_set_pool_total_count,
909 : 1,
910 : 0,
911 : &enc_handle_ptr->picture_parent_control_set_pool_producer_fifo_ptr_dbl_array[instance_index],
912 : (EbFifo ***)EB_NULL,
913 : EB_FALSE,
914 : picture_parent_control_set_creator,
915 : &inputData,
916 : NULL);
917 : }
918 :
919 : /************************************
920 : * Picture Control Set: Child
921 : ************************************/
922 2 : EB_ALLOC_PTR_ARRAY(enc_handle_ptr->picture_control_set_pool_ptr_array, enc_handle_ptr->encode_instance_total_count);
923 :
924 2 : EB_MALLOC_ARRAY(enc_handle_ptr->picture_control_set_pool_producer_fifo_ptr_dbl_array, enc_handle_ptr->encode_instance_total_count);
925 :
926 4 : for (instance_index = 0; instance_index < enc_handle_ptr->encode_instance_total_count; ++instance_index) {
927 : // The segment Width & Height Arrays are in units of LCUs, not samples
928 : PictureControlSetInitData inputData;
929 : unsigned i;
930 :
931 2 : inputData.enc_dec_segment_col = 0;
932 2 : inputData.enc_dec_segment_row = 0;
933 12 : for (i = 0; i <= enc_handle_ptr->sequence_control_set_instance_array[instance_index]->sequence_control_set_ptr->static_config.hierarchical_levels; ++i) {
934 10 : inputData.enc_dec_segment_col = enc_handle_ptr->sequence_control_set_instance_array[instance_index]->sequence_control_set_ptr->enc_dec_segment_col_count_array[i] > inputData.enc_dec_segment_col ?
935 2 : (uint16_t)enc_handle_ptr->sequence_control_set_instance_array[instance_index]->sequence_control_set_ptr->enc_dec_segment_col_count_array[i] :
936 : inputData.enc_dec_segment_col;
937 12 : inputData.enc_dec_segment_row = enc_handle_ptr->sequence_control_set_instance_array[instance_index]->sequence_control_set_ptr->enc_dec_segment_row_count_array[i] > inputData.enc_dec_segment_row ?
938 2 : (uint16_t)enc_handle_ptr->sequence_control_set_instance_array[instance_index]->sequence_control_set_ptr->enc_dec_segment_row_count_array[i] :
939 : inputData.enc_dec_segment_row;
940 : }
941 :
942 2 : inputData.picture_width = enc_handle_ptr->sequence_control_set_instance_array[instance_index]->sequence_control_set_ptr->max_input_luma_width;
943 2 : inputData.picture_height = enc_handle_ptr->sequence_control_set_instance_array[instance_index]->sequence_control_set_ptr->max_input_luma_height;
944 2 : inputData.left_padding = enc_handle_ptr->sequence_control_set_instance_array[instance_index]->sequence_control_set_ptr->left_padding;
945 2 : inputData.right_padding = enc_handle_ptr->sequence_control_set_instance_array[instance_index]->sequence_control_set_ptr->right_padding;
946 2 : inputData.top_padding = enc_handle_ptr->sequence_control_set_instance_array[instance_index]->sequence_control_set_ptr->top_padding;
947 2 : inputData.bot_padding = enc_handle_ptr->sequence_control_set_instance_array[instance_index]->sequence_control_set_ptr->bot_padding;
948 2 : inputData.bit_depth = enc_handle_ptr->sequence_control_set_instance_array[instance_index]->sequence_control_set_ptr->encoder_bit_depth;
949 2 : inputData.film_grain_noise_level = enc_handle_ptr->sequence_control_set_instance_array[instance_index]->sequence_control_set_ptr->film_grain_denoise_strength;
950 2 : inputData.color_format = color_format;
951 2 : inputData.sb_sz = enc_handle_ptr->sequence_control_set_instance_array[instance_index]->sequence_control_set_ptr->sb_sz;
952 2 : inputData.sb_size_pix = scs_init.sb_size;
953 2 : inputData.max_depth = enc_handle_ptr->sequence_control_set_instance_array[instance_index]->sequence_control_set_ptr->max_sb_depth;
954 2 : inputData.hbd_mode_decision = enc_handle_ptr->sequence_control_set_instance_array[instance_index]->sequence_control_set_ptr->static_config.enable_hbd_mode_decision;
955 2 : inputData.cdf_mode = enc_handle_ptr->sequence_control_set_instance_array[instance_index]->sequence_control_set_ptr->cdf_mode;
956 2 : inputData.mfmv = enc_handle_ptr->sequence_control_set_instance_array[instance_index]->sequence_control_set_ptr->mfmv_enabled;
957 :
958 : #if PAL_SUP
959 2 : inputData.cfg_palette = enc_handle_ptr->sequence_control_set_instance_array[0]->sequence_control_set_ptr->static_config.screen_content_mode;
960 : #endif
961 2 : EB_NEW(
962 : enc_handle_ptr->picture_control_set_pool_ptr_array[instance_index],
963 : eb_system_resource_ctor,
964 : enc_handle_ptr->sequence_control_set_instance_array[instance_index]->sequence_control_set_ptr->picture_control_set_pool_init_count_child, //EB_PictureControlSetPoolInitCountChild,
965 : 1,
966 : 0,
967 : &enc_handle_ptr->picture_control_set_pool_producer_fifo_ptr_dbl_array[instance_index],
968 : (EbFifo ***)EB_NULL,
969 : EB_FALSE,
970 : picture_control_set_creator,
971 : &inputData,
972 : NULL);
973 : }
974 :
975 : /************************************
976 : * Picture Buffers
977 : ************************************/
978 :
979 : // Allocate Resource Arrays
980 2 : EB_ALLOC_PTR_ARRAY(enc_handle_ptr->reference_picture_pool_ptr_array, enc_handle_ptr->encode_instance_total_count);
981 2 : EB_ALLOC_PTR_ARRAY(enc_handle_ptr->pa_reference_picture_pool_ptr_array, enc_handle_ptr->encode_instance_total_count);
982 :
983 2 : EB_ALLOC_PTR_ARRAY(enc_handle_ptr->overlay_input_picture_pool_ptr_array, enc_handle_ptr->encode_instance_total_count);
984 2 : EB_MALLOC_ARRAY(enc_handle_ptr->overlay_input_picture_pool_producer_fifo_ptr_dbl_array, enc_handle_ptr->encode_instance_total_count);
985 : // Allocate Producer Fifo Arrays
986 2 : EB_MALLOC_ARRAY(enc_handle_ptr->reference_picture_pool_producer_fifo_ptr_dbl_array, enc_handle_ptr->encode_instance_total_count);
987 2 : EB_MALLOC_ARRAY(enc_handle_ptr->pa_reference_picture_pool_producer_fifo_ptr_dbl_array, enc_handle_ptr->encode_instance_total_count);
988 :
989 : // Rate Control
990 2 : rateControlPorts[0].count = EB_PictureManagerProcessInitCount;
991 2 : rateControlPorts[1].count = EB_PacketizationProcessInitCount;
992 2 : rateControlPorts[2].count = enc_handle_ptr->sequence_control_set_instance_array[0]->sequence_control_set_ptr->entropy_coding_process_init_count;
993 2 : rateControlPorts[3].count = 0;
994 :
995 2 : encDecPorts[ENCDEC_INPUT_PORT_MDC].count = enc_handle_ptr->sequence_control_set_instance_array[0]->sequence_control_set_ptr->mode_decision_configuration_process_init_count;
996 2 : encDecPorts[ENCDEC_INPUT_PORT_ENCDEC].count = enc_handle_ptr->sequence_control_set_instance_array[0]->sequence_control_set_ptr->enc_dec_process_init_count;
997 :
998 4 : for (instance_index = 0; instance_index < enc_handle_ptr->encode_instance_total_count; ++instance_index) {
999 : EbReferenceObjectDescInitData EbReferenceObjectDescInitDataStructure;
1000 : EbPaReferenceObjectDescInitData EbPaReferenceObjectDescInitDataStructure;
1001 : EbPictureBufferDescInitData referencePictureBufferDescInitData;
1002 : EbPictureBufferDescInitData quarterPictureBufferDescInitData;
1003 : EbPictureBufferDescInitData sixteenthPictureBufferDescInitData;
1004 : // Initialize the various Picture types
1005 2 : referencePictureBufferDescInitData.max_width = enc_handle_ptr->sequence_control_set_instance_array[instance_index]->sequence_control_set_ptr->max_input_luma_width;
1006 2 : referencePictureBufferDescInitData.max_height = enc_handle_ptr->sequence_control_set_instance_array[instance_index]->sequence_control_set_ptr->max_input_luma_height;
1007 2 : referencePictureBufferDescInitData.bit_depth = enc_handle_ptr->sequence_control_set_instance_array[instance_index]->sequence_control_set_ptr->encoder_bit_depth;
1008 2 : referencePictureBufferDescInitData.color_format = color_format;
1009 2 : referencePictureBufferDescInitData.buffer_enable_mask = PICTURE_BUFFER_DESC_FULL_MASK;
1010 :
1011 2 : referencePictureBufferDescInitData.left_padding = PAD_VALUE;
1012 2 : referencePictureBufferDescInitData.right_padding = PAD_VALUE;
1013 2 : referencePictureBufferDescInitData.top_padding = PAD_VALUE;
1014 2 : referencePictureBufferDescInitData.bot_padding = PAD_VALUE;
1015 2 : referencePictureBufferDescInitData.mfmv = enc_handle_ptr->sequence_control_set_instance_array[instance_index]->sequence_control_set_ptr->mfmv_enabled;
1016 : // Hsan: split_mode is set @ eb_reference_object_ctor() as both unpacked reference and packed reference are needed for a 10BIT input; unpacked reference @ MD, and packed reference @ EP
1017 :
1018 2 : if (is16bit)
1019 0 : referencePictureBufferDescInitData.bit_depth = EB_10BIT;
1020 :
1021 2 : EbReferenceObjectDescInitDataStructure.reference_picture_desc_init_data = referencePictureBufferDescInitData;
1022 :
1023 : // Reference Picture Buffers
1024 2 : EB_NEW(
1025 : enc_handle_ptr->reference_picture_pool_ptr_array[instance_index],
1026 : eb_system_resource_ctor,
1027 : enc_handle_ptr->sequence_control_set_instance_array[instance_index]->sequence_control_set_ptr->reference_picture_buffer_init_count,//enc_handle_ptr->reference_picture_pool_total_count,
1028 : EB_PictureManagerProcessInitCount,
1029 : 0,
1030 : &enc_handle_ptr->reference_picture_pool_producer_fifo_ptr_dbl_array[instance_index],
1031 : (EbFifo ***)EB_NULL,
1032 : EB_FALSE,
1033 : eb_reference_object_creator,
1034 : &(EbReferenceObjectDescInitDataStructure),
1035 : NULL);
1036 :
1037 : // PA Reference Picture Buffers
1038 : // Currently, only Luma samples are needed in the PA
1039 2 : referencePictureBufferDescInitData.max_width = enc_handle_ptr->sequence_control_set_instance_array[instance_index]->sequence_control_set_ptr->max_input_luma_width;
1040 2 : referencePictureBufferDescInitData.max_height = enc_handle_ptr->sequence_control_set_instance_array[instance_index]->sequence_control_set_ptr->max_input_luma_height;
1041 2 : referencePictureBufferDescInitData.bit_depth = enc_handle_ptr->sequence_control_set_instance_array[instance_index]->sequence_control_set_ptr->encoder_bit_depth;
1042 2 : referencePictureBufferDescInitData.color_format = EB_YUV420; //use 420 for picture analysis
1043 2 : referencePictureBufferDescInitData.buffer_enable_mask = 0;
1044 2 : referencePictureBufferDescInitData.left_padding = enc_handle_ptr->sequence_control_set_instance_array[instance_index]->sequence_control_set_ptr->sb_sz + ME_FILTER_TAP;
1045 2 : referencePictureBufferDescInitData.right_padding = enc_handle_ptr->sequence_control_set_instance_array[instance_index]->sequence_control_set_ptr->sb_sz + ME_FILTER_TAP;
1046 2 : referencePictureBufferDescInitData.top_padding = enc_handle_ptr->sequence_control_set_instance_array[instance_index]->sequence_control_set_ptr->sb_sz + ME_FILTER_TAP;
1047 2 : referencePictureBufferDescInitData.bot_padding = enc_handle_ptr->sequence_control_set_instance_array[instance_index]->sequence_control_set_ptr->sb_sz + ME_FILTER_TAP;
1048 2 : referencePictureBufferDescInitData.split_mode = EB_FALSE;
1049 2 : quarterPictureBufferDescInitData.max_width = enc_handle_ptr->sequence_control_set_instance_array[instance_index]->sequence_control_set_ptr->max_input_luma_width >> 1;
1050 2 : quarterPictureBufferDescInitData.max_height = enc_handle_ptr->sequence_control_set_instance_array[instance_index]->sequence_control_set_ptr->max_input_luma_height >> 1;
1051 2 : quarterPictureBufferDescInitData.bit_depth = enc_handle_ptr->sequence_control_set_instance_array[instance_index]->sequence_control_set_ptr->encoder_bit_depth;
1052 2 : quarterPictureBufferDescInitData.color_format = EB_YUV420;
1053 2 : quarterPictureBufferDescInitData.buffer_enable_mask = PICTURE_BUFFER_DESC_LUMA_MASK;
1054 2 : quarterPictureBufferDescInitData.left_padding = enc_handle_ptr->sequence_control_set_instance_array[instance_index]->sequence_control_set_ptr->sb_sz >> 1;
1055 2 : quarterPictureBufferDescInitData.right_padding = enc_handle_ptr->sequence_control_set_instance_array[instance_index]->sequence_control_set_ptr->sb_sz >> 1;
1056 2 : quarterPictureBufferDescInitData.top_padding = enc_handle_ptr->sequence_control_set_instance_array[instance_index]->sequence_control_set_ptr->sb_sz >> 1;
1057 2 : quarterPictureBufferDescInitData.bot_padding = enc_handle_ptr->sequence_control_set_instance_array[instance_index]->sequence_control_set_ptr->sb_sz >> 1;
1058 2 : quarterPictureBufferDescInitData.split_mode = EB_FALSE;
1059 2 : quarterPictureBufferDescInitData.down_sampled_filtered = (enc_handle_ptr->sequence_control_set_instance_array[instance_index]->sequence_control_set_ptr->down_sampling_method_me_search == ME_FILTERED_DOWNSAMPLED) ? EB_TRUE : EB_FALSE;
1060 :
1061 2 : sixteenthPictureBufferDescInitData.max_width = enc_handle_ptr->sequence_control_set_instance_array[instance_index]->sequence_control_set_ptr->max_input_luma_width >> 2;
1062 2 : sixteenthPictureBufferDescInitData.max_height = enc_handle_ptr->sequence_control_set_instance_array[instance_index]->sequence_control_set_ptr->max_input_luma_height >> 2;
1063 2 : sixteenthPictureBufferDescInitData.bit_depth = enc_handle_ptr->sequence_control_set_instance_array[instance_index]->sequence_control_set_ptr->encoder_bit_depth;
1064 2 : sixteenthPictureBufferDescInitData.color_format = EB_YUV420;
1065 2 : sixteenthPictureBufferDescInitData.buffer_enable_mask = PICTURE_BUFFER_DESC_LUMA_MASK;
1066 2 : sixteenthPictureBufferDescInitData.left_padding = enc_handle_ptr->sequence_control_set_instance_array[instance_index]->sequence_control_set_ptr->sb_sz >> 2;
1067 2 : sixteenthPictureBufferDescInitData.right_padding = enc_handle_ptr->sequence_control_set_instance_array[instance_index]->sequence_control_set_ptr->sb_sz >> 2;
1068 2 : sixteenthPictureBufferDescInitData.top_padding = enc_handle_ptr->sequence_control_set_instance_array[instance_index]->sequence_control_set_ptr->sb_sz >> 2;
1069 2 : sixteenthPictureBufferDescInitData.bot_padding = enc_handle_ptr->sequence_control_set_instance_array[instance_index]->sequence_control_set_ptr->sb_sz >> 2;
1070 2 : sixteenthPictureBufferDescInitData.split_mode = EB_FALSE;
1071 2 : sixteenthPictureBufferDescInitData.down_sampled_filtered = (enc_handle_ptr->sequence_control_set_instance_array[instance_index]->sequence_control_set_ptr->down_sampling_method_me_search == ME_FILTERED_DOWNSAMPLED) ? EB_TRUE : EB_FALSE;
1072 :
1073 2 : EbPaReferenceObjectDescInitDataStructure.reference_picture_desc_init_data = referencePictureBufferDescInitData;
1074 2 : EbPaReferenceObjectDescInitDataStructure.quarter_picture_desc_init_data = quarterPictureBufferDescInitData;
1075 2 : EbPaReferenceObjectDescInitDataStructure.sixteenth_picture_desc_init_data = sixteenthPictureBufferDescInitData;
1076 : // Reference Picture Buffers
1077 2 : EB_NEW(enc_handle_ptr->pa_reference_picture_pool_ptr_array[instance_index],
1078 : eb_system_resource_ctor,
1079 : enc_handle_ptr->sequence_control_set_instance_array[instance_index]->sequence_control_set_ptr->pa_reference_picture_buffer_init_count,
1080 : EB_PictureDecisionProcessInitCount,
1081 : 0,
1082 : &enc_handle_ptr->pa_reference_picture_pool_producer_fifo_ptr_dbl_array[instance_index],
1083 : (EbFifo ***)EB_NULL,
1084 : EB_FALSE,
1085 : eb_pa_reference_object_creator,
1086 : &(EbPaReferenceObjectDescInitDataStructure),
1087 : NULL);
1088 : // Set the SequenceControlSet Picture Pool Fifo Ptrs
1089 2 : enc_handle_ptr->sequence_control_set_instance_array[instance_index]->encode_context_ptr->reference_picture_pool_fifo_ptr = (enc_handle_ptr->reference_picture_pool_producer_fifo_ptr_dbl_array[instance_index])[0];
1090 2 : enc_handle_ptr->sequence_control_set_instance_array[instance_index]->encode_context_ptr->pa_reference_picture_pool_fifo_ptr = (enc_handle_ptr->pa_reference_picture_pool_producer_fifo_ptr_dbl_array[instance_index])[0];
1091 :
1092 2 : if (enc_handle_ptr->sequence_control_set_instance_array[0]->sequence_control_set_ptr->static_config.enable_overlays) {
1093 : // Overlay Input Picture Buffers
1094 0 : EB_NEW(
1095 : enc_handle_ptr->overlay_input_picture_pool_ptr_array[instance_index],
1096 : eb_system_resource_ctor,
1097 : enc_handle_ptr->sequence_control_set_instance_array[instance_index]->sequence_control_set_ptr->overlay_input_picture_buffer_init_count,
1098 : 1,
1099 : 0,
1100 : &enc_handle_ptr->overlay_input_picture_pool_producer_fifo_ptr_dbl_array[instance_index],
1101 : (EbFifo ***)EB_NULL,
1102 : EB_FALSE,
1103 : EbInputBufferHeaderCreator,
1104 : enc_handle_ptr->sequence_control_set_instance_array[instance_index]->sequence_control_set_ptr,
1105 : EbInputBufferHeaderDestoryer);
1106 : // Set the SequenceControlSet Overlay input Picture Pool Fifo Ptrs
1107 0 : enc_handle_ptr->sequence_control_set_instance_array[instance_index]->encode_context_ptr->overlay_input_picture_pool_fifo_ptr = (enc_handle_ptr->overlay_input_picture_pool_producer_fifo_ptr_dbl_array[instance_index])[0];
1108 : }
1109 : }
1110 :
1111 : /************************************
1112 : * System Resource Managers & Fifos
1113 : ************************************/
1114 :
1115 : // EbBufferHeaderType Input
1116 2 : EB_NEW(
1117 : enc_handle_ptr->input_buffer_resource_ptr,
1118 : eb_system_resource_ctor,
1119 : enc_handle_ptr->sequence_control_set_instance_array[0]->sequence_control_set_ptr->input_buffer_fifo_init_count,
1120 : 1,
1121 : EB_ResourceCoordinationProcessInitCount,
1122 : &enc_handle_ptr->input_buffer_producer_fifo_ptr_array,
1123 : &enc_handle_ptr->input_buffer_consumer_fifo_ptr_array,
1124 : EB_TRUE,
1125 : EbInputBufferHeaderCreator,
1126 : enc_handle_ptr->sequence_control_set_instance_array[0]->sequence_control_set_ptr,
1127 : EbInputBufferHeaderDestoryer);
1128 :
1129 : // EbBufferHeaderType Output Stream
1130 2 : EB_ALLOC_PTR_ARRAY(enc_handle_ptr->output_stream_buffer_resource_ptr_array, enc_handle_ptr->encode_instance_total_count);
1131 2 : EB_MALLOC_ARRAY(enc_handle_ptr->output_stream_buffer_producer_fifo_ptr_dbl_array, enc_handle_ptr->encode_instance_total_count);
1132 2 : EB_MALLOC_ARRAY(enc_handle_ptr->output_stream_buffer_consumer_fifo_ptr_dbl_array, enc_handle_ptr->encode_instance_total_count);
1133 :
1134 4 : for (instance_index = 0; instance_index < enc_handle_ptr->encode_instance_total_count; ++instance_index) {
1135 2 : EB_NEW(
1136 : enc_handle_ptr->output_stream_buffer_resource_ptr_array[instance_index],
1137 : eb_system_resource_ctor,
1138 : enc_handle_ptr->sequence_control_set_instance_array[instance_index]->sequence_control_set_ptr->output_stream_buffer_fifo_init_count,
1139 : enc_handle_ptr->sequence_control_set_instance_array[instance_index]->sequence_control_set_ptr->total_process_init_count,//EB_PacketizationProcessInitCount,
1140 : 1,
1141 : &enc_handle_ptr->output_stream_buffer_producer_fifo_ptr_dbl_array[instance_index],
1142 : &enc_handle_ptr->output_stream_buffer_consumer_fifo_ptr_dbl_array[instance_index],
1143 : EB_TRUE,
1144 : EbOutputBufferHeaderCreator,
1145 : &enc_handle_ptr->sequence_control_set_instance_array[0]->sequence_control_set_ptr->static_config,
1146 : EbOutputBufferHeaderDestoryer);
1147 : }
1148 2 : if (enc_handle_ptr->sequence_control_set_instance_array[0]->sequence_control_set_ptr->static_config.recon_enabled) {
1149 : // EbBufferHeaderType Output Recon
1150 0 : EB_ALLOC_PTR_ARRAY(enc_handle_ptr->output_recon_buffer_resource_ptr_array, enc_handle_ptr->encode_instance_total_count);
1151 0 : EB_MALLOC_ARRAY(enc_handle_ptr->output_recon_buffer_producer_fifo_ptr_dbl_array, enc_handle_ptr->encode_instance_total_count);
1152 0 : EB_MALLOC_ARRAY(enc_handle_ptr->output_recon_buffer_consumer_fifo_ptr_dbl_array, enc_handle_ptr->encode_instance_total_count);
1153 :
1154 0 : for (instance_index = 0; instance_index < enc_handle_ptr->encode_instance_total_count; ++instance_index) {
1155 0 : EB_NEW(
1156 : enc_handle_ptr->output_recon_buffer_resource_ptr_array[instance_index],
1157 : eb_system_resource_ctor,
1158 : enc_handle_ptr->sequence_control_set_instance_array[instance_index]->sequence_control_set_ptr->output_recon_buffer_fifo_init_count,
1159 : enc_handle_ptr->sequence_control_set_instance_array[instance_index]->sequence_control_set_ptr->enc_dec_process_init_count,
1160 : 1,
1161 : &enc_handle_ptr->output_recon_buffer_producer_fifo_ptr_dbl_array[instance_index],
1162 : &enc_handle_ptr->output_recon_buffer_consumer_fifo_ptr_dbl_array[instance_index],
1163 : EB_TRUE,
1164 : EbOutputReconBufferHeaderCreator,
1165 : enc_handle_ptr->sequence_control_set_instance_array[0]->sequence_control_set_ptr,
1166 : EbOutputReconBufferHeaderDestoryer);
1167 : }
1168 : }
1169 :
1170 : // Resource Coordination Results
1171 : {
1172 : ResourceCoordinationResultInitData resourceCoordinationResultInitData;
1173 :
1174 2 : EB_NEW(
1175 : enc_handle_ptr->resource_coordination_results_resource_ptr,
1176 : eb_system_resource_ctor,
1177 : enc_handle_ptr->sequence_control_set_instance_array[0]->sequence_control_set_ptr->resource_coordination_fifo_init_count,
1178 : EB_ResourceCoordinationProcessInitCount,
1179 : enc_handle_ptr->sequence_control_set_instance_array[0]->sequence_control_set_ptr->picture_analysis_process_init_count,
1180 : &enc_handle_ptr->resource_coordination_results_producer_fifo_ptr_array,
1181 : &enc_handle_ptr->resource_coordination_results_consumer_fifo_ptr_array,
1182 : EB_TRUE,
1183 : resource_coordination_result_creator,
1184 : &resourceCoordinationResultInitData,
1185 : NULL);
1186 : }
1187 :
1188 : // Picture Analysis Results
1189 : {
1190 : PictureAnalysisResultInitData pictureAnalysisResultInitData;
1191 :
1192 2 : EB_NEW(
1193 : enc_handle_ptr->picture_analysis_results_resource_ptr,
1194 : eb_system_resource_ctor,
1195 : enc_handle_ptr->sequence_control_set_instance_array[0]->sequence_control_set_ptr->picture_analysis_fifo_init_count,
1196 : enc_handle_ptr->sequence_control_set_instance_array[0]->sequence_control_set_ptr->picture_analysis_process_init_count,
1197 : EB_PictureDecisionProcessInitCount,
1198 : &enc_handle_ptr->picture_analysis_results_producer_fifo_ptr_array,
1199 : &enc_handle_ptr->picture_analysis_results_consumer_fifo_ptr_array,
1200 : EB_TRUE,
1201 : picture_analysis_result_creator,
1202 : &pictureAnalysisResultInitData,
1203 : NULL);
1204 : }
1205 :
1206 : // Picture Decision Results
1207 : {
1208 : PictureDecisionResultInitData pictureDecisionResultInitData;
1209 :
1210 2 : EB_NEW(
1211 : enc_handle_ptr->picture_decision_results_resource_ptr,
1212 : eb_system_resource_ctor,
1213 : enc_handle_ptr->sequence_control_set_instance_array[0]->sequence_control_set_ptr->picture_decision_fifo_init_count,
1214 : EB_PictureDecisionProcessInitCount,
1215 : enc_handle_ptr->sequence_control_set_instance_array[0]->sequence_control_set_ptr->motion_estimation_process_init_count,
1216 : &enc_handle_ptr->picture_decision_results_producer_fifo_ptr_array,
1217 : &enc_handle_ptr->picture_decision_results_consumer_fifo_ptr_array,
1218 : EB_TRUE,
1219 : picture_decision_result_creator,
1220 : &pictureDecisionResultInitData,
1221 : NULL);
1222 : }
1223 :
1224 : // Motion Estimation Results
1225 : {
1226 : MotionEstimationResultsInitData motionEstimationResultInitData;
1227 :
1228 2 : EB_NEW(
1229 : enc_handle_ptr->motion_estimation_results_resource_ptr,
1230 : eb_system_resource_ctor,
1231 : enc_handle_ptr->sequence_control_set_instance_array[0]->sequence_control_set_ptr->motion_estimation_fifo_init_count,
1232 : enc_handle_ptr->sequence_control_set_instance_array[0]->sequence_control_set_ptr->motion_estimation_process_init_count,
1233 : EB_InitialRateControlProcessInitCount,
1234 : &enc_handle_ptr->motion_estimation_results_producer_fifo_ptr_array,
1235 : &enc_handle_ptr->motion_estimation_results_consumer_fifo_ptr_array,
1236 : EB_TRUE,
1237 : motion_estimation_results_creator,
1238 : &motionEstimationResultInitData,
1239 : NULL);
1240 : }
1241 :
1242 : // Initial Rate Control Results
1243 : {
1244 : InitialRateControlResultInitData initialRateControlResultInitData;
1245 :
1246 2 : EB_NEW(
1247 : enc_handle_ptr->initial_rate_control_results_resource_ptr,
1248 : eb_system_resource_ctor,
1249 : enc_handle_ptr->sequence_control_set_instance_array[0]->sequence_control_set_ptr->initial_rate_control_fifo_init_count,
1250 : EB_InitialRateControlProcessInitCount,
1251 : enc_handle_ptr->sequence_control_set_instance_array[0]->sequence_control_set_ptr->source_based_operations_process_init_count,
1252 : &enc_handle_ptr->initial_rate_control_results_producer_fifo_ptr_array,
1253 : &enc_handle_ptr->initial_rate_control_results_consumer_fifo_ptr_array,
1254 : EB_TRUE,
1255 : initial_rate_control_results_creator,
1256 : &initialRateControlResultInitData,
1257 : NULL);
1258 : }
1259 :
1260 : // Picture Demux Results
1261 : {
1262 : PictureResultInitData pictureResultInitData;
1263 2 : EB_NEW(
1264 : enc_handle_ptr->picture_demux_results_resource_ptr,
1265 : eb_system_resource_ctor,
1266 : enc_handle_ptr->sequence_control_set_instance_array[0]->sequence_control_set_ptr->picture_demux_fifo_init_count,
1267 : enc_handle_ptr->sequence_control_set_instance_array[0]->sequence_control_set_ptr->source_based_operations_process_init_count + enc_handle_ptr->sequence_control_set_instance_array[0]->sequence_control_set_ptr->rest_process_init_count + 1, // 1 for packetization
1268 : EB_PictureManagerProcessInitCount,
1269 : &enc_handle_ptr->picture_demux_results_producer_fifo_ptr_array,
1270 : &enc_handle_ptr->picture_demux_results_consumer_fifo_ptr_array,
1271 : EB_TRUE,
1272 : picture_results_creator,
1273 : &pictureResultInitData,
1274 : NULL);
1275 :
1276 : }
1277 :
1278 : // Rate Control Tasks
1279 : {
1280 : RateControlTasksInitData rateControlTasksInitData;
1281 :
1282 2 : EB_NEW(
1283 : enc_handle_ptr->rate_control_tasks_resource_ptr,
1284 : eb_system_resource_ctor,
1285 : enc_handle_ptr->sequence_control_set_instance_array[0]->sequence_control_set_ptr->rate_control_tasks_fifo_init_count,
1286 : RateControlPortTotalCount(),
1287 : EB_RateControlProcessInitCount,
1288 : &enc_handle_ptr->rate_control_tasks_producer_fifo_ptr_array,
1289 : &enc_handle_ptr->rate_control_tasks_consumer_fifo_ptr_array,
1290 : EB_TRUE,
1291 : rate_control_tasks_creator,
1292 : &rateControlTasksInitData,
1293 : NULL);
1294 : }
1295 :
1296 : // Rate Control Results
1297 : {
1298 : RateControlResultsInitData rateControlResultInitData;
1299 :
1300 2 : EB_NEW(
1301 : enc_handle_ptr->rate_control_results_resource_ptr,
1302 : eb_system_resource_ctor,
1303 : enc_handle_ptr->sequence_control_set_instance_array[0]->sequence_control_set_ptr->rate_control_fifo_init_count,
1304 : EB_RateControlProcessInitCount,
1305 : enc_handle_ptr->sequence_control_set_instance_array[0]->sequence_control_set_ptr->mode_decision_configuration_process_init_count,
1306 : &enc_handle_ptr->rate_control_results_producer_fifo_ptr_array,
1307 : &enc_handle_ptr->rate_control_results_consumer_fifo_ptr_array,
1308 : EB_TRUE,
1309 : rate_control_results_creator,
1310 : &rateControlResultInitData,
1311 : NULL);
1312 : }
1313 : // EncDec Tasks
1314 : {
1315 : EncDecTasksInitData ModeDecisionResultInitData;
1316 : unsigned i;
1317 :
1318 2 : ModeDecisionResultInitData.enc_dec_segment_row_count = 0;
1319 :
1320 12 : for (i = 0; i <= enc_handle_ptr->sequence_control_set_instance_array[0]->sequence_control_set_ptr->static_config.hierarchical_levels; ++i) {
1321 10 : ModeDecisionResultInitData.enc_dec_segment_row_count = MAX(
1322 : ModeDecisionResultInitData.enc_dec_segment_row_count,
1323 : enc_handle_ptr->sequence_control_set_instance_array[0]->sequence_control_set_ptr->enc_dec_segment_row_count_array[i]);
1324 : }
1325 :
1326 2 : EB_NEW(
1327 : enc_handle_ptr->enc_dec_tasks_resource_ptr,
1328 : eb_system_resource_ctor,
1329 : enc_handle_ptr->sequence_control_set_instance_array[0]->sequence_control_set_ptr->mode_decision_configuration_fifo_init_count,
1330 : EncDecPortTotalCount(),
1331 : enc_handle_ptr->sequence_control_set_instance_array[0]->sequence_control_set_ptr->enc_dec_process_init_count,
1332 : &enc_handle_ptr->enc_dec_tasks_producer_fifo_ptr_array,
1333 : &enc_handle_ptr->enc_dec_tasks_consumer_fifo_ptr_array,
1334 : EB_TRUE,
1335 : enc_dec_tasks_creator,
1336 : &ModeDecisionResultInitData,
1337 : NULL);
1338 : }
1339 :
1340 : // EncDec Results
1341 : {
1342 : EncDecResultsInitData encDecResultInitData;
1343 :
1344 2 : EB_NEW(
1345 : enc_handle_ptr->enc_dec_results_resource_ptr,
1346 : eb_system_resource_ctor,
1347 : enc_handle_ptr->sequence_control_set_instance_array[0]->sequence_control_set_ptr->enc_dec_fifo_init_count,
1348 : enc_handle_ptr->sequence_control_set_instance_array[0]->sequence_control_set_ptr->enc_dec_process_init_count,
1349 : enc_handle_ptr->sequence_control_set_instance_array[0]->sequence_control_set_ptr->dlf_process_init_count,
1350 : &enc_handle_ptr->enc_dec_results_producer_fifo_ptr_array,
1351 : &enc_handle_ptr->enc_dec_results_consumer_fifo_ptr_array,
1352 : EB_TRUE,
1353 : enc_dec_results_creator,
1354 : &encDecResultInitData,
1355 : NULL);
1356 : }
1357 :
1358 : //DLF results
1359 : {
1360 : EntropyCodingResultsInitData dlfResultInitData;
1361 :
1362 2 : EB_NEW(
1363 : enc_handle_ptr->dlf_results_resource_ptr,
1364 : eb_system_resource_ctor,
1365 : enc_handle_ptr->sequence_control_set_instance_array[0]->sequence_control_set_ptr->dlf_fifo_init_count,
1366 : enc_handle_ptr->sequence_control_set_instance_array[0]->sequence_control_set_ptr->dlf_process_init_count,
1367 : enc_handle_ptr->sequence_control_set_instance_array[0]->sequence_control_set_ptr->cdef_process_init_count,
1368 : &enc_handle_ptr->dlf_results_producer_fifo_ptr_array,
1369 : &enc_handle_ptr->dlf_results_consumer_fifo_ptr_array,
1370 : EB_TRUE,
1371 : DlfResultsCreator,
1372 : &dlfResultInitData,
1373 : NULL);
1374 : }
1375 : //CDEF results
1376 : {
1377 : EntropyCodingResultsInitData cdefResultInitData;
1378 :
1379 2 : EB_NEW(
1380 : enc_handle_ptr->cdef_results_resource_ptr,
1381 : eb_system_resource_ctor,
1382 : enc_handle_ptr->sequence_control_set_instance_array[0]->sequence_control_set_ptr->cdef_fifo_init_count,
1383 : enc_handle_ptr->sequence_control_set_instance_array[0]->sequence_control_set_ptr->cdef_process_init_count,
1384 : enc_handle_ptr->sequence_control_set_instance_array[0]->sequence_control_set_ptr->rest_process_init_count,
1385 : &enc_handle_ptr->cdef_results_producer_fifo_ptr_array,
1386 : &enc_handle_ptr->cdef_results_consumer_fifo_ptr_array,
1387 : EB_TRUE,
1388 : CdefResultsCreator,
1389 : &cdefResultInitData,
1390 : NULL);
1391 : }
1392 : //REST results
1393 : {
1394 : EntropyCodingResultsInitData restResultInitData;
1395 :
1396 2 : EB_NEW(
1397 : enc_handle_ptr->rest_results_resource_ptr,
1398 : eb_system_resource_ctor,
1399 : enc_handle_ptr->sequence_control_set_instance_array[0]->sequence_control_set_ptr->rest_fifo_init_count,
1400 : enc_handle_ptr->sequence_control_set_instance_array[0]->sequence_control_set_ptr->rest_process_init_count,
1401 : enc_handle_ptr->sequence_control_set_instance_array[0]->sequence_control_set_ptr->entropy_coding_process_init_count,
1402 : &enc_handle_ptr->rest_results_producer_fifo_ptr_array,
1403 : &enc_handle_ptr->rest_results_consumer_fifo_ptr_array,
1404 : EB_TRUE,
1405 : RestResultsCreator,
1406 : &restResultInitData,
1407 : NULL);
1408 : }
1409 :
1410 : // Entropy Coding Results
1411 : {
1412 : EntropyCodingResultsInitData entropyCodingResultInitData;
1413 :
1414 2 : EB_NEW(
1415 : enc_handle_ptr->entropy_coding_results_resource_ptr,
1416 : eb_system_resource_ctor,
1417 : enc_handle_ptr->sequence_control_set_instance_array[0]->sequence_control_set_ptr->entropy_coding_fifo_init_count,
1418 : enc_handle_ptr->sequence_control_set_instance_array[0]->sequence_control_set_ptr->entropy_coding_process_init_count,
1419 : EB_PacketizationProcessInitCount,
1420 : &enc_handle_ptr->entropy_coding_results_producer_fifo_ptr_array,
1421 : &enc_handle_ptr->entropy_coding_results_consumer_fifo_ptr_array,
1422 : EB_TRUE,
1423 : entropy_coding_results_creator,
1424 : &entropyCodingResultInitData,
1425 : NULL);
1426 : }
1427 :
1428 : /************************************
1429 : * App Callbacks
1430 : ************************************/
1431 4 : for (instance_index = 0; instance_index < enc_handle_ptr->encode_instance_total_count; ++instance_index)
1432 2 : enc_handle_ptr->sequence_control_set_instance_array[instance_index]->encode_context_ptr->app_callback_ptr = enc_handle_ptr->app_callback_ptr_array[instance_index];
1433 : // svt Output Buffer Fifo Ptrs
1434 4 : for (instance_index = 0; instance_index < enc_handle_ptr->encode_instance_total_count; ++instance_index) {
1435 2 : enc_handle_ptr->sequence_control_set_instance_array[instance_index]->encode_context_ptr->stream_output_fifo_ptr = (enc_handle_ptr->output_stream_buffer_producer_fifo_ptr_dbl_array[instance_index])[0];
1436 2 : if (enc_handle_ptr->sequence_control_set_instance_array[0]->sequence_control_set_ptr->static_config.recon_enabled)
1437 0 : enc_handle_ptr->sequence_control_set_instance_array[instance_index]->encode_context_ptr->recon_output_fifo_ptr = (enc_handle_ptr->output_recon_buffer_producer_fifo_ptr_dbl_array[instance_index])[0];
1438 : }
1439 :
1440 : /************************************
1441 : * Contexts
1442 : ************************************/
1443 :
1444 : // Resource Coordination Context
1445 2 : EB_NEW(
1446 : enc_handle_ptr->resource_coordination_context_ptr,
1447 : resource_coordination_context_ctor,
1448 : enc_handle_ptr->input_buffer_consumer_fifo_ptr_array[0],
1449 : enc_handle_ptr->resource_coordination_results_producer_fifo_ptr_array[0],
1450 : enc_handle_ptr->picture_parent_control_set_pool_producer_fifo_ptr_dbl_array[0],//ResourceCoordination works with ParentPCS
1451 : enc_handle_ptr->sequence_control_set_instance_array,
1452 : enc_handle_ptr->sequence_control_set_pool_producer_fifo_ptr_array[0],
1453 : enc_handle_ptr->app_callback_ptr_array,
1454 : enc_handle_ptr->compute_segments_total_count_array,
1455 : enc_handle_ptr->encode_instance_total_count);
1456 :
1457 : // Picture Analysis Context
1458 2 : EB_ALLOC_PTR_ARRAY(enc_handle_ptr->picture_analysis_context_ptr_array, enc_handle_ptr->sequence_control_set_instance_array[0]->sequence_control_set_ptr->picture_analysis_process_init_count);
1459 :
1460 10 : for (processIndex = 0; processIndex < enc_handle_ptr->sequence_control_set_instance_array[0]->sequence_control_set_ptr->picture_analysis_process_init_count; ++processIndex) {
1461 : EbPictureBufferDescInitData pictureBufferDescConf;
1462 8 : pictureBufferDescConf.color_format = color_format;
1463 8 : pictureBufferDescConf.max_width = enc_handle_ptr->sequence_control_set_instance_array[0]->sequence_control_set_ptr->max_input_luma_width;
1464 8 : pictureBufferDescConf.max_height = enc_handle_ptr->sequence_control_set_instance_array[0]->sequence_control_set_ptr->max_input_luma_height;
1465 8 : pictureBufferDescConf.bit_depth = EB_8BIT;
1466 8 : pictureBufferDescConf.buffer_enable_mask = PICTURE_BUFFER_DESC_Y_FLAG;
1467 8 : pictureBufferDescConf.left_padding = 0;
1468 8 : pictureBufferDescConf.right_padding = 0;
1469 8 : pictureBufferDescConf.top_padding = 0;
1470 8 : pictureBufferDescConf.bot_padding = 0;
1471 8 : pictureBufferDescConf.split_mode = EB_FALSE;
1472 :
1473 8 : EB_NEW(
1474 : enc_handle_ptr->picture_analysis_context_ptr_array[processIndex],
1475 : picture_analysis_context_ctor,
1476 : &pictureBufferDescConf,
1477 : EB_TRUE,
1478 : enc_handle_ptr->resource_coordination_results_consumer_fifo_ptr_array[processIndex],
1479 : enc_handle_ptr->picture_analysis_results_producer_fifo_ptr_array[processIndex]);
1480 : }
1481 :
1482 : // Picture Decision Context
1483 : {
1484 : // Initialize the various Picture types
1485 2 : instance_index = 0;
1486 :
1487 2 : EB_NEW(
1488 : enc_handle_ptr->picture_decision_context_ptr,
1489 : picture_decision_context_ctor,
1490 : enc_handle_ptr->picture_analysis_results_consumer_fifo_ptr_array[0],
1491 : enc_handle_ptr->picture_decision_results_producer_fifo_ptr_array[0]);
1492 : }
1493 :
1494 : // Motion Analysis Context
1495 2 : EB_ALLOC_PTR_ARRAY(enc_handle_ptr->motion_estimation_context_ptr_array, enc_handle_ptr->sequence_control_set_instance_array[0]->sequence_control_set_ptr->motion_estimation_process_init_count);
1496 :
1497 10 : for (processIndex = 0; processIndex < enc_handle_ptr->sequence_control_set_instance_array[0]->sequence_control_set_ptr->motion_estimation_process_init_count; ++processIndex) {
1498 8 : EB_NEW(
1499 : enc_handle_ptr->motion_estimation_context_ptr_array[processIndex],
1500 : motion_estimation_context_ctor,
1501 : enc_handle_ptr->picture_decision_results_consumer_fifo_ptr_array[processIndex],
1502 : enc_handle_ptr->motion_estimation_results_producer_fifo_ptr_array[processIndex],
1503 : enc_handle_ptr->sequence_control_set_instance_array[0]->sequence_control_set_ptr->max_input_luma_width,
1504 : enc_handle_ptr->sequence_control_set_instance_array[0]->sequence_control_set_ptr->max_input_luma_height,
1505 : enc_handle_ptr->sequence_control_set_instance_array[instance_index]->sequence_control_set_ptr->nsq_present,
1506 : enc_handle_ptr->sequence_control_set_instance_array[instance_index]->sequence_control_set_ptr->mrp_mode);
1507 : }
1508 :
1509 : // Initial Rate Control Context
1510 2 : EB_NEW(
1511 : enc_handle_ptr->initial_rate_control_context_ptr,
1512 : initial_rate_control_context_ctor,
1513 : enc_handle_ptr->motion_estimation_results_consumer_fifo_ptr_array[0],
1514 : enc_handle_ptr->initial_rate_control_results_producer_fifo_ptr_array[0]);
1515 : // Source Based Operations Context
1516 2 : EB_ALLOC_PTR_ARRAY(enc_handle_ptr->source_based_operations_context_ptr_array, enc_handle_ptr->sequence_control_set_instance_array[0]->sequence_control_set_ptr->source_based_operations_process_init_count);
1517 :
1518 8 : for (processIndex = 0; processIndex < enc_handle_ptr->sequence_control_set_instance_array[0]->sequence_control_set_ptr->source_based_operations_process_init_count; ++processIndex) {
1519 6 : EB_NEW(
1520 : enc_handle_ptr->source_based_operations_context_ptr_array[processIndex],
1521 : source_based_operations_context_ctor,
1522 : enc_handle_ptr->initial_rate_control_results_consumer_fifo_ptr_array[processIndex],
1523 : enc_handle_ptr->picture_demux_results_producer_fifo_ptr_array[processIndex],
1524 : enc_handle_ptr->sequence_control_set_instance_array[0]->sequence_control_set_ptr);
1525 : }
1526 :
1527 : // Picture Manager Context
1528 2 : EB_NEW(
1529 : enc_handle_ptr->picture_manager_context_ptr,
1530 : picture_manager_context_ctor,
1531 : enc_handle_ptr->picture_demux_results_consumer_fifo_ptr_array[0],
1532 : enc_handle_ptr->rate_control_tasks_producer_fifo_ptr_array[RateControlPortLookup(RATE_CONTROL_INPUT_PORT_PICTURE_MANAGER, 0)],
1533 : enc_handle_ptr->picture_control_set_pool_producer_fifo_ptr_dbl_array[0]);//The Child PCS Pool here
1534 : // Rate Control Context
1535 2 : EB_NEW(
1536 : enc_handle_ptr->rate_control_context_ptr,
1537 : rate_control_context_ctor,
1538 : enc_handle_ptr->rate_control_tasks_consumer_fifo_ptr_array[0],
1539 : enc_handle_ptr->rate_control_results_producer_fifo_ptr_array[0],
1540 : enc_handle_ptr->sequence_control_set_instance_array[0]->sequence_control_set_ptr->intra_period_length);
1541 : // Mode Decision Configuration Contexts
1542 : {
1543 : // Mode Decision Configuration Contexts
1544 2 : EB_ALLOC_PTR_ARRAY(enc_handle_ptr->mode_decision_configuration_context_ptr_array, enc_handle_ptr->sequence_control_set_instance_array[0]->sequence_control_set_ptr->mode_decision_configuration_process_init_count);
1545 :
1546 8 : for (processIndex = 0; processIndex < enc_handle_ptr->sequence_control_set_instance_array[0]->sequence_control_set_ptr->mode_decision_configuration_process_init_count; ++processIndex) {
1547 6 : EB_NEW(
1548 : enc_handle_ptr->mode_decision_configuration_context_ptr_array[processIndex],
1549 : mode_decision_configuration_context_ctor,
1550 : enc_handle_ptr->rate_control_results_consumer_fifo_ptr_array[processIndex],
1551 : enc_handle_ptr->enc_dec_tasks_producer_fifo_ptr_array[EncDecPortLookup(ENCDEC_INPUT_PORT_MDC, processIndex)],
1552 : ((enc_handle_ptr->sequence_control_set_instance_array[0]->sequence_control_set_ptr->max_input_luma_width + BLOCK_SIZE_64 - 1) / BLOCK_SIZE_64) *
1553 : ((enc_handle_ptr->sequence_control_set_instance_array[0]->sequence_control_set_ptr->max_input_luma_height + BLOCK_SIZE_64 - 1) / BLOCK_SIZE_64));
1554 : }
1555 : }
1556 :
1557 2 : max_picture_width = 0;
1558 4 : for (instance_index = 0; instance_index < enc_handle_ptr->encode_instance_total_count; ++instance_index) {
1559 2 : if (max_picture_width < enc_handle_ptr->sequence_control_set_instance_array[instance_index]->sequence_control_set_ptr->max_input_luma_width)
1560 2 : max_picture_width = enc_handle_ptr->sequence_control_set_instance_array[instance_index]->sequence_control_set_ptr->max_input_luma_width;
1561 : }
1562 :
1563 : // EncDec Contexts
1564 2 : EB_ALLOC_PTR_ARRAY(enc_handle_ptr->enc_dec_context_ptr_array, enc_handle_ptr->sequence_control_set_instance_array[0]->sequence_control_set_ptr->enc_dec_process_init_count);
1565 :
1566 18 : for (processIndex = 0; processIndex < enc_handle_ptr->sequence_control_set_instance_array[0]->sequence_control_set_ptr->enc_dec_process_init_count; ++processIndex) {
1567 : #if PAL_SUP
1568 16 : EB_NEW(
1569 : enc_handle_ptr->enc_dec_context_ptr_array[processIndex],
1570 : enc_dec_context_ctor,
1571 : enc_handle_ptr->enc_dec_tasks_consumer_fifo_ptr_array[processIndex],
1572 : enc_handle_ptr->enc_dec_results_producer_fifo_ptr_array[processIndex],
1573 : enc_handle_ptr->enc_dec_tasks_producer_fifo_ptr_array[EncDecPortLookup(ENCDEC_INPUT_PORT_ENCDEC, processIndex)],
1574 : enc_handle_ptr->picture_demux_results_producer_fifo_ptr_array[
1575 : enc_handle_ptr->sequence_control_set_instance_array[0]->sequence_control_set_ptr->source_based_operations_process_init_count +
1576 : //1 +
1577 : processIndex], // Add port lookup logic here JMJ
1578 : enc_handle_ptr->sequence_control_set_instance_array[0]->sequence_control_set_ptr->static_config.screen_content_mode,
1579 : is16bit,
1580 : color_format,
1581 : enc_handle_ptr->sequence_control_set_instance_array[0]->sequence_control_set_ptr->static_config.enable_hbd_mode_decision,
1582 : enc_handle_ptr->sequence_control_set_instance_array[0]->sequence_control_set_ptr->max_input_luma_width,
1583 : enc_handle_ptr->sequence_control_set_instance_array[0]->sequence_control_set_ptr->max_input_luma_height
1584 : );
1585 : #else
1586 : EB_NEW(
1587 : enc_handle_ptr->enc_dec_context_ptr_array[processIndex],
1588 : enc_dec_context_ctor,
1589 : enc_handle_ptr->enc_dec_tasks_consumer_fifo_ptr_array[processIndex],
1590 : enc_handle_ptr->enc_dec_results_producer_fifo_ptr_array[processIndex],
1591 : enc_handle_ptr->enc_dec_tasks_producer_fifo_ptr_array[EncDecPortLookup(ENCDEC_INPUT_PORT_ENCDEC, processIndex)],
1592 : enc_handle_ptr->picture_demux_results_producer_fifo_ptr_array[
1593 : enc_handle_ptr->sequence_control_set_instance_array[0]->sequence_control_set_ptr->source_based_operations_process_init_count+
1594 : //1 +
1595 : processIndex], // Add port lookup logic here JMJ
1596 : is16bit,
1597 : color_format,
1598 : enc_handle_ptr->sequence_control_set_instance_array[0]->sequence_control_set_ptr->static_config.enable_hbd_mode_decision,
1599 : enc_handle_ptr->sequence_control_set_instance_array[0]->sequence_control_set_ptr->max_input_luma_width,
1600 : enc_handle_ptr->sequence_control_set_instance_array[0]->sequence_control_set_ptr->max_input_luma_height
1601 : );
1602 : #endif
1603 : }
1604 :
1605 : // Dlf Contexts
1606 2 : EB_ALLOC_PTR_ARRAY(enc_handle_ptr->dlf_context_ptr_array, enc_handle_ptr->sequence_control_set_instance_array[0]->sequence_control_set_ptr->dlf_process_init_count);
1607 :
1608 18 : for (processIndex = 0; processIndex < enc_handle_ptr->sequence_control_set_instance_array[0]->sequence_control_set_ptr->dlf_process_init_count; ++processIndex) {
1609 16 : EB_NEW(
1610 : enc_handle_ptr->dlf_context_ptr_array[processIndex],
1611 : dlf_context_ctor,
1612 : enc_handle_ptr->enc_dec_results_consumer_fifo_ptr_array[processIndex],
1613 : enc_handle_ptr->dlf_results_producer_fifo_ptr_array[processIndex], //output to EC
1614 : is16bit,
1615 : color_format,
1616 : enc_handle_ptr->sequence_control_set_instance_array[0]->sequence_control_set_ptr->max_input_luma_width,
1617 : enc_handle_ptr->sequence_control_set_instance_array[0]->sequence_control_set_ptr->max_input_luma_height
1618 : );
1619 : }
1620 :
1621 : //CDEF Contexts
1622 2 : EB_ALLOC_PTR_ARRAY(enc_handle_ptr->cdef_context_ptr_array, enc_handle_ptr->sequence_control_set_instance_array[0]->sequence_control_set_ptr->cdef_process_init_count);
1623 :
1624 18 : for (processIndex = 0; processIndex < enc_handle_ptr->sequence_control_set_instance_array[0]->sequence_control_set_ptr->cdef_process_init_count; ++processIndex) {
1625 16 : EB_NEW(
1626 : enc_handle_ptr->cdef_context_ptr_array[processIndex],
1627 : cdef_context_ctor,
1628 : enc_handle_ptr->dlf_results_consumer_fifo_ptr_array[processIndex],
1629 : enc_handle_ptr->cdef_results_producer_fifo_ptr_array[processIndex],
1630 : is16bit,
1631 : enc_handle_ptr->sequence_control_set_instance_array[0]->sequence_control_set_ptr->max_input_luma_width,
1632 : enc_handle_ptr->sequence_control_set_instance_array[0]->sequence_control_set_ptr->max_input_luma_height
1633 : );
1634 : }
1635 : //Rest Contexts
1636 2 : EB_ALLOC_PTR_ARRAY(enc_handle_ptr->rest_context_ptr_array, enc_handle_ptr->sequence_control_set_instance_array[0]->sequence_control_set_ptr->rest_process_init_count);
1637 :
1638 18 : for (processIndex = 0; processIndex < enc_handle_ptr->sequence_control_set_instance_array[0]->sequence_control_set_ptr->rest_process_init_count; ++processIndex) {
1639 16 : EB_NEW(
1640 : enc_handle_ptr->rest_context_ptr_array[processIndex],
1641 : rest_context_ctor,
1642 : enc_handle_ptr->cdef_results_consumer_fifo_ptr_array[processIndex],
1643 : enc_handle_ptr->rest_results_producer_fifo_ptr_array[processIndex],
1644 : enc_handle_ptr->picture_demux_results_producer_fifo_ptr_array[
1645 : /*enc_handle_ptr->sequence_control_set_instance_array[0]->sequence_control_set_ptr->source_based_operations_process_init_count*/ 1+ processIndex],
1646 : is16bit,
1647 : color_format,
1648 : enc_handle_ptr->sequence_control_set_instance_array[0]->sequence_control_set_ptr->max_input_luma_width,
1649 : enc_handle_ptr->sequence_control_set_instance_array[0]->sequence_control_set_ptr->max_input_luma_height
1650 : );
1651 : }
1652 :
1653 : // Entropy Coding Contexts
1654 2 : EB_ALLOC_PTR_ARRAY(enc_handle_ptr->entropy_coding_context_ptr_array, enc_handle_ptr->sequence_control_set_instance_array[0]->sequence_control_set_ptr->entropy_coding_process_init_count);
1655 :
1656 8 : for (processIndex = 0; processIndex < enc_handle_ptr->sequence_control_set_instance_array[0]->sequence_control_set_ptr->entropy_coding_process_init_count; ++processIndex) {
1657 6 : EB_NEW(
1658 : enc_handle_ptr->entropy_coding_context_ptr_array[processIndex],
1659 : entropy_coding_context_ctor,
1660 : enc_handle_ptr->rest_results_consumer_fifo_ptr_array[processIndex],
1661 : enc_handle_ptr->entropy_coding_results_producer_fifo_ptr_array[processIndex],
1662 : enc_handle_ptr->rate_control_tasks_producer_fifo_ptr_array[RateControlPortLookup(RATE_CONTROL_INPUT_PORT_ENTROPY_CODING, processIndex)],
1663 : is16bit);
1664 : }
1665 :
1666 : // Packetization Context
1667 2 : EB_NEW(
1668 : enc_handle_ptr->packetization_context_ptr,
1669 : packetization_context_ctor,
1670 : enc_handle_ptr->entropy_coding_results_consumer_fifo_ptr_array[0],
1671 : enc_handle_ptr->rate_control_tasks_producer_fifo_ptr_array[RateControlPortLookup(RATE_CONTROL_INPUT_PORT_PACKETIZATION, 0)]
1672 : , enc_handle_ptr->picture_demux_results_producer_fifo_ptr_array[enc_handle_ptr->sequence_control_set_instance_array[0]->sequence_control_set_ptr->source_based_operations_process_init_count +
1673 : enc_handle_ptr->sequence_control_set_instance_array[0]->sequence_control_set_ptr->enc_dec_process_init_count]
1674 : );
1675 :
1676 : /************************************
1677 : * Thread Handles
1678 : ************************************/
1679 2 : EbSvtAv1EncConfiguration *config_ptr = &enc_handle_ptr->sequence_control_set_instance_array[0]->sequence_control_set_ptr->static_config;
1680 :
1681 2 : EbSetThreadManagementParameters(config_ptr);
1682 :
1683 2 : control_set_ptr = enc_handle_ptr->sequence_control_set_instance_array[0]->sequence_control_set_ptr;
1684 :
1685 : // Resource Coordination
1686 2 : EB_CREATE_THREAD(enc_handle_ptr->resource_coordination_thread_handle, resource_coordination_kernel, enc_handle_ptr->resource_coordination_context_ptr);
1687 10 : EB_CREATE_THREAD_ARRAY(enc_handle_ptr->picture_analysis_thread_handle_array,control_set_ptr->picture_analysis_process_init_count,
1688 : picture_analysis_kernel,
1689 : enc_handle_ptr->picture_analysis_context_ptr_array);
1690 :
1691 : // Picture Decision
1692 2 : EB_CREATE_THREAD(enc_handle_ptr->picture_decision_thread_handle, picture_decision_kernel, enc_handle_ptr->picture_decision_context_ptr);
1693 :
1694 : // Motion Estimation
1695 10 : EB_CREATE_THREAD_ARRAY(enc_handle_ptr->motion_estimation_thread_handle_array, control_set_ptr->motion_estimation_process_init_count,
1696 : motion_estimation_kernel,
1697 : enc_handle_ptr->motion_estimation_context_ptr_array);
1698 :
1699 : // Initial Rate Control
1700 2 : EB_CREATE_THREAD(enc_handle_ptr->initial_rate_control_thread_handle, initial_rate_control_kernel, enc_handle_ptr->initial_rate_control_context_ptr);
1701 :
1702 : // Source Based Oprations
1703 8 : EB_CREATE_THREAD_ARRAY(enc_handle_ptr->source_based_operations_thread_handle_array, control_set_ptr->source_based_operations_process_init_count,
1704 : source_based_operations_kernel,
1705 : enc_handle_ptr->source_based_operations_context_ptr_array);
1706 :
1707 : // Picture Manager
1708 2 : EB_CREATE_THREAD(enc_handle_ptr->picture_manager_thread_handle, picture_manager_kernel, enc_handle_ptr->picture_manager_context_ptr);
1709 :
1710 : // Rate Control
1711 2 : EB_CREATE_THREAD(enc_handle_ptr->rate_control_thread_handle, rate_control_kernel, enc_handle_ptr->rate_control_context_ptr);
1712 :
1713 : // Mode Decision Configuration Process
1714 8 : EB_CREATE_THREAD_ARRAY(enc_handle_ptr->mode_decision_configuration_thread_handle_array, control_set_ptr->mode_decision_configuration_process_init_count,
1715 : mode_decision_configuration_kernel,
1716 : enc_handle_ptr->mode_decision_configuration_context_ptr_array);
1717 :
1718 :
1719 : // EncDec Process
1720 18 : EB_CREATE_THREAD_ARRAY(enc_handle_ptr->enc_dec_thread_handle_array, control_set_ptr->enc_dec_process_init_count,
1721 : enc_dec_kernel,
1722 : enc_handle_ptr->enc_dec_context_ptr_array);
1723 :
1724 : // Dlf Process
1725 18 : EB_CREATE_THREAD_ARRAY(enc_handle_ptr->dlf_thread_handle_array, control_set_ptr->dlf_process_init_count,
1726 : dlf_kernel,
1727 : enc_handle_ptr->dlf_context_ptr_array);
1728 :
1729 : // Cdef Process
1730 18 : EB_CREATE_THREAD_ARRAY(enc_handle_ptr->cdef_thread_handle_array, control_set_ptr->cdef_process_init_count,
1731 : cdef_kernel,
1732 : enc_handle_ptr->cdef_context_ptr_array);
1733 :
1734 : // Rest Process
1735 18 : EB_CREATE_THREAD_ARRAY(enc_handle_ptr->rest_thread_handle_array, control_set_ptr->rest_process_init_count,
1736 : rest_kernel,
1737 : enc_handle_ptr->rest_context_ptr_array);
1738 :
1739 : // Entropy Coding Process
1740 8 : EB_CREATE_THREAD_ARRAY(enc_handle_ptr->entropy_coding_thread_handle_array, control_set_ptr->entropy_coding_process_init_count,
1741 : entropy_coding_kernel,
1742 : enc_handle_ptr->entropy_coding_context_ptr_array);
1743 :
1744 : // Packetization
1745 2 : EB_CREATE_THREAD(enc_handle_ptr->packetization_thread_handle, packetization_kernel, enc_handle_ptr->packetization_context_ptr);
1746 :
1747 : #if DISPLAY_MEMORY
1748 : EB_MEMORY();
1749 : #endif
1750 2 : eb_print_memory_usage();
1751 :
1752 2 : return return_error;
1753 : }
1754 :
1755 : /**********************************
1756 : * DeInitialize Encoder Library
1757 : **********************************/
1758 : #ifdef __GNUC__
1759 : __attribute__((visibility("default")))
1760 : #endif
1761 2 : EB_API EbErrorType eb_deinit_encoder(EbComponentType *svt_enc_component){
1762 2 : if(svt_enc_component == NULL)
1763 0 : return EB_ErrorBadParameter;
1764 2 : return EB_ErrorNone;
1765 : }
1766 :
1767 : EbErrorType eb_svt_enc_init_parameter(
1768 : EbSvtAv1EncConfiguration * config_ptr);
1769 :
1770 : EbErrorType init_svt_av1_encoder_handle(
1771 : EbComponentType * hComponent);
1772 : /**********************************
1773 : * GetHandle
1774 : **********************************/
1775 : #ifdef __GNUC__
1776 : __attribute__((visibility("default")))
1777 : #endif
1778 2 : EB_API EbErrorType eb_init_handle(
1779 : EbComponentType** p_handle, // Function to be called in the future for manipulating the component
1780 : void* p_app_data,
1781 : EbSvtAv1EncConfiguration *config_ptr) // pointer passed back to the client during callbacks
1782 :
1783 : {
1784 2 : EbErrorType return_error = EB_ErrorNone;
1785 2 : if(p_handle == NULL)
1786 0 : return EB_ErrorBadParameter;
1787 :
1788 : #if defined(__linux__)
1789 2 : if(lp_group == NULL) {
1790 2 : EB_MALLOC(lp_group, INITIAL_PROCESSOR_GROUP * sizeof(processorGroup));
1791 : }
1792 : #endif
1793 :
1794 2 : *p_handle = (EbComponentType*)malloc(sizeof(EbComponentType));
1795 2 : if (*p_handle == (EbComponentType*)NULL) {
1796 0 : SVT_LOG("Error: Component Struct Malloc Failed\n");
1797 0 : return_error = EB_ErrorInsufficientResources;
1798 : }
1799 : // Init Component OS objects (threads, semaphores, etc.)
1800 : // also links the various Component control functions
1801 2 : return_error = init_svt_av1_encoder_handle(*p_handle);
1802 :
1803 2 : if (return_error == EB_ErrorNone) {
1804 2 : ((EbComponentType*)(*p_handle))->p_application_private = p_app_data;
1805 2 : return_error = eb_svt_enc_init_parameter(config_ptr);
1806 : }
1807 2 : if (return_error != EB_ErrorNone) {
1808 0 : eb_deinit_encoder(*p_handle);
1809 0 : free(*p_handle);
1810 0 : *p_handle = NULL;
1811 0 : return return_error;
1812 : }
1813 2 : eb_increase_component_count();
1814 2 : return return_error;
1815 : }
1816 :
1817 : /**********************************
1818 : * Encoder Componenet DeInit
1819 : **********************************/
1820 2 : EbErrorType eb_av1_enc_component_de_init(EbComponentType *svt_enc_component)
1821 : {
1822 2 : EbErrorType return_error = EB_ErrorNone;
1823 :
1824 2 : if (svt_enc_component->p_component_private) {
1825 2 : EbEncHandle* handle = (EbEncHandle*)svt_enc_component->p_component_private;
1826 2 : EB_DELETE(handle);
1827 2 : svt_enc_component->p_component_private = NULL;
1828 : }
1829 : else
1830 0 : return_error = EB_ErrorUndefined;
1831 2 : return return_error;
1832 : }
1833 :
1834 : /**********************************
1835 : * eb_deinit_handle
1836 : **********************************/
1837 : #ifdef __GNUC__
1838 : __attribute__((visibility("default")))
1839 : #endif
1840 2 : EB_API EbErrorType eb_deinit_handle(
1841 : EbComponentType *svt_enc_component)
1842 : {
1843 2 : EbErrorType return_error = EB_ErrorNone;
1844 :
1845 2 : if (svt_enc_component) {
1846 2 : return_error = eb_av1_enc_component_de_init(svt_enc_component);
1847 :
1848 2 : free(svt_enc_component);
1849 : #if defined(__linux__)
1850 2 : EB_FREE(lp_group);
1851 : #endif
1852 2 : eb_decrease_component_count();
1853 : }
1854 : else
1855 0 : return_error = EB_ErrorInvalidComponent;
1856 2 : return return_error;
1857 : }
1858 :
1859 : // Sets the default intra period the closest possible to 1 second without breaking the minigop
1860 2 : static int32_t compute_default_intra_period(
1861 : SequenceControlSet *sequence_control_set_ptr){
1862 2 : int32_t intra_period = 0;
1863 2 : EbSvtAv1EncConfiguration *config = &sequence_control_set_ptr->static_config;
1864 4 : int32_t fps = config->frame_rate < 1000 ?
1865 2 : config->frame_rate :
1866 2 : config->frame_rate >> 16;
1867 2 : int32_t mini_gop_size = (1 << (config->hierarchical_levels));
1868 2 : int32_t min_ip = ((int)((fps) / mini_gop_size)*(mini_gop_size));
1869 2 : int32_t max_ip = ((int)((fps + mini_gop_size) / mini_gop_size)*(mini_gop_size));
1870 :
1871 2 : intra_period = (ABS((fps - max_ip)) > ABS((fps - min_ip))) ? min_ip : max_ip;
1872 :
1873 2 : if (config->intra_refresh_type == 1)
1874 2 : intra_period -= 1;
1875 :
1876 2 : return intra_period;
1877 : }
1878 :
1879 : // Set configurations for the hardcoded parameters
1880 2 : void SetDefaultConfigurationParameters(
1881 : SequenceControlSet *sequence_control_set_ptr)
1882 : {
1883 : // LCU Definitions
1884 2 : sequence_control_set_ptr->sb_sz = MAX_SB_SIZE;
1885 2 : sequence_control_set_ptr->max_sb_depth = (uint8_t)EB_MAX_LCU_DEPTH;
1886 :
1887 : // No Cropping Window
1888 2 : sequence_control_set_ptr->conformance_window_flag = 0;
1889 2 : sequence_control_set_ptr->cropping_left_offset = 0;
1890 2 : sequence_control_set_ptr->cropping_right_offset = 0;
1891 2 : sequence_control_set_ptr->cropping_top_offset = 0;
1892 2 : sequence_control_set_ptr->cropping_bottom_offset = 0;
1893 :
1894 2 : sequence_control_set_ptr->static_config.enable_adaptive_quantization = 2;
1895 :
1896 2 : return;
1897 : }
1898 :
1899 2 : static uint32_t compute_default_look_ahead(
1900 : EbSvtAv1EncConfiguration* config){
1901 2 : int32_t lad = 0;
1902 2 : if (config->rate_control_mode == 0)
1903 2 : lad = (2 << config->hierarchical_levels)+1;
1904 : else
1905 0 : lad = config->intra_period_length;
1906 :
1907 2 : return lad;
1908 : }
1909 :
1910 : // Only use the maximum look ahead needed if
1911 0 : static uint32_t cap_look_ahead_distance(
1912 : EbSvtAv1EncConfiguration* config){
1913 0 : uint32_t lad = 0;
1914 :
1915 0 : if(config){
1916 0 : uint32_t fps = config->frame_rate < 1000 ?
1917 0 : config->frame_rate :
1918 0 : config->frame_rate >> 16;
1919 0 : uint32_t max_cqp_lad = (2 << config->hierarchical_levels) + 1;
1920 0 : uint32_t max_rc_lad = fps << 1;
1921 0 : lad = config->look_ahead_distance;
1922 0 : if (config->rate_control_mode == 0 && lad > max_cqp_lad)
1923 0 : lad = max_cqp_lad;
1924 0 : else if (config->rate_control_mode != 0 && lad > max_rc_lad)
1925 0 : lad = max_rc_lad;
1926 : }
1927 :
1928 0 : lad = lad > MAX_LAD ? MAX_LAD: lad; // clip to max allowed lad
1929 :
1930 0 : return lad;
1931 : }
1932 :
1933 2 : void SetParamBasedOnInput(SequenceControlSet *sequence_control_set_ptr)
1934 : {
1935 2 : uint16_t subsampling_x = sequence_control_set_ptr->subsampling_x;
1936 2 : uint16_t subsampling_y = sequence_control_set_ptr->subsampling_y;
1937 2 : sequence_control_set_ptr->general_frame_only_constraint_flag = 0;
1938 2 : sequence_control_set_ptr->general_progressive_source_flag = 1;
1939 2 : sequence_control_set_ptr->general_interlaced_source_flag = 0;
1940 :
1941 : // Update picture width, and picture height
1942 2 : if (sequence_control_set_ptr->max_input_luma_width % MIN_BLOCK_SIZE) {
1943 0 : sequence_control_set_ptr->max_input_pad_right = MIN_BLOCK_SIZE - (sequence_control_set_ptr->max_input_luma_width % MIN_BLOCK_SIZE);
1944 0 : sequence_control_set_ptr->max_input_luma_width = sequence_control_set_ptr->max_input_luma_width + sequence_control_set_ptr->max_input_pad_right;
1945 : } else {
1946 2 : sequence_control_set_ptr->max_input_pad_right = 0;
1947 : }
1948 :
1949 2 : if (sequence_control_set_ptr->max_input_luma_height % MIN_BLOCK_SIZE) {
1950 0 : sequence_control_set_ptr->max_input_pad_bottom = MIN_BLOCK_SIZE - (sequence_control_set_ptr->max_input_luma_height % MIN_BLOCK_SIZE);
1951 0 : sequence_control_set_ptr->max_input_luma_height = sequence_control_set_ptr->max_input_luma_height + sequence_control_set_ptr->max_input_pad_bottom;
1952 : } else {
1953 2 : sequence_control_set_ptr->max_input_pad_bottom = 0;
1954 : }
1955 :
1956 2 : sequence_control_set_ptr->max_input_chroma_width = sequence_control_set_ptr->max_input_luma_width >> subsampling_x;
1957 2 : sequence_control_set_ptr->max_input_chroma_height = sequence_control_set_ptr->max_input_luma_height >> subsampling_y;
1958 :
1959 2 : sequence_control_set_ptr->chroma_width = sequence_control_set_ptr->max_input_luma_width >> subsampling_x;
1960 2 : sequence_control_set_ptr->chroma_height = sequence_control_set_ptr->max_input_luma_height >> subsampling_y;
1961 2 : sequence_control_set_ptr->seq_header.max_frame_width = sequence_control_set_ptr->max_input_luma_width;
1962 2 : sequence_control_set_ptr->seq_header.max_frame_height = sequence_control_set_ptr->max_input_luma_height;
1963 2 : sequence_control_set_ptr->static_config.source_width = sequence_control_set_ptr->max_input_luma_width;
1964 2 : sequence_control_set_ptr->static_config.source_height = sequence_control_set_ptr->max_input_luma_height;
1965 :
1966 2 : derive_input_resolution(
1967 : sequence_control_set_ptr,
1968 2 : sequence_control_set_ptr->seq_header.max_frame_width*sequence_control_set_ptr->seq_header.max_frame_height);
1969 : #if TWO_PASS
1970 : // In two pass encoding, the first pass uses sb size=64
1971 2 : if (sequence_control_set_ptr->static_config.screen_content_mode == 1 || sequence_control_set_ptr->use_output_stat_file)
1972 : #else
1973 : if (sequence_control_set_ptr->static_config.screen_content_mode == 1)
1974 : #endif
1975 0 : sequence_control_set_ptr->static_config.super_block_size = 64;
1976 : else
1977 2 : sequence_control_set_ptr->static_config.super_block_size = (sequence_control_set_ptr->static_config.enc_mode <= ENC_M3 && sequence_control_set_ptr->input_resolution >= INPUT_SIZE_1080i_RANGE) ? 128 : 64;
1978 :
1979 2 : sequence_control_set_ptr->static_config.super_block_size = (sequence_control_set_ptr->static_config.rate_control_mode > 1) ? 64 : sequence_control_set_ptr->static_config.super_block_size;
1980 : // sequence_control_set_ptr->static_config.hierarchical_levels = (sequence_control_set_ptr->static_config.rate_control_mode > 1) ? 3 : sequence_control_set_ptr->static_config.hierarchical_levels;
1981 : // Configure the padding
1982 2 : sequence_control_set_ptr->left_padding = BLOCK_SIZE_64 + 4;
1983 2 : sequence_control_set_ptr->top_padding = BLOCK_SIZE_64 + 4;
1984 2 : sequence_control_set_ptr->right_padding = BLOCK_SIZE_64 + 4;
1985 2 : sequence_control_set_ptr->bot_padding = sequence_control_set_ptr->static_config.super_block_size + 4;
1986 4 : sequence_control_set_ptr->static_config.enable_overlays = sequence_control_set_ptr->static_config.enable_altrefs == EB_FALSE ||
1987 2 : (sequence_control_set_ptr->static_config.altref_nframes <= 1) ||
1988 2 : (sequence_control_set_ptr->static_config.rate_control_mode > 0) ||
1989 2 : sequence_control_set_ptr->static_config.encoder_bit_depth != EB_8BIT ?
1990 : 0 : sequence_control_set_ptr->static_config.enable_overlays;
1991 :
1992 : //0: MRP Mode 0 (4,3)
1993 : //1: MRP Mode 1 (2,2)
1994 2 : sequence_control_set_ptr->mrp_mode = (uint8_t) (sequence_control_set_ptr->static_config.enc_mode == ENC_M0) ? 0 : 1;
1995 :
1996 : //0: ON
1997 : //1: OFF
1998 2 : sequence_control_set_ptr->cdf_mode = (uint8_t)(sequence_control_set_ptr->static_config.enc_mode <= ENC_M6) ? 0 : 1;
1999 :
2000 : //0: NSQ absent
2001 : //1: NSQ present
2002 2 : sequence_control_set_ptr->nsq_present = (uint8_t)(sequence_control_set_ptr->static_config.enc_mode <= ENC_M5) ? 1 : 0;
2003 :
2004 : // Set down-sampling method Settings
2005 : // 0 0: filtering
2006 : // 1 1: decimation
2007 2 : if (sequence_control_set_ptr->static_config.enc_mode == ENC_M0)
2008 1 : sequence_control_set_ptr->down_sampling_method_me_search = ME_FILTERED_DOWNSAMPLED;
2009 : else
2010 1 : sequence_control_set_ptr->down_sampling_method_me_search = ME_DECIMATED_DOWNSAMPLED;
2011 :
2012 : // Set over_boundary_block_mode Settings
2013 : // 0 0: not allowed
2014 : // 1 1: allowed
2015 2 : if (sequence_control_set_ptr->static_config.enc_mode == ENC_M0)
2016 1 : sequence_control_set_ptr->over_boundary_block_mode = 1;
2017 : else
2018 1 : sequence_control_set_ptr->over_boundary_block_mode = 0;
2019 :
2020 2 : sequence_control_set_ptr->mfmv_enabled = (uint8_t)(sequence_control_set_ptr->static_config.enc_mode == ENC_M0) ? 1 : 0;
2021 :
2022 : // Set hbd_mode_decision OFF for high encode modes or bitdepth < 10
2023 2 : if (sequence_control_set_ptr->static_config.enc_mode > ENC_M0 || sequence_control_set_ptr->static_config.encoder_bit_depth < 10)
2024 2 : sequence_control_set_ptr->static_config.enable_hbd_mode_decision = 0;
2025 2 : }
2026 :
2027 2 : void CopyApiFromApp(
2028 : SequenceControlSet *sequence_control_set_ptr,
2029 : EbSvtAv1EncConfiguration *pComponentParameterStructure){
2030 2 : uint32_t hmeRegionIndex = 0;
2031 :
2032 2 : sequence_control_set_ptr->max_input_luma_width = pComponentParameterStructure->source_width;
2033 2 : sequence_control_set_ptr->max_input_luma_height = pComponentParameterStructure->source_height;
2034 :
2035 2 : sequence_control_set_ptr->frame_rate = ((EbSvtAv1EncConfiguration*)pComponentParameterStructure)->frame_rate;
2036 :
2037 2 : sequence_control_set_ptr->general_frame_only_constraint_flag = 0;
2038 2 : sequence_control_set_ptr->general_progressive_source_flag = 1;
2039 2 : sequence_control_set_ptr->general_interlaced_source_flag = 0;
2040 :
2041 : // SB Definitions
2042 2 : sequence_control_set_ptr->static_config.pred_structure = 2; // Hardcoded(Cleanup)
2043 2 : sequence_control_set_ptr->static_config.enable_qp_scaling_flag = 1;
2044 :
2045 2 : sequence_control_set_ptr->max_cu_size = (uint8_t)64;
2046 2 : sequence_control_set_ptr->min_cu_size = (uint8_t)8;
2047 2 : sequence_control_set_ptr->max_intra_size = (uint8_t)32;
2048 2 : sequence_control_set_ptr->min_intra_size = (uint8_t)8;
2049 2 : sequence_control_set_ptr->intra4x4_flag = 1;
2050 2 : sequence_control_set_ptr->max_ref_count = 1;
2051 :
2052 : // Cropping Definitions - Hardcoded(CleanUp)
2053 2 : sequence_control_set_ptr->cropping_left_offset = -1;
2054 2 : sequence_control_set_ptr->cropping_right_offset = -1;
2055 2 : sequence_control_set_ptr->cropping_top_offset = -1;
2056 2 : sequence_control_set_ptr->cropping_bottom_offset = -1;
2057 :
2058 : // Padding Offsets
2059 2 : sequence_control_set_ptr->sb_sz = (uint8_t)((EbSvtAv1EncConfiguration*)pComponentParameterStructure)->sb_sz;
2060 2 : sequence_control_set_ptr->max_sb_depth = (uint8_t)((EbSvtAv1EncConfiguration*)pComponentParameterStructure)->partition_depth;
2061 :
2062 2 : if (sequence_control_set_ptr->cropping_left_offset == -1 &&
2063 2 : sequence_control_set_ptr->cropping_right_offset == -1 &&
2064 2 : sequence_control_set_ptr->cropping_top_offset == -1 &&
2065 2 : sequence_control_set_ptr->cropping_bottom_offset == -1) {
2066 2 : sequence_control_set_ptr->conformance_window_flag = 0;
2067 : }
2068 : else
2069 0 : sequence_control_set_ptr->conformance_window_flag = 1;
2070 2 : if (sequence_control_set_ptr->cropping_left_offset == -1)
2071 2 : sequence_control_set_ptr->cropping_left_offset = 0;
2072 2 : if (sequence_control_set_ptr->cropping_right_offset == -1)
2073 2 : sequence_control_set_ptr->cropping_right_offset = 0;
2074 2 : if (sequence_control_set_ptr->cropping_top_offset == -1)
2075 2 : sequence_control_set_ptr->cropping_top_offset = 0;
2076 2 : if (sequence_control_set_ptr->cropping_bottom_offset == -1)
2077 2 : sequence_control_set_ptr->cropping_bottom_offset = 0;
2078 :
2079 2 : sequence_control_set_ptr->static_config.intra_period_length = ((EbSvtAv1EncConfiguration*)pComponentParameterStructure)->intra_period_length;
2080 2 : sequence_control_set_ptr->static_config.intra_refresh_type = ((EbSvtAv1EncConfiguration*)pComponentParameterStructure)->intra_refresh_type;
2081 2 : sequence_control_set_ptr->static_config.base_layer_switch_mode = ((EbSvtAv1EncConfiguration*)pComponentParameterStructure)->base_layer_switch_mode;
2082 2 : sequence_control_set_ptr->static_config.hierarchical_levels = ((EbSvtAv1EncConfiguration*)pComponentParameterStructure)->hierarchical_levels;
2083 2 : sequence_control_set_ptr->static_config.enc_mode = ((EbSvtAv1EncConfiguration*)pComponentParameterStructure)->enc_mode;
2084 : #if TWO_PASS_USE_2NDP_ME_IN_1STP
2085 2 : sequence_control_set_ptr->static_config.snd_pass_enc_mode = ((EbSvtAv1EncConfiguration*)pComponentParameterStructure)->snd_pass_enc_mode;
2086 : #endif
2087 2 : sequence_control_set_ptr->intra_period_length = sequence_control_set_ptr->static_config.intra_period_length;
2088 2 : sequence_control_set_ptr->intra_refresh_type = sequence_control_set_ptr->static_config.intra_refresh_type;
2089 2 : sequence_control_set_ptr->max_temporal_layers = sequence_control_set_ptr->static_config.hierarchical_levels;
2090 2 : sequence_control_set_ptr->static_config.use_qp_file = ((EbSvtAv1EncConfiguration*)pComponentParameterStructure)->use_qp_file;
2091 : #if TWO_PASS
2092 2 : sequence_control_set_ptr->static_config.input_stat_file = ((EbSvtAv1EncConfiguration*)pComponentParameterStructure)->input_stat_file;
2093 2 : sequence_control_set_ptr->static_config.output_stat_file = ((EbSvtAv1EncConfiguration*)pComponentParameterStructure)->output_stat_file;
2094 2 : sequence_control_set_ptr->use_input_stat_file = sequence_control_set_ptr->static_config.input_stat_file ? 1 : 0;
2095 2 : sequence_control_set_ptr->use_output_stat_file = sequence_control_set_ptr->static_config.output_stat_file ? 1 : 0;
2096 : #endif
2097 : // Deblock Filter
2098 2 : sequence_control_set_ptr->static_config.disable_dlf_flag = ((EbSvtAv1EncConfiguration*)pComponentParameterStructure)->disable_dlf_flag;
2099 :
2100 : // Local Warped Motion
2101 2 : sequence_control_set_ptr->static_config.enable_warped_motion = EB_TRUE;
2102 :
2103 : // Global motion
2104 2 : sequence_control_set_ptr->static_config.enable_global_motion = ((EbSvtAv1EncConfiguration*)pComponentParameterStructure)->enable_global_motion;
2105 :
2106 : // OBMC
2107 2 : sequence_control_set_ptr->static_config.enable_obmc = ((EbSvtAv1EncConfiguration*)pComponentParameterStructure)->enable_obmc;
2108 :
2109 : // RDOQ
2110 2 : sequence_control_set_ptr->static_config.enable_rdoq = ((EbSvtAv1EncConfiguration*)pComponentParameterStructure)->enable_rdoq;
2111 :
2112 : // Filter intra prediction
2113 2 : sequence_control_set_ptr->static_config.enable_filter_intra = ((EbSvtAv1EncConfiguration*)pComponentParameterStructure)->enable_filter_intra;
2114 :
2115 : // ME Tools
2116 2 : sequence_control_set_ptr->static_config.use_default_me_hme = ((EbSvtAv1EncConfiguration*)pComponentParameterStructure)->use_default_me_hme;
2117 2 : sequence_control_set_ptr->static_config.enable_hme_flag = ((EbSvtAv1EncConfiguration*)pComponentParameterStructure)->enable_hme_flag;
2118 2 : sequence_control_set_ptr->static_config.enable_hme_level0_flag = ((EbSvtAv1EncConfiguration*)pComponentParameterStructure)->enable_hme_level0_flag;
2119 2 : sequence_control_set_ptr->static_config.enable_hme_level1_flag = ((EbSvtAv1EncConfiguration*)pComponentParameterStructure)->enable_hme_level1_flag;
2120 2 : sequence_control_set_ptr->static_config.enable_hme_level2_flag = ((EbSvtAv1EncConfiguration*)pComponentParameterStructure)->enable_hme_level2_flag;
2121 2 : sequence_control_set_ptr->static_config.search_area_width = ((EbSvtAv1EncConfiguration*)pComponentParameterStructure)->search_area_width;
2122 2 : sequence_control_set_ptr->static_config.search_area_height = ((EbSvtAv1EncConfiguration*)pComponentParameterStructure)->search_area_height;
2123 2 : sequence_control_set_ptr->static_config.number_hme_search_region_in_width = ((EbSvtAv1EncConfiguration*)pComponentParameterStructure)->number_hme_search_region_in_width;
2124 2 : sequence_control_set_ptr->static_config.number_hme_search_region_in_height = ((EbSvtAv1EncConfiguration*)pComponentParameterStructure)->number_hme_search_region_in_height;
2125 2 : sequence_control_set_ptr->static_config.hme_level0_total_search_area_width = ((EbSvtAv1EncConfiguration*)pComponentParameterStructure)->hme_level0_total_search_area_width;
2126 2 : sequence_control_set_ptr->static_config.hme_level0_total_search_area_height = ((EbSvtAv1EncConfiguration*)pComponentParameterStructure)->hme_level0_total_search_area_height;
2127 2 : sequence_control_set_ptr->static_config.ext_block_flag = ((EbSvtAv1EncConfiguration*)pComponentParameterStructure)->ext_block_flag;
2128 2 : sequence_control_set_ptr->static_config.in_loop_me_flag = ((EbSvtAv1EncConfiguration*)pComponentParameterStructure)->in_loop_me_flag;
2129 :
2130 6 : for (hmeRegionIndex = 0; hmeRegionIndex < sequence_control_set_ptr->static_config.number_hme_search_region_in_width; ++hmeRegionIndex) {
2131 4 : sequence_control_set_ptr->static_config.hme_level0_search_area_in_width_array[hmeRegionIndex] = ((EbSvtAv1EncConfiguration*)pComponentParameterStructure)->hme_level0_search_area_in_width_array[hmeRegionIndex];
2132 4 : sequence_control_set_ptr->static_config.hme_level1_search_area_in_width_array[hmeRegionIndex] = ((EbSvtAv1EncConfiguration*)pComponentParameterStructure)->hme_level1_search_area_in_width_array[hmeRegionIndex];
2133 4 : sequence_control_set_ptr->static_config.hme_level2_search_area_in_width_array[hmeRegionIndex] = ((EbSvtAv1EncConfiguration*)pComponentParameterStructure)->hme_level2_search_area_in_width_array[hmeRegionIndex];
2134 : }
2135 :
2136 6 : for (hmeRegionIndex = 0; hmeRegionIndex < sequence_control_set_ptr->static_config.number_hme_search_region_in_height; ++hmeRegionIndex) {
2137 4 : sequence_control_set_ptr->static_config.hme_level0_search_area_in_height_array[hmeRegionIndex] = ((EbSvtAv1EncConfiguration*)pComponentParameterStructure)->hme_level0_search_area_in_height_array[hmeRegionIndex];
2138 4 : sequence_control_set_ptr->static_config.hme_level1_search_area_in_height_array[hmeRegionIndex] = ((EbSvtAv1EncConfiguration*)pComponentParameterStructure)->hme_level1_search_area_in_height_array[hmeRegionIndex];
2139 4 : sequence_control_set_ptr->static_config.hme_level2_search_area_in_height_array[hmeRegionIndex] = ((EbSvtAv1EncConfiguration*)pComponentParameterStructure)->hme_level2_search_area_in_height_array[hmeRegionIndex];
2140 : }
2141 :
2142 : //Denoise - Hardcoded(CleanUp)
2143 2 : sequence_control_set_ptr->static_config.enable_denoise_flag = 0;
2144 :
2145 : //Film Grain
2146 2 : sequence_control_set_ptr->static_config.film_grain_denoise_strength = ((EbSvtAv1EncConfiguration*)pComponentParameterStructure)->film_grain_denoise_strength;
2147 2 : sequence_control_set_ptr->film_grain_denoise_strength = sequence_control_set_ptr->static_config.film_grain_denoise_strength;
2148 :
2149 : // MD Parameters
2150 2 : sequence_control_set_ptr->static_config.enable_hbd_mode_decision = ((EbSvtAv1EncConfiguration*)pComponentParameterStructure)->encoder_bit_depth > 8 ? ((EbSvtAv1EncConfiguration*)pComponentParameterStructure)->enable_hbd_mode_decision : 0;
2151 2 : sequence_control_set_ptr->static_config.constrained_intra = ((EbSvtAv1EncConfiguration*)pComponentParameterStructure)->constrained_intra;
2152 2 : sequence_control_set_ptr->static_config.enable_palette = ((EbSvtAv1EncConfiguration*)pComponentParameterStructure)->enable_palette;
2153 2 : sequence_control_set_ptr->static_config.olpd_refinement = ((EbSvtAv1EncConfiguration*)pComponentParameterStructure)->olpd_refinement;
2154 : // Adaptive Loop Filter
2155 2 : sequence_control_set_ptr->static_config.tile_rows = ((EbSvtAv1EncConfiguration*)pComponentParameterStructure)->tile_rows;
2156 2 : sequence_control_set_ptr->static_config.tile_columns = ((EbSvtAv1EncConfiguration*)pComponentParameterStructure)->tile_columns;
2157 2 : sequence_control_set_ptr->static_config.unrestricted_motion_vector = ((EbSvtAv1EncConfiguration*)pComponentParameterStructure)->unrestricted_motion_vector;
2158 :
2159 : // Rate Control
2160 2 : sequence_control_set_ptr->static_config.scene_change_detection = ((EbSvtAv1EncConfiguration*)pComponentParameterStructure)->scene_change_detection;
2161 2 : sequence_control_set_ptr->static_config.rate_control_mode = ((EbSvtAv1EncConfiguration*)pComponentParameterStructure)->rate_control_mode;
2162 2 : sequence_control_set_ptr->static_config.look_ahead_distance = ((EbSvtAv1EncConfiguration*)pComponentParameterStructure)->look_ahead_distance;
2163 2 : sequence_control_set_ptr->static_config.frames_to_be_encoded = ((EbSvtAv1EncConfiguration*)pComponentParameterStructure)->frames_to_be_encoded;
2164 2 : sequence_control_set_ptr->static_config.frame_rate = ((EbSvtAv1EncConfiguration*)pComponentParameterStructure)->frame_rate;
2165 2 : sequence_control_set_ptr->static_config.frame_rate_denominator = ((EbSvtAv1EncConfiguration*)pComponentParameterStructure)->frame_rate_denominator;
2166 2 : sequence_control_set_ptr->static_config.frame_rate_numerator = ((EbSvtAv1EncConfiguration*)pComponentParameterStructure)->frame_rate_numerator;
2167 :
2168 2 : sequence_control_set_ptr->static_config.target_bit_rate = ((EbSvtAv1EncConfiguration*)pComponentParameterStructure)->target_bit_rate;
2169 :
2170 4 : sequence_control_set_ptr->static_config.max_qp_allowed = (sequence_control_set_ptr->static_config.rate_control_mode) ?
2171 2 : ((EbSvtAv1EncConfiguration*)pComponentParameterStructure)->max_qp_allowed :
2172 : 63;
2173 :
2174 4 : sequence_control_set_ptr->static_config.min_qp_allowed = (sequence_control_set_ptr->static_config.rate_control_mode) ?
2175 2 : ((EbSvtAv1EncConfiguration*)pComponentParameterStructure)->min_qp_allowed :
2176 : 1; // lossless coding not supported
2177 :
2178 : //Segmentation
2179 : //TODO: check RC mode and set only when RC is enabled in the final version.
2180 2 : sequence_control_set_ptr->static_config.enable_adaptive_quantization = pComponentParameterStructure->enable_adaptive_quantization;
2181 :
2182 : // Misc
2183 2 : sequence_control_set_ptr->static_config.encoder_bit_depth = ((EbSvtAv1EncConfiguration*)pComponentParameterStructure)->encoder_bit_depth;
2184 2 : sequence_control_set_ptr->static_config.encoder_color_format = ((EbSvtAv1EncConfiguration*)pComponentParameterStructure)->encoder_color_format;
2185 2 : if (sequence_control_set_ptr->static_config.encoder_color_format == EB_YUV400) {
2186 0 : SVT_LOG("SVT [Warning]: Color format EB_YUV400 not supported, set to EB_YUV420\n");
2187 0 : sequence_control_set_ptr->static_config.encoder_color_format = EB_YUV420;
2188 : }
2189 2 : sequence_control_set_ptr->chroma_format_idc = (uint32_t)(sequence_control_set_ptr->static_config.encoder_color_format);
2190 2 : sequence_control_set_ptr->encoder_bit_depth = (uint32_t)(sequence_control_set_ptr->static_config.encoder_bit_depth);
2191 :
2192 2 : sequence_control_set_ptr->subsampling_x = (sequence_control_set_ptr->chroma_format_idc == EB_YUV444 ? 1 : 2) - 1;
2193 2 : sequence_control_set_ptr->subsampling_y = (sequence_control_set_ptr->chroma_format_idc >= EB_YUV422 ? 1 : 2) - 1;
2194 2 : sequence_control_set_ptr->static_config.ten_bit_format = ((EbSvtAv1EncConfiguration*)pComponentParameterStructure)->ten_bit_format;
2195 2 : sequence_control_set_ptr->static_config.compressed_ten_bit_format = ((EbSvtAv1EncConfiguration*)pComponentParameterStructure)->compressed_ten_bit_format;
2196 :
2197 : // Thresholds
2198 2 : sequence_control_set_ptr->static_config.high_dynamic_range_input = ((EbSvtAv1EncConfiguration*)pComponentParameterStructure)->high_dynamic_range_input;
2199 2 : sequence_control_set_ptr->static_config.screen_content_mode = ((EbSvtAv1EncConfiguration*)pComponentParameterStructure)->screen_content_mode;
2200 :
2201 : // Annex A parameters
2202 2 : sequence_control_set_ptr->static_config.profile = ((EbSvtAv1EncConfiguration*)pComponentParameterStructure)->profile;
2203 2 : sequence_control_set_ptr->static_config.tier = ((EbSvtAv1EncConfiguration*)pComponentParameterStructure)->tier;
2204 2 : sequence_control_set_ptr->static_config.level = ((EbSvtAv1EncConfiguration*)pComponentParameterStructure)->level;
2205 2 : sequence_control_set_ptr->static_config.stat_report = ((EbSvtAv1EncConfiguration*)pComponentParameterStructure)->stat_report;
2206 :
2207 2 : sequence_control_set_ptr->static_config.injector_frame_rate = ((EbSvtAv1EncConfiguration*)pComponentParameterStructure)->injector_frame_rate;
2208 2 : sequence_control_set_ptr->static_config.speed_control_flag = ((EbSvtAv1EncConfiguration*)pComponentParameterStructure)->speed_control_flag;
2209 :
2210 : // Buffers - Hardcoded(Cleanup)
2211 2 : sequence_control_set_ptr->static_config.asm_type = ((EbSvtAv1EncConfiguration*)pComponentParameterStructure)->asm_type;
2212 :
2213 2 : sequence_control_set_ptr->static_config.channel_id = ((EbSvtAv1EncConfiguration*)pComponentParameterStructure)->channel_id;
2214 2 : sequence_control_set_ptr->static_config.active_channel_count = ((EbSvtAv1EncConfiguration*)pComponentParameterStructure)->active_channel_count;
2215 2 : sequence_control_set_ptr->static_config.logical_processors = ((EbSvtAv1EncConfiguration*)pComponentParameterStructure)->logical_processors;
2216 2 : sequence_control_set_ptr->static_config.target_socket = ((EbSvtAv1EncConfiguration*)pComponentParameterStructure)->target_socket;
2217 2 : sequence_control_set_ptr->qp = ((EbSvtAv1EncConfiguration*)pComponentParameterStructure)->qp;
2218 2 : sequence_control_set_ptr->static_config.recon_enabled = ((EbSvtAv1EncConfiguration*)pComponentParameterStructure)->recon_enabled;
2219 :
2220 : // Extract frame rate from Numerator and Denominator if not 0
2221 2 : if (sequence_control_set_ptr->static_config.frame_rate_numerator != 0 && sequence_control_set_ptr->static_config.frame_rate_denominator != 0)
2222 2 : sequence_control_set_ptr->frame_rate = sequence_control_set_ptr->static_config.frame_rate = (((sequence_control_set_ptr->static_config.frame_rate_numerator << 8) / (sequence_control_set_ptr->static_config.frame_rate_denominator)) << 8);
2223 : // Get Default Intra Period if not specified
2224 2 : if (sequence_control_set_ptr->static_config.intra_period_length == -2)
2225 2 : sequence_control_set_ptr->intra_period_length = sequence_control_set_ptr->static_config.intra_period_length = compute_default_intra_period(sequence_control_set_ptr);
2226 2 : if (sequence_control_set_ptr->static_config.look_ahead_distance == (uint32_t)~0)
2227 2 : sequence_control_set_ptr->static_config.look_ahead_distance = compute_default_look_ahead(&sequence_control_set_ptr->static_config);
2228 : else
2229 0 : sequence_control_set_ptr->static_config.look_ahead_distance = cap_look_ahead_distance(&sequence_control_set_ptr->static_config);
2230 :
2231 2 : sequence_control_set_ptr->static_config.enable_altrefs = pComponentParameterStructure->enable_altrefs;
2232 2 : sequence_control_set_ptr->static_config.altref_strength = pComponentParameterStructure->altref_strength;
2233 2 : sequence_control_set_ptr->static_config.altref_nframes = pComponentParameterStructure->altref_nframes;
2234 2 : sequence_control_set_ptr->static_config.enable_overlays = pComponentParameterStructure->enable_overlays;
2235 :
2236 2 : sequence_control_set_ptr->static_config.sq_weight = pComponentParameterStructure->sq_weight;
2237 :
2238 2 : sequence_control_set_ptr->static_config.md_stage_1_cand_prune_th = pComponentParameterStructure->md_stage_1_cand_prune_th;
2239 2 : sequence_control_set_ptr->static_config.md_stage_1_class_prune_th = pComponentParameterStructure->md_stage_1_class_prune_th;
2240 2 : sequence_control_set_ptr->static_config.md_stage_2_cand_prune_th = pComponentParameterStructure->md_stage_2_cand_prune_th;
2241 2 : sequence_control_set_ptr->static_config.md_stage_2_class_prune_th = pComponentParameterStructure->md_stage_2_class_prune_th;
2242 :
2243 2 : return;
2244 : }
2245 :
2246 : /******************************************
2247 : * Verify Settings
2248 : ******************************************/
2249 : #define PowerOfTwoCheck(x) (((x) != 0) && (((x) & (~(x) + 1)) == (x)))
2250 :
2251 4 : static int VerifyHmeDimention(unsigned int index, unsigned int HmeLevel0SearchAreaInWidth, uint32_t number_hme_search_region_in_width_array[EB_HME_SEARCH_AREA_ROW_MAX_COUNT], unsigned int number_hme_search_region_in_width)
2252 : {
2253 4 : int return_error = 0;
2254 : uint32_t i;
2255 4 : uint32_t total_search_width = 0;
2256 :
2257 12 : for (i = 0; i < number_hme_search_region_in_width; i++)
2258 8 : total_search_width += number_hme_search_region_in_width_array[i];
2259 4 : if ((total_search_width) != (HmeLevel0SearchAreaInWidth)) {
2260 0 : SVT_LOG("Error Instance %u: Invalid HME Total Search Area. \n", index);
2261 0 : return_error = -1;
2262 0 : return return_error;
2263 : }
2264 :
2265 4 : return return_error;
2266 : }
2267 8 : static int VerifyHmeDimentionL1L2(unsigned int index, uint32_t number_hme_search_region_in_width_array[EB_HME_SEARCH_AREA_ROW_MAX_COUNT], unsigned int number_hme_search_region_in_width)
2268 : {
2269 8 : int return_error = 0;
2270 : uint32_t i;
2271 8 : uint32_t total_search_width = 0;
2272 :
2273 24 : for (i = 0; i < number_hme_search_region_in_width; i++)
2274 16 : total_search_width += number_hme_search_region_in_width_array[i];
2275 8 : if ((total_search_width > 256) || (total_search_width == 0)) {
2276 0 : SVT_LOG("Error Instance %u: Invalid HME Total Search Area. Must be [1 - 256].\n", index);
2277 0 : return_error = -1;
2278 0 : return return_error;
2279 : }
2280 :
2281 8 : return return_error;
2282 : }
2283 :
2284 2 : static EbErrorType VerifySettings(
2285 : SequenceControlSet *sequence_control_set_ptr)
2286 : {
2287 2 : EbErrorType return_error = EB_ErrorNone;
2288 2 : EbSvtAv1EncConfiguration *config = &sequence_control_set_ptr->static_config;
2289 2 : unsigned int channelNumber = config->channel_id;
2290 2 : if (config->enc_mode > MAX_ENC_PRESET) {
2291 0 : SVT_LOG("Error instance %u: EncoderMode must be in the range of [0-%d]\n", channelNumber + 1, MAX_ENC_PRESET);
2292 0 : return_error = EB_ErrorBadParameter;
2293 : }
2294 : #if TWO_PASS_USE_2NDP_ME_IN_1STP
2295 2 : if (config->snd_pass_enc_mode > MAX_ENC_PRESET + 1) {
2296 0 : SVT_LOG("Error instance %u: Second pass encoder mode must be in the range of [0-%d]\n", channelNumber + 1, MAX_ENC_PRESET + 1);
2297 0 : return_error = EB_ErrorBadParameter;
2298 : }
2299 : #endif
2300 2 : if (config->ext_block_flag > 1) {
2301 0 : SVT_LOG("Error instance %u: ExtBlockFlag must be [0-1]\n", channelNumber + 1);
2302 0 : return_error = EB_ErrorBadParameter;
2303 : }
2304 :
2305 2 : if (config->in_loop_me_flag > 1) {
2306 0 : SVT_LOG("Error instance %u: InLoopMeFlag must be [0-1]\n", channelNumber + 1);
2307 0 : return_error = EB_ErrorBadParameter;
2308 : }
2309 :
2310 2 : if (sequence_control_set_ptr->max_input_luma_width < 64) {
2311 0 : SVT_LOG("Error instance %u: Source Width must be at least 64\n", channelNumber + 1);
2312 0 : return_error = EB_ErrorBadParameter;
2313 : }
2314 2 : if (sequence_control_set_ptr->max_input_luma_height < 64) {
2315 0 : SVT_LOG("Error instance %u: Source Width must be at least 64\n", channelNumber + 1);
2316 0 : return_error = EB_ErrorBadParameter;
2317 : }
2318 :
2319 2 : if (config->pred_structure != 2) {
2320 0 : SVT_LOG("Error instance %u: Pred Structure must be [2]\n", channelNumber + 1);
2321 0 : return_error = EB_ErrorBadParameter;
2322 : }
2323 :
2324 2 : if (config->base_layer_switch_mode == 1 && config->pred_structure != 2) {
2325 0 : SVT_LOG("Error Instance %u: Base Layer Switch Mode 1 only when Prediction Structure is Random Access\n", channelNumber + 1);
2326 0 : return_error = EB_ErrorBadParameter;
2327 : }
2328 2 : if (sequence_control_set_ptr->max_input_luma_width % 8 && sequence_control_set_ptr->static_config.compressed_ten_bit_format == 1) {
2329 0 : SVT_LOG("Error Instance %u: Only multiple of 8 width is supported for compressed 10-bit inputs \n", channelNumber + 1);
2330 0 : return_error = EB_ErrorBadParameter;
2331 : }
2332 :
2333 2 : if (sequence_control_set_ptr->max_input_luma_width % 2) {
2334 0 : SVT_LOG("Error Instance %u: Source Width must be even for YUV_420 colorspace\n", channelNumber + 1);
2335 0 : return_error = EB_ErrorBadParameter;
2336 : }
2337 :
2338 2 : if (sequence_control_set_ptr->max_input_luma_height % 2) {
2339 0 : SVT_LOG("Error Instance %u: Source Height must be even for YUV_420 colorspace\n", channelNumber + 1);
2340 0 : return_error = EB_ErrorBadParameter;
2341 : }
2342 :
2343 2 : if (sequence_control_set_ptr->max_input_luma_width > 4096) {
2344 0 : SVT_LOG("Error instance %u: Source Width must be less than 4096\n", channelNumber + 1);
2345 0 : return_error = EB_ErrorBadParameter;
2346 : }
2347 :
2348 2 : if (sequence_control_set_ptr->max_input_luma_height > 2160) {
2349 0 : SVT_LOG("Error instance %u: Source Height must be less than 2160\n", channelNumber + 1);
2350 0 : return_error = EB_ErrorBadParameter;
2351 : }
2352 :
2353 2 : if (config->qp > MAX_QP_VALUE) {
2354 0 : SVT_LOG("Error instance %u: QP must be [0 - %d]\n", channelNumber + 1, MAX_QP_VALUE);
2355 0 : return_error = EB_ErrorBadParameter;
2356 : }
2357 2 : if (config->hierarchical_levels != 3 && config->hierarchical_levels != 4) {
2358 0 : SVT_LOG("Error instance %u: Hierarchical Levels supported [3-4]\n", channelNumber + 1);
2359 0 : return_error = EB_ErrorBadParameter;
2360 : }
2361 2 : if (config->intra_period_length < -2 || config->intra_period_length > 255) {
2362 0 : SVT_LOG("Error Instance %u: The intra period must be [-2 - 255] \n", channelNumber + 1);
2363 0 : return_error = EB_ErrorBadParameter;
2364 : }
2365 :
2366 2 : if (config->intra_refresh_type > 2 || config->intra_refresh_type < 1) {
2367 0 : SVT_LOG("Error Instance %u: Invalid intra Refresh Type [1-2]\n", channelNumber + 1);
2368 0 : return_error = EB_ErrorBadParameter;
2369 : }
2370 2 : if (config->base_layer_switch_mode > 1) {
2371 0 : SVT_LOG("Error Instance %u: Invalid Base Layer Switch Mode [0-1] \n", channelNumber + 1);
2372 0 : return_error = EB_ErrorBadParameter;
2373 : }
2374 :
2375 2 : if (config->disable_dlf_flag > 1) {
2376 0 : SVT_LOG("Error Instance %u: Invalid LoopFilterDisable. LoopFilterDisable must be [0 - 1]\n", channelNumber + 1);
2377 0 : return_error = EB_ErrorBadParameter;
2378 : }
2379 :
2380 2 : if (config->use_default_me_hme > 1) {
2381 0 : SVT_LOG("Error Instance %u: invalid use_default_me_hme. use_default_me_hme must be [0 - 1]\n", channelNumber + 1);
2382 0 : return_error = EB_ErrorBadParameter;
2383 : }
2384 2 : if (config->enable_hme_flag > 1) {
2385 0 : SVT_LOG("Error Instance %u: invalid HME. HME must be [0 - 1]\n", channelNumber + 1);
2386 0 : return_error = EB_ErrorBadParameter;
2387 : }
2388 :
2389 2 : if (config->enable_hme_level0_flag > 1) {
2390 0 : SVT_LOG("Error Instance %u: invalid enable HMELevel0. HMELevel0 must be [0 - 1]\n", channelNumber + 1);
2391 0 : return_error = EB_ErrorBadParameter;
2392 : }
2393 :
2394 2 : if (config->enable_hme_level1_flag > 1) {
2395 0 : SVT_LOG("Error Instance %u: invalid enable HMELevel1. HMELevel1 must be [0 - 1]\n", channelNumber + 1);
2396 0 : return_error = EB_ErrorBadParameter;
2397 : }
2398 :
2399 2 : if (config->enable_hme_level2_flag > 1) {
2400 0 : SVT_LOG("Error Instance %u: invalid enable HMELevel2. HMELevel2 must be [0 - 1]\n", channelNumber + 1);
2401 0 : return_error = EB_ErrorBadParameter;
2402 : }
2403 :
2404 2 : if ((config->search_area_width > 256) || (config->search_area_width == 0)) {
2405 0 : SVT_LOG("Error Instance %u: Invalid search_area_width. search_area_width must be [1 - 256]\n", channelNumber + 1);
2406 0 : return_error = EB_ErrorBadParameter;
2407 : }
2408 :
2409 2 : if ((config->search_area_height > 256) || (config->search_area_height == 0)) {
2410 0 : SVT_LOG("Error Instance %u: Invalid search_area_height. search_area_height must be [1 - 256]\n", channelNumber + 1);
2411 0 : return_error = EB_ErrorBadParameter;
2412 : }
2413 :
2414 2 : if (config->enable_hme_flag) {
2415 2 : if ((config->number_hme_search_region_in_width > (uint32_t)EB_HME_SEARCH_AREA_COLUMN_MAX_COUNT) || (config->number_hme_search_region_in_width == 0)) {
2416 0 : SVT_LOG("Error Instance %u: Invalid number_hme_search_region_in_width. number_hme_search_region_in_width must be [1 - %d]\n", channelNumber + 1, EB_HME_SEARCH_AREA_COLUMN_MAX_COUNT);
2417 0 : return_error = EB_ErrorBadParameter;
2418 : }
2419 :
2420 2 : if ((config->number_hme_search_region_in_height > (uint32_t)EB_HME_SEARCH_AREA_ROW_MAX_COUNT) || (config->number_hme_search_region_in_height == 0)) {
2421 0 : SVT_LOG("Error Instance %u: Invalid number_hme_search_region_in_height. number_hme_search_region_in_height must be [1 - %d]\n", channelNumber + 1, EB_HME_SEARCH_AREA_ROW_MAX_COUNT);
2422 0 : return_error = EB_ErrorBadParameter;
2423 : }
2424 :
2425 2 : if ((config->hme_level0_total_search_area_height > 256) || (config->hme_level0_total_search_area_height == 0)) {
2426 0 : SVT_LOG("Error Instance %u: Invalid hme_level0_total_search_area_height. hme_level0_total_search_area_height must be [1 - 256]\n", channelNumber + 1);
2427 0 : return_error = EB_ErrorBadParameter;
2428 : }
2429 2 : if ((config->hme_level0_total_search_area_width > 256) || (config->hme_level0_total_search_area_width == 0)) {
2430 0 : SVT_LOG("Error Instance %u: Invalid hme_level0_total_search_area_width. hme_level0_total_search_area_width must be [1 - 256]\n", channelNumber + 1);
2431 0 : return_error = EB_ErrorBadParameter;
2432 : }
2433 2 : if (VerifyHmeDimention(channelNumber + 1, config->hme_level0_total_search_area_height, config->hme_level0_search_area_in_height_array, config->number_hme_search_region_in_height))
2434 0 : return_error = EB_ErrorBadParameter;
2435 2 : if (VerifyHmeDimention(channelNumber + 1, config->hme_level0_total_search_area_width, config->hme_level0_search_area_in_width_array, config->number_hme_search_region_in_width))
2436 0 : return_error = EB_ErrorBadParameter;
2437 2 : if (VerifyHmeDimentionL1L2(channelNumber + 1, config->hme_level1_search_area_in_width_array, config->number_hme_search_region_in_width))
2438 0 : return_error = EB_ErrorBadParameter;
2439 2 : if (VerifyHmeDimentionL1L2(channelNumber + 1, config->hme_level1_search_area_in_height_array, config->number_hme_search_region_in_width))
2440 0 : return_error = EB_ErrorBadParameter;
2441 2 : if (VerifyHmeDimentionL1L2(channelNumber + 1, config->hme_level2_search_area_in_width_array, config->number_hme_search_region_in_width))
2442 0 : return_error = EB_ErrorBadParameter;
2443 2 : if (VerifyHmeDimentionL1L2(channelNumber + 1, config->hme_level2_search_area_in_height_array, config->number_hme_search_region_in_width))
2444 0 : return_error = EB_ErrorBadParameter;
2445 : }
2446 :
2447 2 : if (config->profile > 2) {
2448 0 : SVT_LOG("Error Instance %u: The maximum allowed profile value is 2 \n", channelNumber + 1);
2449 0 : return_error = EB_ErrorBadParameter;
2450 : }
2451 :
2452 : // Check if the current input video is conformant with the Level constraint
2453 2 : if (config->frame_rate > (240 << 16)) {
2454 0 : SVT_LOG("Error Instance %u: The maximum allowed frame rate is 240 fps\n", channelNumber + 1);
2455 0 : return_error = EB_ErrorBadParameter;
2456 : }
2457 : // Check that the frame_rate is non-zero
2458 2 : if (config->frame_rate <= 0) {
2459 0 : SVT_LOG("Error Instance %u: The frame rate should be greater than 0 fps \n", channelNumber + 1);
2460 0 : return_error = EB_ErrorBadParameter;
2461 : }
2462 2 : if (config->intra_period_length < -2 || config->intra_period_length > 255) {
2463 0 : SVT_LOG("Error Instance %u: The intra period must be [-2 - 255] \n", channelNumber + 1);
2464 0 : return_error = EB_ErrorBadParameter;
2465 : }
2466 2 : if (config->constrained_intra > 1) {
2467 0 : SVT_LOG("Error Instance %u: The constrained intra must be [0 - 1] \n", channelNumber + 1);
2468 0 : return_error = EB_ErrorBadParameter;
2469 : }
2470 2 : if (config->rate_control_mode > 3) {
2471 0 : SVT_LOG("Error Instance %u: The rate control mode must be [0 - 3] \n", channelNumber + 1);
2472 0 : return_error = EB_ErrorBadParameter;
2473 : }
2474 2 : if (config->rate_control_mode == 1) {
2475 0 : SVT_LOG("Error Instance %u: The rate control mode 1 is currently not supported \n", channelNumber + 1);
2476 0 : return_error = EB_ErrorBadParameter;
2477 : }
2478 2 : if ((config->rate_control_mode == 3|| config->rate_control_mode == 2) && config->look_ahead_distance != (uint32_t)config->intra_period_length) {
2479 0 : SVT_LOG("Error Instance %u: The rate control mode 2/3 LAD must be equal to intra_period \n", channelNumber + 1);
2480 0 : return_error = EB_ErrorBadParameter;
2481 : }
2482 2 : if (config->look_ahead_distance > MAX_LAD && config->look_ahead_distance != (uint32_t)~0) {
2483 0 : SVT_LOG("Error Instance %u: The lookahead distance must be [0 - %d] \n", channelNumber + 1, MAX_LAD);
2484 :
2485 0 : return_error = EB_ErrorBadParameter;
2486 : }
2487 2 : if (config->tile_rows < 0 || config->tile_columns < 0 || config->tile_rows > 6 || config->tile_columns > 6) {
2488 0 : SVT_LOG("Error Instance %u: Log2Tile rows/cols must be [0 - 6] \n", channelNumber + 1);
2489 0 : return_error = EB_ErrorBadParameter;
2490 : }
2491 2 : if (config->unrestricted_motion_vector > 1) {
2492 0 : SVT_LOG("Error Instance %u : Invalid Unrestricted Motion Vector flag [0 - 1]\n", channelNumber + 1);
2493 0 : return_error = EB_ErrorBadParameter;
2494 : }
2495 :
2496 2 : if (config->scene_change_detection > 1) {
2497 0 : SVT_LOG("Error Instance %u: The scene change detection must be [0 - 1] \n", channelNumber + 1);
2498 0 : return_error = EB_ErrorBadParameter;
2499 : }
2500 2 : if (config->max_qp_allowed > MAX_QP_VALUE) {
2501 0 : SVT_LOG("Error instance %u: MaxQpAllowed must be [0 - %d]\n", channelNumber + 1, MAX_QP_VALUE);
2502 0 : return_error = EB_ErrorBadParameter;
2503 : }
2504 2 : else if (config->min_qp_allowed >= MAX_QP_VALUE) {
2505 0 : SVT_LOG("Error instance %u: MinQpAllowed must be [0 - %d]\n", channelNumber + 1, MAX_QP_VALUE-1);
2506 0 : return_error = EB_ErrorBadParameter;
2507 : }
2508 2 : else if ((config->min_qp_allowed) > (config->max_qp_allowed)) {
2509 0 : SVT_LOG("Error Instance %u: MinQpAllowed must be smaller than MaxQpAllowed\n", channelNumber + 1);
2510 0 : return_error = EB_ErrorBadParameter;
2511 : }
2512 :
2513 2 : if (config->stat_report > 1) {
2514 0 : SVT_LOG("Error instance %u : Invalid StatReport. StatReport must be [0 - 1]\n", channelNumber + 1);
2515 0 : return_error = EB_ErrorBadParameter;
2516 : }
2517 :
2518 2 : if (config->high_dynamic_range_input > 1) {
2519 0 : SVT_LOG("Error instance %u : Invalid HighDynamicRangeInput. HighDynamicRangeInput must be [0 - 1]\n", channelNumber + 1);
2520 0 : return_error = EB_ErrorBadParameter;
2521 : }
2522 :
2523 2 : if (config->screen_content_mode > 2) {
2524 0 : SVT_LOG("Error instance %u : Invalid screen_content_mode. screen_content_mode must be [0 - 2]\n", channelNumber + 1);
2525 0 : return_error = EB_ErrorBadParameter;
2526 : }
2527 2 : if (sequence_control_set_ptr->static_config.enable_adaptive_quantization > 2) {
2528 0 : SVT_LOG("Error instance %u : Invalid enable_adaptive_quantization. enable_adaptive_quantization must be [0-2]\n", channelNumber + 1);
2529 0 : return_error = EB_ErrorBadParameter;
2530 : }
2531 :
2532 2 : if ((config->encoder_bit_depth != 8) &&
2533 0 : (config->encoder_bit_depth != 10)
2534 : ) {
2535 0 : SVT_LOG("Error instance %u: Encoder Bit Depth shall be only 8 or 10 \n", channelNumber + 1);
2536 0 : return_error = EB_ErrorBadParameter;
2537 : }
2538 : // Check if the EncoderBitDepth is conformant with the Profile constraint
2539 2 : if ((config->profile == 0 || config->profile == 1) && config->encoder_bit_depth > 10) {
2540 0 : SVT_LOG("Error instance %u: The encoder bit depth shall be equal to 8 or 10 for Main/High Profile\n", channelNumber + 1);
2541 0 : return_error = EB_ErrorBadParameter;
2542 : }
2543 :
2544 2 : if (config->profile == 0 && config->encoder_color_format > EB_YUV420) {
2545 0 : SVT_LOG("Error instance %u: Non 420 color format requires profile 1 or 2\n", channelNumber + 1);
2546 0 : return_error = EB_ErrorBadParameter;
2547 : }
2548 :
2549 2 : if (config->profile == 1 && config->encoder_color_format != EB_YUV444) {
2550 0 : SVT_LOG("Error instance %u: Profile 1 requires 4:4:4 color format\n", channelNumber + 1);
2551 0 : return_error = EB_ErrorBadParameter;
2552 : }
2553 :
2554 2 : if (config->profile == 2 && config->encoder_bit_depth <= 10 && config->encoder_color_format != EB_YUV422) {
2555 0 : SVT_LOG("Error instance %u: Profile 2 bit-depth < 10 requires 4:2:2 color format\n", channelNumber + 1);
2556 0 : return_error = EB_ErrorBadParameter;
2557 : }
2558 :
2559 2 : if (config->compressed_ten_bit_format !=0)
2560 : {
2561 0 : SVT_LOG("Error instance %u: Compressed ten bit format is not supported in this version \n", channelNumber + 1);
2562 0 : return_error = EB_ErrorBadParameter;
2563 : }
2564 :
2565 2 : if (config->speed_control_flag > 1) {
2566 0 : SVT_LOG("Error Instance %u: Invalid Speed Control flag [0 - 1]\n", channelNumber + 1);
2567 0 : return_error = EB_ErrorBadParameter;
2568 : }
2569 :
2570 2 : if (((int32_t)(config->asm_type) < -1) || ((int32_t)(config->asm_type) != 1)) {
2571 : // SVT_LOG("Error Instance %u: Invalid asm type value [0: C Only, 1: Auto] .\n", channelNumber + 1);
2572 0 : SVT_LOG("Error Instance %u: Asm 0 is not supported in this build .\n", channelNumber + 1);
2573 0 : return_error = EB_ErrorBadParameter;
2574 : }
2575 :
2576 2 : if (config->target_socket != -1 && config->target_socket != 0 && config->target_socket != 1) {
2577 0 : SVT_LOG("Error instance %u: Invalid target_socket. target_socket must be [-1 - 1] \n", channelNumber + 1);
2578 0 : return_error = EB_ErrorBadParameter;
2579 : }
2580 :
2581 : // alt-ref frames related
2582 2 : if (config->altref_strength > ALTREF_MAX_STRENGTH ) {
2583 0 : SVT_LOG("Error instance %u: invalid altref-strength, should be in the range [0 - %d] \n", channelNumber + 1, ALTREF_MAX_STRENGTH);
2584 0 : return_error = EB_ErrorBadParameter;
2585 : }
2586 :
2587 2 : if (config->altref_nframes > ALTREF_MAX_NFRAMES ) {
2588 0 : SVT_LOG("Error instance %u: invalid altref-nframes, should be in the range [0 - %d] \n", channelNumber + 1, ALTREF_MAX_NFRAMES);
2589 0 : return_error = EB_ErrorBadParameter;
2590 : }
2591 :
2592 : // palette
2593 2 : if (config->enable_palette < (int32_t)(-1) || config->enable_palette >6) {
2594 0 : SVT_LOG( "Error instance %u: Invalid Palette Mode [0 .. 6], your input: %i\n", channelNumber + 1, config->enable_palette);
2595 0 : return_error = EB_ErrorBadParameter;
2596 : }
2597 :
2598 : // RDOQ
2599 2 : if (config->enable_rdoq != (int8_t)0 && config->enable_rdoq != (int8_t)1 && config->enable_rdoq != (int8_t)-1) {
2600 0 : SVT_LOG( "Error instance %u: Invalid RDOQ parameter [-1, 0, 1], your input: %i\n", channelNumber + 1, config->enable_rdoq);
2601 0 : return_error = EB_ErrorBadParameter;
2602 : }
2603 :
2604 : // mdc refinement
2605 2 : if (config->olpd_refinement < (int32_t)(-1) || config->olpd_refinement > 1) {
2606 0 : SVT_LOG("Error instance %u: Invalid OLPD Refinement Mode [0 .. 1], your input: %i\n", channelNumber + 1, config->olpd_refinement);
2607 0 : return_error = EB_ErrorBadParameter;
2608 : }
2609 2 : else if (config->olpd_refinement == 1 && config->enc_mode >= ENC_M1) {
2610 0 : SVT_LOG("Error instance %u: Invalid OLPD Refinement mode for M%d [0], your input: %i\n", channelNumber + 1, config->enc_mode, config->olpd_refinement);
2611 0 : return_error = EB_ErrorBadParameter;
2612 : }
2613 :
2614 2 : return return_error;
2615 : }
2616 :
2617 : /**********************************
2618 : Set Default Library Params
2619 : **********************************/
2620 2 : EbErrorType eb_svt_enc_init_parameter(
2621 : EbSvtAv1EncConfiguration * config_ptr)
2622 : {
2623 2 : EbErrorType return_error = EB_ErrorNone;
2624 :
2625 2 : if (!config_ptr) {
2626 0 : SVT_LOG("The EbSvtAv1EncConfiguration structure is empty! \n");
2627 0 : return EB_ErrorBadParameter;
2628 : }
2629 :
2630 2 : config_ptr->frame_rate = 30 << 16;
2631 2 : config_ptr->frame_rate_numerator = 0;
2632 2 : config_ptr->frame_rate_denominator = 0;
2633 2 : config_ptr->encoder_bit_depth = 8;
2634 2 : config_ptr->ten_bit_format = 0;
2635 2 : config_ptr->compressed_ten_bit_format = 0;
2636 2 : config_ptr->source_width = 0;
2637 2 : config_ptr->source_height = 0;
2638 2 : config_ptr->frames_to_be_encoded = 0;
2639 2 : config_ptr->stat_report = 0;
2640 2 : config_ptr->tile_rows = 0;
2641 2 : config_ptr->tile_columns = 0;
2642 :
2643 2 : config_ptr->qp = 50;
2644 2 : config_ptr->use_qp_file = EB_FALSE;
2645 2 : config_ptr->scene_change_detection = 0;
2646 2 : config_ptr->rate_control_mode = 0;
2647 2 : config_ptr->look_ahead_distance = (uint32_t)~0;
2648 2 : config_ptr->target_bit_rate = 7000000;
2649 2 : config_ptr->max_qp_allowed = 63;
2650 2 : config_ptr->min_qp_allowed = 10;
2651 2 : config_ptr->base_layer_switch_mode = 0;
2652 2 : config_ptr->enc_mode = MAX_ENC_PRESET;
2653 : #if TWO_PASS_USE_2NDP_ME_IN_1STP
2654 2 : config_ptr->snd_pass_enc_mode = MAX_ENC_PRESET + 1;
2655 : #endif
2656 2 : config_ptr->intra_period_length = -2;
2657 2 : config_ptr->intra_refresh_type = 1;
2658 2 : config_ptr->hierarchical_levels = 4;
2659 2 : config_ptr->pred_structure = EB_PRED_RANDOM_ACCESS;
2660 2 : config_ptr->disable_dlf_flag = EB_FALSE;
2661 2 : config_ptr->enable_warped_motion = EB_TRUE;
2662 2 : config_ptr->enable_global_motion = EB_TRUE;
2663 2 : config_ptr->enable_obmc = EB_TRUE;
2664 2 : config_ptr->enable_rdoq = AUTO_MODE;
2665 2 : config_ptr->enable_filter_intra = EB_TRUE;
2666 2 : config_ptr->in_loop_me_flag = EB_TRUE;
2667 2 : config_ptr->ext_block_flag = EB_FALSE;
2668 2 : config_ptr->use_default_me_hme = EB_TRUE;
2669 2 : config_ptr->enable_hme_flag = EB_TRUE;
2670 2 : config_ptr->enable_hme_level0_flag = EB_TRUE;
2671 2 : config_ptr->enable_hme_level1_flag = EB_FALSE;
2672 2 : config_ptr->enable_hme_level2_flag = EB_FALSE;
2673 2 : config_ptr->search_area_width = 16;
2674 2 : config_ptr->search_area_height = 7;
2675 2 : config_ptr->number_hme_search_region_in_width = 2;
2676 2 : config_ptr->number_hme_search_region_in_height = 2;
2677 2 : config_ptr->hme_level0_total_search_area_width = 64;
2678 2 : config_ptr->hme_level0_total_search_area_height = 25;
2679 2 : config_ptr->hme_level0_search_area_in_width_array[0] = 32;
2680 2 : config_ptr->hme_level0_search_area_in_width_array[1] = 32;
2681 2 : config_ptr->hme_level0_search_area_in_height_array[0] = 12;
2682 2 : config_ptr->hme_level0_search_area_in_height_array[1] = 13;
2683 2 : config_ptr->hme_level1_search_area_in_width_array[0] = 1;
2684 2 : config_ptr->hme_level1_search_area_in_width_array[1] = 1;
2685 2 : config_ptr->hme_level1_search_area_in_height_array[0] = 1;
2686 2 : config_ptr->hme_level1_search_area_in_height_array[1] = 1;
2687 2 : config_ptr->hme_level2_search_area_in_width_array[0] = 1;
2688 2 : config_ptr->hme_level2_search_area_in_width_array[1] = 1;
2689 2 : config_ptr->hme_level2_search_area_in_height_array[0] = 1;
2690 2 : config_ptr->hme_level2_search_area_in_height_array[1] = 1;
2691 2 : config_ptr->enable_hbd_mode_decision = 1;
2692 2 : config_ptr->constrained_intra = EB_FALSE;
2693 2 : config_ptr->enable_palette = -1;
2694 2 : config_ptr->olpd_refinement = -1;
2695 : // Bitstream options
2696 : //config_ptr->codeVpsSpsPps = 0;
2697 : //config_ptr->codeEosNal = 0;
2698 2 : config_ptr->unrestricted_motion_vector = EB_TRUE;
2699 :
2700 2 : config_ptr->high_dynamic_range_input = 0;
2701 2 : config_ptr->screen_content_mode = 2;
2702 :
2703 : // Annex A parameters
2704 2 : config_ptr->profile = 0;
2705 2 : config_ptr->tier = 0;
2706 2 : config_ptr->level = 0;
2707 :
2708 : // Latency
2709 2 : config_ptr->injector_frame_rate = 60 << 16;
2710 2 : config_ptr->speed_control_flag = 0;
2711 2 : config_ptr->super_block_size = 128;
2712 :
2713 2 : config_ptr->sb_sz = 64;
2714 2 : config_ptr->partition_depth = (uint8_t)EB_MAX_LCU_DEPTH;
2715 : //config_ptr->latency_mode = 0;
2716 2 : config_ptr->speed_control_flag = 0;
2717 2 : config_ptr->film_grain_denoise_strength = 0;
2718 :
2719 : // ASM Type
2720 2 : config_ptr->asm_type = 1;
2721 :
2722 : // Channel info
2723 2 : config_ptr->logical_processors = 0;
2724 2 : config_ptr->target_socket = -1;
2725 2 : config_ptr->channel_id = 0;
2726 2 : config_ptr->active_channel_count = 1;
2727 :
2728 : // Debug info
2729 2 : config_ptr->recon_enabled = 0;
2730 :
2731 : // Alt-Ref default values
2732 2 : config_ptr->enable_altrefs = EB_TRUE;
2733 2 : config_ptr->altref_nframes = 7;
2734 2 : config_ptr->altref_strength = 5;
2735 2 : config_ptr->enable_overlays = EB_FALSE;
2736 :
2737 2 : config_ptr->sq_weight = 100;
2738 :
2739 2 : config_ptr->md_stage_1_cand_prune_th = 75;
2740 2 : config_ptr->md_stage_1_class_prune_th = 100;
2741 2 : config_ptr->md_stage_2_cand_prune_th = 15;
2742 2 : config_ptr->md_stage_2_class_prune_th = 25;
2743 :
2744 2 : return return_error;
2745 : }
2746 : //#define DEBUG_BUFFERS
2747 2 : static void print_lib_params(
2748 : SequenceControlSet* scs) {
2749 2 : EbSvtAv1EncConfiguration* config = &scs->static_config;
2750 :
2751 2 : SVT_LOG("------------------------------------------- ");
2752 2 : if (config->profile == MAIN_PROFILE)
2753 2 : SVT_LOG("\nSVT [config]: Main Profile\t");
2754 0 : else if (config->profile == HIGH_PROFILE)
2755 0 : SVT_LOG("\nSVT [config]: High Profile\t");
2756 0 : else if (config->profile == PROFESSIONAL_PROFILE)
2757 0 : SVT_LOG("\nSVT [config]: Professional Profile\t");
2758 : else
2759 0 : SVT_LOG("\nSVT [config]: Unknown Profile\t");
2760 :
2761 2 : if (config->tier != 0 && config->level != 0)
2762 0 : SVT_LOG("Tier %d\tLevel %.1f\t", config->tier, (float)(config->level / 10));
2763 : else {
2764 2 : if (config->tier == 0)
2765 2 : SVT_LOG("Tier (auto)\t");
2766 : else
2767 0 : SVT_LOG("Tier %d\t", config->tier);
2768 :
2769 2 : if (config->level == 0)
2770 2 : SVT_LOG("Level (auto)\t");
2771 : else
2772 0 : SVT_LOG("Level %.1f\t", (float)(config->level / 10));
2773 : }
2774 2 : SVT_LOG("\nSVT [config]: EncoderMode \t\t\t\t\t\t\t: %d ", config->enc_mode);
2775 2 : SVT_LOG("\nSVT [config]: EncoderBitDepth / EncoderColorFormat / CompressedTenBitFormat\t: %d / %d / %d", config->encoder_bit_depth, config->encoder_color_format, config->compressed_ten_bit_format);
2776 2 : SVT_LOG("\nSVT [config]: SourceWidth / SourceHeight\t\t\t\t\t: %d / %d ", config->source_width, config->source_height);
2777 2 : if (config->frame_rate_denominator != 0 && config->frame_rate_numerator != 0)
2778 2 : SVT_LOG("\nSVT [config]: Fps_Numerator / Fps_Denominator / Gop Size / IntraRefreshType \t: %d / %d / %d / %d", config->frame_rate_numerator > (1 << 16) ? config->frame_rate_numerator >> 16 : config->frame_rate_numerator,
2779 0 : config->frame_rate_denominator > (1 << 16) ? config->frame_rate_denominator >> 16 : config->frame_rate_denominator,
2780 2 : config->intra_period_length + 1,
2781 : config->intra_refresh_type);
2782 : else
2783 0 : SVT_LOG("\nSVT [config]: FrameRate / Gop Size\t\t\t\t\t\t: %d / %d ", config->frame_rate > 1000 ? config->frame_rate >> 16 : config->frame_rate, config->intra_period_length + 1);
2784 2 : SVT_LOG("\nSVT [config]: HierarchicalLevels / BaseLayerSwitchMode / PredStructure\t\t: %d / %d / %d ", config->hierarchical_levels, config->base_layer_switch_mode, config->pred_structure);
2785 2 : if (config->rate_control_mode == 1)
2786 0 : SVT_LOG("\nSVT [config]: RCMode / TargetBitrate / LookaheadDistance / SceneChange\t\t: ABR / %d / %d / %d ", config->target_bit_rate, config->look_ahead_distance, config->scene_change_detection);
2787 2 : else if (config->rate_control_mode == 2)
2788 0 : SVT_LOG("\nSVT [config]: RCMode / TargetBitrate / LookaheadDistance / SceneChange\t\t: VBR / %d / %d / %d ", config->target_bit_rate, config->look_ahead_distance, config->scene_change_detection);
2789 2 : else if (config->rate_control_mode == 3)
2790 0 : SVT_LOG("\nSVT [config]: RCMode / TargetBitrate / LookaheadDistance / SceneChange\t\t: Constraint VBR / %d / %d / %d ", config->target_bit_rate, config->look_ahead_distance, config->scene_change_detection);
2791 : else
2792 2 : SVT_LOG("\nSVT [config]: BRC Mode / QP / LookaheadDistance / SceneChange\t\t\t: CQP / %d / %d / %d ", scs->qp, config->look_ahead_distance, config->scene_change_detection);
2793 : #ifdef DEBUG_BUFFERS
2794 : SVT_LOG("\nSVT [config]: INPUT / OUTPUT \t\t\t\t\t\t\t: %d / %d", scs->input_buffer_fifo_init_count, scs->output_stream_buffer_fifo_init_count);
2795 : SVT_LOG("\nSVT [config]: CPCS / PAREF / REF \t\t\t\t\t\t: %d / %d / %d", scs->picture_control_set_pool_init_count_child, scs->pa_reference_picture_buffer_init_count, scs->reference_picture_buffer_init_count);
2796 : SVT_LOG("\nSVT [config]: ME_SEG_W0 / ME_SEG_W1 / ME_SEG_W2 / ME_SEG_W3 \t\t\t: %d / %d / %d / %d ",
2797 : scs->me_segment_column_count_array[0],
2798 : scs->me_segment_column_count_array[1],
2799 : scs->me_segment_column_count_array[2],
2800 : scs->me_segment_column_count_array[3]);
2801 : SVT_LOG("\nSVT [config]: ME_SEG_H0 / ME_SEG_H1 / ME_SEG_H2 / ME_SEG_H3 \t\t\t: %d / %d / %d / %d ",
2802 : scs->me_segment_row_count_array[0],
2803 : scs->me_segment_row_count_array[1],
2804 : scs->me_segment_row_count_array[2],
2805 : scs->me_segment_row_count_array[3]);
2806 : SVT_LOG("\nSVT [config]: ME_SEG_W0 / ME_SEG_W1 / ME_SEG_W2 / ME_SEG_W3 \t\t\t: %d / %d / %d / %d ",
2807 : scs->enc_dec_segment_col_count_array[0],
2808 : scs->enc_dec_segment_col_count_array[1],
2809 : scs->enc_dec_segment_col_count_array[2],
2810 : scs->enc_dec_segment_col_count_array[3]);
2811 : SVT_LOG("\nSVT [config]: ME_SEG_H0 / ME_SEG_H1 / ME_SEG_H2 / ME_SEG_H3 \t\t\t: %d / %d / %d / %d ",
2812 : scs->enc_dec_segment_row_count_array[0],
2813 : scs->enc_dec_segment_row_count_array[1],
2814 : scs->enc_dec_segment_row_count_array[2],
2815 : scs->enc_dec_segment_row_count_array[3]);
2816 : SVT_LOG("\nSVT [config]: PA_P / ME_P / SBO_P / MDC_P / ED_P / EC_P \t\t\t: %d / %d / %d / %d / %d / %d ",
2817 : scs->picture_analysis_process_init_count,
2818 : scs->motion_estimation_process_init_count,
2819 : scs->source_based_operations_process_init_count,
2820 : scs->mode_decision_configuration_process_init_count,
2821 : scs->enc_dec_process_init_count,
2822 : scs->entropy_coding_process_init_count);
2823 : SVT_LOG("\nSVT [config]: DLF_P / CDEF_P / REST_P \t\t\t\t\t\t: %d / %d / %d",
2824 : scs->dlf_process_init_count,
2825 : scs->cdef_process_init_count,
2826 : scs->rest_process_init_count);
2827 : #endif
2828 2 : SVT_LOG("\n------------------------------------------- ");
2829 2 : SVT_LOG("\n");
2830 :
2831 2 : fflush(stdout);
2832 2 : }
2833 : /**********************************
2834 :
2835 : * Set Parameter
2836 : **********************************/
2837 : #ifdef __GNUC__
2838 : __attribute__((visibility("default")))
2839 : #endif
2840 2 : EB_API EbErrorType eb_svt_enc_set_parameter(
2841 : EbComponentType *svt_enc_component,
2842 : EbSvtAv1EncConfiguration *pComponentParameterStructure)
2843 : {
2844 2 : if(svt_enc_component == NULL)
2845 0 : return EB_ErrorBadParameter;
2846 :
2847 2 : EbErrorType return_error = EB_ErrorNone;
2848 2 : EbEncHandle *pEncCompData = (EbEncHandle*)svt_enc_component->p_component_private;
2849 2 : uint32_t instance_index = 0;
2850 :
2851 : // Acquire Config Mutex
2852 2 : eb_block_on_mutex(pEncCompData->sequence_control_set_instance_array[instance_index]->config_mutex);
2853 :
2854 2 : SetDefaultConfigurationParameters(
2855 2 : pEncCompData->sequence_control_set_instance_array[instance_index]->sequence_control_set_ptr);
2856 :
2857 2 : CopyApiFromApp(
2858 2 : pEncCompData->sequence_control_set_instance_array[instance_index]->sequence_control_set_ptr,
2859 : (EbSvtAv1EncConfiguration*)pComponentParameterStructure);
2860 :
2861 2 : return_error = (EbErrorType)VerifySettings(
2862 2 : pEncCompData->sequence_control_set_instance_array[instance_index]->sequence_control_set_ptr);
2863 :
2864 2 : if (return_error == EB_ErrorBadParameter)
2865 0 : return EB_ErrorBadParameter;
2866 2 : SetParamBasedOnInput(
2867 2 : pEncCompData->sequence_control_set_instance_array[instance_index]->sequence_control_set_ptr);
2868 :
2869 : // Initialize the Prediction Structure Group
2870 2 : EB_NO_THROW_NEW(
2871 : pEncCompData->sequence_control_set_instance_array[instance_index]->encode_context_ptr->prediction_structure_group_ptr,
2872 : prediction_structure_group_ctor,
2873 : pEncCompData->sequence_control_set_instance_array[instance_index]->sequence_control_set_ptr->static_config.enc_mode,
2874 : pEncCompData->sequence_control_set_instance_array[instance_index]->sequence_control_set_ptr->static_config.base_layer_switch_mode);
2875 2 : if (!pEncCompData->sequence_control_set_instance_array[instance_index]->encode_context_ptr->prediction_structure_group_ptr) {
2876 0 : eb_release_mutex(pEncCompData->sequence_control_set_instance_array[instance_index]->config_mutex);
2877 0 : return EB_ErrorInsufficientResources;
2878 : }
2879 : // Set the Prediction Structure
2880 4 : pEncCompData->sequence_control_set_instance_array[instance_index]->sequence_control_set_ptr->pred_struct_ptr = get_prediction_structure(
2881 2 : pEncCompData->sequence_control_set_instance_array[instance_index]->encode_context_ptr->prediction_structure_group_ptr,
2882 2 : pEncCompData->sequence_control_set_instance_array[instance_index]->sequence_control_set_ptr->static_config.pred_structure,
2883 2 : pEncCompData->sequence_control_set_instance_array[instance_index]->sequence_control_set_ptr->max_ref_count,
2884 2 : pEncCompData->sequence_control_set_instance_array[instance_index]->sequence_control_set_ptr->max_temporal_layers);
2885 :
2886 2 : return_error = load_default_buffer_configuration_settings(
2887 2 : pEncCompData->sequence_control_set_instance_array[instance_index]->sequence_control_set_ptr);
2888 :
2889 2 : print_lib_params(
2890 2 : pEncCompData->sequence_control_set_instance_array[instance_index]->sequence_control_set_ptr);
2891 :
2892 : // Release Config Mutex
2893 2 : eb_release_mutex(pEncCompData->sequence_control_set_instance_array[instance_index]->config_mutex);
2894 :
2895 2 : return return_error;
2896 : }
2897 : #ifdef __GNUC__
2898 : __attribute__((visibility("default")))
2899 : #endif
2900 0 : EB_API EbErrorType eb_svt_enc_stream_header(
2901 : EbComponentType *svt_enc_component,
2902 : EbBufferHeaderType **output_stream_ptr)
2903 : {
2904 0 : EbErrorType return_error = EB_ErrorNone;
2905 0 : EbEncHandle *pEncCompData = (EbEncHandle*)svt_enc_component->p_component_private;
2906 0 : SequenceControlSet *sequenceControlSetPtr = pEncCompData->sequence_control_set_instance_array[0]->sequence_control_set_ptr;
2907 : Bitstream bitstream;
2908 : OutputBitstreamUnit output_bitstream;
2909 : EbBufferHeaderType *outputStreamBuffer;
2910 :
2911 0 : memset(&bitstream, 0, sizeof(Bitstream));
2912 0 : memset(&output_bitstream, 0, sizeof(OutputBitstreamUnit));
2913 0 : bitstream.output_bitstream_ptr = &output_bitstream;
2914 :
2915 0 : outputStreamBuffer = (EbBufferHeaderType *)malloc(sizeof(EbBufferHeaderType));
2916 0 : if (!outputStreamBuffer) {
2917 0 : return EB_ErrorInsufficientResources;
2918 : }
2919 :
2920 0 : outputStreamBuffer->p_buffer = (uint8_t *)malloc(sizeof(uint8_t) * PACKETIZATION_PROCESS_BUFFER_SIZE);
2921 0 : if (!outputStreamBuffer->p_buffer) {
2922 0 : free(outputStreamBuffer);
2923 0 : return EB_ErrorInsufficientResources;
2924 : }
2925 :
2926 0 : outputStreamBuffer->size = sizeof(EbBufferHeaderType);
2927 0 : outputStreamBuffer->n_alloc_len = PACKETIZATION_PROCESS_BUFFER_SIZE;
2928 0 : outputStreamBuffer->p_app_private = NULL;
2929 0 : outputStreamBuffer->pic_type = EB_AV1_INVALID_PICTURE;
2930 0 : outputStreamBuffer->n_filled_len = 0;
2931 :
2932 0 : ((OutputBitstreamUnit *)bitstream.output_bitstream_ptr)->buffer_begin_av1 = outputStreamBuffer->p_buffer;
2933 :
2934 0 : output_bitstream_reset(bitstream.output_bitstream_ptr);
2935 :
2936 : // Code the SPS
2937 0 : encode_sps_av1(&bitstream, sequenceControlSetPtr);
2938 :
2939 0 : outputStreamBuffer->n_filled_len = (uint32_t)(((OutputBitstreamUnit *)bitstream.output_bitstream_ptr)->buffer_av1 - ((OutputBitstreamUnit *)bitstream.output_bitstream_ptr)->buffer_begin_av1);
2940 :
2941 0 : *output_stream_ptr = outputStreamBuffer;
2942 :
2943 0 : return return_error;
2944 : }
2945 : #ifdef __GNUC__
2946 : __attribute__((visibility("default")))
2947 : #endif
2948 0 : EB_API EbErrorType eb_svt_release_enc_stream_header(
2949 : EbBufferHeaderType *stream_header_ptr)
2950 : {
2951 0 : EbErrorType return_error = EB_ErrorNone;
2952 :
2953 0 : if (!stream_header_ptr || !(stream_header_ptr->p_buffer)) {
2954 0 : return EB_ErrorBadParameter;
2955 : }
2956 :
2957 0 : free(stream_header_ptr->p_buffer);
2958 0 : free(stream_header_ptr);
2959 :
2960 0 : return return_error;
2961 : }
2962 : //
2963 : #ifdef __GNUC__
2964 : __attribute__((visibility("default")))
2965 : #endif
2966 0 : EB_API EbErrorType eb_svt_enc_eos_nal(
2967 : EbComponentType *svt_enc_component,
2968 : EbBufferHeaderType **output_stream_ptr
2969 : )
2970 : {
2971 0 : EbErrorType return_error = EB_ErrorNone;
2972 : UNUSED(svt_enc_component);
2973 : UNUSED(output_stream_ptr);
2974 0 : return return_error;
2975 : }
2976 :
2977 : /***********************************************
2978 : **** Copy the input buffer from the
2979 : **** sample application to the library buffers
2980 : ************************************************/
2981 120 : static EbErrorType CopyFrameBuffer(
2982 : SequenceControlSet *sequence_control_set_ptr,
2983 : uint8_t *dst,
2984 : uint8_t *src)
2985 : {
2986 120 : EbSvtAv1EncConfiguration *config = &sequence_control_set_ptr->static_config;
2987 120 : EbErrorType return_error = EB_ErrorNone;
2988 :
2989 120 : EbPictureBufferDesc *input_picture_ptr = (EbPictureBufferDesc*)dst;
2990 120 : EbSvtIOFormat *inputPtr = (EbSvtIOFormat*)src;
2991 : uint16_t inputRowIndex;
2992 120 : EbBool is16BitInput = (EbBool)(config->encoder_bit_depth > EB_8BIT);
2993 :
2994 : // Need to include for Interlacing on the fly with pictureScanType = 1
2995 :
2996 120 : if (!is16BitInput) {
2997 120 : uint32_t lumaBufferOffset = (input_picture_ptr->stride_y*sequence_control_set_ptr->top_padding + sequence_control_set_ptr->left_padding) << is16BitInput;
2998 120 : uint32_t chromaBufferOffset = (input_picture_ptr->stride_cr*(sequence_control_set_ptr->top_padding >> 1) + (sequence_control_set_ptr->left_padding >> 1)) << is16BitInput;
2999 120 : uint16_t lumaStride = input_picture_ptr->stride_y << is16BitInput;
3000 120 : uint16_t chromaStride = input_picture_ptr->stride_cb << is16BitInput;
3001 120 : uint16_t lumaWidth = (uint16_t)(input_picture_ptr->width - sequence_control_set_ptr->max_input_pad_right) << is16BitInput;
3002 120 : uint16_t chromaWidth = (lumaWidth >> 1) << is16BitInput;
3003 120 : uint16_t lumaHeight = (uint16_t)(input_picture_ptr->height - sequence_control_set_ptr->max_input_pad_bottom);
3004 :
3005 120 : uint16_t sourceLumaStride = (uint16_t)(inputPtr->y_stride);
3006 120 : uint16_t sourceCrStride = (uint16_t)(inputPtr->cr_stride);
3007 120 : uint16_t sourceCbStride = (uint16_t)(inputPtr->cb_stride);
3008 :
3009 : //uint16_t lumaHeight = input_picture_ptr->max_height;
3010 : // Y
3011 43320 : for (inputRowIndex = 0; inputRowIndex < lumaHeight; inputRowIndex++) {
3012 43200 : EB_MEMCPY((input_picture_ptr->buffer_y + lumaBufferOffset + lumaStride * inputRowIndex),
3013 : (inputPtr->luma + sourceLumaStride * inputRowIndex),
3014 : lumaWidth);
3015 : }
3016 :
3017 : // U
3018 21720 : for (inputRowIndex = 0; inputRowIndex < lumaHeight >> 1; inputRowIndex++) {
3019 21600 : EB_MEMCPY((input_picture_ptr->buffer_cb + chromaBufferOffset + chromaStride * inputRowIndex),
3020 : (inputPtr->cb + (sourceCbStride*inputRowIndex)),
3021 : chromaWidth);
3022 : }
3023 :
3024 : // V
3025 21720 : for (inputRowIndex = 0; inputRowIndex < lumaHeight >> 1; inputRowIndex++) {
3026 21600 : EB_MEMCPY((input_picture_ptr->buffer_cr + chromaBufferOffset + chromaStride * inputRowIndex),
3027 : (inputPtr->cr + (sourceCrStride*inputRowIndex)),
3028 : chromaWidth);
3029 : }
3030 : }
3031 0 : else if (is16BitInput && config->compressed_ten_bit_format == 1)
3032 : {
3033 0 : {
3034 0 : uint32_t lumaBufferOffset = (input_picture_ptr->stride_y*sequence_control_set_ptr->top_padding + sequence_control_set_ptr->left_padding);
3035 0 : uint32_t chromaBufferOffset = (input_picture_ptr->stride_cr*(sequence_control_set_ptr->top_padding >> 1) + (sequence_control_set_ptr->left_padding >> 1));
3036 0 : uint16_t lumaStride = input_picture_ptr->stride_y;
3037 0 : uint16_t chromaStride = input_picture_ptr->stride_cb;
3038 0 : uint16_t lumaWidth = (uint16_t)(input_picture_ptr->width - sequence_control_set_ptr->max_input_pad_right);
3039 0 : uint16_t chromaWidth = (lumaWidth >> 1);
3040 0 : uint16_t lumaHeight = (uint16_t)(input_picture_ptr->height - sequence_control_set_ptr->max_input_pad_bottom);
3041 :
3042 0 : uint16_t sourceLumaStride = (uint16_t)(inputPtr->y_stride);
3043 0 : uint16_t sourceCrStride = (uint16_t)(inputPtr->cr_stride);
3044 0 : uint16_t sourceCbStride = (uint16_t)(inputPtr->cb_stride);
3045 :
3046 : // Y 8bit
3047 0 : for (inputRowIndex = 0; inputRowIndex < lumaHeight; inputRowIndex++) {
3048 0 : EB_MEMCPY((input_picture_ptr->buffer_y + lumaBufferOffset + lumaStride * inputRowIndex),
3049 : (inputPtr->luma + sourceLumaStride * inputRowIndex),
3050 : lumaWidth);
3051 : }
3052 :
3053 : // U 8bit
3054 0 : for (inputRowIndex = 0; inputRowIndex < lumaHeight >> 1; inputRowIndex++) {
3055 0 : EB_MEMCPY((input_picture_ptr->buffer_cb + chromaBufferOffset + chromaStride * inputRowIndex),
3056 : (inputPtr->cb + (sourceCbStride*inputRowIndex)),
3057 : chromaWidth);
3058 : }
3059 :
3060 : // V 8bit
3061 0 : for (inputRowIndex = 0; inputRowIndex < lumaHeight >> 1; inputRowIndex++) {
3062 0 : EB_MEMCPY((input_picture_ptr->buffer_cr + chromaBufferOffset + chromaStride * inputRowIndex),
3063 : (inputPtr->cr + (sourceCrStride*inputRowIndex)),
3064 : chromaWidth);
3065 : }
3066 :
3067 : //efficient copy - final
3068 : //compressed 2Bit in 1D format
3069 : {
3070 0 : uint16_t luma2BitWidth = sequence_control_set_ptr->max_input_luma_width / 4;
3071 0 : uint16_t lumaHeight = sequence_control_set_ptr->max_input_luma_height;
3072 :
3073 0 : uint16_t sourceLuma2BitStride = sourceLumaStride / 4;
3074 0 : uint16_t sourceChroma2BitStride = sourceLuma2BitStride >> 1;
3075 :
3076 0 : for (inputRowIndex = 0; inputRowIndex < lumaHeight; inputRowIndex++) {
3077 0 : EB_MEMCPY(input_picture_ptr->buffer_bit_inc_y + luma2BitWidth * inputRowIndex, inputPtr->luma_ext + sourceLuma2BitStride * inputRowIndex, luma2BitWidth);
3078 : }
3079 0 : for (inputRowIndex = 0; inputRowIndex < lumaHeight >> 1; inputRowIndex++) {
3080 0 : EB_MEMCPY(input_picture_ptr->buffer_bit_inc_cb + (luma2BitWidth >> 1)*inputRowIndex, inputPtr->cb_ext + sourceChroma2BitStride * inputRowIndex, luma2BitWidth >> 1);
3081 : }
3082 0 : for (inputRowIndex = 0; inputRowIndex < lumaHeight >> 1; inputRowIndex++) {
3083 0 : EB_MEMCPY(input_picture_ptr->buffer_bit_inc_cr + (luma2BitWidth >> 1)*inputRowIndex, inputPtr->cr_ext + sourceChroma2BitStride * inputRowIndex, luma2BitWidth >> 1);
3084 : }
3085 : }
3086 : }
3087 : }
3088 : else { // 10bit packed
3089 :
3090 0 : uint32_t lumaOffset = 0, chromaOffset = 0;
3091 0 : uint32_t lumaBufferOffset = (input_picture_ptr->stride_y*sequence_control_set_ptr->top_padding + sequence_control_set_ptr->left_padding);
3092 0 : uint32_t chromaBufferOffset = (input_picture_ptr->stride_cr*(sequence_control_set_ptr->top_padding >> 1) + (sequence_control_set_ptr->left_padding >> 1));
3093 0 : uint16_t lumaWidth = (uint16_t)(input_picture_ptr->width - sequence_control_set_ptr->max_input_pad_right);
3094 0 : uint16_t chromaWidth = (lumaWidth >> 1);
3095 0 : uint16_t lumaHeight = (uint16_t)(input_picture_ptr->height - sequence_control_set_ptr->max_input_pad_bottom);
3096 :
3097 0 : uint16_t sourceLumaStride = (uint16_t)(inputPtr->y_stride);
3098 0 : uint16_t sourceCrStride = (uint16_t)(inputPtr->cr_stride);
3099 0 : uint16_t sourceCbStride = (uint16_t)(inputPtr->cb_stride);
3100 :
3101 0 : un_pack2d(
3102 0 : (uint16_t*)(inputPtr->luma + lumaOffset),
3103 : sourceLumaStride,
3104 0 : input_picture_ptr->buffer_y + lumaBufferOffset,
3105 0 : input_picture_ptr->stride_y,
3106 0 : input_picture_ptr->buffer_bit_inc_y + lumaBufferOffset,
3107 0 : input_picture_ptr->stride_bit_inc_y,
3108 : lumaWidth,
3109 : lumaHeight);
3110 :
3111 0 : un_pack2d(
3112 0 : (uint16_t*)(inputPtr->cb + chromaOffset),
3113 : sourceCbStride,
3114 0 : input_picture_ptr->buffer_cb + chromaBufferOffset,
3115 0 : input_picture_ptr->stride_cb,
3116 0 : input_picture_ptr->buffer_bit_inc_cb + chromaBufferOffset,
3117 0 : input_picture_ptr->stride_bit_inc_cb,
3118 : chromaWidth,
3119 : (lumaHeight >> 1));
3120 :
3121 0 : un_pack2d(
3122 0 : (uint16_t*)(inputPtr->cr + chromaOffset),
3123 : sourceCrStride,
3124 0 : input_picture_ptr->buffer_cr + chromaBufferOffset,
3125 0 : input_picture_ptr->stride_cr,
3126 0 : input_picture_ptr->buffer_bit_inc_cr + chromaBufferOffset,
3127 0 : input_picture_ptr->stride_bit_inc_cr,
3128 : chromaWidth,
3129 : (lumaHeight >> 1));
3130 : }
3131 120 : return return_error;
3132 : }
3133 122 : static void CopyInputBuffer(
3134 : SequenceControlSet* sequenceControlSet,
3135 : EbBufferHeaderType* dst,
3136 : EbBufferHeaderType* src
3137 : )
3138 : {
3139 : // Copy the higher level structure
3140 122 : dst->n_alloc_len = src->n_alloc_len;
3141 122 : dst->n_filled_len = src->n_filled_len;
3142 122 : dst->flags = src->flags;
3143 122 : dst->pts = src->pts;
3144 122 : dst->n_tick_count = src->n_tick_count;
3145 122 : dst->size = src->size;
3146 122 : dst->qp = src->qp;
3147 122 : dst->pic_type = src->pic_type;
3148 :
3149 : // Copy the picture buffer
3150 122 : if (src->p_buffer != NULL)
3151 120 : CopyFrameBuffer(sequenceControlSet, dst->p_buffer, src->p_buffer);
3152 122 : }
3153 :
3154 : /**********************************
3155 : * Empty This Buffer
3156 : **********************************/
3157 : #ifdef __GNUC__
3158 : __attribute__((visibility("default")))
3159 : #endif
3160 122 : EB_API EbErrorType eb_svt_enc_send_picture(
3161 : EbComponentType *svt_enc_component,
3162 : EbBufferHeaderType *p_buffer)
3163 : {
3164 122 : EbEncHandle *enc_handle_ptr = (EbEncHandle*)svt_enc_component->p_component_private;
3165 : EbObjectWrapper *ebWrapperPtr;
3166 :
3167 : // Take the buffer and put it into our internal queue structure
3168 122 : eb_get_empty_object(
3169 122 : enc_handle_ptr->input_buffer_producer_fifo_ptr_array[0],
3170 : &ebWrapperPtr);
3171 :
3172 122 : if (p_buffer != NULL) {
3173 122 : CopyInputBuffer(
3174 122 : enc_handle_ptr->sequence_control_set_instance_array[0]->sequence_control_set_ptr,
3175 122 : (EbBufferHeaderType*)ebWrapperPtr->object_ptr,
3176 : p_buffer);
3177 : }
3178 :
3179 122 : eb_post_full_object(ebWrapperPtr);
3180 :
3181 122 : return EB_ErrorNone;
3182 : }
3183 0 : static void CopyOutputReconBuffer(
3184 : EbBufferHeaderType *dst,
3185 : EbBufferHeaderType *src
3186 : )
3187 : {
3188 : // copy output bitstream fileds
3189 0 : dst->size = src->size;
3190 0 : dst->n_alloc_len = src->n_alloc_len;
3191 0 : dst->n_filled_len = src->n_filled_len;
3192 0 : dst->p_app_private = src->p_app_private;
3193 0 : dst->n_tick_count = src->n_tick_count;
3194 0 : dst->pts = src->pts;
3195 0 : dst->dts = src->dts;
3196 0 : dst->flags = src->flags;
3197 0 : dst->pic_type = src->pic_type;
3198 0 : if (src->p_buffer)
3199 0 : EB_MEMCPY(dst->p_buffer, src->p_buffer, src->n_filled_len);
3200 :
3201 0 : return;
3202 : }
3203 :
3204 : /**********************************
3205 : * eb_svt_get_packet sends out packet
3206 : **********************************/
3207 : #ifdef __GNUC__
3208 : __attribute__((visibility("default")))
3209 : #endif
3210 238 : EB_API EbErrorType eb_svt_get_packet(
3211 : EbComponentType *svt_enc_component,
3212 : EbBufferHeaderType **p_buffer,
3213 : unsigned char pic_send_done)
3214 : {
3215 238 : EbErrorType return_error = EB_ErrorNone;
3216 238 : EbEncHandle *pEncCompData = (EbEncHandle*)svt_enc_component->p_component_private;
3217 238 : EbObjectWrapper *ebWrapperPtr = NULL;
3218 : EbBufferHeaderType *packet;
3219 238 : if (pic_send_done)
3220 120 : eb_get_full_object(
3221 120 : (pEncCompData->output_stream_buffer_consumer_fifo_ptr_dbl_array[0])[0],
3222 : &ebWrapperPtr);
3223 : else
3224 118 : eb_get_full_object_non_blocking(
3225 118 : (pEncCompData->output_stream_buffer_consumer_fifo_ptr_dbl_array[0])[0],
3226 : &ebWrapperPtr);
3227 :
3228 238 : if (ebWrapperPtr) {
3229 120 : packet = (EbBufferHeaderType*)ebWrapperPtr->object_ptr;
3230 120 : if ( packet->flags & 0xfffffff0 )
3231 0 : return_error = EB_ErrorMax;
3232 : // return the output stream buffer
3233 120 : *p_buffer = packet;
3234 :
3235 : // save the wrapper pointer for the release
3236 120 : (*p_buffer)->wrapper_ptr = (void*)ebWrapperPtr;
3237 : }
3238 : else
3239 118 : return_error = EB_NoErrorEmptyQueue;
3240 238 : return return_error;
3241 : }
3242 :
3243 : #ifdef __GNUC__
3244 : __attribute__((visibility("default")))
3245 : #endif
3246 120 : EB_API void eb_svt_release_out_buffer(
3247 : EbBufferHeaderType **p_buffer)
3248 : {
3249 120 : if (p_buffer && (*p_buffer)->wrapper_ptr)
3250 : // Release out put buffer back into the pool
3251 120 : eb_release_object((EbObjectWrapper *)(*p_buffer)->wrapper_ptr);
3252 120 : return;
3253 : }
3254 :
3255 : /**********************************
3256 : * Fill This Buffer
3257 : **********************************/
3258 : #ifdef __GNUC__
3259 : __attribute__((visibility("default")))
3260 : #endif
3261 0 : EB_API EbErrorType eb_svt_get_recon(
3262 : EbComponentType *svt_enc_component,
3263 : EbBufferHeaderType *p_buffer)
3264 : {
3265 0 : EbErrorType return_error = EB_ErrorNone;
3266 0 : EbEncHandle *pEncCompData = (EbEncHandle*)svt_enc_component->p_component_private;
3267 0 : EbObjectWrapper *ebWrapperPtr = NULL;
3268 :
3269 0 : if (pEncCompData->sequence_control_set_instance_array[0]->sequence_control_set_ptr->static_config.recon_enabled) {
3270 0 : eb_get_full_object_non_blocking(
3271 0 : (pEncCompData->output_recon_buffer_consumer_fifo_ptr_dbl_array[0])[0],
3272 : &ebWrapperPtr);
3273 :
3274 0 : if (ebWrapperPtr) {
3275 0 : EbBufferHeaderType* objPtr = (EbBufferHeaderType*)ebWrapperPtr->object_ptr;
3276 0 : CopyOutputReconBuffer(
3277 : p_buffer,
3278 : objPtr);
3279 :
3280 0 : if (p_buffer->flags != EB_BUFFERFLAG_EOS && p_buffer->flags != 0)
3281 0 : return_error = EB_ErrorMax;
3282 0 : eb_release_object((EbObjectWrapper *)ebWrapperPtr);
3283 : }
3284 : else
3285 0 : return_error = EB_NoErrorEmptyQueue;
3286 : }
3287 : else {
3288 : // recon is not enabled
3289 0 : return_error = EB_ErrorMax;
3290 : }
3291 :
3292 0 : return return_error;
3293 : }
3294 :
3295 : /**********************************
3296 : * Encoder Error Handling
3297 : **********************************/
3298 0 : void lib_svt_encoder_send_error_exit(
3299 : EbPtr hComponent,
3300 : uint32_t error_code)
3301 : {
3302 0 : EbComponentType *svt_enc_component = (EbComponentType*)hComponent;
3303 0 : EbEncHandle *pEncCompData = (EbEncHandle*)svt_enc_component->p_component_private;
3304 0 : EbObjectWrapper *ebWrapperPtr = NULL;
3305 : EbBufferHeaderType *outputPacket;
3306 :
3307 0 : eb_get_empty_object(
3308 0 : (pEncCompData->output_stream_buffer_producer_fifo_ptr_dbl_array[0])[0],
3309 : &ebWrapperPtr);
3310 :
3311 0 : outputPacket = (EbBufferHeaderType*)ebWrapperPtr->object_ptr;
3312 :
3313 0 : outputPacket->size = 0;
3314 0 : outputPacket->flags = error_code;
3315 0 : outputPacket->p_buffer = NULL;
3316 :
3317 0 : eb_post_full_object(ebWrapperPtr);
3318 0 : }
3319 : /**********************************
3320 : * Encoder Handle Initialization
3321 : **********************************/
3322 2 : EbErrorType init_svt_av1_encoder_handle(
3323 : EbComponentType * hComponent)
3324 : {
3325 2 : EbErrorType return_error = EB_ErrorNone;
3326 2 : EbComponentType *svt_enc_component = (EbComponentType*)hComponent;
3327 : EbEncHandle *handle;
3328 :
3329 2 : printf("SVT [version]:\tSVT-AV1 Encoder Lib v%d.%d.%d\n", SVT_VERSION_MAJOR, SVT_VERSION_MINOR, SVT_VERSION_PATCHLEVEL);
3330 : #if ( defined( _MSC_VER ) && (_MSC_VER < 1910) )
3331 : printf("SVT [build] : Visual Studio 2013");
3332 : #elif ( defined( _MSC_VER ) && (_MSC_VER >= 1910) )
3333 : printf("SVT [build] :\tVisual Studio 2017");
3334 : #elif defined(__GNUC__)
3335 2 : printf("SVT [build] :\tGCC %s\t", __VERSION__);
3336 : #else
3337 : printf("SVT [build] :\tunknown compiler");
3338 : #endif
3339 2 : printf(" %u bit\n", (unsigned) sizeof(void*) * 8);
3340 2 : printf("LIB Build date: %s %s\n", __DATE__, __TIME__);
3341 2 : printf("-------------------------------------------\n");
3342 :
3343 2 : SwitchToRealTime();
3344 :
3345 : // Set Component Size & Version
3346 2 : svt_enc_component->size = sizeof(EbComponentType);
3347 :
3348 2 : EB_NEW(handle, eb_enc_handle_ctor, svt_enc_component);
3349 2 : svt_enc_component->p_component_private = handle;
3350 :
3351 2 : return return_error;
3352 : }
3353 144 : static EbErrorType allocate_frame_buffer(
3354 : SequenceControlSet *sequence_control_set_ptr,
3355 : EbBufferHeaderType *inputBuffer)
3356 : {
3357 144 : EbErrorType return_error = EB_ErrorNone;
3358 : EbPictureBufferDescInitData input_picture_buffer_desc_init_data;
3359 144 : EbSvtAv1EncConfiguration * config = &sequence_control_set_ptr->static_config;
3360 144 : uint8_t is16bit = config->encoder_bit_depth > 8 ? 1 : 0;
3361 : // Init Picture Init data
3362 144 : input_picture_buffer_desc_init_data.max_width = (uint16_t)sequence_control_set_ptr->max_input_luma_width;
3363 144 : input_picture_buffer_desc_init_data.max_height = (uint16_t)sequence_control_set_ptr->max_input_luma_height;
3364 144 : input_picture_buffer_desc_init_data.bit_depth = (EbBitDepthEnum)config->encoder_bit_depth;
3365 144 : input_picture_buffer_desc_init_data.color_format = (EbColorFormat)config->encoder_color_format;
3366 :
3367 144 : if (config->compressed_ten_bit_format == 1)
3368 0 : input_picture_buffer_desc_init_data.buffer_enable_mask = 0;
3369 : else
3370 144 : input_picture_buffer_desc_init_data.buffer_enable_mask = is16bit ? PICTURE_BUFFER_DESC_FULL_MASK : 0;
3371 144 : input_picture_buffer_desc_init_data.left_padding = sequence_control_set_ptr->left_padding;
3372 144 : input_picture_buffer_desc_init_data.right_padding = sequence_control_set_ptr->right_padding;
3373 144 : input_picture_buffer_desc_init_data.top_padding = sequence_control_set_ptr->top_padding;
3374 144 : input_picture_buffer_desc_init_data.bot_padding = sequence_control_set_ptr->bot_padding;
3375 :
3376 144 : input_picture_buffer_desc_init_data.split_mode = is16bit ? EB_TRUE : EB_FALSE;
3377 :
3378 144 : input_picture_buffer_desc_init_data.buffer_enable_mask = PICTURE_BUFFER_DESC_FULL_MASK;
3379 :
3380 144 : if (is16bit && config->compressed_ten_bit_format == 1)
3381 0 : input_picture_buffer_desc_init_data.split_mode = EB_FALSE; //do special allocation for 2bit data down below.
3382 : // Enhanced Picture Buffer
3383 : {
3384 : EbPictureBufferDesc* buf;
3385 144 : EB_NEW(
3386 : buf,
3387 : eb_picture_buffer_desc_ctor,
3388 : (EbPtr)&input_picture_buffer_desc_init_data);
3389 144 : inputBuffer->p_buffer = (uint8_t*)buf;
3390 144 : if (is16bit && config->compressed_ten_bit_format == 1) {
3391 : //pack 4 2bit pixels into 1Byte
3392 0 : EB_MALLOC_ALIGNED_ARRAY(buf->buffer_bit_inc_y, (input_picture_buffer_desc_init_data.max_width / 4)*(input_picture_buffer_desc_init_data.max_height));
3393 0 : EB_MALLOC_ALIGNED_ARRAY(buf->buffer_bit_inc_cb, (input_picture_buffer_desc_init_data.max_width / 8)*(input_picture_buffer_desc_init_data.max_height / 2));
3394 0 : EB_MALLOC_ALIGNED_ARRAY(buf->buffer_bit_inc_cr, (input_picture_buffer_desc_init_data.max_width / 8)*(input_picture_buffer_desc_init_data.max_height / 2));
3395 : }
3396 : }
3397 :
3398 144 : return return_error;
3399 : }
3400 : /**************************************
3401 : * EbBufferHeaderType Constructor
3402 : **************************************/
3403 144 : EbErrorType EbInputBufferHeaderCreator(
3404 : EbPtr *objectDblPtr,
3405 : EbPtr objectInitDataPtr)
3406 : {
3407 : EbBufferHeaderType* inputBuffer;
3408 144 : SequenceControlSet *sequence_control_set_ptr = (SequenceControlSet*)objectInitDataPtr;
3409 :
3410 144 : *objectDblPtr = NULL;
3411 144 : EB_CALLOC(inputBuffer, 1, sizeof(EbBufferHeaderType));
3412 144 : *objectDblPtr = (EbPtr)inputBuffer;
3413 : // Initialize Header
3414 144 : inputBuffer->size = sizeof(EbBufferHeaderType);
3415 :
3416 144 : allocate_frame_buffer(
3417 : sequence_control_set_ptr,
3418 : inputBuffer);
3419 :
3420 144 : inputBuffer->p_app_private = NULL;
3421 :
3422 144 : return EB_ErrorNone;
3423 : }
3424 :
3425 144 : void EbInputBufferHeaderDestoryer( EbPtr p)
3426 : {
3427 144 : EbBufferHeaderType *obj = (EbBufferHeaderType*)p;
3428 144 : EbPictureBufferDesc* buf = (EbPictureBufferDesc*)obj->p_buffer;
3429 144 : EB_FREE_ALIGNED_ARRAY(buf->buffer_bit_inc_y);
3430 144 : EB_FREE_ALIGNED_ARRAY(buf->buffer_bit_inc_cb);
3431 144 : EB_FREE_ALIGNED_ARRAY(buf->buffer_bit_inc_cr);
3432 :
3433 144 : EB_DELETE(buf);
3434 144 : EB_FREE(obj);
3435 144 : }
3436 :
3437 : /**************************************
3438 : * EbBufferHeaderType Constructor
3439 : **************************************/
3440 152 : EbErrorType EbOutputBufferHeaderCreator(
3441 : EbPtr *objectDblPtr,
3442 : EbPtr objectInitDataPtr)
3443 : {
3444 152 : EbSvtAv1EncConfiguration * config = (EbSvtAv1EncConfiguration*)objectInitDataPtr;
3445 152 : uint32_t n_stride = (uint32_t)(EB_OUTPUTSTREAMBUFFERSIZE_MACRO(config->source_width * config->source_height)); //TBC
3446 : EbBufferHeaderType* outBufPtr;
3447 :
3448 152 : *objectDblPtr = NULL;
3449 152 : EB_CALLOC(outBufPtr, 1, sizeof(EbBufferHeaderType));
3450 152 : *objectDblPtr = (EbPtr)outBufPtr;
3451 :
3452 : // Initialize Header
3453 152 : outBufPtr->size = sizeof(EbBufferHeaderType);
3454 :
3455 152 : EB_MALLOC(outBufPtr->p_buffer, n_stride);
3456 :
3457 152 : outBufPtr->n_alloc_len = n_stride;
3458 152 : outBufPtr->p_app_private = NULL;
3459 :
3460 : (void)objectInitDataPtr;
3461 :
3462 152 : return EB_ErrorNone;
3463 : }
3464 :
3465 152 : void EbOutputBufferHeaderDestoryer( EbPtr p)
3466 : {
3467 152 : EbBufferHeaderType* obj = (EbBufferHeaderType*)p;
3468 152 : EB_FREE(obj->p_buffer);
3469 152 : EB_FREE(obj);
3470 152 : }
3471 :
3472 : /**************************************
3473 : * EbBufferHeaderType Constructor
3474 : **************************************/
3475 0 : EbErrorType EbOutputReconBufferHeaderCreator(
3476 : EbPtr *objectDblPtr,
3477 : EbPtr objectInitDataPtr)
3478 : {
3479 : EbBufferHeaderType *recon_buffer;
3480 0 : SequenceControlSet *sequence_control_set_ptr = (SequenceControlSet*)objectInitDataPtr;
3481 0 : const uint32_t luma_size =
3482 0 : sequence_control_set_ptr->seq_header.max_frame_width *
3483 0 : sequence_control_set_ptr->seq_header.max_frame_height;
3484 : // both u and v
3485 0 : const uint32_t chroma_size = luma_size >> 1;
3486 0 : const uint32_t tenBit = (sequence_control_set_ptr->static_config.encoder_bit_depth > 8);
3487 0 : const uint32_t frameSize = (luma_size + chroma_size) << tenBit;
3488 :
3489 0 : *objectDblPtr = NULL;
3490 0 : EB_CALLOC(recon_buffer, 1, sizeof(EbBufferHeaderType));
3491 0 : *objectDblPtr = (EbPtr)recon_buffer;
3492 :
3493 : // Initialize Header
3494 0 : recon_buffer->size = sizeof(EbBufferHeaderType);
3495 :
3496 : // Assign the variables
3497 0 : EB_MALLOC(recon_buffer->p_buffer, frameSize);
3498 :
3499 0 : recon_buffer->n_alloc_len = frameSize;
3500 0 : recon_buffer->p_app_private = NULL;
3501 :
3502 0 : return EB_ErrorNone;
3503 : }
3504 :
3505 0 : void EbOutputReconBufferHeaderDestoryer( EbPtr p)
3506 : {
3507 0 : EbBufferHeaderType *obj = (EbBufferHeaderType*)p;
3508 0 : EB_FREE(obj->p_buffer);
3509 0 : EB_FREE(obj);
3510 0 : }
|