]> git.sesse.net Git - vlc/blobdiff - modules/demux/mpeg/es.c
make_URI: add scheme parameter
[vlc] / modules / demux / mpeg / es.c
index 3d05ea383dd9d1e47c26cb128d15763a8851877d..0103e1412532469e33276668a6026a542e25c45b 100644 (file)
 #include <vlc_plugin.h>
 #include <vlc_demux.h>
 #include <vlc_codec.h>
+#include <vlc_codecs.h>
 #include <vlc_input.h>
 
+#include "../../codec/a52.h"
+
 /*****************************************************************************
  * Module descriptor
  *****************************************************************************/
-static int  Open ( vlc_object_t * );
-static void Close( vlc_object_t * );
-
-vlc_module_begin();
-    set_category( CAT_INPUT );
-    set_subcategory( SUBCAT_INPUT_DEMUX );
-    set_description( N_("MPEG-I/II/4 / A52 / DTS audio" ) );
-    set_capability( "demux", 155 );
-    set_callbacks( Open, Close );
-
-    add_shortcut( "mpga" );
-    add_shortcut( "mp3" );
-
-    add_shortcut( "m4a" );
-    add_shortcut( "mp4a" );
-    add_shortcut( "aac" );
-
-    add_shortcut( "ac3" );
-    add_shortcut( "a52" );
-
-    add_shortcut( "dts" );
-vlc_module_end();
+static int  OpenAudio( vlc_object_t * );
+static int  OpenVideo( vlc_object_t * );
+static void Close    ( vlc_object_t * );
+
+#define FPS_TEXT N_("Frames per Second")
+#define FPS_LONGTEXT N_("This is the frame rate used as a fallback when " \
+    "playing MPEG video elementary streams.")
+
+vlc_module_begin ()
+    set_category( CAT_INPUT )
+    set_subcategory( SUBCAT_INPUT_DEMUX )
+    set_description( N_("MPEG-I/II/4 / A52 / DTS / MLP audio" ) )
+    set_capability( "demux", 155 )
+    set_callbacks( OpenAudio, Close )
+
+    add_shortcut( "mpga", "mp3",
+                  "m4a", "mp4a", "aac",
+                  "ac3", "a52",
+                  "eac3",
+                  "dts",
+                  "mlp", "thd" )
+
+    add_submodule()
+    set_description( N_("MPEG-4 video" ) )
+    set_capability( "demux", 0 )
+    set_callbacks( OpenVideo, Close )
+    add_float( "es-fps", 25, NULL, FPS_TEXT, FPS_LONGTEXT, false )
+
+    add_shortcut( "m4v" )
+    add_shortcut( "mp4v" )
+vlc_module_end ()
 
 /*****************************************************************************
  * Local prototypes
@@ -100,6 +112,8 @@ struct demux_sys_t
 
     int64_t i_stream_offset;
 
+    float   f_fps;
+
     /* Mpga specific */
     struct
     {
@@ -116,51 +130,53 @@ static int MpgaInit( demux_t *p_demux );
 static int AacProbe( demux_t *p_demux, int64_t *pi_offset );
 static int AacInit( demux_t *p_demux );
 
+static int EA52Probe( demux_t *p_demux, int64_t *pi_offset );
 static int A52Probe( demux_t *p_demux, int64_t *pi_offset );
 static int A52Init( demux_t *p_demux );
 
 static int DtsProbe( demux_t *p_demux, int64_t *pi_offset );
 static int DtsInit( demux_t *p_demux );
 
-static const codec_t p_codec[] = {
-    { VLC_FOURCC( 'm', 'p', '4', 'a' ), false, "mp4 audio", AacProbe, AacInit },
-    { VLC_FOURCC( 'm', 'p', 'g', 'a' ), false, "mpeg audio", MpgaProbe, MpgaInit },
-    { VLC_FOURCC( 'a', '5', '2', ' ' ), true,  "a52 audio", A52Probe, A52Init },
-    { VLC_FOURCC( 'd', 't', 's', ' ' ), false, "dts audio", DtsProbe, DtsInit },
+static int MlpProbe( demux_t *p_demux, int64_t *pi_offset );
+static int MlpInit( demux_t *p_demux );
+
+static const codec_t p_codecs[] = {
+    { VLC_CODEC_MP4A, false, "mp4 audio",  AacProbe,  AacInit },
+    { VLC_CODEC_MPGA, false, "mpeg audio", MpgaProbe, MpgaInit },
+    { VLC_CODEC_A52, true,  "a52 audio",  A52Probe,  A52Init },
+    { VLC_CODEC_EAC3, true,  "eac3 audio", EA52Probe, A52Init },
+    { VLC_CODEC_DTS, false, "dts audio",  DtsProbe,  DtsInit },
+    { VLC_CODEC_TRUEHD, false, "mlp audio",  MlpProbe,  MlpInit },
 
     { 0, false, NULL, NULL, NULL }
 };
 
+static int VideoInit( demux_t *p_demux );
+
+static const codec_t codec_m4v = {
+    VLC_CODEC_MP4V, false, "mp4 video", NULL,  VideoInit
+};
+
 /*****************************************************************************
- * Open: initializes demux structures
+ * OpenCommon: initializes demux structures
  *****************************************************************************/
-static int Open( vlc_object_t * p_this )
+static int OpenCommon( demux_t *p_demux,
+                       int i_cat, const codec_t *p_codec, int64_t i_bs_offset )
 {
-    demux_t     *p_demux = (demux_t*)p_this;
     demux_sys_t *p_sys;
 
     es_format_t fmt;
-    int64_t i_offset;
-    int i_index;
-
-    for( i_index = 0; p_codec[i_index].i_codec != 0; i_index++ )
-    {
-        if( !p_codec[i_index].pf_probe( p_demux, &i_offset ) )
-            break;
-    }
-
-    if( p_codec[i_index].i_codec == 0 )
-        return VLC_EGENERIC;
 
     DEMUX_INIT_COMMON(); p_sys = p_demux->p_sys;
     memset( p_sys, 0, sizeof( demux_sys_t ) );
-    p_sys->codec = p_codec[i_index];
+    p_sys->codec = *p_codec;
     p_sys->p_es = NULL;
     p_sys->b_start = true;
-    p_sys->i_stream_offset = i_offset;
+    p_sys->i_stream_offset = i_bs_offset;
     p_sys->b_estimate_bitrate = true;
     p_sys->i_bitrate_avg = 0;
     p_sys->b_big_endian = false;
+    p_sys->f_fps = var_InheritFloat( p_demux, "es-fps" );
 
     if( stream_Seek( p_demux->s, p_sys->i_stream_offset ) )
     {
@@ -177,7 +193,7 @@ static int Open( vlc_object_t * p_this )
     msg_Dbg( p_demux, "detected format %4.4s", (const char*)&p_sys->codec.i_codec );
 
     /* Load the audio packetizer */
-    es_format_Init( &fmt, AUDIO_ES, p_sys->codec.i_codec );
+    es_format_Init( &fmt, i_cat, p_sys->codec.i_codec );
     p_sys->p_packetizer = demux_PacketizerNew( p_demux, &fmt, p_sys->codec.psz_name );
     if( !p_sys->p_packetizer )
     {
@@ -186,7 +202,40 @@ static int Open( vlc_object_t * p_this )
     }
     return VLC_SUCCESS;
 }
+static int OpenAudio( vlc_object_t *p_this )
+{
+    demux_t *p_demux = (demux_t*)p_this;
+    for( int i = 0; p_codecs[i].i_codec != 0; i++ )
+    {
+        int64_t i_offset;
+        if( !p_codecs[i].pf_probe( p_demux, &i_offset ) )
+            return OpenCommon( p_demux, AUDIO_ES, &p_codecs[i], i_offset );
+    }
+    return VLC_EGENERIC;
+}
+static int OpenVideo( vlc_object_t *p_this )
+{
+    demux_t *p_demux = (demux_t*)p_this;
 
+    /* Only m4v is supported for the moment */
+    bool b_m4v_ext    = demux_IsPathExtension( p_demux, ".m4v" );
+    bool b_m4v_forced = demux_IsForced( p_demux, "m4v" ) ||
+                        demux_IsForced( p_demux, "mp4v" );
+    if( !b_m4v_ext && !b_m4v_forced )
+        return VLC_EGENERIC;
+
+    const uint8_t *p_peek;
+    if( stream_Peek( p_demux->s, &p_peek, 4 ) < 4 )
+        return VLC_EGENERIC;
+    if( p_peek[0] != 0x00 || p_peek[1] != 0x00 || p_peek[2] != 0x01 )
+    {
+        if( !b_m4v_forced)
+            return VLC_EGENERIC;
+        msg_Warn( p_demux,
+                  "this doesn't look like an MPEG ES stream, continuing anyway" );
+    }
+    return OpenCommon( p_demux, VIDEO_ES, &codec_m4v, 0 );
+}
 /*****************************************************************************
  * Demux: reads and demuxes data packets
  *****************************************************************************
@@ -211,21 +260,10 @@ static int Demux( demux_t *p_demux )
     if( p_sys->codec.b_use_word && !p_sys->b_big_endian && p_block_in->i_buffer > 0 )
     {
         /* Convert to big endian */
-#ifdef HAVE_SWAB
         swab( p_block_in->p_buffer, p_block_in->p_buffer, p_block_in->i_buffer );
-#else
-        uint8_t *p_tmp = p_block_in->p_buffer;
-        for( int i = p_block_in->i_buffer / 2 ; i-- ; )
-        {
-            uint8_t tmp = p_tmp[0];
-            p_tmp[0] = p_tmp[1];
-            p_tmp[1] = tmp;
-            p_tmp += 2;
-        }
-#endif
     }
 
-    p_block_in->i_pts = p_block_in->i_dts = p_sys->b_start || p_sys->b_initial_sync_failed ? 1 : 0;
+    p_block_in->i_pts = p_block_in->i_dts = p_sys->b_start || p_sys->b_initial_sync_failed ? VLC_TS_0 : VLC_TS_INVALID;
     p_sys->b_initial_sync_failed = p_sys->b_start; /* Only try to resync once */
 
     while( ( p_block_out = p_sys->p_packetizer->pf_packetize( p_sys->p_packetizer, &p_block_in ) ) )
@@ -257,19 +295,34 @@ static int Demux( demux_t *p_demux )
                 if( p_sys->b_estimate_bitrate )
                     p_sys->i_bitrate_avg = p_sys->p_packetizer->fmt_out.i_bitrate;
             }
-
-            p_sys->i_pts = p_block_out->i_pts;
+            if( p_sys->p_packetizer->fmt_out.i_cat == VIDEO_ES )
+            {
+                if( p_block_out->i_pts <= VLC_TS_INVALID &&
+                    p_block_out->i_dts <= VLC_TS_INVALID )
+                    p_block_out->i_dts = VLC_TS_0 + p_sys->i_pts + 1000000 / p_sys->f_fps;
+                if( p_block_out->i_dts > VLC_TS_INVALID )
+                    p_sys->i_pts = p_block_out->i_dts - VLC_TS_0;
+            }
+            else
+            {
+                p_sys->i_pts = p_block_out->i_pts - VLC_TS_0;
+            }
 
             /* Re-estimate bitrate */
-            if( p_sys->b_estimate_bitrate && p_sys->i_pts > 1 + INT64_C(500000) )
+            if( p_sys->b_estimate_bitrate && p_sys->i_pts > INT64_C(500000) )
                 p_sys->i_bitrate_avg = 8*INT64_C(1000000)*p_sys->i_bytes/(p_sys->i_pts-1);
             p_sys->i_bytes += p_block_out->i_buffer;
 
             /* Correct timestamp */
-            p_block_out->i_pts += p_sys->i_time_offset;
-            p_block_out->i_dts += p_sys->i_time_offset;
-
-            es_out_Control( p_demux->out, ES_OUT_SET_PCR, p_block_out->i_dts );
+            if( p_block_out->i_pts > VLC_TS_INVALID )
+            {
+                p_block_out->i_pts += p_sys->i_time_offset;
+            }
+            if( p_block_out->i_dts > VLC_TS_INVALID )
+            {
+                p_block_out->i_dts += p_sys->i_time_offset;
+                es_out_Control( p_demux->out, ES_OUT_SET_PCR, p_block_out->i_dts );
+            }
 
             es_out_Send( p_demux->out, p_sys->p_es, p_block_out );
 
@@ -364,6 +417,160 @@ static int Control( demux_t *p_demux, int i_query, va_list args )
     }
 }
 
