[MPlayer-cvslog] CVS: main/libao2 ao_alsa.c,1.27,1.28

Clemens Ladisch CVS syncmail at mplayerhq.hu
Fri Feb 10 10:24:51 CET 2006


CVS change done by Clemens Ladisch CVS

Update of /cvsroot/mplayer/main/libao2
In directory mail:/var2/tmp/cvs-serv32457/libao2

Modified Files:
	ao_alsa.c 
Log Message:
Simplify get_delay(): we don't need to get the complete PCM status but
can call snd_pcm_delay() directly.

To avoid the audio device appearing to be running too fast after an
underrun, ignore any samples that were lost in an underrun.

Index: ao_alsa.c
===================================================================
RCS file: /cvsroot/mplayer/main/libao2/ao_alsa.c,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -r1.27 -r1.28
--- ao_alsa.c	10 Feb 2006 09:21:17 -0000	1.27
+++ ao_alsa.c	10 Feb 2006 09:24:48 -0000	1.28
@@ -1037,35 +1037,20 @@
 /* delay in seconds between first and last sample in buffer */
 static float get_delay(void)
 {
-
   if (alsa_handler) {
-
-    snd_pcm_status_t *status;
-    float ret;
+    snd_pcm_sframes_t delay;
     
-    snd_pcm_status_alloca(&status);
+    if (snd_pcm_delay(alsa_handler, &delay) < 0)
+      return 0;
     
-    if ((ret = snd_pcm_status(alsa_handler, status)) < 0)
-    {
-	mp_msg(MSGT_AO,MSGL_ERR,"alsa-delay: cannot get pcm status: %s\n", snd_strerror(ret));
+    if (delay < 0) {
+      /* underrun - move the application pointer forward to catch up */
+#if SND_LIB_VERSION >= 0x000901 /* snd_pcm_forward() exists since 0.9.0rc8 */
+      snd_pcm_forward(alsa_handler, -delay);
+#endif
+      delay = 0;
     }
-    
-    switch(snd_pcm_status_get_state(status))
-    {
-	case SND_PCM_STATE_OPEN:
-	case SND_PCM_STATE_PREPARED:
-	case SND_PCM_STATE_RUNNING:
-	    ret = (float)snd_pcm_status_get_delay(status)/(float)ao_data.samplerate;
-	    break;
-	default:
-	    ret = 0;
-    }
-    
-
-    if (ret < 0)
-      ret = 0;
-    return(ret);
-    
+    return (float)delay / (float)ao_data.samplerate;
   } else {
     return(0);
   }




More information about the MPlayer-cvslog mailing list