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 #ifndef _IH264D_DEFS_H_ 21 #define _IH264D_DEFS_H_ 22 23 /** 24 ************************************************************************ 25 * \file ih264d_defs.h 26 * 27 * \brief 28 * Type definitions used in the code 29 * 30 * \date 31 * 19/11/2002 32 * 33 * \author Sriram Sethuraman 34 * 35 ************************************************************************ 36 */ 37 #define H264_MAX_FRAME_WIDTH 4080 38 #define H264_MAX_FRAME_HEIGHT 4080 39 #define H264_MAX_FRAME_SIZE (4096 * 2048) 40 41 #define H264_MIN_FRAME_WIDTH 16 42 #define H264_MIN_FRAME_HEIGHT 16 43 44 #define FMT_CONV_NUM_ROWS 16 45 46 /** Bit manipulation macros */ 47 #define CHECKBIT(a,i) ((a) & (1 << i)) 48 #define CLEARBIT(a,i) ((a) &= ~(1 << i)) 49 50 /** Macro to convert a integer to a boolean value */ 51 #define BOOLEAN(x) (!!(x)) 52 53 /** Arithmetic operations */ 54 #define MOD(x,y) ((x)%(y)) 55 #define DIV(x,y) ((x)/(y)) 56 #define MUL(x,y) ((x)*(y)) 57 #define SIGN_POW2_DIV(x, y) (((x) < 0) ? (-((-(x)) >> (y))) : ((x) >> (y))) 58 59 #define MB_ENABLE_FILTERING 0x00 60 #define MB_DISABLE_FILTERING 0x01 61 #define MB_DISABLE_TOP_EDGE 0x02 62 #define MB_DISABLE_LEFT_EDGE 0x04 63 64 /** Maximum number of reference pics */ 65 #define MAX_REF_BUFS 32 66 #define MAX_DISP_BUFS_NEW 64 67 #define MAX_FRAMES 16 68 69 #define INVALID_FRAME_NUM 0x0fffffff 70 #define GAP_FRAME_NUM 0x1fffffff 71 72 /** macros for reference picture lists, refIdx to POC mapping */ 73 // 1 extra entry into reference picture lists for refIdx = -1. 74 // this entry is always 0. this saves conditional checks in 75 // FillBs modules. 76 #define POC_LIST_L0_TO_L1_DIFF (( 2*MAX_FRAMES) + 1) 77 #define POC_LIST_L0_TO_L1_DIFF_1 ((MAX_FRAMES) + 1) 78 79 #define FRM_LIST_L0 0 //0 80 #define FRM_LIST_L1 1 * POC_LIST_L0_TO_L1_DIFF//FRM_LIST_L0 + POC_LIST_L0_TO_L1_DIFF //0+33 //(1 * POC_LIST_L0_TO_L1_DIFF) 81 #define TOP_LIST_FLD_L0 2 * POC_LIST_L0_TO_L1_DIFF//FRM_LIST_L1 + POC_LIST_L0_TO_L1_DIFF //0+33+33 //(2 * POC_LIST_L0_TO_L1_DIFF) 82 #define TOP_LIST_FLD_L1 3 * POC_LIST_L0_TO_L1_DIFF//TOP_LIST_FLD_L0 + POC_LIST_L0_TO_L1_DIFF_1 //0+33+33+17 //(3 * POC_LIST_L0_TO_L1_DIFF) 83 #define BOT_LIST_FLD_L0 4 * POC_LIST_L0_TO_L1_DIFF//TOP_LIST_FLD_L1 + POC_LIST_L0_TO_L1_DIFF_1 //0+33+33+17+17 84 #define BOT_LIST_FLD_L1 5 * POC_LIST_L0_TO_L1_DIFF//BOT_LIST_FLD_L0 + POC_LIST_L0_TO_L1_DIFF_1 //0+33+33+17+17+17 85 #define TOTAL_LIST_ENTRIES 6 * POC_LIST_L0_TO_L1_DIFF//BOT_LIST_FLD_L1 + POC_LIST_L0_TO_L1_DIFF_1 //0+33+33+17+17+17+17 86 #define PAD_MV_BANK_ROW 64 87 #define OFFSET_MV_BANK_ROW ((PAD_MV_BANK_ROW)>>1) 88 #define PAD_PUC_CURNNZ 32 89 #define OFFSET_PUC_CURNNZ (PAD_PUC_CURNNZ) 90 #define PAD_MAP_IDX_POC (1) 91 #define OFFSET_MAP_IDX_POC (1) 92 93 #define OFFSET_MAP_IDX_POC (1) 94 95 #define NAL_REF_IDC(nal_first_byte) ((nal_first_byte >> 5) & 0x3) 96 #define NAL_FORBIDDEN_BIT(nal_first_byte) (nal_first_byte>>7) 97 #define NAL_UNIT_TYPE(nal_first_byte) (nal_first_byte & 0x1F) 98 99 #define INT_PIC_TYPE_I (0x00) 100 101 #define YIELD_CNT_THRESHOLD 8 102 103 104 #define OK 0 105 #define END 1 106 #define NOT_OK -1 107 108 /* For 420SP */ 109 #define YUV420SP_FACTOR 2 110 111 112 /** 113 *************************************************************************** 114 * Enum to hold various mem records being request 115 **************************************************************************** 116 */ 117 enum 118 { 119 /** 120 * Codec Object at API level 121 */ 122 MEM_REC_IV_OBJ, 123 124 /** 125 * Codec context 126 */ 127 MEM_REC_CODEC, 128 129 /** 130 * Bitstream buffer which holds emulation prevention removed bytes 131 */ 132 MEM_REC_BITSBUF, 133 134 /** 135 * Buffer to hold coeff data 136 */ 137 MEM_REC_COEFF_DATA, 138 139 /** 140 * Motion vector bank 141 */ 142 MEM_REC_MVBANK, 143 144 /** 145 * Holds mem records passed to the codec. 146 */ 147 MEM_REC_BACKUP, 148 149 /** 150 * Holds SPS 151 */ 152 MEM_REC_SPS, 153 154 /** 155 * Holds PPS 156 */ 157 MEM_REC_PPS, 158 159 /** 160 * Holds Slice Headers 161 */ 162 MEM_REC_SLICE_HDR, 163 164 /** 165 * Holds thread handles 166 */ 167 MEM_REC_THREAD_HANDLE, 168 169 /** 170 * Contains i4_status map indicating parse i4_status per MB basis 171 */ 172 MEM_REC_PARSE_MAP, 173 174 /** 175 * Contains i4_status map indicating processing i4_status per MB basis 176 */ 177 MEM_REC_PROC_MAP, 178 179 /** 180 * Contains slice number info for each MB 181 */ 182 183 MEM_REC_SLICE_NUM_MAP, 184 185 /** 186 * Holds dpb manager context 187 */ 188 MEM_REC_DPB_MGR, 189 190 /** 191 * Holds neighbors' info 192 */ 193 MEM_REC_NEIGHBOR_INFO, 194 195 /** 196 * Holds neighbors' info 197 */ 198 MEM_REC_PRED_INFO, 199 200 201 /** 202 * Holds inter pred inforamation on packed format info 203 */ 204 MEM_REC_PRED_INFO_PKD, 205 /** 206 * Holds neighbors' info 207 */ 208 MEM_REC_MB_INFO, 209 210 /** 211 * Holds deblock Mb info structure frame level) 212 */ 213 MEM_REC_DEBLK_MB_INFO, 214 215 /** 216 * Holds reference picture buffers in non-shared mode 217 */ 218 MEM_REC_REF_PIC, 219 220 /** 221 * Holds some misc intermediate_buffers 222 */ 223 MEM_REC_EXTRA_MEM, 224 225 /** 226 * Holds some misc intermediate_buffers 227 */ 228 MEM_REC_INTERNAL_SCRATCH, 229 230 /** 231 * Holds some misc intermediate_buffers 232 */ 233 MEM_REC_INTERNAL_PERSIST, 234 235 /* holds structures related to picture buffer manager*/ 236 MEM_REC_PIC_BUF_MGR, 237 238 /*holds structure related to MV buffer manager*/ 239 MEM_REC_MV_BUF_MGR, 240 241 /** 242 * Place holder to compute number of memory records. 243 */ 244 MEM_REC_CNT 245 /* Do not add anything below */ 246 }; 247 248 #ifdef DEBLOCK_THREAD 249 #define H264_MUTEX_LOCK(lock) ithread_mutex_lock(lock) 250 #define H264_MUTEX_UNLOCK(lock) ithread_mutex_unlock(lock) 251 #else //DEBLOCK_THREAD 252 #define H264_MUTEX_LOCK(lock) 253 #define H264_MUTEX_UNLOCK(lock) 254 255 #define DEBUG_THREADS_PRINTF(...) 256 #define DEBUG_PERF_PRINTF(...) 257 258 /** Profile Types*/ 259 #define BASE_PROFILE_IDC 66 260 #define MAIN_PROFILE_IDC 77 261 #define EXTENDED_PROFILE_IDC 88 262 #define HIGH_PROFILE_IDC 100 263 264 265 #define MB_SIZE 16 266 #define BLK8x8SIZE 8 267 #define BLK_SIZE 4 268 #define NUM_BLKS_PER_MB 24 269 #define NUM_LUM_BLKS_PER_MB 16 270 #define LUM_BLK 0 271 #define CHROM_BLK 1 272 #define NUM_PELS_IN_MB 64 273 274 /* Level Types */ 275 #define H264_LEVEL_1_0 10 276 #define H264_LEVEL_1_1 11 277 #define H264_LEVEL_1_2 12 278 #define H264_LEVEL_1_3 13 279 #define H264_LEVEL_2_0 20 280 #define H264_LEVEL_2_1 21 281 #define H264_LEVEL_2_2 22 282 #define H264_LEVEL_3_0 30 283 #define H264_LEVEL_3_1 31 284 #define H264_LEVEL_3_2 32 285 #define H264_LEVEL_4_0 40 286 #define H264_LEVEL_4_1 41 287 #define H264_LEVEL_4_2 42 288 #define H264_LEVEL_5_0 50 289 #define H264_LEVEL_5_1 51 290 291 #define MAX_MBS_LEVEL_51 36864 292 #define MAX_MBS_LEVEL_50 22080 293 #define MAX_MBS_LEVEL_42 8704 294 #define MAX_MBS_LEVEL_41 8192 295 #define MAX_MBS_LEVEL_40 8192 296 #define MAX_MBS_LEVEL_32 5120 297 #define MAX_MBS_LEVEL_31 3600 298 #define MAX_MBS_LEVEL_30 1620 299 #define MAX_MBS_LEVEL_22 1620 300 #define MAX_MBS_LEVEL_21 792 301 #define MAX_MBS_LEVEL_20 396 302 #define MAX_MBS_LEVEL_13 396 303 #define MAX_MBS_LEVEL_12 396 304 #define MAX_MBS_LEVEL_11 396 305 #define MAX_MBS_LEVEL_10 99 306 307 /** NAL Types */ 308 #define SLICE_NAL 1 309 #define SLICE_DATA_PARTITION_A_NAL 2 310 #define SLICE_DATA_PARTITION_B_NAL 3 311 #define SLICE_DATA_PARTITION_C_NAL 4 312 #define IDR_SLICE_NAL 5 313 #define SEI_NAL 6 314 #define SEQ_PARAM_NAL 7 315 #define PIC_PARAM_NAL 8 316 #define ACCESS_UNIT_DELIMITER_RBSP 9 317 #define END_OF_SEQ_RBSP 10 318 #define END_OF_STREAM_RBSP 11 319 #define FILLER_DATA_NAL 12 320 321 /** Entropy coding modes */ 322 #define CAVLC 0 323 #define CABAC 1 324 325 /** Picture Types */ 326 #define I_PIC 0 327 #define IP_PIC 1 328 #define IPB_PIC 2 329 #define SI_PIC 3 330 #define SIP_PIC 4 331 #define ISI_PIC 5 332 #define ISI_PSP_PIC 6 333 #define ALL_PIC 7 334 335 /* Frame or field picture type */ 336 #define FRM_PIC 0x00 337 #define TOP_FLD 0x01 338 #define BOT_FLD 0x02 339 #define COMP_FLD_PAIR 0x03 /* TOP_FLD | BOT_FLD */ 340 #define AFRM_PIC 0x04 341 #define TOP_REF 0x08 342 #define BOT_REF 0x10 343 #define PIC_MASK 0x03 344 #define NON_EXISTING 0xff 345 346 /* field picture type for display */ 347 #define DISP_TOP_FLD 0x00 348 #define DISP_BOT_FLD 0x01 349 350 /** Slice Types */ 351 #define P_SLICE 0 352 #define B_SLICE 1 353 #define I_SLICE 2 354 #define SP_SLICE 3 355 #define SI_SLICE 4 356 357 /* Definition for picture skip */ 358 #define SKIP_NONE (0x0) 359 #define I_SLC_BIT (0x1) 360 #define P_SLC_BIT (0x2) 361 #define B_SLC_BIT (0x4) 362 363 /** Macros used for Deblocking */ 364 #define D_INTER_MB 0 365 #define D_INTRA_MB 1 366 #define D_PRED_NON_16x16 2 367 #define D_B_SLICE 4 368 #define D_B_SUBMB 6 //D_B_SLICE | D_PRED_NON_16x16 | D_INTER_MB 369 #define D_FLD_MB 0x80 370 371 /** Macros for Cabac checks */ 372 /** MbType */ 373 /** |x|x|I_PCM|SKIP| 374 |S|Inter/Intra|P/B|NON-BD16x16/BD16x16,I16x16/I4x4| */ 375 #define CAB_INTRA 0x00 /* 0000 00xx */ 376 #define CAB_INTER 0x04 /* 0000 01xx */ 377 #define CAB_I4x4 0x00 /* 0000 00x0 */ 378 #define CAB_I16x16 0x01 /* 0000 00x1 */ 379 #define CAB_BD16x16 0x04 /* 0000 0100 */ 380 #define CAB_NON_BD16x16 0x05 /* 0000 0101 */ 381 #define CAB_P 0x07 /* 0000 0111 */ 382 #define CAB_SI4x4 0x08 /* 0000 10x0 */ 383 #define CAB_SI16x16 0x09 /* 0000 10x1 */ 384 #define CAB_SKIP_MASK 0x10 /* 0001 0000 */ 385 #define CAB_SKIP 0x10 /* 0001 0000 */ 386 #define CAB_P_SKIP 0x16 /* 0001 x11x */ 387 #define CAB_B_SKIP 0x14 /* 0001 x100 */ 388 #define CAB_BD16x16_MASK 0x07 /* 0000 0111 */ 389 #define CAB_INTRA_MASK 0x04 /* 0000 0100 */ 390 #define CAB_I_PCM 0x20 /* 001x xxxx */ 391 392 /**< Binarization types for CABAC */ 393 /* |x|x|x|x|MSB_FIRST_FLC|FLC|TUNARY|UNARY| */ 394 #define UNARY 1 395 #define TUNARY 2 396 #define FLC 4 397 #define MSB_FIRST_FLC 12 398 399 /** Macroblock Types */ 400 #define I_4x4_MB 0 401 #define I_16x16_MB 1 402 #define P_MB 2 403 #define B_MB 3 404 #define SI_MB 4 405 #define SP_MB 5 406 #define I_PCM_MB 6 407 408 #define SI4x4_MB 0xFF 409 410 /** Intra luma 16x16 and chroma 8x8 prediction modes */ 411 #define NUM_INTRA_PRED_MODES 4 412 #define VERT 0 413 #define HORIZ 1 414 #define DC 2 415 #define PLANE 3 416 #define NOT_VALID -1 417 #define DC_DC_DC_DC 0x02020202 /*packed 4 bytes used in Decode Intra Mb*/ 418 419 /** Intra luma 4x4 prediction modes */ 420 #define NUM_INTRA4x4_PRED_MODES 9 421 422 /** VERT, HORIZ, DC are applicable to 4x4 as well */ 423 /** D - Down; U - Up; L - Left; R - Right */ 424 #define DIAG_DL 3 425 #define DIAG_DR 4 426 #define VERT_R 5 427 #define HORIZ_D 6 428 #define VERT_L 7 429 #define HORIZ_U 8 430 431 /** P_MB prediction modes */ 432 #define NUM_INTER_MB_PRED_MODES 5 433 #define PRED_16x16 0 434 #define PRED_16x8 1 435 #define PRED_8x16 2 436 #define PRED_8x8 3 437 #define PRED_8x8R0 4 438 #define MAGIC_16x16 5 439 #define MB_SKIP 255 440 441 /* P_MB submb modes */ 442 #define P_L0_8x8 0 443 #define P_L0_8x4 1 444 #define P_L0_4x8 2 445 #define P_L0_4x4 3 446 447 /* B_MB submb modes */ 448 #define B_DIRECT_8x8 0 449 #define B_L0_8x8 1 450 #define B_L1_8x8 2 451 #define B_BI_8x8 3 452 #define B_L0_8x4 4 453 #define B_L0_4x8 5 454 #define B_L1_8x4 6 455 #define B_L1_4x8 7 456 #define B_BI_8x4 8 457 #define B_BI_4x8 9 458 #define B_L0_4x4 10 459 #define B_L1_4x4 11 460 #define B_BI_4x4 12 461 462 /** B_MB prediction modes */ 463 #define B_8x8 22 464 #define PRED_INVALID -1 465 #define B_DIRECT 0 466 #define PRED_L0 1 467 #define PRED_L1 2 468 #define BI_PRED 3 469 #define B_DIRECT_BI_PRED 23 470 #define B_DIRECT_PRED_L0 24 471 #define B_DIRECT_PRED_L1 25 472 #define B_DIRECT_SPATIAL 26 473 474 #define B_DIRECT8x8_BI_PRED 13 475 #define B_DIRECT8x8_PRED_L0 14 476 #define B_DIRECT8x8_PRED_L1 15 477 478 #define ONE_TO_ONE 0 479 #define FRM_TO_FLD 1 480 #define FLD_TO_FRM 2 481 482 /** Inter Sub MB Pred modes */ 483 #define NUM_INTER_SUBMB_PRED_MODES 4 484 #define SUBMB_8x8 0 485 #define SUBMB_8x4 1 486 #define SUBMB_4x8 2 487 #define SUBMB_4x4 3 488 489 /** Coded Block Pattern - Chroma */ 490 #define CBPC_ALLZERO 0 491 #define CBPC_ACZERO 1 492 #define CBPC_NONZERO 2 493 494 /** Index for accessing the left MB in the MV predictor array */ 495 #define LEFT 0 496 /** Index for accessing the top MB in the MV predictor array */ 497 #define TOP 1 498 /** Index for accessing the top right MB in the MV predictor array */ 499 #define TOP_R 2 500 /** Index for accessing the top Left MB in the MV predictor array */ 501 #define TOP_L 3 502 503 /** Maximum number of Sequence Parameter sets */ 504 #define MAX_NUM_SEQ_PARAMS 32 505 506 /** Maximum number of Picture Parameter sets */ 507 #define MAX_NUM_PIC_PARAMS 256 508 509 #define MASK_ERR_SEQ_SET_ID (0xFFFFFFE0) 510 #define MASK_ERR_PIC_SET_ID (0xFFFFFF00) 511 512 #define MAX_PIC_ORDER_CNT_TYPE 2 513 514 #define MAX_BITS_IN_FRAME_NUM 16 515 #define MAX_BITS_IN_POC_LSB 16 516 517 #define H264_MAX_REF_PICS 16 518 #define H264_MAX_REF_IDX 32 519 #define MAX_WEIGHT_BIPRED_IDC 2 520 #define MAX_CABAC_INIT_IDC 2 521 522 #define H264_DEFAULT_NUM_CORES 1 523 #define DEFAULT_SEPARATE_PARSE (H264_DEFAULT_NUM_CORES == 2)? 1 :0 524 525 /** Maximum number of Slice groups */ 526 #define MAX_NUM_SLICE_GROUPS 8 527 #define MAX_NUM_REF_FRAMES_OFFSET 255 528 529 /** Deblocking modes for a slice */ 530 #define SLICE_BOUNDARY_DBLK_DISABLED 2 531 #define DBLK_DISABLED 1 532 #define DBLK_ENABLED 0 533 #define MIN_DBLK_FIL_OFF -12 534 #define MAX_DBLK_FIL_OFF 12 535 536 /** Width of the predictor buffers used for MC */ 537 #define MB_SIZE 16 538 #define BLK8x8SIZE 8 539 #define BLK_SIZE 4 540 #define NUM_BLKS_PER_MB 24 541 #define NUM_LUM_BLKS_PER_MB 16 542 543 #define SUB_BLK_WIDTH 4 544 #define SUB_SUB_BLK_SIZE 4 /* 2x2 pixel i4_size */ 545 #define SUB_BLK_SIZE ((SUB_BLK_WIDTH) * (SUB_BLK_WIDTH)) 546 #define MB_LUM_SIZE 256 547 #define MB_CHROM_SIZE 64 548 549 /**< Width to pad the luminance frame buff */ 550 /**< Height to pad the luminance frame buff */ 551 /**< Width to pad the chrominance frame buff */ 552 /**< Height to pad the chrominance frame buff */ 553 554 #define PAD_LEN_Y_H 32 555 #define PAD_LEN_Y_V 20 556 #define PAD_LEN_UV_H 16 557 #define PAD_LEN_UV_V 8 558 559 #define PAD_MV_BANK_ROW 64 560 561 /**< Maimum u4_ofst by which the Mvs could point outside the frame buffers 562 horizontally in the left and vertically in the top direction */ 563 #define MAX_OFFSET_OUTSIDE_X_FRM -20 564 #define MAX_OFFSET_OUTSIDE_Y_FRM -20 565 #define MAX_OFFSET_OUTSIDE_UV_FRM -8 566 567 /** UVLC parsing macros */ 568 #define UEV 1 569 #define SEV 2 570 #define TEV 3 571 572 /** Defines for Boolean values */ 573 #ifndef TRUE 574 #define TRUE 1 575 #define FALSE 0 576 #endif 577 578 #define UNUSED_FOR_REF 0 579 #define IS_SHORT_TERM 1 580 #define IS_LONG_TERM 2 581 582 /** Defines for which field gets displayed first */ 583 #define MAX_FRAMES 16 584 #define INVALID_FRAME_NUM 0x0fffffff 585 #define DO_NOT_DISP 254 586 #define DISP_FLD_FIRST_UNDEF 0 587 #define DISP_TOP_FLD_FIRST 1 588 #define DISP_BOT_FLD_FIRST 2 589 590 /** Misc error resilience requirements*/ 591 #define MASK_LOG2_WEIGHT_DENOM 0xFFFFFFF8 592 #define MASK_PRED_WEIGHT_OFFSET 0xFFFFFF00 593 #define MAX_REDUNDANT_PIC_CNT 127 594 595 596 597 #endif //DEBLOCK_THREAD 598 599 #define NUM_COEFFS_IN_4x4BLK 16 600 601 602 #define MEMSET_16BYTES(pu4_start,value) \ 603 { \ 604 memset(pu4_start,value,16); \ 605 } 606 607 #define MEMCPY_16BYTES(dst,src) \ 608 { \ 609 memcpy(dst,src,16); \ 610 } 611 612 613 #endif /*_IH264D_DEFS_H_*/ 614