A modern Music Player Daemon based on Rockbox open source high quality audio player
libadwaita audio rust zig deno mpris rockbox mpd
at master 282 lines 7.2 kB view raw
1/*************************************************************************** 2 * __________ __ ___. 3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___ 4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / 5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < 6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ 7 * \/ \/ \/ \/ \/ 8 * $Id: $ 9 * 10 * Copyright (C) 2014 by Amaury Pouly 11 * 12 * All files in this archive are subject to the GNU General Public License. 13 * See the file COPYING in the source tree root for full license agreement. 14 * 15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 16 * KIND, either express or implied. 17 * 18 ****************************************************************************/ 19#ifndef USB_AUDIO_H 20#define USB_AUDIO_H 21 22#include "usb_ch9.h" 23#include "usb_class_driver.h" 24 25/* NOTE 26 * 27 * This is USBAudio 1.0. USBAudio 2.0 is notably _not backwards compatible!_ 28 * USBAudio 1.0 over _USB_ 2.0 is perfectly valid! 29 * 30 * Relevant specifications are USB 2.0 and USB Audio Class 1.0. 31 */ 32 33/* 34 * usb_audio_request_endpoints(): 35 * 36 * Calls usb_core_request_endpoint() to request one IN and one OUT 37 * isochronous endpoint. 38 * 39 * Called by allocate_interfaces_and_endpoints(). 40 * 41 * Returns -1 if either request fails, returns 0 if success. 42 * 43 * Also requests buffer allocations. If allocation fails, 44 * returns -1 so that the driver will be disabled by the USB core. 45 */ 46int usb_audio_request_endpoints(struct usb_class_driver *); 47 48/* 49 * usb_audio_set_first_interface(): 50 * 51 * Required function for the class driver. 52 * 53 * Called by allocate_interfaces_and_endpoints() to 54 * tell the class driver what its first interface number is. 55 * Returns the number of the interface available for the next 56 * class driver to use. 57 * 58 * We need 2 interfaces, AudioControl and AudioStreaming. 59 * Return interface+2. 60 */ 61int usb_audio_set_first_interface(int interface); 62 63/* 64 * usb_audio_get_config_descriptor(): 65 * 66 * Required function for the class driver. 67 * 68 * Called by request_handler_device_get_descriptor(), which expects 69 * this function to fill *dest with the configuration descriptor for this 70 * class driver. 71 * 72 * Return the size of this descriptor in bytes. 73 */ 74int usb_audio_get_config_descriptor(unsigned char *dest,int max_packet_size); 75 76/* 77 * usb_audio_init_connection(): 78 * 79 * Called by usb_core_do_set_config() when the 80 * connection is ready to be used. Currently just sets 81 * the audio sample rate to default. 82 */ 83void usb_audio_init_connection(void); 84 85/* 86 * usb_audio_init(): 87 * 88 * Initialize the driver. Called by usb_core_init(). 89 * Currently initializes the sampling frequency values available 90 * to the AudioStreaming interface. 91 */ 92void usb_audio_init(void); 93 94/* 95 * usb_audio_disconnect(): 96 * 97 * Called by usb_core_exit() AND usb_core_do_set_config(). 98 * 99 * Indicates to the Class driver that the connection is no 100 * longer active. Currently just calls usb_audio_stop_playback(). 101 */ 102void usb_audio_disconnect(void); 103 104/* 105 * usb_audio_get_playing(): 106 * 107 * Returns playing/not playing status of usbaudio. 108 */ 109bool usb_audio_get_playing(void); 110 111/* 112 * usb_audio_get_alloc_failed(): 113 * 114 * Return whether the buffer allocation succeeded (0) 115 * or failed (1). 116 */ 117bool usb_audio_get_alloc_failed(void); 118 119/* 120 * usb_audio_transfer_complete(): 121 * 122 * Dummy function. 123 * 124 * The fast_transfer_complete() function needs to be used instead. 125 */ 126void usb_audio_transfer_complete(int ep,int dir, int status, int length); 127 128/* 129 * usb_audio_fast_transfer_complete(): 130 * 131 * Called by usb_core_transfer_complete(). 132 * The normal transfer complete handler system is too slow to deal with 133 * ISO data at the rate required, so this is required. 134 * 135 * Return true if the transfer is handled, false otherwise. 136 */ 137bool usb_audio_fast_transfer_complete(int ep,int dir, int status, int length); 138 139/* 140 * usb_audio_control_request(): 141 * 142 * Called by control_request_handler_drivers(). 143 * Pass control requests down to the appropriate functions. 144 * 145 * Return true if this driver handles the request, false otherwise. 146 */ 147bool usb_audio_control_request(struct usb_ctrlrequest* req, void* reqdata, unsigned char* dest); 148 149/* 150 * usb_audio_set_interface(): 151 * 152 * Called by control_request_handler_drivers(). 153 * Deal with changing the interface between control and streaming. 154 * 155 * Return 0 for success, -1 otherwise. 156 */ 157int usb_audio_set_interface(int intf, int alt); 158 159/* 160 * usb_audio_get_interface(): 161 * 162 * Called by control_request_handler_drivers(). 163 * Get the alternate of the given interface. 164 * 165 * Return the alternate of the given interface, -1 if unknown. 166 */ 167int usb_audio_get_interface(int intf); 168 169/* 170 * usb_audio_get_playback_sampling_frequency(): 171 * 172 * Return the sample rate currently set. 173 */ 174unsigned long usb_audio_get_playback_sampling_frequency(void); 175 176/* 177 * usb_audio_get_main_intf(): 178 * 179 * Return the main usb interface 180 */ 181int usb_audio_get_main_intf(void); 182 183/* 184 * usb_audio_get_alt_intf(): 185 * 186 * Return the alternate usb interface 187 */ 188int usb_audio_get_alt_intf(void); 189 190/* 191 * usb_audio_get_samplesperframe(): 192 * 193 * Return the samples per frame over the last two feedback cycles 194 * This is the samples sent to the mixer. 195 * 196 * This is returned in floating point 16.16 type. To convert to float, 197 * do ((double)result / (1<<16)) 198 */ 199int32_t usb_audio_get_samplesperframe(void); 200 201/* 202 * usb_audio_get_samplesperframe(): 203 * 204 * Return the samples per frame over the last two feedback cycles 205 * This is the samples received from USB. 206 * 207 * This is returned in floating point 16.16 type. To convert to float, 208 * do ((double)result / (1<<16)) 209 */ 210int32_t usb_audio_get_samples_rx_perframe(void); 211 212/* 213 * usb_audio_get_out_ep(): 214 * 215 * Return the out (to device) endpoint 216 */ 217unsigned int usb_audio_get_out_ep(void); 218 219/* 220 * usb_audio_get_in_ep(): 221 * 222 * Return the in (to host) endpoint 223 */ 224unsigned int usb_audio_get_in_ep(void); 225 226/* 227 * usb_audio_get_prebuffering(): 228 * 229 * Return number of buffers filled ahead of playback 230 */ 231int usb_audio_get_prebuffering(void); 232 233/* 234 * usb_audio_get_prebuffering_avg(): 235 * 236 * Return the average number of buffers filled ahead of playback 237 * over the last two feedback cycles 238 * 239 * This is returned in floating point 16.16 type. To convert to float, 240 * do ((double)result / (1<<16)) 241 */ 242int32_t usb_audio_get_prebuffering_avg(void); 243 244/* 245 * usb_audio_get_prebuffering_maxmin(): 246 * 247 * Return the max or min number of buffers filled ahead of playback 248 * over the last feedback cycle 249 */ 250int usb_audio_get_prebuffering_maxmin(bool max); 251 252/* 253 * usb_audio_get_underflow(): 254 * 255 * Return whether playback is in "underflow" state 256 */ 257bool usb_audio_get_underflow(void); 258 259/* 260 * usb_audio_get_overflow(): 261 * 262 * Return whether usb is in "overflow" state 263 */ 264bool usb_audio_get_overflow(void); 265 266/* 267 * usb_audio_get_frames_dropped(): 268 * 269 * Return the number of frames which have been dropped during playback 270 */ 271int usb_audio_get_frames_dropped(void); 272 273/* 274 * usb_audio_get_cur_volume(): 275 * 276 * Return current audio volume in db 277 */ 278int usb_audio_get_cur_volume(void); 279 280bool usb_audio_get_active(void); 281 282#endif