1 /****************************************************************************** 2 * 3 * Copyright (C) 2018 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 ihevce_lap_enc_structs.h 23 * 24 * \brief 25 * This file contains structure definations shared between Encoder and LAP 26 * 27 * \date 28 * 18/09/2012 29 * 30 * \author 31 * Ittiam 32 * 33 ****************************************************************************** 34 */ 35 36 #ifndef _IHEVCE_LAP_ENC_STRUCTS_H_ 37 #define _IHEVCE_LAP_ENC_STRUCTS_H_ 38 39 /*****************************************************************************/ 40 /* Constant Macros */ 41 /*****************************************************************************/ 42 #define MAX_NUM_BUFS_LAP_ENC 15 43 #define MAX_REF_PICS 16 44 #define MAX_PICS_FOR_SGI 16 /*max pics to be hold for Sub-Gop Interleave*/ 45 #define MAX_DUPLICATE_ENTRIES_IN_REF_LIST 2 46 #define MAX_LAP_WINDOW_SIZE 60 47 #define MAX_SUB_GOP_SIZE 16 48 #define MAX_SCENE_NUM 30 49 #define INIT_HEVCE_QP_RC (-300) 50 #define MAX_TEMPORAL_LAYERS 3 51 #define NUM_LAP2_LOOK_AHEAD 25 52 53 #define INFINITE_GOP_CDR_TIME_S 3 54 #define FRAME_PARALLEL_LVL 0 55 #define NUM_SG_INTERLEAVED (1 + FRAME_PARALLEL_LVL) 56 57 #define MAX_NUM_ENC_LOOP_PARALLEL 1 58 #define MAX_NUM_ME_PARALLEL 1 59 #define DIST_MODE_3_NON_REF_B 0 // disabled for normal cases 60 61 #define DENOM_DEFAULT 7 62 #define WGHT_DEFAULT (1 << DENOM_DEFAULT) 63 64 #define MAX_NON_REF_B_PICS_IN_QUEUE_SGI MAX_PICS_FOR_SGI //ELP_RC 65 66 /*minimum stagger in non sequential operation*/ 67 #define MIN_L1_L0_STAGGER_NON_SEQ 1 68 69 /* Enable or disable Psedo presets*/ 70 #undef PSEUDO_PRESETS 71 72 /** 73 ******************************************************************************* 74 @brief Ivalid POC value since negative POCs are also valid as per syntax 75 ******************************************************************************* 76 */ 77 #define INVALID_POC -16384 78 /*****************************************************************************/ 79 /* Function Macros */ 80 /*****************************************************************************/ 81 82 /*****************************************************************************/ 83 /* Typedefs */ 84 /*****************************************************************************/ 85 86 /*****************************************************************************/ 87 /* Enums */ 88 /*****************************************************************************/ 89 /* Scenetype enums */ 90 typedef enum SCENE_TYPE_E 91 { 92 SCENE_TYPE_NORMAL = 0, 93 SCENE_TYPE_SCENE_CUT, 94 SCENE_TYPE_FLASH, 95 SCENE_TYPE_FADE_IN, 96 SCENE_TYPE_FADE_OUT, 97 SCENE_TYPE_DISSOLVE, 98 SCENE_TYPE_PAUSE_TO_RESUME, 99 MAX_NUM_SCENE_TYPES 100 } SCENE_TYPE_E; 101 /*****************************************************************************/ 102 /* Structure */ 103 /*****************************************************************************/ 104 105 /** 106 ****************************************************************************** 107 * @brief Logo structure 108 ****************************************************************************** 109 */ 110 111 typedef struct 112 { 113 /** i4_is_logo_on : Specifies if logo is on or off */ 114 WORD32 i4_is_logo_on; 115 116 /** logo_width : Width of the logo in pixels */ 117 WORD32 logo_width; 118 119 /** logo_height : Width of the logo in pixels */ 120 WORD32 logo_height; 121 122 /** logo_x_offset : horizontal offset for logo from the right end of pic */ 123 WORD32 logo_x_offset; 124 125 /** logo_y_offset : vertical offset for logo from the bottom end of pic */ 126 WORD32 logo_y_offset; 127 128 } ihevce_logo_attrs_t; 129 130 typedef struct 131 { 132 /** 133 * Input YUV buffers pointers and related parameters 134 */ 135 ihevce_lap_params_t s_lap_params; 136 137 /** Width of input luma */ 138 WORD32 i4_width; 139 140 /** Height of input luma */ 141 WORD32 i4_height; 142 143 /** Max closed gop period : Max spacing between IDR frames */ 144 WORD32 i4_max_closed_gop_period; 145 146 /** Min closed gop period : Min spacing between IDR frames */ 147 WORD32 i4_min_closed_gop_period; 148 149 /** Max CRA open gop period: Max spacing between CRA frames */ 150 WORD32 i4_max_cra_open_gop_period; 151 152 /** Max i open gop period: Max spacing between I frames */ 153 WORD32 i4_max_i_open_gop_period; 154 155 /** limits Max gopsize = 2 ^ i4_max_temporal_layers - 1 */ 156 WORD32 i4_max_temporal_layers; 157 158 /** Minimum temporal ID from which B-pictures are coded; Tid=1 (default) 0 (no B) */ 159 WORD32 i4_min_temporal_id_for_b; 160 161 /** Maximum number of reference frames */ 162 WORD32 i4_max_reference_frames; 163 164 /** Interlace field */ 165 WORD32 i4_src_interlace_field; 166 167 /* Frame rate*/ 168 WORD32 i4_frame_rate; 169 170 /** Enable Logo flag */ 171 WORD32 i4_enable_logo; 172 173 /** Bit Depth */ 174 WORD32 i4_internal_bit_depth; 175 176 WORD32 i4_input_bit_depth; 177 178 /* 0 - 400; 1 - 420; 2 - 422; 3 - 444 */ 179 UWORD8 u1_chroma_array_type; 180 181 WORD32 ai4_quality_preset[IHEVCE_MAX_NUM_RESOLUTIONS]; 182 183 WORD32 i4_rc_pass_num; 184 185 /* If enable, enables blu ray compatibility of op*/ 186 WORD32 i4_blu_ray_spec; 187 188 IV_ARCH_T e_arch_type; 189 190 UWORD8 u1_is_popcnt_available; 191 192 WORD32 i4_mres_single_out; 193 194 WORD32 i4_luma_size_copy_src_logo; 195 196 } ihevce_lap_static_params_t; 197 198 /** 199 * @biref luma and chroma weight and offset container structure 200 */ 201 typedef struct 202 { 203 /** 204 * flag to control the weighted pred for luma component of 205 * this reference frame 206 * Range [0 : 1] 207 */ 208 UWORD8 u1_luma_weight_enable_flag; 209 210 /** 211 * flag to control the weighted pred for chroma component of 212 * this reference frame 213 * Range [0 : 1] 214 */ 215 UWORD8 u1_chroma_weight_enable_flag; 216 217 /** 218 * luma weight factor for a reference frame, 219 * Range [0 : 128] 220 * Default = 1 << as_wght_offst 221 */ 222 WORD16 i2_luma_weight; 223 224 /** 225 * luma offset to be added after weighing for reference frame 226 * Range [-128 : 127] 227 * Default = 0 228 */ 229 WORD16 i2_luma_offset; 230 231 /** 232 * chroma weight factor for a reference frame, Default = 1 233 */ 234 WORD16 i2_cb_weight; 235 236 /** 237 * chroma offset to be added after weighing for reference frame, Default = 0 238 */ 239 WORD16 i2_cb_offset; 240 241 /** 242 * chroma weight factor for a reference frame, Default = 1 243 */ 244 WORD16 i2_cr_weight; 245 246 /** 247 * chroma offset to be added after weighing for reference frame, Default = 0 248 */ 249 WORD16 i2_cr_offset; 250 251 } ihevce_wght_offst_t; 252 253 /** 254 * @biref defines the attributes of a reference picture 255 */ 256 typedef struct 257 { 258 /** 259 * weighted prediction attribute for each duplicate entry of a ref pic 260 * Note : Duplicate entries help in using same reference with different 261 * weights and offsets. Example being partial flashes in scence 262 */ 263 ihevce_wght_offst_t as_wght_off[MAX_DUPLICATE_ENTRIES_IN_REF_LIST]; 264 265 /** 266 * delta POC of reference frame w.r.t current Picture POC, 267 */ 268 WORD32 i4_ref_pic_delta_poc; 269 270 /** 271 * flag indicating if this reference frame is to be used as 272 * reference by current picture 273 * shall be 0 or 1 274 */ 275 WORD32 i4_used_by_cur_pic_flag; 276 277 /** 278 * Indicates the number of duplicate entries of a reference picture 279 * in the reference picture list. A reference picture may see multiple 280 * entries in the reference picture list, since that allows the LAP to 281 * assign multiple weighting related parameters to a single reference picture. 282 * Range [1, MAX_DUPLICATE_ENTRIES_IN_REF_LIST] 283 * 284 * Used only when weighted prediction is enabled 285 * 286 */ 287 WORD32 i4_num_duplicate_entries_in_ref_list; 288 289 } ihevce_ref_pic_attrs_t; 290 291 /* @brief IV_YUV_BUF_T: This structure defines attributes 292 * for the input yuv used in enc and lap buffer 293 */ 294 typedef struct 295 { 296 /** i4_size of the structure */ 297 WORD32 i4_size; 298 299 /** Pointer to Luma (Y) Buffer */ 300 void *pv_y_buf; 301 302 /** Pointer to Chroma (Cb) Buffer */ 303 void *pv_u_buf; 304 305 /** Pointer to Chroma (Cr) Buffer */ 306 void *pv_v_buf; 307 308 /** Width of the Luma (Y) Buffer in pixels */ 309 WORD32 i4_y_wd; 310 311 /** Height of the Luma (Y) Buffer in pixels */ 312 WORD32 i4_y_ht; 313 314 /** Stride/Pitch of the Luma (Y) Buffer */ 315 WORD32 i4_y_strd; 316 317 /** Luma Process start offset : x dir. */ 318 WORD32 i4_start_offset_x; 319 320 /** Luma Process start offset : y dir. */ 321 WORD32 i4_start_offset_y; 322 323 /** Width of the Chroma (Cb / Cr) Buffer in pixels */ 324 WORD32 i4_uv_wd; 325 326 /** Height of the Chroma (Cb / Cr) Buffer in pixels */ 327 WORD32 i4_uv_ht; 328 329 /** Stride/Pitch of the Chroma (Cb / Cr) Buffer */ 330 WORD32 i4_uv_strd; 331 332 } iv_enc_yuv_buf_t; 333 334 typedef struct 335 { 336 /** i4_size of the structure */ 337 WORD32 i4_size; 338 339 /** Pointer to Luma (Y) Buffer */ 340 void *pv_y_buf; 341 342 /** Pointer to Chroma (Cb) Buffer */ 343 void *pv_u_buf; 344 345 /** Pointer to Chroma (Cr) Buffer */ 346 void *pv_v_buf; 347 348 } iv_enc_yuv_buf_src_t; 349 350 typedef struct 351 { 352 /*********** common params for both lap_out and rc_lap_out ****************/ 353 354 /* hevc pic types : IDR/CDR/I/P/B etc */ 355 WORD32 i4_pic_type; 356 /* picture order count */ 357 WORD32 i4_poc; 358 /* temporal layer of the current picture */ 359 WORD32 i4_temporal_lyr_id; 360 /** 361 * indicates if the current frame is reference pic 362 * 0 : not ref pic 363 * 1 : ref pic at lower layers (w.r.t to highest layer id) 364 * 2 : ref pic at highest temporal layer id layer 365 */ 366 WORD32 i4_is_ref_pic; 367 /** 368 * Scene type such as Scene Cut, fade in/ out, dissolve, flash etc 369 * enum used is IHEVCE_SCENE_TYPE 370 */ 371 WORD32 i4_scene_type; 372 /** 373 * Scene number helps to identify the reference frames 374 * for the current frame of same scene and 375 * also it can be used to reset the RC model 376 * for each layer whenever scene cut happens 377 */ 378 UWORD32 u4_scene_num; 379 /*display order num*/ 380 WORD32 i4_display_num; 381 382 WORD32 i4_quality_preset; 383 384 /*********** parameters specific to lap_out structure **************/ 385 /* cra pic type flag */ 386 WORD32 i4_is_cra_pic; 387 /** IDR GOP number */ 388 WORD32 i4_idr_gop_num; 389 /** weighted prediction enable flag */ 390 WORD8 i1_weighted_pred_flag; 391 /** weighted bipred enable flag */ 392 WORD8 i1_weighted_bipred_flag; 393 /* number of references for current pic */ 394 WORD32 i4_num_ref_pics; 395 /** 396 * common denominator used for luma weights across all ref pics 397 * Default = 0, Shall be in the range [0:7] 398 */ 399 WORD32 i4_log2_luma_wght_denom; 400 /** 401 * common denominator used for chroma weights across all ref pics 402 * Default = 0, Shall be in the range [0:7] 403 */ 404 WORD32 i4_log2_chroma_wght_denom; 405 /* ref pics to str current Picture POC */ 406 ihevce_ref_pic_attrs_t as_ref_pics[MAX_REF_PICS]; 407 /* Structure for the ITTIAM logo */ 408 ihevce_logo_attrs_t s_logo_ctxt; 409 /* first field flag */ 410 WORD32 i4_first_field; 411 /* associated IRAP poc */ 412 WORD32 i4_assoc_IRAP_poc; 413 WORD32 i4_is_prev_pic_in_Tid0_same_scene; 414 415 WORD32 i4_is_I_in_any_field; 416 WORD32 i4_used; 417 418 WORD32 i4_end_flag; 419 WORD32 i4_force_idr_flag; 420 WORD32 i4_out_flush_flag; 421 WORD32 i4_first_frm_new_res; 422 423 /***** Spatial QP offset related *****/ 424 float f_strength; 425 426 long double ld_curr_frame_8x8_log_avg[2]; 427 long double ld_curr_frame_16x16_log_avg[3]; 428 long double ld_curr_frame_32x32_log_avg[3]; 429 430 LWORD64 i8_curr_frame_8x8_avg_act[2]; 431 LWORD64 i8_curr_frame_16x16_avg_act[3]; 432 LWORD64 i8_curr_frame_32x32_avg_act[3]; 433 434 WORD32 i4_i_pic_lamda_offset; 435 436 double f_i_pic_lamda_modifier; 437 438 WORD32 i4_curr_frm_qp; 439 440 iv_enc_yuv_buf_t s_input_buf; 441 442 /** Frame - level L0 satd accum*/ 443 LWORD64 i8_frame_l0_acc_satd; 444 445 /* Frame - level L1 Activity factor */ 446 LWORD64 i8_frame_level_activity_fact; 447 /*bits esimated for frame calulated for sub pic rc bit control */ 448 WORD32 ai4_frame_bits_estimated[IHEVCE_MAX_NUM_BITRATES]; 449 float f_pred_factor; 450 451 } ihevce_lap_output_params_t; 452 453 /** 454 ****************************************************************************** 455 * @brief Encoder and LAP I/O structutre 456 * s_input_buf : input buffer will be populated by applciation 457 * when LAP gets this buffer only input will be populated 458 * During the time of seeting the encode order for current buffer 459 * LAP should populate the s_lap_out structure. 460 ****************************************************************************** 461 */ 462 typedef struct 463 { 464 /** 465 * Input YUV buffers pointers and related parameters 466 */ 467 iv_input_data_ctrl_buffs_t s_input_buf; 468 469 /** 470 * Following parameters are output of LAP 471 * for the current buffer to be encoded 472 */ 473 ihevce_lap_output_params_t s_lap_out; 474 /** 475 * Following parameters are output of LAP 476 * for the current buffer to be encoded, 477 * which are RC specific parameters 478 */ 479 rc_lap_out_params_t s_rc_lap_out; 480 481 /** 482 * Following parameters are context of LAP QUEUE 483 */ 484 frame_info_t s_frame_info; 485 } ihevce_lap_enc_buf_t; 486 487 /*****************************************************************************/ 488 /* Extern Variable Declarations */ 489 /*****************************************************************************/ 490 491 /*****************************************************************************/ 492 /* Extern Function Declarations */ 493 /*****************************************************************************/ 494 495 #endif /* _IHEVCE_LAP_ENC_STRUCTS_H_ */ 496