This patch separates the pa_card_put code from pa_card_new to allow the card module to initialise the default profile (and have the sinks and sources created) before finishing the card registration. Previously, PA_CORE_HOOK_CARD_PUT was being fired without the card having any sinks or sources. --- src/modules/alsa/module-alsa-card.c | 2 ++ src/modules/bluetooth/module-bluetooth-device.c | 2 ++ src/modules/macosx/module-coreaudio-device.c | 2 ++ src/pulsecore/card.c | 17 +++++++++++++---- src/pulsecore/card.h | 2 ++ 5 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/modules/alsa/module-alsa-card.c b/src/modules/alsa/module-alsa-card.c index 366f4ba..2ab4c5c 100644 --- a/src/modules/alsa/module-alsa-card.c +++ b/src/modules/alsa/module-alsa-card.c @@ -688,6 +688,8 @@ int pa__init(pa_module *m) { "is abused (i.e. fixes are not pushed to ALSA), the decibel fix feature may be removed in some future " "PulseAudio version.", u->card->name); + pa_card_put(u->card); + return 0; fail: diff --git a/src/modules/bluetooth/module-bluetooth-device.c b/src/modules/bluetooth/module-bluetooth-device.c index 06b4033..40c3d4f 100644 --- a/src/modules/bluetooth/module-bluetooth-device.c +++ b/src/modules/bluetooth/module-bluetooth-device.c @@ -3130,6 +3130,8 @@ int pa__init(pa_module* m) { if (init_profile(u) < 0) goto fail; + pa_card_put(u->card); + if (u->sink || u->source) if (start_thread(u) < 0) goto fail; diff --git a/src/modules/macosx/module-coreaudio-device.c b/src/modules/macosx/module-coreaudio-device.c index 6d39158..824eb9b 100644 --- a/src/modules/macosx/module-coreaudio-device.c +++ b/src/modules/macosx/module-coreaudio-device.c @@ -768,6 +768,8 @@ int pa__init(pa_module *m) { /* create sources */ ca_device_create_streams(m, TRUE); + pa_card_put(u->card); + /* create the message thread */ if (!(u->thread = pa_thread_new(u->device_name, thread_func, u))) { pa_log("Failed to create thread."); diff --git a/src/pulsecore/card.c b/src/pulsecore/card.c index 492c051..6e179fb 100644 --- a/src/pulsecore/card.c +++ b/src/pulsecore/card.c @@ -172,15 +172,24 @@ pa_card *pa_card_new(pa_core *core, pa_card_new_data *data) { pa_device_init_icon(c->proplist, TRUE); pa_device_init_intended_roles(c->proplist); - pa_assert_se(pa_idxset_put(core->cards, c, &c->index) >= 0); - pa_log_info("Created %u \"%s\"", c->index, c->name); - pa_subscription_post(core, PA_SUBSCRIPTION_EVENT_CARD|PA_SUBSCRIPTION_EVENT_NEW, c->index); - pa_hook_fire(&core->hooks[PA_CORE_HOOK_CARD_PUT], c); return c; } +void pa_card_put(pa_card *c) { + pa_assert(c); + /* A card should have at least a sink or a source? What about the Off profile? */ + /* pa_assert(!pa_idxset_is_empty(c->sinks) || !pa_idxset_is_empty(c->sources)); */ + /* TODO: do I need to check for other stuff? */ + /* pa_assert(c->set_profile); */ + + pa_assert_se(pa_idxset_put(c->core->cards, c, &c->index) >= 0); + + pa_subscription_post(c->core, PA_SUBSCRIPTION_EVENT_CARD|PA_SUBSCRIPTION_EVENT_NEW, c->index); + pa_hook_fire(&c->core->hooks[PA_CORE_HOOK_CARD_PUT], c); +} + void pa_card_free(pa_card *c) { pa_core *core; diff --git a/src/pulsecore/card.h b/src/pulsecore/card.h index 6f942e8..f592589 100644 --- a/src/pulsecore/card.h +++ b/src/pulsecore/card.h @@ -100,6 +100,8 @@ void pa_card_new_data_done(pa_card_new_data *data); pa_card *pa_card_new(pa_core *c, pa_card_new_data *data); void pa_card_free(pa_card *c); +void pa_card_put(pa_card *c); + int pa_card_set_profile(pa_card *c, const char *name, pa_bool_t save); int pa_card_suspend(pa_card *c, pa_bool_t suspend, pa_suspend_cause_t cause); -- 1.7.11.2