+/*****************************************************************************
+ * Wav header skipper
+ *****************************************************************************/
+#define WAV_PROBE_SIZE (512*1024)
+static int WavSkipHeader( demux_t *p_demux, int *pi_skip, const int pi_format[] )
+{
+    const uint8_t *p_peek;
+    int         i_peek = 0;
+
+    /* */
+    *pi_skip = 0;
+
+    /* Check if we are dealing with a WAV file */
+    if( stream_Peek( p_demux->s, &p_peek, 12+8 ) != 12 + 8 )
+        return VLC_SUCCESS;
+
+    if( memcmp( p_peek, "RIFF", 4 ) || memcmp( &p_peek[8], "WAVE", 4 ) )
+        return VLC_SUCCESS;
+
+    /* Find the wave format header */
+    i_peek = 12 + 8;
+    while( memcmp( p_peek + i_peek - 8, "fmt ", 4 ) )
+    {
+        uint32_t i_len = GetDWLE( p_peek + i_peek - 4 );
+        if( i_len > WAV_PROBE_SIZE || i_peek + i_len > WAV_PROBE_SIZE )
+            return VLC_EGENERIC;
+
+        i_peek += i_len + 8;
+        if( stream_Peek( p_demux->s, &p_peek, i_peek ) != i_peek )
+            return VLC_EGENERIC;
+    }
+
+    /* Sanity check the wave format header */
+    uint32_t i_len = GetDWLE( p_peek + i_peek - 4 );
+    if( i_len > WAV_PROBE_SIZE )
+        return VLC_EGENERIC;
+
+    i_peek += i_len + 8;
+    if( stream_Peek( p_demux->s, &p_peek, i_peek ) != i_peek )
+        return VLC_EGENERIC;
+    const int i_format = GetWLE( p_peek + i_peek - i_len - 8 /* wFormatTag */ );
+    int i_format_idx;
+    for( i_format_idx = 0; pi_format[i_format_idx] != WAVE_FORMAT_UNKNOWN; i_format_idx++ )
+    {
+        if( i_format == pi_format[i_format_idx] )
+            break;
+    }
+    if( pi_format[i_format_idx] == WAVE_FORMAT_UNKNOWN )
+        return VLC_EGENERIC;
+
+    if( i_format == WAVE_FORMAT_PCM )
+    {
+        if( GetWLE( p_peek + i_peek - i_len - 6 /* nChannels */ ) != 2 )
+            return VLC_EGENERIC;
+        if( GetDWLE( p_peek + i_peek - i_len - 4 /* nSamplesPerSec */ ) !=
+            44100 )
+            return VLC_EGENERIC;
+    }
+
+    /* Skip the wave header */
+    while( memcmp( p_peek + i_peek - 8, "data", 4 ) )
+    {
+        uint32_t i_len = GetDWLE( p_peek + i_peek - 4 );
+        if( i_len > WAV_PROBE_SIZE || i_peek + i_len > WAV_PROBE_SIZE )
+            return VLC_EGENERIC;
+
+        i_peek += i_len + 8;
+        if( stream_Peek( p_demux->s, &p_peek, i_peek ) != i_peek )
+            return VLC_EGENERIC;
+    }
+    *pi_skip = i_peek;
+    return VLC_SUCCESS;
+}
+
+static int GenericProbe( demux_t *p_demux, int64_t *pi_offset,
+                         const char * ppsz_name[],
+                         int (*pf_check)( const uint8_t *, int * ), int i_check_size,
+                         const int pi_wav_format[] )
+{
+    bool   b_forced_demux;
+
+    int64_t i_offset;
+    const uint8_t *p_peek;
+    int i_skip;
+
+    b_forced_demux = false;
+    for( int i = 0; ppsz_name[i] != NULL; i++ )
+    {
+        b_forced_demux |= demux_IsForced( p_demux, ppsz_name[i] );
+    }
+
+    i_offset = stream_Tell( p_demux->s );
+
+    if( WavSkipHeader( p_demux, &i_skip, pi_wav_format ) )
+    {
+        if( !b_forced_demux )
+            return VLC_EGENERIC;
+    }
+    const bool b_wav = i_skip > 0;
+
+    /* peek the begining
+     * It is common that wav files have some sort of garbage at the begining
+     * We will accept probing 0.5s of data in this case.
+     */
+    const int i_probe = i_skip + i_check_size + 8000 + ( b_wav ? (44000/2*2*2) : 0);
+    const int i_peek = stream_Peek( p_demux->s, &p_peek, i_probe );
+    if( i_peek < i_skip + i_check_size )
+    {
+        msg_Err( p_demux, "cannot peek" );
+        return VLC_EGENERIC;
+    }
+    for( ;; )
+    {
+        if( i_skip + i_check_size > i_peek )
+        {
+            if( !b_forced_demux )
+                return VLC_EGENERIC;
+            break;
+        }
+        int i_samples = 0;
+        int i_size = pf_check( &p_peek[i_skip], &i_samples );
+        if( i_size >= 0 )
+        {
+            if( i_size == 0 )
+                break;
+
+            /* If we have the frame size, check the next frame for
+             * extra robustness
+             * The second test is because some .wav have paddings
+             */
+            bool b_ok = false;
+            for( int t = 0; t < 1 + !!b_wav; t++ )
+            {
+                if( t == 1 )
+                    i_size = i_samples * 2 * 2;
+                if( i_skip + i_check_size + i_size <= i_peek )
+                {
+                    b_ok = pf_check( &p_peek[i_skip+i_size], NULL ) >= 0;
+                    if( b_ok )
+                        break;
+                }
+            }
+            if( b_ok )
+                break;
+        }
+        i_skip++;
+        if( !b_wav && !b_forced_demux )
+            return VLC_EGENERIC;
+    }
+
+    *pi_offset = i_offset + i_skip;
+    return VLC_SUCCESS;
+}
+
 /*****************************************************************************
  * Mpeg I/II Audio
  *****************************************************************************/
