[MPlayer-dev-eng] [PATCH] -vf fixpts=use_timer

Reimar Döffinger Reimar.Doeffinger at gmx.de
Mon Feb 21 19:27:17 CET 2011


On Sat, Jul 24, 2010 at 10:59:31PM +0200, Rudolf Polzer wrote:
> On Wed, Jul 21, 2010 at 07:55:43PM +0200, Reimar Döffinger wrote:
> > On Wed, Jul 21, 2010 at 02:10:24PM +0200, Rudolf Polzer wrote:
> > > On Tue, Jul 20, 2010 at 07:28:08PM +0200, Reimar Döffinger wrote:
> > > > Oh, and if it's the same code, actually reusing it would be far better
> > > > than copying it.
> > > 
> > > It is not entirely the same, the functions differ because no adjustment to
> > > playback speed, or AO buffer size is done. But yes, the common parts (i.e.:
> > > what I added to mencoder.c) could be merged into one function. Just no idea
> > > where it would belong.
> > 
> > It's getting a bit messy there, but in lack of a better idea mpcommon.[c|h] should
> > do.
> 
> Attached.

Sorry for forgetting about this, if nobody objects I intend to apply soon
(tomorrow maybe?)

> diff --git a/mencoder.c b/mencoder.c
> index 227e876..1c5806b 100644
> --- a/mencoder.c
> +++ b/mencoder.c
> @@ -146,7 +146,6 @@ double cur_vout_time_usage=0;
>  int benchmark=0;
>  
>  // A-V sync:
> -int delay_corrected=1;
>  static float default_max_pts_correction=-1;//0.01f;
>  static float max_pts_correction=0;//default_max_pts_correction;
>  static float c_total=0;
> @@ -381,23 +380,13 @@ static float stop_time(demuxer_t* demuxer, muxer_stream_t* mux_v)
>  	return timeleft;
>  }
>  
> -/// Returns a_pts
> -static float calc_a_pts(demux_stream_t *d_audio)
> -{
> -    sh_audio_t * sh_audio = d_audio ? d_audio->sh : NULL;
> -    float a_pts = 0.;
> -    if (sh_audio)
> -        a_pts = d_audio->pts + (ds_tell_pts(d_audio) - sh_audio->a_in_buffer_len)/(float)sh_audio->i_bps;
> -    return a_pts;
> -}
> -
>  /** \brief Seeks audio forward to pts by dumping audio packets
>   *  \return The current audio pts. */
>  static float forward_audio(float pts, demux_stream_t *d_audio, muxer_stream_t* mux_a)
>  {
>      sh_audio_t * sh_audio = d_audio ? d_audio->sh : NULL;
>      int samplesize, avg;
> -    float a_pts = calc_a_pts(d_audio);
> +    float a_pts = calc_a_pts(sh_audio, d_audio);
>  
>      if (!sh_audio) return a_pts;
>  
> @@ -409,7 +398,7 @@ static float forward_audio(float pts, demux_stream_t *d_audio, muxer_stream_t* m
>      // carefully checking if a_pts is truely correct by reading tiniest amount of data possible.
>      if (pts > a_pts && a_pts == 0.0 && samplesize) {
>          if (demux_read_data(sh_audio->ds,mux_a->buffer,samplesize) <= 0) return a_pts; // EOF
> -        a_pts = calc_a_pts(d_audio);
> +        a_pts = calc_a_pts(sh_audio, d_audio);
>      }
>  
>      while (pts > a_pts) {
> @@ -424,7 +413,7 @@ static float forward_audio(float pts, demux_stream_t *d_audio, muxer_stream_t* m
>              len = ds_get_packet(sh_audio->ds, &crap);
>          }
>          if (len <= 0) break; // EOF of audio.
> -        a_pts = calc_a_pts(d_audio);
> +        a_pts = calc_a_pts(sh_audio, d_audio);
>      }
>      return a_pts;
>  }
> @@ -1585,14 +1574,11 @@ if(sh_audio && !demuxer2){
>            ((ds_tell(d_audio)-sh_audio->a_in_buffer_len)/sh_audio->audio.dwSampleSize) :
>            (d_audio->block_no); // <- used for VBR audio
>          a_pts=samples*(float)sh_audio->audio.dwScale/(float)sh_audio->audio.dwRate;
> -      delay_corrected=1;
>      } else
>  #endif
>      {
>        // PTS = (last timestamp) + (bytes after last timestamp)/(bytes per sec)
> -      a_pts=d_audio->pts;
> -      if(!delay_corrected) if(a_pts) delay_corrected=1;
> -      a_pts+=(ds_tell_pts(d_audio)-sh_audio->a_in_buffer_len)/(float)sh_audio->i_bps;
> +      a_pts=calc_a_pts(sh_audio, d_audio);
>      }
>      v_pts=sh_video ? sh_video->pts : d_video->pts;
>      // av = compensated (with out buffering delay) A-V diff
> diff --git a/mpcommon.c b/mpcommon.c
> index 8b993ff..7c4a0b0 100644
> --- a/mpcommon.c
> +++ b/mpcommon.c
> @@ -345,3 +345,37 @@ const m_option_t noconfig_opts[] = {
>      {NULL, NULL, 0, 0, 0, 0, NULL}
>  };
>  
> +/// Returns a_pts
> +double calc_a_pts(sh_audio_t *sh_audio, demux_stream_t *d_audio)
> +{
> +    if(!sh_audio || !d_audio)
> +	return MP_NOPTS_VALUE;
> +    // 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;
> +    }
> +
> +    return a_pts;
> +}
> diff --git a/mpcommon.h b/mpcommon.h
> index 5150ce2..2a4b6c3 100644
> --- a/mpcommon.h
> +++ b/mpcommon.h
> @@ -46,4 +46,6 @@ void set_osd_subtitle(subtitle *subs);
>  extern int disable_system_conf;
>  extern int disable_user_conf;
>  
> +double calc_a_pts(sh_audio_t *sh_audio, demux_stream_t *d_audio);
> +
>  #endif /* MPLAYER_MPCOMMON_H */
> diff --git a/mplayer.c b/mplayer.c
> index 9ac8dc7..5984754 100644
> --- a/mplayer.c
> +++ b/mplayer.c
> @@ -1726,31 +1726,7 @@ static double written_audio_pts(sh_audio_t *sh_audio, demux_stream_t *d_audio)
>  {
>      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.
>  


More information about the MPlayer-dev-eng mailing list