From 3c1bb7450a7ac51133d8af8082154afdb3dae737 Mon Sep 17 00:00:00 2001 From: Ram Mohan Date: Tue, 3 Oct 2023 17:35:13 +0530 Subject: [PATCH] avcenc: clean up sample application This commit does not introduce any new functionality. This is a cosmetic change. It removes redundant comments, unused variables, indents to a common guideline. --- examples/avcenc/app.h | 155 +-- examples/avcenc/input.c | 188 ++-- examples/avcenc/main.c | 2278 +++++++++++++++++++------------------- examples/avcenc/output.c | 63 +- examples/avcenc/psnr.c | 140 +-- examples/avcenc/psnr.h | 50 +- examples/avcenc/recon.c | 161 +-- 7 files changed, 1538 insertions(+), 1497 deletions(-) diff --git a/examples/avcenc/app.h b/examples/avcenc/app.h index 4abbe541..d5e67418 100644 --- a/examples/avcenc/app.h +++ b/examples/avcenc/app.h @@ -17,23 +17,24 @@ ***************************************************************************** * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore */ -/*****************************************************************************/ -/* */ -/* File Name : app.h */ -/* */ -/* Description : This file contains all the necessary structure and */ -/* enumeration definitions needed for the Application */ -/* */ -/* List of Functions : */ -/* */ -/* Issues / Problems : None */ -/* */ -/* Revision History : */ -/* */ -/* DD MM YYYY Author(s) Changes (Describe the changes made) */ -/* 26 08 2010 Ittiam Draft */ -/* */ -/*****************************************************************************/ + +/** +******************************************************************************* +* @file +* app.h +* +* @brief +* This file contains all the necessary structure and enumeration definitions +* needed for the Application +* +* @author +* ittiam +* +* @remarks +* none +* +******************************************************************************* +*/ #ifndef _APP_H_ #define _APP_H_ @@ -45,6 +46,7 @@ #else #include #endif + /*****************************************************************************/ /* Function Macros */ /*****************************************************************************/ @@ -56,7 +58,6 @@ /*****************************************************************************/ /* Constant Macros */ /*****************************************************************************/ - #define DEFAULT_NUM_INPUT_BUFS 32 #define DEFAULT_MAX_INPUT_BUFS 32 @@ -66,24 +67,12 @@ #define DEFAULT_NUM_RECON_BUFS 32 #define DEFAULT_MAX_RECON_BUFS DEFAULT_NUM_RECON_BUFS - -#define LEN_STATUS_BUFFER (10 * 1024) -#define MAX_VBV_BUFF_SIZE (120 * 16384) -#define MAX_NUM_IO_BUFS 3 - #define DEFAULT_MAX_REF_FRM 2 #define DEFAULT_MAX_REORDER_FRM 0 -#define DEFAULT_QP_MIN 4 -#define DEFAULT_QP_MAX 51 -#define DEFAULT_MAX_BITRATE 240000000 -#define DEFAULT_NUM_BFRAMES 0 #define DEFAULT_MAX_SRCH_RANGE_X 256 #define DEFAULT_MAX_SRCH_RANGE_Y 256 -#define DEFAULT_MAX_FRAMERATE 120000 -#define DEFAULT_NUM_CORES 1 -#define DEFAULT_NUM_CORES_PRE_ENC 0 -#define DEFAULT_FPS 30 -#define DEFAULT_ENC_SPEED 100 +#define DEFAULT_QP_MIN 4 +#define DEFAULT_QP_MAX 49 #define DEFAULT_MEM_REC_CNT 0 #define DEFAULT_RECON_ENABLE 0 @@ -92,7 +81,9 @@ #define DEFAULT_NUM_FRMS 0xFFFFFFFF #define DEFAULT_INP_COLOR_FMT IV_YUV_420SP_UV #define DEFAULT_RECON_COLOR_FMT IV_YUV_420P +#define DEFAULT_NUM_CORES 1 #define DEFAULT_LOOPBACK 0 +#define DEFAULT_MAX_FRAMERATE 120 #define DEFAULT_SRC_FRAME_RATE 30 #define DEFAULT_TGT_FRAME_RATE 30 #define DEFAULT_MAX_WD 1920 @@ -106,24 +97,25 @@ #define DEFAULT_ENABLE_FAST_SAD 0 #define DEFAULT_ENABLE_ALT_REF 0 #define DEFAULT_RC 1 +#define DEFAULT_MAX_BITRATE 240000000 #define DEFAULT_BITRATE 6000000 #define DEFAULT_I_QP 25 #define DEFAULT_I_QP_MAX DEFAULT_QP_MAX -#define DEFAULT_I_QP_MIN 0 +#define DEFAULT_I_QP_MIN DEFAULT_QP_MIN #define DEFAULT_P_QP 28 #define DEFAULT_P_QP_MAX DEFAULT_QP_MAX -#define DEFAULT_P_QP_MIN 0 +#define DEFAULT_P_QP_MIN DEFAULT_QP_MIN #define DEFAULT_B_QP 28 #define DEFAULT_B_QP_MAX DEFAULT_QP_MAX -#define DEFAULT_B_QP_MIN 0 +#define DEFAULT_B_QP_MIN DEFAULT_QP_MIN #define DEFAULT_AIR 0 #define DEFAULT_AIR_REFRESH_PERIOD 30 -#define DEFAULT_SRCH_RNG_X 64 -#define DEFAULT_SRCH_RNG_Y 48 +#define DEFAULT_SRCH_RNG_X 16 +#define DEFAULT_SRCH_RNG_Y 16 #define DEFAULT_I_INTERVAL 30 -#define DEFAULT_IDR_INTERVAL 1000 +#define DEFAULT_IDR_INTERVAL 1200 #define DEFAULT_CONSTRAINED_INTRAPRED 0 -#define DEFAULT_B_FRAMES 0 +#define DEFAULT_NUM_BFRAMES 0 #define DEFAULT_DISABLE_DEBLK_LEVEL 0 #define DEFAULT_HPEL 1 #define DEFAULT_QPEL 1 @@ -132,7 +124,17 @@ #define DEFAULT_SLICE_MODE 0 #define DEFAULT_SLICE_PARAM 256 #define DEFAULT_ENTROPY_CODING_MODE 0 - +#define NUM_SEI_MDCV_PRIMARIES 3 +#define NUM_SEI_CCV_PRIMARIES 3 +#define SII_MAX_SUB_LAYERS 8 +#define SII_SUB_LAYER_IDX 0 +#define SHUTTER_INTERVAL_INFO_PRESENT_FLAG 1 +#define SII_TIME_SCALE 24000000 +#define FIXED_SHUTTER_INTERVAL_WITHIN_CVS_FLAG 0 +#define SII_NUM_UNITS_IN_SHUTTER_INTERVAL 480000 +#define SII_MAX_SUB_LAYERS_MINUS1 (SII_MAX_SUB_LAYERS - 1) +#define SUB_LAYER_NUM_UNITS_IN_SHUTTER_INTERVAL_HFR 480000 +#define SUB_LAYER_NUM_UNITS_IN_SHUTTER_INTERVAL_SFR 240000 #define DEFAULT_MAX_DISPLAY_MASTERING_LUMINANCE 50000 #define DEFAULT_MIN_DISPLAY_MASTERING_LUMINANCE 1 @@ -184,6 +186,12 @@ /*****************************************************************************/ /* Structure definitions */ /*****************************************************************************/ + +/** +************************************************************************** +* @brief input buffer context +************************************************************************** +*/ typedef struct { UWORD8 *pu1_buf; @@ -191,10 +199,15 @@ typedef struct UWORD32 u4_timestamp_low; UWORD32 u4_timestamp_high; UWORD32 u4_is_free; - void *pv_mb_info; - void *pv_pic_info; -}input_buf_t; - + void *pv_mb_info; + void *pv_pic_info; +} input_buf_t; + +/** +************************************************************************** +* @brief output buffer context +************************************************************************** +*/ typedef struct { UWORD8 *pu1_buf; @@ -202,8 +215,13 @@ typedef struct UWORD32 u4_timestamp_low; UWORD32 u4_timestamp_high; UWORD32 u4_is_free; -}output_buf_t; +} output_buf_t; +/** +************************************************************************** +* @brief recon buffer context +************************************************************************** +*/ typedef struct { UWORD8 *pu1_buf; @@ -211,8 +229,13 @@ typedef struct UWORD32 u4_timestamp_low; UWORD32 u4_timestamp_high; UWORD32 u4_is_free; -}recon_buf_t; +} recon_buf_t; +/** +************************************************************************** +* @brief app context +************************************************************************** +*/ typedef struct { iv_obj_t *ps_enc; @@ -233,12 +256,13 @@ typedef struct IV_ARCH_T e_arch; IV_SOC_T e_soc; - WORD32 header_generated; + WORD32 header_generated; void *pv_codec_obj; UWORD32 u4_num_cores; UWORD32 u4_pre_enc_me; UWORD32 u4_pre_enc_ipe; + CHAR ac_ip_fname[STRLENGTH]; CHAR ac_op_fname[STRLENGTH]; CHAR ac_recon_fname[STRLENGTH]; @@ -246,7 +270,6 @@ typedef struct CHAR ac_mb_info_fname[STRLENGTH]; CHAR ac_pic_info_fname[STRLENGTH]; - FILE *fp_ip; FILE *fp_op; FILE *fp_recon; @@ -254,8 +277,6 @@ typedef struct FILE *fp_psnr_ip; FILE *fp_mb_info; FILE *fp_pic_info; - FILE *fp_dump_op; - UWORD32 u4_loopback; UWORD32 u4_max_frame_rate; @@ -266,13 +287,11 @@ typedef struct UWORD32 u4_max_level; UWORD32 u4_strd; - UWORD32 u4_wd; UWORD32 u4_ht; UWORD32 u4_psnr_enable; - UWORD32 u4_enc_speed; UWORD32 u4_me_speed; UWORD32 u4_enable_fast_sad; @@ -280,9 +299,9 @@ typedef struct UWORD32 u4_rc; UWORD32 u4_max_bitrate; UWORD32 u4_bitrate; - UWORD32 u4_i_qp,u4_i_qp_max,u4_i_qp_min; - UWORD32 u4_p_qp,u4_p_qp_max,u4_p_qp_min; - UWORD32 u4_b_qp,u4_b_qp_max,u4_b_qp_min; + UWORD32 u4_i_qp, u4_i_qp_max, u4_i_qp_min; + UWORD32 u4_p_qp, u4_p_qp_max, u4_p_qp_min; + UWORD32 u4_b_qp, u4_b_qp_max, u4_b_qp_min; UWORD32 u4_air; UWORD32 u4_air_refresh_period; UWORD32 u4_srch_rng_x; @@ -290,14 +309,12 @@ typedef struct UWORD32 u4_i_interval; UWORD32 u4_idr_interval; UWORD32 u4_constrained_intra_pred; - UWORD32 u4_b_frames; UWORD32 u4_num_bframes; UWORD32 u4_disable_deblk_level; UWORD32 u4_hpel; UWORD32 u4_qpel; UWORD32 u4_enable_intra_4x4; IV_PROFILE_T e_profile; - UWORD32 u4_slice_mode; UWORD32 u4_slice_param; UWORD32 u4_entropy_coding_mode; @@ -311,17 +328,17 @@ typedef struct output_buf_t as_output_buf[DEFAULT_MAX_OUTPUT_BUFS]; recon_buf_t as_recon_buf[DEFAULT_MAX_RECON_BUFS]; - DOUBLE adbl_psnr[3]; + DOUBLE adbl_psnr[3]; UWORD32 u4_psnr_cnt; - UWORD8 *pu1_psnr_buf; - UWORD8 u4_psnr_buf_size; + UWORD8 *pu1_psnr_buf; + UWORD8 u4_psnr_buf_size; UWORD32 u4_vbv_buffer_delay; UWORD32 u4_vbv_buf_size; - TIMER enc_start_time; - TIMER enc_last_time; - WORD32 avg_time; + TIMER enc_start_time; + TIMER enc_last_time; + WORD32 avg_time; UWORD32 u4_sei_mdcv_params_present_flag; UWORD32 au4_display_primaries_x[NUM_SEI_MDCV_PRIMARIES]; @@ -369,6 +386,7 @@ typedef struct } app_ctxt_t; + /*****************************************************************************/ /* Function Declarations */ /*****************************************************************************/ @@ -391,10 +409,17 @@ void free_input(app_ctxt_t *ps_app_ctxt); void free_recon(app_ctxt_t *ps_app_ctxt); void free_output(app_ctxt_t *ps_app_ctxt); -void init_raw_buf_descr(app_ctxt_t *ps_app_ctxt, iv_raw_buf_t *ps_raw_buf, UWORD8 *pu1_buf, IV_COLOR_FORMAT_T e_color_fmt); +void init_raw_buf_descr(app_ctxt_t *ps_app_ctxt, + iv_raw_buf_t *ps_raw_buf, + UWORD8 *pu1_buf, + IV_COLOR_FORMAT_T e_color_fmt); #ifndef MD5_DISABLE -void calc_md5_cksum(UWORD8 *pu1_inbuf,UWORD32 u4_stride,UWORD32 u4_width,UWORD32 u4_height,UWORD8 *pu1_cksum_p ); +void calc_md5_cksum(UWORD8 *pu1_inbuf, + UWORD32 u4_stride, + UWORD32 u4_width, + UWORD32 u4_height, + UWORD8 *pu1_cksum_p); #else #define calc_md5_cksum(a, b, c, d, e) #endif diff --git a/examples/avcenc/input.c b/examples/avcenc/input.c index bf92d567..80a637d2 100644 --- a/examples/avcenc/input.c +++ b/examples/avcenc/input.c @@ -18,6 +18,23 @@ * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore */ +/** +******************************************************************************* +* @file +* input.c +* +* @brief +* Contains functions necessary for managing input buffers +* +* @author +* ittiam +* +* @remarks +* none +* +******************************************************************************* +*/ + /*****************************************************************************/ /* File Includes */ /*****************************************************************************/ @@ -30,7 +47,6 @@ /* User include files */ #include "ih264_typedefs.h" -#include "ih264_defs.h" #include "iv2.h" #include "ive2.h" #include "ih264e.h" @@ -50,6 +66,11 @@ /* Function Definitions */ /*****************************************************************************/ +/** +************************************************************************** +* @brief read pic level metadata from a file +************************************************************************** +*/ IV_STATUS_T read_pic_info(app_ctxt_t *ps_app_ctxt, void *pv_pic_info) { IV_STATUS_T ret = IV_SUCCESS; @@ -77,6 +98,11 @@ IV_STATUS_T read_pic_info(app_ctxt_t *ps_app_ctxt, void *pv_pic_info) return ret; } +/** +************************************************************************** +* @brief read mb level metadata from a file +************************************************************************** +*/ IV_STATUS_T read_mb_info(app_ctxt_t *ps_app_ctxt, void *pv_mb_info) { IV_STATUS_T ret = IV_SUCCESS; @@ -84,7 +110,7 @@ IV_STATUS_T read_mb_info(app_ctxt_t *ps_app_ctxt, void *pv_mb_info) WORD32 size; WORD32 bytes; - num_mbs = ALIGN16(ps_app_ctxt->u4_wd) * ALIGN16(ps_app_ctxt->u4_ht); + num_mbs = ALIGN16(ps_app_ctxt->u4_wd) * ALIGN16(ps_app_ctxt->u4_ht); num_mbs /= 256; switch(ps_app_ctxt->u4_mb_info_type) @@ -117,52 +143,55 @@ IV_STATUS_T read_mb_info(app_ctxt_t *ps_app_ctxt, void *pv_mb_info) return ret; } +/** +************************************************************************** +* @brief read input from a file +************************************************************************** +*/ IV_STATUS_T read_input(FILE *fp, iv_raw_buf_t *ps_raw_buf) { - WORD32 bytes; - WORD32 wd, ht, strd; - UWORD8 *pu1_buf; WORD32 i; - WORD32 comp; - WORD32 num_comp; - if (IV_YUV_422ILE == ps_raw_buf->e_color_fmt) + if(IV_YUV_422ILE == ps_raw_buf->e_color_fmt) { - wd = ps_raw_buf->au4_wd[0]; - ht = ps_raw_buf->au4_ht[0]; - strd = ps_raw_buf->au4_strd[0]; - pu1_buf = ps_raw_buf->apv_bufs[0]; + WORD32 wd = ps_raw_buf->au4_wd[0]; + WORD32 ht = ps_raw_buf->au4_ht[0]; + WORD32 strd = ps_raw_buf->au4_strd[0]; + UWORD8 *pu1_buf = ps_raw_buf->apv_bufs[0]; for(i = 0; i < ht; i++) { - bytes = fread(pu1_buf, sizeof(UWORD8), wd, fp); - if(bytes != wd ) + WORD32 bytes = fread(pu1_buf, sizeof(UWORD8), wd, fp); + + if(bytes != wd) { - return(IV_FAIL); + return (IV_FAIL); } pu1_buf += strd; } } else { - num_comp = 2; + WORD32 num_comp = 2; + WORD32 comp_idx; if(IV_YUV_420P == ps_raw_buf->e_color_fmt) num_comp = 3; - for(comp = 0; comp < num_comp; comp++) + for(comp_idx = 0; comp_idx < num_comp; comp_idx++) { - wd = ps_raw_buf->au4_wd[comp]; - ht = ps_raw_buf->au4_ht[comp]; - strd = ps_raw_buf->au4_strd[comp]; - pu1_buf = ps_raw_buf->apv_bufs[comp]; + WORD32 wd = ps_raw_buf->au4_wd[comp_idx]; + WORD32 ht = ps_raw_buf->au4_ht[comp_idx]; + WORD32 strd = ps_raw_buf->au4_strd[comp_idx]; + UWORD8 *pu1_buf = ps_raw_buf->apv_bufs[comp_idx]; for(i = 0; i < ht; i++) { - bytes = fread(pu1_buf, sizeof(UWORD8), wd, fp); + WORD32 bytes = fread(pu1_buf, sizeof(UWORD8), wd, fp); + if(bytes != wd) { - return(IV_FAIL); + return (IV_FAIL); } pu1_buf += strd; } @@ -171,53 +200,55 @@ IV_STATUS_T read_input(FILE *fp, iv_raw_buf_t *ps_raw_buf) return IV_SUCCESS; } - +/** +************************************************************************** +* @brief write input to a file +************************************************************************** +*/ IV_STATUS_T dump_input(FILE *fp, iv_raw_buf_t *ps_raw_buf) { - WORD32 bytes; - WORD32 wd, ht, strd; - UWORD8 *pu1_buf; WORD32 i; - WORD32 comp; - WORD32 num_comp; - if (IV_YUV_422ILE == ps_raw_buf->e_color_fmt) + if(IV_YUV_422ILE == ps_raw_buf->e_color_fmt) { - wd = ps_raw_buf->au4_wd[0]; - ht = ps_raw_buf->au4_ht[0]; - strd = ps_raw_buf->au4_strd[0]; - pu1_buf = ps_raw_buf->apv_bufs[0]; + WORD32 wd = ps_raw_buf->au4_wd[0]; + WORD32 ht = ps_raw_buf->au4_ht[0]; + WORD32 strd = ps_raw_buf->au4_strd[0]; + UWORD8 *pu1_buf = ps_raw_buf->apv_bufs[0]; for(i = 0; i < ht; i++) { - bytes = fwrite(pu1_buf, sizeof(UWORD8), wd, fp); - if(bytes != wd ) + WORD32 bytes = fwrite(pu1_buf, sizeof(UWORD8), wd, fp); + + if(bytes != wd) { - return(IV_FAIL); + return (IV_FAIL); } pu1_buf += strd; } } else { - num_comp = 2; + WORD32 num_comp = 2; + WORD32 comp_idx; if(IV_YUV_420P == ps_raw_buf->e_color_fmt) num_comp = 3; - for(comp = 0; comp < num_comp; comp++) + for(comp_idx = 0; comp_idx < num_comp; comp_idx++) { - wd = ps_raw_buf->au4_wd[comp]; - ht = ps_raw_buf->au4_ht[comp]; - strd = ps_raw_buf->au4_strd[comp]; - pu1_buf = ps_raw_buf->apv_bufs[comp]; + WORD32 wd = ps_raw_buf->au4_wd[comp_idx]; + WORD32 ht = ps_raw_buf->au4_ht[comp_idx]; + WORD32 strd = ps_raw_buf->au4_strd[comp_idx]; + UWORD8 *pu1_buf = ps_raw_buf->apv_bufs[comp_idx]; for(i = 0; i < ht; i++) { - bytes = fwrite(pu1_buf, sizeof(UWORD8), wd, fp); + WORD32 bytes = fwrite(pu1_buf, sizeof(UWORD8), wd, fp); + if(bytes != wd) { - return(IV_FAIL); + return (IV_FAIL); } pu1_buf += strd; } @@ -226,77 +257,83 @@ IV_STATUS_T dump_input(FILE *fp, iv_raw_buf_t *ps_raw_buf) return IV_SUCCESS; } +/** +************************************************************************** +* @brief allocate input buffers +************************************************************************** +*/ void allocate_input(app_ctxt_t *ps_app_ctxt) { - WORD32 num_bufs; - WORD32 pic_size; - WORD32 luma_size; - WORD32 chroma_size; + WORD32 luma_size = ps_app_ctxt->u4_wd * ps_app_ctxt->u4_ht; + WORD32 chroma_size = luma_size >> 1; + WORD32 pic_size = luma_size + chroma_size * 2; WORD32 num_mbs; WORD32 i; - UWORD8 *pu1_buf[3]; - ih264e_ctl_getbufinfo_op_t *ps_get_buf_info_op = &ps_app_ctxt->s_get_buf_info_op; - num_bufs = MAX(DEFAULT_NUM_INPUT_BUFS, ps_get_buf_info_op->s_ive_op.u4_min_inp_bufs); + num_bufs = MAX(DEFAULT_NUM_INPUT_BUFS, + ps_get_buf_info_op->s_ive_op.u4_min_inp_bufs); num_bufs = MIN(DEFAULT_MAX_INPUT_BUFS, num_bufs); - /* Size of buffer */ - luma_size = ps_app_ctxt->u4_wd * ps_app_ctxt->u4_ht; - chroma_size = luma_size >> 1; - pic_size = luma_size + chroma_size * 2; - - num_mbs = ALIGN16(ps_app_ctxt->u4_max_wd) * ALIGN16(ps_app_ctxt->u4_max_ht); + num_mbs = ALIGN16(ps_app_ctxt->u4_max_wd) * ALIGN16(ps_app_ctxt->u4_max_ht); num_mbs /= 256; /* Memset the input buffer array to set is_free to 0 */ - memset(ps_app_ctxt->as_input_buf, 0, sizeof(input_buf_t) * DEFAULT_MAX_INPUT_BUFS); + memset(ps_app_ctxt->as_input_buf, 0, + sizeof(input_buf_t) * DEFAULT_MAX_INPUT_BUFS); for(i = 0; i < num_bufs; i++) { - pu1_buf[0] = (UWORD8 *)ih264a_aligned_malloc(16, pic_size); - if(NULL == pu1_buf[0]) + UWORD8 *pu1_buf = (UWORD8 *)ih264a_aligned_malloc(16, pic_size); + if(NULL == pu1_buf) { CHAR ac_error[STRLENGTH]; sprintf(ac_error, "Allocation failed for input buffer of size %d\n", pic_size); codec_exit(ac_error); } - ps_app_ctxt->as_input_buf[i].pu1_buf = pu1_buf[0]; + ps_app_ctxt->as_input_buf[i].pu1_buf = pu1_buf; - pu1_buf[0] = (UWORD8 *)ih264a_aligned_malloc(16, num_mbs * sizeof(ih264e_mb_info_t)); - if(NULL == pu1_buf[0]) + pu1_buf = (UWORD8 *)ih264a_aligned_malloc( + 16, num_mbs * sizeof(ih264e_mb_info_t)); + if(NULL == pu1_buf) { CHAR ac_error[STRLENGTH]; - sprintf(ac_error, "Allocation failed for mb info buffer of size %d\n", + sprintf(ac_error, + "Allocation failed for mb info buffer of size %d\n", (WORD32)(num_mbs * sizeof(ih264e_mb_info_t))); codec_exit(ac_error); } - ps_app_ctxt->as_input_buf[i].pv_mb_info = pu1_buf[0]; - pu1_buf[0] = (UWORD8 *)ih264a_aligned_malloc(16, sizeof(ih264e_pic_info2_t)); - if(NULL == pu1_buf[0]) + ps_app_ctxt->as_input_buf[i].pv_mb_info = pu1_buf; + pu1_buf = (UWORD8 *)ih264a_aligned_malloc(16, + sizeof(ih264e_pic_info2_t)); + if(NULL == pu1_buf) { CHAR ac_error[STRLENGTH]; - sprintf(ac_error, "Allocation failed for pic info buffer of size %d\n", - (WORD32) sizeof(ih264e_pic_info2_t)); + sprintf(ac_error, + "Allocation failed for pic info buffer of size %d\n", + (WORD32)sizeof(ih264e_pic_info2_t)); codec_exit(ac_error); } - ps_app_ctxt->as_input_buf[i].pv_pic_info = pu1_buf[0]; + ps_app_ctxt->as_input_buf[i].pv_pic_info = pu1_buf; ps_app_ctxt->as_input_buf[i].u4_buf_size = pic_size; ps_app_ctxt->as_input_buf[i].u4_is_free = 1; } - return; } - +/** +************************************************************************** +* @brief free input buffers +************************************************************************** +*/ void free_input(app_ctxt_t *ps_app_ctxt) { - WORD32 num_bufs; WORD32 i; - num_bufs = MAX(DEFAULT_NUM_INPUT_BUFS, ps_app_ctxt->s_get_buf_info_op.s_ive_op.u4_min_inp_bufs); + num_bufs = MAX(DEFAULT_NUM_INPUT_BUFS, + ps_app_ctxt->s_get_buf_info_op.s_ive_op.u4_min_inp_bufs); num_bufs = MIN(DEFAULT_MAX_INPUT_BUFS, num_bufs); for(i = 0; i < num_bufs; i++) @@ -305,6 +342,5 @@ void free_input(app_ctxt_t *ps_app_ctxt) ih264a_aligned_free(ps_app_ctxt->as_input_buf[i].pv_mb_info); ih264a_aligned_free(ps_app_ctxt->as_input_buf[i].pv_pic_info); } - return; } diff --git a/examples/avcenc/main.c b/examples/avcenc/main.c index 61a4bca1..79629b76 100644 --- a/examples/avcenc/main.c +++ b/examples/avcenc/main.c @@ -18,6 +18,23 @@ * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore */ +/** +******************************************************************************* +* @file +* main.c +* +* @brief +* sample test application +* +* @author +* ittiam +* +* @remarks +* none +* +******************************************************************************* +*/ + /*****************************************************************************/ /* File Includes */ /*****************************************************************************/ @@ -35,22 +52,15 @@ #else #include #endif + /* User include files */ #include "ih264_typedefs.h" -#include "ih264_defs.h" #include "iv2.h" #include "ive2.h" #include "ih264e.h" #include "app.h" #include "psnr.h" -/* Function declarations */ -#ifndef MD5_DISABLE -void calc_md5_cksum(UWORD8 *pu1_inbuf,UWORD32 u4_stride,UWORD32 u4_width,UWORD32 u4_height,UWORD8 *pu1_cksum_p ); -#else -#define calc_md5_cksum(a, b, c, d, e) -#endif - /*****************************************************************************/ /* Enums */ /*****************************************************************************/ @@ -126,126 +136,129 @@ typedef enum PIC_INFO_TYPE, } ARGUMENT_T; +/*****************************************************************************/ +/* Structure definitions */ +/*****************************************************************************/ + +/** +************************************************************************** +* @brief argument mapping construct +************************************************************************** +*/ typedef struct { - CHAR argument_shortname[8]; - CHAR argument_name[128]; - ARGUMENT_T argument; - CHAR description[512]; + CHAR argument_shortname[8]; + CHAR argument_name[128]; + ARGUMENT_T argument; + CHAR description[512]; } argument_t; -static const argument_t argument_mapping[] = - { - { "--", "--help", HELP, "Print this help\n" }, - { "-i", "--input", INPUT_FILE, "Input file\n" }, - { "-o", "--output", OUTPUT_FILE, "Output file\n" }, - { "--", "--recon_enable", RECON_ENABLE, "Recon enable flag\n" }, - { "-r", "--recon", RECON_FILE, "Recon file \n" }, - { "--", "--input_chroma_format", INPUT_CHROMA_FORMAT, - "Input Chroma format Supported values YUV_420P, YUV_420SP_UV, YUV_420SP_VU\n" }, - { "--", "--recon_chroma_format", RECON_CHROMA_FORMAT, - "Recon Chroma format Supported values YUV_420P, YUV_420SP_UV, YUV_420SP_VU\n" }, - { "-w", "--width", WD, "Width of input file\n" }, - { "-h", "--height", HT, "Height file\n" }, - { "--", "--start_frame", START_FRM, "Starting frame number\n" }, - { "-f", "--num_frames", NUM_FRMS, "Number of frames to be encoded\n" }, - { "--", "--rc", RC, "Rate control mode 0: Constant Qp, 1: Storage, 2: CBR non low delay, 3: CBR low delay \n" }, - { "--", "--max_framerate", MAX_FRAMERATE, "Maximum frame rate \n" }, - { "--", "--tgt_framerate", TGT_FRAMERATE, "Target frame rate \n" }, - { "--", "--src_framerate", SRC_FRAMERATE, "Source frame rate \n" }, - { "--", "--i_interval", I_INTERVAL, "Intra frame interval \n" }, - { "--", "--idr_interval", IDR_INTERVAL, "IDR frame interval \n" }, - { "--", "--constrained_intrapred", CONSTRAINED_INTRA_PRED, "Constrained IntraPrediction Flag \n" }, - { "--", "--bframes", NUM_B_FRMS, "Maximum number of consecutive B frames \n" }, - { "--", "--speed", ENC_SPEED, "Encoder speed preset 0 (slowest) and 100 (fastest)\n" }, - { "--", "--me_speed", ME_SPEED, "Encoder speed preset 0 (slowest) and 100 (fastest)\n" }, - { "--", "--fast_sad", FAST_SAD, " Flag for faster sad execution\n" }, - { "--", "--alt_ref", ALT_REF , "Flag to enable alternate refernce frames"}, - { "--", "--hpel", HPEL, "Flag to enable/disable Quarter pel estimation \n" }, - { "--", "--qpel", QPEL, "Flag to enable/disable Quarter pel estimation \n" }, - { "--", "--disable_deblock_level", DISABLE_DEBLOCK_LEVEL, - "Disable deblock level - 0 : Enables deblock completely, 1: enables for I and 8th frame , 2: Enables for I only, 3 : disables completely\n" }, - { "--", "--search_range_x", SRCH_RNG_X, "Search range for X \n" }, - { "--", "--search_range_y", SRCH_RNG_Y, "Search range for Y \n" }, - { "--", "--psnr", PSNR, "Enable PSNR computation (Disable while benchmarking performance) \n" }, - { "--", "--pre_enc_me", PRE_ENC_ME, "Flag to enable/disable Pre Enc Motion Estimation\n" }, - { "--", "--pre_enc_ipe", PRE_ENC_IPE, "Flag to enable/disable Pre Enc Intra prediction Estimation\n" }, - { "-n", "--num_cores", NUMCORES, "Number of cores to be used\n" }, - { "--", "--adaptive_intra_refresh", AIR ,"Adaptive Intra Refresh enable/disable\n"}, - { "--", "--air_refresh_period", AIR_REFRESH_PERIOD,"adaptive intra refresh period\n"}, - { "--", "--slice", SLICE_MODE, "Slice mode- 0 :No slice, 1: Bytes per slice, 2: MB/CTB per slice \n" }, - { "--", "--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" }, - { "--", "--max_wd", MAX_WD, "Maximum width (Default: 1920) \n" }, - { "--", "--max_ht", MAX_HT, "Maximum height (Default: 1088)\n" }, - { "--", "--max_level", MAX_LEVEL, "Maximum Level (Default: 50)\n" }, - { "--", "--arch", ARCH, "Set Architecture. Supported values ARM_NONEON, ARM_A9Q, ARM_A7, ARM_A5, ARM_NEONINTR, X86_GENERIC, X86_SSSE3, X86_SSE4 \n" }, - { "--", "--soc", SOC, "Set SOC. Supported values GENERIC, HISI_37X \n" }, - { "--", "--chksum", CHKSUM_FILE, "Save Check sum file for recon data\n" }, - { "--", "--chksum_enable", CHKSUM_ENABLE, "Recon MD5 Checksum file\n"}, - { "-c", "--config", CONFIG, "config file (Default: enc.cfg)\n" }, - { "--", "--loopback", LOOPBACK, "Enable encoding in a loop\n" }, - { "--", "--profile", PROFILE, "Profile mode: Supported values BASE, MAIN, HIGH\n" }, - { "--", "--max_bitrate", MAX_BITRATE, "Max bitrate\n"}, - { "--", "--bitrate", BITRATE, "Target bitrate\n"}, - { "--", "--qp_i", I_QP, "QP for I frames\n"}, - { "--", "--qp_p", P_QP, "QP for P frames\n"}, - { "--", "--qp_b", B_QP, "QP for B frames\n"}, - { "--", "--qp_i_max", I_QP_MAX, "Max QP for I frames\n"}, - { "--", "--qp_p_max", P_QP_MAX, "Max QP for P frames\n"}, - { "--", "--qp_b_max", B_QP_MAX, "Max QP for B frames\n"}, - { "--", "--qp_i_min", I_QP_MIN, "Min QP for I frames\n"}, - { "--", "--qp_p_min", P_QP_MIN, "Min QP for P frames\n"}, - { "--", "--qp_b_min", B_QP_MIN, "Min QP for B frames\n"}, - { "--", "--entropy", ENTROPY, "Entropy coding mode(0: CAVLC or 1: CABAC)\n"}, - { "--", "--vbv_delay", VBV_DELAY, "VBV buffer delay\n"}, - { "--", "--vbv_size", VBV_SIZE, "VBV buffer size\n"}, - { "-i4", "--intra_4x4_enable", INTRA_4x4_ENABLE, "Intra 4x4 enable \n" }, - { "--", "--mb_info_file", MB_INFO_FILE, "MB info file\n"}, - { "--", "--mb_info_type", MB_INFO_TYPE, "MB info type\n"}, - { "--", "--pic_info_file", PIC_INFO_FILE, "Pic info file\n"}, - { "--", "--pic_info_type", PIC_INFO_TYPE, "Pic info type\n"}, - }; - - - /*****************************************************************************/ -/* Function Declarations */ +/* Global definitions */ /*****************************************************************************/ +/** +************************************************************************** +* @brief list of supported arguments +************************************************************************** +*/ +static const argument_t argument_mapping[] = +{ + { "--", "--help", HELP, "Print this help\n" }, + { "-i", "--input", INPUT_FILE, "Input file\n" }, + { "-o", "--output", OUTPUT_FILE, "Output file\n" }, + { "--", "--recon_enable", RECON_ENABLE, "Recon enable flag\n" }, + { "-r", "--recon", RECON_FILE, "Recon file \n" }, + { "--", "--input_chroma_format", INPUT_CHROMA_FORMAT, + "Input Chroma format Supported values YUV_420P, YUV_420SP_UV, YUV_420SP_VU\n" }, + { "--", "--recon_chroma_format", RECON_CHROMA_FORMAT, + "Recon Chroma format Supported values YUV_420P, YUV_420SP_UV, YUV_420SP_VU\n" }, + { "-w", "--width", WD, "Width of input file\n" }, + { "-h", "--height", HT, "Height of input file\n" }, + { "--", "--start_frame", START_FRM, "Starting frame number\n" }, + { "-f", "--num_frames", NUM_FRMS, "Number of frames to be encoded\n" }, + { "--", "--rc", RC, "Rate control mode 0: Constant Qp, 1: Storage, 2: CBR non low delay \n" }, + { "--", "--max_framerate", MAX_FRAMERATE, "Maximum frame rate \n" }, + { "--", "--tgt_framerate", TGT_FRAMERATE, "Target frame rate \n" }, + { "--", "--src_framerate", SRC_FRAMERATE, "Source frame rate \n" }, + { "--", "--i_interval", I_INTERVAL, "Intra frame interval \n" }, + { "--", "--idr_interval", IDR_INTERVAL, "IDR frame interval \n" }, + { "--", "--constrained_intrapred", CONSTRAINED_INTRA_PRED, "Constrained IntraPrediction Flag \n" }, + { "--", "--bframes", NUM_B_FRMS, "Maximum number of consecutive B frames \n" }, + { "--", "--speed", ENC_SPEED, "Encoder speed preset 0 (slowest) and 100 (fastest)\n" }, + { "--", "--me_speed", ME_SPEED, "Encoder speed preset 0 (slowest) and 100 (fastest)\n" }, + { "--", "--fast_sad", FAST_SAD, "Flag for faster sad execution\n" }, + { "--", "--alt_ref", ALT_REF , "Flag to enable alternate reference frames\n"}, + { "--", "--hpel", HPEL, "Flag to enable/disable Quarter pel estimation \n" }, + { "--", "--qpel", QPEL, "Flag to enable/disable Quarter pel estimation \n" }, + { "--", "--disable_deblock_level", DISABLE_DEBLOCK_LEVEL, + "Disable deblock level - 0 : Enables deblock completely, " + "1: enables for I and 8th frame , 2: Enables for I only, " + "3 : disables completely\n" }, + { "--", "--search_range_x", SRCH_RNG_X, "Search range for X \n" }, + { "--", "--search_range_y", SRCH_RNG_Y, "Search range for Y \n" }, + { "--", "--psnr", PSNR, "Enable PSNR computation (Disable while benchmarking performance) \n" }, + { "--", "--pre_enc_me", PRE_ENC_ME, "Flag to enable/disable Pre Enc Motion Estimation\n" }, + { "--", "--pre_enc_ipe", PRE_ENC_IPE, "Flag to enable/disable Pre Enc Intra prediction Estimation\n" }, + { "-n", "--num_cores", NUMCORES, "Number of cores to be used\n" }, + { "--", "--adaptive_intra_refresh", AIR, "Adaptive Intra Refresh enable/disable\n"}, + { "--", "--air_refresh_period", AIR_REFRESH_PERIOD,"adaptive intra refresh period\n"}, + { "--", "--slice", SLICE_MODE, "Slice mode - 0 :No slice, 1: Bytes per slice, 2: MB/CTB per slice\n" }, + { "--", "--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" }, + { "--", "--max_wd", MAX_WD, "Maximum width (Default: 1920) \n" }, + { "--", "--max_ht", MAX_HT, "Maximum height (Default: 1088)\n" }, + { "--", "--max_level", MAX_LEVEL, "Maximum Level (Default: 50)\n" }, + { "--", "--arch", ARCH, "Set Architecture. Supported values ARM_NONEON, ARM_A9Q, ARM_A7, ARM_A5, ARM_NEONINTR, X86_GENERIC, X86_SSSE3, X86_SSE4 \n" }, + { "--", "--soc", SOC, "Set SOC. Supported values GENERIC\n" }, + { "--", "--chksum", CHKSUM_FILE, "Save Check sum file for recon data\n" }, + { "--", "--chksum_enable", CHKSUM_ENABLE, "Recon MD5 Checksum file\n"}, + { "-c", "--config", CONFIG, "config file (Default: enc.cfg)\n" }, + { "--", "--loopback", LOOPBACK, "Enable encoding in a loop\n" }, + { "--", "--profile", PROFILE, "Profile mode: Supported values BASE, MAIN, HIGH\n" }, + { "--", "--max_bitrate", MAX_BITRATE, "Max bitrate\n"}, + { "--", "--bitrate", BITRATE, "Target bitrate\n"}, + { "--", "--qp_i", I_QP, "QP for I frames\n"}, + { "--", "--qp_p", P_QP, "QP for P frames\n"}, + { "--", "--qp_b", B_QP, "QP for B frames\n"}, + { "--", "--qp_i_max",I_QP_MAX, "Max QP for I frames\n"}, + { "--", "--qp_p_max", P_QP_MAX, "Max QP for P frames\n"}, + { "--", "--qp_b_max", B_QP_MAX, "Max QP for B frames\n"}, + { "--", "--qp_i_min", I_QP_MIN, "Min QP for I frames\n"}, + { "--", "--qp_p_min", P_QP_MIN, "Min QP for P frames\n"}, + { "--", "--qp_b_min", B_QP_MIN, "Min QP for B frames\n"}, + { "--", "--entropy", ENTROPY, "Entropy coding mode(0: CAVLC or 1: CABAC)\n"}, + { "--", "--vbv_delay", VBV_DELAY, "VBV buffer delay\n"}, + { "--", "--vbv_size", VBV_SIZE, "VBV buffer size\n"}, + { "--", "--intra_4x4_enable", INTRA_4x4_ENABLE, "Intra 4x4 enable \n" }, + { "--", "--mb_info_file", MB_INFO_FILE, "MB info file\n"}, + { "--", "--mb_info_type", MB_INFO_TYPE, "MB info type\n"}, + { "--", "--pic_info_file", PIC_INFO_FILE, "Pic info file\n"}, + { "--", "--pic_info_type", PIC_INFO_TYPE, "Pic info type\n"}, +}; /*****************************************************************************/ /* Function Definitions */ /*****************************************************************************/ - +/** +******************************************************************************* +* +* @brief Returns malloc data. Ideally should return aligned memory +* +* @param[in] alignment +* Alignment +* +* @param[in] size +* size +* +* @returns pointer to allocated memory +* +* @remarks none +* +******************************************************************************* +*/ #if(defined X86) && (defined X86_MINGW) -/*****************************************************************************/ -/* Function to print library calls */ -/*****************************************************************************/ -/*****************************************************************************/ -/* */ -/* Function Name : memalign */ -/* */ -/* Description : Returns malloc data. Ideally should return aligned memory*/ -/* support alignment will be added later */ -/* */ -/* Inputs : alignment */ -/* size */ -/* Globals : */ -/* Processing : */ -/* */ -/* Outputs : */ -/* Returns : */ -/* */ -/* Issues : */ -/* */ -/* Revision History: */ -/* */ -/* DD MM YYYY Author(s) Changes */ -/* 07 09 2012 100189 Initial Version */ -/* */ -/*****************************************************************************/ void * ih264a_aligned_malloc(WORD32 alignment, WORD32 size) { @@ -291,53 +304,43 @@ void ih264a_aligned_free(void *pv_buf) #endif -/*****************************************************************************/ -/* */ -/* Function Name : codec_exit */ -/* */ -/* Description : handles unrecoverable errors */ -/* Inputs : Error message */ -/* Globals : None */ -/* Processing : Prints error message to console and exits. */ -/* Outputs : Error message to the console */ -/* Returns : None */ -/* */ -/* Issues : */ -/* */ -/* Revision History: */ -/* */ -/* DD MM YYYY Author(s) Changes (Describe the changes made) */ -/* 07 06 2006 Sankar Creation */ -/* */ -/*****************************************************************************/ +/** +******************************************************************************* +* +* @brief handles unrecoverable errors. Prints error message to console and exits. +* +* @param[in] pc_err_message +* error message +* +* @returns none +* +******************************************************************************* +*/ void codec_exit(CHAR *pc_err_message) { printf("%s\n", pc_err_message); exit(-1); } -/*****************************************************************************/ -/* */ -/* Function Name : codec_exit */ -/* */ -/* Description : handles unrecoverable errors */ -/* Inputs : Error message */ -/* Globals : None */ -/* Processing : Prints error message to console and exits. */ -/* Outputs : Error mesage to the console */ -/* Returns : None */ -/* */ -/* Issues : */ -/* */ -/* Revision History: */ -/* */ -/* DD MM YYYY Author(s) Changes (Describe the changes made) */ -/* 07 06 2006 Sankar Creation */ -/* */ -/*****************************************************************************/ +/** +******************************************************************************* +* +* @brief Maps input string to color format +* +* @param[in] value +* string +* +* @returns color format ID +* +* @remarks If the input string is not recognized, display a message and choose +* YUV420P as color format +* +******************************************************************************* +*/ IV_COLOR_FORMAT_T get_chroma_fmt(CHAR *value) { - IV_COLOR_FORMAT_T e_chroma_format; + IV_COLOR_FORMAT_T e_chroma_format = IV_YUV_420P; + if((strcmp(value, "YUV_420P")) == 0) e_chroma_format = IV_YUV_420P; else if((strcmp(value, "YUV_422ILE")) == 0) @@ -351,35 +354,30 @@ IV_COLOR_FORMAT_T get_chroma_fmt(CHAR *value) else if((strcmp(value, "YUV_420SP_VU")) == 0) e_chroma_format = IV_YUV_420SP_VU; else - { printf("\nInvalid colour format setting it to IV_YUV_420P\n"); - e_chroma_format = IV_YUV_420P; - } + return e_chroma_format; } -/*****************************************************************************/ -/* */ -/* Function Name : codec_exit */ -/* */ -/* Description : handles unrecoverable errors */ -/* Inputs : Error message */ -/* Globals : None */ -/* Processing : Prints error message to console and exits. */ -/* Outputs : Error mesage to the console */ -/* Returns : None */ -/* */ -/* Issues : */ -/* */ -/* Revision History: */ -/* */ -/* DD MM YYYY Author(s) Changes (Describe the changes made) */ -/* 07 06 2006 Sankar Creation */ -/* */ -/*****************************************************************************/ +/** +******************************************************************************* +* +* @brief Maps input string to a speed preset +* +* @param[in] value +* string +* +* @returns speed preset ID +* +* @remarks If the input string is not recognized, display a message and choose +* IVE_FASTEST as speed preset +* +******************************************************************************* +*/ IVE_SPEED_CONFIG get_speed_preset(CHAR *value) { - IVE_SPEED_CONFIG e_enc_speed_preset; + IVE_SPEED_CONFIG e_enc_speed_preset = IVE_FASTEST; + if((strcmp(value, "CONFIG")) == 0) e_enc_speed_preset = IVE_CONFIG; else if((strcmp(value, "SLOWEST")) == 0) @@ -393,40 +391,21 @@ IVE_SPEED_CONFIG get_speed_preset(CHAR *value) else if((strcmp(value, "FASTEST")) == 0) e_enc_speed_preset = IVE_FASTEST; else - { printf("\nInvalid speed preset, setting it to IVE_FASTEST\n"); - e_enc_speed_preset = IVE_FASTEST; - } + return e_enc_speed_preset; } -/*****************************************************************************/ -/* */ -/* Function Name : print_usage */ -/* */ -/* Description : Prints argument format */ -/* */ -/* */ -/* Inputs : */ -/* Globals : */ -/* Processing : Prints argument format */ -/* */ -/* Outputs : */ -/* Returns : */ -/* */ -/* Issues : */ -/* */ -/* Revision History: */ -/* */ -/* DD MM YYYY Author(s) Changes */ -/* 07 09 2012 100189 Initial Version */ -/* */ -/*****************************************************************************/ - +/** +******************************************************************************* +* @brief prints application usage +******************************************************************************* +*/ void print_usage(void) { WORD32 i = 0; WORD32 num_entries = sizeof(argument_mapping) / sizeof(argument_t); + printf("\nUsage:\n"); while(i < num_entries) { @@ -436,364 +415,353 @@ void print_usage(void) } } -/*****************************************************************************/ -/* */ -/* Function Name : get_argument */ -/* */ -/* Description : Gets argument for a given string */ -/* */ -/* */ -/* Inputs : name */ -/* Globals : */ -/* Processing : Searches the given string in the array and returns */ -/* appropriate argument ID */ -/* */ -/* Outputs : Argument ID */ -/* Returns : Argument ID */ -/* */ -/* Issues : */ -/* */ -/* Revision History: */ -/* */ -/* DD MM YYYY Author(s) Changes */ -/* 07 09 2012 100189 Initial Version */ -/* */ -/*****************************************************************************/ +/** +******************************************************************************* +* +* @brief Maps input string to a argument +* +* @param[in] value +* string +* +* @returns argument ID +* +* @remarks If the input string is not recognized, returns INVALID +* +******************************************************************************* +*/ ARGUMENT_T get_argument(CHAR *name) { - WORD32 i = 0; + WORD32 i; WORD32 num_entries = sizeof(argument_mapping) / sizeof(argument_t); - while(i < num_entries) + + for(i = 0;i < num_entries;i++) { - if((0 == strcmp(argument_mapping[i].argument_name, name)) || - ((0 == strcmp(argument_mapping[i].argument_shortname, name)) && - (0 != strcmp(argument_mapping[i].argument_shortname, "--")))) + if((0 == strcmp(argument_mapping[i].argument_name, name)) || + ((0 == strcmp(argument_mapping[i].argument_shortname, name)) && + (0 != strcmp(argument_mapping[i].argument_shortname, "--")))) { return argument_mapping[i].argument; } - i++; } return INVALID; } -/*****************************************************************************/ -/* */ -/* Function Name : get_argument */ -/* */ -/* Description : Gets argument for a given string */ -/* */ -/* */ -/* Inputs : name */ -/* Globals : */ -/* Processing : Searches the given string in the array and returns */ -/* appropriate argument ID */ -/* */ -/* Outputs : Argument ID */ -/* Returns : Argument ID */ -/* */ -/* Issues : */ -/* */ -/* Revision History: */ -/* */ -/* DD MM YYYY Author(s) Changes */ -/* 07 09 2012 100189 Initial Version */ -/* */ -/*****************************************************************************/ +/** +******************************************************************************* +* +* @brief Parse input argument +* +* @param[in] ps_app_ctxt +* pointer to application context +* +* @param[in] argument +* argument string +* +* @param[in] value +* value corresponding to the argument +* +* @returns none +* +* @remarks none +* +******************************************************************************* +*/ void parse_argument(app_ctxt_t *ps_app_ctxt, CHAR *argument, CHAR *value) { - ARGUMENT_T arg; + ARGUMENT_T arg = get_argument(argument); - arg = get_argument(argument); switch(arg) { - case HELP: - print_usage(); - exit(-1); - break; - case SLICE_MODE: - sscanf(value, "%d", &ps_app_ctxt->u4_slice_mode); - break; - case SLICE_PARAM: - sscanf(value, "%d", &ps_app_ctxt->u4_slice_param); - break; - case INPUT_FILE: - sscanf(value, "%s", ps_app_ctxt->ac_ip_fname); - break; - - case OUTPUT_FILE: - sscanf(value, "%s", ps_app_ctxt->ac_op_fname); - break; - - case RECON_FILE: - sscanf(value, "%s", ps_app_ctxt->ac_recon_fname); - break; - - case RECON_ENABLE: - sscanf(value, "%d", &ps_app_ctxt->u4_recon_enable); - break; - - case CHKSUM_FILE: - sscanf(value, "%s", ps_app_ctxt->ac_chksum_fname); - break; - - case CHKSUM_ENABLE: - sscanf(value, "%d", &ps_app_ctxt->u4_chksum_enable); - break; - - case MB_INFO_FILE: - sscanf(value, "%s", ps_app_ctxt->ac_mb_info_fname); - break; - - case MB_INFO_TYPE: - sscanf(value, "%d", &ps_app_ctxt->u4_mb_info_type); - break; - - case PIC_INFO_FILE: - sscanf(value, "%s", ps_app_ctxt->ac_pic_info_fname); - break; - - case PIC_INFO_TYPE: - sscanf(value, "%d", &ps_app_ctxt->u4_pic_info_type); - break; - - case INPUT_CHROMA_FORMAT: - ps_app_ctxt->e_inp_color_fmt = get_chroma_fmt(value); - break; - - case RECON_CHROMA_FORMAT: - ps_app_ctxt->e_recon_color_fmt = get_chroma_fmt(value); - break; - - case MAX_WD: - sscanf(value, "%d", &ps_app_ctxt->u4_max_wd); - break; - - case MAX_HT: - sscanf(value, "%d", &ps_app_ctxt->u4_max_ht); - break; - - case WD: - sscanf(value, "%d", &ps_app_ctxt->u4_wd); - break; - - case HT: - sscanf(value, "%d", &ps_app_ctxt->u4_ht); - break; - - case MAX_LEVEL: - sscanf(value, "%d", &ps_app_ctxt->u4_max_level); - break; - - case ENC_SPEED: - ps_app_ctxt->u4_enc_speed = get_speed_preset(value); - break; - - case ME_SPEED: - sscanf(value, "%d", &ps_app_ctxt->u4_me_speed); - break; - - case START_FRM: - sscanf(value, "%d", &ps_app_ctxt->u4_start_frm); - break; - - case NUM_FRMS: - sscanf(value, "%d", &ps_app_ctxt->u4_max_num_frms); - break; - - case MAX_FRAMERATE: - sscanf(value, "%d", &ps_app_ctxt->u4_max_frame_rate); - if(ps_app_ctxt->u4_max_frame_rate <= 0) - ps_app_ctxt->u4_max_frame_rate = DEFAULT_MAX_FRAMERATE; - break; - - case SRC_FRAMERATE: - sscanf(value, "%d", &ps_app_ctxt->u4_src_frame_rate); - if(ps_app_ctxt->u4_src_frame_rate <= 0) - ps_app_ctxt->u4_src_frame_rate = DEFAULT_SRC_FRAME_RATE; - break; - - case TGT_FRAMERATE: - sscanf(value, "%d", &ps_app_ctxt->u4_tgt_frame_rate); - if(ps_app_ctxt->u4_tgt_frame_rate <= 0) - ps_app_ctxt->u4_tgt_frame_rate = DEFAULT_TGT_FRAME_RATE; - break; - - case RC: - sscanf(value, "%d", &ps_app_ctxt->u4_rc); - break; - - case MAX_BITRATE: - sscanf(value, "%d", &ps_app_ctxt->u4_max_bitrate); - break; - - case BITRATE: - sscanf(value, "%d", &ps_app_ctxt->u4_bitrate); - break; - - case I_QP: - sscanf(value, "%d", &ps_app_ctxt->u4_i_qp); - break; - - case I_QP_MAX: - sscanf(value, "%d", &ps_app_ctxt->u4_i_qp_max); - break; - - case I_QP_MIN: - sscanf(value, "%d", &ps_app_ctxt->u4_i_qp_min); - break; - - case P_QP: - sscanf(value, "%d", &ps_app_ctxt->u4_p_qp); - break; - - case P_QP_MAX: - sscanf(value, "%d", &ps_app_ctxt->u4_p_qp_max); - break; - - case P_QP_MIN: - sscanf(value, "%d", &ps_app_ctxt->u4_p_qp_min); - break; - - case B_QP: - sscanf(value, "%d", &ps_app_ctxt->u4_b_qp); - break; - - case B_QP_MAX: - sscanf(value, "%d", &ps_app_ctxt->u4_b_qp_max); - break; - - case B_QP_MIN: - sscanf(value, "%d", &ps_app_ctxt->u4_b_qp_min); - break; - - case ENTROPY: - sscanf(value, "%d", &ps_app_ctxt->u4_entropy_coding_mode); - break; - - case AIR: - sscanf(value, "%d", &ps_app_ctxt->u4_air); - break; - - case ARCH: - if((strcmp(value, "ARM_NONEON")) == 0) - ps_app_ctxt->e_arch = ARCH_ARM_NONEON; - else if((strcmp(value, "ARM_A9Q")) == 0) - ps_app_ctxt->e_arch = ARCH_ARM_A9Q; - else if((strcmp(value, "ARM_A7")) == 0) - ps_app_ctxt->e_arch = ARCH_ARM_A7; - else if((strcmp(value, "ARM_A5")) == 0) - ps_app_ctxt->e_arch = ARCH_ARM_A5; - else if((strcmp(value, "ARM_NEONINTR")) == 0) - ps_app_ctxt->e_arch = ARCH_ARM_NEONINTR; - else if((strcmp(value, "X86_GENERIC")) == 0) - ps_app_ctxt->e_arch = ARCH_X86_GENERIC; - else if((strcmp(value, "X86_SSSE3")) == 0) - ps_app_ctxt->e_arch = ARCH_X86_SSSE3; - else if((strcmp(value, "X86_SSE42")) == 0) - ps_app_ctxt->e_arch = ARCH_X86_SSE42; - else if((strcmp(value, "ARM_A53")) == 0) - ps_app_ctxt->e_arch = ARCH_ARM_A53; - else if((strcmp(value, "ARM_A57")) == 0) - ps_app_ctxt->e_arch = ARCH_ARM_A57; - else if((strcmp(value, "ARM_V8_NEON")) == 0) - ps_app_ctxt->e_arch = ARCH_ARM_V8_NEON; - else - { - printf("\nInvalid Arch. Setting it to ARM_A9Q\n"); - ps_app_ctxt->e_arch = ARCH_ARM_A9Q; - } - - break; - case SOC: - if((strcmp(value, "GENERIC")) == 0) - ps_app_ctxt->e_soc = SOC_GENERIC; - else if((strcmp(value, "HISI_37X")) == 0) - ps_app_ctxt->e_soc = SOC_HISI_37X; - else - { - ps_app_ctxt->e_soc = SOC_GENERIC; - } - break; - - case NUMCORES: - sscanf(value, "%d", &ps_app_ctxt->u4_num_cores); - break; - - case LOOPBACK: - sscanf(value, "%d", &ps_app_ctxt->u4_loopback); - break; - - case PRE_ENC_ME: - sscanf(value, "%d", &ps_app_ctxt->u4_pre_enc_me); - break; - - case PRE_ENC_IPE: - sscanf(value, "%d", &ps_app_ctxt->u4_pre_enc_ipe); - break; - - case HPEL: - sscanf(value, "%d", &ps_app_ctxt->u4_hpel); - break; - - case QPEL: - sscanf(value, "%d", &ps_app_ctxt->u4_qpel); - break; - - case SRCH_RNG_X: - sscanf(value, "%d", &ps_app_ctxt->u4_srch_rng_x); - break; - - case SRCH_RNG_Y: - sscanf(value, "%d", &ps_app_ctxt->u4_srch_rng_y); - break; - - case I_INTERVAL: - sscanf(value, "%d", &ps_app_ctxt->u4_i_interval); - break; - - case IDR_INTERVAL: - sscanf(value, "%d", &ps_app_ctxt->u4_idr_interval); - break; - - case CONSTRAINED_INTRA_PRED: - sscanf(value, "%d", &ps_app_ctxt->u4_constrained_intra_pred); - break; - - case NUM_B_FRMS: - sscanf(value, "%d", &ps_app_ctxt->u4_num_bframes); - break; - - case DISABLE_DEBLOCK_LEVEL: - sscanf(value, "%d", &ps_app_ctxt->u4_disable_deblk_level); - break; - - case VBV_DELAY: - sscanf(value, "%d", &ps_app_ctxt->u4_vbv_buffer_delay); - break; - - case VBV_SIZE: - sscanf(value, "%d", &ps_app_ctxt->u4_vbv_buf_size); - break; - - case FAST_SAD: - sscanf(value, "%d", &ps_app_ctxt->u4_enable_fast_sad); - break; - - case ALT_REF: - sscanf(value, "%d", &ps_app_ctxt->u4_enable_alt_ref); - break; - - case AIR_REFRESH_PERIOD: - sscanf(value, "%d", &ps_app_ctxt->u4_air_refresh_period); - break; - - case PROFILE: + case HELP: + print_usage(); + exit(-1); + break; + + case SLICE_MODE: + sscanf(value, "%d", &ps_app_ctxt->u4_slice_mode); + break; + + case SLICE_PARAM: + sscanf(value, "%d", &ps_app_ctxt->u4_slice_param); + break; + + case INPUT_FILE: + sscanf(value, "%s", ps_app_ctxt->ac_ip_fname); + break; + + case OUTPUT_FILE: + sscanf(value, "%s", ps_app_ctxt->ac_op_fname); + break; + + case RECON_FILE: + sscanf(value, "%s", ps_app_ctxt->ac_recon_fname); + break; + + case RECON_ENABLE: + sscanf(value, "%d", &ps_app_ctxt->u4_recon_enable); + break; + + case CHKSUM_FILE: + sscanf(value, "%s", ps_app_ctxt->ac_chksum_fname); + break; + + case CHKSUM_ENABLE: + sscanf(value, "%d", &ps_app_ctxt->u4_chksum_enable); + break; + + case MB_INFO_FILE: + sscanf(value, "%s", ps_app_ctxt->ac_mb_info_fname); + break; + + case MB_INFO_TYPE: + sscanf(value, "%d", &ps_app_ctxt->u4_mb_info_type); + break; + + case PIC_INFO_FILE: + sscanf(value, "%s", ps_app_ctxt->ac_pic_info_fname); + break; + + case PIC_INFO_TYPE: + sscanf(value, "%d", &ps_app_ctxt->u4_pic_info_type); + break; + + case INPUT_CHROMA_FORMAT: + ps_app_ctxt->e_inp_color_fmt = get_chroma_fmt(value); + break; + + case RECON_CHROMA_FORMAT: + ps_app_ctxt->e_recon_color_fmt = get_chroma_fmt(value); + break; + + case MAX_WD: + sscanf(value, "%d", &ps_app_ctxt->u4_max_wd); + break; + + case MAX_HT: + sscanf(value, "%d", &ps_app_ctxt->u4_max_ht); + break; + + case WD: + sscanf(value, "%d", &ps_app_ctxt->u4_wd); + break; + + case HT: + sscanf(value, "%d", &ps_app_ctxt->u4_ht); + break; + + case MAX_LEVEL: + sscanf(value, "%d", &ps_app_ctxt->u4_max_level); + break; + + case ENC_SPEED: + ps_app_ctxt->u4_enc_speed = get_speed_preset(value); + break; + + case ME_SPEED: + sscanf(value, "%d", &ps_app_ctxt->u4_me_speed); + break; + + case START_FRM: + sscanf(value, "%d", &ps_app_ctxt->u4_start_frm); + break; + + case NUM_FRMS: + sscanf(value, "%d", &ps_app_ctxt->u4_max_num_frms); + break; + + case MAX_FRAMERATE: + sscanf(value, "%d", &ps_app_ctxt->u4_max_frame_rate); + if(ps_app_ctxt->u4_max_frame_rate <= 0) + ps_app_ctxt->u4_max_frame_rate = DEFAULT_MAX_FRAMERATE; + break; + + case SRC_FRAMERATE: + sscanf(value, "%d", &ps_app_ctxt->u4_src_frame_rate); + if(ps_app_ctxt->u4_src_frame_rate <= 0) + ps_app_ctxt->u4_src_frame_rate = DEFAULT_SRC_FRAME_RATE; + break; + + case TGT_FRAMERATE: + sscanf(value, "%d", &ps_app_ctxt->u4_tgt_frame_rate); + if(ps_app_ctxt->u4_tgt_frame_rate <= 0) + ps_app_ctxt->u4_tgt_frame_rate = DEFAULT_TGT_FRAME_RATE; + break; + + case RC: + sscanf(value, "%d", &ps_app_ctxt->u4_rc); + break; + + case MAX_BITRATE: + sscanf(value, "%d", &ps_app_ctxt->u4_max_bitrate); + break; + + case BITRATE: + sscanf(value, "%d", &ps_app_ctxt->u4_bitrate); + break; + + case I_QP: + sscanf(value, "%d", &ps_app_ctxt->u4_i_qp); + break; + + case I_QP_MAX: + sscanf(value, "%d", &ps_app_ctxt->u4_i_qp_max); + break; + + case I_QP_MIN: + sscanf(value, "%d", &ps_app_ctxt->u4_i_qp_min); + break; + + case P_QP: + sscanf(value, "%d", &ps_app_ctxt->u4_p_qp); + break; + + case P_QP_MAX: + sscanf(value, "%d", &ps_app_ctxt->u4_p_qp_max); + break; + + case P_QP_MIN: + sscanf(value, "%d", &ps_app_ctxt->u4_p_qp_min); + break; + + case B_QP: + sscanf(value, "%d", &ps_app_ctxt->u4_b_qp); + break; + + case B_QP_MAX: + sscanf(value, "%d", &ps_app_ctxt->u4_b_qp_max); + break; + + case B_QP_MIN: + sscanf(value, "%d", &ps_app_ctxt->u4_b_qp_min); + break; + + case ENTROPY: + sscanf(value, "%d", &ps_app_ctxt->u4_entropy_coding_mode); + break; + + case AIR: + sscanf(value, "%d", &ps_app_ctxt->u4_air); + break; + + case ARCH: + if((strcmp(value, "ARM_NONEON")) == 0) + ps_app_ctxt->e_arch = ARCH_ARM_NONEON; + else if((strcmp(value, "ARM_A9Q")) == 0) + ps_app_ctxt->e_arch = ARCH_ARM_A9Q; + else if((strcmp(value, "ARM_A7")) == 0) + ps_app_ctxt->e_arch = ARCH_ARM_A7; + else if((strcmp(value, "ARM_A5")) == 0) + ps_app_ctxt->e_arch = ARCH_ARM_A5; + else if((strcmp(value, "ARM_NEONINTR")) == 0) + ps_app_ctxt->e_arch = ARCH_ARM_NEONINTR; + else if((strcmp(value, "X86_GENERIC")) == 0) + ps_app_ctxt->e_arch = ARCH_X86_GENERIC; + else if((strcmp(value, "X86_SSSE3")) == 0) + ps_app_ctxt->e_arch = ARCH_X86_SSSE3; + else if((strcmp(value, "X86_SSE42")) == 0) + ps_app_ctxt->e_arch = ARCH_X86_SSE42; + else if((strcmp(value, "ARM_A53")) == 0) + ps_app_ctxt->e_arch = ARCH_ARM_A53; + else if((strcmp(value, "ARM_A57")) == 0) + ps_app_ctxt->e_arch = ARCH_ARM_A57; + else if((strcmp(value, "ARM_V8_NEON")) == 0) + ps_app_ctxt->e_arch = ARCH_ARM_V8_NEON; + else + { + printf("\nInvalid Arch. Setting it to ARM_A9Q\n"); + ps_app_ctxt->e_arch = ARCH_ARM_A9Q; + } + break; + + case SOC: + if((strcmp(value, "GENERIC")) == 0) + ps_app_ctxt->e_soc = SOC_GENERIC; + else + { + printf("\nInvalid SOC. Setting it to SOC_GENERIC\n"); + ps_app_ctxt->e_soc = SOC_GENERIC; + } + break; + + case NUMCORES: + sscanf(value, "%d", &ps_app_ctxt->u4_num_cores); + break; + + case LOOPBACK: + sscanf(value, "%d", &ps_app_ctxt->u4_loopback); + break; + + case PRE_ENC_ME: + sscanf(value, "%d", &ps_app_ctxt->u4_pre_enc_me); + break; + + case PRE_ENC_IPE: + sscanf(value, "%d", &ps_app_ctxt->u4_pre_enc_ipe); + break; + + case HPEL: + sscanf(value, "%d", &ps_app_ctxt->u4_hpel); + break; + + case QPEL: + sscanf(value, "%d", &ps_app_ctxt->u4_qpel); + break; + + case SRCH_RNG_X: + sscanf(value, "%d", &ps_app_ctxt->u4_srch_rng_x); + break; + + case SRCH_RNG_Y: + sscanf(value, "%d", &ps_app_ctxt->u4_srch_rng_y); + break; + + case I_INTERVAL: + sscanf(value, "%d", &ps_app_ctxt->u4_i_interval); + break; + + case IDR_INTERVAL: + sscanf(value, "%d", &ps_app_ctxt->u4_idr_interval); + break; + + case CONSTRAINED_INTRA_PRED: + sscanf(value, "%d", &ps_app_ctxt->u4_constrained_intra_pred); + break; + + case NUM_B_FRMS: + sscanf(value, "%d", &ps_app_ctxt->u4_num_bframes); + break; + + case DISABLE_DEBLOCK_LEVEL: + sscanf(value, "%d", &ps_app_ctxt->u4_disable_deblk_level); + break; + + case VBV_DELAY: + sscanf(value, "%d", &ps_app_ctxt->u4_vbv_buffer_delay); + break; + + case VBV_SIZE: + sscanf(value, "%d", &ps_app_ctxt->u4_vbv_buf_size); + break; + + case FAST_SAD: + sscanf(value, "%d", &ps_app_ctxt->u4_enable_fast_sad); + break; + + case ALT_REF: + sscanf(value, "%d", &ps_app_ctxt->u4_enable_alt_ref); + break; + + case AIR_REFRESH_PERIOD: + sscanf(value, "%d", &ps_app_ctxt->u4_air_refresh_period); + break; + + case PROFILE: if((strcmp(value, "BASE")) == 0) ps_app_ctxt->e_profile = IV_PROFILE_BASE; else if((strcmp(value, "MAIN")) == 0) - ps_app_ctxt->e_profile = IV_PROFILE_MAIN; + ps_app_ctxt->e_profile = IV_PROFILE_MAIN; else if((strcmp(value, "HIGH")) == 0) - ps_app_ctxt->e_profile = IV_PROFILE_HIGH; + ps_app_ctxt->e_profile = IV_PROFILE_HIGH; else { printf("\nInvalid profile. Setting it to BASE\n"); @@ -801,74 +769,92 @@ void parse_argument(app_ctxt_t *ps_app_ctxt, CHAR *argument, CHAR *value) } break; - case PSNR: - sscanf(value, "%d", &ps_app_ctxt->u4_psnr_enable); - break; - - case INTRA_4x4_ENABLE: - sscanf(value, "%d", &ps_app_ctxt->u4_enable_intra_4x4); - break; + case PSNR: + sscanf(value, "%d", &ps_app_ctxt->u4_psnr_enable); + break; + case INTRA_4x4_ENABLE: + sscanf(value, "%d", &ps_app_ctxt->u4_enable_intra_4x4); + break; - case INVALID: + case INVALID: default: printf("Ignoring argument : %s\n", argument); break; } } -/*****************************************************************************/ -/* */ -/* Function Name : read_cfg_file */ -/* */ -/* Description : Reads arguments from a configuration file */ -/* */ -/* */ -/* Inputs : ps_app_ctxt : Application context */ -/* fp_cfg_file : Configuration file handle */ -/* Globals : */ -/* Processing : Parses the arguments and fills in the application context*/ -/* */ -/* Outputs : Arguments parsed */ -/* Returns : None */ -/* */ -/* Issues : */ -/* */ -/* Revision History: */ -/* */ -/* DD MM YYYY Author(s) Changes */ -/* 07 09 2012 100189 Initial Version */ -/* */ -/*****************************************************************************/ +/** +******************************************************************************* +* +* @brief Parse config file +* +* @param[in] ps_app_ctxt +* pointer to application context +* +* @param[in] fp_cfg +* config file pointer +* +* @returns none +* +* @remarks none +* +******************************************************************************* +*/ void read_cfg_file(app_ctxt_t *ps_app_ctxt, FILE *fp_cfg) { - CHAR line[STRLENGTH]; - CHAR description[STRLENGTH]; - CHAR value[STRLENGTH]; - CHAR argument[STRLENGTH]; - - while(0 == (feof(fp_cfg))) + while(1) { - int ret; - line[0] = '\0'; - if(NULL == fgets(line, sizeof(line), fp_cfg)) - break; - argument[0] = '\0'; - /* Reading Input File Name */ - ret = sscanf(line, "%s %s %s", argument, value, description); - if(ret < 2) + CHAR line[STRLENGTH] = {'\0'}; + CHAR argument[STRLENGTH] = {'\0'}; + CHAR value[STRLENGTH]; + CHAR description[STRLENGTH]; + + if(NULL == fgets(line, STRLENGTH, fp_cfg)) return; + + /* split string on whitespace */ + sscanf(line, "%s %s %s", argument, value, description); + if(argument[0] == '\0') continue; parse_argument(ps_app_ctxt, argument, value); } } +/** +******************************************************************************* +* +* @brief handles unrecoverable errors. Prints error message to console and exits. +* +* @param[in] pc_err_message +* error message +* +* @returns none +* +* @remarks none +* +******************************************************************************* +*/ void invalid_argument_exit(CHAR *pc_err_message) { print_usage(); codec_exit(pc_err_message); } +/** +******************************************************************************* +* +* @brief validate configured params +* +* @param[in] ps_app_ctxt +* pointer to application context +* +* @returns none +* +* @remarks none +* +******************************************************************************* +*/ void validate_params(app_ctxt_t *ps_app_ctxt) { CHAR ac_error[STRLENGTH]; @@ -899,118 +885,125 @@ void validate_params(app_ctxt_t *ps_app_ctxt) sprintf(ac_error, "Invalid height: %d", ps_app_ctxt->u4_ht); invalid_argument_exit(ac_error); } - if(0 == (WORD32)ps_app_ctxt->u4_max_num_frms) { sprintf(ac_error, "Invalid number of frames to be encoded: %d", ps_app_ctxt->u4_max_num_frms); invalid_argument_exit(ac_error); } - if ((0 != (WORD32)ps_app_ctxt->u4_entropy_coding_mode) - && (1 != (WORD32)ps_app_ctxt->u4_entropy_coding_mode)) - { - sprintf(ac_error, "Invalid entropy codeing mode: %d", - ps_app_ctxt->u4_entropy_coding_mode); - invalid_argument_exit(ac_error); - } - return; } +/** +******************************************************************************* +* +* @brief initialize default params +* +* @param[in] ps_app_ctxt +* pointer to application context +* +* @returns none +* +* @remarks none +* +******************************************************************************* +*/ void init_default_params(app_ctxt_t *ps_app_ctxt) { - - ps_app_ctxt->ps_enc = NULL; - ps_app_ctxt->ps_mem_rec = NULL; - ps_app_ctxt->u4_num_mem_rec = DEFAULT_MEM_REC_CNT; - ps_app_ctxt->u4_recon_enable = DEFAULT_RECON_ENABLE; - ps_app_ctxt->u4_chksum_enable = DEFAULT_CHKSUM_ENABLE; - ps_app_ctxt->u4_mb_info_type = 0; - ps_app_ctxt->u4_pic_info_type = 0; - ps_app_ctxt->u4_mb_info_size = 0; - ps_app_ctxt->u4_pic_info_size = 0; - ps_app_ctxt->u4_start_frm = DEFAULT_START_FRM; - ps_app_ctxt->u4_max_num_frms = DEFAULT_NUM_FRMS; - ps_app_ctxt->avg_time = 0; - ps_app_ctxt->u4_total_bytes = 0; - ps_app_ctxt->u4_pics_cnt = 0; - ps_app_ctxt->e_inp_color_fmt = DEFAULT_INP_COLOR_FMT; - ps_app_ctxt->e_recon_color_fmt = DEFAULT_RECON_COLOR_FMT; - ps_app_ctxt->e_arch = ARCH_ARM_A9Q; - ps_app_ctxt->e_soc = SOC_GENERIC; - ps_app_ctxt->header_generated = 0; - ps_app_ctxt->pv_codec_obj = NULL; - ps_app_ctxt->u4_num_cores = DEFAULT_NUM_CORES; - ps_app_ctxt->u4_pre_enc_me = 0; - ps_app_ctxt->u4_pre_enc_ipe = 0; - ps_app_ctxt->ac_ip_fname[0] = '\0'; - ps_app_ctxt->ac_op_fname[0] = '\0'; - ps_app_ctxt->ac_recon_fname[0] = '\0'; - ps_app_ctxt->ac_chksum_fname[0] = '\0'; - ps_app_ctxt->ac_mb_info_fname[0] = '\0'; - ps_app_ctxt->fp_ip = NULL; - ps_app_ctxt->fp_op = NULL; - ps_app_ctxt->fp_recon = NULL; - ps_app_ctxt->fp_chksum = NULL; - ps_app_ctxt->fp_psnr_ip = NULL; - ps_app_ctxt->fp_mb_info = NULL; - ps_app_ctxt->fp_pic_info = NULL; - ps_app_ctxt->u4_loopback = DEFAULT_LOOPBACK; - ps_app_ctxt->u4_max_frame_rate = DEFAULT_MAX_FRAMERATE; - ps_app_ctxt->u4_src_frame_rate = DEFAULT_SRC_FRAME_RATE; - ps_app_ctxt->u4_tgt_frame_rate = DEFAULT_TGT_FRAME_RATE; - ps_app_ctxt->u4_max_wd = DEFAULT_MAX_WD; - ps_app_ctxt->u4_max_ht = DEFAULT_MAX_HT; - ps_app_ctxt->u4_max_level = DEFAULT_MAX_LEVEL; - ps_app_ctxt->u4_strd = DEFAULT_STRIDE; - ps_app_ctxt->u4_wd = DEFAULT_WD; - ps_app_ctxt->u4_ht = DEFAULT_HT; - ps_app_ctxt->u4_psnr_enable = DEFAULT_PSNR_ENABLE; - ps_app_ctxt->u4_enc_speed = IVE_FASTEST; - ps_app_ctxt->u4_me_speed = DEFAULT_ME_SPEED; - ps_app_ctxt->u4_enable_fast_sad = DEFAULT_ENABLE_FAST_SAD; - ps_app_ctxt->u4_enable_alt_ref = DEFAULT_ENABLE_ALT_REF; - ps_app_ctxt->u4_rc = DEFAULT_RC; - ps_app_ctxt->u4_max_bitrate = DEFAULT_MAX_BITRATE; - ps_app_ctxt->u4_num_bframes = DEFAULT_NUM_BFRAMES; - ps_app_ctxt->u4_bitrate = DEFAULT_BITRATE; - ps_app_ctxt->u4_i_qp = DEFAULT_I_QP; - ps_app_ctxt->u4_p_qp = DEFAULT_P_QP; - ps_app_ctxt->u4_b_qp = DEFAULT_B_QP; - ps_app_ctxt->u4_i_qp_min = DEFAULT_QP_MIN; - ps_app_ctxt->u4_i_qp_max = DEFAULT_QP_MAX; - ps_app_ctxt->u4_p_qp_min = DEFAULT_QP_MIN; - ps_app_ctxt->u4_p_qp_max = DEFAULT_QP_MAX; - ps_app_ctxt->u4_b_qp_min = DEFAULT_QP_MIN; - ps_app_ctxt->u4_b_qp_max = DEFAULT_QP_MAX; - ps_app_ctxt->u4_air = DEFAULT_AIR; - ps_app_ctxt->u4_air_refresh_period = DEFAULT_AIR_REFRESH_PERIOD; - ps_app_ctxt->u4_srch_rng_x = DEFAULT_SRCH_RNG_X; - ps_app_ctxt->u4_srch_rng_y = DEFAULT_SRCH_RNG_Y; - ps_app_ctxt->u4_i_interval = DEFAULT_I_INTERVAL; - ps_app_ctxt->u4_idr_interval = DEFAULT_IDR_INTERVAL; - ps_app_ctxt->u4_constrained_intra_pred = DEFAULT_CONSTRAINED_INTRAPRED; - ps_app_ctxt->u4_disable_deblk_level = DEFAULT_DISABLE_DEBLK_LEVEL; - ps_app_ctxt->u4_hpel = DEFAULT_HPEL; - ps_app_ctxt->u4_qpel = DEFAULT_QPEL; - ps_app_ctxt->u4_enable_intra_4x4 = DEFAULT_I4; - ps_app_ctxt->e_profile = DEFAULT_EPROFILE; - ps_app_ctxt->u4_slice_mode = DEFAULT_SLICE_MODE; - ps_app_ctxt->u4_slice_param = DEFAULT_SLICE_PARAM; - ps_app_ctxt->pv_input_thread_handle = NULL; + ps_app_ctxt->ps_enc = NULL; + ps_app_ctxt->ps_mem_rec = NULL; + ps_app_ctxt->u4_num_mem_rec = DEFAULT_MEM_REC_CNT; + ps_app_ctxt->u4_recon_enable = DEFAULT_RECON_ENABLE; + ps_app_ctxt->u4_chksum_enable = DEFAULT_CHKSUM_ENABLE; + ps_app_ctxt->u4_mb_info_type = 0; + ps_app_ctxt->u4_pic_info_type = 0; + ps_app_ctxt->u4_mb_info_size = 0; + ps_app_ctxt->u4_pic_info_size = 0; + ps_app_ctxt->u4_start_frm = DEFAULT_START_FRM; + ps_app_ctxt->u4_max_num_frms = DEFAULT_NUM_FRMS; + ps_app_ctxt->u4_total_bytes = 0; + ps_app_ctxt->u4_pics_cnt = 0; + ps_app_ctxt->e_inp_color_fmt = DEFAULT_INP_COLOR_FMT; + ps_app_ctxt->e_recon_color_fmt = DEFAULT_RECON_COLOR_FMT; + ps_app_ctxt->e_arch = ARCH_ARM_A9Q; + ps_app_ctxt->e_soc = SOC_GENERIC; + ps_app_ctxt->header_generated = 0; + ps_app_ctxt->pv_codec_obj = NULL; + ps_app_ctxt->u4_num_cores = DEFAULT_NUM_CORES; + ps_app_ctxt->u4_pre_enc_me = 0; + ps_app_ctxt->u4_pre_enc_ipe = 0; + ps_app_ctxt->ac_ip_fname[0] = '\0'; + ps_app_ctxt->ac_op_fname[0] = '\0'; + ps_app_ctxt->ac_recon_fname[0] = '\0'; + ps_app_ctxt->ac_chksum_fname[0] = '\0'; + ps_app_ctxt->ac_mb_info_fname[0] = '\0'; + ps_app_ctxt->fp_ip = NULL; + ps_app_ctxt->fp_op = NULL; + ps_app_ctxt->fp_recon = NULL; + ps_app_ctxt->fp_chksum = NULL; + ps_app_ctxt->fp_psnr_ip = NULL; + ps_app_ctxt->fp_mb_info = NULL; + ps_app_ctxt->fp_pic_info = NULL; + ps_app_ctxt->u4_loopback = DEFAULT_LOOPBACK; + ps_app_ctxt->u4_max_frame_rate = DEFAULT_MAX_FRAMERATE; + ps_app_ctxt->u4_src_frame_rate = DEFAULT_SRC_FRAME_RATE; + ps_app_ctxt->u4_tgt_frame_rate = DEFAULT_TGT_FRAME_RATE; + ps_app_ctxt->u4_max_wd = DEFAULT_MAX_WD; + ps_app_ctxt->u4_max_ht = DEFAULT_MAX_HT; + ps_app_ctxt->u4_max_level = DEFAULT_MAX_LEVEL; + ps_app_ctxt->u4_strd = DEFAULT_STRIDE; + ps_app_ctxt->u4_wd = DEFAULT_WD; + ps_app_ctxt->u4_ht = DEFAULT_HT; + ps_app_ctxt->u4_psnr_enable = DEFAULT_PSNR_ENABLE; + ps_app_ctxt->u4_enc_speed = IVE_FASTEST; + ps_app_ctxt->u4_me_speed = DEFAULT_ME_SPEED; + ps_app_ctxt->u4_enable_fast_sad = DEFAULT_ENABLE_FAST_SAD; + ps_app_ctxt->u4_enable_alt_ref = DEFAULT_ENABLE_ALT_REF; + ps_app_ctxt->u4_rc = DEFAULT_RC; + ps_app_ctxt->u4_max_bitrate = DEFAULT_MAX_BITRATE; + ps_app_ctxt->u4_bitrate = DEFAULT_BITRATE; + ps_app_ctxt->u4_i_qp = DEFAULT_I_QP; + ps_app_ctxt->u4_i_qp_max = DEFAULT_QP_MAX; + ps_app_ctxt->u4_i_qp_min = DEFAULT_QP_MIN; + ps_app_ctxt->u4_p_qp = DEFAULT_P_QP; + ps_app_ctxt->u4_p_qp_max = DEFAULT_QP_MAX; + ps_app_ctxt->u4_p_qp_min = DEFAULT_QP_MIN; + ps_app_ctxt->u4_b_qp = DEFAULT_B_QP; + ps_app_ctxt->u4_b_qp_max = DEFAULT_QP_MAX; + ps_app_ctxt->u4_b_qp_min = DEFAULT_QP_MIN; + ps_app_ctxt->u4_air = DEFAULT_AIR; + ps_app_ctxt->u4_air_refresh_period = DEFAULT_AIR_REFRESH_PERIOD; + ps_app_ctxt->u4_srch_rng_x = DEFAULT_SRCH_RNG_X; + ps_app_ctxt->u4_srch_rng_y = DEFAULT_SRCH_RNG_Y; + ps_app_ctxt->u4_i_interval = DEFAULT_I_INTERVAL; + ps_app_ctxt->u4_idr_interval = DEFAULT_IDR_INTERVAL; + ps_app_ctxt->u4_constrained_intra_pred = DEFAULT_CONSTRAINED_INTRAPRED; + ps_app_ctxt->u4_num_bframes = DEFAULT_NUM_BFRAMES; + ps_app_ctxt->u4_disable_deblk_level = DEFAULT_DISABLE_DEBLK_LEVEL; + ps_app_ctxt->u4_hpel = DEFAULT_HPEL; + ps_app_ctxt->u4_qpel = DEFAULT_QPEL; + ps_app_ctxt->u4_enable_intra_4x4 = DEFAULT_I4; + ps_app_ctxt->e_profile = DEFAULT_EPROFILE; + ps_app_ctxt->u4_slice_mode = DEFAULT_SLICE_MODE; + ps_app_ctxt->u4_slice_param = DEFAULT_SLICE_PARAM; + ps_app_ctxt->u4_entropy_coding_mode = DEFAULT_ENTROPY_CODING_MODE; + ps_app_ctxt->pv_input_thread_handle = NULL; ps_app_ctxt->pv_output_thread_handle = NULL; - ps_app_ctxt->pv_recon_thread_handle = NULL; - ps_app_ctxt->u4_vbv_buf_size = 0; - ps_app_ctxt->u4_vbv_buffer_delay = 1000; - ps_app_ctxt->adbl_psnr[0] = 0.0; - ps_app_ctxt->adbl_psnr[1] = 0.0; - ps_app_ctxt->adbl_psnr[2] = 0.0; - ps_app_ctxt->u4_psnr_cnt = 0; - ps_app_ctxt->pu1_psnr_buf = NULL; - ps_app_ctxt->u4_psnr_buf_size = 0; - ps_app_ctxt->u4_entropy_coding_mode = DEFAULT_ENTROPY_CODING_MODE; - - return; + ps_app_ctxt->pv_recon_thread_handle = NULL; + ps_app_ctxt->adbl_psnr[0] = 0.0; + ps_app_ctxt->adbl_psnr[1] = 0.0; + ps_app_ctxt->adbl_psnr[2] = 0.0; + ps_app_ctxt->u4_psnr_cnt = 0; + ps_app_ctxt->pu1_psnr_buf = NULL; + ps_app_ctxt->u4_psnr_buf_size = 0; + ps_app_ctxt->u4_vbv_buffer_delay = 1000; + ps_app_ctxt->u4_vbv_buf_size = 0; + ps_app_ctxt->avg_time = 0; } +/** +******************************************************************************* +* @brief configure input dimensions +******************************************************************************* +*/ void set_dimensions(app_ctxt_t *ps_app_ctxt, UWORD32 u4_timestamp_low, UWORD32 u4_timestamp_high) @@ -1019,22 +1012,17 @@ void set_dimensions(app_ctxt_t *ps_app_ctxt, ih264e_ctl_set_dimensions_op_t s_frame_dimensions_op; IV_STATUS_T status; + s_frame_dimensions_ip.s_ive_ip.u4_size = sizeof(ih264e_ctl_set_dimensions_ip_t); s_frame_dimensions_ip.s_ive_ip.e_cmd = IVE_CMD_VIDEO_CTL; s_frame_dimensions_ip.s_ive_ip.e_sub_cmd = IVE_CMD_CTL_SET_DIMENSIONS; - - s_frame_dimensions_ip.s_ive_ip.u4_ht = ps_app_ctxt->u4_ht; s_frame_dimensions_ip.s_ive_ip.u4_wd = ps_app_ctxt->u4_wd; - - s_frame_dimensions_ip.s_ive_ip.u4_timestamp_high = u4_timestamp_high; + s_frame_dimensions_ip.s_ive_ip.u4_ht = ps_app_ctxt->u4_ht; s_frame_dimensions_ip.s_ive_ip.u4_timestamp_low = u4_timestamp_low; + s_frame_dimensions_ip.s_ive_ip.u4_timestamp_high = u4_timestamp_high; - s_frame_dimensions_ip.s_ive_ip.u4_size = - sizeof(ih264e_ctl_set_dimensions_ip_t); - s_frame_dimensions_op.s_ive_op.u4_size = - sizeof(ih264e_ctl_set_dimensions_op_t); + s_frame_dimensions_op.s_ive_op.u4_size = sizeof(ih264e_ctl_set_dimensions_op_t); - status = ih264e_api_function(ps_app_ctxt->ps_enc, - &s_frame_dimensions_ip, + status = ih264e_api_function(ps_app_ctxt->ps_enc, &s_frame_dimensions_ip, &s_frame_dimensions_op); if(status != IV_SUCCESS) { @@ -1043,9 +1031,13 @@ void set_dimensions(app_ctxt_t *ps_app_ctxt, s_frame_dimensions_op.s_ive_op.u4_error_code); codec_exit(ac_error); } - return; } +/** +******************************************************************************* +* @brief configure source & target framerates +******************************************************************************* +*/ void set_frame_rate(app_ctxt_t *ps_app_ctxt, UWORD32 u4_timestamp_low, UWORD32 u4_timestamp_high) @@ -1054,32 +1046,32 @@ void set_frame_rate(app_ctxt_t *ps_app_ctxt, ih264e_ctl_set_frame_rate_op_t s_frame_rate_op; IV_STATUS_T status; - s_frame_rate_ip.s_ive_ip.e_cmd = IVE_CMD_VIDEO_CTL; - s_frame_rate_ip.s_ive_ip.e_sub_cmd = IVE_CMD_CTL_SET_FRAMERATE; - - s_frame_rate_ip.s_ive_ip.u4_src_frame_rate = - ps_app_ctxt->u4_src_frame_rate; - s_frame_rate_ip.s_ive_ip.u4_tgt_frame_rate = - ps_app_ctxt->u4_tgt_frame_rate; + s_frame_rate_ip.s_ive_ip.u4_size = sizeof(ih264e_ctl_set_frame_rate_ip_t); + s_frame_rate_ip.s_ive_ip.e_cmd = IVE_CMD_VIDEO_CTL; + s_frame_rate_ip.s_ive_ip.e_sub_cmd = IVE_CMD_CTL_SET_FRAMERATE; + s_frame_rate_ip.s_ive_ip.u4_src_frame_rate = ps_app_ctxt->u4_src_frame_rate; + s_frame_rate_ip.s_ive_ip.u4_tgt_frame_rate = ps_app_ctxt->u4_tgt_frame_rate; + s_frame_rate_ip.s_ive_ip.u4_timestamp_low = u4_timestamp_low; + s_frame_rate_ip.s_ive_ip.u4_timestamp_high = u4_timestamp_high; - s_frame_rate_ip.s_ive_ip.u4_timestamp_high = u4_timestamp_high; - s_frame_rate_ip.s_ive_ip.u4_timestamp_low = u4_timestamp_low; + s_frame_rate_op.s_ive_op.u4_size = sizeof(ih264e_ctl_set_frame_rate_op_t); - s_frame_rate_ip.s_ive_ip.u4_size = sizeof(ih264e_ctl_set_frame_rate_ip_t); - s_frame_rate_op.s_ive_op.u4_size = sizeof(ih264e_ctl_set_frame_rate_op_t); - - status = ih264e_api_function(ps_app_ctxt->ps_enc,&s_frame_rate_ip,&s_frame_rate_op); + status = ih264e_api_function(ps_app_ctxt->ps_enc, &s_frame_rate_ip, + &s_frame_rate_op); if(status != IV_SUCCESS) - { - CHAR ac_error[STRLENGTH]; - sprintf(ac_error, "Unable to set frame rate = 0x%x\n", - s_frame_rate_op.s_ive_op.u4_error_code); - codec_exit(ac_error); - } - return; + { + CHAR ac_error[STRLENGTH]; + sprintf(ac_error, "Unable to set frame rate = 0x%x\n", + s_frame_rate_op.s_ive_op.u4_error_code); + codec_exit(ac_error); + } } - +/** +******************************************************************************* +* @brief configure IPE params +******************************************************************************* +*/ void set_ipe_params(app_ctxt_t *ps_app_ctxt, UWORD32 u4_timestamp_low, UWORD32 u4_timestamp_high) @@ -1088,22 +1080,19 @@ void set_ipe_params(app_ctxt_t *ps_app_ctxt, ih264e_ctl_set_ipe_params_op_t s_ipe_params_op; IV_STATUS_T status; - s_ipe_params_ip.s_ive_ip.e_cmd = IVE_CMD_VIDEO_CTL; - s_ipe_params_ip.s_ive_ip.e_sub_cmd = IVE_CMD_CTL_SET_IPE_PARAMS; + s_ipe_params_ip.s_ive_ip.u4_size = sizeof(ih264e_ctl_set_ipe_params_ip_t); + s_ipe_params_ip.s_ive_ip.e_cmd = IVE_CMD_VIDEO_CTL; + s_ipe_params_ip.s_ive_ip.e_sub_cmd = IVE_CMD_CTL_SET_IPE_PARAMS; + s_ipe_params_ip.s_ive_ip.u4_enable_intra_4x4 = ps_app_ctxt->u4_enable_intra_4x4; + s_ipe_params_ip.s_ive_ip.u4_enc_speed_preset = ps_app_ctxt->u4_enc_speed; + s_ipe_params_ip.s_ive_ip.u4_timestamp_low = u4_timestamp_low; + s_ipe_params_ip.s_ive_ip.u4_timestamp_high = u4_timestamp_high; + s_ipe_params_ip.s_ive_ip.u4_constrained_intra_pred = ps_app_ctxt->u4_constrained_intra_pred; - s_ipe_params_ip.s_ive_ip.u4_enable_intra_4x4 = ps_app_ctxt->u4_enable_intra_4x4; - s_ipe_params_ip.s_ive_ip.u4_enc_speed_preset = ps_app_ctxt->u4_enc_speed; + s_ipe_params_op.s_ive_op.u4_size = sizeof(ih264e_ctl_set_ipe_params_op_t); - s_ipe_params_ip.s_ive_ip.u4_timestamp_high = u4_timestamp_high; - s_ipe_params_ip.s_ive_ip.u4_timestamp_low = u4_timestamp_low; - - s_ipe_params_ip.s_ive_ip.u4_size = sizeof(ih264e_ctl_set_ipe_params_ip_t); - s_ipe_params_op.s_ive_op.u4_size = sizeof(ih264e_ctl_set_ipe_params_op_t); - - s_ipe_params_ip.s_ive_ip.u4_constrained_intra_pred = - ps_app_ctxt->u4_constrained_intra_pred; - - status = ih264e_api_function(ps_app_ctxt->ps_enc,&s_ipe_params_ip,&s_ipe_params_op); + status = ih264e_api_function(ps_app_ctxt->ps_enc, &s_ipe_params_ip, + &s_ipe_params_op); if(status != IV_SUCCESS) { CHAR ac_error[STRLENGTH]; @@ -1111,60 +1100,66 @@ void set_ipe_params(app_ctxt_t *ps_app_ctxt, s_ipe_params_op.s_ive_op.u4_error_code); codec_exit(ac_error); } - return; } +/** +******************************************************************************* +* @brief configure bitrate +******************************************************************************* +*/ void set_bit_rate(app_ctxt_t *ps_app_ctxt, - UWORD32 u4_timestamp_low, UWORD32 u4_timestamp_high) + UWORD32 u4_timestamp_low, + UWORD32 u4_timestamp_high) { ih264e_ctl_set_bitrate_ip_t s_bitrate_ip; ih264e_ctl_set_bitrate_op_t s_bitrate_op; IV_STATUS_T status; - s_bitrate_ip.s_ive_ip.e_cmd = IVE_CMD_VIDEO_CTL; - s_bitrate_ip.s_ive_ip.e_sub_cmd = IVE_CMD_CTL_SET_BITRATE; - - s_bitrate_ip.s_ive_ip.u4_target_bitrate = ps_app_ctxt->u4_bitrate; - - s_bitrate_ip.s_ive_ip.u4_timestamp_high = u4_timestamp_high; - s_bitrate_ip.s_ive_ip.u4_timestamp_low = u4_timestamp_low; + s_bitrate_ip.s_ive_ip.u4_size = sizeof(ih264e_ctl_set_bitrate_ip_t); + s_bitrate_ip.s_ive_ip.e_cmd = IVE_CMD_VIDEO_CTL; + s_bitrate_ip.s_ive_ip.e_sub_cmd = IVE_CMD_CTL_SET_BITRATE; + s_bitrate_ip.s_ive_ip.u4_target_bitrate = ps_app_ctxt->u4_bitrate; + s_bitrate_ip.s_ive_ip.u4_timestamp_low = u4_timestamp_low; + s_bitrate_ip.s_ive_ip.u4_timestamp_high = u4_timestamp_high; - s_bitrate_ip.s_ive_ip.u4_size = sizeof(ih264e_ctl_set_bitrate_ip_t); - s_bitrate_op.s_ive_op.u4_size = sizeof(ih264e_ctl_set_bitrate_op_t); + s_bitrate_op.s_ive_op.u4_size = sizeof(ih264e_ctl_set_bitrate_op_t); - status = ih264e_api_function(ps_app_ctxt->ps_enc,&s_bitrate_ip,&s_bitrate_op); + status = ih264e_api_function(ps_app_ctxt->ps_enc, &s_bitrate_ip, + &s_bitrate_op); if(status != IV_SUCCESS) - { - CHAR ac_error[STRLENGTH]; - sprintf(ac_error, "Unable to set bit rate = 0x%x\n", - s_bitrate_op.s_ive_op.u4_error_code); - codec_exit(ac_error); - } - return; + { + CHAR ac_error[STRLENGTH]; + sprintf(ac_error, "Unable to set bit rate = 0x%x\n", + s_bitrate_op.s_ive_op.u4_error_code); + codec_exit(ac_error); + } } - +/** +******************************************************************************* +* @brief configure frame type +******************************************************************************* +*/ void set_frame_type(app_ctxt_t *ps_app_ctxt, UWORD32 u4_timestamp_low, UWORD32 u4_timestamp_high, - IV_PICTURE_CODING_TYPE_T e_frame_type) + IV_PICTURE_CODING_TYPE_T e_frame_type) { ih264e_ctl_set_frame_type_ip_t s_frame_type_ip; ih264e_ctl_set_frame_type_op_t s_frame_type_op; IV_STATUS_T status; - s_frame_type_ip.s_ive_ip.e_cmd = IVE_CMD_VIDEO_CTL; - s_frame_type_ip.s_ive_ip.e_sub_cmd = IVE_CMD_CTL_SET_FRAMETYPE; - - s_frame_type_ip.s_ive_ip.e_frame_type = e_frame_type; - - s_frame_type_ip.s_ive_ip.u4_timestamp_high = u4_timestamp_high; - s_frame_type_ip.s_ive_ip.u4_timestamp_low = u4_timestamp_low; + s_frame_type_ip.s_ive_ip.u4_size = sizeof(ih264e_ctl_set_frame_type_ip_t); + s_frame_type_ip.s_ive_ip.e_cmd = IVE_CMD_VIDEO_CTL; + s_frame_type_ip.s_ive_ip.e_sub_cmd = IVE_CMD_CTL_SET_FRAMETYPE; + s_frame_type_ip.s_ive_ip.e_frame_type = e_frame_type; + s_frame_type_ip.s_ive_ip.u4_timestamp_low = u4_timestamp_low; + s_frame_type_ip.s_ive_ip.u4_timestamp_high = u4_timestamp_high; - s_frame_type_ip.s_ive_ip.u4_size = sizeof(ih264e_ctl_set_frame_type_ip_t); - s_frame_type_op.s_ive_op.u4_size = sizeof(ih264e_ctl_set_frame_type_op_t); + s_frame_type_op.s_ive_op.u4_size = sizeof(ih264e_ctl_set_frame_type_op_t); - status = ih264e_api_function(ps_app_ctxt->ps_enc,&s_frame_type_ip,&s_frame_type_op); + status = ih264e_api_function(ps_app_ctxt->ps_enc, &s_frame_type_ip, + &s_frame_type_op); if(status != IV_SUCCESS) { CHAR ac_error[STRLENGTH]; @@ -1172,70 +1167,73 @@ void set_frame_type(app_ctxt_t *ps_app_ctxt, s_frame_type_op.s_ive_op.u4_error_code); codec_exit(ac_error); } - return; } +/** +******************************************************************************* +* @brief configure qp +******************************************************************************* +*/ void set_qp(app_ctxt_t *ps_app_ctxt, - UWORD32 u4_timestamp_low, UWORD32 u4_timestamp_high) + UWORD32 u4_timestamp_low, + UWORD32 u4_timestamp_high) { ih264e_ctl_set_qp_ip_t s_qp_ip; ih264e_ctl_set_qp_op_t s_qp_op; IV_STATUS_T status; - s_qp_ip.s_ive_ip.e_cmd = IVE_CMD_VIDEO_CTL; - s_qp_ip.s_ive_ip.e_sub_cmd = IVE_CMD_CTL_SET_QP; - + s_qp_ip.s_ive_ip.u4_size = sizeof(ih264e_ctl_set_qp_ip_t); + s_qp_ip.s_ive_ip.e_cmd = IVE_CMD_VIDEO_CTL; + s_qp_ip.s_ive_ip.e_sub_cmd = IVE_CMD_CTL_SET_QP; s_qp_ip.s_ive_ip.u4_i_qp = ps_app_ctxt->u4_i_qp; s_qp_ip.s_ive_ip.u4_i_qp_max = ps_app_ctxt->u4_i_qp_max; s_qp_ip.s_ive_ip.u4_i_qp_min = ps_app_ctxt->u4_i_qp_min; - s_qp_ip.s_ive_ip.u4_p_qp = ps_app_ctxt->u4_p_qp; s_qp_ip.s_ive_ip.u4_p_qp_max = ps_app_ctxt->u4_p_qp_max; s_qp_ip.s_ive_ip.u4_p_qp_min = ps_app_ctxt->u4_p_qp_min; - s_qp_ip.s_ive_ip.u4_b_qp = ps_app_ctxt->u4_b_qp; s_qp_ip.s_ive_ip.u4_b_qp_max = ps_app_ctxt->u4_b_qp_max; s_qp_ip.s_ive_ip.u4_b_qp_min = ps_app_ctxt->u4_b_qp_min; + s_qp_ip.s_ive_ip.u4_timestamp_low = u4_timestamp_low; + s_qp_ip.s_ive_ip.u4_timestamp_high = u4_timestamp_high; - s_qp_ip.s_ive_ip.u4_timestamp_high = u4_timestamp_high; - s_qp_ip.s_ive_ip.u4_timestamp_low = u4_timestamp_low; - - s_qp_ip.s_ive_ip.u4_size = sizeof(ih264e_ctl_set_qp_ip_t); - s_qp_op.s_ive_op.u4_size = sizeof(ih264e_ctl_set_qp_op_t); + s_qp_op.s_ive_op.u4_size = sizeof(ih264e_ctl_set_qp_op_t); - status = ih264e_api_function(ps_app_ctxt->ps_enc,&s_qp_ip,&s_qp_op); + status = ih264e_api_function(ps_app_ctxt->ps_enc, &s_qp_ip, &s_qp_op); if(status != IV_SUCCESS) - { - CHAR ac_error[STRLENGTH]; - sprintf(ac_error, "Unable to set qp 0x%x\n", - s_qp_op.s_ive_op.u4_error_code); - codec_exit(ac_error); - } - return; + { + CHAR ac_error[STRLENGTH]; + sprintf(ac_error, "Unable to set qp 0x%x\n", + s_qp_op.s_ive_op.u4_error_code); + codec_exit(ac_error); + } } +/** +******************************************************************************* +* @brief configure encoder mode +******************************************************************************* +*/ void set_enc_mode(app_ctxt_t *ps_app_ctxt, - UWORD32 u4_timestamp_low, UWORD32 u4_timestamp_high, + UWORD32 u4_timestamp_low, + UWORD32 u4_timestamp_high, IVE_ENC_MODE_T e_enc_mode) { - IV_STATUS_T status; - ih264e_ctl_set_enc_mode_ip_t s_enc_mode_ip; ih264e_ctl_set_enc_mode_op_t s_enc_mode_op; + IV_STATUS_T status; + s_enc_mode_ip.s_ive_ip.u4_size = sizeof(ih264e_ctl_set_enc_mode_ip_t); s_enc_mode_ip.s_ive_ip.e_cmd = IVE_CMD_VIDEO_CTL; s_enc_mode_ip.s_ive_ip.e_sub_cmd = IVE_CMD_CTL_SET_ENC_MODE; - s_enc_mode_ip.s_ive_ip.e_enc_mode = e_enc_mode; - - s_enc_mode_ip.s_ive_ip.u4_timestamp_high = u4_timestamp_high; s_enc_mode_ip.s_ive_ip.u4_timestamp_low = u4_timestamp_low; + s_enc_mode_ip.s_ive_ip.u4_timestamp_high = u4_timestamp_high; - s_enc_mode_ip.s_ive_ip.u4_size = sizeof(ih264e_ctl_set_enc_mode_ip_t); s_enc_mode_op.s_ive_op.u4_size = sizeof(ih264e_ctl_set_enc_mode_op_t); status = ih264e_api_function(ps_app_ctxt->ps_enc, &s_enc_mode_ip, - &s_enc_mode_op); + &s_enc_mode_op); if(status != IV_SUCCESS) { CHAR ac_error[STRLENGTH]; @@ -1243,10 +1241,13 @@ void set_enc_mode(app_ctxt_t *ps_app_ctxt, s_enc_mode_op.s_ive_op.u4_error_code); codec_exit(ac_error); } - return; } - +/** +******************************************************************************* +* @brief configure vbv params +******************************************************************************* +*/ void set_vbv_params(app_ctxt_t *ps_app_ctxt, UWORD32 u4_timestamp_low, UWORD32 u4_timestamp_high) @@ -1255,20 +1256,17 @@ void set_vbv_params(app_ctxt_t *ps_app_ctxt, ih264e_ctl_set_vbv_params_op_t s_vbv_op; IV_STATUS_T status; - s_vbv_ip.s_ive_ip.e_cmd = IVE_CMD_VIDEO_CTL; - s_vbv_ip.s_ive_ip.e_sub_cmd = IVE_CMD_CTL_SET_VBV_PARAMS; - + s_vbv_ip.s_ive_ip.u4_size = sizeof(ih264e_ctl_set_vbv_params_ip_t); + s_vbv_ip.s_ive_ip.e_cmd = IVE_CMD_VIDEO_CTL; + s_vbv_ip.s_ive_ip.e_sub_cmd = IVE_CMD_CTL_SET_VBV_PARAMS; + s_vbv_ip.s_ive_ip.u4_vbv_buffer_delay = ps_app_ctxt->u4_vbv_buffer_delay; s_vbv_ip.s_ive_ip.u4_vbv_buf_size = ps_app_ctxt->u4_vbv_buf_size; - s_vbv_ip.s_ive_ip.u4_vbv_buffer_delay = - ps_app_ctxt->u4_vbv_buffer_delay; + s_vbv_ip.s_ive_ip.u4_timestamp_low = u4_timestamp_low; + s_vbv_ip.s_ive_ip.u4_timestamp_high = u4_timestamp_high; - s_vbv_ip.s_ive_ip.u4_timestamp_high = u4_timestamp_high; - s_vbv_ip.s_ive_ip.u4_timestamp_low = u4_timestamp_low; + s_vbv_op.s_ive_op.u4_size = sizeof(ih264e_ctl_set_vbv_params_op_t); - s_vbv_ip.s_ive_ip.u4_size = sizeof(ih264e_ctl_set_vbv_params_ip_t); - s_vbv_op.s_ive_op.u4_size = sizeof(ih264e_ctl_set_vbv_params_op_t); - - status = ih264e_api_function(ps_app_ctxt->ps_enc,&s_vbv_ip,&s_vbv_op); + status = ih264e_api_function(ps_app_ctxt->ps_enc, &s_vbv_ip, &s_vbv_op); if(status != IV_SUCCESS) { CHAR ac_error[STRLENGTH]; @@ -1276,9 +1274,13 @@ void set_vbv_params(app_ctxt_t *ps_app_ctxt, s_vbv_op.s_ive_op.u4_error_code); codec_exit(ac_error); } - return; } +/** +******************************************************************************* +* @brief configure air params +******************************************************************************* +*/ void set_air_params(app_ctxt_t *ps_app_ctxt, UWORD32 u4_timestamp_low, UWORD32 u4_timestamp_high) @@ -1287,54 +1289,52 @@ void set_air_params(app_ctxt_t *ps_app_ctxt, ih264e_ctl_set_air_params_op_t s_air_op; IV_STATUS_T status; - s_air_ip.s_ive_ip.e_cmd = IVE_CMD_VIDEO_CTL; - s_air_ip.s_ive_ip.e_sub_cmd = IVE_CMD_CTL_SET_AIR_PARAMS; - + s_air_ip.s_ive_ip.u4_size = sizeof(ih264e_ctl_set_air_params_ip_t); + s_air_ip.s_ive_ip.e_cmd = IVE_CMD_VIDEO_CTL; + s_air_ip.s_ive_ip.e_sub_cmd = IVE_CMD_CTL_SET_AIR_PARAMS; s_air_ip.s_ive_ip.e_air_mode = ps_app_ctxt->u4_air; s_air_ip.s_ive_ip.u4_air_refresh_period = ps_app_ctxt->u4_air_refresh_period; + s_air_ip.s_ive_ip.u4_timestamp_low = u4_timestamp_low; + s_air_ip.s_ive_ip.u4_timestamp_high = u4_timestamp_high; - s_air_ip.s_ive_ip.u4_timestamp_high = u4_timestamp_high; - s_air_ip.s_ive_ip.u4_timestamp_low = u4_timestamp_low; + s_air_op.s_ive_op.u4_size = sizeof(ih264e_ctl_set_air_params_op_t); - s_air_ip.s_ive_ip.u4_size = sizeof(ih264e_ctl_set_air_params_ip_t); - s_air_op.s_ive_op.u4_size = sizeof(ih264e_ctl_set_air_params_op_t); - - status = ih264e_api_function(ps_app_ctxt->ps_enc,&s_air_ip,&s_air_op); + status = ih264e_api_function(ps_app_ctxt->ps_enc, &s_air_ip, &s_air_op); if(status != IV_SUCCESS) - { - CHAR ac_error[STRLENGTH]; - sprintf(ac_error, "Unable to set air params = 0x%x\n", - s_air_op.s_ive_op.u4_error_code); - codec_exit(ac_error); - } - return; + { + CHAR ac_error[STRLENGTH]; + sprintf(ac_error, "Unable to set air params = 0x%x\n", + s_air_op.s_ive_op.u4_error_code); + codec_exit(ac_error); + } } +/** +******************************************************************************* +* @brief configure me params +******************************************************************************* +*/ void set_me_params(app_ctxt_t *ps_app_ctxt, - UWORD32 u4_timestamp_low, - UWORD32 u4_timestamp_high) + UWORD32 u4_timestamp_low, + UWORD32 u4_timestamp_high) { - IV_STATUS_T status; - ih264e_ctl_set_me_params_ip_t s_me_params_ip; ih264e_ctl_set_me_params_op_t s_me_params_op; + IV_STATUS_T status; + s_me_params_ip.s_ive_ip.u4_size = sizeof(ih264e_ctl_set_me_params_ip_t); s_me_params_ip.s_ive_ip.e_cmd = IVE_CMD_VIDEO_CTL; s_me_params_ip.s_ive_ip.e_sub_cmd = IVE_CMD_CTL_SET_ME_PARAMS; - + s_me_params_ip.s_ive_ip.u4_me_speed_preset = ps_app_ctxt->u4_me_speed; + s_me_params_ip.s_ive_ip.u4_enable_hpel = ps_app_ctxt->u4_hpel; + s_me_params_ip.s_ive_ip.u4_enable_qpel = ps_app_ctxt->u4_qpel; s_me_params_ip.s_ive_ip.u4_enable_fast_sad = ps_app_ctxt->u4_enable_fast_sad; s_me_params_ip.s_ive_ip.u4_enable_alt_ref = ps_app_ctxt->u4_enable_alt_ref; - - s_me_params_ip.s_ive_ip.u4_enable_hpel = ps_app_ctxt->u4_hpel; - s_me_params_ip.s_ive_ip.u4_enable_qpel = ps_app_ctxt->u4_qpel; - s_me_params_ip.s_ive_ip.u4_me_speed_preset = ps_app_ctxt->u4_me_speed; - s_me_params_ip.s_ive_ip.u4_srch_rng_x = ps_app_ctxt->u4_srch_rng_x; - s_me_params_ip.s_ive_ip.u4_srch_rng_y = ps_app_ctxt->u4_srch_rng_y; - - s_me_params_ip.s_ive_ip.u4_timestamp_high = u4_timestamp_high; + s_me_params_ip.s_ive_ip.u4_srch_rng_x = ps_app_ctxt->u4_srch_rng_x; + s_me_params_ip.s_ive_ip.u4_srch_rng_y = ps_app_ctxt->u4_srch_rng_y; s_me_params_ip.s_ive_ip.u4_timestamp_low = u4_timestamp_low; + s_me_params_ip.s_ive_ip.u4_timestamp_high = u4_timestamp_high; - s_me_params_ip.s_ive_ip.u4_size = sizeof(ih264e_ctl_set_me_params_ip_t); s_me_params_op.s_ive_op.u4_size = sizeof(ih264e_ctl_set_me_params_op_t); status = ih264e_api_function(ps_app_ctxt->ps_enc, &s_me_params_ip, @@ -1346,29 +1346,29 @@ void set_me_params(app_ctxt_t *ps_app_ctxt, s_me_params_op.s_ive_op.u4_error_code); codec_exit(ac_error); } - return; } - +/** +******************************************************************************* +* @brief configure gop params +******************************************************************************* +*/ void set_gop_params(app_ctxt_t *ps_app_ctxt, UWORD32 u4_timestamp_low, UWORD32 u4_timestamp_high) { - IV_STATUS_T status; - ih264e_ctl_set_gop_params_ip_t s_gop_params_ip; ih264e_ctl_set_gop_params_op_t s_gop_params_op; + IV_STATUS_T status; + s_gop_params_ip.s_ive_ip.u4_size = sizeof(ih264e_ctl_set_gop_params_ip_t); s_gop_params_ip.s_ive_ip.e_cmd = IVE_CMD_VIDEO_CTL; s_gop_params_ip.s_ive_ip.e_sub_cmd = IVE_CMD_CTL_SET_GOP_PARAMS; - s_gop_params_ip.s_ive_ip.u4_i_frm_interval = ps_app_ctxt->u4_i_interval; s_gop_params_ip.s_ive_ip.u4_idr_frm_interval = ps_app_ctxt->u4_idr_interval; - - s_gop_params_ip.s_ive_ip.u4_timestamp_high = u4_timestamp_high; s_gop_params_ip.s_ive_ip.u4_timestamp_low = u4_timestamp_low; + s_gop_params_ip.s_ive_ip.u4_timestamp_high = u4_timestamp_high; - s_gop_params_ip.s_ive_ip.u4_size = sizeof(ih264e_ctl_set_gop_params_ip_t); s_gop_params_op.s_ive_op.u4_size = sizeof(ih264e_ctl_set_gop_params_op_t); status = ih264e_api_function(ps_app_ctxt->ps_enc, &s_gop_params_ip, @@ -1376,37 +1376,37 @@ void set_gop_params(app_ctxt_t *ps_app_ctxt, if(status != IV_SUCCESS) { CHAR ac_error[STRLENGTH]; - sprintf(ac_error, "Unable to set ME params = 0x%x\n", + sprintf(ac_error, "Unable to set GOP params = 0x%x\n", s_gop_params_op.s_ive_op.u4_error_code); codec_exit(ac_error); } - return; } +/** +******************************************************************************* +* @brief configure profile params +******************************************************************************* +*/ void set_profile_params(app_ctxt_t *ps_app_ctxt, - UWORD32 u4_timestamp_low, - UWORD32 u4_timestamp_high) + UWORD32 u4_timestamp_low, + UWORD32 u4_timestamp_high) { - IV_STATUS_T status; - ih264e_ctl_set_profile_params_ip_t s_profile_params_ip; ih264e_ctl_set_profile_params_op_t s_profile_params_op; + IV_STATUS_T status; + s_profile_params_ip.s_ive_ip.u4_size = sizeof(ih264e_ctl_set_profile_params_ip_t); s_profile_params_ip.s_ive_ip.e_cmd = IVE_CMD_VIDEO_CTL; s_profile_params_ip.s_ive_ip.e_sub_cmd = IVE_CMD_CTL_SET_PROFILE_PARAMS; - s_profile_params_ip.s_ive_ip.e_profile = ps_app_ctxt->e_profile; - - s_profile_params_ip.s_ive_ip.u4_entropy_coding_mode = ps_app_ctxt->u4_entropy_coding_mode; - s_profile_params_ip.s_ive_ip.u4_timestamp_high = u4_timestamp_high; s_profile_params_ip.s_ive_ip.u4_timestamp_low = u4_timestamp_low; + s_profile_params_ip.s_ive_ip.u4_entropy_coding_mode = ps_app_ctxt->u4_entropy_coding_mode; - s_profile_params_ip.s_ive_ip.u4_size = sizeof(ih264e_ctl_set_profile_params_ip_t); s_profile_params_op.s_ive_op.u4_size = sizeof(ih264e_ctl_set_profile_params_op_t); status = ih264e_api_function(ps_app_ctxt->ps_enc, &s_profile_params_ip, - &s_profile_params_op); + &s_profile_params_op); if(status != IV_SUCCESS) { CHAR ac_error[STRLENGTH]; @@ -1414,32 +1414,32 @@ void set_profile_params(app_ctxt_t *ps_app_ctxt, s_profile_params_op.s_ive_op.u4_error_code); codec_exit(ac_error); } - return; } +/** +******************************************************************************* +* @brief configure deblock params +******************************************************************************* +*/ void set_deblock_params(app_ctxt_t *ps_app_ctxt, - UWORD32 u4_timestamp_low, - UWORD32 u4_timestamp_high) + UWORD32 u4_timestamp_low, + UWORD32 u4_timestamp_high) { - IV_STATUS_T status; - ih264e_ctl_set_deblock_params_ip_t s_deblock_params_ip; ih264e_ctl_set_deblock_params_op_t s_deblock_params_op; + IV_STATUS_T status; + s_deblock_params_ip.s_ive_ip.u4_size = sizeof(ih264e_ctl_set_deblock_params_ip_t); s_deblock_params_ip.s_ive_ip.e_cmd = IVE_CMD_VIDEO_CTL; s_deblock_params_ip.s_ive_ip.e_sub_cmd = IVE_CMD_CTL_SET_DEBLOCK_PARAMS; - - s_deblock_params_ip.s_ive_ip.u4_disable_deblock_level = - ps_app_ctxt->u4_disable_deblk_level; - + s_deblock_params_ip.s_ive_ip.u4_disable_deblock_level = ps_app_ctxt->u4_disable_deblk_level; s_deblock_params_ip.s_ive_ip.u4_timestamp_high = u4_timestamp_high; s_deblock_params_ip.s_ive_ip.u4_timestamp_low = u4_timestamp_low; - s_deblock_params_ip.s_ive_ip.u4_size = sizeof(ih264e_ctl_set_deblock_params_ip_t); s_deblock_params_op.s_ive_op.u4_size = sizeof(ih264e_ctl_set_deblock_params_op_t); status = ih264e_api_function(ps_app_ctxt->ps_enc, &s_deblock_params_ip, - &s_deblock_params_op); + &s_deblock_params_op); if(status != IV_SUCCESS) { CHAR ac_error[STRLENGTH]; @@ -1447,20 +1447,22 @@ void set_deblock_params(app_ctxt_t *ps_app_ctxt, s_deblock_params_op.s_ive_op.u4_error_code); codec_exit(ac_error); } - return; } - +/** +******************************************************************************* +* @brief configure VUI params +******************************************************************************* +*/ void set_vui_params(app_ctxt_t *ps_app_ctxt) { - IV_STATUS_T status; - ih264e_vui_ip_t s_vui_params_ip; ih264e_vui_op_t s_vui_params_op; + IV_STATUS_T status; + s_vui_params_ip.u4_size = sizeof(ih264e_vui_ip_t); s_vui_params_ip.e_cmd = IVE_CMD_VIDEO_CTL; s_vui_params_ip.e_sub_cmd = IVE_CMD_CTL_SET_VUI_PARAMS; - s_vui_params_ip.u1_aspect_ratio_info_present_flag = 0; s_vui_params_ip.u1_aspect_ratio_idc = 0; s_vui_params_ip.u2_sar_width = 0; @@ -1494,12 +1496,10 @@ void set_vui_params(app_ctxt_t *ps_app_ctxt) s_vui_params_ip.u1_num_reorder_frames = 0; s_vui_params_ip.u1_max_dec_frame_buffering = 0; - - s_vui_params_ip.u4_size = sizeof(ih264e_vui_ip_t); s_vui_params_op.u4_size = sizeof(ih264e_vui_op_t); status = ih264e_api_function(ps_app_ctxt->ps_enc, &s_vui_params_ip, - &s_vui_params_op); + &s_vui_params_op); if(status != IV_SUCCESS) { CHAR ac_error[STRLENGTH]; @@ -1808,10 +1808,14 @@ void set_sei_sii_params(app_ctxt_t *ps_app_ctxt, UWORD32 u4_timestamp_low, return; } -#define PEAK_WINDOW_SIZE 8 - +/** +******************************************************************************* +* @brief encode input +******************************************************************************* +*/ void synchronous_encode(iv_obj_t *ps_enc, app_ctxt_t *ps_app_ctxt) { +#define PEAK_WINDOW_SIZE 8 ih264e_video_encode_ip_t ih264e_video_encode_ip = {0}; ih264e_video_encode_op_t ih264e_video_encode_op = {0}; @@ -1825,10 +1829,10 @@ void synchronous_encode(iv_obj_t *ps_enc, app_ctxt_t *ps_app_ctxt) WORD32 i, is_last = 0, buff_size = 0, num_bytes = 0; UWORD32 u4_total_time = 0; UWORD8 *pu1_buf = NULL; - UWORD32 u4_timestamp_low, u4_timestamp_high; + UWORD32 u4_timestamp_low = 0, u4_timestamp_high = 0; void *pv_mb_info = NULL, *pv_pic_info = NULL; - TIMER curtime ; + TIMER curtime; #ifdef WINDOWS_TIMER TIMER frequency; #endif @@ -1837,34 +1841,31 @@ void synchronous_encode(iv_obj_t *ps_enc, app_ctxt_t *ps_app_ctxt) WORD32 peak_avg_max = 0, timetaken = 0; iv_raw_buf_t s_inp_buf, s_recon_buf; CHAR ac_error[STRLENGTH]; - WORD32 end_of_frames=0; - WORD32 i4_inp_done =0; - - u4_timestamp_low = 0; - u4_timestamp_high = 0; + WORD32 end_of_frames = 0; + WORD32 i4_inp_done = 0; - /*************************************************************************/ - /* Allocate I/O Buffers */ - /*************************************************************************/ + /* Allocate I/O Buffers */ allocate_input(ps_app_ctxt); allocate_output(ps_app_ctxt); allocate_recon(ps_app_ctxt); - /* init psnr */ + /* init psnr ctxt */ init_psnr(ps_app_ctxt); /* open file pointers */ ps_app_ctxt->fp_ip = fopen(ps_app_ctxt->ac_ip_fname, "rb"); if(NULL == ps_app_ctxt->fp_ip) { - sprintf(ac_error, "Unable to open input file for reading: %s", ps_app_ctxt->ac_ip_fname); + sprintf(ac_error, "Unable to open input file for reading: %s", + ps_app_ctxt->ac_ip_fname); invalid_argument_exit(ac_error); } ps_app_ctxt->fp_op = fopen(ps_app_ctxt->ac_op_fname, "wb"); if(NULL == ps_app_ctxt->fp_op) { - sprintf(ac_error, "Unable to open output file for writing: %s", ps_app_ctxt->ac_op_fname); + sprintf(ac_error, "Unable to open output file for writing: %s", + ps_app_ctxt->ac_op_fname); invalid_argument_exit(ac_error); } @@ -1873,49 +1874,57 @@ void synchronous_encode(iv_obj_t *ps_enc, app_ctxt_t *ps_app_ctxt) ps_app_ctxt->fp_recon = fopen(ps_app_ctxt->ac_recon_fname, "wb"); if(NULL == ps_app_ctxt->fp_recon) { - sprintf(ac_error, "Unable to open recon file for writing: %s", ps_app_ctxt->ac_recon_fname); + sprintf(ac_error, "Unable to open recon file for writing: %s", + ps_app_ctxt->ac_recon_fname); invalid_argument_exit(ac_error); } } if(1 == ps_app_ctxt->u4_chksum_enable) { - ps_app_ctxt->fp_chksum = fopen(ps_app_ctxt->ac_chksum_fname, "wb"); + ps_app_ctxt->fp_chksum = fopen(ps_app_ctxt->ac_chksum_fname, "wb"); if(NULL == ps_app_ctxt->fp_chksum) { - sprintf(ac_error, "Unable to open checksum file for writing: %s", ps_app_ctxt->ac_chksum_fname); + sprintf(ac_error, "Unable to open checksum file for writing: %s", + ps_app_ctxt->ac_chksum_fname); invalid_argument_exit(ac_error); } } - /* If PSNR is enabled, open input file again and hold a different file pointer - * This makes it easy to compute PSNR without adding dependency between input and recon threads + /* + * If PSNR is enabled, open input file again and hold a different file pointer + * This makes it easy to compute PSNR without adding dependency between + * input and recon threads */ if(1 == ps_app_ctxt->u4_psnr_enable) { - ps_app_ctxt->fp_psnr_ip = fopen(ps_app_ctxt->ac_ip_fname, "rb"); + ps_app_ctxt->fp_psnr_ip = fopen(ps_app_ctxt->ac_ip_fname, "rb"); if(NULL == ps_app_ctxt->fp_psnr_ip) { - sprintf(ac_error, "Unable to open input file for reading: %s", ps_app_ctxt->ac_ip_fname); + sprintf(ac_error, "Unable to open input file for reading: %s", + ps_app_ctxt->ac_ip_fname); invalid_argument_exit(ac_error); } } if(0 != ps_app_ctxt->u4_mb_info_type) { - ps_app_ctxt->fp_mb_info = fopen(ps_app_ctxt->ac_mb_info_fname, "rb"); + ps_app_ctxt->fp_mb_info = fopen(ps_app_ctxt->ac_mb_info_fname, "rb"); if(NULL == ps_app_ctxt->fp_mb_info) { - sprintf(ac_error, "Unable to open MB info file for reading: %s", ps_app_ctxt->ac_mb_info_fname); + sprintf(ac_error, "Unable to open MB info file for reading: %s", + ps_app_ctxt->ac_mb_info_fname); invalid_argument_exit(ac_error); } } - if (ps_app_ctxt->u4_pic_info_type) + + if(ps_app_ctxt->u4_pic_info_type) { - ps_app_ctxt->fp_pic_info = fopen(ps_app_ctxt->ac_pic_info_fname, "rb"); + ps_app_ctxt->fp_pic_info = fopen(ps_app_ctxt->ac_pic_info_fname, "rb"); if(NULL == ps_app_ctxt->fp_pic_info) { - sprintf(ac_error, "Unable to open Pic info file for reading: %s", ps_app_ctxt->ac_pic_info_fname); + sprintf(ac_error, "Unable to open Pic info file for reading: %s", + ps_app_ctxt->ac_pic_info_fname); invalid_argument_exit(ac_error); } } @@ -2070,10 +2079,7 @@ void synchronous_encode(iv_obj_t *ps_enc, app_ctxt_t *ps_app_ctxt) } set_sei_sii_params(ps_app_ctxt, u4_timestamp_low, u4_timestamp_high); - /******************************************************************************/ - /****************** Input Initialization **************************************/ - /******************************************************************************/ - + /* Input Initialization */ for(i = 0; i < DEFAULT_MAX_INPUT_BUFS; i++) { if(ps_app_ctxt->as_input_buf[i].u4_is_free) @@ -2085,103 +2091,97 @@ void synchronous_encode(iv_obj_t *ps_enc, app_ctxt_t *ps_app_ctxt) break; } } - if (i == DEFAULT_MAX_INPUT_BUFS) { printf("\n Unable to find a free input buffer!!"); exit(0); } - memset(&ih264e_video_encode_ip, 0, sizeof(ih264e_video_encode_ip)); - memset(&ih264e_video_encode_op, 0, sizeof(ih264e_video_encode_op)); - ps_video_encode_ip->u4_size = sizeof(ih264e_video_encode_ip_t); - ps_video_encode_op->u4_size = sizeof(ih264e_video_encode_op_t); - ps_video_encode_ip->e_cmd = IVE_CMD_VIDEO_ENCODE; ps_video_encode_ip->pv_bufs = pu1_buf; ps_video_encode_ip->pv_mb_info = pv_mb_info; ps_video_encode_ip->pv_pic_info = pv_pic_info; ps_video_encode_ip->u4_pic_info_type = ps_app_ctxt->u4_pic_info_type; + + ps_video_encode_op->u4_size = sizeof(ih264e_video_encode_op_t); + /* * Since the buffers are used for reading, - * And after each row we have a stride we nned to calculate + * And after each row we have a stride we need to calculate * the luma size according to the stride */ ps_inp_raw_buf->e_color_fmt = ps_app_ctxt->e_inp_color_fmt; - - /* Initialize for 420SP */ - if(IV_YUV_420SP_UV == ps_app_ctxt->e_inp_color_fmt|| - IV_YUV_420SP_VU == ps_app_ctxt->e_inp_color_fmt) + if(IV_YUV_420SP_UV == ps_app_ctxt->e_inp_color_fmt + || IV_YUV_420SP_VU == ps_app_ctxt->e_inp_color_fmt) { - /*init luma buffer*/ + /* init luma buffer */ ps_inp_raw_buf->apv_bufs[0] = pu1_buf; - /*Init chroma buffer*/ + /* init chroma buffer */ pu1_buf += ps_app_ctxt->u4_strd * ps_app_ctxt->u4_ht; ps_inp_raw_buf->apv_bufs[1] = pu1_buf; - ps_inp_raw_buf->au4_wd[0] = ps_app_ctxt->u4_wd; - ps_inp_raw_buf->au4_wd[1] = ps_app_ctxt->u4_wd; + ps_inp_raw_buf->au4_wd[0] = ps_app_ctxt->u4_wd; + ps_inp_raw_buf->au4_wd[1] = ps_app_ctxt->u4_wd; - ps_inp_raw_buf->au4_ht[0] = ps_app_ctxt->u4_ht; - ps_inp_raw_buf->au4_ht[1] = ps_app_ctxt->u4_ht / 2; + ps_inp_raw_buf->au4_ht[0] = ps_app_ctxt->u4_ht; + ps_inp_raw_buf->au4_ht[1] = ps_app_ctxt->u4_ht / 2; - ps_inp_raw_buf->au4_strd[0] = ps_app_ctxt->u4_strd; - ps_inp_raw_buf->au4_strd[1] = ps_app_ctxt->u4_strd; + ps_inp_raw_buf->au4_strd[0] = ps_app_ctxt->u4_strd; + ps_inp_raw_buf->au4_strd[1] = ps_app_ctxt->u4_strd; } else if(IV_YUV_420P == ps_app_ctxt->e_inp_color_fmt) { - /* init buffers */ + /* init luma buffer */ ps_inp_raw_buf->apv_bufs[0] = pu1_buf; pu1_buf += (ps_app_ctxt->u4_wd) * ps_app_ctxt->u4_ht; + + /* init chroma buffer U */ ps_inp_raw_buf->apv_bufs[1] = pu1_buf; pu1_buf += (ps_app_ctxt->u4_wd >> 1) * (ps_app_ctxt->u4_ht >> 1); + + /* init chroma buffer V */ ps_inp_raw_buf->apv_bufs[2] = pu1_buf; - ps_inp_raw_buf->au4_wd[0] = ps_app_ctxt->u4_wd; - ps_inp_raw_buf->au4_wd[1] = ps_app_ctxt->u4_wd / 2; - ps_inp_raw_buf->au4_wd[2] = ps_app_ctxt->u4_wd / 2; + ps_inp_raw_buf->au4_wd[0] = ps_app_ctxt->u4_wd; + ps_inp_raw_buf->au4_wd[1] = ps_app_ctxt->u4_wd / 2; + ps_inp_raw_buf->au4_wd[2] = ps_app_ctxt->u4_wd / 2; - ps_inp_raw_buf->au4_ht[0] = ps_app_ctxt->u4_ht; - ps_inp_raw_buf->au4_ht[1] = ps_app_ctxt->u4_ht / 2; - ps_inp_raw_buf->au4_ht[2] = ps_app_ctxt->u4_ht / 2; + ps_inp_raw_buf->au4_ht[0] = ps_app_ctxt->u4_ht; + ps_inp_raw_buf->au4_ht[1] = ps_app_ctxt->u4_ht / 2; + ps_inp_raw_buf->au4_ht[2] = ps_app_ctxt->u4_ht / 2; - ps_inp_raw_buf->au4_strd[0] = ps_app_ctxt->u4_strd; - ps_inp_raw_buf->au4_strd[1] = ps_app_ctxt->u4_strd / 2; - ps_inp_raw_buf->au4_strd[2] = ps_app_ctxt->u4_strd / 2; + ps_inp_raw_buf->au4_strd[0] = ps_app_ctxt->u4_strd; + ps_inp_raw_buf->au4_strd[1] = ps_app_ctxt->u4_strd / 2; + ps_inp_raw_buf->au4_strd[2] = ps_app_ctxt->u4_strd / 2; } else if(IV_YUV_422ILE == ps_app_ctxt->e_inp_color_fmt) { - /*init luma buffer*/ + /* init luma buffer */ ps_inp_raw_buf->apv_bufs[0] = pu1_buf; - ps_inp_raw_buf->au4_wd[0] = ps_app_ctxt->u4_wd * 2; + ps_inp_raw_buf->au4_wd[0] = ps_app_ctxt->u4_wd * 2; - ps_inp_raw_buf->au4_ht[0] = ps_app_ctxt->u4_ht; + ps_inp_raw_buf->au4_ht[0] = ps_app_ctxt->u4_ht; - ps_inp_raw_buf->au4_strd[0] = ps_app_ctxt->u4_strd *2; + ps_inp_raw_buf->au4_strd[0] = ps_app_ctxt->u4_strd * 2; } - /* - * Here we read input and other associated buffers. Regardless of success - * we will proceed from here as we will need extra calls to flush out - * input queue in encoder. Note that this is not necessary. You can just - * send encode calls till with valid output and recon buffers till the - * queue is flushed. - */ + /* Read input and other associated buffers */ while(1) { - IV_STATUS_T mb_info_status = IV_SUCCESS, pic_info_status = IV_SUCCESS; + IV_STATUS_T mb_info_status = IV_SUCCESS; + IV_STATUS_T pic_info_status = IV_SUCCESS; status = read_input(ps_app_ctxt->fp_ip, ps_inp_raw_buf); - if (ps_app_ctxt->u4_mb_info_type != 0) + if(ps_app_ctxt->u4_mb_info_type != 0) { mb_info_status = read_mb_info(ps_app_ctxt, pv_mb_info); } - if (ps_app_ctxt->u4_pic_info_type != 0) + if(ps_app_ctxt->u4_pic_info_type != 0) { pic_info_status = read_pic_info(ps_app_ctxt, pv_pic_info); } @@ -2194,15 +2194,14 @@ void synchronous_encode(iv_obj_t *ps_enc, app_ctxt_t *ps_app_ctxt) break; } else + { fseek(ps_app_ctxt->fp_ip, 0, SEEK_SET); + } } break; } - /******************************************************************************/ - /****************** Output Initialization *************************************/ - /******************************************************************************/ - + /* Output Initialization */ for(i = 0; i < DEFAULT_MAX_OUTPUT_BUFS; i++) { if(ps_app_ctxt->as_output_buf[i].u4_is_free) @@ -2213,23 +2212,28 @@ void synchronous_encode(iv_obj_t *ps_enc, app_ctxt_t *ps_app_ctxt) break; } } + if (i == DEFAULT_MAX_OUTPUT_BUFS) + { + printf("\n Unable to find a free output buffer!!"); + exit(0); + } ps_video_encode_ip->s_out_buf.pv_buf = pu1_buf; ps_video_encode_ip->s_out_buf.u4_bytes = 0; ps_video_encode_ip->s_out_buf.u4_bufsize = buff_size; - /******************************************************************************/ - /****************** Recon Initialization **************************************/ - /******************************************************************************/ - 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); + /* Recon Initialization */ + 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); + ps_video_encode_ip->s_recon_buf = s_recon_buf; if(ps_app_ctxt->u4_psnr_enable) - init_raw_buf_descr(ps_app_ctxt, &s_inp_buf, ps_app_ctxt->pu1_psnr_buf, ps_app_ctxt->e_inp_color_fmt); - - ps_video_encode_ip->s_recon_buf = s_recon_buf; + { + init_raw_buf_descr(ps_app_ctxt, &s_inp_buf, + ps_app_ctxt->pu1_psnr_buf, + ps_app_ctxt->e_inp_color_fmt); + } - /******************************************************************************/ - /************************* Un Initialized *************************************/ - /******************************************************************************/ if(0 == ps_app_ctxt->u4_loopback) { /* If input file is read completely and loopback is not enabled, @@ -2240,9 +2244,8 @@ void synchronous_encode(iv_obj_t *ps_enc, app_ctxt_t *ps_app_ctxt) } } - /* If last frame, send input null to get back encoded frames */ - if ( is_last == 1 || ((ps_app_ctxt->u4_max_num_frms) <= u4_timestamp_low) ) + if(is_last == 1 || ((ps_app_ctxt->u4_max_num_frms) <= u4_timestamp_low)) { is_last = 1; ps_inp_raw_buf->apv_bufs[0] = NULL; @@ -2252,18 +2255,20 @@ void synchronous_encode(iv_obj_t *ps_enc, app_ctxt_t *ps_app_ctxt) ps_video_encode_ip->u4_is_last = is_last; ps_video_encode_ip->u4_mb_info_type = ps_app_ctxt->u4_mb_info_type; - ps_video_encode_ip->u4_pic_info_type = ps_app_ctxt->u4_pic_info_type;; + ps_video_encode_ip->u4_pic_info_type = ps_app_ctxt->u4_pic_info_type; + ps_video_encode_op->s_out_buf.pv_buf = NULL; ps_video_encode_ip->u4_timestamp_high = u4_timestamp_high; ps_video_encode_ip->u4_timestamp_low = u4_timestamp_low; - GETTIME(&ps_app_ctxt->enc_last_time); - status = ih264e_api_function(ps_enc, &ih264e_video_encode_ip, &ih264e_video_encode_op); - - if (IV_SUCCESS != status) + /* encoder api call */ + status = ih264e_api_function(ps_enc, &ih264e_video_encode_ip, + &ih264e_video_encode_op); + if(IV_SUCCESS != status) { - printf("Encode Frame failed = 0x%x\n", ih264e_video_encode_op.s_ive_op.u4_error_code); + printf("Encode Frame failed = 0x%x\n", + ih264e_video_encode_op.s_ive_op.u4_error_code); break; } @@ -2277,6 +2282,7 @@ void synchronous_encode(iv_obj_t *ps_enc, app_ctxt_t *ps_app_ctxt) #ifdef PROFILE_ENABLE { WORD32 peak_avg, id; + u4_total_time += timetaken; peak_window[peak_window_idx++] = timetaken; if(peak_window_idx == PEAK_WINDOW_SIZE) @@ -2292,17 +2298,13 @@ void synchronous_encode(iv_obj_t *ps_enc, app_ctxt_t *ps_app_ctxt) } #endif - /******************************************************************************/ - /****************** Writing Output ********************************************/ - /******************************************************************************/ + /* Write Output */ num_bytes = 0; - if(1 == ps_video_encode_op->output_present) { num_bytes = ps_video_encode_op->s_out_buf.u4_bytes; buff_size = ps_video_encode_op->s_out_buf.u4_bufsize; pu1_buf = (UWORD8*)ps_video_encode_op->s_out_buf.pv_buf; - status = write_output(ps_app_ctxt->fp_op, pu1_buf, num_bytes); if(IV_SUCCESS != status) { @@ -2312,12 +2314,13 @@ void synchronous_encode(iv_obj_t *ps_enc, app_ctxt_t *ps_app_ctxt) } /* free input bufer if codec returns a valid input buffer */ - if (ps_video_encode_op->s_inp_buf.apv_bufs[0]) + if(ps_video_encode_op->s_inp_buf.apv_bufs[0]) { /* Reuse of freed input buffer */ for(i = 0; i < DEFAULT_MAX_INPUT_BUFS; i++) { - if(ps_app_ctxt->as_input_buf[i].pu1_buf == ps_video_encode_op->s_inp_buf.apv_bufs[0]) + if(ps_app_ctxt->as_input_buf[i].pu1_buf + == ps_video_encode_op->s_inp_buf.apv_bufs[0]) { ps_app_ctxt->as_input_buf[i].u4_is_free = 1; break; @@ -2326,11 +2329,12 @@ void synchronous_encode(iv_obj_t *ps_enc, app_ctxt_t *ps_app_ctxt) } /* free output buffer if codec returns a valid output buffer */ - // if(ps_video_encode_op->s_out_buf.pv_buf) + if(ps_video_encode_op->s_out_buf.pv_buf) { for(i = 0; i < DEFAULT_MAX_OUTPUT_BUFS; i++) { - if(ps_app_ctxt->as_output_buf[i].pu1_buf == ps_video_encode_op->s_out_buf.pv_buf) + if(ps_app_ctxt->as_output_buf[i].pu1_buf + == ps_video_encode_op->s_out_buf.pv_buf) { ps_app_ctxt->as_output_buf[i].u4_is_free = 1; break; @@ -2338,41 +2342,33 @@ void synchronous_encode(iv_obj_t *ps_enc, app_ctxt_t *ps_app_ctxt) } } - /********************************************************************** - * Print stats - **********************************************************************/ + /* Print stats */ { - UWORD8 u1_pic_type[][5] = - { "IDR", "I", "P", "B", "NA" }; + UWORD8 u1_pic_type[][5] = { "IDR", "I", "P", "B", "NA" }; WORD32 lookup_idx = 0; - if (ih264e_video_encode_op.s_ive_op.u4_encoded_frame_type - == IV_IDR_FRAME) - { - lookup_idx = 0; - } - else if(ih264e_video_encode_op.s_ive_op.u4_encoded_frame_type - == IV_I_FRAME) + switch(ih264e_video_encode_op.s_ive_op.u4_encoded_frame_type) { - lookup_idx = 1; - } - else if(ih264e_video_encode_op.s_ive_op.u4_encoded_frame_type - == IV_P_FRAME) - { - lookup_idx = 2; - } - else if(ih264e_video_encode_op.s_ive_op.u4_encoded_frame_type - == IV_B_FRAME) - { - lookup_idx = 3; - } - else if(ih264e_video_encode_op.s_ive_op.u4_encoded_frame_type - == IV_NA_FRAME) - { - lookup_idx = 4; + case IV_IDR_FRAME: + lookup_idx = 0; + break; + case IV_I_FRAME: + lookup_idx = 1; + break; + case IV_P_FRAME: + lookup_idx = 2; + break; + case IV_B_FRAME: + lookup_idx = 3; + break; + case IV_NA_FRAME: + lookup_idx = 4; + break; + default: + break; } - if (ih264e_video_encode_op.s_ive_op.u4_encoded_frame_type + if(ih264e_video_encode_op.s_ive_op.u4_encoded_frame_type != IV_NA_FRAME) { ps_app_ctxt->u4_pics_cnt++; @@ -2380,7 +2376,7 @@ void synchronous_encode(iv_obj_t *ps_enc, app_ctxt_t *ps_app_ctxt) ps_app_ctxt->u4_total_bytes += num_bytes; } - if (ps_app_ctxt->u4_psnr_enable == 0) + if(ps_app_ctxt->u4_psnr_enable == 0) { printf("[%s] PicNum %4d Bytes Generated %6d TimeTaken(microsec): %6d AvgTime: %6d PeakAvgTimeMax: %6d\n", u1_pic_type[lookup_idx], ps_app_ctxt->u4_pics_cnt, @@ -2500,7 +2496,8 @@ void synchronous_encode(iv_obj_t *ps_enc, app_ctxt_t *ps_app_ctxt) } } - /* Pic count is 1 more than actual num frames encoded, because last call is to just get the output */ + /* Pic count is 1 more than actual num frames encoded, because last call is + * to just get the output */ ps_app_ctxt->u4_pics_cnt--; if(ps_app_ctxt->u4_psnr_enable) @@ -2538,29 +2535,12 @@ void synchronous_encode(iv_obj_t *ps_enc, app_ctxt_t *ps_app_ctxt) free_recon(ps_app_ctxt); } -/*****************************************************************************/ -/* */ -/* Function Name : main */ -/* */ -/* Description : Application to demonstrate codec API */ -/* */ -/* */ -/* Inputs : argc - Number of arguments */ -/* argv[] - Arguments */ -/* Globals : */ -/* Processing : Shows how to use create, process, control and delete */ -/* */ -/* Outputs : Codec output in a file */ -/* Returns : */ -/* */ -/* Issues : Assumes both PROFILE_ENABLE to be */ -/* defined for multithread decode-display working */ -/* */ -/* Revision History: */ -/* */ -/* DD MM YYYY Author(s) Changes */ -/* 20 11 2013 100189 Initial Version */ -/*****************************************************************************/ +/** +******************************************************************************* +* @brief Application to demonstrate codec API. Shows how to use create, +* process, control and delete +******************************************************************************* +*/ #ifdef IOS int h264enc_main(char * homedir,char *documentdir, int screen_wd, int screen_ht) #else @@ -2677,7 +2657,6 @@ int main(int argc, char *argv[]) #endif - validate_params(&s_app_ctxt); @@ -2689,42 +2668,44 @@ int main(int argc, char *argv[]) ih264e_num_mem_rec_op_t s_num_mem_rec_op; s_num_mem_rec_ip.s_ive_ip.u4_size = sizeof(ih264e_num_mem_rec_ip_t); - s_num_mem_rec_op.s_ive_op.u4_size = sizeof(ih264e_num_mem_rec_op_t); - s_num_mem_rec_ip.s_ive_ip.e_cmd = IV_CMD_GET_NUM_MEM_REC; - status = ih264e_api_function(0, &s_num_mem_rec_ip, &s_num_mem_rec_op); + s_num_mem_rec_op.s_ive_op.u4_size = sizeof(ih264e_num_mem_rec_op_t); + status = ih264e_api_function(NULL, &s_num_mem_rec_ip, &s_num_mem_rec_op); if(status != IV_SUCCESS) { - sprintf(ac_error, "Get number of memory records failed = 0x%x\n", s_num_mem_rec_op.s_ive_op.u4_error_code); + sprintf(ac_error, "Get number of memory records failed = 0x%x\n", + s_num_mem_rec_op.s_ive_op.u4_error_code); codec_exit(ac_error); } - s_app_ctxt.u4_num_mem_rec = num_mem_recs = s_num_mem_rec_op.s_ive_op.u4_num_mem_rec; + s_app_ctxt.u4_num_mem_rec = s_num_mem_rec_op.s_ive_op.u4_num_mem_rec; + num_mem_recs = s_num_mem_rec_op.s_ive_op.u4_num_mem_rec; } - /* Allocate array to hold memory records */ - s_app_ctxt.ps_mem_rec = (iv_mem_rec_t *) malloc(num_mem_recs * sizeof(iv_mem_rec_t)); + /*************************************************************************/ + /* Allocate and Default initialize MemRecords */ + /*************************************************************************/ + s_app_ctxt.ps_mem_rec = malloc(num_mem_recs * sizeof(iv_mem_rec_t)); if(NULL == s_app_ctxt.ps_mem_rec) { - - sprintf(ac_error, "Unable to allocate memory for hold memory records: Size %d", (WORD32)(num_mem_recs * sizeof(iv_mem_rec_t))); + sprintf(ac_error, + "Unable to allocate memory for hold memory records: Size %d", + (WORD32)(num_mem_recs * sizeof(iv_mem_rec_t))); codec_exit(ac_error); } - + /* Default init memory records */ { - iv_mem_rec_t *ps_mem_rec; - ps_mem_rec = s_app_ctxt.ps_mem_rec; - for(i = 0; i < num_mem_recs; i++) + iv_mem_rec_t *ps_mem_rec = s_app_ctxt.ps_mem_rec; + + for(i = 0; i < num_mem_recs; i++, ps_mem_rec++) { ps_mem_rec->u4_size = sizeof(iv_mem_rec_t); ps_mem_rec->pv_base = NULL; ps_mem_rec->u4_mem_size = 0; ps_mem_rec->u4_mem_alignment = 0; ps_mem_rec->e_mem_type = IV_NA_MEM_TYPE; - - ps_mem_rec++; } } @@ -2736,22 +2717,21 @@ int main(int argc, char *argv[]) ih264e_fill_mem_rec_op_t s_fill_mem_rec_op; s_fill_mem_rec_ip.s_ive_ip.u4_size = sizeof(ih264e_fill_mem_rec_ip_t); - s_fill_mem_rec_op.s_ive_op.u4_size = sizeof(ih264e_fill_mem_rec_op_t); - s_fill_mem_rec_ip.s_ive_ip.e_cmd = IV_CMD_FILL_NUM_MEM_REC; s_fill_mem_rec_ip.s_ive_ip.ps_mem_rec = s_app_ctxt.ps_mem_rec; s_fill_mem_rec_ip.s_ive_ip.u4_num_mem_rec = s_app_ctxt.u4_num_mem_rec; s_fill_mem_rec_ip.s_ive_ip.u4_max_wd = s_app_ctxt.u4_max_wd; s_fill_mem_rec_ip.s_ive_ip.u4_max_ht = s_app_ctxt.u4_max_ht; - s_fill_mem_rec_ip.s_ive_ip.u4_max_level = s_app_ctxt.u4_max_level; - s_fill_mem_rec_ip.s_ive_ip.e_color_format = DEFAULT_INP_COLOR_FMT; s_fill_mem_rec_ip.s_ive_ip.u4_max_ref_cnt = DEFAULT_MAX_REF_FRM; s_fill_mem_rec_ip.s_ive_ip.u4_max_reorder_cnt = DEFAULT_MAX_REORDER_FRM; + s_fill_mem_rec_ip.s_ive_ip.u4_max_level = s_app_ctxt.u4_max_level; + s_fill_mem_rec_ip.s_ive_ip.e_color_format = DEFAULT_INP_COLOR_FMT; s_fill_mem_rec_ip.s_ive_ip.u4_max_srch_rng_x = DEFAULT_MAX_SRCH_RANGE_X; s_fill_mem_rec_ip.s_ive_ip.u4_max_srch_rng_y = DEFAULT_MAX_SRCH_RANGE_Y; - status = ih264e_api_function(0, &s_fill_mem_rec_ip, &s_fill_mem_rec_op); + s_fill_mem_rec_op.s_ive_op.u4_size = sizeof(ih264e_fill_mem_rec_op_t); + status = ih264e_api_function(NULL, &s_fill_mem_rec_ip, &s_fill_mem_rec_op); if(status != IV_SUCCESS) { sprintf(ac_error, "Fill memory records failed = 0x%x\n", @@ -2764,19 +2744,19 @@ int main(int argc, char *argv[]) /* Allocating Memory for Mem Records */ /*************************************************************************/ { - WORD32 total_size; - iv_mem_rec_t *ps_mem_rec; - total_size = 0; + iv_mem_rec_t *ps_mem_rec = s_app_ctxt.ps_mem_rec; + WORD32 total_size = 0; - ps_mem_rec = s_app_ctxt.ps_mem_rec; for(i = 0; i < num_mem_recs; i++) { - ps_mem_rec->pv_base = ih264a_aligned_malloc(ps_mem_rec->u4_mem_alignment, - ps_mem_rec->u4_mem_size); + ps_mem_rec->pv_base = ih264a_aligned_malloc( + ps_mem_rec->u4_mem_alignment, + ps_mem_rec->u4_mem_size); if(ps_mem_rec->pv_base == NULL) { - sprintf(ac_error, "Allocation failure for mem record id %d size %d\n", - i, ps_mem_rec->u4_mem_size); + sprintf(ac_error, + "Allocation failure for mem record id %d size %d\n", i, + ps_mem_rec->u4_mem_size); codec_exit(ac_error); } total_size += ps_mem_rec->u4_mem_size; @@ -2800,8 +2780,6 @@ int main(int argc, char *argv[]) s_app_ctxt.ps_enc = ps_enc; s_init_ip.s_ive_ip.u4_size = sizeof(ih264e_init_ip_t); - s_init_op.s_ive_op.u4_size = sizeof(ih264e_init_op_t); - s_init_ip.s_ive_ip.e_cmd = IV_CMD_INIT; s_init_ip.s_ive_ip.u4_num_mem_rec = s_app_ctxt.u4_num_mem_rec; s_init_ip.s_ive_ip.ps_mem_rec = s_app_ctxt.ps_mem_rec; @@ -2811,29 +2789,31 @@ int main(int argc, char *argv[]) s_init_ip.s_ive_ip.u4_max_reorder_cnt = DEFAULT_MAX_REORDER_FRM; s_init_ip.s_ive_ip.u4_max_level = s_app_ctxt.u4_max_level; s_init_ip.s_ive_ip.e_inp_color_fmt = s_app_ctxt.e_inp_color_fmt; - if(s_app_ctxt.u4_recon_enable || s_app_ctxt.u4_psnr_enable || s_app_ctxt.u4_chksum_enable) + if(s_app_ctxt.u4_recon_enable || s_app_ctxt.u4_psnr_enable + || s_app_ctxt.u4_chksum_enable) { - s_init_ip.s_ive_ip.u4_enable_recon = 1; + s_init_ip.s_ive_ip.u4_enable_recon = 1; } else { - s_init_ip.s_ive_ip.u4_enable_recon = 0; + s_init_ip.s_ive_ip.u4_enable_recon = 0; } - s_init_ip.s_ive_ip.e_recon_color_fmt = s_app_ctxt.e_recon_color_fmt; - s_init_ip.s_ive_ip.e_rc_mode = s_app_ctxt.u4_rc; - s_init_ip.s_ive_ip.u4_max_framerate = s_app_ctxt.u4_max_frame_rate; - s_init_ip.s_ive_ip.u4_max_bitrate = s_app_ctxt.u4_max_bitrate; - s_init_ip.s_ive_ip.u4_num_bframes = s_app_ctxt.u4_num_bframes; - s_init_ip.s_ive_ip.e_content_type = IV_PROGRESSIVE; - s_init_ip.s_ive_ip.u4_max_srch_rng_x = DEFAULT_MAX_SRCH_RANGE_X; - s_init_ip.s_ive_ip.u4_max_srch_rng_y = DEFAULT_MAX_SRCH_RANGE_Y; - s_init_ip.s_ive_ip.e_slice_mode = s_app_ctxt.u4_slice_mode; - s_init_ip.s_ive_ip.u4_slice_param = s_app_ctxt.u4_slice_param; - s_init_ip.s_ive_ip.e_arch = s_app_ctxt.e_arch; - s_init_ip.s_ive_ip.e_soc = s_app_ctxt.e_soc; + s_init_ip.s_ive_ip.e_recon_color_fmt = s_app_ctxt.e_recon_color_fmt; + s_init_ip.s_ive_ip.e_rc_mode = s_app_ctxt.u4_rc; + s_init_ip.s_ive_ip.u4_max_framerate = s_app_ctxt.u4_max_frame_rate; + s_init_ip.s_ive_ip.u4_max_bitrate = s_app_ctxt.u4_max_bitrate; + s_init_ip.s_ive_ip.u4_num_bframes = s_app_ctxt.u4_num_bframes; + s_init_ip.s_ive_ip.e_content_type = IV_PROGRESSIVE; + s_init_ip.s_ive_ip.u4_max_srch_rng_x = DEFAULT_MAX_SRCH_RANGE_X; + s_init_ip.s_ive_ip.u4_max_srch_rng_y = DEFAULT_MAX_SRCH_RANGE_Y; + s_init_ip.s_ive_ip.e_slice_mode = s_app_ctxt.u4_slice_mode; + s_init_ip.s_ive_ip.u4_slice_param = s_app_ctxt.u4_slice_param; + s_init_ip.s_ive_ip.e_arch = s_app_ctxt.e_arch; + s_init_ip.s_ive_ip.e_soc = s_app_ctxt.e_soc; - status = ih264e_api_function(ps_enc, &s_init_ip, &s_init_op); + s_init_op.s_ive_op.u4_size = sizeof(ih264e_init_op_t); + status = ih264e_api_function(ps_enc, &s_init_ip, &s_init_op); if(status != IV_SUCCESS) { sprintf(ac_error, "Init memory records failed = 0x%x\n", @@ -2848,24 +2828,24 @@ int main(int argc, char *argv[]) { ih264e_ctl_set_num_cores_ip_t s_ctl_set_num_cores_ip; ih264e_ctl_set_num_cores_op_t s_ctl_set_num_cores_op; + + s_ctl_set_num_cores_ip.s_ive_ip.u4_size = sizeof(ih264e_ctl_set_num_cores_ip_t); s_ctl_set_num_cores_ip.s_ive_ip.e_cmd = IVE_CMD_VIDEO_CTL; s_ctl_set_num_cores_ip.s_ive_ip.e_sub_cmd = IVE_CMD_CTL_SET_NUM_CORES; s_ctl_set_num_cores_ip.s_ive_ip.u4_num_cores = s_app_ctxt.u4_num_cores; s_ctl_set_num_cores_ip.s_ive_ip.u4_timestamp_high = 0; s_ctl_set_num_cores_ip.s_ive_ip.u4_timestamp_low = 0; - s_ctl_set_num_cores_ip.s_ive_ip.u4_size = sizeof(ih264e_ctl_set_num_cores_ip_t); s_ctl_set_num_cores_op.s_ive_op.u4_size = sizeof(ih264e_ctl_set_num_cores_op_t); - status = ih264e_api_function(ps_enc, (void *) &s_ctl_set_num_cores_ip, - (void *) &s_ctl_set_num_cores_op); + status = ih264e_api_function(ps_enc, (void *)&s_ctl_set_num_cores_ip, + (void *)&s_ctl_set_num_cores_op); if(status != IV_SUCCESS) { sprintf(ac_error, "Unable to set processor params = 0x%x\n", s_ctl_set_num_cores_op.s_ive_op.u4_error_code); codec_exit(ac_error); } - } /*************************************************************************/ @@ -2875,15 +2855,18 @@ int main(int argc, char *argv[]) ih264e_ctl_getversioninfo_ip_t s_ctl_set_getversioninfo_ip; ih264e_ctl_getversioninfo_op_t s_ctl_set_getversioninfo_op; CHAR ac_version_string[STRLENGTH]; + + s_ctl_set_getversioninfo_ip.s_ive_ip.u4_size = sizeof(ih264e_ctl_getversioninfo_ip_t); s_ctl_set_getversioninfo_ip.s_ive_ip.e_cmd = IVE_CMD_VIDEO_CTL; s_ctl_set_getversioninfo_ip.s_ive_ip.e_sub_cmd = IVE_CMD_CTL_GETVERSION; s_ctl_set_getversioninfo_ip.s_ive_ip.pu1_version = (UWORD8 *)ac_version_string; s_ctl_set_getversioninfo_ip.s_ive_ip.u4_version_bufsize = sizeof(ac_version_string); - s_ctl_set_getversioninfo_ip.s_ive_ip.u4_size = sizeof(ih264e_ctl_getversioninfo_ip_t); + s_ctl_set_getversioninfo_op.s_ive_op.u4_size = sizeof(ih264e_ctl_getversioninfo_op_t); - status = ih264e_api_function(ps_enc, (void *) &s_ctl_set_getversioninfo_ip, - (void *) &s_ctl_set_getversioninfo_op); + status = ih264e_api_function(ps_enc, + (void *)&s_ctl_set_getversioninfo_ip, + (void *)&s_ctl_set_getversioninfo_op); if(status != IV_SUCCESS) { sprintf(ac_error, "Unable to get codec version = 0x%x\n", @@ -2901,17 +2884,17 @@ int main(int argc, char *argv[]) ih264e_ctl_getbufinfo_op_t s_get_buf_info_op; s_get_buf_info_ip.s_ive_ip.u4_size = sizeof(ih264e_ctl_getbufinfo_ip_t); - s_get_buf_info_op.s_ive_op.u4_size = sizeof(ih264e_ctl_getbufinfo_op_t); - s_get_buf_info_ip.s_ive_ip.e_cmd = IVE_CMD_VIDEO_CTL; s_get_buf_info_ip.s_ive_ip.e_sub_cmd = IVE_CMD_CTL_GETBUFINFO; s_get_buf_info_ip.s_ive_ip.u4_max_ht = s_app_ctxt.u4_max_ht; s_get_buf_info_ip.s_ive_ip.u4_max_wd = s_app_ctxt.u4_max_wd; s_get_buf_info_ip.s_ive_ip.e_inp_color_fmt = s_app_ctxt.e_inp_color_fmt; - status = ih264e_api_function(ps_enc, &s_get_buf_info_ip, &s_get_buf_info_op); + s_get_buf_info_op.s_ive_op.u4_size = sizeof(ih264e_ctl_getbufinfo_op_t); - if (status != IV_SUCCESS) + status = ih264e_api_function(ps_enc, &s_get_buf_info_ip, + &s_get_buf_info_op); + if(status != IV_SUCCESS) { sprintf(ac_error, "Unable to get I/O buffer requirements = 0x%x\n", s_get_buf_info_op.s_ive_op.u4_error_code); @@ -2920,70 +2903,69 @@ int main(int argc, char *argv[]) s_app_ctxt.s_get_buf_info_op = s_get_buf_info_op; } - /*****************************************************************************/ - /* Add the following initializations based on the parameters in context */ - /*****************************************************************************/ + /**************************************************************************/ + /* Add the following initializations based on the parameters in context */ + /**************************************************************************/ - - /*****************************************************************************/ - /* Video control Set Frame dimensions */ - /*****************************************************************************/ + /**************************************************************************/ + /* Video control Set Frame dimensions */ + /**************************************************************************/ s_app_ctxt.u4_strd = s_app_ctxt.u4_wd; set_dimensions(&s_app_ctxt, 0, 0); - /*****************************************************************************/ - /* Video control Set Frame rates */ - /*****************************************************************************/ + /**************************************************************************/ + /* Video control Set Frame rates */ + /**************************************************************************/ set_frame_rate(&s_app_ctxt, 0, 0); - /*****************************************************************************/ - /* Video control Set IPE Params */ - /*****************************************************************************/ + /**************************************************************************/ + /* Video control Set IPE Params */ + /**************************************************************************/ set_ipe_params(&s_app_ctxt, 0, 0); - /*****************************************************************************/ - /* Video control Set Bitrate */ - /*****************************************************************************/ + /**************************************************************************/ + /* Video control Set Bitrate */ + /**************************************************************************/ set_bit_rate(&s_app_ctxt, 0, 0); - /*****************************************************************************/ - /* Video control Set QP */ - /*****************************************************************************/ - set_qp(&s_app_ctxt,0,0); - - /*****************************************************************************/ - /* Video control Set AIR params */ - /*****************************************************************************/ - set_air_params(&s_app_ctxt,0,0); - - /*****************************************************************************/ - /* Video control Set VBV params */ - /*****************************************************************************/ - set_vbv_params(&s_app_ctxt,0,0); - - /*****************************************************************************/ - /* Video control Set Motion estimation params */ - /*****************************************************************************/ - set_me_params(&s_app_ctxt,0,0); - - /*****************************************************************************/ - /* Video control Set GOP params */ - /*****************************************************************************/ + /**************************************************************************/ + /* Video control Set QP */ + /**************************************************************************/ + set_qp(&s_app_ctxt, 0, 0); + + /**************************************************************************/ + /* Video control Set AIR params */ + /**************************************************************************/ + set_air_params(&s_app_ctxt, 0, 0); + + /**************************************************************************/ + /* Video control Set VBV params */ + /**************************************************************************/ + set_vbv_params(&s_app_ctxt, 0, 0); + + /**************************************************************************/ + /* Video control Set Motion estimation params */ + /**************************************************************************/ + set_me_params(&s_app_ctxt, 0, 0); + + /**************************************************************************/ + /* Video control Set GOP params */ + /**************************************************************************/ set_gop_params(&s_app_ctxt, 0, 0); - /*****************************************************************************/ - /* Video control Set Deblock params */ - /*****************************************************************************/ + /**************************************************************************/ + /* Video control Set Deblock params */ + /**************************************************************************/ set_deblock_params(&s_app_ctxt, 0, 0); - /*****************************************************************************/ - /* Video control Set Profile params */ - /*****************************************************************************/ + /**************************************************************************/ + /* Video control Set Profile params */ + /**************************************************************************/ set_profile_params(&s_app_ctxt, 0, 0); - /*****************************************************************************/ - /* Video usability information */ - /*****************************************************************************/ + /**************************************************************************/ + /* Video usability information */ + /**************************************************************************/ set_vui_params(&s_app_ctxt); #ifdef IOS @@ -3008,11 +2990,13 @@ int main(int argc, char *argv[]) #endif /*************************************************************************/ - /* begin encoding */ + /* Encoding */ /*************************************************************************/ - synchronous_encode(ps_enc, &s_app_ctxt); + /*************************************************************************/ + /* Print summary */ + /*************************************************************************/ { DOUBLE bytes_per_frame; DOUBLE bytes_per_second; @@ -3049,18 +3033,15 @@ int main(int argc, char *argv[]) { ih264e_retrieve_mem_rec_ip_t s_retrieve_mem_ip; ih264e_retrieve_mem_rec_op_t s_retrieve_mem_op; - iv_mem_rec_t *ps_mem_rec; - s_retrieve_mem_ip.s_ive_ip.u4_size = - sizeof(ih264e_retrieve_mem_rec_ip_t); - s_retrieve_mem_op.s_ive_op.u4_size = - sizeof(ih264e_retrieve_mem_rec_op_t); + iv_mem_rec_t *ps_mem_rec = s_app_ctxt.ps_mem_rec; + s_retrieve_mem_ip.s_ive_ip.u4_size = sizeof(ih264e_retrieve_mem_rec_ip_t); s_retrieve_mem_ip.s_ive_ip.e_cmd = IV_CMD_RETRIEVE_MEMREC; s_retrieve_mem_ip.s_ive_ip.ps_mem_rec = s_app_ctxt.ps_mem_rec; - status = ih264e_api_function(ps_enc, &s_retrieve_mem_ip, - &s_retrieve_mem_op); + s_retrieve_mem_op.s_ive_op.u4_size = sizeof(ih264e_retrieve_mem_rec_op_t); + status = ih264e_api_function(ps_enc, &s_retrieve_mem_ip, &s_retrieve_mem_op); if(status != IV_SUCCESS) { sprintf(ac_error, "Unable to retrieve memory records = 0x%x\n", @@ -3069,15 +3050,12 @@ int main(int argc, char *argv[]) } /* Free memory records */ - ps_mem_rec = s_app_ctxt.ps_mem_rec; for(i = 0; i < num_mem_recs; i++) { ih264a_aligned_free(ps_mem_rec->pv_base); ps_mem_rec++; } - free(s_app_ctxt.ps_mem_rec); - } return 0; diff --git a/examples/avcenc/output.c b/examples/avcenc/output.c index 8d164002..0702afd9 100644 --- a/examples/avcenc/output.c +++ b/examples/avcenc/output.c @@ -18,20 +18,35 @@ * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore */ +/** +******************************************************************************* +* @file +* output.c +* +* @brief +* Contains functions necessary for managing output buffers +* +* @author +* ittiam +* +* @remarks +* none +* +******************************************************************************* +*/ + /*****************************************************************************/ /* File Includes */ /*****************************************************************************/ /* System include files */ - #include #include #include #include -/* User include files */ +/* User include files */ #include "ih264_typedefs.h" -#include "ih264_defs.h" #include "iv2.h" #include "ive2.h" #include "ih264e.h" @@ -41,12 +56,22 @@ /* Constant Macros */ /*****************************************************************************/ #define PEAK_WINDOW_SIZE 8 + + /*****************************************************************************/ /* Macros */ /*****************************************************************************/ + + /*****************************************************************************/ -/* Function Declarations */ +/* Function Definitions */ /*****************************************************************************/ + +/** +************************************************************************** +* @brief Write bitstream buffers to a file +************************************************************************** +*/ IV_STATUS_T write_output(FILE *fp, UWORD8 *pu1_buf, WORD32 num_bytes) { WORD32 bytes; @@ -59,19 +84,27 @@ IV_STATUS_T write_output(FILE *fp, UWORD8 *pu1_buf, WORD32 num_bytes) return IV_SUCCESS; } +/** +************************************************************************** +* @brief allocate bitstream buffers +************************************************************************** +*/ void allocate_output(app_ctxt_t *ps_app_ctxt) { - WORD32 num_bufs; WORD32 i; UWORD8 *pu1_buf; WORD32 buf_size; - num_bufs = MAX(DEFAULT_NUM_OUTPUT_BUFS, ps_app_ctxt->s_get_buf_info_op.s_ive_op.u4_min_out_bufs); + + num_bufs = MAX(DEFAULT_NUM_OUTPUT_BUFS, + ps_app_ctxt->s_get_buf_info_op.s_ive_op.u4_min_out_bufs); num_bufs = MIN(DEFAULT_MAX_OUTPUT_BUFS, num_bufs); buf_size = ps_app_ctxt->s_get_buf_info_op.s_ive_op.au4_min_out_buf_size[0]; + /* Memset the output buffer array to set is_free to 0 */ - memset(ps_app_ctxt->as_output_buf, 0, sizeof(output_buf_t) * DEFAULT_MAX_OUTPUT_BUFS); + memset(ps_app_ctxt->as_output_buf, 0, + sizeof(output_buf_t) * DEFAULT_MAX_OUTPUT_BUFS); for(i = 0; i < num_bufs; i++) { @@ -79,31 +112,33 @@ void allocate_output(app_ctxt_t *ps_app_ctxt) if(NULL == pu1_buf) { CHAR ac_error[STRLENGTH]; - sprintf(ac_error, "Allocation failed for output buffer of size %d\n", + sprintf(ac_error, + "Allocation failed for output buffer of size %d\n", buf_size); codec_exit(ac_error); } ps_app_ctxt->as_output_buf[i].pu1_buf = pu1_buf; ps_app_ctxt->as_output_buf[i].u4_buf_size = buf_size; ps_app_ctxt->as_output_buf[i].u4_is_free = 1; - } - return; } +/** +************************************************************************** +* @brief free bitstream buffers +************************************************************************** +*/ void free_output(app_ctxt_t *ps_app_ctxt) { - WORD32 num_bufs; WORD32 i; - num_bufs = MAX(DEFAULT_NUM_OUTPUT_BUFS, ps_app_ctxt->s_get_buf_info_op.s_ive_op.u4_min_out_bufs); + num_bufs = MAX(DEFAULT_NUM_OUTPUT_BUFS, + ps_app_ctxt->s_get_buf_info_op.s_ive_op.u4_min_out_bufs); num_bufs = MIN(DEFAULT_MAX_OUTPUT_BUFS, num_bufs); for(i = 0; i < num_bufs; i++) { - ih264a_aligned_free(ps_app_ctxt->as_output_buf[i].pu1_buf); } - return; } diff --git a/examples/avcenc/psnr.c b/examples/avcenc/psnr.c index 87a03b0d..97623745 100644 --- a/examples/avcenc/psnr.c +++ b/examples/avcenc/psnr.c @@ -18,6 +18,23 @@ * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore */ +/** +******************************************************************************* +* @file +* psnr.c +* +* @brief +* Contains functions necessary for computing psnr +* +* @author +* ittiam +* +* @remarks +* none +* +******************************************************************************* +*/ + /*****************************************************************************/ /* File Includes */ /*****************************************************************************/ @@ -29,71 +46,38 @@ /* User include files */ #include "ih264_typedefs.h" -#include "ih264_defs.h" #include "iv2.h" #include "ive2.h" #include "ih264e.h" #include "app.h" #include "psnr.h" + /*****************************************************************************/ -/* */ -/* Function Name : init_psnr */ -/* */ -/* Description : Initialize PSNR for the Y, U, V component */ -/* */ -/* Inputs : */ -/* */ -/* Globals : */ -/* */ -/* Processing : */ -/* */ -/* Outputs : */ -/* */ -/* Returns : */ -/* */ -/* Issues : */ -/* */ -/* Revision History: */ -/* */ -/* DD MM YYYY Author(s) Changes (Describe the changes made) */ -/* 28 12 2005 Ittiam Draft */ -/* */ +/* Function Definition */ /*****************************************************************************/ + +/** +************************************************************************** +* @brief Initialize PSNR for the Y, U, V component +************************************************************************** +*/ void init_psnr(app_ctxt_t *ps_app_ctxt) { - ps_app_ctxt->adbl_psnr[0] = 0; - ps_app_ctxt->adbl_psnr[1] = 0; - ps_app_ctxt->adbl_psnr[2] = 0; - ps_app_ctxt->u4_psnr_cnt = 0; + ps_app_ctxt->adbl_psnr[0] = 0; + ps_app_ctxt->adbl_psnr[1] = 0; + ps_app_ctxt->adbl_psnr[2] = 0; + ps_app_ctxt->u4_psnr_cnt = 0; } - -/*****************************************************************************/ -/* */ -/* Function Name : compute_psnr */ -/* */ -/* Description : Computes the PSNR for the Y, U, V component */ -/* */ -/* Inputs : */ -/* */ -/* Globals : */ -/* */ -/* Processing : */ -/* */ -/* Outputs : */ -/* */ -/* Returns : */ -/* */ -/* Issues : */ -/* */ -/* Revision History: */ -/* */ -/* DD MM YYYY Author(s) Changes (Describe the changes made) */ -/* 28 12 2005 Ittiam Draft */ -/* */ -/*****************************************************************************/ -void compute_psnr(app_ctxt_t *ps_app_ctxt, iv_raw_buf_t *ps_buf1, iv_raw_buf_t *ps_buf2) +/** +************************************************************************** +* @brief Computes PSNR for the Y, U, V component +************************************************************************** +*/ +void compute_psnr(app_ctxt_t *ps_app_ctxt, + iv_raw_buf_t *ps_buf1, + iv_raw_buf_t *ps_buf2) { WORD32 i, j; WORD32 comp; @@ -145,7 +129,7 @@ void compute_psnr(app_ctxt_t *ps_app_ctxt, iv_raw_buf_t *ps_buf1, iv_raw_buf_t * break; } } - if ((IV_YUV_420SP_UV == ps_buf2->e_color_fmt) + if((IV_YUV_420SP_UV == ps_buf2->e_color_fmt) || (IV_YUV_420SP_VU == ps_buf2->e_color_fmt)) { switch(comp) @@ -159,8 +143,8 @@ void compute_psnr(app_ctxt_t *ps_app_ctxt, iv_raw_buf_t *ps_buf1, iv_raw_buf_t * else pu1_buf2 = (UWORD8 *)ps_buf2->apv_bufs[1] + 1; incr2 = 2; - wd = ps_buf2->au4_wd[0] >> 1; - ht = ps_buf2->au4_ht[0] >> 1; + wd = ps_buf1->au4_wd[0] >> 1; + ht = ps_buf1->au4_ht[0] >> 1; break; case 2: @@ -169,8 +153,8 @@ void compute_psnr(app_ctxt_t *ps_app_ctxt, iv_raw_buf_t *ps_buf1, iv_raw_buf_t * else pu1_buf2 = ps_buf2->apv_bufs[1]; incr2 = 2; - wd = ps_buf2->au4_wd[0] >> 1; - ht = ps_buf2->au4_ht[0] >> 1; + wd = ps_buf1->au4_wd[0] >> 1; + ht = ps_buf1->au4_ht[0] >> 1; strd2 = ps_buf2->au4_strd[1] - ps_buf2->au4_wd[1]; break; @@ -212,43 +196,25 @@ void compute_psnr(app_ctxt_t *ps_app_ctxt, iv_raw_buf_t *ps_buf1, iv_raw_buf_t * break; } printf("%2.2f\t", df_psnr[comp]); - } ps_app_ctxt->u4_psnr_cnt++; } - -/*****************************************************************************/ -/* */ -/* Function Name : print_average_psnr */ -/* */ -/* Description : Computes the average PSNR for the Y, U, V component */ -/* */ -/* Inputs : */ -/* */ -/* Globals : */ -/* */ -/* Processing : */ -/* */ -/* Outputs : */ -/* */ -/* Returns : */ -/* */ -/* Issues : */ -/* */ -/* Revision History: */ -/* */ -/* DD MM YYYY Author(s) Changes (Describe the changes made) */ -/* 28 12 2005 Ittiam Draft */ -/* */ -/*****************************************************************************/ +/** +************************************************************************** +* @brief Prints PSNR for the Y, U, V component +************************************************************************** +*/ void print_average_psnr(app_ctxt_t *ps_app_ctxt) { printf("\n"); - printf("Avg PSNR Y : %-2.2f\n", (ps_app_ctxt->adbl_psnr[0] / ps_app_ctxt->u4_psnr_cnt)); - printf("Avg PSNR U : %-2.2f\n", (ps_app_ctxt->adbl_psnr[1] / ps_app_ctxt->u4_psnr_cnt)); - printf("Avg PSNR V : %-2.2f\n", (ps_app_ctxt->adbl_psnr[2] / ps_app_ctxt->u4_psnr_cnt)); + printf("Avg PSNR Y : %-2.2f\n", + (ps_app_ctxt->adbl_psnr[0] / ps_app_ctxt->u4_psnr_cnt)); + printf("Avg PSNR U : %-2.2f\n", + (ps_app_ctxt->adbl_psnr[1] / ps_app_ctxt->u4_psnr_cnt)); + printf("Avg PSNR V : %-2.2f\n", + (ps_app_ctxt->adbl_psnr[2] / ps_app_ctxt->u4_psnr_cnt)); } diff --git a/examples/avcenc/psnr.h b/examples/avcenc/psnr.h index fd388cfa..f91e0bb2 100644 --- a/examples/avcenc/psnr.h +++ b/examples/avcenc/psnr.h @@ -17,24 +17,26 @@ ***************************************************************************** * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore */ -/****************************************************************************/ -/* */ -/* File Name : psnr.h */ -/* */ -/* Description : Contains functions for psnr computation */ -/* */ -/* List of Functions : ih264e_api_function */ -/* compute_psnr */ -/* print_average_psnr */ -/* Issues / Problems : */ -/* */ -/* Revision History : */ -/* */ -/* DD MM YYYY Author(s) Changes (Describe the changes) */ -/* */ -/****************************************************************************/ -#ifndef PSNR_H -#define PSNR_H + +/** +******************************************************************************* +* @file +* psnr.h +* +* @brief +* Contains declarations of functions for psnr computation +* +* @author +* ittiam +* +* @remarks +* none +* +******************************************************************************* +*/ + +#ifndef _PSNR_H_ +#define _PSNR_H_ /*****************************************************************************/ /* Function Declarations */ @@ -47,16 +49,6 @@ void compute_psnr(app_ctxt_t *ps_app_ctxt, void print_average_psnr(app_ctxt_t *ps_app_ctxt); -#if COMPUTE_PSNR - -#define GET_AVERAGE_PSNR_Y(print) print_average_psnr(print) - -#else /* COMPUTE_PSNR */ - -#define GET_AVERAGE_PSNR_Y(print) 0 - -#endif /* COMPUTE_PSNR */ - -#endif +#endif /* _PSNR_H_ */ diff --git a/examples/avcenc/recon.c b/examples/avcenc/recon.c index 89cfe402..20bab6cc 100644 --- a/examples/avcenc/recon.c +++ b/examples/avcenc/recon.c @@ -18,20 +18,35 @@ * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore */ +/** +******************************************************************************* +* @file +* recon.c +* +* @brief +* Contains functions necessary for managing recon buffers +* +* @author +* ittiam +* +* @remarks +* none +* +******************************************************************************* +*/ + /*****************************************************************************/ /* File Includes */ /*****************************************************************************/ /* System include files */ - #include #include #include #include -/* User include files */ +/* User include files */ #include "ih264_typedefs.h" -#include "ih264_defs.h" #include "iv2.h" #include "ive2.h" #include "ih264e.h" @@ -48,62 +63,61 @@ /*****************************************************************************/ -/* Function Declarations */ +/* Function Definitions */ /*****************************************************************************/ +/** +************************************************************************** +* @brief Write recon buffers to a file +************************************************************************** +*/ IV_STATUS_T write_recon(FILE *fp, iv_raw_buf_t *ps_raw_buf) { - WORD32 bytes; - WORD32 wd, ht; - UWORD8 *pu1_buf; - WORD32 i; - WORD32 comp; - WORD32 num_comp; + WORD32 num_comp = 2; + WORD32 comp_idx; - num_comp = 2; if(IV_YUV_420P == ps_raw_buf->e_color_fmt) num_comp = 3; - for(comp = 0; comp < num_comp; comp++) + for(comp_idx = 0; comp_idx < num_comp; comp_idx++) { - wd = ps_raw_buf->au4_wd[comp]; - ht = ps_raw_buf->au4_ht[comp]; - pu1_buf = ps_raw_buf->apv_bufs[comp]; + WORD32 wd = ps_raw_buf->au4_wd[comp_idx]; + WORD32 ht = ps_raw_buf->au4_ht[comp_idx]; + UWORD8 *pu1_buf = ps_raw_buf->apv_bufs[comp_idx]; + WORD32 i; + for(i = 0; i < ht; i++) { - bytes = fwrite(pu1_buf, sizeof(UWORD8), wd, fp); + WORD32 bytes = fwrite(pu1_buf, sizeof(UWORD8), wd, fp); if(bytes != wd) { - return(IV_FAIL); + return (IV_FAIL); } pu1_buf += wd; } } - fflush(fp); return IV_SUCCESS; } + +/** +************************************************************************** +* @brief Allocate space for recon buffers +************************************************************************** +*/ void allocate_recon(app_ctxt_t *ps_app_ctxt) { - - WORD32 num_bufs; - WORD32 pic_size; - WORD32 luma_size; - WORD32 chroma_size; + WORD32 num_bufs = DEFAULT_NUM_RECON_BUFS; + /* Size of buffer for YUV420 */ + WORD32 luma_size = ps_app_ctxt->u4_max_wd * ps_app_ctxt->u4_max_ht; + WORD32 chroma_size = (luma_size) / 4; + WORD32 pic_size = luma_size + chroma_size * 2; WORD32 i; - UWORD8 *pu1_buf; - - num_bufs = DEFAULT_NUM_RECON_BUFS; - - /* Size of buffer for YUV420/420SP */ - luma_size = ps_app_ctxt->u4_max_wd * ps_app_ctxt->u4_max_ht; - chroma_size = (luma_size) / 4; - pic_size = luma_size + chroma_size * 2; - for(i = 0; i < num_bufs; i++) { - pu1_buf = (UWORD8 *)ih264a_aligned_malloc(16, pic_size); + UWORD8 *pu1_buf = (UWORD8 *)ih264a_aligned_malloc(16, pic_size); + if(NULL == pu1_buf) { CHAR ac_error[STRLENGTH]; @@ -115,10 +129,10 @@ void allocate_recon(app_ctxt_t *ps_app_ctxt) ps_app_ctxt->as_recon_buf[i].u4_buf_size = pic_size; ps_app_ctxt->as_recon_buf[i].u4_is_free = 1; } - if(ps_app_ctxt->u4_psnr_enable) { - pu1_buf = (UWORD8 *)ih264a_aligned_malloc(16, pic_size); + UWORD8 *pu1_buf = (UWORD8 *)ih264a_aligned_malloc(16, pic_size); + if(NULL == pu1_buf) { CHAR ac_error[STRLENGTH]; @@ -129,81 +143,80 @@ void allocate_recon(app_ctxt_t *ps_app_ctxt) ps_app_ctxt->pu1_psnr_buf = pu1_buf; ps_app_ctxt->u4_psnr_buf_size = pic_size; } - return; } +/** +************************************************************************** +* @brief free recon buffers +************************************************************************** +*/ void free_recon(app_ctxt_t *ps_app_ctxt) { - - WORD32 num_bufs; + WORD32 num_bufs = DEFAULT_NUM_RECON_BUFS; WORD32 i; - num_bufs = DEFAULT_NUM_RECON_BUFS; - for(i = 0; i < num_bufs; i++) { ih264a_aligned_free(ps_app_ctxt->as_recon_buf[i].pu1_buf); } - if(ps_app_ctxt->u4_psnr_enable) { ih264a_aligned_free(ps_app_ctxt->pu1_psnr_buf); - } - return; } - - -void init_raw_buf_descr(app_ctxt_t *ps_app_ctxt, iv_raw_buf_t *ps_raw_buf, UWORD8 *pu1_buf, IV_COLOR_FORMAT_T e_color_fmt) +/** +************************************************************************** +* @brief initialize raw buffer descriptor +* All the pointers and dimensions are initialized here to support change in +* resolution from the application +************************************************************************** +*/ +void init_raw_buf_descr(app_ctxt_t *ps_app_ctxt, + iv_raw_buf_t *ps_raw_buf, + UWORD8 *pu1_buf, + IV_COLOR_FORMAT_T e_color_fmt) { - WORD32 luma_size; - WORD32 chroma_size; + WORD32 luma_size = ps_app_ctxt->u4_max_wd * ps_app_ctxt->u4_max_ht; + WORD32 chroma_size = (luma_size) / 4; - /* All the pointers and dimensions are initialized here - * to support change in resolution from the application */ - luma_size = ps_app_ctxt->u4_max_wd * ps_app_ctxt->u4_max_ht; - chroma_size = (luma_size) / 4; + ps_raw_buf->u4_size = sizeof(iv_raw_buf_t); + ps_raw_buf->e_color_fmt = e_color_fmt; ps_raw_buf->apv_bufs[0] = pu1_buf; pu1_buf += luma_size; - ps_raw_buf->apv_bufs[1] = pu1_buf; pu1_buf += chroma_size; - ps_raw_buf->apv_bufs[2] = NULL; if(IV_YUV_420P == e_color_fmt) { ps_raw_buf->apv_bufs[2] = pu1_buf; } - ps_raw_buf->e_color_fmt = e_color_fmt; - ps_raw_buf->au4_wd[0] = ps_app_ctxt->u4_wd; - ps_raw_buf->au4_ht[0] = ps_app_ctxt->u4_ht; - ps_raw_buf->au4_strd[0] = ps_app_ctxt->u4_wd; - + ps_raw_buf->au4_wd[0] = ps_app_ctxt->u4_wd; + ps_raw_buf->au4_ht[0] = ps_app_ctxt->u4_ht; + ps_raw_buf->au4_strd[0] = ps_app_ctxt->u4_wd; /* Initialize for 420SP */ { - ps_raw_buf->au4_wd[1] = ps_app_ctxt->u4_wd; - ps_raw_buf->au4_wd[2] = 0; + ps_raw_buf->au4_wd[1] = ps_app_ctxt->u4_wd; + ps_raw_buf->au4_wd[2] = 0; - ps_raw_buf->au4_ht[1] = ps_app_ctxt->u4_ht / 2; - ps_raw_buf->au4_ht[2] = 0; + ps_raw_buf->au4_ht[1] = ps_app_ctxt->u4_ht / 2; + ps_raw_buf->au4_ht[2] = 0; - ps_raw_buf->au4_strd[1] = ps_app_ctxt->u4_wd; - ps_raw_buf->au4_strd[2] = 0; + ps_raw_buf->au4_strd[1] = ps_app_ctxt->u4_wd; + ps_raw_buf->au4_strd[2] = 0; } - if(IV_YUV_420P == e_color_fmt) { - ps_raw_buf->au4_wd[1] = ps_app_ctxt->u4_wd / 2; - ps_raw_buf->au4_wd[2] = ps_app_ctxt->u4_wd / 2; + ps_raw_buf->au4_wd[1] = ps_app_ctxt->u4_wd / 2; + ps_raw_buf->au4_wd[2] = ps_app_ctxt->u4_wd / 2; - ps_raw_buf->au4_ht[1] = ps_app_ctxt->u4_ht / 2; - ps_raw_buf->au4_ht[2] = ps_app_ctxt->u4_ht / 2; + ps_raw_buf->au4_ht[1] = ps_app_ctxt->u4_ht / 2; + ps_raw_buf->au4_ht[2] = ps_app_ctxt->u4_ht / 2; - ps_raw_buf->au4_strd[1] = ps_app_ctxt->u4_wd / 2; - ps_raw_buf->au4_strd[2] = ps_app_ctxt->u4_wd / 2; + ps_raw_buf->au4_strd[1] = ps_app_ctxt->u4_wd / 2; + ps_raw_buf->au4_strd[2] = ps_app_ctxt->u4_wd / 2; } /* If stride is not initialized, then use width as stride */ if(0 == ps_raw_buf->au4_strd[0]) @@ -212,9 +225,5 @@ void init_raw_buf_descr(app_ctxt_t *ps_app_ctxt, iv_raw_buf_t *ps_raw_buf, UWORD ps_raw_buf->au4_strd[1] = ps_raw_buf->au4_wd[1]; ps_raw_buf->au4_strd[2] = ps_raw_buf->au4_wd[2]; } - - ps_raw_buf->u4_size = sizeof(iv_raw_buf_t); - return; } -