From 74832704a88f6f7818b7d7cf03e7b5ab52ee94e0 Mon Sep 17 00:00:00 2001 From: Abramo Bagnara Date: Tue, 4 Jul 2000 19:29:16 +0000 Subject: [PATCH] Implemented generic sync requests --- include/pcm.h | 21 ++++++++++++++++++++- src/pcm/pcm.c | 40 ++++++++++++++++++++++++++++++++++++---- src/pcm/pcm_hw.c | 10 ---------- src/pcm/pcm_local.h | 1 - src/pcm/pcm_multi.c | 14 -------------- src/pcm/pcm_plug.c | 7 ------- 6 files changed, 56 insertions(+), 37 deletions(-) diff --git a/include/pcm.h b/include/pcm.h index 9369f39e..637cda2a 100644 --- a/include/pcm.h +++ b/include/pcm.h @@ -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); diff --git a/src/pcm/pcm.c b/src/pcm/pcm.c index 39dac4f6..9a4b80f7 100644 --- a/src/pcm/pcm.c +++ b/src/pcm/pcm.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #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) -{ - assert(handle); - return handle->ops->sync_go(handle->op_arg, 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) +{ + 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); diff --git a/src/pcm/pcm_hw.c b/src/pcm/pcm_hw.c index ac375ad2..f6d8eae0 100644 --- a/src/pcm/pcm_hw.c +++ b/src/pcm/pcm_hw.c @@ -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, diff --git a/src/pcm/pcm_local.h b/src/pcm/pcm_local.h index 75891ddf..65743a9e 100644 --- a/src/pcm/pcm_local.h +++ b/src/pcm/pcm_local.h @@ -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); diff --git a/src/pcm/pcm_multi.c b/src/pcm/pcm_multi.c index 2ee15292..6dfb62ab 100644 --- a/src/pcm/pcm_multi.c +++ b/src/pcm/pcm_multi.c @@ -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, diff --git a/src/pcm/pcm_plug.c b/src/pcm/pcm_plug.c index 56378ea1..97b7a492 100644 --- a/src/pcm/pcm_plug.c +++ b/src/pcm/pcm_plug.c @@ -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, -- 2.47.1