summaryrefslogtreecommitdiffstats
path: root/demux/demux_mng.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_mng.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_mng.c')
-rw-r--r--demux/demux_mng.c31
1 files changed, 12 insertions, 19 deletions
diff --git a/demux/demux_mng.c b/demux/demux_mng.c
index 824a668868..6c5bbc2e45 100644
--- a/demux/demux_mng.c
+++ b/demux/demux_mng.c
@@ -255,21 +255,6 @@ static mng_bool demux_mng_settimer(mng_handle h_mng, mng_uint32 msecs)
}
/**
- * \brief MPlayer callback: Check if stream contains MNG data.
- * \param[in] demuxer demuxer structure
- * \return demuxer type constant, \p 0 if unknown
- */
-static int demux_mng_check_file(demuxer_t *demuxer)
-{
- char buf[4];
- if (stream_read(demuxer->stream, buf, 4) != 4)
- return -1;
- if (memcmp(buf, "\x8AMNG", 4))
- return -1;
- return 0;
-}
-
-/**
* \brief MPlayer callback: Fill buffer from MNG stream.
* \param[in] demuxer demuxer structure
* \return \p 1 on success, \p 0 on error
@@ -343,13 +328,24 @@ static int demux_mng_fill_buffer(demuxer_t * demuxer)
return 1;
}
-static int demux_mng_open(demuxer_t * demuxer)
+static int demux_mng_open(demuxer_t * demuxer, enum demux_check check)
{
mng_priv_t * mng_priv;
mng_handle h_mng;
mng_retcode mng_ret;
sh_video_t * sh_video;
+ if (check > DEMUX_CHECK_REQUEST)
+ return -1; // check too unsafe
+ if (check > DEMUX_CHECK_FORCE) {
+ char buf[4];
+ if (stream_read(demuxer->stream, buf, 4) != 4)
+ return -1;
+ if (memcmp(buf, "\x8AMNG", 4))
+ return -1;
+ stream_seek(demuxer->stream, demuxer->stream->start_pos);
+ }
+
// create private data structure
mng_priv = calloc(1, sizeof(mng_priv_t));
@@ -569,9 +565,6 @@ const demuxer_desc_t demuxer_desc_mng = {
.shortdesc = "MNG",
.author = "Stefan Schuermans <stefan@blinkenarea.org>",
.comment = "MNG files, using libmng",
- .type = DEMUXER_TYPE_MNG,
- .safe_check = 0, // unsafe autodetect (only checking magic at beginning of stream)
- .check_file = demux_mng_check_file,
.fill_buffer = demux_mng_fill_buffer,
.open = demux_mng_open,
.close = demux_mng_close,