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 #else 46 #include <sys/time.h> 47 #endif 48 /*****************************************************************************/ 49 /* Function Macros */ 50 /*****************************************************************************/ 51 #define MAX(a, b) ((a) > (b))? (a) : (b) 52 #define MIN(a, b) ((a) < (b))? (a) : (b) 53 54 #define ALIGN16(x) ((((x) + 15) >> 4) << 4) 55 56 /*****************************************************************************/ 57 /* Constant Macros */ 58 /*****************************************************************************/ 59 60 #define DEFAULT_NUM_INPUT_BUFS 32 61 #define DEFAULT_MAX_INPUT_BUFS 32 62 63 #define DEFAULT_NUM_OUTPUT_BUFS 32 64 #define DEFAULT_MAX_OUTPUT_BUFS 32 65 66 #define DEFAULT_NUM_RECON_BUFS 32 67 #define DEFAULT_MAX_RECON_BUFS DEFAULT_NUM_RECON_BUFS 68 69 70 #define LEN_STATUS_BUFFER (10 * 1024) 71 #define MAX_VBV_BUFF_SIZE (120 * 16384) 72 #define MAX_NUM_IO_BUFS 3 73 74 #define DEFAULT_MAX_REF_FRM 2 75 #define DEFAULT_MAX_REORDER_FRM 0 76 #define DEFAULT_QP_MIN 4 77 #define DEFAULT_QP_MAX 51 78 #define DEFAULT_MAX_BITRATE 240000000 79 #define DEFAULT_NUM_BFRAMES 0 80 #define DEFAULT_MAX_SRCH_RANGE_X 256 81 #define DEFAULT_MAX_SRCH_RANGE_Y 256 82 #define DEFAULT_MAX_FRAMERATE 120000 83 #define DEFAULT_NUM_CORES 1 84 #define DEFAULT_NUM_CORES_PRE_ENC 0 85 #define DEFAULT_FPS 30 86 #define DEFAULT_ENC_SPEED 100 87 88 #define DEFAULT_MEM_REC_CNT 0 89 #define DEFAULT_RECON_ENABLE 0 90 #define DEFAULT_CHKSUM_ENABLE 0 91 #define DEFAULT_START_FRM 0 92 #define DEFAULT_NUM_FRMS 0xFFFFFFFF 93 #define DEFAULT_INP_COLOR_FMT IV_YUV_420SP_UV 94 #define DEFAULT_RECON_COLOR_FMT IV_YUV_420P 95 #define DEFAULT_LOOPBACK 0 96 #define DEFAULT_SRC_FRAME_RATE 30 97 #define DEFAULT_TGT_FRAME_RATE 30 98 #define DEFAULT_MAX_WD 1920 99 #define DEFAULT_MAX_HT 1920 100 #define DEFAULT_MAX_LEVEL 40 101 #define DEFAULT_STRIDE 0 102 #define DEFAULT_WD 0 103 #define DEFAULT_HT 0 104 #define DEFAULT_PSNR_ENABLE 0 105 #define DEFAULT_ME_SPEED 100 106 #define DEFAULT_ENABLE_FAST_SAD 0 107 #define DEFAULT_ENABLE_ALT_REF 0 108 #define DEFAULT_RC 1 109 #define DEFAULT_BITRATE 6000000 110 #define DEFAULT_I_QP 25 111 #define DEFAULT_I_QP_MAX DEFAULT_QP_MAX 112 #define DEFAULT_I_QP_MIN 0 113 #define DEFAULT_P_QP 28 114 #define DEFAULT_P_QP_MAX DEFAULT_QP_MAX 115 #define DEFAULT_P_QP_MIN 0 116 #define DEFAULT_B_QP 28 117 #define DEFAULT_B_QP_MAX DEFAULT_QP_MAX 118 #define DEFAULT_B_QP_MIN 0 119 #define DEFAULT_AIR 0 120 #define DEFAULT_AIR_REFRESH_PERIOD 30 121 #define DEFAULT_SRCH_RNG_X 64 122 #define DEFAULT_SRCH_RNG_Y 48 123 #define DEFAULT_I_INTERVAL 30 124 #define DEFAULT_IDR_INTERVAL 1000 125 #define DEFAULT_CONSTRAINED_INTRAPRED 0 126 #define DEFAULT_B_FRAMES 0 127 #define DEFAULT_DISABLE_DEBLK_LEVEL 0 128 #define DEFAULT_HPEL 1 129 #define DEFAULT_QPEL 1 130 #define DEFAULT_I4 1 131 #define DEFAULT_EPROFILE IV_PROFILE_BASE 132 #define DEFAULT_SLICE_MODE 0 133 #define DEFAULT_SLICE_PARAM 256 134 #define DEFAULT_ENTROPY_CODING_MODE 0 135 136 #define DEFAULT_MAX_DISPLAY_MASTERING_LUMINANCE 50000 137 #define DEFAULT_MIN_DISPLAY_MASTERING_LUMINANCE 1 138 139 #define STRLENGTH 500 140 141 142 /*****************************************************************************/ 143 /* profile Macros */ 144 /*****************************************************************************/ 145 #ifdef PROFILE_ENABLE 146 #ifdef WINDOWS_TIMER 147 typedef LARGE_INTEGER TIMER; 148 #else 149 //#ifdef X86_MINGW 150 typedef struct timeval TIMER; 151 //#endif 152 #endif 153 #endif 154 155 #ifdef PROFILE_ENABLE 156 #ifdef WINDOWS_TIMER 157 #define GETTIME(timer) QueryPerformanceCounter(timer); 158 #else 159 //#ifdef X86_MINGW 160 #define GETTIME(timer) gettimeofday(timer,NULL); 161 //#endif 162 #endif 163 164 #ifdef WINDOWS_TIMER 165 #define ELAPSEDTIME(s_start_timer,s_end_timer, s_elapsed_time, frequency) \ 166 { \ 167 TIMER s_temp_time; \ 168 s_temp_time.LowPart = s_end_timer.LowPart - s_start_timer.LowPart ; \ 169 s_elapsed_time = (UWORD32) ( ((DOUBLE)s_temp_time.LowPart / (DOUBLE)frequency.LowPart ) * 1000000); \ 170 } 171 #else 172 //#ifdef X86_MINGW 173 #define ELAPSEDTIME(s_start_timer,s_end_timer, s_elapsed_time, frequency) \ 174 s_elapsed_time = ((s_end_timer.tv_sec - s_start_timer.tv_sec) * 1000000) + (s_end_timer.tv_usec - s_start_timer.tv_usec); 175 //#endif 176 #endif 177 178 #else 179 #define GETTIME(timer) 180 #define ELAPSEDTIME(s_start_timer,s_end_timer, s_elapsed_time, frequency) 181 #endif 182 183 184 /*****************************************************************************/ 185 /* Structure definitions */ 186 /*****************************************************************************/ 187 typedef struct 188 { 189 UWORD8 *pu1_buf; 190 UWORD32 u4_buf_size; 191 UWORD32 u4_timestamp_low; 192 UWORD32 u4_timestamp_high; 193 UWORD32 u4_is_free; 194 void *pv_mb_info; 195 void *pv_pic_info; 196 }input_buf_t; 197 198 typedef struct 199 { 200 UWORD8 *pu1_buf; 201 UWORD32 u4_buf_size; 202 UWORD32 u4_timestamp_low; 203 UWORD32 u4_timestamp_high; 204 UWORD32 u4_is_free; 205 }output_buf_t; 206 207 typedef struct 208 { 209 UWORD8 *pu1_buf; 210 UWORD32 u4_buf_size; 211 UWORD32 u4_timestamp_low; 212 UWORD32 u4_timestamp_high; 213 UWORD32 u4_is_free; 214 }recon_buf_t; 215 216 typedef struct 217 { 218 iv_obj_t *ps_enc; 219 iv_mem_rec_t *ps_mem_rec; 220 UWORD32 u4_num_mem_rec; 221 UWORD32 u4_recon_enable; 222 UWORD32 u4_chksum_enable; 223 UWORD32 u4_mb_info_type; 224 UWORD32 u4_pic_info_type; 225 UWORD32 u4_mb_info_size; 226 UWORD32 u4_pic_info_size; 227 UWORD32 u4_start_frm; 228 UWORD32 u4_max_num_frms; 229 UWORD32 u4_total_bytes; 230 UWORD32 u4_pics_cnt; 231 IV_COLOR_FORMAT_T e_inp_color_fmt; 232 IV_COLOR_FORMAT_T e_recon_color_fmt; 233 IV_ARCH_T e_arch; 234 IV_SOC_T e_soc; 235 236 WORD32 header_generated; 237 void *pv_codec_obj; 238 239 UWORD32 u4_num_cores; 240 UWORD32 u4_pre_enc_me; 241 UWORD32 u4_pre_enc_ipe; 242 CHAR ac_ip_fname[STRLENGTH]; 243 CHAR ac_op_fname[STRLENGTH]; 244 CHAR ac_recon_fname[STRLENGTH]; 245 CHAR ac_chksum_fname[STRLENGTH]; 246 CHAR ac_mb_info_fname[STRLENGTH]; 247 CHAR ac_pic_info_fname[STRLENGTH]; 248 249 250 FILE *fp_ip; 251 FILE *fp_op; 252 FILE *fp_recon; 253 FILE *fp_chksum; 254 FILE *fp_psnr_ip; 255 FILE *fp_mb_info; 256 FILE *fp_pic_info; 257 FILE *fp_dump_op; 258 259 260 UWORD32 u4_loopback; 261 UWORD32 u4_max_frame_rate; 262 UWORD32 u4_src_frame_rate; 263 UWORD32 u4_tgt_frame_rate; 264 UWORD32 u4_max_wd; 265 UWORD32 u4_max_ht; 266 UWORD32 u4_max_level; 267 268 UWORD32 u4_strd; 269 270 UWORD32 u4_wd; 271 UWORD32 u4_ht; 272 273 UWORD32 u4_psnr_enable; 274 275 276 UWORD32 u4_enc_speed; 277 UWORD32 u4_me_speed; 278 UWORD32 u4_enable_fast_sad; 279 UWORD32 u4_enable_alt_ref; 280 UWORD32 u4_rc; 281 UWORD32 u4_max_bitrate; 282 UWORD32 u4_bitrate; 283 UWORD32 u4_i_qp,u4_i_qp_max,u4_i_qp_min; 284 UWORD32 u4_p_qp,u4_p_qp_max,u4_p_qp_min; 285 UWORD32 u4_b_qp,u4_b_qp_max,u4_b_qp_min; 286 UWORD32 u4_air; 287 UWORD32 u4_air_refresh_period; 288 UWORD32 u4_srch_rng_x; 289 UWORD32 u4_srch_rng_y; 290 UWORD32 u4_i_interval; 291 UWORD32 u4_idr_interval; 292 UWORD32 u4_constrained_intra_pred; 293 UWORD32 u4_b_frames; 294 UWORD32 u4_num_bframes; 295 UWORD32 u4_disable_deblk_level; 296 UWORD32 u4_hpel; 297 UWORD32 u4_qpel; 298 UWORD32 u4_enable_intra_4x4; 299 IV_PROFILE_T e_profile; 300 301 UWORD32 u4_slice_mode; 302 UWORD32 u4_slice_param; 303 UWORD32 u4_entropy_coding_mode; 304 305 void *pv_input_thread_handle; 306 void *pv_output_thread_handle; 307 void *pv_recon_thread_handle; 308 309 ih264e_ctl_getbufinfo_op_t s_get_buf_info_op; 310 input_buf_t as_input_buf[DEFAULT_MAX_INPUT_BUFS]; 311 output_buf_t as_output_buf[DEFAULT_MAX_OUTPUT_BUFS]; 312 recon_buf_t as_recon_buf[DEFAULT_MAX_RECON_BUFS]; 313 314 DOUBLE adbl_psnr[3]; 315 UWORD32 u4_psnr_cnt; 316 UWORD8 *pu1_psnr_buf; 317 UWORD8 u4_psnr_buf_size; 318 319 UWORD32 u4_vbv_buffer_delay; 320 UWORD32 u4_vbv_buf_size; 321 322 TIMER enc_start_time; 323 TIMER enc_last_time; 324 WORD32 avg_time; 325 326 UWORD32 u4_sei_mdcv_params_present_flag; 327 UWORD32 au4_display_primaries_x[NUM_SEI_MDCV_PRIMARIES]; 328 UWORD32 au4_display_primaries_y[NUM_SEI_MDCV_PRIMARIES]; 329 UWORD32 u4_white_point_x; 330 UWORD32 u4_white_point_y; 331 UWORD32 u4_max_display_mastering_luminance; 332 UWORD32 u4_min_display_mastering_luminance; 333 334 UWORD32 u4_sei_cll_params_present_flag; 335 UWORD32 u4_max_content_light_level; 336 UWORD32 u4_max_pic_average_light_level; 337 338 UWORD32 u4_sei_ave_params_present_flag; 339 UWORD32 u4_ambient_illuminance; 340 UWORD32 u4_ambient_light_x; 341 UWORD32 u4_ambient_light_y; 342 343 UWORD32 u4_sei_ccv_params_present_flag; 344 UWORD32 u4_ccv_cancel_flag; 345 UWORD32 u4_ccv_persistence_flag; 346 UWORD32 u4_ccv_primaries_present_flag; 347 UWORD32 u4_ccv_min_luminance_value_present_flag; 348 UWORD32 u4_ccv_max_luminance_value_present_flag; 349 UWORD32 u4_ccv_avg_luminance_value_present_flag; 350 UWORD32 u4_ccv_reserved_zero_2bits; 351 WORD32 ai4_ccv_primaries_x[NUM_SEI_CCV_PRIMARIES]; 352 WORD32 ai4_ccv_primaries_y[NUM_SEI_CCV_PRIMARIES]; 353 UWORD32 u4_ccv_min_luminance_value; 354 UWORD32 u4_ccv_max_luminance_value; 355 UWORD32 u4_ccv_avg_luminance_value; 356 357 ih264e_ctl_set_sei_mdcv_params_ip_t s_sei_mdcv_params; 358 ih264e_ctl_set_sei_cll_params_ip_t s_sei_cll_params; 359 ih264e_ctl_set_sei_ave_params_ip_t s_sei_ave_params; 360 361 } app_ctxt_t; 362 363 /*****************************************************************************/ 364 /* Function Declarations */ 365 /*****************************************************************************/ 366 void codec_exit(CHAR *pc_err_message); 367 void allocate_input(app_ctxt_t *ps_app_ctxt); 368 void allocate_output(app_ctxt_t *ps_app_ctxt); 369 void allocate_recon(app_ctxt_t *ps_app_ctxt); 370 371 IV_STATUS_T read_input(FILE *fp, iv_raw_buf_t *ps_raw_buf); 372 IV_STATUS_T write_recon(FILE *fp, iv_raw_buf_t *ps_raw_buf); 373 IV_STATUS_T write_output(FILE *fp, UWORD8 *pu1_buf, WORD32 num_bytes); 374 375 IV_STATUS_T read_mb_info(app_ctxt_t *ps_app_ctxt, void *pv_mb_info); 376 IV_STATUS_T read_pic_info(app_ctxt_t *ps_app_ctxt, void *pv_pic_info); 377 378 void * ih264a_aligned_malloc(WORD32 alignment, WORD32 size); 379 void ih264a_aligned_free(void *pv_buf); 380 381 void free_input(app_ctxt_t *ps_app_ctxt); 382 void free_recon(app_ctxt_t *ps_app_ctxt); 383 void free_output(app_ctxt_t *ps_app_ctxt); 384 385 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); 386 387 #ifndef MD5_DISABLE 388 void calc_md5_cksum(UWORD8 *pu1_inbuf,UWORD32 u4_stride,UWORD32 u4_width,UWORD32 u4_height,UWORD8 *pu1_cksum_p ); 389 #else 390 #define calc_md5_cksum(a, b, c, d, e) 391 #endif 392 393 #endif /* _APP_H_ */ 394