summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/modules/module-rescue-streams.c59
1 files changed, 55 insertions, 4 deletions
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 <pulse/xmalloc.h>
#include <pulsecore/core.h>
+#include <pulsecore/sink-input.h>
+#include <pulsecore/source-output.h>
#include <pulsecore/modargs.h>
#include <pulsecore/log.h>
#include <pulsecore/namereg.h>
@@ -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);
}