Bluetooth: Audio: broadcast_sink_sync array of stream pointers
Change bt_audio_broadcast_sink_sync to use an array of pointers to bt_audio_streams, instead of an array of streams. This makes the API more flexible, as well consistent with the broadcast source and unicast APIs. Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
This commit is contained in:
parent
5628b29b01
commit
9defebbfd3
4 changed files with 31 additions and 15 deletions
|
@ -1737,9 +1737,9 @@ int bt_audio_broadcast_sink_scan_stop(void);
|
||||||
* @param indexes_bitfield Bitfield of the BIS index to sync to. To sync to
|
* @param indexes_bitfield Bitfield of the BIS index to sync to. To sync to
|
||||||
* e.g. BIS index 1 and 2, this should have the value
|
* e.g. BIS index 1 and 2, this should have the value
|
||||||
* of BIT(1) | BIT(2).
|
* of BIT(1) | BIT(2).
|
||||||
* @param streams Stream objects to be used for the receiver. If
|
* @param streams Stream object pointerss to be used for the
|
||||||
* multiple BIS indexes shall be synchronized,
|
* receiver. If multiple BIS indexes shall be
|
||||||
* multiple streams shall be provided.
|
* synchronized, multiple streams shall be provided.
|
||||||
* @param codec Codec configuration.
|
* @param codec Codec configuration.
|
||||||
* @param broadcast_code The 16-octet broadcast code. Shall be supplied if
|
* @param broadcast_code The 16-octet broadcast code. Shall be supplied if
|
||||||
* the broadcast is encrypted (see the syncable
|
* the broadcast is encrypted (see the syncable
|
||||||
|
@ -1749,7 +1749,7 @@ int bt_audio_broadcast_sink_scan_stop(void);
|
||||||
*/
|
*/
|
||||||
int bt_audio_broadcast_sink_sync(struct bt_audio_broadcast_sink *sink,
|
int bt_audio_broadcast_sink_sync(struct bt_audio_broadcast_sink *sink,
|
||||||
uint32_t indexes_bitfield,
|
uint32_t indexes_bitfield,
|
||||||
struct bt_audio_stream *streams,
|
struct bt_audio_stream *streams[],
|
||||||
struct bt_codec *codec,
|
struct bt_codec *codec,
|
||||||
const uint8_t broadcast_code[16]);
|
const uint8_t broadcast_code[16]);
|
||||||
|
|
||||||
|
|
|
@ -849,7 +849,10 @@ static void broadcast_sink_cleanup_streams(struct bt_audio_broadcast_sink *sink)
|
||||||
for (size_t i = 0; i < sink->stream_count; i++) {
|
for (size_t i = 0; i < sink->stream_count; i++) {
|
||||||
struct bt_audio_stream *stream;
|
struct bt_audio_stream *stream;
|
||||||
|
|
||||||
stream = &sink->streams[i];
|
stream = sink->streams[i];
|
||||||
|
if (stream == NULL) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (stream->ep != NULL) {
|
if (stream->ep != NULL) {
|
||||||
stream->ep->stream = NULL;
|
stream->ep->stream = NULL;
|
||||||
|
@ -871,7 +874,7 @@ static void broadcast_sink_cleanup(struct bt_audio_broadcast_sink *sink)
|
||||||
|
|
||||||
int bt_audio_broadcast_sink_sync(struct bt_audio_broadcast_sink *sink,
|
int bt_audio_broadcast_sink_sync(struct bt_audio_broadcast_sink *sink,
|
||||||
uint32_t indexes_bitfield,
|
uint32_t indexes_bitfield,
|
||||||
struct bt_audio_stream *streams,
|
struct bt_audio_stream *streams[],
|
||||||
struct bt_codec *codec,
|
struct bt_codec *codec,
|
||||||
const uint8_t broadcast_code[16])
|
const uint8_t broadcast_code[16])
|
||||||
{
|
{
|
||||||
|
@ -926,13 +929,20 @@ int bt_audio_broadcast_sink_sync(struct bt_audio_broadcast_sink *sink,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (size_t i = 0; i < stream_count; i++) {
|
||||||
|
CHECKIF(streams[i] == NULL) {
|
||||||
|
BT_DBG("streams[%zu] is NULL", i);
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
sink->stream_count = stream_count;
|
sink->stream_count = stream_count;
|
||||||
sink->streams = streams;
|
sink->streams = streams;
|
||||||
sink->codec = codec;
|
sink->codec = codec;
|
||||||
for (size_t i = 0; i < stream_count; i++) {
|
for (size_t i = 0; i < stream_count; i++) {
|
||||||
struct bt_audio_stream *stream;
|
struct bt_audio_stream *stream;
|
||||||
|
|
||||||
stream = &streams[i];
|
stream = streams[i];
|
||||||
|
|
||||||
err = bt_audio_broadcast_sink_setup_stream(sink->index, stream,
|
err = bt_audio_broadcast_sink_setup_stream(sink->index, stream,
|
||||||
sink->codec);
|
sink->codec);
|
||||||
|
@ -964,7 +974,7 @@ int bt_audio_broadcast_sink_sync(struct bt_audio_broadcast_sink *sink,
|
||||||
}
|
}
|
||||||
|
|
||||||
for (size_t i = 0; i < stream_count; i++) {
|
for (size_t i = 0; i < stream_count; i++) {
|
||||||
struct bt_audio_ep *ep = streams[i].ep;
|
struct bt_audio_ep *ep = streams[i]->ep;
|
||||||
|
|
||||||
ep->broadcast_sink = sink;
|
ep->broadcast_sink = sink;
|
||||||
broadcast_sink_set_ep_state(ep,
|
broadcast_sink_set_ep_state(ep,
|
||||||
|
@ -984,7 +994,7 @@ int bt_audio_broadcast_sink_stop(struct bt_audio_broadcast_sink *sink)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
stream = &sink->streams[0];
|
stream = sink->streams[0];
|
||||||
|
|
||||||
if (stream == NULL) {
|
if (stream == NULL) {
|
||||||
BT_DBG("stream is NULL");
|
BT_DBG("stream is NULL");
|
||||||
|
@ -1011,6 +1021,7 @@ int bt_audio_broadcast_sink_stop(struct bt_audio_broadcast_sink *sink)
|
||||||
|
|
||||||
sink->big = NULL;
|
sink->big = NULL;
|
||||||
sink->stream_count = 0;
|
sink->stream_count = 0;
|
||||||
|
sink->streams = NULL;
|
||||||
/* Channel states will be updated in the ep_iso_disconnected function */
|
/* Channel states will be updated in the ep_iso_disconnected function */
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -1018,7 +1029,7 @@ int bt_audio_broadcast_sink_stop(struct bt_audio_broadcast_sink *sink)
|
||||||
|
|
||||||
int bt_audio_broadcast_sink_delete(struct bt_audio_broadcast_sink *sink)
|
int bt_audio_broadcast_sink_delete(struct bt_audio_broadcast_sink *sink)
|
||||||
{
|
{
|
||||||
struct bt_audio_stream *stream;
|
struct bt_audio_stream **streams;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
CHECKIF(sink == NULL) {
|
CHECKIF(sink == NULL) {
|
||||||
|
@ -1026,9 +1037,8 @@ int bt_audio_broadcast_sink_delete(struct bt_audio_broadcast_sink *sink)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
stream = &sink->streams[0];
|
streams = sink->streams;
|
||||||
|
if (streams != NULL && streams[0] != NULL && streams[0]->ep != NULL) {
|
||||||
if (stream != NULL && stream->ep != NULL) {
|
|
||||||
BT_DBG("Sink is not stopped");
|
BT_DBG("Sink is not stopped");
|
||||||
return -EBADMSG;
|
return -EBADMSG;
|
||||||
}
|
}
|
||||||
|
|
|
@ -100,7 +100,7 @@ struct bt_audio_broadcast_sink {
|
||||||
struct bt_iso_big *big;
|
struct bt_iso_big *big;
|
||||||
struct bt_iso_chan *bis[BROADCAST_SNK_STREAM_CNT];
|
struct bt_iso_chan *bis[BROADCAST_SNK_STREAM_CNT];
|
||||||
/* The streams used to create the broadcast sink */
|
/* The streams used to create the broadcast sink */
|
||||||
struct bt_audio_stream *streams;
|
struct bt_audio_stream **streams;
|
||||||
};
|
};
|
||||||
|
|
||||||
static inline const char *bt_audio_ep_state_str(uint8_t state)
|
static inline const char *bt_audio_ep_state_str(uint8_t state)
|
||||||
|
|
|
@ -1260,6 +1260,7 @@ static int cmd_accept_broadcast(const struct shell *sh, size_t argc,
|
||||||
|
|
||||||
static int cmd_sync_broadcast(const struct shell *sh, size_t argc, char *argv[])
|
static int cmd_sync_broadcast(const struct shell *sh, size_t argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
static struct bt_audio_stream *streams[ARRAY_SIZE(broadcast_sink_streams)];
|
||||||
uint32_t bis_bitfield;
|
uint32_t bis_bitfield;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
|
@ -1278,8 +1279,13 @@ static int cmd_sync_broadcast(const struct shell *sh, size_t argc, char *argv[])
|
||||||
return -ENOEXEC;
|
return -ENOEXEC;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
(void)memset(streams, 0, sizeof(streams));
|
||||||
|
for (size_t i = 0; i < ARRAY_SIZE(streams); i++) {
|
||||||
|
streams[i] = &broadcast_sink_streams[i];
|
||||||
|
}
|
||||||
|
|
||||||
err = bt_audio_broadcast_sink_sync(default_sink, bis_bitfield,
|
err = bt_audio_broadcast_sink_sync(default_sink, bis_bitfield,
|
||||||
broadcast_sink_streams,
|
streams,
|
||||||
&default_preset->preset.codec,
|
&default_preset->preset.codec,
|
||||||
NULL);
|
NULL);
|
||||||
if (err != 0) {
|
if (err != 0) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue