From 8eaa63689a25be909dc31c6a2c8c9dad3777943a Mon Sep 17 00:00:00 2001 From: wm4 Date: Mon, 29 Dec 2014 23:09:50 +0100 Subject: demux_mf: move mf.c contents to demux_mf.c There's no reason why parts of this demuxer would be in a separate source file. The existence of this code is already somewhat questionable anyway, so it may as well be dumped into a single file. Even stranger that demux.c included mf.h for no reason (it was an artifact from 2002 when the architecture was uncleaner). --- demux/demux_mf.c | 124 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 122 insertions(+), 2 deletions(-) (limited to 'demux/demux_mf.c') diff --git a/demux/demux_mf.c b/demux/demux_mf.c index 5bb2cf392a..4fb5f2a1f4 100644 --- a/demux/demux_mf.c +++ b/demux/demux_mf.c @@ -22,22 +22,142 @@ #include #include #include -#include #include "osdep/io.h" #include "talloc.h" #include "common/msg.h" #include "options/options.h" +#include "options/path.h" +#include "misc/ctype.h" #include "stream/stream.h" #include "demux.h" #include "stheader.h" #include "codec_tags.h" -#include "mf.h" #define MF_MAX_FILE_SIZE (1024 * 1024 * 256) +typedef struct mf { + struct mp_log *log; + struct sh_video *sh; + int curr_frame; + int nr_of_files; + char **names; + // optional + struct stream **streams; +} mf_t; + + +static void mf_add(mf_t *mf, const char *fname) +{ + char *entry = talloc_strdup(mf, fname); + MP_TARRAY_APPEND(mf, mf->names, mf->nr_of_files, entry); +} + +static mf_t *open_mf_pattern(void *talloc_ctx, struct mp_log *log, char *filename) +{ + int error_count = 0; + int count = 0; + + mf_t *mf = talloc_zero(talloc_ctx, mf_t); + mf->log = log; + + if (filename[0] == '@') { + FILE *lst_f = fopen(filename + 1, "r"); + if (lst_f) { + char *fname = talloc_size(mf, 512); + while (fgets(fname, 512, lst_f)) { + /* remove spaces from end of fname */ + char *t = fname + strlen(fname) - 1; + while (t > fname && mp_isspace(*t)) + *(t--) = 0; + if (!mp_path_exists(fname)) { + mp_verbose(log, "file not found: '%s'\n", fname); + } else { + mf_add(mf, fname); + } + } + fclose(lst_f); + + mp_info(log, "number of files: %d\n", mf->nr_of_files); + goto exit_mf; + } + mp_info(log, "%s is not indirect filelist\n", filename + 1); + } + + if (strchr(filename, ',')) { + mp_info(log, "filelist: %s\n", filename); + bstr bfilename = bstr0(filename); + + while (bfilename.len) { + bstr bfname; + bstr_split_tok(bfilename, ",", &bfname, &bfilename); + char *fname2 = bstrdup0(mf, bfname); + + if (!mp_path_exists(fname2)) + mp_verbose(log, "file not found: '%s'\n", fname2); + else { + mf_add(mf, fname2); + } + talloc_free(fname2); + } + mp_info(log, "number of files: %d\n", mf->nr_of_files); + + goto exit_mf; + } + + char *fname = talloc_size(mf, strlen(filename) + 32); + + if (!strchr(filename, '%')) { + strcpy(fname, filename); + if (!strchr(filename, '*')) + strcat(fname, "*"); + + mp_info(log, "search expr: %s\n", fname); + + glob_t gg; + if (glob(fname, 0, NULL, &gg)) { + talloc_free(mf); + return NULL; + } + + for (int i = 0; i < gg.gl_pathc; i++) { + if (mp_path_isdir(gg.gl_pathv[i])) + continue; + mf_add(mf, gg.gl_pathv[i]); + } + mp_info(log, "number of files: %d\n", mf->nr_of_files); + globfree(&gg); + goto exit_mf; + } + + mp_info(log, "search expr: %s\n", filename); + + while (error_count < 5) { + sprintf(fname, filename, count++); + if (!mp_path_exists(fname)) { + error_count++; + mp_verbose(log, "file not found: '%s'\n", fname); + } else { + mf_add(mf, fname); + } + } + + mp_info(log, "number of files: %d\n", mf->nr_of_files); + +exit_mf: + return mf; +} + +static mf_t *open_mf_single(void *talloc_ctx, struct mp_log *log, char *filename) +{ + mf_t *mf = talloc_zero(talloc_ctx, mf_t); + mf->log = log; + mf_add(mf, filename); + return mf; +} + static void demux_seek_mf(demuxer_t *demuxer, double rel_seek_secs, int flags) { mf_t *mf = demuxer->priv; -- cgit v1.2.3