OSDN Git Service

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