Skip to content

Commit

Permalink
Bluetooth: audio: ascs: Fix audio ISO allocation in QoS->QoS transition
Browse files Browse the repository at this point in the history
ASE in QoS state already have audio ISO object.
This will just skip the audio ISO allocation and binding in such case
if CIG and CIS parameters did not change.

Signed-off-by: Mariusz Skamra <[email protected]>
  • Loading branch information
MariuszSkamra authored and carlescufi committed Nov 8, 2022
1 parent 1029426 commit e4f0bcd
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions subsys/bluetooth/audio/ascs.c
Original file line number Diff line number Diff line change
Expand Up @@ -1387,7 +1387,6 @@ static int ase_stream_qos(struct bt_audio_stream *stream,
uint8_t cig_id,
uint8_t cis_id)
{
struct bt_audio_iso *iso;
struct bt_audio_ep *ep;

BT_DBG("stream %p ep %p qos %p", stream, stream->ep, qos);
Expand Down Expand Up @@ -1428,22 +1427,31 @@ static int ase_stream_qos(struct bt_audio_stream *stream,
}
}

iso = audio_iso_get_or_new(ascs, cig_id, cis_id);
if (iso == NULL) {
BT_ERR("Could not allocate audio_iso");
return -ENOMEM;
/* QoS->QoS transition. Unbind ISO if CIG/CIS changed. */
if (ep->iso != NULL && (ep->cig_id != cig_id || ep->cis_id != cis_id)) {
bt_audio_iso_unbind_ep(ep->iso, ep);
}

if (bt_audio_iso_get_ep(iso, ep->dir) != NULL) {
BT_ERR("iso %p already in use in dir %u",
&iso->chan, ep->dir);
if (ep->iso == NULL) {
struct bt_audio_iso *iso;

iso = audio_iso_get_or_new(ascs, cig_id, cis_id);
if (iso == NULL) {
BT_ERR("Could not allocate audio_iso");
return -ENOMEM;
}

if (bt_audio_iso_get_ep(iso, ep->dir) != NULL) {
BT_ERR("iso %p already in use in dir %u",
&iso->chan, ep->dir);
bt_audio_iso_unref(iso);
return -EALREADY;
}

bt_audio_iso_bind_ep(iso, ep);
bt_audio_iso_unref(iso);
return -EALREADY;
}

bt_audio_iso_bind_ep(iso, ep);
bt_audio_iso_unref(iso);

stream->qos = qos;

ascs_ep_set_state(ep, BT_AUDIO_EP_STATE_QOS_CONFIGURED);
Expand Down

0 comments on commit e4f0bcd

Please sign in to comment.