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