@@ -404,21 +611,32 @@ static int MpgaGetFrameSamples( uint32_t h )
 
 static int MpgaProbe( demux_t *p_demux, int64_t *pi_offset )
 {
+    const int pi_wav[] = { WAVE_FORMAT_MPEG, WAVE_FORMAT_MPEGLAYER3, WAVE_FORMAT_UNKNOWN };
     bool   b_forced;
     bool   b_forced_demux;
     int64_t i_offset;
 
-    const uint8_t     *p_peek;
+    const uint8_t *p_peek;
+    int i_skip;
 
     b_forced = demux_IsPathExtension( p_demux, ".mp3" );
     b_forced_demux = demux_IsForced( p_demux, "mp3" ) ||
                      demux_IsForced( p_demux, "mpga" );
 
     i_offset = stream_Tell( p_demux->s );
-    if( stream_Peek( p_demux->s, &p_peek, 4 ) < 4 )
+
+    if( WavSkipHeader( p_demux, &i_skip, pi_wav ) )
+    {
+        if( !b_forced_demux )
+            return VLC_EGENERIC;
+
         return VLC_EGENERIC;
+    }
 
-    if( !MpgaCheckSync( p_peek ) )
+    if( stream_Peek( p_demux->s, &p_peek, i_skip + 4 ) < i_skip + 4 )
+        return VLC_EGENERIC;
+
+    if( !MpgaCheckSync( &p_peek[i_skip] ) )
     {
         bool b_ok = false;
         int i_peek;
@@ -426,22 +644,20 @@ static int MpgaProbe( demux_t *p_demux, int64_t *pi_offset )
         if( !b_forced_demux && !b_forced )
             return VLC_EGENERIC;
 
-        i_peek = stream_Peek( p_demux->s, &p_peek, 8096 );
-        while( i_peek > 4 )
+        i_peek = stream_Peek( p_demux->s, &p_peek, i_skip + 8096 );
+        while( i_skip + 4 < i_peek )
         {
-            if( MpgaCheckSync( p_peek ) )
+            if( MpgaCheckSync( &p_peek[i_skip] ) )
             {
                 b_ok = true;
                 break;
             }
-            p_peek += 1;
-            i_peek -= 1;
-            i_offset++;
+            i_skip++;
         }
         if( !b_ok && !b_forced_demux )
             return VLC_EGENERIC;
     }
-    *pi_offset = i_offset;
+    *pi_offset = i_offset + i_skip;
     return VLC_SUCCESS;
 }
 
