OSDN Git Service

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