[vlc-devel] [PATCH] Preload local directory for mkv only when needed

Denis Charmet typx at dinauz.org
Thu Jan 26 23:58:33 CET 2012


The option is now default enabled to be as simple as possible for the end users.
---
 modules/demux/mkv/matroska_segment.cpp       |    1 +
 modules/demux/mkv/matroska_segment.hpp       |    1 +
 modules/demux/mkv/matroska_segment_parse.cpp |    7 +++++++
 modules/demux/mkv/mkv.cpp                    |    9 +++++++--
 4 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/modules/demux/mkv/matroska_segment.cpp b/modules/demux/mkv/matroska_segment.cpp
index 635140a..455f7d9 100644
--- a/modules/demux/mkv/matroska_segment.cpp
+++ b/modules/demux/mkv/matroska_segment.cpp
@@ -76,6 +76,7 @@ matroska_segment_c::matroska_segment_c( demux_sys_t & demuxer, EbmlStream & estr
     ,sys(demuxer)
     ,ep(NULL)
     ,b_preloaded(false)
+    ,b_ref_external_segments(false)
 {
     p_indexes = (mkv_index_t*)malloc( sizeof( mkv_index_t ) * i_index_max );
 }
diff --git a/modules/demux/mkv/matroska_segment.hpp b/modules/demux/mkv/matroska_segment.hpp
index 8ab6d8c..713f498 100644
--- a/modules/demux/mkv/matroska_segment.hpp
+++ b/modules/demux/mkv/matroska_segment.hpp
@@ -97,6 +97,7 @@ public:
     demux_sys_t                    & sys;
     EbmlParser                     *ep;
     bool                           b_preloaded;
+    bool                           b_ref_external_segments;
 
     bool Preload();
     bool PreloadFamily( const matroska_segment_c & segment );
diff --git a/modules/demux/mkv/matroska_segment_parse.cpp b/modules/demux/mkv/matroska_segment_parse.cpp
index 1a5ec21..c916915 100644
--- a/modules/demux/mkv/matroska_segment_parse.cpp
+++ b/modules/demux/mkv/matroska_segment_parse.cpp
@@ -710,14 +710,20 @@ void matroska_segment_c::ParseInfo( KaxInfo *info )
         else if( MKV_IS_ID( l, KaxPrevUID ) )
         {
             if ( p_prev_segment_uid == NULL )
+            {
                 p_prev_segment_uid = new KaxPrevUID(*static_cast<KaxPrevUID*>(l));
+                b_ref_external_segments = true;
+            }
 
             msg_Dbg( &sys.demuxer, "|   |   + PrevUID=%d", *(uint32*)p_prev_segment_uid->GetBuffer() );
         }
         else if( MKV_IS_ID( l, KaxNextUID ) )
         {
             if ( p_next_segment_uid == NULL )
+            {
                 p_next_segment_uid = new KaxNextUID(*static_cast<KaxNextUID*>(l));
+                b_ref_external_segments = true;
+            }
 
             msg_Dbg( &sys.demuxer, "|   |   + NextUID=%d", *(uint32*)p_next_segment_uid->GetBuffer() );
         }
@@ -860,6 +866,7 @@ void matroska_segment_c::ParseChapterAtom( int i_level, KaxChapterAtom *ca, chap
         else if( MKV_IS_ID( l, KaxChapterSegmentUID ) )
         {
             chapters.p_segment_uid = new KaxChapterSegmentUID( *static_cast<KaxChapterSegmentUID*>(l) );
+            b_ref_external_segments = true;
             msg_Dbg( &sys.demuxer, "|   |   |   |   + ChapterSegmentUID= %u", *(uint32*)chapters.p_segment_uid->GetBuffer() );
         }
         else if( MKV_IS_ID( l, KaxChapterSegmentEditionUID ) )
diff --git a/modules/demux/mkv/mkv.cpp b/modules/demux/mkv/mkv.cpp
index 443c38c..03643ca 100644
--- a/modules/demux/mkv/mkv.cpp
+++ b/modules/demux/mkv/mkv.cpp
@@ -58,7 +58,7 @@ vlc_module_begin ()
             N_("Chapter codecs"),
             N_("Use chapter codecs found in the segment."), true );
 
-    add_bool( "mkv-preload-local-dir", false,
+    add_bool( "mkv-preload-local-dir", true,
             N_("Preload MKV files in the same directory"),
             N_("Preload matroska files in the same directory to find linked segments (not good for broken files)."), false );
 
@@ -92,6 +92,7 @@ static int Open( vlc_object_t * p_this )
     std::string         s_path, s_filename;
     vlc_stream_io_callback *p_io_callback;
     EbmlStream         *p_io_stream;
+    bool                b_need_preload = false;
 
     /* peek the begining */
     if( stream_Peek( p_demux->s, &p_peek, 4 ) < 4 ) return VLC_EGENERIC;
@@ -130,6 +131,7 @@ static int Open( vlc_object_t * p_this )
     for (size_t i=0; i<p_stream->segments.size(); i++)
     {
         p_stream->segments[i]->Preload();
+        b_need_preload |= p_stream->segments[i]->b_ref_external_segments; 
     }
 
     p_segment = p_stream->segments[0];
@@ -139,8 +141,9 @@ static int Open( vlc_object_t * p_this )
         goto error;
     }
 
-    if (var_InheritBool( p_demux, "mkv-preload-local-dir" ))
+    if (b_need_preload && var_InheritBool( p_demux, "mkv-preload-local-dir" ))
     {
+        msg_Dbg( p_demux, "Preloading local dir" );
         /* get the files from the same dir from the same family (based on p_demux->psz_path) */
         if ( p_demux->psz_file && !strcmp( p_demux->psz_access, "file" ) )
         {
@@ -233,6 +236,8 @@ static int Open( vlc_object_t * p_this )
 
         p_sys->PreloadFamily( *p_segment );
     }
+    else if (b_need_preload)
+        msg_Warn( p_demux, "This file references other files, you may want to enable the preload of local directory");
 
     if ( !p_sys->PreloadLinked() ||
          !p_sys->PreparePlayback( NULL ) )
-- 
1.7.8.3




More information about the vlc-devel mailing list