VA-API

va.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2007-2009 Intel Corporation. All Rights Reserved.
00003  *
00004  * Permission is hereby granted, free of charge, to any person obtaining a
00005  * copy of this software and associated documentation files (the
00006  * "Software"), to deal in the Software without restriction, including
00007  * without limitation the rights to use, copy, modify, merge, publish,
00008  * distribute, sub license, and/or sell copies of the Software, and to
00009  * permit persons to whom the Software is furnished to do so, subject to
00010  * the following conditions:
00011  * 
00012  * The above copyright notice and this permission notice (including the
00013  * next paragraph) shall be included in all copies or substantial portions
00014  * of the Software.
00015  * 
00016  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00017  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00018  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
00019  * IN NO EVENT SHALL INTEL AND/OR ITS SUPPLIERS BE LIABLE FOR
00020  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
00021  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
00022  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00023  */
00024 /*
00025  * Video Acceleration (VA) API Specification
00026  *
00027  * Rev. 0.30
00028  * <jonathan.bian@intel.com>
00029  *
00030  * Revision History:
00031  * rev 0.10 (12/10/2006 Jonathan Bian) - Initial draft
00032  * rev 0.11 (12/15/2006 Jonathan Bian) - Fixed some errors
00033  * rev 0.12 (02/05/2007 Jonathan Bian) - Added VC-1 data structures for slice level decode
00034  * rev 0.13 (02/28/2007 Jonathan Bian) - Added GetDisplay()
00035  * rev 0.14 (04/13/2007 Jonathan Bian) - Fixed MPEG-2 PictureParameter structure, cleaned up a few funcs.
00036  * rev 0.15 (04/20/2007 Jonathan Bian) - Overhauled buffer management
00037  * rev 0.16 (05/02/2007 Jonathan Bian) - Added error codes and fixed some issues with configuration
00038  * rev 0.17 (05/07/2007 Jonathan Bian) - Added H.264/AVC data structures for slice level decode.
00039  * rev 0.18 (05/14/2007 Jonathan Bian) - Added data structures for MPEG-4 slice level decode 
00040  *                                       and MPEG-2 motion compensation.
00041  * rev 0.19 (08/06/2007 Jonathan Bian) - Removed extra type for bitplane data.
00042  * rev 0.20 (08/08/2007 Jonathan Bian) - Added missing fields to VC-1 PictureParameter structure.
00043  * rev 0.21 (08/20/2007 Jonathan Bian) - Added image and subpicture support.
00044  * rev 0.22 (08/27/2007 Jonathan Bian) - Added support for chroma-keying and global alpha.
00045  * rev 0.23 (09/11/2007 Jonathan Bian) - Fixed some issues with images and subpictures.
00046  * rev 0.24 (09/18/2007 Jonathan Bian) - Added display attributes.
00047  * rev 0.25 (10/18/2007 Jonathan Bian) - Changed to use IDs only for some types.
00048  * rev 0.26 (11/07/2007 Waldo Bastian) - Change vaCreateBuffer semantics
00049  * rev 0.27 (11/19/2007 Matt Sottek)   - Added DeriveImage
00050  * rev 0.28 (12/06/2007 Jonathan Bian) - Added new versions of PutImage and AssociateSubpicture 
00051  *                                       to enable scaling
00052  * rev 0.29 (02/07/2008 Jonathan Bian) - VC1 parameter fixes,
00053  *                                       added VA_STATUS_ERROR_RESOLUTION_NOT_SUPPORTED
00054  * rev 0.30 (03/01/2009 Jonathan Bian) - Added encoding support for H.264 BP and MPEG-4 SP and fixes
00055  *                                       for ISO C conformance.
00056  * rev 0.31 (09/02/2009 Gwenole Beauchesne) - VC-1/H264 fields change for VDPAU and XvBA backend
00057  *                                       Application needs to relink with the new library.
00058  *
00059  * rev 0.31.1 (03/29/2009)              - Data structure for JPEG encode
00060  * rev 0.31.2 (01/13/2011 Anthony Pabon)- Added a flag to indicate Subpicture coordinates are screen
00061  *                                        screen relative rather than source video relative.
00062  * rev 0.32.0 (01/13/2011 Xiang Haihao) - Add profile into VAPictureParameterBufferVC1
00063  *                                        update VAAPI to 0.32.0
00064  *
00065  * Acknowledgements:
00066  *  Some concepts borrowed from XvMC and XvImage.
00067  *  Waldo Bastian (Intel), Matt Sottek (Intel),  Austin Yuan (Intel), and Gwenole Beauchesne (SDS)
00068  *  contributed to various aspects of the API.
00069  */
00070 
00078 #ifndef _VA_H_
00079 #define _VA_H_
00080 
00081 #include <va/va_version.h>
00082 
00083 #ifdef __cplusplus
00084 extern "C" {
00085 #endif
00086 
00109 /* 
00110 Overview 
00111 
00112 The VA API is intended to provide an interface between a video decode/encode/display
00113 application (client) and a hardware accelerator (server), to off-load 
00114 video decode/encode/display operations from the host to the hardware accelerator at various 
00115 entry-points.
00116 
00117 The basic operation steps are:
00118 
00119 - Negotiate a mutually acceptable configuration with the server to lock
00120   down profile, entrypoints, and other attributes that will not change on 
00121   a frame-by-frame basis.
00122 - Create a decode context which represents a "virtualized" hardware decode 
00123   device
00124 - Get and fill decode buffers with picture level, slice level and macroblock 
00125   level data (depending on entrypoints)
00126 - Pass the decode buffers to the server to decode the current frame
00127 
00128 Initialization & Configuration Management 
00129 
00130 - Find out supported profiles
00131 - Find out entrypoints for a given profile
00132 - Find out configuration attributes for a given profile/entrypoint pair
00133 - Create a configuration for use by the decoder
00134 
00135 */
00136 
00137 typedef void* VADisplay;        /* window system dependent */
00138 
00139 typedef int VAStatus;   /* Return status type from functions */
00140 /* Values for the return status */
00141 #define VA_STATUS_SUCCESS                       0x00000000
00142 #define VA_STATUS_ERROR_OPERATION_FAILED        0x00000001
00143 #define VA_STATUS_ERROR_ALLOCATION_FAILED       0x00000002
00144 #define VA_STATUS_ERROR_INVALID_DISPLAY         0x00000003
00145 #define VA_STATUS_ERROR_INVALID_CONFIG          0x00000004
00146 #define VA_STATUS_ERROR_INVALID_CONTEXT         0x00000005
00147 #define VA_STATUS_ERROR_INVALID_SURFACE         0x00000006
00148 #define VA_STATUS_ERROR_INVALID_BUFFER          0x00000007
00149 #define VA_STATUS_ERROR_INVALID_IMAGE           0x00000008
00150 #define VA_STATUS_ERROR_INVALID_SUBPICTURE      0x00000009
00151 #define VA_STATUS_ERROR_ATTR_NOT_SUPPORTED      0x0000000a
00152 #define VA_STATUS_ERROR_MAX_NUM_EXCEEDED        0x0000000b
00153 #define VA_STATUS_ERROR_UNSUPPORTED_PROFILE     0x0000000c
00154 #define VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT  0x0000000d
00155 #define VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT   0x0000000e
00156 #define VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE  0x0000000f
00157 #define VA_STATUS_ERROR_SURFACE_BUSY            0x00000010
00158 #define VA_STATUS_ERROR_FLAG_NOT_SUPPORTED      0x00000011
00159 #define VA_STATUS_ERROR_INVALID_PARAMETER       0x00000012
00160 #define VA_STATUS_ERROR_RESOLUTION_NOT_SUPPORTED 0x00000013
00161 #define VA_STATUS_ERROR_UNIMPLEMENTED           0x00000014
00162 #define VA_STATUS_ERROR_SURFACE_IN_DISPLAYING   0x00000015
00163 #define VA_STATUS_ERROR_INVALID_IMAGE_FORMAT    0x00000016
00164 #define VA_STATUS_ERROR_DECODING_ERROR          0x00000017
00165 #define VA_STATUS_ERROR_ENCODING_ERROR          0x00000018
00166 
00173 #define VA_STATUS_ERROR_INVALID_VALUE           0x00000019
00174 
00175 #define VA_STATUS_ERROR_UNSUPPORTED_FILTER      0x00000020
00176 
00177 #define VA_STATUS_ERROR_INVALID_FILTER_CHAIN    0x00000021
00178 #define VA_STATUS_ERROR_UNKNOWN                 0xFFFFFFFF
00179 
00180 /* De-interlacing flags for vaPutSurface() */
00181 #define VA_FRAME_PICTURE        0x00000000 
00182 #define VA_TOP_FIELD            0x00000001
00183 #define VA_BOTTOM_FIELD         0x00000002
00184 
00185 /*
00186  * Enabled the positioning/cropping/blending feature:
00187  * 1, specify the video playback position in the isurface
00188  * 2, specify the cropping info for video playback
00189  * 3, encoded video will blend with background color
00190  */
00191 #define VA_ENABLE_BLEND         0x00000004 /* video area blend with the constant color */ 
00192     
00193 /*
00194  * Clears the drawable with background color.
00195  * for hardware overlay based implementation this flag
00196  * can be used to turn off the overlay
00197  */
00198 #define VA_CLEAR_DRAWABLE       0x00000008
00199 
00200 /* Color space conversion flags for vaPutSurface() */
00201 #define VA_SRC_BT601            0x00000010
00202 #define VA_SRC_BT709            0x00000020
00203 #define VA_SRC_SMPTE_240        0x00000040
00204 
00205 /* Scaling flags for vaPutSurface() */
00206 #define VA_FILTER_SCALING_DEFAULT       0x00000000
00207 #define VA_FILTER_SCALING_FAST          0x00000100
00208 #define VA_FILTER_SCALING_HQ            0x00000200
00209 #define VA_FILTER_SCALING_NL_ANAMORPHIC 0x00000300
00210 #define VA_FILTER_SCALING_MASK          0x00000f00
00211 
00212 /*
00213  * Returns a short english description of error_status
00214  */
00215 const char *vaErrorStr(VAStatus error_status);
00216 
00217 /*
00218  * Initialization:
00219  * A display must be obtained by calling vaGetDisplay() before calling
00220  * vaInitialize() and other functions. This connects the API to the 
00221  * native window system.
00222  * For X Windows, native_dpy would be from XOpenDisplay()
00223  */
00224 typedef void* NativeDisplay;    /* window system dependent */
00225 
00226 int vaDisplayIsValid(VADisplay dpy);
00227     
00228 /*
00229  * Initialize the library 
00230  */
00231 VAStatus vaInitialize (
00232     VADisplay dpy,
00233     int *major_version,  /* out */
00234     int *minor_version   /* out */
00235 );
00236 
00237 /*
00238  * After this call, all library internal resources will be cleaned up
00239  */ 
00240 VAStatus vaTerminate (
00241     VADisplay dpy
00242 );
00243 
00244 /*
00245  * vaQueryVendorString returns a pointer to a zero-terminated string
00246  * describing some aspects of the VA implemenation on a specific    
00247  * hardware accelerator. The format of the returned string is vendor
00248  * specific and at the discretion of the implementer.
00249  * e.g. for the Intel GMA500 implementation, an example would be:
00250  * "Intel GMA500 - 2.0.0.32L.0005"
00251  */
00252 const char *vaQueryVendorString (
00253     VADisplay dpy
00254 );
00255 
00256 typedef int (*VAPrivFunc)();
00257 
00258 /*
00259  * Return a function pointer given a function name in the library.
00260  * This allows private interfaces into the library
00261  */ 
00262 VAPrivFunc vaGetLibFunc (
00263     VADisplay dpy,
00264     const char *func
00265 );
00266 
00267 /* Currently defined profiles */
00268 typedef enum
00269 {
00271     VAProfileNone                       = -1,
00272     VAProfileMPEG2Simple                = 0,
00273     VAProfileMPEG2Main                  = 1,
00274     VAProfileMPEG4Simple                = 2,
00275     VAProfileMPEG4AdvancedSimple        = 3,
00276     VAProfileMPEG4Main                  = 4,
00277     VAProfileH264Baseline               = 5,
00278     VAProfileH264Main                   = 6,
00279     VAProfileH264High                   = 7,
00280     VAProfileVC1Simple                  = 8,
00281     VAProfileVC1Main                    = 9,
00282     VAProfileVC1Advanced                = 10,
00283     VAProfileH263Baseline               = 11,
00284     VAProfileJPEGBaseline               = 12,
00285     VAProfileH264ConstrainedBaseline = 13
00286 } VAProfile;
00287 
00288 /* 
00289  *  Currently defined entrypoints 
00290  */
00291 typedef enum
00292 {
00293     VAEntrypointVLD             = 1,
00294     VAEntrypointIZZ             = 2,
00295     VAEntrypointIDCT            = 3,
00296     VAEntrypointMoComp          = 4,
00297     VAEntrypointDeblocking      = 5,
00298     VAEntrypointEncSlice        = 6,    /* slice level encode */
00299     VAEntrypointEncPicture      = 7,    /* pictuer encode, JPEG, etc */
00300     VAEntrypointVideoProc       = 10,   
00301 } VAEntrypoint;
00302 
00303 /* Currently defined configuration attribute types */
00304 typedef enum
00305 {
00306     VAConfigAttribRTFormat              = 0,
00307     VAConfigAttribSpatialResidual       = 1,
00308     VAConfigAttribSpatialClipping       = 2,
00309     VAConfigAttribIntraResidual         = 3,
00310     VAConfigAttribEncryption            = 4,
00311     VAConfigAttribRateControl           = 5
00312 } VAConfigAttribType;
00313 
00314 /*
00315  * Configuration attributes
00316  * If there is more than one value for an attribute, a default
00317  * value will be assigned to the attribute if the client does not
00318  * specify the attribute when creating a configuration
00319  */
00320 typedef struct _VAConfigAttrib {
00321     VAConfigAttribType type;
00322     unsigned int value; /* OR'd flags (bits) for this attribute */
00323 } VAConfigAttrib;
00324 
00325 /* attribute value for VAConfigAttribRTFormat */
00326 #define VA_RT_FORMAT_YUV420     0x00000001      
00327 #define VA_RT_FORMAT_YUV422     0x00000002
00328 #define VA_RT_FORMAT_YUV444     0x00000004
00329 #define VA_RT_FORMAT_PROTECTED  0x80000000
00330 
00331 /* attribute value for VAConfigAttribRateControl */
00332 #define VA_RC_NONE      0x00000001      
00333 #define VA_RC_CBR       0x00000002      
00334 #define VA_RC_VBR       0x00000004      
00335 #define VA_RC_VCM       0x00000008 /* video conference mode */
00336 
00337 /*
00338  * if an attribute is not applicable for a given
00339  * profile/entrypoint pair, then set the value to the following 
00340  */
00341 #define VA_ATTRIB_NOT_SUPPORTED 0x80000000
00342 
00343 /* Get maximum number of profiles supported by the implementation */
00344 int vaMaxNumProfiles (
00345     VADisplay dpy
00346 );
00347 
00348 /* Get maximum number of entrypoints supported by the implementation */
00349 int vaMaxNumEntrypoints (
00350     VADisplay dpy
00351 );
00352 
00353 /* Get maximum number of attributs supported by the implementation */
00354 int vaMaxNumConfigAttributes (
00355     VADisplay dpy
00356 );
00357 
00358 /* 
00359  * Query supported profiles 
00360  * The caller must provide a "profile_list" array that can hold at
00361  * least vaMaxNumProfile() entries. The actual number of profiles
00362  * returned in "profile_list" is returned in "num_profile".
00363  */
00364 VAStatus vaQueryConfigProfiles (
00365     VADisplay dpy,
00366     VAProfile *profile_list,    /* out */
00367     int *num_profiles           /* out */
00368 );
00369 
00370 /* 
00371  * Query supported entrypoints for a given profile 
00372  * The caller must provide an "entrypoint_list" array that can hold at
00373  * least vaMaxNumEntrypoints() entries. The actual number of entrypoints 
00374  * returned in "entrypoint_list" is returned in "num_entrypoints".
00375  */
00376 VAStatus vaQueryConfigEntrypoints (
00377     VADisplay dpy,
00378     VAProfile profile,
00379     VAEntrypoint *entrypoint_list,      /* out */
00380     int *num_entrypoints                /* out */
00381 );
00382 
00383 /* 
00384  * Get attributes for a given profile/entrypoint pair 
00385  * The caller must provide an "attrib_list" with all attributes to be 
00386  * retrieved.  Upon return, the attributes in "attrib_list" have been 
00387  * updated with their value.  Unknown attributes or attributes that are 
00388  * not supported for the given profile/entrypoint pair will have their 
00389  * value set to VA_ATTRIB_NOT_SUPPORTED
00390  */
00391 VAStatus vaGetConfigAttributes (
00392     VADisplay dpy,
00393     VAProfile profile,
00394     VAEntrypoint entrypoint,
00395     VAConfigAttrib *attrib_list, /* in/out */
00396     int num_attribs
00397 );
00398 
00399 /* Generic ID type, can be re-typed for specific implementation */
00400 typedef unsigned int VAGenericID;
00401 
00402 typedef VAGenericID VAConfigID;
00403 
00404 /* 
00405  * Create a configuration for the decode pipeline 
00406  * it passes in the attribute list that specifies the attributes it cares 
00407  * about, with the rest taking default values.  
00408  */
00409 VAStatus vaCreateConfig (
00410     VADisplay dpy,
00411     VAProfile profile, 
00412     VAEntrypoint entrypoint, 
00413     VAConfigAttrib *attrib_list,
00414     int num_attribs,
00415     VAConfigID *config_id /* out */
00416 );
00417 
00418 /* 
00419  * Free resources associdated with a given config 
00420  */
00421 VAStatus vaDestroyConfig (
00422     VADisplay dpy,
00423     VAConfigID config_id
00424 );
00425 
00426 /* 
00427  * Query all attributes for a given configuration 
00428  * The profile of the configuration is returned in "profile"
00429  * The entrypoint of the configuration is returned in "entrypoint"
00430  * The caller must provide an "attrib_list" array that can hold at least 
00431  * vaMaxNumConfigAttributes() entries. The actual number of attributes 
00432  * returned in "attrib_list" is returned in "num_attribs"
00433  */
00434 VAStatus vaQueryConfigAttributes (
00435     VADisplay dpy,
00436     VAConfigID config_id, 
00437     VAProfile *profile,         /* out */
00438     VAEntrypoint *entrypoint,   /* out */
00439     VAConfigAttrib *attrib_list,/* out */
00440     int *num_attribs            /* out */
00441 );
00442 
00443 
00444 /*
00445  * Contexts and Surfaces
00446  *
00447  * Context represents a "virtual" video decode pipeline. Surfaces are render 
00448  * targets for a given context. The data in the surfaces are not accessible  
00449  * to the client and the internal data format of the surface is implementatin 
00450  * specific. 
00451  *
00452  * Surfaces will be bound to a context when the context is created. Once
00453  * a surface is bound to a given context, it can not be used to create  
00454  * another context. The association is removed when the context is destroyed
00455  * 
00456  * Both contexts and surfaces are identified by unique IDs and its
00457  * implementation specific internals are kept opaque to the clients
00458  */
00459 
00460 typedef VAGenericID VAContextID;
00461 
00462 typedef VAGenericID VASurfaceID;
00463 
00464 #define VA_INVALID_ID           0xffffffff
00465 #define VA_INVALID_SURFACE      VA_INVALID_ID
00466 
00468 typedef enum  {
00469     VAGenericValueTypeInteger = 1,      
00470     VAGenericValueTypeFloat,            
00471     VAGenericValueTypePointer,          
00472     VAGenericValueTypeFunc              
00473 } VAGenericValueType;
00474 
00476 typedef void (*VAGenericFunc)(void);
00477 
00479 typedef struct _VAGenericValue {
00481     VAGenericValueType  type;
00483     union {
00485         int             i;
00487         float           f;
00489         void           *p;
00491         VAGenericFunc   fn;
00492     }                   value;
00493 } VAGenericValue;
00494 
00495 /* 
00496  * vaCreateSurfaces - Create an array of surfaces used for decode and display  
00497  *  dpy: display
00498  *  width: surface width
00499  *  height: surface height
00500  *  format: VA_RT_FORMAT_YUV420, VA_RT_FORMAT_YUV422 or VA_RT_FORMAT_YUV444
00501  *  num_surfaces: number of surfaces to be created
00502  *  surfaces: array of surfaces created upon return
00503  */
00504 VAStatus vaCreateSurfaces (
00505     VADisplay dpy,
00506     int width,
00507     int height,
00508     int format,
00509     int num_surfaces,
00510     VASurfaceID *surfaces       /* out */
00511 );
00512 
00513     
00514 /*
00515  * vaDestroySurfaces - Destroy resources associated with surfaces. 
00516  *  Surfaces can only be destroyed after the context associated has been 
00517  *  destroyed.  
00518  *  dpy: display
00519  *  surfaces: array of surfaces to destroy
00520  *  num_surfaces: number of surfaces in the array to be destroyed.
00521  */
00522 VAStatus vaDestroySurfaces (
00523     VADisplay dpy,
00524     VASurfaceID *surfaces,
00525     int num_surfaces
00526 );
00527 
00528 #define VA_PROGRESSIVE 0x1
00529 /*
00530  * vaCreateContext - Create a context
00531  *  dpy: display
00532  *  config_id: configuration for the context
00533  *  picture_width: coded picture width
00534  *  picture_height: coded picture height
00535  *  flag: any combination of the following:
00536  *    VA_PROGRESSIVE (only progressive frame pictures in the sequence when set)
00537  *  render_targets: render targets (surfaces) tied to the context
00538  *  num_render_targets: number of render targets in the above array
00539  *  context: created context id upon return
00540  */
00541 VAStatus vaCreateContext (
00542     VADisplay dpy,
00543     VAConfigID config_id,
00544     int picture_width,
00545     int picture_height,
00546     int flag,
00547     VASurfaceID *render_targets,
00548     int num_render_targets,
00549     VAContextID *context                /* out */
00550 );
00551 
00552 /*
00553  * vaDestroyContext - Destroy a context 
00554  *  dpy: display
00555  *  context: context to be destroyed
00556  */
00557 VAStatus vaDestroyContext (
00558     VADisplay dpy,
00559     VAContextID context
00560 );
00561 
00562 /*
00563  * Buffers 
00564  * Buffers are used to pass various types of data from the
00565  * client to the server. The server maintains a data store
00566  * for each buffer created, and the client idenfies a buffer
00567  * through a unique buffer id assigned by the server.
00568  */
00569 
00570 typedef VAGenericID VABufferID;
00571 
00572 typedef enum
00573 {
00574     VAPictureParameterBufferType        = 0,
00575     VAIQMatrixBufferType                = 1,
00576     VABitPlaneBufferType                = 2,
00577     VASliceGroupMapBufferType           = 3,
00578     VASliceParameterBufferType          = 4,
00579     VASliceDataBufferType               = 5,
00580     VAMacroblockParameterBufferType     = 6,
00581     VAResidualDataBufferType            = 7,
00582     VADeblockingParameterBufferType     = 8,
00583     VAImageBufferType                   = 9,
00584     VAProtectedSliceDataBufferType      = 10,
00585     VAQMatrixBufferType                 = 11,
00586 /* Following are encode buffer types */
00587     VAEncCodedBufferType                = 21,
00588     VAEncSequenceParameterBufferType    = 22,
00589     VAEncPictureParameterBufferType     = 23,
00590     VAEncSliceParameterBufferType       = 24,
00591     VAEncH264VUIBufferType              = 25,
00592     VAEncH264SEIBufferType              = 26,
00593     VAEncMiscParameterBufferType        = 27,
00594 /* Following are video processing buffer types */
00601     VAProcPipelineParameterBufferType   = 31,
00614     VAProcFilterParameterBufferType     = 32,
00615     VABufferTypeMax                     = 0xff
00616 } VABufferType;
00617 
00618 typedef enum
00619 {
00620     VAEncMiscParameterTypeFrameRate     = 0,
00621     VAEncMiscParameterTypeRateControl   = 1,
00622     VAEncMiscParameterTypeMaxSliceSize  = 2,
00623     VAEncMiscParameterTypeAIR           = 3,
00624 } VAEncMiscParameterType;
00625 
00626 /*
00627  *  For application, e.g. set a new bitrate
00628  *    VABufferID buf_id;
00629  *    VAEncMiscParameterBuffer *misc_param;
00630  *    VAEncMiscParameterRateControl *misc_rate_ctrl;
00631  * 
00632  *    vaCreateBuffer(dpy, context, VAEncMiscParameterBufferType,
00633  *              sizeof(VAEncMiscParameterBuffer) + sizeof(VAEncMiscParameterRateControl),
00634  *              1, NULL, &buf_id);
00635  *
00636  *    vaMapBuffer(dpy,buf_id,(void **)&misc_param);
00637  *    misc_param->type = VAEncMiscParameterTypeRateControl;
00638  *    misc_rate_ctrl= (VAEncMiscParameterRateControl *)misc_param->data;
00639  *    misc_rate_ctrl->bits_per_second = 6400000;
00640  *    vaUnmapBuffer(dpy, buf_id);
00641  *    vaRenderPicture(dpy, context, &buf_id, 1);
00642  */
00643 typedef struct _VAEncMiscParameterBuffer
00644 {
00645     VAEncMiscParameterType type;
00646     unsigned int data[0];
00647 } VAEncMiscParameterBuffer;
00648 
00649 typedef struct _VAEncMiscParameterRateControl
00650 {
00651     unsigned int bits_per_second; /* this is the maximum bit-rate to be constrained by the rate control implementation */
00652     unsigned int target_percentage; /* this is the bit-rate the rate control is targeting, as a percentage of the maximum bit-rate */
00653                                     /* for example if target_percentage is 95 then the rate control will target a bit-rate that is */
00654                                     /* 95% of the maximum bit-rate */
00655     unsigned int window_size; /* windows size in milliseconds. For example if this is set to 500, then the rate control will guarantee the */
00656                               /* target bit-rate over a 500 ms window */
00657     unsigned int initial_qp;  /* initial QP at I frames */
00658     unsigned int min_qp;     
00659 } VAEncMiscParameterRateControl;
00660 
00661 typedef struct _VAEncMiscParameterFrameRate
00662 {
00663     unsigned int framerate;
00664 } VAEncMiscParameterFrameRate;
00665 
00666 /*
00667  * Allow a maximum slice size to be specified (in bits).
00668  * The encoder will attempt to make sure that individual slices do not exceed this size
00669  * Or to signal applicate if the slice size exceed this size, see "status" of VACodedBufferSegment
00670  */
00671 typedef struct _VAEncMiscParameterMaxSliceSize
00672 {
00673     unsigned int max_slice_size;
00674 } VAEncMiscParameterMaxSliceSize;
00675 
00676 typedef struct _VAEncMiscParameterAIR
00677 {
00678     unsigned int air_num_mbs;
00679     unsigned int air_threshold;
00680     unsigned int air_auto; /* if set to 1 then hardware auto-tune the AIR threshold */
00681 } VAEncMiscParameterAIR;
00682 
00683 
00684 /* 
00685  * There will be cases where the bitstream buffer will not have enough room to hold
00686  * the data for the entire slice, and the following flags will be used in the slice
00687  * parameter to signal to the server for the possible cases.
00688  * If a slice parameter buffer and slice data buffer pair is sent to the server with 
00689  * the slice data partially in the slice data buffer (BEGIN and MIDDLE cases below), 
00690  * then a slice parameter and data buffer needs to be sent again to complete this slice. 
00691  */
00692 #define VA_SLICE_DATA_FLAG_ALL          0x00    /* whole slice is in the buffer */
00693 #define VA_SLICE_DATA_FLAG_BEGIN        0x01    /* The beginning of the slice is in the buffer but the end if not */
00694 #define VA_SLICE_DATA_FLAG_MIDDLE       0x02    /* Neither beginning nor end of the slice is in the buffer */
00695 #define VA_SLICE_DATA_FLAG_END          0x04    /* end of the slice is in the buffer */
00696 
00697 /* Codec-independent Slice Parameter Buffer base */
00698 typedef struct _VASliceParameterBufferBase
00699 {
00700     unsigned int slice_data_size;       /* number of bytes in the slice data buffer for this slice */
00701     unsigned int slice_data_offset;     /* the offset to the first byte of slice data */
00702     unsigned int slice_data_flag;       /* see VA_SLICE_DATA_FLAG_XXX definitions */
00703 } VASliceParameterBufferBase;
00704 
00705 
00706 /****************************
00707  * JEPG data structure
00708  ***************************/
00709 typedef struct _VAQMatrixBufferJPEG
00710 {
00711     int load_lum_quantiser_matrix;
00712     int load_chroma_quantiser_matrix;
00713     unsigned char lum_quantiser_matrix[64];
00714     unsigned char chroma_quantiser_matrix[64];
00715 } VAQMatrixBufferJPEG;
00716 
00717 typedef struct _VAEncPictureParameterBufferJPEG
00718 {
00719     VASurfaceID reconstructed_picture;
00720     unsigned short picture_width;
00721     unsigned short picture_height;
00722     VABufferID coded_buf;
00723 } VAEncPictureParameterBufferJPEG;
00724 
00725 
00726 /****************************
00727  * MPEG-2 data structures
00728  ****************************/
00729  
00730 /* MPEG-2 Picture Parameter Buffer */
00731 /* 
00732  * For each frame or field, and before any slice data, a single
00733  * picture parameter buffer must be send.
00734  */
00735 typedef struct _VAPictureParameterBufferMPEG2
00736 {
00737     unsigned short horizontal_size;
00738     unsigned short vertical_size;
00739     VASurfaceID forward_reference_picture;
00740     VASurfaceID backward_reference_picture;
00741     /* meanings of the following fields are the same as in the standard */
00742     int picture_coding_type;
00743     int f_code; /* pack all four fcode into this */
00744     union {
00745         struct {
00746             unsigned int intra_dc_precision             : 2; 
00747             unsigned int picture_structure              : 2; 
00748             unsigned int top_field_first                : 1; 
00749             unsigned int frame_pred_frame_dct           : 1; 
00750             unsigned int concealment_motion_vectors     : 1;
00751             unsigned int q_scale_type                   : 1;
00752             unsigned int intra_vlc_format               : 1;
00753             unsigned int alternate_scan                 : 1;
00754             unsigned int repeat_first_field             : 1;
00755             unsigned int progressive_frame              : 1;
00756             unsigned int is_first_field                 : 1; /* indicate whether the current field
00757                                                               * is the first field for field picture
00758                                                               */
00759         } bits;
00760         unsigned int value;
00761     } picture_coding_extension;
00762 } VAPictureParameterBufferMPEG2;
00763 
00764 /* MPEG-2 Inverse Quantization Matrix Buffer */
00765 typedef struct _VAIQMatrixBufferMPEG2
00766 {
00767     int load_intra_quantiser_matrix;
00768     int load_non_intra_quantiser_matrix;
00769     int load_chroma_intra_quantiser_matrix;
00770     int load_chroma_non_intra_quantiser_matrix;
00771     unsigned char intra_quantiser_matrix[64];
00772     unsigned char non_intra_quantiser_matrix[64];
00773     unsigned char chroma_intra_quantiser_matrix[64];
00774     unsigned char chroma_non_intra_quantiser_matrix[64];
00775 } VAIQMatrixBufferMPEG2;
00776 
00777 /* MPEG-2 Slice Parameter Buffer */
00778 typedef struct _VASliceParameterBufferMPEG2
00779 {
00780     unsigned int slice_data_size;/* number of bytes in the slice data buffer for this slice */
00781     unsigned int slice_data_offset;/* the offset to the first byte of slice data */
00782     unsigned int slice_data_flag; /* see VA_SLICE_DATA_FLAG_XXX defintions */
00783     unsigned int macroblock_offset;/* the offset to the first bit of MB from the first byte of slice data */
00784     unsigned int slice_horizontal_position;
00785     unsigned int slice_vertical_position;
00786     int quantiser_scale_code;
00787     int intra_slice_flag;
00788 } VASliceParameterBufferMPEG2;
00789 
00790 /* MPEG-2 Macroblock Parameter Buffer */
00791 typedef struct _VAMacroblockParameterBufferMPEG2
00792 {
00793     unsigned short macroblock_address;
00794     /* 
00795      * macroblock_address (in raster scan order)
00796      * top-left: 0
00797      * bottom-right: picture-height-in-mb*picture-width-in-mb - 1
00798      */
00799     unsigned char macroblock_type;  /* see definition below */
00800     union {
00801         struct {
00802             unsigned int frame_motion_type              : 2; 
00803             unsigned int field_motion_type              : 2; 
00804             unsigned int dct_type                       : 1; 
00805         } bits;
00806         unsigned int value;
00807     } macroblock_modes;
00808     unsigned char motion_vertical_field_select; 
00809     /* 
00810      * motion_vertical_field_select:
00811      * see section 6.3.17.2 in the spec
00812      * only the lower 4 bits are used
00813      * bit 0: first vector forward
00814      * bit 1: first vector backward
00815      * bit 2: second vector forward
00816      * bit 3: second vector backward
00817      */
00818     short PMV[2][2][2]; /* see Table 7-7 in the spec */
00819     unsigned short coded_block_pattern;
00820     /* 
00821      * The bitplanes for coded_block_pattern are described 
00822      * in Figure 6.10-12 in the spec
00823      */
00824      
00825     /* Number of skipped macroblocks after this macroblock */
00826     unsigned short num_skipped_macroblocks;
00827 } VAMacroblockParameterBufferMPEG2;
00828 
00829 /* 
00830  * OR'd flags for macroblock_type (section 6.3.17.1 in the spec)
00831  */
00832 #define VA_MB_TYPE_MOTION_FORWARD       0x02
00833 #define VA_MB_TYPE_MOTION_BACKWARD      0x04
00834 #define VA_MB_TYPE_MOTION_PATTERN       0x08
00835 #define VA_MB_TYPE_MOTION_INTRA         0x10
00836 
00837 /* 
00838  * MPEG-2 Residual Data Buffer 
00839  * For each macroblock, there wil be 64 shorts (16-bit) in the 
00840  * residual data buffer
00841  */
00842 
00843 /****************************
00844  * MPEG-4 Part 2 data structures
00845  ****************************/
00846  
00847 /* MPEG-4 Picture Parameter Buffer */
00848 /* 
00849  * For each frame or field, and before any slice data, a single
00850  * picture parameter buffer must be send.
00851  */
00852 typedef struct _VAPictureParameterBufferMPEG4
00853 {
00854     unsigned short vop_width;
00855     unsigned short vop_height;
00856     VASurfaceID forward_reference_picture;
00857     VASurfaceID backward_reference_picture;
00858     union {
00859         struct {
00860             unsigned int short_video_header             : 1; 
00861             unsigned int chroma_format                  : 2; 
00862             unsigned int interlaced                     : 1; 
00863             unsigned int obmc_disable                   : 1; 
00864             unsigned int sprite_enable                  : 2; 
00865             unsigned int sprite_warping_accuracy        : 2; 
00866             unsigned int quant_type                     : 1; 
00867             unsigned int quarter_sample                 : 1; 
00868             unsigned int data_partitioned               : 1; 
00869             unsigned int reversible_vlc                 : 1; 
00870             unsigned int resync_marker_disable          : 1; 
00871         } bits;
00872         unsigned int value;
00873     } vol_fields;
00874     unsigned char no_of_sprite_warping_points;
00875     short sprite_trajectory_du[3];
00876     short sprite_trajectory_dv[3];
00877     unsigned char quant_precision;
00878     union {
00879         struct {
00880             unsigned int vop_coding_type                : 2; 
00881             unsigned int backward_reference_vop_coding_type     : 2; 
00882             unsigned int vop_rounding_type              : 1; 
00883             unsigned int intra_dc_vlc_thr               : 3; 
00884             unsigned int top_field_first                : 1; 
00885             unsigned int alternate_vertical_scan_flag   : 1; 
00886         } bits;
00887         unsigned int value;
00888     } vop_fields;
00889     unsigned char vop_fcode_forward;
00890     unsigned char vop_fcode_backward;
00891     unsigned short vop_time_increment_resolution;
00892     /* short header related */
00893     unsigned char num_gobs_in_vop;
00894     unsigned char num_macroblocks_in_gob;
00895     /* for direct mode prediction */
00896     short TRB;
00897     short TRD;
00898 } VAPictureParameterBufferMPEG4;
00899 
00900 /* MPEG-4 Inverse Quantization Matrix Buffer */
00901 typedef struct _VAIQMatrixBufferMPEG4
00902 {
00903     int load_intra_quant_mat;
00904     int load_non_intra_quant_mat;
00905     unsigned char intra_quant_mat[64];
00906     unsigned char non_intra_quant_mat[64];
00907 } VAIQMatrixBufferMPEG4;
00908 
00909 /* MPEG-4 Slice Parameter Buffer */
00910 typedef struct _VASliceParameterBufferMPEG4
00911 {
00912     unsigned int slice_data_size;/* number of bytes in the slice data buffer for this slice */
00913     unsigned int slice_data_offset;/* the offset to the first byte of slice data */
00914     unsigned int slice_data_flag; /* see VA_SLICE_DATA_FLAG_XXX defintions */
00915     unsigned int macroblock_offset;/* the offset to the first bit of MB from the first byte of slice data */
00916     unsigned int macroblock_number;
00917     int quant_scale;
00918 } VASliceParameterBufferMPEG4;
00919 
00920 /*
00921  VC-1 data structures
00922 */
00923 
00924 typedef enum   /* see 7.1.1.32 */
00925 {
00926     VAMvMode1Mv                        = 0,
00927     VAMvMode1MvHalfPel                 = 1,
00928     VAMvMode1MvHalfPelBilinear         = 2,
00929     VAMvModeMixedMv                    = 3,
00930     VAMvModeIntensityCompensation      = 4 
00931 } VAMvModeVC1;
00932 
00933 /* VC-1 Picture Parameter Buffer */
00934 /* 
00935  * For each picture, and before any slice data, a picture parameter
00936  * buffer must be send. Multiple picture parameter buffers may be
00937  * sent for a single picture. In that case picture parameters will
00938  * apply to all slice data that follow it until a new picture
00939  * parameter buffer is sent.
00940  *
00941  * Notes:
00942  *   pic_quantizer_type should be set to the applicable quantizer
00943  *   type as defined by QUANTIZER (J.1.19) and either
00944  *   PQUANTIZER (7.1.1.8) or PQINDEX (7.1.1.6)
00945  */
00946 typedef struct _VAPictureParameterBufferVC1
00947 {
00948     VASurfaceID forward_reference_picture;
00949     VASurfaceID backward_reference_picture;
00950     /* if out-of-loop post-processing is done on the render
00951        target, then we need to keep the in-loop decoded 
00952        picture as a reference picture */
00953     VASurfaceID inloop_decoded_picture;
00954 
00955     /* sequence layer for AP or meta data for SP and MP */
00956     union {
00957         struct {
00958             unsigned int pulldown       : 1; /* SEQUENCE_LAYER::PULLDOWN */
00959             unsigned int interlace      : 1; /* SEQUENCE_LAYER::INTERLACE */
00960             unsigned int tfcntrflag     : 1; /* SEQUENCE_LAYER::TFCNTRFLAG */
00961             unsigned int finterpflag    : 1; /* SEQUENCE_LAYER::FINTERPFLAG */
00962             unsigned int psf            : 1; /* SEQUENCE_LAYER::PSF */
00963             unsigned int multires       : 1; /* METADATA::MULTIRES */
00964             unsigned int overlap        : 1; /* METADATA::OVERLAP */
00965             unsigned int syncmarker     : 1; /* METADATA::SYNCMARKER */
00966             unsigned int rangered       : 1; /* METADATA::RANGERED */
00967             unsigned int max_b_frames   : 3; /* METADATA::MAXBFRAMES */
00968             unsigned int profile        : 2; /* SEQUENCE_LAYER::PROFILE or The MSB of METADATA::PROFILE */
00969         } bits;
00970         unsigned int value;
00971     } sequence_fields;
00972 
00973     unsigned short coded_width;         /* ENTRY_POINT_LAYER::CODED_WIDTH */
00974     unsigned short coded_height;        /* ENTRY_POINT_LAYER::CODED_HEIGHT */
00975     union {
00976         struct {
00977             unsigned int broken_link    : 1; /* ENTRY_POINT_LAYER::BROKEN_LINK */
00978             unsigned int closed_entry   : 1; /* ENTRY_POINT_LAYER::CLOSED_ENTRY */
00979             unsigned int panscan_flag   : 1; /* ENTRY_POINT_LAYER::PANSCAN_FLAG */
00980             unsigned int loopfilter     : 1; /* ENTRY_POINT_LAYER::LOOPFILTER */
00981         } bits;
00982         unsigned int value;
00983     } entrypoint_fields;
00984     unsigned char conditional_overlap_flag; /* ENTRY_POINT_LAYER::CONDOVER */
00985     unsigned char fast_uvmc_flag;       /* ENTRY_POINT_LAYER::FASTUVMC */
00986     union {
00987         struct {
00988             unsigned int luma_flag      : 1; /* ENTRY_POINT_LAYER::RANGE_MAPY_FLAG */
00989             unsigned int luma           : 3; /* ENTRY_POINT_LAYER::RANGE_MAPY */
00990             unsigned int chroma_flag    : 1; /* ENTRY_POINT_LAYER::RANGE_MAPUV_FLAG */
00991             unsigned int chroma         : 3; /* ENTRY_POINT_LAYER::RANGE_MAPUV */
00992         } bits;
00993         unsigned int value;
00994     } range_mapping_fields;
00995 
00996     unsigned char b_picture_fraction;   /* PICTURE_LAYER::BFRACTION */
00997     unsigned char cbp_table;            /* PICTURE_LAYER::CBPTAB/ICBPTAB */
00998     unsigned char mb_mode_table;        /* PICTURE_LAYER::MBMODETAB */
00999     unsigned char range_reduction_frame;/* PICTURE_LAYER::RANGEREDFRM */
01000     unsigned char rounding_control;     /* PICTURE_LAYER::RNDCTRL */
01001     unsigned char post_processing;      /* PICTURE_LAYER::POSTPROC */
01002     unsigned char picture_resolution_index;     /* PICTURE_LAYER::RESPIC */
01003     unsigned char luma_scale;           /* PICTURE_LAYER::LUMSCALE */
01004     unsigned char luma_shift;           /* PICTURE_LAYER::LUMSHIFT */
01005     union {
01006         struct {
01007             unsigned int picture_type           : 3; /* PICTURE_LAYER::PTYPE */
01008             unsigned int frame_coding_mode      : 3; /* PICTURE_LAYER::FCM */
01009             unsigned int top_field_first        : 1; /* PICTURE_LAYER::TFF */
01010             unsigned int is_first_field         : 1; /* set to 1 if it is the first field */
01011             unsigned int intensity_compensation : 1; /* PICTURE_LAYER::INTCOMP */
01012         } bits;
01013         unsigned int value;
01014     } picture_fields;
01015     union {
01016         struct {
01017             unsigned int mv_type_mb     : 1;    /* PICTURE::MVTYPEMB */
01018             unsigned int direct_mb      : 1;    /* PICTURE::DIRECTMB */
01019             unsigned int skip_mb        : 1;    /* PICTURE::SKIPMB */
01020             unsigned int field_tx       : 1;    /* PICTURE::FIELDTX */
01021             unsigned int forward_mb     : 1;    /* PICTURE::FORWARDMB */
01022             unsigned int ac_pred        : 1;    /* PICTURE::ACPRED */
01023             unsigned int overflags      : 1;    /* PICTURE::OVERFLAGS */
01024         } flags;
01025         unsigned int value;
01026     } raw_coding;
01027     union {
01028         struct {
01029             unsigned int bp_mv_type_mb   : 1;    /* PICTURE::MVTYPEMB */
01030             unsigned int bp_direct_mb    : 1;    /* PICTURE::DIRECTMB */
01031             unsigned int bp_skip_mb      : 1;    /* PICTURE::SKIPMB */  
01032             unsigned int bp_field_tx     : 1;    /* PICTURE::FIELDTX */ 
01033             unsigned int bp_forward_mb   : 1;    /* PICTURE::FORWARDMB */
01034             unsigned int bp_ac_pred      : 1;    /* PICTURE::ACPRED */   
01035             unsigned int bp_overflags    : 1;    /* PICTURE::OVERFLAGS */
01036         } flags;
01037         unsigned int value;
01038     } bitplane_present; /* signal what bitplane is being passed via the bitplane buffer */
01039     union {
01040         struct {
01041             unsigned int reference_distance_flag : 1;/* PICTURE_LAYER::REFDIST_FLAG */
01042             unsigned int reference_distance     : 5;/* PICTURE_LAYER::REFDIST */
01043             unsigned int num_reference_pictures: 1;/* PICTURE_LAYER::NUMREF */
01044             unsigned int reference_field_pic_indicator  : 1;/* PICTURE_LAYER::REFFIELD */
01045         } bits;
01046         unsigned int value;
01047     } reference_fields;
01048     union {
01049         struct {
01050             unsigned int mv_mode                : 3; /* PICTURE_LAYER::MVMODE */
01051             unsigned int mv_mode2               : 3; /* PICTURE_LAYER::MVMODE2 */
01052             unsigned int mv_table               : 3; /* PICTURE_LAYER::MVTAB/IMVTAB */
01053             unsigned int two_mv_block_pattern_table: 2; /* PICTURE_LAYER::2MVBPTAB */
01054             unsigned int four_mv_switch         : 1; /* PICTURE_LAYER::4MVSWITCH */
01055             unsigned int four_mv_block_pattern_table : 2; /* PICTURE_LAYER::4MVBPTAB */
01056             unsigned int extended_mv_flag       : 1; /* ENTRY_POINT_LAYER::EXTENDED_MV */
01057             unsigned int extended_mv_range      : 2; /* PICTURE_LAYER::MVRANGE */
01058             unsigned int extended_dmv_flag      : 1; /* ENTRY_POINT_LAYER::EXTENDED_DMV */
01059             unsigned int extended_dmv_range     : 2; /* PICTURE_LAYER::DMVRANGE */
01060         } bits;
01061         unsigned int value;
01062     } mv_fields;
01063     union {
01064         struct {
01065             unsigned int dquant : 2;    /* ENTRY_POINT_LAYER::DQUANT */
01066             unsigned int quantizer     : 2;     /* ENTRY_POINT_LAYER::QUANTIZER */
01067             unsigned int half_qp        : 1;    /* PICTURE_LAYER::HALFQP */
01068             unsigned int pic_quantizer_scale : 5;/* PICTURE_LAYER::PQUANT */
01069             unsigned int pic_quantizer_type : 1;/* PICTURE_LAYER::PQUANTIZER */
01070             unsigned int dq_frame       : 1;    /* VOPDQUANT::DQUANTFRM */
01071             unsigned int dq_profile     : 2;    /* VOPDQUANT::DQPROFILE */
01072             unsigned int dq_sb_edge     : 2;    /* VOPDQUANT::DQSBEDGE */
01073             unsigned int dq_db_edge     : 2;    /* VOPDQUANT::DQDBEDGE */
01074             unsigned int dq_binary_level : 1;   /* VOPDQUANT::DQBILEVEL */
01075             unsigned int alt_pic_quantizer : 5;/* VOPDQUANT::ALTPQUANT */
01076         } bits;
01077         unsigned int value;
01078     } pic_quantizer_fields;
01079     union {
01080         struct {
01081             unsigned int variable_sized_transform_flag  : 1;/* ENTRY_POINT_LAYER::VSTRANSFORM */
01082             unsigned int mb_level_transform_type_flag   : 1;/* PICTURE_LAYER::TTMBF */
01083             unsigned int frame_level_transform_type     : 2;/* PICTURE_LAYER::TTFRM */
01084             unsigned int transform_ac_codingset_idx1    : 2;/* PICTURE_LAYER::TRANSACFRM */
01085             unsigned int transform_ac_codingset_idx2    : 2;/* PICTURE_LAYER::TRANSACFRM2 */
01086             unsigned int intra_transform_dc_table       : 1;/* PICTURE_LAYER::TRANSDCTAB */
01087         } bits;
01088         unsigned int value;
01089     } transform_fields;
01090 } VAPictureParameterBufferVC1;
01091 
01092 /* VC-1 Bitplane Buffer 
01093 There will be at most three bitplanes coded in any picture header. To send 
01094 the bitplane data more efficiently, each byte is divided in two nibbles, with
01095 each nibble carrying three bitplanes for one macroblock.  The following table
01096 shows the bitplane data arrangement within each nibble based on the picture
01097 type.
01098 
01099 Picture Type    Bit3            Bit2            Bit1            Bit0
01100 I or BI                         OVERFLAGS       ACPRED          FIELDTX
01101 P                               MYTYPEMB        SKIPMB          DIRECTMB
01102 B                               FORWARDMB       SKIPMB          DIRECTMB
01103 
01104 Within each byte, the lower nibble is for the first MB and the upper nibble is 
01105 for the second MB.  E.g. the lower nibble of the first byte in the bitplane
01106 buffer is for Macroblock #1 and the upper nibble of the first byte is for 
01107 Macroblock #2 in the first row.
01108 */
01109 
01110 /* VC-1 Slice Parameter Buffer */
01111 typedef struct _VASliceParameterBufferVC1
01112 {
01113     unsigned int slice_data_size;/* number of bytes in the slice data buffer for this slice */
01114     unsigned int slice_data_offset;/* the offset to the first byte of slice data */
01115     unsigned int slice_data_flag; /* see VA_SLICE_DATA_FLAG_XXX defintions */
01116     unsigned int macroblock_offset;/* the offset to the first bit of MB from the first byte of slice data */
01117     unsigned int slice_vertical_position;
01118 } VASliceParameterBufferVC1;
01119 
01120 /* VC-1 Slice Data Buffer */
01121 /* 
01122 This is simplely a buffer containing raw bit-stream bytes 
01123 */
01124 
01125 /****************************
01126  * H.264/AVC data structures
01127  ****************************/
01128 
01129 typedef struct _VAPictureH264
01130 {
01131     VASurfaceID picture_id;
01132     unsigned int frame_idx;
01133     unsigned int flags;
01134     signed int TopFieldOrderCnt;
01135     signed int BottomFieldOrderCnt;
01136 } VAPictureH264;
01137 /* flags in VAPictureH264 could be OR of the following */
01138 #define VA_PICTURE_H264_INVALID                 0x00000001
01139 #define VA_PICTURE_H264_TOP_FIELD               0x00000002
01140 #define VA_PICTURE_H264_BOTTOM_FIELD            0x00000004
01141 #define VA_PICTURE_H264_SHORT_TERM_REFERENCE    0x00000008
01142 #define VA_PICTURE_H264_LONG_TERM_REFERENCE     0x00000010
01143 
01144 /* H.264 Picture Parameter Buffer */
01145 /* 
01146  * For each picture, and before any slice data, a single
01147  * picture parameter buffer must be send.
01148  */
01149 typedef struct _VAPictureParameterBufferH264
01150 {
01151     VAPictureH264 CurrPic;
01152     VAPictureH264 ReferenceFrames[16];  /* in DPB */
01153     unsigned short picture_width_in_mbs_minus1;
01154     unsigned short picture_height_in_mbs_minus1;
01155     unsigned char bit_depth_luma_minus8;
01156     unsigned char bit_depth_chroma_minus8;
01157     unsigned char num_ref_frames;
01158     union {
01159         struct {
01160             unsigned int chroma_format_idc                      : 2; 
01161             unsigned int residual_colour_transform_flag         : 1; 
01162             unsigned int gaps_in_frame_num_value_allowed_flag   : 1; 
01163             unsigned int frame_mbs_only_flag                    : 1; 
01164             unsigned int mb_adaptive_frame_field_flag           : 1; 
01165             unsigned int direct_8x8_inference_flag              : 1; 
01166             unsigned int MinLumaBiPredSize8x8                   : 1; /* see A.3.3.2 */
01167             unsigned int log2_max_frame_num_minus4              : 4;
01168             unsigned int pic_order_cnt_type                     : 2;
01169             unsigned int log2_max_pic_order_cnt_lsb_minus4      : 4;
01170             unsigned int delta_pic_order_always_zero_flag       : 1;
01171         } bits;
01172         unsigned int value;
01173     } seq_fields;
01174     unsigned char num_slice_groups_minus1;
01175     unsigned char slice_group_map_type;
01176     unsigned short slice_group_change_rate_minus1;
01177     signed char pic_init_qp_minus26;
01178     signed char pic_init_qs_minus26;
01179     signed char chroma_qp_index_offset;
01180     signed char second_chroma_qp_index_offset;
01181     union {
01182         struct {
01183             unsigned int entropy_coding_mode_flag       : 1;
01184             unsigned int weighted_pred_flag             : 1;
01185             unsigned int weighted_bipred_idc            : 2;
01186             unsigned int transform_8x8_mode_flag        : 1;
01187             unsigned int field_pic_flag                 : 1;
01188             unsigned int constrained_intra_pred_flag    : 1;
01189             unsigned int pic_order_present_flag                 : 1;
01190             unsigned int deblocking_filter_control_present_flag : 1;
01191             unsigned int redundant_pic_cnt_present_flag         : 1;
01192             unsigned int reference_pic_flag                     : 1; /* nal_ref_idc != 0 */
01193         } bits;
01194         unsigned int value;
01195     } pic_fields;
01196     unsigned short frame_num;
01197 } VAPictureParameterBufferH264;
01198 
01199 /* H.264 Inverse Quantization Matrix Buffer */
01200 typedef struct _VAIQMatrixBufferH264
01201 {
01202     unsigned char ScalingList4x4[6][16];
01203     unsigned char ScalingList8x8[2][64];
01204 } VAIQMatrixBufferH264;
01205 
01206 /* 
01207  * H.264 Slice Group Map Buffer 
01208  * When VAPictureParameterBufferH264::num_slice_group_minus1 is not equal to 0,
01209  * A slice group map buffer should be sent for each picture if required. The buffer
01210  * is sent only when there is a change in the mapping values.
01211  * The slice group map buffer map "map units" to slice groups as specified in 
01212  * section 8.2.2 of the H.264 spec. The buffer will contain one byte for each macroblock 
01213  * in raster scan order
01214  */ 
01215 
01216 /* H.264 Slice Parameter Buffer */
01217 typedef struct _VASliceParameterBufferH264
01218 {
01219     unsigned int slice_data_size;/* number of bytes in the slice data buffer for this slice */
01220     unsigned int slice_data_offset;/* the offset to the NAL start code for this slice */
01221     unsigned int slice_data_flag; /* see VA_SLICE_DATA_FLAG_XXX defintions */
01222     unsigned short slice_data_bit_offset; /* bit offset from NAL start code to the beginning of slice data */
01223     unsigned short first_mb_in_slice;
01224     unsigned char slice_type;
01225     unsigned char direct_spatial_mv_pred_flag;
01226     unsigned char num_ref_idx_l0_active_minus1;
01227     unsigned char num_ref_idx_l1_active_minus1;
01228     unsigned char cabac_init_idc;
01229     char slice_qp_delta;
01230     unsigned char disable_deblocking_filter_idc;
01231     char slice_alpha_c0_offset_div2;
01232     char slice_beta_offset_div2;
01233     VAPictureH264 RefPicList0[32];      /* See 8.2.4.2 */
01234     VAPictureH264 RefPicList1[32];      /* See 8.2.4.2 */
01235     unsigned char luma_log2_weight_denom;
01236     unsigned char chroma_log2_weight_denom;
01237     unsigned char luma_weight_l0_flag;
01238     short luma_weight_l0[32];
01239     short luma_offset_l0[32];
01240     unsigned char chroma_weight_l0_flag;
01241     short chroma_weight_l0[32][2];
01242     short chroma_offset_l0[32][2];
01243     unsigned char luma_weight_l1_flag;
01244     short luma_weight_l1[32];
01245     short luma_offset_l1[32];
01246     unsigned char chroma_weight_l1_flag;
01247     short chroma_weight_l1[32][2];
01248     short chroma_offset_l1[32][2];
01249 } VASliceParameterBufferH264;
01250 
01251 /****************************
01252  * Common encode data structures 
01253  ****************************/
01254 typedef enum
01255 {
01256     VAEncPictureTypeIntra               = 0,
01257     VAEncPictureTypePredictive          = 1,
01258     VAEncPictureTypeBidirectional       = 2,
01259 } VAEncPictureType;
01260 
01261 /* Encode Slice Parameter Buffer */
01262 typedef struct _VAEncSliceParameterBuffer
01263 {
01264     unsigned int start_row_number;      /* starting MB row number for this slice */
01265     unsigned int slice_height;  /* slice height measured in MB */
01266     union {
01267         struct {
01268             unsigned int is_intra       : 1;
01269             unsigned int disable_deblocking_filter_idc : 2;
01270             unsigned int uses_long_term_ref             :1;
01271             unsigned int is_long_term_ref               :1;
01272         } bits;
01273         unsigned int value;
01274     } slice_flags;
01275 } VAEncSliceParameterBuffer;
01276 
01277 /****************************
01278  * H.264 specific encode data structures
01279  ****************************/
01280 
01281 typedef struct _VAEncSequenceParameterBufferH264
01282 {
01283     unsigned char seq_parameter_set_id;
01284     unsigned char level_idc;
01285     unsigned int intra_period;
01286     unsigned int intra_idr_period;
01287     unsigned int max_num_ref_frames;
01288     unsigned int picture_width_in_mbs;
01289     unsigned int picture_height_in_mbs;
01290     unsigned int bits_per_second;
01291     unsigned int frame_rate;
01292     unsigned int initial_qp;
01293     unsigned int min_qp;
01294     unsigned int basic_unit_size;
01295     unsigned char vui_flag;
01296 } VAEncSequenceParameterBufferH264;
01297 
01298 #define H264_LAST_PICTURE_EOSEQ     0x01 /* the last picture in the sequence */
01299 #define H264_LAST_PICTURE_EOSTREAM  0x02 /* the last picture in the stream */
01300 typedef struct _VAEncPictureParameterBufferH264
01301 {
01302     VASurfaceID reference_picture;
01303     VASurfaceID reconstructed_picture;
01304     VABufferID coded_buf;
01305     unsigned short picture_width;
01306     unsigned short picture_height;
01307     unsigned char last_picture;
01308 } VAEncPictureParameterBufferH264;
01309 
01310 /****************************
01311  * H.263 specific encode data structures
01312  ****************************/
01313 
01314 typedef struct _VAEncSequenceParameterBufferH263
01315 {
01316     unsigned int intra_period;
01317     unsigned int bits_per_second;
01318     unsigned int frame_rate;
01319     unsigned int initial_qp;
01320     unsigned int min_qp;
01321 } VAEncSequenceParameterBufferH263;
01322 
01323 typedef struct _VAEncPictureParameterBufferH263
01324 {
01325     VASurfaceID reference_picture;
01326     VASurfaceID reconstructed_picture;
01327     VABufferID coded_buf;
01328     unsigned short picture_width;
01329     unsigned short picture_height;
01330     VAEncPictureType picture_type;
01331 } VAEncPictureParameterBufferH263;
01332 
01333 /****************************
01334  * MPEG-4 specific encode data structures
01335  ****************************/
01336 
01337 typedef struct _VAEncSequenceParameterBufferMPEG4
01338 {
01339     unsigned char profile_and_level_indication;
01340     unsigned int intra_period;
01341     unsigned int video_object_layer_width;
01342     unsigned int video_object_layer_height;
01343     unsigned int vop_time_increment_resolution;
01344     unsigned int fixed_vop_rate;
01345     unsigned int fixed_vop_time_increment;
01346     unsigned int bits_per_second;
01347     unsigned int frame_rate;
01348     unsigned int initial_qp;
01349     unsigned int min_qp;
01350 } VAEncSequenceParameterBufferMPEG4;
01351 
01352 typedef struct _VAEncPictureParameterBufferMPEG4
01353 {
01354     VASurfaceID reference_picture;
01355     VASurfaceID reconstructed_picture;
01356     VABufferID coded_buf;
01357     unsigned short picture_width;
01358     unsigned short picture_height;
01359     unsigned int modulo_time_base; /* number of 1s */
01360     unsigned int vop_time_increment;
01361     VAEncPictureType picture_type;
01362 } VAEncPictureParameterBufferMPEG4;
01363 
01364 
01365 
01366 /* Buffer functions */
01367 
01368 /*
01369  * Creates a buffer for "num_elements" elements of "size" bytes and 
01370  * initalize with "data".
01371  * if "data" is null, then the contents of the buffer data store
01372  * are undefined.
01373  * Basically there are two ways to get buffer data to the server side. One is 
01374  * to call vaCreateBuffer() with a non-null "data", which results the data being
01375  * copied to the data store on the server side.  A different method that 
01376  * eliminates this copy is to pass null as "data" when calling vaCreateBuffer(),
01377  * and then use vaMapBuffer() to map the data store from the server side to the
01378  * client address space for access.
01379  *  Note: image buffers are created by the library, not the client. Please see 
01380  *        vaCreateImage on how image buffers are managed.
01381  */
01382 VAStatus vaCreateBuffer (
01383     VADisplay dpy,
01384     VAContextID context,
01385     VABufferType type,  /* in */
01386     unsigned int size,  /* in */
01387     unsigned int num_elements, /* in */
01388     void *data,         /* in */
01389     VABufferID *buf_id  /* out */
01390 );
01391 
01392 /*
01393  * Convey to the server how many valid elements are in the buffer. 
01394  * e.g. if multiple slice parameters are being held in a single buffer,
01395  * this will communicate to the server the number of slice parameters
01396  * that are valid in the buffer.
01397  */
01398 VAStatus vaBufferSetNumElements (
01399     VADisplay dpy,
01400     VABufferID buf_id,  /* in */
01401     unsigned int num_elements /* in */
01402 );
01403 
01404 
01405 /*
01406  * device independent data structure for codedbuffer
01407  */
01408 
01409 /* 
01410  * FICTURE_AVE_QP(bit7-0): The average Qp value used during this frame
01411  * LARGE_SLICE(bit8):At least one slice in the current frame was large
01412  *              enough for the encoder to attempt to limit its size.
01413  * SLICE_OVERFLOW(bit9): At least one slice in the current frame has
01414  *              exceeded the maximum slice size specified.
01415  * BITRATE_OVERFLOW(bit10): The peak bitrate was exceeded for this frame.
01416  * BITRATE_HIGH(bit11): The frame size got within the safety margin of the maximum size (VCM only)
01417  * AIR_MB_OVER_THRESHOLD: the number of MBs adapted to Intra MB
01418  */
01419 #define VA_CODED_BUF_STATUS_PICTURE_AVE_QP_MASK         0xff
01420 #define VA_CODED_BUF_STATUS_LARGE_SLICE_MASK            0x100
01421 #define VA_CODED_BUF_STATUS_SLICE_OVERFLOW_MASK         0x200
01422 #define VA_CODED_BUF_STATUS_BITRATE_OVERFLOW            0x400
01423 #define VA_CODED_BUF_STATUS_BITRATE_HIGH                0x800
01424 #define VA_CODED_BUF_STATUS_AIR_MB_OVER_THRESHOLD       0xff0000
01425 
01426 /*
01427  * device independent data structure for codedbuffer
01428  */
01429 typedef  struct _VACodedBufferSegment  {
01430     unsigned int size;/* size of the data buffer in the coded buffer segment, in bytes */
01431     unsigned int bit_offset; /* bit offset into the data buffer where valid bitstream data begins */
01432     unsigned int status; /* status set by the driver on the coded buffer*/
01433     unsigned int reserved; /* for future use */
01434     void *buf; /* pointer to the beginning of the data buffer in the coded buffer segment */
01435     void *next; /* pointer to the next VACodedBufferSegment */
01436 } VACodedBufferSegment;
01437      
01438 /*
01439  * Map data store of the buffer into the client's address space
01440  * vaCreateBuffer() needs to be called with "data" set to NULL before
01441  * calling vaMapBuffer()
01442  *
01443  * if buffer type is VAEncCodedBufferType, pbuf points to link-list of
01444  * VACodedBufferSegment, and the list is terminated if "next" is NULL
01445  */
01446 VAStatus vaMapBuffer (
01447     VADisplay dpy,
01448     VABufferID buf_id,  /* in */
01449     void **pbuf         /* out */
01450 );
01451 
01452 /*
01453  * After client making changes to a mapped data store, it needs to
01454  * "Unmap" it to let the server know that the data is ready to be
01455  * consumed by the server
01456  */
01457 VAStatus vaUnmapBuffer (
01458     VADisplay dpy,
01459     VABufferID buf_id   /* in */
01460 );
01461 
01462 /*
01463  * After this call, the buffer is deleted and this buffer_id is no longer valid
01464  * Only call this if the buffer is not going to be passed to vaRenderBuffer
01465  */
01466 VAStatus vaDestroyBuffer (
01467     VADisplay dpy,
01468     VABufferID buffer_id
01469 );
01470 
01471 /*
01472 Render (Decode) Pictures
01473 
01474 A picture represents either a frame or a field.
01475 
01476 The Begin/Render/End sequence sends the decode buffers to the server
01477 */
01478 
01479 /*
01480  * Get ready to decode a picture to a target surface
01481  */
01482 VAStatus vaBeginPicture (
01483     VADisplay dpy,
01484     VAContextID context,
01485     VASurfaceID render_target
01486 );
01487 
01488 /* 
01489  * Send decode buffers to the server.
01490  * Buffers are automatically destroyed afterwards
01491  */
01492 VAStatus vaRenderPicture (
01493     VADisplay dpy,
01494     VAContextID context,
01495     VABufferID *buffers,
01496     int num_buffers
01497 );
01498 
01499 /* 
01500  * Make the end of rendering for a picture. 
01501  * The server should start processing all pending operations for this 
01502  * surface. This call is non-blocking. The client can start another 
01503  * Begin/Render/End sequence on a different render target.
01504  */
01505 VAStatus vaEndPicture (
01506     VADisplay dpy,
01507     VAContextID context
01508 );
01509 
01510 /*
01511 
01512 Synchronization 
01513 
01514 */
01515 
01516 /* 
01517  * This function blocks until all pending operations on the render target
01518  * have been completed.  Upon return it is safe to use the render target for a 
01519  * different picture. 
01520  */
01521 VAStatus vaSyncSurface (
01522     VADisplay dpy,
01523     VASurfaceID render_target
01524 );
01525 
01526 typedef enum
01527 {
01528     VASurfaceRendering  = 1, /* Rendering in progress */ 
01529     VASurfaceDisplaying = 2, /* Displaying in progress (not safe to render into it) */ 
01530                              /* this status is useful if surface is used as the source */
01531                              /* of an overlay */
01532     VASurfaceReady      = 4, /* not being rendered or displayed */
01533     VASurfaceSkipped    = 8  /* Indicate a skipped frame during encode */
01534 } VASurfaceStatus;
01535 
01536 /*
01537  * Find out any pending ops on the render target 
01538  */
01539 VAStatus vaQuerySurfaceStatus (
01540     VADisplay dpy,
01541     VASurfaceID render_target,
01542     VASurfaceStatus *status     /* out */
01543 );
01544 
01545 typedef enum
01546 {
01547     VADecodeSliceMissing            = 0,
01548     VADecodeMBError                 = 1,
01549 } VADecodeErrorType;
01550 
01551 /*
01552  * Client calls vaQuerySurfaceError with VA_STATUS_ERROR_DECODING_ERROR, server side returns
01553  * an array of structure VASurfaceDecodeMBErrors, and the array is terminated by setting status=-1
01554 */
01555 typedef struct _VASurfaceDecodeMBErrors
01556 {
01557     int status; /* 1 if hardware has returned detailed info below, -1 means this record is invalid */
01558     unsigned int start_mb; /* start mb address with errors */
01559     unsigned int end_mb;  /* end mb address with errors */
01560     VADecodeErrorType decode_error_type;
01561 } VASurfaceDecodeMBErrors;
01562 
01563 /*
01564  * After the application gets VA_STATUS_ERROR_DECODING_ERROR after calling vaSyncSurface(),
01565  * it can call vaQuerySurfaceError to find out further details on the particular error.
01566  * VA_STATUS_ERROR_DECODING_ERROR should be passed in as "error_status",
01567  * upon the return, error_info will point to an array of _VASurfaceDecodeMBErrors structure,
01568  * which is allocated and filled by libVA with detailed information on the missing or error macroblocks.
01569  * The array is terminated if "status==-1" is detected.
01570  */
01571 VAStatus vaQuerySurfaceError(
01572     VADisplay dpy,
01573     VASurfaceID surface,
01574     VAStatus error_status,
01575     void **error_info
01576 );
01577 
01578 /*
01579  * Images and Subpictures
01580  * VAImage is used to either get the surface data to client memory, or 
01581  * to copy image data in client memory to a surface. 
01582  * Both images, subpictures and surfaces follow the same 2D coordinate system where origin 
01583  * is at the upper left corner with positive X to the right and positive Y down
01584  */
01585 #define VA_FOURCC(ch0, ch1, ch2, ch3) \
01586     ((unsigned long)(unsigned char) (ch0) | ((unsigned long)(unsigned char) (ch1) << 8) | \
01587     ((unsigned long)(unsigned char) (ch2) << 16) | ((unsigned long)(unsigned char) (ch3) << 24 ))
01588 
01589 /* a few common FourCCs */
01590 #define VA_FOURCC_NV12          0x3231564E
01591 #define VA_FOURCC_AI44          0x34344149
01592 #define VA_FOURCC_RGBA          0x41424752
01593 #define VA_FOURCC_BGRA          0x41524742
01594 #define VA_FOURCC_UYVY          0x59565955
01595 #define VA_FOURCC_YUY2          0x32595559
01596 #define VA_FOURCC_AYUV          0x56555941
01597 #define VA_FOURCC_NV11          0x3131564e
01598 #define VA_FOURCC_YV12          0x32315659
01599 #define VA_FOURCC_P208          0x38303250
01600 #define VA_FOURCC_IYUV          0x56555949
01601 
01602 /* byte order */
01603 #define VA_LSB_FIRST            1
01604 #define VA_MSB_FIRST            2
01605 
01606 typedef struct _VAImageFormat
01607 {
01608     unsigned int        fourcc;
01609     unsigned int        byte_order; /* VA_LSB_FIRST, VA_MSB_FIRST */
01610     unsigned int        bits_per_pixel;
01611     /* for RGB formats */
01612     unsigned int        depth; /* significant bits per pixel */
01613     unsigned int        red_mask;
01614     unsigned int        green_mask;
01615     unsigned int        blue_mask;
01616     unsigned int        alpha_mask;
01617 } VAImageFormat;
01618 
01619 typedef VAGenericID VAImageID;
01620 
01621 typedef struct _VAImage
01622 {
01623     VAImageID           image_id; /* uniquely identify this image */
01624     VAImageFormat       format;
01625     VABufferID          buf;    /* image data buffer */
01626     /*
01627      * Image data will be stored in a buffer of type VAImageBufferType to facilitate
01628      * data store on the server side for optimal performance. The buffer will be 
01629      * created by the CreateImage function, and proper storage allocated based on the image
01630      * size and format. This buffer is managed by the library implementation, and 
01631      * accessed by the client through the buffer Map/Unmap functions.
01632      */
01633     unsigned short      width; 
01634     unsigned short      height;
01635     unsigned int        data_size;
01636     unsigned int        num_planes;     /* can not be greater than 3 */
01637     /* 
01638      * An array indicating the scanline pitch in bytes for each plane.
01639      * Each plane may have a different pitch. Maximum 3 planes for planar formats
01640      */
01641     unsigned int        pitches[3];
01642     /* 
01643      * An array indicating the byte offset from the beginning of the image data 
01644      * to the start of each plane.
01645      */
01646     unsigned int        offsets[3];
01647 
01648     /* The following fields are only needed for paletted formats */
01649     int num_palette_entries;   /* set to zero for non-palette images */
01650     /* 
01651      * Each component is one byte and entry_bytes indicates the number of components in 
01652      * each entry (eg. 3 for YUV palette entries). set to zero for non-palette images   
01653      */
01654     int entry_bytes; 
01655     /*
01656      * An array of ascii characters describing the order of the components within the bytes.
01657      * Only entry_bytes characters of the string are used.
01658      */
01659     char component_order[4];
01660 } VAImage;
01661 
01662 /* Get maximum number of image formats supported by the implementation */
01663 int vaMaxNumImageFormats (
01664     VADisplay dpy
01665 );
01666 
01667 /* 
01668  * Query supported image formats 
01669  * The caller must provide a "format_list" array that can hold at
01670  * least vaMaxNumImageFormats() entries. The actual number of formats
01671  * returned in "format_list" is returned in "num_formats".
01672  */
01673 VAStatus vaQueryImageFormats (
01674     VADisplay dpy,
01675     VAImageFormat *format_list, /* out */
01676     int *num_formats            /* out */
01677 );
01678 
01679 /* 
01680  * Create a VAImage structure
01681  * The width and height fields returned in the VAImage structure may get 
01682  * enlarged for some YUV formats. Upon return from this function, 
01683  * image->buf has been created and proper storage allocated by the library. 
01684  * The client can access the image through the Map/Unmap calls.
01685  */
01686 VAStatus vaCreateImage (
01687     VADisplay dpy,
01688     VAImageFormat *format,
01689     int width,
01690     int height,
01691     VAImage *image      /* out */
01692 );
01693 
01694 /*
01695  * Should call DestroyImage before destroying the surface it is bound to
01696  */
01697 VAStatus vaDestroyImage (
01698     VADisplay dpy,
01699     VAImageID image
01700 );
01701 
01702 VAStatus vaSetImagePalette (
01703     VADisplay dpy,
01704     VAImageID image,
01705     /* 
01706      * pointer to an array holding the palette data.  The size of the array is 
01707      * num_palette_entries * entry_bytes in size.  The order of the components 
01708      * in the palette is described by the component_order in VAImage struct    
01709      */
01710     unsigned char *palette 
01711 );
01712 
01713 /*
01714  * Retrive surface data into a VAImage
01715  * Image must be in a format supported by the implementation
01716  */
01717 VAStatus vaGetImage (
01718     VADisplay dpy,
01719     VASurfaceID surface,
01720     int x,      /* coordinates of the upper left source pixel */
01721     int y,
01722     unsigned int width, /* width and height of the region */
01723     unsigned int height,
01724     VAImageID image
01725 );
01726 
01727 /*
01728  * Copy data from a VAImage to a surface
01729  * Image must be in a format supported by the implementation
01730  * Returns a VA_STATUS_ERROR_SURFACE_BUSY if the surface
01731  * shouldn't be rendered into when this is called
01732  */
01733 VAStatus vaPutImage (
01734     VADisplay dpy,
01735     VASurfaceID surface,
01736     VAImageID image,
01737     int src_x,
01738     int src_y,
01739     unsigned int src_width,
01740     unsigned int src_height,
01741     int dest_x,
01742     int dest_y,
01743     unsigned int dest_width,
01744     unsigned int dest_height
01745 );
01746 
01747 /*
01748  * Derive an VAImage from an existing surface.
01749  * This interface will derive a VAImage and corresponding image buffer from
01750  * an existing VA Surface. The image buffer can then be mapped/unmapped for
01751  * direct CPU access. This operation is only possible on implementations with
01752  * direct rendering capabilities and internal surface formats that can be
01753  * represented with a VAImage. When the operation is not possible this interface
01754  * will return VA_STATUS_ERROR_OPERATION_FAILED. Clients should then fall back
01755  * to using vaCreateImage + vaPutImage to accomplish the same task in an
01756  * indirect manner.
01757  *
01758  * Implementations should only return success when the resulting image buffer
01759  * would be useable with vaMap/Unmap.
01760  *
01761  * When directly accessing a surface special care must be taken to insure
01762  * proper synchronization with the graphics hardware. Clients should call
01763  * vaQuerySurfaceStatus to insure that a surface is not the target of concurrent
01764  * rendering or currently being displayed by an overlay.
01765  *
01766  * Additionally nothing about the contents of a surface should be assumed
01767  * following a vaPutSurface. Implementations are free to modify the surface for
01768  * scaling or subpicture blending within a call to vaPutImage.
01769  *
01770  * Calls to vaPutImage or vaGetImage using the same surface from which the image
01771  * has been derived will return VA_STATUS_ERROR_SURFACE_BUSY. vaPutImage or
01772  * vaGetImage with other surfaces is supported.
01773  *
01774  * An image created with vaDeriveImage should be freed with vaDestroyImage. The
01775  * image and image buffer structures will be destroyed; however, the underlying
01776  * surface will remain unchanged until freed with vaDestroySurfaces.
01777  */
01778 VAStatus vaDeriveImage (
01779     VADisplay dpy,
01780     VASurfaceID surface,
01781     VAImage *image      /* out */
01782 );
01783 
01784 /*
01785  * Subpictures 
01786  * Subpicture is a special type of image that can be blended 
01787  * with a surface during vaPutSurface(). Subpicture can be used to render
01788  * DVD sub-titles or closed captioning text etc.  
01789  */
01790 
01791 typedef VAGenericID VASubpictureID;
01792 
01793 /* Get maximum number of subpicture formats supported by the implementation */
01794 int vaMaxNumSubpictureFormats (
01795     VADisplay dpy
01796 );
01797 
01798 /* flags for subpictures */
01799 #define VA_SUBPICTURE_CHROMA_KEYING                     0x0001
01800 #define VA_SUBPICTURE_GLOBAL_ALPHA                      0x0002
01801 #define VA_SUBPICTURE_DESTINATION_IS_SCREEN_COORD       0x0004
01802 /* 
01803  * Query supported subpicture formats 
01804  * The caller must provide a "format_list" array that can hold at
01805  * least vaMaxNumSubpictureFormats() entries. The flags arrary holds the flag 
01806  * for each format to indicate additional capabilities for that format. The actual 
01807  * number of formats returned in "format_list" is returned in "num_formats".
01808  *  flags: returned value to indicate addtional capabilities
01809  *         VA_SUBPICTURE_CHROMA_KEYING - supports chroma-keying
01810  *         VA_SUBPICTURE_GLOBAL_ALPHA - supports global alpha
01811  *         VA_SUBPICTURE_DESTINATION_IS_SCREEN_COORD - supports unscaled screen relative subpictures for On Screen Display
01812  */
01813 
01814 VAStatus vaQuerySubpictureFormats (
01815     VADisplay dpy,
01816     VAImageFormat *format_list, /* out */
01817     unsigned int *flags,        /* out */
01818     unsigned int *num_formats   /* out */
01819 );
01820 
01821 /* 
01822  * Subpictures are created with an image associated. 
01823  */
01824 VAStatus vaCreateSubpicture (
01825     VADisplay dpy,
01826     VAImageID image,
01827     VASubpictureID *subpicture  /* out */
01828 );
01829 
01830 /*
01831  * Destroy the subpicture before destroying the image it is assocated to
01832  */
01833 VAStatus vaDestroySubpicture (
01834     VADisplay dpy,
01835     VASubpictureID subpicture
01836 );
01837 
01838 /* 
01839  * Bind an image to the subpicture. This image will now be associated with 
01840  * the subpicture instead of the one at creation.
01841  */
01842 VAStatus vaSetSubpictureImage (
01843     VADisplay dpy,
01844     VASubpictureID subpicture,
01845     VAImageID image
01846 );
01847 
01848 /*
01849  * If chromakey is enabled, then the area where the source value falls within
01850  * the chromakey [min, max] range is transparent
01851  * The chromakey component format is the following:
01852  *  For RGB: [0:7] Red [8:15] Blue [16:23] Green   
01853  *  For YUV: [0:7] V [8:15] U [16:23] Y
01854  * The chromakey mask can be used to mask out certain components for chromakey
01855  * comparision
01856  */
01857 VAStatus vaSetSubpictureChromakey (
01858     VADisplay dpy,
01859     VASubpictureID subpicture,
01860     unsigned int chromakey_min,
01861     unsigned int chromakey_max,
01862     unsigned int chromakey_mask
01863 );
01864 
01865 /*
01866  * Global alpha value is between 0 and 1. A value of 1 means fully opaque and 
01867  * a value of 0 means fully transparent. If per-pixel alpha is also specified then
01868  * the overall alpha is per-pixel alpha multiplied by the global alpha
01869  */
01870 VAStatus vaSetSubpictureGlobalAlpha (
01871     VADisplay dpy,
01872     VASubpictureID subpicture,
01873     float global_alpha 
01874 );
01875 
01876 /*
01877  * vaAssociateSubpicture associates the subpicture with target_surfaces.
01878  * It defines the region mapping between the subpicture and the target  
01879  * surfaces through source and destination rectangles (with the same width and height).
01880  * Both will be displayed at the next call to vaPutSurface.  Additional
01881  * associations before the call to vaPutSurface simply overrides the association.
01882  */
01883 VAStatus vaAssociateSubpicture (
01884     VADisplay dpy,
01885     VASubpictureID subpicture,
01886     VASurfaceID *target_surfaces,
01887     int num_surfaces,
01888     short src_x, /* upper left offset in subpicture */
01889     short src_y,
01890     unsigned short src_width,
01891     unsigned short src_height,
01892     short dest_x, /* upper left offset in surface */
01893     short dest_y,
01894     unsigned short dest_width,
01895     unsigned short dest_height,
01896     /*
01897      * whether to enable chroma-keying, global-alpha, or screen relative mode
01898      * see VA_SUBPICTURE_XXX values
01899      */
01900     unsigned int flags
01901 );
01902 
01903 /*
01904  * vaDeassociateSubpicture removes the association of the subpicture with target_surfaces.
01905  */
01906 VAStatus vaDeassociateSubpicture (
01907     VADisplay dpy,
01908     VASubpictureID subpicture,
01909     VASurfaceID *target_surfaces,
01910     int num_surfaces
01911 );
01912 
01913 typedef struct _VARectangle
01914 {
01915     short x;
01916     short y;
01917     unsigned short width;
01918     unsigned short height;
01919 } VARectangle;
01920 
01921 /*
01922  * Display attributes
01923  * Display attributes are used to control things such as contrast, hue, saturation,
01924  * brightness etc. in the rendering process.  The application can query what
01925  * attributes are supported by the driver, and then set the appropriate attributes
01926  * before calling vaPutSurface()
01927  */
01928 /* PowerVR IEP Lite attributes */
01929 typedef enum
01930 {
01931     VADISPLAYATTRIB_BLE_OFF              = 0x00,
01932     VADISPLAYATTRIB_BLE_LOW,
01933     VADISPLAYATTRIB_BLE_MEDIUM,
01934     VADISPLAYATTRIB_BLE_HIGH,
01935     VADISPLAYATTRIB_BLE_NONE,
01936 } VADisplayAttribBLEMode;
01937 
01938 /* attribute value for VADisplayAttribRotation   */
01939 #define VA_ROTATION_NONE        0x00000000
01940 #define VA_ROTATION_90          0x00000001
01941 #define VA_ROTATION_180         0x00000002
01942 #define VA_ROTATION_270         0x00000003
01943 
01944 /* attribute value for VADisplayAttribOutOfLoopDeblock */
01945 #define VA_OOL_DEBLOCKING_FALSE 0x00000000
01946 #define VA_OOL_DEBLOCKING_TRUE  0x00000001
01947 
01948 /* Render mode */
01949 #define VA_RENDER_MODE_UNDEFINED           0
01950 #define VA_RENDER_MODE_LOCAL_OVERLAY       1
01951 #define VA_RENDER_MODE_LOCAL_GPU           2
01952 #define VA_RENDER_MODE_EXTERNAL_OVERLAY    4
01953 #define VA_RENDER_MODE_EXTERNAL_GPU        8
01954 
01955 /* Render device */
01956 #define VA_RENDER_DEVICE_UNDEFINED  0
01957 #define VA_RENDER_DEVICE_LOCAL      1
01958 #define VA_RENDER_DEVICE_EXTERNAL   2
01959 
01960 /* Currently defined display attribute types */
01961 typedef enum
01962 {
01963     VADisplayAttribBrightness           = 0,
01964     VADisplayAttribContrast             = 1,
01965     VADisplayAttribHue                  = 2,
01966     VADisplayAttribSaturation           = 3,
01967     /* client can specifiy a background color for the target window
01968      * the new feature of video conference,
01969      * the uncovered area of the surface is filled by this color
01970      * also it will blend with the decoded video color
01971      */
01972     VADisplayAttribBackgroundColor      = 4,
01973     /*
01974      * this is a gettable only attribute. For some implementations that use the
01975      * hardware overlay, after PutSurface is called, the surface can not be    
01976      * re-used until after the subsequent PutSurface call. If this is the case 
01977      * then the value for this attribute will be set to 1 so that the client   
01978      * will not attempt to re-use the surface right after returning from a call
01979      * to PutSurface.
01980      *
01981      * Don't use it, use flag VASurfaceDisplaying of vaQuerySurfaceStatus since
01982      * driver may use overlay or GPU alternatively
01983      */
01984     VADisplayAttribDirectSurface       = 5,
01985     VADisplayAttribRotation            = 6,     
01986     VADisplayAttribOutofLoopDeblock    = 7,
01987 
01988     /* PowerVR IEP Lite specific attributes */
01989     VADisplayAttribBLEBlackMode        = 8,
01990     VADisplayAttribBLEWhiteMode        = 9,
01991     VADisplayAttribBlueStretch         = 10,
01992     VADisplayAttribSkinColorCorrection = 11,
01993     /*
01994      * For type VADisplayAttribCSCMatrix, "value" field is a pointer to the color
01995      * conversion matrix. Each element in the matrix is float-point
01996      */
01997     VADisplayAttribCSCMatrix           = 12,
01998     /* specify the constant color used to blend with video surface
01999      * Cd = Cv*Cc*Ac + Cb *(1 - Ac) C means the constant RGB
02000      *      d: the final color to overwrite into the frame buffer 
02001      *      v: decoded video after color conversion, 
02002      *      c: video color specified by VADisplayAttribBlendColor
02003      *      b: background color of the drawable
02004      */
02005     VADisplayAttribBlendColor          = 13,
02006     /*
02007      * Indicate driver to skip painting color key or not.
02008      * only applicable if the render is overlay
02009      */
02010     VADisplayAttribOverlayAutoPaintColorKey   = 14,
02011     /*
02012      * customized overlay color key, the format is RGB888
02013      * [23:16] = Red, [15:08] = Green, [07:00] = Blue.
02014      */
02015     VADisplayAttribOverlayColorKey      = 15,
02016     /*
02017      * The hint for the implementation of vaPutSurface
02018      * normally, the driver could use an overlay or GPU to render the surface on the screen
02019      * this flag provides APP the flexibity to switch the render dynamically
02020      */
02021     VADisplayAttribRenderMode           = 16,
02022     /*
02023      * specify if vaPutSurface needs to render into specified monitors
02024      * one example is that one external monitor (e.g. HDMI) is enabled, 
02025      * but the window manager is not aware of it, and there is no associated drawable
02026      */
02027     VADisplayAttribRenderDevice        = 17,
02028     /*
02029      * specify vaPutSurface render area if there is no drawable on the monitor
02030      */
02031     VADisplayAttribRenderRect          = 18,
02032 } VADisplayAttribType;
02033 
02034 /* flags for VADisplayAttribute */
02035 #define VA_DISPLAY_ATTRIB_NOT_SUPPORTED 0x0000
02036 #define VA_DISPLAY_ATTRIB_GETTABLE      0x0001
02037 #define VA_DISPLAY_ATTRIB_SETTABLE      0x0002
02038 
02039 typedef struct _VADisplayAttribute
02040 {
02041     VADisplayAttribType type;
02042     int min_value;
02043     int max_value;
02044     int value;  /* used by the set/get attribute functions */
02045 /* flags can be VA_DISPLAY_ATTRIB_GETTABLE or VA_DISPLAY_ATTRIB_SETTABLE or OR'd together */
02046     unsigned int flags;
02047 } VADisplayAttribute;
02048 
02049 /* Get maximum number of display attributs supported by the implementation */
02050 int vaMaxNumDisplayAttributes (
02051     VADisplay dpy
02052 );
02053 
02054 /* 
02055  * Query display attributes 
02056  * The caller must provide a "attr_list" array that can hold at
02057  * least vaMaxNumDisplayAttributes() entries. The actual number of attributes
02058  * returned in "attr_list" is returned in "num_attributes".
02059  */
02060 VAStatus vaQueryDisplayAttributes (
02061     VADisplay dpy,
02062     VADisplayAttribute *attr_list,      /* out */
02063     int *num_attributes                 /* out */
02064 );
02065 
02066 /* 
02067  * Get display attributes 
02068  * This function returns the current attribute values in "attr_list".
02069  * Only attributes returned with VA_DISPLAY_ATTRIB_GETTABLE set in the "flags" field
02070  * from vaQueryDisplayAttributes() can have their values retrieved.  
02071  */
02072 VAStatus vaGetDisplayAttributes (
02073     VADisplay dpy,
02074     VADisplayAttribute *attr_list,      /* in/out */
02075     int num_attributes
02076 );
02077 
02078 /* 
02079  * Set display attributes 
02080  * Only attributes returned with VA_DISPLAY_ATTRIB_SETTABLE set in the "flags" field
02081  * from vaQueryDisplayAttributes() can be set.  If the attribute is not settable or 
02082  * the value is out of range, the function returns VA_STATUS_ERROR_ATTR_NOT_SUPPORTED
02083  */
02084 VAStatus vaSetDisplayAttributes (
02085     VADisplay dpy,
02086     VADisplayAttribute *attr_list,
02087     int num_attributes
02088 );
02089 
02092 #ifdef __cplusplus
02093 }
02094 #endif
02095 
02096 #endif /* _VA_H_ */
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines