1 /*
2  * Copyright (c) 2024 Nordic Semiconductor ASA
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #include <stdint.h>
8 
9 #include <zephyr/bluetooth/audio/audio.h>
10 #include <zephyr/bluetooth/audio/cap.h>
11 #include <zephyr/bluetooth/conn.h>
12 #include <zephyr/kernel.h>
13 
14 #define SINK_CONTEXT        BT_AUDIO_CONTEXT_TYPE_UNSPECIFIED
15 #define SOURCE_CONTEXT      BT_AUDIO_CONTEXT_TYPE_UNSPECIFIED
16 
17 /** Struct to contain information for a specific peer (CAP) device */
18 struct peer_config {
19 	/** Stream for the source endpoint */
20 	struct bt_cap_stream source_stream;
21 	/** Stream for the sink endpoint */
22 	struct bt_cap_stream sink_stream;
23 	/** Semaphore to help wait for a release operation if the source stream is not idle */
24 	struct k_sem source_stream_sem;
25 	/** Semaphore to help wait for a release operation if the sink stream is not idle */
26 	struct k_sem sink_stream_sem;
27 	/** ACL connection object for the peer device */
28 	struct bt_conn *conn;
29 	/** Current sequence number for TX */
30 	uint16_t tx_seq_num;
31 };
32 
33 /**
34  * @brief Initialize the unicast part of the CAP Acceptor
35  *
36  * @param peer Pointer to the specific peer to initialize the CAP Acceptor for
37  *
38  * @retval 0 if success
39  * @retval -ENOEXEC if callbacks failed to be registered
40  */
41 int init_cap_acceptor_unicast(struct peer_config *peer);
42 
43 /**
44  * @brief Initialize the unicast part of the CAP Acceptor
45  *
46  * @retval 0 if success
47  * @retval -ENOEXEC if callbacks failed to be registered
48  */
49 int init_cap_acceptor_broadcast(void);
50 
51 /**
52  * @brief Request to allocate a CAP stream
53  *
54  * @param dir Audio direction of the stream to allocate
55  *
56  * @retval Pointer to the allocated CAP stream
57  * @retval NULL if no more CAP streams for the @p dir could be allocated
58  */
59 struct bt_cap_stream *stream_alloc(enum bt_audio_dir dir);
60 
61 /**
62  * Notify about a released stream
63 
64  * This is used to handle some state checks in the main.c file.
65  *
66  * @param cap_stream Pointer to the stream that was released
67  */
68 void stream_released(const struct bt_cap_stream *cap_stream);
69