2 * Copyright (c) 2007 Intel Corporation. All Rights Reserved.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the
6 * "Software"), to deal in the Software without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish,
8 * distribute, sub license, and/or sell copies of the Software, and to
9 * permit persons to whom the Software is furnished to do so, subject to
10 * the following conditions:
12 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial portions
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
19 * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
20 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 * Video Decode Acceleration API Specification
28 * <jonathan.bian@intel.com>
31 * rev 0.10 (12/10/2006 Jonathan Bian) - Initial draft
32 * rev 0.11 (12/15/2006 Jonathan Bian) - Fixed some errors
33 * rev 0.12 (02/05/2007 Jonathan Bian) - Added VC-1 data structures for slice level decode
34 * rev 0.13 (02/28/2007 Jonathan Bian) - Added GetDisplay()
35 * rev 0.14 (04/13/2007 Jonathan Bian) - Fixed MPEG-2 PictureParameter structure, cleaned up a few funcs.
36 * rev 0.15 (04/20/2007 Jonathan Bian) - Overhauled buffer management
37 * rev 0.16 (05/02/2007 Jonathan Bian) - Added error codes and fixed some issues with configuration
38 * rev 0.17 (05/07/2007 Jonathan Bian) - Added H.264/AVC data structures for slice level decode.
39 * rev 0.18 (05/14/2007 Jonathan Bian) - Added data structures for MPEG-4 slice level decode
40 * and MPEG-2 motion compensation.
41 * rev 0.19 (08/06/2007 Jonathan Bian) - Removed extra type for bitplane data.
42 * rev 0.20 (08/08/2007 Jonathan Bian) - Added missing fields to VC-1 PictureParameter structure.
45 * Thanks to Waldo Bastian for many valuable feedbacks.
57 This is a decode only interface currently. The basic steps are:
59 - Negotiate a mutually acceptable configuration with the server to lock
60 down profile, entrypoints, and other attributes that will not change on
61 a frame-by-frame basis.
62 - Create a decode context which represents a "virtualized" hardware decode
64 - Get and fill decode buffers with picture level, slice level and macroblock
65 level data (depending on entrypoints)
66 - Pass the decode buffers to the server to decode the current frame
68 Initialization & Configuration Management
70 - Find out supported profiles
71 - Find out entrypoints for a given profile
72 - Find out configuration attributes for a given profile/entrypoint pair
73 - Create a configuration for use by the decoder
77 typedef void* VADisplay; /* window system dependent */
79 typedef int VAStatus; /* Return status type from functions */
80 /* Values for the return status */
81 #define VA_STATUS_SUCCESS 0x00000000
82 #define VA_STATUS_ERROR_ALLOCATION_FAILED 0x00000001
83 #define VA_STATUS_ERROR_INVALID_CONFIG 0x00000002
84 #define VA_STATUS_ERROR_INVALID_CONTEXT 0x00000003
85 #define VA_STATUS_ERROR_INVALID_SURFACE 0x00000004
86 #define VA_STATUS_ERROR_INVALID_BUFFER 0x00000005
87 #define VA_STATUS_ERROR_ATTR_NOT_SUPPORTED 0x00000006 /* Todo: Remove */
88 #define VA_STATUS_ERROR_MAX_NUM_EXCEEDED 0x00000007
89 #define VA_STATUS_ERROR_UNSUPPORTED_PROFILE 0x00000008
90 #define VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT 0x00000009
91 #define VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT 0x0000000a
92 #define VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE 0x0000000b
93 #define VA_STATUS_ERROR_UNKNOWN 0xFFFFFFFF
96 * Returns a short english description of error_status
98 const char *vaErrorStr(VAStatus error_status);
102 * A display must be obtained by calling vaGetDisplay() before calling
103 * vaInitialize() and other functions. This connects the API to the
104 * native window system.
105 * For X Windows, native_dpy would be from XOpenDisplay()
107 typedef void* NativeDisplay; /* window system dependent */
109 VADisplay vaGetDisplay (
110 NativeDisplay native_dpy /* implementation specific */
113 VAStatus vaInitialize (
115 int *major_version, /* out */
116 int *minor_version /* out */
120 * After this call, all library internal resources will be cleaned up
122 VAStatus vaTerminate (
126 /* Currently defined profiles */
129 VAProfileMPEG2Simple = 0,
130 VAProfileMPEG2Main = 1,
131 VAProfileMPEG4Simple = 2,
132 VAProfileMPEG4AdvancedSimple = 3,
133 VAProfileMPEG4Main = 4,
134 VAProfileH264Baseline = 5,
135 VAProfileH264Main = 6,
136 VAProfileH264High = 7,
137 VAProfileVC1Simple = 8,
138 VAProfileVC1Main = 9,
139 VAProfileVC1Advanced = 10,
142 /* Currently defined entrypoints */
147 VAEntrypointIDCT = 3,
148 VAEntrypointMoComp = 4,
149 VAEntrypointDeblocking = 5,
152 /* Currently defined configuration attribute types */
155 VAConfigAttribRTFormat = 0,
156 VAConfigAttribSpatialResidual = 1,
157 VAConfigAttribSpatialClipping = 2,
158 VAConfigAttribIntraResidual = 3,
159 VAConfigAttribEncryption = 4,
160 } VAConfigAttribType;
163 * Configuration attributes
164 * If there is more than one value for an attribute, a default
165 * value will be assigned to the attribute if the client does not
166 * specify the attribute when creating a configuration
168 typedef struct _VAConfigAttrib {
169 VAConfigAttribType type;
170 unsigned int value; /* OR'd flags (bits) for this attribute */
173 /* attribute value for VAConfigAttribRTFormat */
174 #define VA_RT_FORMAT_YUV420 0x00000001
175 #define VA_RT_FORMAT_YUV422 0x00000002
176 #define VA_RT_FORMAT_YUV444 0x00000004
179 * if an attribute is not applicable for a given
180 * profile/entrypoint pair, then set the value to the following
182 #define VA_ATTRIB_NOT_SUPPORTED 0x80000000
184 /* Get maximum number of profiles supported by the implementation */
185 int vaMaxNumProfiles (
189 /* Get maximum number of entrypoints supported by the implementation */
190 int vaMaxNumEntrypoints (
194 /* Get maximum number of attributs supported by the implementation */
195 int vaMaxNumConfigAttributes (
200 * Query supported profiles
201 * The caller must provide a "profile_list" array that can hold at
202 * least vaMaxNumProfile() entries. The actual number of profiles
203 * returned in "profile_list" is returned in "num_profile".
205 VAStatus vaQueryConfigProfiles (
207 VAProfile *profile_list, /* out */
208 int *num_profiles /* out */
212 * Query supported entrypoints for a given profile
213 * The caller must provide an "entrypoint_list" array that can hold at
214 * least vaMaxNumEntrypoints() entries. The actual number of entrypoints
215 * returned in "entrypoint_list" is returned in "num_entrypoints".
217 VAStatus vaQueryConfigEntrypoints (
220 VAEntrypoint *entrypoint_list, /* out */
221 int *num_entrypoints /* out */
225 * Query attributes for a given profile/entrypoint pair
226 * The caller must provide an
\93attrib_list
\94 with all attributes to be
227 * queried. Upon return, the attributes in
\93attrib_list
\94 have been
228 * updated with their value. Unknown attributes or attributes that are
229 * not supported for the given profile/entrypoint pair will have their
230 * value set to VA_ATTRIB_NOT_SUPPORTED
232 VAStatus vaQueryConfigAttributes (
235 VAEntrypoint entrypoint,
236 VAConfigAttrib *attrib_list, /* in/out */
240 typedef int VAConfigID;
243 * Create a configuration for the decode pipeline
244 * it passes in the attribute list that specifies the attributes it cares
245 * about, with the rest taking default values.
247 VAStatus vaCreateConfig (
250 VAEntrypoint entrypoint,
251 VAConfigAttrib *attrib_list,
253 VAConfigID *config_id /* out */
257 * Get all attributes for a given configuration
258 * The profile of the configuration is returned in
\93profile
\94
259 * The entrypoint of the configuration is returned in
\93entrypoint
\94
260 * The caller must provide an
\93attrib_list
\94 array that can hold at least
261 * vaMaxNumConfigAttributes() entries. The actual number of attributes
262 * returned in
\93attrib_list
\94 is returned in
\93num_attribs
\94
264 VAStatus vaGetConfigAttributes (
266 VAConfigID config_id,
267 VAProfile *profile, /* out */
268 VAEntrypoint *entrypoint, /* out */
269 VAConfigAttrib *attrib_list,/* out */
270 int *num_attribs /* out */
277 * Context represents a "virtual" video decode pipeline
280 /* generic context ID type, can be re-typed for specific implementation */
281 typedef int VAContextID;
283 /* generic surface ID type, can be re-typed for specific implementation */
284 typedef int VASurfaceID;
286 #define VA_INVALID_SURFACE -1
288 typedef struct _VAContext
290 VAContextID context_id; /* to identify this context */
291 VAConfigID config_id;
292 unsigned short picture_width;
293 unsigned short picture_height;
294 VASurfaceID *render_targets;
295 int num_render_targets;
301 flags - Any combination of the following:
302 VA_PROGRESSIVE (only progressive frame pictures in the sequence when set)
304 #define VA_PROGRESSIVE 0x1
310 Surfaces are render targets for a given context. The data in the surfaces
311 are not accessible to the client and the internal data format of
312 the surface is implementatin specific.
314 Question: Is there a need to know the data format (fourcc) or just
315 differentiate between 420/422/444 is sufficient?
319 typedef struct _VASurface
321 VASurfaceID surface_id; /* uniquely identify this surface */
322 VAContextID context_id; /* which context does this surface belong */
323 unsigned short width;
324 unsigned short height;
325 int format; /* 420/422/444 */
326 void *privData; /* private to the library */
330 * Surfaces will be bound to a context when the context is created. Once
331 * a surface is bound to a given context, it can not be used to create
332 * another context. The association is removed when the context is destroyed
335 /* Surface Functions */
336 VAStatus vaCreateSurfaces (
342 VASurface *surfaces /* out */
346 * surfaces can only be destroyed after the context associated has been
349 VAStatus vaDestroySurface (
351 VASurface *surface_list,
355 VAStatus vaCreateContext (
357 VAConfigID config_id,
361 VASurface *render_targets,
362 int num_render_targets,
363 VAContext *context /* out */
366 VAStatus vaDestroyContext (
374 * Buffers are used to pass various types of data from the
375 * client to the server. The server maintains a data store
376 * for each buffer created, and the client idenfies a buffer
377 * through a unique buffer id assigned by the server.
381 typedef int VABufferID;
385 VAPictureParameterBufferType = 0,
386 VAIQMatrixBufferType = 1,
387 VABitPlaneBufferType = 2,
388 VASliceGroupMapBufferType = 3,
389 VASliceParameterBufferType = 4,
390 VASliceDataBufferType = 5,
391 VAMacroblockParameterBufferType = 6,
392 VAResidualDataBufferType = 7,
393 VADeblockingParameterBufferType = 8
396 /****************************
397 * MPEG-2 data structures
398 ****************************/
400 /* MPEG-2 Picture Parameter Buffer */
402 * For each frame or field, and before any slice data, a single
403 * picture parameter buffer must be send.
405 typedef struct _VAPictureParameterBufferMPEG2
407 unsigned short horizontal_size;
408 unsigned short vertical_size;
409 VASurfaceID forward_reference_picture;
410 VASurfaceID backward_reference_picture;
411 /* meanings of the following fields are the same as in the standard */
412 int picture_coding_type;
413 int f_code; /* pack all four fcode into this */
416 unsigned char intra_dc_precision : 2;
417 unsigned char picture_structure : 2;
418 unsigned char top_field_first : 1;
419 unsigned char frame_pred_frame_dct : 1;
420 unsigned char concealment_motion_vectors : 1;
421 unsigned char q_scale_type : 1;
422 unsigned char intra_vlc_format : 1;
423 unsigned char alternate_scan : 1;
424 unsigned char repeat_first_field : 1;
425 unsigned char progressive_frame : 1;
426 unsigned char is_first_field : 1;/* indicate whether the current field is the first field for field picture */
428 unsigned int picture_coding_extension;
430 } VAPictureParameterBufferMPEG2;
432 /* MPEG-2 Inverse Quantization Matrix Buffer */
433 typedef struct _VAIQMatrixBufferMPEG2
435 int load_intra_quantiser_matrix;
436 int load_non_intra_quantiser_matrix;
437 int load_chroma_intra_quantiser_matrix;
438 int load_chroma_non_intra_quantiser_matrix;
439 unsigned char intra_quantiser_matrix[64];
440 unsigned char non_intra_quantiser_matrix[64];
441 unsigned char chroma_intra_quantiser_matrix[64];
442 unsigned char chroma_non_intra_quantiser_matrix[64];
443 } VAIQMatrixBufferMPEG2;
446 * There will be cases where the bitstream buffer will not have enough room to hold
447 * the data for the entire slice, and the following flags will be used in the slice
448 * parameter to signal to the server for the possible cases.
449 * If a slice parameter buffer and slice data buffer pair is sent to the server with
450 * the slice data partially in the slice data buffer (BEGIN and MIDDLE cases below),
451 * then a slice parameter and data buffer needs to be sent again to complete this slice.
453 #define VA_SLICE_DATA_FLAG_ALL 0x00 /* whole slice is in the buffer */
454 #define VA_SLICE_DATA_FLAG_BEGIN 0x01 /* The beginning of the slice is in the buffer but the end if not */
455 #define VA_SLICE_DATA_FLAG_MIDDLE 0x02 /* Neither beginning nor end of the slice is in the buffer */
456 #define VA_SLICE_DATA_FLAG_END 0x04 /* end of the slice is in the buffer */
458 /* MPEG-2 Slice Parameter Buffer */
459 typedef struct _VASliceParameterBufferMPEG2
461 unsigned int slice_data_size;/* number of bytes in the slice data buffer for this slice */
462 unsigned int slice_data_offset;/* the offset to the first byte of slice data */
463 unsigned int slice_data_flag; /* see VA_SLICE_DATA_FLAG_XXX defintions */
464 unsigned int macroblock_offset;/* the offset to the first bit of MB from the first byte of slice data */
465 unsigned int slice_vertical_position;
466 int quantiser_scale_code;
467 int intra_slice_flag;
468 } VASliceParameterBufferMPEG2;
470 /* MPEG-2 Macroblock Parameter Buffer */
471 typedef struct _VAMacroblockParameterBufferMPEG2
473 unsigned short macroblock_address;
475 * macroblock_address (in raster scan order)
477 * bottom-right: picture-height-in-mb*picture-width-in-mb - 1
479 unsigned char macroblock_type; /* see definition below */
482 unsigned char frame_motion_type : 2;
483 unsigned char field_motion_type : 2;
484 unsigned char dct_type : 1;
486 unsigned char macroblock_modes;
488 unsigned char motion_vertical_field_select;
490 * motion_vertical_field_select:
491 * see section 6.3.17.2 in the spec
492 * only the lower 4 bits are used
493 * bit 0: first vector forward
494 * bit 1: first vector backward
495 * bit 2: second vector forward
496 * bit 3: second vector backward
498 short PMV[2][2][2]; /* see Table 7-7 in the spec */
499 unsigned short coded_block_pattern;
501 * The bitplanes for coded_block_pattern are described
502 * in Figure 6.10-12 in the spec
505 /* Number of skipped macroblocks after this macroblock */
506 unsigned short num_skipped_macroblocks;
507 } VAMacroblockParameterBufferMPEG2;
510 * OR'd flags for macroblock_type (section 6.3.17.1 in the spec)
512 #define VA_MB_TYPE_MOTION_FORWARD 0x02
513 #define VA_MB_TYPE_MOTION_BACKWARD 0x04
514 #define VA_MB_TYPE_MOTION_PATTERN 0x08
515 #define VA_MB_TYPE_MOTION_INTRA 0x10
518 * MPEG-2 Residual Data Buffer
519 * For each macroblock, there wil be 64 shorts (16-bit) in the
520 * residual data buffer
523 /****************************
524 * MPEG-4 Part 2 data structures
525 ****************************/
527 /* MPEG-4 Picture Parameter Buffer */
529 * For each frame or field, and before any slice data, a single
530 * picture parameter buffer must be send.
532 typedef struct _VAPictureParameterBufferMPEG4
534 unsigned short vop_width;
535 unsigned short vop_height;
536 VASurfaceID forward_reference_picture;
537 VASurfaceID backward_reference_picture;
540 unsigned char short_video_header : 1;
541 unsigned char chroma_format : 2;
542 unsigned char interlaced : 1;
543 unsigned char obmc_disable : 1;
544 unsigned char sprite_enable : 2;
545 unsigned char sprite_warping_accuracy : 2;
546 unsigned char quant_type : 1;
547 unsigned char quarter_sample : 1;
548 unsigned char data_partitioned : 1;
549 unsigned char reversible_vlc : 1;
551 unsigned short vol_fields;
553 unsigned char no_of_sprite_warping_points;
554 short sprite_trajectory_du[3];
555 short sprite_trajectory_dv[3];
556 unsigned char quant_precision;
559 unsigned char vop_coding_type : 2;
560 unsigned char backward_reference_vop_coding_type : 2;
561 unsigned char vop_rounding_type : 1;
562 unsigned char intra_dc_vlc_thr : 3;
563 unsigned char top_field_first : 1;
564 unsigned char alternate_vertical_scan_flag : 1;
566 unsigned short vop_fields;
568 unsigned char vop_fcode_forward;
569 unsigned char vop_fcode_backward;
570 /* short header related */
571 unsigned char num_gobs_in_vop;
572 unsigned char num_macroblocks_in_gob;
573 /* for direct mode prediction */
576 } VAPictureParameterBufferMPEG4;
578 /* MPEG-4 Inverse Quantization Matrix Buffer */
579 typedef struct _VAIQMatrixBufferMPEG4
581 int load_intra_quant_mat;
582 int load_non_intra_quant_mat;
583 unsigned char intra_quant_mat[64];
584 unsigned char non_intra_quant_mat[64];
585 } VAIQMatrixBufferMPEG4;
587 /* MPEG-4 Slice Parameter Buffer */
588 typedef struct _VASliceParameterBufferMPEG4
590 unsigned int slice_data_size;/* number of bytes in the slice data buffer for this slice */
591 unsigned int slice_data_offset;/* the offset to the first byte of slice data */
592 unsigned int slice_data_flag; /* see VA_SLICE_DATA_FLAG_XXX defintions */
593 unsigned int macroblock_offset;/* the offset to the first bit of MB from the first byte of slice data */
594 unsigned int macroblock_number;
596 } VASliceParameterBufferMPEG4;
602 /* VC-1 Picture Parameter Buffer */
604 * For each picture, and before any slice data, a picture parameter
605 * buffer must be send. Multiple picture parameter buffers may be
606 * sent for a single picture. In that case picture parameters will
607 * apply to all slice data that follow it until a new picture
608 * parameter buffer is sent.
611 * pic_quantizer_type should be set to the applicable quantizer
612 * type as defined by QUANTIZER (J.1.19) and either
613 * PQUANTIZER (7.1.1.8) or PQINDEX (7.1.1.6)
615 typedef struct _VAPictureParameterBufferVC1
617 VASurfaceID forward_reference_picture;
618 VASurfaceID backward_reference_picture;
619 /* if out-of-loop post-processing is done on the render
620 target, then we need to keep the in-loop decoded
621 picture as a reference picture */
622 VASurfaceID inloop_decoded_picture;
624 /* sequence layer for AP or meta data for SP and MP */
627 unsigned char interlace : 1; /* SEQUENCE_LAYER::INTERLACE */
628 unsigned char syncmarker : 1;/* METADATA::SYNCMARKER */
629 unsigned char overlap : 1;/* METADATA::OVERLAP */
631 unsigned char sequence_fields;
634 unsigned short coded_width; /* ENTRY_POINT_LAYER::CODED_WIDTH */
635 unsigned short coded_height; /* ENTRY_POINT_LAYER::CODED_HEIGHT */
636 unsigned char closed_entry; /* ENTRY_POINT_LAYER::CLOSED_ENTRY */
637 unsigned char broken_link; /* ENTRY_POINT_LAYER::BROKEN_LINK */
638 unsigned char loopfilter; /* ENTRY_POINT_LAYER::LOOPFILTER */
639 unsigned char conditional_overlap_flag; /* ENTRY_POINT_LAYER::CONDOVER */
640 unsigned char fast_uvmc_flag; /* ENTRY_POINT_LAYER::FASTUVMC */
643 unsigned char range_mapping_luma_flag: 1; /* ENTRY_POINT_LAYER::RANGE_MAPY_FLAG */
644 unsigned char range_mapping_luma: 3; /* ENTRY_POINT_LAYER::RANGE_MAPY */
645 unsigned char range_mapping_chroma_flag: 1; /* ENTRY_POINT_LAYER::RANGE_MAPUV_FLAG */
646 unsigned char range_mapping_chroma: 3; /* ENTRY_POINT_LAYER::RANGE_MAPUV */
648 unsigned char range_mapping_fields;
651 unsigned char b_picture_fraction; /* PICTURE_LAYER::BFRACTION */
652 unsigned char cbp_table; /* PICTURE_LAYER::CBPTAB/ICBPTAB */
653 unsigned char mb_mode_table; /* PICTURE_LAYER::MBMODETAB */
654 unsigned char range_reduction_frame;/* PICTURE_LAYER::RANGEREDFRM */
655 unsigned char rounding_control; /* PICTURE_LAYER::RNDCTRL */
656 unsigned char post_processing; /* PICTURE_LAYER::POSTPROC */
657 unsigned char picture_resolution_index; /* PICTURE_LAYER::RESPIC */
658 unsigned char luma_scale; /* PICTURE_LAYER::LUMSCALE */
659 unsigned char luma_shift; /* PICTURE_LAYER::LUMSHIFT */
662 unsigned char picture_type : 2; /* PICTURE_LAYER::PTYPE */
663 unsigned char frame_coding_mode : 3;/* PICTURE_LAYER::FCM */
664 unsigned char top_field_first : 1;/* PICTURE_LAYER::TFF */
665 unsigned char is_first_field : 1; /* set to 1 if it is the first field */
666 unsigned char intensity_compensation: 1;/* PICTURE_LAYER::INTCOMP */
668 unsigned char picture_fields;
672 unsigned char mv_type_mb : 1; /* PICTURE::MVTYPEMB */
673 unsigned char direct_mb : 1; /* PICTURE::DIRECTMB */
674 unsigned char skip_mb : 1; /* PICTURE::SKIPMB */
675 unsigned char field_tx : 1; /* PICTURE::FIELDTX */
676 unsigned char foward_mb : 1; /* PICTURE::FORWARDMB */
677 unsigned char ac_pred : 1; /* PICTURE::ACPRED */
678 unsigned char overflags : 1; /* PICTURE::OVERFLAGS */
680 unsigned char raw_coding_flag;
684 unsigned char reference_distance_flag : 1;/* PICTURE_LAYER::REFDIST_FLAG */
685 unsigned char reference_distance : 1;/* PICTURE_LAYER::REFDIST */
686 unsigned char num_reference_pictures: 1;/* PICTURE_LAYER::NUMREF */
687 unsigned char reference_field_pic_indicator : 1;/* PICTURE_LAYER::REFFIELD */
689 unsigned short reference_fields;
693 unsigned char mv_mode : 2; /* PICTURE_LAYER::MVMODE */
694 unsigned char mv_mode2 : 2; /* PICTURE_LAYER::MVMODE2 */
695 unsigned char mv_table : 3;/* PICTURE_LAYER::MVTAB/IMVTAB */
696 unsigned char two_mv_block_pattern_table: 2;/* PICTURE_LAYER::2MVBPTAB */
697 unsigned char four_mv_switch: 1; /* PICTURE_LAYER::4MVSWITCH */
698 unsigned char four_mv_block_pattern_table : 2;/* PICTURE_LAYER::4MVBPTAB */
699 unsigned char extended_mv_flag: 1;/* ENTRY_POINT_LAYER::EXTENDED_MV */
700 unsigned char extended_mv_range : 2;/* PICTURE_LAYER::MVRANGE */
701 unsigned char extended_dmv_flag : 1;/* ENTRY_POINT_LAYER::EXTENDED_DMV */
702 unsigned char extended_dmv_range : 2;/* PICTURE_LAYER::DMVRANGE */
704 unsigned int mv_fields;
708 unsigned char dquant : 2; /* ENTRY_POINT_LAYER::DQUANT */
709 unsigned char half_qp : 1; /* PICTURE_LAYER::HALFQP */
710 unsigned char pic_quantizer_scale : 1;/* PICTURE_LAYER::PQUANT */
711 unsigned char pic_quantizer_type : 1;/* PICTURE_LAYER::PQUANTIZER */
712 unsigned char dq_frame : 1; /* VOPDQUANT::DQUANTFRM */
713 unsigned char dq_profile : 2; /* VOPDQUANT::DQPROFILE */
714 unsigned char dq_sb_edge : 2; /* VOPDQUANT::DQSBEDGE */
715 unsigned char dq_db_edge : 2; /* VOPDQUANT::DQDBEDGE */
716 unsigned char dq_binary_level : 1; /* VOPDQUANT::DQBILEVEL */
717 unsigned char alt_pic_quantizer : 5;/* VOPDQUANT::ALTPQUANT */
719 unsigned long pic_quantizer_fields;
723 unsigned char variable_sized_transform_flag : 1;/* ENTRY_POINT_LAYER::VSTRANSFORM */
724 unsigned char mb_level_transform_type_flag : 1;/* PICTURE_LAYER::TTMBF */
725 unsigned char frame_level_transform_type : 2;/* PICTURE_LAYER::TTFRM */
726 unsigned char transform_ac_codingset_idx1 : 2;/* PICTURE_LAYER::TRANSACFRM */
727 unsigned char transform_ac_codingset_idx2 : 2;/* PICTURE_LAYER::TRANSACFRM2 */
728 unsigned char intra_transform_dc_table : 1;/* PICTURE_LAYER::TRANSDCTAB */
730 unsigned short transform_fields;
732 } VAPictureParameterBufferVC1;
734 /* VC-1 Bitplane Buffer
735 There will be at most three bitplanes coded in any picture header. To send
736 the bitplane data more efficiently, each byte is divided in two nibbles, with
737 each nibble carrying three bitplanes for one macroblock. The following table
738 shows the bitplane data arrangement within each nibble based on the picture
741 Picture Type Bit3 Bit2 Bit1 Bit0
742 I or BI OVERFLAGS ACPRED FIELDTX
743 P MYTYPEMB SKIPMB DIRECTMB
744 B FORWARDMB SKIPMB DIRECTMB
746 Within each byte, the lower nibble is for the first MB and the upper nibble is
747 for the second MB. E.g. the lower nibble of the first byte in the bitplane
748 buffer is for Macroblock #1 and the upper nibble of the first byte is for
749 Macroblock #2 in the first row.
752 /* VC-1 Slice Parameter Buffer */
753 typedef struct _VASliceParameterBufferVC1
755 unsigned int slice_data_size;/* number of bytes in the slice data buffer for this slice */
756 unsigned int slice_data_offset;/* the offset to the first byte of slice data */
757 unsigned int slice_data_flag; /* see VA_SLICE_DATA_FLAG_XXX defintions */
758 unsigned int macroblock_offset;/* the offset to the first bit of MB from the first byte of slice data */
759 unsigned int slice_vertical_position;
760 } VASliceParameterBufferVC1;
762 /* VC-1 Slice Data Buffer */
764 This is simplely a buffer containing raw bit-stream bytes
767 /****************************
768 * H.264/AVC data structures
769 ****************************/
771 typedef struct _VAPictureH264
773 VASurfaceID picture_id;
775 unsigned int TopFieldOrderCnt;
776 unsigned int BottomFieldOrderCnt;
778 /* flags in VAPictureH264 could be OR of the following */
779 #define VA_PICTURE_H264_INVALID 0x00000001
780 #define VA_PICTURE_H264_TOP_FIELD 0x00000002
781 #define VA_PICTURE_H264_BOTTOM_FIELD 0x00000004
782 #define VA_PICTURE_H264_SHORT_TERM_REFERENCE 0x00000008
783 #define VA_PICTURE_H264_LONG_TERM_REFERENCE 0x00000010
784 #define VA_PICTURE_H264_USED_AS_REFERENCE 0x00000020
786 /* H.264 Picture Parameter Buffer */
788 * For each picture, and before any slice data, a single
789 * picture parameter buffer must be send.
791 typedef struct _VAPictureParameterBufferH264
793 VAPictureH264 CurrPic;
794 VAPictureH264 ReferenceFrames[16]; /* in DPB */
795 unsigned short picture_width_in_mbs_minus1;
796 unsigned short picture_height_in_mbs_minus1;
797 unsigned char bit_depth_luma_minus8;
798 unsigned char bit_depth_chroma_minus8;
799 unsigned char num_ref_frames;
802 unsigned char chroma_format_idc : 2;
803 unsigned char residual_colour_transform_flag : 1;
804 unsigned char frame_mbs_only_flag : 1;
805 unsigned char mb_adaptive_frame_field_flag : 1;
806 unsigned char direct_8x8_inference_flag : 1;
807 unsigned char MinLumaBiPredSize8x8 : 1; /* see A.3.3.2 */
809 unsigned char seq_fields;
811 unsigned char num_slice_groups_minus1;
812 unsigned char slice_group_map_type;
813 unsigned char pic_init_qp_minus26;
814 unsigned char chroma_qp_index_offset;
815 unsigned char second_chroma_qp_index_offset;
818 unsigned char entropy_coding_mode_flag : 1;
819 unsigned char weighted_pred_flag : 1;
820 unsigned char weighted_bipred_idc : 1;
821 unsigned char transform_8x8_mode_flag : 1;
822 unsigned char field_pic_flag : 1;
823 unsigned char constrained_intra_pred_flag : 1;
825 unsigned char pic_fields;
827 unsigned short frame_num;
828 } VAPictureParameterBufferH264;
830 /* H.264 Inverse Quantization Matrix Buffer */
831 typedef struct _VAIQMatrixBufferH264
833 unsigned char ScalingList4x4[6][16];
834 unsigned char ScalingList8x8[2][64];
835 } VAIQMatrixBufferH264;
838 * H.264 Slice Group Map Buffer
839 * When VAPictureParameterBufferH264::num_slice_group_minus1 is not equal to 0,
840 * A slice group map buffer should be sent for each picture if required. The buffer
841 * is sent only when there is a change in the mapping values.
842 * The slice group map buffer map "map units" to slice groups as specified in
843 * section 8.2.2 of the H.264 spec. The buffer will contain one byte for each macroblock
844 * in raster scan order
847 /* H.264 Slice Parameter Buffer */
848 typedef struct _VASliceParameterBufferH264
850 unsigned int slice_data_size;/* number of bytes in the slice data buffer for this slice */
851 unsigned int slice_data_offset;/* the offset to first byte of slice data */
852 unsigned int slice_data_flag; /* see VA_SLICE_DATA_FLAG_XXX defintions */
853 unsigned short slice_data_bit_offset; /* bit offset in the first byte of valid data */
854 unsigned short first_mb_in_slice;
855 unsigned char slice_type;
856 unsigned char direct_spatial_mv_pred_flag;
857 unsigned char num_ref_idx_l0_active_minus1;
858 unsigned char num_ref_idx_l1_active_minus1;
859 unsigned char cabac_init_idc;
861 unsigned char disable_deblocking_filter_idc;
862 char slice_alpha_c0_offset_div2;
863 char slice_beta_offset_div2;
864 VAPictureH264 RefPicList0[32]; /* See 8.2.4.2 */
865 VAPictureH264 RefPicList1[32]; /* See 8.2.4.2 */
866 unsigned char luma_log2_weight_denom;
867 unsigned char chroma_log2_weight_denom;
868 unsigned char luma_weight_l0_flag;
869 short luma_weight_l0[32];
870 short luma_offset_l0[32];
871 unsigned char chroma_weight_l0_flag;
872 short chroma_weight_l0[32][2];
873 short chroma_offset_l0[32][2];
874 unsigned char luma_weight_l1_flag;
875 short luma_weight_l1[32];
876 short luma_offset_l1[32];
877 unsigned char chroma_weight_l1_flag;
878 short chroma_weight_l1[32][2];
879 short chroma_offset_l1[32][2];
880 } VASliceParameterBufferH264;
882 /* Buffer functions */
885 * Creates a buffer for storing a certain type of data, no data store allocated
887 VAStatus vaCreateBuffer (
889 VABufferType type, /* in */
890 VABufferID *buf_id /* out */
894 * Create data store for the buffer and initalize with "data".
895 * if "data" is null, then the contents of the buffer data store
897 * Basically there are two ways to get buffer data to the server side. One is
898 * to call vaBufferData() with a non-null "data", which results the data being
899 * copied to the data store on the server side. A different method that
900 * eliminates this copy is to pass null as "data" when calling vaBufferData(),
901 * and then use vaMapBuffer() to map the data store from the server side to the
902 * client address space for access.
904 VAStatus vaBufferData (
906 VABufferID buf_id, /* in */
907 unsigned int size, /* in */
908 unsigned int num_elements, /* in */
913 * Convey to the server how many valid elements are in the buffer.
914 * e.g. if multiple slice parameters are being held in a single buffer,
915 * this will communicate to the server the number of slice parameters
916 * that are valid in the buffer.
918 VAStatus vaBufferSetNumElements (
920 VABufferID buf_id, /* in */
921 unsigned int num_elements /* in */
925 * Map data store of the buffer into the client's address space
926 * vaBufferData() needs to be called with "data" set to NULL before
927 * calling vaMapBuffer()
929 VAStatus vaMapBuffer (
931 VABufferID buf_id, /* in */
932 void **pbuf /* out */
936 * After client making changes to a mapped data store, it needs to
937 * "Unmap" it to let the server know that the data is ready to be
938 * consumed by the server
940 VAStatus vaUnmapBuffer (
942 VABufferID buf_id /* in */
946 * After this call, the buffer is deleted and this buffer_id is no longer valid
948 VAStatus vaDestroyBuffer (
954 Render (Decode) Pictures
956 A picture represents either a frame or a field.
958 The Begin/Render/End sequence sends the decode buffers to the server
962 * Get ready to decode a picture to a target surface
964 VAStatus vaBeginPicture (
967 VASurface *render_target
971 * Send decode buffers to the server.
973 VAStatus vaRenderPicture (
981 * Make the end of rendering for a picture.
982 * The server should start processing all pending operations for this
983 * surface. This call is non-blocking. The client can start another
984 * Begin/Render/End sequence on a different render target.
986 VAStatus vaEndPicture (
998 * This function blocks until all pending operations on the render target
999 * have been completed. Upon return it is safe to use the render target for a
1000 * different picture.
1002 VAStatus vaSyncSurface (
1005 VASurface *render_target
1010 VASurfaceRendering = 0,
1015 * Find out any pending ops on the render target
1017 VAStatus vaQuerySurfaceStatus (
1020 VASurface *render_target,
1021 VASurfaceStatus *status /* out */
1025 * Copies the surface to a buffer
1026 * The stride of the surface will be stored in *stride
1027 * Caller should free the returned buffer with free() when done.
1029 VAStatus vaDbgCopySurfaceToBuffer(VADisplay dpy,
1031 void **buffer, /* out */
1032 unsigned int *stride /* out */
1042 /*****************************************************************************/
1044 Sample Program (w/ pseudo code)
1046 Mostly to demonstrate program flow with no error handling ...
1048 /*****************************************************************************/
1050 /* MPEG-2 VLD decode for a 720x480 frame */
1052 int major_ver, minor_ver;
1053 vaInitialize(dpy, &major_ver, &minor_ver);
1055 int max_num_profiles, max_num_entrypoints, max_num_attribs;
1056 max_num_profiles = vaMaxNumProfiles(dpy);
1057 max_num_entrypoints = vaMaxNumProfiles(dpy);
1058 max_num_attribs = vaMaxNumProfiles(dpy);
1060 /* find out whether MPEG2 MP is supported */
1061 VAProfile *profiles = malloc(sizeof(VAProfile)*max_num_profiles);
1063 vaQueryConfigProfiles(dpy, profiles, &profiles);
1065 * traverse "profiles" to locate the one that matches VAProfileMPEG2Main
1068 /* now get the available entrypoints for MPEG2 MP */
1069 VAEntrypoint *entrypoints = malloc(sizeof(VAEntrypoint)*max_num_entrypoints);
1070 int num_entrypoints;
1071 vaQueryConfigEntrypoints(dpy, VAProfileMPEG2Main, entrypoints, &num_entrypoints);
1073 /* traverse "entrypoints" to see whether VLD is there */
1075 /* Assuming finding VLD, find out the format for the render target */
1076 VAConfigAttrib attrib;
1077 attrib.type = VAConfigAttribRTFormat;
1078 vaQueryConfigAttributes(dpy, VAProfileMPEG2Main, VAEntrypointVLD,
1081 if (attrib.value & VA_RT_FORMAT_YUV420)
1082 /* Found desired RT format, keep going */
1084 VAConfigID config_id;
1085 vaCreateConfig(dpy, VAProfileMPEG2Main, VAEntrypointVLD, &attrib, 1,
1089 * create surfaces for the current target as well as reference frames
1090 * we can get by with 4 surfaces for MPEG-2
1092 VASurface surfaces[4];
1093 vaCreateSurfaces(dpy, 720, 480, VA_RT_FORMAT_YUV420, 4, surfaces);
1096 * Create a context for this decode pipe
1099 vaCreateContext(dpy, config_id, 720, 480, VA_PROGRESSIVE, surfaces,
1102 /* Create a picture parameter buffer for this frame */
1103 VABufferID picture_buf;
1104 VAPictureParameterBufferMPEG2 *picture_param;
1105 vaCreateBuffer(dpy, VAPictureParameterBufferType, &picture_buf);
1106 vaBufferData(dpy, picture_buf, sizeof(VAPictureParameterBufferMPEG2), NULL);
1107 vaMapBuffer(dpy, picture_buf, &picture_param);
1108 picture_param->horizontal_size = 720;
1109 picture_param->vertical_size = 480;
1110 picture_param->picture_coding_type = 1; /* I-frame */
1111 /* fill in picture_coding_extension fields here */
1112 vaUnmapBuffer(dpy, picture_buf);
1115 /* Create an IQ matrix buffer for this frame */
1117 VAIQMatrixBufferMPEG2 *iq_matrix;
1118 vaCreateBuffer(dpy, VAIQMatrixBufferType, &iq_buf);
1119 vaBufferData(dpy, iq_buf, sizeof(VAIQMatrixBufferMPEG2), NULL);
1120 vaMapBuffer(dpy, iq_buf, &iq_matrix);
1121 /* fill values for IQ_matrix here */
1122 vaUnmapBuffer(dpy, iq_buf);
1124 /* send the picture and IQ matrix buffers to the server */
1125 vaBeginPicture(dpy, context, &surfaces[0]);
1127 vaRenderPicture(dpy, context, &picture_buf, 1);
1128 vaRenderPicture(dpy, context, &iq_buf, 1);
1131 * Send slices in this frame to the server.
1132 * For MPEG-2, each slice is one row of macroblocks, and
1133 * we have 30 slices for a 720x480 frame
1135 for (int i = 1; i <= 30; i++) {
1137 /* Create a slice parameter buffer */
1138 VABufferID slice_param_buf;
1139 VASliceParameterBufferMPEG2 *slice_param;
1140 vaCreateBuffer(dpy, VASliceParameterBufferType, &slice_param_buf);
1141 vaBufferData(dpy, slice_param_buf, sizeof(VASliceParameterBufferMPEG2), NULL);
1142 vaMapBuffer(dpy, slice_param_buf, &slice_param);
1143 slice_param->slice_data_offset = 0;
1144 /* Let's say all slices in this bit-stream has 64-bit header */
1145 slice_param->macroblock_offset = 64;
1146 slice_param->vertical_position = i;
1147 /* set up the rest based on what is in the slice header ... */
1148 vaUnmapBuffer(dpy, slice_param_buf);
1150 /* send the slice parameter buffer */
1151 vaRenderPicture(dpy, context, &slice_param_buf, 1);
1153 /* Create a slice data buffer */
1154 unsigned char *slice_data;
1155 VABufferID slice_data_buf;
1156 vaCreateBuffer(dpy, VASliceDataBufferType, slice_data_buf);
1157 vaBufferData(dpy, slice_data_buf, x /* decoder figure out how big */, NULL);
1158 vaMapBuffer(dpy, slice_data_buf, &slice_data);
1159 /* decoder fill in slice_data */
1160 vaUnmapBuffer(dpy, slice_data_buf);
1162 /* send the slice data buffer */
1163 vaRenderPicture(dpy, context, &slice_data_buf, 1);
1166 /* all slices have been sent, mark the end for this frame */
1167 vaEndPicture(dpy, context);