summaryrefslogtreecommitdiffstats
path: root/src/modules
diff options
context:
space:
mode:
Diffstat (limited to 'src/modules')
-rw-r--r--src/modules/module-card-restore.c13
-rw-r--r--src/modules/module-device-restore.c15
-rw-r--r--src/modules/module-position-event-sounds.c12
-rw-r--r--src/modules/module-stream-restore.c73
4 files changed, 72 insertions, 41 deletions
diff --git a/src/modules/module-card-restore.c b/src/modules/module-card-restore.c
index 02e973c4..4dffd365 100644
--- a/src/modules/module-card-restore.c
+++ b/src/modules/module-card-restore.c
@@ -68,7 +68,10 @@ struct userdata {
GDBM_FILE gdbm_file;
};
-struct entry {
+#define ENTRY_VERSION 1
+
+struct entry PA_GCC_PACKED {
+ uint8_t version;
char profile[PA_NAME_MAX];
};
@@ -104,12 +107,17 @@ static struct entry* read_entry(struct userdata *u, const char *name) {
goto fail;
if (data.dsize != sizeof(struct entry)) {
- pa_log_warn("Database contains entry for card %s of wrong size %lu != %lu", name, (unsigned long) data.dsize, (unsigned long) sizeof(struct entry));
+ pa_log_debug("Database contains entry for card %s of wrong size %lu != %lu. Probably due to upgrade, ignoring.", name, (unsigned long) data.dsize, (unsigned long) sizeof(struct entry));
goto fail;
}
e = (struct entry*) data.dptr;
+ if (e->version != ENTRY_VERSION) {
+ pa_log_debug("Version of database entry for card %s doesn't match our version. Probably due to upgrade, ignoring.", name);
+ goto fail;
+ }
+
if (!memchr(e->profile, 0, sizeof(e->profile))) {
pa_log_warn("Database contains entry for card %s with missing NUL byte in profile name", name);
goto fail;
@@ -148,6 +156,7 @@ static void subscribe_callback(pa_core *c, pa_subscription_event_type_t t, uint3
return;
memset(&entry, 0, sizeof(entry));
+ entry.version = ENTRY_VERSION;
if (!(card = pa_idxset_get_by_index(c->cards, idx)))
return;
diff --git a/src/modules/module-device-restore.c b/src/modules/module-device-restore.c
index 8e0cf92b..7c56c240 100644
--- a/src/modules/module-device-restore.c
+++ b/src/modules/module-device-restore.c
@@ -79,10 +79,13 @@ struct userdata {
pa_bool_t restore_muted:1;
};
-struct entry {
+#define ENTRY_VERSION 1
+
+struct entry PA_GCC_PACKED {
+ uint8_t version;
+ pa_bool_t muted:1;
pa_channel_map channel_map;
pa_cvolume volume;
- pa_bool_t muted:1;
};
static void save_time_callback(pa_mainloop_api*a, pa_time_event* e, const struct timeval *tv, void *userdata) {
@@ -117,12 +120,17 @@ static struct entry* read_entry(struct userdata *u, const char *name) {
goto fail;
if (data.dsize != sizeof(struct entry)) {
- pa_log_warn("Database contains entry for device %s of wrong size %lu != %lu", name, (unsigned long) data.dsize, (unsigned long) sizeof(struct entry));
+ pa_log_debug("Database contains entry for device %s of wrong size %lu != %lu. Probably due to upgrade, ignoring.", name, (unsigned long) data.dsize, (unsigned long) sizeof(struct entry));
goto fail;
}
e = (struct entry*) data.dptr;
+ if (e->version != ENTRY_VERSION) {
+ pa_log_debug("Version of database entry for device %s doesn't match our version. Probably due to upgrade, ignoring.", name);
+ goto fail;
+ }
+
if (!(pa_cvolume_valid(&e->volume))) {
pa_log_warn("Invalid volume stored in database for device %s", name);
goto fail;
@@ -173,6 +181,7 @@ static void subscribe_callback(pa_core *c, pa_subscription_event_type_t t, uint3
return;
memset(&entry, 0, sizeof(entry));
+ entry.version = ENTRY_VERSION;
if ((t & PA_SUBSCRIPTION_EVENT_FACILITY_MASK) == PA_SUBSCRIPTION_EVENT_SINK) {
pa_sink *sink;
diff --git a/src/modules/module-position-event-sounds.c b/src/modules/module-position-event-sounds.c
index 8e4f4c32..e17cbe80 100644
--- a/src/modules/module-position-event-sounds.c
+++ b/src/modules/module-position-event-sounds.c
@@ -80,16 +80,16 @@ static pa_hook_result_t sink_input_fixate_hook_callback(pa_core *core, pa_sink_i
pa_log_debug("Positioning event sound '%s' at %0.2f.", pa_strnull(pa_proplist_gets(data->proplist, PA_PROP_EVENT_ID)), f);
- if (!data->virtual_volume_is_set) {
- pa_cvolume_reset(&data->virtual_volume, data->sample_spec.channels);
- data->virtual_volume_is_set = TRUE;
- data->virtual_volume_is_absolute = FALSE;
+ if (!data->volume_is_set) {
+ pa_cvolume_reset(&data->volume, data->sample_spec.channels);
+ data->volume_is_set = TRUE;
+ data->volume_is_absolute = FALSE;
}
- pa_cvolume_set_balance(&data->virtual_volume, &data->channel_map, f*2.0-1.0);
+ pa_cvolume_set_balance(&data->volume, &data->channel_map, f*2.0-1.0);
data->save_volume = FALSE;
- pa_log_debug("Final volume %s.", pa_cvolume_snprint(t, sizeof(t), &data->virtual_volume));
+ pa_log_debug("Final volume %s.", pa_cvolume_snprint(t, sizeof(t), &data->volume));
return PA_HOOK_OK;
}
diff --git a/src/modules/module-stream-restore.c b/src/modules/module-stream-restore.c
index 0c9bd4f9..b1630fe1 100644
--- a/src/modules/module-stream-restore.c
+++ b/src/modules/module-stream-restore.c
@@ -90,16 +90,18 @@ struct userdata {
pa_idxset *subscribed;
};
-struct entry {
+#define ENTRY_VERSION 1
+
+struct entry PA_GCC_PACKED {
+ uint8_t version;
+ pa_bool_t muted_valid:1, relative_volume_valid:1, absolute_volume_valid:1, device_valid:1;
+ pa_bool_t muted:1;
pa_channel_map channel_map;
- char device[PA_NAME_MAX];
pa_cvolume relative_volume;
pa_cvolume absolute_volume;
- pa_bool_t muted:1;
- pa_bool_t device_valid:1, relative_volume_valid:1, absolute_volume_valid:1, muted_valid:1;
+ char device[PA_NAME_MAX];
};
-
enum {
SUBCOMMAND_TEST,
SUBCOMMAND_READ,
@@ -161,19 +163,19 @@ static struct entry* read_entry(struct userdata *u, const char *name) {
if (data.dsize != sizeof(struct entry)) {
/* This is probably just a database upgrade, hence let's not
* consider this more than a debug message */
- pa_log_debug("Database contains entry for stream %s of wrong size %lu != %lu", name, (unsigned long) data.dsize, (unsigned long) sizeof(struct entry));
+ pa_log_debug("Database contains entry for stream %s of wrong size %lu != %lu. Probably due to uprade, ignoring.", name, (unsigned long) data.dsize, (unsigned long) sizeof(struct entry));
goto fail;
}
e = (struct entry*) data.dptr;
- if (!memchr(e->device, 0, sizeof(e->device))) {
- pa_log_warn("Database contains entry for stream %s with missing NUL byte in device name", name);
+ if (e->version != ENTRY_VERSION) {
+ pa_log_debug("Version of database entry for stream %s doesn't match our version. Probably due to upgrade, ignoring.", name);
goto fail;
}
- if (!(pa_channel_map_valid(&e->channel_map))) {
- pa_log_warn("Invalid channel map stored in database for stream %s", name);
+ if (!memchr(e->device, 0, sizeof(e->device))) {
+ pa_log_warn("Database contains entry for stream %s with missing NUL byte in device name", name);
goto fail;
}
@@ -182,6 +184,11 @@ static struct entry* read_entry(struct userdata *u, const char *name) {
goto fail;
}
+ if ((e->relative_volume_valid || e->absolute_volume_valid) && !(pa_channel_map_valid(&e->channel_map))) {
+ pa_log_warn("Invalid channel map stored in database for stream %s", name);
+ goto fail;
+ }
+
if ((e->relative_volume_valid && (!pa_cvolume_valid(&e->relative_volume) || e->relative_volume.channels != e->channel_map.channels)) ||
(e->absolute_volume_valid && (!pa_cvolume_valid(&e->absolute_volume) || e->absolute_volume.channels != e->channel_map.channels))) {
pa_log_warn("Invalid volume stored in database for stream %s", name);
@@ -233,7 +240,7 @@ static pa_bool_t entries_equal(const struct entry *a, const struct entry *b) {
return FALSE;
if (a->muted_valid != b->muted_valid ||
- (a->muted && (a->muted != b->muted)))
+ (a->muted_valid && (a->muted != b->muted)))
return FALSE;
t = b->relative_volume;
@@ -265,6 +272,7 @@ static void subscribe_callback(pa_core *c, pa_subscription_event_type_t t, uint3
return;
memset(&entry, 0, sizeof(entry));
+ entry.version = ENTRY_VERSION;
if ((t & PA_SUBSCRIPTION_EVENT_FACILITY_MASK) == PA_SUBSCRIPTION_EVENT_SINK_INPUT) {
pa_sink_input *sink_input;
@@ -388,32 +396,33 @@ static pa_hook_result_t sink_input_fixate_hook_callback(pa_core *c, pa_sink_inpu
if (u->restore_volume) {
- if (!new_data->virtual_volume_is_set) {
+ if (!new_data->volume_is_set) {
pa_cvolume v;
pa_cvolume_init(&v);
if (new_data->sink->flags & PA_SINK_FLAT_VOLUME) {
+ /* We don't check for e->device_valid here because
+ that bit marks whether it is a good choice for
+ restoring, not just if the data is filled in. */
if (e->absolute_volume_valid &&
- e->device_valid &&
- pa_streq(new_data->sink->name, e->device)) {
+ (e->device[0] == 0 || pa_streq(new_data->sink->name, e->device))) {
v = e->absolute_volume;
- new_data->virtual_volume_is_absolute = TRUE;
+ new_data->volume_is_absolute = TRUE;
} else if (e->relative_volume_valid) {
-
v = e->relative_volume;
- new_data->virtual_volume_is_absolute = FALSE;
+ new_data->volume_is_absolute = FALSE;
}
} else if (e->relative_volume_valid) {
v = e->relative_volume;
- new_data->virtual_volume_is_absolute = FALSE;
+ new_data->volume_is_absolute = FALSE;
}
if (v.channels > 0) {
pa_log_info("Restoring volume for sink input %s.", name);
- pa_sink_input_new_data_set_virtual_volume(new_data, pa_cvolume_remap(&v, &e->channel_map, &new_data->channel_map));
+ pa_sink_input_new_data_set_volume(new_data, pa_cvolume_remap(&v, &e->channel_map, &new_data->channel_map));
new_data->save_volume = TRUE;
}
} else
@@ -523,11 +532,10 @@ static void apply_entry(struct userdata *u, const char *name, struct entry *e) {
if (si->sink->flags & PA_SINK_FLAT_VOLUME) {
if (e->absolute_volume_valid &&
- e->device_valid &&
- pa_streq(e->device, si->sink->name))
+ (e->device[0] == 0 || pa_streq(e->device, si->sink->name)))
v = e->absolute_volume;
else if (e->relative_volume_valid) {
- pa_cvolume t = si->sink->virtual_volume;
+ pa_cvolume t = *pa_sink_get_volume(si->sink, FALSE);
pa_sw_cvolume_multiply(&v, &e->relative_volume, pa_cvolume_remap(&t, &si->sink->channel_map, &e->channel_map));
}
} else if (e->relative_volume_valid)
@@ -655,10 +663,11 @@ static int extension_cb(pa_native_protocol *p, pa_module *m, pa_native_connectio
if ((e = read_entry(u, name))) {
pa_cvolume r;
+ pa_channel_map cm;
pa_tagstruct_puts(reply, name);
- pa_tagstruct_put_channel_map(reply, &e->channel_map);
- pa_tagstruct_put_cvolume(reply, e->relative_volume_valid ? &e->relative_volume : pa_cvolume_init(&r));
+ pa_tagstruct_put_channel_map(reply, (e->relative_volume_valid || e->absolute_volume_valid) ? &e->channel_map : pa_channel_map_init(&cm));
+ pa_tagstruct_put_cvolume(reply, e->absolute_volume_valid ? &e->absolute_volume : (e->relative_volume_valid ? &e->relative_volume : pa_cvolume_init(&r)));
pa_tagstruct_puts(reply, e->device_valid ? e->device : NULL);
pa_tagstruct_put_boolean(reply, e->muted_valid ? e->muted : FALSE);
@@ -697,21 +706,25 @@ static int extension_cb(pa_native_protocol *p, pa_module *m, pa_native_connectio
int k;
memset(&entry, 0, sizeof(entry));
+ entry.version = ENTRY_VERSION;
if (pa_tagstruct_gets(t, &name) < 0 ||
pa_tagstruct_get_channel_map(t, &entry.channel_map) ||
- pa_tagstruct_get_cvolume(t, &entry.relative_volume) < 0 ||
+ pa_tagstruct_get_cvolume(t, &entry.absolute_volume) < 0 ||
pa_tagstruct_gets(t, &device) < 0 ||
pa_tagstruct_get_boolean(t, &muted) < 0)
goto fail;
- entry.absolute_volume_valid = FALSE;
- entry.relative_volume_valid = entry.relative_volume.channels > 0;
-
- if (entry.relative_volume_valid &&
- entry.channel_map.channels != entry.relative_volume.channels)
+ if (!name || !*name)
goto fail;
+ entry.relative_volume = entry.absolute_volume;
+ entry.absolute_volume_valid = entry.relative_volume_valid = entry.relative_volume.channels > 0;
+
+ if (entry.relative_volume_valid)
+ if (!pa_cvolume_compatible_with_channel_map(&entry.relative_volume, &entry.channel_map))
+ goto fail;
+
entry.muted = muted;
entry.muted_valid = TRUE;