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);
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);
#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"
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);
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;
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,
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);
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;
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,
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;
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,