1 /* pcm_plugin.h 2 ** Copyright (c) 2019, The Linux Foundation. All rights reserved. 3 ** 4 ** Redistribution and use in source and binary forms, with or without 5 ** modification, are permitted provided that the following conditions are 6 ** met: 7 ** * Redistributions of source code must retain the above copyright 8 ** notice, this list of conditions and the following disclaimer. 9 ** * Redistributions in binary form must reproduce the above 10 ** copyright notice, this list of conditions and the following 11 ** disclaimer in the documentation and/or other materials provided 12 ** with the distribution. 13 ** * Neither the name of The Linux Foundation nor the names of its 14 ** contributors may be used to endorse or promote products derived 15 ** from this software without specific prior written permission. 16 ** 17 ** THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED 18 ** WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 19 ** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT 20 ** ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS 21 ** BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 ** CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 ** SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 24 ** BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 25 ** WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 26 ** OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 27 ** IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 **/ 29 30 #ifndef __PCM_PLUGIN_H__ 31 #define __PCM_PLUGIN_H__ 32 33 #include <poll.h> 34 35 #define PCM_PLUGIN_OPEN_FN(name) \ 36 int name##_open(struct pcm_plugin **plugin, \ 37 unsigned int card, \ 38 unsigned int device, \ 39 int mode) 40 41 #define PCM_PLUGIN_OPEN_FN_PTR() \ 42 int (*plugin_open_fn) (struct pcm_plugin **plugin, \ 43 unsigned int card, \ 44 unsigned int device, \ 45 int mode); 46 47 struct pcm_plugin; 48 49 struct pcm_plugin_ops { 50 int (*close) (struct pcm_plugin *plugin); 51 int (*hw_params) (struct pcm_plugin *plugin, 52 struct snd_pcm_hw_params *params); 53 int (*sw_params) (struct pcm_plugin *plugin, 54 struct snd_pcm_sw_params *params); 55 int (*sync_ptr) (struct pcm_plugin *plugin, 56 struct snd_pcm_sync_ptr *sync_ptr); 57 int (*writei_frames) (struct pcm_plugin *plugin, 58 struct snd_xferi *x); 59 int (*readi_frames) (struct pcm_plugin *plugin, 60 struct snd_xferi *x); 61 int (*ttstamp) (struct pcm_plugin *plugin, 62 int *tstamp); 63 int (*prepare) (struct pcm_plugin *plugin); 64 int (*start) (struct pcm_plugin *plugin); 65 int (*drop) (struct pcm_plugin *plugin); 66 int (*ioctl) (struct pcm_plugin *plugin, 67 int cmd, void *arg); 68 void* (*mmap) (struct pcm_plugin *plugin, void *addr, size_t length, int prot, 69 int flags, off_t offset); 70 int (*munmap) (struct pcm_plugin *plugin, void *addr, size_t length); 71 int (*poll) (struct pcm_plugin *plugin, struct pollfd *pfd, nfds_t nfds, 72 int timeout); 73 }; 74 75 struct pcm_plugin_min_max { 76 unsigned int min; 77 unsigned int max; 78 }; 79 80 struct pcm_plugin_hw_constraints { 81 uint64_t access; 82 /* As of this implementation ALSA supports 52 formats */ 83 uint64_t format; 84 struct pcm_plugin_min_max bit_width; 85 struct pcm_plugin_min_max channels; 86 struct pcm_plugin_min_max rate; 87 struct pcm_plugin_min_max periods; 88 struct pcm_plugin_min_max period_bytes; 89 }; 90 91 struct pcm_plugin { 92 unsigned int card; 93 94 struct pcm_plugin_ops *ops; 95 struct pcm_plugin_hw_constraints *constraints; 96 97 void *node; 98 int mode; 99 void *priv; 100 101 unsigned int state; 102 }; 103 104 #endif /* end of __PCM_PLUGIN_H__ */ 105