summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--audio/avdtp.c11
-rw-r--r--audio/control.c14
-rw-r--r--audio/manager.c18
-rw-r--r--audio/manager.h5
4 files changed, 34 insertions, 14 deletions
diff --git a/audio/avdtp.c b/audio/avdtp.c
index 26e38b5d..63b9bdc4 100644
--- a/audio/avdtp.c
+++ b/audio/avdtp.c
@@ -48,6 +48,7 @@
#include "control.h"
#include "avdtp.h"
#include "glib-helper.h"
+#include "sink.h"
#include <bluetooth/l2cap.h>
@@ -2748,6 +2749,7 @@ static void avdtp_server_cb(GIOChannel *chan, int err, const bdaddr_t *src,
socklen_t size;
struct l2cap_options l2o;
struct avdtp *session;
+ struct audio_device *dev;
char address[18];
if (err < 0) {
@@ -2780,6 +2782,15 @@ static void avdtp_server_cb(GIOChannel *chan, int err, const bdaddr_t *src,
goto drop;
}
+ dev = manager_get_device(src, dst, NULL);
+ if (!dev) {
+ error("Unable to get audio device object for %s", address);
+ goto drop;
+ }
+
+ if (!dev->sink)
+ dev->sink = sink_init(dev);
+
session->mtu = l2o.imtu;
session->sock = sk;
diff --git a/audio/control.c b/audio/control.c
index 1dcab3c2..8b3b2d8a 100644
--- a/audio/control.c
+++ b/audio/control.c
@@ -666,6 +666,7 @@ static void avctp_server_cb(GIOChannel *chan, int err, const bdaddr_t *src,
struct l2cap_options l2o;
struct avctp *session;
GIOCondition flags = G_IO_ERR | G_IO_HUP | G_IO_NVAL;
+ struct audio_device *dev;
char address[18];
if (err < 0) {
@@ -685,6 +686,15 @@ static void avctp_server_cb(GIOChannel *chan, int err, const bdaddr_t *src,
goto drop;
}
+ dev = manager_get_device(src, dst, NULL);
+ if (!dev) {
+ error("Unable to get audio device object for %s", address);
+ goto drop;
+ }
+
+ if (!dev->control)
+ dev->control = control_init(dev);
+
session->state = AVCTP_STATE_CONNECTING;
session->sock = g_io_channel_unix_get_fd(chan);
@@ -694,7 +704,6 @@ static void avctp_server_cb(GIOChannel *chan, int err, const bdaddr_t *src,
err = errno;
error("getsockopt(L2CAP_OPTIONS): %s (%d)", strerror(err),
err);
- avctp_unref(session);
goto drop;
}
@@ -721,7 +730,8 @@ proceed:
return;
drop:
- close(session->sock);
+ g_io_channel_close(chan);
+ avctp_unref(session);
}
static GIOChannel *avctp_server_socket(const bdaddr_t *src, gboolean master)
diff --git a/audio/manager.c b/audio/manager.c
index 5a043f5e..ee44835c 100644
--- a/audio/manager.c
+++ b/audio/manager.c
@@ -491,10 +491,13 @@ static void ag_io_cb(GIOChannel *chan, int err, const bdaddr_t *src,
uuid = HFP_AG_UUID;
}
- device = manager_find_device(dst, NULL, FALSE);
+ device = manager_get_device(src, dst, NULL);
if (!device)
goto drop;
+ if (!device->headset)
+ device->headset = headset_init(device, NULL, 0);
+
if (headset_get_state(device) > HEADSET_STATE_DISCONNECTED) {
debug("Refusing new connection since one already exists");
goto drop;
@@ -685,7 +688,7 @@ static int audio_probe(struct btd_device *device, GSList *records)
adapter_get_address(adapter, &src);
device_get_address(device, &dst);
- dev = manager_get_device(&src, &dst, path, NULL);
+ dev = manager_get_device(&src, &dst, path);
if (!dev) {
debug("audio_probe: unable to get a device object");
return -1;
@@ -1057,14 +1060,12 @@ struct audio_device *manager_find_device(const bdaddr_t *bda, const char *interf
return NULL;
}
-struct audio_device *manager_get_device(bdaddr_t *src, bdaddr_t *dst,
- const char *path, gboolean *created)
+struct audio_device *manager_get_device(const bdaddr_t *src,
+ const bdaddr_t *dst,
+ const char *path)
{
struct audio_device *dev;
- if (created)
- *created = FALSE;
-
dev = manager_find_device(dst, NULL, FALSE);
if (dev)
return dev;
@@ -1100,8 +1101,5 @@ struct audio_device *manager_get_device(bdaddr_t *src, bdaddr_t *dst,
devices = g_slist_append(devices, dev);
- if (created)
- *created = TRUE;
-
return dev;
}
diff --git a/audio/manager.h b/audio/manager.h
index 7feaf83c..3d712f41 100644
--- a/audio/manager.h
+++ b/audio/manager.h
@@ -38,5 +38,6 @@ gboolean server_is_enabled(bdaddr_t *src, uint16_t svc);
struct audio_device *manager_find_device(const bdaddr_t *bda, const char *interface,
gboolean connected);
-struct audio_device *manager_get_device(bdaddr_t *sba, bdaddr_t *dba,
- const char *path, gboolean *created);
+struct audio_device *manager_get_device(const bdaddr_t *src,
+ const bdaddr_t *dst,
+ const char *path);