~ubuntu-branches/ubuntu/vivid/mpv/vivid

« back to all changes in this revision

Viewing changes to demux/mf.c

  • Committer: Package Import Robot
  • Author(s): Alessandro Ghedini
  • Date: 2013-12-29 20:04:26 UTC
  • mfrom: (1.1.9)
  • Revision ID: package-import@ubuntu.com-20131229200426-w0qsj8clnui1pxaw
Tags: 0.3.0-1
* New upstream release
  - Fix --vf=expand example in manpage (Closes: #732271)
* Add 03_waf.patch to provide uncompressed waf scripts and modules
* Switch to waf build script
* Drop libmng-dev Build-Depends (not used anymore)
* Bump Standards-Version to 3.9.5 (no changes needed)
* Enable support for dvdnav
* Install more docs

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
 
31
31
#include "config.h"
32
32
 
33
 
#ifdef HAVE_GLOB
 
33
#if HAVE_GLOB
34
34
#include <glob.h>
35
35
#else
36
36
#include "osdep/glob.h"
37
37
#endif
38
38
 
39
 
#include "mpvcore/mp_msg.h"
 
39
#include "talloc.h"
 
40
#include "common/msg.h"
40
41
#include "stream/stream.h"
41
 
#include "mpvcore/path.h"
 
42
#include "options/path.h"
42
43
 
43
44
#include "mf.h"
44
45
 
45
 
double mf_fps = 25.0;
46
 
char * mf_type = NULL; //"jpg";
47
 
 
48
 
mf_t* open_mf_pattern(char * filename)
 
46
double mf_fps = 1.0;
 
47
char *mf_type = NULL;  //"jpg";
 
48
 
 
49
static void mf_add(mf_t *mf, const char *fname)
 
50
{
 
51
    char *entry = talloc_strdup(mf, fname);
 
52
    MP_TARRAY_APPEND(mf, mf->names, mf->nr_of_files, entry);
 
53
}
 
54
 
 
55
mf_t *open_mf_pattern(void *talloc_ctx, struct mp_log *log, char *filename)
49
56
{
50
57
#if defined(HAVE_GLOB) || defined(__MINGW32__)
51
 
 glob_t        gg;
52
 
 int           i;
53
 
 char        * fname = NULL;
54
 
 mf_t        * mf;
55
 
 int           error_count = 0;
56
 
 int           count = 0;
57
 
 
58
 
 mf=calloc( 1,sizeof( mf_t ) );
59
 
 
60
 
 if( filename[0] == '@' )
61
 
  {
62
 
   FILE *lst_f=fopen(filename + 1,"r");
63
 
   if ( lst_f )
64
 
    {
65
 
     fname=malloc(MP_PATH_MAX);
66
 
     while ( fgets( fname,MP_PATH_MAX,lst_f ) )
67
 
      {
68
 
       /* remove spaces from end of fname */
69
 
       char *t=fname + strlen( fname ) - 1;
70
 
       while ( t > fname && isspace( *t ) ) *(t--)=0;
71
 
       if ( !mp_path_exists( fname ) )
72
 
        {
73
 
         mp_msg( MSGT_STREAM,MSGL_V,"[mf] file not found: '%s'\n",fname );
74
 
        }
75
 
        else
76
 
        {
77
 
         mf->names=realloc( mf->names,( mf->nr_of_files + 1 ) * sizeof( char* ) );
78
 
         mf->names[mf->nr_of_files]=strdup( fname );
79
 
         mf->nr_of_files++;
80
 
        }
81
 
      }
82
 
      fclose( lst_f );
83
 
 
84
 
      mp_msg( MSGT_STREAM,MSGL_INFO,"[mf] number of files: %d\n",mf->nr_of_files );
85
 
      goto exit_mf;
86
 
    }
87
 
    mp_msg( MSGT_STREAM,MSGL_INFO,"[mf] %s is not indirect filelist\n",filename+1 );
88
 
  }
89
 
 
90
 
 if( strchr( filename,',') )
91
 
  {
92
 
   mp_msg( MSGT_STREAM,MSGL_INFO,"[mf] filelist: %s\n",filename );
93
 
   bstr bfilename = bstr0(filename);
94
 
 
95
 
   while (bfilename.len)
96
 
    {
97
 
     bstr bfname;
98
 
     bstr_split_tok(bfilename, ",", &bfname, &bfilename);
99
 
     char *fname2 = bstrdup0(NULL, bfname);
100
 
 
101
 
     if ( !mp_path_exists( fname2 ) )
102
 
      {
103
 
       mp_msg( MSGT_STREAM,MSGL_V,"[mf] file not found: '%s'\n",fname2 );
104
 
      }
105
 
      else
106
 
      {
107
 
       mf->names=realloc( mf->names,( mf->nr_of_files + 1 ) * sizeof( char* ) );
108
 
       mf->names[mf->nr_of_files] = strdup(fname2);
109
 
//       mp_msg( MSGT_STREAM,MSGL_V,"[mf] added file %d.: %s\n",mf->nr_of_files,mf->names[mf->nr_of_files] );
110
 
       mf->nr_of_files++;
111
 
      }
112
 
      talloc_free(fname2);
113
 
    }
114
 
   mp_msg( MSGT_STREAM,MSGL_INFO,"[mf] number of files: %d\n",mf->nr_of_files );
115
 
 
116
 
   goto exit_mf;
117
 
  }
118
 
 
119
 
 fname=malloc( strlen( filename ) + 32 );
120
 
 
121
 
 if ( !strchr( filename,'%' ) )
122
 
  {
123
 
   strcpy( fname,filename );
124
 
   if ( !strchr( filename,'*' ) ) strcat( fname,"*" );
125
 
 
126
 
   mp_msg( MSGT_STREAM,MSGL_INFO,"[mf] search expr: %s\n",fname );
127
 
 
128
 
   if ( glob( fname,0,NULL,&gg ) )
129
 
    { free( mf ); free( fname ); return NULL; }
130
 
 
131
 
   mf->nr_of_files=0;
132
 
   mf->names=calloc( gg.gl_pathc, sizeof( char* ) );
133
 
 
134
 
   for( i=0;i < gg.gl_pathc;i++ )
135
 
    {
136
 
     if (mp_path_isdir(gg.gl_pathv[i]))
137
 
       continue;
138
 
     mf->names[mf->nr_of_files]=strdup( gg.gl_pathv[i] );
139
 
     mf->nr_of_files++;
140
 
//     mp_msg( MSGT_STREAM,MSGL_DBG2,"[mf] added file %d.: %s\n",i,mf->names[i] );
141
 
    }
142
 
   mp_msg( MSGT_STREAM,MSGL_INFO,"[mf] number of files: %d\n",mf->nr_of_files);
143
 
   globfree( &gg );
144
 
   goto exit_mf;
145
 
  }
146
 
 
147
 
 mp_msg( MSGT_STREAM,MSGL_INFO,"[mf] search expr: %s\n",filename );
148
 
 
149
 
 while ( error_count < 5 )
150
 
  {
151
 
   sprintf( fname,filename,count++ );
152
 
   if ( !mp_path_exists( fname ) )
153
 
    {
154
 
     error_count++;
155
 
     mp_msg( MSGT_STREAM,MSGL_V,"[mf] file not found: '%s'\n",fname );
156
 
    }
157
 
    else
158
 
    {
159
 
     mf->names=realloc( mf->names,( mf->nr_of_files + 1 ) * sizeof( char* ) );
160
 
     mf->names[mf->nr_of_files]=strdup( fname );
161
 
//     mp_msg( MSGT_STREAM,MSGL_V,"[mf] added file %d.: %s\n",mf->nr_of_files,mf->names[mf->nr_of_files] );
162
 
     mf->nr_of_files++;
163
 
    }
164
 
  }
165
 
 
166
 
 mp_msg( MSGT_STREAM,MSGL_INFO,"[mf] number of files: %d\n",mf->nr_of_files );
 
58
    int error_count = 0;
 
59
    int count = 0;
 
60
 
 
61
    mf_t *mf = talloc_zero(talloc_ctx, mf_t);
 
62
    mf->log = log;
 
63
 
 
64
    if (filename[0] == '@') {
 
65
        FILE *lst_f = fopen(filename + 1, "r");
 
66
        if (lst_f) {
 
67
            char *fname = talloc_size(mf, MP_PATH_MAX);
 
68
            while (fgets(fname, MP_PATH_MAX, lst_f)) {
 
69
                /* remove spaces from end of fname */
 
70
                char *t = fname + strlen(fname) - 1;
 
71
                while (t > fname && isspace(*t))
 
72
                    *(t--) = 0;
 
73
                if (!mp_path_exists(fname)) {
 
74
                    mp_verbose(log, "file not found: '%s'\n", fname);
 
75
                } else {
 
76
                    mf_add(mf, fname);
 
77
                }
 
78
            }
 
79
            fclose(lst_f);
 
80
 
 
81
            mp_info(log, "number of files: %d\n", mf->nr_of_files);
 
82
            goto exit_mf;
 
83
        }
 
84
        mp_info(log, "%s is not indirect filelist\n", filename + 1);
 
85
    }
 
86
 
 
87
    if (strchr(filename, ',')) {
 
88
        mp_info(log, "filelist: %s\n", filename);
 
89
        bstr bfilename = bstr0(filename);
 
90
 
 
91
        while (bfilename.len) {
 
92
            bstr bfname;
 
93
            bstr_split_tok(bfilename, ",", &bfname, &bfilename);
 
94
            char *fname2 = bstrdup0(mf, bfname);
 
95
 
 
96
            if (!mp_path_exists(fname2))
 
97
                mp_verbose(log, "file not found: '%s'\n", fname2);
 
98
            else {
 
99
                mf_add(mf, fname2);
 
100
            }
 
101
            talloc_free(fname2);
 
102
        }
 
103
        mp_info(log, "number of files: %d\n", mf->nr_of_files);
 
104
 
 
105
        goto exit_mf;
 
106
    }
 
107
 
 
108
    char *fname = talloc_size(mf, strlen(filename) + 32);
 
109
 
 
110
    if (!strchr(filename, '%')) {
 
111
        strcpy(fname, filename);
 
112
        if (!strchr(filename, '*'))
 
113
            strcat(fname, "*");
 
114
 
 
115
        mp_info(log, "search expr: %s\n", fname);
 
116
 
 
117
        glob_t gg;
 
118
        if (glob(fname, 0, NULL, &gg)) {
 
119
            talloc_free(mf);
 
120
            return NULL;
 
121
        }
 
122
 
 
123
        for (int i = 0; i < gg.gl_pathc; i++) {
 
124
            if (mp_path_isdir(gg.gl_pathv[i]))
 
125
                continue;
 
126
            mf_add(mf, gg.gl_pathv[i]);
 
127
        }
 
128
        mp_info(log, "number of files: %d\n", mf->nr_of_files);
 
129
        globfree(&gg);
 
130
        goto exit_mf;
 
131
    }
 
132
 
 
133
    mp_info(log, "search expr: %s\n", filename);
 
134
 
 
135
    while (error_count < 5) {
 
136
        sprintf(fname, filename, count++);
 
137
        if (!mp_path_exists(fname)) {
 
138
            error_count++;
 
139
            mp_verbose(log, "file not found: '%s'\n", fname);
 
140
        } else {
 
141
            mf_add(mf, fname);
 
142
        }
 
143
    }
 
144
 
 
145
    mp_info(log, "number of files: %d\n", mf->nr_of_files);
167
146
 
168
147
exit_mf:
169
 
 free( fname );
170
 
 return mf;
 
148
    return mf;
171
149
#else
172
 
 mp_msg(MSGT_STREAM,MSGL_FATAL,"[mf] mf support is disabled on your os\n");
173
 
 return 0;
 
150
    mp_fatal(log, "mf support is disabled on your os\n");
 
151
    return 0;
174
152
#endif
175
153
}
176
154
 
177
 
mf_t* open_mf_single(char * filename)
 
155
mf_t *open_mf_single(void *talloc_ctx, struct mp_log *log, char *filename)
178
156
{
179
 
    mf_t *mf = calloc(1, sizeof(mf_t));
180
 
    mf->nr_of_files = 1;
181
 
    mf->names = calloc(1, sizeof(char *));
182
 
    mf->names[0] = strdup(filename);
 
157
    mf_t *mf = talloc_zero(talloc_ctx, mf_t);
 
158
    mf->log = log;
 
159
    mf_add(mf, filename);
183
160
    return mf;
184
161
}