diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2013-03-27 11:19:54 +0400 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2013-03-27 11:19:54 +0400 |
commit | 31eee77a4503ac38c3d9d96a5f77df86648c700c (patch) | |
tree | 6b7454f75cf78ff485e9b28f5f768daad9cd69b1 /intern/audaspace/jack/AUD_JackLibrary.cpp | |
parent | 91b2b970ade21a70c3c7289cefff6c2cbb2059cd (diff) |
Fix #33518: Jack sync doesn't work in 2.64, 2.64 or 2.65 stable versions
Added new build option WITH_JACK_DYNLOAD for CMake and
WITH_BF_JACK_DYNLOAD for SCons, which means there'll be
no build-time linking against libjack and getting symbols
from libjack will happen runtime using dlopen and dlsym
tricks.
Alternative would be to use weak linking, but it'll require
having wrapper for preloading libjack.
This new options are disabled by default and they only
intended to be used on linux. Other platforms shall not
be using this and there shall be no functional changes
on non-linux platforms at all.
Diffstat (limited to 'intern/audaspace/jack/AUD_JackLibrary.cpp')
-rw-r--r-- | intern/audaspace/jack/AUD_JackLibrary.cpp | 116 |
1 files changed, 116 insertions, 0 deletions
diff --git a/intern/audaspace/jack/AUD_JackLibrary.cpp b/intern/audaspace/jack/AUD_JackLibrary.cpp new file mode 100644 index 00000000000..150d22b324c --- /dev/null +++ b/intern/audaspace/jack/AUD_JackLibrary.cpp @@ -0,0 +1,116 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * Copyright 2013 Blender Foundation + * + * This file is part of AudaSpace. + * + * Audaspace is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * AudaSpace is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Audaspace; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file audaspace/jack/AUD_JacLibrary.cpp + * \ingroup audjack + */ + +#define AUD_JACK_LIBRARY_IMPL + +#include "AUD_JackLibrary.h" + +#ifdef WITH_JACK_DYNLOAD +# include <dlfcn.h> +# include <stdio.h> +#endif + +#ifdef WITH_JACK_DYNLOAD +static void *jack_handle = NULL; +#endif + +static bool jack_supported = false; + +void AUD_jack_init(void) +{ +#ifdef WITH_JACK_DYNLOAD + jack_handle = dlopen("libjack.so", RTLD_LAZY); + + if (!jack_handle) { + fprintf(stderr, "%s\n", dlerror()); + return; + } + +# define JACK_SYMBOL(sym) \ + { \ + char *error; \ + *(void **) (&(AUD_##sym)) = dlsym(jack_handle, #sym); \ + if ((error = dlerror()) != NULL) { \ + fprintf(stderr, "%s\n", error); \ + return; \ + } \ + } (void)0 + + dlerror(); /* Clear any existing error */ +#else // WITH_JACK_DYNLOAD +# define JACK_SYMBOL(sym) AUD_##sym = sym +#endif // WITH_JACK_DYNLOAD + + JACK_SYMBOL(jack_transport_query); + JACK_SYMBOL(jack_transport_locate); + + JACK_SYMBOL(jack_transport_start); + JACK_SYMBOL(jack_transport_stop); + + JACK_SYMBOL(jack_ringbuffer_reset); + JACK_SYMBOL(jack_ringbuffer_write); + JACK_SYMBOL(jack_ringbuffer_write_space); + JACK_SYMBOL(jack_ringbuffer_write_advance); + JACK_SYMBOL(jack_ringbuffer_read); + JACK_SYMBOL(jack_ringbuffer_create); + JACK_SYMBOL(jack_ringbuffer_free); + JACK_SYMBOL(jack_ringbuffer_read_space); + JACK_SYMBOL(jack_set_sync_callback); + + JACK_SYMBOL(jack_port_get_buffer); + + JACK_SYMBOL(jack_client_open); + JACK_SYMBOL(jack_set_process_callback); + JACK_SYMBOL(jack_on_shutdown); + JACK_SYMBOL(jack_port_register); + JACK_SYMBOL(jack_client_close); + JACK_SYMBOL(jack_get_sample_rate); + JACK_SYMBOL(jack_activate); + JACK_SYMBOL(jack_get_ports); + JACK_SYMBOL(jack_port_name); + JACK_SYMBOL(jack_connect); + + jack_supported = true; + +#undef JACK_SYMBOL +} + +void AUD_jack_exit(void) +{ +#ifdef WITH_JACK_DYNLOAD + if (jack_handle) { + dlclose(jack_handle); + } +#endif + jack_supported = false; +} + +bool AUD_jack_supported(void) +{ + return jack_supported; +} |