Lines Matching refs:sh_stream

178 	struct shell_stream *sh_stream = CONTAINER_OF(cap_stream, struct shell_stream, stream);  in shell_stream_from_bap_stream()  local
180 return sh_stream; in shell_stream_from_bap_stream()
183 struct bt_bap_stream *bap_stream_from_shell_stream(struct shell_stream *sh_stream) in bap_stream_from_shell_stream() argument
185 return &sh_stream->stream.bap_stream; in bap_stream_from_shell_stream()
193 void bap_foreach_stream(void (*func)(struct shell_stream *sh_stream, void *data), void *data) in bap_foreach_stream() argument
217 static int get_lc3_chan_alloc_from_index(const struct shell_stream *sh_stream, uint8_t index, in get_lc3_chan_alloc_from_index() argument
220 const bool has_left = (sh_stream->lc3_chan_allocation & BT_AUDIO_LOCATION_FRONT_LEFT) != 0; in get_lc3_chan_alloc_from_index()
222 (sh_stream->lc3_chan_allocation & BT_AUDIO_LOCATION_FRONT_RIGHT) != 0; in get_lc3_chan_alloc_from_index()
223 const bool is_mono = sh_stream->lc3_chan_allocation == BT_AUDIO_LOCATION_MONO_AUDIO; in get_lc3_chan_alloc_from_index()
255 struct shell_stream *sh_stream = shell_stream_from_bap_stream(bap_stream); in get_next_seq_num() local
262 if (!sh_stream->is_tx) { in get_next_seq_num()
268 delta_ticks = uptime_ticks - sh_stream->tx.connected_at_ticks; in get_next_seq_num()
294 static int init_lc3_encoder(struct shell_stream *sh_stream) in init_lc3_encoder() argument
296 if (sh_stream == NULL) { in init_lc3_encoder()
301 if (!sh_stream->is_tx) { in init_lc3_encoder()
306 if (sh_stream->tx.lc3_encoder != NULL) { in init_lc3_encoder()
311 if (sh_stream->lc3_freq_hz == 0 || sh_stream->lc3_frame_duration_us == 0) { in init_lc3_encoder()
313 sh_stream->lc3_freq_hz, sh_stream->lc3_frame_duration_us); in init_lc3_encoder()
319 const size_t frame_size = bap_usb_get_frame_size(sh_stream); in init_lc3_encoder()
332 bap_stream_from_shell_stream(sh_stream), sh_stream->lc3_frame_duration_us, in init_lc3_encoder()
333 sh_stream->lc3_freq_hz); in init_lc3_encoder()
335 sh_stream->tx.lc3_encoder = in init_lc3_encoder()
336 lc3_setup_encoder(sh_stream->lc3_frame_duration_us, sh_stream->lc3_freq_hz, in init_lc3_encoder()
338 &sh_stream->tx.lc3_encoder_mem); in init_lc3_encoder()
339 if (sh_stream->tx.lc3_encoder == NULL) { in init_lc3_encoder()
368 static bool encode_frame(struct shell_stream *sh_stream, uint8_t index, size_t frame_cnt, in encode_frame() argument
371 const size_t total_frames = sh_stream->lc3_chan_cnt * sh_stream->lc3_frame_blocks_per_sdu; in encode_frame()
372 const uint16_t octets_per_frame = sh_stream->lc3_octets_per_frame; in encode_frame()
379 err = get_lc3_chan_alloc_from_index(sh_stream, index, &chan_alloc); in encode_frame()
386 bap_usb_get_frame(sh_stream, chan_alloc, lc3_tx_buf); in encode_frame()
389 fill_lc3_tx_buf_sin(lc3_tx_buf, sh_stream->lc3_frame_duration_us, in encode_frame()
390 AUDIO_TONE_FREQUENCY_HZ, sh_stream->lc3_freq_hz); in encode_frame()
393 if ((sh_stream->tx.encoded_cnt % bap_stats_interval) == 0) { in encode_frame()
395 sh_stream->tx.encoded_cnt, octets_per_frame, frame_cnt + 1, in encode_frame()
399 lc3_ret = lc3_encode(sh_stream->tx.lc3_encoder, LC3_PCM_FORMAT_S16, lc3_tx_buf, 1, in encode_frame()
412 static size_t encode_frame_block(struct shell_stream *sh_stream, size_t frame_cnt, in encode_frame_block() argument
415 const uint8_t chan_cnt = sh_stream->lc3_chan_cnt; in encode_frame_block()
422 if (encode_frame(sh_stream, i, frame_cnt, out_buf)) { in encode_frame_block()
430 static void do_lc3_encode(struct shell_stream *sh_stream, struct net_buf *out_buf) in do_lc3_encode() argument
432 if (IS_ENABLED(CONFIG_USB_DEVICE_AUDIO) && !bap_usb_can_get_full_sdu(sh_stream)) { in do_lc3_encode()
437 for (uint8_t i = 0U; i < sh_stream->lc3_frame_blocks_per_sdu; i++) { in do_lc3_encode()
438 frame_cnt += encode_frame_block(sh_stream, frame_cnt, out_buf); in do_lc3_encode()
440 sh_stream->tx.encoded_cnt++; in do_lc3_encode()
445 static void lc3_audio_send_data(struct shell_stream *sh_stream) in lc3_audio_send_data() argument
447 struct bt_bap_stream *bap_stream = bap_stream_from_shell_stream(sh_stream); in lc3_audio_send_data()
448 const uint16_t tx_sdu_len = sh_stream->lc3_frame_blocks_per_sdu * sh_stream->lc3_chan_cnt * in lc3_audio_send_data()
449 sh_stream->lc3_octets_per_frame; in lc3_audio_send_data()
453 if (!sh_stream->is_tx || !sh_stream->tx.active) { in lc3_audio_send_data()
458 if (sh_stream->tx.lc3_encoder == NULL) { in lc3_audio_send_data()
472 tx_sdu_len, sh_stream->lc3_frame_blocks_per_sdu, in lc3_audio_send_data()
473 sh_stream->lc3_chan_cnt, sh_stream->lc3_octets_per_frame, in lc3_audio_send_data()
478 if (atomic_get(&sh_stream->tx.lc3_enqueue_cnt) == 0U) { in lc3_audio_send_data()
486 do_lc3_encode(sh_stream, buf); in lc3_audio_send_data()
488 err = bt_bap_stream_send(bap_stream, buf, sh_stream->tx.seq_num); in lc3_audio_send_data()
496 if ((sh_stream->tx.lc3_sdu_cnt % bap_stats_interval) == 0U) { in lc3_audio_send_data()
498 sh_stream->tx.lc3_sdu_cnt, bap_stream, tx_sdu_len, in lc3_audio_send_data()
499 sh_stream->tx.seq_num); in lc3_audio_send_data()
502 sh_stream->tx.lc3_sdu_cnt++; in lc3_audio_send_data()
503 sh_stream->tx.seq_num++; in lc3_audio_send_data()
504 atomic_dec(&sh_stream->tx.lc3_enqueue_cnt); in lc3_audio_send_data()
509 struct shell_stream *sh_stream = shell_stream_from_bap_stream(bap_stream); in lc3_sent_cb() local
511 if (!sh_stream->is_tx) { in lc3_sent_cb()
515 atomic_inc(&sh_stream->tx.lc3_enqueue_cnt); in lc3_sent_cb()
518 static void encode_and_send_cb(struct shell_stream *sh_stream, void *user_data) in encode_and_send_cb() argument
520 if (sh_stream->is_tx) { in encode_and_send_cb()
521 lc3_audio_send_data(sh_stream); in encode_and_send_cb()
2591 struct shell_stream *sh_stream; member
2609 static int init_lc3_decoder(struct shell_stream *sh_stream) in init_lc3_decoder() argument
2611 if (sh_stream == NULL) { in init_lc3_decoder()
2616 if (!sh_stream->is_rx) { in init_lc3_decoder()
2621 if (sh_stream->rx.lc3_decoder != NULL) { in init_lc3_decoder()
2626 if (sh_stream->lc3_freq_hz == 0 || sh_stream->lc3_frame_duration_us == 0) { in init_lc3_decoder()
2628 sh_stream->lc3_freq_hz, sh_stream->lc3_frame_duration_us); in init_lc3_decoder()
2635 sh_stream->lc3_frame_duration_us, sh_stream->lc3_freq_hz); in init_lc3_decoder()
2637 sh_stream->rx.lc3_decoder = in init_lc3_decoder()
2638 lc3_setup_decoder(sh_stream->lc3_frame_duration_us, sh_stream->lc3_freq_hz, in init_lc3_decoder()
2640 &sh_stream->rx.lc3_decoder_mem); in init_lc3_decoder()
2641 if (sh_stream->rx.lc3_decoder == NULL) { in init_lc3_decoder()
2651 const struct shell_stream *sh_stream = data->sh_stream; in decode_frame() local
2652 const size_t total_frames = sh_stream->lc3_chan_cnt * sh_stream->lc3_frame_blocks_per_sdu; in decode_frame()
2653 const uint16_t octets_per_frame = sh_stream->lc3_octets_per_frame; in decode_frame()
2661 if ((sh_stream->rx.decoded_cnt % bap_stats_interval) == 0) { in decode_frame()
2662 shell_print(ctx_shell, "[%zu]: Performing PLC", sh_stream->rx.decoded_cnt); in decode_frame()
2669 if ((sh_stream->rx.decoded_cnt % bap_stats_interval) == 0) { in decode_frame()
2671 sh_stream->rx.decoded_cnt, octets_per_frame, frame_cnt + 1, in decode_frame()
2676 err = lc3_decode(sh_stream->rx.lc3_decoder, iso_data, octets_per_frame, LC3_PCM_FORMAT_S16, in decode_frame()
2689 const struct shell_stream *sh_stream = data->sh_stream; in decode_frame_block() local
2690 const uint8_t chan_cnt = sh_stream->lc3_chan_cnt; in decode_frame_block()
2704 err = get_lc3_chan_alloc_from_index(sh_stream, i, &chan_alloc); in decode_frame_block()
2712 sh_stream != usb_left_stream) || in decode_frame_block()
2714 sh_stream != usb_right_stream)) { in decode_frame_block()
2741 struct shell_stream *sh_stream = data->sh_stream; in do_lc3_decode() local
2743 if (sh_stream->is_rx && sh_stream->rx.lc3_decoder != NULL) { in do_lc3_decode()
2744 const uint8_t frame_blocks_per_sdu = sh_stream->lc3_frame_blocks_per_sdu; in do_lc3_decode()
2758 sh_stream->rx.decoded_cnt++; in do_lc3_decode()
2768 struct shell_stream *sh_stream = data->sh_stream; in lc3_decoder_thread_func() local
2770 if (sh_stream->is_rx && sh_stream->rx.lc3_decoder == NULL) { in lc3_decoder_thread_func()
2788 struct shell_stream *sh_stream = shell_stream_from_bap_stream(stream); in audio_recv() local
2790 if (!sh_stream->is_rx) { in audio_recv()
2794 sh_stream->rx.rx_cnt++; in audio_recv()
2796 if (info->ts == sh_stream->rx.last_info.ts) { in audio_recv()
2797 sh_stream->rx.dup_ts++; in audio_recv()
2800 if (info->seq_num == sh_stream->rx.last_info.seq_num) { in audio_recv()
2801 sh_stream->rx.dup_psn++; in audio_recv()
2806 sh_stream->rx.empty_sdu_pkts++; in audio_recv()
2808 sh_stream->rx.valid_sdu_pkts++; in audio_recv()
2813 sh_stream->rx.err_pkts++; in audio_recv()
2817 sh_stream->rx.lost_pkts++; in audio_recv()
2820 if ((sh_stream->rx.rx_cnt % bap_stats_interval) == 0) { in audio_recv()
2825 sh_stream->rx.rx_cnt, stream, buf->len, info->ts, info->seq_num, in audio_recv()
2826 info->flags, sh_stream->rx.valid_sdu_pkts, sh_stream->rx.dup_ts, in audio_recv()
2827 sh_stream->rx.dup_psn, sh_stream->rx.err_pkts, sh_stream->rx.lost_pkts, in audio_recv()
2828 sh_stream->rx.empty_sdu_pkts); in audio_recv()
2831 (void)memcpy(&sh_stream->rx.last_info, info, sizeof(sh_stream->rx.last_info)); in audio_recv()
2834 if (sh_stream->rx.lc3_decoder != NULL) { in audio_recv()
2835 const uint8_t frame_blocks_per_sdu = sh_stream->lc3_frame_blocks_per_sdu; in audio_recv()
2836 const uint16_t octets_per_frame = sh_stream->lc3_octets_per_frame; in audio_recv()
2837 const uint8_t chan_cnt = sh_stream->lc3_chan_cnt; in audio_recv()
2865 data->sh_stream = sh_stream; in audio_recv()
2919 struct shell_stream *sh_stream = shell_stream_from_bap_stream(bap_stream); in stream_started_cb() local
2931 sh_stream->is_rx = info.can_recv; in stream_started_cb()
2932 sh_stream->is_tx = info.can_send; in stream_started_cb()
2938 if (sh_stream->is_tx) { in stream_started_cb()
2939 atomic_set(&sh_stream->tx.lc3_enqueue_cnt, PRIME_COUNT); in stream_started_cb()
2940 sh_stream->tx.lc3_sdu_cnt = 0U; in stream_started_cb()
2950 sh_stream->lc3_freq_hz = (uint32_t)ret; in stream_started_cb()
2954 sh_stream->lc3_freq_hz = 0U; in stream_started_cb()
2958 sh_stream->lc3_freq_hz = 0U; in stream_started_cb()
2962 sh_stream->lc3_freq_hz = 0U; in stream_started_cb()
2969 sh_stream->lc3_frame_duration_us = (uint32_t)ret; in stream_started_cb()
2972 sh_stream->lc3_frame_duration_us = 0U; in stream_started_cb()
2976 sh_stream->lc3_frame_duration_us = 0U; in stream_started_cb()
2980 codec_cfg, &sh_stream->lc3_chan_allocation, false); in stream_started_cb()
2982 sh_stream->lc3_chan_cnt = in stream_started_cb()
2983 bt_audio_get_chan_count(sh_stream->lc3_chan_allocation); in stream_started_cb()
2986 sh_stream->lc3_chan_allocation = BT_AUDIO_LOCATION_MONO_AUDIO; in stream_started_cb()
2987 sh_stream->lc3_chan_cnt = 1U; in stream_started_cb()
2992 sh_stream->lc3_frame_blocks_per_sdu = (uint8_t)ret; in stream_started_cb()
2995 sh_stream->lc3_frame_blocks_per_sdu = 0U; in stream_started_cb()
3000 sh_stream->lc3_octets_per_frame = (uint16_t)ret; in stream_started_cb()
3003 sh_stream->lc3_octets_per_frame = 0U; in stream_started_cb()
3007 if (sh_stream->is_tx && sh_stream->tx.lc3_encoder == NULL) { in stream_started_cb()
3008 const int err = init_lc3_encoder(sh_stream); in stream_started_cb()
3018 sh_stream->tx.active = true; in stream_started_cb()
3024 if (sh_stream->is_rx) { in stream_started_cb()
3025 if (sh_stream->rx.lc3_decoder == NULL) { in stream_started_cb()
3026 const int err = init_lc3_decoder(sh_stream); in stream_started_cb()
3036 sh_stream->rx.decoded_cnt = 0U; in stream_started_cb()
3039 if ((sh_stream->lc3_chan_allocation & in stream_started_cb()
3044 sh_stream); in stream_started_cb()
3045 usb_left_stream = sh_stream; in stream_started_cb()
3052 if ((sh_stream->lc3_chan_allocation & in stream_started_cb()
3057 sh_stream); in stream_started_cb()
3058 usb_right_stream = sh_stream; in stream_started_cb()
3071 if (sh_stream->is_tx) { in stream_started_cb()
3072 sh_stream->tx.connected_at_ticks = k_uptime_ticks(); in stream_started_cb()
3077 if (sh_stream->is_rx) { in stream_started_cb()
3078 sh_stream->rx.empty_sdu_pkts = 0U; in stream_started_cb()
3079 sh_stream->rx.valid_sdu_pkts = 0U; in stream_started_cb()
3080 sh_stream->rx.lost_pkts = 0U; in stream_started_cb()
3081 sh_stream->rx.err_pkts = 0U; in stream_started_cb()
3082 sh_stream->rx.dup_psn = 0U; in stream_started_cb()
3083 sh_stream->rx.rx_cnt = 0U; in stream_started_cb()
3084 sh_stream->rx.dup_ts = 0U; in stream_started_cb()
3092 static void update_usb_streams_cb(struct shell_stream *sh_stream, void *user_data) in update_usb_streams_cb() argument
3094 if (sh_stream->is_rx) { in update_usb_streams_cb()
3096 (sh_stream->lc3_chan_allocation & BT_AUDIO_LOCATION_FRONT_LEFT) != 0) { in update_usb_streams_cb()
3097 shell_info(ctx_shell, "Setting new USB left stream to %p", sh_stream); in update_usb_streams_cb()
3098 usb_left_stream = sh_stream; in update_usb_streams_cb()
3102 (sh_stream->lc3_chan_allocation & BT_AUDIO_LOCATION_FRONT_RIGHT) != 0) { in update_usb_streams_cb()
3103 shell_info(ctx_shell, "Setting new USB right stream to %p", sh_stream); in update_usb_streams_cb()
3104 usb_right_stream = sh_stream; in update_usb_streams_cb()
3109 static void update_usb_streams(struct shell_stream *sh_stream) in update_usb_streams() argument
3111 if (sh_stream->is_rx) { in update_usb_streams()
3112 if (sh_stream == usb_left_stream) { in update_usb_streams()
3117 if (sh_stream == usb_right_stream) { in update_usb_streams()
3127 static void clear_stream_data(struct shell_stream *sh_stream) in clear_stream_data() argument
3130 if (IS_ARRAY_ELEMENT(broadcast_sink_streams, sh_stream)) { in clear_stream_data()
3146 if (sh_stream->is_rx) { in clear_stream_data()
3148 memset(&sh_stream->rx, 0, sizeof(sh_stream->rx)); in clear_stream_data()
3153 if (sh_stream->is_tx) { in clear_stream_data()
3154 memset(&sh_stream->tx, 0, sizeof(sh_stream->tx)); in clear_stream_data()
3158 sh_stream->is_rx = sh_stream->is_tx = false; in clear_stream_data()
3162 update_usb_streams(sh_stream); in clear_stream_data()
3169 struct shell_stream *sh_stream = shell_stream_from_bap_stream(stream); in stream_stopped_cb() local
3173 clear_stream_data(sh_stream); in stream_stopped_cb()
3185 struct shell_stream *sh_stream = shell_stream_from_bap_stream(stream); in stream_released_cb() local
3226 clear_stream_data(sh_stream); in stream_released_cb()
3980 static void start_sine_stream_cb(struct shell_stream *sh_stream, void *user_data) in start_sine_stream_cb() argument
3982 if (sh_stream->is_tx) { in start_sine_stream_cb()
3983 struct bt_bap_stream *bap_stream = bap_stream_from_shell_stream(sh_stream); in start_sine_stream_cb()
3987 err = init_lc3_encoder(sh_stream); in start_sine_stream_cb()
3994 sh_stream->tx.active = true; in start_sine_stream_cb()
3995 sh_stream->tx.seq_num = get_next_seq_num(bap_stream_from_shell_stream(sh_stream)); in start_sine_stream_cb()
4018 struct shell_stream *sh_stream = shell_stream_from_bap_stream(default_stream); in cmd_start_sine() local
4020 start_sine_stream_cb(sh_stream, (void *)sh); in cmd_start_sine()
4026 static void stop_sine_stream_cb(struct shell_stream *sh_stream, void *user_data) in stop_sine_stream_cb() argument
4028 if (sh_stream->is_tx) { in stop_sine_stream_cb()
4029 struct bt_bap_stream *bap_stream = bap_stream_from_shell_stream(sh_stream); in stop_sine_stream_cb()
4034 sh_stream->tx.active = false; in stop_sine_stream_cb()
4055 struct shell_stream *sh_stream = shell_stream_from_bap_stream(default_stream); in cmd_stop_sine() local
4057 stop_sine_stream_cb(sh_stream, (void *)sh); in cmd_stop_sine()