summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAaron Plattner <aplattner@nvidia.com>2009-11-17 00:18:05 -0800
committerAaron Plattner <aplattner@nvidia.com>2009-11-17 13:13:06 -0800
commit0537b13e292bc772e984872a3986e41fb51f9258 (patch)
tree2fef0f05e04527c7373bf557aeb8e52bad36e2d7 /src
parentf1f2b25e39b7092a94067f1c787a9b5c5c58bb5d (diff)
Move VDPAU drivers into their own module directory.
* Add a --with-module-dir configure parameter. * Pass the moduledir into the wrapper. Use it to construct the path to search for drivers. Require drivers to end in a ".1" version, in case we ever want to rev. the interface between the wrapper and the drivers. * If no driver is found in the new module dir, look for one in the default search paths. This is intended to find libvdpau_nvidia.so for drivers that predate the change to move it, and can be removed in the future. * Stash the moduledir into vdpau.pc. Drivers can find this with `pkg-config --variable=moduledir vdpau`. * Add a version to libvdpau_trace.so in case the interface between it and libvdpau.so ever changes. * Install libvdpau_trace.so.1 to moduledir instead of libdir. Signed-off-by: Aaron Plattner <aplattner@nvidia.com> Acked-by: Stephen Warren <swarren@nvidia.com>
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am1
-rw-r--r--src/vdpau_wrapper.c26
2 files changed, 18 insertions, 9 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 0bca810..923eaac 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,5 +1,6 @@
AM_CFLAGS = \
-I$(top_srcdir)/include \
+ -DVDPAU_MODULEDIR="\"$(moduledir)\"" \
$(X11_CFLAGS)
lib_LTLIBRARIES = libvdpau.la
diff --git a/src/vdpau_wrapper.c b/src/vdpau_wrapper.c
index 2687c31..a635f6c 100644
--- a/src/vdpau_wrapper.c
+++ b/src/vdpau_wrapper.c
@@ -22,6 +22,7 @@
*/
#include <dlfcn.h>
+#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -46,7 +47,7 @@ static void _vdp_wrapper_error_breakpoint(char const * file, int line, char cons
#endif
-#define DRIVER_LIB_FORMAT "libvdpau_%s.so"
+#define DRIVER_LIB_FORMAT "%slibvdpau_%s.so%s"
VdpStatus vdp_device_create_x11(
Display * display,
@@ -57,7 +58,7 @@ VdpStatus vdp_device_create_x11(
)
{
char const * vdpau_driver;
- char * vdpau_driver_lib;
+ char vdpau_driver_lib[PATH_MAX];
void * backend_dll;
char const * vdpau_trace;
char const * func_name;
@@ -70,15 +71,23 @@ VdpStatus vdp_device_create_x11(
vdpau_driver = "nvidia";
}
- vdpau_driver_lib = malloc(strlen(DRIVER_LIB_FORMAT) + strlen(vdpau_driver) + 1);
- if (!vdpau_driver_lib) {
+ if (snprintf(vdpau_driver_lib, sizeof(vdpau_driver_lib), DRIVER_LIB_FORMAT,
+ VDPAU_MODULEDIR "/", vdpau_driver, ".1") >=
+ sizeof(vdpau_driver_lib)) {
+ fprintf(stderr, "Failed to construct driver path: path too long\n");
_VDP_ERROR_BREAKPOINT();
- return VDP_STATUS_RESOURCES;
+ return VDP_STATUS_NO_IMPLEMENTATION;
}
- sprintf(vdpau_driver_lib, DRIVER_LIB_FORMAT, vdpau_driver);
backend_dll = dlopen(vdpau_driver_lib, RTLD_NOW | RTLD_GLOBAL);
- free(vdpau_driver_lib);
+ if (!backend_dll) {
+ /* Try again using the old path, which is guaranteed to fit in PATH_MAX
+ * if the complete path fit above. */
+ snprintf(vdpau_driver_lib, sizeof(vdpau_driver_lib), DRIVER_LIB_FORMAT,
+ "", vdpau_driver, "");
+ backend_dll = dlopen(vdpau_driver_lib, RTLD_NOW | RTLD_GLOBAL);
+ }
+
if (!backend_dll) {
fprintf(stderr, "Failed to open VDPAU backend %s\n", dlerror());
_VDP_ERROR_BREAKPOINT();
@@ -90,7 +99,7 @@ VdpStatus vdp_device_create_x11(
void * trace_dll;
SetDllHandle * set_dll_handle;
- trace_dll = dlopen("libvdpau_trace.so", RTLD_NOW | RTLD_GLOBAL);
+ trace_dll = dlopen(VDPAU_MODULEDIR "/libvdpau_trace.so.1", RTLD_NOW | RTLD_GLOBAL);
if (!trace_dll) {
fprintf(stderr, "Failed to open VDPAU trace library %s\n", dlerror());
_VDP_ERROR_BREAKPOINT();
@@ -134,4 +143,3 @@ VdpStatus vdp_device_create_x11(
get_proc_address
);
}
-