annotate libmpdemux/mf.c @ 34435:f28606bb351b

Support for Avid Meridian Uncompressed via FFmpeg. Patch by Paul B Mahol, onemda gmail
author cehoyos
date Thu, 05 Jan 2012 20:18:38 +0000
parents 25667edae85c
children 9b4ba0fb999b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
18
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
19 #include <ctype.h>
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
20 #include <stdio.h>
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
21 #include <stdlib.h>
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
22 #include <string.h>
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
23 #include <unistd.h>
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
24 #include <fcntl.h>
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
25 #include <errno.h>
32679
fcd252bdedd0 Don't hardcode filename length.
ranma
parents: 30633
diff changeset
26 #include <limits.h>
19300
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
27 #include <sys/types.h>
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
28 #include <sys/stat.h>
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
29
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
30 #include "config.h"
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
31
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
32 #ifdef HAVE_GLOB
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
33 #include <glob.h>
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
34 #else
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
35 #include "osdep/glob.h"
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
36 #endif
30313
7f7591482564 Add a proper header for our strsep implementation so strsep will
reimar
parents: 29263
diff changeset
37 #include "osdep/strsep.h"
19300
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
38
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
39 #include "mp_msg.h"
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
40 #include "help_mp.h"
22605
4d81dbdf46b9 Add explicit location for headers from the stream/ directory.
diego
parents: 19300
diff changeset
41 #include "stream/stream.h"
19300
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
42
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
43 #include "mf.h"
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
44
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
45 int mf_w = 0; //352; // let codecs to detect it
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
46 int mf_h = 0; //288;
25964
cb07fc632de1 Change mf_fps to double
reimar
parents: 22605
diff changeset
47 double mf_fps = 25.0;
19300
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
48 char * mf_type = NULL; //"jpg";
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
49
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
50 mf_t* open_mf(char * filename){
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
51 #if defined(HAVE_GLOB) || defined(__MINGW32__)
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
52 glob_t gg;
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
53 struct stat fs;
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
54 int i;
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
55 char * fname;
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
56 mf_t * mf;
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
57 int error_count = 0;
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
58 int count = 0;
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
59
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
60 mf=calloc( 1,sizeof( mf_t ) );
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
61
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
62 if( filename[0] == '@' )
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29238
diff changeset
63 {
19300
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
64 FILE *lst_f=fopen(filename + 1,"r");
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29238
diff changeset
65 if ( lst_f )
19300
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
66 {
32679
fcd252bdedd0 Don't hardcode filename length.
ranma
parents: 30633
diff changeset
67 fname=malloc(PATH_MAX);
fcd252bdedd0 Don't hardcode filename length.
ranma
parents: 30633
diff changeset
68 while ( fgets( fname,PATH_MAX,lst_f ) )
19300
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
69 {
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
70 /* remove spaces from end of fname */
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
71 char *t=fname + strlen( fname ) - 1;
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
72 while ( t > fname && isspace( *t ) ) *(t--)=0;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29238
diff changeset
73 if ( stat( fname,&fs ) )
19300
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_V,"[mf] file not found: '%s'\n",fname );
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
76 }
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
77 else
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
78 {
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
79 mf->names=realloc( mf->names,( mf->nr_of_files + 1 ) * sizeof( char* ) );
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
80 mf->names[mf->nr_of_files]=strdup( fname );
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
81 mf->nr_of_files++;
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
82 }
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
83 }
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
84 fclose( lst_f );
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29238
diff changeset
85
19300
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
86 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
87 goto exit_mf;
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
88 }
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
89 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
90 }
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
91
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
92 if( strchr( filename,',') )
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29238
diff changeset
93 {
19300
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
94 mp_msg( MSGT_STREAM,MSGL_INFO,"[mf] filelist: %s\n",filename );
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29238
diff changeset
95
19300
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
96 while ( ( fname=strsep( &filename,"," ) ) )
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
97 {
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29238
diff changeset
98 if ( stat( fname,&fs ) )
19300
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
99 {
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
100 mp_msg( MSGT_STREAM,MSGL_V,"[mf] file not found: '%s'\n",fname );
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
101 }
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
102 else
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
103 {
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
104 mf->names=realloc( mf->names,( mf->nr_of_files + 1 ) * sizeof( char* ) );
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
105 mf->names[mf->nr_of_files]=strdup( fname );
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
106 // 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
107 mf->nr_of_files++;
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
108 }
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
109 }
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
110 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
111
19300
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
112 goto exit_mf;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29238
diff changeset
113 }
19300
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
114
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
115 fname=malloc( strlen( filename ) + 32 );
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
116
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
117 if ( !strchr( filename,'%' ) )
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
118 {
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29238
diff changeset
119 strcpy( fname,filename );
19300
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
120 if ( !strchr( filename,'*' ) ) strcat( fname,"*" );
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
121
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
122 mp_msg( MSGT_STREAM,MSGL_INFO,"[mf] search expr: %s\n",fname );
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
123
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
124 if ( glob( fname,0,NULL,&gg ) )
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
125 { free( mf ); free( fname ); return NULL; }
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
126
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
127 mf->nr_of_files=gg.gl_pathc;
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
128 mf->names=calloc( gg.gl_pathc, sizeof( char* ) );
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
129
33841
25667edae85c cleanup: adjust printf format strings to match parameter types
diego
parents: 32679
diff changeset
130 mp_msg( MSGT_STREAM, MSGL_INFO, "[mf] number of files: %d (%zu)\n", mf->nr_of_files, gg.gl_pathc * sizeof( char* ) );
19300
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
131
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
132 for( i=0;i < gg.gl_pathc;i++ )
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
133 {
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
134 stat( gg.gl_pathv[i],&fs );
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
135 if( S_ISDIR( fs.st_mode ) ) continue;
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
136 mf->names[i]=strdup( gg.gl_pathv[i] );
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
137 // 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
138 }
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
139 globfree( &gg );
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
140 goto exit_mf;
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] search expr: %s\n",filename );
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29238
diff changeset
144
19300
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
145 while ( error_count < 5 )
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
146 {
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
147 sprintf( fname,filename,count++ );
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29238
diff changeset
148 if ( stat( fname,&fs ) )
19300
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
149 {
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
150 error_count++;
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
151 mp_msg( MSGT_STREAM,MSGL_V,"[mf] file not found: '%s'\n",fname );
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
152 }
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
153 else
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
154 {
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
155 mf->names=realloc( mf->names,( mf->nr_of_files + 1 ) * sizeof( char* ) );
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
156 mf->names[mf->nr_of_files]=strdup( fname );
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
157 // 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
158 mf->nr_of_files++;
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
159 }
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
160 }
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
161
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
162 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
163
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
164 exit_mf:
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
165 free( fname );
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
166 return mf;
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
167 #else
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
168 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
169 return 0;
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
170 #endif
0c7ad1c632cc mf.[hc] belong to libmpdemux
ben
parents:
diff changeset
171 }