2 * Copyright (c) 2007 Intel Corporation. All Rights Reserved.
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:
12 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial portions
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 PRECISION INSIGHT 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.
25 * Video Decode Acceleration API Specification
28 * <jonathan.bian@intel.com>
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/07/2007 Jonathan Bian) - Fixed some issues with images and subpictures.
48 * Some concepts borrowed from XvMC and XvImage.
49 * Thanks to Waldo Bastian for many valuable feedbacks.
61 This is currently a decode only interface (with some rendering support).
63 The basic operation steps are:
65 - Negotiate a mutually acceptable configuration with the server to lock
66 down profile, entrypoints, and other attributes that will not change on
67 a frame-by-frame basis.
68 - Create a decode context which represents a "virtualized" hardware decode
70 - Get and fill decode buffers with picture level, slice level and macroblock
71 level data (depending on entrypoints)
72 - Pass the decode buffers to the server to decode the current frame
74 Initialization & Configuration Management
76 - Find out supported profiles
77 - Find out entrypoints for a given profile
78 - Find out configuration attributes for a given profile/entrypoint pair
79 - Create a configuration for use by the decoder
83 typedef void* VADisplay; /* window system dependent */
85 typedef int VAStatus; /* Return status type from functions */
86 /* Values for the return status */
87 #define VA_STATUS_SUCCESS 0x00000000
88 #define VA_STATUS_ERROR_ALLOCATION_FAILED 0x00000001
89 #define VA_STATUS_ERROR_INVALID_CONFIG 0x00000002
90 #define VA_STATUS_ERROR_INVALID_CONTEXT 0x00000003
91 #define VA_STATUS_ERROR_INVALID_SURFACE 0x00000004
92 #define VA_STATUS_ERROR_INVALID_BUFFER 0x00000005
93 #define VA_STATUS_ERROR_ATTR_NOT_SUPPORTED 0x00000006 /* Todo: Remove */
94 #define VA_STATUS_ERROR_MAX_NUM_EXCEEDED 0x00000007
95 #define VA_STATUS_ERROR_UNSUPPORTED_PROFILE 0x00000008
96 #define VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT 0x00000009
97 #define VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT 0x0000000a
98 #define VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE 0x0000000b
99 #define VA_STATUS_ERROR_UNKNOWN 0xFFFFFFFF
102 * Returns a short english description of error_status
104 const char *vaErrorStr(VAStatus error_status);
108 * A display must be obtained by calling vaGetDisplay() before calling
109 * vaInitialize() and other functions. This connects the API to the
110 * native window system.
111 * For X Windows, native_dpy would be from XOpenDisplay()
113 typedef void* NativeDisplay; /* window system dependent */
115 VADisplay vaGetDisplay (
116 NativeDisplay native_dpy /* implementation specific */
119 VAStatus vaInitialize (
121 int *major_version, /* out */
122 int *minor_version /* out */
126 * After this call, all library internal resources will be cleaned up
128 VAStatus vaTerminate (
132 /* Currently defined profiles */
135 VAProfileMPEG2Simple = 0,
136 VAProfileMPEG2Main = 1,
137 VAProfileMPEG4Simple = 2,
138 VAProfileMPEG4AdvancedSimple = 3,
139 VAProfileMPEG4Main = 4,
140 VAProfileH264Baseline = 5,
141 VAProfileH264Main = 6,
142 VAProfileH264High = 7,
143 VAProfileVC1Simple = 8,
144 VAProfileVC1Main = 9,
145 VAProfileVC1Advanced = 10,
149 * Currently defined entrypoints
155 VAEntrypointIDCT = 3,
156 VAEntrypointMoComp = 4,
157 VAEntrypointDeblocking = 5,
160 /* Currently defined configuration attribute types */
163 VAConfigAttribRTFormat = 0,
164 VAConfigAttribSpatialResidual = 1,
165 VAConfigAttribSpatialClipping = 2,
166 VAConfigAttribIntraResidual = 3,
167 VAConfigAttribEncryption = 4,
168 } VAConfigAttribType;
171 * Configuration attributes
172 * If there is more than one value for an attribute, a default
173 * value will be assigned to the attribute if the client does not
174 * specify the attribute when creating a configuration
176 typedef struct _VAConfigAttrib {
177 VAConfigAttribType type;
178 unsigned int value; /* OR'd flags (bits) for this attribute */
181 /* attribute value for VAConfigAttribRTFormat */
182 #define VA_RT_FORMAT_YUV420 0x00000001
183 #define VA_RT_FORMAT_YUV422 0x00000002
184 #define VA_RT_FORMAT_YUV444 0x00000004
187 * if an attribute is not applicable for a given
188 * profile/entrypoint pair, then set the value to the following
190 #define VA_ATTRIB_NOT_SUPPORTED 0x80000000
192 /* Get maximum number of profiles supported by the implementation */
193 int vaMaxNumProfiles (
197 /* Get maximum number of entrypoints supported by the implementation */
198 int vaMaxNumEntrypoints (
202 /* Get maximum number of attributs supported by the implementation */
203 int vaMaxNumConfigAttributes (
208 * Query supported profiles
209 * The caller must provide a "profile_list" array that can hold at
210 * least vaMaxNumProfile() entries. The actual number of profiles
211 * returned in "profile_list" is returned in "num_profile".
213 VAStatus vaQueryConfigProfiles (
215 VAProfile *profile_list, /* out */
216 int *num_profiles /* out */
220 * Query supported entrypoints for a given profile
221 * The caller must provide an "entrypoint_list" array that can hold at
222 * least vaMaxNumEntrypoints() entries. The actual number of entrypoints
223 * returned in "entrypoint_list" is returned in "num_entrypoints".
225 VAStatus vaQueryConfigEntrypoints (
228 VAEntrypoint *entrypoint_list, /* out */
229 int *num_entrypoints /* out */
233 * Query attributes for a given profile/entrypoint pair
234 * The caller must provide an
\93attrib_list
\94 with all attributes to be
235 * queried. Upon return, the attributes in
\93attrib_list
\94 have been
236 * updated with their value. Unknown attributes or attributes that are
237 * not supported for the given profile/entrypoint pair will have their
238 * value set to VA_ATTRIB_NOT_SUPPORTED
240 VAStatus vaQueryConfigAttributes (
243 VAEntrypoint entrypoint,
244 VAConfigAttrib *attrib_list, /* in/out */
248 typedef int VAConfigID;
251 * Create a configuration for the decode pipeline
252 * it passes in the attribute list that specifies the attributes it cares
253 * about, with the rest taking default values.
255 VAStatus vaCreateConfig (
258 VAEntrypoint entrypoint,
259 VAConfigAttrib *attrib_list,
261 VAConfigID *config_id /* out */
265 * Get all attributes for a given configuration
266 * The profile of the configuration is returned in
\93profile
\94
267 * The entrypoint of the configuration is returned in
\93entrypoint
\94
268 * The caller must provide an
\93attrib_list
\94 array that can hold at least
269 * vaMaxNumConfigAttributes() entries. The actual number of attributes
270 * returned in
\93attrib_list
\94 is returned in
\93num_attribs
\94
272 VAStatus vaGetConfigAttributes (
274 VAConfigID config_id,
275 VAProfile *profile, /* out */
276 VAEntrypoint *entrypoint, /* out */
277 VAConfigAttrib *attrib_list,/* out */
278 int *num_attribs /* out */
285 * Context represents a "virtual" video decode pipeline
288 /* generic context ID type, can be re-typed for specific implementation */
289 typedef int VAContextID;
291 /* generic surface ID type, can be re-typed for specific implementation */
292 typedef int VASurfaceID;
294 #define VA_INVALID_SURFACE -1
296 typedef struct _VAContext
298 VAContextID context_id; /* to identify this context */
299 VAConfigID config_id;
300 unsigned short picture_width;
301 unsigned short picture_height;
302 VASurfaceID *render_targets;
303 int num_render_targets;
309 flags - Any combination of the following:
310 VA_PROGRESSIVE (only progressive frame pictures in the sequence when set)
312 #define VA_PROGRESSIVE 0x1
318 Surfaces are render targets for a given context. The data in the surfaces
319 are not accessible to the client and the internal data format of
320 the surface is implementatin specific.
322 Question: Is there a need to know the data format (fourcc) or just
323 differentiate between 420/422/444 is sufficient?
327 typedef struct _VASurface
329 VASurfaceID surface_id; /* uniquely identify this surface */
330 VAContextID context_id; /* which context does this surface belong */
331 unsigned short width;
332 unsigned short height;
333 int format; /* 420/422/444 */
334 void *privData; /* private to the library */
338 * Surfaces will be bound to a context when the context is created. Once
339 * a surface is bound to a given context, it can not be used to create
340 * another context. The association is removed when the context is destroyed
343 /* Surface Functions */
344 VAStatus vaCreateSurfaces (
350 VASurface *surfaces /* out */
354 * surfaces can only be destroyed after the context associated has been
357 VAStatus vaDestroySurface (
359 VASurface *surface_list,
363 VAStatus vaCreateContext (
365 VAConfigID config_id,
369 VASurface *render_targets,
370 int num_render_targets,
371 VAContext *context /* out */
374 VAStatus vaDestroyContext (
382 * Buffers are used to pass various types of data from the
383 * client to the server. The server maintains a data store
384 * for each buffer created, and the client idenfies a buffer
385 * through a unique buffer id assigned by the server.
389 typedef int VABufferID;
393 VAPictureParameterBufferType = 0,
394 VAIQMatrixBufferType = 1,
395 VABitPlaneBufferType = 2,
396 VASliceGroupMapBufferType = 3,
397 VASliceParameterBufferType = 4,
398 VASliceDataBufferType = 5,
399 VAMacroblockParameterBufferType = 6,
400 VAResidualDataBufferType = 7,
401 VADeblockingParameterBufferType = 8,
402 VAImageBufferType = 9
405 /****************************
406 * MPEG-2 data structures
407 ****************************/
409 /* MPEG-2 Picture Parameter Buffer */
411 * For each frame or field, and before any slice data, a single
412 * picture parameter buffer must be send.
414 typedef struct _VAPictureParameterBufferMPEG2
416 unsigned short horizontal_size;
417 unsigned short vertical_size;
418 VASurfaceID forward_reference_picture;
419 VASurfaceID backward_reference_picture;
420 /* meanings of the following fields are the same as in the standard */
421 int picture_coding_type;
422 int f_code; /* pack all four fcode into this */
425 unsigned char intra_dc_precision : 2;
426 unsigned char picture_structure : 2;
427 unsigned char top_field_first : 1;
428 unsigned char frame_pred_frame_dct : 1;
429 unsigned char concealment_motion_vectors : 1;
430 unsigned char q_scale_type : 1;
431 unsigned char intra_vlc_format : 1;
432 unsigned char alternate_scan : 1;
433 unsigned char repeat_first_field : 1;
434 unsigned char progressive_frame : 1;
435 unsigned char is_first_field : 1; /* indicate whether the current field
436 * is the first field for field picture
439 unsigned int picture_coding_extension;
441 } VAPictureParameterBufferMPEG2;
443 /* MPEG-2 Inverse Quantization Matrix Buffer */
444 typedef struct _VAIQMatrixBufferMPEG2
446 int load_intra_quantiser_matrix;
447 int load_non_intra_quantiser_matrix;
448 int load_chroma_intra_quantiser_matrix;
449 int load_chroma_non_intra_quantiser_matrix;
450 unsigned char intra_quantiser_matrix[64];
451 unsigned char non_intra_quantiser_matrix[64];
452 unsigned char chroma_intra_quantiser_matrix[64];
453 unsigned char chroma_non_intra_quantiser_matrix[64];
454 } VAIQMatrixBufferMPEG2;
457 * There will be cases where the bitstream buffer will not have enough room to hold
458 * the data for the entire slice, and the following flags will be used in the slice
459 * parameter to signal to the server for the possible cases.
460 * If a slice parameter buffer and slice data buffer pair is sent to the server with
461 * the slice data partially in the slice data buffer (BEGIN and MIDDLE cases below),
462 * then a slice parameter and data buffer needs to be sent again to complete this slice.
464 #define VA_SLICE_DATA_FLAG_ALL 0x00 /* whole slice is in the buffer */
465 #define VA_SLICE_DATA_FLAG_BEGIN 0x01 /* The beginning of the slice is in the buffer but the end if not */
466 #define VA_SLICE_DATA_FLAG_MIDDLE 0x02 /* Neither beginning nor end of the slice is in the buffer */
467 #define VA_SLICE_DATA_FLAG_END 0x04 /* end of the slice is in the buffer */
469 /* MPEG-2 Slice Parameter Buffer */
470 typedef struct _VASliceParameterBufferMPEG2
472 unsigned int slice_data_size;/* number of bytes in the slice data buffer for this slice */
473 unsigned int slice_data_offset;/* the offset to the first byte of slice data */
474 unsigned int slice_data_flag; /* see VA_SLICE_DATA_FLAG_XXX defintions */
475 unsigned int macroblock_offset;/* the offset to the first bit of MB from the first byte of slice data */
476 unsigned int slice_vertical_position;
477 int quantiser_scale_code;
478 int intra_slice_flag;
479 } VASliceParameterBufferMPEG2;
481 /* MPEG-2 Macroblock Parameter Buffer */
482 typedef struct _VAMacroblockParameterBufferMPEG2
484 unsigned short macroblock_address;
486 * macroblock_address (in raster scan order)
488 * bottom-right: picture-height-in-mb*picture-width-in-mb - 1
490 unsigned char macroblock_type; /* see definition below */
493 unsigned char frame_motion_type : 2;
494 unsigned char field_motion_type : 2;
495 unsigned char dct_type : 1;
497 unsigned char macroblock_modes;
499 unsigned char motion_vertical_field_select;
501 * motion_vertical_field_select:
502 * see section 6.3.17.2 in the spec
503 * only the lower 4 bits are used
504 * bit 0: first vector forward
505 * bit 1: first vector backward
506 * bit 2: second vector forward
507 * bit 3: second vector backward
509 short PMV[2][2][2]; /* see Table 7-7 in the spec */
510 unsigned short coded_block_pattern;
512 * The bitplanes for coded_block_pattern are described
513 * in Figure 6.10-12 in the spec
516 /* Number of skipped macroblocks after this macroblock */
517 unsigned short num_skipped_macroblocks;
518 } VAMacroblockParameterBufferMPEG2;
521 * OR'd flags for macroblock_type (section 6.3.17.1 in the spec)
523 #define VA_MB_TYPE_MOTION_FORWARD 0x02
524 #define VA_MB_TYPE_MOTION_BACKWARD 0x04
525 #define VA_MB_TYPE_MOTION_PATTERN 0x08
526 #define VA_MB_TYPE_MOTION_INTRA 0x10
529 * MPEG-2 Residual Data Buffer
530 * For each macroblock, there wil be 64 shorts (16-bit) in the
531 * residual data buffer
534 /****************************
535 * MPEG-4 Part 2 data structures
536 ****************************/
538 /* MPEG-4 Picture Parameter Buffer */
540 * For each frame or field, and before any slice data, a single
541 * picture parameter buffer must be send.
543 typedef struct _VAPictureParameterBufferMPEG4
545 unsigned short vop_width;
546 unsigned short vop_height;
547 VASurfaceID forward_reference_picture;
548 VASurfaceID backward_reference_picture;
551 unsigned char short_video_header : 1;
552 unsigned char chroma_format : 2;
553 unsigned char interlaced : 1;
554 unsigned char obmc_disable : 1;
555 unsigned char sprite_enable : 2;
556 unsigned char sprite_warping_accuracy : 2;
557 unsigned char quant_type : 1;
558 unsigned char quarter_sample : 1;
559 unsigned char data_partitioned : 1;
560 unsigned char reversible_vlc : 1;
562 unsigned short vol_fields;
564 unsigned char no_of_sprite_warping_points;
565 short sprite_trajectory_du[3];
566 short sprite_trajectory_dv[3];
567 unsigned char quant_precision;
570 unsigned char vop_coding_type : 2;
571 unsigned char backward_reference_vop_coding_type : 2;
572 unsigned char vop_rounding_type : 1;
573 unsigned char intra_dc_vlc_thr : 3;
574 unsigned char top_field_first : 1;
575 unsigned char alternate_vertical_scan_flag : 1;
577 unsigned short vop_fields;
579 unsigned char vop_fcode_forward;
580 unsigned char vop_fcode_backward;
581 /* short header related */
582 unsigned char num_gobs_in_vop;
583 unsigned char num_macroblocks_in_gob;
584 /* for direct mode prediction */
587 } VAPictureParameterBufferMPEG4;
589 /* MPEG-4 Inverse Quantization Matrix Buffer */
590 typedef struct _VAIQMatrixBufferMPEG4
592 int load_intra_quant_mat;
593 int load_non_intra_quant_mat;
594 unsigned char intra_quant_mat[64];
595 unsigned char non_intra_quant_mat[64];
596 } VAIQMatrixBufferMPEG4;
598 /* MPEG-4 Slice Parameter Buffer */
599 typedef struct _VASliceParameterBufferMPEG4
601 unsigned int slice_data_size;/* number of bytes in the slice data buffer for this slice */
602 unsigned int slice_data_offset;/* the offset to the first byte of slice data */
603 unsigned int slice_data_flag; /* see VA_SLICE_DATA_FLAG_XXX defintions */
604 unsigned int macroblock_offset;/* the offset to the first bit of MB from the first byte of slice data */
605 unsigned int macroblock_number;
607 } VASliceParameterBufferMPEG4;
613 /* VC-1 Picture Parameter Buffer */
615 * For each picture, and before any slice data, a picture parameter
616 * buffer must be send. Multiple picture parameter buffers may be
617 * sent for a single picture. In that case picture parameters will
618 * apply to all slice data that follow it until a new picture
619 * parameter buffer is sent.
622 * pic_quantizer_type should be set to the applicable quantizer
623 * type as defined by QUANTIZER (J.1.19) and either
624 * PQUANTIZER (7.1.1.8) or PQINDEX (7.1.1.6)
626 typedef struct _VAPictureParameterBufferVC1
628 VASurfaceID forward_reference_picture;
629 VASurfaceID backward_reference_picture;
630 /* if out-of-loop post-processing is done on the render
631 target, then we need to keep the in-loop decoded
632 picture as a reference picture */
633 VASurfaceID inloop_decoded_picture;
635 /* sequence layer for AP or meta data for SP and MP */
638 unsigned char interlace : 1; /* SEQUENCE_LAYER::INTERLACE */
639 unsigned char syncmarker : 1;/* METADATA::SYNCMARKER */
640 unsigned char overlap : 1;/* METADATA::OVERLAP */
642 unsigned char sequence_fields;
645 unsigned short coded_width; /* ENTRY_POINT_LAYER::CODED_WIDTH */
646 unsigned short coded_height; /* ENTRY_POINT_LAYER::CODED_HEIGHT */
647 unsigned char closed_entry; /* ENTRY_POINT_LAYER::CLOSED_ENTRY */
648 unsigned char broken_link; /* ENTRY_POINT_LAYER::BROKEN_LINK */
649 unsigned char loopfilter; /* ENTRY_POINT_LAYER::LOOPFILTER */
650 unsigned char conditional_overlap_flag; /* ENTRY_POINT_LAYER::CONDOVER */
651 unsigned char fast_uvmc_flag; /* ENTRY_POINT_LAYER::FASTUVMC */
654 unsigned char range_mapping_luma_flag: 1; /* ENTRY_POINT_LAYER::RANGE_MAPY_FLAG */
655 unsigned char range_mapping_luma: 3; /* ENTRY_POINT_LAYER::RANGE_MAPY */
656 unsigned char range_mapping_chroma_flag: 1; /* ENTRY_POINT_LAYER::RANGE_MAPUV_FLAG */
657 unsigned char range_mapping_chroma: 3; /* ENTRY_POINT_LAYER::RANGE_MAPUV */
659 unsigned char range_mapping_fields;
662 unsigned char b_picture_fraction; /* PICTURE_LAYER::BFRACTION */
663 unsigned char cbp_table; /* PICTURE_LAYER::CBPTAB/ICBPTAB */
664 unsigned char mb_mode_table; /* PICTURE_LAYER::MBMODETAB */
665 unsigned char range_reduction_frame;/* PICTURE_LAYER::RANGEREDFRM */
666 unsigned char rounding_control; /* PICTURE_LAYER::RNDCTRL */
667 unsigned char post_processing; /* PICTURE_LAYER::POSTPROC */
668 unsigned char picture_resolution_index; /* PICTURE_LAYER::RESPIC */
669 unsigned char luma_scale; /* PICTURE_LAYER::LUMSCALE */
670 unsigned char luma_shift; /* PICTURE_LAYER::LUMSHIFT */
673 unsigned char picture_type : 2; /* PICTURE_LAYER::PTYPE */
674 unsigned char frame_coding_mode : 3;/* PICTURE_LAYER::FCM */
675 unsigned char top_field_first : 1;/* PICTURE_LAYER::TFF */
676 unsigned char is_first_field : 1; /* set to 1 if it is the first field */
677 unsigned char intensity_compensation: 1;/* PICTURE_LAYER::INTCOMP */
679 unsigned char picture_fields;
683 unsigned char mv_type_mb : 1; /* PICTURE::MVTYPEMB */
684 unsigned char direct_mb : 1; /* PICTURE::DIRECTMB */
685 unsigned char skip_mb : 1; /* PICTURE::SKIPMB */
686 unsigned char field_tx : 1; /* PICTURE::FIELDTX */
687 unsigned char foward_mb : 1; /* PICTURE::FORWARDMB */
688 unsigned char ac_pred : 1; /* PICTURE::ACPRED */
689 unsigned char overflags : 1; /* PICTURE::OVERFLAGS */
691 unsigned char raw_coding_flag;
695 unsigned char reference_distance_flag : 1;/* PICTURE_LAYER::REFDIST_FLAG */
696 unsigned char reference_distance : 1;/* PICTURE_LAYER::REFDIST */
697 unsigned char num_reference_pictures: 1;/* PICTURE_LAYER::NUMREF */
698 unsigned char reference_field_pic_indicator : 1;/* PICTURE_LAYER::REFFIELD */
700 unsigned short reference_fields;
704 unsigned char mv_mode : 2; /* PICTURE_LAYER::MVMODE */
705 unsigned char mv_mode2 : 2; /* PICTURE_LAYER::MVMODE2 */
706 unsigned char mv_table : 3;/* PICTURE_LAYER::MVTAB/IMVTAB */
707 unsigned char two_mv_block_pattern_table: 2;/* PICTURE_LAYER::2MVBPTAB */
708 unsigned char four_mv_switch: 1; /* PICTURE_LAYER::4MVSWITCH */
709 unsigned char four_mv_block_pattern_table : 2;/* PICTURE_LAYER::4MVBPTAB */
710 unsigned char extended_mv_flag: 1;/* ENTRY_POINT_LAYER::EXTENDED_MV */
711 unsigned char extended_mv_range : 2;/* PICTURE_LAYER::MVRANGE */
712 unsigned char extended_dmv_flag : 1;/* ENTRY_POINT_LAYER::EXTENDED_DMV */
713 unsigned char extended_dmv_range : 2;/* PICTURE_LAYER::DMVRANGE */
715 unsigned int mv_fields;
719 unsigned char dquant : 2; /* ENTRY_POINT_LAYER::DQUANT */
720 unsigned char half_qp : 1; /* PICTURE_LAYER::HALFQP */
721 unsigned char pic_quantizer_scale : 1;/* PICTURE_LAYER::PQUANT */
722 unsigned char pic_quantizer_type : 1;/* PICTURE_LAYER::PQUANTIZER */
723 unsigned char dq_frame : 1; /* VOPDQUANT::DQUANTFRM */
724 unsigned char dq_profile : 2; /* VOPDQUANT::DQPROFILE */
725 unsigned char dq_sb_edge : 2; /* VOPDQUANT::DQSBEDGE */
726 unsigned char dq_db_edge : 2; /* VOPDQUANT::DQDBEDGE */
727 unsigned char dq_binary_level : 1; /* VOPDQUANT::DQBILEVEL */
728 unsigned char alt_pic_quantizer : 5;/* VOPDQUANT::ALTPQUANT */
730 unsigned long pic_quantizer_fields;
734 unsigned char variable_sized_transform_flag : 1;/* ENTRY_POINT_LAYER::VSTRANSFORM */
735 unsigned char mb_level_transform_type_flag : 1;/* PICTURE_LAYER::TTMBF */
736 unsigned char frame_level_transform_type : 2;/* PICTURE_LAYER::TTFRM */
737 unsigned char transform_ac_codingset_idx1 : 2;/* PICTURE_LAYER::TRANSACFRM */
738 unsigned char transform_ac_codingset_idx2 : 2;/* PICTURE_LAYER::TRANSACFRM2 */
739 unsigned char intra_transform_dc_table : 1;/* PICTURE_LAYER::TRANSDCTAB */
741 unsigned short transform_fields;
743 } VAPictureParameterBufferVC1;
745 /* VC-1 Bitplane Buffer
746 There will be at most three bitplanes coded in any picture header. To send
747 the bitplane data more efficiently, each byte is divided in two nibbles, with
748 each nibble carrying three bitplanes for one macroblock. The following table
749 shows the bitplane data arrangement within each nibble based on the picture
752 Picture Type Bit3 Bit2 Bit1 Bit0
753 I or BI OVERFLAGS ACPRED FIELDTX
754 P MYTYPEMB SKIPMB DIRECTMB
755 B FORWARDMB SKIPMB DIRECTMB
757 Within each byte, the lower nibble is for the first MB and the upper nibble is
758 for the second MB. E.g. the lower nibble of the first byte in the bitplane
759 buffer is for Macroblock #1 and the upper nibble of the first byte is for
760 Macroblock #2 in the first row.
763 /* VC-1 Slice Parameter Buffer */
764 typedef struct _VASliceParameterBufferVC1
766 unsigned int slice_data_size;/* number of bytes in the slice data buffer for this slice */
767 unsigned int slice_data_offset;/* the offset to the first byte of slice data */
768 unsigned int slice_data_flag; /* see VA_SLICE_DATA_FLAG_XXX defintions */
769 unsigned int macroblock_offset;/* the offset to the first bit of MB from the first byte of slice data */
770 unsigned int slice_vertical_position;
771 } VASliceParameterBufferVC1;
773 /* VC-1 Slice Data Buffer */
775 This is simplely a buffer containing raw bit-stream bytes
778 /****************************
779 * H.264/AVC data structures
780 ****************************/
782 typedef struct _VAPictureH264
784 VASurfaceID picture_id;
786 unsigned int TopFieldOrderCnt;
787 unsigned int BottomFieldOrderCnt;
789 /* flags in VAPictureH264 could be OR of the following */
790 #define VA_PICTURE_H264_INVALID 0x00000001
791 #define VA_PICTURE_H264_TOP_FIELD 0x00000002
792 #define VA_PICTURE_H264_BOTTOM_FIELD 0x00000004
793 #define VA_PICTURE_H264_SHORT_TERM_REFERENCE 0x00000008
794 #define VA_PICTURE_H264_LONG_TERM_REFERENCE 0x00000010
796 /* H.264 Picture Parameter Buffer */
798 * For each picture, and before any slice data, a single
799 * picture parameter buffer must be send.
801 typedef struct _VAPictureParameterBufferH264
803 VAPictureH264 CurrPic;
804 VAPictureH264 ReferenceFrames[16]; /* in DPB */
805 unsigned short picture_width_in_mbs_minus1;
806 unsigned short picture_height_in_mbs_minus1;
807 unsigned char bit_depth_luma_minus8;
808 unsigned char bit_depth_chroma_minus8;
809 unsigned char num_ref_frames;
812 unsigned char chroma_format_idc : 2;
813 unsigned char residual_colour_transform_flag : 1;
814 unsigned char frame_mbs_only_flag : 1;
815 unsigned char mb_adaptive_frame_field_flag : 1;
816 unsigned char direct_8x8_inference_flag : 1;
817 unsigned char MinLumaBiPredSize8x8 : 1; /* see A.3.3.2 */
819 unsigned char seq_fields;
821 unsigned char num_slice_groups_minus1;
822 unsigned char slice_group_map_type;
823 unsigned char pic_init_qp_minus26;
824 unsigned char chroma_qp_index_offset;
825 unsigned char second_chroma_qp_index_offset;
828 unsigned char entropy_coding_mode_flag : 1;
829 unsigned char weighted_pred_flag : 1;
830 unsigned char weighted_bipred_idc : 1;
831 unsigned char transform_8x8_mode_flag : 1;
832 unsigned char field_pic_flag : 1;
833 unsigned char constrained_intra_pred_flag : 1;
835 unsigned char pic_fields;
837 unsigned short frame_num;
838 } VAPictureParameterBufferH264;
840 /* H.264 Inverse Quantization Matrix Buffer */
841 typedef struct _VAIQMatrixBufferH264
843 unsigned char ScalingList4x4[6][16];
844 unsigned char ScalingList8x8[2][64];
845 } VAIQMatrixBufferH264;
848 * H.264 Slice Group Map Buffer
849 * When VAPictureParameterBufferH264::num_slice_group_minus1 is not equal to 0,
850 * A slice group map buffer should be sent for each picture if required. The buffer
851 * is sent only when there is a change in the mapping values.
852 * The slice group map buffer map "map units" to slice groups as specified in
853 * section 8.2.2 of the H.264 spec. The buffer will contain one byte for each macroblock
854 * in raster scan order
857 /* H.264 Slice Parameter Buffer */
858 typedef struct _VASliceParameterBufferH264
860 unsigned int slice_data_size;/* number of bytes in the slice data buffer for this slice */
861 unsigned int slice_data_offset;/* the offset to first byte of slice data */
862 unsigned int slice_data_flag; /* see VA_SLICE_DATA_FLAG_XXX defintions */
863 unsigned short slice_data_bit_offset; /* bit offset in the first byte of valid data */
864 unsigned short first_mb_in_slice;
865 unsigned char slice_type;
866 unsigned char direct_spatial_mv_pred_flag;
867 unsigned char num_ref_idx_l0_active_minus1;
868 unsigned char num_ref_idx_l1_active_minus1;
869 unsigned char cabac_init_idc;
871 unsigned char disable_deblocking_filter_idc;
872 char slice_alpha_c0_offset_div2;
873 char slice_beta_offset_div2;
874 VAPictureH264 RefPicList0[32]; /* See 8.2.4.2 */
875 VAPictureH264 RefPicList1[32]; /* See 8.2.4.2 */
876 unsigned char luma_log2_weight_denom;
877 unsigned char chroma_log2_weight_denom;
878 unsigned char luma_weight_l0_flag;
879 short luma_weight_l0[32];
880 short luma_offset_l0[32];
881 unsigned char chroma_weight_l0_flag;
882 short chroma_weight_l0[32][2];
883 short chroma_offset_l0[32][2];
884 unsigned char luma_weight_l1_flag;
885 short luma_weight_l1[32];
886 short luma_offset_l1[32];
887 unsigned char chroma_weight_l1_flag;
888 short chroma_weight_l1[32][2];
889 short chroma_offset_l1[32][2];
890 } VASliceParameterBufferH264;
892 /* Buffer functions */
895 * Creates a buffer for storing a certain type of data, no data store allocated
897 VAStatus vaCreateBuffer (
899 VABufferType type, /* in */
900 VABufferID *buf_id /* out */
904 * Create data store for the buffer and initalize with "data".
905 * if "data" is null, then the contents of the buffer data store
907 * Basically there are two ways to get buffer data to the server side. One is
908 * to call vaBufferData() with a non-null "data", which results the data being
909 * copied to the data store on the server side. A different method that
910 * eliminates this copy is to pass null as "data" when calling vaBufferData(),
911 * and then use vaMapBuffer() to map the data store from the server side to the
912 * client address space for access.
914 VAStatus vaBufferData (
916 VABufferID buf_id, /* in */
917 unsigned int size, /* in */
918 unsigned int num_elements, /* in */
923 * Convey to the server how many valid elements are in the buffer.
924 * e.g. if multiple slice parameters are being held in a single buffer,
925 * this will communicate to the server the number of slice parameters
926 * that are valid in the buffer.
928 VAStatus vaBufferSetNumElements (
930 VABufferID buf_id, /* in */
931 unsigned int num_elements /* in */
935 * Map data store of the buffer into the client's address space
936 * vaBufferData() needs to be called with "data" set to NULL before
937 * calling vaMapBuffer()
939 VAStatus vaMapBuffer (
941 VABufferID buf_id, /* in */
942 void **pbuf /* out */
946 * After client making changes to a mapped data store, it needs to
947 * "Unmap" it to let the server know that the data is ready to be
948 * consumed by the server
950 VAStatus vaUnmapBuffer (
952 VABufferID buf_id /* in */
956 * After this call, the buffer is deleted and this buffer_id is no longer valid
958 VAStatus vaDestroyBuffer (
964 Render (Decode) Pictures
966 A picture represents either a frame or a field.
968 The Begin/Render/End sequence sends the decode buffers to the server
972 * Get ready to decode a picture to a target surface
974 VAStatus vaBeginPicture (
977 VASurface *render_target
981 * Send decode buffers to the server.
983 VAStatus vaRenderPicture (
991 * Make the end of rendering for a picture.
992 * The server should start processing all pending operations for this
993 * surface. This call is non-blocking. The client can start another
994 * Begin/Render/End sequence on a different render target.
996 VAStatus vaEndPicture (
1008 * This function blocks until all pending operations on the render target
1009 * have been completed. Upon return it is safe to use the render target for a
1010 * different picture.
1012 VAStatus vaSyncSurface (
1015 VASurface *render_target
1020 VASurfaceRendering = 0, /* Rendering in progress */
1021 VASurfaceDisplaying = 1, /* Displaying in progress (not safe to render into it) */
1022 /* this status is useful if surface is used as the source */
1024 VASurfaceReady = 2 /* not being rendered or displayed */
1028 * Find out any pending ops on the render target
1030 VAStatus vaQuerySurfaceStatus (
1033 VASurface *render_target,
1034 VASurfaceStatus *status /* out */
1039 * Copies the surface to a buffer
1040 * The stride of the surface will be stored in *stride
1041 * Caller should free the returned buffer with free() when done.
1043 VAStatus vaDbgCopySurfaceToBuffer(VADisplay dpy,
1045 void **buffer, /* out */
1046 unsigned int *stride /* out */
1050 * Images and Subpictures
1051 * VAImage is used to either get the surface data to client memory, or
1052 * to copy image data in client memory to a surface.
1053 * Both images, subpictures and surfaces follow the same 2D coordinate system where origin
1054 * is at the upper left corner with positive X to the right and positive Y down
1056 #define MAKEFOURCC(ch0, ch1, ch2, ch3) \
1057 ((unsigned long)(unsigned char) (ch0) | ((unsigned long)(unsigned char) (ch1) << 8) | \
1058 ((unsigned long)(unsigned char) (ch2) << 16) | ((unsigned long)(unsigned char) (ch3) << 24 ))
1060 /* a few common FourCCs */
1061 #define VA_FOURCC_NV12 0x3231564E
1062 #define VA_FOURCC_AI44 0x34344149
1063 #define VA_FOURCC_RGBA 0x41424752
1065 typedef struct _VAImageFormat
1067 unsigned int fourcc;
1068 unsigned int byte_order; /* VA_LSB_FIRST, VA_MSB_FIRST */
1069 unsigned int bits_per_pixel;
1070 /* for RGB formats */
1071 unsigned int depth; /* significant bits per pixel */
1072 unsigned int red_mask;
1073 unsigned int green_mask;
1074 unsigned int blue_mask;
1075 unsigned int alpha_mask;
1078 typedef int VAImageID;
1080 typedef struct _VAImage
1082 VAImageID image_id; /* uniquely identify this image */
1083 VAImageFormat format;
1084 VABufferID buf; /* image data buffer */
1086 * Image data will be stored in a buffer of type VAImageBufferType to facilitate
1087 * data store on the server side for optimal performance.
1088 * It is expected that the client will first call vaCreateImage which returns a VAImage
1089 * structure with the following fields filled by the library. It will then
1090 * create the "buf" with vaBufferCreate. For PutImage, then client will call
1091 * vaBufferData() with the image data before calling PutImage, and for GetImage
1092 * the client will call vaBufferData() with a NULL data pointer, and then call GetImage.
1093 * After that the client can use the Map/Unmap buffer functions to access the image data.
1095 unsigned short width;
1096 unsigned short height;
1097 unsigned int data_size;
1098 unsigned int num_planes;
1100 * An array of size num_planes indicating the scanline pitch in bytes.
1101 * Each plane may have a different pitch.
1103 unsigned int *pitches;
1105 * An array of size num_planes indicating the byte offset from
1106 * the beginning of the image data to the start of each plane.
1108 unsigned int *offsets;
1111 /* Get maximum number of image formats supported by the implementation */
1112 int vaMaxNumImageFormats (
1117 * Query supported image formats
1118 * The caller must provide a "format_list" array that can hold at
1119 * least vaMaxNumImageFormats() entries. The actual number of formats
1120 * returned in "format_list" is returned in "num_formats".
1122 VAStatus vaQueryImageFormats (
1124 VAImageFormat *format_list, /* out */
1125 int *num_formats /* out */
1129 * Create a VAImage structure
1130 * The width and height fields returned in the VAImage structure may get
1131 * enlarged for some YUV formats. The size of the data buffer that needs
1132 * to be allocated will be given in the "data_size" field in VAImage.
1133 * Image data is not allocated by this function. The client should
1134 * allocate the memory required for the data and fill in the data field after
1135 * looking at "data_size" returned from this call.
1137 VAStatus vaCreateImage (
1139 VAImageFormat *format,
1142 VAImage *image /* out */
1146 * Should call DestroyImage before destroying the surface it is bound to
1148 VAStatus vaDestroyImage (
1154 * Retrive surface data into a VAImage
1155 * Image must be in a format supported by the implementation
1157 VAStatus vaGetImage (
1160 int x, /* coordinates of the upper left source pixel */
1162 unsigned int width, /* width and height of the region */
1163 unsigned int height,
1168 * Copy data from a VAImage to a surface
1169 * Image must be in a format supported by the implementation
1171 VAStatus vaPutImage (
1178 unsigned int height,
1185 * Subpicture is a special type of image that can be blended
1186 * with a surface during vaPutSurface(). Subpicture can be used to render
1187 * DVD sub-titles or closed captioning text etc.
1190 typedef int VASubpictureID;
1192 typedef struct _VASubpicture
1194 VASubpictureID subpicture_id; /* uniquely identify this subpicture */
1195 VASurfaceID surface_id; /* which surface does this subpicture associate with */
1197 /* The following fields are set by the library */
1198 int num_palette_entries; /* paletted formats only. set to zero for image without palettes */
1200 * Each component is one byte and entry_bytes indicates the number of components in
1201 * each entry (eg. 3 for YUV palette entries). set to zero for image without palettes
1205 * An array of ascii characters describing teh order of the components within the bytes.
1206 * Only entry_bytes characters of the string are used.
1208 char component_order[4];
1210 /* chromakey range */
1211 unsigned int chromakey_min;
1212 unsigned int chromakey_max;
1215 unsigned int global_alpha;
1218 unsigned int flags; /* see below */
1221 /* flags for subpictures */
1222 #define VA_SUBPICTURE_CHROMA_KEYING 0x0001
1223 #define VA_SUBPICTURE_GLOBAL_ALPHA 0x0002
1225 /* Get maximum number of subpicture formats supported by the implementation */
1226 int vaMaxNumSubpictureFormats (
1231 * Query supported subpicture formats
1232 * The caller must provide a "format_list" array that can hold at
1233 * least vaMaxNumSubpictureFormats() entries. The flags arrary holds the flag
1234 * for each format to indicate additional capabilities for that format. The actual
1235 * number of formats returned in "format_list" is returned in "num_formats".
1237 VAStatus vaQuerySubpictureFormats (
1239 VAImageFormat *format_list, /* out */
1240 unsigned int *flags, /* out */
1241 unsigned int *num_formats /* out */
1245 * Subpictures are created with an image associated.
1247 VAStatus vaCreateSubpicture (
1250 VASubpicture *subpicture /* out */
1254 * Destroy the subpicture before destroying the image it is assocated to
1256 VAStatus vaDestroySubpicture (
1258 VASubpicture *subpicture
1262 * Bind an image to the subpicture. This image will now be associated with
1263 * the subpicture instead of the one at creation.
1265 VAStatus vaSetSubpictureImage (
1267 VASubpicture *subpicture,
1271 VAStatus vaSetSubpicturePalette (
1273 VASubpicture *subpicture,
1275 * pointer to an array holding the palette data. The size of the array is
1276 * num_palette_entries * entry_bytes in size. The order of the components
1277 * in the palette is described by the component_order in VASubpicture struct
1279 unsigned char *palette
1283 * If chromakey is enabled, then the area where the source value falls within
1284 * the chromakey [min, max] range is transparent
1286 VAStatus vaSetSubpictureChromakey (
1288 VASubpicture *subpicture,
1289 unsigned int chromakey_min,
1290 unsigned int chromakey_max
1294 * Global alpha value is between 0 and 1. A value of 1 means fully opaque and
1295 * a value of 0 means fully transparent. If per-pixel alpha is also specified then
1296 * the overall alpha is per-pixel alpha multiplied by the global alpha
1298 VAStatus vaSetSubpictureGlobalAlpha (
1300 VASubpicture *subpicture,
1305 vaAssociateSubpicture associates the subpicture with the target_surface.
1306 It defines the region mapping between the subpicture and the target
1307 surface through source and destination rectangles (with the same width and height).
1308 Both will be displayed at the next call to vaPutSurface. Additional
1309 associations before the call to vaPutSurface simply overrides the association.
1311 VAStatus vaAssociateSubpicture (
1313 VASurface *target_surface,
1314 VASubpicture *subpicture,
1315 short src_x, /* upper left offset in subpicture */
1317 short dest_x, /* upper left offset in surface */
1319 unsigned short width,
1320 unsigned short height,
1322 * whether to enable chroma-keying or global-alpha
1323 * see VA_SUBPICTURE_XXX values
1328 typedef struct _VARectangle
1332 unsigned short width;
1333 unsigned short height;
1343 /*****************************************************************************/
1345 Sample Program (w/ pseudo code)
1347 Mostly to demonstrate program flow with no error handling ...
1349 /*****************************************************************************/
1351 /* MPEG-2 VLD decode for a 720x480 frame */
1353 int major_ver, minor_ver;
1354 vaInitialize(dpy, &major_ver, &minor_ver);
1356 int max_num_profiles, max_num_entrypoints, max_num_attribs;
1357 max_num_profiles = vaMaxNumProfiles(dpy);
1358 max_num_entrypoints = vaMaxNumProfiles(dpy);
1359 max_num_attribs = vaMaxNumProfiles(dpy);
1361 /* find out whether MPEG2 MP is supported */
1362 VAProfile *profiles = malloc(sizeof(VAProfile)*max_num_profiles);
1364 vaQueryConfigProfiles(dpy, profiles, &profiles);
1366 * traverse "profiles" to locate the one that matches VAProfileMPEG2Main
1369 /* now get the available entrypoints for MPEG2 MP */
1370 VAEntrypoint *entrypoints = malloc(sizeof(VAEntrypoint)*max_num_entrypoints);
1371 int num_entrypoints;
1372 vaQueryConfigEntrypoints(dpy, VAProfileMPEG2Main, entrypoints, &num_entrypoints);
1374 /* traverse "entrypoints" to see whether VLD is there */
1376 /* Assuming finding VLD, find out the format for the render target */
1377 VAConfigAttrib attrib;
1378 attrib.type = VAConfigAttribRTFormat;
1379 vaQueryConfigAttributes(dpy, VAProfileMPEG2Main, VAEntrypointVLD,
1382 if (attrib.value & VA_RT_FORMAT_YUV420)
1383 /* Found desired RT format, keep going */
1385 VAConfigID config_id;
1386 vaCreateConfig(dpy, VAProfileMPEG2Main, VAEntrypointVLD, &attrib, 1,
1390 * create surfaces for the current target as well as reference frames
1391 * we can get by with 4 surfaces for MPEG-2
1393 VASurface surfaces[4];
1394 vaCreateSurfaces(dpy, 720, 480, VA_RT_FORMAT_YUV420, 4, surfaces);
1397 * Create a context for this decode pipe
1400 vaCreateContext(dpy, config_id, 720, 480, VA_PROGRESSIVE, surfaces,
1403 /* Create a picture parameter buffer for this frame */
1404 VABufferID picture_buf;
1405 VAPictureParameterBufferMPEG2 *picture_param;
1406 vaCreateBuffer(dpy, VAPictureParameterBufferType, &picture_buf);
1407 vaBufferData(dpy, picture_buf, sizeof(VAPictureParameterBufferMPEG2), NULL);
1408 vaMapBuffer(dpy, picture_buf, &picture_param);
1409 picture_param->horizontal_size = 720;
1410 picture_param->vertical_size = 480;
1411 picture_param->picture_coding_type = 1; /* I-frame */
1412 /* fill in picture_coding_extension fields here */
1413 vaUnmapBuffer(dpy, picture_buf);
1416 /* Create an IQ matrix buffer for this frame */
1418 VAIQMatrixBufferMPEG2 *iq_matrix;
1419 vaCreateBuffer(dpy, VAIQMatrixBufferType, &iq_buf);
1420 vaBufferData(dpy, iq_buf, sizeof(VAIQMatrixBufferMPEG2), NULL);
1421 vaMapBuffer(dpy, iq_buf, &iq_matrix);
1422 /* fill values for IQ_matrix here */
1423 vaUnmapBuffer(dpy, iq_buf);
1425 /* send the picture and IQ matrix buffers to the server */
1426 vaBeginPicture(dpy, context, &surfaces[0]);
1428 vaRenderPicture(dpy, context, &picture_buf, 1);
1429 vaRenderPicture(dpy, context, &iq_buf, 1);
1432 * Send slices in this frame to the server.
1433 * For MPEG-2, each slice is one row of macroblocks, and
1434 * we have 30 slices for a 720x480 frame
1436 for (int i = 1; i <= 30; i++) {
1438 /* Create a slice parameter buffer */
1439 VABufferID slice_param_buf;
1440 VASliceParameterBufferMPEG2 *slice_param;
1441 vaCreateBuffer(dpy, VASliceParameterBufferType, &slice_param_buf);
1442 vaBufferData(dpy, slice_param_buf, sizeof(VASliceParameterBufferMPEG2), NULL);
1443 vaMapBuffer(dpy, slice_param_buf, &slice_param);
1444 slice_param->slice_data_offset = 0;
1445 /* Let's say all slices in this bit-stream has 64-bit header */
1446 slice_param->macroblock_offset = 64;
1447 slice_param->vertical_position = i;
1448 /* set up the rest based on what is in the slice header ... */
1449 vaUnmapBuffer(dpy, slice_param_buf);
1451 /* send the slice parameter buffer */
1452 vaRenderPicture(dpy, context, &slice_param_buf, 1);
1454 /* Create a slice data buffer */
1455 unsigned char *slice_data;
1456 VABufferID slice_data_buf;
1457 vaCreateBuffer(dpy, VASliceDataBufferType, slice_data_buf);
1458 vaBufferData(dpy, slice_data_buf, x /* decoder figure out how big */, NULL);
1459 vaMapBuffer(dpy, slice_data_buf, &slice_data);
1460 /* decoder fill in slice_data */
1461 vaUnmapBuffer(dpy, slice_data_buf);
1463 /* send the slice data buffer */
1464 vaRenderPicture(dpy, context, &slice_data_buf, 1);
1467 /* all slices have been sent, mark the end for this frame */
1468 vaEndPicture(dpy, context);
1470 /* The following code demonstrates rendering a sub-title with the target surface */
1471 /* Find out supported Subpicture formats */
1472 VAImageFormat sub_formats[4];
1474 vaQuerySubpictureFormats(dpy, sub_formats, &num_formats);
1475 /* Assume that we find AI44 as a subpicture format in sub_formats[0] */
1477 VASubpicture subpicture;
1478 unsigned char sub_data[128][16];
1479 /* fill sub_data with subtitle in AI44 */
1480 vaCreateImage(dpy, sub_formats, 128, 16,&sub_image);
1481 vaCreateSubpicture(dpy, &sub_image, &subpicture);
1482 unsigned char palette[3][16];
1483 /* fill the palette data */
1484 vaSetSubpicturePalette(dpy, &subpicture, palette);
1485 vaAssociateSubpicture(dpy, surfaces, &subpicture, 0, 0, 296, 400, 128, 16);
1486 vaPutSurface(dpy, surfaces, win, 0, 0, 720, 480, 100, 100, 640, 480, NULL, 0, 0);