sd_ass: initialize structs for external tracks properly
[mplayer.git] / libmpdemux / mf.c
blobd232944593c1f9a998b7496c5b2d8902bad2af74
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>
29 #include "osdep/io.h"
31 #include "config.h"
33 #ifdef HAVE_GLOB
34 #include <glob.h>
35 #else
36 #include "osdep/glob.h"
37 #endif
38 #include "osdep/strsep.h"
40 #include "mp_msg.h"
41 #include "stream/stream.h"
42 #include "path.h"
44 #include "mf.h"
46 int mf_w = 0; //352; // let codecs to detect it
47 int mf_h = 0; //288;
48 double mf_fps = 25.0;
49 char * mf_type = NULL; //"jpg";
51 mf_t* open_mf(char * filename){
52 #if defined(HAVE_GLOB) || defined(__MINGW32__)
53 glob_t gg;
54 int i;
55 char * fname;
56 mf_t * mf;
57 int error_count = 0;
58 int count = 0;
60 mf=calloc( 1,sizeof( mf_t ) );
62 if( filename[0] == '@' )
64 FILE *lst_f=fopen(filename + 1,"r");
65 if ( lst_f )
67 fname=malloc(MP_PATH_MAX);
68 while ( fgets( fname,MP_PATH_MAX,lst_f ) )
70 /* remove spaces from end of fname */
71 char *t=fname + strlen( fname ) - 1;
72 while ( t > fname && isspace( *t ) ) *(t--)=0;
73 if ( !mp_path_exists( fname ) )
75 mp_msg( MSGT_STREAM,MSGL_V,"[mf] file not found: '%s'\n",fname );
77 else
79 mf->names=realloc( mf->names,( mf->nr_of_files + 1 ) * sizeof( char* ) );
80 mf->names[mf->nr_of_files]=strdup( fname );
81 mf->nr_of_files++;
84 fclose( lst_f );
86 mp_msg( MSGT_STREAM,MSGL_INFO,"[mf] number of files: %d\n",mf->nr_of_files );
87 goto exit_mf;
89 mp_msg( MSGT_STREAM,MSGL_INFO,"[mf] %s is not indirect filelist\n",filename+1 );
92 if( strchr( filename,',') )
94 mp_msg( MSGT_STREAM,MSGL_INFO,"[mf] filelist: %s\n",filename );
96 while ( ( fname=strsep( &filename,"," ) ) )
98 if ( !mp_path_exists( fname ) )
100 mp_msg( MSGT_STREAM,MSGL_V,"[mf] file not found: '%s'\n",fname );
102 else
104 mf->names=realloc( mf->names,( mf->nr_of_files + 1 ) * sizeof( char* ) );
105 mf->names[mf->nr_of_files]=strdup( fname );
106 // mp_msg( MSGT_STREAM,MSGL_V,"[mf] added file %d.: %s\n",mf->nr_of_files,mf->names[mf->nr_of_files] );
107 mf->nr_of_files++;
110 mp_msg( MSGT_STREAM,MSGL_INFO,"[mf] number of files: %d\n",mf->nr_of_files );
112 goto exit_mf;
115 fname=malloc( strlen( filename ) + 32 );
117 if ( !strchr( filename,'%' ) )
119 strcpy( fname,filename );
120 if ( !strchr( filename,'*' ) ) strcat( fname,"*" );
122 mp_msg( MSGT_STREAM,MSGL_INFO,"[mf] search expr: %s\n",fname );
124 if ( glob( fname,0,NULL,&gg ) )
125 { free( mf ); free( fname ); return NULL; }
127 mf->nr_of_files=gg.gl_pathc;
128 mf->names=calloc( gg.gl_pathc, sizeof( char* ) );
130 mp_msg( MSGT_STREAM,MSGL_INFO,"[mf] number of files: %d (%zd)\n",mf->nr_of_files, gg.gl_pathc * sizeof( char* ) );
132 for( i=0;i < gg.gl_pathc;i++ )
134 if (mp_path_isdir(gg.gl_pathv[i]))
135 continue;
136 mf->names[i]=strdup( gg.gl_pathv[i] );
137 // mp_msg( MSGT_STREAM,MSGL_DBG2,"[mf] added file %d.: %s\n",i,mf->names[i] );
139 globfree( &gg );
140 goto exit_mf;
143 mp_msg( MSGT_STREAM,MSGL_INFO,"[mf] search expr: %s\n",filename );
145 while ( error_count < 5 )
147 sprintf( fname,filename,count++ );
148 if ( !mp_path_exists( fname ) )
150 error_count++;
151 mp_msg( MSGT_STREAM,MSGL_V,"[mf] file not found: '%s'\n",fname );
153 else
155 mf->names=realloc( mf->names,( mf->nr_of_files + 1 ) * sizeof( char* ) );
156 mf->names[mf->nr_of_files]=strdup( fname );
157 // mp_msg( MSGT_STREAM,MSGL_V,"[mf] added file %d.: %s\n",mf->nr_of_files,mf->names[mf->nr_of_files] );
158 mf->nr_of_files++;
162 mp_msg( MSGT_STREAM,MSGL_INFO,"[mf] number of files: %d\n",mf->nr_of_files );
164 exit_mf:
165 free( fname );
166 return mf;
167 #else
168 mp_msg(MSGT_STREAM,MSGL_FATAL,"[mf] mf support is disabled on your os\n");
169 return 0;
170 #endif