[vlc-devel] [PATCH] Free unused resources when using linked mkvs

Denis Charmet typx at dinauz.org
Mon Feb 11 23:21:51 CET 2013


---
 modules/demux/mkv/demux.cpp |   32 ++++++++++++++++++++++++++++++++
 modules/demux/mkv/demux.hpp |    1 +
 modules/demux/mkv/mkv.cpp   |    2 ++
 3 files changed, 35 insertions(+)

diff --git a/modules/demux/mkv/demux.cpp b/modules/demux/mkv/demux.cpp
index 4077405..60f1b2e 100644
--- a/modules/demux/mkv/demux.cpp
+++ b/modules/demux/mkv/demux.cpp
@@ -713,6 +713,38 @@ bool demux_sys_t::PreloadLinked()
     return true;
 }
 
+void demux_sys_t::FreeUnused()
+{
+    size_t i;
+    for( i = 0; i < streams.size(); i++ )
+    {
+        bool used = false;
+        struct matroska_stream_c *p_s = streams[i];
+        for( size_t j = 0; j < p_s->segments.size(); j++ )
+        {
+            if( p_s->segments[j]->b_preloaded )
+            {
+                used = true;
+                break;
+            }
+        }
+        if( !used )
+        {
+            streams[i] = NULL;
+            delete p_s;
+        }
+        
+    }
+    for( i = 0; i < opened_segments.size(); i++)
+    {
+        if( !opened_segments[i]->b_preloaded )
+        {
+            delete opened_segments[i];
+            opened_segments[i] = NULL;
+        }
+    }
+}
+
 virtual_segment_c *demux_sys_t::VirtualFromSegments( std::vector<matroska_segment_c*> *p_segments ) const
 {
     if ( p_segments->empty() )
diff --git a/modules/demux/mkv/demux.hpp b/modules/demux/mkv/demux.hpp
index 3cb5f60..c295f13 100644
--- a/modules/demux/mkv/demux.hpp
+++ b/modules/demux/mkv/demux.hpp
@@ -382,6 +382,7 @@ public:
 
     void PreloadFamily( const matroska_segment_c & of_segment );
     bool PreloadLinked();
+    void FreeUnused();
     bool PreparePlayback( virtual_segment_c *p_new_segment );
     matroska_stream_c *AnalyseAllSegmentsFound( demux_t *p_demux, EbmlStream *p_estream, bool b_initial = false );
     void JumpTo( virtual_segment_c & p_segment, virtual_chapter_c * p_chapter );
diff --git a/modules/demux/mkv/mkv.cpp b/modules/demux/mkv/mkv.cpp
index c2d5478..7238ff2 100644
--- a/modules/demux/mkv/mkv.cpp
+++ b/modules/demux/mkv/mkv.cpp
@@ -247,6 +247,8 @@ static int Open( vlc_object_t * p_this )
         goto error;
     }
 
+    p_sys->FreeUnused();
+
     p_sys->InitUi();
 
     return VLC_SUCCESS;
-- 
1.7.10.4




More information about the vlc-devel mailing list