changeset 692:14a2f35921a0

allow playing from stdin
author arpi_esp
date Thu, 03 May 2001 23:32:56 +0000
parents 3693fd4c4ec2
children 3b039b8938e6
files asfheader.c aviheader.c mplayer.c stream.c stream.h
diffstat 5 files changed, 36 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/asfheader.c	Thu May 03 22:39:38 2001 +0000
+++ b/asfheader.c	Thu May 03 23:32:56 2001 +0000
@@ -180,6 +180,9 @@
 //    case 0x33000890: return "guid_index_chunk";
 
   } // switch GUID
+
+  if((*((unsigned int*)&objh.guid))==0x75b22636) break; // movi chunk
+
   if(!stream_seek(demuxer->stream,endpos)) break;
 } // while EOF
 
--- a/aviheader.c	Thu May 03 22:39:38 2001 +0000
+++ b/aviheader.c	Thu May 03 23:32:56 2001 +0000
@@ -49,6 +49,7 @@
       demuxer->movi_start=stream_tell(demuxer->stream);
       demuxer->movi_end=demuxer->movi_start+len;
       if(verbose>=1) printf("Found movie at 0x%X - 0x%X\n",demuxer->movi_start,demuxer->movi_end);
+      if(index_mode==-2) break; // reading from non-seekable source (stdin)
       len=(len+1)&(~1);
       stream_skip(demuxer->stream,len);
     }
--- a/mplayer.c	Thu May 03 22:39:38 2001 +0000
+++ b/mplayer.c	Thu May 03 23:32:56 2001 +0000
@@ -553,11 +553,18 @@
 } else {
 //============ Open plain FILE ============
   int len;
-  f=open(filename,O_RDONLY);
-  if(f<0){ printf("File not found: '%s'\n",filename);return 1; }
-  len=lseek(f,0,SEEK_END); lseek(f,0,SEEK_SET);
-  stream=new_stream(f,STREAMTYPE_FILE);
-  stream->end_pos=len;
+  if(!strcmp(filename,"-")){
+      // read from stdin
+      printf("Reading from stdin...\n");
+      f=0; // 0=stdin
+      stream=new_stream(f,STREAMTYPE_STREAM);
+  } else {
+      f=open(filename,O_RDONLY);
+      if(f<0){ printf("File not found: '%s'\n",filename);return 1; }
+      len=lseek(f,0,SEEK_END); lseek(f,0,SEEK_SET);
+      stream=new_stream(f,STREAMTYPE_FILE);
+      stream->end_pos=len;
+  }
 }
 
 #ifdef HAVE_LIBCSS
@@ -658,7 +665,7 @@
 switch(file_format){
  case DEMUXER_TYPE_AVI: {
   //---- AVI header:
-  read_avi_header(demuxer,index_mode);
+  read_avi_header(demuxer,f?index_mode:-2);
   stream_reset(demuxer->stream);
   stream_seek(demuxer->stream,demuxer->movi_start);
   demuxer->idx_pos=0;
@@ -1157,7 +1164,7 @@
 #ifdef USE_TERMCAP
   load_termcap(NULL); // load key-codes
 #endif
-  getch2_enable();
+  if(f) getch2_enable();
 
   //========= Catch terminate signals: ================
   // terminate requests:
@@ -1636,7 +1643,7 @@
 #ifdef HAVE_LIRC
           lirc_mp_getinput()<=0 &&
 #endif
-          getch2(20)<=0 && mplayer_get_key()<=0){
+          (!f || getch2(20)<=0) && mplayer_get_key()<=0){
 	  video_out->check_events();
       }
       osd_function=OSD_PLAY;
@@ -1653,7 +1660,7 @@
 #ifdef HAVE_LIRC
       (c=lirc_mp_getinput())>0 ||
 #endif
-      (c=getch2(0))>0 || (c=mplayer_get_key())>0) switch(c){
+      (f && (c=getch2(0)))>0 || (c=mplayer_get_key())>0) switch(c){
     // seek 10 sec
     case KEY_RIGHT:
       osd_function=OSD_FFW;
--- a/stream.c	Thu May 03 22:39:38 2001 +0000
+++ b/stream.c	Thu May 03 23:32:56 2001 +0000
@@ -24,6 +24,7 @@
   if(s->eof){ s->buf_pos=s->buf_len=0; return 0; }
   switch(s->type){
   case STREAMTYPE_FILE:
+  case STREAMTYPE_STREAM:
     len=read(s->fd,s->buffer,STREAM_BUFFER_SIZE);break;
   case STREAMTYPE_VCD:
 #ifdef VCD_CACHE
@@ -55,6 +56,7 @@
 
   switch(s->type){
   case STREAMTYPE_FILE:
+  case STREAMTYPE_STREAM:
     newpos=pos&(~(STREAM_BUFFER_SIZE-1));break;
   case STREAMTYPE_VCD:
     newpos=(pos/VCD_SECTOR_DATA)*VCD_SECTOR_DATA;break;
@@ -63,18 +65,29 @@
   pos-=newpos;
 
 if(newpos==0 || newpos!=s->pos){
-  s->pos=newpos; // real seek
   switch(s->type){
   case STREAMTYPE_FILE:
+    s->pos=newpos; // real seek
     if(lseek(s->fd,s->pos,SEEK_SET)<0) s->eof=1;
     break;
   case STREAMTYPE_VCD:
+    s->pos=newpos; // real seek
 #ifdef VCD_CACHE
     vcd_cache_seek(s->pos/VCD_SECTOR_DATA);
 #else
     vcd_set_msf(s->pos/VCD_SECTOR_DATA);
 #endif
     break;
+  case STREAMTYPE_STREAM:
+    //s->pos=newpos; // real seek
+    if(newpos<s->pos){
+      printf("Cannot seek backward in linear streams!\n");
+      return 1;
+    }
+    while(s->pos<newpos){
+      if(stream_fill_buffer(s)<=0) break; // EOF
+    }
+    break;
   }
 //   putchar('.');fflush(stdout);
 //} else {
--- a/stream.h	Thu May 03 22:39:38 2001 +0000
+++ b/stream.h	Thu May 03 23:32:56 2001 +0000
@@ -3,6 +3,7 @@
 
 #define STREAMTYPE_FILE 0
 #define STREAMTYPE_VCD  1
+#define STREAMTYPE_STREAM 2    // same as FILE but no seeking (for stdin)
 
 #define VCD_SECTOR_SIZE 2352
 #define VCD_SECTOR_OFFS 24
@@ -109,7 +110,7 @@
 }
 
 inline static void stream_skip(stream_t *s,int len){
-  if(len<0 || len>2*STREAM_BUFFER_SIZE){
+  if(len<0 || (len>2*STREAM_BUFFER_SIZE && s->type!=STREAMTYPE_STREAM)){
     // negative or big skip!
     stream_seek(s,stream_tell(s)+len);
     return;