mirror of
https://github.com/alsa-project/alsa-lib.git
synced 2025-11-04 13:30:08 -05:00
pcm: file: add infile read support for mmap mode
mmap_begin callback is used to copy data from input file to mmaped buffer guard for corner use of api (multiple mmap_begin calls by user) is introduced to check if next continuous buffer was already overwritten buffer is overwritten with input file data only in case of stream capture Signed-off-by: Adam Miartus <amiartus@de.adit-jv.com> Reviewed-by: Timo Wischer <twischer@de.adit-jv.com> Signed-off-by: Takashi Iwai <tiwai@suse.de>
This commit is contained in:
parent
e520f45480
commit
fe7ff721a9
1 changed files with 31 additions and 0 deletions
|
|
@ -88,6 +88,7 @@ typedef struct {
|
|||
size_t buffer_bytes;
|
||||
struct wav_fmt wav_header;
|
||||
size_t filelen;
|
||||
char ifmmap_overwritten;
|
||||
} snd_pcm_file_t;
|
||||
|
||||
#if __BYTE_ORDER == __LITTLE_ENDIAN
|
||||
|
|
@ -630,6 +631,8 @@ static snd_pcm_sframes_t snd_pcm_file_mmap_commit(snd_pcm_t *pcm,
|
|||
const snd_pcm_channel_area_t *areas;
|
||||
snd_pcm_sframes_t result;
|
||||
|
||||
file->ifmmap_overwritten = 0;
|
||||
|
||||
result = snd_pcm_mmap_begin(file->gen.slave, &areas, &ofs, &siz);
|
||||
if (result >= 0) {
|
||||
assert(ofs == offset && siz == size);
|
||||
|
|
@ -640,6 +643,32 @@ static snd_pcm_sframes_t snd_pcm_file_mmap_commit(snd_pcm_t *pcm,
|
|||
return result;
|
||||
}
|
||||
|
||||
static int snd_pcm_file_mmap_begin(snd_pcm_t *pcm, const snd_pcm_channel_area_t **areas,
|
||||
snd_pcm_uframes_t *offset, snd_pcm_uframes_t *frames)
|
||||
{
|
||||
snd_pcm_file_t *file = pcm->private_data;
|
||||
snd_pcm_channel_area_t areas_if[pcm->channels];
|
||||
snd_pcm_uframes_t frames_if;
|
||||
void *buffer = NULL;
|
||||
int result;
|
||||
|
||||
result = snd_pcm_mmap_begin(file->gen.slave, areas, offset, frames);
|
||||
if (result < 0)
|
||||
return result;
|
||||
|
||||
if (pcm->stream != SND_PCM_STREAM_CAPTURE)
|
||||
return result;
|
||||
|
||||
/* user may run mmap_begin without mmap_commit multiple times in row */
|
||||
if (file->ifmmap_overwritten)
|
||||
return result;
|
||||
file->ifmmap_overwritten = 1;
|
||||
|
||||
snd_pcm_file_areas_read_infile(pcm, *areas, *offset, *frames);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static int snd_pcm_file_hw_free(snd_pcm_t *pcm)
|
||||
{
|
||||
snd_pcm_file_t *file = pcm->private_data;
|
||||
|
|
@ -666,6 +695,7 @@ static int snd_pcm_file_hw_params(snd_pcm_t *pcm, snd_pcm_hw_params_t * params)
|
|||
file->wbuf_size = slave->buffer_size * 2;
|
||||
file->wbuf_size_bytes = snd_pcm_frames_to_bytes(slave, file->wbuf_size);
|
||||
file->wbuf_used_bytes = 0;
|
||||
file->ifmmap_overwritten = 0;
|
||||
assert(!file->wbuf);
|
||||
file->wbuf = malloc(file->wbuf_size_bytes);
|
||||
if (file->wbuf == NULL) {
|
||||
|
|
@ -777,6 +807,7 @@ static const snd_pcm_fast_ops_t snd_pcm_file_fast_ops = {
|
|||
.poll_descriptors = snd_pcm_generic_poll_descriptors,
|
||||
.poll_revents = snd_pcm_generic_poll_revents,
|
||||
.htimestamp = snd_pcm_generic_htimestamp,
|
||||
.mmap_begin = snd_pcm_file_mmap_begin,
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue