mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-10-31 22:25:33 -04:00
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
This commit is contained in:
parent
3334814ebb
commit
2bf4653713
1 changed files with 55 additions and 4 deletions
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue