aboutsummaryrefslogtreecommitdiff
path: root/src/pcm.c
diff options
context:
space:
mode:
authorRicardo Biehl Pasquali <pasqualirb@gmail.com>2018-12-22 11:17:32 -0200
committerRicardo Biehl Pasquali <pasqualirb@gmail.com>2019-01-08 16:48:19 -0200
commitd759f4801789c6c83174a5eca474b59eda3e8090 (patch)
tree8016c19d1f5b1aa5e55671d3242e150157a40324 /src/pcm.c
parente45431eab4840a48ca62c3e5ef49fe46dac75a48 (diff)
pcm: Put mmap functions together
pcm_mmap_transfer() will be rewritten. Put together functions related to mmap transfer. Signed-off-by: Ricardo Biehl Pasquali <pasqualirb@gmail.com>
Diffstat (limited to 'src/pcm.c')
-rw-r--r--src/pcm.c88
1 files changed, 44 insertions, 44 deletions
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);