• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2011 Intel Corporation. All Rights Reserved.
3  * Copyright (c) Imagination Technologies Limited, UK
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a
6  * copy of this software and associated documentation files (the
7  * "Software"), to deal in the Software without restriction, including
8  * without limitation the rights to use, copy, modify, merge, publish,
9  * distribute, sub license, and/or sell copies of the Software, and to
10  * permit persons to whom the Software is furnished to do so, subject to
11  * the following conditions:
12  *
13  * The above copyright notice and this permission notice (including the
14  * next paragraph) shall be included in all copies or substantial portions
15  * of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
20  * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
21  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24  *
25  * Authors:
26  *    Elaine Wang <elaine.wang@intel.com>
27  *    Zeng Li <zeng.li@intel.com>
28  *
29  */
30 
31 /*
32  * Description  DMA code for mtx Platform     : Generic
33  */
34 
35 #ifndef _PNW_HOSTHEADER_H_
36 #define _PNW_HOSTHEADER_H_
37 
38 
39 #include "img_types.h"
40 
41 /* Structure contains QP parameters, used with the DoHeader() routine */
42 typedef struct {
43     IMG_UINT32 H264_QP;
44     IMG_UINT32 H263_MPG4_FrameQ_scale;
45     IMG_UINT32 H263_MPG4_SliceQ_scale;
46 } MTX_QP_INFO;
47 
48 /* #include "topaz_vlc_regs.h" */
49 
50 /* Allocating 32 words (128 bytes aligned to 8 bytes) */
51 #define MAX_HEADERSIZEWORDS (32)
52 
53 typedef enum {
54     ELEMENT_STARTCODE_RAWDATA = 0,/* Rawdata that includes a start code */
55     ELEMENT_RAWDATA,            /* Rawdata */
56     ELEMENT_QP,                 /* Insert the H264 Picture Header QP parameter (no rawdata) */
57     ELEMENT_SQP,                /* Insert the H264 Slice Header QP parameter (no rawdata) */
58     ELEMENT_FRAMEQSCALE,        /* Insert the H263/MPEG4 Frame Q_scale parameter (vob_quant field) (no rawdata) */
59     ELEMENT_SLICEQSCALE,        /* Insert the H263/MPEG4 Slice Q_scale parameter (quant_scale field) (no rawdata) */
60     ELEMENT_INSERTBYTEALIGN_H264,/* Insert the byte align field (no rawdata) */
61     ELEMENT_INSERTBYTEALIGN_MPG4, /* Insert the byte align field  (no rawdata) */
62 
63     /*SEI_INSERTION*/
64     BPH_SEI_NAL_INITIAL_CPB_REMOVAL_DELAY,
65     BPH_SEI_NAL_INITIAL_CPB_REMOVAL_DELAY_OFFSET,
66     PTH_SEI_NAL_CPB_REMOVAL_DELAY,
67     PTH_SEI_NAL_DPB_OUTPUT_DELAY
68 } HEADER_ELEMENT_TYPE;
69 
70 
71 typedef struct _MTX_HEADER_ELEMENT_ {
72     HEADER_ELEMENT_TYPE Element_Type;
73     IMG_UINT8 Size;
74     IMG_UINT8 Bits;
75 } MTX_HEADER_ELEMENT;
76 
77 
78 typedef struct _MTX_HEADER_PARAMS_ {
79     IMG_UINT32 Elements;
80     MTX_HEADER_ELEMENT asElementStream[MAX_HEADERSIZEWORDS-1];
81 } MTX_HEADER_PARAMS;
82 
83 #define ELEMENTS_EMPTY 9999
84 
85 /* H264 Structures
86  */
87 
88 /* Define some constants for the variable elements in the header stream */
89 typedef enum _SHPROFILES {
90     SH_PROFILE_BP = 0,
91     SH_PROFILE_MP = 1,
92     SH_PROFILE_HP = 2,
93 } SH_PROFILE_TYPE;
94 
95 /* Level number definitions (integer level numbers, non-intermediary only.. except level 1b) */
96 typedef enum _SHLEVELS {
97     SH_LEVEL_1 = 10,
98     SH_LEVEL_1B = 11,
99     SH_LEVEL_11 = 11,
100     SH_LEVEL_12 = 12,
101     SH_LEVEL_13 = 13,
102     SH_LEVEL_2 = 20,
103     SH_LEVEL_21 = 21,
104     SH_LEVEL_22 = 22,
105     SH_LEVEL_3 = 30,
106     SH_LEVEL_31 = 31,
107     SH_LEVEL_32 = 32,
108     SH_LEVEL_4 = 40,
109     SH_LEVEL_41 = 41,
110     SH_LEVEL_42 = 42,
111     SH_LEVEL_5 = 50,
112     SH_LEVEL_51 = 51
113 } SH_LEVEL_TYPE;
114 
115 
116 typedef enum _SLHP_SLICEFRAME_TYPE_ {
117     SLHP_P_SLICEFRAME_TYPE,
118     SLHP_B_SLICEFRAME_TYPE,
119     SLHP_I_SLICEFRAME_TYPE,
120     SLHP_SP_SLICEFRAME_TYPE,
121     SLHP_SI_SLICEFRAME_TYPE,
122 
123     SLHP_IDR_SLICEFRAME_TYPE
124 
125 } SLHP_SLICEFRAME_TYPE;
126 
127 
128 /* Input parameters for the header generation
129  * Some of the following data structures may have fields that are actually static..
130  * may want to prune them down a bit later.
131  */
132 typedef struct _H264_VUI_PARAMS_STRUC {
133     IMG_BOOL aspect_ratio_info_present_flag;
134     IMG_UINT8 aspect_ratio_idc;
135     IMG_UINT16 sar_width;
136     IMG_UINT16 sar_height;
137     IMG_UINT32 Time_Scale;
138     IMG_UINT32 num_units_in_tick;
139     IMG_UINT32 bit_rate_value_minus1; /* bitrate/64)-1 */
140     IMG_UINT32 cbp_size_value_minus1; /* (bitrate*1.5)/16 */
141     IMG_UINT8 CBR;
142     IMG_UINT8 initial_cpb_removal_delay_length_minus1;
143     IMG_UINT8 cpb_removal_delay_length_minus1;
144     IMG_UINT8 dpb_output_delay_length_minus1;
145     IMG_UINT8 time_offset_length;
146 } H264_VUI_PARAMS;
147 
148 typedef struct _H264_CROP_PARAMS_STRUCT_ {
149     IMG_BOOL bClip;
150     IMG_UINT16 LeftCropOffset;
151     IMG_UINT16 RightCropOffset;
152     IMG_UINT16 TopCropOffset;
153     IMG_UINT16 BottomCropOffset;
154 } H264_CROP_PARAMS;
155 
156 typedef struct _H264_SEQUENCE_HEADER_PARAMS_STRUC {
157     SH_PROFILE_TYPE ucProfile;
158     SH_LEVEL_TYPE ucLevel;
159     IMG_UINT8 ucWidth_in_mbs_minus1;
160     IMG_UINT8 ucHeight_in_maps_units_minus1;
161     IMG_UINT8 gaps_in_frame_num_value;
162     IMG_UINT8 ucFrame_mbs_only_flag;
163     IMG_UINT8 VUI_Params_Present;
164     H264_VUI_PARAMS VUI_Params;
165 } H264_SEQUENCE_HEADER_PARAMS;
166 
167 
168 typedef struct _H264_SLICE_HEADER_PARAMS_STRUC {
169     IMG_UINT8 Start_Code_Prefix_Size_Bytes;
170     SLHP_SLICEFRAME_TYPE SliceFrame_Type;
171     IMG_UINT32 First_MB_Address;
172     IMG_UINT8 Frame_Num_DO;
173     IMG_UINT8 Picture_Num_DO;
174     IMG_BOOL UsesLongTermRef;
175     IMG_BOOL IsLongTermRef;
176     IMG_UINT8 Disable_Deblocking_Filter_Idc;
177     IMG_INT8 iDebAlphaOffsetDiv2;
178     IMG_INT8 iDebBetaOffsetDiv2;
179 } H264_SLICE_HEADER_PARAMS;
180 
181 
182 
183 /* MPEG4 Structures
184  */
185 typedef enum _MPEG4_PROFILE {
186     SP = 1,
187     ASP = 3
188 } MPEG4_PROFILE_TYPE;
189 
190 typedef enum _FIXED_VOP_TIME_ENUM {
191     _30FPS = 1,
192     _15FPS = 2,
193     _10FPS = 3
194 } FIXED_VOP_TIME_TYPE;
195 
196 typedef struct _VBVPARAMS_STRUC {
197     IMG_UINT32  First_half_bit_rate;
198     IMG_UINT32  Latter_half_bit_rate;
199     IMG_UINT32  First_half_vbv_buffer_size;
200     IMG_UINT32  Latter_half_vbv_buffer_size;
201     IMG_UINT32  First_half_vbv_occupancy;
202     IMG_UINT32  Latter_half_vbv_occupancy;
203 } VBVPARAMS;
204 
205 
206 /*
207  * H263 Structures
208  */
209 
210 typedef enum _VOP_CODING_ENUM {
211     I_FRAME = 0,
212     P_FRAME = 1
213 } VOP_CODING_TYPE, H263_PICTURE_CODING_TYPE;
214 
215 typedef enum _SEARCH_RANGE_ENUM {
216     PLUSMINUS_32 = 2,
217     PLUSMINUS_64 = 3,
218     FCODE_EQ_4 = 4
219 }  SEARCH_RANGE_TYPE;
220 
221 typedef enum _H263_SOURCE_FORMAT_ENUM {
222     _128x96_SubQCIF = 1,
223     _176x144_QCIF = 2,
224     _352x288_CIF = 3,
225     _704x576_4CIF = 4
226 } H263_SOURCE_FORMAT_TYPE;
227 
228 
229 #define SIZEINBITS(a) (sizeof(a)*8)
230 
231 /* H264 header preparation */
232 void pnw__H264_prepare_sequence_header(
233     unsigned char *pHeaderMemory,
234     IMG_UINT32 uiPicWidthInMbs,
235     IMG_UINT32 uiPicHeightInMbs,
236     IMG_BOOL VUI_present, H264_VUI_PARAMS *VUI_params,
237     H264_CROP_PARAMS *psCropParams,
238     IMG_UINT8 uiLevel,
239     IMG_UINT8 uiProfile);
240 
241 void pnw__H264_prepare_picture_header(unsigned char *pHeaderMemory, IMG_BOOL bCabacEnaled, IMG_INT8 CQPOffset);
242 
243 void pnw__H264_prepare_slice_header(
244     unsigned char *pHeaderMemory,
245     IMG_BOOL    bIntraSlice,
246     IMG_UINT32 uiDisableDeblockingFilterIDC,
247     IMG_UINT32 uiFrameNumber,
248     IMG_UINT32 uiFirst_MB_Address,
249     IMG_UINT32 uiMBSkipRun,
250     IMG_BOOL bCabacEnabled,
251     IMG_BOOL bForceIDR,
252     IMG_BOOL bUsesLongTermRef,
253     IMG_BOOL bIsLOngTermRef,
254     IMG_UINT16 uiIdrPicId);
255 
256 void pnw__H264_prepare_eodofstream_header(unsigned char *pHeaderMemory);
257 void pnw__H264_prepare_endofpicture_header(unsigned char *pHeaderMemory);
258 void pnw__H264_prepare_endofsequence_header(unsigned char *pHeaderMemory);
259 
260 
261 /* MPEG4 header preparation */
262 void pnw__MPEG4_prepare_sequence_header(
263     unsigned char *pHeaderMemory,
264     IMG_BOOL bBFrame,
265     MPEG4_PROFILE_TYPE sProfile,
266     IMG_UINT8 Profile_and_level_indication,
267     FIXED_VOP_TIME_TYPE sFixed_vop_time_increment,
268     IMG_UINT32 Picture_Width_Pixels,
269     IMG_UINT32 Picture_Height_Pixels,
270     VBVPARAMS * psVBVParams,
271     IMG_UINT32 VopTimeResolution);
272 
273 void pnw__MPEG4_prepare_vop_header(
274     unsigned char *pHeaderMem,
275     IMG_BOOL bIsVOP_coded,
276     IMG_UINT32 VOP_time_increment,
277     IMG_UINT8 sSearch_range,
278     IMG_UINT8 eVop_Coding_Type,
279     IMG_UINT32 VopTimeResolution);
280 
281 
282 /* H263 header preparation */
283 void pnw__H263_prepare_sequence_header(
284     unsigned char *pHeaderMem,
285     IMG_UINT8 Profile_and_level_indication);
286 
287 void pnw__H263_prepare_picture_header(
288     unsigned char *pHeaderMem,
289     IMG_UINT8 Temporal_Ref,
290     H263_PICTURE_CODING_TYPE PictureCodingType,
291     H263_SOURCE_FORMAT_TYPE SourceFormatType,
292     IMG_UINT8 FrameRate,
293     IMG_UINT16 PictureWidth,
294     IMG_UINT16 PictureHeigth);
295 
296 void pnw__H263_prepare_GOBslice_header(
297     unsigned char *pHeaderMem,
298     IMG_UINT8 GOBNumber,
299     IMG_UINT8 GOBFrameId);
300 
301 void pnw__H264_prepare_SEI_buffering_period_header(
302     MTX_HEADER_PARAMS * pMTX_Header,
303     IMG_UINT8 ui8NalHrdBpPresentFlag,
304     IMG_UINT8 ui8nal_cpb_cnt_minus1,
305     IMG_UINT8 ui8nal_initial_cpb_removal_delay_length,
306     IMG_UINT32 ui32nal_initial_cpb_removal_delay,
307     IMG_UINT32 ui32nal_initial_cpb_removal_delay_offset,
308     IMG_UINT8 ui8VclHrdBpPresentFlag,
309     IMG_UINT8 ui8vcl_cpb_cnt_minus1,
310     IMG_UINT32 ui32vcl_initial_cpb_removal_delay,
311     IMG_UINT32 ui32vcl_initial_cpb_removal_delay_offset);
312 
313 void pnw__H264_prepare_SEI_picture_timing_header(
314     MTX_HEADER_PARAMS * pMTX_Header,
315     IMG_UINT8 ui8CpbDpbDelaysPresentFlag,
316     IMG_UINT32 ui32cpb_removal_delay_length_minus1,
317     IMG_UINT32 ui32dpb_output_delay_length_minus1,
318     IMG_UINT32 ui32cpb_removal_delay,
319     IMG_UINT32 ui32dpb_output_delay,
320     IMG_UINT8 ui8pic_struct_present_flag,
321     IMG_UINT8 ui8pic_struct,
322     IMG_UINT8 ui8NumClockTS,
323     IMG_UINT8 *aui8clock_timestamp_flag,
324     IMG_UINT8 ui8full_timestamp_flag,
325     IMG_UINT8 ui8seconds_flag,
326     IMG_UINT8 ui8minutes_flag,
327     IMG_UINT8 ui8hours_flag,
328     IMG_UINT8 ui8seconds_value,
329     IMG_UINT8 ui8minutes_value,
330     IMG_UINT8 ui8hours_value,
331     IMG_UINT8 ui8ct_type,
332     IMG_UINT8 ui8nuit_field_based_flag,
333     IMG_UINT8 ui8counting_type,
334     IMG_UINT8 ui8discontinuity_flag,
335     IMG_UINT8 ui8cnt_dropped_flag,
336     IMG_UINT8 ui8n_frames,
337     IMG_UINT8 ui8time_offset_length,
338     IMG_INT32 i32time_offset);
339 
340 
341 #endif /* _PNW_HOSTHEADER_H_ */
342 
343 
344 
345 
346