diff --git a/profiles/audio/a2dp.c b/profiles/audio/a2dp.c
index 35b9e9d..fc98bb2 100644
--- a/profiles/audio/a2dp.c
+++ b/profiles/audio/a2dp.c
if (server == NULL)
return NULL;
+ chan = queue_find(server->channels, match_by_device, device);
+ if (!chan) {
+ chan = channel_new(server, device, NULL);
+ if (!chan)
+ return NULL;
+ }
+
+ if (chan->session)
+ return avdtp_ref(chan->session);
+
/* Check if there is any SEP available */
for (entry = queue_get_entries(server->seps); entry;
entry = entry->next) {
- struct a2dp_sep *sep = entry->data;
+ struct avdtp_local_sep *sep = entry->data;
- if (avdtp_sep_get_state(sep->lsep) == AVDTP_STATE_IDLE)
+ if (avdtp_sep_get_state(sep) == AVDTP_STATE_IDLE)
goto found;
}
return NULL;
found:
- chan = queue_find(server->channels, match_by_device, device);
- if (!chan) {
- chan = channel_new(server, device, NULL);
- if (!chan)
- return NULL;
- }
-
- if (chan->session)
- return avdtp_ref(chan->session);
-
chan->session = avdtp_new(NULL, device, server->seps);
if (!chan->session) {
channel_remove(chan);