From 2bbd7bac63a48361d3d848ba1d3838a0ef5eb2bd Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 25 May 2006 01:14:06 +0000 Subject: add support to disable emulation of /dev/dsp,/dev/mixer,/dev/sndstat selectively by either passing an environment variable or by defining a symbol __padsp_disable__ in the process git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@964 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/utils/padsp.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 58 insertions(+), 3 deletions(-) diff --git a/src/utils/padsp.c b/src/utils/padsp.c index 746965d7..2f0f7260 100644 --- a/src/utils/padsp.c +++ b/src/utils/padsp.c @@ -191,6 +191,61 @@ static void debug(const char *format, ...) { } } +static int padsp_disabled(void) { + static int *sym; + static int sym_resolved = 0; + + /* If the current process has a symbol __padsp_disabled__ we use + * it to detect whether we should enable our stuff or not. A + * program needs to be compiled with -rdynamic for this to work! + * The symbol must be an int containing a three bit bitmask: bit 1 + * -> disable /dev/dsp emulation, bit 2 -> disable /dev/sndstat + * emulation, bit 3 -> disable /dev/mixer emulation. Hence a value + * 7 disables padsp entirely. */ + + pthread_mutex_lock(&func_mutex); + if (!sym_resolved) { + sym = (int*) dlsym_fn(RTLD_DEFAULT, "__padsp_disabled__"); + sym_resolved = 1; + + } + pthread_mutex_unlock(&func_mutex); + + if (!sym) + return 0; + + return *sym; +} + +static int dsp_cloak_enable(void) { + if (padsp_disabled() & 1) + return 0; + + if (getenv("PADSP_NO_DSP")) + return 0; + + return 1; +} + +static int sndstat_cloak_enable(void) { + if (padsp_disabled() & 2) + return 0; + + if (getenv("PADSP_NO_SNDSTAT")) + return 0; + + return 1; +} + +static int mixer_cloak_enable(void) { + if (padsp_disabled() & 4) + return 0; + + if (getenv("PADSP_NO_MIXER")) + return 0; + + return 1; +} static pthread_key_t recursion_key; static void recursion_key_alloc(void) { @@ -1010,11 +1065,11 @@ int open(const char *filename, int flags, ...) { return _open(filename, flags, mode); } - if (strcmp(filename, "/dev/dsp") == 0 || strcmp(filename, "/dev/adsp") == 0) { + if (dsp_cloak_enable() && (strcmp(filename, "/dev/dsp") == 0 || strcmp(filename, "/dev/adsp") == 0)) { r = dsp_open(flags, &_errno); - } else if (strcmp(filename, "/dev/mixer") == 0) { + } else if (mixer_cloak_enable() && strcmp(filename, "/dev/mixer") == 0) { r = mixer_open(flags, &_errno); - } else if (strcmp(filename, "/dev/sndstat") == 0) { + } else if (sndstat_cloak_enable() && strcmp(filename, "/dev/sndstat") == 0) { r = sndstat_open(flags, &_errno); } else { function_exit(); -- cgit