]> git.sesse.net Git - vlc/blobdiff - modules/demux/mkv.cpp
* include/configuration.h: some small re-work of the config declaration macros.
[vlc] / modules / demux / mkv.cpp
index 85b485aa89f1fc768f35d077f76d358612715035..72ea0cc7634f6a3f68467ad0e8868a3e84672bf0 100644 (file)
@@ -2,7 +2,7 @@
  * mkv.cpp : matroska demuxer
  *****************************************************************************
  * Copyright (C) 2001 VideoLAN
- * $Id: mkv.cpp,v 1.9 2003/06/24 18:42:50 fenrir Exp $
+ * $Id: mkv.cpp,v 1.37 2003/11/05 00:39:16 gbazin Exp $
  *
  * Authors: Laurent Aimar <fenrir@via.ecp.fr>
  *
 #include <vlc/input.h>
 
 #include <codecs.h>                        /* BITMAPINFOHEADER, WAVEFORMATEX */
+#include "iso_lang.h"
 
 #include <iostream>
 #include <cassert>
 #include <typeinfo>
-#include <wchar.h>
+
+#ifdef HAVE_WCHAR_H
+#   include <wchar.h>
+#endif
 
 /* libebml and matroska */
 #include "ebml/EbmlHead.h"
 #include "ebml/EbmlVoid.h"
 
 #include "matroska/FileKax.h"
+#ifdef HAVE_MATROSKA_KAXATTACHMENTS_H
+#include "matroska/KaxAttachments.h"
+#else
 #include "matroska/KaxAttachements.h"
+#endif
 #include "matroska/KaxBlock.h"
 #include "matroska/KaxBlockData.h"
 #include "matroska/KaxChapters.h"
 #include "matroska/KaxTracks.h"
 #include "matroska/KaxTrackAudio.h"
 #include "matroska/KaxTrackVideo.h"
+#include "matroska/KaxTrackEntryData.h"
 
 #include "ebml/StdIOCallback.h"
 
 using namespace LIBMATROSKA_NAMESPACE;
 using namespace std;
 
-
-/*****************************************************************************
- * Local prototypes
- *****************************************************************************/
-static int  Activate  ( vlc_object_t * );
-static void Deactivate( vlc_object_t * );
-static int  Demux     ( input_thread_t * );
-
 /*****************************************************************************
  * Module descriptor
  *****************************************************************************/
+static int  Open ( vlc_object_t * );
+static void Close( vlc_object_t * );
+
 vlc_module_begin();
-#if 0
     add_category_hint( N_("mkv-demuxer"), NULL, VLC_TRUE );
-        add_bool( "mkv-index", 0, NULL,
-                  N_("Create index if no cues found"),
-                  N_("Create index if no cues found"), VLC_TRUE );
-#endif
+        add_bool( "mkv-seek-percent", 1, NULL,
+                  N_("Seek based on percent not time"),
+                  N_("Seek based on percent not time"), VLC_TRUE );
+
     set_description( _("mka/mkv stream demuxer" ) );
     set_capability( "demux", 50 );
-    set_callbacks( Activate, Deactivate );
+    set_callbacks( Open, Close );
     add_shortcut( "mka" );
     add_shortcut( "mkv" );
 vlc_module_end();
 
+/*****************************************************************************
+ * Local prototypes
+ *****************************************************************************/
+static int  Demux   ( input_thread_t * );
+static void Seek    ( input_thread_t *, mtime_t i_date, int i_percent );
+
 
 /*****************************************************************************
  * Stream managment
@@ -107,11 +116,11 @@ vlc_module_end();
 class vlc_stream_io_callback: public IOCallback
 {
   private:
-    input_thread_t *p_input;
+    stream_t       *s;
     vlc_bool_t     mb_eof;
 
   public:
-    vlc_stream_io_callback( input_thread_t * );
+    vlc_stream_io_callback( stream_t * );
 
     virtual uint32_t read            ( void *p_buffer, size_t i_size);
     virtual void     setFilePointer  ( int64_t i_offset, seek_mode mode = seek_beginning );
@@ -151,18 +160,7 @@ class EbmlParser
 /*****************************************************************************
  * Some functions to manipulate memory
  *****************************************************************************/
-#define GetWLE( p )     __GetWLE( (uint8_t*)p )
-#define GetDWLE( p )    __GetDWLE( (uint8_t*)p )
 #define GetFOURCC( p )  __GetFOURCC( (uint8_t*)p )
