Blame include/pcm_ioplug.h

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