[MPlayer-dev-eng] [PATCH] Playing final chunk of audio

Reimar Döffinger Reimar.Doeffinger at gmx.de
Sun Oct 17 15:27:26 CEST 2010


On Sun, Oct 17, 2010 at 01:10:43PM +0200, Marek Dopiera wrote:
> Index: libao2/ao_sun.c
> ===================================================================
> --- libao2/ao_sun.c	(wersja 32499)
> +++ libao2/ao_sun.c	(kopia robocza)
> @@ -665,7 +665,14 @@
>  // it should round it down to outburst*n
>  // return: number of bytes played
>  static int play(void* data,int len,int flags){
> -    if (len < ao_data.outburst) return 0;
> +	if (len < ao_data.outburst && !(flags & AOPLAY_FINAL_CHUNK)) return 0;
> +	if (len < ao_data.outburst && (flags & AOPLAY_FINAL_CHUNK)) {
> +		//in such a case try to write, but if it fails, just return 0
> +		len = write(audio_fd, data, len);
> +		if (len <= 0)
> +			return 0;
> +	}
> +

It should just ignore errors, for low bitrate streams (8kHz mono), it
will lose over one second. That's not just a minor issue that can be ignored.
Below patch should work:
Index: libao2/ao_sun.c
===================================================================
--- libao2/ao_sun.c     (revision 32499)
+++ libao2/ao_sun.c     (working copy)
@@ -665,9 +665,11 @@
 // it should round it down to outburst*n
 // return: number of bytes played
 static int play(void* data,int len,int flags){
-    if (len < ao_data.outburst) return 0;
+    if (!(flags & AOPLAY_FINAL_CHUNK)) {
     len /= ao_data.outburst;
     len *= ao_data.outburst;
+    }
+    if (len <= 0) return 0;
 
     len = write(audio_fd, data, len);
     if(len > 0) {


> Index: mplayer.c
> ===================================================================
> --- mplayer.c	(wersja 32499)
> +++ mplayer.c	(kopia robocza)
> @@ -2190,7 +2190,7 @@
>  		    sh_audio->a_out_buffer_len);
>  	    mpctx->delay += playback_speed*playsize/(double)ao_data.bps;
>  	}
> -	else if ((format_change || audio_eof) && mpctx->audio_out->get_delay() < .04) {
> +	else if (format_change || audio_eof) {
>  	    // Sanity check to avoid hanging in case current ao doesn't output
>  	    // partial chunks and doesn't check for AOPLAY_FINAL_CHUNK
>  	    mp_msg(MSGT_CPLAYER, MSGL_WARN, "Audio output truncated at end.\n");

If that makes a real difference, the get_delay function is broken to the point
of being useless and should be fixed (unless ao_sun really has a absolute minimum
latency of 40 ms).


More information about the MPlayer-dev-eng mailing list