Added mmap_control access function. Converted static checks in asserts. Uniformed avail functions to kernel code

This commit is contained in:
Abramo Bagnara 2000-06-04 13:13:01 +00:00
parent f11e203d6e
commit ef2a9bdd88
6 changed files with 239 additions and 359 deletions

View file

@ -112,10 +112,14 @@ int snd_pcm_capture_flush(snd_pcm_t *handle);
int snd_pcm_stream_flush(snd_pcm_t *handle, int stream); int snd_pcm_stream_flush(snd_pcm_t *handle, int stream);
int snd_pcm_playback_pause(snd_pcm_t *handle, int enable); int snd_pcm_playback_pause(snd_pcm_t *handle, int enable);
int snd_pcm_stream_pause(snd_pcm_t *handle, int stream, int enable); int snd_pcm_stream_pause(snd_pcm_t *handle, int stream, int enable);
ssize_t snd_pcm_transfer_size(snd_pcm_t *handle, int stream);
int snd_pcm_stream_state(snd_pcm_t *handle, int stream); int snd_pcm_stream_state(snd_pcm_t *handle, int stream);
int snd_pcm_mmap_stream_state(snd_pcm_t *handle, int stream);
ssize_t snd_pcm_stream_byte_io(snd_pcm_t *handle, int stream, int update); ssize_t snd_pcm_stream_byte_io(snd_pcm_t *handle, int stream, int update);
ssize_t snd_pcm_mmap_stream_byte_io(snd_pcm_t *handle, int stream);
ssize_t snd_pcm_stream_byte_data(snd_pcm_t *handle, int stream);
ssize_t snd_pcm_mmap_stream_byte_data(snd_pcm_t *handle, int stream);
ssize_t snd_pcm_stream_seek(snd_pcm_t *pcm, int stream, off_t offset); ssize_t snd_pcm_stream_seek(snd_pcm_t *pcm, int stream, off_t offset);
ssize_t snd_pcm_mmap_stream_seek(snd_pcm_t *pcm, int stream, off_t offset);
ssize_t snd_pcm_write(snd_pcm_t *handle, const void *buffer, size_t size); 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_read(snd_pcm_t *handle, void *buffer, size_t size);
ssize_t snd_pcm_writev(snd_pcm_t *pcm, const struct iovec *vector, unsigned long count); ssize_t snd_pcm_writev(snd_pcm_t *pcm, const struct iovec *vector, unsigned long count);
@ -137,11 +141,9 @@ ssize_t snd_pcm_mmap_write(snd_pcm_t *handle, const void *buffer, size_t size);
ssize_t snd_pcm_mmap_read(snd_pcm_t *handle, void *buffer, size_t size); ssize_t snd_pcm_mmap_read(snd_pcm_t *handle, void *buffer, size_t size);
ssize_t snd_pcm_mmap_writev(snd_pcm_t *pcm, const struct iovec *vector, unsigned long count); ssize_t snd_pcm_mmap_writev(snd_pcm_t *pcm, const struct iovec *vector, unsigned long count);
ssize_t snd_pcm_mmap_readv(snd_pcm_t *pcm, const struct iovec *vector, unsigned long count); ssize_t snd_pcm_mmap_readv(snd_pcm_t *pcm, const struct iovec *vector, unsigned long count);
int snd_pcm_mmap_frames_used(snd_pcm_t *pcm, int stream, ssize_t *frames); int snd_pcm_mmap_frames_avail(snd_pcm_t *pcm, int stream, ssize_t *frames);
int snd_pcm_mmap_frames_free(snd_pcm_t *pcm, int stream, ssize_t *frames);
ssize_t snd_pcm_mmap_frames_xfer(snd_pcm_t *pcm, int stream, size_t frames); ssize_t snd_pcm_mmap_frames_xfer(snd_pcm_t *pcm, int stream, size_t frames);
ssize_t snd_pcm_mmap_frames_offset(snd_pcm_t *pcm, int stream); ssize_t snd_pcm_mmap_frames_offset(snd_pcm_t *pcm, int stream);
int snd_pcm_mmap_commit_frames(snd_pcm_t *pcm, int stream, int frames);
ssize_t snd_pcm_mmap_write_areas(snd_pcm_t *pcm, snd_pcm_channel_area_t *channels, size_t frames); ssize_t snd_pcm_mmap_write_areas(snd_pcm_t *pcm, snd_pcm_channel_area_t *channels, size_t frames);
ssize_t snd_pcm_mmap_write_frames(snd_pcm_t *pcm, const void *buffer, size_t frames); ssize_t snd_pcm_mmap_write_frames(snd_pcm_t *pcm, const void *buffer, size_t frames);
ssize_t snd_pcm_mmap_read_areas(snd_pcm_t *pcm, snd_pcm_channel_area_t *channels, size_t frames); ssize_t snd_pcm_mmap_read_areas(snd_pcm_t *pcm, snd_pcm_channel_area_t *channels, size_t frames);
@ -161,6 +163,7 @@ int snd_pcm_areas_copy(const snd_pcm_channel_area_t *src_channels, size_t src_of
const snd_pcm_channel_area_t *dst_channels, size_t dst_offset, const snd_pcm_channel_area_t *dst_channels, size_t dst_offset,
size_t vcount, size_t frames, int format); size_t vcount, size_t frames, int format);
/* misc */ /* misc */
int snd_pcm_format_signed(int format); int snd_pcm_format_signed(int format);

View file

