mirror of
https://github.com/alsa-project/alsa-lib.git
synced 2025-11-03 09:01:52 -05:00
Merged pcmfinal branch.
This commit is contained in:
parent
3cc2b957fb
commit
41bb7068f2
57 changed files with 5189 additions and 3088 deletions
|
|
@ -23,11 +23,16 @@
|
|||
#include "pcm_local.h"
|
||||
#include "pcm_plugin.h"
|
||||
|
||||
enum {
|
||||
SND_PCM_FILE_FORMAT_RAW
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
snd_pcm_t *slave;
|
||||
int close_slave;
|
||||
char *fname;
|
||||
int fd;
|
||||
int format;
|
||||
} snd_pcm_file_t;
|
||||
|
||||
static int snd_pcm_file_close(snd_pcm_t *pcm)
|
||||
|
|
@ -68,18 +73,6 @@ static int snd_pcm_file_channel_info(snd_pcm_t *pcm, snd_pcm_channel_info_t * in
|
|||
return snd_pcm_channel_info(file->slave, info);
|
||||
}
|
||||
|
||||
static int snd_pcm_file_channel_params(snd_pcm_t *pcm, snd_pcm_channel_params_t * params)
|
||||
{
|
||||
snd_pcm_file_t *file = pcm->private;
|
||||
return snd_pcm_channel_params(file->slave, params);
|
||||
}
|
||||
|
||||
static int snd_pcm_file_channel_setup(snd_pcm_t *pcm, snd_pcm_channel_setup_t * setup)
|
||||
{
|
||||
snd_pcm_file_t *file = pcm->private;
|
||||
return snd_pcm_channel_setup(file->slave, setup);
|
||||
}
|
||||
|
||||
static int snd_pcm_file_status(snd_pcm_t *pcm, snd_pcm_status_t * status)
|
||||
{
|
||||
snd_pcm_file_t *file = pcm->private;
|
||||
|
|
@ -148,11 +141,16 @@ static void snd_pcm_file_write_areas(snd_pcm_t *pcm,
|
|||
snd_pcm_file_t *file = pcm->private;
|
||||
size_t bytes = snd_pcm_frames_to_bytes(pcm, frames);
|
||||
char *buf;
|
||||
size_t channels = pcm->setup.format.channels;
|
||||
size_t channels = pcm->channels;
|
||||
snd_pcm_channel_area_t buf_areas[channels];
|
||||
size_t channel;
|
||||
ssize_t r;
|
||||
if (pcm->setup.mmap_shape != SND_PCM_MMAP_INTERLEAVED) {
|
||||
switch (pcm->access) {
|
||||
case SND_PCM_ACCESS_MMAP_INTERLEAVED:
|
||||
case SND_PCM_ACCESS_RW_INTERLEAVED:
|
||||
buf = snd_pcm_channel_area_addr(areas, offset);
|
||||
break;
|
||||
default:
|
||||
buf = alloca(bytes);
|
||||
for (channel = 0; channel < channels; ++channel) {
|
||||
snd_pcm_channel_area_t *a = &buf_areas[channel];
|
||||
|
|
@ -161,9 +159,8 @@ static void snd_pcm_file_write_areas(snd_pcm_t *pcm,
|
|||
a->step = pcm->bits_per_frame;
|
||||
}
|
||||
snd_pcm_areas_copy(areas, offset, buf_areas, 0,
|
||||
channels, frames, pcm->setup.format.sfmt);
|
||||
} else
|
||||
buf = snd_pcm_channel_area_addr(areas, offset);
|
||||
channels, frames, pcm->format);
|
||||
}
|
||||
r = write(file->fd, buf, bytes);
|
||||
assert(r == (ssize_t)bytes);
|
||||
}
|
||||
|
|
@ -183,7 +180,7 @@ static ssize_t snd_pcm_file_writei(snd_pcm_t *pcm, const void *buffer, size_t si
|
|||
static ssize_t snd_pcm_file_writen(snd_pcm_t *pcm, void **bufs, size_t size)
|
||||
{
|
||||
snd_pcm_file_t *file = pcm->private;
|
||||
snd_pcm_channel_area_t areas[pcm->setup.format.channels];
|
||||
snd_pcm_channel_area_t areas[pcm->channels];
|
||||
ssize_t n = snd_pcm_writen(file->slave, bufs, size);
|
||||
if (n > 0) {
|
||||
snd_pcm_areas_from_bufs(pcm, areas, bufs);
|
||||
|
|
@ -207,7 +204,7 @@ static ssize_t snd_pcm_file_readi(snd_pcm_t *pcm, void *buffer, size_t size)
|
|||
static ssize_t snd_pcm_file_readn(snd_pcm_t *pcm, void **bufs, size_t size)
|
||||
{
|
||||
snd_pcm_file_t *file = pcm->private;
|
||||
snd_pcm_channel_area_t areas[pcm->setup.format.channels];
|
||||
snd_pcm_channel_area_t areas[pcm->channels];
|
||||
ssize_t n = snd_pcm_writen(file->slave, bufs, size);
|
||||
if (n > 0) {
|
||||
snd_pcm_areas_from_bufs(pcm, areas, bufs);
|
||||
|
|
@ -226,12 +223,12 @@ static ssize_t snd_pcm_file_mmap_forward(snd_pcm_t *pcm, size_t size)
|
|||
return n;
|
||||
while (xfer < (size_t)n) {
|
||||
size_t frames = size - xfer;
|
||||
size_t cont = pcm->setup.buffer_size - ofs;
|
||||
size_t cont = pcm->buffer_size - ofs;
|
||||
if (cont < frames)
|
||||
frames = cont;
|
||||
snd_pcm_file_write_areas(pcm, snd_pcm_mmap_areas(file->slave), ofs, frames);
|
||||
ofs += frames;
|
||||
if (ofs == pcm->setup.buffer_size)
|
||||
if (ofs == pcm->buffer_size)
|
||||
ofs = 0;
|
||||
xfer += frames;
|
||||
}
|
||||
|
|
@ -250,44 +247,46 @@ static int snd_pcm_file_set_avail_min(snd_pcm_t *pcm, size_t frames)
|
|||
return snd_pcm_set_avail_min(file->slave, frames);
|
||||
}
|
||||
|
||||
static int snd_pcm_file_mmap(snd_pcm_t *pcm)
|
||||
static int snd_pcm_file_hw_info(snd_pcm_t *pcm, snd_pcm_hw_info_t * info)
|
||||
{
|
||||
snd_pcm_file_t *file = pcm->private;
|
||||
int err = snd_pcm_mmap(file->slave);
|
||||
if (err < 0)
|
||||
return err;
|
||||
pcm->mmap_info_count = file->slave->mmap_info_count;
|
||||
pcm->mmap_info = file->slave->mmap_info;
|
||||
return 0;
|
||||
return snd_pcm_hw_info(file->slave, info);
|
||||
}
|
||||
|
||||
static int snd_pcm_file_munmap(snd_pcm_t *pcm)
|
||||
static int snd_pcm_file_hw_params(snd_pcm_t *pcm, snd_pcm_hw_params_t * params)
|
||||
{
|
||||
snd_pcm_file_t *file = pcm->private;
|
||||
int err = snd_pcm_munmap(file->slave);
|
||||
if (err < 0)
|
||||
return err;
|
||||
pcm->mmap_info_count = 0;
|
||||
pcm->mmap_info = 0;
|
||||
return 0;
|
||||
return snd_pcm_hw_params(file->slave, params);
|
||||
}
|
||||
|
||||
static int snd_pcm_file_params_info(snd_pcm_t *pcm, snd_pcm_params_info_t * info)
|
||||
static int snd_pcm_file_sw_params(snd_pcm_t *pcm, snd_pcm_sw_params_t * params)
|
||||
{
|
||||
snd_pcm_file_t *file = pcm->private;
|
||||
return snd_pcm_params_info(file->slave, info);
|
||||
return snd_pcm_sw_params(file->slave, params);
|
||||
}
|
||||
|
||||
static int snd_pcm_file_params(snd_pcm_t *pcm, snd_pcm_params_t * params)
|
||||
static int snd_pcm_file_dig_info(snd_pcm_t *pcm, snd_pcm_dig_info_t * info)
|
||||
{
|
||||
snd_pcm_file_t *file = pcm->private;
|
||||
return snd_pcm_params(file->slave, params);
|
||||
return snd_pcm_dig_info(file->slave, info);
|
||||
}
|
||||
|
||||
static int snd_pcm_file_setup(snd_pcm_t *pcm, snd_pcm_setup_t * setup)
|
||||
static int snd_pcm_file_dig_params(snd_pcm_t *pcm, snd_pcm_dig_params_t * params)
|
||||
{
|
||||
snd_pcm_file_t *file = pcm->private;
|
||||
return snd_pcm_setup(file->slave, setup);
|
||||
return snd_pcm_dig_params(file->slave, params);
|
||||
}
|
||||
|
||||
static int snd_pcm_file_mmap(snd_pcm_t *pcm ATTRIBUTE_UNUSED)
|
||||
{
|
||||
snd_pcm_file_t *file = pcm->private;
|
||||
return snd_pcm_mmap(file->slave);
|
||||
}
|
||||
|
||||
static int snd_pcm_file_munmap(snd_pcm_t *pcm ATTRIBUTE_UNUSED)
|
||||
{
|
||||
snd_pcm_file_t *file = pcm->private;
|
||||
return snd_pcm_munmap(file->slave);
|
||||
}
|
||||
|
||||
static void snd_pcm_file_dump(snd_pcm_t *pcm, FILE *fp)
|
||||
|
|
@ -297,7 +296,7 @@ static void snd_pcm_file_dump(snd_pcm_t *pcm, FILE *fp)
|
|||
fprintf(fp, "File PCM (file=%s)\n", file->fname);
|
||||
else
|
||||
fprintf(fp, "File PCM (fd=%d)\n", file->fd);
|
||||
if (pcm->valid_setup) {
|
||||
if (pcm->setup) {
|
||||
fprintf(fp, "Its setup is:\n");
|
||||
snd_pcm_dump_setup(pcm, fp);
|
||||
}
|
||||
|
|
@ -308,12 +307,12 @@ static void snd_pcm_file_dump(snd_pcm_t *pcm, FILE *fp)
|
|||
snd_pcm_ops_t snd_pcm_file_ops = {
|
||||
close: snd_pcm_file_close,
|
||||
info: snd_pcm_file_info,
|
||||
params_info: snd_pcm_file_params_info,
|
||||
params: snd_pcm_file_params,
|
||||
setup: snd_pcm_file_setup,
|
||||
hw_info: snd_pcm_file_hw_info,
|
||||
hw_params: snd_pcm_file_hw_params,
|
||||
sw_params: snd_pcm_file_sw_params,
|
||||
dig_info: snd_pcm_file_dig_info,
|
||||
dig_params: snd_pcm_file_dig_params,
|
||||
channel_info: snd_pcm_file_channel_info,
|
||||
channel_params: snd_pcm_file_channel_params,
|
||||
channel_setup: snd_pcm_file_channel_setup,
|
||||
dump: snd_pcm_file_dump,
|
||||
nonblock: snd_pcm_file_nonblock,
|
||||
async: snd_pcm_file_async,
|
||||
|
|
@ -340,11 +339,11 @@ snd_pcm_fast_ops_t snd_pcm_file_fast_ops = {
|
|||
set_avail_min: snd_pcm_file_set_avail_min,
|
||||
};
|
||||
|
||||
int snd_pcm_file_open(snd_pcm_t **pcmp, char *name, char *fname, int fd, snd_pcm_t *slave, int close_slave)
|
||||
int snd_pcm_file_open(snd_pcm_t **pcmp, char *name, char *fname, int fd, char *fmt, snd_pcm_t *slave, int close_slave)
|
||||
{
|
||||
snd_pcm_t *pcm;
|
||||
snd_pcm_file_t *file;
|
||||
assert(pcmp && slave);
|
||||
assert(pcmp);
|
||||
if (fname) {
|
||||
fd = open(fname, O_WRONLY|O_CREAT, 0666);
|
||||
if (fd < 0) {
|
||||
|
|
@ -354,8 +353,16 @@ int snd_pcm_file_open(snd_pcm_t **pcmp, char *name, char *fname, int fd, snd_pcm
|
|||
}
|
||||
file = calloc(1, sizeof(snd_pcm_file_t));
|
||||
if (!file) {
|
||||
if (fname)
|
||||
close(fd);
|
||||
return -ENOMEM;
|
||||
}
|
||||
if (fmt == NULL ||
|
||||
strcmp(fmt, "raw") == 0)
|
||||
file->format = SND_PCM_FILE_FORMAT_RAW;
|
||||
else
|
||||
ERR("file format %s is unknown", fmt);
|
||||
|
||||
file->fname = fname;
|
||||
file->fd = fd;
|
||||
file->slave = slave;
|
||||
|
|
@ -393,6 +400,7 @@ int _snd_pcm_file_open(snd_pcm_t **pcmp, char *name,
|
|||
int err;
|
||||
snd_pcm_t *spcm;
|
||||
char *fname = NULL;
|
||||
char *format = NULL;
|
||||
long fd = -1;
|
||||
snd_config_foreach(i, conf) {
|
||||
snd_config_t *n = snd_config_entry(i);
|
||||
|
|
@ -408,6 +416,12 @@ int _snd_pcm_file_open(snd_pcm_t **pcmp, char *name,
|
|||
return -EINVAL;
|
||||
continue;
|
||||
}
|
||||
if (strcmp(n->id, "format") == 0) {
|
||||
err = snd_config_string_get(n, &format);
|
||||
if (err < 0)
|
||||
return -EINVAL;
|
||||
continue;
|
||||
}
|
||||
if (strcmp(n->id, "file") == 0) {
|
||||
err = snd_config_string_get(n, &fname);
|
||||
if (err < 0) {
|
||||
|
|
@ -434,7 +448,7 @@ int _snd_pcm_file_open(snd_pcm_t **pcmp, char *name,
|
|||
free(sname);
|
||||
if (err < 0)
|
||||
return err;
|
||||
err = snd_pcm_file_open(pcmp, name, fname, fd, spcm, 1);
|
||||
err = snd_pcm_file_open(pcmp, name, fname, fd, format, spcm, 1);
|
||||
if (err < 0)
|
||||
snd_pcm_close(spcm);
|
||||
return err;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue