[PATCH] module-coreaudio-detect: Add 'card_name' parameter

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Allow limiting the cards (=device string) considered while
detecting core audio devices.

Background is that CoreAudio adds devices dynamically
(e.g. multiple Airplay devices, Parallels Access Sound). This
changes the lowest index number and leads to sending output
to wrong device unintentionally. set-default-sink won't
cut it, as CoreAudio sink names change as well (they're
named like ___v_______v__.1, ___v_______v__.2 etc., the index
part changes based on the available devices and when they're
detected).

Usage example:
load-module module-coreaudio-detect card_name="Built-in Output"
---
 src/modules/macosx/module-coreaudio-detect.c | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/src/modules/macosx/module-coreaudio-detect.c b/src/modules/macosx/module-coreaudio-detect.c
index 81cd94c..83625a3 100644
--- a/src/modules/macosx/module-coreaudio-detect.c
+++ b/src/modules/macosx/module-coreaudio-detect.c
@@ -41,10 +41,11 @@ PA_MODULE_AUTHOR("Daniel Mack");
 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> ");
+PA_MODULE_USAGE("ioproc_frames=<passed on to module-coreaudio-device> card_name=<fixed card name>");
 
 static const char* const valid_modargs[] = {
     "ioproc_frames",
+    "card_name",
     NULL
 };
 
@@ -60,6 +61,7 @@ struct userdata {
     int detect_fds[2];
     pa_io_event *detect_io;
     unsigned int ioproc_frames;
+    char* card_name;
     PA_LLIST_HEAD(ca_device, devices);
 };
 
@@ -69,7 +71,7 @@ static int ca_device_added(struct pa_module *m, AudioObjectID id) {
     pa_module *mod;
     struct userdata *u;
     struct ca_device *dev;
-    char *args, tmp[64];
+    char *args, tmp[128];
     UInt32 size;
 
     pa_assert(m);
@@ -88,6 +90,17 @@ static int ca_device_added(struct pa_module *m, AudioObjectID id) {
     if (!err && pa_streq(tmp, "pulseaudio.org"))
         return 0;
 
+    if (u->card_name != NULL) {
+        size = sizeof(tmp);
+        property_address.mSelector = kAudioDevicePropertyDeviceName;
+        err = AudioObjectGetPropertyData(id, &property_address, 0, NULL, &size, tmp);
+        if (!err) {
+          pa_log_debug("New device name is %s (card_name is %s)", tmp, u->card_name);
+          if (!pa_streq(tmp, u->card_name))
+            return 0;
+        }
+    }
+
     if (u->ioproc_frames)
         args = pa_sprintf_malloc("object_id=%d ioproc_frames=%d", (int) id, u->ioproc_frames);
     else
@@ -223,6 +236,7 @@ int pa__init(pa_module *m) {
     }
 
     pa_modargs_get_value_u32(ma, "ioproc_frames", &u->ioproc_frames);
+    u->card_name = pa_xstrdup(pa_modargs_get_value(ma, "card_name", NULL));
 
     property_address.mSelector = kAudioHardwarePropertyDevices;
     property_address.mScope = kAudioObjectPropertyScopeGlobal;
@@ -280,5 +294,6 @@ void pa__done(pa_module *m) {
     if (u->detect_io)
         m->core->mainloop->io_free(u->detect_io);
 
+    pa_xfree(u->card_name);
     pa_xfree(u);
 }
-- 
2.2.1



[Index of Archives]     [Linux Audio Users]     [AMD Graphics]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux