[MPlayer-dev-eng] [PATCH] make demuxer_get_percent_pos() recheck file length

Rich Felker dalias at aerifal.cx
Sun Oct 2 01:04:36 CEST 2005


On Sat, Oct 01, 2005 at 02:53:00PM -0700, Scott W. Larson wrote:
> This makes demuxer_get_percent_pos() calculate the position using the 
> present length of the file instead of the length it was when mplayer was 
> started. This is useful for "time shifting" applications which append to 
> a file as it's being played by mplayer. The progress bar will always 
> show how much file is left at that moment so you'll know how far behind 
> "real time" you are.

> Index: libmpdemux/demuxer.c
> ===================================================================
> RCS file: /cvsroot/mplayer/main/libmpdemux/demuxer.c,v
> retrieving revision 1.207
> diff -u -r1.207 demuxer.c
> --- libmpdemux/demuxer.c	23 Sep 2005 22:35:03 -0000	1.207
> +++ libmpdemux/demuxer.c	1 Oct 2005 21:39:11 -0000
> @@ -943,7 +943,17 @@
>  int demuxer_get_percent_pos(demuxer_t *demuxer){     
>      int ans = 0;
>      int res = demux_control(demuxer, DEMUXER_CTRL_GET_PERCENT_POS, &ans);
> -    int len = (demuxer->movi_end - demuxer->movi_start) / 100;
> +    int len;
> +    off_t save_pos = lseek(demuxer->stream->fd, 0, SEEK_CUR);
> +    off_t end_of_file;
> +                                                                                
> +    // Get present length of file by seeking to end and
> +    // seeking back.
> +    end_of_file = lseek(demuxer->stream->fd, 0, SEEK_END);
> +    lseek(demuxer->stream->fd, save_pos, SEEK_SET);
> +    demuxer->movi_end = end_of_file;
> +    len = (demuxer->movi_end - demuxer->movi_start) / 100;

I have a feeling this could break horribly with non-file streams...

Rich




More information about the MPlayer-dev-eng mailing list