Commit ee9491a1 authored by Emil Velikov's avatar Emil Velikov Committed by Aaron Plattner
Browse files

Add VDPAU_DRIVER_PATH support



Allow the user to specify the location of the backend driver,
via the VDPAU_DRIVER_PATH environment variable. This allows
easier testing of VDPAU backends without the need to rebuild
libvdpau.

Inspired by LIBGL_DRIVERS_PATH from mesa.
Signed-off-by: default avatarEmil Velikov <emil.l.velikov@gmail.com>
Acked-by: default avatarStephen Warren <swarren@nvidia.com>
Reviewed-by: default avatarAaron Plattner <aplattner@nvidia.com>
Signed-off-by: default avatarAaron Plattner <aplattner@nvidia.com>
parent 186195b1
...@@ -81,6 +81,8 @@ extern "C" { ...@@ -81,6 +81,8 @@ extern "C" {
* - \c /usr/lib/vdpau/libvdpau_nvidia.so.1 * - \c /usr/lib/vdpau/libvdpau_nvidia.so.1
* - \c /usr/lib/vdpau/libvdpau_intel.so.1 * - \c /usr/lib/vdpau/libvdpau_intel.so.1
* - \c /usr/lib/vdpau/libvdpau_ati.so.1 * - \c /usr/lib/vdpau/libvdpau_ati.so.1
* The library path can be overridden by the VDPAU_DRIVER_PATH
* environment variable.
* *
* The VDPAU wrapper library implements just one function; \ref * The VDPAU wrapper library implements just one function; \ref
* vdp_device_create_x11. The wrapper will implement this function * vdp_device_create_x11. The wrapper will implement this function
......
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <unistd.h>
#include <vdpau/vdpau_x11.h> #include <vdpau/vdpau_x11.h>
#if DRI2 #if DRI2
#include "mesa_dri2.h" #include "mesa_dri2.h"
...@@ -66,7 +67,8 @@ static void _vdp_wrapper_error_breakpoint(char const * file, int line, char cons ...@@ -66,7 +67,8 @@ static void _vdp_wrapper_error_breakpoint(char const * file, int line, char cons
#endif #endif
#define DRIVER_LIB_FORMAT "%slibvdpau_%s.so%s" #define DRIVER_FALLBACK_LIB_FORMAT "libvdpau_%s.so"
#define DRIVER_LIB_FORMAT "%s/libvdpau_%s.so.1"
static char * _vdp_get_driver_name_from_dri2( static char * _vdp_get_driver_name_from_dri2(
Display * display, Display * display,
...@@ -107,6 +109,7 @@ static VdpStatus _vdp_open_driver( ...@@ -107,6 +109,7 @@ static VdpStatus _vdp_open_driver(
{ {
char const * vdpau_driver; char const * vdpau_driver;
char * vdpau_driver_dri2 = NULL; char * vdpau_driver_dri2 = NULL;
const char * vdpau_driver_path = NULL;
char vdpau_driver_lib[PATH_MAX]; char vdpau_driver_lib[PATH_MAX];
char const * vdpau_trace; char const * vdpau_trace;
char const * func_name; char const * func_name;
...@@ -120,24 +123,41 @@ static VdpStatus _vdp_open_driver( ...@@ -120,24 +123,41 @@ static VdpStatus _vdp_open_driver(
vdpau_driver = "nvidia"; vdpau_driver = "nvidia";
} }
if (snprintf(vdpau_driver_lib, sizeof(vdpau_driver_lib), DRIVER_LIB_FORMAT, if (geteuid() == getuid()) {
VDPAU_MODULEDIR "/", vdpau_driver, ".1") >= /* don't allow setuid apps to use VDPAU_DRIVER_PATH */
sizeof(vdpau_driver_lib)) { vdpau_driver_path = getenv("VDPAU_DRIVER_PATH");
fprintf(stderr, "Failed to construct driver path: path too long\n"); if (vdpau_driver_path &&
if (vdpau_driver_dri2) { snprintf(vdpau_driver_lib, sizeof(vdpau_driver_lib),
XFree(vdpau_driver_dri2); DRIVER_LIB_FORMAT, vdpau_driver_path, vdpau_driver) <
vdpau_driver_dri2 = NULL; sizeof(vdpau_driver_lib)) {
_vdp_driver_dll = dlopen(vdpau_driver_lib, RTLD_NOW | RTLD_GLOBAL);
}
}
/* Fallback to VDPAU_MODULEDIR when VDPAU_DRIVER_PATH is not set,
* or if we fail to create the driver path/dlopen the library. */
if (!_vdp_driver_dll) {
if (snprintf(vdpau_driver_lib, sizeof(vdpau_driver_lib),
DRIVER_LIB_FORMAT, VDPAU_MODULEDIR, vdpau_driver) >=
sizeof(vdpau_driver_lib)) {
fprintf(stderr, "Failed to construct driver path: path too long\n");
if (vdpau_driver_dri2) {
XFree(vdpau_driver_dri2);
vdpau_driver_dri2 = NULL;
}
_VDP_ERROR_BREAKPOINT();
return VDP_STATUS_NO_IMPLEMENTATION;
}
else {
_vdp_driver_dll = dlopen(vdpau_driver_lib, RTLD_NOW | RTLD_GLOBAL);
} }
_VDP_ERROR_BREAKPOINT();
return VDP_STATUS_NO_IMPLEMENTATION;
} }
_vdp_driver_dll = dlopen(vdpau_driver_lib, RTLD_NOW | RTLD_GLOBAL);
if (!_vdp_driver_dll) { if (!_vdp_driver_dll) {
/* Try again using the old path, which is guaranteed to fit in PATH_MAX /* Try again using the old path, which is guaranteed to fit in PATH_MAX
* if the complete path fit above. */ * if the complete path fit above. */
snprintf(vdpau_driver_lib, sizeof(vdpau_driver_lib), DRIVER_LIB_FORMAT, snprintf(vdpau_driver_lib, sizeof(vdpau_driver_lib),
"", vdpau_driver, ""); DRIVER_FALLBACK_LIB_FORMAT, vdpau_driver);
_vdp_driver_dll = dlopen(vdpau_driver_lib, RTLD_NOW | RTLD_GLOBAL); _vdp_driver_dll = dlopen(vdpau_driver_lib, RTLD_NOW | RTLD_GLOBAL);
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment