static void a2dp_discovery_complete(struct avdtp *session, GSList *seps, struct avdtp_error *err, void *user_data) { struct unix_client *client = user_data; char buf[BT_SUGGESTED_BUFFER_SIZE]; struct bt_get_capabilities_rsp *rsp = (void *) buf; struct a2dp_data *a2dp = &client->d.a2dp; GSList *l; if (!g_slist_find(clients, client)) { DBG("Client disconnected during discovery"); return; } if (err) goto failed; memset(buf, 0, sizeof(buf)); client->req_id = 0; rsp->h.type = BT_RESPONSE; rsp->h.name = BT_GET_CAPABILITIES; rsp->h.length = sizeof(*rsp); ba2str(&client->dev->src, rsp->source); ba2str(&client->dev->dst, rsp->destination); strncpy(rsp->object, client->dev->path, sizeof(rsp->object)); for (l = seps; l; l = g_slist_next(l)) { struct avdtp_remote_sep *rsep = l->data; struct a2dp_sep *sep; struct avdtp_service_capability *cap; struct avdtp_stream *stream; uint8_t type, seid, configured = 0, lock = 0; GSList *cl; type = avdtp_get_type(rsep); if (type != AVDTP_SEP_TYPE_SINK && type != AVDTP_SEP_TYPE_SOURCE) continue; cap = avdtp_get_codec(rsep); if (cap->category != AVDTP_MEDIA_CODEC) continue; seid = avdtp_get_seid(rsep); if (client->seid != 0 && client->seid != seid) continue; stream = avdtp_get_stream(rsep); if (stream) { configured = 1; if (client->seid == seid) cap = avdtp_stream_get_codec(stream); } for (cl = clients; cl; cl = cl->next) { struct unix_client *c = cl->data; struct a2dp_data *ca2dp = &c->d.a2dp; if (ca2dp->session == session && c->seid == seid) { lock = c->lock; break; } } sep = a2dp_get_sep(session, stream); if (sep && a2dp_sep_get_lock(sep)) lock = BT_WRITE_LOCK; a2dp_append_codec(rsp, cap, seid, type, configured, lock); } unix_ipc_sendmsg(client, &rsp->h); return; failed: error("discovery failed"); unix_ipc_error(client, BT_GET_CAPABILITIES, EIO); if (a2dp->sep) { a2dp_sep_unlock(a2dp->sep, a2dp->session); a2dp->sep = NULL; } avdtp_unref(a2dp->session); a2dp->session = NULL; a2dp->stream = NULL; }
static void a2dp_config_complete(struct avdtp *session, struct a2dp_sep *sep, struct avdtp_stream *stream, struct avdtp_error *err, void *user_data) { struct unix_client *client = user_data; char buf[BT_SUGGESTED_BUFFER_SIZE]; struct bt_set_configuration_rsp *rsp = (void *) buf; struct a2dp_data *a2dp = &client->d.a2dp; uint16_t imtu, omtu; GSList *caps; client->req_id = 0; if (err) goto failed; memset(buf, 0, sizeof(buf)); if (!stream) goto failed; if (client->cb_id > 0) avdtp_stream_remove_cb(a2dp->session, a2dp->stream, client->cb_id); a2dp->sep = sep; a2dp->stream = stream; if (!avdtp_stream_get_transport(stream, &client->data_fd, &imtu, &omtu, &caps)) { error("Unable to get stream transport"); goto failed; } rsp->h.type = BT_RESPONSE; rsp->h.name = BT_SET_CONFIGURATION; rsp->h.length = sizeof(*rsp); /* FIXME: Use imtu when fd_opt is CFG_FD_OPT_READ */ rsp->link_mtu = omtu; unix_ipc_sendmsg(client, &rsp->h); client->cb_id = avdtp_stream_add_cb(session, stream, stream_state_changed, client); return; failed: error("config failed"); unix_ipc_error(client, BT_SET_CONFIGURATION, EIO); if (a2dp->sep && a2dp_sep_get_lock(a2dp->sep)) { a2dp_sep_unlock(a2dp->sep, a2dp->session); a2dp->sep = NULL; } avdtp_unref(a2dp->session); a2dp->session = NULL; a2dp->stream = NULL; a2dp->sep = NULL; }