xref: /btstack/src/classic/avdtp_source.h (revision ced70f9bfeafe291ec597a3a9cc862e39e0da3ce)
1 /*
2  * Copyright (C) 2016 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  * 4. Any redistribution, use, or modification is done solely for
17  *    personal benefit and not for any commercial purpose or for
18  *    monetary gain.
19  *
20  * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS
21  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BLUEKITCHEN
24  * GMBH OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
27  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
28  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
30  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31  * SUCH DAMAGE.
32  *
33  * Please inquire about commercial licensing options at
34  * [email protected]
35  *
36  */
37 
38 /**
39  * @title AVDTP Source
40  *
41  * Audio/Video Distribution Transport Protocol (AVDTP) Source is a device that streames media data.
42  *
43  */
44 
45 #ifndef AVDTP_SOURCE_H
46 #define AVDTP_SOURCE_H
47 
48 #include <stdint.h>
49 #include "classic/avdtp.h"
50 
51 #if defined __cplusplus
52 extern "C" {
53 #endif
54 
55 /* API_START */
56 
57 /**
58  * @brief Register media transport category with local stream endpoint identified by seid
59  * @param seid
60  */
61 void avdtp_source_register_media_transport_category(uint8_t seid);
62 
63 /**
64  * @brief Register reporting category with local stream endpoint identified by seid
65  * @param seid
66  */
67 void avdtp_source_register_reporting_category(uint8_t seid);
68 
69 /**
70  * @brief Register delay reporting category with local stream endpoint identified by seid
71  * @param seid
72  */
73 void avdtp_source_register_delay_reporting_category(uint8_t seid);
74 
75 /**
76  * @brief Register recovery category with local stream endpoint identified by seid
77  * @param seid
78  * @param maximum_recovery_window_size
79  * @param maximum_number_media_packets
80  */
81 void avdtp_source_register_recovery_category(uint8_t seid, uint8_t maximum_recovery_window_size, uint8_t maximum_number_media_packets);
82 
83 /**
84  * @brief Register content protection category with local stream endpoint identified by seid
85  * @param seid
86  * @param cp_type
87  * @param cp_type_value
88  * @param cp_type_value_len
89  */
90 void avdtp_source_register_content_protection_category(uint8_t seid, uint16_t cp_type, const uint8_t * cp_type_value, uint8_t cp_type_value_len);
91 
92 /**
93  * @brief Register header compression category with local stream endpoint identified by seid
94  * @param seid
95  * @param back_ch
96  * @param media
97  * @param recovery
98  */
99 void avdtp_source_register_header_compression_category(uint8_t seid, uint8_t back_ch, uint8_t media, uint8_t recovery);
100 
101 /**
102  * @brief Register media codec category with local stream endpoint identified by seid
103  * @param seid
104  * @param media_type
105  * @param media_codec_type
106  * @param media_codec_info
107  * @param media_codec_info_len
108  */
109 void avdtp_source_register_media_codec_category(uint8_t seid, avdtp_media_type_t media_type, avdtp_media_codec_type_t media_codec_type, const uint8_t *media_codec_info, uint16_t media_codec_info_len);
110 
111 /**
112  * @brief Register multiplexing category with local stream endpoint identified by seid
113  * @param seid
114  * @param fragmentation
115  */
116 void avdtp_source_register_multiplexing_category(uint8_t seid, uint8_t fragmentation);
117 
118 /**
119  * @brief Initialize up AVDTP Source device.
120  */
121 void avdtp_source_init(void);
122 
123 /**
124  * @brief Register callback for the AVDTP Source client. See btstack_defines.h for AVDTP_SUBEVENT_* events
125  *
126  * @param callback
127  */
128 void avdtp_source_register_packet_handler(btstack_packet_handler_t callback);
129 
130 /**
131  * @brief Connect to device with a bluetooth address. (and perform configuration?)
132  * @param bd_addr
133  * @param avdtp_cid Assigned avdtp cid
134  * @return status ERROR_CODE_SUCCESS if succesful, otherwise BTSTACK_MEMORY_ALLOC_FAILED, SDP_QUERY_BUSY
135  */
136 uint8_t avdtp_source_connect(bd_addr_t bd_addr, uint16_t * avdtp_cid);
137 
138 /**
139  * @brief Disconnect from device with connection handle.
140  * @param avdtp_cid
141  * @return status ERROR_CODE_SUCCESS if succesful, otherwise ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER
142  */
143 uint8_t avdtp_source_disconnect(uint16_t avdtp_cid);
144 
145 /**
146  * @brief Discover stream endpoints
147  * @param avdtp_cid
148  * @return status ERROR_CODE_SUCCESS if succesful, otherwise ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER, ERROR_CODE_COMMAND_DISALLOWED
149  */
150 uint8_t avdtp_source_discover_stream_endpoints(uint16_t avdtp_cid);
151 
152 /**
153  * @brief Get capabilities
154  * @param avdtp_cid
155  * @return status ERROR_CODE_SUCCESS if succesful, otherwise ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER, ERROR_CODE_COMMAND_DISALLOWED
156  */
157 uint8_t avdtp_source_get_capabilities(uint16_t avdtp_cid, uint8_t acp_seid);
158 
159 /**
160  * @brief Get all capabilities
161  * @param avdtp_cid
162  * @return status ERROR_CODE_SUCCESS if succesful, otherwise ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER, ERROR_CODE_COMMAND_DISALLOWED
163  */
164 uint8_t avdtp_source_get_all_capabilities(uint16_t avdtp_cid, uint8_t acp_seid);
165 
166 /**
167  * @brief Set configuration
168  * @param avdtp_cid
169  * @return status ERROR_CODE_SUCCESS if succesful, otherwise ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER, ERROR_CODE_COMMAND_DISALLOWED
170  */
171 uint8_t avdtp_source_set_configuration(uint16_t avdtp_cid, uint8_t int_seid, uint8_t acp_seid, uint16_t configured_services_bitmap, avdtp_capabilities_t configuration);
172 
173 /**
174  * @brief Reconfigure stream
175  * @param avdtp_cid
176  * @param seid
177  * @return status ERROR_CODE_SUCCESS if succesful, otherwise ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER, ERROR_CODE_COMMAND_DISALLOWED
178  */
179 uint8_t avdtp_source_reconfigure(uint16_t avdtp_cid, uint8_t int_seid, uint8_t acp_seid, uint16_t configured_services_bitmap, avdtp_capabilities_t configuration);
180 
181 /**
182  * @brief Get configuration
183  * @param avdtp_cid
184  * @return status ERROR_CODE_SUCCESS if succesful, otherwise ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER, ERROR_CODE_COMMAND_DISALLOWED
185  */
186 uint8_t avdtp_source_get_configuration(uint16_t avdtp_cid, uint8_t acp_seid);
187 
188 
189 /**
190  * @brief Open stream
191  * @param avdtp_cid
192  * @param seid
193  * @return status ERROR_CODE_SUCCESS if succesful, otherwise ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER, ERROR_CODE_COMMAND_DISALLOWED
194  */
195 uint8_t avdtp_source_open_stream(uint16_t avdtp_cid, uint8_t int_seid, uint8_t acp_seid);
196 
197 /**
198  * @brief Start stream
199  * @param local_seid
200 * @return status ERROR_CODE_SUCCESS if succesful, otherwise ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER, ERROR_CODE_COMMAND_DISALLOWED
201  */
202 uint8_t avdtp_source_start_stream(uint16_t avdtp_cid, uint8_t local_seid);
203 
204 /**
205  * @brief Abort stream
206  * @param local_seid
207  * @return status ERROR_CODE_SUCCESS if succesful, otherwise ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER, ERROR_CODE_COMMAND_DISALLOWED
208  */
209 uint8_t avdtp_source_abort_stream(uint16_t avdtp_cid, uint8_t local_seid);
210 
211 /**
212  * @brief Start stream
213  * @param local_seid
214  * @return status ERROR_CODE_SUCCESS if succesful, otherwise ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER, ERROR_CODE_COMMAND_DISALLOWED
215  */
216 uint8_t avdtp_source_stop_stream(uint16_t avdtp_cid, uint8_t local_seid);
217 
218 /**
219  * @brief Suspend stream
220  * @param local_seid
221  * @return status ERROR_CODE_SUCCESS if succesful, otherwise ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER, ERROR_CODE_COMMAND_DISALLOWED
222  */
223 uint8_t avdtp_source_suspend(uint16_t avdtp_cid, uint8_t local_seid);
224 
225 /**
226  * @brief Create stream endpoint
227  * @param sep_type          AVDTP_SOURCE or AVDTP_SINK, see avdtp.h
228  * @param media_type        AVDTP_AUDIO, AVDTP_VIDEO or AVDTP_MULTIMEDIA, see avdtp.h
229  * @return pointer to newly created stream endpoint, or NULL if allocation failed
230  */
231 avdtp_stream_endpoint_t * avdtp_source_create_stream_endpoint(avdtp_sep_type_t sep_type, avdtp_media_type_t media_type);
232 
233 /**
234  *  @brief Unregister stream endpoint and free it's memory
235  *  @param stream_endpoint created by avdtp_sink_create_stream_endpoint
236  */
237 void avdtp_source_finalize_stream_endpoint(avdtp_stream_endpoint_t * stream_endpoint);
238 
239 /**
240  * @brief Send media packet
241  * @param avdtp_cid         AVDTP channel identifier.
242  * @param local_seid        ID of a local stream endpoint.
243  * @param packet
244  * @param size
245  * @return status
246  */
247 uint8_t avdtp_source_stream_send_media_packet(uint16_t avdtp_cid, uint8_t local_seid, const uint8_t * packet, uint16_t size);
248 
249 /**
250  * @brief Send media payload including RTP header
251  * @param avdtp_cid         AVDTP channel identifier.
252  * @param local_seid        ID of a local stream endpoint.
253  * @param marker
254  * @param timestamp         in sample rate units
255  * @param payload
256  * @param size
257  * @return status
258  */
259 uint8_t
260 avdtp_source_stream_send_media_payload_rtp(uint16_t avdtp_cid, uint8_t local_seid, uint8_t marker, uint32_t timestamp,
261                                            const uint8_t *payload, uint16_t size);
262 
263 /**
264  * @brief Request to send a media packet. Packet can be then sent on reception of AVDTP_SUBEVENT_STREAMING_CAN_SEND_MEDIA_PACKET_NOW event.
265  * @param avdtp_cid         AVDTP channel identifier.
266  * @param local_seid        ID of a local stream endpoint.
267  */
268 void avdtp_source_stream_endpoint_request_can_send_now(uint16_t avddp_cid, uint8_t local_seid);
269 
270 /**
271  * @brief Return maximal media payload size, does not include media header.
272  * @param avdtp_cid         AVDTP channel identifier.
273  * @param local_seid        ID of a local stream endpoint.
274  */
275 int avdtp_max_media_payload_size(uint16_t avdtp_cid, uint8_t local_seid);
276 
277 /**
278  * @brief Register media configuration validator. Can reject insuitable configuration or report stream endpoint as currently busy
279  * @note validator has to return AVDTP error codes like: AVDTP_ERROR_CODE_SEP_IN_USE or AVDTP_ERROR_CODE_UNSUPPORTED_CONFIGURATION
280  *       the callback receives the media configuration in the same format as the existing AVDTP_SUBEVENT_SIGNALING_MEDIA_CODEC_SBC_CONFIGURATION
281  *       and similar
282  * @param callback
283  */
284 void avdtp_source_register_media_config_validator(uint8_t (*callback)(const avdtp_stream_endpoint_t * stream_endpoint, const uint8_t * event, uint16_t size));
285 
286 /**
287  * @brief De-Init AVDTP Source.
288  */
289 void avdtp_source_deinit(void);
290 
291 /* API_END */
292 
293 #if defined __cplusplus
294 }
295 #endif
296 
297 #endif // AVDTP_SOURCE_H
298