#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,
if (pcm->stream[stream].open)
return pcm->ops->info(pcm, stream, info);
}
- return -EBADFD;
+ assert(0);
}
int snd_pcm_stream_info(snd_pcm_t *pcm, snd_pcm_stream_info_t *info)
if (pcm->stream[stream].open)
return pcm->ops->sync_go(pcm, stream, sync);
}
- return -EBADFD;
+ assert(0);
}
int snd_pcm_stream_drain(snd_pcm_t *pcm, int stream)
if ((width = snd_pcm_format_physical_width(format->format)) < 0)
return width;
size = format->channels * frames * width;
- if ((size % 8) != 0)
- return -EINVAL;
+ assert(size % 8 == 0);
size /= 8;
ptr = (char *)snd_pcm_plug_buf_alloc(plugin->handle, plugin->stream, size);
if (ptr == NULL)
return -ENOMEM;
- if ((size % format->channels) != 0)
- return -EINVAL;
+ assert(size % format->channels == 0);
size /= format->channels;
for (channel = 0; channel < format->channels; channel++, v++) {
v->enabled = 1;
const char *name,
snd_pcm_format_t *src_format,
snd_pcm_format_t *dst_format,
- int extra,
+ size_t extra,
snd_pcm_plugin_t **ret)
{
snd_pcm_plugin_t *plugin;
- if (!handle)
- return -EFAULT;
- if (extra < 0)
- return -EINVAL;
- if (stream < 0 || stream > 1)
- return -EINVAL;
- if (!src_format || !dst_format)
- return -EFAULT;
+ assert(handle);
+ assert(stream >= 0 && stream <= 1);
+ assert(src_format && dst_format);
plugin = (snd_pcm_plugin_t *)calloc(1, sizeof(*plugin) + extra);
if (plugin == NULL)
return -ENOMEM;
plugin->handle = handle;
plugin->stream = stream;
memcpy(&plugin->src_format, src_format, sizeof(snd_pcm_format_t));
- if ((plugin->src_width = snd_pcm_format_physical_width(src_format->format)) < 0)
- return -EINVAL;
+ plugin->src_width = snd_pcm_format_physical_width(src_format->format);
+ assert(plugin->src_width > 0);
memcpy(&plugin->dst_format, dst_format, sizeof(snd_pcm_format_t));
- if ((plugin->dst_width = snd_pcm_format_physical_width(dst_format->format)) < 0)
- return -EINVAL;
+ plugin->dst_width = snd_pcm_format_physical_width(dst_format->format);
+ assert(plugin->dst_width > 0);
plugin->src_channels = calloc(src_format->channels, sizeof(snd_pcm_plugin_channel_t));
if (plugin->src_channels == NULL) {
free(plugin);
{
ssize_t result;
- if (plugin == NULL)
- return -EFAULT;
+ assert(plugin);
result = frames * plugin->src_format.channels * plugin->src_width;
- if (result % 8 != 0)
- return -EINVAL;
+ assert(result % 8 == 0);
return result / 8;
}
{
ssize_t result;
- if (plugin == NULL)
- return -EFAULT;
+ assert(plugin);
result = frames * plugin->dst_format.channels * plugin->dst_width;
- if (result % 8 != 0)
- return -EINVAL;
+ assert(result % 8 == 0);
return result / 8;
}
ssize_t result;
long tmp;
- if (plugin == NULL)
- return -EFAULT;
+ assert(plugin);
result = size * 8;
tmp = plugin->src_format.channels * plugin->src_width;
- if (result % tmp != 0)
- return -EINVAL;
+ assert(result % tmp == 0);
return result / tmp;
}
ssize_t result;
long tmp;
- if (plugin == NULL)
- return -EFAULT;
+ assert(plugin);
result = size * 8;
tmp = plugin->dst_format.channels * plugin->dst_width;
- if (result % tmp != 0)
- return -EINVAL;
+ assert(result % tmp == 0);
return result / tmp;
}
{
snd_pcm_plugin_t *plugin, *plugin_prev, *plugin_next;
- if (handle == NULL)
- return -EFAULT;
- if (stream != SND_PCM_STREAM_PLAYBACK &&
- stream != SND_PCM_STREAM_CAPTURE)
- return -EINVAL;
+ assert(handle);
if (drv_frames == 0)
return 0;
if (stream == SND_PCM_STREAM_PLAYBACK) {
drv_frames = plugin->dst_frames(plugin, drv_frames);
plugin = plugin_next;
}
- }
+ } else
+ assert(0);
return drv_frames;
}
snd_pcm_plugin_t *plugin, *plugin_prev, *plugin_next;
ssize_t frames;
- if (handle == NULL)
- return -EFAULT;
- if (stream != SND_PCM_STREAM_PLAYBACK &&
- stream != SND_PCM_STREAM_CAPTURE)
- return -EINVAL;
+ assert(handle);
if (clt_frames == 0)
return 0;
frames = clt_frames;
}
plugin = plugin_prev;
}
- }
+ } else
+ assert(0);
return frames;
}
snd_pcm_plugin_t *plugin;
ssize_t result = 0;
- if (handle == NULL)
- return -EFAULT;
- if (stream != SND_PCM_STREAM_PLAYBACK &&
- stream != SND_PCM_STREAM_CAPTURE)
- return -EINVAL;
+ assert(handle);
if (drv_size == 0)
return 0;
if (stream == SND_PCM_STREAM_PLAYBACK) {
return result;
plugin = snd_pcm_plug_last(handle, SND_PCM_STREAM_CAPTURE);
result = snd_pcm_plugin_dst_frames_to_size(plugin, result);
- }
+ } else
+ assert(0);
return result;
}
snd_pcm_plugin_t *plugin;
ssize_t result = 0;
- if (handle == NULL)
- return -EFAULT;
- if (stream != SND_PCM_STREAM_PLAYBACK &&
- stream != SND_PCM_STREAM_CAPTURE)
- return -EINVAL;
+ assert(handle);
if (clt_size == 0)
return 0;
if (stream == SND_PCM_STREAM_PLAYBACK) {
return result;
plugin = snd_pcm_plug_first(handle, SND_PCM_STREAM_CAPTURE);
result = snd_pcm_plugin_src_frames_to_size(plugin, result);
- }
+ } else
+ assert(0);
return result;
}
memcpy(srcparams, slave_params, sizeof(*slave_params));
break;
default:
+ assert(0);
return -EINVAL;
}
memcpy(&tmpparams, srcparams, sizeof(*srcparams));
snd_pcm_format_t *format;
int width, nchannels, channel;
- if (buf == NULL)
- return -EINVAL;
+ assert(buf);
if (stream == SND_PCM_STREAM_PLAYBACK) {
plugin = snd_pcm_plug_first(handle, stream);
format = &plugin->src_format;
*channels = v;
if ((width = snd_pcm_format_physical_width(format->format)) < 0)
return width;
- if ((count * 8) % width != 0)
- return -EINVAL;
+ assert(count * 8 % width == 0);
nchannels = format->channels;
- if (format->interleave ||
- format->channels == 1) {
- for (channel = 0; channel < nchannels; channel++, v++) {
- v->enabled = 1;
- v->wanted = (stream == SND_PCM_STREAM_CAPTURE);
- v->aptr = NULL;
- v->area.addr = buf;
- v->area.first = channel * width;
- v->area.step = nchannels * width;
- }
- return count;
- } else
- return -EINVAL;
+ assert(format->interleave || format->channels == 1);
+ for (channel = 0; channel < nchannels; channel++, v++) {
+ v->enabled = 1;
+ v->wanted = (stream == SND_PCM_STREAM_CAPTURE);
+ v->aptr = NULL;
+ v->area.addr = buf;
+ v->area.first = channel * width;
+ v->area.step = nchannels * width;
+ }
+ return count;
}
ssize_t snd_pcm_plug_client_channels_iovec(snd_pcm_plugin_handle_t *handle,
return width;
nchannels = format->channels;
if (format->interleave) {
- if (count != 1 || vector->iov_base == NULL ||
- (vector->iov_len * 8) % width != 0)
- return -EINVAL;
+ assert(count == 1 && vector->iov_base &&
+ vector->iov_len * 8 % width == 0);
for (channel = 0; channel < nchannels; channel++, v++) {
v->enabled = 1;
return vector->iov_len;
} else {
size_t len;
- if (count != nchannels)
- return -EINVAL;
+ assert(count == nchannels);
len = vector->iov_len;
- if ((len * 8) % width != 0)
- return -EINVAL;
+ assert(len * 8 % width == 0);
for (channel = 0; channel < nchannels; channel++, v++, vector++) {
- if (vector->iov_len != len)
- return -EINVAL;
+ assert(vector->iov_len == len);
v->enabled = (vector->iov_base != NULL);
v->wanted = (v->enabled && (stream == SND_PCM_STREAM_CAPTURE));
v->aptr = NULL;
break;
}
default:
- return -EINVAL;
+ assert(0);
}
return 0;
}
break;
}
default:
- return -EINVAL;
+ assert(0);
}
return 0;
}
return 0;
}
-int snd_pcm_hw_stream_fd(snd_pcm_t *pcm, int stream)
-{
- snd_pcm_hw_t *hw;
- if (!pcm)
- return -EINVAL;
- if (stream < 0 || stream > 1)
- return -EINVAL;
- hw = (snd_pcm_hw_t*) &pcm->private;
- return hw->stream[stream].fd;
-}
-
static int snd_pcm_hw_stream_nonblock(snd_pcm_t *pcm, int stream, int nonblock)
{
long flags;
filefmt = SND_FILE_PCM_CAPTURE;
break;
default:
- return -EINVAL;
+ assert(0);
}
if ((err = snd_ctl_pcm_stream_prefer_subdevice(ctl, device, stream, subdevice)) < 0)
return err;
snd_ctl_t *ctl;
int pfd = -1, cfd = -1;
- if (!handle)
- return -EFAULT;
+ assert(handle);
*handle = NULL;
- if (card < 0 || card >= SND_CARDS)
- return -EINVAL;
+ assert(card >= 0 && card < SND_CARDS);
if ((err = snd_ctl_open(&ctl, card)) < 0)
return err;
if (mode & SND_PCM_OPEN_PLAYBACK) {
}
}
snd_ctl_close(ctl);
- if (pfd < 0 && cfd < 0)
- return -EINVAL;
+ assert(pfd >= 0 || cfd >= 0);
err = snd_pcm_abstract_open(handle, mode, SND_PCM_TYPE_HW, sizeof(snd_pcm_hw_t));
if (err < 0) {
*
*/
-#include <pthread.h>
+#include <assert.h>
#include "asoundlib.h"
struct snd_pcm_ops {
#include <stdio.h>
#include <malloc.h>
#include <errno.h>
-#include <assert.h>
#include <sys/poll.h>
#include <sys/uio.h>
#include "pcm_local.h"
int snd_pcm_frames_avail(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;
+ assert(pcm);
+ assert(stream >= 0 && stream <= 1);
str = &pcm->stream[stream];
- if (!str->mmap_control)
- return -EBADFD;
+ assert(str->mmap_control);
if (stream == SND_PCM_STREAM_PLAYBACK)
*frames = snd_pcm_mmap_playback_frames_avail(pcm);
else
{
snd_pcm_stream_t *str;
snd_pcm_mmap_control_t *ctrl;
- if (!pcm)
- return -EFAULT;
- if (stream < 0 || stream > 1)
- return -EINVAL;
+ assert(pcm);
+ assert(stream >= 0 && stream <= 1);
str = &pcm->stream[stream];
- if (!str->mmap_control)
- return -EBADFD;
ctrl = str->mmap_control;
- if (ctrl->status < SND_PCM_STATUS_PREPARED)
- return -EBADFD;
+ assert(ctrl);
+ assert(ctrl->status >= SND_PCM_STATUS_PREPARED);
if (stream == SND_PCM_STREAM_PLAYBACK) {
return snd_pcm_mmap_playback_ready(pcm);
} else {
ssize_t snd_pcm_mmap_frames_xfer(snd_pcm_t *pcm, int stream, size_t frames)
{
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->mmap_control)
- return -EBADFD;
+ assert(str->mmap_control);
if (stream == SND_PCM_STREAM_PLAYBACK)
return snd_pcm_mmap_playback_frames_xfer(pcm, frames);
else
{
snd_pcm_stream_t *str;
snd_pcm_mmap_control_t *ctrl;
- if (!pcm)
- return -EFAULT;
- if (stream < 0 || stream > 1)
- return -EINVAL;
+ assert(pcm);
+ assert(stream >= 0 && stream <= 1);
str = &pcm->stream[stream];
- if (!str->mmap_control)
- return -EBADFD;
ctrl = str->mmap_control;
- if (!ctrl)
- return -EBADFD;
+ assert(ctrl);
return (ctrl->byte_data % str->setup.buffer_size) * 8 / str->bits_per_frame;
}
str = &pcm->stream[SND_PCM_STREAM_PLAYBACK];
ctrl = str->mmap_control;
- if (ctrl->status < SND_PCM_STATUS_PREPARED)
- return -EBADFD;
+ assert(ctrl->status >= SND_PCM_STATUS_PREPARED);
if (str->setup.mode == SND_PCM_MODE_FRAGMENT) {
- if (frames % str->frames_per_frag != 0)
- return -EINVAL;
+ assert(frames % str->frames_per_frag == 0);
} else {
if (ctrl->status == SND_PCM_STATUS_RUNNING &&
str->mode & SND_PCM_NONBLOCK)
{
snd_pcm_stream_t *str;
unsigned int nchannels;
- if (!pcm)
- return -EFAULT;
+ assert(pcm);
str = &pcm->stream[SND_PCM_STREAM_PLAYBACK];
- if (!str->mmap_data || !str->mmap_control)
- return -EBADFD;
- if (frames > 0 && !buffer)
- return -EFAULT;
+ assert(str->mmap_data && str->mmap_control);
+ assert(frames == 0 || buffer);
nchannels = str->setup.format.channels;
- if (!str->setup.format.interleave && nchannels > 1)
- return -EINVAL;
+ assert(str->setup.format.interleave || nchannels == 1);
{
snd_pcm_channel_area_t channels[nchannels];
unsigned int channel;
snd_pcm_stream_t *str;
unsigned int nchannels;
ssize_t frames;
- if (!pcm)
- return -EFAULT;
+ assert(pcm);
str = &pcm->stream[SND_PCM_STREAM_PLAYBACK];
- if (!str->mmap_data || !str->mmap_control)
- return -EBADFD;
- if (bytes > 0 && !buffer)
- return -EFAULT;
+ assert(str->mmap_data && str->mmap_control);
+ assert(bytes == 0 || buffer);
nchannels = str->setup.format.channels;
- if (!str->setup.format.interleave && nchannels > 1)
- return -EINVAL;
+ assert(str->setup.format.interleave || nchannels == 1);
frames = bytes * 8 / str->bits_per_frame;
frames = snd_pcm_mmap_write_frames(pcm, buffer, frames);
if (frames <= 0)
snd_pcm_stream_t *str;
size_t result = 0;
unsigned int nchannels;
- if (!pcm)
- return -EFAULT;
+ assert(pcm);
str = &pcm->stream[SND_PCM_STREAM_PLAYBACK];
- if (!str->mmap_data || !str->mmap_control)
- return -EBADFD;
- if (vcount > 0 && !vector)
- return -EFAULT;
+ assert(str->mmap_data && str->mmap_control);
+ assert(vcount == 0 || vector);
nchannels = str->setup.format.channels;
if (str->setup.format.interleave) {
unsigned int b;
snd_pcm_channel_area_t channels[nchannels];
unsigned long bcount;
unsigned int b;
- if (vcount % nchannels)
- return -EINVAL;
+ assert(vcount % nchannels == 0);
bcount = vcount / nchannels;
for (b = 0; b < bcount; b++) {
unsigned int v;
size_t frames;
bytes = vector[0].iov_len;
for (v = 0; v < nchannels; ++v) {
- if (vector[v].iov_len != bytes)
- return -EINVAL;
+ assert(vector[v].iov_len == bytes);
channels[v].addr = vector[v].iov_base;
channels[v].first = 0;
channels[v].step = str->sample_width;
str = &pcm->stream[SND_PCM_STREAM_CAPTURE];
ctrl = str->mmap_control;
- if (ctrl->status < SND_PCM_STATUS_PREPARED)
- return -EBADFD;
+ assert(ctrl->status >= SND_PCM_STATUS_PREPARED);
if (str->setup.mode == SND_PCM_MODE_FRAGMENT) {
- if (frames % str->frames_per_frag != 0)
- return -EINVAL;
+ assert(frames % str->frames_per_frag == 0);
} else {
if (ctrl->status == SND_PCM_STATUS_RUNNING &&
str->mode & SND_PCM_NONBLOCK)
{
snd_pcm_stream_t *str;
unsigned int nchannels;
- if (!pcm)
- return -EFAULT;
+ assert(pcm);
str = &pcm->stream[SND_PCM_STREAM_CAPTURE];
- if (!str->mmap_data || !str->mmap_control)
- return -EBADFD;
- if (frames > 0 && !buffer)
- return -EFAULT;
+ assert(str->mmap_data && str->mmap_control);
+ assert(frames == 0 || buffer);
nchannels = str->setup.format.channels;
- if (!str->setup.format.interleave && nchannels > 1)
- return -EINVAL;
+ assert(str->setup.format.interleave || nchannels == 1);
{
snd_pcm_channel_area_t channels[nchannels];
unsigned int channel;
snd_pcm_stream_t *str;
unsigned int nchannels;
ssize_t frames;
- if (!pcm)
- return -EFAULT;
+ assert(pcm);
str = &pcm->stream[SND_PCM_STREAM_CAPTURE];
- if (!str->mmap_data || !str->mmap_control)
- return -EBADFD;
- if (bytes > 0 && !buffer)
- return -EFAULT;
+ assert(str->mmap_data && str->mmap_control);
+ assert(bytes == 0 || buffer);
nchannels = str->setup.format.channels;
- if (!str->setup.format.interleave && nchannels > 1)
- return -EINVAL;
+ assert(str->setup.format.interleave || nchannels == 1);
frames = bytes * 8 / str->bits_per_frame;
frames = snd_pcm_mmap_read_frames(pcm, buffer, frames);
if (frames <= 0)
snd_pcm_stream_t *str;
size_t result = 0;
unsigned int nchannels;
- if (!pcm)
- return -EFAULT;
+ assert(pcm);
str = &pcm->stream[SND_PCM_STREAM_CAPTURE];
- if (!str->mmap_data || !str->mmap_control)
- return -EBADFD;
- if (vcount > 0 && !vector)
- return -EFAULT;
+ assert(str->mmap_data && str->mmap_control);
+ assert(vcount == 0 || vector);
nchannels = str->setup.format.channels;
if (str->setup.format.interleave) {
unsigned int b;
snd_pcm_channel_area_t channels[nchannels];
unsigned long bcount;
unsigned int b;
- if (vcount % nchannels)
- return -EINVAL;
+ assert(vcount % nchannels == 0);
bcount = vcount / nchannels;
for (b = 0; b < bcount; b++) {
unsigned int v;
size_t frames;
bytes = vector[0].iov_len;
for (v = 0; v < nchannels; ++v) {
- if (vector[v].iov_len != bytes)
- return -EINVAL;
+ assert(vector[v].iov_len == bytes);
channels[v].addr = vector[v].iov_base;
channels[v].first = 0;
channels[v].step = str->sample_width;
snd_pcm_stream_t *str;
size_t csize;
int err;
- if (!pcm || !control)
- return -EFAULT;
- if (stream < 0 || stream > 1)
- return -EINVAL;
+ assert(pcm);
+ assert(stream >= 0 && stream <= 1);
str = &pcm->stream[stream];
- if (!str->valid_setup)
- return -EBADFD;
+ assert(str->valid_setup);
if (str->mmap_control) {
- *control = str->mmap_control;
+ if (control)
+ *control = str->mmap_control;
return 0;
}
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, &str->mmap_control, csize)) < 0)
return err;
- str->mmap_control = *control;
+ if (control)
+ *control = str->mmap_control;
str->mmap_control_size = csize;
return 0;
}
unsigned int channel;
int interleaved = 1, noninterleaved = 1;
int err;
- if (!pcm)
- return -EFAULT;
- if (stream < 0 || stream > 1)
- return -EINVAL;
+ assert(pcm);
+ assert(stream >= 0 && stream <= 1);
str = &pcm->stream[stream];
- if (!str->mmap_data)
- return -EBADFD;
+ assert(str->mmap_data);
a = calloc(str->setup.format.channels, sizeof(*areas));
for (channel = 0, ap = a; channel < str->setup.format.channels; ++channel, ++ap) {
s.channel = channel;
snd_pcm_stream_info_t info;
size_t bsize;
int err;
- if (!pcm || !data)
- return -EFAULT;
- if (stream < 0 || stream > 1)
- return -EINVAL;
+ assert(pcm);
+ assert(stream >= 0 && stream <= 1);
str = &pcm->stream[stream];
- if (!str->valid_setup)
- return -EBADFD;
+ assert(str->valid_setup);
if (str->mmap_data) {
- *data = str->mmap_data;
+ if (data)
+ *data = str->mmap_data;
return 0;
}
bsize = info.mmap_size;
if (!(info.flags & SND_PCM_STREAM_INFO_MMAP))
return -ENXIO;
- if ((err = pcm->ops->mmap_data(pcm, stream, data, bsize)) < 0)
+ if ((err = pcm->ops->mmap_data(pcm, stream, (void**)&str->mmap_data, bsize)) < 0)
return err;
- str->mmap_data = *data;
+ if (data)
+ *data = str->mmap_data;
str->mmap_data_size = bsize;
err = snd_pcm_mmap_get_areas(pcm, stream, NULL);
if (err < 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->mmap_control)
- return -EBADFD;
+ assert(str->mmap_control);
if ((err = pcm->ops->munmap_control(pcm, stream, str->mmap_control, str->mmap_control_size)) < 0)
return err;
str->mmap_control = 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->mmap_data)
- return -EBADFD;
+ assert(str->mmap_data);
if ((err = pcm->ops->munmap_data(pcm, stream, str->mmap_data, str->mmap_data_size)) < 0)
return err;
free(str->channels);
snd_pcm_plug_t *plug;
snd_pcm_plug_stream_t *plugstr;
snd_pcm_t *pcm;
- if (!plugin)
- return -EFAULT;
+ assert(plugin);
pcm = plugin->handle;
plug = (snd_pcm_plug_t*) &pcm->private;
plugstr = &plug->stream[plugin->stream];
snd_pcm_plug_t *plug;
snd_pcm_plug_stream_t *plugstr;
snd_pcm_t *pcm;
- if (!plugin)
- return -EFAULT;
+ assert(plugin);
pcm = plugin->handle;
plug = (snd_pcm_plug_t*) &pcm->private;
plugstr = &plug->stream[plugin->stream];
snd_pcm_plug_t *plug;
snd_pcm_t *pcm;
snd_pcm_plug_stream_t *plugstr;
- if (!plugin)
- return -EFAULT;
+ assert(plugin);
pcm = plugin->handle;
plug = (snd_pcm_plug_t*) &pcm->private;
snd_pcm_plugin_t *plugin;
snd_pcm_plug_t *plug;
snd_pcm_plug_stream_t *plugstr;
- 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);
plug = (snd_pcm_plug_t*) &pcm->private;
plugstr = &plug->stream[stream];
snd_pcm_plug_stream_t *plugstr;
int idx;
- if (!pcm)
- return -EINVAL;
- 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);
plug = (snd_pcm_plug_t*) &pcm->private;
plugstr = &plug->stream[stream];
return snd_pcm_plug_first(pcm, stream) == NULL;
}
-#if 0
-double snd_pcm_plug_client_ratio(snd_pcm_t *pcm, int stream)
-{
- ssize_t client;
- if (!pcm)
- return -EFAULT;
- if (stream < 0 || stream > 1)
- return -EINVAL;
- if (!pcm->stream[stream].open)
- return -EBADFD;
-
- client = snd_pcm_plug_client_size(pcm, stream, 1000000);
- if (client < 0)
- return 0;
- return (double)client / (double)1000000;
-}
-
-double snd_pcm_plug_slave_ratio(snd_pcm_t *pcm, int stream)
-{
- ssize_t slave;
- if (!pcm)
- return -EFAULT;
- if (stream < 0 || stream > 1)
- return -EINVAL;
- if (!pcm->stream[stream].open)
- return -EBADFD;
-
- slave = snd_pcm_plug_slave_size(pcm, stream, 1000000);
- if (slave < 0)
- return 0;
- return (double)slave / (double)1000000;
-}
-#endif
-
/*
*
*/
snd_pcm_stream_info_t slave_info;
snd_pcm_plugin_t *plugin;
snd_pcm_plug_t *plug;
+ size_t bytes_per_frame;
int err;
int stream = params->stream;
return snd_pcm_stream_params(plug->slave, params);
/* compute right sizes */
- slave_params.frag_size = snd_pcm_plug_slave_size(pcm, stream, params->frag_size);
- slave_params.buffer_size = snd_pcm_plug_slave_size(pcm, stream, params->buffer_size);
- slave_params.bytes_fill_max = snd_pcm_plug_slave_size(pcm, stream, params->bytes_fill_max);
- slave_params.bytes_min = snd_pcm_plug_slave_size(pcm, stream, params->bytes_min);
- slave_params.bytes_xrun_max = snd_pcm_plug_slave_size(pcm, stream, params->bytes_xrun_max);
- slave_params.bytes_align = snd_pcm_plug_slave_size(pcm, stream, params->bytes_align);
+ bytes_per_frame = snd_pcm_format_size(params->format.format, params->format.channels);
+ if (bytes_per_frame == 0)
+ bytes_per_frame = 1;
+ params1.frag_size -= params1.frag_size % bytes_per_frame;
+ slave_params.frag_size = snd_pcm_plug_slave_size(pcm, stream, params1.frag_size);
+ params1.buffer_size -= params1.buffer_size % bytes_per_frame;
+ slave_params.buffer_size = snd_pcm_plug_slave_size(pcm, stream, params1.buffer_size);
+ params1.bytes_fill_max -= params1.bytes_fill_max % bytes_per_frame;
+ slave_params.bytes_fill_max = snd_pcm_plug_slave_size(pcm, stream, params1.bytes_fill_max);
+ params1.bytes_min -= params1.bytes_min % bytes_per_frame;
+ slave_params.bytes_min = snd_pcm_plug_slave_size(pcm, stream, params1.bytes_min);
+ params1.bytes_xrun_max -= params1.bytes_xrun_max % bytes_per_frame;
+ slave_params.bytes_xrun_max = snd_pcm_plug_slave_size(pcm, stream, params1.bytes_xrun_max);
+ params1.bytes_align -= params1.bytes_align % bytes_per_frame;
+ slave_params.bytes_align = snd_pcm_plug_slave_size(pcm, stream, params1.bytes_align);
if (slave_params.byte_boundary == 0 || slave_params.byte_boundary > INT_MAX)
slave_params.byte_boundary = INT_MAX;
slave_params.byte_boundary /= params->buffer_size;
step = 1;
else {
step = channels;
- if (count % channels != 0)
- return -EINVAL;
+ assert(count % channels == 0);
}
for (k = 0; k < count; k += step, vector += step) {
snd_pcm_plugin_channel_t *channels;
step = 1;
else {
step = channels;
- if (count % channels != 0)
- return -EINVAL;
+ assert(count % channels == 0);
}
for (k = 0; k < count; k += step) {
snd_pcm_plugin_channel_t *channels;
adpcm_t *data;
unsigned int channel;
- if (plugin == NULL || src_channels == NULL || dst_channels == NULL)
- return -EFAULT;
+ assert(plugin && src_channels && dst_channels);
if (frames == 0)
return 0;
for (channel = 0; channel < plugin->src_format.channels; channel++) {
if (plugin->src_format.format == SND_PCM_SFMT_IMA_ADPCM) {
- if (src_channels[channel].area.first % 4 != 0 ||
- src_channels[channel].area.step % 4 != 0 ||
- dst_channels[channel].area.first % 8 != 0 ||
- dst_channels[channel].area.step % 8 != 0)
- return -EINVAL;
+ assert(src_channels[channel].area.first % 4 == 0 &&
+ src_channels[channel].area.step % 4 == 0 &&
+ dst_channels[channel].area.first % 8 == 0 &&
+ dst_channels[channel].area.step % 8 == 0);
} else {
- if (src_channels[channel].area.first % 8 != 0 ||
- src_channels[channel].area.step % 8 != 0 ||
- dst_channels[channel].area.first % 4 != 0 ||
- dst_channels[channel].area.step % 4 != 0)
- return -EINVAL;
+ assert(src_channels[channel].area.first % 8 == 0 &&
+ src_channels[channel].area.step % 8 == 0 &&
+ dst_channels[channel].area.first % 4 == 0 &&
+ dst_channels[channel].area.step % 4 == 0);
}
}
data = (adpcm_t *)plugin->extra_data;
snd_pcm_plugin_action_t action,
unsigned long udata UNUSED)
{
- if (plugin == NULL)
- return -EINVAL;
+ assert(plugin);
switch (action) {
case INIT:
case PREPARE:
snd_pcm_format_t *format;
adpcm_f func;
- if (r_plugin == NULL)
- return -EINVAL;
+ assert(r_plugin);
*r_plugin = NULL;
- if (src_format->rate != dst_format->rate)
- return -EINVAL;
- if (src_format->channels != dst_format->channels)
- return -EINVAL;
+ assert(src_format->rate == dst_format->rate);
+ assert(src_format->channels == dst_format->channels);
if (dst_format->format == SND_PCM_SFMT_IMA_ADPCM) {
format = src_format;
func = adpcm_decode;
}
else
- return -EINVAL;
- if (!snd_pcm_format_linear(format->format))
- return -EINVAL;
+ assert(0);
+ assert(snd_pcm_format_linear(format->format));
err = snd_pcm_plugin_build(handle, stream,
"Ima-ADPCM<->linear conversion",
alaw_t *data;
unsigned int channel;
- if (plugin == NULL || src_channels == NULL || dst_channels == NULL)
- return -EFAULT;
+ assert(plugin && src_channels && dst_channels);
if (frames == 0)
return 0;
for (channel = 0; channel < plugin->src_format.channels; channel++) {
- if (src_channels[channel].area.first % 8 != 0 ||
- src_channels[channel].area.step % 8 != 0)
- return -EINVAL;
- if (dst_channels[channel].area.first % 8 != 0 ||
- dst_channels[channel].area.step % 8 != 0)
- return -EINVAL;
+ assert(src_channels[channel].area.first % 8 == 0 &&
+ src_channels[channel].area.step % 8 == 0);
+ assert(dst_channels[channel].area.first % 8 == 0 &&
+ dst_channels[channel].area.step % 8 == 0);
}
data = (alaw_t *)plugin->extra_data;
data->func(plugin, src_channels, dst_channels, frames);
snd_pcm_format_t *format;
alaw_f func;
- if (r_plugin == NULL)
- return -EINVAL;
+ assert(r_plugin);
*r_plugin = NULL;
- if (src_format->rate != dst_format->rate)
- return -EINVAL;
- if (src_format->channels != dst_format->channels)
- return -EINVAL;
+ assert(src_format->rate == dst_format->rate);
+ assert(src_format->channels == dst_format->channels);
if (dst_format->format == SND_PCM_SFMT_A_LAW) {
format = src_format;
func = alaw_decode;
}
else
- return -EINVAL;
- if (!snd_pcm_format_linear(format->format))
- return -EINVAL;
+ assert(0);
+ assert(snd_pcm_format_linear(format->format));
err = snd_pcm_plugin_build(handle, stream,
"A-Law<->linear conversion",
unsigned int channel;
unsigned int nchannels;
- if (plugin == NULL || src_channels == NULL || dst_channels == NULL)
- return -EFAULT;
+ assert(plugin && src_channels && dst_channels);
if (frames == 0)
return 0;
nchannels = plugin->src_format.channels;
for (channel = 0; channel < nchannels; channel++) {
- if (src_channels->area.first % 8 != 0 ||
- src_channels->area.step % 8 != 0)
- return -EINVAL;
- if (dst_channels->area.first % 8 != 0 ||
- dst_channels->area.step % 8 != 0)
- return -EINVAL;
+ assert(src_channels->area.first % 8 == 0 &&
+ src_channels->area.step % 8 == 0);
+ assert(dst_channels->area.first % 8 == 0 &&
+ dst_channels->area.step % 8 == 0);
if (!src_channels->enabled) {
if (dst_channels->wanted)
snd_pcm_area_silence(&dst_channels->area, 0, frames, plugin->dst_format.format);
snd_pcm_plugin_t *plugin;
int width;
- if (r_plugin == NULL)
- return -EFAULT;
+ assert(r_plugin);
*r_plugin = NULL;
- if (src_format->format != dst_format->format)
- return -EINVAL;
- if (src_format->rate != dst_format->rate)
- return -EINVAL;
- if (src_format->channels != dst_format->channels)
- return -EINVAL;
+ assert(src_format->format == dst_format->format);
+ assert(src_format->rate == dst_format->rate);
+ assert(src_format->channels == dst_format->channels);
width = snd_pcm_format_physical_width(src_format->format);
- if (width < 0)
- return -EINVAL;
+ assert(width > 0);
err = snd_pcm_plugin_build(handle, stream,
"copy",
struct iovec *vec;
int count, channel;
- if (plugin == NULL)
- return -EINVAL;
+ assert(plugin);
data = (io_t *)plugin->extra_data;
- if (data == NULL)
- return -EINVAL;
+ assert(data);
vec = (struct iovec *)((char *)data + sizeof(*data));
if (plugin->stream == SND_PCM_STREAM_PLAYBACK) {
- if (src_channels == NULL)
- return -EINVAL;
+ assert(src_channels);
if ((result = snd_pcm_plugin_src_frames_to_size(plugin, frames)) < 0)
return result;
count = plugin->src_format.channels;
return result;
return snd_pcm_plugin_src_size_to_frames(plugin, result);
} else if (plugin->stream == SND_PCM_STREAM_CAPTURE) {
- if (dst_channels == NULL)
- return -EINVAL;
+ assert(dst_channels);
if ((result = snd_pcm_plugin_dst_frames_to_size(plugin, frames)) < 0)
return result;
count = plugin->dst_format.channels;
return result;
return snd_pcm_plugin_dst_size_to_frames(plugin, result);
} else {
- return -EINVAL;
+ assert(0);
}
+ return 0;
}
static ssize_t io_src_channels(snd_pcm_plugin_t *plugin,
io_t *data;
snd_pcm_plugin_t *plugin;
- if (r_plugin == NULL)
- return -EINVAL;
+ assert(r_plugin);
*r_plugin = NULL;
- if (pcm == NULL || format == NULL)
- return -EINVAL;
+ assert(pcm && format);
err = snd_pcm_plugin_build(pcm, stream,
"I/O io",
format, format,
linear_t *data;
unsigned int channel;
- if (plugin == NULL || src_channels == NULL || dst_channels == NULL)
- return -EFAULT;
+ assert(plugin && src_channels && dst_channels);
data = (linear_t *)plugin->extra_data;
if (frames == 0)
return 0;
for (channel = 0; channel < plugin->src_format.channels; channel++) {
- if (src_channels[channel].area.first % 8 != 0 ||
- src_channels[channel].area.step % 8 != 0)
- return -EINVAL;
- if (dst_channels[channel].area.first % 8 != 0 ||
- dst_channels[channel].area.step % 8 != 0)
- return -EINVAL;
+ assert(src_channels[channel].area.first % 8 == 0 &&
+ src_channels[channel].area.step % 8 == 0);
+ assert(dst_channels[channel].area.first % 8 == 0 &&
+ dst_channels[channel].area.step % 8 == 0);
}
convert(plugin, src_channels, dst_channels, frames);
return frames;
struct linear_private_data *data;
snd_pcm_plugin_t *plugin;
- if (r_plugin == NULL)
- return -EFAULT;
+ assert(r_plugin);
*r_plugin = NULL;
- if (src_format->rate != dst_format->rate)
- return -EINVAL;
- if (src_format->channels != dst_format->channels)
- return -EINVAL;
- if (!(snd_pcm_format_linear(src_format->format) &&
- snd_pcm_format_linear(dst_format->format)))
- return -EINVAL;
+ assert(src_format->rate == dst_format->rate);
+ assert(src_format->channels == dst_format->channels);
+ assert(snd_pcm_format_linear(src_format->format) &&
+ snd_pcm_format_linear(dst_format->format));
err = snd_pcm_plugin_build(handle, stream,
"linear format conversion",
int ready;
unsigned int channel;
- if (plugin == NULL || channels == NULL)
- return -EINVAL;
+ assert(plugin && channels);
data = (mmap_t *)plugin->extra_data;
ctrl = data->control;
stream = &data->slave->stream[plugin->stream];
assert(snd_pcm_mmap_ready(data->slave, plugin->stream));
}
pos = ctrl->byte_data % setup->buffer_size;
- if ((pos * 8) % stream->bits_per_frame != 0)
- return -EINVAL;
+ assert((pos * 8) % stream->bits_per_frame == 0);
pos = (pos * 8) / stream->bits_per_frame;
sv = plugin->src_channels;
size_t pos;
int ready;
- if (plugin == NULL || channels == NULL)
- return -EINVAL;
+ assert(plugin && channels);
data = (mmap_t *)plugin->extra_data;
stream = &data->slave->stream[plugin->stream];
assert(snd_pcm_mmap_ready(data->slave, plugin->stream));
}
pos = ctrl->byte_data % setup->buffer_size;
- if ((pos * 8) % stream->bits_per_frame != 0)
- return -EINVAL;
+ assert((pos * 8) % stream->bits_per_frame == 0);
pos = (pos * 8) / stream->bits_per_frame;
sv = stream->channels;
snd_pcm_stream_t *str;
int err;
- if (plugin == NULL)
- return -EINVAL;
+ assert(plugin && plugin->prev);
+ assert(src_channels);
data = (mmap_t *)plugin->extra_data;
- if (src_channels == NULL)
- return -EINVAL;
- if (plugin->prev == NULL)
- return -EINVAL;
ctrl = data->control;
- if (ctrl == NULL)
- return -EINVAL;
+ assert(ctrl);
str = &data->slave->stream[SND_PCM_STREAM_PLAYBACK];
setup = &str->setup;
snd_pcm_mmap_control_t *ctrl;
snd_pcm_stream_t *str;
- if (plugin == NULL)
- return -EINVAL;
+ assert(plugin && plugin->next);
data = (mmap_t *)plugin->extra_data;
- if (plugin->next == NULL)
- return -EINVAL;
-
ctrl = data->control;
- if (ctrl == NULL)
- return -EINVAL;
+ assert(ctrl);
str = &data->slave->stream[SND_PCM_STREAM_CAPTURE];
/* FIXME: not here the increment */
{
struct mmap_private_data *data;
- if (plugin == NULL)
- return -EINVAL;
+ assert(plugin);
data = (mmap_t *)plugin->extra_data;
if (action == INIT) {
snd_pcm_stream_setup_t *setup;
mmap_t *data;
snd_pcm_plugin_t *plugin;
- if (r_plugin == NULL)
- return -EINVAL;
+ assert(r_plugin);
*r_plugin = NULL;
- if (!pcm)
- return -EINVAL;
+ assert(pcm);
err = snd_pcm_plugin_build(pcm, stream,
"I/O mmap",
format, format,
mulaw_t *data;
unsigned int channel;
- if (plugin == NULL || src_channels == NULL || dst_channels == NULL)
- return -EFAULT;
+ assert(plugin && src_channels && dst_channels);
if (frames == 0)
return 0;
for (channel = 0; channel < plugin->src_format.channels; channel++) {
- if (src_channels[channel].area.first % 8 != 0 ||
- src_channels[channel].area.step % 8 != 0)
- return -EINVAL;
- if (dst_channels[channel].area.first % 8 != 0 ||
- dst_channels[channel].area.step % 8 != 0)
- return -EINVAL;
+ assert(src_channels[channel].area.first % 8 == 0 &&
+ src_channels[channel].area.step % 8 == 0);
+ assert(dst_channels[channel].area.first % 8 == 0 &&
+ dst_channels[channel].area.step % 8 == 0);
}
data = (mulaw_t *)plugin->extra_data;
data->func(plugin, src_channels, dst_channels, frames);
snd_pcm_format_t *format;
mulaw_f func;
- if (r_plugin == NULL)
- return -EINVAL;
+ assert(r_plugin);
*r_plugin = NULL;
- if (src_format->rate != dst_format->rate)
- return -EINVAL;
- if (src_format->channels != dst_format->channels)
- return -EINVAL;
+ assert(src_format->rate == dst_format->rate);
+ assert(src_format->channels == dst_format->channels);
if (dst_format->format == SND_PCM_SFMT_MU_LAW) {
format = src_format;
format = dst_format;
func = mulaw_decode;
}
- else
- return -EINVAL;
- if (!snd_pcm_format_linear(format->format))
+ else {
+ assert(0);
return -EINVAL;
+ }
+ assert(snd_pcm_format_linear(format->format));
err = snd_pcm_plugin_build(handle, stream,
"Mu-Law<->linear conversion",
rate_t *data;
ssize_t res;
- if (plugin == NULL || frames <= 0)
- return -EINVAL;
+ assert(plugin);
+ if (frames == 0)
+ return 0;
data = (rate_t *)plugin->extra_data;
if (plugin->src_format.rate < plugin->dst_format.rate) {
res = (((frames * data->pitch) + (BITS/2)) >> SHIFT);
rate_t *data;
ssize_t res;
- if (plugin == NULL || frames <= 0)
- return -EINVAL;
+ assert(plugin);
+ if (frames == 0)
+ return 0;
data = (rate_t *)plugin->extra_data;
if (plugin->src_format.rate < plugin->dst_format.rate) {
res = (((frames << SHIFT) + (data->pitch / 2)) / data->pitch);
unsigned int channel;
rate_t *data;
- if (plugin == NULL || src_channels == NULL || dst_channels == NULL)
- return -EFAULT;
+ assert(plugin && src_channels && dst_channels);
if (frames == 0)
return 0;
for (channel = 0; channel < plugin->src_format.channels; channel++) {
- if (src_channels[channel].area.first % 8 != 0 ||
- src_channels[channel].area.step % 8 != 0)
- return -EINVAL;
- if (dst_channels[channel].area.first % 8 != 0 ||
- dst_channels[channel].area.step % 8 != 0)
- return -EINVAL;
+ assert(src_channels[channel].area.first % 8 == 0 &&
+ src_channels[channel].area.step % 8 == 0);
+ assert(dst_channels[channel].area.first % 8 == 0 &&
+ dst_channels[channel].area.step % 8 == 0);
}
dst_frames = rate_dst_frames(plugin, frames);
snd_pcm_plugin_action_t action,
unsigned long udata UNUSED)
{
- if (plugin == NULL)
- return -EINVAL;
+ assert(plugin);
switch (action) {
case INIT:
case PREPARE:
rate_t *data;
snd_pcm_plugin_t *plugin;
- if (r_plugin == NULL)
- return -EINVAL;
+ assert(r_plugin);
*r_plugin = NULL;
- if (src_format->channels != dst_format->channels)
- return -EINVAL;
- if (src_format->channels < 1)
- return -EINVAL;
- if (snd_pcm_format_linear(src_format->format) <= 0)
- return -EINVAL;
- if (snd_pcm_format_linear(dst_format->format) <= 0)
- return -EINVAL;
- if (src_format->rate == dst_format->rate)
- return -EINVAL;
+ assert(src_format->channels == dst_format->channels);
+ assert(src_format->channels > 0);
+ assert(snd_pcm_format_linear(src_format->format) > 0);
+ assert(snd_pcm_format_linear(dst_format->format) > 0);
+ assert(src_format->rate != dst_format->rate);
err = snd_pcm_plugin_build(handle, stream,
"rate conversion",
int nsrcs = 0;
ttable_src_t srcs[plugin->src_format.channels];
for (src_channel = 0; src_channel < plugin->src_format.channels; ++src_channel) {
- if (*sptr < 0 || *sptr > FULL)
- return -EINVAL;
+ assert(*sptr >= 0 && *sptr <= FULL);
if (*sptr != 0) {
srcs[nsrcs].channel = src_channel;
#if ROUTE_PLUGIN_USE_FLOAT
sptr++;
}
#if 0
- if (t > FULL)
- return -EINVAL;
+ assert(t <= FULL);
#endif
dptr->att = att;
dptr->nsrcs = nsrcs;
ttable_dst_t *ttp;
snd_pcm_plugin_channel_t *dvp;
- if (plugin == NULL || src_channels == NULL || dst_channels == NULL)
- return -EFAULT;
+ assert(plugin && src_channels && dst_channels);
if (frames == 0)
return 0;
data = (route_t *)plugin->extra_data;
src_nchannels = plugin->src_format.channels;
for (src_channel = 0; src_channel < src_nchannels; ++src_channel) {
- if (src_channels[src_channel].area.first % 8 != 0 ||
- src_channels[src_channel].area.step % 8 != 0)
- return -EINVAL;
+ assert(src_channels[src_channel].area.first % 8 == 0 &&
+ src_channels[src_channel].area.step % 8 == 0);
}
dst_nchannels = plugin->dst_format.channels;
for (dst_channel = 0; dst_channel < dst_nchannels; ++dst_channel) {
- if (dst_channels[dst_channel].area.first % 8 != 0 ||
- dst_channels[dst_channel].area.step % 8 != 0)
- return -EINVAL;
+ assert(dst_channels[dst_channel].area.first % 8 == 0 &&
+ dst_channels[dst_channel].area.step % 8 == 0);
}
ttp = data->ttable;
snd_pcm_plugin_t *plugin;
int err;
- if (!r_plugin)
- return -EFAULT;
+ assert(r_plugin);
*r_plugin = NULL;
- if (src_format->rate != dst_format->rate)
- return -EINVAL;
- if (!(snd_pcm_format_linear(src_format->format) &&
- snd_pcm_format_linear(dst_format->format)))
- return -EINVAL;
+ assert(src_format->rate == dst_format->rate);
+ assert(snd_pcm_format_linear(src_format->format) &&
+ snd_pcm_format_linear(dst_format->format));
err = snd_pcm_plugin_build(handle, stream,
"attenuated route conversion",