-static uint16_t __GetWLE( uint8_t *p )
-{
-    return (uint16_t)p[0] | ( ((uint16_t)p[1]) << 8 );
-}
-static uint32_t __GetDWLE( uint8_t *p )
-{
-    return (uint32_t)p[0] | ( ((uint32_t)p[1]) << 8 ) |
-            ( ((uint32_t)p[2]) << 16 ) | ( ((uint32_t)p[3]) << 24 );
-}
 static vlc_fourcc_t __GetFOURCC( uint8_t *p )
 {
     return VLC_FOURCC( p[0], p[1], p[2], p[3] );
@@ -175,6 +173,7 @@ typedef struct
 {
     int         i_cat;
     vlc_bool_t  b_default;
+    vlc_bool_t  b_enabled;
     int         i_number;
 
     int         i_extra_data;
@@ -186,6 +185,7 @@ typedef struct
     vlc_fourcc_t i_codec;
 
     uint64_t     i_default_duration;
+    float        f_timecodescale;
     /* video */
     int         i_width;
     int         i_height;
@@ -210,6 +210,14 @@ typedef struct
 
     /* hack : it's for seek */
     vlc_bool_t      b_search_keyframe;
+
+    /* informative */
+    char         *psz_name;
+    char         *psz_codec_name;
+    char         *psz_codec_settings;
+    char         *psz_codec_info_url;
+    char         *psz_codec_download_url;
+
 } mkv_track_t;
 
 typedef struct
@@ -270,10 +278,12 @@ static char *UTF8ToStr          ( const UTFstring &u );
 static void LoadCues            ( input_thread_t *);
 static void InformationsCreate  ( input_thread_t *p_input );
 
+static char *LanguageGetName    ( const char *psz_code );
+
 /*****************************************************************************
- * Activate: initializes matroska demux structures
+ * Open: initializes matroska demux structures
  *****************************************************************************/
-static int Activate( vlc_object_t * p_this )
+static int Open( vlc_object_t * p_this )
 {
     input_thread_t *p_input = (input_thread_t *)p_this;
     demux_sys_t    *p_sys;
@@ -285,16 +295,9 @@ static int Activate( vlc_object_t * p_this )
 
     EbmlElement     *el = NULL, *el1 = NULL, *el2 = NULL, *el3 = NULL, *el4 = NULL;
 
-
-    /* Initialize access plug-in structures. */
-    if( p_input->i_mtu == 0 )
-    {
-        /* Improve speed. */
-        p_input->i_bufsize = INPUT_DEFAULT_BUFSIZE;
-    }
-
     /* Set the demux function */
     p_input->pf_demux = Demux;
+    p_input->pf_demux_control = demux_vaControlDefault;
 
     /* peek the begining */
     if( input_Peek( p_input, &p_peek, 4 ) < 4 )
@@ -304,16 +307,19 @@ static int Activate( vlc_object_t * p_this )
     }
 
     /* is a valid file */
-    if( p_peek[0] != 0x1a || p_peek[1] != 0x45 || p_peek[2] != 0xdf || p_peek[3] != 0xa3 )
+    if( p_peek[0] != 0x1a || p_peek[1] != 0x45 ||
+        p_peek[2] != 0xdf || p_peek[3] != 0xa3 )
     {
-        msg_Warn( p_input, "matroska module discarded (invalid header)" );
+        msg_Warn( p_input, "matroska module discarded "
+                           "(invalid header 0x%.2x%.2x%.2x%.2x)",
+                           p_peek[0], p_peek[1], p_peek[2], p_peek[3] );
         return VLC_EGENERIC;
     }
 
-    p_input->p_demux_data = p_sys = (demux_sys_t*)malloc( sizeof( demux_sys_t ) );
+    p_input->p_demux_data = p_sys = (demux_sys_t*)malloc(sizeof( demux_sys_t ));
     memset( p_sys, 0, sizeof( demux_sys_t ) );
 
-    p_sys->in = new vlc_stream_io_callback( p_input );
+    p_sys->in = new vlc_stream_io_callback( p_input->s );
     p_sys->es = new EbmlStream( *p_sys->in );
     p_sys->f_duration   = -1;
     p_sys->i_timescale     = MKVD_TIMECODESCALE;
@@ -327,7 +333,8 @@ static int Activate( vlc_object_t * p_this )
     p_sys->b_cues       = VLC_FALSE;
     p_sys->i_index      = 0;
     p_sys->i_index_max  = 1024;
-    p_sys->index        = (mkv_index_t*)malloc( sizeof( mkv_index_t ) * p_sys->i_index_max );
+    p_sys->index        = (mkv_index_t*)malloc( sizeof( mkv_index_t ) *
+                                                p_sys->i_index_max );
 
     p_sys->psz_muxing_application = NULL;
     p_sys->psz_writing_application = NULL;
@@ -383,7 +390,8 @@ static int Activate( vlc_object_t * p_this )
                     tcs.ReadData( p_sys->es->I_O() );
                     p_sys->i_timescale = uint64(tcs);
 
-                    msg_Dbg( p_input, "|   |   + TimecodeScale=%lld", p_sys->i_timescale );
+                    msg_Dbg( p_input, "|   |   + TimecodeScale="I64Fd,
+                             p_sys->i_timescale );
                 }
                 else if( EbmlId( *el2 ) == KaxDuration::ClassInfos.GlobalId )
                 {
@@ -392,7 +400,8 @@ static int Activate( vlc_object_t * p_this )
                     dur.ReadData( p_sys->es->I_O() );
                     p_sys->f_duration = float(dur);
 
-                    msg_Dbg( p_input, "|   |   + Duration=%f", p_sys->f_duration );
+                    msg_Dbg( p_input, "|   |   + Duration=%f",
+                             p_sys->f_duration );
                 }
                 else if( EbmlId( *el2 ) == KaxMuxingApp::ClassInfos.GlobalId )
                 {
@@ -402,7 +411,8 @@ static int Activate( vlc_object_t * p_this )
 
                     p_sys->psz_muxing_application = UTF8ToStr( UTFstring( mapp ) );
 
-                    msg_Dbg( p_input, "|   |   + Muxing Application=%s", p_sys->psz_muxing_application );
+                    msg_Dbg( p_input, "|   |   + Muxing Application=%s",
+                             p_sys->psz_muxing_application );
                 }
                 else if( EbmlId( *el2 ) == KaxWritingApp::ClassInfos.GlobalId )
                 {
@@ -412,7 +422,8 @@ static int Activate( vlc_object_t * p_this )
 
                     p_sys->psz_writing_application = UTF8ToStr( UTFstring( wapp ) );
 
-                    msg_Dbg( p_input, "|   |   + Wrinting Application=%s", p_sys->psz_writing_application );
+                    msg_Dbg( p_input, "|   |   + Wrinting Application=%s",
+                             p_sys->psz_writing_application );
                 }
                 else if( EbmlId( *el2 ) == KaxSegmentFilename::ClassInfos.GlobalId )
                 {
@@ -422,7 +433,8 @@ static int Activate( vlc_object_t * p_this )
 
                     p_sys->psz_segment_filename = UTF8ToStr( UTFstring( sfn ) );
 
-                    msg_Dbg( p_input, "|   |   + Segment Filename=%s", p_sys->psz_segment_filename );
+                    msg_Dbg( p_input, "|   |   + Segment Filename=%s",
+                             p_sys->psz_segment_filename );
                 }
                 else if( EbmlId( *el2 ) == KaxTitle::ClassInfos.GlobalId )
                 {
@@ -434,7 +446,7 @@ static int Activate( vlc_object_t * p_this )
 
                     msg_Dbg( p_input, "|   |   + Title=%s", p_sys->psz_title );
                 }
-#ifdef HAVE_TIME_H
+#ifdef HAVE_GMTIME_R
                 else if( EbmlId( *el2 ) == KaxDateUTC::ClassInfos.GlobalId )
                 {
                     KaxDateUTC &date = *(KaxDateUTC*)el2;
@@ -457,7 +469,7 @@ static int Activate( vlc_object_t * p_this )
 #endif
                 else
                 {
-                    msg_Dbg( p_input, "|   |   + Unknow (%s)", typeid(*el2).name() );
+                    msg_Dbg( p_input, "|   |   + Unknown (%s)", typeid(*el2).name() );
                 }
             }
             p_sys->ep->Up();
@@ -478,19 +490,27 @@ static int Activate( vlc_object_t * p_this )
 #define tk  p_sys->track[p_sys->i_track - 1]
                     memset( &tk, 0, sizeof( mkv_track_t ) );
                     tk.i_cat = UNKNOWN_ES;
-                    tk.b_default = VLC_FALSE;
+                    tk.b_default = VLC_TRUE;
+                    tk.b_enabled = VLC_TRUE;
                     tk.i_number = p_sys->i_track - 1;
                     tk.i_extra_data = 0;
                     tk.p_extra_data = NULL;
                     tk.i_codec = 0;
                     tk.psz_codec = NULL;
-                    tk.psz_language = NULL;
+                    tk.psz_language = strdup("English");
                     tk.i_default_duration = 0;
+                    tk.f_timecodescale = 1.0;
 
                     tk.b_inited = VLC_FALSE;
                     tk.i_data_init = 0;
                     tk.p_data_init = NULL;
 
+                    tk.psz_name = NULL;
+                    tk.psz_codec_name = NULL;
+                    tk.psz_codec_settings = NULL;
+                    tk.psz_codec_info_url = NULL;
+                    tk.psz_codec_download_url = NULL;
+
                     p_sys->ep->Down();
 
                     while( ( el3 = p_sys->ep->Get() ) != NULL )
@@ -501,22 +521,16 @@ static int Activate( vlc_object_t * p_this )
                             tnum.ReadData( p_sys->es->I_O() );
 
                             tk.i_number = uint32( tnum );
-                            msg_Dbg( p_input, "|   |   |   + Track Number=%u", uint32( tnum ) );
+                            msg_Dbg( p_input, "|   |   |   + Track Number=%u",
+                                     uint32( tnum ) );
                         }
                         else  if( EbmlId( *el3 ) == KaxTrackUID::ClassInfos.GlobalId )
                         {
                             KaxTrackUID &tuid = *(KaxTrackUID*)el3;
                             tuid.ReadData( p_sys->es->I_O() );
 
-                            msg_Dbg( p_input, "|   |   |   + Track UID=%u", uint32( tuid ) );
-                        }
-                        else  if( EbmlId( *el3 ) == KaxTrackDefaultDuration::ClassInfos.GlobalId )
-                        {
-                            KaxTrackDefaultDuration &defd = *(KaxTrackDefaultDuration*)el3;
-                            defd.ReadData( p_sys->es->I_O() );
-
-                            tk.i_default_duration = uint64(defd);
-                            msg_Dbg( p_input, "|   |   |   + Track Default Duration=%lld", uint64(defd) );
+                            msg_Dbg( p_input, "|   |   |   + Track UID=%u",
+                                     uint32( tuid ) );
                         }
                         else  if( EbmlId( *el3 ) == KaxTrackType::ClassInfos.GlobalId )
                         {
@@ -543,49 +557,154 @@ static int Activate( vlc_object_t * p_this )
                                     break;
                             }
 
