summaryrefslogtreecommitdiffstats
path: root/demux/demux_mf.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2013-07-12 21:58:11 +0200
committerwm4 <wm4@nowhere>2013-07-12 22:16:26 +0200
commit3269bd178020c5d821e8b2d1fd807a38d63e93ce (patch)
tree474e0f7a712cc7002984ec1bdda7d445b5fd8c77 /demux/demux_mf.c
parent311d2f199a7b1f4d819cfb799a0f0f571596b91e (diff)
downloadmpv-3269bd178020c5d821e8b2d1fd807a38d63e93ce.tar.bz2
mpv-3269bd178020c5d821e8b2d1fd807a38d63e93ce.tar.xz
demux: rewrite probing and demuxer initialization
Get rid of the strange and messy reliance on DEMUXER_TYPE_ constants. Instead of having two open functions for the demuxer callbacks (which somehow are both optional, but you can also decide to implement both...), just have one function. This function takes a parameter that tells the demuxer how strictly it should check for the file headers. This is a nice simplification and allows more flexibility. Remove the file extension code. This literally did nothing (anymore). Change demux_lavf so that we check our other builtin demuxers first before libavformat tries to guess by file extension.
Diffstat (limited to 'demux/demux_mf.c')
-rw-r--r--demux/demux_mf.c77
1 files changed, 32 insertions, 45 deletions
diff --git a/demux/demux_mf.c b/demux/demux_mf.c
index 5e3469a0f1..33747f12d7 100644
--- a/demux/demux_mf.c
+++ b/demux/demux_mf.c
@@ -149,9 +149,9 @@ static const struct {
{0}
};
-static const char *probe_format(mf_t *mf)
+static const char *probe_format(mf_t *mf, enum demux_check check)
{
- if (mf->nr_of_files < 1)
+ if (check > DEMUX_CHECK_REQUEST)
return NULL;
char *type = mf_type;
if (!type || !type[0]) {
@@ -159,47 +159,42 @@ static const char *probe_format(mf_t *mf)
if (p)
type = p + 1;
}
- if (!type || !type[0])
- return NULL;
- int i;
- for (i = 0; type2format[i].type; i++) {
- if (strcasecmp(type, type2format[i].type) == 0)
- break;
+ for (int i = 0; type2format[i].type; i++) {
+ if (type && strcasecmp(type, type2format[i].type) == 0)
+ return type2format[i].codec;
}
- return type2format[i].codec;
-}
-
-static mf_t *open_mf(demuxer_t *demuxer)
-{
- if (!demuxer->stream->url)
- return NULL;
-
- if (strncmp(demuxer->stream->url, "mf://", 5) == 0) {
- return open_mf_pattern(demuxer->stream->url + 5);
- } else {
- mf_t *mf = open_mf_single(demuxer->stream->url);
- mf->streams = calloc(1, sizeof(struct stream *));
- mf->streams[0] = demuxer->stream;
- return mf;
+ if (check == DEMUX_CHECK_REQUEST) {
+ if (!mf_type) {
+ mp_msg(MSGT_DEMUX, MSGL_ERR,
+ "[demux_mf] file type was not set! (try --mf-type=ext)\n");
+ } else {
+ mp_msg(MSGT_DEMUX, MSGL_ERR,
+ "[demux_mf] --mf-type set to an unknown codec!\n");
+ }
}
+ return NULL;
}
-static int demux_check_file(demuxer_t *demuxer)
-{
- if (demuxer->stream->type == STREAMTYPE_MF)
- return 0;
- mf_t *mf = open_mf(demuxer);
- bool ok = mf && probe_format(mf);
- free_mf(mf);
- return ok ? 0 : -1;
-}
-
-static int demux_open_mf(demuxer_t* demuxer)
+static int demux_open_mf(demuxer_t* demuxer, enum demux_check check)
{
sh_video_t *sh_video = NULL;
+ mf_t *mf;
+
+ if (strncmp(demuxer->stream->url, "mf://", 5) == 0 &&
+ demuxer->stream->type == STREAMTYPE_MF)
+ {
+ mf = open_mf_pattern(demuxer->stream->url + 5);
+ } else {
+ mf = open_mf_single(demuxer->stream->url);
+ mf->streams = calloc(1, sizeof(struct stream *));
+ mf->streams[0] = demuxer->stream;
+ }
+
+ if (!mf || mf->nr_of_files < 1)
+ goto error;
- mf_t *mf = open_mf(demuxer);
- if (!mf)
+ const char *codec = probe_format(mf, check);
+ if (!codec)
goto error;
mf->curr_frame = 0;
@@ -211,12 +206,7 @@ static int demux_open_mf(demuxer_t* demuxer)
struct sh_stream *sh = new_sh_stream(demuxer, STREAM_VIDEO);
sh_video = sh->video;
- sh_video->gsh->codec = probe_format(mf);
- if (!sh_video->gsh->codec) {
- mp_msg(MSGT_DEMUX, MSGL_INFO, "[demux_mf] file type was not set! (try -mf type=ext)\n" );
- goto error;
- }
-
+ sh_video->gsh->codec = codec;
sh_video->disp_w = 0;
sh_video->disp_h = 0;
sh_video->fps = mf_fps;
@@ -259,9 +249,6 @@ const demuxer_desc_t demuxer_desc_mf = {
.shortdesc = "MF",
.author = "?",
.comment = "multiframe?, pictures demuxer",
- .type = DEMUXER_TYPE_MF,
- .safe_check = 1,
- .check_file = demux_check_file,
.fill_buffer = demux_mf_fill_buffer,
.open = demux_open_mf,
.close = demux_close_mf,