diff --git a/libmpdemux/demux_mf.c b/libmpdemux/demux_mf.c index a72af16fe4..61cad83388 100644 --- a/libmpdemux/demux_mf.c +++ b/libmpdemux/demux_mf.c @@ -15,21 +15,15 @@ #include "stheader.h" #include "mf.h" -typedef struct -{ - int nr_of_frames; - int curr_frame; -} demuxer_mf_t; - void demux_seek_mf(demuxer_t *demuxer,float rel_seek_secs,int flags){ - demuxer_mf_t * mf = (demuxer_mf_t *)demuxer->priv; + mf_t * mf = (mf_t *)demuxer->priv; sh_video_t * sh_video = demuxer->video->sh; int newpos = (flags & 1)?0:mf->curr_frame; - if ( flags & 2 ) newpos+=rel_seek_secs*mf->nr_of_frames; + if ( flags & 2 ) newpos+=rel_seek_secs*mf->nr_of_files; else newpos+=rel_seek_secs * sh_video->fps; if ( newpos < 0 ) newpos=0; - if( newpos > mf->nr_of_frames) newpos=mf->nr_of_frames; + if( newpos > mf->nr_of_files) newpos=mf->nr_of_files; mf->curr_frame=newpos; } @@ -38,49 +32,43 @@ void demux_seek_mf(demuxer_t *demuxer,float rel_seek_secs,int flags){ // 1 = successfully read a packet int demux_mf_fill_buffer(demuxer_t *demuxer){ mf_t * mf; - demuxer_mf_t * dmf; struct stat fs; FILE * f; - dmf=(demuxer_mf_t*)demuxer->priv; - if ( dmf->curr_frame >= dmf->nr_of_frames ) return 0; - mf=(mf_t*)demuxer->stream->priv; + mf=(mf_t*)demuxer->priv; + if ( mf->curr_frame >= mf->nr_of_files ) return 0; - stat( mf->names[dmf->curr_frame],&fs ); -// printf( "[demux_mf] frame: %d (%s,%d)\n",dmf->curr_frame,mf->names[dmf->curr_frame],fs.st_size ); + stat( mf->names[mf->curr_frame],&fs ); +// printf( "[demux_mf] frame: %d (%s,%d)\n",mf->curr_frame,mf->names[mf->curr_frame],fs.st_size ); - if ( !( f=fopen( mf->names[dmf->curr_frame],"r" ) ) ) return 0; + if ( !( f=fopen( mf->names[mf->curr_frame],"r" ) ) ) return 0; { sh_video_t * sh_video = demuxer->video->sh; demux_packet_t * dp = new_demux_packet( fs.st_size ); if ( !fread( dp->buffer,fs.st_size,1,f ) ) return 0; - dp->pts=dmf->curr_frame / sh_video->fps; - dp->pos=dmf->curr_frame; + dp->pts=mf->curr_frame / sh_video->fps; + dp->pos=mf->curr_frame; dp->flags=0; // append packet to DS stream: ds_add_packet( demuxer->video,dp ); } fclose( f ); - dmf->curr_frame++; + mf->curr_frame++; return 1; } demuxer_t* demux_open_mf(demuxer_t* demuxer){ sh_video_t *sh_video = NULL; mf_t *mf = NULL; - demuxer_mf_t *dmf = NULL; + + if(!demuxer->stream->url) return NULL; + mf=open_mf(demuxer->stream->url); + if(!mf) return NULL; + mf->curr_frame=0; - mf=(mf_t*)demuxer->stream->priv; - dmf=calloc( 1,sizeof( demuxer_mf_t ) ); - - // go back to the beginning - stream_reset(demuxer->stream); -// stream_seek(demuxer->stream, 0); demuxer->movi_start = 0; demuxer->movi_end = mf->nr_of_files - 1; - dmf->nr_of_frames= mf->nr_of_files; - dmf->curr_frame=0; // create a new video stream header sh_video = new_sh_video(demuxer, 0); @@ -99,7 +87,7 @@ demuxer_t* demux_open_mf(demuxer_t* demuxer){ if ( !strcasecmp( mf_type,"png" )) sh_video->format = mmioFOURCC('M', 'P', 'N', 'G' ); else if ( !strcasecmp( mf_type,"tga" )) sh_video->format = mmioFOURCC('M', 'T', 'G', 'A' ); - else { mp_msg(MSGT_DEMUX, MSGL_INFO, "[demux_mf] unknow input file type.\n" ); free( dmf ); return NULL; } + else { mp_msg(MSGT_DEMUX, MSGL_INFO, "[demux_mf] unknow input file type.\n" ); free( mf ); return NULL; } sh_video->disp_w = mf_w; sh_video->disp_h = mf_h; @@ -120,15 +108,15 @@ demuxer_t* demux_open_mf(demuxer_t* demuxer){ /* disable seeking */ // demuxer->seekable = 0; - demuxer->priv=(void*)dmf; + demuxer->priv=(void*)mf; return demuxer; } void demux_close_mf(demuxer_t* demuxer) { - demuxer_mf_t *dmf = demuxer->priv; + mf_t *mf = demuxer->priv; - if(!dmf) + if(!mf) return; - free(dmf); + free(mf); } diff --git a/libmpdemux/mf.c b/libmpdemux/mf.c index bc6d97704c..434a426185 100644 --- a/libmpdemux/mf.c +++ b/libmpdemux/mf.c @@ -24,8 +24,7 @@ int mf_h = 288; float mf_fps = 25.0; char * mf_type = "jpg"; -int stream_open_mf(char * filename,stream_t * stream) -{ +mf_t* open_mf(char * filename){ glob_t gg; struct stat fs; int i; @@ -70,7 +69,7 @@ int stream_open_mf(char * filename,stream_t * stream) mp_msg( MSGT_STREAM,MSGL_INFO,"[mf] search expr: %s\n",fname ); if ( glob( fname,0,NULL,&gg ) ) - { free( mf ); free( fname ); return 0; } + { free( mf ); free( fname ); return NULL; } mf->nr_of_files=gg.gl_pathc; mf->names=malloc( gg.gl_pathc * sizeof( char* ) ); @@ -111,7 +110,6 @@ int stream_open_mf(char * filename,stream_t * stream) exit_mf: free( fname ); - stream->priv=(void*)mf; - return 1; + return mf; } diff --git a/libmpdemux/mf.h b/libmpdemux/mf.h index 6ebb3c0a5e..f147477aba 100644 --- a/libmpdemux/mf.h +++ b/libmpdemux/mf.h @@ -10,8 +10,11 @@ extern char * mf_type; typedef struct { - int nr_of_files; + int curr_frame; + int nr_of_files; char ** names; } mf_t; +mf_t* open_mf(char * filename); + #endif diff --git a/libmpdemux/open.c b/libmpdemux/open.c index 0966ad9dfd..0bdcaf0a89 100644 --- a/libmpdemux/open.c +++ b/libmpdemux/open.c @@ -428,13 +428,9 @@ tv_err: if (mf_support == 1) { /* create stream */ - stream = new_stream(-1, STREAMTYPE_MF); - if (!stream) - return(NULL); - - if (!stream_open_mf(filename, stream)) - return(NULL); - + stream = new_stream(-1, STREAMTYPE_DUMMY); + if (!stream) return(NULL); + stream->url=strdup(filename); return(stream); } diff --git a/libmpdemux/stream.c b/libmpdemux/stream.c index 78cbd847cd..c1bc6cbf99 100644 --- a/libmpdemux/stream.c +++ b/libmpdemux/stream.c @@ -254,6 +254,7 @@ stream_t* new_stream(int fd,int type){ s->buf_pos=s->buf_len=0; s->start_pos=s->end_pos=0; s->priv=NULL; + s->url=NULL; s->cache_pid=0; stream_reset(s); return s; diff --git a/libmpdemux/stream.h b/libmpdemux/stream.h index 08b4a56953..deca3cd222 100644 --- a/libmpdemux/stream.h +++ b/libmpdemux/stream.h @@ -7,17 +7,17 @@ #define STREAM_BUFFER_SIZE 2048 -#define STREAMTYPE_FILE 0 -#define STREAMTYPE_VCD 1 -#define STREAMTYPE_STREAM 2 // same as FILE but no seeking (for stdin) -#define STREAMTYPE_DVD 3 -#define STREAMTYPE_MEMORY 4 -#define STREAMTYPE_TV 5 -#define STREAMTYPE_PLAYLIST 6 -#define STREAMTYPE_MF 7 -#define STREAMTYPE_DS 8 -#define STREAMTYPE_DVDNAV 9 // we cannot safely "seek" in this... -#define STREAMTYPE_CDDA 10 +#define STREAMTYPE_DUMMY -1 // for placeholders, when the actual reading is handled in the demuxer +#define STREAMTYPE_FILE 0 // read from seekable file +#define STREAMTYPE_VCD 1 // raw mode-2 CDROM reading, 2324 bytes/sector +#define STREAMTYPE_STREAM 2 // same as FILE but no seeking (for net/stdin) +#define STREAMTYPE_DVD 3 // libdvdread +#define STREAMTYPE_MEMORY 4 // read data from memory area +#define STREAMTYPE_TV 5 // FIXME!!! dummy +#define STREAMTYPE_PLAYLIST 6 // FIXME!!! same as STREAMTYPE_FILE now +#define STREAMTYPE_DS 8 // read from a demuxer stream +#define STREAMTYPE_DVDNAV 9 // we cannot safely "seek" in this... +#define STREAMTYPE_CDDA 10 // raw audio CD reader #define VCD_SECTOR_SIZE 2352 #define VCD_SECTOR_OFFS 24 @@ -31,18 +31,19 @@ int vcd_seek_to_track(int fd,int track); void vcd_read_toc(int fd); typedef struct { - int fd; - int type; // 0=file 1=VCD + int fd; // file descriptor, see man open(2) + int type; // see STREAMTYPE_* unsigned int buf_pos,buf_len; off_t pos,start_pos,end_pos; int eof; unsigned int cache_pid; void* cache_data; void* priv; // used for DVD, TV, RTSP etc - unsigned char buffer[STREAM_BUFFER_SIZE>VCD_SECTOR_SIZE?STREAM_BUFFER_SIZE:VCD_SECTOR_SIZE]; + char* url; // strdup() of filename/url #ifdef STREAMING streaming_ctrl_t *streaming_ctrl; #endif + unsigned char buffer[STREAM_BUFFER_SIZE>VCD_SECTOR_SIZE?STREAM_BUFFER_SIZE:VCD_SECTOR_SIZE]; } stream_t; #ifdef USE_STREAM_CACHE