[MPlayer-dev-eng] [PATCH] libmpdemux: clean up stream/file detection

Eric Lammerts eric at lammerts.org
Mon May 20 13:48:14 CEST 2002


Hello,
This patch removes the assumption that "-" is always a stream and a
filename is always a regular file. Instead, lseek() is used to
determine if it's a file or a stream.

This makes it possible to
a) play from a named pipe (fifo)
b) seek in a movie played with "mplayer - < /some/regular.file"

Eric


Index: libmpdemux/open.c
===================================================================
RCS file: /cvsroot/mplayer/main/libmpdemux/open.c,v
retrieving revision 1.43
diff -u -r1.43 open.c
--- libmpdemux/open.c	2 May 2002 10:32:55 -0000	1.43
+++ libmpdemux/open.c	20 May 2002 11:43:55 -0000
@@ -418,15 +418,6 @@
     return(stream);
   }

-//============ Open STDIN ============
-  if(!strcmp(filename,"-")){
-      // read from stdin
-      mp_msg(MSGT_OPEN,MSGL_INFO,MSGTR_ReadSTDIN);
-      f=0; // 0=stdin
-      stream=new_stream(f,STREAMTYPE_STREAM);
-      return stream;
-  }
-
 #ifdef STREAMING
   url = url_new(filename);
   if(url) {
@@ -442,22 +433,30 @@
   }
 #endif

-//============ Open plain FILE ============
-       f=open(filename,O_RDONLY);
-       if(f<0){ mp_msg(MSGT_OPEN,MSGL_ERR,MSGTR_FileNotFound,filename);return NULL; }
-       len=lseek(f,0,SEEK_END); lseek(f,0,SEEK_SET);
-       if (len == -1)
-	 perror("Error: lseek failed to obtain video file size");
-       else
+//============ Open STDIN or plain FILE ============
+  if(!strcmp(filename,"-")){
+      // read from stdin
+      mp_msg(MSGT_OPEN,MSGL_INFO,MSGTR_ReadSTDIN);
+      f=0; // 0=stdin
+  } else {
+      f=open(filename,O_RDONLY);
+      if(f<0){ mp_msg(MSGT_OPEN,MSGL_ERR,MSGTR_FileNotFound,filename);return NULL; }
+  }
+
+  len=lseek(f,0,SEEK_END);
+  if (len == -1) {
+    stream=new_stream(f,STREAMTYPE_STREAM);
+  } else {
+    lseek(f,0,SEEK_SET);
 #ifdef _LARGEFILE_SOURCE
-	 mp_msg(MSGT_OPEN,MSGL_V,"File size is %lld bytes\n", (long long)len);
+    mp_msg(MSGT_OPEN,MSGL_V,"File size is %lld bytes\n", (long long)len);
 #else
-	 mp_msg(MSGT_OPEN,MSGL_V,"File size is %u bytes\n", (unsigned int)len);
+    mp_msg(MSGT_OPEN,MSGL_V,"File size is %u bytes\n", (unsigned int)len);
 #endif
-       stream=new_stream(f,STREAMTYPE_FILE);
-       stream->end_pos=len;
-       return stream;
-
+    stream=new_stream(f,STREAMTYPE_FILE);
+    stream->end_pos=len;
+  }
+  return stream;
 }

 int dvd_parse_chapter_range(struct config *conf, const char *range){





More information about the MPlayer-dev-eng mailing list