xref: /btstack/src/classic/avrcp_target.h (revision 9e6ecc42e2e5bcf3df14d088a5dc54b167bd5d33)
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  * @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_RESERVED_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_PLAYE_APPLICATIONS
64 } avrcp_target_supported_feature_t;
65 
66 /**
67  * @brief AVRCP Target service record.
68  * @param service
69  * @param service_record_handle
70  * @param supported_features 16-bit bitmap, see AVRCP_FEATURE_MASK_* in avrcp.h
71  * @param service_name
72  * @param service_provider_name
73  */
74 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);
75 
76 /**
77  * @brief Set up AVRCP Target service.
78  */
79 void    avrcp_target_init(void);
80 
81 /**
82  * @brief Register callback for the AVRCP Target client.
83  * @param callback
84  */
85 void    avrcp_target_register_packet_handler(btstack_packet_handler_t callback);
86 
87 /**
88  * @brief Select Player that is controlled by Controller
89  * @param callback
90  * @note Callback should return if selected player is valid
91  */
92 void avrcp_target_register_set_addressed_player_handler(bool (*callback)(uint16_t player_id));
93 
94 /**
95  * @brief Send a list of Company IDs supported by target.
96  * @note  The avrcp_target_packet_handler will receive AVRCP_SUBEVENT_COMPANY_IDS_QUERY event. Use this function to respond.
97  * @param avrcp_cid
98  * @param num_company_ids
99  * @param company_ids
100  * @param company_ids_size
101  * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if connection is not found, otherwise ERROR_CODE_SUCCESS
102  */
103 uint8_t avrcp_target_supported_companies(uint16_t avrcp_cid, uint8_t num_company_ids, const uint8_t *company_ids, uint8_t company_ids_size);
104 
105 /**
106  * @brief Send a list of Events supported by target.
107  * @note  The avrcp_target_packet_handler will receive AVRCP_SUBEVENT_EVENT_IDS_QUERY event. Use this function to respond.
108  * @param avrcp_cid
109  * @param num_event_ids
110  * @param event_ids
111  * @param event_ids_size
112  * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if connection is not found, otherwise ERROR_CODE_SUCCESS
113  */
114 uint8_t avrcp_target_supported_events(uint16_t avrcp_cid, uint8_t num_event_ids, const uint8_t *event_ids, uint8_t event_ids_size);
115 
116 /**
117  * @brief Send a play status.
118  * @note  The avrcp_target_packet_handler will receive AVRCP_SUBEVENT_PLAY_STATUS_QUERY event. Use this function to respond.
119  * @param avrcp_cid
120  * @param song_length_ms
121  * @param song_position_ms
122  * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if connection is not found, otherwise ERROR_CODE_SUCCESS
123  */
124 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);
125 
126 /**
127  * @brief Set Now Playing Info that is send to Controller if notifications are enabled
128  * @param avrcp_cid
129  * @param current_track
130  * @param total_tracks
131  * @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
132  */
133 uint8_t avrcp_target_set_now_playing_info(uint16_t avrcp_cid, const avrcp_track_t * current_track, uint16_t total_tracks);
134 
135 /**
136  * @brief Set Playing status and send to Controller
137  * @param avrcp_cid
138  * @param playback_status
139  * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if connection is not found, otherwise ERROR_CODE_SUCCESS
140  */
141 uint8_t avrcp_target_set_playback_status(uint16_t avrcp_cid, avrcp_playback_status_t playback_status);
142 
143 /**
144  * @brief Set Unit Info
145  * @param avrcp_cid
146  * @param unit_type
147  * @param company_id
148  * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if connection is not found, otherwise ERROR_CODE_SUCCESS
149  */
150 uint8_t avrcp_target_set_unit_info(uint16_t avrcp_cid, avrcp_subunit_type_t unit_type, uint32_t company_id);
151 
152 /**
153  * @brief Set Subunit Info
154  * @param avrcp_cid
155  * @param subunit_type
156  * @param subunit_info_data
157  * @param subunit_info_data_size
158  * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if connection is not found, otherwise ERROR_CODE_SUCCESS
159  */
160 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);
161 
162 /**
163  * @brief Send Playing Content Changed Notification if enabled
164  * @param avrcp_cid
165  * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if connection is not found, otherwise ERROR_CODE_SUCCESS
166  */
167 uint8_t avrcp_target_playing_content_changed(uint16_t avrcp_cid);
168 
169 /**
170  * @brief Send Addressed Player Changed Notification if enabled
171  * @param avrcp_cid
172  * @param player_id
173  * @param uid_counter
174  * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if connection is not found, otherwise ERROR_CODE_SUCCESS
175  */
176 uint8_t avrcp_target_addressed_player_changed(uint16_t avrcp_cid, uint16_t player_id, uint16_t uid_counter);
177 
178 /**
179  * @brief Set Battery Status Changed and send notification if enabled
180  * @param avrcp_cid
181  * @param battery_status
182  * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if connection is not found, otherwise ERROR_CODE_SUCCESS
183  */
184 uint8_t avrcp_target_battery_status_changed(uint16_t avrcp_cid, avrcp_battery_status_t battery_status);
185 
186 /**
187  * @brief Overwrite the absolute volume requested by controller with the actual absolute volume.
188  * This function can only be called on AVRCP_SUBEVENT_NOTIFICATION_VOLUME_CHANGED event, which indicates a set absolute volume request by controller.
189  * 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.
190  *
191  * @param avrcp_cid
192  * @param absolute_volume
193  * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if connection is not found, otherwise ERROR_CODE_SUCCESS
194  */
195 uint8_t avrcp_target_adjust_absolute_volume(uint16_t avrcp_cid, uint8_t absolute_volume);
196 
197 
198 /**
199  * @brief Set Absolute Volume and send notification if enabled
200  * @param avrcp_cid
201  * @param absolute_volume
202  * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if connection is not found, otherwise ERROR_CODE_SUCCESS
203  */
204 uint8_t avrcp_target_volume_changed(uint16_t avrcp_cid, uint8_t absolute_volume);
205 
206 /**
207  * @brief Set Track and send notification if enabled
208  * @param avrcp_cid
209  * @param trackID
210  * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if connection is not found, otherwise ERROR_CODE_SUCCESS
211  */
212 uint8_t avrcp_target_track_changed(uint16_t avrcp_cid, uint8_t * trackID);
213 
214 /**
215  * @brief Send Operation Rejected message
216  * @param avrcp_cid
217  * @param opid
218  * @param operands_length
219  * @param operand
220  * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if connection is not found, otherwise ERROR_CODE_SUCCESS
221  */
222 uint8_t avrcp_target_operation_rejected(uint16_t avrcp_cid, avrcp_operation_id_t opid, uint8_t operands_length, uint8_t operand);
223 
224 /**
225  * @brief Send Operation Accepted message
226  * @param avrcp_cid
227  * @param opid
228  * @param operands_length
229  * @param operand
230  * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if connection is not found, otherwise ERROR_CODE_SUCCESS
231  */
232 uint8_t avrcp_target_operation_accepted(uint16_t avrcp_cid, avrcp_operation_id_t opid, uint8_t operands_length, uint8_t operand);
233 
234 /**
235  * @brief Send Operation Not Implemented message
236  * @param avrcp_cid
237  * @param opid
238  * @param operands_length
239  * @param operand
240  * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if connection is not found, otherwise ERROR_CODE_SUCCESS
241  */
242 uint8_t avrcp_target_operation_not_implemented(uint16_t avrcp_cid, avrcp_operation_id_t opid, uint8_t operands_length, uint8_t operand);
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