From fc69109d6989d4536c6a73d287d89fa8dc1de8cc Mon Sep 17 00:00:00 2001 From: Abramo Bagnara Date: Mon, 31 Jan 2000 12:40:05 +0000 Subject: [PATCH] added readv/writev support --- include/pcm.h | 2 ++ src/pcm/pcm.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/include/pcm.h b/include/pcm.h index 47dd2e05..2797e364 100644 --- a/include/pcm.h +++ b/include/pcm.h @@ -42,6 +42,8 @@ int snd_pcm_playback_pause(snd_pcm_t *handle, int enable); ssize_t snd_pcm_transfer_size(snd_pcm_t *handle, int channel); ssize_t snd_pcm_write(snd_pcm_t *handle, const void *buffer, size_t size); ssize_t snd_pcm_read(snd_pcm_t *handle, void *buffer, size_t size); +ssize_t snd_pcm_writev(snd_pcm_t *pcm, const struct iovec *vector, int count); +ssize_t snd_pcm_readv(snd_pcm_t *pcm, const struct iovec *vector, int count); int snd_pcm_mmap(snd_pcm_t *handle, int channel, snd_pcm_mmap_control_t **control, void **buffer); int snd_pcm_munmap(snd_pcm_t *handle, int channel); diff --git a/src/pcm/pcm.c b/src/pcm/pcm.c index 4cb9f01a..99fccae2 100644 --- a/src/pcm/pcm.c +++ b/src/pcm/pcm.c @@ -448,6 +448,29 @@ ssize_t snd_pcm_write(snd_pcm_t *pcm, const void *buffer, size_t size) return result; } +ssize_t snd_pcm_writev(snd_pcm_t *pcm, const struct iovec *vector, int count) +{ + ssize_t result; + + if (!pcm || (!vector && count > 0) || count < 0) + return -EINVAL; + if (pcm->fd[SND_PCM_CHANNEL_PLAYBACK] < 0) + return -EINVAL; +#if 0 + result = writev(pcm->fd[SND_PCM_CHANNEL_PLAYBACK], vector, count); +#else + { + snd_v_args_t args; + args.vector = vector; + args.count = count; + result = ioctl(pcm->fd[SND_PCM_CHANNEL_PLAYBACK], SND_IOCTL_WRITEV, &args); + } +#endif + if (result < 0) + return -errno; + return result; +} + ssize_t snd_pcm_read(snd_pcm_t *pcm, void *buffer, size_t size) { ssize_t result; @@ -462,6 +485,29 @@ ssize_t snd_pcm_read(snd_pcm_t *pcm, void *buffer, size_t size) return result; } +ssize_t snd_pcm_readv(snd_pcm_t *pcm, const struct iovec *vector, int count) +{ + ssize_t result; + + if (!pcm || (!vector && count > 0) || count < 0) + return -EINVAL; + if (pcm->fd[SND_PCM_CHANNEL_CAPTURE] < 0) + return -EINVAL; +#if 0 + result = readv(pcm->fd[SND_PCM_CHANNEL_CAPTURE], vector, count); +#else + { + snd_v_args_t args; + args.vector = vector; + args.count = count; + result = ioctl(pcm->fd[SND_PCM_CHANNEL_CAPTURE], SND_IOCTL_READV, &args); + } +#endif + if (result < 0) + return -errno; + return result; +} + int snd_pcm_mmap(snd_pcm_t *pcm, int channel, snd_pcm_mmap_control_t **control, void **buffer) { snd_pcm_channel_info_t info; -- 2.47.1