Fixes
[mplayer/glamo.git] / libmpdemux / mf.c
blob2c05ea0e35309b4e933d1838c2e85d9eedff7ecb
2 #include <ctype.h>
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <string.h>
6 #include <unistd.h>
7 #include <fcntl.h>
8 #include <errno.h>
9 #include <sys/types.h>
10 #include <sys/stat.h>
12 #include "config.h"
14 #ifdef HAVE_GLOB
15 #include <glob.h>
16 #else
17 #include "osdep/glob.h"
18 #endif
20 #include "mp_msg.h"
21 #include "help_mp.h"
22 #include "stream.h"
24 #include "mf.h"
26 int mf_w = 0; //352; // let codecs to detect it
27 int mf_h = 0; //288;
28 float mf_fps = 25.0;
29 char * mf_type = NULL; //"jpg";
31 mf_t* open_mf(char * filename){
32 #if defined(HAVE_GLOB) || defined(__MINGW32__)
33 glob_t gg;
34 struct stat fs;
35 int i;
36 char * fname;
37 mf_t * mf;
38 int error_count = 0;
39 int count = 0;
41 mf=calloc( 1,sizeof( mf_t ) );
43 if( filename[0] == '@' )
45 FILE *lst_f=fopen(filename + 1,"r");
46 if ( lst_f )
48 fname=malloc( 255 );
49 while ( fgets( fname,255,lst_f ) )
51 /* remove spaces from end of fname */
52 char *t=fname + strlen( fname ) - 1;
53 while ( t > fname && isspace( *t ) ) *(t--)=0;
54 if ( stat( fname,&fs ) )
56 mp_msg( MSGT_STREAM,MSGL_V,"[mf] file not found: '%s'\n",fname );
58 else
60 mf->names=realloc( mf->names,( mf->nr_of_files + 1 ) * sizeof( char* ) );
61 mf->names[mf->nr_of_files]=strdup( fname );
62 mf->nr_of_files++;
65 fclose( lst_f );
67 mp_msg( MSGT_STREAM,MSGL_INFO,"[mf] number of files: %d\n",mf->nr_of_files );
68 goto exit_mf;
70 mp_msg( MSGT_STREAM,MSGL_INFO,"[mf] %s is not indirect filelist\n",filename+1 );
73 if( strchr( filename,',') )
75 mp_msg( MSGT_STREAM,MSGL_INFO,"[mf] filelist: %s\n",filename );
77 while ( ( fname=strsep( &filename,"," ) ) )
79 if ( stat( fname,&fs ) )
81 mp_msg( MSGT_STREAM,MSGL_V,"[mf] file not found: '%s'\n",fname );
83 else
85 mf->names=realloc( mf->names,( mf->nr_of_files + 1 ) * sizeof( char* ) );
86 mf->names[mf->nr_of_files]=strdup( fname );
87 // mp_msg( MSGT_STREAM,MSGL_V,"[mf] added file %d.: %s\n",mf->nr_of_files,mf->names[mf->nr_of_files] );
88 mf->nr_of_files++;
91 mp_msg( MSGT_STREAM,MSGL_INFO,"[mf] number of files: %d\n",mf->nr_of_files );
93 goto exit_mf;
96 fname=malloc( strlen( filename ) + 32 );
98 if ( !strchr( filename,'%' ) )
100 strcpy( fname,filename );
101 if ( !strchr( filename,'*' ) ) strcat( fname,"*" );
103 mp_msg( MSGT_STREAM,MSGL_INFO,"[mf] search expr: %s\n",fname );
105 if ( glob( fname,0,NULL,&gg ) )
106 { free( mf ); free( fname ); return NULL; }
108 mf->nr_of_files=gg.gl_pathc;
109 mf->names=calloc( gg.gl_pathc, sizeof( char* ) );
111 mp_msg( MSGT_STREAM,MSGL_INFO,"[mf] number of files: %d (%d)\n",mf->nr_of_files, gg.gl_pathc * sizeof( char* ) );
113 for( i=0;i < gg.gl_pathc;i++ )
115 stat( gg.gl_pathv[i],&fs );
116 if( S_ISDIR( fs.st_mode ) ) continue;
117 mf->names[i]=strdup( gg.gl_pathv[i] );
118 // mp_msg( MSGT_STREAM,MSGL_DBG2,"[mf] added file %d.: %s\n",i,mf->names[i] );
120 globfree( &gg );
121 goto exit_mf;
124 mp_msg( MSGT_STREAM,MSGL_INFO,"[mf] search expr: %s\n",filename );
126 while ( error_count < 5 )
128 sprintf( fname,filename,count++ );
129 if ( stat( fname,&fs ) )
131 error_count++;
132 mp_msg( MSGT_STREAM,MSGL_V,"[mf] file not found: '%s'\n",fname );
134 else
136 mf->names=realloc( mf->names,( mf->nr_of_files + 1 ) * sizeof( char* ) );
137 mf->names[mf->nr_of_files]=strdup( fname );
138 // mp_msg( MSGT_STREAM,MSGL_V,"[mf] added file %d.: %s\n",mf->nr_of_files,mf->names[mf->nr_of_files] );
139 mf->nr_of_files++;
143 mp_msg( MSGT_STREAM,MSGL_INFO,"[mf] number of files: %d\n",mf->nr_of_files );
145 exit_mf:
146 free( fname );
147 return mf;
148 #else
149 mp_msg(MSGT_STREAM,MSGL_FATAL,"[mf] mf support is disabled on your os\n");
150 return 0;
151 #endif