|
33 | 33 | #include "common.h" |
34 | 34 |
|
35 | 35 | #if defined(CONFIG_BT_CAP_INITIATOR) && defined(CONFIG_BT_BAP_BROADCAST_SOURCE) |
| 36 | +CREATE_FLAG(flag_source_started); |
| 37 | + |
36 | 38 | /* Zephyr Controller works best while Extended Advertising interval to be a multiple |
37 | 39 | * of the ISO Interval minus 10 ms (max. advertising random delay). This is |
38 | 40 | * required to place the AUX_ADV_IND PDUs in a non-overlapping interval with the |
@@ -75,8 +77,8 @@ static struct bt_bap_lc3_preset broadcast_preset_16_2_1 = |
75 | 77 | BT_BAP_LC3_BROADCAST_PRESET_16_2_1(LOCATION, CONTEXT); |
76 | 78 | static size_t stream_count; |
77 | 79 |
|
78 | | -static K_SEM_DEFINE(sem_broadcast_started, 0U, ARRAY_SIZE(broadcast_streams)); |
79 | | -static K_SEM_DEFINE(sem_broadcast_stopped, 0U, ARRAY_SIZE(broadcast_streams)); |
| 80 | +static K_SEM_DEFINE(sem_broadcast_stream_started, 0U, ARRAY_SIZE(broadcast_streams)); |
| 81 | +static K_SEM_DEFINE(sem_broadcast_stream_stopped, 0U, ARRAY_SIZE(broadcast_streams)); |
80 | 82 |
|
81 | 83 | static const struct named_lc3_preset lc3_broadcast_presets[] = { |
82 | 84 | {"8_1_1", BT_BAP_LC3_BROADCAST_PRESET_8_1_1(LOCATION, CONTEXT)}, |
@@ -114,24 +116,24 @@ static const struct named_lc3_preset lc3_broadcast_presets[] = { |
114 | 116 | {"48_6_2", BT_BAP_LC3_BROADCAST_PRESET_48_6_2(LOCATION, CONTEXT)}, |
115 | 117 | }; |
116 | 118 |
|
117 | | -static void broadcast_started_cb(struct bt_bap_stream *stream) |
| 119 | +static void broadcast_stream_started_cb(struct bt_bap_stream *stream) |
118 | 120 | { |
119 | 121 | struct audio_test_stream *test_stream = audio_test_stream_from_bap_stream(stream); |
120 | 122 |
|
121 | 123 | test_stream->seq_num = 0U; |
122 | 124 | test_stream->tx_cnt = 0U; |
123 | 125 |
|
124 | 126 | printk("Stream %p started\n", stream); |
125 | | - k_sem_give(&sem_broadcast_started); |
| 127 | + k_sem_give(&sem_broadcast_stream_started); |
126 | 128 | } |
127 | 129 |
|
128 | | -static void broadcast_stopped_cb(struct bt_bap_stream *stream, uint8_t reason) |
| 130 | +static void broadcast_stream_stopped_cb(struct bt_bap_stream *stream, uint8_t reason) |
129 | 131 | { |
130 | 132 | printk("Stream %p stopped with reason 0x%02X\n", stream, reason); |
131 | | - k_sem_give(&sem_broadcast_stopped); |
| 133 | + k_sem_give(&sem_broadcast_stream_stopped); |
132 | 134 | } |
133 | 135 |
|
134 | | -static void broadcast_sent_cb(struct bt_bap_stream *bap_stream) |
| 136 | +static void broadcast_stream_sent_cb(struct bt_bap_stream *bap_stream) |
135 | 137 | { |
136 | 138 | struct audio_test_stream *test_stream = audio_test_stream_from_bap_stream(bap_stream); |
137 | 139 | struct bt_cap_stream *cap_stream = cap_stream_from_audio_test_stream(test_stream); |
@@ -178,13 +180,30 @@ static void broadcast_sent_cb(struct bt_bap_stream *bap_stream) |
178 | 180 | } |
179 | 181 |
|
180 | 182 | static struct bt_bap_stream_ops broadcast_stream_ops = { |
181 | | - .started = broadcast_started_cb, |
182 | | - .stopped = broadcast_stopped_cb, |
183 | | - .sent = broadcast_sent_cb, |
| 183 | + .started = broadcast_stream_started_cb, |
| 184 | + .stopped = broadcast_stream_stopped_cb, |
| 185 | + .sent = broadcast_stream_sent_cb, |
184 | 186 | }; |
185 | 187 |
|
| 188 | +static void broadcast_source_started_cb(struct bt_cap_broadcast_source *broadcast_source) |
| 189 | +{ |
| 190 | + printk("Broadcast source %p started\n", broadcast_source); |
| 191 | + SET_FLAG(flag_source_started); |
| 192 | +} |
| 193 | + |
| 194 | +static void broadcast_source_stopped_cb(struct bt_cap_broadcast_source *broadcast_source, |
| 195 | + uint8_t reason) |
| 196 | +{ |
| 197 | + printk("Broadcast source %p stopped with reason 0x%02X\n", broadcast_source, reason); |
| 198 | + UNSET_FLAG(flag_source_started); |
| 199 | +} |
| 200 | + |
186 | 201 | static void init(void) |
187 | 202 | { |
| 203 | + static struct bt_cap_initiator_cb broadcast_cbs = { |
| 204 | + .broadcast_started = broadcast_source_started_cb, |
| 205 | + .broadcast_stopped = broadcast_source_stopped_cb, |
| 206 | + }; |
188 | 207 | int err; |
189 | 208 |
|
190 | 209 | err = bt_enable(NULL); |
@@ -221,6 +240,12 @@ static void init(void) |
221 | 240 |
|
222 | 241 | printk("Registered GTBS\n"); |
223 | 242 | } |
| 243 | + |
| 244 | + err = bt_cap_initiator_register_cb(&broadcast_cbs); |
| 245 | + if (err != 0) { |
| 246 | + FAIL("Failed to register broadcast callbacks: %d\n", err); |
| 247 | + return; |
| 248 | + } |
224 | 249 | } |
225 | 250 |
|
226 | 251 | static void setup_extended_adv(struct bt_le_ext_adv **adv) |
@@ -605,9 +630,11 @@ static void test_broadcast_audio_stop(struct bt_cap_broadcast_source *broadcast_ |
605 | 630 | /* Wait for all to be stopped */ |
606 | 631 | printk("Waiting for broadcast_streams to be stopped\n"); |
607 | 632 | for (size_t i = 0U; i < stream_count; i++) { |
608 | | - k_sem_take(&sem_broadcast_stopped, K_FOREVER); |
| 633 | + k_sem_take(&sem_broadcast_stream_stopped, K_FOREVER); |
609 | 634 | } |
610 | 635 |
|
| 636 | + WAIT_FOR_UNSET_FLAG(flag_source_started); |
| 637 | + |
611 | 638 | printk("Broadcast source stopped\n"); |
612 | 639 |
|
613 | 640 | /* Verify that it cannot be stopped twice */ |
@@ -679,17 +706,19 @@ static void test_main_cap_initiator_broadcast(void) |
679 | 706 | /* Wait for all to be started */ |
680 | 707 | printk("Waiting for broadcast_streams to be started\n"); |
681 | 708 | for (size_t i = 0U; i < stream_count; i++) { |
682 | | - k_sem_take(&sem_broadcast_started, K_FOREVER); |
| 709 | + k_sem_take(&sem_broadcast_stream_started, K_FOREVER); |
683 | 710 | } |
684 | 711 |
|
| 712 | + WAIT_FOR_FLAG(flag_source_started); |
| 713 | + |
685 | 714 | /* Initialize sending */ |
686 | 715 | for (size_t i = 0U; i < stream_count; i++) { |
687 | 716 | struct audio_test_stream *test_stream = &broadcast_source_streams[i]; |
688 | 717 |
|
689 | 718 | test_stream->tx_active = true; |
690 | 719 |
|
691 | 720 | for (unsigned int j = 0U; j < BROADCAST_ENQUEUE_COUNT; j++) { |
692 | | - broadcast_sent_cb(bap_stream_from_audio_test_stream(test_stream)); |
| 721 | + broadcast_stream_sent_cb(bap_stream_from_audio_test_stream(test_stream)); |
693 | 722 | } |
694 | 723 | } |
695 | 724 |
|
@@ -785,17 +814,19 @@ static int test_cap_initiator_ac(const struct cap_initiator_ac_param *param) |
785 | 814 | /* Wait for all to be started */ |
786 | 815 | printk("Waiting for broadcast_streams to be started\n"); |
787 | 816 | for (size_t i = 0U; i < stream_count; i++) { |
788 | | - k_sem_take(&sem_broadcast_started, K_FOREVER); |
| 817 | + k_sem_take(&sem_broadcast_stream_started, K_FOREVER); |
789 | 818 | } |
790 | 819 |
|
| 820 | + WAIT_FOR_FLAG(flag_source_started); |
| 821 | + |
791 | 822 | /* Initialize sending */ |
792 | 823 | for (size_t i = 0U; i < stream_count; i++) { |
793 | 824 | struct audio_test_stream *test_stream = &broadcast_source_streams[i]; |
794 | 825 |
|
795 | 826 | test_stream->tx_active = true; |
796 | 827 |
|
797 | 828 | for (unsigned int j = 0U; j < BROADCAST_ENQUEUE_COUNT; j++) { |
798 | | - broadcast_sent_cb(bap_stream_from_audio_test_stream(test_stream)); |
| 829 | + broadcast_stream_sent_cb(bap_stream_from_audio_test_stream(test_stream)); |
799 | 830 | } |
800 | 831 | } |
801 | 832 |
|
|
0 commit comments