diff --git a/client/pulseaudio/src/modules/macosx/module-coreaudio-detect.c b/client/pulseaudio/src/modules/macosx/module-coreaudio-detect.c index d9c09da5e..fea95f688 100644 --- a/client/pulseaudio/src/modules/macosx/module-coreaudio-detect.c +++ b/client/pulseaudio/src/modules/macosx/module-coreaudio-detect.c @@ -26,6 +26,7 @@ #include #include #include +#include #include #include @@ -115,6 +116,7 @@ static int ca_update_device_list(struct pa_module *m) { OSStatus err; UInt32 i, size, num_devices; AudioDeviceID *device_id; + AudioDeviceID default_id; struct ca_device *dev; struct userdata *u; @@ -178,6 +180,68 @@ scan_removed: } } + /* configure the default source */ + + property_address.mSelector = kAudioHardwarePropertyDefaultInputDevice; + property_address.mScope = kAudioObjectPropertyScopeGlobal; + property_address.mElement = kAudioObjectPropertyElementMaster; + + size = sizeof(AudioDeviceID); + err = AudioObjectGetPropertyData(kAudioObjectSystemObject, &property_address, 0, NULL, &size, &default_id); + if (err) { + pa_log("Unable to get kAudioHardwarePropertyDefaultInputDevice."); + } else { + PA_LLIST_FOREACH(dev, u->devices) { + pa_source *source; + uint32_t idx; + + if (dev->id != default_id) + continue; + + PA_IDXSET_FOREACH(source, m->core->sources, idx) { + if (source->monitor_of) + continue; + if (!source->module || source->module->index != dev->module_index) + continue; + + pa_namereg_set_default_source(m->core, source); + break; + } + + break; + } + } + + /* configure the default source */ + + property_address.mSelector = kAudioHardwarePropertyDefaultOutputDevice; + property_address.mScope = kAudioObjectPropertyScopeGlobal; + property_address.mElement = kAudioObjectPropertyElementMaster; + + size = sizeof(AudioDeviceID); + err = AudioObjectGetPropertyData(kAudioObjectSystemObject, &property_address, 0, NULL, &size, &default_id); + if (err) { + pa_log("Unable to get kAudioHardwarePropertyDefaultOutputDevice."); + } else { + PA_LLIST_FOREACH(dev, u->devices) { + pa_sink *sink; + uint32_t idx; + + if (dev->id != default_id) + continue; + + PA_IDXSET_FOREACH(sink, m->core->sinks, idx) { + if (!sink->module || sink->module->index != dev->module_index) + continue; + + pa_namereg_set_default_sink(m->core, sink); + break; + } + + break; + } + } + pa_xfree(device_id); return 0; } @@ -231,6 +295,24 @@ int pa__init(pa_module *m) { goto fail; } + property_address.mSelector = kAudioHardwarePropertyDefaultInputDevice; + property_address.mScope = kAudioObjectPropertyScopeGlobal; + property_address.mElement = kAudioObjectPropertyElementMaster; + + if (AudioObjectAddPropertyListener(kAudioObjectSystemObject, &property_address, property_listener_proc, u)) { + pa_log("AudioObjectAddPropertyListener() failed."); + goto fail; + } + + property_address.mSelector = kAudioHardwarePropertyDefaultOutputDevice; + property_address.mScope = kAudioObjectPropertyScopeGlobal; + property_address.mElement = kAudioObjectPropertyElementMaster; + + if (AudioObjectAddPropertyListener(kAudioObjectSystemObject, &property_address, property_listener_proc, u)) { + pa_log("AudioObjectAddPropertyListener() failed."); + goto fail; + } + if (ca_update_device_list(m)) goto fail; @@ -260,6 +342,18 @@ void pa__done(pa_module *m) { AudioObjectRemovePropertyListener(kAudioObjectSystemObject, &property_address, property_listener_proc, u); + property_address.mSelector = kAudioHardwarePropertyDefaultInputDevice; + property_address.mScope = kAudioObjectPropertyScopeGlobal; + property_address.mElement = kAudioObjectPropertyElementMaster; + + AudioObjectRemovePropertyListener(kAudioObjectSystemObject, &property_address, property_listener_proc, u); + + property_address.mSelector = kAudioHardwarePropertyDefaultOutputDevice; + property_address.mScope = kAudioObjectPropertyScopeGlobal; + property_address.mElement = kAudioObjectPropertyElementMaster; + + AudioObjectRemovePropertyListener(kAudioObjectSystemObject, &property_address, property_listener_proc, u); + while (dev) { struct ca_device *next = dev->next;