-                            msg_Dbg( p_input, "|   |   |   + Track Type=%s", psz_type );
+                            msg_Dbg( p_input, "|   |   |   + Track Type=%s",
+                                     psz_type );
                         }
-                        else  if( EbmlId( *el3 ) == KaxTrackAudio::ClassInfos.GlobalId )
+                        else  if( EbmlId( *el3 ) == KaxTrackFlagEnabled::ClassInfos.GlobalId )
                         {
-                            msg_Dbg( p_input, "|   |   |   + Track Audio" );
-                            tk.i_channels = 0;
-                            tk.i_samplerate = 0;
-                            tk.i_bitspersample = 0;
+                            KaxTrackFlagEnabled &fenb = *(KaxTrackFlagEnabled*)el3;
+                            fenb.ReadData( p_sys->es->I_O() );
 
-                            p_sys->ep->Down();
+                            tk.b_enabled = uint32( fenb );
+                            msg_Dbg( p_input, "|   |   |   + Track Enabled=%u",
+                                     uint32( fenb )  );
+                        }
+                        else  if( EbmlId( *el3 ) == KaxTrackFlagDefault::ClassInfos.GlobalId )
+                        {
+                            KaxTrackFlagDefault &fdef = *(KaxTrackFlagDefault*)el3;
+                            fdef.ReadData( p_sys->es->I_O() );
 
-                            while( ( el4 = p_sys->ep->Get() ) != NULL )
-                            {
-                                if( EbmlId( *el4 ) == KaxAudioSamplingFreq::ClassInfos.GlobalId )
-                                {
-                                    KaxAudioSamplingFreq &afreq = *(KaxAudioSamplingFreq*)el4;
-                                    afreq.ReadData( p_sys->es->I_O() );
+                            tk.b_default = uint32( fdef );
+                            msg_Dbg( p_input, "|   |   |   + Track Default=%u",
+                                     uint32( fdef )  );
+                        }
+                        else  if( EbmlId( *el3 ) == KaxTrackFlagLacing::ClassInfos.GlobalId )
+                        {
+                            KaxTrackFlagLacing &lac = *(KaxTrackFlagLacing*)el3;
+                            lac.ReadData( p_sys->es->I_O() );
 
-                                    tk.i_samplerate = (int)float( afreq );
-                                    msg_Dbg( p_input, "|   |   |   |   + afreq=%d", tk.i_samplerate );
-                                }
-                                else if( EbmlId( *el4 ) == KaxAudioChannels::ClassInfos.GlobalId )
-                                {
-                                    KaxAudioChannels &achan = *(KaxAudioChannels*)el4;
-                                    achan.ReadData( p_sys->es->I_O() );
+                            msg_Dbg( p_input, "|   |   |   + Track Lacing=%d",
+                                     uint32( lac ) );
+                        }
+                        else  if( EbmlId( *el3 ) == KaxTrackMinCache::ClassInfos.GlobalId )
+                        {
+                            KaxTrackMinCache &cmin = *(KaxTrackMinCache*)el3;
+                            cmin.ReadData( p_sys->es->I_O() );
 
-                                    tk.i_channels = uint8( achan );
-                                    msg_Dbg( p_input, "|   |   |   |   + achan=%u", uint8( achan ) );
-                                }
-                                else if( EbmlId( *el4 ) == KaxAudioBitDepth::ClassInfos.GlobalId )
-                                {
-                                    KaxAudioBitDepth &abits = *(KaxAudioBitDepth*)el4;
-                                    abits.ReadData( p_sys->es->I_O() );
+                            msg_Dbg( p_input, "|   |   |   + Track MinCache=%d",
+                                     uint32( cmin ) );
+                        }
+                        else  if( EbmlId( *el3 ) == KaxTrackMaxCache::ClassInfos.GlobalId )
+                        {
+                            KaxTrackMaxCache &cmax = *(KaxTrackMaxCache*)el3;
+                            cmax.ReadData( p_sys->es->I_O() );
 
-                                    tk.i_bitspersample = uint8( abits );
-                                    msg_Dbg( p_input, "|   |   |   |   + abits=%u", uint8( abits ) );
-                                }
-                                else
-                                {
-                                    msg_Dbg( p_input, "|   |   |   |   + Unknow (%s)", typeid(*el4).name() );
-                                }
+                            msg_Dbg( p_input, "|   |   |   + Track MaxCache=%d",
+                                     uint32( cmax ) );
+                        }
+                        else  if( EbmlId( *el3 ) == KaxTrackDefaultDuration::ClassInfos.GlobalId )
+                        {
+                            KaxTrackDefaultDuration &defd = *(KaxTrackDefaultDuration*)el3;
+                            defd.ReadData( p_sys->es->I_O() );
+
+                            tk.i_default_duration = uint64(defd);
+                            msg_Dbg( p_input, "|   |   |   + Track Default Duration="I64Fd, uint64(defd) );
+                        }
+                        else  if( EbmlId( *el3 ) == KaxTrackTimecodeScale::ClassInfos.GlobalId )
+                        {
+                            KaxTrackTimecodeScale &ttcs = *(KaxTrackTimecodeScale*)el3;
+                            ttcs.ReadData( p_sys->es->I_O() );
+
+                            tk.f_timecodescale = float( ttcs );
+                            msg_Dbg( p_input, "|   |   |   + Track TimeCodeScale=%f", tk.f_timecodescale );
+                        }
+                        else if( EbmlId( *el3 ) == KaxTrackName::ClassInfos.GlobalId )
+                        {
+                            KaxTrackName &tname = *(KaxTrackName*)el3;
+                            tname.ReadData( p_sys->es->I_O() );
+
+                            tk.psz_name = UTF8ToStr( UTFstring( tname ) );
+                            msg_Dbg( p_input, "|   |   |   + Track Name=%s",
+                                     tk.psz_name );
+                        }
+                        else  if( EbmlId( *el3 ) == KaxTrackLanguage::ClassInfos.GlobalId )
+                        {
+                            KaxTrackLanguage &lang = *(KaxTrackLanguage*)el3;
+                            lang.ReadData( p_sys->es->I_O() );
+
+                            tk.psz_language =
+                                LanguageGetName( string( lang ).c_str() );
+                            msg_Dbg( p_input,
+                                     "|   |   |   + Track Language=`%s'(%s) ",
+                                     tk.psz_language, string( lang ).c_str() );
+                        }
+                        else  if( EbmlId( *el3 ) == KaxCodecID::ClassInfos.GlobalId )
+                        {
+                            KaxCodecID &codecid = *(KaxCodecID*)el3;
+                            codecid.ReadData( p_sys->es->I_O() );
+
+                            tk.psz_codec = strdup( string( codecid ).c_str() );
+                            msg_Dbg( p_input, "|   |   |   + Track CodecId=%s",
+                                     string( codecid ).c_str() );
+                        }
+                        else  if( EbmlId( *el3 ) == KaxCodecPrivate::ClassInfos.GlobalId )
+                        {
+                            KaxCodecPrivate &cpriv = *(KaxCodecPrivate*)el3;
+                            cpriv.ReadData( p_sys->es->I_O() );
+
+                            tk.i_extra_data = cpriv.GetSize();
+                            if( tk.i_extra_data > 0 )
+                            {
+                                tk.p_extra_data = (uint8_t*)malloc( tk.i_extra_data );
+                                memcpy( tk.p_extra_data, cpriv.GetBuffer(), tk.i_extra_data );
                             }
-                            p_sys->ep->Up();
+                            msg_Dbg( p_input, "|   |   |   + Track CodecPrivate size="I64Fd, cpriv.GetSize() );
+                        }
+                        else if( EbmlId( *el3 ) == KaxCodecName::ClassInfos.GlobalId )
+                        {
+                            KaxCodecName &cname = *(KaxCodecName*)el3;
+                            cname.ReadData( p_sys->es->I_O() );
+
+                            tk.psz_codec_name = UTF8ToStr( UTFstring( cname ) );
+                            msg_Dbg( p_input, "|   |   |   + Track Codec Name=%s", tk.psz_codec_name );
+                        }
+                        else if( EbmlId( *el3 ) == KaxCodecSettings::ClassInfos.GlobalId )
+                        {
+                            KaxCodecSettings &cset = *(KaxCodecSettings*)el3;
+                            cset.ReadData( p_sys->es->I_O() );
+
+                            tk.psz_codec_settings = UTF8ToStr( UTFstring( cset ) );
+                            msg_Dbg( p_input, "|   |   |   + Track Codec Settings=%s", tk.psz_codec_settings );
+                        }
+                        else if( EbmlId( *el3 ) == KaxCodecInfoURL::ClassInfos.GlobalId )
+                        {
+                            KaxCodecInfoURL &ciurl = *(KaxCodecInfoURL*)el3;
+                            ciurl.ReadData( p_sys->es->I_O() );
+
+                            tk.psz_codec_info_url = strdup( string( ciurl ).c_str() );
+                            msg_Dbg( p_input, "|   |   |   + Track Codec Info URL=%s", tk.psz_codec_info_url );
+                        }
+                        else if( EbmlId( *el3 ) == KaxCodecDownloadURL::ClassInfos.GlobalId )
+                        {
+                            KaxCodecDownloadURL &cdurl = *(KaxCodecDownloadURL*)el3;
+                            cdurl.ReadData( p_sys->es->I_O() );
+
+                            tk.psz_codec_download_url = strdup( string( cdurl ).c_str() );
+                            msg_Dbg( p_input, "|   |   |   + Track Codec Info URL=%s", tk.psz_codec_download_url );
+                        }
+                        else if( EbmlId( *el3 ) == KaxCodecDecodeAll::ClassInfos.GlobalId )
+                        {
+                            KaxCodecDecodeAll &cdall = *(KaxCodecDecodeAll*)el3;
+                            cdall.ReadData( p_sys->es->I_O() );
+
+                            msg_Dbg( p_input, "|   |   |   + Track Codec Decode All=%u <== UNUSED", uint8( cdall ) );
+                        }
+                        else if( EbmlId( *el3 ) == KaxTrackOverlay::ClassInfos.GlobalId )
+                        {
+                            KaxTrackOverlay &tovr = *(KaxTrackOverlay*)el3;
+                            tovr.ReadData( p_sys->es->I_O() );
+
+                            msg_Dbg( p_input, "|   |   |   + Track Overlay=%u <== UNUSED", uint32( tovr ) );
                         }
                         else  if( EbmlId( *el3 ) == KaxTrackVideo::ClassInfos.GlobalId )
                         {
@@ -600,7 +719,21 @@ static int Activate( vlc_object_t * p_this )
 
                             while( ( el4 = p_sys->ep->Get() ) != NULL )
                             {
-                                if( EbmlId( *el4 ) == KaxVideoPixelWidth::ClassInfos.GlobalId )
+                                if( EbmlId( *el4 ) == KaxVideoFlagInterlaced::ClassInfos.GlobalId )
+                                {
+                                    KaxVideoFlagInterlaced &fint = *(KaxVideoFlagInterlaced*)el4;
+                                    fint.ReadData( p_sys->es->I_O() );
+
+                                    msg_Dbg( p_input, "|   |   |   |   + Track Video Interlaced=%u", uint8( fint ) );
+                                }
+                                else if( EbmlId( *el4 ) == KaxVideoStereoMode::ClassInfos.GlobalId )
+                                {
+                                    KaxVideoStereoMode &stereo = *(KaxVideoStereoMode*)el4;
+                                    stereo.ReadData( p_sys->es->I_O() );
+
+                                    msg_Dbg( p_input, "|   |   |   |   + Track Video Stereo Mode=%u", uint8( stereo ) );
+                                }
+                                else if( EbmlId( *el4 ) == KaxVideoPixelWidth::ClassInfos.GlobalId )
                                 {
                                     KaxVideoPixelWidth &vwidth = *(KaxVideoPixelWidth*)el4;
                                     vwidth.ReadData( p_sys->es->I_O() );
@@ -640,82 +773,89 @@ static int Activate( vlc_object_t * p_this )
                                     tk.f_fps = float( vfps );
                                     msg_Dbg( p_input, "   |   |   |   + fps=%f", float( vfps ) );
                                 }
+                                else if( EbmlId( *el4 ) == KaxVideoDisplayUnit::ClassInfos.GlobalId )
+                                {
+                                     KaxVideoDisplayUnit &vdmode = *(KaxVideoDisplayUnit*)el4;
+                                    vdmode.ReadData( p_sys->es->I_O() );
+
+                                    msg_Dbg( p_input, "|   |   |   |   + Track Video Display Unit=%s",
+                                             uint8( vdmode ) == 0 ? "pixels" : ( uint8( vdmode ) == 1 ? "centimeters": "inches" ) );
+                                }
+                                else if( EbmlId( *el4 ) == KaxVideoAspectRatio::ClassInfos.GlobalId )
+                                {
+                                    KaxVideoAspectRatio &ratio = *(KaxVideoAspectRatio*)el4;
+                                    ratio.ReadData( p_sys->es->I_O() );
+
+                                    msg_Dbg( p_input, "   |   |   |   + Track Video Aspect Ratio Type=%u", uint8( ratio ) );
+                                }
+                                else if( EbmlId( *el4 ) == KaxVideoGamma::ClassInfos.GlobalId )
+                                {
+                                    KaxVideoGamma &gamma = *(KaxVideoGamma*)el4;
+                                    gamma.ReadData( p_sys->es->I_O() );
+
+                                    msg_Dbg( p_input, "   |   |   |   + fps=%f", float( gamma ) );
+                                }
                                 else
                                 {
-                                    msg_Dbg( p_input, "|   |   |   |   + Unknow (%s)", typeid(*el4).name() );
+                                    msg_Dbg( p_input, "|   |   |   |   + Unknown (%s)", typeid(*el4).name() );
                                 }
                             }
                             p_sys->ep->Up();
                         }
-                        else  if( EbmlId( *el3 ) == KaxCodecID::ClassInfos.GlobalId )
+                        else  if( EbmlId( *el3 ) == KaxTrackAudio::ClassInfos.GlobalId )
                         {
-                            KaxCodecID &codecid = *(KaxCodecID*)el3;
-                            codecid.ReadData( p_sys->es->I_O() );
+                            msg_Dbg( p_input, "|   |   |   + Track Audio" );
+                            tk.i_channels = 0;
+                            tk.i_samplerate = 0;
+                            tk.i_bitspersample = 0;
 
-                            tk.psz_codec = strdup( string( codecid ).c_str() );
-                            msg_Dbg( p_input, "|   |   |   + Track CodecId=%s", string( codecid ).c_str() );
-                        }
-                        else  if( EbmlId( *el3 ) == KaxCodecPrivate::ClassInfos.GlobalId )
-                        {
-                            KaxCodecPrivate &cpriv = *(KaxCodecPrivate*)el3;
-                            cpriv.ReadData( p_sys->es->I_O() );
+                            p_sys->ep->Down();
 
-                            tk.i_extra_data = cpriv.GetSize();
-                            if( tk.i_extra_data > 0 )
+                            while( ( el4 = p_sys->ep->Get() ) != NULL )
                             {
-                                tk.p_extra_data = (uint8_t*)malloc( tk.i_extra_data );
-                                memcpy( tk.p_extra_data, cpriv.GetBuffer(), tk.i_extra_data );
-                            }
-                            msg_Dbg( p_input, "|   |   |   + Track CodecPrivate size=%lld", cpriv.GetSize() );
-                        }
-                        else  if( EbmlId( *el3 ) == KaxTrackFlagDefault::ClassInfos.GlobalId )
-                        {
-                            KaxTrackFlagDefault &fdef = *(KaxTrackFlagDefault*)el3;
-                            fdef.ReadData( p_sys->es->I_O() );
-
-                            tk.b_default = uint32( fdef );
-                            msg_Dbg( p_input, "|   |   |   + Track Default=%u", uint32( fdef )  );
-                        }
-                        else  if( EbmlId( *el3 ) == KaxTrackLanguage::ClassInfos.GlobalId )
-                        {
-                            KaxTrackLanguage &lang = *(KaxTrackLanguage*)el3;
-
-                            lang.ReadData( p_sys->es->I_O() );
-
-                            tk.psz_language = strdup( string( lang ).c_str() );
-                            msg_Dbg( p_input, "|   |   |   + Track Language=`%s'", string( lang ).c_str() );
-                        }
-                        else  if( EbmlId( *el3 ) == KaxTrackFlagLacing::ClassInfos.GlobalId )
-                        {
-                            KaxTrackFlagLacing &lac = *(KaxTrackFlagLacing*)el3;
-                            lac.ReadData( p_sys->es->I_O() );
+                                if( EbmlId( *el4 ) == KaxAudioSamplingFreq::ClassInfos.GlobalId )
+                                {
+                                    KaxAudioSamplingFreq &afreq = *(KaxAudioSamplingFreq*)el4;
+                                    afreq.ReadData( p_sys->es->I_O() );
 
-                            msg_Dbg( p_input, "|   |   |   + Track Lacing=%d", uint32( lac ) );
-                        }
-                        else  if( EbmlId( *el3 ) == KaxTrackMinCache::ClassInfos.GlobalId )
-                        {
-                            KaxTrackMinCache &cmin = *(KaxTrackMinCache*)el3;
-                            cmin.ReadData( p_sys->es->I_O() );
+                                    tk.i_samplerate = (int)float( afreq );
+                                    msg_Dbg( p_input, "|   |   |   |   + afreq=%d", tk.i_samplerate );
+                                }
+                                else if( EbmlId( *el4 ) == KaxAudioChannels::ClassInfos.GlobalId )
+                                {
+                                    KaxAudioChannels &achan = *(KaxAudioChannels*)el4;
+                                    achan.ReadData( p_sys->es->I_O() );
 
-                            msg_Dbg( p_input, "|   |   |   + Track MinCache=%d", uint32( cmin ) );
-                        }
-                        else  if( EbmlId( *el3 ) == KaxTrackMaxCache::ClassInfos.GlobalId )
-                        {
-                            KaxTrackMaxCache &cmax = *(KaxTrackMaxCache*)el3;
-                            cmax.ReadData( p_sys->es->I_O() );
+                                    tk.i_channels = uint8( achan );
+                                    msg_Dbg( p_input, "|   |   |   |   + achan=%u", uint8( achan ) );
+                                }
+                                else if( EbmlId( *el4 ) == KaxAudioBitDepth::ClassInfos.GlobalId )
+                                {
+                                    KaxAudioBitDepth &abits = *(KaxAudioBitDepth*)el4;
+                                    abits.ReadData( p_sys->es->I_O() );
 
-                            msg_Dbg( p_input, "|   |   |   + Track MaxCache=%d", uint32( cmax ) );
+                                    tk.i_bitspersample = uint8( abits );
+                                    msg_Dbg( p_input, "|   |   |   |   + abits=%u", uint8( abits ) );
+                                }
+                                else
+                                {
+                                    msg_Dbg( p_input, "|   |   |   |   + Unknown (%s)", typeid(*el4).name() );
+                                }
+                            }
+                            p_sys->ep->Up();
                         }
                         else
                         {
-                            msg_Dbg( p_input, "|   |   |   + Unknow (%s)", typeid(*el3).name() );
+                            msg_Dbg( p_input, "|   |   |   + Unknown (%s)",
+                                     typeid(*el3).name() );
                         }
                     }
                     p_sys->ep->Up();
                 }
                 else
                 {
-                    msg_Dbg( p_input, "|   |   + Unknow (%s)", typeid(*el2).name() );
+                    msg_Dbg( p_input, "|   |   + Unknown (%s)",
+                             typeid(*el2).name() );
                 }
 #undef tk
             }
