Home | History | Annotate | Download | only in alsa
      1 /**
      2  * \file include/pcm_ioplug.h
      3  * \brief External I/O-Plugin SDK
      4  * \author Takashi Iwai <tiwai (at) suse.de>
      5  * \date 2005
      6  *
      7  * External I/O-Plugin SDK
      8  */
      9 
     10 /*
     11  * ALSA external PCM plugin SDK
     12  *
     13  * Copyright (c) 2005 Takashi Iwai <tiwai (at) suse.de>
     14  *
     15  *   This library is free software; you can redistribute it and/or modify
     16  *   it under the terms of the GNU Lesser General Public License as
     17  *   published by the Free Software Foundation; either version 2.1 of
     18  *   the License, or (at your option) any later version.
     19  *
     20  *   This program is distributed in the hope that it will be useful,
     21  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
     22  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     23  *   GNU Lesser General Public License for more details.
     24  *
     25  *   You should have received a copy of the GNU Lesser General Public
     26  *   License along with this library; if not, write to the Free Software
     27  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
     28  *
     29  */
     30 
     31 #ifndef __ALSA_PCM_IOPLUG_H
     32 #define __ALSA_PCM_IOPLUG_H
     33 
     34 /**
     35  * \defgroup PCM_IOPlug External I/O plugin SDK
     36  * \ingroup Plugin_SDK
     37  * See the \ref pcm page for more details.
     38  * \{
     39  */
     40 
     41 /** hw constraints for ioplug */
     42 enum {
     43 	SND_PCM_IOPLUG_HW_ACCESS = 0,	/**< access type */
     44 	SND_PCM_IOPLUG_HW_FORMAT,	/**< format */
     45 	SND_PCM_IOPLUG_HW_CHANNELS,	/**< channels */
     46 	SND_PCM_IOPLUG_HW_RATE,		/**< rate */
     47 	SND_PCM_IOPLUG_HW_PERIOD_BYTES,	/**< period bytes */
     48 	SND_PCM_IOPLUG_HW_BUFFER_BYTES,	/**< buffer bytes */
     49 	SND_PCM_IOPLUG_HW_PERIODS,	/**< number of periods */
     50 	SND_PCM_IOPLUG_HW_PARAMS	/**< max number of hw constraints */
     51 };
     52 
     53 /** I/O plugin handle */
     54 typedef struct snd_pcm_ioplug snd_pcm_ioplug_t;
     55 /** Callback table of ioplug */
     56 typedef struct snd_pcm_ioplug_callback snd_pcm_ioplug_callback_t;
     57 
     58 /**
     59  * bit flags for additional conditions
     60  */
     61 #define SND_PCM_IOPLUG_FLAG_LISTED	(1<<0)		/* list up this PCM */
     62 
     63 /*
     64  * Protocol version
     65  */
     66 #define SND_PCM_IOPLUG_VERSION_MAJOR	1	/**< Protocol major version */
     67 #define SND_PCM_IOPLUG_VERSION_MINOR	0	/**< Protocol minor version */
     68 #define SND_PCM_IOPLUG_VERSION_TINY	1	/**< Protocol tiny version */
     69 /**
     70  * IO-plugin protocol version
     71  */
     72 #define SND_PCM_IOPLUG_VERSION		((SND_PCM_IOPLUG_VERSION_MAJOR<<16) |\
     73 					 (SND_PCM_IOPLUG_VERSION_MINOR<<8) |\
     74 					 (SND_PCM_IOPLUG_VERSION_TINY))
     75 
     76 /** Handle of ioplug */
     77 struct snd_pcm_ioplug {
     78 	/**
     79 	 * protocol version; #SND_PCM_IOPLUG_VERSION must be filled here
     80 	 * before calling #snd_pcm_ioplug_create()
     81 	 */
     82 	unsigned int version;
     83 	/**
     84 	 * name of this plugin; must be filled before calling #snd_pcm_ioplug_create()
     85 	 */
     86 	const char *name;
     87 	unsigned int flags;	/**< SND_PCM_IOPLUG_FLAG_XXX */
     88 	int poll_fd;		/**< poll file descriptor */
     89 	unsigned int poll_events;	/**< poll events */
     90 	unsigned int mmap_rw;		/**< pseudo mmap mode */
     91 	/**
     92 	 * callbacks of this plugin; must be filled before calling #snd_pcm_ioplug_create()
     93 	 */
     94 	const snd_pcm_ioplug_callback_t *callback;
     95 	/**
     96 	 * private data, which can be used freely in the driver callbacks
     97 	 */
     98 	void *private_data;
     99 	/**
    100 	 * PCM handle filled by #snd_pcm_extplug_create()
    101 	 */
    102 	snd_pcm_t *pcm;
    103 
    104 	snd_pcm_stream_t stream;	/**< stream direcion; read-only */
    105 	snd_pcm_state_t state;		/**< current PCM state; read-only */
    106 	volatile snd_pcm_uframes_t appl_ptr;	/**< application pointer; read-only */
    107 	volatile snd_pcm_uframes_t hw_ptr;	/**< hw pointer; read-only */
    108 	int nonblock;			/**< non-block mode; read-only */
    109 
    110 	snd_pcm_access_t access;	/**< access type; filled after hw_params is called */
    111 	snd_pcm_format_t format;	/**< PCM format; filled after hw_params is called */
    112 	unsigned int channels;		/**< number of channels; filled after hw_params is called */
    113 	unsigned int rate;		/**< rate; filled after hw_params is called */
    114 	snd_pcm_uframes_t period_size;	/**< period size; filled after hw_params is called */
    115 	snd_pcm_uframes_t buffer_size;	/**< buffer size; filled after hw_params is called */
    116 };
    117 
    118 /** Callback table of ioplug */
    119 struct snd_pcm_ioplug_callback {
    120 	/**
    121 	 * start the PCM; required
    122 	 */
    123 	int (*start)(snd_pcm_ioplug_t *io);
    124 	/**
    125 	 * stop the PCM; required
    126 	 */
    127 	int (*stop)(snd_pcm_ioplug_t *io);
    128 	/**
    129 	 * get the current DMA position; required
    130 	 */
    131 	snd_pcm_sframes_t (*pointer)(snd_pcm_ioplug_t *io);
    132 	/**
    133 	 * transfer the data; optional
    134 	 */
    135 	snd_pcm_sframes_t (*transfer)(snd_pcm_ioplug_t *io,
    136 				      const snd_pcm_channel_area_t *areas,
    137 				      snd_pcm_uframes_t offset,
    138 				      snd_pcm_uframes_t size);
    139 	/**
    140 	 * close the PCM; optional
    141 	 */
    142 	int (*close)(snd_pcm_ioplug_t *io);
    143 	/**
    144 	 * hw_params; optional
    145 	 */
    146 	int (*hw_params)(snd_pcm_ioplug_t *io, snd_pcm_hw_params_t *params);
    147 	/**
    148 	 * hw_free; optional
    149 	 */
    150 	int (*hw_free)(snd_pcm_ioplug_t *io);
    151 	/**
    152 	 * sw_params; optional
    153 	 */
    154 	int (*sw_params)(snd_pcm_ioplug_t *io, snd_pcm_sw_params_t *params);
    155 	/**
    156 	 * prepare; optional
    157 	 */
    158 	int (*prepare)(snd_pcm_ioplug_t *io);
    159 	/**
    160 	 * drain; optional
    161 	 */
    162 	int (*drain)(snd_pcm_ioplug_t *io);
    163 	/**
    164 	 * toggle pause; optional
    165 	 */
    166 	int (*pause)(snd_pcm_ioplug_t *io, int enable);
    167 	/**
    168 	 * resume; optional
    169 	 */
    170 	int (*resume)(snd_pcm_ioplug_t *io);
    171 	/**
    172 	 * poll descriptors count; optional
    173 	 */
    174 	int (*poll_descriptors_count)(snd_pcm_ioplug_t *io);
    175 	/**
    176 	 * poll descriptors; optional
    177 	 */
    178 	int (*poll_descriptors)(snd_pcm_ioplug_t *io, struct pollfd *pfd, unsigned int space);
    179 	/**
    180 	 * mangle poll events; optional
    181 	 */
    182 	int (*poll_revents)(snd_pcm_ioplug_t *io, struct pollfd *pfd, unsigned int nfds, unsigned short *revents);
    183 	/**
    184 	 * dump; optional
    185 	 */
    186 	void (*dump)(snd_pcm_ioplug_t *io, snd_output_t *out);
    187 	/**
    188 	 * get the delay for the running PCM; optional
    189 	 */
    190 	int (*delay)(snd_pcm_ioplug_t *io, snd_pcm_sframes_t *delayp);
    191 };
    192 
    193 
    194 int snd_pcm_ioplug_create(snd_pcm_ioplug_t *io, const char *name,
    195 			  snd_pcm_stream_t stream, int mode);
    196 int snd_pcm_ioplug_delete(snd_pcm_ioplug_t *io);
    197 
    198 /* update poll_fd and mmap_rw */
    199 int snd_pcm_ioplug_reinit_status(snd_pcm_ioplug_t *ioplug);
    200 
    201 /* get a mmap area (for mmap_rw only) */
    202 const snd_pcm_channel_area_t *snd_pcm_ioplug_mmap_areas(snd_pcm_ioplug_t *ioplug);
    203 
    204 /* clear hw_parameter setting */
    205 void snd_pcm_ioplug_params_reset(snd_pcm_ioplug_t *io);
    206 
    207 /* hw_parameter setting */
    208 int snd_pcm_ioplug_set_param_minmax(snd_pcm_ioplug_t *io, int type, unsigned int min, unsigned int max);
    209 int snd_pcm_ioplug_set_param_list(snd_pcm_ioplug_t *io, int type, unsigned int num_list, const unsigned int *list);
    210 
    211 /** \} */
    212 
    213 #endif /* __ALSA_PCM_IOPLUG_H */
    214