API: h264 encode: fix comments.
[platform/upstream/libva.git] / va / va.h
1 /*
2  * Copyright (c) 2007-2009 Intel Corporation. All Rights Reserved.
3  *
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:
11  * 
12  * The above copyright notice and this permission notice (including the
13  * next paragraph) shall be included in all copies or substantial portions
14  * of the Software.
15  * 
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 INTEL 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.
23  */
24 /*
25  * Video Acceleration (VA) API Specification
26  *
27  * Rev. 0.30
28  * <jonathan.bian@intel.com>
29  *
30  * Revision History:
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 
51  *                                       to enable scaling
52  * rev 0.29 (02/07/2008 Jonathan Bian) - VC1 parameter fixes,
53  *                                       added VA_STATUS_ERROR_RESOLUTION_NOT_SUPPORTED
54  * rev 0.30 (03/01/2009 Jonathan Bian) - Added encoding support for H.264 BP and MPEG-4 SP and fixes
55  *                                       for ISO C conformance.
56  * rev 0.31 (09/02/2009 Gwenole Beauchesne) - VC-1/H264 fields change for VDPAU and XvBA backend
57  *                                       Application needs to relink with the new library.
58  *
59  * rev 0.31.1 (03/29/2009)              - Data structure for JPEG encode
60  * rev 0.31.2 (01/13/2011 Anthony Pabon)- Added a flag to indicate Subpicture coordinates are screen
61  *                                        screen relative rather than source video relative.
62  * rev 0.32.0 (01/13/2011 Xiang Haihao) - Add profile into VAPictureParameterBufferVC1
63  *                                        update VAAPI to 0.32.0
64  *
65  * Acknowledgements:
66  *  Some concepts borrowed from XvMC and XvImage.
67  *  Waldo Bastian (Intel), Matt Sottek (Intel),  Austin Yuan (Intel), and Gwenole Beauchesne (SDS)
68  *  contributed to various aspects of the API.
69  */
70
71 #ifndef _VA_H_
72 #define _VA_H_
73
74 #include <va/va_version.h>
75
76 #ifdef __cplusplus
77 extern "C" {
78 #endif
79
80 /* 
81 Overview 
82
83 The VA API is intended to provide an interface between a video decode/encode/display
84 application (client) and a hardware accelerator (server), to off-load 
85 video decode/encode/display operations from the host to the hardware accelerator at various 
86 entry-points.
87
88 The basic operation steps are:
89
90 - Negotiate a mutually acceptable configuration with the server to lock
91   down profile, entrypoints, and other attributes that will not change on 
92   a frame-by-frame basis.
93 - Create a decode context which represents a "virtualized" hardware decode 
94   device
95 - Get and fill decode buffers with picture level, slice level and macroblock 
96   level data (depending on entrypoints)
97 - Pass the decode buffers to the server to decode the current frame
98
99 Initialization & Configuration Management 
100
101 - Find out supported profiles
102 - Find out entrypoints for a given profile
103 - Find out configuration attributes for a given profile/entrypoint pair
104 - Create a configuration for use by the decoder
105
106 */
107
108 typedef void* VADisplay;        /* window system dependent */
109
110 typedef int VAStatus;   /* Return status type from functions */
111 /* Values for the return status */
112 #define VA_STATUS_SUCCESS                       0x00000000
113 #define VA_STATUS_ERROR_OPERATION_FAILED        0x00000001
114 #define VA_STATUS_ERROR_ALLOCATION_FAILED       0x00000002
115 #define VA_STATUS_ERROR_INVALID_DISPLAY         0x00000003
116 #define VA_STATUS_ERROR_INVALID_CONFIG          0x00000004
117 #define VA_STATUS_ERROR_INVALID_CONTEXT         0x00000005
118 #define VA_STATUS_ERROR_INVALID_SURFACE         0x00000006
119 #define VA_STATUS_ERROR_INVALID_BUFFER          0x00000007
120 #define VA_STATUS_ERROR_INVALID_IMAGE           0x00000008
121 #define VA_STATUS_ERROR_INVALID_SUBPICTURE      0x00000009
122 #define VA_STATUS_ERROR_ATTR_NOT_SUPPORTED      0x0000000a
123 #define VA_STATUS_ERROR_MAX_NUM_EXCEEDED        0x0000000b
124 #define VA_STATUS_ERROR_UNSUPPORTED_PROFILE     0x0000000c
125 #define VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT  0x0000000d
126 #define VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT   0x0000000e
127 #define VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE  0x0000000f
128 #define VA_STATUS_ERROR_SURFACE_BUSY            0x00000010
129 #define VA_STATUS_ERROR_FLAG_NOT_SUPPORTED      0x00000011
130 #define VA_STATUS_ERROR_INVALID_PARAMETER       0x00000012
131 #define VA_STATUS_ERROR_RESOLUTION_NOT_SUPPORTED 0x00000013
132 #define VA_STATUS_ERROR_UNIMPLEMENTED           0x00000014
133 #define VA_STATUS_ERROR_SURFACE_IN_DISPLAYING   0x00000015
134 #define VA_STATUS_ERROR_INVALID_IMAGE_FORMAT    0x00000016
135 #define VA_STATUS_ERROR_DECODING_ERROR          0x00000017
136 #define VA_STATUS_ERROR_ENCODING_ERROR          0x00000018
137 /**
138  * \brief An invalid/unsupported value was supplied.
139  *
140  * This is a catch-all error code for invalid or unsupported values.
141  * e.g. value exceeding the valid range, invalid type in the context
142  * of generic attribute values.
143  */
144 #define VA_STATUS_ERROR_INVALID_VALUE           0x00000019
145 #define VA_STATUS_ERROR_UNKNOWN                 0xFFFFFFFF
146
147 /* De-interlacing flags for vaPutSurface() */
148 #define VA_FRAME_PICTURE        0x00000000 
149 #define VA_TOP_FIELD            0x00000001
150 #define VA_BOTTOM_FIELD         0x00000002
151
152 /*
153  * Enabled the positioning/cropping/blending feature:
154  * 1, specify the video playback position in the isurface
155  * 2, specify the cropping info for video playback
156  * 3, encoded video will blend with background color
157  */
158 #define VA_ENABLE_BLEND         0x00000004 /* video area blend with the constant color */ 
159     
160 /*
161  * Clears the drawable with background color.
162  * for hardware overlay based implementation this flag
163  * can be used to turn off the overlay
164  */
165 #define VA_CLEAR_DRAWABLE       0x00000008
166
167 /* Color space conversion flags for vaPutSurface() */
168 #define VA_SRC_BT601            0x00000010
169 #define VA_SRC_BT709            0x00000020
170 #define VA_SRC_SMPTE_240        0x00000040
171
172 /* Scaling flags for vaPutSurface() */
173 #define VA_FILTER_SCALING_DEFAULT       0x00000000
174 #define VA_FILTER_SCALING_FAST          0x00000100
175 #define VA_FILTER_SCALING_HQ            0x00000200
176 #define VA_FILTER_SCALING_NL_ANAMORPHIC 0x00000300
177 #define VA_FILTER_SCALING_MASK          0x00000f00
178
179 /*
180  * Returns a short english description of error_status
181  */
182 const char *vaErrorStr(VAStatus error_status);
183
184 /*
185  * Initialization:
186  * A display must be obtained by calling vaGetDisplay() before calling
187  * vaInitialize() and other functions. This connects the API to the 
188  * native window system.
189  * For X Windows, native_dpy would be from XOpenDisplay()
190  */
191 typedef void* VANativeDisplay;  /* window system dependent */
192
193 int vaDisplayIsValid(VADisplay dpy);
194     
195 /*
196  * Initialize the library 
197  */
198 VAStatus vaInitialize (
199     VADisplay dpy,
200     int *major_version,  /* out */
201     int *minor_version   /* out */
202 );
203
204 /*
205  * After this call, all library internal resources will be cleaned up
206  */ 
207 VAStatus vaTerminate (
208     VADisplay dpy
209 );
210
211 /*
212  * vaQueryVendorString returns a pointer to a zero-terminated string
213  * describing some aspects of the VA implemenation on a specific    
214  * hardware accelerator. The format of the returned string is vendor
215  * specific and at the discretion of the implementer.
216  * e.g. for the Intel GMA500 implementation, an example would be:
217  * "Intel GMA500 - 2.0.0.32L.0005"
218  */
219 const char *vaQueryVendorString (
220     VADisplay dpy
221 );
222
223 typedef int (*VAPrivFunc)();
224
225 /*
226  * Return a function pointer given a function name in the library.
227  * This allows private interfaces into the library
228  */ 
229 VAPrivFunc vaGetLibFunc (
230     VADisplay dpy,
231     const char *func
232 );
233
234 /* Currently defined profiles */
235 typedef enum
236 {
237     VAProfileMPEG2Simple                = 0,
238     VAProfileMPEG2Main                  = 1,
239     VAProfileMPEG4Simple                = 2,
240     VAProfileMPEG4AdvancedSimple        = 3,
241     VAProfileMPEG4Main                  = 4,
242     VAProfileH264Baseline               = 5,
243     VAProfileH264Main                   = 6,
244     VAProfileH264High                   = 7,
245     VAProfileVC1Simple                  = 8,
246     VAProfileVC1Main                    = 9,
247     VAProfileVC1Advanced                = 10,
248     VAProfileH263Baseline               = 11,
249     VAProfileJPEGBaseline               = 12,
250     VAProfileH264ConstrainedBaseline = 13
251 } VAProfile;
252
253 /* 
254  *  Currently defined entrypoints 
255  */
256 typedef enum
257 {
258     VAEntrypointVLD             = 1,
259     VAEntrypointIZZ             = 2,
260     VAEntrypointIDCT            = 3,
261     VAEntrypointMoComp          = 4,
262     VAEntrypointDeblocking      = 5,
263     VAEntrypointEncSlice        = 6,    /* slice level encode */
264     VAEntrypointEncPicture      = 7     /* pictuer encode, JPEG, etc */
265 } VAEntrypoint;
266
267 /* Currently defined configuration attribute types */
268 typedef enum
269 {
270     VAConfigAttribRTFormat              = 0,
271     VAConfigAttribSpatialResidual       = 1,
272     VAConfigAttribSpatialClipping       = 2,
273     VAConfigAttribIntraResidual         = 3,
274     VAConfigAttribEncryption            = 4,
275     VAConfigAttribRateControl           = 5,
276
277     /** @name Attributes for encoding */
278     /**@{*/
279     /**
280      * \brief Packed headers mode. Read/write.
281      *
282      * This attribute determines what packed headers the driver supports,
283      * through vaGetConfigAttributes(); and what packed headers the user
284      * will be providing to the driver, through vaCreateConfig(), if the
285      * driver supports those.
286      *
287      * See \c VA_ENC_PACKED_HEADER_xxx for the list of packed headers.
288      */
289     VAConfigAttribEncPackedHeaders      = 10,
290     /**
291      * \brief Interlaced mode. Read/write.
292      *
293      * This attribute determines what kind of interlaced encoding mode
294      * the driver supports.
295      *
296      * See \c VA_ENC_INTERLACED_xxx for the list of interlaced modes.
297      */
298     VAConfigAttribEncInterlaced         = 11,
299     /**
300      * \brief Maximum number of reference frames. Read-only.
301      *
302      * This attribute determines the maximum number of reference
303      * frames supported for encoding.
304      *
305      * Note: for H.264 encoding, the value represents the maximum
306      * number of reference frames for both the reference picture list
307      * 0 (top 16 bits) and the reference picture list 1 (bottom 16
308      * bits).
309      */
310     VAConfigAttribEncMaxRefFrames       = 13,
311     /**
312      * \brief Maximum number of slices per frame. Read-only.
313      *
314      * This attribute determines the maximum number of slices the
315      * driver can support to encode a single frame.
316      */
317     VAConfigAttribEncMaxSlices          = 14,
318     /**
319      * \brief Slice structure. Read-only.
320      *
321      * This attribute determines slice structures supported by the
322      * driver for encoding. This attribute is a hint to the user so
323      * that he can choose a suitable surface size and how to arrange
324      * the encoding process of multiple slices per frame.
325      *
326      * More specifically, for H.264 encoding, this attribute
327      * determines the range of accepted values to
328      * VAEncSliceParameterBufferH264::macroblock_address and
329      * VAEncSliceParameterBufferH264::num_macroblocks.
330      *
331      * See \c VA_ENC_SLICE_STRUCTURE_xxx for the supported slice
332      * structure types.
333      */
334     VAConfigAttribEncSliceStructure     = 15,
335     /**@}*/
336 } VAConfigAttribType;
337
338 /*
339  * Configuration attributes
340  * If there is more than one value for an attribute, a default
341  * value will be assigned to the attribute if the client does not
342  * specify the attribute when creating a configuration
343  */
344 typedef struct _VAConfigAttrib {
345     VAConfigAttribType type;
346     unsigned int value; /* OR'd flags (bits) for this attribute */
347 } VAConfigAttrib;
348
349 /* attribute value for VAConfigAttribRTFormat */
350 #define VA_RT_FORMAT_YUV420     0x00000001      
351 #define VA_RT_FORMAT_YUV422     0x00000002
352 #define VA_RT_FORMAT_YUV444     0x00000004
353 #define VA_RT_FORMAT_PROTECTED  0x80000000
354
355 /* attribute value for VAConfigAttribRateControl */
356 #define VA_RC_NONE      0x00000001      
357 #define VA_RC_CBR       0x00000002      
358 #define VA_RC_VBR       0x00000004      
359 #define VA_RC_VCM       0x00000008 /* video conference mode */
360
361 /** @name Attribute values for VAConfigAttribEncPackedHeaders */
362 /**@{*/
363 /** \brief Driver does not support any packed headers mode. */
364 #define VA_ENC_PACKED_HEADER_NONE       0x00000000
365 /** \brief Driver supports packed sequence headers. e.g. SPS for H.264. */
366 #define VA_ENC_PACKED_HEADER_SEQUENCE   0x00000001
367 /** \brief Driver supports packed picture headers. e.g. PPS for H.264. */
368 #define VA_ENC_PACKED_HEADER_PICTURE    0x00000002
369 /** \brief Driver supports packed slice headers. e.g. \c slice_header() for H.264. */
370 #define VA_ENC_PACKED_HEADER_SLICE      0x00000004
371 /**@}*/
372
373 /** @name Attribute values for VAConfigAttribEncInterlaced */
374 /**@{*/
375 /** \brief Driver does not support interlaced coding. */
376 #define VA_ENC_INTERLACED_NONE          0x00000000
377 /** \brief Driver supports interlaced frame coding. */
378 #define VA_ENC_INTERLACED_FRAME         0x00000001
379 /** \brief Driver supports interlaced field coding. */
380 #define VA_ENC_INTERLACED_FIELD         0x00000002
381 /** \brief Driver supports macroblock adaptive frame field coding. */
382 #define VA_ENC_INTERLACED_MBAFF         0x00000004
383 /** \brief Driver supports picture adaptive frame field coding. */
384 #define VA_ENC_INTERLACED_PAFF          0x00000008
385 /**@}*/
386
387 /** @name Attribute values for VAConfigAttribEncSliceStructure */
388 /**@{*/
389 /** \brief Driver supports an arbitrary number of rows per slice. */
390 #define VA_ENC_SLICE_STRUCTURE_ARBITRARY_ROWS           0x00000000
391 /** \brief Driver supports a power-of-two number of rows per slice. */
392 #define VA_ENC_SLICE_STRUCTURE_POWER_OF_TWO_ROWS        0x00000001
393 /** \brief Driver supports an arbitrary number of rows per slice. */
394 #define VA_ENC_SLICE_STRUCTURE_ARBITRARY_MACROBLOCKS    0x00000002
395 /**@}*/
396
397 /*
398  * if an attribute is not applicable for a given
399  * profile/entrypoint pair, then set the value to the following 
400  */
401 #define VA_ATTRIB_NOT_SUPPORTED 0x80000000
402
403 /* Get maximum number of profiles supported by the implementation */
404 int vaMaxNumProfiles (
405     VADisplay dpy
406 );
407
408 /* Get maximum number of entrypoints supported by the implementation */
409 int vaMaxNumEntrypoints (
410     VADisplay dpy
411 );
412
413 /* Get maximum number of attributs supported by the implementation */
414 int vaMaxNumConfigAttributes (
415     VADisplay dpy
416 );
417
418 /* 
419  * Query supported profiles 
420  * The caller must provide a "profile_list" array that can hold at
421  * least vaMaxNumProfile() entries. The actual number of profiles
422  * returned in "profile_list" is returned in "num_profile".
423  */
424 VAStatus vaQueryConfigProfiles (
425     VADisplay dpy,
426     VAProfile *profile_list,    /* out */
427     int *num_profiles           /* out */
428 );
429
430 /* 
431  * Query supported entrypoints for a given profile 
432  * The caller must provide an "entrypoint_list" array that can hold at
433  * least vaMaxNumEntrypoints() entries. The actual number of entrypoints 
434  * returned in "entrypoint_list" is returned in "num_entrypoints".
435  */
436 VAStatus vaQueryConfigEntrypoints (
437     VADisplay dpy,
438     VAProfile profile,
439     VAEntrypoint *entrypoint_list,      /* out */
440     int *num_entrypoints                /* out */
441 );
442
443 /* 
444  * Get attributes for a given profile/entrypoint pair 
445  * The caller must provide an "attrib_list" with all attributes to be 
446  * retrieved.  Upon return, the attributes in "attrib_list" have been 
447  * updated with their value.  Unknown attributes or attributes that are 
448  * not supported for the given profile/entrypoint pair will have their 
449  * value set to VA_ATTRIB_NOT_SUPPORTED
450  */
451 VAStatus vaGetConfigAttributes (
452     VADisplay dpy,
453     VAProfile profile,
454     VAEntrypoint entrypoint,
455     VAConfigAttrib *attrib_list, /* in/out */
456     int num_attribs
457 );
458
459 /* Generic ID type, can be re-typed for specific implementation */
460 typedef unsigned int VAGenericID;
461
462 typedef VAGenericID VAConfigID;
463
464 /* 
465  * Create a configuration for the decode pipeline 
466  * it passes in the attribute list that specifies the attributes it cares 
467  * about, with the rest taking default values.  
468  */
469 VAStatus vaCreateConfig (
470     VADisplay dpy,
471     VAProfile profile, 
472     VAEntrypoint entrypoint, 
473     VAConfigAttrib *attrib_list,
474     int num_attribs,
475     VAConfigID *config_id /* out */
476 );
477
478 /* 
479  * Free resources associdated with a given config 
480  */
481 VAStatus vaDestroyConfig (
482     VADisplay dpy,
483     VAConfigID config_id
484 );
485
486 /* 
487  * Query all attributes for a given configuration 
488  * The profile of the configuration is returned in "profile"
489  * The entrypoint of the configuration is returned in "entrypoint"
490  * The caller must provide an "attrib_list" array that can hold at least 
491  * vaMaxNumConfigAttributes() entries. The actual number of attributes 
492  * returned in "attrib_list" is returned in "num_attribs"
493  */
494 VAStatus vaQueryConfigAttributes (
495     VADisplay dpy,
496     VAConfigID config_id, 
497     VAProfile *profile,         /* out */
498     VAEntrypoint *entrypoint,   /* out */
499     VAConfigAttrib *attrib_list,/* out */
500     int *num_attribs            /* out */
501 );
502
503
504 /*
505  * Contexts and Surfaces
506  *
507  * Context represents a "virtual" video decode pipeline. Surfaces are render 
508  * targets for a given context. The data in the surfaces are not accessible  
509  * to the client and the internal data format of the surface is implementatin 
510  * specific. 
511  *
512  * Surfaces will be bound to a context when the context is created. Once
513  * a surface is bound to a given context, it can not be used to create  
514  * another context. The association is removed when the context is destroyed
515  * 
516  * Both contexts and surfaces are identified by unique IDs and its
517  * implementation specific internals are kept opaque to the clients
518  */
519
520 typedef VAGenericID VAContextID;
521
522 typedef VAGenericID VASurfaceID;
523
524 #define VA_INVALID_ID           0xffffffff
525 #define VA_INVALID_SURFACE      VA_INVALID_ID
526
527 /** \brief Generic value types. */
528 typedef enum  {
529     VAGenericValueTypeInteger = 1,      /**< 32-bit signed integer. */
530     VAGenericValueTypeFloat,            /**< 32-bit floating-point value. */
531     VAGenericValueTypePointer,          /**< Generic pointer type */
532     VAGenericValueTypeFunc              /**< Pointer to function */
533 } VAGenericValueType;
534
535 /** \brief Generic function type. */
536 typedef void (*VAGenericFunc)(void);
537
538 /** \brief Generic value. */
539 typedef struct _VAGenericValue {
540     /** \brief Value type. See #VAGenericValueType. */
541     VAGenericValueType  type;
542     /** \brief Value holder. */
543     union {
544         /** \brief 32-bit signed integer. */
545         int             i;
546         /** \brief 32-bit float. */
547         float           f;
548         /** \brief Generic pointer. */
549         void           *p;
550         /** \brief Pointer to function. */
551         VAGenericFunc   fn;
552     }                   value;
553 } VAGenericValue;
554
555 /* 
556  * vaCreateSurfaces - Create an array of surfaces used for decode and display  
557  *  dpy: display
558  *  width: surface width
559  *  height: surface height
560  *  format: VA_RT_FORMAT_YUV420, VA_RT_FORMAT_YUV422 or VA_RT_FORMAT_YUV444
561  *  num_surfaces: number of surfaces to be created
562  *  surfaces: array of surfaces created upon return
563  */
564 VAStatus vaCreateSurfaces (
565     VADisplay dpy,
566     int width,
567     int height,
568     int format,
569     int num_surfaces,
570     VASurfaceID *surfaces       /* out */
571 );
572
573     
574 /*
575  * vaDestroySurfaces - Destroy resources associated with surfaces. 
576  *  Surfaces can only be destroyed after the context associated has been 
577  *  destroyed.  
578  *  dpy: display
579  *  surfaces: array of surfaces to destroy
580  *  num_surfaces: number of surfaces in the array to be destroyed.
581  */
582 VAStatus vaDestroySurfaces (
583     VADisplay dpy,
584     VASurfaceID *surfaces,
585     int num_surfaces
586 );
587
588 #define VA_PROGRESSIVE 0x1
589 /*
590  * vaCreateContext - Create a context
591  *  dpy: display
592  *  config_id: configuration for the context
593  *  picture_width: coded picture width
594  *  picture_height: coded picture height
595  *  flag: any combination of the following:
596  *    VA_PROGRESSIVE (only progressive frame pictures in the sequence when set)
597  *  render_targets: render targets (surfaces) tied to the context
598  *  num_render_targets: number of render targets in the above array
599  *  context: created context id upon return
600  */
601 VAStatus vaCreateContext (
602     VADisplay dpy,
603     VAConfigID config_id,
604     int picture_width,
605     int picture_height,
606     int flag,
607     VASurfaceID *render_targets,
608     int num_render_targets,
609     VAContextID *context                /* out */
610 );
611
612 /*
613  * vaDestroyContext - Destroy a context 
614  *  dpy: display
615  *  context: context to be destroyed
616  */
617 VAStatus vaDestroyContext (
618     VADisplay dpy,
619     VAContextID context
620 );
621
622 /*
623  * Buffers 
624  * Buffers are used to pass various types of data from the
625  * client to the server. The server maintains a data store
626  * for each buffer created, and the client idenfies a buffer
627  * through a unique buffer id assigned by the server.
628  */
629
630 typedef VAGenericID VABufferID;
631
632 typedef enum
633 {
634     VAPictureParameterBufferType        = 0,
635     VAIQMatrixBufferType                = 1,
636     VABitPlaneBufferType                = 2,
637     VASliceGroupMapBufferType           = 3,
638     VASliceParameterBufferType          = 4,
639     VASliceDataBufferType               = 5,
640     VAMacroblockParameterBufferType     = 6,
641     VAResidualDataBufferType            = 7,
642     VADeblockingParameterBufferType     = 8,
643     VAImageBufferType                   = 9,
644     VAProtectedSliceDataBufferType      = 10,
645     VAQMatrixBufferType                 = 11,
646     VAHuffmanTableBufferType            = 12,
647
648 /* Following are encode buffer types */
649     VAEncCodedBufferType                = 21,
650     VAEncSequenceParameterBufferType    = 22,
651     VAEncPictureParameterBufferType     = 23,
652     VAEncSliceParameterBufferType       = 24,
653     VAEncPackedHeaderParameterBufferType = 25,
654     VAEncPackedHeaderDataBufferType     = 26,
655     VAEncMiscParameterBufferType        = 27,
656     VAEncMacroblockParameterBufferType  = 28,
657     VABufferTypeMax                     = 0xff
658 } VABufferType;
659
660 typedef enum
661 {
662     VAEncMiscParameterTypeFrameRate     = 0,
663     VAEncMiscParameterTypeRateControl   = 1,
664     VAEncMiscParameterTypeMaxSliceSize  = 2,
665     VAEncMiscParameterTypeAIR           = 3,
666 } VAEncMiscParameterType;
667
668 /** \brief Packed header type. */
669 typedef enum {
670     VAEncPackedHeaderSequence           = 1, /**< Packed sequence header. */
671     VAEncPackedHeaderPicture            = 2, /**< Packed picture header. */
672     VAEncPackedHeaderSlice              = 3, /**< Packed slice header. */
673 } VAEncPackedHeaderType;
674
675 /** \brief Packed header parameter. */
676 typedef struct _VAEncPackedHeaderParameterBuffer {
677     /** Type of the packed header buffer. See #VAEncPackedHeaderType. */
678     VAEncPackedHeaderType       type;
679     /** \brief Size of the #VAEncPackedHeaderDataBuffer in bits. */
680     unsigned int                bit_length;
681     /** \brief Flag: buffer contains start code emulation prevention bytes? */
682     unsigned char               has_emulation_bytes;
683 } VAEncPackedHeaderParameterBuffer;
684
685 /*
686  *  For application, e.g. set a new bitrate
687  *    VABufferID buf_id;
688  *    VAEncMiscParameterBuffer *misc_param;
689  *    VAEncMiscParameterRateControl *misc_rate_ctrl;
690  * 
691  *    vaCreateBuffer(dpy, context, VAEncMiscParameterBufferType,
692  *              sizeof(VAEncMiscParameterBuffer) + sizeof(VAEncMiscParameterRateControl),
693  *              1, NULL, &buf_id);
694  *
695  *    vaMapBuffer(dpy,buf_id,(void **)&misc_param);
696  *    misc_param->type = VAEncMiscParameterTypeRateControl;
697  *    misc_rate_ctrl= (VAEncMiscParameterRateControl *)misc_param->data;
698  *    misc_rate_ctrl->bits_per_second = 6400000;
699  *    vaUnmapBuffer(dpy, buf_id);
700  *    vaRenderPicture(dpy, context, &buf_id, 1);
701  */
702 typedef struct _VAEncMiscParameterBuffer
703 {
704     VAEncMiscParameterType type;
705     unsigned int data[0];
706 } VAEncMiscParameterBuffer;
707
708 typedef struct _VAEncMiscParameterRateControl
709 {
710     unsigned int bits_per_second; /* this is the maximum bit-rate to be constrained by the rate control implementation */
711     unsigned int target_percentage; /* this is the bit-rate the rate control is targeting, as a percentage of the maximum bit-rate */
712                                     /* for example if target_percentage is 95 then the rate control will target a bit-rate that is */
713                                     /* 95% of the maximum bit-rate */
714     unsigned int window_size; /* windows size in milliseconds. For example if this is set to 500, then the rate control will guarantee the */
715                               /* target bit-rate over a 500 ms window */
716     unsigned int initial_qp;  /* initial QP at I frames */
717     unsigned int min_qp;     
718 } VAEncMiscParameterRateControl;
719
720 typedef struct _VAEncMiscParameterFrameRate
721 {
722     unsigned int framerate;
723 } VAEncMiscParameterFrameRate;
724
725 /*
726  * Allow a maximum slice size to be specified (in bits).
727  * The encoder will attempt to make sure that individual slices do not exceed this size
728  * Or to signal applicate if the slice size exceed this size, see "status" of VACodedBufferSegment
729  */
730 typedef struct _VAEncMiscParameterMaxSliceSize
731 {
732     unsigned int max_slice_size;
733 } VAEncMiscParameterMaxSliceSize;
734
735 typedef struct _VAEncMiscParameterAIR
736 {
737     unsigned int air_num_mbs;
738     unsigned int air_threshold;
739     unsigned int air_auto; /* if set to 1 then hardware auto-tune the AIR threshold */
740 } VAEncMiscParameterAIR;
741
742
743 /* 
744  * There will be cases where the bitstream buffer will not have enough room to hold
745  * the data for the entire slice, and the following flags will be used in the slice
746  * parameter to signal to the server for the possible cases.
747  * If a slice parameter buffer and slice data buffer pair is sent to the server with 
748  * the slice data partially in the slice data buffer (BEGIN and MIDDLE cases below), 
749  * then a slice parameter and data buffer needs to be sent again to complete this slice. 
750  */
751 #define VA_SLICE_DATA_FLAG_ALL          0x00    /* whole slice is in the buffer */
752 #define VA_SLICE_DATA_FLAG_BEGIN        0x01    /* The beginning of the slice is in the buffer but the end if not */
753 #define VA_SLICE_DATA_FLAG_MIDDLE       0x02    /* Neither beginning nor end of the slice is in the buffer */
754 #define VA_SLICE_DATA_FLAG_END          0x04    /* end of the slice is in the buffer */
755
756 /* Codec-independent Slice Parameter Buffer base */
757 typedef struct _VASliceParameterBufferBase
758 {
759     unsigned int slice_data_size;       /* number of bytes in the slice data buffer for this slice */
760     unsigned int slice_data_offset;     /* the offset to the first byte of slice data */
761     unsigned int slice_data_flag;       /* see VA_SLICE_DATA_FLAG_XXX definitions */
762 } VASliceParameterBufferBase;
763
764
765 /****************************
766  * JEPG data structure
767  ***************************/
768 typedef struct _VAQMatrixBufferJPEG
769 {
770     int load_lum_quantiser_matrix;
771     int load_chroma_quantiser_matrix;
772     unsigned char lum_quantiser_matrix[64];
773     unsigned char chroma_quantiser_matrix[64];
774 } VAQMatrixBufferJPEG;
775
776 typedef struct _VAEncPictureParameterBufferJPEG
777 {
778     VASurfaceID reconstructed_picture;
779     unsigned short picture_width;
780     unsigned short picture_height;
781     VABufferID coded_buf;
782 } VAEncPictureParameterBufferJPEG;
783
784 #include <va/va_dec_jpeg.h>
785
786 /****************************
787  * MPEG-2 data structures
788  ****************************/
789  
790 /* MPEG-2 Picture Parameter Buffer */
791 /* 
792  * For each frame or field, and before any slice data, a single
793  * picture parameter buffer must be send.
794  */
795 typedef struct _VAPictureParameterBufferMPEG2
796 {
797     unsigned short horizontal_size;
798     unsigned short vertical_size;
799     VASurfaceID forward_reference_picture;
800     VASurfaceID backward_reference_picture;
801     /* meanings of the following fields are the same as in the standard */
802     int picture_coding_type;
803     int f_code; /* pack all four fcode into this */
804     union {
805         struct {
806             unsigned int intra_dc_precision             : 2; 
807             unsigned int picture_structure              : 2; 
808             unsigned int top_field_first                : 1; 
809             unsigned int frame_pred_frame_dct           : 1; 
810             unsigned int concealment_motion_vectors     : 1;
811             unsigned int q_scale_type                   : 1;
812             unsigned int intra_vlc_format               : 1;
813             unsigned int alternate_scan                 : 1;
814             unsigned int repeat_first_field             : 1;
815             unsigned int progressive_frame              : 1;
816             unsigned int is_first_field                 : 1; /* indicate whether the current field
817                                                               * is the first field for field picture
818                                                               */
819         } bits;
820         unsigned int value;
821     } picture_coding_extension;
822 } VAPictureParameterBufferMPEG2;
823
824 /* MPEG-2 Inverse Quantization Matrix Buffer */
825 typedef struct _VAIQMatrixBufferMPEG2
826 {
827     int load_intra_quantiser_matrix;
828     int load_non_intra_quantiser_matrix;
829     int load_chroma_intra_quantiser_matrix;
830     int load_chroma_non_intra_quantiser_matrix;
831     unsigned char intra_quantiser_matrix[64];
832     unsigned char non_intra_quantiser_matrix[64];
833     unsigned char chroma_intra_quantiser_matrix[64];
834     unsigned char chroma_non_intra_quantiser_matrix[64];
835 } VAIQMatrixBufferMPEG2;
836
837 /* MPEG-2 Slice Parameter Buffer */
838 typedef struct _VASliceParameterBufferMPEG2
839 {
840     unsigned int slice_data_size;/* number of bytes in the slice data buffer for this slice */
841     unsigned int slice_data_offset;/* the offset to the first byte of slice data */
842     unsigned int slice_data_flag; /* see VA_SLICE_DATA_FLAG_XXX defintions */
843     unsigned int macroblock_offset;/* the offset to the first bit of MB from the first byte of slice data */
844     unsigned int slice_horizontal_position;
845     unsigned int slice_vertical_position;
846     int quantiser_scale_code;
847     int intra_slice_flag;
848 } VASliceParameterBufferMPEG2;
849
850 /* MPEG-2 Macroblock Parameter Buffer */
851 typedef struct _VAMacroblockParameterBufferMPEG2
852 {
853     unsigned short macroblock_address;
854     /* 
855      * macroblock_address (in raster scan order)
856      * top-left: 0
857      * bottom-right: picture-height-in-mb*picture-width-in-mb - 1
858      */
859     unsigned char macroblock_type;  /* see definition below */
860     union {
861         struct {
862             unsigned int frame_motion_type              : 2; 
863             unsigned int field_motion_type              : 2; 
864             unsigned int dct_type                       : 1; 
865         } bits;
866         unsigned int value;
867     } macroblock_modes;
868     unsigned char motion_vertical_field_select; 
869     /* 
870      * motion_vertical_field_select:
871      * see section 6.3.17.2 in the spec
872      * only the lower 4 bits are used
873      * bit 0: first vector forward
874      * bit 1: first vector backward
875      * bit 2: second vector forward
876      * bit 3: second vector backward
877      */
878     short PMV[2][2][2]; /* see Table 7-7 in the spec */
879     unsigned short coded_block_pattern;
880     /* 
881      * The bitplanes for coded_block_pattern are described 
882      * in Figure 6.10-12 in the spec
883      */
884      
885     /* Number of skipped macroblocks after this macroblock */
886     unsigned short num_skipped_macroblocks;
887 } VAMacroblockParameterBufferMPEG2;
888
889 /* 
890  * OR'd flags for macroblock_type (section 6.3.17.1 in the spec)
891  */
892 #define VA_MB_TYPE_MOTION_FORWARD       0x02
893 #define VA_MB_TYPE_MOTION_BACKWARD      0x04
894 #define VA_MB_TYPE_MOTION_PATTERN       0x08
895 #define VA_MB_TYPE_MOTION_INTRA         0x10
896
897 /* 
898  * MPEG-2 Residual Data Buffer 
899  * For each macroblock, there wil be 64 shorts (16-bit) in the 
900  * residual data buffer
901  */
902
903 /****************************
904  * MPEG-4 Part 2 data structures
905  ****************************/
906  
907 /* MPEG-4 Picture Parameter Buffer */
908 /* 
909  * For each frame or field, and before any slice data, a single
910  * picture parameter buffer must be send.
911  */
912 typedef struct _VAPictureParameterBufferMPEG4
913 {
914     unsigned short vop_width;
915     unsigned short vop_height;
916     VASurfaceID forward_reference_picture;
917     VASurfaceID backward_reference_picture;
918     union {
919         struct {
920             unsigned int short_video_header             : 1; 
921             unsigned int chroma_format                  : 2; 
922             unsigned int interlaced                     : 1; 
923             unsigned int obmc_disable                   : 1; 
924             unsigned int sprite_enable                  : 2; 
925             unsigned int sprite_warping_accuracy        : 2; 
926             unsigned int quant_type                     : 1; 
927             unsigned int quarter_sample                 : 1; 
928             unsigned int data_partitioned               : 1; 
929             unsigned int reversible_vlc                 : 1; 
930             unsigned int resync_marker_disable          : 1; 
931         } bits;
932         unsigned int value;
933     } vol_fields;
934     unsigned char no_of_sprite_warping_points;
935     short sprite_trajectory_du[3];
936     short sprite_trajectory_dv[3];
937     unsigned char quant_precision;
938     union {
939         struct {
940             unsigned int vop_coding_type                : 2; 
941             unsigned int backward_reference_vop_coding_type     : 2; 
942             unsigned int vop_rounding_type              : 1; 
943             unsigned int intra_dc_vlc_thr               : 3; 
944             unsigned int top_field_first                : 1; 
945             unsigned int alternate_vertical_scan_flag   : 1; 
946         } bits;
947         unsigned int value;
948     } vop_fields;
949     unsigned char vop_fcode_forward;
950     unsigned char vop_fcode_backward;
951     unsigned short vop_time_increment_resolution;
952     /* short header related */
953     unsigned char num_gobs_in_vop;
954     unsigned char num_macroblocks_in_gob;
955     /* for direct mode prediction */
956     short TRB;
957     short TRD;
958 } VAPictureParameterBufferMPEG4;
959
960 /* MPEG-4 Inverse Quantization Matrix Buffer */
961 typedef struct _VAIQMatrixBufferMPEG4
962 {
963     int load_intra_quant_mat;
964     int load_non_intra_quant_mat;
965     unsigned char intra_quant_mat[64];
966     unsigned char non_intra_quant_mat[64];
967 } VAIQMatrixBufferMPEG4;
968
969 /* MPEG-4 Slice Parameter Buffer */
970 typedef struct _VASliceParameterBufferMPEG4
971 {
972     unsigned int slice_data_size;/* number of bytes in the slice data buffer for this slice */
973     unsigned int slice_data_offset;/* the offset to the first byte of slice data */
974     unsigned int slice_data_flag; /* see VA_SLICE_DATA_FLAG_XXX defintions */
975     unsigned int macroblock_offset;/* the offset to the first bit of MB from the first byte of slice data */
976     unsigned int macroblock_number;
977     int quant_scale;
978 } VASliceParameterBufferMPEG4;
979
980 /*
981  VC-1 data structures
982 */
983
984 typedef enum   /* see 7.1.1.32 */
985 {
986     VAMvMode1Mv                        = 0,
987     VAMvMode1MvHalfPel                 = 1,
988     VAMvMode1MvHalfPelBilinear         = 2,
989     VAMvModeMixedMv                    = 3,
990     VAMvModeIntensityCompensation      = 4 
991 } VAMvModeVC1;
992
993 /* VC-1 Picture Parameter Buffer */
994 /* 
995  * For each picture, and before any slice data, a picture parameter
996  * buffer must be send. Multiple picture parameter buffers may be
997  * sent for a single picture. In that case picture parameters will
998  * apply to all slice data that follow it until a new picture
999  * parameter buffer is sent.
1000  *
1001  * Notes:
1002  *   pic_quantizer_type should be set to the applicable quantizer
1003  *   type as defined by QUANTIZER (J.1.19) and either
1004  *   PQUANTIZER (7.1.1.8) or PQINDEX (7.1.1.6)
1005  */
1006 typedef struct _VAPictureParameterBufferVC1
1007 {
1008     VASurfaceID forward_reference_picture;
1009     VASurfaceID backward_reference_picture;
1010     /* if out-of-loop post-processing is done on the render
1011        target, then we need to keep the in-loop decoded 
1012        picture as a reference picture */
1013     VASurfaceID inloop_decoded_picture;
1014
1015     /* sequence layer for AP or meta data for SP and MP */
1016     union {
1017         struct {
1018             unsigned int pulldown       : 1; /* SEQUENCE_LAYER::PULLDOWN */
1019             unsigned int interlace      : 1; /* SEQUENCE_LAYER::INTERLACE */
1020             unsigned int tfcntrflag     : 1; /* SEQUENCE_LAYER::TFCNTRFLAG */
1021             unsigned int finterpflag    : 1; /* SEQUENCE_LAYER::FINTERPFLAG */
1022             unsigned int psf            : 1; /* SEQUENCE_LAYER::PSF */
1023             unsigned int multires       : 1; /* METADATA::MULTIRES */
1024             unsigned int overlap        : 1; /* METADATA::OVERLAP */
1025             unsigned int syncmarker     : 1; /* METADATA::SYNCMARKER */
1026             unsigned int rangered       : 1; /* METADATA::RANGERED */
1027             unsigned int max_b_frames   : 3; /* METADATA::MAXBFRAMES */
1028             unsigned int profile        : 2; /* SEQUENCE_LAYER::PROFILE or The MSB of METADATA::PROFILE */
1029         } bits;
1030         unsigned int value;
1031     } sequence_fields;
1032
1033     unsigned short coded_width;         /* ENTRY_POINT_LAYER::CODED_WIDTH */
1034     unsigned short coded_height;        /* ENTRY_POINT_LAYER::CODED_HEIGHT */
1035     union {
1036         struct {
1037             unsigned int broken_link    : 1; /* ENTRY_POINT_LAYER::BROKEN_LINK */
1038             unsigned int closed_entry   : 1; /* ENTRY_POINT_LAYER::CLOSED_ENTRY */
1039             unsigned int panscan_flag   : 1; /* ENTRY_POINT_LAYER::PANSCAN_FLAG */
1040             unsigned int loopfilter     : 1; /* ENTRY_POINT_LAYER::LOOPFILTER */
1041         } bits;
1042         unsigned int value;
1043     } entrypoint_fields;
1044     unsigned char conditional_overlap_flag; /* ENTRY_POINT_LAYER::CONDOVER */
1045     unsigned char fast_uvmc_flag;       /* ENTRY_POINT_LAYER::FASTUVMC */
1046     union {
1047         struct {
1048             unsigned int luma_flag      : 1; /* ENTRY_POINT_LAYER::RANGE_MAPY_FLAG */
1049             unsigned int luma           : 3; /* ENTRY_POINT_LAYER::RANGE_MAPY */
1050             unsigned int chroma_flag    : 1; /* ENTRY_POINT_LAYER::RANGE_MAPUV_FLAG */
1051             unsigned int chroma         : 3; /* ENTRY_POINT_LAYER::RANGE_MAPUV */
1052         } bits;
1053         unsigned int value;
1054     } range_mapping_fields;
1055
1056     unsigned char b_picture_fraction;   /* PICTURE_LAYER::BFRACTION */
1057     unsigned char cbp_table;            /* PICTURE_LAYER::CBPTAB/ICBPTAB */
1058     unsigned char mb_mode_table;        /* PICTURE_LAYER::MBMODETAB */
1059     unsigned char range_reduction_frame;/* PICTURE_LAYER::RANGEREDFRM */
1060     unsigned char rounding_control;     /* PICTURE_LAYER::RNDCTRL */
1061     unsigned char post_processing;      /* PICTURE_LAYER::POSTPROC */
1062     unsigned char picture_resolution_index;     /* PICTURE_LAYER::RESPIC */
1063     unsigned char luma_scale;           /* PICTURE_LAYER::LUMSCALE */
1064     unsigned char luma_shift;           /* PICTURE_LAYER::LUMSHIFT */
1065     union {
1066         struct {
1067             unsigned int picture_type           : 3; /* PICTURE_LAYER::PTYPE */
1068             unsigned int frame_coding_mode      : 3; /* PICTURE_LAYER::FCM */
1069             unsigned int top_field_first        : 1; /* PICTURE_LAYER::TFF */
1070             unsigned int is_first_field         : 1; /* set to 1 if it is the first field */
1071             unsigned int intensity_compensation : 1; /* PICTURE_LAYER::INTCOMP */
1072         } bits;
1073         unsigned int value;
1074     } picture_fields;
1075     union {
1076         struct {
1077             unsigned int mv_type_mb     : 1;    /* PICTURE::MVTYPEMB */
1078             unsigned int direct_mb      : 1;    /* PICTURE::DIRECTMB */
1079             unsigned int skip_mb        : 1;    /* PICTURE::SKIPMB */
1080             unsigned int field_tx       : 1;    /* PICTURE::FIELDTX */
1081             unsigned int forward_mb     : 1;    /* PICTURE::FORWARDMB */
1082             unsigned int ac_pred        : 1;    /* PICTURE::ACPRED */
1083             unsigned int overflags      : 1;    /* PICTURE::OVERFLAGS */
1084         } flags;
1085         unsigned int value;
1086     } raw_coding;
1087     union {
1088         struct {
1089             unsigned int bp_mv_type_mb   : 1;    /* PICTURE::MVTYPEMB */
1090             unsigned int bp_direct_mb    : 1;    /* PICTURE::DIRECTMB */
1091             unsigned int bp_skip_mb      : 1;    /* PICTURE::SKIPMB */  
1092             unsigned int bp_field_tx     : 1;    /* PICTURE::FIELDTX */ 
1093             unsigned int bp_forward_mb   : 1;    /* PICTURE::FORWARDMB */
1094             unsigned int bp_ac_pred      : 1;    /* PICTURE::ACPRED */   
1095             unsigned int bp_overflags    : 1;    /* PICTURE::OVERFLAGS */
1096         } flags;
1097         unsigned int value;
1098     } bitplane_present; /* signal what bitplane is being passed via the bitplane buffer */
1099     union {
1100         struct {
1101             unsigned int reference_distance_flag : 1;/* PICTURE_LAYER::REFDIST_FLAG */
1102             unsigned int reference_distance     : 5;/* PICTURE_LAYER::REFDIST */
1103             unsigned int num_reference_pictures: 1;/* PICTURE_LAYER::NUMREF */
1104             unsigned int reference_field_pic_indicator  : 1;/* PICTURE_LAYER::REFFIELD */
1105         } bits;
1106         unsigned int value;
1107     } reference_fields;
1108     union {
1109         struct {
1110             unsigned int mv_mode                : 3; /* PICTURE_LAYER::MVMODE */
1111             unsigned int mv_mode2               : 3; /* PICTURE_LAYER::MVMODE2 */
1112             unsigned int mv_table               : 3; /* PICTURE_LAYER::MVTAB/IMVTAB */
1113             unsigned int two_mv_block_pattern_table: 2; /* PICTURE_LAYER::2MVBPTAB */
1114             unsigned int four_mv_switch         : 1; /* PICTURE_LAYER::4MVSWITCH */
1115             unsigned int four_mv_block_pattern_table : 2; /* PICTURE_LAYER::4MVBPTAB */
1116             unsigned int extended_mv_flag       : 1; /* ENTRY_POINT_LAYER::EXTENDED_MV */
1117             unsigned int extended_mv_range      : 2; /* PICTURE_LAYER::MVRANGE */
1118             unsigned int extended_dmv_flag      : 1; /* ENTRY_POINT_LAYER::EXTENDED_DMV */
1119             unsigned int extended_dmv_range     : 2; /* PICTURE_LAYER::DMVRANGE */
1120         } bits;
1121         unsigned int value;
1122     } mv_fields;
1123     union {
1124         struct {
1125             unsigned int dquant : 2;    /* ENTRY_POINT_LAYER::DQUANT */
1126             unsigned int quantizer     : 2;     /* ENTRY_POINT_LAYER::QUANTIZER */
1127             unsigned int half_qp        : 1;    /* PICTURE_LAYER::HALFQP */
1128             unsigned int pic_quantizer_scale : 5;/* PICTURE_LAYER::PQUANT */
1129             unsigned int pic_quantizer_type : 1;/* PICTURE_LAYER::PQUANTIZER */
1130             unsigned int dq_frame       : 1;    /* VOPDQUANT::DQUANTFRM */
1131             unsigned int dq_profile     : 2;    /* VOPDQUANT::DQPROFILE */
1132             unsigned int dq_sb_edge     : 2;    /* VOPDQUANT::DQSBEDGE */
1133             unsigned int dq_db_edge     : 2;    /* VOPDQUANT::DQDBEDGE */
1134             unsigned int dq_binary_level : 1;   /* VOPDQUANT::DQBILEVEL */
1135             unsigned int alt_pic_quantizer : 5;/* VOPDQUANT::ALTPQUANT */
1136         } bits;
1137         unsigned int value;
1138     } pic_quantizer_fields;
1139     union {
1140         struct {
1141             unsigned int variable_sized_transform_flag  : 1;/* ENTRY_POINT_LAYER::VSTRANSFORM */
1142             unsigned int mb_level_transform_type_flag   : 1;/* PICTURE_LAYER::TTMBF */
1143             unsigned int frame_level_transform_type     : 2;/* PICTURE_LAYER::TTFRM */
1144             unsigned int transform_ac_codingset_idx1    : 2;/* PICTURE_LAYER::TRANSACFRM */
1145             unsigned int transform_ac_codingset_idx2    : 2;/* PICTURE_LAYER::TRANSACFRM2 */
1146             unsigned int intra_transform_dc_table       : 1;/* PICTURE_LAYER::TRANSDCTAB */
1147         } bits;
1148         unsigned int value;
1149     } transform_fields;
1150 } VAPictureParameterBufferVC1;
1151
1152 /* VC-1 Bitplane Buffer 
1153 There will be at most three bitplanes coded in any picture header. To send 
1154 the bitplane data more efficiently, each byte is divided in two nibbles, with
1155 each nibble carrying three bitplanes for one macroblock.  The following table
1156 shows the bitplane data arrangement within each nibble based on the picture
1157 type.
1158
1159 Picture Type    Bit3            Bit2            Bit1            Bit0
1160 I or BI                         OVERFLAGS       ACPRED          FIELDTX
1161 P                               MYTYPEMB        SKIPMB          DIRECTMB
1162 B                               FORWARDMB       SKIPMB          DIRECTMB
1163
1164 Within each byte, the lower nibble is for the first MB and the upper nibble is 
1165 for the second MB.  E.g. the lower nibble of the first byte in the bitplane
1166 buffer is for Macroblock #1 and the upper nibble of the first byte is for 
1167 Macroblock #2 in the first row.
1168 */
1169
1170 /* VC-1 Slice Parameter Buffer */
1171 typedef struct _VASliceParameterBufferVC1
1172 {
1173     unsigned int slice_data_size;/* number of bytes in the slice data buffer for this slice */
1174     unsigned int slice_data_offset;/* the offset to the first byte of slice data */
1175     unsigned int slice_data_flag; /* see VA_SLICE_DATA_FLAG_XXX defintions */
1176     unsigned int macroblock_offset;/* the offset to the first bit of MB from the first byte of slice data */
1177     unsigned int slice_vertical_position;
1178 } VASliceParameterBufferVC1;
1179
1180 /* VC-1 Slice Data Buffer */
1181 /* 
1182 This is simplely a buffer containing raw bit-stream bytes 
1183 */
1184
1185 /****************************
1186  * H.264/AVC data structures
1187  ****************************/
1188
1189 typedef struct _VAPictureH264
1190 {
1191     VASurfaceID picture_id;
1192     unsigned int frame_idx;
1193     unsigned int flags;
1194     signed int TopFieldOrderCnt;
1195     signed int BottomFieldOrderCnt;
1196 } VAPictureH264;
1197 /* flags in VAPictureH264 could be OR of the following */
1198 #define VA_PICTURE_H264_INVALID                 0x00000001
1199 #define VA_PICTURE_H264_TOP_FIELD               0x00000002
1200 #define VA_PICTURE_H264_BOTTOM_FIELD            0x00000004
1201 #define VA_PICTURE_H264_SHORT_TERM_REFERENCE    0x00000008
1202 #define VA_PICTURE_H264_LONG_TERM_REFERENCE     0x00000010
1203
1204 /* H.264 Picture Parameter Buffer */
1205 /* 
1206  * For each picture, and before any slice data, a single
1207  * picture parameter buffer must be send.
1208  */
1209 typedef struct _VAPictureParameterBufferH264
1210 {
1211     VAPictureH264 CurrPic;
1212     VAPictureH264 ReferenceFrames[16];  /* in DPB */
1213     unsigned short picture_width_in_mbs_minus1;
1214     unsigned short picture_height_in_mbs_minus1;
1215     unsigned char bit_depth_luma_minus8;
1216     unsigned char bit_depth_chroma_minus8;
1217     unsigned char num_ref_frames;
1218     union {
1219         struct {
1220             unsigned int chroma_format_idc                      : 2; 
1221             unsigned int residual_colour_transform_flag         : 1; 
1222             unsigned int gaps_in_frame_num_value_allowed_flag   : 1; 
1223             unsigned int frame_mbs_only_flag                    : 1; 
1224             unsigned int mb_adaptive_frame_field_flag           : 1; 
1225             unsigned int direct_8x8_inference_flag              : 1; 
1226             unsigned int MinLumaBiPredSize8x8                   : 1; /* see A.3.3.2 */
1227             unsigned int log2_max_frame_num_minus4              : 4;
1228             unsigned int pic_order_cnt_type                     : 2;
1229             unsigned int log2_max_pic_order_cnt_lsb_minus4      : 4;
1230             unsigned int delta_pic_order_always_zero_flag       : 1;
1231         } bits;
1232         unsigned int value;
1233     } seq_fields;
1234     unsigned char num_slice_groups_minus1;
1235     unsigned char slice_group_map_type;
1236     unsigned short slice_group_change_rate_minus1;
1237     signed char pic_init_qp_minus26;
1238     signed char pic_init_qs_minus26;
1239     signed char chroma_qp_index_offset;
1240     signed char second_chroma_qp_index_offset;
1241     union {
1242         struct {
1243             unsigned int entropy_coding_mode_flag       : 1;
1244             unsigned int weighted_pred_flag             : 1;
1245             unsigned int weighted_bipred_idc            : 2;
1246             unsigned int transform_8x8_mode_flag        : 1;
1247             unsigned int field_pic_flag                 : 1;
1248             unsigned int constrained_intra_pred_flag    : 1;
1249             unsigned int pic_order_present_flag                 : 1;
1250             unsigned int deblocking_filter_control_present_flag : 1;
1251             unsigned int redundant_pic_cnt_present_flag         : 1;
1252             unsigned int reference_pic_flag                     : 1; /* nal_ref_idc != 0 */
1253         } bits;
1254         unsigned int value;
1255     } pic_fields;
1256     unsigned short frame_num;
1257 } VAPictureParameterBufferH264;
1258
1259 /* H.264 Inverse Quantization Matrix Buffer */
1260 typedef struct _VAIQMatrixBufferH264
1261 {
1262     unsigned char ScalingList4x4[6][16];
1263     unsigned char ScalingList8x8[2][64];
1264 } VAIQMatrixBufferH264;
1265
1266 /* 
1267  * H.264 Slice Group Map Buffer 
1268  * When VAPictureParameterBufferH264::num_slice_group_minus1 is not equal to 0,
1269  * A slice group map buffer should be sent for each picture if required. The buffer
1270  * is sent only when there is a change in the mapping values.
1271  * The slice group map buffer map "map units" to slice groups as specified in 
1272  * section 8.2.2 of the H.264 spec. The buffer will contain one byte for each macroblock 
1273  * in raster scan order
1274  */ 
1275
1276 /* H.264 Slice Parameter Buffer */
1277 typedef struct _VASliceParameterBufferH264
1278 {
1279     unsigned int slice_data_size;/* number of bytes in the slice data buffer for this slice */
1280     /** \brief Byte offset to the NAL Header Unit for this slice. */
1281     unsigned int slice_data_offset;
1282     unsigned int slice_data_flag; /* see VA_SLICE_DATA_FLAG_XXX defintions */
1283     /**
1284      * \brief Bit offset from NAL Header Unit to the begining of slice_data().
1285      *
1286      * This bit offset is relative to and includes the NAL unit byte
1287      * and represents the number of bits parsed in the slice_header()
1288      * after the removal of any emulation prevention bytes in
1289      * there. However, the slice data buffer passed to the hardware is
1290      * the original bitstream, thus including any emulation prevention
1291      * bytes.
1292      */
1293     unsigned short slice_data_bit_offset;
1294     unsigned short first_mb_in_slice;
1295     unsigned char slice_type;
1296     unsigned char direct_spatial_mv_pred_flag;
1297     unsigned char num_ref_idx_l0_active_minus1;
1298     unsigned char num_ref_idx_l1_active_minus1;
1299     unsigned char cabac_init_idc;
1300     char slice_qp_delta;
1301     unsigned char disable_deblocking_filter_idc;
1302     char slice_alpha_c0_offset_div2;
1303     char slice_beta_offset_div2;
1304     VAPictureH264 RefPicList0[32];      /* See 8.2.4.2 */
1305     VAPictureH264 RefPicList1[32];      /* See 8.2.4.2 */
1306     unsigned char luma_log2_weight_denom;
1307     unsigned char chroma_log2_weight_denom;
1308     unsigned char luma_weight_l0_flag;
1309     short luma_weight_l0[32];
1310     short luma_offset_l0[32];
1311     unsigned char chroma_weight_l0_flag;
1312     short chroma_weight_l0[32][2];
1313     short chroma_offset_l0[32][2];
1314     unsigned char luma_weight_l1_flag;
1315     short luma_weight_l1[32];
1316     short luma_offset_l1[32];
1317     unsigned char chroma_weight_l1_flag;
1318     short chroma_weight_l1[32][2];
1319     short chroma_offset_l1[32][2];
1320 } VASliceParameterBufferH264;
1321
1322 /****************************
1323  * Common encode data structures 
1324  ****************************/
1325 typedef enum
1326 {
1327     VAEncPictureTypeIntra               = 0,
1328     VAEncPictureTypePredictive          = 1,
1329     VAEncPictureTypeBidirectional       = 2,
1330 } VAEncPictureType;
1331
1332 /* Encode Slice Parameter Buffer */
1333 typedef struct _VAEncSliceParameterBuffer
1334 {
1335     unsigned int start_row_number;      /* starting MB row number for this slice */
1336     unsigned int slice_height;  /* slice height measured in MB */
1337     union {
1338         struct {
1339             unsigned int is_intra       : 1;
1340             unsigned int disable_deblocking_filter_idc : 2;
1341             unsigned int uses_long_term_ref             :1;
1342             unsigned int is_long_term_ref               :1;
1343         } bits;
1344         unsigned int value;
1345     } slice_flags;
1346 } VAEncSliceParameterBuffer;
1347
1348 /****************************
1349  * H.264 specific encode data structures
1350  ****************************/
1351
1352 typedef struct _VAEncSequenceParameterBufferH264Baseline
1353 {
1354     unsigned char seq_parameter_set_id;
1355     unsigned char level_idc;
1356     unsigned int intra_period;
1357     unsigned int intra_idr_period;
1358     unsigned int max_num_ref_frames;
1359     unsigned int picture_width_in_mbs;
1360     unsigned int picture_height_in_mbs;
1361     unsigned int bits_per_second;
1362     unsigned int frame_rate;
1363     unsigned int initial_qp;
1364     unsigned int min_qp;
1365     unsigned int basic_unit_size;
1366     unsigned char vui_flag;
1367 } VAEncSequenceParameterBufferH264Baseline;
1368
1369 #define H264_LAST_PICTURE_EOSEQ     0x01 /* the last picture in the sequence */
1370 #define H264_LAST_PICTURE_EOSTREAM  0x02 /* the last picture in the stream */
1371 typedef struct _VAEncPictureParameterBufferH264Baseline
1372 {
1373     VASurfaceID reference_picture;
1374     VASurfaceID reconstructed_picture;
1375     VABufferID coded_buf;
1376     unsigned short picture_width;
1377     unsigned short picture_height;
1378     unsigned char last_picture;
1379 } VAEncPictureParameterBufferH264Baseline;
1380
1381 /****************************
1382  * H.263 specific encode data structures
1383  ****************************/
1384
1385 typedef struct _VAEncSequenceParameterBufferH263
1386 {
1387     unsigned int intra_period;
1388     unsigned int bits_per_second;
1389     unsigned int frame_rate;
1390     unsigned int initial_qp;
1391     unsigned int min_qp;
1392 } VAEncSequenceParameterBufferH263;
1393
1394 typedef struct _VAEncPictureParameterBufferH263
1395 {
1396     VASurfaceID reference_picture;
1397     VASurfaceID reconstructed_picture;
1398     VABufferID coded_buf;
1399     unsigned short picture_width;
1400     unsigned short picture_height;
1401     VAEncPictureType picture_type;
1402 } VAEncPictureParameterBufferH263;
1403
1404 /****************************
1405  * MPEG-4 specific encode data structures
1406  ****************************/
1407
1408 typedef struct _VAEncSequenceParameterBufferMPEG4
1409 {
1410     unsigned char profile_and_level_indication;
1411     unsigned int intra_period;
1412     unsigned int video_object_layer_width;
1413     unsigned int video_object_layer_height;
1414     unsigned int vop_time_increment_resolution;
1415     unsigned int fixed_vop_rate;
1416     unsigned int fixed_vop_time_increment;
1417     unsigned int bits_per_second;
1418     unsigned int frame_rate;
1419     unsigned int initial_qp;
1420     unsigned int min_qp;
1421 } VAEncSequenceParameterBufferMPEG4;
1422
1423 typedef struct _VAEncPictureParameterBufferMPEG4
1424 {
1425     VASurfaceID reference_picture;
1426     VASurfaceID reconstructed_picture;
1427     VABufferID coded_buf;
1428     unsigned short picture_width;
1429     unsigned short picture_height;
1430     unsigned int modulo_time_base; /* number of 1s */
1431     unsigned int vop_time_increment;
1432     VAEncPictureType picture_type;
1433 } VAEncPictureParameterBufferMPEG4;
1434
1435
1436
1437 /* Buffer functions */
1438
1439 /*
1440  * Creates a buffer for "num_elements" elements of "size" bytes and 
1441  * initalize with "data".
1442  * if "data" is null, then the contents of the buffer data store
1443  * are undefined.
1444  * Basically there are two ways to get buffer data to the server side. One is 
1445  * to call vaCreateBuffer() with a non-null "data", which results the data being
1446  * copied to the data store on the server side.  A different method that 
1447  * eliminates this copy is to pass null as "data" when calling vaCreateBuffer(),
1448  * and then use vaMapBuffer() to map the data store from the server side to the
1449  * client address space for access.
1450  *  Note: image buffers are created by the library, not the client. Please see 
1451  *        vaCreateImage on how image buffers are managed.
1452  */
1453 VAStatus vaCreateBuffer (
1454     VADisplay dpy,
1455     VAContextID context,
1456     VABufferType type,  /* in */
1457     unsigned int size,  /* in */
1458     unsigned int num_elements, /* in */
1459     void *data,         /* in */
1460     VABufferID *buf_id  /* out */
1461 );
1462
1463 /*
1464  * Convey to the server how many valid elements are in the buffer. 
1465  * e.g. if multiple slice parameters are being held in a single buffer,
1466  * this will communicate to the server the number of slice parameters
1467  * that are valid in the buffer.
1468  */
1469 VAStatus vaBufferSetNumElements (
1470     VADisplay dpy,
1471     VABufferID buf_id,  /* in */
1472     unsigned int num_elements /* in */
1473 );
1474
1475
1476 /*
1477  * device independent data structure for codedbuffer
1478  */
1479
1480 /* 
1481  * FICTURE_AVE_QP(bit7-0): The average Qp value used during this frame
1482  * LARGE_SLICE(bit8):At least one slice in the current frame was large
1483  *              enough for the encoder to attempt to limit its size.
1484  * SLICE_OVERFLOW(bit9): At least one slice in the current frame has
1485  *              exceeded the maximum slice size specified.
1486  * BITRATE_OVERFLOW(bit10): The peak bitrate was exceeded for this frame.
1487  * BITRATE_HIGH(bit11): The frame size got within the safety margin of the maximum size (VCM only)
1488  * AIR_MB_OVER_THRESHOLD: the number of MBs adapted to Intra MB
1489  */
1490 #define VA_CODED_BUF_STATUS_PICTURE_AVE_QP_MASK         0xff
1491 #define VA_CODED_BUF_STATUS_LARGE_SLICE_MASK            0x100
1492 #define VA_CODED_BUF_STATUS_SLICE_OVERFLOW_MASK         0x200
1493 #define VA_CODED_BUF_STATUS_BITRATE_OVERFLOW            0x400
1494 #define VA_CODED_BUF_STATUS_BITRATE_HIGH                0x800
1495 #define VA_CODED_BUF_STATUS_AIR_MB_OVER_THRESHOLD       0xff0000
1496
1497 /*
1498  * device independent data structure for codedbuffer
1499  */
1500 typedef  struct _VACodedBufferSegment  {
1501     unsigned int size;/* size of the data buffer in the coded buffer segment, in bytes */
1502     unsigned int bit_offset; /* bit offset into the data buffer where valid bitstream data begins */
1503     unsigned int status; /* status set by the driver on the coded buffer*/
1504     unsigned int reserved; /* for future use */
1505     void *buf; /* pointer to the beginning of the data buffer in the coded buffer segment */
1506     void *next; /* pointer to the next VACodedBufferSegment */
1507 } VACodedBufferSegment;
1508      
1509 /*
1510  * Map data store of the buffer into the client's address space
1511  * vaCreateBuffer() needs to be called with "data" set to NULL before
1512  * calling vaMapBuffer()
1513  *
1514  * if buffer type is VAEncCodedBufferType, pbuf points to link-list of
1515  * VACodedBufferSegment, and the list is terminated if "next" is NULL
1516  */
1517 VAStatus vaMapBuffer (
1518     VADisplay dpy,
1519     VABufferID buf_id,  /* in */
1520     void **pbuf         /* out */
1521 );
1522
1523 /*
1524  * After client making changes to a mapped data store, it needs to
1525  * "Unmap" it to let the server know that the data is ready to be
1526  * consumed by the server
1527  */
1528 VAStatus vaUnmapBuffer (
1529     VADisplay dpy,
1530     VABufferID buf_id   /* in */
1531 );
1532
1533 /*
1534  * After this call, the buffer is deleted and this buffer_id is no longer valid
1535  * Only call this if the buffer is not going to be passed to vaRenderBuffer
1536  */
1537 VAStatus vaDestroyBuffer (
1538     VADisplay dpy,
1539     VABufferID buffer_id
1540 );
1541
1542 /*
1543 Render (Decode) Pictures
1544
1545 A picture represents either a frame or a field.
1546
1547 The Begin/Render/End sequence sends the decode buffers to the server
1548 */
1549
1550 /*
1551  * Get ready to decode a picture to a target surface
1552  */
1553 VAStatus vaBeginPicture (
1554     VADisplay dpy,
1555     VAContextID context,
1556     VASurfaceID render_target
1557 );
1558
1559 /* 
1560  * Send decode buffers to the server.
1561  * Buffers are automatically destroyed afterwards
1562  */
1563 VAStatus vaRenderPicture (
1564     VADisplay dpy,
1565     VAContextID context,
1566     VABufferID *buffers,
1567     int num_buffers
1568 );
1569
1570 /* 
1571  * Make the end of rendering for a picture. 
1572  * The server should start processing all pending operations for this 
1573  * surface. This call is non-blocking. The client can start another 
1574  * Begin/Render/End sequence on a different render target.
1575  */
1576 VAStatus vaEndPicture (
1577     VADisplay dpy,
1578     VAContextID context
1579 );
1580
1581 /*
1582
1583 Synchronization 
1584
1585 */
1586
1587 /* 
1588  * This function blocks until all pending operations on the render target
1589  * have been completed.  Upon return it is safe to use the render target for a 
1590  * different picture. 
1591  */
1592 VAStatus vaSyncSurface (
1593     VADisplay dpy,
1594     VASurfaceID render_target
1595 );
1596
1597 typedef enum
1598 {
1599     VASurfaceRendering  = 1, /* Rendering in progress */ 
1600     VASurfaceDisplaying = 2, /* Displaying in progress (not safe to render into it) */ 
1601                              /* this status is useful if surface is used as the source */
1602                              /* of an overlay */
1603     VASurfaceReady      = 4, /* not being rendered or displayed */
1604     VASurfaceSkipped    = 8  /* Indicate a skipped frame during encode */
1605 } VASurfaceStatus;
1606
1607 /*
1608  * Find out any pending ops on the render target 
1609  */
1610 VAStatus vaQuerySurfaceStatus (
1611     VADisplay dpy,
1612     VASurfaceID render_target,
1613     VASurfaceStatus *status     /* out */
1614 );
1615
1616 typedef enum
1617 {
1618     VADecodeSliceMissing            = 0,
1619     VADecodeMBError                 = 1,
1620 } VADecodeErrorType;
1621
1622 /*
1623  * Client calls vaQuerySurfaceError with VA_STATUS_ERROR_DECODING_ERROR, server side returns
1624  * an array of structure VASurfaceDecodeMBErrors, and the array is terminated by setting status=-1
1625 */
1626 typedef struct _VASurfaceDecodeMBErrors
1627 {
1628     int status; /* 1 if hardware has returned detailed info below, -1 means this record is invalid */
1629     unsigned int start_mb; /* start mb address with errors */
1630     unsigned int end_mb;  /* end mb address with errors */
1631     VADecodeErrorType decode_error_type;
1632 } VASurfaceDecodeMBErrors;
1633
1634 /*
1635  * After the application gets VA_STATUS_ERROR_DECODING_ERROR after calling vaSyncSurface(),
1636  * it can call vaQuerySurfaceError to find out further details on the particular error.
1637  * VA_STATUS_ERROR_DECODING_ERROR should be passed in as "error_status",
1638  * upon the return, error_info will point to an array of _VASurfaceDecodeMBErrors structure,
1639  * which is allocated and filled by libVA with detailed information on the missing or error macroblocks.
1640  * The array is terminated if "status==-1" is detected.
1641  */
1642 VAStatus vaQuerySurfaceError(
1643     VADisplay dpy,
1644     VASurfaceID surface,
1645     VAStatus error_status,
1646     void **error_info
1647 );
1648
1649 /*
1650  * Images and Subpictures
1651  * VAImage is used to either get the surface data to client memory, or 
1652  * to copy image data in client memory to a surface. 
1653  * Both images, subpictures and surfaces follow the same 2D coordinate system where origin 
1654  * is at the upper left corner with positive X to the right and positive Y down
1655  */
1656 #define VA_FOURCC(ch0, ch1, ch2, ch3) \
1657     ((unsigned long)(unsigned char) (ch0) | ((unsigned long)(unsigned char) (ch1) << 8) | \
1658     ((unsigned long)(unsigned char) (ch2) << 16) | ((unsigned long)(unsigned char) (ch3) << 24 ))
1659
1660 /* a few common FourCCs */
1661 #define VA_FOURCC_NV12          0x3231564E
1662 #define VA_FOURCC_AI44          0x34344149
1663 #define VA_FOURCC_RGBA          0x41424752
1664 #define VA_FOURCC_BGRA          0x41524742
1665 #define VA_FOURCC_UYVY          0x59565955
1666 #define VA_FOURCC_YUY2          0x32595559
1667 #define VA_FOURCC_AYUV          0x56555941
1668 #define VA_FOURCC_NV11          0x3131564e
1669 #define VA_FOURCC_YV12          0x32315659
1670 #define VA_FOURCC_P208          0x38303250
1671 #define VA_FOURCC_IYUV          0x56555949
1672
1673 /* byte order */
1674 #define VA_LSB_FIRST            1
1675 #define VA_MSB_FIRST            2
1676
1677 typedef struct _VAImageFormat
1678 {
1679     unsigned int        fourcc;
1680     unsigned int        byte_order; /* VA_LSB_FIRST, VA_MSB_FIRST */
1681     unsigned int        bits_per_pixel;
1682     /* for RGB formats */
1683     unsigned int        depth; /* significant bits per pixel */
1684     unsigned int        red_mask;
1685     unsigned int        green_mask;
1686     unsigned int        blue_mask;
1687     unsigned int        alpha_mask;
1688 } VAImageFormat;
1689
1690 typedef VAGenericID VAImageID;
1691
1692 typedef struct _VAImage
1693 {
1694     VAImageID           image_id; /* uniquely identify this image */
1695     VAImageFormat       format;
1696     VABufferID          buf;    /* image data buffer */
1697     /*
1698      * Image data will be stored in a buffer of type VAImageBufferType to facilitate
1699      * data store on the server side for optimal performance. The buffer will be 
1700      * created by the CreateImage function, and proper storage allocated based on the image
1701      * size and format. This buffer is managed by the library implementation, and 
1702      * accessed by the client through the buffer Map/Unmap functions.
1703      */
1704     unsigned short      width; 
1705     unsigned short      height;
1706     unsigned int        data_size;
1707     unsigned int        num_planes;     /* can not be greater than 3 */
1708     /* 
1709      * An array indicating the scanline pitch in bytes for each plane.
1710      * Each plane may have a different pitch. Maximum 3 planes for planar formats
1711      */
1712     unsigned int        pitches[3];
1713     /* 
1714      * An array indicating the byte offset from the beginning of the image data 
1715      * to the start of each plane.
1716      */
1717     unsigned int        offsets[3];
1718
1719     /* The following fields are only needed for paletted formats */
1720     int num_palette_entries;   /* set to zero for non-palette images */
1721     /* 
1722      * Each component is one byte and entry_bytes indicates the number of components in 
1723      * each entry (eg. 3 for YUV palette entries). set to zero for non-palette images   
1724      */
1725     int entry_bytes; 
1726     /*
1727      * An array of ascii characters describing the order of the components within the bytes.
1728      * Only entry_bytes characters of the string are used.
1729      */
1730     char component_order[4];
1731 } VAImage;
1732
1733 /* Get maximum number of image formats supported by the implementation */
1734 int vaMaxNumImageFormats (
1735     VADisplay dpy
1736 );
1737
1738 /* 
1739  * Query supported image formats 
1740  * The caller must provide a "format_list" array that can hold at
1741  * least vaMaxNumImageFormats() entries. The actual number of formats
1742  * returned in "format_list" is returned in "num_formats".
1743  */
1744 VAStatus vaQueryImageFormats (
1745     VADisplay dpy,
1746     VAImageFormat *format_list, /* out */
1747     int *num_formats            /* out */
1748 );
1749
1750 /* 
1751  * Create a VAImage structure
1752  * The width and height fields returned in the VAImage structure may get 
1753  * enlarged for some YUV formats. Upon return from this function, 
1754  * image->buf has been created and proper storage allocated by the library. 
1755  * The client can access the image through the Map/Unmap calls.
1756  */
1757 VAStatus vaCreateImage (
1758     VADisplay dpy,
1759     VAImageFormat *format,
1760     int width,
1761     int height,
1762     VAImage *image      /* out */
1763 );
1764
1765 /*
1766  * Should call DestroyImage before destroying the surface it is bound to
1767  */
1768 VAStatus vaDestroyImage (
1769     VADisplay dpy,
1770     VAImageID image
1771 );
1772
1773 VAStatus vaSetImagePalette (
1774     VADisplay dpy,
1775     VAImageID image,
1776     /* 
1777      * pointer to an array holding the palette data.  The size of the array is 
1778      * num_palette_entries * entry_bytes in size.  The order of the components 
1779      * in the palette is described by the component_order in VAImage struct    
1780      */
1781     unsigned char *palette 
1782 );
1783
1784 /*
1785  * Retrive surface data into a VAImage
1786  * Image must be in a format supported by the implementation
1787  */
1788 VAStatus vaGetImage (
1789     VADisplay dpy,
1790     VASurfaceID surface,
1791     int x,      /* coordinates of the upper left source pixel */
1792     int y,
1793     unsigned int width, /* width and height of the region */
1794     unsigned int height,
1795     VAImageID image
1796 );
1797
1798 /*
1799  * Copy data from a VAImage to a surface
1800  * Image must be in a format supported by the implementation
1801  * Returns a VA_STATUS_ERROR_SURFACE_BUSY if the surface
1802  * shouldn't be rendered into when this is called
1803  */
1804 VAStatus vaPutImage (
1805     VADisplay dpy,
1806     VASurfaceID surface,
1807     VAImageID image,
1808     int src_x,
1809     int src_y,
1810     unsigned int src_width,
1811     unsigned int src_height,
1812     int dest_x,
1813     int dest_y,
1814     unsigned int dest_width,
1815     unsigned int dest_height
1816 );
1817
1818 /*
1819  * Derive an VAImage from an existing surface.
1820  * This interface will derive a VAImage and corresponding image buffer from
1821  * an existing VA Surface. The image buffer can then be mapped/unmapped for
1822  * direct CPU access. This operation is only possible on implementations with
1823  * direct rendering capabilities and internal surface formats that can be
1824  * represented with a VAImage. When the operation is not possible this interface
1825  * will return VA_STATUS_ERROR_OPERATION_FAILED. Clients should then fall back
1826  * to using vaCreateImage + vaPutImage to accomplish the same task in an
1827  * indirect manner.
1828  *
1829  * Implementations should only return success when the resulting image buffer
1830  * would be useable with vaMap/Unmap.
1831  *
1832  * When directly accessing a surface special care must be taken to insure
1833  * proper synchronization with the graphics hardware. Clients should call
1834  * vaQuerySurfaceStatus to insure that a surface is not the target of concurrent
1835  * rendering or currently being displayed by an overlay.
1836  *
1837  * Additionally nothing about the contents of a surface should be assumed
1838  * following a vaPutSurface. Implementations are free to modify the surface for
1839  * scaling or subpicture blending within a call to vaPutImage.
1840  *
1841  * Calls to vaPutImage or vaGetImage using the same surface from which the image
1842  * has been derived will return VA_STATUS_ERROR_SURFACE_BUSY. vaPutImage or
1843  * vaGetImage with other surfaces is supported.
1844  *
1845  * An image created with vaDeriveImage should be freed with vaDestroyImage. The
1846  * image and image buffer structures will be destroyed; however, the underlying
1847  * surface will remain unchanged until freed with vaDestroySurfaces.
1848  */
1849 VAStatus vaDeriveImage (
1850     VADisplay dpy,
1851     VASurfaceID surface,
1852     VAImage *image      /* out */
1853 );
1854
1855 /*
1856  * Subpictures 
1857  * Subpicture is a special type of image that can be blended 
1858  * with a surface during vaPutSurface(). Subpicture can be used to render
1859  * DVD sub-titles or closed captioning text etc.  
1860  */
1861
1862 typedef VAGenericID VASubpictureID;
1863
1864 /* Get maximum number of subpicture formats supported by the implementation */
1865 int vaMaxNumSubpictureFormats (
1866     VADisplay dpy
1867 );
1868
1869 /* flags for subpictures */
1870 #define VA_SUBPICTURE_CHROMA_KEYING                     0x0001
1871 #define VA_SUBPICTURE_GLOBAL_ALPHA                      0x0002
1872 #define VA_SUBPICTURE_DESTINATION_IS_SCREEN_COORD       0x0004
1873 /* 
1874  * Query supported subpicture formats 
1875  * The caller must provide a "format_list" array that can hold at
1876  * least vaMaxNumSubpictureFormats() entries. The flags arrary holds the flag 
1877  * for each format to indicate additional capabilities for that format. The actual 
1878  * number of formats returned in "format_list" is returned in "num_formats".
1879  *  flags: returned value to indicate addtional capabilities
1880  *         VA_SUBPICTURE_CHROMA_KEYING - supports chroma-keying
1881  *         VA_SUBPICTURE_GLOBAL_ALPHA - supports global alpha
1882  *         VA_SUBPICTURE_DESTINATION_IS_SCREEN_COORD - supports unscaled screen relative subpictures for On Screen Display
1883  */
1884
1885 VAStatus vaQuerySubpictureFormats (
1886     VADisplay dpy,
1887     VAImageFormat *format_list, /* out */
1888     unsigned int *flags,        /* out */
1889     unsigned int *num_formats   /* out */
1890 );
1891
1892 /* 
1893  * Subpictures are created with an image associated. 
1894  */
1895 VAStatus vaCreateSubpicture (
1896     VADisplay dpy,
1897     VAImageID image,
1898     VASubpictureID *subpicture  /* out */
1899 );
1900
1901 /*
1902  * Destroy the subpicture before destroying the image it is assocated to
1903  */
1904 VAStatus vaDestroySubpicture (
1905     VADisplay dpy,
1906     VASubpictureID subpicture
1907 );
1908
1909 /* 
1910  * Bind an image to the subpicture. This image will now be associated with 
1911  * the subpicture instead of the one at creation.
1912  */
1913 VAStatus vaSetSubpictureImage (
1914     VADisplay dpy,
1915     VASubpictureID subpicture,
1916     VAImageID image
1917 );
1918
1919 /*
1920  * If chromakey is enabled, then the area where the source value falls within
1921  * the chromakey [min, max] range is transparent
1922  * The chromakey component format is the following:
1923  *  For RGB: [0:7] Red [8:15] Blue [16:23] Green   
1924  *  For YUV: [0:7] V [8:15] U [16:23] Y
1925  * The chromakey mask can be used to mask out certain components for chromakey
1926  * comparision
1927  */
1928 VAStatus vaSetSubpictureChromakey (
1929     VADisplay dpy,
1930     VASubpictureID subpicture,
1931     unsigned int chromakey_min,
1932     unsigned int chromakey_max,
1933     unsigned int chromakey_mask
1934 );
1935
1936 /*
1937  * Global alpha value is between 0 and 1. A value of 1 means fully opaque and 
1938  * a value of 0 means fully transparent. If per-pixel alpha is also specified then
1939  * the overall alpha is per-pixel alpha multiplied by the global alpha
1940  */
1941 VAStatus vaSetSubpictureGlobalAlpha (
1942     VADisplay dpy,
1943     VASubpictureID subpicture,
1944     float global_alpha 
1945 );
1946
1947 /*
1948  * vaAssociateSubpicture associates the subpicture with target_surfaces.
1949  * It defines the region mapping between the subpicture and the target  
1950  * surfaces through source and destination rectangles (with the same width and height).
1951  * Both will be displayed at the next call to vaPutSurface.  Additional
1952  * associations before the call to vaPutSurface simply overrides the association.
1953  */
1954 VAStatus vaAssociateSubpicture (
1955     VADisplay dpy,
1956     VASubpictureID subpicture,
1957     VASurfaceID *target_surfaces,
1958     int num_surfaces,
1959     short src_x, /* upper left offset in subpicture */
1960     short src_y,
1961     unsigned short src_width,
1962     unsigned short src_height,
1963     short dest_x, /* upper left offset in surface */
1964     short dest_y,
1965     unsigned short dest_width,
1966     unsigned short dest_height,
1967     /*
1968      * whether to enable chroma-keying, global-alpha, or screen relative mode
1969      * see VA_SUBPICTURE_XXX values
1970      */
1971     unsigned int flags
1972 );
1973
1974 /*
1975  * vaDeassociateSubpicture removes the association of the subpicture with target_surfaces.
1976  */
1977 VAStatus vaDeassociateSubpicture (
1978     VADisplay dpy,
1979     VASubpictureID subpicture,
1980     VASurfaceID *target_surfaces,
1981     int num_surfaces
1982 );
1983
1984 typedef struct _VARectangle
1985 {
1986     short x;
1987     short y;
1988     unsigned short width;
1989     unsigned short height;
1990 } VARectangle;
1991
1992 /*
1993  * Display attributes
1994  * Display attributes are used to control things such as contrast, hue, saturation,
1995  * brightness etc. in the rendering process.  The application can query what
1996  * attributes are supported by the driver, and then set the appropriate attributes
1997  * before calling vaPutSurface()
1998  */
1999 /* PowerVR IEP Lite attributes */
2000 typedef enum
2001 {
2002     VADISPLAYATTRIB_BLE_OFF              = 0x00,
2003     VADISPLAYATTRIB_BLE_LOW,
2004     VADISPLAYATTRIB_BLE_MEDIUM,
2005     VADISPLAYATTRIB_BLE_HIGH,
2006     VADISPLAYATTRIB_BLE_NONE,
2007 } VADisplayAttribBLEMode;
2008
2009 /* attribute value for VADisplayAttribRotation   */
2010 #define VA_ROTATION_NONE        0x00000000
2011 #define VA_ROTATION_90          0x00000001
2012 #define VA_ROTATION_180         0x00000002
2013 #define VA_ROTATION_270         0x00000003
2014
2015 /* attribute value for VADisplayAttribOutOfLoopDeblock */
2016 #define VA_OOL_DEBLOCKING_FALSE 0x00000000
2017 #define VA_OOL_DEBLOCKING_TRUE  0x00000001
2018
2019 /* Render mode */
2020 #define VA_RENDER_MODE_UNDEFINED           0
2021 #define VA_RENDER_MODE_LOCAL_OVERLAY       1
2022 #define VA_RENDER_MODE_LOCAL_GPU           2
2023 #define VA_RENDER_MODE_EXTERNAL_OVERLAY    4
2024 #define VA_RENDER_MODE_EXTERNAL_GPU        8
2025
2026 /* Render device */
2027 #define VA_RENDER_DEVICE_UNDEFINED  0
2028 #define VA_RENDER_DEVICE_LOCAL      1
2029 #define VA_RENDER_DEVICE_EXTERNAL   2
2030
2031 /* Currently defined display attribute types */
2032 typedef enum
2033 {
2034     VADisplayAttribBrightness           = 0,
2035     VADisplayAttribContrast             = 1,
2036     VADisplayAttribHue                  = 2,
2037     VADisplayAttribSaturation           = 3,
2038     /* client can specifiy a background color for the target window
2039      * the new feature of video conference,
2040      * the uncovered area of the surface is filled by this color
2041      * also it will blend with the decoded video color
2042      */
2043     VADisplayAttribBackgroundColor      = 4,
2044     /*
2045      * this is a gettable only attribute. For some implementations that use the
2046      * hardware overlay, after PutSurface is called, the surface can not be    
2047      * re-used until after the subsequent PutSurface call. If this is the case 
2048      * then the value for this attribute will be set to 1 so that the client   
2049      * will not attempt to re-use the surface right after returning from a call
2050      * to PutSurface.
2051      *
2052      * Don't use it, use flag VASurfaceDisplaying of vaQuerySurfaceStatus since
2053      * driver may use overlay or GPU alternatively
2054      */
2055     VADisplayAttribDirectSurface       = 5,
2056     VADisplayAttribRotation            = 6,     
2057     VADisplayAttribOutofLoopDeblock    = 7,
2058
2059     /* PowerVR IEP Lite specific attributes */
2060     VADisplayAttribBLEBlackMode        = 8,
2061     VADisplayAttribBLEWhiteMode        = 9,
2062     VADisplayAttribBlueStretch         = 10,
2063     VADisplayAttribSkinColorCorrection = 11,
2064     /*
2065      * For type VADisplayAttribCSCMatrix, "value" field is a pointer to the color
2066      * conversion matrix. Each element in the matrix is float-point
2067      */
2068     VADisplayAttribCSCMatrix           = 12,
2069     /* specify the constant color used to blend with video surface
2070      * Cd = Cv*Cc*Ac + Cb *(1 - Ac) C means the constant RGB
2071      *      d: the final color to overwrite into the frame buffer 
2072      *      v: decoded video after color conversion, 
2073      *      c: video color specified by VADisplayAttribBlendColor
2074      *      b: background color of the drawable
2075      */
2076     VADisplayAttribBlendColor          = 13,
2077     /*
2078      * Indicate driver to skip painting color key or not.
2079      * only applicable if the render is overlay
2080      */
2081     VADisplayAttribOverlayAutoPaintColorKey   = 14,
2082     /*
2083      * customized overlay color key, the format is RGB888
2084      * [23:16] = Red, [15:08] = Green, [07:00] = Blue.
2085      */
2086     VADisplayAttribOverlayColorKey      = 15,
2087     /*
2088      * The hint for the implementation of vaPutSurface
2089      * normally, the driver could use an overlay or GPU to render the surface on the screen
2090      * this flag provides APP the flexibity to switch the render dynamically
2091      */
2092     VADisplayAttribRenderMode           = 16,
2093     /*
2094      * specify if vaPutSurface needs to render into specified monitors
2095      * one example is that one external monitor (e.g. HDMI) is enabled, 
2096      * but the window manager is not aware of it, and there is no associated drawable
2097      */
2098     VADisplayAttribRenderDevice        = 17,
2099     /*
2100      * specify vaPutSurface render area if there is no drawable on the monitor
2101      */
2102     VADisplayAttribRenderRect          = 18,
2103 } VADisplayAttribType;
2104
2105 /* flags for VADisplayAttribute */
2106 #define VA_DISPLAY_ATTRIB_NOT_SUPPORTED 0x0000
2107 #define VA_DISPLAY_ATTRIB_GETTABLE      0x0001
2108 #define VA_DISPLAY_ATTRIB_SETTABLE      0x0002
2109
2110 typedef struct _VADisplayAttribute
2111 {
2112     VADisplayAttribType type;
2113     int min_value;
2114     int max_value;
2115     int value;  /* used by the set/get attribute functions */
2116 /* flags can be VA_DISPLAY_ATTRIB_GETTABLE or VA_DISPLAY_ATTRIB_SETTABLE or OR'd together */
2117     unsigned int flags;
2118 } VADisplayAttribute;
2119
2120 /* Get maximum number of display attributs supported by the implementation */
2121 int vaMaxNumDisplayAttributes (
2122     VADisplay dpy
2123 );
2124
2125 /* 
2126  * Query display attributes 
2127  * The caller must provide a "attr_list" array that can hold at
2128  * least vaMaxNumDisplayAttributes() entries. The actual number of attributes
2129  * returned in "attr_list" is returned in "num_attributes".
2130  */
2131 VAStatus vaQueryDisplayAttributes (
2132     VADisplay dpy,
2133     VADisplayAttribute *attr_list,      /* out */
2134     int *num_attributes                 /* out */
2135 );
2136
2137 /* 
2138  * Get display attributes 
2139  * This function returns the current attribute values in "attr_list".
2140  * Only attributes returned with VA_DISPLAY_ATTRIB_GETTABLE set in the "flags" field
2141  * from vaQueryDisplayAttributes() can have their values retrieved.  
2142  */
2143 VAStatus vaGetDisplayAttributes (
2144     VADisplay dpy,
2145     VADisplayAttribute *attr_list,      /* in/out */
2146     int num_attributes
2147 );
2148
2149 /* 
2150  * Set display attributes 
2151  * Only attributes returned with VA_DISPLAY_ATTRIB_SETTABLE set in the "flags" field
2152  * from vaQueryDisplayAttributes() can be set.  If the attribute is not settable or 
2153  * the value is out of range, the function returns VA_STATUS_ERROR_ATTR_NOT_SUPPORTED
2154  */
2155 VAStatus vaSetDisplayAttributes (
2156     VADisplay dpy,
2157     VADisplayAttribute *attr_list,
2158     int num_attributes
2159 );
2160
2161 #ifdef __cplusplus
2162 }
2163 #endif
2164
2165 #endif /* _VA_H_ */