1 /* btp_bap_audio_stream.h - Bluetooth BAP Tester */
2 
3 /*
4  * Copyright (c) 2023 Codecoup
5  * Copyright (c) 2024 Nordic Semiconductor ASA
6  *
7  * SPDX-License-Identifier: Apache-2.0
8  */
9 
10 #ifndef BTP_BAP_AUDIO_STREAM_H
11 #define BTP_BAP_AUDIO_STREAM_H
12 
13 #include <stdint.h>
14 
15 #include <zephyr/bluetooth/conn.h>
16 #include <zephyr/bluetooth/audio/bap.h>
17 #include <zephyr/bluetooth/audio/cap.h>
18 #include <zephyr/sys/util_macro.h>
19 #include <zephyr/types.h>
20 
21 struct btp_bap_audio_stream {
22 	struct bt_cap_stream cap_stream;
23 };
24 
25 /**
26  * @brief Initialize TX
27  *
28  * This will initialize TX if not already initialized. This creates and starts a thread that
29  * will attempt to send data on all streams registered with btp_bap_audio_stream_tx_register().
30  */
31 void btp_bap_audio_stream_tx_init(void);
32 
33 /**
34  * @brief Register a stream for TX
35  *
36  * This will add it to the list of streams the TX thread will attempt to send on.
37  *
38  * @param bap_stream The stream to register
39  *
40  * @retval 0 on success
41  * @retval -EINVAL @p bap_stream is NULL
42  * @retval -EINVAL @p bap_stream is not configured for TX
43  * @retval -EINVAL @p bap_stream.codec_cfg contains invalid values
44  * @retval -ENOMEM if not more streams can be registered
45  */
46 int btp_bap_audio_stream_tx_register(struct btp_bap_audio_stream *stream);
47 
48 /**
49  * @brief Unregister a stream for TX
50  *
51  * This will remove it to the list of streams the TX thread will attempt to send on.
52  *
53  * @param bap_stream The stream to unregister
54  *
55  * @retval 0 on success
56  * @retval -EINVAL @p bap_stream is NULL
57  * @retval -EINVAL @p bap_stream is not configured for TX
58  * @retval -EALREADY @p bap_stream is currently not registered
59  */
60 int btp_bap_audio_stream_tx_unregister(struct btp_bap_audio_stream *stream);
61 
62 /**
63  * @brief Test if the provided stream has been configured for TX
64  *
65  * @param bap_stream The stream to test for TX support
66  *
67  * @retval true if it has been configured for TX, and false if not
68  */
69 bool btp_bap_audio_stream_can_send(struct btp_bap_audio_stream *stream);
70 
71 /**
72  * @brief Callback to indicate a TX complete
73  *
74  * @param stream The stream that completed TX
75  */
76 void btp_bap_audio_stream_sent_cb(struct bt_bap_stream *stream);
77 
78 /* Generate 310 octets of mock data going 0x00, 0x01, ..., 0xff, 0x00, 0x01, ..., 0xff, etc
79  * For 2 x 155 = 310 octets is used as the maximum number of channels per stream defined by BAP is 2
80  * and the maximum octets per codec frame is 155 for the 48_6 configs.
81  * If we ever want to send multiple frames per SDU, we can simply multiply this value.
82  */
83 #define BTP_BAP_AUDIO_STREAM_ISO_DATA_GEN(_i, _) (uint8_t) _i
84 static const uint8_t btp_bap_audio_stream_mock_data[] = {
85 	LISTIFY(310, BTP_BAP_AUDIO_STREAM_ISO_DATA_GEN, (,)),
86 };
87 #endif /* BTP_BAP_AUDIO_STREAM_H */
88