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_TraceCreateSurfaces,
714 dpy, width, height, format, num_surfaces, surfaces,
715 attrib_list, num_attribs);
721 VAStatus vaDestroySurfaces (
723 VASurfaceID *surface_list,
727 VADriverContextP ctx;
731 return ctx->vtable->vaDestroySurfaces( ctx, surface_list, num_surfaces );
734 VAStatus vaCreateContext (
736 VAConfigID config_id,
740 VASurfaceID *render_targets,
741 int num_render_targets,
742 VAContextID *context /* out */
745 VADriverContextP ctx;
751 vaStatus = ctx->vtable->vaCreateContext( ctx, config_id, picture_width, picture_height,
752 flag, render_targets, num_render_targets, context );
754 /* keep current encode/decode resoluton */
755 VA_TRACE_FUNC(va_TraceCreateContext, dpy, config_id, picture_width, picture_height, flag, render_targets, num_render_targets, context);
760 VAStatus vaDestroyContext (
765 VADriverContextP ctx;
769 return ctx->vtable->vaDestroyContext( ctx, context );
772 VAStatus vaCreateBuffer (
774 VAContextID context, /* in */
775 VABufferType type, /* in */
776 unsigned int size, /* in */
777 unsigned int num_elements, /* in */
779 VABufferID *buf_id /* out */
782 VADriverContextP ctx;
787 VA_FOOL_FUNC(va_FoolCreateBuffer, dpy, context, type, size, num_elements, data, buf_id);
789 return VA_STATUS_SUCCESS;
791 return ctx->vtable->vaCreateBuffer( ctx, context, type, size, num_elements, data, buf_id);
794 VAStatus vaBufferSetNumElements (
796 VABufferID buf_id, /* in */
797 unsigned int num_elements /* in */
800 VADriverContextP ctx;
806 return ctx->vtable->vaBufferSetNumElements( ctx, buf_id, num_elements );
810 VAStatus vaMapBuffer (
812 VABufferID buf_id, /* in */
813 void **pbuf /* out */
816 VADriverContextP ctx;
823 VA_FOOL_FUNC(va_FoolMapBuffer, dpy, buf_id, pbuf);
825 return VA_STATUS_SUCCESS;
827 va_status = ctx->vtable->vaMapBuffer( ctx, buf_id, pbuf );
829 VA_TRACE_LOG(va_TraceMapBuffer, dpy, buf_id, pbuf);
834 VAStatus vaUnmapBuffer (
836 VABufferID buf_id /* in */
839 VADriverContextP ctx;
844 VA_FOOL_FUNC(va_FoolUnmapBuffer, dpy, buf_id);
846 return VA_STATUS_SUCCESS;
848 return ctx->vtable->vaUnmapBuffer( ctx, buf_id );
851 VAStatus vaDestroyBuffer (
856 VADriverContextP ctx;
862 return ctx->vtable->vaDestroyBuffer( ctx, buffer_id );
865 VAStatus vaBufferInfo (
867 VAContextID context, /* in */
868 VABufferID buf_id, /* in */
869 VABufferType *type, /* out */
870 unsigned int *size, /* out */
871 unsigned int *num_elements /* out */
874 VADriverContextP ctx;
880 VA_FOOL_FUNC(va_FoolBufferInfo, dpy, buf_id, type, size, num_elements);
882 return VA_STATUS_SUCCESS;
884 return ctx->vtable->vaBufferInfo( ctx, buf_id, type, size, num_elements );
887 VAStatus vaBeginPicture (
890 VASurfaceID render_target
893 VADriverContextP ctx;
899 VA_TRACE_FUNC(va_TraceBeginPicture, dpy, context, render_target);
902 va_status = ctx->vtable->vaBeginPicture( ctx, context, render_target );
907 VAStatus vaRenderPicture (
914 VADriverContextP ctx;
919 VA_TRACE_LOG(va_TraceRenderPicture, dpy, context, buffers, num_buffers);
922 return ctx->vtable->vaRenderPicture( ctx, context, buffers, num_buffers );
925 VAStatus vaEndPicture (
931 VADriverContextP ctx;
936 /* dump encode source surface */
937 VA_TRACE_SURFACE(va_TraceEndPicture, dpy, context, 0);
938 /* return directly if do dummy operation */
941 va_status = ctx->vtable->vaEndPicture( ctx, context );
942 /* dump decode dest surface */
943 VA_TRACE_SURFACE(va_TraceEndPicture, dpy, context, 1);
948 VAStatus vaSyncSurface (
950 VASurfaceID render_target
954 VADriverContextP ctx;
959 va_status = ctx->vtable->vaSyncSurface( ctx, render_target );
960 VA_TRACE_LOG(va_TraceSyncSurface, dpy, render_target);
965 VAStatus vaQuerySurfaceStatus (
967 VASurfaceID render_target,
968 VASurfaceStatus *status /* out */
972 VADriverContextP ctx;
976 va_status = ctx->vtable->vaQuerySurfaceStatus( ctx, render_target, status );
978 VA_TRACE_LOG(va_TraceQuerySurfaceStatus, dpy, render_target, status);
983 VAStatus vaQuerySurfaceError (
986 VAStatus error_status,
987 void **error_info /*out*/
991 VADriverContextP ctx;
995 va_status = ctx->vtable->vaQuerySurfaceError( ctx, surface, error_status, error_info );
997 VA_TRACE_LOG(va_TraceQuerySurfaceError, dpy, surface, error_status, error_info);
1002 /* Get maximum number of image formats supported by the implementation */
1003 int vaMaxNumImageFormats (
1007 if (!vaDisplayIsValid(dpy))
1010 return CTX(dpy)->max_image_formats;
1013 VAStatus vaQueryImageFormats (
1015 VAImageFormat *format_list, /* out */
1016 int *num_formats /* out */
1019 VADriverContextP ctx;
1023 return ctx->vtable->vaQueryImageFormats ( ctx, format_list, num_formats);
1027 * The width and height fields returned in the VAImage structure may get
1028 * enlarged for some YUV formats. The size of the data buffer that needs
1029 * to be allocated will be given in the "data_size" field in VAImage.
1030 * Image data is not allocated by this function. The client should
1031 * allocate the memory and fill in the VAImage structure's data field
1032 * after looking at "data_size" returned from the library.
1034 VAStatus vaCreateImage (
1036 VAImageFormat *format,
1039 VAImage *image /* out */
1042 VADriverContextP ctx;
1046 return ctx->vtable->vaCreateImage ( ctx, format, width, height, image);
1050 * Should call DestroyImage before destroying the surface it is bound to
1052 VAStatus vaDestroyImage (
1057 VADriverContextP ctx;
1061 return ctx->vtable->vaDestroyImage ( ctx, image);
1064 VAStatus vaSetImagePalette (
1067 unsigned char *palette
1070 VADriverContextP ctx;
1074 return ctx->vtable->vaSetImagePalette ( ctx, image, palette);
1078 * Retrieve surface data into a VAImage
1079 * Image must be in a format supported by the implementation
1081 VAStatus vaGetImage (
1083 VASurfaceID surface,
1084 int x, /* coordinates of the upper left source pixel */
1086 unsigned int width, /* width and height of the region */
1087 unsigned int height,
1091 VADriverContextP ctx;
1095 return ctx->vtable->vaGetImage ( ctx, surface, x, y, width, height, image);
1099 * Copy data from a VAImage to a surface
1100 * Image must be in a format supported by the implementation
1102 VAStatus vaPutImage (
1104 VASurfaceID surface,
1108 unsigned int src_width,
1109 unsigned int src_height,
1112 unsigned int dest_width,
1113 unsigned int dest_height
1116 VADriverContextP ctx;
1120 return ctx->vtable->vaPutImage ( ctx, surface, image, src_x, src_y, src_width, src_height, dest_x, dest_y, dest_width, dest_height );
1124 * Derive an VAImage from an existing surface.
1125 * This interface will derive a VAImage and corresponding image buffer from
1126 * an existing VA Surface. The image buffer can then be mapped/unmapped for
1127 * direct CPU access. This operation is only possible on implementations with
1128 * direct rendering capabilities and internal surface formats that can be
1129 * represented with a VAImage. When the operation is not possible this interface
1130 * will return VA_STATUS_ERROR_OPERATION_FAILED. Clients should then fall back
1131 * to using vaCreateImage + vaPutImage to accomplish the same task in an
1134 * Implementations should only return success when the resulting image buffer
1135 * would be useable with vaMap/Unmap.
1137 * When directly accessing a surface special care must be taken to insure
1138 * proper synchronization with the graphics hardware. Clients should call
1139 * vaQuerySurfaceStatus to insure that a surface is not the target of concurrent
1140 * rendering or currently being displayed by an overlay.
1142 * Additionally nothing about the contents of a surface should be assumed
1143 * following a vaPutSurface. Implementations are free to modify the surface for
1144 * scaling or subpicture blending within a call to vaPutImage.
1146 * Calls to vaPutImage or vaGetImage using the same surface from which the image
1147 * has been derived will return VA_STATUS_ERROR_SURFACE_BUSY. vaPutImage or
1148 * vaGetImage with other surfaces is supported.
1150 * An image created with vaDeriveImage should be freed with vaDestroyImage. The
1151 * image and image buffer structures will be destroyed; however, the underlying
1152 * surface will remain unchanged until freed with vaDestroySurfaces.
1154 VAStatus vaDeriveImage (
1156 VASurfaceID surface,
1157 VAImage *image /* out */
1160 VADriverContextP ctx;
1164 return ctx->vtable->vaDeriveImage ( ctx, surface, image );
1168 /* Get maximum number of subpicture formats supported by the implementation */
1169 int vaMaxNumSubpictureFormats (
1173 if (!vaDisplayIsValid(dpy))
1176 return CTX(dpy)->max_subpic_formats;
1180 * Query supported subpicture formats
1181 * The caller must provide a "format_list" array that can hold at
1182 * least vaMaxNumSubpictureFormats() entries. The flags arrary holds the flag
1183 * for each format to indicate additional capabilities for that format. The actual
1184 * number of formats returned in "format_list" is returned in "num_formats".
1186 VAStatus vaQuerySubpictureFormats (
1188 VAImageFormat *format_list, /* out */
1189 unsigned int *flags, /* out */
1190 unsigned int *num_formats /* out */
1193 VADriverContextP ctx;
1198 return ctx->vtable->vaQuerySubpictureFormats ( ctx, format_list, flags, num_formats);
1202 * Subpictures are created with an image associated.
1204 VAStatus vaCreateSubpicture (
1207 VASubpictureID *subpicture /* out */
1210 VADriverContextP ctx;
1214 return ctx->vtable->vaCreateSubpicture ( ctx, image, subpicture );
1218 * Destroy the subpicture before destroying the image it is assocated to
1220 VAStatus vaDestroySubpicture (
1222 VASubpictureID subpicture
1225 VADriverContextP ctx;
1229 return ctx->vtable->vaDestroySubpicture ( ctx, subpicture);
1232 VAStatus vaSetSubpictureImage (
1234 VASubpictureID subpicture,
1238 VADriverContextP ctx;
1242 return ctx->vtable->vaSetSubpictureImage ( ctx, subpicture, image);
1247 * If chromakey is enabled, then the area where the source value falls within
1248 * the chromakey [min, max] range is transparent
1250 VAStatus vaSetSubpictureChromakey (
1252 VASubpictureID subpicture,
1253 unsigned int chromakey_min,
1254 unsigned int chromakey_max,
1255 unsigned int chromakey_mask
1258 VADriverContextP ctx;
1262 return ctx->vtable->vaSetSubpictureChromakey ( ctx, subpicture, chromakey_min, chromakey_max, chromakey_mask );
1267 * Global alpha value is between 0 and 1. A value of 1 means fully opaque and
1268 * a value of 0 means fully transparent. If per-pixel alpha is also specified then
1269 * the overall alpha is per-pixel alpha multiplied by the global alpha
1271 VAStatus vaSetSubpictureGlobalAlpha (
1273 VASubpictureID subpicture,
1277 VADriverContextP ctx;
1281 return ctx->vtable->vaSetSubpictureGlobalAlpha ( ctx, subpicture, global_alpha );
1285 vaAssociateSubpicture associates the subpicture with the target_surface.
1286 It defines the region mapping between the subpicture and the target
1287 surface through source and destination rectangles (with the same width and height).
1288 Both will be displayed at the next call to vaPutSurface. Additional
1289 associations before the call to vaPutSurface simply overrides the association.
1291 VAStatus vaAssociateSubpicture (
1293 VASubpictureID subpicture,
1294 VASurfaceID *target_surfaces,
1296 short src_x, /* upper left offset in subpicture */
1298 unsigned short src_width,
1299 unsigned short src_height,
1300 short dest_x, /* upper left offset in surface */
1302 unsigned short dest_width,
1303 unsigned short dest_height,
1305 * whether to enable chroma-keying or global-alpha
1306 * see VA_SUBPICTURE_XXX values
1311 VADriverContextP ctx;
1315 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 );
1319 * vaDeassociateSubpicture removes the association of the subpicture with target_surfaces.
1321 VAStatus vaDeassociateSubpicture (
1323 VASubpictureID subpicture,
1324 VASurfaceID *target_surfaces,
1328 VADriverContextP ctx;
1332 return ctx->vtable->vaDeassociateSubpicture ( ctx, subpicture, target_surfaces, num_surfaces );
1336 /* Get maximum number of display attributes supported by the implementation */
1337 int vaMaxNumDisplayAttributes (
1343 if (!vaDisplayIsValid(dpy))
1346 tmp = CTX(dpy)->max_display_attributes;
1348 VA_TRACE_LOG(va_TraceMaxNumDisplayAttributes, dpy, tmp);
1354 * Query display attributes
1355 * The caller must provide a "attr_list" array that can hold at
1356 * least vaMaxNumDisplayAttributes() entries. The actual number of attributes
1357 * returned in "attr_list" is returned in "num_attributes".
1359 VAStatus vaQueryDisplayAttributes (
1361 VADisplayAttribute *attr_list, /* out */
1362 int *num_attributes /* out */
1365 VADriverContextP ctx;
1370 va_status = ctx->vtable->vaQueryDisplayAttributes ( ctx, attr_list, num_attributes );
1372 VA_TRACE_LOG(va_TraceQueryDisplayAttributes, dpy, attr_list, num_attributes);
1379 * Get display attributes
1380 * This function returns the current attribute values in "attr_list".
1381 * Only attributes returned with VA_DISPLAY_ATTRIB_GETTABLE set in the "flags" field
1382 * from vaQueryDisplayAttributes() can have their values retrieved.
1384 VAStatus vaGetDisplayAttributes (
1386 VADisplayAttribute *attr_list, /* in/out */
1390 VADriverContextP ctx;
1395 va_status = ctx->vtable->vaGetDisplayAttributes ( ctx, attr_list, num_attributes );
1397 VA_TRACE_LOG(va_TraceGetDisplayAttributes, dpy, attr_list, num_attributes);
1403 * Set display attributes
1404 * Only attributes returned with VA_DISPLAY_ATTRIB_SETTABLE set in the "flags" field
1405 * from vaQueryDisplayAttributes() can be set. If the attribute is not settable or
1406 * the value is out of range, the function returns VA_STATUS_ERROR_ATTR_NOT_SUPPORTED
1408 VAStatus vaSetDisplayAttributes (
1410 VADisplayAttribute *attr_list,
1414 VADriverContextP ctx;
1419 va_status = ctx->vtable->vaSetDisplayAttributes ( ctx, attr_list, num_attributes );
1420 VA_TRACE_LOG(va_TraceSetDisplayAttributes, dpy, attr_list, num_attributes);
1425 VAStatus vaLockSurface(VADisplay dpy,
1426 VASurfaceID surface,
1427 unsigned int *fourcc, /* following are output argument */
1428 unsigned int *luma_stride,
1429 unsigned int *chroma_u_stride,
1430 unsigned int *chroma_v_stride,
1431 unsigned int *luma_offset,
1432 unsigned int *chroma_u_offset,
1433 unsigned int *chroma_v_offset,
1434 unsigned int *buffer_name,
1438 VADriverContextP ctx;
1442 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);
1446 VAStatus vaUnlockSurface(VADisplay dpy,
1450 VADriverContextP ctx;
1454 return ctx->vtable->vaUnlockSurface( ctx, surface );
1457 /* Video Processing */
1458 #define VA_VPP_INIT_CONTEXT(ctx, dpy) do { \
1459 CHECK_DISPLAY(dpy); \
1462 return VA_STATUS_ERROR_INVALID_DISPLAY; \
1465 #define VA_VPP_INVOKE(dpy, func, args) do { \
1466 if (!ctx->vtable_vpp->va##func) \
1467 return VA_STATUS_ERROR_UNIMPLEMENTED; \
1468 status = ctx->vtable_vpp->va##func args; \
1472 vaQueryVideoProcFilters(
1474 VAContextID context,
1475 VAProcFilterType *filters,
1476 unsigned int *num_filters
1479 VADriverContextP ctx;
1482 VA_VPP_INIT_CONTEXT(ctx, dpy);
1485 QueryVideoProcFilters,
1486 (ctx, context, filters, num_filters)
1492 vaQueryVideoProcFilterCaps(
1494 VAContextID context,
1495 VAProcFilterType type,
1497 unsigned int *num_filter_caps
1500 VADriverContextP ctx;
1503 VA_VPP_INIT_CONTEXT(ctx, dpy);
1506 QueryVideoProcFilterCaps,
1507 (ctx, context, type, filter_caps, num_filter_caps)
1513 vaQueryVideoProcPipelineCaps(
1515 VAContextID context,
1516 VABufferID *filters,
1517 unsigned int num_filters,
1518 VAProcPipelineCaps *pipeline_caps
1521 VADriverContextP ctx;
1524 VA_VPP_INIT_CONTEXT(ctx, dpy);
1527 QueryVideoProcPipelineCaps,
1528 (ctx, context, filters, num_filters, pipeline_caps)