jpayne@69: /** jpayne@69: * \file include/pcm_ioplug.h jpayne@69: * \brief External I/O-Plugin SDK jpayne@69: * \author Takashi Iwai jpayne@69: * \date 2005 jpayne@69: * jpayne@69: * External I/O-Plugin SDK jpayne@69: */ jpayne@69: jpayne@69: /* jpayne@69: * ALSA external PCM plugin SDK jpayne@69: * jpayne@69: * Copyright (c) 2005 Takashi Iwai jpayne@69: * jpayne@69: * This library is free software; you can redistribute it and/or modify jpayne@69: * it under the terms of the GNU Lesser General Public License as jpayne@69: * published by the Free Software Foundation; either version 2.1 of jpayne@69: * the License, or (at your option) any later version. jpayne@69: * jpayne@69: * This program is distributed in the hope that it will be useful, jpayne@69: * but WITHOUT ANY WARRANTY; without even the implied warranty of jpayne@69: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the jpayne@69: * GNU Lesser General Public License for more details. jpayne@69: * jpayne@69: * You should have received a copy of the GNU Lesser General Public jpayne@69: * License along with this library; if not, write to the Free Software jpayne@69: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA jpayne@69: * jpayne@69: */ jpayne@69: jpayne@69: #ifndef __ALSA_PCM_IOPLUG_H jpayne@69: #define __ALSA_PCM_IOPLUG_H jpayne@69: jpayne@69: /** jpayne@69: * \defgroup PCM_IOPlug External I/O plugin SDK jpayne@69: * \ingroup Plugin_SDK jpayne@69: * See the \ref pcm page for more details. jpayne@69: * \{ jpayne@69: */ jpayne@69: jpayne@69: /** hw constraints for ioplug */ jpayne@69: enum { jpayne@69: SND_PCM_IOPLUG_HW_ACCESS = 0, /**< access type */ jpayne@69: SND_PCM_IOPLUG_HW_FORMAT, /**< format */ jpayne@69: SND_PCM_IOPLUG_HW_CHANNELS, /**< channels */ jpayne@69: SND_PCM_IOPLUG_HW_RATE, /**< rate */ jpayne@69: SND_PCM_IOPLUG_HW_PERIOD_BYTES, /**< period bytes */ jpayne@69: SND_PCM_IOPLUG_HW_BUFFER_BYTES, /**< buffer bytes */ jpayne@69: SND_PCM_IOPLUG_HW_PERIODS, /**< number of periods */ jpayne@69: SND_PCM_IOPLUG_HW_PARAMS /**< max number of hw constraints */ jpayne@69: }; jpayne@69: jpayne@69: /** I/O plugin handle */ jpayne@69: typedef struct snd_pcm_ioplug snd_pcm_ioplug_t; jpayne@69: /** Callback table of ioplug */ jpayne@69: typedef struct snd_pcm_ioplug_callback snd_pcm_ioplug_callback_t; jpayne@69: #ifdef DOC_HIDDEN jpayne@69: /* redefine typedefs for stupid doxygen */ jpayne@69: typedef snd_pcm_ioplug snd_pcm_ioplug_t; jpayne@69: typedef snd_pcm_ioplug_callback snd_pcm_ioplug_callback_t; jpayne@69: #endif jpayne@69: jpayne@69: /* jpayne@69: * bit flags for additional conditions jpayne@69: */ jpayne@69: #define SND_PCM_IOPLUG_FLAG_LISTED (1<<0) /**< list up this PCM */ jpayne@69: #define SND_PCM_IOPLUG_FLAG_MONOTONIC (1<<1) /**< monotonic timestamps */ jpayne@69: /** hw pointer wrap around at boundary instead of buffer_size */ jpayne@69: #define SND_PCM_IOPLUG_FLAG_BOUNDARY_WA (1<<2) jpayne@69: jpayne@69: /* jpayne@69: * Protocol version jpayne@69: */ jpayne@69: #define SND_PCM_IOPLUG_VERSION_MAJOR 1 /**< Protocol major version */ jpayne@69: #define SND_PCM_IOPLUG_VERSION_MINOR 0 /**< Protocol minor version */ jpayne@69: #define SND_PCM_IOPLUG_VERSION_TINY 2 /**< Protocol tiny version */ jpayne@69: /** jpayne@69: * IO-plugin protocol version jpayne@69: */ jpayne@69: #define SND_PCM_IOPLUG_VERSION ((SND_PCM_IOPLUG_VERSION_MAJOR<<16) |\ jpayne@69: (SND_PCM_IOPLUG_VERSION_MINOR<<8) |\ jpayne@69: (SND_PCM_IOPLUG_VERSION_TINY)) jpayne@69: jpayne@69: /** Handle of ioplug */ jpayne@69: struct snd_pcm_ioplug { jpayne@69: /** jpayne@69: * protocol version; #SND_PCM_IOPLUG_VERSION must be filled here jpayne@69: * before calling #snd_pcm_ioplug_create() jpayne@69: */ jpayne@69: unsigned int version; jpayne@69: /** jpayne@69: * name of this plugin; must be filled before calling #snd_pcm_ioplug_create() jpayne@69: */ jpayne@69: const char *name; jpayne@69: unsigned int flags; /**< SND_PCM_IOPLUG_FLAG_XXX */ jpayne@69: int poll_fd; /**< poll file descriptor */ jpayne@69: unsigned int poll_events; /**< poll events */ jpayne@69: unsigned int mmap_rw; /**< pseudo mmap mode */ jpayne@69: /** jpayne@69: * callbacks of this plugin; must be filled before calling #snd_pcm_ioplug_create() jpayne@69: */ jpayne@69: const snd_pcm_ioplug_callback_t *callback; jpayne@69: /** jpayne@69: * private data, which can be used freely in the driver callbacks jpayne@69: */ jpayne@69: void *private_data; jpayne@69: /** jpayne@69: * PCM handle filled by #snd_pcm_ioplug_create() jpayne@69: */ jpayne@69: snd_pcm_t *pcm; jpayne@69: jpayne@69: snd_pcm_stream_t stream; /**< stream direcion; read-only */ jpayne@69: snd_pcm_state_t state; /**< current PCM state; read-only */ jpayne@69: volatile snd_pcm_uframes_t appl_ptr; /**< application pointer; read-only */ jpayne@69: volatile snd_pcm_uframes_t hw_ptr; /**< hw pointer; read-only */ jpayne@69: int nonblock; /**< non-block mode; read-only */ jpayne@69: jpayne@69: snd_pcm_access_t access; /**< access type; filled after hw_params is called */ jpayne@69: snd_pcm_format_t format; /**< PCM format; filled after hw_params is called */ jpayne@69: unsigned int channels; /**< number of channels; filled after hw_params is called */ jpayne@69: unsigned int rate; /**< rate; filled after hw_params is called */ jpayne@69: snd_pcm_uframes_t period_size; /**< period size; filled after hw_params is called */ jpayne@69: snd_pcm_uframes_t buffer_size; /**< buffer size; filled after hw_params is called */ jpayne@69: }; jpayne@69: jpayne@69: /** Callback table of ioplug */ jpayne@69: struct snd_pcm_ioplug_callback { jpayne@69: /** jpayne@69: * start the PCM; required, called inside mutex lock jpayne@69: */ jpayne@69: int (*start)(snd_pcm_ioplug_t *io); jpayne@69: /** jpayne@69: * stop the PCM; required, called inside mutex lock jpayne@69: */ jpayne@69: int (*stop)(snd_pcm_ioplug_t *io); jpayne@69: /** jpayne@69: * get the current DMA position; required, called inside mutex lock jpayne@69: * \return buffer position up to buffer_size or jpayne@69: * when #SND_PCM_IOPLUG_FLAG_BOUNDARY_WA flag is set up to boundary or jpayne@69: * a negative error code for Xrun jpayne@69: */ jpayne@69: snd_pcm_sframes_t (*pointer)(snd_pcm_ioplug_t *io); jpayne@69: /** jpayne@69: * transfer the data; optional, called inside mutex lock jpayne@69: */ jpayne@69: snd_pcm_sframes_t (*transfer)(snd_pcm_ioplug_t *io, jpayne@69: const snd_pcm_channel_area_t *areas, jpayne@69: snd_pcm_uframes_t offset, jpayne@69: snd_pcm_uframes_t size); jpayne@69: /** jpayne@69: * close the PCM; optional jpayne@69: */ jpayne@69: int (*close)(snd_pcm_ioplug_t *io); jpayne@69: /** jpayne@69: * hw_params; optional jpayne@69: */ jpayne@69: int (*hw_params)(snd_pcm_ioplug_t *io, snd_pcm_hw_params_t *params); jpayne@69: /** jpayne@69: * hw_free; optional jpayne@69: */ jpayne@69: int (*hw_free)(snd_pcm_ioplug_t *io); jpayne@69: /** jpayne@69: * sw_params; optional jpayne@69: */ jpayne@69: int (*sw_params)(snd_pcm_ioplug_t *io, snd_pcm_sw_params_t *params); jpayne@69: /** jpayne@69: * prepare; optional jpayne@69: */ jpayne@69: int (*prepare)(snd_pcm_ioplug_t *io); jpayne@69: /** jpayne@69: * drain; optional jpayne@69: */ jpayne@69: int (*drain)(snd_pcm_ioplug_t *io); jpayne@69: /** jpayne@69: * toggle pause; optional, called inside mutex lock jpayne@69: */ jpayne@69: int (*pause)(snd_pcm_ioplug_t *io, int enable); jpayne@69: /** jpayne@69: * resume; optional jpayne@69: */ jpayne@69: int (*resume)(snd_pcm_ioplug_t *io); jpayne@69: /** jpayne@69: * poll descriptors count; optional jpayne@69: */ jpayne@69: int (*poll_descriptors_count)(snd_pcm_ioplug_t *io); jpayne@69: /** jpayne@69: * poll descriptors; optional jpayne@69: */ jpayne@69: int (*poll_descriptors)(snd_pcm_ioplug_t *io, struct pollfd *pfd, unsigned int space); jpayne@69: /** jpayne@69: * mangle poll events; optional jpayne@69: */ jpayne@69: int (*poll_revents)(snd_pcm_ioplug_t *io, struct pollfd *pfd, unsigned int nfds, unsigned short *revents); jpayne@69: /** jpayne@69: * dump; optional jpayne@69: */ jpayne@69: void (*dump)(snd_pcm_ioplug_t *io, snd_output_t *out); jpayne@69: /** jpayne@69: * get the delay for the running PCM; optional; since v1.0.1 jpayne@69: */ jpayne@69: int (*delay)(snd_pcm_ioplug_t *io, snd_pcm_sframes_t *delayp); jpayne@69: /** jpayne@69: * query the channel maps; optional; since v1.0.2 jpayne@69: */ jpayne@69: snd_pcm_chmap_query_t **(*query_chmaps)(snd_pcm_ioplug_t *io); jpayne@69: /** jpayne@69: * get the channel map; optional; since v1.0.2 jpayne@69: */ jpayne@69: snd_pcm_chmap_t *(*get_chmap)(snd_pcm_ioplug_t *io); jpayne@69: /** jpayne@69: * set the channel map; optional; since v1.0.2 jpayne@69: */ jpayne@69: int (*set_chmap)(snd_pcm_ioplug_t *io, const snd_pcm_chmap_t *map); jpayne@69: }; jpayne@69: jpayne@69: jpayne@69: int snd_pcm_ioplug_create(snd_pcm_ioplug_t *io, const char *name, jpayne@69: snd_pcm_stream_t stream, int mode); jpayne@69: int snd_pcm_ioplug_delete(snd_pcm_ioplug_t *io); jpayne@69: jpayne@69: /* update poll_fd and mmap_rw */ jpayne@69: int snd_pcm_ioplug_reinit_status(snd_pcm_ioplug_t *ioplug); jpayne@69: jpayne@69: /* get a mmap area (for mmap_rw only) */ jpayne@69: const snd_pcm_channel_area_t *snd_pcm_ioplug_mmap_areas(snd_pcm_ioplug_t *ioplug); jpayne@69: jpayne@69: /* clear hw_parameter setting */ jpayne@69: void snd_pcm_ioplug_params_reset(snd_pcm_ioplug_t *io); jpayne@69: jpayne@69: /* hw_parameter setting */ jpayne@69: int snd_pcm_ioplug_set_param_minmax(snd_pcm_ioplug_t *io, int type, unsigned int min, unsigned int max); jpayne@69: int snd_pcm_ioplug_set_param_list(snd_pcm_ioplug_t *io, int type, unsigned int num_list, const unsigned int *list); jpayne@69: jpayne@69: /* change PCM status */ jpayne@69: int snd_pcm_ioplug_set_state(snd_pcm_ioplug_t *ioplug, snd_pcm_state_t state); jpayne@69: jpayne@69: /* calucalte the available frames */ jpayne@69: snd_pcm_uframes_t snd_pcm_ioplug_avail(const snd_pcm_ioplug_t * const ioplug, jpayne@69: const snd_pcm_uframes_t hw_ptr, jpayne@69: const snd_pcm_uframes_t appl_ptr); jpayne@69: snd_pcm_uframes_t snd_pcm_ioplug_hw_avail(const snd_pcm_ioplug_t * const ioplug, jpayne@69: const snd_pcm_uframes_t hw_ptr, jpayne@69: const snd_pcm_uframes_t appl_ptr); jpayne@69: jpayne@69: /** \} */ jpayne@69: jpayne@69: #endif /* __ALSA_PCM_IOPLUG_H */