sink, source: Assign to s->muted from only one place

Forcing all mute changes to go through set_mute() makes it easier to
check where the muted field is changed, and it also allows us to have
only one place where notifications for changed mute are sent.
This commit is contained in:
Tanu Kaskinen 2014-04-15 13:56:10 +03:00
parent dbd2a8f851
commit e4a7625ba8
7 changed files with 87 additions and 64 deletions

View file

@ -508,7 +508,7 @@ void pa_sink_set_write_volume_callback(pa_sink *s, pa_sink_cb_t cb) {
pa_subscription_post(s->core, PA_SUBSCRIPTION_EVENT_SINK|PA_SUBSCRIPTION_EVENT_CHANGE, s->index);
}
void pa_sink_set_get_mute_callback(pa_sink *s, pa_sink_cb_t cb) {
void pa_sink_set_get_mute_callback(pa_sink *s, pa_sink_get_mute_cb_t cb) {
pa_assert(s);
s->get_mute = cb;
@ -2228,21 +2228,15 @@ bool pa_sink_get_mute(pa_sink *s, bool force_refresh) {
pa_assert_ctl_context();
pa_assert(PA_SINK_IS_LINKED(s->state));
if (s->refresh_muted || force_refresh) {
bool old_muted = s->muted;
if ((s->refresh_muted || force_refresh) && s->get_mute) {
bool mute;
if (!(s->flags & PA_SINK_DEFERRED_VOLUME) && s->get_mute)
s->get_mute(s);
pa_assert_se(pa_asyncmsgq_send(s->asyncmsgq, PA_MSGOBJECT(s), PA_SINK_MESSAGE_GET_MUTE, NULL, 0, NULL) == 0);
if (old_muted != s->muted) {
s->save_muted = true;
pa_subscription_post(s->core, PA_SUBSCRIPTION_EVENT_SINK|PA_SUBSCRIPTION_EVENT_CHANGE, s->index);
/* Make sure the soft mute status stays in sync */
pa_assert_se(pa_asyncmsgq_send(s->asyncmsgq, PA_MSGOBJECT(s), PA_SINK_MESSAGE_SET_MUTE, NULL, 0, NULL) == 0);
if (s->flags & PA_SINK_DEFERRED_VOLUME) {
if (pa_asyncmsgq_send(s->asyncmsgq, PA_MSGOBJECT(s), PA_SINK_MESSAGE_GET_MUTE, &mute, 0, NULL) >= 0)
pa_sink_mute_changed(s, mute);
} else {
if (s->get_mute(s, &mute) >= 0)
pa_sink_mute_changed(s, mute);
}
}
@ -2750,7 +2744,7 @@ int pa_sink_process_msg(pa_msgobject *o, int code, void *userdata, int64_t offse
case PA_SINK_MESSAGE_GET_MUTE:
if (s->flags & PA_SINK_DEFERRED_VOLUME && s->get_mute)
s->get_mute(s);
return s->get_mute(s, userdata);
return 0;