#include <errno.h>
#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 95)
-#define ERR(...) snd_lib_error(__FILE__, __LINE__, __FUNCTION__, 0, __VA_ARGS__)
+#define SNDERR(...) snd_lib_error(__FILE__, __LINE__, __FUNCTION__, 0, __VA_ARGS__)
#define SYSERR(...) snd_lib_error(__FILE__, __LINE__, __FUNCTION__, errno, __VA_ARGS__)
#else
-#define ERR(args...) snd_lib_error(__FILE__, __LINE__, __FUNCTION__, 0, ##args)
+#define SNDERR(args...) snd_lib_error(__FILE__, __LINE__, __FUNCTION__, 0, ##args)
#define SYSERR(args...) snd_lib_error(__FILE__, __LINE__, __FUNCTION__, errno, ##args)
#endif
if (_snd_config_search(father, id, -1, &n) == 0) {
if (mode != REMOVE) {
if (n->type != SND_CONFIG_TYPE_COMPOUND) {
- ERR("%s is not a compound", id);
+ SNDERR("%s is not a compound", id);
return -EINVAL;
}
n->u.compound.join = 1;
snd_config_delete(n);
}
if (mode == NOCREATE) {
- ERR("%s does not exists", id);
+ SNDERR("%s does not exists", id);
free(id);
return -ENOENT;
}
} else {
n = NULL;
if (mode == NOCREATE) {
- ERR("%s does not exists", id);
+ SNDERR("%s does not exists", id);
free(id);
return -ENOENT;
}
{
if (n) {
if (n->type != SND_CONFIG_TYPE_COMPOUND) {
- ERR("%s is not a compound", id);
+ SNDERR("%s is not a compound", id);
return -EINVAL;
}
} else {
free(s);
if (n) {
if (n->type != SND_CONFIG_TYPE_REAL) {
- ERR("%s is not a real", id);
+ SNDERR("%s is not a real", id);
return -EINVAL;
}
} else {
free(s);
if (n) {
if (n->type != SND_CONFIG_TYPE_INTEGER) {
- ERR("%s is not an integer", id);
+ SNDERR("%s is not an integer", id);
return -EINVAL;
}
} else {
}
if (n) {
if (n->type != SND_CONFIG_TYPE_STRING) {
- ERR("%s is not a string", id);
+ SNDERR("%s is not a string", id);
free(s);
return -EINVAL;
}
assert(0);
break;
}
- ERR("%s:%d:%d:%s", fd->name ? fd->name : "",
+ SNDERR("%s:%d:%d:%s", fd->name ? fd->name : "",
fd->line, fd->column, str);
}
snd_config_delete(config);
goto _end;
}
if (get_char(&input) != EOF) {
- ERR("%s:%d:%d:Unexpected }", fd->name ? fd->name : "",
+ SNDERR("%s:%d:%d:Unexpected }", fd->name ? fd->name : "",
fd->line, fd->column);
snd_config_delete(config);
err = -EINVAL;
err = sscanf(name, "shm:%256[^,],%256[^,]", socket, sname);
if (err == 2)
return snd_ctl_shm_open(ctlp, name, socket, sname);
- ERR("Unknown control %s", name);
+ SNDERR("Unknown control %s", name);
return -ENOENT;
}
if (snd_config_get_type(ctl_conf) != SND_CONFIG_TYPE_COMPOUND)
if (err != 1)
return -EBADFD;
if (ctrl->cmd) {
- ERR("Server has not done the cmd");
+ SNDERR("Server has not done the cmd");
return -EBADFD;
}
return ctrl->result;
if (err != 1)
return -EBADFD;
if (ctrl->cmd) {
- ERR("Server has not done the cmd");
+ SNDERR("Server has not done the cmd");
return -EBADFD;
}
return ctrl->result;
result = make_local_socket(socket);
if (result < 0) {
- ERR("server for socket %s is not running", socket);
+ SNDERR("server for socket %s is not running", socket);
goto _err;
}
sock = result;
req->namelen = snamelen;
err = write(sock, req, reqlen);
if (err < 0) {
- ERR("write error");
+ SNDERR("write error");
result = -errno;
goto _err;
}
if ((size_t) err != reqlen) {
- ERR("write size error");
+ SNDERR("write size error");
result = -EINVAL;
goto _err;
}
err = read(sock, &ans, sizeof(ans));
if (err < 0) {
- ERR("read error");
+ SNDERR("read error");
result = -errno;
goto _err;
}
if (err != sizeof(ans)) {
- ERR("read size error");
+ SNDERR("read size error");
result = -EINVAL;
goto _err;
}
if (strcmp(id, "server") == 0) {
err = snd_config_get_string(n, &server);
if (err < 0) {
- ERR("Invalid type for %s", id);
+ SNDERR("Invalid type for %s", id);
return -EINVAL;
}
continue;
if (strcmp(id, "sname") == 0) {
err = snd_config_get_string(n, &sname);
if (err < 0) {
- ERR("Invalid type for %s", id);
+ SNDERR("Invalid type for %s", id);
return -EINVAL;
}
continue;
}
- ERR("Unknown field %s", id);
+ SNDERR("Unknown field %s", id);
return -EINVAL;
}
if (!sname) {
- ERR("sname is not defined");
+ SNDERR("sname is not defined");
return -EINVAL;
}
if (!server) {
- ERR("server is not defined");
+ SNDERR("server is not defined");
return -EINVAL;
}
err = snd_config_searchv(snd_config, &sconfig, "server", server, 0);
if (err < 0) {
- ERR("Unknown server %s", server);
+ SNDERR("Unknown server %s", server);
return -EINVAL;
}
snd_config_for_each(i, next, conf) {
if (strcmp(id, "host") == 0) {
err = snd_config_get_string(n, &host);
if (err < 0) {
- ERR("Invalid type for %s", id);
+ SNDERR("Invalid type for %s", id);
return -EINVAL;
}
continue;
if (strcmp(id, "socket") == 0) {
err = snd_config_get_string(n, &socket);
if (err < 0) {
- ERR("Invalid type for %s", id);
+ SNDERR("Invalid type for %s", id);
return -EINVAL;
}
continue;
if (strcmp(id, "port") == 0) {
err = snd_config_get_integer(n, &port);
if (err < 0) {
- ERR("Invalid type for %s", id);
+ SNDERR("Invalid type for %s", id);
return -EINVAL;
}
continue;
}
- ERR("Unknown field %s", id);
+ SNDERR("Unknown field %s", id);
return -EINVAL;
}
if (!host) {
- ERR("host is not defined");
+ SNDERR("host is not defined");
return -EINVAL;
}
if (!socket) {
- ERR("socket is not defined");
+ SNDERR("socket is not defined");
return -EINVAL;
}
h = gethostbyname(host);
if (!h) {
- ERR("Cannot resolve %s", host);
+ SNDERR("Cannot resolve %s", host);
return -EINVAL;
}
local = is_local(h);
if (!local) {
- ERR("%s is not the local host", host);
+ SNDERR("%s is not the local host", host);
return -EINVAL;
}
return snd_ctl_shm_open(handlep, name, socket, sname);
next_ffff = lseek(fd, 0, SEEK_CUR) + ffff.length;
if (file == index) {
#ifdef IW_ROM_DEBUG
- ERR("file header at 0x%x size 0x%x\n", rom_pos - sizeof(ffff), ffff.length);
+ SNDERR("file header at 0x%x size 0x%x\n", rom_pos - sizeof(ffff), ffff.length);
#endif
iwf = malloc(sizeof(*iwf));
if (iwf == NULL) {
unsigned char *current;
#ifdef IW_ROM_DEBUG
- ERR("load_iw_patch - nlayers = %i\n", snd_LE_to_host_16(*(((unsigned short *)patch) + 8/2));
+ SNDERR("load_iw_patch - nlayers = %i\n", snd_LE_to_host_16(*(((unsigned short *)patch) + 8/2));
#endif
instr->layer_type = patch[6];
instr->exclusion = patch[7];
pcm_shm.c pcm_file.c pcm_share.c pcm_null.c pcm_meter.c \
pcm_params.c
noinst_HEADERS = atomic.h pcm_local.h pcm_plugin.h mask.h mask_inline.h \
- interval.h interval_inline.h plugin_ops.h
+ interval.h interval_inline.h plugin_ops.h pcm_meter.h
all: libpcm.la
}
if (strcmp(name, "null") == 0)
return snd_pcm_null_open(pcmp, name, stream, mode);
- ERR("Unknown PCM %s", name);
+ SNDERR("Unknown PCM %s", name);
return -ENOENT;
}
if (snd_config_get_type(pcm_conf) != SND_CONFIG_TYPE_COMPOUND) {
- ERR("Invalid type for PCM %s definition", name);
+ SNDERR("Invalid type for PCM %s definition", name);
return -EINVAL;
}
err = snd_config_search(pcm_conf, "type", &conf);
if (err < 0) {
- ERR("type is not defined");
+ SNDERR("type is not defined");
return err;
}
err = snd_config_get_string(conf, &str);
if (err < 0) {
- ERR("Invalid type for %s", snd_config_get_id(conf));
+ SNDERR("Invalid type for %s", snd_config_get_id(conf));
return err;
}
err = snd_config_searchv(snd_config, &type_conf, "pcmtype", str, 0);
if (err < 0) {
- ERR("Unknown PCM type %s", str);
+ SNDERR("Unknown PCM type %s", str);
return err;
}
snd_config_for_each(i, next, type_conf) {
if (strcmp(id, "lib") == 0) {
err = snd_config_get_string(n, &lib);
if (err < 0) {
- ERR("Invalid type for %s", id);
+ SNDERR("Invalid type for %s", id);
return -EINVAL;
}
continue;
if (strcmp(id, "open") == 0) {
err = snd_config_get_string(n, &open);
if (err < 0) {
- ERR("Invalid type for %s", id);
+ SNDERR("Invalid type for %s", id);
return -EINVAL;
}
continue;
- ERR("Unknown field %s", id);
+ SNDERR("Unknown field %s", id);
return -EINVAL;
}
}
if (!open) {
- ERR("open is not defined");
+ SNDERR("open is not defined");
return -EINVAL;
}
if (!lib)
lib = "libasound.so";
h = dlopen(lib, RTLD_NOW);
if (!h) {
- ERR("Cannot open shared library %s", lib);
+ SNDERR("Cannot open shared library %s", lib);
return -ENOENT;
}
open_func = dlsym(h, open);
dlclose(h);
if (!open_func) {
- ERR("symbol %s is not defined inside %s", open, lib);
+ SNDERR("symbol %s is not defined inside %s", open, lib);
return -ENXIO;
}
return open_func(pcmp, name, pcm_conf, stream, mode);
if (strcmp(id, "sname") == 0) {
err = snd_config_get_string(n, &sname);
if (err < 0) {
- ERR("Invalid type for %s", id);
+ SNDERR("Invalid type for %s", id);
return -EINVAL;
}
continue;
const char *f;
err = snd_config_get_string(n, &f);
if (err < 0) {
- ERR("Invalid type for %s", id);
+ SNDERR("Invalid type for %s", id);
return -EINVAL;
}
sformat = snd_pcm_format_value(f);
if (sformat == SND_PCM_FORMAT_UNKNOWN) {
- ERR("Unknown sformat");
+ SNDERR("Unknown sformat");
return -EINVAL;
}
if (snd_pcm_format_linear(sformat) != 1 &&
sformat != SND_PCM_FORMAT_IMA_ADPCM) {
- ERR("Invalid sformat");
+ SNDERR("Invalid sformat");
return -EINVAL;
}
continue;
}
- ERR("Unknown field %s", id);
+ SNDERR("Unknown field %s", id);
return -EINVAL;
}
if (!sname) {
- ERR("sname is not defined");
+ SNDERR("sname is not defined");
return -EINVAL;
}
if (sformat == SND_PCM_FORMAT_UNKNOWN) {
- ERR("sformat is not defined");
+ SNDERR("sformat is not defined");
return -EINVAL;
}
/* This is needed cause snd_config_update may destroy config */
if (strcmp(id, "sname") == 0) {
err = snd_config_get_string(n, &sname);
if (err < 0) {
- ERR("Invalid type for %s", id);
+ SNDERR("Invalid type for %s", id);
return -EINVAL;
}
continue;
const char *f;
err = snd_config_get_string(n, &f);
if (err < 0) {
- ERR("Invalid type for %s", id);
+ SNDERR("Invalid type for %s", id);
return -EINVAL;
}
sformat = snd_pcm_format_value(f);
if (sformat == SND_PCM_FORMAT_UNKNOWN) {
- ERR("Unknown sformat");
+ SNDERR("Unknown sformat");
return -EINVAL;
}
if (snd_pcm_format_linear(sformat) != 1 &&
sformat != SND_PCM_FORMAT_A_LAW) {
- ERR("Invalid sformat");
+ SNDERR("Invalid sformat");
return -EINVAL;
}
continue;
}
- ERR("Unknown field %s", id);
+ SNDERR("Unknown field %s", id);
return -EINVAL;
}
if (!sname) {
- ERR("sname is not defined");
+ SNDERR("sname is not defined");
return -EINVAL;
}
if (sformat == SND_PCM_FORMAT_UNKNOWN) {
- ERR("sformat is not defined");
+ SNDERR("sformat is not defined");
return -EINVAL;
}
/* This is needed cause snd_config_update may destroy config */
if (strcmp(id, "sname") == 0) {
err = snd_config_get_string(n, &sname);
if (err < 0) {
- ERR("Invalid type for %s", id);
+ SNDERR("Invalid type for %s", id);
return -EINVAL;
}
continue;
}
- ERR("Unknown field %s", id);
+ SNDERR("Unknown field %s", id);
return -EINVAL;
}
if (!sname) {
- ERR("sname is not defined");
+ SNDERR("sname is not defined");
return -EINVAL;
}
/* This is needed cause snd_config_update may destroy config */
strcmp(fmt, "raw") == 0)
format = SND_PCM_FILE_FORMAT_RAW;
else {
- ERR("file format %s is unknown", fmt);
+ SNDERR("file format %s is unknown", fmt);
return -EINVAL;
}
if (fname) {
if (strcmp(id, "sname") == 0) {
err = snd_config_get_string(n, &sname);
if (err < 0) {
- ERR("Invalid type for %s", id);
+ SNDERR("Invalid type for %s", id);
return -EINVAL;
}
continue;
if (strcmp(id, "format") == 0) {
err = snd_config_get_string(n, &format);
if (err < 0) {
- ERR("Invalid type for %s", id);
+ SNDERR("Invalid type for %s", id);
return -EINVAL;
}
continue;
if (err < 0) {
err = snd_config_get_integer(n, &fd);
if (err < 0) {
- ERR("Invalid type for %s", id);
+ SNDERR("Invalid type for %s", id);
return -EINVAL;
}
}
continue;
}
- ERR("Unknown field %s", id);
+ SNDERR("Unknown field %s", id);
return -EINVAL;
}
if (!sname) {
- ERR("sname is not defined");
+ SNDERR("sname is not defined");
return -EINVAL;
}
if (!fname && fd < 0) {
- ERR("file is not defined");
+ SNDERR("file is not defined");
return -EINVAL;
}
if (fname) {
if (err < 0) {
err = snd_config_get_string(n, &str);
if (err < 0) {
- ERR("Invalid type for %s", id);
+ SNDERR("Invalid type for %s", id);
return -EINVAL;
}
card = snd_card_get_index(str);
if (card < 0) {
- ERR("Invalid value for %s", id);
+ SNDERR("Invalid value for %s", id);
return card;
}
}
if (strcmp(id, "device") == 0) {
err = snd_config_get_integer(n, &device);
if (err < 0) {
- ERR("Invalid type for %s", id);
+ SNDERR("Invalid type for %s", id);
return err;
}
continue;
if (strcmp(id, "subdevice") == 0) {
err = snd_config_get_integer(n, &subdevice);
if (err < 0) {
- ERR("Invalid type for %s", id);
+ SNDERR("Invalid type for %s", id);
return err;
}
continue;
}
- ERR("Unknown field %s", id);
+ SNDERR("Unknown field %s", id);
return -EINVAL;
}
if (card < 0) {
- ERR("card is not defined");
+ SNDERR("card is not defined");
return -EINVAL;
}
return snd_pcm_hw_open(pcmp, name, card, device, subdevice, stream, mode);
if (strcmp(id, "sname") == 0) {
err = snd_config_get_string(n, &sname);
if (err < 0) {
- ERR("Invalid type for %s", id);
+ SNDERR("Invalid type for %s", id);
return -EINVAL;
}
continue;
const char *f;
err = snd_config_get_string(n, &f);
if (err < 0) {
- ERR("Invalid type for %s", id);
+ SNDERR("Invalid type for %s", id);
return -EINVAL;
}
sformat = snd_pcm_format_value(f);
if (sformat == SND_PCM_FORMAT_UNKNOWN) {
- ERR("Unknown sformat %s", f);
+ SNDERR("Unknown sformat %s", f);
return err;
}
if (snd_pcm_format_linear(sformat) != 1) {
- ERR("sformat is not linear");
+ SNDERR("sformat is not linear");
return -EINVAL;
}
continue;
}
- ERR("Unknown field %s", id);
+ SNDERR("Unknown field %s", id);
return -EINVAL;
}
if (!sname) {
- ERR("sname is not defined");
+ SNDERR("sname is not defined");
return -EINVAL;
}
if (sformat == SND_PCM_FORMAT_UNKNOWN) {
- ERR("sformat is not defined");
+ SNDERR("sformat is not defined");
return -EINVAL;
}
/* This is needed cause snd_config_update may destroy config */
/*
* PCM - Meter plugin
- * Copyright (c) 2000 by Abramo Bagnara <abramo@alsa-project.org>
- *
+ * Copyright (c) 2001 by Abramo Bagnara <abramo@alsa-project.org>
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
*/
#include <byteswap.h>
-#include <pthread.h>
#include <time.h>
-#include <asm/atomic.h>
-#include "pcm_local.h"
-#include "pcm_plugin.h"
-#include "list.h"
-
-#define FPS 50
-
-typedef struct _snd_pcm_meter_scope snd_pcm_meter_scope_t;
+#include "pcm_meter.h"
-struct _snd_pcm_meter_scope {
- snd_pcm_t *pcm;
- char *name;
- void (*init)(snd_pcm_meter_scope_t *scope);
- void (*start)(snd_pcm_meter_scope_t *scope);
- void (*stop)(snd_pcm_meter_scope_t *scope);
- void (*update)(snd_pcm_meter_scope_t *scope);
- void (*reset)(snd_pcm_meter_scope_t *scope);
- void (*close)(snd_pcm_meter_scope_t *scope);
- void *private_data;
- struct list_head list;
-};
+#define FREQUENCY 50
-typedef struct _snd_pcm_meter {
- snd_pcm_t *slave;
- int close_slave;
- snd_pcm_uframes_t rptr;
- snd_pcm_uframes_t buf_size;
- snd_pcm_channel_area_t *buf_areas;
- snd_pcm_uframes_t now;
- char *buf;
- pthread_t thread;
- int closed;
- struct list_head scopes;
- int running;
- atomic_t reset;
- pthread_mutex_t update_mutex;
- pthread_mutex_t running_mutex;
- pthread_cond_t running_cond;
-} snd_pcm_meter_t;
+typedef struct _snd_pcm_meter_s16 {
+ snd_pcm_adpcm_state_t *adpcm_states;
+ unsigned int index;
+ snd_pcm_uframes_t old;
+} snd_pcm_meter_s16_t;
-void debug_init(snd_pcm_meter_scope_t *scope ATTRIBUTE_UNUSED)
+int s16_open(snd_pcm_meter_scope_t *scope)
{
- fprintf(stderr, "init\n");
+ snd_pcm_meter_t *meter = scope->pcm->private_data;
+ snd_pcm_t *spcm = meter->slave;
+ snd_pcm_channel_area_t *a;
+ unsigned int c;
+ snd_pcm_meter_s16_t *s16;
+ int index;
+ if (spcm->format == SND_PCM_FORMAT_S16 &&
+ spcm->access == SND_PCM_ACCESS_MMAP_NONINTERLEAVED) {
+ meter->buf16 = (int16_t *) meter->buf;
+ return -EINVAL;
+ }
+ switch (spcm->format) {
+ case SND_PCM_FORMAT_A_LAW:
+ case SND_PCM_FORMAT_MU_LAW:
+ case SND_PCM_FORMAT_IMA_ADPCM:
+ index = snd_pcm_linear_put_index(SND_PCM_FORMAT_S16, SND_PCM_FORMAT_S16);
+ break;
+ case SND_PCM_FORMAT_S8:
+ case SND_PCM_FORMAT_S16_LE:
+ case SND_PCM_FORMAT_S16_BE:
+ case SND_PCM_FORMAT_S24_LE:
+ case SND_PCM_FORMAT_S24_BE:
+ case SND_PCM_FORMAT_S32_LE:
+ case SND_PCM_FORMAT_S32_BE:
+ case SND_PCM_FORMAT_U8:
+ case SND_PCM_FORMAT_U16_LE:
+ case SND_PCM_FORMAT_U16_BE:
+ case SND_PCM_FORMAT_U24_LE:
+ case SND_PCM_FORMAT_U24_BE:
+ case SND_PCM_FORMAT_U32_LE:
+ case SND_PCM_FORMAT_U32_BE:
+ index = snd_pcm_linear_convert_index(spcm->format, SND_PCM_FORMAT_S16);
+ break;
+ default:
+ return -EINVAL;
+ }
+ s16 = calloc(1, sizeof(*s16));
+ if (!s16)
+ return -ENOMEM;
+ s16->index = index;
+ if (spcm->format == SND_PCM_FORMAT_IMA_ADPCM) {
+ s16->adpcm_states = calloc(spcm->channels, sizeof(*s16->adpcm_states));
+ if (!s16->adpcm_states) {
+ free(s16);
+ return -ENOMEM;
+ }
+ }
+ meter->buf16 = malloc(meter->buf_size * 2 * spcm->channels);
+ if (!meter->buf16) {
+ if (s16->adpcm_states)
+ free(s16->adpcm_states);
+ free(s16);
+ return -ENOMEM;
+ }
+ a = calloc(spcm->channels, sizeof(*a));
+ if (!a) {
+ free(meter->buf16);
+ if (s16->adpcm_states)
+ free(s16->adpcm_states);
+ free(s16);
+ return -ENOMEM;
+ }
+ meter->buf16_areas = a;
+ for (c = 0; c < spcm->channels; c++, a++) {
+ a->addr = meter->buf16 + c * meter->buf_size;
+ a->first = 0;
+ a->step = 16;
+ }
+ scope->private_data = s16;
+ return 0;
}
-void debug_start(snd_pcm_meter_scope_t *scope ATTRIBUTE_UNUSED)
+void s16_close(snd_pcm_meter_scope_t *scope)
{
- fprintf(stderr, "start\n");
+ snd_pcm_meter_t *meter = scope->pcm->private_data;
+ snd_pcm_meter_s16_t *s16 = scope->private_data;
+ if (s16->adpcm_states)
+ free(s16->adpcm_states);
+ free(s16);
+ free(meter->buf16);
+ meter->buf16 = NULL;
+ free(meter->buf16_areas);
}
-void debug_stop(snd_pcm_meter_scope_t *scope ATTRIBUTE_UNUSED)
+void s16_start(snd_pcm_meter_scope_t *scope ATTRIBUTE_UNUSED)
{
- fprintf(stderr, "\nstop\n");
}
-void debug_update(snd_pcm_meter_scope_t *scope ATTRIBUTE_UNUSED)
+void s16_stop(snd_pcm_meter_scope_t *scope ATTRIBUTE_UNUSED)
{
- snd_pcm_meter_t *meter = scope->pcm->private_data;
- fprintf(stderr, "update %08ld\r", meter->now);
}
-void debug_reset(snd_pcm_meter_scope_t *scope ATTRIBUTE_UNUSED)
+void s16_update(snd_pcm_meter_scope_t *scope)
{
- fprintf(stderr, "\nreset\n");
+ snd_pcm_meter_t *meter = scope->pcm->private_data;
+ snd_pcm_meter_s16_t *s16 = scope->private_data;
+ snd_pcm_t *spcm = meter->slave;
+ snd_pcm_sframes_t size;
+ snd_pcm_uframes_t offset;
+ size = meter->now - s16->old;
+ if (size < 0)
+ size += spcm->boundary;
+ offset = s16->old % meter->buf_size;
+ while (size > 0) {
+ snd_pcm_uframes_t frames = size;
+ snd_pcm_uframes_t cont = meter->buf_size - offset;
+ if (frames > cont)
+ frames = cont;
+ switch (spcm->format) {
+ case SND_PCM_FORMAT_A_LAW:
+ snd_pcm_alaw_decode(meter->buf16_areas, offset,
+ meter->buf_areas, offset,
+ spcm->channels, frames,
+ s16->index);
+ break;
+ case SND_PCM_FORMAT_MU_LAW:
+ snd_pcm_mulaw_decode(meter->buf16_areas, offset,
+ meter->buf_areas, offset,
+ spcm->channels, frames,
+ s16->index);
+ break;
+ case SND_PCM_FORMAT_IMA_ADPCM:
+ snd_pcm_adpcm_decode(meter->buf16_areas, offset,
+ meter->buf_areas, offset,
+ spcm->channels, frames,
+ s16->index,
+ s16->adpcm_states);
+ break;
+ default:
+ snd_pcm_linear_convert(meter->buf16_areas, offset,
+ meter->buf_areas, offset,
+ spcm->channels, frames,
+ s16->index);
+ break;
+ }
+ if (frames == cont)
+ offset = 0;
+ else
+ offset += frames;
+ size -= frames;
+ }
+ s16->old = meter->now;
}
-void debug_close(snd_pcm_meter_scope_t *scope ATTRIBUTE_UNUSED)
+void s16_reset(snd_pcm_meter_scope_t *scope)
{
- fprintf(stderr, "\nclose\n");
-}
-
-snd_pcm_meter_scope_t debug_scope = {
- name: "debug",
- init: debug_init,
- start: debug_start,
- stop: debug_stop,
- update: debug_update,
- reset: debug_reset,
- close: debug_close,
+ snd_pcm_meter_t *meter = scope->pcm->private_data;
+ snd_pcm_meter_s16_t *s16 = scope->private_data;
+ s16->old = meter->now;
+}
+
+snd_pcm_meter_scope_t s16_scope = {
+ name: "s16",
+ open: s16_open,
+ start: s16_start,
+ stop: s16_stop,
+ update: s16_update,
+ reset: s16_reset,
+ close: s16_close,
pcm: NULL,
+ active: 0,
list: { 0, 0 },
private_data: NULL,
};
snd_pcm_meter_t *meter = pcm->private_data;
scope->pcm = pcm;
list_add_tail(&scope->list, &meter->scopes);
- scope->init(scope);
}
void snd_pcm_meter_add_frames(snd_pcm_t *pcm,
snd_pcm_t *spcm = meter->slave;
struct list_head *pos;
snd_pcm_meter_scope_t *scope;
- int reset;
- struct timespec delay = {
- tv_sec: 0,
- tv_nsec: 1000000000 / FPS,
- };
+ int err, reset;
+ list_for_each(pos, &meter->scopes) {
+ scope = list_entry(pos, snd_pcm_meter_scope_t, list);
+ err = scope->open(scope);
+ scope->active = (err >= 0);
+ }
while (!meter->closed) {
snd_pcm_sframes_t now;
snd_pcm_status_t status;
if ((snd_pcm_uframes_t) now >= pcm->boundary)
now -= pcm->boundary;
}
- meter->now = now % meter->buf_size;
+ meter->now = now;
if (pcm->stream == SND_PCM_STREAM_CAPTURE)
reset = snd_pcm_meter_update_scope(pcm);
else {
atomic_dec(&meter->reset);
}
}
- if (!meter->running) {
+ if (reset) {
list_for_each(pos, &meter->scopes) {
scope = list_entry(pos, snd_pcm_meter_scope_t, list);
- scope->start(scope);
+ if (scope->active)
+ scope->reset(scope);
}
- meter->running = 1;
- } else if (reset) {
+ continue;
+ }
+ if (!meter->running) {
list_for_each(pos, &meter->scopes) {
scope = list_entry(pos, snd_pcm_meter_scope_t, list);
- scope->reset(scope);
+ if (scope->active)
+ scope->start(scope);
}
+ meter->running = 1;
}
list_for_each(pos, &meter->scopes) {
scope = list_entry(pos, snd_pcm_meter_scope_t, list);
- scope->update(scope);
+ if (scope->active)
+ scope->update(scope);
}
- nanosleep(&delay, NULL);
+ nanosleep(&meter->delay, NULL);
}
list_for_each(pos, &meter->scopes) {
scope = list_entry(pos, snd_pcm_meter_scope_t, list);
- scope->close(scope);
+ if (scope->active)
+ scope->close(scope);
}
return NULL;
}
{
snd_pcm_meter_t *meter = pcm->private_data;
int err = 0;
- meter->closed = 1;
- pthread_mutex_lock(&meter->running_mutex);
- pthread_cond_signal(&meter->running_cond);
- pthread_mutex_unlock(&meter->running_mutex);
- err = pthread_join(meter->thread, 0);
- assert(err == 0);
pthread_mutex_destroy(&meter->update_mutex);
pthread_mutex_destroy(&meter->running_mutex);
pthread_cond_destroy(&meter->running_cond);
if (meter->close_slave)
err = snd_pcm_close(meter->slave);
free(meter);
- return 0;
+ return err;
}
static int snd_pcm_meter_nonblock(snd_pcm_t *pcm, int nonblock)
a->first = 0;
a->step = slave->sample_bits;
}
+ meter->closed = 0;
+ err = pthread_create(&meter->thread, NULL, snd_pcm_meter_thread, pcm);
+ assert(err == 0);
return 0;
}
static int snd_pcm_meter_hw_free(snd_pcm_t *pcm)
{
snd_pcm_meter_t *meter = pcm->private_data;
+ int err;
+ meter->closed = 1;
+ pthread_mutex_lock(&meter->running_mutex);
+ pthread_cond_signal(&meter->running_cond);
+ pthread_mutex_unlock(&meter->running_mutex);
+ err = pthread_join(meter->thread, 0);
+ assert(err == 0);
if (meter->buf) {
free(meter->buf);
free(meter->buf_areas);
mmap_forward: snd_pcm_meter_mmap_forward,
};
-int snd_pcm_meter_open(snd_pcm_t **pcmp, const char *name, snd_pcm_t *slave, int close_slave)
+int snd_pcm_meter_open(snd_pcm_t **pcmp, const char *name, unsigned int frequency,
+ snd_pcm_t *slave, int close_slave)
{
snd_pcm_t *pcm;
snd_pcm_meter_t *meter;
- int err;
assert(pcmp);
meter = calloc(1, sizeof(snd_pcm_meter_t));
if (!meter)
return -ENOMEM;
meter->slave = slave;
meter->close_slave = close_slave;
+ meter->delay.tv_sec = 0;
+ meter->delay.tv_nsec = 1000000000 / frequency;
INIT_LIST_HEAD(&meter->scopes);
pcm = calloc(1, sizeof(snd_pcm_t));
pcm->appl_ptr = slave->appl_ptr;
*pcmp = pcm;
-#if 1
- snd_pcm_meter_add_scope(pcm, &debug_scope);
-#endif
pthread_mutex_init(&meter->update_mutex, NULL);
pthread_mutex_init(&meter->running_mutex, NULL);
pthread_cond_init(&meter->running_cond, NULL);
- err = pthread_create(&meter->thread, NULL, snd_pcm_meter_thread, pcm);
- assert(err == 0);
+#if 1
+ snd_pcm_meter_add_scope(pcm, &s16_scope);
+#endif
+#if 1
+ {
+ extern snd_pcm_meter_scope_t level_scope;
+ snd_pcm_meter_add_scope(pcm, &level_scope);
+ }
+#endif
return 0;
}
const char *sname = NULL;
int err;
snd_pcm_t *spcm;
+ long frequency = -1;
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, "sname") == 0) {
err = snd_config_get_string(n, &sname);
if (err < 0) {
- ERR("Invalid type for %s", id);
+ SNDERR("Invalid type for %s", id);
+ return -EINVAL;
+ }
+ continue;
+ }
+ if (strcmp(id, "frequency") == 0) {
+ err = snd_config_get_integer(n, &frequency);
+ if (err < 0) {
+ SNDERR("Invalid type for %s", id);
return -EINVAL;
}
continue;
}
- ERR("Unknown field %s", id);
+ SNDERR("Unknown field %s", id);
return -EINVAL;
}
if (!sname) {
- ERR("sname is not defined");
+ SNDERR("sname is not defined");
return -EINVAL;
}
free((void *) sname);
if (err < 0)
return err;
- err = snd_pcm_meter_open(pcmp, name, spcm, 1);
+ err = snd_pcm_meter_open(pcmp, name, frequency < 0 ? FREQUENCY : frequency, spcm, 1);
if (err < 0)
snd_pcm_close(spcm);
return err;
--- /dev/null
+/*
+ * PCM - Meter plugin
+ * Copyright (c) 2001 by Abramo Bagnara <abramo@alsa-project.org>
+ *
+ * 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 <pthread.h>
+#include <asm/atomic.h>
+#include "list.h"
+#include "pcm_local.h"
+#include "pcm_plugin.h"
+
+typedef struct _snd_pcm_meter_scope snd_pcm_meter_scope_t;
+
+struct _snd_pcm_meter_scope {
+ snd_pcm_t *pcm;
+ int active;
+ char *name;
+ int (*open)(snd_pcm_meter_scope_t *scope);
+ void (*start)(snd_pcm_meter_scope_t *scope);
+ void (*stop)(snd_pcm_meter_scope_t *scope);
+ void (*update)(snd_pcm_meter_scope_t *scope);
+ void (*reset)(snd_pcm_meter_scope_t *scope);
+ void (*close)(snd_pcm_meter_scope_t *scope);
+ void *private_data;
+ struct list_head list;
+};
+
+typedef struct _snd_pcm_meter {
+ snd_pcm_t *slave;
+ int close_slave;
+ snd_pcm_uframes_t rptr;
+ snd_pcm_uframes_t buf_size;
+ snd_pcm_channel_area_t *buf_areas;
+ snd_pcm_uframes_t now;
+ unsigned char *buf;
+ struct list_head scopes;
+ int closed;
+ int running;
+ atomic_t reset;
+ pthread_t thread;
+ pthread_mutex_t update_mutex;
+ pthread_mutex_t running_mutex;
+ pthread_cond_t running_cond;
+ int16_t *buf16;
+ snd_pcm_channel_area_t *buf16_areas;
+ struct timespec delay;
+} snd_pcm_meter_t;
+
if (strcmp(id, "sname") == 0) {
err = snd_config_get_string(n, &sname);
if (err < 0) {
- ERR("Invalid type for %s", id);
+ SNDERR("Invalid type for %s", id);
return -EINVAL;
}
continue;
const char *f;
err = snd_config_get_string(n, &f);
if (err < 0) {
- ERR("Invalid type for %s", id);
+ SNDERR("Invalid type for %s", id);
return -EINVAL;
}
sformat = snd_pcm_format_value(f);
if (sformat == SND_PCM_FORMAT_UNKNOWN) {
- ERR("Unknown sformat");
+ SNDERR("Unknown sformat");
return -EINVAL;
}
if (snd_pcm_format_linear(sformat) != 1 &&
sformat != SND_PCM_FORMAT_MU_LAW) {
- ERR("Invalid sformat");
+ SNDERR("Invalid sformat");
return -EINVAL;
}
continue;
}
- ERR("Unknown field %s", id);
+ SNDERR("Unknown field %s", id);
return -EINVAL;
}
if (!sname) {
- ERR("sname is not defined");
+ SNDERR("sname is not defined");
return -EINVAL;
}
if (sformat == SND_PCM_FORMAT_UNKNOWN) {
- ERR("sformat is not defined");
+ SNDERR("sformat is not defined");
return -EINVAL;
}
/* This is needed cause snd_config_update may destroy config */
for (k = 0; k < multi->slaves_count; ++k) {
err = snd_pcm_multi_hw_refine_sprepare(pcm, k, &sparams[k]);
if (err < 0) {
- ERR("Slave PCM #%d not useable", k);
+ SNDERR("Slave PCM #%d not useable", k);
return err;
}
}
continue;
if (strcmp(id, "slave") == 0) {
if (snd_config_get_type(n) != SND_CONFIG_TYPE_COMPOUND) {
- ERR("Invalid type for %s", id);
+ SNDERR("Invalid type for %s", id);
return -EINVAL;
}
slave = n;
}
if (strcmp(id, "binding") == 0) {
if (snd_config_get_type(n) != SND_CONFIG_TYPE_COMPOUND) {
- ERR("Invalid type for %s", id);
+ SNDERR("Invalid type for %s", id);
return -EINVAL;
}
binding = n;
continue;
}
- ERR("Unknown field %s", id);
+ SNDERR("Unknown field %s", id);
return -EINVAL;
}
if (!slave) {
- ERR("slave is not defined");
+ SNDERR("slave is not defined");
return -EINVAL;
}
if (!binding) {
- ERR("binding is not defined");
+ SNDERR("binding is not defined");
return -EINVAL;
}
snd_config_for_each(i, inext, slave) {
errno = 0;
cchannel = strtol(id, &p, 10);
if (errno || *p || cchannel < 0) {
- ERR("Invalid channel number: %s", id);
+ SNDERR("Invalid channel number: %s", id);
return -EINVAL;
}
if ((unsigned)cchannel >= channels_count)
channels_count = cchannel + 1;
}
if (channels_count == 0) {
- ERR("No cannels defined");
+ SNDERR("No cannels defined");
return -EINVAL;
}
slaves_id = calloc(slaves_count, sizeof(*slaves_id));
if (strcmp(id, "name") == 0) {
err = snd_config_get_string(n, &name);
if (err < 0) {
- ERR("Invalid type for %s", id);
+ SNDERR("Invalid type for %s", id);
goto _free;
}
continue;
if (strcmp(id, "channels") == 0) {
err = snd_config_get_integer(n, &channels);
if (err < 0) {
- ERR("Invalid type for %s", id);
+ SNDERR("Invalid type for %s", id);
goto _free;
}
continue;
}
- ERR("Unknown field %s", id);
+ SNDERR("Unknown field %s", id);
err = -EINVAL;
goto _free;
}
if (!name) {
- ERR("name is not defined");
+ SNDERR("name is not defined");
err = -EINVAL;
goto _free;
}
if (channels < 0) {
- ERR("channels is not defined");
+ SNDERR("channels is not defined");
err = -EINVAL;
goto _free;
}
const char *id = snd_config_get_id(m);
cchannel = strtol(id, 0, 10);
if (cchannel < 0) {
- ERR("Invalid channel number: %s", id);
+ SNDERR("Invalid channel number: %s", id);
err = -EINVAL;
goto _free;
}
if (err < 0) {
err = snd_config_get_integer(n, &val);
if (err < 0) {
- ERR("Invalid value for %s", id);
+ SNDERR("Invalid value for %s", id);
goto _free;
}
sprintf(buf, "%ld", val);
if (strcmp(id, "schannel") == 0) {
err = snd_config_get_integer(n, &schannel);
if (err < 0) {
- ERR("Invalid type for %s", id);
+ SNDERR("Invalid type for %s", id);
goto _free;
}
continue;
}
- ERR("Unknown field %s", id);
+ SNDERR("Unknown field %s", id);
err = -EINVAL;
goto _free;
}
if (slave < 0 || (unsigned int)slave >= slaves_count) {
- ERR("Invalid or missing sidx");
+ SNDERR("Invalid or missing sidx");
err = -EINVAL;
goto _free;
}
if (schannel < 0 ||
(unsigned int) schannel >= slaves_channels[slave]) {
- ERR("Invalid or missing schannel");
+ SNDERR("Invalid or missing schannel");
err = -EINVAL;
goto _free;
}
continue;
if (strcmp(id, "type") == 0)
continue;
- ERR("Unknown field %s", id);
+ SNDERR("Unknown field %s", id);
return -EINVAL;
}
return snd_pcm_null_open(pcmp, name, stream, mode);
snd_pcm_hw_param_set_first(pcm, params, SND_PCM_HW_PARAM_CHANNELS, 0);
snd_pcm_hw_param_set_first(pcm, params, SND_PCM_HW_PARAM_RATE, 0);
snd_pcm_hw_param_set_first(pcm, params, SND_PCM_HW_PARAM_PERIOD_TIME, 0);
+ snd_pcm_hw_param_set_first(pcm, params, SND_PCM_HW_PARAM_PERIOD_SIZE, 0);
snd_pcm_hw_param_set_last(pcm, params, SND_PCM_HW_PARAM_BUFFER_SIZE, 0);
snd_pcm_hw_param_set_first(pcm, params, SND_PCM_HW_PARAM_TICK_TIME, 0);
}
return err;
err = sprepare(pcm, &sparams);
if (err < 0) {
- ERR("Slave PCM not useable");
+ SNDERR("Slave PCM not useable");
return err;
}
do {
_snd_pcm_hw_param_set_mask(sparams, SND_PCM_HW_PARAM_ACCESS,
&access_mask);
}
- 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;
+ if (snd_pcm_hw_param_always_eq(params, SND_PCM_HW_PARAM_RATE, sparams))
+ 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;
+ }
err = _snd_pcm_hw_params_refine(sparams, links, params);
if (err < 0)
return err;
unsigned int rate_min, srate_min;
int rate_mindir, srate_mindir;
format_mask = snd_pcm_hw_param_get_mask(params,
- SND_PCM_HW_PARAM_FORMAT);
+ SND_PCM_HW_PARAM_FORMAT);
sformat_mask = snd_pcm_hw_param_get_mask(sparams,
- SND_PCM_HW_PARAM_FORMAT);
+ SND_PCM_HW_PARAM_FORMAT);
snd_mask_none(&fmt_mask);
for (format = 0; format <= SND_PCM_FORMAT_LAST; snd_enum_incr(format)) {
snd_pcm_format_t f;
return err;
}
- 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;
+ if (snd_pcm_hw_param_always_eq(params, SND_PCM_HW_PARAM_RATE, sparams))
+ 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;
+ }
err = _snd_pcm_hw_params_refine(params, links, sparams);
if (err < 0)
return err;
if (strcmp(id, "sname") == 0) {
err = snd_config_get_string(n, &sname);
if (err < 0) {
- ERR("Invalid type for %s", id);
+ SNDERR("Invalid type for %s", id);
return -EINVAL;
}
continue;
}
if (strcmp(id, "ttable") == 0) {
if (snd_config_get_type(n) != SND_CONFIG_TYPE_COMPOUND) {
- ERR("Invalid type for %s", id);
+ SNDERR("Invalid type for %s", id);
return -EINVAL;
}
tt = n;
continue;
}
- ERR("Unknown field %s", id);
+ SNDERR("Unknown field %s", id);
return -EINVAL;
}
if (!sname) {
- ERR("sname is not defined");
+ SNDERR("sname is not defined");
return -EINVAL;
}
if (tt) {
if (strcmp(id, "sname") == 0) {
err = snd_config_get_string(n, &sname);
if (err < 0) {
- ERR("Invalid type for %s", id);
+ SNDERR("Invalid type for %s", id);
return -EINVAL;
}
continue;
const char *f;
err = snd_config_get_string(n, &f);
if (err < 0) {
- ERR("Invalid type for %s", id);
+ SNDERR("Invalid type for %s", id);
return -EINVAL;
}
sformat = snd_pcm_format_value(f);
if (sformat == SND_PCM_FORMAT_UNKNOWN) {
- ERR("Unknown sformat");
+ SNDERR("Unknown sformat");
return -EINVAL;
}
if (snd_pcm_format_linear(sformat) != 1) {
- ERR("sformat is not linear");
+ SNDERR("sformat is not linear");
return -EINVAL;
}
continue;
if (strcmp(id, "srate") == 0) {
err = snd_config_get_integer(n, &srate);
if (err < 0) {
- ERR("Invalid type for %s", id);
+ SNDERR("Invalid type for %s", id);
return -EINVAL;
}
continue;
}
- ERR("Unknown field %s", id);
+ SNDERR("Unknown field %s", id);
return -EINVAL;
}
if (!sname) {
- ERR("sname is not defined");
+ SNDERR("sname is not defined");
return -EINVAL;
}
if (srate < 0) {
- ERR("srate is not defined");
+ SNDERR("srate is not defined");
return -EINVAL;
}
/* This is needed cause snd_config_update may destroy config */
cchannel = strtol(snd_config_get_id(in), &p, 10);
if (errno || *p ||
cchannel < 0 || (unsigned int) cchannel > tt_csize) {
- ERR("Invalid client channel: %s", snd_config_get_id(in));
+ SNDERR("Invalid client channel: %s", snd_config_get_id(in));
return -EINVAL;
}
if (snd_config_get_type(in) != SND_CONFIG_TYPE_COMPOUND)
if (errno || *p ||
schannel < 0 || (unsigned int) schannel > tt_ssize ||
(schannels > 0 && schannel >= schannels)) {
- ERR("Invalid slave channel: %s", id);
+ SNDERR("Invalid slave channel: %s", id);
return -EINVAL;
}
err = snd_config_get_real(jn, &value);
long v;
err = snd_config_get_integer(jn, &v);
if (err < 0) {
- ERR("Invalid type for %s", id);
+ SNDERR("Invalid type for %s", id);
return -EINVAL;
}
value = v;
if (strcmp(id, "sname") == 0) {
err = snd_config_get_string(n, &sname);
if (err < 0) {
- ERR("Invalid type for %s", id);
+ SNDERR("Invalid type for %s", id);
return -EINVAL;
}
continue;
const char *f;
err = snd_config_get_string(n, &f);
if (err < 0) {
- ERR("Invalid type for %s", id);
+ SNDERR("Invalid type for %s", id);
return -EINVAL;
}
sformat = snd_pcm_format_value(f);
if (sformat == SND_PCM_FORMAT_UNKNOWN) {
- ERR("Unknown sformat");
+ SNDERR("Unknown sformat");
return -EINVAL;
}
if (snd_pcm_format_linear(sformat) != 1) {
- ERR("sformat is not linear");
+ SNDERR("sformat is not linear");
return -EINVAL;
}
continue;
if (strcmp(id, "schannels") == 0) {
err = snd_config_get_integer(n, &schannels);
if (err < 0) {
- ERR("Invalid type for %s", id);
+ SNDERR("Invalid type for %s", id);
return -EINVAL;
}
continue;
}
if (strcmp(id, "ttable") == 0) {
if (snd_config_get_type(n) != SND_CONFIG_TYPE_COMPOUND) {
- ERR("Invalid type for %s", id);
+ SNDERR("Invalid type for %s", id);
return -EINVAL;
}
tt = n;
continue;
}
- ERR("Unknown field %s", id);
+ SNDERR("Unknown field %s", id);
return -EINVAL;
}
if (!sname) {
- ERR("sname is not defined");
+ SNDERR("sname is not defined");
return -EINVAL;
}
if (!tt) {
- ERR("ttable is not defined");
+ SNDERR("ttable is not defined");
return -EINVAL;
}
spcm->tick_time, 0);
_err:
if (err < 0) {
- ERR("slave is already running with different setup");
+ SNDERR("slave is already running with different setup");
err = -EBUSY;
goto _end;
}
for (k = 0; k < channels_count; ++k) {
if (channels_map[k] < 0 || channels_map[k] > 31) {
- ERR("Invalid slave channel (%d) in binding", channels_map[k]);
+ SNDERR("Invalid slave channel (%d) in binding", channels_map[k]);
return -EINVAL;
}
if (slave_map[channels_map[k]]) {
- ERR("Repeated slave channel (%d) in binding", channels_map[k]);
+ SNDERR("Repeated slave channel (%d) in binding", channels_map[k]);
return -EINVAL;
}
slave_map[channels_map[k]] = 1;
unsigned int k;
for (k = 0; k < sh->channels_count; ++k) {
if (slave_map[sh->slave_channels[k]]) {
- ERR("Slave channel %d is already in use", sh->slave_channels[k]);
+ SNDERR("Slave channel %d is already in use", sh->slave_channels[k]);
Pthread_mutex_unlock(&slave->mutex);
close(sd[0]);
close(sd[1]);
if (strcmp(id, "sname") == 0) {
err = snd_config_get_string(n, &sname);
if (err < 0) {
- ERR("Invalid type for %s", id);
+ SNDERR("Invalid type for %s", id);
return -EINVAL;
}
continue;
const char *f;
err = snd_config_get_string(n, &f);
if (err < 0) {
- ERR("Invalid type for %s", id);
+ SNDERR("Invalid type for %s", id);
return -EINVAL;
}
sformat = snd_pcm_format_value(f);
if (sformat == SND_PCM_FORMAT_UNKNOWN) {
- ERR("Unknown format %s", f);
+ SNDERR("Unknown format %s", f);
return -EINVAL;
}
continue;
if (strcmp(id, "schannels") == 0) {
err = snd_config_get_integer(n, &schannels_count);
if (err < 0) {
- ERR("Invalid type for %s", id);
+ SNDERR("Invalid type for %s", id);
return -EINVAL;
}
continue;
if (strcmp(id, "srate") == 0) {
err = snd_config_get_integer(n, &srate);
if (err < 0) {
- ERR("Invalid type for %s", id);
+ SNDERR("Invalid type for %s", id);
return -EINVAL;
}
continue;
}
if (strcmp(id, "binding") == 0) {
if (snd_config_get_type(n) != SND_CONFIG_TYPE_COMPOUND) {
- ERR("Invalid type for %s", id);
+ SNDERR("Invalid type for %s", id);
return -EINVAL;
}
binding = n;
continue;
}
- ERR("Unknown field %s", id);
+ SNDERR("Unknown field %s", id);
return -EINVAL;
}
if (!sname) {
- ERR("sname is not defined");
+ SNDERR("sname is not defined");
return -EINVAL;
}
if (!binding) {
- ERR("binding is not defined");
+ SNDERR("binding is not defined");
return -EINVAL;
}
snd_config_for_each(i, next, binding) {
errno = 0;
cchannel = strtol(id, &p, 10);
if (errno || *p || cchannel < 0) {
- ERR("Invalid client channel in binding: %s", id);
+ SNDERR("Invalid client channel in binding: %s", id);
return -EINVAL;
}
if ((unsigned)cchannel >= channels_count)
channels_count = cchannel + 1;
}
if (channels_count == 0) {
- ERR("No bindings defined");
+ SNDERR("No bindings defined");
return -EINVAL;
}
channels_map = calloc(channels_count, sizeof(*channels_map));
if (err != 1)
return -EBADFD;
if (ctrl->cmd) {
- ERR("Server has not done the cmd");
+ SNDERR("Server has not done the cmd");
return -EBADFD;
}
return ctrl->result;
if (err != 1)
return -EBADFD;
if (ctrl->cmd) {
- ERR("Server has not done the cmd");
+ SNDERR("Server has not done the cmd");
return -EBADFD;
}
return ctrl->result;
result = make_local_socket(socket);
if (result < 0) {
- ERR("server for socket %s is not running", socket);
+ SNDERR("server for socket %s is not running", socket);
goto _err;
}
sock = result;
goto _err;
}
if ((size_t) err != reqlen) {
- ERR("write size error");
+ SNDERR("write size error");
result = -EINVAL;
goto _err;
}
goto _err;
}
if (err != sizeof(ans)) {
- ERR("read size error");
+ SNDERR("read size error");
result = -EINVAL;
goto _err;
}
if (strcmp(id, "server") == 0) {
err = snd_config_get_string(n, &server);
if (err < 0) {
- ERR("Invalid type for %s", id);
+ SNDERR("Invalid type for %s", id);
return -EINVAL;
}
continue;
if (strcmp(id, "sname") == 0) {
err = snd_config_get_string(n, &sname);
if (err < 0) {
- ERR("Invalid type for %s", id);
+ SNDERR("Invalid type for %s", id);
return -EINVAL;
}
continue;
}
- ERR("Unknown field %s", id);
+ SNDERR("Unknown field %s", id);
return -EINVAL;
}
if (!sname) {
- ERR("sname is not defined");
+ SNDERR("sname is not defined");
return -EINVAL;
}
if (!server) {
- ERR("server is not defined");
+ SNDERR("server is not defined");
return -EINVAL;
}
err = snd_config_searchv(snd_config, &sconfig, "server", server, 0);
if (err < 0) {
- ERR("Unknown server %s", server);
+ SNDERR("Unknown server %s", server);
return -EINVAL;
}
snd_config_for_each(i, next, sconfig) {
if (strcmp(id, "host") == 0) {
err = snd_config_get_string(n, &host);
if (err < 0) {
- ERR("Invalid type for %s", id);
+ SNDERR("Invalid type for %s", id);
return -EINVAL;
}
continue;
if (strcmp(id, "socket") == 0) {
err = snd_config_get_string(n, &socket);
if (err < 0) {
- ERR("Invalid type for %s", id);
+ SNDERR("Invalid type for %s", id);
return -EINVAL;
}
continue;
if (strcmp(id, "port") == 0) {
err = snd_config_get_integer(n, &port);
if (err < 0) {
- ERR("Invalid type for %s", id);
+ SNDERR("Invalid type for %s", id);
return -EINVAL;
}
continue;
}
- ERR("Unknown field %s", id);
+ SNDERR("Unknown field %s", id);
return -EINVAL;
}
if (!host) {
- ERR("host is not defined");
+ SNDERR("host is not defined");
return -EINVAL;
}
if (!socket) {
- ERR("socket is not defined");
+ SNDERR("socket is not defined");
return -EINVAL;
}
h = gethostbyname(host);
if (!h) {
- ERR("Cannot resolve %s", host);
+ SNDERR("Cannot resolve %s", host);
return -EINVAL;
}
local = is_local(h);
if (!local) {
- ERR("%s is not the local host", host);
+ SNDERR("%s is not the local host", host);
return -EINVAL;
}
return snd_pcm_shm_open(pcmp, name, socket, sname, stream, mode);
err = sscanf(name, "hw:%d,%d", &card, &dev);
if (err == 2)
return snd_rawmidi_hw_open(inputp, outputp, name, card, dev, -1, mode);
- ERR("Unknown RAWMIDI %s", name);
+ SNDERR("Unknown RAWMIDI %s", name);
return -ENOENT;
}
if (snd_config_get_type(rawmidi_conf) != SND_CONFIG_TYPE_COMPOUND) {
- ERR("Invalid type for RAWMIDI %s definition", name);
+ SNDERR("Invalid type for RAWMIDI %s definition", name);
return -EINVAL;
}
err = snd_config_search(rawmidi_conf, "type", &conf);
if (err < 0) {
- ERR("type is not defined");
+ SNDERR("type is not defined");
return err;
}
err = snd_config_get_string(conf, &str);
if (err < 0) {
- ERR("Invalid type for %s", snd_config_get_id(conf));
+ SNDERR("Invalid type for %s", snd_config_get_id(conf));
return err;
}
err = snd_config_searchv(snd_config, &type_conf, "rawmiditype", str, 0);
if (err < 0) {
- ERR("Unknown RAWMIDI type %s", str);
+ SNDERR("Unknown RAWMIDI type %s", str);
return err;
}
snd_config_for_each(i, next, type_conf) {
if (strcmp(id, "lib") == 0) {
err = snd_config_get_string(n, &lib);
if (err < 0) {
- ERR("Invalid type for %s", id);
+ SNDERR("Invalid type for %s", id);
return -EINVAL;
}
continue;
if (strcmp(id, "open") == 0) {
err = snd_config_get_string(n, &open);
if (err < 0) {
- ERR("Invalid type for %s", id);
+ SNDERR("Invalid type for %s", id);
return -EINVAL;
}
continue;
- ERR("Unknown field %s", id);
+ SNDERR("Unknown field %s", id);
return -EINVAL;
}
}
if (!open) {
- ERR("open is not defined");
+ SNDERR("open is not defined");
return -EINVAL;
}
if (!lib)
lib = "libasound.so";
h = dlopen(lib, RTLD_NOW);
if (!h) {
- ERR("Cannot open shared library %s", lib);
+ SNDERR("Cannot open shared library %s", lib);
return -ENOENT;
}
open_func = dlsym(h, open);
dlclose(h);
if (!open_func) {
- ERR("symbol %s is not defined inside %s", open, lib);
+ SNDERR("symbol %s is not defined inside %s", open, lib);
return -ENXIO;
}
err = open_func(inputp, outputp, name, rawmidi_conf, mode);
if (err < 0) {
if (strcmp(name, "hw") == 0)
return snd_seq_hw_open(seqp, name, streams, mode);
- ERR("Unknown SEQ %s", name);
+ SNDERR("Unknown SEQ %s", name);
return -ENOENT;
}
if (snd_config_get_type(seq_conf) != SND_CONFIG_TYPE_COMPOUND) {
- ERR("Invalid type for SEQ %s definition", name);
+ SNDERR("Invalid type for SEQ %s definition", name);
return -EINVAL;
}
err = snd_config_search(seq_conf, "type", &conf);
if (err < 0) {
- ERR("type is not defined");
+ SNDERR("type is not defined");
return err;
}
err = snd_config_get_string(conf, &str);
if (err < 0) {
- ERR("Invalid type for %s", snd_config_get_id(conf));
+ SNDERR("Invalid type for %s", snd_config_get_id(conf));
return err;
}
err = snd_config_searchv(snd_config, &type_conf, "seqtype", str, 0);
if (err < 0) {
- ERR("Unknown SEQ type %s", str);
+ SNDERR("Unknown SEQ type %s", str);
return err;
}
snd_config_for_each(i, next, type_conf) {
if (strcmp(id, "lib") == 0) {
err = snd_config_get_string(n, &lib);
if (err < 0) {
- ERR("Invalid type for %s", id);
+ SNDERR("Invalid type for %s", id);
return -EINVAL;
}
continue;
if (strcmp(id, "open") == 0) {
err = snd_config_get_string(n, &open);
if (err < 0) {
- ERR("Invalid type for %s", id);
+ SNDERR("Invalid type for %s", id);
return -EINVAL;
}
continue;
- ERR("Unknown field %s", id);
+ SNDERR("Unknown field %s", id);
return -EINVAL;
}
}
if (!open) {
- ERR("open is not defined");
+ SNDERR("open is not defined");
return -EINVAL;
}
if (!lib)
lib = "libasound.so";
h = dlopen(lib, RTLD_NOW);
if (!h) {
- ERR("Cannot open shared library %s", lib);
+ SNDERR("Cannot open shared library %s", lib);
return -ENOENT;
}
open_func = dlsym(h, open);
dlclose(h);
if (!open_func) {
- ERR("symbol %s is not defined inside %s", open, lib);
+ SNDERR("symbol %s is not defined inside %s", open, lib);
return -ENXIO;
}
return open_func(seqp, name, seq_conf, streams, mode);