diff options
author | dvdli <dvdli@google.com> | 2020-12-09 15:45:04 +0800 |
---|---|---|
committer | dvdli <dvdli@google.com> | 2020-12-09 15:49:00 +0800 |
commit | 565fc0e3da9bf0ccea99eb4386a4890cdba56134 (patch) | |
tree | 03ac552ddc7dd874c233a4c4a15db8d08cc90748 /src | |
parent | f64fb3998ccb438cbda2b8eafa8e33462f1e652d (diff) |
fix mmap-related functions' bugs
1. sync hw ptr before calculating the avail
2. return zero when reading or writing successfully
Diffstat (limited to 'src')
-rw-r--r-- | src/pcm.c | 20 |
1 files changed, 17 insertions, 3 deletions
@@ -1242,6 +1242,7 @@ static inline int pcm_mmap_capture_avail(struct pcm *pcm) int pcm_mmap_avail(struct pcm *pcm) { + pcm_sync_ptr(pcm, SNDRV_PCM_SYNC_PTR_HWSYNC); if (pcm->flags & PCM_IN) return pcm_mmap_capture_avail(pcm); else @@ -1552,8 +1553,14 @@ int pcm_mmap_write(struct pcm *pcm, const void *data, unsigned int count) if ((~pcm->flags) & (PCM_OUT | PCM_MMAP)) return -ENOSYS; - return pcm_mmap_transfer(pcm, (void *)data, - pcm_bytes_to_frames(pcm, count)); + unsigned int frames = pcm_bytes_to_frames(pcm, count); + int res = pcm_mmap_transfer(pcm, (void *) data, frames); + + if (res < 0) { + return res; + } + + return (unsigned int) res == frames ? 0 : -EIO; } int pcm_mmap_read(struct pcm *pcm, void *data, unsigned int count) @@ -1561,7 +1568,14 @@ int pcm_mmap_read(struct pcm *pcm, void *data, unsigned int count) if ((~pcm->flags) & (PCM_IN | PCM_MMAP)) return -ENOSYS; - return pcm_mmap_transfer(pcm, data, pcm_bytes_to_frames(pcm, count)); + unsigned int frames = pcm_bytes_to_frames(pcm, count); + int res = pcm_mmap_transfer(pcm, data, frames); + + if (res < 0) { + return res; + } + + return (unsigned int) res == frames ? 0 : -EIO; } /* Returns current read/write position in the mmap buffer with associated time stamp. */ |