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