[MPlayer-dev-eng] [PATCH] Matroska demuxer part 1

Moritz Bunkus moritz at bunkus.org
Tue Apr 22 23:27:32 CEST 2003


Hi.

This is the first of two parts of the Matroska demuxer. This does NOT
include the demuxer itself, just the patch that touches all the other
files (configure, demuxer.c etc.). As I haven't changed MPlayer's
configure script before (and as I'm not an expert of 'bash vs sh vs
othershells') I'd like you to check my code for correctness.

The configure method tries to find the Matroska and EBML libraries in
the standard directories, in /usr/include/{matroska,ebml} and
/usr/local/include/{matroska,ebml}. The user can use
'--with-extra-incdir' and '--with-extra-libdir' in order to specify the
paths. If all three tests fail (is there a smoother way to test all
three cases?) then no Matroska support will be included at all.

Summary: Matroska support is enabled only if the libs are found. No
additional C++ code is compiled or linked if the support is not
wanted. I know that this is important for some of you, but I tried to
make it as easy for those who WANT Matroska support as well, that's why
I automatically let configure try those other include directories as
well.

(I'd like to commit the Matroska demuxer this weekend after I've done
some cleanups on it - that's why I'm asking for advice now.)

-- 
 ==> Ciao, Mosu (Moritz Bunkus)
-------------- next part --------------
diff -NurX mkvexcludes main/configure main-mkv/configure
--- main/configure	2003-04-22 22:56:39.000000000 +0200
+++ main-mkv/configure	2003-04-22 23:05:54.000000000 +0200
@@ -189,6 +189,7 @@
   --enable-libfame       enable libfame realtime encoder [autodetect]
   --enable-vorbis        build with OggVorbis support [autodetect]
   --enable-tremor        build with integer-only OggVorbis support [disabled]
+  --enable-matroska      build with Matroska support [autodetect]
   --enable-faad          build with FAAD2 (MP4/AAC) support [autodetect]
   --disable-libdv        disable libdv 0.9.5 en/decoding support [autodetect]
   --disable-mad          disable libmad (mpeg audio) support [autodetect]
@@ -1021,6 +1022,7 @@
 _liblzo=auto
 _mad=auto
 _vorbis=auto
+_matroska=auto
 _tremor=no
 _faad=auto
 _xmms=no
@@ -1174,6 +1176,8 @@
   --disable-vorbis)	_vorbis=no	;;
   --enable-tremor)	_tremor=yes	;;
   --disable-tremor)	_tremor=no	;;
+  --enable-matroska)    _matroska=yes   ;;
+  --disable-matroska)   _matroska=no    ;;
   --enable-faad)	_faad=yes	;;
   --disable-faad)	_faad=no	;;
   --enable-xmms)	_xmms=yes	;;
@@ -4021,6 +4025,42 @@
 echores "$_vorbis"
 
 
+echocheck "Matroska support"
+if test "$_matroska" = auto ; then
+  _matroska=no
+  cat > $TMPC << EOF
+#include <EbmlConfig.h>
+int main(void) { return 0; }
+EOF
+  cc_check -lmatroska -lebml && _matroska=yes
+  if test "$_matroska" = no ; then
+    _saved_inc_extra=$_inc_extra
+    _inc_extra="$_inc_extra -I/usr/include/ebml -I/usr/include/matroska"
+    cc_check -lmatroska -lebml && _matroska=yes
+    if test "$_matroska" = no ; then
+      _inc_extra="$_saved_inc_extra -I/usr/local/include/ebml -I/usr/local/include/matroska"
+      cc_check -lmatroska -lebml && _matroska=yes
+      if test "$_matroska" = no ; then
+        _inc_extra=$_saved_inc_extra
+      fi
+    fi
+  fi
+fi
+if test "$_matroska" = yes ; then
+  _def_matroska='#define HAVE_MATROSKA 1'
+  _inputmodules="libmatroska $_inputmodules"
+  _ld_matroska="-lmatroska -lebml -lstdc++"
+  case $cc_version in
+    2.*) _def_matroska_gcc2="#define LIBEBML_GCC2"     ;;
+    *)   _def_matroska_gcc2="/*#define LIBEBML_GCC2*/" ;;
+  esac
+else
+  _def_matroska='#undef HAVE_MATROSKA'
+  _noinputmodules="libmatroska $_noinputmodules"
+fi
+echores "$_matroska"
+
+
 echocheck "faad2 (AAC) support"
 if test "$_faad" = auto ; then
   _faad=no
@@ -5144,6 +5184,8 @@
 CONFIG_RISKY = yes
 LIBMENU = $_menu
 I18NLIBS = $_i18n_libs
+MATROSKA = $_matroska
+MATROSKA_LIB = $_ld_matroska
 
 OPENDIVX = $_opendivx
 
@@ -5639,6 +5681,10 @@
 /* enable Tremor as vorbis decoder */
 $_def_tremor
 
+/* enable Matroska support */
+$_def_matroska
+$_def_matroska_gcc2
+
 /* enable FAAD (AAC) support */
 $_def_faad
 $_def_faad_version