@@ -574,143 +790,57 @@ static int AacInit( demux_t *p_demux )
     return VLC_SUCCESS;
 }
 
+
 /*****************************************************************************
- * Wav header skipper
+ * A52
  *****************************************************************************/
-#define WAV_PROBE_SIZE (512*1024)
-static int WavSkipHeader( demux_t *p_demux, int *pi_skip )
+static int A52CheckSync( const uint8_t *p_peek, bool *p_big_endian, int *pi_samples, bool b_eac3 )
 {
-    const uint8_t *p_peek;
-    int         i_peek = 0;
+    vlc_a52_header_t header;
+    uint8_t p_tmp[VLC_A52_HEADER_SIZE];
 
-    /* */
-    *pi_skip = 0;
-
-    /* Check if we are dealing with a WAV file */
-    if( stream_Peek( p_demux->s, &p_peek, 12+8 ) != 12 + 8 )
-        return VLC_SUCCESS;
-
-    if( memcmp( p_peek, "RIFF", 4 ) || memcmp( &p_peek[8], "WAVE", 4 ) )
-        return VLC_SUCCESS;
-
-    /* Find the wave format header */
-    i_peek = 12 + 8;
-    while( memcmp( p_peek + i_peek - 8, "fmt ", 4 ) )
+    *p_big_endian =  p_peek[0] == 0x0b && p_peek[1] == 0x77;
+    if( !*p_big_endian )
     {
-        uint32_t i_len = GetDWLE( p_peek + i_peek - 4 );
-        if( i_len > WAV_PROBE_SIZE || i_peek + i_len > WAV_PROBE_SIZE )
-            return VLC_EGENERIC;
-
-        i_peek += i_len + 8;
-        if( stream_Peek( p_demux->s, &p_peek, i_peek ) != i_peek )
-            return VLC_EGENERIC;
+        swab( p_peek, p_tmp, VLC_A52_HEADER_SIZE );
+        p_peek = p_tmp;
     }
 
-    /* Sanity check the wave format header */
-    uint32_t i_len = GetDWLE( p_peek + i_peek - 4 );
-    if( i_len > WAV_PROBE_SIZE )
+    if( vlc_a52_header_Parse( &header, p_peek, VLC_A52_HEADER_SIZE ) )
         return VLC_EGENERIC;
 
-    i_peek += i_len + 8;
-    if( stream_Peek( p_demux->s, &p_peek, i_peek ) != i_peek )
-        return VLC_EGENERIC;
-    if( GetWLE( p_peek + i_peek - i_len - 8 /* wFormatTag */ ) !=
-        1 /* WAVE_FORMAT_PCM */ )
-        return VLC_EGENERIC;
-    if( GetWLE( p_peek + i_peek - i_len - 6 /* nChannels */ ) != 2 )
+    if( !header.b_eac3 != !b_eac3 )
         return VLC_EGENERIC;
-    if( GetDWLE( p_peek + i_peek - i_len - 4 /* nSamplesPerSec */ ) !=
-        44100 )
-        return VLC_EGENERIC;
-
-    /* Skip the wave header */
-    while( memcmp( p_peek + i_peek - 8, "data", 4 ) )
-    {
-        uint32_t i_len = GetDWLE( p_peek + i_peek - 4 );
-        if( i_len > WAV_PROBE_SIZE || i_peek + i_len > WAV_PROBE_SIZE )
-            return VLC_EGENERIC;
-
-        i_peek += i_len + 8;
-        if( stream_Peek( p_demux->s, &p_peek, i_peek ) != i_peek )
-            return VLC_EGENERIC;
-    }
-    *pi_skip = i_peek;
-    return VLC_SUCCESS;
+    if( pi_samples )
+        *pi_samples = header.i_samples;
+    return header.i_size;
 }
