Skip to content

Commit

Permalink
bap: Split bap_state and bap_connecting in two functions
Browse files Browse the repository at this point in the history
Split bap_state and bap_connecting in two specific functions
for unicast (bap_state, bap_connecting) and broadcast
(bap_state_bcast, bap_connecting_bcast).
  • Loading branch information
silviubarbulescu authored and Vudentz committed Feb 20, 2024
1 parent c5f1c5b commit 5629f47
Showing 1 changed file with 107 additions and 50 deletions.
157 changes: 107 additions & 50 deletions profiles/audio/bap.c
Original file line number Diff line number Diff line change
Expand Up @@ -2098,25 +2098,19 @@ static void bap_state(struct bt_bap_stream *stream, uint8_t old_state,
return;
}

if (bt_bap_stream_get_type(stream) ==
BT_BAP_STREAM_TYPE_UCAST) {
/* Wait QoS response to respond */
setup->id = bt_bap_stream_qos(stream,
&setup->qos,
qos_cb, setup);
if (!setup->id) {
error("Failed to Configure QoS");
bt_bap_stream_release(stream,
NULL, NULL);
}
/* Wait QoS response to respond */
setup->id = bt_bap_stream_qos(stream,
&setup->qos,
qos_cb, setup);
if (!setup->id) {
error("Failed to Configure QoS");
bt_bap_stream_release(stream,
NULL, NULL);
}
}
break;
case BT_BAP_STREAM_STATE_QOS:
if (bt_bap_stream_get_type(stream) ==
BT_BAP_STREAM_TYPE_UCAST) {
setup_create_io(data, setup, stream, true);
}
break;
case BT_BAP_STREAM_STATE_ENABLING:
if (setup)
Expand All @@ -2127,6 +2121,45 @@ static void bap_state(struct bt_bap_stream *stream, uint8_t old_state,
}
}

static void bap_state_bcast(struct bt_bap_stream *stream, uint8_t old_state,
uint8_t new_state, void *user_data)
{
struct bap_data *data = user_data;
struct bap_setup *setup;

DBG("stream %p: %s(%u) -> %s(%u)", stream,
bt_bap_stream_statestr(old_state), old_state,
bt_bap_stream_statestr(new_state), new_state);

/* Ignore transitions back to same state */
if (new_state == old_state)
return;

setup = bap_find_setup_by_stream(data, stream);

switch (new_state) {
case BT_BAP_STREAM_STATE_IDLE:
/* Release stream if idle */
if (setup)
setup_free(setup);
else
queue_remove(data->streams, stream);
break;
case BT_BAP_STREAM_STATE_CONFIG:
if (setup && !setup->id) {
setup_create_io(data, setup, stream, true);
if (!setup->io) {
error("Unable to create io");
if (old_state != BT_BAP_STREAM_STATE_RELEASING)
bt_bap_stream_release(stream, NULL,
NULL);
return;
}
}
break;
}
}

