blob: b66faea99639fd16776e1d380d25f410c6dc0e3c [file] [log] [blame]
Thierry Strudel58ab4ce2014-09-25 22:01:08 -07001/*
2 * Copyright (C) 2014 Intel Corporation. All rights reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef VBP_LOADER_H
18#define VBP_LOADER_H
19
20#include <va/va.h>
21
22#ifdef USE_HW_VP8
23#include <va/va_dec_vp8.h>
24#endif
25
26#ifndef TRUE
27#define TRUE 1
28#endif
29
30#ifndef FALSE
31#define FALSE 0
32#endif
33
34
35#ifndef uint8
36typedef unsigned char uint8;
37#endif
38#ifndef uint16
39typedef unsigned short uint16;
40#endif
41#ifndef uint32
42typedef unsigned int uint32;
43#endif
44#ifndef int16
45typedef short int16;
46#endif
47
48typedef void *Handle;
49
50/*
51 * MPEG-4 Part 2 data structure
52 */
53
54typedef struct _vbp_codec_data_mp42
55{
56 uint8 profile_and_level_indication;
57 uint32 video_object_layer_width;
58 uint32 video_object_layer_height;
59
60 // 0 for unspecified, PAL/NTSC/SECAM
61 uint8 video_format;
62
63 // 0 short range, 1 full range
64 uint8 video_range;
65
66 // default 2 (unspecified), 1 for BT709.
67 uint8 matrix_coefficients;
68
69 uint8 short_video_header;
70
71 // always exist for mpeg-4,
72 uint8 aspect_ratio_info;
73 uint8 par_width;
74 uint8 par_height;
75
76 // bit rate
77 int bit_rate;
78} vbp_codec_data_mp42;
79
80typedef struct _vbp_slice_data_mp42
81{
82 uint8* buffer_addr;
83 uint32 slice_offset;
84 uint32 slice_size;
85 VASliceParameterBufferMPEG4 slice_param;
86} vbp_slice_data_mp42;
87
88typedef struct _vbp_picture_data_mp42 vbp_picture_data_mp42;
89
90struct _vbp_picture_data_mp42
91{
92 uint8 vop_coded;
93 uint16 vop_time_increment;
94 /* indicates if current buffer contains parameter for the first slice of the picture */
95 uint8 new_picture_flag;
96 VAPictureParameterBufferMPEG4 picture_param;
97 vbp_slice_data_mp42 slice_data;
98
99 vbp_picture_data_mp42* next_picture_data;
100};
101
102typedef struct _vbp_data_mp42
103{
104 vbp_codec_data_mp42 codec_data;
105 VAIQMatrixBufferMPEG4 iq_matrix_buffer;
106
107 uint32 number_picture_data;
108 uint32 number_pictures;
109
110 vbp_picture_data_mp42 *picture_data;
111
112} vbp_data_mp42;
113
114/*
115 * H.264 data structure
116 */
117
118typedef struct _vbp_codec_data_h264
119{
120 uint8 pic_parameter_set_id;
121 uint8 seq_parameter_set_id;
122
123 uint8 profile_idc;
124 uint8 level_idc;
125 /*constraint flag sets (h.264 Spec v2009)*/
126 uint8 constraint_set0_flag;
127 uint8 constraint_set1_flag;
128 uint8 constraint_set2_flag;
129 uint8 constraint_set3_flag;
130 uint8 constraint_set4_flag;
131
132 uint8 num_ref_frames;
133 uint8 gaps_in_frame_num_value_allowed_flag;
134
135 uint8 frame_mbs_only_flag;
136 uint8 mb_adaptive_frame_field_flag;
137
138 int frame_width;
139 int frame_height;
140
141 uint8 vui_parameters_present_flag;
142
143 /* aspect ratio */
144 uint8 aspect_ratio_idc;
145 uint16 sar_width;
146 uint16 sar_height;
147
148 /* cropping information */
149 int crop_top;
150 int crop_bottom;
151 int crop_left;
152 int crop_right;
153
154 /* video fromat */
155
156 // default 5 unspecified
157 uint8 video_format;
158 uint8 video_full_range_flag;
159
160 // default 2 unspecified
161 uint8 matrix_coefficients;
162
163 uint8 pic_order_cnt_type;
164 int log2_max_pic_order_cnt_lsb_minus4;
165
166 int bit_rate;
167
168 int has_slice;
169} vbp_codec_data_h264;
170
171typedef struct _vbp_slice_data_h264
172{
173 uint8* buffer_addr;
174
175 uint32 slice_offset; /* slice data offset */
176
177 uint32 slice_size; /* slice data size */
178
179 uint8 nal_unit_type;
180
181 VASliceParameterBufferH264 slc_parms;
182
183} vbp_slice_data_h264;
184
185
186typedef struct _vbp_picture_data_h264
187{
188 VAPictureParameterBufferH264* pic_parms;
189
190 uint32 num_slices;
191
192 vbp_slice_data_h264* slc_data;
193
194} vbp_picture_data_h264;
195
196
197typedef struct _vbp_data_h264
198{
199 /* rolling counter of buffers sent by vbp_parse */
200 uint32 buf_number;
201
202 uint32 num_pictures;
203
204 /* if SPS has been received */
205 uint8 has_sps;
206
207 /* if PPS has been received */
208 uint8 has_pps;
209
210 uint8 new_sps;
211
212 uint8 new_pps;
213
214 vbp_picture_data_h264* pic_data;
215
216 /**
217 * do we need to send matrix to VA for each picture? If not, we need
218 * a flag indicating whether it is updated.
219 */
220 VAIQMatrixBufferH264* IQ_matrix_buf;
221
222 vbp_codec_data_h264* codec_data;
223
224#ifdef USE_SLICE_HEADER_PARSING
225 VAParsePictureParameterBuffer* pic_parse_buffer;
226#endif
227
228} vbp_data_h264;
229
230/*
231 * vc1 data structure
232 */
233typedef struct _vbp_codec_data_vc1
234{
235 /* Sequence layer. */
236 uint8 PROFILE;
237 uint8 LEVEL;
238 uint8 POSTPROCFLAG;
239 uint8 PULLDOWN;
240 uint8 INTERLACE;
241 uint8 TFCNTRFLAG;
242 uint8 FINTERPFLAG;
243 uint8 PSF;
244
245 // default 2: unspecified
246 uint8 MATRIX_COEF;
247
248 /* Entry point layer. */
249 uint8 BROKEN_LINK;
250 uint8 CLOSED_ENTRY;
251 uint8 PANSCAN_FLAG;
252 uint8 REFDIST_FLAG;
253 uint8 LOOPFILTER;
254 uint8 FASTUVMC;
255 uint8 EXTENDED_MV;
256 uint8 DQUANT;
257 uint8 VSTRANSFORM;
258 uint8 OVERLAP;
259 uint8 QUANTIZER;
260 uint16 CODED_WIDTH;
261 uint16 CODED_HEIGHT;
262 uint8 EXTENDED_DMV;
263 uint8 RANGE_MAPY_FLAG;
264 uint8 RANGE_MAPY;
265 uint8 RANGE_MAPUV_FLAG;
266 uint8 RANGE_MAPUV;
267
268 /* Others. */
269 uint8 RANGERED;
270 uint8 MAXBFRAMES;
271 uint8 MULTIRES;
272 uint8 SYNCMARKER;
273 uint8 RNDCTRL;
274 uint8 REFDIST;
275 uint16 widthMB;
276 uint16 heightMB;
277
278 uint8 INTCOMPFIELD;
279 uint8 LUMSCALE2;
280 uint8 LUMSHIFT2;
281
282 // aspect ratio
283
284 // default unspecified
285 uint8 ASPECT_RATIO;
286
287 uint8 ASPECT_HORIZ_SIZE;
288 uint8 ASPECT_VERT_SIZE;
289 // bit rate
290 int bit_rate;
291} vbp_codec_data_vc1;
292
293typedef struct _vbp_slice_data_vc1
294{
295 uint8 *buffer_addr;
296 uint32 slice_offset;
297 uint32 slice_size;
298 VASliceParameterBufferVC1 slc_parms; /* pointer to slice parms */
299} vbp_slice_data_vc1;
300
301
302typedef struct _vbp_picture_data_vc1
303{
304 uint32 picture_is_skipped; /* VC1_PTYPE_SKIPPED is PTYPE is skipped. */
305 VAPictureParameterBufferVC1 *pic_parms; /* current parsed picture header */
306 uint32 size_bitplanes; /* based on number of MBs */
307 uint8 *packed_bitplanes; /* contains up to three bitplanes packed for libVA */
308 uint32 num_slices; /* number of slices. always at least one */
309 vbp_slice_data_vc1 *slc_data; /* pointer to array of slice data */
310} vbp_picture_data_vc1;
311
312typedef struct _vbp_data_vc1
313{
314 uint32 buf_number; /* rolling counter of buffers sent by vbp_parse */
315 vbp_codec_data_vc1 *se_data; /* parsed SH/EPs */
316
317 uint32 num_pictures;
318
319 vbp_picture_data_vc1* pic_data;
320} vbp_data_vc1;
321
322#ifdef USE_HW_VP8
323typedef struct _vbp_codec_data_vp8
324{
325 uint8 frame_type;
326 uint8 version_num;
327 int show_frame;
328
329 uint32 frame_width;
330 uint32 frame_height;
331
332 int refresh_alt_frame;
333 int refresh_golden_frame;
334 int refresh_last_frame;
335
336 /* cropping information */
337 int crop_top;
338 int crop_bottom;
339 int crop_left;
340 int crop_right;
341
342 int golden_copied;
343 int altref_copied;
344} vbp_codec_data_vp8;
345
346typedef struct _vbp_slice_data_vp8
347{
348 uint8 *buffer_addr;
349 uint32 slice_offset;
350 uint32 slice_size;
351 VASliceParameterBufferVP8 slc_parms; /* pointer to slice parms */
352} vbp_slice_data_vp8;
353
354typedef struct _vbp_picture_data_vp8
355{
356 VAPictureParameterBufferVP8* pic_parms; /* current parsed picture header */
357
358 uint32 num_slices; /* number of slices. always one for VP8 */
359 vbp_slice_data_vp8 *slc_data; /* pointer to array of slice data */
360} vbp_picture_data_vp8;
361
362typedef struct _vbp_data_vp8
363{
364 uint32 buf_number; /* rolling counter of buffers sent by vbp_parse */
365 vbp_codec_data_vp8 *codec_data;
366
367 uint32 num_pictures;
368
369 vbp_picture_data_vp8* pic_data;
370
371 VAProbabilityDataBufferVP8* prob_data;
372 VAIQMatrixBufferVP8* IQ_matrix_buf;
373} vbp_data_vp8;
374#endif
375
376enum _picture_type
377{
378 VC1_PTYPE_I,
379 VC1_PTYPE_P,
380 VC1_PTYPE_B,
381 VC1_PTYPE_BI,
382 VC1_PTYPE_SKIPPED
383};
384
385enum _vbp_parser_error
386{
387 VBP_OK,
388 VBP_TYPE,
389 VBP_LOAD,
390 VBP_INIT,
391 VBP_DATA,
392 VBP_DONE,
393 VBP_MEM,
394 VBP_PARM,
395 VBP_PARTIAL,
396 VBP_MULTI,
397 VBP_ERROR
398};
399
400enum _vbp_parser_type
401{
402 VBP_VC1,
403 VBP_MPEG2,
404 VBP_MPEG4,
405 VBP_H264,
406#ifdef USE_HW_VP8
407 VBP_VP8,
408#endif
409#if (defined USE_AVC_SHORT_FORMAT || defined USE_SLICE_HEADER_PARSING)
410 VBP_H264SECURE,
411#endif
412};
413
414
415/*
416 * open video bitstream parser to parse a specific media type.
417 * @param parser_type: one of the types defined in #vbp_parser_type
418 * @param hcontext: pointer to hold returned VBP context handle.
419 * @return VBP_OK on success, anything else on failure.
420 *
421 */
422uint32 vbp_open(uint32 parser_type, Handle *hcontext);
423
424/*
425 * close video bitstream parser.
426 * @param hcontext: VBP context handle.
427 * @returns VBP_OK on success, anything else on failure.
428 *
429 */
430uint32 vbp_close(Handle hcontext);
431
432/*
433 * parse bitstream.
434 * @param hcontext: handle to VBP context.
435 * @param data: pointer to bitstream buffer.
436 * @param size: size of bitstream buffer.
437 * @param init_flag: 1 if buffer contains bitstream configuration data, 0 otherwise.
438 * @return VBP_OK on success, anything else on failure.
439 *
440 */
441uint32 vbp_parse(Handle hcontext, uint8 *data, uint32 size, uint8 init_data_flag);
442
443/*
444 * query parsing result.
445 * @param hcontext: handle to VBP context.
446 * @param data: pointer to hold a data blob that contains parsing result.
447 * Structure of data blob is determined by the media type.
448 * @return VBP_OK on success, anything else on failure.
449 *
450 */
451uint32 vbp_query(Handle hcontext, void **data);
452
453
454/*
455 * flush any un-parsed bitstream.
456 * @param hcontext: handle to VBP context.
457 * @returns VBP_OK on success, anything else on failure.
458 *
459 */
460uint32 vbp_flush(Handle hcontent);
461
462#if (defined USE_AVC_SHORT_FORMAT || defined USE_SLICE_HEADER_PARSING)
463/*
464 * update the the vbp context using the new data
465 * @param hcontext: handle to VBP context.
466 * @param data: pointer to the new data buffer.
467 * @param size: size of new data buffer.
468 * @param data: pointer to hold a data blob that contains parsing result.
469 * @returns VBP_OK on success, anything else on failure.
470 *
471*/
472uint32 vbp_update(Handle hcontext, void *newdata, uint32 size, void **data);
473#endif
474
475#endif /* VBP_LOADER_H */