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