static void pac_added(struct bt_bap_pac *pac, void *user_data)
{
struct btd_service *service = user_data;
Expand Down Expand Up @@ -2320,45 +2353,69 @@ static void bap_connecting(struct bt_bap_stream *stream, bool state, int fd,

g_io_channel_set_close_on_unref(io, FALSE);

switch (bt_bap_stream_get_type(setup->stream)) {
case BT_BAP_STREAM_TYPE_UCAST:
/* Attempt to get CIG/CIS if they have not been set */
if (qos->ucast.cig_id == BT_ISO_QOS_CIG_UNSET ||
qos->ucast.cis_id == BT_ISO_QOS_CIS_UNSET) {
struct bt_iso_qos iso_qos;
/* Attempt to get CIG/CIS if they have not been set */
if (qos->ucast.cig_id == BT_ISO_QOS_CIG_UNSET ||
qos->ucast.cis_id == BT_ISO_QOS_CIS_UNSET) {
struct bt_iso_qos iso_qos;

if (!io_get_qos(io, &iso_qos)) {
g_io_channel_unref(io);
return;
}

qos->ucast.cig_id = iso_qos.ucast.cig;
qos->ucast.cis_id = iso_qos.ucast.cis;
if (!io_get_qos(io, &iso_qos)) {
g_io_channel_unref(io);
return;
}

DBG("stream %p fd %d: CIG 0x%02x CIS 0x%02x", stream, fd,
qos->ucast.cig_id, qos->ucast.cis_id);
break;
case BT_BAP_STREAM_TYPE_BCAST:
/* Attempt to get BIG/BIS if they have not been set */
if (setup->qos.bcast.big == BT_ISO_QOS_BIG_UNSET ||
setup->qos.bcast.bis == BT_ISO_QOS_BIS_UNSET) {
struct bt_iso_qos iso_qos;
qos->ucast.cig_id = iso_qos.ucast.cig;
qos->ucast.cis_id = iso_qos.ucast.cis;
}

if (!io_get_qos(io, &iso_qos)) {
g_io_channel_unref(io);
return;
}
DBG("stream %p fd %d: CIG 0x%02x CIS 0x%02x", stream, fd,
qos->ucast.cig_id, qos->ucast.cis_id);
}

qos->bcast.big = iso_qos.bcast.big;
qos->bcast.bis = iso_qos.bcast.bis;
bt_bap_stream_config(setup->stream, qos, setup->caps,
NULL, NULL);
static void bap_connecting_bcast(struct bt_bap_stream *stream, bool state,
int fd, void *user_data)
{
struct bap_data *data = user_data;
struct bap_setup *setup;
GIOChannel *io;

if (!state)
return;

setup = bap_find_setup_by_stream(data, stream);
if (!setup)
return;

setup->recreate = false;

if (!setup->io) {
io = g_io_channel_unix_new(fd);
setup->io_id = g_io_add_watch(io,
G_IO_HUP | G_IO_ERR | G_IO_NVAL,
setup_io_disconnected, setup);
setup->io = io;
} else
io = setup->io;

g_io_channel_set_close_on_unref(io, FALSE);

/* Attempt to get BIG/BIS if they have not been set */
if (setup->qos.bcast.big == BT_ISO_QOS_BIG_UNSET ||
setup->qos.bcast.bis == BT_ISO_QOS_BIS_UNSET) {
struct bt_iso_qos iso_qos;

if (!io_get_qos(io, &iso_qos)) {
g_io_channel_unref(io);
return;
}

DBG("stream %p fd %d: BIG 0x%02x BIS 0x%02x", stream, fd,
qos->bcast.big, qos->bcast.bis);
setup->qos.bcast.big = iso_qos.bcast.big;
setup->qos.bcast.bis = iso_qos.bcast.bis;
bt_bap_stream_config(setup->stream, &setup->qos, setup->caps,
NULL, NULL);
}

DBG("stream %p fd %d: BIG 0x%02x BIS 0x%02x", stream, fd,
setup->qos.bcast.big, setup->qos.bcast.bis);
}

static void bap_attached(struct bt_bap *bap, void *user_data)
Expand Down Expand Up @@ -2456,10 +2513,10 @@ static int bap_bcast_probe(struct btd_service *service)

data->ready_id = bt_bap_ready_register(data->bap, bap_ready, service,
NULL);
data->state_id = bt_bap_state_register(data->bap, bap_state,
bap_connecting, data, NULL);
data->state_id = bt_bap_state_register(data->bap, bap_state_bcast,
bap_connecting_bcast, data, NULL);
data->pac_id = bt_bap_pac_register(data->bap, pac_added_broadcast,
pac_removed_broadcast, data, NULL);
pac_removed_broadcast, data, NULL);

bt_bap_set_user_data(data->bap, service);

Expand Down Expand Up @@ -2611,8 +2668,8 @@ static int bap_adapter_probe(struct btd_profile *p,
return -EINVAL;
}

data->state_id = bt_bap_state_register(data->bap, bap_state,
bap_connecting, data, NULL);
data->state_id = bt_bap_state_register(data->bap, bap_state_bcast,
bap_connecting_bcast, data, NULL);
data->pac_id = bt_bap_pac_register(data->bap, pac_added_broadcast,
pac_removed_broadcast, data, NULL);

Expand Down

0 comments on commit 5629f47

Please sign in to comment.