OSDN Git Service

Fix build issue again
[android-x86/hardware-intel-common-libva.git] / va / va.c
diff --git a/va/va.c b/va/va.c
index 0369044..162b110 100644 (file)
--- a/va/va.c
+++ b/va/va.c
  */
 
 #define _GNU_SOURCE 1
+#include "sysdeps.h"
 #include "va.h"
 #include "va_backend.h"
+#include "va_trace.h"
+#include "va_fool.h"
+#include "config.h"
 
 #include <assert.h>
 #include <stdarg.h>
 #include <dlfcn.h>
 #include <unistd.h>
 
-
-#define DRIVER_INIT_FUNC       "__vaDriverInit_0_31"
-
 #define DRIVER_EXTENSION       "_drv_video.so"
 
 #define CTX(dpy) (((VADisplayContextP)dpy)->pDriverContext)
 #define CHECK_DISPLAY(dpy) if( !vaDisplayIsValid(dpy) ) { return VA_STATUS_ERROR_INVALID_DISPLAY; }
 
 #define ASSERT         assert
-#define CHECK_VTABLE(s, ctx, func) if (!va_checkVtable(ctx->vtable.va##func, #func)) s = VA_STATUS_ERROR_UNKNOWN;
+#define CHECK_VTABLE(s, ctx, func) if (!va_checkVtable(ctx->vtable->va##func, #func)) s = VA_STATUS_ERROR_UNKNOWN;
 #define CHECK_MAXIMUM(s, ctx, var) if (!va_checkMaximum(ctx->max_##var, #var)) s = VA_STATUS_ERROR_UNKNOWN;
 #define CHECK_STRING(s, ctx, var) if (!va_checkString(ctx->str_##var, #var)) s = VA_STATUS_ERROR_UNKNOWN;
 
 extern int trace_flag;
 #define VA_TRACE(trace_func,...)                \
     if (trace_flag) {                           \
-        va_TraceMsg("========%s========\n", __func__);   \
         trace_func(__VA_ARGS__);                \
     }
 
-static int vaDisplayIsValid(VADisplay dpy)
+extern int fool_decode;
+extern int fool_encode;
+#define VA_FOOL(fool_func,...)                 \
+    if (fool_decode || fool_encode) {          \
+        ret = fool_func(__VA_ARGS__);          \
+    }
+
+/*
+ * read a config "env" for libva.conf or from environment setting
+ * liva.conf has higher priority
+ * return 0: the "env" is set, and the value is copied into env_value
+ *        1: the env is not set
+ */
+int va_parseConfig(char *env, char *env_value)
+{
+    char *token, *value, *saveptr;
+    char oneline[1024];
+    FILE *fp=NULL;
+
+
+    if (env == NULL)
+        return 1;
+    
+    fp = fopen("/etc/libva.conf", "r");
+    while (fp && (fgets(oneline, 1024, fp) != NULL)) {
+       if (strlen(oneline) == 1)
+           continue;
+        token = strtok_r(oneline, "=\n", &saveptr);
+       value = strtok_r(NULL, "=\n", &saveptr);
+
+       if (NULL == token || NULL == value)
+           continue;
+
+        if (strcmp(token, env) == 0) {
+            if (env_value)
+                strncpy(env_value,value, 1024);
+
+            fclose(fp);
+
+            return 0;
+        }
+    }
+    if (fp)
+        fclose(fp);
+
+    /* no setting in config file, use env setting */
+    if (getenv(env)) {
+        if (env_value)
+            strncpy(env_value, getenv(env), 1024);
+
+        return 0;
+    }
+    
+    return 1;
+}
+
+int vaDisplayIsValid(VADisplay dpy)
 {
     VADisplayContextP pDisplayContext = (VADisplayContextP)dpy;
     return pDisplayContext && (pDisplayContext->vadpy_magic == VA_DISPLAY_MAGIC) && pDisplayContext->vaIsValid(pDisplayContext);
 }
 
-static void va_errorMessage(const char *msg, ...)
+void va_errorMessage(const char *msg, ...)
 {
     va_list args;
 
@@ -70,7 +126,7 @@ static void va_errorMessage(const char *msg, ...)
     va_end(args);
 }
 
