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_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_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_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_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_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_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_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_free(snd_pcm_t *pcm, int stream, ssize_t *frames);
+int snd_pcm_mmap_frames_avail(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_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_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);
const snd_pcm_channel_area_t *dst_channels, size_t dst_offset,
size_t vcount, size_t frames, int format);
+
/* misc */
int snd_pcm_format_signed(int format);
#include <errno.h>
#include <sys/poll.h>
#include <sys/uio.h>
+#include <assert.h>
#include "pcm_local.h"
int snd_pcm_abstract_open(snd_pcm_t **handle, int mode,
{
snd_pcm_t *pcm;
- if (!handle)
- return -EFAULT;
+ assert(handle);
*handle = NULL;
pcm = (snd_pcm_t *) calloc(1, sizeof(snd_pcm_t) + extra);
int ret = 0;
int err;
snd_pcm_stream_t *str;
- if (!pcm)
- return -EFAULT;
- if (stream < 0 || stream > 1)
- return -EINVAL;
+ assert(pcm);
+ assert(stream >= 0 && stream <= 1);
str = &pcm->stream[stream];
- if (!str->open)
- return -EBADFD;
+ assert(str->open);
if (str->mmap_control) {
if ((err = snd_pcm_munmap_control(pcm, stream)) < 0)
ret = err;
int err, ret = 0;
int stream;
- if (!pcm)
- return -EFAULT;
+ assert(pcm);
for (stream = 0; stream < 2; ++stream) {
if (pcm->stream[stream].open) {
if ((err = snd_pcm_stream_close(pcm, stream)) < 0)
int snd_pcm_stream_nonblock(snd_pcm_t *pcm, int stream, int nonblock)
{
int err;
- if (!pcm)
- return -EFAULT;
- if (stream < 0 || stream > 1)
- return -EINVAL;
- if (!pcm->stream[stream].open)
- return -EBADFD;
+ snd_pcm_stream_t *str;
+ assert(pcm);
+ assert(stream >= 0 && stream <= 1);
+ str = &pcm->stream[stream];
+ assert(pcm->stream[stream].open);
if ((err = pcm->ops->stream_nonblock(pcm, stream, nonblock)) < 0)
return err;
if (nonblock)
- pcm->stream[stream].mode |= SND_PCM_NONBLOCK;
+ str->mode |= SND_PCM_NONBLOCK;
else
- pcm->stream[stream].mode &= ~SND_PCM_NONBLOCK;
+ str->mode &= ~SND_PCM_NONBLOCK;
return 0;
}
int snd_pcm_info(snd_pcm_t *pcm, snd_pcm_info_t *info)
{
int stream;
- if (!pcm || !info)
- return -EFAULT;
+ assert(pcm && info);
for (stream = 0; stream < 2; ++stream) {
if (pcm->stream[stream].open)
return pcm->ops->info(pcm, stream, info);
int snd_pcm_stream_info(snd_pcm_t *pcm, snd_pcm_stream_info_t *info)
{
- if (!pcm || !info)
- return -EFAULT;
- if (info->stream < 0 || info->stream > 1)
- return -EINVAL;
- if (!pcm->stream[info->stream].open)
- return -EBADFD;
+ assert(pcm && info);
+ assert(info->stream >= 0 && info->stream <= 1);
+ assert(pcm->stream[info->stream].open);
return pcm->ops->stream_info(pcm, info);
}
int err;
snd_pcm_stream_setup_t setup;
snd_pcm_stream_t *str;
- if (!pcm || !params)
- return -EFAULT;
- if (params->stream < 0 || params->stream > 1)
- return -EINVAL;
+ assert(pcm && params);
+ assert(params->stream >= 0 && params->stream <= 1);
str = &pcm->stream[params->stream];
- if (!str->open)
- return -EBADFD;
- if (str->mmap_control)
- return -EBADFD;
+ assert(str->open);
+ assert(!str->mmap_data);
if ((err = pcm->ops->stream_params(pcm, params)) < 0)
return err;
str->valid_setup = 0;
{
int err;
snd_pcm_stream_t *str;
- if (!pcm || !setup)
- return -EFAULT;
- if (setup->stream < 0 || setup->stream > 1)
- return -EINVAL;
+ assert(pcm && setup);
+ assert(setup->stream >= 0 && setup->stream <= 1);
str = &pcm->stream[setup->stream];
- if (!str->open)
- return -EBADFD;
+ assert(str->open);
if (str->valid_setup) {
memcpy(setup, &str->setup, sizeof(*setup));
return 0;
const snd_pcm_stream_setup_t* snd_pcm_stream_cached_setup(snd_pcm_t *pcm, int stream)
{
snd_pcm_stream_t *str;
- if (!pcm)
- return 0;
- if (stream < 0 || stream > 1)
- return 0;
+ assert(pcm);
+ assert(stream >= 0 && stream <= 1);
str = &pcm->stream[stream];
- if (!str->open || !str->valid_setup)
- return 0;
+ assert(str->valid_setup);
return &str->setup;
}
int snd_pcm_channel_setup(snd_pcm_t *pcm, int stream, snd_pcm_channel_setup_t *setup)
{
snd_pcm_stream_t *str;
- if (!pcm || !setup)
- return -EFAULT;
- if (stream < 0 || stream > 1)
- return -EINVAL;
+ assert(pcm && setup);
+ assert(stream >= 0 && stream <= 1);
str = &pcm->stream[stream];
- if (!str->open || !str->valid_setup)
- return -EBADFD;
+ assert(str->valid_setup);
return pcm->ops->channel_setup(pcm, stream, setup);
}
int snd_pcm_stream_status(snd_pcm_t *pcm, snd_pcm_stream_status_t *status)
{
- if (!pcm || !status)
- return -EFAULT;
- if (status->stream < 0 || status->stream > 1)
- return -EINVAL;
- if (!pcm->stream[status->stream].open)
- return -EBADFD;
+ assert(pcm && status);
+ assert(status->stream >= 0 && status->stream <= 1);
+ assert(pcm->stream[status->stream].open);
return pcm->ops->stream_status(pcm, status);
}
int snd_pcm_stream_state(snd_pcm_t *pcm, int stream)
{
snd_pcm_stream_t *str;
- if (!pcm)
- return -EFAULT;
- if (stream < 0 || stream > 1)
- return -EINVAL;
+ assert(pcm);
+ assert(stream >= 0 && stream <= 1);
str = &pcm->stream[stream];
- if (!str->open)
- return -EBADFD;
+ assert(str->open);
if (str->mmap_control)
return str->mmap_control->status;
return pcm->ops->stream_state(pcm, stream);
int snd_pcm_stream_byte_io(snd_pcm_t *pcm, int stream, int update)
{
snd_pcm_stream_t *str;
- if (!pcm)
- return -EFAULT;
- if (stream < 0 || stream > 1)
- return -EINVAL;
+ assert(pcm);
+ assert(stream >= 0 && stream <= 1);
str = &pcm->stream[stream];
- if (!str->open)
- return -EBADFD;
+ assert(str->valid_setup);
if (str->mmap_control && !update)
return str->mmap_control->byte_io;
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)
{
- if (!pcm)
- return -EFAULT;
- if (stream < 0 || stream > 1)
- return -EINVAL;
- if (!pcm->stream[stream].open)
- return -EBADFD;
+ assert(pcm);
+ assert(stream >= 0 && stream <= 1);
+ assert(pcm->stream[stream].open);
return pcm->ops->stream_prepare(pcm, stream);
}
int snd_pcm_stream_go(snd_pcm_t *pcm, int stream)
{
snd_pcm_stream_t *str;
- if (!pcm)
- return -EFAULT;
- if (stream < 0 || stream > 1)
- return -EINVAL;
+ assert(pcm);
+ assert(stream >= 0 && stream <= 1);
str = &pcm->stream[stream];
- if (!str->open)
- return -EBADFD;
+ assert(str->valid_setup);
return pcm->ops->stream_go(pcm, stream);
}
int snd_pcm_sync_go(snd_pcm_t *pcm, snd_pcm_sync_t *sync)
{
int stream;
- if (!pcm || !sync)
- return -EFAULT;
+ assert(pcm && sync);
for (stream = 0; stream < 2; ++stream) {
if (pcm->stream[stream].open)
return pcm->ops->sync_go(pcm, stream, sync);
int snd_pcm_stream_drain(snd_pcm_t *pcm, int stream)
{
- if (!pcm)
- return -EFAULT;
- if (stream < 0 || stream > 1)
- return -EINVAL;
- if (!pcm->stream[stream].open)
- return -EBADFD;
- if (stream != SND_PCM_STREAM_PLAYBACK)
- return -EBADFD;
+ assert(pcm);
+ assert(stream >= 0 && stream <= 1);
+ assert(pcm->stream[stream].open);
+ assert(stream == SND_PCM_STREAM_PLAYBACK);
return pcm->ops->stream_drain(pcm, stream);
}
int snd_pcm_stream_flush(snd_pcm_t *pcm, int stream)
{
- int err;
- if (!pcm)
- return -EFAULT;
- if (stream < 0 || stream > 1)
- return -EINVAL;
- if (!pcm->stream[stream].open)
- return -EBADFD;
+ assert(pcm);
+ assert(stream >= 0 && stream <= 1);
+ assert(pcm->stream[stream].open);
return pcm->ops->stream_flush(pcm, stream);
}
int snd_pcm_stream_pause(snd_pcm_t *pcm, int stream, int enable)
{
- int err;
- if (!pcm)
- return -EFAULT;
- if (stream < 0 || stream > 1)
- return -EINVAL;
- if (!pcm->stream[stream].open)
- return -EBADFD;
- if (stream != SND_PCM_STREAM_PLAYBACK)
- return -EBADFD;
+ assert(pcm);
+ assert(stream >= 0 && stream <= 1);
+ assert(pcm->stream[stream].open);
+ assert(stream == SND_PCM_STREAM_PLAYBACK);
return pcm->ops->stream_pause(pcm, stream, 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)
{
snd_pcm_stream_t *str;
- size_t bytes_per_frame;
- if (!pcm)
- return -EFAULT;
- if (stream < 0 || stream > 1)
- return -EINVAL;
+ assert(pcm);
+ assert(stream >= 0 && stream <= 1);
str = &pcm->stream[stream];
- if (!str->open)
- return -EBADFD;
- if (!str->valid_setup)
- return -EBADFD;
-#if 0
- /* TODO */
- if (str->mmap_control) {
- } else
-#endif
+ assert(str->valid_setup);
+ if (str->mmap_control)
+ return snd_pcm_mmap_stream_seek(pcm, stream, offset);
+ else
return pcm->ops->stream_seek(pcm, stream, offset);
}
ssize_t snd_pcm_write(snd_pcm_t *pcm, const void *buffer, size_t size)
{
- if (!pcm)
- return -EFAULT;
- if (!pcm->stream[SND_PCM_STREAM_PLAYBACK].open ||
- !pcm->stream[SND_PCM_STREAM_PLAYBACK].valid_setup)
- return -EBADFD;
- if (size > 0 && !buffer)
- return -EFAULT;
+ assert(pcm);
+ assert(pcm->stream[SND_PCM_STREAM_PLAYBACK].valid_setup);
+ assert(size == 0 || buffer);
return pcm->ops->write(pcm, buffer, size);
}
ssize_t snd_pcm_writev(snd_pcm_t *pcm, const struct iovec *vector, unsigned long count)
{
- if (!pcm)
- return -EFAULT;
- if (!pcm->stream[SND_PCM_STREAM_PLAYBACK].open ||
- !pcm->stream[SND_PCM_STREAM_PLAYBACK].valid_setup)
- return -EBADFD;
- if (count > 0 && !vector)
- return -EFAULT;
+ assert(pcm);
+ assert(pcm->stream[SND_PCM_STREAM_PLAYBACK].valid_setup);
+ assert(count == 0 || vector);
return pcm->ops->writev(pcm, vector, count);
}
ssize_t snd_pcm_read(snd_pcm_t *pcm, void *buffer, size_t size)
{
- if (!pcm)
- return -EFAULT;
- if (!pcm->stream[SND_PCM_STREAM_CAPTURE].open ||
- !pcm->stream[SND_PCM_STREAM_CAPTURE].valid_setup)
- return -EBADFD;
- if (size > 0 && !buffer)
- return -EFAULT;
+ assert(pcm);
+ assert(pcm->stream[SND_PCM_STREAM_CAPTURE].valid_setup);
+ assert(size == 0 || buffer);
return pcm->ops->read(pcm, buffer, size);
}
ssize_t snd_pcm_readv(snd_pcm_t *pcm, const struct iovec *vector, unsigned long count)
{
- if (!pcm)
- return -EFAULT;
- if (!pcm->stream[SND_PCM_STREAM_CAPTURE].open ||
- !pcm->stream[SND_PCM_STREAM_CAPTURE].valid_setup)
- return -EBADFD;
- if (count > 0 && !vector)
- return -EFAULT;
+ assert(pcm);
+ assert(pcm->stream[SND_PCM_STREAM_CAPTURE].valid_setup);
+ assert(count == 0 || vector);
return pcm->ops->readv(pcm, vector, count);
}
int snd_pcm_file_descriptor(snd_pcm_t* pcm, int stream)
{
- if (!pcm)
- return -EFAULT;
- if (stream < 0 || stream > 1)
- return -EINVAL;
- if (!pcm->stream[stream].open)
- return -EBADFD;
+ assert(pcm);
+ assert(stream >= 0 && stream <= 1);
+ assert(pcm->stream[stream].open);
return pcm->ops->file_descriptor(pcm, stream);
}
int snd_pcm_channels_mask(snd_pcm_t *pcm, int stream, bitset_t *client_vmask)
{
- if (!pcm)
- return -EFAULT;
- if (stream < 0 || stream > 1)
- return -EINVAL;
- if (!pcm->stream[stream].open)
- return -EBADFD;
+ assert(pcm);
+ assert(stream >= 0 && stream <= 1);
+ assert(pcm->stream[stream].valid_setup);
return pcm->ops->channels_mask(pcm, stream, client_vmask);
}
ssize_t snd_pcm_bytes_per_second(snd_pcm_t *pcm, int stream)
{
snd_pcm_stream_t *str;
- if (!pcm)
- return -EFAULT;
- if (stream < 0 || stream > 1)
- return -EINVAL;
+ assert(pcm);
+ assert(stream >= 0 && stream <= 1);
str = &pcm->stream[stream];
- if (!str->open || !str->valid_setup)
- return -EBADFD;
+ assert(str->valid_setup);
return snd_pcm_format_bytes_per_second(&str->setup.format);
}
{
snd_pcm_stream_t *str;
snd_pcm_stream_setup_t *setup;
- if (!pcm)
- return -EFAULT;
- if (stream < 0 || stream > 1)
- return -EINVAL;
+ assert(pcm);
+ assert(stream >= 0 && stream <= 1);
str = &pcm->stream[stream];
- if (!str->open || !str->valid_setup)
- return -EBADFD;
+ assert(str->valid_setup);
setup = &str->setup;
fprintf(fp, "stream: %s\n", assoc(setup->stream, streams));
fprintf(fp, "mode: %s\n", assoc(setup->mode, modes));
size_t mmap_control_size;
char *mmap_data;
size_t mmap_data_size;
+ enum { _INTERLEAVED, _NONINTERLEAVED, _COMPLEX } mmap_type;
} snd_pcm_stream_t;
struct snd_pcm {
#define pdprintf( args... ) { ; }
#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;
- bytes_used = str->mmap_control->byte_data - str->mmap_control->byte_io;
- if (bytes_used < (ssize_t)(str->setup.buffer_size - str->setup.byte_boundary))
- bytes_used += str->setup.byte_boundary;
- return bytes_used;
+ ssize_t bytes_avail = str->mmap_control->byte_io + str->setup.buffer_size - str->mmap_control->byte_data;
+ if (bytes_avail < 0)
+ bytes_avail += str->setup.byte_boundary;
+ return bytes_avail;
}
-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;
- bytes_used = str->mmap_control->byte_io - str->mmap_control->byte_data;
- if (bytes_used < 0)
- bytes_used += str->setup.byte_boundary;
- return bytes_used;
+ ssize_t bytes_avail = str->mmap_control->byte_io - str->mmap_control->byte_data;
+ if (bytes_avail < 0)
+ bytes_avail += str->setup.byte_boundary;
+ return bytes_avail;
}
#include <sys/uio.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];
- 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;
}
-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];
- 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;
}
-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;
if (!pcm)
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_used(pcm);
- else
- *frames = snd_pcm_mmap_capture_frames_used(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)
+ if (!str->mmap_control)
return -EBADFD;
if (stream == SND_PCM_STREAM_PLAYBACK)
- *frames = snd_pcm_mmap_playback_frames_free(pcm);
+ *frames = snd_pcm_mmap_playback_frames_avail(pcm);
else
- *frames = snd_pcm_mmap_capture_frames_free(pcm);
+ *frames = snd_pcm_mmap_capture_frames_avail(pcm);
return 0;
}
str = &pcm->stream[SND_PCM_STREAM_PLAYBACK];
if (str->mmap_control->status == SND_PCM_STATUS_XRUN)
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)
if (str->setup.xrun_mode == SND_PCM_XRUN_DRAIN)
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 ret;
}
if (stream < 0 || stream > 1)
return -EINVAL;
str = &pcm->stream[stream];
- if (!str->open || !str->mmap_control)
+ if (!str->mmap_control)
return -EBADFD;
ctrl = str->mmap_control;
if (ctrl->status < SND_PCM_STATUS_PREPARED)
snd_pcm_stream_t *str = &pcm->stream[SND_PCM_STREAM_PLAYBACK];
snd_pcm_mmap_control_t *ctrl = str->mmap_control;
size_t bytes_cont;
- size_t byte_data = ctrl->byte_data;
- size_t bytes_free = snd_pcm_mmap_playback_bytes_free(str);
- if (bytes_free < bytes)
- bytes = bytes_free;
- bytes_cont = str->setup.buffer_size - (byte_data % str->setup.buffer_size);
+ size_t bytes_avail = snd_pcm_mmap_playback_bytes_avail(str);
+ if (bytes_avail < bytes)
+ bytes = bytes_avail;
+ bytes_cont = str->setup.buffer_size - ctrl->byte_data % str->setup.buffer_size;
if (bytes_cont < bytes)
bytes = bytes_cont;
- bytes -= bytes % str->setup.bytes_align;
return bytes;
}
snd_pcm_stream_t *str = &pcm->stream[SND_PCM_STREAM_CAPTURE];
snd_pcm_mmap_control_t *ctrl = str->mmap_control;
size_t bytes_cont;
- size_t byte_data = ctrl->byte_data;
- size_t bytes_used = snd_pcm_mmap_capture_bytes_used(str);
- if (bytes_used < bytes)
- bytes = bytes_used;
- bytes_cont = str->setup.buffer_size - (byte_data % str->setup.buffer_size);
+ size_t bytes_avail = snd_pcm_mmap_capture_bytes_avail(str);
+ if (bytes_avail < bytes)
+ bytes = bytes_avail;
+ bytes_cont = str->setup.buffer_size - ctrl->byte_data % str->setup.buffer_size;
if (bytes_cont < bytes)
bytes = bytes_cont;
- bytes -= bytes % str->setup.bytes_align;
return bytes;
}
if (stream < 0 || stream > 1)
return -EINVAL;
str = &pcm->stream[stream];
- if (!str->open || !str->mmap_control)
+ if (!str->mmap_control)
return -EBADFD;
if (stream == SND_PCM_STREAM_PLAYBACK)
return snd_pcm_mmap_playback_frames_xfer(pcm, frames);
if (stream < 0 || stream > 1)
return -EINVAL;
str = &pcm->stream[stream];
- if (!str->open)
+ if (!str->mmap_control)
return -EBADFD;
ctrl = str->mmap_control;
if (!ctrl)
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_mmap_control_t *ctrl;
- size_t byte_data, bytes;
- if (!pcm)
- return -EFAULT;
- if (stream < 0 || stream > 1)
- return -EINVAL;
+ assert(pcm);
+ assert(stream >= 0 && stream <= 1);
str = &pcm->stream[stream];
- if (!str->open)
- return -EBADFD;
- ctrl = str->mmap_control;
- if (!ctrl)
+ 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;
- 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;
+ }
+ 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 {
- ctrl->byte_data = byte_data;
+ 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;
}
- return 0;
+ 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)
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)
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;
offset += frames1;
result += frames1;
if (!pcm)
return -EFAULT;
str = &pcm->stream[SND_PCM_STREAM_PLAYBACK];
- if (!str->open || !str->valid_setup)
- return -EBADFD;
if (!str->mmap_data || !str->mmap_control)
return -EBADFD;
if (frames > 0 && !buffer)
if (!pcm)
return -EFAULT;
str = &pcm->stream[SND_PCM_STREAM_PLAYBACK];
- if (!str->open || !str->valid_setup)
- return -EBADFD;
if (!str->mmap_data || !str->mmap_control)
return -EBADFD;
if (bytes > 0 && !buffer)
if (!pcm)
return -EFAULT;
str = &pcm->stream[SND_PCM_STREAM_PLAYBACK];
- if (!str->open || !str->valid_setup)
- return -EBADFD;
if (!str->mmap_data || !str->mmap_control)
return -EBADFD;
if (vcount > 0 && !vector)
if (ctrl->status == SND_PCM_STATUS_XRUN &&
str->setup.xrun_mode == SND_PCM_XRUN_DRAIN)
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;
offset += frames1;
result += frames1;
if (!pcm)
return -EFAULT;
str = &pcm->stream[SND_PCM_STREAM_CAPTURE];
- if (!str->open || !str->valid_setup)
- return -EBADFD;
if (!str->mmap_data || !str->mmap_control)
return -EBADFD;
if (frames > 0 && !buffer)
if (!pcm)
return -EFAULT;
str = &pcm->stream[SND_PCM_STREAM_CAPTURE];
- if (!str->open || !str->valid_setup)
- return -EBADFD;
if (!str->mmap_data || !str->mmap_control)
return -EBADFD;
if (bytes > 0 && !buffer)
if (!pcm)
return -EFAULT;
str = &pcm->stream[SND_PCM_STREAM_CAPTURE];
- if (!str->open || !str->valid_setup)
- return -EBADFD;
if (!str->mmap_data || !str->mmap_control)
return -EBADFD;
if (vcount > 0 && !vector)
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)
{
snd_pcm_stream_t *str;
- snd_pcm_stream_info_t info;
size_t csize;
int err;
if (!pcm || !control)
if (stream < 0 || stream > 1)
return -EINVAL;
str = &pcm->stream[stream];
- if (!str->open)
+ if (!str->valid_setup)
return -EBADFD;
if (str->mmap_control) {
*control = str->mmap_control;
return 0;
}
- if (!str->valid_setup)
- return -EBADFD;
csize = sizeof(snd_pcm_mmap_control_t);
if ((err = pcm->ops->mmap_control(pcm, stream, control, csize)) < 0)
snd_pcm_channel_setup_t s;
snd_pcm_channel_area_t *a, *ap;
unsigned int channel;
+ int interleaved = 1, noninterleaved = 1;
int err;
if (!pcm)
return -EFAULT;
if (stream < 0 || stream > 1)
return -EINVAL;
str = &pcm->stream[stream];
- if (!str->open || !str->valid_setup || !str->mmap_data)
+ if (!str->mmap_data)
return -EBADFD;
a = calloc(str->setup.format.channels, sizeof(*areas));
for (channel = 0, ap = a; channel < str->setup.format.channels; ++channel, ++ap) {
if (areas)
areas[channel] = 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;
return 0;
}
if (stream < 0 || stream > 1)
return -EINVAL;
str = &pcm->stream[stream];
- if (!str->open)
+ if (!str->valid_setup)
return -EBADFD;
if (str->mmap_data) {
*data = str->mmap_data;
return 0;
}
- if (!str->valid_setup)
- return -EBADFD;
info.stream = stream;
err = snd_pcm_stream_info(pcm, &info);
if (stream < 0 || stream > 1)
return -EINVAL;
str = &pcm->stream[stream];
- if (!str->open)
- return -EBADFD;
if (!str->mmap_control)
- return -EINVAL;
+ return -EBADFD;
if ((err = pcm->ops->munmap_control(pcm, stream, str->mmap_control, str->mmap_control_size)) < 0)
return err;
str->mmap_control = 0;
if (stream < 0 || stream > 1)
return -EINVAL;
str = &pcm->stream[stream];
- if (!str->open)
- return -EBADFD;
if (!str->mmap_data)
- return -EINVAL;
+ return -EBADFD;
if ((err = pcm->ops->munmap_data(pcm, stream, str->mmap_data, str->mmap_data_size)) < 0)
return err;
free(str->channels);
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;
return snd_pcm_info(plug->slave, info);
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;
return snd_pcm_sync_go(plug->slave, sync);
mmap_t *data;
snd_pcm_stream_setup_t *setup;
snd_pcm_mmap_control_t *ctrl;
- snd_pcm_stream_t *stream;
+ snd_pcm_stream_t *str;
int err;
if (plugin == NULL)
ctrl = data->control;
if (ctrl == NULL)
return -EINVAL;
- stream = &data->slave->stream[SND_PCM_STREAM_PLAYBACK];
- setup = &stream->setup;
+ str = &data->slave->stream[SND_PCM_STREAM_PLAYBACK];
+ setup = &str->setup;
#if 0
for (channel = 0; channel < plugin->src_format.channels; channel++) {
}
#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 &&
- (stream->setup.start_mode == SND_PCM_START_DATA ||
- (stream->setup.start_mode == SND_PCM_START_FULL &&
+ (str->setup.start_mode == SND_PCM_START_DATA ||
+ (str->setup.start_mode == SND_PCM_START_FULL &&
!snd_pcm_mmap_ready(data->slave, plugin->stream)))) {
err = snd_pcm_stream_go(data->slave, plugin->stream);
if (err < 0)
size_t frames)
{
mmap_t *data;
- snd_pcm_stream_setup_t *setup;
snd_pcm_mmap_control_t *ctrl;
+ snd_pcm_stream_t *str;
if (plugin == NULL)
return -EINVAL;
ctrl = data->control;
if (ctrl == NULL)
return -EINVAL;
- setup = &data->slave->stream[SND_PCM_STREAM_CAPTURE].setup;
+ str = &data->slave->stream[SND_PCM_STREAM_CAPTURE];
/* 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;
}