[MPlayer-users] Disable audio when using "." to step forward in a movie

Reimar Döffinger Reimar.Doeffinger at stud.uni-karlsruhe.de
Mon Feb 16 19:35:43 CET 2009


On Mon, Feb 16, 2009 at 06:59:23PM +0100, Reimar Döffinger wrote:
> Well, there is also e.g. OSS and JACK, I think they don't have the
> issue.
> I also made a patch for that ALSA issue a long time ago (long enough
> that I neither have it on hand nor do I know what issues it had - it
> should be in the -dev-eng archives somewhere though).

Correction: I made the patch for OSS and it was already applied.
You can try attached patch for ALSA, though it will not help for e.g.
AC3 passthrough.
The reason why disabling sound during '.' does not make much sense is
because
1) it is simply implemented as a unpause, pause command
2) the issues still exists the same way when someone quickly
pauses/unpauses

Greetings,
Reimar Döffinger
-------------- next part --------------
diff --git a/libao2/ao_alsa.c b/libao2/ao_alsa.c
index 6d2e1f9..7c77e40 100644
--- a/libao2/ao_alsa.c
+++ b/libao2/ao_alsa.c
@@ -84,6 +84,7 @@ static int ao_noblock = 0;
 
 static int open_mode;
 static int alsa_can_pause = 0;
+static float onpause_delay;
 
 #define ALSA_DEVICE_SIZE 256
 
@@ -759,6 +760,7 @@ static void audio_pause(void)
 {
     int err;
 
+    onpause_delay = get_delay();
     if (alsa_can_pause) {
         if ((err = snd_pcm_pause(alsa_handler, 1)) < 0)
         {
@@ -777,6 +779,7 @@ static void audio_pause(void)
 
 static void audio_resume(void)
 {
+    int delay_bytes;
     int err;
 
     if (snd_pcm_state(alsa_handler) == SND_PCM_STATE_SUSPENDED) {
@@ -797,6 +800,16 @@ static void audio_resume(void)
             return;
         }
     }
+    // try to restore the same delay value as before pause
+    // delay difference in samples
+    delay_bytes = (onpause_delay - get_delay()) * ao_data.samplerate;
+    // convert to bytes
+    delay_bytes *= ao_data.channels * bytes_per_sample;
+    if (delay_bytes > 0 && !(ao_data.format & AF_FORMAT_SPECIAL_MASK)) {
+        void *silence = calloc(1, delay_bytes);
+        play(silence, delay_bytes, 0);
+        free(silence);
+    }
 }
 
 /* stop playing and empty buffers (for seeking/pause) */
@@ -809,6 +822,7 @@ static void reset(void)
 	mp_msg(MSGT_AO,MSGL_ERR,MSGTR_AO_ALSA_PcmPrepareError, snd_strerror(err));
 	return;
     }
+    onpause_delay = 0;
     if ((err = snd_pcm_prepare(alsa_handler)) < 0)
     {
 	mp_msg(MSGT_AO,MSGL_ERR,MSGTR_AO_ALSA_PcmPrepareError, snd_strerror(err));


More information about the MPlayer-users mailing list