source: move the streams to the default_source when the source unlink

When a source is unlinked, all streams of this source are moved to
default_source, this action is implemented in the core rather than
modules now.

And after this change, the module-rescue-streams is not needed, but
for backward compatibility, we keep it as a dummy module.

Signed-off-by: Hui Wang <hui.wang@canonical.com>
This commit is contained in:
Hui Wang 2019-12-10 16:26:34 +08:00 committed by Tanu Kaskinen
parent 976a366c9f
commit 5e0d5a8682
12 changed files with 35 additions and 267 deletions

View file

@ -65,7 +65,7 @@ PA_MODULE_USAGE(
"restore_volume=<Save/restore volumes?> "
"restore_muted=<Save/restore muted states?> "
"on_hotplug=<This argument is obsolete, please remove it from configuration> "
"on_rescue=<When device becomes unavailable, recheck streams?> "
"on_rescue=<This argument is obsolete, please remove it from configuration> "
"fallback_table=<filename>");
#define SAVE_INTERVAL (10 * PA_USEC_PER_SEC)
@ -95,7 +95,6 @@ struct userdata {
*sink_input_fixate_hook_slot,
*source_output_new_hook_slot,
*source_output_fixate_hook_slot,
*source_unlink_hook_slot,
*connection_unlink_hook_slot;
pa_time_event *save_time_event;
pa_database* database;
@ -103,7 +102,6 @@ struct userdata {
bool restore_device:1;
bool restore_volume:1;
bool restore_muted:1;
bool on_rescue:1;
pa_native_protocol *protocol;
pa_idxset *subscribed;
@ -1641,57 +1639,6 @@ static pa_hook_result_t source_output_fixate_hook_callback(pa_core *c, pa_source
return PA_HOOK_OK;
}
static pa_hook_result_t source_unlink_hook_callback(pa_core *c, pa_source *source, struct userdata *u) {
pa_source_output *so;
uint32_t idx;
pa_assert(c);
pa_assert(source);
pa_assert(u);
pa_assert(u->on_rescue && u->restore_device);
/* There's no point in doing anything if the core is shut down anyway */
if (c->state == PA_CORE_SHUTDOWN)
return PA_HOOK_OK;
PA_IDXSET_FOREACH(so, source->outputs, idx) {
char *name;
struct entry *e;
if (so->direct_on_input)
continue;
if (!so->source)
continue;
/* Skip this source output if it is connecting a filter source to
* the master */
if (so->destination_source)
continue;
if (!(name = pa_proplist_get_stream_group(so->proplist, "source-output", IDENTIFICATION_PROPERTY)))
continue;
if ((e = entry_read(u, name))) {
if (e->device_valid) {
pa_source *d;
if ((d = pa_namereg_get(c, e->device, PA_NAMEREG_SOURCE)) &&
d != source &&
PA_SOURCE_IS_LINKED(d->state))
pa_source_output_move_to(so, d, true);
}
entry_free(e);
}
pa_xfree(name);
}
return PA_HOOK_OK;
}
static int fill_db(struct userdata *u, const char *filename) {
FILE *f;
int n = 0;
@ -2271,7 +2218,8 @@ int pa__init(pa_module*m) {
pa_sink_input *si;
pa_source_output *so;
uint32_t idx;
bool restore_device = true, restore_volume = true, restore_muted = true, on_rescue = true;
bool restore_device = true, restore_volume = true, restore_muted = true;
#ifdef HAVE_DBUS
pa_datum key;
bool done;
@ -2286,14 +2234,14 @@ int pa__init(pa_module*m) {
if (pa_modargs_get_value_boolean(ma, "restore_device", &restore_device) < 0 ||
pa_modargs_get_value_boolean(ma, "restore_volume", &restore_volume) < 0 ||
pa_modargs_get_value_boolean(ma, "restore_muted", &restore_muted) < 0 ||
pa_modargs_get_value_boolean(ma, "on_rescue", &on_rescue) < 0) {
pa_log("restore_device=, restore_volume=, restore_muted= and on_rescue= expect boolean arguments");
pa_modargs_get_value_boolean(ma, "restore_muted", &restore_muted) < 0) {
pa_log("restore_device=, restore_volume= and restore_muted= expect boolean arguments");
goto fail;
}
if (pa_modargs_get_value(ma, "on_hotplug", NULL) != NULL)
pa_log("on_hotplug is an obsolete argument, please remove it from your configuration");
if (pa_modargs_get_value(ma, "on_hotplug", NULL) != NULL ||
pa_modargs_get_value(ma, "on_rescue", NULL) != NULL)
pa_log("on_hotplug and on_rescue are obsolete arguments, please remove them from your configuration");
if (!restore_muted && !restore_volume && !restore_device)
pa_log_warn("Neither restoring volume, nor restoring muted, nor restoring device enabled!");
@ -2304,7 +2252,6 @@ int pa__init(pa_module*m) {
u->restore_device = restore_device;
u->restore_volume = restore_volume;
u->restore_muted = restore_muted;
u->on_rescue = on_rescue;
u->subscribed = pa_idxset_new(pa_idxset_trivial_hash_func, pa_idxset_trivial_compare_func);
u->protocol = pa_native_protocol_get(m->core);
@ -2320,11 +2267,6 @@ int pa__init(pa_module*m) {
pa_module_hook_connect(m, &m->core->hooks[PA_CORE_HOOK_SOURCE_OUTPUT_NEW], PA_HOOK_EARLY, (pa_hook_cb_t) source_output_new_hook_callback, u);
}
if (restore_device && on_rescue) {
/* A little bit earlier than module-intended-roles, module-rescue-streams, ... */
pa_module_hook_connect(m, &m->core->hooks[PA_CORE_HOOK_SOURCE_UNLINK], PA_HOOK_LATE, (pa_hook_cb_t) source_unlink_hook_callback, u);
}
if (restore_volume || restore_muted) {
pa_module_hook_connect(m, &m->core->hooks[PA_CORE_HOOK_SINK_INPUT_FIXATE], PA_HOOK_EARLY, (pa_hook_cb_t) sink_input_fixate_hook_callback, u);
pa_module_hook_connect(m, &m->core->hooks[PA_CORE_HOOK_SOURCE_OUTPUT_FIXATE], PA_HOOK_EARLY, (pa_hook_cb_t) source_output_fixate_hook_callback, u);