[pulseaudio-discuss] Add a single "On" profile to coreaudio devices. Fixes crash on OS X.

Sjors Gielen pulseaudio at sjorsgielen.nl
Sat Jul 7 06:22:45 PDT 2012


Hi all,

Since commit 12af302a last month, cards always have at least one
profile, so there is also always an active_profile (this makes the code
more simple). However, module-coreaudio-device did not create a profile
yet, causing a crash of PulseAudio when used on OS X. This patch fixes
this crash, by adding a single "On" profile. I've also added a TODO for
adding an "Off" profile which removes all sinks and sources -- I can
work on resolving this TODO later on.

Thanks,
Sjors

-------------- next part --------------
From a4eee9137c1a6a43a7f45fa45fa444cf4ddd5e0f Mon Sep 17 00:00:00 2001
From: Sjors Gielen <sjors at sjorsgielen.nl>
Date: Sat, 7 Jul 2012 14:47:10 +0200
Subject: [PATCH] Add a single "On" profile to coreaudio devices. Fixes crash
 on OS X.

---
 src/modules/macosx/module-coreaudio-device.c |   13 +++++++++++++
 1 files changed, 13 insertions(+), 0 deletions(-)

diff --git a/src/modules/macosx/module-coreaudio-device.c b/src/modules/macosx/module-coreaudio-device.c
index 47fd1e6..fc5ce96 100644
--- a/src/modules/macosx/module-coreaudio-device.c
+++ b/src/modules/macosx/module-coreaudio-device.c
@@ -22,6 +22,7 @@
 /* TODO:
     - implement hardware volume controls
     - handle audio device stream format changes (will require changes to the core)
+    - add an "off" mode that removes all sinks and sources
 */
 
 #ifdef HAVE_CONFIG_H
@@ -43,6 +44,7 @@
 #include <pulsecore/strbuf.h>
 #include <pulsecore/thread.h>
 #include <pulsecore/thread-mq.h>
+#include <pulsecore/i18n.h>
 
 #include <CoreAudio/CoreAudio.h>
 #include <CoreAudio/CoreAudioTypes.h>
@@ -125,6 +127,10 @@ struct coreaudio_source {
     PA_LLIST_FIELDS(coreaudio_source);
 };
 
+static int card_set_profile(pa_card *c, pa_card_profile *new_profile) {
+    return 0;
+}
+
 static OSStatus io_render_proc (AudioDeviceID          device,
                                 const AudioTimeStamp  *now,
                                 const AudioBufferList *inputData,
@@ -686,6 +692,7 @@ int pa__init(pa_module *m) {
     pa_modargs *ma = NULL;
     char tmp[64];
     pa_card_new_data card_new_data;
+    pa_card_profile *p;
     coreaudio_sink *ca_sink;
     coreaudio_source *ca_source;
     AudioObjectPropertyAddress property_address;
@@ -733,6 +740,11 @@ int pa__init(pa_module *m) {
     if (!err)
         u->vendor_name = pa_xstrdup(tmp);
 
+    /* add on profile */
+    p = pa_card_profile_new("on", _("On"), 0);
+    pa_hashmap_put(card_new_data.profiles, p->name, p);
+    pa_card_new_data_set_profile(&card_new_data, "on");
+
     /* create the card object */
     u->card = pa_card_new(m->core, &card_new_data);
     if (!u->card) {
@@ -742,6 +754,7 @@ int pa__init(pa_module *m) {
 
     pa_card_new_data_done(&card_new_data);
     u->card->userdata = u;
+    u->card->set_profile = card_set_profile;
 
     u->rtpoll = pa_rtpoll_new();
     pa_thread_mq_init(&u->thread_mq, m->core->mainloop, u->rtpoll);
-- 
1.7.4.4


More information about the pulseaudio-discuss mailing list