diff -NurX mkvexcludes main/libmpdemux/demuxer.c main-mkv/libmpdemux/demuxer.c
--- main/libmpdemux/demuxer.c	2003-04-18 01:42:46.000000000 +0200
+++ main-mkv/libmpdemux/demuxer.c	2003-04-22 23:01:39.000000000 +0200
@@ -135,6 +135,7 @@
 extern void demux_close_xmms(demuxer_t* demuxer);
 extern void demux_close_gif(demuxer_t* demuxer);
 extern void demux_close_ts(demuxer_t* demuxer);
+extern void demux_close_mkv(demuxer_t* demuxer);
 
 #ifdef USE_TV
 #include "tv.h"
@@ -185,6 +186,10 @@
     case DEMUXER_TYPE_OGG:
       demux_close_ogg(demuxer); break;
 #endif
+#ifdef HAVE_MATROSKA
+    case DEMUXER_TYPE_MATROSKA:
+      demux_close_mkv(demuxer); break;
+#endif
 #ifdef STREAMING_LIVE_DOT_COM
     case DEMUXER_TYPE_RTP:
       demux_close_rtp(demuxer); break;
@@ -292,6 +297,7 @@
 extern int demux_rawaudio_fill_buffer(demuxer_t* demuxer, demux_stream_t *ds);
 extern int demux_rawvideo_fill_buffer(demuxer_t* demuxer, demux_stream_t *ds);
 extern int demux_smjpeg_fill_buffer(demuxer_t* demux);
+extern int demux_mkv_fill_buffer(demuxer_t *d);
 
 int demux_fill_buffer(demuxer_t *demux,demux_stream_t *ds){
   // Note: parameter 'ds' can be NULL!
@@ -330,6 +336,9 @@
 #ifdef HAVE_OGGVORBIS
     case DEMUXER_TYPE_OGG: return demux_ogg_fill_buffer(demux);
 #endif
+#ifdef HAVE_MATROSKA
+    case DEMUXER_TYPE_MATROSKA: return demux_mkv_fill_buffer(demux);
+#endif
     case DEMUXER_TYPE_RAWAUDIO: return demux_rawaudio_fill_buffer(demux,ds);
     case DEMUXER_TYPE_RAWVIDEO: return demux_rawvideo_fill_buffer(demux,ds);
 #ifdef STREAMING_LIVE_DOT_COM
@@ -574,6 +583,7 @@
 extern int gif_check_file(demuxer_t *demuxer);
 extern int demux_open_gif(demuxer_t* demuxer);
 extern int ts_check_file(demuxer_t * demuxer);
+extern int demux_open_mkv(demuxer_t *demuxer);
 
 extern demuxer_t* init_avi_with_ogg(demuxer_t* demuxer);
 
@@ -700,6 +710,19 @@
       demuxer = NULL;
   }
 }
+#ifdef HAVE_MATROSKA
+//=============== Try to open as Matroska file: =================
+if(file_format==DEMUXER_TYPE_UNKNOWN || file_format==DEMUXER_TYPE_MATROSKA){
+  demuxer=new_demuxer(stream,DEMUXER_TYPE_MATROSKA,audio_id,video_id,dvdsub_id);
+  if(demux_mkv_open(demuxer)){
+      mp_msg(MSGT_DEMUXER,MSGL_INFO,MSGTR_Detected_XXX_FileFormat,"Matroska");
+      file_format=DEMUXER_TYPE_MATROSKA;
+  } else {
+      free_demuxer(demuxer);
+      demuxer = NULL;
+  }
+}
+#endif
 
 //=============== Try based on filename EXTENSION: =================
 // Ok. We're over the stable detectable fileformats, the next ones are a bit
@@ -1277,6 +1300,7 @@
 extern void demux_rawaudio_seek(demuxer_t *demuxer,float rel_seek_secs,int flags);
 extern void demux_rawvideo_seek(demuxer_t *demuxer,float rel_seek_secs,int flags);
 extern void demux_xmms_seek(demuxer_t *demuxer,float rel_seek_secs,int flags);
