annotate libmpdemux/mf.c @ 26807:1b34360d41de

In case 2 styles have the same name, prefer the latest one.
author eugeni
date Mon, 19 May 2008 18:37:27 +0000
parents cb07fc632de1
children d643e4643313
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
19300
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
1
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
2 #include <ctype.h>
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
3 #include <stdio.h>
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
4 #include <stdlib.h>
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
5 #include <string.h>
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
6 #include <unistd.h>
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
7 #include <fcntl.h>
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
8 #include <errno.h>
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
9 #include <sys/types.h>
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
10 #include <sys/stat.h>
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
11
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
12 #include "config.h"
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
13
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
14 #ifdef HAVE_GLOB
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
15 #include <glob.h>
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
16 #else
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
17 #include "osdep/glob.h"
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
18 #endif
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
19
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
20 #include "mp_msg.h"
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
21 #include "help_mp.h"
22605
4d81dbdf46b9 Add explicit location for headers from the stream/ directory.
diego
parents: 19300
diff changeset
22 #include "stream/stream.h"
19300
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
23
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
24 #include "mf.h"
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
25
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
26 int mf_w = 0; //352; // let codecs to detect it
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
27 int mf_h = 0; //288;
25964
cb07fc632de1 Change mf_fps to double
reimar
parents: 22605
diff changeset
28 double mf_fps = 25.0;
19300
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
29 char * mf_type = NULL; //"jpg";
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
30
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
31 mf_t* open_mf(char * filename){
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
32 #if defined(HAVE_GLOB) || defined(__MINGW32__)
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
33 glob_t gg;
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
34 struct stat fs;
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
35 int i;
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
36 char * fname;
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
37 mf_t * mf;
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
38 int error_count = 0;
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
39 int count = 0;
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
40
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
41 mf=calloc( 1,sizeof( mf_t ) );
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
42
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
43 if( filename[0] == '@' )
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
44 {
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
45 FILE *lst_f=fopen(filename + 1,"r");
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
46 if ( lst_f )
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
47 {
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
48 fname=malloc( 255 );
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
49 while ( fgets( fname,255,lst_f ) )
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
50 {
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
51 /* remove spaces from end of fname */
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
52 char *t=fname + strlen( fname ) - 1;
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
53 while ( t > fname && isspace( *t ) ) *(t--)=0;
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
54 if ( stat( fname,&fs ) )
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
55 {
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
56 mp_msg( MSGT_STREAM,MSGL_V,"[mf] file not found: '%s'\n",fname );
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
57 }
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
58 else
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
59 {
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
60 mf->names=realloc( mf->names,( mf->nr_of_files + 1 ) * sizeof( char* ) );
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
61 mf->names[mf->nr_of_files]=strdup( fname );
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
62 mf->nr_of_files++;
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
63 }
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
64 }
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
65 fclose( lst_f );
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
66
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
67 mp_msg( MSGT_STREAM,MSGL_INFO,"[mf] number of files: %d\n",mf->nr_of_files );
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
68 goto exit_mf;
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
69 }
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
70 mp_msg( MSGT_STREAM,MSGL_INFO,"[mf] %s is not indirect filelist\n",filename+1 );
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
71 }
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
72
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
73 if( strchr( filename,',') )
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
74 {
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
75 mp_msg( MSGT_STREAM,MSGL_INFO,"[mf] filelist: %s\n",filename );
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
76
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
77 while ( ( fname=strsep( &filename,"," ) ) )
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
78 {
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
79 if ( stat( fname,&fs ) )
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
80 {
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
81 mp_msg( MSGT_STREAM,MSGL_V,"[mf] file not found: '%s'\n",fname );
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
82 }
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
83 else
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
84 {
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
85 mf->names=realloc( mf->names,( mf->nr_of_files + 1 ) * sizeof( char* ) );
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
86 mf->names[mf->nr_of_files]=strdup( fname );
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
87 // mp_msg( MSGT_STREAM,MSGL_V,"[mf] added file %d.: %s\n",mf->nr_of_files,mf->names[mf->nr_of_files] );
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
88 mf->nr_of_files++;
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
89 }
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
90 }
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
91 mp_msg( MSGT_STREAM,MSGL_INFO,"[mf] number of files: %d\n",mf->nr_of_files );
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
92
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
93 goto exit_mf;
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
94 }
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
95
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
96 fname=malloc( strlen( filename ) + 32 );
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
97
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
98 if ( !strchr( filename,'%' ) )
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
99 {
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
100 strcpy( fname,filename );
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
101 if ( !strchr( filename,'*' ) ) strcat( fname,"*" );
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
102
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
103 mp_msg( MSGT_STREAM,MSGL_INFO,"[mf] search expr: %s\n",fname );
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
104
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
105 if ( glob( fname,0,NULL,&gg ) )
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
106 { free( mf ); free( fname ); return NULL; }
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
107
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
108 mf->nr_of_files=gg.gl_pathc;
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
109 mf->names=calloc( gg.gl_pathc, sizeof( char* ) );
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
110
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
111 mp_msg( MSGT_STREAM,MSGL_INFO,"[mf] number of files: %d (%d)\n",mf->nr_of_files, gg.gl_pathc * sizeof( char* ) );
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
112
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
113 for( i=0;i < gg.gl_pathc;i++ )
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
114 {
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
115 stat( gg.gl_pathv[i],&fs );
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
116 if( S_ISDIR( fs.st_mode ) ) continue;
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
117 mf->names[i]=strdup( gg.gl_pathv[i] );
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
118 // mp_msg( MSGT_STREAM,MSGL_DBG2,"[mf] added file %d.: %s\n",i,mf->names[i] );
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
119 }
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
120 globfree( &gg );
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
121 goto exit_mf;
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
122 }
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
123
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
124 mp_msg( MSGT_STREAM,MSGL_INFO,"[mf] search expr: %s\n",filename );
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
125
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
126 while ( error_count < 5 )
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
127 {
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
128 sprintf( fname,filename,count++ );
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
129 if ( stat( fname,&fs ) )
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
130 {
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
131 error_count++;
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
132 mp_msg( MSGT_STREAM,MSGL_V,"[mf] file not found: '%s'\n",fname );
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
133 }
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
134 else
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
135 {
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
136 mf->names=realloc( mf->names,( mf->nr_of_files + 1 ) * sizeof( char* ) );
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
137 mf->names[mf->nr_of_files]=strdup( fname );
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
138 // mp_msg( MSGT_STREAM,MSGL_V,"[mf] added file %d.: %s\n",mf->nr_of_files,mf->names[mf->nr_of_files] );
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
139 mf->nr_of_files++;
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
140 }
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
141 }
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
142
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
143 mp_msg( MSGT_STREAM,MSGL_INFO,"[mf] number of files: %d\n",mf->nr_of_files );
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
144
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
145 exit_mf:
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
146 free( fname );
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
147 return mf;
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
148 #else
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
149 mp_msg(MSGT_STREAM,MSGL_FATAL,"[mf] mf support is disabled on your os\n");
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
150 return 0;
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
151 #endif
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
152 }
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
153