@@ -754,7 +894,8 @@ static int Activate( vlc_object_t * p_this )
                         }
                         else
                         {
-                            msg_Dbg( p_input, "|   |   |   + Unknow (%s)", typeid(*el).name() );
+                            msg_Dbg( p_input, "|   |   |   + Unknown (%s)",
+                                     typeid(*el).name() );
                         }
                     }
                     p_sys->ep->Up();
@@ -763,17 +904,20 @@ static int Activate( vlc_object_t * p_this )
                     {
                         if( id == KaxCues::ClassInfos.GlobalId )
                         {
-                            msg_Dbg( p_input, "|   |   |   = cues at %lld", i_pos );
+                            msg_Dbg( p_input, "|   |   |   = cues at "I64Fd,
+                                     i_pos );
                             p_sys->i_cues_position = p_sys->segment->GetGlobalPosition( i_pos );
                         }
                         else if( id == KaxChapters::ClassInfos.GlobalId )
                         {
-                            msg_Dbg( p_input, "|   |   |   = chapters at %lld", i_pos );
+                            msg_Dbg( p_input, "|   |   |   = chapters at "I64Fd,
+                                     i_pos );
                             p_sys->i_chapters_position = p_sys->segment->GetGlobalPosition( i_pos );
                         }
                         else if( id == KaxTags::ClassInfos.GlobalId )
                         {
-                            msg_Dbg( p_input, "|   |   |   = tags at %lld", i_pos );
+                            msg_Dbg( p_input, "|   |   |   = tags at "I64Fd,
+                                     i_pos );
                             p_sys->i_tags_position = p_sys->segment->GetGlobalPosition( i_pos );
                         }
 
@@ -781,7 +925,8 @@ static int Activate( vlc_object_t * p_this )
                 }
                 else
                 {
-                    msg_Dbg( p_input, "|   |   + Unknow (%s)", typeid(*el).name() );
+                    msg_Dbg( p_input, "|   |   + Unknown (%s)",
+                             typeid(*el).name() );
                 }
             }
             p_sys->ep->Up();
