mirror of
https://github.com/mpv-player/mpv
synced 2024-12-23 23:32:26 +00:00
allow playing from stdin
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@693 b3059339-0415-0410-9bf9-f77b7e298cf2
This commit is contained in:
parent
dc776b2b5c
commit
01df02c62c
@ -180,6 +180,9 @@ if(verbose){
|
||||
// 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
|
||||
|
||||
|
@ -49,6 +49,7 @@ while(1){
|
||||
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);
|
||||
}
|
||||
|
25
mplayer.c
25
mplayer.c
@ -553,11 +553,18 @@ if(vcd_track){
|
||||
} 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 @@ d_dvdsub=demuxer->sub;
|
||||
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 @@ int osd_last_pts=-303;
|
||||
#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 @@ switch(sh_video->codec->driver){
|
||||
#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 @@ switch(sh_video->codec->driver){
|
||||
#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;
|
||||
|
15
stream.c
15
stream.c
@ -24,6 +24,7 @@ int stream_fill_buffer(stream_t *s){
|
||||
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 @@ if(verbose>=3){
|
||||
|
||||
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 @@ if(verbose>=3){
|
||||
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 {
|
||||
|
3
stream.h
3
stream.h
@ -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 int stream_seek(stream_t *s,unsigned int pos){
|
||||
}
|
||||
|
||||
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;
|
||||
|
Loading…
Reference in New Issue
Block a user