-
-static int GenericProbe( demux_t *p_demux, int64_t *pi_offset,
-                         const char * ppsz_name[],
-                         bool (*pf_check)( const uint8_t * ), int i_check_size )
+static int EA52CheckSyncProbe( const uint8_t *p_peek, int *pi_samples )
 {
-    bool   b_forced_demux;
-
-    int64_t i_offset;
-    const uint8_t *p_peek;
-    int i_skip;
-
-    b_forced_demux = false;
-    for( int i = 0; ppsz_name[i] != NULL; i++ )
-    {
-        b_forced_demux |= demux_IsForced( p_demux, ppsz_name[i] );
-    }
-
-    i_offset = stream_Tell( p_demux->s );
-
-    if( WavSkipHeader( p_demux, &i_skip ) )
-    {
-        if( !b_forced_demux )
-            return VLC_EGENERIC;
-    }
-
-    /* peek the begining */
-    if( stream_Peek( p_demux->s, &p_peek, i_skip + i_check_size ) < i_skip + i_check_size )
-    {
-        msg_Err( p_demux, "cannot peek" );
-        return VLC_EGENERIC;
-    }
-    if( !pf_check( &p_peek[i_skip] ) )
-    {
-        if( !b_forced_demux )
-            return VLC_EGENERIC;
-    }
-
-    *pi_offset = i_offset + i_skip;
-    return VLC_SUCCESS;
+    bool b_dummy;
+    return A52CheckSync( p_peek, &b_dummy, pi_samples, true );
 }
 
