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