Added argument handling for the slave PCMs.

The configuration root (snd_config) can be specified for the internal routines.
The pcm_hooks code was recoded (independent code moved to control/setup.c).
Improved the pcm_multi plugin (added master configuration).
This commit is contained in:
Jaroslav Kysela 2001-06-11 13:35:48 +00:00
parent 61bf03ce70
commit bf780a25a5
29 changed files with 1179 additions and 1070 deletions

View file

@ -17,6 +17,10 @@ server.NAME {
pcm_type.NAME {
[lib STR] # Library file (default libasound.so)
[open STR] # Open function (default _snd_pcm_NAME_open)
[redirect { # Redirect this PCM to an another
[filename STR] # Configuration file specification
name STR # PCM name specification
}]
}
# PCM scope type definition
@ -177,6 +181,7 @@ pcm.NAME {
channel INT # Slave channel
}
}
[master INT] # Define the master slave
type file # File plugin

View file

@ -43,6 +43,7 @@ int snd_config_expand(snd_config_t *config, const char *args,
int snd_config_add(snd_config_t *config, snd_config_t *leaf);
int snd_config_delete(snd_config_t *config);
int snd_config_copy(snd_config_t **dst, snd_config_t *src);
int snd_config_make(snd_config_t **config, const char *key,
snd_config_type_t type);
@ -55,9 +56,11 @@ int snd_config_set_id(snd_config_t *config, const char *id);
int snd_config_set_integer(snd_config_t *config, long value);
int snd_config_set_real(snd_config_t *config, double value);
int snd_config_set_string(snd_config_t *config, const char *value);
int snd_config_set_ascii(snd_config_t *config, const char *ascii);
int snd_config_get_integer(snd_config_t *config, long *value);
int snd_config_get_real(snd_config_t *config, double *value);
int snd_config_get_string(snd_config_t *config, const char **value);
int snd_config_get_ascii(snd_config_t *config, char **value);
snd_config_iterator_t snd_config_iterator_first(snd_config_t *node);
snd_config_iterator_t snd_config_iterator_next(snd_config_iterator_t iterator);
@ -80,10 +83,24 @@ const char *snd_config_get_id(snd_config_t *config);
extern snd_config_t *snd_config;
int snd_config_update(void);
/* Misc functions */
int snd_config_get_bool_ascii(const char *ascii);
int snd_config_get_bool(snd_config_t *conf);
int snd_config_get_ctl_iface_ascii(const char *ascii);
int snd_config_get_ctl_iface(snd_config_t *conf);
typedef int (snd_config_string_replace_callback_t)(const char *what, char **dst, void *private_data);
int snd_config_string_replace(const char *src, char idchr,
snd_config_string_replace_callback_t *callback,
void *private_data,
char **dst);
int snd_config_redirect_load(snd_config_t *root, snd_config_t *config,
char **name, snd_config_t **dst_config,
int *dst_dynamic);
#ifdef __cplusplus
}
#endif

View file

