From bb5823a3c9c137a2f2fa45c27e7f7322d6a6eb28 Mon Sep 17 00:00:00 2001 From: "Igor V. Kovalenko" Date: Mon, 9 May 2022 21:43:25 +0300 Subject: [PATCH] module-suspend-on-idle: Allow suspending a sink when the monitor source becomes idle When monitor source becomes idle it may happen that monitored sink has no uncorked inputs anymore and can now be suspended. To allow this, detect if state is changed for monitor source and check state of monitored sink instead. This change allows pulseaudio to suspend devices when pavucontrol volume meters are disabled and corresponding peaks resampled streams are corked. Part-of: --- src/modules/module-suspend-on-idle.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/modules/module-suspend-on-idle.c b/src/modules/module-suspend-on-idle.c index 08a1b1db8..498b09449 100644 --- a/src/modules/module-suspend-on-idle.c +++ b/src/modules/module-suspend-on-idle.c @@ -385,8 +385,17 @@ static pa_hook_result_t device_state_changed_hook_cb(pa_core *c, pa_object *o, s pa_object_assert_ref(o); pa_assert(u); - if (!(d = pa_hashmap_get(u->device_infos, o))) - return PA_HOOK_OK; + if (!(d = pa_hashmap_get(u->device_infos, o))) { + /* We never suspend monitor sources, therefore they are not in the map. + * Still, when monitor source becomes idle it may happen that monitored + * sink has no uncorked inputs anymore and can now be suspended. + */ + if (pa_source_isinstance(o) && PA_SOURCE(o)->monitor_of) { + pa_log_debug("State of monitor source '%s' has changed, checking state of monitored sink", PA_SOURCE(o)->name); + return device_state_changed_hook_cb(c, PA_OBJECT(PA_SOURCE(o)->monitor_of), u); + } else + return PA_HOOK_OK; + } if (pa_sink_isinstance(o)) { pa_sink *s = PA_SINK(o);