[vlc-commits] Free unused resources when using linked mkvs

Denis Charmet git at videolan.org
Tue Feb 12 11:52:26 CET 2013


vlc/vlc-2.0 | branch: master | Denis Charmet <typx at dinauz.org> | Mon Feb 11 23:18:42 2013 +0100| [76c37c46f9a01e03dbefe7b6360cc6293d990e73] | committer: Jean-Baptiste Kempf

Free unused resources when using linked mkvs
(cherry picked from commit 0fafbb87581a526dcdd7183cd49a472ada2bb8d7)

Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>

> http://git.videolan.org/gitweb.cgi/vlc/vlc-2.0.git/?a=commit;h=76c37c46f9a01e03dbefe7b6360cc6293d990e73
---

 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 d863bb7..47c0f99 100644
--- a/modules/demux/mkv/demux.cpp
+++ b/modules/demux/mkv/demux.cpp
@@ -691,6 +691,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 ce7c966..a4fb495 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 0c98367..d17849b 100644
--- a/modules/demux/mkv/mkv.cpp
+++ b/modules/demux/mkv/mkv.cpp
@@ -246,6 +246,8 @@ static int Open( vlc_object_t * p_this )
         goto error;
     }
 
+    p_sys->FreeUnused();
+
     p_sys->InitUi();
 
     return VLC_SUCCESS;



More information about the vlc-commits mailing list