[MPlayer-dev-eng] [PATCH] refresh end_pos in stream_file.c

Davide Baldo davide.baldo.88 at gmail.com
Tue May 20 21:56:57 CEST 2014


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;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: stream_file_end_pos
Type: application/octet-stream
Size: 846 bytes
Desc: not available
URL: <https://lists.mplayerhq.hu/pipermail/mplayer-dev-eng/attachments/20140520/dd93fa32/attachment.obj>


More information about the MPlayer-dev-eng mailing list