[PATCH] refresh end_pos in stream_file.c
This improvement allow to download and watch a file at the same time without having to re-open mplayer to refresh the end_pos of the stream. I'm not sure about the impact of lseek() at each read, should be trivial in any OS but i'm not sure about it. I attached the patch as well. Index: stream/stream_file.c =================================================================== --- stream/stream_file.c (revision 37205) +++ stream/stream_file.c (working copy) @@ -64,7 +64,13 @@ int r = read(s->fd,buffer,max_len); // We are certain this is EOF, do not retry if (max_len && r == 0) s->eof = 1; - return (r <= 0) ? -1 : r; + int bytes_num = (r <= 0) ? -1 : r; + if (bytes_num > 0 && s->fd != STDIN_FILENO) { + off_t current = lseek(s->fd,0,SEEK_CUR); + s->end_pos = lseek(s->fd,0,SEEK_END); + lseek(s->fd,current,SEEK_SET); + } + return bytes_num; } static int write_buffer(stream_t *s, char* buffer, int len) { @@ -81,6 +87,7 @@ } static int seek(stream_t *s, int64_t newpos) { + s->end_pos = lseek(s->fd,0,SEEK_END); s->pos = newpos; if(lseek(s->fd,s->pos,SEEK_SET)<0) { s->eof=1;
On Tue, May 20, 2014 at 09:56:57PM +0200, Davide Baldo wrote:
This improvement allow to download and watch a file at the same time without having to re-open mplayer to refresh the end_pos of the stream. I'm not sure about the impact of lseek() at each read, should be trivial in any OS but i'm not sure about it. I attached the patch as well.
This came up before: It should not be necessary. The end_pos will be ignored/updated if we do not actually reach EOF at that point.
On 05/20/2014 01:03 PM, Reimar Döffinger wrote:
This came up before: It should not be necessary. The end_pos will be ignored/updated if we do not actually reach EOF at that point.
The OSD will show that you've reached EOF which is misleading if the file has grown since mplayer has started. I've been applying the attached patch for years to display the correct percentage of the remaining file but it only works for MPEG TS streams. There's probably a more general solution.
On Tue, May 20, 2014 at 01:39:19PM -0700, Scott W. Larson wrote:
On 05/20/2014 01:03 PM, Reimar Döffinger wrote:
This came up before: It should not be necessary. The end_pos will be ignored/updated if we do not actually reach EOF at that point.
The OSD will show that you've reached EOF which is misleading if the file has grown since mplayer has started.
These are quite different issues, with completely different solutions. For the case where it doesn't actually play past the original file size, the solution is to simply double-check once the endpos is reached (or rather, just never use it except as a hint at all). That is advisable in general since with streams it can happen that the original size indication isn't right anyway. The OSD on the other hand is completely different. For example it will only affect certain demuxers, in combination with certain stream types. These demuxers do have the issue that their time estimate is complete nonsense anyway. So for example, the MOV, MKV, ... demuxers are not affected. Even the TS demuxer is not affected when it is used as part of playing Bluray media. In addition, since it is only for the OSD it is not a good idea to update it on every read - updating maybe once per second should be enough. For the -PS demuxer it would require even more work, since that one uses endpos to find and estimate the final time stamp, and thus get the length. Just updating endpos won't help one bit. So while making the OSD work properly in this case would be nice, a good solution isn't easy and it doesn't seem all that important to. If someone wants to work on it I'll be happy to help out, but I'm fairly certain it won't be done on one afternoon or so.
participants (3)
-
Davide Baldo -
Reimar Döffinger -
Scott W. Larson