Skip to content
Closed
31 changes: 18 additions & 13 deletions src/shared/bap.c
Original file line number Diff line number Diff line change
Expand Up @@ -1283,8 +1283,10 @@ static void bap_abort_stream_req(struct bt_bap *bap,
queue_remove_all(bap->reqs, match_req_stream, stream, bap_req_abort);
}

static void bt_bap_stream_unref(struct bt_bap_stream *stream)
static void bt_bap_stream_unref(void *data)
{
struct bt_bap_stream *stream = data;

if (!stream)
return;

Expand All @@ -1308,7 +1310,6 @@ static void bap_ucast_detach(struct bt_bap_stream *stream)
queue_remove(stream->bap->streams, stream);
bap_stream_clear_cfm(stream);

stream->ep = NULL;
ep->stream = NULL;
bt_bap_stream_unref(stream);
}
Expand Down Expand Up @@ -1751,6 +1752,16 @@ static bool stream_notify_state(void *data)
return false;
}

static struct bt_bap_stream *bt_bap_stream_ref(struct bt_bap_stream *stream)
{
if (!stream)
return NULL;

__sync_fetch_and_add(&stream->ref_count, 1);

return stream;
}

static void bap_ucast_set_state(struct bt_bap_stream *stream, uint8_t state)
{
struct bt_bap_endpoint *ep = stream->ep;
Expand All @@ -1771,7 +1782,8 @@ static void bap_ucast_set_state(struct bt_bap_stream *stream, uint8_t state)
else if (!stream->state_id)
stream->state_id = timeout_add(BAP_PROCESS_TIMEOUT,
stream_notify_state,
stream, NULL);
bt_bap_stream_ref(stream),
bt_bap_stream_unref);
else /* If a state_id is already pending then queue the old one */
queue_push_tail(stream->pending_states,
UINT_TO_PTR(ep->old_state));
Expand Down Expand Up @@ -2136,6 +2148,9 @@ static uint8_t stream_metadata(struct bt_bap_stream *stream, struct iovec *meta,
util_iov_free(stream->meta, 1);
stream->meta = util_iov_dup(meta, 1);

/* Force state change to the same state to update the metadata */
stream_set_state(stream, bt_bap_stream_get_state(stream));

return 0;
}

Expand Down Expand Up @@ -2258,16 +2273,6 @@ static unsigned int bap_ucast_release(struct bt_bap_stream *stream,
return req->id;
}

static struct bt_bap_stream *bt_bap_stream_ref(struct bt_bap_stream *stream)
{
if (!stream)
return NULL;

__sync_fetch_and_add(&stream->ref_count, 1);

return stream;
}

static void bap_bcast_set_state(struct bt_bap_stream *stream, uint8_t state)
{
struct bt_bap *bap = stream->bap;
Expand Down
2 changes: 1 addition & 1 deletion src/shared/lc3.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
#define LC3_FRAME_COUNT (LC3_TYPE_BASE + 4)

#define LC3_CAPABILITIES(_freq, _duration, _chan_count, _len_min, _len_max) \
UTIL_IOV_INIT(0x02, LC3_FREQ, _freq, _freq >> 8, \
UTIL_IOV_INIT(0x03, LC3_FREQ, _freq, _freq >> 8, \
0x02, LC3_DURATION, _duration, \
0x02, LC3_CHAN_COUNT, _chan_count, \
0x05, LC3_FRAME_LEN, _len_min, _len_min >> 8, \
Expand Down
Loading