1 /* 2 * Copyright (C) 2023 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 Cover Art Client 40 * 41 */ 42 43 #ifndef AVRCP_COVER_ART_CLIENT_H 44 #define AVRCP_COVER_ART_CLIENT_H 45 46 #include <stdint.h> 47 48 #include "bluetooth.h" 49 #include "btstack_config.h" 50 #include "btstack_defines.h" 51 #include "classic/goep_client.h" 52 #include "btstack_linked_list.h" 53 #include "classic/obex_parser.h" 54 #include "l2cap.h" 55 #include "obex.h" 56 57 #if defined __cplusplus 58 extern "C" { 59 #endif 60 61 #ifdef ENABLE_AVRCP_COVER_ART 62 typedef enum { 63 AVRCP_COVER_ART_INIT = 0, 64 AVRCP_COVER_ART_W4_SDP_QUERY_COMPLETE, 65 AVRCP_COVER_ART_W2_GOEP_CONNECT, 66 AVRCP_COVER_ART_W4_GOEP_CONNECTION, 67 AVRCP_COVER_ART_W2_SEND_CONNECT_REQUEST, 68 AVRCP_COVER_ART_W4_CONNECT_RESPONSE, 69 AVRCP_COVER_ART_W4_USER_AUTHENTICATION, 70 AVRCP_COVER_ART_W2_SEND_AUTHENTICATED_CONNECT, 71 AVRCP_COVER_ART_CONNECTED, 72 // generic get object 73 AVRCP_COVER_ART_W2_SEND_GET_OBJECT, 74 AVRCP_COVER_ART_W4_OBJECT, 75 // disconnect 76 AVRCP_COVER_ART_W2_SEND_DISCONNECT_REQUEST, 77 AVRCP_COVER_ART_W4_DISCONNECT_RESPONSE, 78 // abort operation 79 AVRCP_COVER_ART_W4_ABORT_COMPLETE, 80 } avrcp_cover_art_state_t; 81 82 typedef struct { 83 uint8_t srm_value; 84 uint8_t srmp_value; 85 } avrcp_cover_art_obex_srm_t; 86 87 typedef struct { 88 btstack_linked_item_t item; 89 90 uint16_t cover_art_cid; 91 uint16_t avrcp_cid; 92 bd_addr_t addr; 93 94 btstack_packet_handler_t packet_handler; 95 96 uint8_t *ertm_buffer; 97 uint32_t ertm_buffer_size; 98 const l2cap_ertm_config_t * ertm_config; 99 100 uint16_t goep_cid; 101 goep_client_t goep_client; 102 103 avrcp_cover_art_state_t state; 104 105 // 106 bool flow_control_enabled; 107 bool flow_next_triggered; 108 bool flow_wait_for_user; 109 110 // obex parser 111 bool obex_parser_waiting_for_response; 112 obex_parser_t obex_parser; 113 uint8_t obex_header_buffer[4]; 114 115 // obex srm 116 avrcp_cover_art_obex_srm_t obex_srm; 117 obex_srm_state_t srm_state; 118 119 // request 120 const char * object_type; 121 const char * image_handle; 122 const char * image_descriptor; 123 bool first_request; 124 125 } avrcp_cover_art_client_t; 126 127 /* API_START */ 128 129 /** 130 * @brief Set up AVRCP Cover Art client 131 */ 132 void avrcp_cover_art_client_init(void); 133 134 /** 135 * @brief Connect to AVRCP Cover Art service on a remote device, emits AVRCP_SUBEVENT_COVER_ART_CONNECTION_ESTABLISHED with status 136 * @param packet_handler 137 * @param remote_addr 138 * @param ertm_buffer 139 * @param ertm_buffer_size 140 * @param ertm_config 141 * @param avrcp_cover_art_cid outgoing parameter, valid if status == ERROR_CODE_SUCCESS 142 * @return status 143 */ 144 uint8_t 145 avrcp_cover_art_client_connect(avrcp_cover_art_client_t *cover_art_client, btstack_packet_handler_t packet_handler, 146 bd_addr_t remote_addr, uint8_t *ertm_buffer, uint32_t ertm_buffer_size, 147 const l2cap_ertm_config_t *ertm_config, uint16_t *avrcp_cover_art_cid); 148 149 /** 150 * @brief Request cover art thumbnail for cover with a given image handle retrieved via 151 * - avrcp_controller_get_now_playing_info or 152 * - avrcp_controller_get_element_attributes(... AVRCP_MEDIA_ATTR_DEFAULT_COVER_ART ...) 153 * @param avrcp_cover_art_cid 154 * @param image_handle 155 * @return status 156 */ 157 uint8_t avrcp_cover_art_client_get_linked_thumbnail(uint16_t avrcp_cover_art_cid, const char * image_handle); 158 159 /** 160 * @brief Request cover art image for given image handle retrieved via 161 * - avrcp_controller_get_now_playing_info or 162 * - avrcp_controller_get_element_attributes(... AVRCP_MEDIA_ATTR_DEFAULT_COVER_ART ...) 163 * and given image descriptor 164 * @param avrcp_cover_art_cid 165 * @param image_handle 166 * @param image_descriptor 167 * @return status 168 */ 169 uint8_t avrcp_cover_art_client_get_image(uint16_t avrcp_cover_art_cid, const char * image_handle, const char * image_descriptor); 170 171 /** 172 * @brief Request image properties for given image handle retrieved via 173 * - avrcp_controller_get_now_playing_info or 174 * - avrcp_controller_get_element_attributes(... AVRCP_MEDIA_ATTR_DEFAULT_COVER_ART ...) 175 * @param avrcp_cover_art_cid 176 * @param image_handle 177 * @return status 178 */ 179 uint8_t avrcp_cover_art_client_get_image_properties(uint16_t avrcp_cover_art_cid, const char * image_handle); 180 181 /** 182 * @brief Disconnect from AVRCP Cover Art service 183 * @param avrcp_cover_art_cid 184 * @return status 185 */ 186 uint8_t avrcp_cover_art_client_disconnect(uint16_t avrcp_cover_art_cid); 187 188 /** 189 * @brief De-Init AVRCP Cover Art Client 190 */ 191 void avrcp_cover_art_client_deinit(void); 192 193 /* API_END */ 194 195 #endif 196 197 #if defined __cplusplus 198 } 199 #endif 200 201 #endif // AVRCP_COVER_ART_CLIENT_H 202