diff mplayer.c @ 32863:674117ab7ce7

Move MPlayer's audio pts calculation code into mp_common.c and reuse it in mencoder. This should improve A-V sync behaviour a lot when re-encoding audio. Patch by Rudolf Polzer [divVerent alientrap org]
author reimar
date Tue, 22 Feb 2011 18:22:16 +0000
parents 607521cb5616
children 5522b2153a0d
line wrap: on
line diff
--- a/mplayer.c	Tue Feb 22 18:18:15 2011 +0000
+++ b/mplayer.c	Tue Feb 22 18:22:16 2011 +0000
@@ -1717,31 +1717,7 @@
 {
     double buffered_output;
     // first calculate the end pts of audio that has been output by decoder
-    double a_pts = sh_audio->pts;
-    if (a_pts != MP_NOPTS_VALUE)
-	// Good, decoder supports new way of calculating audio pts.
-	// sh_audio->pts is the timestamp of the latest input packet with
-	// known pts that the decoder has decoded. sh_audio->pts_bytes is
-	// the amount of bytes the decoder has written after that timestamp.
-	a_pts += sh_audio->pts_bytes / (double) sh_audio->o_bps;
-    else {
-	// Decoder doesn't support new way of calculating pts (or we're
-	// being called before it has decoded anything with known timestamp).
-	// Use the old method of audio pts calculation: take the timestamp
-	// of last packet with known pts the decoder has read data from,
-	// and add amount of bytes read after the beginning of that packet
-	// divided by input bps. This will be inaccurate if the input/output
-	// ratio is not constant for every audio packet or if it is constant
-	// but not accurately known in sh_audio->i_bps.
-
-	a_pts = d_audio->pts;
-	// ds_tell_pts returns bytes read after last timestamp from
-	// demuxing layer, decoder might use sh_audio->a_in_buffer for bytes
-	// it has read but not decoded
-	if (sh_audio->i_bps)
-	    a_pts += (ds_tell_pts(d_audio) - sh_audio->a_in_buffer_len) /
-		(double)sh_audio->i_bps;
-    }
+    double a_pts = calc_a_pts(sh_audio, d_audio);
     // Now a_pts hopefully holds the pts for end of audio from decoder.
     // Substract data in buffers between decoder and audio out.