diff --git a/profiles/audio/media.c b/profiles/audio/media.c
index b17c555..1faa1c2 100644
--- a/profiles/audio/media.c
+++ b/profiles/audio/media.c
}
static int pac_select(struct bt_bap_pac *lpac, struct bt_bap_pac *rpac,
- uint32_t chan_alloc, struct bt_bap_pac_qos *qos,
+ uint32_t location, struct bt_bap_pac_qos *qos,
bt_bap_pac_select_t cb, void *cb_data, void *user_data)
{
struct media_endpoint *endpoint = user_data;
g_dbus_dict_append_entry(&dict, "Locations", DBUS_TYPE_UINT32,
&loc);
- if (chan_alloc)
+ if (location)
g_dbus_dict_append_entry(&dict, "ChannelAllocation",
- DBUS_TYPE_UINT32, &chan_alloc);
+ DBUS_TYPE_UINT32, &location);
if (metadata) {
key = "Metadata";
diff --git a/profiles/audio/transport.c b/profiles/audio/transport.c
index 23ea267..e207345 100644
--- a/profiles/audio/transport.c
+++ b/profiles/audio/transport.c
media_request_reply(owner->pending, EIO);
transport->owner = NULL;
- if (bap->linked)
- queue_foreach(bt_bap_stream_io_get_links(bap->stream),
- linked_transport_remove_owner, owner);
+ if (bap->linked) {
+ struct bt_bap_stream *link;
+
+ link = bt_bap_stream_io_get_link(bap->stream);
+ linked_transport_remove_owner(link, owner);
+ }
if (owner->watch)
g_dbus_remove_watch(btd_get_dbus_connection(), owner->watch);
DBG("Transport %s Owner %s", transport->path, owner->name);
transport->owner = owner;
- if (bap->linked)
- queue_foreach(bt_bap_stream_io_get_links(bap->stream),
- linked_transport_set_owner, owner);
+ if (bap->linked) {
+ struct bt_bap_stream *link;
+
+ link = bt_bap_stream_io_get_link(bap->stream);
+ linked_transport_set_owner(link, owner);
+ }
owner->transport = transport;
owner->watch = g_dbus_add_disconnect_watch(btd_get_dbus_connection(),
return bap->linked;
}
-static void append_links(void *data, void *user_data)
+static void append_link(void *data, void *user_data)
{
struct bt_bap_stream *stream = data;
DBusMessageIter *array = user_data;
struct media_transport *transport;
+ if (!stream)
+ return;
+
transport = find_transport_by_bap_stream(stream);
if (!transport) {
error("Unable to find transport");
{
struct media_transport *transport = data;
struct bap_transport *bap = transport->data;
- struct queue *links = bt_bap_stream_io_get_links(bap->stream);
+ struct bt_bap_stream *link = bt_bap_stream_io_get_link(bap->stream);
DBusMessageIter array;
dbus_message_iter_open_container(iter, DBUS_TYPE_ARRAY,
DBUS_TYPE_OBJECT_PATH_AS_STRING,
&array);
- queue_foreach(links, append_links, &array);
+ append_link(link, &array);
dbus_message_iter_close_container(iter, &array);
static void bap_update_links(const struct media_transport *transport)
{
struct bap_transport *bap = transport->data;
- struct queue *links = bt_bap_stream_io_get_links(bap->stream);
+ struct bt_bap_stream *link = bt_bap_stream_io_get_link(bap->stream);
- if (bap->linked == !queue_isempty(links))
+ if (bap->linked == (!!link))
return;
- bap->linked = !queue_isempty(links);
+ bap->linked = link ? true : false;
/* Check if the links transport has been create yet */
- if (bap->linked && !queue_find(links, match_link_transport, NULL)) {
+ if (bap->linked && !match_link_transport(link, NULL)) {
bap->linked = false;
return;
}
transport_state_t state)
{
struct bap_transport *bap = transport->data;
+ struct bt_bap_stream *link;
if (!bap->linked)
return;
- /* Update links */
- queue_foreach(bt_bap_stream_io_get_links(bap->stream), link_set_state,
- UINT_TO_PTR(state));
+ link = bt_bap_stream_io_get_link(bap->stream);
+
+ /* Update link */
+ link_set_state(link, UINT_TO_PTR(state));
}
static void bap_state_changed(struct bt_bap_stream *stream, uint8_t old_state,
diff --git a/src/shared/bap.c b/src/shared/bap.c
index af2cc1e..078d308 100644
--- a/src/shared/bap.c
+++ b/src/shared/bap.c
struct iovec *cc;
struct iovec *meta;
struct bt_bap_qos qos;
- struct queue *links;
+ struct bt_bap_stream *link;
struct bt_bap_stream_io *io;
bool client;
void *user_data;
stream_io_free(io);
}
-static void bap_stream_unlink(void *data, void *user_data)
-{
- struct bt_bap_stream *link = data;
- struct bt_bap_stream *stream = user_data;
-
- queue_remove(link->links, stream);
-}
-
static void bap_stream_free(void *data)
{
struct bt_bap_stream *stream = data;
if (stream->ep)
stream->ep->stream = NULL;
- queue_foreach(stream->links, bap_stream_unlink, stream);
- queue_destroy(stream->links, NULL);
+ if (stream->link)
+ stream->link->link = NULL;
+
stream_io_unref(stream->io);
util_iov_free(stream->cc, 1);
util_iov_free(stream->meta, 1);
bap_stream_free(stream);
}
-static void bap_stream_io_link(void *data, void *user_data)
+static bool bap_stream_io_link(const void *data, const void *user_data)
{
- struct bt_bap_stream *stream = data;
- struct bt_bap_stream *link = user_data;
+ struct bt_bap_stream *stream = (void *)data;
+ struct bt_bap_stream *link = (void *)user_data;
- bt_bap_stream_io_link(stream, link);
+ return !bt_bap_stream_io_link(stream, link);
}
static void bap_stream_update_io_links(struct bt_bap_stream *stream)
DBG(bap, "stream %p", stream);
- queue_foreach(bap->streams, bap_stream_io_link, stream);
+ queue_find(bap->streams, bap_stream_io_link, stream);
}
static struct bt_bap_stream_io *stream_io_ref(struct bt_bap_stream_io *io)
return stream_io_ref(sio);
}
-static void stream_find_io(void *data, void *user_data)
-{
- struct bt_bap_stream *stream = data;
- struct bt_bap_stream_io **io = user_data;
-
- if (*io)
- return;
-
- *io = stream->io;
-}
-
static struct bt_bap_stream_io *stream_get_io(struct bt_bap_stream *stream)
{
- struct bt_bap_stream_io *io;
-
if (!stream)
return NULL;
if (stream->io)
return stream->io;
- io = NULL;
- queue_foreach(stream->links, stream_find_io, &io);
+ if (stream->link)
+ return stream->link->io;
- return io;
+ return NULL;
}
static bool stream_io_disconnected(struct io *io, void *user_data);
return true;
}
-static bool match_stream_io(const void *data, const void *user_data)
-{
- const struct bt_bap_stream *stream = data;
- const struct bt_bap_stream_io *io = user_data;
-
- if (!stream->io)
- return false;
-
- return stream->io == io;
-}
-
static bool bap_stream_io_detach(struct bt_bap_stream *stream)
{
struct bt_bap_stream *link;
io = stream->io;
stream->io = NULL;
- link = queue_find(stream->links, match_stream_io, io);
+ link = stream->link;
if (link) {
/* Detach link if in QoS state */
if (link->ep->state == BT_ASCS_ASE_STATE_QOS)
pac->bdb = bdb;
pac->name = name ? strdup(name) : NULL;
pac->type = type;
+
if (codec)
pac->codec = *codec;
- bap_pac_merge(pac, data, metadata);
-
if (qos)
pac->qos = *qos;
+ bap_pac_merge(pac, data, metadata);
+
return pac;
}
return req->id;
}
-static void bap_stream_enable_link(void *data, void *user_data)
-{
- struct bt_bap_stream *stream = data;
- struct iovec *metadata = user_data;
-
- bap_stream_metadata(stream, BT_ASCS_ENABLE, metadata, NULL, NULL);
-}
-
unsigned int bt_bap_stream_enable(struct bt_bap_stream *stream,
bool enable_links,
struct iovec *metadata,
if (!ret || !enable_links)
return ret;
- queue_foreach(stream->links, bap_stream_enable_link, metadata);
+ if (stream->link)
+ bap_stream_metadata(stream->link, BT_ASCS_ENABLE,
+ metadata, NULL, NULL);
break;
case BT_BAP_STREAM_TYPE_BCAST:
if (!bt_bap_stream_io_dir(stream))
return 0;
}
-static void bap_stream_disable_link(void *data, void *user_data)
-{
- struct bt_bap_stream *stream = data;
- struct bt_bap_req *req;
- struct iovec iov;
- struct bt_ascs_disable disable;
-
- memset(&disable, 0, sizeof(disable));
-
- disable.ase = stream->ep->id;
-
- iov.iov_base = &disable;
- iov.iov_len = sizeof(disable);
-
- req = bap_req_new(stream, BT_ASCS_DISABLE, &iov, 1, NULL, NULL);
-
- if (!bap_queue_req(stream->bap, req))
- bap_req_free(req);
-}
-
unsigned int bt_bap_stream_disable(struct bt_bap_stream *stream,
bool disable_links,
bt_bap_stream_func_t func,
}
if (disable_links)
- queue_foreach(stream->links, bap_stream_disable_link,
- NULL);
+ bt_bap_stream_disable(stream->link, false, NULL, NULL);
return req->id;
bap_stream_set_io(stream, INT_TO_PTR(fd));
- queue_foreach(stream->links, bap_stream_set_io, INT_TO_PTR(fd));
+ if (stream->link)
+ bap_stream_set_io(stream, INT_TO_PTR(fd));
return true;
}
if (!stream || !link || stream == link)
return -EINVAL;
- if (queue_find(stream->links, NULL, link))
+ if (stream->link || link->link)
return -EALREADY;
if (stream->client != link->client ||
stream->qos.ucast.cig_id != link->qos.ucast.cig_id ||
- stream->qos.ucast.cis_id != link->qos.ucast.cis_id)
+ stream->qos.ucast.cis_id != link->qos.ucast.cis_id ||
+ stream->ep->dir == link->ep->dir)
return -EINVAL;
- if (!stream->links)
- stream->links = queue_new();
-
- if (!link->links)
- link->links = queue_new();
-
- queue_push_tail(stream->links, link);
- queue_push_tail(link->links, stream);
+ stream->link = link;
+ link->link = stream;
/* Link IOs if already set on stream/link */
if (stream->io && !link->io)
return 0;
}
-struct queue *bt_bap_stream_io_get_links(struct bt_bap_stream *stream)
+struct bt_bap_stream *bt_bap_stream_io_get_link(struct bt_bap_stream *stream)
{
if (!stream)
return NULL;
- return stream->links;
+ return stream->link;
}
static void bap_stream_get_in_qos(void *data, void *user_data)
struct bt_bap_stream *stream = data;
struct bt_bap_qos **qos = user_data;
+ if (!stream)
+ return;
+
if (!qos || *qos || stream->ep->dir != BT_BAP_SOURCE ||
!stream->qos.ucast.io_qos.sdu)
return;
struct bt_bap_stream *stream = data;
struct bt_bap_qos **qos = user_data;
+ if (!stream)
+ return;
+
if (!qos || *qos || stream->ep->dir != BT_BAP_SINK ||
!stream->qos.ucast.io_qos.sdu)
return;
switch (stream->ep->dir) {
case BT_BAP_SOURCE:
bap_stream_get_in_qos(stream, in);
- queue_foreach(stream->links, bap_stream_get_out_qos, out);
+ bap_stream_get_out_qos(stream->link, out);
break;
case BT_BAP_SINK:
bap_stream_get_out_qos(stream, out);
- queue_foreach(stream->links, bap_stream_get_in_qos, in);
+ bap_stream_get_in_qos(stream->link, in);
break;
default:
return false;
return in && out;
}
-static void bap_stream_get_dir(void *data, void *user_data)
-{
- struct bt_bap_stream *stream = data;
- uint8_t *dir = user_data;
-
- *dir |= stream->ep->dir;
-}
-
uint8_t bt_bap_stream_io_dir(struct bt_bap_stream *stream)
{
uint8_t dir;
dir = stream->ep->dir;
- queue_foreach(stream->links, bap_stream_get_dir, &dir);
+ if (stream->link)
+ dir |= stream->link->ep->dir;
return dir;
}
int fd = PTR_TO_INT(user_data);
const struct queue_entry *entry;
+ if (!stream)
+ return;
+
if (fd >= 0)
bap_stream_io_attach(stream, fd, true);
else
return -EINVAL;
bap_stream_io_connecting(stream, INT_TO_PTR(fd));
-
- queue_foreach(stream->links, bap_stream_io_connecting, INT_TO_PTR(fd));
+ bap_stream_io_connecting(stream->link, INT_TO_PTR(fd));
return 0;
}
diff --git a/src/shared/bap.h b/src/shared/bap.h
index 9be198c..51edc08 100644
--- a/src/shared/bap.h
+++ b/src/shared/bap.h
int bt_bap_stream_io_link(struct bt_bap_stream *stream,
struct bt_bap_stream *link);
-struct queue *bt_bap_stream_io_get_links(struct bt_bap_stream *stream);
+struct bt_bap_stream *bt_bap_stream_io_get_link(struct bt_bap_stream *stream);
bool bt_bap_stream_io_get_qos(struct bt_bap_stream *stream,
struct bt_bap_qos **in,
struct bt_bap_qos **out);