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