Home | History | Annotate | Download | only in encoder
      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 */
    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 */
    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_rate_factor %d \n", ps_static_cfg_prms->s_config_prms.i4_rate_factor);
    334             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);
    335             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);
    336             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);
    337             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);
    338             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);
    339 
    340             PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "\n");
    341 
    342             PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "\nIHEVCE : ps_static_cfg_prms->s_lap_prms\n");
    343             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);
    344             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);
    345 
    346             PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "\nIHEVCE : ps_static_cfg_prms->s_out_strm_prms\n");
    347             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);
    348             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);
    349             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);
    350             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);
    351             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);
    352             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);
    353             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);
    354             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);
    355             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);
    356             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);
    357             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);
    358             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);
    359             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);
    360             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);
    361             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);
    362             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);
    363             for(i4_i = 0; i4_i < 3; i4_i++)
    364                 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]);
    365             for(i4_i = 0; i4_i < 3; i4_i++)
    366                 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]);
    367             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);
    368             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);
    369             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);
    370             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);
    371             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);
    372 
    373             PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "\nIHEVCE : ps_static_cfg_prms->s_app_tile_params\n");
    374             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);
    375             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);
    376             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);
    377             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);
    378 
    379             for(i4_i = 0; i4_i < ps_static_cfg_prms->s_app_tile_params.i4_num_tile_cols; i4_i++)
    380                 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]);
    381 
    382             for(i4_i = 0; i4_i < ps_static_cfg_prms->s_app_tile_params.i4_num_tile_rows; i4_i++)
    383                 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]);
    384 
    385             PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "\nIHEVCE : ps_static_cfg_prms->s_slice_params\n");
    386             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);
    387             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);
    388 
    389             PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "\nIHEVCE : ps_static_cfg_prms->s_vui_sei_prms\n");
    390             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);
    391 
    392             PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "IHEVCE : u1_aspect_ratio_idc ");
    393             for(i4_resolution_id_loop = 0; i4_resolution_id_loop < i4_num_res_layers; i4_resolution_id_loop++)
    394             {
    395                 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]);
    396             }
    397 
    398             PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "\nIHEVCE : au2_sar_width ");
    399             for(i4_resolution_id_loop = 0; i4_resolution_id_loop < i4_num_res_layers; i4_resolution_id_loop++)
    400             {
    401                 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]);
    402             }
    403             PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "\nIHEVCE : au2_sar_width ");
    404             for(i4_resolution_id_loop = 0; i4_resolution_id_loop < i4_num_res_layers; i4_resolution_id_loop++)
    405             {
    406                 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]);
    407             }
    408             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);
    409             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);
    410             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);
    411             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);
    412             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);
    413             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);
    414             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);
    415             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);
    416             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);
    417             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);
    418             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);
    419             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);
    420             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);
    421             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);
    422             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);
    423         }
    424 
    425         PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "\nIHEVCE : ps_static_cfg_prms \n");
    426         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);
    427         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);
    428         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);
    429 
    430         PRINTF(ps_sys_api->pv_cb_handle, i4_res_id, i4_br_id, "**********************************************\n");
    431     }
    432     // clang-format on
    433 
    434     if(ps_static_cfg_prms->s_multi_thrd_prms.i4_num_proc_groups > MAX_NUMBER_PROC_GRPS)
    435     {
    436         error_code = IHEVCE_UNSUPPORTED_PROC_CONFIG;
    437         ps_sys_api->ihevce_printf(
    438             pv_cb_handle, "IHEVCE ERROR:  Number of Processor Groups not supported \n");
    439         return (IHEVCE_SETUNSUPPORTEDINPUT(error_code));
    440     }
    441 
    442     /* Error check for system-api callback functions */
    443     if(NULL == ps_sys_api->ihevce_printf)
    444     {
    445         error_code = IHEVCE_SYSTEM_APIS_NOT_INITIALLIZED;
    446         return (IHEVCE_SETUNSUPPORTEDINPUT(error_code));
    447     }
    448     if(NULL == ps_sys_api->s_file_io_api.ihevce_fopen)
    449     {
    450         error_code = IHEVCE_SYSTEM_APIS_NOT_INITIALLIZED;
    451         ps_sys_api->ihevce_printf(
    452             pv_cb_handle, "IHEVCE ERROR: ihevce_fopen callback function not initiallized\n");
    453         return (IHEVCE_SETUNSUPPORTEDINPUT(error_code));
    454     }
    455     if(NULL == ps_sys_api->s_file_io_api.ihevce_fclose)
    456     {
    457         error_code = IHEVCE_SYSTEM_APIS_NOT_INITIALLIZED;
    458         ps_sys_api->ihevce_printf(
    459             pv_cb_handle, "IHEVCE ERROR: ihevce_fclose callback function not initiallized\n");
    460         return (IHEVCE_SETUNSUPPORTEDINPUT(error_code));
    461     }
    462     if(NULL == ps_sys_api->s_file_io_api.ihevce_fflush)
    463     {
    464         error_code = IHEVCE_SYSTEM_APIS_NOT_INITIALLIZED;
    465         ps_sys_api->ihevce_printf(
    466             pv_cb_handle, "IHEVCE ERROR: ihevce_fflush callback function not initiallized\n");
    467         return (IHEVCE_SETUNSUPPORTEDINPUT(error_code));
    468     }
    469     if(NULL == ps_sys_api->s_file_io_api.ihevce_fseek)
    470     {
    471         error_code = IHEVCE_SYSTEM_APIS_NOT_INITIALLIZED;
    472         ps_sys_api->ihevce_printf(
    473             pv_cb_handle, "IHEVCE ERROR: ihevce_fseek callback function not initiallized\n");
    474         return (IHEVCE_SETUNSUPPORTEDINPUT(error_code));
    475     }
    476     if(NULL == ps_sys_api->s_file_io_api.ihevce_fread)
    477     {
    478         error_code = IHEVCE_SYSTEM_APIS_NOT_INITIALLIZED;
    479         ps_sys_api->ihevce_printf(
    480             pv_cb_handle, "IHEVCE ERROR: ihevce_fread callback function not initiallized\n");
    481         return (IHEVCE_SETUNSUPPORTEDINPUT(error_code));
    482     }
    483     if(NULL == ps_sys_api->s_file_io_api.ihevce_fscanf)
    484     {
    485         error_code = IHEVCE_SYSTEM_APIS_NOT_INITIALLIZED;
    486         ps_sys_api->ihevce_printf(
    487             pv_cb_handle, "IHEVCE ERROR: ihevce_fscanf callback function not initiallized\n");
    488         return (IHEVCE_SETUNSUPPORTEDINPUT(error_code));
    489     }
    490     if(NULL == ps_sys_api->ihevce_sscanf)
    491     {
    492         error_code = IHEVCE_SYSTEM_APIS_NOT_INITIALLIZED;
    493         ps_sys_api->ihevce_printf(
    494             pv_cb_handle, "IHEVCE ERROR: ihevce_sscanf callback function not initiallized\n");
    495         return (IHEVCE_SETUNSUPPORTEDINPUT(error_code));
    496     }
    497     if(NULL == ps_sys_api->s_file_io_api.ihevce_fprintf)
    498     {
    499         error_code = IHEVCE_SYSTEM_APIS_NOT_INITIALLIZED;
    500         ps_sys_api->ihevce_printf(
    501             pv_cb_handle, "IHEVCE ERROR: ihevce_fprintf callback function not initiallized\n");
    502         return (IHEVCE_SETUNSUPPORTEDINPUT(error_code));
    503     }
    504     if(NULL == ps_sys_api->s_file_io_api.ihevce_fwrite)
    505     {
    506         error_code = IHEVCE_SYSTEM_APIS_NOT_INITIALLIZED;
    507         ps_sys_api->ihevce_printf(
    508             pv_cb_handle, "IHEVCE ERROR: ihevce_fwrite callback function not initiallized\n");
    509         return (IHEVCE_SETUNSUPPORTEDINPUT(error_code));
    510     }
    511     if(NULL == ps_sys_api->ihevce_sprintf)
    512     {
    513         error_code = IHEVCE_SYSTEM_APIS_NOT_INITIALLIZED;
    514         ps_sys_api->ihevce_printf(
    515             pv_cb_handle, "IHEVCE ERROR: ihevce_sprintf callback function not initiallized\n");
    516         return (IHEVCE_SETUNSUPPORTEDINPUT(error_code));
    517     }
    518 
    519     /* Error check for static source parameters */
    520     if((ps_static_cfg_prms->s_src_prms.i4_orig_width > HEVCE_MAX_WIDTH) ||
    521        (ps_static_cfg_prms->s_src_prms.i4_orig_width < 2))
    522     {
    523         error_code = IHEVCE_WIDTH_NOT_SUPPORTED;
    524         ps_sys_api->ihevce_printf(pv_cb_handle, "IHEVCE ERROR:  i4_src_width out of range \n");
    525         return (IHEVCE_SETUNSUPPORTEDINPUT(error_code));
    526     }
    527 
    528     if((ps_static_cfg_prms->s_src_prms.i4_orig_height > HEVCE_MAX_HEIGHT) ||
    529        (ps_static_cfg_prms->s_src_prms.i4_orig_height < 2))
    530     {
    531         error_code = IHEVCE_HEIGHT_NOT_SUPPORTED;
    532         ps_sys_api->ihevce_printf(pv_cb_handle, "IHEVCE ERROR:  i4_src_height out of range \n");
    533         return (IHEVCE_SETUNSUPPORTEDINPUT(error_code));
    534     }
    535     /*check for odd resolution*/
    536     if(0 != (ps_static_cfg_prms->s_src_prms.i4_width & 1))
    537     {
    538         error_code = IHEVCE_WIDTH_NOT_SUPPORTED;
    539         ps_sys_api->ihevce_printf(pv_cb_handle, "IHEVCE ERROR:  i4_src_width not supported \n");
    540         return (IHEVCE_SETUNSUPPORTEDINPUT(error_code));
    541     }
    542     if(0 != (ps_static_cfg_prms->s_src_prms.i4_height & 1))
    543     {
    544         error_code = IHEVCE_HEIGHT_NOT_SUPPORTED;
    545         ps_sys_api->ihevce_printf(pv_cb_handle, "IHEVCE ERROR:  i4_src_height not supported \n");
    546         return (IHEVCE_SETUNSUPPORTEDINPUT(error_code));
    547     }
    548 
    549     if((ps_static_cfg_prms->s_src_prms.i4_frm_rate_denom != 1000) &&
    550        (ps_static_cfg_prms->s_src_prms.i4_frm_rate_denom != 1001))
    551     {
    552         error_code = IHEVCE_FRAME_RATE_NOT_SUPPORTED;
    553         ps_sys_api->ihevce_printf(pv_cb_handle, "IHEVCE ERROR: frame rate denom not supported \n");
    554         return IHEVCE_SETUNSUPPORTEDINPUT(error_code);
    555     }
    556 
    557     if((((ps_static_cfg_prms->s_src_prms.i4_frm_rate_num * 1.0) /
    558           ps_static_cfg_prms->s_src_prms.i4_frm_rate_denom) > MAX_FRAME_RATE) ||
    559        (((ps_static_cfg_prms->s_src_prms.i4_frm_rate_num * 1.0) /
    560           ps_static_cfg_prms->s_src_prms.i4_frm_rate_denom) < MIN_FRAME_RATE))
    561     {
    562         error_code = IHEVCE_FRAME_RATE_NOT_SUPPORTED;
    563         ps_sys_api->ihevce_printf(
    564             pv_cb_handle,
    565             "IHEVCE ERROR: Frame rate (%d / %d) is out of range [%.1f - %.1f]\n",
    566             ps_static_cfg_prms->s_src_prms.i4_frm_rate_num,
    567             ps_static_cfg_prms->s_src_prms.i4_frm_rate_denom,
    568             MIN_FRAME_RATE, MAX_FRAME_RATE);
    569         return IHEVCE_SETUNSUPPORTEDINPUT(error_code);
    570     }
    571 
    572     if(ps_static_cfg_prms->s_src_prms.i4_field_pic != 0)
    573     {
    574         error_code = IHEVCE_CONTENT_TYPE_NOT_SUPPORTED;
    575         ps_sys_api->ihevce_printf(pv_cb_handle, "IHEVCE ERROR: Field encoding not supported \n");
    576         return IHEVCE_SETUNSUPPORTEDINPUT(error_code);
    577     }
    578 
    579     if(ps_static_cfg_prms->s_src_prms.inp_chr_format != IV_YUV_420SP_UV &&
    580        ps_static_cfg_prms->s_src_prms.inp_chr_format != IV_YUV_420P)
    581     {
    582         error_code = IHEVCE_CHROMA_FORMAT_NOT_SUPPORTED;
    583         ps_sys_api->ihevce_printf(pv_cb_handle, "IHEVCE ERROR: i4_input_chroma_format Invalid \n");
    584         return IHEVCE_SETUNSUPPORTEDINPUT(error_code);
    585     }
    586 
    587     if(ps_static_cfg_prms->s_src_prms.i4_chr_format != IV_YUV_420SP_UV)
    588     {
    589         error_code = IHEVCE_CHROMA_FORMAT_NOT_SUPPORTED;
    590         ps_sys_api->ihevce_printf(
    591             pv_cb_handle, "IHEVCE ERROR: i4_internal_chroma_format Invalid \n");
    592         return IHEVCE_SETUNSUPPORTEDINPUT(error_code);
    593     }
    594 
    595     /* Check error for interoperability flags */
    596     if(ps_static_cfg_prms->s_out_strm_prms.i4_interop_flags != 0)
    597     {
    598         error_code = IHEVCE_INTEROPERABILITY_FLAG_SUPPORTED;
    599         ps_sys_api->ihevce_printf(
    600             pv_cb_handle, "IHEVCE ERROR: i4_interop_flags out of range, to be set to 0\n");
    601         return (IHEVCE_SETUNSUPPORTEDINPUT(error_code));
    602     }
    603 
    604     /* Error check for static output stream parameters  */
    605     if(ps_static_cfg_prms->s_out_strm_prms.i4_codec_type != 0)
    606     {
    607         error_code = IHEVCE_CODEC_NOT_SUPPORTED;
    608         ps_sys_api->ihevce_printf(
    609             pv_cb_handle, "IHEVCE ERROR: i4_codec_type should be set to 0 \n");
    610         return IHEVCE_SETUNSUPPORTEDINPUT(error_code);
    611     }
    612 
    613     if(ps_static_cfg_prms->s_out_strm_prms.i4_codec_profile != 1)
    614     {
    615         error_code = IHEVCE_CODEC_PROFILE_NOT_SUPPORTED;
    616         ps_sys_api->ihevce_printf(
    617             pv_cb_handle, "IHEVCE ERROR: i4_codec_profile should be set to 1 \n");
    618         return IHEVCE_SETUNSUPPORTEDINPUT(error_code);
    619     }
    620 
    621     if(ps_static_cfg_prms->s_tgt_lyr_prms.i4_internal_bit_depth != 8)
    622     {
    623         error_code = IHEVCE_OUTPUT_BIT_DEPTH_OUT_OF_RANGE;
    624         ps_sys_api->ihevce_printf(
    625             pv_cb_handle,
    626             "IHEVCE ERROR: (output_bit_depth = %d) not supported \n",
    627             ps_static_cfg_prms->s_tgt_lyr_prms.i4_internal_bit_depth);
    628         return IHEVCE_SETUNSUPPORTEDINPUT(error_code);
    629     }
    630 
    631     if(ps_static_cfg_prms->s_src_prms.i4_input_bit_depth != 8)
    632     {
    633         error_code = IHEVCE_INPUT_BIT_DEPTH_OUT_OF_RANGE;
    634         ps_sys_api->ihevce_printf(
    635             pv_cb_handle, "IHEVCE ERROR: i4_input_bit_depth value not supported \n");
    636         return IHEVCE_SETUNSUPPORTEDINPUT(error_code);
    637     }
    638 
    639     if((ps_static_cfg_prms->s_out_strm_prms.i4_vui_enable > 1) ||
    640        (ps_static_cfg_prms->s_out_strm_prms.i4_vui_enable < 0))
    641     {
    642         error_code = IHEVCE_VUI_ENABLE_OUT_OF_RANGE;
    643         ps_sys_api->ihevce_printf(
    644             pv_cb_handle, "IHEVCE ERROR: i4_vui_enable should be set to 1 or 0 \n");
    645         return IHEVCE_SETUNSUPPORTEDINPUT(error_code);
    646     }
    647 
    648     if((ps_static_cfg_prms->s_out_strm_prms.i4_sei_enable_flag > 1) ||
    649        (ps_static_cfg_prms->s_out_strm_prms.i4_sei_enable_flag < 0))
    650     {
    651         error_code = IHEVCE_SEI_ENABLE_OUT_OF_RANGE;
    652         ps_sys_api->ihevce_printf(
    653             pv_cb_handle, "IHEVCE ERROR: i4_sei_enable_flags should be set to 1 or 0 \n");
    654         return IHEVCE_SETUNSUPPORTEDINPUT(error_code);
    655     }
    656 
    657     if((ps_static_cfg_prms->s_out_strm_prms.i4_sei_payload_enable_flag > 1) ||
    658        (ps_static_cfg_prms->s_out_strm_prms.i4_sei_payload_enable_flag < 0))
    659     {
    660         error_code = IHEVCE_SEI_PAYLOAD_ENABLE_OUT_OF_RANGE;
    661         ps_sys_api->ihevce_printf(
    662             pv_cb_handle, "IHEVCE ERROR: i4_sei_payload_enable_flag should be set to 1 or 0 \n");
    663         return IHEVCE_SETUNSUPPORTEDINPUT(error_code);
    664     }
    665     if((ps_static_cfg_prms->s_multi_thrd_prms.i4_max_num_cores > MAX_NUM_CORES) ||
    666        (ps_static_cfg_prms->s_multi_thrd_prms.i4_max_num_cores < 1))
    667     {
    668         error_code = IHEVCE_INVALID_CORE_CONFIG;
    669         ps_sys_api->ihevce_printf(
    670             pv_cb_handle, "IHEVCE ERROR: Invalid Number of Cores configured\n");
    671         return IHEVCE_SETUNSUPPORTEDINPUT(error_code);
    672     }
    673 
    674     if((ps_static_cfg_prms->e_arch_type != ARCH_NA) &&
    675        (ps_static_cfg_prms->e_arch_type != ARCH_ARM_NONEON))
    676     {
    677         error_code = IHEVCE_ARCHITECTURE_TYPE_UNSUPPORTED;
    678         ps_sys_api->ihevce_printf(pv_cb_handle, "IHEVCE ERROR: unsupported archType \n");
    679         return IHEVCE_SETUNSUPPORTEDINPUT(error_code);
    680     }
    681 
    682     if(ps_static_cfg_prms->s_coding_tools_prms.i4_vqet != 0)
    683     {
    684         error_code = IHEVCE_VISUAL_QUALITY_ENHANCEMENTS_TOGGLER_VALUE_UNSUPPORTED;
    685         ps_sys_api->ihevce_printf(
    686             pv_cb_handle,
    687             "IHEVCE ERROR: visual_quality_enhancements_toggler should be set to 0 \n");
    688         return IHEVCE_SETUNSUPPORTEDINPUT(error_code);
    689     }
    690 
    691     if(ps_static_cfg_prms->s_coding_tools_prms.i4_max_temporal_layers < 0 ||
    692        ps_static_cfg_prms->s_coding_tools_prms.i4_max_temporal_layers > 3)
    693     {
    694         error_code = IHEVCE_TEMPORAL_LAYERS_NOT_SUPPORTED;
    695         ps_sys_api->ihevce_printf(
    696             pv_cb_handle, "IHEVCE ERROR: i4_max_temporal_layers out of range \n");
    697         return IHEVCE_SETUNSUPPORTEDINPUT(error_code);
    698     }
    699 
    700     if((ps_static_cfg_prms->s_coding_tools_prms.i4_max_closed_gop_period < 0) ||
    701        (ps_static_cfg_prms->s_coding_tools_prms.i4_max_cra_open_gop_period < 0) ||
    702        (ps_static_cfg_prms->s_coding_tools_prms.i4_max_i_open_gop_period < 0))
    703     {
    704         error_code = IHEVCE_INVALID_GOP_PERIOD;
    705         ps_sys_api->ihevce_printf(
    706             pv_cb_handle,
    707             "IHEVCE ERROR: gop period is not valid for the configured temporal layers\n");
    708         return IHEVCE_SETUNSUPPORTEDINPUT(error_code);
    709     }
    710 
    711     {
    712         WORD32 sub_gop_size = (1 << ps_static_cfg_prms->s_coding_tools_prms.i4_max_temporal_layers)
    713                               << ps_static_cfg_prms->s_src_prms.i4_field_pic;
    714         WORD32 i4_max_idr_period, i4_min_idr_period, i4_max_cra_period, i4_max_i_period;
    715         WORD32 i4_max_i_distance;
    716         WORD32 i4_min_i_distance = 0, i4_non_zero_idr_period = 0x7FFFFFFF,
    717                i4_non_zero_cra_period = 0x7FFFFFFF, i4_non_zero_i_period = 0x7FFFFFFF;
    718         i4_max_idr_period = ps_static_cfg_prms->s_coding_tools_prms.i4_max_closed_gop_period;
    719         i4_min_idr_period = ps_static_cfg_prms->s_coding_tools_prms.i4_min_closed_gop_period;
    720         i4_max_cra_period = ps_static_cfg_prms->s_coding_tools_prms.i4_max_cra_open_gop_period;
    721         i4_max_i_period = ps_static_cfg_prms->s_coding_tools_prms.i4_max_i_open_gop_period;
    722         i4_max_i_distance = MAX(MAX(i4_max_idr_period, i4_max_cra_period), i4_max_i_period);
    723 
    724         if(sub_gop_size > 1)
    725         {
    726             switch(sub_gop_size)
    727             {
    728             case 2:
    729                 ps_static_cfg_prms->s_coding_tools_prms.i4_max_closed_gop_period =
    730                     ALIGN2(i4_max_idr_period);
    731 
    732                 if(i4_max_idr_period > 1)
    733                     ps_static_cfg_prms->s_coding_tools_prms.i4_max_closed_gop_period =
    734                         ps_static_cfg_prms->s_coding_tools_prms.i4_max_closed_gop_period + 1;
    735 
    736                 ps_static_cfg_prms->s_coding_tools_prms.i4_max_cra_open_gop_period =
    737                     ALIGN2(i4_max_cra_period);
    738                 ps_static_cfg_prms->s_coding_tools_prms.i4_max_i_open_gop_period =
    739                     ALIGN2(i4_max_i_period);
    740                 break;
    741             case 4:
    742                 ps_static_cfg_prms->s_coding_tools_prms.i4_max_closed_gop_period =
    743                     ALIGN4(i4_max_idr_period);
    744 
    745                 if(i4_max_idr_period > 1)
    746                     ps_static_cfg_prms->s_coding_tools_prms.i4_max_closed_gop_period =
    747                         ps_static_cfg_prms->s_coding_tools_prms.i4_max_closed_gop_period + 1;
    748 
    749                 ps_static_cfg_prms->s_coding_tools_prms.i4_max_cra_open_gop_period =
    750                     ALIGN4(i4_max_cra_period);
    751                 ps_static_cfg_prms->s_coding_tools_prms.i4_max_i_open_gop_period =
    752                     ALIGN4(i4_max_i_period);
    753                 break;
    754             case 8:
    755                 ps_static_cfg_prms->s_coding_tools_prms.i4_max_closed_gop_period =
    756                     ALIGN8(i4_max_idr_period);
    757 
    758                 if(i4_max_idr_period > 1)
    759                     ps_static_cfg_prms->s_coding_tools_prms.i4_max_closed_gop_period =
    760                         ps_static_cfg_prms->s_coding_tools_prms.i4_max_closed_gop_period + 1;
    761 
    762                 ps_static_cfg_prms->s_coding_tools_prms.i4_max_cra_open_gop_period =
    763                     ALIGN8(i4_max_cra_period);
    764                 ps_static_cfg_prms->s_coding_tools_prms.i4_max_i_open_gop_period =
    765                     ALIGN8(i4_max_i_period);
    766                 break;
    767             }
    768         }
    769 
    770         if(0 != i4_max_idr_period)
    771         {
    772             i4_non_zero_idr_period = i4_max_idr_period;
    773         }
    774         if(0 != i4_max_cra_period)
    775         {
    776             i4_non_zero_cra_period = i4_max_cra_period;
    777         }
    778         if(0 != i4_max_i_period)
    779         {
    780             i4_non_zero_i_period = i4_max_i_period;
    781         }
    782         i4_min_i_distance =
    783             MIN(MIN(i4_non_zero_idr_period, i4_non_zero_cra_period), i4_non_zero_i_period);
    784         if(i4_min_i_distance < sub_gop_size && i4_min_i_distance)
    785         {
    786             error_code = IHEVCE_INVALID_GOP_PERIOD;
    787             ps_sys_api->ihevce_printf(
    788                 pv_cb_handle,
    789                 "IHEVCE ERROR: gop period is not valid for the configured temporal layers\n");
    790             return IHEVCE_SETUNSUPPORTEDINPUT(error_code);
    791         }
    792 
    793         if((i4_min_idr_period > i4_max_idr_period) || (i4_min_idr_period < 0))
    794         {
    795             error_code = IHEVCE_INVALID_GOP_PERIOD;
    796             ps_sys_api->ihevce_printf(
    797                 pv_cb_handle,
    798                 "IHEVCE ERROR: gop period is not valid => min closed gop > max closed gop\n");
    799             return IHEVCE_SETUNSUPPORTEDINPUT(error_code);
    800         }
    801         if(ps_static_cfg_prms->s_coding_tools_prms.i4_max_temporal_layers && i4_max_i_distance == 1)
    802         {
    803             error_code = IHEVCE_TEMPORAL_LAYERS_NOT_SUPPORTED;
    804             ps_sys_api->ihevce_printf(
    805                 pv_cb_handle, "IHEVCE ERROR: Invalid max temporal layer for I only encoding\n");
    806             return IHEVCE_SETUNSUPPORTEDINPUT(error_code);
    807         }
    808         if((i4_max_idr_period < i4_max_cra_period || i4_max_idr_period < i4_max_i_period) &&
    809            i4_max_idr_period)
    810         {
    811             error_code = IHEVCE_INVALID_GOP_PERIOD;
    812             ps_sys_api->ihevce_printf(
    813                 pv_cb_handle,
    814                 "IHEVCE ERROR: MAX IDR period can't be less than Max CRA or I period\n");
    815             return IHEVCE_SETUNSUPPORTEDINPUT(error_code);
    816         }
    817         if((i4_max_cra_period < i4_max_i_period) && i4_max_cra_period)
    818         {
    819             error_code = IHEVCE_INVALID_GOP_PERIOD;
    820             ps_sys_api->ihevce_printf(
    821                 pv_cb_handle, "IHEVCE ERROR: MAX CRA period can't be less than Max I period\n");
    822             return IHEVCE_SETUNSUPPORTEDINPUT(error_code);
    823         }
    824     }
    825     if(0 != ps_static_cfg_prms->s_tgt_lyr_prms.i4_enable_temporal_scalability)
    826     {
    827         error_code = IHEVCE_INVALID_TEMPORAL_SCALABILITY;
    828         ps_sys_api->ihevce_printf(
    829             pv_cb_handle, "IHEVCE ERROR: Temporal scalability is not supported \n");
    830         return IHEVCE_SETUNSUPPORTEDINPUT(error_code);
    831     }
    832 
    833     if(ps_static_cfg_prms->s_coding_tools_prms.i4_max_reference_frames != -1)
    834     {
    835         error_code = IHEVCE_REF_FRAMES_NOT_SUPPORTED;
    836         ps_sys_api->ihevce_printf(
    837             pv_cb_handle, "IHEVCE ERROR: only supported value for i4_max_reference_frames is -1\n");
    838         return IHEVCE_SETUNSUPPORTEDINPUT(error_code);
    839     }
    840 
    841     if(ps_static_cfg_prms->s_coding_tools_prms.i4_weighted_pred_enable != 0 &&
    842        ps_static_cfg_prms->s_coding_tools_prms.i4_weighted_pred_enable != 1)
    843     {
    844         error_code = IHEVCE_INVALID_WEIGHTED_PREDICTION_INPUT;
    845         ps_sys_api->ihevce_printf(pv_cb_handle, "IHEVCE ERROR: i4_weighted_pred_enable invalid \n");
    846         return IHEVCE_SETUNSUPPORTEDINPUT(error_code);
    847     }
    848 
    849     if(ps_static_cfg_prms->s_coding_tools_prms.i4_deblocking_type != 0 &&
    850        ps_static_cfg_prms->s_coding_tools_prms.i4_deblocking_type != 1 &&
    851        ps_static_cfg_prms->s_coding_tools_prms.i4_deblocking_type != 2)
    852     {
    853         error_code = IHEVCE_INVALID_DEBLOCKING_TYPE_INPUT;
    854         ps_sys_api->ihevce_printf(pv_cb_handle, "IHEVCE ERROR: i4_deblocking_type invalid\n");
    855         return IHEVCE_SETUNSUPPORTEDINPUT(error_code);
    856     }
    857 
    858     if(ps_static_cfg_prms->s_coding_tools_prms.i4_use_default_sc_mtx != 0 &&
    859        ps_static_cfg_prms->s_coding_tools_prms.i4_use_default_sc_mtx != 1)
    860     {
    861         error_code = IHEVCE_INVALID_DEFAULT_SC_MATRIX_ENABLE_INPUT;
    862         ps_sys_api->ihevce_printf(pv_cb_handle, "IHEVCE ERROR: i4_use_default_sc_mtx invalid \n");
    863         return IHEVCE_SETUNSUPPORTEDINPUT(error_code);
    864     }
    865 
    866     if(ps_static_cfg_prms->s_coding_tools_prms.i4_cropping_mode != 0 &&
    867        ps_static_cfg_prms->s_coding_tools_prms.i4_cropping_mode != 1)
    868     {
    869         error_code = IHEVCE_INVALID_CROPPING_MODE;
    870         ps_sys_api->ihevce_printf(pv_cb_handle, "IHEVCE ERROR: i4_cropping_mode invalid \n");
    871         return IHEVCE_SETUNSUPPORTEDINPUT(error_code);
    872     }
    873 
    874     /* Error checks for Static Config Parameters */
    875     if(ps_static_cfg_prms->s_config_prms.i4_min_log2_cu_size != 3)
    876     {
    877         error_code = IHEVCE_MIN_CU_SIZE_INPUT_NOT_SUPPORTED;
    878         ps_sys_api->ihevce_printf(pv_cb_handle, "IHEVCE ERROR: i4_min_log2_cu_size invalid \n");
    879         return IHEVCE_SETUNSUPPORTEDINPUT(error_code);
    880     }
    881 
    882     if(ps_static_cfg_prms->s_config_prms.i4_min_log2_tu_size != 2)
    883     {
    884         error_code = IHEVCE_MIN_TU_SIZE_INPUT_NOT_SUPPORTED;
    885         ps_sys_api->ihevce_printf(pv_cb_handle, "IHEVCE ERROR: i4_min_log2_tu_size invalid \n");
    886         return IHEVCE_SETUNSUPPORTEDINPUT(error_code);
    887     }
    888 
    889     if(ps_static_cfg_prms->s_config_prms.i4_max_log2_cu_size < 4 ||
    890        ps_static_cfg_prms->s_config_prms.i4_max_log2_cu_size > 6)
    891     {
    892         error_code = IHEVCE_MAX_CU_SIZE_INPUT_NOT_SUPPORTED;
    893         ps_sys_api->ihevce_printf(pv_cb_handle, "IHEVCE ERROR: i4_max_log2_cu_size invalid \n");
    894         return IHEVCE_SETUNSUPPORTEDINPUT(error_code);
    895     }
    896 
    897     if(ps_static_cfg_prms->s_config_prms.i4_max_log2_tu_size < 2 ||
    898        ps_static_cfg_prms->s_config_prms.i4_max_log2_tu_size > 5)
    899     {
    900         error_code = IHEVCE_MAX_TU_SIZE_INPUT_NOT_SUPPORTED;
    901         ps_sys_api->ihevce_printf(pv_cb_handle, "IHEVCE ERROR: i4_max_log2_tu_size invalid \n");
    902         return IHEVCE_SETUNSUPPORTEDINPUT(error_code);
    903     }
    904 
    905     if(ps_static_cfg_prms->s_config_prms.i4_min_log2_cu_size == 4 &&
    906        ps_static_cfg_prms->s_config_prms.i4_max_log2_tu_size == 5)
    907     {
    908         /* Because tu size should always be lesser than the cu size */
    909         error_code = IHEVCE_INVALID_MAX_TU_SIZE;
    910         ps_sys_api->ihevce_printf(
    911             pv_cb_handle,
    912             "IHEVCE ERROR: Invalid combination of i4_min_log2_cu_size and i4_max_log2_tu_size\n");
    913         return IHEVCE_SETUNSUPPORTEDINPUT(error_code);
    914     }
    915 
    916     if(ps_static_cfg_prms->s_config_prms.i4_max_tr_tree_depth_I < 1 ||
    917        ps_static_cfg_prms->s_config_prms.i4_max_tr_tree_depth_I > 3)
    918     {
    919         error_code = IHEVCE_INVALID_TR_TREE_DEPTH_FOR_I_FRAME;
    920         ps_sys_api->ihevce_printf(
    921             pv_cb_handle, "IHEVCE ERROR: i4_max_tr_tree_depth_I out of range\n");
    922         return IHEVCE_SETUNSUPPORTEDINPUT(error_code);
    923     }
    924 
    925     if(ps_static_cfg_prms->s_config_prms.i4_max_tr_tree_depth_nI < 1 ||
    926        ps_static_cfg_prms->s_config_prms.i4_max_tr_tree_depth_nI > 4)
    927     {
    928         error_code = IHEVCE_INVALID_TR_TREE_DEPTH;
    929         ps_sys_api->ihevce_printf(
    930             pv_cb_handle, "IHEVCE ERROR: i4_max_tr_tree_depth_nI out of range\n");
    931         return IHEVCE_SETUNSUPPORTEDINPUT(error_code);
    932     }
    933 
    934     if(ps_static_cfg_prms->s_config_prms.i4_max_search_range_horz < 64 ||
    935        ps_static_cfg_prms->s_config_prms.i4_max_search_range_horz > 512)
    936     {
    937         error_code = IHEVCE_UNSUPPORTED_HORIZONTAL_SEARCH_RANGE;
    938         ps_sys_api->ihevce_printf(
    939             pv_cb_handle, "IHEVCE ERROR: i4_max_search_range_horz out of range\n");
    940         return IHEVCE_SETUNSUPPORTEDINPUT(error_code);
    941     }
    942 
    943     if(ps_static_cfg_prms->s_config_prms.i4_max_search_range_vert < 32 ||
    944        ps_static_cfg_prms->s_config_prms.i4_max_search_range_vert > 256)
    945     {
    946         error_code = IHEVCE_UNSUPPORTED_VERTICAL_SEARCH_RANGE;
    947         ps_sys_api->ihevce_printf(
    948             pv_cb_handle, "IHEVCE ERROR: i4_max_search_range_vert out of range\n");
    949         return IHEVCE_SETUNSUPPORTEDINPUT(error_code);
    950     }
    951 
    952     if(ps_static_cfg_prms->s_lap_prms.i4_rc_look_ahead_pics > NUM_LAP2_LOOK_AHEAD ||
    953        ps_static_cfg_prms->s_lap_prms.i4_rc_look_ahead_pics < 0)
    954     {
    955         error_code = IHEVCE_UNSUPPORTED_LOOK_AHEAD;
    956         ps_sys_api->ihevce_printf(
    957             pv_cb_handle,
    958             "IHEVCE ERROR: rc look ahead pc must be in range of 0 to NUM_LAP2_LOOK_AHEAD\n");
    959         return IHEVCE_SETUNSUPPORTEDINPUT(error_code);
    960     }
    961 
    962     /* Num res instances should be less than equal to IHEVCE_MAX_NUM_RESOLUTIONS */
    963     if((i4_num_resolutions < 1) || (i4_num_resolutions > IHEVCE_MAX_NUM_RESOLUTIONS))
    964     {
    965         error_code = IHEVCE_NUM_MAX_RESOLUTIONS_NOT_SUPPORTED;
    966         ps_sys_api->ihevce_printf(pv_cb_handle, "IHEVCE ERROR: invalid i4_num_resolutions \n");
    967         return (IHEVCE_SETUNSUPPORTEDINPUT(error_code));
    968     }
    969 
    970     if((ps_static_cfg_prms->i4_res_id < 0) || (ps_static_cfg_prms->i4_res_id >= i4_num_resolutions))
    971     {
    972         error_code = IHEVCE_NUM_MAX_RESOLUTIONS_NOT_SUPPORTED;
    973         ps_sys_api->ihevce_printf(pv_cb_handle, "IHEVCE ERROR: invalid i4_num_resolutions \n");
    974         return (IHEVCE_SETUNSUPPORTEDINPUT(error_code));
    975     }
    976 
    977     if((ps_static_cfg_prms->s_tgt_lyr_prms.i4_mres_single_out < 0) ||
    978        (ps_static_cfg_prms->s_tgt_lyr_prms.i4_mres_single_out > 1))
    979     {
    980         error_code = IHEVCE_INVALID_MRES_SINGLE_OUT;
    981         ps_sys_api->ihevce_printf(
    982             pv_cb_handle, "IHEVCE ERROR: invalid i4_mres_single_out value \n");
    983         return (IHEVCE_SETUNSUPPORTEDINPUT(error_code));
    984     }
    985 
    986     if((ps_static_cfg_prms->i4_save_recon) &&
    987        (1 == ps_static_cfg_prms->s_tgt_lyr_prms.i4_mres_single_out))
    988     {
    989         ps_sys_api->ihevce_printf(
    990             pv_cb_handle,
    991             "IHEVCE WARNING: i4_save_recon not supported for mres single out case \n");
    992         ps_static_cfg_prms->i4_save_recon = 0;
    993     }
    994 
    995     if((1 == i4_num_resolutions) && (1 == ps_static_cfg_prms->s_tgt_lyr_prms.i4_mres_single_out))
    996     {
    997         ps_sys_api->ihevce_printf(
    998             pv_cb_handle,
    999             "IHEVCE WARNING: i4_mres_single_out value changed to 0 for single resolution case \n");
   1000         ps_static_cfg_prms->s_tgt_lyr_prms.i4_mres_single_out = 0;
   1001     }
   1002 
   1003     if(ps_static_cfg_prms->s_tgt_lyr_prms.i4_mbr_quality_setting < 0 ||
   1004        ps_static_cfg_prms->s_tgt_lyr_prms.i4_mbr_quality_setting > 3)
   1005     {
   1006         error_code = IHEVCE_INVALID_MBR_QUALITY_SETTING;
   1007         ps_sys_api->ihevce_printf(pv_cb_handle, "IHEVCE ERROR: invalid mbr quality setting\n");
   1008         return (IHEVCE_SETUNSUPPORTEDINPUT(error_code));
   1009     }
   1010 
   1011     if(ps_static_cfg_prms->s_tgt_lyr_prms.i4_multi_res_layer_reuse != 0)
   1012     {
   1013         error_code = IHEVCE_MULTI_RES_LAYER_REUSE_NOT_SUPPORTED;
   1014         ps_sys_api->ihevce_printf(
   1015             pv_cb_handle,
   1016             "IHEVCE ERROR: reuse of info across resolution is not currently supported \n");
   1017         return IHEVCE_SETUNSUPPORTEDINPUT(error_code);
   1018     }
   1019 
   1020     for(i4_resolution_id = 0; i4_resolution_id < i4_num_resolutions; i4_resolution_id++)
   1021     {
   1022         WORD32 codec_level_index, quality_preset, height, width, frm_rate_scale_factor;
   1023         WORD32 br_ctr;
   1024         UWORD32 u4_luma_sample_rate;
   1025         WORD32 max_dpb_size;
   1026         WORD32 i4_field_pic = ps_static_cfg_prms->s_src_prms.i4_field_pic;
   1027 
   1028         codec_level_index = ihevce_get_level_index(
   1029             ps_static_cfg_prms->s_tgt_lyr_prms.as_tgt_params[i4_resolution_id].i4_codec_level);
   1030         quality_preset =
   1031             ps_static_cfg_prms->s_tgt_lyr_prms.as_tgt_params[i4_resolution_id].i4_quality_preset;
   1032         height = ps_static_cfg_prms->s_tgt_lyr_prms.as_tgt_params[i4_resolution_id].i4_height;
   1033         width = ps_static_cfg_prms->s_tgt_lyr_prms.as_tgt_params[i4_resolution_id].i4_width;
   1034         frm_rate_scale_factor = ps_static_cfg_prms->s_tgt_lyr_prms.as_tgt_params[i4_resolution_id]
   1035                                     .i4_frm_rate_scale_factor;
   1036         /* Check error for max picture size(luma) for the given level */
   1037         if((width * height) > g_as_level_data[codec_level_index].i4_max_luma_picture_size)
   1038         {
   1039             error_code = IHEVCE_PIC_SIZE_NOT_SUPPORTED;
   1040             ps_sys_api->ihevce_printf(
   1041                 pv_cb_handle,
   1042                 "IHEVCE ERROR: (i4_tgt_width * i4_tgt_height) out of range for resolution number "
   1043                 "'%d' codec level %d "
   1044                 "\n",
   1045                 i4_resolution_id,
   1046                 codec_level_index);
   1047             return (IHEVCE_SETUNSUPPORTEDINPUT(error_code));
   1048         }
   1049 
   1050         if((width * height) <= (g_as_level_data[codec_level_index].i4_max_luma_picture_size >> 2))
   1051         {
   1052             max_dpb_size = 16;
   1053         }
   1054         else if((width * height) <= (g_as_level_data[codec_level_index].i4_max_luma_picture_size >> 1))
   1055         {
   1056             max_dpb_size = 12;
   1057         }
   1058         else if(
   1059             (width * height) <=
   1060             (3 * g_as_level_data[codec_level_index].i4_max_luma_picture_size >> 2))
   1061         {
   1062             max_dpb_size = 8;
   1063         }
   1064         else
   1065         {
   1066             max_dpb_size = 6;
   1067         }
   1068 
   1069         /* DPB check */
   1070         if((((DEFAULT_MAX_REFERENCE_PICS - i4_field_pic) /*max reference*/ + 2) << i4_field_pic) >
   1071            max_dpb_size)
   1072         {
   1073             error_code = IHEVCE_CODEC_LEVEL_NOT_SUPPORTED;
   1074             ps_sys_api->ihevce_printf(
   1075                 pv_cb_handle, "IHEVCE ERROR: i4_codec_level should be set correct \n");
   1076             return IHEVCE_SETUNSUPPORTEDINPUT(error_code);
   1077         }
   1078 
   1079         if((quality_preset > IHEVCE_QUALITY_P7) || (quality_preset < 0) || (quality_preset == 1))
   1080         {
   1081             error_code = IHEVCE_INVALID_QUALITY_PRESET_INPUT;
   1082             ps_sys_api->ihevce_printf(pv_cb_handle, "IHEVCE ERROR: i4_quality_preset invalid \n");
   1083             return IHEVCE_SETUNSUPPORTEDINPUT(error_code);
   1084         }
   1085 
   1086         /* Error checks for target width and height */
   1087         if((height > HEVCE_MAX_HEIGHT) || (height < HEVCE_MIN_HEIGHT) ||
   1088            (height != ps_static_cfg_prms->s_src_prms.i4_height))
   1089         {
   1090             error_code = IHEVCE_TGT_HEIGHT_NOT_SUPPORTED;
   1091             ps_sys_api->ihevce_printf(pv_cb_handle, "IHEVCE ERROR: Target height not supported\n");
   1092             return IHEVCE_SETUNSUPPORTEDINPUT(error_code);
   1093         }
   1094 
   1095         if((width > HEVCE_MAX_WIDTH) || (width < HEVCE_MIN_WIDTH) ||
   1096            (width != ps_static_cfg_prms->s_src_prms.i4_width))
   1097         {
   1098             error_code = IHEVCE_TGT_WIDTH_NOT_SUPPORTED;
   1099             ps_sys_api->ihevce_printf(pv_cb_handle, "IHEVCE ERROR: Target width not supported\n");
   1100             return IHEVCE_SETUNSUPPORTEDINPUT(error_code);
   1101         }
   1102 
   1103         /* Error checks for the codec level */
   1104         if(ps_static_cfg_prms->s_tgt_lyr_prms.as_tgt_params[i4_resolution_id].i4_codec_level >
   1105            LEVEL6)
   1106         {
   1107             error_code = IHEVCE_CODEC_LEVEL_NOT_SUPPORTED;
   1108             ps_sys_api->ihevce_printf(
   1109                 pv_cb_handle,
   1110                 "IHEVCE ERROR: i4_codec_level should be set to a max value of 153 \n");
   1111             return IHEVCE_SETUNSUPPORTEDINPUT(error_code);
   1112         }
   1113 
   1114         if(frm_rate_scale_factor != 1)
   1115         {
   1116             error_code = IHEVCE_TGT_FRAME_RATE_SCALING_NOT_SUPPORTED;
   1117             ps_sys_api->ihevce_printf(
   1118                 pv_cb_handle, "IHEVCE ERROR:  Target frame rate scaler should be 1 \n");
   1119             return IHEVCE_SETUNSUPPORTEDINPUT(error_code);
   1120         }
   1121 
   1122         u4_luma_sample_rate = (UWORD32)(width * height);
   1123         u4_luma_sample_rate *= (UWORD32)(
   1124             ps_static_cfg_prms->s_src_prms.i4_frm_rate_num /
   1125             (ps_static_cfg_prms->s_src_prms.i4_frm_rate_denom * frm_rate_scale_factor));
   1126         /* Check error for max samples rate (frame rate * luma picture size) for the given level */
   1127         if(u4_luma_sample_rate > g_as_level_data[codec_level_index].u4_max_luma_sample_rate)
   1128         {
   1129             error_code = IHEVCE_LUMA_SAMPLE_RATE_NOT_SUPPORTED;
   1130             ps_sys_api->ihevce_printf(
   1131                 pv_cb_handle,
   1132                 "IHEVCE ERROR: input sample rate (i4_src_width * i4_src_height * i4_frm_rate_num / "
   1133                 "i4_frm_rate_denom ) "
   1134                 "exceeds u4_max_luma_sample_rate\n");
   1135             return (IHEVCE_SETUNSUPPORTEDINPUT(error_code));
   1136         }
   1137 
   1138         /* Num instances should be less than equal to IHEVCE_MAX_NUM_BITRATES */
   1139         if((ai4_num_bitrate_instances[i4_resolution_id] < 1) ||
   1140            (ai4_num_bitrate_instances[i4_resolution_id] > IHEVCE_MAX_NUM_BITRATES))
   1141         {
   1142             error_code = IHEVCE_INVALID_NUM_BR_INSTANCES;
   1143             ps_sys_api->ihevce_printf(
   1144                 pv_cb_handle, "IHEVCE ERROR: invalid i4_num_bitrate_instances \n");
   1145             return (IHEVCE_SETUNSUPPORTEDINPUT(error_code));
   1146         }
   1147 
   1148         /* check for codec tier */
   1149         if((ps_static_cfg_prms->s_out_strm_prms.i4_codec_tier > HIGH_TIER) ||
   1150            (ps_static_cfg_prms->s_out_strm_prms.i4_codec_tier < MAIN_TIER))
   1151         {
   1152             error_code = IHEVC_CODEC_TIER_NOT_SUPPORTED;
   1153             ps_sys_api->ihevce_printf(pv_cb_handle, "IHEVCE ERROR: Codec tier  out of range\n");
   1154             return IHEVCE_SETUNSUPPORTEDINPUT(error_code);
   1155         }
   1156 
   1157         if((ps_static_cfg_prms->s_tgt_lyr_prms.as_tgt_params[i4_resolution_id].i4_codec_level <
   1158             120) &&
   1159            (ps_static_cfg_prms->s_out_strm_prms.i4_codec_tier == HIGH_TIER))
   1160         {
   1161             error_code = IHEVC_CODEC_TIER_NOT_SUPPORTED;
   1162             ps_sys_api->ihevce_printf(
   1163                 pv_cb_handle, "IHEVCE ERROR: Codec tier = HIGH TIER Not supported below Level 4\n");
   1164             return IHEVCE_SETUNSUPPORTEDINPUT(error_code);
   1165         }
   1166 
   1167         /* Check error for max bitrate for the given level */
   1168         for(br_ctr = 0; br_ctr < ai4_num_bitrate_instances[i4_resolution_id]; br_ctr++)
   1169         {
   1170             WORD32 frame_qp = ps_static_cfg_prms->s_tgt_lyr_prms.as_tgt_params[i4_resolution_id]
   1171                                   .ai4_frame_qp[br_ctr];
   1172             WORD32 tgt_bitrate = ps_static_cfg_prms->s_tgt_lyr_prms.as_tgt_params[i4_resolution_id]
   1173                                      .ai4_tgt_bitrate[br_ctr];
   1174             WORD32 peak_bitrate;
   1175 
   1176             if(frame_qp > 51 || frame_qp <= 0)
   1177             {
   1178                 error_code = IHEVCE_UNSUPPORTED_FRAME_QP;
   1179                 ps_sys_api->ihevce_printf(pv_cb_handle, "IHEVCE ERROR: i4_frame_qp out of range\n");
   1180                 return IHEVCE_SETUNSUPPORTEDINPUT(error_code);
   1181             }
   1182             if((frame_qp < ps_static_cfg_prms->s_config_prms.i4_min_frame_qp) ||
   1183                ((frame_qp + ps_static_cfg_prms->s_coding_tools_prms.i4_max_temporal_layers + 1) >
   1184                 ps_static_cfg_prms->s_config_prms.i4_max_frame_qp))
   1185             {
   1186                 error_code = IHEVCE_UNSUPPORTED_FRAME_QP;
   1187                 ps_sys_api->ihevce_printf(pv_cb_handle, "IHEVCE ERROR: i4_frame_qp out of range\n");
   1188                 return IHEVCE_SETUNSUPPORTEDINPUT(error_code);
   1189             }
   1190 
   1191             if(tgt_bitrate >
   1192                    g_as_level_data[codec_level_index]
   1193                            .i4_max_bit_rate[ps_static_cfg_prms->s_out_strm_prms.i4_codec_tier] *
   1194                        1000 ||
   1195                tgt_bitrate <= 0)
   1196             {
   1197                 error_code = IHEVCE_BITRATE_NOT_SUPPORTED;
   1198                 ps_sys_api->ihevce_printf(
   1199                     pv_cb_handle,
   1200                     "IHEVCE ERROR: i4_tgt_bitrate out of range for resoltuion number %d bitrate "
   1201                     "number %d\n",
   1202                     i4_resolution_id,
   1203                     br_ctr);
   1204                 return (IHEVCE_SETUNSUPPORTEDINPUT(error_code));
   1205             }
   1206 
   1207             peak_bitrate = tgt_bitrate << 1;
   1208             peak_bitrate =
   1209                 MIN(peak_bitrate,
   1210                     g_as_level_data[codec_level_index]
   1211                             .i4_max_bit_rate[ps_static_cfg_prms->s_out_strm_prms.i4_codec_tier] *
   1212                         1000);
   1213             ps_static_cfg_prms->s_tgt_lyr_prms.as_tgt_params[i4_resolution_id]
   1214                 .ai4_peak_bitrate[br_ctr] = peak_bitrate;
   1215             ps_static_cfg_prms->s_tgt_lyr_prms.as_tgt_params[i4_resolution_id]
   1216                 .ai4_max_vbv_buffer_size[br_ctr] = peak_bitrate;
   1217         }
   1218     }
   1219 
   1220     if((ps_static_cfg_prms->i4_br_id < 0) ||
   1221        (ps_static_cfg_prms->i4_br_id >= ai4_num_bitrate_instances[ps_static_cfg_prms->i4_res_id]))
   1222     {
   1223         error_code = IHEVCE_INVALID_NUM_BR_INSTANCES;
   1224         ps_sys_api->ihevce_printf(
   1225             pv_cb_handle, "IHEVCE ERROR: invalid i4_num_bitrate_instances \n");
   1226         return (IHEVCE_SETUNSUPPORTEDINPUT(error_code));
   1227     }
   1228 
   1229     /* Check error for rate control mode for the given level */
   1230     if(ps_static_cfg_prms->s_config_prms.i4_rate_control_mode != 2 &&
   1231        ps_static_cfg_prms->s_config_prms.i4_rate_control_mode != 3 &&
   1232        ps_static_cfg_prms->s_config_prms.i4_rate_control_mode != 5)
   1233     {
   1234         error_code = IHEVCE_RATE_CONTROL_MDOE_NOT_SUPPORTED;
   1235         ps_sys_api->ihevce_printf(
   1236             pv_cb_handle, "IHEVCE ERROR: i4_rate_control_mode out of range\n");
   1237         return (IHEVCE_SETUNSUPPORTEDINPUT(error_code));
   1238     }
   1239 
   1240     /* Check error for pass number */
   1241     if(ps_static_cfg_prms->s_pass_prms.i4_pass != 0)
   1242     {
   1243         error_code = IHEVCE_RATE_CONTROL_PASS_INVALID;
   1244         ps_sys_api->ihevce_printf(pv_cb_handle, "IHEVCE ERROR: i4_pass out of range\n");
   1245         return (IHEVCE_SETUNSUPPORTEDINPUT(error_code));
   1246     }
   1247 
   1248     /* Check error for cu level qp modultion for the given level */
   1249     if(ps_static_cfg_prms->s_config_prms.i4_cu_level_rc != 0 &&
   1250        ps_static_cfg_prms->s_config_prms.i4_cu_level_rc != 1)
   1251     {
   1252         error_code = IHEVCE_RATE_CONTROL_MDOE_NOT_SUPPORTED;
   1253         ps_sys_api->ihevce_printf(pv_cb_handle, "IHEVCE ERROR: i4_cu_level_rc out of range\n");
   1254         return (IHEVCE_SETUNSUPPORTEDINPUT(error_code));
   1255     }
   1256 
   1257     /* size error checks for the api structures */
   1258     if(ps_static_cfg_prms->i4_size != sizeof(ihevce_static_cfg_params_t))
   1259     {
   1260         error_code = IHEVCE_INVALID_SIZE;
   1261         ps_sys_api->ihevce_printf(
   1262             pv_cb_handle,
   1263             "IHEVCE ERROR: Size element of ihevce_static_cfg_params_t is not matching with actual "
   1264             "size");
   1265         return (IHEVCE_SETUNSUPPORTEDINPUT(error_code));
   1266     }
   1267     if(ps_static_cfg_prms->s_src_prms.i4_size != sizeof(ihevce_src_params_t))
   1268     {
   1269         error_code = IHEVCE_INVALID_SIZE;
   1270         ps_sys_api->ihevce_printf(
   1271             pv_cb_handle,
   1272             "IHEVCE ERROR: Size element of ihevce_src_params_t is not matching with actual size");
   1273         return (IHEVCE_SETUNSUPPORTEDINPUT(error_code));
   1274     }
   1275     if(ps_static_cfg_prms->s_tgt_lyr_prms.i4_size != sizeof(ihevce_tgt_layer_params_t))
   1276     {
   1277         error_code = IHEVCE_INVALID_SIZE;
   1278         ps_sys_api->ihevce_printf(
   1279             pv_cb_handle,
   1280             "IHEVCE ERROR: Size element of ihevce_tgt_layer_params_t is not matching with actual "
   1281             "size");
   1282         return (IHEVCE_SETUNSUPPORTEDINPUT(error_code));
   1283     }
   1284     if(ps_static_cfg_prms->s_out_strm_prms.i4_size != sizeof(ihevce_out_strm_params_t))
   1285     {
   1286         error_code = IHEVCE_INVALID_SIZE;
   1287         ps_sys_api->ihevce_printf(
   1288             pv_cb_handle,
   1289             "IHEVCE ERROR: Size element of ihevce_out_strm_params_t is not matching with actual "
   1290             "size");
   1291         return (IHEVCE_SETUNSUPPORTEDINPUT(error_code));
   1292     }
   1293     if(ps_static_cfg_prms->s_coding_tools_prms.i4_size != sizeof(ihevce_coding_params_t))
   1294     {
   1295         error_code = IHEVCE_INVALID_SIZE;
   1296         ps_sys_api->ihevce_printf(
   1297             pv_cb_handle,
   1298             "IHEVCE ERROR: Size element of ihevce_coding_params_t is not matching with actual "
   1299             "size");
   1300         return (IHEVCE_SETUNSUPPORTEDINPUT(error_code));
   1301     }
   1302     if(ps_static_cfg_prms->s_config_prms.i4_size != sizeof(ihevce_config_prms_t))
   1303     {
   1304         error_code = IHEVCE_INVALID_SIZE;
   1305         ps_sys_api->ihevce_printf(
   1306             pv_cb_handle,
   1307             "IHEVCE ERROR: Size element of ihevce_config_prms_t is not matching with actual size");
   1308         return (IHEVCE_SETUNSUPPORTEDINPUT(error_code));
   1309     }
   1310     if(ps_static_cfg_prms->s_multi_thrd_prms.i4_size != sizeof(ihevce_static_multi_thread_params_t))
   1311     {
   1312         error_code = IHEVCE_INVALID_SIZE;
   1313         ps_sys_api->ihevce_printf(
   1314             pv_cb_handle,
   1315             "IHEVCE ERROR: Size element of ihevce_static_multi_thread_params_t is not matching "
   1316             "with actual size");
   1317         return (IHEVCE_SETUNSUPPORTEDINPUT(error_code));
   1318     }
   1319     for(i4_resolution_id = 0; i4_resolution_id < i4_num_resolutions; i4_resolution_id++)
   1320     {
   1321         if(ps_static_cfg_prms->s_tgt_lyr_prms.as_tgt_params[i4_resolution_id].i4_size !=
   1322            sizeof(ihevce_tgt_params_t))
   1323         {
   1324             error_code = IHEVCE_INVALID_SIZE;
   1325             ps_sys_api->ihevce_printf(
   1326                 pv_cb_handle,
   1327                 "IHEVCE ERROR: Size element of ihevce_tgt_params_t is not matching with actual "
   1328                 "size");
   1329             return (IHEVCE_SETUNSUPPORTEDINPUT(error_code));
   1330         }
   1331     }
   1332 
   1333     if(ps_static_cfg_prms->s_lap_prms.i4_size != sizeof(ihevce_lap_params_t))
   1334     {
   1335         error_code = IHEVCE_INVALID_SIZE;
   1336         ps_sys_api->ihevce_printf(
   1337             pv_cb_handle,
   1338             "IHEVCE ERROR: Size element of ihevce_lap_params_t is not matching with actual size");
   1339         return (IHEVCE_SETUNSUPPORTEDINPUT(error_code));
   1340     }
   1341 
   1342     for(i4_resolution_id = 0; i4_resolution_id < i4_num_resolutions; i4_resolution_id++)
   1343     {
   1344         if(ps_static_cfg_prms->s_tgt_lyr_prms.as_tgt_params[i4_resolution_id].i4_size !=
   1345            sizeof(ihevce_tgt_params_t))
   1346         {
   1347             error_code = IHEVCE_INVALID_SIZE;
   1348             ps_sys_api->ihevce_printf(
   1349                 pv_cb_handle,
   1350                 "IHEVCE ERROR: Size element of ihevce_tgt_params_t is not matching with actual "
   1351                 "size");
   1352             return (IHEVCE_SETUNSUPPORTEDINPUT(error_code));
   1353         }
   1354     }
   1355 
   1356     /* Check SEI related error checks */
   1357     if(1 == ps_static_cfg_prms->s_out_strm_prms.i4_sei_enable_flag)
   1358     {
   1359         WORD32 i;
   1360         /* Check values for i4_sei_hash_flags */
   1361         if(!((ps_static_cfg_prms->s_out_strm_prms.i4_decoded_pic_hash_sei_flag == 2) ||
   1362              (ps_static_cfg_prms->s_out_strm_prms.i4_decoded_pic_hash_sei_flag == 3) ||
   1363              (ps_static_cfg_prms->s_out_strm_prms.i4_decoded_pic_hash_sei_flag == 0)))
   1364         {
   1365             error_code = IHEVCE_SEI_HASH_VALUE_NOT_SUPPORTED;
   1366             ps_sys_api->ihevce_printf(
   1367                 pv_cb_handle, "IHEVCE ERROR: i4_sei_hash_flags out of range\n");
   1368             return (IHEVCE_SETUNSUPPORTEDINPUT(error_code));
   1369         }
   1370 
   1371         /* Content Light Level Info error check */
   1372         if((ps_static_cfg_prms->s_out_strm_prms.i4_sei_cll_enable > 1) ||
   1373            (ps_static_cfg_prms->s_out_strm_prms.i4_sei_cll_enable < 0))
   1374         {
   1375             error_code = IHEVCE_SEI_CLL_ENABLE_OUT_OF_RANGE;
   1376             ps_sys_api->ihevce_printf(
   1377                 pv_cb_handle, "IHEVCE ERROR: i4_sei_cll_enable out of range\n");
   1378             return (IHEVCE_SETUNSUPPORTEDINPUT(error_code));
   1379         }
   1380 
   1381         if((ps_static_cfg_prms->s_out_strm_prms.i4_sei_buffer_period_flags ||
   1382             ps_static_cfg_prms->s_out_strm_prms.i4_sei_pic_timing_flags) &&
   1383            (!ps_static_cfg_prms->s_out_strm_prms.i4_vui_enable))
   1384         {
   1385             error_code = IHEVCE_SEI_ENABLED_VUI_DISABLED;
   1386             ps_sys_api->ihevce_printf(
   1387                 pv_cb_handle,
   1388                 "IHEVCE ERROR: Both SEI and VUI ought to be enabled when either "
   1389                 "'i4_sei_buffer_period_flags' or "
   1390                 "'i4_sei_pic_timing_flags' are enabled\n");
   1391             return (IHEVCE_SETUNSUPPORTEDINPUT(error_code));
   1392         }
   1393 
   1394         if((1 == ps_static_cfg_prms->s_out_strm_prms.i4_sei_buffer_period_flags) &&
   1395            (3 == ps_static_cfg_prms->s_config_prms.i4_rate_control_mode))
   1396         {
   1397             error_code = IHEVCE_SEI_MESSAGES_DEPENDENCY;
   1398             ps_sys_api->ihevce_printf(
   1399                 pv_cb_handle,
   1400                 "IHEVCE ERROR: i4_sei_buffer_period_flags should be disabled for CQP mode of Rate "
   1401                 "control \n");
   1402             return (IHEVCE_SETUNSUPPORTEDINPUT(error_code));
   1403         }
   1404 
   1405         /* Check values for i4_sei_mastering_disp_colour_vol_flags */
   1406         if((ps_static_cfg_prms->s_out_strm_prms.i4_sei_mastering_disp_colour_vol_flags != 0) &&
   1407            (ps_static_cfg_prms->s_out_strm_prms.i4_sei_mastering_disp_colour_vol_flags != 1))
   1408         {
   1409             error_code = IHEVCE_MASTERING_DISP_COL_VOL_OUT_OF_RANGE;
   1410             ps_sys_api->ihevce_printf(
   1411                 pv_cb_handle,
   1412                 "IHEVCE ERROR: i4_sei_mastering_disp_colour_vol_flags out of range\n");
   1413             return (IHEVCE_SETUNSUPPORTEDINPUT(error_code));
   1414         }
   1415 
   1416         if(1 == ps_static_cfg_prms->s_out_strm_prms.i4_sei_mastering_disp_colour_vol_flags)
   1417         {
   1418             /* Check values for u2_display_primaries_x and u2_display_primaries_y */
   1419             for(i = 0; i < 3; i++)
   1420             {
   1421                 if((ps_static_cfg_prms->s_out_strm_prms.au2_display_primaries_x[i] > 50000))
   1422                 {
   1423                     error_code = IHEVCE_DISPLAY_PRIMARY_X_OUT_OF_RANGE;
   1424                     ps_sys_api->ihevce_printf(
   1425                         pv_cb_handle, "IHEVCE ERROR: au2_display_primaries_x out of range\n");
   1426                     return (IHEVCE_SETUNSUPPORTEDINPUT(error_code));
   1427                 }
   1428 
   1429                 if((ps_static_cfg_prms->s_out_strm_prms.au2_display_primaries_y[i] > 50000))
   1430                 {
   1431                     error_code = IHEVCE_DISPLAY_PRIMARY_Y_OUT_OF_RANGE;
   1432                     ps_sys_api->ihevce_printf(
   1433                         pv_cb_handle, "IHEVCE ERROR: au2_display_primaries_y out of range\n");
   1434                     return (IHEVCE_SETUNSUPPORTEDINPUT(error_code));
   1435                 }
   1436             }
   1437 
   1438             if((ps_static_cfg_prms->s_out_strm_prms.u2_white_point_x > 50000))
   1439             {
   1440                 error_code = IHEVCE_WHITE_POINT_X_OUT_OF_RANGE;
   1441                 ps_sys_api->ihevce_printf(
   1442                     pv_cb_handle, "IHEVCE ERROR: u2_white_point_x out of range\n");
   1443                 return (IHEVCE_SETUNSUPPORTEDINPUT(error_code));
   1444             }
   1445 
   1446             if((ps_static_cfg_prms->s_out_strm_prms.u2_white_point_y > 50000))
   1447             {
   1448                 error_code = IHEVCE_WHITE_POINT_Y_OUT_OF_RANGE;
   1449                 ps_sys_api->ihevce_printf(
   1450                     pv_cb_handle, "IHEVCE ERROR: u2_white_point_y out of range\n");
   1451                 return (IHEVCE_SETUNSUPPORTEDINPUT(error_code));
   1452             }
   1453 
   1454             if(ps_static_cfg_prms->s_out_strm_prms.u4_max_display_mastering_luminance <=
   1455                ps_static_cfg_prms->s_out_strm_prms.u4_min_display_mastering_luminance)
   1456             {
   1457                 error_code = IHEVCE_MAX_DISP_MATERING_LUM_OUT_OF_RANGE;
   1458                 ps_sys_api->ihevce_printf(
   1459                     pv_cb_handle,
   1460                     "IHEVCE ERROR: u4_max_display_mastering_luminance should be greater then "
   1461                     "u4_min_display_mastering_luminance \n");
   1462                 return (IHEVCE_SETUNSUPPORTEDINPUT(error_code));
   1463             }
   1464         }
   1465     }
   1466 
   1467     if(1 == ps_static_cfg_prms->s_out_strm_prms.i4_vui_enable)
   1468     {
   1469         /* validate static vui parameters */
   1470         if(((ps_static_cfg_prms->s_vui_sei_prms.u1_aspect_ratio_info_present_flag & 0xFE) > 0))
   1471         {
   1472             error_code = IHEVC_INVALID_ASPECT_RATIO_PARAMS;
   1473             ps_sys_api->ihevce_printf(
   1474                 pv_cb_handle, "IHEVCE ERROR: invalid aspect ratio parameters\n");
   1475             return (IHEVCE_SETUNSUPPORTEDINPUT(error_code));
   1476         }
   1477 
   1478         if(((ps_static_cfg_prms->s_vui_sei_prms.u1_overscan_info_present_flag & 0xFE) > 0) ||
   1479            ((ps_static_cfg_prms->s_vui_sei_prms.u1_overscan_appropriate_flag & 0xFE) > 0))
   1480         {
   1481             error_code = IHEVC_INVALID_OVERSCAN_PARAMS;
   1482             ps_sys_api->ihevce_printf(pv_cb_handle, "IHEVCE ERROR: invalid overscan parameters\n");
   1483             return (IHEVCE_SETUNSUPPORTEDINPUT(error_code));
   1484         }
   1485 
   1486         if(((ps_static_cfg_prms->s_vui_sei_prms.u1_video_signal_type_present_flag & 0xFE) > 0) ||
   1487            (ps_static_cfg_prms->s_vui_sei_prms.u1_video_format > 5) ||
   1488            ((ps_static_cfg_prms->s_vui_sei_prms.u1_video_full_range_flag & 0xFE) > 0))
   1489         {
   1490             error_code = IHEVC_INVALID_VIDEO_PARAMS;
   1491             ps_sys_api->ihevce_printf(
   1492                 pv_cb_handle, "IHEVCE ERROR: invalid video signal type parameters\n");
   1493             return (IHEVCE_SETUNSUPPORTEDINPUT(error_code));
   1494         }
   1495 
   1496         if(((ps_static_cfg_prms->s_vui_sei_prms.u1_colour_description_present_flag & 0xFE) > 0))
   1497         {
   1498             error_code = IHEVC_INVALID_COLOUR_PARAMS;
   1499             ps_sys_api->ihevce_printf(
   1500                 pv_cb_handle, "IHEVCE ERROR: invalid colour description parameters\n");
   1501             return (IHEVCE_SETUNSUPPORTEDINPUT(error_code));
   1502         }
   1503 
   1504         if(((ps_static_cfg_prms->s_vui_sei_prms.u1_chroma_loc_info_present_flag & 0xFE) > 0) ||
   1505            (ps_static_cfg_prms->s_vui_sei_prms.u1_chroma_sample_loc_type_top_field > 5) ||
   1506            (ps_static_cfg_prms->s_vui_sei_prms.u1_chroma_sample_loc_type_bottom_field > 5))
   1507         {
   1508             error_code = IHEVC_INVALID_CHROMA_PARAMS;
   1509             ps_sys_api->ihevce_printf(
   1510                 pv_cb_handle, "IHEVCE ERROR: invalid chroma info parameters\n");
   1511             return (IHEVCE_SETUNSUPPORTEDINPUT(error_code));
   1512         }
   1513 
   1514         if((ps_static_cfg_prms->s_vui_sei_prms.u1_timing_info_present_flag & 0xFE) > 0)
   1515         {
   1516             error_code = IHEVC_INVALID_TIMING_INFO_PARAM;
   1517             ps_sys_api->ihevce_printf(
   1518                 pv_cb_handle, "IHEVCE ERROR: invalid timing info present flag\n");
   1519             return (IHEVCE_SETUNSUPPORTEDINPUT(error_code));
   1520         }
   1521 
   1522         if(((ps_static_cfg_prms->s_vui_sei_prms.u1_vui_hrd_parameters_present_flag & 0xFE) > 0) ||
   1523            ((ps_static_cfg_prms->s_vui_sei_prms.u1_nal_hrd_parameters_present_flag & 0xFE) > 0))
   1524         {
   1525             error_code = IHEVC_INVALID_HRD_PRESENT_PARAMS;
   1526             ps_sys_api->ihevce_printf(
   1527                 pv_cb_handle, "IHEVCE ERROR: invalid vui or vcl hrd parameters present flag\n");
   1528             return (IHEVCE_SETUNSUPPORTEDINPUT(error_code));
   1529         }
   1530     }
   1531 
   1532     error_code = ihevce_validate_tile_config_params(ps_static_cfg_prms);
   1533     if(IHEVCE_SUCCESS != error_code)
   1534     {
   1535         return error_code;
   1536     }
   1537 
   1538     if(ps_static_cfg_prms->s_slice_params.i4_slice_segment_mode != 0)
   1539     {
   1540         error_code = IHEVCE_BAD_SLICE_PARAMS;
   1541         ps_sys_api->ihevce_printf(
   1542             pv_cb_handle, "IHEVCE ERROR: i4_slice_segment_mode should be 0 \n");
   1543         return IHEVCE_SETUNSUPPORTEDINPUT(error_code);
   1544     }
   1545 
   1546     return IHEVCE_SUCCESS;
   1547 }
   1548 
   1549 /*!
   1550 ******************************************************************************
   1551 * \if Function name : ihevce_get_level_index \endif
   1552 *
   1553 * \brief
   1554 *    This function returns the index of level based on codec_level value
   1555 *    Please see the LEVEL_T enum def
   1556 *
   1557 * \param[in] Codec Level
   1558 *
   1559 * \return
   1560 *    Index of Codec level
   1561 *
   1562 * \author
   1563 *    Ittiam
   1564 *
   1565 *****************************************************************************
   1566 */
   1567 WORD32 ihevce_get_level_index(WORD32 i4_codec_level)
   1568 {
   1569     switch(i4_codec_level)
   1570     {
   1571     case LEVEL1:
   1572         return 0;
   1573     case LEVEL2:
   1574         return 1;
   1575     case LEVEL2_1:
   1576         return 2;
   1577     case LEVEL3:
   1578         return 3;
   1579     case LEVEL3_1:
   1580         return 4;
   1581     case LEVEL4:
   1582         return 5;
   1583     case LEVEL4_1:
   1584         return 6;
   1585     case LEVEL5:
   1586         return 7;
   1587     case LEVEL5_1:
   1588         return 8;
   1589     case LEVEL5_2:
   1590         return 9;
   1591     case LEVEL6:
   1592         return 10;
   1593     case LEVEL6_1:
   1594         return 11;
   1595     case LEVEL6_2:
   1596         return 12;
   1597     default:
   1598         return 0;
   1599     }
   1600 }
   1601