Blame src/pcm/pcm_generic.c

Packit 4a16fb
/**
Packit 4a16fb
 * \file pcm/pcm_generic.c
Packit 4a16fb
 * \ingroup PCM
Packit 4a16fb
 * \brief PCM Interface
Packit 4a16fb
 * \author Jaroslav Kysela <perex@perex.cz>
Packit 4a16fb
 * \date 2004
Packit 4a16fb
 */
Packit 4a16fb
/*
Packit 4a16fb
 *  PCM - Common generic plugin code
Packit 4a16fb
 *  Copyright (c) 2004 by Jaroslav Kysela <perex@perex.cz> 
Packit 4a16fb
 *
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
#include <sys/ioctl.h>
Packit 4a16fb
#include <limits.h>
Packit 4a16fb
#include "pcm_local.h"
Packit 4a16fb
#include "pcm_generic.h"
Packit 4a16fb
Packit 4a16fb
#ifndef DOC_HIDDEN
Packit 4a16fb
Packit 4a16fb
int snd_pcm_generic_close(snd_pcm_t *pcm)
Packit 4a16fb
{
Packit 4a16fb
	snd_pcm_generic_t *generic = pcm->private_data;
Packit 4a16fb
	int err = 0;
Packit 4a16fb
	if (generic->close_slave)
Packit 4a16fb
		err = snd_pcm_close(generic->slave);
Packit 4a16fb
	free(generic);
Packit 4a16fb
	return err;
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
int snd_pcm_generic_nonblock(snd_pcm_t *pcm, int nonblock)
Packit 4a16fb
{
Packit 4a16fb
	snd_pcm_generic_t *generic = pcm->private_data;
Packit 4a16fb
	return snd_pcm_nonblock(generic->slave, nonblock);
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
int snd_pcm_generic_async(snd_pcm_t *pcm, int sig, pid_t pid)
Packit 4a16fb
{
Packit 4a16fb
	snd_pcm_generic_t *generic = pcm->private_data;
Packit 4a16fb
	return snd_pcm_async(generic->slave, sig, pid);
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
int snd_pcm_generic_poll_descriptors_count(snd_pcm_t *pcm)
Packit 4a16fb
{
Packit 4a16fb
	snd_pcm_generic_t *generic = pcm->private_data;
Packit 4a16fb
	return snd_pcm_poll_descriptors_count(generic->slave);
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
int snd_pcm_generic_poll_descriptors(snd_pcm_t *pcm, struct pollfd *pfds, unsigned int space)
Packit 4a16fb
{
Packit 4a16fb
	snd_pcm_generic_t *generic = pcm->private_data;
Packit 4a16fb
	return snd_pcm_poll_descriptors(generic->slave, pfds, space);
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
int snd_pcm_generic_poll_revents(snd_pcm_t *pcm, struct pollfd *pfds, unsigned int nfds, unsigned short *revents)
Packit 4a16fb
{
Packit 4a16fb
	snd_pcm_generic_t *generic = pcm->private_data;
Packit 4a16fb
	return snd_pcm_poll_descriptors_revents(generic->slave, pfds, nfds, revents);
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
int snd_pcm_generic_info(snd_pcm_t *pcm, snd_pcm_info_t * info)
Packit 4a16fb
{
Packit 4a16fb
	snd_pcm_generic_t *generic = pcm->private_data;
Packit 4a16fb
	return snd_pcm_info(generic->slave, info);
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
int snd_pcm_generic_hw_free(snd_pcm_t *pcm)
Packit 4a16fb
{
Packit 4a16fb
	snd_pcm_generic_t *generic = pcm->private_data;
Packit 4a16fb
	return snd_pcm_hw_free(generic->slave);
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
int snd_pcm_generic_sw_params(snd_pcm_t *pcm, snd_pcm_sw_params_t *params)
Packit 4a16fb
{
Packit 4a16fb
	snd_pcm_generic_t *generic = pcm->private_data;
Packit 4a16fb
	return snd_pcm_sw_params(generic->slave, params);
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
int snd_pcm_generic_hw_refine(snd_pcm_t *pcm, snd_pcm_hw_params_t *params)
Packit 4a16fb
{
Packit 4a16fb
	snd_pcm_generic_t *generic = pcm->private_data;
Packit 4a16fb
	return snd_pcm_hw_refine(generic->slave, params);
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
int snd_pcm_generic_hw_params(snd_pcm_t *pcm, snd_pcm_hw_params_t *params)
Packit 4a16fb
{
Packit 4a16fb
	snd_pcm_generic_t *generic = pcm->private_data;
Packit 4a16fb
	return _snd_pcm_hw_params_internal(generic->slave, params);
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
int snd_pcm_generic_prepare(snd_pcm_t *pcm)
Packit 4a16fb
{
Packit 4a16fb
	snd_pcm_generic_t *generic = pcm->private_data;
Packit 4a16fb
	return snd_pcm_prepare(generic->slave);
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
int snd_pcm_generic_channel_info(snd_pcm_t *pcm, snd_pcm_channel_info_t *info)
Packit 4a16fb
{
Packit 4a16fb
	snd_pcm_generic_t *generic = pcm->private_data;
Packit 4a16fb
	if (pcm->mmap_shadow) {
Packit 4a16fb
		/* No own buffer is required - the plugin won't change
Packit 4a16fb
		 * the data on the buffer, or do safely on-the-place
Packit 4a16fb
		 * conversion
Packit 4a16fb
		 */
