xref: /btstack/src/classic/avrcp_target.h (revision a63b240e41589795888612304723ba387f49f6df)
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 AVRCP Target
40  *
41  */
42 
43 #ifndef AVRCP_TARGET_H
44 #define AVRCP_TARGET_H
45 
46 #include <stdint.h>
47 #include "classic/avrcp.h"
48 
49 #if defined __cplusplus
50 extern "C" {
51 #endif
52 
53 /* API_START */
54 
55 typedef enum {
56     AVRCP_TARGET_SUPPORTED_FEATURE_CATEGORY_PLAYER_OR_RECORDER = 0,
57     AVRCP_TARGET_SUPPORTED_FEATURE_CATEGORY_MONITOR_OR_AMPLIFIER,
58     AVRCP_TARGET_SUPPORTED_FEATURE_CATEGORY_TUNER,
59     AVRCP_TARGET_SUPPORTED_FEATURE_CATEGORY_MENU,
60     AVRCP_TARGET_SUPPORTED_FEATURE_PLAYER_APPLICATION_SETTINGS, // AVRCP_TARGET_SUPPORTED_FEATURE_CATEGORY_PLAYER_OR_RECORDER must be 1 for this feature to be set
61     AVRCP_TARGET_SUPPORTED_FEATURE_GROUP_NAVIGATION,            // AVRCP_TARGET_SUPPORTED_FEATURE_CATEGORY_PLAYER_OR_RECORDER must be 1 for this feature to be set
62     AVRCP_TARGET_SUPPORTED_FEATURE_BROWSING,
63     AVRCP_TARGET_SUPPORTED_FEATURE_MULTIPLE_MEDIA_PLAYER_APPLICATIONS,
64     AVRCP_TARGET_SUPPORTED_FEATURE_COVER_ART,
65 } avrcp_target_supported_feature_t;
66 
67 /**
68  * @brief AVRCP Target service record.
69  * @param service
70  * @param service_record_handle
71  * @param supported_features 16-bit bitmap, see AVRCP_FEATURE_MASK_* in avrcp.h
72  * @param service_name or NULL for default value. Provide "" (empty string) to skip attribute
73  * @param service_provider_name or NULL for default value. Provide "" (empty string) to skip attribute
74  */
75 void    avrcp_target_create_sdp_record(uint8_t * service, uint32_t service_record_handle, uint16_t supported_features, const char * service_name, const char * service_provider_name);
76 
77 /**
78  * @brief Set up AVRCP Target service.
79  */
80 void    avrcp_target_init(void);
81 
82 /**
83  * @brief Register callback for the AVRCP Target client.
84  * @param callback
85  */
86 void    avrcp_target_register_packet_handler(btstack_packet_handler_t callback);
87 
88 /**
89  * @brief Select Player that is controlled by Controller
90  * @param callback
91  * @note Callback should return if selected player is valid
92  */
93 void avrcp_target_register_set_addressed_player_handler(bool (*callback)(uint16_t player_id));
94 
95 /**
96  * @brief Register a list of Company IDs supported by target.
97  * @param avrcp_cid
98  * @param num_companies
99  * @param companies
100  * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if connection is not found, otherwise ERROR_CODE_SUCCESS
101  */
102 uint8_t avrcp_target_support_companies(uint16_t avrcp_cid, uint8_t num_companies, const uint32_t *companies);
103 
104 /**
105  * @brief Register event ID supported by target.
106  * @param avrcp_cid
107  * @param event_id
108  * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if connection is not found, ERROR_CODE_UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE for unsupported event id, otherwise ERROR_CODE_SUCCESS,
109  */
110 uint8_t avrcp_target_support_event(uint16_t avrcp_cid, avrcp_notification_event_id_t event_id);
111 
112 /**
113  * @brief Send a play status.
114  * @note  The avrcp_target_packet_handler will receive AVRCP_SUBEVENT_PLAY_STATUS_QUERY event. Use this function to respond.
115  * @param avrcp_cid
116  * @param song_length_ms
117  * @param song_position_ms
118  * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if connection is not found, otherwise ERROR_CODE_SUCCESS
119  */
120 uint8_t avrcp_target_play_status(uint16_t avrcp_cid, uint32_t song_length_ms, uint32_t song_position_ms, avrcp_playback_status_t status);
121 
122 /**
123  * @brief Set Now Playing Info that is send to Controller if notifications are enabled
124  * @param avrcp_cid
125  * @param current_track
126  * @param total_tracks
127  * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if connection is not found, ERROR_CODE_COMMAND_DISALLOWED if no track is provided, otherwise ERROR_CODE_SUCCESS
128  */
129 uint8_t avrcp_target_set_now_playing_info(uint16_t avrcp_cid, const avrcp_track_t * current_track, uint16_t total_tracks);
130 
131 /**
132  * @brief Set Playing status and send to Controller
133  * @param avrcp_cid
134  * @param playback_status
135  * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if connection is not found, otherwise ERROR_CODE_SUCCESS
136  */
137 uint8_t avrcp_target_set_playback_status(uint16_t avrcp_cid, avrcp_playback_status_t playback_status);
138 
139 /**
140  * @brief Set Unit Info
141  * @param avrcp_cid
142  * @param unit_type
143  * @param company_id
144  * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if connection is not found, otherwise ERROR_CODE_SUCCESS
145  */
146 uint8_t avrcp_target_set_unit_info(uint16_t avrcp_cid, avrcp_subunit_type_t unit_type, uint32_t company_id);
147 
148 /**
149  * @brief Set Subunit Info
150  * @param avrcp_cid
151  * @param subunit_type
152  * @param subunit_info_data
153  * @param subunit_info_data_size
154  * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if connection is not found, otherwise ERROR_CODE_SUCCESS
155  */
156 uint8_t avrcp_target_set_subunit_info(uint16_t avrcp_cid, avrcp_subunit_type_t subunit_type, const uint8_t * subunit_info_data, uint16_t subunit_info_data_size);
157 
158 /**
159  * @brief Send Playing Content Changed Notification if enabled
160  * @param avrcp_cid
161  * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if connection is not found, otherwise ERROR_CODE_SUCCESS
162  */
163 uint8_t avrcp_target_playing_content_changed(uint16_t avrcp_cid);
164 
165 /**
166  * @brief Send Addressed Player Changed Notification if enabled
167  * @param avrcp_cid
168  * @param player_id
169  * @param uid_counter
170  * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if connection is not found, otherwise ERROR_CODE_SUCCESS
171  */
172 uint8_t avrcp_target_addressed_player_changed(uint16_t avrcp_cid, uint16_t player_id, uint16_t uid_counter);
173 
174 /**
175  * @brief Set Battery Status Changed and send notification if enabled
176  * @param avrcp_cid
177  * @param battery_status
178  * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if connection is not found, otherwise ERROR_CODE_SUCCESS
179  */
180 uint8_t avrcp_target_battery_status_changed(uint16_t avrcp_cid, avrcp_battery_status_t battery_status);
181 
182 /**
183  * @brief Overwrite the absolute volume requested by controller with the actual absolute volume.
184  * This function can only be called on AVRCP_SUBEVENT_NOTIFICATION_VOLUME_CHANGED event, which indicates a set absolute volume request by controller.
185  * If the absolute volume requested by controller does not match the granularity of volume control the TG provides, you can use this function to adjust the actual value.
186  *
187  * @param avrcp_cid
188  * @param absolute_volume
189  * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if connection is not found, otherwise ERROR_CODE_SUCCESS
190  */
191 uint8_t avrcp_target_adjust_absolute_volume(uint16_t avrcp_cid, uint8_t absolute_volume);
192 
193 
194 /**
195  * @brief Set Absolute Volume and send notification if enabled
196  * @param avrcp_cid
197  * @param absolute_volume
198  * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if connection is not found, otherwise ERROR_CODE_SUCCESS
199  */
200 uint8_t avrcp_target_volume_changed(uint16_t avrcp_cid, uint8_t absolute_volume);
201 
202 /**
203  * @brief Set Track and send notification if enabled
204  * @param avrcp_cid
205  * @param trackID
206  * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if connection is not found, otherwise ERROR_CODE_SUCCESS
207  */
208 uint8_t avrcp_target_track_changed(uint16_t avrcp_cid, uint8_t * trackID);
209 
210 /**
211  * @brief Send Operation Rejected message
212  * @param avrcp_cid
213  * @param opid
214  * @param operands_length
215  * @param operand
216  * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if connection is not found, otherwise ERROR_CODE_SUCCESS
217  */
218 uint8_t avrcp_target_operation_rejected(uint16_t avrcp_cid, avrcp_operation_id_t opid, uint8_t operands_length, uint8_t operand);
219 
220 /**
221  * @brief Send Operation Accepted message
222  * @param avrcp_cid
223  * @param opid
224  * @param operands_length
225  * @param operand
226  * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if connection is not found, otherwise ERROR_CODE_SUCCESS
227  */
228 uint8_t avrcp_target_operation_accepted(uint16_t avrcp_cid, avrcp_operation_id_t opid, uint8_t operands_length, uint8_t operand);
229 
230 /**
231  * @brief Send Operation Not Implemented message
232  * @param avrcp_cid
233  * @param opid
234  * @param operands_length
235  * @param operand
236  * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if connection is not found, otherwise ERROR_CODE_SUCCESS
237  */
238 uint8_t avrcp_target_operation_not_implemented(uint16_t avrcp_cid, avrcp_operation_id_t opid, uint8_t operands_length, uint8_t operand);
239 
240 uint8_t avrcp_target_uids_changed(uint16_t avrcp_cid, uint16_t uid_counter);
241 uint8_t avrcp_target_send_response_for_play_item_cmd(uint16_t avrcp_cid, avrcp_status_code_t status);
242 uint8_t avrcp_target_send_response_for_add_to_now_playing_cmd(uint16_t avrcp_cid, avrcp_status_code_t status);
243 
244 /**
245  * @brief De-Init AVRCP Browsing Target
246  */
247 void avrcp_target_deinit(void);
248 
249 /* API_END */
250 
251  // Used by AVRCP target and AVRCP browsing target
252 extern avrcp_context_t avrcp_target_context;
253 
254 #if defined __cplusplus
255 }
256 #endif
257 
258 #endif // AVRCP_TARGET_H
259