From eee059ac127f7c88a536634e796d8de36e8459af Mon Sep 17 00:00:00 2001 From: Jaska Uimonen Date: Mon, 20 Jan 2014 14:44:25 +0200 Subject: [PATCH] audio manager connection fixes Change-Id: I7cccd64f6618bc158bf3532de8c92704ac04045b --- murphy/audiomgr.c | 71 ++++++++++++++++++++++++++++++------------------------- murphy/dbusif.c | 17 ++++++------- 2 files changed, 48 insertions(+), 40 deletions(-) diff --git a/murphy/audiomgr.c b/murphy/audiomgr.c index f6321a8..d970e76 100644 --- a/murphy/audiomgr.c +++ b/murphy/audiomgr.c @@ -113,7 +113,7 @@ struct pa_audiomgr *pa_audiomgr_init(struct userdata *u) pa_audiomgr *am; pa_assert(u); - + am = pa_xnew0(pa_audiomgr, 1); am->domain.id = AM_ID_INVALID; @@ -165,7 +165,7 @@ void pa_audiomgr_register_domain(struct userdata *u) void pa_audiomgr_domain_registered(struct userdata *u, uint16_t id, - uint16_t state, + uint16_t state, am_domainreg_data *dr) { pa_audiomgr *am; @@ -180,9 +180,9 @@ void pa_audiomgr_domain_registered(struct userdata *u, am->domain.state = state; pa_log_debug("start domain registration for '%s' domain", dr->name); - + pa_discover_domain_up(u); - + pa_log_debug("domain registration for '%s' domain is complete", dr->name); pa_routerif_domain_complete(u, id); @@ -238,18 +238,18 @@ void pa_audiomgr_register_node(struct userdata *u, mir_node *node) rd->avail.status = AS_AVAILABLE; rd->avail.reason = 0; rd->mainvol = 32767; - + if (node->direction == mir_input) { rd->interrupt = IS_OFF; method = audiomgr_register_source; - } + } else { rd->mute = MS_UNMUTED; method = audiomgr_register_sink; } - + success = pa_routerif_register_node(u, method, rd); - + if (success) { pa_log_debug("initiate registration node '%s' (%p)" "to audio manager", rd->name, node); @@ -333,16 +333,16 @@ void pa_audiomgr_unregister_node(struct userdata *u, mir_node *node) pa_log("%s: confused with data structures: node %u (%p)" "is not in the hash table", __FILE__, node->amid, node); } - - + + if (node->direction == mir_input) method = audiomgr_deregister_source; else method = audiomgr_deregister_sink; - - + + success = pa_routerif_unregister_node(u, method, ud); - + if (success) { pa_log_debug("sucessfully unregistered node '%s' (%p/%p)" "from audio manager", node->amname, key, node); @@ -405,7 +405,7 @@ void pa_audiomgr_add_default_route(struct userdata *u, if (defrts->nlink >= defrts->maxlink) { defrts->maxlink += 16; - + size = sizeof(link_t) * defrts->maxlink; defrts->links = realloc(defrts->links, size); pa_assert(defrts->links); @@ -478,31 +478,39 @@ void pa_audiomgr_connect(struct userdata *u, am_connect_data *cd) mir_node *from = NULL; mir_node *to = NULL; int err = E_OK; + bool autoconn = false; pa_assert(u); pa_assert(cd); pa_assert_se((am = u->audiomgr)); - if ((from = pa_hashmap_get(am->nodes, node_hash(mir_input, cd->source))) && - (to = pa_hashmap_get(am->nodes, node_hash(mir_output, cd->sink)))) - { - cid = cd->connection; - - pa_log_debug("routing '%s' => '%s'", from->amname, to->amname); + if (cd->format == CF_AUTO) { + autoconn = true; + pa_log_debug("automatic connection request received"); + } - if (!(conn = mir_router_add_explicit_route(u, cid, from, to))) - err = E_NOT_POSSIBLE; + if (autoconn == false) { + if ((from = pa_hashmap_get(am->nodes, node_hash(mir_input, cd->source))) && + (to = pa_hashmap_get(am->nodes, node_hash(mir_output, cd->sink)))) + { + cid = cd->connection; + + pa_log_debug("routing '%s' => '%s'", from->amname, to->amname); + + if (!(conn = mir_router_add_explicit_route(u, cid, from, to))) + err = E_NOT_POSSIBLE; + else { + pa_log_debug("registering connection (%u/%p)", + cd->connection, conn); + pa_hashmap_put(am->conns, conn_hash(cid), conn); + } + } else { - pa_log_debug("registering connection (%u/%p)", - cd->connection, conn); - pa_hashmap_put(am->conns, conn_hash(cid), conn); + pa_log_debug("failed to connect: can't find node for %s %u", + from ? "sink" : "source", from ? cd->sink : cd->source); + err = E_NON_EXISTENT; } } - else { - pa_log_debug("failed to connect: can't find node for %s %u", - from ? "sink" : "source", from ? cd->sink : cd->source); - err = E_NON_EXISTENT; - } memset(&ad, 0, sizeof(ad)); ad.handle = cd->handle; @@ -538,7 +546,7 @@ void pa_audiomgr_disconnect(struct userdata *u, am_connect_data *cd) ad.param1 = cd->connection; ad.error = err; - pa_routerif_acknowledge(u, audiomgr_disconnect, &ad); + pa_routerif_acknowledge(u, audiomgr_disconnect_ack, &ad); } static bool find_default_route(struct userdata *u, @@ -600,4 +608,3 @@ static void *conn_hash(uint16_t connid) * End: * */ - diff --git a/murphy/dbusif.c b/murphy/dbusif.c index 3670f4f..3477ba0 100644 --- a/murphy/dbusif.c +++ b/murphy/dbusif.c @@ -159,6 +159,8 @@ pa_routerif *pa_routerif_init(struct userdata *u, unsigned int flags; char nambuf[128]; char pathbuf[128]; + char ctlnambuf[128]; + char ctlpathbuf[128]; char *amrnam; char *amrpath; char *amcnam; @@ -216,9 +218,9 @@ pa_routerif *pa_routerif_init(struct userdata *u, snprintf(pathbuf, sizeof(pathbuf), "%s%s" AUDIOMGR_DBUS_ROUTE_PATH, ampath, slash); amrpath = pathbuf; - snprintf(pathbuf, sizeof(pathbuf), "%s%s" AUDIOMGR_DBUS_CONTROL_PATH, + snprintf(ctlpathbuf, sizeof(ctlpathbuf), "%s%s" AUDIOMGR_DBUS_CONTROL_PATH, ampath, slash); - amcpath = pathbuf; + amcpath = ctlpathbuf; } else { ampath = AUDIOMGR_DBUS_PATH; @@ -231,14 +233,14 @@ pa_routerif *pa_routerif_init(struct userdata *u, snprintf(nambuf, sizeof(nambuf), "%s%s" AUDIOMGR_DBUS_ROUTE_NAME, amnam, dot); amrnam = nambuf; - snprintf(nambuf, sizeof(nambuf), "%s%s" AUDIOMGR_DBUS_CONTROL_NAME, + snprintf(ctlnambuf, sizeof(ctlnambuf), "%s%s" AUDIOMGR_DBUS_CONTROL_NAME, amnam, dot); - amcnam = nambuf; + amcnam = ctlnambuf; } else { amnam = AUDIOMGR_DBUS_INTERFACE; amrnam = AUDIOMGR_DBUS_INTERFACE "." AUDIOMGR_DBUS_ROUTE_NAME; - amcnam = AUDIOMGR_DBUS_INTERFACE "." AUDIOMGR_DBUS_ROUTE_NAME; + amcnam = AUDIOMGR_DBUS_INTERFACE "." AUDIOMGR_DBUS_CONTROL_NAME; } snprintf(admarule, sizeof(admarule), "type='signal',sender='%s',path='%s'," @@ -259,8 +261,8 @@ pa_routerif *pa_routerif_init(struct userdata *u, routerif->amnam = pa_xstrdup(amnam); routerif->amrpath = pa_xstrdup(amrpath); routerif->amrnam = pa_xstrdup(amrnam); - routerif->amcpath = pa_xstrdup(amrpath); - routerif->amcnam = pa_xstrdup(amrnam); + routerif->amcpath = pa_xstrdup(amcpath); + routerif->amcnam = pa_xstrdup(amcnam); routerif->admarule = pa_xstrdup(admarule); u->routerif = routerif; /* Argh.. */ @@ -1093,7 +1095,6 @@ bool pa_routerif_register_implicit_connection(struct userdata *u, dbus_message_set_no_reply(msg, true); success = dbus_message_append_args(msg, - DBUS_TYPE_UINT16, &cd->connection, DBUS_TYPE_INT16 , &cd->format, DBUS_TYPE_UINT16, &cd->source, DBUS_TYPE_UINT16, &cd->sink, -- 2.7.4