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