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