@@ -800,9 +945,13 @@ static int Activate( vlc_object_t * p_this )
             /* stop parsing the stream */
             break;
         }
+#ifdef HAVE_MATROSKA_KAXATTACHMENTS_H
+        else if( EbmlId( *el1 ) == KaxAttachments::ClassInfos.GlobalId )
+#else
         else if( EbmlId( *el1 ) == KaxAttachements::ClassInfos.GlobalId )
+#endif
         {
-            msg_Dbg( p_input, "|   + Attachements FIXME TODO (but probably never supported)" );
+            msg_Dbg( p_input, "|   + Attachments FIXME TODO (but probably never supported)" );
         }
         else if( EbmlId( *el1 ) == KaxChapters::ClassInfos.GlobalId )
         {
@@ -814,7 +963,7 @@ static int Activate( vlc_object_t * p_this )
         }
         else
         {
-            msg_Dbg( p_input, "|   + Unknow (%s)", typeid(*el1).name() );
+            msg_Dbg( p_input, "|   + Unknown (%s)", typeid(*el1).name() );
         }
     }
 
@@ -830,14 +979,20 @@ static int Activate( vlc_object_t * p_this )
     }
 
     /* *** Load the cue if found *** */
-    if( p_sys->i_cues_position >= 0 && p_input->stream.b_seekable )
+    if( p_sys->i_cues_position >= 0 )
     {
-        LoadCues( p_input );
+        vlc_bool_t b_seekable;
+
+        stream_Control( p_input->s, STREAM_CAN_FASTSEEK, &b_seekable );
+        if( b_seekable )
+        {
+            LoadCues( p_input );
+        }
     }
 
     if( !p_sys->b_cues || p_sys->i_index <= 0 )
     {
-        msg_Warn( p_input, "no cues/empty cues found -> seek won't be precise" );
+        msg_Warn( p_input, "no cues/empty cues found->seek won't be precise" );
 
         IndexAppendCluster( p_input, p_sys->cluster );
 
@@ -859,16 +1014,14 @@ static int Activate( vlc_object_t * p_this )
         goto error;
     }
     p_input->stream.p_selected_program = p_input->stream.pp_programs[0];