-static void va_infoMessage(const char *msg, ...)
+void va_infoMessage(const char *msg, ...)
 {
     va_list args;
 
@@ -129,10 +185,6 @@ static VAStatus va_openDriver(VADisplay dpy, char *driver_name)
     {
         /* don't allow setuid apps to use LIBVA_DRIVERS_PATH */
         search_path = getenv("LIBVA_DRIVERS_PATH");
-        if (!search_path)
-        {
-            search_path = getenv("LIBGL_DRIVERS_PATH");
-        }
     }
     if (!search_path)
     {
@@ -153,8 +205,11 @@ static VAStatus va_openDriver(VADisplay dpy, char *driver_name)
         strncat( driver_path, DRIVER_EXTENSION, strlen(DRIVER_EXTENSION) );
         
         va_infoMessage("Trying to open %s\n", driver_path);
-
+#ifndef ANDROID
         handle = dlopen( driver_path, RTLD_NOW | RTLD_GLOBAL | RTLD_NODELETE );
+#else
+        handle = dlopen( driver_path, RTLD_NOW| RTLD_GLOBAL);
+#endif
         if (!handle)
         {
             /* Don't give errors for non-existing files */
@@ -166,15 +221,26 @@ static VAStatus va_openDriver(VADisplay dpy, char *driver_name)
         else
         {
             VADriverInit init_func;
-            init_func = (VADriverInit) dlsym(handle, DRIVER_INIT_FUNC);
+            init_func = (VADriverInit) dlsym(handle, VA_DRIVER_INIT_FUNC_S);
             if (!init_func)
             {
-                va_errorMessage("%s has no function %s\n", driver_path, DRIVER_INIT_FUNC);
+                va_errorMessage("%s has no function %s\n", driver_path, VA_DRIVER_INIT_FUNC_S);
                 dlclose(handle);
             }
             else
             {
-                vaStatus = (*init_func)(ctx);
+                struct VADriverVTable *vtable = ctx->vtable;
+
+                vaStatus = VA_STATUS_SUCCESS;
+                if (!vtable) {
+                    vtable = calloc(1, sizeof(*vtable));
+                    if (!vtable)
+                        vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED;
+                }
+                ctx->vtable = vtable;
+
+                if (VA_STATUS_SUCCESS == vaStatus)
+                    vaStatus = (*init_func)(ctx);
 
                 if (VA_STATUS_SUCCESS == vaStatus)
                 {
@@ -314,6 +380,8 @@ const char *vaErrorStr(VAStatus error_status)
             return "the requested function is not implemented";
         case VA_STATUS_ERROR_SURFACE_IN_DISPLAYING:
             return "surface is in displaying (may by overlay)" ;
+        case VA_STATUS_ERROR_INVALID_IMAGE_FORMAT:
+            return "invalid VAImageFormat";
         case VA_STATUS_ERROR_UNKNOWN:
             return "unknown libva error";
     }
@@ -326,30 +394,47 @@ VAStatus vaInitialize (
     int *minor_version          /* out */
 )
 {
-  char *driver_name = NULL;
-  VAStatus vaStatus;
-  
-  CHECK_DISPLAY(dpy);
+    const char *driver_name_env = NULL;
+    char *driver_name = NULL;
+    VAStatus vaStatus;
 
-  va_TraceInit();
+    CHECK_DISPLAY(dpy);
 
-  va_infoMessage("libva version %s\n", VA_VERSION_S);
+    va_TraceInit(dpy);
 
-  vaStatus = va_getDriverName(dpy, &driver_name);
-  va_infoMessage("va_getDriverName() returns %d\n", vaStatus);
-  
-  if (VA_STATUS_SUCCESS == vaStatus)
-  {
-      vaStatus = va_openDriver(dpy, driver_name);
-      va_infoMessage("va_openDriver() returns %d\n", vaStatus);
-      
-      *major_version = VA_MAJOR_VERSION;
-      *minor_version = VA_MINOR_VERSION;
-  }
+    va_FoolInit(dpy);
 
-  if (driver_name)
-      free(driver_name);
-  return vaStatus;
+    va_infoMessage("libva version %s\n", VA_VERSION_S);
+
+    driver_name_env = getenv("LIBVA_DRIVER_NAME");
+    if (driver_name_env && geteuid() == getuid())
+    {
+        /* Don't allow setuid apps to use LIBVA_DRIVER_NAME */
+        driver_name = strdup(driver_name_env);
+        vaStatus = VA_STATUS_SUCCESS;
+        va_infoMessage("User requested driver '%s'\n", driver_name);
+    }
+    else
+    {
+        vaStatus = va_getDriverName(dpy, &driver_name);
+        va_infoMessage("va_getDriverName() returns %d\n", vaStatus);
+    }
+
+    if (VA_STATUS_SUCCESS == vaStatus)
+    {
+        vaStatus = va_openDriver(dpy, driver_name);
+        va_infoMessage("va_openDriver() returns %d\n", vaStatus);
+
+        *major_version = VA_MAJOR_VERSION;
+        *minor_version = VA_MINOR_VERSION;
+    }
+
+    if (driver_name)
+        free(driver_name);
+    
+    VA_TRACE(va_TraceInitialize, dpy, major_version, minor_version);
+
+    return vaStatus;
 }
 
 
@@ -367,17 +452,22 @@ VAStatus vaTerminate (
   CHECK_DISPLAY(dpy);
   old_ctx = CTX(dpy);
 
-  if (old_ctx->handle)
-  {
-      vaStatus = old_ctx->vtable.vaTerminate(old_ctx);
+  if (old_ctx->handle) {
+      vaStatus = old_ctx->vtable->vaTerminate(old_ctx);
       dlclose(old_ctx->handle);
       old_ctx->handle = NULL;
   }
+  free(old_ctx->vtable);
+  old_ctx->vtable = NULL;
 
   if (VA_STATUS_SUCCESS == vaStatus)
       pDisplayContext->vaDestroy(pDisplayContext);
 
-  va_TraceEnd();
+  VA_TRACE(va_TraceTerminate, dpy);
+
+  va_TraceEnd(dpy);
+
+  va_FoolEnd(dpy);
 
   return vaStatus;
 }
@@ -446,7 +536,7 @@ VAStatus vaQueryConfigEntrypoints (
   CHECK_DISPLAY(dpy);
   ctx = CTX(dpy);
 
-  return ctx->vtable.vaQueryConfigEntrypoints ( ctx, profile, entrypoints, num_entrypoints);
+  return ctx->vtable->vaQueryConfigEntrypoints ( ctx, profile, entrypoints, num_entrypoints);
 }
 
 VAStatus vaGetConfigAttributes (
@@ -461,7 +551,7 @@ VAStatus vaGetConfigAttributes (
   CHECK_DISPLAY(dpy);
   ctx = CTX(dpy);
 
-  return ctx->vtable.vaGetConfigAttributes ( ctx, profile, entrypoint, attrib_list, num_attribs );
+  return ctx->vtable->vaGetConfigAttributes ( ctx, profile, entrypoint, attrib_list, num_attribs );
 }
 
 VAStatus vaQueryConfigProfiles (
@@ -474,7 +564,7 @@ VAStatus vaQueryConfigProfiles (
   CHECK_DISPLAY(dpy);
   ctx = CTX(dpy);
 
-  return ctx->vtable.vaQueryConfigProfiles ( ctx, profile_list, num_profiles );
+  return ctx->vtable->vaQueryConfigProfiles ( ctx, profile_list, num_profiles );
 }
 
 VAStatus vaCreateConfig (
@@ -487,11 +577,19 @@ VAStatus vaCreateConfig (
 )
 {
   VADriverContextP ctx;
+  VAStatus vaStatus = VA_STATUS_SUCCESS;
+  int ret = 0;
+  
   CHECK_DISPLAY(dpy);
   ctx = CTX(dpy);
 
+  VA_FOOL(va_FoolCreateConfig, dpy, profile, entrypoint, attrib_list, num_attribs, config_id);
+
+  vaStatus =  ctx->vtable->vaCreateConfig ( ctx, profile, entrypoint, attrib_list, num_attribs, config_id );
+
   VA_TRACE(va_TraceCreateConfig, dpy, profile, entrypoint, attrib_list, num_attribs, config_id);
-  return ctx->vtable.vaCreateConfig ( ctx, profile, entrypoint, attrib_list, num_attribs, config_id );
+  
+  return vaStatus;
 }
 
 VAStatus vaDestroyConfig (
@@ -503,7 +601,7 @@ VAStatus vaDestroyConfig (
   CHECK_DISPLAY(dpy);
   ctx = CTX(dpy);
 
-  return ctx->vtable.vaDestroyConfig ( ctx, config_id );
+  return ctx->vtable->vaDestroyConfig ( ctx, config_id );
 }
 
 VAStatus vaQueryConfigAttributes (
@@ -519,7 +617,7 @@ VAStatus vaQueryConfigAttributes (
   CHECK_DISPLAY(dpy);
   ctx = CTX(dpy);
 
-  return ctx->vtable.vaQueryConfigAttributes( ctx, config_id, profile, entrypoint, attrib_list, num_attribs);
+  return ctx->vtable->vaQueryConfigAttributes( ctx, config_id, profile, entrypoint, attrib_list, num_attribs);
 }
 
 VAStatus vaCreateSurfaces (
@@ -532,11 +630,19 @@ VAStatus vaCreateSurfaces (
 )
 {
   VADriverContextP ctx;
+  VAStatus vaStatus;
+  int ret = 0;
+
   CHECK_DISPLAY(dpy);
   ctx = CTX(dpy);
 
+  vaStatus = ctx->vtable->vaCreateSurfaces( ctx, width, height, format, num_surfaces, surfaces );
+
   VA_TRACE(va_TraceCreateSurface, dpy, width, height, format, num_surfaces, surfaces);
-  return ctx->vtable.vaCreateSurfaces( ctx, width, height, format, num_surfaces, surfaces );
+
+  VA_FOOL(va_FoolCreateSurfaces, dpy, width, height, format, num_surfaces, surfaces);
+  
+  return vaStatus;
 }
 
 
@@ -550,7 +656,7 @@ VAStatus vaDestroySurfaces (
   CHECK_DISPLAY(dpy);
   ctx = CTX(dpy);
 
-  return ctx->vtable.vaDestroySurfaces( ctx, surface_list, num_surfaces );
+  return ctx->vtable->vaDestroySurfaces( ctx, surface_list, num_surfaces );
 }
 
 VAStatus vaCreateContext (
@@ -565,12 +671,17 @@ VAStatus vaCreateContext (
 )
 {
   VADriverContextP ctx;
+  VAStatus vaStatus;
+  
   CHECK_DISPLAY(dpy);
   ctx = CTX(dpy);
 
-  VA_TRACE(va_TraceCreateContext, dpy, config_id, picture_width, picture_height, flag, render_targets, num_render_targets, context);
-  return ctx->vtable.vaCreateContext( ctx, config_id, picture_width, picture_height,
+  vaStatus = ctx->vtable->vaCreateContext( ctx, config_id, picture_width, picture_height,
                                       flag, render_targets, num_render_targets, context );
+
+  VA_TRACE(va_TraceCreateContext, dpy, config_id, picture_width, picture_height, flag, render_targets, num_render_targets, context);
+
+  return vaStatus;
 }
 
 VAStatus vaDestroyContext (
@@ -582,7 +693,7 @@ VAStatus vaDestroyContext (
   CHECK_DISPLAY(dpy);
   ctx = CTX(dpy);
 
-  return ctx->vtable.vaDestroyContext( ctx, context );
+  return ctx->vtable->vaDestroyContext( ctx, context );
 }
 
 VAStatus vaCreateBuffer (
@@ -598,8 +709,13 @@ VAStatus vaCreateBuffer (
   VADriverContextP ctx;
   CHECK_DISPLAY(dpy);
   ctx = CTX(dpy);
+  int ret = 0;
 
-  return ctx->vtable.vaCreateBuffer( ctx, context, type, size, num_elements, data, buf_id);
+  VA_FOOL(va_FoolCreateBuffer, dpy, context, type, size, num_elements, data, buf_id);
+  if (ret)
+      return VA_STATUS_SUCCESS;
+
+  return ctx->vtable->vaCreateBuffer( ctx, context, type, size, num_elements, data, buf_id);
 }
 
 VAStatus vaBufferSetNumElements (
@@ -612,7 +728,7 @@ VAStatus vaBufferSetNumElements (
   CHECK_DISPLAY(dpy);
   ctx = CTX(dpy);
 
-  return ctx->vtable.vaBufferSetNumElements( ctx, buf_id, num_elements );
+  return ctx->vtable->vaBufferSetNumElements( ctx, buf_id, num_elements );
 }
 
 
@@ -623,10 +739,22 @@ VAStatus vaMapBuffer (
 )
 {
   VADriverContextP ctx;
+  VAStatus va_status;
+  int ret = 0;
+  
   CHECK_DISPLAY(dpy);
   ctx = CTX(dpy);
+  
+  VA_FOOL(va_FoolMapBuffer, dpy, buf_id, pbuf);
+  if (ret)
+      return VA_STATUS_SUCCESS;
+
+  va_status = ctx->vtable->vaMapBuffer( ctx, buf_id, pbuf );
 
-  return ctx->vtable.vaMapBuffer( ctx, buf_id, pbuf );
+  if (va_status == VA_STATUS_SUCCESS)
+      VA_TRACE(va_TraceMapBuffer, dpy, buf_id, pbuf);
+  
+  return va_status;
 }
 
 VAStatus vaUnmapBuffer (
@@ -637,8 +765,13 @@ VAStatus vaUnmapBuffer (
   VADriverContextP ctx;
   CHECK_DISPLAY(dpy);
   ctx = CTX(dpy);
+  int ret = 0;
+
+  VA_FOOL(va_FoolUnmapBuffer, dpy, buf_id);
+  if (ret)
+      return VA_STATUS_SUCCESS;
 
-  return ctx->vtable.vaUnmapBuffer( ctx, buf_id );
+  return ctx->vtable->vaUnmapBuffer( ctx, buf_id );
 }
 
 VAStatus vaDestroyBuffer (
@@ -650,7 +783,7 @@ VAStatus vaDestroyBuffer (
   CHECK_DISPLAY(dpy);
   ctx = CTX(dpy);
 
-  return ctx->vtable.vaDestroyBuffer( ctx, buffer_id );
+  return ctx->vtable->vaDestroyBuffer( ctx, buffer_id );
 }
 
 VAStatus vaBufferInfo (
@@ -666,10 +799,7 @@ VAStatus vaBufferInfo (
   CHECK_DISPLAY(dpy);
   ctx = CTX(dpy);
 
-  if (ctx->vtable.vaBufferInfo)
-      return ctx->vtable.vaBufferInfo( ctx, context, buf_id, type, size, num_elements );
-  else
-      return VA_STATUS_ERROR_UNIMPLEMENTED;
+  return ctx->vtable->vaBufferInfo( ctx, context, buf_id, type, size, num_elements );
 }
 
 VAStatus vaBeginPicture (
@@ -679,11 +809,18 @@ VAStatus vaBeginPicture (
 )
 {
   VADriverContextP ctx;
+  int ret = 0;
+
   CHECK_DISPLAY(dpy);
   ctx = CTX(dpy);
 
-  VA_TRACE(va_TraceBeginPicture, ctx, context, render_target);
-  return ctx->vtable.vaBeginPicture( ctx, context, render_target );
+  VA_TRACE(va_TraceBeginPicture, dpy, context, render_target);
+
+  VA_FOOL(va_FoolBeginPicture, dpy, context, render_target);
+  if (ret)
+      return VA_STATUS_SUCCESS;
+
+  return ctx->vtable->vaBeginPicture( ctx, context, render_target );
 }
 
 VAStatus vaRenderPicture (
@@ -694,11 +831,18 @@ VAStatus vaRenderPicture (
 )
 {
   VADriverContextP ctx;
+  int ret = 0;
+
   CHECK_DISPLAY(dpy);
   ctx = CTX(dpy);
 
+  VA_FOOL(va_FoolRenderPicture, dpy, context, buffers, num_buffers);
+  if (ret)
+      return VA_STATUS_SUCCESS;
+
   VA_TRACE(va_TraceRenderPicture, dpy, context, buffers, num_buffers);
-  return ctx->vtable.vaRenderPicture( ctx, context, buffers, num_buffers );
+
+  return ctx->vtable->vaRenderPicture( ctx, context, buffers, num_buffers );
 }
 
 VAStatus vaEndPicture (
@@ -706,12 +850,24 @@ VAStatus vaEndPicture (
     VAContextID context
 )
 {
+  VAStatus va_status;
   VADriverContextP ctx;
+  int ret = 0;
+
   CHECK_DISPLAY(dpy);
   ctx = CTX(dpy);
 
+  VA_FOOL(va_FoolEndPicture, dpy, context);
+  if (ret) {
+      VA_TRACE(va_TraceEndPicture, dpy, context);
+      return VA_STATUS_SUCCESS;
+  }
+  
+  va_status = ctx->vtable->vaEndPicture( ctx, context );
+  
   VA_TRACE(va_TraceEndPicture, dpy, context);
-  return ctx->vtable.vaEndPicture( ctx, context );
+
+  return va_status;
 }
 
 VAStatus vaSyncSurface (
@@ -719,11 +875,21 @@ VAStatus vaSyncSurface (
     VASurfaceID render_target
 )
 {
+  VAStatus va_status;
   VADriverContextP ctx;
+  int ret = 0;
+
   CHECK_DISPLAY(dpy);
   ctx = CTX(dpy);
 
-  return ctx->vtable.vaSyncSurface( ctx, render_target );
+  VA_FOOL(va_FoolSyncSurface, dpy, render_target);
+  if (ret)
+      return VA_STATUS_SUCCESS;
+  
+  va_status = ctx->vtable->vaSyncSurface( ctx, render_target );
+  VA_TRACE(va_TraceSyncSurface, dpy, render_target);
+
+  return va_status;
 }
 
 VAStatus vaQuerySurfaceStatus (
@@ -732,11 +898,35 @@ VAStatus vaQuerySurfaceStatus (
     VASurfaceStatus *status    /* out */
 )
 {
+  VAStatus va_status;
   VADriverContextP ctx;
   CHECK_DISPLAY(dpy);
   ctx = CTX(dpy);
 
-  return ctx->vtable.vaQuerySurfaceStatus( ctx, render_target, status );
+  va_status = ctx->vtable->vaQuerySurfaceStatus( ctx, render_target, status );
+
+  VA_TRACE(va_TraceQuerySurfaceStatus, dpy, render_target, status);
+
+  return va_status;
+}
+
+VAStatus vaQuerySurfaceError (
+       VADisplay dpy,
+       VASurfaceID surface,
+       VAStatus error_status,
+       void **error_info /*out*/
+)
+{
+  VAStatus va_status;
+  VADriverContextP ctx;
+  CHECK_DISPLAY(dpy);
+  ctx = CTX(dpy);
+
+  va_status = ctx->vtable->vaQuerySurfaceError( ctx, surface, error_status, error_info );
+
+  VA_TRACE(va_TraceQuerySurfaceError, dpy, surface, error_status, error_info);
+
+  return va_status;
 }
 
 /* Get maximum number of image formats supported by the implementation */
@@ -760,7 +950,7 @@ VAStatus vaQueryImageFormats (
   CHECK_DISPLAY(dpy);
   ctx = CTX(dpy);
 
-  return ctx->vtable.vaQueryImageFormats ( ctx, format_list, num_formats);
+  return ctx->vtable->vaQueryImageFormats ( ctx, format_list, num_formats);
 }
 
 /* 
@@ -783,7 +973,7 @@ VAStatus vaCreateImage (
   CHECK_DISPLAY(dpy);
   ctx = CTX(dpy);
 
-  return ctx->vtable.vaCreateImage ( ctx, format, width, height, image);
+  return ctx->vtable->vaCreateImage ( ctx, format, width, height, image);
 }
 
 /*
@@ -798,7 +988,7 @@ VAStatus vaDestroyImage (
   CHECK_DISPLAY(dpy);
   ctx = CTX(dpy);
 
-  return ctx->vtable.vaDestroyImage ( ctx, image);
+  return ctx->vtable->vaDestroyImage ( ctx, image);
 }
 
 VAStatus vaSetImagePalette (
@@ -811,7 +1001,7 @@ VAStatus vaSetImagePalette (
   CHECK_DISPLAY(dpy);
   ctx = CTX(dpy);
 
-  return ctx->vtable.vaSetImagePalette ( ctx, image, palette);
+  return ctx->vtable->vaSetImagePalette ( ctx, image, palette);
 }
 
 /*
@@ -832,7 +1022,7 @@ VAStatus vaGetImage (
   CHECK_DISPLAY(dpy);
   ctx = CTX(dpy);
 
-  return ctx->vtable.vaGetImage ( ctx, surface, x, y, width, height, image);
+  return ctx->vtable->vaGetImage ( ctx, surface, x, y, width, height, image);
 }
 
 /*
@@ -857,7 +1047,7 @@ VAStatus vaPutImage (
   CHECK_DISPLAY(dpy);
   ctx = CTX(dpy);
 
-  return ctx->vtable.vaPutImage ( ctx, surface, image, src_x, src_y, src_width, src_height, dest_x, dest_y, dest_width, dest_height );
+  return ctx->vtable->vaPutImage ( ctx, surface, image, src_x, src_y, src_width, src_height, dest_x, dest_y, dest_width, dest_height );
 }
 
 /*
@@ -901,7 +1091,7 @@ VAStatus vaDeriveImage (
   CHECK_DISPLAY(dpy);
   ctx = CTX(dpy);
 
-  return ctx->vtable.vaDeriveImage ( ctx, surface, image );
+  return ctx->vtable->vaDeriveImage ( ctx, surface, image );
 }
 
 
@@ -931,10 +1121,16 @@ VAStatus vaQuerySubpictureFormats (
 )
 {
   VADriverContextP ctx;
+  int ret = 0;
+
   CHECK_DISPLAY(dpy);
   ctx = CTX(dpy);
 
-  return ctx->vtable.vaQuerySubpictureFormats ( ctx, format_list, flags, num_formats);
+  VA_FOOL(va_FoolQuerySubpictureFormats, dpy, format_list, flags, num_formats);
+  if (ret)
+      return VA_STATUS_SUCCESS;
+
+  return ctx->vtable->vaQuerySubpictureFormats ( ctx, format_list, flags, num_formats);
 }
 
 /* 
@@ -950,7 +1146,7 @@ VAStatus vaCreateSubpicture (
   CHECK_DISPLAY(dpy);
   ctx = CTX(dpy);
 
-  return ctx->vtable.vaCreateSubpicture ( ctx, image, subpicture );
+  return ctx->vtable->vaCreateSubpicture ( ctx, image, subpicture );
 }
 
 /*
@@ -965,7 +1161,7 @@ VAStatus vaDestroySubpicture (
   CHECK_DISPLAY(dpy);
   ctx = CTX(dpy);
 
-  return ctx->vtable.vaDestroySubpicture ( ctx, subpicture);
+  return ctx->vtable->vaDestroySubpicture ( ctx, subpicture);
 }
 
 VAStatus vaSetSubpictureImage (
@@ -978,7 +1174,7 @@ VAStatus vaSetSubpictureImage (
   CHECK_DISPLAY(dpy);
   ctx = CTX(dpy);
 
-  return ctx->vtable.vaSetSubpictureImage ( ctx, subpicture, image);
+  return ctx->vtable->vaSetSubpictureImage ( ctx, subpicture, image);
 }
 
 
@@ -998,7 +1194,7 @@ VAStatus vaSetSubpictureChromakey (
   CHECK_DISPLAY(dpy);
   ctx = CTX(dpy);
 
-  return ctx->vtable.vaSetSubpictureChromakey ( ctx, subpicture, chromakey_min, chromakey_max, chromakey_mask );
+  return ctx->vtable->vaSetSubpictureChromakey ( ctx, subpicture, chromakey_min, chromakey_max, chromakey_mask );
 }
 
 
@@ -1017,7 +1213,7 @@ VAStatus vaSetSubpictureGlobalAlpha (
   CHECK_DISPLAY(dpy);
   ctx = CTX(dpy);
 
-  return ctx->vtable.vaSetSubpictureGlobalAlpha ( ctx, subpicture, global_alpha );
+  return ctx->vtable->vaSetSubpictureGlobalAlpha ( ctx, subpicture, global_alpha );
 }
 
 /*
@@ -1051,7 +1247,7 @@ VAStatus vaAssociateSubpicture (
   CHECK_DISPLAY(dpy);
   ctx = CTX(dpy);
 
-  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 );
+  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 );
 }
 
 /*
@@ -1068,7 +1264,7 @@ VAStatus vaDeassociateSubpicture (
   CHECK_DISPLAY(dpy);
   ctx = CTX(dpy);
 
-  return ctx->vtable.vaDeassociateSubpicture ( ctx, subpicture, target_surfaces, num_surfaces );
+  return ctx->vtable->vaDeassociateSubpicture ( ctx, subpicture, target_surfaces, num_surfaces );
 }
 
 
@@ -1077,10 +1273,16 @@ int vaMaxNumDisplayAttributes (
     VADisplay dpy
 )
 {
+  int tmp;
+    
   if( !vaDisplayIsValid(dpy) )
       return 0;
   
-  return CTX(dpy)->max_display_attributes;
+  tmp = CTX(dpy)->max_display_attributes;
+
+  VA_TRACE(va_TraceMaxNumDisplayAttributes, dpy, tmp);
+  
+  return tmp;
 }
 
 /* 
@@ -1099,7 +1301,14 @@ VAStatus vaQueryDisplayAttributes (
   CHECK_DISPLAY(dpy);
   ctx = CTX(dpy);
 
-  return ctx->vtable.vaQueryDisplayAttributes ( ctx, attr_list, num_attributes );
+  VAStatus va_status;
+  
+  va_status = ctx->vtable->vaQueryDisplayAttributes ( ctx, attr_list, num_attributes );
+
+  VA_TRACE(va_TraceQueryDisplayAttributes, dpy, attr_list, num_attributes);
+
+  return va_status;
+  
 }
 
 /* 
@@ -1118,7 +1327,13 @@ VAStatus vaGetDisplayAttributes (
   CHECK_DISPLAY(dpy);
   ctx = CTX(dpy);
 
-  return ctx->vtable.vaGetDisplayAttributes ( ctx, attr_list, num_attributes );
+  VAStatus va_status;
+  
+  va_status = ctx->vtable->vaGetDisplayAttributes ( ctx, attr_list, num_attributes );
+
+  VA_TRACE(va_TraceGetDisplayAttributes, dpy, attr_list, num_attributes);
+  
+  return va_status;
 }
 
 /* 
@@ -1137,70 +1352,13 @@ VAStatus vaSetDisplayAttributes (
   CHECK_DISPLAY(dpy);
   ctx = CTX(dpy);
 
-  return ctx->vtable.vaSetDisplayAttributes ( ctx, attr_list, num_attributes );
-}
+  VA_TRACE(va_TraceSetDisplayAttributes, dpy, attr_list, num_attributes);
 
-/* Wrap a CI (camera imaging) frame as a VA surface to share captured video between camear
- * and VA encode. With frame_id, VA driver need to call CI interfaces to get the information
- * of the frame, and to determine if the frame can be wrapped as a VA surface
- *
- * Application should make sure the frame is idle before the frame is passed into VA stack
- * and also a vaSyncSurface should be called before application tries to access the frame
- * from CI stack
- */
-VAStatus vaCreateSurfaceFromCIFrame (
-    VADisplay dpy,
-    unsigned long frame_id,
-    VASurfaceID *surface       /* out */
-)
-{
-  VADriverContextP ctx;
-  CHECK_DISPLAY(dpy);
-  ctx = CTX(dpy);
-
-  if (ctx->vtable.vaCreateSurfaceFromCIFrame)
-      return ctx->vtable.vaCreateSurfaceFromCIFrame( ctx, frame_id, surface );
-  else
-      return VA_STATUS_ERROR_UNIMPLEMENTED;
-}
-
-
-/* Wrap a V4L2 buffer as a VA surface, so that V4L2 camera, VA encode
- * can share the data without copy
- * The VA driver should query the camera device from v4l2_fd to see
- * if camera device memory/buffer can be wrapped into a VA surface
- * Buffer information is passed in by v4l2_fmt and v4l2_buf structure,
- * VA driver also needs do further check if the buffer can meet encode
- * hardware requirement, such as dimension, fourcc, stride, etc
- *
- * Application should make sure the buffer is idle before the frame into VA stack
- * and also a vaSyncSurface should be called before application tries to access the frame
- * from V4L2 stack
- */
-VAStatus vaCreateSurfaceFromV4L2Buf(
-    VADisplay dpy,
-    int v4l2_fd,         /* file descriptor of V4L2 device */
-    struct v4l2_format *v4l2_fmt,       /* format of V4L2 */
-    struct v4l2_buffer *v4l2_buf,       /* V4L2 buffer */
-    VASurfaceID *surface              /* out */
-)
-{
-  VADriverContextP ctx;
-  CHECK_DISPLAY(dpy);
-  ctx = CTX(dpy);
-
-  if (ctx->vtable.vaCreateSurfaceFromV4L2Buf) 
-      return ctx->vtable.vaCreateSurfaceFromV4L2Buf( ctx, v4l2_fd, v4l2_fmt, v4l2_buf, surface );
-  else
-      return VA_STATUS_ERROR_UNKNOWN;
+  
+  return ctx->vtable->vaSetDisplayAttributes ( ctx, attr_list, num_attributes );
 }
 
-/* It is a debug interface, and isn't exported in core VAAPI
- * It is used to dump surface data into system memory
- * Application should explicitly call free to release the buffer memory
- */
-
-VAStatus vaCopySurfaceToBuffer(VADisplay dpy,
+VAStatus vaLockSurface(VADisplay dpy,
     VASurfaceID surface,
     unsigned int *fourcc, /* following are output argument */
     unsigned int *luma_stride,
@@ -1209,6 +1367,7 @@ VAStatus vaCopySurfaceToBuffer(VADisplay dpy,
     unsigned int *luma_offset,
     unsigned int *chroma_u_offset,
     unsigned int *chroma_v_offset,
+    unsigned int *buffer_name,
     void **buffer 
 )
 {
@@ -1216,8 +1375,17 @@ VAStatus vaCopySurfaceToBuffer(VADisplay dpy,
   CHECK_DISPLAY(dpy);
   ctx = CTX(dpy);
 
-  if (ctx->vtable.vaCopySurfaceToBuffer)
-      return ctx->vtable.vaCopySurfaceToBuffer( ctx, surface, fourcc, luma_stride, chroma_u_stride, chroma_v_stride, luma_offset, chroma_u_offset, chroma_v_offset, buffer);
-  else
-      return VA_STATUS_ERROR_UNIMPLEMENTED;
+  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);
+}
+
+
+VAStatus vaUnlockSurface(VADisplay dpy,
+    VASurfaceID surface
+)
+{
+  VADriverContextP ctx;
+  CHECK_DISPLAY(dpy);
+  ctx = CTX(dpy);
+
+  return ctx->vtable->vaUnlockSurface( ctx, surface );
 }