diff --git a/Makefile b/Makefile index 7a9940d9fe..d895462d18 100644 --- a/Makefile +++ b/Makefile @@ -20,8 +20,8 @@ PRG_CFG = codec-cfg prefix = /usr/local BINDIR = ${prefix}/bin # BINDIR = /usr/local/bin -SRCS = codec-cfg.c subreader.c linux/getch2.c linux/timer-lx.c linux/shmem.c xa/xa_gsm.c lirc_mp.c cfgparser.c mixer.c dvdauth.c spudec.c -OBJS = codec-cfg.o subreader.o linux/getch2.o linux/timer-lx.o linux/shmem.o xa/xa_gsm.o lirc_mp.o cfgparser.o mixer.o dvdauth.o spudec.o +SRCS = stream.c codec-cfg.c subreader.c linux/getch2.c linux/timer-lx.c linux/shmem.c xa/xa_gsm.c lirc_mp.c cfgparser.c mixer.c dvdauth.c spudec.c +OBJS = stream.o codec-cfg.o subreader.o linux/getch2.o linux/timer-lx.o linux/shmem.o xa/xa_gsm.o lirc_mp.o cfgparser.o mixer.o dvdauth.o spudec.o CFLAGS = $(OPTFLAGS) $(CSS_INC) -Iloader -Ilibvo # -Wall A_LIBS = -Lmp3lib -lMP3 -Llibac3 -lac3 VO_LIBS = -Llibvo -lvo $(X_LIBS) diff --git a/mplayer.c b/mplayer.c index 9c9f1ada16..d1bce11746 100644 --- a/mplayer.c +++ b/mplayer.c @@ -233,7 +233,7 @@ static int max_framesize=0; // Input media streaming & demultiplexer: //**************************************************************************// -#include "stream.c" +#include "stream.h" #include "demuxer.c" #include "stheader.h" @@ -605,11 +605,13 @@ if(!parse_codec_cfg(get_path("codecs.conf"))){ if(vcd_track){ //============ Open VideoCD track ============== + int ret; f=open(filename,O_RDONLY); if(f<0){ printf("CD-ROM Device '%s' not found!\n",filename);return 1; } vcd_read_toc(f); - if(!vcd_seek_to_track(f,vcd_track)){ printf("Error selecting VCD track!\n");return 1;} - seek_to_byte+=VCD_SECTOR_DATA*vcd_get_msf(); + ret=vcd_seek_to_track(f,vcd_track); + if(ret==-1){ printf("Error selecting VCD track!\n");return 1;} + seek_to_byte+=ret; if(verbose) printf("VCD start byte position: 0x%X\n",seek_to_byte); stream_type=STREAMTYPE_VCD; #ifdef VCD_CACHE diff --git a/stream.c b/stream.c index e2240b2e34..8cdffbf2e0 100644 --- a/stream.c +++ b/stream.c @@ -1,22 +1,24 @@ +#include +#include + +#include +#include + +//#include +//#include +//#include + +#include + +#include "stream.h" + +extern int verbose; // defined in mplayer.c + #include "vcd_read.c" //=================== STREAMER ========================= -#define STREAM_BUFFER_SIZE 2048 - -#define STREAMTYPE_FILE 0 -#define STREAMTYPE_VCD 1 - -typedef struct { - int fd; - long pos; - int eof; - int type; // 0=file 1=VCD - unsigned int buf_pos,buf_len; - unsigned char buffer[STREAM_BUFFER_SIZE]; -} stream_t; - int stream_fill_buffer(stream_t *s){ int len; if(s->eof){ s->buf_pos=s->buf_len=0; return 0; } @@ -39,87 +41,14 @@ int stream_fill_buffer(stream_t *s){ return len; } -inline int stream_read_char(stream_t *s){ - return (s->buf_posbuf_len)?s->buffer[s->buf_pos++]: - (stream_fill_buffer(s)?s->buffer[s->buf_pos++]:-256); -// if(s->buf_posbuf_len) return s->buffer[s->buf_pos++]; -// stream_fill_buffer(s); -// if(s->buf_posbuf_len) return s->buffer[s->buf_pos++]; -// return 0; // EOF -} - -inline unsigned int stream_read_word(stream_t *s){ - int x,y; - x=stream_read_char(s); - y=stream_read_char(s); - return (x<<8)|y; -} - -inline unsigned int stream_read_dword(stream_t *s){ - unsigned int y; - y=stream_read_char(s); - y=(y<<8)|stream_read_char(s); - y=(y<<8)|stream_read_char(s); - y=(y<<8)|stream_read_char(s); - return y; -} - -inline unsigned int stream_read_word_le(stream_t *s){ - int x,y; - x=stream_read_char(s); - y=stream_read_char(s); - return (y<<8)|x; -} - -inline unsigned int stream_read_dword_le(stream_t *s){ - unsigned int y; - y=stream_read_char(s); - y|=stream_read_char(s)<<8; - y|=stream_read_char(s)<<16; - y|=stream_read_char(s)<<24; - return y; -} - -inline void stream_read(stream_t *s,char* mem,int len){ - while(len>0){ - int x; - x=s->buf_len-s->buf_pos; - if(x==0){ - if(!stream_fill_buffer(s)) return; // EOF - x=s->buf_len-s->buf_pos; - } - if(s->buf_pos>s->buf_len) printf("stream_read: WARNING! s->buf_pos>s->buf_len\n"); - if(x>len) x=len; - memcpy(mem,&s->buffer[s->buf_pos],x); - s->buf_pos+=x; mem+=x; len-=x; - } -} - -inline int stream_eof(stream_t *s){ - return s->eof; -} - -inline int stream_tell(stream_t *s){ - return s->pos+s->buf_pos-s->buf_len; -} - -inline int stream_seek(stream_t *s,unsigned int pos){ +int stream_seek_long(stream_t *s,unsigned int pos){ unsigned int newpos; - if(verbose>=3) printf("seek to 0x%X\n",pos); - - if(pospos){ - int x=pos-(s->pos-s->buf_len); - if(x>=0){ - s->buf_pos=x; -// putchar('*');fflush(stdout); - return 1; - } - } +// if(verbose>=3) printf("seek to 0x%X\n",pos); if(verbose>=3){ printf("s->pos=%X newpos=%X new_bufpos=%X buflen=%X \n", - s->pos,newpos,pos,s->buf_len); + (unsigned int)s->pos,newpos,pos,s->buf_len); } s->buf_pos=s->buf_len=0; @@ -157,27 +86,10 @@ if(newpos==0 || newpos!=s->pos){ s->buf_pos=pos; // byte position in sector return 1; } - printf("stream_seek: WARNING! Can't seek to 0x%X !\n",pos+newpos); + if(verbose) printf("stream_seek: WARNING! Can't seek to 0x%X !\n",pos+newpos); return 0; } -inline void stream_skip(stream_t *s,int len){ - if(len<0 || len>2*STREAM_BUFFER_SIZE){ - // negative or big skip! - stream_seek(s,stream_tell(s)+len); - return; - } - while(len>0){ - int x=s->buf_len-s->buf_pos; - if(x==0){ - if(!stream_fill_buffer(s)) return; // EOF - x=s->buf_len-s->buf_pos; - } - if(x>len) x=len; - //memcpy(mem,&s->buf[s->buf_pos],x); - s->buf_pos+=x; len-=x; - } -} void stream_reset(stream_t *s){ if(s->eof){ diff --git a/stream.h b/stream.h new file mode 100644 index 0000000000..4babec6df0 --- /dev/null +++ b/stream.h @@ -0,0 +1,131 @@ + +#define STREAM_BUFFER_SIZE 2048 + +#define STREAMTYPE_FILE 0 +#define STREAMTYPE_VCD 1 + +#define VCD_SECTOR_SIZE 2352 +#define VCD_SECTOR_OFFS 24 +#define VCD_SECTOR_DATA 2324 + +int vcd_seek_to_track(int fd,int track); +void vcd_read_toc(int fd); + +#ifdef VCD_CACHE +void vcd_cache_init(int s); +#endif + +typedef struct { + int fd; + long pos; + int eof; + int type; // 0=file 1=VCD + unsigned int buf_pos,buf_len; + unsigned char buffer[STREAM_BUFFER_SIZE]; +} stream_t; + +int stream_fill_buffer(stream_t *s); +int stream_seek_long(stream_t *s,unsigned int pos); + +inline static int stream_read_char(stream_t *s){ + return (s->buf_posbuf_len)?s->buffer[s->buf_pos++]: + (stream_fill_buffer(s)?s->buffer[s->buf_pos++]:-256); +// if(s->buf_posbuf_len) return s->buffer[s->buf_pos++]; +// stream_fill_buffer(s); +// if(s->buf_posbuf_len) return s->buffer[s->buf_pos++]; +// return 0; // EOF +} + +inline static unsigned int stream_read_word(stream_t *s){ + int x,y; + x=stream_read_char(s); + y=stream_read_char(s); + return (x<<8)|y; +} + +inline static unsigned int stream_read_dword(stream_t *s){ + unsigned int y; + y=stream_read_char(s); + y=(y<<8)|stream_read_char(s); + y=(y<<8)|stream_read_char(s); + y=(y<<8)|stream_read_char(s); + return y; +} + +inline static unsigned int stream_read_word_le(stream_t *s){ + int x,y; + x=stream_read_char(s); + y=stream_read_char(s); + return (y<<8)|x; +} + +inline static unsigned int stream_read_dword_le(stream_t *s){ + unsigned int y; + y=stream_read_char(s); + y|=stream_read_char(s)<<8; + y|=stream_read_char(s)<<16; + y|=stream_read_char(s)<<24; + return y; +} + +inline static void stream_read(stream_t *s,char* mem,int len){ + while(len>0){ + int x; + x=s->buf_len-s->buf_pos; + if(x==0){ + if(!stream_fill_buffer(s)) return; // EOF + x=s->buf_len-s->buf_pos; + } + if(s->buf_pos>s->buf_len) printf("stream_read: WARNING! s->buf_pos>s->buf_len\n"); + if(x>len) x=len; + memcpy(mem,&s->buffer[s->buf_pos],x); + s->buf_pos+=x; mem+=x; len-=x; + } +} + +inline static int stream_eof(stream_t *s){ + return s->eof; +} + +inline static int stream_tell(stream_t *s){ + return s->pos+s->buf_pos-s->buf_len; +} + +inline static int stream_seek(stream_t *s,unsigned int pos){ + +// if(verbose>=3) printf("seek to 0x%X\n",pos); + + if(pospos){ + int x=pos-(s->pos-s->buf_len); + if(x>=0){ + s->buf_pos=x; +// putchar('*');fflush(stdout); + return 1; + } + } + + return stream_seek_long(s,pos); +} + +inline static void stream_skip(stream_t *s,int len){ + if(len<0 || len>2*STREAM_BUFFER_SIZE){ + // negative or big skip! + stream_seek(s,stream_tell(s)+len); + return; + } + while(len>0){ + int x=s->buf_len-s->buf_pos; + if(x==0){ + if(!stream_fill_buffer(s)) return; // EOF + x=s->buf_len-s->buf_pos; + } + if(x>len) x=len; + //memcpy(mem,&s->buf[s->buf_pos],x); + s->buf_pos+=x; len-=x; + } +} + +void stream_reset(stream_t *s); +stream_t* new_stream(int fd,int type); +void free_stream(stream_t *s); +