OSDN Git Service

H264 FEI support
[android-x86/hardware-intel-common-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 /**
72  * \file va.h
73  * \brief The Core API
74  *
75  * This file contains the \ref api_core "Core API".
76  */
77
78 #ifndef _VA_H_
79 #define _VA_H_
80
81 #include <stddef.h>
82 #include <stdint.h>
83 #include <va/va_version.h>
84
85 #ifdef __cplusplus
86 extern "C" {
87 #endif
88
89 /**
90  * \mainpage Video Acceleration (VA) API
91  *
92  * \section intro Introduction
93  *
94  * The main motivation for VA-API (Video Acceleration API) is to
95  * enable hardware accelerated video decode and encode at various
96  * entry-points (VLD, IDCT, Motion Compensation etc.) for the
97  * prevailing coding standards today (MPEG-2, MPEG-4 ASP/H.263, MPEG-4
98  * AVC/H.264, VC-1/VMW3, and JPEG).
99  *
100  * VA-API is split into several modules:
101  * - \ref api_core
102  * - \ref api_enc_h264
103  * - \ref api_vpp
104  */
105
106 /**
107  * \defgroup api_core Core API
108  *
109  * @{
110  */
111
112 /**
113 Overview 
114
115 The VA API is intended to provide an interface between a video decode/encode/display
116 application (client) and a hardware accelerator (server), to off-load 
117 video decode/encode/display operations from the host to the hardware accelerator at various 
118 entry-points.
119
120 The basic operation steps are:
121
122 - Negotiate a mutually acceptable configuration with the server to lock
123   down profile, entrypoints, and other attributes that will not change on 
124   a frame-by-frame basis.
125 - Create a decode context which represents a "virtualized" hardware decode 
126   device
127 - Get and fill decode buffers with picture level, slice level and macroblock 
128   level data (depending on entrypoints)
129 - Pass the decode buffers to the server to decode the current frame
130
131 Initialization & Configuration Management 
132
133 - Find out supported profiles
134 - Find out entrypoints for a given profile
135 - Find out configuration attributes for a given profile/entrypoint pair
136 - Create a configuration for use by the decoder
137
138 */
139
140 typedef void* VADisplay;        /* window system dependent */
141
142 typedef int VAStatus;   /** Return status type from functions */
143 /** Values for the return status */
144 #define VA_STATUS_SUCCESS                       0x00000000
145 #define VA_STATUS_ERROR_OPERATION_FAILED        0x00000001
146 #define VA_STATUS_ERROR_ALLOCATION_FAILED       0x00000002
147 #define VA_STATUS_ERROR_INVALID_DISPLAY         0x00000003
148 #define VA_STATUS_ERROR_INVALID_CONFIG          0x00000004
149 #define VA_STATUS_ERROR_INVALID_CONTEXT         0x00000005
150 #define VA_STATUS_ERROR_INVALID_SURFACE         0x00000006
151 #define VA_STATUS_ERROR_INVALID_BUFFER          0x00000007
152 #define VA_STATUS_ERROR_INVALID_IMAGE           0x00000008
153 #define VA_STATUS_ERROR_INVALID_SUBPICTURE      0x00000009
154 #define VA_STATUS_ERROR_ATTR_NOT_SUPPORTED      0x0000000a
155 #define VA_STATUS_ERROR_MAX_NUM_EXCEEDED        0x0000000b
156 #define VA_STATUS_ERROR_UNSUPPORTED_PROFILE     0x0000000c
157 #define VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT  0x0000000d
158 #define VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT   0x0000000e
159 #define VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE  0x0000000f
160 #define VA_STATUS_ERROR_SURFACE_BUSY            0x00000010
161 #define VA_STATUS_ERROR_FLAG_NOT_SUPPORTED      0x00000011
162 #define VA_STATUS_ERROR_INVALID_PARAMETER       0x00000012
163 #define VA_STATUS_ERROR_RESOLUTION_NOT_SUPPORTED 0x00000013
164 #define VA_STATUS_ERROR_UNIMPLEMENTED           0x00000014
165 #define VA_STATUS_ERROR_SURFACE_IN_DISPLAYING   0x00000015
166 #define VA_STATUS_ERROR_INVALID_IMAGE_FORMAT    0x00000016
167 #define VA_STATUS_ERROR_DECODING_ERROR          0x00000017
168 #define VA_STATUS_ERROR_ENCODING_ERROR          0x00000018
169 /**
170  * \brief An invalid/unsupported value was supplied.
171  *
172  * This is a catch-all error code for invalid or unsupported values.
173  * e.g. value exceeding the valid range, invalid type in the context
174  * of generic attribute values.
175  */
176 #define VA_STATUS_ERROR_INVALID_VALUE           0x00000019
177 /** \brief An unsupported filter was supplied. */
178 #define VA_STATUS_ERROR_UNSUPPORTED_FILTER      0x00000020
179 /** \brief An invalid filter chain was supplied. */
180 #define VA_STATUS_ERROR_INVALID_FILTER_CHAIN    0x00000021
181 /** \brief Indicate HW busy (e.g. run multiple encoding simultaneously). */
182 #define VA_STATUS_ERROR_HW_BUSY                 0x00000022
183 /** \brief An unsupported memory type was supplied. */
184 #define VA_STATUS_ERROR_UNSUPPORTED_MEMORY_TYPE 0x00000024
185 #define VA_STATUS_ERROR_UNKNOWN                 0xFFFFFFFF
186
187 /** De-interlacing flags for vaPutSurface() */
188 #define VA_FRAME_PICTURE        0x00000000 
189 #define VA_TOP_FIELD            0x00000001
190 #define VA_BOTTOM_FIELD         0x00000002
191
192 /**
193  * Enabled the positioning/cropping/blending feature:
194  * 1, specify the video playback position in the isurface
195  * 2, specify the cropping info for video playback
196  * 3, encoded video will blend with background color
197  */
198 #define VA_ENABLE_BLEND         0x00000004 /* video area blend with the constant color */ 
199     
200 /**
201  * Clears the drawable with background color.
202  * for hardware overlay based implementation this flag
203  * can be used to turn off the overlay
204  */
205 #define VA_CLEAR_DRAWABLE       0x00000008
206
207 /** Color space conversion flags for vaPutSurface() */
208 #define VA_SRC_COLOR_MASK       0x000000f0
209 #define VA_SRC_BT601            0x00000010
210 #define VA_SRC_BT709            0x00000020
211 #define VA_SRC_SMPTE_240        0x00000040
212
213 /** Scaling flags for vaPutSurface() */
214 #define VA_FILTER_SCALING_DEFAULT       0x00000000
215 #define VA_FILTER_SCALING_FAST          0x00000100
216 #define VA_FILTER_SCALING_HQ            0x00000200
217 #define VA_FILTER_SCALING_NL_ANAMORPHIC 0x00000300
218 #define VA_FILTER_SCALING_MASK          0x00000f00
219
220 /**
221  * Returns a short english description of error_status
222  */
223 const char *vaErrorStr(VAStatus error_status);
224
225 typedef struct _VARectangle
226 {
227     short x;
228     short y;
229     unsigned short width;
230     unsigned short height;
231 } VARectangle;
232
233 /** \brief Generic motion vector data structure. */
234 typedef struct _VAMotionVector {
235     /** \mv0[0]: horizontal motion vector for past reference */
236     /** \mv0[1]: vertical motion vector for past reference */
237     /** \mv1[0]: horizontal motion vector for future reference */
238     /** \mv1[1]: vertical motion vector for future reference */
239     int16_t  mv0[2];  /* past reference */
240     int16_t  mv1[2];  /* future reference */
241 } VAMotionVector;
242
243 /** Type of a message callback, used for both error and info log. */
244 typedef void (*vaMessageCallback)(const char *message);
245
246 /**
247  * Set the callback for error messages, or NULL for no logging.
248  * Returns the previous one, or NULL if it was disabled.
249  */
250 vaMessageCallback vaSetErrorCallback(vaMessageCallback);
251
252 /**
253  * Set the callback for info messages, or NULL for no logging.
254  * Returns the previous one, or NULL if it was disabled.
255  */
256 vaMessageCallback vaSetInfoCallback(vaMessageCallback);
257
258 /**
259  * Initialization:
260  * A display must be obtained by calling vaGetDisplay() before calling
261  * vaInitialize() and other functions. This connects the API to the 
262  * native window system.
263  * For X Windows, native_dpy would be from XOpenDisplay()
264  */
265 typedef void* VANativeDisplay;  /* window system dependent */
266
267 int vaDisplayIsValid(VADisplay dpy);
268
269 /**
270  *  Set the override driver name instead of queried driver driver.
271  */
272 VAStatus vaSetDriverName(VADisplay dpy,
273                          char *driver_name
274 );
275
276 /**
277  * Initialize the library 
278  */
279 VAStatus vaInitialize (
280     VADisplay dpy,
281     int *major_version,  /* out */
282     int *minor_version   /* out */
283 );
284
285 /**
286  * After this call, all library internal resources will be cleaned up
287  */ 
288 VAStatus vaTerminate (
289     VADisplay dpy
290 );
291
292 /**
293  * vaQueryVendorString returns a pointer to a zero-terminated string
294  * describing some aspects of the VA implemenation on a specific    
295  * hardware accelerator. The format of the returned string is vendor
296  * specific and at the discretion of the implementer.
297  * e.g. for the Intel GMA500 implementation, an example would be:
298  * "Intel GMA500 - 2.0.0.32L.0005"
299  */
300 const char *vaQueryVendorString (
301     VADisplay dpy
302 );
303
304 typedef int (*VAPrivFunc)(void);
305
306 /**
307  * Return a function pointer given a function name in the library.
308  * This allows private interfaces into the library
309  */ 
310 VAPrivFunc vaGetLibFunc (
311     VADisplay dpy,
312     const char *func
313 );
314
315 /** Currently defined profiles */
316 typedef enum
317 {
318     /** \brief Profile ID used for video processing. */
319     VAProfileNone                       = -1,
320     VAProfileMPEG2Simple                = 0,
321     VAProfileMPEG2Main                  = 1,
322     VAProfileMPEG4Simple                = 2,
323     VAProfileMPEG4AdvancedSimple        = 3,
324     VAProfileMPEG4Main                  = 4,
325     VAProfileH264Baseline               = 5,
326     VAProfileH264Main                   = 6,
327     VAProfileH264High                   = 7,
328     VAProfileVC1Simple                  = 8,
329     VAProfileVC1Main                    = 9,
330     VAProfileVC1Advanced                = 10,
331     VAProfileH263Baseline               = 11,
332     VAProfileJPEGBaseline               = 12,
333     VAProfileH264ConstrainedBaseline    = 13,
334     VAProfileVP8Version0_3              = 14,
335     VAProfileH264MultiviewHigh          = 15,
336     VAProfileH264StereoHigh             = 16,
337     VAProfileHEVCMain                   = 17,
338     VAProfileHEVCMain10                 = 18,
339     VAProfileVP9Profile0                = 19,
340     VAProfileVP9Profile1                = 20,
341     VAProfileVP9Profile2                = 21,
342     VAProfileVP9Profile3                = 22
343 } VAProfile;
344
345 /**
346  *  Currently defined entrypoints 
347  */
348 typedef enum
349 {
350     VAEntrypointVLD             = 1,
351     VAEntrypointIZZ             = 2,
352     VAEntrypointIDCT            = 3,
353     VAEntrypointMoComp          = 4,
354     VAEntrypointDeblocking      = 5,
355     VAEntrypointEncSlice        = 6,    /* slice level encode */
356     VAEntrypointEncPicture      = 7,    /* pictuer encode, JPEG, etc */
357     /*
358      * For an implementation that supports a low power/high performance variant
359      * for slice level encode, it can choose to expose the
360      * VAEntrypointEncSliceLP entrypoint. Certain encoding tools may not be
361      * available with this entrypoint (e.g. interlace, MBAFF) and the
362      * application can query the encoding configuration attributes to find
363      * out more details if this entrypoint is supported.
364      */
365     VAEntrypointEncSliceLP      = 8,
366     VAEntrypointVideoProc       = 10,   /**< Video pre/post-processing. */
367     /**
368      * \brief VAEntrypointFEI
369      *
370      * The purpose of FEI (Flexible Encoding Infrastructure) is to allow applications to
371      * have more controls and trade off quality for speed with their own IPs.
372      * The application can optionally provide input to ENC for extra encode control
373      * and get the output from ENC. Application can chose to modify the ENC
374      * output/PAK input during encoding, but the performance impact is significant.
375      *
376      * On top of the existing buffers for normal encode, there will be
377      * one extra input buffer (VAEncMiscParameterFEIFrameControl) and
378      * three extra output buffers (VAEncFEIMVBufferType, VAEncFEIMBModeBufferType
379      * and VAEncFEIDistortionBufferType) for VAEntrypointFEI entry function.
380      * If separate PAK is set, two extra input buffers
381      * (VAEncFEIMVBufferType, VAEncFEIMBModeBufferType) are needed for PAK input.
382      **/
383     VAEntrypointFEI         = 11,
384 } VAEntrypoint;
385
386 /** Currently defined configuration attribute types */
387 typedef enum
388 {
389     VAConfigAttribRTFormat              = 0,
390     VAConfigAttribSpatialResidual       = 1,
391     VAConfigAttribSpatialClipping       = 2,
392     VAConfigAttribIntraResidual         = 3,
393     VAConfigAttribEncryption            = 4,
394     VAConfigAttribRateControl           = 5,
395
396     /** @name Attributes for decoding */
397     /**@{*/
398     /**
399      * \brief Slice Decoding mode. Read/write.
400      *
401      * This attribute determines what mode the driver supports for slice
402      * decoding, through vaGetConfigAttributes(); and what mode the user
403      * will be providing to the driver, through vaCreateConfig(), if the
404      * driver supports those. If this attribute is not set by the user then
405      * it is assumed that VA_DEC_SLICE_MODE_NORMAL mode is used.
406      *
407      * See \c VA_DEC_SLICE_MODE_xxx for the list of slice decoding modes.
408      */
409     VAConfigAttribDecSliceMode          = 6,
410
411     /** @name Attributes for encoding */
412     /**@{*/
413     /**
414      * \brief Packed headers mode. Read/write.
415      *
416      * This attribute determines what packed headers the driver supports,
417      * through vaGetConfigAttributes(); and what packed headers the user
418      * will be providing to the driver, through vaCreateConfig(), if the
419      * driver supports those.
420      *
421      * See \c VA_ENC_PACKED_HEADER_xxx for the list of packed headers.
422      */
423     VAConfigAttribEncPackedHeaders      = 10,
424     /**
425      * \brief Interlaced mode. Read/write.
426      *
427      * This attribute determines what kind of interlaced encoding mode
428      * the driver supports.
429      *
430      * See \c VA_ENC_INTERLACED_xxx for the list of interlaced modes.
431      */
432     VAConfigAttribEncInterlaced         = 11,
433     /**
434      * \brief Maximum number of reference frames. Read-only.
435      *
436      * This attribute determines the maximum number of reference
437      * frames supported for encoding.
438      *
439      * Note: for H.264 encoding, the value represents the maximum number
440      * of reference frames for both the reference picture list 0 (bottom
441      * 16 bits) and the reference picture list 1 (top 16 bits).
442      */
443     VAConfigAttribEncMaxRefFrames       = 13,
444     /**
445      * \brief Maximum number of slices per frame. Read-only.
446      *
447      * This attribute determines the maximum number of slices the
448      * driver can support to encode a single frame.
449      */
450     VAConfigAttribEncMaxSlices          = 14,
451     /**
452      * \brief Slice structure. Read-only.
453      *
454      * This attribute determines slice structures supported by the
455      * driver for encoding. This attribute is a hint to the user so
456      * that he can choose a suitable surface size and how to arrange
457      * the encoding process of multiple slices per frame.
458      *
459      * More specifically, for H.264 encoding, this attribute
460      * determines the range of accepted values to
461      * VAEncSliceParameterBufferH264::macroblock_address and
462      * VAEncSliceParameterBufferH264::num_macroblocks.
463      *
464      * See \c VA_ENC_SLICE_STRUCTURE_xxx for the supported slice
465      * structure types.
466      */
467     VAConfigAttribEncSliceStructure     = 15,
468     /**
469      * \brief Macroblock information. Read-only.
470      *
471      * This attribute determines whether the driver supports extra
472      * encoding information per-macroblock. e.g. QP.
473      *
474      * More specifically, for H.264 encoding, if the driver returns a non-zero
475      * value for this attribute, this means the application can create
476      * additional #VAEncMacroblockParameterBufferH264 buffers referenced
477      * through VAEncSliceParameterBufferH264::macroblock_info.
478      */
479     VAConfigAttribEncMacroblockInfo     = 16,
480     /**
481      * \brief JPEG encoding attribute. Read-only.
482      *
483      * This attribute exposes a number of capabilities of the underlying
484      * JPEG implementation. The attribute value is partitioned into fields as defined in the 
485      * VAConfigAttribValEncJPEG union.
486      */
487     VAConfigAttribEncJPEG             = 20,
488     /**
489      * \brief Encoding quality range attribute. Read-only.
490      *
491      * This attribute conveys whether the driver supports different quality level settings
492      * for encoding. A value less than or equal to 1 means that the encoder only has a single
493      * quality setting, and a value greater than 1 represents the number of quality levels 
494      * that can be configured. e.g. a value of 2 means there are two distinct quality levels. 
495      */
496     VAConfigAttribEncQualityRange     = 21,
497     /**
498      * \brief Encoding skip frame attribute. Read-only.
499      *
500      * This attribute conveys whether the driver supports sending skip frame parameters 
501      * (VAEncMiscParameterTypeSkipFrame) to the encoder's rate control, when the user has 
502      * externally skipped frames. 
503      */
504     VAConfigAttribEncSkipFrame        = 24,
505     /**
506      * \brief Encoding region-of-interest (ROI) attribute. Read-only.
507      *
508      * This attribute conveys whether the driver supports region-of-interest (ROI) encoding,
509      * based on user provided ROI rectangles.  The attribute value is partitioned into fields
510      * as defined in the VAConfigAttribValEncROI union.
511      *
512      * If ROI encoding is supported, the ROI information is passed to the driver using
513      * VAEncMiscParameterTypeROI.
514      */
515     VAConfigAttribEncROI              = 25,
516     /**
517      * \brief Encoding extended rate control attribute. Read-only.
518      *
519      * This attribute conveys whether the driver supports any extended rate control features
520      * The attribute value is partitioned into fields as defined in the
521      * VAConfigAttribValEncRateControlExt union.
522      */
523     VAConfigAttribEncRateControlExt   = 26,
524
525     /**
526      * \brief Encode function type for FEI.
527      *
528      * This attribute conveys whether the driver supports different function types for encode.
529      * It can be VA_FEI_FUNCTION_ENC, VA_FEI_FUNCTION_PAK, or VA_FEI_FUNCTION_ENC_PAK. Currently
530      * it is for FEI entry point only.
531      * Default is VA_FEI_FUNCTION_ENC_PAK.
532      */
533     VAConfigAttribFEIFunctionType     = 32,
534     /**
535      * \brief Maximum number of FEI MV predictors. Read-only.
536      *
537      * This attribute determines the maximum number of MV predictors the driver
538      * can support to encode a single frame. 0 means no MV predictor is supported.
539      * Currently it is for FEI entry point only.
540      */
541     VAConfigAttribFEIMVPredictors     = 33,
542     /**@}*/
543     VAConfigAttribTypeMax
544 } VAConfigAttribType;
545
546 /**
547  * Configuration attributes
548  * If there is more than one value for an attribute, a default
549  * value will be assigned to the attribute if the client does not
550  * specify the attribute when creating a configuration
551  */
552 typedef struct _VAConfigAttrib {
553     VAConfigAttribType type;
554     unsigned int value; /* OR'd flags (bits) for this attribute */
555 } VAConfigAttrib;
556
557 /** attribute value for VAConfigAttribRTFormat */
558 #define VA_RT_FORMAT_YUV420     0x00000001      
559 #define VA_RT_FORMAT_YUV422     0x00000002
560 #define VA_RT_FORMAT_YUV444     0x00000004
561 #define VA_RT_FORMAT_YUV411     0x00000008
562 #define VA_RT_FORMAT_YUV400     0x00000010
563 /** YUV formats with more than 8 bpp */
564 #define VA_RT_FORMAT_YUV420_10BPP       0x00000100
565 /** RGB formats */
566 #define VA_RT_FORMAT_RGB16      0x00010000
567 #define VA_RT_FORMAT_RGB32      0x00020000
568 /* RGBP covers RGBP and BGRP fourcc */ 
569 #define VA_RT_FORMAT_RGBP       0x00100000
570 #define VA_RT_FORMAT_PROTECTED  0x80000000
571
572 /** @name Attribute values for VAConfigAttribRateControl */
573 /**@{*/
574 /** \brief Driver does not support any form of rate control. */
575 #define VA_RC_NONE                      0x00000001
576 /** \brief Constant bitrate. */
577 #define VA_RC_CBR                       0x00000002
578 /** \brief Variable bitrate. */
579 #define VA_RC_VBR                       0x00000004
580 /** \brief Video conference mode. */
581 #define VA_RC_VCM                       0x00000008
582 /** \brief Constant QP. */
583 #define VA_RC_CQP                       0x00000010
584 /** \brief Variable bitrate with peak rate higher than average bitrate. */
585 #define VA_RC_VBR_CONSTRAINED           0x00000020
586 /** \brief Macroblock based rate control.  Per MB control is decided
587  *  internally in the encoder. It may be combined with other RC modes, except CQP. */
588 #define VA_RC_MB                        0x00000080
589
590 /**@}*/
591
592 /** @name Attribute values for VAConfigAttribDecSliceMode */
593 /**@{*/
594 /** \brief Driver supports normal mode for slice decoding */
595 #define VA_DEC_SLICE_MODE_NORMAL       0x00000001
596 /** \brief Driver supports base mode for slice decoding */
597 #define VA_DEC_SLICE_MODE_BASE         0x00000002
598 /**@}*/
599
600 /** @name Attribute values for VAConfigAttribEncPackedHeaders */
601 /**@{*/
602 /** \brief Driver does not support any packed headers mode. */
603 #define VA_ENC_PACKED_HEADER_NONE       0x00000000
604 /** \brief Driver supports packed sequence headers. e.g. SPS for H.264. */
605 #define VA_ENC_PACKED_HEADER_SEQUENCE   0x00000001
606 /** \brief Driver supports packed picture headers. e.g. PPS for H.264. */
607 #define VA_ENC_PACKED_HEADER_PICTURE    0x00000002
608 /** \brief Driver supports packed slice headers. e.g. \c slice_header() for H.264. */
609 #define VA_ENC_PACKED_HEADER_SLICE      0x00000004
610 /** \brief Driver supports misc packed headers. e.g. SEI for H.264. */
611 #define VA_ENC_PACKED_HEADER_MISC       0x00000008
612 /** \brief Driver supports raw packed header, see VAEncPackedHeaderRawData */
613 #define VA_ENC_PACKED_HEADER_RAW_DATA   0x00000010
614 /**@}*/
615
616 /** @name Attribute values for VAConfigAttribEncInterlaced */
617 /**@{*/
618 /** \brief Driver does not support interlaced coding. */
619 #define VA_ENC_INTERLACED_NONE          0x00000000
620 /** \brief Driver supports interlaced frame coding. */
621 #define VA_ENC_INTERLACED_FRAME         0x00000001
622 /** \brief Driver supports interlaced field coding. */
623 #define VA_ENC_INTERLACED_FIELD         0x00000002
624 /** \brief Driver supports macroblock adaptive frame field coding. */
625 #define VA_ENC_INTERLACED_MBAFF         0x00000004
626 /** \brief Driver supports picture adaptive frame field coding. */
627 #define VA_ENC_INTERLACED_PAFF          0x00000008
628 /**@}*/
629
630 /** @name Attribute values for VAConfigAttribEncSliceStructure */
631 /**@{*/
632 /** \brief Driver supports an arbitrary number of rows per slice. */
633 #define VA_ENC_SLICE_STRUCTURE_ARBITRARY_ROWS           0x00000000
634 /** \brief Driver supports a power-of-two number of rows per slice. */
635 #define VA_ENC_SLICE_STRUCTURE_POWER_OF_TWO_ROWS        0x00000001
636 /** \brief Driver supports an arbitrary number of macroblocks per slice. */
637 #define VA_ENC_SLICE_STRUCTURE_ARBITRARY_MACROBLOCKS    0x00000002
638 /**@}*/
639
640 /** \brief Attribute value for VAConfigAttribEncJPEG */
641 typedef union _VAConfigAttribValEncJPEG {
642     struct {
643         /** \brief set to 1 for arithmatic coding. */
644         unsigned int arithmatic_coding_mode : 1;
645         /** \brief set to 1 for progressive dct. */
646         unsigned int progressive_dct_mode : 1;
647         /** \brief set to 1 for non-interleaved. */
648         unsigned int non_interleaved_mode : 1;
649         /** \brief set to 1 for differential. */
650         unsigned int differential_mode : 1;
651         unsigned int max_num_components : 3;
652         unsigned int max_num_scans : 4;
653         unsigned int max_num_huffman_tables : 3;
654         unsigned int max_num_quantization_tables : 3;
655     } bits;
656     unsigned int value;
657 } VAConfigAttribValEncJPEG;
658
659 /** \brief Attribute value for VAConfigAttribEncROI */
660 typedef union _VAConfigAttribValEncROI {
661     struct {
662         /** \brief The number of ROI regions supported, 0 if ROI is not supported. */
663         unsigned int num_roi_regions            : 8;
664         /**
665          * \brief A flag indicates whether ROI priority is supported
666          *
667          * \ref roi_rc_priority_support equal to 1 specifies the underlying driver supports
668          * ROI priority when VAConfigAttribRateControl != VA_RC_CQP, user can use \c roi_value
669          * in #VAEncROI to set ROI priority. \ref roi_rc_priority_support equal to 0 specifies
670          * the underlying driver doesn't support ROI priority.
671          *
672          * User should ignore \ref roi_rc_priority_support when VAConfigAttribRateControl == VA_RC_CQP
673          * because ROI delta QP is always required when VAConfigAttribRateControl == VA_RC_CQP.
674          */
675         unsigned int roi_rc_priority_support    : 1;
676         /**
677          * \brief A flag indicates whether ROI delta QP is supported
678          *
679          * \ref roi_rc_qp_delat_support equal to 1 specifies the underlying driver supports
680          * ROI delta QP when VAConfigAttribRateControl != VA_RC_CQP, user can use \c roi_value
681          * in #VAEncROI to set ROI delta QP. \ref roi_rc_qp_delat_support equal to 0 specifies
682          * the underlying driver doesn't support ROI delta QP.
683          *
684          * User should ignore \ref roi_rc_qp_delat_support when VAConfigAttribRateControl == VA_RC_CQP
685          * because ROI delta QP is always required when VAConfigAttribRateControl == VA_RC_CQP.
686          */
687         unsigned int roi_rc_qp_delat_support    : 1;
688         unsigned int reserved                   : 22;
689      } bits;
690      unsigned int value;
691 } VAConfigAttribValEncROI;
692
693 /** \brief Attribute value for VAConfigAttribEncRateControlExt */
694 typedef union _VAConfigAttribValEncRateControlExt {
695     struct {
696         /**
697          * \brief The maximum number of temporal layers minus 1
698          *
699          * \ref max_num_temporal_layers_minus1 plus 1 specifies the maximum number of temporal
700          * layers that supported by the underlying driver. \ref max_num_temporal_layers_minus1
701          * equal to 0 implies the underlying driver doesn't support encoding with temporal layer.
702          */
703         unsigned int max_num_temporal_layers_minus1      : 8;
704
705         /**
706          * /brief support temporal layer bit-rate control flag
707          *
708          * \ref temporal_layer_bitrate_control_flag equal to 1 specifies the underlying driver
709          * can support bit-rate control per temporal layer when (#VAConfigAttribRateControl == #VA_RC_CBR ||
710          * #VAConfigAttribRateControl == #VA_RC_VBR).
711          *
712          * The underlying driver must set \ref temporal_layer_bitrate_control_flag to 0 when
713          * \c max_num_temporal_layers_minus1 is equal to 0
714          *
715          * To use bit-rate control per temporal layer, an application must send the right layer
716          * structure via #VAEncMiscParameterTemporalLayerStructure at the beginning of a coded sequence
717          * and then followed by #VAEncMiscParameterRateControl and #VAEncMiscParameterFrameRate structures
718          * for each layer, using the \c temporal_id field as the layer identifier. Otherwise
719          * the driver doesn't use bitrate control per temporal layer if an application doesn't send the
720          * layer structure via #VAEncMiscParameterTemporalLayerStructure to the driver. The driver returns
721          * VA_STATUS_ERROR_INVALID_PARAMETER if an application sends a wrong layer structure or doesn't send
722          * #VAEncMiscParameterRateControl and #VAEncMiscParameterFrameRate for each layer.
723          *
724          * The driver will ignore #VAEncMiscParameterTemporalLayerStructure and the \c temporal_id field
725          * in #VAEncMiscParameterRateControl and #VAEncMiscParameterFrameRate if
726          * \ref temporal_layer_bitrate_control_flag is equal to 0 or #VAConfigAttribRateControl == #VA_RC_CQP
727          */
728         unsigned int temporal_layer_bitrate_control_flag : 1;
729         unsigned int reserved                            : 23;
730     } bits;
731     unsigned int value;
732 } VAConfigAttribValEncRateControlExt;
733
734 /**
735  * if an attribute is not applicable for a given
736  * profile/entrypoint pair, then set the value to the following 
737  */
738 #define VA_ATTRIB_NOT_SUPPORTED 0x80000000
739
740 /** Get maximum number of profiles supported by the implementation */
741 int vaMaxNumProfiles (
742     VADisplay dpy
743 );
744
745 /** Get maximum number of entrypoints supported by the implementation */
746 int vaMaxNumEntrypoints (
747     VADisplay dpy
748 );
749
750 /** Get maximum number of attributs supported by the implementation */
751 int vaMaxNumConfigAttributes (
752     VADisplay dpy
753 );
754
755 /**
756  * Query supported profiles 
757  * The caller must provide a "profile_list" array that can hold at
758  * least vaMaxNumProfile() entries. The actual number of profiles
759  * returned in "profile_list" is returned in "num_profile".
760  */
761 VAStatus vaQueryConfigProfiles (
762     VADisplay dpy,
763     VAProfile *profile_list,    /* out */
764     int *num_profiles           /* out */
765 );
766
767 /**
768  * Query supported entrypoints for a given profile 
769  * The caller must provide an "entrypoint_list" array that can hold at
770  * least vaMaxNumEntrypoints() entries. The actual number of entrypoints 
771  * returned in "entrypoint_list" is returned in "num_entrypoints".
772  */
773 VAStatus vaQueryConfigEntrypoints (
774     VADisplay dpy,
775     VAProfile profile,
776     VAEntrypoint *entrypoint_list,      /* out */
777     int *num_entrypoints                /* out */
778 );
779
780 /**
781  * Get attributes for a given profile/entrypoint pair 
782  * The caller must provide an "attrib_list" with all attributes to be 
783  * retrieved.  Upon return, the attributes in "attrib_list" have been 
784  * updated with their value.  Unknown attributes or attributes that are 
785  * not supported for the given profile/entrypoint pair will have their 
786  * value set to VA_ATTRIB_NOT_SUPPORTED
787  */
788 VAStatus vaGetConfigAttributes (
789     VADisplay dpy,
790     VAProfile profile,
791     VAEntrypoint entrypoint,
792     VAConfigAttrib *attrib_list, /* in/out */
793     int num_attribs
794 );
795
796 /** Generic ID type, can be re-typed for specific implementation */
797 typedef unsigned int VAGenericID;
798
799 typedef VAGenericID VAConfigID;
800
801 /**
802  * Create a configuration for the decode pipeline 
803  * it passes in the attribute list that specifies the attributes it cares 
804  * about, with the rest taking default values.  
805  */
806 VAStatus vaCreateConfig (
807     VADisplay dpy,
808     VAProfile profile, 
809     VAEntrypoint entrypoint, 
810     VAConfigAttrib *attrib_list,
811     int num_attribs,
812     VAConfigID *config_id /* out */
813 );
814
815 /**
816  * Free resources associdated with a given config 
817  */
818 VAStatus vaDestroyConfig (
819     VADisplay dpy,
820     VAConfigID config_id
821 );
822
823 /**
824  * Query all attributes for a given configuration 
825  * The profile of the configuration is returned in "profile"
826  * The entrypoint of the configuration is returned in "entrypoint"
827  * The caller must provide an "attrib_list" array that can hold at least 
828  * vaMaxNumConfigAttributes() entries. The actual number of attributes 
829  * returned in "attrib_list" is returned in "num_attribs"
830  */
831 VAStatus vaQueryConfigAttributes (
832     VADisplay dpy,
833     VAConfigID config_id, 
834     VAProfile *profile,         /* out */
835     VAEntrypoint *entrypoint,   /* out */
836     VAConfigAttrib *attrib_list,/* out */
837     int *num_attribs            /* out */
838 );
839
840
841 /**
842  * Contexts and Surfaces
843  *
844  * Context represents a "virtual" video decode pipeline. Surfaces are render 
845  * targets for a given context. The data in the surfaces are not accessible  
846  * to the client and the internal data format of the surface is implementatin 
847  * specific. 
848  *
849  * Surfaces will be bound to a context when the context is created. Once
850  * a surface is bound to a given context, it can not be used to create  
851  * another context. The association is removed when the context is destroyed
852  * 
853  * Both contexts and surfaces are identified by unique IDs and its
854  * implementation specific internals are kept opaque to the clients
855  */
856
857 typedef VAGenericID VAContextID;
858
859 typedef VAGenericID VASurfaceID;
860
861 #define VA_INVALID_ID           0xffffffff
862 #define VA_INVALID_SURFACE      VA_INVALID_ID
863
864 /** \brief Generic value types. */
865 typedef enum  {
866     VAGenericValueTypeInteger = 1,      /**< 32-bit signed integer. */
867     VAGenericValueTypeFloat,            /**< 32-bit floating-point value. */
868     VAGenericValueTypePointer,          /**< Generic pointer type */
869     VAGenericValueTypeFunc              /**< Pointer to function */
870 } VAGenericValueType;
871
872 /** \brief Generic function type. */
873 typedef void (*VAGenericFunc)(void);
874
875 /** \brief Generic value. */
876 typedef struct _VAGenericValue {
877     /** \brief Value type. See #VAGenericValueType. */
878     VAGenericValueType  type;
879     /** \brief Value holder. */
880     union {
881         /** \brief 32-bit signed integer. */
882         int             i;
883         /** \brief 32-bit float. */
884         float           f;
885         /** \brief Generic pointer. */
886         void           *p;
887         /** \brief Pointer to function. */
888         VAGenericFunc   fn;
889     }                   value;
890 } VAGenericValue;
891
892 /** @name Surface attribute flags */
893 /**@{*/
894 /** \brief Surface attribute is not supported. */
895 #define VA_SURFACE_ATTRIB_NOT_SUPPORTED 0x00000000
896 /** \brief Surface attribute can be got through vaQuerySurfaceAttributes(). */
897 #define VA_SURFACE_ATTRIB_GETTABLE      0x00000001
898 /** \brief Surface attribute can be set through vaCreateSurfaces(). */
899 #define VA_SURFACE_ATTRIB_SETTABLE      0x00000002
900 /**@}*/
901
902 /** \brief Surface attribute types. */
903 typedef enum {
904     VASurfaceAttribNone = 0,
905     /**
906      * \brief Pixel format (fourcc).
907      *
908      * The value is meaningful as input to vaQuerySurfaceAttributes().
909      * If zero, the driver returns the optimal pixel format for the
910      * specified config. Otherwise, if non-zero, the value represents
911      * a pixel format (FOURCC) that is kept as is on output, if the
912      * driver supports it. Otherwise, the driver sets the value to
913      * zero and drops the \c VA_SURFACE_ATTRIB_SETTABLE flag.
914      */
915     VASurfaceAttribPixelFormat,
916     /** \brief Minimal width in pixels (int, read-only). */
917     VASurfaceAttribMinWidth,
918     /** \brief Maximal width in pixels (int, read-only). */
919     VASurfaceAttribMaxWidth,
920     /** \brief Minimal height in pixels (int, read-only). */
921     VASurfaceAttribMinHeight,
922     /** \brief Maximal height in pixels (int, read-only). */
923     VASurfaceAttribMaxHeight,
924     /** \brief Surface memory type expressed in bit fields (int, read/write). */
925     VASurfaceAttribMemoryType,
926     /** \brief External buffer descriptor (pointer, write). */
927     VASurfaceAttribExternalBufferDescriptor,
928     /** \brief Surface usage hint, gives the driver a hint of intended usage 
929      *  to optimize allocation (e.g. tiling) (int, read/write). */
930     VASurfaceAttribUsageHint,
931     /** \brief Number of surface attributes. */
932     VASurfaceAttribCount
933 } VASurfaceAttribType;
934
935 /** \brief Surface attribute. */
936 typedef struct _VASurfaceAttrib {
937     /** \brief Type. */
938     VASurfaceAttribType type;
939     /** \brief Flags. See "Surface attribute flags". */
940     unsigned int        flags;
941     /** \brief Value. See "Surface attribute types" for the expected types. */
942     VAGenericValue      value;
943 } VASurfaceAttrib;
944
945 /** 
946  * @name VASurfaceAttribMemoryType values in bit fields. 
947  * Bit 0:7 are reserved for generic types, Bit 31:28 are reserved for 
948  * Linux DRM, Bit 23:20 are reserved for Android. DRM and Android specific
949  * types are defined in DRM and Android header files.
950  */
951 /**@{*/
952 /** \brief VA memory type (default) is supported. */
953 #define VA_SURFACE_ATTRIB_MEM_TYPE_VA                   0x00000001
954 /** \brief V4L2 buffer memory type is supported. */
955 #define VA_SURFACE_ATTRIB_MEM_TYPE_V4L2                 0x00000002
956 /** \brief User pointer memory type is supported. */
957 #define VA_SURFACE_ATTRIB_MEM_TYPE_USER_PTR             0x00000004
958 /**@}*/
959
960 /** 
961  * \brief VASurfaceAttribExternalBuffers structure for 
962  * the VASurfaceAttribExternalBufferDescriptor attribute.
963  */
964 typedef struct _VASurfaceAttribExternalBuffers {
965     /** \brief pixel format in fourcc. */
966     unsigned int pixel_format;
967     /** \brief width in pixels. */
968     unsigned int width;
969     /** \brief height in pixels. */
970     unsigned int height;
971     /** \brief total size of the buffer in bytes. */
972     unsigned int data_size;
973     /** \brief number of planes for planar layout */
974     unsigned int num_planes;
975     /** \brief pitch for each plane in bytes */
976     unsigned int pitches[4];
977     /** \brief offset for each plane in bytes */
978     unsigned int offsets[4];
979     /** \brief buffer handles or user pointers */
980     unsigned long *buffers;
981     /** \brief number of elements in the "buffers" array */
982     unsigned int num_buffers;
983     /** \brief flags. See "Surface external buffer descriptor flags". */
984     unsigned int flags;
985     /** \brief reserved for passing private data */
986     void *private_data;
987 } VASurfaceAttribExternalBuffers;
988
989 /** @name VASurfaceAttribExternalBuffers flags */
990 /**@{*/
991 /** \brief Enable memory tiling */
992 #define VA_SURFACE_EXTBUF_DESC_ENABLE_TILING    0x00000001
993 /** \brief Memory is cacheable */
994 #define VA_SURFACE_EXTBUF_DESC_CACHED           0x00000002
995 /** \brief Memory is non-cacheable */
996 #define VA_SURFACE_EXTBUF_DESC_UNCACHED         0x00000004
997 /** \brief Memory is write-combined */
998 #define VA_SURFACE_EXTBUF_DESC_WC               0x00000008
999 /** \brief Memory is protected */
1000 #define VA_SURFACE_EXTBUF_DESC_PROTECTED        0x80000000
1001
1002 /** @name VASurfaceAttribUsageHint attribute usage hint flags */
1003 /**@{*/
1004 /** \brief Surface usage not indicated. */
1005 #define VA_SURFACE_ATTRIB_USAGE_HINT_GENERIC    0x00000000
1006 /** \brief Surface used by video decoder. */
1007 #define VA_SURFACE_ATTRIB_USAGE_HINT_DECODER    0x00000001
1008 /** \brief Surface used by video encoder. */
1009 #define VA_SURFACE_ATTRIB_USAGE_HINT_ENCODER    0x00000002
1010 /** \brief Surface read by video post-processing. */
1011 #define VA_SURFACE_ATTRIB_USAGE_HINT_VPP_READ   0x00000004
1012 /** \brief Surface written by video post-processing. */
1013 #define VA_SURFACE_ATTRIB_USAGE_HINT_VPP_WRITE  0x00000008
1014 /** \brief Surface used for display. */
1015 #define VA_SURFACE_ATTRIB_USAGE_HINT_DISPLAY    0x00000010
1016
1017 /**@}*/
1018
1019 /**
1020  * \brief Queries surface attributes for the supplied config.
1021  *
1022  * Unlike vaGetSurfaceAttributes(), this function queries for all
1023  * supported attributes for the supplied VA @config. In particular, if
1024  * the underlying hardware supports the creation of VA surfaces in
1025  * various formats, then this function will enumerate all pixel
1026  * formats that are supported.
1027  *
1028  * The \c attrib_list array is allocated by the user and \c
1029  * num_attribs shall be initialized to the number of allocated
1030  * elements in that array. Upon successful return, the actual number
1031  * of attributes will be overwritten into \c num_attribs. Otherwise,
1032  * \c VA_STATUS_ERROR_MAX_NUM_EXCEEDED is returned and \c num_attribs
1033  * is adjusted to the number of elements that would be returned if
1034  * enough space was available.
1035  *
1036  * Note: it is perfectly valid to pass NULL to the \c attrib_list
1037  * argument when vaQuerySurfaceAttributes() is used to determine the
1038  * actual number of elements that need to be allocated.
1039  *
1040  * @param[in] dpy               the VA display
1041  * @param[in] config            the config identifying a codec or a video
1042  *     processing pipeline
1043  * @param[out] attrib_list      the output array of #VASurfaceAttrib elements
1044  * @param[in,out] num_attribs   the number of elements allocated on
1045  *      input, the number of elements actually filled in output
1046  */
1047 VAStatus
1048 vaQuerySurfaceAttributes(
1049     VADisplay           dpy,
1050     VAConfigID          config,
1051     VASurfaceAttrib    *attrib_list,
1052     unsigned int       *num_attribs
1053 );
1054
1055 /**
1056  * \brief Creates an array of surfaces
1057  *
1058  * Creates an array of surfaces. The optional list of attributes shall
1059  * be constructed and validated through vaGetSurfaceAttributes() or
1060  * constructed based based on what the underlying hardware could
1061  * expose through vaQuerySurfaceAttributes().
1062  *
1063  * @param[in] dpy               the VA display
1064  * @param[in] format            the desired surface format. See \c VA_RT_FORMAT_*
1065  * @param[in] width             the surface width
1066  * @param[in] height            the surface height
1067  * @param[out] surfaces         the array of newly created surfaces
1068  * @param[in] num_surfaces      the number of surfaces to create
1069  * @param[in] attrib_list       the list of (optional) attributes, or \c NULL
1070  * @param[in] num_attribs       the number of attributes supplied in
1071  *     \c attrib_list, or zero
1072  */
1073 VAStatus
1074 vaCreateSurfaces(
1075     VADisplay           dpy,
1076     unsigned int        format,
1077     unsigned int        width,
1078     unsigned int        height,
1079     VASurfaceID        *surfaces,
1080     unsigned int        num_surfaces,
1081     VASurfaceAttrib    *attrib_list,
1082     unsigned int        num_attribs
1083 );
1084     
1085 /**
1086  * vaDestroySurfaces - Destroy resources associated with surfaces. 
1087  *  Surfaces can only be destroyed after the context associated has been 
1088  *  destroyed.  
1089  *  dpy: display
1090  *  surfaces: array of surfaces to destroy
1091  *  num_surfaces: number of surfaces in the array to be destroyed.
1092  */
1093 VAStatus vaDestroySurfaces (
1094     VADisplay dpy,
1095     VASurfaceID *surfaces,
1096     int num_surfaces
1097 );
1098
1099 #define VA_PROGRESSIVE 0x1
1100 /**
1101  * vaCreateContext - Create a context
1102  *  dpy: display
1103  *  config_id: configuration for the context
1104  *  picture_width: coded picture width
1105  *  picture_height: coded picture height
1106  *  flag: any combination of the following:
1107  *    VA_PROGRESSIVE (only progressive frame pictures in the sequence when set)
1108  *  render_targets: render targets (surfaces) tied to the context
1109  *  num_render_targets: number of render targets in the above array
1110  *  context: created context id upon return
1111  */
1112 VAStatus vaCreateContext (
1113     VADisplay dpy,
1114     VAConfigID config_id,
1115     int picture_width,
1116     int picture_height,
1117     int flag,
1118     VASurfaceID *render_targets,
1119     int num_render_targets,
1120     VAContextID *context                /* out */
1121 );
1122
1123 /**
1124  * vaDestroyContext - Destroy a context 
1125  *  dpy: display
1126  *  context: context to be destroyed
1127  */
1128 VAStatus vaDestroyContext (
1129     VADisplay dpy,
1130     VAContextID context
1131 );
1132
1133 /**
1134  * Buffers 
1135  * Buffers are used to pass various types of data from the
1136  * client to the server. The server maintains a data store
1137  * for each buffer created, and the client idenfies a buffer
1138  * through a unique buffer id assigned by the server.
1139  */
1140
1141 typedef VAGenericID VABufferID;
1142
1143 typedef enum
1144 {
1145     VAPictureParameterBufferType        = 0,
1146     VAIQMatrixBufferType                = 1,
1147     VABitPlaneBufferType                = 2,
1148     VASliceGroupMapBufferType           = 3,
1149     VASliceParameterBufferType          = 4,
1150     VASliceDataBufferType               = 5,
1151     VAMacroblockParameterBufferType     = 6,
1152     VAResidualDataBufferType            = 7,
1153     VADeblockingParameterBufferType     = 8,
1154     VAImageBufferType                   = 9,
1155     VAProtectedSliceDataBufferType      = 10,
1156     VAQMatrixBufferType                 = 11,
1157     VAHuffmanTableBufferType            = 12,
1158     VAProbabilityBufferType             = 13,
1159
1160 /* Following are encode buffer types */
1161     VAEncCodedBufferType                = 21,
1162     VAEncSequenceParameterBufferType    = 22,
1163     VAEncPictureParameterBufferType     = 23,
1164     VAEncSliceParameterBufferType       = 24,
1165     VAEncPackedHeaderParameterBufferType = 25,
1166     VAEncPackedHeaderDataBufferType     = 26,
1167     VAEncMiscParameterBufferType        = 27,
1168     VAEncMacroblockParameterBufferType  = 28,
1169     VAEncMacroblockMapBufferType        = 29,
1170
1171     /**
1172      * \brief Encoding QP buffer
1173      *
1174      * This buffer contains QP per MB for encoding. Currently
1175      * VAEncQPBufferH264 is defined for H.264 encoding, see
1176      * #VAEncQPBufferH264 for details
1177      */
1178     VAEncQPBufferType                   = 30,
1179 /* Following are video processing buffer types */
1180     /**
1181      * \brief Video processing pipeline parameter buffer.
1182      *
1183      * This buffer describes the video processing pipeline. See
1184      * #VAProcPipelineParameterBuffer for details.
1185      */
1186     VAProcPipelineParameterBufferType   = 41,
1187     /**
1188      * \brief Video filter parameter buffer.
1189      *
1190      * This buffer describes the video filter parameters. All buffers
1191      * inherit from #VAProcFilterParameterBufferBase, thus including
1192      * a unique filter buffer type.
1193      *
1194      * The default buffer used by most filters is #VAProcFilterParameterBuffer.
1195      * Filters requiring advanced parameters include, but are not limited to,
1196      * deinterlacing (#VAProcFilterParameterBufferDeinterlacing),
1197      * color balance (#VAProcFilterParameterBufferColorBalance), etc.
1198      */
1199     VAProcFilterParameterBufferType     = 42,
1200     /**
1201      * \brief FEI specific buffer types
1202      */
1203     VAEncFEIMVBufferType                = 43,
1204     VAEncFEIMBCodeBufferType            = 44,
1205     VAEncFEIDistortionBufferType        = 45,
1206     VAEncFEIMBControlBufferType         = 46,
1207     VAEncFEIMVPredictorBufferType       = 47,
1208     VABufferTypeMax
1209 } VABufferType;
1210
1211 typedef enum
1212 {
1213     VAEncMiscParameterTypeFrameRate     = 0,
1214     VAEncMiscParameterTypeRateControl   = 1,
1215     VAEncMiscParameterTypeMaxSliceSize  = 2,
1216     VAEncMiscParameterTypeAIR           = 3,
1217     /** \brief Buffer type used to express a maximum frame size (in bits). */
1218     VAEncMiscParameterTypeMaxFrameSize  = 4,
1219     /** \brief Buffer type used for HRD parameters. */
1220     VAEncMiscParameterTypeHRD           = 5,
1221     VAEncMiscParameterTypeQualityLevel  = 6,
1222     /** \brief Buffer type used for sending skip frame parameters to the encoder's
1223       * rate control, when the user has externally skipped frames. */
1224     VAEncMiscParameterTypeSkipFrame     = 9,
1225     /** \brief Buffer type used for region-of-interest (ROI) parameters. */
1226     VAEncMiscParameterTypeROI           = 10,
1227     /** \brief Buffer type used for temporal layer structure */
1228     VAEncMiscParameterTypeTemporalLayerStructure   = 12,
1229     /** \brief Buffer type used for FEI input frame level parameters */
1230     VAEncMiscParameterTypeFEIFrameControl = 18,
1231 } VAEncMiscParameterType;
1232
1233 /** \brief Packed header type. */
1234 typedef enum {
1235     /** \brief Packed sequence header. */
1236     VAEncPackedHeaderSequence   = 1,
1237     /** \brief Packed picture header. */
1238     VAEncPackedHeaderPicture    = 2,
1239     /** \brief Packed slice header. */
1240     VAEncPackedHeaderSlice      = 3,
1241     /** 
1242      * \brief Packed raw header. 
1243      * 
1244      * Packed raw data header can be used by the client to insert a header  
1245      * into the bitstream data buffer at the point it is passed, the driver 
1246      * will handle the raw packed header based on "has_emulation_bytes" field
1247      * in the packed header parameter structure.
1248      */
1249     VAEncPackedHeaderRawData    = 4,
1250     /** \brief Misc packed header. See codec-specific definitions. */
1251     VAEncPackedHeaderMiscMask   = 0x80000000,
1252 } VAEncPackedHeaderType;
1253
1254 /** \brief Packed header parameter. */
1255 typedef struct _VAEncPackedHeaderParameterBuffer {
1256     /** Type of the packed header buffer. See #VAEncPackedHeaderType. */
1257     unsigned int                type;
1258     /** \brief Size of the #VAEncPackedHeaderDataBuffer in bits. */
1259     unsigned int                bit_length;
1260     /** \brief Flag: buffer contains start code emulation prevention bytes? */
1261     unsigned char               has_emulation_bytes;
1262 } VAEncPackedHeaderParameterBuffer;
1263
1264 /**
1265  *  For application, e.g. set a new bitrate
1266  *    VABufferID buf_id;
1267  *    VAEncMiscParameterBuffer *misc_param;
1268  *    VAEncMiscParameterRateControl *misc_rate_ctrl;
1269  * 
1270  *    vaCreateBuffer(dpy, context, VAEncMiscParameterBufferType,
1271  *              sizeof(VAEncMiscParameterBuffer) + sizeof(VAEncMiscParameterRateControl),
1272  *              1, NULL, &buf_id);
1273  *
1274  *    vaMapBuffer(dpy,buf_id,(void **)&misc_param);
1275  *    misc_param->type = VAEncMiscParameterTypeRateControl;
1276  *    misc_rate_ctrl= (VAEncMiscParameterRateControl *)misc_param->data;
1277  *    misc_rate_ctrl->bits_per_second = 6400000;
1278  *    vaUnmapBuffer(dpy, buf_id);
1279  *    vaRenderPicture(dpy, context, &buf_id, 1);
1280  */
1281 typedef struct _VAEncMiscParameterBuffer
1282 {
1283     VAEncMiscParameterType type;
1284     unsigned int data[0];
1285 } VAEncMiscParameterBuffer;
1286
1287 /** \brief Temporal layer Structure*/
1288 typedef struct _VAEncMiscParameterTemporalLayerStructure
1289 {
1290     /** \brief The number of temporal layers */
1291     unsigned int number_of_layers;
1292     /** \brief The length of the array defining frame layer membership. Should be 1-32 */
1293     unsigned int periodicity;
1294     /**
1295      * \brief The array indicating the layer id for each frame
1296      *
1297      * The layer id for the first frame in a coded sequence is always 0, so layer_id[] specifies the layer
1298      * ids for frames starting from the 2nd frame.
1299      */
1300     unsigned int layer_id[32];
1301 } VAEncMiscParameterTemporalLayerStructure;
1302
1303
1304 /** \brief Rate control parameters */
1305 typedef struct _VAEncMiscParameterRateControl
1306 {
1307     /* this is the maximum bit-rate to be constrained by the rate control implementation */
1308     unsigned int bits_per_second;
1309     /* this is the bit-rate the rate control is targeting, as a percentage of the maximum
1310      * bit-rate for example if target_percentage is 95 then the rate control will target
1311      * a bit-rate that is 95% of the maximum bit-rate
1312      */
1313     unsigned int target_percentage;
1314     /* windows size in milliseconds. For example if this is set to 500,
1315      * then the rate control will guarantee the target bit-rate over a 500 ms window
1316      */
1317     unsigned int window_size;
1318     /* initial QP at I frames */
1319     unsigned int initial_qp;
1320     unsigned int min_qp;
1321     unsigned int basic_unit_size;
1322     union
1323     {
1324         struct
1325         {
1326             unsigned int reset : 1;
1327             unsigned int disable_frame_skip : 1; /* Disable frame skip in rate control mode */
1328             unsigned int disable_bit_stuffing : 1; /* Disable bit stuffing in rate control mode */
1329             unsigned int mb_rate_control : 4; /* Control VA_RC_MB 0: default, 1: enable, 2: disable, other: reserved*/
1330             /*
1331              * The temporal layer that the rate control parameters are specified for.
1332              */
1333             unsigned int temporal_id : 8;
1334             unsigned int reserved : 17;
1335         } bits;
1336         unsigned int value;
1337     } rc_flags;
1338 } VAEncMiscParameterRateControl;
1339
1340 typedef struct _VAEncMiscParameterFrameRate
1341 {
1342     /*
1343      * The framerate is specified as a number of frames per second, as a
1344      * fraction.  The denominator of the fraction is given in the top half
1345      * (the high two bytes) of the framerate field, and the numerator is
1346      * given in the bottom half (the low two bytes).
1347      *
1348      * That is:
1349      * denominator = framerate >> 16 & 0xffff;
1350      * numerator   = framerate & 0xffff;
1351      * fps         = numerator / denominator;
1352      *
1353      * For example, if framerate is set to (100 << 16 | 750), this is
1354      * 750 / 100, hence 7.5fps.
1355      *
1356      * If the denominator is zero (the high two bytes are both zero) then
1357      * it takes the value one instead, so the framerate is just the integer
1358      * in the low 2 bytes.
1359      */
1360     unsigned int framerate;
1361     union
1362     {
1363         struct
1364         {
1365             /*
1366              * The temporal id the framerate parameters are specified for.
1367              */
1368             unsigned int temporal_id : 8;
1369             unsigned int reserved : 24;
1370          } bits;
1371          unsigned int value;
1372      } framerate_flags;
1373 } VAEncMiscParameterFrameRate;
1374
1375 /**
1376  * Allow a maximum slice size to be specified (in bits).
1377  * The encoder will attempt to make sure that individual slices do not exceed this size
1378  * Or to signal applicate if the slice size exceed this size, see "status" of VACodedBufferSegment
1379  */
1380 typedef struct _VAEncMiscParameterMaxSliceSize
1381 {
1382     unsigned int max_slice_size;
1383 } VAEncMiscParameterMaxSliceSize;
1384
1385 typedef struct _VAEncMiscParameterAIR
1386 {
1387     unsigned int air_num_mbs;
1388     unsigned int air_threshold;
1389     unsigned int air_auto; /* if set to 1 then hardware auto-tune the AIR threshold */
1390 } VAEncMiscParameterAIR;
1391
1392 typedef struct _VAEncMiscParameterHRD
1393 {
1394     unsigned int initial_buffer_fullness;       /* in bits */
1395     unsigned int buffer_size;                   /* in bits */
1396 } VAEncMiscParameterHRD;
1397
1398 /**
1399  * \brief Defines a maximum frame size (in bits).
1400  *
1401  * This misc parameter buffer defines the maximum size of a frame (in
1402  * bits). The encoder will try to make sure that each frame does not
1403  * exceed this size. Otherwise, if the frame size exceeds this size,
1404  * the \c status flag of #VACodedBufferSegment will contain
1405  * #VA_CODED_BUF_STATUS_FRAME_SIZE_OVERFLOW.
1406  */
1407 typedef struct _VAEncMiscParameterBufferMaxFrameSize {
1408     /** \brief Type. Shall be set to #VAEncMiscParameterTypeMaxFrameSize. */
1409     VAEncMiscParameterType      type;
1410     /** \brief Maximum size of a frame (in bits). */
1411     unsigned int                max_frame_size;
1412 } VAEncMiscParameterBufferMaxFrameSize;
1413
1414 /**
1415  * \brief Encoding quality level.
1416  *
1417  * The encoding quality could be set through this structure, if the implementation  
1418  * supports multiple quality levels. The quality level set through this structure is 
1419  * persistent over the entire coded sequence, or until a new structure is being sent.
1420  * The quality level range can be queried through the VAConfigAttribEncQualityRange 
1421  * attribute. A lower value means higher quality, and a value of 1 represents the highest 
1422  * quality. The quality level setting is used as a trade-off between quality and speed/power 
1423  * consumption, with higher quality corresponds to lower speed and higher power consumption. 
1424  */
1425 typedef struct _VAEncMiscParameterBufferQualityLevel {
1426     /** \brief Encoding quality level setting. When set to 0, default quality
1427      * level is used.
1428      */
1429     unsigned int                quality_level;
1430 } VAEncMiscParameterBufferQualityLevel;
1431
1432 /**
1433  * \brief Encoding skip frame.
1434  *
1435  * The application may choose to skip frames externally to the encoder (e.g. drop completely or 
1436  * code as all skip's). For rate control purposes the encoder will need to know the size and number 
1437  * of skipped frames.  Skip frame(s) indicated through this structure is applicable only to the 
1438  * current frame.  It is allowed for the application to still send in packed headers for the driver to 
1439  * pack, although no frame will be encoded (e.g. for HW to encrypt the frame).  
1440  */
1441 typedef struct _VAEncMiscParameterSkipFrame {
1442     /** \brief Indicates skip frames as below.
1443       * 0: Encode as normal, no skip.
1444       * 1: One or more frames were skipped prior to the current frame, encode the current frame as normal.  
1445       * 2: The current frame is to be skipped, do not encode it but pack/encrypt the packed header contents
1446       *    (all except VAEncPackedHeaderSlice) which could contain actual frame contents (e.g. pack the frame 
1447       *    in VAEncPackedHeaderPicture).  */
1448     unsigned char               skip_frame_flag;
1449     /** \brief The number of frames skipped prior to the current frame.  Valid when skip_frame_flag = 1. */
1450     unsigned char               num_skip_frames;
1451     /** \brief When skip_frame_flag = 1, the size of the skipped frames in bits.   When skip_frame_flag = 2, 
1452       * the size of the current skipped frame that is to be packed/encrypted in bits. */
1453     unsigned int                size_skip_frames;
1454 } VAEncMiscParameterSkipFrame;
1455
1456 /**
1457  * \brief Encoding region-of-interest (ROI).
1458  *
1459  * The encoding ROI can be set through VAEncMiscParameterBufferROI, if the implementation
1460  * supports ROI input. The ROI set through this structure is applicable only to the
1461  * current frame or field, so must be sent every frame or field to be applied.  The number of
1462  * supported ROIs can be queried through the VAConfigAttribEncROI.  The encoder will use the
1463  * ROI information to adjust the QP values of the MB's that fall within the ROIs.
1464  */
1465 typedef struct _VAEncROI
1466 {
1467         /** \brief Defines the ROI boundary in pixels, the driver will map it to appropriate
1468          *  codec coding units.  It is relative to frame coordinates for the frame case and
1469          *  to field coordinates for the field case. */
1470         VARectangle     roi_rectangle;
1471         /**
1472          * \brief ROI value
1473          *
1474          * \ref roi_value specifies ROI delta QP or ROI priority.
1475          * --  ROI delta QP is the value that will be added on top of the frame level QP.
1476          * --  ROI priority specifies the priority of a region, it can be positive (more important)
1477          * or negative (less important) values and is compared with non-ROI region (taken as value 0),
1478          * E.g. ROI region with \ref roi_value -3 is less important than the non-ROI region (\ref roi_value
1479          * implied to be 0) which is less important than ROI region with roi_value +2. For overlapping
1480          * regions, the roi_value that is first in the ROI array will have priority.
1481          *
1482          * \ref roi_value always specifes ROI delta QP when VAConfigAttribRateControl == VA_RC_CQP, no matter
1483          * the value of \c roi_value_is_qp_delta in #VAEncMiscParameterBufferROI.
1484          *
1485          * \ref roi_value depends on \c roi_value_is_qp_delta in #VAEncMiscParameterBufferROI when
1486          * VAConfigAttribRateControl != VA_RC_CQP. \ref roi_value specifies ROI_delta QP if \c roi_value_is_qp_delta
1487          * in VAEncMiscParameterBufferROI is 1, otherwise \ref roi_value specifies ROI priority.
1488          */
1489         char            roi_value;
1490 } VAEncROI;
1491
1492 typedef struct _VAEncMiscParameterBufferROI {
1493     /** \brief Number of ROIs being sent.*/
1494     unsigned int        num_roi;
1495
1496     /** \brief Valid when VAConfigAttribRateControl != VA_RC_CQP, then the encoder's
1497      *  rate control will determine actual delta QPs.  Specifies the max/min allowed delta
1498      *  QPs. */
1499     char                max_delta_qp;
1500     char                min_delta_qp;
1501
1502    /** \brief Pointer to a VAEncROI array with num_roi elements.  It is relative to frame
1503      *  coordinates for the frame case and to field coordinates for the field case.*/
1504     VAEncROI            *roi;
1505     union {
1506         struct {
1507             /**
1508              * \brief An indication for roi value.
1509              *
1510              * \ref roi_value_is_qp_delta equal to 1 indicates \c roi_value in #VAEncROI should
1511              * be used as ROI delta QP. \ref roi_value_is_qp_delta equal to 0 indicates \c roi_value
1512              * in #VAEncROI should be used as ROI priority.
1513              *
1514              * \ref roi_value_is_qp_delta is only available when VAConfigAttribRateControl != VA_RC_CQP,
1515              * the setting must comply with \c roi_rc_priority_support and \c roi_rc_qp_delat_support in
1516              * #VAConfigAttribValEncROI. The underlying driver should ignore this field
1517              * when VAConfigAttribRateControl == VA_RC_CQP.
1518              */
1519             uint32_t  roi_value_is_qp_delta    : 1;
1520             uint32_t  reserved                 : 31;
1521         } bits;
1522         uint32_t value;
1523     } roi_flags;
1524 } VAEncMiscParameterBufferROI;
1525
1526 /**
1527  * There will be cases where the bitstream buffer will not have enough room to hold
1528  * the data for the entire slice, and the following flags will be used in the slice
1529  * parameter to signal to the server for the possible cases.
1530  * If a slice parameter buffer and slice data buffer pair is sent to the server with 
1531  * the slice data partially in the slice data buffer (BEGIN and MIDDLE cases below), 
1532  * then a slice parameter and data buffer needs to be sent again to complete this slice. 
1533  */
1534 #define VA_SLICE_DATA_FLAG_ALL          0x00    /* whole slice is in the buffer */
1535 #define VA_SLICE_DATA_FLAG_BEGIN        0x01    /* The beginning of the slice is in the buffer but the end if not */
1536 #define VA_SLICE_DATA_FLAG_MIDDLE       0x02    /* Neither beginning nor end of the slice is in the buffer */
1537 #define VA_SLICE_DATA_FLAG_END          0x04    /* end of the slice is in the buffer */
1538
1539 /* Codec-independent Slice Parameter Buffer base */
1540 typedef struct _VASliceParameterBufferBase
1541 {
1542     unsigned int slice_data_size;       /* number of bytes in the slice data buffer for this slice */
1543     unsigned int slice_data_offset;     /* the offset to the first byte of slice data */
1544     unsigned int slice_data_flag;       /* see VA_SLICE_DATA_FLAG_XXX definitions */
1545 } VASliceParameterBufferBase;
1546
1547 /**********************************
1548  * JPEG common  data structures
1549  **********************************/
1550 /**
1551  * \brief Huffman table for JPEG decoding.
1552  *
1553  * This structure holds the complete Huffman tables. This is an
1554  * aggregation of all Huffman table (DHT) segments maintained by the
1555  * application. i.e. up to 2 Huffman tables are stored in there for
1556  * baseline profile.
1557  *
1558  * The #load_huffman_table array can be used as a hint to notify the
1559  * VA driver implementation about which table(s) actually changed
1560  * since the last submission of this buffer.
1561  */
1562 typedef struct _VAHuffmanTableBufferJPEGBaseline {
1563     /** \brief Specifies which #huffman_table is valid. */
1564     unsigned char       load_huffman_table[2];
1565     /** \brief Huffman tables indexed by table identifier (Th). */
1566     struct {
1567         /** @name DC table (up to 12 categories) */
1568         /**@{*/
1569         /** \brief Number of Huffman codes of length i + 1 (Li). */
1570         unsigned char   num_dc_codes[16];
1571         /** \brief Value associated with each Huffman code (Vij). */
1572         unsigned char   dc_values[12];
1573         /**@}*/
1574         /** @name AC table (2 special codes + up to 16 * 10 codes) */
1575         /**@{*/
1576         /** \brief Number of Huffman codes of length i + 1 (Li). */
1577         unsigned char   num_ac_codes[16];
1578         /** \brief Value associated with each Huffman code (Vij). */
1579         unsigned char   ac_values[162];
1580         /** \brief Padding to 4-byte boundaries. Must be set to zero. */
1581         unsigned char   pad[2];
1582         /**@}*/
1583     }                   huffman_table[2];
1584 } VAHuffmanTableBufferJPEGBaseline;
1585
1586 /****************************
1587  * MPEG-2 data structures
1588  ****************************/
1589  
1590 /* MPEG-2 Picture Parameter Buffer */
1591 /* 
1592  * For each frame or field, and before any slice data, a single
1593  * picture parameter buffer must be send.
1594  */
1595 typedef struct _VAPictureParameterBufferMPEG2
1596 {
1597     unsigned short horizontal_size;
1598     unsigned short vertical_size;
1599     VASurfaceID forward_reference_picture;
1600     VASurfaceID backward_reference_picture;
1601     /* meanings of the following fields are the same as in the standard */
1602     int picture_coding_type;
1603     int f_code; /* pack all four fcode into this */
1604     union {
1605         struct {
1606             unsigned int intra_dc_precision             : 2; 
1607             unsigned int picture_structure              : 2; 
1608             unsigned int top_field_first                : 1; 
1609             unsigned int frame_pred_frame_dct           : 1; 
1610             unsigned int concealment_motion_vectors     : 1;
1611             unsigned int q_scale_type                   : 1;
1612             unsigned int intra_vlc_format               : 1;
1613             unsigned int alternate_scan                 : 1;
1614             unsigned int repeat_first_field             : 1;
1615             unsigned int progressive_frame              : 1;
1616             unsigned int is_first_field                 : 1; /* indicate whether the current field
1617                                                               * is the first field for field picture
1618                                                               */
1619         } bits;
1620         unsigned int value;
1621     } picture_coding_extension;
1622 } VAPictureParameterBufferMPEG2;
1623
1624 /** MPEG-2 Inverse Quantization Matrix Buffer */
1625 typedef struct _VAIQMatrixBufferMPEG2
1626 {
1627     /** \brief Same as the MPEG-2 bitstream syntax element. */
1628     int load_intra_quantiser_matrix;
1629     /** \brief Same as the MPEG-2 bitstream syntax element. */
1630     int load_non_intra_quantiser_matrix;
1631     /** \brief Same as the MPEG-2 bitstream syntax element. */
1632     int load_chroma_intra_quantiser_matrix;
1633     /** \brief Same as the MPEG-2 bitstream syntax element. */
1634     int load_chroma_non_intra_quantiser_matrix;
1635     /** \brief Luminance intra matrix, in zig-zag scan order. */
1636     unsigned char intra_quantiser_matrix[64];
1637     /** \brief Luminance non-intra matrix, in zig-zag scan order. */
1638     unsigned char non_intra_quantiser_matrix[64];
1639     /** \brief Chroma intra matrix, in zig-zag scan order. */
1640     unsigned char chroma_intra_quantiser_matrix[64];
1641     /** \brief Chroma non-intra matrix, in zig-zag scan order. */
1642     unsigned char chroma_non_intra_quantiser_matrix[64];
1643 } VAIQMatrixBufferMPEG2;
1644
1645 /** MPEG-2 Slice Parameter Buffer */
1646 typedef struct _VASliceParameterBufferMPEG2
1647 {
1648     unsigned int slice_data_size;/* number of bytes in the slice data buffer for this slice */
1649     unsigned int slice_data_offset;/* the offset to the first byte of slice data */
1650     unsigned int slice_data_flag; /* see VA_SLICE_DATA_FLAG_XXX defintions */
1651     unsigned int macroblock_offset;/* the offset to the first bit of MB from the first byte of slice data */
1652     unsigned int slice_horizontal_position;
1653     unsigned int slice_vertical_position;
1654     int quantiser_scale_code;
1655     int intra_slice_flag;
1656 } VASliceParameterBufferMPEG2;
1657
1658 /** MPEG-2 Macroblock Parameter Buffer */
1659 typedef struct _VAMacroblockParameterBufferMPEG2
1660 {
1661     unsigned short macroblock_address;
1662     /* 
1663      * macroblock_address (in raster scan order)
1664      * top-left: 0
1665      * bottom-right: picture-height-in-mb*picture-width-in-mb - 1
1666      */
1667     unsigned char macroblock_type;  /* see definition below */
1668     union {
1669         struct {
1670             unsigned int frame_motion_type              : 2; 
1671             unsigned int field_motion_type              : 2; 
1672             unsigned int dct_type                       : 1; 
1673         } bits;
1674         unsigned int value;
1675     } macroblock_modes;
1676     unsigned char motion_vertical_field_select; 
1677     /* 
1678      * motion_vertical_field_select:
1679      * see section 6.3.17.2 in the spec
1680      * only the lower 4 bits are used
1681      * bit 0: first vector forward
1682      * bit 1: first vector backward
1683      * bit 2: second vector forward
1684      * bit 3: second vector backward
1685      */
1686     short PMV[2][2][2]; /* see Table 7-7 in the spec */
1687     unsigned short coded_block_pattern;
1688     /* 
1689      * The bitplanes for coded_block_pattern are described 
1690      * in Figure 6.10-12 in the spec
1691      */
1692      
1693     /* Number of skipped macroblocks after this macroblock */
1694     unsigned short num_skipped_macroblocks;
1695 } VAMacroblockParameterBufferMPEG2;
1696
1697 /* 
1698  * OR'd flags for macroblock_type (section 6.3.17.1 in the spec)
1699  */
1700 #define VA_MB_TYPE_MOTION_FORWARD       0x02
1701 #define VA_MB_TYPE_MOTION_BACKWARD      0x04
1702 #define VA_MB_TYPE_MOTION_PATTERN       0x08
1703 #define VA_MB_TYPE_MOTION_INTRA         0x10
1704
1705 /**
1706  * MPEG-2 Residual Data Buffer 
1707  * For each macroblock, there wil be 64 shorts (16-bit) in the 
1708  * residual data buffer
1709  */
1710
1711 /****************************
1712  * MPEG-4 Part 2 data structures
1713  ****************************/
1714  
1715 /* MPEG-4 Picture Parameter Buffer */
1716 /* 
1717  * For each frame or field, and before any slice data, a single
1718  * picture parameter buffer must be send.
1719  */
1720 typedef struct _VAPictureParameterBufferMPEG4
1721 {
1722     unsigned short vop_width;
1723     unsigned short vop_height;
1724     VASurfaceID forward_reference_picture;
1725     VASurfaceID backward_reference_picture;
1726     union {
1727         struct {
1728             unsigned int short_video_header             : 1; 
1729             unsigned int chroma_format                  : 2; 
1730             unsigned int interlaced                     : 1; 
1731             unsigned int obmc_disable                   : 1; 
1732             unsigned int sprite_enable                  : 2; 
1733             unsigned int sprite_warping_accuracy        : 2; 
1734             unsigned int quant_type                     : 1; 
1735             unsigned int quarter_sample                 : 1; 
1736             unsigned int data_partitioned               : 1; 
1737             unsigned int reversible_vlc                 : 1; 
1738             unsigned int resync_marker_disable          : 1; 
1739         } bits;
1740         unsigned int value;
1741     } vol_fields;
1742     unsigned char no_of_sprite_warping_points;
1743     short sprite_trajectory_du[3];
1744     short sprite_trajectory_dv[3];
1745     unsigned char quant_precision;
1746     union {
1747         struct {
1748             unsigned int vop_coding_type                : 2; 
1749             unsigned int backward_reference_vop_coding_type     : 2; 
1750             unsigned int vop_rounding_type              : 1; 
1751             unsigned int intra_dc_vlc_thr               : 3; 
1752             unsigned int top_field_first                : 1; 
1753             unsigned int alternate_vertical_scan_flag   : 1; 
1754         } bits;
1755         unsigned int value;
1756     } vop_fields;
1757     unsigned char vop_fcode_forward;
1758     unsigned char vop_fcode_backward;
1759     unsigned short vop_time_increment_resolution;
1760     /* short header related */
1761     unsigned char num_gobs_in_vop;
1762     unsigned char num_macroblocks_in_gob;
1763     /* for direct mode prediction */
1764     short TRB;
1765     short TRD;
1766 } VAPictureParameterBufferMPEG4;
1767
1768 /** MPEG-4 Inverse Quantization Matrix Buffer */
1769 typedef struct _VAIQMatrixBufferMPEG4
1770 {
1771     /** Same as the MPEG-4:2 bitstream syntax element. */
1772     int load_intra_quant_mat;
1773     /** Same as the MPEG-4:2 bitstream syntax element. */
1774     int load_non_intra_quant_mat;
1775     /** The matrix for intra blocks, in zig-zag scan order. */
1776     unsigned char intra_quant_mat[64];
1777     /** The matrix for non-intra blocks, in zig-zag scan order. */
1778     unsigned char non_intra_quant_mat[64];
1779 } VAIQMatrixBufferMPEG4;
1780
1781 /** MPEG-4 Slice Parameter Buffer */
1782 typedef struct _VASliceParameterBufferMPEG4
1783 {
1784     unsigned int slice_data_size;/* number of bytes in the slice data buffer for this slice */
1785     unsigned int slice_data_offset;/* the offset to the first byte of slice data */
1786     unsigned int slice_data_flag; /* see VA_SLICE_DATA_FLAG_XXX defintions */
1787     unsigned int macroblock_offset;/* the offset to the first bit of MB from the first byte of slice data */
1788     unsigned int macroblock_number;
1789     int quant_scale;
1790 } VASliceParameterBufferMPEG4;
1791
1792 /**
1793  VC-1 data structures
1794 */
1795
1796 typedef enum   /* see 7.1.1.32 */
1797 {
1798     VAMvMode1Mv                        = 0,
1799     VAMvMode1MvHalfPel                 = 1,
1800     VAMvMode1MvHalfPelBilinear         = 2,
1801     VAMvModeMixedMv                    = 3,
1802     VAMvModeIntensityCompensation      = 4 
1803 } VAMvModeVC1;
1804
1805 /** VC-1 Picture Parameter Buffer */
1806 /* 
1807  * For each picture, and before any slice data, a picture parameter
1808  * buffer must be send. Multiple picture parameter buffers may be
1809  * sent for a single picture. In that case picture parameters will
1810  * apply to all slice data that follow it until a new picture
1811  * parameter buffer is sent.
1812  *
1813  * Notes:
1814  *   pic_quantizer_type should be set to the applicable quantizer
1815  *   type as defined by QUANTIZER (J.1.19) and either
1816  *   PQUANTIZER (7.1.1.8) or PQINDEX (7.1.1.6)
1817  */
1818 typedef struct _VAPictureParameterBufferVC1
1819 {
1820     VASurfaceID forward_reference_picture;
1821     VASurfaceID backward_reference_picture;
1822     /* if out-of-loop post-processing is done on the render
1823        target, then we need to keep the in-loop decoded 
1824        picture as a reference picture */
1825     VASurfaceID inloop_decoded_picture;
1826
1827     /* sequence layer for AP or meta data for SP and MP */
1828     union {
1829         struct {
1830             unsigned int pulldown       : 1; /* SEQUENCE_LAYER::PULLDOWN */
1831             unsigned int interlace      : 1; /* SEQUENCE_LAYER::INTERLACE */
1832             unsigned int tfcntrflag     : 1; /* SEQUENCE_LAYER::TFCNTRFLAG */
1833             unsigned int finterpflag    : 1; /* SEQUENCE_LAYER::FINTERPFLAG */
1834             unsigned int psf            : 1; /* SEQUENCE_LAYER::PSF */
1835             unsigned int multires       : 1; /* METADATA::MULTIRES */
1836             unsigned int overlap        : 1; /* METADATA::OVERLAP */
1837             unsigned int syncmarker     : 1; /* METADATA::SYNCMARKER */
1838             unsigned int rangered       : 1; /* METADATA::RANGERED */
1839             unsigned int max_b_frames   : 3; /* METADATA::MAXBFRAMES */
1840             unsigned int profile        : 2; /* SEQUENCE_LAYER::PROFILE or The MSB of METADATA::PROFILE */
1841         } bits;
1842         unsigned int value;
1843     } sequence_fields;
1844
1845     unsigned short coded_width;         /* ENTRY_POINT_LAYER::CODED_WIDTH */
1846     unsigned short coded_height;        /* ENTRY_POINT_LAYER::CODED_HEIGHT */
1847     union {
1848         struct {
1849             unsigned int broken_link    : 1; /* ENTRY_POINT_LAYER::BROKEN_LINK */
1850             unsigned int closed_entry   : 1; /* ENTRY_POINT_LAYER::CLOSED_ENTRY */
1851             unsigned int panscan_flag   : 1; /* ENTRY_POINT_LAYER::PANSCAN_FLAG */
1852             unsigned int loopfilter     : 1; /* ENTRY_POINT_LAYER::LOOPFILTER */
1853         } bits;
1854         unsigned int value;
1855     } entrypoint_fields;
1856     unsigned char conditional_overlap_flag; /* ENTRY_POINT_LAYER::CONDOVER */
1857     unsigned char fast_uvmc_flag;       /* ENTRY_POINT_LAYER::FASTUVMC */
1858     union {
1859         struct {
1860             unsigned int luma_flag      : 1; /* ENTRY_POINT_LAYER::RANGE_MAPY_FLAG */
1861             unsigned int luma           : 3; /* ENTRY_POINT_LAYER::RANGE_MAPY */
1862             unsigned int chroma_flag    : 1; /* ENTRY_POINT_LAYER::RANGE_MAPUV_FLAG */
1863             unsigned int chroma         : 3; /* ENTRY_POINT_LAYER::RANGE_MAPUV */
1864         } bits;
1865         unsigned int value;
1866     } range_mapping_fields;
1867
1868     unsigned char b_picture_fraction;   /* PICTURE_LAYER::BFRACTION */
1869     unsigned char cbp_table;            /* PICTURE_LAYER::CBPTAB/ICBPTAB */
1870     unsigned char mb_mode_table;        /* PICTURE_LAYER::MBMODETAB */
1871     unsigned char range_reduction_frame;/* PICTURE_LAYER::RANGEREDFRM */
1872     unsigned char rounding_control;     /* PICTURE_LAYER::RNDCTRL */
1873     unsigned char post_processing;      /* PICTURE_LAYER::POSTPROC */
1874     unsigned char picture_resolution_index;     /* PICTURE_LAYER::RESPIC */
1875     unsigned char luma_scale;           /* PICTURE_LAYER::LUMSCALE */
1876     unsigned char luma_shift;           /* PICTURE_LAYER::LUMSHIFT */
1877     union {
1878         struct {
1879             unsigned int picture_type           : 3; /* PICTURE_LAYER::PTYPE */
1880             unsigned int frame_coding_mode      : 3; /* PICTURE_LAYER::FCM */
1881             unsigned int top_field_first        : 1; /* PICTURE_LAYER::TFF */
1882             unsigned int is_first_field         : 1; /* set to 1 if it is the first field */
1883             unsigned int intensity_compensation : 1; /* PICTURE_LAYER::INTCOMP */
1884         } bits;
1885         unsigned int value;
1886     } picture_fields;
1887     union {
1888         struct {
1889             unsigned int mv_type_mb     : 1;    /* PICTURE::MVTYPEMB */
1890             unsigned int direct_mb      : 1;    /* PICTURE::DIRECTMB */
1891             unsigned int skip_mb        : 1;    /* PICTURE::SKIPMB */
1892             unsigned int field_tx       : 1;    /* PICTURE::FIELDTX */
1893             unsigned int forward_mb     : 1;    /* PICTURE::FORWARDMB */
1894             unsigned int ac_pred        : 1;    /* PICTURE::ACPRED */
1895             unsigned int overflags      : 1;    /* PICTURE::OVERFLAGS */
1896         } flags;
1897         unsigned int value;
1898     } raw_coding;
1899     union {
1900         struct {
1901             unsigned int bp_mv_type_mb   : 1;    /* PICTURE::MVTYPEMB */
1902             unsigned int bp_direct_mb    : 1;    /* PICTURE::DIRECTMB */
1903             unsigned int bp_skip_mb      : 1;    /* PICTURE::SKIPMB */  
1904             unsigned int bp_field_tx     : 1;    /* PICTURE::FIELDTX */ 
1905             unsigned int bp_forward_mb   : 1;    /* PICTURE::FORWARDMB */
1906             unsigned int bp_ac_pred      : 1;    /* PICTURE::ACPRED */   
1907             unsigned int bp_overflags    : 1;    /* PICTURE::OVERFLAGS */
1908         } flags;
1909         unsigned int value;
1910     } bitplane_present; /* signal what bitplane is being passed via the bitplane buffer */
1911     union {
1912         struct {
1913             unsigned int reference_distance_flag : 1;/* PICTURE_LAYER::REFDIST_FLAG */
1914             unsigned int reference_distance     : 5;/* PICTURE_LAYER::REFDIST */
1915             unsigned int num_reference_pictures: 1;/* PICTURE_LAYER::NUMREF */
1916             unsigned int reference_field_pic_indicator  : 1;/* PICTURE_LAYER::REFFIELD */
1917         } bits;
1918         unsigned int value;
1919     } reference_fields;
1920     union {
1921         struct {
1922             unsigned int mv_mode                : 3; /* PICTURE_LAYER::MVMODE */
1923             unsigned int mv_mode2               : 3; /* PICTURE_LAYER::MVMODE2 */
1924             unsigned int mv_table               : 3; /* PICTURE_LAYER::MVTAB/IMVTAB */
1925             unsigned int two_mv_block_pattern_table: 2; /* PICTURE_LAYER::2MVBPTAB */
1926             unsigned int four_mv_switch         : 1; /* PICTURE_LAYER::4MVSWITCH */
1927             unsigned int four_mv_block_pattern_table : 2; /* PICTURE_LAYER::4MVBPTAB */
1928             unsigned int extended_mv_flag       : 1; /* ENTRY_POINT_LAYER::EXTENDED_MV */
1929             unsigned int extended_mv_range      : 2; /* PICTURE_LAYER::MVRANGE */
1930             unsigned int extended_dmv_flag      : 1; /* ENTRY_POINT_LAYER::EXTENDED_DMV */
1931             unsigned int extended_dmv_range     : 2; /* PICTURE_LAYER::DMVRANGE */
1932         } bits;
1933         unsigned int value;
1934     } mv_fields;
1935     union {
1936         struct {
1937             unsigned int dquant : 2;    /* ENTRY_POINT_LAYER::DQUANT */
1938             unsigned int quantizer     : 2;     /* ENTRY_POINT_LAYER::QUANTIZER */
1939             unsigned int half_qp        : 1;    /* PICTURE_LAYER::HALFQP */
1940             unsigned int pic_quantizer_scale : 5;/* PICTURE_LAYER::PQUANT */
1941             unsigned int pic_quantizer_type : 1;/* PICTURE_LAYER::PQUANTIZER */
1942             unsigned int dq_frame       : 1;    /* VOPDQUANT::DQUANTFRM */
1943             unsigned int dq_profile     : 2;    /* VOPDQUANT::DQPROFILE */
1944             unsigned int dq_sb_edge     : 2;    /* VOPDQUANT::DQSBEDGE */
1945             unsigned int dq_db_edge     : 2;    /* VOPDQUANT::DQDBEDGE */
1946             unsigned int dq_binary_level : 1;   /* VOPDQUANT::DQBILEVEL */
1947             unsigned int alt_pic_quantizer : 5;/* VOPDQUANT::ALTPQUANT */
1948         } bits;
1949         unsigned int value;
1950     } pic_quantizer_fields;
1951     union {
1952         struct {
1953             unsigned int variable_sized_transform_flag  : 1;/* ENTRY_POINT_LAYER::VSTRANSFORM */
1954             unsigned int mb_level_transform_type_flag   : 1;/* PICTURE_LAYER::TTMBF */
1955             unsigned int frame_level_transform_type     : 2;/* PICTURE_LAYER::TTFRM */
1956             unsigned int transform_ac_codingset_idx1    : 2;/* PICTURE_LAYER::TRANSACFRM */
1957             unsigned int transform_ac_codingset_idx2    : 2;/* PICTURE_LAYER::TRANSACFRM2 */
1958             unsigned int intra_transform_dc_table       : 1;/* PICTURE_LAYER::TRANSDCTAB */
1959         } bits;
1960         unsigned int value;
1961     } transform_fields;
1962 } VAPictureParameterBufferVC1;
1963
1964 /** VC-1 Bitplane Buffer
1965 There will be at most three bitplanes coded in any picture header. To send 
1966 the bitplane data more efficiently, each byte is divided in two nibbles, with
1967 each nibble carrying three bitplanes for one macroblock.  The following table
1968 shows the bitplane data arrangement within each nibble based on the picture
1969 type.
1970
1971 Picture Type    Bit3            Bit2            Bit1            Bit0
1972 I or BI                         OVERFLAGS       ACPRED          FIELDTX
1973 P                               MYTYPEMB        SKIPMB          DIRECTMB
1974 B                               FORWARDMB       SKIPMB          DIRECTMB
1975
1976 Within each byte, the lower nibble is for the first MB and the upper nibble is 
1977 for the second MB.  E.g. the lower nibble of the first byte in the bitplane
1978 buffer is for Macroblock #1 and the upper nibble of the first byte is for 
1979 Macroblock #2 in the first row.
1980 */
1981
1982 /* VC-1 Slice Parameter Buffer */
1983 typedef struct _VASliceParameterBufferVC1
1984 {
1985     unsigned int slice_data_size;/* number of bytes in the slice data buffer for this slice */
1986     unsigned int slice_data_offset;/* the offset to the first byte of slice data */
1987     unsigned int slice_data_flag; /* see VA_SLICE_DATA_FLAG_XXX defintions */
1988     unsigned int macroblock_offset;/* the offset to the first bit of MB from the first byte of slice data */
1989     unsigned int slice_vertical_position;
1990 } VASliceParameterBufferVC1;
1991
1992 /* VC-1 Slice Data Buffer */
1993 /* 
1994 This is simplely a buffer containing raw bit-stream bytes 
1995 */
1996
1997 /****************************
1998  * H.264/AVC data structures
1999  ****************************/
2000
2001 typedef struct _VAPictureH264
2002 {
2003     VASurfaceID picture_id;
2004     unsigned int frame_idx;
2005     unsigned int flags;
2006     signed int TopFieldOrderCnt;
2007     signed int BottomFieldOrderCnt;
2008 } VAPictureH264;
2009 /* flags in VAPictureH264 could be OR of the following */
2010 #define VA_PICTURE_H264_INVALID                 0x00000001
2011 #define VA_PICTURE_H264_TOP_FIELD               0x00000002
2012 #define VA_PICTURE_H264_BOTTOM_FIELD            0x00000004
2013 #define VA_PICTURE_H264_SHORT_TERM_REFERENCE    0x00000008
2014 #define VA_PICTURE_H264_LONG_TERM_REFERENCE     0x00000010
2015
2016 /** H.264 Picture Parameter Buffer */
2017 /* 
2018  * For each picture, and before any slice data, a single
2019  * picture parameter buffer must be send.
2020  */
2021 typedef struct _VAPictureParameterBufferH264
2022 {
2023     VAPictureH264 CurrPic;
2024     VAPictureH264 ReferenceFrames[16];  /* in DPB */
2025     unsigned short picture_width_in_mbs_minus1;
2026     unsigned short picture_height_in_mbs_minus1;
2027     unsigned char bit_depth_luma_minus8;
2028     unsigned char bit_depth_chroma_minus8;
2029     unsigned char num_ref_frames;
2030     union {
2031         struct {
2032             unsigned int chroma_format_idc                      : 2; 
2033             unsigned int residual_colour_transform_flag         : 1; 
2034             unsigned int gaps_in_frame_num_value_allowed_flag   : 1; 
2035             unsigned int frame_mbs_only_flag                    : 1; 
2036             unsigned int mb_adaptive_frame_field_flag           : 1; 
2037             unsigned int direct_8x8_inference_flag              : 1; 
2038             unsigned int MinLumaBiPredSize8x8                   : 1; /* see A.3.3.2 */
2039             unsigned int log2_max_frame_num_minus4              : 4;
2040             unsigned int pic_order_cnt_type                     : 2;
2041             unsigned int log2_max_pic_order_cnt_lsb_minus4      : 4;
2042             unsigned int delta_pic_order_always_zero_flag       : 1;
2043         } bits;
2044         unsigned int value;
2045     } seq_fields;
2046     unsigned char num_slice_groups_minus1;
2047     unsigned char slice_group_map_type;
2048     unsigned short slice_group_change_rate_minus1;
2049     signed char pic_init_qp_minus26;
2050     signed char pic_init_qs_minus26;
2051     signed char chroma_qp_index_offset;
2052     signed char second_chroma_qp_index_offset;
2053     union {
2054         struct {
2055             unsigned int entropy_coding_mode_flag       : 1;
2056             unsigned int weighted_pred_flag             : 1;
2057             unsigned int weighted_bipred_idc            : 2;
2058             unsigned int transform_8x8_mode_flag        : 1;
2059             unsigned int field_pic_flag                 : 1;
2060             unsigned int constrained_intra_pred_flag    : 1;
2061             unsigned int pic_order_present_flag                 : 1;
2062             unsigned int deblocking_filter_control_present_flag : 1;
2063             unsigned int redundant_pic_cnt_present_flag         : 1;
2064             unsigned int reference_pic_flag                     : 1; /* nal_ref_idc != 0 */
2065         } bits;
2066         unsigned int value;
2067     } pic_fields;
2068     unsigned short frame_num;
2069 } VAPictureParameterBufferH264;
2070
2071 /** H.264 Inverse Quantization Matrix Buffer */
2072 typedef struct _VAIQMatrixBufferH264
2073 {
2074     /** \brief 4x4 scaling list, in raster scan order. */
2075     unsigned char ScalingList4x4[6][16];
2076     /** \brief 8x8 scaling list, in raster scan order. */
2077     unsigned char ScalingList8x8[2][64];
2078 } VAIQMatrixBufferH264;
2079
2080 /**
2081  * H.264 Slice Group Map Buffer 
2082  * When VAPictureParameterBufferH264::num_slice_group_minus1 is not equal to 0,
2083  * A slice group map buffer should be sent for each picture if required. The buffer
2084  * is sent only when there is a change in the mapping values.
2085  * The slice group map buffer map "map units" to slice groups as specified in 
2086  * section 8.2.2 of the H.264 spec. The buffer will contain one byte for each macroblock 
2087  * in raster scan order
2088  */ 
2089
2090 /** H.264 Slice Parameter Buffer */
2091 typedef struct _VASliceParameterBufferH264
2092 {
2093     unsigned int slice_data_size;/* number of bytes in the slice data buffer for this slice */
2094     /** \brief Byte offset to the NAL Header Unit for this slice. */
2095     unsigned int slice_data_offset;
2096     unsigned int slice_data_flag; /* see VA_SLICE_DATA_FLAG_XXX defintions */
2097     /**
2098      * \brief Bit offset from NAL Header Unit to the begining of slice_data().
2099      *
2100      * This bit offset is relative to and includes the NAL unit byte
2101      * and represents the number of bits parsed in the slice_header()
2102      * after the removal of any emulation prevention bytes in
2103      * there. However, the slice data buffer passed to the hardware is
2104      * the original bitstream, thus including any emulation prevention
2105      * bytes.
2106      */
2107     unsigned short slice_data_bit_offset;
2108     unsigned short first_mb_in_slice;
2109     unsigned char slice_type;
2110     unsigned char direct_spatial_mv_pred_flag;
2111     unsigned char num_ref_idx_l0_active_minus1;
2112     unsigned char num_ref_idx_l1_active_minus1;
2113     unsigned char cabac_init_idc;
2114     char slice_qp_delta;
2115     unsigned char disable_deblocking_filter_idc;
2116     char slice_alpha_c0_offset_div2;
2117     char slice_beta_offset_div2;
2118     VAPictureH264 RefPicList0[32];      /* See 8.2.4.2 */
2119     VAPictureH264 RefPicList1[32];      /* See 8.2.4.2 */
2120     unsigned char luma_log2_weight_denom;
2121     unsigned char chroma_log2_weight_denom;
2122     unsigned char luma_weight_l0_flag;
2123     short luma_weight_l0[32];
2124     short luma_offset_l0[32];
2125     unsigned char chroma_weight_l0_flag;
2126     short chroma_weight_l0[32][2];
2127     short chroma_offset_l0[32][2];
2128     unsigned char luma_weight_l1_flag;
2129     short luma_weight_l1[32];
2130     short luma_offset_l1[32];
2131     unsigned char chroma_weight_l1_flag;
2132     short chroma_weight_l1[32][2];
2133     short chroma_offset_l1[32][2];
2134 } VASliceParameterBufferH264;
2135
2136 /****************************
2137  * Common encode data structures 
2138  ****************************/
2139 typedef enum
2140 {
2141     VAEncPictureTypeIntra               = 0,
2142     VAEncPictureTypePredictive          = 1,
2143     VAEncPictureTypeBidirectional       = 2,
2144 } VAEncPictureType;
2145
2146 /* Encode Slice Parameter Buffer */
2147 typedef struct _VAEncSliceParameterBuffer
2148 {
2149     unsigned int start_row_number;      /* starting MB row number for this slice */
2150     unsigned int slice_height;  /* slice height measured in MB */
2151     union {
2152         struct {
2153             unsigned int is_intra       : 1;
2154             unsigned int disable_deblocking_filter_idc : 2;
2155             unsigned int uses_long_term_ref             :1;
2156             unsigned int is_long_term_ref               :1;
2157         } bits;
2158         unsigned int value;
2159     } slice_flags;
2160 } VAEncSliceParameterBuffer;
2161
2162
2163 /****************************
2164  * H.263 specific encode data structures
2165  ****************************/
2166
2167 typedef struct _VAEncSequenceParameterBufferH263
2168 {
2169     unsigned int intra_period;
2170     unsigned int bits_per_second;
2171     unsigned int frame_rate;
2172     unsigned int initial_qp;
2173     unsigned int min_qp;
2174 } VAEncSequenceParameterBufferH263;
2175
2176 typedef struct _VAEncPictureParameterBufferH263
2177 {
2178     VASurfaceID reference_picture;
2179     VASurfaceID reconstructed_picture;
2180     VABufferID coded_buf;
2181     unsigned short picture_width;
2182     unsigned short picture_height;
2183     VAEncPictureType picture_type;
2184 } VAEncPictureParameterBufferH263;
2185
2186 /****************************
2187  * MPEG-4 specific encode data structures
2188  ****************************/
2189
2190 typedef struct _VAEncSequenceParameterBufferMPEG4
2191 {
2192     unsigned char profile_and_level_indication;
2193     unsigned int intra_period;
2194     unsigned int video_object_layer_width;
2195     unsigned int video_object_layer_height;
2196     unsigned int vop_time_increment_resolution;
2197     unsigned int fixed_vop_rate;
2198     unsigned int fixed_vop_time_increment;
2199     unsigned int bits_per_second;
2200     unsigned int frame_rate;
2201     unsigned int initial_qp;
2202     unsigned int min_qp;
2203 } VAEncSequenceParameterBufferMPEG4;
2204
2205 typedef struct _VAEncPictureParameterBufferMPEG4
2206 {
2207     VASurfaceID reference_picture;
2208     VASurfaceID reconstructed_picture;
2209     VABufferID coded_buf;
2210     unsigned short picture_width;
2211     unsigned short picture_height;
2212     unsigned int modulo_time_base; /* number of 1s */
2213     unsigned int vop_time_increment;
2214     VAEncPictureType picture_type;
2215 } VAEncPictureParameterBufferMPEG4;
2216
2217
2218
2219 /** Buffer functions */
2220
2221 /**
2222  * Creates a buffer for "num_elements" elements of "size" bytes and 
2223  * initalize with "data".
2224  * if "data" is null, then the contents of the buffer data store
2225  * are undefined.
2226  * Basically there are two ways to get buffer data to the server side. One is 
2227  * to call vaCreateBuffer() with a non-null "data", which results the data being
2228  * copied to the data store on the server side.  A different method that 
2229  * eliminates this copy is to pass null as "data" when calling vaCreateBuffer(),
2230  * and then use vaMapBuffer() to map the data store from the server side to the
2231  * client address space for access.
2232  * The user must call vaDestroyBuffer() to destroy a buffer.
2233  *  Note: image buffers are created by the library, not the client. Please see 
2234  *        vaCreateImage on how image buffers are managed.
2235  */
2236 VAStatus vaCreateBuffer (
2237     VADisplay dpy,
2238     VAContextID context,
2239     VABufferType type,  /* in */
2240     unsigned int size,  /* in */
2241     unsigned int num_elements, /* in */
2242     void *data,         /* in */
2243     VABufferID *buf_id  /* out */
2244 );
2245
2246 /**
2247  * Convey to the server how many valid elements are in the buffer. 
2248  * e.g. if multiple slice parameters are being held in a single buffer,
2249  * this will communicate to the server the number of slice parameters
2250  * that are valid in the buffer.
2251  */
2252 VAStatus vaBufferSetNumElements (
2253     VADisplay dpy,
2254     VABufferID buf_id,  /* in */
2255     unsigned int num_elements /* in */
2256 );
2257
2258
2259 /**
2260  * device independent data structure for codedbuffer
2261  */
2262
2263 /* 
2264  * FICTURE_AVE_QP(bit7-0): The average Qp value used during this frame
2265  * LARGE_SLICE(bit8):At least one slice in the current frame was large
2266  *              enough for the encoder to attempt to limit its size.
2267  * SLICE_OVERFLOW(bit9): At least one slice in the current frame has
2268  *              exceeded the maximum slice size specified.
2269  * BITRATE_OVERFLOW(bit10): The peak bitrate was exceeded for this frame.
2270  * BITRATE_HIGH(bit11): The frame size got within the safety margin of the maximum size (VCM only)
2271  * AIR_MB_OVER_THRESHOLD: the number of MBs adapted to Intra MB
2272  */
2273 #define VA_CODED_BUF_STATUS_PICTURE_AVE_QP_MASK         0xff
2274 #define VA_CODED_BUF_STATUS_LARGE_SLICE_MASK            0x100
2275 #define VA_CODED_BUF_STATUS_SLICE_OVERFLOW_MASK         0x200
2276 #define VA_CODED_BUF_STATUS_BITRATE_OVERFLOW            0x400
2277 #define VA_CODED_BUF_STATUS_BITRATE_HIGH                0x800
2278 /**
2279  * \brief The frame has exceeded the maximum requested size.
2280  *
2281  * This flag indicates that the encoded frame size exceeds the value
2282  * specified through a misc parameter buffer of type
2283  * #VAEncMiscParameterTypeMaxFrameSize.
2284  */
2285 #define VA_CODED_BUF_STATUS_FRAME_SIZE_OVERFLOW         0x1000
2286 #define VA_CODED_BUF_STATUS_AIR_MB_OVER_THRESHOLD       0xff0000
2287
2288 /**
2289  * \brief The coded buffer segment contains a single NAL unit. 
2290  *
2291  * This flag indicates that the coded buffer segment contains a
2292  * single NAL unit. This flag might be useful to the user for 
2293  * processing the coded buffer.
2294  */
2295 #define VA_CODED_BUF_STATUS_SINGLE_NALU                 0x10000000      
2296
2297 /**
2298  * \brief Coded buffer segment.
2299  *
2300  * #VACodedBufferSegment is an element of a linked list describing
2301  * some information on the coded buffer. The coded buffer segment
2302  * could contain either a single NAL unit, or more than one NAL unit. 
2303  * It is recommended (but not required) to return a single NAL unit 
2304  * in a coded buffer segment, and the implementation should set the 
2305  * VA_CODED_BUF_STATUS_SINGLE_NALU status flag if that is the case.
2306  */
2307 typedef  struct _VACodedBufferSegment  {
2308     /**
2309      * \brief Size of the data buffer in this segment (in bytes).
2310      */
2311     unsigned int        size;
2312     /** \brief Bit offset into the data buffer where the video data starts. */
2313     unsigned int        bit_offset;
2314     /** \brief Status set by the driver. See \c VA_CODED_BUF_STATUS_*. */
2315     unsigned int        status;
2316     /** \brief Reserved for future use. */
2317     unsigned int        reserved;
2318     /** \brief Pointer to the start of the data buffer. */
2319     void               *buf;
2320     /**
2321      * \brief Pointer to the next #VACodedBufferSegment element,
2322      * or \c NULL if there is none.
2323      */
2324     void               *next;
2325 } VACodedBufferSegment;
2326      
2327 /**
2328  * Map data store of the buffer into the client's address space
2329  * vaCreateBuffer() needs to be called with "data" set to NULL before
2330  * calling vaMapBuffer()
2331  *
2332  * if buffer type is VAEncCodedBufferType, pbuf points to link-list of
2333  * VACodedBufferSegment, and the list is terminated if "next" is NULL
2334  */
2335 VAStatus vaMapBuffer (
2336     VADisplay dpy,
2337     VABufferID buf_id,  /* in */
2338     void **pbuf         /* out */
2339 );
2340
2341 /**
2342  * After client making changes to a mapped data store, it needs to
2343  * "Unmap" it to let the server know that the data is ready to be
2344  * consumed by the server
2345  */
2346 VAStatus vaUnmapBuffer (
2347     VADisplay dpy,
2348     VABufferID buf_id   /* in */
2349 );
2350
2351 /**
2352  * After this call, the buffer is deleted and this buffer_id is no longer valid
2353  *
2354  * A buffer can be re-used and sent to the server by another Begin/Render/End
2355  * sequence if vaDestroyBuffer() is not called with this buffer.
2356  *
2357  * Note re-using a shared buffer (e.g. a slice data buffer) between the host and the
2358  * hardware accelerator can result in performance dropping.
2359  */
2360 VAStatus vaDestroyBuffer (
2361     VADisplay dpy,
2362     VABufferID buffer_id
2363 );
2364
2365 /** \brief VA buffer information */
2366 typedef struct {
2367     /** \brief Buffer handle */
2368     uintptr_t           handle;
2369     /** \brief Buffer type (See \ref VABufferType). */
2370     uint32_t            type;
2371     /**
2372      * \brief Buffer memory type (See \ref VASurfaceAttribMemoryType).
2373      *
2374      * On input to vaAcquireBufferHandle(), this field can serve as a hint
2375      * to specify the set of memory types the caller is interested in.
2376      * On successful return from vaAcquireBufferHandle(), the field is
2377      * updated with the best matching memory type.
2378      */
2379     uint32_t            mem_type;
2380     /** \brief Size of the underlying buffer. */
2381     size_t              mem_size;
2382 } VABufferInfo;
2383
2384 /**
2385  * \brief Acquires buffer handle for external API usage
2386  *
2387  * Locks the VA buffer object \ref buf_id for external API usage like
2388  * EGL or OpenCL (OCL). This function is a synchronization point. This
2389  * means that any pending operation is guaranteed to be completed
2390  * prior to returning from the function.
2391  *
2392  * If the referenced VA buffer object is the backing store of a VA
2393  * surface, then this function acts as if vaSyncSurface() on the
2394  * parent surface was called first.
2395  *
2396  * The \ref VABufferInfo argument shall be zero'ed on input. On
2397  * successful output, the data structure is filled in with all the
2398  * necessary buffer level implementation details like handle, type,
2399  * memory type and memory size.
2400  *
2401  * Note: the external API implementation, or the application, can
2402  * express the memory types it is interested in by filling in the \ref
2403  * mem_type field accordingly. On successful output, the memory type
2404  * that fits best the request and that was used is updated in the \ref
2405  * VABufferInfo data structure. If none of the supplied memory types
2406  * is supported, then a \ref VA_STATUS_ERROR_UNSUPPORTED_MEMORY_TYPE
2407  * error is returned.
2408  *
2409  * The \ref VABufferInfo data is valid until vaReleaseBufferHandle()
2410  * is called. Besides, no additional operation is allowed on any of
2411  * the buffer parent object until vaReleaseBufferHandle() is called.
2412  * e.g. decoding into a VA surface backed with the supplied VA buffer
2413  * object \ref buf_id would fail with a \ref VA_STATUS_ERROR_SURFACE_BUSY
2414  * error.
2415  *
2416  * Possible errors:
2417  * - \ref VA_STATUS_ERROR_UNIMPLEMENTED: the VA driver implementation
2418  *   does not support this interface
2419  * - \ref VA_STATUS_ERROR_INVALID_DISPLAY: an invalid display was supplied
2420  * - \ref VA_STATUS_ERROR_INVALID_BUFFER: an invalid buffer was supplied
2421  * - \ref VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE: the implementation
2422  *   does not support exporting buffers of the specified type
2423  * - \ref VA_STATUS_ERROR_UNSUPPORTED_MEMORY_TYPE: none of the requested
2424  *   memory types in \ref VABufferInfo.mem_type was supported
2425  *
2426  * @param[in] dpy               the VA display
2427  * @param[in] buf_id            the VA buffer
2428  * @param[in,out] buf_info      the associated VA buffer information
2429  * @return VA_STATUS_SUCCESS if successful
2430  */
2431 VAStatus
2432 vaAcquireBufferHandle(VADisplay dpy, VABufferID buf_id, VABufferInfo *buf_info);
2433
2434 /**
2435  * \brief Releases buffer after usage from external API
2436  *
2437  * Unlocks the VA buffer object \ref buf_id from external API usage like
2438  * EGL or OpenCL (OCL). This function is a synchronization point. This
2439  * means that any pending operation is guaranteed to be completed
2440  * prior to returning from the function.
2441  *
2442  * The \ref VABufferInfo argument shall point to the original data
2443  * structure that was obtained from vaAcquireBufferHandle(), unaltered.
2444  * This is necessary so that the VA driver implementation could
2445  * deallocate any resources that were needed.
2446  *
2447  * In any case, returning from this function invalidates any contents
2448  * in \ref VABufferInfo. i.e. the underlyng buffer handle is no longer
2449  * valid. Therefore, VA driver implementations are free to reset this
2450  * data structure to safe defaults.
2451  *
2452  * Possible errors:
2453  * - \ref VA_STATUS_ERROR_UNIMPLEMENTED: the VA driver implementation
2454  *   does not support this interface
2455  * - \ref VA_STATUS_ERROR_INVALID_DISPLAY: an invalid display was supplied
2456  * - \ref VA_STATUS_ERROR_INVALID_BUFFER: an invalid buffer was supplied
2457  * - \ref VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE: the implementation
2458  *   does not support exporting buffers of the specified type
2459  *
2460  * @param[in] dpy               the VA display
2461  * @param[in] buf_id            the VA buffer
2462  * @return VA_STATUS_SUCCESS if successful
2463  */
2464 VAStatus
2465 vaReleaseBufferHandle(VADisplay dpy, VABufferID buf_id);
2466
2467 /*
2468 Render (Decode) Pictures
2469
2470 A picture represents either a frame or a field.
2471
2472 The Begin/Render/End sequence sends the decode buffers to the server
2473 */
2474
2475 /**
2476  * Get ready to decode a picture to a target surface
2477  */
2478 VAStatus vaBeginPicture (
2479     VADisplay dpy,
2480     VAContextID context,
2481     VASurfaceID render_target
2482 );
2483
2484 /**
2485  * Send decode buffers to the server.
2486  */
2487 VAStatus vaRenderPicture (
2488     VADisplay dpy,
2489     VAContextID context,
2490     VABufferID *buffers,
2491     int num_buffers
2492 );
2493
2494 /**
2495  * Make the end of rendering for a picture. 
2496  * The server should start processing all pending operations for this 
2497  * surface. This call is non-blocking. The client can start another 
2498  * Begin/Render/End sequence on a different render target.
2499  */
2500 VAStatus vaEndPicture (
2501     VADisplay dpy,
2502     VAContextID context
2503 );
2504
2505 /*
2506
2507 Synchronization 
2508
2509 */
2510
2511 /**
2512  * This function blocks until all pending operations on the render target
2513  * have been completed.  Upon return it is safe to use the render target for a 
2514  * different picture. 
2515  */
2516 VAStatus vaSyncSurface (
2517     VADisplay dpy,
2518     VASurfaceID render_target
2519 );
2520
2521 typedef enum
2522 {
2523     VASurfaceRendering  = 1, /* Rendering in progress */ 
2524     VASurfaceDisplaying = 2, /* Displaying in progress (not safe to render into it) */ 
2525                              /* this status is useful if surface is used as the source */
2526                              /* of an overlay */
2527     VASurfaceReady      = 4, /* not being rendered or displayed */
2528     VASurfaceSkipped    = 8  /* Indicate a skipped frame during encode */
2529 } VASurfaceStatus;
2530
2531 /**
2532  * Find out any pending ops on the render target 
2533  */
2534 VAStatus vaQuerySurfaceStatus (
2535     VADisplay dpy,
2536     VASurfaceID render_target,
2537     VASurfaceStatus *status     /* out */
2538 );
2539
2540 typedef enum
2541 {
2542     VADecodeSliceMissing            = 0,
2543     VADecodeMBError                 = 1,
2544 } VADecodeErrorType;
2545
2546 /**
2547  * Client calls vaQuerySurfaceError with VA_STATUS_ERROR_DECODING_ERROR, server side returns
2548  * an array of structure VASurfaceDecodeMBErrors, and the array is terminated by setting status=-1
2549 */
2550 typedef struct _VASurfaceDecodeMBErrors
2551 {
2552     int status; /* 1 if hardware has returned detailed info below, -1 means this record is invalid */
2553     unsigned int start_mb; /* start mb address with errors */
2554     unsigned int end_mb;  /* end mb address with errors */
2555     VADecodeErrorType decode_error_type;
2556 } VASurfaceDecodeMBErrors;
2557
2558 /**
2559  * After the application gets VA_STATUS_ERROR_DECODING_ERROR after calling vaSyncSurface(),
2560  * it can call vaQuerySurfaceError to find out further details on the particular error.
2561  * VA_STATUS_ERROR_DECODING_ERROR should be passed in as "error_status",
2562  * upon the return, error_info will point to an array of _VASurfaceDecodeMBErrors structure,
2563  * which is allocated and filled by libVA with detailed information on the missing or error macroblocks.
2564  * The array is terminated if "status==-1" is detected.
2565  */
2566 VAStatus vaQuerySurfaceError(
2567     VADisplay dpy,
2568     VASurfaceID surface,
2569     VAStatus error_status,
2570     void **error_info
2571 );
2572
2573 /**
2574  * Images and Subpictures
2575  * VAImage is used to either get the surface data to client memory, or 
2576  * to copy image data in client memory to a surface. 
2577  * Both images, subpictures and surfaces follow the same 2D coordinate system where origin 
2578  * is at the upper left corner with positive X to the right and positive Y down
2579  */
2580 #define VA_FOURCC(ch0, ch1, ch2, ch3) \
2581     ((unsigned long)(unsigned char) (ch0) | ((unsigned long)(unsigned char) (ch1) << 8) | \
2582     ((unsigned long)(unsigned char) (ch2) << 16) | ((unsigned long)(unsigned char) (ch3) << 24 ))
2583
2584 /* 
2585  * Pre-defined fourcc codes
2586  */
2587 #define VA_FOURCC_NV12          0x3231564E
2588 #define VA_FOURCC_AI44          0x34344149
2589 #define VA_FOURCC_RGBA          0x41424752
2590 #define VA_FOURCC_RGBX          0x58424752
2591 #define VA_FOURCC_BGRA          0x41524742
2592 #define VA_FOURCC_BGRX          0x58524742
2593 #define VA_FOURCC_ARGB          0x42475241
2594 #define VA_FOURCC_XRGB          0x42475258
2595 #define VA_FOURCC_ABGR          0x52474241
2596 #define VA_FOURCC_XBGR          0x52474258
2597 #define VA_FOURCC_UYVY          0x59565955
2598 #define VA_FOURCC_YUY2          0x32595559
2599 #define VA_FOURCC_AYUV          0x56555941
2600 #define VA_FOURCC_NV11          0x3131564e
2601 #define VA_FOURCC_YV12          0x32315659
2602 #define VA_FOURCC_P208          0x38303250
2603 #define VA_FOURCC_IYUV          0x56555949
2604 #define VA_FOURCC_YV24          0x34325659
2605 #define VA_FOURCC_YV32          0x32335659
2606 #define VA_FOURCC_Y800          0x30303859
2607 #define VA_FOURCC_IMC3          0x33434D49
2608 #define VA_FOURCC_411P          0x50313134
2609 #define VA_FOURCC_422H          0x48323234
2610 #define VA_FOURCC_422V          0x56323234
2611 #define VA_FOURCC_444P          0x50343434
2612 #define VA_FOURCC_RGBP          0x50424752
2613 #define VA_FOURCC_BGRP          0x50524742
2614 #define VA_FOURCC_411R          0x52313134 /* rotated 411P */
2615 /**
2616  * Planar YUV 4:2:2.
2617  * 8-bit Y plane, followed by 8-bit 2x1 subsampled V and U planes
2618  */
2619 #define VA_FOURCC_YV16          0x36315659
2620 /**
2621  * 10-bit and 16-bit Planar YUV 4:2:0. 
2622  */
2623 #define VA_FOURCC_P010          0x30313050
2624 #define VA_FOURCC_P016          0x36313050
2625
2626 /**
2627  * 10-bit Planar YUV 420 and occupy the lower 10-bit.
2628  */
2629 #define VA_FOURCC_I010          0x30313049
2630
2631 /* byte order */
2632 #define VA_LSB_FIRST            1
2633 #define VA_MSB_FIRST            2
2634
2635 typedef struct _VAImageFormat
2636 {
2637     unsigned int        fourcc;
2638     unsigned int        byte_order; /* VA_LSB_FIRST, VA_MSB_FIRST */
2639     unsigned int        bits_per_pixel;
2640     /* for RGB formats */
2641     unsigned int        depth; /* significant bits per pixel */
2642     unsigned int        red_mask;
2643     unsigned int        green_mask;
2644     unsigned int        blue_mask;
2645     unsigned int        alpha_mask;
2646 } VAImageFormat;
2647
2648 typedef VAGenericID VAImageID;
2649
2650 typedef struct _VAImage
2651 {
2652     VAImageID           image_id; /* uniquely identify this image */
2653     VAImageFormat       format;
2654     VABufferID          buf;    /* image data buffer */
2655     /*
2656      * Image data will be stored in a buffer of type VAImageBufferType to facilitate
2657      * data store on the server side for optimal performance. The buffer will be 
2658      * created by the CreateImage function, and proper storage allocated based on the image
2659      * size and format. This buffer is managed by the library implementation, and 
2660      * accessed by the client through the buffer Map/Unmap functions.
2661      */
2662     unsigned short      width; 
2663     unsigned short      height;
2664     unsigned int        data_size;
2665     unsigned int        num_planes;     /* can not be greater than 3 */
2666     /* 
2667      * An array indicating the scanline pitch in bytes for each plane.
2668      * Each plane may have a different pitch. Maximum 3 planes for planar formats
2669      */
2670     unsigned int        pitches[3];
2671     /* 
2672      * An array indicating the byte offset from the beginning of the image data 
2673      * to the start of each plane.
2674      */
2675     unsigned int        offsets[3];
2676
2677     /* The following fields are only needed for paletted formats */
2678     int num_palette_entries;   /* set to zero for non-palette images */
2679     /* 
2680      * Each component is one byte and entry_bytes indicates the number of components in 
2681      * each entry (eg. 3 for YUV palette entries). set to zero for non-palette images   
2682      */
2683     int entry_bytes; 
2684     /*
2685      * An array of ascii characters describing the order of the components within the bytes.
2686      * Only entry_bytes characters of the string are used.
2687      */
2688     char component_order[4];
2689 } VAImage;
2690
2691 /** Get maximum number of image formats supported by the implementation */
2692 int vaMaxNumImageFormats (
2693     VADisplay dpy
2694 );
2695
2696 /**
2697  * Query supported image formats 
2698  * The caller must provide a "format_list" array that can hold at
2699  * least vaMaxNumImageFormats() entries. The actual number of formats
2700  * returned in "format_list" is returned in "num_formats".
2701  */
2702 VAStatus vaQueryImageFormats (
2703     VADisplay dpy,
2704     VAImageFormat *format_list, /* out */
2705     int *num_formats            /* out */
2706 );
2707
2708 /**
2709  * Create a VAImage structure
2710  * The width and height fields returned in the VAImage structure may get 
2711  * enlarged for some YUV formats. Upon return from this function, 
2712  * image->buf has been created and proper storage allocated by the library. 
2713  * The client can access the image through the Map/Unmap calls.
2714  */
2715 VAStatus vaCreateImage (
2716     VADisplay dpy,
2717     VAImageFormat *format,
2718     int width,
2719     int height,
2720     VAImage *image      /* out */
2721 );
2722
2723 /**
2724  * Should call DestroyImage before destroying the surface it is bound to
2725  */
2726 VAStatus vaDestroyImage (
2727     VADisplay dpy,
2728     VAImageID image
2729 );
2730
2731 VAStatus vaSetImagePalette (
2732     VADisplay dpy,
2733     VAImageID image,
2734     /* 
2735      * pointer to an array holding the palette data.  The size of the array is 
2736      * num_palette_entries * entry_bytes in size.  The order of the components 
2737      * in the palette is described by the component_order in VAImage struct    
2738      */
2739     unsigned char *palette 
2740 );
2741
2742 /**
2743  * Retrive surface data into a VAImage
2744  * Image must be in a format supported by the implementation
2745  */
2746 VAStatus vaGetImage (
2747     VADisplay dpy,
2748     VASurfaceID surface,
2749     int x,      /* coordinates of the upper left source pixel */
2750     int y,
2751     unsigned int width, /* width and height of the region */
2752     unsigned int height,
2753     VAImageID image
2754 );
2755
2756 /**
2757  * Copy data from a VAImage to a surface
2758  * Image must be in a format supported by the implementation
2759  * Returns a VA_STATUS_ERROR_SURFACE_BUSY if the surface
2760  * shouldn't be rendered into when this is called
2761  */
2762 VAStatus vaPutImage (
2763     VADisplay dpy,
2764     VASurfaceID surface,
2765     VAImageID image,
2766     int src_x,
2767     int src_y,
2768     unsigned int src_width,
2769     unsigned int src_height,
2770     int dest_x,
2771     int dest_y,
2772     unsigned int dest_width,
2773     unsigned int dest_height
2774 );
2775
2776 /**
2777  * Derive an VAImage from an existing surface.
2778  * This interface will derive a VAImage and corresponding image buffer from
2779  * an existing VA Surface. The image buffer can then be mapped/unmapped for
2780  * direct CPU access. This operation is only possible on implementations with
2781  * direct rendering capabilities and internal surface formats that can be
2782  * represented with a VAImage. When the operation is not possible this interface
2783  * will return VA_STATUS_ERROR_OPERATION_FAILED. Clients should then fall back
2784  * to using vaCreateImage + vaPutImage to accomplish the same task in an
2785  * indirect manner.
2786  *
2787  * Implementations should only return success when the resulting image buffer
2788  * would be useable with vaMap/Unmap.
2789  *
2790  * When directly accessing a surface special care must be taken to insure
2791  * proper synchronization with the graphics hardware. Clients should call
2792  * vaQuerySurfaceStatus to insure that a surface is not the target of concurrent
2793  * rendering or currently being displayed by an overlay.
2794  *
2795  * Additionally nothing about the contents of a surface should be assumed
2796  * following a vaPutSurface. Implementations are free to modify the surface for
2797  * scaling or subpicture blending within a call to vaPutImage.
2798  *
2799  * Calls to vaPutImage or vaGetImage using the same surface from which the image
2800  * has been derived will return VA_STATUS_ERROR_SURFACE_BUSY. vaPutImage or
2801  * vaGetImage with other surfaces is supported.
2802  *
2803  * An image created with vaDeriveImage should be freed with vaDestroyImage. The
2804  * image and image buffer structures will be destroyed; however, the underlying
2805  * surface will remain unchanged until freed with vaDestroySurfaces.
2806  */
2807 VAStatus vaDeriveImage (
2808     VADisplay dpy,
2809     VASurfaceID surface,
2810     VAImage *image      /* out */
2811 );
2812
2813 /**
2814  * Subpictures 
2815  * Subpicture is a special type of image that can be blended 
2816  * with a surface during vaPutSurface(). Subpicture can be used to render
2817  * DVD sub-titles or closed captioning text etc.  
2818  */
2819
2820 typedef VAGenericID VASubpictureID;
2821
2822 /** Get maximum number of subpicture formats supported by the implementation */
2823 int vaMaxNumSubpictureFormats (
2824     VADisplay dpy
2825 );
2826
2827 /** flags for subpictures */
2828 #define VA_SUBPICTURE_CHROMA_KEYING                     0x0001
2829 #define VA_SUBPICTURE_GLOBAL_ALPHA                      0x0002
2830 #define VA_SUBPICTURE_DESTINATION_IS_SCREEN_COORD       0x0004
2831 /**
2832  * Query supported subpicture formats 
2833  * The caller must provide a "format_list" array that can hold at
2834  * least vaMaxNumSubpictureFormats() entries. The flags arrary holds the flag 
2835  * for each format to indicate additional capabilities for that format. The actual 
2836  * number of formats returned in "format_list" is returned in "num_formats".
2837  *  flags: returned value to indicate addtional capabilities
2838  *         VA_SUBPICTURE_CHROMA_KEYING - supports chroma-keying
2839  *         VA_SUBPICTURE_GLOBAL_ALPHA - supports global alpha
2840  *         VA_SUBPICTURE_DESTINATION_IS_SCREEN_COORD - supports unscaled screen relative subpictures for On Screen Display
2841  */
2842
2843 VAStatus vaQuerySubpictureFormats (
2844     VADisplay dpy,
2845     VAImageFormat *format_list, /* out */
2846     unsigned int *flags,        /* out */
2847     unsigned int *num_formats   /* out */
2848 );
2849
2850 /**
2851  * Subpictures are created with an image associated. 
2852  */
2853 VAStatus vaCreateSubpicture (
2854     VADisplay dpy,
2855     VAImageID image,
2856     VASubpictureID *subpicture  /* out */
2857 );
2858
2859 /**
2860  * Destroy the subpicture before destroying the image it is assocated to
2861  */
2862 VAStatus vaDestroySubpicture (
2863     VADisplay dpy,
2864     VASubpictureID subpicture
2865 );
2866
2867 /**
2868  * Bind an image to the subpicture. This image will now be associated with 
2869  * the subpicture instead of the one at creation.
2870  */
2871 VAStatus vaSetSubpictureImage (
2872     VADisplay dpy,
2873     VASubpictureID subpicture,
2874     VAImageID image
2875 );
2876
2877 /**
2878  * If chromakey is enabled, then the area where the source value falls within
2879  * the chromakey [min, max] range is transparent
2880  * The chromakey component format is the following:
2881  *  For RGB: [0:7] Red [8:15] Blue [16:23] Green   
2882  *  For YUV: [0:7] V [8:15] U [16:23] Y
2883  * The chromakey mask can be used to mask out certain components for chromakey
2884  * comparision
2885  */
2886 VAStatus vaSetSubpictureChromakey (
2887     VADisplay dpy,
2888     VASubpictureID subpicture,
2889     unsigned int chromakey_min,
2890     unsigned int chromakey_max,
2891     unsigned int chromakey_mask
2892 );
2893
2894 /**
2895  * Global alpha value is between 0 and 1. A value of 1 means fully opaque and 
2896  * a value of 0 means fully transparent. If per-pixel alpha is also specified then
2897  * the overall alpha is per-pixel alpha multiplied by the global alpha
2898  */
2899 VAStatus vaSetSubpictureGlobalAlpha (
2900     VADisplay dpy,
2901     VASubpictureID subpicture,
2902     float global_alpha 
2903 );
2904
2905 /**
2906  * vaAssociateSubpicture associates the subpicture with target_surfaces.
2907  * It defines the region mapping between the subpicture and the target  
2908  * surfaces through source and destination rectangles (with the same width and height).
2909  * Both will be displayed at the next call to vaPutSurface.  Additional
2910  * associations before the call to vaPutSurface simply overrides the association.
2911  */
2912 VAStatus vaAssociateSubpicture (
2913     VADisplay dpy,
2914     VASubpictureID subpicture,
2915     VASurfaceID *target_surfaces,
2916     int num_surfaces,
2917     short src_x, /* upper left offset in subpicture */
2918     short src_y,
2919     unsigned short src_width,
2920     unsigned short src_height,
2921     short dest_x, /* upper left offset in surface */
2922     short dest_y,
2923     unsigned short dest_width,
2924     unsigned short dest_height,
2925     /*
2926      * whether to enable chroma-keying, global-alpha, or screen relative mode
2927      * see VA_SUBPICTURE_XXX values
2928      */
2929     unsigned int flags
2930 );
2931
2932 /**
2933  * vaDeassociateSubpicture removes the association of the subpicture with target_surfaces.
2934  */
2935 VAStatus vaDeassociateSubpicture (
2936     VADisplay dpy,
2937     VASubpictureID subpicture,
2938     VASurfaceID *target_surfaces,
2939     int num_surfaces
2940 );
2941
2942 /**
2943  * Display attributes
2944  * Display attributes are used to control things such as contrast, hue, saturation,
2945  * brightness etc. in the rendering process.  The application can query what
2946  * attributes are supported by the driver, and then set the appropriate attributes
2947  * before calling vaPutSurface()
2948  */
2949 /* PowerVR IEP Lite attributes */
2950 typedef enum
2951 {
2952     VADISPLAYATTRIB_BLE_OFF              = 0x00,
2953     VADISPLAYATTRIB_BLE_LOW,
2954     VADISPLAYATTRIB_BLE_MEDIUM,
2955     VADISPLAYATTRIB_BLE_HIGH,
2956     VADISPLAYATTRIB_BLE_NONE,
2957 } VADisplayAttribBLEMode;
2958
2959 /** attribute value for VADisplayAttribRotation   */
2960 #define VA_ROTATION_NONE        0x00000000
2961 #define VA_ROTATION_90          0x00000001
2962 #define VA_ROTATION_180         0x00000002
2963 #define VA_ROTATION_270         0x00000003
2964
2965 /** attribute value for VADisplayAttribOutOfLoopDeblock */
2966 #define VA_OOL_DEBLOCKING_FALSE 0x00000000
2967 #define VA_OOL_DEBLOCKING_TRUE  0x00000001
2968
2969 /** Render mode */
2970 #define VA_RENDER_MODE_UNDEFINED           0
2971 #define VA_RENDER_MODE_LOCAL_OVERLAY       1
2972 #define VA_RENDER_MODE_LOCAL_GPU           2
2973 #define VA_RENDER_MODE_EXTERNAL_OVERLAY    4
2974 #define VA_RENDER_MODE_EXTERNAL_GPU        8
2975
2976 /** Render device */
2977 #define VA_RENDER_DEVICE_UNDEFINED  0
2978 #define VA_RENDER_DEVICE_LOCAL      1
2979 #define VA_RENDER_DEVICE_EXTERNAL   2
2980
2981 /** Currently defined display attribute types */
2982 typedef enum
2983 {
2984     VADisplayAttribBrightness           = 0,
2985     VADisplayAttribContrast             = 1,
2986     VADisplayAttribHue                  = 2,
2987     VADisplayAttribSaturation           = 3,
2988     /* client can specifiy a background color for the target window
2989      * the new feature of video conference,
2990      * the uncovered area of the surface is filled by this color
2991      * also it will blend with the decoded video color
2992      */
2993     VADisplayAttribBackgroundColor      = 4,
2994     /*
2995      * this is a gettable only attribute. For some implementations that use the
2996      * hardware overlay, after PutSurface is called, the surface can not be    
2997      * re-used until after the subsequent PutSurface call. If this is the case 
2998      * then the value for this attribute will be set to 1 so that the client   
2999      * will not attempt to re-use the surface right after returning from a call
3000      * to PutSurface.
3001      *
3002      * Don't use it, use flag VASurfaceDisplaying of vaQuerySurfaceStatus since
3003      * driver may use overlay or GPU alternatively
3004      */
3005     VADisplayAttribDirectSurface       = 5,
3006     VADisplayAttribRotation            = 6,     
3007     VADisplayAttribOutofLoopDeblock    = 7,
3008
3009     /* PowerVR IEP Lite specific attributes */
3010     VADisplayAttribBLEBlackMode        = 8,
3011     VADisplayAttribBLEWhiteMode        = 9,
3012     VADisplayAttribBlueStretch         = 10,
3013     VADisplayAttribSkinColorCorrection = 11,
3014     /*
3015      * For type VADisplayAttribCSCMatrix, "value" field is a pointer to the color
3016      * conversion matrix. Each element in the matrix is float-point
3017      */
3018     VADisplayAttribCSCMatrix           = 12,
3019     /* specify the constant color used to blend with video surface
3020      * Cd = Cv*Cc*Ac + Cb *(1 - Ac) C means the constant RGB
3021      *      d: the final color to overwrite into the frame buffer 
3022      *      v: decoded video after color conversion, 
3023      *      c: video color specified by VADisplayAttribBlendColor
3024      *      b: background color of the drawable
3025      */
3026     VADisplayAttribBlendColor          = 13,
3027     /*
3028      * Indicate driver to skip painting color key or not.
3029      * only applicable if the render is overlay
3030      */
3031     VADisplayAttribOverlayAutoPaintColorKey   = 14,
3032     /*
3033      * customized overlay color key, the format is RGB888
3034      * [23:16] = Red, [15:08] = Green, [07:00] = Blue.
3035      */
3036     VADisplayAttribOverlayColorKey      = 15,
3037     /*
3038      * The hint for the implementation of vaPutSurface
3039      * normally, the driver could use an overlay or GPU to render the surface on the screen
3040      * this flag provides APP the flexibity to switch the render dynamically
3041      */
3042     VADisplayAttribRenderMode           = 16,
3043     /*
3044      * specify if vaPutSurface needs to render into specified monitors
3045      * one example is that one external monitor (e.g. HDMI) is enabled, 
3046      * but the window manager is not aware of it, and there is no associated drawable
3047      */
3048     VADisplayAttribRenderDevice        = 17,
3049     /*
3050      * specify vaPutSurface render area if there is no drawable on the monitor
3051      */
3052     VADisplayAttribRenderRect          = 18,
3053 } VADisplayAttribType;
3054
3055 /* flags for VADisplayAttribute */
3056 #define VA_DISPLAY_ATTRIB_NOT_SUPPORTED 0x0000
3057 #define VA_DISPLAY_ATTRIB_GETTABLE      0x0001
3058 #define VA_DISPLAY_ATTRIB_SETTABLE      0x0002
3059
3060 typedef struct _VADisplayAttribute
3061 {
3062     VADisplayAttribType type;
3063     int min_value;
3064     int max_value;
3065     int value;  /* used by the set/get attribute functions */
3066 /* flags can be VA_DISPLAY_ATTRIB_GETTABLE or VA_DISPLAY_ATTRIB_SETTABLE or OR'd together */
3067     unsigned int flags;
3068 } VADisplayAttribute;
3069
3070 /** Get maximum number of display attributs supported by the implementation */
3071 int vaMaxNumDisplayAttributes (
3072     VADisplay dpy
3073 );
3074
3075 /**
3076  * Query display attributes 
3077  * The caller must provide a "attr_list" array that can hold at
3078  * least vaMaxNumDisplayAttributes() entries. The actual number of attributes
3079  * returned in "attr_list" is returned in "num_attributes".
3080  */
3081 VAStatus vaQueryDisplayAttributes (
3082     VADisplay dpy,
3083     VADisplayAttribute *attr_list,      /* out */
3084     int *num_attributes                 /* out */
3085 );
3086
3087 /**
3088  * Get display attributes 
3089  * This function returns the current attribute values in "attr_list".
3090  * Only attributes returned with VA_DISPLAY_ATTRIB_GETTABLE set in the "flags" field
3091  * from vaQueryDisplayAttributes() can have their values retrieved.  
3092  */
3093 VAStatus vaGetDisplayAttributes (
3094     VADisplay dpy,
3095     VADisplayAttribute *attr_list,      /* in/out */
3096     int num_attributes
3097 );
3098
3099 /**
3100  * Set display attributes 
3101  * Only attributes returned with VA_DISPLAY_ATTRIB_SETTABLE set in the "flags" field
3102  * from vaQueryDisplayAttributes() can be set.  If the attribute is not settable or 
3103  * the value is out of range, the function returns VA_STATUS_ERROR_ATTR_NOT_SUPPORTED
3104  */
3105 VAStatus vaSetDisplayAttributes (
3106     VADisplay dpy,
3107     VADisplayAttribute *attr_list,
3108     int num_attributes
3109 );
3110
3111 /****************************
3112  * HEVC data structures
3113  ****************************/
3114 /** 
3115  * \brief Description of picture properties of those in DPB surfaces.
3116  *
3117  * If only progressive scan is supported, each surface contains one whole 
3118  * frame picture.
3119  * Otherwise, each surface contains two fields of whole picture.
3120  * In this case, two entries of ReferenceFrames[] may share same picture_id
3121  * value.
3122  */
3123 typedef struct _VAPictureHEVC
3124 {
3125     /** \brief reconstructed picture buffer surface index 
3126      * invalid when taking value VA_INVALID_SURFACE.
3127      */
3128     VASurfaceID             picture_id;
3129     /** \brief picture order count. 
3130      * in HEVC, POCs for top and bottom fields of same picture should
3131      * take different values.
3132      */
3133     int32_t                 pic_order_cnt;
3134     /* described below */
3135     uint32_t                flags;
3136 } VAPictureHEVC;
3137
3138 /* flags in VAPictureHEVC could be OR of the following */
3139 #define VA_PICTURE_HEVC_INVALID                 0x00000001
3140 /** \brief indication of interlace scan picture. 
3141  * should take same value for all the pictures in sequence.
3142  */ 
3143 #define VA_PICTURE_HEVC_FIELD_PIC               0x00000002
3144 /** \brief polarity of the field picture.
3145  * top field takes even lines of buffer surface.
3146  * bottom field takes odd lines of buffer surface.
3147  */
3148 #define VA_PICTURE_HEVC_BOTTOM_FIELD            0x00000004
3149 /** \brief Long term reference picture */
3150 #define VA_PICTURE_HEVC_LONG_TERM_REFERENCE     0x00000008
3151 /**
3152  * VA_PICTURE_HEVC_RPS_ST_CURR_BEFORE, VA_PICTURE_HEVC_RPS_ST_CURR_AFTER
3153  * and VA_PICTURE_HEVC_RPS_LT_CURR of any picture in ReferenceFrames[] should 
3154  * be exclusive. No more than one of them can be set for any picture.
3155  * Sum of NumPocStCurrBefore, NumPocStCurrAfter and NumPocLtCurr
3156  * equals NumPocTotalCurr, which should be equal to or smaller than 8.
3157  * Application should provide valid values for both short format and long format.
3158  * The pictures in DPB with any of these three flags turned on are referred by
3159  * the current picture.
3160  */
3161 /** \brief RefPicSetStCurrBefore of HEVC spec variable 
3162  * Number of ReferenceFrames[] entries with this bit set equals 
3163  * NumPocStCurrBefore.
3164  */
3165 #define VA_PICTURE_HEVC_RPS_ST_CURR_BEFORE      0x00000010
3166 /** \brief RefPicSetStCurrAfter of HEVC spec variable
3167  * Number of ReferenceFrames[] entries with this bit set equals 
3168  * NumPocStCurrAfter.
3169  */
3170 #define VA_PICTURE_HEVC_RPS_ST_CURR_AFTER       0x00000020
3171 /** \brief RefPicSetLtCurr of HEVC spec variable
3172  * Number of ReferenceFrames[] entries with this bit set equals 
3173  * NumPocLtCurr.
3174  */
3175 #define VA_PICTURE_HEVC_RPS_LT_CURR             0x00000040
3176
3177 #include <va/va_dec_hevc.h>
3178 #include <va/va_dec_jpeg.h>
3179 #include <va/va_dec_vp8.h>
3180 #include <va/va_dec_vp9.h>
3181 #include <va/va_enc_hevc.h>
3182 #include <va/va_enc_h264.h>
3183 #include <va/va_enc_jpeg.h>
3184 #include <va/va_enc_mpeg2.h>
3185 #include <va/va_enc_vp8.h>
3186 #include <va/va_enc_vp9.h>
3187 #include <va/va_fei.h>
3188 #include <va/va_fei_h264.h>
3189 #include <va/va_vpp.h>
3190
3191 /**@}*/
3192
3193 #ifdef __cplusplus
3194 }
3195 #endif
3196
3197 #endif /* _VA_H_ */