#include <pulsecore/source-output.h>
#include <pulsecore/modargs.h>
#include <pulsecore/log.h>
-#include <pulsecore/namereg.h>
#include "module-suspend-on-idle-symdef.h"
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_LOAD_ONCE(true);
+PA_MODULE_USAGE("timeout=<timeout>");
static const char* const valid_modargs[] = {
"timeout",
if (d->sink && pa_sink_check_suspend(d->sink) <= 0 && !(d->sink->suspend_cause & PA_SUSPEND_IDLE)) {
pa_log_info("Sink %s idle for too long, suspending ...", d->sink->name);
- pa_sink_suspend(d->sink, TRUE, PA_SUSPEND_IDLE);
+ pa_sink_suspend(d->sink, true, PA_SUSPEND_IDLE);
+ pa_core_maybe_vacuum(d->userdata->core);
}
if (d->source && pa_source_check_suspend(d->source) <= 0 && !(d->source->suspend_cause & PA_SUSPEND_IDLE)) {
pa_log_info("Source %s idle for too long, suspending ...", d->source->name);
- pa_source_suspend(d->source, TRUE, PA_SUSPEND_IDLE);
+ pa_source_suspend(d->source, true, PA_SUSPEND_IDLE);
+ pa_core_maybe_vacuum(d->userdata->core);
}
}
d->userdata->core->mainloop->time_restart(d->time_event, NULL);
if (d->sink) {
- pa_sink_suspend(d->sink, FALSE, PA_SUSPEND_IDLE);
-
- pa_log_debug("Sink %s becomes busy.", d->sink->name);
+ pa_log_debug("Sink %s becomes busy, resuming.", d->sink->name);
+ pa_sink_suspend(d->sink, false, PA_SUSPEND_IDLE);
}
if (d->source) {
- pa_source_suspend(d->source, FALSE, PA_SUSPEND_IDLE);
-
- pa_log_debug("Source %s becomes busy.", d->source->name);
+ pa_log_debug("Source %s becomes busy, resuming.", d->source->name);
+ pa_source_suspend(d->source, false, PA_SUSPEND_IDLE);
}
}
pa_assert(data);
pa_assert(u);
+ /* We need to resume the audio device here even for
+ * PA_SINK_INPUT_START_CORKED, since we need the device parameters
+ * to be fully available while the stream is set up. */
+
if ((d = pa_hashmap_get(u->device_infos, data->sink)))
resume(d);
static pa_hook_result_t sink_input_move_finish_hook_cb(pa_core *c, pa_sink_input *s, struct userdata *u) {
struct device_info *d;
+ pa_sink_input_state_t state;
pa_assert(c);
pa_sink_input_assert_ref(s);
pa_assert(u);
+ state = pa_sink_input_get_state(s);
+ if (state != PA_SINK_INPUT_RUNNING && state != PA_SINK_INPUT_DRAINED)
+ return PA_HOOK_OK;
+
if ((d = pa_hashmap_get(u->device_infos, s->sink)))
resume(d);
pa_source_output_assert_ref(s);
pa_assert(u);
+ if (pa_source_output_get_state(s) != PA_SOURCE_OUTPUT_RUNNING)
+ return PA_HOOK_OK;
+
if (s->source->monitor_of)
d = pa_hashmap_get(u->device_infos, s->source->monitor_of);
else
static pa_hook_result_t sink_input_state_changed_hook_cb(pa_core *c, pa_sink_input *s, struct userdata *u) {
struct device_info *d;
pa_sink_input_state_t state;
+
pa_assert(c);
pa_sink_input_assert_ref(s);
pa_assert(u);
}
static pa_hook_result_t source_output_state_changed_hook_cb(pa_core *c, pa_source_output *s, struct userdata *u) {
- pa_source_output_state_t state;
-
pa_assert(c);
pa_source_output_assert_ref(s);
pa_assert(u);
- state = pa_source_output_get_state(s);
-
- if (state == PA_SOURCE_OUTPUT_RUNNING) {
+ if (pa_source_output_get_state(s) == PA_SOURCE_OUTPUT_RUNNING) {
struct device_info *d;
if (s->source->monitor_of)
pa_sink *s = PA_SINK(o);
pa_sink_state_t state = pa_sink_get_state(s);
- if (pa_sink_check_suspend(s) <= 0) {
-
+ if (pa_sink_check_suspend(s) <= 0)
if (PA_SINK_IS_OPENED(state))
restart(d);
- }
-
} else if (pa_source_isinstance(o)) {
pa_source *s = PA_SOURCE(o);
pa_source_state_t state = pa_source_get_state(s);
- if (pa_source_check_suspend(s) <= 0) {
-
+ if (pa_source_check_suspend(s) <= 0)
if (PA_SOURCE_IS_OPENED(state))
restart(d);
- }
}
return PA_HOOK_OK;
u->timeout = timeout;
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))
+ PA_IDXSET_FOREACH(sink, m->core->sinks, idx)
device_new_hook_cb(m->core, PA_OBJECT(sink), u);
- for (source = pa_idxset_first(m->core->sources, &idx); source; source = pa_idxset_next(m->core->sources, &idx))
+ PA_IDXSET_FOREACH(source, m->core->sources, idx)
device_new_hook_cb(m->core, PA_OBJECT(source), u);
u->sink_new_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SINK_PUT], PA_HOOK_NORMAL, (pa_hook_cb_t) device_new_hook_cb, u);
void pa__done(pa_module*m) {
struct userdata *u;
- struct device_info *d;
pa_assert(m);
if (u->source_output_state_changed_slot)
pa_hook_slot_free(u->source_output_state_changed_slot);
- while ((d = pa_hashmap_steal_first(u->device_infos)))
- device_info_free(d);
-
- pa_hashmap_free(u->device_infos, NULL, NULL);
+ pa_hashmap_free(u->device_infos, (pa_free_cb_t) device_info_free);
pa_xfree(u);
}