-/*****************************************************************************
- * A52
- *****************************************************************************/
-static bool A52CheckSync( const uint8_t *p_peek, bool *p_big_endian )
+static int EA52Probe( demux_t *p_demux, int64_t *pi_offset )
 {
-    /* Little endian version of the bitstream */
-    if( p_peek[0] == 0x77 && p_peek[1] == 0x0b &&
-        p_peek[4] < 0x60 /* bsid < 12 */ )
-    {
-        *p_big_endian = false;
-        return true;
-    }
-    /* Big endian version of the bitstream */
-    else if( p_peek[0] == 0x0b && p_peek[1] == 0x77 &&
-             p_peek[5] < 0x60 /* bsid < 12 */ )
-    {
-        *p_big_endian = true;
-        return true;
-    }
+    const char *ppsz_name[] = { "eac3", NULL };
+    const int pi_wav[] = { WAVE_FORMAT_PCM, WAVE_FORMAT_A52, WAVE_FORMAT_UNKNOWN };
 
-    return false;
+    return GenericProbe( p_demux, pi_offset, ppsz_name, EA52CheckSyncProbe, VLC_A52_HEADER_SIZE, pi_wav );
 }
-static bool A52CheckSyncProbe( const uint8_t *p_peek )
+
+static int A52CheckSyncProbe( const uint8_t *p_peek, int *pi_samples )
 {
     bool b_dummy;
-    return A52CheckSync( p_peek, &b_dummy );
+    return A52CheckSync( p_peek, &b_dummy, pi_samples, false );
 }
 
 static int A52Probe( demux_t *p_demux, int64_t *pi_offset )
 {
     const char *ppsz_name[] = { "a52", "ac3", NULL };
+    const int pi_wav[] = { WAVE_FORMAT_PCM, WAVE_FORMAT_A52, WAVE_FORMAT_UNKNOWN };
 
-    return GenericProbe( p_demux, pi_offset, ppsz_name, A52CheckSyncProbe, 10 );
+    return GenericProbe( p_demux, pi_offset, ppsz_name, A52CheckSyncProbe, VLC_A52_HEADER_SIZE, pi_wav );
 }
 
 static int A52Init( demux_t *p_demux )
