cleanup: Silence compilation warnings on MinGW-w64
[mplayer.git] / libmpdemux / mf.c
blob6b22c6147df2389ef6e59b7837f4ab7b94202666
1 /*
2 * This file is part of MPlayer.
4 * MPlayer is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * MPlayer is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 #include <ctype.h>
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <string.h>
23 #include <unistd.h>
24 #include <fcntl.h>
25 #include <errno.h>
26 #include <limits.h>
27 #include <sys/types.h>
28 #include <sys/stat.h>
30 #include "config.h"
32 #ifdef HAVE_GLOB
33 #include <glob.h>
34 #else
35 #include "osdep/glob.h"
36 #endif
37 #include "osdep/strsep.h"
39 #include "mp_msg.h"
40 #include "stream/stream.h"
42 #include "mf.h"
44 int mf_w = 0; //352; // let codecs to detect it
45 int mf_h = 0; //288;
46 double mf_fps = 25.0;
47 char * mf_type = NULL; //"jpg";
49 mf_t* open_mf(char * filename){
50 #if defined(HAVE_GLOB) || defined(__MINGW32__)
51 glob_t gg;
52 struct stat fs;
53 int i;
54 char * fname;
55 mf_t * mf;
56 int error_count = 0;
57 int count = 0;
59 mf=calloc( 1,sizeof( mf_t ) );
61 if( filename[0] == '@' )
63 FILE *lst_f=fopen(filename + 1,"r");
64 if ( lst_f )
66 fname=malloc(PATH_MAX);
67 while ( fgets( fname,PATH_MAX,lst_f ) )
69 /* remove spaces from end of fname */
70 char *t=fname + strlen( fname ) - 1;
71 while ( t > fname && isspace( *t ) ) *(t--)=0;
72 if ( stat( fname,&fs ) )
74 mp_msg( MSGT_STREAM,MSGL_V,"[mf] file not found: '%s'\n",fname );
76 else
78 mf->names=realloc( mf->names,( mf->nr_of_files + 1 ) * sizeof( char* ) );
79 mf->names[mf->nr_of_files]=strdup( fname );
80 mf->nr_of_files++;
83 fclose( lst_f );
85 mp_msg( MSGT_STREAM,MSGL_INFO,"[mf] number of files: %d\n",mf->nr_of_files );
86 goto exit_mf;
88 mp_msg( MSGT_STREAM,MSGL_INFO,"[mf] %s is not indirect filelist\n",filename+1 );
91 if( strchr( filename,',') )
93 mp_msg( MSGT_STREAM,MSGL_INFO,"[mf] filelist: %s\n",filename );
95 while ( ( fname=strsep( &filename,"," ) ) )
97 if ( stat( fname,&fs ) )
99 mp_msg( MSGT_STREAM,MSGL_V,"[mf] file not found: '%s'\n",fname );
101 else
103 mf->names=realloc( mf->names,( mf->nr_of_files + 1 ) * sizeof( char* ) );
104 mf->names[mf->nr_of_files]=strdup( fname );
105 // mp_msg( MSGT_STREAM,MSGL_V,"[mf] added file %d.: %s\n",mf->nr_of_files,mf->names[mf->nr_of_files] );
106 mf->nr_of_files++;
109 mp_msg( MSGT_STREAM,MSGL_INFO,"[mf] number of files: %d\n",mf->nr_of_files );
111 goto exit_mf;
114 fname=malloc( strlen( filename ) + 32 );
116 if ( !strchr( filename,'%' ) )
118 strcpy( fname,filename );
119 if ( !strchr( filename,'*' ) ) strcat( fname,"*" );
121 mp_msg( MSGT_STREAM,MSGL_INFO,"[mf] search expr: %s\n",fname );
123 if ( glob( fname,0,NULL,&gg ) )
124 { free( mf ); free( fname ); return NULL; }
126 mf->nr_of_files=gg.gl_pathc;
127 mf->names=calloc( gg.gl_pathc, sizeof( char* ) );
129 mp_msg( MSGT_STREAM,MSGL_INFO,"[mf] number of files: %d (%zd)\n",mf->nr_of_files, gg.gl_pathc * sizeof( char* ) );
131 for( i=0;i < gg.gl_pathc;i++ )
133 stat( gg.gl_pathv[i],&fs );
134 if( S_ISDIR( fs.st_mode ) ) continue;
135 mf->names[i]=strdup( gg.gl_pathv[i] );
136 // mp_msg( MSGT_STREAM,MSGL_DBG2,"[mf] added file %d.: %s\n",i,mf->names[i] );
138 globfree( &gg );
139 goto exit_mf;
142 mp_msg( MSGT_STREAM,MSGL_INFO,"[mf] search expr: %s\n",filename );
144 while ( error_count < 5 )
146 sprintf( fname,filename,count++ );
147 if ( stat( fname,&fs ) )
149 error_count++;
150 mp_msg( MSGT_STREAM,MSGL_V,"[mf] file not found: '%s'\n",fname );
152 else
154 mf->names=realloc( mf->names,( mf->nr_of_files + 1 ) * sizeof( char* ) );
155 mf->names[mf->nr_of_files]=strdup( fname );
156 // mp_msg( MSGT_STREAM,MSGL_V,"[mf] added file %d.: %s\n",mf->nr_of_files,mf->names[mf->nr_of_files] );
157 mf->nr_of_files++;
161 mp_msg( MSGT_STREAM,MSGL_INFO,"[mf] number of files: %d\n",mf->nr_of_files );
163 exit_mf:
164 free( fname );
165 return mf;
166 #else
167 mp_msg(MSGT_STREAM,MSGL_FATAL,"[mf] mf support is disabled on your os\n");
168 return 0;
169 #endif