diff options
author | Arun Raghavan <arun.raghavan@collabora.co.uk> | 2013-08-03 11:39:17 +0530 |
---|---|---|
committer | Arun Raghavan <arun.raghavan@collabora.co.uk> | 2013-08-08 11:58:22 +0530 |
commit | f8f0d4c26bd71214ef2be4027d39480f9eaaae9e (patch) | |
tree | 8e6c33d30e1eac6346f6260e4254995c7f4f3cc2 | |
parent | bc7aaff377d062ef3ebc113313e8391190785fb4 (diff) | |
download | pulseaudio-f8f0d4c26bd71214ef2be4027d39480f9eaaae9e.tar.gz |
sink-input: Don't assert when removing non-existent volume factor
This makes it easier for users of this API to add/updated a volume
factor by doing a _remove_volume_factor() followed by an
add_volume_factor(), rather than having to either remember whether this
is the first set operation or have an API to query whether a factor has
already been set.
-rw-r--r-- | src/pulsecore/sink-input.c | 12 | ||||
-rw-r--r-- | src/pulsecore/sink-input.h | 2 |
2 files changed, 11 insertions, 3 deletions
diff --git a/src/pulsecore/sink-input.c b/src/pulsecore/sink-input.c index c6d540eaf..a27571599 100644 --- a/src/pulsecore/sink-input.c +++ b/src/pulsecore/sink-input.c @@ -1330,7 +1330,9 @@ void pa_sink_input_add_volume_factor(pa_sink_input *i, const char *key, const pa pa_assert_se(pa_asyncmsgq_send(i->sink->asyncmsgq, PA_MSGOBJECT(i), PA_SINK_INPUT_MESSAGE_SET_SOFT_VOLUME, NULL, 0, NULL) == 0); } -void pa_sink_input_remove_volume_factor(pa_sink_input *i, const char *key) { +/* Returns 0 if an entry was removed and -1 if no entry for the given key was + * found. */ +int pa_sink_input_remove_volume_factor(pa_sink_input *i, const char *key) { struct volume_factor_entry *v; pa_sink_input_assert_ref(i); @@ -1338,7 +1340,11 @@ void pa_sink_input_remove_volume_factor(pa_sink_input *i, const char *key) { pa_assert_ctl_context(); pa_assert(PA_SINK_INPUT_IS_LINKED(i->state)); - pa_assert_se(v = pa_hashmap_remove(i->volume_factor_items, key)); + v = pa_hashmap_remove(i->volume_factor_items, key); + + if (!v) + return -1; + volume_factor_entry_free(v); switch (pa_hashmap_size(i->volume_factor_items)) { @@ -1357,6 +1363,8 @@ void pa_sink_input_remove_volume_factor(pa_sink_input *i, const char *key) { /* Copy the new soft_volume to the thread_info struct */ pa_assert_se(pa_asyncmsgq_send(i->sink->asyncmsgq, PA_MSGOBJECT(i), PA_SINK_INPUT_MESSAGE_SET_SOFT_VOLUME, NULL, 0, NULL) == 0); + + return 0; } /* Called from main context */ diff --git a/src/pulsecore/sink-input.h b/src/pulsecore/sink-input.h index 4cf8614e4..da337174f 100644 --- a/src/pulsecore/sink-input.h +++ b/src/pulsecore/sink-input.h @@ -371,7 +371,7 @@ bool pa_sink_input_is_passthrough(pa_sink_input *i); bool pa_sink_input_is_volume_readable(pa_sink_input *i); void pa_sink_input_set_volume(pa_sink_input *i, const pa_cvolume *volume, bool save, bool absolute); void pa_sink_input_add_volume_factor(pa_sink_input *i, const char *key, const pa_cvolume *volume_factor); -void pa_sink_input_remove_volume_factor(pa_sink_input *i, const char *key); +int pa_sink_input_remove_volume_factor(pa_sink_input *i, const char *key); pa_cvolume *pa_sink_input_get_volume(pa_sink_input *i, pa_cvolume *volume, bool absolute); void pa_sink_input_set_mute(pa_sink_input *i, bool mute, bool save); |