[MPlayer-dev-eng] [PATCH] audio dropping

Reimar Döffinger Reimar.Doeffinger at stud.uni-karlsruhe.de
Mon Nov 6 22:59:31 CET 2006


Hello,
On Mon, Nov 06, 2006 at 06:52:23PM +0100, Reimar D?ffinger wrote:
> the attached patch implements audio dropping if audio is too far behind
> video, e.g. when using -delay 10. This also (except for the large
> startup delay) fixes http://bugzilla.mplayerhq.hu/show_bug.cgi?id=609
> Like this it would be enabled by default, heavy testing will be needed
> to see if this is a good idea.
> If there are no objections I will apply soon.

Alternative, more complicated but also more precise version.

Greetings,
Reimar Döffinger
-------------- next part --------------
Index: mplayer.c
===================================================================
--- mplayer.c	(revision 20725)
+++ mplayer.c	(working copy)
@@ -312,6 +312,7 @@
        float force_fps=0;
 static int force_srate=0;
 static int audio_output_format=0;
+static int audio_dropping=1;
        int frame_dropping=0; // option  0=no drop  1= drop vo  2= drop decode
 static int play_n_frames=-1;
 static int play_n_frames_mf=-1;
@@ -4064,6 +4065,7 @@
   int playsize;
   int playflags=0;
   int audio_eof=0;
+  double delay;
 
   current_module="play_audio";
   
@@ -4082,6 +4084,23 @@
   // Fill buffer if needed:
   current_module="decode_audio";   // Enter AUDIO decoder module
   t=GetTimer();
+  delay = playback_speed * audio_out->get_delay() - sh_audio->delay;
+  if (audio_dropping && sh_video && !frame_time_remaining && delay > 1.0) {
+    while (delay > 0) {
+      int ret = 0;
+      int dropsize = delay * ao_data.bps - sh_audio->a_out_buffer_len;
+      double corr;
+      sh_audio->a_out_buffer_len = 0;
+      if (dropsize > MAX_OUTBURST) dropsize = MAX_OUTBURST;
+      if (dropsize > 0)
+        ret = decode_audio(sh_audio, sh_audio->a_out_buffer, dropsize, sh_audio->a_out_buffer_size);
+      if (ret <= 0)
+        break;
+      corr = playback_speed * ret / (double)ao_data.bps;
+      sh_audio->delay += corr;
+      delay -= corr;
+    }
+  }
   while (sh_audio->a_out_buffer_len < playsize) {
     int ret=decode_audio(sh_audio,&sh_audio->a_out_buffer[sh_audio->a_out_buffer_len],
         playsize-sh_audio->a_out_buffer_len,sh_audio->a_out_buffer_size-sh_audio->a_out_buffer_len);
Index: cfg-mplayer.h
===================================================================
--- cfg-mplayer.h	(revision 20725)
+++ cfg-mplayer.h	(working copy)
@@ -305,6 +305,8 @@
 	{"framedrop", &frame_dropping, CONF_TYPE_FLAG, 0, 0, 1, NULL},
 	{"hardframedrop", &frame_dropping, CONF_TYPE_FLAG, 0, 0, 2, NULL},
 	{"noframedrop", &frame_dropping, CONF_TYPE_FLAG, 0, 1, 0, NULL},
+	{"audiodrop", &audio_dropping, CONF_TYPE_FLAG, 0, 0, 1, NULL},
+	{"noaudiodrop", &audio_dropping, CONF_TYPE_FLAG, 0, 1, 0, NULL},
 
 	{"autoq", &auto_quality, CONF_TYPE_INT, CONF_RANGE, 0, 100, NULL},
 
Index: DOCS/man/en/mplayer.1
===================================================================
--- DOCS/man/en/mplayer.1	(revision 20725)
+++ DOCS/man/en/mplayer.1	(working copy)
@@ -690,6 +690,11 @@
 .SH "PLAYER OPTIONS (MPLAYER ONLY)"
 .
 .TP
+.B \-(no)audiodrop
+Skip audio playback if audio is too far behind video.
+Useful especially with large \-delay values.
+.
+.TP
 .B \-autoq <quality> (use with \-vf [s]pp)
 Dynamically changes the level of postprocessing depending on the available spare
 CPU time.


More information about the MPlayer-dev-eng mailing list