Mercurial > mplayer.hg
annotate libmpdemux/mf.c @ 36802:621b61818a0f
configure: add -Zhigh-mem linker flag for OS/2
x264 encoder crashes due to memory allocation failure. This fixes the problem.
author | komh |
---|---|
date | Thu, 20 Feb 2014 13:59:34 +0000 |
parents | 9b4ba0fb999b |
children |
rev | line source |
---|---|
29238
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
25964
diff
changeset
|
1 /* |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
25964
diff
changeset
|
2 * This file is part of MPlayer. |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
25964
diff
changeset
|
3 * |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
25964
diff
changeset
|
4 * MPlayer is free software; you can redistribute it and/or modify |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
25964
diff
changeset
|
5 * it under the terms of the GNU General Public License as published by |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
25964
diff
changeset
|
6 * the Free Software Foundation; either version 2 of the License, or |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
25964
diff
changeset
|
7 * (at your option) any later version. |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
25964
diff
changeset
|
8 * |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
25964
diff
changeset
|
9 * MPlayer is distributed in the hope that it will be useful, |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
25964
diff
changeset
|
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
25964
diff
changeset
|
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
25964
diff
changeset
|
12 * GNU General Public License for more details. |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
25964
diff
changeset
|
13 * |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
25964
diff
changeset
|
14 * You should have received a copy of the GNU General Public License along |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
25964
diff
changeset
|
15 * with MPlayer; if not, write to the Free Software Foundation, Inc., |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
25964
diff
changeset
|
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
25964
diff
changeset
|
17 */ |
19300 | 18 |
35951 | 19 #define _BSD_SOURCE |
20 | |
19300 | 21 #include <ctype.h> |
22 #include <stdio.h> | |
23 #include <stdlib.h> | |
24 #include <string.h> | |
25 #include <unistd.h> | |
26 #include <fcntl.h> | |
27 #include <errno.h> | |
32679 | 28 #include <limits.h> |
19300 | 29 #include <sys/types.h> |
30 #include <sys/stat.h> | |
31 | |
32 #include "config.h" | |
33 | |
34 #ifdef HAVE_GLOB | |
35 #include <glob.h> | |
36 #else | |
37 #include "osdep/glob.h" | |
38 #endif | |
30313
7f7591482564
Add a proper header for our strsep implementation so strsep will
reimar
parents:
29263
diff
changeset
|
39 #include "osdep/strsep.h" |
19300 | 40 |
41 #include "mp_msg.h" | |
42 #include "help_mp.h" | |
22605
4d81dbdf46b9
Add explicit location for headers from the stream/ directory.
diego
parents:
19300
diff
changeset
|
43 #include "stream/stream.h" |
19300 | 44 |
45 #include "mf.h" | |
46 | |
47 int mf_w = 0; //352; // let codecs to detect it | |
48 int mf_h = 0; //288; | |
25964 | 49 double mf_fps = 25.0; |
19300 | 50 char * mf_type = NULL; //"jpg"; |
51 | |
52 mf_t* open_mf(char * filename){ | |
53 #if defined(HAVE_GLOB) || defined(__MINGW32__) | |
54 glob_t gg; | |
55 struct stat fs; | |
56 int i; | |
57 char * fname; | |
58 mf_t * mf; | |
59 int error_count = 0; | |
60 int count = 0; | |
61 | |
62 mf=calloc( 1,sizeof( mf_t ) ); | |
63 | |
64 if( filename[0] == '@' ) | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29238
diff
changeset
|
65 { |
19300 | 66 FILE *lst_f=fopen(filename + 1,"r"); |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29238
diff
changeset
|
67 if ( lst_f ) |
19300 | 68 { |
32679 | 69 fname=malloc(PATH_MAX); |
70 while ( fgets( fname,PATH_MAX,lst_f ) ) | |
19300 | 71 { |
72 /* remove spaces from end of fname */ | |
73 char *t=fname + strlen( fname ) - 1; | |
74 while ( t > fname && isspace( *t ) ) *(t--)=0; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29238
diff
changeset
|
75 if ( stat( fname,&fs ) ) |
19300 | 76 { |
77 mp_msg( MSGT_STREAM,MSGL_V,"[mf] file not found: '%s'\n",fname ); | |
78 } | |
79 else | |
80 { | |
81 mf->names=realloc( mf->names,( mf->nr_of_files + 1 ) * sizeof( char* ) ); | |
82 mf->names[mf->nr_of_files]=strdup( fname ); | |
83 mf->nr_of_files++; | |
84 } | |
85 } | |
86 fclose( lst_f ); | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29238
diff
changeset
|
87 |
19300 | 88 mp_msg( MSGT_STREAM,MSGL_INFO,"[mf] number of files: %d\n",mf->nr_of_files ); |
89 goto exit_mf; | |
90 } | |
91 mp_msg( MSGT_STREAM,MSGL_INFO,"[mf] %s is not indirect filelist\n",filename+1 ); | |
92 } | |
93 | |
94 if( strchr( filename,',') ) | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29238
diff
changeset
|
95 { |
19300 | 96 mp_msg( MSGT_STREAM,MSGL_INFO,"[mf] filelist: %s\n",filename ); |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29238
diff
changeset
|
97 |
19300 | 98 while ( ( fname=strsep( &filename,"," ) ) ) |
99 { | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29238
diff
changeset
|
100 if ( stat( fname,&fs ) ) |
19300 | 101 { |
102 mp_msg( MSGT_STREAM,MSGL_V,"[mf] file not found: '%s'\n",fname ); | |
103 } | |
104 else | |
105 { | |
106 mf->names=realloc( mf->names,( mf->nr_of_files + 1 ) * sizeof( char* ) ); | |
107 mf->names[mf->nr_of_files]=strdup( fname ); | |
108 // mp_msg( MSGT_STREAM,MSGL_V,"[mf] added file %d.: %s\n",mf->nr_of_files,mf->names[mf->nr_of_files] ); | |
109 mf->nr_of_files++; | |
110 } | |
111 } | |
112 mp_msg( MSGT_STREAM,MSGL_INFO,"[mf] number of files: %d\n",mf->nr_of_files ); | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29238
diff
changeset
|
113 |
19300 | 114 goto exit_mf; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29238
diff
changeset
|
115 } |
19300 | 116 |
117 fname=malloc( strlen( filename ) + 32 ); | |
118 | |
119 if ( !strchr( filename,'%' ) ) | |
120 { | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29238
diff
changeset
|
121 strcpy( fname,filename ); |
19300 | 122 if ( !strchr( filename,'*' ) ) strcat( fname,"*" ); |
123 | |
124 mp_msg( MSGT_STREAM,MSGL_INFO,"[mf] search expr: %s\n",fname ); | |
125 | |
126 if ( glob( fname,0,NULL,&gg ) ) | |
127 { free( mf ); free( fname ); return NULL; } | |
128 | |
129 mf->nr_of_files=gg.gl_pathc; | |
130 mf->names=calloc( gg.gl_pathc, sizeof( char* ) ); | |
131 | |
33841
25667edae85c
cleanup: adjust printf format strings to match parameter types
diego
parents:
32679
diff
changeset
|
132 mp_msg( MSGT_STREAM, MSGL_INFO, "[mf] number of files: %d (%zu)\n", mf->nr_of_files, gg.gl_pathc * sizeof( char* ) ); |
19300 | 133 |
134 for( i=0;i < gg.gl_pathc;i++ ) | |
135 { | |
136 stat( gg.gl_pathv[i],&fs ); | |
137 if( S_ISDIR( fs.st_mode ) ) continue; | |
138 mf->names[i]=strdup( gg.gl_pathv[i] ); | |
139 // mp_msg( MSGT_STREAM,MSGL_DBG2,"[mf] added file %d.: %s\n",i,mf->names[i] ); | |
140 } | |
141 globfree( &gg ); | |
142 goto exit_mf; | |
143 } | |
144 | |
145 mp_msg( MSGT_STREAM,MSGL_INFO,"[mf] search expr: %s\n",filename ); | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29238
diff
changeset
|
146 |
19300 | 147 while ( error_count < 5 ) |
148 { | |
149 sprintf( fname,filename,count++ ); | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29238
diff
changeset
|
150 if ( stat( fname,&fs ) ) |
19300 | 151 { |
152 error_count++; | |
153 mp_msg( MSGT_STREAM,MSGL_V,"[mf] file not found: '%s'\n",fname ); | |
154 } | |
155 else | |
156 { | |
157 mf->names=realloc( mf->names,( mf->nr_of_files + 1 ) * sizeof( char* ) ); | |
158 mf->names[mf->nr_of_files]=strdup( fname ); | |
159 // mp_msg( MSGT_STREAM,MSGL_V,"[mf] added file %d.: %s\n",mf->nr_of_files,mf->names[mf->nr_of_files] ); | |
160 mf->nr_of_files++; | |
161 } | |
162 } | |
163 | |
164 mp_msg( MSGT_STREAM,MSGL_INFO,"[mf] number of files: %d\n",mf->nr_of_files ); | |
165 | |
166 exit_mf: | |
167 free( fname ); | |
168 return mf; | |
169 #else | |
170 mp_msg(MSGT_STREAM,MSGL_FATAL,"[mf] mf support is disabled on your os\n"); | |
171 return 0; | |
172 #endif | |
173 } |