xref: /btstack/src/classic/avdtp_source.h (revision d58a1b5f11ada8ddf896c41fff5a35e7f140c37e)
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 MATTHIAS
24  * RINGWALD 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  * avdtp_source.h
40  *
41  * Audio/Video Distribution Transport Protocol Source
42  *
43  * AVDTP Source is a device that streames media data.
44  */
45 
46 #ifndef AVDTP_SOURCE_H
47 #define AVDTP_SOURCE_H
48 
49 #include <stdint.h>
50 #include "classic/avdtp.h"
51 
52 #if defined __cplusplus
53 extern "C" {
54 #endif
55 
56 /* API_START */
57 
58 /**
59  * @brief Register media transport category with local stream endpoint identified by seid
60  * @param seid
61  */
62 void avdtp_source_register_media_transport_category(uint8_t seid);
63 
64 /**
65  * @brief Register reporting category with local stream endpoint identified by seid
66  * @param seid
67  */
68 void avdtp_source_register_reporting_category(uint8_t seid);
69 
70 /**
71  * @brief Register delay reporting category with local stream endpoint identified by seid
72  * @param seid
73  */
74 void avdtp_source_register_delay_reporting_category(uint8_t seid);
75 
76 /**
77  * @brief Register recovery category with local stream endpoint identified by seid
78  * @param seid
79  * @param maximum_recovery_window_size
80  * @param maximum_number_media_packets
81  */
82 void avdtp_source_register_recovery_category(uint8_t seid, uint8_t maximum_recovery_window_size, uint8_t maximum_number_media_packets);
83 
84 /**
85  * @brief Register content protection category with local stream endpoint identified by seid
86  * @param seid
87  * @param cp_type
88  * @param cp_type_value
89  * @param cp_type_value_len
90  */
91 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);
92 
93 /**
94  * @brief Register header compression category with local stream endpoint identified by seid
95  * @param seid
96  * @param back_ch
97  * @param media
98  * @param recovery
99  */
100 void avdtp_source_register_header_compression_category(uint8_t seid, uint8_t back_ch, uint8_t media, uint8_t recovery);
101 
102 /**
103  * @brief Register media codec category with local stream endpoint identified by seid
104  * @param seid
105  * @param media_type
106  * @param media_codec_type
107  * @param media_codec_info
108  * @param media_codec_info_len
109  */
110 void avdtp_source_register_media_codec_category(uint8_t seid, avdtp_media_type_t media_type, avdtp_media_codec_type_t media_codec_type, uint8_t * media_codec_info, uint16_t media_codec_info_len);
111 
112 /**
113  * @brief Register multiplexing category with local stream endpoint identified by seid
114  * @param seid
115  * @param fragmentation
116  */
117 void avdtp_source_register_multiplexing_category(uint8_t seid, uint8_t fragmentation);
118 
119 /**
120  * @brief Initialize up AVDTP Source device.
121  */
122 void avdtp_source_init(avdtp_context_t * avdtp_context);
123 
124 /**
125  * @brief Register callback for the AVDTP Source client. See btstack_defines.h for AVDTP_SUBEVENT_* events
126  *
127  * @param callback
128  */
129 void avdtp_source_register_packet_handler(btstack_packet_handler_t callback);
130 
131 /**
132  * @brief Connect to device with a bluetooth address. (and perform configuration?)
133  * @param bd_addr
134  * @param avdtp_cid Assigned avdtp cid
135  * @return status ERROR_CODE_SUCCESS if succesful, otherwise BTSTACK_MEMORY_ALLOC_FAILED, SDP_QUERY_BUSY
136  */
137 uint8_t avdtp_source_connect(bd_addr_t bd_addr, uint16_t * avdtp_cid);
138 
139 /**
140  * @brief Disconnect from device with connection handle.
141  * @param avdtp_cid
142  * @return status ERROR_CODE_SUCCESS if succesful, otherwise AVDTP_CONNECTION_DOES_NOT_EXIST
143  */
144 uint8_t avdtp_source_disconnect(uint16_t avdtp_cid);
145 
146 /**
147  * @brief Discover stream endpoints
148  * @param avdtp_cid
149  * @return status ERROR_CODE_SUCCESS if succesful, otherwise AVDTP_CONNECTION_DOES_NOT_EXIST, AVDTP_CONNECTION_IN_WRONG_STATE
150  */
151 uint8_t avdtp_source_discover_stream_endpoints(uint16_t avdtp_cid);
152 
153 /**
154  * @brief Get capabilities
155  * @param avdtp_cid
156  * @return status ERROR_CODE_SUCCESS if succesful, otherwise AVDTP_CONNECTION_DOES_NOT_EXIST, AVDTP_CONNECTION_IN_WRONG_STATE
157  */
158 uint8_t avdtp_source_get_capabilities(uint16_t avdtp_cid, uint8_t acp_seid);
159 
160 /**
161  * @brief Get all capabilities
162  * @param avdtp_cid
163  * @return status ERROR_CODE_SUCCESS if succesful, otherwise AVDTP_CONNECTION_DOES_NOT_EXIST, AVDTP_CONNECTION_IN_WRONG_STATE
164  */
165 uint8_t avdtp_source_get_all_capabilities(uint16_t avdtp_cid, uint8_t acp_seid);
166 
167 /**
168  * @brief Set configuration
169  * @param avdtp_cid
170  * @return status ERROR_CODE_SUCCESS if succesful, otherwise AVDTP_CONNECTION_DOES_NOT_EXIST, AVDTP_CONNECTION_IN_WRONG_STATE, AVDTP_STREAM_ENDPOINT_DOES_NOT_EXIST, AVDTP_STREAM_ENDPOINT_IN_WRONG_STATE
171  */
172 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);
173 
174 /**
175  * @brief Reconfigure stream
176  * @param avdtp_cid
177  * @param seid
178  * @return status ERROR_CODE_SUCCESS if succesful, otherwise AVDTP_CONNECTION_DOES_NOT_EXIST, AVDTP_CONNECTION_IN_WRONG_STATE, AVDTP_STREAM_ENDPOINT_DOES_NOT_EXIST, AVDTP_STREAM_ENDPOINT_IN_WRONG_STATE
179  */
180 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);
181 
182 /**
183  * @brief Get configuration
184  * @param avdtp_cid
185  * @return status ERROR_CODE_SUCCESS if succesful, otherwise AVDTP_CONNECTION_DOES_NOT_EXIST, AVDTP_CONNECTION_IN_WRONG_STATE
186  */
187 uint8_t avdtp_source_get_configuration(uint16_t avdtp_cid, uint8_t acp_seid);
188 
189 
190 /**
191  * @brief Open stream
192  * @param avdtp_cid
193  * @param seid
194  * @return status ERROR_CODE_SUCCESS if succesful, otherwise AVDTP_CONNECTION_DOES_NOT_EXIST, AVDTP_CONNECTION_IN_WRONG_STATE, AVDTP_SEID_DOES_NOT_EXIST, AVDTP_MEDIA_CONNECTION_DOES_NOT_EXIST
195  */
196 uint8_t avdtp_source_open_stream(uint16_t avdtp_cid, uint8_t int_seid, uint8_t acp_seid);
197 
198 /**
199  * @brief Start stream
200  * @param local_seid
201 * @return status ERROR_CODE_SUCCESS if succesful, otherwise AVDTP_CONNECTION_DOES_NOT_EXIST, AVDTP_SEID_DOES_NOT_EXIST, AVDTP_MEDIA_CONNECTION_DOES_NOT_EXIST
202  */
203 uint8_t avdtp_source_start_stream(uint16_t avdtp_cid, uint8_t local_seid);
204 
205 /**
206  * @brief Abort stream
207  * @param local_seid
208  * @return status ERROR_CODE_SUCCESS if succesful, otherwise AVDTP_CONNECTION_DOES_NOT_EXIST, AVDTP_SEID_DOES_NOT_EXIST, AVDTP_MEDIA_CONNECTION_DOES_NOT_EXIST
209  */
210 uint8_t avdtp_source_abort_stream(uint16_t avdtp_cid, uint8_t local_seid);
211 
212 /**
213  * @brief Start stream
214  * @param local_seid
215  * @return status ERROR_CODE_SUCCESS if succesful, otherwise AVDTP_CONNECTION_DOES_NOT_EXIST, AVDTP_SEID_DOES_NOT_EXIST, AVDTP_MEDIA_CONNECTION_DOES_NOT_EXIST,
216  */
217 uint8_t avdtp_source_stop_stream(uint16_t avdtp_cid, uint8_t local_seid);
218 
219 /**
220  * @brief Suspend stream
221  * @param local_seid
222  * @return status ERROR_CODE_SUCCESS if succesful, otherwise AVDTP_CONNECTION_DOES_NOT_EXIST, AVDTP_SEID_DOES_NOT_EXIST, AVDTP_MEDIA_CONNECTION_DOES_NOT_EXIST
223  */
224 uint8_t avdtp_source_suspend(uint16_t avdtp_cid, uint8_t local_seid);
225 
226 /**
227  * @brief Create stream endpoint
228  * @param sep_type          AVDTP_SOURCE or AVDTP_SINK, see avdtp.h
229  * @param media_type        AVDTP_AUDIO, AVDTP_VIDEO or AVDTP_MULTIMEDIA, see avdtp.h
230  * @return pointer to newly created stream endpoint, or NULL if allocation failed
231  */
232 avdtp_stream_endpoint_t * avdtp_source_create_stream_endpoint(avdtp_sep_type_t sep_type, avdtp_media_type_t media_type);
233 
234 /**
235  * @brief Send media payload.
236  * @param avdtp_cid         AVDTP channel identifyer.
237  * @param local_seid        ID of a local stream endpoint.
238  * @param storage
239  * @param num_bytes_to_copy
240  * @param num_frames
241  * @param marker
242  * @return max_media_payload_size_without_media_header
243  */
244 int avdtp_source_stream_send_media_payload(uint16_t avdtp_cid, uint8_t local_seid, uint8_t * storage, int num_bytes_to_copy, uint8_t num_frames, uint8_t marker);
245 
246 /**
247  * @brief Request to send a media packet. Packet can be then sent on reception of AVDTP_SUBEVENT_STREAMING_CAN_SEND_MEDIA_PACKET_NOW event.
248  * @param avdtp_cid         AVDTP channel identifyer.
249  * @param local_seid        ID of a local stream endpoint.
250  */
251 void avdtp_source_stream_endpoint_request_can_send_now(uint16_t avddp_cid, uint8_t local_seid);
252 
253 /**
254  * @brief Return maximal media payload size, does not include media header.
255  * @param avdtp_cid         AVDTP channel identifyer.
256  * @param local_seid        ID of a local stream endpoint.
257  */
258 int avdtp_max_media_payload_size(uint16_t avdtp_cid, uint8_t local_seid);
259 
260 /* API_END */
261 
262 #if defined __cplusplus
263 }
264 #endif
265 
266 #endif // AVDTP_SOURCE_H
267