struct source_state_callback {
source_state_cb cb;
- struct audio_device *dev;
+ struct btd_service *service;
void *user_data;
unsigned int id;
};
"SOURCE_STATE_PLAYING",
};
-static void source_set_state(struct audio_device *dev, source_state_t new_state)
+static void source_set_state(struct btd_service *service,
+ source_state_t new_state)
{
- struct source *source = btd_service_get_user_data(dev->source);
+ struct source *source = btd_service_get_user_data(service);
+ struct audio_device *dev = source->dev;
source_state_t old_state = source->state;
GSList *l;
for (l = source_callbacks; l != NULL; l = l->next) {
struct source_state_callback *cb = l->data;
- if (cb->dev != dev)
+ if (cb->service != service)
continue;
- cb->cb(dev, old_state, new_state, cb->user_data);
+ cb->cb(service, old_state, new_state, cb->user_data);
}
if (new_state != SOURCE_STATE_DISCONNECTED)
switch (new_state) {
case AVDTP_SESSION_STATE_DISCONNECTED:
- source_set_state(dev, SOURCE_STATE_DISCONNECTED);
+ source_set_state(dev->source, SOURCE_STATE_DISCONNECTED);
break;
case AVDTP_SESSION_STATE_CONNECTING:
- source_set_state(dev, SOURCE_STATE_CONNECTING);
+ source_set_state(dev->source, SOURCE_STATE_CONNECTING);
break;
case AVDTP_SESSION_STATE_CONNECTED:
break;
struct avdtp_error *err,
void *user_data)
{
- struct audio_device *dev = user_data;
- struct source *source = btd_service_get_user_data(dev->source);
+ struct btd_service *service = user_data;
+ struct source *source = btd_service_get_user_data(service);
if (err)
return;
btd_service_disconnecting_complete(source->service, 0);
if (source->disconnect_id > 0) {
- a2dp_cancel(dev, source->disconnect_id);
+ a2dp_cancel(source->dev, source->disconnect_id);
source->disconnect_id = 0;
}
break;
case AVDTP_STATE_OPEN:
btd_service_connecting_complete(source->service, 0);
- source_set_state(dev, SOURCE_STATE_CONNECTED);
+ source_set_state(service, SOURCE_STATE_CONNECTED);
break;
case AVDTP_STATE_STREAMING:
- source_set_state(dev, SOURCE_STATE_PLAYING);
+ source_set_state(service, SOURCE_STATE_PLAYING);
break;
case AVDTP_STATE_CONFIGURED:
case AVDTP_STATE_CLOSING:
return TRUE;
}
-int source_connect(struct audio_device *dev)
+int source_connect(struct btd_service *service)
{
- struct source *source = btd_service_get_user_data(dev->source);
+ struct source *source = btd_service_get_user_data(service);
if (!source->session)
- source->session = avdtp_get(dev);
+ source->session = avdtp_get(source->dev);
if (!source->session) {
DBG("Unable to get a session");
if (source->stream_state >= AVDTP_STATE_OPEN)
return -EALREADY;
- if (!source_setup_stream(source->service, NULL)) {
+ if (!source_setup_stream(service, NULL)) {
DBG("Failed to create a stream");
return -EIO;
}
return 0;
}
-static void source_free(struct audio_device *dev)
+static void source_free(struct btd_service *service)
{
- struct source *source = btd_service_get_user_data(dev->source);
+ struct source *source = btd_service_get_user_data(service);
+ struct audio_device *dev = source->dev;
if (source->cb_id)
avdtp_stream_remove_cb(source->session, source->stream,
dev->source = NULL;
}
-void source_unregister(struct audio_device *dev)
+void source_unregister(struct btd_service *service)
{
- DBG("%s", device_get_path(dev->btd_dev));
+ struct btd_device *dev = btd_service_get_device(service);
+
+ DBG("%s", device_get_path(dev));
- source_free(dev);
+ source_free(service);
}
int source_init(struct audio_device *dev, struct btd_service *service)
return 0;
}
-gboolean source_new_stream(struct audio_device *dev, struct avdtp *session,
+gboolean source_new_stream(struct btd_service *service, struct avdtp *session,
struct avdtp_stream *stream)
{
- struct source *source = btd_service_get_user_data(dev->source);
+ struct source *source = btd_service_get_user_data(service);
if (source->stream)
return FALSE;
source->stream = stream;
source->cb_id = avdtp_stream_add_cb(session, stream,
- stream_state_changed, dev);
+ stream_state_changed, service);
return TRUE;
}
-int source_disconnect(struct audio_device *dev, gboolean shutdown)
+int source_disconnect(struct btd_service *service, gboolean shutdown)
{
- struct source *source = btd_service_get_user_data(dev->source);
+ struct source *source = btd_service_get_user_data(service);
if (!source->session)
return -ENOTCONN;
/* cancel pending connect */
if (source->connect_id > 0) {
- a2dp_cancel(dev, source->connect_id);
+ a2dp_cancel(source->dev, source->connect_id);
source->connect_id = 0;
btd_service_connecting_complete(source->service, -ECANCELED);
return avdtp_close(source->session, source->stream, FALSE);
}
-unsigned int source_add_state_cb(struct audio_device *dev, source_state_cb cb,
- void *user_data)
+unsigned int source_add_state_cb(struct btd_service *service,
+ source_state_cb cb, void *user_data)
{
struct source_state_callback *state_cb;
static unsigned int id = 0;
state_cb = g_new(struct source_state_callback, 1);
state_cb->cb = cb;
- state_cb->dev = dev;
+ state_cb->service = service;
state_cb->user_data = user_data;
state_cb->id = ++id;
SOURCE_STATE_PLAYING,
} source_state_t;
-typedef void (*source_state_cb) (struct audio_device *dev,
+typedef void (*source_state_cb) (struct btd_service *service,
source_state_t old_state,
source_state_t new_state,
void *user_data);
struct btd_service;
-unsigned int source_add_state_cb(struct audio_device *dev, source_state_cb cb,
- void *user_data);
+unsigned int source_add_state_cb(struct btd_service *service,
+ source_state_cb cb, void *user_data);
gboolean source_remove_state_cb(unsigned int id);
int source_init(struct audio_device *dev, struct btd_service *service);
-void source_unregister(struct audio_device *dev);
-int source_connect(struct audio_device *dev);
-gboolean source_new_stream(struct audio_device *dev, struct avdtp *session,
+void source_unregister(struct btd_service *service);
+int source_connect(struct btd_service *service);
+gboolean source_new_stream(struct btd_service *service, struct avdtp *session,
struct avdtp_stream *stream);
gboolean source_setup_stream(struct btd_service *service,
struct avdtp *session);
-int source_disconnect(struct audio_device *dev, gboolean shutdown);
+int source_disconnect(struct btd_service *service, gboolean shutdown);