diff --git a/configure.ac b/configure.ac
index d288590c7fc4a763f15b6461b5ce27a20bd4c520..a90561858e6c876ba08021c8322f972cc20a81e7 100644
--- a/configure.ac
+++ b/configure.ac
@@ -4220,7 +4220,6 @@ AC_CONFIG_FILES([
   modules/audio_mixer/Makefile
   modules/audio_output/Makefile
   modules/control/Makefile
-  modules/demux/Makefile
   modules/gui/Makefile
   modules/gui/macosx/Makefile
   modules/gui/minimal_macosx/Makefile
diff --git a/modules/Makefile.am b/modules/Makefile.am
index 02b04420663e2b14fbd94c24f15f44a09a87d9cf..a589972f7072c98e926ece5a5f564fea38357829 100644
--- a/modules/Makefile.am
+++ b/modules/Makefile.am
@@ -1,12 +1,12 @@
 noinst_LTLIBRARIES =
 noinst_HEADERS =
+
 BASE_SUBDIRS = \
 	access/rtp \
 	audio_filter \
 	audio_mixer \
 	audio_output \
 	control \
-	demux \
 	gui \
 	meta_engine \
 	misc \
@@ -58,6 +58,12 @@ endif
 include common.am
 include access/Makefile.am
 include codec/Makefile.am
+include demux/Makefile.am
+
+BUILT_SOURCES += dummy.cpp
+
+dummy.cpp:
+	touch dummy.cpp
 
 if HAVE_WIN32
 module.rc: $(top_builddir)/modules/module.rc.in $(top_builddir)/config.status
diff --git a/modules/codec/Makefile.am b/modules/codec/Makefile.am
index 92ae800e257cdf86925228e1779ced268eb53e60..9db48a827b0db36f5fcf26507b7cd1be35fb13f1 100644
--- a/modules/codec/Makefile.am
+++ b/modules/codec/Makefile.am
@@ -26,14 +26,9 @@ codec_LTLIBRARIES += libaes3_plugin.la
 libaraw_plugin_la_SOURCES = codec/araw.c
 codec_LTLIBRARIES += libaraw_plugin.la
 
-libdts_plugin_la_SOURCES = codec/dts.c
-libdts_plugin_la_LIBADD = libvlc_dts_header.la
+libdts_plugin_la_SOURCES = codec/dts.c codec/dts_header.c codec/dts_header.h
 codec_LTLIBRARIES += libdts_plugin.la
 
-libvlc_dts_header_la_SOURCES = codec/dts_header.c codec/dts_header.h
-libvlc_dts_header_la_LDFLAGS = -static
-noinst_LTLIBRARIES += libvlc_dts_header.la
-
 libfaad_plugin_la_SOURCES = codec/faad.c
 libfaad_plugin_la_CPPFLAGS = $(AM_CPPFLAGS) $(CPPFLAGS_faad)
 libfaad_plugin_la_LDFLAGS = $(AM_LDFLAGS) -rpath '$(codecdir)'
diff --git a/modules/demux/Makefile.am b/modules/demux/Makefile.am
index ba976b4d9d9edb43cb5571139231fbb0d54c6555..1252e73e88bb25e6af5be2727463c3395a189a50 100644
--- a/modules/demux/Makefile.am
+++ b/modules/demux/Makefile.am
@@ -1,143 +1,141 @@
-include ../common.am
 demuxdir = $(pluginsdir)/demux
 demux_LTLIBRARIES =
-EXTRA_LTLIBRARIES =
 
-libflacsys_plugin_la_SOURCES = flac.c xiph_metadata.h xiph_metadata.c
+libflacsys_plugin_la_SOURCES = demux/flac.c demux/xiph_metadata.h demux/xiph_metadata.c
 demux_LTLIBRARIES += libflacsys_plugin.la
 
-libogg_plugin_la_SOURCES = ogg.c ogg.h oggseek.c oggseek.h \
-	xiph_metadata.h xiph.h xiph_metadata.c
+libogg_plugin_la_SOURCES = demux/ogg.c demux/ogg.h demux/oggseek.c demux/oggseek.h \
+	demux/xiph_metadata.h demux/xiph.h demux/xiph_metadata.c
 libogg_plugin_la_CFLAGS = $(AM_CFLAGS) $(CFLAGS_ogg)
 libogg_plugin_la_LDFLAGS = $(AM_LDFLAGS) -rpath '$(demuxdir)'
 libogg_plugin_la_LIBADD = $(LIBS_ogg)
 EXTRA_LTLIBRARIES += libogg_plugin.la
 demux_LTLIBRARIES += $(LTLIBogg)
 
-libdemuxdump_plugin_la_SOURCES = demuxdump.c
+libdemuxdump_plugin_la_SOURCES = demux/demuxdump.c
 demux_LTLIBRARIES += libdemuxdump_plugin.la
 
-librawdv_plugin_la_SOURCES = rawdv.c rawdv.h
+librawdv_plugin_la_SOURCES = demux/rawdv.c demux/rawdv.h
 demux_LTLIBRARIES += librawdv_plugin.la
 
-librawvid_plugin_la_SOURCES = rawvid.c
+librawvid_plugin_la_SOURCES = demux/rawvid.c
 demux_LTLIBRARIES += librawvid_plugin.la
 
-libau_plugin_la_SOURCES = au.c
+libau_plugin_la_SOURCES = demux/au.c
 demux_LTLIBRARIES += libau_plugin.la
 
-librawaud_plugin_la_SOURCES = rawaud.c
+librawaud_plugin_la_SOURCES = demux/rawaud.c
 demux_LTLIBRARIES += librawaud_plugin.la
 
-libwav_plugin_la_SOURCES = wav.c
+libwav_plugin_la_SOURCES = demux/wav.c
 demux_LTLIBRARIES += libwav_plugin.la
 
-libnsv_plugin_la_SOURCES = nsv.c
+libnsv_plugin_la_SOURCES = demux/nsv.c
 demux_LTLIBRARIES += libnsv_plugin.la
 
-libreal_plugin_la_SOURCES = real.c
+libreal_plugin_la_SOURCES = demux/real.c
 demux_LTLIBRARIES += libreal_plugin.la
 
-libps_plugin_la_SOURCES = ps.c ps.h
+libps_plugin_la_SOURCES = demux/ps.c demux/ps.h
 demux_LTLIBRARIES += libps_plugin.la
 
-libmod_plugin_la_SOURCES = mod.c
+libmod_plugin_la_SOURCES = demux/mod.c
 libmod_plugin_la_CXXFLAGS = $(AM_CXXFLAGS) $(CXXFLAGS_mod)
 libmod_plugin_la_LDFLAGS = $(AM_LDFLAGS) -rpath '$(demuxdir)'
 libmod_plugin_la_LIBADD = $(LIBS_mod)
 EXTRA_LTLIBRARIES += libmod_plugin.la
 demux_LTLIBRARIES += $(LTLIBmod)
 
-libpva_plugin_la_SOURCES = pva.c
+libpva_plugin_la_SOURCES = demux/pva.c
 demux_LTLIBRARIES += libpva_plugin.la
 
-libaiff_plugin_la_SOURCES = aiff.c
+libaiff_plugin_la_SOURCES = demux/aiff.c
 demux_LTLIBRARIES += libaiff_plugin.la
 
-libmjpeg_plugin_la_SOURCES = mjpeg.c mxpeg_helper.h
+libmjpeg_plugin_la_SOURCES = demux/mjpeg.c demux/mxpeg_helper.h
 demux_LTLIBRARIES += libmjpeg_plugin.la
 
-libsubtitle_plugin_la_SOURCES = subtitle.c
+libsubtitle_plugin_la_SOURCES = demux/subtitle.c
 demux_LTLIBRARIES += libsubtitle_plugin.la
 
-libty_plugin_la_SOURCES = ty.c ../codec/cc.h
+libty_plugin_la_SOURCES = demux/ty.c codec/cc.h
 demux_LTLIBRARIES += libty_plugin.la
 
-libvobsub_plugin_la_SOURCES = vobsub.c vobsub.h
+libvobsub_plugin_la_SOURCES = demux/vobsub.c demux/vobsub.h
 demux_LTLIBRARIES += libvobsub_plugin.la
 
-libvoc_plugin_la_SOURCES = voc.c
+libvoc_plugin_la_SOURCES = demux/voc.c
 demux_LTLIBRARIES += libvoc_plugin.la
 
-libxa_plugin_la_SOURCES = xa.c
+libxa_plugin_la_SOURCES = demux/xa.c
 demux_LTLIBRARIES += libxa_plugin.la
 
-libnuv_plugin_la_SOURCES = nuv.c
+libnuv_plugin_la_SOURCES = demux/nuv.c
 demux_LTLIBRARIES += libnuv_plugin.la
 
-libnsc_plugin_la_SOURCES = nsc.c
+libnsc_plugin_la_SOURCES = demux/nsc.c
 demux_LTLIBRARIES += libnsc_plugin.la
 
-libmpc_plugin_la_SOURCES = mpc.c
+libmpc_plugin_la_SOURCES = demux/mpc.c
 libmpc_plugin_la_LDFLAGS = $(AM_LDFLAGS) -rpath '$(demuxdir)'
 libmpc_plugin_la_LIBADD = $(LIBS_mpc)
 EXTRA_LTLIBRARIES += libmpc_plugin.la
 demux_LTLIBRARIES += $(LTLIBmpc)
 
-libtta_plugin_la_SOURCES = tta.c
+libtta_plugin_la_SOURCES = demux/tta.c
 libtta_plugin_la_LDFLAGS = $(AM_LDFLAGS) -rpath '$(demuxdir)'
 demux_LTLIBRARIES += libtta_plugin.la
 
-libvc1_plugin_la_SOURCES = vc1.c
+libvc1_plugin_la_SOURCES = demux/vc1.c
 libvc1_plugin_la_LDFLAGS = $(AM_LDFLAGS) -rpath '$(demuxdir)'
 demux_LTLIBRARIES += libvc1_plugin.la
 
-libdemux_cdg_plugin_la_SOURCES = cdg.c
+libdemux_cdg_plugin_la_SOURCES = demux/cdg.c
 libdemux_cdg_plugin_la_LDFLAGS = $(AM_LDFLAGS) -rpath '$(demuxdir)'
 demux_LTLIBRARIES += libdemux_cdg_plugin.la
 
-libsmf_plugin_la_SOURCES = smf.c
+libsmf_plugin_la_SOURCES = demux/smf.c
 libsmf_plugin_la_LDFLAGS = $(AM_LDFLAGS) -rpath '$(demuxdir)'
 demux_LTLIBRARIES += libsmf_plugin.la
 
-libgme_plugin_la_SOURCES = gme.c dummy.cpp
+libgme_plugin_la_SOURCES = demux/gme.c dummy.cpp
 libgme_plugin_la_LDFLAGS = $(AM_LDFLAGS) -rpath '$(demuxdir)'
 libgme_plugin_la_LIBADD = $(LIBS_gme)
 EXTRA_LTLIBRARIES += libgme_plugin.la
 demux_LTLIBRARIES += $(LTLIBgme)
 
-libsid_plugin_la_SOURCES = sid.cpp
+libsid_plugin_la_SOURCES = demux/sid.cpp
 libsid_plugin_la_CFLAGS = $(AM_CFLAGS) $(CFLAGS_sid)
 libsid_plugin_la_LDFLAGS = $(AM_LDFLAGS) -rpath '$(demuxdir)'
 libsid_plugin_la_LIBADD = $(LIBS_sid)
 EXTRA_LTLIBRARIES += libsid_plugin.la
 demux_LTLIBRARIES += $(LTLIBsid)
 
-libdiracsys_plugin_la_SOURCES = dirac.c
+libdiracsys_plugin_la_SOURCES = demux/dirac.c
 demux_LTLIBRARIES += libdiracsys_plugin.la
 
-libimage_plugin_la_SOURCES = image.c mxpeg_helper.h
+libimage_plugin_la_SOURCES = demux/image.c demux/mxpeg_helper.h
 demux_LTLIBRARIES += libimage_plugin.la
 
-libdemux_stl_plugin_la_SOURCES = stl.c
+libdemux_stl_plugin_la_SOURCES = demux/stl.c
 demux_LTLIBRARIES += libdemux_stl_plugin.la
 
-libasf_plugin_la_SOURCES = asf/asf.c asf/libasf.c asf/libasf.h asf/libasf_guid.h
+libasf_plugin_la_SOURCES = demux/asf/asf.c demux/asf/libasf.c demux/asf/libasf.h demux/asf/libasf_guid.h
 demux_LTLIBRARIES += libasf_plugin.la
 
-libavi_plugin_la_SOURCES = avi/avi.c avi/libavi.c avi/libavi.h
+libavi_plugin_la_SOURCES = demux/avi/avi.c demux/avi/libavi.c demux/avi/libavi.h
 demux_LTLIBRARIES += libavi_plugin.la
 
-libavformat_plugin_la_SOURCES = avformat/demux.c \
-	../codec/avcodec/fourcc.c \
-	../codec/avcodec/chroma.c \
-	../codec/avcodec/cpu.c \
-	../codec/avcodec/avcommon.h \
-	../codec/avcodec/avcommon_compat.h \
-	vobsub.h \
-	avformat/avformat.c avformat/avformat.h
+libavformat_plugin_la_SOURCES = demux/avformat/demux.c \
+	codec/avcodec/fourcc.c \
+	codec/avcodec/chroma.c \
+	codec/avcodec/cpu.c \
+	codec/avcodec/avcommon.h \
+	codec/avcodec/avcommon_compat.h \
+	demux/vobsub.h \
+	demux/avformat/avformat.c demux/avformat/avformat.h
 if ENABLE_SOUT
-libavformat_plugin_la_SOURCES += avformat/mux.c
+libavformat_plugin_la_SOURCES += demux/avformat/mux.c
 endif
 libavformat_plugin_la_CFLAGS = $(AM_CFLAGS) $(AVFORMAT_CFLAGS) $(AVUTIL_CFLAGS)
 libavformat_plugin_la_LIBADD = $(AVFORMAT_LIBS) $(AVUTIL_LIBS) $(LIBM)
@@ -155,25 +153,24 @@ if HAVE_AVFORMAT
 demux_LTLIBRARIES += libavformat_plugin.la
 endif
 
-libes_plugin_la_SOURCES  = mpeg/es.c
-libes_plugin_la_LIBADD = ../libvlc_dts_header.la
+libes_plugin_la_SOURCES  = demux/mpeg/es.c codec/dts_header.c codec/dts_header.h
 demux_LTLIBRARIES += libes_plugin.la
 
-libh264_plugin_la_SOURCES = mpeg/h264.c
+libh264_plugin_la_SOURCES = demux/mpeg/h264.c
 demux_LTLIBRARIES += libh264_plugin.la
 
 libmkv_plugin_la_SOURCES = \
-	mkv/util.hpp mkv/util.cpp \
-	mkv/virtual_segment.hpp mkv/virtual_segment.cpp \
-	mkv/matroska_segment.hpp mkv/matroska_segment.cpp \
-	mkv/matroska_segment_parse.cpp \
-	mkv/demux.hpp mkv/demux.cpp \
-	mkv/Ebml_parser.hpp mkv/Ebml_parser.cpp \
-	mkv/chapters.hpp mkv/chapters.cpp \
-	mkv/chapter_command.hpp mkv/chapter_command.cpp \
-	mkv/stream_io_callback.hpp mkv/stream_io_callback.cpp \
-	mp4/libmp4.c vobsub.h \
-	mkv/mkv.hpp mkv/mkv.cpp
+	demux/mkv/util.hpp demux/mkv/util.cpp \
+	demux/mkv/virtual_segment.hpp demux/mkv/virtual_segment.cpp \
+	demux/mkv/matroska_segment.hpp demux/mkv/matroska_segment.cpp \
+	demux/mkv/matroska_segment_parse.cpp \
+	demux/mkv/demux.hpp demux/mkv/demux.cpp \
+	demux/mkv/Ebml_parser.hpp demux/mkv/Ebml_parser.cpp \
+	demux/mkv/chapters.hpp demux/mkv/chapters.cpp \
+	demux/mkv/chapter_command.hpp demux/mkv/chapter_command.cpp \
+	demux/mkv/stream_io_callback.hpp demux/mkv/stream_io_callback.cpp \
+	demux/mp4/libmp4.c demux/vobsub.h \
+	demux/mkv/mkv.hpp demux/mkv/mkv.cpp
 libmkv_plugin_la_CPPFLAGS = $(AM_CPPFLAGS)
 libmkv_plugin_la_LDFLAGS = $(AM_LDFLAGS) -rpath '$(demuxdir)'
 libmkv_plugin_la_LIBADD = $(LIBS_mkv)
@@ -183,7 +180,7 @@ endif
 demux_LTLIBRARIES += $(LTLIBmkv)
 EXTRA_LTLIBRARIES += libmkv_plugin.la
 
-libmp4_plugin_la_SOURCES = mp4/mp4.c mp4/libmp4.c mp4/libmp4.h mp4/id3genres.h
+libmp4_plugin_la_SOURCES = demux/mp4/mp4.c demux/mp4/libmp4.c demux/mp4/libmp4.h demux/mp4/id3genres.h
 libmp4_plugin_la_LIBADD = $(LIBM)
 libmp4_plugin_la_LDFLAGS = $(AM_LDFLAGS)
 if HAVE_ZLIB
@@ -191,31 +188,31 @@ libmp4_plugin_la_LIBADD += -lz
 endif
 demux_LTLIBRARIES += libmp4_plugin.la
 
-libmpgv_plugin_la_SOURCES = mpeg/mpgv.c
+libmpgv_plugin_la_SOURCES = demux/mpeg/mpgv.c
 demux_LTLIBRARIES += libmpgv_plugin.la
 
 libplaylist_plugin_la_SOURCES = \
-	playlist/asx.c \
-	playlist/b4s.c \
-	playlist/dvb.c \
-	playlist/gvp.c \
-	playlist/ifo.c \
-	playlist/itml.c \
-	playlist/itml.h \
-	playlist/m3u.c \
-	playlist/pls.c \
-	playlist/podcast.c \
-	playlist/qtl.c \
-	playlist/ram.c \
-	playlist/sgimb.c \
-	playlist/shoutcast.c \
-	playlist/wpl.c \
-	playlist/xspf.c \
-	playlist/zpl.c \
-	playlist/playlist.c playlist/playlist.h
+	demux/playlist/asx.c \
+	demux/playlist/b4s.c \
+	demux/playlist/dvb.c \
+	demux/playlist/gvp.c \
+	demux/playlist/ifo.c \
+	demux/playlist/itml.c \
+	demux/playlist/itml.h \
+	demux/playlist/m3u.c \
+	demux/playlist/pls.c \
+	demux/playlist/podcast.c \
+	demux/playlist/qtl.c \
+	demux/playlist/ram.c \
+	demux/playlist/sgimb.c \
+	demux/playlist/shoutcast.c \
+	demux/playlist/wpl.c \
+	demux/playlist/xspf.c \
+	demux/playlist/zpl.c \
+	demux/playlist/playlist.c demux/playlist/playlist.h
 demux_LTLIBRARIES += libplaylist_plugin.la
 
-libts_plugin_la_SOURCES = ts.c ../mux/mpeg/csa.c ../mux/mpeg/dvbpsi_compat.h dvb-text.h
+libts_plugin_la_SOURCES = demux/ts.c mux/mpeg/csa.c mux/mpeg/dvbpsi_compat.h demux/dvb-text.h
 libts_plugin_la_CFLAGS = $(AM_CFLAGS) $(DVBPSI_CFLAGS)
 libts_plugin_la_LIBADD = $(DVBPSI_LIBS) $(SOCKET_LIBS)
 if HAVE_WIN32
@@ -224,8 +221,3 @@ endif
 if HAVE_DVBPSI
 demux_LTLIBRARIES += libts_plugin.la
 endif
-
-BUILT_SOURCES += dummy.cpp
-
-dummy.cpp:
-	touch dummy.cpp