From b3675c28fa1c4bc4707e5700bc618240fc10e212 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Sat, 21 Mar 2009 02:45:31 +0100 Subject: add functions that modules can call whenever they now the volume changed --- src/pulsecore/sink.c | 26 ++++++++++++++++++++++++++ src/pulsecore/sink.h | 2 ++ src/pulsecore/source.c | 27 ++++++++++++++++++++++++++- src/pulsecore/source.h | 2 ++ 4 files changed, 56 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/pulsecore/sink.c b/src/pulsecore/sink.c index c725595f..147926a0 100644 --- a/src/pulsecore/sink.c +++ b/src/pulsecore/sink.c @@ -1134,6 +1134,19 @@ const pa_cvolume *pa_sink_get_volume(pa_sink *s, pa_bool_t force_refresh) { return &s->virtual_volume; } +/* Called from main thread */ +void pa_sink_volume_changed(pa_sink *s, const pa_cvolume *new_volume) { + pa_sink_assert_ref(s); + + /* The sink implementor may call this if the volume changed to make sure everyone is notified */ + + if (pa_cvolume_equal(&s->virtual_volume, new_volume)) + return; + + s->virtual_volume = *new_volume; + pa_subscription_post(s->core, PA_SUBSCRIPTION_EVENT_SINK|PA_SUBSCRIPTION_EVENT_CHANGE, s->index); +} + /* Called from main thread */ void pa_sink_set_mute(pa_sink *s, pa_bool_t mute) { pa_bool_t old_muted; @@ -1173,6 +1186,19 @@ pa_bool_t pa_sink_get_mute(pa_sink *s, pa_bool_t force_refresh) { return s->muted; } +/* Called from main thread */ +void pa_sink_mute_changed(pa_sink *s, pa_bool_t new_muted) { + pa_sink_assert_ref(s); + + /* The sink implementor may call this if the volume changed to make sure everyone is notified */ + + if (s->muted == new_muted) + return; + + s->muted = new_muted; + pa_subscription_post(s->core, PA_SUBSCRIPTION_EVENT_SINK|PA_SUBSCRIPTION_EVENT_CHANGE, s->index); +} + /* Called from main thread */ pa_bool_t pa_sink_update_proplist(pa_sink *s, pa_update_mode_t mode, pa_proplist *p) { diff --git a/src/pulsecore/sink.h b/src/pulsecore/sink.h index 0d33679f..448f2805 100644 --- a/src/pulsecore/sink.h +++ b/src/pulsecore/sink.h @@ -224,6 +224,8 @@ void pa_sink_detach(pa_sink *s); void pa_sink_attach(pa_sink *s); void pa_sink_set_soft_volume(pa_sink *s, const pa_cvolume *volume); +void pa_sink_volume_changed(pa_sink *s, const pa_cvolume *new_volume); +void pa_sink_mute_changed(pa_sink *s, pa_bool_t new_muted); pa_bool_t pa_device_init_description(pa_proplist *p); pa_bool_t pa_device_init_icon(pa_proplist *p, pa_bool_t is_sink); diff --git a/src/pulsecore/source.c b/src/pulsecore/source.c index cc6dfc40..ac1ef1e7 100644 --- a/src/pulsecore/source.c +++ b/src/pulsecore/source.c @@ -674,6 +674,19 @@ const pa_cvolume *pa_source_get_volume(pa_source *s, pa_bool_t force_refresh) { return &s->virtual_volume; } +/* Called from main thread */ +void pa_source_volume_changed(pa_source *s, const pa_cvolume *new_volume) { + pa_source_assert_ref(s); + + /* The source implementor may call this if the volume changed to make sure everyone is notified */ + + if (pa_cvolume_equal(&s->virtual_volume, new_volume)) + return; + + s->virtual_volume = *new_volume; + pa_subscription_post(s->core, PA_SUBSCRIPTION_EVENT_SOURCE|PA_SUBSCRIPTION_EVENT_CHANGE, s->index); +} + /* Called from main thread */ void pa_source_set_mute(pa_source *s, pa_bool_t mute) { pa_bool_t old_muted; @@ -695,7 +708,6 @@ void pa_source_set_mute(pa_source *s, pa_bool_t mute) { /* Called from main thread */ pa_bool_t pa_source_get_mute(pa_source *s, pa_bool_t force_refresh) { - pa_source_assert_ref(s); pa_assert(PA_SOURCE_IS_LINKED(s->state)); @@ -714,6 +726,19 @@ pa_bool_t pa_source_get_mute(pa_source *s, pa_bool_t force_refresh) { return s->muted; } +/* Called from main thread */ +void pa_source_mute_changed(pa_source *s, pa_bool_t new_muted) { + pa_source_assert_ref(s); + + /* The source implementor may call this if the mute state changed to make sure everyone is notified */ + + if (s->muted == new_muted) + return; + + s->muted = new_muted; + pa_subscription_post(s->core, PA_SUBSCRIPTION_EVENT_SOURCE|PA_SUBSCRIPTION_EVENT_CHANGE, s->index); +} + /* Called from main thread */ pa_bool_t pa_source_update_proplist(pa_source *s, pa_update_mode_t mode, pa_proplist *p) { pa_source_assert_ref(s); diff --git a/src/pulsecore/source.h b/src/pulsecore/source.h index 26471de0..68bf2f06 100644 --- a/src/pulsecore/source.h +++ b/src/pulsecore/source.h @@ -211,6 +211,8 @@ void pa_source_detach(pa_source *s); void pa_source_attach(pa_source *s); void pa_source_set_soft_volume(pa_source *s, const pa_cvolume *volume); +void pa_source_volume_changed(pa_source *s, const pa_cvolume *new_volume); +void pa_source_mute_changed(pa_source *s, pa_bool_t new_muted); int pa_source_sync_suspend(pa_source *s); -- cgit