mirror of
https://github.com/alsa-project/alsa-lib.git
synced 2025-10-29 05:40:25 -04:00
Implemented generic sync requests
This commit is contained in:
parent
9c72daca41
commit
74832704a8
6 changed files with 55 additions and 36 deletions
|
|
@ -100,6 +100,23 @@ typedef struct snd_pcm_loopback snd_pcm_loopback_t;
|
|||
|
||||
typedef enum { SND_PCM_TYPE_HW, SND_PCM_TYPE_PLUG, SND_PCM_TYPE_MULTI } snd_pcm_type_t;
|
||||
|
||||
typedef struct {
|
||||
snd_pcm_t *handle;
|
||||
snd_timestamp_t tstamp;
|
||||
int result;
|
||||
union {
|
||||
char reserved[256];
|
||||
} arg;
|
||||
} snd_pcm_synchro_request_t;
|
||||
|
||||
typedef enum { SND_PCM_SYNCHRO_GO } snd_pcm_synchro_cmd_t;
|
||||
|
||||
#define snd_pcm_synchro_mode_t snd_pcm_sync_mode_t
|
||||
#define SND_PCM_SYNCHRO_MODE_NORMAL SND_PCM_SYNC_MODE_NORMAL
|
||||
#define SND_PCM_SYNCHRO_MODE_HARDWARE SND_PCM_SYNC_MODE_HARDWARE
|
||||
#define SND_PCM_SYNCHRO_MODE_RELAXED SND_PCM_SYNC_MODE_RELAXED
|
||||
|
||||
|
||||
int snd_pcm_hw_open_subdevice(snd_pcm_t **handle, int card, int device, int subdevice, int stream, int mode);
|
||||
int snd_pcm_hw_open(snd_pcm_t **handle, int card, int device, int stream, int mode);
|
||||
|
||||
|
|
@ -115,7 +132,9 @@ int snd_pcm_channel_setup(snd_pcm_t *handle, snd_pcm_channel_setup_t *setup);
|
|||
int snd_pcm_status(snd_pcm_t *handle, snd_pcm_status_t *status);
|
||||
int snd_pcm_prepare(snd_pcm_t *handle);
|
||||
int snd_pcm_go(snd_pcm_t *handle);
|
||||
int snd_pcm_sync_go(snd_pcm_t *handle, snd_pcm_sync_t *sync);
|
||||
int snd_pcm_synchro(snd_pcm_synchro_cmd_t cmd,
|
||||
unsigned int reqs_count, snd_pcm_synchro_request_t *reqs,
|
||||
snd_pcm_synchro_mode_t mode);
|
||||
int snd_pcm_drain(snd_pcm_t *handle);
|
||||
int snd_pcm_flush(snd_pcm_t *handle);
|
||||
int snd_pcm_pause(snd_pcm_t *handle, int enable);
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@
|
|||
#include <string.h>
|
||||
#include <malloc.h>
|
||||
#include <errno.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/poll.h>
|
||||
#include <sys/uio.h>
|
||||
#include "pcm_local.h"
|
||||
|
|
@ -167,12 +168,43 @@ int snd_pcm_go(snd_pcm_t *handle)
|
|||
return handle->ops->go(handle->op_arg);
|
||||
}
|
||||
|
||||
int snd_pcm_sync_go(snd_pcm_t *handle, snd_pcm_sync_t *sync)
|
||||
int snd_pcm_synchro(snd_pcm_synchro_cmd_t cmd,
|
||||
unsigned int reqs_count, snd_pcm_synchro_request_t *reqs,
|
||||
snd_pcm_synchro_mode_t mode)
|
||||
{
|
||||
assert(handle);
|
||||
return handle->ops->sync_go(handle->op_arg, sync);
|
||||
snd_pcm_sync_request_t *sync_reqs;
|
||||
snd_pcm_sync_t sync;
|
||||
unsigned int k;
|
||||
assert(reqs_count > 0 && reqs);
|
||||
sync_reqs = __builtin_alloca(sizeof(*sync_reqs) * reqs_count);
|
||||
switch (cmd) {
|
||||
case SND_PCM_SYNCHRO_GO:
|
||||
break;
|
||||
default:
|
||||
assert(0);
|
||||
return -EINVAL;
|
||||
}
|
||||
sync.mode = mode;
|
||||
sync.requests_count = reqs_count;
|
||||
sync.requests = sync_reqs;
|
||||
for (k = 0; k < reqs_count; ++k) {
|
||||
switch (snd_pcm_type(reqs[k].handle)) {
|
||||
case SND_PCM_TYPE_HW:
|
||||
case SND_PCM_TYPE_PLUG:
|
||||
sync_reqs[k].fd = snd_pcm_file_descriptor(reqs[k].handle);
|
||||
break;
|
||||
default:
|
||||
/* Not yet implemented */
|
||||
assert(0);
|
||||
return -ENOSYS;
|
||||
}
|
||||
}
|
||||
if (ioctl(sync_reqs[0].fd, SND_PCM_IOCTL_SYNC, &sync) < 0)
|
||||
return -errno;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int snd_pcm_drain(snd_pcm_t *handle)
|
||||
{
|
||||
assert(handle);
|
||||
|
|
|
|||
|
|
@ -158,15 +158,6 @@ static int snd_pcm_hw_go(void *private)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int snd_pcm_hw_sync_go(void *private, snd_pcm_sync_t *sync)
|
||||
{
|
||||
snd_pcm_hw_t *hw = (snd_pcm_hw_t*) private;
|
||||
int fd = hw->fd;
|
||||
if (ioctl(fd, SND_PCM_IOCTL_SYNC_GO, sync) < 0)
|
||||
return -errno;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int snd_pcm_hw_drain(void *private)
|
||||
{
|
||||
snd_pcm_hw_t *hw = (snd_pcm_hw_t*) private;
|
||||
|
|
@ -352,7 +343,6 @@ struct snd_pcm_ops snd_pcm_hw_ops = {
|
|||
state: snd_pcm_hw_state,
|
||||
prepare: snd_pcm_hw_prepare,
|
||||
go: snd_pcm_hw_go,
|
||||
sync_go: snd_pcm_hw_sync_go,
|
||||
drain: snd_pcm_hw_drain,
|
||||
flush: snd_pcm_hw_flush,
|
||||
pause: snd_pcm_hw_pause,
|
||||
|
|
|
|||
|
|
@ -33,7 +33,6 @@ struct snd_pcm_ops {
|
|||
int (*status)(void *private, snd_pcm_status_t *status);
|
||||
int (*prepare)(void *private);
|
||||
int (*go)(void *private);
|
||||
int (*sync_go)(void *private, snd_pcm_sync_t *sync);
|
||||
int (*drain)(void *private);
|
||||
int (*flush)(void *private);
|
||||
int (*pause)(void *private, int enable);
|
||||
|
|
|
|||
|
|
@ -292,19 +292,6 @@ static int snd_pcm_multi_go(void *private)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int snd_pcm_multi_sync_go(void *private, snd_pcm_sync_t *sync)
|
||||
{
|
||||
snd_pcm_multi_t *multi = (snd_pcm_multi_t*) private;
|
||||
unsigned int i;
|
||||
for (i = 0; i < multi->slaves_count; ++i) {
|
||||
snd_pcm_t *handle = multi->slaves[i].handle;
|
||||
int err = snd_pcm_sync_go(handle, sync);
|
||||
if (err < 0)
|
||||
return err;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int snd_pcm_multi_drain(void *private)
|
||||
{
|
||||
snd_pcm_multi_t *multi = (snd_pcm_multi_t*) private;
|
||||
|
|
@ -603,7 +590,6 @@ struct snd_pcm_ops snd_pcm_multi_ops = {
|
|||
state: snd_pcm_multi_state,
|
||||
prepare: snd_pcm_multi_prepare,
|
||||
go: snd_pcm_multi_go,
|
||||
sync_go: snd_pcm_multi_sync_go,
|
||||
drain: snd_pcm_multi_drain,
|
||||
flush: snd_pcm_multi_flush,
|
||||
pause: snd_pcm_multi_pause,
|
||||
|
|
|
|||
|
|
@ -309,12 +309,6 @@ static int snd_pcm_plug_go(void *private)
|
|||
return snd_pcm_go(plug->slave);
|
||||
}
|
||||
|
||||
static int snd_pcm_plug_sync_go(void *private, snd_pcm_sync_t *sync)
|
||||
{
|
||||
snd_pcm_plug_t *plug = (snd_pcm_plug_t*) private;
|
||||
return snd_pcm_sync_go(plug->slave, sync);
|
||||
}
|
||||
|
||||
static int snd_pcm_plug_drain(void *private)
|
||||
{
|
||||
snd_pcm_plug_t *plug = (snd_pcm_plug_t*) private;
|
||||
|
|
@ -592,7 +586,6 @@ struct snd_pcm_ops snd_pcm_plug_ops = {
|
|||
state: snd_pcm_plug_state,
|
||||
prepare: snd_pcm_plug_prepare,
|
||||
go: snd_pcm_plug_go,
|
||||
sync_go: snd_pcm_plug_sync_go,
|
||||
drain: snd_pcm_plug_drain,
|
||||
flush: snd_pcm_plug_flush,
|
||||
pause: snd_pcm_plug_pause,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue