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') 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') 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 eec623a23b6c30508d8bb4ecbdd1fff7c715a3f8 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 4 Aug 2008 18:58:29 +0200 Subject: add hooks for connection creation/deletion, for that export pa_native_connection --- src/modules/module-x11-publish.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/modules') diff --git a/src/modules/module-x11-publish.c b/src/modules/module-x11-publish.c index c29535e6..1dbc939d 100644 --- a/src/modules/module-x11-publish.c +++ b/src/modules/module-x11-publish.c @@ -152,7 +152,7 @@ int pa__init(pa_module*m) { u->x11_client = NULL; u->x11_wrapper = NULL; - u->hook_slot = pa_hook_connect(pa_native_protocol_servers_changed(u->protocol), PA_HOOK_NORMAL, servers_changed_cb, u); + u->hook_slot = pa_hook_connect(&pa_native_protocol_hooks(u->protocol)[PA_NATIVE_HOOK_SERVERS_CHANGED], PA_HOOK_NORMAL, servers_changed_cb, u); if (!(u->auth_cookie = pa_auth_cookie_get(m->core, pa_modargs_get_value(ma, "cookie", PA_NATIVE_COOKIE_FILE), PA_NATIVE_COOKIE_LENGTH))) goto fail; -- cgit From 6cc3a615fa4f2c0f53e77d431d77422433cda1f0 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 4 Aug 2008 19:00:43 +0200 Subject: store channel map in database and remap volumes if necessary --- src/modules/module-stream-restore.c | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) (limited to 'src/modules') diff --git a/src/modules/module-stream-restore.c b/src/modules/module-stream-restore.c index 22e2ff62..cac8a9bb 100644 --- a/src/modules/module-stream-restore.c +++ b/src/modules/module-stream-restore.c @@ -65,6 +65,7 @@ static const char* const valid_modargs[] = { struct userdata { pa_core *core; + pa_module *module; pa_subscription *subscription; pa_hook_slot *sink_input_new_hook_slot, @@ -79,8 +80,9 @@ struct userdata { }; struct entry { - pa_cvolume volume; char device[PA_NAME_MAX]; + pa_channel_map channel_map; + pa_cvolume volume; pa_bool_t muted:1; }; @@ -146,7 +148,17 @@ static struct entry* read_entry(struct userdata *u, char *name) { } if (!(pa_cvolume_valid(&e->volume))) { - pa_log_warn("Invalid volume stored in database for device %s", name); + pa_log_warn("Invalid volume stored in database for stream %s", name); + goto fail; + } + + if (!(pa_channel_map_valid(&e->channel_map))) { + pa_log_warn("Invalid channel map stored in database for stream %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 stream %s", name); goto fail; } @@ -182,6 +194,7 @@ static void subscribe_callback(pa_core *c, pa_subscription_event_type_t t, uint3 if (!(name = get_name(sink_input->proplist, "sink-input"))) return; + entry.channel_map = sink_input->channel_map; entry.volume = *pa_sink_input_get_volume(sink_input); entry.muted = pa_sink_input_get_mute(sink_input); pa_strlcpy(entry.device, sink_input->sink->name, sizeof(entry.device)); @@ -197,15 +210,16 @@ static void subscribe_callback(pa_core *c, pa_subscription_event_type_t t, uint3 if (!(name = get_name(source_output->proplist, "source-output"))) return; - memset(&entry.volume, 0, sizeof(entry.volume)); - entry.muted = FALSE; - + /* The following fields are filled in to make the entry valid + * according to read_entry(). They are otherwise useless */ + entry.channel_map = source_output->channel_map; + pa_cvolume_reset(&entry.volume, entry.channel_map.channels); pa_strlcpy(entry.device, source_output->source->name, sizeof(entry.device)); } 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 && strcmp(old->device, entry.device) == 0) { @@ -276,11 +290,9 @@ static pa_hook_result_t sink_input_fixate_hook_callback(pa_core *c, pa_sink_inpu 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 input %s.", name); - pa_sink_input_new_data_set_volume(new_data, &e->volume); + pa_sink_input_new_data_set_volume(new_data, pa_cvolume_remap(&e->volume, &e->channel_map, &new_data->channel_map)); } if (u->restore_muted) { @@ -353,6 +365,7 @@ 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_device = restore_device; u->restore_volume = restore_volume; -- cgit From 88c3db6636988e39c99220ba4969625b709e97ed Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 4 Aug 2008 19:01:13 +0200 Subject: add protocol extension to module-stream-restore --- src/modules/module-stream-restore.c | 332 ++++++++++++++++++++++++++++++++++-- 1 file changed, 322 insertions(+), 10 deletions(-) (limited to 'src/modules') diff --git a/src/modules/module-stream-restore.c b/src/modules/module-stream-restore.c index cac8a9bb..ee6fab42 100644 --- a/src/modules/module-stream-restore.c +++ b/src/modules/module-stream-restore.c @@ -46,6 +46,9 @@ #include #include #include +#include +#include +#include #include "module-stream-restore-symdef.h" @@ -70,13 +73,17 @@ struct userdata { pa_hook_slot *sink_input_new_hook_slot, *sink_input_fixate_hook_slot, - *source_output_new_hook_slot; + *source_output_new_hook_slot, + *connection_unlink_hook_slot; pa_time_event *save_time_event; GDBM_FILE gdbm_file; pa_bool_t restore_device:1; pa_bool_t restore_volume:1; pa_bool_t restore_muted:1; + + pa_native_protocol *protocol; + pa_idxset *subscribed; }; struct entry { @@ -86,6 +93,16 @@ struct entry { pa_bool_t muted:1; }; + +enum { + SUBCOMMAND_TEST, + SUBCOMMAND_READ, + SUBCOMMAND_WRITE, + SUBCOMMAND_DELETE, + SUBCOMMAND_SUBSCRIBE, + SUBCOMMAND_EVENT +}; + static void save_time_callback(pa_mainloop_api*a, pa_time_event* e, const struct timeval *tv, void *userdata) { struct userdata *u = userdata; @@ -170,6 +187,32 @@ fail: return NULL; } +static void trigger_save(struct userdata *u) { + struct timeval tv; + pa_native_connection *c; + uint32_t idx; + + for (c = pa_idxset_first(u->subscribed, &idx); c; c = pa_idxset_next(u->subscribed, &idx)) { + pa_tagstruct *t; + + t = pa_tagstruct_new(NULL, 0); + pa_tagstruct_putu32(t, PA_COMMAND_EXTENSION); + pa_tagstruct_putu32(t, 0); + pa_tagstruct_putu32(t, u->module->index); + pa_tagstruct_puts(t, u->module->name); + pa_tagstruct_putu32(t, SUBCOMMAND_EVENT); + + pa_pstream_send_tagstruct(pa_native_connection_get_pstream(c), t); + } + + 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; @@ -185,6 +228,8 @@ static void subscribe_callback(pa_core *c, pa_subscription_event_type_t t, uint3 t != (PA_SUBSCRIPTION_EVENT_SOURCE_OUTPUT|PA_SUBSCRIPTION_EVENT_CHANGE)) return; + memset(&entry, 0, sizeof(entry)); + if ((t & PA_SUBSCRIPTION_EVENT_FACILITY_MASK) == PA_SUBSCRIPTION_EVENT_SINK_INPUT) { pa_sink_input *sink_input; @@ -241,14 +286,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_input_new_hook_callback(pa_core *c, pa_sink_input_new_data *new_data, struct userdata *u) { @@ -264,7 +304,6 @@ static pa_hook_result_t sink_input_new_hook_callback(pa_core *c, pa_sink_input_n pa_sink *s; if (u->restore_device && - e->device[0] && (s = pa_namereg_get(c, e->device, PA_NAMEREG_SINK, TRUE))) { pa_log_info("Restoring device for stream %s.", name); @@ -321,7 +360,6 @@ static pa_hook_result_t source_output_new_hook_callback(pa_core *c, pa_source_ou pa_source *s; if (u->restore_device && - e->device[0] && (s = pa_namereg_get(c, e->device, PA_NAMEREG_SOURCE, TRUE))) { pa_log_info("Restoring device for stream %s.", name); @@ -336,6 +374,262 @@ static pa_hook_result_t source_output_new_hook_callback(pa_core *c, pa_source_ou return PA_HOOK_OK; } +#define EXT_VERSION 1 + +static void clear_db(struct userdata *u) { + datum key; + + pa_assert(u); + + key = gdbm_firstkey(u->gdbm_file); + while (key.dptr) { + datum next_key; + next_key = gdbm_nextkey(u->gdbm_file, key); + + gdbm_delete(u->gdbm_file, key); + pa_xfree(key.dptr); + + key = next_key; + } + + gdbm_reorganize(u->gdbm_file); +} + +static void apply_entry(struct userdata *u, const char *name, struct entry *e) { + pa_sink_input *si; + pa_source_output *so; + uint32_t idx; + + pa_assert(u); + pa_assert(name); + pa_assert(e); + + for (si = pa_idxset_first(u->core->sink_inputs, &idx); si; si = pa_idxset_next(u->core->sink_inputs, &idx)) { + char *n; + pa_sink *s; + + if (!(n = get_name(si->proplist, "sink_input"))) + continue; + + if (strcmp(name, n)) { + pa_xfree(n); + continue; + } + + if (u->restore_volume) { + pa_log_info("Restoring volume for sink input %s.", name); + pa_sink_input_set_volume(si, pa_cvolume_remap(&e->volume, &e->channel_map, &si->channel_map)); + } + + if (u->restore_muted) { + pa_log_info("Restoring mute state for sink input %s.", name); + pa_sink_input_set_mute(si, e->muted); + } + + if (u->restore_device && + (s = pa_namereg_get(u->core, e->device, PA_NAMEREG_SOURCE, TRUE))) { + + pa_log_info("Restoring device for stream %s.", name); + pa_sink_input_move_to(si, s); + } + } + + for (so = pa_idxset_first(u->core->source_outputs, &idx); so; so = pa_idxset_next(u->core->source_outputs, &idx)) { + char *n; + pa_source *s; + + if (!(n = get_name(so->proplist, "source-output"))) + continue; + + if (strcmp(name, n)) { + pa_xfree(n); + continue; + } + + if (u->restore_device && + (s = pa_namereg_get(u->core, e->device, PA_NAMEREG_SOURCE, TRUE))) { + + pa_log_info("Restoring device for stream %s.", name); + pa_source_output_move_to(so, s); + } + } +} + +static int extension_cb(pa_native_protocol *p, pa_module *m, pa_native_connection *c, uint32_t tag, pa_tagstruct *t) { + struct userdata *u; + uint32_t command; + pa_tagstruct *reply; + + pa_assert(p); + pa_assert(m); + pa_assert(c); + pa_assert(t); + + u = m->userdata; + + if (pa_tagstruct_getu32(t, &command) < 0) + goto fail; + + reply = pa_tagstruct_new(NULL, 0); + pa_tagstruct_putu32(reply, PA_COMMAND_REPLY); + pa_tagstruct_putu32(reply, tag); + + switch (command) { + case SUBCOMMAND_TEST: { + if (!pa_tagstruct_eof(t)) + goto fail; + + pa_tagstruct_putu32(reply, EXT_VERSION); + break; + } + + case SUBCOMMAND_READ: { + datum key; + + if (!pa_tagstruct_eof(t)) + goto fail; + + key = gdbm_firstkey(u->gdbm_file); + while (key.dptr) { + datum next_key; + struct entry *e; + char *name; + + next_key = gdbm_nextkey(u->gdbm_file, key); + + name = pa_xstrndup(key.dptr, key.dsize); + pa_xfree(key.dptr); + + if ((e = read_entry(u, name))) { + pa_tagstruct_puts(reply, name); + pa_tagstruct_put_channel_map(reply, &e->channel_map); + pa_tagstruct_put_cvolume(reply, &e->volume); + pa_tagstruct_puts(reply, e->device); + pa_tagstruct_put_boolean(reply, e->muted); + + pa_xfree(e); + } + + pa_xfree(name); + + key = next_key; + } + + break; + } + + case SUBCOMMAND_WRITE: { + uint32_t mode; + pa_bool_t apply_immediately; + + if (pa_tagstruct_getu32(t, &mode) < 0 || + pa_tagstruct_get_boolean(t, &apply_immediately) < 0) + goto fail; + + if (mode != PA_UPDATE_MERGE && + mode != PA_UPDATE_REPLACE && + mode != PA_UPDATE_SET) + goto fail; + + if (mode == PA_UPDATE_SET) + clear_db(u); + + while (!pa_tagstruct_eof(t)) { + const char *name, *device; + pa_bool_t muted; + struct entry entry; + datum key, data; + + memset(&entry, 0, sizeof(entry)); + + if (pa_tagstruct_gets(t, &name) < 0 || + pa_tagstruct_get_channel_map(t, &entry.channel_map) || + pa_tagstruct_get_cvolume(t, &entry.volume) < 0 || + pa_tagstruct_gets(t, &device) < 0 || + pa_tagstruct_get_boolean(t, &muted) < 0) + goto fail; + + if (entry.channel_map.channels != entry.volume.channels) + goto fail; + + entry.muted = muted; + pa_strlcpy(entry.device, device, sizeof(entry.device)); + + key.dptr = (void*) name; + key.dsize = strlen(name); + + data.dptr = (void*) &entry; + data.dsize = sizeof(entry); + + if (gdbm_store(u->gdbm_file, key, data, mode == PA_UPDATE_REPLACE ? GDBM_REPLACE : GDBM_INSERT) == 1) + if (apply_immediately) + apply_entry(u, name, &entry); + } + + trigger_save(u); + + break; + } + + case SUBCOMMAND_DELETE: + + while (!pa_tagstruct_eof(t)) { + const char *name; + datum key; + + if (pa_tagstruct_gets(t, &name) < 0) + goto fail; + + key.dptr = (void*) name; + key.dsize = strlen(name); + + gdbm_delete(u->gdbm_file, key); + } + + trigger_save(u); + + break; + + case SUBCOMMAND_SUBSCRIBE: { + + pa_bool_t enabled; + + if (pa_tagstruct_get_boolean(t, &enabled) < 0 || + !pa_tagstruct_eof(t)) + goto fail; + + if (enabled) + pa_idxset_put(u->subscribed, c, NULL); + else + pa_idxset_remove_by_data(u->subscribed, c, NULL); + + break; + } + + default: + goto fail; + } + + pa_pstream_send_tagstruct(pa_native_connection_get_pstream(c), reply); + return 0; + +fail: + + if (reply) + pa_tagstruct_free(reply); + + return -1; +} + +static pa_hook_result_t connection_unlink_hook_cb(pa_native_protocol *p, pa_native_connection *c, struct userdata *u) { + pa_assert(p); + pa_assert(c); + pa_assert(u); + + pa_idxset_remove_by_data(u->subscribed, c, NULL); + return PA_HOOK_OK; +} + int pa__init(pa_module*m) { pa_modargs *ma = NULL; struct userdata *u; @@ -370,6 +664,13 @@ int pa__init(pa_module*m) { u->restore_device = restore_device; u->restore_volume = restore_volume; u->restore_muted = restore_muted; + u->gdbm_file = NULL; + u->subscribed = pa_idxset_new(pa_idxset_trivial_hash_func, pa_idxset_trivial_compare_func); + + u->protocol = pa_native_protocol_get(m->core); + pa_native_protocol_install_ext(u->protocol, m, extension_cb); + + u->connection_unlink_hook_slot = pa_hook_connect(&pa_native_protocol_hooks(u->protocol)[PA_NATIVE_HOOK_CONNECTION_UNLINK], PA_HOOK_NORMAL, (pa_hook_cb_t) connection_unlink_hook_cb, u); u->subscription = pa_subscription_new(m->core, PA_SUBSCRIPTION_MASK_SINK_INPUT|PA_SUBSCRIPTION_MASK_SOURCE_OUTPUT, subscribe_callback, u); @@ -436,11 +737,22 @@ void pa__done(pa_module*m) { if (u->source_output_new_hook_slot) pa_hook_slot_free(u->source_output_new_hook_slot); + if (u->connection_unlink_hook_slot) + pa_hook_slot_free(u->connection_unlink_hook_slot); + if (u->save_time_event) u->core->mainloop->time_free(u->save_time_event); if (u->gdbm_file) gdbm_close(u->gdbm_file); + if (u->protocol) { + pa_native_protocol_remove_ext(u->protocol, m); + pa_native_protocol_unref(u->protocol); + } + + if (u->subscribed) + pa_idxset_free(u->subscribed, NULL, NULL); + pa_xfree(u); } -- cgit From ca127532fcddd28cc40bbbe0646a1205b365ffb7 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 5 Aug 2008 19:03:11 +0200 Subject: add a function to dump the stream database for debugging purposes --- src/modules/module-stream-restore.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'src/modules') diff --git a/src/modules/module-stream-restore.c b/src/modules/module-stream-restore.c index ee6fab42..b6d7b0f3 100644 --- a/src/modules/module-stream-restore.c +++ b/src/modules/module-stream-restore.c @@ -455,6 +455,38 @@ static void apply_entry(struct userdata *u, const char *name, struct entry *e) { } } +#if 0 +static void dump_database(struct userdata *u) { + datum key; + + key = gdbm_firstkey(u->gdbm_file); + while (key.dptr) { + datum next_key; + struct entry *e; + char *name; + + next_key = gdbm_nextkey(u->gdbm_file, key); + + name = pa_xstrndup(key.dptr, key.dsize); + pa_xfree(key.dptr); + + if ((e = read_entry(u, name))) { + char t[256]; + pa_log("name=%s", name); + pa_log("device=%s", e->device); + pa_log("channel_map=%s", pa_channel_map_snprint(t, sizeof(t), &e->channel_map)); + pa_log("volume=%s", pa_cvolume_snprint(t, sizeof(t), &e->volume)); + pa_log("mute=%s", pa_yes_no(e->muted)); + pa_xfree(e); + } + + pa_xfree(name); + + key = next_key; + } +} +#endif + static int extension_cb(pa_native_protocol *p, pa_module *m, pa_native_connection *c, uint32_t tag, pa_tagstruct *t) { struct userdata *u; uint32_t command; -- cgit From 34dd4a20f2e976b260e8aa3f3128e55ec80bb85b Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 5 Aug 2008 23:56:25 +0200 Subject: fix shutdown when --disallow-module-loading=1 is passed --- src/modules/gconf/module-gconf.c | 4 ++-- src/modules/module-always-sink.c | 4 ++-- src/modules/module-cli.c | 2 +- src/modules/module-combine.c | 2 +- src/modules/module-detect.c | 2 +- src/modules/module-esound-compat-spawnfd.c | 2 +- src/modules/module-esound-compat-spawnpid.c | 2 +- src/modules/module-esound-sink.c | 4 ++-- src/modules/module-hal-detect.c | 2 +- src/modules/module-ladspa-sink.c | 2 +- src/modules/module-lirc.c | 2 +- src/modules/module-mmkbd-evdev.c | 2 +- src/modules/module-remap-sink.c | 2 +- src/modules/module-sine.c | 2 +- src/modules/module-tunnel.c | 30 ++++++++++++++--------------- src/modules/module-x11-bell.c | 2 +- src/modules/module-x11-publish.c | 2 +- src/modules/module-x11-xsmp.c | 2 +- src/modules/module-zeroconf-discover.c | 10 +++++----- src/modules/module-zeroconf-publish.c | 2 +- src/modules/rtp/module-rtp-send.c | 2 +- 21 files changed, 42 insertions(+), 42 deletions(-) (limited to 'src/modules') diff --git a/src/modules/gconf/module-gconf.c b/src/modules/gconf/module-gconf.c index a2a43278..e2b0f7c0 100644 --- a/src/modules/gconf/module-gconf.c +++ b/src/modules/gconf/module-gconf.c @@ -142,7 +142,7 @@ static void unload_one_module(struct userdata *u, struct module_info*m, unsigned return; pa_log_debug("Unloading module #%i", m->items[i].index); - pa_module_unload_by_index(u->core, m->items[i].index); + pa_module_unload_by_index(u->core, m->items[i].index, TRUE); m->items[i].index = PA_INVALID_INDEX; pa_xfree(m->items[i].name); pa_xfree(m->items[i].args); @@ -324,7 +324,7 @@ static void io_event_cb( u->io_event = NULL; } - pa_module_unload_request(u->module); + pa_module_unload_request(u->module, TRUE); } } diff --git a/src/modules/module-always-sink.c b/src/modules/module-always-sink.c index 8b67a36d..9d60c29e 100644 --- a/src/modules/module-always-sink.c +++ b/src/modules/module-always-sink.c @@ -108,7 +108,7 @@ static pa_hook_result_t put_hook_callback(pa_core *c, pa_sink *sink, void* userd pa_log_info("A new sink has been discovered. Unloading null-sink."); - pa_module_unload_request(u->null_module); + pa_module_unload_request(u->null_module, TRUE); u->null_module = NULL; return PA_HOOK_OK; @@ -171,7 +171,7 @@ void pa__done(pa_module*m) { if (u->unlink_slot) pa_hook_slot_free(u->unlink_slot); if (u->null_module) - pa_module_unload_request(u->null_module); + pa_module_unload_request(u->null_module, TRUE); pa_xfree(u->sink_name); pa_xfree(u); diff --git a/src/modules/module-cli.c b/src/modules/module-cli.c index df7783fa..7a58877a 100644 --- a/src/modules/module-cli.c +++ b/src/modules/module-cli.c @@ -53,7 +53,7 @@ static void eof_and_unload_cb(pa_cli*c, void *userdata) { pa_assert(c); pa_assert(m); - pa_module_unload_request(m); + pa_module_unload_request(m, TRUE); } static void eof_and_exit_cb(pa_cli*c, void *userdata) { diff --git a/src/modules/module-combine.c b/src/modules/module-combine.c index 0a0b8d20..1bfe4b4c 100644 --- a/src/modules/module-combine.c +++ b/src/modules/module-combine.c @@ -489,7 +489,7 @@ static void sink_input_kill_cb(pa_sink_input *i) { pa_sink_input_assert_ref(i); pa_assert(o = i->userdata); - pa_module_unload_request(o->userdata->module); + pa_module_unload_request(o->userdata->module, TRUE); output_free(o); } diff --git a/src/modules/module-detect.c b/src/modules/module-detect.c index 13bcfcd1..09b720df 100644 --- a/src/modules/module-detect.c +++ b/src/modules/module-detect.c @@ -256,7 +256,7 @@ int pa__init(pa_module*m) { pa_log_info("loaded %i modules.", n); /* We were successful and can unload ourselves now. */ - pa_module_unload_request(m); + pa_module_unload_request(m, TRUE); pa_modargs_free(ma); diff --git a/src/modules/module-esound-compat-spawnfd.c b/src/modules/module-esound-compat-spawnfd.c index 8eb4985b..578ad3b5 100644 --- a/src/modules/module-esound-compat-spawnfd.c +++ b/src/modules/module-esound-compat-spawnfd.c @@ -66,7 +66,7 @@ int pa__init(pa_module*m) { pa_assert_se(pa_close(fd) == 0); - pa_module_unload_request(m); + pa_module_unload_request(m, TRUE); ret = 0; diff --git a/src/modules/module-esound-compat-spawnpid.c b/src/modules/module-esound-compat-spawnpid.c index 67f0a231..f75335d5 100644 --- a/src/modules/module-esound-compat-spawnpid.c +++ b/src/modules/module-esound-compat-spawnpid.c @@ -65,7 +65,7 @@ int pa__init(pa_module*m) { if (kill(pid, SIGUSR1) < 0) pa_log_warn("kill(%u) failed: %s", pid, pa_cstrerror(errno)); - pa_module_unload_request(m); + pa_module_unload_request(m, TRUE); ret = 0; diff --git a/src/modules/module-esound-sink.c b/src/modules/module-esound-sink.c index 6ca64978..f748808e 100644 --- a/src/modules/module-esound-sink.c +++ b/src/modules/module-esound-sink.c @@ -479,7 +479,7 @@ static void io_callback(PA_GCC_UNUSED pa_iochannel *io, void*userdata) { u->io = NULL; } - pa_module_unload_request(u->module); + pa_module_unload_request(u->module, TRUE); } } @@ -491,7 +491,7 @@ static void on_connection(PA_GCC_UNUSED pa_socket_client *c, pa_iochannel*io, vo if (!io) { pa_log("Connection failed: %s", pa_cstrerror(errno)); - pa_module_unload_request(u->module); + pa_module_unload_request(u->module, TRUE); return; } diff --git a/src/modules/module-hal-detect.c b/src/modules/module-hal-detect.c index bfabd91a..caa7a1fa 100644 --- a/src/modules/module-hal-detect.c +++ b/src/modules/module-hal-detect.c @@ -511,7 +511,7 @@ static void device_removed_cb(LibHalContext* context, const char *udi) { pa_log_debug("Device removed: %s", udi); if ((d = pa_hashmap_remove(u->devices, udi))) { - pa_module_unload_by_index(u->core, d->index); + pa_module_unload_by_index(u->core, d->index, TRUE); hal_device_free(d); } } diff --git a/src/modules/module-ladspa-sink.c b/src/modules/module-ladspa-sink.c index eae80086..23eeb340 100644 --- a/src/modules/module-ladspa-sink.c +++ b/src/modules/module-ladspa-sink.c @@ -340,7 +340,7 @@ static void sink_input_kill_cb(pa_sink_input *i) { pa_sink_input_unref(u->sink_input); u->sink_input = NULL; - pa_module_unload_request(u->module); + pa_module_unload_request(u->module, TRUE); } /* Called from IO thread context */ diff --git a/src/modules/module-lirc.c b/src/modules/module-lirc.c index 0570a6a1..f34f7be3 100644 --- a/src/modules/module-lirc.c +++ b/src/modules/module-lirc.c @@ -178,7 +178,7 @@ fail: u->module->core->mainloop->io_free(u->io); u->io = NULL; - pa_module_unload_request(u->module); + pa_module_unload_request(u->module, TRUE); pa_xfree(code); } diff --git a/src/modules/module-mmkbd-evdev.c b/src/modules/module-mmkbd-evdev.c index 4388e49c..7da77c0d 100644 --- a/src/modules/module-mmkbd-evdev.c +++ b/src/modules/module-mmkbd-evdev.c @@ -159,7 +159,7 @@ fail: u->module->core->mainloop->io_free(u->io); u->io = NULL; - pa_module_unload_request(u->module); + pa_module_unload_request(u->module, TRUE); } #define test_bit(bit, array) (array[bit/8] & (1<<(bit%8))) diff --git a/src/modules/module-remap-sink.c b/src/modules/module-remap-sink.c index bd86f4d6..5b2be118 100644 --- a/src/modules/module-remap-sink.c +++ b/src/modules/module-remap-sink.c @@ -255,7 +255,7 @@ static void sink_input_kill_cb(pa_sink_input *i) { pa_sink_input_unref(u->sink_input); u->sink_input = NULL; - pa_module_unload_request(u->module); + pa_module_unload_request(u->module, TRUE); } /* Called from IO thread context */ diff --git a/src/modules/module-sine.c b/src/modules/module-sine.c index 38780f24..a6324526 100644 --- a/src/modules/module-sine.c +++ b/src/modules/module-sine.c @@ -99,7 +99,7 @@ static void sink_input_kill_cb(pa_sink_input *i) { pa_sink_input_unref(u->sink_input); u->sink_input = NULL; - pa_module_unload_request(u->module); + pa_module_unload_request(u->module, TRUE); } /* Called from IO thread context */ diff --git a/src/modules/module-tunnel.c b/src/modules/module-tunnel.c index af27ce74..79ce1dd2 100644 --- a/src/modules/module-tunnel.c +++ b/src/modules/module-tunnel.c @@ -231,7 +231,7 @@ static void command_stream_killed(pa_pdispatch *pd, uint32_t command, uint32_t pa_assert(u->pdispatch == pd); pa_log_warn("Stream killed"); - pa_module_unload_request(u->module); + pa_module_unload_request(u->module, TRUE); } /* Called from main context */ @@ -262,7 +262,7 @@ static void command_suspended(pa_pdispatch *pd, uint32_t command, uint32_t tag pa_tagstruct_get_boolean(t, &suspended) < 0 || !pa_tagstruct_eof(t)) { pa_log("Invalid packet"); - pa_module_unload_request(u->module); + pa_module_unload_request(u->module, TRUE); return; } @@ -652,7 +652,7 @@ static void command_request(pa_pdispatch *pd, uint32_t command, uint32_t tag, p return; fail: - pa_module_unload_request(u->module); + pa_module_unload_request(u->module, TRUE); } #endif @@ -765,7 +765,7 @@ static void stream_get_latency_callback(pa_pdispatch *pd, uint32_t command, uint fail: - pa_module_unload_request(u->module); + pa_module_unload_request(u->module, TRUE); } /* Called from main context */ @@ -902,7 +902,7 @@ static void server_info_cb(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa return; fail: - pa_module_unload_request(u->module); + pa_module_unload_request(u->module, TRUE); } #ifdef TUNNEL_SINK @@ -979,7 +979,7 @@ static void sink_info_cb(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_t return; fail: - pa_module_unload_request(u->module); + pa_module_unload_request(u->module, TRUE); pa_proplist_free(pl); } @@ -1066,7 +1066,7 @@ static void sink_input_info_cb(pa_pdispatch *pd, uint32_t command, uint32_t tag return; fail: - pa_module_unload_request(u->module); + pa_module_unload_request(u->module, TRUE); pa_proplist_free(pl); } @@ -1142,7 +1142,7 @@ static void source_info_cb(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa return; fail: - pa_module_unload_request(u->module); + pa_module_unload_request(u->module, TRUE); pa_proplist_free(pl); } @@ -1204,7 +1204,7 @@ static void command_subscribe_event(pa_pdispatch *pd, uint32_t command, uint32 if (pa_tagstruct_getu32(t, &e) < 0 || pa_tagstruct_getu32(t, &idx) < 0) { pa_log("Invalid protocol reply"); - pa_module_unload_request(u->module); + pa_module_unload_request(u->module, TRUE); return; } @@ -1344,7 +1344,7 @@ parse_error: pa_log("Invalid reply. (Create stream)"); fail: - pa_module_unload_request(u->module); + pa_module_unload_request(u->module, TRUE); } @@ -1502,7 +1502,7 @@ static void setup_complete_callback(pa_pdispatch *pd, uint32_t command, uint32_t return; fail: - pa_module_unload_request(u->module); + pa_module_unload_request(u->module, TRUE); } /* Called from main context */ @@ -1513,7 +1513,7 @@ static void pstream_die_callback(pa_pstream *p, void *userdata) { pa_assert(u); pa_log_warn("Stream died."); - pa_module_unload_request(u->module); + pa_module_unload_request(u->module, TRUE); } /* Called from main context */ @@ -1526,7 +1526,7 @@ static void pstream_packet_callback(pa_pstream *p, pa_packet *packet, const pa_c if (pa_pdispatch_run(u->pdispatch, packet, creds, u) < 0) { pa_log("Invalid packet"); - pa_module_unload_request(u->module); + pa_module_unload_request(u->module, TRUE); return; } } @@ -1542,7 +1542,7 @@ static void pstream_memblock_callback(pa_pstream *p, uint32_t channel, int64_t o if (channel != u->channel) { pa_log("Recieved memory block on bad channel."); - pa_module_unload_request(u->module); + pa_module_unload_request(u->module, TRUE); return; } @@ -1568,7 +1568,7 @@ static void on_connection(pa_socket_client *sc, pa_iochannel *io, void *userdata if (!io) { pa_log("Connection failed: %s", pa_cstrerror(errno)); - pa_module_unload_request(u->module); + pa_module_unload_request(u->module, TRUE); return; } diff --git a/src/modules/module-x11-bell.c b/src/modules/module-x11-bell.c index f7be48f7..ae16b9ae 100644 --- a/src/modules/module-x11-bell.c +++ b/src/modules/module-x11-bell.c @@ -106,7 +106,7 @@ static void x11_kill_cb(pa_x11_wrapper *w, void *userdata) { u->x11_client = NULL; u->x11_wrapper = NULL; - pa_module_unload_request(u->module); + pa_module_unload_request(u->module, TRUE); } int pa__init(pa_module*m) { diff --git a/src/modules/module-x11-publish.c b/src/modules/module-x11-publish.c index 1dbc939d..c6c5bacd 100644 --- a/src/modules/module-x11-publish.c +++ b/src/modules/module-x11-publish.c @@ -126,7 +126,7 @@ static void x11_kill_cb(pa_x11_wrapper *w, void *userdata) { u->x11_client = NULL; u->x11_wrapper = NULL; - pa_module_unload_request(u->module); + pa_module_unload_request(u->module, TRUE); } int pa__init(pa_module*m) { diff --git a/src/modules/module-x11-xsmp.c b/src/modules/module-x11-xsmp.c index 0b2e375a..12e100b7 100644 --- a/src/modules/module-x11-xsmp.c +++ b/src/modules/module-x11-xsmp.c @@ -77,7 +77,7 @@ static void die_cb(SmcConn connection, SmPointer client_data){ pa_x11_wrapper_unref(u->x11); u->x11 = NULL; - pa_module_unload_request(u->module); + pa_module_unload_request(u->module, TRUE); } static void save_complete_cb(SmcConn connection, SmPointer client_data) { diff --git a/src/modules/module-zeroconf-discover.c b/src/modules/module-zeroconf-discover.c index 2fc81370..a4fbf020 100644 --- a/src/modules/module-zeroconf-discover.c +++ b/src/modules/module-zeroconf-discover.c @@ -286,7 +286,7 @@ static void browser_cb( struct tunnel *t2; if ((t2 = pa_hashmap_get(u->tunnels, t))) { - pa_module_unload_by_index(u->core, t2->module_index); + pa_module_unload_by_index(u->core, t2->module_index, TRUE); pa_hashmap_remove(u->tunnels, t2); tunnel_free(t2); } @@ -319,7 +319,7 @@ static void client_callback(AvahiClient *c, AvahiClientState state, void *userda browser_cb, u))) { pa_log("avahi_service_browser_new() failed: %s", avahi_strerror(avahi_client_errno(c))); - pa_module_unload_request(u->module); + pa_module_unload_request(u->module, TRUE); } } @@ -334,7 +334,7 @@ static void client_callback(AvahiClient *c, AvahiClientState state, void *userda browser_cb, u))) { pa_log("avahi_service_browser_new() failed: %s", avahi_strerror(avahi_client_errno(c))); - pa_module_unload_request(u->module); + pa_module_unload_request(u->module, TRUE); } } @@ -348,7 +348,7 @@ static void client_callback(AvahiClient *c, AvahiClientState state, void *userda if (!(u->client = avahi_client_new(u->avahi_poll, AVAHI_CLIENT_NO_FAIL, client_callback, u, &error))) { pa_log("avahi_client_new() failed: %s", avahi_strerror(error)); - pa_module_unload_request(u->module); + pa_module_unload_request(u->module, TRUE); } } @@ -427,7 +427,7 @@ void pa__done(pa_module*m) { struct tunnel *t; while ((t = pa_hashmap_steal_first(u->tunnels))) { - pa_module_unload_by_index(u->core, t->module_index); + pa_module_unload_by_index(u->core, t->module_index, TRUE); tunnel_free(t); } diff --git a/src/modules/module-zeroconf-publish.c b/src/modules/module-zeroconf-publish.c index 78929179..985564f4 100644 --- a/src/modules/module-zeroconf-publish.c +++ b/src/modules/module-zeroconf-publish.c @@ -539,7 +539,7 @@ static void client_callback(AvahiClient *c, AvahiClientState state, void *userda if (!(u->client = avahi_client_new(u->avahi_poll, AVAHI_CLIENT_NO_FAIL, client_callback, u, &error))) { pa_log("avahi_client_new() failed: %s", avahi_strerror(error)); - pa_module_unload_request(u->module); + pa_module_unload_request(u->module, TRUE); } } diff --git a/src/modules/rtp/module-rtp-send.c b/src/modules/rtp/module-rtp-send.c index d0d06c4d..5e542253 100644 --- a/src/modules/rtp/module-rtp-send.c +++ b/src/modules/rtp/module-rtp-send.c @@ -139,7 +139,7 @@ static void source_output_kill(pa_source_output* o) { pa_source_output_assert_ref(o); pa_assert_se(u = o->userdata); - pa_module_unload_request(u->module); + pa_module_unload_request(u->module, TRUE); pa_source_output_unlink(u->source_output); pa_source_output_unref(u->source_output); -- cgit From 756fac8d0433d02819d3910238ebf1b7a33a3046 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 6 Aug 2008 19:39:12 +0200 Subject: add new switch --disallow-exit --- src/modules/module-cli.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/modules') diff --git a/src/modules/module-cli.c b/src/modules/module-cli.c index 7a58877a..439aa8b0 100644 --- a/src/modules/module-cli.c +++ b/src/modules/module-cli.c @@ -62,7 +62,7 @@ static void eof_and_exit_cb(pa_cli*c, void *userdata) { pa_assert(c); pa_assert(m); - m->core->mainloop->quit(m->core->mainloop, 0); + pa_core_exit(m->core, FALSE, 0); } int pa__init(pa_module*m) { -- cgit From b983c0bd14150b7e6d9c57a8ddd9a43cfd8d13bb Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 6 Aug 2008 21:35:32 +0200 Subject: include host name in default sink/default source file --- src/modules/module-default-device-restore.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'src/modules') diff --git a/src/modules/module-default-device-restore.c b/src/modules/module-default-device-restore.c index 7f21efa0..4037881f 100644 --- a/src/modules/module-default-device-restore.c +++ b/src/modules/module-default-device-restore.c @@ -27,6 +27,7 @@ #include #include +#include #include #include @@ -41,8 +42,6 @@ PA_MODULE_DESCRIPTION("Automatically restore the default sink and source"); PA_MODULE_VERSION(PACKAGE_VERSION); PA_MODULE_LOAD_ONCE(TRUE); -#define DEFAULT_SINK_FILE "default-sink" -#define DEFAULT_SOURCE_FILE "default-source" #define DEFAULT_SAVE_INTERVAL 5 struct userdata { @@ -155,16 +154,28 @@ static void subscribe_cb(pa_core *c, pa_subscription_event_type_t t, uint32_t id int pa__init(pa_module *m) { struct userdata *u; + char hn[256], *fn; pa_assert(m); m->userdata = u = pa_xnew0(struct userdata, 1); u->core = m->core; - if (!(u->sink_filename = pa_state_path(DEFAULT_SINK_FILE))) + if (!pa_get_host_name(hn, sizeof(hn))) goto fail; - if (!(u->source_filename = pa_state_path(DEFAULT_SOURCE_FILE))) + fn = pa_sprintf_malloc("default-sink.%s", hn); + u->sink_filename = pa_state_path(fn); + pa_xfree(fn); + + if (!u->sink_filename) + goto fail; + + fn = pa_sprintf_malloc("default-source.%s", hn); + u->source_filename = pa_state_path(fn); + pa_xfree(fn); + + if (!u->source_filename) goto fail; load(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-default-device-restore.c | 16 ++-------------- src/modules/module-device-restore.c | 10 +++++----- src/modules/module-stream-restore.c | 10 +++++----- src/modules/module-volume-restore.c | 2 +- 4 files changed, 13 insertions(+), 25 deletions(-) (limited to 'src/modules') diff --git a/src/modules/module-default-device-restore.c b/src/modules/module-default-device-restore.c index 4037881f..d2cc24f3 100644 --- a/src/modules/module-default-device-restore.c +++ b/src/modules/module-default-device-restore.c @@ -154,28 +154,16 @@ static void subscribe_cb(pa_core *c, pa_subscription_event_type_t t, uint32_t id int pa__init(pa_module *m) { struct userdata *u; - char hn[256], *fn; pa_assert(m); m->userdata = u = pa_xnew0(struct userdata, 1); u->core = m->core; - if (!pa_get_host_name(hn, sizeof(hn))) + if (!(u->sink_filename = pa_state_path("default-sink", TRUE))) goto fail; - fn = pa_sprintf_malloc("default-sink.%s", hn); - u->sink_filename = pa_state_path(fn); - pa_xfree(fn); - - if (!u->sink_filename) - goto fail; - - fn = pa_sprintf_malloc("default-source.%s", hn); - u->source_filename = pa_state_path(fn); - pa_xfree(fn); - - if (!u->source_filename) + if (!(u->source_filename = pa_state_path("default-source", TRUE))) goto fail; load(u); 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) diff --git a/src/modules/module-stream-restore.c b/src/modules/module-stream-restore.c index b6d7b0f3..ec4e7c79 100644 --- a/src/modules/module-stream-restore.c +++ b/src/modules/module-stream-restore.c @@ -666,7 +666,6 @@ int pa__init(pa_module*m) { pa_modargs *ma = NULL; struct userdata *u; char *fname, *fn; - char hn[256]; pa_sink_input *si; pa_source_output *so; uint32_t idx; @@ -714,11 +713,12 @@ int pa__init(pa_module*m) { if (restore_volume || restore_muted) u->sink_input_fixate_hook_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SINK_INPUT_FIXATE], PA_HOOK_EARLY, (pa_hook_cb_t) sink_input_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("stream-volumes.%s."CANONICAL_HOST".gdbm", hn); - fname = pa_state_path(fn); + fn = pa_sprintf_malloc("stream-volumes."CANONICAL_HOST".gdbm"); + fname = pa_state_path(fn, TRUE); pa_xfree(fn); if (!fname) diff --git a/src/modules/module-volume-restore.c b/src/modules/module-volume-restore.c index d862c203..0fb17a0d 100644 --- a/src/modules/module-volume-restore.c +++ b/src/modules/module-volume-restore.c @@ -493,7 +493,7 @@ int pa__init(pa_module*m) { m->userdata = u; - if (!(u->table_file = pa_state_path(pa_modargs_get_value(ma, "table", DEFAULT_VOLUME_TABLE_FILE)))) + if (!(u->table_file = pa_state_path(pa_modargs_get_value(ma, "table", DEFAULT_VOLUME_TABLE_FILE), TRUE))) goto fail; if (pa_modargs_get_value_boolean(ma, "restore_device", &restore_device) < 0 || -- cgit From 432b4e5f7d9ea722d13bbe4c117a4f9b78091e4f Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Sat, 9 Aug 2008 16:20:29 +0200 Subject: don't use PA_GCC_UNUSED anymore --- src/modules/alsa-util.c | 4 ++-- src/modules/dbus-util.c | 2 +- src/modules/module-esound-sink.c | 4 ++-- src/modules/module-hal-detect.c | 2 +- src/modules/module-lirc.c | 2 +- src/modules/module-mmkbd-evdev.c | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) (limited to 'src/modules') diff --git a/src/modules/alsa-util.c b/src/modules/alsa-util.c index 8abf834d..c987315e 100644 --- a/src/modules/alsa-util.c +++ b/src/modules/alsa-util.c @@ -56,7 +56,7 @@ struct pa_alsa_fdlist { void *userdata; }; -static void io_cb(pa_mainloop_api*a, pa_io_event* e, PA_GCC_UNUSED int fd, pa_io_event_flags_t events, void *userdata) { +static void io_cb(pa_mainloop_api*a, pa_io_event* e, int fd, pa_io_event_flags_t events, void *userdata) { struct pa_alsa_fdlist *fdl = userdata; int err, i; @@ -102,7 +102,7 @@ static void io_cb(pa_mainloop_api*a, pa_io_event* e, PA_GCC_UNUSED int fd, pa_io snd_mixer_handle_events(fdl->mixer); } -static void defer_cb(pa_mainloop_api*a, PA_GCC_UNUSED pa_defer_event* e, void *userdata) { +static void defer_cb(pa_mainloop_api*a, pa_defer_event* e, void *userdata) { struct pa_alsa_fdlist *fdl = userdata; int num_fds, i, err; struct pollfd *temp; diff --git a/src/modules/dbus-util.c b/src/modules/dbus-util.c index 8e0066bc..c9c32a15 100644 --- a/src/modules/dbus-util.c +++ b/src/modules/dbus-util.c @@ -90,7 +90,7 @@ static pa_io_event_flags_t get_watch_flags(DBusWatch *watch) { } /* pa_io_event_cb_t IO event handler */ -static void handle_io_event(PA_GCC_UNUSED pa_mainloop_api *ea, pa_io_event *e, int fd, pa_io_event_flags_t events, void *userdata) { +static void handle_io_event(pa_mainloop_api *ea, pa_io_event *e, int fd, pa_io_event_flags_t events, void *userdata) { unsigned int flags = 0; DBusWatch *watch = userdata; diff --git a/src/modules/module-esound-sink.c b/src/modules/module-esound-sink.c index f748808e..e0c07d56 100644 --- a/src/modules/module-esound-sink.c +++ b/src/modules/module-esound-sink.c @@ -468,7 +468,7 @@ static int do_read(struct userdata *u) { return 0; } -static void io_callback(PA_GCC_UNUSED pa_iochannel *io, void*userdata) { +static void io_callback(pa_iochannel *io, void*userdata) { struct userdata *u = userdata; pa_assert(u); @@ -483,7 +483,7 @@ static void io_callback(PA_GCC_UNUSED pa_iochannel *io, void*userdata) { } } -static void on_connection(PA_GCC_UNUSED pa_socket_client *c, pa_iochannel*io, void *userdata) { +static void on_connection(pa_socket_client *c, pa_iochannel*io, void *userdata) { struct userdata *u = userdata; pa_socket_client_unref(u->client); diff --git a/src/modules/module-hal-detect.c b/src/modules/module-hal-detect.c index caa7a1fa..ce766258 100644 --- a/src/modules/module-hal-detect.c +++ b/src/modules/module-hal-detect.c @@ -108,7 +108,7 @@ static void hal_device_free(struct device* d) { pa_xfree(d); } -static void hal_device_free_cb(void *d, PA_GCC_UNUSED void *data) { +static void hal_device_free_cb(void *d, void *data) { hal_device_free(d); } diff --git a/src/modules/module-lirc.c b/src/modules/module-lirc.c index f34f7be3..4fd05434 100644 --- a/src/modules/module-lirc.c +++ b/src/modules/module-lirc.c @@ -65,7 +65,7 @@ struct userdata { static int lirc_in_use = 0; -static void io_callback(pa_mainloop_api *io, PA_GCC_UNUSED pa_io_event *e, PA_GCC_UNUSED int fd, pa_io_event_flags_t events, void*userdata) { +static void io_callback(pa_mainloop_api *io, pa_io_event *e, int fd, pa_io_event_flags_t events, void*userdata) { struct userdata *u = userdata; char *name = NULL, *code = NULL; diff --git a/src/modules/module-mmkbd-evdev.c b/src/modules/module-mmkbd-evdev.c index 7da77c0d..3f012b7f 100644 --- a/src/modules/module-mmkbd-evdev.c +++ b/src/modules/module-mmkbd-evdev.c @@ -76,7 +76,7 @@ struct userdata { pa_module *module; }; -static void io_callback(pa_mainloop_api *io, PA_GCC_UNUSED pa_io_event *e, PA_GCC_UNUSED int fd, pa_io_event_flags_t events, void*userdata) { +static void io_callback(pa_mainloop_api *io, pa_io_event *e, int fd, pa_io_event_flags_t events, void*userdata) { struct userdata *u = userdata; pa_assert(io); -- cgit From 72f520f93c576facf8a49af28b764e1be8ee4ad5 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Sat, 9 Aug 2008 17:04:27 +0200 Subject: make gcc shut up --- src/modules/module-stream-restore.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/modules') diff --git a/src/modules/module-stream-restore.c b/src/modules/module-stream-restore.c index ec4e7c79..b999304a 100644 --- a/src/modules/module-stream-restore.c +++ b/src/modules/module-stream-restore.c @@ -490,7 +490,7 @@ static void dump_database(struct userdata *u) { static int extension_cb(pa_native_protocol *p, pa_module *m, pa_native_connection *c, uint32_t tag, pa_tagstruct *t) { struct userdata *u; uint32_t command; - pa_tagstruct *reply; + pa_tagstruct *reply = NULL; pa_assert(p); pa_assert(m); -- cgit From 8ca254c49065cb49fcc6225f1270752f61ba8b17 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 11 Aug 2008 19:46:11 +0200 Subject: fix two uninitialized memory accesses --- src/modules/module-alsa-sink.c | 6 +++--- src/modules/module-alsa-source.c | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'src/modules') diff --git a/src/modules/module-alsa-sink.c b/src/modules/module-alsa-sink.c index aad6801e..cba959f4 100644 --- a/src/modules/module-alsa-sink.c +++ b/src/modules/module-alsa-sink.c @@ -239,7 +239,7 @@ static size_t check_left_to_play(struct userdata *u, snd_pcm_sframes_t n) { static int mmap_write(struct userdata *u, pa_usec_t *sleep_usec) { int work_done = 0; - pa_usec_t max_sleep_usec, process_usec; + pa_usec_t max_sleep_usec = 0, process_usec = 0; size_t left_to_play; pa_assert(u); @@ -354,7 +354,7 @@ static int mmap_write(struct userdata *u, pa_usec_t *sleep_usec) { static int unix_write(struct userdata *u, pa_usec_t *sleep_usec) { int work_done = 0; - pa_usec_t max_sleep_usec, process_usec; + pa_usec_t max_sleep_usec = 0, process_usec = 0; size_t left_to_play; pa_assert(u); @@ -974,7 +974,7 @@ static void thread_func(void *userdata) { /* Render some data and write it to the dsp */ if (PA_SINK_IS_OPENED(u->sink->thread_info.state)) { int work_done; - pa_usec_t sleep_usec; + pa_usec_t sleep_usec = 0; if (u->sink->thread_info.rewind_requested) if (process_rewind(u) < 0) diff --git a/src/modules/module-alsa-source.c b/src/modules/module-alsa-source.c index 1cc467d9..f1b6622a 100644 --- a/src/modules/module-alsa-source.c +++ b/src/modules/module-alsa-source.c @@ -234,7 +234,7 @@ static size_t check_left_to_record(struct userdata *u, snd_pcm_sframes_t n) { static int mmap_read(struct userdata *u, pa_usec_t *sleep_usec) { int work_done = 0; - pa_usec_t max_sleep_usec, process_usec; + pa_usec_t max_sleep_usec = 0, process_usec = 0; size_t left_to_record; pa_assert(u); @@ -331,7 +331,7 @@ static int mmap_read(struct userdata *u, pa_usec_t *sleep_usec) { static int unix_read(struct userdata *u, pa_usec_t *sleep_usec) { int work_done = 0; - pa_usec_t max_sleep_usec, process_usec; + pa_usec_t max_sleep_usec = 0, process_usec = 0; size_t left_to_record; pa_assert(u); @@ -837,7 +837,7 @@ static void thread_func(void *userdata) { /* Read some data and pass it to the sources */ if (PA_SOURCE_IS_OPENED(u->source->thread_info.state)) { int work_done = 0; - pa_usec_t sleep_usec; + pa_usec_t sleep_usec = 0; if (u->use_mmap) work_done = mmap_read(u, &sleep_usec); -- cgit From 3c88af711eee69d6bfda4268e0492278bcb59a02 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 13 Aug 2008 13:51:13 +0200 Subject: fix protocol destruction --- src/modules/module-protocol-stub.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'src/modules') diff --git a/src/modules/module-protocol-stub.c b/src/modules/module-protocol-stub.c index 8136c6fc..4fe439f9 100644 --- a/src/modules/module-protocol-stub.c +++ b/src/modules/module-protocol-stub.c @@ -260,7 +260,7 @@ int pa__init(pa_module*m) { goto fail; } - u = pa_xnew0(struct userdata, 1); + m->userdata = u = pa_xnew0(struct userdata, 1); u->module = m; #if defined(USE_PROTOCOL_SIMPLE) @@ -368,8 +368,6 @@ int pa__init(pa_module*m) { # endif #endif - m->userdata = u; - if (ma) pa_modargs_free(ma); @@ -390,7 +388,8 @@ void pa__done(pa_module*m) { pa_assert(m); - u = m->userdata; + if (!(u = m->userdata)) + return; #if defined(USE_PROTOCOL_SIMPLE) if (u->simple_protocol) { -- cgit From 8ab85fdf9e8d5465ae29434f6618b63c3511b767 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 13 Aug 2008 13:53:31 +0200 Subject: reword some log messages --- src/modules/alsa-util.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/modules') diff --git a/src/modules/alsa-util.c b/src/modules/alsa-util.c index c987315e..2dcf6d9c 100644 --- a/src/modules/alsa-util.c +++ b/src/modules/alsa-util.c @@ -808,7 +808,7 @@ int pa_alsa_calc_mixer_map(snd_mixer_elem_t *elem, const pa_channel_map *channel if (channel_map->channels > 1 && ((playback && snd_mixer_selem_has_playback_volume_joined(elem)) || (!playback && snd_mixer_selem_has_capture_volume_joined(elem)))) { - pa_log_info("ALSA device lacks independant volume controls for each channel, falling back to software volume control."); + pa_log_info("ALSA device lacks independant volume controls for each channel."); return -1; } @@ -820,7 +820,7 @@ int pa_alsa_calc_mixer_map(snd_mixer_elem_t *elem, const pa_channel_map *channel id = alsa_channel_ids[channel_map->map[i]]; if (!is_mono && id == SND_MIXER_SCHN_UNKNOWN) { - pa_log_info("Configured channel map contains channel '%s' that is unknown to the ALSA mixer. Falling back to software volume control.", pa_channel_position_to_string(channel_map->map[i])); + pa_log_info("Configured channel map contains channel '%s' that is unknown to the ALSA mixer.", pa_channel_position_to_string(channel_map->map[i])); return -1; } @@ -832,7 +832,7 @@ int pa_alsa_calc_mixer_map(snd_mixer_elem_t *elem, const pa_channel_map *channel if ((playback && (!snd_mixer_selem_has_playback_channel(elem, id) || (is_mono && !snd_mixer_selem_is_playback_mono(elem)))) || (!playback && (!snd_mixer_selem_has_capture_channel(elem, id) || (is_mono && !snd_mixer_selem_is_capture_mono(elem))))) { - pa_log_info("ALSA device lacks separate volumes control for channel '%s', falling back to software volume control.", pa_channel_position_to_string(channel_map->map[i])); + pa_log_info("ALSA device lacks separate volumes control for channel '%s'", pa_channel_position_to_string(channel_map->map[i])); return -1; } -- cgit From 29daef7a265db1977db4eb2eb68dd85c943fceef Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 13 Aug 2008 13:54:17 +0200 Subject: add new function pa_alsa_volume_divide() --- src/modules/alsa-util.c | 24 ++++++++++++++++++++++++ src/modules/alsa-util.h | 3 +++ 2 files changed, 27 insertions(+) (limited to 'src/modules') diff --git a/src/modules/alsa-util.c b/src/modules/alsa-util.c index 2dcf6d9c..be3cdf44 100644 --- a/src/modules/alsa-util.c +++ b/src/modules/alsa-util.c @@ -1117,3 +1117,27 @@ pa_rtpoll_item* pa_alsa_build_pollfd(snd_pcm_t *pcm, pa_rtpoll *rtpoll) { return item; } + +pa_cvolume *pa_alsa_volume_divide(pa_cvolume *r, const pa_cvolume *t) { + unsigned i; + + pa_assert(r); + pa_assert(t); + pa_assert(r->channels == t->channels); + + for (i = 0; i < r->channels; i++) { + double a, b, c; + + a = pa_sw_volume_to_linear(r->values[i]); /* the hw volume */ + b = pa_sw_volume_to_linear(t->values[i]); /* the intended volume */ + + if (a <= 0) + c = 0; + else + c = b / a; + + r->values[i] = pa_sw_volume_from_linear(c); + } + + return r; +} diff --git a/src/modules/alsa-util.h b/src/modules/alsa-util.h index 4de8bcd2..1b73200b 100644 --- a/src/modules/alsa-util.h +++ b/src/modules/alsa-util.h @@ -26,6 +26,7 @@ #include #include +#include #include #include #include @@ -94,4 +95,6 @@ int pa_alsa_recover_from_poll(snd_pcm_t *pcm, int revents); pa_rtpoll_item* pa_alsa_build_pollfd(snd_pcm_t *pcm, pa_rtpoll *rtpoll); +pa_cvolume *pa_alsa_volume_divide(pa_cvolume *r, const pa_cvolume *t); + #endif -- cgit From 8a10eba744c42cb5db4e6446c2f77b6cbc5eb028 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 13 Aug 2008 13:59:06 +0200 Subject: extend hardware dB scale in software to full range if necessary, instead of reverting back to software-only volume control --- src/modules/module-alsa-sink.c | 247 +++++++++++++++++++++++---------------- src/modules/module-alsa-source.c | 239 ++++++++++++++++++++++--------------- 2 files changed, 295 insertions(+), 191 deletions(-) (limited to 'src/modules') diff --git a/src/modules/module-alsa-sink.c b/src/modules/module-alsa-sink.c index cba959f4..255896c2 100644 --- a/src/modules/module-alsa-sink.c +++ b/src/modules/module-alsa-sink.c @@ -68,8 +68,7 @@ PA_MODULE_USAGE( "mmap= " "tsched= " "tsched_buffer_size= " - "tsched_buffer_watermark= " - "mixer_reset="); + "tsched_buffer_watermark="); static const char* const valid_modargs[] = { "sink_name", @@ -85,7 +84,6 @@ static const char* const valid_modargs[] = { "tsched", "tsched_buffer_size", "tsched_buffer_watermark", - "mixer_reset", NULL }; @@ -112,6 +110,8 @@ struct userdata { long hw_volume_max, hw_volume_min; long hw_dB_max, hw_dB_min; pa_bool_t hw_dB_supported; + pa_bool_t mixer_seperate_channels; + pa_cvolume hardware_volume; size_t frame_size, fragment_size, hwbuf_size, tsched_watermark; unsigned nfragments; @@ -737,8 +737,8 @@ static int mixer_callback(snd_mixer_elem_t *elem, unsigned int mask) { return 0; if (mask & SND_CTL_EVENT_MASK_VALUE) { - pa_sink_get_volume(u->sink); - pa_sink_get_mute(u->sink); + pa_sink_get_volume(u->sink, TRUE); + pa_sink_get_mute(u->sink, TRUE); } return 0; @@ -747,30 +747,60 @@ static int mixer_callback(snd_mixer_elem_t *elem, unsigned int mask) { static int sink_get_volume_cb(pa_sink *s) { struct userdata *u = s->userdata; int err; - int i; + unsigned i; + pa_cvolume r; + char t[PA_CVOLUME_SNPRINT_MAX]; pa_assert(u); pa_assert(u->mixer_elem); - for (i = 0; i < s->sample_spec.channels; i++) { - long alsa_vol; + if (u->mixer_seperate_channels) { - pa_assert(snd_mixer_selem_has_playback_channel(u->mixer_elem, u->mixer_map[i])); + r.channels = s->sample_spec.channels; - if (u->hw_dB_supported) { + for (i = 0; i < s->sample_spec.channels; i++) { + long alsa_vol; - if ((err = snd_mixer_selem_get_playback_dB(u->mixer_elem, u->mixer_map[i], &alsa_vol)) >= 0) { - s->volume.values[i] = pa_sw_volume_from_dB(alsa_vol / 100.0); - continue; - } + if (u->hw_dB_supported) { + + if ((err = snd_mixer_selem_get_playback_dB(u->mixer_elem, u->mixer_map[i], &alsa_vol)) < 0) + goto fail; + + r.values[i] = pa_sw_volume_from_dB((double) alsa_vol / 100.0); + } else { - u->hw_dB_supported = FALSE; + if ((err = snd_mixer_selem_get_playback_volume(u->mixer_elem, u->mixer_map[i], &alsa_vol)) < 0) + goto fail; + + r.values[i] = (pa_volume_t) round(((double) (alsa_vol - u->hw_volume_min) * PA_VOLUME_NORM) / (u->hw_volume_max - u->hw_volume_min)); + } } - if ((err = snd_mixer_selem_get_playback_volume(u->mixer_elem, u->mixer_map[i], &alsa_vol)) < 0) + } else { + long alsa_vol; + + pa_assert(u->hw_dB_supported); + + if ((err = snd_mixer_selem_get_playback_dB(u->mixer_elem, SND_MIXER_SCHN_MONO, &alsa_vol)) < 0) goto fail; - s->volume.values[i] = (pa_volume_t) roundf(((float) (alsa_vol - u->hw_volume_min) * PA_VOLUME_NORM) / (u->hw_volume_max - u->hw_volume_min)); + pa_cvolume_set(&r, s->sample_spec.channels, pa_sw_volume_from_dB((double) alsa_vol / 100.0)); + } + + pa_log_debug("Read hardware volume: %s", pa_cvolume_snprint(t, sizeof(t), &r)); + + if (!pa_cvolume_equal(&u->hardware_volume, &r)) { + + u->hardware_volume = s->volume = r; + + if (u->hw_dB_supported) { + pa_cvolume reset; + + /* Hmm, so the hardware volume changed, let's reset our software volume */ + + pa_cvolume_reset(&reset, s->sample_spec.channels); + pa_sink_set_soft_volume(s, &reset); + } } return 0; @@ -784,45 +814,90 @@ fail: static int sink_set_volume_cb(pa_sink *s) { struct userdata *u = s->userdata; int err; - int i; + unsigned i; + pa_cvolume r; pa_assert(u); pa_assert(u->mixer_elem); - for (i = 0; i < s->sample_spec.channels; i++) { - long alsa_vol; - pa_volume_t vol; + if (u->mixer_seperate_channels) { - pa_assert(snd_mixer_selem_has_playback_channel(u->mixer_elem, u->mixer_map[i])); + r.channels = s->sample_spec.channels; - vol = PA_MIN(s->volume.values[i], PA_VOLUME_NORM); + for (i = 0; i < s->sample_spec.channels; i++) { + long alsa_vol; + pa_volume_t vol; - if (u->hw_dB_supported) { - alsa_vol = (long) (pa_sw_volume_to_dB(vol) * 100); - alsa_vol = PA_CLAMP_UNLIKELY(alsa_vol, u->hw_dB_min, u->hw_dB_max); + vol = s->volume.values[i]; - if ((err = snd_mixer_selem_set_playback_dB(u->mixer_elem, u->mixer_map[i], alsa_vol, -1)) >= 0) { + if (u->hw_dB_supported) { - if (snd_mixer_selem_get_playback_dB(u->mixer_elem, u->mixer_map[i], &alsa_vol) >= 0) - s->volume.values[i] = pa_sw_volume_from_dB(alsa_vol / 100.0); + alsa_vol = (long) (pa_sw_volume_to_dB(vol) * 100); + alsa_vol = PA_CLAMP_UNLIKELY(alsa_vol, u->hw_dB_min, u->hw_dB_max); - continue; - } + if ((err = snd_mixer_selem_set_playback_dB(u->mixer_elem, u->mixer_map[i], alsa_vol, 1)) < 0) + goto fail; - u->hw_dB_supported = FALSE; + if ((err = snd_mixer_selem_get_playback_dB(u->mixer_elem, u->mixer_map[i], &alsa_vol)) < 0) + goto fail; + r.values[i] = pa_sw_volume_from_dB((double) alsa_vol / 100.0); + } else { + + alsa_vol = (long) round(((double) vol * (u->hw_volume_max - u->hw_volume_min)) / PA_VOLUME_NORM) + u->hw_volume_min; + alsa_vol = PA_CLAMP_UNLIKELY(alsa_vol, u->hw_volume_min, u->hw_volume_max); + + if ((err = snd_mixer_selem_set_playback_volume(u->mixer_elem, u->mixer_map[i], alsa_vol)) < 0) + goto fail; + + if ((err = snd_mixer_selem_get_playback_volume(u->mixer_elem, u->mixer_map[i], &alsa_vol)) < 0) + goto fail; + + r.values[i] = (pa_volume_t) round(((double) (alsa_vol - u->hw_volume_min) * PA_VOLUME_NORM) / (u->hw_volume_max - u->hw_volume_min)); + } } - alsa_vol = (long) roundf(((float) vol * (u->hw_volume_max - u->hw_volume_min)) / PA_VOLUME_NORM) + u->hw_volume_min; - alsa_vol = PA_CLAMP_UNLIKELY(alsa_vol, u->hw_volume_min, u->hw_volume_max); + } else { + pa_volume_t vol; + long alsa_vol; + + pa_assert(u->hw_dB_supported); + + vol = pa_cvolume_max(&s->volume); + + alsa_vol = (long) (pa_sw_volume_to_dB(vol) * 100); + alsa_vol = PA_CLAMP_UNLIKELY(alsa_vol, u->hw_dB_min, u->hw_dB_max); + + if ((err = snd_mixer_selem_set_playback_dB_all(u->mixer_elem, alsa_vol, 1)) < 0) + goto fail; - if ((err = snd_mixer_selem_set_playback_volume(u->mixer_elem, u->mixer_map[i], alsa_vol)) < 0) + if ((err = snd_mixer_selem_get_playback_dB(u->mixer_elem, SND_MIXER_SCHN_MONO, &alsa_vol)) < 0) goto fail; - if (snd_mixer_selem_get_playback_volume(u->mixer_elem, u->mixer_map[i], &alsa_vol) >= 0) - s->volume.values[i] = (pa_volume_t) roundf(((float) (alsa_vol - u->hw_volume_min) * PA_VOLUME_NORM) / (u->hw_volume_max - u->hw_volume_min)); + pa_cvolume_set(&r, s->volume.channels, pa_sw_volume_from_dB((double) alsa_vol / 100.0)); } + u->hardware_volume = r; + + if (u->hw_dB_supported) { + char t[PA_CVOLUME_SNPRINT_MAX]; + + /* Match exactly what the user requested by software */ + + pa_alsa_volume_divide(&r, &s->volume); + pa_sink_set_soft_volume(s, &r); + + pa_log_debug("Requested volume: %s", pa_cvolume_snprint(t, sizeof(t), &s->volume)); + pa_log_debug("Got hardware volume: %s", pa_cvolume_snprint(t, sizeof(t), &u->hardware_volume)); + pa_log_debug("Calculated software volume: %s", pa_cvolume_snprint(t, sizeof(t), &r)); + + } else + + /* We can't match exactly what the user requested, hence let's + * at least tell the user about it */ + + s->volume = r; + return 0; fail: @@ -1100,7 +1175,7 @@ int pa__init(pa_module*m) { const char *name; char *name_buf = NULL; pa_bool_t namereg_fail; - pa_bool_t use_mmap = TRUE, b, use_tsched = TRUE, d, mixer_reset = TRUE; + pa_bool_t use_mmap = TRUE, b, use_tsched = TRUE, d; pa_usec_t usec; pa_sink_new_data data; @@ -1157,11 +1232,6 @@ int pa__init(pa_module*m) { use_tsched = FALSE; } - if (pa_modargs_get_value_boolean(ma, "mixer_reset", &mixer_reset) < 0) { - pa_log("Failed to parse mixer_reset argument."); - goto fail; - } - u = pa_xnew0(struct userdata, 1); u->core = m->core; u->module = m; @@ -1322,6 +1392,8 @@ int pa__init(pa_module*m) { u->hw_dB_supported = FALSE; u->hw_dB_min = u->hw_dB_max = 0; u->hw_volume_min = u->hw_volume_max = 0; + u->mixer_seperate_channels = FALSE; + pa_cvolume_mute(&u->hardware_volume, u->sink->sample_spec.channels); if (use_tsched) fix_tsched_watermark(u); @@ -1349,76 +1421,51 @@ int pa__init(pa_module*m) { if (u->mixer_handle) { pa_assert(u->mixer_elem); - if (snd_mixer_selem_has_playback_volume(u->mixer_elem)) - - if (pa_alsa_calc_mixer_map(u->mixer_elem, &map, u->mixer_map, TRUE) >= 0 && - snd_mixer_selem_get_playback_volume_range(u->mixer_elem, &u->hw_volume_min, &u->hw_volume_max) >= 0) { - - pa_bool_t suitable = TRUE; + if (snd_mixer_selem_has_playback_volume(u->mixer_elem)) { + pa_bool_t suitable = TRUE; + if (snd_mixer_selem_get_playback_volume_range(u->mixer_elem, &u->hw_volume_min, &u->hw_volume_max) < 0) { + pa_log_info("Failed to get volume range. Falling back to software volume control."); + suitable = FALSE; + } else { pa_log_info("Volume ranges from %li to %li.", u->hw_volume_min, u->hw_volume_max); + pa_assert(u->hw_volume_min < u->hw_volume_max); + } - if (u->hw_volume_min > u->hw_volume_max) { - - pa_log_info("Minimal volume %li larger than maximum volume %li. Strange stuff Falling back to software volume control.", u->hw_volume_min, u->hw_volume_max); - suitable = FALSE; - - } else if (u->hw_volume_max - u->hw_volume_min < 3) { - - pa_log_info("Device has less than 4 volume levels. Falling back to software volume control."); - suitable = FALSE; - - } else if (snd_mixer_selem_get_playback_dB_range(u->mixer_elem, &u->hw_dB_min, &u->hw_dB_max) >= 0) { - - /* u->hw_dB_max = 0; u->hw_dB_min = -3000; Use this to make valgrind shut up */ - - pa_log_info("Volume ranges from %0.2f dB to %0.2f dB.", u->hw_dB_min/100.0, u->hw_dB_max/100.0); - - /* Let's see if this thing actually is useful for muting */ - if (u->hw_dB_min > -6000) { - pa_log_info("Device cannot attenuate for more than -60 dB (only %0.2f dB supported), falling back to software volume control.", ((double) u->hw_dB_min) / 100); - - suitable = FALSE; - } else if (u->hw_dB_max < 0) { - - pa_log_info("Device is still attenuated at maximum volume setting (%0.2f dB is maximum). Strange stuff. Falling back to software volume control.", ((double) u->hw_dB_max) / 100); - suitable = FALSE; + if (snd_mixer_selem_get_playback_dB_range(u->mixer_elem, &u->hw_dB_min, &u->hw_dB_max) < 0) + pa_log_info("Mixer doesn't support dB information."); + else { + pa_log_info("Volume ranges from %0.2f dB to %0.2f dB.", u->hw_dB_min/100.0, u->hw_dB_max/100.0); + pa_assert(u->hw_dB_min < u->hw_dB_max); + u->hw_dB_supported = TRUE; + } - } else if (u->hw_dB_min >= u->hw_dB_max) { + if (suitable && + !u->hw_dB_supported && + u->hw_volume_max - u->hw_volume_min < 3) { - pa_log_info("Minimal dB (%0.2f) larger or equal to maximum dB (%0.2f). Strange stuff. Falling back to software volume control.", ((double) u->hw_dB_min) / 100, ((double) u->hw_dB_max) / 100); - suitable = FALSE; + pa_log_info("Device doesn't do dB volume and has less than 4 volume levels. Falling back to software volume control."); + suitable = FALSE; + } - } else { + if (suitable) { + u->mixer_seperate_channels = pa_alsa_calc_mixer_map(u->mixer_elem, &map, u->mixer_map, TRUE) >= 0; - if (u->hw_dB_max > 0) { - /* dB > 0 means overamplification, and clipping, we don't want that here */ - pa_log_info("Device can do overamplification for %0.2f dB. Limiting to 0 db", ((double) u->hw_dB_max) / 100); - u->hw_dB_max = 0; - } + u->sink->get_volume = sink_get_volume_cb; + u->sink->set_volume = sink_set_volume_cb; + u->sink->flags |= PA_SINK_HW_VOLUME_CTRL | (u->hw_dB_supported ? PA_SINK_DECIBEL_VOLUME : 0); + pa_log_info("Using hardware volume control. Hardware dB scale %s.", u->hw_dB_supported ? "supported" : "not supported"); - u->hw_dB_supported = TRUE; - } - } - - if (suitable) { - u->sink->get_volume = sink_get_volume_cb; - u->sink->set_volume = sink_set_volume_cb; - u->sink->flags |= PA_SINK_HW_VOLUME_CTRL | (u->hw_dB_supported ? PA_SINK_DECIBEL_VOLUME : 0); - pa_log_info("Using hardware volume control. Hardware dB scale %s.", u->hw_dB_supported ? "supported" : "not supported"); - - } else if (mixer_reset) { - pa_log_info("Using software volume control. Trying to reset sound card to 0 dB."); - pa_alsa_0dB_playback(u->mixer_elem); - } else - pa_log_info("Using software volume control. Leaving hw mixer controls untouched."); - } + } else + pa_log_info("Using software volume control."); + } if (snd_mixer_selem_has_playback_switch(u->mixer_elem)) { u->sink->get_mute = sink_get_mute_cb; u->sink->set_mute = sink_set_mute_cb; u->sink->flags |= PA_SINK_HW_MUTE_CTRL; - } + } else + pa_log_info("Using software mute control."); u->mixer_fdl = pa_alsa_fdlist_new(); diff --git a/src/modules/module-alsa-source.c b/src/modules/module-alsa-source.c index f1b6622a..0e4efad5 100644 --- a/src/modules/module-alsa-source.c +++ b/src/modules/module-alsa-source.c @@ -69,8 +69,7 @@ PA_MODULE_USAGE( "mmap= " "tsched= " "tsched_buffer_size= " - "tsched_buffer_watermark= " - "mixer_reset="); + "tsched_buffer_watermark="); static const char* const valid_modargs[] = { "source_name", @@ -86,7 +85,6 @@ static const char* const valid_modargs[] = { "tsched", "tsched_buffer_size", "tsched_buffer_watermark", - "mixer_reset", NULL }; @@ -113,6 +111,9 @@ struct userdata { long hw_volume_max, hw_volume_min; long hw_dB_max, hw_dB_min; pa_bool_t hw_dB_supported; + pa_bool_t mixer_seperate_channels; + + pa_cvolume hardware_volume; size_t frame_size, fragment_size, hwbuf_size, tsched_watermark; unsigned nfragments; @@ -680,8 +681,8 @@ static int mixer_callback(snd_mixer_elem_t *elem, unsigned int mask) { return 0; if (mask & SND_CTL_EVENT_MASK_VALUE) { - pa_source_get_volume(u->source); - pa_source_get_mute(u->source); + pa_source_get_volume(u->source, TRUE); + pa_source_get_mute(u->source, TRUE); } return 0; @@ -690,30 +691,60 @@ static int mixer_callback(snd_mixer_elem_t *elem, unsigned int mask) { static int source_get_volume_cb(pa_source *s) { struct userdata *u = s->userdata; int err; - int i; + unsigned i; + pa_cvolume r; + char t[PA_CVOLUME_SNPRINT_MAX]; pa_assert(u); pa_assert(u->mixer_elem); - for (i = 0; i < s->sample_spec.channels; i++) { - long alsa_vol; + if (u->mixer_seperate_channels) { - pa_assert(snd_mixer_selem_has_capture_channel(u->mixer_elem, u->mixer_map[i])); + r.channels = s->sample_spec.channels; - if (u->hw_dB_supported) { + for (i = 0; i < s->sample_spec.channels; i++) { + long alsa_vol; - if ((err = snd_mixer_selem_get_capture_dB(u->mixer_elem, u->mixer_map[i], &alsa_vol)) >= 0) { - s->volume.values[i] = pa_sw_volume_from_dB(alsa_vol / 100.0); - continue; - } + if (u->hw_dB_supported) { + + if ((err = snd_mixer_selem_get_capture_dB(u->mixer_elem, u->mixer_map[i], &alsa_vol)) < 0) + goto fail; + + r.values[i] = pa_sw_volume_from_dB((double) alsa_vol / 100.0); + } else { + + if ((err = snd_mixer_selem_get_capture_volume(u->mixer_elem, u->mixer_map[i], &alsa_vol)) < 0) + goto fail; - u->hw_dB_supported = FALSE; + r.values[i] = (pa_volume_t) round(((double) (alsa_vol - u->hw_volume_min) * PA_VOLUME_NORM) / (u->hw_volume_max - u->hw_volume_min)); + } } - if ((err = snd_mixer_selem_get_capture_volume(u->mixer_elem, u->mixer_map[i], &alsa_vol)) < 0) + } else { + long alsa_vol; + + pa_assert(u->hw_dB_supported); + + if ((err = snd_mixer_selem_get_capture_dB(u->mixer_elem, SND_MIXER_SCHN_MONO, &alsa_vol)) < 0) goto fail; - s->volume.values[i] = (pa_volume_t) roundf(((float) (alsa_vol - u->hw_volume_min) * PA_VOLUME_NORM) / (u->hw_volume_max - u->hw_volume_min)); + pa_cvolume_set(&r, s->sample_spec.channels, pa_sw_volume_from_dB((double) alsa_vol / 100.0)); + } + + pa_log_debug("Read hardware volume: %s", pa_cvolume_snprint(t, sizeof(t), &r)); + + if (!pa_cvolume_equal(&u->hardware_volume, &r)) { + + u->hardware_volume = s->volume = r; + + if (u->hw_dB_supported) { + pa_cvolume reset; + + /* Hmm, so the hardware volume changed, let's reset our software volume */ + + pa_cvolume_reset(&reset, s->sample_spec.channels); + pa_source_set_soft_volume(s, &reset); + } } return 0; @@ -727,45 +758,90 @@ fail: static int source_set_volume_cb(pa_source *s) { struct userdata *u = s->userdata; int err; - int i; + unsigned i; + pa_cvolume r; pa_assert(u); pa_assert(u->mixer_elem); - for (i = 0; i < s->sample_spec.channels; i++) { - long alsa_vol; - pa_volume_t vol; + if (u->mixer_seperate_channels) { - pa_assert(snd_mixer_selem_has_capture_channel(u->mixer_elem, u->mixer_map[i])); + r.channels = s->sample_spec.channels; - vol = PA_MIN(s->volume.values[i], PA_VOLUME_NORM); + for (i = 0; i < s->sample_spec.channels; i++) { + long alsa_vol; + pa_volume_t vol; - if (u->hw_dB_supported) { - alsa_vol = (long) (pa_sw_volume_to_dB(vol) * 100); - alsa_vol = PA_CLAMP_UNLIKELY(alsa_vol, u->hw_dB_min, u->hw_dB_max); + vol = s->volume.values[i]; + if (u->hw_dB_supported) { - if ((err = snd_mixer_selem_set_capture_dB(u->mixer_elem, u->mixer_map[i], alsa_vol, -1)) >= 0) { + alsa_vol = (long) (pa_sw_volume_to_dB(vol) * 100); + alsa_vol = PA_CLAMP_UNLIKELY(alsa_vol, u->hw_dB_min, u->hw_dB_max); - if (snd_mixer_selem_get_capture_dB(u->mixer_elem, u->mixer_map[i], &alsa_vol) >= 0) - s->volume.values[i] = pa_sw_volume_from_dB(alsa_vol / 100.0); + if ((err = snd_mixer_selem_set_capture_dB(u->mixer_elem, u->mixer_map[i], alsa_vol, 1)) < 0) + goto fail; - continue; - } + if ((err = snd_mixer_selem_get_capture_dB(u->mixer_elem, u->mixer_map[i], &alsa_vol)) < 0) + goto fail; + + r.values[i] = pa_sw_volume_from_dB((double) alsa_vol / 100.0); + } else { - u->hw_dB_supported = FALSE; + alsa_vol = (long) round(((double) vol * (u->hw_volume_max - u->hw_volume_min)) / PA_VOLUME_NORM) + u->hw_volume_min; + alsa_vol = PA_CLAMP_UNLIKELY(alsa_vol, u->hw_volume_min, u->hw_volume_max); + + if ((err = snd_mixer_selem_set_capture_volume(u->mixer_elem, u->mixer_map[i], alsa_vol)) < 0) + goto fail; + + if ((err = snd_mixer_selem_get_capture_volume(u->mixer_elem, u->mixer_map[i], &alsa_vol)) < 0) + goto fail; + + r.values[i] = (pa_volume_t) round(((double) (alsa_vol - u->hw_volume_min) * PA_VOLUME_NORM) / (u->hw_volume_max - u->hw_volume_min)); + } } - alsa_vol = (long) roundf(((float) vol * (u->hw_volume_max - u->hw_volume_min)) / PA_VOLUME_NORM) + u->hw_volume_min; - alsa_vol = PA_CLAMP_UNLIKELY(alsa_vol, u->hw_volume_min, u->hw_volume_max); + } else { + pa_volume_t vol; + long alsa_vol; + + pa_assert(u->hw_dB_supported); + + vol = pa_cvolume_max(&s->volume); - if ((err = snd_mixer_selem_set_capture_volume(u->mixer_elem, u->mixer_map[i], alsa_vol)) < 0) + alsa_vol = (long) (pa_sw_volume_to_dB(vol) * 100); + alsa_vol = PA_CLAMP_UNLIKELY(alsa_vol, u->hw_dB_min, u->hw_dB_max); + + if ((err = snd_mixer_selem_set_capture_dB_all(u->mixer_elem, alsa_vol, 1)) < 0) + goto fail; + + if ((err = snd_mixer_selem_get_capture_dB(u->mixer_elem, SND_MIXER_SCHN_MONO, &alsa_vol)) < 0) goto fail; - if (snd_mixer_selem_get_capture_volume(u->mixer_elem, u->mixer_map[i], &alsa_vol) >= 0) - s->volume.values[i] = (pa_volume_t) roundf(((float) (alsa_vol - u->hw_volume_min) * PA_VOLUME_NORM) / (u->hw_volume_max - u->hw_volume_min)); + pa_cvolume_set(&r, s->volume.channels, pa_sw_volume_from_dB((double) alsa_vol / 100.0)); } + u->hardware_volume = r; + + if (u->hw_dB_supported) { + char t[PA_CVOLUME_SNPRINT_MAX]; + + /* Match exactly what the user requested by software */ + + pa_alsa_volume_divide(&r, &s->volume); + pa_source_set_soft_volume(s, &r); + + pa_log_debug("Requested volume: %s", pa_cvolume_snprint(t, sizeof(t), &s->volume)); + pa_log_debug("Got hardware volume: %s", pa_cvolume_snprint(t, sizeof(t), &u->hardware_volume)); + pa_log_debug("Calculated software volume: %s", pa_cvolume_snprint(t, sizeof(t), &r)); + + } else + + /* We can't match exactly what the user requested, hence let's + * at least tell the user about it */ + + s->volume = r; + return 0; fail: @@ -932,7 +1008,7 @@ int pa__init(pa_module*m) { const char *name; char *name_buf = NULL; pa_bool_t namereg_fail; - pa_bool_t use_mmap = TRUE, b, use_tsched = TRUE, d, mixer_reset = TRUE; + pa_bool_t use_mmap = TRUE, b, use_tsched = TRUE, d; pa_source_new_data data; snd_pcm_info_alloca(&pcm_info); @@ -988,11 +1064,6 @@ int pa__init(pa_module*m) { use_tsched = FALSE; } - if (pa_modargs_get_value_boolean(ma, "mixer_reset", &mixer_reset) < 0) { - pa_log("Failed to parse mixer_reset argument."); - goto fail; - } - u = pa_xnew0(struct userdata, 1); u->core = m->core; u->module = m; @@ -1146,6 +1217,8 @@ int pa__init(pa_module*m) { u->hw_dB_supported = FALSE; u->hw_dB_min = u->hw_dB_max = 0; u->hw_volume_min = u->hw_volume_max = 0; + u->mixer_seperate_channels = FALSE; + pa_cvolume_mute(&u->hardware_volume, u->source->sample_spec.channels); if (use_tsched) fix_tsched_watermark(u); @@ -1168,67 +1241,51 @@ int pa__init(pa_module*m) { if (u->mixer_handle) { pa_assert(u->mixer_elem); - if (snd_mixer_selem_has_capture_volume(u->mixer_elem)) - if (pa_alsa_calc_mixer_map(u->mixer_elem, &map, u->mixer_map, FALSE) >= 0 && - snd_mixer_selem_get_capture_volume_range(u->mixer_elem, &u->hw_volume_min, &u->hw_volume_max) >= 0) { - - pa_bool_t suitable = TRUE; + if (snd_mixer_selem_has_capture_volume(u->mixer_elem)) { + pa_bool_t suitable = TRUE; + if (snd_mixer_selem_get_capture_volume_range(u->mixer_elem, &u->hw_volume_min, &u->hw_volume_max) < 0) { + pa_log_info("Failed to get volume range. Falling back to software volume control."); + suitable = FALSE; + } else { pa_log_info("Volume ranges from %li to %li.", u->hw_volume_min, u->hw_volume_max); + pa_assert(u->hw_volume_min < u->hw_volume_max); + } - if (u->hw_volume_min > u->hw_volume_max) { - - pa_log_info("Minimal volume %li larger than maximum volume %li. Strange stuff Falling back to software volume control.", u->hw_volume_min, u->hw_volume_max); - suitable = FALSE; - - } else if (u->hw_volume_max - u->hw_volume_min < 3) { - - pa_log_info("Device has less than 4 volume levels. Falling back to software volume control."); - suitable = FALSE; - - } else if (snd_mixer_selem_get_capture_dB_range(u->mixer_elem, &u->hw_dB_min, &u->hw_dB_max) >= 0) { - - pa_log_info("Volume ranges from %0.2f dB to %0.2f dB.", u->hw_dB_min/100.0, u->hw_dB_max/100.0); - - /* Let's see if this thing actually is useful for muting */ - if (u->hw_dB_min > -6000) { - pa_log_info("Device cannot attenuate for more than -60 dB (only %0.2f dB supported), falling back to software volume control.", ((double) u->hw_dB_min) / 100); - - suitable = FALSE; - } else if (u->hw_dB_max < 0) { - - pa_log_info("Device is still attenuated at maximum volume setting (%0.2f dB is maximum). Strange stuff. Falling back to software volume control.", ((double) u->hw_dB_max) / 100); - suitable = FALSE; - - } else if (u->hw_dB_min >= u->hw_dB_max) { - - pa_log_info("Minimal dB (%0.2f) larger or equal to maximum dB (%0.2f). Strange stuff. Falling back to software volume control.", ((double) u->hw_dB_min) / 100, ((double) u->hw_dB_max) / 100); - suitable = FALSE; + if (snd_mixer_selem_get_capture_dB_range(u->mixer_elem, &u->hw_dB_min, &u->hw_dB_max) < 0) + pa_log_info("Mixer doesn't support dB information."); + else { + pa_log_info("Volume ranges from %0.2f dB to %0.2f dB.", u->hw_dB_min/100.0, u->hw_dB_max/100.0); + pa_assert(u->hw_dB_min < u->hw_dB_max); + u->hw_dB_supported = TRUE; + } - } else - u->hw_dB_supported = TRUE; - } + if (suitable && + !u->hw_dB_supported && + u->hw_volume_max - u->hw_volume_min < 3) { - if (suitable) { - u->source->get_volume = source_get_volume_cb; - u->source->set_volume = source_set_volume_cb; - u->source->flags |= PA_SOURCE_HW_VOLUME_CTRL | (u->hw_dB_supported ? PA_SOURCE_DECIBEL_VOLUME : 0); - pa_log_info("Using hardware volume control. Hardware dB scale %s.", u->hw_dB_supported ? "supported" : "not supported"); + pa_log_info("Device has less than 4 volume levels. Falling back to software volume control."); + suitable = FALSE; + } - } else if (mixer_reset) { - pa_log_info("Using software volume control. Trying to reset sound card to 0 dB."); - pa_alsa_0dB_capture(u->mixer_elem); - } else - pa_log_info("Using software volume control. Leaving hw mixer controls untouched."); - } + if (suitable) { + u->mixer_seperate_channels = pa_alsa_calc_mixer_map(u->mixer_elem, &map, u->mixer_map, FALSE) >= 0; + u->source->get_volume = source_get_volume_cb; + u->source->set_volume = source_set_volume_cb; + u->source->flags |= PA_SOURCE_HW_VOLUME_CTRL | (u->hw_dB_supported ? PA_SOURCE_DECIBEL_VOLUME : 0); + pa_log_info("Using hardware volume control. Hardware dB scale %s.", u->hw_dB_supported ? "supported" : "not supported"); + } else + pa_log_info("Using software volume control."); + } if (snd_mixer_selem_has_capture_switch(u->mixer_elem)) { u->source->get_mute = source_get_mute_cb; u->source->set_mute = source_set_mute_cb; u->source->flags |= PA_SOURCE_HW_MUTE_CTRL; - } + } else + pa_log_info("Using software mute control."); u->mixer_fdl = pa_alsa_fdlist_new(); -- cgit From abd85af93993b99c073e7c5dc833207a7af34946 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 13 Aug 2008 13:59:29 +0200 Subject: drop 0db reset functions since they are not necessary anymore --- src/modules/alsa-util.c | 50 ------------------------------------------------- src/modules/alsa-util.h | 3 --- 2 files changed, 53 deletions(-) (limited to 'src/modules') diff --git a/src/modules/alsa-util.c b/src/modules/alsa-util.c index be3cdf44..e3e8c85c 100644 --- a/src/modules/alsa-util.c +++ b/src/modules/alsa-util.c @@ -850,56 +850,6 @@ int pa_alsa_calc_mixer_map(snd_mixer_elem_t *elem, const pa_channel_map *channel return 0; } -void pa_alsa_0dB_playback(snd_mixer_elem_t *elem) { - long min, max, v; - - pa_assert(elem); - - /* Try to enable 0 dB if possible. If ALSA cannot do dB, then use - * raw volume levels and fix them to 75% */ - - if (snd_mixer_selem_set_playback_dB_all(elem, 0, -1) >= 0) - return; - - if (snd_mixer_selem_set_playback_dB_all(elem, 0, 1) >= 0) - return; - - if (snd_mixer_selem_get_playback_volume_range(elem, &min, &max) < 0) - return; - - v = min + ((max - min) * 3) / 4; /* 75% */ - - if (v <= min) - v = max; - - snd_mixer_selem_set_playback_volume_all(elem, v); -} - -void pa_alsa_0dB_capture(snd_mixer_elem_t *elem) { - long min, max, v; - - pa_assert(elem); - - /* Try to enable 0 dB if possible. If ALSA cannot do dB, then use - * raw volume levels and fix them to 75% */ - - if (snd_mixer_selem_set_capture_dB_all(elem, 0, -1) >= 0) - return; - - if (snd_mixer_selem_set_capture_dB_all(elem, 0, 1) >= 0) - return; - - if (snd_mixer_selem_get_capture_volume_range(elem, &min, &max) < 0) - return; - - v = min + ((max - min) * 3) / 4; /* 75% */ - - if (v <= min) - v = max; - - snd_mixer_selem_set_capture_volume_all(elem, v); -} - void pa_alsa_dump(snd_pcm_t *pcm) { int err; snd_output_t *out; diff --git a/src/modules/alsa-util.h b/src/modules/alsa-util.h index 1b73200b..7991a107 100644 --- a/src/modules/alsa-util.h +++ b/src/modules/alsa-util.h @@ -80,9 +80,6 @@ snd_pcm_t *pa_alsa_open_by_device_string( int pa_alsa_calc_mixer_map(snd_mixer_elem_t *elem, const pa_channel_map *channel_map, snd_mixer_selem_channel_id_t mixer_map[], pa_bool_t playback); -void pa_alsa_0dB_playback(snd_mixer_elem_t *elem); -void pa_alsa_0dB_capture(snd_mixer_elem_t *elem); - void pa_alsa_dump(snd_pcm_t *pcm); void pa_alsa_dump_status(snd_pcm_t *pcm); -- 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 ++++---- src/modules/module-lirc.c | 4 ++-- src/modules/module-mmkbd-evdev.c | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) (limited to 'src/modules') 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))) { diff --git a/src/modules/module-lirc.c b/src/modules/module-lirc.c index 4fd05434..97e97dc7 100644 --- a/src/modules/module-lirc.c +++ b/src/modules/module-lirc.c @@ -122,7 +122,7 @@ static void io_callback(pa_mainloop_api *io, pa_io_event *e, int fd, pa_io_event pa_log("Failed to get sink '%s'", u->sink_name); else { int i; - pa_cvolume cv = *pa_sink_get_volume(s); + pa_cvolume cv = *pa_sink_get_volume(s, FALSE); #define DELTA (PA_VOLUME_NORM/20) @@ -159,7 +159,7 @@ static void io_callback(pa_mainloop_api *io, pa_io_event *e, int fd, pa_io_event case MUTE_TOGGLE: - pa_sink_set_mute(s, !pa_sink_get_mute(s)); + pa_sink_set_mute(s, !pa_sink_get_mute(s, FALSE)); break; case INVALID: diff --git a/src/modules/module-mmkbd-evdev.c b/src/modules/module-mmkbd-evdev.c index 3f012b7f..21f176a4 100644 --- a/src/modules/module-mmkbd-evdev.c +++ b/src/modules/module-mmkbd-evdev.c @@ -113,7 +113,7 @@ static void io_callback(pa_mainloop_api *io, pa_io_event *e, int fd, pa_io_event pa_log("Failed to get sink '%s'", u->sink_name); else { int i; - pa_cvolume cv = *pa_sink_get_volume(s); + pa_cvolume cv = *pa_sink_get_volume(s, FALSE); #define DELTA (PA_VOLUME_NORM/20) @@ -142,7 +142,7 @@ static void io_callback(pa_mainloop_api *io, pa_io_event *e, int fd, pa_io_event case MUTE_TOGGLE: - pa_sink_set_mute(s, !pa_sink_get_mute(s)); + pa_sink_set_mute(s, !pa_sink_get_mute(s, FALSE)); break; case INVALID: -- cgit From f68a6e5cab772184caf89895766eec32da4c7598 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 15 Aug 2008 14:33:18 +0200 Subject: don't restore devices for direct-on-input streams --- src/modules/module-stream-restore.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/modules') diff --git a/src/modules/module-stream-restore.c b/src/modules/module-stream-restore.c index b999304a..bf62f94c 100644 --- a/src/modules/module-stream-restore.c +++ b/src/modules/module-stream-restore.c @@ -360,6 +360,7 @@ static pa_hook_result_t source_output_new_hook_callback(pa_core *c, pa_source_ou pa_source *s; if (u->restore_device && + !new_data->direct_on_input && (s = pa_namereg_get(c, e->device, PA_NAMEREG_SOURCE, TRUE))) { pa_log_info("Restoring device for stream %s.", name); -- cgit From 512c24c65abf42d2546491607da4fed286c79e1f Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 15 Aug 2008 14:37:26 +0200 Subject: apply the correct rules to sink inputs --- src/modules/module-stream-restore.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/modules') diff --git a/src/modules/module-stream-restore.c b/src/modules/module-stream-restore.c index bf62f94c..e0683e72 100644 --- a/src/modules/module-stream-restore.c +++ b/src/modules/module-stream-restore.c @@ -409,7 +409,7 @@ static void apply_entry(struct userdata *u, const char *name, struct entry *e) { char *n; pa_sink *s; - if (!(n = get_name(si->proplist, "sink_input"))) + if (!(n = get_name(si->proplist, "sink-input"))) continue; if (strcmp(name, n)) { -- cgit From 63402b392be251ca5519cc668c3bf698aa33aed0 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 15 Aug 2008 14:37:54 +0200 Subject: apply volumes properly more than once in a row --- src/modules/module-stream-restore.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/modules') diff --git a/src/modules/module-stream-restore.c b/src/modules/module-stream-restore.c index e0683e72..5b9922ec 100644 --- a/src/modules/module-stream-restore.c +++ b/src/modules/module-stream-restore.c @@ -418,8 +418,9 @@ static void apply_entry(struct userdata *u, const char *name, struct entry *e) { } if (u->restore_volume) { + pa_cvolume v = e->volume; pa_log_info("Restoring volume for sink input %s.", name); - pa_sink_input_set_volume(si, pa_cvolume_remap(&e->volume, &e->channel_map, &si->channel_map)); + pa_sink_input_set_volume(si, pa_cvolume_remap(&v, &e->channel_map, &si->channel_map)); } if (u->restore_muted) { -- cgit From f84536bc0a76d751fe5adaef76d227a41b3285fc Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 15 Aug 2008 14:38:18 +0200 Subject: apply newly configured rules properly --- src/modules/module-stream-restore.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/modules') diff --git a/src/modules/module-stream-restore.c b/src/modules/module-stream-restore.c index 5b9922ec..73b32502 100644 --- a/src/modules/module-stream-restore.c +++ b/src/modules/module-stream-restore.c @@ -554,7 +554,7 @@ static int extension_cb(pa_native_protocol *p, pa_module *m, pa_native_connectio case SUBCOMMAND_WRITE: { uint32_t mode; - pa_bool_t apply_immediately; + pa_bool_t apply_immediately = FALSE; if (pa_tagstruct_getu32(t, &mode) < 0 || pa_tagstruct_get_boolean(t, &apply_immediately) < 0) @@ -573,6 +573,7 @@ static int extension_cb(pa_native_protocol *p, pa_module *m, pa_native_connectio pa_bool_t muted; struct entry entry; datum key, data; + int k; memset(&entry, 0, sizeof(entry)); @@ -595,7 +596,7 @@ static int extension_cb(pa_native_protocol *p, pa_module *m, pa_native_connectio data.dptr = (void*) &entry; data.dsize = sizeof(entry); - if (gdbm_store(u->gdbm_file, key, data, mode == PA_UPDATE_REPLACE ? GDBM_REPLACE : GDBM_INSERT) == 1) + if ((k = gdbm_store(u->gdbm_file, key, data, mode == PA_UPDATE_REPLACE ? GDBM_REPLACE : GDBM_INSERT)) == 0) if (apply_immediately) apply_entry(u, name, &entry); } -- cgit From 8d596a9bc560eb6740e2f303cda712eb7169c3ce Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 15 Aug 2008 14:40:08 +0200 Subject: Make Multicast TTL for RTP configurable, patch from 'dfort' Signed-off-by: Lennart Poettering --- src/modules/rtp/module-rtp-send.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'src/modules') diff --git a/src/modules/rtp/module-rtp-send.c b/src/modules/rtp/module-rtp-send.c index 5e542253..aad21265 100644 --- a/src/modules/rtp/module-rtp-send.c +++ b/src/modules/rtp/module-rtp-send.c @@ -67,10 +67,12 @@ PA_MODULE_USAGE( "destination= " "port= " "mtu= " - "loop=" + "loop= " + "ttl=" ); #define DEFAULT_PORT 46000 +#define DEFAULT_TTL 1 #define SAP_PORT 9875 #define DEFAULT_DESTINATION "224.0.0.56" #define MEMBLOCKQ_MAXLENGTH (1024*170) @@ -86,6 +88,7 @@ static const char* const valid_modargs[] = { "port", "mtu" , "loop", + "ttl", NULL }; @@ -167,6 +170,7 @@ int pa__init(pa_module*m) { pa_modargs *ma = NULL; const char *dest; uint32_t port = DEFAULT_PORT, mtu; + unsigned char ttl = DEFAULT_TTL; int af, fd = -1, sap_fd = -1; pa_source *s; pa_sample_spec ss; @@ -235,6 +239,11 @@ int pa__init(pa_module*m) { if (port & 1) pa_log_warn("Port number not even as suggested in RFC3550!"); + if (pa_modargs_get_value_u32(ma, "ttl", &ttl) < 0 || ttl < 1 || ttl > 0xFF) { + pa_log("ttl= expects a numerical argument between 1 and 255."); + goto fail; + } + dest = pa_modargs_get_value(ma, "destination", DEFAULT_DESTINATION); if (inet_pton(AF_INET6, dest, &sa6.sin6_addr) > 0) { @@ -279,6 +288,11 @@ int pa__init(pa_module*m) { goto fail; } + if (ttl != DEFAULT_TTL && setsockopt(fd, IPPROTO_IP, IP_MULTICAST_TTL, &ttl, sizeof(ttl)) < 0) { + pa_log("IP_MULTICAST_TTL failed: %s", pa_cstrerror(errno)); + goto fail; + } + /* If the socket queue is full, let's drop packets */ pa_make_fd_nonblock(fd); pa_make_udp_socket_low_delay(fd); @@ -290,6 +304,7 @@ int pa__init(pa_module*m) { pa_proplist_sets(data.proplist, "rtp.destination", dest); pa_proplist_setf(data.proplist, "rtp.mtu", "%lu", (unsigned long) mtu); pa_proplist_setf(data.proplist, "rtp.port", "%lu", (unsigned long) port); + pa_proplist_setf(data.proplist, "rtp.ttl", "%lu", (unsigned long) ttl); data.driver = __FILE__; data.module = m; data.source = s; @@ -342,7 +357,7 @@ int pa__init(pa_module*m) { pa_rtp_context_init_send(&u->rtp_context, fd, m->core->cookie, payload, pa_frame_size(&ss)); pa_sap_context_init_send(&u->sap_context, sap_fd, p); - pa_log_info("RTP stream initialized with mtu %u on %s:%u, SSRC=0x%08x, payload=%u, initial sequence #%u", mtu, dest, port, u->rtp_context.ssrc, payload, u->rtp_context.sequence); + pa_log_info("RTP stream initialized with mtu %u on %s:%u ttl=%u, SSRC=0x%08x, payload=%u, initial sequence #%u", mtu, dest, port, ttl, u->rtp_context.ssrc, payload, u->rtp_context.sequence); pa_log_info("SDP-Data:\n%s\nEOF", p); pa_sap_send(&u->sap_context, 0); -- cgit From 67858c6e46b6795893ef1337bef1d86c018cdd9e Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 18 Aug 2008 17:36:59 +0200 Subject: fix type error --- src/modules/rtp/module-rtp-send.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'src/modules') diff --git a/src/modules/rtp/module-rtp-send.c b/src/modules/rtp/module-rtp-send.c index aad21265..1423cbc1 100644 --- a/src/modules/rtp/module-rtp-send.c +++ b/src/modules/rtp/module-rtp-send.c @@ -170,7 +170,7 @@ int pa__init(pa_module*m) { pa_modargs *ma = NULL; const char *dest; uint32_t port = DEFAULT_PORT, mtu; - unsigned char ttl = DEFAULT_TTL; + uint32_t ttl = DEFAULT_TTL; int af, fd = -1, sap_fd = -1; pa_source *s; pa_sample_spec ss; @@ -288,9 +288,13 @@ int pa__init(pa_module*m) { goto fail; } - if (ttl != DEFAULT_TTL && setsockopt(fd, IPPROTO_IP, IP_MULTICAST_TTL, &ttl, sizeof(ttl)) < 0) { - pa_log("IP_MULTICAST_TTL failed: %s", pa_cstrerror(errno)); - goto fail; + if (ttl != DEFAULT_TTL) { + int _ttl = (int) ttl; + + if (setsockopt(fd, IPPROTO_IP, IP_MULTICAST_TTL, &_ttl, sizeof(_ttl)) < 0) { + pa_log("IP_MULTICAST_TTL failed: %s", pa_cstrerror(errno)); + goto fail; + } } /* If the socket queue is full, let's drop packets */ -- cgit From b8ba2de7ddfea2b0fa53dc7e8614d16b16ec1915 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 18 Aug 2008 17:49:47 +0200 Subject: restore volume/device for streams only when it wasn't set before --- src/modules/module-stream-restore.c | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) (limited to 'src/modules') diff --git a/src/modules/module-stream-restore.c b/src/modules/module-stream-restore.c index 73b32502..7bbb47d5 100644 --- a/src/modules/module-stream-restore.c +++ b/src/modules/module-stream-restore.c @@ -306,8 +306,11 @@ static pa_hook_result_t sink_input_new_hook_callback(pa_core *c, pa_sink_input_n if (u->restore_device && (s = pa_namereg_get(c, e->device, PA_NAMEREG_SINK, TRUE))) { - pa_log_info("Restoring device for stream %s.", name); - new_data->sink = s; + if (!new_data->sink) { + pa_log_info("Restoring device for stream %s.", name); + new_data->sink = s; + } else + pa_log_info("Not restore device for stream %s, because already set.", name); } pa_xfree(e); @@ -330,13 +333,20 @@ static pa_hook_result_t sink_input_fixate_hook_callback(pa_core *c, pa_sink_inpu if ((e = read_entry(u, name))) { if (u->restore_volume) { - pa_log_info("Restoring volume for sink input %s.", name); - pa_sink_input_new_data_set_volume(new_data, pa_cvolume_remap(&e->volume, &e->channel_map, &new_data->channel_map)); + + if (!new_data->volume_is_set) { + pa_log_info("Restoring volume for sink input %s.", name); + pa_sink_input_new_data_set_volume(new_data, pa_cvolume_remap(&e->volume, &e->channel_map, &new_data->channel_map)); + } else + pa_log_debug("Not restoring volume for sink input %s, because already set.", name); } if (u->restore_muted) { - pa_log_info("Restoring mute state for sink input %s.", name); - pa_sink_input_new_data_set_muted(new_data, e->muted); + if (!new_data->muted_is_set) { + pa_log_info("Restoring mute state for sink input %s.", name); + pa_sink_input_new_data_set_muted(new_data, e->muted); + } else + pa_log_debug("Not restoring mute state for sink input %s, because already set.", name); } pa_xfree(e); @@ -363,8 +373,11 @@ static pa_hook_result_t source_output_new_hook_callback(pa_core *c, pa_source_ou !new_data->direct_on_input && (s = pa_namereg_get(c, e->device, PA_NAMEREG_SOURCE, TRUE))) { - pa_log_info("Restoring device for stream %s.", name); - new_data->source = s; + if (!new_data->source) { + pa_log_info("Restoring device for stream %s.", name); + new_data->source = s; + } else + pa_log_info("Not restroing device for stream %s, because already set", name); } pa_xfree(e); -- cgit From 5cc2187bec5923e13fb3958d57a5243aaa57b982 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 18 Aug 2008 19:55:55 +0200 Subject: add some code to make invalid valgrind warnings go away --- src/modules/module-alsa-sink.c | 17 +++++++++++++++++ src/modules/module-alsa-source.c | 17 +++++++++++++++++ 2 files changed, 34 insertions(+) (limited to 'src/modules') diff --git a/src/modules/module-alsa-sink.c b/src/modules/module-alsa-sink.c index 255896c2..8980ba24 100644 --- a/src/modules/module-alsa-sink.c +++ b/src/modules/module-alsa-sink.c @@ -28,6 +28,10 @@ #include +#ifdef HAVE_VALGRIND_MEMCHECK_H +#include +#endif + #include #include #include @@ -766,6 +770,10 @@ static int sink_get_volume_cb(pa_sink *s) { if ((err = snd_mixer_selem_get_playback_dB(u->mixer_elem, u->mixer_map[i], &alsa_vol)) < 0) goto fail; +#ifdef HAVE_VALGRIND_MEMCHECK_H + VALGRIND_MAKE_MEM_DEFINED(&alsa_vol, sizeof(alsa_vol)); +#endif + r.values[i] = pa_sw_volume_from_dB((double) alsa_vol / 100.0); } else { @@ -784,6 +792,10 @@ static int sink_get_volume_cb(pa_sink *s) { if ((err = snd_mixer_selem_get_playback_dB(u->mixer_elem, SND_MIXER_SCHN_MONO, &alsa_vol)) < 0) goto fail; +#ifdef HAVE_VALGRIND_MEMCHECK_H + VALGRIND_MAKE_MEM_DEFINED(&alsa_vol, sizeof(alsa_vol)); +#endif + pa_cvolume_set(&r, s->sample_spec.channels, pa_sw_volume_from_dB((double) alsa_vol / 100.0)); } @@ -1435,6 +1447,11 @@ int pa__init(pa_module*m) { if (snd_mixer_selem_get_playback_dB_range(u->mixer_elem, &u->hw_dB_min, &u->hw_dB_max) < 0) pa_log_info("Mixer doesn't support dB information."); else { +#ifdef HAVE_VALGRIND_MEMCHECK_H + VALGRIND_MAKE_MEM_DEFINED(&u->hw_dB_min, sizeof(u->hw_dB_min)); + VALGRIND_MAKE_MEM_DEFINED(&u->hw_dB_max, sizeof(u->hw_dB_max)); +#endif + pa_log_info("Volume ranges from %0.2f dB to %0.2f dB.", u->hw_dB_min/100.0, u->hw_dB_max/100.0); pa_assert(u->hw_dB_min < u->hw_dB_max); u->hw_dB_supported = TRUE; diff --git a/src/modules/module-alsa-source.c b/src/modules/module-alsa-source.c index 0e4efad5..9cf5aaf6 100644 --- a/src/modules/module-alsa-source.c +++ b/src/modules/module-alsa-source.c @@ -28,6 +28,10 @@ #include +#ifdef HAVE_VALGRIND_MEMCHECK_H +#include +#endif + #include #include #include @@ -710,6 +714,10 @@ static int source_get_volume_cb(pa_source *s) { if ((err = snd_mixer_selem_get_capture_dB(u->mixer_elem, u->mixer_map[i], &alsa_vol)) < 0) goto fail; +#ifdef HAVE_VALGRIND_MEMCHECK_H + VALGRIND_MAKE_MEM_DEFINED(&alsa_vol, sizeof(alsa_vol)); +#endif + r.values[i] = pa_sw_volume_from_dB((double) alsa_vol / 100.0); } else { @@ -728,6 +736,10 @@ static int source_get_volume_cb(pa_source *s) { if ((err = snd_mixer_selem_get_capture_dB(u->mixer_elem, SND_MIXER_SCHN_MONO, &alsa_vol)) < 0) goto fail; +#ifdef HAVE_VALGRIND_MEMCHECK_H + VALGRIND_MAKE_MEM_DEFINED(&alsa_vol, sizeof(alsa_vol)); +#endif + pa_cvolume_set(&r, s->sample_spec.channels, pa_sw_volume_from_dB((double) alsa_vol / 100.0)); } @@ -1255,6 +1267,11 @@ int pa__init(pa_module*m) { if (snd_mixer_selem_get_capture_dB_range(u->mixer_elem, &u->hw_dB_min, &u->hw_dB_max) < 0) pa_log_info("Mixer doesn't support dB information."); else { +#ifdef HAVE_VALGRIND_MEMCHECK_H + VALGRIND_MAKE_MEM_DEFINED(&u->hw_dB_min, sizeof(u->hw_dB_min)); + VALGRIND_MAKE_MEM_DEFINED(&u->hw_dB_max, sizeof(u->hw_dB_max)); +#endif + pa_log_info("Volume ranges from %0.2f dB to %0.2f dB.", u->hw_dB_min/100.0, u->hw_dB_max/100.0); pa_assert(u->hw_dB_min < u->hw_dB_max); u->hw_dB_supported = TRUE; -- cgit From e65c514542d5eee842fde9eb1eb6186c9f37c45b Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 18 Aug 2008 20:07:32 +0200 Subject: don't unref pa_native_options object twice --- src/modules/module-native-protocol-fd.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'src/modules') diff --git a/src/modules/module-native-protocol-fd.c b/src/modules/module-native-protocol-fd.c index fa9c0e4f..f17f435a 100644 --- a/src/modules/module-native-protocol-fd.c +++ b/src/modules/module-native-protocol-fd.c @@ -48,7 +48,8 @@ static const char* const valid_modargs[] = { int pa__init(pa_module*m) { pa_iochannel *io; pa_modargs *ma; - int fd, r = -1; + int32_t fd; + int r = -1; pa_native_options *options = NULL; pa_assert(m); @@ -63,18 +64,16 @@ int pa__init(pa_module*m) { goto finish; } - options = pa_native_options_new(); - options->module = m; - options->auth_anonymous = TRUE; + m->userdata = pa_native_protocol_get(m->core); io = pa_iochannel_new(m->core->mainloop, fd, fd); - m->userdata = pa_native_protocol_get(m->core); + options = pa_native_options_new(); + options->module = m; + options->auth_anonymous = TRUE; pa_native_protocol_connect(m->userdata, io, options); - pa_native_options_unref(options); - r = 0; finish: -- 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/alsa-util.c | 31 ++++++------ src/modules/dbus-util.c | 6 +-- src/modules/gconf/module-gconf.c | 8 +-- src/modules/module-alsa-sink.c | 75 +++++++++++++++-------------- src/modules/module-alsa-source.c | 55 ++++++++++----------- src/modules/module-combine.c | 6 +-- src/modules/module-detect.c | 6 +-- src/modules/module-device-restore.c | 4 +- src/modules/module-esound-compat-spawnpid.c | 2 +- src/modules/module-esound-sink.c | 16 +++--- src/modules/module-hal-detect.c | 10 ++-- src/modules/module-jack-sink.c | 10 ++-- src/modules/module-jack-source.c | 4 +- src/modules/module-ladspa-sink.c | 28 +++++------ src/modules/module-oss.c | 66 +++++++++++++------------ src/modules/module-pipe-sink.c | 6 +-- src/modules/module-pipe-source.c | 6 +-- src/modules/module-protocol-stub.c | 10 ++-- src/modules/module-sine.c | 6 +-- src/modules/module-stream-restore.c | 10 ++-- src/modules/module-tunnel.c | 36 +++++++------- src/modules/module-volume-restore.c | 2 +- src/modules/module-x11-bell.c | 2 +- src/modules/module-x11-xsmp.c | 4 +- src/modules/module-zeroconf-discover.c | 4 +- src/modules/oss-util.c | 6 +-- src/modules/rtp/module-rtp-recv.c | 18 +++---- src/modules/rtp/module-rtp-send.c | 17 ++++--- src/modules/rtp/rtp.c | 21 ++++---- src/modules/rtp/sap.c | 28 +++++------ src/modules/rtp/sdp.c | 8 +-- 31 files changed, 259 insertions(+), 252 deletions(-) (limited to 'src/modules') diff --git a/src/modules/alsa-util.c b/src/modules/alsa-util.c index e3e8c85c..e8c7e146 100644 --- a/src/modules/alsa-util.c +++ b/src/modules/alsa-util.c @@ -39,7 +39,7 @@ #include "alsa-util.h" struct pa_alsa_fdlist { - int num_fds; + unsigned num_fds; struct pollfd *fds; /* This is a temporary buffer used to avoid lots of mallocs */ struct pollfd *work_fds; @@ -50,7 +50,7 @@ struct pa_alsa_fdlist { pa_defer_event *defer; pa_io_event **ios; - int polled; + pa_bool_t polled; void (*cb)(void *userdata); void *userdata; @@ -59,7 +59,8 @@ struct pa_alsa_fdlist { static void io_cb(pa_mainloop_api*a, pa_io_event* e, int fd, pa_io_event_flags_t events, void *userdata) { struct pa_alsa_fdlist *fdl = userdata; - int err, i; + int err; + unsigned i; unsigned short revents; pa_assert(a); @@ -71,11 +72,11 @@ static void io_cb(pa_mainloop_api*a, pa_io_event* e, int fd, pa_io_event_flags_t if (fdl->polled) return; - fdl->polled = 1; + fdl->polled = TRUE; memcpy(fdl->work_fds, fdl->fds, sizeof(struct pollfd) * fdl->num_fds); - for (i = 0;i < fdl->num_fds; i++) { + for (i = 0; i < fdl->num_fds; i++) { if (e == fdl->ios[i]) { if (events & PA_IO_EVENT_INPUT) fdl->work_fds[i].revents |= POLLIN; @@ -104,7 +105,8 @@ static void io_cb(pa_mainloop_api*a, pa_io_event* e, int fd, pa_io_event_flags_t static void defer_cb(pa_mainloop_api*a, pa_defer_event* e, void *userdata) { struct pa_alsa_fdlist *fdl = userdata; - int num_fds, i, err; + unsigned num_fds, i; + int err; struct pollfd *temp; pa_assert(a); @@ -113,8 +115,7 @@ static void defer_cb(pa_mainloop_api*a, pa_defer_event* e, void *userdata) { a->defer_enable(fdl->defer, 0); - num_fds = snd_mixer_poll_descriptors_count(fdl->mixer); - pa_assert(num_fds > 0); + num_fds = (unsigned) snd_mixer_poll_descriptors_count(fdl->mixer); if (num_fds != fdl->num_fds) { if (fdl->fds) @@ -132,7 +133,7 @@ static void defer_cb(pa_mainloop_api*a, pa_defer_event* e, void *userdata) { return; } - fdl->polled = 0; + fdl->polled = FALSE; if (memcmp(fdl->fds, fdl->work_fds, sizeof(struct pollfd) * num_fds) == 0) return; @@ -176,7 +177,7 @@ struct pa_alsa_fdlist *pa_alsa_fdlist_new(void) { fdl->m = NULL; fdl->defer = NULL; fdl->ios = NULL; - fdl->polled = 0; + fdl->polled = FALSE; return fdl; } @@ -190,9 +191,9 @@ void pa_alsa_fdlist_free(struct pa_alsa_fdlist *fdl) { } if (fdl->ios) { - int i; + unsigned i; pa_assert(fdl->m); - for (i = 0;i < fdl->num_fds;i++) + for (i = 0; i < fdl->num_fds; i++) fdl->m->io_free(fdl->ios[i]); pa_xfree(fdl->ios); } @@ -403,7 +404,7 @@ int pa_alsa_set_hw_params( /* If the sample rate deviates too much, we need to resample */ if (r < ss->rate*.95 || r > ss->rate*1.05) ss->rate = r; - ss->channels = c; + ss->channels = (uint8_t) c; ss->format = f; pa_assert(_periods > 0); @@ -1056,10 +1057,10 @@ pa_rtpoll_item* pa_alsa_build_pollfd(snd_pcm_t *pcm, pa_rtpoll *rtpoll) { return NULL; } - item = pa_rtpoll_item_new(rtpoll, PA_RTPOLL_NEVER, n); + item = pa_rtpoll_item_new(rtpoll, PA_RTPOLL_NEVER, (unsigned) n); pollfd = pa_rtpoll_item_get_pollfd(item, NULL); - if ((err = snd_pcm_poll_descriptors(pcm, pollfd, n)) < 0) { + if ((err = snd_pcm_poll_descriptors(pcm, pollfd, (unsigned) n)) < 0) { pa_log("snd_pcm_poll_descriptors() failed: %s", snd_strerror(err)); pa_rtpoll_item_free(item); return NULL; diff --git a/src/modules/dbus-util.c b/src/modules/dbus-util.c index c9c32a15..d2abf087 100644 --- a/src/modules/dbus-util.c +++ b/src/modules/dbus-util.c @@ -126,7 +126,7 @@ static void handle_time_event(pa_mainloop_api *ea, pa_time_event* e, const struc dbus_timeout_handle(timeout); /* restart it for the next scheduled time */ - pa_timeval_add(&next, dbus_timeout_get_interval(timeout) * 1000); + pa_timeval_add(&next, (pa_usec_t) dbus_timeout_get_interval(timeout) * 1000); ea->time_restart(e, &next); } } @@ -192,7 +192,7 @@ static dbus_bool_t add_timeout(DBusTimeout *timeout, void *data) { return FALSE; pa_gettimeofday(&tv); - pa_timeval_add(&tv, dbus_timeout_get_interval(timeout) * 1000); + pa_timeval_add(&tv, (pa_usec_t) dbus_timeout_get_interval(timeout) * 1000); ev = c->mainloop->time_new(c->mainloop, &tv, handle_time_event, timeout); @@ -227,7 +227,7 @@ static void toggle_timeout(DBusTimeout *timeout, void *data) { struct timeval tv; pa_gettimeofday(&tv); - pa_timeval_add(&tv, dbus_timeout_get_interval(timeout) * 1000); + pa_timeval_add(&tv, (pa_usec_t) dbus_timeout_get_interval(timeout) * 1000); c->mainloop->time_restart(ev, &tv); } else diff --git a/src/modules/gconf/module-gconf.c b/src/modules/gconf/module-gconf.c index e2b0f7c0..6e8ab6ea 100644 --- a/src/modules/gconf/module-gconf.c +++ b/src/modules/gconf/module-gconf.c @@ -96,7 +96,7 @@ static int fill_buf(struct userdata *u) { if ((r = pa_read(u->fd, u->buf + u->buf_fill, BUF_MAX - u->buf_fill, &u->fd_type)) <= 0) return -1; - u->buf_fill += r; + u->buf_fill += (size_t) r; return 0; } @@ -123,7 +123,7 @@ static char *read_string(struct userdata *u) { if ((e = memchr(u->buf, 0, u->buf_fill))) { char *ret = pa_xstrdup(u->buf); - u->buf_fill -= e - u->buf +1; + u->buf_fill -= (size_t) (e - u->buf +1); memmove(u->buf, e+1, u->buf_fill); return ret; } @@ -164,10 +164,10 @@ static void unload_all_modules(struct userdata *u, struct module_info*m) { static void load_module( struct userdata *u, struct module_info *m, - int i, + unsigned i, const char *name, const char *args, - int is_new) { + pa_bool_t is_new) { pa_module *mod; diff --git a/src/modules/module-alsa-sink.c b/src/modules/module-alsa-sink.c index 8980ba24..e3f9a5ff 100644 --- a/src/modules/module-alsa-sink.c +++ b/src/modules/module-alsa-sink.c @@ -143,7 +143,7 @@ static void fix_tsched_watermark(struct userdata *u) { size_t min_sleep, min_wakeup; pa_assert(u); - max_use = u->hwbuf_size - u->hwbuf_unused_frames * u->frame_size; + max_use = u->hwbuf_size - (size_t) u->hwbuf_unused_frames * u->frame_size; min_sleep = pa_usec_to_bytes(TSCHED_MIN_SLEEP_USEC, &u->sink->sample_spec); min_wakeup = pa_usec_to_bytes(TSCHED_MIN_WAKEUP_USEC, &u->sink->sample_spec); @@ -216,8 +216,8 @@ static int try_recover(struct userdata *u, const char *call, int err) { static size_t check_left_to_play(struct userdata *u, snd_pcm_sframes_t n) { size_t left_to_play; - if (n*u->frame_size < u->hwbuf_size) - left_to_play = u->hwbuf_size - (n*u->frame_size); + if ((size_t) n*u->frame_size < u->hwbuf_size) + left_to_play = u->hwbuf_size - ((size_t) n*u->frame_size); else left_to_play = 0; @@ -263,7 +263,7 @@ static int mmap_write(struct userdata *u, pa_usec_t *sleep_usec) { if (PA_UNLIKELY((n = snd_pcm_avail_update(u->pcm_handle)) < 0)) { - if ((r = try_recover(u, "snd_pcm_avail_update", n)) == 0) + if ((r = try_recover(u, "snd_pcm_avail_update", (int) n)) == 0) continue; return r; @@ -295,6 +295,7 @@ static int mmap_write(struct userdata *u, pa_usec_t *sleep_usec) { int err; const snd_pcm_channel_area_t *areas; snd_pcm_uframes_t offset, frames = (snd_pcm_uframes_t) n; + snd_pcm_sframes_t sframes; /* pa_log_debug("%lu frames to write", (unsigned long) frames); */ @@ -330,9 +331,9 @@ static int mmap_write(struct userdata *u, pa_usec_t *sleep_usec) { * a little bit longer around? */ pa_memblock_unref_fixed(chunk.memblock); - if (PA_UNLIKELY((err = snd_pcm_mmap_commit(u->pcm_handle, offset, frames)) < 0)) { + if (PA_UNLIKELY((sframes = snd_pcm_mmap_commit(u->pcm_handle, offset, frames)) < 0)) { - if ((r = try_recover(u, "snd_pcm_mmap_commit", err)) == 0) + if ((r = try_recover(u, "snd_pcm_mmap_commit", (int) sframes)) == 0) continue; return r; @@ -340,7 +341,7 @@ static int mmap_write(struct userdata *u, pa_usec_t *sleep_usec) { work_done = 1; - u->frame_index += frames; + u->frame_index += (int64_t) frames; u->since_start += frames * u->frame_size; /* pa_log_debug("wrote %lu frames", (unsigned long) frames); */ @@ -348,7 +349,7 @@ static int mmap_write(struct userdata *u, pa_usec_t *sleep_usec) { if (frames >= (snd_pcm_uframes_t) n) break; - n -= frames; + n -= (snd_pcm_sframes_t) frames; } } @@ -375,7 +376,7 @@ static int unix_write(struct userdata *u, pa_usec_t *sleep_usec) { if (PA_UNLIKELY((n = snd_pcm_avail_update(u->pcm_handle)) < 0)) { - if ((r = try_recover(u, "snd_pcm_avail_update", n)) == 0) + if ((r = try_recover(u, "snd_pcm_avail_update", (int) n)) == 0) continue; return r; @@ -406,31 +407,31 @@ static int unix_write(struct userdata *u, pa_usec_t *sleep_usec) { /* pa_log_debug("%lu frames to write", (unsigned long) frames); */ if (u->memchunk.length <= 0) - pa_sink_render(u->sink, n * u->frame_size, &u->memchunk); + pa_sink_render(u->sink, (size_t) n * u->frame_size, &u->memchunk); pa_assert(u->memchunk.length > 0); - frames = u->memchunk.length / u->frame_size; + frames = (snd_pcm_sframes_t) (u->memchunk.length / u->frame_size); if (frames > n) frames = n; p = pa_memblock_acquire(u->memchunk.memblock); - frames = snd_pcm_writei(u->pcm_handle, (const uint8_t*) p + u->memchunk.index, frames); + frames = snd_pcm_writei(u->pcm_handle, (const uint8_t*) p + u->memchunk.index, (snd_pcm_uframes_t) frames); pa_memblock_release(u->memchunk.memblock); pa_assert(frames != 0); if (PA_UNLIKELY(frames < 0)) { - if ((r = try_recover(u, "snd_pcm_writei", n)) == 0) + if ((r = try_recover(u, "snd_pcm_writei", (int) frames)) == 0) continue; return r; } - u->memchunk.index += frames * u->frame_size; - u->memchunk.length -= frames * u->frame_size; + u->memchunk.index += (size_t) frames * u->frame_size; + u->memchunk.length -= (size_t) frames * u->frame_size; if (u->memchunk.length <= 0) { pa_memblock_unref(u->memchunk.memblock); @@ -440,7 +441,7 @@ static int unix_write(struct userdata *u, pa_usec_t *sleep_usec) { work_done = 1; u->frame_index += frames; - u->since_start += frames * u->frame_size; + u->since_start += (size_t) frames * u->frame_size; /* pa_log_debug("wrote %lu frames", (unsigned long) frames); */ @@ -494,7 +495,7 @@ static void update_smoother(struct userdata *u) { /* now1 = pa_timeval_load(×tamp); */ now1 = pa_rtclock_usec(); - now2 = pa_bytes_to_usec(frames * u->frame_size, &u->sink->sample_spec); + now2 = pa_bytes_to_usec((uint64_t) frames * u->frame_size, &u->sink->sample_spec); pa_smoother_put(u->smoother, now1, now2); } @@ -508,7 +509,7 @@ static pa_usec_t sink_get_latency(struct userdata *u) { now1 = pa_rtclock_usec(); now2 = pa_smoother_get(u->smoother, now1); - delay = (int64_t) pa_bytes_to_usec(u->frame_index * u->frame_size, &u->sink->sample_spec) - (int64_t) now2; + delay = (int64_t) pa_bytes_to_usec((uint64_t) u->frame_index * u->frame_size, &u->sink->sample_spec) - (int64_t) now2; if (delay > 0) r = (pa_usec_t) delay; @@ -577,9 +578,9 @@ static int update_sw_params(struct userdata *u) { if (PA_UNLIKELY(b < u->frame_size)) b = u->frame_size; - u->hwbuf_unused_frames = - PA_LIKELY(b < u->hwbuf_size) ? - ((u->hwbuf_size - b) / u->frame_size) : 0; + u->hwbuf_unused_frames = (snd_pcm_sframes_t) + (PA_LIKELY(b < u->hwbuf_size) ? + ((u->hwbuf_size - b) / u->frame_size) : 0); fix_tsched_watermark(u); } @@ -588,7 +589,7 @@ static int update_sw_params(struct userdata *u) { pa_log_debug("hwbuf_unused_frames=%lu", (unsigned long) u->hwbuf_unused_frames); /* We need at last one frame in the used part of the buffer */ - avail_min = u->hwbuf_unused_frames + 1; + avail_min = (snd_pcm_uframes_t) u->hwbuf_unused_frames + 1; if (u->use_tsched) { pa_usec_t sleep_usec, process_usec; @@ -604,7 +605,7 @@ static int update_sw_params(struct userdata *u) { return err; } - pa_sink_set_max_request(u->sink, u->hwbuf_size - u->hwbuf_unused_frames * u->frame_size); + pa_sink_set_max_request(u->sink, u->hwbuf_size - (size_t) u->hwbuf_unused_frames * u->frame_size); return 0; } @@ -780,7 +781,7 @@ static int sink_get_volume_cb(pa_sink *s) { if ((err = snd_mixer_selem_get_playback_volume(u->mixer_elem, u->mixer_map[i], &alsa_vol)) < 0) goto fail; - r.values[i] = (pa_volume_t) round(((double) (alsa_vol - u->hw_volume_min) * PA_VOLUME_NORM) / (u->hw_volume_max - u->hw_volume_min)); + r.values[i] = (pa_volume_t) round(((double) (alsa_vol - u->hw_volume_min) * PA_VOLUME_NORM) / (double) (u->hw_volume_max - u->hw_volume_min)); } } @@ -856,7 +857,7 @@ static int sink_set_volume_cb(pa_sink *s) { r.values[i] = pa_sw_volume_from_dB((double) alsa_vol / 100.0); } else { - alsa_vol = (long) round(((double) vol * (u->hw_volume_max - u->hw_volume_min)) / PA_VOLUME_NORM) + u->hw_volume_min; + alsa_vol = (long) round(((double) vol * (double) (u->hw_volume_max - u->hw_volume_min)) / PA_VOLUME_NORM) + u->hw_volume_min; alsa_vol = PA_CLAMP_UNLIKELY(alsa_vol, u->hw_volume_min, u->hw_volume_max); if ((err = snd_mixer_selem_set_playback_volume(u->mixer_elem, u->mixer_map[i], alsa_vol)) < 0) @@ -865,7 +866,7 @@ static int sink_set_volume_cb(pa_sink *s) { if ((err = snd_mixer_selem_get_playback_volume(u->mixer_elem, u->mixer_map[i], &alsa_vol)) < 0) goto fail; - r.values[i] = (pa_volume_t) round(((double) (alsa_vol - u->hw_volume_min) * PA_VOLUME_NORM) / (u->hw_volume_max - u->hw_volume_min)); + r.values[i] = (pa_volume_t) round(((double) (alsa_vol - u->hw_volume_min) * PA_VOLUME_NORM) / (double) (u->hw_volume_max - u->hw_volume_min)); } } @@ -990,7 +991,7 @@ static int process_rewind(struct userdata *u) { snd_pcm_hwsync(u->pcm_handle); if ((unused = snd_pcm_avail_update(u->pcm_handle)) < 0) { - pa_log("snd_pcm_avail_update() failed: %s", snd_strerror(unused)); + pa_log("snd_pcm_avail_update() failed: %s", snd_strerror((int) unused)); return -1; } @@ -1009,15 +1010,15 @@ static int process_rewind(struct userdata *u) { pa_log_debug("Limited to %lu bytes.", (unsigned long) rewind_nbytes); - in_frames = (snd_pcm_sframes_t) rewind_nbytes / u->frame_size; + in_frames = (snd_pcm_sframes_t) (rewind_nbytes / u->frame_size); pa_log_debug("before: %lu", (unsigned long) in_frames); - if ((out_frames = snd_pcm_rewind(u->pcm_handle, in_frames)) < 0) { - pa_log("snd_pcm_rewind() failed: %s", snd_strerror(out_frames)); + if ((out_frames = snd_pcm_rewind(u->pcm_handle, (snd_pcm_uframes_t) in_frames)) < 0) { + pa_log("snd_pcm_rewind() failed: %s", snd_strerror((int) out_frames)); return -1; } pa_log_debug("after: %lu", (unsigned long) out_frames); - rewind_nbytes = out_frames * u->frame_size; + rewind_nbytes = (size_t) out_frames * u->frame_size; if (rewind_nbytes <= 0) pa_log_info("Tried rewind, but was apparently not possible."); @@ -1211,11 +1212,11 @@ int pa__init(pa_module*m) { frame_size = pa_frame_size(&ss); nfrags = m->core->default_n_fragments; - frag_size = pa_usec_to_bytes(m->core->default_fragment_size_msec*PA_USEC_PER_MSEC, &ss); + frag_size = (uint32_t) pa_usec_to_bytes(m->core->default_fragment_size_msec*PA_USEC_PER_MSEC, &ss); if (frag_size <= 0) - frag_size = frame_size; - tsched_size = pa_usec_to_bytes(DEFAULT_TSCHED_BUFFER_USEC, &ss); - tsched_watermark = pa_usec_to_bytes(DEFAULT_TSCHED_WATERMARK_USEC, &ss); + frag_size = (uint32_t) frame_size; + tsched_size = (uint32_t) pa_usec_to_bytes(DEFAULT_TSCHED_BUFFER_USEC, &ss); + tsched_watermark = (uint32_t) pa_usec_to_bytes(DEFAULT_TSCHED_WATERMARK_USEC, &ss); if (pa_modargs_get_value_u32(ma, "fragments", &nfrags) < 0 || pa_modargs_get_value_u32(ma, "fragment_size", &frag_size) < 0 || @@ -1395,7 +1396,7 @@ int pa__init(pa_module*m) { pa_sink_set_rtpoll(u->sink, u->rtpoll); u->frame_size = frame_size; - u->fragment_size = frag_size = period_frames * frame_size; + u->fragment_size = frag_size = (uint32_t) (period_frames * frame_size); u->nfragments = nfrags; u->hwbuf_size = u->fragment_size * nfrags; u->hwbuf_unused_frames = 0; @@ -1452,7 +1453,7 @@ int pa__init(pa_module*m) { VALGRIND_MAKE_MEM_DEFINED(&u->hw_dB_max, sizeof(u->hw_dB_max)); #endif - pa_log_info("Volume ranges from %0.2f dB to %0.2f dB.", u->hw_dB_min/100.0, u->hw_dB_max/100.0); + pa_log_info("Volume ranges from %0.2f dB to %0.2f dB.", (double) u->hw_dB_min/100.0, (double) u->hw_dB_max/100.0); pa_assert(u->hw_dB_min < u->hw_dB_max); u->hw_dB_supported = TRUE; } diff --git a/src/modules/module-alsa-source.c b/src/modules/module-alsa-source.c index 9cf5aaf6..54ffde57 100644 --- a/src/modules/module-alsa-source.c +++ b/src/modules/module-alsa-source.c @@ -141,7 +141,7 @@ static void fix_tsched_watermark(struct userdata *u) { size_t min_sleep, min_wakeup; pa_assert(u); - max_use = u->hwbuf_size - u->hwbuf_unused_frames * u->frame_size; + max_use = u->hwbuf_size - (size_t) u->hwbuf_unused_frames * u->frame_size; min_sleep = pa_usec_to_bytes(TSCHED_MIN_SLEEP_USEC, &u->source->sample_spec); min_wakeup = pa_usec_to_bytes(TSCHED_MIN_WAKEUP_USEC, &u->source->sample_spec); @@ -212,8 +212,8 @@ static int try_recover(struct userdata *u, const char *call, int err) { static size_t check_left_to_record(struct userdata *u, snd_pcm_sframes_t n) { size_t left_to_record; - if (n*u->frame_size < u->hwbuf_size) - left_to_record = u->hwbuf_size - (n*u->frame_size); + if ((size_t) n*u->frame_size < u->hwbuf_size) + left_to_record = u->hwbuf_size - ((size_t) n*u->frame_size); else left_to_record = 0; @@ -256,7 +256,7 @@ static int mmap_read(struct userdata *u, pa_usec_t *sleep_usec) { if (PA_UNLIKELY((n = snd_pcm_avail_update(u->pcm_handle)) < 0)) { - if ((r = try_recover(u, "snd_pcm_avail_update", n)) == 0) + if ((r = try_recover(u, "snd_pcm_avail_update", (int) n)) == 0) continue; return r; @@ -277,6 +277,7 @@ static int mmap_read(struct userdata *u, pa_usec_t *sleep_usec) { snd_pcm_uframes_t offset, frames = (snd_pcm_uframes_t) n; pa_memchunk chunk; void *p; + snd_pcm_sframes_t sframes; /* pa_log_debug("%lu frames to read", (unsigned long) frames); */ @@ -309,9 +310,9 @@ static int mmap_read(struct userdata *u, pa_usec_t *sleep_usec) { pa_source_post(u->source, &chunk); pa_memblock_unref_fixed(chunk.memblock); - if (PA_UNLIKELY((err = snd_pcm_mmap_commit(u->pcm_handle, offset, frames)) < 0)) { + if (PA_UNLIKELY((sframes = snd_pcm_mmap_commit(u->pcm_handle, offset, frames)) < 0)) { - if ((r = try_recover(u, "snd_pcm_mmap_commit", err)) == 0) + if ((r = try_recover(u, "snd_pcm_mmap_commit", (int) sframes)) == 0) continue; return r; @@ -319,14 +320,14 @@ static int mmap_read(struct userdata *u, pa_usec_t *sleep_usec) { work_done = 1; - u->frame_index += frames; + u->frame_index += (int64_t) frames; /* pa_log_debug("read %lu frames", (unsigned long) frames); */ if (frames >= (snd_pcm_uframes_t) n) break; - n -= frames; + n -= (snd_pcm_sframes_t) frames; } } @@ -353,7 +354,7 @@ static int unix_read(struct userdata *u, pa_usec_t *sleep_usec) { if (PA_UNLIKELY((n = snd_pcm_avail_update(u->pcm_handle)) < 0)) { - if ((r = try_recover(u, "snd_pcm_avail_update", n)) == 0) + if ((r = try_recover(u, "snd_pcm_avail_update", (int) n)) == 0) continue; return r; @@ -375,7 +376,7 @@ static int unix_read(struct userdata *u, pa_usec_t *sleep_usec) { chunk.memblock = pa_memblock_new(u->core->mempool, (size_t) -1); - frames = pa_memblock_get_length(chunk.memblock) / u->frame_size; + frames = (snd_pcm_sframes_t) (pa_memblock_get_length(chunk.memblock) / u->frame_size); if (frames > n) frames = n; @@ -383,7 +384,7 @@ static int unix_read(struct userdata *u, pa_usec_t *sleep_usec) { /* pa_log_debug("%lu frames to read", (unsigned long) n); */ p = pa_memblock_acquire(chunk.memblock); - frames = snd_pcm_readi(u->pcm_handle, (uint8_t*) p, frames); + frames = snd_pcm_readi(u->pcm_handle, (uint8_t*) p, (snd_pcm_uframes_t) frames); pa_memblock_release(chunk.memblock); pa_assert(frames != 0); @@ -391,14 +392,14 @@ static int unix_read(struct userdata *u, pa_usec_t *sleep_usec) { if (PA_UNLIKELY(frames < 0)) { pa_memblock_unref(chunk.memblock); - if ((r = try_recover(u, "snd_pcm_readi", n)) == 0) + if ((r = try_recover(u, "snd_pcm_readi", (int) (frames))) == 0) continue; return r; } chunk.index = 0; - chunk.length = frames * u->frame_size; + chunk.length = (size_t) frames * u->frame_size; pa_source_post(u->source, &chunk); pa_memblock_unref(chunk.memblock); @@ -442,7 +443,7 @@ static void update_smoother(struct userdata *u) { frames = u->frame_index + delay; now1 = pa_rtclock_usec(); - now2 = pa_bytes_to_usec(frames * u->frame_size, &u->source->sample_spec); + now2 = pa_bytes_to_usec((uint64_t) frames * u->frame_size, &u->source->sample_spec); pa_smoother_put(u->smoother, now1, now2); } @@ -457,7 +458,7 @@ static pa_usec_t source_get_latency(struct userdata *u) { now1 = pa_rtclock_usec(); now2 = pa_smoother_get(u->smoother, now1); - delay = (int64_t) now2 - pa_bytes_to_usec(u->frame_index * u->frame_size, &u->source->sample_spec); + delay = (int64_t) now2 - (int64_t) pa_bytes_to_usec((uint64_t) u->frame_index * u->frame_size, &u->source->sample_spec); if (delay > 0) r = (pa_usec_t) delay; @@ -522,9 +523,9 @@ static int update_sw_params(struct userdata *u) { if (PA_UNLIKELY(b < u->frame_size)) b = u->frame_size; - u->hwbuf_unused_frames = - PA_LIKELY(b < u->hwbuf_size) ? - ((u->hwbuf_size - b) / u->frame_size) : 0; + u->hwbuf_unused_frames = (snd_pcm_sframes_t) + (PA_LIKELY(b < u->hwbuf_size) ? + ((u->hwbuf_size - b) / u->frame_size) : 0); fix_tsched_watermark(u); } @@ -724,7 +725,7 @@ static int source_get_volume_cb(pa_source *s) { if ((err = snd_mixer_selem_get_capture_volume(u->mixer_elem, u->mixer_map[i], &alsa_vol)) < 0) goto fail; - r.values[i] = (pa_volume_t) round(((double) (alsa_vol - u->hw_volume_min) * PA_VOLUME_NORM) / (u->hw_volume_max - u->hw_volume_min)); + r.values[i] = (pa_volume_t) round(((double) (alsa_vol - u->hw_volume_min) * PA_VOLUME_NORM) / (double) (u->hw_volume_max - u->hw_volume_min)); } } @@ -800,7 +801,7 @@ static int source_set_volume_cb(pa_source *s) { r.values[i] = pa_sw_volume_from_dB((double) alsa_vol / 100.0); } else { - alsa_vol = (long) round(((double) vol * (u->hw_volume_max - u->hw_volume_min)) / PA_VOLUME_NORM) + u->hw_volume_min; + alsa_vol = (long) round(((double) vol * (double) (u->hw_volume_max - u->hw_volume_min)) / PA_VOLUME_NORM) + u->hw_volume_min; alsa_vol = PA_CLAMP_UNLIKELY(alsa_vol, u->hw_volume_min, u->hw_volume_max); if ((err = snd_mixer_selem_set_capture_volume(u->mixer_elem, u->mixer_map[i], alsa_vol)) < 0) @@ -809,7 +810,7 @@ static int source_set_volume_cb(pa_source *s) { if ((err = snd_mixer_selem_get_capture_volume(u->mixer_elem, u->mixer_map[i], &alsa_vol)) < 0) goto fail; - r.values[i] = (pa_volume_t) round(((double) (alsa_vol - u->hw_volume_min) * PA_VOLUME_NORM) / (u->hw_volume_max - u->hw_volume_min)); + r.values[i] = (pa_volume_t) round(((double) (alsa_vol - u->hw_volume_min) * PA_VOLUME_NORM) / (double) (u->hw_volume_max - u->hw_volume_min)); } } @@ -1043,11 +1044,11 @@ int pa__init(pa_module*m) { frame_size = pa_frame_size(&ss); nfrags = m->core->default_n_fragments; - frag_size = pa_usec_to_bytes(m->core->default_fragment_size_msec*PA_USEC_PER_MSEC, &ss); + frag_size = (uint32_t) pa_usec_to_bytes(m->core->default_fragment_size_msec*PA_USEC_PER_MSEC, &ss); if (frag_size <= 0) - frag_size = frame_size; - tsched_size = pa_usec_to_bytes(DEFAULT_TSCHED_BUFFER_USEC, &ss); - tsched_watermark = pa_usec_to_bytes(DEFAULT_TSCHED_WATERMARK_USEC, &ss); + frag_size = (uint32_t) frame_size; + tsched_size = (uint32_t) pa_usec_to_bytes(DEFAULT_TSCHED_BUFFER_USEC, &ss); + tsched_watermark = (uint32_t) pa_usec_to_bytes(DEFAULT_TSCHED_WATERMARK_USEC, &ss); if (pa_modargs_get_value_u32(ma, "fragments", &nfrags) < 0 || pa_modargs_get_value_u32(ma, "fragment_size", &frag_size) < 0 || @@ -1220,7 +1221,7 @@ int pa__init(pa_module*m) { pa_source_set_rtpoll(u->source, u->rtpoll); u->frame_size = frame_size; - u->fragment_size = frag_size = period_frames * frame_size; + u->fragment_size = frag_size = (uint32_t) (period_frames * frame_size); u->nfragments = nfrags; u->hwbuf_size = u->fragment_size * nfrags; u->hwbuf_unused_frames = 0; @@ -1272,7 +1273,7 @@ int pa__init(pa_module*m) { VALGRIND_MAKE_MEM_DEFINED(&u->hw_dB_max, sizeof(u->hw_dB_max)); #endif - pa_log_info("Volume ranges from %0.2f dB to %0.2f dB.", u->hw_dB_min/100.0, u->hw_dB_max/100.0); + pa_log_info("Volume ranges from %0.2f dB to %0.2f dB.", (double) u->hw_dB_min/100.0, (double) u->hw_dB_max/100.0); pa_assert(u->hw_dB_min < u->hw_dB_max); u->hw_dB_supported = TRUE; } diff --git a/src/modules/module-combine.c b/src/modules/module-combine.c index 1bfe4b4c..9fd12e30 100644 --- a/src/modules/module-combine.c +++ b/src/modules/module-combine.c @@ -206,9 +206,9 @@ static void adjust_rates(struct userdata *u) { continue; if (o->total_latency < target_latency) - r -= (uint32_t) (((((double) target_latency - o->total_latency))/u->adjust_time)*r/PA_USEC_PER_SEC); + r -= (uint32_t) ((((double) (target_latency - o->total_latency))/(double)u->adjust_time)*(double)r/PA_USEC_PER_SEC); else if (o->total_latency > target_latency) - r += (uint32_t) (((((double) o->total_latency - target_latency))/u->adjust_time)*r/PA_USEC_PER_SEC); + r += (uint32_t) ((((double) (o->total_latency - target_latency))/(double)u->adjust_time)*(double)r/PA_USEC_PER_SEC); if (r < (uint32_t) (base_rate*0.9) || r > (uint32_t) (base_rate*1.1)) { pa_log_warn("[%s] sample rates too different, not adjusting (%u vs. %u).", pa_proplist_gets(o->sink_input->proplist, PA_PROP_MEDIA_NAME), base_rate, r); @@ -389,7 +389,7 @@ static void request_memblock(struct output *o, size_t length) { /* OK, we need to prepare new data, but only if the sink is actually running */ if (pa_atomic_load(&o->userdata->thread_info.running)) - pa_asyncmsgq_send(o->outq, PA_MSGOBJECT(o->userdata->sink), SINK_MESSAGE_NEED, o, length, NULL); + pa_asyncmsgq_send(o->outq, PA_MSGOBJECT(o->userdata->sink), SINK_MESSAGE_NEED, o, (int64_t) length, NULL); } /* Called from I/O thread context */ diff --git a/src/modules/module-detect.c b/src/modules/module-detect.c index 09b720df..1616d47c 100644 --- a/src/modules/module-detect.c +++ b/src/modules/module-detect.c @@ -236,16 +236,16 @@ int pa__init(pa_module*m) { goto fail; } -#if HAVE_ALSA +#ifdef HAVE_ALSA if ((n = detect_alsa(m->core, just_one)) <= 0) #endif #if HAVE_OSS if ((n = detect_oss(m->core, just_one)) <= 0) #endif -#if HAVE_SOLARIS +#ifdef HAVE_SOLARIS if ((n = detect_solaris(m->core, just_one)) <= 0) #endif -#if OS_IS_WIN32 +#ifdef OS_IS_WIN32 if ((n = detect_waveout(m->core, just_one)) <= 0) #endif { 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); diff --git a/src/modules/module-esound-compat-spawnpid.c b/src/modules/module-esound-compat-spawnpid.c index f75335d5..882dba8c 100644 --- a/src/modules/module-esound-compat-spawnpid.c +++ b/src/modules/module-esound-compat-spawnpid.c @@ -62,7 +62,7 @@ int pa__init(pa_module*m) { goto finish; } - if (kill(pid, SIGUSR1) < 0) + if (kill((pid_t) pid, SIGUSR1) < 0) pa_log_warn("kill(%u) failed: %s", pid, pa_cstrerror(errno)); pa_module_unload_request(m, TRUE); diff --git a/src/modules/module-esound-sink.c b/src/modules/module-esound-sink.c index e0c07d56..14f1810a 100644 --- a/src/modules/module-esound-sink.c +++ b/src/modules/module-esound-sink.c @@ -165,7 +165,7 @@ static int sink_process_msg(pa_msgobject *o, int code, void *data, int64_t offse pa_usec_t w, r; r = pa_smoother_get(u->smoother, pa_rtclock_usec()); - w = pa_bytes_to_usec(u->offset + u->memchunk.length, &u->sink->sample_spec); + w = pa_bytes_to_usec((uint64_t) u->offset + u->memchunk.length, &u->sink->sample_spec); *((pa_usec_t*) data) = w > r ? w - r : 0; break; @@ -250,8 +250,8 @@ static void thread_func(void *userdata) { } else { u->offset += l; - u->memchunk.index += l; - u->memchunk.length -= l; + u->memchunk.index += (size_t) l; + u->memchunk.length -= (size_t) l; if (u->memchunk.length <= 0) { pa_memblock_unref(u->memchunk.memblock); @@ -285,7 +285,7 @@ static void thread_func(void *userdata) { } #endif - usec = pa_bytes_to_usec(n, &u->sink->sample_spec); + usec = pa_bytes_to_usec((uint64_t) n, &u->sink->sample_spec); if (usec > u->latency) usec -= u->latency; @@ -296,7 +296,7 @@ static void thread_func(void *userdata) { } /* Hmm, nothing to do. Let's sleep */ - pollfd->events = PA_SINK_IS_OPENED(u->sink->thread_info.state) ? POLLOUT : 0; + pollfd->events = (short) (PA_SINK_IS_OPENED(u->sink->thread_info.state) ? POLLOUT : 0); } if ((ret = pa_rtpoll_run(u->rtpoll, TRUE)) < 0) @@ -342,7 +342,7 @@ static int do_write(struct userdata *u) { return -1; } - u->write_index += r; + u->write_index += (size_t) r; pa_assert(u->write_index <= u->write_length); if (u->write_index == u->write_length) { @@ -458,7 +458,7 @@ static int do_read(struct userdata *u) { return -1; } - u->read_index += r; + u->read_index += (size_t) r; pa_assert(u->read_index <= u->read_length); if (u->read_index == u->read_length) @@ -545,7 +545,7 @@ int pa__init(pa_module*m) { u->format = (ss.format == PA_SAMPLE_U8 ? ESD_BITS8 : ESD_BITS16) | (ss.channels == 2 ? ESD_STEREO : ESD_MONO); - u->rate = ss.rate; + u->rate = (int32_t) ss.rate; u->block_size = pa_usec_to_bytes(PA_USEC_PER_SEC/20, &ss); u->read_data = u->write_data = NULL; diff --git a/src/modules/module-hal-detect.c b/src/modules/module-hal-detect.c index ce766258..c76a366c 100644 --- a/src/modules/module-hal-detect.c +++ b/src/modules/module-hal-detect.c @@ -405,7 +405,7 @@ static void device_added_time_cb(pa_mainloop_api *ea, pa_time_event *ev, const s dbus_error_init(&error); if (!pa_hashmap_get(td->u->devices, td->udi)) { - int b; + dbus_bool_t b; struct device *d; b = libhal_device_exists(td->u->context, td->udi, &error); @@ -433,7 +433,7 @@ static void device_added_cb(LibHalContext *context, const char *udi) { struct timeval tv; struct timerdata *t; struct userdata *u; - int good = 0; + pa_bool_t good = FALSE; pa_assert_se(u = libhal_ctx_get_user_data(context)); @@ -749,17 +749,17 @@ int pa__init(pa_module*m) { } if ((api = pa_modargs_get_value(ma, "api", NULL))) { - int good = 0; + pa_bool_t good = FALSE; #ifdef HAVE_ALSA if (strcmp(api, CAPABILITY_ALSA) == 0) { - good = 1; + good = TRUE; api = CAPABILITY_ALSA; } #endif #ifdef HAVE_OSS if (strcmp(api, CAPABILITY_OSS) == 0) { - good = 1; + good = TRUE; api = CAPABILITY_OSS; } #endif diff --git a/src/modules/module-jack-sink.c b/src/modules/module-jack-sink.c index edc543a8..555cb825 100644 --- a/src/modules/module-jack-sink.c +++ b/src/modules/module-jack-sink.c @@ -130,12 +130,12 @@ static int sink_process_msg(pa_msgobject *o, int code, void *data, int64_t offse void *p; pa_assert(offset > 0); - nbytes = offset * pa_frame_size(&u->sink->sample_spec); + nbytes = (size_t) offset * pa_frame_size(&u->sink->sample_spec); pa_sink_render_full(u->sink, nbytes, &chunk); p = (uint8_t*) pa_memblock_acquire(chunk.memblock) + chunk.index; - pa_deinterleave(p, u->buffer, u->channels, sizeof(float), offset); + pa_deinterleave(p, u->buffer, u->channels, sizeof(float), (unsigned) offset); pa_memblock_release(chunk.memblock); pa_memblock_unref(chunk.memblock); @@ -149,10 +149,10 @@ static int sink_process_msg(pa_msgobject *o, int code, void *data, int64_t offse ss.channels = 1; for (c = 0; c < u->channels; c++) - pa_silence_memory(u->buffer[c], offset * pa_sample_size(&ss), &ss); + pa_silence_memory(u->buffer[c], (size_t) offset * pa_sample_size(&ss), &ss); } - u->frames_in_buffer = offset; + u->frames_in_buffer = (jack_nframes_t) offset; u->saved_frame_time = * (jack_nframes_t*) data; u->saved_frame_time_valid = TRUE; @@ -342,7 +342,7 @@ int pa__init(pa_module*m) { pa_log_info("Successfully connected as '%s'", jack_get_client_name(u->client)); - ss.channels = u->channels = channels; + u->channels = ss.channels = (uint8_t) channels; ss.rate = jack_get_sample_rate(u->client); ss.format = PA_SAMPLE_FLOAT32NE; diff --git a/src/modules/module-jack-source.c b/src/modules/module-jack-source.c index 03f9d15c..9eccbbfa 100644 --- a/src/modules/module-jack-source.c +++ b/src/modules/module-jack-source.c @@ -116,7 +116,7 @@ static int source_process_msg(pa_msgobject *o, int code, void *data, int64_t off if (u->source->thread_info.state == PA_SOURCE_RUNNING) pa_source_post(u->source, chunk); - u->saved_frame_time = offset; + u->saved_frame_time = (jack_nframes_t) offset; u->saved_frame_time_valid = TRUE; return 0; @@ -309,7 +309,7 @@ int pa__init(pa_module*m) { pa_log_info("Successfully connected as '%s'", jack_get_client_name(u->client)); - ss.channels = u->channels = channels; + u->channels = ss.channels = (uint8_t) channels; ss.rate = jack_get_sample_rate(u->client); ss.format = PA_SAMPLE_FLOAT32NE; diff --git a/src/modules/module-ladspa-sink.c b/src/modules/module-ladspa-sink.c index 23eeb340..9127af01 100644 --- a/src/modules/module-ladspa-sink.c +++ b/src/modules/module-ladspa-sink.c @@ -187,7 +187,7 @@ static int sink_input_pop_cb(pa_sink_input *i, size_t nbytes, pa_memchunk *chunk pa_assert(tchunk.length > 0); fs = pa_frame_size(&i->sample_spec); - n = PA_MIN(tchunk.length, u->block_size) / fs; + n = (unsigned) (PA_MIN(tchunk.length, u->block_size) / fs); pa_assert(n > 0); @@ -502,9 +502,9 @@ int pa__init(pa_module*m) { u->block_size = pa_frame_align(pa_mempool_block_size_max(m->core->mempool), &ss); - u->input = (LADSPA_Data*) pa_xnew(uint8_t, u->block_size); + u->input = (LADSPA_Data*) pa_xnew(uint8_t, (unsigned) u->block_size); if (LADSPA_IS_INPLACE_BROKEN(d->Properties)) - u->output = (LADSPA_Data*) pa_xnew(uint8_t, u->block_size); + u->output = (LADSPA_Data*) pa_xnew(uint8_t, (unsigned) u->block_size); else u->output = u->input; @@ -530,8 +530,8 @@ int pa__init(pa_module*m) { char *k; unsigned long h; - u->control = pa_xnew(LADSPA_Data, n_control); - use_default = pa_xnew(pa_bool_t, n_control); + u->control = pa_xnew(LADSPA_Data, (unsigned) n_control); + use_default = pa_xnew(pa_bool_t, (unsigned) n_control); p = 0; while ((k = pa_split(cdata, ",", &state)) && p < n_control) { @@ -552,7 +552,7 @@ int pa__init(pa_module*m) { pa_xfree(k); use_default[p] = FALSE; - u->control[p++] = f; + u->control[p++] = (LADSPA_Data) f; } /* The previous loop doesn't take the last control value into account @@ -601,8 +601,8 @@ int pa__init(pa_module*m) { upper = d->PortRangeHints[p].UpperBound; if (LADSPA_IS_HINT_SAMPLE_RATE(hint)) { - lower *= ss.rate; - upper *= ss.rate; + lower *= (LADSPA_Data) ss.rate; + upper *= (LADSPA_Data) ss.rate; } switch (hint & LADSPA_HINT_DEFAULT_MASK) { @@ -617,23 +617,23 @@ int pa__init(pa_module*m) { case LADSPA_HINT_DEFAULT_LOW: if (LADSPA_IS_HINT_LOGARITHMIC(hint)) - u->control[h] = exp(log(lower) * 0.75 + log(upper) * 0.25); + u->control[h] = (LADSPA_Data) exp(log(lower) * 0.75 + log(upper) * 0.25); else - u->control[h] = lower * 0.75 + upper * 0.25; + u->control[h] = (LADSPA_Data) (lower * 0.75 + upper * 0.25); break; case LADSPA_HINT_DEFAULT_MIDDLE: if (LADSPA_IS_HINT_LOGARITHMIC(hint)) - u->control[h] = exp(log(lower) * 0.5 + log(upper) * 0.5); + u->control[h] = (LADSPA_Data) exp(log(lower) * 0.5 + log(upper) * 0.5); else - u->control[h] = lower * 0.5 + upper * 0.5; + u->control[h] = (LADSPA_Data) (lower * 0.5 + upper * 0.5); break; case LADSPA_HINT_DEFAULT_HIGH: if (LADSPA_IS_HINT_LOGARITHMIC(hint)) - u->control[h] = exp(log(lower) * 0.25 + log(upper) * 0.75); + u->control[h] = (LADSPA_Data) exp(log(lower) * 0.25 + log(upper) * 0.75); else - u->control[h] = lower * 0.25 + upper * 0.75; + u->control[h] = (LADSPA_Data) (lower * 0.25 + upper * 0.75); break; case LADSPA_HINT_DEFAULT_0: diff --git a/src/modules/module-oss.c b/src/modules/module-oss.c index 15b1e956..3333eb83 100644 --- a/src/modules/module-oss.c +++ b/src/modules/module-oss.c @@ -258,7 +258,7 @@ static int mmap_write(struct userdata *u) { u->out_mmap_saved_nfrags = 0; if (info.blocks > 0) - mmap_fill_memblocks(u, info.blocks); + mmap_fill_memblocks(u, (unsigned) info.blocks); return info.blocks; } @@ -336,7 +336,7 @@ static int mmap_read(struct userdata *u) { u->in_mmap_saved_nfrags = 0; if (info.blocks > 0) { - mmap_post_memblocks(u, info.blocks); + mmap_post_memblocks(u, (unsigned) info.blocks); mmap_clear_memblocks(u, u->in_nfrags/2); } @@ -356,12 +356,12 @@ static pa_usec_t mmap_sink_get_latency(struct userdata *u) { u->out_mmap_saved_nfrags += info.blocks; - bpos = ((u->out_mmap_current + u->out_mmap_saved_nfrags) * u->out_fragment_size) % u->out_hwbuf_size; + bpos = ((u->out_mmap_current + (unsigned) u->out_mmap_saved_nfrags) * u->out_fragment_size) % u->out_hwbuf_size; if (bpos <= (size_t) info.ptr) - n = u->out_hwbuf_size - (info.ptr - bpos); + n = u->out_hwbuf_size - ((size_t) info.ptr - bpos); else - n = bpos - info.ptr; + n = bpos - (size_t) info.ptr; /* pa_log("n = %u, bpos = %u, ptr = %u, total=%u, fragsize = %u, n_frags = %u\n", n, bpos, (unsigned) info.ptr, total, u->out_fragment_size, u->out_fragments); */ @@ -380,12 +380,12 @@ static pa_usec_t mmap_source_get_latency(struct userdata *u) { } u->in_mmap_saved_nfrags += info.blocks; - bpos = ((u->in_mmap_current + u->in_mmap_saved_nfrags) * u->in_fragment_size) % u->in_hwbuf_size; + bpos = ((u->in_mmap_current + (unsigned) u->in_mmap_saved_nfrags) * u->in_fragment_size) % u->in_hwbuf_size; if (bpos <= (size_t) info.ptr) - n = info.ptr - bpos; + n = (size_t) info.ptr - bpos; else - n = u->in_hwbuf_size - bpos + info.ptr; + n = u->in_hwbuf_size - bpos + (size_t) info.ptr; /* pa_log("n = %u, bpos = %u, ptr = %u, total=%u, fragsize = %u, n_frags = %u\n", n, bpos, (unsigned) info.ptr, total, u->in_fragment_size, u->in_fragments); */ @@ -404,7 +404,7 @@ static pa_usec_t io_sink_get_latency(struct userdata *u) { pa_log_info("Device doesn't support SNDCTL_DSP_GETODELAY: %s", pa_cstrerror(errno)); u->use_getodelay = 0; } else - r = pa_bytes_to_usec(arg, &u->sink->sample_spec); + r = pa_bytes_to_usec((size_t) arg, &u->sink->sample_spec); } @@ -415,7 +415,7 @@ static pa_usec_t io_sink_get_latency(struct userdata *u) { pa_log_info("Device doesn't support SNDCTL_DSP_GETOSPACE: %s", pa_cstrerror(errno)); u->use_getospace = 0; } else - r = pa_bytes_to_usec(info.bytes, &u->sink->sample_spec); + r = pa_bytes_to_usec((size_t) info.bytes, &u->sink->sample_spec); } if (u->memchunk.memblock) @@ -437,7 +437,7 @@ static pa_usec_t io_source_get_latency(struct userdata *u) { pa_log_info("Device doesn't support SNDCTL_DSP_GETISPACE: %s", pa_cstrerror(errno)); u->use_getispace = 0; } else - r = pa_bytes_to_usec(info.bytes, &u->source->sample_spec); + r = pa_bytes_to_usec((size_t) info.bytes, &u->source->sample_spec); } return r; @@ -528,8 +528,9 @@ static int unsuspend(struct userdata *u) { if ((u->fd = pa_oss_open(u->device_name, &m, NULL)) < 0) { pa_log_warn("Resume failed, device busy (%s)", pa_cstrerror(errno)); return -1; + } - if (m != u->mode) + if (m != u->mode) { pa_log_warn("Resume failed, couldn't open device with original access mode."); goto fail; } @@ -859,7 +860,7 @@ static int source_set_volume(pa_source *s) { static void thread_func(void *userdata) { struct userdata *u = userdata; int write_type = 0, read_type = 0; - unsigned short revents = 0; + short revents = 0; pa_assert(u); @@ -935,7 +936,7 @@ static void thread_func(void *userdata) { ssize_t t; if (u->memchunk.length <= 0) - pa_sink_render(u->sink, l, &u->memchunk); + pa_sink_render(u->sink, (size_t) l, &u->memchunk); pa_assert(u->memchunk.length > 0); @@ -965,8 +966,8 @@ static void thread_func(void *userdata) { } else { - u->memchunk.index += t; - u->memchunk.length -= t; + u->memchunk.index += (size_t) t; + u->memchunk.length -= (size_t) t; if (u->memchunk.length <= 0) { pa_memblock_unref(u->memchunk.memblock); @@ -1031,7 +1032,8 @@ static void thread_func(void *userdata) { } while (l > 0) { - ssize_t t, k; + ssize_t t; + size_t k; pa_assert(l > 0); @@ -1039,8 +1041,8 @@ static void thread_func(void *userdata) { k = pa_memblock_get_length(memchunk.memblock); - if (k > l) - k = l; + if (k > (size_t) l) + k = (size_t) l; k = (k/u->frame_size)*u->frame_size; @@ -1071,7 +1073,7 @@ static void thread_func(void *userdata) { } else { memchunk.index = 0; - memchunk.length = t; + memchunk.length = (size_t) t; pa_source_post(u->source, &memchunk); pa_memblock_unref(memchunk.memblock); @@ -1099,9 +1101,9 @@ static void thread_func(void *userdata) { pa_assert(u->fd >= 0); pollfd = pa_rtpoll_item_get_pollfd(u->rtpoll_item, NULL); - pollfd->events = - ((u->source && PA_SOURCE_IS_OPENED(u->source->thread_info.state)) ? POLLIN : 0) | - ((u->sink && PA_SINK_IS_OPENED(u->sink->thread_info.state)) ? POLLOUT : 0); + pollfd->events = (short) + (((u->source && PA_SOURCE_IS_OPENED(u->source->thread_info.state)) ? POLLIN : 0) | + ((u->sink && PA_SINK_IS_OPENED(u->sink->thread_info.state)) ? POLLOUT : 0)); } /* Hmm, nothing to do. Let's sleep */ @@ -1179,10 +1181,10 @@ int pa__init(pa_module*m) { goto fail; } - nfrags = m->core->default_n_fragments; - frag_size = pa_usec_to_bytes(m->core->default_fragment_size_msec*1000, &ss); + nfrags = (int) m->core->default_n_fragments; + frag_size = (int) pa_usec_to_bytes(m->core->default_fragment_size_msec*1000, &ss); if (frag_size <= 0) - frag_size = pa_frame_size(&ss); + frag_size = (int) pa_frame_size(&ss); if (pa_modargs_get_value_s32(ma, "fragments", &nfrags) < 0 || pa_modargs_get_value_s32(ma, "fragment_size", &frag_size) < 0) { pa_log("Failed to parse fragments arguments"); @@ -1238,8 +1240,8 @@ int pa__init(pa_module*m) { u->mode = mode; u->frame_size = pa_frame_size(&ss); u->device_name = pa_xstrdup(dev); - u->in_nfrags = u->out_nfrags = u->nfrags = nfrags; - u->out_fragment_size = u->in_fragment_size = u->frag_size = frag_size; + u->in_nfrags = u->out_nfrags = (uint32_t) (u->nfrags = nfrags); + u->out_fragment_size = u->in_fragment_size = (uint32_t) (u->frag_size = frag_size); u->use_mmap = use_mmap; u->rtpoll = pa_rtpoll_new(); pa_thread_mq_init(&u->thread_mq, m->core->mainloop, u->rtpoll); @@ -1248,15 +1250,15 @@ int pa__init(pa_module*m) { if (ioctl(fd, SNDCTL_DSP_GETISPACE, &info) >= 0) { pa_log_info("Input -- %u fragments of size %u.", info.fragstotal, info.fragsize); - u->in_fragment_size = info.fragsize; - u->in_nfrags = info.fragstotal; + u->in_fragment_size = (uint32_t) info.fragsize; + u->in_nfrags = (uint32_t) info.fragstotal; u->use_getispace = TRUE; } if (ioctl(fd, SNDCTL_DSP_GETOSPACE, &info) >= 0) { pa_log_info("Output -- %u fragments of size %u.", info.fragstotal, info.fragsize); - u->out_fragment_size = info.fragsize; - u->out_nfrags = info.fragstotal; + u->out_fragment_size = (uint32_t) info.fragsize; + u->out_nfrags = (uint32_t) info.fragstotal; u->use_getospace = TRUE; } diff --git a/src/modules/module-pipe-sink.c b/src/modules/module-pipe-sink.c index f389cd06..ae230b2c 100644 --- a/src/modules/module-pipe-sink.c +++ b/src/modules/module-pipe-sink.c @@ -145,8 +145,8 @@ static int process_render(struct userdata *u) { } else { - u->memchunk.index += l; - u->memchunk.length -= l; + u->memchunk.index += (size_t) l; + u->memchunk.length -= (size_t) l; if (u->memchunk.length <= 0) { pa_memblock_unref(u->memchunk.memblock); @@ -189,7 +189,7 @@ static void thread_func(void *userdata) { } /* Hmm, nothing to do. Let's sleep */ - pollfd->events = u->sink->thread_info.state == PA_SINK_RUNNING ? POLLOUT : 0; + pollfd->events = (short) (u->sink->thread_info.state == PA_SINK_RUNNING ? POLLOUT : 0); if ((ret = pa_rtpoll_run(u->rtpoll, TRUE)) < 0) goto fail; diff --git a/src/modules/module-pipe-source.c b/src/modules/module-pipe-source.c index b0de34ca..25151d95 100644 --- a/src/modules/module-pipe-source.c +++ b/src/modules/module-pipe-source.c @@ -135,9 +135,9 @@ static void thread_func(void *userdata) { } else { - u->memchunk.length = l; + u->memchunk.length = (size_t) l; pa_source_post(u->source, &u->memchunk); - u->memchunk.index += l; + u->memchunk.index += (size_t) l; if (u->memchunk.index >= pa_memblock_get_length(u->memchunk.memblock)) { pa_memblock_unref(u->memchunk.memblock); @@ -149,7 +149,7 @@ static void thread_func(void *userdata) { } /* Hmm, nothing to do. Let's sleep */ - pollfd->events = u->source->thread_info.state == PA_SOURCE_RUNNING ? POLLIN : 0; + pollfd->events = (short) (u->source->thread_info.state == PA_SOURCE_RUNNING ? POLLIN : 0); if ((ret = pa_rtpoll_run(u->rtpoll, TRUE)) < 0) goto fail; diff --git a/src/modules/module-protocol-stub.c b/src/modules/module-protocol-stub.c index 4fe439f9..0e98b1c3 100644 --- a/src/modules/module-protocol-stub.c +++ b/src/modules/module-protocol-stub.c @@ -299,11 +299,11 @@ int pa__init(pa_module*m) { listen_on = pa_modargs_get_value(ma, "listen", NULL); if (listen_on) { - u->socket_server_ipv6 = pa_socket_server_new_ipv6_string(m->core->mainloop, listen_on, port, TCPWRAP_SERVICE); - u->socket_server_ipv4 = pa_socket_server_new_ipv4_string(m->core->mainloop, listen_on, port, TCPWRAP_SERVICE); + u->socket_server_ipv6 = pa_socket_server_new_ipv6_string(m->core->mainloop, listen_on, (uint16_t) port, TCPWRAP_SERVICE); + u->socket_server_ipv4 = pa_socket_server_new_ipv4_string(m->core->mainloop, listen_on, (uint16_t) port, TCPWRAP_SERVICE); } else { - u->socket_server_ipv6 = pa_socket_server_new_ipv6_any(m->core->mainloop, port, TCPWRAP_SERVICE); - u->socket_server_ipv4 = pa_socket_server_new_ipv4_any(m->core->mainloop, port, TCPWRAP_SERVICE); + u->socket_server_ipv6 = pa_socket_server_new_ipv6_any(m->core->mainloop, (uint16_t) port, TCPWRAP_SERVICE); + u->socket_server_ipv4 = pa_socket_server_new_ipv4_any(m->core->mainloop, (uint16_t) port, TCPWRAP_SERVICE); } if (!u->socket_server_ipv4 && !u->socket_server_ipv6) @@ -327,7 +327,7 @@ int pa__init(pa_module*m) { /* This socket doesn't reside in our own runtime dir but in * /tmp/.esd/, hence we have to create the dir first */ - if (pa_make_secure_parent_dir(u->socket_path, pa_in_system_mode() ? 0755 : 0700, (uid_t)-1, (gid_t)-1) < 0) { + if (pa_make_secure_parent_dir(u->socket_path, pa_in_system_mode() ? 0755U : 0700U, (uid_t)-1, (gid_t)-1) < 0) { pa_log("Failed to create socket directory '%s': %s\n", u->socket_path, pa_cstrerror(errno)); goto fail; } diff --git a/src/modules/module-sine.c b/src/modules/module-sine.c index a6324526..21565cc4 100644 --- a/src/modules/module-sine.c +++ b/src/modules/module-sine.c @@ -116,13 +116,13 @@ static void sink_input_state_change_cb(pa_sink_input *i, pa_sink_input_state_t s pa_sink_input_request_rewind(i, 0, FALSE, TRUE); } -static void calc_sine(float *f, size_t l, float freq) { +static void calc_sine(float *f, size_t l, double freq) { size_t i; l /= sizeof(float); for (i = 0; i < l; i++) - f[i] = (float) sin((double) i/l*M_PI*2*freq)/2; + f[i] = (float) sin((double) i/(double)l*M_PI*2*freq)/2; } int pa__init(pa_module*m) { @@ -163,7 +163,7 @@ int pa__init(pa_module*m) { u->memblock = pa_memblock_new(m->core->mempool, pa_bytes_per_second(&ss)); p = pa_memblock_acquire(u->memblock); - calc_sine(p, pa_memblock_get_length(u->memblock), frequency); + calc_sine(p, pa_memblock_get_length(u->memblock), (double) frequency); pa_memblock_release(u->memblock); pa_sink_input_new_data_init(&data); diff --git a/src/modules/module-stream-restore.c b/src/modules/module-stream-restore.c index 7bbb47d5..37e8b067 100644 --- a/src/modules/module-stream-restore.c +++ b/src/modules/module-stream-restore.c @@ -145,7 +145,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); @@ -277,7 +277,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); @@ -544,7 +544,7 @@ static int extension_cb(pa_native_protocol *p, pa_module *m, pa_native_connectio next_key = gdbm_nextkey(u->gdbm_file, key); - name = pa_xstrndup(key.dptr, key.dsize); + name = pa_xstrndup(key.dptr, (size_t) key.dsize); pa_xfree(key.dptr); if ((e = read_entry(u, name))) { @@ -604,7 +604,7 @@ static int extension_cb(pa_native_protocol *p, pa_module *m, pa_native_connectio pa_strlcpy(entry.device, device, sizeof(entry.device)); key.dptr = (void*) name; - key.dsize = strlen(name); + key.dsize = (int) strlen(name); data.dptr = (void*) &entry; data.dsize = sizeof(entry); @@ -629,7 +629,7 @@ static int extension_cb(pa_native_protocol *p, pa_module *m, pa_native_connectio goto fail; key.dptr = (void*) name; - key.dsize = strlen(name); + key.dsize = (int) strlen(name); gdbm_delete(u->gdbm_file, key); } diff --git a/src/modules/module-tunnel.c b/src/modules/module-tunnel.c index 79ce1dd2..de3c7274 100644 --- a/src/modules/module-tunnel.c +++ b/src/modules/module-tunnel.c @@ -178,7 +178,7 @@ struct userdata { #ifdef TUNNEL_SINK char *sink_name; pa_sink *sink; - int32_t requested_bytes; + size_t requested_bytes; #else char *source_name; pa_source *source; @@ -389,7 +389,7 @@ static void send_data(struct userdata *u) { u->requested_bytes -= memchunk.length; - u->counter += memchunk.length; + u->counter += (int64_t) memchunk.length; } } @@ -417,7 +417,7 @@ static int sink_process_msg(pa_msgobject *o, int code, void *data, int64_t offse case PA_SINK_MESSAGE_GET_LATENCY: { pa_usec_t yl, yr, *usec = data; - yl = pa_bytes_to_usec(u->counter, &u->sink->sample_spec); + yl = pa_bytes_to_usec((uint64_t) u->counter, &u->sink->sample_spec); yr = pa_smoother_get(u->smoother, pa_rtclock_usec()); *usec = yl > yr ? yl - yr : 0; @@ -444,10 +444,10 @@ static int sink_process_msg(pa_msgobject *o, int code, void *data, int64_t offse case SINK_MESSAGE_UPDATE_LATENCY: { pa_usec_t y; - y = pa_bytes_to_usec(u->counter, &u->sink->sample_spec); + y = pa_bytes_to_usec((uint64_t) u->counter, &u->sink->sample_spec); if (y > (pa_usec_t) offset || offset < 0) - y -= offset; + y -= (pa_usec_t) offset; else y = 0; @@ -465,7 +465,7 @@ static int sink_process_msg(pa_msgobject *o, int code, void *data, int64_t offse pa_pstream_send_memblock(u->pstream, u->channel, 0, PA_SEEK_RELATIVE, chunk); - u->counter_delta += chunk->length; + u->counter_delta += (int64_t) chunk->length; return 0; } @@ -520,7 +520,7 @@ static int source_process_msg(pa_msgobject *o, int code, void *data, int64_t off case PA_SOURCE_MESSAGE_GET_LATENCY: { pa_usec_t yr, yl, *usec = data; - yl = pa_bytes_to_usec(u->counter, &PA_SINK(o)->sample_spec); + yl = pa_bytes_to_usec((uint64_t) u->counter, &PA_SINK(o)->sample_spec); yr = pa_smoother_get(u->smoother, pa_rtclock_usec()); *usec = yr > yl ? yr - yl : 0; @@ -532,7 +532,7 @@ static int source_process_msg(pa_msgobject *o, int code, void *data, int64_t off if (PA_SOURCE_IS_OPENED(u->source->thread_info.state)) pa_source_post(u->source, chunk); - u->counter += chunk->length; + u->counter += (int64_t) chunk->length; return 0; @@ -544,10 +544,10 @@ static int source_process_msg(pa_msgobject *o, int code, void *data, int64_t off case SOURCE_MESSAGE_UPDATE_LATENCY: { pa_usec_t y; - y = pa_bytes_to_usec(u->counter, &u->source->sample_spec); + y = pa_bytes_to_usec((uint64_t) u->counter, &u->source->sample_spec); if (offset >= 0 || y > (pa_usec_t) -offset) - y += offset; + y += (pa_usec_t) offset; else y = 0; @@ -736,9 +736,9 @@ static void stream_get_latency_callback(pa_pdispatch *pd, uint32_t command, uint /* Add the length of our server-side buffer */ if (write_index >= read_index) - delay += (int64_t) pa_bytes_to_usec(write_index-read_index, ss); + delay += (int64_t) pa_bytes_to_usec((uint64_t) (write_index-read_index), ss); else - delay -= (int64_t) pa_bytes_to_usec(read_index-write_index, ss); + delay -= (int64_t) pa_bytes_to_usec((uint64_t) (read_index-write_index), ss); /* Our measurements are already out of date, hence correct by the * * transport latency */ @@ -750,9 +750,9 @@ static void stream_get_latency_callback(pa_pdispatch *pd, uint32_t command, uint /* Now correct by what we have have read/written since we requested the update */ #ifdef TUNNEL_SINK - delay += (int64_t) pa_bytes_to_usec(u->counter_delta, ss); + delay += (int64_t) pa_bytes_to_usec((uint64_t) u->counter_delta, ss); #else - delay -= (int64_t) pa_bytes_to_usec(u->counter_delta, ss); + delay -= (int64_t) pa_bytes_to_usec((uint64_t) u->counter_delta, ss); #endif #ifdef TUNNEL_SINK @@ -1425,11 +1425,11 @@ static void setup_complete_callback(pa_pdispatch *pd, uint32_t command, uint32_t u->maxlength = 4*1024*1024; #ifdef TUNNEL_SINK - u->tlength = pa_usec_to_bytes(PA_USEC_PER_MSEC * DEFAULT_TLENGTH_MSEC, &u->sink->sample_spec); - u->minreq = pa_usec_to_bytes(PA_USEC_PER_MSEC * DEFAULT_MINREQ_MSEC, &u->sink->sample_spec); + u->tlength = (uint32_t) pa_usec_to_bytes(PA_USEC_PER_MSEC * DEFAULT_TLENGTH_MSEC, &u->sink->sample_spec); + u->minreq = (uint32_t) pa_usec_to_bytes(PA_USEC_PER_MSEC * DEFAULT_MINREQ_MSEC, &u->sink->sample_spec); u->prebuf = u->tlength; #else - u->fragsize = pa_usec_to_bytes(PA_USEC_PER_MSEC * DEFAULT_FRAGSIZE_MSEC, &u->source->sample_spec); + u->fragsize = (uint32_t) pa_usec_to_bytes(PA_USEC_PER_MSEC * DEFAULT_FRAGSIZE_MSEC, &u->source->sample_spec); #endif #ifdef TUNNEL_SINK @@ -1548,7 +1548,7 @@ static void pstream_memblock_callback(pa_pstream *p, uint32_t channel, int64_t o pa_asyncmsgq_send(u->source->asyncmsgq, PA_MSGOBJECT(u->source), SOURCE_MESSAGE_POST, PA_UINT_TO_PTR(seek), offset, chunk); - u->counter_delta += chunk->length; + u->counter_delta += (int64_t) chunk->length; } #endif diff --git a/src/modules/module-volume-restore.c b/src/modules/module-volume-restore.c index 0fb17a0d..aac0d046 100644 --- a/src/modules/module-volume-restore.c +++ b/src/modules/module-volume-restore.c @@ -103,7 +103,7 @@ static pa_cvolume* parse_volume(const char *s, pa_cvolume *v) { if (k <= 0 || k > (long) PA_CHANNELS_MAX) return NULL; - v->channels = (unsigned) k; + v->channels = (uint8_t) k; for (i = 0; i < v->channels; i++) { p += strspn(p, WHITESPACE); diff --git a/src/modules/module-x11-bell.c b/src/modules/module-x11-bell.c index ae16b9ae..e93721c1 100644 --- a/src/modules/module-x11-bell.c +++ b/src/modules/module-x11-bell.c @@ -82,7 +82,7 @@ static int x11_event_cb(pa_x11_wrapper *w, XEvent *e, void *userdata) { bne = (XkbBellNotifyEvent*) e; - if (pa_scache_play_item_by_name(u->core, u->scache_item, u->sink_name, TRUE, (bne->percent*PA_VOLUME_NORM)/100, NULL, NULL) < 0) { + if (pa_scache_play_item_by_name(u->core, u->scache_item, u->sink_name, TRUE, ((pa_volume_t) bne->percent*PA_VOLUME_NORM)/100U, NULL, NULL) < 0) { pa_log_info("Ringing bell failed, reverting to X11 device bell."); XkbForceDeviceBell(pa_x11_wrapper_get_display(w), bne->device, bne->bell_class, bne->bell_id, bne->percent); } diff --git a/src/modules/module-x11-xsmp.c b/src/modules/module-x11-xsmp.c index 12e100b7..57d182fd 100644 --- a/src/modules/module-x11-xsmp.c +++ b/src/modules/module-x11-xsmp.c @@ -181,7 +181,7 @@ int pa__init(pa_module*m) { prop_program.name = (char*) SmProgram; prop_program.type = (char*) SmARRAY8; val_program.value = (char*) PACKAGE_NAME; - val_program.length = strlen(val_program.value); + val_program.length = (int) strlen(val_program.value); prop_program.num_vals = 1; prop_program.vals = &val_program; prop_list[0] = &prop_program; @@ -190,7 +190,7 @@ int pa__init(pa_module*m) { prop_user.type = (char*) SmARRAY8; pa_get_user_name(t, sizeof(t)); val_user.value = t; - val_user.length = strlen(val_user.value); + val_user.length = (int) strlen(val_user.value); prop_user.num_vals = 1; prop_user.vals = &val_user; prop_list[1] = &prop_user; diff --git a/src/modules/module-zeroconf-discover.c b/src/modules/module-zeroconf-discover.c index a4fbf020..c8087abb 100644 --- a/src/modules/module-zeroconf-discover.c +++ b/src/modules/module-zeroconf-discover.c @@ -173,9 +173,9 @@ static void resolver_cb( device = value; value = NULL; } else if (strcmp(key, "rate") == 0) - ss.rate = atoi(value); + ss.rate = (uint32_t) atoi(value); else if (strcmp(key, "channels") == 0) - ss.channels = atoi(value); + ss.channels = (uint8_t) atoi(value); else if (strcmp(key, "format") == 0) ss.format = pa_parse_sample_format(value); else if (strcmp(key, "channel_map") == 0) { diff --git a/src/modules/oss-util.c b/src/modules/oss-util.c index 2791e165..f766030d 100644 --- a/src/modules/oss-util.c +++ b/src/modules/oss-util.c @@ -204,10 +204,10 @@ int pa_oss_auto_format(int fd, pa_sample_spec *ss) { if (ss->channels != channels) { pa_log_warn("device doesn't support %i channels, using %i channels.", ss->channels, channels); - ss->channels = channels; + ss->channels = (uint8_t) channels; } - speed = ss->rate; + speed = (int) ss->rate; if (ioctl(fd, SNDCTL_DSP_SPEED, &speed) < 0) { pa_log("SNDCTL_DSP_SPEED: %s", pa_cstrerror(errno)); return -1; @@ -219,7 +219,7 @@ int pa_oss_auto_format(int fd, pa_sample_spec *ss) { /* If the sample rate deviates too much, we need to resample */ if (speed < ss->rate*.95 || speed > ss->rate*1.05) - ss->rate = speed; + ss->rate = (uint32_t) speed; } return 0; diff --git a/src/modules/rtp/module-rtp-recv.c b/src/modules/rtp/module-rtp-recv.c index e04e4611..01637892 100644 --- a/src/modules/rtp/module-rtp-recv.c +++ b/src/modules/rtp/module-rtp-recv.c @@ -238,15 +238,15 @@ static int rtpoll_work_cb(pa_rtpoll_item *i) { else delta = j; - pa_memblockq_seek(s->memblockq, delta * s->rtp_context.frame_size, PA_SEEK_RELATIVE); + pa_memblockq_seek(s->memblockq, delta * (int64_t) s->rtp_context.frame_size, PA_SEEK_RELATIVE); pa_rtclock_get(&now); - pa_smoother_put(s->smoother, pa_timeval_load(&now), pa_bytes_to_usec(pa_memblockq_get_write_index(s->memblockq), &s->sink_input->sample_spec)); + pa_smoother_put(s->smoother, pa_timeval_load(&now), pa_bytes_to_usec((uint64_t) pa_memblockq_get_write_index(s->memblockq), &s->sink_input->sample_spec)); if (pa_memblockq_push(s->memblockq, &chunk) < 0) { pa_log_warn("Queue overrun"); - pa_memblockq_seek(s->memblockq, chunk.length, PA_SEEK_RELATIVE); + pa_memblockq_seek(s->memblockq, (int64_t) chunk.length, PA_SEEK_RELATIVE); } pa_log("blocks in q: %u", pa_memblockq_get_nblocks(s->memblockq)); @@ -254,9 +254,9 @@ static int rtpoll_work_cb(pa_rtpoll_item *i) { pa_memblock_unref(chunk.memblock); /* The next timestamp we expect */ - s->offset = s->rtp_context.timestamp + (chunk.length / s->rtp_context.frame_size); + s->offset = s->rtp_context.timestamp + (uint32_t) (chunk.length / s->rtp_context.frame_size); - pa_atomic_store(&s->timestamp, now.tv_sec); + pa_atomic_store(&s->timestamp, (int) now.tv_sec); if (s->last_rate_update + RATE_UPDATE_INTERVAL < pa_timeval_load(&now)) { pa_usec_t wi, ri, render_delay, sink_delay = 0, latency, fix; @@ -265,7 +265,7 @@ static int rtpoll_work_cb(pa_rtpoll_item *i) { pa_log("Updating sample rate"); wi = pa_smoother_get(s->smoother, pa_timeval_load(&now)); - ri = pa_bytes_to_usec(pa_memblockq_get_read_index(s->memblockq), &s->sink_input->sample_spec); + ri = pa_bytes_to_usec((uint64_t) pa_memblockq_get_read_index(s->memblockq), &s->sink_input->sample_spec); if (PA_MSGOBJECT(s->sink_input->sink)->process_msg(PA_MSGOBJECT(s->sink_input->sink), PA_SINK_MESSAGE_GET_LATENCY, &sink_delay, 0, NULL) < 0) sink_delay = 0; @@ -291,7 +291,7 @@ static int rtpoll_work_cb(pa_rtpoll_item *i) { fix = latency - s->intended_latency; /* How many samples is this per second? */ - fix_samples = fix * s->sink_input->thread_info.sample_spec.rate / RATE_UPDATE_INTERVAL; + fix_samples = (unsigned) (fix * (pa_usec_t) s->sink_input->thread_info.sample_spec.rate / (pa_usec_t) RATE_UPDATE_INTERVAL); /* Check if deviation is in bounds */ if (fix_samples > s->sink_input->sample_spec.rate*.20) @@ -431,7 +431,7 @@ static struct session *session_new(struct userdata *u, const pa_sdp_info *sdp_in s->smoother = pa_smoother_new(PA_USEC_PER_SEC*5, PA_USEC_PER_SEC*2, TRUE, 10); pa_smoother_set_time_offset(s->smoother, pa_timeval_load(&now)); s->last_rate_update = pa_timeval_load(&now); - pa_atomic_store(&s->timestamp, now.tv_sec); + pa_atomic_store(&s->timestamp, (int) now.tv_sec); if ((fd = mcast_socket((const struct sockaddr*) &sdp_info->sa, sdp_info->salen)) < 0) goto fail; @@ -566,7 +566,7 @@ static void sap_event_cb(pa_mainloop_api *m, pa_io_event *e, int fd, pa_io_event } else { struct timeval now; pa_rtclock_get(&now); - pa_atomic_store(&s->timestamp, now.tv_sec); + pa_atomic_store(&s->timestamp, (int) now.tv_sec); pa_sdp_info_destroy(&info); } diff --git a/src/modules/rtp/module-rtp-send.c b/src/modules/rtp/module-rtp-send.c index 1423cbc1..280067a5 100644 --- a/src/modules/rtp/module-rtp-send.c +++ b/src/modules/rtp/module-rtp-send.c @@ -171,7 +171,8 @@ int pa__init(pa_module*m) { const char *dest; uint32_t port = DEFAULT_PORT, mtu; uint32_t ttl = DEFAULT_TTL; - int af, fd = -1, sap_fd = -1; + sa_family_t af; + int fd = -1, sap_fd = -1; pa_source *s; pa_sample_spec ss; pa_channel_map cm; @@ -223,14 +224,14 @@ int pa__init(pa_module*m) { payload = pa_rtp_payload_from_sample_spec(&ss); - mtu = pa_frame_align(DEFAULT_MTU, &ss); + mtu = (uint32_t) pa_frame_align(DEFAULT_MTU, &ss); if (pa_modargs_get_value_u32(ma, "mtu", &mtu) < 0 || mtu < 1 || mtu % pa_frame_size(&ss) != 0) { pa_log("Invalid MTU."); goto fail; } - port = DEFAULT_PORT + ((rand() % 512) << 1); + port = DEFAULT_PORT + ((uint32_t) (rand() % 512) << 1); if (pa_modargs_get_value_u32(ma, "port", &port) < 0 || port < 1 || port > 0xFFFF) { pa_log("port= expects a numerical argument between 1 and 65535."); goto fail; @@ -248,12 +249,12 @@ int pa__init(pa_module*m) { if (inet_pton(AF_INET6, dest, &sa6.sin6_addr) > 0) { sa6.sin6_family = af = AF_INET6; - sa6.sin6_port = htons(port); + sa6.sin6_port = htons((uint16_t) port); sap_sa6 = sa6; sap_sa6.sin6_port = htons(SAP_PORT); } else if (inet_pton(AF_INET, dest, &sa4.sin_addr) > 0) { sa4.sin_family = af = AF_INET; - sa4.sin_port = htons(port); + sa4.sin_port = htons((uint16_t) port); sap_sa4 = sa4; sap_sa4.sin_port = htons(SAP_PORT); } else { @@ -266,7 +267,7 @@ int pa__init(pa_module*m) { goto fail; } - if (connect(fd, af == AF_INET ? (struct sockaddr*) &sa4 : (struct sockaddr*) &sa6, af == AF_INET ? sizeof(sa4) : sizeof(sa6)) < 0) { + if (connect(fd, af == AF_INET ? (struct sockaddr*) &sa4 : (struct sockaddr*) &sa6, (socklen_t) (af == AF_INET ? sizeof(sa4) : sizeof(sa6))) < 0) { pa_log("connect() failed: %s", pa_cstrerror(errno)); goto fail; } @@ -276,7 +277,7 @@ int pa__init(pa_module*m) { goto fail; } - if (connect(sap_fd, af == AF_INET ? (struct sockaddr*) &sap_sa4 : (struct sockaddr*) &sap_sa6, af == AF_INET ? sizeof(sap_sa4) : sizeof(sap_sa6)) < 0) { + if (connect(sap_fd, af == AF_INET ? (struct sockaddr*) &sap_sa4 : (struct sockaddr*) &sap_sa6, (socklen_t) (af == AF_INET ? sizeof(sap_sa4) : sizeof(sap_sa6))) < 0) { pa_log("connect() failed: %s", pa_cstrerror(errno)); goto fail; } @@ -354,7 +355,7 @@ int pa__init(pa_module*m) { p = pa_sdp_build(af, af == AF_INET ? (void*) &((struct sockaddr_in*) &sa_dst)->sin_addr : (void*) &((struct sockaddr_in6*) &sa_dst)->sin6_addr, af == AF_INET ? (void*) &sa4.sin_addr : (void*) &sa6.sin6_addr, - n, port, payload, &ss); + n, (uint16_t) port, payload, &ss); pa_xfree(n); diff --git a/src/modules/rtp/rtp.c b/src/modules/rtp/rtp.c index 5a33ebc2..88351010 100644 --- a/src/modules/rtp/rtp.c +++ b/src/modules/rtp/rtp.c @@ -50,7 +50,7 @@ pa_rtp_context* pa_rtp_context_init_send(pa_rtp_context *c, int fd, uint32_t ssr c->sequence = (uint16_t) (rand()*rand()); c->timestamp = 0; c->ssrc = ssrc ? ssrc : (uint32_t) (rand()*rand()); - c->payload = payload & 127; + c->payload = (uint8_t) (payload & 127U); c->frame_size = frame_size; pa_memchunk_reset(&c->memchunk); @@ -99,7 +99,8 @@ int pa_rtp_send(pa_rtp_context *c, size_t size, pa_memblockq *q) { if (r < 0 || n >= size || iov_idx >= MAX_IOVECS) { uint32_t header[3]; struct msghdr m; - int k, i; + ssize_t k; + int i; if (n > 0) { header[0] = htonl(((uint32_t) 2 << 30) | ((uint32_t) c->payload << 16) | ((uint32_t) c->sequence)); @@ -112,7 +113,7 @@ int pa_rtp_send(pa_rtp_context *c, size_t size, pa_memblockq *q) { m.msg_name = NULL; m.msg_namelen = 0; m.msg_iov = iov; - m.msg_iovlen = iov_idx; + m.msg_iovlen = (size_t) iov_idx; m.msg_control = NULL; m.msg_controllen = 0; m.msg_flags = 0; @@ -128,7 +129,7 @@ int pa_rtp_send(pa_rtp_context *c, size_t size, pa_memblockq *q) { } else k = 0; - c->timestamp += n/c->frame_size; + c->timestamp += (unsigned) (n/c->frame_size); if (k < 0) { if (errno != EAGAIN && errno != EINTR) /* If the queue is full, just ignore it */ @@ -162,7 +163,7 @@ int pa_rtp_recv(pa_rtp_context *c, pa_memchunk *chunk, pa_mempool *pool) { struct msghdr m; struct iovec iov; uint32_t header; - int cc; + unsigned cc; ssize_t r; pa_assert(c); @@ -197,7 +198,7 @@ int pa_rtp_recv(pa_rtp_context *c, pa_memchunk *chunk, pa_mempool *pool) { chunk->index = c->memchunk.index; iov.iov_base = (uint8_t*) pa_memblock_acquire(chunk->memblock) + chunk->index; - iov.iov_len = size; + iov.iov_len = (size_t) size; m.msg_name = NULL; m.msg_namelen = 0; @@ -246,16 +247,16 @@ int pa_rtp_recv(pa_rtp_context *c, pa_memchunk *chunk, pa_mempool *pool) { } cc = (header >> 24) & 0xF; - c->payload = (header >> 16) & 127; - c->sequence = header & 0xFFFF; + c->payload = (uint8_t) ((header >> 16) & 127U); + c->sequence = (uint16_t) (header & 0xFFFFU); - if (12 + cc*4 > size) { + if (12 + cc*4 > (unsigned) size) { pa_log_warn("RTP packet too short. (CSRC)"); goto fail; } chunk->index += 12 + cc*4; - chunk->length = size - 12 + cc*4; + chunk->length = (size_t) size - 12 + cc*4; if (chunk->length % c->frame_size != 0) { pa_log_warn("Bad RTP packet size."); diff --git a/src/modules/rtp/sap.c b/src/modules/rtp/sap.c index 5d9b58fa..b0c95aa5 100644 --- a/src/modules/rtp/sap.c +++ b/src/modules/rtp/sap.c @@ -76,7 +76,7 @@ int pa_sap_send(pa_sap_context *c, pa_bool_t goodbye) { socklen_t salen = sizeof(sa_buf); struct iovec iov[4]; struct msghdr m; - int k; + ssize_t k; if (getsockname(c->fd, sa, &salen) < 0) { pa_log("getsockname() failed: %s\n", pa_cstrerror(errno)); @@ -94,7 +94,7 @@ int pa_sap_send(pa_sap_context *c, pa_bool_t goodbye) { iov[0].iov_len = sizeof(header); iov[1].iov_base = sa->sa_family == AF_INET ? (void*) &((struct sockaddr_in*) sa)->sin_addr : (void*) &((struct sockaddr_in6*) sa)->sin6_addr; - iov[1].iov_len = sa->sa_family == AF_INET ? 4 : 16; + iov[1].iov_len = sa->sa_family == AF_INET ? 4U : 16U; iov[2].iov_base = (char*) MIME_TYPE; iov[2].iov_len = sizeof(MIME_TYPE); @@ -113,7 +113,7 @@ int pa_sap_send(pa_sap_context *c, pa_bool_t goodbye) { if ((k = sendmsg(c->fd, &m, MSG_DONTWAIT)) < 0) pa_log_warn("sendmsg() failed: %s\n", pa_cstrerror(errno)); - return k; + return (int) k; } pa_sap_context* pa_sap_context_init_recv(pa_sap_context *c, int fd) { @@ -128,10 +128,10 @@ pa_sap_context* pa_sap_context_init_recv(pa_sap_context *c, int fd) { int pa_sap_recv(pa_sap_context *c, pa_bool_t *goodbye) { struct msghdr m; struct iovec iov; - int size, k; + int size; char *buf = NULL, *e; uint32_t header; - int six, ac; + unsigned six, ac, k; ssize_t r; pa_assert(c); @@ -142,11 +142,11 @@ int pa_sap_recv(pa_sap_context *c, pa_bool_t *goodbye) { goto fail; } - buf = pa_xnew(char, size+1); + buf = pa_xnew(char, (unsigned) size+1); buf[size] = 0; iov.iov_base = buf; - iov.iov_len = size; + iov.iov_len = (size_t) size; m.msg_name = NULL; m.msg_namelen = 0; @@ -184,21 +184,21 @@ int pa_sap_recv(pa_sap_context *c, pa_bool_t *goodbye) { goto fail; } - six = (header >> 28) & 1; - ac = (header >> 16) & 0xFF; + six = (header >> 28) & 1U; + ac = (header >> 16) & 0xFFU; - k = 4 + (six ? 16 : 4) + ac*4; - if (size < k) { + k = 4 + (six ? 16U : 4U) + ac*4U; + if ((unsigned) size < k) { pa_log_warn("SAP packet too short (AD)."); goto fail; } e = buf + k; - size -= k; + size -= (int) k; if ((unsigned) size >= sizeof(MIME_TYPE) && !strcmp(e, MIME_TYPE)) { e += sizeof(MIME_TYPE); - size -= sizeof(MIME_TYPE); + size -= (int) sizeof(MIME_TYPE); } else if ((unsigned) size < sizeof(PA_SDP_HEADER)-1 || strncmp(e, PA_SDP_HEADER, sizeof(PA_SDP_HEADER)-1)) { pa_log_warn("Invalid SDP header."); goto fail; @@ -207,7 +207,7 @@ int pa_sap_recv(pa_sap_context *c, pa_bool_t *goodbye) { if (c->sdp_data) pa_xfree(c->sdp_data); - c->sdp_data = pa_xstrndup(e, size); + c->sdp_data = pa_xstrndup(e, (unsigned) size); pa_xfree(buf); *goodbye = !!((header >> 26) & 1); diff --git a/src/modules/rtp/sdp.c b/src/modules/rtp/sdp.c index cef90433..59989e1a 100644 --- a/src/modules/rtp/sdp.c +++ b/src/modules/rtp/sdp.c @@ -55,7 +55,7 @@ char *pa_sdp_build(int af, const void *src, const void *dst, const char *name, u if (!(u = pa_get_user_name(un, sizeof(un)))) u = "-"; - ntp = time(NULL) + 2208988800U; + ntp = (uint32_t) time(NULL) + 2208988800U; pa_assert_se(a = inet_ntop(af, src, buf_src, sizeof(buf_src))); pa_assert_se(a = inet_ntop(af, dst, buf_dst, sizeof(buf_dst))); @@ -99,10 +99,10 @@ static pa_sample_spec *parse_sdp_sample_spec(pa_sample_spec *ss, char *c) { return NULL; if (sscanf(c, "%u/%u", &rate, &channels) == 2) { - ss->rate = rate; - ss->channels = channels; + ss->rate = (uint32_t) rate; + ss->channels = (uint8_t) channels; } else if (sscanf(c, "%u", &rate) == 2) { - ss->rate = rate; + ss->rate = (uint32_t) rate; ss->channels = 1; } else return NULL; -- cgit From dc9b8dce309728b47059b9b44fd3bbd3798667ae Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 20 Aug 2008 03:33:06 +0300 Subject: add a few missing casts --- src/modules/module-combine.c | 4 ++-- src/modules/module-oss.c | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) (limited to 'src/modules') diff --git a/src/modules/module-combine.c b/src/modules/module-combine.c index 9fd12e30..d61d127a 100644 --- a/src/modules/module-combine.c +++ b/src/modules/module-combine.c @@ -233,7 +233,7 @@ static void time_callback(pa_mainloop_api*a, pa_time_event* e, const struct time adjust_rates(u); pa_gettimeofday(&n); - n.tv_sec += u->adjust_time; + n.tv_sec += (time_t) u->adjust_time; u->sink->core->mainloop->time_restart(e, &n); } @@ -1159,7 +1159,7 @@ int pa__init(pa_module*m) { if (u->adjust_time > 0) { struct timeval tv; pa_gettimeofday(&tv); - tv.tv_sec += u->adjust_time; + tv.tv_sec += (time_t) u->adjust_time; u->time_event = m->core->mainloop->time_new(m->core->mainloop, &tv, time_callback, u); } diff --git a/src/modules/module-oss.c b/src/modules/module-oss.c index 3333eb83..23a32549 100644 --- a/src/modules/module-oss.c +++ b/src/modules/module-oss.c @@ -899,7 +899,7 @@ static void thread_func(void *userdata) { ssize_t l; pa_bool_t loop = FALSE, work_done = FALSE; - l = u->out_fragment_size; + l = (ssize_t) u->out_fragment_size; if (u->use_getospace) { audio_buf_info info; @@ -920,14 +920,14 @@ static void thread_func(void *userdata) { /* Round down to multiples of the fragment size, * because OSS needs that (at least some versions * do) */ - l = (l/u->out_fragment_size) * u->out_fragment_size; + l = (l/(ssize_t) u->out_fragment_size) * (ssize_t) u->out_fragment_size; /* Hmm, so poll() signalled us that we can read * something, but GETOSPACE told us there was nothing? * Hmm, make the best of it, try to read some data, to * avoid spinning forever. */ if (l <= 0 && (revents & POLLOUT)) { - l = u->out_fragment_size; + l = (ssize_t) u->out_fragment_size; loop = FALSE; } @@ -1010,7 +1010,7 @@ static void thread_func(void *userdata) { pa_memchunk memchunk; pa_bool_t loop = FALSE, work_done = FALSE; - l = u->in_fragment_size; + l = (ssize_t) u->in_fragment_size; if (u->use_getispace) { audio_buf_info info; @@ -1024,10 +1024,10 @@ static void thread_func(void *userdata) { } } - l = (l/u->in_fragment_size) * u->in_fragment_size; + l = (l/(ssize_t) u->in_fragment_size) * (ssize_t) u->in_fragment_size; if (l <= 0 && (revents & POLLIN)) { - l = u->in_fragment_size; + l = (ssize_t) u->in_fragment_size; loop = FALSE; } -- cgit