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.
28 #include "va_backend.h"
29 #include "va_backend_vpp.h"
41 #define DRIVER_EXTENSION "_drv_video.so"
43 #define CTX(dpy) (((VADisplayContextP)dpy)->pDriverContext)
44 #define CHECK_DISPLAY(dpy) if( !vaDisplayIsValid(dpy) ) { return VA_STATUS_ERROR_INVALID_DISPLAY; }
47 #define CHECK_VTABLE(s, ctx, func) if (!va_checkVtable(ctx->vtable->va##func, #func)) s = VA_STATUS_ERROR_UNKNOWN;
48 #define CHECK_MAXIMUM(s, ctx, var) if (!va_checkMaximum(ctx->max_##var, #var)) s = VA_STATUS_ERROR_UNKNOWN;
49 #define CHECK_STRING(s, ctx, var) if (!va_checkString(ctx->str_##var, #var)) s = VA_STATUS_ERROR_UNKNOWN;
52 * read a config "env" for libva.conf or from environment setting
53 * liva.conf has higher priority
54 * return 0: the "env" is set, and the value is copied into env_value
55 * 1: the env is not set
57 int va_parseConfig(char *env, char *env_value)
59 char *token, *value, *saveptr;
66 fp = fopen("/etc/libva.conf", "r");
67 while (fp && (fgets(oneline, 1024, fp) != NULL)) {
68 if (strlen(oneline) == 1)
70 token = strtok_r(oneline, "=\n", &saveptr);
71 value = strtok_r(NULL, "=\n", &saveptr);
73 if (NULL == token || NULL == value)
76 if (strcmp(token, env) == 0) {
78 strncpy(env_value,value, 1024);
88 /* no setting in config file, use env setting */
91 strncpy(env_value, getenv(env), 1024);
99 int vaDisplayIsValid(VADisplay dpy)
101 VADisplayContextP pDisplayContext = (VADisplayContextP)dpy;
102 return pDisplayContext && (pDisplayContext->vadpy_magic == VA_DISPLAY_MAGIC) && pDisplayContext->vaIsValid(pDisplayContext);
105 void va_errorMessage(const char *msg, ...)
107 char buf[512], *dynbuf;
112 len = vsnprintf(buf, sizeof(buf), msg, args);
115 if (len >= (int)sizeof(buf)) {
116 dynbuf = malloc(len + 1);
120 n = vsnprintf(dynbuf, len + 1, msg, args);
123 va_log_error(dynbuf);
130 void va_infoMessage(const char *msg, ...)
132 char buf[512], *dynbuf;
137 len = vsnprintf(buf, sizeof(buf), msg, args);
140 if (len >= (int)sizeof(buf)) {
141 dynbuf = malloc(len + 1);
145 n = vsnprintf(dynbuf, len + 1, msg, args);
155 static bool va_checkVtable(void *ptr, char *function)
158 va_errorMessage("No valid vtable entry for va%s\n", function);
164 static bool va_checkMaximum(int value, char *variable)
167 va_errorMessage("Failed to define max_%s in init\n", variable);
173 static bool va_checkString(const char* value, char *variable)
176 va_errorMessage("Failed to define str_%s in init\n", variable);
183 va_getDriverInitName(char *name, int namelen, int major, int minor)
185 int ret = snprintf(name, namelen, "__vaDriverInit_%d_%d", major, minor);
186 return ret > 0 && ret < namelen;
189 static VAStatus va_getDriverName(VADisplay dpy, char **driver_name)
191 VADisplayContextP pDisplayContext = (VADisplayContextP)dpy;
193 return pDisplayContext->vaGetDriverName(pDisplayContext, driver_name);
196 static VAStatus va_openDriver(VADisplay dpy, char *driver_name)
198 VADriverContextP ctx = CTX(dpy);
199 VAStatus vaStatus = VA_STATUS_ERROR_UNKNOWN;
200 char *search_path = NULL;
204 if (geteuid() == getuid())
205 /* don't allow setuid apps to use LIBVA_DRIVERS_PATH */
206 search_path = getenv("LIBVA_DRIVERS_PATH");
208 search_path = VA_DRIVERS_PATH;
210 search_path = strdup((const char *)search_path);
211 driver_dir = strtok_r(search_path, ":", &saveptr);
214 char *driver_path = (char *) malloc( strlen(driver_dir) +
215 strlen(driver_name) +
216 strlen(DRIVER_EXTENSION) + 2 );
217 strncpy( driver_path, driver_dir, strlen(driver_dir) + 1);
218 strncat( driver_path, "/", strlen("/") );
219 strncat( driver_path, driver_name, strlen(driver_name) );
220 strncat( driver_path, DRIVER_EXTENSION, strlen(DRIVER_EXTENSION) );
222 va_infoMessage("Trying to open %s\n", driver_path);
224 handle = dlopen( driver_path, RTLD_NOW | RTLD_GLOBAL | RTLD_NODELETE );
226 handle = dlopen( driver_path, RTLD_NOW| RTLD_GLOBAL);
229 /* Don't give errors for non-existing files */
230 if (0 == access( driver_path, F_OK))
231 va_errorMessage("dlopen of %s failed: %s\n", driver_path, dlerror());
233 VADriverInit init_func = NULL;
234 char init_func_s[256];
237 static const struct {
240 } compatible_versions[] = {
241 { VA_MAJOR_VERSION, VA_MINOR_VERSION },
247 for (i = 0; compatible_versions[i].major >= 0; i++) {
248 if (va_getDriverInitName(init_func_s, sizeof(init_func_s),
249 compatible_versions[i].major,
250 compatible_versions[i].minor)) {
251 init_func = (VADriverInit)dlsym(handle, init_func_s);
253 va_infoMessage("Found init function %s\n", init_func_s);
259 if (compatible_versions[i].major < 0) {
260 va_errorMessage("%s has no function %s\n",
261 driver_path, init_func_s);
264 struct VADriverVTable *vtable = ctx->vtable;
265 struct VADriverVTableVPP *vtable_vpp = ctx->vtable_vpp;
267 vaStatus = VA_STATUS_SUCCESS;
269 vtable = calloc(1, sizeof(*vtable));
271 vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED;
273 ctx->vtable = vtable;
276 vtable_vpp = calloc(1, sizeof(*vtable_vpp));
278 vtable_vpp->version = VA_DRIVER_VTABLE_VPP_VERSION;
280 vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED;
282 ctx->vtable_vpp = vtable_vpp;
284 if (VA_STATUS_SUCCESS == vaStatus)
285 vaStatus = (*init_func)(ctx);
287 if (VA_STATUS_SUCCESS == vaStatus) {
288 CHECK_MAXIMUM(vaStatus, ctx, profiles);
289 CHECK_MAXIMUM(vaStatus, ctx, entrypoints);
290 CHECK_MAXIMUM(vaStatus, ctx, attributes);
291 CHECK_MAXIMUM(vaStatus, ctx, image_formats);
292 CHECK_MAXIMUM(vaStatus, ctx, subpic_formats);
293 CHECK_MAXIMUM(vaStatus, ctx, display_attributes);
294 CHECK_STRING(vaStatus, ctx, vendor);
295 CHECK_VTABLE(vaStatus, ctx, Terminate);
296 CHECK_VTABLE(vaStatus, ctx, QueryConfigProfiles);
297 CHECK_VTABLE(vaStatus, ctx, QueryConfigEntrypoints);
298 CHECK_VTABLE(vaStatus, ctx, QueryConfigAttributes);
299 CHECK_VTABLE(vaStatus, ctx, CreateConfig);
300 CHECK_VTABLE(vaStatus, ctx, DestroyConfig);
301 CHECK_VTABLE(vaStatus, ctx, GetConfigAttributes);
302 CHECK_VTABLE(vaStatus, ctx, CreateSurfaces);
303 CHECK_VTABLE(vaStatus, ctx, DestroySurfaces);
304 CHECK_VTABLE(vaStatus, ctx, CreateContext);
305 CHECK_VTABLE(vaStatus, ctx, DestroyContext);
306 CHECK_VTABLE(vaStatus, ctx, CreateBuffer);
307 CHECK_VTABLE(vaStatus, ctx, BufferSetNumElements);
308 CHECK_VTABLE(vaStatus, ctx, MapBuffer);
309 CHECK_VTABLE(vaStatus, ctx, UnmapBuffer);
310 CHECK_VTABLE(vaStatus, ctx, DestroyBuffer);
311 CHECK_VTABLE(vaStatus, ctx, BeginPicture);
312 CHECK_VTABLE(vaStatus, ctx, RenderPicture);
313 CHECK_VTABLE(vaStatus, ctx, EndPicture);
314 CHECK_VTABLE(vaStatus, ctx, SyncSurface);
315 CHECK_VTABLE(vaStatus, ctx, QuerySurfaceStatus);
316 CHECK_VTABLE(vaStatus, ctx, PutSurface);
317 CHECK_VTABLE(vaStatus, ctx, QueryImageFormats);
318 CHECK_VTABLE(vaStatus, ctx, CreateImage);
319 CHECK_VTABLE(vaStatus, ctx, DeriveImage);
320 CHECK_VTABLE(vaStatus, ctx, DestroyImage);
321 CHECK_VTABLE(vaStatus, ctx, SetImagePalette);
322 CHECK_VTABLE(vaStatus, ctx, GetImage);
323 CHECK_VTABLE(vaStatus, ctx, PutImage);
324 CHECK_VTABLE(vaStatus, ctx, QuerySubpictureFormats);
325 CHECK_VTABLE(vaStatus, ctx, CreateSubpicture);
326 CHECK_VTABLE(vaStatus, ctx, DestroySubpicture);
327 CHECK_VTABLE(vaStatus, ctx, SetSubpictureImage);
328 CHECK_VTABLE(vaStatus, ctx, SetSubpictureChromakey);
329 CHECK_VTABLE(vaStatus, ctx, SetSubpictureGlobalAlpha);
330 CHECK_VTABLE(vaStatus, ctx, AssociateSubpicture);
331 CHECK_VTABLE(vaStatus, ctx, DeassociateSubpicture);
332 CHECK_VTABLE(vaStatus, ctx, QueryDisplayAttributes);
333 CHECK_VTABLE(vaStatus, ctx, GetDisplayAttributes);
334 CHECK_VTABLE(vaStatus, ctx, SetDisplayAttributes);
336 if (VA_STATUS_SUCCESS != vaStatus) {
337 va_errorMessage("%s init failed\n", driver_path);
340 if (VA_STATUS_SUCCESS == vaStatus)
341 ctx->handle = handle;
348 driver_dir = strtok_r(NULL, ":", &saveptr);
356 VAPrivFunc vaGetLibFunc(VADisplay dpy, const char *func)
358 VADriverContextP ctx;
359 if (!vaDisplayIsValid(dpy))
363 if (NULL == ctx->handle)
366 return (VAPrivFunc) dlsym(ctx->handle, func);
371 * Returns a short english description of error_status
373 const char *vaErrorStr(VAStatus error_status)
375 switch(error_status) {
376 case VA_STATUS_SUCCESS:
377 return "success (no error)";
378 case VA_STATUS_ERROR_OPERATION_FAILED:
379 return "operation failed";
380 case VA_STATUS_ERROR_ALLOCATION_FAILED:
381 return "resource allocation failed";
382 case VA_STATUS_ERROR_INVALID_DISPLAY:
383 return "invalid VADisplay";
384 case VA_STATUS_ERROR_INVALID_CONFIG:
385 return "invalid VAConfigID";
386 case VA_STATUS_ERROR_INVALID_CONTEXT:
387 return "invalid VAContextID";
388 case VA_STATUS_ERROR_INVALID_SURFACE:
389 return "invalid VASurfaceID";
390 case VA_STATUS_ERROR_INVALID_BUFFER:
391 return "invalid VABufferID";
392 case VA_STATUS_ERROR_INVALID_IMAGE:
393 return "invalid VAImageID";
394 case VA_STATUS_ERROR_INVALID_SUBPICTURE:
395 return "invalid VASubpictureID";
396 case VA_STATUS_ERROR_ATTR_NOT_SUPPORTED:
397 return "attribute not supported";
398 case VA_STATUS_ERROR_MAX_NUM_EXCEEDED:
399 return "list argument exceeds maximum number";
400 case VA_STATUS_ERROR_UNSUPPORTED_PROFILE:
401 return "the requested VAProfile is not supported";
402 case VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT:
403 return "the requested VAEntryPoint is not supported";
404 case VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT:
405 return "the requested RT Format is not supported";
406 case VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE:
407 return "the requested VABufferType is not supported";
408 case VA_STATUS_ERROR_SURFACE_BUSY:
409 return "surface is in use";
410 case VA_STATUS_ERROR_FLAG_NOT_SUPPORTED:
411 return "flag not supported";
412 case VA_STATUS_ERROR_INVALID_PARAMETER:
413 return "invalid parameter";
414 case VA_STATUS_ERROR_RESOLUTION_NOT_SUPPORTED:
415 return "resolution not supported";
416 case VA_STATUS_ERROR_UNIMPLEMENTED:
417 return "the requested function is not implemented";
418 case VA_STATUS_ERROR_SURFACE_IN_DISPLAYING:
419 return "surface is in displaying (may by overlay)" ;
420 case VA_STATUS_ERROR_INVALID_IMAGE_FORMAT:
421 return "invalid VAImageFormat";
422 case VA_STATUS_ERROR_UNKNOWN:
423 return "unknown libva error";
425 return "unknown libva error / description missing";
428 VAStatus vaInitialize (
430 int *major_version, /* out */
431 int *minor_version /* out */
434 const char *driver_name_env = NULL;
435 char *driver_name = NULL;
444 va_infoMessage("VA-API version %s\n", VA_VERSION_S);
446 driver_name_env = getenv("LIBVA_DRIVER_NAME");
447 if (driver_name_env && geteuid() == getuid()) {
448 /* Don't allow setuid apps to use LIBVA_DRIVER_NAME */
449 driver_name = strdup(driver_name_env);
450 vaStatus = VA_STATUS_SUCCESS;
451 va_infoMessage("User requested driver '%s'\n", driver_name);
453 vaStatus = va_getDriverName(dpy, &driver_name);
454 va_infoMessage("va_getDriverName() returns %d\n", vaStatus);
457 if (VA_STATUS_SUCCESS == vaStatus) {
458 vaStatus = va_openDriver(dpy, driver_name);
459 va_infoMessage("va_openDriver() returns %d\n", vaStatus);
461 *major_version = VA_MAJOR_VERSION;
462 *minor_version = VA_MINOR_VERSION;
468 VA_TRACE_LOG(va_TraceInitialize, dpy, major_version, minor_version);
475 * After this call, all library internal resources will be cleaned up
477 VAStatus vaTerminate (
481 VAStatus vaStatus = VA_STATUS_SUCCESS;
482 VADisplayContextP pDisplayContext = (VADisplayContextP)dpy;
483 VADriverContextP old_ctx;
488 if (old_ctx->handle) {
489 vaStatus = old_ctx->vtable->vaTerminate(old_ctx);
490 dlclose(old_ctx->handle);
491 old_ctx->handle = NULL;
493 free(old_ctx->vtable);
494 old_ctx->vtable = NULL;
495 free(old_ctx->vtable_vpp);
496 old_ctx->vtable_vpp = NULL;
498 if (VA_STATUS_SUCCESS == vaStatus)
499 pDisplayContext->vaDestroy(pDisplayContext);
501 VA_TRACE_LOG(va_TraceTerminate, dpy);
511 * vaQueryVendorString returns a pointer to a zero-terminated string
512 * describing some aspects of the VA implemenation on a specific
513 * hardware accelerator. The format of the returned string is:
514 * <vendorname>-<major_version>-<minor_version>-<addtional_info>
515 * e.g. for the Intel GMA500 implementation, an example would be:
516 * "IntelGMA500-1.0-0.2-patch3
518 const char *vaQueryVendorString (
522 if (!vaDisplayIsValid(dpy))
525 return CTX(dpy)->str_vendor;
529 /* Get maximum number of profiles supported by the implementation */
530 int vaMaxNumProfiles (
534 if (!vaDisplayIsValid(dpy))
537 return CTX(dpy)->max_profiles;
540 /* Get maximum number of entrypoints supported by the implementation */
541 int vaMaxNumEntrypoints (
545 if (!vaDisplayIsValid(dpy))
548 return CTX(dpy)->max_entrypoints;
552 /* Get maximum number of attributs supported by the implementation */
553 int vaMaxNumConfigAttributes (
557 if (!vaDisplayIsValid(dpy))
560 return CTX(dpy)->max_attributes;
563 VAStatus vaQueryConfigEntrypoints (
566 VAEntrypoint *entrypoints, /* out */
567 int *num_entrypoints /* out */
570 VADriverContextP ctx;
574 return ctx->vtable->vaQueryConfigEntrypoints ( ctx, profile, entrypoints, num_entrypoints);
577 VAStatus vaGetConfigAttributes (
580 VAEntrypoint entrypoint,
581 VAConfigAttrib *attrib_list, /* in/out */
585 VADriverContextP ctx;
589 return ctx->vtable->vaGetConfigAttributes ( ctx, profile, entrypoint, attrib_list, num_attribs );
592 VAStatus vaQueryConfigProfiles (
594 VAProfile *profile_list, /* out */
595 int *num_profiles /* out */
598 VADriverContextP ctx;
602 return ctx->vtable->vaQueryConfigProfiles ( ctx, profile_list, num_profiles );
605 VAStatus vaCreateConfig (
608 VAEntrypoint entrypoint,
609 VAConfigAttrib *attrib_list,
611 VAConfigID *config_id /* out */
614 VADriverContextP ctx;
615 VAStatus vaStatus = VA_STATUS_SUCCESS;
621 vaStatus = ctx->vtable->vaCreateConfig ( ctx, profile, entrypoint, attrib_list, num_attribs, config_id );
623 /* record the current entrypoint for further trace/fool determination */
624 VA_TRACE_FUNC(va_TraceCreateConfig, dpy, profile, entrypoint, attrib_list, num_attribs, config_id);
625 VA_FOOL_FUNC(va_FoolCreateConfig, dpy, profile, entrypoint, attrib_list, num_attribs, config_id);
630 VAStatus vaDestroyConfig (
635 VADriverContextP ctx;
639 return ctx->vtable->vaDestroyConfig ( ctx, config_id );
642 VAStatus vaQueryConfigAttributes (
644 VAConfigID config_id,
645 VAProfile *profile, /* out */
646 VAEntrypoint *entrypoint, /* out */
647 VAConfigAttrib *attrib_list,/* out */
648 int *num_attribs /* out */
651 VADriverContextP ctx;
655 return ctx->vtable->vaQueryConfigAttributes( ctx, config_id, profile, entrypoint, attrib_list, num_attribs);
659 vaGetSurfaceAttributes(
662 VASurfaceAttrib *attrib_list,
663 unsigned int num_attribs
666 VADriverContextP ctx;
672 return VA_STATUS_ERROR_INVALID_DISPLAY;
674 if (!ctx->vtable->vaGetSurfaceAttributes)
675 return VA_STATUS_ERROR_UNIMPLEMENTED;
677 vaStatus = ctx->vtable->vaGetSurfaceAttributes(ctx, config,
678 attrib_list, num_attribs);
688 VASurfaceID *surfaces,
689 unsigned int num_surfaces,
690 VASurfaceAttrib *attrib_list,
691 unsigned int num_attribs
694 VADriverContextP ctx;
700 return VA_STATUS_ERROR_INVALID_DISPLAY;
702 if (ctx->vtable->vaCreateSurfaces2)
703 return ctx->vtable->vaCreateSurfaces2(ctx, format, width, height,
704 surfaces, num_surfaces,
705 attrib_list, num_attribs);
707 if (attrib_list && num_attribs > 0)
708 return VA_STATUS_ERROR_ATTR_NOT_SUPPORTED;
710 vaStatus = ctx->vtable->vaCreateSurfaces(ctx, width, height, format,
711 num_surfaces, surfaces);
713 VA_TRACE_LOG(va_TraceCreateSurface,
714 dpy, width, height, format, num_surfaces, surfaces);
720 VAStatus vaDestroySurfaces (
722 VASurfaceID *surface_list,
726 VADriverContextP ctx;
730 return ctx->vtable->vaDestroySurfaces( ctx, surface_list, num_surfaces );
733 VAStatus vaCreateContext (
735 VAConfigID config_id,
739 VASurfaceID *render_targets,
740 int num_render_targets,
741 VAContextID *context /* out */
744 VADriverContextP ctx;
750 vaStatus = ctx->vtable->vaCreateContext( ctx, config_id, picture_width, picture_height,
751 flag, render_targets, num_render_targets, context );
753 /* keep current encode/decode resoluton */
754 VA_TRACE_FUNC(va_TraceCreateContext, dpy, config_id, picture_width, picture_height, flag, render_targets, num_render_targets, context);
759 VAStatus vaDestroyContext (
764 VADriverContextP ctx;
768 return ctx->vtable->vaDestroyContext( ctx, context );
771 VAStatus vaCreateBuffer (
773 VAContextID context, /* in */
774 VABufferType type, /* in */
775 unsigned int size, /* in */
776 unsigned int num_elements, /* in */
778 VABufferID *buf_id /* out */
781 VADriverContextP ctx;
786 VA_FOOL_FUNC(va_FoolCreateBuffer, dpy, context, type, size, num_elements, data, buf_id);
788 return VA_STATUS_SUCCESS;
790 return ctx->vtable->vaCreateBuffer( ctx, context, type, size, num_elements, data, buf_id);
793 VAStatus vaBufferSetNumElements (
795 VABufferID buf_id, /* in */
796 unsigned int num_elements /* in */
799 VADriverContextP ctx;
805 return ctx->vtable->vaBufferSetNumElements( ctx, buf_id, num_elements );
809 VAStatus vaMapBuffer (
811 VABufferID buf_id, /* in */
812 void **pbuf /* out */
815 VADriverContextP ctx;
822 VA_FOOL_FUNC(va_FoolMapBuffer, dpy, buf_id, pbuf);
824 return VA_STATUS_SUCCESS;
826 va_status = ctx->vtable->vaMapBuffer( ctx, buf_id, pbuf );
828 VA_TRACE_LOG(va_TraceMapBuffer, dpy, buf_id, pbuf);
833 VAStatus vaUnmapBuffer (
835 VABufferID buf_id /* in */
838 VADriverContextP ctx;
843 VA_FOOL_FUNC(va_FoolUnmapBuffer, dpy, buf_id);
845 return VA_STATUS_SUCCESS;
847 return ctx->vtable->vaUnmapBuffer( ctx, buf_id );
850 VAStatus vaDestroyBuffer (
855 VADriverContextP ctx;
861 return ctx->vtable->vaDestroyBuffer( ctx, buffer_id );
864 VAStatus vaBufferInfo (
866 VAContextID context, /* in */
867 VABufferID buf_id, /* in */
868 VABufferType *type, /* out */
869 unsigned int *size, /* out */
870 unsigned int *num_elements /* out */
873 VADriverContextP ctx;
879 VA_FOOL_FUNC(va_FoolBufferInfo, dpy, buf_id, type, size, num_elements);
881 return VA_STATUS_SUCCESS;
883 return ctx->vtable->vaBufferInfo( ctx, buf_id, type, size, num_elements );
886 VAStatus vaBeginPicture (
889 VASurfaceID render_target
892 VADriverContextP ctx;
898 VA_TRACE_FUNC(va_TraceBeginPicture, dpy, context, render_target);
901 va_status = ctx->vtable->vaBeginPicture( ctx, context, render_target );
906 VAStatus vaRenderPicture (
913 VADriverContextP ctx;
918 VA_TRACE_LOG(va_TraceRenderPicture, dpy, context, buffers, num_buffers);
921 return ctx->vtable->vaRenderPicture( ctx, context, buffers, num_buffers );
924 VAStatus vaEndPicture (
930 VADriverContextP ctx;
935 /* dump encode source surface */
936 VA_TRACE_SURFACE(va_TraceEndPicture, dpy, context, 0);
937 /* return directly if do dummy operation */
940 va_status = ctx->vtable->vaEndPicture( ctx, context );
941 /* dump decode dest surface */
942 VA_TRACE_SURFACE(va_TraceEndPicture, dpy, context, 1);
947 VAStatus vaSyncSurface (
949 VASurfaceID render_target
953 VADriverContextP ctx;
958 va_status = ctx->vtable->vaSyncSurface( ctx, render_target );
959 VA_TRACE_LOG(va_TraceSyncSurface, dpy, render_target);
964 VAStatus vaQuerySurfaceStatus (
966 VASurfaceID render_target,
967 VASurfaceStatus *status /* out */
971 VADriverContextP ctx;
975 va_status = ctx->vtable->vaQuerySurfaceStatus( ctx, render_target, status );
977 VA_TRACE_LOG(va_TraceQuerySurfaceStatus, dpy, render_target, status);
982 VAStatus vaQuerySurfaceError (
985 VAStatus error_status,
986 void **error_info /*out*/
990 VADriverContextP ctx;
994 va_status = ctx->vtable->vaQuerySurfaceError( ctx, surface, error_status, error_info );
996 VA_TRACE_LOG(va_TraceQuerySurfaceError, dpy, surface, error_status, error_info);
1001 /* Get maximum number of image formats supported by the implementation */
1002 int vaMaxNumImageFormats (
1006 if (!vaDisplayIsValid(dpy))
1009 return CTX(dpy)->max_image_formats;
1012 VAStatus vaQueryImageFormats (
1014 VAImageFormat *format_list, /* out */
1015 int *num_formats /* out */
1018 VADriverContextP ctx;
1022 return ctx->vtable->vaQueryImageFormats ( ctx, format_list, num_formats);
1026 * The width and height fields returned in the VAImage structure may get
1027 * enlarged for some YUV formats. The size of the data buffer that needs
1028 * to be allocated will be given in the "data_size" field in VAImage.
1029 * Image data is not allocated by this function. The client should
1030 * allocate the memory and fill in the VAImage structure's data field
1031 * after looking at "data_size" returned from the library.
1033 VAStatus vaCreateImage (
1035 VAImageFormat *format,
1038 VAImage *image /* out */
1041 VADriverContextP ctx;
1045 return ctx->vtable->vaCreateImage ( ctx, format, width, height, image);
1049 * Should call DestroyImage before destroying the surface it is bound to
1051 VAStatus vaDestroyImage (
1056 VADriverContextP ctx;
1060 return ctx->vtable->vaDestroyImage ( ctx, image);
1063 VAStatus vaSetImagePalette (
1066 unsigned char *palette
1069 VADriverContextP ctx;
1073 return ctx->vtable->vaSetImagePalette ( ctx, image, palette);
1077 * Retrieve surface data into a VAImage
1078 * Image must be in a format supported by the implementation
1080 VAStatus vaGetImage (
1082 VASurfaceID surface,
1083 int x, /* coordinates of the upper left source pixel */
1085 unsigned int width, /* width and height of the region */
1086 unsigned int height,
1090 VADriverContextP ctx;
1094 return ctx->vtable->vaGetImage ( ctx, surface, x, y, width, height, image);
1098 * Copy data from a VAImage to a surface
1099 * Image must be in a format supported by the implementation
1101 VAStatus vaPutImage (
1103 VASurfaceID surface,
1107 unsigned int src_width,
1108 unsigned int src_height,
1111 unsigned int dest_width,
1112 unsigned int dest_height
1115 VADriverContextP ctx;
1119 return ctx->vtable->vaPutImage ( ctx, surface, image, src_x, src_y, src_width, src_height, dest_x, dest_y, dest_width, dest_height );
1123 * Derive an VAImage from an existing surface.
1124 * This interface will derive a VAImage and corresponding image buffer from
1125 * an existing VA Surface. The image buffer can then be mapped/unmapped for
1126 * direct CPU access. This operation is only possible on implementations with
1127 * direct rendering capabilities and internal surface formats that can be
1128 * represented with a VAImage. When the operation is not possible this interface
1129 * will return VA_STATUS_ERROR_OPERATION_FAILED. Clients should then fall back
1130 * to using vaCreateImage + vaPutImage to accomplish the same task in an
1133 * Implementations should only return success when the resulting image buffer
1134 * would be useable with vaMap/Unmap.
1136 * When directly accessing a surface special care must be taken to insure
1137 * proper synchronization with the graphics hardware. Clients should call
1138 * vaQuerySurfaceStatus to insure that a surface is not the target of concurrent
1139 * rendering or currently being displayed by an overlay.
1141 * Additionally nothing about the contents of a surface should be assumed
1142 * following a vaPutSurface. Implementations are free to modify the surface for
1143 * scaling or subpicture blending within a call to vaPutImage.
1145 * Calls to vaPutImage or vaGetImage using the same surface from which the image
1146 * has been derived will return VA_STATUS_ERROR_SURFACE_BUSY. vaPutImage or
1147 * vaGetImage with other surfaces is supported.
1149 * An image created with vaDeriveImage should be freed with vaDestroyImage. The
1150 * image and image buffer structures will be destroyed; however, the underlying
1151 * surface will remain unchanged until freed with vaDestroySurfaces.
1153 VAStatus vaDeriveImage (
1155 VASurfaceID surface,
1156 VAImage *image /* out */
1159 VADriverContextP ctx;
1163 return ctx->vtable->vaDeriveImage ( ctx, surface, image );
1167 /* Get maximum number of subpicture formats supported by the implementation */
1168 int vaMaxNumSubpictureFormats (
1172 if (!vaDisplayIsValid(dpy))
1175 return CTX(dpy)->max_subpic_formats;
1179 * Query supported subpicture formats
1180 * The caller must provide a "format_list" array that can hold at
1181 * least vaMaxNumSubpictureFormats() entries. The flags arrary holds the flag
1182 * for each format to indicate additional capabilities for that format. The actual
1183 * number of formats returned in "format_list" is returned in "num_formats".
1185 VAStatus vaQuerySubpictureFormats (
1187 VAImageFormat *format_list, /* out */
1188 unsigned int *flags, /* out */
1189 unsigned int *num_formats /* out */
1192 VADriverContextP ctx;
1197 return ctx->vtable->vaQuerySubpictureFormats ( ctx, format_list, flags, num_formats);
1201 * Subpictures are created with an image associated.
1203 VAStatus vaCreateSubpicture (
1206 VASubpictureID *subpicture /* out */
1209 VADriverContextP ctx;
1213 return ctx->vtable->vaCreateSubpicture ( ctx, image, subpicture );
1217 * Destroy the subpicture before destroying the image it is assocated to
1219 VAStatus vaDestroySubpicture (
1221 VASubpictureID subpicture
1224 VADriverContextP ctx;
1228 return ctx->vtable->vaDestroySubpicture ( ctx, subpicture);
1231 VAStatus vaSetSubpictureImage (
1233 VASubpictureID subpicture,
1237 VADriverContextP ctx;
1241 return ctx->vtable->vaSetSubpictureImage ( ctx, subpicture, image);
1246 * If chromakey is enabled, then the area where the source value falls within
1247 * the chromakey [min, max] range is transparent
1249 VAStatus vaSetSubpictureChromakey (
1251 VASubpictureID subpicture,
1252 unsigned int chromakey_min,
1253 unsigned int chromakey_max,
1254 unsigned int chromakey_mask
1257 VADriverContextP ctx;
1261 return ctx->vtable->vaSetSubpictureChromakey ( ctx, subpicture, chromakey_min, chromakey_max, chromakey_mask );
1266 * Global alpha value is between 0 and 1. A value of 1 means fully opaque and
1267 * a value of 0 means fully transparent. If per-pixel alpha is also specified then
1268 * the overall alpha is per-pixel alpha multiplied by the global alpha
1270 VAStatus vaSetSubpictureGlobalAlpha (
1272 VASubpictureID subpicture,
1276 VADriverContextP ctx;
1280 return ctx->vtable->vaSetSubpictureGlobalAlpha ( ctx, subpicture, global_alpha );
1284 vaAssociateSubpicture associates the subpicture with the target_surface.
1285 It defines the region mapping between the subpicture and the target
1286 surface through source and destination rectangles (with the same width and height).
1287 Both will be displayed at the next call to vaPutSurface. Additional
1288 associations before the call to vaPutSurface simply overrides the association.
1290 VAStatus vaAssociateSubpicture (
1292 VASubpictureID subpicture,
1293 VASurfaceID *target_surfaces,
1295 short src_x, /* upper left offset in subpicture */
1297 unsigned short src_width,
1298 unsigned short src_height,
1299 short dest_x, /* upper left offset in surface */
1301 unsigned short dest_width,
1302 unsigned short dest_height,
1304 * whether to enable chroma-keying or global-alpha
1305 * see VA_SUBPICTURE_XXX values
1310 VADriverContextP ctx;
1314 return ctx->vtable->vaAssociateSubpicture ( ctx, subpicture, target_surfaces, num_surfaces, src_x, src_y, src_width, src_height, dest_x, dest_y, dest_width, dest_height, flags );
1318 * vaDeassociateSubpicture removes the association of the subpicture with target_surfaces.
1320 VAStatus vaDeassociateSubpicture (
1322 VASubpictureID subpicture,
1323 VASurfaceID *target_surfaces,
1327 VADriverContextP ctx;
1331 return ctx->vtable->vaDeassociateSubpicture ( ctx, subpicture, target_surfaces, num_surfaces );
1335 /* Get maximum number of display attributes supported by the implementation */
1336 int vaMaxNumDisplayAttributes (
1342 if (!vaDisplayIsValid(dpy))
1345 tmp = CTX(dpy)->max_display_attributes;
1347 VA_TRACE_LOG(va_TraceMaxNumDisplayAttributes, dpy, tmp);
1353 * Query display attributes
1354 * The caller must provide a "attr_list" array that can hold at
1355 * least vaMaxNumDisplayAttributes() entries. The actual number of attributes
1356 * returned in "attr_list" is returned in "num_attributes".
1358 VAStatus vaQueryDisplayAttributes (
1360 VADisplayAttribute *attr_list, /* out */
1361 int *num_attributes /* out */
1364 VADriverContextP ctx;
1369 va_status = ctx->vtable->vaQueryDisplayAttributes ( ctx, attr_list, num_attributes );
1371 VA_TRACE_LOG(va_TraceQueryDisplayAttributes, dpy, attr_list, num_attributes);
1378 * Get display attributes
1379 * This function returns the current attribute values in "attr_list".
1380 * Only attributes returned with VA_DISPLAY_ATTRIB_GETTABLE set in the "flags" field
1381 * from vaQueryDisplayAttributes() can have their values retrieved.
1383 VAStatus vaGetDisplayAttributes (
1385 VADisplayAttribute *attr_list, /* in/out */
1389 VADriverContextP ctx;
1394 va_status = ctx->vtable->vaGetDisplayAttributes ( ctx, attr_list, num_attributes );
1396 VA_TRACE_LOG(va_TraceGetDisplayAttributes, dpy, attr_list, num_attributes);
1402 * Set display attributes
1403 * Only attributes returned with VA_DISPLAY_ATTRIB_SETTABLE set in the "flags" field
1404 * from vaQueryDisplayAttributes() can be set. If the attribute is not settable or
1405 * the value is out of range, the function returns VA_STATUS_ERROR_ATTR_NOT_SUPPORTED
1407 VAStatus vaSetDisplayAttributes (
1409 VADisplayAttribute *attr_list,
1413 VADriverContextP ctx;
1418 va_status = ctx->vtable->vaSetDisplayAttributes ( ctx, attr_list, num_attributes );
1419 VA_TRACE_LOG(va_TraceSetDisplayAttributes, dpy, attr_list, num_attributes);
1424 VAStatus vaLockSurface(VADisplay dpy,
1425 VASurfaceID surface,
1426 unsigned int *fourcc, /* following are output argument */
1427 unsigned int *luma_stride,
1428 unsigned int *chroma_u_stride,
1429 unsigned int *chroma_v_stride,
1430 unsigned int *luma_offset,
1431 unsigned int *chroma_u_offset,
1432 unsigned int *chroma_v_offset,
1433 unsigned int *buffer_name,
1437 VADriverContextP ctx;
1441 return ctx->vtable->vaLockSurface( ctx, surface, fourcc, luma_stride, chroma_u_stride, chroma_v_stride, luma_offset, chroma_u_offset, chroma_v_offset, buffer_name, buffer);
1445 VAStatus vaUnlockSurface(VADisplay dpy,
1449 VADriverContextP ctx;
1453 return ctx->vtable->vaUnlockSurface( ctx, surface );
1456 /* Video Processing */
1457 #define VA_VPP_INIT_CONTEXT(ctx, dpy) do { \
1458 CHECK_DISPLAY(dpy); \
1461 return VA_STATUS_ERROR_INVALID_DISPLAY; \
1464 #define VA_VPP_INVOKE(dpy, func, args) do { \
1465 if (!ctx->vtable_vpp->va##func) \
1466 return VA_STATUS_ERROR_UNIMPLEMENTED; \
1467 status = ctx->vtable_vpp->va##func args; \
1471 vaQueryVideoProcFilters(
1473 VAContextID context,
1474 VAProcFilterType *filters,
1475 unsigned int *num_filters
1478 VADriverContextP ctx;
1481 VA_VPP_INIT_CONTEXT(ctx, dpy);
1484 QueryVideoProcFilters,
1485 (ctx, context, filters, num_filters)
1491 vaQueryVideoProcFilterCaps(
1493 VAContextID context,
1494 VAProcFilterType type,
1496 unsigned int *num_filter_caps
1499 VADriverContextP ctx;
1502 VA_VPP_INIT_CONTEXT(ctx, dpy);
1505 QueryVideoProcFilterCaps,
1506 (ctx, context, type, filter_caps, num_filter_caps)
1512 vaQueryVideoProcPipelineCaps(
1514 VAContextID context,
1515 VABufferID *filters,
1516 unsigned int num_filters,
1517 VAProcPipelineCaps *pipeline_caps
1520 VADriverContextP ctx;
1523 VA_VPP_INIT_CONTEXT(ctx, dpy);
1526 QueryVideoProcPipelineCaps,
1527 (ctx, context, filters, num_filters, pipeline_caps)