@@ -21,7 +21,11 @@ BUILD_ASSERT(CONFIG_BT_ISO_TX_BUF_COUNT >= TOTAL_BUF_NEEDED,
21
21
22
22
static struct bt_bap_lc3_preset preset_16_2_1 = BT_BAP_LC3_BROADCAST_PRESET_16_2_1 (
23
23
BT_AUDIO_LOCATION_FRONT_LEFT , BT_AUDIO_CONTEXT_TYPE_UNSPECIFIED );
24
- static struct bt_bap_stream streams [CONFIG_BT_BAP_BROADCAST_SRC_STREAM_COUNT ];
24
+ static struct broadcast_source_stream {
25
+ struct bt_bap_stream stream ;
26
+ uint16_t seq_num ;
27
+ size_t sent_cnt ;
28
+ } streams [CONFIG_BT_BAP_BROADCAST_SRC_STREAM_COUNT ];
25
29
static struct bt_bap_broadcast_source * broadcast_source ;
26
30
27
31
NET_BUF_POOL_FIXED_DEFINE (tx_pool ,
@@ -39,6 +43,11 @@ static K_SEM_DEFINE(sem_stopped, 0U, ARRAY_SIZE(streams));
39
43
40
44
static void stream_started_cb (struct bt_bap_stream * stream )
41
45
{
46
+ struct broadcast_source_stream * source_stream =
47
+ CONTAINER_OF (stream , struct broadcast_source_stream , stream );
48
+
49
+ source_stream -> seq_num = 0U ;
50
+ source_stream -> sent_cnt = 0U ;
42
51
k_sem_give (& sem_started );
43
52
}
44
53
@@ -49,7 +58,8 @@ static void stream_stopped_cb(struct bt_bap_stream *stream, uint8_t reason)
49
58
50
59
static void stream_sent_cb (struct bt_bap_stream * stream )
51
60
{
52
- static uint32_t sent_cnt ;
61
+ struct broadcast_source_stream * source_stream =
62
+ CONTAINER_OF (stream , struct broadcast_source_stream , stream );
53
63
struct net_buf * buf ;
54
64
int ret ;
55
65
@@ -66,18 +76,17 @@ static void stream_sent_cb(struct bt_bap_stream *stream)
66
76
67
77
net_buf_reserve (buf , BT_ISO_CHAN_SEND_RESERVE );
68
78
net_buf_add_mem (buf , mock_data , preset_16_2_1 .qos .sdu );
69
- ret = bt_bap_stream_send (stream , buf , seq_num ++ ,
70
- BT_ISO_TIMESTAMP_NONE );
79
+ ret = bt_bap_stream_send (stream , buf , source_stream -> seq_num ++ , BT_ISO_TIMESTAMP_NONE );
71
80
if (ret < 0 ) {
72
81
/* This will end broadcasting on this stream. */
73
82
printk ("Unable to broadcast data on %p: %d\n" , stream , ret );
74
83
net_buf_unref (buf );
75
84
return ;
76
85
}
77
86
78
- sent_cnt ++ ;
79
- if ((sent_cnt % 1000U ) == 0U ) {
80
- printk ("Sent %u total ISO packets\n" , sent_cnt );
87
+ source_stream -> sent_cnt ++ ;
88
+ if ((source_stream -> sent_cnt % 1000U ) == 0U ) {
89
+ printk ("Stream %p: Sent %u total ISO packets\n" , stream , source_stream -> sent_cnt );
81
90
}
82
91
}
83
92
@@ -106,7 +115,7 @@ static int setup_broadcast_source(struct bt_bap_broadcast_source **source)
106
115
}
107
116
108
117
for (size_t j = 0U ; j < ARRAY_SIZE (stream_params ); j ++ ) {
109
- stream_params [j ].stream = & streams [j ];
118
+ stream_params [j ].stream = & streams [j ]. stream ;
110
119
stream_params [j ].data = NULL ;
111
120
stream_params [j ].data_len = 0U ;
112
121
bt_bap_stream_cb_register (stream_params [j ].stream , & stream_ops );
@@ -249,7 +258,7 @@ int main(void)
249
258
/* Initialize sending */
250
259
for (size_t i = 0U ; i < ARRAY_SIZE (streams ); i ++ ) {
251
260
for (unsigned int j = 0U ; j < BROADCAST_ENQUEUE_COUNT ; j ++ ) {
252
- stream_sent_cb (& streams [i ]);
261
+ stream_sent_cb (& streams [i ]. stream );
253
262
}
254
263
}
255
264
0 commit comments