This patch adds the ability to restore profiles if they are added after card creation. Adding profiles after card creation mainly happens for bluetooth cards. Buglink: https://bugs.freedesktop.org/show_bug.cgi?id=65349 --- src/modules/module-card-restore.c | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/src/modules/module-card-restore.c b/src/modules/module-card-restore.c index 928f153..4feb68b 100644 --- a/src/modules/module-card-restore.c +++ b/src/modules/module-card-restore.c @@ -64,7 +64,8 @@ struct userdata { pa_module *module; pa_hook_slot *card_new_hook_slot; pa_hook_slot *card_put_hook_slot; - pa_hook_slot *card_profile_hook_slot; + pa_hook_slot *card_profile_changed_hook_slot; + pa_hook_slot *card_profile_added_hook_slot; pa_hook_slot *port_offset_hook_slot; pa_time_event *save_time_event; pa_database *database; @@ -380,7 +381,7 @@ finish: return PA_HOOK_OK; } -static pa_hook_result_t card_profile_change_callback(pa_core *c, pa_card *card, struct userdata *u) { +static pa_hook_result_t card_profile_changed_callback(pa_core *c, pa_card *card, struct userdata *u) { struct entry *entry; pa_assert(card); @@ -403,6 +404,24 @@ static pa_hook_result_t card_profile_change_callback(pa_core *c, pa_card *card, return PA_HOOK_OK; } +static pa_hook_result_t card_profile_added_callback(pa_core *c, pa_card_profile *profile, struct userdata *u) { + struct entry *entry; + + pa_assert(profile); + + if (!(entry = entry_read(u, profile->card->name))) + return PA_HOOK_OK; + + if (pa_safe_streq(entry->profile, profile->name)) { + pa_card_set_profile(profile->card, profile->name, true); + pa_log_info("Restored profile '%s' for card %s.", profile->name, profile->card->name); + } + + entry_free(entry); + + return PA_HOOK_OK; +} + static pa_hook_result_t port_offset_change_callback(pa_core *c, pa_device_port *port, struct userdata *u) { struct entry *entry; pa_card *card; @@ -487,7 +506,8 @@ int pa__init(pa_module*m) { u->card_new_hook_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_CARD_NEW], PA_HOOK_EARLY, (pa_hook_cb_t) card_new_hook_callback, u); u->card_put_hook_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_CARD_PUT], PA_HOOK_NORMAL, (pa_hook_cb_t) card_put_hook_callback, u); - u->card_profile_hook_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_CARD_PROFILE_CHANGED], PA_HOOK_NORMAL, (pa_hook_cb_t) card_profile_change_callback, u); + u->card_profile_changed_hook_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_CARD_PROFILE_CHANGED], PA_HOOK_NORMAL, (pa_hook_cb_t) card_profile_changed_callback, u); + u->card_profile_added_hook_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_CARD_PROFILE_ADDED], PA_HOOK_NORMAL, (pa_hook_cb_t) card_profile_added_callback, u); u->port_offset_hook_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_PORT_LATENCY_OFFSET_CHANGED], PA_HOOK_NORMAL, (pa_hook_cb_t) port_offset_change_callback, u); u->hooks_connected = true; @@ -526,7 +546,8 @@ void pa__done(pa_module*m) { if (u->hooks_connected) { pa_hook_slot_free(u->card_new_hook_slot); pa_hook_slot_free(u->card_put_hook_slot); - pa_hook_slot_free(u->card_profile_hook_slot); + pa_hook_slot_free(u->card_profile_changed_hook_slot); + pa_hook_slot_free(u->card_profile_added_hook_slot); pa_hook_slot_free(u->port_offset_hook_slot); } -- 1.8.3.3