[VDPAU] [PATCH] Add VDPAU_DRIVER_PATH support

Emil Velikov emil.l.velikov at gmail.com
Thu Feb 6 17:57:14 PST 2014


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.

v2:
 - Fix compilation issues.

Signed-off-by: Emil Velikov <emil.l.velikov at gmail.com>
---

Hi Aaron,

I've spent a bit of time pondering on your suggestion to control
the trace library using the same env variable.

IMHO this will cause unnecessary complexity considering the
permutations between driver/tracer locations.

My initial goal was to ease the use and testing of vdpau backends,
in order to avoid rebuilding libvdpau. As the trace library is part
of libvdpau (thus defeating the purpose of the whole exercise) I'm
planning to stick with my original goal.

Cheers,
-Emil 

 include/vdpau/vdpau_x11.h |  2 ++
 src/vdpau_wrapper.c       | 14 ++++++++++++--
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/include/vdpau/vdpau_x11.h b/include/vdpau/vdpau_x11.h
index ae5a377..1aa66fe 100644
--- a/include/vdpau/vdpau_x11.h
+++ b/include/vdpau/vdpau_x11.h
@@ -81,6 +81,8 @@ extern "C" {
  *   - \c /usr/lib/vdpau/libvdpau_nvidia.so.1
  *   - \c /usr/lib/vdpau/libvdpau_intel.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
  * vdp_device_create_x11. The wrapper will implement this function
diff --git a/src/vdpau_wrapper.c b/src/vdpau_wrapper.c
index 9932937..e5f5082 100644
--- a/src/vdpau_wrapper.c
+++ b/src/vdpau_wrapper.c
@@ -30,6 +30,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <unistd.h>
 #include <vdpau/vdpau_x11.h>
 #if DRI2
 #include "mesa_dri2.h"
@@ -66,7 +67,7 @@ static void _vdp_wrapper_error_breakpoint(char const * file, int line, char cons
 
 #endif
 
-#define DRIVER_LIB_FORMAT "%slibvdpau_%s.so%s"
+#define DRIVER_LIB_FORMAT "%s/libvdpau_%s.so%s"
 
 static char * _vdp_get_driver_name_from_dri2(
     Display *             display,
@@ -107,6 +108,7 @@ static VdpStatus _vdp_open_driver(
 {
     char const * vdpau_driver;
     char * vdpau_driver_dri2 = NULL;
+    const char * vdpau_driver_path = NULL;
     char         vdpau_driver_lib[PATH_MAX];
     char const * vdpau_trace;
     char const * func_name;
@@ -120,8 +122,16 @@ static VdpStatus _vdp_open_driver(
         vdpau_driver = "nvidia";
     }
 
+    if (geteuid() == getuid()) {
+        /* don't allow setuid apps to use VDPAU_DRIVER_PATH */
+        vdpau_driver_path = getenv("VDPAU_DRIVER_PATH");
+    }
+
+    if (!vdpau_driver_path)
+        vdpau_driver_path = VDPAU_MODULEDIR;
+
     if (snprintf(vdpau_driver_lib, sizeof(vdpau_driver_lib), DRIVER_LIB_FORMAT,
-                 VDPAU_MODULEDIR "/", vdpau_driver, ".1") >=
+                 vdpau_driver_path, vdpau_driver, ".1") >=
             sizeof(vdpau_driver_lib)) {
         fprintf(stderr, "Failed to construct driver path: path too long\n");
         if (vdpau_driver_dri2) {
-- 
1.8.5.2



More information about the VDPAU mailing list