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
49 * rev 0.27 (11/19/2007 Matt Sottek) - Added DeriveImage
50 * rev 0.28 (12/06/2007 Jonathan Bian) - Added new versions of PutImage and AssociateSubpicture
54 * Some concepts borrowed from XvMC and XvImage.
55 * Thanks to Waldo Bastian, Matt Sottek and Austin Yuan at Intel for many valuable feedbacks.
68 This API is intended to provide an interface between a video decode
69 application (client) and a hardware decode accelerator (server), to off-load
70 video decode operations from the host to the hardware accelerator at various
73 The basic operation steps are:
75 - Negotiate a mutually acceptable configuration with the server to lock
76 down profile, entrypoints, and other attributes that will not change on
77 a frame-by-frame basis.
78 - Create a decode context which represents a "virtualized" hardware decode
80 - Get and fill decode buffers with picture level, slice level and macroblock
81 level data (depending on entrypoints)
82 - Pass the decode buffers to the server to decode the current frame
84 Initialization & Configuration Management
86 - Find out supported profiles
87 - Find out entrypoints for a given profile
88 - Find out configuration attributes for a given profile/entrypoint pair
89 - Create a configuration for use by the decoder
93 typedef void* VADisplay; /* window system dependent */
95 typedef int VAStatus; /* Return status type from functions */
96 /* Values for the return status */
97 #define VA_STATUS_SUCCESS 0x00000000
98 #define VA_STATUS_ERROR_OPERATION_FAILED 0x00000001
99 #define VA_STATUS_ERROR_ALLOCATION_FAILED 0x00000002
100 #define VA_STATUS_ERROR_INVALID_DISPLAY 0x00000003
101 #define VA_STATUS_ERROR_INVALID_CONFIG 0x00000004
102 #define VA_STATUS_ERROR_INVALID_CONTEXT 0x00000005
103 #define VA_STATUS_ERROR_INVALID_SURFACE 0x00000006
104 #define VA_STATUS_ERROR_INVALID_BUFFER 0x00000007
105 #define VA_STATUS_ERROR_INVALID_IMAGE 0x00000008
106 #define VA_STATUS_ERROR_INVALID_SUBPICTURE 0x00000009
107 #define VA_STATUS_ERROR_ATTR_NOT_SUPPORTED 0x0000000a
108 #define VA_STATUS_ERROR_MAX_NUM_EXCEEDED 0x0000000b
109 #define VA_STATUS_ERROR_UNSUPPORTED_PROFILE 0x0000000c
110 #define VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT 0x0000000d
111 #define VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT 0x0000000e
112 #define VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE 0x0000000f
113 #define VA_STATUS_ERROR_SURFACE_BUSY 0x00000010
114 #define VA_STATUS_ERROR_UNKNOWN 0xFFFFFFFF
117 * Returns a short english description of error_status
119 const char *vaErrorStr(VAStatus error_status);
123 * A display must be obtained by calling vaGetDisplay() before calling
124 * vaInitialize() and other functions. This connects the API to the
125 * native window system.
126 * For X Windows, native_dpy would be from XOpenDisplay()
128 typedef void* NativeDisplay; /* window system dependent */
130 VADisplay vaGetDisplay (
131 NativeDisplay native_dpy /* implementation specific */
135 * Initialize the library
137 VAStatus vaInitialize (
139 int *major_version, /* out */
140 int *minor_version /* out */
144 * After this call, all library internal resources will be cleaned up
146 VAStatus vaTerminate (
151 * vaQueryVendorString returns a pointer to a zero-terminated string
152 * describing some aspects of the VA implemenation on a specific
153 * hardware accelerator. The format of the returned string is vendor
154 * specific and at the discretion of the implementer.
155 * e.g. for the Intel GMA500 implementation, an example would be:
156 * "Intel GMA500 - 2.0.0.32L.0005"
158 const char *vaQueryVendorString (
162 typedef int (*VAPrivFunc)();
165 * Return a function pointer given a function name in the library.
166 * This allows private interfaces into the library
168 VAPrivFunc vaGetLibFunc (
173 /* Currently defined profiles */
176 VAProfileMPEG2Simple = 0,
177 VAProfileMPEG2Main = 1,
178 VAProfileMPEG4Simple = 2,
179 VAProfileMPEG4AdvancedSimple = 3,
180 VAProfileMPEG4Main = 4,
181 VAProfileH264Baseline = 5,
182 VAProfileH264Main = 6,
183 VAProfileH264High = 7,
184 VAProfileVC1Simple = 8,
185 VAProfileVC1Main = 9,
186 VAProfileVC1Advanced = 10,
190 * Currently defined entrypoints
196 VAEntrypointIDCT = 3,
197 VAEntrypointMoComp = 4,
198 VAEntrypointDeblocking = 5,
201 /* Currently defined configuration attribute types */
204 VAConfigAttribRTFormat = 0,
205 VAConfigAttribSpatialResidual = 1,
206 VAConfigAttribSpatialClipping = 2,
207 VAConfigAttribIntraResidual = 3,
208 VAConfigAttribEncryption = 4,
209 } VAConfigAttribType;
212 * Configuration attributes
213 * If there is more than one value for an attribute, a default
214 * value will be assigned to the attribute if the client does not
215 * specify the attribute when creating a configuration
217 typedef struct _VAConfigAttrib {
218 VAConfigAttribType type;
219 unsigned int value; /* OR'd flags (bits) for this attribute */
222 /* attribute value for VAConfigAttribRTFormat */
223 #define VA_RT_FORMAT_YUV420 0x00000001
224 #define VA_RT_FORMAT_YUV422 0x00000002
225 #define VA_RT_FORMAT_YUV444 0x00000004
228 * if an attribute is not applicable for a given
229 * profile/entrypoint pair, then set the value to the following
231 #define VA_ATTRIB_NOT_SUPPORTED 0x80000000
233 /* Get maximum number of profiles supported by the implementation */
234 int vaMaxNumProfiles (
238 /* Get maximum number of entrypoints supported by the implementation */
239 int vaMaxNumEntrypoints (
243 /* Get maximum number of attributs supported by the implementation */
244 int vaMaxNumConfigAttributes (
249 * Query supported profiles
250 * The caller must provide a "profile_list" array that can hold at
251 * least vaMaxNumProfile() entries. The actual number of profiles
252 * returned in "profile_list" is returned in "num_profile".
254 VAStatus vaQueryConfigProfiles (
256 VAProfile *profile_list, /* out */
257 int *num_profiles /* out */
261 * Query supported entrypoints for a given profile
262 * The caller must provide an "entrypoint_list" array that can hold at
263 * least vaMaxNumEntrypoints() entries. The actual number of entrypoints
264 * returned in "entrypoint_list" is returned in "num_entrypoints".
266 VAStatus vaQueryConfigEntrypoints (
269 VAEntrypoint *entrypoint_list, /* out */
270 int *num_entrypoints /* out */
274 * Get attributes for a given profile/entrypoint pair
275 * The caller must provide an "attrib_list" with all attributes to be
276 * retrieved. Upon return, the attributes in "attrib_list" have been
277 * updated with their value. Unknown attributes or attributes that are
278 * not supported for the given profile/entrypoint pair will have their
279 * value set to VA_ATTRIB_NOT_SUPPORTED
281 VAStatus vaGetConfigAttributes (
284 VAEntrypoint entrypoint,
285 VAConfigAttrib *attrib_list, /* in/out */
289 /* Generic ID type, can be re-typed for specific implementation */
290 typedef unsigned int VAGenericID;
292 typedef VAGenericID VAConfigID;
295 * Create a configuration for the decode pipeline
296 * it passes in the attribute list that specifies the attributes it cares
297 * about, with the rest taking default values.
299 VAStatus vaCreateConfig (
302 VAEntrypoint entrypoint,
303 VAConfigAttrib *attrib_list,
305 VAConfigID *config_id /* out */
309 * Free resources associdated with a given config
311 VAStatus vaDestroyConfig (
317 * Query all attributes for a given configuration
318 * The profile of the configuration is returned in "profile"
319 * The entrypoint of the configuration is returned in "entrypoint"
320 * The caller must provide an "attrib_list" array that can hold at least
321 * vaMaxNumConfigAttributes() entries. The actual number of attributes
322 * returned in "attrib_list" is returned in "num_attribs"
324 VAStatus vaQueryConfigAttributes (
326 VAConfigID config_id,
327 VAProfile *profile, /* out */
328 VAEntrypoint *entrypoint, /* out */
329 VAConfigAttrib *attrib_list,/* out */
330 int *num_attribs /* out */
335 * Contexts and Surfaces
337 * Context represents a "virtual" video decode pipeline. Surfaces are render
338 * targets for a given context. The data in the surfaces are not accessible
339 * to the client and the internal data format of the surface is implementatin
342 * Surfaces will be bound to a context when the context is created. Once
343 * a surface is bound to a given context, it can not be used to create
344 * another context. The association is removed when the context is destroyed
346 * Both contexts and surfaces are identified by unique IDs and its
347 * implementation specific internals are kept opaque to the clients
350 typedef VAGenericID VAContextID;
352 typedef VAGenericID VASurfaceID;
354 #define VA_INVALID_SURFACE -1
357 * vaCreateSurfaces - Create an array of surfaces used for decode and display
359 * width: surface width
360 * height: surface height
361 * format: VA_RT_FORMAT_YUV420, VA_RT_FORMAT_YUV422 or VA_RT_FORMAT_YUV444
362 * num_surfaces: number of surfaces to be created
363 * surfaces: array of surfaces created upon return
365 VAStatus vaCreateSurfaces (
371 VASurfaceID *surfaces /* out */
375 * vaDestroySurfaces - Destroy resources associated with surfaces.
376 * Surfaces can only be destroyed after the context associated has been
379 * surfaces: array of surfaces to destroy
380 * num_surfaces: number of surfaces in the array to be destroyed.
382 VAStatus vaDestroySurfaces (
384 VASurfaceID *surfaces,
388 #define VA_PROGRESSIVE 0x1
390 * vaCreateContext - Create a context
392 * config_id: configuration for the context
393 * picture_width: coded picture width
394 * picture_height: coded picture height
395 * flag: any combination of the following:
396 * VA_PROGRESSIVE (only progressive frame pictures in the sequence when set)
397 * render_targets: render targets (surfaces) tied to the context
398 * num_render_targets: number of render targets in the above array
399 * context: created context id upon return
401 VAStatus vaCreateContext (
403 VAConfigID config_id,
407 VASurfaceID *render_targets,
408 int num_render_targets,
409 VAContextID *context /* out */
413 * vaDestroyContext - Destroy a context
415 * context: context to be destroyed
417 VAStatus vaDestroyContext (
424 * Buffers are used to pass various types of data from the
425 * client to the server. The server maintains a data store
426 * for each buffer created, and the client idenfies a buffer
427 * through a unique buffer id assigned by the server.
430 typedef VAGenericID VABufferID;
434 VAPictureParameterBufferType = 0,
435 VAIQMatrixBufferType = 1,
436 VABitPlaneBufferType = 2,
437 VASliceGroupMapBufferType = 3,
438 VASliceParameterBufferType = 4,
439 VASliceDataBufferType = 5,
440 VAMacroblockParameterBufferType = 6,
441 VAResidualDataBufferType = 7,
442 VADeblockingParameterBufferType = 8,
443 VAImageBufferType = 9
446 /****************************
447 * MPEG-2 data structures
448 ****************************/
450 /* MPEG-2 Picture Parameter Buffer */
452 * For each frame or field, and before any slice data, a single
453 * picture parameter buffer must be send.
455 typedef struct _VAPictureParameterBufferMPEG2
457 unsigned short horizontal_size;
458 unsigned short vertical_size;
459 VASurfaceID forward_reference_picture;
460 VASurfaceID backward_reference_picture;
461 /* meanings of the following fields are the same as in the standard */
462 int picture_coding_type;
463 int f_code; /* pack all four fcode into this */
466 unsigned char intra_dc_precision : 2;
467 unsigned char picture_structure : 2;
468 unsigned char top_field_first : 1;
469 unsigned char frame_pred_frame_dct : 1;
470 unsigned char concealment_motion_vectors : 1;
471 unsigned char q_scale_type : 1;
472 unsigned char intra_vlc_format : 1;
473 unsigned char alternate_scan : 1;
474 unsigned char repeat_first_field : 1;
475 unsigned char progressive_frame : 1;
476 unsigned char is_first_field : 1; /* indicate whether the current field
477 * is the first field for field picture
480 unsigned int picture_coding_extension;
482 } VAPictureParameterBufferMPEG2;
484 /* MPEG-2 Inverse Quantization Matrix Buffer */
485 typedef struct _VAIQMatrixBufferMPEG2
487 int load_intra_quantiser_matrix;
488 int load_non_intra_quantiser_matrix;
489 int load_chroma_intra_quantiser_matrix;
490 int load_chroma_non_intra_quantiser_matrix;
491 unsigned char intra_quantiser_matrix[64];
492 unsigned char non_intra_quantiser_matrix[64];
493 unsigned char chroma_intra_quantiser_matrix[64];
494 unsigned char chroma_non_intra_quantiser_matrix[64];
495 } VAIQMatrixBufferMPEG2;
498 * There will be cases where the bitstream buffer will not have enough room to hold
499 * the data for the entire slice, and the following flags will be used in the slice
500 * parameter to signal to the server for the possible cases.
501 * If a slice parameter buffer and slice data buffer pair is sent to the server with
502 * the slice data partially in the slice data buffer (BEGIN and MIDDLE cases below),
503 * then a slice parameter and data buffer needs to be sent again to complete this slice.
505 #define VA_SLICE_DATA_FLAG_ALL 0x00 /* whole slice is in the buffer */
506 #define VA_SLICE_DATA_FLAG_BEGIN 0x01 /* The beginning of the slice is in the buffer but the end if not */
507 #define VA_SLICE_DATA_FLAG_MIDDLE 0x02 /* Neither beginning nor end of the slice is in the buffer */
508 #define VA_SLICE_DATA_FLAG_END 0x04 /* end of the slice is in the buffer */
510 /* MPEG-2 Slice Parameter Buffer */
511 typedef struct _VASliceParameterBufferMPEG2
513 unsigned int slice_data_size;/* number of bytes in the slice data buffer for this slice */
514 unsigned int slice_data_offset;/* the offset to the first byte of slice data */
515 unsigned int slice_data_flag; /* see VA_SLICE_DATA_FLAG_XXX defintions */
516 unsigned int macroblock_offset;/* the offset to the first bit of MB from the first byte of slice data */
517 unsigned int slice_vertical_position;
518 int quantiser_scale_code;
519 int intra_slice_flag;
520 } VASliceParameterBufferMPEG2;
522 /* MPEG-2 Macroblock Parameter Buffer */
523 typedef struct _VAMacroblockParameterBufferMPEG2
525 unsigned short macroblock_address;
527 * macroblock_address (in raster scan order)
529 * bottom-right: picture-height-in-mb*picture-width-in-mb - 1
531 unsigned char macroblock_type; /* see definition below */
534 unsigned char frame_motion_type : 2;
535 unsigned char field_motion_type : 2;
536 unsigned char dct_type : 1;
538 unsigned char macroblock_modes;
540 unsigned char motion_vertical_field_select;
542 * motion_vertical_field_select:
543 * see section 6.3.17.2 in the spec
544 * only the lower 4 bits are used
545 * bit 0: first vector forward
546 * bit 1: first vector backward
547 * bit 2: second vector forward
548 * bit 3: second vector backward
550 short PMV[2][2][2]; /* see Table 7-7 in the spec */
551 unsigned short coded_block_pattern;
553 * The bitplanes for coded_block_pattern are described
554 * in Figure 6.10-12 in the spec
557 /* Number of skipped macroblocks after this macroblock */
558 unsigned short num_skipped_macroblocks;
559 } VAMacroblockParameterBufferMPEG2;
562 * OR'd flags for macroblock_type (section 6.3.17.1 in the spec)
564 #define VA_MB_TYPE_MOTION_FORWARD 0x02
565 #define VA_MB_TYPE_MOTION_BACKWARD 0x04
566 #define VA_MB_TYPE_MOTION_PATTERN 0x08
567 #define VA_MB_TYPE_MOTION_INTRA 0x10
570 * MPEG-2 Residual Data Buffer
571 * For each macroblock, there wil be 64 shorts (16-bit) in the
572 * residual data buffer
575 /****************************
576 * MPEG-4 Part 2 data structures
577 ****************************/
579 /* MPEG-4 Picture Parameter Buffer */
581 * For each frame or field, and before any slice data, a single
582 * picture parameter buffer must be send.
584 typedef struct _VAPictureParameterBufferMPEG4
586 unsigned short vop_width;
587 unsigned short vop_height;
588 VASurfaceID forward_reference_picture;
589 VASurfaceID backward_reference_picture;
592 unsigned char short_video_header : 1;
593 unsigned char chroma_format : 2;
594 unsigned char interlaced : 1;
595 unsigned char obmc_disable : 1;
596 unsigned char sprite_enable : 2;
597 unsigned char sprite_warping_accuracy : 2;
598 unsigned char quant_type : 1;
599 unsigned char quarter_sample : 1;
600 unsigned char data_partitioned : 1;
601 unsigned char reversible_vlc : 1;
603 unsigned short vol_fields;
605 unsigned char no_of_sprite_warping_points;
606 short sprite_trajectory_du[3];
607 short sprite_trajectory_dv[3];
608 unsigned char quant_precision;
611 unsigned char vop_coding_type : 2;
612 unsigned char backward_reference_vop_coding_type : 2;
613 unsigned char vop_rounding_type : 1;
614 unsigned char intra_dc_vlc_thr : 3;
615 unsigned char top_field_first : 1;
616 unsigned char alternate_vertical_scan_flag : 1;
618 unsigned short vop_fields;
620 unsigned char vop_fcode_forward;
621 unsigned char vop_fcode_backward;
622 /* short header related */
623 unsigned char num_gobs_in_vop;
624 unsigned char num_macroblocks_in_gob;
625 /* for direct mode prediction */
628 } VAPictureParameterBufferMPEG4;
630 /* MPEG-4 Inverse Quantization Matrix Buffer */
631 typedef struct _VAIQMatrixBufferMPEG4
633 int load_intra_quant_mat;
634 int load_non_intra_quant_mat;
635 unsigned char intra_quant_mat[64];
636 unsigned char non_intra_quant_mat[64];
637 } VAIQMatrixBufferMPEG4;
639 /* MPEG-4 Slice Parameter Buffer */
640 typedef struct _VASliceParameterBufferMPEG4
642 unsigned int slice_data_size;/* number of bytes in the slice data buffer for this slice */
643 unsigned int slice_data_offset;/* the offset to the first byte of slice data */
644 unsigned int slice_data_flag; /* see VA_SLICE_DATA_FLAG_XXX defintions */
645 unsigned int macroblock_offset;/* the offset to the first bit of MB from the first byte of slice data */
646 unsigned int macroblock_number;
648 } VASliceParameterBufferMPEG4;
654 typedef enum /* see 7.1.1.32 */
657 VAMvMode1MvHalfPel = 1,
658 VAMvMode1MvHalfPelBilinear = 2,
660 VAMvModeIntensityCompensation = 4
663 /* VC-1 Picture Parameter Buffer */
665 * For each picture, and before any slice data, a picture parameter
666 * buffer must be send. Multiple picture parameter buffers may be
667 * sent for a single picture. In that case picture parameters will
668 * apply to all slice data that follow it until a new picture
669 * parameter buffer is sent.
672 * pic_quantizer_type should be set to the applicable quantizer
673 * type as defined by QUANTIZER (J.1.19) and either
674 * PQUANTIZER (7.1.1.8) or PQINDEX (7.1.1.6)
676 typedef struct _VAPictureParameterBufferVC1
678 VASurfaceID forward_reference_picture;
679 VASurfaceID backward_reference_picture;
680 /* if out-of-loop post-processing is done on the render
681 target, then we need to keep the in-loop decoded
682 picture as a reference picture */
683 VASurfaceID inloop_decoded_picture;
685 /* sequence layer for AP or meta data for SP and MP */
688 unsigned char interlace : 1; /* SEQUENCE_LAYER::INTERLACE */
689 unsigned char syncmarker : 1;/* METADATA::SYNCMARKER */
690 unsigned char overlap : 1;/* METADATA::OVERLAP */
692 unsigned char sequence_fields;
695 unsigned short coded_width; /* ENTRY_POINT_LAYER::CODED_WIDTH */
696 unsigned short coded_height; /* ENTRY_POINT_LAYER::CODED_HEIGHT */
697 unsigned char closed_entry; /* ENTRY_POINT_LAYER::CLOSED_ENTRY */
698 unsigned char broken_link; /* ENTRY_POINT_LAYER::BROKEN_LINK */
699 unsigned char loopfilter; /* ENTRY_POINT_LAYER::LOOPFILTER */
700 unsigned char conditional_overlap_flag; /* ENTRY_POINT_LAYER::CONDOVER */
701 unsigned char fast_uvmc_flag; /* ENTRY_POINT_LAYER::FASTUVMC */
704 unsigned char range_mapping_luma_flag: 1; /* ENTRY_POINT_LAYER::RANGE_MAPY_FLAG */
705 unsigned char range_mapping_luma: 3; /* ENTRY_POINT_LAYER::RANGE_MAPY */
706 unsigned char range_mapping_chroma_flag: 1; /* ENTRY_POINT_LAYER::RANGE_MAPUV_FLAG */
707 unsigned char range_mapping_chroma: 3; /* ENTRY_POINT_LAYER::RANGE_MAPUV */
709 unsigned char range_mapping_fields;
712 unsigned char b_picture_fraction; /* PICTURE_LAYER::BFRACTION */
713 unsigned char cbp_table; /* PICTURE_LAYER::CBPTAB/ICBPTAB */
714 unsigned char mb_mode_table; /* PICTURE_LAYER::MBMODETAB */
715 unsigned char range_reduction_frame;/* PICTURE_LAYER::RANGEREDFRM */
716 unsigned char rounding_control; /* PICTURE_LAYER::RNDCTRL */
717 unsigned char post_processing; /* PICTURE_LAYER::POSTPROC */
718 unsigned char picture_resolution_index; /* PICTURE_LAYER::RESPIC */
719 unsigned char luma_scale; /* PICTURE_LAYER::LUMSCALE */
720 unsigned char luma_shift; /* PICTURE_LAYER::LUMSHIFT */
723 unsigned char picture_type : 2; /* PICTURE_LAYER::PTYPE */
724 unsigned char frame_coding_mode : 3;/* PICTURE_LAYER::FCM */
725 unsigned char top_field_first : 1;/* PICTURE_LAYER::TFF */
726 unsigned char is_first_field : 1; /* set to 1 if it is the first field */
727 unsigned char intensity_compensation: 1;/* PICTURE_LAYER::INTCOMP */
729 unsigned char picture_fields;
733 unsigned char mv_type_mb : 1; /* PICTURE::MVTYPEMB */
734 unsigned char direct_mb : 1; /* PICTURE::DIRECTMB */
735 unsigned char skip_mb : 1; /* PICTURE::SKIPMB */
736 unsigned char field_tx : 1; /* PICTURE::FIELDTX */
737 unsigned char forward_mb : 1; /* PICTURE::FORWARDMB */
738 unsigned char ac_pred : 1; /* PICTURE::ACPRED */
739 unsigned char overflags : 1; /* PICTURE::OVERFLAGS */
741 unsigned char raw_coding_flag;
745 unsigned char bp_mv_type_mb : 1; /* PICTURE::MVTYPEMB */
746 unsigned char bp_direct_mb : 1; /* PICTURE::DIRECTMB */
747 unsigned char bp_skip_mb : 1; /* PICTURE::SKIPMB */
748 unsigned char bp_field_tx : 1; /* PICTURE::FIELDTX */
749 unsigned char bp_forward_mb : 1; /* PICTURE::FORWARDMB */
750 unsigned char bp_ac_pred : 1; /* PICTURE::ACPRED */
751 unsigned char bp_overflags : 1; /* PICTURE::OVERFLAGS */
753 unsigned char bitplane_present_flag; /* signal what bitplane is being passed via the bitplane buffer */
757 unsigned char reference_distance_flag : 1;/* PICTURE_LAYER::REFDIST_FLAG */
758 unsigned char reference_distance : 1;/* PICTURE_LAYER::REFDIST */
759 unsigned char num_reference_pictures: 1;/* PICTURE_LAYER::NUMREF */
760 unsigned char reference_field_pic_indicator : 1;/* PICTURE_LAYER::REFFIELD */
762 unsigned short reference_fields;
766 VAMvModeVC1 mv_mode : 3; /* PICTURE_LAYER::MVMODE */
767 VAMvModeVC1 mv_mode2 : 3; /* PICTURE_LAYER::MVMODE2 */
768 unsigned char mv_table : 3; /* PICTURE_LAYER::MVTAB/IMVTAB */
769 unsigned char two_mv_block_pattern_table: 2; /* PICTURE_LAYER::2MVBPTAB */
770 unsigned char four_mv_switch : 1; /* PICTURE_LAYER::4MVSWITCH */
771 unsigned char four_mv_block_pattern_table : 2; /* PICTURE_LAYER::4MVBPTAB */
772 unsigned char extended_mv_flag : 1; /* ENTRY_POINT_LAYER::EXTENDED_MV */
773 unsigned char extended_mv_range : 2; /* PICTURE_LAYER::MVRANGE */
774 unsigned char extended_dmv_flag : 1; /* ENTRY_POINT_LAYER::EXTENDED_DMV */
775 unsigned char extended_dmv_range : 2; /* PICTURE_LAYER::DMVRANGE */
777 unsigned int mv_fields;
781 unsigned char dquant : 2; /* ENTRY_POINT_LAYER::DQUANT */
782 unsigned char half_qp : 1; /* PICTURE_LAYER::HALFQP */
783 unsigned char pic_quantizer_scale : 5;/* PICTURE_LAYER::PQUANT */
784 unsigned char pic_quantizer_type : 1;/* PICTURE_LAYER::PQUANTIZER */
785 unsigned char dq_frame : 1; /* VOPDQUANT::DQUANTFRM */
786 unsigned char dq_profile : 2; /* VOPDQUANT::DQPROFILE */
787 unsigned char dq_sb_edge : 2; /* VOPDQUANT::DQSBEDGE */
788 unsigned char dq_db_edge : 2; /* VOPDQUANT::DQDBEDGE */
789 unsigned char dq_binary_level : 1; /* VOPDQUANT::DQBILEVEL */
790 unsigned char alt_pic_quantizer : 5;/* VOPDQUANT::ALTPQUANT */
792 unsigned long pic_quantizer_fields;
796 unsigned char variable_sized_transform_flag : 1;/* ENTRY_POINT_LAYER::VSTRANSFORM */
797 unsigned char mb_level_transform_type_flag : 1;/* PICTURE_LAYER::TTMBF */
798 unsigned char frame_level_transform_type : 2;/* PICTURE_LAYER::TTFRM */
799 unsigned char transform_ac_codingset_idx1 : 2;/* PICTURE_LAYER::TRANSACFRM */
800 unsigned char transform_ac_codingset_idx2 : 2;/* PICTURE_LAYER::TRANSACFRM2 */
801 unsigned char intra_transform_dc_table : 1;/* PICTURE_LAYER::TRANSDCTAB */
803 unsigned short transform_fields;
805 } VAPictureParameterBufferVC1;
807 /* VC-1 Bitplane Buffer
808 There will be at most three bitplanes coded in any picture header. To send
809 the bitplane data more efficiently, each byte is divided in two nibbles, with
810 each nibble carrying three bitplanes for one macroblock. The following table
811 shows the bitplane data arrangement within each nibble based on the picture
814 Picture Type Bit3 Bit2 Bit1 Bit0
815 I or BI OVERFLAGS ACPRED FIELDTX
816 P MYTYPEMB SKIPMB DIRECTMB
817 B FORWARDMB SKIPMB DIRECTMB
819 Within each byte, the lower nibble is for the first MB and the upper nibble is
820 for the second MB. E.g. the lower nibble of the first byte in the bitplane
821 buffer is for Macroblock #1 and the upper nibble of the first byte is for
822 Macroblock #2 in the first row.
825 /* VC-1 Slice Parameter Buffer */
826 typedef struct _VASliceParameterBufferVC1
828 unsigned int slice_data_size;/* number of bytes in the slice data buffer for this slice */
829 unsigned int slice_data_offset;/* the offset to the first byte of slice data */
830 unsigned int slice_data_flag; /* see VA_SLICE_DATA_FLAG_XXX defintions */
831 unsigned int macroblock_offset;/* the offset to the first bit of MB from the first byte of slice data */
832 unsigned int slice_vertical_position;
833 } VASliceParameterBufferVC1;
835 /* VC-1 Slice Data Buffer */
837 This is simplely a buffer containing raw bit-stream bytes
840 /****************************
841 * H.264/AVC data structures
842 ****************************/
844 typedef struct _VAPictureH264
846 VASurfaceID picture_id;
848 unsigned int TopFieldOrderCnt;
849 unsigned int BottomFieldOrderCnt;
851 /* flags in VAPictureH264 could be OR of the following */
852 #define VA_PICTURE_H264_INVALID 0x00000001
853 #define VA_PICTURE_H264_TOP_FIELD 0x00000002
854 #define VA_PICTURE_H264_BOTTOM_FIELD 0x00000004
855 #define VA_PICTURE_H264_SHORT_TERM_REFERENCE 0x00000008
856 #define VA_PICTURE_H264_LONG_TERM_REFERENCE 0x00000010
858 /* H.264 Picture Parameter Buffer */
860 * For each picture, and before any slice data, a single
861 * picture parameter buffer must be send.
863 typedef struct _VAPictureParameterBufferH264
865 VAPictureH264 CurrPic;
866 VAPictureH264 ReferenceFrames[16]; /* in DPB */
867 unsigned short picture_width_in_mbs_minus1;
868 unsigned short picture_height_in_mbs_minus1;
869 unsigned char bit_depth_luma_minus8;
870 unsigned char bit_depth_chroma_minus8;
871 unsigned char num_ref_frames;
874 unsigned char chroma_format_idc : 2;
875 unsigned char residual_colour_transform_flag : 1;
876 unsigned char frame_mbs_only_flag : 1;
877 unsigned char mb_adaptive_frame_field_flag : 1;
878 unsigned char direct_8x8_inference_flag : 1;
879 unsigned char MinLumaBiPredSize8x8 : 1; /* see A.3.3.2 */
881 unsigned char seq_fields;
883 unsigned char num_slice_groups_minus1;
884 unsigned char slice_group_map_type;
885 signed char pic_init_qp_minus26;
886 signed char chroma_qp_index_offset;
887 signed char second_chroma_qp_index_offset;
890 unsigned char entropy_coding_mode_flag : 1;
891 unsigned char weighted_pred_flag : 1;
892 unsigned char weighted_bipred_idc : 2;
893 unsigned char transform_8x8_mode_flag : 1;
894 unsigned char field_pic_flag : 1;
895 unsigned char constrained_intra_pred_flag : 1;
897 unsigned char pic_fields;
899 unsigned short frame_num;
900 } VAPictureParameterBufferH264;
902 /* H.264 Inverse Quantization Matrix Buffer */
903 typedef struct _VAIQMatrixBufferH264
905 unsigned char ScalingList4x4[6][16];
906 unsigned char ScalingList8x8[2][64];
907 } VAIQMatrixBufferH264;
910 * H.264 Slice Group Map Buffer
911 * When VAPictureParameterBufferH264::num_slice_group_minus1 is not equal to 0,
912 * A slice group map buffer should be sent for each picture if required. The buffer
913 * is sent only when there is a change in the mapping values.
914 * The slice group map buffer map "map units" to slice groups as specified in
915 * section 8.2.2 of the H.264 spec. The buffer will contain one byte for each macroblock
916 * in raster scan order
919 /* H.264 Slice Parameter Buffer */
920 typedef struct _VASliceParameterBufferH264
922 unsigned int slice_data_size;/* number of bytes in the slice data buffer for this slice */
923 unsigned int slice_data_offset;/* the offset to the NAL start code for this slice */
924 unsigned int slice_data_flag; /* see VA_SLICE_DATA_FLAG_XXX defintions */
925 unsigned short slice_data_bit_offset; /* bit offset from NAL start code to the beginning of slice data */
926 unsigned short first_mb_in_slice;
927 unsigned char slice_type;
928 unsigned char direct_spatial_mv_pred_flag;
929 unsigned char num_ref_idx_l0_active_minus1;
930 unsigned char num_ref_idx_l1_active_minus1;
931 unsigned char cabac_init_idc;
933 unsigned char disable_deblocking_filter_idc;
934 char slice_alpha_c0_offset_div2;
935 char slice_beta_offset_div2;
936 VAPictureH264 RefPicList0[32]; /* See 8.2.4.2 */
937 VAPictureH264 RefPicList1[32]; /* See 8.2.4.2 */
938 unsigned char luma_log2_weight_denom;
939 unsigned char chroma_log2_weight_denom;
940 unsigned char luma_weight_l0_flag;
941 short luma_weight_l0[32];
942 short luma_offset_l0[32];
943 unsigned char chroma_weight_l0_flag;
944 short chroma_weight_l0[32][2];
945 short chroma_offset_l0[32][2];
946 unsigned char luma_weight_l1_flag;
947 short luma_weight_l1[32];
948 short luma_offset_l1[32];
949 unsigned char chroma_weight_l1_flag;
950 short chroma_weight_l1[32][2];
951 short chroma_offset_l1[32][2];
952 } VASliceParameterBufferH264;
954 /* Buffer functions */
957 * Creates a buffer for "num_elements" elements of "size" bytes and
958 * initalize with "data".
959 * if "data" is null, then the contents of the buffer data store
961 * Basically there are two ways to get buffer data to the server side. One is
962 * to call vaCreateBuffer() with a non-null "data", which results the data being
963 * copied to the data store on the server side. A different method that
964 * eliminates this copy is to pass null as "data" when calling vaCreateBuffer(),
965 * and then use vaMapBuffer() to map the data store from the server side to the
966 * client address space for access.
967 * Note: image buffers are created by the library, not the client. Please see
968 * vaCreateImage on how image buffers are managed.
970 VAStatus vaCreateBuffer (
973 VABufferType type, /* in */
974 unsigned int size, /* in */
975 unsigned int num_elements, /* in */
977 VABufferID *buf_id /* out */
981 * Convey to the server how many valid elements are in the buffer.
982 * e.g. if multiple slice parameters are being held in a single buffer,
983 * this will communicate to the server the number of slice parameters
984 * that are valid in the buffer.
986 VAStatus vaBufferSetNumElements (
988 VABufferID buf_id, /* in */
989 unsigned int num_elements /* in */
993 * Map data store of the buffer into the client's address space
994 * vaCreateBuffer() needs to be called with "data" set to NULL before
995 * calling vaMapBuffer()
997 VAStatus vaMapBuffer (
999 VABufferID buf_id, /* in */
1000 void **pbuf /* out */
1004 * After client making changes to a mapped data store, it needs to
1005 * "Unmap" it to let the server know that the data is ready to be
1006 * consumed by the server
1008 VAStatus vaUnmapBuffer (
1010 VABufferID buf_id /* in */
1014 * After this call, the buffer is deleted and this buffer_id is no longer valid
1015 * Only call this if the buffer is not going to be passed to vaRenderBuffer
1017 VAStatus vaDestroyBuffer (
1019 VABufferID buffer_id
1023 Render (Decode) Pictures
1025 A picture represents either a frame or a field.
1027 The Begin/Render/End sequence sends the decode buffers to the server
1031 * Get ready to decode a picture to a target surface
1033 VAStatus vaBeginPicture (
1035 VAContextID context,
1036 VASurfaceID render_target
1040 * Send decode buffers to the server.
1041 * Buffers are automatically destroyed afterwards
1043 VAStatus vaRenderPicture (
1045 VAContextID context,
1046 VABufferID *buffers,
1051 * Make the end of rendering for a picture.
1052 * The server should start processing all pending operations for this
1053 * surface. This call is non-blocking. The client can start another
1054 * Begin/Render/End sequence on a different render target.
1056 VAStatus vaEndPicture (
1068 * This function blocks until all pending operations on the render target
1069 * have been completed. Upon return it is safe to use the render target for a
1070 * different picture.
1072 VAStatus vaSyncSurface (
1074 VAContextID context,
1075 VASurfaceID render_target
1080 VASurfaceRendering = 0, /* Rendering in progress */
1081 VASurfaceDisplaying = 1, /* Displaying in progress (not safe to render into it) */
1082 /* this status is useful if surface is used as the source */
1084 VASurfaceReady = 2 /* not being rendered or displayed */
1088 * Find out any pending ops on the render target
1090 VAStatus vaQuerySurfaceStatus (
1092 VASurfaceID render_target,
1093 VASurfaceStatus *status /* out */
1097 * Images and Subpictures
1098 * VAImage is used to either get the surface data to client memory, or
1099 * to copy image data in client memory to a surface.
1100 * Both images, subpictures and surfaces follow the same 2D coordinate system where origin
1101 * is at the upper left corner with positive X to the right and positive Y down
1103 #define MAKEFOURCC(ch0, ch1, ch2, ch3) \
1104 ((unsigned long)(unsigned char) (ch0) | ((unsigned long)(unsigned char) (ch1) << 8) | \
1105 ((unsigned long)(unsigned char) (ch2) << 16) | ((unsigned long)(unsigned char) (ch3) << 24 ))
1107 /* a few common FourCCs */
1108 #define VA_FOURCC_NV12 0x3231564E
1109 #define VA_FOURCC_AI44 0x34344149
1110 #define VA_FOURCC_RGBA 0x41424752
1113 #define VA_LSB_FIRST 1
1114 #define VA_MSB_FIRST 2
1116 typedef struct _VAImageFormat
1118 unsigned int fourcc;
1119 unsigned int byte_order; /* VA_LSB_FIRST, VA_MSB_FIRST */
1120 unsigned int bits_per_pixel;
1121 /* for RGB formats */
1122 unsigned int depth; /* significant bits per pixel */
1123 unsigned int red_mask;
1124 unsigned int green_mask;
1125 unsigned int blue_mask;
1126 unsigned int alpha_mask;
1129 typedef VAGenericID VAImageID;
1131 typedef struct _VAImage
1133 VAImageID image_id; /* uniquely identify this image */
1134 VAImageFormat format;
1135 VABufferID buf; /* image data buffer */
1137 * Image data will be stored in a buffer of type VAImageBufferType to facilitate
1138 * data store on the server side for optimal performance. The buffer will be
1139 * created by the CreateImage function, and proper storage allocated based on the image
1140 * size and format. This buffer is managed by the library implementation, and
1141 * accessed by the client through the buffer Map/Unmap functions.
1143 unsigned short width;
1144 unsigned short height;
1145 unsigned int data_size;
1146 unsigned int num_planes; /* can not be greater than 3 */
1148 * An array indicating the scanline pitch in bytes for each plane.
1149 * Each plane may have a different pitch. Maximum 3 planes for planar formats
1151 unsigned int pitches[3];
1153 * An array indicating the byte offset from the beginning of the image data
1154 * to the start of each plane.
1156 unsigned int offsets[3];
1158 /* The following fields are only needed for paletted formats */
1159 int num_palette_entries; /* set to zero for non-palette images */
1161 * Each component is one byte and entry_bytes indicates the number of components in
1162 * each entry (eg. 3 for YUV palette entries). set to zero for non-palette images
1166 * An array of ascii characters describing the order of the components within the bytes.
1167 * Only entry_bytes characters of the string are used.
1169 char component_order[4];
1172 /* Get maximum number of image formats supported by the implementation */
1173 int vaMaxNumImageFormats (
1178 * Query supported image formats
1179 * The caller must provide a "format_list" array that can hold at
1180 * least vaMaxNumImageFormats() entries. The actual number of formats
1181 * returned in "format_list" is returned in "num_formats".
1183 VAStatus vaQueryImageFormats (
1185 VAImageFormat *format_list, /* out */
1186 int *num_formats /* out */
1190 * Create a VAImage structure
1191 * The width and height fields returned in the VAImage structure may get
1192 * enlarged for some YUV formats. Upon return from this function,
1193 * image->buf has been created and proper storage allocated by the library.
1194 * The client can access the image through the Map/Unmap calls.
1196 VAStatus vaCreateImage (
1198 VAImageFormat *format,
1201 VAImage *image /* out */
1205 * Should call DestroyImage before destroying the surface it is bound to
1207 VAStatus vaDestroyImage (
1212 VAStatus vaSetImagePalette (
1216 * pointer to an array holding the palette data. The size of the array is
1217 * num_palette_entries * entry_bytes in size. The order of the components
1218 * in the palette is described by the component_order in VAImage struct
1220 unsigned char *palette
1224 * Retrive surface data into a VAImage
1225 * Image must be in a format supported by the implementation
1227 VAStatus vaGetImage (
1229 VASurfaceID surface,
1230 int x, /* coordinates of the upper left source pixel */
1232 unsigned int width, /* width and height of the region */
1233 unsigned int height,
1238 * Copy data from a VAImage to a surface
1239 * Image must be in a format supported by the implementation
1240 * Returns a VA_STATUS_ERROR_SURFACE_BUSY if the surface
1241 * shouldn't be rendered into when this is called
1242 * The source and destionation width and height are the same and
1243 * no scaling is performed with this operation.
1245 VAStatus vaPutImage (
1247 VASurfaceID surface,
1252 unsigned int height,
1258 * Similar to vaPutImage but with additional destination width
1259 * and height arguments to enable scaling
1261 VAStatus vaPutImage2 (
1263 VASurfaceID surface,
1267 unsigned int src_width,
1268 unsigned int src_height,
1271 unsigned int dest_width,
1272 unsigned int dest_height
1276 * Derive an VAImage from an existing surface.
1277 * This interface will derive a VAImage and corresponding image buffer from
1278 * an existing VA Surface. The image buffer can then be mapped/unmapped for
1279 * direct CPU access. This operation is only possible on implementations with
1280 * direct rendering capabilities and internal surface formats that can be
1281 * represented with a VAImage. When the operation is not possible this interface
1282 * will return VA_STATUS_ERROR_OPERATION_FAILED. Clients should then fall back
1283 * to using vaCreateImage + vaPutImage to accomplish the same task in an
1286 * Implementations should only return success when the resulting image buffer
1287 * would be useable with vaMap/Unmap.
1289 * When directly accessing a surface special care must be taken to insure
1290 * proper synchronization with the graphics hardware. Clients should call
1291 * vaQuerySurfaceStatus to insure that a surface is not the target of concurrent
1292 * rendering or currently being displayed by an overlay.
1294 * Additionally nothing about the contents of a surface should be assumed
1295 * following a vaPutSurface. Implementations are free to modify the surface for
1296 * scaling or subpicture blending within a call to vaPutImage.
1298 * Calls to vaPutImage or vaGetImage using the same surface from which the image
1299 * has been derived will return VA_STATUS_ERROR_SURFACE_BUSY. vaPutImage or
1300 * vaGetImage with other surfaces is supported.
1302 * An image created with vaDeriveImage should be freed with vaDestroyImage. The
1303 * image and image buffer structures will be destroyed; however, the underlying
1304 * surface will remain unchanged until freed with vaDestroySurfaces.
1306 VAStatus vaDeriveImage (
1308 VASurfaceID surface,
1309 VAImage *image /* out */
1316 * Subpicture is a special type of image that can be blended
1317 * with a surface during vaPutSurface(). Subpicture can be used to render
1318 * DVD sub-titles or closed captioning text etc.
1321 typedef VAGenericID VASubpictureID;
1323 /* Get maximum number of subpicture formats supported by the implementation */
1324 int vaMaxNumSubpictureFormats (
1328 /* flags for subpictures */
1329 #define VA_SUBPICTURE_CHROMA_KEYING 0x0001
1330 #define VA_SUBPICTURE_GLOBAL_ALPHA 0x0002
1332 * Query supported subpicture formats
1333 * The caller must provide a "format_list" array that can hold at
1334 * least vaMaxNumSubpictureFormats() entries. The flags arrary holds the flag
1335 * for each format to indicate additional capabilities for that format. The actual
1336 * number of formats returned in "format_list" is returned in "num_formats".
1337 * flags: returned value to indicate addtional capabilities
1338 * VA_SUBPICTURE_CHROMA_KEYING - supports chroma-keying
1339 * VA_SUBPICTURE_GLOBAL_ALPHA - supports global alpha
1341 VAStatus vaQuerySubpictureFormats (
1343 VAImageFormat *format_list, /* out */
1344 unsigned int *flags, /* out */
1345 unsigned int *num_formats /* out */
1349 * Subpictures are created with an image associated.
1351 VAStatus vaCreateSubpicture (
1354 VASubpictureID *subpicture /* out */
1358 * Destroy the subpicture before destroying the image it is assocated to
1360 VAStatus vaDestroySubpicture (
1362 VASubpictureID subpicture
1366 * Bind an image to the subpicture. This image will now be associated with
1367 * the subpicture instead of the one at creation.
1369 VAStatus vaSetSubpictureImage (
1371 VASubpictureID subpicture,
1376 * If chromakey is enabled, then the area where the source value falls within
1377 * the chromakey [min, max] range is transparent
1378 * The chromakey component format is the following:
1379 * For RGB: [0:7] Red [8:15] Blue [16:23] Green
1380 * For YUV: [0:7] V [8:15] U [16:23] Y
1381 * The chromakey mask can be used to mask out certain components for chromakey
1384 VAStatus vaSetSubpictureChromakey (
1386 VASubpictureID subpicture,
1387 unsigned int chromakey_min,
1388 unsigned int chromakey_max,
1389 unsigned int chromakey_mask
1393 * Global alpha value is between 0 and 1. A value of 1 means fully opaque and
1394 * a value of 0 means fully transparent. If per-pixel alpha is also specified then
1395 * the overall alpha is per-pixel alpha multiplied by the global alpha
1397 VAStatus vaSetSubpictureGlobalAlpha (
1399 VASubpictureID subpicture,
1404 * vaAssociateSubpicture associates the subpicture with target_surfaces.
1405 * It defines the region mapping between the subpicture and the target
1406 * surfaces through source and destination rectangles (with the same width and height).
1407 * Both will be displayed at the next call to vaPutSurface. Additional
1408 * associations before the call to vaPutSurface simply overrides the association.
1410 VAStatus vaAssociateSubpicture (
1412 VASubpictureID subpicture,
1413 VASurfaceID *target_surfaces,
1415 short src_x, /* upper left offset in subpicture */
1417 short dest_x, /* upper left offset in surface */
1419 unsigned short width,
1420 unsigned short height,
1422 * whether to enable chroma-keying or global-alpha
1423 * see VA_SUBPICTURE_XXX values
1429 * Similar to vaAssociateSubpicture but with additional destination width
1430 * and height to enable scaling
1432 VAStatus vaAssociateSubpicture2 (
1434 VASubpictureID subpicture,
1435 VASurfaceID *target_surfaces,
1437 short src_x, /* upper left offset in subpicture */
1439 unsigned short src_width,
1440 unsigned short src_height,
1441 short dest_x, /* upper left offset in surface */
1443 unsigned short dest_width,
1444 unsigned short dest_height,
1446 * whether to enable chroma-keying or global-alpha
1447 * see VA_SUBPICTURE_XXX values
1453 * vaDeassociateSubpicture removes the association of the subpicture with target_surfaces.
1455 VAStatus vaDeassociateSubpicture (
1457 VASubpictureID subpicture,
1458 VASurfaceID *target_surfaces,
1462 typedef struct _VARectangle
1466 unsigned short width;
1467 unsigned short height;
1471 * Display attributes
1472 * Display attributes are used to control things such as contrast, hue, saturation,
1473 * brightness etc. in the rendering process. The application can query what
1474 * attributes are supported by the driver, and then set the appropriate attributes
1475 * before calling vaPutSurface()
1478 /* Currently defined display attribute types */
1481 VADisplayAttribBrightness = 0,
1482 VADisplayAttribContrast = 1,
1483 VADisplayAttribHue = 2,
1484 VADisplayAttribSaturation = 3,
1485 /* client can specifiy a background color for the target window */
1486 VADisplayAttribBackgroundColor = 4,
1488 * this is a gettable only attribute. For some implementations that use the
1489 * hardware overlay, after PutSurface is called, the surface can not be
1490 * re-used until after the subsequent PutSurface call. If this is the case
1491 * then the value for this attribute will be set to 1 so that the client
1492 * will not attempt to re-use the surface right after returning from a call
1495 VADisplayAttribDirectSurface = 5,
1496 } VADisplayAttribType;
1498 /* flags for VADisplayAttribute */
1499 #define VA_DISPLAY_ATTRIB_NOT_SUPPORTED 0x0000
1500 #define VA_DISPLAY_ATTRIB_GETTABLE 0x0001
1501 #define VA_DISPLAY_ATTRIB_SETTABLE 0x0002
1503 typedef struct _VADisplayAttribute
1505 VADisplayAttribType type;
1508 int value; /* used by the set/get attribute functions */
1509 /* flags can be VA_DISPLAY_ATTRIB_GETTABLE or VA_DISPLAY_ATTRIB_SETTABLE or OR'd together */
1511 } VADisplayAttribute;
1513 /* Get maximum number of display attributs supported by the implementation */
1514 int vaMaxNumDisplayAttributes (
1519 * Query display attributes
1520 * The caller must provide a "attr_list" array that can hold at
1521 * least vaMaxNumDisplayAttributes() entries. The actual number of attributes
1522 * returned in "attr_list" is returned in "num_attributes".
1524 VAStatus vaQueryDisplayAttributes (
1526 VADisplayAttribute *attr_list, /* out */
1527 int *num_attributes /* out */
1531 * Get display attributes
1532 * This function returns the current attribute values in "attr_list".
1533 * Only attributes returned with VA_DISPLAY_ATTRIB_GETTABLE set in the "flags" field
1534 * from vaQueryDisplayAttributes() can have their values retrieved.
1536 VAStatus vaGetDisplayAttributes (
1538 VADisplayAttribute *attr_list, /* in/out */
1543 * Set display attributes
1544 * Only attributes returned with VA_DISPLAY_ATTRIB_SETTABLE set in the "flags" field
1545 * from vaQueryDisplayAttributes() can be set. If the attribute is not settable or
1546 * the value is out of range, the function returns VA_STATUS_ERROR_ATTR_NOT_SUPPORTED
1548 VAStatus vaSetDisplayAttributes (
1550 VADisplayAttribute *attr_list,
1561 /*****************************************************************************/
1563 Sample Program (w/ pseudo code)
1565 Mostly to demonstrate program flow with no error handling ...
1567 /*****************************************************************************/
1569 /* MPEG-2 VLD decode for a 720x480 frame */
1571 int major_ver, minor_ver;
1572 vaInitialize(dpy, &major_ver, &minor_ver);
1574 int max_num_profiles, max_num_entrypoints, max_num_attribs;
1575 max_num_profiles = vaMaxNumProfiles(dpy);
1576 max_num_entrypoints = vaMaxNumEntrypoints(dpy);
1577 max_num_attribs = vaMaxNumAttributes(dpy);
1579 /* find out whether MPEG2 MP is supported */
1580 VAProfile *profiles = malloc(sizeof(VAProfile)*max_num_profiles);
1582 vaQueryConfigProfiles(dpy, profiles, &profiles);
1584 * traverse "profiles" to locate the one that matches VAProfileMPEG2Main
1587 /* now get the available entrypoints for MPEG2 MP */
1588 VAEntrypoint *entrypoints = malloc(sizeof(VAEntrypoint)*max_num_entrypoints);
1589 int num_entrypoints;
1590 vaQueryConfigEntrypoints(dpy, VAProfileMPEG2Main, entrypoints, &num_entrypoints);
1592 /* traverse "entrypoints" to see whether VLD is there */
1594 /* Assuming finding VLD, find out the format for the render target */
1595 VAConfigAttrib attrib;
1596 attrib.type = VAConfigAttribRTFormat;
1597 vaGetConfigAttributes(dpy, VAProfileMPEG2Main, VAEntrypointVLD,
1600 if (attrib.value & VA_RT_FORMAT_YUV420)
1601 /* Found desired RT format, keep going */
1603 VAConfigID config_id;
1604 vaCreateConfig(dpy, VAProfileMPEG2Main, VAEntrypointVLD, &attrib, 1,
1608 * create surfaces for the current target as well as reference frames
1609 * we can get by with 4 surfaces for MPEG-2
1611 VASurfaceID surfaces[4];
1612 vaCreateSurfaces(dpy, 720, 480, VA_RT_FORMAT_YUV420, 4, surfaces);
1615 * Create a context for this decode pipe
1617 VAContextID context;
1618 vaCreateContext(dpy, config_id, 720, 480, VA_PROGRESSIVE, surfaces,
1621 /* Create a picture parameter buffer for this frame */
1622 VABufferID picture_buf;
1623 VAPictureParameterBufferMPEG2 *picture_param;
1624 vaCreateBuffer(dpy, context, VAPictureParameterBufferType, sizeof(VAPictureParameterBufferMPEG2), 1, NULL, &picture_buf);
1625 vaMapBuffer(dpy, picture_buf, &picture_param);
1626 picture_param->horizontal_size = 720;
1627 picture_param->vertical_size = 480;
1628 picture_param->picture_coding_type = 1; /* I-frame */
1629 /* fill in picture_coding_extension fields here */
1630 vaUnmapBuffer(dpy, picture_buf);
1632 /* Create an IQ matrix buffer for this frame */
1634 VAIQMatrixBufferMPEG2 *iq_matrix;
1635 vaCreateBuffer(dpy, context, VAIQMatrixBufferType, sizeof(VAIQMatrixBufferMPEG2), 1, NULL, &iq_buf);
1636 vaMapBuffer(dpy, iq_buf, &iq_matrix);
1637 /* fill values for IQ_matrix here */
1638 vaUnmapBuffer(dpy, iq_buf);
1640 /* send the picture and IQ matrix buffers to the server */
1641 vaBeginPicture(dpy, context, surfaces[0]);
1643 vaRenderPicture(dpy, context, &picture_buf, 1);
1644 vaRenderPicture(dpy, context, &iq_buf, 1);
1647 * Send slices in this frame to the server.
1648 * For MPEG-2, each slice is one row of macroblocks, and
1649 * we have 30 slices for a 720x480 frame
1651 for (int i = 1; i <= 30; i++) {
1653 /* Create a slice parameter buffer */
1654 VABufferID slice_param_buf;
1655 VASliceParameterBufferMPEG2 *slice_param;
1656 vaCreateBuffer(dpy, context, VASliceParameterBufferType, sizeof(VASliceParameterBufferMPEG2), 1, NULL, &slice_param_buf);
1657 vaMapBuffer(dpy, slice_param_buf, &slice_param);
1658 slice_param->slice_data_offset = 0;
1659 /* Let's say all slices in this bit-stream has 64-bit header */
1660 slice_param->macroblock_offset = 64;
1661 slice_param->vertical_position = i;
1662 /* set up the rest based on what is in the slice header ... */
1663 vaUnmapBuffer(dpy, slice_param_buf);
1665 /* send the slice parameter buffer */
1666 vaRenderPicture(dpy, context, &slice_param_buf, 1);
1668 /* Create a slice data buffer */
1669 unsigned char *slice_data;
1670 VABufferID slice_data_buf;
1671 vaCreateBuffer(dpy, context, VASliceDataBufferType, x /* decoder figure out how big */, 1, NULL, &slice_data_buf);
1672 vaMapBuffer(dpy, slice_data_buf, &slice_data);
1673 /* decoder fill in slice_data */
1674 vaUnmapBuffer(dpy, slice_data_buf);
1676 /* send the slice data buffer */
1677 vaRenderPicture(dpy, context, &slice_data_buf, 1);
1680 /* all slices have been sent, mark the end for this frame */
1681 vaEndPicture(dpy, context);
1683 /* The following code demonstrates rendering a sub-title with the target surface */
1684 /* Find out supported Subpicture formats */
1685 VAImageFormat sub_formats[4];
1687 vaQuerySubpictureFormats(dpy, sub_formats, &num_formats);
1688 /* Assume that we find AI44 as a subpicture format in sub_formats[0] */
1690 VASubpictureID subpicture;
1691 unsigned char *sub_data;
1692 /* create an image for the subtitle */
1693 vaCreateImage(dpy, sub_formats, 128, 16, &sub_image);
1694 vaMapBuffer(dpy, sub_image->buf, &sub_data);
1695 /* fill the image data */
1696 vaUnmapBuffer(dpy, sub_image->buf);
1697 vaCreateSubpicture(dpy, sub_image, &subpicture);
1698 unsigned char palette[3][16];
1699 /* fill the palette data */
1700 vaSetSubpicturePalette(dpy, subpicture, palette);
1701 vaAssociateSubpicture(dpy, subpicture, surfaces, 1, 0, 0, 296, 400, 128, 16);
1702 vaPutSurface(dpy, surfaces, win, 0, 0, 720, 480, 100, 100, 640, 480, NULL, 0, 0);