diff --git a/configure.ac b/configure.ac index af60fff8e..6b540e4a7 100644 --- a/configure.ac +++ b/configure.ac @@ -172,6 +172,10 @@ case $host in AC_MSG_RESULT([linux]) pulse_target_os=linux ;; + *-*-darwin*) + AC_MSG_RESULT([darwin]) + pulse_target_os=darwin + ;; *) AC_MSG_RESULT([unknown]) pulse_target_os=unknown @@ -291,15 +295,21 @@ AC_SUBST([LIBLTDL]) #### Determine build environment #### os_is_win32=0 +os_is_darwin=0 case "$host_os" in mingw*) AC_DEFINE([OS_IS_WIN32], 1, [Build target is Windows.]) os_is_win32=1 ;; + darwin*) + AC_DEFINE([OS_IS_DARWIN], 1, [Build target is Darwin.]) + os_is_darwin=1 + ;; esac AM_CONDITIONAL(OS_IS_WIN32, test "x$os_is_win32" = "x1") +AM_CONDITIONAL(OS_IS_DARWIN, test "x$os_is_darwin" = "x1") ################################### # Basic environment checks # @@ -403,6 +413,22 @@ AC_SEARCH_LIBS([backtrace], [execinfo]) # build, disabling its ability to make dlls. AC_CHECK_FUNCS([getopt_long], [], [AC_CHECK_LIB([iberty], [getopt_long])]) +# Darwin/OS X +if test "x$os_is_darwin" = "x1" ; then + AC_MSG_CHECKING([looking for Apple CoreService Framework]) + # How do I check a framework "library" - AC_CHECK_LIB prob. won't work??, just assign LIBS & hope + AC_CHECK_HEADER([/Developer/Headers/FlatCarbon/CoreServices.h], + [LIBS="$LIBS -framework CoreServices"], + [AC_MSG_ERROR([CoreServices.h header file not found]) ]) + + AC_MSG_RESULT([ok]) + AC_DEFINE([HAVE_CLOCK_GETTIME], 1, [Using clock_gettime() replacement]) + HAVE_BONJOUR=1 +fi + +AC_SUBST(HAVE_BONJOUR) +AM_CONDITIONAL([HAVE_BONJOUR], [test "x$HAVE_BONJOUR" = x1]) + #### Check for functions #### # ISO diff --git a/src/Makefile.am b/src/Makefile.am index 11826a42c..0224cb3fb 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -640,12 +640,21 @@ libpulsecommon_@PA_MAJORMINORMICRO@_la_SOURCES += \ pulsecore/mutex-win32.c pulsecore/mutex.h \ pulsecore/thread-win32.c pulsecore/thread.h \ pulsecore/semaphore-win32.c pulsecore/semaphore.h -else +else !OS_IS_WIN32 +if OS_IS_DARWIN +libpulsecommon_@PA_MAJORMINORMICRO@_la_SOURCES += \ + pulsecore/mutex-posix.c pulsecore/mutex.h \ + pulsecore/thread-posix.c pulsecore/thread.h \ + pulsecore/semaphore-osx.c pulsecore/semaphore.h +libpulsecommon_@PA_MAJORMINORMICRO@_la_CFLAGS += "-I/Developer/Headers/FlatCarbon/" +#libpulsecommon_@PA_MAJORMINORMICRO@_la_LDFLAGS += "-framework CoreServices" +else !OS_IS_DARWIN libpulsecommon_@PA_MAJORMINORMICRO@_la_SOURCES += \ pulsecore/mutex-posix.c pulsecore/mutex.h \ pulsecore/thread-posix.c pulsecore/thread.h \ pulsecore/semaphore-posix.c pulsecore/semaphore.h -endif +endif !OS_IS_DARWIN +endif !OS_IS_WIN32 if HAVE_X11 libpulsecommon_@PA_MAJORMINORMICRO@_la_SOURCES += pulsecore/x11prop.c pulsecore/x11prop.h @@ -1057,6 +1066,12 @@ modlibexec_LTLIBRARIES += \ module-oss.la endif +if HAVE_COREAUDIO +modlibexec_LTLIBRARIES += \ + module-coreaudio-detect.la \ + module-coreaudio-device.la +endif + pulselibexec_PROGRAMS = if HAVE_ALSA @@ -1108,6 +1123,11 @@ modlibexec_LTLIBRARIES += \ module-zeroconf-discover.la endif +if HAVE_BONJOUR +modlibexec_LTLIBRARIES += \ + module-bonjour-publish.la +endif + if HAVE_LIRC modlibexec_LTLIBRARIES += \ module-lirc.la @@ -1216,6 +1236,7 @@ SYMDEF_FILES = \ modules/module-esound-sink-symdef.h \ modules/module-zeroconf-publish-symdef.h \ modules/module-zeroconf-discover-symdef.h \ + modules/module-bonjour-publish-symdef.h \ modules/module-lirc-symdef.h \ modules/module-mmkbd-evdev-symdef.h \ modules/module-http-protocol-tcp-symdef.h \ @@ -1229,6 +1250,8 @@ SYMDEF_FILES = \ modules/alsa/module-alsa-sink-symdef.h \ modules/alsa/module-alsa-source-symdef.h \ modules/alsa/module-alsa-card-symdef.h \ + modules/coreaudio/module-coreaudio-detect-symdef.h \ + modules/coreaudio/module-coreaudio-device-symdef.h \ modules/module-solaris-symdef.h \ modules/module-waveout-symdef.h \ modules/module-detect-symdef.h \ @@ -1460,6 +1483,19 @@ module_oss_la_SOURCES = modules/oss/module-oss.c module_oss_la_LDFLAGS = $(MODULE_LDFLAGS) module_oss_la_LIBADD = $(AM_LIBADD) liboss-util.la libpulsecore-@PA_MAJORMINORMICRO@.la libpulsecommon-@PA_MAJORMINORMICRO@.la libpulse.la +# COREAUDIO + +module_coreaudio_detect_la_SOURCES = modules/coreaudio/module-coreaudio-detect.c +module_coreaudio_detect_la_LDFLAGS = $(MODULE_LDFLAGS) \ + -Wl,-framework -Wl,Cocoa -framework CoreAudio \ + -Wl,-framework -Wl,AudioUnit -framework AudioUnit +module_coreaudio_detect_la_LIBADD = $(AM_LIBADD) libpulsecore-@PA_MAJORMINORMICRO@.la libpulsecommon-@PA_MAJORMINORMICRO@.la libpulse.la + +module_coreaudio_device_la_SOURCES = modules/coreaudio/module-coreaudio-device.c +module_coreaudio_device_la_LDFLAGS = $(MODULE_LDFLAGS) \ + -Wl,-framework -Wl,Cocoa -framework CoreAudio \ + -Wl,-framework -Wl,AudioUnit -framework AudioUnit +module_coreaudio_device_la_LIBADD = $(AM_LIBADD) libpulsecore-@PA_MAJORMINORMICRO@.la libpulsecommon-@PA_MAJORMINORMICRO@.la libpulse.la # ALSA libalsa_util_la_SOURCES = modules/alsa/alsa-util.c modules/alsa/alsa-util.h modules/alsa/alsa-mixer.c modules/alsa/alsa-mixer.h modules/alsa/alsa-sink.c modules/alsa/alsa-sink.h modules/alsa/alsa-source.c modules/alsa/alsa-source.h modules/reserve-wrap.c modules/reserve-wrap.h @@ -1518,6 +1554,13 @@ module_zeroconf_discover_la_LDFLAGS = $(MODULE_LDFLAGS) module_zeroconf_discover_la_LIBADD = $(AM_LIBADD) $(AVAHI_LIBS) libavahi-wrap.la libpulsecore-@PA_MAJORMINORMICRO@.la libpulsecommon-@PA_MAJORMINORMICRO@.la libpulse.la module_zeroconf_discover_la_CFLAGS = $(AM_CFLAGS) $(AVAHI_CFLAGS) +# Bonjour + +module_bonjour_publish_la_SOURCES = modules/module-bonjour-publish.c +module_bonjour_publish_la_LDFLAGS = $(MODULE_LDFLAGS) \ + -Wl,-framework -Wl,CoreFoundation -framework CoreFoundation +module_bonjour_publish_la_LIBADD = libpulsecore-@PA_MAJORMINORMICRO@.la libpulsecommon-@PA_MAJORMINORMICRO@.la libpulse.la + # LIRC module_lirc_la_SOURCES = modules/module-lirc.c diff --git a/src/modules/coreaudio/module-coreaudio-detect.c b/src/modules/coreaudio/module-coreaudio-detect.c new file mode 100644 index 000000000..872678e76 --- /dev/null +++ b/src/modules/coreaudio/module-coreaudio-detect.c @@ -0,0 +1,229 @@ +/*** + This file is part of PulseAudio. + + Copyright 2009 Daniel Mack + + PulseAudio is free software; you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published + by the Free Software Foundation; either version 2.1 of the License, + or (at your option) any later version. + + PulseAudio 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 Lesser General Public License + along with PulseAudio; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + USA. +***/ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include + +#include +#include +#include +#include +#include + +#include + +#include "module-coreaudio-detect-symdef.h" + +#define DEVICE_MODULE_NAME "module-coreaudio-device" + +PA_MODULE_AUTHOR("Daniel Mack"); +PA_MODULE_DESCRIPTION("CoreAudio device detection"); +PA_MODULE_VERSION(PACKAGE_VERSION); +PA_MODULE_LOAD_ONCE(TRUE); +PA_MODULE_USAGE(""); + +typedef struct ca_device ca_device; + +struct ca_device { + AudioDeviceID id; + unsigned int module_index; + PA_LLIST_FIELDS(ca_device); +}; + +struct userdata { + int detect_fds[2]; + pa_io_event *detect_io; + + PA_LLIST_HEAD(ca_device, devices); +}; + +static int ca_device_added(struct pa_module *m, AudioDeviceID id) { + pa_module *mod; + struct userdata *u = m->userdata; + struct ca_device *dev; + char *args; + + pa_assert(u); + + args = pa_sprintf_malloc("device_id=%d", (int) id); + pa_log_debug("Loading %s with arguments '%s'", DEVICE_MODULE_NAME, args); + mod = pa_module_load(m->core, DEVICE_MODULE_NAME, args); + pa_xfree(args); + + if (!mod) { + pa_log_info("Failed to load module %s with arguments '%s'", DEVICE_MODULE_NAME, args); + return -1; + } + + dev = pa_xnew0(ca_device, 1); + dev->module_index = mod->index; + dev->id = id; + + PA_LLIST_INIT(ca_device, dev); + PA_LLIST_PREPEND(ca_device, u->devices, dev); + + return 0; +} + +static int ca_update_device_list(struct pa_module *m) { + OSStatus err; + UInt32 i, size, num_devices; + Boolean writable; + AudioDeviceID *device_id; + struct ca_device *dev; + struct userdata *u = m->userdata; + + pa_assert(u); + + /* get the number of currently available audio devices */ + err = AudioHardwareGetPropertyInfo(kAudioHardwarePropertyDevices, &size, &writable); + if (err) { + pa_log("Unable to get info for kAudioHardwarePropertyDevices."); + return -1; + } + + num_devices = size / sizeof(AudioDeviceID); + device_id = pa_xnew(AudioDeviceID, num_devices); + + err = AudioHardwareGetProperty(kAudioHardwarePropertyDevices, &size, device_id); + if (err) { + pa_log("Unable to get kAudioHardwarePropertyDevices."); + pa_xfree(device_id); + return -1; + } + + /* scan for devices which are reported but not in our cached list */ + for (i = 0; i < num_devices; i++) { + bool found = FALSE; + + PA_LLIST_FOREACH(dev, u->devices) + if (dev->id == device_id[i]) { + found = TRUE; + break; + } + + if (!found) + ca_device_added(m, device_id[i]); + } + + /* scan for devices which are in our cached list but are not reported */ +scan_removed: + + PA_LLIST_FOREACH(dev, u->devices) { + bool found = FALSE; + + for (i = 0; i < num_devices; i++) + if (dev->id == device_id[i]) { + found = TRUE; + break; + } + + if (!found) { + pa_log_debug("device id %d has been removed (module index %d) %p", (unsigned int) dev->id, dev->module_index, dev); + pa_module_unload_request_by_index(m->core, dev->module_index, TRUE); + PA_LLIST_REMOVE(ca_device, u->devices, dev); + pa_xfree(dev); + /* the current list item pointer is not valid anymore, so start over. */ + goto scan_removed; + } + } + + pa_xfree(device_id); + return 0; +} + +static OSStatus property_listener_proc(AudioHardwarePropertyID property, void *data) { + struct userdata *u = data; + char dummy = 1; + + pa_assert(u); + + /* dispatch module load/unload operations in main thread */ + if (property == kAudioHardwarePropertyDevices) + write(u->detect_fds[1], &dummy, 1); + + return 0; +} + +static void detect_handle(pa_mainloop_api *a, pa_io_event *e, int fd, pa_io_event_flags_t events, void *userdata) { + pa_module *m = userdata; + char dummy; + + pa_assert(m); + + read(fd, &dummy, 1); + ca_update_device_list(m); +} + +int pa__init(pa_module *m) { + struct userdata *u = pa_xnew0(struct userdata, 1); + + m->userdata = u; + + if (AudioHardwareAddPropertyListener(kAudioHardwarePropertyDevices, property_listener_proc, u)) { + pa_log("AudioHardwareAddPropertyListener() failed."); + goto fail; + } + + if (ca_update_device_list(m)) + goto fail; + + pa_assert_se(pipe(u->detect_fds) == 0); + pa_assert_se(u->detect_io = m->core->mainloop->io_new(m->core->mainloop, u->detect_fds[0], PA_IO_EVENT_INPUT, detect_handle, m)); + + return 0; + +fail: + pa_xfree(u); + return -1; +} + +void pa__done(pa_module *m) { + struct userdata *u = m->userdata; + struct ca_device *dev = u->devices; + + pa_assert(u); + + AudioHardwareRemovePropertyListener(kAudioHardwarePropertyDevices, property_listener_proc); + + while (dev) { + struct ca_device *next = dev->next; + + pa_module_unload_request_by_index(m->core, dev->module_index, TRUE); + pa_xfree(dev); + + dev = next; + } + + if (u->detect_fds[0] >= 0) + close(u->detect_fds[0]); + + if (u->detect_fds[1] >= 0) + close(u->detect_fds[1]); + + if (u->detect_io) + m->core->mainloop->io_free(u->detect_io); + + pa_xfree(u); +} diff --git a/src/modules/coreaudio/module-coreaudio-device.c b/src/modules/coreaudio/module-coreaudio-device.c new file mode 100644 index 000000000..a3699e686 --- /dev/null +++ b/src/modules/coreaudio/module-coreaudio-device.c @@ -0,0 +1,820 @@ +/*** + This file is part of PulseAudio. + + Copyright 2009 Daniel Mack + + PulseAudio is free software; you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published + by the Free Software Foundation; either version 2.1 of the License, + or (at your option) any later version. + + PulseAudio 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 Lesser General Public License + along with PulseAudio; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + USA. +***/ + +/* TODO: + - implement hardware volume controls + - handle audio device stream format changes (will require changes to the core) +*/ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include "module-coreaudio-device-symdef.h" + +#define DEFAULT_FRAMES_PER_IOPROC 512 + +PA_MODULE_AUTHOR("Daniel Mack"); +PA_MODULE_DESCRIPTION("CoreAudio device"); +PA_MODULE_VERSION(PACKAGE_VERSION); +PA_MODULE_LOAD_ONCE(FALSE); +PA_MODULE_USAGE("device_id= " + "ioproc_frames=