@@ -722,10 +852,10 @@ static int A52Init( demux_t *p_demux )
 
     const uint8_t *p_peek;
 
-    /* peek the begining (10 is for a52 header) */
-    if( stream_Peek( p_demux->s, &p_peek, 10 ) >= 10 )
+    /* peek the begining */
+    if( stream_Peek( p_demux->s, &p_peek, VLC_A52_HEADER_SIZE ) >= VLC_A52_HEADER_SIZE )
     {
-        A52CheckSync( p_peek, &p_sys->b_big_endian );
+        A52CheckSync( p_peek, &p_sys->b_big_endian, NULL, true );
     }
     return VLC_SUCCESS;
 }
@@ -733,43 +863,47 @@ static int A52Init( demux_t *p_demux )
 /*****************************************************************************
  * DTS
  *****************************************************************************/
-static bool DtsCheckSync( const uint8_t *p_peek )
+static int DtsCheckSync( const uint8_t *p_peek, int *pi_samples )
 {
+    /* TODO return frame size for robustness */
+
     /* 14 bits, little endian version of the bitstream */
     if( p_peek[0] == 0xff && p_peek[1] == 0x1f &&
         p_peek[2] == 0x00 && p_peek[3] == 0xe8 &&
         (p_peek[4] & 0xf0) == 0xf0 && p_peek[5] == 0x07 )
     {
-        return true;
+        return 0;
     }
     /* 14 bits, big endian version of the bitstream */
     else if( p_peek[0] == 0x1f && p_peek[1] == 0xff &&
              p_peek[2] == 0xe8 && p_peek[3] == 0x00 &&
              p_peek[4] == 0x07 && (p_peek[5] & 0xf0) == 0xf0)
     {
-        return true;
+        return 0;
     }
     /* 16 bits, big endian version of the bitstream */
     else if( p_peek[0] == 0x7f && p_peek[1] == 0xfe &&
              p_peek[2] == 0x80 && p_peek[3] == 0x01 )
     {
-        return true;
+        return 0;
     }
     /* 16 bits, little endian version of the bitstream */
     else if( p_peek[0] == 0xfe && p_peek[1] == 0x7f &&
              p_peek[2] == 0x01 && p_peek[3] == 0x80 )
     {
-        return true;
+        return 0;
     }
 
-    return false;
+    VLC_UNUSED(pi_samples);
+    return VLC_EGENERIC;
 }
 
 static int DtsProbe( demux_t *p_demux, int64_t *pi_offset )
 {
     const char *ppsz_name[] = { "dts", NULL };
+    const int pi_wav[] = { WAVE_FORMAT_PCM, WAVE_FORMAT_DTS, WAVE_FORMAT_UNKNOWN };
 
-    return GenericProbe( p_demux, pi_offset, ppsz_name, DtsCheckSync, 11 );
+    return GenericProbe( p_demux, pi_offset, ppsz_name, DtsCheckSync, 11, pi_wav );
 }
 static int DtsInit( demux_t *p_demux )
 {
@@ -780,3 +914,46 @@ static int DtsInit( demux_t *p_demux )
     return VLC_SUCCESS;
 }
 
