configure.ac | 3 + src/daemon/default.pa.in | 4 ++ src/daemon/system.pa.in | 4 ++ src/modules/macosx/module-coreaudio-device.c | 46 +++++++++++++++++++++++++-- 4 files changed, 55 insertions(+), 2 deletions(-)
New commits: commit 403ba1e676d10e174425c6611a0e170550ba731d Author: Mihai Moldovan <[email protected]> Date: Mon Apr 20 20:46:02 2015 +0200 module-coreaudio-device: get channel name as CFString and convert to plain C string. This is an OpenPGP/MIME signed message (RFC 4880 and 3156) The old code fetched the channel name via AudioObjectGetPropertyData() and accessed the "returned" data as a plain char buffer. This may or may not have worked at some point according to the Apple CFString documentation, which warns that the actual data layout is an implementation detail and subject to change at any time. On recent OS X versions, this behavior led to "random data" channel names like >H��{, H��{<. We need to actually let AudioObjectGetPropertyData() populate a CFString struct and convert this into a plain char buffer. The conversion function will not free the CFString, so do that in the caller. Signed-off-by: Mihai Moldovan <[email protected]> diff --git a/src/modules/macosx/module-coreaudio-device.c b/src/modules/macosx/module-coreaudio-device.c index cbf1f27..0c92d42 100644 --- a/src/modules/macosx/module-coreaudio-device.c +++ b/src/modules/macosx/module-coreaudio-device.c @@ -375,6 +375,30 @@ static int ca_sink_set_state(pa_sink *s, pa_sink_state_t state) { return 0; } +/* Caveat: The caller is responsible to get rid of the CFString(Ref). */ +static bool CFString_to_cstr_n(CFStringRef cfstr, char *buf, long n) { + bool ret; + + pa_assert (buf); + + ret = false; + + if (cfstr != NULL) { + const char *tmp = CFStringGetCStringPtr(cfstr, kCFStringEncodingUTF8); + + if (tmp == NULL) { + if (CFStringGetCString(cfstr, buf, n, kCFStringEncodingUTF8)) + ret = true; + } else { + strncpy(buf, tmp, n); + buf[n - 1] = 0; + ret = true; + } + } + + return ret; +} + static int ca_device_create_sink(pa_module *m, AudioBuffer *buf, int channel_idx) { OSStatus err; UInt32 size; @@ -387,6 +411,7 @@ static int ca_device_create_sink(pa_module *m, AudioBuffer *buf, int channel_idx char tmp[255]; pa_strbuf *strbuf; AudioObjectPropertyAddress property_address; + CFStringRef tmp_cfstr = NULL; ca_sink = pa_xnew0(coreaudio_sink, 1); ca_sink->map.channels = buf->mNumberChannels; @@ -401,7 +426,15 @@ static int ca_device_create_sink(pa_module *m, AudioBuffer *buf, int channel_idx property_address.mScope = kAudioDevicePropertyScopeOutput; property_address.mElement = channel_idx + i + 1; size = sizeof(tmp); - err = AudioObjectGetPropertyData(u->object_id, &property_address, 0, NULL, &size, tmp); + err = AudioObjectGetPropertyData(u->object_id, &property_address, 0, NULL, &size, &tmp_cfstr); + if (err == 0) { + err = !(CFString_to_cstr_n(tmp_cfstr, tmp, sizeof(tmp))); + + if (tmp_cfstr) { + CFRelease(tmp_cfstr); + } + } + if (err || !strlen(tmp)) snprintf(tmp, sizeof(tmp), "Channel %d", (int) property_address.mElement); @@ -505,6 +538,7 @@ static int ca_device_create_source(pa_module *m, AudioBuffer *buf, int channel_i char tmp[255]; pa_strbuf *strbuf; AudioObjectPropertyAddress property_address; + CFStringRef tmp_cfstr = NULL; ca_source = pa_xnew0(coreaudio_source, 1); ca_source->map.channels = buf->mNumberChannels; @@ -519,7 +553,15 @@ static int ca_device_create_source(pa_module *m, AudioBuffer *buf, int channel_i property_address.mScope = kAudioDevicePropertyScopeInput; property_address.mElement = channel_idx + i + 1; size = sizeof(tmp); - err = AudioObjectGetPropertyData(u->object_id, &property_address, 0, NULL, &size, tmp); + err = AudioObjectGetPropertyData(u->object_id, &property_address, 0, NULL, &size, &tmp_cfstr); + if (err == 0) { + err = !(CFString_to_cstr_n(tmp_cfstr, tmp, sizeof(tmp))); + + if (tmp_cfstr) { + CFRelease(tmp_cfstr); + } + } + if (err || !strlen(tmp)) snprintf(tmp, sizeof(tmp), "Channel %d", (int) property_address.mElement); commit cf91aaa2b60893230f526d8d241e12c2b47508f8 Author: Mihai Moldovan <[email protected]> Date: Tue Apr 21 08:01:27 2015 +0200 system.pa.in: load module-coreaudio-detect if HAVE_COREAUDIO. This is an OpenPGP/MIME signed message (RFC 4880 and 3156) Signed-off-by: Mihai Moldovan <[email protected]> diff --git a/src/daemon/system.pa.in b/src/daemon/system.pa.in index 01cea10..06e3f1e 100755 --- a/src/daemon/system.pa.in +++ b/src/daemon/system.pa.in @@ -28,6 +28,10 @@ load-module module-udev-detect .ifexists module-hal-detect@PA_SOEXT@ load-module module-hal-detect .else +], @HAVE_COREAUDIO@, 1, [dnl +.ifexists module-coreaudio-detect@PA_SOEXT@ +load-module module-coreaudio-detect +.else ], [dnl .ifexists module-detect@PA_SOEXT@ ])dnl commit 48c91d52f92ddce2922c3e0532d95b6252b6d44e Author: Mihai Moldovan <[email protected]> Date: Tue Apr 21 08:01:16 2015 +0200 default.pa.in: load module-coreaudio-detect if HAVE_COREAUDIO. This is an OpenPGP/MIME signed message (RFC 4880 and 3156) Signed-off-by: Mihai Moldovan <[email protected]> diff --git a/src/daemon/default.pa.in b/src/daemon/default.pa.in index 5ec4641..783e326 100755 --- a/src/daemon/default.pa.in +++ b/src/daemon/default.pa.in @@ -70,6 +70,10 @@ ifelse(@HAVE_UDEV@, 1, [dnl .ifexists module-udev-detect@PA_SOEXT@ load-module module-udev-detect .else +], @HAVE_COREAUDIO@, 1, [dnl +.ifexists module-coreaudio-detect@PA_SOEXT@ +load-module module-coreaudio-detect +.else ], [dnl .ifexists module-detect@PA_SOEXT@ ])dnl commit 51caceb7705c206e9f04829f3bfd399da75f80cc Author: Mihai Moldovan <[email protected]> Date: Tue Apr 21 08:01:05 2015 +0200 configure.ac: add HAVE_COREAUDIO to automake and code. This is an OpenPGP/MIME signed message (RFC 4880 and 3156) Signed-off-by: Mihai Moldovan <[email protected]> diff --git a/configure.ac b/configure.ac index 2dbf7f2..ee1b437 100644 --- a/configure.ac +++ b/configure.ac @@ -781,8 +781,11 @@ AS_IF([test "x$enable_coreaudio_output" != "xno"], AS_IF([test "x$enable_coreaudio_output" = "xyes" && test "x$HAVE_COREAUDIO" = "x0"], [AC_MSG_ERROR([*** CoreAudio output support not found])]) +AC_SUBST(HAVE_COREAUDIO) AM_CONDITIONAL([HAVE_COREAUDIO], [test "x$HAVE_COREAUDIO" = "x1" && test "x$enable_coreaudio_output" != "xno"]) +AS_IF([test "x$HAVE_COREAUDIO" = "x1"], AC_DEFINE([HAVE_COREAUDIO], 1, [Have CoreAudio?])) + #### ALSA support (optional) #### AC_ARG_ENABLE([alsa],
_______________________________________________ pulseaudio-commits mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/pulseaudio-commits
