app.h revision 8d3d303c7942ced6a987a52db8977d768dc3605f
1/****************************************************************************** 2 * 3 * Copyright (C) 2015 The Android Open Source Project 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at: 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 * 17 ***************************************************************************** 18 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore 19*/ 20/*****************************************************************************/ 21/* */ 22/* File Name : app.h */ 23/* */ 24/* Description : This file contains all the necessary structure and */ 25/* enumeration definitions needed for the Application */ 26/* */ 27/* List of Functions : */ 28/* */ 29/* Issues / Problems : None */ 30/* */ 31/* Revision History : */ 32/* */ 33/* DD MM YYYY Author(s) Changes (Describe the changes made) */ 34/* 26 08 2010 Ittiam Draft */ 35/* */ 36/*****************************************************************************/ 37 38#ifndef _APP_H_ 39#define _APP_H_ 40 41#include "iv2.h" 42#include "ive2.h" 43#ifdef WINDOWS_TIMER 44#include <windows.h> 45#endif 46/*****************************************************************************/ 47/* Function Macros */ 48/*****************************************************************************/ 49#define MAX(a, b) ((a) > (b))? (a) : (b) 50#define MIN(a, b) ((a) < (b))? (a) : (b) 51 52#define ALIGN16(x) ((((x) + 15) >> 4) << 4) 53 54/*****************************************************************************/ 55/* Constant Macros */ 56/*****************************************************************************/ 57 58#define DEFAULT_NUM_INPUT_BUFS 1 59#define DEFAULT_MAX_INPUT_BUFS 32 60 61#define DEFAULT_NUM_OUTPUT_BUFS 1 62#define DEFAULT_MAX_OUTPUT_BUFS 32 63 64#define DEFAULT_NUM_RECON_BUFS 1 65#define DEFAULT_MAX_RECON_BUFS DEFAULT_NUM_RECON_BUFS 66 67 68#define LEN_STATUS_BUFFER (10 * 1024) 69#define MAX_VBV_BUFF_SIZE (120 * 16384) 70#define MAX_NUM_IO_BUFS 3 71 72#define DEFAULT_MAX_REF_FRM 1 73#define DEFAULT_MAX_REORDER_FRM 0 74#define DEFAULT_QP_MIN 0 75#define DEFAULT_QP_MAX 51 76#define DEFAULT_MAX_BITRATE 20000000 77#define DEFAULT_MAX_SRCH_RANGE_X 256 78#define DEFAULT_MAX_SRCH_RANGE_Y 256 79#define DEFAULT_MAX_FRAMERATE 120000 80#define DEFAULT_NUM_CORES 1 81#define DEFAULT_NUM_CORES_PRE_ENC 0 82#define DEFAULT_FPS 30 83#define DEFAULT_ENC_SPEED 100 84 85#define DEFAULT_MEM_REC_CNT 0 86#define DEFAULT_RECON_ENABLE 0 87#define DEFAULT_CHKSUM_ENABLE 0 88#define DEFAULT_START_FRM 0 89#define DEFAULT_NUM_FRMS 0xFFFFFFFF 90#define DEFAULT_INP_COLOR_FMT IV_YUV_420SP_UV 91#define DEFAULT_RECON_COLOR_FMT IV_YUV_420P 92#define DEFAULT_LOOPBACK 0 93#define DEFAULT_SRC_FRAME_RATE 30 94#define DEFAULT_TGT_FRAME_RATE 30 95#define DEFAULT_MAX_WD 1920 96#define DEFAULT_MAX_HT 1920 97#define DEFAULT_MAX_LEVEL 50 98#define DEFAULT_STRIDE 0 99#define DEFAULT_WD 0 100#define DEFAULT_HT 0 101#define DEFAULT_PSNR_ENABLE 0 102#define DEFAULT_ME_SPEED 100 103#define DEFAULT_ENABLE_FAST_SAD 0 104#define DEFAULT_ENABLE_ALT_REF 0 105#define DEFAULT_RC 1 106#define DEFAULT_BITRATE 6000000 107#define DEFAULT_I_QP 25 108#define DEFAULT_I_QP_MAX DEFAULT_QP_MAX 109#define DEFAULT_I_QP_MIN 0 110#define DEFAULT_P_QP 28 111#define DEFAULT_P_QP_MAX DEFAULT_QP_MAX 112#define DEFAULT_P_QP_MIN 0 113#define DEFAULT_B_QP 28 114#define DEFAULT_B_QP_MAX DEFAULT_QP_MAX 115#define DEFAULT_B_QP_MIN 0 116#define DEFAULT_AIR 0 117#define DEFAULT_AIR_REFRESH_PERIOD 30 118#define DEFAULT_SRCH_RNG_X 64 119#define DEFAULT_SRCH_RNG_Y 48 120#define DEFAULT_I_INTERVAL 30 121#define DEFAULT_IDR_INTERVAL 1000 122#define DEFAULT_B_FRAMES 0 123#define DEFAULT_DISABLE_DEBLK_LEVEL 0 124#define DEFAULT_HPEL 1 125#define DEFAULT_QPEL 1 126#define DEFAULT_I4 1 127#define DEFAULT_EPROFILE IV_PROFILE_BASE 128#define DEFAULT_SLICE_MODE 0 129#define DEFAULT_SLICE_PARAM 256 130#define DEFAULT_ARCH ARCH_ARM_A9Q 131#define STRLENGTH 500 132 133 134/*****************************************************************************/ 135/* profile Macros */ 136/*****************************************************************************/ 137#ifdef PROFILE_ENABLE 138 #ifdef WINDOWS_TIMER 139 typedef LARGE_INTEGER TIMER; 140 #else 141 //#ifdef X86_MINGW 142 typedef struct timeval TIMER; 143 //#endif 144 #endif 145#endif 146 147#ifdef PROFILE_ENABLE 148 #ifdef WINDOWS_TIMER 149 #define GETTIME(timer) QueryPerformanceCounter(timer); 150 #else 151 //#ifdef X86_MINGW 152 #define GETTIME(timer) gettimeofday(timer,NULL); 153 //#endif 154 #endif 155 156 #ifdef WINDOWS_TIMER 157 #define ELAPSEDTIME(s_start_timer,s_end_timer, s_elapsed_time, frequency) \ 158 { \ 159 TIMER s_temp_time; \ 160 s_temp_time.LowPart = s_end_timer.LowPart - s_start_timer.LowPart ; \ 161 s_elapsed_time = (UWORD32) ( ((DOUBLE)s_temp_time.LowPart / (DOUBLE)frequency.LowPart ) * 1000000); \ 162 } 163 #else 164 //#ifdef X86_MINGW 165 #define ELAPSEDTIME(s_start_timer,s_end_timer, s_elapsed_time, frequency) \ 166 s_elapsed_time = ((s_end_timer.tv_sec - s_start_timer.tv_sec) * 1000000) + (s_end_timer.tv_usec - s_start_timer.tv_usec); 167 //#endif 168 #endif 169 170#else 171 #define GETTIME(timer) 172 #define ELAPSEDTIME(s_start_timer,s_end_timer, s_elapsed_time, frequency) 173#endif 174 175 176/*****************************************************************************/ 177/* Structure definitions */ 178/*****************************************************************************/ 179typedef struct 180{ 181 UWORD8 *pu1_buf; 182 UWORD32 u4_buf_size; 183 UWORD32 u4_timestamp_low; 184 UWORD32 u4_timestamp_high; 185 UWORD32 u4_is_free; 186 void *pv_mb_info; 187 void *pv_pic_info; 188}input_buf_t; 189 190typedef struct 191{ 192 UWORD8 *pu1_buf; 193 UWORD32 u4_buf_size; 194 UWORD32 u4_timestamp_low; 195 UWORD32 u4_timestamp_high; 196 UWORD32 u4_is_free; 197}output_buf_t; 198 199typedef struct 200{ 201 UWORD8 *pu1_buf; 202 UWORD32 u4_buf_size; 203 UWORD32 u4_timestamp_low; 204 UWORD32 u4_timestamp_high; 205 UWORD32 u4_is_free; 206}recon_buf_t; 207 208typedef struct 209{ 210 iv_obj_t *ps_enc; 211 iv_mem_rec_t *ps_mem_rec; 212 UWORD32 u4_num_mem_rec; 213 UWORD32 u4_recon_enable; 214 UWORD32 u4_chksum_enable; 215 UWORD32 u4_mb_info_type; 216 UWORD32 u4_pic_info_type; 217 UWORD32 u4_mb_info_size; 218 UWORD32 u4_pic_info_size; 219 UWORD32 u4_start_frm; 220 UWORD32 u4_max_num_frms; 221 UWORD32 u4_total_bytes; 222 UWORD32 u4_pics_cnt; 223 IV_COLOR_FORMAT_T e_inp_color_fmt; 224 IV_COLOR_FORMAT_T e_recon_color_fmt; 225 IV_ARCH_T e_arch; 226 IV_SOC_T e_soc; 227 228 WORD32 header_generated; 229 void *pv_codec_obj; 230 231 UWORD32 u4_num_cores; 232 UWORD32 u4_pre_enc_me; 233 UWORD32 u4_pre_enc_ipe; 234 CHAR ac_ip_fname[STRLENGTH]; 235 CHAR ac_op_fname[STRLENGTH]; 236 CHAR ac_recon_fname[STRLENGTH]; 237 CHAR ac_chksum_fname[STRLENGTH]; 238 CHAR ac_mb_info_fname[STRLENGTH]; 239 CHAR ac_pic_info_fname[STRLENGTH]; 240 241 242 FILE *fp_ip; 243 FILE *fp_op; 244 FILE *fp_recon; 245 FILE *fp_chksum; 246 FILE *fp_psnr_ip; 247 FILE *fp_mb_info; 248 FILE *fp_pic_info; 249 FILE *fp_dump_op; 250 251 252 UWORD32 u4_loopback; 253 UWORD32 u4_max_frame_rate; 254 UWORD32 u4_src_frame_rate; 255 UWORD32 u4_tgt_frame_rate; 256 UWORD32 u4_max_wd; 257 UWORD32 u4_max_ht; 258 UWORD32 u4_max_level; 259 260 UWORD32 u4_strd; 261 262 UWORD32 u4_wd; 263 UWORD32 u4_ht; 264 265 UWORD32 u4_psnr_enable; 266 267 268 UWORD32 u4_enc_speed; 269 UWORD32 u4_me_speed; 270 UWORD32 u4_enable_fast_sad; 271 UWORD32 u4_enable_alt_ref; 272 UWORD32 u4_rc; 273 UWORD32 u4_max_bitrate; 274 UWORD32 u4_bitrate; 275 UWORD32 u4_i_qp,u4_i_qp_max,u4_i_qp_min; 276 UWORD32 u4_p_qp,u4_p_qp_max,u4_p_qp_min; 277 UWORD32 u4_b_qp,u4_b_qp_max,u4_b_qp_min; 278 UWORD32 u4_air; 279 UWORD32 u4_air_refresh_period; 280 UWORD32 u4_srch_rng_x; 281 UWORD32 u4_srch_rng_y; 282 UWORD32 u4_i_interval; 283 UWORD32 u4_idr_interval; 284 UWORD32 u4_b_frames; 285 UWORD32 u4_disable_deblk_level; 286 UWORD32 u4_hpel; 287 UWORD32 u4_qpel; 288 UWORD32 u4_enable_intra_4x4; 289 IV_PROFILE_T e_profile; 290 291 UWORD32 u4_slice_mode; 292 UWORD32 u4_slice_param; 293 294 void *pv_input_thread_handle; 295 void *pv_output_thread_handle; 296 void *pv_recon_thread_handle; 297 298 ih264e_ctl_getbufinfo_op_t s_get_buf_info_op; 299 input_buf_t as_input_buf[DEFAULT_MAX_INPUT_BUFS]; 300 output_buf_t as_output_buf[DEFAULT_MAX_OUTPUT_BUFS]; 301 recon_buf_t as_recon_buf[DEFAULT_MAX_RECON_BUFS]; 302 303 DOUBLE adbl_psnr[3]; 304 UWORD32 u4_psnr_cnt; 305 UWORD8 *pu1_psnr_buf; 306 UWORD8 u4_psnr_buf_size; 307 308 UWORD32 u4_vbv_buffer_delay; 309 UWORD32 u4_vbv_buf_size; 310 311 TIMER enc_start_time; 312 TIMER enc_last_time; 313 WORD32 avg_time; 314 315 316} app_ctxt_t; 317 318/*****************************************************************************/ 319/* Function Declarations */ 320/*****************************************************************************/ 321void codec_exit(CHAR *pc_err_message); 322void allocate_input(app_ctxt_t *ps_app_ctxt); 323void allocate_output(app_ctxt_t *ps_app_ctxt); 324void allocate_recon(app_ctxt_t *ps_app_ctxt); 325 326IV_STATUS_T read_input(FILE *fp, iv_raw_buf_t *ps_raw_buf); 327IV_STATUS_T write_recon(FILE *fp, iv_raw_buf_t *ps_raw_buf); 328IV_STATUS_T write_output(FILE *fp, UWORD8 *pu1_buf, WORD32 num_bytes); 329 330IV_STATUS_T read_mb_info(app_ctxt_t *ps_app_ctxt, void *pv_mb_info); 331IV_STATUS_T read_pic_info(app_ctxt_t *ps_app_ctxt, void *pv_pic_info); 332 333void * ih264a_aligned_malloc(WORD32 alignment, WORD32 size); 334void ih264a_aligned_free(void *pv_buf); 335 336void free_input(app_ctxt_t *ps_app_ctxt); 337void free_recon(app_ctxt_t *ps_app_ctxt); 338void free_output(app_ctxt_t *ps_app_ctxt); 339 340void 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); 341 342#ifndef MD5_DISABLE 343void calc_md5_cksum(UWORD8 *pu1_inbuf,UWORD32 u4_stride,UWORD32 u4_width,UWORD32 u4_height,UWORD8 *pu1_cksum_p ); 344#else 345#define calc_md5_cksum(a, b, c, d, e) 346#endif 347 348#endif /* _APP_H_ */ 349