[pulseaudio-commits] r1254 - /trunk/src/modules/module-rescue-streams.c

svnmailer-noreply at 0pointer.de svnmailer-noreply at 0pointer.de
Sun Aug 13 13:45:19 PDT 2006


Author: lennart
Date: Sun Aug 13 22:45:19 2006
New Revision: 1254

URL: http://0pointer.de/cgi-bin/viewcvs.cgi?rev=1254&root=pulseaudio&view=rev
Log:
extend module-rescue-streams to move also source outputs when a source dies

Modified:
    trunk/src/modules/module-rescue-streams.c

Modified: trunk/src/modules/module-rescue-streams.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/modules/module-rescue-streams.c?rev=1254&root=pulseaudio&r1=1253&r2=1254&view=diff
==============================================================================
--- trunk/src/modules/module-rescue-streams.c (original)
+++ trunk/src/modules/module-rescue-streams.c Sun Aug 13 22:45:19 2006
@@ -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 @@
     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 @@
     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 @@
         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);
 }




More information about the pulseaudio-commits mailing list