changeset 7407:8780415baa87

stream layer cleanup - part 1 STREAMTYPE_MF removed, using STREAMTYPE_DUMMY instead mf.c/demux_mf updated to do the opening in demux_open instead of stream_open
author arpi
date Sun, 15 Sep 2002 19:47:49 +0000
parents 1394aebaa838
children 0c6948b8100f
files libmpdemux/demux_mf.c libmpdemux/mf.c libmpdemux/mf.h libmpdemux/open.c libmpdemux/stream.c libmpdemux/stream.h
diffstat 6 files changed, 47 insertions(+), 60 deletions(-) [+]
line wrap: on
line diff
--- a/libmpdemux/demux_mf.c	Sun Sep 15 18:48:16 2002 +0000
+++ b/libmpdemux/demux_mf.c	Sun Sep 15 19:47:49 2002 +0000
@@ -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 @@
 //     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 @@
      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 @@
   /* 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);  
 }
--- a/libmpdemux/mf.c	Sun Sep 15 18:48:16 2002 +0000
+++ b/libmpdemux/mf.c	Sun Sep 15 19:47:49 2002 +0000
@@ -24,8 +24,7 @@
 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 @@
    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 @@
 
 exit_mf:
  free( fname );
- stream->priv=(void*)mf;
- return 1;
+ return mf;
 }
 
--- a/libmpdemux/mf.h	Sun Sep 15 18:48:16 2002 +0000
+++ b/libmpdemux/mf.h	Sun Sep 15 19:47:49 2002 +0000
@@ -10,8 +10,11 @@
 
 typedef struct
 {
- int     nr_of_files;
+ int curr_frame;
+ int nr_of_files;
  char ** names;
 } mf_t;
 
+mf_t* open_mf(char * filename);
+
 #endif
--- a/libmpdemux/open.c	Sun Sep 15 18:48:16 2002 +0000
+++ b/libmpdemux/open.c	Sun Sep 15 19:47:49 2002 +0000
@@ -428,13 +428,9 @@
   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);
   }
   
--- a/libmpdemux/stream.c	Sun Sep 15 18:48:16 2002 +0000
+++ b/libmpdemux/stream.c	Sun Sep 15 19:47:49 2002 +0000
@@ -254,6 +254,7 @@
   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;
--- a/libmpdemux/stream.h	Sun Sep 15 18:48:16 2002 +0000
+++ b/libmpdemux/stream.h	Sun Sep 15 19:47:49 2002 +0000
@@ -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 @@
 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