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