changeset 34754:9d4720deada1

Use approach used by ao_oss to avoid audio desync when framestepping with ao_alsa and no hardware pause support. This fixes bug #2052.
author reimar
date Thu, 05 Apr 2012 22:29:37 +0000
parents 00ebd36202c6
children 1ce66378ae1e
files libao2/ao_alsa.c libao2/ao_oss.c libao2/audio_out.c libao2/audio_out_internal.h
diffstat 4 files changed, 16 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/libao2/ao_alsa.c	Thu Apr 05 21:59:09 2012 +0000
+++ b/libao2/ao_alsa.c	Thu Apr 05 22:29:37 2012 +0000
@@ -65,6 +65,7 @@
 static size_t bytes_per_sample;
 
 static int alsa_can_pause;
+static int prepause_space;
 
 #define ALSA_DEVICE_SIZE 256
 
@@ -691,6 +692,7 @@
         }
           mp_msg(MSGT_AO,MSGL_V,"alsa-pause: pause supported by hardware\n");
     } else {
+        prepause_space = get_space();
         if ((err = snd_pcm_drop(alsa_handler)) < 0)
         {
             mp_msg(MSGT_AO,MSGL_ERR,MSGTR_AO_ALSA_PcmDropError, snd_strerror(err));
@@ -720,6 +722,7 @@
            mp_msg(MSGT_AO,MSGL_ERR,MSGTR_AO_ALSA_PcmPrepareError, snd_strerror(err));
             return;
         }
+        mp_ao_resume_refill(&audio_out_alsa, prepause_space);
     }
 }
 
--- a/libao2/ao_oss.c	Thu Apr 05 21:59:09 2012 +0000
+++ b/libao2/ao_oss.c	Thu Apr 05 22:29:37 2012 +0000
@@ -473,14 +473,8 @@
 // resume playing, after audio_pause()
 static void audio_resume(void)
 {
-    int fillcnt;
     reset();
-    fillcnt = get_space() - prepause_space;
-    if (fillcnt > 0 && !(ao_data.format & AF_FORMAT_SPECIAL_MASK)) {
-      void *silence = calloc(fillcnt, 1);
-      play(silence, fillcnt, 0);
-      free(silence);
-    }
+    mp_ao_resume_refill(&audio_out_oss, prepause_space);
 }
 
 
--- a/libao2/audio_out.c	Thu Apr 05 21:59:09 2012 +0000
+++ b/libao2/audio_out.c	Thu Apr 05 22:29:37 2012 +0000
@@ -189,3 +189,13 @@
     }
     return NULL;
 }
+
+void mp_ao_resume_refill(const ao_functions_t *ao, int prepause_space)
+{
+    int fillcnt = ao->get_space() - prepause_space;
+    if (fillcnt > 0 && !(ao_data.format & AF_FORMAT_SPECIAL_MASK)) {
+      void *silence = calloc(fillcnt, 1);
+      ao->play(silence, fillcnt, 0);
+      free(silence);
+    }
+}
--- a/libao2/audio_out_internal.h	Thu Apr 05 21:59:09 2012 +0000
+++ b/libao2/audio_out_internal.h	Thu Apr 05 22:29:37 2012 +0000
@@ -45,4 +45,6 @@
 	audio_resume\
 };
 
+void mp_ao_resume_refill(const ao_functions_t *ao, int prepause_space);
+
 #endif /* MPLAYER_AUDIO_OUT_INTERNAL_H */