mirror of
https://github.com/alsa-project/alsa-lib.git
synced 2025-11-05 13:30:00 -05:00
Better PCM mmap API. Fixed pcm_multi
This commit is contained in:
parent
c4f95f48c3
commit
6a3b962d06
16 changed files with 279 additions and 279 deletions
|
|
@ -44,36 +44,6 @@ size_t page_align(size_t size)
|
|||
return size;
|
||||
}
|
||||
|
||||
snd_pcm_uframes_t snd_pcm_mmap_playback_xfer(snd_pcm_t *pcm, snd_pcm_uframes_t frames)
|
||||
{
|
||||
snd_pcm_uframes_t cont;
|
||||
snd_pcm_uframes_t avail = snd_pcm_mmap_playback_avail(pcm);
|
||||
if (avail < frames)
|
||||
frames = avail;
|
||||
cont = pcm->buffer_size - *pcm->appl_ptr % pcm->buffer_size;
|
||||
if (cont < frames)
|
||||
frames = cont;
|
||||
return frames;
|
||||
}
|
||||
|
||||
snd_pcm_uframes_t snd_pcm_mmap_capture_xfer(snd_pcm_t *pcm, snd_pcm_uframes_t frames)
|
||||
{
|
||||
snd_pcm_uframes_t cont;
|
||||
snd_pcm_uframes_t avail = snd_pcm_mmap_capture_avail(pcm);
|
||||
if (avail < frames)
|
||||
frames = avail;
|
||||
cont = pcm->buffer_size - *pcm->appl_ptr % pcm->buffer_size;
|
||||
if (cont < frames)
|
||||
frames = cont;
|
||||
return frames;
|
||||
}
|
||||
|
||||
snd_pcm_uframes_t snd_pcm_mmap_hw_offset(snd_pcm_t *pcm)
|
||||
{
|
||||
assert(pcm);
|
||||
return *pcm->hw_ptr % pcm->buffer_size;
|
||||
}
|
||||
|
||||
void snd_pcm_mmap_appl_backward(snd_pcm_t *pcm, snd_pcm_uframes_t frames)
|
||||
{
|
||||
snd_pcm_sframes_t appl_ptr = *pcm->appl_ptr;
|
||||
|
|
@ -115,28 +85,18 @@ static snd_pcm_uframes_t snd_pcm_mmap_write_areas(snd_pcm_t *pcm,
|
|||
snd_pcm_uframes_t offset,
|
||||
snd_pcm_uframes_t size)
|
||||
{
|
||||
const snd_pcm_channel_area_t *pcm_areas;
|
||||
snd_pcm_uframes_t pcm_offset;
|
||||
snd_pcm_uframes_t xfer = size;
|
||||
assert(snd_pcm_mmap_playback_avail(pcm) >= size);
|
||||
pcm_areas = snd_pcm_mmap_areas(pcm);
|
||||
pcm_offset = snd_pcm_mmap_offset(pcm);
|
||||
while (size > 0) {
|
||||
const snd_pcm_channel_area_t *pcm_areas;
|
||||
snd_pcm_uframes_t pcm_offset;
|
||||
snd_pcm_uframes_t frames = size;
|
||||
snd_pcm_uframes_t cont = pcm->buffer_size - pcm_offset;
|
||||
int err;
|
||||
if (frames > cont)
|
||||
frames = cont;
|
||||
snd_pcm_mmap_begin(pcm, &pcm_areas, &pcm_offset, &frames);
|
||||
snd_pcm_areas_copy(pcm_areas, pcm_offset,
|
||||
areas, offset,
|
||||
pcm->channels,
|
||||
frames, pcm->format);
|
||||
err = snd_pcm_mmap_forward(pcm, frames);
|
||||
assert(err == (snd_pcm_sframes_t)frames);
|
||||
if (frames == cont)
|
||||
pcm_offset = 0;
|
||||
else
|
||||
pcm_offset += frames;
|
||||
snd_pcm_mmap_commit(pcm, pcm_offset, frames);
|
||||
offset += frames;
|
||||
size -= frames;
|
||||
}
|
||||
|
|
@ -148,28 +108,18 @@ static snd_pcm_uframes_t snd_pcm_mmap_read_areas(snd_pcm_t *pcm,
|
|||
snd_pcm_uframes_t offset,
|
||||
snd_pcm_uframes_t size)
|
||||
{
|
||||
const snd_pcm_channel_area_t *pcm_areas;
|
||||
snd_pcm_uframes_t pcm_offset;
|
||||
snd_pcm_uframes_t xfer = size;
|
||||
assert(snd_pcm_mmap_capture_avail(pcm) >= size);
|
||||
pcm_areas = snd_pcm_mmap_areas(pcm);
|
||||
pcm_offset = snd_pcm_mmap_offset(pcm);
|
||||
while (size > 0) {
|
||||
const snd_pcm_channel_area_t *pcm_areas;
|
||||
snd_pcm_uframes_t pcm_offset;
|
||||
snd_pcm_uframes_t frames = size;
|
||||
snd_pcm_uframes_t cont = pcm->buffer_size - pcm_offset;
|
||||
int err;
|
||||
if (frames > cont)
|
||||
frames = cont;
|
||||
snd_pcm_mmap_begin(pcm, &pcm_areas, &pcm_offset, &frames);
|
||||
snd_pcm_areas_copy(areas, offset,
|
||||
pcm_areas, pcm_offset,
|
||||
pcm->channels,
|
||||
frames, pcm->format);
|
||||
err = snd_pcm_mmap_forward(pcm, frames);
|
||||
assert(err == (snd_pcm_sframes_t)frames);
|
||||
if (frames == cont)
|
||||
pcm_offset = 0;
|
||||
else
|
||||
pcm_offset += frames;
|
||||
snd_pcm_mmap_commit(pcm, pcm_offset, frames);
|
||||
offset += frames;
|
||||
size -= frames;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue