1 /******************************************************************************
2  *
3  * Copyright (C) 2018 The Android Open Source Project
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at:
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *****************************************************************************
18  * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19 */
20 
21 /*!
22 ******************************************************************************
23 * \file ihevce_error_checks.c
24 *
25 * \brief
26 *    This file contains all the functions which checks the validity of the
27 *    parameters passed to the encoder.
28 *
29 * \date
30 *    18/09/2012
31 *
32 * \author
33 *    Ittiam
34 *
35 * List of Functions
36 *    ihevce_get_level_index()
37 *    ihevce_hle_validate_static_params()
38 *    ihevce_validate_tile_config_params()
39 *
40 ******************************************************************************
41 */
42 
43 /*****************************************************************************/
44 /* File Includes                                                             */
45 /*****************************************************************************/
46 /* System include files */
47 #include <stdio.h>
48 #include <string.h>
49 #include <stdlib.h>
50 #include <assert.h>
51 #include <stdarg.h>
52 #include <math.h>
53 
54 /* User include files */
55 #include "ihevc_typedefs.h"
56 #include "itt_video_api.h"
57 #include "ihevce_api.h"
58 
59 #include "rc_cntrl_param.h"
60 #include "rc_frame_info_collector.h"
61 #include "rc_look_ahead_params.h"
62 
63 #include "ihevc_defs.h"
64 #include "ihevc_macros.h"
65 #include "ihevc_debug.h"
66 #include "ihevc_structs.h"
67 #include "ihevc_platform_macros.h"
68 #include "ihevc_deblk.h"
69 #include "ihevc_itrans_recon.h"
70 #include "ihevc_chroma_itrans_recon.h"
71 #include "ihevc_chroma_intra_pred.h"
72 #include "ihevc_intra_pred.h"
73 #include "ihevc_inter_pred.h"
74 #include "ihevc_mem_fns.h"
75 #include "ihevc_padding.h"
76 #include "ihevc_weighted_pred.h"
77 #include "ihevc_sao.h"
78 #include "ihevc_resi_trans.h"
79 #include "ihevc_quant_iquant_ssd.h"
80 #include "ihevc_cabac_tables.h"
81 #include "ihevc_trans_tables.h"
82 #include "ihevc_trans_macros.h"
83 
84 #include "ihevce_defs.h"
85 #include "ihevce_lap_enc_structs.h"
86 #include "ihevce_hle_interface.h"
87 #include "ihevce_multi_thrd_structs.h"
88 #include "ihevce_multi_thrd_funcs.h"
89 #include "ihevce_me_common_defs.h"
90 #include "ihevce_had_satd.h"
91 #include "ihevce_error_codes.h"
92 #include "ihevce_error_checks.h"
93 #include "ihevce_bitstream.h"
94 #include "ihevce_cabac.h"
95 #include "ihevce_rdoq_macros.h"
96 #include "ihevce_function_selector.h"
97 #include "ihevce_enc_structs.h"
98 #include "ihevce_global_tables.h"
99 #include "ihevce_trace.h"
100 
101 /*****************************************************************************/
102 /* Function Definitions                                                      */
103 /*****************************************************************************/
104 
105 /*!
106 ******************************************************************************
107 * \if Function name : ihevce_validate_tile_config_params \endif
108 *
109 * \brief
110 *    This function validates the static parameters related to tiles
111 *
112 * \param[in] Encoder static config prms pointer
113 *
114 * \return
115 *    None
116 *
117 * \author
118 *    Ittiam
119 *
120 *****************************************************************************
121 */
ihevce_validate_tile_config_params(ihevce_static_cfg_params_t * ps_static_cfg_prms)122 WORD32 ihevce_validate_tile_config_params(ihevce_static_cfg_params_t *ps_static_cfg_prms)
123 {
124     WORD32 error_code = IHEVCE_SUCCESS;
125     ihevce_sys_api_t *ps_sys_api = &ps_static_cfg_prms->s_sys_api;
126     void *pv_cb_handle = ps_sys_api->pv_cb_handle;
127 
128     /* As of now tiles are not supported */
129     if(ps_static_cfg_prms->s_app_tile_params.i4_tiles_enabled_flag != 0)
130     {
131         error_code = IHEVCE_BAD_TILE_CONFIGURATION;
132         ps_sys_api->ihevce_printf(
133             pv_cb_handle, "IHEVCE ERROR: i4_tiles_enabled_flag should be set to 0 \n");
134         return IHEVCE_SETUNSUPPORTEDINPUT(error_code);
135     }
136 
137     return error_code;
138 }
139 
140 /*!
141 ******************************************************************************
142 * \if Function name : ihevce_hle_validate_static_params \endif
143 *
144 * \brief
145 *    This function validates the static parameters before creating the encoder
146 *    instance.
147 *
148 * \param[in] Encoder context pointer
149 *
150 * \return
151 *    Error code
152 *
153 * \author
154 *    Ittiam
155 *
156 *****************************************************************************
157 */
ihevce_hle_validate_static_params(ihevce_static_cfg_params_t * ps_static_cfg_prms)158 WORD32 ihevce_hle_validate_static_params(ihevce_static_cfg_params_t *ps_static_cfg_prms)
159 {
160     WORD32 error_code;
161     WORD32 i4_resolution_id;
162     WORD32 ai4_num_bitrate_instances[IHEVCE_MAX_NUM_RESOLUTIONS] = { 1 };
163     WORD32 i4_num_resolutions;
164     ihevce_sys_api_t *ps_sys_api = &ps_static_cfg_prms->s_sys_api;
165     void *pv_cb_handle = ps_sys_api->pv_cb_handle;
166 
167     /* derive local variables */
168     i4_num_resolutions = ps_static_cfg_prms->s_tgt_lyr_prms.i4_num_res_layers;
169     for(i4_resolution_id = 0; i4_resolution_id < i4_num_resolutions; i4_resolution_id++)
170     {
171         ai4_num_bitrate_instances[i4_resolution_id] =
172             ps_static_cfg_prms->s_tgt_lyr_prms.as_tgt_params[i4_resolution_id]
173                 .i4_num_bitrate_instances;
174     }
175     // clang-format off
176     if(0 != ps_static_cfg_prms->i4_log_dump_level)
177     {
178         /* Print all the config params */
179         if((0 == ps_static_cfg_prms->i4_res_id) && (0 == ps_static_cfg_prms->i4_br_id))
180         {
181             WORD32 i4_resolution_id_loop, i4_i;
182             WORD32 i4_num_res_layers = ps_static_cfg_prms->s_tgt_lyr_prms.i4_num_res_layers;
183 
184             PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "**********************************************\n");
185             PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "*********** STATIC PARAMS CONFIG *************\n");
186             PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "**********************************************\n");
187 
188             PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "IHEVCE : ps_static_cfg_prms->s_src_prms \n");
189             PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "IHEVCE : i4_width %d                    \n", ps_static_cfg_prms->s_src_prms.i4_width);
190             PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "IHEVCE : i4_height %d                   \n", ps_static_cfg_prms->s_src_prms.i4_height);
191             PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "IHEVCE : i4_frm_rate_num %d             \n", ps_static_cfg_prms->s_src_prms.i4_frm_rate_num);
192             PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "IHEVCE : i4_frm_rate_denom %d           \n", ps_static_cfg_prms->s_src_prms.i4_frm_rate_denom);
193             PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "IHEVCE : i4_field_pic %d                \n", ps_static_cfg_prms->s_src_prms.i4_field_pic);
194             PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "IHEVCE : i4_chr_format %d               \n", ps_static_cfg_prms->s_src_prms.i4_chr_format);
195             PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "IHEVCE : i4_input_bit_depth %d          \n", ps_static_cfg_prms->s_src_prms.i4_input_bit_depth);
196             PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "IHEVCE : i4_topfield_first %d           \n\n", ps_static_cfg_prms->s_src_prms.i4_topfield_first);
197 
198             PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "IHEVCE : ps_static_cfg_prms->s_tgt_lyr_prms \n");
199             PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "IHEVCE : i4_num_res_layers %d               \n", i4_num_res_layers);
200             PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "IHEVCE : i4_multi_res_layer_reuse %d        \n", ps_static_cfg_prms->s_tgt_lyr_prms.i4_multi_res_layer_reuse);
201             PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "IHEVCE : i4_mbr_quality_setting %d          \n", ps_static_cfg_prms->s_tgt_lyr_prms.i4_mbr_quality_setting);
202 
203             PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "IHEVCE : For Each resolution,");
204             PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "\nIHEVCE : i4_target_width ");
205             for(i4_resolution_id_loop = 0; i4_resolution_id_loop < i4_num_res_layers; i4_resolution_id_loop++)
206             {
207                 PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "res_id %d %d ", i4_resolution_id_loop, ps_static_cfg_prms->s_tgt_lyr_prms.as_tgt_params[i4_resolution_id_loop].i4_width);
208             }
209 
210             PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "\nIHEVCE : i4_target_width ");
211             for(i4_resolution_id_loop = 0; i4_resolution_id_loop < i4_num_res_layers; i4_resolution_id_loop++)
212             {
213                 PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "res_id %d %d ", i4_resolution_id_loop, ps_static_cfg_prms->s_tgt_lyr_prms.as_tgt_params[i4_resolution_id_loop].i4_height);
214             }
215 
216             PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "\nIHEVCE : i4_frm_rate_scale_factor ");
217             for(i4_resolution_id_loop = 0; i4_resolution_id_loop < i4_num_res_layers; i4_resolution_id_loop++)
218             {
219                 PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "res_id %d %d ", i4_resolution_id_loop,
220                     ps_static_cfg_prms->s_tgt_lyr_prms.as_tgt_params[i4_resolution_id_loop].i4_frm_rate_scale_factor);
221             }
222 
223             PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "\nIHEVCE : i4_codec_level ");
224             for(i4_resolution_id_loop = 0; i4_resolution_id_loop < i4_num_res_layers; i4_resolution_id_loop++)
225             {
226                 PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "res_id %d %d ", i4_resolution_id_loop, ps_static_cfg_prms->s_tgt_lyr_prms.as_tgt_params[i4_resolution_id_loop].i4_codec_level);
227             }
228 
229             PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "\nIHEVCE : i4_num_bitrate_instances ");
230             for(i4_resolution_id_loop = 0; i4_resolution_id_loop < i4_num_res_layers; i4_resolution_id_loop++)
231             {
232                 PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "res_id %d %d", i4_resolution_id_loop,
233                     ps_static_cfg_prms->s_tgt_lyr_prms.as_tgt_params[i4_resolution_id_loop].i4_num_bitrate_instances);
234             }
235 
236             PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "\n");
237             for(i4_resolution_id_loop = 0; i4_resolution_id_loop < i4_num_res_layers; i4_resolution_id_loop++)
238             {
239                 WORD32 i4_num_bitrate_instances, i4_br_loop;
240                 i4_num_bitrate_instances = ps_static_cfg_prms->s_tgt_lyr_prms.as_tgt_params[i4_resolution_id_loop].i4_num_bitrate_instances;
241                 PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "IHEVCE : i4_tgt_bitrate res_id %d ", i4_resolution_id_loop);
242                 for(i4_br_loop = 0; i4_br_loop < i4_num_bitrate_instances; i4_br_loop++)
243                 {
244                     PRINTF(
245                         ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "br_id %d %d ", i4_br_loop, ps_static_cfg_prms->s_tgt_lyr_prms.as_tgt_params[i4_resolution_id_loop].ai4_tgt_bitrate[i4_br_loop]);
246                 }
247                 PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "\n");
248                 PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "IHEVCE : i4_peak_bitrate res_id %d ", i4_resolution_id_loop);
249                 for(i4_br_loop = 0; i4_br_loop < i4_num_bitrate_instances; i4_br_loop++)
250                 {
251                     PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "br_id %d %d ", i4_br_loop,
252                         ps_static_cfg_prms->s_tgt_lyr_prms.as_tgt_params[i4_resolution_id_loop].ai4_peak_bitrate[i4_br_loop]);
253                 }
254                 PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "\n");
255                 PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "IHEVCE : vbv_buffer_size res_id %d ", i4_resolution_id_loop);
256                 for(i4_br_loop = 0; i4_br_loop < i4_num_bitrate_instances; i4_br_loop++)
257                 {
258                     PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "br_id %d %d ", i4_br_loop,
259                         ps_static_cfg_prms->s_tgt_lyr_prms.as_tgt_params[i4_resolution_id_loop].ai4_max_vbv_buffer_size[i4_br_loop]);
260                 }
261                 PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "\n");
262             }
263 
264             for(i4_resolution_id_loop = 0; i4_resolution_id_loop < i4_num_res_layers; i4_resolution_id_loop++)
265             {
266                 WORD32 i4_num_bitrate_instances, i4_br_loop;
267 
268                 i4_num_bitrate_instances = ps_static_cfg_prms->s_tgt_lyr_prms.as_tgt_params[i4_resolution_id_loop].i4_num_bitrate_instances;
269                 PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "IHEVCE : i4_frame_qp res_id %d ", i4_resolution_id_loop);
270                 for(i4_br_loop = 0; i4_br_loop < i4_num_bitrate_instances; i4_br_loop++)
271                 {
272                     PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "br_id %d %d ", i4_br_loop, ps_static_cfg_prms->s_tgt_lyr_prms.as_tgt_params[i4_resolution_id_loop].ai4_frame_qp[i4_br_loop]);
273                 }
274                 PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "\n");
275             }
276 
277             PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "IHEVCE : i4_internal_bit_depth %d               \n", ps_static_cfg_prms->s_tgt_lyr_prms.i4_internal_bit_depth);
278             PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "IHEVCE : i4_enable_temporal_scalability %d               \n", ps_static_cfg_prms->s_tgt_lyr_prms.i4_enable_temporal_scalability);
279 
280             PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "IHEVCE : i4_quality_preset ");
281             for(i4_resolution_id_loop = 0; i4_resolution_id_loop < i4_num_res_layers; i4_resolution_id_loop++)
282             {
283                 PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "res_id %d %d", i4_resolution_id_loop, ps_static_cfg_prms->s_tgt_lyr_prms.as_tgt_params[i4_resolution_id_loop].i4_quality_preset);
284             }
285             PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "\n");
286 
287             PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "\nIHEVCE : ps_static_cfg_prms->s_coding_tools_prms \n");
288             PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "IHEVCE : i4_max_idr_period %d \n", ps_static_cfg_prms->s_coding_tools_prms.i4_max_closed_gop_period);
289             PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "IHEVCE : i4_min_idr_period %d \n", ps_static_cfg_prms->s_coding_tools_prms.i4_min_closed_gop_period);
290             PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "IHEVCE : i4_max_cra_period %d \n", ps_static_cfg_prms->s_coding_tools_prms.i4_max_cra_open_gop_period);
291             PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "IHEVCE : i4_i_cra_period %d \n", ps_static_cfg_prms->s_coding_tools_prms.i4_max_i_open_gop_period);
292             PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "IHEVCE : i4_max_temporal_layers %d \n", ps_static_cfg_prms->s_coding_tools_prms.i4_max_temporal_layers);
293             PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "IHEVCE : i4_max_reference_frames %d \n", ps_static_cfg_prms->s_coding_tools_prms.i4_max_reference_frames);
294             PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "IHEVCE : i4_deblocking_type %d \n", ps_static_cfg_prms->s_coding_tools_prms.i4_deblocking_type);
295             PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "IHEVCE : i4_use_default_sc_mtx %d \n", ps_static_cfg_prms->s_coding_tools_prms.i4_use_default_sc_mtx);
296             PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "IHEVCE : i4_enable_entropy_sync %d \n", ps_static_cfg_prms->s_coding_tools_prms.i4_enable_entropy_sync);
297             PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "IHEVCE : i4_cropping_mode %d \n", ps_static_cfg_prms->s_coding_tools_prms.i4_cropping_mode);
298             PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "IHEVCE : i4_vqet %d \n", ps_static_cfg_prms->s_coding_tools_prms.i4_vqet);
299 
300             switch(ps_static_cfg_prms->e_arch_type)
301             {
302             case ARCH_NA:
303                 PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "IHEVCE : archType %d \n", 0);
304                 break;
305 #ifdef ARM
306             case ARCH_ARM_NONEON:
307                 PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "IHEVCE : archType %d \n", 4);
308                 break;
309 #endif
310             default:
311                 break;
312             }
313 
314             PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "\nIHEVCE : ps_static_cfg_prms->s_config_prms \n");
315             PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "IHEVCE : i4_num_frms_to_encode %d \n", ps_static_cfg_prms->s_config_prms.i4_num_frms_to_encode);
316             PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "IHEVCE : i4_max_log2_cu_size %d \n", ps_static_cfg_prms->s_config_prms.i4_max_log2_cu_size);
317             PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "IHEVCE : i4_max_log2_cu_size %d \n", ps_static_cfg_prms->s_config_prms.i4_min_log2_cu_size);
318             PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "IHEVCE : i4_max_log2_cu_size %d \n", ps_static_cfg_prms->s_config_prms.i4_max_log2_tu_size);
319             PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "IHEVCE : i4_max_log2_cu_size %d \n", ps_static_cfg_prms->s_config_prms.i4_min_log2_cu_size);
320             PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "IHEVCE : i4_max_tr_tree_depth_I %d \n", ps_static_cfg_prms->s_config_prms.i4_max_tr_tree_depth_I);
321             PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "IHEVCE : i4_max_tr_tree_depth_nI %d \n", ps_static_cfg_prms->s_config_prms.i4_max_tr_tree_depth_nI);
322             PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "IHEVCE : i4_max_search_range_horz %d \n", ps_static_cfg_prms->s_config_prms.i4_max_search_range_horz);
323             PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "IHEVCE : i4_max_search_range_vert %d \n", ps_static_cfg_prms->s_config_prms.i4_max_search_range_vert);
324 
325             PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "\nIHEVCE : ps_static_cfg_prms->s_multi_thrd_prms \n");
326             PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "IHEVCE : i4_max_num_cores %d \n", ps_static_cfg_prms->s_multi_thrd_prms.i4_max_num_cores);
327             PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "IHEVCE : i4_use_thrd_affinity %d \n", ps_static_cfg_prms->s_multi_thrd_prms.i4_use_thrd_affinity);
328 
329             PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "\nIHEVCE : rate control params \n");
330             PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "IHEVCE : i4_rate_control_mode %d \n", ps_static_cfg_prms->s_config_prms.i4_rate_control_mode);
331             PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "IHEVCE : i4_cu_level_rc %d \n", ps_static_cfg_prms->s_config_prms.i4_cu_level_rc);
332             PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "IHEVCE : i4_pass %d \n", ps_static_cfg_prms->s_pass_prms.i4_pass);
333             PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "IHEVCE : i4_vbr_max_peak_rate_dur %d \n", ps_static_cfg_prms->s_config_prms.i4_vbr_max_peak_rate_dur);
334             PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "IHEVCE : i4_init_vbv_fullness %d \n", ps_static_cfg_prms->s_config_prms.i4_init_vbv_fullness);
335             PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "IHEVCE : i4_stuffing_enable %d \n", ps_static_cfg_prms->s_config_prms.i4_stuffing_enable);
336             PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "IHEVCE : i4_max_frame_qp %d \n", ps_static_cfg_prms->s_config_prms.i4_max_frame_qp);
337             PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "IHEVCE : i4_min_frame_qp %d \n", ps_static_cfg_prms->s_config_prms.i4_min_frame_qp);
338 
339             PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "\n");
340 
341             PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "\nIHEVCE : ps_static_cfg_prms->s_lap_prms\n");
342             PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "IHEVCE : i4_rc_look_ahead_pics %d \n", ps_static_cfg_prms->s_lap_prms.i4_rc_look_ahead_pics);
343             PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "IHEVCE : i4_enable_wts_ofsts %d \n", ps_static_cfg_prms->s_lap_prms.i4_enable_wts_ofsts);
344 
345             PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "\nIHEVCE : ps_static_cfg_prms->s_out_strm_prms\n");
346             PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "IHEVCE : i4_codec_type %d \n", ps_static_cfg_prms->s_out_strm_prms.i4_codec_type);
347             PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "IHEVCE : i4_codec_profile %d \n", ps_static_cfg_prms->s_out_strm_prms.i4_codec_profile);
348             PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "IHEVCE : i4_codec_tier %d \n", ps_static_cfg_prms->s_out_strm_prms.i4_codec_tier);
349             PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "IHEVCE : i4_aud_enable_flags %d \n", ps_static_cfg_prms->s_out_strm_prms.i4_aud_enable_flags);
350             PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "IHEVCE : i4_interop_flags %d \n", ps_static_cfg_prms->s_out_strm_prms.i4_interop_flags);
351             PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "IHEVCE : i4_sps_at_cdr_enable %d \n", ps_static_cfg_prms->s_out_strm_prms.i4_sps_at_cdr_enable);
352             PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "IHEVCE : i4_vui_enable %d \n", ps_static_cfg_prms->s_out_strm_prms.i4_vui_enable);
353             PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "IHEVCE : i4_sei_enable_flag %d \n", ps_static_cfg_prms->s_out_strm_prms.i4_sei_enable_flag);
354             PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "IHEVCE : i4_sei_payload_enable_flag %d \n", ps_static_cfg_prms->s_out_strm_prms.i4_sei_payload_enable_flag);
355             PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "IHEVCE : i4_sei_buffer_period_flags %d \n", ps_static_cfg_prms->s_out_strm_prms.i4_sei_buffer_period_flags);
356             PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "IHEVCE : i4_sei_pic_timing_flags %d \n", ps_static_cfg_prms->s_out_strm_prms.i4_sei_pic_timing_flags);
357             PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "IHEVCE : i4_sei_cll_enable %d \n", ps_static_cfg_prms->s_out_strm_prms.i4_sei_cll_enable);
358             PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "IHEVCE : u2_sei_avg_cll %d \n", ps_static_cfg_prms->s_out_strm_prms.u2_sei_avg_cll);
359             PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "IHEVCE : u2_sei_max_cll %d \n", ps_static_cfg_prms->s_out_strm_prms.u2_sei_max_cll);
360             PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "IHEVCE : i4_sei_recovery_point_flags %d \n", ps_static_cfg_prms->s_out_strm_prms.i4_sei_recovery_point_flags);
361             PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "IHEVCE : i4_sei_mastering_disp_colour_vol_flags %d \n", ps_static_cfg_prms->s_out_strm_prms.i4_sei_mastering_disp_colour_vol_flags);
362             for(i4_i = 0; i4_i < 3; i4_i++)
363                 PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "IHEVCE : u2_display_primaries_x[i4_i] %d \n", ps_static_cfg_prms->s_out_strm_prms.au2_display_primaries_x[i4_i]);
364             for(i4_i = 0; i4_i < 3; i4_i++)
365                 PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "IHEVCE : u2_display_primaries_y[i4_i] %d \n", ps_static_cfg_prms->s_out_strm_prms.au2_display_primaries_y[i4_i]);
366             PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "IHEVCE : u2_white_point_x %d \n", ps_static_cfg_prms->s_out_strm_prms.u2_white_point_x);
367             PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "IHEVCE : u2_white_point_y %d \n", ps_static_cfg_prms->s_out_strm_prms.u2_white_point_y);
368             PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "IHEVCE : u4_max_display_mastering_luminance %d \n", ps_static_cfg_prms->s_out_strm_prms.u4_max_display_mastering_luminance);
369             PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "IHEVCE : u4_min_display_mastering_luminance %d \n", ps_static_cfg_prms->s_out_strm_prms.u4_min_display_mastering_luminance);
370             PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "IHEVCE : i4_sei_hash_flags %d \n", ps_static_cfg_prms->s_out_strm_prms.i4_decoded_pic_hash_sei_flag);
371 
372             PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "\nIHEVCE : ps_static_cfg_prms->s_app_tile_params\n");
373             PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "IHEVCE : i4_tiles_enabled_flag %d \n", ps_static_cfg_prms->s_app_tile_params.i4_tiles_enabled_flag);
374             PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "IHEVCE : i4_uniform_spacing_flag %d \n", ps_static_cfg_prms->s_app_tile_params.i4_uniform_spacing_flag);
375             PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "IHEVCE : i4_num_tile_cols %d \n", ps_static_cfg_prms->s_app_tile_params.i4_num_tile_cols);
376             PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "IHEVCE : i4_num_tile_rows %d \n", ps_static_cfg_prms->s_app_tile_params.i4_num_tile_rows);
377 
378             for(i4_i = 0; i4_i < ps_static_cfg_prms->s_app_tile_params.i4_num_tile_cols; i4_i++)
379                 PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "IHEVCE : i4_column_width[i4_i] %d \n", ps_static_cfg_prms->s_app_tile_params.ai4_column_width[i4_i]);
380 
381             for(i4_i = 0; i4_i < ps_static_cfg_prms->s_app_tile_params.i4_num_tile_rows; i4_i++)
382                 PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "IHEVCE : i4_row_height[i4_i] %d \n", ps_static_cfg_prms->s_app_tile_params.ai4_row_height[i4_i]);
383 
384             PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "\nIHEVCE : ps_static_cfg_prms->s_slice_params\n");
385             PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "IHEVCE : i4_slice_segment_mode %d \n", ps_static_cfg_prms->s_slice_params.i4_slice_segment_mode);
386             PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "IHEVCE : i4_slice_segment_argument %d \n", ps_static_cfg_prms->s_slice_params.i4_slice_segment_argument);
387 
388             PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "\nIHEVCE : ps_static_cfg_prms->s_vui_sei_prms\n");
389             PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "IHEVCE : u1_aspect_ratio_info_present_flag %d \n", ps_static_cfg_prms->s_vui_sei_prms.u1_aspect_ratio_info_present_flag);
390 
391             PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "IHEVCE : u1_aspect_ratio_idc ");
392             for(i4_resolution_id_loop = 0; i4_resolution_id_loop < i4_num_res_layers; i4_resolution_id_loop++)
393             {
394                 PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "res_id %d %d ", i4_resolution_id_loop, ps_static_cfg_prms->s_vui_sei_prms.au1_aspect_ratio_idc[i4_resolution_id_loop]);
395             }
396 
397             PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "\nIHEVCE : au2_sar_width ");
398             for(i4_resolution_id_loop = 0; i4_resolution_id_loop < i4_num_res_layers; i4_resolution_id_loop++)
399             {
400                 PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "res_id %d %d ", i4_resolution_id_loop, ps_static_cfg_prms->s_vui_sei_prms.au2_sar_width[i4_resolution_id_loop]);
401             }
402             PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "\nIHEVCE : au2_sar_width ");
403             for(i4_resolution_id_loop = 0; i4_resolution_id_loop < i4_num_res_layers; i4_resolution_id_loop++)
404             {
405                 PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "res_id %d %d ", i4_resolution_id_loop, ps_static_cfg_prms->s_vui_sei_prms.au2_sar_height[i4_resolution_id_loop]);
406             }
407             PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "\nIHEVCE : u1_overscan_info_present_flag %d \n", ps_static_cfg_prms->s_vui_sei_prms.u1_overscan_info_present_flag);
408             PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "IHEVCE : u1_overscan_appropriate_flag %d \n", ps_static_cfg_prms->s_vui_sei_prms.u1_overscan_appropriate_flag);
409             PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "IHEVCE : u1_video_signal_type_present_flag %d \n", ps_static_cfg_prms->s_vui_sei_prms.u1_video_signal_type_present_flag);
410             PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "IHEVCE : u1_video_format %d \n", ps_static_cfg_prms->s_vui_sei_prms.u1_video_format);
411             PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "IHEVCE : u1_video_full_range_flag %d \n", ps_static_cfg_prms->s_vui_sei_prms.u1_video_full_range_flag);
412             PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "IHEVCE : u1_colour_description_present_flag %d \n", ps_static_cfg_prms->s_vui_sei_prms.u1_colour_description_present_flag);
413             PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "IHEVCE : u1_colour_primaries %d \n", ps_static_cfg_prms->s_vui_sei_prms.u1_colour_primaries);
414             PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "IHEVCE : u1_transfer_characteristics %d \n", ps_static_cfg_prms->s_vui_sei_prms.u1_transfer_characteristics);
415             PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "IHEVCE : u1_matrix_coefficients %d \n", ps_static_cfg_prms->s_vui_sei_prms.u1_matrix_coefficients);
416             PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "IHEVCE : u1_chroma_loc_info_present_flag %d \n", ps_static_cfg_prms->s_vui_sei_prms.u1_chroma_loc_info_present_flag);
417             PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "IHEVCE : u1_chroma_sample_loc_type_top_field %d \n", ps_static_cfg_prms->s_vui_sei_prms.u1_chroma_sample_loc_type_top_field);
418             PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "IHEVCE : u1_chroma_sample_loc_type_bottom_field %d \n", ps_static_cfg_prms->s_vui_sei_prms.u1_chroma_sample_loc_type_bottom_field);
419             PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "IHEVCE : u1_timing_info_present_flag %d \n", ps_static_cfg_prms->s_vui_sei_prms.u1_timing_info_present_flag);
420             PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "IHEVCE : u1_vui_hrd_parameters_present_flag %d \n", ps_static_cfg_prms->s_vui_sei_prms.u1_vui_hrd_parameters_present_flag);
421             PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "IHEVCE : u1_nal_hrd_parameters_present_flag %d \n", ps_static_cfg_prms->s_vui_sei_prms.u1_nal_hrd_parameters_present_flag);
422         }
423 
424         PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "\nIHEVCE : ps_static_cfg_prms \n");
425         PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "IHEVCE : i4_enable_logo %d                   \n", ps_static_cfg_prms->i4_enable_logo);
426         PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "IHEVCE : i4_log_dump_level %d                \n", ps_static_cfg_prms->i4_log_dump_level);
427         PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "IHEVCE : i4_save_recon %d                    \n", ps_static_cfg_prms->i4_save_recon);
428 
429         PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "**********************************************\n");
430     }
431     // clang-format on
432 
433     if(ps_static_cfg_prms->s_multi_thrd_prms.i4_num_proc_groups > MAX_NUMBER_PROC_GRPS)
434     {
435         error_code = IHEVCE_UNSUPPORTED_PROC_CONFIG;
436         ps_sys_api->ihevce_printf(
437             pv_cb_handle, "IHEVCE ERROR:  Number of Processor Groups not supported \n");
438         return (IHEVCE_SETUNSUPPORTEDINPUT(error_code));
439     }
440 
441     /* Error check for system-api callback functions */
442     if(NULL == ps_sys_api->ihevce_printf)
443     {
444         error_code = IHEVCE_SYSTEM_APIS_NOT_INITIALLIZED;
445         return (IHEVCE_SETUNSUPPORTEDINPUT(error_code));
446     }
447     if(NULL == ps_sys_api->s_file_io_api.ihevce_fopen)
448     {
449         error_code = IHEVCE_SYSTEM_APIS_NOT_INITIALLIZED;
450         ps_sys_api->ihevce_printf(
451             pv_cb_handle, "IHEVCE ERROR: ihevce_fopen callback function not initiallized\n");
452         return (IHEVCE_SETUNSUPPORTEDINPUT(error_code));
453     }
454     if(NULL == ps_sys_api->s_file_io_api.ihevce_fclose)
455     {
456         error_code = IHEVCE_SYSTEM_APIS_NOT_INITIALLIZED;
457         ps_sys_api->ihevce_printf(
458             pv_cb_handle, "IHEVCE ERROR: ihevce_fclose callback function not initiallized\n");
459         return (IHEVCE_SETUNSUPPORTEDINPUT(error_code));
460     }
461     if(NULL == ps_sys_api->s_file_io_api.ihevce_fflush)
462     {
463         error_code = IHEVCE_SYSTEM_APIS_NOT_INITIALLIZED;
464         ps_sys_api->ihevce_printf(
465             pv_cb_handle, "IHEVCE ERROR: ihevce_fflush callback function not initiallized\n");
466         return (IHEVCE_SETUNSUPPORTEDINPUT(error_code));
467     }
468     if(NULL == ps_sys_api->s_file_io_api.ihevce_fseek)
469     {
470         error_code = IHEVCE_SYSTEM_APIS_NOT_INITIALLIZED;
471         ps_sys_api->ihevce_printf(
472             pv_cb_handle, "IHEVCE ERROR: ihevce_fseek callback function not initiallized\n");
473         return (IHEVCE_SETUNSUPPORTEDINPUT(error_code));
474     }
475     if(NULL == ps_sys_api->s_file_io_api.ihevce_fread)
476     {
477         error_code = IHEVCE_SYSTEM_APIS_NOT_INITIALLIZED;
478         ps_sys_api->ihevce_printf(
479             pv_cb_handle, "IHEVCE ERROR: ihevce_fread callback function not initiallized\n");
480         return (IHEVCE_SETUNSUPPORTEDINPUT(error_code));
481     }
482     if(NULL == ps_sys_api->s_file_io_api.ihevce_fscanf)
483     {
484         error_code = IHEVCE_SYSTEM_APIS_NOT_INITIALLIZED;
485         ps_sys_api->ihevce_printf(
486             pv_cb_handle, "IHEVCE ERROR: ihevce_fscanf callback function not initiallized\n");
487         return (IHEVCE_SETUNSUPPORTEDINPUT(error_code));
488     }
489     if(NULL == ps_sys_api->ihevce_sscanf)
490     {
491         error_code = IHEVCE_SYSTEM_APIS_NOT_INITIALLIZED;
492         ps_sys_api->ihevce_printf(
493             pv_cb_handle, "IHEVCE ERROR: ihevce_sscanf callback function not initiallized\n");
494         return (IHEVCE_SETUNSUPPORTEDINPUT(error_code));
495     }
496     if(NULL == ps_sys_api->s_file_io_api.ihevce_fprintf)
497     {
498         error_code = IHEVCE_SYSTEM_APIS_NOT_INITIALLIZED;
499         ps_sys_api->ihevce_printf(
500             pv_cb_handle, "IHEVCE ERROR: ihevce_fprintf callback function not initiallized\n");
501         return (IHEVCE_SETUNSUPPORTEDINPUT(error_code));
502     }
503     if(NULL == ps_sys_api->s_file_io_api.ihevce_fwrite)
504     {
505         error_code = IHEVCE_SYSTEM_APIS_NOT_INITIALLIZED;
506         ps_sys_api->ihevce_printf(
507             pv_cb_handle, "IHEVCE ERROR: ihevce_fwrite callback function not initiallized\n");
508         return (IHEVCE_SETUNSUPPORTEDINPUT(error_code));
509     }
510     if(NULL == ps_sys_api->ihevce_sprintf)
511     {
512         error_code = IHEVCE_SYSTEM_APIS_NOT_INITIALLIZED;
513         ps_sys_api->ihevce_printf(
514             pv_cb_handle, "IHEVCE ERROR: ihevce_sprintf callback function not initiallized\n");
515         return (IHEVCE_SETUNSUPPORTEDINPUT(error_code));
516     }
517 
518     /* Error check for static source parameters */
519     if((ps_static_cfg_prms->s_src_prms.i4_orig_width > HEVCE_MAX_WIDTH) ||
520        (ps_static_cfg_prms->s_src_prms.i4_orig_width < 2))
521     {
522         error_code = IHEVCE_WIDTH_NOT_SUPPORTED;
523         ps_sys_api->ihevce_printf(pv_cb_handle, "IHEVCE ERROR:  i4_src_width out of range \n");
524         return (IHEVCE_SETUNSUPPORTEDINPUT(error_code));
525     }
526 
527     if((ps_static_cfg_prms->s_src_prms.i4_orig_height > HEVCE_MAX_HEIGHT) ||
528        (ps_static_cfg_prms->s_src_prms.i4_orig_height < 2))
529     {
530         error_code = IHEVCE_HEIGHT_NOT_SUPPORTED;
531         ps_sys_api->ihevce_printf(pv_cb_handle, "IHEVCE ERROR:  i4_src_height out of range \n");
532         return (IHEVCE_SETUNSUPPORTEDINPUT(error_code));
533     }
534     /*check for odd resolution*/
535     if(0 != (ps_static_cfg_prms->s_src_prms.i4_width & 1))
536     {
537         error_code = IHEVCE_WIDTH_NOT_SUPPORTED;
538         ps_sys_api->ihevce_printf(pv_cb_handle, "IHEVCE ERROR:  i4_src_width not supported \n");
539         return (IHEVCE_SETUNSUPPORTEDINPUT(error_code));
540     }
541     if(0 != (ps_static_cfg_prms->s_src_prms.i4_height & 1))
542     {
543         error_code = IHEVCE_HEIGHT_NOT_SUPPORTED;
544         ps_sys_api->ihevce_printf(pv_cb_handle, "IHEVCE ERROR:  i4_src_height not supported \n");
545         return (IHEVCE_SETUNSUPPORTEDINPUT(error_code));
546     }
547 
548     if((ps_static_cfg_prms->s_src_prms.i4_frm_rate_denom != 1000) &&
549        (ps_static_cfg_prms->s_src_prms.i4_frm_rate_denom != 1001))
550     {
551         error_code = IHEVCE_FRAME_RATE_NOT_SUPPORTED;
552         ps_sys_api->ihevce_printf(pv_cb_handle, "IHEVCE ERROR: frame rate denom not supported \n");
553         return IHEVCE_SETUNSUPPORTEDINPUT(error_code);
554     }
555 
556     if((((ps_static_cfg_prms->s_src_prms.i4_frm_rate_num * 1.0) /
557           ps_static_cfg_prms->s_src_prms.i4_frm_rate_denom) > MAX_FRAME_RATE) ||
558        (((ps_static_cfg_prms->s_src_prms.i4_frm_rate_num * 1.0) /
559           ps_static_cfg_prms->s_src_prms.i4_frm_rate_denom) < MIN_FRAME_RATE))
560     {
561         error_code = IHEVCE_FRAME_RATE_NOT_SUPPORTED;
562         ps_sys_api->ihevce_printf(
563             pv_cb_handle,
564             "IHEVCE ERROR: Frame rate (%d / %d) is out of range [%.1f - %.1f]\n",
565             ps_static_cfg_prms->s_src_prms.i4_frm_rate_num,
566             ps_static_cfg_prms->s_src_prms.i4_frm_rate_denom,
567             MIN_FRAME_RATE, MAX_FRAME_RATE);
568         return IHEVCE_SETUNSUPPORTEDINPUT(error_code);
569     }
570 
571     if(ps_static_cfg_prms->s_src_prms.i4_field_pic != 0)
572     {
573         error_code = IHEVCE_CONTENT_TYPE_NOT_SUPPORTED;
574         ps_sys_api->ihevce_printf(pv_cb_handle, "IHEVCE ERROR: Field encoding not supported \n");
575         return IHEVCE_SETUNSUPPORTEDINPUT(error_code);
576     }
577 
578     if(ps_static_cfg_prms->s_src_prms.inp_chr_format != IV_YUV_420SP_UV &&
579        ps_static_cfg_prms->s_src_prms.inp_chr_format != IV_YUV_420P)
580     {
581         error_code = IHEVCE_CHROMA_FORMAT_NOT_SUPPORTED;
582         ps_sys_api->ihevce_printf(pv_cb_handle, "IHEVCE ERROR: i4_input_chroma_format Invalid \n");
583         return IHEVCE_SETUNSUPPORTEDINPUT(error_code);
584     }
585 
586     if(ps_static_cfg_prms->s_src_prms.i4_chr_format != IV_YUV_420SP_UV)
587     {
588         error_code = IHEVCE_CHROMA_FORMAT_NOT_SUPPORTED;
589         ps_sys_api->ihevce_printf(
590             pv_cb_handle, "IHEVCE ERROR: i4_internal_chroma_format Invalid \n");
591         return IHEVCE_SETUNSUPPORTEDINPUT(error_code);
592     }
593 
594     /* Check error for interoperability flags */
595     if(ps_static_cfg_prms->s_out_strm_prms.i4_interop_flags != 0)
596     {
597         error_code = IHEVCE_INTEROPERABILITY_FLAG_SUPPORTED;
598         ps_sys_api->ihevce_printf(
599             pv_cb_handle, "IHEVCE ERROR: i4_interop_flags out of range, to be set to 0\n");
600         return (IHEVCE_SETUNSUPPORTEDINPUT(error_code));
601     }
602 
603     /* Error check for static output stream parameters  */
604     if(ps_static_cfg_prms->s_out_strm_prms.i4_codec_type != 0)
605     {
606         error_code = IHEVCE_CODEC_NOT_SUPPORTED;
607         ps_sys_api->ihevce_printf(
608             pv_cb_handle, "IHEVCE ERROR: i4_codec_type should be set to 0 \n");
609         return IHEVCE_SETUNSUPPORTEDINPUT(error_code);
610     }
611 
612     if(ps_static_cfg_prms->s_out_strm_prms.i4_codec_profile != 1)
613     {
614         error_code = IHEVCE_CODEC_PROFILE_NOT_SUPPORTED;
615         ps_sys_api->ihevce_printf(
616             pv_cb_handle, "IHEVCE ERROR: i4_codec_profile should be set to 1 \n");
617         return IHEVCE_SETUNSUPPORTEDINPUT(error_code);
618     }
619 
620     if(ps_static_cfg_prms->s_tgt_lyr_prms.i4_internal_bit_depth != 8)
621     {
622         error_code = IHEVCE_OUTPUT_BIT_DEPTH_OUT_OF_RANGE;
623         ps_sys_api->ihevce_printf(
624             pv_cb_handle,
625             "IHEVCE ERROR: (output_bit_depth = %d) not supported \n",
626             ps_static_cfg_prms->s_tgt_lyr_prms.i4_internal_bit_depth);
627         return IHEVCE_SETUNSUPPORTEDINPUT(error_code);
628     }
629 
630     if(ps_static_cfg_prms->s_src_prms.i4_input_bit_depth != 8)
631     {
632         error_code = IHEVCE_INPUT_BIT_DEPTH_OUT_OF_RANGE;
633         ps_sys_api->ihevce_printf(
634             pv_cb_handle, "IHEVCE ERROR: i4_input_bit_depth value not supported \n");
635         return IHEVCE_SETUNSUPPORTEDINPUT(error_code);
636     }
637 
638     if((ps_static_cfg_prms->s_out_strm_prms.i4_vui_enable > 1) ||
639        (ps_static_cfg_prms->s_out_strm_prms.i4_vui_enable < 0))
640     {
641         error_code = IHEVCE_VUI_ENABLE_OUT_OF_RANGE;
642         ps_sys_api->ihevce_printf(
643             pv_cb_handle, "IHEVCE ERROR: i4_vui_enable should be set to 1 or 0 \n");
644         return IHEVCE_SETUNSUPPORTEDINPUT(error_code);
645     }
646 
647     if((ps_static_cfg_prms->s_out_strm_prms.i4_sei_enable_flag > 1) ||
648        (ps_static_cfg_prms->s_out_strm_prms.i4_sei_enable_flag < 0))
649     {
650         error_code = IHEVCE_SEI_ENABLE_OUT_OF_RANGE;
651         ps_sys_api->ihevce_printf(
652             pv_cb_handle, "IHEVCE ERROR: i4_sei_enable_flags should be set to 1 or 0 \n");
653         return IHEVCE_SETUNSUPPORTEDINPUT(error_code);
654     }
655 
656     if((ps_static_cfg_prms->s_out_strm_prms.i4_sei_payload_enable_flag > 1) ||
657        (ps_static_cfg_prms->s_out_strm_prms.i4_sei_payload_enable_flag < 0))
658     {
659         error_code = IHEVCE_SEI_PAYLOAD_ENABLE_OUT_OF_RANGE;
660         ps_sys_api->ihevce_printf(
661             pv_cb_handle, "IHEVCE ERROR: i4_sei_payload_enable_flag should be set to 1 or 0 \n");
662         return IHEVCE_SETUNSUPPORTEDINPUT(error_code);
663     }
664     if((ps_static_cfg_prms->s_multi_thrd_prms.i4_max_num_cores > MAX_NUM_CORES) ||
665        (ps_static_cfg_prms->s_multi_thrd_prms.i4_max_num_cores < 1))
666     {
667         error_code = IHEVCE_INVALID_CORE_CONFIG;
668         ps_sys_api->ihevce_printf(
669             pv_cb_handle, "IHEVCE ERROR: Invalid Number of Cores configured\n");
670         return IHEVCE_SETUNSUPPORTEDINPUT(error_code);
671     }
672 
673     if((ps_static_cfg_prms->e_arch_type != ARCH_NA) &&
674        (ps_static_cfg_prms->e_arch_type != ARCH_ARM_NONEON))
675     {
676         error_code = IHEVCE_ARCHITECTURE_TYPE_UNSUPPORTED;
677         ps_sys_api->ihevce_printf(pv_cb_handle, "IHEVCE ERROR: unsupported archType \n");
678         return IHEVCE_SETUNSUPPORTEDINPUT(error_code);
679     }
680 
681     if(ps_static_cfg_prms->s_coding_tools_prms.i4_vqet != 0)
682     {
683         error_code = IHEVCE_VISUAL_QUALITY_ENHANCEMENTS_TOGGLER_VALUE_UNSUPPORTED;
684         ps_sys_api->ihevce_printf(
685             pv_cb_handle,
686             "IHEVCE ERROR: visual_quality_enhancements_toggler should be set to 0 \n");
687         return IHEVCE_SETUNSUPPORTEDINPUT(error_code);
688     }
689 
690     if(ps_static_cfg_prms->s_coding_tools_prms.i4_max_temporal_layers < 0 ||
691        ps_static_cfg_prms->s_coding_tools_prms.i4_max_temporal_layers > 3)
692     {
693         error_code = IHEVCE_TEMPORAL_LAYERS_NOT_SUPPORTED;
694         ps_sys_api->ihevce_printf(
695             pv_cb_handle, "IHEVCE ERROR: i4_max_temporal_layers out of range \n");
696         return IHEVCE_SETUNSUPPORTEDINPUT(error_code);
697     }
698 
699     if((ps_static_cfg_prms->s_coding_tools_prms.i4_max_closed_gop_period < 0) ||
700        (ps_static_cfg_prms->s_coding_tools_prms.i4_max_cra_open_gop_period < 0) ||
701        (ps_static_cfg_prms->s_coding_tools_prms.i4_max_i_open_gop_period < 0))
702     {
703         error_code = IHEVCE_INVALID_GOP_PERIOD;
704         ps_sys_api->ihevce_printf(
705             pv_cb_handle,
706             "IHEVCE ERROR: gop period is not valid for the configured temporal layers\n");
707         return IHEVCE_SETUNSUPPORTEDINPUT(error_code);
708     }
709 
710     {
711         WORD32 sub_gop_size = (1 << ps_static_cfg_prms->s_coding_tools_prms.i4_max_temporal_layers)
712                               << ps_static_cfg_prms->s_src_prms.i4_field_pic;
713         WORD32 i4_max_idr_period, i4_min_idr_period, i4_max_cra_period, i4_max_i_period;
714         WORD32 i4_max_i_distance;
715         WORD32 i4_min_i_distance = 0, i4_non_zero_idr_period = 0x7FFFFFFF,
716                i4_non_zero_cra_period = 0x7FFFFFFF, i4_non_zero_i_period = 0x7FFFFFFF;
717         i4_max_idr_period = ps_static_cfg_prms->s_coding_tools_prms.i4_max_closed_gop_period;
718         i4_min_idr_period = ps_static_cfg_prms->s_coding_tools_prms.i4_min_closed_gop_period;
719         i4_max_cra_period = ps_static_cfg_prms->s_coding_tools_prms.i4_max_cra_open_gop_period;
720         i4_max_i_period = ps_static_cfg_prms->s_coding_tools_prms.i4_max_i_open_gop_period;
721         i4_max_i_distance = MAX(MAX(i4_max_idr_period, i4_max_cra_period), i4_max_i_period);
722 
723         if(sub_gop_size > 1)
724         {
725             switch(sub_gop_size)
726             {
727             case 2:
728                 ps_static_cfg_prms->s_coding_tools_prms.i4_max_closed_gop_period =
729                     ALIGN2(i4_max_idr_period);
730 
731                 if(i4_max_idr_period > 1)
732                     ps_static_cfg_prms->s_coding_tools_prms.i4_max_closed_gop_period =
733                         ps_static_cfg_prms->s_coding_tools_prms.i4_max_closed_gop_period + 1;
734 
735                 ps_static_cfg_prms->s_coding_tools_prms.i4_max_cra_open_gop_period =
736                     ALIGN2(i4_max_cra_period);
737                 ps_static_cfg_prms->s_coding_tools_prms.i4_max_i_open_gop_period =
738                     ALIGN2(i4_max_i_period);
739                 break;
740             case 4:
741                 ps_static_cfg_prms->s_coding_tools_prms.i4_max_closed_gop_period =
742                     ALIGN4(i4_max_idr_period);
743 
744                 if(i4_max_idr_period > 1)
745                     ps_static_cfg_prms->s_coding_tools_prms.i4_max_closed_gop_period =
746                         ps_static_cfg_prms->s_coding_tools_prms.i4_max_closed_gop_period + 1;
747 
748                 ps_static_cfg_prms->s_coding_tools_prms.i4_max_cra_open_gop_period =
749                     ALIGN4(i4_max_cra_period);
750                 ps_static_cfg_prms->s_coding_tools_prms.i4_max_i_open_gop_period =
751                     ALIGN4(i4_max_i_period);
752                 break;
753             case 8:
754                 ps_static_cfg_prms->s_coding_tools_prms.i4_max_closed_gop_period =
755                     ALIGN8(i4_max_idr_period);
756 
757                 if(i4_max_idr_period > 1)
758                     ps_static_cfg_prms->s_coding_tools_prms.i4_max_closed_gop_period =
759                         ps_static_cfg_prms->s_coding_tools_prms.i4_max_closed_gop_period + 1;
760 
761                 ps_static_cfg_prms->s_coding_tools_prms.i4_max_cra_open_gop_period =
762                     ALIGN8(i4_max_cra_period);
763                 ps_static_cfg_prms->s_coding_tools_prms.i4_max_i_open_gop_period =
764                     ALIGN8(i4_max_i_period);
765                 break;
766             }
767         }
768 
769         if(0 != i4_max_idr_period)
770         {
771             i4_non_zero_idr_period = i4_max_idr_period;
772         }
773         if(0 != i4_max_cra_period)
774         {
775             i4_non_zero_cra_period = i4_max_cra_period;
776         }
777         if(0 != i4_max_i_period)
778         {
779             i4_non_zero_i_period = i4_max_i_period;
780         }
781         i4_min_i_distance =
782             MIN(MIN(i4_non_zero_idr_period, i4_non_zero_cra_period), i4_non_zero_i_period);
783         if(i4_min_i_distance < sub_gop_size && i4_min_i_distance)
784         {
785             error_code = IHEVCE_INVALID_GOP_PERIOD;
786             ps_sys_api->ihevce_printf(
787                 pv_cb_handle,
788                 "IHEVCE ERROR: gop period is not valid for the configured temporal layers\n");
789             return IHEVCE_SETUNSUPPORTEDINPUT(error_code);
790         }
791 
792         if((i4_min_idr_period > i4_max_idr_period) || (i4_min_idr_period < 0))
793         {
794             error_code = IHEVCE_INVALID_GOP_PERIOD;
795             ps_sys_api->ihevce_printf(
796                 pv_cb_handle,
797                 "IHEVCE ERROR: gop period is not valid => min closed gop > max closed gop\n");
798             return IHEVCE_SETUNSUPPORTEDINPUT(error_code);
799         }
800         if(ps_static_cfg_prms->s_coding_tools_prms.i4_max_temporal_layers && i4_max_i_distance == 1)
801         {
802             error_code = IHEVCE_TEMPORAL_LAYERS_NOT_SUPPORTED;
803             ps_sys_api->ihevce_printf(
804                 pv_cb_handle, "IHEVCE ERROR: Invalid max temporal layer for I only encoding\n");
805             return IHEVCE_SETUNSUPPORTEDINPUT(error_code);
806         }
807         if((i4_max_idr_period < i4_max_cra_period || i4_max_idr_period < i4_max_i_period) &&
808            i4_max_idr_period)
809         {
810             error_code = IHEVCE_INVALID_GOP_PERIOD;
811             ps_sys_api->ihevce_printf(
812                 pv_cb_handle,
813                 "IHEVCE ERROR: MAX IDR period can't be less than Max CRA or I period\n");
814             return IHEVCE_SETUNSUPPORTEDINPUT(error_code);
815         }
816         if((i4_max_cra_period < i4_max_i_period) && i4_max_cra_period)
817         {
818             error_code = IHEVCE_INVALID_GOP_PERIOD;
819             ps_sys_api->ihevce_printf(
820                 pv_cb_handle, "IHEVCE ERROR: MAX CRA period can't be less than Max I period\n");
821             return IHEVCE_SETUNSUPPORTEDINPUT(error_code);
822         }
823     }
824     if(0 != ps_static_cfg_prms->s_tgt_lyr_prms.i4_enable_temporal_scalability)
825     {
826         error_code = IHEVCE_INVALID_TEMPORAL_SCALABILITY;
827         ps_sys_api->ihevce_printf(
828             pv_cb_handle, "IHEVCE ERROR: Temporal scalability is not supported \n");
829         return IHEVCE_SETUNSUPPORTEDINPUT(error_code);
830     }
831 
832     if(ps_static_cfg_prms->s_coding_tools_prms.i4_max_reference_frames != -1)
833     {
834         error_code = IHEVCE_REF_FRAMES_NOT_SUPPORTED;
835         ps_sys_api->ihevce_printf(
836             pv_cb_handle, "IHEVCE ERROR: only supported value for i4_max_reference_frames is -1\n");
837         return IHEVCE_SETUNSUPPORTEDINPUT(error_code);
838     }
839 
840     if(ps_static_cfg_prms->s_coding_tools_prms.i4_weighted_pred_enable != 0 &&
841        ps_static_cfg_prms->s_coding_tools_prms.i4_weighted_pred_enable != 1)
842     {
843         error_code = IHEVCE_INVALID_WEIGHTED_PREDICTION_INPUT;
844         ps_sys_api->ihevce_printf(pv_cb_handle, "IHEVCE ERROR: i4_weighted_pred_enable invalid \n");
845         return IHEVCE_SETUNSUPPORTEDINPUT(error_code);
846     }
847 
848     if(ps_static_cfg_prms->s_coding_tools_prms.i4_deblocking_type != 0 &&
849        ps_static_cfg_prms->s_coding_tools_prms.i4_deblocking_type != 1 &&
850        ps_static_cfg_prms->s_coding_tools_prms.i4_deblocking_type != 2)
851     {
852         error_code = IHEVCE_INVALID_DEBLOCKING_TYPE_INPUT;
853         ps_sys_api->ihevce_printf(pv_cb_handle, "IHEVCE ERROR: i4_deblocking_type invalid\n");
854         return IHEVCE_SETUNSUPPORTEDINPUT(error_code);
855     }
856 
857     if(ps_static_cfg_prms->s_coding_tools_prms.i4_use_default_sc_mtx != 0 &&
858        ps_static_cfg_prms->s_coding_tools_prms.i4_use_default_sc_mtx != 1)
859     {
860         error_code = IHEVCE_INVALID_DEFAULT_SC_MATRIX_ENABLE_INPUT;
861         ps_sys_api->ihevce_printf(pv_cb_handle, "IHEVCE ERROR: i4_use_default_sc_mtx invalid \n");
862         return IHEVCE_SETUNSUPPORTEDINPUT(error_code);
863     }
864 
865     if(ps_static_cfg_prms->s_coding_tools_prms.i4_cropping_mode != 0 &&
866        ps_static_cfg_prms->s_coding_tools_prms.i4_cropping_mode != 1)
867     {
868         error_code = IHEVCE_INVALID_CROPPING_MODE;
869         ps_sys_api->ihevce_printf(pv_cb_handle, "IHEVCE ERROR: i4_cropping_mode invalid \n");
870         return IHEVCE_SETUNSUPPORTEDINPUT(error_code);
871     }
872 
873     /* Error checks for Static Config Parameters */
874     if(ps_static_cfg_prms->s_config_prms.i4_min_log2_cu_size != 3)
875     {
876         error_code = IHEVCE_MIN_CU_SIZE_INPUT_NOT_SUPPORTED;
877         ps_sys_api->ihevce_printf(pv_cb_handle, "IHEVCE ERROR: i4_min_log2_cu_size invalid \n");
878         return IHEVCE_SETUNSUPPORTEDINPUT(error_code);
879     }
880 
881     if(ps_static_cfg_prms->s_config_prms.i4_min_log2_tu_size != 2)
882     {
883         error_code = IHEVCE_MIN_TU_SIZE_INPUT_NOT_SUPPORTED;
884         ps_sys_api->ihevce_printf(pv_cb_handle, "IHEVCE ERROR: i4_min_log2_tu_size invalid \n");
885         return IHEVCE_SETUNSUPPORTEDINPUT(error_code);
886     }
887 
888     if(ps_static_cfg_prms->s_config_prms.i4_max_log2_cu_size < 4 ||
889        ps_static_cfg_prms->s_config_prms.i4_max_log2_cu_size > 6)
890     {
891         error_code = IHEVCE_MAX_CU_SIZE_INPUT_NOT_SUPPORTED;
892         ps_sys_api->ihevce_printf(pv_cb_handle, "IHEVCE ERROR: i4_max_log2_cu_size invalid \n");
893         return IHEVCE_SETUNSUPPORTEDINPUT(error_code);
894     }
895 
896     if(ps_static_cfg_prms->s_config_prms.i4_max_log2_tu_size < 2 ||
897        ps_static_cfg_prms->s_config_prms.i4_max_log2_tu_size > 5)
898     {
899         error_code = IHEVCE_MAX_TU_SIZE_INPUT_NOT_SUPPORTED;
900         ps_sys_api->ihevce_printf(pv_cb_handle, "IHEVCE ERROR: i4_max_log2_tu_size invalid \n");
901         return IHEVCE_SETUNSUPPORTEDINPUT(error_code);
902     }
903 
904     if(ps_static_cfg_prms->s_config_prms.i4_min_log2_cu_size == 4 &&
905        ps_static_cfg_prms->s_config_prms.i4_max_log2_tu_size == 5)
906     {
907         /* Because tu size should always be lesser than the cu size */
908         error_code = IHEVCE_INVALID_MAX_TU_SIZE;
909         ps_sys_api->ihevce_printf(
910             pv_cb_handle,
911             "IHEVCE ERROR: Invalid combination of i4_min_log2_cu_size and i4_max_log2_tu_size\n");
912         return IHEVCE_SETUNSUPPORTEDINPUT(error_code);
913     }
914 
915     if(ps_static_cfg_prms->s_config_prms.i4_max_tr_tree_depth_I < 1 ||
916        ps_static_cfg_prms->s_config_prms.i4_max_tr_tree_depth_I > 3)
917     {
918         error_code = IHEVCE_INVALID_TR_TREE_DEPTH_FOR_I_FRAME;
919         ps_sys_api->ihevce_printf(
920             pv_cb_handle, "IHEVCE ERROR: i4_max_tr_tree_depth_I out of range\n");
921         return IHEVCE_SETUNSUPPORTEDINPUT(error_code);
922     }
923 
924     if(ps_static_cfg_prms->s_config_prms.i4_max_tr_tree_depth_nI < 1 ||
925        ps_static_cfg_prms->s_config_prms.i4_max_tr_tree_depth_nI > 4)
926     {
927         error_code = IHEVCE_INVALID_TR_TREE_DEPTH;
928         ps_sys_api->ihevce_printf(
929             pv_cb_handle, "IHEVCE ERROR: i4_max_tr_tree_depth_nI out of range\n");
930         return IHEVCE_SETUNSUPPORTEDINPUT(error_code);
931     }
932 
933     if(ps_static_cfg_prms->s_config_prms.i4_max_search_range_horz < 64 ||
934        ps_static_cfg_prms->s_config_prms.i4_max_search_range_horz > 512)
935     {
936         error_code = IHEVCE_UNSUPPORTED_HORIZONTAL_SEARCH_RANGE;
937         ps_sys_api->ihevce_printf(
938             pv_cb_handle, "IHEVCE ERROR: i4_max_search_range_horz out of range\n");
939         return IHEVCE_SETUNSUPPORTEDINPUT(error_code);
940     }
941 
942     if(ps_static_cfg_prms->s_config_prms.i4_max_search_range_vert < 32 ||
943        ps_static_cfg_prms->s_config_prms.i4_max_search_range_vert > 256)
944     {
945         error_code = IHEVCE_UNSUPPORTED_VERTICAL_SEARCH_RANGE;
946         ps_sys_api->ihevce_printf(
947             pv_cb_handle, "IHEVCE ERROR: i4_max_search_range_vert out of range\n");
948         return IHEVCE_SETUNSUPPORTEDINPUT(error_code);
949     }
950 
951     if(ps_static_cfg_prms->s_lap_prms.i4_rc_look_ahead_pics > NUM_LAP2_LOOK_AHEAD ||
952        ps_static_cfg_prms->s_lap_prms.i4_rc_look_ahead_pics < 0)
953     {
954         error_code = IHEVCE_UNSUPPORTED_LOOK_AHEAD;
955         ps_sys_api->ihevce_printf(
956             pv_cb_handle,
957             "IHEVCE ERROR: rc look ahead pc must be in range of 0 to NUM_LAP2_LOOK_AHEAD\n");
958         return IHEVCE_SETUNSUPPORTEDINPUT(error_code);
959     }
960 
961     /* Num res instances should be less than equal to IHEVCE_MAX_NUM_RESOLUTIONS */
962     if((i4_num_resolutions < 1) || (i4_num_resolutions > IHEVCE_MAX_NUM_RESOLUTIONS))
963     {
964         error_code = IHEVCE_NUM_MAX_RESOLUTIONS_NOT_SUPPORTED;
965         ps_sys_api->ihevce_printf(pv_cb_handle, "IHEVCE ERROR: invalid i4_num_resolutions \n");
966         return (IHEVCE_SETUNSUPPORTEDINPUT(error_code));
967     }
968 
969     if((ps_static_cfg_prms->i4_res_id < 0) || (ps_static_cfg_prms->i4_res_id >= i4_num_resolutions))
970     {
971         error_code = IHEVCE_NUM_MAX_RESOLUTIONS_NOT_SUPPORTED;
972         ps_sys_api->ihevce_printf(pv_cb_handle, "IHEVCE ERROR: invalid i4_num_resolutions \n");
973         return (IHEVCE_SETUNSUPPORTEDINPUT(error_code));
974     }
975 
976     if((ps_static_cfg_prms->s_tgt_lyr_prms.i4_mres_single_out < 0) ||
977        (ps_static_cfg_prms->s_tgt_lyr_prms.i4_mres_single_out > 1))
978     {
979         error_code = IHEVCE_INVALID_MRES_SINGLE_OUT;
980         ps_sys_api->ihevce_printf(
981             pv_cb_handle, "IHEVCE ERROR: invalid i4_mres_single_out value \n");
982         return (IHEVCE_SETUNSUPPORTEDINPUT(error_code));
983     }
984 
985     if((ps_static_cfg_prms->i4_save_recon) &&
986        (1 == ps_static_cfg_prms->s_tgt_lyr_prms.i4_mres_single_out))
987     {
988         ps_sys_api->ihevce_printf(
989             pv_cb_handle,
990             "IHEVCE WARNING: i4_save_recon not supported for mres single out case \n");
991         ps_static_cfg_prms->i4_save_recon = 0;
992     }
993 
994     if((1 == i4_num_resolutions) && (1 == ps_static_cfg_prms->s_tgt_lyr_prms.i4_mres_single_out))
995     {
996         ps_sys_api->ihevce_printf(
997             pv_cb_handle,
998             "IHEVCE WARNING: i4_mres_single_out value changed to 0 for single resolution case \n");
999         ps_static_cfg_prms->s_tgt_lyr_prms.i4_mres_single_out = 0;
1000     }
1001 
1002     if(ps_static_cfg_prms->s_tgt_lyr_prms.i4_mbr_quality_setting < 0 ||
1003        ps_static_cfg_prms->s_tgt_lyr_prms.i4_mbr_quality_setting > 3)
1004     {
1005         error_code = IHEVCE_INVALID_MBR_QUALITY_SETTING;
1006         ps_sys_api->ihevce_printf(pv_cb_handle, "IHEVCE ERROR: invalid mbr quality setting\n");
1007         return (IHEVCE_SETUNSUPPORTEDINPUT(error_code));
1008     }
1009 
1010     if(ps_static_cfg_prms->s_tgt_lyr_prms.i4_multi_res_layer_reuse != 0)
1011     {
1012         error_code = IHEVCE_MULTI_RES_LAYER_REUSE_NOT_SUPPORTED;
1013         ps_sys_api->ihevce_printf(
1014             pv_cb_handle,
1015             "IHEVCE ERROR: reuse of info across resolution is not currently supported \n");
1016         return IHEVCE_SETUNSUPPORTEDINPUT(error_code);
1017     }
1018 
1019     for(i4_resolution_id = 0; i4_resolution_id < i4_num_resolutions; i4_resolution_id++)
1020     {
1021         WORD32 codec_level_index, quality_preset, height, width, frm_rate_scale_factor;
1022         WORD32 br_ctr;
1023         UWORD32 u4_luma_sample_rate;
1024         WORD32 max_dpb_size;
1025         WORD32 i4_field_pic = ps_static_cfg_prms->s_src_prms.i4_field_pic;
1026 
1027         codec_level_index = ihevce_get_level_index(
1028             ps_static_cfg_prms->s_tgt_lyr_prms.as_tgt_params[i4_resolution_id].i4_codec_level);
1029         quality_preset =
1030             ps_static_cfg_prms->s_tgt_lyr_prms.as_tgt_params[i4_resolution_id].i4_quality_preset;
1031         height = ps_static_cfg_prms->s_tgt_lyr_prms.as_tgt_params[i4_resolution_id].i4_height;
1032         width = ps_static_cfg_prms->s_tgt_lyr_prms.as_tgt_params[i4_resolution_id].i4_width;
1033         frm_rate_scale_factor = ps_static_cfg_prms->s_tgt_lyr_prms.as_tgt_params[i4_resolution_id]
1034                                     .i4_frm_rate_scale_factor;
1035         /* Check error for max picture size(luma) for the given level */
1036         if((width * height) > g_as_level_data[codec_level_index].i4_max_luma_picture_size)
1037         {
1038             error_code = IHEVCE_PIC_SIZE_NOT_SUPPORTED;
1039             ps_sys_api->ihevce_printf(
1040                 pv_cb_handle,
1041                 "IHEVCE ERROR: (i4_tgt_width * i4_tgt_height) out of range for resolution number "
1042                 "'%d' codec level %d "
1043                 "\n",
1044                 i4_resolution_id,
1045                 codec_level_index);
1046             return (IHEVCE_SETUNSUPPORTEDINPUT(error_code));
1047         }
1048 
1049         if((width * height) <= (g_as_level_data[codec_level_index].i4_max_luma_picture_size >> 2))
1050         {
1051             max_dpb_size = 16;
1052         }
1053         else if((width * height) <= (g_as_level_data[codec_level_index].i4_max_luma_picture_size >> 1))
1054         {
1055             max_dpb_size = 12;
1056         }
1057         else if(
1058             (width * height) <=
1059             (3 * g_as_level_data[codec_level_index].i4_max_luma_picture_size >> 2))
1060         {
1061             max_dpb_size = 8;
1062         }
1063         else
1064         {
1065             max_dpb_size = 6;
1066         }
1067 
1068         /* DPB check */
1069         if((((DEFAULT_MAX_REFERENCE_PICS - i4_field_pic) /*max reference*/ + 2) << i4_field_pic) >
1070            max_dpb_size)
1071         {
1072             error_code = IHEVCE_CODEC_LEVEL_NOT_SUPPORTED;
1073             ps_sys_api->ihevce_printf(
1074                 pv_cb_handle, "IHEVCE ERROR: i4_codec_level should be set correct \n");
1075             return IHEVCE_SETUNSUPPORTEDINPUT(error_code);
1076         }
1077 
1078         if((quality_preset > IHEVCE_QUALITY_P7) || (quality_preset < 0) || (quality_preset == 1))
1079         {
1080             error_code = IHEVCE_INVALID_QUALITY_PRESET_INPUT;
1081             ps_sys_api->ihevce_printf(pv_cb_handle, "IHEVCE ERROR: i4_quality_preset invalid \n");
1082             return IHEVCE_SETUNSUPPORTEDINPUT(error_code);
1083         }
1084 
1085         /* Error checks for target width and height */
1086         if((height > HEVCE_MAX_HEIGHT) || (height < HEVCE_MIN_HEIGHT) ||
1087            (height != ps_static_cfg_prms->s_src_prms.i4_height))
1088         {
1089             error_code = IHEVCE_TGT_HEIGHT_NOT_SUPPORTED;
1090             ps_sys_api->ihevce_printf(pv_cb_handle, "IHEVCE ERROR: Target height not supported\n");
1091             return IHEVCE_SETUNSUPPORTEDINPUT(error_code);
1092         }
1093 
1094         if((width > HEVCE_MAX_WIDTH) || (width < HEVCE_MIN_WIDTH) ||
1095            (width != ps_static_cfg_prms->s_src_prms.i4_width))
1096         {
1097             error_code = IHEVCE_TGT_WIDTH_NOT_SUPPORTED;
1098             ps_sys_api->ihevce_printf(pv_cb_handle, "IHEVCE ERROR: Target width not supported\n");
1099             return IHEVCE_SETUNSUPPORTEDINPUT(error_code);
1100         }
1101 
1102         /* Error checks for the codec level */
1103         if(ps_static_cfg_prms->s_tgt_lyr_prms.as_tgt_params[i4_resolution_id].i4_codec_level >
1104            LEVEL6)
1105         {
1106             error_code = IHEVCE_CODEC_LEVEL_NOT_SUPPORTED;
1107             ps_sys_api->ihevce_printf(
1108                 pv_cb_handle,
1109                 "IHEVCE ERROR: i4_codec_level should be set to a max value of 153 \n");
1110             return IHEVCE_SETUNSUPPORTEDINPUT(error_code);
1111         }
1112 
1113         if(frm_rate_scale_factor != 1)
1114         {
1115             error_code = IHEVCE_TGT_FRAME_RATE_SCALING_NOT_SUPPORTED;
1116             ps_sys_api->ihevce_printf(
1117                 pv_cb_handle, "IHEVCE ERROR:  Target frame rate scaler should be 1 \n");
1118             return IHEVCE_SETUNSUPPORTEDINPUT(error_code);
1119         }
1120 
1121         u4_luma_sample_rate = (UWORD32)(width * height);
1122         u4_luma_sample_rate *= (UWORD32)(
1123             ps_static_cfg_prms->s_src_prms.i4_frm_rate_num /
1124             (ps_static_cfg_prms->s_src_prms.i4_frm_rate_denom * frm_rate_scale_factor));
1125         /* Check error for max samples rate (frame rate * luma picture size) for the given level */
1126         if(u4_luma_sample_rate > g_as_level_data[codec_level_index].u4_max_luma_sample_rate)
1127         {
1128             error_code = IHEVCE_LUMA_SAMPLE_RATE_NOT_SUPPORTED;
1129             ps_sys_api->ihevce_printf(
1130                 pv_cb_handle,
1131                 "IHEVCE ERROR: input sample rate (i4_src_width * i4_src_height * i4_frm_rate_num / "
1132                 "i4_frm_rate_denom ) "
1133                 "exceeds u4_max_luma_sample_rate\n");
1134             return (IHEVCE_SETUNSUPPORTEDINPUT(error_code));
1135         }
1136 
1137         /* Num instances should be less than equal to IHEVCE_MAX_NUM_BITRATES */
1138         if((ai4_num_bitrate_instances[i4_resolution_id] < 1) ||
1139            (ai4_num_bitrate_instances[i4_resolution_id] > IHEVCE_MAX_NUM_BITRATES))
1140         {
1141             error_code = IHEVCE_INVALID_NUM_BR_INSTANCES;
1142             ps_sys_api->ihevce_printf(
1143                 pv_cb_handle, "IHEVCE ERROR: invalid i4_num_bitrate_instances \n");
1144             return (IHEVCE_SETUNSUPPORTEDINPUT(error_code));
1145         }
1146 
1147         /* check for codec tier */
1148         if((ps_static_cfg_prms->s_out_strm_prms.i4_codec_tier > HIGH_TIER) ||
1149            (ps_static_cfg_prms->s_out_strm_prms.i4_codec_tier < MAIN_TIER))
1150         {
1151             error_code = IHEVC_CODEC_TIER_NOT_SUPPORTED;
1152             ps_sys_api->ihevce_printf(pv_cb_handle, "IHEVCE ERROR: Codec tier  out of range\n");
1153             return IHEVCE_SETUNSUPPORTEDINPUT(error_code);
1154         }
1155 
1156         if((ps_static_cfg_prms->s_tgt_lyr_prms.as_tgt_params[i4_resolution_id].i4_codec_level <
1157             120) &&
1158            (ps_static_cfg_prms->s_out_strm_prms.i4_codec_tier == HIGH_TIER))
1159         {
1160             error_code = IHEVC_CODEC_TIER_NOT_SUPPORTED;
1161             ps_sys_api->ihevce_printf(
1162                 pv_cb_handle, "IHEVCE ERROR: Codec tier = HIGH TIER Not supported below Level 4\n");
1163             return IHEVCE_SETUNSUPPORTEDINPUT(error_code);
1164         }
1165 
1166         /* Check error for max bitrate for the given level */
1167         for(br_ctr = 0; br_ctr < ai4_num_bitrate_instances[i4_resolution_id]; br_ctr++)
1168         {
1169             WORD32 frame_qp = ps_static_cfg_prms->s_tgt_lyr_prms.as_tgt_params[i4_resolution_id]
1170                                   .ai4_frame_qp[br_ctr];
1171             WORD32 tgt_bitrate = ps_static_cfg_prms->s_tgt_lyr_prms.as_tgt_params[i4_resolution_id]
1172                                      .ai4_tgt_bitrate[br_ctr];
1173             WORD32 peak_bitrate;
1174 
1175             if(frame_qp > 51 || frame_qp <= 0)
1176             {
1177                 error_code = IHEVCE_UNSUPPORTED_FRAME_QP;
1178                 ps_sys_api->ihevce_printf(pv_cb_handle, "IHEVCE ERROR: i4_frame_qp out of range\n");
1179                 return IHEVCE_SETUNSUPPORTEDINPUT(error_code);
1180             }
1181             if((frame_qp < ps_static_cfg_prms->s_config_prms.i4_min_frame_qp) ||
1182                ((frame_qp + ps_static_cfg_prms->s_coding_tools_prms.i4_max_temporal_layers + 1) >
1183                 ps_static_cfg_prms->s_config_prms.i4_max_frame_qp))
1184             {
1185                 error_code = IHEVCE_UNSUPPORTED_FRAME_QP;
1186                 ps_sys_api->ihevce_printf(pv_cb_handle, "IHEVCE ERROR: i4_frame_qp out of range\n");
1187                 return IHEVCE_SETUNSUPPORTEDINPUT(error_code);
1188             }
1189 
1190             if(tgt_bitrate >
1191                    g_as_level_data[codec_level_index]
1192                            .i4_max_bit_rate[ps_static_cfg_prms->s_out_strm_prms.i4_codec_tier] *
1193                        CBP_VCL_FACTOR ||
1194                tgt_bitrate < 4000)
1195             {
1196                 error_code = IHEVCE_BITRATE_NOT_SUPPORTED;
1197                 ps_sys_api->ihevce_printf(
1198                     pv_cb_handle,
1199                     "IHEVCE ERROR: i4_tgt_bitrate out of range for resoltuion number %d bitrate "
1200                     "number %d\n",
1201                     i4_resolution_id,
1202                     br_ctr);
1203                 return (IHEVCE_SETUNSUPPORTEDINPUT(error_code));
1204             }
1205 
1206             peak_bitrate = tgt_bitrate << 1;
1207             peak_bitrate =
1208                 MIN(peak_bitrate,
1209                     g_as_level_data[codec_level_index]
1210                             .i4_max_bit_rate[ps_static_cfg_prms->s_out_strm_prms.i4_codec_tier] *
1211                         1000);
1212             ps_static_cfg_prms->s_tgt_lyr_prms.as_tgt_params[i4_resolution_id]
1213                 .ai4_peak_bitrate[br_ctr] = peak_bitrate;
1214             ps_static_cfg_prms->s_tgt_lyr_prms.as_tgt_params[i4_resolution_id]
1215                 .ai4_max_vbv_buffer_size[br_ctr] = peak_bitrate;
1216         }
1217     }
1218 
1219     if((ps_static_cfg_prms->i4_br_id < 0) ||
1220        (ps_static_cfg_prms->i4_br_id >= ai4_num_bitrate_instances[ps_static_cfg_prms->i4_res_id]))
1221     {
1222         error_code = IHEVCE_INVALID_NUM_BR_INSTANCES;
1223         ps_sys_api->ihevce_printf(
1224             pv_cb_handle, "IHEVCE ERROR: invalid i4_num_bitrate_instances \n");
1225         return (IHEVCE_SETUNSUPPORTEDINPUT(error_code));
1226     }
1227 
1228     /* Check error for rate control mode for the given level */
1229     if(ps_static_cfg_prms->s_config_prms.i4_rate_control_mode != 2 &&
1230        ps_static_cfg_prms->s_config_prms.i4_rate_control_mode != 3 &&
1231        ps_static_cfg_prms->s_config_prms.i4_rate_control_mode != 5)
1232     {
1233         error_code = IHEVCE_RATE_CONTROL_MDOE_NOT_SUPPORTED;
1234         ps_sys_api->ihevce_printf(
1235             pv_cb_handle, "IHEVCE ERROR: i4_rate_control_mode out of range\n");
1236         return (IHEVCE_SETUNSUPPORTEDINPUT(error_code));
1237     }
1238 
1239     /* Check error for pass number */
1240     if(ps_static_cfg_prms->s_pass_prms.i4_pass != 0)
1241     {
1242         error_code = IHEVCE_RATE_CONTROL_PASS_INVALID;
1243         ps_sys_api->ihevce_printf(pv_cb_handle, "IHEVCE ERROR: i4_pass out of range\n");
1244         return (IHEVCE_SETUNSUPPORTEDINPUT(error_code));
1245     }
1246 
1247     /* Check error for cu level qp modultion for the given level */
1248     if(ps_static_cfg_prms->s_config_prms.i4_cu_level_rc != 0 &&
1249        ps_static_cfg_prms->s_config_prms.i4_cu_level_rc != 1)
1250     {
1251         error_code = IHEVCE_RATE_CONTROL_MDOE_NOT_SUPPORTED;
1252         ps_sys_api->ihevce_printf(pv_cb_handle, "IHEVCE ERROR: i4_cu_level_rc out of range\n");
1253         return (IHEVCE_SETUNSUPPORTEDINPUT(error_code));
1254     }
1255 
1256     /* size error checks for the api structures */
1257     if(ps_static_cfg_prms->i4_size != sizeof(ihevce_static_cfg_params_t))
1258     {
1259         error_code = IHEVCE_INVALID_SIZE;
1260         ps_sys_api->ihevce_printf(
1261             pv_cb_handle,
1262             "IHEVCE ERROR: Size element of ihevce_static_cfg_params_t is not matching with actual "
1263             "size");
1264         return (IHEVCE_SETUNSUPPORTEDINPUT(error_code));
1265     }
1266     if(ps_static_cfg_prms->s_src_prms.i4_size != sizeof(ihevce_src_params_t))
1267     {
1268         error_code = IHEVCE_INVALID_SIZE;
1269         ps_sys_api->ihevce_printf(
1270             pv_cb_handle,
1271             "IHEVCE ERROR: Size element of ihevce_src_params_t is not matching with actual size");
1272         return (IHEVCE_SETUNSUPPORTEDINPUT(error_code));
1273     }
1274     if(ps_static_cfg_prms->s_tgt_lyr_prms.i4_size != sizeof(ihevce_tgt_layer_params_t))
1275     {
1276         error_code = IHEVCE_INVALID_SIZE;
1277         ps_sys_api->ihevce_printf(
1278             pv_cb_handle,
1279             "IHEVCE ERROR: Size element of ihevce_tgt_layer_params_t is not matching with actual "
1280             "size");
1281         return (IHEVCE_SETUNSUPPORTEDINPUT(error_code));
1282     }
1283     if(ps_static_cfg_prms->s_out_strm_prms.i4_size != sizeof(ihevce_out_strm_params_t))
1284     {
1285         error_code = IHEVCE_INVALID_SIZE;
1286         ps_sys_api->ihevce_printf(
1287             pv_cb_handle,
1288             "IHEVCE ERROR: Size element of ihevce_out_strm_params_t is not matching with actual "
1289             "size");
1290         return (IHEVCE_SETUNSUPPORTEDINPUT(error_code));
1291     }
1292     if(ps_static_cfg_prms->s_coding_tools_prms.i4_size != sizeof(ihevce_coding_params_t))
1293     {
1294         error_code = IHEVCE_INVALID_SIZE;
1295         ps_sys_api->ihevce_printf(
1296             pv_cb_handle,
1297             "IHEVCE ERROR: Size element of ihevce_coding_params_t is not matching with actual "
1298             "size");
1299         return (IHEVCE_SETUNSUPPORTEDINPUT(error_code));
1300     }
1301     if(ps_static_cfg_prms->s_config_prms.i4_size != sizeof(ihevce_config_prms_t))
1302     {
1303         error_code = IHEVCE_INVALID_SIZE;
1304         ps_sys_api->ihevce_printf(
1305             pv_cb_handle,
1306             "IHEVCE ERROR: Size element of ihevce_config_prms_t is not matching with actual size");
1307         return (IHEVCE_SETUNSUPPORTEDINPUT(error_code));
1308     }
1309     if(ps_static_cfg_prms->s_multi_thrd_prms.i4_size != sizeof(ihevce_static_multi_thread_params_t))
1310     {
1311         error_code = IHEVCE_INVALID_SIZE;
1312         ps_sys_api->ihevce_printf(
1313             pv_cb_handle,
1314             "IHEVCE ERROR: Size element of ihevce_static_multi_thread_params_t is not matching "
1315             "with actual size");
1316         return (IHEVCE_SETUNSUPPORTEDINPUT(error_code));
1317     }
1318     for(i4_resolution_id = 0; i4_resolution_id < i4_num_resolutions; i4_resolution_id++)
1319     {
1320         if(ps_static_cfg_prms->s_tgt_lyr_prms.as_tgt_params[i4_resolution_id].i4_size !=
1321            sizeof(ihevce_tgt_params_t))
1322         {
1323             error_code = IHEVCE_INVALID_SIZE;
1324             ps_sys_api->ihevce_printf(
1325                 pv_cb_handle,
1326                 "IHEVCE ERROR: Size element of ihevce_tgt_params_t is not matching with actual "
1327                 "size");
1328             return (IHEVCE_SETUNSUPPORTEDINPUT(error_code));
1329         }
1330     }
1331 
1332     if(ps_static_cfg_prms->s_lap_prms.i4_size != sizeof(ihevce_lap_params_t))
1333     {
1334         error_code = IHEVCE_INVALID_SIZE;
1335         ps_sys_api->ihevce_printf(
1336             pv_cb_handle,
1337             "IHEVCE ERROR: Size element of ihevce_lap_params_t is not matching with actual size");
1338         return (IHEVCE_SETUNSUPPORTEDINPUT(error_code));
1339     }
1340 
1341     for(i4_resolution_id = 0; i4_resolution_id < i4_num_resolutions; i4_resolution_id++)
1342     {
1343         if(ps_static_cfg_prms->s_tgt_lyr_prms.as_tgt_params[i4_resolution_id].i4_size !=
1344            sizeof(ihevce_tgt_params_t))
1345         {
1346             error_code = IHEVCE_INVALID_SIZE;
1347             ps_sys_api->ihevce_printf(
1348                 pv_cb_handle,
1349                 "IHEVCE ERROR: Size element of ihevce_tgt_params_t is not matching with actual "
1350                 "size");
1351             return (IHEVCE_SETUNSUPPORTEDINPUT(error_code));
1352         }
1353     }
1354 
1355     /* Check SEI related error checks */
1356     if(1 == ps_static_cfg_prms->s_out_strm_prms.i4_sei_enable_flag)
1357     {
1358         WORD32 i;
1359         /* Check values for i4_sei_hash_flags */
1360         if(!((ps_static_cfg_prms->s_out_strm_prms.i4_decoded_pic_hash_sei_flag == 2) ||
1361              (ps_static_cfg_prms->s_out_strm_prms.i4_decoded_pic_hash_sei_flag == 3) ||
1362              (ps_static_cfg_prms->s_out_strm_prms.i4_decoded_pic_hash_sei_flag == 0)))
1363         {
1364             error_code = IHEVCE_SEI_HASH_VALUE_NOT_SUPPORTED;
1365             ps_sys_api->ihevce_printf(
1366                 pv_cb_handle, "IHEVCE ERROR: i4_sei_hash_flags out of range\n");
1367             return (IHEVCE_SETUNSUPPORTEDINPUT(error_code));
1368         }
1369 
1370         /* Content Light Level Info error check */
1371         if((ps_static_cfg_prms->s_out_strm_prms.i4_sei_cll_enable > 1) ||
1372            (ps_static_cfg_prms->s_out_strm_prms.i4_sei_cll_enable < 0))
1373         {
1374             error_code = IHEVCE_SEI_CLL_ENABLE_OUT_OF_RANGE;
1375             ps_sys_api->ihevce_printf(
1376                 pv_cb_handle, "IHEVCE ERROR: i4_sei_cll_enable out of range\n");
1377             return (IHEVCE_SETUNSUPPORTEDINPUT(error_code));
1378         }
1379 
1380         if((ps_static_cfg_prms->s_out_strm_prms.i4_sei_buffer_period_flags ||
1381             ps_static_cfg_prms->s_out_strm_prms.i4_sei_pic_timing_flags) &&
1382            (!ps_static_cfg_prms->s_out_strm_prms.i4_vui_enable))
1383         {
1384             error_code = IHEVCE_SEI_ENABLED_VUI_DISABLED;
1385             ps_sys_api->ihevce_printf(
1386                 pv_cb_handle,
1387                 "IHEVCE ERROR: Both SEI and VUI ought to be enabled when either "
1388                 "'i4_sei_buffer_period_flags' or "
1389                 "'i4_sei_pic_timing_flags' are enabled\n");
1390             return (IHEVCE_SETUNSUPPORTEDINPUT(error_code));
1391         }
1392 
1393         if((1 == ps_static_cfg_prms->s_out_strm_prms.i4_sei_buffer_period_flags) &&
1394            (3 == ps_static_cfg_prms->s_config_prms.i4_rate_control_mode))
1395         {
1396             error_code = IHEVCE_SEI_MESSAGES_DEPENDENCY;
1397             ps_sys_api->ihevce_printf(
1398                 pv_cb_handle,
1399                 "IHEVCE ERROR: i4_sei_buffer_period_flags should be disabled for CQP mode of Rate "
1400                 "control \n");
1401             return (IHEVCE_SETUNSUPPORTEDINPUT(error_code));
1402         }
1403 
1404         /* Check values for i4_sei_mastering_disp_colour_vol_flags */
1405         if((ps_static_cfg_prms->s_out_strm_prms.i4_sei_mastering_disp_colour_vol_flags != 0) &&
1406            (ps_static_cfg_prms->s_out_strm_prms.i4_sei_mastering_disp_colour_vol_flags != 1))
1407         {
1408             error_code = IHEVCE_MASTERING_DISP_COL_VOL_OUT_OF_RANGE;
1409             ps_sys_api->ihevce_printf(
1410                 pv_cb_handle,
1411                 "IHEVCE ERROR: i4_sei_mastering_disp_colour_vol_flags out of range\n");
1412             return (IHEVCE_SETUNSUPPORTEDINPUT(error_code));
1413         }
1414 
1415         if(1 == ps_static_cfg_prms->s_out_strm_prms.i4_sei_mastering_disp_colour_vol_flags)
1416         {
1417             /* Check values for u2_display_primaries_x and u2_display_primaries_y */
1418             for(i = 0; i < 3; i++)
1419             {
1420                 if((ps_static_cfg_prms->s_out_strm_prms.au2_display_primaries_x[i] > 50000))
1421                 {
1422                     error_code = IHEVCE_DISPLAY_PRIMARY_X_OUT_OF_RANGE;
1423                     ps_sys_api->ihevce_printf(
1424                         pv_cb_handle, "IHEVCE ERROR: au2_display_primaries_x out of range\n");
1425                     return (IHEVCE_SETUNSUPPORTEDINPUT(error_code));
1426                 }
1427 
1428                 if((ps_static_cfg_prms->s_out_strm_prms.au2_display_primaries_y[i] > 50000))
1429                 {
1430                     error_code = IHEVCE_DISPLAY_PRIMARY_Y_OUT_OF_RANGE;
1431                     ps_sys_api->ihevce_printf(
1432                         pv_cb_handle, "IHEVCE ERROR: au2_display_primaries_y out of range\n");
1433                     return (IHEVCE_SETUNSUPPORTEDINPUT(error_code));
1434                 }
1435             }
1436 
1437             if((ps_static_cfg_prms->s_out_strm_prms.u2_white_point_x > 50000))
1438             {
1439                 error_code = IHEVCE_WHITE_POINT_X_OUT_OF_RANGE;
1440                 ps_sys_api->ihevce_printf(
1441                     pv_cb_handle, "IHEVCE ERROR: u2_white_point_x out of range\n");
1442                 return (IHEVCE_SETUNSUPPORTEDINPUT(error_code));
1443             }
1444 
1445             if((ps_static_cfg_prms->s_out_strm_prms.u2_white_point_y > 50000))
1446             {
1447                 error_code = IHEVCE_WHITE_POINT_Y_OUT_OF_RANGE;
1448                 ps_sys_api->ihevce_printf(
1449                     pv_cb_handle, "IHEVCE ERROR: u2_white_point_y out of range\n");
1450                 return (IHEVCE_SETUNSUPPORTEDINPUT(error_code));
1451             }
1452 
1453             if(ps_static_cfg_prms->s_out_strm_prms.u4_max_display_mastering_luminance <=
1454                ps_static_cfg_prms->s_out_strm_prms.u4_min_display_mastering_luminance)
1455             {
1456                 error_code = IHEVCE_MAX_DISP_MATERING_LUM_OUT_OF_RANGE;
1457                 ps_sys_api->ihevce_printf(
1458                     pv_cb_handle,
1459                     "IHEVCE ERROR: u4_max_display_mastering_luminance should be greater then "
1460                     "u4_min_display_mastering_luminance \n");
1461                 return (IHEVCE_SETUNSUPPORTEDINPUT(error_code));
1462             }
1463         }
1464     }
1465 
1466     if(1 == ps_static_cfg_prms->s_out_strm_prms.i4_vui_enable)
1467     {
1468         /* validate static vui parameters */
1469         if(((ps_static_cfg_prms->s_vui_sei_prms.u1_aspect_ratio_info_present_flag & 0xFE) > 0))
1470         {
1471             error_code = IHEVC_INVALID_ASPECT_RATIO_PARAMS;
1472             ps_sys_api->ihevce_printf(
1473                 pv_cb_handle, "IHEVCE ERROR: invalid aspect ratio parameters\n");
1474             return (IHEVCE_SETUNSUPPORTEDINPUT(error_code));
1475         }
1476 
1477         if(((ps_static_cfg_prms->s_vui_sei_prms.u1_overscan_info_present_flag & 0xFE) > 0) ||
1478            ((ps_static_cfg_prms->s_vui_sei_prms.u1_overscan_appropriate_flag & 0xFE) > 0))
1479         {
1480             error_code = IHEVC_INVALID_OVERSCAN_PARAMS;
1481             ps_sys_api->ihevce_printf(pv_cb_handle, "IHEVCE ERROR: invalid overscan parameters\n");
1482             return (IHEVCE_SETUNSUPPORTEDINPUT(error_code));
1483         }
1484 
1485         if(((ps_static_cfg_prms->s_vui_sei_prms.u1_video_signal_type_present_flag & 0xFE) > 0) ||
1486            (ps_static_cfg_prms->s_vui_sei_prms.u1_video_format > 5) ||
1487            ((ps_static_cfg_prms->s_vui_sei_prms.u1_video_full_range_flag & 0xFE) > 0))
1488         {
1489             error_code = IHEVC_INVALID_VIDEO_PARAMS;
1490             ps_sys_api->ihevce_printf(
1491                 pv_cb_handle, "IHEVCE ERROR: invalid video signal type parameters\n");
1492             return (IHEVCE_SETUNSUPPORTEDINPUT(error_code));
1493         }
1494 
1495         if(((ps_static_cfg_prms->s_vui_sei_prms.u1_colour_description_present_flag & 0xFE) > 0))
1496         {
1497             error_code = IHEVC_INVALID_COLOUR_PARAMS;
1498             ps_sys_api->ihevce_printf(
1499                 pv_cb_handle, "IHEVCE ERROR: invalid colour description parameters\n");
1500             return (IHEVCE_SETUNSUPPORTEDINPUT(error_code));
1501         }
1502 
1503         if(((ps_static_cfg_prms->s_vui_sei_prms.u1_chroma_loc_info_present_flag & 0xFE) > 0) ||
1504            (ps_static_cfg_prms->s_vui_sei_prms.u1_chroma_sample_loc_type_top_field > 5) ||
1505            (ps_static_cfg_prms->s_vui_sei_prms.u1_chroma_sample_loc_type_bottom_field > 5))
1506         {
1507             error_code = IHEVC_INVALID_CHROMA_PARAMS;
1508             ps_sys_api->ihevce_printf(
1509                 pv_cb_handle, "IHEVCE ERROR: invalid chroma info parameters\n");
1510             return (IHEVCE_SETUNSUPPORTEDINPUT(error_code));
1511         }
1512 
1513         if((ps_static_cfg_prms->s_vui_sei_prms.u1_timing_info_present_flag & 0xFE) > 0)
1514         {
1515             error_code = IHEVC_INVALID_TIMING_INFO_PARAM;
1516             ps_sys_api->ihevce_printf(
1517                 pv_cb_handle, "IHEVCE ERROR: invalid timing info present flag\n");
1518             return (IHEVCE_SETUNSUPPORTEDINPUT(error_code));
1519         }
1520 
1521         if(((ps_static_cfg_prms->s_vui_sei_prms.u1_vui_hrd_parameters_present_flag & 0xFE) > 0) ||
1522            ((ps_static_cfg_prms->s_vui_sei_prms.u1_nal_hrd_parameters_present_flag & 0xFE) > 0))
1523         {
1524             error_code = IHEVC_INVALID_HRD_PRESENT_PARAMS;
1525             ps_sys_api->ihevce_printf(
1526                 pv_cb_handle, "IHEVCE ERROR: invalid vui or vcl hrd parameters present flag\n");
1527             return (IHEVCE_SETUNSUPPORTEDINPUT(error_code));
1528         }
1529     }
1530 
1531     error_code = ihevce_validate_tile_config_params(ps_static_cfg_prms);
1532     if(IHEVCE_SUCCESS != error_code)
1533     {
1534         return error_code;
1535     }
1536 
1537     if(ps_static_cfg_prms->s_slice_params.i4_slice_segment_mode != 0)
1538     {
1539         error_code = IHEVCE_BAD_SLICE_PARAMS;
1540         ps_sys_api->ihevce_printf(
1541             pv_cb_handle, "IHEVCE ERROR: i4_slice_segment_mode should be 0 \n");
1542         return IHEVCE_SETUNSUPPORTEDINPUT(error_code);
1543     }
1544 
1545     return IHEVCE_SUCCESS;
1546 }
1547 
1548 /*!
1549 ******************************************************************************
1550 * \if Function name : ihevce_get_level_index \endif
1551 *
1552 * \brief
1553 *    This function returns the index of level based on codec_level value
1554 *    Please see the LEVEL_T enum def
1555 *
1556 * \param[in] Codec Level
1557 *
1558 * \return
1559 *    Index of Codec level
1560 *
1561 * \author
1562 *    Ittiam
1563 *
1564 *****************************************************************************
1565 */
ihevce_get_level_index(WORD32 i4_codec_level)1566 WORD32 ihevce_get_level_index(WORD32 i4_codec_level)
1567 {
1568     switch(i4_codec_level)
1569     {
1570     case LEVEL1:
1571         return 0;
1572     case LEVEL2:
1573         return 1;
1574     case LEVEL2_1:
1575         return 2;
1576     case LEVEL3:
1577         return 3;
1578     case LEVEL3_1:
1579         return 4;
1580     case LEVEL4:
1581         return 5;
1582     case LEVEL4_1:
1583         return 6;
1584     case LEVEL5:
1585         return 7;
1586     case LEVEL5_1:
1587         return 8;
1588     case LEVEL5_2:
1589         return 9;
1590     case LEVEL6:
1591         return 10;
1592     case LEVEL6_1:
1593         return 11;
1594     case LEVEL6_2:
1595         return 12;
1596     default:
1597         return 0;
1598     }
1599 }
1600