@ -25,6 +25,7 @@
#include <errno.h> #include <errno.h>
#include <sys/poll.h> #include <sys/poll.h>
#include <sys/uio.h> #include <sys/uio.h>
#include <assert.h>
#include "pcm_local.h" #include "pcm_local.h"
int snd_pcm_abstract_open(snd_pcm_t **handle, int mode, int snd_pcm_abstract_open(snd_pcm_t **handle, int mode,
@ -32,8 +33,7 @@ int snd_pcm_abstract_open(snd_pcm_t **handle, int mode,
{ {
snd_pcm_t *pcm; snd_pcm_t *pcm;
if (!handle) assert(handle);
return -EFAULT;
*handle = NULL; *handle = NULL;
pcm = (snd_pcm_t *) calloc(1, sizeof(snd_pcm_t) + extra); pcm = (snd_pcm_t *) calloc(1, sizeof(snd_pcm_t) + extra);
@ -65,13 +65,10 @@ int snd_pcm_stream_close(snd_pcm_t *pcm, int stream)
int ret = 0; int ret = 0;
int err; int err;
snd_pcm_stream_t *str; snd_pcm_stream_t *str;
if (!pcm) assert(pcm);
return -EFAULT; assert(stream >= 0 && stream <= 1);
if (stream < 0 || stream > 1)
return -EINVAL;
str = &pcm->stream[stream]; str = &pcm->stream[stream];
if (!str->open) assert(str->open);
return -EBADFD;
if (str->mmap_control) { if (str->mmap_control) {
if ((err = snd_pcm_munmap_control(pcm, stream)) < 0) if ((err = snd_pcm_munmap_control(pcm, stream)) < 0)
ret = err; ret = err;
@ -92,8 +89,7 @@ int snd_pcm_close(snd_pcm_t *pcm)
int err, ret = 0; int err, ret = 0;
int stream; int stream;
if (!pcm) assert(pcm);
return -EFAULT;
for (stream = 0; stream < 2; ++stream) { for (stream = 0; stream < 2; ++stream) {
if (pcm->stream[stream].open) { if (pcm->stream[stream].open) {
if ((err = snd_pcm_stream_close(pcm, stream)) < 0) if ((err = snd_pcm_stream_close(pcm, stream)) < 0)
@ -107,26 +103,24 @@ int snd_pcm_close(snd_pcm_t *pcm)
int snd_pcm_stream_nonblock(snd_pcm_t *pcm, int stream, int nonblock) int snd_pcm_stream_nonblock(snd_pcm_t *pcm, int stream, int nonblock)
{ {
int err; int err;
if (!pcm) snd_pcm_stream_t *str;
return -EFAULT; assert(pcm);
if (stream < 0 || stream > 1) assert(stream >= 0 && stream <= 1);
return -EINVAL; str = &pcm->stream[stream];
if (!pcm->stream[stream].open) assert(pcm->stream[stream].open);
return -EBADFD;
if ((err = pcm->ops->stream_nonblock(pcm, stream, nonblock)) < 0) if ((err = pcm->ops->stream_nonblock(pcm, stream, nonblock)) < 0)
return err; return err;
if (nonblock) if (nonblock)
pcm->stream[stream].mode |= SND_PCM_NONBLOCK; str->mode |= SND_PCM_NONBLOCK;
else else
pcm->stream[stream].mode &= ~SND_PCM_NONBLOCK; str->mode &= ~SND_PCM_NONBLOCK;
return 0; return 0;
} }
int snd_pcm_info(snd_pcm_t *pcm, snd_pcm_info_t *info) int snd_pcm_info(snd_pcm_t *pcm, snd_pcm_info_t *info)
{ {
int stream; int stream;
if (!pcm || !info) assert(pcm && info);
return -EFAULT;
for (stream = 0; stream < 2; ++stream) { for (stream = 0; stream < 2; ++stream) {
if (pcm->stream[stream].open) if (pcm->stream[stream].open)
return pcm->ops->info(pcm, stream, info); return pcm->ops->info(pcm, stream, info);
@ -136,12 +130,9 @@ int snd_pcm_info(snd_pcm_t *pcm, snd_pcm_info_t *info)
int snd_pcm_stream_info(snd_pcm_t *pcm, snd_pcm_stream_info_t *info) int snd_pcm_stream_info(snd_pcm_t *pcm, snd_pcm_stream_info_t *info)
{ {
if (!pcm || !info) assert(pcm && info);
return -EFAULT; assert(info->stream >= 0 && info->stream <= 1);
if (info->stream < 0 || info->stream > 1) assert(pcm->stream[info->stream].open);
return -EINVAL;
if (!pcm->stream[info->stream].open)
return -EBADFD;
return pcm->ops->stream_info(pcm, info); return pcm->ops->stream_info(pcm, info);
} }
@ -150,15 +141,11 @@ int snd_pcm_stream_params(snd_pcm_t *pcm, snd_pcm_stream_params_t *params)
int err; int err;
snd_pcm_stream_setup_t setup; snd_pcm_stream_setup_t setup;
snd_pcm_stream_t *str; snd_pcm_stream_t *str;
if (!pcm || !params) assert(pcm && params);
return -EFAULT; assert(params->stream >= 0 && params->stream <= 1);
if (params->stream < 0 || params->stream > 1)
return -EINVAL;
str = &pcm->stream[params->stream]; str = &pcm->stream[params->stream];
if (!str->open) assert(str->open);
return -EBADFD; assert(!str->mmap_data);
if (str->mmap_control)
return -EBADFD;
if ((err = pcm->ops->stream_params(pcm, params)) < 0) if ((err = pcm->ops->stream_params(pcm, params)) < 0)
return err; return err;
str->valid_setup = 0; str->valid_setup = 0;
@ -170,13 +157,10 @@ int snd_pcm_stream_setup(snd_pcm_t *pcm, snd_pcm_stream_setup_t *setup)
{ {
int err; int err;
snd_pcm_stream_t *str; snd_pcm_stream_t *str;
if (!pcm || !setup) assert(pcm && setup);
return -EFAULT; assert(setup->stream >= 0 && setup->stream <= 1);
if (setup->stream < 0 || setup->stream > 1)
return -EINVAL;
str = &pcm->stream[setup->stream]; str = &pcm->stream[setup->stream];
if (!str->open) assert(str->open);
return -EBADFD;
if (str->valid_setup) { if (str->valid_setup) {
memcpy(setup, &str->setup, sizeof(*setup)); memcpy(setup, &str->setup, sizeof(*setup));
return 0; return 0;
@ -194,50 +178,38 @@ int snd_pcm_stream_setup(snd_pcm_t *pcm, snd_pcm_stream_setup_t *setup)
const snd_pcm_stream_setup_t* snd_pcm_stream_cached_setup(snd_pcm_t *pcm, int stream) const snd_pcm_stream_setup_t* snd_pcm_stream_cached_setup(snd_pcm_t *pcm, int stream)
{ {
snd_pcm_stream_t *str; snd_pcm_stream_t *str;
if (!pcm) assert(pcm);
return 0; assert(stream >= 0 && stream <= 1);
if (stream < 0 || stream > 1)
return 0;
str = &pcm->stream[stream]; str = &pcm->stream[stream];
if (!str->open || !str->valid_setup) assert(str->valid_setup);
return 0;
return &str->setup; return &str->setup;
} }
int snd_pcm_channel_setup(snd_pcm_t *pcm, int stream, snd_pcm_channel_setup_t *setup) int snd_pcm_channel_setup(snd_pcm_t *pcm, int stream, snd_pcm_channel_setup_t *setup)
{ {
snd_pcm_stream_t *str; snd_pcm_stream_t *str;
if (!pcm || !setup) assert(pcm && setup);
return -EFAULT; assert(stream >= 0 && stream <= 1);
if (stream < 0 || stream > 1)
return -EINVAL;
str = &pcm->stream[stream]; str = &pcm->stream[stream];
if (!str->open || !str->valid_setup) assert(str->valid_setup);
return -EBADFD;
return pcm->ops->channel_setup(pcm, stream, setup); return pcm->ops->channel_setup(pcm, stream, setup);
} }
int snd_pcm_stream_status(snd_pcm_t *pcm, snd_pcm_stream_status_t *status) int snd_pcm_stream_status(snd_pcm_t *pcm, snd_pcm_stream_status_t *status)
{ {
if (!pcm || !status) assert(pcm && status);
return -EFAULT; assert(status->stream >= 0 && status->stream <= 1);
if (status->stream < 0 || status->stream > 1) assert(pcm->stream[status->stream].open);
return -EINVAL;
if (!pcm->stream[status->stream].open)
return -EBADFD;
return pcm->ops->stream_status(pcm, status); return pcm->ops->stream_status(pcm, status);
} }
int snd_pcm_stream_state(snd_pcm_t *pcm, int stream) int snd_pcm_stream_state(snd_pcm_t *pcm, int stream)
{ {
snd_pcm_stream_t *str; snd_pcm_stream_t *str;
if (!pcm) assert(pcm);
return -EFAULT; assert(stream >= 0 && stream <= 1);
if (stream < 0 || stream > 1)
return -EINVAL;
str = &pcm->stream[stream]; str = &pcm->stream[stream];
if (!str->open) assert(str->open);
return -EBADFD;
if (str->mmap_control) if (str->mmap_control)
return str->mmap_control->status; return str->mmap_control->status;
return pcm->ops->stream_state(pcm, stream); return pcm->ops->stream_state(pcm, stream);
@ -246,26 +218,32 @@ int snd_pcm_stream_state(snd_pcm_t *pcm, int stream)
int snd_pcm_stream_byte_io(snd_pcm_t *pcm, int stream, int update) int snd_pcm_stream_byte_io(snd_pcm_t *pcm, int stream, int update)
{ {
snd_pcm_stream_t *str; snd_pcm_stream_t *str;
if (!pcm) assert(pcm);
return -EFAULT; assert(stream >= 0 && stream <= 1);
if (stream < 0 || stream > 1)
return -EINVAL;
str = &pcm->stream[stream]; str = &pcm->stream[stream];
if (!str->open) assert(str->valid_setup);
return -EBADFD;
if (str->mmap_control && !update) if (str->mmap_control && !update)
return str->mmap_control->byte_io; return str->mmap_control->byte_io;
return pcm->ops->stream_byte_io(pcm, stream, update); return pcm->ops->stream_byte_io(pcm, stream, update);
} }
int snd_pcm_stream_byte_data(snd_pcm_t *pcm, int stream)
{
snd_pcm_stream_t *str;
assert(pcm);
assert(stream >= 0 && stream <= 1);
str = &pcm->stream[stream];
assert(str->valid_setup);
if (str->mmap_control)
return str->mmap_control->byte_data;
return pcm->ops->stream_seek(pcm, stream, 0);
}
int snd_pcm_stream_prepare(snd_pcm_t *pcm, int stream) int snd_pcm_stream_prepare(snd_pcm_t *pcm, int stream)
{ {
if (!pcm) assert(pcm);
return -EFAULT; assert(stream >= 0 && stream <= 1);
if (stream < 0 || stream > 1) assert(pcm->stream[stream].open);
return -EINVAL;
if (!pcm->stream[stream].open)
return -EBADFD;
return pcm->ops->stream_prepare(pcm, stream); return pcm->ops->stream_prepare(pcm, stream);
} }
@ -282,13 +260,10 @@ int snd_pcm_capture_prepare(snd_pcm_t *pcm)
int snd_pcm_stream_go(snd_pcm_t *pcm, int stream) int snd_pcm_stream_go(snd_pcm_t *pcm, int stream)
{ {
snd_pcm_stream_t *str; snd_pcm_stream_t *str;
if (!pcm) assert(pcm);
return -EFAULT; assert(stream >= 0 && stream <= 1);
if (stream < 0 || stream > 1)
return -EINVAL;
str = &pcm->stream[stream]; str = &pcm->stream[stream];
if (!str->open) assert(str->valid_setup);
return -EBADFD;
return pcm->ops->stream_go(pcm, stream); return pcm->ops->stream_go(pcm, stream);
} }
@ -305,8 +280,7 @@ int snd_pcm_capture_go(snd_pcm_t *pcm)
int snd_pcm_sync_go(snd_pcm_t *pcm, snd_pcm_sync_t *sync) int snd_pcm_sync_go(snd_pcm_t *pcm, snd_pcm_sync_t *sync)
{ {
int stream; int stream;
if (!pcm || !sync) assert(pcm && sync);
return -EFAULT;
for (stream = 0; stream < 2; ++stream) { for (stream = 0; stream < 2; ++stream) {
if (pcm->stream[stream].open) if (pcm->stream[stream].open)
return pcm->ops->sync_go(pcm, stream, sync); return pcm->ops->sync_go(pcm, stream, sync);
@ -316,14 +290,10 @@ int snd_pcm_sync_go(snd_pcm_t *pcm, snd_pcm_sync_t *sync)
int snd_pcm_stream_drain(snd_pcm_t *pcm, int stream) int snd_pcm_stream_drain(snd_pcm_t *pcm, int stream)
{ {
if (!pcm) assert(pcm);
return -EFAULT; assert(stream >= 0 && stream <= 1);
if (stream < 0 || stream > 1) assert(pcm->stream[stream].open);
return -EINVAL; assert(stream == SND_PCM_STREAM_PLAYBACK);
if (!pcm->stream[stream].open)
return -EBADFD;
if (stream != SND_PCM_STREAM_PLAYBACK)
return -EBADFD;
return pcm->ops->stream_drain(pcm, stream); return pcm->ops->stream_drain(pcm, stream);
} }
@ -334,13 +304,9 @@ int snd_pcm_playback_drain(snd_pcm_t *pcm)
int snd_pcm_stream_flush(snd_pcm_t *pcm, int stream) int snd_pcm_stream_flush(snd_pcm_t *pcm, int stream)
{ {
int err; assert(pcm);
if (!pcm) assert(stream >= 0 && stream <= 1);
return -EFAULT; assert(pcm->stream[stream].open);
if (stream < 0 || stream > 1)
return -EINVAL;
if (!pcm->stream[stream].open)
return -EBADFD;
return pcm->ops->stream_flush(pcm, stream); return pcm->ops->stream_flush(pcm, stream);
} }
@ -356,15 +322,10 @@ int snd_pcm_capture_flush(snd_pcm_t *pcm)
int snd_pcm_stream_pause(snd_pcm_t *pcm, int stream, int enable) int snd_pcm_stream_pause(snd_pcm_t *pcm, int stream, int enable)
{ {
int err; assert(pcm);
if (!pcm) assert(stream >= 0 && stream <= 1);
return -EFAULT; assert(pcm->stream[stream].open);
if (stream < 0 || stream > 1) assert(stream == SND_PCM_STREAM_PLAYBACK);
return -EINVAL;
if (!pcm->stream[stream].open)
return -EBADFD;
if (stream != SND_PCM_STREAM_PLAYBACK)
return -EBADFD;
return pcm->ops->stream_pause(pcm, stream, enable); return pcm->ops->stream_pause(pcm, stream, enable);
} }
@ -373,124 +334,74 @@ int snd_pcm_playback_pause(snd_pcm_t *pcm, int enable)
return snd_pcm_stream_pause(pcm, SND_PCM_STREAM_PLAYBACK, enable); return snd_pcm_stream_pause(pcm, SND_PCM_STREAM_PLAYBACK, enable);
} }
ssize_t snd_pcm_transfer_size(snd_pcm_t *pcm, int stream)
{
snd_pcm_stream_t *str;
if (!pcm)
return -EFAULT;
if (stream < 0 || stream > 1)
return -EINVAL;
str = &pcm->stream[stream];
if (!str->open)
return -EBADFD;
if (!str->valid_setup)
return -EBADFD;
if (str->setup.mode != SND_PCM_MODE_FRAGMENT)
return -EBADFD;
return str->setup.frag_size;
}
ssize_t snd_pcm_stream_seek(snd_pcm_t *pcm, int stream, off_t offset) ssize_t snd_pcm_stream_seek(snd_pcm_t *pcm, int stream, off_t offset)
{ {
snd_pcm_stream_t *str; snd_pcm_stream_t *str;
size_t bytes_per_frame; assert(pcm);
if (!pcm) assert(stream >= 0 && stream <= 1);
return -EFAULT;
if (stream < 0 || stream > 1)
return -EINVAL;
str = &pcm->stream[stream]; str = &pcm->stream[stream];
if (!str->open) assert(str->valid_setup);
return -EBADFD; if (str->mmap_control)
if (!str->valid_setup) return snd_pcm_mmap_stream_seek(pcm, stream, offset);
return -EBADFD; else
#if 0
/* TODO */
if (str->mmap_control) {
} else
#endif
return pcm->ops->stream_seek(pcm, stream, offset); return pcm->ops->stream_seek(pcm, stream, offset);
} }
ssize_t snd_pcm_write(snd_pcm_t *pcm, const void *buffer, size_t size) ssize_t snd_pcm_write(snd_pcm_t *pcm, const void *buffer, size_t size)
{ {
if (!pcm) assert(pcm);
return -EFAULT; assert(pcm->stream[SND_PCM_STREAM_PLAYBACK].valid_setup);
if (!pcm->stream[SND_PCM_STREAM_PLAYBACK].open || assert(size == 0 || buffer);
!pcm->stream[SND_PCM_STREAM_PLAYBACK].valid_setup)
return -EBADFD;
if (size > 0 && !buffer)
return -EFAULT;
return pcm->ops->write(pcm, buffer, size); return pcm->ops->write(pcm, buffer, size);
} }
ssize_t snd_pcm_writev(snd_pcm_t *pcm, const struct iovec *vector, unsigned long count) ssize_t snd_pcm_writev(snd_pcm_t *pcm, const struct iovec *vector, unsigned long count)
{ {
if (!pcm) assert(pcm);
return -EFAULT; assert(pcm->stream[SND_PCM_STREAM_PLAYBACK].valid_setup);
if (!pcm->stream[SND_PCM_STREAM_PLAYBACK].open || assert(count == 0 || vector);
!pcm->stream[SND_PCM_STREAM_PLAYBACK].valid_setup)
return -EBADFD;
if (count > 0 && !vector)
return -EFAULT;
return pcm->ops->writev(pcm, vector, count); return pcm->ops->writev(pcm, vector, count);
} }
ssize_t snd_pcm_read(snd_pcm_t *pcm, void *buffer, size_t size) ssize_t snd_pcm_read(snd_pcm_t *pcm, void *buffer, size_t size)
{ {
if (!pcm) assert(pcm);
return -EFAULT; assert(pcm->stream[SND_PCM_STREAM_CAPTURE].valid_setup);
if (!pcm->stream[SND_PCM_STREAM_CAPTURE].open || assert(size == 0 || buffer);
!pcm->stream[SND_PCM_STREAM_CAPTURE].valid_setup)
return -EBADFD;
if (size > 0 && !buffer)
return -EFAULT;
return pcm->ops->read(pcm, buffer, size); return pcm->ops->read(pcm, buffer, size);
} }
ssize_t snd_pcm_readv(snd_pcm_t *pcm, const struct iovec *vector, unsigned long count) ssize_t snd_pcm_readv(snd_pcm_t *pcm, const struct iovec *vector, unsigned long count)
{ {
if (!pcm) assert(pcm);
return -EFAULT; assert(pcm->stream[SND_PCM_STREAM_CAPTURE].valid_setup);
if (!pcm->stream[SND_PCM_STREAM_CAPTURE].open || assert(count == 0 || vector);
!pcm->stream[SND_PCM_STREAM_CAPTURE].valid_setup)
return -EBADFD;
if (count > 0 && !vector)
return -EFAULT;
return pcm->ops->readv(pcm, vector, count); return pcm->ops->readv(pcm, vector, count);
} }
int snd_pcm_file_descriptor(snd_pcm_t* pcm, int stream) int snd_pcm_file_descriptor(snd_pcm_t* pcm, int stream)
{ {
if (!pcm) assert(pcm);
return -EFAULT; assert(stream >= 0 && stream <= 1);
if (stream < 0 || stream > 1) assert(pcm->stream[stream].open);
return -EINVAL;
if (!pcm->stream[stream].open)
return -EBADFD;
return pcm->ops->file_descriptor(pcm, stream); return pcm->ops->file_descriptor(pcm, stream);
} }
int snd_pcm_channels_mask(snd_pcm_t *pcm, int stream, bitset_t *client_vmask) int snd_pcm_channels_mask(snd_pcm_t *pcm, int stream, bitset_t *client_vmask)
{ {
if (!pcm) assert(pcm);
return -EFAULT; assert(stream >= 0 && stream <= 1);
if (stream < 0 || stream > 1) assert(pcm->stream[stream].valid_setup);
return -EINVAL;
if (!pcm->stream[stream].open)
return -EBADFD;
return pcm->ops->channels_mask(pcm, stream, client_vmask); return pcm->ops->channels_mask(pcm, stream, client_vmask);
} }
ssize_t snd_pcm_bytes_per_second(snd_pcm_t *pcm, int stream) ssize_t snd_pcm_bytes_per_second(snd_pcm_t *pcm, int stream)
{ {
snd_pcm_stream_t *str; snd_pcm_stream_t *str;
if (!pcm) assert(pcm);
return -EFAULT; assert(stream >= 0 && stream <= 1);
if (stream < 0 || stream > 1)
return -EINVAL;
str = &pcm->stream[stream]; str = &pcm->stream[stream];
if (!str->open || !str->valid_setup) assert(str->valid_setup);
return -EBADFD;
return snd_pcm_format_bytes_per_second(&str->setup.format); return snd_pcm_format_bytes_per_second(&str->setup.format);
} }
@ -578,13 +489,10 @@ int snd_pcm_dump_setup(snd_pcm_t *pcm, int stream, FILE *fp)
{ {
snd_pcm_stream_t *str; snd_pcm_stream_t *str;
snd_pcm_stream_setup_t *setup; snd_pcm_stream_setup_t *setup;
if (!pcm) assert(pcm);
return -EFAULT; assert(stream >= 0 && stream <= 1);
if (stream < 0 || stream > 1)
return -EINVAL;
str = &pcm->stream[stream]; str = &pcm->stream[stream];
if (!str->open || !str->valid_setup) assert(str->valid_setup);
return -EBADFD;
setup = &str->setup; setup = &str->setup;
fprintf(fp, "stream: %s\n", assoc(setup->stream, streams)); fprintf(fp, "stream: %s\n", assoc(setup->stream, streams));
fprintf(fp, "mode: %s\n", assoc(setup->mode, modes)); fprintf(fp, "mode: %s\n", assoc(setup->mode, modes));

View file

@ -79,6 +79,7 @@ typedef struct {
size_t mmap_control_size; size_t mmap_control_size;
char *mmap_data; char *mmap_data;
size_t mmap_data_size; size_t mmap_data_size;
enum { _INTERLEAVED, _NONINTERLEAVED, _COMPLEX } mmap_type;
} snd_pcm_stream_t; } snd_pcm_stream_t;
struct snd_pcm { struct snd_pcm {
@ -131,21 +132,19 @@ int conv_index(int src_format, int dst_format);
#define pdprintf( args... ) { ; } #define pdprintf( args... ) { ; }
#endif #endif
static inline ssize_t snd_pcm_mmap_playback_bytes_used(snd_pcm_stream_t *str) static inline size_t snd_pcm_mmap_playback_bytes_avail(snd_pcm_stream_t *str)
{ {
ssize_t bytes_used; ssize_t bytes_avail = str->mmap_control->byte_io + str->setup.buffer_size - str->mmap_control->byte_data;
bytes_used = str->mmap_control->byte_data - str->mmap_control->byte_io; if (bytes_avail < 0)
if (bytes_used < (ssize_t)(str->setup.buffer_size - str->setup.byte_boundary)) bytes_avail += str->setup.byte_boundary;
bytes_used += str->setup.byte_boundary; return bytes_avail;
return bytes_used;
} }
static inline size_t snd_pcm_mmap_capture_bytes_used(snd_pcm_stream_t *str) static inline size_t snd_pcm_mmap_capture_bytes_avail(snd_pcm_stream_t *str)
{ {
ssize_t bytes_used; ssize_t bytes_avail = str->mmap_control->byte_io - str->mmap_control->byte_data;
bytes_used = str->mmap_control->byte_io - str->mmap_control->byte_data; if (bytes_avail < 0)
if (bytes_used < 0) bytes_avail += str->setup.byte_boundary;
bytes_used += str->setup.byte_boundary; return bytes_avail;
return bytes_used;
} }

View file

@ -26,21 +26,21 @@
#include <sys/uio.h> #include <sys/uio.h>
#include "pcm_local.h" #include "pcm_local.h"
static ssize_t snd_pcm_mmap_playback_frames_used(snd_pcm_t *pcm) static ssize_t snd_pcm_mmap_playback_frames_avail(snd_pcm_t *pcm)
{ {
snd_pcm_stream_t *str = &pcm->stream[SND_PCM_STREAM_PLAYBACK]; snd_pcm_stream_t *str = &pcm->stream[SND_PCM_STREAM_PLAYBACK];
ssize_t bytes = snd_pcm_mmap_playback_bytes_used(str); ssize_t bytes = snd_pcm_mmap_playback_bytes_avail(str);
return bytes * 8 / str->bits_per_frame; return bytes * 8 / str->bits_per_frame;
} }
static size_t snd_pcm_mmap_capture_frames_used(snd_pcm_t *pcm) static size_t snd_pcm_mmap_capture_frames_avail(snd_pcm_t *pcm)
{ {
snd_pcm_stream_t *str = &pcm->stream[SND_PCM_STREAM_CAPTURE]; snd_pcm_stream_t *str = &pcm->stream[SND_PCM_STREAM_CAPTURE];
size_t bytes = snd_pcm_mmap_capture_bytes_used(str); size_t bytes = snd_pcm_mmap_capture_bytes_avail(str);
return bytes * 8 / str->bits_per_frame; return bytes * 8 / str->bits_per_frame;
} }
int snd_pcm_mmap_frames_used(snd_pcm_t *pcm, int stream, ssize_t *frames) int snd_pcm_frames_avail(snd_pcm_t *pcm, int stream, ssize_t *frames)
{ {
snd_pcm_stream_t *str; snd_pcm_stream_t *str;
if (!pcm) if (!pcm)
@ -48,53 +48,12 @@ int snd_pcm_mmap_frames_used(snd_pcm_t *pcm, int stream, ssize_t *frames)
if (stream < 0 || stream > 1) if (stream < 0 || stream > 1)
return -EINVAL; return -EINVAL;
str = &pcm->stream[stream]; str = &pcm->stream[stream];
if (!str->open || !str->mmap_control) if (!str->mmap_control)
return -EBADFD; return -EBADFD;
if (stream == SND_PCM_STREAM_PLAYBACK) if (stream == SND_PCM_STREAM_PLAYBACK)
*frames = snd_pcm_mmap_playback_frames_used(pcm); *frames = snd_pcm_mmap_playback_frames_avail(pcm);
else else
*frames = snd_pcm_mmap_capture_frames_used(pcm); *frames = snd_pcm_mmap_capture_frames_avail(pcm);
return 0;
}
static inline size_t snd_pcm_mmap_playback_bytes_free(snd_pcm_stream_t *str)
{
return str->setup.buffer_size - snd_pcm_mmap_playback_bytes_used(str);
}
static size_t snd_pcm_mmap_playback_frames_free(snd_pcm_t *pcm)
{
snd_pcm_stream_t *str = &pcm->stream[SND_PCM_STREAM_PLAYBACK];
size_t bytes = snd_pcm_mmap_playback_bytes_free(str);
return bytes * 8 / str->bits_per_frame;
}
static inline ssize_t snd_pcm_mmap_capture_bytes_free(snd_pcm_stream_t *str)
{
return str->setup.buffer_size - snd_pcm_mmap_capture_bytes_used(str);
}
static ssize_t snd_pcm_mmap_capture_frames_free(snd_pcm_t *pcm)
{
snd_pcm_stream_t *str = &pcm->stream[SND_PCM_STREAM_CAPTURE];
ssize_t bytes = snd_pcm_mmap_capture_bytes_free(str);
return bytes * 8 / str->bits_per_frame;
}
int snd_pcm_mmap_frames_free(snd_pcm_t *pcm, int stream, ssize_t *frames)
{
snd_pcm_stream_t *str;
if (!pcm)
return -EFAULT;
if (stream < 0 || stream > 1)
return -EINVAL;
str = &pcm->stream[stream];
if (!str->open || !str->mmap_control)
return -EBADFD;
if (stream == SND_PCM_STREAM_PLAYBACK)
*frames = snd_pcm_mmap_playback_frames_free(pcm);
else
*frames = snd_pcm_mmap_capture_frames_free(pcm);
return 0; return 0;
} }
@ -104,7 +63,7 @@ static int snd_pcm_mmap_playback_ready(snd_pcm_t *pcm)
str = &pcm->stream[SND_PCM_STREAM_PLAYBACK]; str = &pcm->stream[SND_PCM_STREAM_PLAYBACK];
if (str->mmap_control->status == SND_PCM_STATUS_XRUN) if (str->mmap_control->status == SND_PCM_STATUS_XRUN)
return -EPIPE; return -EPIPE;
return (str->setup.buffer_size - snd_pcm_mmap_playback_bytes_used(str)) >= str->setup.bytes_min; return snd_pcm_mmap_playback_bytes_avail(str) >= str->setup.bytes_min;
} }
static int snd_pcm_mmap_capture_ready(snd_pcm_t *pcm) static int snd_pcm_mmap_capture_ready(snd_pcm_t *pcm)
@ -117,7 +76,7 @@ static int snd_pcm_mmap_capture_ready(snd_pcm_t *pcm)
if (str->setup.xrun_mode == SND_PCM_XRUN_DRAIN) if (str->setup.xrun_mode == SND_PCM_XRUN_DRAIN)
return -EPIPE; return -EPIPE;
} }
if (snd_pcm_mmap_capture_bytes_used(str) >= str->setup.bytes_min) if (snd_pcm_mmap_capture_bytes_avail(str) >= str->setup.bytes_min)
return 1; return 1;
return ret; return ret;
} }
@ -131,7 +90,7 @@ int snd_pcm_mmap_ready(snd_pcm_t *pcm, int stream)
if (stream < 0 || stream > 1) if (stream < 0 || stream > 1)
return -EINVAL; return -EINVAL;
str = &pcm->stream[stream]; str = &pcm->stream[stream];
if (!str->open || !str->mmap_control) if (!str->mmap_control)
return -EBADFD; return -EBADFD;
ctrl = str->mmap_control; ctrl = str->mmap_control;
if (ctrl->status < SND_PCM_STATUS_PREPARED) if (ctrl->status < SND_PCM_STATUS_PREPARED)
@ -148,14 +107,12 @@ static size_t snd_pcm_mmap_playback_bytes_xfer(snd_pcm_t *pcm, size_t bytes)
snd_pcm_stream_t *str = &pcm->stream[SND_PCM_STREAM_PLAYBACK]; snd_pcm_stream_t *str = &pcm->stream[SND_PCM_STREAM_PLAYBACK];
snd_pcm_mmap_control_t *ctrl = str->mmap_control; snd_pcm_mmap_control_t *ctrl = str->mmap_control;
size_t bytes_cont; size_t bytes_cont;
size_t byte_data = ctrl->byte_data; size_t bytes_avail = snd_pcm_mmap_playback_bytes_avail(str);
size_t bytes_free = snd_pcm_mmap_playback_bytes_free(str); if (bytes_avail < bytes)
if (bytes_free < bytes) bytes = bytes_avail;
bytes = bytes_free; bytes_cont = str->setup.buffer_size - ctrl->byte_data % str->setup.buffer_size;
bytes_cont = str->setup.buffer_size - (byte_data % str->setup.buffer_size);
if (bytes_cont < bytes) if (bytes_cont < bytes)
bytes = bytes_cont; bytes = bytes_cont;
bytes -= bytes % str->setup.bytes_align;
return bytes; return bytes;
} }
@ -164,14 +121,12 @@ static size_t snd_pcm_mmap_capture_bytes_xfer(snd_pcm_t *pcm, size_t bytes)
snd_pcm_stream_t *str = &pcm->stream[SND_PCM_STREAM_CAPTURE]; snd_pcm_stream_t *str = &pcm->stream[SND_PCM_STREAM_CAPTURE];
snd_pcm_mmap_control_t *ctrl = str->mmap_control; snd_pcm_mmap_control_t *ctrl = str->mmap_control;
size_t bytes_cont; size_t bytes_cont;
size_t byte_data = ctrl->byte_data; size_t bytes_avail = snd_pcm_mmap_capture_bytes_avail(str);
size_t bytes_used = snd_pcm_mmap_capture_bytes_used(str); if (bytes_avail < bytes)
if (bytes_used < bytes) bytes = bytes_avail;
bytes = bytes_used; bytes_cont = str->setup.buffer_size - ctrl->byte_data % str->setup.buffer_size;
bytes_cont = str->setup.buffer_size - (byte_data % str->setup.buffer_size);
if (bytes_cont < bytes) if (bytes_cont < bytes)
bytes = bytes_cont; bytes = bytes_cont;
bytes -= bytes % str->setup.bytes_align;
return bytes; return bytes;
} }
@ -199,7 +154,7 @@ ssize_t snd_pcm_mmap_frames_xfer(snd_pcm_t *pcm, int stream, size_t frames)
if (stream < 0 || stream > 1) if (stream < 0 || stream > 1)
return -EINVAL; return -EINVAL;
str = &pcm->stream[stream]; str = &pcm->stream[stream];
if (!str->open || !str->mmap_control) if (!str->mmap_control)
return -EBADFD; return -EBADFD;
if (stream == SND_PCM_STREAM_PLAYBACK) if (stream == SND_PCM_STREAM_PLAYBACK)
return snd_pcm_mmap_playback_frames_xfer(pcm, frames); return snd_pcm_mmap_playback_frames_xfer(pcm, frames);
@ -216,7 +171,7 @@ ssize_t snd_pcm_mmap_frames_offset(snd_pcm_t *pcm, int stream)
if (stream < 0 || stream > 1) if (stream < 0 || stream > 1)
return -EINVAL; return -EINVAL;
str = &pcm->stream[stream]; str = &pcm->stream[stream];
if (!str->open) if (!str->mmap_control)
return -EBADFD; return -EBADFD;
ctrl = str->mmap_control; ctrl = str->mmap_control;
if (!ctrl) if (!ctrl)
@ -224,32 +179,80 @@ ssize_t snd_pcm_mmap_frames_offset(snd_pcm_t *pcm, int stream)
return (ctrl->byte_data % str->setup.buffer_size) * 8 / str->bits_per_frame; return (ctrl->byte_data % str->setup.buffer_size) * 8 / str->bits_per_frame;
} }
int snd_pcm_mmap_commit_frames(snd_pcm_t *pcm, int stream, int frames) int snd_pcm_mmap_stream_state(snd_pcm_t *pcm, int stream)
{ {
snd_pcm_stream_t *str; snd_pcm_stream_t *str;
snd_pcm_mmap_control_t *ctrl; assert(pcm);
size_t byte_data, bytes; assert(stream >= 0 && stream <= 1);
if (!pcm)
return -EFAULT;
if (stream < 0 || stream > 1)
return -EINVAL;
str = &pcm->stream[stream]; str = &pcm->stream[stream];
if (!str->open) assert(str->mmap_control);
return str->mmap_control->status;
}
int snd_pcm_mmap_stream_byte_io(snd_pcm_t *pcm, int stream)
{
snd_pcm_stream_t *str;
assert(pcm);
assert(stream >= 0 && stream <= 1);
str = &pcm->stream[stream];
assert(str->mmap_control);
return str->mmap_control->byte_io;
}
int snd_pcm_mmap_stream_byte_data(snd_pcm_t *pcm, int stream)
{
snd_pcm_stream_t *str;
assert(pcm);
assert(stream >= 0 && stream <= 1);
str = &pcm->stream[stream];
assert(str->mmap_control);
return str->mmap_control->byte_data;
}
ssize_t snd_pcm_mmap_stream_seek(snd_pcm_t *pcm, int stream, off_t offset)
{
snd_pcm_stream_t *str;
ssize_t byte_data;
assert(pcm);
assert(stream >= 0 && stream <= 1);
str = &pcm->stream[stream];
assert(str->mmap_control);
byte_data = str->mmap_control->byte_data;
if (offset == 0)
return byte_data;
switch (str->mmap_control->status) {
case SND_PCM_STATUS_RUNNING:
if (str->setup.mode == SND_PCM_MODE_FRAME)
snd_pcm_stream_byte_io(pcm, stream, 1);
break;
case SND_PCM_STATUS_PREPARED:
break;
default:
return -EBADFD; return -EBADFD;
ctrl = str->mmap_control;
if (!ctrl)
return -EBADFD;
bytes = frames * str->bits_per_frame;
if (bytes % 8)
return -EINVAL;
bytes /= 8;
byte_data = ctrl->byte_data + bytes;
if (byte_data == str->setup.byte_boundary) {
ctrl->byte_data = 0;
} else {
ctrl->byte_data = byte_data;
} }
return 0; if (offset < 0) {
if (offset < -(ssize_t)str->setup.buffer_size)
offset = -(ssize_t)str->setup.buffer_size;
else
offset -= offset % str->setup.bytes_align;
byte_data += offset;
if (byte_data < 0)
byte_data += str->setup.byte_boundary;
} else {
size_t bytes_avail;
if (stream == SND_PCM_STREAM_PLAYBACK)
bytes_avail = snd_pcm_mmap_playback_bytes_avail(str);
else
bytes_avail = snd_pcm_mmap_capture_bytes_avail(str);
if ((size_t)offset > bytes_avail)
offset = bytes_avail;
offset -= offset % str->setup.bytes_align;
byte_data += offset;
if ((size_t)byte_data >= str->setup.byte_boundary)
byte_data -= str->setup.byte_boundary;
}
str->mmap_control->byte_data = byte_data;
return byte_data;
} }
ssize_t snd_pcm_mmap_write_areas(snd_pcm_t *pcm, snd_pcm_channel_area_t *channels, size_t frames) ssize_t snd_pcm_mmap_write_areas(snd_pcm_t *pcm, snd_pcm_channel_area_t *channels, size_t frames)
@ -299,7 +302,7 @@ ssize_t snd_pcm_mmap_write_areas(snd_pcm_t *pcm, snd_pcm_channel_area_t *channel
snd_pcm_areas_copy(channels, offset, str->channels, mmap_offset, str->setup.format.channels, frames1, str->setup.format.format); snd_pcm_areas_copy(channels, offset, str->channels, mmap_offset, str->setup.format.channels, frames1, str->setup.format.format);
if (ctrl->status == SND_PCM_STATUS_XRUN) if (ctrl->status == SND_PCM_STATUS_XRUN)
return result > 0 ? result : -EPIPE; return result > 0 ? result : -EPIPE;
snd_pcm_mmap_commit_frames(pcm, SND_PCM_STREAM_PLAYBACK, frames1); snd_pcm_stream_seek(pcm, SND_PCM_STREAM_PLAYBACK, frames1 * str->bits_per_frame / 8);
frames -= frames1; frames -= frames1;
offset += frames1; offset += frames1;
result += frames1; result += frames1;
@ -322,8 +325,6 @@ ssize_t snd_pcm_mmap_write_frames(snd_pcm_t *pcm, const void *buffer, size_t fra
if (!pcm) if (!pcm)
return -EFAULT; return -EFAULT;
str = &pcm->stream[SND_PCM_STREAM_PLAYBACK]; str = &pcm->stream[SND_PCM_STREAM_PLAYBACK];
if (!str->open || !str->valid_setup)
return -EBADFD;
if (!str->mmap_data || !str->mmap_control) if (!str->mmap_data || !str->mmap_control)
return -EBADFD; return -EBADFD;
if (frames > 0 && !buffer) if (frames > 0 && !buffer)
@ -351,8 +352,6 @@ ssize_t snd_pcm_mmap_write(snd_pcm_t *pcm, const void *buffer, size_t bytes)
if (!pcm) if (!pcm)
return -EFAULT; return -EFAULT;
str = &pcm->stream[SND_PCM_STREAM_PLAYBACK]; str = &pcm->stream[SND_PCM_STREAM_PLAYBACK];
if (!str->open || !str->valid_setup)
return -EBADFD;
if (!str->mmap_data || !str->mmap_control) if (!str->mmap_data || !str->mmap_control)
return -EBADFD; return -EBADFD;
if (bytes > 0 && !buffer) if (bytes > 0 && !buffer)
@ -375,8 +374,6 @@ ssize_t snd_pcm_mmap_writev(snd_pcm_t *pcm, const struct iovec *vector, unsigned
if (!pcm) if (!pcm)
return -EFAULT; return -EFAULT;
str = &pcm->stream[SND_PCM_STREAM_PLAYBACK]; str = &pcm->stream[SND_PCM_STREAM_PLAYBACK];
if (!str->open || !str->valid_setup)
return -EBADFD;
if (!str->mmap_data || !str->mmap_control) if (!str->mmap_data || !str->mmap_control)
return -EBADFD; return -EBADFD;
if (vcount > 0 && !vector) if (vcount > 0 && !vector)
@ -485,7 +482,7 @@ ssize_t snd_pcm_mmap_read_areas(snd_pcm_t *pcm, snd_pcm_channel_area_t *channels
if (ctrl->status == SND_PCM_STATUS_XRUN && if (ctrl->status == SND_PCM_STATUS_XRUN &&
str->setup.xrun_mode == SND_PCM_XRUN_DRAIN) str->setup.xrun_mode == SND_PCM_XRUN_DRAIN)
return result > 0 ? result : -EPIPE; return result > 0 ? result : -EPIPE;
snd_pcm_mmap_commit_frames(pcm, SND_PCM_STREAM_CAPTURE, frames1); snd_pcm_stream_seek(pcm, SND_PCM_STREAM_CAPTURE, frames1 * str->bits_per_frame / 8);
frames -= frames1; frames -= frames1;
offset += frames1; offset += frames1;
result += frames1; result += frames1;
@ -500,8 +497,6 @@ ssize_t snd_pcm_mmap_read_frames(snd_pcm_t *pcm, const void *buffer, size_t fram
if (!pcm) if (!pcm)
return -EFAULT; return -EFAULT;
str = &pcm->stream[SND_PCM_STREAM_CAPTURE]; str = &pcm->stream[SND_PCM_STREAM_CAPTURE];
if (!str->open || !str->valid_setup)
return -EBADFD;
if (!str->mmap_data || !str->mmap_control) if (!str->mmap_data || !str->mmap_control)
return -EBADFD; return -EBADFD;
if (frames > 0 && !buffer) if (frames > 0 && !buffer)
@ -529,8 +524,6 @@ ssize_t snd_pcm_mmap_read(snd_pcm_t *pcm, void *buffer, size_t bytes)
if (!pcm) if (!pcm)
return -EFAULT; return -EFAULT;
str = &pcm->stream[SND_PCM_STREAM_CAPTURE]; str = &pcm->stream[SND_PCM_STREAM_CAPTURE];
if (!str->open || !str->valid_setup)
return -EBADFD;
if (!str->mmap_data || !str->mmap_control) if (!str->mmap_data || !str->mmap_control)
return -EBADFD; return -EBADFD;
if (bytes > 0 && !buffer) if (bytes > 0 && !buffer)
@ -553,8 +546,6 @@ ssize_t snd_pcm_mmap_readv(snd_pcm_t *pcm, const struct iovec *vector, unsigned
if (!pcm) if (!pcm)
return -EFAULT; return -EFAULT;
str = &pcm->stream[SND_PCM_STREAM_CAPTURE]; str = &pcm->stream[SND_PCM_STREAM_CAPTURE];
if (!str->open || !str->valid_setup)
return -EBADFD;
if (!str->mmap_data || !str->mmap_control) if (!str->mmap_data || !str->mmap_control)
return -EBADFD; return -EBADFD;
if (vcount > 0 && !vector) if (vcount > 0 && !vector)
@ -609,36 +600,9 @@ ssize_t snd_pcm_mmap_readv(snd_pcm_t *pcm, const struct iovec *vector, unsigned
return result * str->bits_per_frame / 8; return result * str->bits_per_frame / 8;
} }
static ssize_t mmap_playback_bytes_xfer(snd_pcm_stream_t *str)
{
snd_pcm_mmap_control_t *ctrl = str->mmap_control;
size_t bytes_cont;
size_t byte_io = ctrl->byte_io;
ssize_t bytes = snd_pcm_mmap_playback_bytes_used(str);
bytes_cont = str->setup.buffer_size - (byte_io % str->setup.buffer_size);
if ((ssize_t)bytes_cont < bytes)
bytes = bytes_cont;
bytes -= bytes % str->setup.bytes_align;
return bytes;
}
static ssize_t mmap_capture_bytes_xfer(snd_pcm_stream_t *str)
{
snd_pcm_mmap_control_t *ctrl = str->mmap_control;
size_t bytes_cont;
size_t byte_io = ctrl->byte_io;
ssize_t bytes = snd_pcm_mmap_capture_bytes_free(str);
bytes_cont = str->setup.buffer_size - (byte_io % str->setup.buffer_size);
if ((ssize_t)bytes_cont < bytes)
bytes = bytes_cont;
bytes -= bytes % str->setup.bytes_align;
return bytes;
}
int snd_pcm_mmap_control(snd_pcm_t *pcm, int stream, snd_pcm_mmap_control_t **control) int snd_pcm_mmap_control(snd_pcm_t *pcm, int stream, snd_pcm_mmap_control_t **control)
{ {
snd_pcm_stream_t *str; snd_pcm_stream_t *str;
snd_pcm_stream_info_t info;
size_t csize; size_t csize;
int err; int err;
if (!pcm || !control) if (!pcm || !control)
@ -646,14 +610,12 @@ int snd_pcm_mmap_control(snd_pcm_t *pcm, int stream, snd_pcm_mmap_control_t **co
if (stream < 0 || stream > 1) if (stream < 0 || stream > 1)
return -EINVAL; return -EINVAL;
str = &pcm->stream[stream]; str = &pcm->stream[stream];
if (!str->open) if (!str->valid_setup)
return -EBADFD; return -EBADFD;
if (str->mmap_control) { if (str->mmap_control) {
*control = str->mmap_control; *control = str->mmap_control;
return 0; return 0;
} }
if (!str->valid_setup)
return -EBADFD;
csize = sizeof(snd_pcm_mmap_control_t); csize = sizeof(snd_pcm_mmap_control_t);
if ((err = pcm->ops->mmap_control(pcm, stream, control, csize)) < 0) if ((err = pcm->ops->mmap_control(pcm, stream, control, csize)) < 0)
@ -669,13 +631,14 @@ int snd_pcm_mmap_get_areas(snd_pcm_t *pcm, int stream, snd_pcm_channel_area_t *a
snd_pcm_channel_setup_t s; snd_pcm_channel_setup_t s;
snd_pcm_channel_area_t *a, *ap; snd_pcm_channel_area_t *a, *ap;
unsigned int channel; unsigned int channel;
int interleaved = 1, noninterleaved = 1;
int err; int err;
if (!pcm) if (!pcm)
return -EFAULT; return -EFAULT;
if (stream < 0 || stream > 1) if (stream < 0 || stream > 1)
return -EINVAL; return -EINVAL;
str = &pcm->stream[stream]; str = &pcm->stream[stream];
if (!str->open || !str->valid_setup || !str->mmap_data) if (!str->mmap_data)
return -EBADFD; return -EBADFD;
a = calloc(str->setup.format.channels, sizeof(*areas)); a = calloc(str->setup.format.channels, sizeof(*areas));
for (channel = 0, ap = a; channel < str->setup.format.channels; ++channel, ++ap) { for (channel = 0, ap = a; channel < str->setup.format.channels; ++channel, ++ap) {
@ -688,7 +651,19 @@ int snd_pcm_mmap_get_areas(snd_pcm_t *pcm, int stream, snd_pcm_channel_area_t *a
if (areas) if (areas)
areas[channel] = s.area; areas[channel] = s.area;
*ap = s.area; *ap = s.area;
if (ap->step != str->sample_width || ap->first != 0)
noninterleaved = 0;
if (ap->addr != a[0].addr ||
ap->step != str->bits_per_frame ||
ap->first != channel * str->sample_width)
interleaved = 0;
} }
if (noninterleaved)
str->mmap_type = _NONINTERLEAVED;
else if (interleaved)
str->mmap_type = _INTERLEAVED;
else
str->mmap_type = _COMPLEX;
str->channels = a; str->channels = a;
return 0; return 0;
} }
@ -704,14 +679,12 @@ int snd_pcm_mmap_data(snd_pcm_t *pcm, int stream, void **data)
if (stream < 0 || stream > 1) if (stream < 0 || stream > 1)
return -EINVAL; return -EINVAL;
str = &pcm->stream[stream]; str = &pcm->stream[stream];
if (!str->open) if (!str->valid_setup)
return -EBADFD; return -EBADFD;
if (str->mmap_data) { if (str->mmap_data) {
*data = str->mmap_data; *data = str->mmap_data;
return 0; return 0;
} }
if (!str->valid_setup)
return -EBADFD;
info.stream = stream; info.stream = stream;
err = snd_pcm_stream_info(pcm, &info); err = snd_pcm_stream_info(pcm, &info);
@ -753,10 +726,8 @@ int snd_pcm_munmap_control(snd_pcm_t *pcm, int stream)
if (stream < 0 || stream > 1) if (stream < 0 || stream > 1)
return -EINVAL; return -EINVAL;
str = &pcm->stream[stream]; str = &pcm->stream[stream];
if (!str->open)
return -EBADFD;
if (!str->mmap_control) if (!str->mmap_control)
return -EINVAL; return -EBADFD;
if ((err = pcm->ops->munmap_control(pcm, stream, str->mmap_control, str->mmap_control_size)) < 0) if ((err = pcm->ops->munmap_control(pcm, stream, str->mmap_control, str->mmap_control_size)) < 0)
return err; return err;
str->mmap_control = 0; str->mmap_control = 0;
@ -773,10 +744,8 @@ int snd_pcm_munmap_data(snd_pcm_t *pcm, int stream)
if (stream < 0 || stream > 1) if (stream < 0 || stream > 1)
return -EINVAL; return -EINVAL;
str = &pcm->stream[stream]; str = &pcm->stream[stream];
if (!str->open)
return -EBADFD;
if (!str->mmap_data) if (!str->mmap_data)
return -EINVAL; return -EBADFD;
if ((err = pcm->ops->munmap_data(pcm, stream, str->mmap_data, str->mmap_data_size)) < 0) if ((err = pcm->ops->munmap_data(pcm, stream, str->mmap_data, str->mmap_data_size)) < 0)
return err; return err;
free(str->channels); free(str->channels);

View file

@ -310,7 +310,7 @@ static int snd_pcm_plug_stream_nonblock(snd_pcm_t *pcm, int stream, int nonblock
return snd_pcm_stream_nonblock(plug->slave, stream, nonblock); return snd_pcm_stream_nonblock(plug->slave, stream, nonblock);
} }
static int snd_pcm_plug_info(snd_pcm_t *pcm, int stream, snd_pcm_info_t * info) static int snd_pcm_plug_info(snd_pcm_t *pcm, int stream UNUSED, snd_pcm_info_t * info)
{ {
snd_pcm_plug_t *plug = (snd_pcm_plug_t*) &pcm->private; snd_pcm_plug_t *plug = (snd_pcm_plug_t*) &pcm->private;
return snd_pcm_info(plug->slave, info); return snd_pcm_info(plug->slave, info);
@ -534,7 +534,7 @@ static int snd_pcm_plug_stream_go(snd_pcm_t *pcm, int stream)
return snd_pcm_stream_go(plug->slave, stream); return snd_pcm_stream_go(plug->slave, stream);
} }
static int snd_pcm_plug_sync_go(snd_pcm_t *pcm, int stream, snd_pcm_sync_t *sync) static int snd_pcm_plug_sync_go(snd_pcm_t *pcm, int stream UNUSED, snd_pcm_sync_t *sync)
{ {
snd_pcm_plug_t *plug = (snd_pcm_plug_t*) &pcm->private; snd_pcm_plug_t *plug = (snd_pcm_plug_t*) &pcm->private;
return snd_pcm_sync_go(plug->slave, sync); return snd_pcm_sync_go(plug->slave, sync);

View file

@ -187,7 +187,7 @@ static ssize_t mmap_playback_transfer(snd_pcm_plugin_t *plugin,
mmap_t *data; mmap_t *data;
snd_pcm_stream_setup_t *setup; snd_pcm_stream_setup_t *setup;
snd_pcm_mmap_control_t *ctrl; snd_pcm_mmap_control_t *ctrl;
snd_pcm_stream_t *stream; snd_pcm_stream_t *str;
int err; int err;
if (plugin == NULL) if (plugin == NULL)
@ -200,8 +200,8 @@ static ssize_t mmap_playback_transfer(snd_pcm_plugin_t *plugin,
ctrl = data->control; ctrl = data->control;
if (ctrl == NULL) if (ctrl == NULL)
return -EINVAL; return -EINVAL;
stream = &data->slave->stream[SND_PCM_STREAM_PLAYBACK]; str = &data->slave->stream[SND_PCM_STREAM_PLAYBACK];
setup = &stream->setup; setup = &str->setup;
#if 0 #if 0
for (channel = 0; channel < plugin->src_format.channels; channel++) { for (channel = 0; channel < plugin->src_format.channels; channel++) {
@ -210,10 +210,10 @@ static ssize_t mmap_playback_transfer(snd_pcm_plugin_t *plugin,
} }
#endif #endif
snd_pcm_mmap_commit_frames(data->slave, SND_PCM_STREAM_PLAYBACK, frames); snd_pcm_stream_seek(data->slave, SND_PCM_STREAM_PLAYBACK, frames * str->bits_per_frame / 8);
if (ctrl->status == SND_PCM_STATUS_PREPARED && if (ctrl->status == SND_PCM_STATUS_PREPARED &&
(stream->setup.start_mode == SND_PCM_START_DATA || (str->setup.start_mode == SND_PCM_START_DATA ||
(stream->setup.start_mode == SND_PCM_START_FULL && (str->setup.start_mode == SND_PCM_START_FULL &&
!snd_pcm_mmap_ready(data->slave, plugin->stream)))) { !snd_pcm_mmap_ready(data->slave, plugin->stream)))) {
err = snd_pcm_stream_go(data->slave, plugin->stream); err = snd_pcm_stream_go(data->slave, plugin->stream);
if (err < 0) if (err < 0)
@ -228,8 +228,8 @@ static ssize_t mmap_capture_transfer(snd_pcm_plugin_t *plugin,
size_t frames) size_t frames)
{ {
mmap_t *data; mmap_t *data;
snd_pcm_stream_setup_t *setup;
snd_pcm_mmap_control_t *ctrl; snd_pcm_mmap_control_t *ctrl;
snd_pcm_stream_t *str;
if (plugin == NULL) if (plugin == NULL)
return -EINVAL; return -EINVAL;
@ -240,10 +240,11 @@ static ssize_t mmap_capture_transfer(snd_pcm_plugin_t *plugin,
ctrl = data->control; ctrl = data->control;
if (ctrl == NULL) if (ctrl == NULL)
return -EINVAL; return -EINVAL;
setup = &data->slave->stream[SND_PCM_STREAM_CAPTURE].setup; str = &data->slave->stream[SND_PCM_STREAM_CAPTURE];
/* FIXME: not here the increment */ /* FIXME: not here the increment */
snd_pcm_mmap_commit_frames(data->slave, SND_PCM_STREAM_CAPTURE, frames); snd_pcm_stream_seek(data->slave, SND_PCM_STREAM_CAPTURE, frames * str->bits_per_frame / 8);
return frames; return frames;
} }