From c1ece6ce85526d170c9dcb7a80371ee008248eb1 Mon Sep 17 00:00:00 2001 From: Colin Guthrie Date: Sat, 19 Sep 2009 16:13:25 +0100 Subject: device-manager: Provide a way for clients to enable/disable role-based device-priority routing. The routing logic itself does not yet exist, but the command currently will unload/load module-stream-restore as approriate. (module-stream-restore would conflict with the role-based priority-routing). --- src/modules/module-device-manager.c | 56 +++++++++++++++++++++++++++++++++++++ src/pulse/ext-device-manager.c | 32 +++++++++++++++++++++ src/pulse/ext-device-manager.h | 7 +++++ 3 files changed, 95 insertions(+) (limited to 'src') diff --git a/src/modules/module-device-manager.c b/src/modules/module-device-manager.c index 77b6f2fe..5685dbb8 100644 --- a/src/modules/module-device-manager.c +++ b/src/modules/module-device-manager.c @@ -79,6 +79,10 @@ struct userdata { pa_native_protocol *protocol; pa_idxset *subscribed; + + pa_bool_t role_device_priority_routing; + pa_bool_t stream_restore_used; + pa_bool_t checked_stream_restore; }; #define ENTRY_VERSION 1 @@ -93,6 +97,7 @@ enum { SUBCOMMAND_READ, SUBCOMMAND_WRITE, SUBCOMMAND_DELETE, + SUBCOMMAND_ROLE_DEVICE_PRIORITY_ROUTING, SUBCOMMAND_SUBSCRIBE, SUBCOMMAND_EVENT }; @@ -473,6 +478,57 @@ static int extension_cb(pa_native_protocol *p, pa_module *m, pa_native_connectio break; + case SUBCOMMAND_ROLE_DEVICE_PRIORITY_ROUTING: + + while (!pa_tagstruct_eof(t)) { + pa_bool_t enable; + uint32_t sridx = PA_INVALID_INDEX; + uint32_t idx; + pa_module *module; + + if (pa_tagstruct_get_boolean(t, &enable) < 0) + goto fail; + + /* If this is the first run, check for stream restore module */ + if (!u->checked_stream_restore) { + u->checked_stream_restore = TRUE; + + for (module = pa_idxset_first(u->core->modules, &idx); module; module = pa_idxset_next(u->core->modules, &idx)) { + if (strcmp(module->name, "module-stream-restore") == 0) { + pa_log_debug("Detected module-stream-restore is currently in use"); + u->stream_restore_used = TRUE; + sridx = module->index; + } + } + } + + u->role_device_priority_routing = enable; + if (enable) { + if (u->stream_restore_used) { + if (PA_INVALID_INDEX == sridx) { + /* As a shortcut on first load, we have sridx filled in, but otherwise we search for it. */ + for (module = pa_idxset_first(u->core->modules, &idx); module; module = pa_idxset_next(u->core->modules, &idx)) { + if (strcmp(module->name, "module-stream-restore") == 0) { + sridx = module->index; + } + } + } + if (PA_INVALID_INDEX != sridx) { + pa_log_debug("Unloading module-stream-restore to enable role-based device-priority routing"); + pa_module_unload_request_by_index(u->core, sridx, TRUE); + } + } + } else if (u->stream_restore_used) { + /* We want to reload module-stream-restore */ + if (!pa_module_load(u->core, "module-stream-restore", "")) + pa_log_warn("Failed to load module-stream-restore while disabling role-based device-priority routing"); + } + } + + trigger_save(u); + + break; + case SUBCOMMAND_SUBSCRIBE: { pa_bool_t enabled; diff --git a/src/pulse/ext-device-manager.c b/src/pulse/ext-device-manager.c index 1c6eee5e..0603a89a 100644 --- a/src/pulse/ext-device-manager.c +++ b/src/pulse/ext-device-manager.c @@ -41,6 +41,7 @@ enum { SUBCOMMAND_READ, SUBCOMMAND_WRITE, SUBCOMMAND_DELETE, + SUBCOMMAND_ROLE_DEVICE_PRIORITY_ROUTING, SUBCOMMAND_SUBSCRIBE, SUBCOMMAND_EVENT }; @@ -289,6 +290,37 @@ fail: return NULL; } +pa_operation *pa_ext_device_manager_enable_role_device_priority_routing( + pa_context *c, + int enable, + pa_context_success_cb_t cb, + void *userdata) { + + uint32_t tag; + pa_operation *o = NULL; + pa_tagstruct *t = NULL; + + pa_assert(c); + pa_assert(PA_REFCNT_VALUE(c) >= 1); + + PA_CHECK_VALIDITY_RETURN_NULL(c, !pa_detect_fork(), PA_ERR_FORKED); + PA_CHECK_VALIDITY_RETURN_NULL(c, c->state == PA_CONTEXT_READY, PA_ERR_BADSTATE); + PA_CHECK_VALIDITY_RETURN_NULL(c, c->version >= 14, PA_ERR_NOTSUPPORTED); + + o = pa_operation_new(c, NULL, (pa_operation_cb_t) cb, userdata); + + t = pa_tagstruct_command(c, PA_COMMAND_EXTENSION, &tag); + pa_tagstruct_putu32(t, PA_INVALID_INDEX); + pa_tagstruct_puts(t, "module-device-manager"); + pa_tagstruct_putu32(t, SUBCOMMAND_ROLE_DEVICE_PRIORITY_ROUTING); + pa_tagstruct_put_boolean(t, !!enable); + + pa_pstream_send_tagstruct(c->pstream, t); + pa_pdispatch_register_reply(c->pdispatch, tag, DEFAULT_TIMEOUT, pa_context_simple_ack_callback, pa_operation_ref(o), (pa_free_cb_t) pa_operation_unref); + + return o; +} + pa_operation *pa_ext_device_manager_subscribe( pa_context *c, int enable, diff --git a/src/pulse/ext-device-manager.h b/src/pulse/ext-device-manager.h index 33bcbfa8..29d56ba4 100644 --- a/src/pulse/ext-device-manager.h +++ b/src/pulse/ext-device-manager.h @@ -82,6 +82,13 @@ pa_operation *pa_ext_device_manager_delete( pa_context_success_cb_t cb, void *userdata); +/** Subscribe to changes in the device database. \since 0.9.19 */ +pa_operation *pa_ext_device_manager_enable_role_device_priority_routing( + pa_context *c, + int enable, + pa_context_success_cb_t cb, + void *userdata); + /** Subscribe to changes in the device database. \since 0.9.19 */ pa_operation *pa_ext_device_manager_subscribe( pa_context *c, -- cgit