2000-05-08 18:53:38 +00:00
|
|
|
/*
|
|
|
|
|
* PCM - Plug
|
|
|
|
|
* Copyright (c) 2000 by Abramo Bagnara <abramo@alsa-project.org>
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* This library is free software; you can redistribute it and/or modify
|
2001-12-30 09:22:54 +00:00
|
|
|
* it under the terms of the GNU Lesser General Public License as
|
|
|
|
|
* published by the Free Software Foundation; either version 2.1 of
|
2000-05-08 18:53:38 +00:00
|
|
|
* the License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2001-12-30 09:22:54 +00:00
|
|
|
* GNU Lesser General Public License for more details.
|
2000-05-08 18:53:38 +00:00
|
|
|
*
|
2001-12-30 09:22:54 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2000-05-08 18:53:38 +00:00
|
|
|
* License along with this library; if not, write to the Free Software
|
2001-12-30 09:22:54 +00:00
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
2000-05-08 18:53:38 +00:00
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "pcm_local.h"
|
2000-09-24 09:57:26 +00:00
|
|
|
#include "pcm_plugin.h"
|
2000-05-08 18:53:38 +00:00
|
|
|
|
2001-10-24 14:14:11 +00:00
|
|
|
#ifndef PIC
|
|
|
|
|
/* entry for static linking */
|
|
|
|
|
const char *_snd_module_pcm_plug = "";
|
|
|
|
|
#endif
|
|
|
|
|
|
2001-07-19 09:11:05 +00:00
|
|
|
enum snd_pcm_plug_route_policy {
|
|
|
|
|
PLUG_ROUTE_POLICY_NONE,
|
2001-08-20 09:02:41 +00:00
|
|
|
PLUG_ROUTE_POLICY_DEFAULT,
|
2001-07-19 09:11:05 +00:00
|
|
|
PLUG_ROUTE_POLICY_COPY,
|
2001-08-20 13:15:30 +00:00
|
|
|
PLUG_ROUTE_POLICY_AVERAGE,
|
2001-07-19 09:11:05 +00:00
|
|
|
PLUG_ROUTE_POLICY_DUP,
|
|
|
|
|
};
|
|
|
|
|
|
2000-09-24 09:57:26 +00:00
|
|
|
typedef struct {
|
|
|
|
|
snd_pcm_t *req_slave;
|
|
|
|
|
int close_slave;
|
|
|
|
|
snd_pcm_t *slave;
|
2001-07-07 15:53:20 +00:00
|
|
|
snd_pcm_format_t sformat;
|
|
|
|
|
int schannels;
|
|
|
|
|
int srate;
|
2001-07-19 09:11:05 +00:00
|
|
|
enum snd_pcm_plug_route_policy route_policy;
|
2001-01-26 09:56:30 +00:00
|
|
|
snd_pcm_route_ttable_entry_t *ttable;
|
2001-10-25 18:21:18 +00:00
|
|
|
int ttable_ok;
|
2000-09-24 09:57:26 +00:00
|
|
|
unsigned int tt_ssize, tt_cused, tt_sused;
|
|
|
|
|
} snd_pcm_plug_t;
|
|
|
|
|
|
2000-09-11 15:49:10 +00:00
|
|
|
static int snd_pcm_plug_close(snd_pcm_t *pcm)
|
2000-05-08 18:53:38 +00:00
|
|
|
{
|
2001-02-11 15:45:35 +00:00
|
|
|
snd_pcm_plug_t *plug = pcm->private_data;
|
2000-09-24 09:57:26 +00:00
|
|
|
int err, result = 0;
|
|
|
|
|
if (plug->ttable)
|
|
|
|
|
free(plug->ttable);
|
2001-01-19 13:10:50 +00:00
|
|
|
assert(plug->slave == plug->req_slave);
|
2000-09-24 09:57:26 +00:00
|
|
|
if (plug->close_slave) {
|
|
|
|
|
err = snd_pcm_close(plug->req_slave);
|
|
|
|
|
if (err < 0)
|
|
|
|
|
result = err;
|
|
|
|
|
}
|
2000-09-11 15:49:10 +00:00
|
|
|
free(plug);
|
2000-09-24 09:57:26 +00:00
|
|
|
return result;
|
2000-05-08 18:53:38 +00:00
|
|
|
}
|
|
|
|
|
|
2000-09-11 15:49:10 +00:00
|
|
|
static int snd_pcm_plug_nonblock(snd_pcm_t *pcm, int nonblock)
|
2000-05-08 18:53:38 +00:00
|
|
|
{
|
2001-02-11 15:45:35 +00:00
|
|
|
snd_pcm_plug_t *plug = pcm->private_data;
|
2000-06-21 15:03:06 +00:00
|
|
|
return snd_pcm_nonblock(plug->slave, nonblock);
|
2000-05-08 18:53:38 +00:00
|
|
|
}
|
|
|
|
|
|
2000-10-11 12:37:27 +00:00
|
|
|
static int snd_pcm_plug_async(snd_pcm_t *pcm, int sig, pid_t pid)
|
|
|
|
|
{
|
2001-02-11 15:45:35 +00:00
|
|
|
snd_pcm_plug_t *plug = pcm->private_data;
|
2000-10-11 12:37:27 +00:00
|
|
|
return snd_pcm_async(plug->slave, sig, pid);
|
|
|
|
|
}
|
|
|
|
|
|
2000-09-11 15:49:10 +00:00
|
|
|
static int snd_pcm_plug_info(snd_pcm_t *pcm, snd_pcm_info_t *info)
|
2000-05-08 18:53:38 +00:00
|
|
|
{
|
2001-02-11 15:45:35 +00:00
|
|
|
snd_pcm_plug_t *plug = pcm->private_data;
|
2000-09-24 09:57:26 +00:00
|
|
|
snd_pcm_t *slave = plug->req_slave;
|
|
|
|
|
int err;
|
2000-05-08 18:53:38 +00:00
|
|
|
|
2000-09-24 09:57:26 +00:00
|
|
|
if ((err = snd_pcm_info(slave, info)) < 0)
|
2000-05-08 18:53:38 +00:00
|
|
|
return err;
|
2000-07-01 10:38:29 +00:00
|
|
|
return 0;
|
|
|
|
|
}
|
2000-06-21 15:03:06 +00:00
|
|
|
|
2001-02-04 17:03:17 +00:00
|
|
|
static snd_pcm_format_t linear_preferred_formats[] = {
|
2000-12-08 15:41:14 +00:00
|
|
|
#ifdef SND_LITTLE_ENDIAN
|
|
|
|
|
SND_PCM_FORMAT_S16_LE,
|
|
|
|
|
SND_PCM_FORMAT_U16_LE,
|
|
|
|
|
SND_PCM_FORMAT_S16_BE,
|
|
|
|
|
SND_PCM_FORMAT_U16_BE,
|
|
|
|
|
#else
|
|
|
|
|
SND_PCM_FORMAT_S16_BE,
|
|
|
|
|
SND_PCM_FORMAT_U16_BE,
|
|
|
|
|
SND_PCM_FORMAT_S16_LE,
|
|
|
|
|
SND_PCM_FORMAT_U16_LE,
|
|
|
|
|
#endif
|
|
|
|
|
#ifdef SND_LITTLE_ENDIAN
|
|
|
|
|
SND_PCM_FORMAT_S32_LE,
|
|
|
|
|
SND_PCM_FORMAT_U32_LE,
|
|
|
|
|
SND_PCM_FORMAT_S32_BE,
|
|
|
|
|
SND_PCM_FORMAT_U32_BE,
|
|
|
|
|
#else
|
|
|
|
|
SND_PCM_FORMAT_S32_BE,
|
|
|
|
|
SND_PCM_FORMAT_U32_BE,
|
|
|
|
|
SND_PCM_FORMAT_S32_LE,
|
|
|
|
|
SND_PCM_FORMAT_U32_LE,
|
|
|
|
|
#endif
|
|
|
|
|
SND_PCM_FORMAT_S8,
|
2001-11-27 14:24:44 +00:00
|
|
|
SND_PCM_FORMAT_U8,
|
|
|
|
|
#ifdef SND_LITTLE_ENDIAN
|
|
|
|
|
SND_PCM_FORMAT_FLOAT_LE,
|
|
|
|
|
SND_PCM_FORMAT_FLOAT64_LE,
|
|
|
|
|
SND_PCM_FORMAT_FLOAT_BE,
|
|
|
|
|
SND_PCM_FORMAT_FLOAT64_BE,
|
|
|
|
|
#else
|
|
|
|
|
SND_PCM_FORMAT_FLOAT_BE,
|
|
|
|
|
SND_PCM_FORMAT_FLOAT64_BE,
|
|
|
|
|
SND_PCM_FORMAT_FLOAT_LE,
|
|
|
|
|
SND_PCM_FORMAT_FLOAT64_LE,
|
|
|
|
|
#endif
|
|
|
|
|
#ifdef SND_LITTLE_ENDIAN
|
|
|
|
|
SND_PCM_FORMAT_S24_LE,
|
|
|
|
|
SND_PCM_FORMAT_U24_LE,
|
|
|
|
|
SND_PCM_FORMAT_S24_BE,
|
|
|
|
|
SND_PCM_FORMAT_U24_BE,
|
|
|
|
|
#else
|
|
|
|
|
SND_PCM_FORMAT_S24_BE,
|
|
|
|
|
SND_PCM_FORMAT_U24_BE,
|
|
|
|
|
SND_PCM_FORMAT_S24_LE,
|
|
|
|
|
SND_PCM_FORMAT_U24_LE,
|
|
|
|
|
#endif
|
2000-12-08 15:41:14 +00:00
|
|
|
};
|
|
|
|
|
|
2001-02-04 17:03:17 +00:00
|
|
|
static snd_pcm_format_t nonlinear_preferred_formats[] = {
|
2000-12-08 15:41:14 +00:00
|
|
|
SND_PCM_FORMAT_MU_LAW,
|
|
|
|
|
SND_PCM_FORMAT_A_LAW,
|
|
|
|
|
SND_PCM_FORMAT_IMA_ADPCM,
|
|
|
|
|
};
|
|
|
|
|
|
2001-11-27 14:24:44 +00:00
|
|
|
static snd_pcm_format_t float_preferred_formats[] = {
|
|
|
|
|
#ifdef SND_LITTLE_ENDIAN
|
|
|
|
|
SND_PCM_FORMAT_FLOAT_LE,
|
|
|
|
|
SND_PCM_FORMAT_FLOAT64_LE,
|
|
|
|
|
SND_PCM_FORMAT_FLOAT_BE,
|
|
|
|
|
SND_PCM_FORMAT_FLOAT64_BE,
|
|
|
|
|
#else
|
|
|
|
|
SND_PCM_FORMAT_FLOAT_BE,
|
|
|
|
|
SND_PCM_FORMAT_FLOAT64_BE,
|
|
|
|
|
SND_PCM_FORMAT_FLOAT_LE,
|
|
|
|
|
SND_PCM_FORMAT_FLOAT64_LE,
|
|
|
|
|
#endif
|
|
|
|
|
};
|
|
|
|
|
|
2001-02-04 17:03:17 +00:00
|
|
|
static snd_pcm_format_t snd_pcm_plug_slave_format(snd_pcm_format_t format, const snd_pcm_format_mask_t *format_mask)
|
2000-12-08 15:41:14 +00:00
|
|
|
{
|
|
|
|
|
int w, u, e, wid, w1, dw;
|
2001-02-04 18:57:05 +00:00
|
|
|
snd_pcm_format_mask_t lin = { SND_PCM_FMTBIT_LINEAR };
|
2001-11-27 14:24:44 +00:00
|
|
|
snd_pcm_format_mask_t fl = { SND_PCM_FMTBIT_FLOAT };
|
2001-02-04 17:03:17 +00:00
|
|
|
if (snd_pcm_format_mask_test(format_mask, format))
|
2000-12-08 15:41:14 +00:00
|
|
|
return format;
|
2001-11-27 14:24:44 +00:00
|
|
|
if (!snd_pcm_format_mask_test(&lin, format) &&
|
|
|
|
|
!snd_pcm_format_mask_test(&fl, format)) {
|
2000-12-08 15:41:14 +00:00
|
|
|
unsigned int i;
|
2001-07-11 14:09:01 +00:00
|
|
|
switch (format) {
|
2000-12-08 15:41:14 +00:00
|
|
|
case SND_PCM_FORMAT_MU_LAW:
|
|
|
|
|
case SND_PCM_FORMAT_A_LAW:
|
|
|
|
|
case SND_PCM_FORMAT_IMA_ADPCM:
|
|
|
|
|
for (i = 0; i < sizeof(linear_preferred_formats) / sizeof(linear_preferred_formats[0]); ++i) {
|
2001-02-04 17:03:17 +00:00
|
|
|
snd_pcm_format_t f = linear_preferred_formats[i];
|
|
|
|
|
if (snd_pcm_format_mask_test(format_mask, f))
|
2000-12-08 15:41:14 +00:00
|
|
|
return f;
|
|
|
|
|
}
|
|
|
|
|
/* Fall through */
|
|
|
|
|
default:
|
2001-02-05 15:44:42 +00:00
|
|
|
return SND_PCM_FORMAT_UNKNOWN;
|
2000-12-08 15:41:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
2001-02-04 18:57:05 +00:00
|
|
|
snd_mask_intersect(&lin, format_mask);
|
2001-11-27 14:24:44 +00:00
|
|
|
snd_mask_intersect(&fl, format_mask);
|
|
|
|
|
if (snd_mask_empty(&lin) && snd_mask_empty(&fl)) {
|
2000-12-08 15:41:14 +00:00
|
|
|
unsigned int i;
|
|
|
|
|
for (i = 0; i < sizeof(nonlinear_preferred_formats) / sizeof(nonlinear_preferred_formats[0]); ++i) {
|
2001-02-04 17:03:17 +00:00
|
|
|
snd_pcm_format_t f = nonlinear_preferred_formats[i];
|
|
|
|
|
if (snd_pcm_format_mask_test(format_mask, f))
|
2000-12-08 15:41:14 +00:00
|
|
|
return f;
|
|
|
|
|
}
|
2001-02-05 15:44:42 +00:00
|
|
|
return SND_PCM_FORMAT_UNKNOWN;
|
2000-12-08 15:41:14 +00:00
|
|
|
}
|
2001-11-27 14:24:44 +00:00
|
|
|
if (snd_pcm_format_float(format)) {
|
|
|
|
|
if (snd_pcm_format_mask_test(&fl, format)) {
|
|
|
|
|
unsigned int i;
|
|
|
|
|
for (i = 0; i < sizeof(float_preferred_formats) / sizeof(float_preferred_formats[0]); ++i) {
|
|
|
|
|
snd_pcm_format_t f = float_preferred_formats[i];
|
|
|
|
|
if (snd_pcm_format_mask_test(format_mask, f))
|
|
|
|
|
return f;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
w = 32;
|
|
|
|
|
u = 0;
|
|
|
|
|
e = snd_pcm_format_big_endian(format);
|
|
|
|
|
} else if (snd_mask_empty(&lin)) {
|
|
|
|
|
unsigned int i;
|
|
|
|
|
for (i = 0; i < sizeof(float_preferred_formats) / sizeof(float_preferred_formats[0]); ++i) {
|
|
|
|
|
snd_pcm_format_t f = float_preferred_formats[i];
|
|
|
|
|
if (snd_pcm_format_mask_test(format_mask, f))
|
|
|
|
|
return f;
|
|
|
|
|
}
|
|
|
|
|
return SND_PCM_FORMAT_UNKNOWN;
|
|
|
|
|
} else {
|
|
|
|
|
w = snd_pcm_format_width(format);
|
|
|
|
|
u = snd_pcm_format_unsigned(format);
|
|
|
|
|
e = snd_pcm_format_big_endian(format);
|
|
|
|
|
}
|
2000-12-08 15:41:14 +00:00
|
|
|
w1 = w;
|
|
|
|
|
dw = 8;
|
|
|
|
|
for (wid = 0; wid < 4; ++wid) {
|
|
|
|
|
int end, e1 = e;
|
|
|
|
|
for (end = 0; end < 2; ++end) {
|
|
|
|
|
int sgn, u1 = u;
|
|
|
|
|
for (sgn = 0; sgn < 2; ++sgn) {
|
2001-02-04 17:03:17 +00:00
|
|
|
snd_pcm_format_t f;
|
2000-12-08 15:41:14 +00:00
|
|
|
f = snd_pcm_build_linear_format(w1, u1, e1);
|
2001-02-05 15:44:42 +00:00
|
|
|
assert(f != SND_PCM_FORMAT_UNKNOWN);
|
2001-02-04 17:03:17 +00:00
|
|
|
if (snd_pcm_format_mask_test(format_mask, f))
|
2000-12-08 15:41:14 +00:00
|
|
|
return f;
|
|
|
|
|
u1 = !u1;
|
|
|
|
|
}
|
|
|
|
|
e1 = !e1;
|
|
|
|
|
}
|
|
|
|
|
if (w1 < 32)
|
|
|
|
|
w1 += dw;
|
|
|
|
|
else {
|
|
|
|
|
w1 = w - 8;
|
|
|
|
|
dw = -8;
|
|
|
|
|
}
|
|
|
|
|
}
|
2001-02-05 15:44:42 +00:00
|
|
|
return SND_PCM_FORMAT_UNKNOWN;
|
2000-12-08 15:41:14 +00:00
|
|
|
}
|
|
|
|
|
|
2000-09-24 09:57:26 +00:00
|
|
|
static void snd_pcm_plug_clear(snd_pcm_t *pcm)
|
2000-05-08 18:53:38 +00:00
|
|
|
{
|
2001-02-11 15:45:35 +00:00
|
|
|
snd_pcm_plug_t *plug = pcm->private_data;
|
2000-09-24 09:57:26 +00:00
|
|
|
snd_pcm_t *slave = plug->req_slave;
|
|
|
|
|
/* Clear old plugins */
|
|
|
|
|
if (plug->slave != slave) {
|
|
|
|
|
snd_pcm_close(plug->slave);
|
|
|
|
|
plug->slave = slave;
|
|
|
|
|
pcm->fast_ops = slave->fast_ops;
|
|
|
|
|
pcm->fast_op_arg = slave->fast_op_arg;
|
2000-05-08 18:53:38 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2000-12-21 20:44:10 +00:00
|
|
|
typedef struct {
|
2001-01-15 15:15:24 +00:00
|
|
|
snd_pcm_access_t access;
|
|
|
|
|
snd_pcm_format_t format;
|
2000-12-21 20:44:10 +00:00
|
|
|
unsigned int channels;
|
|
|
|
|
unsigned int rate;
|
|
|
|
|
} snd_pcm_plug_params_t;
|
|
|
|
|
|
|
|
|
|
static int snd_pcm_plug_change_rate(snd_pcm_t *pcm, snd_pcm_t **new, snd_pcm_plug_params_t *clt, snd_pcm_plug_params_t *slv)
|
2000-05-08 18:53:38 +00:00
|
|
|
{
|
2001-02-11 15:45:35 +00:00
|
|
|
snd_pcm_plug_t *plug = pcm->private_data;
|
2000-09-24 09:57:26 +00:00
|
|
|
int err;
|
2000-11-20 20:10:46 +00:00
|
|
|
assert(snd_pcm_format_linear(slv->format));
|
2000-09-24 09:57:26 +00:00
|
|
|
if (clt->rate == slv->rate)
|
2000-05-08 18:53:38 +00:00
|
|
|
return 0;
|
2000-11-20 20:10:46 +00:00
|
|
|
err = snd_pcm_rate_open(new, NULL, slv->format, slv->rate, plug->slave, plug->slave != plug->req_slave);
|
2000-06-21 15:03:06 +00:00
|
|
|
if (err < 0)
|
|
|
|
|
return err;
|
2000-12-11 11:16:07 +00:00
|
|
|
slv->access = clt->access;
|
2000-09-24 09:57:26 +00:00
|
|
|
slv->rate = clt->rate;
|
2000-11-20 20:10:46 +00:00
|
|
|
if (snd_pcm_format_linear(clt->format))
|
|
|
|
|
slv->format = clt->format;
|
2000-09-24 09:57:26 +00:00
|
|
|
return 1;
|
2000-05-08 18:53:38 +00:00
|
|
|
}
|
|
|
|
|
|
2000-12-21 20:44:10 +00:00
|
|
|
static int snd_pcm_plug_change_channels(snd_pcm_t *pcm, snd_pcm_t **new, snd_pcm_plug_params_t *clt, snd_pcm_plug_params_t *slv)
|
2000-05-08 18:53:38 +00:00
|
|
|
{
|
2001-02-11 15:45:35 +00:00
|
|
|
snd_pcm_plug_t *plug = pcm->private_data;
|
2000-09-24 09:57:26 +00:00
|
|
|
unsigned int tt_ssize, tt_cused, tt_sused;
|
2001-01-26 09:56:30 +00:00
|
|
|
snd_pcm_route_ttable_entry_t *ttable;
|
2000-09-24 09:57:26 +00:00
|
|
|
int err;
|
2000-11-20 20:10:46 +00:00
|
|
|
assert(snd_pcm_format_linear(slv->format));
|
2001-10-25 18:21:18 +00:00
|
|
|
if (clt->channels == slv->channels && !plug->ttable)
|
2000-09-24 09:57:26 +00:00
|
|
|
return 0;
|
|
|
|
|
if (clt->rate != slv->rate &&
|
|
|
|
|
clt->channels > slv->channels)
|
|
|
|
|
return 0;
|
2001-08-21 08:59:07 +00:00
|
|
|
tt_ssize = slv->channels;
|
|
|
|
|
tt_cused = clt->channels;
|
|
|
|
|
tt_sused = slv->channels;
|
|
|
|
|
ttable = alloca(tt_cused * tt_sused * sizeof(*ttable));
|
|
|
|
|
if (plug->ttable) { /* expand or shrink table */
|
|
|
|
|
unsigned int c = 0, s = 0;
|
|
|
|
|
for (c = 0; c < tt_cused; c++) {
|
|
|
|
|
for (s = 0; s < tt_sused; s++) {
|
|
|
|
|
snd_pcm_route_ttable_entry_t v;
|
|
|
|
|
if (c >= plug->tt_cused)
|
|
|
|
|
v = 0;
|
|
|
|
|
else if (s >= plug->tt_sused)
|
|
|
|
|
v = 0;
|
|
|
|
|
else
|
|
|
|
|
v = plug->ttable[c * plug->tt_ssize + s];
|
|
|
|
|
ttable[c * tt_ssize + s] = v;
|
|
|
|
|
}
|
|
|
|
|
}
|
2001-10-25 18:21:18 +00:00
|
|
|
plug->ttable_ok = 1;
|
2000-09-24 09:57:26 +00:00
|
|
|
} else {
|
|
|
|
|
unsigned int k;
|
|
|
|
|
unsigned int c = 0, s = 0;
|
2001-08-21 08:59:07 +00:00
|
|
|
enum snd_pcm_plug_route_policy rpolicy = plug->route_policy;
|
2000-09-24 09:57:26 +00:00
|
|
|
int n;
|
|
|
|
|
for (k = 0; k < tt_cused * tt_sused; ++k)
|
|
|
|
|
ttable[k] = 0;
|
2001-08-20 09:02:41 +00:00
|
|
|
if (rpolicy == PLUG_ROUTE_POLICY_DEFAULT) {
|
|
|
|
|
rpolicy = PLUG_ROUTE_POLICY_COPY;
|
2001-12-08 09:32:50 +00:00
|
|
|
/* it's hack for mono conversion */
|
|
|
|
|
if (clt->channels == 1 || slv->channels == 1)
|
2001-08-20 13:15:30 +00:00
|
|
|
rpolicy = PLUG_ROUTE_POLICY_AVERAGE;
|
2001-08-20 09:02:41 +00:00
|
|
|
}
|
|
|
|
|
switch (rpolicy) {
|
2001-08-20 13:15:30 +00:00
|
|
|
case PLUG_ROUTE_POLICY_AVERAGE:
|
2001-07-19 09:11:05 +00:00
|
|
|
case PLUG_ROUTE_POLICY_DUP:
|
|
|
|
|
if (clt->channels > slv->channels) {
|
|
|
|
|
n = clt->channels;
|
|
|
|
|
} else {
|
|
|
|
|
n = slv->channels;
|
|
|
|
|
}
|
|
|
|
|
while (n-- > 0) {
|
|
|
|
|
snd_pcm_route_ttable_entry_t v = FULL;
|
2001-08-20 13:15:30 +00:00
|
|
|
if (rpolicy == PLUG_ROUTE_POLICY_AVERAGE) {
|
2001-07-19 09:11:05 +00:00
|
|
|
if (pcm->stream == SND_PCM_STREAM_PLAYBACK &&
|
|
|
|
|
clt->channels > slv->channels) {
|
|
|
|
|
int srcs = clt->channels / slv->channels;
|
|
|
|
|
if (s < clt->channels % slv->channels)
|
|
|
|
|
srcs++;
|
|
|
|
|
v /= srcs;
|
|
|
|
|
} else if (pcm->stream == SND_PCM_STREAM_CAPTURE &&
|
|
|
|
|
slv->channels > clt->channels) {
|
|
|
|
|
int srcs = slv->channels / clt->channels;
|
|
|
|
|
if (s < slv->channels % clt->channels)
|
|
|
|
|
srcs++;
|
|
|
|
|
v /= srcs;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
ttable[c * tt_ssize + s] = v;
|
|
|
|
|
if (++c == clt->channels)
|
|
|
|
|
c = 0;
|
|
|
|
|
if (++s == slv->channels)
|
|
|
|
|
s = 0;
|
2000-09-24 09:57:26 +00:00
|
|
|
}
|
2001-07-19 09:11:05 +00:00
|
|
|
break;
|
|
|
|
|
case PLUG_ROUTE_POLICY_COPY:
|
|
|
|
|
if (clt->channels < slv->channels) {
|
|
|
|
|
n = clt->channels;
|
|
|
|
|
} else {
|
|
|
|
|
n = slv->channels;
|
|
|
|
|
}
|
|
|
|
|
for (c = 0; (int)c < n; c++)
|
|
|
|
|
ttable[c * tt_ssize + c] = FULL;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
SNDERR("Invalid route policy");
|
|
|
|
|
break;
|
2000-09-24 09:57:26 +00:00
|
|
|
}
|
|
|
|
|
}
|
2001-03-29 17:50:28 +00:00
|
|
|
err = snd_pcm_route_open(new, NULL, slv->format, (int) slv->channels, ttable, tt_ssize, tt_cused, tt_sused, plug->slave, plug->slave != plug->req_slave);
|
2000-05-08 18:53:38 +00:00
|
|
|
if (err < 0)
|
|
|
|
|
return err;
|
2000-09-24 09:57:26 +00:00
|
|
|
slv->channels = clt->channels;
|
2000-12-11 11:16:07 +00:00
|
|
|
slv->access = clt->access;
|
2000-11-20 20:10:46 +00:00
|
|
|
if (snd_pcm_format_linear(clt->format))
|
|
|
|
|
slv->format = clt->format;
|
2000-09-24 09:57:26 +00:00
|
|
|
return 1;
|
2000-06-01 21:58:25 +00:00
|
|
|
}
|
|
|
|
|
|
2000-12-21 20:44:10 +00:00
|
|
|
static int snd_pcm_plug_change_format(snd_pcm_t *pcm, snd_pcm_t **new, snd_pcm_plug_params_t *clt, snd_pcm_plug_params_t *slv)
|
2000-06-01 21:58:25 +00:00
|
|
|
{
|
2001-02-11 15:45:35 +00:00
|
|
|
snd_pcm_plug_t *plug = pcm->private_data;
|
2001-02-04 17:03:17 +00:00
|
|
|
int err;
|
|
|
|
|
snd_pcm_format_t cfmt;
|
2001-03-29 17:50:28 +00:00
|
|
|
int (*f)(snd_pcm_t **_pcm, const char *name, snd_pcm_format_t sformat, snd_pcm_t *slave, int close_slave);
|
2000-11-20 20:10:46 +00:00
|
|
|
if (snd_pcm_format_linear(slv->format)) {
|
2000-09-24 09:57:26 +00:00
|
|
|
/* Conversion is done in another plugin */
|
2000-11-20 20:10:46 +00:00
|
|
|
if (clt->format == slv->format ||
|
2000-09-24 09:57:26 +00:00
|
|
|
clt->rate != slv->rate ||
|
|
|
|
|
clt->channels != slv->channels)
|
|
|
|
|
return 0;
|
2000-11-20 20:10:46 +00:00
|
|
|
cfmt = clt->format;
|
2001-07-11 14:09:01 +00:00
|
|
|
switch (clt->format) {
|
2000-11-20 20:10:46 +00:00
|
|
|
case SND_PCM_FORMAT_MU_LAW:
|
2000-09-24 09:57:26 +00:00
|
|
|
f = snd_pcm_mulaw_open;
|
|
|
|
|
break;
|
2000-11-20 20:10:46 +00:00
|
|
|
case SND_PCM_FORMAT_A_LAW:
|
2000-09-24 09:57:26 +00:00
|
|
|
f = snd_pcm_alaw_open;
|
|
|
|
|
break;
|
2000-11-20 20:10:46 +00:00
|
|
|
case SND_PCM_FORMAT_IMA_ADPCM:
|
2000-09-24 09:57:26 +00:00
|
|
|
f = snd_pcm_adpcm_open;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
2001-11-27 14:24:44 +00:00
|
|
|
if (snd_pcm_format_float(clt->format)) {
|
|
|
|
|
f = snd_pcm_lfloat_open;
|
|
|
|
|
} else {
|
|
|
|
|
assert(snd_pcm_format_linear(clt->format));
|
|
|
|
|
f = snd_pcm_linear_open;
|
|
|
|
|
}
|
2000-09-24 09:57:26 +00:00
|
|
|
break;
|
|
|
|
|
}
|
2001-11-27 14:24:44 +00:00
|
|
|
} else if (snd_pcm_format_float(slv->format)) {
|
|
|
|
|
/* Conversion is done in another plugin */
|
|
|
|
|
if (clt->format == slv->format &&
|
|
|
|
|
clt->rate == slv->rate &&
|
|
|
|
|
clt->channels == slv->channels)
|
|
|
|
|
return 0;
|
|
|
|
|
cfmt = clt->format;
|
|
|
|
|
if (snd_pcm_format_linear(clt->format))
|
|
|
|
|
f = snd_pcm_lfloat_open;
|
|
|
|
|
else {
|
|
|
|
|
assert(0); /* TODO */
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
}
|
2000-09-24 09:57:26 +00:00
|
|
|
} else {
|
2000-12-11 11:16:07 +00:00
|
|
|
/* No conversion is needed */
|
|
|
|
|
if (clt->format == slv->format &&
|
|
|
|
|
clt->rate == slv->rate &&
|
|
|
|
|
clt->channels == clt->channels)
|
|
|
|
|
return 0;
|
2001-07-11 14:09:01 +00:00
|
|
|
switch (slv->format) {
|
2000-11-20 20:10:46 +00:00
|
|
|
case SND_PCM_FORMAT_MU_LAW:
|
2000-09-24 09:57:26 +00:00
|
|
|
f = snd_pcm_mulaw_open;
|
|
|
|
|
break;
|
2000-11-20 20:10:46 +00:00
|
|
|
case SND_PCM_FORMAT_A_LAW:
|
2000-09-24 09:57:26 +00:00
|
|
|
f = snd_pcm_alaw_open;
|
|
|
|
|
break;
|
2000-11-20 20:10:46 +00:00
|
|
|
case SND_PCM_FORMAT_IMA_ADPCM:
|
2000-09-24 09:57:26 +00:00
|
|
|
f = snd_pcm_adpcm_open;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
assert(0);
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
}
|
2000-11-20 20:10:46 +00:00
|
|
|
if (snd_pcm_format_linear(clt->format))
|
|
|
|
|
cfmt = clt->format;
|
2000-09-24 09:57:26 +00:00
|
|
|
else
|
2000-11-20 20:10:46 +00:00
|
|
|
cfmt = SND_PCM_FORMAT_S16;
|
2000-09-24 09:57:26 +00:00
|
|
|
}
|
2000-11-20 20:10:46 +00:00
|
|
|
err = f(new, NULL, slv->format, plug->slave, plug->slave != plug->req_slave);
|
2000-05-08 18:53:38 +00:00
|
|
|
if (err < 0)
|
|
|
|
|
return err;
|
2000-11-20 20:10:46 +00:00
|
|
|
slv->format = cfmt;
|
2000-12-11 11:16:07 +00:00
|
|
|
slv->access = clt->access;
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
2000-12-21 20:44:10 +00:00
|
|
|
static int snd_pcm_plug_change_access(snd_pcm_t *pcm, snd_pcm_t **new, snd_pcm_plug_params_t *clt, snd_pcm_plug_params_t *slv)
|
2000-12-11 11:16:07 +00:00
|
|
|
{
|
2001-02-11 15:45:35 +00:00
|
|
|
snd_pcm_plug_t *plug = pcm->private_data;
|
2000-12-11 11:16:07 +00:00
|
|
|
int err;
|
|
|
|
|
if (clt->access == slv->access)
|
|
|
|
|
return 0;
|
|
|
|
|
err = snd_pcm_copy_open(new, NULL, plug->slave, plug->slave != plug->req_slave);
|
|
|
|
|
if (err < 0)
|
|
|
|
|
return err;
|
|
|
|
|
slv->access = clt->access;
|
2000-09-24 09:57:26 +00:00
|
|
|
return 1;
|
2000-05-08 18:53:38 +00:00
|
|
|
}
|
|
|
|
|
|
2000-09-24 09:57:26 +00:00
|
|
|
static int snd_pcm_plug_insert_plugins(snd_pcm_t *pcm,
|
2000-12-21 20:44:10 +00:00
|
|
|
snd_pcm_plug_params_t *client,
|
|
|
|
|
snd_pcm_plug_params_t *slave)
|
2000-05-08 18:53:38 +00:00
|
|
|
{
|
2001-02-11 15:45:35 +00:00
|
|
|
snd_pcm_plug_t *plug = pcm->private_data;
|
2001-03-29 17:50:28 +00:00
|
|
|
int (*funcs[])(snd_pcm_t *_pcm, snd_pcm_t **new, snd_pcm_plug_params_t *s, snd_pcm_plug_params_t *d) = {
|
2000-09-24 09:57:26 +00:00
|
|
|
snd_pcm_plug_change_format,
|
|
|
|
|
snd_pcm_plug_change_channels,
|
|
|
|
|
snd_pcm_plug_change_rate,
|
|
|
|
|
snd_pcm_plug_change_channels,
|
2000-12-11 11:16:07 +00:00
|
|
|
snd_pcm_plug_change_format,
|
|
|
|
|
snd_pcm_plug_change_access
|
2000-09-24 09:57:26 +00:00
|
|
|
};
|
2000-12-21 20:44:10 +00:00
|
|
|
snd_pcm_plug_params_t p = *slave;
|
2000-09-24 09:57:26 +00:00
|
|
|
unsigned int k = 0;
|
2001-10-25 18:21:18 +00:00
|
|
|
plug->ttable_ok = 0;
|
2000-12-11 11:16:07 +00:00
|
|
|
while (client->format != p.format ||
|
|
|
|
|
client->channels != p.channels ||
|
|
|
|
|
client->rate != p.rate ||
|
|
|
|
|
client->access != p.access) {
|
2000-09-24 09:57:26 +00:00
|
|
|
snd_pcm_t *new;
|
|
|
|
|
int err;
|
|
|
|
|
assert(k < sizeof(funcs)/sizeof(*funcs));
|
2000-11-20 20:10:46 +00:00
|
|
|
err = funcs[k](pcm, &new, client, &p);
|
2000-09-24 09:57:26 +00:00
|
|
|
if (err < 0) {
|
|
|
|
|
snd_pcm_plug_clear(pcm);
|
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
if (err) {
|
|
|
|
|
plug->slave = new;
|
|
|
|
|
pcm->fast_ops = new->fast_ops;
|
|
|
|
|
pcm->fast_op_arg = new->fast_op_arg;
|
|
|
|
|
}
|
|
|
|
|
k++;
|
|
|
|
|
}
|
2001-10-25 18:21:18 +00:00
|
|
|
/* it's exception, user specified ttable, but no reduction/expand */
|
|
|
|
|
if (plug->ttable && !plug->ttable_ok) {
|
|
|
|
|
snd_pcm_t *new;
|
|
|
|
|
int err;
|
|
|
|
|
err = snd_pcm_plug_change_channels(pcm, &new, client, &p);
|
|
|
|
|
if (err < 0) {
|
|
|
|
|
snd_pcm_plug_clear(pcm);
|
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
assert(err);
|
|
|
|
|
assert(plug->ttable_ok);
|
|
|
|
|
plug->slave = new;
|
|
|
|
|
pcm->fast_ops = new->fast_ops;
|
|
|
|
|
pcm->fast_op_arg = new->fast_op_arg;
|
|
|
|
|
}
|
2000-09-24 09:57:26 +00:00
|
|
|
return 0;
|
2000-05-08 18:53:38 +00:00
|
|
|
}
|
|
|
|
|
|
2001-11-24 10:53:14 +00:00
|
|
|
static int snd_pcm_plug_hw_refine_cprepare(snd_pcm_t *pcm ATTRIBUTE_UNUSED, snd_pcm_hw_params_t *params)
|
2001-01-18 18:20:31 +00:00
|
|
|
{
|
2001-11-27 14:24:44 +00:00
|
|
|
unsigned int rate_min, channels_max;
|
2001-11-24 10:53:14 +00:00
|
|
|
|
|
|
|
|
/* HACK: to avoid overflow in PARTBIT_RATE code */
|
|
|
|
|
rate_min = snd_pcm_hw_param_get_min(params, SND_PCM_HW_PARAM_RATE, NULL);
|
2001-12-11 15:10:27 +00:00
|
|
|
if (rate_min < 4000) {
|
2001-11-27 14:24:44 +00:00
|
|
|
_snd_pcm_hw_param_set_min(params, SND_PCM_HW_PARAM_RATE, 4000, 0);
|
2001-12-11 15:10:27 +00:00
|
|
|
if (snd_pcm_hw_param_empty(params, SND_PCM_HW_PARAM_RATE))
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
}
|
2001-11-27 14:24:44 +00:00
|
|
|
/* HACK: to avoid overflow in PERIOD_SIZE code */
|
|
|
|
|
channels_max = snd_pcm_hw_param_get_max(params, SND_PCM_HW_PARAM_CHANNELS, NULL);
|
2001-12-11 15:10:27 +00:00
|
|
|
if (channels_max > 10000) {
|
2001-11-27 14:24:44 +00:00
|
|
|
_snd_pcm_hw_param_set_max(params, SND_PCM_HW_PARAM_CHANNELS, 10000, 0);
|
2001-12-11 15:10:27 +00:00
|
|
|
if (snd_pcm_hw_param_empty(params, SND_PCM_HW_PARAM_CHANNELS))
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
}
|
2001-01-18 18:20:31 +00:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2001-07-07 15:53:20 +00:00
|
|
|
static int snd_pcm_plug_hw_refine_sprepare(snd_pcm_t *pcm, snd_pcm_hw_params_t *sparams)
|
2001-01-18 18:20:31 +00:00
|
|
|
{
|
2001-07-07 15:53:20 +00:00
|
|
|
snd_pcm_plug_t *plug = pcm->private_data;
|
2001-02-05 15:44:42 +00:00
|
|
|
_snd_pcm_hw_params_any(sparams);
|
2001-07-07 15:53:20 +00:00
|
|
|
if (plug->sformat >= 0) {
|
|
|
|
|
_snd_pcm_hw_params_set_format(sparams, plug->sformat);
|
|
|
|
|
_snd_pcm_hw_params_set_subformat(sparams, SND_PCM_SUBFORMAT_STD);
|
|
|
|
|
}
|
|
|
|
|
if (plug->schannels > 0)
|
|
|
|
|
_snd_pcm_hw_param_set(sparams, SND_PCM_HW_PARAM_CHANNELS,
|
|
|
|
|
plug->schannels, 0);
|
|
|
|
|
if (plug->srate > 0)
|
|
|
|
|
_snd_pcm_hw_param_set_minmax(sparams, SND_PCM_HW_PARAM_RATE,
|
|
|
|
|
plug->srate, 0, plug->srate + 1, -1);
|
|
|
|
|
if (plug->sformat >= 0 || plug->schannels > 0 || plug->srate > 0) {
|
|
|
|
|
int err = snd_pcm_hw_refine(plug->req_slave, sparams);
|
|
|
|
|
if (err < 0)
|
|
|
|
|
return err;
|
|
|
|
|
}
|
2001-02-05 15:44:42 +00:00
|
|
|
return 0;
|
2001-01-18 18:20:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int snd_pcm_plug_hw_refine_schange(snd_pcm_t *pcm, snd_pcm_hw_params_t *params,
|
|
|
|
|
snd_pcm_hw_params_t *sparams)
|
|
|
|
|
{
|
2001-02-11 15:45:35 +00:00
|
|
|
snd_pcm_plug_t *plug = pcm->private_data;
|
2001-01-18 18:20:31 +00:00
|
|
|
snd_pcm_t *slave = plug->req_slave;
|
|
|
|
|
unsigned int links = (SND_PCM_HW_PARBIT_PERIOD_TIME |
|
|
|
|
|
SND_PCM_HW_PARBIT_TICK_TIME);
|
2001-02-04 17:03:17 +00:00
|
|
|
const snd_pcm_format_mask_t *format_mask, *sformat_mask;
|
2001-02-04 18:57:05 +00:00
|
|
|
snd_pcm_format_mask_t sfmt_mask;
|
2001-01-18 18:20:31 +00:00
|
|
|
int err;
|
2001-02-04 17:03:17 +00:00
|
|
|
snd_pcm_format_t format;
|
2001-01-30 16:51:26 +00:00
|
|
|
snd_interval_t t, buffer_size;
|
|
|
|
|
const snd_interval_t *srate, *crate;
|
2001-12-11 15:10:27 +00:00
|
|
|
|
2001-07-07 15:53:20 +00:00
|
|
|
if (plug->srate == -2)
|
|
|
|
|
links |= SND_PCM_HW_PARBIT_RATE;
|
2001-11-23 11:47:01 +00:00
|
|
|
else {
|
2001-07-07 15:53:20 +00:00
|
|
|
snd_pcm_hw_param_refine_near(slave, sparams, SND_PCM_HW_PARAM_RATE,
|
|
|
|
|
params);
|
2001-11-23 11:47:01 +00:00
|
|
|
}
|
|
|
|
|
|
2001-07-07 15:53:20 +00:00
|
|
|
if (plug->schannels == -2)
|
|
|
|
|
links |= SND_PCM_HW_PARBIT_CHANNELS;
|
|
|
|
|
else
|
|
|
|
|
snd_pcm_hw_param_refine_near(slave, sparams, SND_PCM_HW_PARAM_CHANNELS,
|
|
|
|
|
params);
|
|
|
|
|
if (plug->sformat == -2)
|
|
|
|
|
links |= SND_PCM_HW_PARBIT_FORMAT;
|
|
|
|
|
else {
|
|
|
|
|
format_mask = snd_pcm_hw_param_get_mask(params,
|
|
|
|
|
SND_PCM_HW_PARAM_FORMAT);
|
|
|
|
|
sformat_mask = snd_pcm_hw_param_get_mask(sparams,
|
|
|
|
|
SND_PCM_HW_PARAM_FORMAT);
|
|
|
|
|
snd_mask_none(&sfmt_mask);
|
2001-07-11 14:09:01 +00:00
|
|
|
for (format = 0; format <= SND_PCM_FORMAT_LAST; format++) {
|
2001-07-07 15:53:20 +00:00
|
|
|
snd_pcm_format_t f;
|
|
|
|
|
if (!snd_pcm_format_mask_test(format_mask, format))
|
2001-01-18 18:20:31 +00:00
|
|
|
continue;
|
2001-07-07 15:53:20 +00:00
|
|
|
if (snd_pcm_format_mask_test(sformat_mask, format))
|
|
|
|
|
f = format;
|
|
|
|
|
else {
|
|
|
|
|
f = snd_pcm_plug_slave_format(format, sformat_mask);
|
|
|
|
|
if (f == SND_PCM_FORMAT_UNKNOWN)
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
snd_pcm_format_mask_set(&sfmt_mask, f);
|
2001-01-18 18:20:31 +00:00
|
|
|
}
|
|
|
|
|
|
2001-11-26 15:27:02 +00:00
|
|
|
if (snd_pcm_format_mask_empty(&sfmt_mask)) {
|
2001-12-11 15:10:27 +00:00
|
|
|
SNDERR("Unable to find an useable slave format for '%s'", pcm->name);
|
2001-11-26 15:27:02 +00:00
|
|
|
for (format = 0; format <= SND_PCM_FORMAT_LAST; format++) {
|
|
|
|
|
if (!snd_pcm_format_mask_test(format_mask, format))
|
|
|
|
|
continue;
|
|
|
|
|
SNDERR("Format: %s", snd_pcm_format_name(format));
|
|
|
|
|
}
|
|
|
|
|
for (format = 0; format <= SND_PCM_FORMAT_LAST; format++) {
|
|
|
|
|
if (!snd_pcm_format_mask_test(sformat_mask, format))
|
|
|
|
|
continue;
|
|
|
|
|
SNDERR("Slave format: %s", snd_pcm_format_name(format));
|
|
|
|
|
}
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
}
|
2001-07-07 15:53:20 +00:00
|
|
|
err = snd_pcm_hw_param_set_mask(slave, sparams, SND_CHANGE,
|
|
|
|
|
SND_PCM_HW_PARAM_FORMAT, &sfmt_mask);
|
2001-12-11 15:10:27 +00:00
|
|
|
if (err < 0)
|
|
|
|
|
return -EINVAL;
|
2001-07-07 15:53:20 +00:00
|
|
|
}
|
2001-01-18 18:20:31 +00:00
|
|
|
|
|
|
|
|
if (snd_pcm_hw_param_never_eq(params, SND_PCM_HW_PARAM_FORMAT, sparams) ||
|
|
|
|
|
snd_pcm_hw_param_never_eq(params, SND_PCM_HW_PARAM_CHANNELS, sparams) ||
|
|
|
|
|
snd_pcm_hw_param_never_eq(params, SND_PCM_HW_PARAM_RATE, sparams) ||
|
|
|
|
|
snd_pcm_hw_param_never_eq(params, SND_PCM_HW_PARAM_ACCESS, sparams)) {
|
2001-02-04 18:57:05 +00:00
|
|
|
snd_pcm_access_mask_t access_mask = { SND_PCM_ACCBIT_MMAP };
|
2001-02-04 17:03:17 +00:00
|
|
|
_snd_pcm_hw_param_set_mask(sparams, SND_PCM_HW_PARAM_ACCESS,
|
2001-02-04 18:57:05 +00:00
|
|
|
&access_mask);
|
2001-12-11 15:10:27 +00:00
|
|
|
if (snd_pcm_access_mask_empty(snd_pcm_hw_param_get_mask(sparams, SND_PCM_HW_PARAM_ACCESS))) {
|
|
|
|
|
SNDERR("Unable to find an useable access for '%s'", pcm->name);
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
}
|
2001-01-18 18:20:31 +00:00
|
|
|
}
|
2001-07-07 15:53:20 +00:00
|
|
|
if ((links & SND_PCM_HW_PARBIT_RATE) ||
|
|
|
|
|
snd_pcm_hw_param_always_eq(params, SND_PCM_HW_PARAM_RATE, sparams))
|
2001-03-04 20:39:02 +00:00
|
|
|
links |= (SND_PCM_HW_PARBIT_PERIOD_SIZE |
|
|
|
|
|
SND_PCM_HW_PARBIT_BUFFER_SIZE);
|
|
|
|
|
else {
|
|
|
|
|
snd_interval_copy(&buffer_size, snd_pcm_hw_param_get_interval(params, SND_PCM_HW_PARAM_BUFFER_SIZE));
|
|
|
|
|
snd_interval_unfloor(&buffer_size);
|
|
|
|
|
crate = snd_pcm_hw_param_get_interval(params, SND_PCM_HW_PARAM_RATE);
|
|
|
|
|
srate = snd_pcm_hw_param_get_interval(sparams, SND_PCM_HW_PARAM_RATE);
|
|
|
|
|
snd_interval_muldiv(&buffer_size, srate, crate, &t);
|
|
|
|
|
err = _snd_pcm_hw_param_set_interval(sparams, SND_PCM_HW_PARAM_BUFFER_SIZE, &t);
|
|
|
|
|
if (err < 0)
|
|
|
|
|
return err;
|
|
|
|
|
}
|
2001-01-19 09:48:33 +00:00
|
|
|
err = _snd_pcm_hw_params_refine(sparams, links, params);
|
2001-01-18 18:20:31 +00:00
|
|
|
if (err < 0)
|
|
|
|
|
return err;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int snd_pcm_plug_hw_refine_cchange(snd_pcm_t *pcm ATTRIBUTE_UNUSED,
|
|
|
|
|
snd_pcm_hw_params_t *params,
|
|
|
|
|
snd_pcm_hw_params_t *sparams)
|
|
|
|
|
{
|
2001-07-07 15:53:20 +00:00
|
|
|
snd_pcm_plug_t *plug = pcm->private_data;
|
2001-01-18 18:20:31 +00:00
|
|
|
unsigned int links = (SND_PCM_HW_PARBIT_PERIOD_TIME |
|
|
|
|
|
SND_PCM_HW_PARBIT_TICK_TIME);
|
2001-02-04 17:03:17 +00:00
|
|
|
const snd_pcm_format_mask_t *format_mask, *sformat_mask;
|
2001-02-04 18:57:05 +00:00
|
|
|
snd_pcm_format_mask_t fmt_mask;
|
2001-01-18 18:20:31 +00:00
|
|
|
int err;
|
2001-02-04 17:03:17 +00:00
|
|
|
snd_pcm_format_t format;
|
2001-01-30 16:51:26 +00:00
|
|
|
snd_interval_t t;
|
|
|
|
|
const snd_interval_t *sbuffer_size;
|
|
|
|
|
const snd_interval_t *srate, *crate;
|
2001-01-22 16:07:11 +00:00
|
|
|
unsigned int rate_min, srate_min;
|
|
|
|
|
int rate_mindir, srate_mindir;
|
2001-07-07 15:53:20 +00:00
|
|
|
|
|
|
|
|
if (plug->schannels == -2)
|
|
|
|
|
links |= SND_PCM_HW_PARBIT_CHANNELS;
|
|
|
|
|
|
|
|
|
|
if (plug->sformat == -2)
|
|
|
|
|
links |= SND_PCM_HW_PARBIT_FORMAT;
|
|
|
|
|
else {
|
|
|
|
|
format_mask = snd_pcm_hw_param_get_mask(params,
|
|
|
|
|
SND_PCM_HW_PARAM_FORMAT);
|
|
|
|
|
sformat_mask = snd_pcm_hw_param_get_mask(sparams,
|
|
|
|
|
SND_PCM_HW_PARAM_FORMAT);
|
|
|
|
|
snd_mask_none(&fmt_mask);
|
2001-07-11 14:09:01 +00:00
|
|
|
for (format = 0; format <= SND_PCM_FORMAT_LAST; format++) {
|
2001-07-07 15:53:20 +00:00
|
|
|
snd_pcm_format_t f;
|
|
|
|
|
if (!snd_pcm_format_mask_test(format_mask, format))
|
2001-01-18 18:20:31 +00:00
|
|
|
continue;
|
2001-07-07 15:53:20 +00:00
|
|
|
if (snd_pcm_format_mask_test(sformat_mask, format))
|
|
|
|
|
f = format;
|
|
|
|
|
else {
|
|
|
|
|
f = snd_pcm_plug_slave_format(format, sformat_mask);
|
|
|
|
|
if (f == SND_PCM_FORMAT_UNKNOWN)
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
snd_pcm_format_mask_set(&fmt_mask, format);
|
2001-01-18 18:20:31 +00:00
|
|
|
}
|
|
|
|
|
|
2001-11-27 14:24:44 +00:00
|
|
|
if (snd_pcm_format_mask_empty(&fmt_mask)) {
|
|
|
|
|
SNDERR("Unable to find an useable client format");
|
|
|
|
|
for (format = 0; format <= SND_PCM_FORMAT_LAST; format++) {
|
|
|
|
|
if (!snd_pcm_format_mask_test(format_mask, format))
|
|
|
|
|
continue;
|
|
|
|
|
SNDERR("Format: %s", snd_pcm_format_name(format));
|
|
|
|
|
}
|
|
|
|
|
for (format = 0; format <= SND_PCM_FORMAT_LAST; format++) {
|
|
|
|
|
if (!snd_pcm_format_mask_test(sformat_mask, format))
|
|
|
|
|
continue;
|
|
|
|
|
SNDERR("Slave format: %s", snd_pcm_format_name(format));
|
|
|
|
|
}
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
}
|
|
|
|
|
|
2001-07-07 15:53:20 +00:00
|
|
|
err = _snd_pcm_hw_param_set_mask(params,
|
|
|
|
|
SND_PCM_HW_PARAM_FORMAT, &fmt_mask);
|
2001-01-22 16:07:11 +00:00
|
|
|
if (err < 0)
|
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
|
2001-07-07 15:53:20 +00:00
|
|
|
if (plug->srate == -2)
|
|
|
|
|
links |= SND_PCM_HW_PARBIT_RATE;
|
|
|
|
|
else {
|
|
|
|
|
/* This is a temporary hack, waiting for a better solution */
|
|
|
|
|
rate_min = snd_pcm_hw_param_get_min(params, SND_PCM_HW_PARAM_RATE, &rate_mindir);
|
|
|
|
|
srate_min = snd_pcm_hw_param_get_min(sparams, SND_PCM_HW_PARAM_RATE, &srate_mindir);
|
|
|
|
|
if (rate_min == srate_min && srate_mindir > rate_mindir) {
|
|
|
|
|
err = _snd_pcm_hw_param_set_min(params, SND_PCM_HW_PARAM_RATE, srate_min, srate_mindir);
|
|
|
|
|
if (err < 0)
|
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if ((links & SND_PCM_HW_PARBIT_RATE) ||
|
|
|
|
|
snd_pcm_hw_param_always_eq(params, SND_PCM_HW_PARAM_RATE, sparams))
|
2001-03-04 20:39:02 +00:00
|
|
|
links |= (SND_PCM_HW_PARBIT_PERIOD_SIZE |
|
|
|
|
|
SND_PCM_HW_PARBIT_BUFFER_SIZE);
|
|
|
|
|
else {
|
|
|
|
|
sbuffer_size = snd_pcm_hw_param_get_interval(sparams, SND_PCM_HW_PARAM_BUFFER_SIZE);
|
|
|
|
|
crate = snd_pcm_hw_param_get_interval(params, SND_PCM_HW_PARAM_RATE);
|
|
|
|
|
srate = snd_pcm_hw_param_get_interval(sparams, SND_PCM_HW_PARAM_RATE);
|
|
|
|
|
snd_interval_muldiv(sbuffer_size, crate, srate, &t);
|
|
|
|
|
snd_interval_floor(&t);
|
|
|
|
|
err = _snd_pcm_hw_param_set_interval(params, SND_PCM_HW_PARAM_BUFFER_SIZE, &t);
|
|
|
|
|
if (err < 0)
|
|
|
|
|
return err;
|
|
|
|
|
}
|
2001-01-18 18:20:31 +00:00
|
|
|
err = _snd_pcm_hw_params_refine(params, links, sparams);
|
|
|
|
|
if (err < 0)
|
|
|
|
|
return err;
|
|
|
|
|
/* FIXME */
|
|
|
|
|
params->info &= ~(SND_PCM_INFO_MMAP | SND_PCM_INFO_MMAP_VALID);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int snd_pcm_plug_hw_refine_slave(snd_pcm_t *pcm, snd_pcm_hw_params_t *params)
|
|
|
|
|
{
|
2001-02-11 15:45:35 +00:00
|
|
|
snd_pcm_plug_t *plug = pcm->private_data;
|
2001-01-18 18:20:31 +00:00
|
|
|
return snd_pcm_hw_refine(plug->req_slave, params);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int snd_pcm_plug_hw_refine(snd_pcm_t *pcm, snd_pcm_hw_params_t *params)
|
|
|
|
|
{
|
|
|
|
|
return snd_pcm_hw_refine_slave(pcm, params,
|
|
|
|
|
snd_pcm_plug_hw_refine_cprepare,
|
|
|
|
|
snd_pcm_plug_hw_refine_cchange,
|
|
|
|
|
snd_pcm_plug_hw_refine_sprepare,
|
|
|
|
|
snd_pcm_plug_hw_refine_schange,
|
|
|
|
|
snd_pcm_plug_hw_refine_slave);
|
|
|
|
|
}
|
|
|
|
|
|
2000-11-20 20:10:46 +00:00
|
|
|
static int snd_pcm_plug_hw_params(snd_pcm_t *pcm, snd_pcm_hw_params_t *params)
|
2000-05-08 18:53:38 +00:00
|
|
|
{
|
2001-02-11 15:45:35 +00:00
|
|
|
snd_pcm_plug_t *plug = pcm->private_data;
|
2000-09-24 09:57:26 +00:00
|
|
|
snd_pcm_t *slave = plug->req_slave;
|
2000-12-21 20:44:10 +00:00
|
|
|
snd_pcm_plug_params_t clt_params, slv_params;
|
2000-11-20 20:10:46 +00:00
|
|
|
snd_pcm_hw_params_t sparams;
|
2001-01-18 18:20:31 +00:00
|
|
|
int err;
|
|
|
|
|
|
|
|
|
|
err = snd_pcm_plug_hw_refine_sprepare(pcm, &sparams);
|
|
|
|
|
assert(err >= 0);
|
|
|
|
|
err = snd_pcm_plug_hw_refine_schange(pcm, params, &sparams);
|
|
|
|
|
assert(err >= 0);
|
|
|
|
|
err = snd_pcm_hw_refine_soft(slave, &sparams);
|
2000-12-08 15:41:14 +00:00
|
|
|
assert(err >= 0);
|
|
|
|
|
|
2001-02-04 17:03:17 +00:00
|
|
|
clt_params.access = snd_pcm_hw_params_get_access(params);
|
|
|
|
|
clt_params.format = snd_pcm_hw_params_get_format(params);
|
|
|
|
|
clt_params.channels = snd_pcm_hw_params_get_channels(params);
|
|
|
|
|
clt_params.rate = snd_pcm_hw_params_get_rate(params, 0);
|
2000-12-08 15:41:14 +00:00
|
|
|
|
2001-02-04 17:03:17 +00:00
|
|
|
slv_params.format = snd_pcm_hw_params_get_format(&sparams);
|
|
|
|
|
slv_params.channels = snd_pcm_hw_params_get_channels(&sparams);
|
|
|
|
|
slv_params.rate = snd_pcm_hw_params_get_rate(&sparams, 0);
|
2000-12-10 21:39:54 +00:00
|
|
|
snd_pcm_plug_clear(pcm);
|
2001-01-22 09:27:50 +00:00
|
|
|
if (!(clt_params.format == slv_params.format &&
|
|
|
|
|
clt_params.channels == slv_params.channels &&
|
|
|
|
|
clt_params.rate == slv_params.rate &&
|
2001-10-25 18:21:18 +00:00
|
|
|
!plug->ttable &&
|
2001-02-06 23:48:10 +00:00
|
|
|
snd_pcm_hw_params_test_access(slave, &sparams,
|
|
|
|
|
clt_params.access) >= 0)) {
|
2001-02-04 17:03:17 +00:00
|
|
|
slv_params.access = snd_pcm_hw_params_set_access_first(slave, &sparams);
|
2001-01-22 09:27:50 +00:00
|
|
|
err = snd_pcm_plug_insert_plugins(pcm, &clt_params, &slv_params);
|
|
|
|
|
if (err < 0)
|
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
slave = plug->slave;
|
2001-02-05 09:35:17 +00:00
|
|
|
err = _snd_pcm_hw_params(slave, params);
|
2000-10-14 10:31:34 +00:00
|
|
|
if (err < 0) {
|
2000-09-24 09:57:26 +00:00
|
|
|
snd_pcm_plug_clear(pcm);
|
2000-10-14 10:31:34 +00:00
|
|
|
return err;
|
2000-10-10 11:17:23 +00:00
|
|
|
}
|
2000-10-14 10:31:34 +00:00
|
|
|
pcm->hw_ptr = slave->hw_ptr;
|
|
|
|
|
pcm->appl_ptr = slave->appl_ptr;
|
|
|
|
|
return 0;
|
2000-05-08 18:53:38 +00:00
|
|
|
}
|
|
|
|
|
|
2001-01-19 13:10:50 +00:00
|
|
|
static int snd_pcm_plug_hw_free(snd_pcm_t *pcm)
|
|
|
|
|
{
|
2001-02-11 15:45:35 +00:00
|
|
|
snd_pcm_plug_t *plug = pcm->private_data;
|
2001-01-19 13:10:50 +00:00
|
|
|
snd_pcm_t *slave = plug->slave;
|
|
|
|
|
int err = snd_pcm_hw_free(slave);
|
|
|
|
|
snd_pcm_plug_clear(pcm);
|
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
|
2000-11-20 20:10:46 +00:00
|
|
|
static int snd_pcm_plug_sw_params(snd_pcm_t *pcm, snd_pcm_sw_params_t * params)
|
2000-05-29 19:53:30 +00:00
|
|
|
{
|
2001-02-11 15:45:35 +00:00
|
|
|
snd_pcm_plug_t *plug = pcm->private_data;
|
2001-01-22 09:27:50 +00:00
|
|
|
return snd_pcm_sw_params(plug->slave, params);
|
2000-05-08 18:53:38 +00:00
|
|
|
}
|
|
|
|
|
|
2000-11-20 20:10:46 +00:00
|
|
|
static int snd_pcm_plug_channel_info(snd_pcm_t *pcm, snd_pcm_channel_info_t *info)
|
2000-05-08 18:53:38 +00:00
|
|
|
{
|
2001-02-11 15:45:35 +00:00
|
|
|
snd_pcm_plug_t *plug = pcm->private_data;
|
2000-11-20 20:10:46 +00:00
|
|
|
return snd_pcm_channel_info(plug->slave, info);
|
2000-05-08 18:53:38 +00:00
|
|
|
}
|
|
|
|
|
|
2000-12-10 21:39:54 +00:00
|
|
|
static int snd_pcm_plug_mmap(snd_pcm_t *pcm ATTRIBUTE_UNUSED)
|
2000-06-10 12:39:51 +00:00
|
|
|
{
|
2000-12-10 21:39:54 +00:00
|
|
|
return 0;
|
2000-06-10 12:39:51 +00:00
|
|
|
}
|
|
|
|
|
|
2000-12-10 21:39:54 +00:00
|
|
|
static int snd_pcm_plug_munmap(snd_pcm_t *pcm ATTRIBUTE_UNUSED)
|
2000-05-08 18:53:38 +00:00
|
|
|
{
|
2000-12-10 21:39:54 +00:00
|
|
|
return 0;
|
2000-05-08 18:53:38 +00:00
|
|
|
}
|
2000-11-20 20:10:46 +00:00
|
|
|
|
2001-01-17 11:00:32 +00:00
|
|
|
static void snd_pcm_plug_dump(snd_pcm_t *pcm, snd_output_t *out)
|
2000-07-17 15:33:29 +00:00
|
|
|
{
|
2001-02-11 15:45:35 +00:00
|
|
|
snd_pcm_plug_t *plug = pcm->private_data;
|
2001-01-17 11:00:32 +00:00
|
|
|
snd_output_printf(out, "Plug PCM: ");
|
|
|
|
|
snd_pcm_dump(plug->slave, out);
|
2000-07-17 15:33:29 +00:00
|
|
|
}
|
|
|
|
|
|
2000-10-14 10:31:34 +00:00
|
|
|
snd_pcm_ops_t snd_pcm_plug_ops = {
|
2000-06-21 15:03:06 +00:00
|
|
|
close: snd_pcm_plug_close,
|
2000-05-08 18:53:38 +00:00
|
|
|
info: snd_pcm_plug_info,
|
2000-12-21 20:44:10 +00:00
|
|
|
hw_refine: snd_pcm_plug_hw_refine,
|
2000-11-20 20:10:46 +00:00
|
|
|
hw_params: snd_pcm_plug_hw_params,
|
2001-01-19 13:10:50 +00:00
|
|
|
hw_free: snd_pcm_plug_hw_free,
|
2000-11-20 20:10:46 +00:00
|
|
|
sw_params: snd_pcm_plug_sw_params,
|
2000-08-28 09:14:37 +00:00
|
|
|
channel_info: snd_pcm_plug_channel_info,
|
2000-09-24 09:57:26 +00:00
|
|
|
dump: snd_pcm_plug_dump,
|
|
|
|
|
nonblock: snd_pcm_plug_nonblock,
|
2000-10-11 12:37:27 +00:00
|
|
|
async: snd_pcm_plug_async,
|
2000-10-14 10:31:34 +00:00
|
|
|
mmap: snd_pcm_plug_mmap,
|
|
|
|
|
munmap: snd_pcm_plug_munmap,
|
2000-05-08 18:53:38 +00:00
|
|
|
};
|
|
|
|
|
|
2000-10-14 10:31:34 +00:00
|
|
|
int snd_pcm_plug_open(snd_pcm_t **pcmp,
|
2001-02-06 23:48:10 +00:00
|
|
|
const char *name,
|
2001-07-07 15:53:20 +00:00
|
|
|
snd_pcm_format_t sformat, int schannels, int srate,
|
2001-07-19 09:11:05 +00:00
|
|
|
enum snd_pcm_plug_route_policy route_policy,
|
2001-01-26 09:56:30 +00:00
|
|
|
snd_pcm_route_ttable_entry_t *ttable,
|
2000-09-24 09:57:26 +00:00
|
|
|
unsigned int tt_ssize,
|
|
|
|
|
unsigned int tt_cused, unsigned int tt_sused,
|
|
|
|
|
snd_pcm_t *slave, int close_slave)
|
2000-06-21 15:03:06 +00:00
|
|
|
{
|
2000-10-14 10:31:34 +00:00
|
|
|
snd_pcm_t *pcm;
|
2000-06-21 15:03:06 +00:00
|
|
|
snd_pcm_plug_t *plug;
|
2001-06-20 20:52:12 +00:00
|
|
|
int err;
|
2000-10-14 10:31:34 +00:00
|
|
|
assert(pcmp && slave);
|
2000-06-21 15:03:06 +00:00
|
|
|
plug = calloc(1, sizeof(snd_pcm_plug_t));
|
2000-09-24 09:57:26 +00:00
|
|
|
if (!plug)
|
2000-06-21 15:03:06 +00:00
|
|
|
return -ENOMEM;
|
2001-07-07 15:53:20 +00:00
|
|
|
plug->sformat = sformat;
|
|
|
|
|
plug->schannels = schannels;
|
|
|
|
|
plug->srate = srate;
|
2000-09-24 09:57:26 +00:00
|
|
|
plug->slave = plug->req_slave = slave;
|
2000-05-08 18:53:38 +00:00
|
|
|
plug->close_slave = close_slave;
|
2001-07-19 09:11:05 +00:00
|
|
|
plug->route_policy = route_policy;
|
2000-09-24 09:57:26 +00:00
|
|
|
plug->ttable = ttable;
|
|
|
|
|
plug->tt_ssize = tt_ssize;
|
|
|
|
|
plug->tt_cused = tt_cused;
|
|
|
|
|
plug->tt_sused = tt_sused;
|
|
|
|
|
|
2001-06-20 20:52:12 +00:00
|
|
|
err = snd_pcm_new(&pcm, SND_PCM_TYPE_PLUG, name, slave->stream, slave->mode);
|
|
|
|
|
if (err < 0) {
|
2000-09-24 09:57:26 +00:00
|
|
|
free(plug);
|
2001-06-20 20:52:12 +00:00
|
|
|
return err;
|
2000-09-24 09:57:26 +00:00
|
|
|
}
|
2000-10-14 10:31:34 +00:00
|
|
|
pcm->ops = &snd_pcm_plug_ops;
|
|
|
|
|
pcm->fast_ops = slave->fast_ops;
|
|
|
|
|
pcm->fast_op_arg = slave->fast_op_arg;
|
2001-02-11 15:45:35 +00:00
|
|
|
pcm->private_data = plug;
|
2000-10-14 10:31:34 +00:00
|
|
|
pcm->poll_fd = slave->poll_fd;
|
|
|
|
|
pcm->hw_ptr = slave->hw_ptr;
|
|
|
|
|
pcm->appl_ptr = slave->appl_ptr;
|
|
|
|
|
*pcmp = pcm;
|
2000-09-24 09:57:26 +00:00
|
|
|
|
2000-05-08 18:53:38 +00:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2001-07-07 15:53:20 +00:00
|
|
|
#define MAX_CHANNELS 64
|
2000-05-08 18:53:38 +00:00
|
|
|
|
2001-02-06 23:48:10 +00:00
|
|
|
int _snd_pcm_plug_open(snd_pcm_t **pcmp, const char *name,
|
2001-06-11 13:35:48 +00:00
|
|
|
snd_config_t *root, snd_config_t *conf,
|
2001-02-04 17:03:17 +00:00
|
|
|
snd_pcm_stream_t stream, int mode)
|
2000-09-24 09:57:26 +00:00
|
|
|
{
|
2001-02-11 15:45:35 +00:00
|
|
|
snd_config_iterator_t i, next;
|
2000-09-24 09:57:26 +00:00
|
|
|
int err;
|
|
|
|
|
snd_pcm_t *spcm;
|
2001-05-14 15:44:37 +00:00
|
|
|
snd_config_t *slave = NULL, *sconf;
|
2000-09-24 09:57:26 +00:00
|
|
|
snd_config_t *tt = NULL;
|
2001-08-20 09:02:41 +00:00
|
|
|
enum snd_pcm_plug_route_policy route_policy = PLUG_ROUTE_POLICY_DEFAULT;
|
2001-01-26 09:56:30 +00:00
|
|
|
snd_pcm_route_ttable_entry_t *ttable = NULL;
|
2000-09-24 09:57:26 +00:00
|
|
|
unsigned int cused, sused;
|
2001-07-07 15:53:20 +00:00
|
|
|
snd_pcm_format_t sformat = SND_PCM_FORMAT_UNKNOWN;
|
|
|
|
|
int schannels = -1, srate = -1;
|
2001-02-11 15:45:35 +00:00
|
|
|
snd_config_for_each(i, next, conf) {
|
2001-02-07 11:34:33 +00:00
|
|
|
snd_config_t *n = snd_config_iterator_entry(i);
|
2001-11-19 08:14:21 +00:00
|
|
|
const char *id;
|
|
|
|
|
if (snd_config_get_id(n, &id) < 0)
|
|
|
|
|
continue;
|
2001-06-04 18:04:18 +00:00
|
|
|
if (snd_pcm_conf_generic_id(id))
|
2000-09-24 09:57:26 +00:00
|
|
|
continue;
|
2001-03-17 16:34:43 +00:00
|
|
|
if (strcmp(id, "slave") == 0) {
|
|
|
|
|
slave = n;
|
2000-09-24 09:57:26 +00:00
|
|
|
continue;
|
|
|
|
|
}
|
2001-02-07 11:34:33 +00:00
|
|
|
if (strcmp(id, "ttable") == 0) {
|
2001-07-19 09:11:05 +00:00
|
|
|
route_policy = PLUG_ROUTE_POLICY_NONE;
|
2001-02-07 11:34:33 +00:00
|
|
|
if (snd_config_get_type(n) != SND_CONFIG_TYPE_COMPOUND) {
|
2001-03-04 20:39:02 +00:00
|
|
|
SNDERR("Invalid type for %s", id);
|
2000-09-24 09:57:26 +00:00
|
|
|
return -EINVAL;
|
2000-11-30 09:40:50 +00:00
|
|
|
}
|
2000-09-24 09:57:26 +00:00
|
|
|
tt = n;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2001-07-19 09:11:05 +00:00
|
|
|
if (strcmp(id, "route_policy") == 0) {
|
|
|
|
|
const char *str;
|
|
|
|
|
if ((err = snd_config_get_string(n, &str)) < 0) {
|
|
|
|
|
SNDERR("Invalid type for %s", id);
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
}
|
2001-08-20 09:02:41 +00:00
|
|
|
if (tt != NULL)
|
|
|
|
|
SNDERR("Table is defined, route policy is ignored");
|
|
|
|
|
if (!strcmp(str, "default"))
|
|
|
|
|
route_policy = PLUG_ROUTE_POLICY_DEFAULT;
|
2001-08-20 13:15:30 +00:00
|
|
|
else if (!strcmp(str, "average"))
|
|
|
|
|
route_policy = PLUG_ROUTE_POLICY_AVERAGE;
|
2001-07-19 09:11:05 +00:00
|
|
|
else if (!strcmp(str, "copy"))
|
|
|
|
|
route_policy = PLUG_ROUTE_POLICY_COPY;
|
|
|
|
|
else if (!strcmp(str, "duplicate"))
|
|
|
|
|
route_policy = PLUG_ROUTE_POLICY_DUP;
|
2001-07-21 09:55:01 +00:00
|
|
|
continue;
|
2001-07-19 09:11:05 +00:00
|
|
|
}
|
2001-03-04 20:39:02 +00:00
|
|
|
SNDERR("Unknown field %s", id);
|
2000-09-24 09:57:26 +00:00
|
|
|
return -EINVAL;
|
|
|
|
|
}
|
2001-03-17 16:34:43 +00:00
|
|
|
if (!slave) {
|
|
|
|
|
SNDERR("slave is not defined");
|
2000-09-24 09:57:26 +00:00
|
|
|
return -EINVAL;
|
2000-11-30 09:40:50 +00:00
|
|
|
}
|
2001-07-07 15:53:20 +00:00
|
|
|
err = snd_pcm_slave_conf(root, slave, &sconf, 3,
|
|
|
|
|
SND_PCM_HW_PARAM_FORMAT, SCONF_UNCHANGED, &sformat,
|
|
|
|
|
SND_PCM_HW_PARAM_CHANNELS, SCONF_UNCHANGED, &schannels,
|
|
|
|
|
SND_PCM_HW_PARAM_RATE, SCONF_UNCHANGED, &srate);
|
2001-03-17 16:34:43 +00:00
|
|
|
if (err < 0)
|
|
|
|
|
return err;
|
2000-09-24 09:57:26 +00:00
|
|
|
if (tt) {
|
|
|
|
|
ttable = malloc(MAX_CHANNELS * MAX_CHANNELS * sizeof(*ttable));
|
|
|
|
|
err = snd_pcm_route_load_ttable(tt, ttable, MAX_CHANNELS, MAX_CHANNELS,
|
|
|
|
|
&cused, &sused, -1);
|
2001-06-16 22:03:23 +00:00
|
|
|
if (err < 0) {
|
|
|
|
|
snd_config_delete(sconf);
|
2000-09-24 09:57:26 +00:00
|
|
|
return err;
|
2001-06-16 22:03:23 +00:00
|
|
|
}
|
2000-09-24 09:57:26 +00:00
|
|
|
}
|
|
|
|
|
|
2001-06-15 08:47:59 +00:00
|
|
|
err = snd_pcm_open_slave(&spcm, root, sconf, stream, mode);
|
2001-06-16 22:03:23 +00:00
|
|
|
snd_config_delete(sconf);
|
2000-09-24 09:57:26 +00:00
|
|
|
if (err < 0)
|
|
|
|
|
return err;
|
2001-07-07 15:53:20 +00:00
|
|
|
err = snd_pcm_plug_open(pcmp, name, sformat, schannels, srate,
|
2001-07-19 09:11:05 +00:00
|
|
|
route_policy, ttable, MAX_CHANNELS, cused, sused, spcm, 1);
|
2000-09-24 09:57:26 +00:00
|
|
|
if (err < 0)
|
|
|
|
|
snd_pcm_close(spcm);
|
|
|
|
|
return err;
|
|
|
|
|
}
|
2001-10-24 14:14:11 +00:00
|
|
|
SND_DLSYM_BUILD_VERSION(_snd_pcm_plug_open, SND_PCM_DLSYM_VERSION);
|