Changed other static checks in assert

This commit is contained in:
Abramo Bagnara 2000-06-04 16:24:04 +00:00
parent ef2a9bdd88
commit a44c94959e
15 changed files with 258 additions and 473 deletions

View file

@ -25,7 +25,6 @@
#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,
@ -125,7 +124,7 @@ int snd_pcm_info(snd_pcm_t *pcm, snd_pcm_info_t *info)
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)
@ -285,7 +284,7 @@ int snd_pcm_sync_go(snd_pcm_t *pcm, snd_pcm_sync_t *sync)
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)

View file

@ -81,14 +81,12 @@ static ssize_t snd_pcm_plugin_side_channels(snd_pcm_plugin_t *plugin,
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;
@ -127,19 +125,14 @@ int snd_pcm_plugin_build(snd_pcm_plugin_handle_t *handle,
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;
@ -147,11 +140,11 @@ int snd_pcm_plugin_build(snd_pcm_plugin_handle_t *handle,
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);
@ -205,11 +198,9 @@ ssize_t snd_pcm_plugin_src_frames_to_size(snd_pcm_plugin_t *plugin, size_t frame
{
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;
}
@ -217,11 +208,9 @@ ssize_t snd_pcm_plugin_dst_frames_to_size(snd_pcm_plugin_t *plugin, size_t frame
{
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;
}
@ -230,12 +219,10 @@ ssize_t snd_pcm_plugin_src_size_to_frames(snd_pcm_plugin_t *plugin, size_t size)
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;
}
@ -244,12 +231,10 @@ ssize_t snd_pcm_plugin_dst_size_to_frames(snd_pcm_plugin_t *plugin, size_t size)
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;
}
@ -257,11 +242,7 @@ ssize_t snd_pcm_plug_client_frames(snd_pcm_plugin_handle_t *handle, int stream,
{
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) {
@ -280,7 +261,8 @@ ssize_t snd_pcm_plug_client_frames(snd_pcm_plugin_handle_t *handle, int stream,
drv_frames = plugin->dst_frames(plugin, drv_frames);
plugin = plugin_next;
}
}
} else
assert(0);
return drv_frames;
}
@ -289,11 +271,7 @@ ssize_t snd_pcm_plug_slave_frames(snd_pcm_plugin_handle_t *handle, int stream, s
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;
@ -319,7 +297,8 @@ ssize_t snd_pcm_plug_slave_frames(snd_pcm_plugin_handle_t *handle, int stream, s
}
plugin = plugin_prev;
}
}
} else
assert(0);
return frames;
}
@ -328,11 +307,7 @@ ssize_t snd_pcm_plug_client_size(snd_pcm_plugin_handle_t *handle, int stream, si
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) {
@ -359,7 +334,8 @@ ssize_t snd_pcm_plug_client_size(snd_pcm_plugin_handle_t *handle, int stream, si
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;
}
@ -368,11 +344,7 @@ ssize_t snd_pcm_plug_slave_size(snd_pcm_plugin_handle_t *handle, int stream, siz
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) {
@ -399,7 +371,8 @@ ssize_t snd_pcm_plug_slave_size(snd_pcm_plugin_handle_t *handle, int stream, siz
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;
}
@ -548,6 +521,7 @@ int snd_pcm_plug_format(snd_pcm_plugin_handle_t *handle,
memcpy(srcparams, slave_params, sizeof(*slave_params));
break;
default:
assert(0);
return -EINVAL;
}
memcpy(&tmpparams, srcparams, sizeof(*srcparams));
@ -808,8 +782,7 @@ ssize_t snd_pcm_plug_client_channels_buf(snd_pcm_plugin_handle_t *handle,
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;
@ -823,11 +796,9 @@ ssize_t snd_pcm_plug_client_channels_buf(snd_pcm_plugin_handle_t *handle,
*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) {
assert(format->interleave || format->channels == 1);
for (channel = 0; channel < nchannels; channel++, v++) {
v->enabled = 1;
v->wanted = (stream == SND_PCM_STREAM_CAPTURE);
@ -837,8 +808,6 @@ ssize_t snd_pcm_plug_client_channels_buf(snd_pcm_plugin_handle_t *handle,
v->area.step = nchannels * width;
}
return count;
} else
return -EINVAL;
}
ssize_t snd_pcm_plug_client_channels_iovec(snd_pcm_plugin_handle_t *handle,
@ -868,9 +837,8 @@ 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;
@ -883,14 +851,11 @@ ssize_t snd_pcm_plug_client_channels_iovec(snd_pcm_plugin_handle_t *handle,
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;
@ -1234,7 +1199,7 @@ int snd_pcm_area_silence(const snd_pcm_channel_area_t *dst_area, size_t dst_offs
break;
}
default:
return -EINVAL;
assert(0);
}
return 0;
}
@ -1370,7 +1335,7 @@ int snd_pcm_area_copy(const snd_pcm_channel_area_t *src_area, size_t src_offset,
break;
}
default:
return -EINVAL;
assert(0);
}
return 0;
}

View file

@ -54,17 +54,6 @@ static int snd_pcm_hw_stream_close(snd_pcm_t *pcm, int stream)
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;
@ -377,7 +366,7 @@ static int snd_pcm_hw_open_stream(int card, int device, int stream, int subdevic
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;
@ -424,12 +413,10 @@ int snd_pcm_open_subdevice(snd_pcm_t **handle, int card, int device, int subdevi
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) {
@ -457,8 +444,7 @@ int snd_pcm_open_subdevice(snd_pcm_t **handle, int card, int device, int subdevi
}
}
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) {

View file

@ -19,7 +19,7 @@
*
*/
#include <pthread.h>
#include <assert.h>
#include "asoundlib.h"
struct snd_pcm_ops {

View file

@ -21,7 +21,6 @@
#include <stdio.h>
#include <malloc.h>
#include <errno.h>
#include <assert.h>
#include <sys/poll.h>
#include <sys/uio.h>
#include "pcm_local.h"
@ -43,13 +42,10 @@ static size_t snd_pcm_mmap_capture_frames_avail(snd_pcm_t *pcm)
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
@ -85,16 +81,12 @@ int snd_pcm_mmap_ready(snd_pcm_t *pcm, int stream)
{
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 {
@ -149,13 +141,10 @@ static ssize_t snd_pcm_mmap_capture_frames_xfer(snd_pcm_t *pcm, size_t frames)
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
@ -166,16 +155,11 @@ ssize_t snd_pcm_mmap_frames_offset(snd_pcm_t *pcm, int stream)
{
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;
}
@ -265,11 +249,9 @@ ssize_t snd_pcm_mmap_write_areas(snd_pcm_t *pcm, snd_pcm_channel_area_t *channel
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)
@ -322,16 +304,12 @@ ssize_t snd_pcm_mmap_write_frames(snd_pcm_t *pcm, const void *buffer, size_t fra
{
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;
@ -349,16 +327,12 @@ ssize_t snd_pcm_mmap_write(snd_pcm_t *pcm, const void *buffer, size_t bytes)
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)
@ -371,13 +345,10 @@ ssize_t snd_pcm_mmap_writev(snd_pcm_t *pcm, const struct iovec *vector, unsigned
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;
@ -396,8 +367,7 @@ ssize_t snd_pcm_mmap_writev(snd_pcm_t *pcm, const struct iovec *vector, unsigned
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;
@ -406,8 +376,7 @@ ssize_t snd_pcm_mmap_writev(snd_pcm_t *pcm, const struct iovec *vector, unsigned
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;
@ -438,11 +407,9 @@ ssize_t snd_pcm_mmap_read_areas(snd_pcm_t *pcm, snd_pcm_channel_area_t *channels
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)
@ -494,16 +461,12 @@ ssize_t snd_pcm_mmap_read_frames(snd_pcm_t *pcm, const void *buffer, size_t fram
{
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;
@ -521,16 +484,12 @@ ssize_t snd_pcm_mmap_read(snd_pcm_t *pcm, void *buffer, size_t bytes)
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)
@ -543,13 +502,10 @@ ssize_t snd_pcm_mmap_readv(snd_pcm_t *pcm, const struct iovec *vector, unsigned
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;
@ -568,8 +524,7 @@ ssize_t snd_pcm_mmap_readv(snd_pcm_t *pcm, const struct iovec *vector, unsigned
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;
@ -578,8 +533,7 @@ ssize_t snd_pcm_mmap_readv(snd_pcm_t *pcm, const struct iovec *vector, unsigned
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;
@ -605,22 +559,21 @@ int snd_pcm_mmap_control(snd_pcm_t *pcm, int stream, snd_pcm_mmap_control_t **co
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) {
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;
}
@ -633,13 +586,10 @@ int snd_pcm_mmap_get_areas(snd_pcm_t *pcm, int stream, snd_pcm_channel_area_t *a
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;
@ -674,14 +624,12 @@ int snd_pcm_mmap_data(snd_pcm_t *pcm, int stream, void **data)
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) {
if (data)
*data = str->mmap_data;
return 0;
}
@ -693,9 +641,10 @@ int snd_pcm_mmap_data(snd_pcm_t *pcm, int stream, void **data)
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)
@ -721,13 +670,10 @@ int snd_pcm_munmap_control(snd_pcm_t *pcm, int stream)
{
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;
@ -739,13 +685,10 @@ int snd_pcm_munmap_data(snd_pcm_t *pcm, int stream)
{
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);

View file

@ -86,8 +86,7 @@ int snd_pcm_plugin_insert(snd_pcm_plugin_t *plugin)
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];
@ -108,8 +107,7 @@ int snd_pcm_plugin_append(snd_pcm_plugin_t *plugin)
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];
@ -133,8 +131,7 @@ int snd_pcm_plugin_remove_to(snd_pcm_plugin_t *plugin)
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;
@ -161,12 +158,9 @@ int snd_pcm_plug_remove_first(snd_pcm_t *pcm, int stream)
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];
@ -190,12 +184,9 @@ int snd_pcm_plug_clear(snd_pcm_t *pcm, int 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];
@ -257,40 +248,6 @@ int snd_pcm_plug_direct(snd_pcm_t *pcm, int 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
/*
*
*/
@ -377,6 +334,7 @@ static int snd_pcm_plug_stream_params(snd_pcm_t *pcm, snd_pcm_stream_params_t *p
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;
@ -408,12 +366,21 @@ static int snd_pcm_plug_stream_params(snd_pcm_t *pcm, snd_pcm_stream_params_t *p
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;
@ -625,8 +592,7 @@ ssize_t snd_pcm_plug_writev(snd_pcm_t *pcm, const struct iovec *vector, unsigned
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;
@ -660,8 +626,7 @@ ssize_t snd_pcm_plug_readv(snd_pcm_t *pcm, const struct iovec *vector, unsigned
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;

View file

@ -333,23 +333,20 @@ static ssize_t adpcm_transfer(snd_pcm_plugin_t *plugin,
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;
@ -361,8 +358,7 @@ static int adpcm_action(snd_pcm_plugin_t * plugin,
snd_pcm_plugin_action_t action,
unsigned long udata UNUSED)
{
if (plugin == NULL)
return -EINVAL;
assert(plugin);
switch (action) {
case INIT:
case PREPARE:
@ -388,14 +384,11 @@ int snd_pcm_plugin_build_adpcm(snd_pcm_plugin_handle_t *handle,
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;
@ -406,9 +399,8 @@ int snd_pcm_plugin_build_adpcm(snd_pcm_plugin_handle_t *handle,
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",

View file

@ -234,17 +234,14 @@ static ssize_t alaw_transfer(snd_pcm_plugin_t *plugin,
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);
@ -263,14 +260,11 @@ int snd_pcm_plugin_build_alaw(snd_pcm_plugin_handle_t *handle,
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;
@ -281,9 +275,8 @@ int snd_pcm_plugin_build_alaw(snd_pcm_plugin_handle_t *handle,
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",

View file

@ -42,18 +42,15 @@ static ssize_t copy_transfer(snd_pcm_plugin_t *plugin,
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);
@ -78,20 +75,15 @@ int snd_pcm_plugin_build_copy(snd_pcm_plugin_handle_t *handle,
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",

View file

@ -55,15 +55,12 @@ static ssize_t io_transfer(snd_pcm_plugin_t *plugin,
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;
@ -84,8 +81,7 @@ static ssize_t io_transfer(snd_pcm_plugin_t *plugin,
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;
@ -110,8 +106,9 @@ static ssize_t io_transfer(snd_pcm_plugin_t *plugin,
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,
@ -140,11 +137,9 @@ int snd_pcm_plugin_build_io(snd_pcm_plugin_handle_t *pcm,
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,

View file

@ -92,18 +92,15 @@ static ssize_t linear_transfer(snd_pcm_plugin_t *plugin,
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;
@ -144,17 +141,13 @@ int snd_pcm_plugin_build_linear(snd_pcm_plugin_handle_t *handle,
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",

View file

@ -57,8 +57,7 @@ static ssize_t mmap_src_channels(snd_pcm_plugin_t *plugin,
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];
@ -86,8 +85,7 @@ static ssize_t mmap_src_channels(snd_pcm_plugin_t *plugin,
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;
@ -125,8 +123,7 @@ static ssize_t mmap_dst_channels(snd_pcm_plugin_t *plugin,
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];
@ -159,8 +156,7 @@ static ssize_t mmap_dst_channels(snd_pcm_plugin_t *plugin,
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;
@ -190,16 +186,11 @@ static ssize_t mmap_playback_transfer(snd_pcm_plugin_t *plugin,
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;
@ -231,15 +222,10 @@ static ssize_t mmap_capture_transfer(snd_pcm_plugin_t *plugin,
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 */
@ -254,8 +240,7 @@ static int mmap_action(snd_pcm_plugin_t *plugin,
{
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;
@ -305,11 +290,9 @@ int snd_pcm_plugin_build_mmap(snd_pcm_plugin_handle_t *pcm,
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,

View file

@ -250,17 +250,14 @@ static ssize_t mulaw_transfer(snd_pcm_plugin_t *plugin,
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);
@ -279,14 +276,11 @@ int snd_pcm_plugin_build_mulaw(snd_pcm_plugin_handle_t *handle,
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;
@ -296,10 +290,11 @@ int snd_pcm_plugin_build_mulaw(snd_pcm_plugin_handle_t *handle,
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",

View file

@ -241,8 +241,9 @@ static ssize_t rate_src_frames(snd_pcm_plugin_t *plugin, size_t frames)
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);
@ -272,8 +273,9 @@ static ssize_t rate_dst_frames(snd_pcm_plugin_t *plugin, size_t frames)
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);
@ -307,17 +309,14 @@ static ssize_t rate_transfer(snd_pcm_plugin_t *plugin,
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);
@ -330,8 +329,7 @@ static int rate_action(snd_pcm_plugin_t *plugin,
snd_pcm_plugin_action_t action,
unsigned long udata UNUSED)
{
if (plugin == NULL)
return -EINVAL;
assert(plugin);
switch (action) {
case INIT:
case PREPARE:
@ -355,20 +353,14 @@ int snd_pcm_plugin_build_rate(snd_pcm_plugin_handle_t *handle,
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",

View file

@ -438,8 +438,7 @@ static int route_load_ttable(snd_pcm_plugin_t *plugin,
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
@ -457,8 +456,7 @@ static int route_load_ttable(snd_pcm_plugin_t *plugin,
sptr++;
}
#if 0
if (t > FULL)
return -EINVAL;
assert(t <= FULL);
#endif
dptr->att = att;
dptr->nsrcs = nsrcs;
@ -494,24 +492,21 @@ static ssize_t route_transfer(snd_pcm_plugin_t *plugin,
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;
@ -550,14 +545,11 @@ int snd_pcm_plugin_build_route(snd_pcm_plugin_handle_t *handle,
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",