Added abstraction layer to controls. Added client/server support to controls. Cleaned private_data use for PCMs. Cleaned aserver

This commit is contained in:
Abramo Bagnara 2000-09-11 15:49:10 +00:00
parent 1acf1f3fb9
commit df35e8457a
18 changed files with 1623 additions and 778 deletions

View file

@ -788,7 +788,7 @@ static int _snd_pcm_open_client(snd_pcm_t **handlep, snd_config_t *conf,
} else {
if (port < 0 || !name)
return -EINVAL;
return snd_pcm_client_create(handlep, host, port, SND_TRANSPORT_TYPE_SHM, name, stream, mode);
return snd_pcm_client_create(handlep, host, port, SND_TRANSPORT_TYPE_TCP, name, stream, mode);
}
}

View file

@ -38,7 +38,6 @@
#include "aserver.h"
typedef struct {
snd_pcm_t *handle;
int data_fd;
int ctrl_fd;
union {
@ -80,13 +79,14 @@ int receive_fd(int socket, void *data, size_t len, int *fd)
return ret;
}
static void clean_state(snd_pcm_client_t *client)
static void clean_poll(snd_pcm_t *pcm)
{
snd_pcm_client_t *client = pcm->private;
struct pollfd pfd;
int err;
char buf[1];
pfd.fd = client->data_fd;
switch (client->handle->stream) {
switch (pcm->stream) {
case SND_PCM_STREAM_PLAYBACK:
pfd.events = POLLOUT;
while (1) {
@ -112,11 +112,13 @@ static void clean_state(snd_pcm_client_t *client)
}
}
static int snd_pcm_client_shm_action(snd_pcm_client_t *client)
static int snd_pcm_client_shm_action(snd_pcm_t *pcm)
{
snd_pcm_client_t *client = pcm->private;
int err;
char buf[1];
snd_pcm_client_shm_t *ctrl = client->u.shm.ctrl;
clean_poll(pcm);
err = write(client->ctrl_fd, buf, 1);
if (err != 1)
return -EBADFD;
@ -130,12 +132,14 @@ static int snd_pcm_client_shm_action(snd_pcm_client_t *client)
return 0;
}
static int snd_pcm_client_shm_action_fd(snd_pcm_client_t *client)
static int snd_pcm_client_shm_action_fd(snd_pcm_t *pcm)
{
snd_pcm_client_t *client = pcm->private;
int err;
char buf[1];
snd_pcm_client_shm_t *ctrl = client->u.shm.ctrl;
int fd;
clean_poll(pcm);
err = write(client->ctrl_fd, buf, 1);
if (err != 1)
return -EBADFD;
@ -151,242 +155,242 @@ static int snd_pcm_client_shm_action_fd(snd_pcm_client_t *client)
return fd;
}
static int snd_pcm_client_shm_close(void *private)
static int snd_pcm_client_shm_close(snd_pcm_t *pcm)
{
snd_pcm_client_t *client = (snd_pcm_client_t*) private;
snd_pcm_client_t *client = pcm->private;
snd_pcm_client_shm_t *ctrl = client->u.shm.ctrl;
int result;
ctrl->cmd = SND_PCM_IOCTL_CLOSE;
result = snd_pcm_client_shm_action(client);
result = snd_pcm_client_shm_action(pcm);
if (result >= 0)
result = ctrl->result;
shmdt((void *)ctrl);
close(client->data_fd);
close(client->ctrl_fd);
free(client);
return result;
}
static int snd_pcm_client_shm_nonblock(void *private, int nonblock)
static int snd_pcm_client_shm_nonblock(snd_pcm_t *pcm, int nonblock)
{
/* FIXME */
return 0;
}
static int snd_pcm_client_shm_info(void *private, snd_pcm_info_t * info)
static int snd_pcm_client_shm_info(snd_pcm_t *pcm, snd_pcm_info_t * info)
{
snd_pcm_client_t *client = (snd_pcm_client_t*) private;
snd_pcm_client_t *client = pcm->private;
snd_pcm_client_shm_t *ctrl = client->u.shm.ctrl;
int err;
// ctrl->u.info = *info;
ctrl->cmd = SND_PCM_IOCTL_INFO;
err = snd_pcm_client_shm_action(client);
err = snd_pcm_client_shm_action(pcm);
if (err < 0)
return err;
memcpy(info, &ctrl->u.info, sizeof(*info));
*info = ctrl->u.info;
return ctrl->result;
}
static int snd_pcm_client_shm_params_info(void *private, snd_pcm_params_info_t * info)
static int snd_pcm_client_shm_params_info(snd_pcm_t *pcm, snd_pcm_params_info_t * info)
{
snd_pcm_client_t *client = (snd_pcm_client_t*) private;
snd_pcm_client_t *client = pcm->private;
snd_pcm_client_shm_t *ctrl = client->u.shm.ctrl;
int err;
ctrl->cmd = SND_PCM_IOCTL_PARAMS_INFO;
ctrl->u.params_info = *info;
err = snd_pcm_client_shm_action(client);
err = snd_pcm_client_shm_action(pcm);
if (err < 0)
return err;
*info = ctrl->u.params_info;
return ctrl->result;
}
static int snd_pcm_client_shm_params(void *private, snd_pcm_params_t * params)
static int snd_pcm_client_shm_params(snd_pcm_t *pcm, snd_pcm_params_t * params)
{
snd_pcm_client_t *client = (snd_pcm_client_t*) private;
snd_pcm_client_t *client = pcm->private;
snd_pcm_client_shm_t *ctrl = client->u.shm.ctrl;
int err;
ctrl->cmd = SND_PCM_IOCTL_PARAMS;
ctrl->u.params = *params;
err = snd_pcm_client_shm_action(client);
err = snd_pcm_client_shm_action(pcm);
if (err < 0)
return err;
*params = ctrl->u.params;
return ctrl->result;
}
static int snd_pcm_client_shm_setup(void *private, snd_pcm_setup_t * setup)
static int snd_pcm_client_shm_setup(snd_pcm_t *pcm, snd_pcm_setup_t * setup)
{
snd_pcm_client_t *client = (snd_pcm_client_t*) private;
snd_pcm_client_t *client = pcm->private;
snd_pcm_client_shm_t *ctrl = client->u.shm.ctrl;
int err;
ctrl->cmd = SND_PCM_IOCTL_SETUP;
// ctrl->u.setup = *setup;
err = snd_pcm_client_shm_action(client);
err = snd_pcm_client_shm_action(pcm);
if (err < 0)
return err;
*setup = ctrl->u.setup;
return ctrl->result;
}
static int snd_pcm_client_shm_channel_info(void *private, snd_pcm_channel_info_t * info)
static int snd_pcm_client_shm_channel_info(snd_pcm_t *pcm, snd_pcm_channel_info_t * info)
{
snd_pcm_client_t *client = (snd_pcm_client_t*) private;
snd_pcm_client_t *client = pcm->private;
snd_pcm_client_shm_t *ctrl = client->u.shm.ctrl;
int err;
ctrl->cmd = SND_PCM_IOCTL_CHANNEL_INFO;
ctrl->u.channel_info = *info;
err = snd_pcm_client_shm_action(client);
err = snd_pcm_client_shm_action(pcm);
if (err < 0)
return err;
*info = ctrl->u.channel_info;
return ctrl->result;
}
static int snd_pcm_client_shm_channel_params(void *private, snd_pcm_channel_params_t * params)
static int snd_pcm_client_shm_channel_params(snd_pcm_t *pcm, snd_pcm_channel_params_t * params)
{
snd_pcm_client_t *client = (snd_pcm_client_t*) private;
snd_pcm_client_t *client = pcm->private;
snd_pcm_client_shm_t *ctrl = client->u.shm.ctrl;
int err;
ctrl->cmd = SND_PCM_IOCTL_CHANNEL_PARAMS;
ctrl->u.channel_params = *params;
err = snd_pcm_client_shm_action(client);
err = snd_pcm_client_shm_action(pcm);
if (err < 0)
return err;
*params = ctrl->u.channel_params;
return ctrl->result;
}
static int snd_pcm_client_shm_channel_setup(void *private, snd_pcm_channel_setup_t * setup)
static int snd_pcm_client_shm_channel_setup(snd_pcm_t *pcm, snd_pcm_channel_setup_t * setup)
{
snd_pcm_client_t *client = (snd_pcm_client_t*) private;
snd_pcm_client_t *client = pcm->private;
snd_pcm_client_shm_t *ctrl = client->u.shm.ctrl;
int err;
ctrl->cmd = SND_PCM_IOCTL_CHANNEL_SETUP;
ctrl->u.channel_setup = *setup;
err = snd_pcm_client_shm_action(client);
err = snd_pcm_client_shm_action(pcm);
if (err < 0)
return err;
*setup = ctrl->u.channel_setup;
return ctrl->result;
}
static int snd_pcm_client_shm_status(void *private, snd_pcm_status_t * status)
static int snd_pcm_client_shm_status(snd_pcm_t *pcm, snd_pcm_status_t * status)
{
snd_pcm_client_t *client = (snd_pcm_client_t*) private;
snd_pcm_client_t *client = pcm->private;
snd_pcm_client_shm_t *ctrl = client->u.shm.ctrl;
int err;
ctrl->cmd = SND_PCM_IOCTL_STATUS;
// ctrl->u.status = *status;
err = snd_pcm_client_shm_action(client);
err = snd_pcm_client_shm_action(pcm);
if (err < 0)
return err;
*status = ctrl->u.status;
return ctrl->result;
}
static int snd_pcm_client_shm_state(void *private)
static int snd_pcm_client_shm_state(snd_pcm_t *pcm)
{
snd_pcm_status_t status;
int err = snd_pcm_client_shm_status(private, &status);
int err = snd_pcm_client_shm_status(pcm, &status);
if (err < 0)
return err;
return status.state;
}
static ssize_t snd_pcm_client_shm_frame_io(void *private, int update)
static ssize_t snd_pcm_client_shm_frame_io(snd_pcm_t *pcm, int update)
{
snd_pcm_client_t *client = (snd_pcm_client_t*) private;
snd_pcm_client_t *client = pcm->private;
snd_pcm_client_shm_t *ctrl = client->u.shm.ctrl;
int err;
ctrl->cmd = SND_PCM_IOCTL_FRAME_IO;
ctrl->u.frame_io = update;
err = snd_pcm_client_shm_action(client);
err = snd_pcm_client_shm_action(pcm);
if (err < 0)
return err;
return ctrl->result;
}
static int snd_pcm_client_shm_prepare(void *private)
static int snd_pcm_client_shm_prepare(snd_pcm_t *pcm)
{
snd_pcm_client_t *client = (snd_pcm_client_t*) private;
snd_pcm_client_t *client = pcm->private;
snd_pcm_client_shm_t *ctrl = client->u.shm.ctrl;
int err;
ctrl->cmd = SND_PCM_IOCTL_PREPARE;
err = snd_pcm_client_shm_action(client);
err = snd_pcm_client_shm_action(pcm);
if (err < 0)
return err;
return ctrl->result;
}
static int snd_pcm_client_shm_go(void *private)
static int snd_pcm_client_shm_go(snd_pcm_t *pcm)
{
snd_pcm_client_t *client = (snd_pcm_client_t*) private;
snd_pcm_client_t *client = pcm->private;
snd_pcm_client_shm_t *ctrl = client->u.shm.ctrl;
int err;
ctrl->cmd = SND_PCM_IOCTL_GO;
err = snd_pcm_client_shm_action(client);
err = snd_pcm_client_shm_action(pcm);
if (err < 0)
return err;
return ctrl->result;
}
static int snd_pcm_client_shm_drain(void *private)
static int snd_pcm_client_shm_drain(snd_pcm_t *pcm)
{
snd_pcm_client_t *client = (snd_pcm_client_t*) private;
snd_pcm_client_t *client = pcm->private;
snd_pcm_client_shm_t *ctrl = client->u.shm.ctrl;
int err;
ctrl->cmd = SND_PCM_IOCTL_DRAIN;
err = snd_pcm_client_shm_action(client);
err = snd_pcm_client_shm_action(pcm);
if (err < 0)
return err;
return ctrl->result;
}
static int snd_pcm_client_shm_flush(void *private)
static int snd_pcm_client_shm_flush(snd_pcm_t *pcm)
{
snd_pcm_client_t *client = (snd_pcm_client_t*) private;
snd_pcm_client_t *client = pcm->private;
snd_pcm_client_shm_t *ctrl = client->u.shm.ctrl;
int err;
ctrl->cmd = SND_PCM_IOCTL_FLUSH;
err = snd_pcm_client_shm_action(client);
err = snd_pcm_client_shm_action(pcm);
if (err < 0)
return err;
return ctrl->result;
}
static int snd_pcm_client_shm_pause(void *private, int enable)
static int snd_pcm_client_shm_pause(snd_pcm_t *pcm, int enable)
{
snd_pcm_client_t *client = (snd_pcm_client_t*) private;
snd_pcm_client_t *client = pcm->private;
snd_pcm_client_shm_t *ctrl = client->u.shm.ctrl;
int err;
ctrl->cmd = SND_PCM_IOCTL_PAUSE;
ctrl->u.pause = enable;
err = snd_pcm_client_shm_action(client);
err = snd_pcm_client_shm_action(pcm);
if (err < 0)
return err;
return ctrl->result;
}
static ssize_t snd_pcm_client_shm_frame_data(void *private, off_t offset)
static ssize_t snd_pcm_client_shm_frame_data(snd_pcm_t *pcm, off_t offset)
{
snd_pcm_client_t *client = (snd_pcm_client_t*) private;
snd_pcm_client_t *client = pcm->private;
snd_pcm_client_shm_t *ctrl = client->u.shm.ctrl;
int err;
ctrl->cmd = SND_PCM_IOCTL_FRAME_DATA;
ctrl->u.frame_data = offset;
clean_state(client);
err = snd_pcm_client_shm_action(client);
err = snd_pcm_client_shm_action(pcm);
if (err < 0)
return err;
return ctrl->result;
}
static ssize_t snd_pcm_client_shm_write(void *private, snd_timestamp_t *tstamp, const void *buffer, size_t size)
static ssize_t snd_pcm_client_shm_write(snd_pcm_t *pcm, snd_timestamp_t *tstamp, const void *buffer, size_t size)
{
snd_pcm_client_t *client = (snd_pcm_client_t*) private;
snd_pcm_client_t *client = pcm->private;
snd_pcm_client_shm_t *ctrl = client->u.shm.ctrl;
size_t maxsize = PCM_SHM_DATA_MAXLEN;
size_t bytes = snd_pcm_frames_to_bytes(client->handle, size);
size_t bytes = snd_pcm_frames_to_bytes(pcm, size);
int err;
if (bytes > maxsize)
return -EINVAL;
@ -394,21 +398,20 @@ static ssize_t snd_pcm_client_shm_write(void *private, snd_timestamp_t *tstamp,
// ctrl->u.write.tstamp = *tstamp;
ctrl->u.write.count = size;
memcpy(ctrl->data, buffer, bytes);
clean_state(client);
err = snd_pcm_client_shm_action(client);
err = snd_pcm_client_shm_action(pcm);
if (err < 0)
return err;
return ctrl->result;
}
static ssize_t snd_pcm_client_shm_writev(void *private, snd_timestamp_t *tstamp, const struct iovec *vector, unsigned long count)
static ssize_t snd_pcm_client_shm_writev(snd_pcm_t *pcm, snd_timestamp_t *tstamp, const struct iovec *vector, unsigned long count)
{
/* FIXME: interleaved */
snd_pcm_client_t *client = (snd_pcm_client_t*) private;
snd_pcm_client_t *client = pcm->private;
snd_pcm_client_shm_t *ctrl = client->u.shm.ctrl;
size_t vecsize = count * sizeof(struct iovec);
size_t maxsize = PCM_SHM_DATA_MAXLEN;
int bits_per_sample = client->handle->bits_per_sample;
int bits_per_sample = pcm->bits_per_sample;
char *base;
struct iovec *vec;
unsigned long k;
@ -430,44 +433,42 @@ static ssize_t snd_pcm_client_shm_writev(void *private, snd_timestamp_t *tstamp,
vec[k].iov_base = (void *) ofs;
ofs += len;
}
clean_state(client);
err = snd_pcm_client_shm_action(client);
err = snd_pcm_client_shm_action(pcm);
if (err < 0)
return err;
return ctrl->result;
}
static ssize_t snd_pcm_client_shm_read(void *private, snd_timestamp_t *tstamp, void *buffer, size_t size)
static ssize_t snd_pcm_client_shm_read(snd_pcm_t *pcm, snd_timestamp_t *tstamp, void *buffer, size_t size)
{
snd_pcm_client_t *client = (snd_pcm_client_t*) private;
snd_pcm_client_t *client = pcm->private;
snd_pcm_client_shm_t *ctrl = client->u.shm.ctrl;
size_t maxsize = PCM_SHM_DATA_MAXLEN;
size_t bytes = snd_pcm_frames_to_bytes(client->handle, size);
size_t bytes = snd_pcm_frames_to_bytes(pcm, size);
int err;
if (bytes > maxsize)
return -EINVAL;
ctrl->cmd = SND_PCM_IOCTL_READ_FRAMES;
// ctrl->u.read.tstamp = *tstamp;
ctrl->u.read.count = size;
clean_state(client);
err = snd_pcm_client_shm_action(client);
err = snd_pcm_client_shm_action(pcm);
if (err < 0)
return err;
if (ctrl->result <= 0)
return ctrl->result;
bytes = snd_pcm_frames_to_bytes(client->handle, ctrl->result);
bytes = snd_pcm_frames_to_bytes(pcm, ctrl->result);
memcpy(buffer, ctrl->data, bytes);
return ctrl->result;
}
ssize_t snd_pcm_client_shm_readv(void *private, snd_timestamp_t *tstamp, const struct iovec *vector, unsigned long count)
ssize_t snd_pcm_client_shm_readv(snd_pcm_t *pcm, snd_timestamp_t *tstamp, const struct iovec *vector, unsigned long count)
{
/* FIXME: interleaved */
snd_pcm_client_t *client = (snd_pcm_client_t*) private;
snd_pcm_client_t *client = pcm->private;
snd_pcm_client_shm_t *ctrl = client->u.shm.ctrl;
size_t vecsize = count * sizeof(struct iovec);
size_t maxsize = PCM_SHM_DATA_MAXLEN;
int bits_per_sample = client->handle->bits_per_sample;
int bits_per_sample = pcm->bits_per_sample;
char *base;
struct iovec *vec;
unsigned long k;
@ -488,13 +489,12 @@ ssize_t snd_pcm_client_shm_readv(void *private, snd_timestamp_t *tstamp, const s
vec[k].iov_base = (void *) ofs;
ofs += len;
}
clean_state(client);
err = snd_pcm_client_shm_action(client);
err = snd_pcm_client_shm_action(pcm);
if (err < 0)
return err;
if (ctrl->result <= 0)
return ctrl->result;
bytes = snd_pcm_frames_to_bytes(client->handle, ctrl->result);
bytes = snd_pcm_frames_to_bytes(pcm, ctrl->result);
ofs = 0;
for (k = 0; k < count; ++k) {
/* FIXME: optimize partial read */
@ -505,14 +505,14 @@ ssize_t snd_pcm_client_shm_readv(void *private, snd_timestamp_t *tstamp, const s
return ctrl->result;
}
static int snd_pcm_client_shm_mmap_status(void *private, snd_pcm_mmap_status_t **status)
static int snd_pcm_client_shm_mmap_status(snd_pcm_t *pcm, snd_pcm_mmap_status_t **status)
{
snd_pcm_client_t *client = (snd_pcm_client_t*) private;
snd_pcm_client_t *client = pcm->private;
snd_pcm_client_shm_t *ctrl = client->u.shm.ctrl;
void *ptr;
int fd;
ctrl->cmd = SND_PCM_IOCTL_MMAP_STATUS;
fd = snd_pcm_client_shm_action_fd(client);
fd = snd_pcm_client_shm_action_fd(pcm);
if (fd < 0)
return fd;
ptr = mmap(NULL, sizeof(snd_pcm_mmap_status_t), PROT_READ, MAP_FILE|MAP_SHARED,
@ -524,14 +524,14 @@ static int snd_pcm_client_shm_mmap_status(void *private, snd_pcm_mmap_status_t *
return 0;
}
static int snd_pcm_client_shm_mmap_control(void *private, snd_pcm_mmap_control_t **control)
static int snd_pcm_client_shm_mmap_control(snd_pcm_t *pcm, snd_pcm_mmap_control_t **control)
{
snd_pcm_client_t *client = (snd_pcm_client_t*) private;
snd_pcm_client_t *client = pcm->private;
snd_pcm_client_shm_t *ctrl = client->u.shm.ctrl;
void *ptr;
int fd;
ctrl->cmd = SND_PCM_IOCTL_MMAP_CONTROL;
fd = snd_pcm_client_shm_action_fd(client);
fd = snd_pcm_client_shm_action_fd(pcm);
if (fd < 0)
return fd;
ptr = mmap(NULL, sizeof(snd_pcm_mmap_control_t), PROT_READ|PROT_WRITE, MAP_FILE|MAP_SHARED,
@ -543,18 +543,18 @@ static int snd_pcm_client_shm_mmap_control(void *private, snd_pcm_mmap_control_t
return 0;
}
static int snd_pcm_client_shm_mmap_data(void *private, void **buffer, size_t bsize ATTRIBUTE_UNUSED)
static int snd_pcm_client_shm_mmap_data(snd_pcm_t *pcm, void **buffer, size_t bsize ATTRIBUTE_UNUSED)
{
snd_pcm_client_t *client = (snd_pcm_client_t*) private;
snd_pcm_client_t *client = pcm->private;
snd_pcm_client_shm_t *ctrl = client->u.shm.ctrl;
void *ptr;
int prot;
int fd;
ctrl->cmd = SND_PCM_IOCTL_MMAP_DATA;
fd = snd_pcm_client_shm_action_fd(client);
fd = snd_pcm_client_shm_action_fd(pcm);
if (fd < 0)
return fd;
prot = client->handle->stream == SND_PCM_STREAM_PLAYBACK ? PROT_WRITE : PROT_READ;
prot = pcm->stream == SND_PCM_STREAM_PLAYBACK ? PROT_WRITE : PROT_READ;
ptr = mmap(NULL, bsize, prot, MAP_FILE|MAP_SHARED,
fd, SND_PCM_MMAP_OFFSET_DATA);
close(fd);
@ -564,14 +564,14 @@ static int snd_pcm_client_shm_mmap_data(void *private, void **buffer, size_t bsi
return 0;
}
static int snd_pcm_client_shm_munmap_status(void *private ATTRIBUTE_UNUSED, snd_pcm_mmap_status_t *status ATTRIBUTE_UNUSED)
static int snd_pcm_client_shm_munmap_status(snd_pcm_t *pcm ATTRIBUTE_UNUSED, snd_pcm_mmap_status_t *status ATTRIBUTE_UNUSED)
{
#if 0
snd_pcm_client_t *client = (snd_pcm_client_t*) private;
snd_pcm_client_t *client = pcm->private;
snd_pcm_client_shm_t *ctrl = client->u.shm.ctrl;
int err;
ctrl->cmd = SND_PCM_IOCTL_MUNMAP_STATUS;
err = snd_pcm_client_shm_action(client);
err = snd_pcm_client_shm_action(pcm);
if (err < 0)
return err;
return ctrl->result;
@ -582,14 +582,14 @@ static int snd_pcm_client_shm_munmap_status(void *private ATTRIBUTE_UNUSED, snd_
#endif
}
static int snd_pcm_client_shm_munmap_control(void *private ATTRIBUTE_UNUSED, snd_pcm_mmap_control_t *control ATTRIBUTE_UNUSED)
static int snd_pcm_client_shm_munmap_control(snd_pcm_t *pcm ATTRIBUTE_UNUSED, snd_pcm_mmap_control_t *control ATTRIBUTE_UNUSED)
{
#if 0
snd_pcm_client_t *client = (snd_pcm_client_t*) private;
snd_pcm_client_t *client = pcm->private;
snd_pcm_client_shm_t *ctrl = client->u.shm.ctrl;
int err;
ctrl->cmd = SND_PCM_IOCTL_MUNMAP_CONTROL;
err = snd_pcm_client_shm_action(client);
err = snd_pcm_client_shm_action(pcm);
if (err < 0)
return err;
return ctrl->result;
@ -600,14 +600,14 @@ static int snd_pcm_client_shm_munmap_control(void *private ATTRIBUTE_UNUSED, snd
#endif
}
static int snd_pcm_client_shm_munmap_data(void *private ATTRIBUTE_UNUSED, void *buffer, size_t bsize)
static int snd_pcm_client_shm_munmap_data(snd_pcm_t *pcm ATTRIBUTE_UNUSED, void *buffer, size_t bsize)
{
#if 0
snd_pcm_client_t *client = (snd_pcm_client_t*) private;
snd_pcm_client_t *client = pcm->private;
snd_pcm_client_shm_t *ctrl = client->u.shm.ctrl;
int err;
ctrl->cmd = SND_PCM_IOCTL_MUNMAP_DATA;
err = snd_pcm_client_shm_action(client);
err = snd_pcm_client_shm_action(pcm);
if (err < 0)
return err;
return ctrl->result;
@ -618,26 +618,24 @@ static int snd_pcm_client_shm_munmap_data(void *private ATTRIBUTE_UNUSED, void *
#endif
}
static int snd_pcm_client_file_descriptor(void *private)
static int snd_pcm_client_file_descriptor(snd_pcm_t *pcm)
{
snd_pcm_client_t *client = (snd_pcm_client_t*) private;
snd_pcm_client_t *client = pcm->private;
return client->data_fd;
}
static int snd_pcm_client_channels_mask(void *private ATTRIBUTE_UNUSED,
static int snd_pcm_client_channels_mask(snd_pcm_t *pcm ATTRIBUTE_UNUSED,
bitset_t *client_vmask ATTRIBUTE_UNUSED)
{
return 0;
}
static void snd_pcm_client_dump(void *private, FILE *fp)
static void snd_pcm_client_dump(snd_pcm_t *pcm, FILE *fp)
{
snd_pcm_client_t *client = (snd_pcm_client_t*) private;
snd_pcm_t *handle = client->handle;
fprintf(fp, "Client PCM\n");
if (handle->valid_setup) {
if (pcm->valid_setup) {
fprintf(fp, "\nIts setup is:\n");
snd_pcm_dump_setup(handle, fp);
snd_pcm_dump_setup(pcm, fp);
}
}
@ -844,7 +842,6 @@ int snd_pcm_client_create(snd_pcm_t **handlep, char *host, int port, int transpo
goto _err;
}
client->handle = handle;
client->data_fd = fds[0];
client->ctrl_fd = fds[1];
switch (transport) {
@ -855,9 +852,9 @@ int snd_pcm_client_create(snd_pcm_t **handlep, char *host, int port, int transpo
handle->type = SND_PCM_TYPE_CLIENT;
handle->stream = stream;
handle->ops = &snd_pcm_client_ops;
handle->op_arg = client;
handle->op_arg = handle;
handle->fast_ops = &snd_pcm_client_fast_ops;
handle->fast_op_arg = client;
handle->fast_op_arg = handle;
handle->mode = mode;
handle->private = client;
*handlep = handle;

View file

@ -30,7 +30,6 @@
#include "pcm_local.h"
typedef struct {
snd_pcm_t *handle;
int fd;
int card, device, subdevice;
void *mmap_data_ptr;
@ -40,21 +39,21 @@ typedef struct {
#define SND_FILE_PCM_STREAM_CAPTURE "/dev/snd/pcmC%iD%ic"
#define SND_PCM_VERSION_MAX SND_PROTOCOL_VERSION(2, 0, 0)
static int snd_pcm_hw_close(void *private)
static int snd_pcm_hw_close(snd_pcm_t *pcm)
{
snd_pcm_hw_t *hw = (snd_pcm_hw_t*) private;
snd_pcm_hw_t *hw = pcm->private;
int fd = hw->fd;
free(private);
free(hw);
if (fd >= 0)
if (close(fd))
return -errno;
return 0;
}
static int snd_pcm_hw_nonblock(void *private, int nonblock)
static int snd_pcm_hw_nonblock(snd_pcm_t *pcm, int nonblock)
{
long flags;
snd_pcm_hw_t *hw = (snd_pcm_hw_t*) private;
snd_pcm_hw_t *hw = pcm->private;
int fd = hw->fd;
if ((flags = fcntl(fd, F_GETFL)) < 0)
@ -68,63 +67,63 @@ static int snd_pcm_hw_nonblock(void *private, int nonblock)
return 0;
}
static int snd_pcm_hw_info(void *private, snd_pcm_info_t * info)
static int snd_pcm_hw_info(snd_pcm_t *pcm, snd_pcm_info_t * info)
{
snd_pcm_hw_t *hw = (snd_pcm_hw_t*) private;
snd_pcm_hw_t *hw = pcm->private;
int fd = hw->fd;
if (ioctl(fd, SND_PCM_IOCTL_INFO, info) < 0)
return -errno;
return 0;
}
static int snd_pcm_hw_params_info(void *private, snd_pcm_params_info_t * info)
static int snd_pcm_hw_params_info(snd_pcm_t *pcm, snd_pcm_params_info_t * info)
{
snd_pcm_hw_t *hw = (snd_pcm_hw_t*) private;
snd_pcm_hw_t *hw = pcm->private;
int fd = hw->fd;
if (ioctl(fd, SND_PCM_IOCTL_PARAMS_INFO, info) < 0)
return -errno;
return 0;
}
static int snd_pcm_hw_params(void *private, snd_pcm_params_t * params)
static int snd_pcm_hw_params(snd_pcm_t *pcm, snd_pcm_params_t * params)
{
snd_pcm_hw_t *hw = (snd_pcm_hw_t*) private;
snd_pcm_hw_t *hw = pcm->private;
int fd = hw->fd;
if (ioctl(fd, SND_PCM_IOCTL_PARAMS, params) < 0)
return -errno;
return 0;
}
static int snd_pcm_hw_setup(void *private, snd_pcm_setup_t * setup)
static int snd_pcm_hw_setup(snd_pcm_t *pcm, snd_pcm_setup_t * setup)
{
snd_pcm_hw_t *hw = (snd_pcm_hw_t*) private;
snd_pcm_hw_t *hw = pcm->private;
int fd = hw->fd;
if (ioctl(fd, SND_PCM_IOCTL_SETUP, setup) < 0)
return -errno;
return 0;
}
static int snd_pcm_hw_channel_info(void *private, snd_pcm_channel_info_t * info)
static int snd_pcm_hw_channel_info(snd_pcm_t *pcm, snd_pcm_channel_info_t * info)
{
snd_pcm_hw_t *hw = (snd_pcm_hw_t*) private;
snd_pcm_hw_t *hw = pcm->private;
int fd = hw->fd;
if (ioctl(fd, SND_PCM_IOCTL_CHANNEL_INFO, info) < 0)
return -errno;
return 0;
}
static int snd_pcm_hw_channel_params(void *private, snd_pcm_channel_params_t * params)
static int snd_pcm_hw_channel_params(snd_pcm_t *pcm, snd_pcm_channel_params_t * params)
{
snd_pcm_hw_t *hw = (snd_pcm_hw_t*) private;
snd_pcm_hw_t *hw = pcm->private;
int fd = hw->fd;
if (ioctl(fd, SND_PCM_IOCTL_CHANNEL_PARAMS, params) < 0)
return -errno;
return 0;
}
static int snd_pcm_hw_channel_setup(void *private, snd_pcm_channel_setup_t * setup)
static int snd_pcm_hw_channel_setup(snd_pcm_t *pcm, snd_pcm_channel_setup_t * setup)
{
snd_pcm_hw_t *hw = (snd_pcm_hw_t*) private;
snd_pcm_hw_t *hw = pcm->private;
int fd = hw->fd;
if (ioctl(fd, SND_PCM_IOCTL_CHANNEL_SETUP, setup) < 0)
return -errno;
@ -132,18 +131,18 @@ static int snd_pcm_hw_channel_setup(void *private, snd_pcm_channel_setup_t * set
return 0;
}
static int snd_pcm_hw_status(void *private, snd_pcm_status_t * status)
static int snd_pcm_hw_status(snd_pcm_t *pcm, snd_pcm_status_t * status)
{
snd_pcm_hw_t *hw = (snd_pcm_hw_t*) private;
snd_pcm_hw_t *hw = pcm->private;
int fd = hw->fd;
if (ioctl(fd, SND_PCM_IOCTL_STATUS, status) < 0)
return -errno;
return 0;
}
static int snd_pcm_hw_state(void *private)
static int snd_pcm_hw_state(snd_pcm_t *pcm)
{
snd_pcm_hw_t *hw = (snd_pcm_hw_t*) private;
snd_pcm_hw_t *hw = pcm->private;
int fd = hw->fd;
snd_pcm_status_t status;
if (ioctl(fd, SND_PCM_IOCTL_STATUS, status) < 0)
@ -151,9 +150,9 @@ static int snd_pcm_hw_state(void *private)
return status.state;
}
static ssize_t snd_pcm_hw_frame_io(void *private, int update ATTRIBUTE_UNUSED)
static ssize_t snd_pcm_hw_frame_io(snd_pcm_t *pcm, int update ATTRIBUTE_UNUSED)
{
snd_pcm_hw_t *hw = (snd_pcm_hw_t*) private;
snd_pcm_hw_t *hw = pcm->private;
int fd = hw->fd;
ssize_t pos = ioctl(fd, SND_PCM_IOCTL_FRAME_IO);
if (pos < 0)
@ -161,69 +160,68 @@ static ssize_t snd_pcm_hw_frame_io(void *private, int update ATTRIBUTE_UNUSED)
return pos;
}
static int snd_pcm_hw_prepare(void *private)
static int snd_pcm_hw_prepare(snd_pcm_t *pcm)
{
snd_pcm_hw_t *hw = (snd_pcm_hw_t*) private;
snd_pcm_hw_t *hw = pcm->private;
int fd = hw->fd;
if (ioctl(fd, SND_PCM_IOCTL_PREPARE) < 0)
return -errno;
return 0;
}
static int snd_pcm_hw_go(void *private)
static int snd_pcm_hw_go(snd_pcm_t *pcm)
{
snd_pcm_hw_t *hw = (snd_pcm_hw_t*) private;
snd_pcm_hw_t *hw = pcm->private;
int fd = hw->fd;
if (ioctl(fd, SND_PCM_IOCTL_GO) < 0)
return -errno;
return 0;
}
static int snd_pcm_hw_drain(void *private)
static int snd_pcm_hw_drain(snd_pcm_t *pcm)
{
snd_pcm_hw_t *hw = (snd_pcm_hw_t*) private;
snd_pcm_hw_t *hw = pcm->private;
int fd = hw->fd;
if (ioctl(fd, SND_PCM_IOCTL_DRAIN) < 0)
return -errno;
return 0;
}
static int snd_pcm_hw_flush(void *private)
static int snd_pcm_hw_flush(snd_pcm_t *pcm)
{
snd_pcm_hw_t *hw = (snd_pcm_hw_t*) private;
snd_pcm_hw_t *hw = pcm->private;
int fd = hw->fd;
if (ioctl(fd, SND_PCM_IOCTL_FLUSH) < 0)
return -errno;
return 0;
}
static int snd_pcm_hw_pause(void *private, int enable)
static int snd_pcm_hw_pause(snd_pcm_t *pcm, int enable)
{
snd_pcm_hw_t *hw = (snd_pcm_hw_t*) private;
snd_pcm_hw_t *hw = pcm->private;
int fd = hw->fd;
if (ioctl(fd, SND_PCM_IOCTL_PAUSE, enable) < 0)
return -errno;
return 0;
}
static ssize_t snd_pcm_hw_frame_data(void *private, off_t offset)
static ssize_t snd_pcm_hw_frame_data(snd_pcm_t *pcm, off_t offset)
{
ssize_t result;
snd_pcm_hw_t *hw = (snd_pcm_hw_t*) private;
snd_pcm_t *handle = hw->handle;
snd_pcm_hw_t *hw = pcm->private;
int fd = hw->fd;
if (handle->mmap_status && handle->mmap_control)
return snd_pcm_mmap_frame_data(handle, offset);
if (pcm->mmap_status && pcm->mmap_control)
return snd_pcm_mmap_frame_data(pcm, offset);
result = ioctl(fd, SND_PCM_IOCTL_FRAME_DATA, offset);
if (result < 0)
return -errno;
return result;
}
static ssize_t snd_pcm_hw_write(void *private, snd_timestamp_t *tstamp, const void *buffer, size_t size)
static ssize_t snd_pcm_hw_write(snd_pcm_t *pcm, snd_timestamp_t *tstamp, const void *buffer, size_t size)
{
ssize_t result;
snd_pcm_hw_t *hw = (snd_pcm_hw_t*) private;
snd_pcm_hw_t *hw = pcm->private;
int fd = hw->fd;
snd_xfer_t xfer;
if (tstamp)
@ -238,10 +236,10 @@ static ssize_t snd_pcm_hw_write(void *private, snd_timestamp_t *tstamp, const vo
return result;
}
static ssize_t snd_pcm_hw_writev(void *private, snd_timestamp_t *tstamp, const struct iovec *vector, unsigned long count)
static ssize_t snd_pcm_hw_writev(snd_pcm_t *pcm, snd_timestamp_t *tstamp, const struct iovec *vector, unsigned long count)
{
ssize_t result;
snd_pcm_hw_t *hw = (snd_pcm_hw_t*) private;
snd_pcm_hw_t *hw = pcm->private;
int fd = hw->fd;
snd_xferv_t xferv;
if (tstamp)
@ -256,10 +254,10 @@ static ssize_t snd_pcm_hw_writev(void *private, snd_timestamp_t *tstamp, const s
return result;
}
static ssize_t snd_pcm_hw_read(void *private, snd_timestamp_t *tstamp, void *buffer, size_t size)
static ssize_t snd_pcm_hw_read(snd_pcm_t *pcm, snd_timestamp_t *tstamp, void *buffer, size_t size)
{
ssize_t result;
snd_pcm_hw_t *hw = (snd_pcm_hw_t*) private;
snd_pcm_hw_t *hw = pcm->private;
int fd = hw->fd;
snd_xfer_t xfer;
if (tstamp)
@ -274,10 +272,10 @@ static ssize_t snd_pcm_hw_read(void *private, snd_timestamp_t *tstamp, void *buf
return result;
}
ssize_t snd_pcm_hw_readv(void *private, snd_timestamp_t *tstamp, const struct iovec *vector, unsigned long count)
ssize_t snd_pcm_hw_readv(snd_pcm_t *pcm, snd_timestamp_t *tstamp, const struct iovec *vector, unsigned long count)
{
ssize_t result;
snd_pcm_hw_t *hw = (snd_pcm_hw_t*) private;
snd_pcm_hw_t *hw = pcm->private;
int fd = hw->fd;
snd_xferv_t xferv;
if (tstamp)
@ -292,9 +290,9 @@ ssize_t snd_pcm_hw_readv(void *private, snd_timestamp_t *tstamp, const struct io
return result;
}
static int snd_pcm_hw_mmap_status(void *private, snd_pcm_mmap_status_t **status)
static int snd_pcm_hw_mmap_status(snd_pcm_t *pcm, snd_pcm_mmap_status_t **status)
{
snd_pcm_hw_t *hw = (snd_pcm_hw_t*) private;
snd_pcm_hw_t *hw = pcm->private;
void *ptr;
ptr = mmap(NULL, sizeof(snd_pcm_mmap_status_t), PROT_READ, MAP_FILE|MAP_SHARED,
hw->fd, SND_PCM_MMAP_OFFSET_STATUS);
@ -304,9 +302,9 @@ static int snd_pcm_hw_mmap_status(void *private, snd_pcm_mmap_status_t **status)
return 0;
}
static int snd_pcm_hw_mmap_control(void *private, snd_pcm_mmap_control_t **control)
static int snd_pcm_hw_mmap_control(snd_pcm_t *pcm, snd_pcm_mmap_control_t **control)
{
snd_pcm_hw_t *hw = (snd_pcm_hw_t*) private;
snd_pcm_hw_t *hw = pcm->private;
void *ptr;
ptr = mmap(NULL, sizeof(snd_pcm_mmap_control_t), PROT_READ|PROT_WRITE, MAP_FILE|MAP_SHARED,
hw->fd, SND_PCM_MMAP_OFFSET_CONTROL);
@ -316,12 +314,12 @@ static int snd_pcm_hw_mmap_control(void *private, snd_pcm_mmap_control_t **contr
return 0;
}
static int snd_pcm_hw_mmap_data(void *private, void **buffer, size_t bsize)
static int snd_pcm_hw_mmap_data(snd_pcm_t *pcm, void **buffer, size_t bsize)
{
snd_pcm_hw_t *hw = (snd_pcm_hw_t*) private;
snd_pcm_hw_t *hw = pcm->private;
void *ptr;
int prot;
prot = hw->handle->stream == SND_PCM_STREAM_PLAYBACK ? PROT_WRITE : PROT_READ;
prot = pcm->stream == SND_PCM_STREAM_PLAYBACK ? PROT_WRITE : PROT_READ;
ptr = mmap(NULL, bsize, prot, MAP_FILE|MAP_SHARED,
hw->fd, SND_PCM_MMAP_OFFSET_DATA);
if (ptr == MAP_FAILED || ptr == NULL)
@ -330,53 +328,52 @@ static int snd_pcm_hw_mmap_data(void *private, void **buffer, size_t bsize)
return 0;
}
static int snd_pcm_hw_munmap_status(void *private ATTRIBUTE_UNUSED, snd_pcm_mmap_status_t *status)
static int snd_pcm_hw_munmap_status(snd_pcm_t *pcm ATTRIBUTE_UNUSED, snd_pcm_mmap_status_t *status)
{
if (munmap(status, sizeof(*status)) < 0)
return -errno;
return 0;
}
static int snd_pcm_hw_munmap_control(void *private ATTRIBUTE_UNUSED, snd_pcm_mmap_control_t *control)
static int snd_pcm_hw_munmap_control(snd_pcm_t *pcm ATTRIBUTE_UNUSED, snd_pcm_mmap_control_t *control)
{
if (munmap(control, sizeof(*control)) < 0)
return -errno;
return 0;
}
static int snd_pcm_hw_munmap_data(void *private, void *buffer, size_t bsize)
static int snd_pcm_hw_munmap_data(snd_pcm_t *pcm, void *buffer, size_t bsize)
{
snd_pcm_hw_t *hw = (snd_pcm_hw_t*) private;
snd_pcm_hw_t *hw = pcm->private;
if (munmap(buffer, bsize) < 0)
return -errno;
hw->mmap_data_ptr = NULL;
return 0;
}
static int snd_pcm_hw_file_descriptor(void *private)
static int snd_pcm_hw_file_descriptor(snd_pcm_t *pcm)
{
snd_pcm_hw_t *hw = (snd_pcm_hw_t*) private;
snd_pcm_hw_t *hw = pcm->private;
return hw->fd;
}
static int snd_pcm_hw_channels_mask(void *private ATTRIBUTE_UNUSED,
static int snd_pcm_hw_channels_mask(snd_pcm_t *pcm ATTRIBUTE_UNUSED,
bitset_t *client_vmask ATTRIBUTE_UNUSED)
{
return 0;
}
static void snd_pcm_hw_dump(void *private, FILE *fp)
static void snd_pcm_hw_dump(snd_pcm_t *pcm, FILE *fp)
{
snd_pcm_hw_t *hw = (snd_pcm_hw_t*) private;
snd_pcm_t *handle = hw->handle;
snd_pcm_hw_t *hw = pcm->private;
char *name = "Unknown";
snd_card_get_name(hw->card, &name);
fprintf(fp, "Hardware PCM card %d '%s' device %d subdevice %d\n",
hw->card, name, hw->device, hw->subdevice);
free(name);
if (handle->valid_setup) {
if (pcm->valid_setup) {
fprintf(fp, "\nIts setup is:\n");
snd_pcm_dump_setup(handle, fp);
snd_pcm_dump_setup(pcm, fp);
}
}
@ -433,7 +430,7 @@ int snd_pcm_hw_open_subdevice(snd_pcm_t **handlep, int card, int device, int sub
assert(handlep);
*handlep = 0;
if ((ret = snd_ctl_open(&ctl, card)) < 0)
if ((ret = snd_ctl_hw_open(&ctl, card)) < 0)
return ret;
switch (stream) {
@ -492,7 +489,6 @@ int snd_pcm_hw_open_subdevice(snd_pcm_t **handlep, int card, int device, int sub
ret = -ENOMEM;
goto __end;
}
hw->handle = handle;
hw->card = card;
hw->device = device;
hw->subdevice = subdevice;
@ -500,9 +496,9 @@ int snd_pcm_hw_open_subdevice(snd_pcm_t **handlep, int card, int device, int sub
handle->type = SND_PCM_TYPE_HW;
handle->stream = stream;
handle->ops = &snd_pcm_hw_ops;
handle->op_arg = hw;
handle->op_arg = handle;
handle->fast_ops = &snd_pcm_hw_fast_ops;
handle->fast_op_arg = hw;
handle->fast_op_arg = handle;
handle->mode = mode;
handle->private = hw;
*handlep = handle;

View file

@ -23,40 +23,40 @@
#include "asoundlib.h"
struct snd_pcm_ops {
int (*close)(void *private);
int (*info)(void *private, snd_pcm_info_t *info);
int (*params_info)(void *private, snd_pcm_params_info_t *info);
int (*params)(void *private, snd_pcm_params_t *params);
int (*setup)(void *private, snd_pcm_setup_t *setup);
void (*dump)(void *private, FILE *fp);
int (*close)(snd_pcm_t *pcm);
int (*info)(snd_pcm_t *pcm, snd_pcm_info_t *info);
int (*params_info)(snd_pcm_t *pcm, snd_pcm_params_info_t *info);
int (*params)(snd_pcm_t *pcm, snd_pcm_params_t *params);
int (*setup)(snd_pcm_t *pcm, snd_pcm_setup_t *setup);
void (*dump)(snd_pcm_t *pcm, FILE *fp);
};
struct snd_pcm_fast_ops {
int (*nonblock)(void *private, int nonblock);
int (*status)(void *private, snd_pcm_status_t *status);
int (*channel_info)(void *private, snd_pcm_channel_info_t *info);
int (*channel_params)(void *private, snd_pcm_channel_params_t *params);
int (*channel_setup)(void *private, snd_pcm_channel_setup_t *setup);
int (*prepare)(void *private);
int (*go)(void *private);
int (*drain)(void *private);
int (*flush)(void *private);
int (*pause)(void *private, int enable);
int (*state)(void *private);
ssize_t (*frame_io)(void *private, int update);
ssize_t (*frame_data)(void *private, off_t offset);
ssize_t (*write)(void *private, snd_timestamp_t *tstamp, const void *buffer, size_t size);
ssize_t (*writev)(void *private, snd_timestamp_t *tstamp, const struct iovec *vector, unsigned long count);
ssize_t (*read)(void *private, snd_timestamp_t *tstamp, void *buffer, size_t size);
ssize_t (*readv)(void *private, snd_timestamp_t *tstamp, const struct iovec *vector, unsigned long count);
int (*file_descriptor)(void *private);
int (*channels_mask)(void *private, bitset_t *client_vmask);
int (*mmap_status)(void *private, snd_pcm_mmap_status_t **status);
int (*mmap_control)(void *private, snd_pcm_mmap_control_t **control);
int (*mmap_data)(void *private, void **buffer, size_t bsize);
int (*munmap_status)(void *private, snd_pcm_mmap_status_t *status);
int (*munmap_control)(void *private, snd_pcm_mmap_control_t *control);
int (*munmap_data)(void *private, void *buffer, size_t bsize);
int (*nonblock)(snd_pcm_t *pcm, int nonblock);
int (*status)(snd_pcm_t *pcm, snd_pcm_status_t *status);
int (*channel_info)(snd_pcm_t *pcm, snd_pcm_channel_info_t *info);
int (*channel_params)(snd_pcm_t *pcm, snd_pcm_channel_params_t *params);
int (*channel_setup)(snd_pcm_t *pcm, snd_pcm_channel_setup_t *setup);
int (*prepare)(snd_pcm_t *pcm);
int (*go)(snd_pcm_t *pcm);
int (*drain)(snd_pcm_t *pcm);
int (*flush)(snd_pcm_t *pcm);
int (*pause)(snd_pcm_t *pcm, int enable);
int (*state)(snd_pcm_t *pcm);
ssize_t (*frame_io)(snd_pcm_t *pcm, int update);
ssize_t (*frame_data)(snd_pcm_t *pcm, off_t offset);
ssize_t (*write)(snd_pcm_t *pcm, snd_timestamp_t *tstamp, const void *buffer, size_t size);
ssize_t (*writev)(snd_pcm_t *pcm, snd_timestamp_t *tstamp, const struct iovec *vector, unsigned long count);
ssize_t (*read)(snd_pcm_t *pcm, snd_timestamp_t *tstamp, void *buffer, size_t size);
ssize_t (*readv)(snd_pcm_t *pcm, snd_timestamp_t *tstamp, const struct iovec *vector, unsigned long count);
int (*file_descriptor)(snd_pcm_t *pcm);
int (*channels_mask)(snd_pcm_t *pcm, bitset_t *client_vmask);
int (*mmap_status)(snd_pcm_t *pcm, snd_pcm_mmap_status_t **status);
int (*mmap_control)(snd_pcm_t *pcm, snd_pcm_mmap_control_t **control);
int (*mmap_data)(snd_pcm_t *pcm, void **buffer, size_t bsize);
int (*munmap_status)(snd_pcm_t *pcm, snd_pcm_mmap_status_t *status);
int (*munmap_control)(snd_pcm_t *pcm, snd_pcm_mmap_control_t *control);
int (*munmap_data)(snd_pcm_t *pcm, void *buffer, size_t bsize);
};
struct snd_pcm {
@ -73,9 +73,9 @@ struct snd_pcm {
char *mmap_data;
enum { _INTERLEAVED, _NONINTERLEAVED, _COMPLEX } mmap_type;
struct snd_pcm_ops *ops;
void *op_arg;
struct snd_pcm_fast_ops *fast_ops;
void *fast_op_arg;
snd_pcm_t *op_arg;
snd_pcm_t *fast_op_arg;
void *private;
};

View file

@ -44,7 +44,6 @@ typedef struct {
} snd_pcm_multi_bind_t;
typedef struct {
snd_pcm_t *handle;
size_t slaves_count;
snd_pcm_multi_slave_t *slaves;
size_t bindings_count;
@ -55,9 +54,9 @@ typedef struct {
int one_to_many;
} snd_pcm_multi_t;
static int snd_pcm_multi_close(void *private)
static int snd_pcm_multi_close(snd_pcm_t *pcm)
{
snd_pcm_multi_t *multi = (snd_pcm_multi_t*) private;
snd_pcm_multi_t *multi = pcm->private;
unsigned int i;
int ret = 0;
for (i = 0; i < multi->slaves_count; ++i) {
@ -78,20 +77,20 @@ static int snd_pcm_multi_close(void *private)
}
free(multi->slaves);
free(multi->bindings);
free(private);
free(multi);
return ret;
}
static int snd_pcm_multi_nonblock(void *private, int nonblock)
static int snd_pcm_multi_nonblock(snd_pcm_t *pcm, int nonblock)
{
snd_pcm_multi_t *multi = (snd_pcm_multi_t*) private;
snd_pcm_multi_t *multi = pcm->private;
snd_pcm_t *handle = multi->slaves[0].handle;
return snd_pcm_nonblock(handle, nonblock);
}
static int snd_pcm_multi_info(void *private, snd_pcm_info_t *info)
static int snd_pcm_multi_info(snd_pcm_t *pcm, snd_pcm_info_t *info)
{
snd_pcm_multi_t *multi = (snd_pcm_multi_t*) private;
snd_pcm_multi_t *multi = pcm->private;
unsigned int i;
int err;
snd_pcm_t *handle_0 = multi->slaves[0].handle;
@ -112,9 +111,9 @@ static int snd_pcm_multi_info(void *private, snd_pcm_info_t *info)
return 0;
}
static int snd_pcm_multi_params_info(void *private, snd_pcm_params_info_t *info)
static int snd_pcm_multi_params_info(snd_pcm_t *pcm, snd_pcm_params_info_t *info)
{
snd_pcm_multi_t *multi = (snd_pcm_multi_t*) private;
snd_pcm_multi_t *multi = pcm->private;
unsigned int i;
int err;
snd_pcm_t *handle_0 = multi->slaves[0].handle;
@ -153,9 +152,9 @@ static int snd_pcm_multi_params_info(void *private, snd_pcm_params_info_t *info)
return 0;
}
static int snd_pcm_multi_params(void *private, snd_pcm_params_t *params)
static int snd_pcm_multi_params(snd_pcm_t *pcm, snd_pcm_params_t *params)
{
snd_pcm_multi_t *multi = (snd_pcm_multi_t*) private;
snd_pcm_multi_t *multi = pcm->private;
unsigned int i;
snd_pcm_params_t p;
if (params->format.channels != multi->channels_count)
@ -193,9 +192,9 @@ static int snd_pcm_multi_params(void *private, snd_pcm_params_t *params)
return 0;
}
static int snd_pcm_multi_setup(void *private, snd_pcm_setup_t *setup)
static int snd_pcm_multi_setup(snd_pcm_t *pcm, snd_pcm_setup_t *setup)
{
snd_pcm_multi_t *multi = (snd_pcm_multi_t*) private;
snd_pcm_multi_t *multi = pcm->private;
unsigned int i;
int err;
size_t frames_alloc;
@ -231,7 +230,7 @@ static int snd_pcm_multi_setup(void *private, snd_pcm_setup_t *setup)
free(s->iovec);
if (!sh->setup.format.interleave) {
s->iovec = calloc(s->channels_total, sizeof(*s->iovec));
if (!multi->handle->setup.format.interleave)
if (!pcm->setup.format.interleave)
continue;
}
s->buf = malloc(frames_alloc * sh->bits_per_frame / 8);
@ -262,61 +261,61 @@ static int snd_pcm_multi_setup(void *private, snd_pcm_setup_t *setup)
return 0;
}
static int snd_pcm_multi_status(void *private, snd_pcm_status_t *status)
static int snd_pcm_multi_status(snd_pcm_t *pcm, snd_pcm_status_t *status)
{
snd_pcm_multi_t *multi = (snd_pcm_multi_t*) private;
snd_pcm_multi_t *multi = pcm->private;
snd_pcm_t *handle = multi->slaves[0].handle;
return snd_pcm_status(handle, status);
}
static int snd_pcm_multi_state(void *private)
static int snd_pcm_multi_state(snd_pcm_t *pcm)
{
snd_pcm_multi_t *multi = (snd_pcm_multi_t*) private;
snd_pcm_multi_t *multi = pcm->private;
snd_pcm_t *handle = multi->slaves[0].handle;
return snd_pcm_state(handle);
}
static ssize_t snd_pcm_multi_frame_io(void *private, int update)
static ssize_t snd_pcm_multi_frame_io(snd_pcm_t *pcm, int update)
{
snd_pcm_multi_t *multi = (snd_pcm_multi_t*) private;
snd_pcm_multi_t *multi = pcm->private;
snd_pcm_t *handle = multi->slaves[0].handle;
return snd_pcm_frame_io(handle, update);
}
static int snd_pcm_multi_prepare(void *private)
static int snd_pcm_multi_prepare(snd_pcm_t *pcm)
{
snd_pcm_multi_t *multi = (snd_pcm_multi_t*) private;
snd_pcm_multi_t *multi = pcm->private;
return snd_pcm_prepare(multi->slaves[0].handle);
}
static int snd_pcm_multi_go(void *private)
static int snd_pcm_multi_go(snd_pcm_t *pcm)
{
snd_pcm_multi_t *multi = (snd_pcm_multi_t*) private;
snd_pcm_multi_t *multi = pcm->private;
return snd_pcm_go(multi->slaves[0].handle);
}
static int snd_pcm_multi_drain(void *private)
static int snd_pcm_multi_drain(snd_pcm_t *pcm)
{
snd_pcm_multi_t *multi = (snd_pcm_multi_t*) private;
snd_pcm_multi_t *multi = pcm->private;
return snd_pcm_drain(multi->slaves[0].handle);
}
static int snd_pcm_multi_flush(void *private)
static int snd_pcm_multi_flush(snd_pcm_t *pcm)
{
snd_pcm_multi_t *multi = (snd_pcm_multi_t*) private;
snd_pcm_multi_t *multi = pcm->private;
return snd_pcm_flush(multi->slaves[0].handle);
}
static int snd_pcm_multi_pause(void *private, int enable)
static int snd_pcm_multi_pause(snd_pcm_t *pcm, int enable)
{
snd_pcm_multi_t *multi = (snd_pcm_multi_t*) private;
snd_pcm_multi_t *multi = pcm->private;
return snd_pcm_pause(multi->slaves[0].handle, enable);
}
static int snd_pcm_multi_channel_info(void *private, snd_pcm_channel_info_t *info)
static int snd_pcm_multi_channel_info(snd_pcm_t *pcm, snd_pcm_channel_info_t *info)
{
int err;
snd_pcm_multi_t *multi = (snd_pcm_multi_t*) private;
snd_pcm_multi_t *multi = pcm->private;
unsigned int channel = info->channel;
unsigned int i;
for (i = 0; i < multi->bindings_count; ++i) {
@ -331,10 +330,10 @@ static int snd_pcm_multi_channel_info(void *private, snd_pcm_channel_info_t *inf
return -EINVAL;
}
static int snd_pcm_multi_channel_params(void *private, snd_pcm_channel_params_t *params)
static int snd_pcm_multi_channel_params(snd_pcm_t *pcm, snd_pcm_channel_params_t *params)
{
int err;
snd_pcm_multi_t *multi = (snd_pcm_multi_t*) private;
snd_pcm_multi_t *multi = pcm->private;
unsigned int channel = params->channel;
unsigned int i;
for (i = 0; i < multi->bindings_count; ++i) {
@ -349,10 +348,10 @@ static int snd_pcm_multi_channel_params(void *private, snd_pcm_channel_params_t
return -EINVAL;
}
static int snd_pcm_multi_channel_setup(void *private, snd_pcm_channel_setup_t *setup)
static int snd_pcm_multi_channel_setup(snd_pcm_t *pcm, snd_pcm_channel_setup_t *setup)
{
int err;
snd_pcm_multi_t *multi = (snd_pcm_multi_t*) private;
snd_pcm_multi_t *multi = pcm->private;
unsigned int channel = setup->channel;
unsigned int i;
for (i = 0; i < multi->bindings_count; ++i) {
@ -368,9 +367,9 @@ static int snd_pcm_multi_channel_setup(void *private, snd_pcm_channel_setup_t *s
return 0;
}
static ssize_t snd_pcm_multi_frame_data(void *private, off_t offset)
static ssize_t snd_pcm_multi_frame_data(snd_pcm_t *pcm, off_t offset)
{
snd_pcm_multi_t *multi = (snd_pcm_multi_t*) private;
snd_pcm_multi_t *multi = pcm->private;
ssize_t pos, newpos;
unsigned int i;
snd_pcm_t *handle_0 = multi->slaves[0].handle;
@ -395,21 +394,21 @@ static ssize_t snd_pcm_multi_frame_data(void *private, off_t offset)
return newpos;
}
static int snd_pcm_multi_write_copy(snd_pcm_multi_t *multi, const void *buf,
static int snd_pcm_multi_write_copy(snd_pcm_t *pcm, const void *buf,
size_t offset, size_t count)
{
snd_pcm_multi_t *multi = pcm->private;
unsigned int i;
snd_pcm_channel_area_t area;
snd_pcm_t *handle = multi->handle;
area.addr = (void *) buf + offset * handle->bits_per_frame;
area.step = handle->bits_per_frame;
area.addr = (void *) buf + offset * pcm->bits_per_frame;
area.step = pcm->bits_per_frame;
for (i = 0; i < multi->bindings_count; ++i) {
snd_pcm_multi_bind_t *bind = &multi->bindings[i];
snd_pcm_multi_slave_t *slave = &multi->slaves[bind->slave];
int err;
assert(slave->buf);
area.first = handle->bits_per_sample * bind->client_channel;
err = snd_pcm_area_copy(&area, 0, &slave->areas[bind->slave_channel], 0, count, handle->setup.format.format);
area.first = pcm->bits_per_sample * bind->client_channel;
err = snd_pcm_area_copy(&area, 0, &slave->areas[bind->slave_channel], 0, count, pcm->setup.format.format);
if (err < 0)
return err;
if (!slave->handle->setup.format.interleave) {
@ -420,23 +419,23 @@ static int snd_pcm_multi_write_copy(snd_pcm_multi_t *multi, const void *buf,
return 0;
}
static int snd_pcm_multi_writev_copy(snd_pcm_multi_t *multi, const struct iovec *vec,
static int snd_pcm_multi_writev_copy(snd_pcm_t *pcm, const struct iovec *vec,
size_t offset, size_t count)
{
snd_pcm_multi_t *multi = pcm->private;
unsigned int i;
snd_pcm_channel_area_t area;
snd_pcm_t *handle = multi->handle;
area.first = 0;
area.step = handle->bits_per_sample;
area.step = pcm->bits_per_sample;
for (i = 0; i < multi->bindings_count; ++i) {
snd_pcm_multi_bind_t *bind = &multi->bindings[i];
snd_pcm_multi_slave_t *slave = &multi->slaves[bind->slave];
int err;
area.addr = vec[bind->client_channel].iov_base +
offset * handle->bits_per_sample;
offset * pcm->bits_per_sample;
if (slave->handle->setup.format.interleave) {
assert(slave->buf);
err = snd_pcm_area_copy(&area, 0, &slave->areas[bind->slave_channel], 0, count, handle->setup.format.format);
err = snd_pcm_area_copy(&area, 0, &slave->areas[bind->slave_channel], 0, count, pcm->setup.format.format);
if (err < 0)
return err;
} else {
@ -448,8 +447,9 @@ static int snd_pcm_multi_writev_copy(snd_pcm_multi_t *multi, const struct iovec
return 0;
}
static ssize_t snd_pcm_multi_write_io(snd_pcm_multi_t *multi, size_t count)
static ssize_t snd_pcm_multi_write_io(snd_pcm_t *pcm, size_t count)
{
snd_pcm_multi_t *multi = pcm->private;
unsigned int i;
ssize_t frames = count;
for (i = 0; i < multi->slaves_count; ++i) {
@ -467,9 +467,9 @@ static ssize_t snd_pcm_multi_write_io(snd_pcm_multi_t *multi, size_t count)
return frames;
}
static ssize_t snd_pcm_multi_write(void *private, snd_timestamp_t *timestamp ATTRIBUTE_UNUSED, const void *buf, size_t count)
static ssize_t snd_pcm_multi_write(snd_pcm_t *pcm, snd_timestamp_t *timestamp ATTRIBUTE_UNUSED, const void *buf, size_t count)
{
snd_pcm_multi_t *multi = (snd_pcm_multi_t*) private;
snd_pcm_multi_t *multi = pcm->private;
size_t result = 0;
while (count > 0) {
int err;
@ -477,10 +477,10 @@ static ssize_t snd_pcm_multi_write(void *private, snd_timestamp_t *timestamp ATT
size_t frames = count;
if (frames > multi->frames_alloc)
frames = multi->frames_alloc;
err = snd_pcm_multi_write_copy(multi, buf, result, frames);
err = snd_pcm_multi_write_copy(pcm, buf, result, frames);
if (err < 0)
return err;
ret = snd_pcm_multi_write_io(multi, frames);
ret = snd_pcm_multi_write_io(pcm, frames);
if (ret > 0)
result += ret;
if (ret != (ssize_t)frames) {
@ -493,8 +493,9 @@ static ssize_t snd_pcm_multi_write(void *private, snd_timestamp_t *timestamp ATT
return result;
}
static ssize_t snd_pcm_multi_writev1(snd_pcm_multi_t *multi, const struct iovec *vector, size_t count)
static ssize_t snd_pcm_multi_writev1(snd_pcm_t *pcm, const struct iovec *vector, size_t count)
{
snd_pcm_multi_t *multi = pcm->private;
size_t result = 0;
while (count > 0) {
int err;
@ -502,10 +503,10 @@ static ssize_t snd_pcm_multi_writev1(snd_pcm_multi_t *multi, const struct iovec
size_t frames = count;
if (frames > multi->frames_alloc)
frames = multi->frames_alloc;
err = snd_pcm_multi_writev_copy(multi, vector, result, frames);
err = snd_pcm_multi_writev_copy(pcm, vector, result, frames);
if (err < 0)
return err;
ret = snd_pcm_multi_write_io(multi, frames);
ret = snd_pcm_multi_write_io(pcm, frames);
if (ret > 0)
result += ret;
if (ret != (ssize_t) frames) {
@ -518,22 +519,20 @@ static ssize_t snd_pcm_multi_writev1(snd_pcm_multi_t *multi, const struct iovec
return result;
}
static ssize_t snd_pcm_multi_writev(void *private, snd_timestamp_t *timestamp ATTRIBUTE_UNUSED, const struct iovec *vector, unsigned long count)
static ssize_t snd_pcm_multi_writev(snd_pcm_t *pcm, snd_timestamp_t *timestamp ATTRIBUTE_UNUSED, const struct iovec *vector, unsigned long count)
{
snd_pcm_multi_t *multi = (snd_pcm_multi_t*) private;
snd_pcm_t *handle = multi->handle;
unsigned int k, step;
size_t result = 0;
if (handle->setup.format.interleave)
if (pcm->setup.format.interleave)
step = 1;
else
step = handle->setup.format.channels;
step = pcm->setup.format.channels;
for (k = 0; k < count; k += step) {
ssize_t ret;
if (handle->setup.format.interleave)
ret = snd_pcm_multi_write(private, timestamp, vector->iov_base, vector->iov_len);
if (pcm->setup.format.interleave)
ret = snd_pcm_multi_write(pcm, timestamp, vector->iov_base, vector->iov_len);
else
ret = snd_pcm_multi_writev1(multi, vector, vector->iov_len);
ret = snd_pcm_multi_writev1(pcm, vector, vector->iov_len);
if (ret > 0)
result += ret;
if (ret != (ssize_t) vector->iov_len) {
@ -546,21 +545,21 @@ static ssize_t snd_pcm_multi_writev(void *private, snd_timestamp_t *timestamp AT
return result;
}
static ssize_t snd_pcm_multi_read(void *private ATTRIBUTE_UNUSED, snd_timestamp_t *timestamp ATTRIBUTE_UNUSED, void *buf ATTRIBUTE_UNUSED, size_t count ATTRIBUTE_UNUSED)
static ssize_t snd_pcm_multi_read(snd_pcm_t *pcm ATTRIBUTE_UNUSED, snd_timestamp_t *timestamp ATTRIBUTE_UNUSED, void *buf ATTRIBUTE_UNUSED, size_t count ATTRIBUTE_UNUSED)
{
// snd_pcm_multi_t *multi = (snd_pcm_multi_t*) private;
// snd_pcm_multi_t *multi = pcm->private;
return -ENOSYS;
}
static ssize_t snd_pcm_multi_readv(void *private ATTRIBUTE_UNUSED, snd_timestamp_t *timestamp ATTRIBUTE_UNUSED, const struct iovec *vector ATTRIBUTE_UNUSED, unsigned long count ATTRIBUTE_UNUSED)
static ssize_t snd_pcm_multi_readv(snd_pcm_t *pcm ATTRIBUTE_UNUSED, snd_timestamp_t *timestamp ATTRIBUTE_UNUSED, const struct iovec *vector ATTRIBUTE_UNUSED, unsigned long count ATTRIBUTE_UNUSED)
{
// snd_pcm_multi_t *multi = (snd_pcm_multi_t*) private;
// snd_pcm_multi_t *multi = pcm->private;
return -ENOSYS;
}
static int snd_pcm_multi_mmap_status(void *private, snd_pcm_mmap_status_t **status)
static int snd_pcm_multi_mmap_status(snd_pcm_t *pcm, snd_pcm_mmap_status_t **status)
{
snd_pcm_multi_t *multi = (snd_pcm_multi_t*) private;
snd_pcm_multi_t *multi = pcm->private;
unsigned int i;
for (i = 0; i < multi->slaves_count; ++i) {
snd_pcm_t *handle = multi->slaves[i].handle;
@ -572,9 +571,9 @@ static int snd_pcm_multi_mmap_status(void *private, snd_pcm_mmap_status_t **stat
return 0;
}
static int snd_pcm_multi_mmap_control(void *private, snd_pcm_mmap_control_t **control)
static int snd_pcm_multi_mmap_control(snd_pcm_t *pcm, snd_pcm_mmap_control_t **control)
{
snd_pcm_multi_t *multi = (snd_pcm_multi_t*) private;
snd_pcm_multi_t *multi = pcm->private;
snd_pcm_setup_t *setup_0 = &multi->slaves[0].handle->setup;
unsigned int i;
for (i = 1; i < multi->slaves_count; ++i) {
@ -594,9 +593,9 @@ static int snd_pcm_multi_mmap_control(void *private, snd_pcm_mmap_control_t **co
return 0;
}
static int snd_pcm_multi_mmap_data(void *private, void **buffer, size_t bsize ATTRIBUTE_UNUSED)
static int snd_pcm_multi_mmap_data(snd_pcm_t *pcm, void **buffer, size_t bsize ATTRIBUTE_UNUSED)
{
snd_pcm_multi_t *multi = (snd_pcm_multi_t*) private;
snd_pcm_multi_t *multi = pcm->private;
unsigned int i;
for (i = 0; i < multi->slaves_count; ++i) {
snd_pcm_t *handle = multi->slaves[i].handle;
@ -619,9 +618,9 @@ static int snd_pcm_multi_mmap_data(void *private, void **buffer, size_t bsize AT
return 0;
}
static int snd_pcm_multi_munmap_status(void *private, snd_pcm_mmap_status_t *status ATTRIBUTE_UNUSED)
static int snd_pcm_multi_munmap_status(snd_pcm_t *pcm, snd_pcm_mmap_status_t *status ATTRIBUTE_UNUSED)
{
snd_pcm_multi_t *multi = (snd_pcm_multi_t*) private;
snd_pcm_multi_t *multi = pcm->private;
unsigned int i;
int ret = 0;
for (i = 0; i < multi->slaves_count; ++i) {
@ -633,9 +632,9 @@ static int snd_pcm_multi_munmap_status(void *private, snd_pcm_mmap_status_t *sta
return ret;
}
static int snd_pcm_multi_munmap_control(void *private, snd_pcm_mmap_control_t *control ATTRIBUTE_UNUSED)
static int snd_pcm_multi_munmap_control(snd_pcm_t *pcm, snd_pcm_mmap_control_t *control ATTRIBUTE_UNUSED)
{
snd_pcm_multi_t *multi = (snd_pcm_multi_t*) private;
snd_pcm_multi_t *multi = pcm->private;
unsigned int i;
int ret = 0;
for (i = 0; i < multi->slaves_count; ++i) {
@ -647,9 +646,9 @@ static int snd_pcm_multi_munmap_control(void *private, snd_pcm_mmap_control_t *c
return ret;
}
static int snd_pcm_multi_munmap_data(void *private, void *buffer ATTRIBUTE_UNUSED, size_t size ATTRIBUTE_UNUSED)
static int snd_pcm_multi_munmap_data(snd_pcm_t *pcm, void *buffer ATTRIBUTE_UNUSED, size_t size ATTRIBUTE_UNUSED)
{
snd_pcm_multi_t *multi = (snd_pcm_multi_t*) private;
snd_pcm_multi_t *multi = pcm->private;
unsigned int i;
int ret = 0;
for (i = 0; i < multi->slaves_count; ++i) {
@ -661,9 +660,9 @@ static int snd_pcm_multi_munmap_data(void *private, void *buffer ATTRIBUTE_UNUSE
return ret;
}
static int snd_pcm_multi_channels_mask(void *private, bitset_t *client_vmask)
static int snd_pcm_multi_channels_mask(snd_pcm_t *pcm, bitset_t *client_vmask)
{
snd_pcm_multi_t *multi = (snd_pcm_multi_t*) private;
snd_pcm_multi_t *multi = pcm->private;
unsigned int i;
bitset_t *vmasks[multi->slaves_count];
int err;
@ -683,7 +682,7 @@ static int snd_pcm_multi_channels_mask(void *private, bitset_t *client_vmask)
return err;
}
}
bitset_zero(client_vmask, multi->handle->setup.format.channels);
bitset_zero(client_vmask, pcm->setup.format.channels);
for (i = 0; i < multi->bindings_count; ++i) {
snd_pcm_multi_bind_t *b = &multi->bindings[i];
if (bitset_get(vmasks[b->slave], b->slave_channel))
@ -694,22 +693,21 @@ static int snd_pcm_multi_channels_mask(void *private, bitset_t *client_vmask)
return 0;
}
int snd_pcm_multi_file_descriptor(void *private)
int snd_pcm_multi_file_descriptor(snd_pcm_t *pcm)
{
snd_pcm_multi_t *multi = (snd_pcm_multi_t*) private;
snd_pcm_multi_t *multi = pcm->private;
snd_pcm_t *handle = multi->slaves[0].handle;
return snd_pcm_file_descriptor(handle);
}
static void snd_pcm_multi_dump(void *private, FILE *fp)
static void snd_pcm_multi_dump(snd_pcm_t *pcm, FILE *fp)
{
snd_pcm_multi_t *multi = (snd_pcm_multi_t*) private;
snd_pcm_t *handle = multi->handle;
snd_pcm_multi_t *multi = pcm->private;
unsigned int k;
fprintf(fp, "Multi PCM\n");
if (handle->valid_setup) {
if (pcm->valid_setup) {
fprintf(fp, "\nIts setup is:\n");
snd_pcm_dump_setup(handle, fp);
snd_pcm_dump_setup(pcm, fp);
}
for (k = 0; k < multi->slaves_count; ++k) {
fprintf(fp, "\nSlave #%d: ", k);
@ -790,7 +788,6 @@ int snd_pcm_multi_create(snd_pcm_t **handlep, size_t slaves_count,
stream = slaves_handle[0]->stream;
multi->handle = handle;
multi->slaves_count = slaves_count;
multi->slaves = calloc(slaves_count, sizeof(*multi->slaves));
multi->bindings_count = bindings_count;
@ -830,9 +827,9 @@ int snd_pcm_multi_create(snd_pcm_t **handlep, size_t slaves_count,
handle->stream = stream;
handle->mode = multi->slaves[0].handle->mode;
handle->ops = &snd_pcm_multi_ops;
handle->op_arg = multi;
handle->op_arg = handle;
handle->fast_ops = &snd_pcm_multi_fast_ops;
handle->fast_op_arg = multi;
handle->fast_op_arg = handle;
handle->private = multi;
*handlep = handle;
return 0;

View file

@ -129,27 +129,27 @@ snd_pcm_plugin_t *snd_pcm_plug_last(snd_pcm_plug_t *plug)
*
*/
static int snd_pcm_plug_close(void *private)
static int snd_pcm_plug_close(snd_pcm_t *pcm)
{
snd_pcm_plug_t *plug = (snd_pcm_plug_t*) private;
snd_pcm_plug_t *plug = pcm->private;
snd_pcm_plug_clear(plug);
free(plug->handle->fast_ops);
if (plug->close_slave)
return snd_pcm_close(plug->slave);
free(private);
free(plug);
return 0;
}
static int snd_pcm_plug_nonblock(void *private, int nonblock)
static int snd_pcm_plug_nonblock(snd_pcm_t *pcm, int nonblock)
{
snd_pcm_plug_t *plug = (snd_pcm_plug_t*) private;
snd_pcm_plug_t *plug = pcm->private;
return snd_pcm_nonblock(plug->slave, nonblock);
}
static int snd_pcm_plug_info(void *private, snd_pcm_info_t *info)
static int snd_pcm_plug_info(snd_pcm_t *pcm, snd_pcm_info_t *info)
{
int err;
snd_pcm_plug_t *plug = (snd_pcm_plug_t*) private;
snd_pcm_plug_t *plug = pcm->private;
if ((err = snd_pcm_info(plug->slave, info)) < 0)
return err;
@ -158,10 +158,10 @@ static int snd_pcm_plug_info(void *private, snd_pcm_info_t *info)
return 0;
}
static int snd_pcm_plug_params_info(void *private, snd_pcm_params_info_t *info)
static int snd_pcm_plug_params_info(snd_pcm_t *pcm, snd_pcm_params_info_t *info)
{
int err;
snd_pcm_plug_t *plug = (snd_pcm_plug_t*) private;
snd_pcm_plug_t *plug = pcm->private;
snd_pcm_params_info_t slave_info;
int rate;
int slave_format, slave_rate;
@ -260,10 +260,10 @@ static int snd_pcm_plug_action(snd_pcm_plug_t *plug, int action,
return 0;
}
static int snd_pcm_plug_setup(void *private, snd_pcm_setup_t *setup)
static int snd_pcm_plug_setup(snd_pcm_t *pcm, snd_pcm_setup_t *setup)
{
int err;
snd_pcm_plug_t *plug = (snd_pcm_plug_t*) private;
snd_pcm_plug_t *plug = pcm->private;
err = snd_pcm_setup(plug->slave, setup);
if (err < 0)
@ -292,10 +292,10 @@ static int snd_pcm_plug_setup(void *private, snd_pcm_setup_t *setup)
return 0;
}
static int snd_pcm_plug_status(void *private, snd_pcm_status_t *status)
static int snd_pcm_plug_status(snd_pcm_t *pcm, snd_pcm_status_t *status)
{
int err;
snd_pcm_plug_t *plug = (snd_pcm_plug_t*) private;
snd_pcm_plug_t *plug = pcm->private;
err = snd_pcm_status(plug->slave, status);
if (err < 0)
@ -308,24 +308,24 @@ static int snd_pcm_plug_status(void *private, snd_pcm_status_t *status)
return 0;
}
static int snd_pcm_plug_state(void *private)
static int snd_pcm_plug_state(snd_pcm_t *pcm)
{
snd_pcm_plug_t *plug = (snd_pcm_plug_t*) private;
snd_pcm_plug_t *plug = pcm->private;
return snd_pcm_state(plug->slave);
}
static ssize_t snd_pcm_plug_frame_io(void *private, int update)
static ssize_t snd_pcm_plug_frame_io(snd_pcm_t *pcm, int update)
{
snd_pcm_plug_t *plug = (snd_pcm_plug_t*) private;
snd_pcm_plug_t *plug = pcm->private;
ssize_t frame_io = snd_pcm_frame_io(plug->slave, update);
if (frame_io < 0)
return frame_io;
return snd_pcm_plug_client_size(plug, frame_io);
}
static int snd_pcm_plug_prepare(void *private)
static int snd_pcm_plug_prepare(snd_pcm_t *pcm)
{
snd_pcm_plug_t *plug = (snd_pcm_plug_t*) private;
snd_pcm_plug_t *plug = pcm->private;
int err;
err = snd_pcm_prepare(plug->slave);
if (err < 0)
@ -335,15 +335,15 @@ static int snd_pcm_plug_prepare(void *private)
return 0;
}
static int snd_pcm_plug_go(void *private)
static int snd_pcm_plug_go(snd_pcm_t *pcm)
{
snd_pcm_plug_t *plug = (snd_pcm_plug_t*) private;
snd_pcm_plug_t *plug = pcm->private;
return snd_pcm_go(plug->slave);
}
static int snd_pcm_plug_drain(void *private)
static int snd_pcm_plug_drain(snd_pcm_t *pcm)
{
snd_pcm_plug_t *plug = (snd_pcm_plug_t*) private;
snd_pcm_plug_t *plug = pcm->private;
int err;
if ((err = snd_pcm_drain(plug->slave)) < 0)
@ -353,9 +353,9 @@ static int snd_pcm_plug_drain(void *private)
return 0;
}
static int snd_pcm_plug_flush(void *private)
static int snd_pcm_plug_flush(snd_pcm_t *pcm)
{
snd_pcm_plug_t *plug = (snd_pcm_plug_t*) private;
snd_pcm_plug_t *plug = pcm->private;
int err;
if ((err = snd_pcm_flush(plug->slave)) < 0)
@ -365,9 +365,9 @@ static int snd_pcm_plug_flush(void *private)
return 0;
}
static int snd_pcm_plug_pause(void *private, int enable)
static int snd_pcm_plug_pause(snd_pcm_t *pcm, int enable)
{
snd_pcm_plug_t *plug = (snd_pcm_plug_t*) private;
snd_pcm_plug_t *plug = pcm->private;
int err;
if ((err = snd_pcm_pause(plug->slave, enable)) < 0)
@ -377,31 +377,31 @@ static int snd_pcm_plug_pause(void *private, int enable)
return 0;
}
static int snd_pcm_plug_channel_info(void *private ATTRIBUTE_UNUSED, snd_pcm_channel_info_t *info ATTRIBUTE_UNUSED)
static int snd_pcm_plug_channel_info(snd_pcm_t *pcm ATTRIBUTE_UNUSED, snd_pcm_channel_info_t *info ATTRIBUTE_UNUSED)
{
/* FIXME: if route plugin is not inserted or its ttable is trivial
this should be implemented */
return -ENOSYS;
}
static int snd_pcm_plug_channel_params(void *private ATTRIBUTE_UNUSED, snd_pcm_channel_params_t *params ATTRIBUTE_UNUSED)
static int snd_pcm_plug_channel_params(snd_pcm_t *pcm ATTRIBUTE_UNUSED, snd_pcm_channel_params_t *params ATTRIBUTE_UNUSED)
{
/* FIXME: if route plugin is not inserted or its ttable is trivial
this should be implemented */
return -ENOSYS;
}
static int snd_pcm_plug_channel_setup(void *private ATTRIBUTE_UNUSED, snd_pcm_channel_setup_t *setup ATTRIBUTE_UNUSED)
static int snd_pcm_plug_channel_setup(snd_pcm_t *pcm ATTRIBUTE_UNUSED, snd_pcm_channel_setup_t *setup ATTRIBUTE_UNUSED)
{
/* FIXME: if route plugin is not inserted or its ttable is trivial
this should be implemented for non mmap setups */
return -ENOSYS;
}
static ssize_t snd_pcm_plug_frame_data(void *private, off_t offset)
static ssize_t snd_pcm_plug_frame_data(snd_pcm_t *pcm, off_t offset)
{
ssize_t ret;
snd_pcm_plug_t *plug = (snd_pcm_plug_t*) private;
snd_pcm_plug_t *plug = pcm->private;
if (offset < 0) {
offset = snd_pcm_plug_slave_size(plug, -offset);
if (offset < 0)
@ -418,9 +418,9 @@ static ssize_t snd_pcm_plug_frame_data(void *private, off_t offset)
return snd_pcm_plug_client_size(plug, ret);
}
ssize_t snd_pcm_plug_writev(void *private, snd_timestamp_t *tstamp ATTRIBUTE_UNUSED, const struct iovec *vector, unsigned long count)
ssize_t snd_pcm_plug_writev(snd_pcm_t *pcm, snd_timestamp_t *tstamp ATTRIBUTE_UNUSED, const struct iovec *vector, unsigned long count)
{
snd_pcm_plug_t *plug = (snd_pcm_plug_t*) private;
snd_pcm_plug_t *plug = pcm->private;
snd_pcm_t *handle = plug->handle;
unsigned int k, step;
size_t result = 0;
@ -462,9 +462,9 @@ ssize_t snd_pcm_plug_writev(void *private, snd_timestamp_t *tstamp ATTRIBUTE_UNU
return result;
}
ssize_t snd_pcm_plug_readv(void *private, snd_timestamp_t *tstamp ATTRIBUTE_UNUSED, const struct iovec *vector, unsigned long count)
ssize_t snd_pcm_plug_readv(snd_pcm_t *pcm, snd_timestamp_t *tstamp ATTRIBUTE_UNUSED, const struct iovec *vector, unsigned long count)
{
snd_pcm_plug_t *plug = (snd_pcm_plug_t*) private;
snd_pcm_plug_t *plug = pcm->private;
snd_pcm_t *handle = plug->handle;
unsigned int k, step;
size_t result = 0;
@ -506,9 +506,9 @@ ssize_t snd_pcm_plug_readv(void *private, snd_timestamp_t *tstamp ATTRIBUTE_UNUS
return result;
}
ssize_t snd_pcm_plug_write(void *private, snd_timestamp_t *tstamp ATTRIBUTE_UNUSED, const void *buf, size_t count)
ssize_t snd_pcm_plug_write(snd_pcm_t *pcm, snd_timestamp_t *tstamp ATTRIBUTE_UNUSED, const void *buf, size_t count)
{
snd_pcm_plug_t *plug = (snd_pcm_plug_t*) private;
snd_pcm_plug_t *plug = pcm->private;
snd_pcm_t *handle = plug->handle;
ssize_t frames;
snd_pcm_plugin_channel_t *channels;
@ -540,9 +540,9 @@ ssize_t snd_pcm_plug_write(void *private, snd_timestamp_t *tstamp ATTRIBUTE_UNUS
return size;
}
ssize_t snd_pcm_plug_read(void *private, snd_timestamp_t *tstamp ATTRIBUTE_UNUSED, void *buf, size_t count)
ssize_t snd_pcm_plug_read(snd_pcm_t *pcm, snd_timestamp_t *tstamp ATTRIBUTE_UNUSED, void *buf, size_t count)
{
snd_pcm_plug_t *plug = (snd_pcm_plug_t*) private;
snd_pcm_plug_t *plug = pcm->private;
snd_pcm_t *handle = plug->handle;
ssize_t frames;
snd_pcm_plugin_channel_t *channels;
@ -574,55 +574,55 @@ ssize_t snd_pcm_plug_read(void *private, snd_timestamp_t *tstamp ATTRIBUTE_UNUSE
return size;
}
static int snd_pcm_plug_mmap_status(void *private ATTRIBUTE_UNUSED, snd_pcm_mmap_status_t **status ATTRIBUTE_UNUSED)
static int snd_pcm_plug_mmap_status(snd_pcm_t *pcm ATTRIBUTE_UNUSED, snd_pcm_mmap_status_t **status ATTRIBUTE_UNUSED)
{
return -EBADFD;
}
static int snd_pcm_plug_mmap_control(void *private ATTRIBUTE_UNUSED, snd_pcm_mmap_control_t **control ATTRIBUTE_UNUSED)
static int snd_pcm_plug_mmap_control(snd_pcm_t *pcm ATTRIBUTE_UNUSED, snd_pcm_mmap_control_t **control ATTRIBUTE_UNUSED)
{
return -EBADFD;
}
static int snd_pcm_plug_mmap_data(void *private ATTRIBUTE_UNUSED, void **buffer ATTRIBUTE_UNUSED, size_t bsize ATTRIBUTE_UNUSED)
static int snd_pcm_plug_mmap_data(snd_pcm_t *pcm ATTRIBUTE_UNUSED, void **buffer ATTRIBUTE_UNUSED, size_t bsize ATTRIBUTE_UNUSED)
{
return -EBADFD;
}
static int snd_pcm_plug_munmap_status(void *private ATTRIBUTE_UNUSED, snd_pcm_mmap_status_t *status ATTRIBUTE_UNUSED)
static int snd_pcm_plug_munmap_status(snd_pcm_t *pcm ATTRIBUTE_UNUSED, snd_pcm_mmap_status_t *status ATTRIBUTE_UNUSED)
{
return -EBADFD;
}
static int snd_pcm_plug_munmap_control(void *private ATTRIBUTE_UNUSED, snd_pcm_mmap_control_t *control ATTRIBUTE_UNUSED)
static int snd_pcm_plug_munmap_control(snd_pcm_t *pcm ATTRIBUTE_UNUSED, snd_pcm_mmap_control_t *control ATTRIBUTE_UNUSED)
{
return -EBADFD;
}
static int snd_pcm_plug_munmap_data(void *private ATTRIBUTE_UNUSED, void *buffer ATTRIBUTE_UNUSED, size_t size ATTRIBUTE_UNUSED)
static int snd_pcm_plug_munmap_data(snd_pcm_t *pcm ATTRIBUTE_UNUSED, void *buffer ATTRIBUTE_UNUSED, size_t size ATTRIBUTE_UNUSED)
{
return -EBADFD;
}
static int snd_pcm_plug_channels_mask(void *private,
static int snd_pcm_plug_channels_mask(snd_pcm_t *pcm,
bitset_t *client_vmask)
{
snd_pcm_plug_t *plug = (snd_pcm_plug_t*) private;
snd_pcm_plug_t *plug = pcm->private;
if (plug->handle->stream == SND_PCM_STREAM_PLAYBACK)
return snd_pcm_plug_playback_channels_mask(plug, client_vmask);
else
return snd_pcm_plug_capture_channels_mask(plug, client_vmask);
}
int snd_pcm_plug_file_descriptor(void *private)
int snd_pcm_plug_file_descriptor(snd_pcm_t *pcm)
{
snd_pcm_plug_t *plug = (snd_pcm_plug_t*) private;
snd_pcm_plug_t *plug = pcm->private;
return snd_pcm_file_descriptor(plug->slave);
}
static void snd_pcm_plug_dump(void *private, FILE *fp)
static void snd_pcm_plug_dump(snd_pcm_t *pcm, FILE *fp)
{
snd_pcm_plug_t *plug = (snd_pcm_plug_t*) private;
snd_pcm_plug_t *plug = pcm->private;
snd_pcm_t *handle = plug->handle;
snd_pcm_plugin_t *plugin;
if (!plug->first) {
@ -644,7 +644,7 @@ static void snd_pcm_plug_dump(void *private, FILE *fp)
fprintf(fp, "\n");
}
static int snd_pcm_plug_params(void *private, snd_pcm_params_t *params);
static int snd_pcm_plug_params(snd_pcm_t *pcm, snd_pcm_params_t *params);
struct snd_pcm_ops snd_pcm_plug_ops = {
close: snd_pcm_plug_close,
@ -706,7 +706,7 @@ static void snd_pcm_plug_slave_params(snd_pcm_plug_t *plug,
static int snd_pcm_plug_params(void *private, snd_pcm_params_t *params)
static int snd_pcm_plug_params(snd_pcm_t *pcm, snd_pcm_params_t *params)
{
snd_pcm_params_t slave_params;
snd_pcm_info_t slave_info;
@ -717,7 +717,7 @@ static int snd_pcm_plug_params(void *private, snd_pcm_params_t *params)
int err;
int first = 1;
plug = (snd_pcm_plug_t*) private;
plug = pcm->private;
/*
* try to decide, if a conversion is required
@ -776,7 +776,7 @@ static int snd_pcm_plug_params(void *private, snd_pcm_params_t *params)
}
*plug->handle->fast_ops = snd_pcm_plug_fast_ops;
plug->handle->fast_op_arg = plug;
plug->handle->fast_op_arg = pcm;
/*
* I/O plugins
@ -826,10 +826,10 @@ int snd_pcm_plug_create(snd_pcm_t **handlep, snd_pcm_t *slave, int close_slave)
handle->type = SND_PCM_TYPE_PLUG;
handle->stream = slave->stream;
handle->ops = &snd_pcm_plug_ops;
handle->op_arg = plug;
handle->op_arg = handle;
handle->fast_ops = malloc(sizeof(*handle->fast_ops));
*handle->fast_ops = snd_pcm_plug_fast_ops;
handle->fast_op_arg = plug;
handle->fast_op_arg = handle;
handle->mode = slave->mode;
handle->private = plug;
*handlep = handle;