Skip to contentSkip to conversation

pcm: fix snd_pcm_mmap_hw_avail() near the boundary

PATCH In review Alexander E. Patrakov 2 participants 2 messages Aug 31, 2014 – Sep 1, 2014

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 pcm: fix snd_pcm_mmap_hw_avail() near the boundary

This function returned incorrect results when hw.ptr was near the boundary and hw.appl_ptr was near zero. Here "incorrect" means "greater than the boundary".

The result was incorrect, because it was used as a return value of various *_rewindable() functions and also as the delay for ioplug.

---
 src/pcm/pcm_local.h | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)
src/pcm/pcm_local.h +1 -7
index 80bbe59..74ebd60 100644
@@ -461,13 +461,7 @@ static inline snd_pcm_sframes_t snd_pcm_mmap_capture_hw_avail(snd_pcm_t *pcm)
 
 static inline snd_pcm_sframes_t snd_pcm_mmap_hw_avail(snd_pcm_t *pcm)
 {
-	snd_pcm_sframes_t avail;
-	avail = *pcm->hw.ptr - *pcm->appl.ptr;
-	if (pcm->stream == SND_PCM_STREAM_PLAYBACK)
-		avail += pcm->buffer_size;
-	if (avail < 0)
-		avail += pcm->boundary;
-	return pcm->buffer_size - avail;
+	return pcm->buffer_size - snd_pcm_mmap_avail(pcm);
 }
 
 static inline const snd_pcm_channel_area_t *snd_pcm_mmap_areas(snd_pcm_t *pcm)
Signature · 1 line
2.1.0
#1 lore raw

At Sun, 31 Aug 2014 22:23:47 +0600,

Quoted 9 lines · Alexander E. Patrakov

This function returned incorrect results when hw.ptr was near the boundary and hw.appl_ptr was near zero. Here "incorrect" means "greater than the boundary".

The result was incorrect, because it was used as a return value of various *_rewindable() functions and also as the delay for ioplug.

Hrm, the very early version of snd_pcm_mmap_hw_avail() was correctly implemented:

static inline ssize_t snd_pcm_mmap_hw_avail(snd_pcm_t *pcm)

{
       if (pcm->stream == SND_PCM_STREAM_PLAYBACK)
               return snd_pcm_mmap_playback_hw_avail(pcm);
       else
               return snd_pcm_mmap_capture_hw_avail(pcm);
}

Since the commit 9a435c2d934a, the breakage was introduced there. I have no idea what and why this was done so, it's a really old commit more than a decade ago.

In anyway, your fix look good and simple, so I applied it as is now, instead of reverting to the old version above.

BTW, at the next done, don't forget to put maintainers to Cc.

thanks,

Takashi

Quoted 31 lines
---
 src/pcm/pcm_local.h | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)
src/pcm/pcm_local.h +1 -7
index 80bbe59..74ebd60 100644
@@ -461,13 +461,7 @@ static inline snd_pcm_sframes_t snd_pcm_mmap_capture_hw_avail(snd_pcm_t *pcm)
 
 static inline snd_pcm_sframes_t snd_pcm_mmap_hw_avail(snd_pcm_t *pcm)
 {
-	snd_pcm_sframes_t avail;
-	avail = *pcm->hw.ptr - *pcm->appl.ptr;
-	if (pcm->stream == SND_PCM_STREAM_PLAYBACK)
-		avail += pcm->buffer_size;
-	if (avail < 0)
-		avail += pcm->boundary;
-	return pcm->buffer_size - avail;
+	return pcm->buffer_size - snd_pcm_mmap_avail(pcm);
 }
 
 static inline const snd_pcm_channel_area_t *snd_pcm_mmap_areas(snd_pcm_t *pcm)
Signature · 6 lines
2.1.0

_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel