OSDN Git Service

va.h: fix comments error for arbitrary number of MBs per slice.
[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)(void);
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 macroblocks 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      * The framerate is specified as a number of frames per second, as a
1281      * fraction.  The denominator of the fraction is given in the top half
1282      * (the high two bytes) of the framerate field, and the numerator is
1283      * given in the bottom half (the low two bytes).
1284      *
1285      * That is:
1286      * denominator = framerate >> 16 & 0xffff;
1287      * numerator   = framerate & 0xffff;
1288      * fps         = numerator / denominator;
1289      *
1290      * For example, if framerate is set to (100 << 16 | 750), this is
1291      * 750 / 100, hence 7.5fps.
1292      *
1293      * If the denominator is zero (the high two bytes are both zero) then
1294      * it takes the value one instead, so the framerate is just the integer
1295      * in the low 2 bytes.
1296      */
1297     unsigned int framerate;
1298     union
1299     {
1300         struct
1301         {
1302             /*
1303              * The temporal id the framerate parameters are specified for.
1304              */
1305             unsigned int temporal_id : 8;
1306             unsigned int reserved : 24;
1307          } bits;
1308          unsigned int value;
1309      } framerate_flags;
1310 } VAEncMiscParameterFrameRate;
1311
1312 /**
1313  * Allow a maximum slice size to be specified (in bits).
1314  * The encoder will attempt to make sure that individual slices do not exceed this size
1315  * Or to signal applicate if the slice size exceed this size, see "status" of VACodedBufferSegment
1316  */
1317 typedef struct _VAEncMiscParameterMaxSliceSize
1318 {
1319     unsigned int max_slice_size;
1320 } VAEncMiscParameterMaxSliceSize;
1321
1322 typedef struct _VAEncMiscParameterAIR
1323 {
1324     unsigned int air_num_mbs;
1325     unsigned int air_threshold;
1326     unsigned int air_auto; /* if set to 1 then hardware auto-tune the AIR threshold */
1327 } VAEncMiscParameterAIR;
1328
1329 typedef struct _VAEncMiscParameterHRD
1330 {
1331     unsigned int initial_buffer_fullness;       /* in bits */
1332     unsigned int buffer_size;                   /* in bits */
1333 } VAEncMiscParameterHRD;
1334
1335 /**
1336  * \brief Defines a maximum frame size (in bits).
1337  *
1338  * This misc parameter buffer defines the maximum size of a frame (in
1339  * bits). The encoder will try to make sure that each frame does not
1340  * exceed this size. Otherwise, if the frame size exceeds this size,
1341  * the \c status flag of #VACodedBufferSegment will contain
1342  * #VA_CODED_BUF_STATUS_FRAME_SIZE_OVERFLOW.
1343  */
1344 typedef struct _VAEncMiscParameterBufferMaxFrameSize {
1345     /** \brief Type. Shall be set to #VAEncMiscParameterTypeMaxFrameSize. */
1346     VAEncMiscParameterType      type;
1347     /** \brief Maximum size of a frame (in bits). */
1348     unsigned int                max_frame_size;
1349 } VAEncMiscParameterBufferMaxFrameSize;
1350
1351 /**
1352  * \brief Encoding quality level.
1353  *
1354  * The encoding quality could be set through this structure, if the implementation  
1355  * supports multiple quality levels. The quality level set through this structure is 
1356  * persistent over the entire coded sequence, or until a new structure is being sent.
1357  * The quality level range can be queried through the VAConfigAttribEncQualityRange 
1358  * attribute. A lower value means higher quality, and a value of 1 represents the highest 
1359  * quality. The quality level setting is used as a trade-off between quality and speed/power 
1360  * consumption, with higher quality corresponds to lower speed and higher power consumption. 
1361  */
1362 typedef struct _VAEncMiscParameterBufferQualityLevel {
1363     /** \brief Encoding quality level setting. When set to 0, default quality
1364      * level is used.
1365      */
1366     unsigned int                quality_level;
1367 } VAEncMiscParameterBufferQualityLevel;
1368
1369 /**
1370  * \brief Encoding skip frame.
1371  *
1372  * The application may choose to skip frames externally to the encoder (e.g. drop completely or 
1373  * code as all skip's). For rate control purposes the encoder will need to know the size and number 
1374  * of skipped frames.  Skip frame(s) indicated through this structure is applicable only to the 
1375  * current frame.  It is allowed for the application to still send in packed headers for the driver to 
1376  * pack, although no frame will be encoded (e.g. for HW to encrypt the frame).  
1377  */
1378 typedef struct _VAEncMiscParameterSkipFrame {
1379     /** \brief Indicates skip frames as below.
1380       * 0: Encode as normal, no skip.
1381       * 1: One or more frames were skipped prior to the current frame, encode the current frame as normal.  
1382       * 2: The current frame is to be skipped, do not encode it but pack/encrypt the packed header contents
1383       *    (all except VAEncPackedHeaderSlice) which could contain actual frame contents (e.g. pack the frame 
1384       *    in VAEncPackedHeaderPicture).  */
1385     unsigned char               skip_frame_flag;
1386     /** \brief The number of frames skipped prior to the current frame.  Valid when skip_frame_flag = 1. */
1387     unsigned char               num_skip_frames;
1388     /** \brief When skip_frame_flag = 1, the size of the skipped frames in bits.   When skip_frame_flag = 2, 
1389       * the size of the current skipped frame that is to be packed/encrypted in bits. */
1390     unsigned int                size_skip_frames;
1391 } VAEncMiscParameterSkipFrame;
1392
1393 /**
1394  * \brief Encoding region-of-interest (ROI).
1395  *
1396  * The encoding ROI can be set through VAEncMiscParameterBufferROI, if the implementation
1397  * supports ROI input. The ROI set through this structure is applicable only to the
1398  * current frame or field, so must be sent every frame or field to be applied.  The number of
1399  * supported ROIs can be queried through the VAConfigAttribEncROI.  The encoder will use the
1400  * ROI information to adjust the QP values of the MB's that fall within the ROIs.
1401  */
1402 typedef struct _VAEncROI
1403 {
1404         /** \brief Defines the ROI boundary in pixels, the driver will map it to appropriate
1405          *  codec coding units.  It is relative to frame coordinates for the frame case and
1406          *  to field coordinates for the field case. */
1407         VARectangle     roi_rectangle;
1408         /**
1409          * \brief ROI value
1410          *
1411          * \ref roi_value specifies ROI delta QP or ROI priority.
1412          * --  ROI delta QP is the value that will be added on top of the frame level QP.
1413          * --  ROI priority specifies the priority of a region, it can be positive (more important)
1414          * or negative (less important) values and is compared with non-ROI region (taken as value 0),
1415          * E.g. ROI region with \ref roi_value -3 is less important than the non-ROI region (\ref roi_value
1416          * implied to be 0) which is less important than ROI region with roi_value +2. For overlapping
1417          * regions, the roi_value that is first in the ROI array will have priority.
1418          *
1419          * \ref roi_value always specifes ROI delta QP when VAConfigAttribRateControl == VA_RC_CQP, no matter
1420          * the value of \c roi_value_is_qp_delta in #VAEncMiscParameterBufferROI.
1421          *
1422          * \ref roi_value depends on \c roi_value_is_qp_delta in #VAEncMiscParameterBufferROI when
1423          * VAConfigAttribRateControl != VA_RC_CQP. \ref roi_value specifies ROI_delta QP if \c roi_value_is_qp_delta
1424          * in VAEncMiscParameterBufferROI is 1, otherwise \ref roi_value specifies ROI priority.
1425          */
1426         char            roi_value;
1427 } VAEncROI;
1428
1429 typedef struct _VAEncMiscParameterBufferROI {
1430     /** \brief Number of ROIs being sent.*/
1431     unsigned int        num_roi;
1432
1433     /** \brief Valid when VAConfigAttribRateControl != VA_RC_CQP, then the encoder's
1434      *  rate control will determine actual delta QPs.  Specifies the max/min allowed delta
1435      *  QPs. */
1436     char                max_delta_qp;
1437     char                min_delta_qp;
1438
1439    /** \brief Pointer to a VAEncROI array with num_roi elements.  It is relative to frame
1440      *  coordinates for the frame case and to field coordinates for the field case.*/
1441     VAEncROI            *roi;
1442     union {
1443         struct {
1444             /**
1445              * \brief An indication for roi value.
1446              *
1447              * \ref roi_value_is_qp_delta equal to 1 indicates \c roi_value in #VAEncROI should
1448              * be used as ROI delta QP. \ref roi_value_is_qp_delta equal to 0 indicates \c roi_value
1449              * in #VAEncROI should be used as ROI priority.
1450              *
1451              * \ref roi_value_is_qp_delta is only available when VAConfigAttribRateControl != VA_RC_CQP,
1452              * the setting must comply with \c roi_rc_priority_support and \c roi_rc_qp_delat_support in
1453              * #VAConfigAttribValEncROI. The underlying driver should ignore this field
1454              * when VAConfigAttribRateControl == VA_RC_CQP.
1455              */
1456             uint32_t  roi_value_is_qp_delta    : 1;
1457             uint32_t  reserved                 : 31;
1458         } bits;
1459         uint32_t value;
1460     } roi_flags;
1461 } VAEncMiscParameterBufferROI;
1462
1463 /**
1464  * There will be cases where the bitstream buffer will not have enough room to hold
1465  * the data for the entire slice, and the following flags will be used in the slice
1466  * parameter to signal to the server for the possible cases.
1467  * If a slice parameter buffer and slice data buffer pair is sent to the server with 
1468  * the slice data partially in the slice data buffer (BEGIN and MIDDLE cases below), 
1469  * then a slice parameter and data buffer needs to be sent again to complete this slice. 
1470  */
1471 #define VA_SLICE_DATA_FLAG_ALL          0x00    /* whole slice is in the buffer */
1472 #define VA_SLICE_DATA_FLAG_BEGIN        0x01    /* The beginning of the slice is in the buffer but the end if not */
1473 #define VA_SLICE_DATA_FLAG_MIDDLE       0x02    /* Neither beginning nor end of the slice is in the buffer */
1474 #define VA_SLICE_DATA_FLAG_END          0x04    /* end of the slice is in the buffer */
1475
1476 /* Codec-independent Slice Parameter Buffer base */
1477 typedef struct _VASliceParameterBufferBase
1478 {
1479     unsigned int slice_data_size;       /* number of bytes in the slice data buffer for this slice */
1480     unsigned int slice_data_offset;     /* the offset to the first byte of slice data */
1481     unsigned int slice_data_flag;       /* see VA_SLICE_DATA_FLAG_XXX definitions */
1482 } VASliceParameterBufferBase;
1483
1484 /**********************************
1485  * JPEG common  data structures
1486  **********************************/
1487 /**
1488  * \brief Huffman table for JPEG decoding.
1489  *
1490  * This structure holds the complete Huffman tables. This is an
1491  * aggregation of all Huffman table (DHT) segments maintained by the
1492  * application. i.e. up to 2 Huffman tables are stored in there for
1493  * baseline profile.
1494  *
1495  * The #load_huffman_table array can be used as a hint to notify the
1496  * VA driver implementation about which table(s) actually changed
1497  * since the last submission of this buffer.
1498  */
1499 typedef struct _VAHuffmanTableBufferJPEGBaseline {
1500     /** \brief Specifies which #huffman_table is valid. */
1501     unsigned char       load_huffman_table[2];
1502     /** \brief Huffman tables indexed by table identifier (Th). */
1503     struct {
1504         /** @name DC table (up to 12 categories) */
1505         /**@{*/
1506         /** \brief Number of Huffman codes of length i + 1 (Li). */
1507         unsigned char   num_dc_codes[16];
1508         /** \brief Value associated with each Huffman code (Vij). */
1509         unsigned char   dc_values[12];
1510         /**@}*/
1511         /** @name AC table (2 special codes + up to 16 * 10 codes) */
1512         /**@{*/
1513         /** \brief Number of Huffman codes of length i + 1 (Li). */
1514         unsigned char   num_ac_codes[16];
1515         /** \brief Value associated with each Huffman code (Vij). */
1516         unsigned char   ac_values[162];
1517         /** \brief Padding to 4-byte boundaries. Must be set to zero. */
1518         unsigned char   pad[2];
1519         /**@}*/
1520     }                   huffman_table[2];
1521 } VAHuffmanTableBufferJPEGBaseline;
1522
1523 /****************************
1524  * MPEG-2 data structures
1525  ****************************/
1526  
1527 /* MPEG-2 Picture Parameter Buffer */
1528 /* 
1529  * For each frame or field, and before any slice data, a single
1530  * picture parameter buffer must be send.
1531  */
1532 typedef struct _VAPictureParameterBufferMPEG2
1533 {
1534     unsigned short horizontal_size;
1535     unsigned short vertical_size;
1536     VASurfaceID forward_reference_picture;
1537     VASurfaceID backward_reference_picture;
1538     /* meanings of the following fields are the same as in the standard */
1539     int picture_coding_type;
1540     int f_code; /* pack all four fcode into this */
1541     union {
1542         struct {
1543             unsigned int intra_dc_precision             : 2; 
1544             unsigned int picture_structure              : 2; 
1545             unsigned int top_field_first                : 1; 
1546             unsigned int frame_pred_frame_dct           : 1; 
1547             unsigned int concealment_motion_vectors     : 1;
1548             unsigned int q_scale_type                   : 1;
1549             unsigned int intra_vlc_format               : 1;
1550             unsigned int alternate_scan                 : 1;
1551             unsigned int repeat_first_field             : 1;
1552             unsigned int progressive_frame              : 1;
1553             unsigned int is_first_field                 : 1; /* indicate whether the current field
1554                                                               * is the first field for field picture
1555                                                               */
1556         } bits;
1557         unsigned int value;
1558     } picture_coding_extension;
1559 } VAPictureParameterBufferMPEG2;
1560
1561 /** MPEG-2 Inverse Quantization Matrix Buffer */
1562 typedef struct _VAIQMatrixBufferMPEG2
1563 {
1564     /** \brief Same as the MPEG-2 bitstream syntax element. */
1565     int load_intra_quantiser_matrix;
1566     /** \brief Same as the MPEG-2 bitstream syntax element. */
1567     int load_non_intra_quantiser_matrix;
1568     /** \brief Same as the MPEG-2 bitstream syntax element. */
1569     int load_chroma_intra_quantiser_matrix;
1570     /** \brief Same as the MPEG-2 bitstream syntax element. */
1571     int load_chroma_non_intra_quantiser_matrix;
1572     /** \brief Luminance intra matrix, in zig-zag scan order. */
1573     unsigned char intra_quantiser_matrix[64];
1574     /** \brief Luminance non-intra matrix, in zig-zag scan order. */
1575     unsigned char non_intra_quantiser_matrix[64];
1576     /** \brief Chroma intra matrix, in zig-zag scan order. */
1577     unsigned char chroma_intra_quantiser_matrix[64];
1578     /** \brief Chroma non-intra matrix, in zig-zag scan order. */
1579     unsigned char chroma_non_intra_quantiser_matrix[64];
1580 } VAIQMatrixBufferMPEG2;
1581
1582 /** MPEG-2 Slice Parameter Buffer */
1583 typedef struct _VASliceParameterBufferMPEG2
1584 {
1585     unsigned int slice_data_size;/* number of bytes in the slice data buffer for this slice */
1586     unsigned int slice_data_offset;/* the offset to the first byte of slice data */
1587     unsigned int slice_data_flag; /* see VA_SLICE_DATA_FLAG_XXX defintions */
1588     unsigned int macroblock_offset;/* the offset to the first bit of MB from the first byte of slice data */
1589     unsigned int slice_horizontal_position;
1590     unsigned int slice_vertical_position;
1591     int quantiser_scale_code;
1592     int intra_slice_flag;
1593 } VASliceParameterBufferMPEG2;
1594
1595 /** MPEG-2 Macroblock Parameter Buffer */
1596 typedef struct _VAMacroblockParameterBufferMPEG2
1597 {
1598     unsigned short macroblock_address;
1599     /* 
1600      * macroblock_address (in raster scan order)
1601      * top-left: 0
1602      * bottom-right: picture-height-in-mb*picture-width-in-mb - 1
1603      */
1604     unsigned char macroblock_type;  /* see definition below */
1605     union {
1606         struct {
1607             unsigned int frame_motion_type              : 2; 
1608             unsigned int field_motion_type              : 2; 
1609             unsigned int dct_type                       : 1; 
1610         } bits;
1611         unsigned int value;
1612     } macroblock_modes;
1613     unsigned char motion_vertical_field_select; 
1614     /* 
1615      * motion_vertical_field_select:
1616      * see section 6.3.17.2 in the spec
1617      * only the lower 4 bits are used
1618      * bit 0: first vector forward
1619      * bit 1: first vector backward
1620      * bit 2: second vector forward
1621      * bit 3: second vector backward
1622      */
1623     short PMV[2][2][2]; /* see Table 7-7 in the spec */
1624     unsigned short coded_block_pattern;
1625     /* 
1626      * The bitplanes for coded_block_pattern are described 
1627      * in Figure 6.10-12 in the spec
1628      */
1629      
1630     /* Number of skipped macroblocks after this macroblock */
1631     unsigned short num_skipped_macroblocks;
1632 } VAMacroblockParameterBufferMPEG2;
1633
1634 /* 
1635  * OR'd flags for macroblock_type (section 6.3.17.1 in the spec)
1636  */
1637 #define VA_MB_TYPE_MOTION_FORWARD       0x02
1638 #define VA_MB_TYPE_MOTION_BACKWARD      0x04
1639 #define VA_MB_TYPE_MOTION_PATTERN       0x08
1640 #define VA_MB_TYPE_MOTION_INTRA         0x10
1641
1642 /**
1643  * MPEG-2 Residual Data Buffer 
1644  * For each macroblock, there wil be 64 shorts (16-bit) in the 
1645  * residual data buffer
1646  */
1647
1648 /****************************
1649  * MPEG-4 Part 2 data structures
1650  ****************************/
1651  
1652 /* MPEG-4 Picture Parameter Buffer */
1653 /* 
1654  * For each frame or field, and before any slice data, a single
1655  * picture parameter buffer must be send.
1656  */
1657 typedef struct _VAPictureParameterBufferMPEG4
1658 {
1659     unsigned short vop_width;
1660     unsigned short vop_height;
1661     VASurfaceID forward_reference_picture;
1662     VASurfaceID backward_reference_picture;
1663     union {
1664         struct {
1665             unsigned int short_video_header             : 1; 
1666             unsigned int chroma_format                  : 2; 
1667             unsigned int interlaced                     : 1; 
1668             unsigned int obmc_disable                   : 1; 
1669             unsigned int sprite_enable                  : 2; 
1670             unsigned int sprite_warping_accuracy        : 2; 
1671             unsigned int quant_type                     : 1; 
1672             unsigned int quarter_sample                 : 1; 
1673             unsigned int data_partitioned               : 1; 
1674             unsigned int reversible_vlc                 : 1; 
1675             unsigned int resync_marker_disable          : 1; 
1676         } bits;
1677         unsigned int value;
1678     } vol_fields;
1679     unsigned char no_of_sprite_warping_points;
1680     short sprite_trajectory_du[3];
1681     short sprite_trajectory_dv[3];
1682     unsigned char quant_precision;
1683     union {
1684         struct {
1685             unsigned int vop_coding_type                : 2; 
1686             unsigned int backward_reference_vop_coding_type     : 2; 
1687             unsigned int vop_rounding_type              : 1; 
1688             unsigned int intra_dc_vlc_thr               : 3; 
1689             unsigned int top_field_first                : 1; 
1690             unsigned int alternate_vertical_scan_flag   : 1; 
1691         } bits;
1692         unsigned int value;
1693     } vop_fields;
1694     unsigned char vop_fcode_forward;
1695     unsigned char vop_fcode_backward;
1696     unsigned short vop_time_increment_resolution;
1697     /* short header related */
1698     unsigned char num_gobs_in_vop;
1699     unsigned char num_macroblocks_in_gob;
1700     /* for direct mode prediction */
1701     short TRB;
1702     short TRD;
1703 } VAPictureParameterBufferMPEG4;
1704
1705 /** MPEG-4 Inverse Quantization Matrix Buffer */
1706 typedef struct _VAIQMatrixBufferMPEG4
1707 {
1708     /** Same as the MPEG-4:2 bitstream syntax element. */
1709     int load_intra_quant_mat;
1710     /** Same as the MPEG-4:2 bitstream syntax element. */
1711     int load_non_intra_quant_mat;
1712     /** The matrix for intra blocks, in zig-zag scan order. */
1713     unsigned char intra_quant_mat[64];
1714     /** The matrix for non-intra blocks, in zig-zag scan order. */
1715     unsigned char non_intra_quant_mat[64];
1716 } VAIQMatrixBufferMPEG4;
1717
1718 /** MPEG-4 Slice Parameter Buffer */
1719 typedef struct _VASliceParameterBufferMPEG4
1720 {
1721     unsigned int slice_data_size;/* number of bytes in the slice data buffer for this slice */
1722     unsigned int slice_data_offset;/* the offset to the first byte of slice data */
1723     unsigned int slice_data_flag; /* see VA_SLICE_DATA_FLAG_XXX defintions */
1724     unsigned int macroblock_offset;/* the offset to the first bit of MB from the first byte of slice data */
1725     unsigned int macroblock_number;
1726     int quant_scale;
1727 } VASliceParameterBufferMPEG4;
1728
1729 /**
1730  VC-1 data structures
1731 */
1732
1733 typedef enum   /* see 7.1.1.32 */
1734 {
1735     VAMvMode1Mv                        = 0,
1736     VAMvMode1MvHalfPel                 = 1,
1737     VAMvMode1MvHalfPelBilinear         = 2,
1738     VAMvModeMixedMv                    = 3,
1739     VAMvModeIntensityCompensation      = 4 
1740 } VAMvModeVC1;
1741
1742 /** VC-1 Picture Parameter Buffer */
1743 /* 
1744  * For each picture, and before any slice data, a picture parameter
1745  * buffer must be send. Multiple picture parameter buffers may be
1746  * sent for a single picture. In that case picture parameters will
1747  * apply to all slice data that follow it until a new picture
1748  * parameter buffer is sent.
1749  *
1750  * Notes:
1751  *   pic_quantizer_type should be set to the applicable quantizer
1752  *   type as defined by QUANTIZER (J.1.19) and either
1753  *   PQUANTIZER (7.1.1.8) or PQINDEX (7.1.1.6)
1754  */
1755 typedef struct _VAPictureParameterBufferVC1
1756 {
1757     VASurfaceID forward_reference_picture;
1758     VASurfaceID backward_reference_picture;
1759     /* if out-of-loop post-processing is done on the render
1760        target, then we need to keep the in-loop decoded 
1761        picture as a reference picture */
1762     VASurfaceID inloop_decoded_picture;
1763
1764     /* sequence layer for AP or meta data for SP and MP */
1765     union {
1766         struct {
1767             unsigned int pulldown       : 1; /* SEQUENCE_LAYER::PULLDOWN */
1768             unsigned int interlace      : 1; /* SEQUENCE_LAYER::INTERLACE */
1769             unsigned int tfcntrflag     : 1; /* SEQUENCE_LAYER::TFCNTRFLAG */
1770             unsigned int finterpflag    : 1; /* SEQUENCE_LAYER::FINTERPFLAG */
1771             unsigned int psf            : 1; /* SEQUENCE_LAYER::PSF */
1772             unsigned int multires       : 1; /* METADATA::MULTIRES */
1773             unsigned int overlap        : 1; /* METADATA::OVERLAP */
1774             unsigned int syncmarker     : 1; /* METADATA::SYNCMARKER */
1775             unsigned int rangered       : 1; /* METADATA::RANGERED */
1776             unsigned int max_b_frames   : 3; /* METADATA::MAXBFRAMES */
1777             unsigned int profile        : 2; /* SEQUENCE_LAYER::PROFILE or The MSB of METADATA::PROFILE */
1778         } bits;
1779         unsigned int value;
1780     } sequence_fields;
1781
1782     unsigned short coded_width;         /* ENTRY_POINT_LAYER::CODED_WIDTH */
1783     unsigned short coded_height;        /* ENTRY_POINT_LAYER::CODED_HEIGHT */
1784     union {
1785         struct {
1786             unsigned int broken_link    : 1; /* ENTRY_POINT_LAYER::BROKEN_LINK */
1787             unsigned int closed_entry   : 1; /* ENTRY_POINT_LAYER::CLOSED_ENTRY */
1788             unsigned int panscan_flag   : 1; /* ENTRY_POINT_LAYER::PANSCAN_FLAG */
1789             unsigned int loopfilter     : 1; /* ENTRY_POINT_LAYER::LOOPFILTER */
1790         } bits;
1791         unsigned int value;
1792     } entrypoint_fields;
1793     unsigned char conditional_overlap_flag; /* ENTRY_POINT_LAYER::CONDOVER */
1794     unsigned char fast_uvmc_flag;       /* ENTRY_POINT_LAYER::FASTUVMC */
1795     union {
1796         struct {
1797             unsigned int luma_flag      : 1; /* ENTRY_POINT_LAYER::RANGE_MAPY_FLAG */
1798             unsigned int luma           : 3; /* ENTRY_POINT_LAYER::RANGE_MAPY */
1799             unsigned int chroma_flag    : 1; /* ENTRY_POINT_LAYER::RANGE_MAPUV_FLAG */
1800             unsigned int chroma         : 3; /* ENTRY_POINT_LAYER::RANGE_MAPUV */
1801         } bits;
1802         unsigned int value;
1803     } range_mapping_fields;
1804
1805     unsigned char b_picture_fraction;   /* PICTURE_LAYER::BFRACTION */
1806     unsigned char cbp_table;            /* PICTURE_LAYER::CBPTAB/ICBPTAB */
1807     unsigned char mb_mode_table;        /* PICTURE_LAYER::MBMODETAB */
1808     unsigned char range_reduction_frame;/* PICTURE_LAYER::RANGEREDFRM */
1809     unsigned char rounding_control;     /* PICTURE_LAYER::RNDCTRL */
1810     unsigned char post_processing;      /* PICTURE_LAYER::POSTPROC */
1811     unsigned char picture_resolution_index;     /* PICTURE_LAYER::RESPIC */
1812     unsigned char luma_scale;           /* PICTURE_LAYER::LUMSCALE */
1813     unsigned char luma_shift;           /* PICTURE_LAYER::LUMSHIFT */
1814     union {
1815         struct {
1816             unsigned int picture_type           : 3; /* PICTURE_LAYER::PTYPE */
1817             unsigned int frame_coding_mode      : 3; /* PICTURE_LAYER::FCM */
1818             unsigned int top_field_first        : 1; /* PICTURE_LAYER::TFF */
1819             unsigned int is_first_field         : 1; /* set to 1 if it is the first field */
1820             unsigned int intensity_compensation : 1; /* PICTURE_LAYER::INTCOMP */
1821         } bits;
1822         unsigned int value;
1823     } picture_fields;
1824     union {
1825         struct {
1826             unsigned int mv_type_mb     : 1;    /* PICTURE::MVTYPEMB */
1827             unsigned int direct_mb      : 1;    /* PICTURE::DIRECTMB */
1828             unsigned int skip_mb        : 1;    /* PICTURE::SKIPMB */
1829             unsigned int field_tx       : 1;    /* PICTURE::FIELDTX */
1830             unsigned int forward_mb     : 1;    /* PICTURE::FORWARDMB */
1831             unsigned int ac_pred        : 1;    /* PICTURE::ACPRED */
1832             unsigned int overflags      : 1;    /* PICTURE::OVERFLAGS */
1833         } flags;
1834         unsigned int value;
1835     } raw_coding;
1836     union {
1837         struct {
1838             unsigned int bp_mv_type_mb   : 1;    /* PICTURE::MVTYPEMB */
1839             unsigned int bp_direct_mb    : 1;    /* PICTURE::DIRECTMB */
1840             unsigned int bp_skip_mb      : 1;    /* PICTURE::SKIPMB */  
1841             unsigned int bp_field_tx     : 1;    /* PICTURE::FIELDTX */ 
1842             unsigned int bp_forward_mb   : 1;    /* PICTURE::FORWARDMB */
1843             unsigned int bp_ac_pred      : 1;    /* PICTURE::ACPRED */   
1844             unsigned int bp_overflags    : 1;    /* PICTURE::OVERFLAGS */
1845         } flags;
1846         unsigned int value;
1847     } bitplane_present; /* signal what bitplane is being passed via the bitplane buffer */
1848     union {
1849         struct {
1850             unsigned int reference_distance_flag : 1;/* PICTURE_LAYER::REFDIST_FLAG */
1851             unsigned int reference_distance     : 5;/* PICTURE_LAYER::REFDIST */
1852             unsigned int num_reference_pictures: 1;/* PICTURE_LAYER::NUMREF */
1853             unsigned int reference_field_pic_indicator  : 1;/* PICTURE_LAYER::REFFIELD */
1854         } bits;
1855         unsigned int value;
1856     } reference_fields;
1857     union {
1858         struct {
1859             unsigned int mv_mode                : 3; /* PICTURE_LAYER::MVMODE */
1860             unsigned int mv_mode2               : 3; /* PICTURE_LAYER::MVMODE2 */
1861             unsigned int mv_table               : 3; /* PICTURE_LAYER::MVTAB/IMVTAB */
1862             unsigned int two_mv_block_pattern_table: 2; /* PICTURE_LAYER::2MVBPTAB */
1863             unsigned int four_mv_switch         : 1; /* PICTURE_LAYER::4MVSWITCH */
1864             unsigned int four_mv_block_pattern_table : 2; /* PICTURE_LAYER::4MVBPTAB */
1865             unsigned int extended_mv_flag       : 1; /* ENTRY_POINT_LAYER::EXTENDED_MV */
1866             unsigned int extended_mv_range      : 2; /* PICTURE_LAYER::MVRANGE */
1867             unsigned int extended_dmv_flag      : 1; /* ENTRY_POINT_LAYER::EXTENDED_DMV */
1868             unsigned int extended_dmv_range     : 2; /* PICTURE_LAYER::DMVRANGE */
1869         } bits;
1870         unsigned int value;
1871     } mv_fields;
1872     union {
1873         struct {
1874             unsigned int dquant : 2;    /* ENTRY_POINT_LAYER::DQUANT */
1875             unsigned int quantizer     : 2;     /* ENTRY_POINT_LAYER::QUANTIZER */
1876             unsigned int half_qp        : 1;    /* PICTURE_LAYER::HALFQP */
1877             unsigned int pic_quantizer_scale : 5;/* PICTURE_LAYER::PQUANT */
1878             unsigned int pic_quantizer_type : 1;/* PICTURE_LAYER::PQUANTIZER */
1879             unsigned int dq_frame       : 1;    /* VOPDQUANT::DQUANTFRM */
1880             unsigned int dq_profile     : 2;    /* VOPDQUANT::DQPROFILE */
1881             unsigned int dq_sb_edge     : 2;    /* VOPDQUANT::DQSBEDGE */
1882             unsigned int dq_db_edge     : 2;    /* VOPDQUANT::DQDBEDGE */
1883             unsigned int dq_binary_level : 1;   /* VOPDQUANT::DQBILEVEL */
1884             unsigned int alt_pic_quantizer : 5;/* VOPDQUANT::ALTPQUANT */
1885         } bits;
1886         unsigned int value;
1887     } pic_quantizer_fields;
1888     union {
1889         struct {
1890             unsigned int variable_sized_transform_flag  : 1;/* ENTRY_POINT_LAYER::VSTRANSFORM */
1891             unsigned int mb_level_transform_type_flag   : 1;/* PICTURE_LAYER::TTMBF */
1892             unsigned int frame_level_transform_type     : 2;/* PICTURE_LAYER::TTFRM */
1893             unsigned int transform_ac_codingset_idx1    : 2;/* PICTURE_LAYER::TRANSACFRM */
1894             unsigned int transform_ac_codingset_idx2    : 2;/* PICTURE_LAYER::TRANSACFRM2 */
1895             unsigned int intra_transform_dc_table       : 1;/* PICTURE_LAYER::TRANSDCTAB */
1896         } bits;
1897         unsigned int value;
1898     } transform_fields;
1899 } VAPictureParameterBufferVC1;
1900
1901 /** VC-1 Bitplane Buffer
1902 There will be at most three bitplanes coded in any picture header. To send 
1903 the bitplane data more efficiently, each byte is divided in two nibbles, with
1904 each nibble carrying three bitplanes for one macroblock.  The following table
1905 shows the bitplane data arrangement within each nibble based on the picture
1906 type.
1907
1908 Picture Type    Bit3            Bit2            Bit1            Bit0
1909 I or BI                         OVERFLAGS       ACPRED          FIELDTX
1910 P                               MYTYPEMB        SKIPMB          DIRECTMB
1911 B                               FORWARDMB       SKIPMB          DIRECTMB
1912
1913 Within each byte, the lower nibble is for the first MB and the upper nibble is 
1914 for the second MB.  E.g. the lower nibble of the first byte in the bitplane
1915 buffer is for Macroblock #1 and the upper nibble of the first byte is for 
1916 Macroblock #2 in the first row.
1917 */
1918
1919 /* VC-1 Slice Parameter Buffer */
1920 typedef struct _VASliceParameterBufferVC1
1921 {
1922     unsigned int slice_data_size;/* number of bytes in the slice data buffer for this slice */
1923     unsigned int slice_data_offset;/* the offset to the first byte of slice data */
1924     unsigned int slice_data_flag; /* see VA_SLICE_DATA_FLAG_XXX defintions */
1925     unsigned int macroblock_offset;/* the offset to the first bit of MB from the first byte of slice data */
1926     unsigned int slice_vertical_position;
1927 } VASliceParameterBufferVC1;
1928
1929 /* VC-1 Slice Data Buffer */
1930 /* 
1931 This is simplely a buffer containing raw bit-stream bytes 
1932 */
1933
1934 /****************************
1935  * H.264/AVC data structures
1936  ****************************/
1937
1938 typedef struct _VAPictureH264
1939 {
1940     VASurfaceID picture_id;
1941     unsigned int frame_idx;
1942     unsigned int flags;
1943     signed int TopFieldOrderCnt;
1944     signed int BottomFieldOrderCnt;
1945 } VAPictureH264;
1946 /* flags in VAPictureH264 could be OR of the following */
1947 #define VA_PICTURE_H264_INVALID                 0x00000001
1948 #define VA_PICTURE_H264_TOP_FIELD               0x00000002
1949 #define VA_PICTURE_H264_BOTTOM_FIELD            0x00000004
1950 #define VA_PICTURE_H264_SHORT_TERM_REFERENCE    0x00000008
1951 #define VA_PICTURE_H264_LONG_TERM_REFERENCE     0x00000010
1952
1953 /** H.264 Picture Parameter Buffer */
1954 /* 
1955  * For each picture, and before any slice data, a single
1956  * picture parameter buffer must be send.
1957  */
1958 typedef struct _VAPictureParameterBufferH264
1959 {
1960     VAPictureH264 CurrPic;
1961     VAPictureH264 ReferenceFrames[16];  /* in DPB */
1962     unsigned short picture_width_in_mbs_minus1;
1963     unsigned short picture_height_in_mbs_minus1;
1964     unsigned char bit_depth_luma_minus8;
1965     unsigned char bit_depth_chroma_minus8;
1966     unsigned char num_ref_frames;
1967     union {
1968         struct {
1969             unsigned int chroma_format_idc                      : 2; 
1970             unsigned int residual_colour_transform_flag         : 1; 
1971             unsigned int gaps_in_frame_num_value_allowed_flag   : 1; 
1972             unsigned int frame_mbs_only_flag                    : 1; 
1973             unsigned int mb_adaptive_frame_field_flag           : 1; 
1974             unsigned int direct_8x8_inference_flag              : 1; 
1975             unsigned int MinLumaBiPredSize8x8                   : 1; /* see A.3.3.2 */
1976             unsigned int log2_max_frame_num_minus4              : 4;
1977             unsigned int pic_order_cnt_type                     : 2;
1978             unsigned int log2_max_pic_order_cnt_lsb_minus4      : 4;
1979             unsigned int delta_pic_order_always_zero_flag       : 1;
1980         } bits;
1981         unsigned int value;
1982     } seq_fields;
1983     unsigned char num_slice_groups_minus1;
1984     unsigned char slice_group_map_type;
1985     unsigned short slice_group_change_rate_minus1;
1986     signed char pic_init_qp_minus26;
1987     signed char pic_init_qs_minus26;
1988     signed char chroma_qp_index_offset;
1989     signed char second_chroma_qp_index_offset;
1990     union {
1991         struct {
1992             unsigned int entropy_coding_mode_flag       : 1;
1993             unsigned int weighted_pred_flag             : 1;
1994             unsigned int weighted_bipred_idc            : 2;
1995             unsigned int transform_8x8_mode_flag        : 1;
1996             unsigned int field_pic_flag                 : 1;
1997             unsigned int constrained_intra_pred_flag    : 1;
1998             unsigned int pic_order_present_flag                 : 1;
1999             unsigned int deblocking_filter_control_present_flag : 1;
2000             unsigned int redundant_pic_cnt_present_flag         : 1;
2001             unsigned int reference_pic_flag                     : 1; /* nal_ref_idc != 0 */
2002         } bits;
2003         unsigned int value;
2004     } pic_fields;
2005     unsigned short frame_num;
2006 } VAPictureParameterBufferH264;
2007
2008 /** H.264 Inverse Quantization Matrix Buffer */
2009 typedef struct _VAIQMatrixBufferH264
2010 {
2011     /** \brief 4x4 scaling list, in raster scan order. */
2012     unsigned char ScalingList4x4[6][16];
2013     /** \brief 8x8 scaling list, in raster scan order. */
2014     unsigned char ScalingList8x8[2][64];
2015 } VAIQMatrixBufferH264;
2016
2017 /**
2018  * H.264 Slice Group Map Buffer 
2019  * When VAPictureParameterBufferH264::num_slice_group_minus1 is not equal to 0,
2020  * A slice group map buffer should be sent for each picture if required. The buffer
2021  * is sent only when there is a change in the mapping values.
2022  * The slice group map buffer map "map units" to slice groups as specified in 
2023  * section 8.2.2 of the H.264 spec. The buffer will contain one byte for each macroblock 
2024  * in raster scan order
2025  */ 
2026
2027 /** H.264 Slice Parameter Buffer */
2028 typedef struct _VASliceParameterBufferH264
2029 {
2030     unsigned int slice_data_size;/* number of bytes in the slice data buffer for this slice */
2031     /** \brief Byte offset to the NAL Header Unit for this slice. */
2032     unsigned int slice_data_offset;
2033     unsigned int slice_data_flag; /* see VA_SLICE_DATA_FLAG_XXX defintions */
2034     /**
2035      * \brief Bit offset from NAL Header Unit to the begining of slice_data().
2036      *
2037      * This bit offset is relative to and includes the NAL unit byte
2038      * and represents the number of bits parsed in the slice_header()
2039      * after the removal of any emulation prevention bytes in
2040      * there. However, the slice data buffer passed to the hardware is
2041      * the original bitstream, thus including any emulation prevention
2042      * bytes.
2043      */
2044     unsigned short slice_data_bit_offset;
2045     unsigned short first_mb_in_slice;
2046     unsigned char slice_type;
2047     unsigned char direct_spatial_mv_pred_flag;
2048     unsigned char num_ref_idx_l0_active_minus1;
2049     unsigned char num_ref_idx_l1_active_minus1;
2050     unsigned char cabac_init_idc;
2051     char slice_qp_delta;
2052     unsigned char disable_deblocking_filter_idc;
2053     char slice_alpha_c0_offset_div2;
2054     char slice_beta_offset_div2;
2055     VAPictureH264 RefPicList0[32];      /* See 8.2.4.2 */
2056     VAPictureH264 RefPicList1[32];      /* See 8.2.4.2 */
2057     unsigned char luma_log2_weight_denom;
2058     unsigned char chroma_log2_weight_denom;
2059     unsigned char luma_weight_l0_flag;
2060     short luma_weight_l0[32];
2061     short luma_offset_l0[32];
2062     unsigned char chroma_weight_l0_flag;
2063     short chroma_weight_l0[32][2];
2064     short chroma_offset_l0[32][2];
2065     unsigned char luma_weight_l1_flag;
2066     short luma_weight_l1[32];
2067     short luma_offset_l1[32];
2068     unsigned char chroma_weight_l1_flag;
2069     short chroma_weight_l1[32][2];
2070     short chroma_offset_l1[32][2];
2071 } VASliceParameterBufferH264;
2072
2073 /****************************
2074  * Common encode data structures 
2075  ****************************/
2076 typedef enum
2077 {
2078     VAEncPictureTypeIntra               = 0,
2079     VAEncPictureTypePredictive          = 1,
2080     VAEncPictureTypeBidirectional       = 2,
2081 } VAEncPictureType;
2082
2083 /* Encode Slice Parameter Buffer */
2084 typedef struct _VAEncSliceParameterBuffer
2085 {
2086     unsigned int start_row_number;      /* starting MB row number for this slice */
2087     unsigned int slice_height;  /* slice height measured in MB */
2088     union {
2089         struct {
2090             unsigned int is_intra       : 1;
2091             unsigned int disable_deblocking_filter_idc : 2;
2092             unsigned int uses_long_term_ref             :1;
2093             unsigned int is_long_term_ref               :1;
2094         } bits;
2095         unsigned int value;
2096     } slice_flags;
2097 } VAEncSliceParameterBuffer;
2098
2099
2100 /****************************
2101  * H.263 specific encode data structures
2102  ****************************/
2103
2104 typedef struct _VAEncSequenceParameterBufferH263
2105 {
2106     unsigned int intra_period;
2107     unsigned int bits_per_second;
2108     unsigned int frame_rate;
2109     unsigned int initial_qp;
2110     unsigned int min_qp;
2111 } VAEncSequenceParameterBufferH263;
2112
2113 typedef struct _VAEncPictureParameterBufferH263
2114 {
2115     VASurfaceID reference_picture;
2116     VASurfaceID reconstructed_picture;
2117     VABufferID coded_buf;
2118     unsigned short picture_width;
2119     unsigned short picture_height;
2120     VAEncPictureType picture_type;
2121 } VAEncPictureParameterBufferH263;
2122
2123 /****************************
2124  * MPEG-4 specific encode data structures
2125  ****************************/
2126
2127 typedef struct _VAEncSequenceParameterBufferMPEG4
2128 {
2129     unsigned char profile_and_level_indication;
2130     unsigned int intra_period;
2131     unsigned int video_object_layer_width;
2132     unsigned int video_object_layer_height;
2133     unsigned int vop_time_increment_resolution;
2134     unsigned int fixed_vop_rate;
2135     unsigned int fixed_vop_time_increment;
2136     unsigned int bits_per_second;
2137     unsigned int frame_rate;
2138     unsigned int initial_qp;
2139     unsigned int min_qp;
2140 } VAEncSequenceParameterBufferMPEG4;
2141
2142 typedef struct _VAEncPictureParameterBufferMPEG4
2143 {
2144     VASurfaceID reference_picture;
2145     VASurfaceID reconstructed_picture;
2146     VABufferID coded_buf;
2147     unsigned short picture_width;
2148     unsigned short picture_height;
2149     unsigned int modulo_time_base; /* number of 1s */
2150     unsigned int vop_time_increment;
2151     VAEncPictureType picture_type;
2152 } VAEncPictureParameterBufferMPEG4;
2153
2154
2155
2156 /** Buffer functions */
2157
2158 /**
2159  * Creates a buffer for "num_elements" elements of "size" bytes and 
2160  * initalize with "data".
2161  * if "data" is null, then the contents of the buffer data store
2162  * are undefined.
2163  * Basically there are two ways to get buffer data to the server side. One is 
2164  * to call vaCreateBuffer() with a non-null "data", which results the data being
2165  * copied to the data store on the server side.  A different method that 
2166  * eliminates this copy is to pass null as "data" when calling vaCreateBuffer(),
2167  * and then use vaMapBuffer() to map the data store from the server side to the
2168  * client address space for access.
2169  * The user must call vaDestroyBuffer() to destroy a buffer.
2170  *  Note: image buffers are created by the library, not the client. Please see 
2171  *        vaCreateImage on how image buffers are managed.
2172  */
2173 VAStatus vaCreateBuffer (
2174     VADisplay dpy,
2175     VAContextID context,
2176     VABufferType type,  /* in */
2177     unsigned int size,  /* in */
2178     unsigned int num_elements, /* in */
2179     void *data,         /* in */
2180     VABufferID *buf_id  /* out */
2181 );
2182
2183 /**
2184  * Convey to the server how many valid elements are in the buffer. 
2185  * e.g. if multiple slice parameters are being held in a single buffer,
2186  * this will communicate to the server the number of slice parameters
2187  * that are valid in the buffer.
2188  */
2189 VAStatus vaBufferSetNumElements (
2190     VADisplay dpy,
2191     VABufferID buf_id,  /* in */
2192     unsigned int num_elements /* in */
2193 );
2194
2195
2196 /**
2197  * device independent data structure for codedbuffer
2198  */
2199
2200 /* 
2201  * FICTURE_AVE_QP(bit7-0): The average Qp value used during this frame
2202  * LARGE_SLICE(bit8):At least one slice in the current frame was large
2203  *              enough for the encoder to attempt to limit its size.
2204  * SLICE_OVERFLOW(bit9): At least one slice in the current frame has
2205  *              exceeded the maximum slice size specified.
2206  * BITRATE_OVERFLOW(bit10): The peak bitrate was exceeded for this frame.
2207  * BITRATE_HIGH(bit11): The frame size got within the safety margin of the maximum size (VCM only)
2208  * AIR_MB_OVER_THRESHOLD: the number of MBs adapted to Intra MB
2209  */
2210 #define VA_CODED_BUF_STATUS_PICTURE_AVE_QP_MASK         0xff
2211 #define VA_CODED_BUF_STATUS_LARGE_SLICE_MASK            0x100
2212 #define VA_CODED_BUF_STATUS_SLICE_OVERFLOW_MASK         0x200
2213 #define VA_CODED_BUF_STATUS_BITRATE_OVERFLOW            0x400
2214 #define VA_CODED_BUF_STATUS_BITRATE_HIGH                0x800
2215 /**
2216  * \brief The frame has exceeded the maximum requested size.
2217  *
2218  * This flag indicates that the encoded frame size exceeds the value
2219  * specified through a misc parameter buffer of type
2220  * #VAEncMiscParameterTypeMaxFrameSize.
2221  */
2222 #define VA_CODED_BUF_STATUS_FRAME_SIZE_OVERFLOW         0x1000
2223 #define VA_CODED_BUF_STATUS_AIR_MB_OVER_THRESHOLD       0xff0000
2224
2225 /**
2226  * \brief The coded buffer segment contains a single NAL unit. 
2227  *
2228  * This flag indicates that the coded buffer segment contains a
2229  * single NAL unit. This flag might be useful to the user for 
2230  * processing the coded buffer.
2231  */
2232 #define VA_CODED_BUF_STATUS_SINGLE_NALU                 0x10000000      
2233
2234 /**
2235  * \brief Coded buffer segment.
2236  *
2237  * #VACodedBufferSegment is an element of a linked list describing
2238  * some information on the coded buffer. The coded buffer segment
2239  * could contain either a single NAL unit, or more than one NAL unit. 
2240  * It is recommended (but not required) to return a single NAL unit 
2241  * in a coded buffer segment, and the implementation should set the 
2242  * VA_CODED_BUF_STATUS_SINGLE_NALU status flag if that is the case.
2243  */
2244 typedef  struct _VACodedBufferSegment  {
2245     /**
2246      * \brief Size of the data buffer in this segment (in bytes).
2247      */
2248     unsigned int        size;
2249     /** \brief Bit offset into the data buffer where the video data starts. */
2250     unsigned int        bit_offset;
2251     /** \brief Status set by the driver. See \c VA_CODED_BUF_STATUS_*. */
2252     unsigned int        status;
2253     /** \brief Reserved for future use. */
2254     unsigned int        reserved;
2255     /** \brief Pointer to the start of the data buffer. */
2256     void               *buf;
2257     /**
2258      * \brief Pointer to the next #VACodedBufferSegment element,
2259      * or \c NULL if there is none.
2260      */
2261     void               *next;
2262 } VACodedBufferSegment;
2263      
2264 /**
2265  * Map data store of the buffer into the client's address space
2266  * vaCreateBuffer() needs to be called with "data" set to NULL before
2267  * calling vaMapBuffer()
2268  *
2269  * if buffer type is VAEncCodedBufferType, pbuf points to link-list of
2270  * VACodedBufferSegment, and the list is terminated if "next" is NULL
2271  */
2272 VAStatus vaMapBuffer (
2273     VADisplay dpy,
2274     VABufferID buf_id,  /* in */
2275     void **pbuf         /* out */
2276 );
2277
2278 /**
2279  * After client making changes to a mapped data store, it needs to
2280  * "Unmap" it to let the server know that the data is ready to be
2281  * consumed by the server
2282  */
2283 VAStatus vaUnmapBuffer (
2284     VADisplay dpy,
2285     VABufferID buf_id   /* in */
2286 );
2287
2288 /**
2289  * After this call, the buffer is deleted and this buffer_id is no longer valid
2290  *
2291  * A buffer can be re-used and sent to the server by another Begin/Render/End
2292  * sequence if vaDestroyBuffer() is not called with this buffer.
2293  *
2294  * Note re-using a shared buffer (e.g. a slice data buffer) between the host and the
2295  * hardware accelerator can result in performance dropping.
2296  */
2297 VAStatus vaDestroyBuffer (
2298     VADisplay dpy,
2299     VABufferID buffer_id
2300 );
2301
2302 /** \brief VA buffer information */
2303 typedef struct {
2304     /** \brief Buffer handle */
2305     uintptr_t           handle;
2306     /** \brief Buffer type (See \ref VABufferType). */
2307     uint32_t            type;
2308     /**
2309      * \brief Buffer memory type (See \ref VASurfaceAttribMemoryType).
2310      *
2311      * On input to vaAcquireBufferHandle(), this field can serve as a hint
2312      * to specify the set of memory types the caller is interested in.
2313      * On successful return from vaAcquireBufferHandle(), the field is
2314      * updated with the best matching memory type.
2315      */
2316     uint32_t            mem_type;
2317     /** \brief Size of the underlying buffer. */
2318     size_t              mem_size;
2319 } VABufferInfo;
2320
2321 /**
2322  * \brief Acquires buffer handle for external API usage
2323  *
2324  * Locks the VA buffer object \ref buf_id for external API usage like
2325  * EGL or OpenCL (OCL). This function is a synchronization point. This
2326  * means that any pending operation is guaranteed to be completed
2327  * prior to returning from the function.
2328  *
2329  * If the referenced VA buffer object is the backing store of a VA
2330  * surface, then this function acts as if vaSyncSurface() on the
2331  * parent surface was called first.
2332  *
2333  * The \ref VABufferInfo argument shall be zero'ed on input. On
2334  * successful output, the data structure is filled in with all the
2335  * necessary buffer level implementation details like handle, type,
2336  * memory type and memory size.
2337  *
2338  * Note: the external API implementation, or the application, can
2339  * express the memory types it is interested in by filling in the \ref
2340  * mem_type field accordingly. On successful output, the memory type
2341  * that fits best the request and that was used is updated in the \ref
2342  * VABufferInfo data structure. If none of the supplied memory types
2343  * is supported, then a \ref VA_STATUS_ERROR_UNSUPPORTED_MEMORY_TYPE
2344  * error is returned.
2345  *
2346  * The \ref VABufferInfo data is valid until vaReleaseBufferHandle()
2347  * is called. Besides, no additional operation is allowed on any of
2348  * the buffer parent object until vaReleaseBufferHandle() is called.
2349  * e.g. decoding into a VA surface backed with the supplied VA buffer
2350  * object \ref buf_id would fail with a \ref VA_STATUS_ERROR_SURFACE_BUSY
2351  * error.
2352  *
2353  * Possible errors:
2354  * - \ref VA_STATUS_ERROR_UNIMPLEMENTED: the VA driver implementation
2355  *   does not support this interface
2356  * - \ref VA_STATUS_ERROR_INVALID_DISPLAY: an invalid display was supplied
2357  * - \ref VA_STATUS_ERROR_INVALID_BUFFER: an invalid buffer was supplied
2358  * - \ref VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE: the implementation
2359  *   does not support exporting buffers of the specified type
2360  * - \ref VA_STATUS_ERROR_UNSUPPORTED_MEMORY_TYPE: none of the requested
2361  *   memory types in \ref VABufferInfo.mem_type was supported
2362  *
2363  * @param[in] dpy               the VA display
2364  * @param[in] buf_id            the VA buffer
2365  * @param[in,out] buf_info      the associated VA buffer information
2366  * @return VA_STATUS_SUCCESS if successful
2367  */
2368 VAStatus
2369 vaAcquireBufferHandle(VADisplay dpy, VABufferID buf_id, VABufferInfo *buf_info);
2370
2371 /**
2372  * \brief Releases buffer after usage from external API
2373  *
2374  * Unlocks the VA buffer object \ref buf_id from external API usage like
2375  * EGL or OpenCL (OCL). This function is a synchronization point. This
2376  * means that any pending operation is guaranteed to be completed
2377  * prior to returning from the function.
2378  *
2379  * The \ref VABufferInfo argument shall point to the original data
2380  * structure that was obtained from vaAcquireBufferHandle(), unaltered.
2381  * This is necessary so that the VA driver implementation could
2382  * deallocate any resources that were needed.
2383  *
2384  * In any case, returning from this function invalidates any contents
2385  * in \ref VABufferInfo. i.e. the underlyng buffer handle is no longer
2386  * valid. Therefore, VA driver implementations are free to reset this
2387  * data structure to safe defaults.
2388  *
2389  * Possible errors:
2390  * - \ref VA_STATUS_ERROR_UNIMPLEMENTED: the VA driver implementation
2391  *   does not support this interface
2392  * - \ref VA_STATUS_ERROR_INVALID_DISPLAY: an invalid display was supplied
2393  * - \ref VA_STATUS_ERROR_INVALID_BUFFER: an invalid buffer was supplied
2394  * - \ref VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE: the implementation
2395  *   does not support exporting buffers of the specified type
2396  *
2397  * @param[in] dpy               the VA display
2398  * @param[in] buf_id            the VA buffer
2399  * @return VA_STATUS_SUCCESS if successful
2400  */
2401 VAStatus
2402 vaReleaseBufferHandle(VADisplay dpy, VABufferID buf_id);
2403
2404 /*
2405 Render (Decode) Pictures
2406
2407 A picture represents either a frame or a field.
2408
2409 The Begin/Render/End sequence sends the decode buffers to the server
2410 */
2411
2412 /**
2413  * Get ready to decode a picture to a target surface
2414  */
2415 VAStatus vaBeginPicture (
2416     VADisplay dpy,
2417     VAContextID context,
2418     VASurfaceID render_target
2419 );
2420
2421 /**
2422  * Send decode buffers to the server.
2423  */
2424 VAStatus vaRenderPicture (
2425     VADisplay dpy,
2426     VAContextID context,
2427     VABufferID *buffers,
2428     int num_buffers
2429 );
2430
2431 /**
2432  * Make the end of rendering for a picture. 
2433  * The server should start processing all pending operations for this 
2434  * surface. This call is non-blocking. The client can start another 
2435  * Begin/Render/End sequence on a different render target.
2436  */
2437 VAStatus vaEndPicture (
2438     VADisplay dpy,
2439     VAContextID context
2440 );
2441
2442 /*
2443
2444 Synchronization 
2445
2446 */
2447
2448 /**
2449  * This function blocks until all pending operations on the render target
2450  * have been completed.  Upon return it is safe to use the render target for a 
2451  * different picture. 
2452  */
2453 VAStatus vaSyncSurface (
2454     VADisplay dpy,
2455     VASurfaceID render_target
2456 );
2457
2458 typedef enum
2459 {
2460     VASurfaceRendering  = 1, /* Rendering in progress */ 
2461     VASurfaceDisplaying = 2, /* Displaying in progress (not safe to render into it) */ 
2462                              /* this status is useful if surface is used as the source */
2463                              /* of an overlay */
2464     VASurfaceReady      = 4, /* not being rendered or displayed */
2465     VASurfaceSkipped    = 8  /* Indicate a skipped frame during encode */
2466 } VASurfaceStatus;
2467
2468 /**
2469  * Find out any pending ops on the render target 
2470  */
2471 VAStatus vaQuerySurfaceStatus (
2472     VADisplay dpy,
2473     VASurfaceID render_target,
2474     VASurfaceStatus *status     /* out */
2475 );
2476
2477 typedef enum
2478 {
2479     VADecodeSliceMissing            = 0,
2480     VADecodeMBError                 = 1,
2481 } VADecodeErrorType;
2482
2483 /**
2484  * Client calls vaQuerySurfaceError with VA_STATUS_ERROR_DECODING_ERROR, server side returns
2485  * an array of structure VASurfaceDecodeMBErrors, and the array is terminated by setting status=-1
2486 */
2487 typedef struct _VASurfaceDecodeMBErrors
2488 {
2489     int status; /* 1 if hardware has returned detailed info below, -1 means this record is invalid */
2490     unsigned int start_mb; /* start mb address with errors */
2491     unsigned int end_mb;  /* end mb address with errors */
2492     VADecodeErrorType decode_error_type;
2493 } VASurfaceDecodeMBErrors;
2494
2495 /**
2496  * After the application gets VA_STATUS_ERROR_DECODING_ERROR after calling vaSyncSurface(),
2497  * it can call vaQuerySurfaceError to find out further details on the particular error.
2498  * VA_STATUS_ERROR_DECODING_ERROR should be passed in as "error_status",
2499  * upon the return, error_info will point to an array of _VASurfaceDecodeMBErrors structure,
2500  * which is allocated and filled by libVA with detailed information on the missing or error macroblocks.
2501  * The array is terminated if "status==-1" is detected.
2502  */
2503 VAStatus vaQuerySurfaceError(
2504     VADisplay dpy,
2505     VASurfaceID surface,
2506     VAStatus error_status,
2507     void **error_info
2508 );
2509
2510 /**
2511  * Images and Subpictures
2512  * VAImage is used to either get the surface data to client memory, or 
2513  * to copy image data in client memory to a surface. 
2514  * Both images, subpictures and surfaces follow the same 2D coordinate system where origin 
2515  * is at the upper left corner with positive X to the right and positive Y down
2516  */
2517 #define VA_FOURCC(ch0, ch1, ch2, ch3) \
2518     ((unsigned long)(unsigned char) (ch0) | ((unsigned long)(unsigned char) (ch1) << 8) | \
2519     ((unsigned long)(unsigned char) (ch2) << 16) | ((unsigned long)(unsigned char) (ch3) << 24 ))
2520
2521 /* 
2522  * Pre-defined fourcc codes
2523  */
2524 #define VA_FOURCC_NV12          0x3231564E
2525 #define VA_FOURCC_AI44          0x34344149
2526 #define VA_FOURCC_RGBA          0x41424752
2527 #define VA_FOURCC_RGBX          0x58424752
2528 #define VA_FOURCC_BGRA          0x41524742
2529 #define VA_FOURCC_BGRX          0x58524742
2530 #define VA_FOURCC_ARGB          0x42475241
2531 #define VA_FOURCC_XRGB          0x42475258
2532 #define VA_FOURCC_ABGR          0x52474241
2533 #define VA_FOURCC_XBGR          0x52474258
2534 #define VA_FOURCC_UYVY          0x59565955
2535 #define VA_FOURCC_YUY2          0x32595559
2536 #define VA_FOURCC_AYUV          0x56555941
2537 #define VA_FOURCC_NV11          0x3131564e
2538 #define VA_FOURCC_YV12          0x32315659
2539 #define VA_FOURCC_P208          0x38303250
2540 #define VA_FOURCC_IYUV          0x56555949
2541 #define VA_FOURCC_YV24          0x34325659
2542 #define VA_FOURCC_YV32          0x32335659
2543 #define VA_FOURCC_Y800          0x30303859
2544 #define VA_FOURCC_IMC3          0x33434D49
2545 #define VA_FOURCC_411P          0x50313134
2546 #define VA_FOURCC_422H          0x48323234
2547 #define VA_FOURCC_422V          0x56323234
2548 #define VA_FOURCC_444P          0x50343434
2549 #define VA_FOURCC_RGBP          0x50424752
2550 #define VA_FOURCC_BGRP          0x50524742
2551 #define VA_FOURCC_411R          0x52313134 /* rotated 411P */
2552 /**
2553  * Planar YUV 4:2:2.
2554  * 8-bit Y plane, followed by 8-bit 2x1 subsampled V and U planes
2555  */
2556 #define VA_FOURCC_YV16          0x36315659
2557 /**
2558  * 10-bit and 16-bit Planar YUV 4:2:0. 
2559  */
2560 #define VA_FOURCC_P010          0x30313050
2561 #define VA_FOURCC_P016          0x36313050
2562
2563 /**
2564  * 10-bit Planar YUV 420 and occupy the lower 10-bit.
2565  */
2566 #define VA_FOURCC_I010          0x30313049
2567
2568 /* byte order */
2569 #define VA_LSB_FIRST            1
2570 #define VA_MSB_FIRST            2
2571
2572 typedef struct _VAImageFormat
2573 {
2574     unsigned int        fourcc;
2575     unsigned int        byte_order; /* VA_LSB_FIRST, VA_MSB_FIRST */
2576     unsigned int        bits_per_pixel;
2577     /* for RGB formats */
2578     unsigned int        depth; /* significant bits per pixel */
2579     unsigned int        red_mask;
2580     unsigned int        green_mask;
2581     unsigned int        blue_mask;
2582     unsigned int        alpha_mask;
2583 } VAImageFormat;
2584
2585 typedef VAGenericID VAImageID;
2586
2587 typedef struct _VAImage
2588 {
2589     VAImageID           image_id; /* uniquely identify this image */
2590     VAImageFormat       format;
2591     VABufferID          buf;    /* image data buffer */
2592     /*
2593      * Image data will be stored in a buffer of type VAImageBufferType to facilitate
2594      * data store on the server side for optimal performance. The buffer will be 
2595      * created by the CreateImage function, and proper storage allocated based on the image
2596      * size and format. This buffer is managed by the library implementation, and 
2597      * accessed by the client through the buffer Map/Unmap functions.
2598      */
2599     unsigned short      width; 
2600     unsigned short      height;
2601     unsigned int        data_size;
2602     unsigned int        num_planes;     /* can not be greater than 3 */
2603     /* 
2604      * An array indicating the scanline pitch in bytes for each plane.
2605      * Each plane may have a different pitch. Maximum 3 planes for planar formats
2606      */
2607     unsigned int        pitches[3];
2608     /* 
2609      * An array indicating the byte offset from the beginning of the image data 
2610      * to the start of each plane.
2611      */
2612     unsigned int        offsets[3];
2613
2614     /* The following fields are only needed for paletted formats */
2615     int num_palette_entries;   /* set to zero for non-palette images */
2616     /* 
2617      * Each component is one byte and entry_bytes indicates the number of components in 
2618      * each entry (eg. 3 for YUV palette entries). set to zero for non-palette images   
2619      */
2620     int entry_bytes; 
2621     /*
2622      * An array of ascii characters describing the order of the components within the bytes.
2623      * Only entry_bytes characters of the string are used.
2624      */
2625     char component_order[4];
2626 } VAImage;
2627
2628 /** Get maximum number of image formats supported by the implementation */
2629 int vaMaxNumImageFormats (
2630     VADisplay dpy
2631 );
2632
2633 /**
2634  * Query supported image formats 
2635  * The caller must provide a "format_list" array that can hold at
2636  * least vaMaxNumImageFormats() entries. The actual number of formats
2637  * returned in "format_list" is returned in "num_formats".
2638  */
2639 VAStatus vaQueryImageFormats (
2640     VADisplay dpy,
2641     VAImageFormat *format_list, /* out */
2642     int *num_formats            /* out */
2643 );
2644
2645 /**
2646  * Create a VAImage structure
2647  * The width and height fields returned in the VAImage structure may get 
2648  * enlarged for some YUV formats. Upon return from this function, 
2649  * image->buf has been created and proper storage allocated by the library. 
2650  * The client can access the image through the Map/Unmap calls.
2651  */
2652 VAStatus vaCreateImage (
2653     VADisplay dpy,
2654     VAImageFormat *format,
2655     int width,
2656     int height,
2657     VAImage *image      /* out */
2658 );
2659
2660 /**
2661  * Should call DestroyImage before destroying the surface it is bound to
2662  */
2663 VAStatus vaDestroyImage (
2664     VADisplay dpy,
2665     VAImageID image
2666 );
2667
2668 VAStatus vaSetImagePalette (
2669     VADisplay dpy,
2670     VAImageID image,
2671     /* 
2672      * pointer to an array holding the palette data.  The size of the array is 
2673      * num_palette_entries * entry_bytes in size.  The order of the components 
2674      * in the palette is described by the component_order in VAImage struct    
2675      */
2676     unsigned char *palette 
2677 );
2678
2679 /**
2680  * Retrive surface data into a VAImage
2681  * Image must be in a format supported by the implementation
2682  */
2683 VAStatus vaGetImage (
2684     VADisplay dpy,
2685     VASurfaceID surface,
2686     int x,      /* coordinates of the upper left source pixel */
2687     int y,
2688     unsigned int width, /* width and height of the region */
2689     unsigned int height,
2690     VAImageID image
2691 );
2692
2693 /**
2694  * Copy data from a VAImage to a surface
2695  * Image must be in a format supported by the implementation
2696  * Returns a VA_STATUS_ERROR_SURFACE_BUSY if the surface
2697  * shouldn't be rendered into when this is called
2698  */
2699 VAStatus vaPutImage (
2700     VADisplay dpy,
2701     VASurfaceID surface,
2702     VAImageID image,
2703     int src_x,
2704     int src_y,
2705     unsigned int src_width,
2706     unsigned int src_height,
2707     int dest_x,
2708     int dest_y,
2709     unsigned int dest_width,
2710     unsigned int dest_height
2711 );
2712
2713 /**
2714  * Derive an VAImage from an existing surface.
2715  * This interface will derive a VAImage and corresponding image buffer from
2716  * an existing VA Surface. The image buffer can then be mapped/unmapped for
2717  * direct CPU access. This operation is only possible on implementations with
2718  * direct rendering capabilities and internal surface formats that can be
2719  * represented with a VAImage. When the operation is not possible this interface
2720  * will return VA_STATUS_ERROR_OPERATION_FAILED. Clients should then fall back
2721  * to using vaCreateImage + vaPutImage to accomplish the same task in an
2722  * indirect manner.
2723  *
2724  * Implementations should only return success when the resulting image buffer
2725  * would be useable with vaMap/Unmap.
2726  *
2727  * When directly accessing a surface special care must be taken to insure
2728  * proper synchronization with the graphics hardware. Clients should call
2729  * vaQuerySurfaceStatus to insure that a surface is not the target of concurrent
2730  * rendering or currently being displayed by an overlay.
2731  *
2732  * Additionally nothing about the contents of a surface should be assumed
2733  * following a vaPutSurface. Implementations are free to modify the surface for
2734  * scaling or subpicture blending within a call to vaPutImage.
2735  *
2736  * Calls to vaPutImage or vaGetImage using the same surface from which the image
2737  * has been derived will return VA_STATUS_ERROR_SURFACE_BUSY. vaPutImage or
2738  * vaGetImage with other surfaces is supported.
2739  *
2740  * An image created with vaDeriveImage should be freed with vaDestroyImage. The
2741  * image and image buffer structures will be destroyed; however, the underlying
2742  * surface will remain unchanged until freed with vaDestroySurfaces.
2743  */
2744 VAStatus vaDeriveImage (
2745     VADisplay dpy,
2746     VASurfaceID surface,
2747     VAImage *image      /* out */
2748 );
2749
2750 /**
2751  * Subpictures 
2752  * Subpicture is a special type of image that can be blended 
2753  * with a surface during vaPutSurface(). Subpicture can be used to render
2754  * DVD sub-titles or closed captioning text etc.  
2755  */
2756
2757 typedef VAGenericID VASubpictureID;
2758
2759 /** Get maximum number of subpicture formats supported by the implementation */
2760 int vaMaxNumSubpictureFormats (
2761     VADisplay dpy
2762 );
2763
2764 /** flags for subpictures */
2765 #define VA_SUBPICTURE_CHROMA_KEYING                     0x0001
2766 #define VA_SUBPICTURE_GLOBAL_ALPHA                      0x0002
2767 #define VA_SUBPICTURE_DESTINATION_IS_SCREEN_COORD       0x0004
2768 /**
2769  * Query supported subpicture formats 
2770  * The caller must provide a "format_list" array that can hold at
2771  * least vaMaxNumSubpictureFormats() entries. The flags arrary holds the flag 
2772  * for each format to indicate additional capabilities for that format. The actual 
2773  * number of formats returned in "format_list" is returned in "num_formats".
2774  *  flags: returned value to indicate addtional capabilities
2775  *         VA_SUBPICTURE_CHROMA_KEYING - supports chroma-keying
2776  *         VA_SUBPICTURE_GLOBAL_ALPHA - supports global alpha
2777  *         VA_SUBPICTURE_DESTINATION_IS_SCREEN_COORD - supports unscaled screen relative subpictures for On Screen Display
2778  */
2779
2780 VAStatus vaQuerySubpictureFormats (
2781     VADisplay dpy,
2782     VAImageFormat *format_list, /* out */
2783     unsigned int *flags,        /* out */
2784     unsigned int *num_formats   /* out */
2785 );
2786
2787 /**
2788  * Subpictures are created with an image associated. 
2789  */
2790 VAStatus vaCreateSubpicture (
2791     VADisplay dpy,
2792     VAImageID image,
2793     VASubpictureID *subpicture  /* out */
2794 );
2795
2796 /**
2797  * Destroy the subpicture before destroying the image it is assocated to
2798  */
2799 VAStatus vaDestroySubpicture (
2800     VADisplay dpy,
2801     VASubpictureID subpicture
2802 );
2803
2804 /**
2805  * Bind an image to the subpicture. This image will now be associated with 
2806  * the subpicture instead of the one at creation.
2807  */
2808 VAStatus vaSetSubpictureImage (
2809     VADisplay dpy,
2810     VASubpictureID subpicture,
2811     VAImageID image
2812 );
2813
2814 /**
2815  * If chromakey is enabled, then the area where the source value falls within
2816  * the chromakey [min, max] range is transparent
2817  * The chromakey component format is the following:
2818  *  For RGB: [0:7] Red [8:15] Blue [16:23] Green   
2819  *  For YUV: [0:7] V [8:15] U [16:23] Y
2820  * The chromakey mask can be used to mask out certain components for chromakey
2821  * comparision
2822  */
2823 VAStatus vaSetSubpictureChromakey (
2824     VADisplay dpy,
2825     VASubpictureID subpicture,
2826     unsigned int chromakey_min,
2827     unsigned int chromakey_max,
2828     unsigned int chromakey_mask
2829 );
2830
2831 /**
2832  * Global alpha value is between 0 and 1. A value of 1 means fully opaque and 
2833  * a value of 0 means fully transparent. If per-pixel alpha is also specified then
2834  * the overall alpha is per-pixel alpha multiplied by the global alpha
2835  */
2836 VAStatus vaSetSubpictureGlobalAlpha (
2837     VADisplay dpy,
2838     VASubpictureID subpicture,
2839     float global_alpha 
2840 );
2841
2842 /**
2843  * vaAssociateSubpicture associates the subpicture with target_surfaces.
2844  * It defines the region mapping between the subpicture and the target  
2845  * surfaces through source and destination rectangles (with the same width and height).
2846  * Both will be displayed at the next call to vaPutSurface.  Additional
2847  * associations before the call to vaPutSurface simply overrides the association.
2848  */
2849 VAStatus vaAssociateSubpicture (
2850     VADisplay dpy,
2851     VASubpictureID subpicture,
2852     VASurfaceID *target_surfaces,
2853     int num_surfaces,
2854     short src_x, /* upper left offset in subpicture */
2855     short src_y,
2856     unsigned short src_width,
2857     unsigned short src_height,
2858     short dest_x, /* upper left offset in surface */
2859     short dest_y,
2860     unsigned short dest_width,
2861     unsigned short dest_height,
2862     /*
2863      * whether to enable chroma-keying, global-alpha, or screen relative mode
2864      * see VA_SUBPICTURE_XXX values
2865      */
2866     unsigned int flags
2867 );
2868
2869 /**
2870  * vaDeassociateSubpicture removes the association of the subpicture with target_surfaces.
2871  */
2872 VAStatus vaDeassociateSubpicture (
2873     VADisplay dpy,
2874     VASubpictureID subpicture,
2875     VASurfaceID *target_surfaces,
2876     int num_surfaces
2877 );
2878
2879 /**
2880  * Display attributes
2881  * Display attributes are used to control things such as contrast, hue, saturation,
2882  * brightness etc. in the rendering process.  The application can query what
2883  * attributes are supported by the driver, and then set the appropriate attributes
2884  * before calling vaPutSurface()
2885  */
2886 /* PowerVR IEP Lite attributes */
2887 typedef enum
2888 {
2889     VADISPLAYATTRIB_BLE_OFF              = 0x00,
2890     VADISPLAYATTRIB_BLE_LOW,
2891     VADISPLAYATTRIB_BLE_MEDIUM,
2892     VADISPLAYATTRIB_BLE_HIGH,
2893     VADISPLAYATTRIB_BLE_NONE,
2894 } VADisplayAttribBLEMode;
2895
2896 /** attribute value for VADisplayAttribRotation   */
2897 #define VA_ROTATION_NONE        0x00000000
2898 #define VA_ROTATION_90          0x00000001
2899 #define VA_ROTATION_180         0x00000002
2900 #define VA_ROTATION_270         0x00000003
2901
2902 /** attribute value for VADisplayAttribOutOfLoopDeblock */
2903 #define VA_OOL_DEBLOCKING_FALSE 0x00000000
2904 #define VA_OOL_DEBLOCKING_TRUE  0x00000001
2905
2906 /** Render mode */
2907 #define VA_RENDER_MODE_UNDEFINED           0
2908 #define VA_RENDER_MODE_LOCAL_OVERLAY       1
2909 #define VA_RENDER_MODE_LOCAL_GPU           2
2910 #define VA_RENDER_MODE_EXTERNAL_OVERLAY    4
2911 #define VA_RENDER_MODE_EXTERNAL_GPU        8
2912
2913 /** Render device */
2914 #define VA_RENDER_DEVICE_UNDEFINED  0
2915 #define VA_RENDER_DEVICE_LOCAL      1
2916 #define VA_RENDER_DEVICE_EXTERNAL   2
2917
2918 /** Currently defined display attribute types */
2919 typedef enum
2920 {
2921     VADisplayAttribBrightness           = 0,
2922     VADisplayAttribContrast             = 1,
2923     VADisplayAttribHue                  = 2,
2924     VADisplayAttribSaturation           = 3,
2925     /* client can specifiy a background color for the target window
2926      * the new feature of video conference,
2927      * the uncovered area of the surface is filled by this color
2928      * also it will blend with the decoded video color
2929      */
2930     VADisplayAttribBackgroundColor      = 4,
2931     /*
2932      * this is a gettable only attribute. For some implementations that use the
2933      * hardware overlay, after PutSurface is called, the surface can not be    
2934      * re-used until after the subsequent PutSurface call. If this is the case 
2935      * then the value for this attribute will be set to 1 so that the client   
2936      * will not attempt to re-use the surface right after returning from a call
2937      * to PutSurface.
2938      *
2939      * Don't use it, use flag VASurfaceDisplaying of vaQuerySurfaceStatus since
2940      * driver may use overlay or GPU alternatively
2941      */
2942     VADisplayAttribDirectSurface       = 5,
2943     VADisplayAttribRotation            = 6,     
2944     VADisplayAttribOutofLoopDeblock    = 7,
2945
2946     /* PowerVR IEP Lite specific attributes */
2947     VADisplayAttribBLEBlackMode        = 8,
2948     VADisplayAttribBLEWhiteMode        = 9,
2949     VADisplayAttribBlueStretch         = 10,
2950     VADisplayAttribSkinColorCorrection = 11,
2951     /*
2952      * For type VADisplayAttribCSCMatrix, "value" field is a pointer to the color
2953      * conversion matrix. Each element in the matrix is float-point
2954      */
2955     VADisplayAttribCSCMatrix           = 12,
2956     /* specify the constant color used to blend with video surface
2957      * Cd = Cv*Cc*Ac + Cb *(1 - Ac) C means the constant RGB
2958      *      d: the final color to overwrite into the frame buffer 
2959      *      v: decoded video after color conversion, 
2960      *      c: video color specified by VADisplayAttribBlendColor
2961      *      b: background color of the drawable
2962      */
2963     VADisplayAttribBlendColor          = 13,
2964     /*
2965      * Indicate driver to skip painting color key or not.
2966      * only applicable if the render is overlay
2967      */
2968     VADisplayAttribOverlayAutoPaintColorKey   = 14,
2969     /*
2970      * customized overlay color key, the format is RGB888
2971      * [23:16] = Red, [15:08] = Green, [07:00] = Blue.
2972      */
2973     VADisplayAttribOverlayColorKey      = 15,
2974     /*
2975      * The hint for the implementation of vaPutSurface
2976      * normally, the driver could use an overlay or GPU to render the surface on the screen
2977      * this flag provides APP the flexibity to switch the render dynamically
2978      */
2979     VADisplayAttribRenderMode           = 16,
2980     /*
2981      * specify if vaPutSurface needs to render into specified monitors
2982      * one example is that one external monitor (e.g. HDMI) is enabled, 
2983      * but the window manager is not aware of it, and there is no associated drawable
2984      */
2985     VADisplayAttribRenderDevice        = 17,
2986     /*
2987      * specify vaPutSurface render area if there is no drawable on the monitor
2988      */
2989     VADisplayAttribRenderRect          = 18,
2990 } VADisplayAttribType;
2991
2992 /* flags for VADisplayAttribute */
2993 #define VA_DISPLAY_ATTRIB_NOT_SUPPORTED 0x0000
2994 #define VA_DISPLAY_ATTRIB_GETTABLE      0x0001
2995 #define VA_DISPLAY_ATTRIB_SETTABLE      0x0002
2996
2997 typedef struct _VADisplayAttribute
2998 {
2999     VADisplayAttribType type;
3000     int min_value;
3001     int max_value;
3002     int value;  /* used by the set/get attribute functions */
3003 /* flags can be VA_DISPLAY_ATTRIB_GETTABLE or VA_DISPLAY_ATTRIB_SETTABLE or OR'd together */
3004     unsigned int flags;
3005 } VADisplayAttribute;
3006
3007 /** Get maximum number of display attributs supported by the implementation */
3008 int vaMaxNumDisplayAttributes (
3009     VADisplay dpy
3010 );
3011
3012 /**
3013  * Query display attributes 
3014  * The caller must provide a "attr_list" array that can hold at
3015  * least vaMaxNumDisplayAttributes() entries. The actual number of attributes
3016  * returned in "attr_list" is returned in "num_attributes".
3017  */
3018 VAStatus vaQueryDisplayAttributes (
3019     VADisplay dpy,
3020     VADisplayAttribute *attr_list,      /* out */
3021     int *num_attributes                 /* out */
3022 );
3023
3024 /**
3025  * Get display attributes 
3026  * This function returns the current attribute values in "attr_list".
3027  * Only attributes returned with VA_DISPLAY_ATTRIB_GETTABLE set in the "flags" field
3028  * from vaQueryDisplayAttributes() can have their values retrieved.  
3029  */
3030 VAStatus vaGetDisplayAttributes (
3031     VADisplay dpy,
3032     VADisplayAttribute *attr_list,      /* in/out */
3033     int num_attributes
3034 );
3035
3036 /**
3037  * Set display attributes 
3038  * Only attributes returned with VA_DISPLAY_ATTRIB_SETTABLE set in the "flags" field
3039  * from vaQueryDisplayAttributes() can be set.  If the attribute is not settable or 
3040  * the value is out of range, the function returns VA_STATUS_ERROR_ATTR_NOT_SUPPORTED
3041  */
3042 VAStatus vaSetDisplayAttributes (
3043     VADisplay dpy,
3044     VADisplayAttribute *attr_list,
3045     int num_attributes
3046 );
3047
3048 /****************************
3049  * HEVC data structures
3050  ****************************/
3051 /** 
3052  * \brief Description of picture properties of those in DPB surfaces.
3053  *
3054  * If only progressive scan is supported, each surface contains one whole 
3055  * frame picture.
3056  * Otherwise, each surface contains two fields of whole picture.
3057  * In this case, two entries of ReferenceFrames[] may share same picture_id
3058  * value.
3059  */
3060 typedef struct _VAPictureHEVC
3061 {
3062     /** \brief reconstructed picture buffer surface index 
3063      * invalid when taking value VA_INVALID_SURFACE.
3064      */
3065     VASurfaceID             picture_id;
3066     /** \brief picture order count. 
3067      * in HEVC, POCs for top and bottom fields of same picture should
3068      * take different values.
3069      */
3070     int32_t                 pic_order_cnt;
3071     /* described below */
3072     uint32_t                flags;
3073 } VAPictureHEVC;
3074
3075 /* flags in VAPictureHEVC could be OR of the following */
3076 #define VA_PICTURE_HEVC_INVALID                 0x00000001
3077 /** \brief indication of interlace scan picture. 
3078  * should take same value for all the pictures in sequence.
3079  */ 
3080 #define VA_PICTURE_HEVC_FIELD_PIC               0x00000002
3081 /** \brief polarity of the field picture.
3082  * top field takes even lines of buffer surface.
3083  * bottom field takes odd lines of buffer surface.
3084  */
3085 #define VA_PICTURE_HEVC_BOTTOM_FIELD            0x00000004
3086 /** \brief Long term reference picture */
3087 #define VA_PICTURE_HEVC_LONG_TERM_REFERENCE     0x00000008
3088 /**
3089  * VA_PICTURE_HEVC_RPS_ST_CURR_BEFORE, VA_PICTURE_HEVC_RPS_ST_CURR_AFTER
3090  * and VA_PICTURE_HEVC_RPS_LT_CURR of any picture in ReferenceFrames[] should 
3091  * be exclusive. No more than one of them can be set for any picture.
3092  * Sum of NumPocStCurrBefore, NumPocStCurrAfter and NumPocLtCurr
3093  * equals NumPocTotalCurr, which should be equal to or smaller than 8.
3094  * Application should provide valid values for both short format and long format.
3095  * The pictures in DPB with any of these three flags turned on are referred by
3096  * the current picture.
3097  */
3098 /** \brief RefPicSetStCurrBefore of HEVC spec variable 
3099  * Number of ReferenceFrames[] entries with this bit set equals 
3100  * NumPocStCurrBefore.
3101  */
3102 #define VA_PICTURE_HEVC_RPS_ST_CURR_BEFORE      0x00000010
3103 /** \brief RefPicSetStCurrAfter of HEVC spec variable
3104  * Number of ReferenceFrames[] entries with this bit set equals 
3105  * NumPocStCurrAfter.
3106  */
3107 #define VA_PICTURE_HEVC_RPS_ST_CURR_AFTER       0x00000020
3108 /** \brief RefPicSetLtCurr of HEVC spec variable
3109  * Number of ReferenceFrames[] entries with this bit set equals 
3110  * NumPocLtCurr.
3111  */
3112 #define VA_PICTURE_HEVC_RPS_LT_CURR             0x00000040
3113
3114 #include <va/va_dec_hevc.h>
3115 #include <va/va_dec_jpeg.h>
3116 #include <va/va_dec_vp8.h>
3117 #include <va/va_dec_vp9.h>
3118 #include <va/va_enc_hevc.h>
3119 #include <va/va_enc_h264.h>
3120 #include <va/va_enc_jpeg.h>
3121 #include <va/va_enc_mpeg2.h>
3122 #include <va/va_enc_vp8.h>
3123 #include <va/va_enc_vp9.h>
3124 #include <va/va_vpp.h>
3125
3126 /**@}*/
3127
3128 #ifdef __cplusplus
3129 }
3130 #endif
3131
3132 #endif /* _VA_H_ */