pcm handle split. Moved buffer to plugin struct

This commit is contained in:
Abramo Bagnara 2000-06-21 15:03:06 +00:00
parent 4c24f6925e
commit b312f52b76
11 changed files with 722 additions and 891 deletions

View file

@ -372,8 +372,7 @@ static int adpcm_action(snd_pcm_plugin_t * plugin,
return 0; /* silenty ignore other actions */
}
int snd_pcm_plugin_build_adpcm(snd_pcm_plugin_handle_t *handle,
int stream,
int snd_pcm_plugin_build_adpcm(snd_pcm_plug_t *plug,
snd_pcm_format_t *src_format,
snd_pcm_format_t *dst_format,
snd_pcm_plugin_t **r_plugin)
@ -402,10 +401,8 @@ int snd_pcm_plugin_build_adpcm(snd_pcm_plugin_handle_t *handle,
assert(0);
assert(snd_pcm_format_linear(format->format));
err = snd_pcm_plugin_build(handle, stream,
"Ima-ADPCM<->linear conversion",
src_format,
dst_format,
err = snd_pcm_plugin_build(plug, "Ima-ADPCM<->linear conversion",
src_format, dst_format,
sizeof(adpcm_t) + src_format->channels * sizeof(adpcm_channel_t),
&plugin);
if (err < 0)

View file

@ -248,8 +248,7 @@ static ssize_t alaw_transfer(snd_pcm_plugin_t *plugin,
return frames;
}
int snd_pcm_plugin_build_alaw(snd_pcm_plugin_handle_t *handle,
int stream,
int snd_pcm_plugin_build_alaw(snd_pcm_plug_t *plug,
snd_pcm_format_t *src_format,
snd_pcm_format_t *dst_format,
snd_pcm_plugin_t **r_plugin)
@ -278,12 +277,9 @@ int snd_pcm_plugin_build_alaw(snd_pcm_plugin_handle_t *handle,
assert(0);
assert(snd_pcm_format_linear(format->format));
err = snd_pcm_plugin_build(handle, stream,
"A-Law<->linear conversion",
src_format,
dst_format,
sizeof(alaw_t),
&plugin);
err = snd_pcm_plugin_build(plug, "A-Law<->linear conversion",
src_format, dst_format,
sizeof(alaw_t), &plugin);
if (err < 0)
return err;
data = (alaw_t*)plugin->extra_data;

View file

@ -65,8 +65,7 @@ static ssize_t copy_transfer(snd_pcm_plugin_t *plugin,
return frames;
}
int snd_pcm_plugin_build_copy(snd_pcm_plugin_handle_t *handle,
int stream,
int snd_pcm_plugin_build_copy(snd_pcm_plug_t *plug,
snd_pcm_format_t *src_format,
snd_pcm_format_t *dst_format,
snd_pcm_plugin_t **r_plugin)
@ -85,12 +84,8 @@ int snd_pcm_plugin_build_copy(snd_pcm_plugin_handle_t *handle,
width = snd_pcm_format_physical_width(src_format->format);
assert(width > 0);
err = snd_pcm_plugin_build(handle, stream,
"copy",
src_format,
dst_format,
0,
&plugin);
err = snd_pcm_plugin_build(plug, "copy", src_format, dst_format,
0, &plugin);
if (err < 0)
return err;
plugin->transfer = copy_transfer;

View file

@ -23,10 +23,10 @@
#include "../../include/driver.h"
#include "../../include/pcm.h"
#include "../../include/pcm_plugin.h"
#define snd_pcm_write(handle,buf,count) snd_pcm_oss_write3(handle,buf,count,1)
#define snd_pcm_writev(handle,vec,count) snd_pcm_oss_writev3(handle,vec,count,1)
#define snd_pcm_read(handle,buf,count) snd_pcm_oss_read3(handle,buf,count,1)
#define snd_pcm_readv(handle,vec,count) snd_pcm_oss_readv3(handle,vec,count,1)
#define pcm_write(plug,buf,count) snd_pcm_oss_write3(plug,buf,count,1)
#define pcm_writev(plug,vec,count) snd_pcm_oss_writev3(plug,vec,count,1)
#define pcm_read(plug,buf,count) snd_pcm_oss_read3(plug,buf,count,1)
#define pcm_readv(plug,vec,count) snd_pcm_oss_readv3(plug,vec,count,1)
#else
#include <stdio.h>
#include <stdlib.h>
@ -35,65 +35,67 @@
#include <errno.h>
#include <sys/uio.h>
#include "../pcm_local.h"
#define pcm_write(plug,buf,count) snd_pcm_write(plug->slave,buf,count)
#define pcm_writev(plug,vec,count) snd_pcm_writev(plug->slave,vec,count)
#define pcm_read(plug,buf,count) snd_pcm_read(plug->slave,buf,count)
#define pcm_readv(plug,vec,count) snd_pcm_readv(plug->slave,vec,count)
#endif
/*
* Basic io plugin
*/
typedef struct io_private_data {
snd_pcm_plugin_handle_t *slave;
} io_t;
static ssize_t io_transfer(snd_pcm_plugin_t *plugin,
const snd_pcm_plugin_channel_t *src_channels,
snd_pcm_plugin_channel_t *dst_channels,
size_t frames)
static ssize_t io_playback_transfer(snd_pcm_plugin_t *plugin,
const snd_pcm_plugin_channel_t *src_channels,
snd_pcm_plugin_channel_t *dst_channels UNUSED,
size_t frames)
{
io_t *data;
struct iovec *vec;
int count, channel;
assert(plugin);
data = (io_t *)plugin->extra_data;
assert(data);
vec = (struct iovec *)((char *)data + sizeof(*data));
if (plugin->stream == SND_PCM_STREAM_PLAYBACK) {
assert(src_channels);
count = plugin->src_format.channels;
if (plugin->src_format.interleave) {
return snd_pcm_write(data->slave, src_channels->area.addr, frames);
} else {
for (channel = 0; channel < count; channel++) {
if (src_channels[channel].enabled)
vec[channel].iov_base = src_channels[channel].area.addr;
else
vec[channel].iov_base = 0;
vec[channel].iov_len = frames;
}
return snd_pcm_writev(data->slave, vec, count);
}
} else if (plugin->stream == SND_PCM_STREAM_CAPTURE) {
assert(dst_channels);
count = plugin->dst_format.channels;
if (plugin->dst_format.interleave) {
for (channel = 0; channel < count; channel++) {
dst_channels[channel].enabled = src_channels[channel].enabled;
}
return snd_pcm_read(data->slave, dst_channels->area.addr, frames);
} else {
for (channel = 0; channel < count; channel++) {
dst_channels[channel].enabled = src_channels[channel].enabled;
if (dst_channels[channel].enabled)
vec[channel].iov_base = dst_channels[channel].area.addr;
else
vec[channel].iov_base = 0;
vec[channel].iov_len = frames;
}
return snd_pcm_readv(data->slave, vec, count);
}
vec = (struct iovec *)plugin->extra_data;
assert(vec);
assert(src_channels);
count = plugin->src_format.channels;
if (plugin->src_format.interleave) {
return pcm_write(plugin->plug, src_channels->area.addr, frames);
} else {
assert(0);
for (channel = 0; channel < count; channel++) {
if (src_channels[channel].enabled)
vec[channel].iov_base = src_channels[channel].area.addr;
else
vec[channel].iov_base = 0;
vec[channel].iov_len = frames;
}
return pcm_writev(plugin->plug, vec, count);
}
}
static ssize_t io_capture_transfer(snd_pcm_plugin_t *plugin,
const snd_pcm_plugin_channel_t *src_channels UNUSED,
snd_pcm_plugin_channel_t *dst_channels,
size_t frames)
{
struct iovec *vec;
int count, channel;
assert(plugin);
vec = (struct iovec *)plugin->extra_data;
assert(vec);
assert(dst_channels);
count = plugin->dst_format.channels;
if (plugin->dst_format.interleave) {
return pcm_read(plugin->plug, dst_channels->area.addr, frames);
} else {
for (channel = 0; channel < count; channel++) {
if (dst_channels[channel].enabled)
vec[channel].iov_base = dst_channels[channel].area.addr;
else
vec[channel].iov_base = 0;
vec[channel].iov_len = frames;
}
return pcm_readv(plugin->plug, vec, count);
}
return 0;
}
@ -109,36 +111,37 @@ static ssize_t io_src_channels(snd_pcm_plugin_t *plugin,
if (err < 0)
return err;
*channels = v;
for (channel = 0; channel < plugin->src_format.channels; ++channel, ++v)
v->wanted = 1;
if (plugin->src_format.interleave) {
for (channel = 0; channel < plugin->src_format.channels; ++channel, ++v)
v->wanted = 1;
}
return frames;
}
int snd_pcm_plugin_build_io(snd_pcm_plugin_handle_t *pcm,
int stream,
snd_pcm_plugin_handle_t *slave,
snd_pcm_format_t *format,
snd_pcm_plugin_t **r_plugin)
int snd_pcm_plugin_build_io(snd_pcm_plug_t *plug,
snd_pcm_format_t *format,
snd_pcm_plugin_t **r_plugin)
{
int err;
io_t *data;
snd_pcm_plugin_t *plugin;
assert(r_plugin);
*r_plugin = NULL;
assert(pcm && format);
err = snd_pcm_plugin_build(pcm, stream,
"I/O io",
assert(plug && format);
err = snd_pcm_plugin_build(plug, "I/O io",
format, format,
sizeof(io_t) + sizeof(struct iovec) * format->channels,
sizeof(struct iovec) * format->channels,
&plugin);
if (err < 0)
return err;
data = (io_t *)plugin->extra_data;
data->slave = slave;
plugin->transfer = io_transfer;
if (format->interleave && stream == SND_PCM_STREAM_PLAYBACK)
plugin->client_channels = io_src_channels;
if (snd_pcm_plug_stream(plug) == SND_PCM_STREAM_PLAYBACK) {
plugin->transfer = io_playback_transfer;
if (format->interleave)
plugin->client_channels = io_src_channels;
} else {
plugin->transfer = io_capture_transfer;
}
*r_plugin = plugin;
return 0;
}

View file

@ -131,8 +131,7 @@ int conv_index(int src_format, int dst_format)
return src_width * 32 + src_endian * 16 + sign * 8 + dst_width * 2 + dst_endian;
}
int snd_pcm_plugin_build_linear(snd_pcm_plugin_handle_t *handle,
int stream,
int snd_pcm_plugin_build_linear(snd_pcm_plug_t *plug,
snd_pcm_format_t *src_format,
snd_pcm_format_t *dst_format,
snd_pcm_plugin_t **r_plugin)
@ -149,12 +148,9 @@ int snd_pcm_plugin_build_linear(snd_pcm_plugin_handle_t *handle,
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",
src_format,
dst_format,
sizeof(linear_t),
&plugin);
err = snd_pcm_plugin_build(plug, "linear format conversion",
src_format, dst_format,
sizeof(linear_t), &plugin);
if (err < 0)
return err;
data = (linear_t *)plugin->extra_data;

View file

@ -34,7 +34,6 @@
*/
typedef struct mmap_private_data {
snd_pcm_t *slave;
void *buffer;
#if 0
char *silence;
@ -49,42 +48,42 @@ static ssize_t mmap_src_channels(snd_pcm_plugin_t *plugin,
mmap_t *data;
snd_pcm_plugin_channel_t *sv;
snd_pcm_channel_area_t *dv;
snd_pcm_stream_t *stream;
snd_pcm_stream_setup_t *setup;
snd_pcm_t *stream;
snd_pcm_setup_t *setup;
size_t pos;
int ready;
unsigned int channel;
assert(plugin && channels);
data = (mmap_t *)plugin->extra_data;
stream = &data->slave->stream[plugin->stream];
stream = plugin->plug->slave;
setup = &stream->setup;
if (snd_pcm_mmap_stream_state(data->slave, plugin->stream) < SND_PCM_STATE_PREPARED)
if (snd_pcm_mmap_state(stream) < SND_PCM_STATE_PREPARED)
return -EBADFD;
ready = snd_pcm_mmap_ready(data->slave, plugin->stream);
ready = snd_pcm_mmap_ready(stream);
if (ready < 0)
return ready;
if (!ready) {
struct pollfd pfd;
if (snd_pcm_mmap_stream_state(data->slave, plugin->stream) != SND_PCM_STATE_RUNNING)
if (snd_pcm_mmap_state(stream) != SND_PCM_STATE_RUNNING)
return -EPIPE;
if (stream->mode & SND_PCM_NONBLOCK)
return -EAGAIN;
pfd.fd = snd_pcm_file_descriptor(data->slave, plugin->stream);
pfd.fd = snd_pcm_file_descriptor(stream);
pfd.events = POLLOUT | POLLERR;
ready = poll(&pfd, 1, 10000);
if (ready < 0)
return ready;
if (ready && pfd.revents & POLLERR)
return -EPIPE;
assert(snd_pcm_mmap_ready(data->slave, plugin->stream));
assert(snd_pcm_mmap_ready(stream));
}
pos = snd_pcm_mmap_frames_offset(data->slave, plugin->stream);
pos = snd_pcm_mmap_frames_offset(stream);
assert(pos % setup->frames_align == 0);
sv = plugin->src_channels;
sv = plugin->buf_channels;
dv = stream->channels;
*channels = sv;
for (channel = 0; channel < plugin->src_format.channels; ++channel) {
@ -94,78 +93,76 @@ static ssize_t mmap_src_channels(snd_pcm_plugin_t *plugin,
#else
sv->wanted = 1;
#endif
sv->aptr = 0;
sv->area.addr = dv->addr + dv->step * pos / 8;
sv->area.first = dv->first;
sv->area.step = dv->step;
++sv;
++dv;
}
return snd_pcm_mmap_frames_xfer(data->slave, plugin->stream, frames);
return snd_pcm_mmap_frames_xfer(stream, frames);
}
static ssize_t mmap_dst_channels(snd_pcm_plugin_t *plugin,
size_t frames,
snd_pcm_plugin_channel_t **channels)
size_t frames,
snd_pcm_plugin_channel_t **channels)
{
mmap_t *data;
int err;
unsigned int channel;
snd_pcm_plugin_channel_t *dv;
snd_pcm_channel_area_t *sv;
snd_pcm_stream_t *stream;
snd_pcm_stream_setup_t *setup;
snd_pcm_t *stream;
snd_pcm_setup_t *setup;
size_t pos;
int ready;
assert(plugin && channels);
data = (mmap_t *)plugin->extra_data;
stream = &data->slave->stream[plugin->stream];
stream = plugin->plug->slave;
setup = &stream->setup;
if (snd_pcm_mmap_stream_state(data->slave, plugin->stream) < SND_PCM_STATE_PREPARED)
if (snd_pcm_mmap_state(stream) < SND_PCM_STATE_PREPARED)
return -EBADFD;
if (snd_pcm_mmap_stream_state(data->slave, plugin->stream) == SND_PCM_STATE_PREPARED &&
if (snd_pcm_mmap_state(stream) == SND_PCM_STATE_PREPARED &&
stream->setup.start_mode == SND_PCM_START_DATA) {
err = snd_pcm_stream_go(data->slave, plugin->stream);
err = snd_pcm_go(stream);
if (err < 0)
return err;
}
ready = snd_pcm_mmap_ready(data->slave, plugin->stream);
ready = snd_pcm_mmap_ready(stream);
if (ready < 0)
return ready;
if (!ready) {
struct pollfd pfd;
if (snd_pcm_mmap_stream_state(data->slave, plugin->stream) != SND_PCM_STATE_RUNNING)
if (snd_pcm_mmap_state(stream) != SND_PCM_STATE_RUNNING)
return -EPIPE;
if (stream->mode & SND_PCM_NONBLOCK)
return -EAGAIN;
pfd.fd = snd_pcm_file_descriptor(data->slave, plugin->stream);
pfd.fd = snd_pcm_file_descriptor(stream);
pfd.events = POLLIN | POLLERR;
ready = poll(&pfd, 1, 10000);
if (ready < 0)
return ready;
if (ready && pfd.revents & POLLERR)
return -EPIPE;
assert(snd_pcm_mmap_ready(data->slave, plugin->stream));
assert(snd_pcm_mmap_ready(stream));
}
pos = snd_pcm_mmap_frames_offset(data->slave, plugin->stream);
pos = snd_pcm_mmap_frames_offset(stream);
assert(pos % setup->frames_align == 0);
sv = stream->channels;
dv = plugin->dst_channels;
dv = plugin->buf_channels;
*channels = dv;
for (channel = 0; channel < plugin->dst_format.channels; ++channel) {
dv->enabled = 1;
dv->wanted = 0;
dv->aptr = 0;
dv->area.addr = sv->addr + sv->step * pos / 8;
dv->area.first = sv->first;
dv->area.step = sv->step;
++sv;
++dv;
}
return snd_pcm_mmap_frames_xfer(data->slave, plugin->stream, frames);
return snd_pcm_mmap_frames_xfer(stream, frames);
}
static ssize_t mmap_playback_transfer(snd_pcm_plugin_t *plugin,
@ -174,15 +171,15 @@ static ssize_t mmap_playback_transfer(snd_pcm_plugin_t *plugin,
size_t frames)
{
mmap_t *data;
snd_pcm_stream_setup_t *setup;
snd_pcm_stream_t *str;
snd_pcm_setup_t *setup;
snd_pcm_t *stream;
int err;
assert(plugin && plugin->prev);
assert(src_channels);
data = (mmap_t *)plugin->extra_data;
str = &data->slave->stream[SND_PCM_STREAM_PLAYBACK];
setup = &str->setup;
stream = plugin->plug->slave;
setup = &stream->setup;
#if 0
for (channel = 0; channel < plugin->src_format.channels; channel++) {
@ -191,12 +188,12 @@ static ssize_t mmap_playback_transfer(snd_pcm_plugin_t *plugin,
}
#endif
snd_pcm_mmap_stream_frame_data(data->slave, SND_PCM_STREAM_PLAYBACK, frames);
if (snd_pcm_mmap_stream_state(data->slave, plugin->stream) == SND_PCM_STATE_PREPARED &&
(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);
snd_pcm_frame_data(stream, frames);
if (snd_pcm_mmap_state(stream) == SND_PCM_STATE_PREPARED &&
(setup->start_mode == SND_PCM_START_DATA ||
(setup->start_mode == SND_PCM_START_FULL &&
!snd_pcm_mmap_ready(stream)))) {
err = snd_pcm_go(stream);
if (err < 0)
return err;
}
@ -209,14 +206,14 @@ static ssize_t mmap_capture_transfer(snd_pcm_plugin_t *plugin,
size_t frames)
{
mmap_t *data;
snd_pcm_stream_t *str;
snd_pcm_t *stream;
assert(plugin && plugin->next);
data = (mmap_t *)plugin->extra_data;
str = &data->slave->stream[SND_PCM_STREAM_CAPTURE];
stream = plugin->plug->slave;
/* FIXME: not here the increment */
snd_pcm_mmap_stream_frame_data(data->slave, SND_PCM_STREAM_CAPTURE, frames);
snd_pcm_frame_data(stream, frames);
return frames;
}
@ -226,21 +223,23 @@ static int mmap_action(snd_pcm_plugin_t *plugin,
unsigned long udata UNUSED)
{
struct mmap_private_data *data;
snd_pcm_t *stream;
assert(plugin);
stream = plugin->plug->slave;
data = (mmap_t *)plugin->extra_data;
if (action == INIT) {
snd_pcm_stream_setup_t *setup;
snd_pcm_setup_t *setup;
int result;
if (data->buffer) {
snd_pcm_munmap(data->slave, plugin->stream);
snd_pcm_munmap(stream);
data->buffer = 0;
}
result = snd_pcm_mmap(data->slave, plugin->stream, NULL, NULL, (void **)&data->buffer);
result = snd_pcm_mmap(stream, NULL, NULL, (void **)&data->buffer);
if (result < 0)
return result;
setup = &data->slave->stream[plugin->stream].setup;
setup = &stream->setup;
#if 0
if (plugin->stream == SND_PCM_STREAM_PLAYBACK) {
@ -266,12 +265,10 @@ static void mmap_free(snd_pcm_plugin_t *plugin, void *private_data UNUSED)
free(data->silence);
#endif
if (data->buffer)
snd_pcm_munmap(data->slave, plugin->stream);
snd_pcm_munmap(plugin->plug->slave);
}
int snd_pcm_plugin_build_mmap(snd_pcm_plugin_handle_t *pcm,
int stream,
snd_pcm_t *slave,
int snd_pcm_plugin_build_mmap(snd_pcm_plug_t *plug,
snd_pcm_format_t *format,
snd_pcm_plugin_t **r_plugin)
{
@ -281,17 +278,15 @@ int snd_pcm_plugin_build_mmap(snd_pcm_plugin_handle_t *pcm,
assert(r_plugin);
*r_plugin = NULL;
assert(pcm);
err = snd_pcm_plugin_build(pcm, stream,
"I/O mmap",
assert(plug);
err = snd_pcm_plugin_build(plug, "I/O mmap",
format, format,
sizeof(mmap_t) + sizeof(snd_pcm_plugin_channel_t) * format->channels,
&plugin);
if (err < 0)
return err;
data = (mmap_t *)plugin->extra_data;
data->slave = slave;
if (stream == SND_PCM_STREAM_PLAYBACK) {
if (plug->handle->stream == SND_PCM_STREAM_PLAYBACK) {
plugin->client_channels = mmap_src_channels;
plugin->transfer = mmap_playback_transfer;
} else {

View file

@ -264,8 +264,7 @@ static ssize_t mulaw_transfer(snd_pcm_plugin_t *plugin,
return frames;
}
int snd_pcm_plugin_build_mulaw(snd_pcm_plugin_handle_t *handle,
int stream,
int snd_pcm_plugin_build_mulaw(snd_pcm_plug_t *plug,
snd_pcm_format_t *src_format,
snd_pcm_format_t *dst_format,
snd_pcm_plugin_t **r_plugin)
@ -296,12 +295,9 @@ int snd_pcm_plugin_build_mulaw(snd_pcm_plugin_handle_t *handle,
}
assert(snd_pcm_format_linear(format->format));
err = snd_pcm_plugin_build(handle, stream,
"Mu-Law<->linear conversion",
src_format,
dst_format,
sizeof(mulaw_t),
&plugin);
err = snd_pcm_plugin_build(plug, "Mu-Law<->linear conversion",
src_format, dst_format,
sizeof(mulaw_t), &plugin);
if (err < 0)
return err;
data = (mulaw_t*)plugin->extra_data;

View file

@ -343,8 +343,7 @@ static int rate_action(snd_pcm_plugin_t *plugin,
return 0; /* silenty ignore other actions */
}
int snd_pcm_plugin_build_rate(snd_pcm_plugin_handle_t *handle,
int stream,
int snd_pcm_plugin_build_rate(snd_pcm_plug_t *plug,
snd_pcm_format_t *src_format,
snd_pcm_format_t *dst_format,
snd_pcm_plugin_t **r_plugin)
@ -362,10 +361,8 @@ int snd_pcm_plugin_build_rate(snd_pcm_plugin_handle_t *handle,
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",
src_format,
dst_format,
err = snd_pcm_plugin_build(plug, "rate conversion",
src_format, dst_format,
sizeof(rate_t) + src_format->channels * sizeof(rate_channel_t),
&plugin);
if (err < 0)

View file

@ -534,8 +534,7 @@ int getput_index(int format)
return width * 4 + endian * 2 + sign;
}
int snd_pcm_plugin_build_route(snd_pcm_plugin_handle_t *handle,
int stream,
int snd_pcm_plugin_build_route(snd_pcm_plug_t *plug,
snd_pcm_format_t *src_format,
snd_pcm_format_t *dst_format,
route_ttable_entry_t *ttable,
@ -551,10 +550,8 @@ int snd_pcm_plugin_build_route(snd_pcm_plugin_handle_t *handle,
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",
src_format,
dst_format,
err = snd_pcm_plugin_build(plug, "attenuated route conversion",
src_format, dst_format,
sizeof(route_t) + sizeof(data->ttable[0]) * dst_format->channels,
&plugin);
if (err < 0)