+    p_input->stream.i_mux_rate = 0;
+    vlc_mutex_unlock( &p_input->stream.stream_lock );
+
     if( p_sys->f_duration > 1001.0 )
     {
         mtime_t i_duration = (mtime_t)( p_sys->f_duration / 1000.0 );
-        p_input->stream.i_mux_rate = p_input->stream.p_selected_area->i_size / 50 / i_duration;
+        p_input->stream.i_mux_rate = stream_Size( p_input->s )/50 / i_duration;
     }
-    else
-    {
-        p_input->stream.i_mux_rate = 0;
-    }
-    vlc_mutex_unlock( &p_input->stream.stream_lock );
 
     /* add all es */
     msg_Dbg( p_input, "found %d es", p_sys->i_track );
@@ -886,6 +1039,15 @@ static int Activate( vlc_object_t * p_this )
                                i_track + 1,
                                tk.i_cat,
                                tk.psz_language, 0 );
+        if( tk.i_cat == SPU_ES )
+        {
+            vlc_value_t val;
+            val.psz_string = "UTF-8";
+#if defined(HAVE_ICONV)
+            var_Create( p_input, "subsdec-encoding", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
+            var_Set( p_input, "subsdec-encoding", val );
+#endif
+        }
         if( !strcmp( tk.psz_codec, "V_MS/VFW/FOURCC" ) )
         {
             if( tk.i_extra_data < (int)sizeof( BITMAPINFOHEADER ) )
@@ -960,44 +1122,7 @@ static int Activate( vlc_object_t * p_this )
                 p_wf->wBitsPerSample    = GetWLE( &p_wf->wBitsPerSample );
                 p_wf->cbSize            = GetWLE( &p_wf->cbSize );
 
-                switch( p_wf->wFormatTag )
-                {
-                    case WAVE_FORMAT_PCM:
-                        tk.i_codec = VLC_FOURCC( 'a', 'r', 'a', 'w' );
-                        break;
-                    case WAVE_FORMAT_ADPCM:
-                        tk.i_codec = VLC_FOURCC( 'm', 's', 0x00, 0x02 );
-                        break;
-                    case WAVE_FORMAT_ALAW:
-                        tk.i_codec = VLC_FOURCC( 'a', 'l', 'a', 'w' );
-                        break;
-                    case WAVE_FORMAT_MULAW:
-                        tk.i_codec = VLC_FOURCC( 'm', 'l', 'a', 'w' );
-                        break;
-                    case WAVE_FORMAT_IMA_ADPCM:
-                        tk.i_codec = VLC_FOURCC( 'm', 's', 0x00, 0x11 );
-                        break;
-                    case WAVE_FORMAT_MPEG:
-                    case WAVE_FORMAT_MPEGLAYER3:
-                        tk.i_codec = VLC_FOURCC( 'm', 'p', 'g', 'a' );
-                        break;
-                    case WAVE_FORMAT_A52:
-                        tk.i_codec = VLC_FOURCC( 'a', '5', '2', ' ' );
-                        break;
-                    case WAVE_FORMAT_WMA1:
-                        tk.i_codec = VLC_FOURCC( 'w', 'm', 'a', '1' );
-                        break;
-                    case WAVE_FORMAT_WMA2:
-                        tk.i_codec = VLC_FOURCC( 'w', 'm', 'a', '2' );
-                        break;
-                    case WAVE_FORMAT_WMA3:
-                        tk.i_codec = VLC_FOURCC( 'w', 'm', 'a', '3' );
-                        break;
-                    default:
-                        msg_Err( p_input, "unknown wFormatTag=0x%x", p_wf->wFormatTag );
-                        tk.i_codec = VLC_FOURCC( 'm', 's', p_wf->wFormatTag >> 8, p_wf->wFormatTag&0xff );
-                        break;
-                }
+                wf_tag_to_fourcc( p_wf->wFormatTag, &tk.i_codec, NULL );
                 tk.p_es->p_waveformatex = p_wf;
             }
         }
@@ -1119,6 +1244,18 @@ static int Activate( vlc_object_t * p_this )
         {
             tk.i_codec = VLC_FOURCC( 's', 'u', 'b', 't' );
         }
+        else if( !strcmp( tk.psz_codec, "S_TEXT/SSA" ) ||
+                 !strcmp( tk.psz_codec, "S_SSA" ) ||
+                 !strcmp( tk.psz_codec, "S_ASS" ))
+        {
+            tk.i_codec = VLC_FOURCC( 's', 's', 'a', ' ' );
+            tk.p_es->p_demux_data = (es_sys_t *)malloc( sizeof( subtitle_data_t ) );
+            tk.p_es->p_demux_data->psz_header = strdup( (char *)tk.p_extra_data );
+        }
+        else if( !strcmp( tk.psz_codec, "S_VOBSUB" ) )
+        {
+            tk.i_codec = VLC_FOURCC( 's','p','u',' ' );
+        }
         else
         {
             msg_Err( p_input, "unknow codec id=`%s'", tk.psz_codec );
@@ -1187,9 +1324,9 @@ error:
 }
 
 /*****************************************************************************
- * Deactivate: frees unused data
+ * Close: frees unused data
  *****************************************************************************/
-static void Deactivate( vlc_object_t *p_this )
+static void Close( vlc_object_t *p_this )
 {
     input_thread_t *p_input = (input_thread_t *)p_this;
     demux_sys_t    *p_sys   = p_input->p_demux_data;
@@ -1220,6 +1357,8 @@ static void Deactivate( vlc_object_t *p_this )
         free( p_sys->psz_muxing_application );
     }
 
