This changes the way the latency offset is restored. It is now restored separately for every port during port creation. The debug message was also changed, it now prints the port name and offset. --- src/modules/module-card-restore.c | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/src/modules/module-card-restore.c b/src/modules/module-card-restore.c index 2b3235c..bb1be68 100644 --- a/src/modules/module-card-restore.c +++ b/src/modules/module-card-restore.c @@ -65,6 +65,7 @@ struct userdata { pa_hook_slot *card_new_hook_slot; pa_hook_slot *card_put_hook_slot; pa_hook_slot *card_profile_hook_slot; + pa_hook_slot *port_new_hook_slot; pa_hook_slot *port_offset_hook_slot; pa_time_event *save_time_event; pa_database *database; @@ -434,11 +435,26 @@ static pa_hook_result_t port_offset_change_callback(pa_core *c, pa_device_port * return PA_HOOK_OK; } +static pa_hook_result_t port_new_callback(pa_core *c, pa_device_port_new_data *new_data, struct userdata *u) { + struct entry *entry; + struct port_info *p_info; + + if (!new_data->card_name || !(entry = entry_read(u, new_data->card_name))) + return PA_HOOK_OK; + + + if ((p_info = pa_hashmap_get(entry->ports, new_data->name))) { + pa_log_info("Restoring port latency offsets for port %s: %" PRId64 " usecs", new_data->name, p_info->offset); + pa_device_port_new_data_set_latency_offset(new_data, p_info->offset); + } + + entry_free(entry); + + return PA_HOOK_OK; +} + static pa_hook_result_t card_new_hook_callback(pa_core *c, pa_card_new_data *new_data, struct userdata *u) { struct entry *e; - void *state; - pa_device_port *p; - struct port_info *p_info; pa_assert(new_data); @@ -455,15 +471,6 @@ static pa_hook_result_t card_new_hook_callback(pa_core *c, pa_card_new_data *new pa_log_debug("Not restoring profile for card %s, because already set.", new_data->name); } - /* Always restore the latency offsets because their - * initial value is always 0 */ - - pa_log_info("Restoring port latency offsets for card %s.", new_data->name); - - PA_HASHMAP_FOREACH(p_info, e->ports, state) - if ((p = pa_hashmap_get(new_data->ports, p_info->name))) - p->latency_offset = p_info->offset; - entry_free(e); return PA_HOOK_OK; @@ -488,6 +495,7 @@ 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->port_new_hook_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_PORT_NEW], PA_HOOK_EARLY, (pa_hook_cb_t) port_new_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; @@ -527,6 +535,7 @@ void pa__done(pa_module*m) { 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->port_new_hook_slot); pa_hook_slot_free(u->port_offset_hook_slot); } -- 1.8.2.1