xref: /btstack/src/classic/avrcp_controller.h (revision 2c4f9bbb6d93b3f1a90ed62ac67e4cd019f0736a)
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  * avrcp.h
40  *
41  * Audio/Video Remote Control Profile
42  *
43  */
44 
45 #ifndef AVRCP_CONTROLLER_H
46 #define AVRCP_CONTROLLER_H
47 
48 #include <stdint.h>
49 #include "btstack_run_loop.h"
50 #include "btstack_linked_list.h"
51 #include "classic/avrcp.h"
52 
53 #if defined __cplusplus
54 extern "C" {
55 #endif
56 
57 /* API_START */
58 
59 typedef enum {
60     AVRCP_CONTROLLER_SUPPORTED_FEATURE_CATEGORY_PLAYER_OR_RECORDER = 0,
61     AVRCP_CONTROLLER_SUPPORTED_FEATURE_CATEGORY_MONITOR_OR_AMPLIFIER,
62     AVRCP_CONTROLLER_SUPPORTED_FEATURE_CATEGORY_TUNER,
63     AVRCP_CONTROLLER_SUPPORTED_FEATURE_CATEGORY_MENU,
64     AVRCP_CONTROLLER_SUPPORTED_FEATURE_RESERVED_4,
65     AVRCP_CONTROLLER_SUPPORTED_FEATURE_RESERVED_5,
66     AVRCP_CONTROLLER_SUPPORTED_FEATURE_BROWSING
67 } avrcp_controller_supported_feature_t;
68 
69 /**
70  * @brief AVRCP Controller service record.
71  * @param service
72  * @param service_record_handle
73  * @param supported_features 16-bit bitmap, see AVRCP_FEATURE_MASK_* in avrcp.h
74  * @param service_name
75  * @param service_provider_name
76  */
77 void avrcp_controller_create_sdp_record(uint8_t * service, uint32_t service_record_handle, uint16_t supported_features, const char * service_name, const char * service_provider_name);
78 
79 /**
80  * @brief Set up AVRCP Controller service.
81  */
82 void avrcp_controller_init(void);
83 
84 /**
85  * @brief Register callback for the AVRCP Controller client.
86  * @param callback
87  */
88 void avrcp_controller_register_packet_handler(btstack_packet_handler_t callback);
89 
90 /**
91  * @brief Set max num fragments in whuch message can be transmited.
92  * @param avrcp_cid
93  * @param max_num_fragments
94  * @returns status
95  */
96 uint8_t avrcp_controller_set_max_num_fragments(uint16_t avrcp_cid, uint8_t max_num_fragments);
97 
98 
99 /**
100  * @brief Unit info.
101  * @param avrcp_cid
102  * @returns status
103  */
104 uint8_t avrcp_controller_unit_info(uint16_t avrcp_cid);
105 
106 /**
107  * @brief Subunit info.
108  * @param avrcp_cid
109  * @returns status
110  */
111 uint8_t avrcp_controller_subunit_info(uint16_t avrcp_cid);
112 
113 /**
114  * @brief Get capabilities.
115  * @param avrcp_cid
116  * @returns status
117  */
118 uint8_t avrcp_controller_get_supported_company_ids(uint16_t avrcp_cid);
119 
120 /**
121  * @brief Get supported Events.
122  * @param avrcp_cid
123  * @returns status
124  */
125 uint8_t avrcp_controller_get_supported_events(uint16_t avrcp_cid);
126 
127 
128 /**
129  * @brief Start continuous cmd (play, pause, volume up, ...). Event AVRCP_SUBEVENT_OPERATION_COMPLETE returns operation id and status.
130  * @param avrcp_cid
131  * @returns status
132  */
133 uint8_t avrcp_controller_start_press_and_hold_cmd(uint16_t avrcp_cid, avrcp_operation_id_t operation_id);
134 
135 /**
136  * @brief Stops continuous cmd (play, pause, volume up, ...). Event AVRCP_SUBEVENT_OPERATION_COMPLETE returns operation id and status.
137  * @param avrcp_cid
138  * @returns status
139  */
140 uint8_t avrcp_controller_release_press_and_hold_cmd(uint16_t avrcp_cid);
141 
142 /**
143  * @brief Play. Event AVRCP_SUBEVENT_OPERATION_COMPLETE returns operation id and status.
144  * @param avrcp_cid
145  * @returns status
146  */
147 uint8_t avrcp_controller_play(uint16_t avrcp_cid);
148 uint8_t avrcp_controller_press_and_hold_play(uint16_t avrcp_cid);
149 
150 /**
151  * @brief Stop. Event AVRCP_SUBEVENT_OPERATION_COMPLETE returns operation id and status.
152  * @param avrcp_cid
153  * @returns status
154  */
155 uint8_t avrcp_controller_stop(uint16_t avrcp_cid);
156 uint8_t avrcp_controller_press_and_hold_stop(uint16_t avrcp_cid);
157 
158 /**
159  * @brief Pause. Event AVRCP_SUBEVENT_OPERATION_COMPLETE returns operation id and status.
160  * @param avrcp_cid
161  * @returns status
162  */
163 uint8_t avrcp_controller_pause(uint16_t avrcp_cid);
164 uint8_t avrcp_controller_press_and_hold_pause(uint16_t avrcp_cid);
165 
166 /**
167  * @brief Single step - fast forward. Event AVRCP_SUBEVENT_OPERATION_COMPLETE returns operation id and status.
168  * @param avrcp_cid
169  * @returns status
170  */
171 uint8_t avrcp_controller_fast_forward(uint16_t avrcp_cid);
172 uint8_t avrcp_controller_press_and_hold_fast_forward(uint16_t avrcp_cid);
173 
174 
175 /**
176  * @brief Single step rewind. Event AVRCP_SUBEVENT_OPERATION_COMPLETE returns operation id and status.
177  * @param avrcp_cid
178  * @returns status
179  */
180 uint8_t avrcp_controller_rewind(uint16_t avrcp_cid);
181 uint8_t avrcp_controller_press_and_hold_rewind(uint16_t avrcp_cid);
182 
183 /**
184  * @brief Forward. Event AVRCP_SUBEVENT_OPERATION_COMPLETE returns operation id and status.
185  * @param avrcp_cid
186  * @returns status
187  */
188 uint8_t avrcp_controller_forward(uint16_t avrcp_cid);
189 uint8_t avrcp_controller_press_and_hold_forward(uint16_t avrcp_cid);
190 
191 /**
192  * @brief Backward. Event AVRCP_SUBEVENT_OPERATION_COMPLETE returns operation id and status.
193  * @param avrcp_cid
194  * @returns status
195  */
196 uint8_t avrcp_controller_backward(uint16_t avrcp_cid);
197 uint8_t avrcp_controller_press_and_hold_backward(uint16_t avrcp_cid);
198 
199 /**
200  * @brief Turns the volume to high. Event AVRCP_SUBEVENT_OPERATION_COMPLETE returns operation id and status.
201  * @param avrcp_cid
202  * @returns status
203  */
204 uint8_t avrcp_controller_volume_up(uint16_t avrcp_cid);
205 uint8_t avrcp_controller_press_and_hold_volume_up(uint16_t avrcp_cid);
206 /**
207  * @brief Turns the volume to low. Event AVRCP_SUBEVENT_OPERATION_COMPLETE returns operation id and status.
208  * @param avrcp_cid
209  * @returns status
210  */
211 uint8_t avrcp_controller_volume_down(uint16_t avrcp_cid);
212 uint8_t avrcp_controller_press_and_hold_volume_down(uint16_t avrcp_cid);
213 
214 /**
215  * @brief Puts the sound out. Event AVRCP_SUBEVENT_OPERATION_COMPLETE returns operation id and status.
216  * @param avrcp_cid
217  * @returns status
218  */
219 uint8_t avrcp_controller_mute(uint16_t avrcp_cid);
220 uint8_t avrcp_controller_press_and_hold_mute(uint16_t avrcp_cid);
221 
222 /**
223  * @brief Get play status. Returns event of type AVRCP_SUBEVENT_PLAY_STATUS (length, position, play_status).
224  * If TG does not support SongLength And SongPosition on TG, then TG shall return 0xFFFFFFFF.
225  * @param avrcp_cid
226  * @returns status
227  */
228 uint8_t avrcp_controller_get_play_status(uint16_t avrcp_cid);
229 
230 /**
231  * @brief Enable notification. Response via AVRCP_SUBEVENT_ENABLE_NOTIFICATION_COMPLETE.
232  * @param avrcp_cid
233  * @param event_id
234  * @returns status
235  */
236 uint8_t avrcp_controller_enable_notification(uint16_t avrcp_cid, avrcp_notification_event_id_t event_id);
237 
238 /**
239  * @brief Disable notification. Response via AVRCP_SUBEVENT_ENABLE_NOTIFICATION_COMPLETE.
240  * @param avrcp_cid
241  * @param event_id
242  * @returns status
243  */
244 uint8_t avrcp_controller_disable_notification(uint16_t avrcp_cid, avrcp_notification_event_id_t event_id);
245 
246 /**
247  * @brief Get info on now playing media using subset of attribute IDs
248  * @param avrcp_cid
249  * @returns status
250  */
251 uint8_t avrcp_controller_get_element_attributes(uint16_t avrcp_cid, uint8_t num_attributes, avrcp_media_attribute_id_t * attributes);
252 
253 /**
254  * @brief Get info on now playing media using all IDs.
255  * @param avrcp_cid
256  * @returns status
257  */
258 uint8_t avrcp_controller_get_now_playing_info(uint16_t avrcp_cid);
259 
260 /**
261  * @brief Set absolute volume 0-127 (corresponds to 0-100%). Response via AVRCP_SUBEVENT_SET_ABSOLUTE_VOLUME_RESPONSE
262  * @param avrcp_cid
263  * @returns status
264  */
265 uint8_t avrcp_controller_set_absolute_volume(uint16_t avrcp_cid, uint8_t volume);
266 
267 
268 /**
269  * @brief Skip to next playing media. Event AVRCP_SUBEVENT_OPERATION_COMPLETE returns operation id and status.
270  * @param avrcp_cid
271  * @returns status
272  */
273 uint8_t avrcp_controller_skip(uint16_t avrcp_cid);
274 
275 /**
276  * @brief Query repeat and shuffle mode. Response via AVRCP_SUBEVENT_SHUFFLE_AND_REPEAT_MODE.
277  * @param avrcp_cid
278  * @returns status
279  */
280 uint8_t avrcp_controller_query_shuffle_and_repeat_modes(uint16_t avrcp_cid);
281 
282 /**
283  * @brief Set shuffle mode. Event AVRCP_SUBEVENT_OPERATION_COMPLETE returns operation id and status.
284  * @param avrcp_cid
285  * @returns status
286  */
287 uint8_t avrcp_controller_set_shuffle_mode(uint16_t avrcp_cid, avrcp_shuffle_mode_t mode);
288 
289 /**
290  * @brief Set repeat mode. Event AVRCP_SUBEVENT_OPERATION_COMPLETE returns operation id and status.
291  * @param avrcp_cid
292  * @returns status
293  */
294 uint8_t avrcp_controller_set_repeat_mode(uint16_t avrcp_cid, avrcp_repeat_mode_t mode);
295 
296 /**
297  * @brief The PlayItem command starts playing an item indicated by the UID. It is routed to the Addressed Player.
298  * @param avrcp_cid
299  * @param uid
300  * @param uid_counter
301  * @param scope
302  **/
303 uint8_t avrcp_controller_play_item_for_scope(uint16_t avrcp_cid, uint8_t * uid, uint16_t uid_counter, avrcp_browsing_scope_t scope);
304 
305 /**
306  * @brief Adds an item indicated by the UID to the Now Playing queue.
307  * @param avrcp_cid
308  * @param uid
309  * @param uid_counter
310  * @param scope
311  **/
312 uint8_t avrcp_controller_add_item_from_scope_to_now_playing_list(uint16_t avrcp_cid, uint8_t * uid, uint16_t uid_counter, avrcp_browsing_scope_t scope);
313 
314 /**
315  * @brief Set addressed player.
316  * @param avrcp_cid
317  * @param addressed_player_id
318  */
319 uint8_t avrcp_controller_set_addressed_player(uint16_t avrcp_cid, uint16_t addressed_player_id);
320 
321 /**
322  * @brief Send custom command
323  * @param avrcp_cid
324  * @param command_type
325  * @param subunit_type
326  * @param subunit ID
327  * @param command_opcode
328  * @param command_buffer
329  * @param command_len
330  */
331 uint8_t avrcp_controller_send_custom_command(uint16_t avrcp_cid, avrcp_command_type_t command_type, avrcp_subunit_type_t subunit_type, avrcp_subunit_id_t subunit_id, avrcp_command_opcode_t command_opcode, const uint8_t * command_buffer, uint16_t command_len);
332 
333 /**
334  * @brief De-Init AVRCP Controller
335  */
336 void avrcp_controller_deinit(void);
337 
338 /* API_END */
339 
340 // Used by AVRCP controller and AVRCP browsing controller
341 extern avrcp_context_t avrcp_controller_context;
342 
343 #if defined __cplusplus
344 }
345 #endif
346 
347 #endif // AVRCP_CONTROLLER_H
348