diff options
Diffstat (limited to 'src/modules')
-rw-r--r-- | src/modules/module-card-restore.c | 13 | ||||
-rw-r--r-- | src/modules/module-device-restore.c | 15 | ||||
-rw-r--r-- | src/modules/module-position-event-sounds.c | 12 | ||||
-rw-r--r-- | src/modules/module-raop-sink.c | 65 | ||||
-rw-r--r-- | src/modules/module-stream-restore.c | 73 |
5 files changed, 100 insertions, 78 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-raop-sink.c b/src/modules/module-raop-sink.c index 74ee6122..1784b2cc 100644 --- a/src/modules/module-raop-sink.c +++ b/src/modules/module-raop-sink.c @@ -100,9 +100,6 @@ struct userdata { pa_usec_t latency; - pa_volume_t volume; - pa_bool_t muted; - /*esd_format_t format;*/ int32_t rate; @@ -133,6 +130,9 @@ enum { SINK_MESSAGE_RIP_SOCKET }; +/* Forward declaration */ +static void sink_set_volume_cb(pa_sink *); + static void on_connection(PA_GCC_UNUSED int fd, void*userdata) { struct userdata *u = userdata; pa_assert(u); @@ -141,7 +141,7 @@ static void on_connection(PA_GCC_UNUSED int fd, void*userdata) { u->fd = fd; /* Set the initial volume */ - pa_raop_client_set_volume(u->raop, u->volume); + sink_set_volume_cb(u->sink); pa_log_debug("Connection authenticated, handing fd to IO thread..."); @@ -255,43 +255,36 @@ static int sink_process_msg(pa_msgobject *o, int code, void *data, int64_t offse return pa_sink_process_msg(o, code, data, offset, chunk); } -static void sink_get_volume_cb(pa_sink *s) { - struct userdata *u = s->userdata; - int i; - - pa_assert(u); - - for (i = 0; i < s->sample_spec.channels; i++) - s->virtual_volume.values[i] = u->volume; -} - static void sink_set_volume_cb(pa_sink *s) { struct userdata *u = s->userdata; - int rv; + pa_cvolume hw; + pa_volume_t v; + char t[PA_CVOLUME_SNPRINT_MAX]; pa_assert(u); - /* If we're muted, we fake it */ - if (u->muted) + /* If we're muted we don't need to do anything */ + if (s->muted) return; - pa_assert(s->sample_spec.channels > 0); + /* Calculate the max volume of all channels. + We'll use this as our (single) volume on the APEX device and emulate + any variation in channel volumes in software */ + v = pa_cvolume_max(&s->virtual_volume); - /* Avoid pointless volume sets */ - if (u->volume == s->virtual_volume.values[0]) - return; + /* Create a pa_cvolume version of our single value */ + pa_cvolume_set(&hw, s->sample_spec.channels, v); - rv = pa_raop_client_set_volume(u->raop, s->virtual_volume.values[0]); - if (0 == rv) - u->volume = s->virtual_volume.values[0]; -} + /* Perform any software manipulation of the volume needed */ + pa_sw_cvolume_divide(&s->soft_volume, &s->virtual_volume, &hw); -static void sink_get_mute_cb(pa_sink *s) { - struct userdata *u = s->userdata; + pa_log_debug("Requested volume: %s", pa_cvolume_snprint(t, sizeof(t), &s->virtual_volume)); + pa_log_debug("Got hardware volume: %s", pa_cvolume_snprint(t, sizeof(t), &hw)); + pa_log_debug("Calculated software volume: %s", pa_cvolume_snprint(t, sizeof(t), &s->soft_volume)); - pa_assert(u); - - s->muted = u->muted; + /* Any necessary software volume manipulateion is done so set + our hw volume (or v as a single value) on the device */ + pa_raop_client_set_volume(u->raop, v); } static void sink_set_mute_cb(pa_sink *s) { @@ -299,8 +292,11 @@ static void sink_set_mute_cb(pa_sink *s) { pa_assert(u); - pa_raop_client_set_volume(u->raop, (s->muted ? PA_VOLUME_MUTED : u->volume)); - u->muted = s->muted; + if (s->muted) { + pa_raop_client_set_volume(u->raop, PA_VOLUME_MUTED); + } else { + sink_set_volume_cb(s); + } } static void thread_func(void *userdata) { @@ -541,9 +537,6 @@ int pa__init(pa_module*m) { u->next_encoding_overhead = 0; u->encoding_ratio = 1.0; - u->volume = roundf(0.7 * PA_VOLUME_NORM); - u->muted = FALSE; - u->rtpoll = pa_rtpoll_new(); pa_thread_mq_init(&u->thread_mq, m->core->mainloop, u->rtpoll); u->rtpoll_item = NULL; @@ -583,9 +576,7 @@ int pa__init(pa_module*m) { u->sink->parent.process_msg = sink_process_msg; u->sink->userdata = u; - u->sink->get_volume = sink_get_volume_cb; u->sink->set_volume = sink_set_volume_cb; - u->sink->get_mute = sink_get_mute_cb; u->sink->set_mute = sink_set_mute_cb; u->sink->flags = PA_SINK_LATENCY|PA_SINK_NETWORK|PA_SINK_HW_VOLUME_CTRL; 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; |