Last active
June 16, 2020 13:22
-
-
Save topia/cfed3a588974ef836ce01ca4cd62c2ac to your computer and use it in GitHub Desktop.
pulseaudio / CoreAudio name/channel patch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git i/Formula/pulseaudio.rb w/Formula/pulseaudio.rb | |
index 4e2790babf..3531bd0464 100644 | |
--- i/Formula/pulseaudio.rb | |
+++ w/Formula/pulseaudio.rb | |
@@ -18,6 +18,10 @@ class Pulseaudio < Formula | |
depends_on "automake" => :build | |
depends_on "gettext" => :build | |
depends_on "intltool" => :build | |
+ | |
+ patch :p1 do | |
+ url "https://gist.githubusercontent.com/topia/cfed3a588974ef836ce01ca4cd62c2ac/raw/0e40bfaca45252bcefe8c1a16d2039410787fa72/pulseaudio-coreaudio-name-patch.diff" | |
+ end | |
end | |
depends_on "pkg-config" => :build |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/modules/macosx/module-coreaudio-detect.c b/src/modules/macosx/module-coreaudio-detect.c | |
index 1fd2ede70..f0540ab9b 100644 | |
--- a/src/modules/macosx/module-coreaudio-detect.c | |
+++ b/src/modules/macosx/module-coreaudio-detect.c | |
@@ -38,11 +38,13 @@ PA_MODULE_DESCRIPTION("CoreAudio device detection"); | |
PA_MODULE_VERSION(PACKAGE_VERSION); | |
PA_MODULE_LOAD_ONCE(true); | |
PA_MODULE_USAGE("ioproc_frames=<passed on to module-coreaudio-device> " | |
+ "use_device_name=<passed on to module-coreaudio-device> " | |
"record=<enable source?> " | |
"playback=<enable sink?> "); | |
static const char* const valid_modargs[] = { | |
"ioproc_frames", | |
+ "use_device_name", | |
"record", | |
"playback", | |
NULL | |
@@ -60,6 +62,7 @@ struct userdata { | |
int detect_fds[2]; | |
pa_io_event *detect_io; | |
unsigned int ioproc_frames; | |
+ bool use_device_name; | |
bool record; | |
bool playback; | |
PA_LLIST_HEAD(ca_device, devices); | |
@@ -91,9 +94,9 @@ static int ca_device_added(struct pa_module *m, AudioObjectID id) { | |
return 0; | |
if (u->ioproc_frames) | |
- args = pa_sprintf_malloc("object_id=%d ioproc_frames=%d record=%d playback=%d", (int) id, u->ioproc_frames, (int) u->record, (int) u->playback); | |
+ args = pa_sprintf_malloc("object_id=%d ioproc_frames=%d use_device_name=%d record=%d playback=%d", (int) id, u->ioproc_frames, (int)u->use_device_name, (int) u->record, (int) u->playback); | |
else | |
- args = pa_sprintf_malloc("object_id=%d record=%d playback=%d", (int) id, (int) u->record, (int) u->playback); | |
+ args = pa_sprintf_malloc("object_id=%d use_device_name=%d record=%d playback=%d", (int) id, (int)u->use_device_name, (int) u->record, (int) u->playback); | |
pa_log_debug("Loading %s with arguments '%s'", DEVICE_MODULE_NAME, args); | |
pa_module_load(&mod, m->core, DEVICE_MODULE_NAME, args); | |
@@ -242,6 +245,8 @@ int pa__init(pa_module *m) { | |
goto fail; | |
} | |
+ pa_modargs_get_value_boolean(ma, "use_device_name", &u->use_device_name); | |
+ | |
pa_modargs_get_value_u32(ma, "ioproc_frames", &u->ioproc_frames); | |
property_address.mSelector = kAudioHardwarePropertyDevices; | |
diff --git a/src/modules/macosx/module-coreaudio-device.c b/src/modules/macosx/module-coreaudio-device.c | |
index b9dffb937..6c3ae2e85 100644 | |
--- a/src/modules/macosx/module-coreaudio-device.c | |
+++ b/src/modules/macosx/module-coreaudio-device.c | |
@@ -56,12 +56,14 @@ PA_MODULE_VERSION(PACKAGE_VERSION); | |
PA_MODULE_LOAD_ONCE(false); | |
PA_MODULE_USAGE("object_id=<the CoreAudio device id> " | |
"ioproc_frames=<audio frames per IOProc call> " | |
+ "use_device_name=<use device name as stream name?> " | |
"record=<enable source?> " | |
"playback=<enable sink?> "); | |
static const char* const valid_modargs[] = { | |
"object_id", | |
"ioproc_frames", | |
+ "use_device_name", | |
"record", | |
"playback", | |
NULL | |
@@ -87,6 +89,7 @@ struct userdata { | |
pa_module *module; | |
pa_card *card; | |
bool running; | |
+ bool use_device_name; | |
char *device_name, *vendor_name; | |
@@ -428,42 +431,43 @@ static int ca_device_create_sink(pa_module *m, AudioBuffer *buf, int channel_idx | |
/* build a name for this stream */ | |
strbuf = pa_strbuf_new(); | |
- for (i = 0; i < buf->mNumberChannels; i++) { | |
- property_address.mSelector = kAudioObjectPropertyElementName; | |
- property_address.mScope = kAudioDevicePropertyScopeOutput; | |
- property_address.mElement = channel_idx + i + 1; | |
- size = sizeof(tmp_cfstr); | |
- err = AudioObjectGetPropertyData(u->object_id, &property_address, 0, NULL, &size, &tmp_cfstr); | |
- if (err == 0) { | |
- tmp = CFString_to_cstr(tmp_cfstr); | |
- | |
- if (tmp_cfstr) | |
- CFRelease(tmp_cfstr); | |
- } | |
+ if (u->use_device_name) { | |
+ pa_strbuf_puts(strbuf, "output."); | |
+ pa_strbuf_puts(strbuf, u->device_name); | |
+ } else { | |
+ for (i = 0; i < buf->mNumberChannels; i++) { | |
+ property_address.mSelector = kAudioObjectPropertyElementName; | |
+ property_address.mScope = kAudioDevicePropertyScopeOutput; | |
+ property_address.mElement = channel_idx + i + 1; | |
+ size = sizeof(tmp_cfstr); | |
+ err = AudioObjectGetPropertyData(u->object_id, &property_address, 0, NULL, &size, &tmp_cfstr); | |
+ if (err == 0) { | |
+ tmp = CFString_to_cstr(tmp_cfstr); | |
+ | |
+ if (tmp_cfstr) | |
+ CFRelease(tmp_cfstr); | |
+ } | |
- if (i > 0) | |
- pa_strbuf_puts(strbuf, ", "); | |
+ if (i > 0) | |
+ pa_strbuf_puts(strbuf, ", "); | |
- if (err || !tmp || !strlen(tmp)) | |
- pa_strbuf_printf(strbuf, "Channel %d", (int) property_address.mElement); | |
- else | |
- pa_strbuf_puts(strbuf, tmp); | |
+ if (err || !tmp || !strlen(tmp)) | |
+ pa_strbuf_printf(strbuf, "Channel %d", (int) property_address.mElement); | |
+ else | |
+ pa_strbuf_puts(strbuf, tmp); | |
- pa_xfree(tmp); | |
- tmp = NULL; | |
+ pa_xfree(tmp); | |
+ tmp = NULL; | |
+ } | |
} | |
ca_sink->name = pa_strbuf_to_string_free(strbuf); | |
pa_log_debug("Stream name is >%s<", ca_sink->name); | |
- /* default to mono streams */ | |
- for (i = 0; i < ca_sink->map.channels; i++) | |
- ca_sink->map.map[i] = PA_CHANNEL_POSITION_MONO; | |
- | |
- if (buf->mNumberChannels == 2) { | |
- ca_sink->map.map[0] = PA_CHANNEL_POSITION_LEFT; | |
- ca_sink->map.map[1] = PA_CHANNEL_POSITION_RIGHT; | |
+ /* default to AIFF channel mapping */ | |
+ if (pa_channel_map_init_auto(&ca_sink->map, ca_sink->map.channels, PA_CHANNEL_MAP_WAVEEX) == NULL) { | |
+ pa_channel_map_init_auto(&ca_sink->map, ca_sink->map.channels, PA_CHANNEL_MAP_AUX); | |
} | |
ca_sink->ss.rate = u->stream_description.mSampleRate; | |
@@ -562,42 +566,43 @@ static int ca_device_create_source(pa_module *m, AudioBuffer *buf, int channel_i | |
/* build a name for this stream */ | |
strbuf = pa_strbuf_new(); | |
- for (i = 0; i < buf->mNumberChannels; i++) { | |
- property_address.mSelector = kAudioObjectPropertyElementName; | |
- property_address.mScope = kAudioDevicePropertyScopeInput; | |
- property_address.mElement = channel_idx + i + 1; | |
- size = sizeof(tmp_cfstr); | |
- err = AudioObjectGetPropertyData(u->object_id, &property_address, 0, NULL, &size, &tmp_cfstr); | |
- if (err == 0) { | |
- tmp = CFString_to_cstr(tmp_cfstr); | |
- | |
- if (tmp_cfstr) | |
- CFRelease(tmp_cfstr); | |
- } | |
+ if (u->use_device_name) { | |
+ pa_strbuf_puts(strbuf, "input."); | |
+ pa_strbuf_puts(strbuf, u->device_name); | |
+ } else { | |
+ for (i = 0; i < buf->mNumberChannels; i++) { | |
+ property_address.mSelector = kAudioObjectPropertyElementName; | |
+ property_address.mScope = kAudioDevicePropertyScopeInput; | |
+ property_address.mElement = channel_idx + i + 1; | |
+ size = sizeof(tmp_cfstr); | |
+ err = AudioObjectGetPropertyData(u->object_id, &property_address, 0, NULL, &size, &tmp_cfstr); | |
+ if (err == 0) { | |
+ tmp = CFString_to_cstr(tmp_cfstr); | |
+ | |
+ if (tmp_cfstr) | |
+ CFRelease(tmp_cfstr); | |
+ } | |
- if (i > 0) | |
- pa_strbuf_puts(strbuf, ", "); | |
+ if (i > 0) | |
+ pa_strbuf_puts(strbuf, ", "); | |
- if (err || !tmp || !strlen(tmp)) | |
- pa_strbuf_printf(strbuf, "Channel %d", (int) property_address.mElement); | |
- else | |
- pa_strbuf_puts(strbuf, tmp); | |
+ if (err || !tmp || !strlen(tmp)) | |
+ pa_strbuf_printf(strbuf, "Channel %d", (int) property_address.mElement); | |
+ else | |
+ pa_strbuf_puts(strbuf, tmp); | |
- pa_xfree(tmp); | |
- tmp = NULL; | |
+ pa_xfree(tmp); | |
+ tmp = NULL; | |
+ } | |
} | |
ca_source->name = pa_strbuf_to_string_free(strbuf); | |
pa_log_debug("Stream name is >%s<", ca_source->name); | |
- /* default to mono streams */ | |
- for (i = 0; i < ca_source->map.channels; i++) | |
- ca_source->map.map[i] = PA_CHANNEL_POSITION_MONO; | |
- | |
- if (buf->mNumberChannels == 2) { | |
- ca_source->map.map[0] = PA_CHANNEL_POSITION_LEFT; | |
- ca_source->map.map[1] = PA_CHANNEL_POSITION_RIGHT; | |
+ /* default to AIFF channel mapping */ | |
+ if (pa_channel_map_init_auto(&ca_source->map, ca_source->map.channels, PA_CHANNEL_MAP_WAVEEX) == NULL) { | |
+ pa_channel_map_init_auto(&ca_source->map, ca_source->map.channels, PA_CHANNEL_MAP_AUX); | |
} | |
ca_source->ss.rate = u->stream_description.mSampleRate; | |
@@ -793,6 +798,10 @@ int pa__init(pa_module *m) { | |
goto fail; | |
} | |
+ if (pa_modargs_get_value_boolean(ma, "use_device_name", &u->use_device_name) != 0) { | |
+ u->use_device_name = false; | |
+ } | |
+ | |
property_address.mScope = kAudioObjectPropertyScopeGlobal; | |
property_address.mElement = kAudioObjectPropertyElementMaster; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment