Lines Matching refs:sink
65 static void broadcast_sink_cleanup(struct bt_bap_broadcast_sink *sink);
70 const struct bt_bap_broadcast_sink *sink = user_data; in find_recv_state_by_sink_cb() local
72 if (atomic_test_bit(sink->flags, BT_BAP_BROADCAST_SINK_FLAG_SRC_ID_VALID) && in find_recv_state_by_sink_cb()
73 sink->bass_src_id == recv_state->src_id) { in find_recv_state_by_sink_cb()
102 static void update_recv_state_big_synced(const struct bt_bap_broadcast_sink *sink) in update_recv_state_big_synced() argument
108 recv_state = bt_bap_scan_delegator_find_state(find_recv_state_by_sink_cb, (void *)sink); in update_recv_state_big_synced()
110 LOG_WRN("Failed to find receive state for sink %p", sink); in update_recv_state_big_synced()
115 mod_src_param.num_subgroups = sink->subgroup_count; in update_recv_state_big_synced()
116 for (uint8_t i = 0U; i < sink->subgroup_count; i++) { in update_recv_state_big_synced()
118 const struct bt_bap_broadcast_sink_subgroup *sink_subgroup = &sink->subgroups[i]; in update_recv_state_big_synced()
121 subgroup_param->bis_sync = sink_subgroup->bis_indexes & sink->indexes_bitfield; in update_recv_state_big_synced()
140 LOG_WRN("Failed to modify Receive State for sink %p: %d", sink, err); in update_recv_state_big_synced()
144 static void update_recv_state_big_cleared(const struct bt_bap_broadcast_sink *sink, in update_recv_state_big_cleared() argument
151 recv_state = bt_bap_scan_delegator_find_state(find_recv_state_by_sink_cb, (void *)sink); in update_recv_state_big_cleared()
154 LOG_DBG("Could not find receive state for sink %p", sink); in update_recv_state_big_cleared()
184 sink, err); in update_recv_state_big_cleared()
188 static void broadcast_sink_clear_big(struct bt_bap_broadcast_sink *sink, in broadcast_sink_clear_big() argument
191 sink->big = NULL; in broadcast_sink_clear_big()
193 update_recv_state_big_cleared(sink, reason); in broadcast_sink_clear_big()
298 static bool broadcast_sink_is_in_state(struct bt_bap_broadcast_sink *sink, in broadcast_sink_is_in_state() argument
303 if (sink == NULL) { in broadcast_sink_is_in_state()
309 if (sys_slist_is_empty(&sink->streams)) { in broadcast_sink_is_in_state()
315 SYS_SLIST_FOR_EACH_CONTAINER(&sink->streams, stream, _node) { in broadcast_sink_is_in_state()
328 struct bt_bap_broadcast_sink *sink; in broadcast_sink_iso_connected() local
350 sink = broadcast_sink_lookup_iso_chan(chan); in broadcast_sink_iso_connected()
351 if (sink == NULL) { in broadcast_sink_iso_connected()
364 if (broadcast_sink_is_in_state(sink, BT_BAP_EP_STATE_STREAMING)) { in broadcast_sink_iso_connected()
365 update_recv_state_big_synced(sink); in broadcast_sink_iso_connected()
376 struct bt_bap_broadcast_sink *sink; in broadcast_sink_iso_disconnected() local
398 sink = broadcast_sink_lookup_iso_chan(chan); in broadcast_sink_iso_disconnected()
399 if (sink == NULL) { in broadcast_sink_iso_disconnected()
402 if (!sys_slist_find_and_remove(&sink->streams, &stream->_node)) { in broadcast_sink_iso_disconnected()
403 LOG_DBG("Could not find and remove stream %p from sink %p", stream, sink); in broadcast_sink_iso_disconnected()
458 static void broadcast_sink_add_src(struct bt_bap_broadcast_sink *sink) in broadcast_sink_add_src() argument
464 err = bt_le_per_adv_sync_get_info(sink->pa_sync, &sync_info); in broadcast_sink_add_src()
469 add_src_param.broadcast_id = sink->broadcast_id; in broadcast_sink_add_src()
477 sink, err); in broadcast_sink_add_src()
479 sink->bass_src_id = (uint8_t)err; in broadcast_sink_add_src()
480 atomic_set_bit(sink->flags, in broadcast_sink_add_src()
518 static void update_recv_state_base(const struct bt_bap_broadcast_sink *sink, in update_recv_state_base() argument
525 recv_state = bt_bap_scan_delegator_find_state(find_recv_state_by_sink_cb, (void *)sink); in update_recv_state_base()
527 LOG_WRN("Failed to find receive state for sink %p", sink); in update_recv_state_base()
534 LOG_WRN("Failed to modify Receive State for sink %p: %d", sink, err); in update_recv_state_base()
542 mod_src_param.num_subgroups = sink->subgroup_count; in update_recv_state_base()
543 for (uint8_t i = 0U; i < sink->subgroup_count; i++) { in update_recv_state_base()
552 LOG_WRN("Failed to modify Receive State for sink %p: %d", sink, err); in update_recv_state_base()
710 static int store_base_info(struct bt_bap_broadcast_sink *sink, const struct bt_bap_base *base) in store_base_info() argument
734 if (sink->big == NULL) { in store_base_info()
735 sink->qos_cfg.pd = pres_delay; in store_base_info()
736 memcpy(sink->bis, data.bis, sizeof(sink->bis)); in store_base_info()
737 memcpy(sink->subgroups, data.subgroups, sizeof(sink->subgroups)); in store_base_info()
738 sink->subgroup_count = data.subgroup_count; in store_base_info()
739 sink->valid_indexes_bitfield = data.valid_indexes_bitfield; in store_base_info()
776 struct bt_bap_broadcast_sink *sink = (struct bt_bap_broadcast_sink *)user_data; in pa_decode_base() local
787 if (atomic_test_bit(sink->flags, BT_BAP_BROADCAST_SINK_FLAG_BIGINFO_RECEIVED)) { in pa_decode_base()
793 } else if (ret != sink->biginfo_num_bis) { in pa_decode_base()
796 ret, sink->biginfo_num_bis); in pa_decode_base()
802 if (sink->big == NULL) { in pa_decode_base()
803 LOG_DBG("Updating BASE for sink %p with %d subgroups\n", sink, in pa_decode_base()
806 ret = store_base_info(sink, base); in pa_decode_base()
820 if (atomic_test_bit(sink->flags, BT_BAP_BROADCAST_SINK_FLAG_SRC_ID_VALID)) { in pa_decode_base()
821 update_recv_state_base(sink, base); in pa_decode_base()
834 listener->base_recv(sink, base, (size_t)base_size); in pa_decode_base()
845 struct bt_bap_broadcast_sink *sink = broadcast_sink_get_by_pa(sync); in pa_recv() local
847 if (sink == NULL) { in pa_recv()
857 bt_data_parse(buf, pa_decode_base, (void *)sink); in pa_recv()
863 struct bt_bap_broadcast_sink *sink = broadcast_sink_get_by_pa(sync); in pa_term_cb() local
865 if (sink != NULL) { in pa_term_cb()
866 sink->pa_sync = NULL; in pa_term_cb()
870 static void update_recv_state_encryption(const struct bt_bap_broadcast_sink *sink) in update_recv_state_encryption() argument
876 __ASSERT(sink->big == NULL, "Encryption state shall not be updated while synced"); in update_recv_state_encryption()
878 recv_state = bt_bap_scan_delegator_find_state(find_recv_state_by_sink_cb, (void *)sink); in update_recv_state_encryption()
880 LOG_WRN("Failed to find receive state for sink %p", sink); in update_recv_state_encryption()
886 if (atomic_test_bit(sink->flags, in update_recv_state_encryption()
909 LOG_WRN("Failed to modify Receive State for sink %p: %d", sink, err); in update_recv_state_encryption()
917 struct bt_bap_broadcast_sink *sink; in biginfo_recv() local
919 sink = broadcast_sink_get_by_pa(sync); in biginfo_recv()
920 if (sink == NULL) { in biginfo_recv()
925 if (sink->big != NULL) { in biginfo_recv()
930 atomic_set_bit(sink->flags, in biginfo_recv()
932 sink->iso_interval = biginfo->iso_interval; in biginfo_recv()
933 sink->biginfo_num_bis = biginfo->num_bis; in biginfo_recv()
934 if (biginfo->encryption != atomic_test_bit(sink->flags, in biginfo_recv()
936 atomic_set_bit_to(sink->flags, in biginfo_recv()
940 if (atomic_test_bit(sink->flags, in biginfo_recv()
942 update_recv_state_encryption(sink); in biginfo_recv()
946 sink->qos_cfg.framing = biginfo->framing; in biginfo_recv()
947 sink->qos_cfg.phy = biginfo->phy; in biginfo_recv()
948 sink->qos_cfg.sdu = biginfo->max_sdu; in biginfo_recv()
949 sink->qos_cfg.interval = biginfo->sdu_interval; in biginfo_recv()
953 listener->syncable(sink, biginfo); in biginfo_recv()
976 struct bt_bap_broadcast_sink *sink = broadcast_sink_get_by_big(big); in big_started_cb() local
979 if (sink == NULL) { in big_started_cb()
986 listener->started(sink); in big_started_cb()
993 struct bt_bap_broadcast_sink *sink = broadcast_sink_get_by_big(big); in big_stopped_cb() local
996 if (sink == NULL) { in big_stopped_cb()
1001 broadcast_sink_clear_big(sink, reason); in big_stopped_cb()
1005 listener->stopped(sink, reason); in big_stopped_cb()
1080 static int bt_bap_broadcast_sink_setup_stream(struct bt_bap_broadcast_sink *sink, in bt_bap_broadcast_sink_setup_stream() argument
1092 ep = broadcast_sink_new_ep(sink->index); in bt_bap_broadcast_sink_setup_stream()
1107 bt_bap_qos_cfg_to_iso_qos(iso->chan.qos->rx, &sink->qos_cfg); in bt_bap_broadcast_sink_setup_stream()
1113 stream->qos = &sink->qos_cfg; in bt_bap_broadcast_sink_setup_stream()
1118 static void broadcast_sink_cleanup_streams(struct bt_bap_broadcast_sink *sink) in broadcast_sink_cleanup_streams() argument
1122 SYS_SLIST_FOR_EACH_CONTAINER_SAFE(&sink->streams, stream, next, _node) { in broadcast_sink_cleanup_streams()
1133 sys_slist_remove(&sink->streams, NULL, &stream->_node); in broadcast_sink_cleanup_streams()
1136 sink->stream_count = 0; in broadcast_sink_cleanup_streams()
1137 sink->indexes_bitfield = 0U; in broadcast_sink_cleanup_streams()
1140 static void broadcast_sink_cleanup(struct bt_bap_broadcast_sink *sink) in broadcast_sink_cleanup() argument
1142 if (sink->stream_count > 0U) { in broadcast_sink_cleanup()
1143 broadcast_sink_cleanup_streams(sink); in broadcast_sink_cleanup()
1146 (void)memset(sink, 0, sizeof(*sink)); /* also clears flags */ in broadcast_sink_cleanup()
1149 static struct bt_audio_codec_cfg *codec_cfg_from_base_by_index(struct bt_bap_broadcast_sink *sink, in codec_cfg_from_base_by_index() argument
1152 for (size_t i = 0U; i < ARRAY_SIZE(sink->bis); i++) { in codec_cfg_from_base_by_index()
1153 struct bt_bap_broadcast_sink_bis *bis = &sink->bis[i]; in codec_cfg_from_base_by_index()
1170 struct bt_bap_broadcast_sink *sink; in bt_bap_broadcast_sink_create() local
1190 sink = broadcast_sink_free_get(); in bt_bap_broadcast_sink_create()
1191 if (sink == NULL) { in bt_bap_broadcast_sink_create()
1197 sink->broadcast_id = broadcast_id; in bt_bap_broadcast_sink_create()
1198 sink->pa_sync = pa_sync; in bt_bap_broadcast_sink_create()
1203 broadcast_sink_add_src(sink); in bt_bap_broadcast_sink_create()
1210 broadcast_sink_cleanup(sink); in bt_bap_broadcast_sink_create()
1214 sink->bass_src_id = recv_state->src_id; in bt_bap_broadcast_sink_create()
1215 atomic_set_bit(sink->flags, BT_BAP_BROADCAST_SINK_FLAG_SRC_ID_VALID); in bt_bap_broadcast_sink_create()
1217 atomic_set_bit(sink->flags, BT_BAP_BROADCAST_SINK_FLAG_INITIALIZED); in bt_bap_broadcast_sink_create()
1219 *out_sink = sink; in bt_bap_broadcast_sink_create()
1223 int bt_bap_broadcast_sink_sync(struct bt_bap_broadcast_sink *sink, uint32_t indexes_bitfield, in bt_bap_broadcast_sink_sync() argument
1233 CHECKIF(sink == NULL) { in bt_bap_broadcast_sink_sync()
1248 if (sink->pa_sync == NULL) { in bt_bap_broadcast_sink_sync()
1253 if (!atomic_test_bit(sink->flags, in bt_bap_broadcast_sink_sync()
1263 if (atomic_test_bit(sink->flags, in bt_bap_broadcast_sink_sync()
1272 if ((indexes_bitfield & sink->valid_indexes_bitfield) != indexes_bitfield) { in bt_bap_broadcast_sink_sync()
1275 indexes_bitfield, sink->valid_indexes_bitfield); in bt_bap_broadcast_sink_sync()
1283 codec_cfg_from_base_by_index(sink, i); in bt_bap_broadcast_sink_sync()
1304 sink->stream_count = 0U; in bt_bap_broadcast_sink_sync()
1312 err = bt_bap_broadcast_sink_setup_stream(sink, stream, codec_cfg); in bt_bap_broadcast_sink_sync()
1315 broadcast_sink_cleanup_streams(sink); in bt_bap_broadcast_sink_sync()
1319 sink->bis[i].chan = bt_bap_stream_iso_chan_get(stream); in bt_bap_broadcast_sink_sync()
1320 sys_slist_append(&sink->streams, &stream->_node); in bt_bap_broadcast_sink_sync()
1321 sink->stream_count++; in bt_bap_broadcast_sink_sync()
1323 bis_channels[i] = sink->bis[i].chan; in bt_bap_broadcast_sink_sync()
1327 param.num_bis = sink->stream_count; in bt_bap_broadcast_sink_sync()
1330 param.sync_timeout = interval_to_sync_timeout(sink->iso_interval); in bt_bap_broadcast_sink_sync()
1331 param.encryption = atomic_test_bit(sink->flags, in bt_bap_broadcast_sink_sync()
1339 err = bt_iso_big_sync(sink->pa_sync, ¶m, &sink->big); in bt_bap_broadcast_sink_sync()
1341 broadcast_sink_cleanup_streams(sink); in bt_bap_broadcast_sink_sync()
1345 sink->indexes_bitfield = indexes_bitfield; in bt_bap_broadcast_sink_sync()
1349 ep->broadcast_sink = sink; in bt_bap_broadcast_sink_sync()
1356 int bt_bap_broadcast_sink_stop(struct bt_bap_broadcast_sink *sink) in bt_bap_broadcast_sink_stop() argument
1360 CHECKIF(sink == NULL) { in bt_bap_broadcast_sink_stop()
1365 if (sys_slist_is_empty(&sink->streams)) { in bt_bap_broadcast_sink_stop()
1370 if (broadcast_sink_is_in_state(sink, BT_BAP_EP_STATE_IDLE)) { in bt_bap_broadcast_sink_stop()
1371 LOG_DBG("Broadcast sink %p in idle state", sink); in bt_bap_broadcast_sink_stop()
1375 err = bt_iso_big_terminate(sink->big); in bt_bap_broadcast_sink_stop()
1384 int bt_bap_broadcast_sink_delete(struct bt_bap_broadcast_sink *sink) in bt_bap_broadcast_sink_delete() argument
1387 CHECKIF(sink == NULL) { in bt_bap_broadcast_sink_delete()
1392 if (!broadcast_sink_is_in_state(sink, BT_BAP_EP_STATE_IDLE)) { in bt_bap_broadcast_sink_delete()
1393 LOG_DBG("Broadcast sink %p not in idle state", sink); in bt_bap_broadcast_sink_delete()
1398 broadcast_sink_cleanup(sink); in bt_bap_broadcast_sink_delete()