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.
43 * rev 0.21 (08/20/2007 Jonathan Bian) - Added image and subpicture support.
44 * rev 0.22 (08/27/2007 Jonathan Bian) - Added support for chroma-keying and global alpha.
45 * rev 0.23 (09/11/2007 Jonathan Bian) - Fixed some issues with images and subpictures.
46 * rev 0.24 (09/18/2007 Jonathan Bian) - Added display attributes.
47 * rev 0.25 (10/18/2007 Jonathan Bian) - Changed to use IDs only for some types.
48 * rev 0.26 (11/07/2007 Waldo Bastian) - Change vaCreateBuffer semantics
51 * Some concepts borrowed from XvMC and XvImage.
52 * Thanks to Waldo Bastian, Matt Sottek and Austin Yuan at Intel for many valuable feedbacks.
65 This API is intended to provide an interface between a video decode
66 application (client) and a hardware decode accelerator (server), to off-load
67 video decode operations from the host to the hardware accelerator at various
70 The basic operation steps are:
72 - Negotiate a mutually acceptable configuration with the server to lock
73 down profile, entrypoints, and other attributes that will not change on
74 a frame-by-frame basis.
75 - Create a decode context which represents a "virtualized" hardware decode
77 - Get and fill decode buffers with picture level, slice level and macroblock
78 level data (depending on entrypoints)
79 - Pass the decode buffers to the server to decode the current frame
81 Initialization & Configuration Management
83 - Find out supported profiles
84 - Find out entrypoints for a given profile
85 - Find out configuration attributes for a given profile/entrypoint pair
86 - Create a configuration for use by the decoder
90 typedef void* VADisplay; /* window system dependent */
92 typedef int VAStatus; /* Return status type from functions */
93 /* Values for the return status */
94 #define VA_STATUS_SUCCESS 0x00000000
95 #define VA_STATUS_ERROR_OPERATION_FAILED 0x00000001
96 #define VA_STATUS_ERROR_ALLOCATION_FAILED 0x00000002
97 #define VA_STATUS_ERROR_INVALID_DISPLAY 0x00000003
98 #define VA_STATUS_ERROR_INVALID_CONFIG 0x00000004
99 #define VA_STATUS_ERROR_INVALID_CONTEXT 0x00000005
100 #define VA_STATUS_ERROR_INVALID_SURFACE 0x00000006
101 #define VA_STATUS_ERROR_INVALID_BUFFER 0x00000007
102 #define VA_STATUS_ERROR_INVALID_IMAGE 0x00000008
103 #define VA_STATUS_ERROR_INVALID_SUBPICTURE 0x00000009
104 #define VA_STATUS_ERROR_ATTR_NOT_SUPPORTED 0x0000000a
105 #define VA_STATUS_ERROR_MAX_NUM_EXCEEDED 0x0000000b
106 #define VA_STATUS_ERROR_UNSUPPORTED_PROFILE 0x0000000c
107 #define VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT 0x0000000d
108 #define VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT 0x0000000e
109 #define VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE 0x0000000f
110 #define VA_STATUS_ERROR_SURFACE_BUSY 0x00000010
111 #define VA_STATUS_ERROR_UNKNOWN 0xFFFFFFFF
114 * Returns a short english description of error_status
116 const char *vaErrorStr(VAStatus error_status);
120 * A display must be obtained by calling vaGetDisplay() before calling
121 * vaInitialize() and other functions. This connects the API to the
122 * native window system.
123 * For X Windows, native_dpy would be from XOpenDisplay()
125 typedef void* NativeDisplay; /* window system dependent */
127 VADisplay vaGetDisplay (
128 NativeDisplay native_dpy /* implementation specific */
132 * Initialize the library
134 VAStatus vaInitialize (
136 int *major_version, /* out */
137 int *minor_version /* out */
141 * After this call, all library internal resources will be cleaned up
143 VAStatus vaTerminate (
148 * vaQueryVendorString returns a pointer to a zero-terminated string
149 * describing some aspects of the VA implemenation on a specific
150 * hardware accelerator. The format of the returned string is:
151 * <vendorname>-<major_version>-<minor_version>-<addtional_info>
152 * e.g. for the Intel GMA500 implementation, an example would be:
153 * "IntelGMA500-1.0-0.2-patch3
155 const char *vaQueryVendorString (
159 /* Currently defined profiles */
162 VAProfileMPEG2Simple = 0,
163 VAProfileMPEG2Main = 1,
164 VAProfileMPEG4Simple = 2,
165 VAProfileMPEG4AdvancedSimple = 3,
166 VAProfileMPEG4Main = 4,
167 VAProfileH264Baseline = 5,
168 VAProfileH264Main = 6,
169 VAProfileH264High = 7,
170 VAProfileVC1Simple = 8,
171 VAProfileVC1Main = 9,
172 VAProfileVC1Advanced = 10,
176 * Currently defined entrypoints
182 VAEntrypointIDCT = 3,
183 VAEntrypointMoComp = 4,
184 VAEntrypointDeblocking = 5,
187 /* Currently defined configuration attribute types */
190 VAConfigAttribRTFormat = 0,
191 VAConfigAttribSpatialResidual = 1,
192 VAConfigAttribSpatialClipping = 2,
193 VAConfigAttribIntraResidual = 3,
194 VAConfigAttribEncryption = 4,
195 } VAConfigAttribType;
198 * Configuration attributes
199 * If there is more than one value for an attribute, a default
200 * value will be assigned to the attribute if the client does not
201 * specify the attribute when creating a configuration
203 typedef struct _VAConfigAttrib {
204 VAConfigAttribType type;
205 unsigned int value; /* OR'd flags (bits) for this attribute */
208 /* attribute value for VAConfigAttribRTFormat */
209 #define VA_RT_FORMAT_YUV420 0x00000001
210 #define VA_RT_FORMAT_YUV422 0x00000002
211 #define VA_RT_FORMAT_YUV444 0x00000004
214 * if an attribute is not applicable for a given
215 * profile/entrypoint pair, then set the value to the following
217 #define VA_ATTRIB_NOT_SUPPORTED 0x80000000
219 /* Get maximum number of profiles supported by the implementation */
220 int vaMaxNumProfiles (
224 /* Get maximum number of entrypoints supported by the implementation */
225 int vaMaxNumEntrypoints (
229 /* Get maximum number of attributs supported by the implementation */
230 int vaMaxNumConfigAttributes (
235 * Query supported profiles
236 * The caller must provide a "profile_list" array that can hold at
237 * least vaMaxNumProfile() entries. The actual number of profiles
238 * returned in "profile_list" is returned in "num_profile".
240 VAStatus vaQueryConfigProfiles (
242 VAProfile *profile_list, /* out */
243 int *num_profiles /* out */
247 * Query supported entrypoints for a given profile
248 * The caller must provide an "entrypoint_list" array that can hold at
249 * least vaMaxNumEntrypoints() entries. The actual number of entrypoints
250 * returned in "entrypoint_list" is returned in "num_entrypoints".
252 VAStatus vaQueryConfigEntrypoints (
255 VAEntrypoint *entrypoint_list, /* out */
256 int *num_entrypoints /* out */
260 * Get attributes for a given profile/entrypoint pair
261 * The caller must provide an "attrib_list" with all attributes to be
262 * retrieved. Upon return, the attributes in "attrib_list" have been
263 * updated with their value. Unknown attributes or attributes that are
264 * not supported for the given profile/entrypoint pair will have their
265 * value set to VA_ATTRIB_NOT_SUPPORTED
267 VAStatus vaGetConfigAttributes (
270 VAEntrypoint entrypoint,
271 VAConfigAttrib *attrib_list, /* in/out */
275 /* Generic ID type, can be re-typed for specific implementation */
276 typedef unsigned int VAGenericID;
278 typedef VAGenericID VAConfigID;
281 * Create a configuration for the decode pipeline
282 * it passes in the attribute list that specifies the attributes it cares
283 * about, with the rest taking default values.
285 VAStatus vaCreateConfig (
288 VAEntrypoint entrypoint,
289 VAConfigAttrib *attrib_list,
291 VAConfigID *config_id /* out */
295 * Free resources associdated with a given config
297 VAStatus vaDestroyConfig (
303 * Query all attributes for a given configuration
304 * The profile of the configuration is returned in "profile"
305 * The entrypoint of the configuration is returned in "entrypoint"
306 * The caller must provide an "attrib_list" array that can hold at least
307 * vaMaxNumConfigAttributes() entries. The actual number of attributes
308 * returned in "attrib_list" is returned in "num_attribs"
310 VAStatus vaQueryConfigAttributes (
312 VAConfigID config_id,
313 VAProfile *profile, /* out */
314 VAEntrypoint *entrypoint, /* out */
315 VAConfigAttrib *attrib_list,/* out */
316 int *num_attribs /* out */
321 * Contexts and Surfaces
323 * Context represents a "virtual" video decode pipeline. Surfaces are render
324 * targets for a given context. The data in the surfaces are not accessible
325 * to the client and the internal data format of the surface is implementatin
328 * Surfaces will be bound to a context when the context is created. Once
329 * a surface is bound to a given context, it can not be used to create
330 * another context. The association is removed when the context is destroyed
332 * Both contexts and surfaces are identified by unique IDs and its
333 * implementation specific internals are kept opaque to the clients
336 typedef VAGenericID VAContextID;
338 typedef VAGenericID VASurfaceID;
340 #define VA_INVALID_SURFACE -1
343 * vaCreateSurfaces - Create an array of surfaces used for decode and display
345 * width: surface width
346 * height: surface height
347 * format: VA_RT_FORMAT_YUV420, VA_RT_FORMAT_YUV422 or VA_RT_FORMAT_YUV444
348 * num_surfaces: number of surfaces to be created
349 * surfaces: array of surfaces created upon return
351 VAStatus vaCreateSurfaces (
357 VASurfaceID *surfaces /* out */
361 * vaDestroySurfaces - Destroy resources associated with surfaces.
362 * Surfaces can only be destroyed after the context associated has been
365 * surfaces: array of surfaces to destroy
366 * num_surfaces: number of surfaces in the array to be destroyed.
368 VAStatus vaDestroySurfaces (
370 VASurfaceID *surfaces,
374 #define VA_PROGRESSIVE 0x1
376 * vaCreateContext - Create a context
378 * config_id: configuration for the context
379 * picture_width: coded picture width
380 * picture_height: coded picture height
381 * flag: any combination of the following:
382 * VA_PROGRESSIVE (only progressive frame pictures in the sequence when set)
383 * render_targets: render targets (surfaces) tied to the context
384 * num_render_targets: number of render targets in the above array
385 * context: created context id upon return
387 VAStatus vaCreateContext (
389 VAConfigID config_id,
393 VASurfaceID *render_targets,
394 int num_render_targets,
395 VAContextID *context /* out */
399 * vaDestroyContext - Destroy a context
401 * context: context to be destroyed
403 VAStatus vaDestroyContext (
410 * Buffers are used to pass various types of data from the
411 * client to the server. The server maintains a data store
412 * for each buffer created, and the client idenfies a buffer
413 * through a unique buffer id assigned by the server.
416 typedef VAGenericID VABufferID;
420 VAPictureParameterBufferType = 0,
421 VAIQMatrixBufferType = 1,
422 VABitPlaneBufferType = 2,
423 VASliceGroupMapBufferType = 3,
424 VASliceParameterBufferType = 4,
425 VASliceDataBufferType = 5,
426 VAMacroblockParameterBufferType = 6,
427 VAResidualDataBufferType = 7,
428 VADeblockingParameterBufferType = 8,
429 VAImageBufferType = 9
432 /****************************
433 * MPEG-2 data structures
434 ****************************/
436 /* MPEG-2 Picture Parameter Buffer */
438 * For each frame or field, and before any slice data, a single
439 * picture parameter buffer must be send.
441 typedef struct _VAPictureParameterBufferMPEG2
443 unsigned short horizontal_size;
444 unsigned short vertical_size;
445 VASurfaceID forward_reference_picture;
446 VASurfaceID backward_reference_picture;
447 /* meanings of the following fields are the same as in the standard */
448 int picture_coding_type;
449 int f_code; /* pack all four fcode into this */
452 unsigned char intra_dc_precision : 2;
453 unsigned char picture_structure : 2;
454 unsigned char top_field_first : 1;
455 unsigned char frame_pred_frame_dct : 1;
456 unsigned char concealment_motion_vectors : 1;
457 unsigned char q_scale_type : 1;
458 unsigned char intra_vlc_format : 1;
459 unsigned char alternate_scan : 1;
460 unsigned char repeat_first_field : 1;
461 unsigned char progressive_frame : 1;
462 unsigned char is_first_field : 1; /* indicate whether the current field
463 * is the first field for field picture
466 unsigned int picture_coding_extension;
468 } VAPictureParameterBufferMPEG2;
470 /* MPEG-2 Inverse Quantization Matrix Buffer */
471 typedef struct _VAIQMatrixBufferMPEG2
473 int load_intra_quantiser_matrix;
474 int load_non_intra_quantiser_matrix;
475 int load_chroma_intra_quantiser_matrix;
476 int load_chroma_non_intra_quantiser_matrix;
477 unsigned char intra_quantiser_matrix[64];
478 unsigned char non_intra_quantiser_matrix[64];
479 unsigned char chroma_intra_quantiser_matrix[64];
480 unsigned char chroma_non_intra_quantiser_matrix[64];
481 } VAIQMatrixBufferMPEG2;
484 * There will be cases where the bitstream buffer will not have enough room to hold
485 * the data for the entire slice, and the following flags will be used in the slice
486 * parameter to signal to the server for the possible cases.
487 * If a slice parameter buffer and slice data buffer pair is sent to the server with
488 * the slice data partially in the slice data buffer (BEGIN and MIDDLE cases below),
489 * then a slice parameter and data buffer needs to be sent again to complete this slice.
491 #define VA_SLICE_DATA_FLAG_ALL 0x00 /* whole slice is in the buffer */
492 #define VA_SLICE_DATA_FLAG_BEGIN 0x01 /* The beginning of the slice is in the buffer but the end if not */
493 #define VA_SLICE_DATA_FLAG_MIDDLE 0x02 /* Neither beginning nor end of the slice is in the buffer */
494 #define VA_SLICE_DATA_FLAG_END 0x04 /* end of the slice is in the buffer */
496 /* MPEG-2 Slice Parameter Buffer */
497 typedef struct _VASliceParameterBufferMPEG2
499 unsigned int slice_data_size;/* number of bytes in the slice data buffer for this slice */
500 unsigned int slice_data_offset;/* the offset to the first byte of slice data */
501 unsigned int slice_data_flag; /* see VA_SLICE_DATA_FLAG_XXX defintions */
502 unsigned int macroblock_offset;/* the offset to the first bit of MB from the first byte of slice data */
503 unsigned int slice_vertical_position;
504 int quantiser_scale_code;
505 int intra_slice_flag;
506 } VASliceParameterBufferMPEG2;
508 /* MPEG-2 Macroblock Parameter Buffer */
509 typedef struct _VAMacroblockParameterBufferMPEG2
511 unsigned short macroblock_address;
513 * macroblock_address (in raster scan order)
515 * bottom-right: picture-height-in-mb*picture-width-in-mb - 1
517 unsigned char macroblock_type; /* see definition below */
520 unsigned char frame_motion_type : 2;
521 unsigned char field_motion_type : 2;
522 unsigned char dct_type : 1;
524 unsigned char macroblock_modes;
526 unsigned char motion_vertical_field_select;
528 * motion_vertical_field_select:
529 * see section 6.3.17.2 in the spec
530 * only the lower 4 bits are used
531 * bit 0: first vector forward
532 * bit 1: first vector backward
533 * bit 2: second vector forward
534 * bit 3: second vector backward
536 short PMV[2][2][2]; /* see Table 7-7 in the spec */
537 unsigned short coded_block_pattern;
539 * The bitplanes for coded_block_pattern are described
540 * in Figure 6.10-12 in the spec
543 /* Number of skipped macroblocks after this macroblock */
544 unsigned short num_skipped_macroblocks;
545 } VAMacroblockParameterBufferMPEG2;
548 * OR'd flags for macroblock_type (section 6.3.17.1 in the spec)
550 #define VA_MB_TYPE_MOTION_FORWARD 0x02
551 #define VA_MB_TYPE_MOTION_BACKWARD 0x04
552 #define VA_MB_TYPE_MOTION_PATTERN 0x08
553 #define VA_MB_TYPE_MOTION_INTRA 0x10
556 * MPEG-2 Residual Data Buffer
557 * For each macroblock, there wil be 64 shorts (16-bit) in the
558 * residual data buffer
561 /****************************
562 * MPEG-4 Part 2 data structures
563 ****************************/
565 /* MPEG-4 Picture Parameter Buffer */
567 * For each frame or field, and before any slice data, a single
568 * picture parameter buffer must be send.
570 typedef struct _VAPictureParameterBufferMPEG4
572 unsigned short vop_width;
573 unsigned short vop_height;
574 VASurfaceID forward_reference_picture;
575 VASurfaceID backward_reference_picture;
578 unsigned char short_video_header : 1;
579 unsigned char chroma_format : 2;
580 unsigned char interlaced : 1;
581 unsigned char obmc_disable : 1;
582 unsigned char sprite_enable : 2;
583 unsigned char sprite_warping_accuracy : 2;
584 unsigned char quant_type : 1;
585 unsigned char quarter_sample : 1;
586 unsigned char data_partitioned : 1;
587 unsigned char reversible_vlc : 1;
589 unsigned short vol_fields;
591 unsigned char no_of_sprite_warping_points;
592 short sprite_trajectory_du[3];
593 short sprite_trajectory_dv[3];
594 unsigned char quant_precision;
597 unsigned char vop_coding_type : 2;
598 unsigned char backward_reference_vop_coding_type : 2;
599 unsigned char vop_rounding_type : 1;
600 unsigned char intra_dc_vlc_thr : 3;
601 unsigned char top_field_first : 1;
602 unsigned char alternate_vertical_scan_flag : 1;
604 unsigned short vop_fields;
606 unsigned char vop_fcode_forward;
607 unsigned char vop_fcode_backward;
608 /* short header related */
609 unsigned char num_gobs_in_vop;
610 unsigned char num_macroblocks_in_gob;
611 /* for direct mode prediction */
614 } VAPictureParameterBufferMPEG4;
616 /* MPEG-4 Inverse Quantization Matrix Buffer */
617 typedef struct _VAIQMatrixBufferMPEG4
619 int load_intra_quant_mat;
620 int load_non_intra_quant_mat;
621 unsigned char intra_quant_mat[64];
622 unsigned char non_intra_quant_mat[64];
623 } VAIQMatrixBufferMPEG4;
625 /* MPEG-4 Slice Parameter Buffer */
626 typedef struct _VASliceParameterBufferMPEG4
628 unsigned int slice_data_size;/* number of bytes in the slice data buffer for this slice */
629 unsigned int slice_data_offset;/* the offset to the first byte of slice data */
630 unsigned int slice_data_flag; /* see VA_SLICE_DATA_FLAG_XXX defintions */
631 unsigned int macroblock_offset;/* the offset to the first bit of MB from the first byte of slice data */
632 unsigned int macroblock_number;
634 } VASliceParameterBufferMPEG4;
640 typedef enum /* see 7.1.1.32 */
643 VAMvMode1MvHalfPel = 1,
644 VAMvMode1MvHalfPelBilinear = 2,
646 VAMvModeIntensityCompensation = 4
649 /* VC-1 Picture Parameter Buffer */
651 * For each picture, and before any slice data, a picture parameter
652 * buffer must be send. Multiple picture parameter buffers may be
653 * sent for a single picture. In that case picture parameters will
654 * apply to all slice data that follow it until a new picture
655 * parameter buffer is sent.
658 * pic_quantizer_type should be set to the applicable quantizer
659 * type as defined by QUANTIZER (J.1.19) and either
660 * PQUANTIZER (7.1.1.8) or PQINDEX (7.1.1.6)
662 typedef struct _VAPictureParameterBufferVC1
664 VASurfaceID forward_reference_picture;
665 VASurfaceID backward_reference_picture;
666 /* if out-of-loop post-processing is done on the render
667 target, then we need to keep the in-loop decoded
668 picture as a reference picture */
669 VASurfaceID inloop_decoded_picture;
671 /* sequence layer for AP or meta data for SP and MP */
674 unsigned char interlace : 1; /* SEQUENCE_LAYER::INTERLACE */
675 unsigned char syncmarker : 1;/* METADATA::SYNCMARKER */
676 unsigned char overlap : 1;/* METADATA::OVERLAP */
678 unsigned char sequence_fields;
681 unsigned short coded_width; /* ENTRY_POINT_LAYER::CODED_WIDTH */
682 unsigned short coded_height; /* ENTRY_POINT_LAYER::CODED_HEIGHT */
683 unsigned char closed_entry; /* ENTRY_POINT_LAYER::CLOSED_ENTRY */
684 unsigned char broken_link; /* ENTRY_POINT_LAYER::BROKEN_LINK */
685 unsigned char loopfilter; /* ENTRY_POINT_LAYER::LOOPFILTER */
686 unsigned char conditional_overlap_flag; /* ENTRY_POINT_LAYER::CONDOVER */
687 unsigned char fast_uvmc_flag; /* ENTRY_POINT_LAYER::FASTUVMC */
690 unsigned char range_mapping_luma_flag: 1; /* ENTRY_POINT_LAYER::RANGE_MAPY_FLAG */
691 unsigned char range_mapping_luma: 3; /* ENTRY_POINT_LAYER::RANGE_MAPY */
692 unsigned char range_mapping_chroma_flag: 1; /* ENTRY_POINT_LAYER::RANGE_MAPUV_FLAG */
693 unsigned char range_mapping_chroma: 3; /* ENTRY_POINT_LAYER::RANGE_MAPUV */
695 unsigned char range_mapping_fields;
698 unsigned char b_picture_fraction; /* PICTURE_LAYER::BFRACTION */
699 unsigned char cbp_table; /* PICTURE_LAYER::CBPTAB/ICBPTAB */
700 unsigned char mb_mode_table; /* PICTURE_LAYER::MBMODETAB */
701 unsigned char range_reduction_frame;/* PICTURE_LAYER::RANGEREDFRM */
702 unsigned char rounding_control; /* PICTURE_LAYER::RNDCTRL */
703 unsigned char post_processing; /* PICTURE_LAYER::POSTPROC */
704 unsigned char picture_resolution_index; /* PICTURE_LAYER::RESPIC */
705 unsigned char luma_scale; /* PICTURE_LAYER::LUMSCALE */
706 unsigned char luma_shift; /* PICTURE_LAYER::LUMSHIFT */
709 unsigned char picture_type : 2; /* PICTURE_LAYER::PTYPE */
710 unsigned char frame_coding_mode : 3;/* PICTURE_LAYER::FCM */
711 unsigned char top_field_first : 1;/* PICTURE_LAYER::TFF */
712 unsigned char is_first_field : 1; /* set to 1 if it is the first field */
713 unsigned char intensity_compensation: 1;/* PICTURE_LAYER::INTCOMP */
715 unsigned char picture_fields;
719 unsigned char mv_type_mb : 1; /* PICTURE::MVTYPEMB */
720 unsigned char direct_mb : 1; /* PICTURE::DIRECTMB */
721 unsigned char skip_mb : 1; /* PICTURE::SKIPMB */
722 unsigned char field_tx : 1; /* PICTURE::FIELDTX */
723 unsigned char forward_mb : 1; /* PICTURE::FORWARDMB */
724 unsigned char ac_pred : 1; /* PICTURE::ACPRED */
725 unsigned char overflags : 1; /* PICTURE::OVERFLAGS */
727 unsigned char raw_coding_flag;
731 unsigned char bp_mv_type_mb : 1; /* PICTURE::MVTYPEMB */
732 unsigned char bp_direct_mb : 1; /* PICTURE::DIRECTMB */
733 unsigned char bp_skip_mb : 1; /* PICTURE::SKIPMB */
734 unsigned char bp_field_tx : 1; /* PICTURE::FIELDTX */
735 unsigned char bp_forward_mb : 1; /* PICTURE::FORWARDMB */
736 unsigned char bp_ac_pred : 1; /* PICTURE::ACPRED */
737 unsigned char bp_overflags : 1; /* PICTURE::OVERFLAGS */
739 unsigned char bitplane_present_flag; /* signal what bitplane is being passed via the bitplane buffer */
743 unsigned char reference_distance_flag : 1;/* PICTURE_LAYER::REFDIST_FLAG */
744 unsigned char reference_distance : 1;/* PICTURE_LAYER::REFDIST */
745 unsigned char num_reference_pictures: 1;/* PICTURE_LAYER::NUMREF */
746 unsigned char reference_field_pic_indicator : 1;/* PICTURE_LAYER::REFFIELD */
748 unsigned short reference_fields;
752 VAMvModeVC1 mv_mode : 3; /* PICTURE_LAYER::MVMODE */
753 VAMvModeVC1 mv_mode2 : 3; /* PICTURE_LAYER::MVMODE2 */
754 unsigned char mv_table : 3; /* PICTURE_LAYER::MVTAB/IMVTAB */
755 unsigned char two_mv_block_pattern_table: 2; /* PICTURE_LAYER::2MVBPTAB */
756 unsigned char four_mv_switch : 1; /* PICTURE_LAYER::4MVSWITCH */
757 unsigned char four_mv_block_pattern_table : 2; /* PICTURE_LAYER::4MVBPTAB */
758 unsigned char extended_mv_flag : 1; /* ENTRY_POINT_LAYER::EXTENDED_MV */
759 unsigned char extended_mv_range : 2; /* PICTURE_LAYER::MVRANGE */
760 unsigned char extended_dmv_flag : 1; /* ENTRY_POINT_LAYER::EXTENDED_DMV */
761 unsigned char extended_dmv_range : 2; /* PICTURE_LAYER::DMVRANGE */
763 unsigned int mv_fields;
767 unsigned char dquant : 2; /* ENTRY_POINT_LAYER::DQUANT */
768 unsigned char half_qp : 1; /* PICTURE_LAYER::HALFQP */
769 unsigned char pic_quantizer_scale : 5;/* PICTURE_LAYER::PQUANT */
770 unsigned char pic_quantizer_type : 1;/* PICTURE_LAYER::PQUANTIZER */
771 unsigned char dq_frame : 1; /* VOPDQUANT::DQUANTFRM */
772 unsigned char dq_profile : 2; /* VOPDQUANT::DQPROFILE */
773 unsigned char dq_sb_edge : 2; /* VOPDQUANT::DQSBEDGE */
774 unsigned char dq_db_edge : 2; /* VOPDQUANT::DQDBEDGE */
775 unsigned char dq_binary_level : 1; /* VOPDQUANT::DQBILEVEL */
776 unsigned char alt_pic_quantizer : 5;/* VOPDQUANT::ALTPQUANT */
778 unsigned long pic_quantizer_fields;
782 unsigned char variable_sized_transform_flag : 1;/* ENTRY_POINT_LAYER::VSTRANSFORM */
783 unsigned char mb_level_transform_type_flag : 1;/* PICTURE_LAYER::TTMBF */
784 unsigned char frame_level_transform_type : 2;/* PICTURE_LAYER::TTFRM */
785 unsigned char transform_ac_codingset_idx1 : 2;/* PICTURE_LAYER::TRANSACFRM */
786 unsigned char transform_ac_codingset_idx2 : 2;/* PICTURE_LAYER::TRANSACFRM2 */
787 unsigned char intra_transform_dc_table : 1;/* PICTURE_LAYER::TRANSDCTAB */
789 unsigned short transform_fields;
791 } VAPictureParameterBufferVC1;
793 /* VC-1 Bitplane Buffer
794 There will be at most three bitplanes coded in any picture header. To send
795 the bitplane data more efficiently, each byte is divided in two nibbles, with
796 each nibble carrying three bitplanes for one macroblock. The following table
797 shows the bitplane data arrangement within each nibble based on the picture
800 Picture Type Bit3 Bit2 Bit1 Bit0
801 I or BI OVERFLAGS ACPRED FIELDTX
802 P MYTYPEMB SKIPMB DIRECTMB
803 B FORWARDMB SKIPMB DIRECTMB
805 Within each byte, the lower nibble is for the first MB and the upper nibble is
806 for the second MB. E.g. the lower nibble of the first byte in the bitplane
807 buffer is for Macroblock #1 and the upper nibble of the first byte is for
808 Macroblock #2 in the first row.
811 /* VC-1 Slice Parameter Buffer */
812 typedef struct _VASliceParameterBufferVC1
814 unsigned int slice_data_size;/* number of bytes in the slice data buffer for this slice */
815 unsigned int slice_data_offset;/* the offset to the first byte of slice data */
816 unsigned int slice_data_flag; /* see VA_SLICE_DATA_FLAG_XXX defintions */
817 unsigned int macroblock_offset;/* the offset to the first bit of MB from the first byte of slice data */
818 unsigned int slice_vertical_position;
819 } VASliceParameterBufferVC1;
821 /* VC-1 Slice Data Buffer */
823 This is simplely a buffer containing raw bit-stream bytes
826 /****************************
827 * H.264/AVC data structures
828 ****************************/
830 typedef struct _VAPictureH264
832 VASurfaceID picture_id;
834 unsigned int TopFieldOrderCnt;
835 unsigned int BottomFieldOrderCnt;
837 /* flags in VAPictureH264 could be OR of the following */
838 #define VA_PICTURE_H264_INVALID 0x00000001
839 #define VA_PICTURE_H264_TOP_FIELD 0x00000002
840 #define VA_PICTURE_H264_BOTTOM_FIELD 0x00000004
841 #define VA_PICTURE_H264_SHORT_TERM_REFERENCE 0x00000008
842 #define VA_PICTURE_H264_LONG_TERM_REFERENCE 0x00000010
844 /* H.264 Picture Parameter Buffer */
846 * For each picture, and before any slice data, a single
847 * picture parameter buffer must be send.
849 typedef struct _VAPictureParameterBufferH264
851 VAPictureH264 CurrPic;
852 VAPictureH264 ReferenceFrames[16]; /* in DPB */
853 unsigned short picture_width_in_mbs_minus1;
854 unsigned short picture_height_in_mbs_minus1;
855 unsigned char bit_depth_luma_minus8;
856 unsigned char bit_depth_chroma_minus8;
857 unsigned char num_ref_frames;
860 unsigned char chroma_format_idc : 2;
861 unsigned char residual_colour_transform_flag : 1;
862 unsigned char frame_mbs_only_flag : 1;
863 unsigned char mb_adaptive_frame_field_flag : 1;
864 unsigned char direct_8x8_inference_flag : 1;
865 unsigned char MinLumaBiPredSize8x8 : 1; /* see A.3.3.2 */
867 unsigned char seq_fields;
869 unsigned char num_slice_groups_minus1;
870 unsigned char slice_group_map_type;
871 signed char pic_init_qp_minus26;
872 signed char chroma_qp_index_offset;
873 signed char second_chroma_qp_index_offset;
876 unsigned char entropy_coding_mode_flag : 1;
877 unsigned char weighted_pred_flag : 1;
878 unsigned char weighted_bipred_idc : 2;
879 unsigned char transform_8x8_mode_flag : 1;
880 unsigned char field_pic_flag : 1;
881 unsigned char constrained_intra_pred_flag : 1;
883 unsigned char pic_fields;
885 unsigned short frame_num;
886 } VAPictureParameterBufferH264;
888 /* H.264 Inverse Quantization Matrix Buffer */
889 typedef struct _VAIQMatrixBufferH264
891 unsigned char ScalingList4x4[6][16];
892 unsigned char ScalingList8x8[2][64];
893 } VAIQMatrixBufferH264;
896 * H.264 Slice Group Map Buffer
897 * When VAPictureParameterBufferH264::num_slice_group_minus1 is not equal to 0,
898 * A slice group map buffer should be sent for each picture if required. The buffer
899 * is sent only when there is a change in the mapping values.
900 * The slice group map buffer map "map units" to slice groups as specified in
901 * section 8.2.2 of the H.264 spec. The buffer will contain one byte for each macroblock
902 * in raster scan order
905 /* H.264 Slice Parameter Buffer */
906 typedef struct _VASliceParameterBufferH264
908 unsigned int slice_data_size;/* number of bytes in the slice data buffer for this slice */
909 unsigned int slice_data_offset;/* the offset to first byte of slice data */
910 unsigned int slice_data_flag; /* see VA_SLICE_DATA_FLAG_XXX defintions */
911 unsigned short slice_data_bit_offset; /* bit offset in the first byte of valid data */
912 unsigned short first_mb_in_slice;
913 unsigned char slice_type;
914 unsigned char direct_spatial_mv_pred_flag;
915 unsigned char num_ref_idx_l0_active_minus1;
916 unsigned char num_ref_idx_l1_active_minus1;
917 unsigned char cabac_init_idc;
919 unsigned char disable_deblocking_filter_idc;
920 char slice_alpha_c0_offset_div2;
921 char slice_beta_offset_div2;
922 VAPictureH264 RefPicList0[32]; /* See 8.2.4.2 */
923 VAPictureH264 RefPicList1[32]; /* See 8.2.4.2 */
924 unsigned char luma_log2_weight_denom;
925 unsigned char chroma_log2_weight_denom;
926 unsigned char luma_weight_l0_flag;
927 short luma_weight_l0[32];
928 short luma_offset_l0[32];
929 unsigned char chroma_weight_l0_flag;
930 short chroma_weight_l0[32][2];
931 short chroma_offset_l0[32][2];
932 unsigned char luma_weight_l1_flag;
933 short luma_weight_l1[32];
934 short luma_offset_l1[32];
935 unsigned char chroma_weight_l1_flag;
936 short chroma_weight_l1[32][2];
937 short chroma_offset_l1[32][2];
938 } VASliceParameterBufferH264;
940 /* Buffer functions */
943 * Creates a buffer for "num_elements" elements of "size" bytes and
944 * initalize with "data".
945 * if "data" is null, then the contents of the buffer data store
947 * Basically there are two ways to get buffer data to the server side. One is
948 * to call vaCreateBuffer() with a non-null "data", which results the data being
949 * copied to the data store on the server side. A different method that
950 * eliminates this copy is to pass null as "data" when calling vaCreateBuffer(),
951 * and then use vaMapBuffer() to map the data store from the server side to the
952 * client address space for access.
953 * Note: image buffers are created by the library, not the client. Please see
954 * vaCreateImage on how image buffers are managed.
956 VAStatus vaCreateBuffer (
959 VABufferType type, /* in */
960 unsigned int size, /* in */
961 unsigned int num_elements, /* in */
963 VABufferID *buf_id /* out */
967 * Convey to the server how many valid elements are in the buffer.
968 * e.g. if multiple slice parameters are being held in a single buffer,
969 * this will communicate to the server the number of slice parameters
970 * that are valid in the buffer.
972 VAStatus vaBufferSetNumElements (
974 VABufferID buf_id, /* in */
975 unsigned int num_elements /* in */
979 * Map data store of the buffer into the client's address space
980 * vaCreateBuffer() needs to be called with "data" set to NULL before
981 * calling vaMapBuffer()
983 VAStatus vaMapBuffer (
985 VABufferID buf_id, /* in */
986 void **pbuf /* out */
990 * After client making changes to a mapped data store, it needs to
991 * "Unmap" it to let the server know that the data is ready to be
992 * consumed by the server
994 VAStatus vaUnmapBuffer (
996 VABufferID buf_id /* in */
1000 * After this call, the buffer is deleted and this buffer_id is no longer valid
1001 * Only call this if the buffer is not going to be passed to vaRenderBuffer
1003 VAStatus vaDestroyBuffer (
1005 VABufferID buffer_id
1009 Render (Decode) Pictures
1011 A picture represents either a frame or a field.
1013 The Begin/Render/End sequence sends the decode buffers to the server
1017 * Get ready to decode a picture to a target surface
1019 VAStatus vaBeginPicture (
1021 VAContextID context,
1022 VASurfaceID render_target
1026 * Send decode buffers to the server.
1027 * Buffers are automatically destroyed afterwards
1029 VAStatus vaRenderPicture (
1031 VAContextID context,
1032 VABufferID *buffers,
1037 * Make the end of rendering for a picture.
1038 * The server should start processing all pending operations for this
1039 * surface. This call is non-blocking. The client can start another
1040 * Begin/Render/End sequence on a different render target.
1042 VAStatus vaEndPicture (
1054 * This function blocks until all pending operations on the render target
1055 * have been completed. Upon return it is safe to use the render target for a
1056 * different picture.
1058 VAStatus vaSyncSurface (
1060 VAContextID context,
1061 VASurfaceID render_target
1066 VASurfaceRendering = 0, /* Rendering in progress */
1067 VASurfaceDisplaying = 1, /* Displaying in progress (not safe to render into it) */
1068 /* this status is useful if surface is used as the source */
1070 VASurfaceReady = 2 /* not being rendered or displayed */
1074 * Find out any pending ops on the render target
1076 VAStatus vaQuerySurfaceStatus (
1078 VASurfaceID render_target,
1079 VASurfaceStatus *status /* out */
1084 * Copies the surface to a buffer
1085 * The stride of the surface will be stored in *stride
1086 * Caller should free the returned buffer with free() when done.
1088 VAStatus vaDbgCopySurfaceToBuffer(VADisplay dpy,
1089 VASurfaceID surface,
1090 void **buffer, /* out */
1091 unsigned int *stride /* out */
1095 * Images and Subpictures
1096 * VAImage is used to either get the surface data to client memory, or
1097 * to copy image data in client memory to a surface.
1098 * Both images, subpictures and surfaces follow the same 2D coordinate system where origin
1099 * is at the upper left corner with positive X to the right and positive Y down
1101 #define MAKEFOURCC(ch0, ch1, ch2, ch3) \
1102 ((unsigned long)(unsigned char) (ch0) | ((unsigned long)(unsigned char) (ch1) << 8) | \
1103 ((unsigned long)(unsigned char) (ch2) << 16) | ((unsigned long)(unsigned char) (ch3) << 24 ))
1105 /* a few common FourCCs */
1106 #define VA_FOURCC_NV12 0x3231564E
1107 #define VA_FOURCC_AI44 0x34344149
1108 #define VA_FOURCC_RGBA 0x41424752
1111 #define VA_LSB_FIRST 1
1112 #define VA_MSB_FIRST 2
1114 typedef struct _VAImageFormat
1116 unsigned int fourcc;
1117 unsigned int byte_order; /* VA_LSB_FIRST, VA_MSB_FIRST */
1118 unsigned int bits_per_pixel;
1119 /* for RGB formats */
1120 unsigned int depth; /* significant bits per pixel */
1121 unsigned int red_mask;
1122 unsigned int green_mask;
1123 unsigned int blue_mask;
1124 unsigned int alpha_mask;
1127 typedef VAGenericID VAImageID;
1129 typedef struct _VAImage
1131 VAImageID image_id; /* uniquely identify this image */
1132 VAImageFormat format;
1133 VABufferID buf; /* image data buffer */
1135 * Image data will be stored in a buffer of type VAImageBufferType to facilitate
1136 * data store on the server side for optimal performance. The buffer will be
1137 * created by the CreateImage function, and proper storage allocated based on the image
1138 * size and format. This buffer is managed by the library implementation, and
1139 * accessed by the client through the buffer Map/Unmap functions.
1141 unsigned short width;
1142 unsigned short height;
1143 unsigned int data_size;
1144 unsigned int num_planes; /* can not be greater than 3 */
1146 * An array indicating the scanline pitch in bytes for each plane.
1147 * Each plane may have a different pitch. Maximum 3 planes for planar formats
1149 unsigned int pitches[3];
1151 * An array indicating the byte offset from the beginning of the image data
1152 * to the start of each plane.
1154 unsigned int offsets[3];
1156 /* The following fields are only needed for paletted formats */
1157 int num_palette_entries; /* set to zero for non-palette images */
1159 * Each component is one byte and entry_bytes indicates the number of components in
1160 * each entry (eg. 3 for YUV palette entries). set to zero for non-palette images
1164 * An array of ascii characters describing the order of the components within the bytes.
1165 * Only entry_bytes characters of the string are used.
1167 char component_order[4];
1170 /* Get maximum number of image formats supported by the implementation */
1171 int vaMaxNumImageFormats (
1176 * Query supported image formats
1177 * The caller must provide a "format_list" array that can hold at
1178 * least vaMaxNumImageFormats() entries. The actual number of formats
1179 * returned in "format_list" is returned in "num_formats".
1181 VAStatus vaQueryImageFormats (
1183 VAImageFormat *format_list, /* out */
1184 int *num_formats /* out */
1188 * Create a VAImage structure
1189 * The width and height fields returned in the VAImage structure may get
1190 * enlarged for some YUV formats. Upon return from this function,
1191 * image->buf has been created and proper storage allocated by the library.
1192 * The client can access the image through the Map/Unmap calls.
1194 VAStatus vaCreateImage (
1196 VAImageFormat *format,
1199 VAImage *image /* out */
1203 * Should call DestroyImage before destroying the surface it is bound to
1205 VAStatus vaDestroyImage (
1210 VAStatus vaSetImagePalette (
1214 * pointer to an array holding the palette data. The size of the array is
1215 * num_palette_entries * entry_bytes in size. The order of the components
1216 * in the palette is described by the component_order in VAImage struct
1218 unsigned char *palette
1222 * Retrive surface data into a VAImage
1223 * Image must be in a format supported by the implementation
1225 VAStatus vaGetImage (
1227 VASurfaceID surface,
1228 int x, /* coordinates of the upper left source pixel */
1230 unsigned int width, /* width and height of the region */
1231 unsigned int height,
1236 * Copy data from a VAImage to a surface
1237 * Image must be in a format supported by the implementation
1238 * Returns a VA_STATUS_ERROR_SURFACE_BUSY if the surface
1239 * shouldn't be rendered into when this is called
1240 * The source and destionation width and height are the same and
1241 * no scaling is performed with this operation.
1243 VAStatus vaPutImage (
1245 VASurfaceID surface,
1250 unsigned int height,
1257 * Subpicture is a special type of image that can be blended
1258 * with a surface during vaPutSurface(). Subpicture can be used to render
1259 * DVD sub-titles or closed captioning text etc.
1262 typedef VAGenericID VASubpictureID;
1264 /* Get maximum number of subpicture formats supported by the implementation */
1265 int vaMaxNumSubpictureFormats (
1269 /* flags for subpictures */
1270 #define VA_SUBPICTURE_CHROMA_KEYING 0x0001
1271 #define VA_SUBPICTURE_GLOBAL_ALPHA 0x0002
1273 * Query supported subpicture formats
1274 * The caller must provide a "format_list" array that can hold at
1275 * least vaMaxNumSubpictureFormats() entries. The flags arrary holds the flag
1276 * for each format to indicate additional capabilities for that format. The actual
1277 * number of formats returned in "format_list" is returned in "num_formats".
1278 * flags: returned value to indicate addtional capabilities
1279 * VA_SUBPICTURE_CHROMA_KEYING - supports chroma-keying
1280 * VA_SUBPICTURE_GLOBAL_ALPHA - supports global alpha
1282 VAStatus vaQuerySubpictureFormats (
1284 VAImageFormat *format_list, /* out */
1285 unsigned int *flags, /* out */
1286 unsigned int *num_formats /* out */
1290 * Subpictures are created with an image associated.
1292 VAStatus vaCreateSubpicture (
1295 VASubpictureID *subpicture /* out */
1299 * Destroy the subpicture before destroying the image it is assocated to
1301 VAStatus vaDestroySubpicture (
1303 VASubpictureID subpicture
1307 * Bind an image to the subpicture. This image will now be associated with
1308 * the subpicture instead of the one at creation.
1310 VAStatus vaSetSubpictureImage (
1312 VASubpictureID subpicture,
1316 VAStatus vaSetSubpicturePalette (
1318 VASubpictureID subpicture,
1320 * pointer to an array holding the palette data. The size of the array is
1321 * num_palette_entries * entry_bytes in size. The order of the components
1322 * in the palette is described by the component_order in VAImage struct
1324 unsigned char *palette
1328 * If chromakey is enabled, then the area where the source value falls within
1329 * the chromakey [min, max] range is transparent
1330 * The chromakey component format is the following:
1331 * For RGB: [0:7] Red [8:15] Blue [16:23] Green
1332 * For YUV: [0:7] V [8:15] U [16:23] Y
1333 * The chromakey mask can be used to mask out certain components for chromakey
1336 VAStatus vaSetSubpictureChromakey (
1338 VASubpictureID subpicture,
1339 unsigned int chromakey_min,
1340 unsigned int chromakey_max,
1341 unsigned int chromakey_mask
1345 * Global alpha value is between 0 and 1. A value of 1 means fully opaque and
1346 * a value of 0 means fully transparent. If per-pixel alpha is also specified then
1347 * the overall alpha is per-pixel alpha multiplied by the global alpha
1349 VAStatus vaSetSubpictureGlobalAlpha (
1351 VASubpictureID subpicture,
1356 * vaAssociateSubpicture associates the subpicture with target_surfaces.
1357 * It defines the region mapping between the subpicture and the target
1358 * surfaces through source and destination rectangles (with the same width and height).
1359 * Both will be displayed at the next call to vaPutSurface. Additional
1360 * associations before the call to vaPutSurface simply overrides the association.
1362 VAStatus vaAssociateSubpicture (
1364 VASubpictureID subpicture,
1365 VASurfaceID *target_surfaces,
1367 short src_x, /* upper left offset in subpicture */
1369 short dest_x, /* upper left offset in surface */
1371 unsigned short width,
1372 unsigned short height,
1374 * whether to enable chroma-keying or global-alpha
1375 * see VA_SUBPICTURE_XXX values
1381 * vaDeassociateSubpicture removes the association of the subpicture with target_surfaces.
1383 VAStatus vaDeassociateSubpicture (
1385 VASubpictureID subpicture,
1386 VASurfaceID *target_surfaces,
1390 typedef struct _VARectangle
1394 unsigned short width;
1395 unsigned short height;
1399 * Display attributes
1400 * Display attributes are used to control things such as contrast, hue, saturation,
1401 * brightness etc. in the rendering process. The application can query what
1402 * attributes are supported by the driver, and then set the appropriate attributes
1403 * before calling vaPutSurface()
1406 /* Currently defined display attribute types */
1409 VADisplayAttribBrightness = 0,
1410 VADisplayAttribContrast = 1,
1411 VADisplayAttribHue = 2,
1412 VADisplayAttribSaturation = 3,
1413 /* client can specifiy a background color for the target window */
1414 VADisplayAttribBackgroundColor = 4,
1416 * this is a gettable only attribute. For some implementations that use the
1417 * hardware overlay, after PutSurface is called, the surface can not be
1418 * re-used until after the subsequent PutSurface call. If this is the case
1419 * then the value for this attribute will be set to 1 so that the client
1420 * will not attempt to re-use the surface right after returning from a call
1423 VADisplayAttribDirectSurface = 5,
1424 } VADisplayAttribType;
1426 /* flags for VADisplayAttribute */
1427 #define VA_DISPLAY_ATTRIB_NOT_SUPPORTED 0x0000
1428 #define VA_DISPLAY_ATTRIB_GETTABLE 0x0001
1429 #define VA_DISPLAY_ATTRIB_SETTABLE 0x0002
1431 typedef struct _VADisplayAttribute
1433 VADisplayAttribType type;
1436 int value; /* used by the set/get attribute functions */
1437 /* flags can be VA_DISPLAY_ATTRIB_GETTABLE or VA_DISPLAY_ATTRIB_SETTABLE or OR'd together */
1439 } VADisplayAttribute;
1441 /* Get maximum number of display attributs supported by the implementation */
1442 int vaMaxNumDisplayAttributes (
1447 * Query display attributes
1448 * The caller must provide a "attr_list" array that can hold at
1449 * least vaMaxNumDisplayAttributes() entries. The actual number of attributes
1450 * returned in "attr_list" is returned in "num_attributes".
1452 VAStatus vaQueryDisplayAttributes (
1454 VADisplayAttribute *attr_list, /* out */
1455 int *num_attributes /* out */
1459 * Get display attributes
1460 * This function returns the current attribute values in "attr_list".
1461 * Only attributes returned with VA_DISPLAY_ATTRIB_GETTABLE set in the "flags" field
1462 * from vaQueryDisplayAttributes() can have their values retrieved.
1464 VAStatus vaGetDisplayAttributes (
1466 VADisplayAttribute *attr_list, /* in/out */
1471 * Set display attributes
1472 * Only attributes returned with VA_DISPLAY_ATTRIB_SETTABLE set in the "flags" field
1473 * from vaQueryDisplayAttributes() can be set. If the attribute is not settable or
1474 * the value is out of range, the function returns VA_STATUS_ERROR_ATTR_NOT_SUPPORTED
1476 VAStatus vaSetDisplayAttributes (
1478 VADisplayAttribute *attr_list,
1489 /*****************************************************************************/
1491 Sample Program (w/ pseudo code)
1493 Mostly to demonstrate program flow with no error handling ...
1495 /*****************************************************************************/
1497 /* MPEG-2 VLD decode for a 720x480 frame */
1499 int major_ver, minor_ver;
1500 vaInitialize(dpy, &major_ver, &minor_ver);
1502 int max_num_profiles, max_num_entrypoints, max_num_attribs;
1503 max_num_profiles = vaMaxNumProfiles(dpy);
1504 max_num_entrypoints = vaMaxNumProfiles(dpy);
1505 max_num_attribs = vaMaxNumProfiles(dpy);
1507 /* find out whether MPEG2 MP is supported */
1508 VAProfile *profiles = malloc(sizeof(VAProfile)*max_num_profiles);
1510 vaQueryConfigProfiles(dpy, profiles, &profiles);
1512 * traverse "profiles" to locate the one that matches VAProfileMPEG2Main
1515 /* now get the available entrypoints for MPEG2 MP */
1516 VAEntrypoint *entrypoints = malloc(sizeof(VAEntrypoint)*max_num_entrypoints);
1517 int num_entrypoints;
1518 vaQueryConfigEntrypoints(dpy, VAProfileMPEG2Main, entrypoints, &num_entrypoints);
1520 /* traverse "entrypoints" to see whether VLD is there */
1522 /* Assuming finding VLD, find out the format for the render target */
1523 VAConfigAttrib attrib;
1524 attrib.type = VAConfigAttribRTFormat;
1525 vaGetConfigAttributes(dpy, VAProfileMPEG2Main, VAEntrypointVLD,
1528 if (attrib.value & VA_RT_FORMAT_YUV420)
1529 /* Found desired RT format, keep going */
1531 VAConfigID config_id;
1532 vaCreateConfig(dpy, VAProfileMPEG2Main, VAEntrypointVLD, &attrib, 1,
1536 * create surfaces for the current target as well as reference frames
1537 * we can get by with 4 surfaces for MPEG-2
1539 VASurfaceID surfaces[4];
1540 vaCreateSurfaces(dpy, 720, 480, VA_RT_FORMAT_YUV420, 4, surfaces);
1543 * Create a context for this decode pipe
1545 VAContextID context;
1546 vaCreateContext(dpy, config_id, 720, 480, VA_PROGRESSIVE, surfaces,
1549 /* Create a picture parameter buffer for this frame */
1550 VABufferID picture_buf;
1551 VAPictureParameterBufferMPEG2 *picture_param;
1552 vaCreateBuffer(dpy, context, VAPictureParameterBufferType, sizeof(VAPictureParameterBufferMPEG2), 1, NULL, &picture_buf);
1553 vaMapBuffer(dpy, picture_buf, &picture_param);
1554 picture_param->horizontal_size = 720;
1555 picture_param->vertical_size = 480;
1556 picture_param->picture_coding_type = 1; /* I-frame */
1557 /* fill in picture_coding_extension fields here */
1558 vaUnmapBuffer(dpy, picture_buf);
1560 /* Create an IQ matrix buffer for this frame */
1562 VAIQMatrixBufferMPEG2 *iq_matrix;
1563 vaCreateBuffer(dpy, context, VAIQMatrixBufferType, sizeof(VAIQMatrixBufferMPEG2), 1, NULL, &iq_buf);
1564 vaMapBuffer(dpy, iq_buf, &iq_matrix);
1565 /* fill values for IQ_matrix here */
1566 vaUnmapBuffer(dpy, iq_buf);
1568 /* send the picture and IQ matrix buffers to the server */
1569 vaBeginPicture(dpy, context, surfaces[0]);
1571 vaRenderPicture(dpy, context, &picture_buf, 1);
1572 vaRenderPicture(dpy, context, &iq_buf, 1);
1575 * Send slices in this frame to the server.
1576 * For MPEG-2, each slice is one row of macroblocks, and
1577 * we have 30 slices for a 720x480 frame
1579 for (int i = 1; i <= 30; i++) {
1581 /* Create a slice parameter buffer */
1582 VABufferID slice_param_buf;
1583 VASliceParameterBufferMPEG2 *slice_param;
1584 vaCreateBuffer(dpy, context, VASliceParameterBufferType, sizeof(VASliceParameterBufferMPEG2), 1, NULL, &slice_param_buf);
1585 vaMapBuffer(dpy, slice_param_buf, &slice_param);
1586 slice_param->slice_data_offset = 0;
1587 /* Let's say all slices in this bit-stream has 64-bit header */
1588 slice_param->macroblock_offset = 64;
1589 slice_param->vertical_position = i;
1590 /* set up the rest based on what is in the slice header ... */
1591 vaUnmapBuffer(dpy, slice_param_buf);
1593 /* send the slice parameter buffer */
1594 vaRenderPicture(dpy, context, &slice_param_buf, 1);
1596 /* Create a slice data buffer */
1597 unsigned char *slice_data;
1598 VABufferID slice_data_buf;
1599 vaCreateBuffer(dpy, context, VASliceDataBufferType, x /* decoder figure out how big */, 1, NULL, &slice_data_buf);
1600 vaMapBuffer(dpy, slice_data_buf, &slice_data);
1601 /* decoder fill in slice_data */
1602 vaUnmapBuffer(dpy, slice_data_buf);
1604 /* send the slice data buffer */
1605 vaRenderPicture(dpy, context, &slice_data_buf, 1);
1608 /* all slices have been sent, mark the end for this frame */
1609 vaEndPicture(dpy, context);
1611 /* The following code demonstrates rendering a sub-title with the target surface */
1612 /* Find out supported Subpicture formats */
1613 VAImageFormat sub_formats[4];
1615 vaQuerySubpictureFormats(dpy, sub_formats, &num_formats);
1616 /* Assume that we find AI44 as a subpicture format in sub_formats[0] */
1618 VASubpictureID subpicture;
1619 unsigned char *sub_data;
1620 /* create an image for the subtitle */
1621 vaCreateImage(dpy, sub_formats, 128, 16, &sub_image);
1622 vaMapBuffer(dpy, sub_image->buf, &sub_data);
1623 /* fill the image data */
1624 vaUnmapBuffer(dpy, sub_image->buf);
1625 vaCreateSubpicture(dpy, sub_image, &subpicture);
1626 unsigned char palette[3][16];
1627 /* fill the palette data */
1628 vaSetSubpicturePalette(dpy, subpicture, palette);
1629 vaAssociateSubpicture(dpy, subpicture, surfaces, 1, 0, 0, 296, 400, 128, 16);
1630 vaPutSurface(dpy, surfaces, win, 0, 0, 720, 480, 100, 100, 640, 480, NULL, 0, 0);