From 32cf9db43475b33fd43f28897e4fa9ca149aba2c Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 4 Aug 2008 18:55:50 +0200 Subject: store channel map in database and remap volumes if ncessary --- src/modules/module-device-restore.c | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) (limited to 'src/modules/module-device-restore.c') diff --git a/src/modules/module-device-restore.c b/src/modules/module-device-restore.c index c0d2ddb7..d93b9e63 100644 --- a/src/modules/module-device-restore.c +++ b/src/modules/module-device-restore.c @@ -1,7 +1,7 @@ /*** This file is part of PulseAudio. - Copyright 2006 Lennart Poettering + Copyright 2006-2008 Lennart Poettering PulseAudio is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published @@ -64,6 +64,7 @@ static const char* const valid_modargs[] = { struct userdata { pa_core *core; + pa_module *module; pa_subscription *subscription; pa_hook_slot *sink_fixate_hook_slot, @@ -76,6 +77,7 @@ struct userdata { }; struct entry { + pa_channel_map channel_map; pa_cvolume volume; pa_bool_t muted:1; }; @@ -123,6 +125,16 @@ static struct entry* read_entry(struct userdata *u, char *name) { goto fail; } + if (!(pa_channel_map_valid(&e->channel_map))) { + pa_log_warn("Invalid channel map stored in database for device %s", name); + goto fail; + } + + if (e->volume.channels != e->channel_map.channels) { + pa_log_warn("Volume and channel map don't match in database entry for device %s", name); + goto fail; + } + return e; fail: @@ -153,6 +165,7 @@ static void subscribe_callback(pa_core *c, pa_subscription_event_type_t t, uint3 return; name = pa_sprintf_malloc("sink:%s", sink->name); + entry.channel_map = sink->channel_map; entry.volume = *pa_sink_get_volume(sink); entry.muted = pa_sink_get_mute(sink); @@ -165,13 +178,14 @@ static void subscribe_callback(pa_core *c, pa_subscription_event_type_t t, uint3 return; name = pa_sprintf_malloc("source:%s", source->name); + entry.channel_map = source->channel_map; entry.volume = *pa_source_get_volume(source); entry.muted = pa_source_get_mute(source); } if ((old = read_entry(u, name))) { - if (pa_cvolume_equal(&old->volume, &entry.volume) && + if (pa_cvolume_equal(pa_cvolume_remap(&old->volume, &old->channel_map, &entry.channel_map), &entry.volume) && !old->muted == !entry.muted) { pa_xfree(old); @@ -212,11 +226,9 @@ static pa_hook_result_t sink_fixate_hook_callback(pa_core *c, pa_sink_new_data * if ((e = read_entry(u, name))) { - if (u->restore_volume && - e->volume.channels == new_data->sample_spec.channels) { - + if (u->restore_volume) { pa_log_info("Restoring volume for sink %s.", new_data->name); - pa_sink_new_data_set_volume(new_data, &e->volume); + pa_sink_new_data_set_volume(new_data, pa_cvolume_remap(&e->volume, &e->channel_map, &new_data->channel_map)); } if (u->restore_muted) { @@ -242,11 +254,9 @@ static pa_hook_result_t source_fixate_hook_callback(pa_core *c, pa_source_new_da if ((e = read_entry(u, name))) { - if (u->restore_volume && - e->volume.channels == new_data->sample_spec.channels) { - + if (u->restore_volume) { pa_log_info("Restoring volume for source %s.", new_data->name); - pa_source_new_data_set_volume(new_data, &e->volume); + pa_source_new_data_set_volume(new_data, pa_cvolume_remap(&e->volume, &e->channel_map, &new_data->channel_map)); } if (u->restore_muted) { @@ -290,9 +300,11 @@ int pa__init(pa_module*m) { m->userdata = u = pa_xnew(struct userdata, 1); u->core = m->core; + u->module = m; u->save_time_event = NULL; u->restore_volume = restore_volume; u->restore_muted = restore_muted; + u->gdbm_file = NULL; u->subscription = pa_subscription_new(m->core, PA_SUBSCRIPTION_MASK_SINK|PA_SUBSCRIPTION_MASK_SOURCE, subscribe_callback, u); -- cgit From c01f0bc01ff1c4bdd3cbb66ae79e45c73add5011 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 4 Aug 2008 18:56:12 +0200 Subject: split out save trigger function --- src/modules/module-device-restore.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'src/modules/module-device-restore.c') diff --git a/src/modules/module-device-restore.c b/src/modules/module-device-restore.c index d93b9e63..fcd40219 100644 --- a/src/modules/module-device-restore.c +++ b/src/modules/module-device-restore.c @@ -143,6 +143,17 @@ fail: return NULL; } +static void trigger_save(struct userdata *u) { + struct timeval tv; + + if (u->save_time_event) + return; + + pa_gettimeofday(&tv); + tv.tv_sec += SAVE_INTERVAL; + u->save_time_event = u->core->mainloop->time_new(u->core->mainloop, &tv, save_time_callback, u); +} + static void subscribe_callback(pa_core *c, pa_subscription_event_type_t t, uint32_t idx, void *userdata) { struct userdata *u = userdata; struct entry entry, *old; @@ -158,6 +169,8 @@ static void subscribe_callback(pa_core *c, pa_subscription_event_type_t t, uint3 t != (PA_SUBSCRIPTION_EVENT_SOURCE|PA_SUBSCRIPTION_EVENT_CHANGE)) return; + memset(&entry, 0, sizeof(entry)); + if ((t & PA_SUBSCRIPTION_EVENT_FACILITY_MASK) == PA_SUBSCRIPTION_EVENT_SINK) { pa_sink *sink; @@ -206,14 +219,9 @@ static void subscribe_callback(pa_core *c, pa_subscription_event_type_t t, uint3 gdbm_store(u->gdbm_file, key, data, GDBM_REPLACE); - if (!u->save_time_event) { - struct timeval tv; - pa_gettimeofday(&tv); - tv.tv_sec += SAVE_INTERVAL; - u->save_time_event = u->core->mainloop->time_new(u->core->mainloop, &tv, save_time_callback, u); - } - pa_xfree(name); + + trigger_save(u); } static pa_hook_result_t sink_fixate_hook_callback(pa_core *c, pa_sink_new_data *new_data, struct userdata *u) { -- cgit From ecb2bc4f04e5a6a71e19d4be651596cebbb83500 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 7 Aug 2008 02:28:47 +0200 Subject: Modify pa_state_path() to take an additional argument for prepending the machine id to the file name. --- src/modules/module-device-restore.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/modules/module-device-restore.c') diff --git a/src/modules/module-device-restore.c b/src/modules/module-device-restore.c index fcd40219..3d731f12 100644 --- a/src/modules/module-device-restore.c +++ b/src/modules/module-device-restore.c @@ -284,7 +284,6 @@ int pa__init(pa_module*m) { pa_modargs *ma = NULL; struct userdata *u; char *fname, *fn; - char hn[256]; pa_sink *sink; pa_source *source; uint32_t idx; @@ -321,11 +320,12 @@ int pa__init(pa_module*m) { u->source_fixate_hook_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SOURCE_FIXATE], PA_HOOK_EARLY, (pa_hook_cb_t) source_fixate_hook_callback, u); } - if (!pa_get_host_name(hn, sizeof(hn))) - goto fail; + /* We include the host identifier in the file name because gdbm + * files are CPU dependant, and we don't want things to go wrong + * if we are on a multiarch system. */ - fn = pa_sprintf_malloc("device-volumes.%s."CANONICAL_HOST".gdbm", hn); - fname = pa_state_path(fn); + fn = pa_sprintf_malloc("device-volumes."CANONICAL_HOST".gdbm"); + fname = pa_state_path(fn, TRUE); pa_xfree(fn); if (!fname) -- cgit From 916899a9737613a06ff50c9616f1a1016805f8bc Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 13 Aug 2008 13:59:50 +0200 Subject: pass force_refresh=FALSE to all volume/mute read invocations --- src/modules/module-device-restore.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/modules/module-device-restore.c') diff --git a/src/modules/module-device-restore.c b/src/modules/module-device-restore.c index 3d731f12..f7d82e4d 100644 --- a/src/modules/module-device-restore.c +++ b/src/modules/module-device-restore.c @@ -179,8 +179,8 @@ static void subscribe_callback(pa_core *c, pa_subscription_event_type_t t, uint3 name = pa_sprintf_malloc("sink:%s", sink->name); entry.channel_map = sink->channel_map; - entry.volume = *pa_sink_get_volume(sink); - entry.muted = pa_sink_get_mute(sink); + entry.volume = *pa_sink_get_volume(sink, FALSE); + entry.muted = pa_sink_get_mute(sink, FALSE); } else { pa_source *source; @@ -192,8 +192,8 @@ static void subscribe_callback(pa_core *c, pa_subscription_event_type_t t, uint3 name = pa_sprintf_malloc("source:%s", source->name); entry.channel_map = source->channel_map; - entry.volume = *pa_source_get_volume(source); - entry.muted = pa_source_get_mute(source); + entry.volume = *pa_source_get_volume(source, FALSE); + entry.muted = pa_source_get_mute(source, FALSE); } if ((old = read_entry(u, name))) { -- cgit From b7026bf248948a6a30386ddbcc137f48f369a51e Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 19 Aug 2008 22:39:54 +0200 Subject: add a few more gcc warning flags and fix quite a few problems found by doing so --- src/modules/module-device-restore.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/modules/module-device-restore.c') diff --git a/src/modules/module-device-restore.c b/src/modules/module-device-restore.c index f7d82e4d..920b4517 100644 --- a/src/modules/module-device-restore.c +++ b/src/modules/module-device-restore.c @@ -106,7 +106,7 @@ static struct entry* read_entry(struct userdata *u, char *name) { pa_assert(name); key.dptr = name; - key.dsize = strlen(name); + key.dsize = (int) strlen(name); data = gdbm_fetch(u->gdbm_file, key); @@ -210,7 +210,7 @@ static void subscribe_callback(pa_core *c, pa_subscription_event_type_t t, uint3 } key.dptr = name; - key.dsize = strlen(name); + key.dsize = (int) strlen(name); data.dptr = (void*) &entry; data.dsize = sizeof(entry); -- cgit