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
52 * rev 0.29 (02/07/2007 Jonathan Bian) - VC1 parameter fixes,
53 * added VA_STATUS_ERROR_RESOLUTION_NOT_SUPPORTED
56 * Some concepts borrowed from XvMC and XvImage.
57 * Thanks to Waldo Bastian, Matt Sottek and Austin Yuan at Intel for many valuable feedbacks.
70 This API is intended to provide an interface between a video decode
71 application (client) and a hardware decode accelerator (server), to off-load
72 video decode operations from the host to the hardware accelerator at various
75 The basic operation steps are:
77 - Negotiate a mutually acceptable configuration with the server to lock
78 down profile, entrypoints, and other attributes that will not change on
79 a frame-by-frame basis.
80 - Create a decode context which represents a "virtualized" hardware decode
82 - Get and fill decode buffers with picture level, slice level and macroblock
83 level data (depending on entrypoints)
84 - Pass the decode buffers to the server to decode the current frame
86 Initialization & Configuration Management
88 - Find out supported profiles
89 - Find out entrypoints for a given profile
90 - Find out configuration attributes for a given profile/entrypoint pair
91 - Create a configuration for use by the decoder
95 typedef void* VADisplay; /* window system dependent */
97 typedef int VAStatus; /* Return status type from functions */
98 /* Values for the return status */
99 #define VA_STATUS_SUCCESS 0x00000000
100 #define VA_STATUS_ERROR_OPERATION_FAILED 0x00000001
101 #define VA_STATUS_ERROR_ALLOCATION_FAILED 0x00000002
102 #define VA_STATUS_ERROR_INVALID_DISPLAY 0x00000003
103 #define VA_STATUS_ERROR_INVALID_CONFIG 0x00000004
104 #define VA_STATUS_ERROR_INVALID_CONTEXT 0x00000005
105 #define VA_STATUS_ERROR_INVALID_SURFACE 0x00000006
106 #define VA_STATUS_ERROR_INVALID_BUFFER 0x00000007
107 #define VA_STATUS_ERROR_INVALID_IMAGE 0x00000008
108 #define VA_STATUS_ERROR_INVALID_SUBPICTURE 0x00000009
109 #define VA_STATUS_ERROR_ATTR_NOT_SUPPORTED 0x0000000a
110 #define VA_STATUS_ERROR_MAX_NUM_EXCEEDED 0x0000000b
111 #define VA_STATUS_ERROR_UNSUPPORTED_PROFILE 0x0000000c
112 #define VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT 0x0000000d
113 #define VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT 0x0000000e
114 #define VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE 0x0000000f
115 #define VA_STATUS_ERROR_SURFACE_BUSY 0x00000010
116 #define VA_STATUS_ERROR_FLAG_NOT_SUPPORTED 0x00000011
117 #define VA_STATUS_ERROR_INVALID_PARAMETER 0x00000012
118 #define VA_STATUS_ERROR_RESOLUTION_NOT_SUPPORTED 0x00000013
119 #define VA_STATUS_ERROR_UNKNOWN 0xFFFFFFFF
122 * Returns a short english description of error_status
124 const char *vaErrorStr(VAStatus error_status);
128 * A display must be obtained by calling vaGetDisplay() before calling
129 * vaInitialize() and other functions. This connects the API to the
130 * native window system.
131 * For X Windows, native_dpy would be from XOpenDisplay()
133 typedef void* NativeDisplay; /* window system dependent */
135 VADisplay vaGetDisplay (
136 NativeDisplay native_dpy /* implementation specific */
140 * Initialize the library
142 VAStatus vaInitialize (
144 int *major_version, /* out */
145 int *minor_version /* out */
149 * After this call, all library internal resources will be cleaned up
151 VAStatus vaTerminate (
156 * vaQueryVendorString returns a pointer to a zero-terminated string
157 * describing some aspects of the VA implemenation on a specific
158 * hardware accelerator. The format of the returned string is vendor
159 * specific and at the discretion of the implementer.
160 * e.g. for the Intel GMA500 implementation, an example would be:
161 * "Intel GMA500 - 2.0.0.32L.0005"
163 const char *vaQueryVendorString (
167 typedef int (*VAPrivFunc)();
170 * Return a function pointer given a function name in the library.
171 * This allows private interfaces into the library
173 VAPrivFunc vaGetLibFunc (
178 /* Currently defined profiles */
181 VAProfileMPEG2Simple = 0,
182 VAProfileMPEG2Main = 1,
183 VAProfileMPEG4Simple = 2,
184 VAProfileMPEG4AdvancedSimple = 3,
185 VAProfileMPEG4Main = 4,
186 VAProfileH264Baseline = 5,
187 VAProfileH264Main = 6,
188 VAProfileH264High = 7,
189 VAProfileVC1Simple = 8,
190 VAProfileVC1Main = 9,
191 VAProfileVC1Advanced = 10,
192 VAProfileH263Baseline = 11
196 * Currently defined entrypoints
202 VAEntrypointIDCT = 3,
203 VAEntrypointMoComp = 4,
204 VAEntrypointDeblocking = 5,
205 /* Encode entrypoints */
206 VAEntrypointEncodeES = 6, /* slice level encode */
209 /* Currently defined configuration attribute types */
212 VAConfigAttribRTFormat = 0,
213 VAConfigAttribSpatialResidual = 1,
214 VAConfigAttribSpatialClipping = 2,
215 VAConfigAttribIntraResidual = 3,
216 VAConfigAttribEncryption = 4,
217 VAConfigAttribRateControl = 5,
218 } VAConfigAttribType;
221 * Configuration attributes
222 * If there is more than one value for an attribute, a default
223 * value will be assigned to the attribute if the client does not
224 * specify the attribute when creating a configuration
226 typedef struct _VAConfigAttrib {
227 VAConfigAttribType type;
228 unsigned int value; /* OR'd flags (bits) for this attribute */
231 /* attribute value for VAConfigAttribRTFormat */
232 #define VA_RT_FORMAT_YUV420 0x00000001
233 #define VA_RT_FORMAT_YUV422 0x00000002
234 #define VA_RT_FORMAT_YUV444 0x00000004
236 /* attribute value for VAConfigAttribRateControl */
237 #define VA_RC_NONE 0x00000001
238 #define VA_RC_CBR 0x00000002
239 #define VA_RC_VBR 0x00000004
242 * if an attribute is not applicable for a given
243 * profile/entrypoint pair, then set the value to the following
245 #define VA_ATTRIB_NOT_SUPPORTED 0x80000000
247 /* Get maximum number of profiles supported by the implementation */
248 int vaMaxNumProfiles (
252 /* Get maximum number of entrypoints supported by the implementation */
253 int vaMaxNumEntrypoints (
257 /* Get maximum number of attributs supported by the implementation */
258 int vaMaxNumConfigAttributes (
263 * Query supported profiles
264 * The caller must provide a "profile_list" array that can hold at
265 * least vaMaxNumProfile() entries. The actual number of profiles
266 * returned in "profile_list" is returned in "num_profile".
268 VAStatus vaQueryConfigProfiles (
270 VAProfile *profile_list, /* out */
271 int *num_profiles /* out */
275 * Query supported entrypoints for a given profile
276 * The caller must provide an "entrypoint_list" array that can hold at
277 * least vaMaxNumEntrypoints() entries. The actual number of entrypoints
278 * returned in "entrypoint_list" is returned in "num_entrypoints".
280 VAStatus vaQueryConfigEntrypoints (
283 VAEntrypoint *entrypoint_list, /* out */
284 int *num_entrypoints /* out */
288 * Get attributes for a given profile/entrypoint pair
289 * The caller must provide an "attrib_list" with all attributes to be
290 * retrieved. Upon return, the attributes in "attrib_list" have been
291 * updated with their value. Unknown attributes or attributes that are
292 * not supported for the given profile/entrypoint pair will have their
293 * value set to VA_ATTRIB_NOT_SUPPORTED
295 VAStatus vaGetConfigAttributes (
298 VAEntrypoint entrypoint,
299 VAConfigAttrib *attrib_list, /* in/out */
303 /* Generic ID type, can be re-typed for specific implementation */
304 typedef unsigned int VAGenericID;
306 typedef VAGenericID VAConfigID;
309 * Create a configuration for the decode pipeline
310 * it passes in the attribute list that specifies the attributes it cares
311 * about, with the rest taking default values.
313 VAStatus vaCreateConfig (
316 VAEntrypoint entrypoint,
317 VAConfigAttrib *attrib_list,
319 VAConfigID *config_id /* out */
323 * Free resources associdated with a given config
325 VAStatus vaDestroyConfig (
331 * Query all attributes for a given configuration
332 * The profile of the configuration is returned in "profile"
333 * The entrypoint of the configuration is returned in "entrypoint"
334 * The caller must provide an "attrib_list" array that can hold at least
335 * vaMaxNumConfigAttributes() entries. The actual number of attributes
336 * returned in "attrib_list" is returned in "num_attribs"
338 VAStatus vaQueryConfigAttributes (
340 VAConfigID config_id,
341 VAProfile *profile, /* out */
342 VAEntrypoint *entrypoint, /* out */
343 VAConfigAttrib *attrib_list,/* out */
344 int *num_attribs /* out */
349 * Contexts and Surfaces
351 * Context represents a "virtual" video decode pipeline. Surfaces are render
352 * targets for a given context. The data in the surfaces are not accessible
353 * to the client and the internal data format of the surface is implementatin
356 * Surfaces will be bound to a context when the context is created. Once
357 * a surface is bound to a given context, it can not be used to create
358 * another context. The association is removed when the context is destroyed
360 * Both contexts and surfaces are identified by unique IDs and its
361 * implementation specific internals are kept opaque to the clients
364 typedef VAGenericID VAContextID;
366 typedef VAGenericID VASurfaceID;
368 #define VA_INVALID_SURFACE -1
371 * vaCreateSurfaces - Create an array of surfaces used for decode and display
373 * width: surface width
374 * height: surface height
375 * format: VA_RT_FORMAT_YUV420, VA_RT_FORMAT_YUV422 or VA_RT_FORMAT_YUV444
376 * num_surfaces: number of surfaces to be created
377 * surfaces: array of surfaces created upon return
379 VAStatus vaCreateSurfaces (
385 VASurfaceID *surfaces /* out */
389 * vaDestroySurfaces - Destroy resources associated with surfaces.
390 * Surfaces can only be destroyed after the context associated has been
393 * surfaces: array of surfaces to destroy
394 * num_surfaces: number of surfaces in the array to be destroyed.
396 VAStatus vaDestroySurfaces (
398 VASurfaceID *surfaces,
402 #define VA_PROGRESSIVE 0x1
404 * vaCreateContext - Create a context
406 * config_id: configuration for the context
407 * picture_width: coded picture width
408 * picture_height: coded picture height
409 * flag: any combination of the following:
410 * VA_PROGRESSIVE (only progressive frame pictures in the sequence when set)
411 * render_targets: render targets (surfaces) tied to the context
412 * num_render_targets: number of render targets in the above array
413 * context: created context id upon return
415 VAStatus vaCreateContext (
417 VAConfigID config_id,
421 VASurfaceID *render_targets,
422 int num_render_targets,
423 VAContextID *context /* out */
427 * vaDestroyContext - Destroy a context
429 * context: context to be destroyed
431 VAStatus vaDestroyContext (
438 * Buffers are used to pass various types of data from the
439 * client to the server. The server maintains a data store
440 * for each buffer created, and the client idenfies a buffer
441 * through a unique buffer id assigned by the server.
444 typedef VAGenericID VABufferID;
448 VAPictureParameterBufferType = 0,
449 VAIQMatrixBufferType = 1,
450 VABitPlaneBufferType = 2,
451 VASliceGroupMapBufferType = 3,
452 VASliceParameterBufferType = 4,
453 VASliceDataBufferType = 5,
454 VAMacroblockParameterBufferType = 6,
455 VAResidualDataBufferType = 7,
456 VADeblockingParameterBufferType = 8,
457 VAImageBufferType = 9,
458 VAEncCodedBufferType = 10,
459 VAEncSequenceParameterBufferType = 11,
460 VAEncPictureParameterBufferType = 12,
461 VAEncSliceParameterBufferType = 13,
464 /****************************
465 * MPEG-2 data structures
466 ****************************/
468 /* MPEG-2 Picture Parameter Buffer */
470 * For each frame or field, and before any slice data, a single
471 * picture parameter buffer must be send.
473 typedef struct _VAPictureParameterBufferMPEG2
475 unsigned short horizontal_size;
476 unsigned short vertical_size;
477 VASurfaceID forward_reference_picture;
478 VASurfaceID backward_reference_picture;
479 /* meanings of the following fields are the same as in the standard */
480 int picture_coding_type;
481 int f_code; /* pack all four fcode into this */
484 unsigned char intra_dc_precision : 2;
485 unsigned char picture_structure : 2;
486 unsigned char top_field_first : 1;
487 unsigned char frame_pred_frame_dct : 1;
488 unsigned char concealment_motion_vectors : 1;
489 unsigned char q_scale_type : 1;
490 unsigned char intra_vlc_format : 1;
491 unsigned char alternate_scan : 1;
492 unsigned char repeat_first_field : 1;
493 unsigned char progressive_frame : 1;
494 unsigned char is_first_field : 1; /* indicate whether the current field
495 * is the first field for field picture
498 unsigned int picture_coding_extension;
500 } VAPictureParameterBufferMPEG2;
502 /* MPEG-2 Inverse Quantization Matrix Buffer */
503 typedef struct _VAIQMatrixBufferMPEG2
505 int load_intra_quantiser_matrix;
506 int load_non_intra_quantiser_matrix;
507 int load_chroma_intra_quantiser_matrix;
508 int load_chroma_non_intra_quantiser_matrix;
509 unsigned char intra_quantiser_matrix[64];
510 unsigned char non_intra_quantiser_matrix[64];
511 unsigned char chroma_intra_quantiser_matrix[64];
512 unsigned char chroma_non_intra_quantiser_matrix[64];
513 } VAIQMatrixBufferMPEG2;
516 * There will be cases where the bitstream buffer will not have enough room to hold
517 * the data for the entire slice, and the following flags will be used in the slice
518 * parameter to signal to the server for the possible cases.
519 * If a slice parameter buffer and slice data buffer pair is sent to the server with
520 * the slice data partially in the slice data buffer (BEGIN and MIDDLE cases below),
521 * then a slice parameter and data buffer needs to be sent again to complete this slice.
523 #define VA_SLICE_DATA_FLAG_ALL 0x00 /* whole slice is in the buffer */
524 #define VA_SLICE_DATA_FLAG_BEGIN 0x01 /* The beginning of the slice is in the buffer but the end if not */
525 #define VA_SLICE_DATA_FLAG_MIDDLE 0x02 /* Neither beginning nor end of the slice is in the buffer */
526 #define VA_SLICE_DATA_FLAG_END 0x04 /* end of the slice is in the buffer */
528 /* MPEG-2 Slice Parameter Buffer */
529 typedef struct _VASliceParameterBufferMPEG2
531 unsigned int slice_data_size;/* number of bytes in the slice data buffer for this slice */
532 unsigned int slice_data_offset;/* the offset to the first byte of slice data */
533 unsigned int slice_data_flag; /* see VA_SLICE_DATA_FLAG_XXX defintions */
534 unsigned int macroblock_offset;/* the offset to the first bit of MB from the first byte of slice data */
535 unsigned int slice_vertical_position;
536 int quantiser_scale_code;
537 int intra_slice_flag;
538 } VASliceParameterBufferMPEG2;
540 /* MPEG-2 Macroblock Parameter Buffer */
541 typedef struct _VAMacroblockParameterBufferMPEG2
543 unsigned short macroblock_address;
545 * macroblock_address (in raster scan order)
547 * bottom-right: picture-height-in-mb*picture-width-in-mb - 1
549 unsigned char macroblock_type; /* see definition below */
552 unsigned char frame_motion_type : 2;
553 unsigned char field_motion_type : 2;
554 unsigned char dct_type : 1;
556 unsigned char macroblock_modes;
558 unsigned char motion_vertical_field_select;
560 * motion_vertical_field_select:
561 * see section 6.3.17.2 in the spec
562 * only the lower 4 bits are used
563 * bit 0: first vector forward
564 * bit 1: first vector backward
565 * bit 2: second vector forward
566 * bit 3: second vector backward
568 short PMV[2][2][2]; /* see Table 7-7 in the spec */
569 unsigned short coded_block_pattern;
571 * The bitplanes for coded_block_pattern are described
572 * in Figure 6.10-12 in the spec
575 /* Number of skipped macroblocks after this macroblock */
576 unsigned short num_skipped_macroblocks;
577 } VAMacroblockParameterBufferMPEG2;
580 * OR'd flags for macroblock_type (section 6.3.17.1 in the spec)
582 #define VA_MB_TYPE_MOTION_FORWARD 0x02
583 #define VA_MB_TYPE_MOTION_BACKWARD 0x04
584 #define VA_MB_TYPE_MOTION_PATTERN 0x08
585 #define VA_MB_TYPE_MOTION_INTRA 0x10
588 * MPEG-2 Residual Data Buffer
589 * For each macroblock, there wil be 64 shorts (16-bit) in the
590 * residual data buffer
593 /****************************
594 * MPEG-4 Part 2 data structures
595 ****************************/
597 /* MPEG-4 Picture Parameter Buffer */
599 * For each frame or field, and before any slice data, a single
600 * picture parameter buffer must be send.
602 typedef struct _VAPictureParameterBufferMPEG4
604 unsigned short vop_width;
605 unsigned short vop_height;
606 VASurfaceID forward_reference_picture;
607 VASurfaceID backward_reference_picture;
610 unsigned char short_video_header : 1;
611 unsigned char chroma_format : 2;
612 unsigned char interlaced : 1;
613 unsigned char obmc_disable : 1;
614 unsigned char sprite_enable : 2;
615 unsigned char sprite_warping_accuracy : 2;
616 unsigned char quant_type : 1;
617 unsigned char quarter_sample : 1;
618 unsigned char data_partitioned : 1;
619 unsigned char reversible_vlc : 1;
621 unsigned short vol_fields;
623 unsigned char no_of_sprite_warping_points;
624 short sprite_trajectory_du[3];
625 short sprite_trajectory_dv[3];
626 unsigned char quant_precision;
629 unsigned char vop_coding_type : 2;
630 unsigned char backward_reference_vop_coding_type : 2;
631 unsigned char vop_rounding_type : 1;
632 unsigned char intra_dc_vlc_thr : 3;
633 unsigned char top_field_first : 1;
634 unsigned char alternate_vertical_scan_flag : 1;
636 unsigned short vop_fields;
638 unsigned char vop_fcode_forward;
639 unsigned char vop_fcode_backward;
640 /* short header related */
641 unsigned char num_gobs_in_vop;
642 unsigned char num_macroblocks_in_gob;
643 /* for direct mode prediction */
646 } VAPictureParameterBufferMPEG4;
648 /* MPEG-4 Inverse Quantization Matrix Buffer */
649 typedef struct _VAIQMatrixBufferMPEG4
651 int load_intra_quant_mat;
652 int load_non_intra_quant_mat;
653 unsigned char intra_quant_mat[64];
654 unsigned char non_intra_quant_mat[64];
655 } VAIQMatrixBufferMPEG4;
657 /* MPEG-4 Slice Parameter Buffer */
658 typedef struct _VASliceParameterBufferMPEG4
660 unsigned int slice_data_size;/* number of bytes in the slice data buffer for this slice */
661 unsigned int slice_data_offset;/* the offset to the first byte of slice data */
662 unsigned int slice_data_flag; /* see VA_SLICE_DATA_FLAG_XXX defintions */
663 unsigned int macroblock_offset;/* the offset to the first bit of MB from the first byte of slice data */
664 unsigned int macroblock_number;
666 } VASliceParameterBufferMPEG4;
672 typedef enum /* see 7.1.1.32 */
675 VAMvMode1MvHalfPel = 1,
676 VAMvMode1MvHalfPelBilinear = 2,
678 VAMvModeIntensityCompensation = 4
681 /* VC-1 Picture Parameter Buffer */
683 * For each picture, and before any slice data, a picture parameter
684 * buffer must be send. Multiple picture parameter buffers may be
685 * sent for a single picture. In that case picture parameters will
686 * apply to all slice data that follow it until a new picture
687 * parameter buffer is sent.
690 * pic_quantizer_type should be set to the applicable quantizer
691 * type as defined by QUANTIZER (J.1.19) and either
692 * PQUANTIZER (7.1.1.8) or PQINDEX (7.1.1.6)
694 typedef struct _VAPictureParameterBufferVC1
696 VASurfaceID forward_reference_picture;
697 VASurfaceID backward_reference_picture;
698 /* if out-of-loop post-processing is done on the render
699 target, then we need to keep the in-loop decoded
700 picture as a reference picture */
701 VASurfaceID inloop_decoded_picture;
703 /* sequence layer for AP or meta data for SP and MP */
706 unsigned char interlace : 1; /* SEQUENCE_LAYER::INTERLACE */
707 unsigned char syncmarker : 1;/* METADATA::SYNCMARKER */
708 unsigned char overlap : 1;/* METADATA::OVERLAP */
710 unsigned char sequence_fields;
713 unsigned short coded_width; /* ENTRY_POINT_LAYER::CODED_WIDTH */
714 unsigned short coded_height; /* ENTRY_POINT_LAYER::CODED_HEIGHT */
715 unsigned char closed_entry; /* ENTRY_POINT_LAYER::CLOSED_ENTRY */
716 unsigned char broken_link; /* ENTRY_POINT_LAYER::BROKEN_LINK */
717 unsigned char loopfilter; /* ENTRY_POINT_LAYER::LOOPFILTER */
718 unsigned char conditional_overlap_flag; /* ENTRY_POINT_LAYER::CONDOVER */
719 unsigned char fast_uvmc_flag; /* ENTRY_POINT_LAYER::FASTUVMC */
722 unsigned char range_mapping_luma_flag: 1; /* ENTRY_POINT_LAYER::RANGE_MAPY_FLAG */
723 unsigned char range_mapping_luma: 3; /* ENTRY_POINT_LAYER::RANGE_MAPY */
724 unsigned char range_mapping_chroma_flag: 1; /* ENTRY_POINT_LAYER::RANGE_MAPUV_FLAG */
725 unsigned char range_mapping_chroma: 3; /* ENTRY_POINT_LAYER::RANGE_MAPUV */
727 unsigned char range_mapping_fields;
730 unsigned char b_picture_fraction; /* PICTURE_LAYER::BFRACTION */
731 unsigned char cbp_table; /* PICTURE_LAYER::CBPTAB/ICBPTAB */
732 unsigned char mb_mode_table; /* PICTURE_LAYER::MBMODETAB */
733 unsigned char range_reduction_frame;/* PICTURE_LAYER::RANGEREDFRM */
734 unsigned char rounding_control; /* PICTURE_LAYER::RNDCTRL */
735 unsigned char post_processing; /* PICTURE_LAYER::POSTPROC */
736 unsigned char picture_resolution_index; /* PICTURE_LAYER::RESPIC */
737 unsigned char luma_scale; /* PICTURE_LAYER::LUMSCALE */
738 unsigned char luma_shift; /* PICTURE_LAYER::LUMSHIFT */
741 unsigned char picture_type : 2; /* PICTURE_LAYER::PTYPE */
742 unsigned char frame_coding_mode : 3;/* PICTURE_LAYER::FCM */
743 unsigned char top_field_first : 1;/* PICTURE_LAYER::TFF */
744 unsigned char is_first_field : 1; /* set to 1 if it is the first field */
745 unsigned char intensity_compensation: 1;/* PICTURE_LAYER::INTCOMP */
747 unsigned char picture_fields;
751 unsigned char mv_type_mb : 1; /* PICTURE::MVTYPEMB */
752 unsigned char direct_mb : 1; /* PICTURE::DIRECTMB */
753 unsigned char skip_mb : 1; /* PICTURE::SKIPMB */
754 unsigned char field_tx : 1; /* PICTURE::FIELDTX */
755 unsigned char forward_mb : 1; /* PICTURE::FORWARDMB */
756 unsigned char ac_pred : 1; /* PICTURE::ACPRED */
757 unsigned char overflags : 1; /* PICTURE::OVERFLAGS */
759 unsigned char raw_coding_flag;
763 unsigned char bp_mv_type_mb : 1; /* PICTURE::MVTYPEMB */
764 unsigned char bp_direct_mb : 1; /* PICTURE::DIRECTMB */
765 unsigned char bp_skip_mb : 1; /* PICTURE::SKIPMB */
766 unsigned char bp_field_tx : 1; /* PICTURE::FIELDTX */
767 unsigned char bp_forward_mb : 1; /* PICTURE::FORWARDMB */
768 unsigned char bp_ac_pred : 1; /* PICTURE::ACPRED */
769 unsigned char bp_overflags : 1; /* PICTURE::OVERFLAGS */
771 unsigned char bitplane_present_flag; /* signal what bitplane is being passed via the bitplane buffer */
775 unsigned char reference_distance_flag : 1;/* PICTURE_LAYER::REFDIST_FLAG */
776 unsigned char reference_distance : 5;/* PICTURE_LAYER::REFDIST */
777 unsigned char num_reference_pictures: 1;/* PICTURE_LAYER::NUMREF */
778 unsigned char reference_field_pic_indicator : 1;/* PICTURE_LAYER::REFFIELD */
780 unsigned short reference_fields;
784 VAMvModeVC1 mv_mode : 3; /* PICTURE_LAYER::MVMODE */
785 VAMvModeVC1 mv_mode2 : 3; /* PICTURE_LAYER::MVMODE2 */
786 unsigned char mv_table : 3; /* PICTURE_LAYER::MVTAB/IMVTAB */
787 unsigned char two_mv_block_pattern_table: 2; /* PICTURE_LAYER::2MVBPTAB */
788 unsigned char four_mv_switch : 1; /* PICTURE_LAYER::4MVSWITCH */
789 unsigned char four_mv_block_pattern_table : 2; /* PICTURE_LAYER::4MVBPTAB */
790 unsigned char extended_mv_flag : 1; /* ENTRY_POINT_LAYER::EXTENDED_MV */
791 unsigned char extended_mv_range : 2; /* PICTURE_LAYER::MVRANGE */
792 unsigned char extended_dmv_flag : 1; /* ENTRY_POINT_LAYER::EXTENDED_DMV */
793 unsigned char extended_dmv_range : 2; /* PICTURE_LAYER::DMVRANGE */
795 unsigned int mv_fields;
799 unsigned char dquant : 2; /* ENTRY_POINT_LAYER::DQUANT */
800 unsigned char quantizer : 2; /* ENTRY_POINT_LAYER::QUANTIZER */
801 unsigned char half_qp : 1; /* PICTURE_LAYER::HALFQP */
802 unsigned char pic_quantizer_scale : 5;/* PICTURE_LAYER::PQUANT */
803 unsigned char pic_quantizer_type : 1;/* PICTURE_LAYER::PQUANTIZER */
804 unsigned char dq_frame : 1; /* VOPDQUANT::DQUANTFRM */
805 unsigned char dq_profile : 2; /* VOPDQUANT::DQPROFILE */
806 unsigned char dq_sb_edge : 2; /* VOPDQUANT::DQSBEDGE */
807 unsigned char dq_db_edge : 2; /* VOPDQUANT::DQDBEDGE */
808 unsigned char dq_binary_level : 1; /* VOPDQUANT::DQBILEVEL */
809 unsigned char alt_pic_quantizer : 5;/* VOPDQUANT::ALTPQUANT */
811 unsigned long pic_quantizer_fields;
815 unsigned char variable_sized_transform_flag : 1;/* ENTRY_POINT_LAYER::VSTRANSFORM */
816 unsigned char mb_level_transform_type_flag : 1;/* PICTURE_LAYER::TTMBF */
817 unsigned char frame_level_transform_type : 2;/* PICTURE_LAYER::TTFRM */
818 unsigned char transform_ac_codingset_idx1 : 2;/* PICTURE_LAYER::TRANSACFRM */
819 unsigned char transform_ac_codingset_idx2 : 2;/* PICTURE_LAYER::TRANSACFRM2 */
820 unsigned char intra_transform_dc_table : 1;/* PICTURE_LAYER::TRANSDCTAB */
822 unsigned short transform_fields;
824 } VAPictureParameterBufferVC1;
826 /* VC-1 Bitplane Buffer
827 There will be at most three bitplanes coded in any picture header. To send
828 the bitplane data more efficiently, each byte is divided in two nibbles, with
829 each nibble carrying three bitplanes for one macroblock. The following table
830 shows the bitplane data arrangement within each nibble based on the picture
833 Picture Type Bit3 Bit2 Bit1 Bit0
834 I or BI OVERFLAGS ACPRED FIELDTX
835 P MYTYPEMB SKIPMB DIRECTMB
836 B FORWARDMB SKIPMB DIRECTMB
838 Within each byte, the lower nibble is for the first MB and the upper nibble is
839 for the second MB. E.g. the lower nibble of the first byte in the bitplane
840 buffer is for Macroblock #1 and the upper nibble of the first byte is for
841 Macroblock #2 in the first row.
844 /* VC-1 Slice Parameter Buffer */
845 typedef struct _VASliceParameterBufferVC1
847 unsigned int slice_data_size;/* number of bytes in the slice data buffer for this slice */
848 unsigned int slice_data_offset;/* the offset to the first byte of slice data */
849 unsigned int slice_data_flag; /* see VA_SLICE_DATA_FLAG_XXX defintions */
850 unsigned int macroblock_offset;/* the offset to the first bit of MB from the first byte of slice data */
851 unsigned int slice_vertical_position;
852 } VASliceParameterBufferVC1;
854 /* VC-1 Slice Data Buffer */
856 This is simplely a buffer containing raw bit-stream bytes
859 /****************************
860 * H.264/AVC data structures
861 ****************************/
863 typedef struct _VAPictureH264
865 VASurfaceID picture_id;
867 unsigned int TopFieldOrderCnt;
868 unsigned int BottomFieldOrderCnt;
870 /* flags in VAPictureH264 could be OR of the following */
871 #define VA_PICTURE_H264_INVALID 0x00000001
872 #define VA_PICTURE_H264_TOP_FIELD 0x00000002
873 #define VA_PICTURE_H264_BOTTOM_FIELD 0x00000004
874 #define VA_PICTURE_H264_SHORT_TERM_REFERENCE 0x00000008
875 #define VA_PICTURE_H264_LONG_TERM_REFERENCE 0x00000010
877 /* H.264 Picture Parameter Buffer */
879 * For each picture, and before any slice data, a single
880 * picture parameter buffer must be send.
882 typedef struct _VAPictureParameterBufferH264
884 VAPictureH264 CurrPic;
885 VAPictureH264 ReferenceFrames[16]; /* in DPB */
886 unsigned short picture_width_in_mbs_minus1;
887 unsigned short picture_height_in_mbs_minus1;
888 unsigned char bit_depth_luma_minus8;
889 unsigned char bit_depth_chroma_minus8;
890 unsigned char num_ref_frames;
893 unsigned char chroma_format_idc : 2;
894 unsigned char residual_colour_transform_flag : 1;
895 unsigned char frame_mbs_only_flag : 1;
896 unsigned char mb_adaptive_frame_field_flag : 1;
897 unsigned char direct_8x8_inference_flag : 1;
898 unsigned char MinLumaBiPredSize8x8 : 1; /* see A.3.3.2 */
900 unsigned char seq_fields;
902 unsigned char num_slice_groups_minus1;
903 unsigned char slice_group_map_type;
904 signed char pic_init_qp_minus26;
905 signed char chroma_qp_index_offset;
906 signed char second_chroma_qp_index_offset;
909 unsigned char entropy_coding_mode_flag : 1;
910 unsigned char weighted_pred_flag : 1;
911 unsigned char weighted_bipred_idc : 2;
912 unsigned char transform_8x8_mode_flag : 1;
913 unsigned char field_pic_flag : 1;
914 unsigned char constrained_intra_pred_flag : 1;
916 unsigned char pic_fields;
918 unsigned short frame_num;
919 } VAPictureParameterBufferH264;
921 /* H.264 Inverse Quantization Matrix Buffer */
922 typedef struct _VAIQMatrixBufferH264
924 unsigned char ScalingList4x4[6][16];
925 unsigned char ScalingList8x8[2][64];
926 } VAIQMatrixBufferH264;
929 * H.264 Slice Group Map Buffer
930 * When VAPictureParameterBufferH264::num_slice_group_minus1 is not equal to 0,
931 * A slice group map buffer should be sent for each picture if required. The buffer
932 * is sent only when there is a change in the mapping values.
933 * The slice group map buffer map "map units" to slice groups as specified in
934 * section 8.2.2 of the H.264 spec. The buffer will contain one byte for each macroblock
935 * in raster scan order
938 /* H.264 Slice Parameter Buffer */
939 typedef struct _VASliceParameterBufferH264
941 unsigned int slice_data_size;/* number of bytes in the slice data buffer for this slice */
942 unsigned int slice_data_offset;/* the offset to the NAL start code for this slice */
943 unsigned int slice_data_flag; /* see VA_SLICE_DATA_FLAG_XXX defintions */
944 unsigned short slice_data_bit_offset; /* bit offset from NAL start code to the beginning of slice data */
945 unsigned short first_mb_in_slice;
946 unsigned char slice_type;
947 unsigned char direct_spatial_mv_pred_flag;
948 unsigned char num_ref_idx_l0_active_minus1;
949 unsigned char num_ref_idx_l1_active_minus1;
950 unsigned char cabac_init_idc;
952 unsigned char disable_deblocking_filter_idc;
953 char slice_alpha_c0_offset_div2;
954 char slice_beta_offset_div2;
955 VAPictureH264 RefPicList0[32]; /* See 8.2.4.2 */
956 VAPictureH264 RefPicList1[32]; /* See 8.2.4.2 */
957 unsigned char luma_log2_weight_denom;
958 unsigned char chroma_log2_weight_denom;
959 unsigned char luma_weight_l0_flag;
960 short luma_weight_l0[32];
961 short luma_offset_l0[32];
962 unsigned char chroma_weight_l0_flag;
963 short chroma_weight_l0[32][2];
964 short chroma_offset_l0[32][2];
965 unsigned char luma_weight_l1_flag;
966 short luma_weight_l1[32];
967 short luma_offset_l1[32];
968 unsigned char chroma_weight_l1_flag;
969 short chroma_weight_l1[32][2];
970 short chroma_offset_l1[32][2];
971 } VASliceParameterBufferH264;
973 /*****************************************
974 Encode Data Structures
975 ****************************************/
976 typedef struct _VAEncSequenceParameterBufferH264
978 unsigned char level_idc;
979 unsigned int picture_width_in_mbs;
980 unsigned int picture_height_in_mbs;
981 unsigned int bits_per_second;
982 unsigned int frame_rate;
985 unsigned int basic_unit_size;
986 unsigned char vui_flag;
987 } VAEncSequenceParameterBufferH264;
989 typedef struct _VAEncVUIParameterBufferH264
991 unsigned int time_scale;
992 unsigned char initial_cpb_removeal_delay_length_minus1;
993 unsigned char dpb_output_delay_length_minus1;
994 unsigned char time_offset_length;
995 } VAEncVUIParameterBufferH264;
997 typedef struct _VAEncSequenceParameterBufferMPEG4
999 unsigned char profile_and_level_indication;
1000 unsigned int video_object_layer_width;
1001 unsigned int video_object_layer_height;
1002 unsigned int vop_time_increment_resolution;
1003 unsigned int fixed_vop_time_increment;
1004 unsigned int bits_per_second;
1005 unsigned int frame_rate;
1008 } VAEncSequenceParameterBufferMPEG4;
1010 typedef struct _VAEncSequenceParameterBufferH263
1012 unsigned int bits_per_second;
1013 unsigned int frame_rate;
1016 } VAEncSequenceParameterBufferH263;
1018 typedef struct _VAEncPictureParameterBufferH264
1020 VASurfaceID reference_picture;
1021 VASurfaceID reconstructed_picture;
1022 VABufferID coded_buf;
1023 unsigned short picture_width;
1024 unsigned short picture_height;
1025 unsigned char last_picture;/* if set to 1 it indicates the last picture in the sequence */
1026 } VAEncPictureParameterBufferH264;
1030 VAEncPictureTypeIntra = 0,
1031 VAEncPictureTypePredictive = 1,
1032 VAEncPictureTypeBidirectional = 2,
1035 typedef struct _VAEncPictureParameterBufferMPEG4
1037 VASurfaceID reference_picture;
1038 VASurfaceID reconstructed_picture;
1039 VABufferID coded_buf;
1040 unsigned short picture_width;
1041 unsigned short picture_height;
1042 unsigned int vop_time_increment;
1043 VAEncPictureType picture_type;
1044 } VAEncPictureParameterBufferMPEG4;
1046 typedef struct _VAEncPictureParameterBufferH263
1048 VASurfaceID reference_picture;
1049 VASurfaceID reconstructed_picture;
1050 VABufferID coded_buf;
1051 unsigned short picture_width;
1052 unsigned short picture_height;
1053 VAEncPictureType picture_type;
1054 } VAEncPictureParameterBufferH263;
1056 /* Encode Slice Parameter Buffer */
1057 typedef struct _VAEncSliceParameterBuffer
1059 unsigned int start_row_number; /* starting MB row number for this slice */
1060 unsigned int slice_height; /* slice height measured in MB */
1063 unsigned char is_intra : 1;
1064 unsigned char disable_deblocking_filter_idc : 2;
1066 unsigned char flags;
1068 } VAEncSliceParameterBuffer;
1071 /* Buffer functions */
1074 * Creates a buffer for "num_elements" elements of "size" bytes and
1075 * initalize with "data".
1076 * if "data" is null, then the contents of the buffer data store
1078 * Basically there are two ways to get buffer data to the server side. One is
1079 * to call vaCreateBuffer() with a non-null "data", which results the data being
1080 * copied to the data store on the server side. A different method that
1081 * eliminates this copy is to pass null as "data" when calling vaCreateBuffer(),
1082 * and then use vaMapBuffer() to map the data store from the server side to the
1083 * client address space for access.
1084 * Note: image buffers are created by the library, not the client. Please see
1085 * vaCreateImage on how image buffers are managed.
1087 VAStatus vaCreateBuffer (
1089 VAContextID context,
1090 VABufferType type, /* in */
1091 unsigned int size, /* in */
1092 unsigned int num_elements, /* in */
1093 void *data, /* in */
1094 VABufferID *buf_id /* out */
1098 * Convey to the server how many valid elements are in the buffer.
1099 * e.g. if multiple slice parameters are being held in a single buffer,
1100 * this will communicate to the server the number of slice parameters
1101 * that are valid in the buffer.
1103 VAStatus vaBufferSetNumElements (
1105 VABufferID buf_id, /* in */
1106 unsigned int num_elements /* in */
1110 * Map data store of the buffer into the client's address space
1111 * vaCreateBuffer() needs to be called with "data" set to NULL before
1112 * calling vaMapBuffer()
1114 VAStatus vaMapBuffer (
1116 VABufferID buf_id, /* in */
1117 void **pbuf /* out */
1121 * After client making changes to a mapped data store, it needs to
1122 * "Unmap" it to let the server know that the data is ready to be
1123 * consumed by the server
1125 VAStatus vaUnmapBuffer (
1127 VABufferID buf_id /* in */
1131 * After this call, the buffer is deleted and this buffer_id is no longer valid
1132 * Only call this if the buffer is not going to be passed to vaRenderBuffer
1134 VAStatus vaDestroyBuffer (
1136 VABufferID buffer_id
1140 Render (Decode) Pictures
1142 A picture represents either a frame or a field.
1144 The Begin/Render/End sequence sends the decode buffers to the server
1148 * Get ready to decode a picture to a target surface
1150 VAStatus vaBeginPicture (
1152 VAContextID context,
1153 VASurfaceID render_target
1157 * Send decode buffers to the server.
1158 * Buffers are automatically destroyed afterwards
1160 VAStatus vaRenderPicture (
1162 VAContextID context,
1163 VABufferID *buffers,
1168 * Make the end of rendering for a picture.
1169 * The server should start processing all pending operations for this
1170 * surface. This call is non-blocking. The client can start another
1171 * Begin/Render/End sequence on a different render target.
1173 VAStatus vaEndPicture (
1185 * This function blocks until all pending operations on the render target
1186 * have been completed. Upon return it is safe to use the render target for a
1187 * different picture.
1189 VAStatus vaSyncSurface (
1191 VAContextID context,
1192 VASurfaceID render_target
1197 VASurfaceRendering = 0, /* Rendering in progress */
1198 VASurfaceDisplaying = 1, /* Displaying in progress (not safe to render into it) */
1199 /* this status is useful if surface is used as the source */
1201 VASurfaceReady = 2, /* not being rendered or displayed */
1202 VASurfaceSkipped = 3 /* to indicate a skipped frame during encode */
1206 * Find out any pending ops on the render target
1208 VAStatus vaQuerySurfaceStatus (
1210 VASurfaceID render_target,
1211 VASurfaceStatus *status /* out */
1215 * Images and Subpictures
1216 * VAImage is used to either get the surface data to client memory, or
1217 * to copy image data in client memory to a surface.
1218 * Both images, subpictures and surfaces follow the same 2D coordinate system where origin
1219 * is at the upper left corner with positive X to the right and positive Y down
1221 #define MAKEFOURCC(ch0, ch1, ch2, ch3) \
1222 ((unsigned long)(unsigned char) (ch0) | ((unsigned long)(unsigned char) (ch1) << 8) | \
1223 ((unsigned long)(unsigned char) (ch2) << 16) | ((unsigned long)(unsigned char) (ch3) << 24 ))
1225 /* a few common FourCCs */
1226 #define VA_FOURCC_NV12 0x3231564E
1227 #define VA_FOURCC_AI44 0x34344149
1228 #define VA_FOURCC_RGBA 0x41424752
1229 #define VA_FOURCC_UYVY 0x59565955
1230 #define VA_FOURCC_YUY2 0x32595559
1231 #define VA_FOURCC_AYUV 0x56555941
1232 #define VA_FOURCC_NV11 0x3131564e
1233 #define VA_FOURCC_YV12 0x32315659
1234 #define VA_FOURCC_P208 0x38303250
1237 #define VA_LSB_FIRST 1
1238 #define VA_MSB_FIRST 2
1240 typedef struct _VAImageFormat
1242 unsigned int fourcc;
1243 unsigned int byte_order; /* VA_LSB_FIRST, VA_MSB_FIRST */
1244 unsigned int bits_per_pixel;
1245 /* for RGB formats */
1246 unsigned int depth; /* significant bits per pixel */
1247 unsigned int red_mask;
1248 unsigned int green_mask;
1249 unsigned int blue_mask;
1250 unsigned int alpha_mask;
1253 typedef VAGenericID VAImageID;
1255 typedef struct _VAImage
1257 VAImageID image_id; /* uniquely identify this image */
1258 VAImageFormat format;
1259 VABufferID buf; /* image data buffer */
1261 * Image data will be stored in a buffer of type VAImageBufferType to facilitate
1262 * data store on the server side for optimal performance. The buffer will be
1263 * created by the CreateImage function, and proper storage allocated based on the image
1264 * size and format. This buffer is managed by the library implementation, and
1265 * accessed by the client through the buffer Map/Unmap functions.
1267 unsigned short width;
1268 unsigned short height;
1269 unsigned int data_size;
1270 unsigned int num_planes; /* can not be greater than 3 */
1272 * An array indicating the scanline pitch in bytes for each plane.
1273 * Each plane may have a different pitch. Maximum 3 planes for planar formats
1275 unsigned int pitches[3];
1277 * An array indicating the byte offset from the beginning of the image data
1278 * to the start of each plane.
1280 unsigned int offsets[3];
1282 /* The following fields are only needed for paletted formats */
1283 int num_palette_entries; /* set to zero for non-palette images */
1285 * Each component is one byte and entry_bytes indicates the number of components in
1286 * each entry (eg. 3 for YUV palette entries). set to zero for non-palette images
1290 * An array of ascii characters describing the order of the components within the bytes.
1291 * Only entry_bytes characters of the string are used.
1293 char component_order[4];
1296 /* Get maximum number of image formats supported by the implementation */
1297 int vaMaxNumImageFormats (
1302 * Query supported image formats
1303 * The caller must provide a "format_list" array that can hold at
1304 * least vaMaxNumImageFormats() entries. The actual number of formats
1305 * returned in "format_list" is returned in "num_formats".
1307 VAStatus vaQueryImageFormats (
1309 VAImageFormat *format_list, /* out */
1310 int *num_formats /* out */
1314 * Create a VAImage structure
1315 * The width and height fields returned in the VAImage structure may get
1316 * enlarged for some YUV formats. Upon return from this function,
1317 * image->buf has been created and proper storage allocated by the library.
1318 * The client can access the image through the Map/Unmap calls.
1320 VAStatus vaCreateImage (
1322 VAImageFormat *format,
1325 VAImage *image /* out */
1329 * Should call DestroyImage before destroying the surface it is bound to
1331 VAStatus vaDestroyImage (
1336 VAStatus vaSetImagePalette (
1340 * pointer to an array holding the palette data. The size of the array is
1341 * num_palette_entries * entry_bytes in size. The order of the components
1342 * in the palette is described by the component_order in VAImage struct
1344 unsigned char *palette
1348 * Retrive surface data into a VAImage
1349 * Image must be in a format supported by the implementation
1351 VAStatus vaGetImage (
1353 VASurfaceID surface,
1354 int x, /* coordinates of the upper left source pixel */
1356 unsigned int width, /* width and height of the region */
1357 unsigned int height,
1362 * Copy data from a VAImage to a surface
1363 * Image must be in a format supported by the implementation
1364 * Returns a VA_STATUS_ERROR_SURFACE_BUSY if the surface
1365 * shouldn't be rendered into when this is called
1366 * The source and destionation width and height are the same and
1367 * no scaling is performed with this operation.
1369 VAStatus vaPutImage (
1371 VASurfaceID surface,
1376 unsigned int height,
1382 * Similar to vaPutImage but with additional destination width
1383 * and height arguments to enable scaling
1385 VAStatus vaPutImage2 (
1387 VASurfaceID surface,
1391 unsigned int src_width,
1392 unsigned int src_height,
1395 unsigned int dest_width,
1396 unsigned int dest_height
1400 * Derive an VAImage from an existing surface.
1401 * This interface will derive a VAImage and corresponding image buffer from
1402 * an existing VA Surface. The image buffer can then be mapped/unmapped for
1403 * direct CPU access. This operation is only possible on implementations with
1404 * direct rendering capabilities and internal surface formats that can be
1405 * represented with a VAImage. When the operation is not possible this interface
1406 * will return VA_STATUS_ERROR_OPERATION_FAILED. Clients should then fall back
1407 * to using vaCreateImage + vaPutImage to accomplish the same task in an
1410 * Implementations should only return success when the resulting image buffer
1411 * would be useable with vaMap/Unmap.
1413 * When directly accessing a surface special care must be taken to insure
1414 * proper synchronization with the graphics hardware. Clients should call
1415 * vaQuerySurfaceStatus to insure that a surface is not the target of concurrent
1416 * rendering or currently being displayed by an overlay.
1418 * Additionally nothing about the contents of a surface should be assumed
1419 * following a vaPutSurface. Implementations are free to modify the surface for
1420 * scaling or subpicture blending within a call to vaPutImage.
1422 * Calls to vaPutImage or vaGetImage using the same surface from which the image
1423 * has been derived will return VA_STATUS_ERROR_SURFACE_BUSY. vaPutImage or
1424 * vaGetImage with other surfaces is supported.
1426 * An image created with vaDeriveImage should be freed with vaDestroyImage. The
1427 * image and image buffer structures will be destroyed; however, the underlying
1428 * surface will remain unchanged until freed with vaDestroySurfaces.
1430 VAStatus vaDeriveImage (
1432 VASurfaceID surface,
1433 VAImage *image /* out */
1440 * Subpicture is a special type of image that can be blended
1441 * with a surface during vaPutSurface(). Subpicture can be used to render
1442 * DVD sub-titles or closed captioning text etc.
1445 typedef VAGenericID VASubpictureID;
1447 /* Get maximum number of subpicture formats supported by the implementation */
1448 int vaMaxNumSubpictureFormats (
1452 /* flags for subpictures */
1453 #define VA_SUBPICTURE_CHROMA_KEYING 0x0001
1454 #define VA_SUBPICTURE_GLOBAL_ALPHA 0x0002
1456 * Query supported subpicture formats
1457 * The caller must provide a "format_list" array that can hold at
1458 * least vaMaxNumSubpictureFormats() entries. The flags arrary holds the flag
1459 * for each format to indicate additional capabilities for that format. The actual
1460 * number of formats returned in "format_list" is returned in "num_formats".
1461 * flags: returned value to indicate addtional capabilities
1462 * VA_SUBPICTURE_CHROMA_KEYING - supports chroma-keying
1463 * VA_SUBPICTURE_GLOBAL_ALPHA - supports global alpha
1465 VAStatus vaQuerySubpictureFormats (
1467 VAImageFormat *format_list, /* out */
1468 unsigned int *flags, /* out */
1469 unsigned int *num_formats /* out */
1473 * Subpictures are created with an image associated.
1475 VAStatus vaCreateSubpicture (
1478 VASubpictureID *subpicture /* out */
1482 * Destroy the subpicture before destroying the image it is assocated to
1484 VAStatus vaDestroySubpicture (
1486 VASubpictureID subpicture
1490 * Bind an image to the subpicture. This image will now be associated with
1491 * the subpicture instead of the one at creation.
1493 VAStatus vaSetSubpictureImage (
1495 VASubpictureID subpicture,
1500 * If chromakey is enabled, then the area where the source value falls within
1501 * the chromakey [min, max] range is transparent
1502 * The chromakey component format is the following:
1503 * For RGB: [0:7] Red [8:15] Blue [16:23] Green
1504 * For YUV: [0:7] V [8:15] U [16:23] Y
1505 * The chromakey mask can be used to mask out certain components for chromakey
1508 VAStatus vaSetSubpictureChromakey (
1510 VASubpictureID subpicture,
1511 unsigned int chromakey_min,
1512 unsigned int chromakey_max,
1513 unsigned int chromakey_mask
1517 * Global alpha value is between 0 and 1. A value of 1 means fully opaque and
1518 * a value of 0 means fully transparent. If per-pixel alpha is also specified then
1519 * the overall alpha is per-pixel alpha multiplied by the global alpha
1521 VAStatus vaSetSubpictureGlobalAlpha (
1523 VASubpictureID subpicture,
1528 * vaAssociateSubpicture associates the subpicture with target_surfaces.
1529 * It defines the region mapping between the subpicture and the target
1530 * surfaces through source and destination rectangles (with the same width and height).
1531 * Both will be displayed at the next call to vaPutSurface. Additional
1532 * associations before the call to vaPutSurface simply overrides the association.
1534 VAStatus vaAssociateSubpicture (
1536 VASubpictureID subpicture,
1537 VASurfaceID *target_surfaces,
1539 short src_x, /* upper left offset in subpicture */
1541 short dest_x, /* upper left offset in surface */
1543 unsigned short width,
1544 unsigned short height,
1546 * whether to enable chroma-keying or global-alpha
1547 * see VA_SUBPICTURE_XXX values
1553 * Similar to vaAssociateSubpicture but with additional destination width
1554 * and height to enable scaling
1556 VAStatus vaAssociateSubpicture2 (
1558 VASubpictureID subpicture,
1559 VASurfaceID *target_surfaces,
1561 short src_x, /* upper left offset in subpicture */
1563 unsigned short src_width,
1564 unsigned short src_height,
1565 short dest_x, /* upper left offset in surface */
1567 unsigned short dest_width,
1568 unsigned short dest_height,
1570 * whether to enable chroma-keying or global-alpha
1571 * see VA_SUBPICTURE_XXX values
1577 * vaDeassociateSubpicture removes the association of the subpicture with target_surfaces.
1579 VAStatus vaDeassociateSubpicture (
1581 VASubpictureID subpicture,
1582 VASurfaceID *target_surfaces,
1586 typedef struct _VARectangle
1590 unsigned short width;
1591 unsigned short height;
1595 * Display attributes
1596 * Display attributes are used to control things such as contrast, hue, saturation,
1597 * brightness etc. in the rendering process. The application can query what
1598 * attributes are supported by the driver, and then set the appropriate attributes
1599 * before calling vaPutSurface()
1602 /* Currently defined display attribute types */
1605 VADisplayAttribBrightness = 0,
1606 VADisplayAttribContrast = 1,
1607 VADisplayAttribHue = 2,
1608 VADisplayAttribSaturation = 3,
1609 /* client can specifiy a background color for the target window */
1610 VADisplayAttribBackgroundColor = 4,
1612 * this is a gettable only attribute. For some implementations that use the
1613 * hardware overlay, after PutSurface is called, the surface can not be
1614 * re-used until after the subsequent PutSurface call. If this is the case
1615 * then the value for this attribute will be set to 1 so that the client
1616 * will not attempt to re-use the surface right after returning from a call
1619 VADisplayAttribDirectSurface = 5,
1620 } VADisplayAttribType;
1622 /* flags for VADisplayAttribute */
1623 #define VA_DISPLAY_ATTRIB_NOT_SUPPORTED 0x0000
1624 #define VA_DISPLAY_ATTRIB_GETTABLE 0x0001
1625 #define VA_DISPLAY_ATTRIB_SETTABLE 0x0002
1627 typedef struct _VADisplayAttribute
1629 VADisplayAttribType type;
1632 int value; /* used by the set/get attribute functions */
1633 /* flags can be VA_DISPLAY_ATTRIB_GETTABLE or VA_DISPLAY_ATTRIB_SETTABLE or OR'd together */
1635 } VADisplayAttribute;
1637 /* Get maximum number of display attributs supported by the implementation */
1638 int vaMaxNumDisplayAttributes (
1643 * Query display attributes
1644 * The caller must provide a "attr_list" array that can hold at
1645 * least vaMaxNumDisplayAttributes() entries. The actual number of attributes
1646 * returned in "attr_list" is returned in "num_attributes".
1648 VAStatus vaQueryDisplayAttributes (
1650 VADisplayAttribute *attr_list, /* out */
1651 int *num_attributes /* out */
1655 * Get display attributes
1656 * This function returns the current attribute values in "attr_list".
1657 * Only attributes returned with VA_DISPLAY_ATTRIB_GETTABLE set in the "flags" field
1658 * from vaQueryDisplayAttributes() can have their values retrieved.
1660 VAStatus vaGetDisplayAttributes (
1662 VADisplayAttribute *attr_list, /* in/out */
1667 * Set display attributes
1668 * Only attributes returned with VA_DISPLAY_ATTRIB_SETTABLE set in the "flags" field
1669 * from vaQueryDisplayAttributes() can be set. If the attribute is not settable or
1670 * the value is out of range, the function returns VA_STATUS_ERROR_ATTR_NOT_SUPPORTED
1672 VAStatus vaSetDisplayAttributes (
1674 VADisplayAttribute *attr_list,
1685 /*****************************************************************************/
1687 Sample Program (w/ pseudo code)
1689 Mostly to demonstrate program flow with no error handling ...
1691 /*****************************************************************************/
1693 /* MPEG-2 VLD decode for a 720x480 frame */
1695 int major_ver, minor_ver;
1696 vaInitialize(dpy, &major_ver, &minor_ver);
1698 int max_num_profiles, max_num_entrypoints, max_num_attribs;
1699 max_num_profiles = vaMaxNumProfiles(dpy);
1700 max_num_entrypoints = vaMaxNumEntrypoints(dpy);
1701 max_num_attribs = vaMaxNumConfigAttributes(dpy);
1703 /* find out whether MPEG2 MP is supported */
1704 VAProfile *profiles = malloc(sizeof(VAProfile)*max_num_profiles);
1706 vaQueryConfigProfiles(dpy, profiles, &profiles);
1708 * traverse "profiles" to locate the one that matches VAProfileMPEG2Main
1711 /* now get the available entrypoints for MPEG2 MP */
1712 VAEntrypoint *entrypoints = malloc(sizeof(VAEntrypoint)*max_num_entrypoints);
1713 int num_entrypoints;
1714 vaQueryConfigEntrypoints(dpy, VAProfileMPEG2Main, entrypoints, &num_entrypoints);
1716 /* traverse "entrypoints" to see whether VLD is there */
1718 /* Assuming finding VLD, find out the format for the render target */
1719 VAConfigAttrib attrib;
1720 attrib.type = VAConfigAttribRTFormat;
1721 vaGetConfigAttributes(dpy, VAProfileMPEG2Main, VAEntrypointVLD,
1724 if (attrib.value & VA_RT_FORMAT_YUV420)
1725 /* Found desired RT format, keep going */
1727 VAConfigID config_id;
1728 vaCreateConfig(dpy, VAProfileMPEG2Main, VAEntrypointVLD, &attrib, 1,
1732 * create surfaces for the current target as well as reference frames
1733 * we can get by with 4 surfaces for MPEG-2
1735 VASurfaceID surfaces[4];
1736 vaCreateSurfaces(dpy, 720, 480, VA_RT_FORMAT_YUV420, 4, surfaces);
1739 * Create a context for this decode pipe
1741 VAContextID context;
1742 vaCreateContext(dpy, config_id, 720, 480, VA_PROGRESSIVE, surfaces,
1745 /* Create a picture parameter buffer for this frame */
1746 VABufferID picture_buf;
1747 VAPictureParameterBufferMPEG2 *picture_param;
1748 vaCreateBuffer(dpy, context, VAPictureParameterBufferType, sizeof(VAPictureParameterBufferMPEG2), 1, NULL, &picture_buf);
1749 vaMapBuffer(dpy, picture_buf, &picture_param);
1750 picture_param->horizontal_size = 720;
1751 picture_param->vertical_size = 480;
1752 picture_param->picture_coding_type = 1; /* I-frame */
1753 /* fill in picture_coding_extension fields here */
1754 vaUnmapBuffer(dpy, picture_buf);
1756 /* Create an IQ matrix buffer for this frame */
1758 VAIQMatrixBufferMPEG2 *iq_matrix;
1759 vaCreateBuffer(dpy, context, VAIQMatrixBufferType, sizeof(VAIQMatrixBufferMPEG2), 1, NULL, &iq_buf);
1760 vaMapBuffer(dpy, iq_buf, &iq_matrix);
1761 /* fill values for IQ_matrix here */
1762 vaUnmapBuffer(dpy, iq_buf);
1764 /* send the picture and IQ matrix buffers to the server */
1765 vaBeginPicture(dpy, context, surfaces[0]);
1767 vaRenderPicture(dpy, context, &picture_buf, 1);
1768 vaRenderPicture(dpy, context, &iq_buf, 1);
1771 * Send slices in this frame to the server.
1772 * For MPEG-2, each slice is one row of macroblocks, and
1773 * we have 30 slices for a 720x480 frame
1775 for (int i = 1; i <= 30; i++) {
1777 /* Create a slice parameter buffer */
1778 VABufferID slice_param_buf;
1779 VASliceParameterBufferMPEG2 *slice_param;
1780 vaCreateBuffer(dpy, context, VASliceParameterBufferType, sizeof(VASliceParameterBufferMPEG2), 1, NULL, &slice_param_buf);
1781 vaMapBuffer(dpy, slice_param_buf, &slice_param);
1782 slice_param->slice_data_offset = 0;
1783 /* Let's say all slices in this bit-stream has 64-bit header */
1784 slice_param->macroblock_offset = 64;
1785 slice_param->vertical_position = i;
1786 /* set up the rest based on what is in the slice header ... */
1787 vaUnmapBuffer(dpy, slice_param_buf);
1789 /* send the slice parameter buffer */
1790 vaRenderPicture(dpy, context, &slice_param_buf, 1);
1792 /* Create a slice data buffer */
1793 unsigned char *slice_data;
1794 VABufferID slice_data_buf;
1795 vaCreateBuffer(dpy, context, VASliceDataBufferType, x /* decoder figure out how big */, 1, NULL, &slice_data_buf);
1796 vaMapBuffer(dpy, slice_data_buf, &slice_data);
1797 /* decoder fill in slice_data */
1798 vaUnmapBuffer(dpy, slice_data_buf);
1800 /* send the slice data buffer */
1801 vaRenderPicture(dpy, context, &slice_data_buf, 1);
1804 /* all slices have been sent, mark the end for this frame */
1805 vaEndPicture(dpy, context);
1807 /* The following code demonstrates rendering a sub-title with the target surface */
1808 /* Find out supported Subpicture formats */
1809 VAImageFormat sub_formats[4];
1811 vaQuerySubpictureFormats(dpy, sub_formats, &num_formats);
1812 /* Assume that we find AI44 as a subpicture format in sub_formats[0] */
1814 VASubpictureID subpicture;
1815 unsigned char *sub_data;
1816 /* create an image for the subtitle */
1817 vaCreateImage(dpy, sub_formats, 128, 16, &sub_image);
1818 vaMapBuffer(dpy, sub_image->buf, &sub_data);
1819 /* fill the image data */
1820 vaUnmapBuffer(dpy, sub_image->buf);
1821 vaCreateSubpicture(dpy, sub_image, &subpicture);
1822 unsigned char palette[3][16];
1823 /* fill the palette data */
1824 vaSetSubpicturePalette(dpy, subpicture, palette);
1825 vaAssociateSubpicture(dpy, subpicture, surfaces, 1, 0, 0, 296, 400, 128, 16);
1826 vaPutSurface(dpy, surfaces, win, 0, 0, 720, 480, 100, 100, 640, 480, NULL, 0, 0);
1828 /*****************************************************************************/
1830 Sample Encode Program (w/ pseudo code)
1832 Mostly to demonstrate program flow with no error handling ...
1834 /*****************************************************************************/
1836 /* H.264 VLC encode for a 640x480 frame */
1837 int major_ver, minor_ver;
1838 vaInitialize(dpy, &major_ver, &minor_ver);
1840 int max_num_profiles, max_num_entrypoints, max_num_attribs;
1841 max_num_profiles = vaMaxNumProfiles(dpy);
1842 max_num_entrypoints = vaMaxNumEntrypoints(dpy);
1843 max_num_attribs = vaMaxNumConfigAttributes(dpy);
1845 /* find out whether H.264 BP encode is supported */
1846 VAProfile *profiles = malloc(sizeof(VAProfile)*max_num_profiles);
1848 vaQueryConfigProfiles(dpy, profiles, &num_profiles);
1850 * traverse "profiles" to locate the one that matches VAProfileH264BP
1853 /* now get the available entrypoints for H.264 BP */
1854 VAEntrypoint *entrypoints = malloc(sizeof(VAEntrypoint)*max_num_entrypoints);
1855 int num_entrypoints;
1856 vaQueryConfigEntrypoints(dpy, VAProfileH264Baseline, entrypoints, &num_entrypoints);
1858 /* traverse "entrypoints" to see whether VAEntrypointEncodeES is there */
1860 /* Assuming finding VAEntrypointEncodeES, find out the format and rate control mode for the source */
1861 VAConfigAttrib attrib[2];
1862 attrib[0].type = VAConfigAttribRTFormat;
1863 attrib[1].type = VAConfigAttribRateControl;
1864 vaGetConfigAttributes(dpy, VAProfileH264Baseline, VAEntrypointVLC,
1867 if (attrib[0].value & VA_RT_FORMAT_YUV420)
1868 /* Found desired format, keep going */
1870 if (attrib[1].value & VA_RC_CBR)
1871 /* Found desired rate control mode, keep going */
1873 VAConfigID config_id;
1874 vaCreateConfig(dpy, VAProfileH264Baseline, VAEntrypointEncodeES, &attrib[0], 2,
1878 * create surfaces for the current target as well as reference frames
1879 * we can get by with 3 surfaces for H.264 BP
1881 VASurfaceID surfaces[3];
1882 vaCreateSurfaces(dpy, 640, 480, VA_RT_FORMAT_YUV420, 3, surfaces);
1884 /* Create a context for this encode pipe */
1885 VAContextID context;
1886 vaCreateContext(dpy, config_id, 640, 480, VA_PROGRESSIVE, surfaces,
1890 * Create a coded buffer
1892 VABufferID coded_buf;
1893 int coded_buf_size = 640*480*400/(16*16);
1894 vaCreateBuffer(dpy, context, VAEncCodedBufferType, coded_buf_size, 1, NULL, &coded_buf);
1898 * Create header buffer for sequence header, picture header, and slice header
1900 VABufferID sequence_param_buf, picture_param_buf, slice_param_buf;
1901 vaCreateBuffer(dpy, context, VAEncSequenceParameterBufferType, sizof(VAEncSequenceParameterBufferH264), 1, NULL, &sequence_param_buf);
1902 vaCreateBuffer(dpy, context, VAEncPictureParameterBufferType, sizof(VAEncPictureParameterBufferH264), 1, NULL, &picture_param_buf);
1903 vaCreateBuffer(dpy, context, VAEncSliceParameterBufferType, sizof(VAEncSliceParameterBuffer), 1, NULL, &slice_param_buf);
1905 /* Create sequence parameter */
1906 VAEncSequenceParameterBufferH264 sequence_param;
1907 vaMapBuffer(dpy, sequence_param_buf, &sequence_param);
1908 sequence_param.picture_width_in_mbs = 40;
1909 sequence_param.picture_width_in_mbs = 30;
1910 sequence_param.bits_per_second = 3000000;
1911 sequence_param.basic_unit_size = 5;
1912 sequence_param.frame_rate = 30;
1913 sequence_param.initial_qp = 25;
1914 sequence_param.min_qp = 0;
1915 vaUnmapBuffer(dpy,sequence_param_buf);
1918 * Derive 3 image from the surface to upload RAW source YUV data
1920 int src_srf=0,rec_srf=1,ref_srf=2;
1921 VAImage *source_image[3];
1923 for (int i=0; i<3;i++)
1924 vaDeriveImage(dpy,surface[i], source_image[i]);
1926 /* encoding 30 frames */
1927 for (int i = 0; i <= 30; i++) {
1929 * Progess the buffers
1930 * src_srf rec_srf ref_srf
1931 * <--------------------------
1939 vaMapBuffer(dpy, source_image[src_srf].buf, source_buf);
1940 /* put RAW YUV data into source_buf here */
1941 vaUnmapBuffer(dpy, source_image[src_srf].buf);
1943 vaBeginPicture(dpy, context, surfaces[src_srf]);
1946 /* Fill sequence header into sequence_header_buf here */
1947 vaRenderPicture(dpy,context, &sequence_param, 1);
1950 vaMapBuffer(dpy, picture_param_buf, &picture_param);
1951 if (i==0) /* first frame refer itself */
1952 picture->reference_picture = surfaces[src_srf];
1954 picture_param->reference_picture = surfaces[ref_srf];
1955 picture_param->reconstructed_picture = surfaces[rec_srf];
1956 picture_param->coded_buf = coded_buf;
1957 picture_param->picture_width= 640;
1958 picture_param->picture_height = 480;
1959 if ((i % 10) == 0) { /* one I frame within 10 frames */
1960 picture_param->picture_type = VAEncPictureTypeIntra;
1962 picture_param->picture_type = VAEncPictureTypePredictive;
1964 vaUnmapBuffer(dpy,picture_param_buf);
1966 vaRenderPicture(dpy, context, &picture_param_buf, 1);
1969 vaMapBuffer(dpy, slice_param_buf, &slice_param);
1970 slice_param->start_row_number = 0;
1971 slice_param->slice_height = 480;
1972 slice_param->is_intra = 1;
1973 vaUnmapBuffer(dpy,slice_buf);
1975 vaRenderPicture(dpy,context,&slice_param_buf, 1);
1976 vaEndPicture(dpy, context);
1979 vaMapBuffer(dpy, coded_buf, &coded_data)
1980 /* output coded buf from coded_data here */
1981 vaUnmapBuffer(dpy, coded_buf);