Packit 4a16fb
		return snd_pcm_channel_info(generic->slave, info);
Packit 4a16fb
	} else {
Packit 4a16fb
		/* Allocate own buffer */
Packit 4a16fb
		return snd_pcm_channel_info_shm(pcm, info, -1);
Packit 4a16fb
	}
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
int snd_pcm_generic_status(snd_pcm_t *pcm, snd_pcm_status_t * status)
Packit 4a16fb
{ 
Packit 4a16fb
	snd_pcm_generic_t *generic = pcm->private_data;
Packit 4a16fb
	return snd_pcm_status(generic->slave, status);
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
snd_pcm_state_t snd_pcm_generic_state(snd_pcm_t *pcm)
Packit 4a16fb
{
Packit 4a16fb
	snd_pcm_generic_t *generic = pcm->private_data;
Packit 4a16fb
	return snd_pcm_state(generic->slave);
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
int snd_pcm_generic_hwsync(snd_pcm_t *pcm)
Packit 4a16fb
{
Packit 4a16fb
	snd_pcm_generic_t *generic = pcm->private_data;
Packit 4a16fb
	return snd_pcm_hwsync(generic->slave);
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
int snd_pcm_generic_reset(snd_pcm_t *pcm)
Packit 4a16fb
{
Packit 4a16fb
	snd_pcm_generic_t *generic = pcm->private_data;
Packit 4a16fb
	return snd_pcm_reset(generic->slave);
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
int snd_pcm_generic_start(snd_pcm_t *pcm)
Packit 4a16fb
{
Packit 4a16fb
	snd_pcm_generic_t *generic = pcm->private_data;
Packit 4a16fb
	return snd_pcm_start(generic->slave);
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
int snd_pcm_generic_drop(snd_pcm_t *pcm)
Packit 4a16fb
{
Packit 4a16fb
	snd_pcm_generic_t *generic = pcm->private_data;
Packit 4a16fb
	return snd_pcm_drop(generic->slave);
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
int snd_pcm_generic_drain(snd_pcm_t *pcm)
Packit 4a16fb
{
Packit 4a16fb
	snd_pcm_generic_t *generic = pcm->private_data;
Packit 4a16fb
	return snd_pcm_drain(generic->slave);
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
int snd_pcm_generic_pause(snd_pcm_t *pcm, int enable)
Packit 4a16fb
{
Packit 4a16fb
	snd_pcm_generic_t *generic = pcm->private_data;
Packit 4a16fb
	return snd_pcm_pause(generic->slave, enable);
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
int snd_pcm_generic_resume(snd_pcm_t *pcm)
Packit 4a16fb
{
Packit 4a16fb
	snd_pcm_generic_t *generic = pcm->private_data;
Packit 4a16fb
	return snd_pcm_resume(generic->slave);
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
int snd_pcm_generic_delay(snd_pcm_t *pcm, snd_pcm_sframes_t *delayp)
Packit 4a16fb
{
Packit 4a16fb
	snd_pcm_generic_t *generic = pcm->private_data;
Packit 4a16fb
	return snd_pcm_delay(generic->slave, delayp);
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
snd_pcm_sframes_t snd_pcm_generic_forwardable(snd_pcm_t *pcm)
Packit 4a16fb
{
Packit 4a16fb
	snd_pcm_generic_t *generic = pcm->private_data;
Packit 4a16fb
	return snd_pcm_forwardable(generic->slave);
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
snd_pcm_sframes_t snd_pcm_generic_forward(snd_pcm_t *pcm, snd_pcm_uframes_t frames)
Packit 4a16fb
{
Packit 4a16fb
	snd_pcm_generic_t *generic = pcm->private_data;
Packit 4a16fb
	return INTERNAL(snd_pcm_forward)(generic->slave, frames);
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
snd_pcm_sframes_t snd_pcm_generic_rewindable(snd_pcm_t *pcm)
Packit 4a16fb
{
Packit 4a16fb
	snd_pcm_generic_t *generic = pcm->private_data;
Packit 4a16fb
	return snd_pcm_rewindable(generic->slave);
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
snd_pcm_sframes_t snd_pcm_generic_rewind(snd_pcm_t *pcm, snd_pcm_uframes_t frames)
Packit 4a16fb
{
Packit 4a16fb
	snd_pcm_generic_t *generic = pcm->private_data;
Packit 4a16fb
	return snd_pcm_rewind(generic->slave, frames);
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
int snd_pcm_generic_link(snd_pcm_t *pcm1, snd_pcm_t *pcm2)
Packit 4a16fb
{
Packit 4a16fb
	snd_pcm_generic_t *generic = pcm1->private_data;
Packit 4a16fb
	if (generic->slave->fast_ops->link)
Packit 4a16fb
		return generic->slave->fast_ops->link(generic->slave->fast_op_arg, pcm2);
Packit 4a16fb
	return -ENOSYS;
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
int snd_pcm_generic_link_slaves(snd_pcm_t *pcm, snd_pcm_t *master)
Packit 4a16fb
{
Packit 4a16fb
	snd_pcm_generic_t *generic = pcm->private_data;
Packit 4a16fb
	if (generic->slave->fast_ops->link_slaves)
Packit 4a16fb
		return generic->slave->fast_ops->link_slaves(generic->slave->fast_op_arg, master);
Packit 4a16fb
	return -ENOSYS;
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
int snd_pcm_generic_unlink(snd_pcm_t *pcm)
Packit 4a16fb
{
Packit 4a16fb
	snd_pcm_generic_t *generic = pcm->private_data;
Packit 4a16fb
	if (generic->slave->fast_ops->unlink)
Packit 4a16fb
		return generic->slave->fast_ops->unlink(generic->slave->fast_op_arg);
Packit 4a16fb
	return -ENOSYS;
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
snd_pcm_sframes_t snd_pcm_generic_writei(snd_pcm_t *pcm, const void *buffer, snd_pcm_uframes_t size)
Packit 4a16fb
{
Packit 4a16fb
	snd_pcm_generic_t *generic = pcm->private_data;
Packit 4a16fb
	return _snd_pcm_writei(generic->slave, buffer, size);
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
snd_pcm_sframes_t snd_pcm_generic_writen(snd_pcm_t *pcm, void **bufs, snd_pcm_uframes_t size)
Packit 4a16fb
{
Packit 4a16fb
	snd_pcm_generic_t *generic = pcm->private_data;
Packit 4a16fb
	return _snd_pcm_writen(generic->slave, bufs, size);
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
snd_pcm_sframes_t snd_pcm_generic_readi(snd_pcm_t *pcm, void *buffer, snd_pcm_uframes_t size)
Packit 4a16fb
{
Packit 4a16fb
	snd_pcm_generic_t *generic = pcm->private_data;
Packit 4a16fb
	return _snd_pcm_readi(generic->slave, buffer, size);
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
snd_pcm_sframes_t snd_pcm_generic_readn(snd_pcm_t *pcm, void **bufs, snd_pcm_uframes_t size)
Packit 4a16fb
{
Packit 4a16fb
	snd_pcm_generic_t *generic = pcm->private_data;
Packit 4a16fb
	return _snd_pcm_readn(generic->slave, bufs, size);
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
snd_pcm_sframes_t snd_pcm_generic_mmap_commit(snd_pcm_t *pcm, 
Packit 4a16fb
					      snd_pcm_uframes_t offset,
Packit 4a16fb
					      snd_pcm_uframes_t size)
Packit 4a16fb
{
Packit 4a16fb
	snd_pcm_generic_t *generic = pcm->private_data;
Packit 4a16fb
	return snd_pcm_mmap_commit(generic->slave, offset, size);
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
snd_pcm_sframes_t snd_pcm_generic_avail_update(snd_pcm_t *pcm)
Packit 4a16fb
{
Packit 4a16fb
	snd_pcm_generic_t *generic = pcm->private_data;
Packit 4a16fb
	return snd_pcm_avail_update(generic->slave);
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
int snd_pcm_generic_htimestamp(snd_pcm_t *pcm, snd_pcm_uframes_t *avail,
Packit 4a16fb
			       snd_htimestamp_t *tstamp)
Packit 4a16fb
{
Packit 4a16fb
	snd_pcm_generic_t *generic = pcm->private_data;
Packit 4a16fb
	return snd_pcm_htimestamp(generic->slave, avail, tstamp);
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
/* stand-alone version - similar like snd_pcm_hw_htimestamp but
Packit 4a16fb
 * taking the tstamp via gettimestamp().
Packit 4a16fb
 */
Packit 4a16fb
int snd_pcm_generic_real_htimestamp(snd_pcm_t *pcm, snd_pcm_uframes_t *avail,
Packit 4a16fb
				    snd_htimestamp_t *tstamp)
Packit 4a16fb
{
Packit 4a16fb
	snd_pcm_sframes_t avail1;
Packit 4a16fb
	int ok = 0;
Packit 4a16fb
Packit 4a16fb
	while (1) {
Packit 4a16fb
		avail1 = __snd_pcm_avail_update(pcm);
Packit 4a16fb
		if (avail1 < 0)
Packit 4a16fb
			return avail1;
Packit 4a16fb
		if (ok && (snd_pcm_uframes_t)avail1 == *avail)
Packit 4a16fb
			break;
Packit 4a16fb
		*avail = avail1;
Packit 4a16fb
		gettimestamp(tstamp, pcm->tstamp_type);
Packit 4a16fb
		ok = 1;
Packit 4a16fb
	}
Packit 4a16fb
	return 0;
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
int snd_pcm_generic_mmap(snd_pcm_t *pcm)
Packit 4a16fb
{
Packit 4a16fb
	if (pcm->mmap_shadow) {
Packit 4a16fb
		/* Copy the slave mmapped buffer data */
Packit 4a16fb
		snd_pcm_generic_t *generic = pcm->private_data;
Packit 4a16fb
		pcm->mmap_channels = generic->slave->mmap_channels;
Packit 4a16fb
		pcm->running_areas = generic->slave->running_areas;
Packit 4a16fb
		pcm->stopped_areas = generic->slave->stopped_areas;
Packit 4a16fb
	}
Packit 4a16fb
	return 0;
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
int snd_pcm_generic_munmap(snd_pcm_t *pcm)
Packit 4a16fb
{
Packit 4a16fb
	if (pcm->mmap_shadow) {
Packit 4a16fb
		/* Clean up */
Packit 4a16fb
		pcm->mmap_channels = NULL;
Packit 4a16fb
		pcm->running_areas = NULL;
Packit 4a16fb
		pcm->stopped_areas = NULL;
Packit 4a16fb
	}
Packit 4a16fb
	return 0;
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
snd_pcm_chmap_query_t **snd_pcm_generic_query_chmaps(snd_pcm_t *pcm)
Packit 4a16fb
{
Packit 4a16fb
	snd_pcm_generic_t *generic = pcm->private_data;
Packit 4a16fb
	return snd_pcm_query_chmaps(generic->slave);
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
snd_pcm_chmap_t *snd_pcm_generic_get_chmap(snd_pcm_t *pcm)
Packit 4a16fb
{
Packit 4a16fb
	snd_pcm_generic_t *generic = pcm->private_data;
Packit 4a16fb
	return snd_pcm_get_chmap(generic->slave);
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
int snd_pcm_generic_set_chmap(snd_pcm_t *pcm, const snd_pcm_chmap_t *map)
Packit 4a16fb
{
Packit 4a16fb
	snd_pcm_generic_t *generic = pcm->private_data;
Packit 4a16fb
	return snd_pcm_set_chmap(generic->slave, map);
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
int snd_pcm_generic_may_wait_for_avail_min(snd_pcm_t *pcm, snd_pcm_uframes_t avail ATTRIBUTE_UNUSED)
Packit 4a16fb
{
Packit 4a16fb
	snd_pcm_generic_t *generic = pcm->private_data;
Packit 4a16fb
	return snd_pcm_may_wait_for_avail_min(generic->slave, snd_pcm_mmap_avail(generic->slave));
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
#endif /* DOC_HIDDEN */