From a3c677effbbe96b7c19fa7c012e4f9cf318c2b2c Mon Sep 17 00:00:00 2001 From: Sil Vilerino Date: Fri, 3 Feb 2023 13:08:47 -0500 Subject: [PATCH 1/2] va: Let the backends optionally provide the absolute path for driver loading - Split va_OpenDriver into va_OpenDriverFromPath and va_OpenDriverFromName to allow for absolute path driver loading and separate the dlopen logic from the possible paths calculation and iteration - Add new backend function vaGetDriverPathByIndex for driver candidate loading by absolute path - Rename va_getDriverNameByIndex to va_getDriverCandidateByIndex which will now get the driver name or path from the backend. - Rewrite va_openDriver which will now attempt to load the driver from the usual previous driver name and path construction process or use the new absolute path loading mechanism with or without LIBVA_DRIVERS_PATH env variable override. - Add extra attempt to load driver in va_OpenDriver without the drv_video suffix (win32 backend will need this) The two ways with/without suffix is for apps backward compatibility Signed-off-by: Sil Vilerino --- va/va.c | 350 +++++++++++++++++++++++++++++++++----------------------- 1 file changed, 204 insertions(+), 146 deletions(-) diff --git a/va/va.c b/va/va.c index fb62442a9..bbd9d2dcb 100644 --- a/va/va.c +++ b/va/va.c @@ -36,22 +36,29 @@ #include #include #include +#ifndef _MSC_VER +#include +#endif #if defined(_WIN32) #include "compat_win32.h" -#define DRIVER_EXTENSION "_drv_video.dll" -#define DRIVER_PATH_STRING "%s\\%s%s" +#define VA_GET_DRIVER_NAME_HAS_PATH true +#define DRIVER_EXTENSION ".dll" +#define DRIVER_PATH_STRING "%s\\%s%s%s" #define ENV_VAR_SEPARATOR ";" #else #include #include -#define DRIVER_EXTENSION "_drv_video.so" -#define DRIVER_PATH_STRING "%s/%s%s" +#define VA_GET_DRIVER_NAME_HAS_PATH false +#define DRIVER_EXTENSION ".so" +#define DRIVER_PATH_STRING "%s/%s%s%s" #define ENV_VAR_SEPARATOR ":" #endif #ifdef ANDROID #include #endif +#define DRIVER_SUFFIX "_drv_video" + #define ASSERT assert #define CHECK_VTABLE(s, ctx, func) if (!va_checkVtable(dpy, ctx->vtable->va##func, #func)) s = VA_STATUS_ERROR_UNIMPLEMENTED; #define CHECK_MAXIMUM(s, ctx, var) if (!va_checkMaximum(dpy, ctx->max_##var, #var)) s = VA_STATUS_ERROR_UNKNOWN; @@ -71,6 +78,18 @@ static char * secure_getenv(const char *name) } #endif +inline void filename_from_path(const char* absolute_path, char* filename, size_t filename_size) +{ +#ifdef _MSC_VER + _splitpath_s(absolute_path, NULL, 0, NULL, 0, filename, filename_size, NULL, 0); +#else + strncpy(filename, basename((char*)absolute_path), filename_size); + char* ext_pos = strrchr(filename, '.'); + if (ext_pos != NULL) + *ext_pos = '\0'; +#endif +} + /* * read a config "env" for libva.conf or from environment setting * libva.conf has higher priority @@ -371,12 +390,13 @@ static VAStatus va_getDriverNumCandidates(VADisplay dpy, int *num_candidates) return vaStatus; } -static VAStatus va_getDriverNameByIndex(VADisplay dpy, char **driver_name, int candidate_index) +static VAStatus va_getDriverNameByIndex(VADisplay dpy, char **driver_name, int candidate_index, bool *driver_name_is_path) { VADisplayContextP pDisplayContext = (VADisplayContextP)dpy; const char *driver_name_env = NULL; VADriverContextP ctx; VAStatus status = VA_STATUS_SUCCESS; + *driver_name_is_path = VA_GET_DRIVER_NAME_HAS_PATH; ctx = CTX(dpy); if (pDisplayContext->vaGetDriverNameByIndex) { @@ -399,6 +419,7 @@ static VAStatus va_getDriverNameByIndex(VADisplay dpy, char **driver_name, int c return VA_STATUS_ERROR_ALLOCATION_FAILED; } va_infoMessage(dpy, "User requested driver '%s'\n", *driver_name); + *driver_name_is_path = false; return VA_STATUS_SUCCESS; } else if (driver_name_env && (geteuid() == getuid())) { if (*driver_name) @@ -406,21 +427,22 @@ static VAStatus va_getDriverNameByIndex(VADisplay dpy, char **driver_name, int c /*if user set driver name by environment variable*/ *driver_name = strdup(driver_name_env); va_infoMessage(dpy, "User environment variable requested driver '%s'\n", *driver_name); + *driver_name_is_path = false; return VA_STATUS_SUCCESS; } return status; } -static char *va_getDriverPath(const char *driver_dir, const char *driver_name) +static char *va_getDriverPath(const char *driver_dir, const char *driver_name, bool add_name_suffix) { - int n = snprintf(0, 0, DRIVER_PATH_STRING, driver_dir, driver_name, DRIVER_EXTENSION); + int n = snprintf(0, 0, DRIVER_PATH_STRING, driver_dir, driver_name, add_name_suffix ? DRIVER_SUFFIX : "", DRIVER_EXTENSION); if (n < 0) return NULL; char *driver_path = (char *) malloc(n + 1); if (!driver_path) return NULL; n = snprintf(driver_path, n + 1, DRIVER_PATH_STRING, - driver_dir, driver_name, DRIVER_EXTENSION); + driver_dir, driver_name, add_name_suffix ? DRIVER_SUFFIX : "", DRIVER_EXTENSION); if (n < 0) { free(driver_path); return NULL; @@ -428,9 +450,146 @@ static char *va_getDriverPath(const char *driver_dir, const char *driver_name) return driver_path; } -static VAStatus va_openDriver(VADisplay dpy, char *driver_name) +static VAStatus va_openDriverFromPath(VADisplay dpy, char *driver_path) { VADriverContextP ctx = CTX(dpy); + VAStatus vaStatus = VA_STATUS_ERROR_UNKNOWN; + va_infoMessage(dpy, "Trying to open %s\n", driver_path); +#if defined(RTLD_NODELETE) && !defined(ANDROID) + void* handle = dlopen(driver_path, RTLD_NOW | RTLD_GLOBAL | RTLD_NODELETE); +#else + void* handle = dlopen(driver_path, RTLD_NOW | RTLD_GLOBAL); +#endif + if (!handle) { + /* Don't give errors for non-existing files */ + if (0 == access(driver_path, F_OK)) + va_errorMessage(dpy, "dlopen of %s failed: %s\n", driver_path, dlerror()); + } else { + VADriverInit init_func = NULL; + char init_func_s[256]; + int i; + + struct { + int major; + int minor; + } compatible_versions[VA_MINOR_VERSION + 2]; + for (i = 0; i <= VA_MINOR_VERSION; i ++) { + compatible_versions[i].major = VA_MAJOR_VERSION; + compatible_versions[i].minor = VA_MINOR_VERSION - i; + } + compatible_versions[i].major = -1; + compatible_versions[i].minor = -1; + + for (i = 0; compatible_versions[i].major >= 0; i++) { + if (va_getDriverInitName(init_func_s, sizeof(init_func_s), + compatible_versions[i].major, + compatible_versions[i].minor)) { + init_func = (VADriverInit)dlsym(handle, init_func_s); + if (init_func) { + va_infoMessage(dpy, "Found init function %s\n", init_func_s); + break; + } + } + } + + if (compatible_versions[i].major < 0) { + va_errorMessage(dpy, "%s has no function %s\n", + driver_path, init_func_s); + dlclose(handle); + } else { + struct VADriverVTable *vtable = ctx->vtable; + struct VADriverVTableVPP *vtable_vpp = ctx->vtable_vpp; + struct VADriverVTableProt *vtable_prot = ctx->vtable_prot; + + vaStatus = VA_STATUS_SUCCESS; + if (!vtable) { + vtable = calloc(1, sizeof(*vtable)); + if (!vtable) + vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED; + } + ctx->vtable = vtable; + + if (!vtable_vpp) { + vtable_vpp = calloc(1, sizeof(*vtable_vpp)); + if (vtable_vpp) + vtable_vpp->version = VA_DRIVER_VTABLE_VPP_VERSION; + else + vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED; + } + ctx->vtable_vpp = vtable_vpp; + + if (!vtable_prot) { + vtable_prot = calloc(1, sizeof(*vtable_prot)); + if (vtable_prot) + vtable_prot->version = VA_DRIVER_VTABLE_PROT_VERSION; + else + vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED; + } + ctx->vtable_prot = vtable_prot; + + if (init_func && VA_STATUS_SUCCESS == vaStatus) + vaStatus = (*init_func)(ctx); + + if (VA_STATUS_SUCCESS == vaStatus) { + CHECK_MAXIMUM(vaStatus, ctx, profiles); + CHECK_MAXIMUM(vaStatus, ctx, entrypoints); + CHECK_MAXIMUM(vaStatus, ctx, attributes); + CHECK_MAXIMUM(vaStatus, ctx, image_formats); + CHECK_MAXIMUM(vaStatus, ctx, subpic_formats); + CHECK_STRING(vaStatus, ctx, vendor); + CHECK_VTABLE(vaStatus, ctx, Terminate); + CHECK_VTABLE(vaStatus, ctx, QueryConfigProfiles); + CHECK_VTABLE(vaStatus, ctx, QueryConfigEntrypoints); + CHECK_VTABLE(vaStatus, ctx, QueryConfigAttributes); + CHECK_VTABLE(vaStatus, ctx, CreateConfig); + CHECK_VTABLE(vaStatus, ctx, DestroyConfig); + CHECK_VTABLE(vaStatus, ctx, GetConfigAttributes); + CHECK_VTABLE(vaStatus, ctx, CreateSurfaces); + CHECK_VTABLE(vaStatus, ctx, DestroySurfaces); + CHECK_VTABLE(vaStatus, ctx, CreateContext); + CHECK_VTABLE(vaStatus, ctx, DestroyContext); + CHECK_VTABLE(vaStatus, ctx, CreateBuffer); + CHECK_VTABLE(vaStatus, ctx, BufferSetNumElements); + CHECK_VTABLE(vaStatus, ctx, MapBuffer); + CHECK_VTABLE(vaStatus, ctx, UnmapBuffer); + CHECK_VTABLE(vaStatus, ctx, DestroyBuffer); + CHECK_VTABLE(vaStatus, ctx, BeginPicture); + CHECK_VTABLE(vaStatus, ctx, RenderPicture); + CHECK_VTABLE(vaStatus, ctx, EndPicture); + CHECK_VTABLE(vaStatus, ctx, SyncSurface); + CHECK_VTABLE(vaStatus, ctx, QuerySurfaceStatus); + CHECK_VTABLE(vaStatus, ctx, QueryImageFormats); + CHECK_VTABLE(vaStatus, ctx, CreateImage); + CHECK_VTABLE(vaStatus, ctx, DeriveImage); + CHECK_VTABLE(vaStatus, ctx, DestroyImage); + CHECK_VTABLE(vaStatus, ctx, SetImagePalette); + CHECK_VTABLE(vaStatus, ctx, GetImage); + CHECK_VTABLE(vaStatus, ctx, PutImage); + CHECK_VTABLE(vaStatus, ctx, QuerySubpictureFormats); + CHECK_VTABLE(vaStatus, ctx, CreateSubpicture); + CHECK_VTABLE(vaStatus, ctx, DestroySubpicture); + CHECK_VTABLE(vaStatus, ctx, SetSubpictureImage); + CHECK_VTABLE(vaStatus, ctx, SetSubpictureChromakey); + CHECK_VTABLE(vaStatus, ctx, SetSubpictureGlobalAlpha); + CHECK_VTABLE(vaStatus, ctx, AssociateSubpicture); + CHECK_VTABLE(vaStatus, ctx, DeassociateSubpicture); + CHECK_VTABLE(vaStatus, ctx, QueryDisplayAttributes); + CHECK_VTABLE(vaStatus, ctx, GetDisplayAttributes); + CHECK_VTABLE(vaStatus, ctx, SetDisplayAttributes); + } + if (VA_STATUS_SUCCESS != vaStatus) { + va_errorMessage(dpy, "%s init failed\n", driver_path); + dlclose(handle); + } + if (VA_STATUS_SUCCESS == vaStatus) + ctx->handle = handle; + } + } + return vaStatus; +} + +static VAStatus va_openDriverFromName(VADisplay dpy, char *driver_name, bool add_name_suffix) +{ VAStatus vaStatus = VA_STATUS_ERROR_UNKNOWN; char *search_path = NULL; char *saveptr; @@ -450,8 +609,7 @@ static VAStatus va_openDriver(VADisplay dpy, char *driver_name) } driver_dir = strtok_r(search_path, ENV_VAR_SEPARATOR, &saveptr); while (driver_dir) { - void *handle = NULL; - char *driver_path = va_getDriverPath(driver_dir, driver_name); + char *driver_path = va_getDriverPath(driver_dir, driver_name, add_name_suffix); if (!driver_path) { va_errorMessage(dpy, "%s L%d Out of memory\n", __FUNCTION__, __LINE__); @@ -459,140 +617,10 @@ static VAStatus va_openDriver(VADisplay dpy, char *driver_name) return VA_STATUS_ERROR_ALLOCATION_FAILED; } - va_infoMessage(dpy, "Trying to open %s\n", driver_path); -#if defined(RTLD_NODELETE) && !defined(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 */ - if (0 == access(driver_path, F_OK)) - va_errorMessage(dpy, "dlopen of %s failed: %s\n", driver_path, dlerror()); - } else { - VADriverInit init_func = NULL; - char init_func_s[256]; - int i; - - struct { - int major; - int minor; - } compatible_versions[VA_MINOR_VERSION + 2]; - for (i = 0; i <= VA_MINOR_VERSION; i ++) { - compatible_versions[i].major = VA_MAJOR_VERSION; - compatible_versions[i].minor = VA_MINOR_VERSION - i; - } - compatible_versions[i].major = -1; - compatible_versions[i].minor = -1; - - for (i = 0; compatible_versions[i].major >= 0; i++) { - if (va_getDriverInitName(init_func_s, sizeof(init_func_s), - compatible_versions[i].major, - compatible_versions[i].minor)) { - init_func = (VADriverInit)dlsym(handle, init_func_s); - if (init_func) { - va_infoMessage(dpy, "Found init function %s\n", init_func_s); - break; - } - } - } - - if (compatible_versions[i].major < 0) { - va_errorMessage(dpy, "%s has no function %s\n", - driver_path, init_func_s); - dlclose(handle); - } else { - struct VADriverVTable *vtable = ctx->vtable; - struct VADriverVTableVPP *vtable_vpp = ctx->vtable_vpp; - struct VADriverVTableProt *vtable_prot = ctx->vtable_prot; - - vaStatus = VA_STATUS_SUCCESS; - if (!vtable) { - vtable = calloc(1, sizeof(*vtable)); - if (!vtable) - vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED; - } - ctx->vtable = vtable; - - if (!vtable_vpp) { - vtable_vpp = calloc(1, sizeof(*vtable_vpp)); - if (vtable_vpp) - vtable_vpp->version = VA_DRIVER_VTABLE_VPP_VERSION; - else - vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED; - } - ctx->vtable_vpp = vtable_vpp; - - if (!vtable_prot) { - vtable_prot = calloc(1, sizeof(*vtable_prot)); - if (vtable_prot) - vtable_prot->version = VA_DRIVER_VTABLE_PROT_VERSION; - else - vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED; - } - ctx->vtable_prot = vtable_prot; - - if (init_func && VA_STATUS_SUCCESS == vaStatus) - vaStatus = (*init_func)(ctx); - - if (VA_STATUS_SUCCESS == vaStatus) { - CHECK_MAXIMUM(vaStatus, ctx, profiles); - CHECK_MAXIMUM(vaStatus, ctx, entrypoints); - CHECK_MAXIMUM(vaStatus, ctx, attributes); - CHECK_MAXIMUM(vaStatus, ctx, image_formats); - CHECK_MAXIMUM(vaStatus, ctx, subpic_formats); - CHECK_STRING(vaStatus, ctx, vendor); - CHECK_VTABLE(vaStatus, ctx, Terminate); - CHECK_VTABLE(vaStatus, ctx, QueryConfigProfiles); - CHECK_VTABLE(vaStatus, ctx, QueryConfigEntrypoints); - CHECK_VTABLE(vaStatus, ctx, QueryConfigAttributes); - CHECK_VTABLE(vaStatus, ctx, CreateConfig); - CHECK_VTABLE(vaStatus, ctx, DestroyConfig); - CHECK_VTABLE(vaStatus, ctx, GetConfigAttributes); - CHECK_VTABLE(vaStatus, ctx, CreateSurfaces); - CHECK_VTABLE(vaStatus, ctx, DestroySurfaces); - CHECK_VTABLE(vaStatus, ctx, CreateContext); - CHECK_VTABLE(vaStatus, ctx, DestroyContext); - CHECK_VTABLE(vaStatus, ctx, CreateBuffer); - CHECK_VTABLE(vaStatus, ctx, BufferSetNumElements); - CHECK_VTABLE(vaStatus, ctx, MapBuffer); - CHECK_VTABLE(vaStatus, ctx, UnmapBuffer); - CHECK_VTABLE(vaStatus, ctx, DestroyBuffer); - CHECK_VTABLE(vaStatus, ctx, BeginPicture); - CHECK_VTABLE(vaStatus, ctx, RenderPicture); - CHECK_VTABLE(vaStatus, ctx, EndPicture); - CHECK_VTABLE(vaStatus, ctx, SyncSurface); - CHECK_VTABLE(vaStatus, ctx, QuerySurfaceStatus); - CHECK_VTABLE(vaStatus, ctx, QueryImageFormats); - CHECK_VTABLE(vaStatus, ctx, CreateImage); - CHECK_VTABLE(vaStatus, ctx, DeriveImage); - CHECK_VTABLE(vaStatus, ctx, DestroyImage); - CHECK_VTABLE(vaStatus, ctx, SetImagePalette); - CHECK_VTABLE(vaStatus, ctx, GetImage); - CHECK_VTABLE(vaStatus, ctx, PutImage); - CHECK_VTABLE(vaStatus, ctx, QuerySubpictureFormats); - CHECK_VTABLE(vaStatus, ctx, CreateSubpicture); - CHECK_VTABLE(vaStatus, ctx, DestroySubpicture); - CHECK_VTABLE(vaStatus, ctx, SetSubpictureImage); - CHECK_VTABLE(vaStatus, ctx, SetSubpictureChromakey); - CHECK_VTABLE(vaStatus, ctx, SetSubpictureGlobalAlpha); - CHECK_VTABLE(vaStatus, ctx, AssociateSubpicture); - CHECK_VTABLE(vaStatus, ctx, DeassociateSubpicture); - CHECK_VTABLE(vaStatus, ctx, QueryDisplayAttributes); - CHECK_VTABLE(vaStatus, ctx, GetDisplayAttributes); - CHECK_VTABLE(vaStatus, ctx, SetDisplayAttributes); - } - if (VA_STATUS_SUCCESS != vaStatus) { - va_errorMessage(dpy, "%s init failed\n", driver_path); - dlclose(handle); - } - if (VA_STATUS_SUCCESS == vaStatus) - ctx->handle = handle; - free(driver_path); - break; - } - } + vaStatus = va_openDriverFromPath(dpy, driver_path); free(driver_path); + if (VA_STATUS_SUCCESS == vaStatus) + break; driver_dir = strtok_r(NULL, ENV_VAR_SEPARATOR, &saveptr); } @@ -719,6 +747,35 @@ VAStatus vaSetDriverName( return VA_STATUS_SUCCESS; } +static VAStatus va_openDriver( + VADisplay dpy, + char* driver_target, + bool driver_name_is_path +) +{ + VAStatus vaStatus = VA_STATUS_SUCCESS; + if (driver_name_is_path) { + if (!getenv("LIBVA_DRIVERS_PATH")) { + vaStatus = va_openDriverFromPath(dpy, driver_target); + } else { + /* Override absolute path candidate with env var path search */ + char* filename = calloc(strlen(driver_target) + 1, sizeof(char)); + filename_from_path(driver_target, filename, strlen(driver_target) + 1); + vaStatus = va_openDriverFromName(dpy, filename, true /* add_name_suffix */); + if (vaStatus != VA_STATUS_SUCCESS) + vaStatus = va_openDriverFromName(dpy, filename, false /* add_name_suffix */); + free(filename); + } + } else { + vaStatus = va_openDriverFromName(dpy, driver_target, true /* add_name_suffix */); + if (vaStatus != VA_STATUS_SUCCESS) + vaStatus = va_openDriverFromName(dpy, driver_target, false /* add_name_suffix */); + if (vaStatus != VA_STATUS_SUCCESS) + vaStatus = va_openDriverFromPath(dpy, driver_target); + } + return vaStatus; +} + VAStatus vaInitialize( VADisplay dpy, int *major_version, /* out */ @@ -746,12 +803,13 @@ VAStatus vaInitialize( for (candidate_index = 0; candidate_index < num_candidates; candidate_index ++) { if (driver_name) free(driver_name); - vaStatus = va_getDriverNameByIndex(dpy, &driver_name, candidate_index); + bool driver_name_is_path = false; + vaStatus = va_getDriverNameByIndex(dpy, &driver_name, candidate_index, &driver_name_is_path); if (vaStatus != VA_STATUS_SUCCESS) { va_errorMessage(dpy, "vaGetDriverNameByIndex() failed with %s, driver_name = %s\n", vaErrorStr(vaStatus), driver_name); break; } - vaStatus = va_openDriver(dpy, driver_name); + vaStatus = va_openDriver(dpy, driver_name, driver_name_is_path); va_infoMessage(dpy, "va_openDriver() returns %d\n", vaStatus); if (vaStatus == VA_STATUS_SUCCESS) { From 48760f5781924118afa75c3635a77edfd919a716 Mon Sep 17 00:00:00 2001 From: Sil Vilerino Date: Fri, 3 Feb 2023 13:29:16 -0500 Subject: [PATCH 2/2] win32: Refactor for new driver loader - Implement vaGetDriverPathByIndex instead of vaGetDriverNameByIndex - Provide a default driver name to avoid having to always set LIBVA_DRIVERS_PATH on Windows Signed-off-by: Sil Vilerino --- va/win32/va_win32.c | 54 +++++++++++++++++---------------------------- 1 file changed, 20 insertions(+), 34 deletions(-) diff --git a/va/win32/va_win32.c b/va/win32/va_win32.c index a64d55c2b..e9a341abd 100644 --- a/va/win32/va_win32.c +++ b/va/win32/va_win32.c @@ -34,15 +34,15 @@ * which will be selected when provided with an adapter LUID which * does not have a registered VA driver */ -const char VAAPI_DEFAULT_DRIVER_NAME[] = "vaon12"; +const char VAAPI_DEFAULT_DRIVER_PATH[] = "vaon12_drv_video.dll"; typedef struct _VADisplayContextWin32 { LUID adapter_luid; - char registry_driver_name[MAX_PATH]; + char registry_driver_path[MAX_PATH]; bool registry_driver_available_flag; } VADisplayContextWin32; -static void LoadDriverNameFromRegistry(VADisplayContextWin32* pWin32Ctx) +static void LoadDriverPathFromRegistry(VADisplayContextWin32* pWin32Ctx) { HMODULE hGdi32 = LoadLibraryA("gdi32.dll"); if (!hGdi32) @@ -95,8 +95,8 @@ static void LoadDriverNameFromRegistry(VADisplayContextWin32* pWin32Ctx) if (!WideCharToMultiByte(CP_ACP, 0, pRegistryInfo->OutputString, RegistryInfo.OutputValueSize / sizeof(wchar_t), - pWin32Ctx->registry_driver_name, - sizeof(pWin32Ctx->registry_driver_name), + pWin32Ctx->registry_driver_path, + sizeof(pWin32Ctx->registry_driver_path), NULL, NULL)) goto cleanup; @@ -136,43 +136,29 @@ static VAStatus va_DisplayContextGetNumCandidates( int *num_candidates ) { - /* Always report the default driver name + /* Always report the default driver path If available, also add the adapter specific registered driver */ - LUID* adapter = pDisplayContext->pDriverContext->native_dpy; VADisplayContextWin32* pWin32Ctx = (VADisplayContextWin32*) pDisplayContext->opaque; - if (adapter && pWin32Ctx->registry_driver_available_flag) - *num_candidates = 2; - else - *num_candidates = 1; - + *num_candidates = pWin32Ctx->registry_driver_available_flag ? 2 : 1; return VA_STATUS_SUCCESS; } static VAStatus va_DisplayContextGetDriverNameByIndex( VADisplayContextP pDisplayContext, - char **driver_name, + char **driver_absolute_path, int candidate_index ) { - LUID* adapter = pDisplayContext->pDriverContext->native_dpy; VADisplayContextWin32* pWin32Ctx = (VADisplayContextWin32*) pDisplayContext->opaque; - if (adapter && pWin32Ctx->registry_driver_available_flag) { - /* Always prefer the adapter registered driver name as first option */ - if (candidate_index == 0) { - *driver_name = calloc(sizeof(pWin32Ctx->registry_driver_name), sizeof(char)); - memcpy(*driver_name, pWin32Ctx->registry_driver_name, sizeof(pWin32Ctx->registry_driver_name)); - } - /* Provide the default driver name as a fallback option */ - else if (candidate_index == 1) { - *driver_name = calloc(sizeof(VAAPI_DEFAULT_DRIVER_NAME), sizeof(char)); - memcpy(*driver_name, VAAPI_DEFAULT_DRIVER_NAME, sizeof(VAAPI_DEFAULT_DRIVER_NAME)); - } - } else { - /* Provide the default driver name as a fallback option */ - *driver_name = calloc(sizeof(VAAPI_DEFAULT_DRIVER_NAME), sizeof(char)); - memcpy(*driver_name, VAAPI_DEFAULT_DRIVER_NAME, sizeof(VAAPI_DEFAULT_DRIVER_NAME)); + /* Always prefer the adapter registered driver path as first option */ + if (pWin32Ctx->registry_driver_available_flag && (candidate_index == 0)) { + *driver_absolute_path = calloc(sizeof(pWin32Ctx->registry_driver_path), sizeof(char)); + memcpy(*driver_absolute_path, pWin32Ctx->registry_driver_path, sizeof(pWin32Ctx->registry_driver_path)); + return VA_STATUS_SUCCESS; } - + /* Provide the default driver path as a fallback option */ + *driver_absolute_path = calloc(sizeof(VAAPI_DEFAULT_DRIVER_PATH), sizeof(char)); + memcpy(*driver_absolute_path, VAAPI_DEFAULT_DRIVER_PATH, sizeof(VAAPI_DEFAULT_DRIVER_PATH)); return VA_STATUS_SUCCESS; } @@ -202,12 +188,12 @@ VADisplay vaGetDisplayWin32( /* Copy LUID information to display context */ memcpy(&pWin32Ctx->adapter_luid, adapter_luid, sizeof(pWin32Ctx->adapter_luid)); - /* Load the preferred driver name from the driver registry if available */ - LoadDriverNameFromRegistry(pWin32Ctx); + /* Load the preferred driver path from the driver registry if available */ + LoadDriverPathFromRegistry(pWin32Ctx); if (pWin32Ctx->registry_driver_available_flag) { - fprintf(stderr, "VA_Win32: Found driver %s in the registry for LUID %ld %ld \n", pWin32Ctx->registry_driver_name, pWin32Ctx->adapter_luid.LowPart, pWin32Ctx->adapter_luid.HighPart); + fprintf(stderr, "VA_Win32: Found driver %s in the registry for LUID %ld %ld \n", pWin32Ctx->registry_driver_path, pWin32Ctx->adapter_luid.LowPart, pWin32Ctx->adapter_luid.HighPart); } else { - fprintf(stderr, "VA_Win32: Couldn't find a driver in the registry for LUID %ld %ld. Using default driver: %s \n", pWin32Ctx->adapter_luid.LowPart, pWin32Ctx->adapter_luid.HighPart, VAAPI_DEFAULT_DRIVER_NAME); + fprintf(stderr, "VA_Win32: Couldn't find a driver in the registry for LUID %ld %ld. Using default driver: %s \n", pWin32Ctx->adapter_luid.LowPart, pWin32Ctx->adapter_luid.HighPart, VAAPI_DEFAULT_DRIVER_PATH); } }