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 browsing 1 - supported, 0 - not supported 74 * @param supported_features 16-bit bitmap, see AVDTP_SINK_SF_* values in avdtp.h 75 * @param service_name 76 * @param service_provider_name 77 */ 78 void avrcp_controller_create_sdp_record(uint8_t * service, uint32_t service_record_handle, uint8_t browsing, uint16_t supported_features, const char * service_name, const char * service_provider_name); 79 80 /** 81 * @brief Set up AVRCP Controller device. 82 */ 83 void avrcp_controller_init(void); 84 85 /** 86 * @brief Register callback for the AVRCP Controller client. 87 * @param callback 88 */ 89 void avrcp_controller_register_packet_handler(btstack_packet_handler_t callback); 90 91 /** 92 * @brief Connect to device with a Bluetooth address. 93 * @param bd_addr 94 * @param avrcp_cid 95 * @returns status 96 */ 97 uint8_t avrcp_controller_connect(bd_addr_t bd_addr, uint16_t * avrcp_cid); 98 99 /** 100 * @brief Disconnect from AVRCP target 101 * @param avrcp_cid 102 * @returns status 103 */ 104 uint8_t avrcp_controller_disconnect(uint16_t avrcp_cid); 105 106 /** 107 * @brief Set max num fragments in whuch message can be transmited. 108 * @param avrcp_cid 109 * @param max_num_fragments 110 * @returns status 111 */ 112 uint8_t avrcp_controller_set_max_num_fragments(uint16_t avrcp_cid, uint8_t max_num_fragments); 113 114 115 /** 116 * @brief Unit info. 117 * @param avrcp_cid 118 * @returns status 119 */ 120 uint8_t avrcp_controller_unit_info(uint16_t avrcp_cid); 121 122 /** 123 * @brief Subunit info. 124 * @param avrcp_cid 125 * @returns status 126 */ 127 uint8_t avrcp_controller_subunit_info(uint16_t avrcp_cid); 128 129 /** 130 * @brief Get capabilities. 131 * @param avrcp_cid 132 * @returns status 133 */ 134 uint8_t avrcp_controller_get_supported_company_ids(uint16_t avrcp_cid); 135 136 /** 137 * @brief Get supported Events. 138 * @param avrcp_cid 139 * @returns status 140 */ 141 uint8_t avrcp_controller_get_supported_events(uint16_t avrcp_cid); 142 143 144 145 /** 146 * @brief Stops continuous cmd (play, pause, volume up, ...). Event AVRCP_SUBEVENT_OPERATION_COMPLETE returns operation id and status. 147 * @param avrcp_cid 148 * @returns status 149 */ 150 uint8_t avrcp_controller_release_press_and_hold_cmd(uint16_t avrcp_cid); 151 152 /** 153 * @brief Play. Event AVRCP_SUBEVENT_OPERATION_COMPLETE returns operation id and status. 154 * @param avrcp_cid 155 * @returns status 156 */ 157 uint8_t avrcp_controller_play(uint16_t avrcp_cid); 158 uint8_t avrcp_controller_press_and_hold_play(uint16_t avrcp_cid); 159 160 /** 161 * @brief Stop. Event AVRCP_SUBEVENT_OPERATION_COMPLETE returns operation id and status. 162 * @param avrcp_cid 163 * @returns status 164 */ 165 uint8_t avrcp_controller_stop(uint16_t avrcp_cid); 166 uint8_t avrcp_controller_press_and_hold_stop(uint16_t avrcp_cid); 167 168 /** 169 * @brief Pause. Event AVRCP_SUBEVENT_OPERATION_COMPLETE returns operation id and status. 170 * @param avrcp_cid 171 * @returns status 172 */ 173 uint8_t avrcp_controller_pause(uint16_t avrcp_cid); 174 uint8_t avrcp_controller_press_and_hold_pause(uint16_t avrcp_cid); 175 176 /** 177 * @brief Single step - fast forward. Event AVRCP_SUBEVENT_OPERATION_COMPLETE returns operation id and status. 178 * @param avrcp_cid 179 * @returns status 180 */ 181 uint8_t avrcp_controller_fast_forward(uint16_t avrcp_cid); 182 uint8_t avrcp_controller_press_and_hold_fast_forward(uint16_t avrcp_cid); 183 184 185 /** 186 * @brief Single step rewind. Event AVRCP_SUBEVENT_OPERATION_COMPLETE returns operation id and status. 187 * @param avrcp_cid 188 * @returns status 189 */ 190 uint8_t avrcp_controller_rewind(uint16_t avrcp_cid); 191 uint8_t avrcp_controller_press_and_hold_rewind(uint16_t avrcp_cid); 192 193 /** 194 * @brief Forward. Event AVRCP_SUBEVENT_OPERATION_COMPLETE returns operation id and status. 195 * @param avrcp_cid 196 * @returns status 197 */ 198 uint8_t avrcp_controller_forward(uint16_t avrcp_cid); 199 uint8_t avrcp_controller_press_and_hold_forward(uint16_t avrcp_cid); 200 201 /** 202 * @brief Backward. Event AVRCP_SUBEVENT_OPERATION_COMPLETE returns operation id and status. 203 * @param avrcp_cid 204 * @returns status 205 */ 206 uint8_t avrcp_controller_backward(uint16_t avrcp_cid); 207 uint8_t avrcp_controller_press_and_hold_backward(uint16_t avrcp_cid); 208 209 /** 210 * @brief Turns the volume to high. Event AVRCP_SUBEVENT_OPERATION_COMPLETE returns operation id and status. 211 * @param avrcp_cid 212 * @returns status 213 */ 214 uint8_t avrcp_controller_volume_up(uint16_t avrcp_cid); 215 uint8_t avrcp_controller_press_and_hold_volume_up(uint16_t avrcp_cid); 216 /** 217 * @brief Turns the volume to low. Event AVRCP_SUBEVENT_OPERATION_COMPLETE returns operation id and status. 218 * @param avrcp_cid 219 * @returns status 220 */ 221 uint8_t avrcp_controller_volume_down(uint16_t avrcp_cid); 222 uint8_t avrcp_controller_press_and_hold_volume_down(uint16_t avrcp_cid); 223 224 /** 225 * @brief Puts the sound out. Event AVRCP_SUBEVENT_OPERATION_COMPLETE returns operation id and status. 226 * @param avrcp_cid 227 * @returns status 228 */ 229 uint8_t avrcp_controller_mute(uint16_t avrcp_cid); 230 uint8_t avrcp_controller_press_and_hold_mute(uint16_t avrcp_cid); 231 232 /** 233 * @brief Get play status. Returns event of type AVRCP_SUBEVENT_PLAY_STATUS (length, position, play_status). 234 * If TG does not support SongLength And SongPosition on TG, then TG shall return 0xFFFFFFFF. 235 * @param avrcp_cid 236 * @returns status 237 */ 238 uint8_t avrcp_controller_get_play_status(uint16_t avrcp_cid); 239 240 /** 241 * @brief Enable notification. Response via AVRCP_SUBEVENT_ENABLE_NOTIFICATION_COMPLETE. 242 * @param avrcp_cid 243 * @param event_id 244 * @returns status 245 */ 246 uint8_t avrcp_controller_enable_notification(uint16_t avrcp_cid, avrcp_notification_event_id_t event_id); 247 248 /** 249 * @brief Disable notification. Response via AVRCP_SUBEVENT_ENABLE_NOTIFICATION_COMPLETE. 250 * @param avrcp_cid 251 * @param event_id 252 * @returns status 253 */ 254 uint8_t avrcp_controller_disable_notification(uint16_t avrcp_cid, avrcp_notification_event_id_t event_id); 255 256 /** 257 * @brief Get info on now playing media. 258 * @param avrcp_cid 259 * @returns status 260 */ 261 uint8_t avrcp_controller_get_now_playing_info(uint16_t avrcp_cid); 262 263 /** 264 * @brief Set absolute volume 0-127 (corresponds to 0-100%). Response via AVRCP_SUBEVENT_SET_ABSOLUTE_VOLUME_RESPONSE 265 * @param avrcp_cid 266 * @returns status 267 */ 268 uint8_t avrcp_controller_set_absolute_volume(uint16_t avrcp_cid, uint8_t volume); 269 270 271 /** 272 * @brief Skip to next playing media. Event AVRCP_SUBEVENT_OPERATION_COMPLETE returns operation id and status. 273 * @param avrcp_cid 274 * @returns status 275 */ 276 uint8_t avrcp_controller_skip(uint16_t avrcp_cid); 277 278 /** 279 * @brief Query repeat and shuffle mode. Response via AVRCP_SUBEVENT_SHUFFLE_AND_REPEAT_MODE. 280 * @param avrcp_cid 281 * @returns status 282 */ 283 uint8_t avrcp_controller_query_shuffle_and_repeat_modes(uint16_t avrcp_cid); 284 285 /** 286 * @brief Set shuffle mode. Event AVRCP_SUBEVENT_OPERATION_COMPLETE returns operation id and status. 287 * @param avrcp_cid 288 * @returns status 289 */ 290 uint8_t avrcp_controller_set_shuffle_mode(uint16_t avrcp_cid, avrcp_shuffle_mode_t mode); 291 292 /** 293 * @brief Set repeat mode. Event AVRCP_SUBEVENT_OPERATION_COMPLETE returns operation id and status. 294 * @param avrcp_cid 295 * @returns status 296 */ 297 uint8_t avrcp_controller_set_repeat_mode(uint16_t avrcp_cid, avrcp_repeat_mode_t mode); 298 299 /** 300 * @brief The PlayItem command starts playing an item indicated by the UID. It is routed to the Addressed Player. 301 * @param avrcp_cid 302 * @param uid 303 * @param uid_counter 304 * @param scope 305 **/ 306 uint8_t avrcp_controller_play_item_for_scope(uint16_t avrcp_cid, uint8_t * uid, uint16_t uid_counter, avrcp_browsing_scope_t scope); 307 308 /** 309 * @brief Adds an item indicated by the UID to the Now Playing queue. 310 * @param avrcp_cid 311 * @param uid 312 * @param uid_counter 313 * @param scope 314 **/ 315 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); 316 317 /** 318 * @brief Set addressed player. 319 * @param avrcp_cid 320 * @param addressed_player_id 321 */ 322 uint8_t avrcp_controller_set_addressed_player(uint16_t avrcp_cid, uint16_t addressed_player_id); 323 324 325 /* API_END */ 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 command_opcode 334 * @param command_buffer 335 * @param command_len 336 */ 337 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); 338 339 // Used by AVRCP controller and AVRCP browsing controller 340 extern avrcp_context_t avrcp_controller_context; 341 342 #if defined __cplusplus 343 } 344 #endif 345 346 #endif // __AVRCP_CONTROLLER_H 347