+    delete p_sys->segment;
+
     delete p_sys->ep;
     delete p_sys->es;
     delete p_sys->in;
@@ -1281,7 +1420,7 @@ static int BlockGet( input_thread_t *p_input, KaxBlock **pp_block, int64_t *pi_r
 
                 /* add it to the index */
                 if( p_sys->i_index == 0 ||
-                    ( p_sys->i_index > 0 && p_sys->index[p_sys->i_index - 1].i_position < p_sys->cluster->GetElementPosition() ) )
+                    ( p_sys->i_index > 0 && p_sys->index[p_sys->i_index - 1].i_position < (int64_t)p_sys->cluster->GetElementPosition() ) )
                 {
                     IndexAppendCluster( p_input, p_sys->cluster );
                 }
@@ -1371,7 +1510,8 @@ static pes_packet_t *MemToPES( input_thread_t *p_input, uint8_t *p_mem, int i_me
     p_pes->p_first = p_pes->p_last = p_data;
     p_pes->i_nb_data = 1;
     p_pes->i_pes_size = i_mem;
-
+    p_pes->i_rate = p_input->stream.control.i_rate;
+    
     return p_pes;
 }
 
@@ -1485,20 +1625,20 @@ static void BlockDecode( input_thread_t *p_input, KaxBlock *block, mtime_t i_pts
         p_pes->i_pts = i_pts;
         p_pes->i_dts = i_pts;
 
-        if( tk.i_cat == SPU_ES )
+        if( tk.i_cat == SPU_ES && strcmp( tk.psz_codec, "S_VOBSUB" ) )
         {
             if( i_duration > 0 )
             {
-                /* FIXME not sure about that */
-                p_pes->i_dts += i_duration * 1000;// * (mtime_t) 1000 / p_sys->i_timescale;
+                p_pes->i_dts += i_duration * 1000;
             }
             else
             {
                 p_pes->i_dts = 0;
             }
+
             if( p_pes->p_first && p_pes->i_pes_size > 0 )
             {
-                p_pes->p_first->p_payload_end[-1] = '\0';
+                p_pes->p_first->p_payload_end[0] = '\0';
             }
         }
 
@@ -1524,7 +1664,7 @@ static void Seek( input_thread_t *p_input, mtime_t i_date, int i_percent)
     int         i_track_skipping;
     int         i_track;
 
-    msg_Dbg( p_input, "seek request to %lld (%d%%)", i_date, i_percent );
+    msg_Dbg( p_input, "seek request to "I64Fd" (%d%%)", i_date, i_percent );
     if( i_date < 0 && i_percent < 0 )
     {
         return;
@@ -1535,11 +1675,11 @@ static void Seek( input_thread_t *p_input, mtime_t i_date, int i_percent)
     p_sys->cluster = NULL;
 
     /* seek without index or without date */
-    if( !p_sys->b_cues || i_date < 0 )
+    if( config_GetInt( p_input, "mkv-seek-percent" ) || !p_sys->b_cues || i_date < 0 )
     {
-        int64_t i_pos = i_percent * p_input->stream.p_selected_area->i_size / 100;
+        int64_t i_pos = i_percent * stream_Size( p_input->s ) / 100;
 
-        msg_Warn( p_input, "imprecise way of seeking" );
+        msg_Dbg( p_input, "imprecise way of seeking" );
         for( i_index = 0; i_index < p_sys->i_index; i_index++ )
         {
             if( p_sys->index[i_index].i_position >= i_pos)
@@ -1552,7 +1692,8 @@ static void Seek( input_thread_t *p_input, mtime_t i_date, int i_percent)
             i_index--;
         }
 
-        p_sys->in->setFilePointer( p_sys->index[i_index].i_position, seek_beginning );
+        p_sys->in->setFilePointer( p_sys->index[i_index].i_position,
+                                   seek_beginning );
 
         if( p_sys->index[i_index].i_position < i_pos )
         {
@@ -1570,7 +1711,7 @@ static void Seek( input_thread_t *p_input, mtime_t i_date, int i_percent)
                     /* add it to the index */
                     IndexAppendCluster( p_input, cluster );
 
-                    if( cluster->GetElementPosition() >= i_pos )
+                    if( (int64_t)cluster->GetElementPosition() >= i_pos )
                     {
                         p_sys->cluster = cluster;
                         p_sys->ep->Down();
@@ -1595,10 +1736,13 @@ static void Seek( input_thread_t *p_input, mtime_t i_date, int i_percent)
             i_index--;
         }
 
-        msg_Dbg( p_input, "seek got %lld (%d%%)",
-                 p_sys->index[i_index].i_time, (int)(100 * p_sys->index[i_index].i_position /p_input->stream.p_selected_area->i_size ) );
+        msg_Dbg( p_input, "seek got "I64Fd" (%d%%)",
+                 p_sys->index[i_index].i_time,
+                 (int)( 100 * p_sys->index[i_index].i_position /
+                        stream_Size( p_input->s ) ) );
 
-        p_sys->in->setFilePointer( p_sys->index[i_index].i_position, seek_beginning );
+        p_sys->in->setFilePointer( p_sys->index[i_index].i_position,
+                                   seek_beginning );
     }
 
     /* now parse until key frame */
@@ -1677,12 +1821,12 @@ static int Demux( input_thread_t * p_input )
             i_date = (mtime_t)1000000 *
                      (mtime_t)i_duration*
                      (mtime_t)p_sys->in->getFilePointer() /
-                     (mtime_t)p_input->stream.p_selected_area->i_size;
+                     (mtime_t)stream_Size( p_input->s );
         }
-        if( p_input->stream.p_selected_area->i_size > 0 )
+        if( stream_Size( p_input->s ) > 0 )
         {
             i_percent = 100 * p_sys->in->getFilePointer() /
-                            p_input->stream.p_selected_area->i_size;
+                        stream_Size( p_input->s );
         }
 
         Seek( p_input, i_date, i_percent);
@@ -1737,127 +1881,50 @@ static int Demux( input_thread_t * p_input )
 /*****************************************************************************
  * Stream managment
  *****************************************************************************/
-vlc_stream_io_callback::vlc_stream_io_callback( input_thread_t *p_input_ )
+vlc_stream_io_callback::vlc_stream_io_callback( stream_t *s_ )
 {
-    p_input = p_input_;
+    s = s_;
     mb_eof = VLC_FALSE;
 }
+
 uint32_t vlc_stream_io_callback::read( void *p_buffer, size_t i_size )
 {
-    data_packet_t *p_data;
-
-    int i_count;
-    int i_read = 0;
-
-
-    if( !i_size || mb_eof )
+    if( i_size <= 0 || mb_eof )
     {
         return 0;
     }
 
-    do
-    {
-        i_count = input_SplitBuffer(p_input, &p_data, __MIN( i_size, 10240 ) );
-        if( i_count <= 0 )
-        {
-            return i_read;
-        }
-        memcpy( p_buffer, p_data->p_payload_start, i_count );
-        input_DeletePacket( p_input->p_method_data, p_data );
-
-        (uint8_t*)p_buffer += i_count;
-        i_size            -= i_count;
-        i_read            += i_count;
-
-    } while( i_size );
-
-    return i_read;
+    return stream_Read( s, p_buffer, i_size );
 }
 void vlc_stream_io_callback::setFilePointer(int64_t i_offset, seek_mode mode )
 {
     int64_t i_pos;
-    int64_t i_last;
-
-    i_last = getFilePointer();
 
-    vlc_mutex_lock( &p_input->stream.stream_lock );
     switch( mode )
     {
         case seek_beginning:
             i_pos = i_offset;
             break;
         case seek_end:
-            i_pos = p_input->stream.p_selected_area->i_size - i_offset;
+            i_pos = stream_Size( s ) - i_offset;
             break;
         default:
-            i_pos= i_last + i_offset;
+            i_pos= stream_Tell( s ) + i_offset;
             break;
     }
 
-    if( i_pos < 0 ||
-        ( i_pos > p_input->stream.p_selected_area->i_size && p_input->stream.p_selected_area->i_size != 0 ) )
+    if( i_pos < 0 || i_pos >= stream_Size( s ) )
     {
-        msg_Err( p_input, "seeking to wrong place (i_pos=%lld)", i_pos );
-        vlc_mutex_unlock( &p_input->stream.stream_lock );
-
         mb_eof = VLC_TRUE;
         return;
     }
-    vlc_mutex_unlock( &p_input->stream.stream_lock );
 
     mb_eof = VLC_FALSE;
-
-    if( i_pos == i_last )
+    if( stream_Seek( s, i_pos ) )
     {
-        return;
-    }
-
-    msg_Dbg( p_input, "####################seek new=%lld old=%lld", i_pos, getFilePointer() );
-
-    if( p_input->stream.b_seekable &&
-        ( /*p_input->stream.i_method == INPUT_METHOD_FILE ||*/ i_pos < i_last || i_pos - i_last > p_input->i_bufsize / 4 ) )
-    {
-        input_AccessReinit( p_input );
-        p_input->pf_seek( p_input, i_pos );
-    }
-    else if( i_pos > i_last )
-    {
-        data_packet_t   *p_data;
-        int             i_skip = i_pos - i_last;
-
-        if( i_skip > 1024 )
-        {
-            msg_Warn( p_input, "will skip %d bytes, slow", i_skip );
-        }
-
-        while (i_skip > 0 )
-        {
-            int i_read;
-
-            i_read = input_SplitBuffer( p_input, &p_data,
-                                        __MIN( 4096, i_skip ) );
-            if( i_read < 0 )
-            {
-                msg_Err( p_input, "seek failed" );
-                mb_eof = VLC_TRUE;
-                return;
-            }
-            i_skip -= i_read;
-
-            input_DeletePacket( p_input->p_method_data, p_data );
-            if( i_read == 0 && i_skip > 0 )
-            {
-                msg_Err( p_input, "seek failed" );
-                mb_eof = VLC_TRUE;
-                return;
-            }
-        }
-    }
-    else
-    {
-        msg_Err( p_input, "cannot seek or emulate seek to %lld from %lld", i_pos, i_last );
         mb_eof = VLC_TRUE;
     }
+    return;
 }
 size_t vlc_stream_io_callback::write( const void *p_buffer, size_t i_size )
 {
@@ -1865,13 +1932,7 @@ size_t vlc_stream_io_callback::write( const void *p_buffer, size_t i_size )
 }
 uint64_t vlc_stream_io_callback::getFilePointer( void )
 {
-    uint64_t i_pos;
-
-    vlc_mutex_lock( &p_input->stream.stream_lock );
-    i_pos= p_input->stream.p_selected_area->i_tell;
-    vlc_mutex_unlock( &p_input->stream.stream_lock );
-
-    return i_pos;
+    return stream_Tell( s );
 }
 void vlc_stream_io_callback::close( void )
 {
@@ -2072,20 +2133,21 @@ static void LoadCues( input_thread_t *p_input )
                         }
                         else
                         {
-                            msg_Dbg( p_input, "         * Unknow (%s)", typeid(*el).name() );
+                            msg_Dbg( p_input, "         * Unknown (%s)", typeid(*el).name() );
                         }
                     }
                     ep->Up();
                 }
                 else
                 {
-                    msg_Dbg( p_input, "     * Unknow (%s)", typeid(*el).name() );
+                    msg_Dbg( p_input, "     * Unknown (%s)", typeid(*el).name() );
                 }
             }
             ep->Up();
 