+/*****************************************************************************
+ * MLP
+ *****************************************************************************/
+static int MlpCheckSync( const uint8_t *p_peek, int *pi_samples )
+{
+    if( p_peek[4+0] != 0xf8 || p_peek[4+1] != 0x72 || p_peek[4+2] != 0x6f )
+        return -1;
+
+    if( p_peek[4+3] != 0xba && p_peek[4+3] != 0xbb )
+        return -1;
+
+    /* TODO checksum and real size for robustness */
+    VLC_UNUSED(pi_samples);
+    return 0;
+}
+static int MlpProbe( demux_t *p_demux, int64_t *pi_offset )
+{
+    const char *ppsz_name[] = { "mlp", "thd", NULL };
+    const int pi_wav[] = { WAVE_FORMAT_PCM, WAVE_FORMAT_UNKNOWN };
+
+    return GenericProbe( p_demux, pi_offset, ppsz_name, MlpCheckSync, 4+28+16*4, pi_wav );
+}
+static int MlpInit( demux_t *p_demux )
+
+{
+    demux_sys_t *p_sys = p_demux->p_sys;
+
+    p_sys->i_packet_size = 4096;
+
+    return VLC_SUCCESS;
+}
+
+/*****************************************************************************
+ * Video
+ *****************************************************************************/
+static int VideoInit( demux_t *p_demux )
+{
+    demux_sys_t *p_sys = p_demux->p_sys;
+
+    p_sys->i_packet_size = 4096;
+
+    return VLC_SUCCESS;
+}