aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordvdli <70133153+dvdli@users.noreply.github.com>2020-11-04 13:53:36 +0800
committerGitHub <noreply@github.com>2020-11-04 13:53:36 +0800
commit40867609e738919872c88b7716b17c30d96211a4 (patch)
tree297fc1ca9c26be966bed88bfa8f5105ae76ae3cf
parent69855f3dfd8b552551285aeb8747f2e1bdaf4bf8 (diff)
parent4655fedee7c0f28bd0333fe89e5fd276a1276132 (diff)
Merge pull request #189 from wksuper/master
Backward compatible for pcm_write() pcm_read()
-rw-r--r--src/pcm.c17
1 files changed, 14 insertions, 3 deletions
diff --git a/src/pcm.c b/src/pcm.c
index b592780..352ddc6 100644
--- a/src/pcm.c
+++ b/src/pcm.c
@@ -1706,7 +1706,13 @@ int pcm_readi(struct pcm *pcm, void *data, unsigned int frame_count)
*/
int pcm_write(struct pcm *pcm, const void *data, unsigned int count)
{
- return pcm_writei(pcm, data, pcm_bytes_to_frames(pcm, count));
+ unsigned int requested_frames = pcm_bytes_to_frames(pcm, count);
+ int ret = pcm_writei(pcm, data, requested_frames);
+
+ if (ret < 0)
+ return ret;
+
+ return ((unsigned int )ret == requested_frames) ? 0 : -EIO;
}
/** Reads audio samples from PCM.
@@ -1722,7 +1728,13 @@ int pcm_write(struct pcm *pcm, const void *data, unsigned int count)
*/
int pcm_read(struct pcm *pcm, void *data, unsigned int count)
{
- return pcm_readi(pcm, data, pcm_bytes_to_frames(pcm, count));
+ unsigned int requested_frames = pcm_bytes_to_frames(pcm, count);
+ int ret = pcm_readi(pcm, data, requested_frames);
+
+ if (ret < 0)
+ return ret;
+
+ return ((unsigned int )ret == requested_frames) ? 0 : -EIO;
}
/** Gets the delay of the PCM, in terms of frames.
@@ -1738,4 +1750,3 @@ long pcm_get_delay(struct pcm *pcm)
return pcm->pcm_delay;
}
-