From 2bf46537136a73220771c899e86a52b1ee9b22d8 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Sun, 13 Aug 2006 20:45:19 +0000 Subject: extend module-rescue-streams to move also source outputs when a source dies git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1254 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/modules/module-rescue-streams.c | 59 ++++++++++++++++++++++++++++++++++--- 1 file changed, 55 insertions(+), 4 deletions(-) (limited to 'src/modules') diff --git a/src/modules/module-rescue-streams.c b/src/modules/module-rescue-streams.c index 0e3946b1..5700ef43 100644 --- a/src/modules/module-rescue-streams.c +++ b/src/modules/module-rescue-streams.c @@ -26,6 +26,8 @@ #include #include +#include +#include #include #include #include @@ -40,7 +42,11 @@ static const char* const valid_modargs[] = { NULL, }; -static pa_hook_result_t hook_callback(pa_core *c, pa_sink *sink, void* userdata) { +struct userdata { + pa_hook_slot *sink_slot, *source_slot; +}; + +static pa_hook_result_t sink_hook_callback(pa_core *c, pa_sink *sink, void* userdata) { pa_sink_input *i; pa_sink *target; @@ -72,8 +78,41 @@ static pa_hook_result_t hook_callback(pa_core *c, pa_sink *sink, void* userdata) return PA_HOOK_OK; } +static pa_hook_result_t source_hook_callback(pa_core *c, pa_source *source, void* userdata) { + pa_source_output *o; + pa_source *target; + + assert(c); + assert(source); + + if (!pa_idxset_size(source->outputs)) { + pa_log_debug(__FILE__": No source outputs to move away."); + return PA_HOOK_OK; + } + + if (!(target = pa_namereg_get(c, NULL, PA_NAMEREG_SOURCE, 0))) { + pa_log_info(__FILE__": No evacuation source found."); + return PA_HOOK_OK; + } + + assert(target != source); + + while ((o = pa_idxset_first(source->outputs, NULL))) { + if (pa_source_output_move_to(o, target) < 0) { + pa_log_warn(__FILE__": Failed to move source output %u \"%s\" to %s.", o->index, o->name, target->name); + return PA_HOOK_OK; + } + + pa_log_info(__FILE__": Sucessfully moved source output %u \"%s\" to %s.", o->index, o->name, target->name); + } + + + return PA_HOOK_OK; +} + int pa__init(pa_core *c, pa_module*m) { pa_modargs *ma = NULL; + struct userdata *u; assert(c); assert(m); @@ -83,16 +122,28 @@ int pa__init(pa_core *c, pa_module*m) { return -1; } - m->userdata = pa_hook_connect(&c->hook_sink_disconnect, (pa_hook_cb_t) hook_callback, NULL); + m->userdata = u = pa_xnew(struct userdata, 1); + u->sink_slot = pa_hook_connect(&c->hook_sink_disconnect, (pa_hook_cb_t) sink_hook_callback, NULL); + u->source_slot = pa_hook_connect(&c->hook_source_disconnect, (pa_hook_cb_t) source_hook_callback, NULL); pa_modargs_free(ma); return 0; } void pa__done(pa_core *c, pa_module*m) { + struct userdata *u; + assert(c); assert(m); - if (m->userdata) - pa_hook_slot_free((pa_hook_slot*) m->userdata); + if (!m->userdata) + return; + + u = m->userdata; + if (u->sink_slot) + pa_hook_slot_free(u->sink_slot); + if (u->source_slot) + pa_hook_slot_free(u->source_slot); + + pa_xfree(u); } -- cgit