|
Packit Service |
db8eaa |
/**
|
|
Packit Service |
db8eaa |
* \file pcm/pcm_copy.c
|
|
Packit Service |
db8eaa |
* \ingroup PCM_Plugins
|
|
Packit Service |
db8eaa |
* \brief PCM Copy Plugin Interface
|
|
Packit Service |
db8eaa |
* \author Abramo Bagnara <abramo@alsa-project.org>
|
|
Packit Service |
db8eaa |
* \date 2000-2001
|
|
Packit Service |
db8eaa |
*/
|
|
Packit Service |
db8eaa |
/*
|
|
Packit Service |
db8eaa |
* PCM - Copy conversion
|
|
Packit Service |
db8eaa |
* Copyright (c) 2000 by Abramo Bagnara <abramo@alsa-project.org>
|
|
Packit Service |
db8eaa |
*
|
|
Packit Service |
db8eaa |
*
|
|
Packit Service |
db8eaa |
* This library is free software; you can redistribute it and/or modify
|
|
Packit Service |
db8eaa |
* it under the terms of the GNU Lesser General Public License as
|
|
Packit Service |
db8eaa |
* published by the Free Software Foundation; either version 2.1 of
|
|
Packit Service |
db8eaa |
* the License, or (at your option) any later version.
|
|
Packit Service |
db8eaa |
*
|
|
Packit Service |
db8eaa |
* This program is distributed in the hope that it will be useful,
|
|
Packit Service |
db8eaa |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
db8eaa |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
Packit Service |
db8eaa |
* GNU Lesser General Public License for more details.
|
|
Packit Service |
db8eaa |
*
|
|
Packit Service |
db8eaa |
* You should have received a copy of the GNU Lesser General Public
|
|
Packit Service |
db8eaa |
* License along with this library; if not, write to the Free Software
|
|
Packit Service |
db8eaa |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
Packit Service |
db8eaa |
*
|
|
Packit Service |
db8eaa |
*/
|
|
Packit Service |
db8eaa |
|
|
Packit Service |
db8eaa |
#include "bswap.h"
|
|
Packit Service |
db8eaa |
#include "pcm_local.h"
|
|
Packit Service |
db8eaa |
#include "pcm_plugin.h"
|
|
Packit Service |
db8eaa |
|
|
Packit Service |
db8eaa |
#ifndef PIC
|
|
Packit Service |
db8eaa |
/* entry for static linking */
|
|
Packit Service |
db8eaa |
const char *_snd_module_pcm_copy = "";
|
|
Packit Service |
db8eaa |
#endif
|
|
Packit Service |
db8eaa |
|
|
Packit Service |
db8eaa |
#ifndef DOC_HIDDEN
|
|
Packit Service |
db8eaa |
typedef struct {
|
|
Packit Service |
db8eaa |
/* This field need to be the first */
|
|
Packit Service |
db8eaa |
snd_pcm_plugin_t plug;
|
|
Packit Service |
db8eaa |
} snd_pcm_copy_t;
|
|
Packit Service |
db8eaa |
#endif
|
|
Packit Service |
db8eaa |
|
|
Packit Service |
db8eaa |
static int snd_pcm_copy_hw_refine_cprepare(snd_pcm_t *pcm ATTRIBUTE_UNUSED, snd_pcm_hw_params_t *params)
|
|
Packit Service |
db8eaa |
{
|
|
Packit Service |
db8eaa |
int err;
|
|
Packit Service |
db8eaa |
snd_pcm_access_mask_t access_mask = { SND_PCM_ACCBIT_SHM };
|
|
Packit Service |
db8eaa |
err = _snd_pcm_hw_param_set_mask(params, SND_PCM_HW_PARAM_ACCESS,
|
|
Packit Service |
db8eaa |
&access_mask);
|
|
Packit Service |
db8eaa |
if (err < 0)
|
|
Packit Service |
db8eaa |
return err;
|
|
Packit Service |
db8eaa |
params->info &= ~(SND_PCM_INFO_MMAP | SND_PCM_INFO_MMAP_VALID);
|
|
Packit Service |
db8eaa |
return 0;
|
|
Packit Service |
db8eaa |
}
|
|
Packit Service |
db8eaa |
|
|
Packit Service |
db8eaa |
static int snd_pcm_copy_hw_refine_sprepare(snd_pcm_t *pcm ATTRIBUTE_UNUSED, snd_pcm_hw_params_t *sparams)
|
|
Packit Service |
db8eaa |
{
|
|
Packit Service |
db8eaa |
snd_pcm_access_mask_t saccess_mask = { SND_PCM_ACCBIT_MMAP };
|
|
Packit Service |
db8eaa |
_snd_pcm_hw_params_any(sparams);
|
|
Packit Service |
db8eaa |
_snd_pcm_hw_param_set_mask(sparams, SND_PCM_HW_PARAM_ACCESS,
|
|
Packit Service |
db8eaa |
&saccess_mask);
|
|
Packit Service |
db8eaa |
return 0;
|
|
Packit Service |
db8eaa |
}
|
|
Packit Service |
db8eaa |
|
|
Packit Service |
db8eaa |
static int snd_pcm_copy_hw_refine_schange(snd_pcm_t *pcm ATTRIBUTE_UNUSED, snd_pcm_hw_params_t *params,
|
|
Packit Service |
db8eaa |
snd_pcm_hw_params_t *sparams)
|
|
Packit Service |
db8eaa |
{
|
|
Packit Service |
db8eaa |
int err;
|
|
Packit Service |
db8eaa |
unsigned int links = ~SND_PCM_HW_PARBIT_ACCESS;
|
|
Packit Service |
db8eaa |
err = _snd_pcm_hw_params_refine(sparams, links, params);
|
|
Packit Service |
db8eaa |
if (err < 0)
|
|
Packit Service |
db8eaa |
return err;
|
|
Packit Service |
db8eaa |
return 0;
|
|
Packit Service |
db8eaa |
}
|
|
Packit Service |
db8eaa |
|
|
Packit Service |
db8eaa |
static int snd_pcm_copy_hw_refine_cchange(snd_pcm_t *pcm ATTRIBUTE_UNUSED, snd_pcm_hw_params_t *params,
|
|
Packit Service |
db8eaa |
snd_pcm_hw_params_t *sparams)
|
|
Packit Service |
db8eaa |
{
|
|
Packit Service |
db8eaa |
int err;
|
|
Packit Service |
db8eaa |
unsigned int links = ~SND_PCM_HW_PARBIT_ACCESS;
|
|
Packit Service |
db8eaa |
err = _snd_pcm_hw_params_refine(params, links, sparams);
|
|
Packit Service |
db8eaa |
if (err < 0)
|
|
Packit Service |
db8eaa |
return err;
|
|
Packit Service |
db8eaa |
return 0;
|
|
Packit Service |
db8eaa |
}
|
|
Packit Service |
db8eaa |
|
|
Packit Service |
db8eaa |
static int snd_pcm_copy_hw_refine(snd_pcm_t *pcm, snd_pcm_hw_params_t *params)
|
|
Packit Service |
db8eaa |
{
|
|
Packit Service |
db8eaa |
return snd_pcm_hw_refine_slave(pcm, params,
|
|
Packit Service |
db8eaa |
snd_pcm_copy_hw_refine_cprepare,
|
|
Packit Service |
db8eaa |
snd_pcm_copy_hw_refine_cchange,
|
|
Packit Service |
db8eaa |
snd_pcm_copy_hw_refine_sprepare,
|
|
Packit Service |
db8eaa |
snd_pcm_copy_hw_refine_schange,
|
|
Packit Service |
db8eaa |
snd_pcm_generic_hw_refine);
|
|
Packit Service |
db8eaa |
}
|
|
Packit Service |
db8eaa |
|
|
Packit Service |
db8eaa |
static int snd_pcm_copy_hw_params(snd_pcm_t *pcm, snd_pcm_hw_params_t *params)
|
|
Packit Service |
db8eaa |
{
|
|
Packit Service |
db8eaa |
return snd_pcm_hw_params_slave(pcm, params,
|
|
Packit Service |
db8eaa |
snd_pcm_copy_hw_refine_cchange,
|
|
Packit Service |
db8eaa |
snd_pcm_copy_hw_refine_sprepare,
|
|
Packit Service |
db8eaa |
snd_pcm_copy_hw_refine_schange,
|
|
Packit Service |
db8eaa |
snd_pcm_generic_hw_params);
|
|
Packit Service |
db8eaa |
}
|
|
Packit Service |
db8eaa |
|
|
Packit Service |
db8eaa |
static snd_pcm_uframes_t
|
|
Packit Service |
db8eaa |
snd_pcm_copy_write_areas(snd_pcm_t *pcm,
|
|
Packit Service |
db8eaa |
const snd_pcm_channel_area_t *areas,
|
|
Packit Service |
db8eaa |
snd_pcm_uframes_t offset,
|
|
Packit Service |
db8eaa |
snd_pcm_uframes_t size,
|
|
Packit Service |
db8eaa |
const snd_pcm_channel_area_t *slave_areas,
|
|
Packit Service |
db8eaa |
snd_pcm_uframes_t slave_offset,
|
|
Packit Service |
db8eaa |
snd_pcm_uframes_t *slave_sizep)
|
|
Packit Service |
db8eaa |
{
|
|
Packit Service |
db8eaa |
if (size > *slave_sizep)
|
|
Packit Service |
db8eaa |
size = *slave_sizep;
|
|
Packit Service |
db8eaa |
snd_pcm_areas_copy(slave_areas, slave_offset,
|
|
Packit Service |
db8eaa |
areas, offset,
|
|
Packit Service |
db8eaa |
pcm->channels, size, pcm->format);
|
|
Packit Service |
db8eaa |
*slave_sizep = size;
|
|
Packit Service |
db8eaa |
return size;
|
|
Packit Service |
db8eaa |
}
|
|
Packit Service |
db8eaa |
|
|
Packit Service |
db8eaa |
static snd_pcm_uframes_t
|
|
Packit Service |
db8eaa |
snd_pcm_copy_read_areas(snd_pcm_t *pcm,
|
|
Packit Service |
db8eaa |
const snd_pcm_channel_area_t *areas,
|
|
Packit Service |
db8eaa |
snd_pcm_uframes_t offset,
|
|
Packit Service |
db8eaa |
snd_pcm_uframes_t size,
|
|
Packit Service |
db8eaa |
const snd_pcm_channel_area_t *slave_areas,
|
|
Packit Service |
db8eaa |
snd_pcm_uframes_t slave_offset,
|
|
Packit Service |
db8eaa |
snd_pcm_uframes_t *slave_sizep)
|
|
Packit Service |
db8eaa |
{
|
|
Packit Service |
db8eaa |
if (size > *slave_sizep)
|
|
Packit Service |
db8eaa |
size = *slave_sizep;
|
|
Packit Service |
db8eaa |
snd_pcm_areas_copy(areas, offset,
|
|
Packit Service |
db8eaa |
slave_areas, slave_offset,
|
|
Packit Service |
db8eaa |
pcm->channels, size, pcm->format);
|
|
Packit Service |
db8eaa |
*slave_sizep = size;
|
|
Packit Service |
db8eaa |
return size;
|
|
Packit Service |
db8eaa |
}
|
|
Packit Service |
db8eaa |
|
|
Packit Service |
db8eaa |
static void snd_pcm_copy_dump(snd_pcm_t *pcm, snd_output_t *out)
|
|
Packit Service |
db8eaa |
{
|
|
Packit Service |
db8eaa |
snd_pcm_copy_t *copy = pcm->private_data;
|
|
Packit Service |
db8eaa |
snd_output_printf(out, "Copy conversion PCM\n");
|
|
Packit Service |
db8eaa |
if (pcm->setup) {
|
|
Packit Service |
db8eaa |
snd_output_printf(out, "Its setup is:\n");
|
|
Packit Service |
db8eaa |
snd_pcm_dump_setup(pcm, out);
|
|
Packit Service |
db8eaa |
}
|
|
Packit Service |
db8eaa |
snd_output_printf(out, "Slave: ");
|
|
Packit Service |
db8eaa |
snd_pcm_dump(copy->plug.gen.slave, out);
|
|
Packit Service |
db8eaa |
}
|
|
Packit Service |
db8eaa |
|
|
Packit Service |
db8eaa |
static const snd_pcm_ops_t snd_pcm_copy_ops = {
|
|
Packit Service |
db8eaa |
.close = snd_pcm_generic_close,
|
|
Packit Service |
db8eaa |
.info = snd_pcm_generic_info,
|
|
Packit Service |
db8eaa |
.hw_refine = snd_pcm_copy_hw_refine,
|
|
Packit Service |
db8eaa |
.hw_params = snd_pcm_copy_hw_params,
|
|
Packit Service |
db8eaa |
.hw_free = snd_pcm_generic_hw_free,
|
|
Packit Service |
db8eaa |
.sw_params = snd_pcm_generic_sw_params,
|
|
Packit Service |
db8eaa |
.channel_info = snd_pcm_generic_channel_info,
|
|
Packit Service |
db8eaa |
.dump = snd_pcm_copy_dump,
|
|
Packit Service |
db8eaa |
.nonblock = snd_pcm_generic_nonblock,
|
|
Packit Service |
db8eaa |
.async = snd_pcm_generic_async,
|
|
Packit Service |
db8eaa |
.mmap = snd_pcm_generic_mmap,
|
|
Packit Service |
db8eaa |
.munmap = snd_pcm_generic_munmap,
|
|
Packit Service |
db8eaa |
.query_chmaps = snd_pcm_generic_query_chmaps,
|
|
Packit Service |
db8eaa |
.get_chmap = snd_pcm_generic_get_chmap,
|
|
Packit Service |
db8eaa |
.set_chmap = snd_pcm_generic_set_chmap,
|
|
Packit Service |
db8eaa |
};
|
|
Packit Service |
db8eaa |
|
|
Packit Service |
db8eaa |
/**
|
|
Packit Service |
db8eaa |
* \brief Creates a new copy PCM
|
|
Packit Service |
db8eaa |
* \param pcmp Returns created PCM handle
|
|
Packit Service |
db8eaa |
* \param name Name of PCM
|
|
Packit Service |
db8eaa |
* \param slave Slave PCM handle
|
|
Packit Service |
db8eaa |
* \param close_slave When set, the slave PCM handle is closed with copy PCM
|
|
Packit Service |
db8eaa |
* \retval zero on success otherwise a negative error code
|
|
Packit Service |
db8eaa |
* \warning Using of this function might be dangerous in the sense
|
|
Packit Service |
db8eaa |
* of compatibility reasons. The prototype might be freely
|
|
Packit Service |
db8eaa |
* changed in future.
|
|
Packit Service |
db8eaa |
*/
|
|
Packit Service |
db8eaa |
int snd_pcm_copy_open(snd_pcm_t **pcmp, const char *name, snd_pcm_t *slave, int close_slave)
|
|
Packit Service |
db8eaa |
{
|
|
Packit Service |
db8eaa |
snd_pcm_t *pcm;
|
|
Packit Service |
db8eaa |
snd_pcm_copy_t *copy;
|
|
Packit Service |
db8eaa |
int err;
|
|
Packit Service |
db8eaa |
assert(pcmp && slave);
|
|
Packit Service |
db8eaa |
copy = calloc(1, sizeof(snd_pcm_copy_t));
|
|
Packit Service |
db8eaa |
if (!copy) {
|
|
Packit Service |
db8eaa |
return -ENOMEM;
|
|
Packit Service |
db8eaa |
}
|
|
Packit Service |
db8eaa |
snd_pcm_plugin_init(©->plug);
|
|
Packit Service |
db8eaa |
copy->plug.read = snd_pcm_copy_read_areas;
|
|
Packit Service |
db8eaa |
copy->plug.write = snd_pcm_copy_write_areas;
|
|
Packit Service |
db8eaa |
copy->plug.undo_read = snd_pcm_plugin_undo_read_generic;
|
|
Packit Service |
db8eaa |
copy->plug.undo_write = snd_pcm_plugin_undo_write_generic;
|
|
Packit Service |
db8eaa |
copy->plug.gen.slave = slave;
|
|
Packit Service |
db8eaa |
copy->plug.gen.close_slave = close_slave;
|
|
Packit Service |
db8eaa |
|
|
Packit Service |
db8eaa |
err = snd_pcm_new(&pcm, SND_PCM_TYPE_COPY, name, slave->stream, slave->mode);
|
|
Packit Service |
db8eaa |
if (err < 0) {
|
|
Packit Service |
db8eaa |
free(copy);
|
|
Packit Service |
db8eaa |
return err;
|
|
Packit Service |
db8eaa |
}
|
|
Packit Service |
db8eaa |
pcm->ops = &snd_pcm_copy_ops;
|
|
Packit Service |
db8eaa |
pcm->fast_ops = &snd_pcm_plugin_fast_ops;
|
|
Packit Service |
db8eaa |
pcm->private_data = copy;
|
|
Packit Service |
db8eaa |
pcm->poll_fd = slave->poll_fd;
|
|
Packit Service |
db8eaa |
pcm->poll_events = slave->poll_events;
|
|
Packit Service |
db8eaa |
pcm->tstamp_type = slave->tstamp_type;
|
|
Packit Service |
db8eaa |
snd_pcm_set_hw_ptr(pcm, ©->plug.hw_ptr, -1, 0);
|
|
Packit Service |
db8eaa |
snd_pcm_set_appl_ptr(pcm, ©->plug.appl_ptr, -1, 0);
|
|
Packit Service |
db8eaa |
*pcmp = pcm;
|
|
Packit Service |
db8eaa |
|
|
Packit Service |
db8eaa |
return 0;
|
|
Packit Service |
db8eaa |
}
|
|
Packit Service |
db8eaa |
|
|
Packit Service |
db8eaa |
/*! \page pcm_plugins
|
|
Packit Service |
db8eaa |
|
|
Packit Service |
db8eaa |
\section pcm_plugins_copy Plugin: copy
|
|
Packit Service |
db8eaa |
|
|
Packit Service |
db8eaa |
This plugin copies samples from master copy PCM to given slave PCM.
|
|
Packit Service |
db8eaa |
The channel count, format and rate must match for both of them.
|
|
Packit Service |
db8eaa |
|
|
Packit Service |
db8eaa |
\code
|
|
Packit Service |
db8eaa |
pcm.name {
|
|
Packit Service |
db8eaa |
type copy # Copy PCM
|
|
Packit Service |
db8eaa |
slave STR # Slave name
|
|
Packit Service |
db8eaa |
# or
|
|
Packit Service |
db8eaa |
slave { # Slave definition
|
|
Packit Service |
db8eaa |
pcm STR # Slave PCM name
|
|
Packit Service |
db8eaa |
# or
|
|
Packit Service |
db8eaa |
pcm { } # Slave PCM definition
|
|
Packit Service |
db8eaa |
}
|
|
Packit Service |
db8eaa |
}
|
|
Packit Service |
db8eaa |
\endcode
|
|
Packit Service |
db8eaa |
|
|
Packit Service |
db8eaa |
\subsection pcm_plugins_copy_funcref Function reference
|
|
Packit Service |
db8eaa |
|
|
Packit Service |
db8eaa |
|
|
Packit Service |
db8eaa |
snd_pcm_copy_open()
|
|
Packit Service |
db8eaa |
_snd_pcm_copy_open()
|
|
Packit Service |
db8eaa |
|
|
Packit Service |
db8eaa |
|
|
Packit Service |
db8eaa |
*/
|
|
Packit Service |
db8eaa |
|
|
Packit Service |
db8eaa |
/**
|
|
Packit Service |
db8eaa |
* \brief Creates a new copy PCM
|
|
Packit Service |
db8eaa |
* \param pcmp Returns created PCM handle
|
|
Packit Service |
db8eaa |
* \param name Name of PCM
|
|
Packit Service |
db8eaa |
* \param root Root configuration node
|
|
Packit Service |
db8eaa |
* \param conf Configuration node with copy PCM description
|
|
Packit Service |
db8eaa |
* \param stream Stream type
|
|
Packit Service |
db8eaa |
* \param mode Stream mode
|
|
Packit Service |
db8eaa |
* \retval zero on success otherwise a negative error code
|
|
Packit Service |
db8eaa |
* \warning Using of this function might be dangerous in the sense
|
|
Packit Service |
db8eaa |
* of compatibility reasons. The prototype might be freely
|
|
Packit Service |
db8eaa |
* changed in future.
|
|
Packit Service |
db8eaa |
*/
|
|
Packit Service |
db8eaa |
int _snd_pcm_copy_open(snd_pcm_t **pcmp, const char *name,
|
|
Packit Service |
db8eaa |
snd_config_t *root, snd_config_t *conf,
|
|
Packit Service |
db8eaa |
snd_pcm_stream_t stream, int mode)
|
|
Packit Service |
db8eaa |
{
|
|
Packit Service |
db8eaa |
snd_config_iterator_t i, next;
|
|
Packit Service |
db8eaa |
int err;
|
|
Packit Service |
db8eaa |
snd_pcm_t *spcm;
|
|
Packit Service |
db8eaa |
snd_config_t *slave = NULL, *sconf;
|
|
Packit Service |
db8eaa |
snd_config_for_each(i, next, conf) {
|
|
Packit Service |
db8eaa |
snd_config_t *n = snd_config_iterator_entry(i);
|
|
Packit Service |
db8eaa |
const char *id;
|
|
Packit Service |
db8eaa |
if (snd_config_get_id(n, &id) < 0)
|
|
Packit Service |
db8eaa |
continue;
|
|
Packit Service |
db8eaa |
if (snd_pcm_conf_generic_id(id))
|
|
Packit Service |
db8eaa |
continue;
|
|
Packit Service |
db8eaa |
if (strcmp(id, "slave") == 0) {
|
|
Packit Service |
db8eaa |
slave = n;
|
|
Packit Service |
db8eaa |
continue;
|
|
Packit Service |
db8eaa |
}
|
|
Packit Service |
db8eaa |
SNDERR("Unknown field %s", id);
|
|
Packit Service |
db8eaa |
return -EINVAL;
|
|
Packit Service |
db8eaa |
}
|
|
Packit Service |
db8eaa |
if (!slave) {
|
|
Packit Service |
db8eaa |
SNDERR("slave is not defined");
|
|
Packit Service |
db8eaa |
return -EINVAL;
|
|
Packit Service |
db8eaa |
}
|
|
Packit Service |
db8eaa |
err = snd_pcm_slave_conf(root, slave, &sconf, 0);
|
|
Packit Service |
db8eaa |
if (err < 0)
|
|
Packit Service |
db8eaa |
return err;
|
|
Packit Service |
db8eaa |
err = snd_pcm_open_slave(&spcm, root, sconf, stream, mode, conf);
|
|
Packit Service |
db8eaa |
snd_config_delete(sconf);
|
|
Packit Service |
db8eaa |
if (err < 0)
|
|
Packit Service |
db8eaa |
return err;
|
|
Packit Service |
db8eaa |
err = snd_pcm_copy_open(pcmp, name, spcm, 1);
|
|
Packit Service |
db8eaa |
if (err < 0)
|
|
Packit Service |
db8eaa |
snd_pcm_close(spcm);
|
|
Packit Service |
db8eaa |
return err;
|
|
Packit Service |
db8eaa |
}
|
|
Packit Service |
db8eaa |
#ifndef DOC_HIDDEN
|
|
Packit Service |
db8eaa |
SND_DLSYM_BUILD_VERSION(_snd_pcm_copy_open, SND_PCM_DLSYM_VERSION);
|
|
Packit Service |
db8eaa |
#endif
|