Suspend immediately by zeroing timeout value. This helps reconfigure the sinks/sources to new sampling frequency between two tracks in a playlist. This behavior is not suitable when reconfiguration latency is large. We don't enable it for network devices. This mode is not the default, it is only enabled by setting the params suspend-asap parameter Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart at intel.com> --- src/modules/module-suspend-on-idle.c | 22 ++++++++++++++++++++++ 1 files changed, 22 insertions(+), 0 deletions(-) diff --git a/src/modules/module-suspend-on-idle.c b/src/modules/module-suspend-on-idle.c index cfb7879..01a9aa1 100644 --- a/src/modules/module-suspend-on-idle.c +++ b/src/modules/module-suspend-on-idle.c @@ -41,9 +41,13 @@ PA_MODULE_AUTHOR("Lennart Poettering"); PA_MODULE_DESCRIPTION("When a sink/source is idle for too long, suspend it"); PA_MODULE_VERSION(PACKAGE_VERSION); PA_MODULE_LOAD_ONCE(TRUE); +PA_MODULE_USAGE( + "timeout=<default value for timeout>" + "suspend-asap=<suspend non-network/passthrough/local devices immediately?>"); static const char* const valid_modargs[] = { "timeout", + "suspend-asap", NULL, }; @@ -70,6 +74,8 @@ struct userdata { *source_output_move_finish_slot, *sink_input_state_changed_slot, *source_output_state_changed_slot; + + pa_bool_t suspend_asap; }; struct device_info { @@ -112,6 +118,15 @@ static void restart(struct device_info *d) { if (!s || pa_atou(s, &timeout) < 0) timeout = d->userdata->timeout; + if (d->userdata->suspend_asap) + /* suspend non-network, local and passthrough sinks/sources */ + if (((d->sink) && + (!(d->sink->flags&PA_SINK_NETWORK) || + (d->sink->flags&PA_SINK_PASSTHROUGH))) || + ((d->source) && + (!(d->source->flags&PA_SOURCE_NETWORK)))) + timeout = 0; + pa_core_rttime_restart(d->userdata->core, d->time_event, now + timeout * PA_USEC_PER_SEC); if (d->sink) @@ -416,6 +431,7 @@ int pa__init(pa_module*m) { pa_modargs *ma = NULL; struct userdata *u; uint32_t timeout = 5; + pa_bool_t suspend_asap = 0; /* keep regular suspend behavior unless told otherwise */ uint32_t idx; pa_sink *sink; pa_source *source; @@ -432,9 +448,15 @@ int pa__init(pa_module*m) { goto fail; } + if (pa_modargs_get_value_boolean(ma, "suspend-asap", &suspend_asap) < 0) { + pa_log("Failed to parse suspend-asap value."); + goto fail; + } + m->userdata = u = pa_xnew(struct userdata, 1); u->core = m->core; u->timeout = timeout; + u->suspend_asap = suspend_asap; u->device_infos = pa_hashmap_new(pa_idxset_trivial_hash_func, pa_idxset_trivial_compare_func); for (sink = pa_idxset_first(m->core->sinks, &idx); sink; sink = pa_idxset_next(m->core->sinks, &idx)) -- 1.7.4