@ -246,12 +246,8 @@ typedef enum _snd_ctl_type {
/** CTL handle */
typedef struct _snd_ctl snd_ctl_t;
/** SCTL replace type */
typedef struct {
const char *key;
const char *old_value;
const char *new_value;
} snd_sctl_replace_t;
/** Don't destroy the ctl handle when close */
#define SND_SCTL_NOFREE 0x0001
/** SCTL type */
typedef struct _snd_sctl snd_sctl_t;
@ -269,8 +265,12 @@ int snd_card_get_longname(int card, char **name);
int snd_card_type_string_to_enum(const char *strid, snd_card_type_t *enumid);
int snd_card_type_enum_to_string(snd_card_type_t enumid, char **strid);
int snd_sctl_build(snd_ctl_t *ctl, snd_sctl_t **setup, snd_config_t *config, snd_sctl_replace_t *replace);
int snd_sctl_free(snd_ctl_t *ctl, snd_sctl_t *setup);
int snd_sctl_build(snd_sctl_t **ctl, snd_ctl_t *handle, snd_config_t *config,
snd_config_string_replace_callback_t *callback,
void *private_data, int mode);
int snd_sctl_free(snd_sctl_t *handle);
int snd_sctl_install(snd_sctl_t *handle);
int snd_sctl_remove(snd_sctl_t *handle);
int snd_ctl_open(snd_ctl_t **ctl, const char *name, int mode);
int snd_ctl_close(snd_ctl_t *ctl);

View file

@ -59,6 +59,8 @@ typedef enum _snd_set_mode {
size_t page_align(size_t size);
size_t page_size(void);
int safe_strtol(const char *str, long *val);
#define HAVE_GNU_LD
#define HAVE_ELF
#define HAVE_ASM_PREVIOUS_DIRECTIVE

View file

@ -731,6 +731,7 @@ typedef struct _snd_pcm_hook snd_pcm_hook_t;
typedef int (*snd_pcm_hook_func_t)(snd_pcm_hook_t *hook);
snd_pcm_t *snd_pcm_hook_get_pcm(snd_pcm_hook_t *hook);
void *snd_pcm_hook_get_private(snd_pcm_hook_t *hook);
void snd_pcm_hook_set_private(snd_pcm_hook_t *hook, void *private_data);
int snd_pcm_hook_add(snd_pcm_hook_t **hookp, snd_pcm_t *pcm,
snd_pcm_hook_type_t type,
snd_pcm_hook_func_t func, void *private_data);

View file

@ -2,7 +2,7 @@ SUBDIRS=control mixer pcm rawmidi timer hwdep seq instr compat cards
COMPATNUM=@LIBTOOL_VERSION_INFO@
lib_LTLIBRARIES = libasound.la
libasound_la_SOURCES = conf.c input.c output.c error.c
libasound_la_SOURCES = conf.c confmisc.c input.c output.c error.c
libasound_la_LIBADD = control/libcontrol.la mixer/libmixer.la pcm/libpcm.la \
rawmidi/librawmidi.la timer/libtimer.la \
hwdep/libhwdep.la seq/libseq.la instr/libinstr.la \

View file

@ -143,7 +143,7 @@ pcm.surround40_new {
}
redirect {
filename "&(datadir)/cards/&(card_id:$(CARD)).conf"
name "pcm.surround40_$(DEV)_&(pcm_id:$(CARD),$(DEV)):$(CARD),$(DEV)"
name "pcm.surround40_$(DEV)_&(pcm_id:$(CARD),$(DEV)):$(CARD)"
}
}

View file

@ -2,17 +2,70 @@
# Configuration for the SI7018 chip
#
pcm.surround40_0_trident_dx_nx {
pcm.front {
$.0 CARD
$.1 DEV
$.2 SUBDEV
$.CARD {
type integer
}
$.DEV {
type integer
}
$.SUBDEV {
type integer
default -1
}
type hw
card $(CARD)
device $(DEV)
subdevice -1
subdevice $(SUBDEV)
}
pcm_slave.front {
pcm pcm.front
channels 2
}
pcm.rear {
$.0 CARD
$.1 DEV
$.2 SUBDEV
$.CARD {
type integer
}
$.DEV {
type integer
}
$.SUBDEV {
type integer
default -1
}
type hw
card $(CARD)
device $(DEV)
subdevice $(SUBDEV)
}
pcm_slave.rear {
pcm pcm.rear
channels 2
}
pcm.surround40_0_trident_dx_nx {
$.0 CARD
$.CARD {
type integer
}
type multi
slaves {
0 "pcm_slave.front:$(CARD),0,-1"
1 "pcm_slave.rear:$(CARD),0,-1"
}
bindings {
0 { slave 0 channel 0 }
1 { slave 0 channel 1 }
2 { slave 1 channel 0 }
3 { slave 1 channel 1 }
}
}

View file

@ -1665,7 +1665,7 @@ int snd_config_copy(snd_config_t **dst,
* \param dst Destination string
*/
int snd_config_string_replace(const char *src, char idchr,
int (*callback)(const char *what, char **dst, void *private_data),
snd_config_string_replace_callback_t *callback,
void *private_data,
char **dst)
{
@ -1809,11 +1809,7 @@ static int _snd_config_expand(snd_config_t *src,
snd_config_delete(*dst);
return 0;
}
err = snd_config_set_string(*dst, str);
if (err < 0) {
snd_config_delete(*dst);
return err;
}
(*dst)->u.string = str;
} else {
err = snd_config_set_string(*dst, s);
if (err < 0) {
@ -2252,183 +2248,3 @@ static void _snd_config_end(void)
files_info_count = 0;
}
#endif
static int _snd_config_redirect_load_replace(const char *what, char **dst, void *private_data ATTRIBUTE_UNUSED)
{
enum {
CARD_ID,
PCM_ID,
RAWMIDI_ID
} id;
int len;
if (!strcmp(what, "datadir")) {
*dst = strdup(DATADIR "/alsa");
return *dst == NULL ? -ENOMEM : 0;
}
if (!strncmp(what, "card_id:", len = 8))
id = CARD_ID;
else if (!strncmp(what, "pcm_id:", len = 7))
id = PCM_ID;
else if (!strncmp(what, "rawmidi_id:", len = 11))
id = RAWMIDI_ID;
else
return 0;
{
snd_ctl_t *ctl;
int err;
char name[12];
const char *str = NULL;
char *fstr = NULL;
sprintf(name, "hw:%d", atoi(what + len));
err = snd_ctl_open(&ctl, name, 0);
if (err < 0)
return err;
switch (id) {
case CARD_ID:
{
snd_ctl_card_info_t *info;
snd_ctl_card_info_alloca(&info);
err = snd_ctl_card_info(ctl, info);
if (err < 0)
return err;
err = snd_card_type_enum_to_string(snd_ctl_card_info_get_type(info), &fstr);
}
break;
case PCM_ID:
{
char *ptr = strchr(what + len, ',');
int dev = atoi(what + len);
int subdev = ptr ? atoi(ptr + 1) : -1;
snd_pcm_info_t *info;
snd_pcm_info_alloca(&info);
snd_pcm_info_set_device(info, dev);
snd_pcm_info_set_subdevice(info, subdev);
err = snd_ctl_pcm_info(ctl, info);
if (err < 0)
return err;
str = snd_pcm_info_get_id(info);
}
break;
case RAWMIDI_ID:
{
char *ptr = strchr(what + len, ',');
int dev = atoi(what + len);
int subdev = ptr ? atoi(ptr + 1) : -1;
snd_rawmidi_info_t *info;
snd_rawmidi_info_alloca(&info);
snd_rawmidi_info_set_device(info, dev);
snd_rawmidi_info_set_subdevice(info, subdev);
err = snd_ctl_rawmidi_info(ctl, info);
if (err < 0)
return err;
str = snd_rawmidi_info_get_id(info);
}
break;
}
if (err < 0)
return err;
snd_ctl_close(ctl);
*dst = fstr ? fstr : (str ? strdup(str) : NULL);
if (*dst == NULL)
return 0;
return 0;
}
return 0; /* empty */
}
/**
* \brief Redirect the configuration block to an another
* \param root the root of all configurations
* \param config redirect configuration
* \param name the identifier of new configuration block
* \param dst_config new configuration block
* \param dst_dynamic new configuration block is dynamically allocated
*/
int snd_config_redirect_load(snd_config_t *root,
snd_config_t *config,
char **name,
snd_config_t **dst_config,
int *dst_dynamic)
{
int err, dynamic;
snd_config_t *result, *c;
char *rname;
assert(config);
assert(name);
assert(dst_config);
assert(dst_dynamic);
if (snd_config_get_type(config) == SND_CONFIG_TYPE_STRING) {
const char *str;
snd_config_get_string(config, &str);
*name = strdup(str);
if (*name == NULL)
return -ENOMEM;
*dst_config = root;
*dst_dynamic = 0;
return 0;
}
if (snd_config_get_type(config) != SND_CONFIG_TYPE_COMPOUND)
return -EINVAL;
result = root;
dynamic = 0;
rname = NULL;
if (snd_config_search(config, "filename", &c) >= 0) {
snd_config_t *rconfig;
char *filename;
snd_input_t *input;
err = snd_config_copy(&rconfig, root);
if (err < 0)
return err;
if (snd_config_get_type(c) == SND_CONFIG_TYPE_STRING) {
snd_config_get_string(c, (const char **)&filename);
if ((err = snd_config_string_replace(filename, '&', _snd_config_redirect_load_replace, NULL, &filename)) < 0)
goto __filename_error;
if (filename == NULL)
goto __filename_error_einval;
} else {
__filename_error_einval:
err = -EINVAL;
__filename_error:
snd_config_delete(rconfig);
return err;
}
err = snd_input_stdio_open(&input, filename, "r");
if (err < 0) {
SNDERR("Unable to open filename %s: %s", filename, snd_strerror(err));
goto __filename_error;
}
err = snd_config_load(rconfig, input);
if (err < 0) {
snd_input_close(input);
goto __filename_error;
return err;
}
snd_input_close(input);
free(filename);
result = rconfig;
dynamic = 1;
}
if (snd_config_search(config, "name", &c) >= 0) {
const char *ptr;
if ((err = snd_config_get_string(c, &ptr)) < 0)
goto __error;
if ((err = snd_config_string_replace(ptr, '&', _snd_config_redirect_load_replace, NULL, &rname)) < 0)
goto __error;
}
if (rname == NULL) {
err = -EINVAL;
goto __error;
}
*dst_config = result;
*dst_dynamic = dynamic;
*name = rname;
return 0;
__error:
if (rname)
free(rname);
if (dynamic)
snd_config_delete(result);
return err;
}

320
src/confmisc.c Normal file
View file

@ -0,0 +1,320 @@
/*
* Miscellaneous configuration helper functions
* Copyright (c) 2000 by Abramo Bagnara <abramo@alsa-project.org>,
* Jaroslav Kysela <perex@suse.cz>
*
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2 of
* 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
* GNU Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include "local.h"
#include "asoundlib.h"
/**
* \brief Get the boolean value from given ASCII string
* \param ascii The ASCII string to be parsed
* \return a positive value when success otherwise a negative error number
*/
int snd_config_get_bool_ascii(const char *ascii)
{
unsigned int k;
static struct {
const char *str;
int val;
} b[] = {
{ "0", 0 },
{ "1", 1 },
{ "false", 0 },
{ "true", 1 },
{ "no", 0 },
{ "yes", 1 },
{ "off", 0 },
{ "on", 1 },
};
for (k = 0; k < sizeof(b) / sizeof(*b); k++) {
if (strcasecmp(b[k].str, ascii) == 0)
return b[k].val;
}
return -EINVAL;
}
/**
* \brief Get the boolean value
* \param conf The configuration node to be parsed
* \return a positive value when success otherwise a negative error number
*/
int snd_config_get_bool(snd_config_t *conf)
{
long v;
const char *str;
int err;
err = snd_config_get_integer(conf, &v);
if (err >= 0) {
if (v < 0 || v > 1) {
_invalid_value:
SNDERR("Invalid value for %s", snd_config_get_id(conf));
return -EINVAL;
}
return v;
}
err = snd_config_get_string(conf, &str);
if (err < 0) {
SNDERR("Invalid type for %s", snd_config_get_id(conf));
return -EINVAL;
}
err = snd_config_get_bool_ascii(str);
if (err < 0)
goto _invalid_value;
return err;
}
/**
* \brief Get the control interface index from given ASCII string
* \param ascii The ASCII string to be parsed
* \return a positive value when success otherwise a negative error number
*/
int snd_config_get_ctl_iface_ascii(const char *ascii)
{
long v;
snd_ctl_elem_iface_t idx;
if (isdigit(ascii[0])) {
if (safe_strtol(ascii, &v) >= 0) {
if (v < 0 || v > SND_CTL_ELEM_IFACE_LAST)
return -EINVAL;
return v;
}
}
for (idx = 0; idx <= SND_CTL_ELEM_IFACE_LAST; idx++) {
if (strcasecmp(snd_ctl_elem_iface_name(idx), ascii) == 0)
return idx;
}
return -EINVAL;
}
/**
* \brief Get the control interface index
* \param conf The configuration node to be parsed
* \return a positive value when success otherwise a negative error number
*/
int snd_config_get_ctl_iface(snd_config_t *conf)
{
long v;
const char *str;
int err;
err = snd_config_get_integer(conf, &v);
if (err >= 0) {
if (v < 0 || v > SND_CTL_ELEM_IFACE_LAST) {
_invalid_value:
SNDERR("Invalid value for %s", snd_config_get_id(conf));
return -EINVAL;
}
return v;
}
err = snd_config_get_string(conf, &str);
if (err < 0) {
SNDERR("Invalid type for %s", snd_config_get_id(conf));
return -EINVAL;
}
err = snd_config_get_ctl_iface_ascii(str);
if (err < 0)
goto _invalid_value;
return err;
}
static int _snd_config_redirect_load_replace(const char *what, char **dst, void *private_data ATTRIBUTE_UNUSED)
{
enum {
CARD_ID,
PCM_ID,
RAWMIDI_ID
} id;
int len;
if (!strcmp(what, "datadir")) {
*dst = strdup(DATADIR "/alsa");
return *dst == NULL ? -ENOMEM : 0;
}
if (!strncmp(what, "card_id:", len = 8))
id = CARD_ID;
else if (!strncmp(what, "pcm_id:", len = 7))
id = PCM_ID;
else if (!strncmp(what, "rawmidi_id:", len = 11))
id = RAWMIDI_ID;
else
return 0;
{
snd_ctl_t *ctl;
int err;
char name[12];
const char *str = NULL;
char *fstr = NULL;
sprintf(name, "hw:%d", atoi(what + len));
err = snd_ctl_open(&ctl, name, 0);
if (err < 0)
return err;
switch (id) {
case CARD_ID:
{
snd_ctl_card_info_t *info;
snd_ctl_card_info_alloca(&info);
err = snd_ctl_card_info(ctl, info);
if (err < 0)
return err;
err = snd_card_type_enum_to_string(snd_ctl_card_info_get_type(info), &fstr);
}
break;
case PCM_ID:
{
char *ptr = strchr(what + len, ',');
int dev = atoi(what + len);
int subdev = ptr ? atoi(ptr + 1) : -1;
snd_pcm_info_t *info;
snd_pcm_info_alloca(&info);
snd_pcm_info_set_device(info, dev);
snd_pcm_info_set_subdevice(info, subdev);
err = snd_ctl_pcm_info(ctl, info);
if (err < 0)
return err;
str = snd_pcm_info_get_id(info);
}
break;
case RAWMIDI_ID:
{
char *ptr = strchr(what + len, ',');
int dev = atoi(what + len);
int subdev = ptr ? atoi(ptr + 1) : -1;
snd_rawmidi_info_t *info;
snd_rawmidi_info_alloca(&info);
snd_rawmidi_info_set_device(info, dev);
snd_rawmidi_info_set_subdevice(info, subdev);
err = snd_ctl_rawmidi_info(ctl, info);
if (err < 0)
return err;
str = snd_rawmidi_info_get_id(info);
}
break;
}
if (err < 0)
return err;
snd_ctl_close(ctl);
*dst = fstr ? fstr : (str ? strdup(str) : NULL);
if (*dst == NULL)
return 0;
return 0;
}
return 0; /* empty */
}
/**
* \brief Redirect the configuration block to an another
* \param root the root of all configurations
* \param config redirect configuration
* \param name the identifier of new configuration block
* \param dst_config new configuration block
* \param dst_dynamic new configuration block is dynamically allocated
*/
int snd_config_redirect_load(snd_config_t *root,
snd_config_t *config,
char **name,
snd_config_t **dst_config,
int *dst_dynamic)
{
int err, dynamic;
snd_config_t *result, *c;
char *rname;
assert(config);
assert(name);
assert(dst_config);
assert(dst_dynamic);
if (snd_config_get_type(config) == SND_CONFIG_TYPE_STRING) {
const char *str;
snd_config_get_string(config, &str);
*name = strdup(str);
if (*name == NULL)
return -ENOMEM;
*dst_config = root;
*dst_dynamic = 0;
return 0;
}
if (snd_config_get_type(config) != SND_CONFIG_TYPE_COMPOUND)
return -EINVAL;
result = root;
dynamic = 0;
rname = NULL;
if (snd_config_search(config, "filename", &c) >= 0) {
snd_config_t *rconfig;
char *filename;
snd_input_t *input;
err = snd_config_copy(&rconfig, root);
if (err < 0)
return err;
if (snd_config_get_type(c) == SND_CONFIG_TYPE_STRING) {
snd_config_get_string(c, (const char **)&filename);
if ((err = snd_config_string_replace(filename, '&', _snd_config_redirect_load_replace, NULL, &filename)) < 0)
goto __filename_error;
if (filename == NULL)
goto __filename_error_einval;
} else {
__filename_error_einval:
err = -EINVAL;
__filename_error:
snd_config_delete(rconfig);
return err;
}
err = snd_input_stdio_open(&input, filename, "r");
if (err < 0) {
SNDERR("Unable to open filename %s: %s", filename, snd_strerror(err));
goto __filename_error;
}
err = snd_config_load(rconfig, input);
if (err < 0) {
snd_input_close(input);
goto __filename_error;
return err;
}
snd_input_close(input);
free(filename);
result = rconfig;
dynamic = 1;
}
if (snd_config_search(config, "name", &c) >= 0) {
const char *ptr;
if ((err = snd_config_get_string(c, &ptr)) < 0)
goto __error;
if ((err = snd_config_string_replace(ptr, '&', _snd_config_redirect_load_replace, NULL, &rname)) < 0)
goto __error;
}
if (rname == NULL) {
err = -EINVAL;
goto __error;
}
*dst_config = result;
*dst_dynamic = dynamic;
*name = rname;
return 0;
__error:
if (rname)
free(rname);
if (dynamic)
snd_config_delete(result);
return err;
}

View file

@ -1,5 +1,6 @@
/**
* \file control/setup.c
* \author Abramo Bagnara <abramo@alsa-project.org>
* \author Jaroslav Kysela <perex@suse.cz>
* \date 2001
*
@ -7,7 +8,8 @@
*/
/*
* Control Interface - routines for setup from configuration
* Copyright (c) 2000 by Jaroslav Kysela <perex@suse.cz>
* Copyright (c) 2001 by Abramo Bagnara <abramo@alsa-project.org>
* Jaroslav Kysela <perex@suse.cz>
*
*
* This library is free software; you can redistribute it and/or modify
@ -32,258 +34,596 @@
#include <unistd.h>
#include <string.h>
#include <ctype.h>
#include "control_local.h"
#include "list.h"
#include "local.h"
typedef struct snd_sctl_elem {
typedef struct {
unsigned int lock: 1;
unsigned int preserve: 1;
snd_ctl_elem_id_t *id;
snd_ctl_elem_info_t *info;
snd_ctl_elem_value_t *val;
snd_ctl_elem_value_t *mask;
snd_ctl_elem_value_t *old;
struct list_head list;
snd_ctl_elem_value_t *value;
int lock: 1,
preserve: 1;
} snd_sctl_elem_t;
struct _snd_sctl {
struct list_head elements;
int mode;
snd_ctl_t *ctl;
struct list_head elems;
};
static const char *id_str(snd_ctl_elem_id_t *id)
static int free_elems(snd_sctl_t *h)
{
static char str[128];
assert(id);
sprintf(str, "%i,%i,%i,%s,%i",
snd_enum_to_int(snd_ctl_elem_id_get_interface(id)),
snd_ctl_elem_id_get_device(id),
snd_ctl_elem_id_get_subdevice(id),
snd_ctl_elem_id_get_name(id),
snd_ctl_elem_id_get_index(id));
return str;
int err = 0;
while (!list_empty(&h->elems)) {
snd_sctl_elem_t *elem = list_entry(h->elems.next, snd_sctl_elem_t, list);
snd_ctl_elem_id_free(elem->id);
snd_ctl_elem_info_free(elem->info);
snd_ctl_elem_value_free(elem->val);
snd_ctl_elem_value_free(elem->mask);
snd_ctl_elem_value_free(elem->old);
list_del(&elem->list);
free(elem);
}
if ((h->mode & SND_SCTL_NOFREE) == 0)
err = snd_ctl_close(h->ctl);
free(h);
return err;
}
static int config_iface(const char *value)
int snd_sctl_install(snd_sctl_t *h)
{
int idx;
struct list_head *pos;
int err;
unsigned int k;
assert(h);
list_for_each(pos, &h->elems) {
snd_sctl_elem_t *elem = list_entry(pos, snd_sctl_elem_t, list);
unsigned int count;
snd_ctl_elem_type_t type;
if (elem->lock) {
err = snd_ctl_elem_lock(h->ctl, elem->id);
if (err < 0) {
SNDERR("Cannot lock ctl elem");
return err;
}
}
err = snd_ctl_elem_read(h->ctl, elem->old);
if (err < 0) {
SNDERR("Cannot read ctl elem");
return err;
}
count = snd_ctl_elem_info_get_count(elem->info);
type = snd_ctl_elem_info_get_type(elem->info);
switch (type) {
case SND_CTL_ELEM_TYPE_BOOLEAN:
for (k = 0; k < count; ++k) {
int old, val, mask;
old = snd_ctl_elem_value_get_boolean(elem->old, k);
mask = snd_ctl_elem_value_get_boolean(elem->mask, k);
old &= ~mask;
if (old) {
val = snd_ctl_elem_value_get_boolean(elem->val, k);
val |= old;
snd_ctl_elem_value_set_boolean(elem->val, k, val);
}
}
break;
case SND_CTL_ELEM_TYPE_INTEGER:
for (k = 0; k < count; ++k) {
long old, val, mask;
old = snd_ctl_elem_value_get_integer(elem->old, k);
mask = snd_ctl_elem_value_get_integer(elem->mask, k);
old &= ~mask;
if (old) {
val = snd_ctl_elem_value_get_integer(elem->val, k);
val |= old;
snd_ctl_elem_value_set_integer(elem->val, k, val);
}
}
break;
case SND_CTL_ELEM_TYPE_ENUMERATED:
for (k = 0; k < count; ++k) {
unsigned int old, val, mask;
old = snd_ctl_elem_value_get_enumerated(elem->old, k);
mask = snd_ctl_elem_value_get_enumerated(elem->mask, k);
old &= ~mask;
if (old) {
val = snd_ctl_elem_value_get_enumerated(elem->val, k);
val |= old;
snd_ctl_elem_value_set_enumerated(elem->val, k, val);
}
}
break;
case SND_CTL_ELEM_TYPE_IEC958:
count = sizeof(snd_aes_iec958_t);
/* Fall through */
case SND_CTL_ELEM_TYPE_BYTES:
for (k = 0; k < count; ++k) {
unsigned char old, val, mask;
old = snd_ctl_elem_value_get_byte(elem->old, k);
mask = snd_ctl_elem_value_get_byte(elem->mask, k);
old &= ~mask;
if (old) {
val = snd_ctl_elem_value_get_byte(elem->val, k);
val |= old;
snd_ctl_elem_value_set_byte(elem->val, k, val);
}
}
break;
default:
assert(0);
break;
}
err = snd_ctl_elem_write(h->ctl, elem->val);
if (err < 0) {
SNDERR("Cannot write ctl elem");
return err;
}
}
return 0;
}
if (isdigit(*value))
return atoi(value);
for (idx = 0; idx <= SND_CTL_ELEM_IFACE_LAST; idx++)
if (strcasecmp(snd_ctl_elem_iface_name(idx), value) == 0)
return snd_enum_to_int(idx);
SNDERR("iface '%s' error", value);
int snd_sctl_remove(snd_sctl_t *h)
{
struct list_head *pos;
int err;
assert(h);
list_for_each(pos, &h->elems) {
snd_sctl_elem_t *elem = list_entry(pos, snd_sctl_elem_t, list);
if (elem->lock) {
err = snd_ctl_elem_unlock(h->ctl, elem->id);
if (err < 0) {
SNDERR("Cannot unlock ctl elem");
return err;
}
}
if (elem->preserve) {
err = snd_ctl_elem_write(h->ctl, elem->old);
if (err < 0) {
SNDERR("Cannot restore ctl elem");
return err;
}
}
}
return 0;
}
static int snd_config_get_ctl_elem_enumerated(snd_config_t *n, snd_ctl_t *ctl,
snd_ctl_elem_info_t *info)
{
const char *str;
long val;
unsigned int idx, items;
switch (snd_enum_to_int(snd_config_get_type(n))) {
case SND_CONFIG_TYPE_INTEGER:
snd_config_get_integer(n, &val);
return val;
case SND_CONFIG_TYPE_STRING:
snd_config_get_string(n, &str);
break;
default:
return -1;
}
items = snd_ctl_elem_info_get_items(info);
for (idx = 0; idx < items; idx++) {
int err;
snd_ctl_elem_info_set_item(info, idx);
err = snd_ctl_elem_info(ctl, info);
if (err < 0) {
SNDERR("Cannot obtain info for CTL elem");
return err;
}
if (strcmp(str, snd_ctl_elem_info_get_item_name(info)) == 0)
return idx;
}
return -1;
}
static void try_replace(snd_sctl_replace_t *replace, const char *id, const char **value)
static int snd_config_get_ctl_elem_value(snd_config_t *conf,
snd_ctl_t *ctl,
snd_ctl_elem_value_t *val,
snd_ctl_elem_value_t *mask,
snd_ctl_elem_info_t *info)
{
if (replace == NULL)
return;
while (replace->key) {
if (!strcmp(id, replace->key)) {
if (!strcmp(*value, replace->old_value)) {
*value = replace->new_value;
return;
int err;
snd_config_iterator_t i, next;
snd_ctl_elem_id_t *id;
snd_ctl_elem_type_t type;
unsigned int count;
long v;
long idx;
snd_ctl_elem_id_alloca(&id);
snd_ctl_elem_value_get_id(val, id);
count = snd_ctl_elem_info_get_count(info);
type = snd_ctl_elem_info_get_type(info);
if (count == 1) {
switch (snd_enum_to_int(type)) {
case SND_CTL_ELEM_TYPE_BOOLEAN:
v = snd_config_get_bool(conf);
if (v >= 0) {
snd_ctl_elem_value_set_boolean(val, 0, v);
if (mask)
snd_ctl_elem_value_set_boolean(mask, 0, 1);
return 0;
}
break;
case SND_CTL_ELEM_TYPE_INTEGER:
err = snd_config_get_integer(conf, &v);
if (err == 0) {
snd_ctl_elem_value_set_integer(val, 0, v);
if (mask)
snd_ctl_elem_value_set_integer(mask, 0, ~0L);
return 0;
}
break;
case SND_CTL_ELEM_TYPE_ENUMERATED:
v = snd_config_get_ctl_elem_enumerated(conf, ctl, info);
if (v >= 0) {
snd_ctl_elem_value_set_enumerated(val, 0, v);
if (mask)
snd_ctl_elem_value_set_enumerated(mask, 0, ~0);
return 0;
}
break;
case SND_CTL_ELEM_TYPE_BYTES:
case SND_CTL_ELEM_TYPE_IEC958:
break;
default:
SNDERR("Unknow control type: %d", snd_enum_to_int(type));
return -EINVAL;
}
replace++;
}
}
static void add_value(snd_ctl_elem_info_t *info, snd_ctl_elem_value_t *evalue, int idx, const char *value)
{
switch (snd_ctl_elem_info_get_type(info)) {
case SND_CTL_ELEM_TYPE_BOOLEAN:
{
int val = 0;
if (idx < 0 || idx >= 128) {
SNDERR("index out of range (0-127): %i", idx);
return;
}
if (!strcasecmp(value, "true") || !strcasecmp(value, "on"))
val = 1;
else if (isdigit(*value))
val = atoi(value);
snd_ctl_elem_value_set_boolean(evalue, idx, val);
}
break;
case SND_CTL_ELEM_TYPE_INTEGER:
{
if (idx < 0 || idx >= 128) {
SNDERR("index out of range (0-127): %i", idx);
return;
}
snd_ctl_elem_value_set_integer(evalue, idx, strtoul(value, NULL, 10));
}
break;
#if 0
case SND_CTL_ELEM_TYPE_ENUMERATED:
case SND_CTL_ELEM_TYPE_BYTES:
switch (snd_enum_to_int(type)) {
case SND_CTL_ELEM_TYPE_IEC958:
break;
#endif
default:
SNDERR("type %i is not supported", snd_ctl_elem_info_get_type(info));
count = sizeof(snd_aes_iec958_t);
/* Fall through */
case SND_CTL_ELEM_TYPE_BYTES:
{
const char *buf;
err = snd_config_get_string(conf, &buf);
if (err >= 0) {
int c1 = 0;
unsigned int len = strlen(buf);
unsigned int idx = 0;
if (len % 2 != 0 || len > count * 2) {
_bad_content:
SNDERR("bad value content\n");
return -EINVAL;
}
while (*buf) {
int c = *buf++;
if (c >= '0' && c <= '9')
c -= '0';
else if (c >= 'a' && c <= 'f')
c = c - 'a' + 10;
else if (c >= 'A' && c <= 'F')
c = c - 'A' + 10;
else {
goto _bad_content;
}
if (idx % 2 == 1) {
snd_ctl_elem_value_set_byte(val, idx / 2, c1 << 4 | c);
if (mask)
snd_ctl_elem_value_set_byte(mask, idx / 2, 0xff);
} else
c1 = c;
idx++;
}
return 0;
}
}
default:
break;
}
if (snd_config_get_type(conf) != SND_CONFIG_TYPE_COMPOUND) {
SNDERR("bad value type");
return -EINVAL;
}
snd_config_for_each(i, next, conf) {
snd_config_t *n = snd_config_iterator_entry(i);
err = safe_strtol(snd_config_get_id(n), &idx);
if (err < 0 || idx < 0 || (unsigned int) idx >= count) {
SNDERR("bad value index");
return -EINVAL;
}
switch (snd_enum_to_int(type)) {
case SND_CTL_ELEM_TYPE_BOOLEAN:
v = snd_config_get_bool(n);
if (v < 0)
goto _bad_content;
snd_ctl_elem_value_set_boolean(val, idx, v);
if (mask)
snd_ctl_elem_value_set_boolean(mask, idx, 1);
break;
case SND_CTL_ELEM_TYPE_INTEGER:
err = snd_config_get_integer(n, &v);
if (err < 0)
goto _bad_content;
snd_ctl_elem_value_set_integer(val, idx, v);
if (mask)
snd_ctl_elem_value_set_integer(mask, idx, ~0L);
break;
case SND_CTL_ELEM_TYPE_ENUMERATED:
v = snd_config_get_ctl_elem_enumerated(n, ctl, info);
if (v < 0)
goto _bad_content;
snd_ctl_elem_value_set_enumerated(val, idx, v);
if (mask)
snd_ctl_elem_value_set_enumerated(mask, idx, ~0);
break;
case SND_CTL_ELEM_TYPE_BYTES:
case SND_CTL_ELEM_TYPE_IEC958:
err = snd_config_get_integer(n, &v);
if (err < 0 || v < 0 || v > 255)
goto _bad_content;
snd_ctl_elem_value_set_byte(val, idx, v);
if (mask)
snd_ctl_elem_value_set_byte(mask, idx, 0xff);
break;
default:
break;
}
}
return 0;
}
/**
* \brief build and set control primitives from configuration
* \param setup container for control primitives
* \return 0 on success otherwise a negative error code
*
* Build and set control primitives from configuration.
*/
int snd_sctl_build(snd_ctl_t *handle, snd_sctl_t **r_setup, snd_config_t *config, snd_sctl_replace_t *replace)
static int config_replace(snd_config_t *conf,
snd_config_string_replace_callback_t *callback,
void *private_data, char **res)
{
snd_sctl_t *setup;
int err;
char *replace, *tmp;
err = snd_config_get_ascii(conf, &tmp);
if (err < 0)
return err;
err = snd_config_string_replace(tmp, '&', callback, private_data, &replace);
free(tmp);
if (err < 0)
return err;
if (replace == NULL) {
SNDERR("Invalid value for '%s'", snd_config_get_id(conf));
return err;
}
*res = replace;
return 0;
}
static int config_replace_integer(snd_config_t *conf,
snd_config_string_replace_callback_t *callback,
void *private_data, long *res)
{
char *tmp;
int err;
err = config_replace(conf, callback, private_data, &tmp);
if (err < 0)
return err;
err = safe_strtol(tmp, res);
if (err < 0) {
SNDERR("Invalid value for '%s'", snd_config_get_id(conf));
return err;
}
return 0;
}
static int config_replace_bool(snd_config_t *conf,
snd_config_string_replace_callback_t *callback,
void *private_data, int *res)
{
char *tmp;
int err;
err = config_replace(conf, callback, private_data, &tmp);
if (err < 0)
return err;
err = snd_config_get_bool_ascii(tmp);
free(tmp);
if (err < 0) {
SNDERR("Invalid value for '%s'", snd_config_get_id(conf));
return err;
}
*res = err;
return 0;
}
static int add_elem(snd_sctl_t *h, snd_config_t *conf,
snd_config_string_replace_callback_t *callback,
void *private_data)
{
snd_config_iterator_t i, next;
char *tmp;
int iface = SND_CTL_ELEM_IFACE_PCM;
char *name = NULL;
long index = 0;
long device = -1;
long subdevice = -1;
int lock = 0;
int preserve = 0;
snd_config_t *value = NULL, *mask = NULL;
snd_sctl_elem_t *elem = NULL;
int err;
snd_config_for_each(i, next, conf) {
snd_config_t *n = snd_config_iterator_entry(i);
const char *id = snd_config_get_id(n);
if (strcmp(id, "comment") == 0)
continue;
if (strcmp(id, "iface") == 0) {
if ((err = config_replace(n, callback, private_data, &tmp)) < 0)
goto _err;
if ((err = snd_config_get_ctl_iface_ascii(tmp)) < 0) {
SNDERR("Invalid value for '%s'", id);
free(tmp);
goto _err;
}
free(tmp);
continue;
}
if (strcmp(id, "name") == 0) {
if ((err = config_replace(n, callback, private_data, &name)) < 0)
goto _err;
continue;
}
if (strcmp(id, "index") == 0) {
if ((err = config_replace_integer(n, callback, private_data, &index)) < 0)
goto _err;
}
if (strcmp(id, "device") == 0) {
if ((err = config_replace_integer(n, callback, private_data, &device)) < 0)
goto _err;
continue;
}
if (strcmp(id, "subdevice") == 0) {
if ((err = config_replace_integer(n, callback, private_data, &subdevice)) < 0)
goto _err;
}
if (strcmp(id, "lock") == 0) {
if ((err = config_replace_bool(n, callback, private_data, &lock)) < 0)
goto _err;
continue;
}
if (strcmp(id, "preserve") == 0) {
if ((err = config_replace_bool(n, callback, private_data, &preserve)) < 0)
goto _err;
continue;
}
if (strcmp(id, "value") == 0) {
value = n;
continue;
}
if (strcmp(id, "mask") == 0) {
mask = n;
continue;
}
SNDERR("Unknown field %s", id);
return -EINVAL;
}
if (name == NULL) {
SNDERR("Missing control name");
err = -EINVAL;
goto _err;
}
if (value == NULL) {
SNDERR("Missing control value");
err = -EINVAL;
goto _err;
}
if (device < 0)
device = 0;
if (subdevice < 0)
subdevice = 0;
elem = calloc(1, sizeof(*elem));
if (!elem)
return -ENOMEM;
err = snd_ctl_elem_id_malloc(&elem->id);
if (err < 0)
goto _err;
err = snd_ctl_elem_info_malloc(&elem->info);
if (err < 0)
goto _err;
err = snd_ctl_elem_value_malloc(&elem->val);
if (err < 0)
goto _err;
err = snd_ctl_elem_value_malloc(&elem->mask);
if (err < 0)
goto _err;
err = snd_ctl_elem_value_malloc(&elem->old);
if (err < 0)
goto _err;
elem->lock = lock;
elem->preserve = preserve;
snd_ctl_elem_id_set_interface(elem->id, iface);
snd_ctl_elem_id_set_name(elem->id, name);
snd_ctl_elem_id_set_index(elem->id, index);
snd_ctl_elem_id_set_device(elem->id, device);
snd_ctl_elem_id_set_subdevice(elem->id, subdevice);
snd_ctl_elem_info_set_id(elem->info, elem->id);
err = snd_ctl_elem_info(h->ctl, elem->info);
if (err < 0) {
SNDERR("Cannot obtain info for CTL elem");
goto _err;
}
snd_ctl_elem_value_set_id(elem->val, elem->id);
snd_ctl_elem_value_set_id(elem->old, elem->id);
if (mask) {
err = snd_config_get_ctl_elem_value(value, h->ctl, elem->val, NULL, elem->info);
if (err < 0)
goto _err;
err = snd_config_get_ctl_elem_value(mask, h->ctl, elem->mask, NULL, elem->info);
if (err < 0)
goto _err;
} else {
err = snd_config_get_ctl_elem_value(value, h->ctl, elem->val, elem->mask, elem->info);
if (err < 0)
goto _err;
}
err = snd_config_get_ctl_elem_value(value, h->ctl, elem->val, elem->mask, elem->info);
if (err < 0)
goto _err;
list_add_tail(&elem->list, &h->elems);
return 0;
_err:
if (name)
free(name);
if (elem) {
if (elem->id)
snd_ctl_elem_id_free(elem->id);
if (elem->info)
snd_ctl_elem_info_free(elem->info);
if (elem->val)
snd_ctl_elem_value_free(elem->val);
if (elem->mask)
snd_ctl_elem_value_free(elem->mask);
if (elem->old)
snd_ctl_elem_value_free(elem->old);
free(elem);
}
return err;
}
int snd_sctl_build(snd_sctl_t **sctl, snd_ctl_t *handle, snd_config_t *conf,
snd_config_string_replace_callback_t *callback,
void *private_data,
int mode)
{
snd_sctl_t *h;
snd_config_iterator_t i, next;
int err;
assert(handle && r_setup && config);
*r_setup = NULL;
if ((setup = calloc(1, sizeof(*setup))) == NULL)
assert(sctl);
assert(conf);
if (snd_config_get_type(conf) != SND_CONFIG_TYPE_COMPOUND)
return -EINVAL;
h = calloc(1, sizeof(*h));
if (!h) {
if (mode & SND_SCTL_NOFREE)
return -ENOMEM;
snd_ctl_close(handle);
return -ENOMEM;
INIT_LIST_HEAD(&setup->elements);
snd_config_for_each(i, next, config) {
}
h->mode = mode;
h->ctl = handle;
INIT_LIST_HEAD(&h->elems);
snd_config_for_each(i, next, conf) {
snd_config_t *n = snd_config_iterator_entry(i);
// const char *id = snd_config_get_id(n);
if (snd_config_get_type(n) == SND_CONFIG_TYPE_COMPOUND) {
snd_config_iterator_t i, next;
snd_sctl_elem_t *elem;
snd_ctl_elem_id_t *eid;
snd_ctl_elem_info_t *einfo;
snd_ctl_elem_value_t *evalue;
snd_ctl_elem_id_alloca(&eid);
snd_ctl_elem_info_alloca(&einfo);
snd_ctl_elem_value_alloca(&evalue);
elem = calloc(1, sizeof(*elem));
if (elem == NULL) {
SNDERR("malloc problem");
continue;
}
snd_config_for_each(i, next, n) {
snd_config_t *n = snd_config_iterator_entry(i);
const char *id = snd_config_get_id(n);
char svalue[16];
const char *value;
unsigned long i;
if (snd_config_get_type(n) == SND_CONFIG_TYPE_INTEGER) {
snd_config_get_integer(n, &i);
sprintf(svalue, "%li", i);
value = svalue;
} else if (snd_config_get_type(n) == SND_CONFIG_TYPE_STRING) {
snd_config_get_string(n, &value);
} else if (snd_config_get_type(n) == SND_CONFIG_TYPE_COMPOUND) {
value = NULL;
} else {
SNDERR("unknown configuration entry type");
continue;
}
try_replace(replace, id, &value);
if (!strcmp(id, "iface"))
snd_ctl_elem_id_set_interface(eid, config_iface(value));
else if (!strcmp(id, "name"))
snd_ctl_elem_id_set_name(eid, value);
else if (!strcmp(id, "index"))
snd_ctl_elem_id_set_index(eid, atoi(value));
else if (!strcmp(id, "lock"))
elem->lock = 1;
else if (!strcmp(id, "preserve"))
elem->preserve = 1;
else if (!strcmp(id, "value")) {
if (elem->value == NULL) {
if (snd_ctl_elem_value_malloc(&elem->value) < 0) {
SNDERR("malloc problem");
continue;
}
snd_ctl_elem_info_set_id(einfo, eid);
if ((err = snd_ctl_elem_info(handle, einfo)) < 0) {
SNDERR("snd_ctl_elem_info %s : %s", id_str(eid), snd_strerror(err));
continue;
}
snd_ctl_elem_value_set_id(elem->value, eid);
if ((err = snd_ctl_elem_read(handle, elem->value)) < 0) {
SNDERR("snd_ctl_elem_read %s : %s", id_str(eid), snd_strerror(err));
continue;
}
snd_ctl_elem_value_copy(evalue, elem->value);
}
if (value == NULL) {
snd_config_iterator_t i, next;
snd_config_for_each(i, next, n) {
snd_config_t *n = snd_config_iterator_entry(i);
char svalue[16];
const char *value;
int idx = atoi(snd_config_get_id(n));
unsigned long i;
if (snd_config_get_type(n) == SND_CONFIG_TYPE_INTEGER) {
snd_config_get_integer(n, &i);
sprintf(svalue, "%li", i);
value = svalue;
} else if (snd_config_get_type(n) == SND_CONFIG_TYPE_STRING) {
snd_config_get_string(n, &value);
} else {
SNDERR("unknown configuration entry type");
continue;
}
add_value(einfo, evalue, idx, value);
}
} else {
add_value(einfo, evalue, 0, value);
}
}
}
list_add_tail(&elem->list, &setup->elements);
if ((err = snd_ctl_elem_write(handle, evalue)) < 0) {
SNDERR("snd_ctl_elem_write %s : %s", id_str(eid), snd_strerror(err));
snd_sctl_free(handle, setup);
return err;
}
if (elem->lock) {
if ((err = snd_ctl_elem_lock(handle, eid)) < 0) {
SNDERR("snd_ctl_elem_lock %s : %s", id_str(eid), snd_strerror(err));
snd_sctl_free(handle, setup);
return err;
}
}
if (!elem->preserve) {
snd_ctl_elem_value_free(elem->value);
elem->value = NULL;
}
} else {
SNDERR("compound type expected here");
err = add_elem(h, n, callback, private_data);
if (err < 0) {
free_elems(h);
return err;
}
}
*r_setup = setup;
*sctl = h;
return 0;
}
/**
* \brief restore control primitives from configuration
* \param setup container for control primitives
* \return 0 on success otherwise a negative error code
*
* Restore control primitives from configuration
*/
int snd_sctl_free(snd_ctl_t *handle, snd_sctl_t *setup)
int snd_sctl_free(snd_sctl_t *sctl)
{
struct list_head *pos;
snd_sctl_elem_t *elem;
int err;
assert(setup);
__again:
list_for_each(pos, &setup->elements) {
elem = list_entry(pos, snd_sctl_elem_t, list);
if (elem->preserve && elem->value) {
if ((err = snd_ctl_elem_write(handle, elem->value)) < 0)
SNDERR("snd_ctl_elem_write %s : %s", id_str(&elem->value->id), snd_strerror(err));
}
if (elem->value) {
snd_ctl_elem_value_free(elem->value);
elem->value = NULL;
}
list_del(&elem->list);
free(elem);
goto __again;
}
free(setup);
return 0;
assert(sctl);
return free_elems(sctl);
}

View file

@ -7,7 +7,7 @@ libpcm_la_SOURCES = atomic.c mask.c interval.c \
pcm_route.c pcm_mulaw.c pcm_alaw.c pcm_adpcm.c \
pcm_rate.c pcm_plug.c pcm_misc.c pcm_mmap.c pcm_multi.c \
pcm_shm.c pcm_file.c pcm_null.c pcm_share.c \
pcm_meter.c pcm_hooks.c pcm_surr.c
pcm_meter.c pcm_hooks.c
noinst_HEADERS = atomic.h pcm_local.h pcm_plugin.h mask.h mask_inline.h \
interval.h interval_inline.h plugin_ops.h

View file

@ -912,7 +912,7 @@ ssize_t snd_pcm_samples_to_bytes(snd_pcm_t *pcm, int samples)
}
static int snd_pcm_open_conf(snd_pcm_t **pcmp, const char *name,
snd_config_t *pcm_conf,
snd_config_t *root, snd_config_t *pcm_conf,
snd_pcm_stream_t stream, int mode)
{
const char *str;
@ -921,7 +921,8 @@ static int snd_pcm_open_conf(snd_pcm_t **pcmp, const char *name,
snd_config_t *conf, *type_conf = NULL;
snd_config_iterator_t i, next;
const char *lib = NULL, *open_name = NULL;
int (*open_func)(snd_pcm_t **, const char *, snd_config_t *,
int (*open_func)(snd_pcm_t **, const char *,
snd_config_t *, snd_config_t *,
snd_pcm_stream_t, int);
void *h;
if (snd_config_get_type(pcm_conf) != SND_CONFIG_TYPE_COMPOUND) {
@ -989,7 +990,7 @@ static int snd_pcm_open_conf(snd_pcm_t **pcmp, const char *name,
dlclose(h);
return -ENXIO;
}
err = open_func(pcmp, name, pcm_conf, stream, mode);
err = open_func(pcmp, name, root, pcm_conf, stream, mode);
if (err < 0)
return err;
return 0;
@ -1057,7 +1058,7 @@ static int snd_pcm_open_noupdate(snd_pcm_t **pcmp, snd_config_t *root,
snd_config_delete(tmp_conf);
return err;
}
err = snd_pcm_open_conf(pcmp, name, pcm_conf, stream, mode);
err = snd_pcm_open_conf(pcmp, name, root, pcm_conf, stream, mode);
if (args)
snd_config_delete(pcm_conf);
return err;
@ -1083,13 +1084,26 @@ int snd_pcm_open(snd_pcm_t **pcmp, const char *name,
}
#ifndef DOC_HIDDEN
int snd_pcm_open_slave(snd_pcm_t **pcmp, snd_config_t *conf,
snd_pcm_stream_t stream, int mode)
int snd_pcm_open_slave(snd_pcm_t **pcmp, snd_config_t *root, snd_config_t *conf,
const char *args, snd_pcm_stream_t stream, int mode)
{
const char *str;
if (snd_config_get_string(conf, &str) >= 0)
return snd_pcm_open_noupdate(pcmp, snd_config, str, stream, mode);
return snd_pcm_open_conf(pcmp, NULL, conf, stream, mode);
if (snd_config_get_string(conf, &str) >= 0) {
char *tmp;
int err;
if (args == NULL)
return snd_pcm_open_noupdate(pcmp, root, str, stream, mode);
tmp = malloc(strlen(str) + 1 + strlen(args) + 1);
if (tmp == NULL)
return -ENOMEM;
strcpy(tmp, str);
strcat(tmp, ":");
strcat(tmp, args);
err = snd_pcm_open_noupdate(pcmp, root, tmp, stream, mode);
free(tmp);
return err;
}
return snd_pcm_open_conf(pcmp, NULL, root, conf, stream, mode);
}
#endif
@ -4304,7 +4318,8 @@ static const char *names[SND_PCM_HW_PARAM_LAST + 1] = {
[SND_PCM_HW_PARAM_BUFFER_TIME] = "buffer_time"
};
int snd_pcm_slave_conf(snd_config_t *conf, snd_config_t **pcm_conf,
int snd_pcm_slave_conf(snd_config_t *root, snd_config_t *conf,
snd_config_t **pcm_conf, const char **pcm_args,
unsigned int count, ...)
{
snd_config_iterator_t i, next;
@ -4319,12 +4334,45 @@ int snd_pcm_slave_conf(snd_config_t *conf, snd_config_t **pcm_conf,
int pcm_valid = 0;
int err;
va_list args;
assert(root);
assert(conf);
assert(pcm_conf);
if (snd_config_get_string(conf, &str) >= 0) {
err = snd_config_search_alias(snd_config, "pcm_slave", str, &conf);
if (err < 0) {
SNDERR("unknown pcm_slave %s", str);
return err;
char *key;
const char *args = strchr(str, ':');
char *base;
if (args) {
args++;
base = alloca(args - str);
memcpy(base, str, args - str - 1);
base[args - str - 1] = '\0';
key = strchr(base, '.');
if (key)
*key++ = '\0';
} else {
key = strchr(str, '.');
if (key) {
key++;
base = alloca(key - str);
memcpy(base, str, key - str - 1);
base[key - str - 1] = '\0';
} else
base = (char *) str;
}
if (key == NULL) {
key = base;
base = NULL;
}
err = snd_config_search_alias(root, base, key, &conf);
if (err < 0) {
(void)(base == NULL && (err = snd_config_search_alias(root, "pcm_slave", key, &conf)));
if (err < 0) {
SNDERR("unknown pcm_slave %s", str);
return err;
}
}
if (pcm_args)
*pcm_args = args;
}
if (snd_config_get_type(conf) != SND_CONFIG_TYPE_COMPOUND) {
SNDERR("Invalid slave definition");
@ -4371,7 +4419,7 @@ int snd_pcm_slave_conf(snd_config_t *conf, snd_config_t **pcm_conf,
return -EINVAL;
}
*(snd_pcm_format_t*)fields[k].ptr = f;
break;
break;
}
default:
err = snd_config_get_integer(n, &v);
@ -4386,7 +4434,7 @@ int snd_pcm_slave_conf(snd_config_t *conf, snd_config_t **pcm_conf,
if (k < count)
continue;
SNDERR("Unknown field %s", id);
return -EINVAL;
// return -EINVAL;
}
if (!pcm_valid) {
SNDERR("missing field pcm");

View file

@ -548,14 +548,15 @@ int snd_pcm_adpcm_open(snd_pcm_t **pcmp, const char *name, snd_pcm_format_t sfor
}
int _snd_pcm_adpcm_open(snd_pcm_t **pcmp, const char *name,
snd_config_t *conf,
snd_pcm_stream_t stream, int mode)
snd_config_t *root, snd_config_t *conf,
snd_pcm_stream_t stream, int mode)
{
snd_config_iterator_t i, next;
int err;
snd_pcm_t *spcm;
snd_config_t *slave = NULL, *sconf;
snd_pcm_format_t sformat;
const char *args;
snd_config_for_each(i, next, conf) {
snd_config_t *n = snd_config_iterator_entry(i);
const char *id = snd_config_get_id(n);
@ -572,7 +573,7 @@ int _snd_pcm_adpcm_open(snd_pcm_t **pcmp, const char *name,
SNDERR("slave is not defined");
return -EINVAL;
}
err = snd_pcm_slave_conf(slave, &sconf, 1,
err = snd_pcm_slave_conf(root, slave, &sconf, &args, 1,
SND_PCM_HW_PARAM_FORMAT, 1, &sformat);
if (err < 0)
return err;
@ -581,7 +582,7 @@ int _snd_pcm_adpcm_open(snd_pcm_t **pcmp, const char *name,
SNDERR("invalid slave format");
return -EINVAL;
}
err = snd_pcm_open_slave(&spcm, sconf, stream, mode);
err = snd_pcm_open_slave(&spcm, root, sconf, args, stream, mode);
if (err < 0)
return err;
err = snd_pcm_adpcm_open(pcmp, name, sformat, spcm, 1);

View file

@ -421,14 +421,15 @@ int snd_pcm_alaw_open(snd_pcm_t **pcmp, const char *name, snd_pcm_format_t sform
}
int _snd_pcm_alaw_open(snd_pcm_t **pcmp, const char *name,
snd_config_t *conf,
snd_pcm_stream_t stream, int mode)
snd_config_t *root, snd_config_t *conf,
snd_pcm_stream_t stream, int mode)
{
snd_config_iterator_t i, next;
int err;
snd_pcm_t *spcm;
snd_config_t *slave = NULL, *sconf;
snd_pcm_format_t sformat;
const char *args;
snd_config_for_each(i, next, conf) {
snd_config_t *n = snd_config_iterator_entry(i);
const char *id = snd_config_get_id(n);
@ -445,7 +446,7 @@ int _snd_pcm_alaw_open(snd_pcm_t **pcmp, const char *name,
SNDERR("slave is not defined");
return -EINVAL;
}
err = snd_pcm_slave_conf(slave, &sconf, 1,
err = snd_pcm_slave_conf(root, slave, &sconf, &args, 1,
SND_PCM_HW_PARAM_FORMAT, 1, &sformat);
if (err < 0)
return err;
@ -454,7 +455,7 @@ int _snd_pcm_alaw_open(snd_pcm_t **pcmp, const char *name,
SNDERR("invalid slave format");
return -EINVAL;
}
err = snd_pcm_open_slave(&spcm, sconf, stream, mode);
err = snd_pcm_open_slave(&spcm, root, sconf, args, stream, mode);
if (err < 0)
return err;
err = snd_pcm_alaw_open(pcmp, name, sformat, spcm, 1);

View file

@ -191,13 +191,14 @@ int snd_pcm_copy_open(snd_pcm_t **pcmp, const char *name, snd_pcm_t *slave, int
}
int _snd_pcm_copy_open(snd_pcm_t **pcmp, const char *name,
snd_config_t *conf,
snd_config_t *root, snd_config_t *conf,
snd_pcm_stream_t stream, int mode)
{
snd_config_iterator_t i, next;
int err;
snd_pcm_t *spcm;
snd_config_t *slave = NULL, *sconf;
const char *args;
snd_config_for_each(i, next, conf) {
snd_config_t *n = snd_config_iterator_entry(i);
const char *id = snd_config_get_id(n);
@ -214,10 +215,10 @@ int _snd_pcm_copy_open(snd_pcm_t **pcmp, const char *name,
SNDERR("slave is not defined");
return -EINVAL;
}
err = snd_pcm_slave_conf(slave, &sconf, 0);
err = snd_pcm_slave_conf(root, slave, &sconf, &args, 0);
if (err < 0)
return err;
err = snd_pcm_open_slave(&spcm, sconf, stream, mode);
err = snd_pcm_open_slave(&spcm, root, sconf, args, stream, mode);
if (err < 0)
return err;
err = snd_pcm_copy_open(pcmp, name, spcm, 1);

View file

@ -456,7 +456,7 @@ int snd_pcm_file_open(snd_pcm_t **pcmp, const char *name, const char *fname, int
}
int _snd_pcm_file_open(snd_pcm_t **pcmp, const char *name,
snd_config_t *conf,
snd_config_t *root, snd_config_t *conf,
snd_pcm_stream_t stream, int mode)
{
snd_config_iterator_t i, next;
@ -466,6 +466,7 @@ int _snd_pcm_file_open(snd_pcm_t **pcmp, const char *name,
const char *fname = NULL;
const char *format = NULL;
long fd = -1;
const char *args;
snd_config_for_each(i, next, conf) {
snd_config_t *n = snd_config_iterator_entry(i);
const char *id = snd_config_get_id(n);
@ -501,14 +502,14 @@ int _snd_pcm_file_open(snd_pcm_t **pcmp, const char *name,
SNDERR("slave is not defined");
return -EINVAL;
}
err = snd_pcm_slave_conf(slave, &sconf, 0);
err = snd_pcm_slave_conf(root, slave, &sconf, &args, 0);
if (err < 0)
return err;
if (!fname && fd < 0) {
SNDERR("file is not defined");
return -EINVAL;
}
err = snd_pcm_open_slave(&spcm, sconf, stream, mode);
err = snd_pcm_open_slave(&spcm, root, sconf, args, stream, mode);
if (err < 0)
return err;
err = snd_pcm_file_open(pcmp, name, fname, fd, format, spcm, 1);

View file

@ -433,7 +433,7 @@ int snd_pcm_hook_add_conf(snd_pcm_t *pcm, snd_config_t *conf)
}
int _snd_pcm_hooks_open(snd_pcm_t **pcmp, const char *name,
snd_config_t *conf,
snd_config_t *root, snd_config_t *conf,
snd_pcm_stream_t stream, int mode)
{
snd_config_iterator_t i, next;
@ -441,6 +441,7 @@ int _snd_pcm_hooks_open(snd_pcm_t **pcmp, const char *name,
snd_pcm_t *spcm;
snd_config_t *slave = NULL, *sconf;
snd_config_t *hooks = NULL;
const char *args;
snd_config_for_each(i, next, conf) {
snd_config_t *n = snd_config_iterator_entry(i);
const char *id = snd_config_get_id(n);
@ -465,10 +466,10 @@ int _snd_pcm_hooks_open(snd_pcm_t **pcmp, const char *name,
SNDERR("slave is not defined");
return -EINVAL;
}
err = snd_pcm_slave_conf(slave, &sconf, 0);
err = snd_pcm_slave_conf(root, slave, &sconf, &args, 0);
if (err < 0)
return err;
err = snd_pcm_open_slave(&spcm, sconf, stream, mode);
err = snd_pcm_open_slave(&spcm, root, sconf, args, stream, mode);
if (err < 0)
return err;
err = snd_pcm_hooks_open(pcmp, name, spcm, 1);
@ -513,6 +514,17 @@ void *snd_pcm_hook_get_private(snd_pcm_hook_t *hook)
return hook->private_data;
}
/**
* \brief Set callback function private data for a PCM hook
* \param hook PCM hook handle
* \param private_data The private data value
*/
void snd_pcm_hook_set_private(snd_pcm_hook_t *hook, void *private_data)
{
assert(hook);
hook->private_data = private_data;
}
/**
* \brief Add a PCM hook at end of hooks chain
* \param hookp Returned PCM hook handle
@ -561,578 +573,56 @@ int snd_pcm_hook_remove(snd_pcm_hook_t *hook)
return 0;
}
typedef struct {
unsigned int lock: 1;
unsigned int preserve: 1;
snd_ctl_elem_id_t *id;
snd_ctl_elem_info_t *info;
snd_ctl_elem_value_t *val;
snd_ctl_elem_value_t *mask;
snd_ctl_elem_value_t *old;
struct list_head list;
} snd_pcm_hook_ctl_elem_t;
typedef struct {
snd_ctl_t *ctl;
struct list_head elems;
} snd_pcm_hook_ctl_elems_t;
static int free_elems(snd_pcm_hook_ctl_elems_t *h)
{
int err;
while (!list_empty(&h->elems)) {
snd_pcm_hook_ctl_elem_t *elem = list_entry(h->elems.next, snd_pcm_hook_ctl_elem_t, list);
snd_ctl_elem_id_free(elem->id);
snd_ctl_elem_info_free(elem->info);
snd_ctl_elem_value_free(elem->val);
snd_ctl_elem_value_free(elem->mask);
snd_ctl_elem_value_free(elem->old);
list_del(&elem->list);
free(elem);
}
err = snd_ctl_close(h->ctl);
if (err < 0)
return err;
free(h);
return 0;
}
/*
*
*/
static int snd_pcm_hook_ctl_elems_hw_params(snd_pcm_hook_t *hook)
{
snd_pcm_hook_ctl_elems_t *h = snd_pcm_hook_get_private(hook);
struct list_head *pos;
int err;
unsigned int k;
list_for_each(pos, &h->elems) {
snd_pcm_hook_ctl_elem_t *elem = list_entry(pos, snd_pcm_hook_ctl_elem_t, list);
unsigned int count;
snd_ctl_elem_type_t type;
if (elem->lock) {
err = snd_ctl_elem_lock(h->ctl, elem->id);
if (err < 0) {
SNDERR("Cannot lock ctl elem");
return err;
}
}
err = snd_ctl_elem_read(h->ctl, elem->old);
if (err < 0) {
SNDERR("Cannot read ctl elem");
return err;
}
count = snd_ctl_elem_info_get_count(elem->info);
type = snd_ctl_elem_info_get_type(elem->info);
switch (type) {
case SND_CTL_ELEM_TYPE_BOOLEAN:
for (k = 0; k < count; ++k) {
int old, val, mask;
old = snd_ctl_elem_value_get_boolean(elem->old, k);
mask = snd_ctl_elem_value_get_boolean(elem->mask, k);
old &= ~mask;
if (old) {
val = snd_ctl_elem_value_get_boolean(elem->val, k);
val |= old;
snd_ctl_elem_value_set_boolean(elem->val, k, val);
}
}
break;
case SND_CTL_ELEM_TYPE_INTEGER:
for (k = 0; k < count; ++k) {
long old, val, mask;
old = snd_ctl_elem_value_get_integer(elem->old, k);
mask = snd_ctl_elem_value_get_integer(elem->mask, k);
old &= ~mask;
if (old) {
val = snd_ctl_elem_value_get_integer(elem->val, k);
val |= old;
snd_ctl_elem_value_set_integer(elem->val, k, val);
}
}
break;
case SND_CTL_ELEM_TYPE_ENUMERATED:
for (k = 0; k < count; ++k) {
unsigned int old, val, mask;
old = snd_ctl_elem_value_get_enumerated(elem->old, k);
mask = snd_ctl_elem_value_get_enumerated(elem->mask, k);
old &= ~mask;
if (old) {
val = snd_ctl_elem_value_get_enumerated(elem->val, k);
val |= old;
snd_ctl_elem_value_set_enumerated(elem->val, k, val);
}
}
break;
case SND_CTL_ELEM_TYPE_IEC958:
count = sizeof(snd_aes_iec958_t);
/* Fall through */
case SND_CTL_ELEM_TYPE_BYTES:
for (k = 0; k < count; ++k) {
unsigned char old, val, mask;
old = snd_ctl_elem_value_get_byte(elem->old, k);
mask = snd_ctl_elem_value_get_byte(elem->mask, k);
old &= ~mask;
if (old) {
val = snd_ctl_elem_value_get_byte(elem->val, k);
val |= old;
snd_ctl_elem_value_set_byte(elem->val, k, val);
}
}
break;
default:
assert(0);
break;
}
err = snd_ctl_elem_write(h->ctl, elem->val);
if (err < 0) {
SNDERR("Cannot write ctl elem");
return err;
}
}
return 0;
snd_sctl_t *h = snd_pcm_hook_get_private(hook);
return snd_sctl_install(h);
}
static int snd_pcm_hook_ctl_elems_hw_free(snd_pcm_hook_t *hook)
{
snd_pcm_hook_ctl_elems_t *h = snd_pcm_hook_get_private(hook);
struct list_head *pos;
int err;
list_for_each(pos, &h->elems) {
snd_pcm_hook_ctl_elem_t *elem = list_entry(pos, snd_pcm_hook_ctl_elem_t, list);
if (elem->lock) {
err = snd_ctl_elem_unlock(h->ctl, elem->id);
if (err < 0) {
SNDERR("Cannot unlock ctl elem");
return err;
}
}
if (elem->preserve) {
err = snd_ctl_elem_write(h->ctl, elem->old);
if (err < 0) {
SNDERR("Cannot restore ctl elem");
return err;
}
}
}
return 0;
snd_sctl_t *h = snd_pcm_hook_get_private(hook);
return snd_sctl_remove(h);
}
static int snd_pcm_hook_ctl_elems_close(snd_pcm_hook_t *hook)
{
snd_pcm_hook_ctl_elems_t *h = snd_pcm_hook_get_private(hook);
return free_elems(h);
}
int snd_config_get_iface(snd_config_t *conf)
{
long v;
const char *str;
int err;
snd_ctl_elem_iface_t idx;
err = snd_config_get_integer(conf, &v);
if (err >= 0) {
if (v < 0 || v > SND_CTL_ELEM_IFACE_LAST) {
_invalid_value:
SNDERR("Invalid value for %s", snd_config_get_id(conf));
return -EINVAL;
}
return v;
}
err = snd_config_get_string(conf, &str);
if (err < 0) {
SNDERR("Invalid type for %s", snd_config_get_id(conf));
return -EINVAL;
}
for (idx = 0; idx <= SND_CTL_ELEM_IFACE_LAST; idx++) {
if (strcasecmp(snd_ctl_elem_iface_name(idx), str) == 0)
return idx;
}
goto _invalid_value;
}
int snd_config_get_bool(snd_config_t *conf)
{
long v;
const char *str;
int err;
unsigned int k;
static struct {
const char *str;
int val;
} b[] = {
{ "false", 0 },
{ "true", 1 },
{ "no", 0 },
{ "yes", 1 },
{ "off", 0 },
{ "on", 1 },
};
err = snd_config_get_integer(conf, &v);
if (err >= 0) {
if (v < 0 || v > 1) {
_invalid_value:
SNDERR("Invalid value for %s", snd_config_get_id(conf));
return -EINVAL;
}
return v;
}
err = snd_config_get_string(conf, &str);
if (err < 0) {
SNDERR("Invalid type for %s", snd_config_get_id(conf));
return -EINVAL;
}
for (k = 0; k < sizeof(b) / sizeof(*b); k++) {
if (strcasecmp(b[k].str, str) == 0)
return b[k].val;
}
goto _invalid_value;
}
int snd_config_get_ctl_elem_enumerated(snd_config_t *n, snd_ctl_t *ctl,
snd_ctl_elem_info_t *info)
{
const char *str;
long val;
unsigned int idx, items;
switch (snd_enum_to_int(snd_config_get_type(n))) {
case SND_CONFIG_TYPE_INTEGER:
snd_config_get_integer(n, &val);
return val;
case SND_CONFIG_TYPE_STRING:
snd_config_get_string(n, &str);
break;
default:
return -1;
}
items = snd_ctl_elem_info_get_items(info);
for (idx = 0; idx < items; idx++) {
int err;
snd_ctl_elem_info_set_item(info, idx);
err = snd_ctl_elem_info(ctl, info);
if (err < 0) {
SNDERR("Cannot obtain info for CTL elem");
return err;
}
if (strcmp(str, snd_ctl_elem_info_get_item_name(info)) == 0)
return idx;
}
return -1;
}
int snd_config_get_ctl_elem_value(snd_config_t *conf,
snd_ctl_t *ctl,
snd_ctl_elem_value_t *val,
snd_ctl_elem_value_t *mask,
snd_ctl_elem_info_t *info)
{
int err;
snd_config_iterator_t i, next;
snd_ctl_elem_id_t *id;
snd_ctl_elem_type_t type;
unsigned int count;
long v;
long idx;
snd_ctl_elem_id_alloca(&id);
snd_ctl_elem_value_get_id(val, id);
count = snd_ctl_elem_info_get_count(info);
type = snd_ctl_elem_info_get_type(info);
if (count == 1) {
switch (snd_enum_to_int(type)) {
case SND_CTL_ELEM_TYPE_BOOLEAN:
v = snd_config_get_bool(conf);
if (v >= 0) {
snd_ctl_elem_value_set_boolean(val, 0, v);
if (mask)
snd_ctl_elem_value_set_boolean(mask, 0, 1);
return 0;
}
break;
case SND_CTL_ELEM_TYPE_INTEGER:
err = snd_config_get_integer(conf, &v);
if (err == 0) {
snd_ctl_elem_value_set_integer(val, 0, v);
if (mask)
snd_ctl_elem_value_set_integer(mask, 0, ~0L);
return 0;
}
break;
case SND_CTL_ELEM_TYPE_ENUMERATED:
v = snd_config_get_ctl_elem_enumerated(conf, ctl, info);
if (v >= 0) {
snd_ctl_elem_value_set_enumerated(val, 0, v);
if (mask)
snd_ctl_elem_value_set_enumerated(mask, 0, ~0);
return 0;
}
break;
case SND_CTL_ELEM_TYPE_BYTES:
case SND_CTL_ELEM_TYPE_IEC958:
break;
default:
SNDERR("Unknow control type: %d", snd_enum_to_int(type));
return -EINVAL;
}
}
switch (snd_enum_to_int(type)) {
case SND_CTL_ELEM_TYPE_IEC958:
count = sizeof(snd_aes_iec958_t);
/* Fall through */
case SND_CTL_ELEM_TYPE_BYTES:
{
const char *buf;
err = snd_config_get_string(conf, &buf);
if (err >= 0) {
int c1 = 0;
unsigned int len = strlen(buf);
unsigned int idx = 0;
if (len % 2 != 0 || len > count * 2) {
_bad_content:
SNDERR("bad value content\n");
return -EINVAL;
}
while (*buf) {
int c = *buf++;
if (c >= '0' && c <= '9')
c -= '0';
else if (c >= 'a' && c <= 'f')
c = c - 'a' + 10;
else if (c >= 'A' && c <= 'F')
c = c - 'A' + 10;
else {
goto _bad_content;
}
if (idx % 2 == 1) {
snd_ctl_elem_value_set_byte(val, idx / 2, c1 << 4 | c);
if (mask)
snd_ctl_elem_value_set_byte(mask, idx / 2, 0xff);
} else
c1 = c;
idx++;
}
return 0;
}
}
default:
break;
}
if (snd_config_get_type(conf) != SND_CONFIG_TYPE_COMPOUND) {
SNDERR("bad value type");
return -EINVAL;
}
snd_config_for_each(i, next, conf) {
snd_config_t *n = snd_config_iterator_entry(i);
err = safe_strtol(snd_config_get_id(n), &idx);
if (err < 0 || idx < 0 || (unsigned int) idx >= count) {
SNDERR("bad value index");
return -EINVAL;
}
switch (snd_enum_to_int(type)) {
case SND_CTL_ELEM_TYPE_BOOLEAN:
v = snd_config_get_bool(n);
if (v < 0)
goto _bad_content;
snd_ctl_elem_value_set_boolean(val, idx, v);
if (mask)
snd_ctl_elem_value_set_boolean(mask, idx, 1);
break;
case SND_CTL_ELEM_TYPE_INTEGER:
err = snd_config_get_integer(n, &v);
if (err < 0)
goto _bad_content;
snd_ctl_elem_value_set_integer(val, idx, v);
if (mask)
snd_ctl_elem_value_set_integer(mask, idx, ~0L);
break;
case SND_CTL_ELEM_TYPE_ENUMERATED:
v = snd_config_get_ctl_elem_enumerated(n, ctl, info);
if (v < 0)
goto _bad_content;
snd_ctl_elem_value_set_enumerated(val, idx, v);
if (mask)
snd_ctl_elem_value_set_enumerated(mask, idx, ~0);
break;
case SND_CTL_ELEM_TYPE_BYTES:
case SND_CTL_ELEM_TYPE_IEC958:
err = snd_config_get_integer(n, &v);
if (err < 0 || v < 0 || v > 255)
goto _bad_content;
snd_ctl_elem_value_set_byte(val, idx, v);
if (mask)
snd_ctl_elem_value_set_byte(mask, idx, 0xff);
break;
default:
break;
}
}
return 0;
}
static int add_elem(snd_pcm_hook_ctl_elems_t *h, snd_config_t *conf, snd_pcm_info_t *info)
{
snd_config_iterator_t i, next;
int iface = SND_CTL_ELEM_IFACE_PCM;
const char *name = NULL;
long index = 0;
long device = -1;
long subdevice = -1;
int lock = 0;
int preserve = 0;
snd_config_t *value = NULL, *mask = NULL;
snd_pcm_hook_ctl_elem_t *elem;
int err;
snd_config_for_each(i, next, conf) {
snd_config_t *n = snd_config_iterator_entry(i);
const char *id = snd_config_get_id(n);
if (strcmp(id, "comment") == 0)
continue;
if (strcmp(id, "iface") == 0) {
iface = snd_config_get_iface(n);
if (iface < 0)
return iface;
continue;
}
if (strcmp(id, "name") == 0) {
err = snd_config_get_string(n, &name);
if (err < 0) {
_invalid_type:
SNDERR("Invalid type for %s", id);
return err;
}
continue;
}
if (strcmp(id, "index") == 0) {
err = snd_config_get_integer(n, &index);
if (err < 0)
goto _invalid_type;
continue;
}
if (strcmp(id, "device") == 0) {
err = snd_config_get_integer(n, &device);
if (err < 0)
goto _invalid_type;
continue;
}
if (strcmp(id, "subdevice") == 0) {
err = snd_config_get_integer(n, &subdevice);
if (err < 0)
goto _invalid_type;
continue;
}
if (strcmp(id, "lock") == 0) {
lock = snd_config_get_bool(n);
if (lock < 0) {
err = lock;
_invalid_value:
SNDERR("Invalid value for %s", id);
return err;
}
continue;
}
if (strcmp(id, "preserve") == 0) {
preserve = snd_config_get_bool(n);
if (preserve < 0) {
err = preserve;
goto _invalid_value;
}
continue;
}
if (strcmp(id, "value") == 0) {
value = n;
continue;
}
if (strcmp(id, "mask") == 0) {
mask = n;
continue;
}
SNDERR("Unknown field %s", id);
return -EINVAL;
}
if (!name) {
SNDERR("Missing control name");
return -EINVAL;
}
if (!value) {
SNDERR("Missing control value");
return -EINVAL;
}
if (device < 0) {
if (iface == SND_CTL_ELEM_IFACE_PCM)
device = snd_pcm_info_get_device(info);
else
device = 0;
}
if (subdevice < 0) {
if (iface == SND_CTL_ELEM_IFACE_PCM)
subdevice = snd_pcm_info_get_subdevice(info);
else
subdevice = 0;
}
elem = calloc(1, sizeof(*elem));
if (!elem)
return -ENOMEM;
err = snd_ctl_elem_id_malloc(&elem->id);
if (err < 0)
goto _err;
err = snd_ctl_elem_info_malloc(&elem->info);
if (err < 0)
goto _err;
err = snd_ctl_elem_value_malloc(&elem->val);
if (err < 0)
goto _err;
err = snd_ctl_elem_value_malloc(&elem->mask);
if (err < 0)
goto _err;
err = snd_ctl_elem_value_malloc(&elem->old);
if (err < 0)
goto _err;
elem->lock = lock;
elem->preserve = preserve;
snd_ctl_elem_id_set_interface(elem->id, iface);
snd_ctl_elem_id_set_name(elem->id, name);
snd_ctl_elem_id_set_index(elem->id, index);
snd_ctl_elem_id_set_device(elem->id, device);
snd_ctl_elem_id_set_subdevice(elem->id, subdevice);
snd_ctl_elem_info_set_id(elem->info, elem->id);
err = snd_ctl_elem_info(h->ctl, elem->info);
if (err < 0) {
SNDERR("Cannot obtain info for CTL elem");
goto _err;
}
snd_ctl_elem_value_set_id(elem->val, elem->id);
snd_ctl_elem_value_set_id(elem->old, elem->id);
if (mask) {
err = snd_config_get_ctl_elem_value(value, h->ctl, elem->val, NULL, elem->info);
if (err < 0)
goto _err;
err = snd_config_get_ctl_elem_value(mask, h->ctl, elem->mask, NULL, elem->info);
if (err < 0)
goto _err;
} else {
err = snd_config_get_ctl_elem_value(value, h->ctl, elem->val, elem->mask, elem->info);
if (err < 0)
goto _err;
}
err = snd_config_get_ctl_elem_value(value, h->ctl, elem->val, elem->mask, elem->info);
if (err < 0)
goto _err;
list_add_tail(&elem->list, &h->elems);
return 0;
_err:
if (elem->id)
snd_ctl_elem_id_free(elem->id);
if (elem->info)
snd_ctl_elem_info_free(elem->info);
if (elem->val)
snd_ctl_elem_value_free(elem->val);
if (elem->mask)
snd_ctl_elem_value_free(elem->mask);
if (elem->old)
snd_ctl_elem_value_free(elem->old);
free(elem);
snd_sctl_t *h = snd_pcm_hook_get_private(hook);
int err = snd_sctl_free(h);
snd_pcm_hook_set_private(hook, NULL);
return err;
}
static int snd_pcm_hook_ctl_elems_replace(const char *what, char **dst, void *private_data)
{
snd_pcm_t *pcm = private_data;
snd_pcm_info_t *info;
char str[12];
long val;
int err;
snd_pcm_info_alloca(&info);
err = snd_pcm_info(pcm, info);
if (err < 0)
return err;
if (!strcmp(what, "card")) {
val = snd_pcm_info_get_card(info);
} else if (!strcmp(what, "device")) {
val = snd_pcm_info_get_device(info);
} else if (!strcmp(what, "subdevice")) {
val = snd_pcm_info_get_subdevice(info);
} else
return 0; /* empty string */
snprintf(str, sizeof(str), "%li", val);
str[sizeof(str)-1] = '\0';
*dst = strdup(str);
return 0;
}
int _snd_pcm_hook_ctl_elems_install(snd_pcm_t *pcm, snd_config_t *conf)
{
int err;
@ -1140,8 +630,7 @@ int _snd_pcm_hook_ctl_elems_install(snd_pcm_t *pcm, snd_config_t *conf)
snd_pcm_info_t *info;
char ctl_name[16];
snd_ctl_t *ctl;
snd_pcm_hook_ctl_elems_t *h;
snd_config_iterator_t i, next;
snd_sctl_t *sctl;
snd_pcm_hook_t *h_hw_params = NULL, *h_hw_free = NULL, *h_close = NULL;
assert(conf);
assert(snd_config_get_type(conf) == SND_CONFIG_TYPE_COMPOUND);
@ -1160,31 +649,19 @@ int _snd_pcm_hook_ctl_elems_install(snd_pcm_t *pcm, snd_config_t *conf)
SNDERR("Cannot open CTL %s", ctl_name);
return err;
}
h = calloc(1, sizeof(*h));
if (!h) {
snd_ctl_close(ctl);
err = snd_sctl_build(&sctl, ctl, conf, snd_pcm_hook_ctl_elems_replace, pcm, 0);
if (err < 0)
return -ENOMEM;
}
h->ctl = ctl;
INIT_LIST_HEAD(&h->elems);
snd_config_for_each(i, next, conf) {
snd_config_t *n = snd_config_iterator_entry(i);
err = add_elem(h, n, info);
if (err < 0) {
free_elems(h);
return err;
}
}
err = snd_pcm_hook_add(&h_hw_params, pcm, SND_PCM_HOOK_TYPE_HW_PARAMS,
snd_pcm_hook_ctl_elems_hw_params, h);
snd_pcm_hook_ctl_elems_hw_params, sctl);
if (err < 0)
goto _err;
err = snd_pcm_hook_add(&h_hw_free, pcm, SND_PCM_HOOK_TYPE_HW_FREE,
snd_pcm_hook_ctl_elems_hw_free, h);
snd_pcm_hook_ctl_elems_hw_free, sctl);
if (err < 0)
goto _err;
err = snd_pcm_hook_add(&h_close, pcm, SND_PCM_HOOK_TYPE_CLOSE,
snd_pcm_hook_ctl_elems_close, h);
snd_pcm_hook_ctl_elems_close, sctl);
if (err < 0)
goto _err;
return 0;
@ -1195,7 +672,6 @@ int _snd_pcm_hook_ctl_elems_install(snd_pcm_t *pcm, snd_config_t *conf)
snd_pcm_hook_remove(h_hw_free);
if (h_close)
snd_pcm_hook_remove(h_close);
free_elems(h);
snd_sctl_free(sctl);
return err;
}

View file

@ -659,7 +659,8 @@ int snd_pcm_hw_open(snd_pcm_t **pcmp, const char *name, int card, int device, in
return 0;
}
int _snd_pcm_hw_open(snd_pcm_t **pcmp, const char *name, snd_config_t *conf,
int _snd_pcm_hw_open(snd_pcm_t **pcmp, const char *name,
snd_config_t *root ATTRIBUTE_UNUSED, snd_config_t *conf,
snd_pcm_stream_t stream, int mode)
{
snd_config_iterator_t i, next;

View file

@ -326,7 +326,7 @@ int snd_pcm_linear_open(snd_pcm_t **pcmp, const char *name, snd_pcm_format_t sfo
}
int _snd_pcm_linear_open(snd_pcm_t **pcmp, const char *name,
snd_config_t *conf,
snd_config_t *root, snd_config_t *conf,
snd_pcm_stream_t stream, int mode)
{
snd_config_iterator_t i, next;
@ -334,6 +334,7 @@ int _snd_pcm_linear_open(snd_pcm_t **pcmp, const char *name,
snd_pcm_t *spcm;
snd_config_t *slave = NULL, *sconf;
snd_pcm_format_t sformat;
const char *args;
snd_config_for_each(i, next, conf) {
snd_config_t *n = snd_config_iterator_entry(i);
const char *id = snd_config_get_id(n);
@ -350,7 +351,7 @@ int _snd_pcm_linear_open(snd_pcm_t **pcmp, const char *name,
SNDERR("slave is not defined");
return -EINVAL;
}
err = snd_pcm_slave_conf(slave, &sconf, 1,
err = snd_pcm_slave_conf(root, slave, &sconf, &args, 1,
SND_PCM_HW_PARAM_FORMAT, 1, &sformat);
if (err < 0)
return err;
@ -358,7 +359,7 @@ int _snd_pcm_linear_open(snd_pcm_t **pcmp, const char *name,
SNDERR("slave format is not linear");
return -EINVAL;
}
err = snd_pcm_open_slave(&spcm, sconf, stream, mode);
err = snd_pcm_open_slave(&spcm, root, sconf, args, stream, mode);
if (err < 0)
return err;
err = snd_pcm_linear_open(pcmp, name, sformat, spcm, 1);

View file

@ -527,11 +527,11 @@ int snd_pcm_hw_strategy_simple_choices(snd_pcm_hw_strategy_t *strategy, int orde
snd_pcm_hw_strategy_simple_choices_list_t *choices);
#endif
int snd_pcm_slave_conf(snd_config_t *conf, snd_config_t **pcm_conf,
unsigned int count, ...);
int snd_pcm_slave_conf(snd_config_t *root, snd_config_t *conf, snd_config_t **pcm_conf,
const char **args, unsigned int count, ...);
int snd_pcm_open_slave(snd_pcm_t **pcmp, snd_config_t *conf,
snd_pcm_stream_t stream, int mode);
int snd_pcm_open_slave(snd_pcm_t **pcmp, snd_config_t *root, snd_config_t *conf,
const char *args, snd_pcm_stream_t stream, int mode);
int snd_pcm_conf_generic_id(const char *id);
#define SND_PCM_HW_PARBIT_ACCESS (1U << SND_PCM_HW_PARAM_ACCESS)
@ -575,5 +575,3 @@ int snd_pcm_conf_generic_id(const char *id);
(1U << SND_PCM_FORMAT_S32_BE) | \
(1U << SND_PCM_FORMAT_U32_LE) | \
(1U << SND_PCM_FORMAT_U32_BE))
int safe_strtol(const char *str, long *val);

View file

@ -734,7 +734,7 @@ static int snd_pcm_meter_add_scope_conf(snd_pcm_t *pcm, const char *name,
int _snd_pcm_meter_open(snd_pcm_t **pcmp, const char *name,
snd_config_t *conf,
snd_config_t *root, snd_config_t *conf,
snd_pcm_stream_t stream, int mode)
{
snd_config_iterator_t i, next;
@ -743,6 +743,7 @@ int _snd_pcm_meter_open(snd_pcm_t **pcmp, const char *name,
snd_config_t *slave = NULL, *sconf;
long frequency = -1;
snd_config_t *scopes = NULL;
const char *args;
snd_config_for_each(i, next, conf) {
snd_config_t *n = snd_config_iterator_entry(i);
const char *id = snd_config_get_id(n);
@ -775,10 +776,10 @@ int _snd_pcm_meter_open(snd_pcm_t **pcmp, const char *name,
SNDERR("slave is not defined");
return -EINVAL;
}
err = snd_pcm_slave_conf(slave, &sconf, 0);
err = snd_pcm_slave_conf(root, slave, &sconf, &args, 0);
if (err < 0)
return err;
err = snd_pcm_open_slave(&spcm, sconf, stream, mode);
err = snd_pcm_open_slave(&spcm, root, sconf, args, stream, mode);
if (err < 0)
return err;
err = snd_pcm_meter_open(pcmp, name, frequency > 0 ? (unsigned int) frequency : FREQUENCY, spcm, 1);

View file

@ -436,14 +436,15 @@ int snd_pcm_mulaw_open(snd_pcm_t **pcmp, const char *name, snd_pcm_format_t sfor
}
int _snd_pcm_mulaw_open(snd_pcm_t **pcmp, const char *name,
snd_config_t *conf,
snd_pcm_stream_t stream, int mode)
snd_config_t *root, snd_config_t *conf,
snd_pcm_stream_t stream, int mode)
{
snd_config_iterator_t i, next;
int err;
snd_pcm_t *spcm;
snd_config_t *slave = NULL, *sconf;
snd_pcm_format_t sformat;
const char *args;
snd_config_for_each(i, next, conf) {
snd_config_t *n = snd_config_iterator_entry(i);
const char *id = snd_config_get_id(n);
@ -460,7 +461,7 @@ int _snd_pcm_mulaw_open(snd_pcm_t **pcmp, const char *name,
SNDERR("slave is not defined");
return -EINVAL;
}
err = snd_pcm_slave_conf(slave, &sconf, 1,
err = snd_pcm_slave_conf(root, slave, &sconf, &args, 1,
SND_PCM_HW_PARAM_FORMAT, 1, &sformat);
if (err < 0)
return err;
@ -469,7 +470,7 @@ int _snd_pcm_mulaw_open(snd_pcm_t **pcmp, const char *name,
SNDERR("invalid slave format");
return -EINVAL;
}
err = snd_pcm_open_slave(&spcm, sconf, stream, mode);
err = snd_pcm_open_slave(&spcm, root, sconf, args, stream, mode);
if (err < 0)
return err;
err = snd_pcm_mulaw_open(pcmp, name, sformat, spcm, 1);

View file

@ -40,6 +40,7 @@ typedef struct {
typedef struct {
unsigned int slaves_count;
unsigned int master_slave;
snd_pcm_multi_slave_t *slaves;
unsigned int channels_count;
snd_pcm_multi_channel_t *channels;
@ -575,7 +576,7 @@ snd_pcm_fast_ops_t snd_pcm_multi_fast_ops = {
};
int snd_pcm_multi_open(snd_pcm_t **pcmp, const char *name,
unsigned int slaves_count,
unsigned int slaves_count, unsigned int master_slave,
snd_pcm_t **slaves_pcm, unsigned int *schannels_count,
unsigned int channels_count,
int *sidxs, unsigned int *schannels,
@ -590,6 +591,7 @@ int snd_pcm_multi_open(snd_pcm_t **pcmp, const char *name,
assert(pcmp);
assert(slaves_count > 0 && slaves_pcm && schannels_count);
assert(channels_count > 0 && sidxs && schannels);
assert(master_slave < slaves_count);
multi = calloc(1, sizeof(snd_pcm_multi_t));
if (!multi) {
@ -599,6 +601,7 @@ int snd_pcm_multi_open(snd_pcm_t **pcmp, const char *name,
stream = slaves_pcm[0]->stream;
multi->slaves_count = slaves_count;
multi->master_slave = master_slave;
multi->slaves = calloc(slaves_count, sizeof(*multi->slaves));
multi->channels_count = channels_count;
multi->channels = calloc(channels_count, sizeof(*multi->channels));
@ -638,14 +641,15 @@ int snd_pcm_multi_open(snd_pcm_t **pcmp, const char *name,
pcm->fast_ops = &snd_pcm_multi_fast_ops;
pcm->fast_op_arg = pcm;
pcm->private_data = multi;
pcm->poll_fd = multi->slaves[0].pcm->poll_fd;
pcm->hw_ptr = multi->slaves[0].pcm->hw_ptr;
pcm->appl_ptr = multi->slaves[0].pcm->appl_ptr;
pcm->poll_fd = multi->slaves[master_slave].pcm->poll_fd;
pcm->hw_ptr = multi->slaves[master_slave].pcm->hw_ptr;
pcm->appl_ptr = multi->slaves[master_slave].pcm->appl_ptr;
*pcmp = pcm;
return 0;
}
int _snd_pcm_multi_open(snd_pcm_t **pcmp, const char *name, snd_config_t *conf,
int _snd_pcm_multi_open(snd_pcm_t **pcmp, const char *name,
snd_config_t *root, snd_config_t *conf,
snd_pcm_stream_t stream, int mode)
{
snd_config_iterator_t i, inext, j, jnext;
@ -655,11 +659,13 @@ int _snd_pcm_multi_open(snd_pcm_t **pcmp, const char *name, snd_config_t *conf,
unsigned int idx;
const char **slaves_id = NULL;
snd_config_t **slaves_conf = NULL;
const char **slaves_args = NULL;
snd_pcm_t **slaves_pcm = NULL;
unsigned int *slaves_channels = NULL;
int *channels_sidx = NULL;
unsigned int *channels_schannel = NULL;
unsigned int slaves_count = 0;
long master_slave = 0;
unsigned int channels_count = 0;
snd_config_for_each(i, inext, conf) {
snd_config_t *n = snd_config_iterator_entry(i);
@ -682,6 +688,13 @@ int _snd_pcm_multi_open(snd_pcm_t **pcmp, const char *name, snd_config_t *conf,
bindings = n;
continue;
}
if (strcmp(id, "master") == 0) {
if (snd_config_get_integer(n, &((long)master_slave)) < 0) {
SNDERR("Invalid type for %s", id);
return -EINVAL;
}
continue;
}
SNDERR("Unknown field %s", id);
return -EINVAL;
}
@ -696,6 +709,10 @@ int _snd_pcm_multi_open(snd_pcm_t **pcmp, const char *name, snd_config_t *conf,
snd_config_for_each(i, inext, slaves) {
++slaves_count;
}
if (master_slave < 0 || master_slave >= (long)slaves_count) {
SNDERR("Master slave is out of range (0-%u)\n", slaves_count-1);
return -EINVAL;
}
snd_config_for_each(i, inext, bindings) {
long cchannel;
snd_config_t *m = snd_config_iterator_entry(i);
@ -714,6 +731,7 @@ int _snd_pcm_multi_open(snd_pcm_t **pcmp, const char *name, snd_config_t *conf,
}
slaves_id = calloc(slaves_count, sizeof(*slaves_id));
slaves_conf = calloc(slaves_count, sizeof(*slaves_conf));
slaves_args = calloc(slaves_count, sizeof(*slaves_args));
slaves_pcm = calloc(slaves_count, sizeof(*slaves_pcm));
slaves_channels = calloc(slaves_count, sizeof(*slaves_channels));
channels_sidx = calloc(channels_count, sizeof(*channels_sidx));
@ -726,7 +744,7 @@ int _snd_pcm_multi_open(snd_pcm_t **pcmp, const char *name, snd_config_t *conf,
snd_config_t *m = snd_config_iterator_entry(i);
int channels;
slaves_id[idx] = snd_config_get_id(m);
err = snd_pcm_slave_conf(m, &slaves_conf[idx], 1,
err = snd_pcm_slave_conf(root, m, &slaves_conf[idx], &slaves_args[idx], 1,
SND_PCM_HW_PARAM_CHANNELS, 1, &channels);
if (err < 0)
goto _free;
@ -800,12 +818,12 @@ int _snd_pcm_multi_open(snd_pcm_t **pcmp, const char *name, snd_config_t *conf,
}
for (idx = 0; idx < slaves_count; ++idx) {
err = snd_pcm_open_slave(&slaves_pcm[idx], slaves_conf[idx], stream, mode);
err = snd_pcm_open_slave(&slaves_pcm[idx], root, slaves_conf[idx], slaves_args[idx], stream, mode);
if (err < 0)
goto _free;
}
err = snd_pcm_multi_open(pcmp, name, slaves_count, slaves_pcm,
slaves_channels,
err = snd_pcm_multi_open(pcmp, name, slaves_count, master_slave,
slaves_pcm, slaves_channels,
channels_count,
channels_sidx, channels_schannel,
1);
@ -818,6 +836,8 @@ _free:
}
if (slaves_conf)
free(slaves_conf);
if (slaves_args)
free(slaves_args);
if (slaves_pcm)
free(slaves_pcm);
if (slaves_channels)

View file

@ -711,7 +711,7 @@ int snd_pcm_plug_open_hw(snd_pcm_t **pcmp, const char *name, int card, int devic
#define MAX_CHANNELS 32
int _snd_pcm_plug_open(snd_pcm_t **pcmp, const char *name,
snd_config_t *conf,
snd_config_t *root, snd_config_t *conf,
snd_pcm_stream_t stream, int mode)
{
snd_config_iterator_t i, next;
@ -721,6 +721,7 @@ int _snd_pcm_plug_open(snd_pcm_t **pcmp, const char *name,
snd_config_t *tt = NULL;
snd_pcm_route_ttable_entry_t *ttable = NULL;
unsigned int cused, sused;
const char *args;
snd_config_for_each(i, next, conf) {
snd_config_t *n = snd_config_iterator_entry(i);
const char *id = snd_config_get_id(n);
@ -745,7 +746,7 @@ int _snd_pcm_plug_open(snd_pcm_t **pcmp, const char *name,
SNDERR("slave is not defined");
return -EINVAL;
}
err = snd_pcm_slave_conf(slave, &sconf, 0);
err = snd_pcm_slave_conf(root, slave, &sconf, &args, 0);
if (err < 0)
return err;
if (tt) {
@ -756,7 +757,7 @@ int _snd_pcm_plug_open(snd_pcm_t **pcmp, const char *name,
return err;
}
err = snd_pcm_open_slave(&spcm, sconf, stream, mode);
err = snd_pcm_open_slave(&spcm, root, sconf, args, stream, mode);
if (err < 0)
return err;
err = snd_pcm_plug_open(pcmp, name, ttable, MAX_CHANNELS, cused, sused, spcm, 1);

View file

@ -535,8 +535,8 @@ int snd_pcm_rate_open(snd_pcm_t **pcmp, const char *name, snd_pcm_format_t sform
}
int _snd_pcm_rate_open(snd_pcm_t **pcmp, const char *name,
snd_config_t *conf,
snd_pcm_stream_t stream, int mode)
snd_config_t *root, snd_config_t *conf,
snd_pcm_stream_t stream, int mode)
{
snd_config_iterator_t i, next;
int err;
@ -544,6 +544,7 @@ int _snd_pcm_rate_open(snd_pcm_t **pcmp, const char *name,
snd_config_t *slave = NULL, *sconf;
snd_pcm_format_t sformat = SND_PCM_FORMAT_UNKNOWN;
int srate = -1;
const char *args;
snd_config_for_each(i, next, conf) {
snd_config_t *n = snd_config_iterator_entry(i);
const char *id = snd_config_get_id(n);
@ -560,7 +561,7 @@ int _snd_pcm_rate_open(snd_pcm_t **pcmp, const char *name,
SNDERR("slave is not defined");
return -EINVAL;
}
err = snd_pcm_slave_conf(slave, &sconf, 2,
err = snd_pcm_slave_conf(root, slave, &sconf, &args, 2,
SND_PCM_HW_PARAM_FORMAT, 0, &sformat,
SND_PCM_HW_PARAM_RATE, 1, &srate);
if (err < 0)
@ -570,7 +571,7 @@ int _snd_pcm_rate_open(snd_pcm_t **pcmp, const char *name,
SNDERR("slave format is not linear");
return -EINVAL;
}
err = snd_pcm_open_slave(&spcm, sconf, stream, mode);
err = snd_pcm_open_slave(&spcm, root, sconf, args, stream, mode);
if (err < 0)
return err;
err = snd_pcm_rate_open(pcmp, name,

View file

@ -836,7 +836,7 @@ int snd_pcm_route_load_ttable(snd_config_t *tt, snd_pcm_route_ttable_entry_t *tt
#define MAX_CHANNELS 32
int _snd_pcm_route_open(snd_pcm_t **pcmp, const char *name,
snd_config_t *conf,
snd_config_t *root, snd_config_t *conf,
snd_pcm_stream_t stream, int mode)
{
snd_config_iterator_t i, next;
@ -848,6 +848,7 @@ int _snd_pcm_route_open(snd_pcm_t **pcmp, const char *name,
snd_config_t *tt = NULL;
snd_pcm_route_ttable_entry_t ttable[MAX_CHANNELS*MAX_CHANNELS];
unsigned int cused, sused;
const char *args;
snd_config_for_each(i, next, conf) {
snd_config_t *n = snd_config_iterator_entry(i);
const char *id = snd_config_get_id(n);
@ -876,7 +877,7 @@ int _snd_pcm_route_open(snd_pcm_t **pcmp, const char *name,
SNDERR("ttable is not defined");
return -EINVAL;
}
err = snd_pcm_slave_conf(slave, &sconf, 2,
err = snd_pcm_slave_conf(root, slave, &sconf, &args, 2,
SND_PCM_HW_PARAM_FORMAT, 0, &sformat,
SND_PCM_HW_PARAM_CHANNELS, 0, &schannels);
if (err < 0)
@ -892,7 +893,7 @@ int _snd_pcm_route_open(snd_pcm_t **pcmp, const char *name,
if (err < 0)
return err;
err = snd_pcm_open_slave(&spcm, sconf, stream, mode);
err = snd_pcm_open_slave(&spcm, root, sconf, args, stream, mode);
if (err < 0)
return err;
err = snd_pcm_route_open(pcmp, name, sformat, schannels,

View file

@ -1367,7 +1367,8 @@ int snd_pcm_share_open(snd_pcm_t **pcmp, const char *name, const char *sname,
return 0;
}
int _snd_pcm_share_open(snd_pcm_t **pcmp, const char *name, snd_config_t *conf,
int _snd_pcm_share_open(snd_pcm_t **pcmp, const char *name,
snd_config_t *root, snd_config_t *conf,
snd_pcm_stream_t stream, int mode)
{
snd_config_iterator_t i, next;
@ -1413,7 +1414,7 @@ int _snd_pcm_share_open(snd_pcm_t **pcmp, const char *name, snd_config_t *conf,
SNDERR("slave is not defined");
return -EINVAL;
}
err = snd_pcm_slave_conf(slave, &sconf, 5,
err = snd_pcm_slave_conf(root, slave, &sconf, NULL, 5,
SND_PCM_HW_PARAM_CHANNELS, 0, &schannels,
SND_PCM_HW_PARAM_FORMAT, 0, &sformat,
SND_PCM_HW_PARAM_RATE, 0, &srate,

View file

@ -719,7 +719,8 @@ int is_local(struct hostent *hent)
return i < numreqs;
}
int _snd_pcm_shm_open(snd_pcm_t **pcmp, const char *name, snd_config_t *conf,
int _snd_pcm_shm_open(snd_pcm_t **pcmp, const char *name,
snd_config_t *root ATTRIBUTE_UNUSED, snd_config_t *conf,
snd_pcm_stream_t stream, int mode)
{
snd_config_iterator_t i, next;