summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUoti Urpala <uau@glyph.nonexistent.invalid>2008-12-02 18:02:05 +0200
committerUoti Urpala <uau@glyph.nonexistent.invalid>2008-12-02 18:02:05 +0200
commite62517ef6a8d23cd78325a9661f8865bd222e004 (patch)
tree76b7a0af867236c2989ceca1cffcae541ceda9c5
parent62dda60800a902fdaf9b0ec63d8488aaa48c485f (diff)
parent27b167bb75b908541563bab964e97b06d621f837 (diff)
downloadmpv-e62517ef6a8d23cd78325a9661f8865bd222e004.tar.bz2
mpv-e62517ef6a8d23cd78325a9661f8865bd222e004.tar.xz
Merge svn changes up to r28065
-rw-r--r--Changelog47
-rw-r--r--DOCS/man/en/mplayer.15
-rw-r--r--Makefile1
-rwxr-xr-xconfigure52
-rw-r--r--cpudetect.c4
-rw-r--r--etc/codecs.conf8
-rw-r--r--libmpdemux/demux_mng.c625
-rw-r--r--libmpdemux/demuxer.c4
-rw-r--r--libmpdemux/demuxer.h3
-rw-r--r--libmpdemux/video.c1
-rw-r--r--libswscale/rgb2rgb.c17
-rw-r--r--libvo/vo_direct3d.c338
-rw-r--r--libvo/vo_macosx.h4
-rw-r--r--libvo/vo_macosx.m66
-rw-r--r--libvo/vo_sdl.c79
-rw-r--r--stream/cache2.c4
-rw-r--r--vidix/sh_veu_vid.c4
17 files changed, 1031 insertions, 231 deletions
diff --git a/Changelog b/Changelog
index 08ccd04c59..e7c56af62a 100644
--- a/Changelog
+++ b/Changelog
@@ -29,6 +29,7 @@ MPlayer (1.0)
* support for attachments in lavf demuxer
* support for chapters in lavf demuxer
* FLAC speedup in lavf demuxer
+ * MNG demuxer
Filters:
* vf_ow new overcomplete wavelet denoiser
@@ -65,6 +66,8 @@ MPlayer (1.0)
* VIDIX driver for SuperH Mobile VEU hardware block.
* support -border on vo_gl/gl2 in x11
* Direct3D Windows video output driver added.
+ * initial code duplication cleanup between vo_wii and vo_fbdev2
+ * initial code duplication cleanup between vo_x11,vo_xv,vo_xvmc
MEncoder:
* check for system-wide configuration file in MEncoder
@@ -84,6 +87,8 @@ MPlayer (1.0)
* some new slave commands (check DOCS/tech/slave.txt)
* misc fixes to libass
* libdvdcss updated to 1.2.10, now same as upstream version
+ * fix -endchapter support again for -dump* options
+ * add startup volume option
Ports:
* small crash with vo_macosx fixed
@@ -92,6 +97,10 @@ MPlayer (1.0)
* vo_gl now works with -wid and nVidia drivers on Windows (this is a hack)
* VIDIX on SuperH.
* workarounds for AltiVec on Apple gcc 3.3 on Mac OS X dropped
+ * vo_macosx can now be compiled in 64-bits mode
+ * OpenGL support for unmodified MinGW64
+
+
rc2try2:
@@ -102,6 +111,7 @@ MPlayer (1.0)
* buffer overflow in demuxer_mov.c fixed
+
rc2: "AreWeThereYet?" October 7, 2007
(SVN revisions: MPlayer r24722, FFmpeg r10677)
@@ -146,7 +156,6 @@ MPlayer (1.0)
* text subtitles should now work with libavformat demuxer
* cleaned up TiVo demuxer
-
Streaming:
* authentication for Real RTSP streams
* near-precise seeking in dvd:// and dvdnav://
@@ -243,18 +252,21 @@ MPlayer (1.0)
* many compiler warning fixes
+
rc1try3: June 5, 2007 (unreleased)
Security:
* stack overflow in stream_cddb.c fixed
+
rc1try2: December 31, 2006 (unreleased)
Security:
* buffer overflow in asmrp.c fixed
+
rc1: "Codename intentionally left blank" October 22, 2006
(SVN revisions: MPlayer r20372, FFmpeg r6767)
@@ -345,6 +357,7 @@ MPlayer (1.0)
* -nortc is now default since -rtc has disadvantages with recent kernels
+
pre8: "NeuTeam strikes back" June 11, 2006
(SVN revisions: MPlayer r18681, FFmpeg r5466)
@@ -623,25 +636,27 @@ MPlayer (1.0)
screen resolution
+
pre7try3: February 15, 2006 (unreleased)
Security:
* heap overflow in demuxer.h fixed
+
pre7try2: August 26, 2005
Security:
* heap overflow in PCM audio decoder fixed
+
pre7: "PatentCounter" April 16, 2005
Security:
* heap overflow in Real RTSP streaming code fixed
* buffer overflow in MMST streaming code fixed
-
DOCS:
* Czech documentation translation in progress
* German man page almost synced
@@ -779,6 +794,7 @@ MPlayer (1.0)
* put changed notices into all imported files for GPL 2a compliance
+
pre6: "X-mas present" December 23, 2004
DOCS:
@@ -976,6 +992,7 @@ MPlayer (1.0)
* many memleaks fixed
+
pre5try2: December 15, 2004
Security:
@@ -986,6 +1003,7 @@ MPlayer (1.0)
* heap overflow in pnm streaming code fixed
+
pre5: "LinuxTag release" July 15, 2004
Name:
@@ -1113,6 +1131,7 @@ MPlayer (1.0)
* -use-stdin renamed to -noconsolecontrols
+
pre4: "YAML Counter" Apr 28, 2004
Security:
@@ -1284,12 +1303,14 @@ MPlayer (1.0)
* less verbosity in Win32 loader and other places
+
pre3try2: security fix release Mar 3, 2004
Security:
* HTTP parser remote heap overflow vulnerability fixed
+
pre3: "The Real Counter" Dec 9, 2003
DOCS:
@@ -1443,6 +1464,7 @@ MPlayer (1.0)
* rawyuv (i420) 'encoder'
+
pre2: Oct 5, 2003
Security:
@@ -1533,6 +1555,7 @@ MPlayer (1.0)
* subtitle alignment and smart line splitting options
+
pre1: "Development" on the beach Sept 1, 2003
NOTE: the MPlayer 'main' branch was forked at the time of 0.90-rc4, so
0.90-rc5 (and later 0.90 releases) changes are independent!
@@ -1673,6 +1696,7 @@ MPlayer (1.0)
* spelling/grammar fixes in numerous files
+
MPlayer (0.90)
rc4: "FlameCounter" Feb 9, 2003
@@ -1732,6 +1756,7 @@ MPlayer (0.90)
* libavcodec: some B-frame related encoding failures/crashes fixed
+
rc3: "BugfixCounter" Jan 19, 2003
DOCS:
@@ -1820,6 +1845,7 @@ MPlayer (0.90)
* fixed some possible crashes
+
rc2: Dec 24, 2002
General:
* DOCS/tech/encoding-tips.txt and tech/directfb.txt
@@ -1853,6 +1879,7 @@ MPlayer (0.90)
* Fixed a bug in MMX-optimized mp3lib (triggered by OpenBSD).
+
rc1: "CodecCounter" Dec 7, 2002
Docs:
* new French translation
@@ -1892,6 +1919,7 @@ MPlayer (0.90)
* AltiVec (G4) support
+
pre10: "BirthdayCounter" Nov 11, 2002
Docs:
* DVD auth, VCD sections extended (DOCS/cd-dvd.html)
@@ -1949,6 +1977,7 @@ MPlayer (0.90)
* -vop smartblur
+
pre9: Oct 24, 2002
Docs:
* man page rewritten again :)))
@@ -2024,6 +2053,7 @@ MPlayer (0.90)
* complete MPEG-4 GMC decoding support
+
pre8: Sep 18, 2002
Docs:
* man page rewritten, now has better indenting, and can be converted to HTML
@@ -2056,6 +2086,7 @@ MPlayer (0.90)
* Win32 DLL loader merged/synced with avifile CVS
+
pre7: Sep 5, 2002
Cleanup:
* libvo2, old input code & sis_vid removed, other code cleanups
@@ -2084,6 +2115,7 @@ MPlayer (0.90)
* drag'n'drop support
+
pre6: Aug 6, 2002
* WMV1, Sorenson v1 (SVQ1) and RealPlayer 8.0 (RV20/30, Cook) codecs support
* libavcodec M1 direct rendering
@@ -2112,6 +2144,7 @@ MPlayer (0.90)
* man page & README restructured (again :))
+
pre5: Jun 8, 2002
Documentation:
* a lot of fixes, updates, cleanups
@@ -2151,6 +2184,7 @@ MPlayer (0.90)
* various portability fixes (Cygwin, Darwin, 64bit SPARC/Alpha)
+
pre4: May 13, 2002
* X11 fullscreen toggle fixes with many window managers, multifile playback
* DXR2 support
@@ -2161,6 +2195,7 @@ MPlayer (0.90)
* a lot of other fixes
+
pre3: May 3, 2002
* 3DNow! optimization of AC3 4ch downmix fixed, optimizations re-enabled
* DGA error/fail after 1 second of playing fixed
@@ -2174,6 +2209,7 @@ MPlayer (0.90)
* various MJPEG improvements in libavcodec
+
pre2: Apr 30, 2002
* hwac3 fixes (try AFMT_AC3 first), big-endian fixes for PCM audio
* 2-pass encoding with libavcodec (-lavcopts vpass=x), B-frames support
@@ -2195,6 +2231,7 @@ MPlayer (0.90)
* no more black VOBsub subtitles :)
+
pre1: Apr 21, 2002
* 100% GPL - yeah, so what?
* runtime CPU detection - x86 MPlayer binary can run on "any" other x86 CPU
@@ -2212,6 +2249,7 @@ MPlayer (0.90)
* and of course, faster than ever... :)
+
MPlayer (0.60) "The RTFMCounter": Jan 2, 2002
release:
@@ -2220,6 +2258,7 @@ MPlayer (0.60) "The RTFMCounter": Jan 2, 2002
* help file translation updates
+
pre2: Dec 29, 2002
* build fixes (install codecs.conf)
* DVD subtitles improved (stability and pts fixes)
@@ -2230,6 +2269,7 @@ MPlayer (0.60) "The RTFMCounter": Jan 2, 2002
* make install
+
pre1: Dec 25, 2002
* new file formats (MOV, FLI/FLC, VIVO, RealMedia, NuppelVideo, yuv4mpeg,
yuv4mpeg2)
@@ -2261,6 +2301,7 @@ MPlayer (0.50) "The Faszom(C)ounter": Oct 8, 2001
* non-Linux build fixes
+
prex 1-3: Sep 28 2001 - Oct 5 2001
* some pre-beta nationalization support
* HTMLized documentation, split in sections
@@ -2393,6 +2434,7 @@ MPlayer v0.11-pre21: Feb 12, 2001
(de-interlacing has been disabled, because it's buggy now)
+
MPlayer v0.11-pre20: Feb 11, 2001
NI-AVI support, small fixes & patches...
- ASF parser: flag 0x40 (explicit packet size) implemented [Marvin]
@@ -2549,6 +2591,7 @@ MPlayer v0.11-pre11: Jan 29, 2001
- RGB opendivx encoding implemented, now AVI->opendivx is possible.
+
MPlayer v0.11-pre10: Jan 22, 2001
OpenDivX encoding, streaming fixes, AVI seek fixes
- new libvo driver: odivx (OpenDivX File Writer)
diff --git a/DOCS/man/en/mplayer.1 b/DOCS/man/en/mplayer.1
index 0d3adb30d7..2884a4f458 100644
--- a/DOCS/man/en/mplayer.1
+++ b/DOCS/man/en/mplayer.1
@@ -3443,11 +3443,14 @@ Play video through the XFree86 Direct Graphics Access extension.
Considered obsolete.
.
.TP
-.B sdl (SDL only)
+.B sdl (SDL only, buggy/outdated)
Highly platform independent SDL (Simple Directmedia Layer) library
video output driver.
Since SDL uses its own X11 layer, MPlayer X11 options do not have
any effect on SDL.
+Note that it has several minor bugs (\-vm/\-novm is mostly ignored,
+\-fs behaves like \-novm should, window is in top-left corner when
+returning from fullscreen, panscan is not supported, ...)
.PD 0
.RSs
.IPs driver=<driver>
diff --git a/Makefile b/Makefile
index e552e1d644..6a9793a9cf 100644
--- a/Makefile
+++ b/Makefile
@@ -375,6 +375,7 @@ SRCS_COMMON-$(LIVE555) += libmpdemux/demux_rtp.cpp \
libmpdemux/demux_rtp_codec.cpp \
stream/stream_live555.c
SRCS_COMMON-$(MACOSX_FINDER) += osdep/macosx_finder_args.c
+SRCS_COMMON-$(MNG) += libmpdemux/demux_mng.c
SRCS_COMMON-$(MP3LIB) += libmpcodecs/ad_mp3lib.c mp3lib/sr1.c
SRCS_COMMON-$(MP3LIB)-$(ARCH_X86_32) += mp3lib/decode_i586.c
SRCS_COMMON-$(MP3LIB)-$(ARCH_X86_32)-$(HAVE_3DNOW) += mp3lib/dct36_3dnow.c \
diff --git a/configure b/configure
index 063166cc58..ee34ff3524 100755
--- a/configure
+++ b/configure
@@ -286,6 +286,7 @@ Optional features:
Codecs:
--enable-gif enable GIF support [autodetect]
--enable-png enable PNG input/output support [autodetect]
+ --enable-mng enable MNG input support [autodetect]
--enable-jpeg enable JPEG input/output support [autodetect]
--enable-libcdio enable libcdio support [autodetect]
--enable-liblzo enable liblzo support [autodetect]
@@ -422,6 +423,7 @@ Miscellaneous options:
--cc=COMPILER C compiler to build MPlayer [gcc]
--host-cc=COMPILER C compiler for tools needed while building [gcc]
--as=ASSEMBLER assembler to build MPlayer [as]
+ --nm=NM nm tool to build MPlayer [nm]
--yasm=YASM Yasm assembler to build MPlayer [yasm]
--ar=AR librarian to build MPlayer [ar]
--ranlib=RANLIB ranlib to build MPlayer [ranlib]
@@ -508,6 +510,7 @@ _cc=cc
_ar=ar
test "$CC" && _cc="$CC"
_as=auto
+_nm=auto
_yasm=yasm
_runtime_cpudetection=no
_cross_compile=auto
@@ -553,6 +556,7 @@ _directx=auto
_win32waveout=auto
_nas=auto
_png=auto
+_mng=auto
_jpeg=auto
_pnm=yes
_md5sum=yes
@@ -713,6 +717,7 @@ _rpath=no
_asmalign_pot=auto
_stream_cache=yes
_def_stream_cache="#define CONFIG_STREAM_CACHE 1"
+_def_pthread_cache="#undef PTHREAD_CACHE"
_need_shmem=yes
for ac_option do
case "$ac_option" in
@@ -807,6 +812,9 @@ for ac_option do
--as=*)
_as=`echo $ac_option | cut -d '=' -f 2`
;;
+ --nm=*)
+ _nm=`echo $ac_option | cut -d '=' -f 2`
+ ;;
--yasm=*)
_yasm=`echo $ac_option | cut -d '=' -f 2`
;;
@@ -879,6 +887,8 @@ for ac_option do
--disable-nas) _nas=no ;;
--enable-png) _png=yes ;;
--disable-png) _png=no ;;
+ --enable-mng) _mng=yes ;;
+ --disable-mng) _mng=no ;;
--enable-jpeg) _jpeg=yes ;;
--disable-jpeg) _jpeg=no ;;
--enable-pnm) _pnm=yes ;;
@@ -1551,6 +1561,11 @@ if test "$_as" = auto ; then
test -z "$_as" && _as=as
fi
+if test "$_nm" = auto ; then
+ _nm=`$_cc -print-prog-name=nm`
+ test -z "$_nm" && _nm=nm
+fi
+
# XXX: this should be ok..
_cpuinfo="echo"
@@ -2269,7 +2284,7 @@ cat > $TMPC << EOF
int ff_extern;
EOF
cc_check -c || die "Symbol mangling check failed."
-sym=$(nm -P -g $TMPEXE)
+sym=$($_nm -P -g $TMPEXE)
extern_prefix=${sym%%ff_extern*}
_def_extern_prefix="#define EXTERN_PREFIX \"$extern_prefix\""
echores $extern_prefix
@@ -3126,6 +3141,15 @@ else
fi
echores "$_pthreads"
+if cygwin ; then
+ if test "$_pthreads" = yes ; then
+ _def_pthread_cache="#define PTHREAD_CACHE 1"
+ else
+ _stream_cache=no
+ _def_stream_cache="#undef CONFIG_STREAM_CACHE"
+ fi
+fi
+
echocheck "w32threads"
if test "$_pthreads" = yes ; then
_res_comment="using pthread instead"
@@ -4673,6 +4697,28 @@ else
_novomodules="png $_novomodules"
fi
+echocheck "MNG support"
+if test "$_mng" = auto ; then
+ _mng=no
+ cat > $TMPC << EOF
+#include <libmng.h>
+int main(void) {
+ const char * p_ver = mng_version_text();
+ return !p_ver || p_ver[0] == 0;
+}
+EOF
+ if cc_check -lmng -lz $_ld_lm ; then
+ _mng=yes
+ fi
+fi
+echores "$_mng"
+if test "$_mng" = yes ; then
+ _def_mng='#define CONFIG_MNG 1'
+ _ld_extra="$_ld_extra -lmng -lz"
+else
+ _def_mng='#undef CONFIG_MNG'
+fi
+
echocheck "JPEG support"
if test "$_jpeg" = auto ; then
_jpeg=no
@@ -4925,7 +4971,7 @@ fi
if test "$_direct3d" = yes ; then
_def_direct3d='#define CONFIG_DIRECT3D 1'
_libs_mplayer="$_libs_mplayer -ld3d9"
- _vosrc="$_vosrc vo_direct3d.c"
+ _vosrc="$_vosrc vo_direct3d.c w32_common.c"
_vomodules="direct3d $_vomodules"
else
_def_direct3d='#undef CONFIG_DIRECT3D'
@@ -7994,6 +8040,7 @@ LIRC = $_lirc
LIVE555 = $_live
MACOSX_BUNDLE = $_macosx_bundle
MACOSX_FINDER = $_macosx_finder
+MNG = $_mng
MP3LAME = $_mp3lame
MP3LIB = $_mp3lib
MUSEPACK = $_musepack
@@ -8435,6 +8482,7 @@ $_def_ivtv
$_def_jpeg
$_def_md5sum
$_def_mga
+$_def_mng
$_def_png
$_def_pnm
$_def_quartz
diff --git a/cpudetect.c b/cpudetect.c
index ffd0705e0e..a20baa88cd 100644
--- a/cpudetect.c
+++ b/cpudetect.c
@@ -153,8 +153,7 @@ void GetCpuCaps( CpuCaps *caps)
caps->hasMMX = (regs2[3] & (1 << 23 )) >> 23; // 0x0800000
caps->hasSSE = (regs2[3] & (1 << 25 )) >> 25; // 0x2000000
caps->hasSSE2 = (regs2[3] & (1 << 26 )) >> 26; // 0x4000000
- caps->hasSSSE3 = (regs2[3] & (1 << 9 )) >> 9; // 0x0000200
- caps->hasSSE4a = (regs2[3] & (1 << 6 )) >> 6; // 0x0000040
+ caps->hasSSSE3 = (regs2[2] & (1 << 9 )) >> 9; // 0x0000200
caps->hasMMX2 = caps->hasSSE; // SSE cpus supports mmxext too
cl_size = ((regs2[1] >> 8) & 0xFF)*8;
if(cl_size) caps->cl_size = cl_size;
@@ -176,6 +175,7 @@ void GetCpuCaps( CpuCaps *caps)
caps->hasMMX2 |= (regs2[3] & (1 << 22 )) >> 22; // 0x400000
caps->has3DNow = (regs2[3] & (1 << 31 )) >> 31; //0x80000000
caps->has3DNowExt = (regs2[3] & (1 << 30 )) >> 30;
+ caps->hasSSE4a = (regs2[2] & (1 << 6 )) >> 6; // 0x0000040
}
if(regs[0]>=0x80000006)
{
diff --git a/etc/codecs.conf b/etc/codecs.conf
index a22b7aa056..83348738e2 100644
--- a/etc/codecs.conf
+++ b/etc/codecs.conf
@@ -1528,6 +1528,14 @@ videocodec ffrv20
dll rv20
out YV12,I420,IYUV
+videocodec ffrv40
+ info "FFmpeg RV40 decoder"
+ status working
+ fourcc RV40,rv40
+ driver ffmpeg
+ dll rv40
+ out YV12,I420,IYUV
+
videocodec rv20
info "Linux RealPlayer 8 RV20 decoder"
status working
diff --git a/libmpdemux/demux_mng.c b/libmpdemux/demux_mng.c
new file mode 100644
index 0000000000..9d6005f44e
--- /dev/null
+++ b/libmpdemux/demux_mng.c
@@ -0,0 +1,625 @@
+/*
+ * MNG file demuxer for MPlayer
+ *
+ * Copyright (C) 2008 Stefan Schuermans <stefan blinkenarea org>
+ *
+ * This file is part of MPlayer.
+ *
+ * MPlayer is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * MPlayer is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with MPlayer; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include "config.h"
+
+#include "mp_msg.h"
+#include "help_mp.h"
+
+#include "stream/stream.h"
+#include "demuxer.h"
+#include "stheader.h"
+
+#define MNG_SUPPORT_READ
+#define MNG_SUPPORT_DISPLAY
+#include <libmng.h>
+
+/**
+ * \brief some small fixed start time > 0
+ *
+ * Start time must be > 0 for the variable frame time mechanism
+ * (GIF, MATROSKA, MNG) in video.c to work for the first frame.
+ */
+#define MNG_START_PTS 0.01f
+
+/**
+ * \brief private context structure
+ *
+ * This structure is used as private data for MPlayer demuxer
+ * and also as private data for the MNG library.
+ *
+ * All members ending in \p _ms are in milliseconds
+ */
+typedef struct {
+ stream_t * stream; ///< pointer to MNG data input stream
+ mng_handle h_mng; ///< MNG library image handle
+ int header_processed; ///< if MNG image header is processed
+ mng_uint32 width; ///< MNG image width
+ mng_uint32 height; ///< MNG image height
+ int total_time_ms; ///< total MNG animation time
+ unsigned char * canvas; /**< \brief canvas to draw the image onto
+ * \details
+ * \li lines top-down
+ * \li pixels left-to-right
+ * \li channels RGB
+ * \li no padding
+ * \li NULL if no canvas yet
+ */
+ int displaying; /**< \brief if displaying already,
+ * i.e. if mng_display has
+ * already been called
+ */
+ int finished; ///< if animation is finished
+ int global_time_ms; ///< current global time for MNG library
+ int anim_cur_time_ms; ///< current frame time in MNG animation
+ int anim_frame_duration_ms; ///< current frame duration in MNG animation
+ int show_cur_time_ms; /**< \brief current time in the show process,
+ * i.e. time of last demux packet
+ */
+ int show_next_time_ms; /**< \brief next time in the show process,
+ * i.e. time of next demux packet
+ */
+ int timer_ms; /**< \brief number of milliseconds after which
+ * libmng wants to be called again
+ */
+} mng_priv_t;
+
+/**
+ * \brief MNG library callback: Allocate a new zero-filled memory block.
+ * \param[in] size memory block size
+ * \return pointer to new memory block
+ */
+static mng_ptr demux_mng_alloc(mng_size_t size)
+{
+ return calloc(1, size);
+}
+
+/**
+ * \brief MNG library callback: Free memory block.
+ * \param[in] ptr pointer to memory block
+ * \param[in] size memory block size
+ */
+static void demux_mng_free(mng_ptr ptr, mng_size_t size)
+{
+ free(ptr);
+}
+
+/**
+ * \brief MNG library callback: Open MNG stream.
+ * \param[in] h_mng MNG library image handle
+ * \return \p MNG_TRUE on success, \p MNG_FALSE on error (never happens)
+ */
+static mng_bool demux_mng_openstream(mng_handle h_mng)
+{
+ mng_priv_t * mng_priv = mng_get_userdata(h_mng);
+ stream_t * stream = mng_priv->stream;
+
+ // rewind stream to the beginning
+ stream_seek(stream, stream->start_pos);
+
+ return MNG_TRUE;
+}
+
+/**
+ * \brief MNG library callback: Close MNG stream.
+ * \param[in] h_mng MNG library image handle
+ * \return \p MNG_TRUE on success, \p MNG_FALSE on error (never happens)
+ */
+static mng_bool demux_mng_closestream(mng_handle h_mng)
+{
+ return MNG_TRUE;
+}
+
+/**
+ * \brief MNG library callback: Read data from stream.
+ * \param[in] h_mng MNG library image handle
+ * \param[in] buf pointer to buffer to fill with data
+ * \param[in] size size of buffer
+ * \param[out] read number of bytes read from stream
+ * \return \p MNG_TRUE on success, \p MNG_FALSE on error (never happens)
+ */
+static mng_bool demux_mng_readdata(mng_handle h_mng, mng_ptr buf,
+ mng_uint32 size, mng_uint32 * read)
+{
+ mng_priv_t * mng_priv = mng_get_userdata(h_mng);
+ stream_t * stream = mng_priv->stream;
+
+ // simply read data from stream and return number of bytes or error
+ *read = stream_read(stream, buf, size);
+
+ return MNG_TRUE;
+}
+
+/**
+ * \brief MNG library callback: Header information is processed now.
+ * \param[in] h_mng MNG library image handle
+ * \param[in] width image width
+ * \param[in] height image height
+ * \return \p MNG_TRUE on success, \p MNG_FALSE on error
+ */
+static mng_bool demux_mng_processheader(mng_handle h_mng, mng_uint32 width,
+ mng_uint32 height)
+{
+ mng_priv_t * mng_priv = mng_get_userdata(h_mng);
+
+ // remember size in private data
+ mng_priv->header_processed = 1;
+ mng_priv->width = width;
+ mng_priv->height = height;
+
+ // get total animation time
+ mng_priv->total_time_ms = mng_get_playtime(h_mng);
+
+ // allocate canvas
+ mng_priv->canvas = malloc(height * width * 4);
+ if (!mng_priv->canvas) {
+ mp_msg(MSGT_DEMUX, MSGL_ERR,
+ "demux_mng: could not allocate canvas of size %dx%d\n",
+ width, height);
+ return MNG_FALSE;
+ }
+
+ return MNG_TRUE;
+}
+
+/**
+ * \brief MNG library callback: Get access to a canvas line.
+ * \param[in] h_mng MNG library image handle
+ * \param[in] line y coordinate of line to access
+ * \return pointer to line on success, \p MNG_NULL on error
+ */
+static mng_ptr demux_mng_getcanvasline(mng_handle h_mng, mng_uint32 line)
+{
+ mng_priv_t * mng_priv = mng_get_userdata(h_mng);
+
+ // return pointer to canvas line
+ if (line < mng_priv->height && mng_priv->canvas)
+ return (mng_ptr)(mng_priv->canvas + line * mng_priv->width * 4);
+ else
+ return (mng_ptr)MNG_NULL;
+}
+
+/**
+ * \brief MNG library callback: A part of the canvas should be shown.
+ *
+ * This function is called by libmng whenever it thinks a
+ * rectangular part of the display should be updated. This
+ * can happen multiple times for a frame and/or a single time
+ * for a frame. Only the the part of the display occupied by
+ * the rectangle defined by x, y, width, height is to be updated.
+ * It is possible that some parts of the display are not updated
+ * for many frames. There is no chance here to find out if the
+ * current frame is completed with this update or not.
+ *
+ * This mechanism does not match MPlayer's demuxer architecture,
+ * so it will not be used exactly as intended by libmng.
+ * A new frame is generated in the demux_mng_fill_buffer() function
+ * whenever libmng tells us to wait for some time.
+ *
+ * \param[in] h_mng MNG library image handle
+ * \param[in] x rectangle's left edge
+ * \param[in] y rectangle's top edge
+ * \param[in] width rectangle's width
+ * \param[in] height rectangle's heigt
+ * \return \p MNG_TRUE on success, \p MNG_FALSE on error (never happens)
+ */
+static mng_bool demux_mng_refresh(mng_handle h_mng, mng_uint32 x, mng_uint32 y,
+ mng_uint32 width, mng_uint32 height)
+{
+ // nothing to do here, the image data is already on the canvas
+ return MNG_TRUE;
+}
+
+/**
+ * \brief MNG library callback: Get how many milliseconds have passed.
+ * \param[in] h_mng MNG library image handle
+ * \return global time in milliseconds
+ */
+static mng_uint32 demux_mng_gettickcount(mng_handle h_mng)
+{
+ mng_priv_t * mng_priv = mng_get_userdata(h_mng);
+
+ // return current global time
+ return mng_priv->global_time_ms;
+}
+
+/**
+ * \brief MNG library callback: Please call again after some milliseconds.
+ * \param[in] h_mng MNG library image handle
+ * \param[in] msecs number of milliseconds after which to call again
+ * \return \p MNG_TRUE on success, \p MNG_FALSE on error (never happens)
+ */
+static mng_bool demux_mng_settimer(mng_handle h_mng, mng_uint32 msecs)
+{
+ mng_priv_t * mng_priv = mng_get_userdata(h_mng);
+
+ // Save number of milliseconds after which to call the MNG library again
+ // in private data.
+ mng_priv->timer_ms = msecs;
+ return MNG_TRUE;
+}
+
+/**
+ * \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 0;
+ if (memcmp(buf, "\x8AMNG", 4))
+ return 0;
+ return DEMUXER_TYPE_MNG;
+}
+
+/**
+ * \brief MPlayer callback: Fill buffer from MNG stream.
+ * \param[in] demuxer demuxer structure
+ * \param[in] ds demuxer stream
+ * \return \p 1 on success, \p 0 on error
+ */
+static int demux_mng_fill_buffer(demuxer_t * demuxer,
+ demux_stream_t * ds)
+{
+ mng_priv_t * mng_priv = demuxer->priv;
+ mng_handle h_mng = mng_priv->h_mng;
+ mng_retcode mng_ret;
+ demux_packet_t * dp;
+
+ // exit if animation is finished
+ if (mng_priv->finished)
+ return 0;
+
+ // advance animation to requested next show time
+ while (mng_priv->anim_cur_time_ms + mng_priv->anim_frame_duration_ms
+ <= mng_priv->show_next_time_ms && !mng_priv->finished) {
+
+ // advance global and animation time
+ mng_priv->global_time_ms += mng_priv->anim_frame_duration_ms;
+ mng_priv->anim_cur_time_ms += mng_priv->anim_frame_duration_ms;
+
+ // Clear variable MNG library will write number of milliseconds to
+ // (via settimer callback).
+ mng_priv->timer_ms = 0;
+
+ // get next image from MNG library
+ if (mng_priv->displaying)
+ mng_ret = mng_display_resume(h_mng); // resume displaying MNG data
+ // to canvas
+ else
+ mng_ret = mng_display(h_mng); // start displaying MNG data to canvas
+ if (mng_ret && mng_ret != MNG_NEEDTIMERWAIT) {
+ mp_msg(MSGT_DEMUX, MSGL_ERR,
+ "demux_mng: could not display MNG data to canvas: "
+ "mng_retcode %d\n", mng_ret);
+ return 0;
+ }
+ mng_priv->displaying = 1; // mng_display() has been called now
+ mng_priv->finished = mng_ret == 0; // animation is finished iff
+ // mng_display() returned 0
+
+ // save current frame duration
+ mng_priv->anim_frame_duration_ms = mng_priv->timer_ms < 1
+ ? 1 : mng_priv->timer_ms;
+
+ } // while (mng_priv->anim_cur_time_ms + ...
+
+ // create a new demuxer packet
+ dp = new_demux_packet(mng_priv->height * mng_priv->width * 4);
+
+ // copy image data into demuxer packet
+ memcpy(dp->buffer, mng_priv->canvas,
+ mng_priv->height * mng_priv->width * 4);
+
+ // set current show time to requested show time
+ mng_priv->show_cur_time_ms = mng_priv->show_next_time_ms;
+
+ // get time of next frame to show
+ mng_priv->show_next_time_ms = mng_priv->anim_cur_time_ms
+ + mng_priv->anim_frame_duration_ms;
+
+ // Set position and timing information in demuxer video and demuxer packet.
+ // - Time must be time of next frame and always be > 0 for the variable
+ // frame time mechanism (GIF, MATROSKA, MNG) in video.c to work.
+ demuxer->video->dpos++;
+ dp->pts = (float)mng_priv->show_next_time_ms / 1000.0f + MNG_START_PTS;
+ dp->pos = stream_tell(demuxer->stream);
+ ds_add_packet(demuxer->video, dp);
+
+ return 1;
+}
+
+/**
+ * \brief MPlayer callback: Open MNG stream.
+ * \param[in] demuxer demuxer structure
+ * \return demuxer structure on success, \p NULL on error
+ */
+static demuxer_t * demux_mng_open(demuxer_t * demuxer)
+{
+ mng_priv_t * mng_priv;
+ mng_handle h_mng;
+ mng_retcode mng_ret;
+ sh_video_t * sh_video;
+
+ // create private data structure
+ mng_priv = calloc(1, sizeof(mng_priv_t));
+
+ //stream pointer into private data
+ mng_priv->stream = demuxer->stream;
+
+ // initialize MNG image instance
+ h_mng = mng_initialize((mng_ptr)mng_priv, demux_mng_alloc,
+ demux_mng_free, MNG_NULL);
+ if (!h_mng) {
+ mp_msg(MSGT_DEMUX, MSGL_ERR,
+ "demux_mng: could not ini