Lines Matching +full:channel +full:- +full:gap

2  * Copyright (c) 2022-2024 Nordic Semiconductor ASA
5 * SPDX-License-Identifier: Apache-2.0
21 #include <zephyr/bluetooth/gap.h>
171 NULL, NULL, NULL, LC3_ENCODER_PRIORITY, 0, -1);
195 const uint8_t frames_blocks_per_sdu = stream->lc3_frames_blocks_per_sdu; in lc3_decoder_thread()
196 const uint16_t octets_per_frame = stream->lc3_octets_per_frame; in lc3_decoder_thread()
200 k_mutex_lock(&stream->lc3_decoder_mutex, K_FOREVER); in lc3_decoder_thread()
202 if (stream->in_buf == NULL) { in lc3_decoder_thread()
203 k_mutex_unlock(&stream->lc3_decoder_mutex); in lc3_decoder_thread()
208 buf = net_buf_ref(stream->in_buf); in lc3_decoder_thread()
209 net_buf_unref(stream->in_buf); in lc3_decoder_thread()
210 stream->in_buf = NULL; in lc3_decoder_thread()
211 k_mutex_unlock(&stream->lc3_decoder_mutex); in lc3_decoder_thread()
213 frames_per_block = bt_audio_get_chan_count(stream->chan_allocation); in lc3_decoder_thread()
214 if (buf->len != in lc3_decoder_thread()
219 buf->len); in lc3_decoder_thread()
228 (stream->chan_allocation & BT_AUDIO_LOCATION_FRONT_LEFT) != 0; in lc3_decoder_thread()
230 (stream->chan_allocation & BT_AUDIO_LOCATION_FRONT_RIGHT) != 0; in lc3_decoder_thread()
232 stream->chan_allocation == BT_AUDIO_LOCATION_MONO_AUDIO; in lc3_decoder_thread()
251 /* unused channel */ in lc3_decoder_thread()
255 do_lc3_decode(stream->lc3_decoder, data, octets_per_frame, in lc3_decoder_thread()
265 do_lc3_decode(stream->lc3_decoder, data, octets_per_frame, in lc3_decoder_thread()
285 /* Send frames to USB - If we only have a single channel we mix it to stereo */ in lc3_decoder_thread()
301 * If we only have single channel then that is always stored in the in lc3_decoder_thread()
336 printk(" decoder failed - wrong parameters? (err = %d)\n", err); in do_lc3_decode()
348 printk("Enable: stream with codec %p\n", sink_stream->stream.codec_cfg); in lc3_enable()
350 ret = bt_audio_codec_cfg_get_freq(sink_stream->stream.codec_cfg); in lc3_enable()
355 return -1; in lc3_enable()
358 ret = bt_audio_codec_cfg_get_frame_dur(sink_stream->stream.codec_cfg); in lc3_enable()
366 ret = bt_audio_codec_cfg_get_chan_allocation(sink_stream->stream.codec_cfg, in lc3_enable()
367 &sink_stream->chan_allocation, true); in lc3_enable()
369 printk("Error: Channel allocation not set, invalid configuration for LC3"); in lc3_enable()
373 ret = bt_audio_codec_cfg_get_octets_per_frame(sink_stream->stream.codec_cfg); in lc3_enable()
375 sink_stream->lc3_octets_per_frame = (uint16_t)ret; in lc3_enable()
381 ret = bt_audio_codec_cfg_get_frame_blocks_per_sdu(sink_stream->stream.codec_cfg, true); in lc3_enable()
383 sink_stream->lc3_frames_blocks_per_sdu = (uint8_t)ret; in lc3_enable()
389 /* An SDU can consist of X frame blocks, each with Y frames (one per channel) of size Z in in lc3_enable()
392 chan_alloc_bit_cnt = bt_audio_get_chan_count(sink_stream->chan_allocation); in lc3_enable()
393 sdu_size_required = chan_alloc_bit_cnt * sink_stream->lc3_octets_per_frame * in lc3_enable()
394 sink_stream->lc3_frames_blocks_per_sdu; in lc3_enable()
395 if (sdu_size_required > sink_stream->stream.qos->sdu) { in lc3_enable()
398 chan_alloc_bit_cnt, sink_stream->lc3_octets_per_frame, in lc3_enable()
399 sink_stream->lc3_frames_blocks_per_sdu, sdu_size_required, in lc3_enable()
400 sink_stream->stream.qos->sdu); in lc3_enable()
402 return -EINVAL; in lc3_enable()
405 printk("Enabling LC3 decoder with frame duration %uus, frequency %uHz and with channel " in lc3_enable()
407 frame_duration_us, freq_hz, sink_stream->chan_allocation, in lc3_enable()
408 sink_stream->lc3_octets_per_frame, sink_stream->lc3_frames_blocks_per_sdu); in lc3_enable()
411 sink_stream->lc3_decoder = lc3_setup_decoder(frame_duration_us, freq_hz, USB_SAMPLE_RATE, in lc3_enable()
412 &sink_stream->lc3_decoder_mem); in lc3_enable()
414 sink_stream->lc3_decoder = lc3_setup_decoder(frame_duration_us, freq_hz, 0, in lc3_enable()
415 &sink_stream->lc3_decoder_mem); in lc3_enable()
418 if (sink_stream->lc3_decoder == NULL) { in lc3_enable()
419 printk("ERROR: Failed to setup LC3 decoder - wrong parameters?\n"); in lc3_enable()
420 return -1; in lc3_enable()
448 /* USB consumer callback, called every 1ms, consumes data from ring-buffer */
459 * we send frames padded with 0's as usb_audio_data is 0-initialized in usb_data_request_cb()
517 sink_stream->recv_cnt = 0U; in stream_started_cb()
518 sink_stream->loss_cnt = 0U; in stream_started_cb()
519 sink_stream->valid_cnt = 0U; in stream_started_cb()
520 sink_stream->error_cnt = 0U; in stream_started_cb()
525 if (stream->codec_cfg != 0 && stream->codec_cfg->id != BT_HCI_CODING_FORMAT_LC3) { in stream_started_cb()
559 if (info->flags & BT_ISO_FLAGS_ERROR) { in stream_recv_cb()
560 sink_stream->error_cnt++; in stream_recv_cb()
563 if (info->flags & BT_ISO_FLAGS_LOST) { in stream_recv_cb()
564 sink_stream->loss_cnt++; in stream_recv_cb()
567 if (info->flags & BT_ISO_FLAGS_VALID) { in stream_recv_cb()
568 sink_stream->valid_cnt++; in stream_recv_cb()
570 k_mutex_lock(&sink_stream->lc3_decoder_mutex, K_FOREVER); in stream_recv_cb()
571 if (sink_stream->in_buf != NULL) { in stream_recv_cb()
572 net_buf_unref(sink_stream->in_buf); in stream_recv_cb()
573 sink_stream->in_buf = NULL; in stream_recv_cb()
576 sink_stream->in_buf = net_buf_ref(buf); in stream_recv_cb()
577 k_mutex_unlock(&sink_stream->lc3_decoder_mutex); in stream_recv_cb()
583 sink_stream->recv_cnt++; in stream_recv_cb()
584 if ((sink_stream->recv_cnt % LOG_INTERVAL) == 0U) { in stream_recv_cb()
586 &sink_stream->stream, sink_stream->recv_cnt, sink_stream->valid_cnt, in stream_recv_cb()
587 sink_stream->error_cnt, sink_stream->loss_cnt); in stream_recv_cb()
613 * Gets BIS channel allocation (if exists).
623 idx = data->cnt++; in bis_get_channel_allocation_cb()
624 data->bis[idx].index = bis->index; in bis_get_channel_allocation_cb()
625 data->bis[idx].chan_allocation_available = false; in bis_get_channel_allocation_cb()
634 err = bt_audio_codec_cfg_get_chan_allocation(&codec_cfg, &data->bis[idx].chan_allocation, in bis_get_channel_allocation_cb()
637 printk("Could not find channel allocation for BIS: %d\n", err); in bis_get_channel_allocation_cb()
642 /* Channel allocation data available for this bis */ in bis_get_channel_allocation_cb()
643 data->bis[idx].chan_allocation_available = true; in bis_get_channel_allocation_cb()
649 * Called for each subgroup in the BASE. Will populate the 32-bit bitfield of BIS indexes if the
652 * The channel allocation may
653 * - Not exist at all, implicitly meaning BT_AUDIO_LOCATION_MONO_AUDIO
654 * - Exist only in the subgroup codec configuration
655 * - Exist only in the BIS codec configuration
656 * - Exist in both the subgroup and BIS codec configuration, in which case, the BIS codec
688 /* Get channel allocation at subgroup level */ in subgroup_get_valid_bis_indexes_cb()
691 printk("Channel allocation (subgroup level) 0x%x\n", subgroup_chan_allocation); in subgroup_get_valid_bis_indexes_cb()
698 /* Get channel allocation at BIS level */ in subgroup_get_valid_bis_indexes_cb()
701 printk("Get channel allocation error %d\n", err); in subgroup_get_valid_bis_indexes_cb()
706 /* If no BIS channel allocation available use subgroup channel allocation instead if in subgroup_get_valid_bis_indexes_cb()
725 printk("Channel allocation match. BIS index bitfield 0x%x\n", bis_indexes); in subgroup_get_valid_bis_indexes_cb()
736 printk("Channel allocation match. BIS index bitfield 0x%x\n", in subgroup_get_valid_bis_indexes_cb()
763 * Get a 32-bit bitfield of BIS indexes that cover the channel allocation values in in base_recv_cb()
766 printk("Target channel location: 0x%x\n", CONFIG_TARGET_BROADCAST_CHANNEL); in base_recv_cb()
769 if ((err != 0 && err != -ECANCELED) || in base_recv_cb()
770 (err == -ECANCELED && base_bis_index_bitfield == 0)) { in base_recv_cb()
802 biginfo->encryption ? "encrypted" : "not encrypted"); in syncable_cb()
806 if (!biginfo->encryption) { in syncable_cb()
839 if (req_recv_state->pa_sync_state == BT_BAP_PA_STATE_INFO_REQ) { in pa_timer_handler()
845 bt_bap_scan_delegator_set_pa_state(req_recv_state->src_id, in pa_timer_handler()
900 recv_state->pa_sync_state, recv_state->encrypt_state); in recv_state_updated_cb()
902 for (uint8_t i = 0; i < recv_state->num_subgroups; i++) { in recv_state_updated_cb()
903 printk("subgroup %d bis_sync: 0x%08x\n", i, recv_state->subgroups[i].bis_sync); in recv_state_updated_cb()
915 recv_state->pa_sync_state); in pa_sync_req_cb()
919 if (recv_state->pa_sync_state == BT_BAP_PA_STATE_SYNCED || in pa_sync_req_cb()
920 recv_state->pa_sync_state == BT_BAP_PA_STATE_INFO_REQ) { in pa_sync_req_cb()
923 return -1; in pa_sync_req_cb()
938 err = bt_bap_scan_delegator_set_pa_state(recv_state->src_id, in pa_sync_req_cb()
957 printk("PA sync termination req, pa sync state: %u\n", recv_state->pa_sync_state); in pa_sync_term_req_cb()
959 for (uint8_t i = 0; i < recv_state->num_subgroups; i++) { in pa_sync_term_req_cb()
960 printk("subgroup %d bis_sync: 0x%08x\n", i, recv_state->subgroups[i].bis_sync); in pa_sync_term_req_cb()
998 for (uint8_t subgroup = 0; subgroup < recv_state->num_subgroups; subgroup++) { in bis_sync_req_cb()
1012 return -EINVAL; in bis_sync_req_cb()
1021 recv_state, requested_bis_sync, requested_subgroup_sync, recv_state->broadcast_id, in bis_sync_req_cb()
1040 broadcaster_broadcast_id = recv_state->broadcast_id; in bis_sync_req_cb()
1109 if (data->type != BT_DATA_SVC_DATA16) { in scan_check_and_sync_broadcast()
1113 if (data->data_len < BT_UUID_SIZE_16 + BT_AUDIO_BROADCAST_ID_SIZE) { in scan_check_and_sync_broadcast()
1117 if (!bt_uuid_create(&adv_uuid.uuid, data->data, BT_UUID_SIZE_16)) { in scan_check_and_sync_broadcast()
1125 broadcast_id = sys_get_le24(data->data + BT_UUID_SIZE_16); in scan_check_and_sync_broadcast()
1127 bt_addr_le_to_str(info->addr, le_addr, sizeof(le_addr)); in scan_check_and_sync_broadcast()
1130 le_addr, info->sid); in scan_check_and_sync_broadcast()
1133 (req_recv_state != NULL && bt_addr_le_eq(info->addr, &req_recv_state->addr) && in scan_check_and_sync_broadcast()
1134 info->sid == req_recv_state->adv_sid && in scan_check_and_sync_broadcast()
1135 broadcast_id == req_recv_state->broadcast_id)) { in scan_check_and_sync_broadcast()
1139 bt_addr_le_copy(&broadcaster_addr, info->addr); in scan_check_and_sync_broadcast()
1176 switch (data->type) { in data_cb()
1180 memcpy(name, data->data, MIN(data->data_len, NAME_LEN - 1)); in data_cb()
1195 if (info->interval != 0U) { in broadcast_scan_recv()
1225 (req_recv_state != NULL && bt_addr_le_eq(info->addr, &req_recv_state->addr) && in bap_pa_sync_synced_cb()
1226 info->sid == req_recv_state->adv_sid)) { in bap_pa_sync_synced_cb()
1243 printk("PA sync %p lost with reason 0x%02X\n", sync, info->reason); in bap_pa_sync_terminated_cb()
1248 if (info->reason != BT_HCI_ERR_LOCALHOST_TERM_CONN && req_recv_state != NULL) { in bap_pa_sync_terminated_cb()
1260 err = bt_bap_scan_delegator_rem_src(req_recv_state->src_id); in bap_pa_sync_terminated_cb()
1317 return -EIO; in init()
1322 if (err && err != -EALREADY) { in init()
1393 sizeof(CONFIG_BT_DEVICE_NAME) - 1), in start_adv()
1480 printk("Resetting failed: %d - Aborting\n", err); in main()
1551 if (err != 0 && err != -EALREADY) { in main()