xref: /btstack/example/le_audio_demo_util_sink.h (revision c1b6583a190ace9247a1f81941d6be4382eb4f1e)
1 /*
2  * Copyright (C) 2023 BlueKitchen GmbH
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 3. Neither the name of the copyright holders nor the names of
14  *    contributors may be used to endorse or promote products derived
15  *    from this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS
18  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
20  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BLUEKITCHEN
21  * GMBH OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
22  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
23  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
24  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
25  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
27  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28  * SUCH DAMAGE.
29  *
30  */
31 
32 /**
33  *  @brief Send/receive isochronous audio, used by le_audio_* demos
34  */
35 
36 #ifndef LE_AUDIO_DEMO_UTIL_SINK_H
37 #define LE_AUDIO_DEMO_UTIL_SINK_H
38 
39 #include <stdint.h>
40 #include "bluetooth.h"
41 #include "btstack_bool.h"
42 #include "btstack_lc3.h"
43 
44 #if defined __cplusplus
45 extern "C" {
46 #endif
47 
48 enum btstack_codec_ids_e {
49     BTSTACK_CODEC_ID_NONE = 0,
50     BTSTACK_CODEC_ID_COUNTER,
51     BTSTACK_CODEC_ID_LOOPBACK,
52 };
53 
54 /**
55  * @brief Init sink functionality
56  * @param filename_wav
57  */
58 void le_audio_demo_util_sink_init(const char * filename_wav);
59 
60 /**
61  * @brief Enable LC3plus if available for 10 ms frame duration
62  * @param enable
63  */
64 void le_audio_demo_util_sink_enable_lc3plus(bool enable);
65 
66 /**
67  * @brief Configure unicast sink
68  *        Supported num_streams x num_channels_per_stream configurations: 1 x 1, 1 x 2, 2 x 1
69  * @param num_streams
70  * @param num_channels_per_stream
71  * @param sampling_frequency_hz
72  * @param frame_duration
73  * @param octets_per_frame
74  * @param iso_interval_1250us
75  * @param flush_timeout
76  */
77 void le_audio_demo_util_sink_configure_unicast(uint8_t num_streams, uint8_t num_channels_per_stream, uint32_t sampling_frequency_hz,
78                                                btstack_lc3_frame_duration_t frame_duration, uint16_t octets_per_frame,
79                                                uint32_t iso_interval_1250us, uint8_t flush_timeout);
80 
81 /**
82  * @brief Configure broadcast sink
83  *        Supported num_streams x num_channels_per_stream configurations: 1 x 1, 1 x 2, 2 x 1
84  * @param num_streams
85  * @param num_channels_per_stream
86  * @param sampling_frequency_hz
87  * @param frame_duration
88  * @param octets_per_frame
89  * @param iso_interval_1250us
90  * @param pre_transmission_offset
91  */
92 void le_audio_demo_util_sink_configure_broadcast(uint8_t num_streams, uint8_t num_channels_per_stream, uint32_t sampling_frequency_hz,
93                                                btstack_lc3_frame_duration_t frame_duration, uint16_t octets_per_frame,
94                                                uint32_t iso_interval_1250us, uint8_t pre_transmission_offset);
95 
96 /**
97  * @brief Process ISO packet
98  * @param stream_index
99  * @param packet
100  * @param size
101  */
102 void le_audio_demo_util_sink_receive(uint8_t stream_index, uint8_t *packet, uint16_t size);
103 
104 /**
105  * @brief Analyze counting ISO packets
106  * @param stream_index
107  * @param packet
108  * @param size
109  */
110 void le_audio_demo_util_sink_count(uint8_t stream_index, uint8_t *packet, uint16_t size);
111 
112 /**
113  * @brief Close sink: close wav file, stop playbacl
114  */
115 void le_audio_demo_util_sink_close(void);
116 
117 #if defined __cplusplus
118 }
119 #endif
120 #endif // LE_AUDIO_DEMO_UTIL_SINK_H
121