2007-08-02 03:37:08 +08:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* BlueZ - Bluetooth protocol stack for Linux
|
|
|
|
*
|
2007-10-24 01:17:47 +08:00
|
|
|
* Copyright (C) 2006-2007 Nokia Corporation
|
2009-01-02 02:33:20 +08:00
|
|
|
* Copyright (C) 2004-2009 Marcel Holtmann <marcel@holtmann.org>
|
2007-08-02 03:37:08 +08:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include <config.h>
|
|
|
|
#endif
|
|
|
|
|
2007-08-11 19:05:24 +08:00
|
|
|
#include <stdlib.h>
|
2007-09-28 21:46:55 +08:00
|
|
|
#include <errno.h>
|
2007-08-11 19:05:24 +08:00
|
|
|
|
|
|
|
#include <dbus/dbus.h>
|
|
|
|
#include <glib.h>
|
|
|
|
|
2007-08-13 16:14:22 +08:00
|
|
|
#include <bluetooth/bluetooth.h>
|
2007-08-11 19:05:24 +08:00
|
|
|
#include <bluetooth/sdp.h>
|
|
|
|
#include <bluetooth/sdp_lib.h>
|
|
|
|
|
|
|
|
#include "logging.h"
|
2007-08-13 07:58:15 +08:00
|
|
|
#include "device.h"
|
2007-08-27 20:05:10 +08:00
|
|
|
#include "manager.h"
|
2007-08-11 19:05:24 +08:00
|
|
|
#include "avdtp.h"
|
2007-08-13 05:34:50 +08:00
|
|
|
#include "sink.h"
|
2007-08-02 03:37:08 +08:00
|
|
|
#include "a2dp.h"
|
2008-03-28 07:07:19 +08:00
|
|
|
#include "sdpd.h"
|
2007-08-11 19:05:24 +08:00
|
|
|
|
2007-08-19 05:57:26 +08:00
|
|
|
/* The duration that streams without users are allowed to stay in
|
|
|
|
* STREAMING state. */
|
2008-11-15 04:27:16 +08:00
|
|
|
#define SUSPEND_TIMEOUT 5
|
2007-12-04 06:41:29 +08:00
|
|
|
#define RECONFIGURE_TIMEOUT 500
|
2007-08-19 05:57:26 +08:00
|
|
|
|
2007-08-16 23:42:10 +08:00
|
|
|
#ifndef MIN
|
|
|
|
# define MIN(x, y) ((x) < (y) ? (x) : (y))
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef MAX
|
|
|
|
# define MAX(x, y) ((x) > (y) ? (x) : (y))
|
|
|
|
#endif
|
|
|
|
|
|
|
|
struct a2dp_sep {
|
2007-08-24 20:15:20 +08:00
|
|
|
uint8_t type;
|
2008-01-23 21:16:02 +08:00
|
|
|
uint8_t codec;
|
2007-08-16 23:42:10 +08:00
|
|
|
struct avdtp_local_sep *sep;
|
2007-08-19 05:57:26 +08:00
|
|
|
struct avdtp *session;
|
2007-08-16 23:42:10 +08:00
|
|
|
struct avdtp_stream *stream;
|
2007-08-19 05:57:26 +08:00
|
|
|
guint suspend_timer;
|
2007-08-24 20:15:20 +08:00
|
|
|
gboolean locked;
|
2007-08-16 23:42:10 +08:00
|
|
|
gboolean suspending;
|
|
|
|
gboolean starting;
|
|
|
|
};
|
|
|
|
|
2007-12-04 06:41:29 +08:00
|
|
|
struct a2dp_setup_cb {
|
|
|
|
a2dp_config_cb_t config_cb;
|
|
|
|
a2dp_stream_cb_t resume_cb;
|
|
|
|
a2dp_stream_cb_t suspend_cb;
|
2007-08-16 23:42:10 +08:00
|
|
|
void *user_data;
|
2009-01-30 07:24:59 +08:00
|
|
|
unsigned int id;
|
2007-08-16 23:42:10 +08:00
|
|
|
};
|
|
|
|
|
2007-12-04 06:41:29 +08:00
|
|
|
struct a2dp_setup {
|
2007-08-16 23:42:10 +08:00
|
|
|
struct avdtp *session;
|
2007-08-31 14:21:52 +08:00
|
|
|
struct a2dp_sep *sep;
|
2007-08-16 23:42:10 +08:00
|
|
|
struct avdtp_stream *stream;
|
2007-12-08 06:29:26 +08:00
|
|
|
struct avdtp_error *err;
|
2007-12-04 06:41:29 +08:00
|
|
|
GSList *client_caps;
|
|
|
|
gboolean reconfigure;
|
2007-08-16 23:42:10 +08:00
|
|
|
gboolean canceled;
|
2007-12-07 17:36:32 +08:00
|
|
|
gboolean start;
|
2007-08-16 23:42:10 +08:00
|
|
|
GSList *cb;
|
2007-12-04 06:41:29 +08:00
|
|
|
int ref;
|
2007-08-16 23:42:10 +08:00
|
|
|
};
|
|
|
|
|
2007-08-11 19:05:24 +08:00
|
|
|
static DBusConnection *connection = NULL;
|
|
|
|
|
2008-09-09 05:20:29 +08:00
|
|
|
struct a2dp_server {
|
|
|
|
bdaddr_t src;
|
|
|
|
GSList *sinks;
|
|
|
|
GSList *sources;
|
|
|
|
uint32_t source_record_id;
|
|
|
|
uint32_t sink_record_id;
|
|
|
|
};
|
2007-08-11 19:05:24 +08:00
|
|
|
|
2008-09-09 05:20:29 +08:00
|
|
|
static GSList *servers = NULL;
|
2007-08-31 16:28:22 +08:00
|
|
|
static GSList *setups = NULL;
|
2007-12-04 06:41:29 +08:00
|
|
|
static unsigned int cb_id = 0;
|
|
|
|
|
|
|
|
static struct a2dp_setup *setup_ref(struct a2dp_setup *setup)
|
|
|
|
{
|
|
|
|
setup->ref++;
|
|
|
|
|
|
|
|
debug("setup_ref(%p): ref=%d", setup, setup->ref);
|
|
|
|
|
|
|
|
return setup;
|
|
|
|
}
|
2007-08-11 19:05:24 +08:00
|
|
|
|
2007-12-04 06:41:29 +08:00
|
|
|
static void setup_free(struct a2dp_setup *s)
|
2007-08-16 23:42:10 +08:00
|
|
|
{
|
2007-12-04 06:41:29 +08:00
|
|
|
debug("setup_free(%p)", s);
|
2007-08-31 16:28:22 +08:00
|
|
|
setups = g_slist_remove(setups, s);
|
2007-08-16 23:42:10 +08:00
|
|
|
if (s->session)
|
|
|
|
avdtp_unref(s->session);
|
|
|
|
g_slist_foreach(s->cb, (GFunc) g_free, NULL);
|
|
|
|
g_slist_free(s->cb);
|
|
|
|
g_free(s);
|
|
|
|
}
|
|
|
|
|
2007-12-04 06:41:29 +08:00
|
|
|
static void setup_unref(struct a2dp_setup *setup)
|
|
|
|
{
|
|
|
|
setup->ref--;
|
|
|
|
|
|
|
|
debug("setup_unref(%p): ref=%d", setup, setup->ref);
|
|
|
|
|
|
|
|
if (setup->ref <= 0)
|
|
|
|
setup_free(setup);
|
|
|
|
}
|
|
|
|
|
2008-05-29 16:05:16 +08:00
|
|
|
static struct audio_device *a2dp_get_dev(struct avdtp *session)
|
2007-08-31 18:25:18 +08:00
|
|
|
{
|
2009-03-19 22:50:26 +08:00
|
|
|
bdaddr_t src, dst;
|
2007-08-31 18:25:18 +08:00
|
|
|
|
2009-03-19 22:50:26 +08:00
|
|
|
avdtp_get_peers(session, &src, &dst);
|
2007-08-31 18:25:18 +08:00
|
|
|
|
2009-03-14 02:13:44 +08:00
|
|
|
return manager_find_device(NULL, &src, &dst, NULL, FALSE);
|
2007-08-31 18:25:18 +08:00
|
|
|
}
|
|
|
|
|
2007-12-08 06:29:26 +08:00
|
|
|
static gboolean finalize_config(struct a2dp_setup *s)
|
2007-08-16 23:42:10 +08:00
|
|
|
{
|
2007-09-28 21:46:55 +08:00
|
|
|
GSList *l;
|
|
|
|
|
2007-12-04 06:41:29 +08:00
|
|
|
setup_ref(s);
|
2007-09-28 21:46:55 +08:00
|
|
|
for (l = s->cb; l != NULL; l = l->next) {
|
2007-12-04 06:41:29 +08:00
|
|
|
struct a2dp_setup_cb *cb = l->data;
|
2009-03-10 03:53:03 +08:00
|
|
|
struct avdtp_stream *stream = s->err ? NULL : s->stream;
|
2007-12-04 06:41:29 +08:00
|
|
|
|
2009-03-10 03:53:03 +08:00
|
|
|
if (!cb->config_cb)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
cb->config_cb(s->session, s->sep, stream, s->err,
|
|
|
|
cb->user_data);
|
|
|
|
cb->config_cb = NULL;
|
|
|
|
setup_unref(s);
|
2007-09-28 21:46:55 +08:00
|
|
|
}
|
2007-08-16 23:42:10 +08:00
|
|
|
|
2007-12-04 06:41:29 +08:00
|
|
|
setup_unref(s);
|
2007-08-19 23:27:56 +08:00
|
|
|
return FALSE;
|
2007-08-16 23:42:10 +08:00
|
|
|
}
|
2007-08-16 06:57:49 +08:00
|
|
|
|
2007-12-04 06:41:29 +08:00
|
|
|
static gboolean finalize_config_errno(struct a2dp_setup *s, int err)
|
2007-09-28 21:46:55 +08:00
|
|
|
{
|
|
|
|
struct avdtp_error avdtp_err;
|
|
|
|
|
|
|
|
avdtp_error_init(&avdtp_err, AVDTP_ERROR_ERRNO, -err);
|
2007-12-08 06:29:26 +08:00
|
|
|
s->err = err ? &avdtp_err : NULL;
|
2007-09-28 21:46:55 +08:00
|
|
|
|
2007-12-08 06:29:26 +08:00
|
|
|
return finalize_config(s);
|
2007-09-28 21:46:55 +08:00
|
|
|
}
|
|
|
|
|
2007-12-08 06:29:26 +08:00
|
|
|
static gboolean finalize_resume(struct a2dp_setup *s)
|
2007-12-04 06:41:29 +08:00
|
|
|
{
|
|
|
|
GSList *l;
|
|
|
|
|
|
|
|
setup_ref(s);
|
|
|
|
for (l = s->cb; l != NULL; l = l->next) {
|
|
|
|
struct a2dp_setup_cb *cb = l->data;
|
|
|
|
|
2009-03-27 06:22:32 +08:00
|
|
|
if (cb && cb->resume_cb) {
|
2007-12-08 06:29:26 +08:00
|
|
|
cb->resume_cb(s->session, s->err, cb->user_data);
|
2007-12-04 06:41:29 +08:00
|
|
|
cb->resume_cb = NULL;
|
|
|
|
setup_unref(s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
setup_unref(s);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2007-12-08 06:29:26 +08:00
|
|
|
static gboolean finalize_suspend(struct a2dp_setup *s)
|
2007-12-04 06:41:29 +08:00
|
|
|
{
|
|
|
|
GSList *l;
|
|
|
|
|
|
|
|
setup_ref(s);
|
|
|
|
for (l = s->cb; l != NULL; l = l->next) {
|
|
|
|
struct a2dp_setup_cb *cb = l->data;
|
|
|
|
|
|
|
|
if (cb->suspend_cb) {
|
2007-12-08 06:29:26 +08:00
|
|
|
cb->suspend_cb(s->session, s->err, cb->user_data);
|
2007-12-04 06:41:29 +08:00
|
|
|
cb->suspend_cb = NULL;
|
|
|
|
setup_unref(s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
setup_unref(s);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean finalize_suspend_errno(struct a2dp_setup *s, int err)
|
|
|
|
{
|
|
|
|
struct avdtp_error avdtp_err;
|
|
|
|
|
|
|
|
avdtp_error_init(&avdtp_err, AVDTP_ERROR_ERRNO, -err);
|
2007-12-08 06:29:26 +08:00
|
|
|
s->err = err ? &avdtp_err : NULL;
|
2007-12-04 06:41:29 +08:00
|
|
|
|
2007-12-08 06:29:26 +08:00
|
|
|
return finalize_suspend(s);
|
2007-12-04 06:41:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct a2dp_setup *find_setup_by_session(struct avdtp *session)
|
2007-08-31 16:28:22 +08:00
|
|
|
{
|
|
|
|
GSList *l;
|
|
|
|
|
|
|
|
for (l = setups; l != NULL; l = l->next) {
|
2007-12-04 06:41:29 +08:00
|
|
|
struct a2dp_setup *setup = l->data;
|
2007-08-31 16:28:22 +08:00
|
|
|
|
|
|
|
if (setup->session == session)
|
|
|
|
return setup;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2008-05-29 16:05:16 +08:00
|
|
|
static struct a2dp_setup *find_setup_by_dev(struct audio_device *dev)
|
2007-08-31 16:28:22 +08:00
|
|
|
{
|
|
|
|
GSList *l;
|
|
|
|
|
|
|
|
for (l = setups; l != NULL; l = l->next) {
|
2007-12-04 06:41:29 +08:00
|
|
|
struct a2dp_setup *setup = l->data;
|
2008-05-29 16:05:16 +08:00
|
|
|
struct audio_device *setup_dev = a2dp_get_dev(setup->session);
|
2007-08-31 16:28:22 +08:00
|
|
|
|
2007-08-31 18:25:18 +08:00
|
|
|
if (setup_dev == dev)
|
2007-08-31 16:28:22 +08:00
|
|
|
return setup;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2007-08-20 23:12:33 +08:00
|
|
|
static void stream_state_changed(struct avdtp_stream *stream,
|
|
|
|
avdtp_state_t old_state,
|
|
|
|
avdtp_state_t new_state,
|
|
|
|
struct avdtp_error *err,
|
|
|
|
void *user_data)
|
|
|
|
{
|
|
|
|
struct a2dp_sep *sep = user_data;
|
|
|
|
|
|
|
|
if (new_state != AVDTP_STATE_IDLE)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (sep->suspend_timer) {
|
|
|
|
g_source_remove(sep->suspend_timer);
|
|
|
|
sep->suspend_timer = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sep->session) {
|
|
|
|
avdtp_unref(sep->session);
|
|
|
|
sep->session = NULL;
|
|
|
|
}
|
2007-12-07 14:18:59 +08:00
|
|
|
|
2007-08-20 23:12:33 +08:00
|
|
|
sep->stream = NULL;
|
2007-08-30 03:38:37 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2008-01-23 21:16:02 +08:00
|
|
|
static gboolean sbc_setconf_ind(struct avdtp *session,
|
2007-08-13 05:34:50 +08:00
|
|
|
struct avdtp_local_sep *sep,
|
2007-08-11 19:05:24 +08:00
|
|
|
struct avdtp_stream *stream,
|
2007-08-13 05:34:50 +08:00
|
|
|
GSList *caps, uint8_t *err,
|
2007-08-24 20:15:20 +08:00
|
|
|
uint8_t *category, void *user_data)
|
2007-08-11 19:05:24 +08:00
|
|
|
{
|
2007-08-24 20:15:20 +08:00
|
|
|
struct a2dp_sep *a2dp_sep = user_data;
|
2008-05-29 16:05:16 +08:00
|
|
|
struct audio_device *dev;
|
2007-09-04 05:21:20 +08:00
|
|
|
struct avdtp_service_capability *cap;
|
|
|
|
struct avdtp_media_codec_capability *codec_cap;
|
|
|
|
struct sbc_codec_cap *sbc_cap;
|
2007-08-13 05:34:50 +08:00
|
|
|
|
2007-08-24 20:15:20 +08:00
|
|
|
if (a2dp_sep->type == AVDTP_SEP_TYPE_SINK)
|
2008-01-23 21:21:57 +08:00
|
|
|
debug("Sink %p: Set_Configuration_Ind", sep);
|
2007-08-24 20:15:20 +08:00
|
|
|
else
|
2008-01-23 21:21:57 +08:00
|
|
|
debug("Source %p: Set_Configuration_Ind", sep);
|
2007-08-13 05:34:50 +08:00
|
|
|
|
2007-08-31 18:25:18 +08:00
|
|
|
dev = a2dp_get_dev(session);
|
2007-08-13 05:34:50 +08:00
|
|
|
if (!dev) {
|
|
|
|
*err = AVDTP_UNSUPPORTED_CONFIGURATION;
|
|
|
|
*category = 0x00;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2007-09-04 05:21:20 +08:00
|
|
|
/* Check bipool range */
|
|
|
|
for (codec_cap = NULL; caps; caps = g_slist_next(caps)) {
|
|
|
|
cap = caps->data;
|
2009-02-24 19:30:07 +08:00
|
|
|
if (cap->category != AVDTP_MEDIA_CODEC)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (cap->length < sizeof(struct sbc_codec_cap))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
codec_cap = (void *) cap->data;
|
|
|
|
|
|
|
|
if (codec_cap->media_codec_type != A2DP_CODEC_SBC)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
sbc_cap = (void *) codec_cap;
|
|
|
|
|
|
|
|
if (sbc_cap->min_bitpool < MIN_BITPOOL ||
|
2007-09-04 05:21:20 +08:00
|
|
|
sbc_cap->max_bitpool > MAX_BITPOOL) {
|
2009-02-24 19:30:07 +08:00
|
|
|
*err = AVDTP_UNSUPPORTED_CONFIGURATION;
|
|
|
|
*category = AVDTP_MEDIA_CODEC;
|
|
|
|
return FALSE;
|
2007-09-04 05:21:20 +08:00
|
|
|
}
|
2009-02-24 19:30:07 +08:00
|
|
|
|
|
|
|
break;
|
2007-09-04 05:21:20 +08:00
|
|
|
}
|
|
|
|
|
2007-08-20 23:12:33 +08:00
|
|
|
avdtp_stream_add_cb(session, stream, stream_state_changed, a2dp_sep);
|
2007-08-19 05:57:26 +08:00
|
|
|
a2dp_sep->stream = stream;
|
2007-08-16 23:42:10 +08:00
|
|
|
|
2007-08-24 20:15:20 +08:00
|
|
|
if (a2dp_sep->type == AVDTP_SEP_TYPE_SOURCE)
|
2007-08-19 05:57:26 +08:00
|
|
|
sink_new_stream(dev, session, stream);
|
2007-08-11 19:05:24 +08:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2008-01-23 21:16:02 +08:00
|
|
|
static gboolean sbc_getcap_ind(struct avdtp *session, struct avdtp_local_sep *sep,
|
2007-08-24 20:15:20 +08:00
|
|
|
GSList **caps, uint8_t *err, void *user_data)
|
2007-08-11 19:05:24 +08:00
|
|
|
{
|
2007-08-24 20:15:20 +08:00
|
|
|
struct a2dp_sep *a2dp_sep = user_data;
|
2007-08-11 19:05:24 +08:00
|
|
|
struct avdtp_service_capability *media_transport, *media_codec;
|
|
|
|
struct sbc_codec_cap sbc_cap;
|
|
|
|
|
2007-08-24 20:15:20 +08:00
|
|
|
if (a2dp_sep->type == AVDTP_SEP_TYPE_SINK)
|
2008-01-23 21:21:57 +08:00
|
|
|
debug("Sink %p: Get_Capability_Ind", sep);
|
2007-08-11 19:05:24 +08:00
|
|
|
else
|
2008-01-23 21:21:57 +08:00
|
|
|
debug("Source %p: Get_Capability_Ind", sep);
|
2007-08-11 19:05:24 +08:00
|
|
|
|
|
|
|
*caps = NULL;
|
|
|
|
|
|
|
|
media_transport = avdtp_service_cap_new(AVDTP_MEDIA_TRANSPORT,
|
|
|
|
NULL, 0);
|
|
|
|
|
|
|
|
*caps = g_slist_append(*caps, media_transport);
|
|
|
|
|
|
|
|
memset(&sbc_cap, 0, sizeof(struct sbc_codec_cap));
|
|
|
|
|
|
|
|
sbc_cap.cap.media_type = AVDTP_MEDIA_TYPE_AUDIO;
|
|
|
|
sbc_cap.cap.media_codec_type = A2DP_CODEC_SBC;
|
|
|
|
|
2008-01-23 21:11:07 +08:00
|
|
|
sbc_cap.frequency = ( SBC_SAMPLING_FREQ_48000 |
|
|
|
|
SBC_SAMPLING_FREQ_44100 |
|
|
|
|
SBC_SAMPLING_FREQ_32000 |
|
|
|
|
SBC_SAMPLING_FREQ_16000 );
|
2007-08-11 19:05:24 +08:00
|
|
|
|
2008-01-23 21:11:07 +08:00
|
|
|
sbc_cap.channel_mode = ( SBC_CHANNEL_MODE_JOINT_STEREO |
|
|
|
|
SBC_CHANNEL_MODE_STEREO |
|
|
|
|
SBC_CHANNEL_MODE_DUAL_CHANNEL |
|
|
|
|
SBC_CHANNEL_MODE_MONO );
|
2007-08-11 19:05:24 +08:00
|
|
|
|
2008-01-23 21:11:07 +08:00
|
|
|
sbc_cap.block_length = ( SBC_BLOCK_LENGTH_16 |
|
|
|
|
SBC_BLOCK_LENGTH_12 |
|
|
|
|
SBC_BLOCK_LENGTH_8 |
|
|
|
|
SBC_BLOCK_LENGTH_4 );
|
2007-08-11 19:05:24 +08:00
|
|
|
|
2008-01-23 21:11:07 +08:00
|
|
|
sbc_cap.subbands = ( SBC_SUBBANDS_8 | SBC_SUBBANDS_4 );
|
2007-08-11 19:05:24 +08:00
|
|
|
|
2008-01-23 21:11:07 +08:00
|
|
|
sbc_cap.allocation_method = ( SBC_ALLOCATION_LOUDNESS |
|
|
|
|
SBC_ALLOCATION_SNR );
|
2007-08-11 19:05:24 +08:00
|
|
|
|
2007-09-04 05:21:20 +08:00
|
|
|
sbc_cap.min_bitpool = MIN_BITPOOL;
|
|
|
|
sbc_cap.max_bitpool = MAX_BITPOOL;
|
2007-08-11 19:05:24 +08:00
|
|
|
|
|
|
|
media_codec = avdtp_service_cap_new(AVDTP_MEDIA_CODEC, &sbc_cap,
|
|
|
|
sizeof(sbc_cap));
|
|
|
|
|
|
|
|
*caps = g_slist_append(*caps, media_codec);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2008-01-23 21:16:02 +08:00
|
|
|
static gboolean mpeg_setconf_ind(struct avdtp *session,
|
|
|
|
struct avdtp_local_sep *sep,
|
|
|
|
struct avdtp_stream *stream,
|
|
|
|
GSList *caps, uint8_t *err,
|
|
|
|
uint8_t *category, void *user_data)
|
|
|
|
{
|
|
|
|
struct a2dp_sep *a2dp_sep = user_data;
|
2008-05-29 16:05:16 +08:00
|
|
|
struct audio_device *dev;
|
2008-01-23 21:16:02 +08:00
|
|
|
|
|
|
|
if (a2dp_sep->type == AVDTP_SEP_TYPE_SINK)
|
2008-01-23 21:21:57 +08:00
|
|
|
debug("Sink %p: Set_Configuration_Ind", sep);
|
2008-01-23 21:16:02 +08:00
|
|
|
else
|
2008-01-23 21:21:57 +08:00
|
|
|
debug("Source %p: Set_Configuration_Ind", sep);
|
2008-01-23 21:16:02 +08:00
|
|
|
|
|
|
|
dev = a2dp_get_dev(session);
|
|
|
|
if (!dev) {
|
|
|
|
*err = AVDTP_UNSUPPORTED_CONFIGURATION;
|
|
|
|
*category = 0x00;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
avdtp_stream_add_cb(session, stream, stream_state_changed, a2dp_sep);
|
|
|
|
a2dp_sep->stream = stream;
|
|
|
|
|
|
|
|
if (a2dp_sep->type == AVDTP_SEP_TYPE_SOURCE)
|
|
|
|
sink_new_stream(dev, session, stream);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2008-01-23 21:21:57 +08:00
|
|
|
static gboolean mpeg_getcap_ind(struct avdtp *session,
|
|
|
|
struct avdtp_local_sep *sep,
|
2008-01-23 21:16:02 +08:00
|
|
|
GSList **caps, uint8_t *err, void *user_data)
|
|
|
|
{
|
|
|
|
struct a2dp_sep *a2dp_sep = user_data;
|
|
|
|
struct avdtp_service_capability *media_transport, *media_codec;
|
|
|
|
struct mpeg_codec_cap mpeg_cap;
|
|
|
|
|
|
|
|
if (a2dp_sep->type == AVDTP_SEP_TYPE_SINK)
|
2008-01-23 21:21:57 +08:00
|
|
|
debug("Sink %p: Get_Capability_Ind", sep);
|
2008-01-23 21:16:02 +08:00
|
|
|
else
|
2008-01-23 21:21:57 +08:00
|
|
|
debug("Source %p: Get_Capability_Ind", sep);
|
2008-01-23 21:16:02 +08:00
|
|
|
|
|
|
|
*caps = NULL;
|
|
|
|
|
|
|
|
media_transport = avdtp_service_cap_new(AVDTP_MEDIA_TRANSPORT,
|
|
|
|
NULL, 0);
|
|
|
|
|
|
|
|
*caps = g_slist_append(*caps, media_transport);
|
|
|
|
|
|
|
|
memset(&mpeg_cap, 0, sizeof(struct mpeg_codec_cap));
|
|
|
|
|
|
|
|
mpeg_cap.cap.media_type = AVDTP_MEDIA_TYPE_AUDIO;
|
|
|
|
mpeg_cap.cap.media_codec_type = A2DP_CODEC_MPEG12;
|
|
|
|
|
|
|
|
mpeg_cap.frequency = ( MPEG_SAMPLING_FREQ_48000 |
|
|
|
|
MPEG_SAMPLING_FREQ_44100 |
|
|
|
|
MPEG_SAMPLING_FREQ_32000 |
|
|
|
|
MPEG_SAMPLING_FREQ_24000 |
|
|
|
|
MPEG_SAMPLING_FREQ_22050 |
|
|
|
|
MPEG_SAMPLING_FREQ_16000 );
|
|
|
|
|
|
|
|
mpeg_cap.channel_mode = ( MPEG_CHANNEL_MODE_JOINT_STEREO |
|
|
|
|
MPEG_CHANNEL_MODE_STEREO |
|
|
|
|
MPEG_CHANNEL_MODE_DUAL_CHANNEL |
|
|
|
|
MPEG_CHANNEL_MODE_MONO );
|
|
|
|
|
|
|
|
mpeg_cap.layer = ( MPEG_LAYER_MP3 | MPEG_LAYER_MP2 | MPEG_LAYER_MP1 );
|
|
|
|
|
|
|
|
mpeg_cap.bitrate = 0xFFFF;
|
|
|
|
|
|
|
|
media_codec = avdtp_service_cap_new(AVDTP_MEDIA_CODEC, &mpeg_cap,
|
|
|
|
sizeof(mpeg_cap));
|
|
|
|
|
|
|
|
*caps = g_slist_append(*caps, media_codec);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2007-08-13 06:43:14 +08:00
|
|
|
static void setconf_cfm(struct avdtp *session, struct avdtp_local_sep *sep,
|
2007-08-17 05:48:33 +08:00
|
|
|
struct avdtp_stream *stream,
|
2007-08-24 20:15:20 +08:00
|
|
|
struct avdtp_error *err, void *user_data)
|
2007-08-11 19:05:24 +08:00
|
|
|
{
|
2007-08-24 20:15:20 +08:00
|
|
|
struct a2dp_sep *a2dp_sep = user_data;
|
2007-12-04 06:41:29 +08:00
|
|
|
struct a2dp_setup *setup;
|
2008-05-29 16:05:16 +08:00
|
|
|
struct audio_device *dev;
|
2007-08-17 05:48:33 +08:00
|
|
|
int ret;
|
2007-08-16 23:42:10 +08:00
|
|
|
|
2007-08-24 20:15:20 +08:00
|
|
|
if (a2dp_sep->type == AVDTP_SEP_TYPE_SINK)
|
2008-01-23 21:21:57 +08:00
|
|
|
debug("Sink %p: Set_Configuration_Cfm", sep);
|
2007-08-24 20:15:20 +08:00
|
|
|
else
|
2008-01-23 21:21:57 +08:00
|
|
|
debug("Source %p: Set_Configuration_Cfm", sep);
|
2007-08-16 23:42:10 +08:00
|
|
|
|
2007-08-31 16:28:22 +08:00
|
|
|
setup = find_setup_by_session(session);
|
|
|
|
|
2007-08-17 05:48:33 +08:00
|
|
|
if (err) {
|
2007-12-08 06:29:26 +08:00
|
|
|
if (setup) {
|
|
|
|
setup->err = err;
|
|
|
|
finalize_config(setup);
|
|
|
|
}
|
2007-08-17 05:48:33 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-08-20 23:12:33 +08:00
|
|
|
avdtp_stream_add_cb(session, stream, stream_state_changed, a2dp_sep);
|
2007-08-19 05:57:26 +08:00
|
|
|
a2dp_sep->stream = stream;
|
2007-08-16 23:42:10 +08:00
|
|
|
|
|
|
|
if (!setup)
|
|
|
|
return;
|
|
|
|
|
2007-08-31 18:25:18 +08:00
|
|
|
dev = a2dp_get_dev(session);
|
|
|
|
|
2007-08-30 17:13:51 +08:00
|
|
|
/* Notify sink.c of the new stream */
|
2007-08-31 18:25:18 +08:00
|
|
|
sink_new_stream(dev, session, setup->stream);
|
2007-08-30 17:13:51 +08:00
|
|
|
|
2007-08-17 05:48:33 +08:00
|
|
|
ret = avdtp_open(session, stream);
|
|
|
|
if (ret < 0) {
|
|
|
|
error("Error on avdtp_open %s (%d)", strerror(-ret),
|
|
|
|
-ret);
|
2007-08-20 23:12:33 +08:00
|
|
|
setup->stream = NULL;
|
2007-12-04 06:41:29 +08:00
|
|
|
finalize_config_errno(setup, ret);
|
2007-08-16 23:42:10 +08:00
|
|
|
}
|
2007-08-11 19:05:24 +08:00
|
|
|
}
|
|
|
|
|
2007-08-13 06:43:14 +08:00
|
|
|
static gboolean getconf_ind(struct avdtp *session, struct avdtp_local_sep *sep,
|
2007-08-24 20:15:20 +08:00
|
|
|
uint8_t *err, void *user_data)
|
2007-08-11 19:05:24 +08:00
|
|
|
{
|
2007-08-24 20:15:20 +08:00
|
|
|
struct a2dp_sep *a2dp_sep = user_data;
|
|
|
|
|
|
|
|
if (a2dp_sep->type == AVDTP_SEP_TYPE_SINK)
|
2008-01-23 21:21:57 +08:00
|
|
|
debug("Sink %p: Get_Configuration_Ind");
|
2007-08-11 19:05:24 +08:00
|
|
|
else
|
2008-01-23 21:21:57 +08:00
|
|
|
debug("Source %p: Get_Configuration_Ind");
|
2007-08-11 19:05:24 +08:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2007-08-13 06:43:14 +08:00
|
|
|
static void getconf_cfm(struct avdtp *session, struct avdtp_local_sep *sep,
|
2007-08-24 20:15:20 +08:00
|
|
|
struct avdtp_stream *stream, struct avdtp_error *err,
|
|
|
|
void *user_data)
|
2007-08-11 19:05:24 +08:00
|
|
|
{
|
2007-08-24 20:15:20 +08:00
|
|
|
struct a2dp_sep *a2dp_sep = user_data;
|
|
|
|
|
|
|
|
if (a2dp_sep->type == AVDTP_SEP_TYPE_SINK)
|
2008-01-23 21:21:57 +08:00
|
|
|
debug("Sink %p: Set_Configuration_Cfm", sep);
|
2007-08-11 19:05:24 +08:00
|
|
|
else
|
2008-01-23 21:21:57 +08:00
|
|
|
debug("Source %p: Set_Configuration_Cfm", sep);
|
2007-08-11 19:05:24 +08:00
|
|
|
}
|
|
|
|
|
2007-08-13 06:43:14 +08:00
|
|
|
static gboolean open_ind(struct avdtp *session, struct avdtp_local_sep *sep,
|
2007-08-24 20:15:20 +08:00
|
|
|
struct avdtp_stream *stream, uint8_t *err,
|
|
|
|
void *user_data)
|
2007-08-11 19:05:24 +08:00
|
|
|
{
|
2007-08-24 20:15:20 +08:00
|
|
|
struct a2dp_sep *a2dp_sep = user_data;
|
|
|
|
|
|
|
|
if (a2dp_sep->type == AVDTP_SEP_TYPE_SINK)
|
2008-01-23 21:21:57 +08:00
|
|
|
debug("Sink %p: Open_Ind", sep);
|
2007-08-11 19:05:24 +08:00
|
|
|
else
|
2008-01-23 21:21:57 +08:00
|
|
|
debug("Source %p: Open_Ind", sep);
|
2007-08-11 19:05:24 +08:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2007-08-13 06:43:14 +08:00
|
|
|
static void open_cfm(struct avdtp *session, struct avdtp_local_sep *sep,
|
2007-08-24 20:15:20 +08:00
|
|
|
struct avdtp_stream *stream, struct avdtp_error *err,
|
|
|
|
void *user_data)
|
2007-08-11 19:05:24 +08:00
|
|
|
{
|
2007-08-24 20:15:20 +08:00
|
|
|
struct a2dp_sep *a2dp_sep = user_data;
|
2007-12-04 06:41:29 +08:00
|
|
|
struct a2dp_setup *setup;
|
2007-08-24 20:15:20 +08:00
|
|
|
|
|
|
|
if (a2dp_sep->type == AVDTP_SEP_TYPE_SINK)
|
2008-01-23 21:21:57 +08:00
|
|
|
debug("Sink %p: Open_Cfm", sep);
|
2007-08-11 19:05:24 +08:00
|
|
|
else
|
2008-01-23 21:21:57 +08:00
|
|
|
debug("Source %p: Open_Cfm", sep);
|
2007-08-16 06:57:49 +08:00
|
|
|
|
2007-08-31 16:28:22 +08:00
|
|
|
setup = find_setup_by_session(session);
|
2007-08-16 23:42:10 +08:00
|
|
|
if (!setup)
|
2007-08-16 06:57:49 +08:00
|
|
|
return;
|
|
|
|
|
2007-08-16 23:42:10 +08:00
|
|
|
if (setup->canceled) {
|
2007-08-17 05:48:33 +08:00
|
|
|
if (!err)
|
|
|
|
avdtp_close(session, stream);
|
2007-12-04 06:41:29 +08:00
|
|
|
setup_unref(setup);
|
2007-08-16 23:42:10 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-12-04 06:41:29 +08:00
|
|
|
if (setup->reconfigure)
|
|
|
|
setup->reconfigure = FALSE;
|
|
|
|
|
2007-08-17 05:48:33 +08:00
|
|
|
if (err) {
|
|
|
|
setup->stream = NULL;
|
2007-12-08 06:29:26 +08:00
|
|
|
setup->err = err;
|
2007-08-30 03:38:37 +08:00
|
|
|
}
|
2008-10-20 03:27:41 +08:00
|
|
|
|
|
|
|
finalize_config(setup);
|
2007-08-11 19:05:24 +08:00
|
|
|
}
|
|
|
|
|
2007-08-19 05:57:26 +08:00
|
|
|
static gboolean suspend_timeout(struct a2dp_sep *sep)
|
|
|
|
{
|
|
|
|
if (avdtp_suspend(sep->session, sep->stream) == 0)
|
|
|
|
sep->suspending = TRUE;
|
|
|
|
|
2007-08-20 23:12:33 +08:00
|
|
|
sep->suspend_timer = 0;
|
2007-08-19 05:57:26 +08:00
|
|
|
|
|
|
|
avdtp_unref(sep->session);
|
|
|
|
sep->session = NULL;
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2007-08-13 06:43:14 +08:00
|
|
|
static gboolean start_ind(struct avdtp *session, struct avdtp_local_sep *sep,
|
2007-08-24 20:15:20 +08:00
|
|
|
struct avdtp_stream *stream, uint8_t *err,
|
|
|
|
void *user_data)
|
2007-08-11 19:05:24 +08:00
|
|
|
{
|
2007-08-24 20:15:20 +08:00
|
|
|
struct a2dp_sep *a2dp_sep = user_data;
|
2008-10-20 03:14:22 +08:00
|
|
|
struct a2dp_setup *setup;
|
2007-08-19 05:57:26 +08:00
|
|
|
|
2007-08-24 20:15:20 +08:00
|
|
|
if (a2dp_sep->type == AVDTP_SEP_TYPE_SINK)
|
2008-01-23 21:21:57 +08:00
|
|
|
debug("Sink %p: Start_Ind", sep);
|
2007-08-24 20:15:20 +08:00
|
|
|
else
|
2008-01-23 21:21:57 +08:00
|
|
|
debug("Source %p: Start_Ind", sep);
|
2007-08-14 03:14:26 +08:00
|
|
|
|
2008-10-20 03:14:22 +08:00
|
|
|
setup = find_setup_by_session(session);
|
|
|
|
if (setup) {
|
|
|
|
if (setup->canceled)
|
|
|
|
setup_unref(setup);
|
|
|
|
else
|
|
|
|
finalize_resume(setup);
|
|
|
|
}
|
|
|
|
|
2007-10-22 17:01:09 +08:00
|
|
|
if (!a2dp_sep->locked) {
|
|
|
|
a2dp_sep->session = avdtp_ref(session);
|
2008-11-15 04:27:16 +08:00
|
|
|
a2dp_sep->suspend_timer = g_timeout_add_seconds(SUSPEND_TIMEOUT,
|
2007-08-19 05:57:26 +08:00
|
|
|
(GSourceFunc) suspend_timeout,
|
|
|
|
a2dp_sep);
|
2007-10-22 17:01:09 +08:00
|
|
|
}
|
|
|
|
|
2007-08-19 05:57:26 +08:00
|
|
|
return TRUE;
|
2007-08-11 19:05:24 +08:00
|
|
|
}
|
|
|
|
|
2007-08-13 06:43:14 +08:00
|
|
|
static void start_cfm(struct avdtp *session, struct avdtp_local_sep *sep,
|
2007-08-24 20:15:20 +08:00
|
|
|
struct avdtp_stream *stream, struct avdtp_error *err,
|
|
|
|
void *user_data)
|
2007-08-11 19:05:24 +08:00
|
|
|
{
|
2007-08-24 20:15:20 +08:00
|
|
|
struct a2dp_sep *a2dp_sep = user_data;
|
2007-12-04 06:41:29 +08:00
|
|
|
struct a2dp_setup *setup;
|
2007-08-24 20:15:20 +08:00
|
|
|
|
|
|
|
if (a2dp_sep->type == AVDTP_SEP_TYPE_SINK)
|
2008-01-23 21:21:57 +08:00
|
|
|
debug("Sink %p: Start_Cfm", sep);
|
2007-08-11 19:05:24 +08:00
|
|
|
else
|
2008-01-23 21:21:57 +08:00
|
|
|
debug("Source %p: Start_Cfm", sep);
|
2007-08-16 23:42:10 +08:00
|
|
|
|
2007-08-31 16:28:22 +08:00
|
|
|
setup = find_setup_by_session(session);
|
2007-08-16 23:42:10 +08:00
|
|
|
if (!setup)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (setup->canceled) {
|
2007-08-17 05:48:33 +08:00
|
|
|
if (!err)
|
|
|
|
avdtp_close(session, stream);
|
2007-12-04 06:41:29 +08:00
|
|
|
setup_unref(setup);
|
2007-08-16 23:42:10 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-09-28 21:46:55 +08:00
|
|
|
if (err) {
|
2007-08-17 05:48:33 +08:00
|
|
|
setup->stream = NULL;
|
2007-12-08 06:29:26 +08:00
|
|
|
setup->err = err;
|
2007-09-28 21:46:55 +08:00
|
|
|
}
|
2008-10-20 03:27:41 +08:00
|
|
|
|
|
|
|
finalize_resume(setup);
|
2007-08-11 19:05:24 +08:00
|
|
|
}
|
|
|
|
|
2007-08-13 06:43:14 +08:00
|
|
|
static gboolean suspend_ind(struct avdtp *session, struct avdtp_local_sep *sep,
|
2007-08-24 20:15:20 +08:00
|
|
|
struct avdtp_stream *stream, uint8_t *err,
|
|
|
|
void *user_data)
|
2007-08-11 19:05:24 +08:00
|
|
|
{
|
2007-08-24 20:15:20 +08:00
|
|
|
struct a2dp_sep *a2dp_sep = user_data;
|
|
|
|
|
|
|
|
if (a2dp_sep->type == AVDTP_SEP_TYPE_SINK)
|
2008-01-23 21:21:57 +08:00
|
|
|
debug("Sink %p: Suspend_Ind", sep);
|
2007-08-11 19:05:24 +08:00
|
|
|
else
|
2008-01-23 21:21:57 +08:00
|
|
|
debug("Source %p: Suspend_Ind", sep);
|
2007-10-10 17:13:30 +08:00
|
|
|
|
|
|
|
if (a2dp_sep->suspend_timer) {
|
|
|
|
g_source_remove(a2dp_sep->suspend_timer);
|
2007-10-10 17:14:07 +08:00
|
|
|
a2dp_sep->suspend_timer = 0;
|
2007-10-22 17:01:09 +08:00
|
|
|
avdtp_unref(a2dp_sep->session);
|
|
|
|
a2dp_sep->session = NULL;
|
2007-10-10 17:13:30 +08:00
|
|
|
}
|
|
|
|
|
2007-08-11 19:05:24 +08:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2007-08-13 06:43:14 +08:00
|
|
|
static void suspend_cfm(struct avdtp *session, struct avdtp_local_sep *sep,
|
2007-08-24 20:15:20 +08:00
|
|
|
struct avdtp_stream *stream, struct avdtp_error *err,
|
|
|
|
void *user_data)
|
2007-08-11 19:05:24 +08:00
|
|
|
{
|
2007-08-24 20:15:20 +08:00
|
|
|
struct a2dp_sep *a2dp_sep = user_data;
|
2007-12-04 06:41:29 +08:00
|
|
|
struct a2dp_setup *setup;
|
2007-12-07 17:36:32 +08:00
|
|
|
gboolean start;
|
2007-08-19 05:57:26 +08:00
|
|
|
|
2007-08-24 20:15:20 +08:00
|
|
|
if (a2dp_sep->type == AVDTP_SEP_TYPE_SINK)
|
2008-01-23 21:21:57 +08:00
|
|
|
debug("Sink %p: Suspend_Cfm", sep);
|
2007-08-24 20:15:20 +08:00
|
|
|
else
|
2008-01-23 21:21:57 +08:00
|
|
|
debug("Source %p: Suspend_Cfm", sep);
|
2007-08-16 23:42:10 +08:00
|
|
|
|
2007-08-19 05:57:26 +08:00
|
|
|
a2dp_sep->suspending = FALSE;
|
2007-08-16 23:42:10 +08:00
|
|
|
|
2007-08-31 16:28:22 +08:00
|
|
|
setup = find_setup_by_session(session);
|
|
|
|
if (!setup)
|
|
|
|
return;
|
|
|
|
|
2007-12-07 17:36:32 +08:00
|
|
|
start = setup->start;
|
|
|
|
setup->start = FALSE;
|
|
|
|
|
2007-08-17 05:48:33 +08:00
|
|
|
if (err) {
|
2007-12-04 06:41:29 +08:00
|
|
|
setup->stream = NULL;
|
2007-12-08 06:29:26 +08:00
|
|
|
setup->err = err;
|
|
|
|
finalize_suspend(setup);
|
2007-08-16 23:42:10 +08:00
|
|
|
}
|
2007-12-04 06:41:29 +08:00
|
|
|
else
|
|
|
|
finalize_suspend_errno(setup, 0);
|
2007-12-07 17:36:32 +08:00
|
|
|
|
|
|
|
if (!start)
|
|
|
|
return;
|
|
|
|
|
2007-12-08 06:29:26 +08:00
|
|
|
if (err) {
|
|
|
|
setup->err = err;
|
|
|
|
finalize_suspend(setup);
|
|
|
|
} else if (avdtp_start(session, a2dp_sep->stream) < 0) {
|
2007-12-07 17:36:32 +08:00
|
|
|
struct avdtp_error start_err;
|
|
|
|
error("avdtp_start failed");
|
|
|
|
avdtp_error_init(&start_err, AVDTP_ERROR_ERRNO, EIO);
|
2007-12-08 06:29:26 +08:00
|
|
|
setup->err = err;
|
|
|
|
finalize_suspend(setup);
|
2007-12-07 17:36:32 +08:00
|
|
|
}
|
2007-08-11 19:05:24 +08:00
|
|
|
}
|
|
|
|
|
2007-08-13 06:43:14 +08:00
|
|
|
static gboolean close_ind(struct avdtp *session, struct avdtp_local_sep *sep,
|
2007-08-24 20:15:20 +08:00
|
|
|
struct avdtp_stream *stream, uint8_t *err,
|
|
|
|
void *user_data)
|
2007-08-11 19:05:24 +08:00
|
|
|
{
|
2007-08-24 20:15:20 +08:00
|
|
|
struct a2dp_sep *a2dp_sep = user_data;
|
2007-08-19 05:57:26 +08:00
|
|
|
|
2007-08-24 20:15:20 +08:00
|
|
|
if (a2dp_sep->type == AVDTP_SEP_TYPE_SINK)
|
2008-01-23 21:21:57 +08:00
|
|
|
debug("Sink %p: Close_Ind", sep);
|
2007-08-24 20:15:20 +08:00
|
|
|
else
|
2008-01-23 21:21:57 +08:00
|
|
|
debug("Source %p: Close_Ind", sep);
|
2007-08-16 23:42:10 +08:00
|
|
|
|
2007-08-11 19:05:24 +08:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2008-03-08 03:02:55 +08:00
|
|
|
static gboolean a2dp_reconfigure(gpointer data)
|
2007-12-04 06:41:29 +08:00
|
|
|
{
|
|
|
|
struct a2dp_setup *setup = data;
|
|
|
|
struct avdtp_local_sep *lsep;
|
|
|
|
struct avdtp_remote_sep *rsep;
|
2008-03-08 03:02:55 +08:00
|
|
|
struct avdtp_service_capability *cap;
|
|
|
|
struct avdtp_media_codec_capability *codec_cap = NULL;
|
|
|
|
GSList *l;
|
2007-12-04 06:41:29 +08:00
|
|
|
int posix_err;
|
|
|
|
|
2008-03-08 03:02:55 +08:00
|
|
|
for (l = setup->client_caps; l != NULL; l = l->next) {
|
|
|
|
cap = l->data;
|
|
|
|
|
|
|
|
if (cap->category != AVDTP_MEDIA_CODEC)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
codec_cap = (void *) cap->data;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-04-02 01:06:25 +08:00
|
|
|
if (!codec_cap) {
|
|
|
|
error("Cannot find capabilities to reconfigure");
|
|
|
|
posix_err = -EINVAL;
|
|
|
|
goto failed;
|
|
|
|
}
|
|
|
|
|
2007-12-04 06:41:29 +08:00
|
|
|
posix_err = avdtp_get_seps(setup->session, AVDTP_SEP_TYPE_SINK,
|
2008-03-08 03:02:55 +08:00
|
|
|
codec_cap->media_type,
|
|
|
|
codec_cap->media_codec_type,
|
2007-12-04 06:41:29 +08:00
|
|
|
&lsep, &rsep);
|
|
|
|
if (posix_err < 0) {
|
|
|
|
error("No matching ACP and INT SEPs found");
|
2009-04-02 01:06:25 +08:00
|
|
|
goto failed;
|
2007-12-04 06:41:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
posix_err = avdtp_set_configuration(setup->session, rsep, lsep,
|
|
|
|
setup->client_caps,
|
|
|
|
&setup->stream);
|
|
|
|
if (posix_err < 0) {
|
2009-04-02 01:06:25 +08:00
|
|
|
error("avdtp_set_configuration: %s", strerror(-posix_err));
|
|
|
|
goto failed;
|
2007-12-04 06:41:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
2009-04-02 01:06:25 +08:00
|
|
|
|
|
|
|
failed:
|
|
|
|
finalize_config_errno(setup, posix_err);
|
|
|
|
return FALSE;
|
2007-12-04 06:41:29 +08:00
|
|
|
}
|
|
|
|
|
2007-08-13 06:43:14 +08:00
|
|
|
static void close_cfm(struct avdtp *session, struct avdtp_local_sep *sep,
|
2007-08-24 20:15:20 +08:00
|
|
|
struct avdtp_stream *stream, struct avdtp_error *err,
|
|
|
|
void *user_data)
|
2007-08-11 19:05:24 +08:00
|
|
|
{
|
2007-08-24 20:15:20 +08:00
|
|
|
struct a2dp_sep *a2dp_sep = user_data;
|
2007-12-04 06:41:29 +08:00
|
|
|
struct a2dp_setup *setup;
|
2007-08-19 05:57:26 +08:00
|
|
|
|
2007-08-24 20:15:20 +08:00
|
|
|
if (a2dp_sep->type == AVDTP_SEP_TYPE_SINK)
|
2008-01-23 21:21:57 +08:00
|
|
|
debug("Sink %p: Close_Cfm", sep);
|
2007-08-24 20:15:20 +08:00
|
|
|
else
|
2008-01-23 21:21:57 +08:00
|
|
|
debug("Source %p: Close_Cfm", sep);
|
2007-08-30 03:38:37 +08:00
|
|
|
|
2007-08-31 16:28:22 +08:00
|
|
|
setup = find_setup_by_session(session);
|
2007-08-30 03:38:37 +08:00
|
|
|
if (!setup)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (setup->canceled) {
|
2007-12-04 06:41:29 +08:00
|
|
|
setup_unref(setup);
|
2007-08-30 03:38:37 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (err) {
|
|
|
|
setup->stream = NULL;
|
2007-12-08 06:29:26 +08:00
|
|
|
setup->err = err;
|
|
|
|
finalize_config(setup);
|
2007-09-28 21:46:55 +08:00
|
|
|
return;
|
2007-08-30 03:38:37 +08:00
|
|
|
}
|
|
|
|
|
2007-12-04 06:41:29 +08:00
|
|
|
if (setup->reconfigure)
|
2008-12-15 23:17:22 +08:00
|
|
|
g_timeout_add(RECONFIGURE_TIMEOUT, a2dp_reconfigure, setup);
|
2007-08-11 19:05:24 +08:00
|
|
|
}
|
|
|
|
|
2007-08-13 06:43:14 +08:00
|
|
|
static gboolean abort_ind(struct avdtp *session, struct avdtp_local_sep *sep,
|
2007-08-24 20:15:20 +08:00
|
|
|
struct avdtp_stream *stream, uint8_t *err,
|
|
|
|
void *user_data)
|
2007-08-11 19:05:24 +08:00
|
|
|
{
|
2007-08-24 20:15:20 +08:00
|
|
|
struct a2dp_sep *a2dp_sep = user_data;
|
2007-08-19 05:57:26 +08:00
|
|
|
|
2007-08-24 20:15:20 +08:00
|
|
|
if (a2dp_sep->type == AVDTP_SEP_TYPE_SINK)
|
2008-01-23 21:21:57 +08:00
|
|
|
debug("Sink %p: Abort_Ind", sep);
|
2007-08-24 20:15:20 +08:00
|
|
|
else
|
2008-01-23 21:21:57 +08:00
|
|
|
debug("Source %p: Abort_Ind", sep);
|
2007-08-16 23:42:10 +08:00
|
|
|
|
2007-08-31 18:25:18 +08:00
|
|
|
a2dp_sep->stream = NULL;
|
2007-08-31 16:28:22 +08:00
|
|
|
|
2007-08-11 19:05:24 +08:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2007-08-13 06:43:14 +08:00
|
|
|
static void abort_cfm(struct avdtp *session, struct avdtp_local_sep *sep,
|
2007-08-24 20:15:20 +08:00
|
|
|
struct avdtp_stream *stream, struct avdtp_error *err,
|
|
|
|
void *user_data)
|
2007-08-11 19:05:24 +08:00
|
|
|
{
|
2007-08-24 20:15:20 +08:00
|
|
|
struct a2dp_sep *a2dp_sep = user_data;
|
2007-12-04 06:41:29 +08:00
|
|
|
struct a2dp_setup *setup;
|
2007-08-19 05:57:26 +08:00
|
|
|
|
2007-08-24 20:15:20 +08:00
|
|
|
if (a2dp_sep->type == AVDTP_SEP_TYPE_SINK)
|
2008-01-23 21:21:57 +08:00
|
|
|
debug("Sink %p: Abort_Cfm", sep);
|
2007-08-24 20:15:20 +08:00
|
|
|
else
|
2008-01-23 21:21:57 +08:00
|
|
|
debug("Source %p: Abort_Cfm", sep);
|
2007-12-04 06:41:29 +08:00
|
|
|
|
|
|
|
setup = find_setup_by_session(session);
|
|
|
|
if (!setup)
|
|
|
|
return;
|
|
|
|
|
|
|
|
setup_unref(setup);
|
2007-08-11 19:05:24 +08:00
|
|
|
}
|
|
|
|
|
2007-08-13 06:43:14 +08:00
|
|
|
static gboolean reconf_ind(struct avdtp *session, struct avdtp_local_sep *sep,
|
2007-08-24 20:15:20 +08:00
|
|
|
uint8_t *err, void *user_data)
|
2007-08-11 19:05:24 +08:00
|
|
|
{
|
2007-08-24 20:15:20 +08:00
|
|
|
struct a2dp_sep *a2dp_sep = user_data;
|
|
|
|
|
|
|
|
if (a2dp_sep->type == AVDTP_SEP_TYPE_SINK)
|
2008-01-23 21:21:57 +08:00
|
|
|
debug("Sink %p: ReConfigure_Ind", sep);
|
2007-08-11 19:05:24 +08:00
|
|
|
else
|
2008-01-23 21:21:57 +08:00
|
|
|
debug("Source %p: ReConfigure_Ind", sep);
|
2007-08-11 19:05:24 +08:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2007-08-17 05:48:33 +08:00
|
|
|
static void reconf_cfm(struct avdtp *session, struct avdtp_local_sep *sep,
|
2007-08-24 20:15:20 +08:00
|
|
|
struct avdtp_stream *stream, struct avdtp_error *err,
|
|
|
|
void *user_data)
|
2007-08-11 19:05:24 +08:00
|
|
|
{
|
2007-08-24 20:15:20 +08:00
|
|
|
struct a2dp_sep *a2dp_sep = user_data;
|
2007-12-04 06:41:29 +08:00
|
|
|
struct a2dp_setup *setup;
|
2007-08-24 20:15:20 +08:00
|
|
|
|
|
|
|
if (a2dp_sep->type == AVDTP_SEP_TYPE_SINK)
|
2008-01-23 21:21:57 +08:00
|
|
|
debug("Sink %p: ReConfigure_Cfm", sep);
|
2007-08-11 19:05:24 +08:00
|
|
|
else
|
2008-01-23 21:21:57 +08:00
|
|
|
debug("Source %p: ReConfigure_Cfm", sep);
|
2007-08-30 03:38:37 +08:00
|
|
|
|
2007-08-31 16:28:22 +08:00
|
|
|
setup = find_setup_by_session(session);
|
2007-08-30 03:38:37 +08:00
|
|
|
if (!setup)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (setup->canceled) {
|
|
|
|
if (!err)
|
|
|
|
avdtp_close(session, stream);
|
2007-12-04 06:41:29 +08:00
|
|
|
setup_unref(setup);
|
2007-08-30 03:38:37 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (err) {
|
|
|
|
setup->stream = NULL;
|
2007-12-08 06:29:26 +08:00
|
|
|
setup->err = err;
|
2007-08-30 03:38:37 +08:00
|
|
|
}
|
2008-10-20 03:27:41 +08:00
|
|
|
|
|
|
|
finalize_config(setup);
|
2007-08-11 19:05:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct avdtp_sep_cfm cfm = {
|
|
|
|
.set_configuration = setconf_cfm,
|
|
|
|
.get_configuration = getconf_cfm,
|
|
|
|
.open = open_cfm,
|
|
|
|
.start = start_cfm,
|
|
|
|
.suspend = suspend_cfm,
|
|
|
|
.close = close_cfm,
|
|
|
|
.abort = abort_cfm,
|
|
|
|
.reconfigure = reconf_cfm
|
|
|
|
};
|
|
|
|
|
2008-01-23 21:16:02 +08:00
|
|
|
static struct avdtp_sep_ind sbc_ind = {
|
|
|
|
.get_capability = sbc_getcap_ind,
|
|
|
|
.set_configuration = sbc_setconf_ind,
|
|
|
|
.get_configuration = getconf_ind,
|
|
|
|
.open = open_ind,
|
|
|
|
.start = start_ind,
|
|
|
|
.suspend = suspend_ind,
|
|
|
|
.close = close_ind,
|
|
|
|
.abort = abort_ind,
|
|
|
|
.reconfigure = reconf_ind
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct avdtp_sep_ind mpeg_ind = {
|
|
|
|
.get_capability = mpeg_getcap_ind,
|
|
|
|
.set_configuration = mpeg_setconf_ind,
|
2007-08-11 19:05:24 +08:00
|
|
|
.get_configuration = getconf_ind,
|
|
|
|
.open = open_ind,
|
|
|
|
.start = start_ind,
|
|
|
|
.suspend = suspend_ind,
|
|
|
|
.close = close_ind,
|
|
|
|
.abort = abort_ind,
|
|
|
|
.reconfigure = reconf_ind
|
|
|
|
};
|
|
|
|
|
2008-03-28 07:07:19 +08:00
|
|
|
static sdp_record_t *a2dp_source_record()
|
2007-08-11 19:05:24 +08:00
|
|
|
{
|
|
|
|
sdp_list_t *svclass_id, *pfseq, *apseq, *root;
|
|
|
|
uuid_t root_uuid, l2cap, avdtp, a2src;
|
|
|
|
sdp_profile_desc_t profile[1];
|
|
|
|
sdp_list_t *aproto, *proto[2];
|
2008-03-28 07:07:19 +08:00
|
|
|
sdp_record_t *record;
|
2007-08-11 19:05:24 +08:00
|
|
|
sdp_data_t *psm, *version, *features;
|
|
|
|
uint16_t lp = AVDTP_UUID, ver = 0x0100, feat = 0x000F;
|
|
|
|
|
2008-03-28 07:07:19 +08:00
|
|
|
record = sdp_record_alloc();
|
|
|
|
if (!record)
|
|
|
|
return NULL;
|
2007-08-11 19:05:24 +08:00
|
|
|
|
|
|
|
sdp_uuid16_create(&root_uuid, PUBLIC_BROWSE_GROUP);
|
|
|
|
root = sdp_list_append(0, &root_uuid);
|
2008-03-28 07:07:19 +08:00
|
|
|
sdp_set_browse_groups(record, root);
|
2007-08-11 19:05:24 +08:00
|
|
|
|
|
|
|
sdp_uuid16_create(&a2src, AUDIO_SOURCE_SVCLASS_ID);
|
|
|
|
svclass_id = sdp_list_append(0, &a2src);
|
2008-03-28 07:07:19 +08:00
|
|
|
sdp_set_service_classes(record, svclass_id);
|
2007-08-11 19:05:24 +08:00
|
|
|
|
|
|
|
sdp_uuid16_create(&profile[0].uuid, ADVANCED_AUDIO_PROFILE_ID);
|
|
|
|
profile[0].version = 0x0100;
|
|
|
|
pfseq = sdp_list_append(0, &profile[0]);
|
2008-03-28 07:07:19 +08:00
|
|
|
sdp_set_profile_descs(record, pfseq);
|
2007-08-11 19:05:24 +08:00
|
|
|
|
|
|
|
sdp_uuid16_create(&l2cap, L2CAP_UUID);
|
|
|
|
proto[0] = sdp_list_append(0, &l2cap);
|
|
|
|
psm = sdp_data_alloc(SDP_UINT16, &lp);
|
|
|
|
proto[0] = sdp_list_append(proto[0], psm);
|
|
|
|
apseq = sdp_list_append(0, proto[0]);
|
|
|
|
|
|
|
|
sdp_uuid16_create(&avdtp, AVDTP_UUID);
|
|
|
|
proto[1] = sdp_list_append(0, &avdtp);
|
|
|
|
version = sdp_data_alloc(SDP_UINT16, &ver);
|
|
|
|
proto[1] = sdp_list_append(proto[1], version);
|
|
|
|
apseq = sdp_list_append(apseq, proto[1]);
|
|
|
|
|
|
|
|
aproto = sdp_list_append(0, apseq);
|
2008-03-28 07:07:19 +08:00
|
|
|
sdp_set_access_protos(record, aproto);
|
2007-08-11 19:05:24 +08:00
|
|
|
|
|
|
|
features = sdp_data_alloc(SDP_UINT16, &feat);
|
2008-03-28 07:07:19 +08:00
|
|
|
sdp_attr_add(record, SDP_ATTR_SUPPORTED_FEATURES, features);
|
2007-08-11 19:05:24 +08:00
|
|
|
|
2008-03-28 07:07:19 +08:00
|
|
|
sdp_set_info_attr(record, "Audio Source", 0, 0);
|
2007-08-11 19:05:24 +08:00
|
|
|
|
|
|
|
free(psm);
|
|
|
|
free(version);
|
|
|
|
sdp_list_free(proto[0], 0);
|
|
|
|
sdp_list_free(proto[1], 0);
|
|
|
|
sdp_list_free(apseq, 0);
|
|
|
|
sdp_list_free(pfseq, 0);
|
|
|
|
sdp_list_free(aproto, 0);
|
|
|
|
sdp_list_free(root, 0);
|
|
|
|
sdp_list_free(svclass_id, 0);
|
|
|
|
|
2008-03-28 07:07:19 +08:00
|
|
|
return record;
|
2007-08-11 19:05:24 +08:00
|
|
|
}
|
|
|
|
|
2008-03-28 07:07:19 +08:00
|
|
|
static sdp_record_t *a2dp_sink_record()
|
2007-08-11 19:05:24 +08:00
|
|
|
{
|
2008-03-28 07:07:19 +08:00
|
|
|
return NULL;
|
2007-08-11 19:05:24 +08:00
|
|
|
}
|
|
|
|
|
2008-09-09 05:20:29 +08:00
|
|
|
static struct a2dp_sep *a2dp_add_sep(struct a2dp_server *server, uint8_t type,
|
2008-01-23 21:16:02 +08:00
|
|
|
uint8_t codec)
|
2007-08-11 19:05:24 +08:00
|
|
|
{
|
2007-08-24 20:15:20 +08:00
|
|
|
struct a2dp_sep *sep;
|
|
|
|
GSList **l;
|
2008-03-28 07:07:19 +08:00
|
|
|
sdp_record_t *(*create_record)(void);
|
2007-08-24 20:15:20 +08:00
|
|
|
uint32_t *record_id;
|
2008-03-28 07:07:19 +08:00
|
|
|
sdp_record_t *record;
|
2008-01-23 21:16:02 +08:00
|
|
|
struct avdtp_sep_ind *ind;
|
2007-08-11 19:05:24 +08:00
|
|
|
|
2007-08-24 20:15:20 +08:00
|
|
|
sep = g_new0(struct a2dp_sep, 1);
|
|
|
|
|
2008-01-23 21:16:02 +08:00
|
|
|
ind = (codec == A2DP_CODEC_MPEG12) ? &mpeg_ind : &sbc_ind;
|
2008-09-09 05:20:29 +08:00
|
|
|
sep->sep = avdtp_register_sep(&server->src, type,
|
|
|
|
AVDTP_MEDIA_TYPE_AUDIO, codec, ind,
|
|
|
|
&cfm, sep);
|
2007-08-24 20:15:20 +08:00
|
|
|
if (sep->sep == NULL) {
|
|
|
|
g_free(sep);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2008-01-23 21:16:02 +08:00
|
|
|
sep->codec = codec;
|
2007-08-24 20:15:20 +08:00
|
|
|
sep->type = type;
|
|
|
|
|
|
|
|
if (type == AVDTP_SEP_TYPE_SOURCE) {
|
2008-09-09 05:20:29 +08:00
|
|
|
l = &server->sources;
|
2007-08-24 20:15:20 +08:00
|
|
|
create_record = a2dp_source_record;
|
2008-09-09 05:20:29 +08:00
|
|
|
record_id = &server->source_record_id;
|
2007-08-24 20:15:20 +08:00
|
|
|
} else {
|
2008-09-09 05:20:29 +08:00
|
|
|
l = &server->sinks;
|
2007-08-24 20:15:20 +08:00
|
|
|
create_record = a2dp_sink_record;
|
2008-09-09 05:20:29 +08:00
|
|
|
record_id = &server->sink_record_id;
|
2007-08-24 20:15:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (*record_id != 0)
|
|
|
|
goto add;
|
|
|
|
|
2008-03-28 07:07:19 +08:00
|
|
|
record = create_record();
|
|
|
|
if (!record) {
|
2007-08-24 20:15:20 +08:00
|
|
|
error("Unable to allocate new service record");
|
|
|
|
avdtp_unregister_sep(sep->sep);
|
|
|
|
g_free(sep);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2008-09-09 05:20:29 +08:00
|
|
|
if (add_record_to_server(&server->src, record) < 0) {
|
2008-03-28 07:07:19 +08:00
|
|
|
error("Unable to register A2DP service record");\
|
|
|
|
sdp_record_free(record);
|
2007-08-24 20:15:20 +08:00
|
|
|
avdtp_unregister_sep(sep->sep);
|
|
|
|
g_free(sep);
|
|
|
|
return NULL;
|
|
|
|
}
|
2008-03-28 07:07:19 +08:00
|
|
|
*record_id = record->handle;
|
2007-08-24 20:15:20 +08:00
|
|
|
|
|
|
|
add:
|
|
|
|
*l = g_slist_append(*l, sep);
|
|
|
|
|
|
|
|
return sep;
|
|
|
|
}
|
|
|
|
|
2008-09-09 05:20:29 +08:00
|
|
|
static struct a2dp_server *find_server(GSList *list, const bdaddr_t *src)
|
|
|
|
{
|
|
|
|
GSList *l;
|
|
|
|
|
|
|
|
for (l = list; l; l = l->next) {
|
|
|
|
struct a2dp_server *server = l->data;
|
|
|
|
|
|
|
|
if (bacmp(&server->src, src) == 0)
|
|
|
|
return server;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
int a2dp_register(DBusConnection *conn, const bdaddr_t *src, GKeyFile *config)
|
2007-08-24 20:15:20 +08:00
|
|
|
{
|
2008-01-23 21:27:30 +08:00
|
|
|
int sbc_srcs = 1, sbc_sinks = 0;
|
|
|
|
int mpeg12_srcs = 0, mpeg12_sinks = 0;
|
2008-01-31 21:44:03 +08:00
|
|
|
gboolean source = TRUE, sink = TRUE;
|
2008-01-23 21:27:30 +08:00
|
|
|
char *str;
|
|
|
|
GError *err = NULL;
|
2007-08-28 17:54:21 +08:00
|
|
|
int i;
|
2008-09-09 05:20:29 +08:00
|
|
|
struct a2dp_server *server;
|
2007-08-28 17:54:21 +08:00
|
|
|
|
2008-01-23 21:27:30 +08:00
|
|
|
if (!config)
|
|
|
|
goto proceed;
|
|
|
|
|
|
|
|
str = g_key_file_get_string(config, "General", "Disable", &err);
|
|
|
|
|
|
|
|
if (err) {
|
|
|
|
debug("audio.conf: %s", err->message);
|
2008-10-24 18:44:16 +08:00
|
|
|
g_clear_error(&err);
|
2008-01-23 21:27:30 +08:00
|
|
|
} else {
|
|
|
|
if (strstr(str, "Sink"))
|
2008-01-31 21:44:03 +08:00
|
|
|
source = FALSE;
|
2008-01-23 21:27:30 +08:00
|
|
|
if (strstr(str, "Source"))
|
2008-01-31 21:44:03 +08:00
|
|
|
sink = FALSE;
|
2008-01-23 21:27:30 +08:00
|
|
|
g_free(str);
|
|
|
|
}
|
|
|
|
|
|
|
|
str = g_key_file_get_string(config, "A2DP", "SBCSources", &err);
|
|
|
|
if (err) {
|
|
|
|
debug("audio.conf: %s", err->message);
|
2008-10-24 18:44:16 +08:00
|
|
|
g_clear_error(&err);
|
2008-01-23 21:27:30 +08:00
|
|
|
} else {
|
|
|
|
sbc_srcs = atoi(str);
|
|
|
|
g_free(str);
|
|
|
|
}
|
|
|
|
|
|
|
|
str = g_key_file_get_string(config, "A2DP", "MPEG12Sources", &err);
|
|
|
|
if (err) {
|
|
|
|
debug("audio.conf: %s", err->message);
|
2008-10-24 18:44:16 +08:00
|
|
|
g_clear_error(&err);
|
2008-01-23 21:27:30 +08:00
|
|
|
} else {
|
|
|
|
mpeg12_srcs = atoi(str);
|
|
|
|
g_free(str);
|
|
|
|
}
|
|
|
|
|
|
|
|
str = g_key_file_get_string(config, "A2DP", "SBCSinks", &err);
|
|
|
|
if (err) {
|
|
|
|
debug("audio.conf: %s", err->message);
|
2008-10-24 18:44:16 +08:00
|
|
|
g_clear_error(&err);
|
2008-01-23 21:27:30 +08:00
|
|
|
} else {
|
|
|
|
sbc_sinks = atoi(str);
|
|
|
|
g_free(str);
|
|
|
|
}
|
|
|
|
|
|
|
|
str = g_key_file_get_string(config, "A2DP", "MPEG12Sinks", &err);
|
|
|
|
if (err) {
|
|
|
|
debug("audio.conf: %s", err->message);
|
2008-10-24 18:44:16 +08:00
|
|
|
g_clear_error(&err);
|
2008-01-23 21:27:30 +08:00
|
|
|
} else {
|
|
|
|
mpeg12_sinks = atoi(str);
|
|
|
|
g_free(str);
|
|
|
|
}
|
2007-08-11 19:05:24 +08:00
|
|
|
|
2008-01-23 21:27:30 +08:00
|
|
|
proceed:
|
2008-09-09 05:20:29 +08:00
|
|
|
if (!connection)
|
|
|
|
connection = dbus_connection_ref(conn);
|
|
|
|
|
|
|
|
server = find_server(servers, src);
|
|
|
|
if (!server) {
|
2009-02-18 05:23:32 +08:00
|
|
|
int av_err;
|
|
|
|
|
2008-09-09 05:20:29 +08:00
|
|
|
server = g_new0(struct a2dp_server, 1);
|
|
|
|
if (!server)
|
|
|
|
return -ENOMEM;
|
2009-02-18 05:23:32 +08:00
|
|
|
|
|
|
|
av_err = avdtp_init(src, config);
|
|
|
|
if (av_err < 0)
|
|
|
|
return av_err;
|
|
|
|
|
2008-09-09 05:20:29 +08:00
|
|
|
bacpy(&server->src, src);
|
|
|
|
servers = g_slist_append(servers, server);
|
|
|
|
}
|
2007-08-11 19:05:24 +08:00
|
|
|
|
2008-01-31 21:44:03 +08:00
|
|
|
if (source) {
|
2008-01-23 21:27:30 +08:00
|
|
|
for (i = 0; i < sbc_srcs; i++)
|
2008-09-09 05:20:29 +08:00
|
|
|
a2dp_add_sep(server, AVDTP_SEP_TYPE_SOURCE,
|
2008-01-23 21:27:30 +08:00
|
|
|
A2DP_CODEC_SBC);
|
|
|
|
|
|
|
|
for (i = 0; i < mpeg12_srcs; i++)
|
2008-09-09 05:20:29 +08:00
|
|
|
a2dp_add_sep(server, AVDTP_SEP_TYPE_SOURCE,
|
2008-01-23 21:27:30 +08:00
|
|
|
A2DP_CODEC_MPEG12);
|
2008-01-23 21:16:02 +08:00
|
|
|
}
|
2007-08-11 19:05:24 +08:00
|
|
|
|
2008-01-23 21:27:30 +08:00
|
|
|
if (sink) {
|
|
|
|
for (i = 0; i < sbc_sinks; i++)
|
2008-09-09 05:20:29 +08:00
|
|
|
a2dp_add_sep(server, AVDTP_SEP_TYPE_SINK,
|
2008-01-23 21:27:30 +08:00
|
|
|
A2DP_CODEC_SBC);
|
|
|
|
|
|
|
|
for (i = 0; i < mpeg12_sinks; i++)
|
2008-09-09 05:20:29 +08:00
|
|
|
a2dp_add_sep(server, AVDTP_SEP_TYPE_SINK,
|
2008-01-23 21:27:30 +08:00
|
|
|
A2DP_CODEC_MPEG12);
|
2008-01-23 21:16:02 +08:00
|
|
|
}
|
2007-08-11 19:05:24 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-08-24 20:15:20 +08:00
|
|
|
static void a2dp_unregister_sep(struct a2dp_sep *sep)
|
|
|
|
{
|
|
|
|
avdtp_unregister_sep(sep->sep);
|
|
|
|
g_free(sep);
|
|
|
|
}
|
|
|
|
|
2008-09-09 05:20:29 +08:00
|
|
|
void a2dp_unregister(const bdaddr_t *src)
|
2007-08-11 19:05:24 +08:00
|
|
|
{
|
2008-09-09 05:20:29 +08:00
|
|
|
struct a2dp_server *server;
|
2007-08-11 19:05:24 +08:00
|
|
|
|
2008-09-09 05:20:29 +08:00
|
|
|
server = find_server(servers, src);
|
|
|
|
if (!server)
|
|
|
|
return;
|
2007-08-11 19:05:24 +08:00
|
|
|
|
2008-09-09 05:20:29 +08:00
|
|
|
g_slist_foreach(server->sinks, (GFunc) a2dp_unregister_sep, NULL);
|
|
|
|
g_slist_free(server->sinks);
|
2007-08-11 19:05:24 +08:00
|
|
|
|
2008-09-09 05:20:29 +08:00
|
|
|
g_slist_foreach(server->sources, (GFunc) a2dp_unregister_sep, NULL);
|
|
|
|
g_slist_free(server->sources);
|
|
|
|
|
|
|
|
if (server->source_record_id)
|
|
|
|
remove_record_from_server(server->source_record_id);
|
|
|
|
|
|
|
|
if (server->sink_record_id)
|
|
|
|
remove_record_from_server(server->sink_record_id);
|
|
|
|
|
|
|
|
servers = g_slist_remove(servers, server);
|
|
|
|
g_free(server);
|
|
|
|
|
|
|
|
if (servers)
|
|
|
|
return;
|
2007-08-11 19:05:24 +08:00
|
|
|
|
|
|
|
dbus_connection_unref(connection);
|
2008-09-09 05:20:29 +08:00
|
|
|
connection = NULL;
|
2007-08-11 19:05:24 +08:00
|
|
|
}
|
|
|
|
|
2008-05-29 16:05:16 +08:00
|
|
|
gboolean a2dp_source_cancel(struct audio_device *dev, unsigned int id)
|
2007-08-16 23:42:10 +08:00
|
|
|
{
|
2007-12-04 06:41:29 +08:00
|
|
|
struct a2dp_setup_cb *cb_data;
|
|
|
|
struct a2dp_setup *setup;
|
2007-08-16 23:42:10 +08:00
|
|
|
GSList *l;
|
|
|
|
|
2007-08-31 16:28:22 +08:00
|
|
|
setup = find_setup_by_dev(dev);
|
2007-08-16 23:42:10 +08:00
|
|
|
if (!setup)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
for (cb_data = NULL, l = setup->cb; l != NULL; l = g_slist_next(l)) {
|
2007-12-04 06:41:29 +08:00
|
|
|
struct a2dp_setup_cb *cb = l->data;
|
2007-08-16 23:42:10 +08:00
|
|
|
|
|
|
|
if (cb->id == id) {
|
|
|
|
cb_data = cb;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!cb_data)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
setup->cb = g_slist_remove(setup->cb, cb_data);
|
2007-08-17 00:59:27 +08:00
|
|
|
g_free(cb_data);
|
2007-08-16 23:42:10 +08:00
|
|
|
|
2007-08-31 14:21:52 +08:00
|
|
|
if (!setup->cb) {
|
2007-08-16 23:42:10 +08:00
|
|
|
setup->canceled = TRUE;
|
2007-08-31 16:28:22 +08:00
|
|
|
setup->sep = NULL;
|
2007-08-31 14:21:52 +08:00
|
|
|
}
|
2007-08-16 23:42:10 +08:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2009-03-18 22:20:31 +08:00
|
|
|
struct a2dp_sep *a2dp_source_get(struct avdtp *session,
|
|
|
|
struct avdtp_remote_sep *rsep)
|
|
|
|
{
|
|
|
|
GSList *l;
|
|
|
|
struct a2dp_server *server;
|
|
|
|
struct avdtp_service_capability *cap;
|
|
|
|
struct avdtp_media_codec_capability *codec_cap = NULL;
|
|
|
|
bdaddr_t src;
|
|
|
|
|
|
|
|
avdtp_get_peers(session, &src, NULL);
|
|
|
|
server = find_server(servers, &src);
|
|
|
|
if (!server)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
cap = avdtp_get_codec(rsep);
|
|
|
|
codec_cap = (void *) cap->data;
|
|
|
|
|
|
|
|
for (l = server->sources; l != NULL; l = l->next) {
|
|
|
|
struct a2dp_sep *sep = l->data;
|
|
|
|
|
|
|
|
if (sep->locked)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (sep->codec != codec_cap->media_codec_type)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (!sep->stream || avdtp_has_stream(session, sep->stream))
|
|
|
|
return sep;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int a2dp_source_config(struct avdtp *session, struct a2dp_sep *sep,
|
|
|
|
a2dp_config_cb_t cb, GSList *caps,
|
|
|
|
void *user_data)
|
2007-08-16 23:42:10 +08:00
|
|
|
{
|
2007-12-04 06:41:29 +08:00
|
|
|
struct a2dp_setup_cb *cb_data;
|
2007-08-24 20:15:20 +08:00
|
|
|
GSList *l;
|
2008-09-09 05:20:29 +08:00
|
|
|
struct a2dp_server *server;
|
2007-12-04 06:41:29 +08:00
|
|
|
struct a2dp_setup *setup;
|
2009-03-18 22:20:31 +08:00
|
|
|
struct a2dp_sep *tmp;
|
2007-12-04 06:41:29 +08:00
|
|
|
struct avdtp_local_sep *lsep;
|
|
|
|
struct avdtp_remote_sep *rsep;
|
2008-01-23 21:16:02 +08:00
|
|
|
struct avdtp_service_capability *cap;
|
|
|
|
struct avdtp_media_codec_capability *codec_cap = NULL;
|
2007-12-04 06:41:29 +08:00
|
|
|
int posix_err;
|
2008-09-09 05:20:29 +08:00
|
|
|
bdaddr_t src;
|
|
|
|
|
|
|
|
avdtp_get_peers(session, &src, NULL);
|
|
|
|
server = find_server(servers, &src);
|
|
|
|
if (!server)
|
|
|
|
return 0;
|
2007-08-16 23:42:10 +08:00
|
|
|
|
2008-01-23 21:16:02 +08:00
|
|
|
for (l = caps; l != NULL; l = l->next) {
|
|
|
|
cap = l->data;
|
|
|
|
|
|
|
|
if (cap->category != AVDTP_MEDIA_CODEC)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
codec_cap = (void *) cap->data;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!codec_cap)
|
|
|
|
return 0;
|
|
|
|
|
2009-03-18 22:20:31 +08:00
|
|
|
if (sep->codec != codec_cap->media_codec_type)
|
2007-08-20 16:50:22 +08:00
|
|
|
return 0;
|
|
|
|
|
2008-01-23 21:21:57 +08:00
|
|
|
debug("a2dp_source_config: selected SEP %p", sep->sep);
|
2007-08-24 20:15:20 +08:00
|
|
|
|
2007-12-07 16:04:04 +08:00
|
|
|
cb_data = g_new0(struct a2dp_setup_cb, 1);
|
2007-12-04 06:41:29 +08:00
|
|
|
cb_data->config_cb = cb;
|
2007-08-16 23:42:10 +08:00
|
|
|
cb_data->user_data = user_data;
|
2007-08-17 05:48:33 +08:00
|
|
|
cb_data->id = ++cb_id;
|
2007-08-16 23:42:10 +08:00
|
|
|
|
2007-12-04 06:41:29 +08:00
|
|
|
setup = find_setup_by_session(session);
|
|
|
|
if (!setup) {
|
|
|
|
setup = g_new0(struct a2dp_setup, 1);
|
|
|
|
setup->session = avdtp_ref(session);
|
|
|
|
setups = g_slist_append(setups, setup);
|
2007-08-16 23:42:10 +08:00
|
|
|
}
|
|
|
|
|
2007-12-04 06:41:29 +08:00
|
|
|
setup_ref(setup);
|
2007-08-16 23:42:10 +08:00
|
|
|
setup->cb = g_slist_append(setup->cb, cb_data);
|
2007-12-04 06:41:29 +08:00
|
|
|
setup->sep = sep;
|
2007-08-24 20:15:20 +08:00
|
|
|
setup->stream = sep->stream;
|
2007-12-04 06:41:29 +08:00
|
|
|
setup->client_caps = caps;
|
2007-08-16 23:42:10 +08:00
|
|
|
|
2007-08-24 20:15:20 +08:00
|
|
|
switch (avdtp_sep_get_state(sep->sep)) {
|
2007-08-16 23:42:10 +08:00
|
|
|
case AVDTP_STATE_IDLE:
|
2008-09-09 05:20:29 +08:00
|
|
|
for (l = server->sources; l != NULL; l = l->next) {
|
2008-03-08 03:02:55 +08:00
|
|
|
tmp = l->data;
|
|
|
|
|
|
|
|
if (avdtp_has_stream(session, tmp->stream))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (l != NULL) {
|
|
|
|
setup->reconfigure = TRUE;
|
|
|
|
if (avdtp_close(session, tmp->stream) < 0) {
|
|
|
|
error("avdtp_close failed");
|
|
|
|
goto failed;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2007-12-04 06:41:29 +08:00
|
|
|
if (avdtp_get_seps(session, AVDTP_SEP_TYPE_SINK,
|
2008-01-23 21:16:02 +08:00
|
|
|
codec_cap->media_type,
|
|
|
|
codec_cap->media_codec_type,
|
2007-12-04 06:41:29 +08:00
|
|
|
&lsep, &rsep) < 0) {
|
|
|
|
error("No matching ACP and INT SEPs found");
|
|
|
|
goto failed;
|
|
|
|
}
|
|
|
|
|
|
|
|
posix_err = avdtp_set_configuration(session, rsep, lsep,
|
|
|
|
caps, &setup->stream);
|
|
|
|
if (posix_err < 0) {
|
|
|
|
error("avdtp_set_configuration: %s",
|
|
|
|
strerror(-posix_err));
|
2007-08-16 23:42:10 +08:00
|
|
|
goto failed;
|
2007-08-20 16:50:22 +08:00
|
|
|
}
|
2007-08-16 23:42:10 +08:00
|
|
|
break;
|
|
|
|
case AVDTP_STATE_OPEN:
|
2007-12-04 06:41:29 +08:00
|
|
|
case AVDTP_STATE_STREAMING:
|
2009-03-25 01:28:41 +08:00
|
|
|
if (avdtp_stream_has_capabilities(setup->stream, caps)) {
|
|
|
|
debug("Configuration match: resuming");
|
2007-12-04 06:41:29 +08:00
|
|
|
g_idle_add((GSourceFunc) finalize_config, setup);
|
2009-03-25 01:28:41 +08:00
|
|
|
} else if (!setup->reconfigure) {
|
2007-12-04 06:41:29 +08:00
|
|
|
setup->reconfigure = TRUE;
|
|
|
|
if (avdtp_close(session, sep->stream) < 0) {
|
|
|
|
error("avdtp_close failed");
|
|
|
|
goto failed;
|
2007-08-30 03:38:37 +08:00
|
|
|
}
|
|
|
|
}
|
2007-12-04 06:41:29 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
error("SEP in bad state for requesting a new stream");
|
|
|
|
goto failed;
|
|
|
|
}
|
|
|
|
|
|
|
|
return cb_data->id;
|
|
|
|
|
|
|
|
failed:
|
|
|
|
setup_unref(setup);
|
|
|
|
cb_id--;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int a2dp_source_resume(struct avdtp *session, struct a2dp_sep *sep,
|
|
|
|
a2dp_stream_cb_t cb, void *user_data)
|
|
|
|
{
|
|
|
|
struct a2dp_setup_cb *cb_data;
|
|
|
|
struct a2dp_setup *setup;
|
|
|
|
|
2007-12-07 16:52:31 +08:00
|
|
|
cb_data = g_new0(struct a2dp_setup_cb, 1);
|
2007-12-04 06:41:29 +08:00
|
|
|
cb_data->resume_cb = cb;
|
|
|
|
cb_data->user_data = user_data;
|
|
|
|
cb_data->id = ++cb_id;
|
|
|
|
|
|
|
|
setup = find_setup_by_session(session);
|
|
|
|
if (!setup) {
|
|
|
|
setup = g_new0(struct a2dp_setup, 1);
|
|
|
|
setup->session = avdtp_ref(session);
|
|
|
|
setups = g_slist_append(setups, setup);
|
|
|
|
}
|
|
|
|
|
|
|
|
setup_ref(setup);
|
|
|
|
setup->cb = g_slist_append(setup->cb, cb_data);
|
|
|
|
setup->sep = sep;
|
|
|
|
setup->stream = sep->stream;
|
|
|
|
|
|
|
|
switch (avdtp_sep_get_state(sep->sep)) {
|
|
|
|
case AVDTP_STATE_IDLE:
|
|
|
|
goto failed;
|
|
|
|
break;
|
|
|
|
case AVDTP_STATE_OPEN:
|
|
|
|
if (avdtp_start(session, sep->stream) < 0) {
|
2007-08-20 16:50:22 +08:00
|
|
|
error("avdtp_start failed");
|
2007-08-16 23:42:10 +08:00
|
|
|
goto failed;
|
2007-08-20 16:50:22 +08:00
|
|
|
}
|
2007-08-16 23:42:10 +08:00
|
|
|
break;
|
|
|
|
case AVDTP_STATE_STREAMING:
|
2007-12-04 06:41:29 +08:00
|
|
|
if (!sep->suspending && sep->suspend_timer) {
|
|
|
|
g_source_remove(sep->suspend_timer);
|
|
|
|
sep->suspend_timer = 0;
|
|
|
|
avdtp_unref(sep->session);
|
|
|
|
sep->session = NULL;
|
2007-08-16 23:42:10 +08:00
|
|
|
}
|
2007-12-07 17:36:32 +08:00
|
|
|
if (sep->suspending)
|
|
|
|
setup->start = TRUE;
|
|
|
|
else
|
|
|
|
g_idle_add((GSourceFunc) finalize_resume, setup);
|
2007-08-16 23:42:10 +08:00
|
|
|
break;
|
|
|
|
default:
|
2007-12-04 06:41:29 +08:00
|
|
|
error("SEP in bad state");
|
2007-08-16 23:42:10 +08:00
|
|
|
goto failed;
|
|
|
|
}
|
2007-08-30 03:38:37 +08:00
|
|
|
|
2007-12-04 06:41:29 +08:00
|
|
|
return cb_data->id;
|
|
|
|
|
|
|
|
failed:
|
|
|
|
setup_unref(setup);
|
|
|
|
cb_id--;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int a2dp_source_suspend(struct avdtp *session, struct a2dp_sep *sep,
|
|
|
|
a2dp_stream_cb_t cb, void *user_data)
|
|
|
|
{
|
|
|
|
struct a2dp_setup_cb *cb_data;
|
|
|
|
struct a2dp_setup *setup;
|
|
|
|
|
2007-12-07 16:04:04 +08:00
|
|
|
cb_data = g_new0(struct a2dp_setup_cb, 1);
|
2007-12-04 06:41:29 +08:00
|
|
|
cb_data->suspend_cb = cb;
|
|
|
|
cb_data->user_data = user_data;
|
|
|
|
cb_data->id = ++cb_id;
|
|
|
|
|
|
|
|
setup = find_setup_by_session(session);
|
|
|
|
if (!setup) {
|
|
|
|
setup = g_new0(struct a2dp_setup, 1);
|
|
|
|
setup->session = avdtp_ref(session);
|
|
|
|
setups = g_slist_append(setups, setup);
|
|
|
|
}
|
|
|
|
|
|
|
|
setup_ref(setup);
|
|
|
|
setup->cb = g_slist_append(setup->cb, cb_data);
|
|
|
|
setup->sep = sep;
|
|
|
|
setup->stream = sep->stream;
|
|
|
|
|
|
|
|
switch (avdtp_sep_get_state(sep->sep)) {
|
|
|
|
case AVDTP_STATE_IDLE:
|
|
|
|
error("a2dp_source_suspend: no stream to suspend");
|
|
|
|
goto failed;
|
|
|
|
break;
|
|
|
|
case AVDTP_STATE_OPEN:
|
|
|
|
g_idle_add((GSourceFunc) finalize_suspend, setup);
|
|
|
|
break;
|
|
|
|
case AVDTP_STATE_STREAMING:
|
2007-12-07 17:12:00 +08:00
|
|
|
if (avdtp_suspend(session, sep->stream) < 0) {
|
|
|
|
error("avdtp_suspend failed");
|
2007-12-04 06:41:29 +08:00
|
|
|
goto failed;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
error("SEP in bad state for resume");
|
|
|
|
goto failed;
|
|
|
|
}
|
2007-08-31 16:28:22 +08:00
|
|
|
|
2007-08-16 23:42:10 +08:00
|
|
|
return cb_data->id;
|
|
|
|
|
|
|
|
failed:
|
2007-12-04 06:41:29 +08:00
|
|
|
setup_unref(setup);
|
2007-08-16 23:42:10 +08:00
|
|
|
cb_id--;
|
2007-08-17 05:48:33 +08:00
|
|
|
return 0;
|
2007-08-16 23:42:10 +08:00
|
|
|
}
|
|
|
|
|
2007-08-31 18:25:18 +08:00
|
|
|
gboolean a2dp_sep_lock(struct a2dp_sep *sep, struct avdtp *session)
|
2007-08-16 23:42:10 +08:00
|
|
|
{
|
2007-08-31 18:25:18 +08:00
|
|
|
if (sep->locked)
|
|
|
|
return FALSE;
|
2007-08-24 20:44:12 +08:00
|
|
|
|
2008-01-23 21:21:57 +08:00
|
|
|
debug("SEP %p locked", sep->sep);
|
2007-08-31 18:25:18 +08:00
|
|
|
sep->locked = TRUE;
|
2007-08-24 20:15:20 +08:00
|
|
|
|
2007-08-31 18:25:18 +08:00
|
|
|
return TRUE;
|
2007-08-16 23:42:10 +08:00
|
|
|
}
|
|
|
|
|
2007-08-31 18:25:18 +08:00
|
|
|
gboolean a2dp_sep_unlock(struct a2dp_sep *sep, struct avdtp *session)
|
2007-08-16 23:42:10 +08:00
|
|
|
{
|
|
|
|
avdtp_state_t state;
|
|
|
|
|
2007-08-24 20:15:20 +08:00
|
|
|
state = avdtp_sep_get_state(sep->sep);
|
2007-08-16 23:42:10 +08:00
|
|
|
|
2007-08-24 20:15:20 +08:00
|
|
|
sep->locked = FALSE;
|
2007-08-16 23:42:10 +08:00
|
|
|
|
2008-01-23 21:21:57 +08:00
|
|
|
debug("SEP %p unlocked", sep->sep);
|
2007-08-20 16:50:22 +08:00
|
|
|
|
2007-08-24 20:15:20 +08:00
|
|
|
if (!sep->stream || state == AVDTP_STATE_IDLE)
|
2007-08-16 23:42:10 +08:00
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
switch (state) {
|
|
|
|
case AVDTP_STATE_OPEN:
|
|
|
|
/* Set timer here */
|
|
|
|
break;
|
|
|
|
case AVDTP_STATE_STREAMING:
|
2007-08-24 20:15:20 +08:00
|
|
|
if (avdtp_suspend(session, sep->stream) == 0)
|
|
|
|
sep->suspending = TRUE;
|
2007-08-16 23:42:10 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2009-03-20 03:16:19 +08:00
|
|
|
gboolean a2dp_sep_get_lock(struct a2dp_sep *sep)
|
|
|
|
{
|
|
|
|
return sep->locked;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int stream_cmp(gconstpointer data, gconstpointer user_data)
|
|
|
|
{
|
|
|
|
const struct a2dp_sep *sep = data;
|
|
|
|
const struct avdtp_stream *stream = user_data;
|
|
|
|
|
|
|
|
return (sep->stream != stream);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct a2dp_sep *a2dp_get_sep(struct avdtp *session,
|
|
|
|
struct avdtp_stream *stream)
|
|
|
|
{
|
|
|
|
struct a2dp_server *server;
|
|
|
|
bdaddr_t src, dst;
|
|
|
|
GSList *l;
|
|
|
|
|
|
|
|
avdtp_get_peers(session, &src, &dst);
|
|
|
|
|
|
|
|
for (l = servers; l; l = l->next) {
|
|
|
|
server = l->data;
|
|
|
|
|
|
|
|
if (bacmp(&src, &server->src) == 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!l)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
l = g_slist_find_custom(server->sources, stream, stream_cmp);
|
|
|
|
if (l)
|
|
|
|
return l->data;
|
|
|
|
|
|
|
|
l = g_slist_find_custom(server->sinks, stream, stream_cmp);
|
|
|
|
if (l)
|
|
|
|
return l->data;
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|