+extern void demux_mkv_seek(demuxer_t *demuxer,float rel_seek_secs,int flags);
 
 int demux_seek(demuxer_t *demuxer,float rel_seek_secs,int flags){
     demux_stream_t *d_audio=demuxer->audio;
@@ -1366,6 +1390,10 @@
  case DEMUXER_TYPE_XMMS:
       demux_xmms_seek(demuxer,rel_seek_secs,flags); break;
 #endif
+#ifdef HAVE_MATROSKA
+ case DEMUXER_TYPE_MATROSKA:
+      demux_mkv_seek(demuxer,rel_seek_secs,flags);  break;
+#endif
  case DEMUXER_TYPE_MPEG_TS:
       demux_seek_ts(demuxer,rel_seek_secs,flags); break;
 
@@ -1428,6 +1456,7 @@
 extern int demux_asf_control(demuxer_t *demuxer, int cmd, void *arg);
 extern int demux_avi_control(demuxer_t *demuxer, int cmd, void *arg);
 extern int demux_xmms_control(demuxer_t *demuxer, int cmd, void *arg);
+extern int demux_mkv_control(demuxer_t *demuxer, int cmd, void *arg);
 
 int demux_control(demuxer_t *demuxer, int cmd, void *arg) {
     switch(demuxer->type) {
@@ -1445,6 +1474,10 @@
 	case DEMUXER_TYPE_XMMS:
 	    return demux_xmms_control(demuxer,cmd,arg);
 #endif
+#ifdef HAVE_MATROSKA
+        case DEMUXER_TYPE_MATROSKA:
+	    return demux_mkv_control(demuxer,cmd,arg);
+#endif
 	default:
 	    return DEMUXER_CTRL_NOTIMPL;
     }
diff -NurX mkvexcludes main/libmpdemux/demuxer.h main-mkv/libmpdemux/demuxer.h
--- main/libmpdemux/demuxer.h	2003-04-11 21:28:13.000000000 +0200
+++ main-mkv/libmpdemux/demuxer.h	2003-04-22 23:01:39.000000000 +0200
@@ -39,11 +39,12 @@
 #define DEMUXER_TYPE_GIF 28
 #define DEMUXER_TYPE_MPEG_TS 29
 #define DEMUXER_TYPE_H264_ES 30
+#define DEMUXER_TYPE_MATROSKA 31
 
 // This should always match the higest demuxer type number.
 // Unless you want to disallow users to force the demuxer to some types
 #define DEMUXER_TYPE_MIN 0
-#define DEMUXER_TYPE_MAX 30
+#define DEMUXER_TYPE_MAX 31
 
 #define DEMUXER_TYPE_DEMUXERS (1<<16)
 // A virtual demuxer type for the network code
diff -NurX mkvexcludes main/libmpdemux/Makefile main-mkv/libmpdemux/Makefile
--- main/libmpdemux/Makefile	2003-04-21 13:42:27.000000000 +0200
+++ main-mkv/libmpdemux/Makefile	2003-04-22 23:01:39.000000000 +0200
@@ -26,7 +26,9 @@
 SRCS += dvb_tune.c
 endif
 
-
+ifeq ($(MATROSKA),yes)
+CPLUSPLUSSRCS += demux_mkv.cpp
+endif
 
 
 OBJS	= $(SRCS:.c=.o)
diff -NurX mkvexcludes main/Makefile main-mkv/Makefile
--- main/Makefile	2003-04-11 21:27:48.000000000 +0200
+++ main-mkv/Makefile	2003-04-22 23:01:39.000000000 +0200
@@ -35,7 +35,7 @@
 
 VO_LIBS = $(AA_LIB) $(X_LIB) $(SDL_LIB) $(GGI_LIB) $(MP1E_LIB) $(MLIB_LIB) $(SVGA_LIB) $(DIRECTFB_LIB) 
 AO_LIBS = $(ARTS_LIB) $(ESD_LIB) $(NAS_LIB) $(SGIAUDIO_LIB)
-CODEC_LIBS = $(AV_LIB) $(FAME_LIB) $(MAD_LIB) $(VORBIS_LIB) $(FAAD_LIB) $(LIBLZO_LIB) $(DECORE_LIB) $(XVID_LIB) $(PNG_LIB) $(Z_LIB) $(JPEG_LIB) $(ALSA_LIB) $(XMMS_LIB)
+CODEC_LIBS = $(AV_LIB) $(FAME_LIB) $(MAD_LIB) $(VORBIS_LIB) $(FAAD_LIB) $(LIBLZO_LIB) $(DECORE_LIB) $(XVID_LIB) $(PNG_LIB) $(Z_LIB) $(JPEG_LIB) $(ALSA_LIB) $(XMMS_LIB) $(MATROSKA_LIB)
 COMMON_LIBS = libmpcodecs/libmpcodecs.a mp3lib/libMP3.a liba52/liba52.a libmpeg2/libmpeg2.a $(W32_LIB) $(DS_LIB) libaf/libaf.a libmpdemux/libmpdemux.a input/libinput.a postproc/libswscale.a osdep/libosdep.a $(CSS_LIB) $(CODEC_LIBS) $(FREETYPE_LIB) $(TERMCAP_LIB) $(CDPARANOIA_LIB) $(STREAMING_LIB) $(WIN32_LIB) $(GIF_LIB) $(MACOSX_FRAMEWORKS) $(SMBSUPPORT_LIB) $(FRIBIDI_LIB)
 
 CFLAGS = $(OPTFLAGS) -Ilibmpdemux -Iloader -Ilibvo $(FREETYPE_INC) $(EXTRA_INC) $(CDPARANOIA_INC) $(SDL_INC) $(FRIBIDI_INC) # -Wall
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/mplayer-dev-eng/attachments/20030422/5378cb5b/attachment.pgp>


More information about the MPlayer-dev-eng mailing list