mirror of
https://github.com/alsa-project/alsa-lib.git
synced 2025-10-29 05:40:25 -04:00
Added mmap_control access function. Converted static checks in asserts. Uniformed avail functions to kernel code
This commit is contained in:
parent
f11e203d6e
commit
ef2a9bdd88
6 changed files with 239 additions and 359 deletions
|
|
@ -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_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);
|
||||
|
|
@ -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_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);
|
||||
|
|
@ -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,
|
||||
size_t vcount, size_t frames, int format);
|
||||
|
||||
|
||||
/* misc */
|
||||
|
||||
int snd_pcm_format_signed(int format);
|
||||
|
|
|
|||
290
src/pcm/pcm.c
290
src/pcm/pcm.c
|
|
@ -25,6 +25,7 @@
|
|||
#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,
|
||||
|
|
@ -32,8 +33,7 @@ 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);
|
||||
|
|
@ -65,13 +65,10 @@ int snd_pcm_stream_close(snd_pcm_t *pcm, int stream)
|
|||
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;
|
||||
|
|
@ -92,8 +89,7 @@ int snd_pcm_close(snd_pcm_t *pcm)
|
|||
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)
|
||||
|
|
@ -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 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);
|
||||
|
|
@ -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)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
@ -150,15 +141,11 @@ int snd_pcm_stream_params(snd_pcm_t *pcm, snd_pcm_stream_params_t *params)
|
|||
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;
|
||||
|
|
@ -170,13 +157,10 @@ int snd_pcm_stream_setup(snd_pcm_t *pcm, snd_pcm_stream_setup_t *setup)
|
|||
{
|
||||
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;
|
||||
|
|
@ -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)
|
||||
{
|
||||
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);
|
||||
|
|
@ -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)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
@ -282,13 +260,10 @@ int snd_pcm_capture_prepare(snd_pcm_t *pcm)
|
|||
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);
|
||||
}
|
||||
|
||||
|
|
@ -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 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);
|
||||
|
|
@ -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)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
@ -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 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);
|
||||
}
|
||||
|
||||
|
|
@ -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 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);
|
||||
}
|
||||
|
||||
|
|
@ -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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
@ -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_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));
|
||||
|
|
|
|||
|
|
@ -79,6 +79,7 @@ typedef struct {
|
|||
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 {
|
||||
|
|
@ -131,21 +132,19 @@ int conv_index(int src_format, int dst_format);
|
|||
#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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -26,21 +26,21 @@
|
|||
#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)
|
||||
|
|
@ -48,53 +48,12 @@ int snd_pcm_mmap_frames_used(snd_pcm_t *pcm, int stream, ssize_t *frames)
|
|||
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_used(pcm);
|
||||
*frames = snd_pcm_mmap_playback_frames_avail(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)
|
||||
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);
|
||||
*frames = snd_pcm_mmap_capture_frames_avail(pcm);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -104,7 +63,7 @@ static int snd_pcm_mmap_playback_ready(snd_pcm_t *pcm)
|
|||
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)
|
||||
|
|
@ -117,7 +76,7 @@ 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;
|
||||
}
|
||||
|
|
@ -131,7 +90,7 @@ int snd_pcm_mmap_ready(snd_pcm_t *pcm, int stream)
|
|||
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)
|
||||
|
|
@ -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_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;
|
||||
}
|
||||
|
||||
|
|
@ -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_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;
|
||||
}
|
||||
|
||||
|
|
@ -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)
|
||||
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);
|
||||
|
|
@ -216,7 +171,7 @@ ssize_t snd_pcm_mmap_frames_offset(snd_pcm_t *pcm, int stream)
|
|||
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)
|
||||
|
|
@ -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;
|
||||
}
|
||||
|
||||
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)
|
||||
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;
|
||||
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)
|
||||
|
|
@ -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);
|
||||
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;
|
||||
|
|
@ -322,8 +325,6 @@ ssize_t snd_pcm_mmap_write_frames(snd_pcm_t *pcm, const void *buffer, size_t fra
|
|||
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)
|
||||
|
|
@ -351,8 +352,6 @@ ssize_t snd_pcm_mmap_write(snd_pcm_t *pcm, const void *buffer, size_t bytes)
|
|||
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)
|
||||
|
|
@ -375,8 +374,6 @@ ssize_t snd_pcm_mmap_writev(snd_pcm_t *pcm, const struct iovec *vector, unsigned
|
|||
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)
|
||||
|
|
@ -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 &&
|
||||
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;
|
||||
|
|
@ -500,8 +497,6 @@ ssize_t snd_pcm_mmap_read_frames(snd_pcm_t *pcm, const void *buffer, size_t fram
|
|||
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)
|
||||
|
|
@ -529,8 +524,6 @@ ssize_t snd_pcm_mmap_read(snd_pcm_t *pcm, void *buffer, size_t bytes)
|
|||
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)
|
||||
|
|
@ -553,8 +546,6 @@ ssize_t snd_pcm_mmap_readv(snd_pcm_t *pcm, const struct iovec *vector, unsigned
|
|||
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)
|
||||
|
|
@ -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;
|
||||
}
|
||||
|
||||
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)
|
||||
|
|
@ -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)
|
||||
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)
|
||||
|
|
@ -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_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) {
|
||||
|
|
@ -688,7 +651,19 @@ int snd_pcm_mmap_get_areas(snd_pcm_t *pcm, int stream, snd_pcm_channel_area_t *a
|
|||
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;
|
||||
}
|
||||
|
|
@ -704,14 +679,12 @@ int snd_pcm_mmap_data(snd_pcm_t *pcm, int stream, void **data)
|
|||
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);
|
||||
|
|
@ -753,10 +726,8 @@ int snd_pcm_munmap_control(snd_pcm_t *pcm, int stream)
|
|||
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;
|
||||
|
|
@ -773,10 +744,8 @@ int snd_pcm_munmap_data(snd_pcm_t *pcm, int stream)
|
|||
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);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
||||
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);
|
||||
|
|
@ -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);
|
||||
}
|
||||
|
||||
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);
|
||||
|
|
|
|||
|
|
@ -187,7 +187,7 @@ static ssize_t mmap_playback_transfer(snd_pcm_plugin_t *plugin,
|
|||
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)
|
||||
|
|
@ -200,8 +200,8 @@ static ssize_t mmap_playback_transfer(snd_pcm_plugin_t *plugin,
|
|||
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++) {
|
||||
|
|
@ -210,10 +210,10 @@ static ssize_t mmap_playback_transfer(snd_pcm_plugin_t *plugin,
|
|||
}
|
||||
#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)
|
||||
|
|
@ -228,8 +228,8 @@ static ssize_t mmap_capture_transfer(snd_pcm_plugin_t *plugin,
|
|||
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;
|
||||
|
|
@ -240,10 +240,11 @@ static ssize_t mmap_capture_transfer(snd_pcm_plugin_t *plugin,
|
|||
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;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue