Mercurial > mplayer.hg
changeset 578:c2377cd0069f
something moved to brand new stream.h
author | arpi_esp |
---|---|
date | Sun, 22 Apr 2001 16:56:20 +0000 |
parents | feeb61dd92ea |
children | 256f3d32a4af |
files | Makefile mplayer.c stream.c stream.h |
diffstat | 4 files changed, 158 insertions(+), 113 deletions(-) [+] |
line wrap: on
line diff
--- a/Makefile Sun Apr 22 16:29:25 2001 +0000 +++ b/Makefile Sun Apr 22 16:56:20 2001 +0000 @@ -20,8 +20,8 @@ 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)
--- a/mplayer.c Sun Apr 22 16:29:25 2001 +0000 +++ b/mplayer.c Sun Apr 22 16:56:20 2001 +0000 @@ -233,7 +233,7 @@ // Input media streaming & demultiplexer: //**************************************************************************// -#include "stream.c" +#include "stream.h" #include "demuxer.c" #include "stheader.h" @@ -605,11 +605,13 @@ 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
--- a/stream.c Sun Apr 22 16:29:25 2001 +0000 +++ b/stream.c Sun Apr 22 16:56:20 2001 +0000 @@ -1,22 +1,24 @@ + +#include <stdio.h> +#include <stdlib.h> + +#include <sys/ioctl.h> +#include <unistd.h> + +//#include <sys/types.h> +//#include <sys/stat.h> +//#include <fcntl.h> + +#include <linux/cdrom.h> + +#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 @@ return len; } -inline int stream_read_char(stream_t *s){ - return (s->buf_pos<s->buf_len)?s->buffer[s->buf_pos++]: - (stream_fill_buffer(s)?s->buffer[s->buf_pos++]:-256); -// if(s->buf_pos<s->buf_len) return s->buffer[s->buf_pos++]; -// stream_fill_buffer(s); -// if(s->buf_pos<s->buf_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(pos<s->pos){ - 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 @@ 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){
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/stream.h Sun Apr 22 16:56:20 2001 +0000 @@ -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_pos<s->buf_len)?s->buffer[s->buf_pos++]: + (stream_fill_buffer(s)?s->buffer[s->buf_pos++]:-256); +// if(s->buf_pos<s->buf_len) return s->buffer[s->buf_pos++]; +// stream_fill_buffer(s); +// if(s->buf_pos<s->buf_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(pos<s->pos){ + 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); +