From d759f4801789c6c83174a5eca474b59eda3e8090 Mon Sep 17 00:00:00 2001 From: Ricardo Biehl Pasquali Date: Sat, 22 Dec 2018 11:17:32 -0200 Subject: pcm: Put mmap functions together pcm_mmap_transfer() will be rewritten. Put together functions related to mmap transfer. Signed-off-by: Ricardo Biehl Pasquali --- src/pcm.c | 88 +++++++++++++++++++++++++++++++-------------------------------- 1 file changed, 44 insertions(+), 44 deletions(-) (limited to 'src') diff --git a/src/pcm.c b/src/pcm.c index d037f8d..e6f3b48 100644 --- a/src/pcm.c +++ b/src/pcm.c @@ -587,50 +587,6 @@ static void pcm_hw_munmap_status(struct pcm *pcm) { pcm->mmap_control = NULL; } -static int pcm_areas_copy(struct pcm *pcm, unsigned int pcm_offset, - char *buf, unsigned int src_offset, - unsigned int frames) -{ - int size_bytes = pcm_frames_to_bytes(pcm, frames); - int pcm_offset_bytes = pcm_frames_to_bytes(pcm, pcm_offset); - int src_offset_bytes = pcm_frames_to_bytes(pcm, src_offset); - - /* interleaved only atm */ - if (pcm->flags & PCM_IN) - memcpy(buf + src_offset_bytes, - (char*)pcm->mmap_buffer + pcm_offset_bytes, - size_bytes); - else - memcpy((char*)pcm->mmap_buffer + pcm_offset_bytes, - buf + src_offset_bytes, - size_bytes); - return 0; -} - -static int pcm_mmap_transfer_areas(struct pcm *pcm, char *buf, - unsigned int offset, unsigned int size) -{ - void *pcm_areas; - int commit; - unsigned int pcm_offset, frames, count = 0; - - while (size > 0) { - frames = size; - pcm_mmap_begin(pcm, &pcm_areas, &pcm_offset, &frames); - pcm_areas_copy(pcm, pcm_offset, buf, offset, frames); - commit = pcm_mmap_commit(pcm, pcm_offset, frames); - if (commit < 0) { - oops(pcm, commit, "failed to commit %d frames\n", frames); - return commit; - } - - offset += commit; - count += commit; - size -= commit; - } - return count; -} - /** Writes audio samples to PCM. * If the PCM has not been started, it is started in this function. * This function is only valid for PCMs opened with the @ref PCM_OUT flag. @@ -1258,6 +1214,26 @@ int pcm_mmap_begin(struct pcm *pcm, void **areas, unsigned int *offset, return 0; } +static int pcm_areas_copy(struct pcm *pcm, unsigned int pcm_offset, + char *buf, unsigned int src_offset, + unsigned int frames) +{ + int size_bytes = pcm_frames_to_bytes(pcm, frames); + int pcm_offset_bytes = pcm_frames_to_bytes(pcm, pcm_offset); + int src_offset_bytes = pcm_frames_to_bytes(pcm, src_offset); + + /* interleaved only atm */ + if (pcm->flags & PCM_IN) + memcpy(buf + src_offset_bytes, + (char*)pcm->mmap_buffer + pcm_offset_bytes, + size_bytes); + else + memcpy((char*)pcm->mmap_buffer + pcm_offset_bytes, + buf + src_offset_bytes, + size_bytes); + return 0; +} + int pcm_mmap_commit(struct pcm *pcm, unsigned int offset, unsigned int frames) { int ret; @@ -1276,6 +1252,30 @@ int pcm_mmap_commit(struct pcm *pcm, unsigned int offset, unsigned int frames) return frames; } +static int pcm_mmap_transfer_areas(struct pcm *pcm, char *buf, + unsigned int offset, unsigned int size) +{ + void *pcm_areas; + int commit; + unsigned int pcm_offset, frames, count = 0; + + while (size > 0) { + frames = size; + pcm_mmap_begin(pcm, &pcm_areas, &pcm_offset, &frames); + pcm_areas_copy(pcm, pcm_offset, buf, offset, frames); + commit = pcm_mmap_commit(pcm, pcm_offset, frames); + if (commit < 0) { + oops(pcm, commit, "failed to commit %d frames\n", frames); + return commit; + } + + offset += commit; + count += commit; + size -= commit; + } + return count; +} + int pcm_avail_update(struct pcm *pcm) { pcm_sync_ptr(pcm, SNDRV_PCM_SYNC_PTR_APPL|SNDRV_PCM_SYNC_PTR_AVAIL_MIN); -- cgit v1.2.3