Skip to content

Commit 90d2f4a

Browse files
committed
applications: nrf5340_audio: Broadcaster, added print info
- OCT-3345 - Added more info when a broadcaster/Auracast source is started Signed-off-by: Kristoffer Rist Skøien <[email protected]>
1 parent 2335df3 commit 90d2f4a

File tree

3 files changed

+68
-9
lines changed

3 files changed

+68
-9
lines changed

applications/nrf5340_audio/broadcast_source/main.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,5 @@ int main(void)
610610
per_adv_buf_cnt, false);
611611
ERR_CHK_MSG(ret, "Failed to start first advertiser");
612612

613-
LOG_INF("Broadcast source: %s started", CONFIG_BT_AUDIO_BROADCAST_NAME);
614-
615613
return 0;
616614
}

applications/nrf5340_audio/src/bluetooth/bt_stream/broadcast/broadcast_sink.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,7 @@ static void syncable_cb(struct bt_bap_broadcast_sink *sink, const struct bt_iso_
542542
*/
543543
if (!broadcast_code_received && biginfo->encryption == true &&
544544
sink->broadcast_id != prev_broadcast_id) {
545-
LOG_WRN("Stream is encrypted, but haven not received broadcast code");
545+
LOG_WRN("Stream is encrypted, but have not received broadcast code");
546546
return;
547547
}
548548

applications/nrf5340_audio/src/bluetooth/bt_stream/broadcast/broadcast_source.c

Lines changed: 67 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ ZBUS_CHAN_DEFINE(le_audio_chan, struct le_audio_msg, NULL, NULL, ZBUS_OBSERVERS_
4141
ZBUS_MSG_INIT(0));
4242

4343
static struct bt_cap_broadcast_source *broadcast_sources[CONFIG_BT_ISO_MAX_BIG];
44-
struct bt_cap_initiator_broadcast_create_param create_param[CONFIG_BT_ISO_MAX_BIG];
44+
static struct bt_cap_initiator_broadcast_create_param create_param[CONFIG_BT_ISO_MAX_BIG];
4545
/* Make sure we have statically allocated streams for all potential BISes */
4646
static struct bt_cap_stream cap_streams[CONFIG_BT_ISO_MAX_BIG]
4747
[CONFIG_BT_BAP_BROADCAST_SRC_SUBGROUP_COUNT]
@@ -131,7 +131,7 @@ static void stream_started_cb(struct bt_bap_stream *stream)
131131
le_audio_event_publish(LE_AUDIO_EVT_STREAMING, &idx);
132132

133133
/* NOTE: The string below is used by the Nordic CI system */
134-
LOG_INF("Broadcast source %p started", (void *)stream);
134+
LOG_INF("Broadcast stream %p started", (void *)stream);
135135

136136
le_audio_print_codec(stream->codec_cfg, BT_AUDIO_DIR_SOURCE);
137137
}
@@ -169,7 +169,7 @@ static void stream_stopped_cb(struct bt_bap_stream *stream, uint8_t reason)
169169

170170
le_audio_event_publish(LE_AUDIO_EVT_NOT_STREAMING, &idx);
171171

172-
LOG_INF("Broadcast source %p stopped. Reason: %d", (void *)stream, reason);
172+
LOG_INF("Broadcast stream %p stopped. Reason: %d", (void *)stream, reason);
173173

174174
if (delete_broadcast_src[idx.lvl1] && broadcast_sources[idx.lvl1] != NULL &&
175175
!source_has_streaming_streams(idx.lvl1)) {
@@ -750,8 +750,62 @@ void broadcast_source_default_create(struct broadcast_source_big *broadcast_para
750750
}
751751

752752
bt_audio_codec_cfg_meta_set_lang(&subgroups.group_lc3_preset.codec_cfg, "eng");
753+
754+
memcpy(broadcast_param->broadcast_name, CONFIG_BT_AUDIO_BROADCAST_NAME,
755+
sizeof(CONFIG_BT_AUDIO_BROADCAST_NAME));
753756
}
754757

758+
void broadcast_started_cb(struct bt_cap_broadcast_source *source)
759+
{
760+
if (!IS_ENABLED(CONFIG_DEBUG)) {
761+
return;
762+
}
763+
764+
int ret;
765+
int idx = -EINVAL;
766+
767+
for (int i = 0; i < CONFIG_BT_ISO_MAX_BIG; i++) {
768+
if (broadcast_sources[i] == source) {
769+
idx = i;
770+
break;
771+
}
772+
}
773+
774+
if (idx < 0) {
775+
LOG_ERR("Broadcaster not found");
776+
return;
777+
}
778+
779+
uint32_t broadcast_id;
780+
781+
ret = broadcast_source_id_get(idx, &broadcast_id);
782+
if (ret) {
783+
LOG_ERR("Failed to get broadcast ID: %d", ret);
784+
return;
785+
}
786+
787+
LOG_INF("Source %p started", (void *)source);
788+
LOG_INF("\tIndex: %u", idx);
789+
LOG_INF("\tID: %u", broadcast_id);
790+
LOG_INF("\tNum subgroups: %u", create_param[idx].subgroup_count);
791+
792+
if (create_param[idx].encryption) {
793+
LOG_INF("\tEncrypted with key: %s", create_param[idx].broadcast_code);
794+
} else {
795+
LOG_INF("\tNot encrypted");
796+
}
797+
}
798+
799+
void broadcast_stopped_cb(struct bt_cap_broadcast_source *source, uint8_t reason)
800+
{
801+
LOG_INF("Broadcast source %p stopped. Reason: %d", (void *)source, reason);
802+
}
803+
804+
static struct bt_cap_initiator_cb cap_cbs = {
805+
.broadcast_started = broadcast_started_cb,
806+
.broadcast_stopped = broadcast_stopped_cb,
807+
};
808+
755809
int broadcast_source_enable(struct broadcast_source_big const *const broadcast_param,
756810
uint8_t big_index)
757811
{
@@ -767,7 +821,14 @@ int broadcast_source_enable(struct broadcast_source_big const *const broadcast_p
767821
bt_le_audio_tx_init();
768822
}
769823

770-
LOG_INF("Enabling broadcast_source %d", big_index);
824+
ret = bt_cap_initiator_register_cb(&cap_cbs);
825+
826+
if (ret == -EALREADY) {
827+
LOG_DBG("Callbacks already registered");
828+
} else if (ret) {
829+
LOG_ERR("Failed to register callbacks: %d", ret);
830+
return ret;
831+
}
771832

772833
ret = create_param_produce(big_index, broadcast_param, &create_param[big_index]);
773834
if (ret) {
@@ -793,8 +854,8 @@ int broadcast_source_enable(struct broadcast_source_big const *const broadcast_p
793854
}
794855

795856
initialized = true;
796-
797-
LOG_DBG("Broadcast source enabled");
857+
LOG_INF("Created: %p %s", (void *)broadcast_sources[big_index],
858+
broadcast_param->broadcast_name);
798859

799860
return 0;
800861
}

0 commit comments

Comments
 (0)