Home | History | Annotate | Download | only in encoder
      1 /******************************************************************************
      2  *
      3  * Copyright (C) 2015 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 /* File Includes                                                             */
     23 /*****************************************************************************/
     24 
     25 /* System include files */
     26 #include <stdio.h>
     27 #include <stdlib.h>
     28 #include <stddef.h>
     29 #include <assert.h>
     30 #include <string.h>
     31 
     32 #ifndef IOS
     33 #include <malloc.h>
     34 #endif
     35 
     36 #ifdef WINDOWS_TIMER
     37 #include "windows.h"
     38 #else
     39 #include <sys/time.h>
     40 #endif
     41 /* User include files */
     42 #include "ih264_typedefs.h"
     43 #include "iv2.h"
     44 #include "ive2.h"
     45 #include "ih264e.h"
     46 #include "app.h"
     47 #include "psnr.h"
     48 
     49 /* Function declarations */
     50 #ifndef MD5_DISABLE
     51 void calc_md5_cksum(UWORD8 *pu1_inbuf,UWORD32 u4_stride,UWORD32 u4_width,UWORD32 u4_height,UWORD8 *pu1_cksum_p );
     52 #else
     53 #define calc_md5_cksum(a, b, c, d, e)
     54 #endif
     55 
     56 /*****************************************************************************/
     57 /* Enums                                                                     */
     58 /*****************************************************************************/
     59 typedef enum
     60 {
     61     INVALID,
     62     HELP,
     63     INPUT_FILE,
     64     OUTPUT_FILE,
     65     RECON_FILE,
     66     RECON_ENABLE,
     67     CHKSUM_ENABLE,
     68     CHKSUM_FILE,
     69     INPUT_CHROMA_FORMAT,
     70     RECON_CHROMA_FORMAT,
     71     MAX_WD,
     72     MAX_HT,
     73     WD,
     74     HT,
     75     MAX_LEVEL,
     76     ENC_SPEED,
     77     ME_SPEED,
     78     START_FRM,
     79     NUM_FRMS,
     80     MAX_FRAMERATE,
     81     SRC_FRAMERATE,
     82     TGT_FRAMERATE,
     83     RC,
     84     MAX_BITRATE,
     85     BITRATE,
     86     I_QP,
     87     P_QP,
     88     B_QP,
     89     I_QP_MAX,
     90     P_QP_MAX,
     91     B_QP_MAX,
     92     I_QP_MIN,
     93     P_QP_MIN,
     94     B_QP_MIN,
     95     ENTROPY,
     96     AIR,
     97     AIR_REFRESH_PERIOD,
     98     ARCH,
     99     SOC,
    100     NUMCORES,
    101     PRE_ENC_ME,
    102     PRE_ENC_IPE,
    103     HPEL,
    104     QPEL,
    105     SRCH_RNG_X,
    106     SRCH_RNG_Y,
    107     I_INTERVAL,
    108     IDR_INTERVAL,
    109     CONSTRAINED_INTRA_PRED,
    110     B_FRMS,
    111     NUM_B_FRMS,
    112     DISABLE_DBLK,
    113     PROFILE,
    114     FAST_SAD,
    115     ALT_REF,
    116     DISABLE_DEBLOCK_LEVEL,
    117     PSNR,
    118     SLICE_MODE,
    119     SLICE_PARAM,
    120     CONFIG,
    121     LOOPBACK,
    122     VBV_DELAY,
    123     VBV_SIZE,
    124     INTRA_4x4_ENABLE,
    125     MB_INFO_FILE,
    126     MB_INFO_TYPE,
    127     PIC_INFO_FILE,
    128     PIC_INFO_TYPE,
    129 } ARGUMENT_T;
    130 
    131 typedef struct
    132 {
    133     CHAR        argument_shortname[8];
    134     CHAR        argument_name[128];
    135     ARGUMENT_T  argument;
    136     CHAR        description[512];
    137 } argument_t;
    138 
    139 static const argument_t argument_mapping[] =
    140         {
    141                 { "--", "--help", HELP, "Print this help\n" },
    142                 { "-i", "--input", INPUT_FILE, "Input file\n" },
    143                 { "-o", "--output", OUTPUT_FILE, "Output file\n" },
    144                 { "--", "--recon_enable", RECON_ENABLE, "Recon enable flag\n" },
    145                 { "-r", "--recon", RECON_FILE, "Recon file \n" },
    146                 { "--",  "--input_chroma_format",  INPUT_CHROMA_FORMAT,
    147                             "Input Chroma format Supported values YUV_420P, YUV_420SP_UV, YUV_420SP_VU\n" },
    148                 { "--",  "--recon_chroma_format",  RECON_CHROMA_FORMAT,
    149                             "Recon Chroma format Supported values YUV_420P, YUV_420SP_UV, YUV_420SP_VU\n" },
    150                 { "-w", "--width", WD, "Width of input  file\n" },
    151                 { "-h", "--height", HT, "Height file\n" },
    152                 { "--", "--start_frame", START_FRM,  "Starting frame number\n" },
    153                 { "-f", "--num_frames", NUM_FRMS,  "Number of frames to be encoded\n" },
    154                 { "--", "--rc", RC, "Rate control mode 0: Constant Qp, 1: Storage, 2: CBR non low delay, 3: CBR low delay \n" },
    155                 { "--", "--max_framerate", MAX_FRAMERATE, "Maximum frame rate \n" },
    156                 { "--", "--tgt_framerate", TGT_FRAMERATE, "Target frame rate \n" },
    157                 { "--", "--src_framerate", SRC_FRAMERATE, "Source frame rate \n" },
    158                 { "--", "--i_interval", I_INTERVAL,  "Intra frame interval \n" },
    159                 { "--", "--idr_interval", IDR_INTERVAL,  "IDR frame interval \n" },
    160                 { "--", "--constrained_intrapred", CONSTRAINED_INTRA_PRED,  "Constrained IntraPrediction Flag \n" },
    161                 { "--", "--bframes", NUM_B_FRMS, "Maximum number of consecutive B frames \n" },
    162                 { "--", "--speed", ENC_SPEED, "Encoder speed preset 0 (slowest) and 100 (fastest)\n" },
    163                 { "--", "--me_speed", ME_SPEED, "Encoder speed preset 0 (slowest) and 100 (fastest)\n" },
    164                 { "--", "--fast_sad", FAST_SAD, " Flag for faster sad execution\n" },
    165                 { "--", "--alt_ref", ALT_REF , "Flag to enable alternate refernce frames"},
    166                 { "--", "--hpel", HPEL, "Flag to enable/disable Quarter pel estimation \n" },
    167                 { "--", "--qpel", QPEL, "Flag to enable/disable Quarter pel estimation \n" },
    168                 { "--", "--disable_deblock_level",  DISABLE_DEBLOCK_LEVEL,
    169                         "Disable deblock level - 0 : Enables deblock completely, 1: enables for I and 8th frame , 2: Enables for I only, 3 : disables completely\n" },
    170                 { "--", "--search_range_x", SRCH_RNG_X,     "Search range for X  \n" },
    171                 { "--", "--search_range_y", SRCH_RNG_Y,     "Search range for Y \n" },
    172                 { "--", "--psnr", PSNR, "Enable PSNR computation (Disable while benchmarking performance) \n" },
    173                 { "--", "--pre_enc_me", PRE_ENC_ME, "Flag to enable/disable Pre Enc Motion Estimation\n" },
    174                 { "--", "--pre_enc_ipe", PRE_ENC_IPE, "Flag to enable/disable Pre Enc Intra prediction Estimation\n" },
    175                 { "-n", "--num_cores", NUMCORES, "Number of cores to be used\n" },
    176                 { "--", "--adaptive_intra_refresh", AIR ,"Adaptive Intra Refresh enable/disable\n"},
    177                 { "--", "--air_refresh_period", AIR_REFRESH_PERIOD,"adaptive intra refresh period\n"},
    178                 { "--", "--slice", SLICE_MODE,  "Slice mode-  0 :No slice, 1: Bytes per slice, 2: MB/CTB per slice  \n" },
    179                 { "--", "--slice_param",  SLICE_PARAM, "Slice param value based on slice mode. Slice mode of 1 implies number of bytes per slice, 2 implies number of MBs/CTBs, for 0 value is neglected \n" },
    180                 { "--", "--max_wd",      MAX_WD,                "Maximum width (Default: 1920) \n" },
    181                 { "--", "--max_ht",      MAX_HT,                "Maximum height (Default: 1088)\n" },
    182                 { "--", "--max_level",   MAX_LEVEL,             "Maximum Level (Default: 50)\n" },
    183                 { "--", "--arch", ARCH, "Set Architecture. Supported values  ARM_NONEON, ARM_A9Q, ARM_A7, ARM_A5, ARM_NEONINTR, X86_GENERIC, X86_SSSE3, X86_SSE4 \n" },
    184                 { "--", "--soc", SOC, "Set SOC. Supported values  GENERIC, HISI_37X \n" },
    185                 { "--", "--chksum",            CHKSUM_FILE,              "Save Check sum file for recon data\n" },
    186                 { "--", "--chksum_enable",          CHKSUM_ENABLE,               "Recon MD5 Checksum file\n"},
    187                 { "-c", "--config",      CONFIG,              "config file (Default: enc.cfg)\n" },
    188                 { "--", "--loopback",      LOOPBACK,             "Enable encoding in a loop\n" },
    189                 { "--", "--profile",      PROFILE,               "Profile mode: Supported values BASE, MAIN, HIGH\n" },
    190                 { "--", "--max_bitrate",  MAX_BITRATE,           "Max bitrate\n"},
    191                 { "--", "--bitrate",      BITRATE,               "Target bitrate\n"},
    192                 { "--", "--qp_i",         I_QP,                  "QP for I frames\n"},
    193                 { "--", "--qp_p",         P_QP,                  "QP for P frames\n"},
    194                 { "--", "--qp_b",         B_QP,                  "QP for B frames\n"},
    195                 { "--", "--qp_i_max",     I_QP_MAX,              "Max QP for I frames\n"},
    196                 { "--", "--qp_p_max",     P_QP_MAX,              "Max QP for P frames\n"},
    197                 { "--", "--qp_b_max",     B_QP_MAX,              "Max QP for B frames\n"},
    198                 { "--", "--qp_i_min",     I_QP_MIN,              "Min QP for I frames\n"},
    199                 { "--", "--qp_p_min",     P_QP_MIN,              "Min QP for P frames\n"},
    200                 { "--", "--qp_b_min",     B_QP_MIN,              "Min QP for B frames\n"},
    201                 { "--", "--entropy",      ENTROPY,              "Entropy coding mode(0: CAVLC or 1: CABAC)\n"},
    202                 { "--", "--vbv_delay",    VBV_DELAY,             "VBV buffer delay\n"},
    203                 { "--", "--vbv_size",     VBV_SIZE,              "VBV buffer size\n"},
    204                 { "-i4", "--intra_4x4_enable", INTRA_4x4_ENABLE, "Intra 4x4 enable \n" },
    205                 { "--", "--mb_info_file",     MB_INFO_FILE,              "MB info file\n"},
    206                 { "--", "--mb_info_type",     MB_INFO_TYPE,              "MB info type\n"},
    207                 { "--", "--pic_info_file",     PIC_INFO_FILE,              "Pic info file\n"},
    208                 { "--", "--pic_info_type",     PIC_INFO_TYPE,              "Pic info type\n"},
    209         };
    210 
    211 
    212 
    213 /*****************************************************************************/
    214 /*  Function Declarations                                                    */
    215 /*****************************************************************************/
    216 
    217 
    218 
    219 /*****************************************************************************/
    220 /*  Function Definitions                                                     */
    221 /*****************************************************************************/
    222 
    223 
    224 #if(defined X86) && (defined X86_MINGW)
    225 /*****************************************************************************/
    226 /* Function to print library calls                                           */
    227 /*****************************************************************************/
    228 /*****************************************************************************/
    229 /*                                                                           */
    230 /*  Function Name : memalign                                                 */
    231 /*                                                                           */
    232 /*  Description   : Returns malloc data. Ideally should return aligned memory*/
    233 /*                  support alignment will be added later                    */
    234 /*                                                                           */
    235 /*  Inputs        : alignment                                                */
    236 /*                  size                                                     */
    237 /*  Globals       :                                                          */
    238 /*  Processing    :                                                          */
    239 /*                                                                           */
    240 /*  Outputs       :                                                          */
    241 /*  Returns       :                                                          */
    242 /*                                                                           */
    243 /*  Issues        :                                                          */
    244 /*                                                                           */
    245 /*  Revision History:                                                        */
    246 /*                                                                           */
    247 /*         DD MM YYYY   Author(s)       Changes                              */
    248 /*         07 09 2012   100189          Initial Version                      */
    249 /*                                                                           */
    250 /*****************************************************************************/
    251 
    252 void * ih264a_aligned_malloc(WORD32 alignment, WORD32 size)
    253 {
    254     return _aligned_malloc(size, alignment);
    255 }
    256 
    257 void ih264a_aligned_free(void *pv_buf)
    258 {
    259     _aligned_free(pv_buf);
    260     return;
    261 }
    262 
    263 #elif IOS
    264 
    265 void * ih264a_aligned_malloc(WORD32 alignment, WORD32 size)
    266 {
    267     return malloc(size);
    268 }
    269 
    270 void ih264a_aligned_free(void *pv_buf)
    271 {
    272     free(pv_buf);
    273     return;
    274 }
    275 
    276 #else
    277 
    278 void * ih264a_aligned_malloc(WORD32 alignment, WORD32 size)
    279 {
    280     return memalign(alignment, size);
    281 }
    282 
    283 void ih264a_aligned_free(void *pv_buf)
    284 {
    285     free(pv_buf);
    286     return;
    287 }
    288 
    289 #endif
    290 
    291 /*****************************************************************************/
    292 /*                                                                           */
    293 /*  Function Name : codec_exit                                               */
    294 /*                                                                           */
    295 /*  Description   : handles unrecoverable errors                             */
    296 /*  Inputs        : Error message                                            */
    297 /*  Globals       : None                                                     */
    298 /*  Processing    : Prints error message to console and exits.               */
    299 /*  Outputs       : Error message to the console                             */
    300 /*  Returns       : None                                                     */
    301 /*                                                                           */
    302 /*  Issues        :                                                          */
    303 /*                                                                           */
    304 /*  Revision History:                                                        */
    305 /*                                                                           */
    306 /*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
    307 /*         07 06 2006   Sankar          Creation                             */
    308 /*                                                                           */
    309 /*****************************************************************************/
    310 void codec_exit(CHAR *pc_err_message)
    311 {
    312     printf("%s\n", pc_err_message);
    313     exit(-1);
    314 }
    315 
    316 /*****************************************************************************/
    317 /*                                                                           */
    318 /*  Function Name : codec_exit                                               */
    319 /*                                                                           */
    320 /*  Description   : handles unrecoverable errors                             */
    321 /*  Inputs        : Error message                                            */
    322 /*  Globals       : None                                                     */
    323 /*  Processing    : Prints error message to console and exits.               */
    324 /*  Outputs       : Error mesage to the console                              */
    325 /*  Returns       : None                                                     */
    326 /*                                                                           */
    327 /*  Issues        :                                                          */
    328 /*                                                                           */
    329 /*  Revision History:                                                        */
    330 /*                                                                           */
    331 /*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
    332 /*         07 06 2006   Sankar          Creation                             */
    333 /*                                                                           */
    334 /*****************************************************************************/
    335 IV_COLOR_FORMAT_T get_chroma_fmt(CHAR *value)
    336 {
    337     IV_COLOR_FORMAT_T e_chroma_format;
    338     if((strcmp(value, "YUV_420P")) == 0)
    339         e_chroma_format = IV_YUV_420P;
    340     else if((strcmp(value, "YUV_422ILE")) == 0)
    341         e_chroma_format = IV_YUV_422ILE;
    342     else if((strcmp(value, "RGB_565")) == 0)
    343         e_chroma_format = IV_RGB_565;
    344     else if((strcmp(value, "RGBA_8888")) == 0)
    345         e_chroma_format = IV_RGBA_8888;
    346     else if((strcmp(value, "YUV_420SP_UV")) == 0)
    347         e_chroma_format = IV_YUV_420SP_UV;
    348     else if((strcmp(value, "YUV_420SP_VU")) == 0)
    349         e_chroma_format = IV_YUV_420SP_VU;
    350     else
    351     {
    352         printf("\nInvalid colour format setting it to IV_YUV_420P\n");
    353         e_chroma_format = IV_YUV_420P;
    354     }
    355     return e_chroma_format;
    356 }
    357 
    358 /*****************************************************************************/
    359 /*                                                                           */
    360 /*  Function Name : codec_exit                                               */
    361 /*                                                                           */
    362 /*  Description   : handles unrecoverable errors                             */
    363 /*  Inputs        : Error message                                            */
    364 /*  Globals       : None                                                     */
    365 /*  Processing    : Prints error message to console and exits.               */
    366 /*  Outputs       : Error mesage to the console                              */
    367 /*  Returns       : None                                                     */
    368 /*                                                                           */
    369 /*  Issues        :                                                          */
    370 /*                                                                           */
    371 /*  Revision History:                                                        */
    372 /*                                                                           */
    373 /*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
    374 /*         07 06 2006   Sankar          Creation                             */
    375 /*                                                                           */
    376 /*****************************************************************************/
    377 IVE_SPEED_CONFIG get_speed_preset(CHAR *value)
    378 {
    379     IVE_SPEED_CONFIG e_enc_speed_preset;
    380     if((strcmp(value, "CONFIG")) == 0)
    381         e_enc_speed_preset = IVE_CONFIG;
    382     else if((strcmp(value, "SLOWEST")) == 0)
    383         e_enc_speed_preset = IVE_SLOWEST;
    384     else if((strcmp(value, "NORMAL")) == 0)
    385         e_enc_speed_preset = IVE_NORMAL;
    386     else if((strcmp(value, "FAST")) == 0)
    387           e_enc_speed_preset = IVE_FAST;
    388     else if((strcmp(value, "HIGH_SPEED")) == 0)
    389         e_enc_speed_preset = IVE_HIGH_SPEED;
    390     else if((strcmp(value, "FASTEST")) == 0)
    391         e_enc_speed_preset = IVE_FASTEST;
    392     else
    393     {
    394         printf("\nInvalid speed preset, setting it to IVE_FASTEST\n");
    395         e_enc_speed_preset = IVE_FASTEST;
    396     }
    397     return e_enc_speed_preset;
    398 }
    399 
    400 /*****************************************************************************/
    401 /*                                                                           */
    402 /*  Function Name : print_usage                                              */
    403 /*                                                                           */
    404 /*  Description   : Prints argument format                                   */
    405 /*                                                                           */
    406 /*                                                                           */
    407 /*  Inputs        :                                                          */
    408 /*  Globals       :                                                          */
    409 /*  Processing    : Prints argument format                                   */
    410 /*                                                                           */
    411 /*  Outputs       :                                                          */
    412 /*  Returns       :                                                          */
    413 /*                                                                           */
    414 /*  Issues        :                                                          */
    415 /*                                                                           */
    416 /*  Revision History:                                                        */
    417 /*                                                                           */
    418 /*         DD MM YYYY   Author(s)       Changes                              */
    419 /*         07 09 2012   100189          Initial Version                      */
    420 /*                                                                           */
    421 /*****************************************************************************/
    422 
    423 void print_usage(void)
    424 {
    425     WORD32 i = 0;
    426     WORD32 num_entries = sizeof(argument_mapping) / sizeof(argument_t);
    427     printf("\nUsage:\n");
    428     while(i < num_entries)
    429     {
    430         printf("%-32s\t %s", argument_mapping[i].argument_name,
    431                argument_mapping[i].description);
    432         i++;
    433     }
    434 }
    435 
    436 /*****************************************************************************/
    437 /*                                                                           */
    438 /*  Function Name : get_argument                                             */
    439 /*                                                                           */
    440 /*  Description   : Gets argument for a given string                         */
    441 /*                                                                           */
    442 /*                                                                           */
    443 /*  Inputs        : name                                                     */
    444 /*  Globals       :                                                          */
    445 /*  Processing    : Searches the given string in the array and returns       */
    446 /*                  appropriate argument ID                                  */
    447 /*                                                                           */
    448 /*  Outputs       : Argument ID                                              */
    449 /*  Returns       : Argument ID                                              */
    450 /*                                                                           */
    451 /*  Issues        :                                                          */
    452 /*                                                                           */
    453 /*  Revision History:                                                        */
    454 /*                                                                           */
    455 /*         DD MM YYYY   Author(s)       Changes                              */
    456 /*         07 09 2012   100189          Initial Version                      */
    457 /*                                                                           */
    458 /*****************************************************************************/
    459 ARGUMENT_T get_argument(CHAR *name)
    460 {
    461     WORD32 i = 0;
    462     WORD32 num_entries = sizeof(argument_mapping) / sizeof(argument_t);
    463     while(i < num_entries)
    464     {
    465         if((0 == strcmp(argument_mapping[i].argument_name, name))       ||
    466           ((0 == strcmp(argument_mapping[i].argument_shortname, name))  &&
    467            (0 != strcmp(argument_mapping[i].argument_shortname, "--"))))
    468         {
    469             return argument_mapping[i].argument;
    470         }
    471         i++;
    472     }
    473     return INVALID;
    474 }
    475 
    476 /*****************************************************************************/
    477 /*                                                                           */
    478 /*  Function Name : get_argument                                             */
    479 /*                                                                           */
    480 /*  Description   : Gets argument for a given string                         */
    481 /*                                                                           */
    482 /*                                                                           */
    483 /*  Inputs        : name                                                     */
    484 /*  Globals       :                                                          */
    485 /*  Processing    : Searches the given string in the array and returns       */
    486 /*                  appropriate argument ID                                  */
    487 /*                                                                           */
    488 /*  Outputs       : Argument ID                                              */
    489 /*  Returns       : Argument ID                                              */
    490 /*                                                                           */
    491 /*  Issues        :                                                          */
    492 /*                                                                           */
    493 /*  Revision History:                                                        */
    494 /*                                                                           */
    495 /*         DD MM YYYY   Author(s)       Changes                              */
    496 /*         07 09 2012   100189          Initial Version                      */
    497 /*                                                                           */
    498 /*****************************************************************************/
    499 void parse_argument(app_ctxt_t *ps_app_ctxt, CHAR *argument, CHAR *value)
    500 {
    501     ARGUMENT_T arg;
    502 
    503     arg = get_argument(argument);
    504     switch(arg)
    505     {
    506       case HELP:
    507         print_usage();
    508         exit(-1);
    509         break;
    510       case SLICE_MODE:
    511         sscanf(value, "%d", &ps_app_ctxt->u4_slice_mode);
    512         break;
    513       case SLICE_PARAM:
    514         sscanf(value, "%d", &ps_app_ctxt->u4_slice_param);
    515         break;
    516       case INPUT_FILE:
    517         sscanf(value, "%s", ps_app_ctxt->ac_ip_fname);
    518         break;
    519 
    520       case OUTPUT_FILE:
    521         sscanf(value, "%s", ps_app_ctxt->ac_op_fname);
    522         break;
    523 
    524       case RECON_FILE:
    525         sscanf(value, "%s", ps_app_ctxt->ac_recon_fname);
    526         break;
    527 
    528       case RECON_ENABLE:
    529         sscanf(value, "%d", &ps_app_ctxt->u4_recon_enable);
    530         break;
    531 
    532       case CHKSUM_FILE:
    533           sscanf(value, "%s", ps_app_ctxt->ac_chksum_fname);
    534           break;
    535 
    536       case CHKSUM_ENABLE:
    537           sscanf(value, "%d", &ps_app_ctxt->u4_chksum_enable);
    538           break;
    539 
    540       case MB_INFO_FILE:
    541         sscanf(value, "%s", ps_app_ctxt->ac_mb_info_fname);
    542         break;
    543 
    544       case MB_INFO_TYPE:
    545         sscanf(value, "%d", &ps_app_ctxt->u4_mb_info_type);
    546         break;
    547 
    548       case PIC_INFO_FILE:
    549         sscanf(value, "%s", ps_app_ctxt->ac_pic_info_fname);
    550         break;
    551 
    552       case PIC_INFO_TYPE:
    553         sscanf(value, "%d", &ps_app_ctxt->u4_pic_info_type);
    554         break;
    555 
    556       case INPUT_CHROMA_FORMAT:
    557         ps_app_ctxt->e_inp_color_fmt = get_chroma_fmt(value);
    558         break;
    559 
    560       case RECON_CHROMA_FORMAT:
    561         ps_app_ctxt->e_recon_color_fmt = get_chroma_fmt(value);
    562         break;
    563 
    564       case MAX_WD:
    565         sscanf(value, "%d", &ps_app_ctxt->u4_max_wd);
    566         break;
    567 
    568       case MAX_HT:
    569         sscanf(value, "%d", &ps_app_ctxt->u4_max_ht);
    570         break;
    571 
    572       case WD:
    573         sscanf(value, "%d", &ps_app_ctxt->u4_wd);
    574         break;
    575 
    576       case HT:
    577         sscanf(value, "%d", &ps_app_ctxt->u4_ht);
    578         break;
    579 
    580       case MAX_LEVEL:
    581         sscanf(value, "%d", &ps_app_ctxt->u4_max_level);
    582         break;
    583 
    584       case ENC_SPEED:
    585         ps_app_ctxt->u4_enc_speed = get_speed_preset(value);
    586         break;
    587 
    588       case ME_SPEED:
    589         sscanf(value, "%d", &ps_app_ctxt->u4_me_speed);
    590         break;
    591 
    592       case START_FRM:
    593         sscanf(value, "%d", &ps_app_ctxt->u4_start_frm);
    594         break;
    595 
    596       case NUM_FRMS:
    597         sscanf(value, "%d", &ps_app_ctxt->u4_max_num_frms);
    598         break;
    599 
    600       case MAX_FRAMERATE:
    601           sscanf(value, "%d", &ps_app_ctxt->u4_max_frame_rate);
    602           if(ps_app_ctxt->u4_max_frame_rate <= 0)
    603               ps_app_ctxt->u4_max_frame_rate = DEFAULT_MAX_FRAMERATE;
    604           break;
    605 
    606       case SRC_FRAMERATE:
    607         sscanf(value, "%d", &ps_app_ctxt->u4_src_frame_rate);
    608         if(ps_app_ctxt->u4_src_frame_rate <= 0)
    609             ps_app_ctxt->u4_src_frame_rate = DEFAULT_SRC_FRAME_RATE;
    610         break;
    611 
    612       case TGT_FRAMERATE:
    613         sscanf(value, "%d", &ps_app_ctxt->u4_tgt_frame_rate);
    614         if(ps_app_ctxt->u4_tgt_frame_rate <= 0)
    615             ps_app_ctxt->u4_tgt_frame_rate = DEFAULT_TGT_FRAME_RATE;
    616         break;
    617 
    618       case RC:
    619         sscanf(value, "%d", &ps_app_ctxt->u4_rc);
    620         break;
    621 
    622       case MAX_BITRATE:
    623           sscanf(value, "%d", &ps_app_ctxt->u4_max_bitrate);
    624           break;
    625 
    626       case BITRATE:
    627         sscanf(value, "%d", &ps_app_ctxt->u4_bitrate);
    628         break;
    629 
    630       case I_QP:
    631           sscanf(value, "%d", &ps_app_ctxt->u4_i_qp);
    632           break;
    633 
    634       case I_QP_MAX:
    635           sscanf(value, "%d", &ps_app_ctxt->u4_i_qp_max);
    636           break;
    637 
    638       case I_QP_MIN:
    639           sscanf(value, "%d", &ps_app_ctxt->u4_i_qp_min);
    640           break;
    641 
    642       case P_QP:
    643           sscanf(value, "%d", &ps_app_ctxt->u4_p_qp);
    644           break;
    645 
    646       case P_QP_MAX:
    647           sscanf(value, "%d", &ps_app_ctxt->u4_p_qp_max);
    648           break;
    649 
    650       case P_QP_MIN:
    651           sscanf(value, "%d", &ps_app_ctxt->u4_p_qp_min);
    652           break;
    653 
    654       case B_QP:
    655           sscanf(value, "%d", &ps_app_ctxt->u4_b_qp);
    656           break;
    657 
    658       case B_QP_MAX:
    659           sscanf(value, "%d", &ps_app_ctxt->u4_b_qp_max);
    660           break;
    661 
    662       case B_QP_MIN:
    663           sscanf(value, "%d", &ps_app_ctxt->u4_b_qp_min);
    664           break;
    665 
    666       case ENTROPY:
    667           sscanf(value, "%d", &ps_app_ctxt->u4_entropy_coding_mode);
    668           break;
    669 
    670       case AIR:
    671           sscanf(value, "%d", &ps_app_ctxt->u4_air);
    672           break;
    673 
    674       case ARCH:
    675           if((strcmp(value, "ARM_NONEON")) == 0)
    676               ps_app_ctxt->e_arch = ARCH_ARM_NONEON;
    677           else if((strcmp(value, "ARM_A9Q")) == 0)
    678               ps_app_ctxt->e_arch = ARCH_ARM_A9Q;
    679           else if((strcmp(value, "ARM_A7")) == 0)
    680               ps_app_ctxt->e_arch = ARCH_ARM_A7;
    681           else if((strcmp(value, "ARM_A5")) == 0)
    682               ps_app_ctxt->e_arch = ARCH_ARM_A5;
    683           else if((strcmp(value, "ARM_NEONINTR")) == 0)
    684               ps_app_ctxt->e_arch = ARCH_ARM_NEONINTR;
    685           else if((strcmp(value, "X86_GENERIC")) == 0)
    686               ps_app_ctxt->e_arch = ARCH_X86_GENERIC;
    687           else if((strcmp(value, "X86_SSSE3")) == 0)
    688               ps_app_ctxt->e_arch = ARCH_X86_SSSE3;
    689           else if((strcmp(value, "X86_SSE42")) == 0)
    690               ps_app_ctxt->e_arch = ARCH_X86_SSE42;
    691           else if((strcmp(value, "ARM_A53")) == 0)
    692               ps_app_ctxt->e_arch = ARCH_ARM_A53;
    693           else if((strcmp(value, "ARM_A57")) == 0)
    694               ps_app_ctxt->e_arch = ARCH_ARM_A57;
    695           else if((strcmp(value, "ARM_V8_NEON")) == 0)
    696               ps_app_ctxt->e_arch = ARCH_ARM_V8_NEON;
    697           else
    698           {
    699               printf("\nInvalid Arch. Setting it to ARM_A9Q\n");
    700               ps_app_ctxt->e_arch = ARCH_ARM_A9Q;
    701           }
    702 
    703           break;
    704       case SOC:
    705           if((strcmp(value, "GENERIC")) == 0)
    706               ps_app_ctxt->e_soc = SOC_GENERIC;
    707           else if((strcmp(value, "HISI_37X")) == 0)
    708               ps_app_ctxt->e_soc = SOC_HISI_37X;
    709           else
    710           {
    711               ps_app_ctxt->e_soc = SOC_GENERIC;
    712           }
    713           break;
    714 
    715       case NUMCORES:
    716         sscanf(value, "%d", &ps_app_ctxt->u4_num_cores);
    717         break;
    718 
    719       case LOOPBACK:
    720         sscanf(value, "%d", &ps_app_ctxt->u4_loopback);
    721         break;
    722 
    723       case PRE_ENC_ME:
    724         sscanf(value, "%d", &ps_app_ctxt->u4_pre_enc_me);
    725         break;
    726 
    727       case PRE_ENC_IPE:
    728         sscanf(value, "%d", &ps_app_ctxt->u4_pre_enc_ipe);
    729         break;
    730 
    731       case HPEL:
    732         sscanf(value, "%d", &ps_app_ctxt->u4_hpel);
    733         break;
    734 
    735       case QPEL:
    736         sscanf(value, "%d", &ps_app_ctxt->u4_qpel);
    737         break;
    738 
    739       case SRCH_RNG_X:
    740         sscanf(value, "%d", &ps_app_ctxt->u4_srch_rng_x);
    741         break;
    742 
    743       case SRCH_RNG_Y:
    744         sscanf(value, "%d", &ps_app_ctxt->u4_srch_rng_y);
    745         break;
    746 
    747       case I_INTERVAL:
    748         sscanf(value, "%d", &ps_app_ctxt->u4_i_interval);
    749         break;
    750 
    751       case IDR_INTERVAL:
    752         sscanf(value, "%d", &ps_app_ctxt->u4_idr_interval);
    753         break;
    754 
    755       case CONSTRAINED_INTRA_PRED:
    756         sscanf(value, "%d", &ps_app_ctxt->u4_constrained_intra_pred);
    757         break;
    758 
    759       case NUM_B_FRMS:
    760         sscanf(value, "%d", &ps_app_ctxt->u4_num_bframes);
    761         break;
    762 
    763       case DISABLE_DEBLOCK_LEVEL:
    764         sscanf(value, "%d", &ps_app_ctxt->u4_disable_deblk_level);
    765         break;
    766 
    767       case VBV_DELAY:
    768          sscanf(value, "%d", &ps_app_ctxt->u4_vbv_buffer_delay);
    769          break;
    770 
    771       case VBV_SIZE:
    772          sscanf(value, "%d", &ps_app_ctxt->u4_vbv_buf_size);
    773          break;
    774 
    775       case FAST_SAD:
    776           sscanf(value, "%d", &ps_app_ctxt->u4_enable_fast_sad);
    777           break;
    778 
    779       case ALT_REF:
    780           sscanf(value, "%d", &ps_app_ctxt->u4_enable_alt_ref);
    781           break;
    782 
    783       case AIR_REFRESH_PERIOD:
    784           sscanf(value, "%d", &ps_app_ctxt->u4_air_refresh_period);
    785                    break;
    786 
    787       case PROFILE:
    788             if((strcmp(value, "BASE")) == 0)
    789                 ps_app_ctxt->e_profile = IV_PROFILE_BASE;
    790             else if((strcmp(value, "MAIN")) == 0)
    791               ps_app_ctxt->e_profile = IV_PROFILE_MAIN;
    792             else if((strcmp(value, "HIGH")) == 0)
    793               ps_app_ctxt->e_profile = IV_PROFILE_HIGH;
    794             else
    795             {
    796                 printf("\nInvalid profile. Setting it to BASE\n");
    797                 ps_app_ctxt->e_profile = IV_PROFILE_BASE;
    798             }
    799             break;
    800 
    801       case PSNR:
    802           sscanf(value, "%d", &ps_app_ctxt->u4_psnr_enable);
    803           break;
    804 
    805       case INTRA_4x4_ENABLE:
    806           sscanf(value, "%d", &ps_app_ctxt->u4_enable_intra_4x4);
    807           break;
    808 
    809 
    810       case INVALID:
    811         default:
    812             printf("Ignoring argument :  %s\n", argument);
    813             break;
    814     }
    815 }
    816 
    817 /*****************************************************************************/
    818 /*                                                                           */
    819 /*  Function Name : read_cfg_file                                            */
    820 /*                                                                           */
    821 /*  Description   : Reads arguments from a configuration file                */
    822 /*                                                                           */
    823 /*                                                                           */
    824 /*  Inputs        : ps_app_ctxt  : Application context                        */
    825 /*                  fp_cfg_file : Configuration file handle                  */
    826 /*  Globals       :                                                          */
    827 /*  Processing    : Parses the arguments and fills in the application context*/
    828 /*                                                                           */
    829 /*  Outputs       : Arguments parsed                                         */
    830 /*  Returns       : None                                                     */
    831 /*                                                                           */
    832 /*  Issues        :                                                          */
    833 /*                                                                           */
    834 /*  Revision History:                                                        */
    835 /*                                                                           */
    836 /*         DD MM YYYY   Author(s)       Changes                              */
    837 /*         07 09 2012   100189          Initial Version                      */
    838 /*                                                                           */
    839 /*****************************************************************************/
    840 void read_cfg_file(app_ctxt_t *ps_app_ctxt, FILE *fp_cfg)
    841 {
    842     CHAR line[STRLENGTH];
    843     CHAR description[STRLENGTH];
    844     CHAR value[STRLENGTH];
    845     CHAR argument[STRLENGTH];
    846 
    847     while(0 == (feof(fp_cfg)))
    848     {
    849         line[0] = '\0';
    850         fgets(line, STRLENGTH, fp_cfg);
    851         argument[0] = '\0';
    852         /* Reading Input File Name */
    853         sscanf(line, "%s %s %s", argument, value, description);
    854         if(argument[0] == '\0')
    855             continue;
    856 
    857         parse_argument(ps_app_ctxt, argument, value);
    858     }
    859 }
    860 
    861 void invalid_argument_exit(CHAR *pc_err_message)
    862 {
    863     print_usage();
    864     codec_exit(pc_err_message);
    865 }
    866 
    867 void validate_params(app_ctxt_t *ps_app_ctxt)
    868 {
    869     CHAR ac_error[STRLENGTH];
    870 
    871     if(ps_app_ctxt->ac_ip_fname[0] == '\0')
    872     {
    873         invalid_argument_exit("Specify input file");
    874     }
    875     if(ps_app_ctxt->ac_op_fname[0] == '\0')
    876     {
    877         invalid_argument_exit("Specify output file");
    878     }
    879     if((1 == ps_app_ctxt->u4_recon_enable) && (ps_app_ctxt->ac_recon_fname[0] == '\0'))
    880     {
    881         invalid_argument_exit("Specify recon file");
    882     }
    883     if((1 == ps_app_ctxt->u4_chksum_enable) && (ps_app_ctxt->ac_chksum_fname[0] == '\0'))
    884     {
    885         invalid_argument_exit("Specify checksum file");
    886     }
    887     if(0 >= (WORD32)ps_app_ctxt->u4_wd)
    888     {
    889         sprintf(ac_error, "Invalid width: %d", ps_app_ctxt->u4_wd);
    890         invalid_argument_exit(ac_error);
    891     }
    892     if(0 >= (WORD32)ps_app_ctxt->u4_ht)
    893     {
    894         sprintf(ac_error, "Invalid height: %d", ps_app_ctxt->u4_ht);
    895         invalid_argument_exit(ac_error);
    896     }
    897 
    898     if(0 == (WORD32)ps_app_ctxt->u4_max_num_frms)
    899     {
    900         sprintf(ac_error, "Invalid number of frames to be encoded: %d", ps_app_ctxt->u4_max_num_frms);
    901         invalid_argument_exit(ac_error);
    902     }
    903     if ((0 != (WORD32)ps_app_ctxt->u4_entropy_coding_mode)
    904                     && (1 != (WORD32)ps_app_ctxt->u4_entropy_coding_mode))
    905     {
    906         sprintf(ac_error, "Invalid entropy codeing mode: %d",
    907                 ps_app_ctxt->u4_entropy_coding_mode);
    908         invalid_argument_exit(ac_error);
    909     }
    910     return;
    911 }
    912 
    913 void init_default_params(app_ctxt_t *ps_app_ctxt)
    914 {
    915 
    916     ps_app_ctxt->ps_enc                  = NULL;
    917     ps_app_ctxt->ps_mem_rec              = NULL;
    918     ps_app_ctxt->u4_num_mem_rec          = DEFAULT_MEM_REC_CNT;
    919     ps_app_ctxt->u4_recon_enable         = DEFAULT_RECON_ENABLE;
    920     ps_app_ctxt->u4_chksum_enable        = DEFAULT_CHKSUM_ENABLE;
    921     ps_app_ctxt->u4_mb_info_type         = 0;
    922     ps_app_ctxt->u4_pic_info_type        = 0;
    923     ps_app_ctxt->u4_mb_info_size         = 0;
    924     ps_app_ctxt->u4_pic_info_size        = 0;
    925     ps_app_ctxt->u4_start_frm            = DEFAULT_START_FRM;
    926     ps_app_ctxt->u4_max_num_frms         = DEFAULT_NUM_FRMS;
    927     ps_app_ctxt->avg_time                = 0;
    928     ps_app_ctxt->u4_total_bytes          = 0;
    929     ps_app_ctxt->u4_pics_cnt             = 0;
    930     ps_app_ctxt->e_inp_color_fmt         = DEFAULT_INP_COLOR_FMT;
    931     ps_app_ctxt->e_recon_color_fmt       = DEFAULT_RECON_COLOR_FMT;
    932     ps_app_ctxt->e_arch                  = ARCH_ARM_A9Q;
    933     ps_app_ctxt->e_soc                   = SOC_GENERIC;
    934     ps_app_ctxt->header_generated        = 0;
    935     ps_app_ctxt->pv_codec_obj            = NULL;
    936     ps_app_ctxt->u4_num_cores            = DEFAULT_NUM_CORES;
    937     ps_app_ctxt->u4_pre_enc_me           = 0;
    938     ps_app_ctxt->u4_pre_enc_ipe          = 0;
    939     ps_app_ctxt->ac_ip_fname[0]          = '\0';
    940     ps_app_ctxt->ac_op_fname[0]          = '\0';
    941     ps_app_ctxt->ac_recon_fname[0]       = '\0';
    942     ps_app_ctxt->ac_chksum_fname[0]      = '\0';
    943     ps_app_ctxt->ac_mb_info_fname[0]     = '\0';
    944     ps_app_ctxt->fp_ip                   = NULL;
    945     ps_app_ctxt->fp_op                   = NULL;
    946     ps_app_ctxt->fp_recon                = NULL;
    947     ps_app_ctxt->fp_chksum               = NULL;
    948     ps_app_ctxt->fp_psnr_ip              = NULL;
    949     ps_app_ctxt->fp_mb_info              = NULL;
    950     ps_app_ctxt->fp_pic_info             = NULL;
    951     ps_app_ctxt->u4_loopback             = DEFAULT_LOOPBACK;
    952     ps_app_ctxt->u4_max_frame_rate       = DEFAULT_MAX_FRAMERATE;
    953     ps_app_ctxt->u4_src_frame_rate       = DEFAULT_SRC_FRAME_RATE;
    954     ps_app_ctxt->u4_tgt_frame_rate       = DEFAULT_TGT_FRAME_RATE;
    955     ps_app_ctxt->u4_max_wd               = DEFAULT_MAX_WD;
    956     ps_app_ctxt->u4_max_ht               = DEFAULT_MAX_HT;
    957     ps_app_ctxt->u4_max_level            = DEFAULT_MAX_LEVEL;
    958     ps_app_ctxt->u4_strd                 = DEFAULT_STRIDE;
    959     ps_app_ctxt->u4_wd                   = DEFAULT_WD;
    960     ps_app_ctxt->u4_ht                   = DEFAULT_HT;
    961     ps_app_ctxt->u4_psnr_enable          = DEFAULT_PSNR_ENABLE;
    962     ps_app_ctxt->u4_enc_speed            = IVE_FASTEST;
    963     ps_app_ctxt->u4_me_speed             = DEFAULT_ME_SPEED;
    964     ps_app_ctxt->u4_enable_fast_sad      = DEFAULT_ENABLE_FAST_SAD;
    965     ps_app_ctxt->u4_enable_alt_ref       = DEFAULT_ENABLE_ALT_REF;
    966     ps_app_ctxt->u4_rc                   = DEFAULT_RC;
    967     ps_app_ctxt->u4_max_bitrate          = DEFAULT_MAX_BITRATE;
    968     ps_app_ctxt->u4_num_bframes          = DEFAULT_NUM_BFRAMES;
    969     ps_app_ctxt->u4_bitrate              = DEFAULT_BITRATE;
    970     ps_app_ctxt->u4_i_qp                 = DEFAULT_I_QP;
    971     ps_app_ctxt->u4_p_qp                 = DEFAULT_P_QP;
    972     ps_app_ctxt->u4_b_qp                 = DEFAULT_B_QP;
    973     ps_app_ctxt->u4_i_qp_min             = DEFAULT_QP_MIN;
    974     ps_app_ctxt->u4_i_qp_max             = DEFAULT_QP_MAX;
    975     ps_app_ctxt->u4_p_qp_min             = DEFAULT_QP_MIN;
    976     ps_app_ctxt->u4_p_qp_max             = DEFAULT_QP_MAX;
    977     ps_app_ctxt->u4_b_qp_min             = DEFAULT_QP_MIN;
    978     ps_app_ctxt->u4_b_qp_max             = DEFAULT_QP_MAX;
    979     ps_app_ctxt->u4_air                  = DEFAULT_AIR;
    980     ps_app_ctxt->u4_air_refresh_period   = DEFAULT_AIR_REFRESH_PERIOD;
    981     ps_app_ctxt->u4_srch_rng_x           = DEFAULT_SRCH_RNG_X;
    982     ps_app_ctxt->u4_srch_rng_y           = DEFAULT_SRCH_RNG_Y;
    983     ps_app_ctxt->u4_i_interval           = DEFAULT_I_INTERVAL;
    984     ps_app_ctxt->u4_idr_interval         = DEFAULT_IDR_INTERVAL;
    985     ps_app_ctxt->u4_constrained_intra_pred  = DEFAULT_CONSTRAINED_INTRAPRED;
    986     ps_app_ctxt->u4_disable_deblk_level  = DEFAULT_DISABLE_DEBLK_LEVEL;
    987     ps_app_ctxt->u4_hpel                 = DEFAULT_HPEL;
    988     ps_app_ctxt->u4_qpel                 = DEFAULT_QPEL;
    989     ps_app_ctxt->u4_enable_intra_4x4     = DEFAULT_I4;
    990     ps_app_ctxt->e_profile               = DEFAULT_EPROFILE;
    991     ps_app_ctxt->u4_slice_mode           = DEFAULT_SLICE_MODE;
    992     ps_app_ctxt->u4_slice_param          = DEFAULT_SLICE_PARAM;
    993     ps_app_ctxt->pv_input_thread_handle  = NULL;
    994     ps_app_ctxt->pv_output_thread_handle = NULL;
    995     ps_app_ctxt->pv_recon_thread_handle  = NULL;
    996     ps_app_ctxt->u4_vbv_buf_size         = 0;
    997     ps_app_ctxt->u4_vbv_buffer_delay     = 1000;
    998     ps_app_ctxt->adbl_psnr[0]            = 0.0;
    999     ps_app_ctxt->adbl_psnr[1]            = 0.0;
   1000     ps_app_ctxt->adbl_psnr[2]            = 0.0;
   1001     ps_app_ctxt->u4_psnr_cnt             = 0;
   1002     ps_app_ctxt->pu1_psnr_buf            = NULL;
   1003     ps_app_ctxt->u4_psnr_buf_size        = 0;
   1004     ps_app_ctxt->u4_entropy_coding_mode  = DEFAULT_ENTROPY_CODING_MODE;
   1005 
   1006     return;
   1007 }
   1008 
   1009 void set_dimensions(app_ctxt_t *ps_app_ctxt,
   1010                     UWORD32 u4_timestamp_low,
   1011                     UWORD32 u4_timestamp_high)
   1012 {
   1013     ih264e_ctl_set_dimensions_ip_t s_frame_dimensions_ip;
   1014     ih264e_ctl_set_dimensions_op_t s_frame_dimensions_op;
   1015     IV_STATUS_T status;
   1016 
   1017     s_frame_dimensions_ip.s_ive_ip.e_cmd = IVE_CMD_VIDEO_CTL;
   1018     s_frame_dimensions_ip.s_ive_ip.e_sub_cmd = IVE_CMD_CTL_SET_DIMENSIONS;
   1019 
   1020     s_frame_dimensions_ip.s_ive_ip.u4_ht = ps_app_ctxt->u4_ht;
   1021     s_frame_dimensions_ip.s_ive_ip.u4_wd = ps_app_ctxt->u4_wd;
   1022 
   1023     s_frame_dimensions_ip.s_ive_ip.u4_timestamp_high = u4_timestamp_high;
   1024     s_frame_dimensions_ip.s_ive_ip.u4_timestamp_low = u4_timestamp_low;
   1025 
   1026     s_frame_dimensions_ip.s_ive_ip.u4_size =
   1027                     sizeof(ih264e_ctl_set_dimensions_ip_t);
   1028     s_frame_dimensions_op.s_ive_op.u4_size =
   1029                     sizeof(ih264e_ctl_set_dimensions_op_t);
   1030 
   1031     status = ih264e_api_function(ps_app_ctxt->ps_enc,
   1032                                  &s_frame_dimensions_ip,
   1033                                  &s_frame_dimensions_op);
   1034     if(status != IV_SUCCESS)
   1035     {
   1036         CHAR ac_error[STRLENGTH];
   1037         sprintf(ac_error, "Unable to set frame dimensions = 0x%x\n",
   1038                 s_frame_dimensions_op.s_ive_op.u4_error_code);
   1039         codec_exit(ac_error);
   1040     }
   1041     return;
   1042 }
   1043 
   1044 void set_frame_rate(app_ctxt_t *ps_app_ctxt,
   1045                     UWORD32 u4_timestamp_low,
   1046                     UWORD32 u4_timestamp_high)
   1047 {
   1048     ih264e_ctl_set_frame_rate_ip_t s_frame_rate_ip;
   1049     ih264e_ctl_set_frame_rate_op_t s_frame_rate_op;
   1050     IV_STATUS_T status;
   1051 
   1052     s_frame_rate_ip.s_ive_ip.e_cmd  =   IVE_CMD_VIDEO_CTL;
   1053     s_frame_rate_ip.s_ive_ip.e_sub_cmd  =   IVE_CMD_CTL_SET_FRAMERATE;
   1054 
   1055     s_frame_rate_ip.s_ive_ip.u4_src_frame_rate  =
   1056                     ps_app_ctxt->u4_src_frame_rate;
   1057     s_frame_rate_ip.s_ive_ip.u4_tgt_frame_rate  =
   1058                     ps_app_ctxt->u4_tgt_frame_rate;
   1059 
   1060     s_frame_rate_ip.s_ive_ip.u4_timestamp_high  =   u4_timestamp_high;
   1061     s_frame_rate_ip.s_ive_ip.u4_timestamp_low   =   u4_timestamp_low;
   1062 
   1063     s_frame_rate_ip.s_ive_ip.u4_size    =   sizeof(ih264e_ctl_set_frame_rate_ip_t);
   1064     s_frame_rate_op.s_ive_op.u4_size    =   sizeof(ih264e_ctl_set_frame_rate_op_t);
   1065 
   1066     status = ih264e_api_function(ps_app_ctxt->ps_enc,&s_frame_rate_ip,&s_frame_rate_op);
   1067     if(status != IV_SUCCESS)
   1068        {
   1069            CHAR ac_error[STRLENGTH];
   1070            sprintf(ac_error, "Unable to set frame rate = 0x%x\n",
   1071                    s_frame_rate_op.s_ive_op.u4_error_code);
   1072            codec_exit(ac_error);
   1073        }
   1074        return;
   1075 }
   1076 
   1077 
   1078 void set_ipe_params(app_ctxt_t *ps_app_ctxt,
   1079                     UWORD32 u4_timestamp_low,
   1080                     UWORD32 u4_timestamp_high)
   1081 {
   1082     ih264e_ctl_set_ipe_params_ip_t s_ipe_params_ip;
   1083     ih264e_ctl_set_ipe_params_op_t s_ipe_params_op;
   1084     IV_STATUS_T status;
   1085 
   1086     s_ipe_params_ip.s_ive_ip.e_cmd  =   IVE_CMD_VIDEO_CTL;
   1087     s_ipe_params_ip.s_ive_ip.e_sub_cmd  =   IVE_CMD_CTL_SET_IPE_PARAMS;
   1088 
   1089     s_ipe_params_ip.s_ive_ip.u4_enable_intra_4x4  = ps_app_ctxt->u4_enable_intra_4x4;
   1090     s_ipe_params_ip.s_ive_ip.u4_enc_speed_preset  = ps_app_ctxt->u4_enc_speed;
   1091 
   1092     s_ipe_params_ip.s_ive_ip.u4_timestamp_high  =   u4_timestamp_high;
   1093     s_ipe_params_ip.s_ive_ip.u4_timestamp_low   =   u4_timestamp_low;
   1094 
   1095     s_ipe_params_ip.s_ive_ip.u4_size    =   sizeof(ih264e_ctl_set_ipe_params_ip_t);
   1096     s_ipe_params_op.s_ive_op.u4_size    =   sizeof(ih264e_ctl_set_ipe_params_op_t);
   1097 
   1098     s_ipe_params_ip.s_ive_ip.u4_constrained_intra_pred =
   1099                                             ps_app_ctxt->u4_constrained_intra_pred;
   1100 
   1101     status = ih264e_api_function(ps_app_ctxt->ps_enc,&s_ipe_params_ip,&s_ipe_params_op);
   1102     if(status != IV_SUCCESS)
   1103     {
   1104         CHAR ac_error[STRLENGTH];
   1105         sprintf(ac_error, "Unable to set ipe params = 0x%x\n",
   1106                 s_ipe_params_op.s_ive_op.u4_error_code);
   1107         codec_exit(ac_error);
   1108     }
   1109     return;
   1110 }
   1111 
   1112 void set_bit_rate(app_ctxt_t *ps_app_ctxt,
   1113                   UWORD32 u4_timestamp_low, UWORD32 u4_timestamp_high)
   1114 {
   1115     ih264e_ctl_set_bitrate_ip_t s_bitrate_ip;
   1116     ih264e_ctl_set_bitrate_op_t s_bitrate_op;
   1117     IV_STATUS_T status;
   1118 
   1119     s_bitrate_ip.s_ive_ip.e_cmd  =   IVE_CMD_VIDEO_CTL;
   1120     s_bitrate_ip.s_ive_ip.e_sub_cmd  =   IVE_CMD_CTL_SET_BITRATE;
   1121 
   1122     s_bitrate_ip.s_ive_ip.u4_target_bitrate  =   ps_app_ctxt->u4_bitrate;
   1123 
   1124     s_bitrate_ip.s_ive_ip.u4_timestamp_high  =   u4_timestamp_high;
   1125     s_bitrate_ip.s_ive_ip.u4_timestamp_low   =   u4_timestamp_low;
   1126 
   1127     s_bitrate_ip.s_ive_ip.u4_size    =   sizeof(ih264e_ctl_set_bitrate_ip_t);
   1128     s_bitrate_op.s_ive_op.u4_size    =   sizeof(ih264e_ctl_set_bitrate_op_t);
   1129 
   1130     status = ih264e_api_function(ps_app_ctxt->ps_enc,&s_bitrate_ip,&s_bitrate_op);
   1131     if(status != IV_SUCCESS)
   1132        {
   1133            CHAR ac_error[STRLENGTH];
   1134            sprintf(ac_error, "Unable to set bit rate = 0x%x\n",
   1135                    s_bitrate_op.s_ive_op.u4_error_code);
   1136            codec_exit(ac_error);
   1137        }
   1138        return;
   1139 }
   1140 
   1141 
   1142 void set_frame_type(app_ctxt_t *ps_app_ctxt,
   1143                     UWORD32 u4_timestamp_low,
   1144                     UWORD32 u4_timestamp_high,
   1145                     IV_PICTURE_CODING_TYPE_T  e_frame_type)
   1146 {
   1147     ih264e_ctl_set_frame_type_ip_t s_frame_type_ip;
   1148     ih264e_ctl_set_frame_type_op_t s_frame_type_op;
   1149     IV_STATUS_T status;
   1150 
   1151     s_frame_type_ip.s_ive_ip.e_cmd  =   IVE_CMD_VIDEO_CTL;
   1152     s_frame_type_ip.s_ive_ip.e_sub_cmd  =   IVE_CMD_CTL_SET_FRAMETYPE;
   1153 
   1154     s_frame_type_ip.s_ive_ip.e_frame_type  =   e_frame_type;
   1155 
   1156     s_frame_type_ip.s_ive_ip.u4_timestamp_high  =   u4_timestamp_high;
   1157     s_frame_type_ip.s_ive_ip.u4_timestamp_low   =   u4_timestamp_low;
   1158 
   1159     s_frame_type_ip.s_ive_ip.u4_size    =   sizeof(ih264e_ctl_set_frame_type_ip_t);
   1160     s_frame_type_op.s_ive_op.u4_size    =   sizeof(ih264e_ctl_set_frame_type_op_t);
   1161 
   1162     status = ih264e_api_function(ps_app_ctxt->ps_enc,&s_frame_type_ip,&s_frame_type_op);
   1163     if(status != IV_SUCCESS)
   1164     {
   1165         CHAR ac_error[STRLENGTH];
   1166         sprintf(ac_error, "Unable to set frame type = 0x%x\n",
   1167                 s_frame_type_op.s_ive_op.u4_error_code);
   1168         codec_exit(ac_error);
   1169     }
   1170     return;
   1171 }
   1172 
   1173 void set_qp(app_ctxt_t *ps_app_ctxt,
   1174             UWORD32 u4_timestamp_low, UWORD32 u4_timestamp_high)
   1175 {
   1176     ih264e_ctl_set_qp_ip_t s_qp_ip;
   1177     ih264e_ctl_set_qp_op_t s_qp_op;
   1178     IV_STATUS_T status;
   1179 
   1180     s_qp_ip.s_ive_ip.e_cmd  =   IVE_CMD_VIDEO_CTL;
   1181     s_qp_ip.s_ive_ip.e_sub_cmd  =   IVE_CMD_CTL_SET_QP;
   1182 
   1183     s_qp_ip.s_ive_ip.u4_i_qp = ps_app_ctxt->u4_i_qp;
   1184     s_qp_ip.s_ive_ip.u4_i_qp_max = ps_app_ctxt->u4_i_qp_max;
   1185     s_qp_ip.s_ive_ip.u4_i_qp_min = ps_app_ctxt->u4_i_qp_min;
   1186 
   1187     s_qp_ip.s_ive_ip.u4_p_qp = ps_app_ctxt->u4_p_qp;
   1188     s_qp_ip.s_ive_ip.u4_p_qp_max = ps_app_ctxt->u4_p_qp_max;
   1189     s_qp_ip.s_ive_ip.u4_p_qp_min = ps_app_ctxt->u4_p_qp_min;
   1190 
   1191     s_qp_ip.s_ive_ip.u4_b_qp = ps_app_ctxt->u4_b_qp;
   1192     s_qp_ip.s_ive_ip.u4_b_qp_max = ps_app_ctxt->u4_b_qp_max;
   1193     s_qp_ip.s_ive_ip.u4_b_qp_min = ps_app_ctxt->u4_b_qp_min;
   1194 
   1195     s_qp_ip.s_ive_ip.u4_timestamp_high  =   u4_timestamp_high;
   1196     s_qp_ip.s_ive_ip.u4_timestamp_low   =   u4_timestamp_low;
   1197 
   1198     s_qp_ip.s_ive_ip.u4_size    =   sizeof(ih264e_ctl_set_qp_ip_t);
   1199     s_qp_op.s_ive_op.u4_size    =   sizeof(ih264e_ctl_set_qp_op_t);
   1200 
   1201     status = ih264e_api_function(ps_app_ctxt->ps_enc,&s_qp_ip,&s_qp_op);
   1202     if(status != IV_SUCCESS)
   1203        {
   1204            CHAR ac_error[STRLENGTH];
   1205            sprintf(ac_error, "Unable to set qp 0x%x\n",
   1206                    s_qp_op.s_ive_op.u4_error_code);
   1207            codec_exit(ac_error);
   1208        }
   1209        return;
   1210 }
   1211 
   1212 void set_enc_mode(app_ctxt_t *ps_app_ctxt,
   1213                   UWORD32 u4_timestamp_low, UWORD32 u4_timestamp_high,
   1214                   IVE_ENC_MODE_T e_enc_mode)
   1215 {
   1216     IV_STATUS_T status;
   1217 
   1218     ih264e_ctl_set_enc_mode_ip_t s_enc_mode_ip;
   1219     ih264e_ctl_set_enc_mode_op_t s_enc_mode_op;
   1220 
   1221     s_enc_mode_ip.s_ive_ip.e_cmd = IVE_CMD_VIDEO_CTL;
   1222     s_enc_mode_ip.s_ive_ip.e_sub_cmd = IVE_CMD_CTL_SET_ENC_MODE;
   1223 
   1224     s_enc_mode_ip.s_ive_ip.e_enc_mode = e_enc_mode;
   1225 
   1226     s_enc_mode_ip.s_ive_ip.u4_timestamp_high = u4_timestamp_high;
   1227     s_enc_mode_ip.s_ive_ip.u4_timestamp_low = u4_timestamp_low;
   1228 
   1229     s_enc_mode_ip.s_ive_ip.u4_size = sizeof(ih264e_ctl_set_enc_mode_ip_t);
   1230     s_enc_mode_op.s_ive_op.u4_size = sizeof(ih264e_ctl_set_enc_mode_op_t);
   1231 
   1232     status = ih264e_api_function(ps_app_ctxt->ps_enc, &s_enc_mode_ip,
   1233                                       &s_enc_mode_op);
   1234     if(status != IV_SUCCESS)
   1235     {
   1236         CHAR ac_error[STRLENGTH];
   1237         sprintf(ac_error, "Unable to set in header encode mode = 0x%x\n",
   1238                 s_enc_mode_op.s_ive_op.u4_error_code);
   1239         codec_exit(ac_error);
   1240     }
   1241     return;
   1242 }
   1243 
   1244 
   1245 void set_vbv_params(app_ctxt_t *ps_app_ctxt,
   1246                     UWORD32 u4_timestamp_low,
   1247                     UWORD32 u4_timestamp_high)
   1248 {
   1249     ih264e_ctl_set_vbv_params_ip_t s_vbv_ip;
   1250     ih264e_ctl_set_vbv_params_op_t s_vbv_op;
   1251     IV_STATUS_T status;
   1252 
   1253     s_vbv_ip.s_ive_ip.e_cmd  =   IVE_CMD_VIDEO_CTL;
   1254     s_vbv_ip.s_ive_ip.e_sub_cmd  =   IVE_CMD_CTL_SET_VBV_PARAMS;
   1255 
   1256     s_vbv_ip.s_ive_ip.u4_vbv_buf_size = ps_app_ctxt->u4_vbv_buf_size;
   1257     s_vbv_ip.s_ive_ip.u4_vbv_buffer_delay  =
   1258                     ps_app_ctxt->u4_vbv_buffer_delay;
   1259 
   1260     s_vbv_ip.s_ive_ip.u4_timestamp_high  =   u4_timestamp_high;
   1261     s_vbv_ip.s_ive_ip.u4_timestamp_low   =   u4_timestamp_low;
   1262 
   1263     s_vbv_ip.s_ive_ip.u4_size    =   sizeof(ih264e_ctl_set_vbv_params_ip_t);
   1264     s_vbv_op.s_ive_op.u4_size    =   sizeof(ih264e_ctl_set_vbv_params_op_t);
   1265 
   1266     status = ih264e_api_function(ps_app_ctxt->ps_enc,&s_vbv_ip,&s_vbv_op);
   1267     if(status != IV_SUCCESS)
   1268     {
   1269         CHAR ac_error[STRLENGTH];
   1270         sprintf(ac_error, "Unable to set VBC params = 0x%x\n",
   1271                 s_vbv_op.s_ive_op.u4_error_code);
   1272         codec_exit(ac_error);
   1273     }
   1274     return;
   1275 }
   1276 
   1277 void set_air_params(app_ctxt_t *ps_app_ctxt,
   1278                     UWORD32 u4_timestamp_low,
   1279                     UWORD32 u4_timestamp_high)
   1280 {
   1281     ih264e_ctl_set_air_params_ip_t s_air_ip;
   1282     ih264e_ctl_set_air_params_op_t s_air_op;
   1283     IV_STATUS_T status;
   1284 
   1285     s_air_ip.s_ive_ip.e_cmd  =   IVE_CMD_VIDEO_CTL;
   1286     s_air_ip.s_ive_ip.e_sub_cmd  =   IVE_CMD_CTL_SET_AIR_PARAMS;
   1287 
   1288     s_air_ip.s_ive_ip.e_air_mode = ps_app_ctxt->u4_air;
   1289     s_air_ip.s_ive_ip.u4_air_refresh_period = ps_app_ctxt->u4_air_refresh_period;
   1290 
   1291     s_air_ip.s_ive_ip.u4_timestamp_high  =   u4_timestamp_high;
   1292     s_air_ip.s_ive_ip.u4_timestamp_low   =   u4_timestamp_low;
   1293 
   1294     s_air_ip.s_ive_ip.u4_size    =   sizeof(ih264e_ctl_set_air_params_ip_t);
   1295     s_air_op.s_ive_op.u4_size    =   sizeof(ih264e_ctl_set_air_params_op_t);
   1296 
   1297     status = ih264e_api_function(ps_app_ctxt->ps_enc,&s_air_ip,&s_air_op);
   1298     if(status != IV_SUCCESS)
   1299        {
   1300            CHAR ac_error[STRLENGTH];
   1301            sprintf(ac_error, "Unable to set air params = 0x%x\n",
   1302                    s_air_op.s_ive_op.u4_error_code);
   1303            codec_exit(ac_error);
   1304        }
   1305        return;
   1306 }
   1307 
   1308 void set_me_params(app_ctxt_t *ps_app_ctxt,
   1309                     UWORD32 u4_timestamp_low,
   1310                     UWORD32 u4_timestamp_high)
   1311 {
   1312     IV_STATUS_T status;
   1313 
   1314     ih264e_ctl_set_me_params_ip_t s_me_params_ip;
   1315     ih264e_ctl_set_me_params_op_t s_me_params_op;
   1316 
   1317     s_me_params_ip.s_ive_ip.e_cmd = IVE_CMD_VIDEO_CTL;
   1318     s_me_params_ip.s_ive_ip.e_sub_cmd = IVE_CMD_CTL_SET_ME_PARAMS;
   1319 
   1320     s_me_params_ip.s_ive_ip.u4_enable_fast_sad = ps_app_ctxt->u4_enable_fast_sad;
   1321     s_me_params_ip.s_ive_ip.u4_enable_alt_ref = ps_app_ctxt->u4_enable_alt_ref;
   1322 
   1323     s_me_params_ip.s_ive_ip.u4_enable_hpel  =   ps_app_ctxt->u4_hpel;
   1324     s_me_params_ip.s_ive_ip.u4_enable_qpel  =   ps_app_ctxt->u4_qpel;
   1325     s_me_params_ip.s_ive_ip.u4_me_speed_preset  =   ps_app_ctxt->u4_me_speed;
   1326     s_me_params_ip.s_ive_ip.u4_srch_rng_x   =   ps_app_ctxt->u4_srch_rng_x;
   1327     s_me_params_ip.s_ive_ip.u4_srch_rng_y   =   ps_app_ctxt->u4_srch_rng_y;
   1328 
   1329     s_me_params_ip.s_ive_ip.u4_timestamp_high = u4_timestamp_high;
   1330     s_me_params_ip.s_ive_ip.u4_timestamp_low = u4_timestamp_low;
   1331 
   1332     s_me_params_ip.s_ive_ip.u4_size = sizeof(ih264e_ctl_set_me_params_ip_t);
   1333     s_me_params_op.s_ive_op.u4_size = sizeof(ih264e_ctl_set_me_params_op_t);
   1334 
   1335     status = ih264e_api_function(ps_app_ctxt->ps_enc, &s_me_params_ip,
   1336                                  &s_me_params_op);
   1337     if(status != IV_SUCCESS)
   1338     {
   1339         CHAR ac_error[STRLENGTH];
   1340         sprintf(ac_error, "Unable to set me params = 0x%x\n",
   1341                 s_me_params_op.s_ive_op.u4_error_code);
   1342         codec_exit(ac_error);
   1343     }
   1344     return;
   1345 }
   1346 
   1347 
   1348 void set_gop_params(app_ctxt_t *ps_app_ctxt,
   1349                     UWORD32 u4_timestamp_low,
   1350                     UWORD32 u4_timestamp_high)
   1351 {
   1352     IV_STATUS_T status;
   1353 
   1354     ih264e_ctl_set_gop_params_ip_t s_gop_params_ip;
   1355     ih264e_ctl_set_gop_params_op_t s_gop_params_op;
   1356 
   1357     s_gop_params_ip.s_ive_ip.e_cmd = IVE_CMD_VIDEO_CTL;
   1358     s_gop_params_ip.s_ive_ip.e_sub_cmd = IVE_CMD_CTL_SET_GOP_PARAMS;
   1359 
   1360     s_gop_params_ip.s_ive_ip.u4_i_frm_interval = ps_app_ctxt->u4_i_interval;
   1361     s_gop_params_ip.s_ive_ip.u4_idr_frm_interval = ps_app_ctxt->u4_idr_interval;
   1362 
   1363     s_gop_params_ip.s_ive_ip.u4_timestamp_high = u4_timestamp_high;
   1364     s_gop_params_ip.s_ive_ip.u4_timestamp_low = u4_timestamp_low;
   1365 
   1366     s_gop_params_ip.s_ive_ip.u4_size = sizeof(ih264e_ctl_set_gop_params_ip_t);
   1367     s_gop_params_op.s_ive_op.u4_size = sizeof(ih264e_ctl_set_gop_params_op_t);
   1368 
   1369     status = ih264e_api_function(ps_app_ctxt->ps_enc, &s_gop_params_ip,
   1370                                       &s_gop_params_op);
   1371     if(status != IV_SUCCESS)
   1372     {
   1373         CHAR ac_error[STRLENGTH];
   1374         sprintf(ac_error, "Unable to set ME params = 0x%x\n",
   1375                 s_gop_params_op.s_ive_op.u4_error_code);
   1376         codec_exit(ac_error);
   1377     }
   1378     return;
   1379 }
   1380 
   1381 void set_profile_params(app_ctxt_t *ps_app_ctxt,
   1382                     UWORD32 u4_timestamp_low,
   1383                     UWORD32 u4_timestamp_high)
   1384 {
   1385     IV_STATUS_T status;
   1386 
   1387     ih264e_ctl_set_profile_params_ip_t s_profile_params_ip;
   1388     ih264e_ctl_set_profile_params_op_t s_profile_params_op;
   1389 
   1390     s_profile_params_ip.s_ive_ip.e_cmd = IVE_CMD_VIDEO_CTL;
   1391     s_profile_params_ip.s_ive_ip.e_sub_cmd = IVE_CMD_CTL_SET_PROFILE_PARAMS;
   1392 
   1393     s_profile_params_ip.s_ive_ip.e_profile = ps_app_ctxt->e_profile;
   1394 
   1395     s_profile_params_ip.s_ive_ip.u4_entropy_coding_mode = ps_app_ctxt->u4_entropy_coding_mode;
   1396 
   1397     s_profile_params_ip.s_ive_ip.u4_timestamp_high = u4_timestamp_high;
   1398     s_profile_params_ip.s_ive_ip.u4_timestamp_low = u4_timestamp_low;
   1399 
   1400     s_profile_params_ip.s_ive_ip.u4_size = sizeof(ih264e_ctl_set_profile_params_ip_t);
   1401     s_profile_params_op.s_ive_op.u4_size = sizeof(ih264e_ctl_set_profile_params_op_t);
   1402 
   1403     status = ih264e_api_function(ps_app_ctxt->ps_enc, &s_profile_params_ip,
   1404                                       &s_profile_params_op);
   1405     if(status != IV_SUCCESS)
   1406     {
   1407         CHAR ac_error[STRLENGTH];
   1408         sprintf(ac_error, "Unable to set profile params = 0x%x\n",
   1409                 s_profile_params_op.s_ive_op.u4_error_code);
   1410         codec_exit(ac_error);
   1411     }
   1412     return;
   1413 }
   1414 
   1415 void set_deblock_params(app_ctxt_t *ps_app_ctxt,
   1416                     UWORD32 u4_timestamp_low,
   1417                     UWORD32 u4_timestamp_high)
   1418 {
   1419     IV_STATUS_T status;
   1420 
   1421     ih264e_ctl_set_deblock_params_ip_t s_deblock_params_ip;
   1422     ih264e_ctl_set_deblock_params_op_t s_deblock_params_op;
   1423 
   1424     s_deblock_params_ip.s_ive_ip.e_cmd = IVE_CMD_VIDEO_CTL;
   1425     s_deblock_params_ip.s_ive_ip.e_sub_cmd = IVE_CMD_CTL_SET_DEBLOCK_PARAMS;
   1426 
   1427     s_deblock_params_ip.s_ive_ip.u4_disable_deblock_level =
   1428                     ps_app_ctxt->u4_disable_deblk_level;
   1429 
   1430     s_deblock_params_ip.s_ive_ip.u4_timestamp_high = u4_timestamp_high;
   1431     s_deblock_params_ip.s_ive_ip.u4_timestamp_low = u4_timestamp_low;
   1432 
   1433     s_deblock_params_ip.s_ive_ip.u4_size = sizeof(ih264e_ctl_set_deblock_params_ip_t);
   1434     s_deblock_params_op.s_ive_op.u4_size = sizeof(ih264e_ctl_set_deblock_params_op_t);
   1435 
   1436     status = ih264e_api_function(ps_app_ctxt->ps_enc, &s_deblock_params_ip,
   1437                                       &s_deblock_params_op);
   1438     if(status != IV_SUCCESS)
   1439     {
   1440         CHAR ac_error[STRLENGTH];
   1441         sprintf(ac_error, "Unable to enable/disable deblock params = 0x%x\n",
   1442                 s_deblock_params_op.s_ive_op.u4_error_code);
   1443         codec_exit(ac_error);
   1444     }
   1445     return;
   1446 }
   1447 
   1448 
   1449 void set_vui_params(app_ctxt_t *ps_app_ctxt)
   1450 {
   1451     IV_STATUS_T status;
   1452 
   1453     ih264e_vui_ip_t s_vui_params_ip;
   1454     ih264e_vui_op_t s_vui_params_op;
   1455 
   1456     s_vui_params_ip.e_cmd = IVE_CMD_VIDEO_CTL;
   1457     s_vui_params_ip.e_sub_cmd = IVE_CMD_CTL_SET_VUI_PARAMS;
   1458 
   1459     s_vui_params_ip.u1_aspect_ratio_info_present_flag = 0;
   1460     s_vui_params_ip.u1_aspect_ratio_idc = 0;
   1461     s_vui_params_ip.u2_sar_width = 0;
   1462     s_vui_params_ip.u2_sar_height = 0;
   1463     s_vui_params_ip.u1_overscan_info_present_flag = 0;
   1464     s_vui_params_ip.u1_overscan_appropriate_flag = 0;
   1465     s_vui_params_ip.u1_video_signal_type_present_flag = 0;
   1466     s_vui_params_ip.u1_video_format = 0;
   1467     s_vui_params_ip.u1_video_full_range_flag = 0;
   1468     s_vui_params_ip.u1_colour_description_present_flag = 0;
   1469     s_vui_params_ip.u1_colour_primaries = 0;
   1470     s_vui_params_ip.u1_transfer_characteristics = 0;
   1471     s_vui_params_ip.u1_matrix_coefficients = 0;
   1472     s_vui_params_ip.u1_chroma_loc_info_present_flag = 0;
   1473     s_vui_params_ip.u1_chroma_sample_loc_type_top_field = 0;
   1474     s_vui_params_ip.u1_chroma_sample_loc_type_bottom_field = 0;
   1475     s_vui_params_ip.u1_vui_timing_info_present_flag = 0;
   1476     s_vui_params_ip.u4_vui_num_units_in_tick = 0;
   1477     s_vui_params_ip.u4_vui_time_scale = 0;
   1478     s_vui_params_ip.u1_fixed_frame_rate_flag = 0;
   1479     s_vui_params_ip.u1_nal_hrd_parameters_present_flag = 0;
   1480     s_vui_params_ip.u1_vcl_hrd_parameters_present_flag = 0;
   1481     s_vui_params_ip.u1_low_delay_hrd_flag = 0;
   1482     s_vui_params_ip.u1_pic_struct_present_flag = 0;
   1483     s_vui_params_ip.u1_bitstream_restriction_flag = 0;
   1484     s_vui_params_ip.u1_motion_vectors_over_pic_boundaries_flag = 0;
   1485     s_vui_params_ip.u1_max_bytes_per_pic_denom = 0;
   1486     s_vui_params_ip.u1_max_bits_per_mb_denom = 0;
   1487     s_vui_params_ip.u1_log2_max_mv_length_horizontal = 0;
   1488     s_vui_params_ip.u1_log2_max_mv_length_vertical = 0;
   1489     s_vui_params_ip.u1_num_reorder_frames = 0;
   1490     s_vui_params_ip.u1_max_dec_frame_buffering = 0;
   1491 
   1492 
   1493     s_vui_params_ip.u4_size = sizeof(ih264e_vui_ip_t);
   1494     s_vui_params_op.u4_size = sizeof(ih264e_vui_op_t);
   1495 
   1496     status = ih264e_api_function(ps_app_ctxt->ps_enc, &s_vui_params_ip,
   1497                                       &s_vui_params_op);
   1498     if(status != IV_SUCCESS)
   1499     {
   1500         CHAR ac_error[STRLENGTH];
   1501         sprintf(ac_error, "Unable to set vui params = 0x%x\n",
   1502                 s_vui_params_op.u4_error_code);
   1503         codec_exit(ac_error);
   1504     }
   1505     return;
   1506 }
   1507 #define PEAK_WINDOW_SIZE    8
   1508 
   1509 void synchronous_encode(iv_obj_t *ps_enc, app_ctxt_t *ps_app_ctxt)
   1510 {
   1511     ih264e_video_encode_ip_t ih264e_video_encode_ip;
   1512     ih264e_video_encode_op_t ih264e_video_encode_op;
   1513 
   1514     ive_video_encode_ip_t *ps_video_encode_ip = &ih264e_video_encode_ip.s_ive_ip;
   1515     ive_video_encode_op_t *ps_video_encode_op = &ih264e_video_encode_op.s_ive_op;
   1516 
   1517     iv_raw_buf_t *ps_inp_raw_buf = &ps_video_encode_ip->s_inp_buf;
   1518 
   1519     IV_STATUS_T status = IV_SUCCESS;
   1520 
   1521     WORD32 i, is_last = 0, buff_size = 0, num_bytes = 0;
   1522     UWORD32 u4_total_time = 0;
   1523     UWORD8 *pu1_buf = NULL;
   1524     UWORD32 u4_timestamp_low, u4_timestamp_high;
   1525     void *pv_mb_info = NULL, *pv_pic_info = NULL;
   1526 
   1527     TIMER curtime ;
   1528 #ifdef WINDOWS_TIMER
   1529     TIMER frequency;
   1530 #endif
   1531     WORD32 peak_window[PEAK_WINDOW_SIZE] = {0};
   1532     WORD32 peak_window_idx = 0;
   1533     WORD32 peak_avg_max = 0, timetaken = 0;
   1534     iv_raw_buf_t s_inp_buf, s_recon_buf;
   1535     CHAR ac_error[STRLENGTH];
   1536     WORD32 end_of_frames=0;
   1537     WORD32 i4_inp_done =0;
   1538 
   1539     u4_timestamp_low = 0;
   1540     u4_timestamp_high = 0;
   1541 
   1542     /*************************************************************************/
   1543     /*                         Allocate I/O Buffers                          */
   1544     /*************************************************************************/
   1545     allocate_input(ps_app_ctxt);
   1546     allocate_output(ps_app_ctxt);
   1547     allocate_recon(ps_app_ctxt);
   1548 
   1549     /* init psnr */
   1550     init_psnr(ps_app_ctxt);
   1551 
   1552     /* open file pointers */
   1553     ps_app_ctxt->fp_ip = fopen(ps_app_ctxt->ac_ip_fname, "rb");
   1554     if(NULL == ps_app_ctxt->fp_ip)
   1555     {
   1556         sprintf(ac_error, "Unable to open input file for reading: %s", ps_app_ctxt->ac_ip_fname);
   1557         invalid_argument_exit(ac_error);
   1558     }
   1559 
   1560     ps_app_ctxt->fp_op = fopen(ps_app_ctxt->ac_op_fname, "wb");
   1561     if(NULL == ps_app_ctxt->fp_op)
   1562     {
   1563         sprintf(ac_error, "Unable to open output file for writing: %s", ps_app_ctxt->ac_op_fname);
   1564         invalid_argument_exit(ac_error);
   1565     }
   1566 
   1567     if(1 == ps_app_ctxt->u4_recon_enable)
   1568     {
   1569         ps_app_ctxt->fp_recon = fopen(ps_app_ctxt->ac_recon_fname, "wb");
   1570         if(NULL == ps_app_ctxt->fp_recon)
   1571         {
   1572             sprintf(ac_error, "Unable to open recon file for writing: %s", ps_app_ctxt->ac_recon_fname);
   1573             invalid_argument_exit(ac_error);
   1574         }
   1575     }
   1576 
   1577     if(1 == ps_app_ctxt->u4_chksum_enable)
   1578     {
   1579         ps_app_ctxt->fp_chksum               = fopen(ps_app_ctxt->ac_chksum_fname, "wb");
   1580         if(NULL == ps_app_ctxt->fp_chksum)
   1581         {
   1582             sprintf(ac_error, "Unable to open checksum file for writing: %s", ps_app_ctxt->ac_chksum_fname);
   1583             invalid_argument_exit(ac_error);
   1584         }
   1585     }
   1586 
   1587     /* If PSNR is enabled, open input file again and hold a different file pointer
   1588      * This makes it easy to compute PSNR without adding dependency between input and recon threads
   1589      */
   1590     if(1 == ps_app_ctxt->u4_psnr_enable)
   1591     {
   1592         ps_app_ctxt->fp_psnr_ip              = fopen(ps_app_ctxt->ac_ip_fname, "rb");
   1593         if(NULL == ps_app_ctxt->fp_psnr_ip)
   1594         {
   1595             sprintf(ac_error, "Unable to open input file for reading: %s", ps_app_ctxt->ac_ip_fname);
   1596             invalid_argument_exit(ac_error);
   1597         }
   1598     }
   1599 
   1600     if(0 != ps_app_ctxt->u4_mb_info_type)
   1601     {
   1602         ps_app_ctxt->fp_mb_info  = fopen(ps_app_ctxt->ac_mb_info_fname, "rb");
   1603         if(NULL == ps_app_ctxt->fp_mb_info)
   1604         {
   1605             sprintf(ac_error, "Unable to open MB info file for reading: %s", ps_app_ctxt->ac_mb_info_fname);
   1606             invalid_argument_exit(ac_error);
   1607         }
   1608     }
   1609     if (ps_app_ctxt->u4_pic_info_type)
   1610     {
   1611         ps_app_ctxt->fp_pic_info  = fopen(ps_app_ctxt->ac_pic_info_fname, "rb");
   1612         if(NULL == ps_app_ctxt->fp_pic_info)
   1613         {
   1614             sprintf(ac_error, "Unable to open Pic info file for reading: %s", ps_app_ctxt->ac_pic_info_fname);
   1615             invalid_argument_exit(ac_error);
   1616         }
   1617     }
   1618 
   1619     GETTIME(&ps_app_ctxt->enc_start_time);
   1620     ps_app_ctxt->enc_last_time = ps_app_ctxt->enc_start_time;
   1621 
   1622     while(1)
   1623     {
   1624 
   1625         /******************************************************************************/
   1626         /****************** Input Initialization **************************************/
   1627         /******************************************************************************/
   1628 
   1629         for(i = 0; i < DEFAULT_MAX_INPUT_BUFS; i++)
   1630         {
   1631             if(ps_app_ctxt->as_input_buf[i].u4_is_free)
   1632             {
   1633                 pu1_buf = ps_app_ctxt->as_input_buf[i].pu1_buf;
   1634                 pv_mb_info = ps_app_ctxt->as_input_buf[i].pv_mb_info;
   1635                 pv_pic_info = ps_app_ctxt->as_input_buf[i].pv_pic_info;
   1636                 ps_app_ctxt->as_input_buf[i].u4_is_free = 0;
   1637                 break;
   1638             }
   1639         }
   1640 
   1641         if (i == DEFAULT_MAX_INPUT_BUFS)
   1642         {
   1643             printf("\n Unable to find a free input buffer!!");
   1644             exit(0);
   1645         }
   1646 
   1647         ps_video_encode_ip->u4_size = sizeof(ih264e_video_encode_ip_t);
   1648         ps_video_encode_op->u4_size = sizeof(ih264e_video_encode_op_t);
   1649 
   1650         ps_video_encode_ip->e_cmd = IVE_CMD_VIDEO_ENCODE;
   1651         ps_video_encode_ip->pv_bufs = pu1_buf;
   1652         ps_video_encode_ip->pv_mb_info = pv_mb_info;
   1653         ps_video_encode_ip->pv_pic_info = pv_pic_info;
   1654         ps_video_encode_ip->u4_pic_info_type = ps_app_ctxt->u4_pic_info_type;
   1655         /*
   1656          * Since the buffers are used for reading,
   1657          * And after each row we have a stride we nned to calculate
   1658          * the luma size according to the stride
   1659          */
   1660         ps_inp_raw_buf->e_color_fmt = ps_app_ctxt->e_inp_color_fmt;
   1661 
   1662         /* Initialize for 420SP */
   1663         if(IV_YUV_420SP_UV == ps_app_ctxt->e_inp_color_fmt||
   1664                         IV_YUV_420SP_VU == ps_app_ctxt->e_inp_color_fmt)
   1665         {
   1666             /*init luma buffer*/
   1667             ps_inp_raw_buf->apv_bufs[0] = pu1_buf;
   1668 
   1669             /*Init chroma buffer*/
   1670             pu1_buf += ps_app_ctxt->u4_strd * ps_app_ctxt->u4_ht;
   1671             ps_inp_raw_buf->apv_bufs[1] = pu1_buf;
   1672 
   1673             ps_inp_raw_buf->au4_wd[0] =  ps_app_ctxt->u4_wd;
   1674             ps_inp_raw_buf->au4_wd[1] =  ps_app_ctxt->u4_wd;
   1675 
   1676             ps_inp_raw_buf->au4_ht[0] =  ps_app_ctxt->u4_ht;
   1677             ps_inp_raw_buf->au4_ht[1] =  ps_app_ctxt->u4_ht / 2;
   1678 
   1679             ps_inp_raw_buf->au4_strd[0] =  ps_app_ctxt->u4_strd;
   1680             ps_inp_raw_buf->au4_strd[1] =  ps_app_ctxt->u4_strd;
   1681         }
   1682         else if(IV_YUV_420P == ps_app_ctxt->e_inp_color_fmt)
   1683         {
   1684             /* init buffers */
   1685             ps_inp_raw_buf->apv_bufs[0] = pu1_buf;
   1686             pu1_buf += (ps_app_ctxt->u4_wd) * ps_app_ctxt->u4_ht;
   1687             ps_inp_raw_buf->apv_bufs[1] = pu1_buf;
   1688             pu1_buf += (ps_app_ctxt->u4_wd >> 1) * (ps_app_ctxt->u4_ht >> 1);
   1689             ps_inp_raw_buf->apv_bufs[2] = pu1_buf;
   1690 
   1691             ps_inp_raw_buf->au4_wd[0] =  ps_app_ctxt->u4_wd;
   1692             ps_inp_raw_buf->au4_wd[1] =  ps_app_ctxt->u4_wd / 2;
   1693             ps_inp_raw_buf->au4_wd[2] =  ps_app_ctxt->u4_wd / 2;
   1694 
   1695             ps_inp_raw_buf->au4_ht[0] =  ps_app_ctxt->u4_ht;
   1696             ps_inp_raw_buf->au4_ht[1] =  ps_app_ctxt->u4_ht / 2;
   1697             ps_inp_raw_buf->au4_ht[2] =  ps_app_ctxt->u4_ht / 2;
   1698 
   1699             ps_inp_raw_buf->au4_strd[0] =  ps_app_ctxt->u4_strd;
   1700             ps_inp_raw_buf->au4_strd[1] =  ps_app_ctxt->u4_strd / 2;
   1701             ps_inp_raw_buf->au4_strd[2] =  ps_app_ctxt->u4_strd / 2;
   1702 
   1703         }
   1704         else if(IV_YUV_422ILE == ps_app_ctxt->e_inp_color_fmt)
   1705         {
   1706             /*init luma buffer*/
   1707             ps_inp_raw_buf->apv_bufs[0] = pu1_buf;
   1708 
   1709             ps_inp_raw_buf->au4_wd[0] =  ps_app_ctxt->u4_wd * 2;
   1710 
   1711             ps_inp_raw_buf->au4_ht[0] =  ps_app_ctxt->u4_ht;
   1712 
   1713             ps_inp_raw_buf->au4_strd[0] = ps_app_ctxt->u4_strd *2;
   1714         }
   1715 
   1716         /*
   1717          * Here we read input and other associated buffers. Regardless of success
   1718          * we will proceed from here as we will need extra calls to flush out
   1719          * input queue in encoder. Note that this is not necessary. You can just
   1720          * send encode calls till with valid output and recon buffers till the
   1721          * queue is flushed.
   1722          */
   1723         while(1)
   1724         {
   1725             IV_STATUS_T mb_info_status = IV_SUCCESS, pic_info_status = IV_SUCCESS;
   1726 
   1727             status = read_input(ps_app_ctxt->fp_ip, ps_inp_raw_buf);
   1728 
   1729             if (ps_app_ctxt->u4_mb_info_type != 0)
   1730             {
   1731                 mb_info_status = read_mb_info(ps_app_ctxt, pv_mb_info);
   1732             }
   1733             if (ps_app_ctxt->u4_pic_info_type != 0)
   1734             {
   1735                 pic_info_status = read_pic_info(ps_app_ctxt, pv_pic_info);
   1736             }
   1737             if((IV_SUCCESS != status) || (IV_SUCCESS != mb_info_status)
   1738                             || (IV_SUCCESS != pic_info_status))
   1739             {
   1740                 if(0 == ps_app_ctxt->u4_loopback)
   1741                 {
   1742                     is_last = 1;
   1743                     break;
   1744                 }
   1745                 else
   1746                     fseek(ps_app_ctxt->fp_ip, 0, SEEK_SET);
   1747             }
   1748             break;
   1749         }
   1750 
   1751         /******************************************************************************/
   1752         /****************** Output Initialization *************************************/
   1753         /******************************************************************************/
   1754 
   1755         for(i = 0; i < DEFAULT_MAX_OUTPUT_BUFS; i++)
   1756         {
   1757             if(ps_app_ctxt->as_output_buf[i].u4_is_free)
   1758             {
   1759                 pu1_buf = ps_app_ctxt->as_output_buf[i].pu1_buf;
   1760                 buff_size = ps_app_ctxt->as_output_buf[i].u4_buf_size;
   1761                 ps_app_ctxt->as_output_buf[i].u4_is_free = 0;
   1762                 break;
   1763             }
   1764         }
   1765         ps_video_encode_ip->s_out_buf.pv_buf = pu1_buf;
   1766         ps_video_encode_ip->s_out_buf.u4_bytes = 0;
   1767         ps_video_encode_ip->s_out_buf.u4_bufsize = buff_size;
   1768 
   1769         /******************************************************************************/
   1770         /****************** Recon Initialization **************************************/
   1771         /******************************************************************************/
   1772         init_raw_buf_descr(ps_app_ctxt, &s_recon_buf, ps_app_ctxt->as_recon_buf[0].pu1_buf, ps_app_ctxt->e_recon_color_fmt);
   1773 
   1774         if(ps_app_ctxt->u4_psnr_enable)
   1775             init_raw_buf_descr(ps_app_ctxt, &s_inp_buf, ps_app_ctxt->pu1_psnr_buf, ps_app_ctxt->e_inp_color_fmt);
   1776 
   1777         ps_video_encode_ip->s_recon_buf = s_recon_buf;
   1778 
   1779         /******************************************************************************/
   1780         /************************* Un Initialized *************************************/
   1781         /******************************************************************************/
   1782         if(0 == ps_app_ctxt->u4_loopback)
   1783         {
   1784             /* If input file is read completely and loopback is not enabled,
   1785              *  then exit the loop */
   1786             if(feof(ps_app_ctxt->fp_ip))
   1787             {
   1788                 is_last = 1;
   1789             }
   1790         }
   1791 
   1792 
   1793         /* If last frame, send input null to get back encoded frames */
   1794         if ( is_last == 1 || ((ps_app_ctxt->u4_max_num_frms) <= u4_timestamp_low) )
   1795         {
   1796             is_last = 1;
   1797             ps_inp_raw_buf->apv_bufs[0] = NULL;
   1798             ps_inp_raw_buf->apv_bufs[1] = NULL;
   1799             ps_inp_raw_buf->apv_bufs[2] = NULL;
   1800         }
   1801 
   1802         ps_video_encode_ip->u4_is_last = is_last;
   1803         ps_video_encode_ip->u4_mb_info_type = ps_app_ctxt->u4_mb_info_type;
   1804         ps_video_encode_ip->u4_pic_info_type = ps_app_ctxt->u4_pic_info_type;;
   1805         ps_video_encode_op->s_out_buf.pv_buf= NULL;
   1806         ps_video_encode_ip->u4_timestamp_high = u4_timestamp_high;
   1807         ps_video_encode_ip->u4_timestamp_low = u4_timestamp_low;
   1808 
   1809 
   1810         GETTIME(&ps_app_ctxt->enc_last_time);
   1811 
   1812         status = ih264e_api_function(ps_enc, &ih264e_video_encode_ip, &ih264e_video_encode_op);
   1813 
   1814         if (IV_SUCCESS != status)
   1815         {
   1816             printf("Encode Frame failed = 0x%x\n", ih264e_video_encode_op.s_ive_op.u4_error_code);
   1817             break;
   1818         }
   1819 
   1820 #ifdef WINDOWS_TIMER
   1821         QueryPerformanceFrequency ( &frequency);
   1822 #endif
   1823         GETTIME(&curtime);
   1824         ELAPSEDTIME(ps_app_ctxt->enc_last_time, curtime, timetaken, frequency);
   1825         ps_app_ctxt->enc_last_time = curtime;
   1826 
   1827 #ifdef PROFILE_ENABLE
   1828         {
   1829             WORD32 peak_avg, id;
   1830             u4_total_time += timetaken;
   1831             peak_window[peak_window_idx++] = timetaken;
   1832             if(peak_window_idx == PEAK_WINDOW_SIZE)
   1833                 peak_window_idx = 0;
   1834             peak_avg = 0;
   1835             for(id = 0; id < PEAK_WINDOW_SIZE; id++)
   1836             {
   1837                 peak_avg += peak_window[id];
   1838             }
   1839             peak_avg /= PEAK_WINDOW_SIZE;
   1840             if (peak_avg > peak_avg_max)
   1841                 peak_avg_max = peak_avg;
   1842         }
   1843 #endif
   1844 
   1845         /******************************************************************************/
   1846         /****************** Writing Output ********************************************/
   1847         /******************************************************************************/
   1848         num_bytes = 0;
   1849 
   1850         if(1 == ps_video_encode_op->output_present)
   1851         {
   1852             num_bytes = ps_video_encode_op->s_out_buf.u4_bytes;
   1853             buff_size = ps_video_encode_op->s_out_buf.u4_bufsize;
   1854             pu1_buf = (UWORD8*)ps_video_encode_op->s_out_buf.pv_buf;
   1855 
   1856             status = write_output(ps_app_ctxt->fp_op, pu1_buf, num_bytes);
   1857             if(IV_SUCCESS != status)
   1858             {
   1859                 printf("Error: Unable to write to output file\n");
   1860                 break;
   1861             }
   1862         }
   1863 
   1864         /* free input bufer if codec returns a valid input buffer */
   1865         if (ps_video_encode_op->s_inp_buf.apv_bufs[0])
   1866         {
   1867             /* Reuse of freed input buffer */
   1868             for(i = 0; i < DEFAULT_MAX_INPUT_BUFS; i++)
   1869             {
   1870                 if(ps_app_ctxt->as_input_buf[i].pu1_buf == ps_video_encode_op->s_inp_buf.apv_bufs[0])
   1871                 {
   1872                     ps_app_ctxt->as_input_buf[i].u4_is_free = 1;
   1873                     break;
   1874                 }
   1875             }
   1876         }
   1877 
   1878         /* free output buffer if codec returns a valid output buffer */
   1879         // if(ps_video_encode_op->s_out_buf.pv_buf)
   1880         {
   1881             for(i = 0; i < DEFAULT_MAX_OUTPUT_BUFS; i++)
   1882             {
   1883                 if(ps_app_ctxt->as_output_buf[i].pu1_buf == ps_video_encode_op->s_out_buf.pv_buf)
   1884                 {
   1885                     ps_app_ctxt->as_output_buf[i].u4_is_free = 1;
   1886                     break;
   1887                 }
   1888             }
   1889         }
   1890 
   1891         /**********************************************************************
   1892          *  Print stats
   1893          **********************************************************************/
   1894         {
   1895             UWORD8 u1_pic_type[][5] =
   1896                 { "IDR", "I", "P", "B", "NA" };
   1897             WORD32 lookup_idx = 0;
   1898 
   1899             if (ih264e_video_encode_op.s_ive_op.u4_encoded_frame_type
   1900                             == IV_IDR_FRAME)
   1901             {
   1902                 lookup_idx = 0;
   1903             }
   1904             else if(ih264e_video_encode_op.s_ive_op.u4_encoded_frame_type
   1905                             == IV_I_FRAME)
   1906             {
   1907                 lookup_idx = 1;
   1908             }
   1909             else if(ih264e_video_encode_op.s_ive_op.u4_encoded_frame_type
   1910                             == IV_P_FRAME)
   1911             {
   1912                 lookup_idx = 2;
   1913             }
   1914             else if(ih264e_video_encode_op.s_ive_op.u4_encoded_frame_type
   1915                             == IV_B_FRAME)
   1916             {
   1917                 lookup_idx = 3;
   1918             }
   1919             else if(ih264e_video_encode_op.s_ive_op.u4_encoded_frame_type
   1920                             == IV_NA_FRAME)
   1921             {
   1922                 lookup_idx = 4;
   1923             }
   1924 
   1925             if (ih264e_video_encode_op.s_ive_op.u4_encoded_frame_type
   1926                             != IV_NA_FRAME)
   1927             {
   1928                 ps_app_ctxt->u4_pics_cnt++;
   1929                 ps_app_ctxt->avg_time = u4_total_time / ps_app_ctxt->u4_pics_cnt;
   1930                 ps_app_ctxt->u4_total_bytes += num_bytes;
   1931             }
   1932 
   1933             if (ps_app_ctxt->u4_psnr_enable == 0)
   1934             {
   1935                 printf("[%s] PicNum %4d Bytes Generated %6d TimeTaken(microsec): %6d AvgTime: %6d PeakAvgTimeMax: %6d\n",
   1936                        u1_pic_type[lookup_idx], ps_app_ctxt->u4_pics_cnt,
   1937                        num_bytes, timetaken, ps_app_ctxt->avg_time,
   1938                        peak_avg_max);
   1939             }
   1940         }
   1941 
   1942 
   1943         /* For psnr computation, we need to read the correct input frame and
   1944          * compare with recon. The difficulty with doing it is that we only know
   1945          * that the frame number of recon is monotonically increasing. There
   1946          * may be gaps in the recon if any pre or post enc skip happens. There are
   1947          * 3 senarios
   1948          *  1) A frame is encoded -> returns the pic type
   1949          *  2) A frame is not encoded -> Encoder is waiting, the frame may get
   1950          *     encoded later
   1951          *  3) A frame is not encoded -> A post enc or pre enc skip happend. The
   1952          *     frame is not going to be encoded
   1953          *
   1954          *     The 1st and 2nd scenarios are easy, since we just needs to increment
   1955          *     recon cnt whenever we get a valid recon. This cnt can we used to
   1956          *     sync the recon and input
   1957          *     3rd scenario in conjuction with 2nd will pose problems. Even if
   1958          *     the returning frame is NA, we donot know we should increment the
   1959          *     recon cnt or not becasue it can be case 2 or case 3.
   1960          *
   1961          *  Solutions:
   1962          *  -------------------------
   1963          *   One way to over come this will be to return more information as of
   1964          *   the frame type. We can send if a frame was skipped as a part of the
   1965          *   return frame type.
   1966          *   This will not work. Since the output and recon are not in sync, we
   1967          *   cannot use the current output frame type to determine if a recon
   1968          *   is present currently or not. We need some other way to acheive this.
   1969          *
   1970          *   Other way to do this which is cleaner and maintains the seperation
   1971          *   between recon and the ouptut is to set the width [& height] of output recon
   1972          *   buffer to be zero. Hence we will in effect be saying :"look there
   1973          *   is a recon, but due to frame not being encoded it is having a width 0".
   1974          *   To be more clear we need to make height also to be zero.
   1975          *
   1976          *   But are we using these variables for allocating and deallocating
   1977          *   the buffers some where ? No we are not. The buffer gets re-init
   1978          *   at every encode call
   1979          *
   1980          *   Fixes
   1981          *   ------------------------
   1982          *   Currently the recon buff width and height are set in the encoder.
   1983          *   This will not work now because since recon and input are not
   1984          *   in sync. Hence a recon buff sent at time stamp x will get used to
   1985          *   fill recon of input at time stamp y (x > y). If we reduced the
   1986          *   frame dimensions in between, the recon buffer will not have enough
   1987          *   space. Hence we need to set the with and height appropriatley inside
   1988          *   lib itself.
   1989          */
   1990 
   1991         if (ps_app_ctxt->u4_recon_enable || ps_app_ctxt->u4_chksum_enable
   1992                         || ps_app_ctxt->u4_psnr_enable)
   1993         {
   1994             if (ps_video_encode_op->dump_recon)
   1995             {
   1996                 s_recon_buf = ps_video_encode_op->s_recon_buf;
   1997 
   1998                 /* Read input for psnr computuation */
   1999                 if (ps_app_ctxt->u4_psnr_enable)
   2000                     read_input(ps_app_ctxt->fp_psnr_ip, &s_inp_buf);
   2001 
   2002                 /* if we have a valid recon buffer do the assocated tasks */
   2003                 if (s_recon_buf.au4_wd[0])
   2004                 {
   2005                     /* Dump recon when enabled, and output bytes != 0 */
   2006                     if (ps_app_ctxt->u4_recon_enable)
   2007                     {
   2008                         status = write_recon(ps_app_ctxt->fp_recon, &s_recon_buf);
   2009                         if (IV_SUCCESS != status)
   2010                         {
   2011                             printf("Error: Unable to write to recon file\n");
   2012                             break;
   2013                         }
   2014                     }
   2015 
   2016                     if (ps_app_ctxt->u4_psnr_enable)
   2017                     {
   2018                         compute_psnr(ps_app_ctxt, &s_recon_buf, &s_inp_buf);
   2019                     }
   2020 
   2021 
   2022                     if (ps_app_ctxt->u4_chksum_enable)
   2023                     {
   2024                         WORD32 comp, num_comp = 2;
   2025 
   2026                         if (IV_YUV_420P == s_recon_buf.e_color_fmt)
   2027                             num_comp = 3;
   2028 
   2029                         for (comp = 0; comp < num_comp; comp++)
   2030                         {
   2031                             UWORD8 au1_chksum[16];
   2032                             calc_md5_cksum((UWORD8 *)s_recon_buf.apv_bufs[comp],
   2033                                            s_recon_buf.au4_strd[comp],
   2034                                            s_recon_buf.au4_wd[comp],
   2035                                            s_recon_buf.au4_ht[comp],
   2036                                            au1_chksum);
   2037                             fwrite(au1_chksum, sizeof(UWORD8), 16, ps_app_ctxt->fp_chksum);
   2038                         }
   2039                     }
   2040                 }
   2041             }
   2042         }
   2043 
   2044         u4_timestamp_low++;
   2045 
   2046         /* Break if all the encoded frames are taken from encoder */
   2047         if (1 == ps_video_encode_op->u4_is_last)
   2048         {
   2049             break;
   2050         }
   2051     }
   2052 
   2053     /* Pic count is 1 more than actual num frames encoded, because last call is to just get the output  */
   2054     ps_app_ctxt->u4_pics_cnt--;
   2055 
   2056     if(ps_app_ctxt->u4_psnr_enable)
   2057     {
   2058         print_average_psnr(ps_app_ctxt);
   2059     }
   2060 
   2061     /* house keeping operations */
   2062     fclose(ps_app_ctxt->fp_ip);
   2063     fclose(ps_app_ctxt->fp_op);
   2064     if(1 == ps_app_ctxt->u4_recon_enable)
   2065     {
   2066         fclose(ps_app_ctxt->fp_recon);
   2067     }
   2068     if(1 == ps_app_ctxt->u4_chksum_enable)
   2069     {
   2070         fclose(ps_app_ctxt->fp_chksum);
   2071     }
   2072     if(1 == ps_app_ctxt->u4_psnr_enable)
   2073     {
   2074         fclose(ps_app_ctxt->fp_psnr_ip);
   2075     }
   2076 
   2077     if(0 != ps_app_ctxt->u4_mb_info_type)
   2078     {
   2079         fclose(ps_app_ctxt->fp_mb_info);
   2080     }
   2081     if (ps_app_ctxt->u4_pic_info_type)
   2082     {
   2083         fclose(ps_app_ctxt->fp_pic_info);
   2084     }
   2085 
   2086     free_input(ps_app_ctxt);
   2087     free_output(ps_app_ctxt);
   2088     free_recon(ps_app_ctxt);
   2089 }
   2090 
   2091 /*****************************************************************************/
   2092 /*                                                                           */
   2093 /*  Function Name : main                                                     */
   2094 /*                                                                           */
   2095 /*  Description   : Application to demonstrate codec API                     */
   2096 /*                                                                           */
   2097 /*                                                                           */
   2098 /*  Inputs        : argc    - Number of arguments                            */
   2099 /*                  argv[]  - Arguments                                      */
   2100 /*  Globals       :                                                          */
   2101 /*  Processing    : Shows how to use create, process, control and delete     */
   2102 /*                                                                           */
   2103 /*  Outputs       : Codec output in a file                                   */
   2104 /*  Returns       :                                                          */
   2105 /*                                                                           */
   2106 /*  Issues        : Assumes both PROFILE_ENABLE to be                        */
   2107 /*                  defined for multithread decode-display working           */
   2108 /*                                                                           */
   2109 /*  Revision History:                                                        */
   2110 /*                                                                           */
   2111 /*         DD MM YYYY   Author(s)       Changes                              */
   2112 /*         20 11 2013   100189          Initial Version                      */
   2113 /*****************************************************************************/
   2114 #ifdef IOS
   2115 int h264enc_main(char * homedir,char *documentdir, int screen_wd, int screen_ht)
   2116 #else
   2117 int main(int argc, char *argv[])
   2118 #endif
   2119 {
   2120     /* Config Parameters for Encoding */
   2121     app_ctxt_t s_app_ctxt;
   2122 
   2123     /* error string */
   2124     CHAR ac_error[STRLENGTH];
   2125 
   2126     /* config file name */
   2127     CHAR ac_cfg_fname[STRLENGTH];
   2128 
   2129     /* error status */
   2130     IV_STATUS_T status = IV_SUCCESS;
   2131 #ifdef IOS
   2132     /* temp var */
   2133     CHAR filename_with_path[STRLENGTH];
   2134 #endif
   2135     WORD32 num_mem_recs;
   2136     iv_obj_t *ps_enc;
   2137     WORD32 i;
   2138     FILE *fp_cfg = NULL;
   2139 
   2140 #ifdef X86_MINGW
   2141 
   2142     /* For getting printfs without any delay in eclipse */
   2143     setvbuf(stdout, NULL, _IONBF, 0);
   2144     setvbuf(stderr, NULL, _IONBF, 0);
   2145 
   2146 #endif
   2147 
   2148     init_default_params(&s_app_ctxt);
   2149 
   2150 #ifndef IOS
   2151 
   2152     /* Usage */
   2153     if(argc < 2)
   2154     {
   2155         printf("Using enc.cfg as configuration file \n");
   2156         strcpy(ac_cfg_fname, "enc.cfg");
   2157     }
   2158     else if(argc == 2)
   2159     {
   2160         if (!strcmp(argv[1], "--help"))
   2161         {
   2162             print_usage();
   2163             exit(-1);
   2164         }
   2165         strcpy(ac_cfg_fname, argv[1]);
   2166     }
   2167 
   2168 #else
   2169     strcpy(ac_cfg_fname, "test.cfg");
   2170 
   2171 #endif
   2172 
   2173     /*************************************************************************/
   2174     /* Parse arguments                                                       */
   2175     /*************************************************************************/
   2176 
   2177 #ifndef IOS
   2178 
   2179     /* Read command line arguments */
   2180     if(argc > 2)
   2181     {
   2182         for(i = 1; i + 1 < argc; i += 2)
   2183         {
   2184             if(CONFIG == get_argument(argv[i]))
   2185             {
   2186                 strcpy(ac_cfg_fname, argv[i + 1]);
   2187                 if((fp_cfg = fopen(ac_cfg_fname, "r")) == NULL)
   2188                 {
   2189                     sprintf(ac_error,
   2190                             "Could not open Configuration file %s",
   2191                             ac_cfg_fname);
   2192                     codec_exit(ac_error);
   2193                 }
   2194                 read_cfg_file(&s_app_ctxt, fp_cfg);
   2195                 fclose(fp_cfg);
   2196             }
   2197             else
   2198             {
   2199                 parse_argument(&s_app_ctxt, argv[i], argv[i + 1]);
   2200             }
   2201         }
   2202     }
   2203     else
   2204     {
   2205         if((fp_cfg = fopen(ac_cfg_fname, "r")) == NULL)
   2206         {
   2207             sprintf(ac_error, "Could not open Configuration file %s",
   2208                     ac_cfg_fname);
   2209             codec_exit(ac_error);
   2210         }
   2211         read_cfg_file(&s_app_ctxt, fp_cfg);
   2212         fclose(fp_cfg);
   2213     }
   2214 
   2215 #else
   2216 
   2217     sprintf(filename_with_path, "%s/%s", homedir, "enc.cfg");
   2218     if((fp_cfg = fopen(filename_with_path, "r")) == NULL)
   2219     {
   2220         sprintf(ac_error, "Could not open Configuration file %s",
   2221                 ac_cfg_fname);
   2222         codec_exit(ac_error);
   2223 
   2224     }
   2225     read_cfg_file(&s_app_ctxt, fp_cfg);
   2226     fclose(fp_cfg);
   2227 
   2228 #endif
   2229 
   2230 
   2231     validate_params(&s_app_ctxt);
   2232 
   2233 
   2234     /*************************************************************************/
   2235     /*                      Getting Number of MemRecords                     */
   2236     /*************************************************************************/
   2237     {
   2238         ih264e_num_mem_rec_ip_t s_num_mem_rec_ip;
   2239         ih264e_num_mem_rec_op_t s_num_mem_rec_op;
   2240 
   2241         s_num_mem_rec_ip.s_ive_ip.u4_size = sizeof(ih264e_num_mem_rec_ip_t);
   2242         s_num_mem_rec_op.s_ive_op.u4_size = sizeof(ih264e_num_mem_rec_op_t);
   2243 
   2244         s_num_mem_rec_ip.s_ive_ip.e_cmd = IV_CMD_GET_NUM_MEM_REC;
   2245 
   2246         status = ih264e_api_function(0, &s_num_mem_rec_ip, &s_num_mem_rec_op);
   2247 
   2248         if(status != IV_SUCCESS)
   2249         {
   2250             sprintf(ac_error, "Get number of memory records failed = 0x%x\n", s_num_mem_rec_op.s_ive_op.u4_error_code);
   2251             codec_exit(ac_error);
   2252         }
   2253 
   2254         s_app_ctxt.u4_num_mem_rec = num_mem_recs = s_num_mem_rec_op.s_ive_op.u4_num_mem_rec;
   2255     }
   2256 
   2257     /* Allocate array to hold memory records */
   2258     s_app_ctxt.ps_mem_rec = (iv_mem_rec_t *) malloc(num_mem_recs * sizeof(iv_mem_rec_t));
   2259     if(NULL == s_app_ctxt.ps_mem_rec)
   2260     {
   2261 
   2262         sprintf(ac_error, "Unable to allocate memory for hold memory records: Size %d", (WORD32)(num_mem_recs * sizeof(iv_mem_rec_t)));
   2263         codec_exit(ac_error);
   2264     }
   2265 
   2266     {
   2267         iv_mem_rec_t *ps_mem_rec;
   2268         ps_mem_rec = s_app_ctxt.ps_mem_rec;
   2269         for(i = 0; i < num_mem_recs; i++)
   2270         {
   2271             ps_mem_rec->u4_size = sizeof(iv_mem_rec_t);
   2272             ps_mem_rec->pv_base = NULL;
   2273             ps_mem_rec->u4_mem_size = 0;
   2274             ps_mem_rec->u4_mem_alignment = 0;
   2275             ps_mem_rec->e_mem_type = IV_NA_MEM_TYPE;
   2276 
   2277             ps_mem_rec++;
   2278         }
   2279     }
   2280 
   2281     /*************************************************************************/
   2282     /*                      Getting MemRecords Attributes                    */
   2283     /*************************************************************************/
   2284     {
   2285         ih264e_fill_mem_rec_ip_t s_fill_mem_rec_ip;
   2286         ih264e_fill_mem_rec_op_t s_fill_mem_rec_op;
   2287 
   2288         s_fill_mem_rec_ip.s_ive_ip.u4_size = sizeof(ih264e_fill_mem_rec_ip_t);
   2289         s_fill_mem_rec_op.s_ive_op.u4_size = sizeof(ih264e_fill_mem_rec_op_t);
   2290 
   2291         s_fill_mem_rec_ip.s_ive_ip.e_cmd = IV_CMD_FILL_NUM_MEM_REC;
   2292         s_fill_mem_rec_ip.s_ive_ip.ps_mem_rec = s_app_ctxt.ps_mem_rec;
   2293         s_fill_mem_rec_ip.s_ive_ip.u4_num_mem_rec = s_app_ctxt.u4_num_mem_rec;
   2294         s_fill_mem_rec_ip.s_ive_ip.u4_max_wd = s_app_ctxt.u4_max_wd;
   2295         s_fill_mem_rec_ip.s_ive_ip.u4_max_ht = s_app_ctxt.u4_max_ht;
   2296         s_fill_mem_rec_ip.s_ive_ip.u4_max_level = s_app_ctxt.u4_max_level;
   2297         s_fill_mem_rec_ip.s_ive_ip.e_color_format = DEFAULT_INP_COLOR_FMT;
   2298         s_fill_mem_rec_ip.s_ive_ip.u4_max_ref_cnt = DEFAULT_MAX_REF_FRM;
   2299         s_fill_mem_rec_ip.s_ive_ip.u4_max_reorder_cnt = DEFAULT_MAX_REORDER_FRM;
   2300         s_fill_mem_rec_ip.s_ive_ip.u4_max_srch_rng_x = DEFAULT_MAX_SRCH_RANGE_X;
   2301         s_fill_mem_rec_ip.s_ive_ip.u4_max_srch_rng_y = DEFAULT_MAX_SRCH_RANGE_Y;
   2302 
   2303         status = ih264e_api_function(0, &s_fill_mem_rec_ip, &s_fill_mem_rec_op);
   2304 
   2305         if(status != IV_SUCCESS)
   2306         {
   2307             sprintf(ac_error, "Fill memory records failed = 0x%x\n",
   2308                     s_fill_mem_rec_op.s_ive_op.u4_error_code);
   2309             codec_exit(ac_error);
   2310         }
   2311     }
   2312 
   2313     /*************************************************************************/
   2314     /*                      Allocating Memory for Mem Records                */
   2315     /*************************************************************************/
   2316     {
   2317         WORD32 total_size;
   2318         iv_mem_rec_t *ps_mem_rec;
   2319         total_size = 0;
   2320 
   2321         ps_mem_rec = s_app_ctxt.ps_mem_rec;
   2322         for(i = 0; i < num_mem_recs; i++)
   2323         {
   2324             ps_mem_rec->pv_base = ih264a_aligned_malloc(ps_mem_rec->u4_mem_alignment,
   2325                                            ps_mem_rec->u4_mem_size);
   2326             if(ps_mem_rec->pv_base == NULL)
   2327             {
   2328                 sprintf(ac_error, "Allocation failure for mem record id %d size %d\n",
   2329                         i, ps_mem_rec->u4_mem_size);
   2330                 codec_exit(ac_error);
   2331             }
   2332             total_size += ps_mem_rec->u4_mem_size;
   2333 
   2334             ps_mem_rec++;
   2335         }
   2336         printf("\nTotal memory for codec %d\n", total_size);
   2337     }
   2338 
   2339 
   2340     /*************************************************************************/
   2341     /*                        Codec Instance Creation                        */
   2342     /*************************************************************************/
   2343     {
   2344         ih264e_init_ip_t s_init_ip;
   2345         ih264e_init_op_t s_init_op;
   2346 
   2347         ps_enc = s_app_ctxt.ps_mem_rec[0].pv_base;
   2348         ps_enc->u4_size = sizeof(iv_obj_t);
   2349         ps_enc->pv_fxns = ih264e_api_function;
   2350         s_app_ctxt.ps_enc = ps_enc;
   2351 
   2352         s_init_ip.s_ive_ip.u4_size = sizeof(ih264e_init_ip_t);
   2353         s_init_op.s_ive_op.u4_size = sizeof(ih264e_init_op_t);
   2354 
   2355         s_init_ip.s_ive_ip.e_cmd = IV_CMD_INIT;
   2356         s_init_ip.s_ive_ip.u4_num_mem_rec = s_app_ctxt.u4_num_mem_rec;
   2357         s_init_ip.s_ive_ip.ps_mem_rec = s_app_ctxt.ps_mem_rec;
   2358         s_init_ip.s_ive_ip.u4_max_wd = s_app_ctxt.u4_max_wd;
   2359         s_init_ip.s_ive_ip.u4_max_ht = s_app_ctxt.u4_max_ht;
   2360         s_init_ip.s_ive_ip.u4_max_ref_cnt = DEFAULT_MAX_REF_FRM;
   2361         s_init_ip.s_ive_ip.u4_max_reorder_cnt = DEFAULT_MAX_REORDER_FRM;
   2362         s_init_ip.s_ive_ip.u4_max_level = s_app_ctxt.u4_max_level;
   2363         s_init_ip.s_ive_ip.e_inp_color_fmt = s_app_ctxt.e_inp_color_fmt;
   2364         if(s_app_ctxt.u4_recon_enable || s_app_ctxt.u4_psnr_enable || s_app_ctxt.u4_chksum_enable)
   2365         {
   2366             s_init_ip.s_ive_ip.u4_enable_recon           = 1;
   2367         }
   2368         else
   2369         {
   2370             s_init_ip.s_ive_ip.u4_enable_recon           = 0;
   2371         }
   2372         s_init_ip.s_ive_ip.e_recon_color_fmt    = s_app_ctxt.e_recon_color_fmt;
   2373         s_init_ip.s_ive_ip.e_rc_mode            = s_app_ctxt.u4_rc;
   2374         s_init_ip.s_ive_ip.u4_max_framerate     = s_app_ctxt.u4_max_frame_rate;
   2375         s_init_ip.s_ive_ip.u4_max_bitrate       = s_app_ctxt.u4_max_bitrate;
   2376         s_init_ip.s_ive_ip.u4_num_bframes       = s_app_ctxt.u4_num_bframes;
   2377         s_init_ip.s_ive_ip.e_content_type       = IV_PROGRESSIVE;
   2378         s_init_ip.s_ive_ip.u4_max_srch_rng_x    = DEFAULT_MAX_SRCH_RANGE_X;
   2379         s_init_ip.s_ive_ip.u4_max_srch_rng_y    = DEFAULT_MAX_SRCH_RANGE_Y;
   2380         s_init_ip.s_ive_ip.e_slice_mode         = s_app_ctxt.u4_slice_mode;
   2381         s_init_ip.s_ive_ip.u4_slice_param       = s_app_ctxt.u4_slice_param;
   2382         s_init_ip.s_ive_ip.e_arch               = s_app_ctxt.e_arch;
   2383         s_init_ip.s_ive_ip.e_soc                = s_app_ctxt.e_soc;
   2384 
   2385         status = ih264e_api_function(ps_enc, &s_init_ip, &s_init_op);
   2386 
   2387         if(status != IV_SUCCESS)
   2388         {
   2389             sprintf(ac_error, "Init memory records failed = 0x%x\n",
   2390                     s_init_op.s_ive_op.u4_error_code);
   2391             codec_exit(ac_error);
   2392         }
   2393     }
   2394 
   2395     /*************************************************************************/
   2396     /*                        set processor details                          */
   2397     /*************************************************************************/
   2398     {
   2399         ih264e_ctl_set_num_cores_ip_t s_ctl_set_num_cores_ip;
   2400         ih264e_ctl_set_num_cores_op_t s_ctl_set_num_cores_op;
   2401         s_ctl_set_num_cores_ip.s_ive_ip.e_cmd = IVE_CMD_VIDEO_CTL;
   2402         s_ctl_set_num_cores_ip.s_ive_ip.e_sub_cmd = IVE_CMD_CTL_SET_NUM_CORES;
   2403         s_ctl_set_num_cores_ip.s_ive_ip.u4_num_cores = s_app_ctxt.u4_num_cores;
   2404         s_ctl_set_num_cores_ip.s_ive_ip.u4_timestamp_high = 0;
   2405         s_ctl_set_num_cores_ip.s_ive_ip.u4_timestamp_low = 0;
   2406         s_ctl_set_num_cores_ip.s_ive_ip.u4_size = sizeof(ih264e_ctl_set_num_cores_ip_t);
   2407 
   2408         s_ctl_set_num_cores_op.s_ive_op.u4_size = sizeof(ih264e_ctl_set_num_cores_op_t);
   2409 
   2410         status = ih264e_api_function(ps_enc, (void *) &s_ctl_set_num_cores_ip,
   2411                 (void *) &s_ctl_set_num_cores_op);
   2412         if(status != IV_SUCCESS)
   2413         {
   2414             sprintf(ac_error, "Unable to set processor params = 0x%x\n",
   2415                     s_ctl_set_num_cores_op.s_ive_op.u4_error_code);
   2416             codec_exit(ac_error);
   2417         }
   2418 
   2419     }
   2420 
   2421     /*************************************************************************/
   2422     /*                        Get Codec Version                              */
   2423     /*************************************************************************/
   2424     {
   2425         ih264e_ctl_getversioninfo_ip_t s_ctl_set_getversioninfo_ip;
   2426         ih264e_ctl_getversioninfo_op_t s_ctl_set_getversioninfo_op;
   2427         CHAR ac_version_string[STRLENGTH];
   2428         s_ctl_set_getversioninfo_ip.s_ive_ip.e_cmd = IVE_CMD_VIDEO_CTL;
   2429         s_ctl_set_getversioninfo_ip.s_ive_ip.e_sub_cmd = IVE_CMD_CTL_GETVERSION;
   2430         s_ctl_set_getversioninfo_ip.s_ive_ip.pu1_version = (UWORD8 *)ac_version_string;
   2431         s_ctl_set_getversioninfo_ip.s_ive_ip.u4_version_bufsize = sizeof(ac_version_string);
   2432         s_ctl_set_getversioninfo_ip.s_ive_ip.u4_size = sizeof(ih264e_ctl_getversioninfo_ip_t);
   2433         s_ctl_set_getversioninfo_op.s_ive_op.u4_size = sizeof(ih264e_ctl_getversioninfo_op_t);
   2434 
   2435         status = ih264e_api_function(ps_enc, (void *) &s_ctl_set_getversioninfo_ip,
   2436                 (void *) &s_ctl_set_getversioninfo_op);
   2437         if(status != IV_SUCCESS)
   2438         {
   2439             sprintf(ac_error, "Unable to get codec version = 0x%x\n",
   2440                     s_ctl_set_getversioninfo_op.s_ive_op.u4_error_code);
   2441             codec_exit(ac_error);
   2442         }
   2443         printf("CODEC VERSION %s\n", ac_version_string);
   2444     }
   2445 
   2446     /*************************************************************************/
   2447     /*                      Get I/O Buffer Requirement                       */
   2448     /*************************************************************************/
   2449     {
   2450         ih264e_ctl_getbufinfo_ip_t s_get_buf_info_ip;
   2451         ih264e_ctl_getbufinfo_op_t s_get_buf_info_op;
   2452 
   2453         s_get_buf_info_ip.s_ive_ip.u4_size = sizeof(ih264e_ctl_getbufinfo_ip_t);
   2454         s_get_buf_info_op.s_ive_op.u4_size = sizeof(ih264e_ctl_getbufinfo_op_t);
   2455 
   2456         s_get_buf_info_ip.s_ive_ip.e_cmd = IVE_CMD_VIDEO_CTL;
   2457         s_get_buf_info_ip.s_ive_ip.e_sub_cmd = IVE_CMD_CTL_GETBUFINFO;
   2458         s_get_buf_info_ip.s_ive_ip.u4_max_ht = s_app_ctxt.u4_max_ht;
   2459         s_get_buf_info_ip.s_ive_ip.u4_max_wd = s_app_ctxt.u4_max_wd;
   2460         s_get_buf_info_ip.s_ive_ip.e_inp_color_fmt = s_app_ctxt.e_inp_color_fmt;
   2461 
   2462         status = ih264e_api_function(ps_enc, &s_get_buf_info_ip, &s_get_buf_info_op);
   2463 
   2464         if (status != IV_SUCCESS)
   2465         {
   2466             sprintf(ac_error, "Unable to get I/O buffer requirements = 0x%x\n",
   2467                     s_get_buf_info_op.s_ive_op.u4_error_code);
   2468             codec_exit(ac_error);
   2469         }
   2470         s_app_ctxt.s_get_buf_info_op = s_get_buf_info_op;
   2471     }
   2472 
   2473     /*****************************************************************************/
   2474     /* Add the following initializations based on the parameters in context      */
   2475     /*****************************************************************************/
   2476 
   2477 
   2478     /*****************************************************************************/
   2479     /*   Video control  Set Frame dimensions                                     */
   2480     /*****************************************************************************/
   2481     s_app_ctxt.u4_strd = s_app_ctxt.u4_wd;
   2482     set_dimensions(&s_app_ctxt, 0, 0);
   2483 
   2484     /*****************************************************************************/
   2485     /*   Video control  Set Frame rates                                          */
   2486     /*****************************************************************************/
   2487     set_frame_rate(&s_app_ctxt, 0, 0);
   2488 
   2489     /*****************************************************************************/
   2490     /*   Video control  Set IPE Params                                           */
   2491     /*****************************************************************************/
   2492     set_ipe_params(&s_app_ctxt, 0, 0);
   2493 
   2494     /*****************************************************************************/
   2495     /*   Video control  Set Bitrate                                              */
   2496     /*****************************************************************************/
   2497     set_bit_rate(&s_app_ctxt, 0, 0);
   2498 
   2499     /*****************************************************************************/
   2500     /*   Video control  Set QP                                                   */
   2501     /*****************************************************************************/
   2502     set_qp(&s_app_ctxt,0,0);
   2503 
   2504     /*****************************************************************************/
   2505     /*   Video control  Set AIR params                                           */
   2506     /*****************************************************************************/
   2507     set_air_params(&s_app_ctxt,0,0);
   2508 
   2509     /*****************************************************************************/
   2510     /*   Video control  Set VBV params                                           */
   2511     /*****************************************************************************/
   2512     set_vbv_params(&s_app_ctxt,0,0);
   2513 
   2514     /*****************************************************************************/
   2515     /*   Video control  Set Motion estimation params                             */
   2516     /*****************************************************************************/
   2517     set_me_params(&s_app_ctxt,0,0);
   2518 
   2519     /*****************************************************************************/
   2520     /*   Video control  Set GOP params                                           */
   2521     /*****************************************************************************/
   2522     set_gop_params(&s_app_ctxt, 0, 0);
   2523 
   2524     /*****************************************************************************/
   2525     /*   Video control  Set Deblock params                                       */
   2526     /*****************************************************************************/
   2527     set_deblock_params(&s_app_ctxt, 0, 0);
   2528 
   2529     /*****************************************************************************/
   2530     /*   Video control  Set Profile params                                       */
   2531     /*****************************************************************************/
   2532     set_profile_params(&s_app_ctxt, 0, 0);
   2533 
   2534     /*****************************************************************************/
   2535     /*   Video control Set in Encode header mode                                 */
   2536     /*****************************************************************************/
   2537     set_enc_mode(&s_app_ctxt, 0, 0, IVE_ENC_MODE_PICTURE);
   2538 
   2539     /*****************************************************************************/
   2540     /*   Video usability information                                             */
   2541     /*****************************************************************************/
   2542     set_vui_params(&s_app_ctxt);
   2543 
   2544 #ifdef IOS
   2545     /* Correct file paths */
   2546     sprintf(filename_with_path, "%s/%s", documentdir, s_app_ctxt.ac_ip_fname);
   2547     strcpy (s_app_ctxt.ac_ip_fname, filename_with_path);
   2548 
   2549     sprintf(filename_with_path, "%s/%s", documentdir, s_app_ctxt.ac_op_fname);
   2550     strcpy (s_app_ctxt.ac_op_fname, filename_with_path);
   2551 
   2552     sprintf(filename_with_path, "%s/%s", documentdir, s_app_ctxt.ac_recon_fname);
   2553     strcpy (s_app_ctxt.ac_recon_fname, filename_with_path);
   2554 
   2555     sprintf(filename_with_path, "%s/%s", documentdir, s_app_ctxt.ac_chksum_fname);
   2556     strcpy (s_app_ctxt.ac_chksum_fname, filename_with_path);
   2557 
   2558     sprintf(filename_with_path, "%s/%s", documentdir, s_app_ctxt.ac_mb_info_fname);
   2559     strcpy (s_app_ctxt.ac_mb_info_fname, filename_with_path);
   2560 
   2561     sprintf(filename_with_path, "%s/%s", documentdir, s_app_ctxt.ac_pic_info_fname);
   2562     strcpy (s_app_ctxt.ac_pic_info_fname, filename_with_path);
   2563 #endif
   2564 
   2565     /*************************************************************************/
   2566     /*               begin encoding                                          */
   2567     /*************************************************************************/
   2568 
   2569     synchronous_encode(ps_enc, &s_app_ctxt);
   2570 
   2571     {
   2572         DOUBLE bytes_per_frame;
   2573         DOUBLE bytes_per_second;
   2574         WORD32 achieved_bitrate;
   2575 
   2576         if(s_app_ctxt.u4_pics_cnt != 0)
   2577         {
   2578             bytes_per_frame = (s_app_ctxt.u4_total_bytes) / (s_app_ctxt.u4_pics_cnt);
   2579         }
   2580         else
   2581         {
   2582             bytes_per_frame = 0;
   2583         }
   2584         bytes_per_second = (bytes_per_frame * s_app_ctxt.u4_tgt_frame_rate);
   2585 
   2586         achieved_bitrate = bytes_per_second * 8;
   2587 
   2588         printf("\nEncoding Completed\n");
   2589         printf("Summary\n");
   2590         printf("Input filename                  : %s\n", s_app_ctxt.ac_ip_fname);
   2591         printf("Output filename                 : %s\n", s_app_ctxt.ac_op_fname);
   2592         printf("Output Width                    : %-4d\n", s_app_ctxt.u4_wd);
   2593         printf("Output Height                   : %-4d\n", s_app_ctxt.u4_ht);
   2594         printf("Target Bitrate (bps)            : %-4d\n", s_app_ctxt.u4_bitrate);
   2595         printf("Achieved Bitrate (bps)          : %-4d\n", achieved_bitrate);
   2596         printf("Average Time per Frame          : %-4d\n", s_app_ctxt.avg_time);
   2597         printf("Achieved FPS                    : %-4.2f\n", 1000000.0 / s_app_ctxt.avg_time);
   2598     }
   2599 
   2600 
   2601     /*************************************************************************/
   2602     /*                         Close Codec Instance                         */
   2603     /*************************************************************************/
   2604     {
   2605         ih264e_retrieve_mem_rec_ip_t s_retrieve_mem_ip;
   2606         ih264e_retrieve_mem_rec_op_t s_retrieve_mem_op;
   2607         iv_mem_rec_t *ps_mem_rec;
   2608         s_retrieve_mem_ip.s_ive_ip.u4_size =
   2609                         sizeof(ih264e_retrieve_mem_rec_ip_t);
   2610         s_retrieve_mem_op.s_ive_op.u4_size =
   2611                         sizeof(ih264e_retrieve_mem_rec_op_t);
   2612 
   2613         s_retrieve_mem_ip.s_ive_ip.e_cmd = IV_CMD_RETRIEVE_MEMREC;
   2614         s_retrieve_mem_ip.s_ive_ip.ps_mem_rec = s_app_ctxt.ps_mem_rec;
   2615 
   2616         status = ih264e_api_function(ps_enc, &s_retrieve_mem_ip,
   2617                                           &s_retrieve_mem_op);
   2618 
   2619         if(status != IV_SUCCESS)
   2620         {
   2621             sprintf(ac_error, "Unable to retrieve memory records = 0x%x\n",
   2622                     s_retrieve_mem_op.s_ive_op.u4_error_code);
   2623             codec_exit(ac_error);
   2624         }
   2625 
   2626         /* Free memory records */
   2627         ps_mem_rec = s_app_ctxt.ps_mem_rec;
   2628         for(i = 0; i < num_mem_recs; i++)
   2629         {
   2630             ih264a_aligned_free(ps_mem_rec->pv_base);
   2631             ps_mem_rec++;
   2632         }
   2633 
   2634         free(s_app_ctxt.ps_mem_rec);
   2635 
   2636     }
   2637 
   2638     return 0;
   2639 }
   2640 
   2641 
   2642 #ifdef  ANDROID_NDK
   2643 int raise(int a)
   2644 {
   2645     printf("Divide by zero\n");
   2646     return 0;
   2647 }
   2648 void __aeabi_assert(const char *assertion, const char *file, unsigned int line)
   2649 {
   2650     return;
   2651 }
   2652 #endif
   2653