xref: /btstack/src/classic/avrcp_cover_art_client.h (revision f3827b09ae588e731e98a760d4d15a7ddebcbab5)
1ac726063SMatthias Ringwald /*
2ac726063SMatthias Ringwald  * Copyright (C) 2023 BlueKitchen GmbH
3ac726063SMatthias Ringwald  *
4ac726063SMatthias Ringwald  * Redistribution and use in source and binary forms, with or without
5ac726063SMatthias Ringwald  * modification, are permitted provided that the following conditions
6ac726063SMatthias Ringwald  * are met:
7ac726063SMatthias Ringwald  *
8ac726063SMatthias Ringwald  * 1. Redistributions of source code must retain the above copyright
9ac726063SMatthias Ringwald  *    notice, this list of conditions and the following disclaimer.
10ac726063SMatthias Ringwald  * 2. Redistributions in binary form must reproduce the above copyright
11ac726063SMatthias Ringwald  *    notice, this list of conditions and the following disclaimer in the
12ac726063SMatthias Ringwald  *    documentation and/or other materials provided with the distribution.
13ac726063SMatthias Ringwald  * 3. Neither the name of the copyright holders nor the names of
14ac726063SMatthias Ringwald  *    contributors may be used to endorse or promote products derived
15ac726063SMatthias Ringwald  *    from this software without specific prior written permission.
16ac726063SMatthias Ringwald  * 4. Any redistribution, use, or modification is done solely for
17ac726063SMatthias Ringwald  *    personal benefit and not for any commercial purpose or for
18ac726063SMatthias Ringwald  *    monetary gain.
19ac726063SMatthias Ringwald  *
20ac726063SMatthias Ringwald  * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS
21ac726063SMatthias Ringwald  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22ac726063SMatthias Ringwald  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23ac726063SMatthias Ringwald  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BLUEKITCHEN
24ac726063SMatthias Ringwald  * GMBH OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25ac726063SMatthias Ringwald  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26ac726063SMatthias Ringwald  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
27ac726063SMatthias Ringwald  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
28ac726063SMatthias Ringwald  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29ac726063SMatthias Ringwald  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
30ac726063SMatthias Ringwald  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31ac726063SMatthias Ringwald  * SUCH DAMAGE.
32ac726063SMatthias Ringwald  *
33ac726063SMatthias Ringwald  * Please inquire about commercial licensing options at
34ac726063SMatthias Ringwald  * [email protected]
35ac726063SMatthias Ringwald  *
36ac726063SMatthias Ringwald  */
37ac726063SMatthias Ringwald 
38ac726063SMatthias Ringwald /**
39ac726063SMatthias Ringwald  * @title AVRCP Cover Art Client
40ac726063SMatthias Ringwald  *
41ac726063SMatthias Ringwald  */
42ac726063SMatthias Ringwald 
43ac726063SMatthias Ringwald #ifndef AVRCP_COVER_ART_CLIENT_H
44ac726063SMatthias Ringwald #define AVRCP_COVER_ART_CLIENT_H
45ac726063SMatthias Ringwald 
46ac726063SMatthias Ringwald #include <stdint.h>
47ac726063SMatthias Ringwald 
48ac726063SMatthias Ringwald #include "bluetooth.h"
49ac726063SMatthias Ringwald #include "btstack_config.h"
50ac726063SMatthias Ringwald #include "btstack_defines.h"
51ac726063SMatthias Ringwald #include "classic/goep_client.h"
52ac726063SMatthias Ringwald #include "btstack_linked_list.h"
53ac726063SMatthias Ringwald #include "classic/obex_parser.h"
54ac726063SMatthias Ringwald #include "l2cap.h"
55d3eadd6dSMatthias Ringwald #include "obex.h"
56ac726063SMatthias Ringwald 
57ac726063SMatthias Ringwald #if defined __cplusplus
58ac726063SMatthias Ringwald extern "C" {
59ac726063SMatthias Ringwald #endif
60ac726063SMatthias Ringwald 
61ac726063SMatthias Ringwald #ifdef ENABLE_AVRCP_COVER_ART
62ac726063SMatthias Ringwald typedef enum {
63ac726063SMatthias Ringwald     AVRCP_COVER_ART_INIT = 0,
64ac726063SMatthias Ringwald     AVRCP_COVER_ART_W4_SDP_QUERY_COMPLETE,
65ac726063SMatthias Ringwald     AVRCP_COVER_ART_W2_GOEP_CONNECT,
66ac726063SMatthias Ringwald     AVRCP_COVER_ART_W4_GOEP_CONNECTION,
67ac726063SMatthias Ringwald     AVRCP_COVER_ART_W2_SEND_CONNECT_REQUEST,
68ac726063SMatthias Ringwald     AVRCP_COVER_ART_W4_CONNECT_RESPONSE,
69ac726063SMatthias Ringwald     AVRCP_COVER_ART_W4_USER_AUTHENTICATION,
70ac726063SMatthias Ringwald     AVRCP_COVER_ART_W2_SEND_AUTHENTICATED_CONNECT,
71ac726063SMatthias Ringwald     AVRCP_COVER_ART_CONNECTED,
72ac726063SMatthias Ringwald     // generic get object
73ac726063SMatthias Ringwald     AVRCP_COVER_ART_W2_SEND_GET_OBJECT,
74ac726063SMatthias Ringwald     AVRCP_COVER_ART_W4_OBJECT,
75ac726063SMatthias Ringwald     // disconnect
76ac726063SMatthias Ringwald     AVRCP_COVER_ART_W2_SEND_DISCONNECT_REQUEST,
77ac726063SMatthias Ringwald     AVRCP_COVER_ART_W4_DISCONNECT_RESPONSE,
78ac726063SMatthias Ringwald     // abort operation
79ac726063SMatthias Ringwald     AVRCP_COVER_ART_W4_ABORT_COMPLETE,
80ac726063SMatthias Ringwald } avrcp_cover_art_state_t;
81ac726063SMatthias Ringwald 
821a3b1957SMatthias Ringwald typedef enum {
831a3b1957SMatthias Ringwald     AVRCP_COVER_ART_SRM_DISABLED,
841a3b1957SMatthias Ringwald     AVRCP_COVER_ART_SRM_W4_CONFIRM,
851a3b1957SMatthias Ringwald     AVRCP_COVER_ART_SRM_ENABLED_BUT_WAITING,
861a3b1957SMatthias Ringwald     AVRCP_COVER_ART_SRM_ENABLED
871a3b1957SMatthias Ringwald } avrcp_cover_art_srm_state_t;
881a3b1957SMatthias Ringwald 
89ac726063SMatthias Ringwald typedef struct {
90*f3827b09SMatthias Ringwald     avrcp_cover_art_srm_state_t srm_state;
91*f3827b09SMatthias Ringwald 
92*f3827b09SMatthias Ringwald     uint8_t srm_value;
93*f3827b09SMatthias Ringwald     uint8_t srmp_value;
94*f3827b09SMatthias Ringwald } avrcp_cover_art_obex_srm_t;
95*f3827b09SMatthias Ringwald 
96*f3827b09SMatthias Ringwald typedef  struct {
97ac726063SMatthias Ringwald     btstack_linked_item_t item;
98ac726063SMatthias Ringwald 
99ac726063SMatthias Ringwald     uint16_t cover_art_cid;
100ac726063SMatthias Ringwald     uint16_t avrcp_cid;
101ac726063SMatthias Ringwald     bd_addr_t addr;
102ac726063SMatthias Ringwald 
103ac726063SMatthias Ringwald     btstack_packet_handler_t packet_handler;
104ac726063SMatthias Ringwald 
105ac726063SMatthias Ringwald     uint8_t *ertm_buffer;
106ac726063SMatthias Ringwald     uint32_t ertm_buffer_size;
107ac726063SMatthias Ringwald     const l2cap_ertm_config_t * ertm_config;
108ac726063SMatthias Ringwald 
109ac726063SMatthias Ringwald     uint16_t goep_cid;
110ac726063SMatthias Ringwald     goep_client_t goep_client;
111ac726063SMatthias Ringwald 
112ac726063SMatthias Ringwald     avrcp_cover_art_state_t state;
113ac726063SMatthias Ringwald 
114ac726063SMatthias Ringwald     //
115ac726063SMatthias Ringwald     bool flow_control_enabled;
116ac726063SMatthias Ringwald     bool flow_next_triggered;
117ac726063SMatthias Ringwald     bool flow_wait_for_user;
118ac726063SMatthias Ringwald 
119ac726063SMatthias Ringwald     // obex parser
120ac726063SMatthias Ringwald     bool obex_parser_waiting_for_response;
121ac726063SMatthias Ringwald     obex_parser_t obex_parser;
122ac726063SMatthias Ringwald     uint8_t obex_header_buffer[4];
123ac726063SMatthias Ringwald 
124ac726063SMatthias Ringwald     // obex srm
125ac726063SMatthias Ringwald     avrcp_cover_art_obex_srm_t obex_srm;
126ac726063SMatthias Ringwald 
127ac726063SMatthias Ringwald     // request
128ac726063SMatthias Ringwald     const char * object_type;
129ac726063SMatthias Ringwald     const char * image_handle;
130ac726063SMatthias Ringwald     const char * image_descriptor;
131ac726063SMatthias Ringwald     bool first_request;
132ac726063SMatthias Ringwald 
133ac726063SMatthias Ringwald } avrcp_cover_art_client_t;
134ac726063SMatthias Ringwald 
135ac726063SMatthias Ringwald /* API_START */
136ac726063SMatthias Ringwald 
137ac726063SMatthias Ringwald /**
138ac726063SMatthias Ringwald  * @brief Set up AVRCP Cover Art client
139ac726063SMatthias Ringwald  */
140ac726063SMatthias Ringwald void avrcp_cover_art_client_init(void);
141ac726063SMatthias Ringwald 
142ac726063SMatthias Ringwald /**
143ac726063SMatthias Ringwald  * @brief   Connect to AVRCP Cover Art service on a remote device, emits AVRCP_SUBEVENT_COVER_ART_CONNECTION_ESTABLISHED with status
144ac726063SMatthias Ringwald  * @param   packet_handler
145ac726063SMatthias Ringwald  * @param   remote_addr
146ac726063SMatthias Ringwald  * @param   ertm_buffer
147ac726063SMatthias Ringwald  * @param   ertm_buffer_size
148ac726063SMatthias Ringwald  * @param   ertm_config
149ac726063SMatthias Ringwald  * @param   avrcp_cover_art_cid  outgoing parameter, valid if status == ERROR_CODE_SUCCESS
150ac726063SMatthias Ringwald  * @return status
151ac726063SMatthias Ringwald  */
152ac726063SMatthias Ringwald uint8_t
153ac726063SMatthias Ringwald avrcp_cover_art_client_connect(avrcp_cover_art_client_t *cover_art_client, btstack_packet_handler_t packet_handler,
154ac726063SMatthias Ringwald                                bd_addr_t remote_addr, uint8_t *ertm_buffer, uint32_t ertm_buffer_size,
155ac726063SMatthias Ringwald                                const l2cap_ertm_config_t *ertm_config, uint16_t *avrcp_cover_art_cid);
156ac726063SMatthias Ringwald 
157ac726063SMatthias Ringwald /**
158ac726063SMatthias Ringwald  * @brief Request cover art thumbnail for cover with a given image handle retrieved via
159ac726063SMatthias Ringwald  *        - avrcp_controller_get_now_playing_info or
160ac726063SMatthias Ringwald  *        - avrcp_controller_get_element_attributes(... AVRCP_MEDIA_ATTR_DEFAULT_COVER_ART ...)
161ac726063SMatthias Ringwald  * @param avrcp_cover_art_cid
162ac726063SMatthias Ringwald  * @param image_handle
163ac726063SMatthias Ringwald  * @return status
164ac726063SMatthias Ringwald  */
165ac726063SMatthias Ringwald uint8_t avrcp_cover_art_client_get_linked_thumbnail(uint16_t avrcp_cover_art_cid, const char * image_handle);
166ac726063SMatthias Ringwald 
167ac726063SMatthias Ringwald /**
168ac726063SMatthias Ringwald  * @brief Request cover art image for given image handle retrieved via
169ac726063SMatthias Ringwald  *        - avrcp_controller_get_now_playing_info or
170ac726063SMatthias Ringwald  *        - avrcp_controller_get_element_attributes(... AVRCP_MEDIA_ATTR_DEFAULT_COVER_ART ...)
171ac726063SMatthias Ringwald  *        and given image descriptor
172ac726063SMatthias Ringwald  * @param avrcp_cover_art_cid
173ac726063SMatthias Ringwald  * @param image_handle
174ac726063SMatthias Ringwald  * @param image_descriptor
175ac726063SMatthias Ringwald  * @return status
176ac726063SMatthias Ringwald  */
177ac726063SMatthias Ringwald uint8_t avrcp_cover_art_client_get_image(uint16_t avrcp_cover_art_cid, const char * image_handle, const char * image_descriptor);
178ac726063SMatthias Ringwald 
179ac726063SMatthias Ringwald /**
180ac726063SMatthias Ringwald  * @brief Request image properties for given image handle retrieved via
181ac726063SMatthias Ringwald  *        - avrcp_controller_get_now_playing_info or
182ac726063SMatthias Ringwald  *        - avrcp_controller_get_element_attributes(... AVRCP_MEDIA_ATTR_DEFAULT_COVER_ART ...)
183ac726063SMatthias Ringwald  * @param avrcp_cover_art_cid
184ac726063SMatthias Ringwald  * @param image_handle
185ac726063SMatthias Ringwald  * @return status
186ac726063SMatthias Ringwald  */
187ac726063SMatthias Ringwald uint8_t avrcp_cover_art_client_get_image_properties(uint16_t avrcp_cover_art_cid, const char * image_handle);
188ac726063SMatthias Ringwald 
189ac726063SMatthias Ringwald /**
190ac726063SMatthias Ringwald  * @brief   Disconnect from AVRCP Cover Art service
191ac726063SMatthias Ringwald  * @param   avrcp_cover_art_cid
192ac726063SMatthias Ringwald  * @return status
193ac726063SMatthias Ringwald  */
194ac726063SMatthias Ringwald uint8_t avrcp_cover_art_client_disconnect(uint16_t avrcp_cover_art_cid);
195ac726063SMatthias Ringwald 
196ac726063SMatthias Ringwald /**
197ac726063SMatthias Ringwald  * @brief De-Init AVRCP Cover Art Client
198ac726063SMatthias Ringwald  */
199ac726063SMatthias Ringwald void avrcp_cover_art_client_deinit(void);
200ac726063SMatthias Ringwald 
201ac726063SMatthias Ringwald /* API_END */
202ac726063SMatthias Ringwald 
203ac726063SMatthias Ringwald #endif
204ac726063SMatthias Ringwald 
205ac726063SMatthias Ringwald #if defined __cplusplus
206ac726063SMatthias Ringwald }
207ac726063SMatthias Ringwald #endif
208ac726063SMatthias Ringwald 
209ac726063SMatthias Ringwald #endif // AVRCP_COVER_ART_CLIENT_H
210