blob: 9c84be9a391fb6c91510ffcd2434cfbe887db251 [file] [log] [blame]
Hamsalekha S8d3d3032015-03-13 21:24:58 +05301/******************************************************************************
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/**
21*******************************************************************************
22* @file
23* ih264_defs.h
24*
25* @brief
26* Definitions used in the codec
27*
28* @author
29* Ittiam
30*
31*
32* @remarks
33* None
34*
35*******************************************************************************
36*/
37
38#ifndef IH264_DEFS_H_
39#define IH264_DEFS_H_
40
41/*****************************************************************************/
42/* Enums */
43/*****************************************************************************/
44
45
46/*****************************************************************************/
47/* Profile and Levels */
48/*****************************************************************************/
49
50/**
51******************************************************************************
52 * @enum PROFILE_IDC
53 * @brief Defines the set of possible profiles
54******************************************************************************
55*/
56enum
57{
58 IH264_PROFILE_BASELINE = 66,
59 IH264_PROFILE_MAIN = 77,
60 IH264_PROFILE_EXTENDED = 88,
61 IH264_PROFILE_HIGH = 100,
62 IH264_PROFILE_HIGH10 = 110,
63 IH264_PROFILE_HIGH422 = 122,
64 IH264_PROFILE_HIGH444 = 144,
65};
66
67/**
68******************************************************************************
69 * @enum LEVEL_IDC
70 * @brief Defines the set of possible levels
71******************************************************************************
72*/
73typedef enum
74{
75 IH264_LEVEL_10 = 10,
76 IH264_LEVEL_1B = 9,
77 IH264_LEVEL_11 = 11,
78 IH264_LEVEL_12 = 12,
79 IH264_LEVEL_13 = 13,
80 IH264_LEVEL_20 = 20,
81 IH264_LEVEL_21 = 21,
82 IH264_LEVEL_22 = 22,
83 IH264_LEVEL_30 = 30,
84 IH264_LEVEL_31 = 31,
85 IH264_LEVEL_32 = 32,
86 IH264_LEVEL_40 = 40,
87 IH264_LEVEL_41 = 41,
88 IH264_LEVEL_42 = 42,
89 IH264_LEVEL_50 = 50,
90 IH264_LEVEL_51 = 51,
91}IH264_LEVEL_T;
92
93
94/**
95******************************************************************************
96 * @enum PIC TYPES
97 * @brief Defines the set of possible picture type - not signaled in bitstream
98******************************************************************************
99*/
100typedef enum
101{
102 PIC_NA = 0x7FFFFFFF,
103 PIC_IDR = 0,
104 PIC_I = 1,
105 PIC_P = 2,
106 PIC_B = 3,
107 PIC_P_NONREF = 4,
108 PIC_B_NONREF = 5,
109 PIC_MAX,
110}PIC_TYPE_T;
111
112/**
113******************************************************************************
114 * @enum FRAME-FIELD types
115 * @brief Defines the set of possible field types.
116******************************************************************************
117*/
118enum
119{
120 TOP_FIELD,
121 BOTTOM_FIELD,
122 FRAME,
123};
124
125/**
126******************************************************************************
127 * @enum SLICE TYPES
128 * @brief Defines the set of possible SLICE TYPES
129******************************************************************************
130*/
131enum
132{
133 PSLICE = 0,
134 BSLICE = 1,
135 ISLICE = 2,
136 SPSLICE = 3,
137 SISLICE = 4,
138 MAXSLICE_TYPE,
139};
140
141/**
142******************************************************************************
143 * @enum NAL_UNIT_TYPE
144 * @brief Defines the set of possible nal unit types
145******************************************************************************
146*/
147enum
148{
149 NAL_UNSPEC_0 = 0,
150 NAL_SLICE_NON_IDR = 1,
151 NAL_SLICE_DPA = 2,
152 NAL_SLICE_DPB = 3,
153 NAL_SLICE_DPC = 4,
154 NAL_SLICE_IDR = 5,
155 NAL_SEI = 6,
156 NAL_SPS = 7,
157 NAL_PPS = 8,
158 NAL_AUD = 9,
159 NAL_EOSEQ = 10,
160 NAL_EOSTR = 11,
161 NAL_FILLER = 12,
162 NAL_SPSE = 13,
163 NAL_RES_18 = 14,
164 NAL_AUX_PIC = 19,
165 NAL_RES_23 = 20,
166 NAL_UNSPEC_31 = 24,
167};
168
169/**
170******************************************************************************
171 * @enum CHROMA_FORMAT_IDC
172 * @brief Defines the set of possible chroma formats
173 * Note Chorma format Do not change enum values
174******************************************************************************
175*/
176enum
177{
178 CHROMA_FMT_IDC_MONOCHROME = 0,
179 CHROMA_FMT_IDC_YUV420 = 1,
180 CHROMA_FMT_IDC_YUV422 = 2,
181 CHROMA_FMT_IDC_YUV444 = 3,
182 CHROMA_FMT_IDC_YUV444_PLANES = 4,
183};
184
185
186/**
187******************************************************************************
188 * @enum MBMODES_I16x16
189 * @brief Defines the set of possible intra 16x16 mb modes
190******************************************************************************
191*/
192typedef enum
193{
194 VERT_I16x16 = 0,
195 HORZ_I16x16 = 1,
196 DC_I16x16 = 2,
197 PLANE_I16x16 = 3,
198 MAX_I16x16 = 4,
199}MBMODES_I16x16;
200
201/**
202******************************************************************************
203 * @enum MBMODES_I4x4
204 * @brief Defines the set of possible intra 4x4 mb modes
205******************************************************************************
206*/
207typedef enum
208{
209 VERT_I4x4 = 0,
210 HORZ_I4x4 = 1,
211 DC_I4x4 = 2,
212 DIAG_DL_I4x4 = 3,
213 DIAG_DR_I4x4 = 4,
214 VERT_R_I4x4 = 5,
215 HORZ_D_I4x4 = 6,
216 VERT_L_I4x4 = 7,
217 HORZ_U_I4x4 = 8,
218 MAX_I4x4 = 9,
219}MBMODES_I4x4;
220
221/**
222******************************************************************************
223 * @enum MBMODES_I8x8
224 * @brief Defines the set of possible intra 8x8 mb modes
225******************************************************************************
226*/
227typedef enum
228{
229 VERT_I8x8 = 0,
230 HORZ_I8x8 = 1,
231 DC_I8x8 = 2,
232 DIAG_DL_I8x8 = 3,
233 DIAG_DR_I8x8 = 4,
234 VERT_R_I8x8 = 5,
235 HORZ_D_I8x8 = 6,
236 VERT_L_I8x8 = 7,
237 HORZ_U_I8x8 = 8,
238 MAX_I8x8 = 9,
239}MBMODES_I8x8;
240
241/**
242******************************************************************************
243 * @enum MBMODES_CHROMA_I8x8 (Chroma)
244 * @brief Defines the set of possible intra 8x8 mb modes for chroma
245******************************************************************************
246*/
247typedef enum
248{
249 DC_CH_I8x8 = 0,
250 HORZ_CH_I8x8 = 1,
251 VERT_CH_I8x8 = 2,
252 PLANE_CH_I8x8 = 3,
253 MAX_CH_I8x8 = 4,
254}MBMODES_CHROMA_I8x8;
255
256/**
257******************************************************************************
258 * @enum MBTYPES
259 * @brief Defines the set of possible macro block types
260******************************************************************************
261*/
262typedef enum
263{
264 I16x16 = 0,
265 I4x4 = 1,
266 I8x8 = 2,
267 P16x16 = 3,
268 P16x8 = 4,
269 P8x16 = 5,
270 P8x8 = 6,
271 PSKIP = 7,
272 IPCM = 8,
Harinarayanan K K134291e2015-06-18 16:03:38 +0530273 B16x16 = 9,
274 BSKIP = 10,
275 BDIRECT = 11,
Hamsalekha S8d3d3032015-03-13 21:24:58 +0530276 MAX_MBTYPES,
277}MBTYPES_T;
278
279/* Prediction list */
280/* Do not change enum values */
281enum
282{
283 PRED_L0 = 0,
284 PRED_L1 = 1,
285 PRED_BI = 2
286};
287
288
289/**
290******************************************************************************
291 * @enum ENTROPY_BLK_TYPE
292 * @brief Defines the nature of blocks employed in entropy coding
293******************************************************************************
294*/
295typedef enum
296{
297 ENTROPY_BLK_INVALID = -1,
298 CAVLC_LUMA_4x4_DC = 0,
299 CAVLC_LUMA_4x4_AC = 1,
300 CAVLC_LUMA_4x4 = 2,
301 CAVLC_CHROMA_4x4_DC = 3,
302 CAVLC_CHROMA_4x4_AC = 4,
303} ENTROPY_BLK_TYPE;
304
305/**
306******************************************************************************
307 * @enum ENTROPY_MODE
308 * @brief Entropy coding modes
309******************************************************************************
310*/
311typedef enum
312{
313 CAVLC = 0,
314 CABAC = 1,
315} ENTROPY_MODE;
316
317/**
318******************************************************************************
319 * @enum COMPONENT_TYPE
320 * @brief components Y, U & V
321******************************************************************************
322*/
323typedef enum
324{
325 Y,
326 U,
327 V,
328} COMPONENT_TYPE;
329
330
331/**
332******************************************************************************
333 * @enum MBPART_PREDMODE_T
Hamsalekha Scaab4fe2015-05-07 16:38:07 +0530334 * @brief MbPartps_pred_mode_ctxt Table 7-11 to 7-14
Hamsalekha S8d3d3032015-03-13 21:24:58 +0530335******************************************************************************
336*/
337typedef enum
338{
339 MBPART_NA,
340 MBPART_I4x4,
341 MBPART_I8x8,
342 MBPART_I16x16,
343 MBPART_L0,
344 MBPART_L1,
345 MBPART_BI,
346 MBPART_DIRECT,
347 MBPART_IPCM,
348}MBPART_PREDMODE_T;
349
350
351typedef enum
352{
353 I_NxN,
354 I_16x16_0_0_0,
355 I_16x16_1_0_0,
356 I_16x16_2_0_0,
357 I_16x16_3_0_0,
358 I_16x16_0_1_0,
359 I_16x16_1_1_0,
360 I_16x16_2_1_0,
361 I_16x16_3_1_0,
362 I_16x16_0_2_0,
363 I_16x16_1_2_0,
364 I_16x16_2_2_0,
365 I_16x16_3_2_0,
366 I_16x16_0_0_1,
367 I_16x16_1_0_1,
368 I_16x16_2_0_1,
369 I_16x16_3_0_1,
370 I_16x16_0_1_1,
371 I_16x16_1_1_1,
372 I_16x16_2_1_1,
373 I_16x16_3_1_1,
374 I_16x16_0_2_1,
375 I_16x16_1_2_1,
376 I_16x16_2_2_1,
377 I_16x16_3_2_1,
378 I_PCM,
379}MBTYPE_ISLICE_T;
380
381typedef enum
382{
383 P_L0_16x16,
384 P_L0_L0_16x8,
385 P_L0_L0_8x16,
386 P_8x8,
387 P_8x8REF0,
388 P_SKIP
389}MBTYPE_PSLICE_T;
390
391typedef enum
392{
393 B_DIRECT_16x16,
394 B_L0_16x16,
395 B_L1_16x16,
396 B_BI_16x16,
397 B_L0_L0_16x8,
398 B_L0_L0_8x16,
399 B_L1_L1_16x8,
400 B_L1_L1_8x16,
401 B_L0_L1_16x8,
402 B_L0_L1_8x16,
403 B_L1_L0_16x8,
404 B_L1_L0_8x16,
405 B_L0_BI_16x8,
406 B_L0_BI_8x16,
407 B_L1_BI_16x8,
408 B_L1_BI_8x16,
409 B_BI_L0_16x8,
410 B_BI_L0_8x16,
411 B_BI_L1_16x8,
412 B_BI_L1_8x16,
413 B_BI_BI_16x8,
414 B_BI_BI_8x16,
415 B_8x8,
416 B_SKIP,
417}MBTYPE_BSLICE_T;
418
419
420typedef enum
421{
422 P_L0_8x8,
423 P_L0_8x4,
424 P_L0_4x8,
425 P_L0_4x4,
426}SUBMBTYPE_PSLICE_T;
427
428typedef enum
429{
430 B_DIRECT_8x8,
431 B_L0_8x8,
432 B_L1_8x8,
433 B_BI_8x8,
434 B_L0_8x4,
435 B_L0_4x8,
436 B_L1_8x4,
437 B_L1_4x8,
438 B_BI_8x4,
439 B_BI_4x8,
440 B_L0_4x4,
441 B_L1_4x4,
442 B_BI_4x4,
443}SUBMBTYPE_BSLICE_T;
444
445/**
446 * DC Mode pattern for 4 4x4 sub blocks in an MB row
447 */
448#define DC_I16X16_MB_ROW (DC_I16x16 << 24) | (DC_I16x16 << 16) | \
449 (DC_I16x16 << 8) | DC_I16x16
450
451
452
453/*****************************************************************************/
454/* Constant Macros */
455/*****************************************************************************/
456
457/*****************************************************************************/
458/* Reference frame defs */
459/*****************************************************************************/
460/* Maximum DPB size */
461#define MAX_DPB_SIZE 16
462
463/* Maximum mmco commands in slice header */
464#define MAX_MMCO_COMMANDS 32
465
466/* Maximum reference reorder idc */
467#define MAX_MODICATION_IDC 32
468
469/*****************************************************************************/
470/* SPS restrictions */
471/*****************************************************************************/
472
473/* Number of SPS allowed */
474/* An extra buffer is allocated to write the parsed data
475 * It is copied to the appropriate location later */
476#define MAX_SPS_CNT (32 + 1)
477
478/* Maximum long term reference pics */
479#define MAX_LTREF_PICS_SPS 16
480
481/* Maximum short term reference pics */
482#define MAX_STREF_PICS_SPS 64
483
484
485/*****************************************************************************/
486/* PPS restrictions */
487/*****************************************************************************/
488
489/* Number of PPS allowed */
490/* An extra buffer is allocated to write the parsed data
491 * It is copied to the appropriate location later */
492#define MAX_PPS_CNT (256 + 1)
493
494/*****************************************************************************/
495/* Macro definitions for sizes of MB, PU, TU, CU */
496/*****************************************************************************/
497#define MB_SIZE 16
498#define BLK8x8SIZE 8
499#define BLK_SIZE 4
500
501
502/* TU Size Range */
503#define MAX_TU_SIZE 8
504#define MIN_TU_SIZE 4
505
506/* Max Transform Size */
507#define MAX_TRANS_SIZE (MAX_TU_SIZE*MAX_TU_SIZE)
508
509/* PU Size Range */
510#define MAX_PU_SIZE 16
511#define MIN_PU_SIZE 4
512
513/* Number of max TU in a MB row */
514#define MAX_TU_IN_MB_ROW ((MB_SIZE / MIN_TU_SIZE))
515
516/* Number of max PU in a CTb row */
517#define MAX_PU_IN_MB_ROW ((MB_SIZE / MIN_PU_SIZE))
518
519
520/* Number of max PU in a MB */
521/*****************************************************************************/
522/* Note though for 64 x 64 MB, Max PU in MB is 128, in order to store */
523/* intra pred info, 256 entries are needed */
524/*****************************************************************************/
525#define MAX_PU_IN_MB ((MB_SIZE / MIN_PU_SIZE) * \
526 (MB_SIZE / MIN_PU_SIZE))
527
528/* Number of max TU in a MB */
529#define MAX_TU_IN_MB ((MB_SIZE / MIN_TU_SIZE) * \
530 (MB_SIZE / MIN_TU_SIZE))
531
532
533
534/**
535 * Maximum transform depths
536 */
537#define MAX_TRAFO_DEPTH 5
538
539#define MAX_DC_4x4_SUBBLK_LUMA 1
540#define MAX_AC_4x4_SUBBLK_LUMA 16
541#define MAX_DC_4x4_SUBBLK_CHROMA 2
542#define MAX_AC_4x4_SUBBLK_CHROMA 8
543
544#define MAX_4x4_SUBBLKS (MAX_DC_4x4_SUBBLK_LUMA + MAX_DC_4x4_SUBBLK_CHROMA +\
545 MAX_AC_4x4_SUBBLK_LUMA + MAX_AC_4x4_SUBBLK_CHROMA)
546
547/* Max number of deblocking edges */
548#define MAX_VERT_DEBLK_EDGES ((MB_SIZE/8) * (MB_SIZE/4))
549#define MAX_HORZ_DEBLK_EDGES ((MB_SIZE/4) * (MB_SIZE/8))
550
551/* Qp can not change below 8x8 level */
552#define MAX_DEBLK_QP_CNT ((MB_SIZE/8) * (MB_SIZE/8))
553
554/*****************************************************************************/
555/* Parsing related macros */
556/*****************************************************************************/
557#define SUBBLK_COEFF_CNT 16
558
559/* Quant and Trans defs */
560
561/*****************************************************************************/
562/* Sizes for Transform functions */
563/*****************************************************************************/
564#define TRANS_SIZE_4 4
565#define TRANS_SIZE_8 8
566#define TRANS_SIZE_16 16
567#define TRANS_SIZE_32 32
568
569
570#define IT_SHIFT_STAGE_1 7
571#define IT_SHIFT_STAGE_2 12
572
573/**
574 * @breif Maximum transform dynamic range (excluding sign bit)
575 */
576#define MAX_TR_DYNAMIC_RANGE 15
577
578/**
579 * @brief Q(QP%6) * IQ(QP%6) = 2^20
580 */
581#define QUANT_IQUANT_SHIFT 20
582
583/**
584 * @breif Q factor for Qp%6 multiplication
585 */
586#define QUANT_SHIFT 14
587
588/**
589 * @breif Q shift factor for flat rescale matrix weights
590 */
591#define FLAT_RESCALE_MAT_Q_SHIFT 11
592
593/**
594 * @breif Scaling matrix is represented in Q15 format
595 */
596#define SCALING_Q_SHIFT 15
597
598/**
599 * @brief rounding factor for quantization represented in Q9 format
600 */
601#define QUANT_ROUND_FACTOR_Q 9
602
603/**
604 * @brief Minimum qp supported in H264 spec
605 */
606#define MIN_H264_QP 0
607
608/**
609 * @brief Maximum qp supported in H264 spec
610 */
611#define MAX_H264_QP 51
612
613/**
Harish Mahendrakar7befa932019-07-02 14:29:52 -0700614 * @brief Minimum delta scale supported in H264 spec
615 */
616#define MIN_H264_DELTA_SCALE (-128)
617
618/**
619 * @brief Maximum delta scale supported in H264 spec
620 */
621#define MAX_H264_DELTA_SCALE 127
622
623/**
Hamsalekha S8d3d3032015-03-13 21:24:58 +0530624 * @breif Total number of transform sizes
625 * used for sizeID while getting scale matrix
626 */
627#define NUM_UNIQUE_TRANS_SIZE 4
628
629/**
630 * @breif Maximum number of bits in frameNumber signaling
631 */
632#define MAX_BITS_IN_FRAME_NUM 16
633
634/**
635 * @breif Maximum number of bits in POC LSB signaling
636 */
637#define MAX_BITS_IN_POC_LSB 16
638
639
640/**
641 * @breif Maximum PIC Order Count type
642 */
643#define MAX_PIC_ORDER_COUNT_TYPE 2
644
645
646/**
647 * @breif Maximum Weighted bipred idc
648 */
649#define MAX_WEIGHT_BIPRED_IDC 2
650
651/*****************************************************************************/
652/* Number of scaling matrices for each transform size */
653/*****************************************************************************/
654#define SCALE_MAT_CNT_TRANS_SIZE_4 6
655#define SCALE_MAT_CNT_TRANS_SIZE_8 6
656#define SCALE_MAT_CNT_TRANS_SIZE_16 6
657#define SCALE_MAT_CNT_TRANS_SIZE_32 2
658
659/* Maximum number of scale matrices for a given transform size */
660#define SCALE_MAT_CNT_MAX_PER_TRANS_SIZE 6
661
662/* Total number of scale matrices */
663#define TOTAL_SCALE_MAT_COUNT (SCALE_MAT_CNT_TRANS_SIZE_4 + \
664 SCALE_MAT_CNT_TRANS_SIZE_8 + \
665 SCALE_MAT_CNT_TRANS_SIZE_16 + \
666 SCALE_MAT_CNT_TRANS_SIZE_32)
667
668
669/*****************************************************************************/
670/* Intra pred Macros */
671/*****************************************************************************/
672/** Planar Intra prediction mode */
673#define INTRA_PLANAR 0
674
675/** DC Intra prediction mode */
676#define INTRA_DC 1
677
678/** Gives angular mode for intra prediction */
679#define INTRA_ANGULAR(x) (x)
680
681/** Following is used to signal no intra prediction in case of pcm blocks
682 */
683#define INTRA_PRED_NONE 63
684
685
686/** Following is used to signal no intra prediction is needed for first three
687 * 4x4 luma blocks in case of 4x4 TU sizes
688 * Also used in pcm cases
689 */
690#define INTRA_PRED_CHROMA_IDX_NONE 7
691
692
693/**
694******************************************************************************
695 * @brief neighbor availability masks
696******************************************************************************
697 */
698#define LEFT_MB_AVAILABLE_MASK 0x01
699#define TOP_LEFT_MB_AVAILABLE_MASK 0x02
700#define TOP_MB_AVAILABLE_MASK 0x04
701#define TOP_RIGHT_MB_AVAILABLE_MASK 0x08
702
Chamarthi Kishoread2eaf82019-10-01 11:59:43 +0530703/**
704******************************************************************************
705 * @brief SEI macros
706******************************************************************************
707 */
708/*
709 * @brief specifies the number of colour primary components of the mastering display
710 */
711#define NUM_SEI_MDCV_PRIMARIES 3
712
713/*
714 * @brief specifies the number of colour primary components of the nominal content colour volume
715 */
716#define NUM_SEI_CCV_PRIMARIES 3
717
718#define DISPLAY_PRIMARIES_X_UPPER_LIMIT 37000
719#define DISPLAY_PRIMARIES_X_LOWER_LIMIT 5
720#define DISPLAY_PRIMARIES_X_DIVISION_FACTOR 5
721
722#define DISPLAY_PRIMARIES_Y_UPPER_LIMIT 42000
723#define DISPLAY_PRIMARIES_Y_LOWER_LIMIT 5
724#define DISPLAY_PRIMARIES_Y_DIVISION_FACTOR 5
725
726#define WHITE_POINT_X_UPPER_LIMIT 37000
727#define WHITE_POINT_X_LOWER_LIMIT 5
728#define WHITE_POINT_X_DIVISION_FACTOR 5
729
730#define WHITE_POINT_Y_UPPER_LIMIT 42000
731#define WHITE_POINT_Y_LOWER_LIMIT 5
732#define WHITE_POINT_Y_DIVISION_FACTOR 5
733
734#define MAX_DISPLAY_MASTERING_LUMINANCE_UPPER_LIMIT 100000000
735#define MAX_DISPLAY_MASTERING_LUMINANCE_LOWER_LIMIT 50000
736#define MAX_DISPLAY_MASTERING_LUMINANCE_DIVISION_FACTOR 10000
737
738#define MIN_DISPLAY_MASTERING_LUMINANCE_UPPER_LIMIT 50000
739#define MIN_DISPLAY_MASTERING_LUMINANCE_LOWER_LIMIT 1
740
741#define AMBIENT_LIGHT_X_UPPER_LIMIT 50000
742#define AMBIENT_LIGHT_Y_UPPER_LIMIT 50000
743
744#define CCV_PRIMARIES_X_UPPER_LIMIT 5000000
745#define CCV_PRIMARIES_X_LOWER_LIMIT -5000000
746#define CCV_PRIMARIES_Y_UPPER_LIMIT 5000000
747#define CCV_PRIMARIES_Y_LOWER_LIMIT -5000000
748
Hamsalekha S8d3d3032015-03-13 21:24:58 +0530749#endif /* IH264_DEFS_H_ */