[vlc-devel] [PATCH 2/8] mkv: create a virtual_chapter_c with its sub chapters

Steve Lhomme robux4 at videolabs.io
Wed Mar 16 13:43:25 CET 2016


this will allow the adjustment of the start/stop timestamps from lower chapters
---
 modules/demux/mkv/virtual_segment.cpp | 18 +++++++++++-------
 modules/demux/mkv/virtual_segment.hpp |  5 +++--
 2 files changed, 14 insertions(+), 9 deletions(-)

diff --git a/modules/demux/mkv/virtual_segment.cpp b/modules/demux/mkv/virtual_segment.cpp
index c2d216c..7773a5b 100644
--- a/modules/demux/mkv/virtual_segment.cpp
+++ b/modules/demux/mkv/virtual_segment.cpp
@@ -44,10 +44,11 @@ virtual_chapter_c * virtual_chapter_c::CreateVirtualChapter( chapter_item_c * p_
                                                              std::vector<matroska_segment_c*> & segments,
                                                              int64_t & usertime_offset, bool b_ordered)
 {
+    std::vector<virtual_chapter_c *> sub_chapters;
     if( !p_chap )
     {
         /* Dummy chapter use the whole segment */
-        return new (std::nothrow) virtual_chapter_c( main_segment, NULL, 0, main_segment.i_duration * 1000 );
+        return new (std::nothrow) virtual_chapter_c( main_segment, NULL, 0, main_segment.i_duration * 1000, sub_chapters );
     }
 
     int64_t start = ( b_ordered )? usertime_offset : p_chap->i_start_time;
@@ -67,11 +68,6 @@ virtual_chapter_c * virtual_chapter_c::CreateVirtualChapter( chapter_item_c * p_
     if ( !p_segment->b_preloaded )
         p_segment->Preload();
 
-    virtual_chapter_c * p_vchap = new (std::nothrow) virtual_chapter_c( *p_segment, p_chap, start, stop );
-
-    if( !p_vchap )
-        return NULL;
-
     int64_t tmp = usertime_offset;
 
     for( size_t i = 0; i < p_chap->sub_chapters.size(); i++ )
@@ -79,7 +75,15 @@ virtual_chapter_c * virtual_chapter_c::CreateVirtualChapter( chapter_item_c * p_
         virtual_chapter_c * p_vsubchap = CreateVirtualChapter( p_chap->sub_chapters[i], *p_segment, segments, tmp, b_ordered );
 
         if( p_vsubchap )
-            p_vchap->sub_chapters.push_back( p_vsubchap );
+            sub_chapters.push_back( p_vsubchap );
+    }
+
+    virtual_chapter_c * p_vchap = new (std::nothrow) virtual_chapter_c( *p_segment, p_chap, start, stop, sub_chapters );
+    if( !p_vchap )
+    {
+        for( size_t i = 0 ; i < sub_chapters.size(); i++ )
+            delete sub_chapters[i];
+        return NULL;
     }
 
     if( tmp == usertime_offset )
diff --git a/modules/demux/mkv/virtual_segment.hpp b/modules/demux/mkv/virtual_segment.hpp
index 7b08cc2..7b943a1 100644
--- a/modules/demux/mkv/virtual_segment.hpp
+++ b/modules/demux/mkv/virtual_segment.hpp
@@ -36,9 +36,10 @@
 class virtual_chapter_c
 {
 public:
-    virtual_chapter_c( matroska_segment_c &seg, chapter_item_c *p_chap, int64_t start, int64_t stop ):
+    virtual_chapter_c( matroska_segment_c &seg, chapter_item_c *p_chap, int64_t start, int64_t stop, std::vector<virtual_chapter_c *> & sub_chaps ):
         segment(seg), p_chapter(p_chap),
-        i_mk_virtual_start_time(start), i_mk_virtual_stop_time(stop)
+        i_mk_virtual_start_time(start), i_mk_virtual_stop_time(stop),
+        sub_chapters(sub_chaps)
     {}
     ~virtual_chapter_c();
 
-- 
2.7.2.windows.1



More information about the vlc-devel mailing list