aboutsummaryrefslogtreecommitdiff
path: root/src/pcm.c
diff options
context:
space:
mode:
authordvdli <dvdli@google.com>2020-12-09 15:45:04 +0800
committerdvdli <dvdli@google.com>2020-12-09 15:49:00 +0800
commit565fc0e3da9bf0ccea99eb4386a4890cdba56134 (patch)
tree03ac552ddc7dd874c233a4c4a15db8d08cc90748 /src/pcm.c
parentf64fb3998ccb438cbda2b8eafa8e33462f1e652d (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/pcm.c')
-rw-r--r--src/pcm.c20
1 files changed, 17 insertions, 3 deletions
diff --git a/src/pcm.c b/src/pcm.c
index 17775d5..169d982 100644
--- a/src/pcm.c
+++ b/src/pcm.c
@@ -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. */