mirror of
https://github.com/alsa-project/alsa-lib.git
synced 2025-10-31 22:25:35 -04:00
Enhanced snd_pcm_mmap_read/write_areas to support the blocking behaviour.
Removed wrong asserts.
This commit is contained in:
parent
711a344fa4
commit
808fb82d1f
1 changed files with 30 additions and 14 deletions
|
|
@ -86,19 +86,27 @@ static snd_pcm_uframes_t snd_pcm_mmap_write_areas(snd_pcm_t *pcm,
|
||||||
snd_pcm_uframes_t size)
|
snd_pcm_uframes_t size)
|
||||||
{
|
{
|
||||||
snd_pcm_uframes_t xfer = size;
|
snd_pcm_uframes_t xfer = size;
|
||||||
assert(snd_pcm_mmap_playback_avail(pcm) >= size);
|
int res;
|
||||||
while (size > 0) {
|
while (size > 0) {
|
||||||
const snd_pcm_channel_area_t *pcm_areas;
|
const snd_pcm_channel_area_t *pcm_areas;
|
||||||
snd_pcm_uframes_t pcm_offset;
|
snd_pcm_uframes_t pcm_offset;
|
||||||
snd_pcm_uframes_t frames = size;
|
snd_pcm_uframes_t frames = size;
|
||||||
snd_pcm_mmap_begin(pcm, &pcm_areas, &pcm_offset, &frames);
|
snd_pcm_mmap_begin(pcm, &pcm_areas, &pcm_offset, &frames);
|
||||||
snd_pcm_areas_copy(pcm_areas, pcm_offset,
|
if (frames > 0)
|
||||||
areas, offset,
|
snd_pcm_areas_copy(pcm_areas, pcm_offset,
|
||||||
pcm->channels,
|
areas, offset,
|
||||||
frames, pcm->format);
|
pcm->channels,
|
||||||
|
frames, pcm->format);
|
||||||
snd_pcm_mmap_commit(pcm, pcm_offset, frames);
|
snd_pcm_mmap_commit(pcm, pcm_offset, frames);
|
||||||
offset += frames;
|
if (frames == 0) {
|
||||||
size -= frames;
|
if (pcm->mode & SND_PCM_NONBLOCK)
|
||||||
|
return xfer;
|
||||||
|
if ((res = snd_pcm_wait(pcm, -1)) < 0)
|
||||||
|
return xfer > 0 ? xfer : res;
|
||||||
|
} else {
|
||||||
|
offset += frames;
|
||||||
|
size -= frames;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return xfer;
|
return xfer;
|
||||||
}
|
}
|
||||||
|
|
@ -109,19 +117,27 @@ static snd_pcm_uframes_t snd_pcm_mmap_read_areas(snd_pcm_t *pcm,
|
||||||
snd_pcm_uframes_t size)
|
snd_pcm_uframes_t size)
|
||||||
{
|
{
|
||||||
snd_pcm_uframes_t xfer = size;
|
snd_pcm_uframes_t xfer = size;
|
||||||
assert(snd_pcm_mmap_capture_avail(pcm) >= size);
|
int res;
|
||||||
while (size > 0) {
|
while (size > 0) {
|
||||||
const snd_pcm_channel_area_t *pcm_areas;
|
const snd_pcm_channel_area_t *pcm_areas;
|
||||||
snd_pcm_uframes_t pcm_offset;
|
snd_pcm_uframes_t pcm_offset;
|
||||||
snd_pcm_uframes_t frames = size;
|
snd_pcm_uframes_t frames = size;
|
||||||
snd_pcm_mmap_begin(pcm, &pcm_areas, &pcm_offset, &frames);
|
snd_pcm_mmap_begin(pcm, &pcm_areas, &pcm_offset, &frames);
|
||||||
snd_pcm_areas_copy(areas, offset,
|
if (frames > 0)
|
||||||
pcm_areas, pcm_offset,
|
snd_pcm_areas_copy(areas, offset,
|
||||||
pcm->channels,
|
pcm_areas, pcm_offset,
|
||||||
frames, pcm->format);
|
pcm->channels,
|
||||||
|
frames, pcm->format);
|
||||||
snd_pcm_mmap_commit(pcm, pcm_offset, frames);
|
snd_pcm_mmap_commit(pcm, pcm_offset, frames);
|
||||||
offset += frames;
|
if (frames == 0) {
|
||||||
size -= frames;
|
if (pcm->mode & SND_PCM_NONBLOCK)
|
||||||
|
return xfer;
|
||||||
|
if ((res = snd_pcm_wait(pcm, -1)) < 0)
|
||||||
|
return xfer > 0 ? xfer : res;
|
||||||
|
} else {
|
||||||
|
offset += frames;
|
||||||
|
size -= frames;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return xfer;
|
return xfer;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue