1/*
2 INTEL CONFIDENTIAL
3 Copyright 2009 Intel Corporation All Rights Reserved.
4 The source code contained or described herein and all documents related to the source code ("Material") are owned by Intel Corporation or its suppliers or licensors. Title to the Material remains with Intel Corporation or its suppliers and licensors. The Material contains trade secrets and proprietary and confidential information of Intel or its suppliers and licensors. The Material is protected by worldwide copyright and trade secret laws and treaty provisions. No part of the Material may be used, copied, reproduced, modified, published, uploaded, posted, transmitted, distributed, or disclosed in any way without Intel’s prior express written permission.
5
6 No license under any patent, copyright, trade secret or other intellectual property right is granted to or conferred upon you by disclosure or delivery of the Materials, either expressly, by implication, inducement, estoppel or otherwise. Any license under such intellectual property rights must be express and approved by Intel in writing.
7 */
8
9#ifndef VBP_LOADER_H
10#define VBP_LOADER_H
11
12#include <va/va.h>
13
14#ifndef TRUE
15#define TRUE 1
16#endif
17
18#ifndef FALSE
19#define FALSE 0
20#endif
21
22
23#ifndef uint8
24typedef unsigned char uint8;
25#endif
26#ifndef uint16
27typedef unsigned short uint16;
28#endif
29#ifndef uint32
30typedef unsigned int uint32;
31#endif
32#ifndef bool
33typedef int bool;
34#endif
35
36typedef void *Handle;
37
38/*
39 * MPEG-4 Part 2 data structure
40 */
41
42typedef struct _vbp_codec_data_mp42
43{
44    uint8  profile_and_level_indication;
45} vbp_codec_data_mp42;
46
47typedef struct _vbp_slice_data_mp42
48{
49	uint8* buffer_addr;
50	uint32 slice_offset;
51	uint32 slice_size;
52	VASliceParameterBufferMPEG4 slice_param;
53} vbp_slice_data_mp42;
54
55typedef struct _vbp_picture_data_mp42
56{
57	uint8 vop_coded;
58	VAPictureParameterBufferMPEG4 picture_param;
59	VAIQMatrixBufferMPEG4 iq_matrix_buffer;
60
61	uint32 number_slices;
62	vbp_slice_data_mp42 *slice_data;
63
64} vbp_picture_data_mp42;
65
66typedef struct _vbp_data_mp42
67{
68	vbp_codec_data_mp42 codec_data;
69
70	uint32 number_pictures;
71	vbp_picture_data_mp42 *picture_data;
72
73} vbp_data_mp42;
74
75/*
76 * H.264 data structure
77 */
78
79typedef struct _vbp_codec_data_h264
80{
81	uint8		pic_parameter_set_id;
82	uint8	 	seq_parameter_set_id;
83
84	uint8 		profile_idc;
85	uint8 		level_idc;
86	uint8		constraint_set1_flag;
87
88	uint8	 	num_ref_frames;
89	uint8	 	gaps_in_frame_num_value_allowed_flag;
90
91	uint8	 	frame_mbs_only_flag;
92	uint8	 	mb_adaptive_frame_field_flag;
93
94	int			frame_width;
95	int			frame_height;
96
97	uint8	 	frame_cropping_flag;
98	int 		frame_crop_rect_left_offset;
99	int			frame_crop_rect_right_offset;
100	int 		frame_crop_rect_top_offset;
101	int 		frame_crop_rect_bottom_offset;
102
103	uint8	 	vui_parameters_present_flag;
104	/* aspect ratio */
105	uint8  		aspect_ratio_info_present_flag;
106	uint8  		aspect_ratio_idc;
107	uint16		sar_width;
108	uint16		sar_height;
109
110	/* video fromat */
111	uint8   	video_signal_type_present_flag;
112	uint8  		video_format;
113
114} vbp_codec_data_h264;
115
116typedef struct _vbp_slice_data_h264
117{
118     uint8* buffer_addr;
119
120     uint32 slice_offset; /* slice data offset */
121
122     uint32 slice_size; /* slice data size */
123
124     VASliceParameterBufferH264 slc_parms;
125
126} vbp_slice_data_h264;
127
128
129 typedef struct _vbp_picture_data_h264
130 {
131     VAPictureParameterBufferH264* pic_parms;
132
133     uint32 num_slices;
134
135     vbp_slice_data_h264* slc_data;
136
137 } vbp_picture_data_h264;
138
139
140typedef struct _vbp_data_h264
141{
142     /* rolling counter of buffers sent by vbp_parse */
143     uint32 buf_number;
144
145	 uint32 num_pictures;
146
147	 vbp_picture_data_h264* pic_data;
148
149     /**
150	 * do we need to send matrix to VA for each picture? If not, we need
151     * a flag indicating whether it is updated.
152	 */
153     VAIQMatrixBufferH264* IQ_matrix_buf;
154
155     vbp_codec_data_h264* codec_data;
156
157} vbp_data_h264;
158
159/*
160 * vc1 data structure
161 */
162typedef struct _vbp_codec_data_vc1
163{
164	/* Sequence layer. */
165	uint8  PROFILE;
166	uint8  LEVEL;
167	uint8  POSTPROCFLAG;
168	uint8  PULLDOWN;
169	uint8  INTERLACE;
170	uint8  TFCNTRFLAG;
171	uint8  FINTERPFLAG;
172	uint8  PSF;
173
174	/* Entry point layer. */
175	uint8  BROKEN_LINK;
176	uint8  CLOSED_ENTRY;
177	uint8  PANSCAN_FLAG;
178	uint8  REFDIST_FLAG;
179	uint8  LOOPFILTER;
180	uint8  FASTUVMC;
181	uint8  EXTENDED_MV;
182	uint8  DQUANT;
183	uint8  VSTRANSFORM;
184	uint8  OVERLAP;
185	uint8  QUANTIZER;
186	uint16 CODED_WIDTH;
187	uint16 CODED_HEIGHT;
188	uint8  EXTENDED_DMV;
189	uint8  RANGE_MAPY_FLAG;
190	uint8  RANGE_MAPY;
191	uint8  RANGE_MAPUV_FLAG;
192	uint8  RANGE_MAPUV;
193
194	/* Others. */
195	uint8  RANGERED;
196	uint8  MAXBFRAMES;
197	uint8  MULTIRES;
198	uint8  SYNCMARKER;
199	uint8  RNDCTRL;
200	uint8  REFDIST;
201	uint16 widthMB;
202	uint16 heightMB;
203
204	uint8  INTCOMPFIELD;
205	uint8  LUMSCALE2;
206	uint8  LUMSHIFT2;
207} vbp_codec_data_vc1;
208
209typedef struct _vbp_slice_data_vc1
210{
211	uint8 *buffer_addr;
212	uint32 slice_offset;
213	uint32 slice_size;
214	VASliceParameterBufferVC1 slc_parms;     /* pointer to slice parms */
215} vbp_slice_data_vc1;
216
217
218typedef struct _vbp_picture_data_vc1
219{
220	uint32 picture_is_skipped;                /* VC1_PTYPE_SKIPPED is PTYPE is skipped. */
221	VAPictureParameterBufferVC1 *pic_parms;   /* current parsed picture header */
222	uint32 size_bitplanes;                    /* based on number of MBs */
223	uint8 *packed_bitplanes;                  /* contains up to three bitplanes packed for libVA */
224	uint32 num_slices;                        /* number of slices.  always at least one */
225	vbp_slice_data_vc1 *slc_data;             /* pointer to array of slice data */
226} vbp_picture_data_vc1;
227
228typedef struct _vbp_data_vc1
229{
230	uint32 buf_number;                        /* rolling counter of buffers sent by vbp_parse */
231	vbp_codec_data_vc1 *se_data;              /* parsed SH/EPs */
232
233	uint32 num_pictures;
234
235	vbp_picture_data_vc1* pic_data;
236} vbp_data_vc1;
237
238enum _picture_type
239{
240	VC1_PTYPE_I,
241	VC1_PTYPE_P,
242	VC1_PTYPE_B,
243	VC1_PTYPE_BI,
244	VC1_PTYPE_SKIPPED
245};
246
247enum _vbp_parser_error
248{
249	VBP_OK,
250	VBP_TYPE,
251	VBP_LOAD,
252	VBP_UNLOAD,
253	VBP_INIT,
254	VBP_DATA,
255	VBP_DONE,
256	VBP_GLIB,
257	VBP_MEM,
258	VBP_PARM,
259	VBP_CXT,
260	VBP_IMPL
261};
262
263enum _vbp_parser_type
264{
265	VBP_VC1,
266	VBP_MPEG2,
267	VBP_MPEG4,
268	VBP_H264
269};
270
271/*
272 * open video bitstream parser to parse a specific media type.
273 * @param  parser_type: one of the types defined in #vbp_parser_type
274 * @param  hcontext: pointer to hold returned VBP context handle.
275 * @return VBP_OK on success, anything else on failure.
276 *
277 */
278uint32 vbp_open(uint32 parser_type, Handle *hcontext);
279
280/*
281 * close video bitstream parser.
282 * @param hcontext: VBP context handle.
283 * @returns VBP_OK on success, anything else on failure.
284 *
285 */
286uint32 vbp_close(Handle hcontext);
287
288/*
289 * parse bitstream.
290 * @param hcontext: handle to VBP context.
291 * @param data: pointer to bitstream buffer.
292 * @param size: size of bitstream buffer.
293 * @param init_flag: 1 if buffer contains bitstream configuration data, 0 otherwise.
294 * @return VBP_OK on success, anything else on failure.
295 *
296 */
297uint32 vbp_parse(Handle hcontext, uint8 *data, uint32 size, uint8 init_data_flag);
298
299/*
300 * query parsing result.
301 * @param hcontext: handle to VBP context.
302 * @param data: pointer to hold a data blob that contains parsing result.
303 * 				Structure of data blob is determined by the media type.
304 * @return VBP_OK on success, anything else on failure.
305 *
306 */
307uint32 vbp_query(Handle hcontext, void **data);
308
309
310/*
311 * flush any un-parsed bitstream.
312 * @param hcontext: handle to VBP context.
313 * @returns VBP_OK on success, anything else on failure.
314 *
315 */
316uint32 vbp_flush(Handle hcontent);
317
318#endif /* VBP_LOADER_H */
319