Diff between fa8aa7b269f4eb1a581e8beb9d069d4ea4e079a0 and c6fed41a02d30732e6a0797185ae7397d565b954

Changed Files

File Additions Deletions Status
android/a2dp.c +60 -4 modified

Full Patch

diff --git a/android/a2dp.c b/android/a2dp.c
index 27360d3..d89c828 100644
--- a/android/a2dp.c
+++ b/android/a2dp.c
@@ -477,6 +477,60 @@ static const struct ipc_handler cmd_handlers[] = {
 	{ bt_a2dp_disconnect, false, sizeof(struct hal_cmd_a2dp_disconnect) },
 };
 
+static struct a2dp_setup *find_setup_by_device(struct a2dp_device *dev)
+{
+	GSList *l;
+
+	for (l = setups; l; l = g_slist_next(l)) {
+		struct a2dp_setup *setup = l->data;
+
+		if (setup->dev == dev)
+			return setup;
+	}
+
+	return NULL;
+}
+
+static void transport_connect_cb(GIOChannel *chan, GError *err,
+							gpointer user_data)
+{
+	struct a2dp_device *dev = user_data;
+	struct a2dp_setup *setup;
+	uint16_t imtu, omtu;
+	GError *gerr = NULL;
+	int fd;
+
+	if (err) {
+		error("%s", err->message);
+		return;
+	}
+
+	setup = find_setup_by_device(dev);
+	if (!setup) {
+		error("Unable to find stream setup");
+		return;
+	}
+
+	bt_io_get(chan, &gerr,
+			BT_IO_OPT_IMTU, &imtu,
+			BT_IO_OPT_OMTU, &omtu,
+			BT_IO_OPT_INVALID);
+	if (gerr) {
+		error("%s", gerr->message);
+		g_error_free(gerr);
+		return;
+	}
+
+	fd = g_io_channel_unix_get_fd(chan);
+
+	if (!avdtp_stream_set_transport(setup->stream, fd, imtu, omtu)) {
+		error("avdtp_stream_set_transport: failed");
+		return;
+	}
+
+	g_io_channel_set_close_on_unref(chan, FALSE);
+}
+
 static void connect_cb(GIOChannel *chan, GError *err, gpointer user_data)
 {
 	struct a2dp_device *dev;
@@ -501,13 +555,15 @@ static void connect_cb(GIOChannel *chan, GError *err, gpointer user_data)
 		return;
 	}
 
-	l = g_slist_find_custom(devices, &dst, device_cmp);
-	if (l)
-		return;
-
 	ba2str(&dst, address);
 	DBG("Incoming connection from %s", address);
 
+	l = g_slist_find_custom(devices, &dst, device_cmp);
+	if (l) {
+		transport_connect_cb(chan, err, l->data);
+		return;
+	}
+
 	dev = a2dp_device_new(&dst);
 	signaling_connect_cb(chan, err, dev);
 }