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;
53 * read a config "env" for libva.conf or from environment setting
54 * liva.conf has higher priority
55 * return 0: the "env" is set, and the value is copied into env_value
56 * 1: the env is not set
58 int va_parseConfig(char *env, char *env_value)
60 char *token, *value, *saveptr;
67 fp = fopen("/etc/libva.conf", "r");
68 while (fp && (fgets(oneline, 1024, fp) != NULL)) {
69 if (strlen(oneline) == 1)
71 token = strtok_r(oneline, "=\n", &saveptr);
72 value = strtok_r(NULL, "=\n", &saveptr);
74 if (NULL == token || NULL == value)
77 if (strcmp(token, env) == 0) {
79 strncpy(env_value,value, 1024);
89 /* no setting in config file, use env setting */
92 strncpy(env_value, getenv(env), 1024);
100 int vaDisplayIsValid(VADisplay dpy)
102 VADisplayContextP pDisplayContext = (VADisplayContextP)dpy;
103 return pDisplayContext && (pDisplayContext->vadpy_magic == VA_DISPLAY_MAGIC) && pDisplayContext->vaIsValid(pDisplayContext);
106 void va_errorMessage(const char *msg, ...)
108 char buf[512], *dynbuf;
113 len = vsnprintf(buf, sizeof(buf), msg, args);
116 if (len >= (int)sizeof(buf)) {
117 dynbuf = malloc(len + 1);
121 n = vsnprintf(dynbuf, len + 1, msg, args);
124 va_log_error(dynbuf);
131 void va_infoMessage(const char *msg, ...)
133 char buf[512], *dynbuf;
138 len = vsnprintf(buf, sizeof(buf), msg, args);
141 if (len >= (int)sizeof(buf)) {
142 dynbuf = malloc(len + 1);
146 n = vsnprintf(dynbuf, len + 1, msg, args);
156 static bool va_checkVtable(void *ptr, char *function)
159 va_errorMessage("No valid vtable entry for va%s\n", function);
165 static bool va_checkMaximum(int value, char *variable)
168 va_errorMessage("Failed to define max_%s in init\n", variable);
174 static bool va_checkString(const char* value, char *variable)
177 va_errorMessage("Failed to define str_%s in init\n", variable);
184 va_getDriverInitName(char *name, int namelen, int major, int minor)
186 int ret = snprintf(name, namelen, "__vaDriverInit_%d_%d", major, minor);
187 return ret > 0 && ret < namelen;
190 static VAStatus va_getDriverName(VADisplay dpy, char **driver_name)
192 VADisplayContextP pDisplayContext = (VADisplayContextP)dpy;
194 return pDisplayContext->vaGetDriverName(pDisplayContext, driver_name);
197 static VAStatus va_openDriver(VADisplay dpy, char *driver_name)
199 VADriverContextP ctx = CTX(dpy);
200 VAStatus vaStatus = VA_STATUS_ERROR_UNKNOWN;
201 char *search_path = NULL;
205 if (geteuid() == getuid())
206 /* don't allow setuid apps to use LIBVA_DRIVERS_PATH */
207 search_path = getenv("LIBVA_DRIVERS_PATH");
209 search_path = VA_DRIVERS_PATH;
211 search_path = strdup((const char *)search_path);
212 driver_dir = strtok_r(search_path, ":", &saveptr);
215 char *driver_path = (char *) malloc( strlen(driver_dir) +
216 strlen(driver_name) +
217 strlen(DRIVER_EXTENSION) + 2 );
218 strncpy( driver_path, driver_dir, strlen(driver_dir) + 1);
219 strncat( driver_path, "/", strlen("/") );
220 strncat( driver_path, driver_name, strlen(driver_name) );
221 strncat( driver_path, DRIVER_EXTENSION, strlen(DRIVER_EXTENSION) );
223 va_infoMessage("Trying to open %s\n", driver_path);
225 handle = dlopen( driver_path, RTLD_NOW | RTLD_GLOBAL | RTLD_NODELETE );
227 handle = dlopen( driver_path, RTLD_NOW| RTLD_GLOBAL);
230 /* Don't give errors for non-existing files */
231 if (0 == access( driver_path, F_OK))
232 va_errorMessage("dlopen of %s failed: %s\n", driver_path, dlerror());
234 VADriverInit init_func = NULL;
235 char init_func_s[256];
238 static const struct {
241 } compatible_versions[] = {
242 { VA_MAJOR_VERSION, VA_MINOR_VERSION },
248 for (i = 0; compatible_versions[i].major >= 0; i++) {
249 if (va_getDriverInitName(init_func_s, sizeof(init_func_s),
250 compatible_versions[i].major,
251 compatible_versions[i].minor)) {
252 init_func = (VADriverInit)dlsym(handle, init_func_s);
254 va_infoMessage("Found init function %s\n", init_func_s);
260 if (compatible_versions[i].major < 0) {
261 va_errorMessage("%s has no function %s\n",
262 driver_path, init_func_s);
265 struct VADriverVTable *vtable = ctx->vtable;
266 struct VADriverVTableVPP *vtable_vpp = ctx->vtable_vpp;
268 vaStatus = VA_STATUS_SUCCESS;
270 vtable = calloc(1, sizeof(*vtable));
272 vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED;
274 ctx->vtable = vtable;
277 vtable_vpp = calloc(1, sizeof(*vtable_vpp));
279 vtable_vpp->version = VA_DRIVER_VTABLE_VPP_VERSION;
281 vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED;
283 ctx->vtable_vpp = vtable_vpp;
285 if (VA_STATUS_SUCCESS == vaStatus)
286 vaStatus = (*init_func)(ctx);
288 if (VA_STATUS_SUCCESS == vaStatus) {
289 CHECK_MAXIMUM(vaStatus, ctx, profiles);
290 CHECK_MAXIMUM(vaStatus, ctx, entrypoints);
291 CHECK_MAXIMUM(vaStatus, ctx, attributes);
292 CHECK_MAXIMUM(vaStatus, ctx, image_formats);
293 CHECK_MAXIMUM(vaStatus, ctx, subpic_formats);
294 CHECK_MAXIMUM(vaStatus, ctx, display_attributes);
295 CHECK_STRING(vaStatus, ctx, vendor);
296 CHECK_VTABLE(vaStatus, ctx, Terminate);
297 CHECK_VTABLE(vaStatus, ctx, QueryConfigProfiles);
298 CHECK_VTABLE(vaStatus, ctx, QueryConfigEntrypoints);
299 CHECK_VTABLE(vaStatus, ctx, QueryConfigAttributes);
300 CHECK_VTABLE(vaStatus, ctx, CreateConfig);
301 CHECK_VTABLE(vaStatus, ctx, DestroyConfig);
302 CHECK_VTABLE(vaStatus, ctx, GetConfigAttributes);
303 CHECK_VTABLE(vaStatus, ctx, CreateSurfaces);
304 CHECK_VTABLE(vaStatus, ctx, DestroySurfaces);
305 CHECK_VTABLE(vaStatus, ctx, CreateContext);
306 CHECK_VTABLE(vaStatus, ctx, DestroyContext);
307 CHECK_VTABLE(vaStatus, ctx, CreateBuffer);
308 CHECK_VTABLE(vaStatus, ctx, BufferSetNumElements);
309 CHECK_VTABLE(vaStatus, ctx, MapBuffer);
310 CHECK_VTABLE(vaStatus, ctx, UnmapBuffer);
311 CHECK_VTABLE(vaStatus, ctx, DestroyBuffer);
312 CHECK_VTABLE(vaStatus, ctx, BeginPicture);
313 CHECK_VTABLE(vaStatus, ctx, RenderPicture);
314 CHECK_VTABLE(vaStatus, ctx, EndPicture);
315 CHECK_VTABLE(vaStatus, ctx, SyncSurface);
316 CHECK_VTABLE(vaStatus, ctx, QuerySurfaceStatus);
317 CHECK_VTABLE(vaStatus, ctx, PutSurface);
318 CHECK_VTABLE(vaStatus, ctx, QueryImageFormats);
319 CHECK_VTABLE(vaStatus, ctx, CreateImage);
320 CHECK_VTABLE(vaStatus, ctx, DeriveImage);
321 CHECK_VTABLE(vaStatus, ctx, DestroyImage);
322 CHECK_VTABLE(vaStatus, ctx, SetImagePalette);
323 CHECK_VTABLE(vaStatus, ctx, GetImage);
324 CHECK_VTABLE(vaStatus, ctx, PutImage);
325 CHECK_VTABLE(vaStatus, ctx, QuerySubpictureFormats);
326 CHECK_VTABLE(vaStatus, ctx, CreateSubpicture);
327 CHECK_VTABLE(vaStatus, ctx, DestroySubpicture);
328 CHECK_VTABLE(vaStatus, ctx, SetSubpictureImage);
329 CHECK_VTABLE(vaStatus, ctx, SetSubpictureChromakey);
330 CHECK_VTABLE(vaStatus, ctx, SetSubpictureGlobalAlpha);
331 CHECK_VTABLE(vaStatus, ctx, AssociateSubpicture);
332 CHECK_VTABLE(vaStatus, ctx, DeassociateSubpicture);
333 CHECK_VTABLE(vaStatus, ctx, QueryDisplayAttributes);
334 CHECK_VTABLE(vaStatus, ctx, GetDisplayAttributes);
335 CHECK_VTABLE(vaStatus, ctx, SetDisplayAttributes);
337 if (VA_STATUS_SUCCESS != vaStatus) {
338 va_errorMessage("%s init failed\n", driver_path);
341 if (VA_STATUS_SUCCESS == vaStatus)
342 ctx->handle = handle;
349 driver_dir = strtok_r(NULL, ":", &saveptr);
357 VAPrivFunc vaGetLibFunc(VADisplay dpy, const char *func)
359 VADriverContextP ctx;
360 if (!vaDisplayIsValid(dpy))
364 if (NULL == ctx->handle)
367 return (VAPrivFunc) dlsym(ctx->handle, func);
372 * Returns a short english description of error_status
374 const char *vaErrorStr(VAStatus error_status)
376 switch(error_status) {
377 case VA_STATUS_SUCCESS:
378 return "success (no error)";
379 case VA_STATUS_ERROR_OPERATION_FAILED:
380 return "operation failed";
381 case VA_STATUS_ERROR_ALLOCATION_FAILED:
382 return "resource allocation failed";
383 case VA_STATUS_ERROR_INVALID_DISPLAY:
384 return "invalid VADisplay";
385 case VA_STATUS_ERROR_INVALID_CONFIG:
386 return "invalid VAConfigID";
387 case VA_STATUS_ERROR_INVALID_CONTEXT:
388 return "invalid VAContextID";
389 case VA_STATUS_ERROR_INVALID_SURFACE:
390 return "invalid VASurfaceID";
391 case VA_STATUS_ERROR_INVALID_BUFFER:
392 return "invalid VABufferID";
393 case VA_STATUS_ERROR_INVALID_IMAGE:
394 return "invalid VAImageID";
395 case VA_STATUS_ERROR_INVALID_SUBPICTURE:
396 return "invalid VASubpictureID";
397 case VA_STATUS_ERROR_ATTR_NOT_SUPPORTED:
398 return "attribute not supported";
399 case VA_STATUS_ERROR_MAX_NUM_EXCEEDED:
400 return "list argument exceeds maximum number";
401 case VA_STATUS_ERROR_UNSUPPORTED_PROFILE:
402 return "the requested VAProfile is not supported";
403 case VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT:
404 return "the requested VAEntryPoint is not supported";
405 case VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT:
406 return "the requested RT Format is not supported";
407 case VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE:
408 return "the requested VABufferType is not supported";
409 case VA_STATUS_ERROR_SURFACE_BUSY:
410 return "surface is in use";
411 case VA_STATUS_ERROR_FLAG_NOT_SUPPORTED:
412 return "flag not supported";
413 case VA_STATUS_ERROR_INVALID_PARAMETER:
414 return "invalid parameter";
415 case VA_STATUS_ERROR_RESOLUTION_NOT_SUPPORTED:
416 return "resolution not supported";
417 case VA_STATUS_ERROR_UNIMPLEMENTED:
418 return "the requested function is not implemented";
419 case VA_STATUS_ERROR_SURFACE_IN_DISPLAYING:
420 return "surface is in displaying (may by overlay)" ;
421 case VA_STATUS_ERROR_INVALID_IMAGE_FORMAT:
422 return "invalid VAImageFormat";
423 case VA_STATUS_ERROR_INVALID_VALUE:
424 return "an invalid/unsupported value was supplied";
425 case VA_STATUS_ERROR_UNSUPPORTED_FILTER:
426 return "the requested filter is not supported";
427 case VA_STATUS_ERROR_INVALID_FILTER_CHAIN:
428 return "an invalid filter chain was supplied";
429 case VA_STATUS_ERROR_UNKNOWN:
430 return "unknown libva error";
432 return "unknown libva error / description missing";
435 VAStatus vaInitialize (
437 int *major_version, /* out */
438 int *minor_version /* out */
441 const char *driver_name_env = NULL;
442 char *driver_name = NULL;
451 va_infoMessage("VA-API version %s\n", VA_VERSION_S);
453 driver_name_env = getenv("LIBVA_DRIVER_NAME");
454 if (driver_name_env && geteuid() == getuid()) {
455 /* Don't allow setuid apps to use LIBVA_DRIVER_NAME */
456 driver_name = strdup(driver_name_env);
457 vaStatus = VA_STATUS_SUCCESS;
458 va_infoMessage("User requested driver '%s'\n", driver_name);
460 vaStatus = va_getDriverName(dpy, &driver_name);
461 va_infoMessage("va_getDriverName() returns %d\n", vaStatus);
464 if (VA_STATUS_SUCCESS == vaStatus) {
465 vaStatus = va_openDriver(dpy, driver_name);
466 va_infoMessage("va_openDriver() returns %d\n", vaStatus);
468 *major_version = VA_MAJOR_VERSION;
469 *minor_version = VA_MINOR_VERSION;
475 VA_TRACE_LOG(va_TraceInitialize, dpy, major_version, minor_version);
482 * After this call, all library internal resources will be cleaned up
484 VAStatus vaTerminate (
488 VAStatus vaStatus = VA_STATUS_SUCCESS;
489 VADisplayContextP pDisplayContext = (VADisplayContextP)dpy;
490 VADriverContextP old_ctx;
495 if (old_ctx->handle) {
496 vaStatus = old_ctx->vtable->vaTerminate(old_ctx);
497 dlclose(old_ctx->handle);
498 old_ctx->handle = NULL;
500 free(old_ctx->vtable);
501 old_ctx->vtable = NULL;
502 free(old_ctx->vtable_vpp);
503 old_ctx->vtable_vpp = NULL;
505 if (VA_STATUS_SUCCESS == vaStatus)
506 pDisplayContext->vaDestroy(pDisplayContext);
508 VA_TRACE_LOG(va_TraceTerminate, dpy);
518 * vaQueryVendorString returns a pointer to a zero-terminated string
519 * describing some aspects of the VA implemenation on a specific
520 * hardware accelerator. The format of the returned string is:
521 * <vendorname>-<major_version>-<minor_version>-<addtional_info>
522 * e.g. for the Intel GMA500 implementation, an example would be:
523 * "IntelGMA500-1.0-0.2-patch3
525 const char *vaQueryVendorString (
529 if (!vaDisplayIsValid(dpy))
532 return CTX(dpy)->str_vendor;
536 /* Get maximum number of profiles supported by the implementation */
537 int vaMaxNumProfiles (
541 if (!vaDisplayIsValid(dpy))
544 return CTX(dpy)->max_profiles;
547 /* Get maximum number of entrypoints supported by the implementation */
548 int vaMaxNumEntrypoints (
552 if (!vaDisplayIsValid(dpy))
555 return CTX(dpy)->max_entrypoints;
559 /* Get maximum number of attributs supported by the implementation */
560 int vaMaxNumConfigAttributes (
564 if (!vaDisplayIsValid(dpy))
567 return CTX(dpy)->max_attributes;
570 VAStatus vaQueryConfigEntrypoints (
573 VAEntrypoint *entrypoints, /* out */
574 int *num_entrypoints /* out */
577 VADriverContextP ctx;
581 return ctx->vtable->vaQueryConfigEntrypoints ( ctx, profile, entrypoints, num_entrypoints);
584 VAStatus vaGetConfigAttributes (
587 VAEntrypoint entrypoint,
588 VAConfigAttrib *attrib_list, /* in/out */
592 VADriverContextP ctx;
596 return ctx->vtable->vaGetConfigAttributes ( ctx, profile, entrypoint, attrib_list, num_attribs );
599 VAStatus vaQueryConfigProfiles (
601 VAProfile *profile_list, /* out */
602 int *num_profiles /* out */
605 VADriverContextP ctx;
609 return ctx->vtable->vaQueryConfigProfiles ( ctx, profile_list, num_profiles );
612 VAStatus vaCreateConfig (
615 VAEntrypoint entrypoint,
616 VAConfigAttrib *attrib_list,
618 VAConfigID *config_id /* out */
621 VADriverContextP ctx;
622 VAStatus vaStatus = VA_STATUS_SUCCESS;
628 vaStatus = ctx->vtable->vaCreateConfig ( ctx, profile, entrypoint, attrib_list, num_attribs, config_id );
630 /* record the current entrypoint for further trace/fool determination */
631 VA_TRACE_FUNC(va_TraceCreateConfig, dpy, profile, entrypoint, attrib_list, num_attribs, config_id);
632 VA_FOOL_FUNC(va_FoolCreateConfig, dpy, profile, entrypoint, attrib_list, num_attribs, config_id);
637 VAStatus vaDestroyConfig (
642 VADriverContextP ctx;
646 return ctx->vtable->vaDestroyConfig ( ctx, config_id );
649 VAStatus vaQueryConfigAttributes (
651 VAConfigID config_id,
652 VAProfile *profile, /* out */
653 VAEntrypoint *entrypoint, /* out */
654 VAConfigAttrib *attrib_list,/* out */
655 int *num_attribs /* out */
658 VADriverContextP ctx;
662 return ctx->vtable->vaQueryConfigAttributes( ctx, config_id, profile, entrypoint, attrib_list, num_attribs);
666 vaGetSurfaceAttributes(
669 VASurfaceAttrib *attrib_list,
670 unsigned int num_attribs
673 VADriverContextP ctx;
679 return VA_STATUS_ERROR_INVALID_DISPLAY;
681 if (!ctx->vtable->vaGetSurfaceAttributes)
682 return VA_STATUS_ERROR_UNIMPLEMENTED;
684 vaStatus = ctx->vtable->vaGetSurfaceAttributes(ctx, config,
685 attrib_list, num_attribs);
695 VASurfaceID *surfaces,
696 unsigned int num_surfaces,
697 VASurfaceAttrib *attrib_list,
698 unsigned int num_attribs
701 VADriverContextP ctx;
707 return VA_STATUS_ERROR_INVALID_DISPLAY;
709 if (ctx->vtable->vaCreateSurfaces2)
710 return ctx->vtable->vaCreateSurfaces2(ctx, format, width, height,
711 surfaces, num_surfaces,
712 attrib_list, num_attribs);
714 if (attrib_list && num_attribs > 0)
715 return VA_STATUS_ERROR_ATTR_NOT_SUPPORTED;
717 vaStatus = ctx->vtable->vaCreateSurfaces(ctx, width, height, format,
718 num_surfaces, surfaces);
720 VA_TRACE_LOG(va_TraceCreateSurfaces,
721 dpy, width, height, format, num_surfaces, surfaces,
722 attrib_list, num_attribs);
728 VAStatus vaDestroySurfaces (
730 VASurfaceID *surface_list,
734 VADriverContextP ctx;
738 return ctx->vtable->vaDestroySurfaces( ctx, surface_list, num_surfaces );
741 VAStatus vaCreateContext (
743 VAConfigID config_id,
747 VASurfaceID *render_targets,
748 int num_render_targets,
749 VAContextID *context /* out */
752 VADriverContextP ctx;
758 vaStatus = ctx->vtable->vaCreateContext( ctx, config_id, picture_width, picture_height,
759 flag, render_targets, num_render_targets, context );
761 /* keep current encode/decode resoluton */
762 VA_TRACE_FUNC(va_TraceCreateContext, dpy, config_id, picture_width, picture_height, flag, render_targets, num_render_targets, context);
767 VAStatus vaDestroyContext (
772 VADriverContextP ctx;
776 return ctx->vtable->vaDestroyContext( ctx, context );
779 VAStatus vaCreateBuffer (
781 VAContextID context, /* in */
782 VABufferType type, /* in */
783 unsigned int size, /* in */
784 unsigned int num_elements, /* in */
786 VABufferID *buf_id /* out */
789 VADriverContextP ctx;
794 VA_FOOL_FUNC(va_FoolCreateBuffer, dpy, context, type, size, num_elements, data, buf_id);
796 return VA_STATUS_SUCCESS;
798 return ctx->vtable->vaCreateBuffer( ctx, context, type, size, num_elements, data, buf_id);
801 VAStatus vaBufferSetNumElements (
803 VABufferID buf_id, /* in */
804 unsigned int num_elements /* in */
807 VADriverContextP ctx;
813 return ctx->vtable->vaBufferSetNumElements( ctx, buf_id, num_elements );
817 VAStatus vaMapBuffer (
819 VABufferID buf_id, /* in */
820 void **pbuf /* out */
823 VADriverContextP ctx;
830 VA_FOOL_FUNC(va_FoolMapBuffer, dpy, buf_id, pbuf);
832 return VA_STATUS_SUCCESS;
834 va_status = ctx->vtable->vaMapBuffer( ctx, buf_id, pbuf );
836 VA_TRACE_LOG(va_TraceMapBuffer, dpy, buf_id, pbuf);
841 VAStatus vaUnmapBuffer (
843 VABufferID buf_id /* in */
846 VADriverContextP ctx;
851 VA_FOOL_FUNC(va_FoolUnmapBuffer, dpy, buf_id);
853 return VA_STATUS_SUCCESS;
855 return ctx->vtable->vaUnmapBuffer( ctx, buf_id );
858 VAStatus vaDestroyBuffer (
863 VADriverContextP ctx;
869 return ctx->vtable->vaDestroyBuffer( ctx, buffer_id );
872 VAStatus vaBufferInfo (
874 VAContextID context, /* in */
875 VABufferID buf_id, /* in */
876 VABufferType *type, /* out */
877 unsigned int *size, /* out */
878 unsigned int *num_elements /* out */
881 VADriverContextP ctx;
887 VA_FOOL_FUNC(va_FoolBufferInfo, dpy, buf_id, type, size, num_elements);
889 return VA_STATUS_SUCCESS;
891 return ctx->vtable->vaBufferInfo( ctx, buf_id, type, size, num_elements );
894 VAStatus vaBeginPicture (
897 VASurfaceID render_target
900 VADriverContextP ctx;
906 VA_TRACE_FUNC(va_TraceBeginPicture, dpy, context, render_target);
909 va_status = ctx->vtable->vaBeginPicture( ctx, context, render_target );
914 VAStatus vaRenderPicture (
921 VADriverContextP ctx;
926 VA_TRACE_LOG(va_TraceRenderPicture, dpy, context, buffers, num_buffers);
929 return ctx->vtable->vaRenderPicture( ctx, context, buffers, num_buffers );
932 VAStatus vaEndPicture (
938 VADriverContextP ctx;
943 /* dump encode source surface */
944 VA_TRACE_SURFACE(va_TraceEndPicture, dpy, context, 0);
945 /* return directly if do dummy operation */
948 va_status = ctx->vtable->vaEndPicture( ctx, context );
949 /* dump decode dest surface */
950 VA_TRACE_SURFACE(va_TraceEndPicture, dpy, context, 1);
955 VAStatus vaSyncSurface (
957 VASurfaceID render_target
961 VADriverContextP ctx;
966 va_status = ctx->vtable->vaSyncSurface( ctx, render_target );
967 VA_TRACE_LOG(va_TraceSyncSurface, dpy, render_target);
972 VAStatus vaQuerySurfaceStatus (
974 VASurfaceID render_target,
975 VASurfaceStatus *status /* out */
979 VADriverContextP ctx;
983 va_status = ctx->vtable->vaQuerySurfaceStatus( ctx, render_target, status );
985 VA_TRACE_LOG(va_TraceQuerySurfaceStatus, dpy, render_target, status);
990 VAStatus vaQuerySurfaceError (
993 VAStatus error_status,
994 void **error_info /*out*/
998 VADriverContextP ctx;
1002 va_status = ctx->vtable->vaQuerySurfaceError( ctx, surface, error_status, error_info );
1004 VA_TRACE_LOG(va_TraceQuerySurfaceError, dpy, surface, error_status, error_info);
1009 /* Get maximum number of image formats supported by the implementation */
1010 int vaMaxNumImageFormats (
1014 if (!vaDisplayIsValid(dpy))
1017 return CTX(dpy)->max_image_formats;
1020 VAStatus vaQueryImageFormats (
1022 VAImageFormat *format_list, /* out */
1023 int *num_formats /* out */
1026 VADriverContextP ctx;
1030 return ctx->vtable->vaQueryImageFormats ( ctx, format_list, num_formats);
1034 * The width and height fields returned in the VAImage structure may get
1035 * enlarged for some YUV formats. The size of the data buffer that needs
1036 * to be allocated will be given in the "data_size" field in VAImage.
1037 * Image data is not allocated by this function. The client should
1038 * allocate the memory and fill in the VAImage structure's data field
1039 * after looking at "data_size" returned from the library.
1041 VAStatus vaCreateImage (
1043 VAImageFormat *format,
1046 VAImage *image /* out */
1049 VADriverContextP ctx;
1053 return ctx->vtable->vaCreateImage ( ctx, format, width, height, image);
1057 * Should call DestroyImage before destroying the surface it is bound to
1059 VAStatus vaDestroyImage (
1064 VADriverContextP ctx;
1068 return ctx->vtable->vaDestroyImage ( ctx, image);
1071 VAStatus vaSetImagePalette (
1074 unsigned char *palette
1077 VADriverContextP ctx;
1081 return ctx->vtable->vaSetImagePalette ( ctx, image, palette);
1085 * Retrieve surface data into a VAImage
1086 * Image must be in a format supported by the implementation
1088 VAStatus vaGetImage (
1090 VASurfaceID surface,
1091 int x, /* coordinates of the upper left source pixel */
1093 unsigned int width, /* width and height of the region */
1094 unsigned int height,
1098 VADriverContextP ctx;
1102 return ctx->vtable->vaGetImage ( ctx, surface, x, y, width, height, image);
1106 * Copy data from a VAImage to a surface
1107 * Image must be in a format supported by the implementation
1109 VAStatus vaPutImage (
1111 VASurfaceID surface,
1115 unsigned int src_width,
1116 unsigned int src_height,
1119 unsigned int dest_width,
1120 unsigned int dest_height
1123 VADriverContextP ctx;
1127 return ctx->vtable->vaPutImage ( ctx, surface, image, src_x, src_y, src_width, src_height, dest_x, dest_y, dest_width, dest_height );
1131 * Derive an VAImage from an existing surface.
1132 * This interface will derive a VAImage and corresponding image buffer from
1133 * an existing VA Surface. The image buffer can then be mapped/unmapped for
1134 * direct CPU access. This operation is only possible on implementations with
1135 * direct rendering capabilities and internal surface formats that can be
1136 * represented with a VAImage. When the operation is not possible this interface
1137 * will return VA_STATUS_ERROR_OPERATION_FAILED. Clients should then fall back
1138 * to using vaCreateImage + vaPutImage to accomplish the same task in an
1141 * Implementations should only return success when the resulting image buffer
1142 * would be useable with vaMap/Unmap.
1144 * When directly accessing a surface special care must be taken to insure
1145 * proper synchronization with the graphics hardware. Clients should call
1146 * vaQuerySurfaceStatus to insure that a surface is not the target of concurrent
1147 * rendering or currently being displayed by an overlay.
1149 * Additionally nothing about the contents of a surface should be assumed
1150 * following a vaPutSurface. Implementations are free to modify the surface for
1151 * scaling or subpicture blending within a call to vaPutImage.
1153 * Calls to vaPutImage or vaGetImage using the same surface from which the image
1154 * has been derived will return VA_STATUS_ERROR_SURFACE_BUSY. vaPutImage or
1155 * vaGetImage with other surfaces is supported.
1157 * An image created with vaDeriveImage should be freed with vaDestroyImage. The
1158 * image and image buffer structures will be destroyed; however, the underlying
1159 * surface will remain unchanged until freed with vaDestroySurfaces.
1161 VAStatus vaDeriveImage (
1163 VASurfaceID surface,
1164 VAImage *image /* out */
1167 VADriverContextP ctx;
1171 return ctx->vtable->vaDeriveImage ( ctx, surface, image );
1175 /* Get maximum number of subpicture formats supported by the implementation */
1176 int vaMaxNumSubpictureFormats (
1180 if (!vaDisplayIsValid(dpy))
1183 return CTX(dpy)->max_subpic_formats;
1187 * Query supported subpicture formats
1188 * The caller must provide a "format_list" array that can hold at
1189 * least vaMaxNumSubpictureFormats() entries. The flags arrary holds the flag
1190 * for each format to indicate additional capabilities for that format. The actual
1191 * number of formats returned in "format_list" is returned in "num_formats".
1193 VAStatus vaQuerySubpictureFormats (
1195 VAImageFormat *format_list, /* out */
1196 unsigned int *flags, /* out */
1197 unsigned int *num_formats /* out */
1200 VADriverContextP ctx;
1205 return ctx->vtable->vaQuerySubpictureFormats ( ctx, format_list, flags, num_formats);
1209 * Subpictures are created with an image associated.
1211 VAStatus vaCreateSubpicture (
1214 VASubpictureID *subpicture /* out */
1217 VADriverContextP ctx;
1221 return ctx->vtable->vaCreateSubpicture ( ctx, image, subpicture );
1225 * Destroy the subpicture before destroying the image it is assocated to
1227 VAStatus vaDestroySubpicture (
1229 VASubpictureID subpicture
1232 VADriverContextP ctx;
1236 return ctx->vtable->vaDestroySubpicture ( ctx, subpicture);
1239 VAStatus vaSetSubpictureImage (
1241 VASubpictureID subpicture,
1245 VADriverContextP ctx;
1249 return ctx->vtable->vaSetSubpictureImage ( ctx, subpicture, image);
1254 * If chromakey is enabled, then the area where the source value falls within
1255 * the chromakey [min, max] range is transparent
1257 VAStatus vaSetSubpictureChromakey (
1259 VASubpictureID subpicture,
1260 unsigned int chromakey_min,
1261 unsigned int chromakey_max,
1262 unsigned int chromakey_mask
1265 VADriverContextP ctx;
1269 return ctx->vtable->vaSetSubpictureChromakey ( ctx, subpicture, chromakey_min, chromakey_max, chromakey_mask );
1274 * Global alpha value is between 0 and 1. A value of 1 means fully opaque and
1275 * a value of 0 means fully transparent. If per-pixel alpha is also specified then
1276 * the overall alpha is per-pixel alpha multiplied by the global alpha
1278 VAStatus vaSetSubpictureGlobalAlpha (
1280 VASubpictureID subpicture,
1284 VADriverContextP ctx;
1288 return ctx->vtable->vaSetSubpictureGlobalAlpha ( ctx, subpicture, global_alpha );
1292 vaAssociateSubpicture associates the subpicture with the target_surface.
1293 It defines the region mapping between the subpicture and the target
1294 surface through source and destination rectangles (with the same width and height).
1295 Both will be displayed at the next call to vaPutSurface. Additional
1296 associations before the call to vaPutSurface simply overrides the association.
1298 VAStatus vaAssociateSubpicture (
1300 VASubpictureID subpicture,
1301 VASurfaceID *target_surfaces,
1303 short src_x, /* upper left offset in subpicture */
1305 unsigned short src_width,
1306 unsigned short src_height,
1307 short dest_x, /* upper left offset in surface */
1309 unsigned short dest_width,
1310 unsigned short dest_height,
1312 * whether to enable chroma-keying or global-alpha
1313 * see VA_SUBPICTURE_XXX values
1318 VADriverContextP ctx;
1322 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 );
1326 * vaDeassociateSubpicture removes the association of the subpicture with target_surfaces.
1328 VAStatus vaDeassociateSubpicture (
1330 VASubpictureID subpicture,
1331 VASurfaceID *target_surfaces,
1335 VADriverContextP ctx;
1339 return ctx->vtable->vaDeassociateSubpicture ( ctx, subpicture, target_surfaces, num_surfaces );
1343 /* Get maximum number of display attributes supported by the implementation */
1344 int vaMaxNumDisplayAttributes (
1350 if (!vaDisplayIsValid(dpy))
1353 tmp = CTX(dpy)->max_display_attributes;
1355 VA_TRACE_LOG(va_TraceMaxNumDisplayAttributes, dpy, tmp);
1361 * Query display attributes
1362 * The caller must provide a "attr_list" array that can hold at
1363 * least vaMaxNumDisplayAttributes() entries. The actual number of attributes
1364 * returned in "attr_list" is returned in "num_attributes".
1366 VAStatus vaQueryDisplayAttributes (
1368 VADisplayAttribute *attr_list, /* out */
1369 int *num_attributes /* out */
1372 VADriverContextP ctx;
1377 va_status = ctx->vtable->vaQueryDisplayAttributes ( ctx, attr_list, num_attributes );
1379 VA_TRACE_LOG(va_TraceQueryDisplayAttributes, dpy, attr_list, num_attributes);
1386 * Get display attributes
1387 * This function returns the current attribute values in "attr_list".
1388 * Only attributes returned with VA_DISPLAY_ATTRIB_GETTABLE set in the "flags" field
1389 * from vaQueryDisplayAttributes() can have their values retrieved.
1391 VAStatus vaGetDisplayAttributes (
1393 VADisplayAttribute *attr_list, /* in/out */
1397 VADriverContextP ctx;
1402 va_status = ctx->vtable->vaGetDisplayAttributes ( ctx, attr_list, num_attributes );
1404 VA_TRACE_LOG(va_TraceGetDisplayAttributes, dpy, attr_list, num_attributes);
1410 * Set display attributes
1411 * Only attributes returned with VA_DISPLAY_ATTRIB_SETTABLE set in the "flags" field
1412 * from vaQueryDisplayAttributes() can be set. If the attribute is not settable or
1413 * the value is out of range, the function returns VA_STATUS_ERROR_ATTR_NOT_SUPPORTED
1415 VAStatus vaSetDisplayAttributes (
1417 VADisplayAttribute *attr_list,
1421 VADriverContextP ctx;
1426 va_status = ctx->vtable->vaSetDisplayAttributes ( ctx, attr_list, num_attributes );
1427 VA_TRACE_LOG(va_TraceSetDisplayAttributes, dpy, attr_list, num_attributes);
1432 VAStatus vaLockSurface(VADisplay dpy,
1433 VASurfaceID surface,
1434 unsigned int *fourcc, /* following are output argument */
1435 unsigned int *luma_stride,
1436 unsigned int *chroma_u_stride,
1437 unsigned int *chroma_v_stride,
1438 unsigned int *luma_offset,
1439 unsigned int *chroma_u_offset,
1440 unsigned int *chroma_v_offset,
1441 unsigned int *buffer_name,
1445 VADriverContextP ctx;
1449 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);
1453 VAStatus vaUnlockSurface(VADisplay dpy,
1457 VADriverContextP ctx;
1461 return ctx->vtable->vaUnlockSurface( ctx, surface );
1464 /* Video Processing */
1465 #define VA_VPP_INIT_CONTEXT(ctx, dpy) do { \
1466 CHECK_DISPLAY(dpy); \
1469 return VA_STATUS_ERROR_INVALID_DISPLAY; \
1472 #define VA_VPP_INVOKE(dpy, func, args) do { \
1473 if (!ctx->vtable_vpp->va##func) \
1474 return VA_STATUS_ERROR_UNIMPLEMENTED; \
1475 status = ctx->vtable_vpp->va##func args; \
1479 vaQueryVideoProcFilters(
1481 VAContextID context,
1482 VAProcFilterType *filters,
1483 unsigned int *num_filters
1486 VADriverContextP ctx;
1489 VA_VPP_INIT_CONTEXT(ctx, dpy);
1492 QueryVideoProcFilters,
1493 (ctx, context, filters, num_filters)
1499 vaQueryVideoProcFilterCaps(
1501 VAContextID context,
1502 VAProcFilterType type,
1504 unsigned int *num_filter_caps
1507 VADriverContextP ctx;
1510 VA_VPP_INIT_CONTEXT(ctx, dpy);
1513 QueryVideoProcFilterCaps,
1514 (ctx, context, type, filter_caps, num_filter_caps)
1520 vaQueryVideoProcPipelineCaps(
1522 VAContextID context,
1523 VABufferID *filters,
1524 unsigned int num_filters,
1525 VAProcPipelineCaps *pipeline_caps
1528 VADriverContextP ctx;
1531 VA_VPP_INIT_CONTEXT(ctx, dpy);
1534 QueryVideoProcPipelineCaps,
1535 (ctx, context, filters, num_filters, pipeline_caps)