-            msg_Dbg( p_input, " * added time=%lld pos=%lld track=%d bnum=%d",
-                     idx.i_time, idx.i_position, idx.i_track, idx.i_block_number );
+            msg_Dbg( p_input, " * added time="I64Fd" pos="I64Fd
+                     " track=%d bnum=%d", idx.i_time, idx.i_position,
+                     idx.i_track, idx.i_block_number );
 
             p_sys->i_index++;
             if( p_sys->i_index >= p_sys->i_index_max )
@@ -2097,7 +2159,7 @@ static void LoadCues( input_thread_t *p_input )
         }
         else
         {
-            msg_Dbg( p_input, " * Unknow (%s)", typeid(*el).name() );
+            msg_Dbg( p_input, " * Unknown (%s)", typeid(*el).name() );
         }
     }
     delete ep;
@@ -2281,6 +2343,27 @@ static void InformationsCreate( input_thread_t *p_input )
 
         sprintf( psz_cat, "Stream %d", i_track );
         p_cat = input_InfoCategory( p_input, psz_cat);
+        if( tk.psz_name )
+        {
+            input_AddInfo( p_cat, _("Name"), "%s", tk.psz_name );
+        }
+        if( tk.psz_codec_name )
+        {
+            input_AddInfo( p_cat, _("Codec Name"), "%s", tk.psz_codec_name );
+        }
+        if( tk.psz_codec_settings )
+        {
+            input_AddInfo( p_cat, _("Codec Setting"), "%s", tk.psz_codec_settings );
+        }
+        if( tk.psz_codec_info_url )
+        {
+            input_AddInfo( p_cat, _("Codec Info"), "%s", tk.psz_codec_info_url );
+        }
+        if( tk.psz_codec_download_url )
+        {
+            input_AddInfo( p_cat, _("Codec Download"), "%s", tk.psz_codec_download_url );
+        }
+
         switch( tk.i_cat )
         {
             case AUDIO_ES:
@@ -2323,9 +2406,16 @@ static void InformationsCreate( input_thread_t *p_input )
 
 #undef  tk
     }
-    if( p_sys->i_tags_position >= 0 && p_input->stream.b_seekable )
+
+    if( p_sys->i_tags_position >= 0 )
     {
-        LoadTags( p_input );
+        vlc_bool_t b_seekable;
+
+        stream_Control( p_input->s, STREAM_CAN_FASTSEEK, &b_seekable );
+        if( b_seekable )
+        {
+            LoadTags( p_input );
+        }
     }
 }
 
@@ -2382,3 +2472,38 @@ static char * UTF8ToStr( const UTFstring &u )
     return dst;
 }
 
+static char *LanguageGetName    ( const char *psz_code )
+{
+    const iso639_lang_t *pl;
+
+    if( strlen( psz_code ) == 2 )
+    {
+        pl = GetLang_1( psz_code );
+    }
+    else if( strlen( psz_code ) == 3 )
+    {
+        pl = GetLang_2B( psz_code );
+        if( !strcmp( pl->psz_iso639_1, "??" ) )
+        {
+            pl = GetLang_2T( psz_code );
+        }
+    }
+    else
+    {
+        return strdup( psz_code );
+    }
+
+    if( !strcmp( pl->psz_iso639_1, "??" ) )
+    {
+       return strdup( psz_code );
+    }
+    else
+    {
+        if( *pl->psz_native_name )
+        {
+            return strdup( pl->psz_native_name );
+        }
+        return strdup( pl->psz_eng_name );
+    }
+}
+