[vlc-commits] demux:mkv: make the matroska_segment_c own its EbmlParser

Steve Lhomme git at videolan.org
Thu Jan 25 13:55:38 CET 2018


vlc | branch: master | Steve Lhomme <robux4 at ycbcr.xyz> | Thu Jan 25 13:32:27 2018 +0100| [a62d3f305decd80c5c787a809904f95e1da383ff] | committer: Steve Lhomme

demux:mkv: make the matroska_segment_c own its EbmlParser

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

 modules/demux/mkv/demux.cpp                   |  7 +-----
 modules/demux/mkv/matroska_segment.cpp        | 35 +++++++++++++--------------
 modules/demux/mkv/matroska_segment.hpp        |  6 +++--
 modules/demux/mkv/matroska_segment_seeker.cpp |  8 +++---
 4 files changed, 26 insertions(+), 30 deletions(-)

diff --git a/modules/demux/mkv/demux.cpp b/modules/demux/mkv/demux.cpp
index a17d36dc30..e622eb0654 100644
--- a/modules/demux/mkv/demux.cpp
+++ b/modules/demux/mkv/demux.cpp
@@ -505,13 +505,8 @@ bool demux_sys_t::AnalyseAllSegmentsFound( demux_t *p_demux, matroska_stream_c *
 
         if ( MKV_IS_ID( p_l0, KaxSegment) )
         {
-            EbmlParser  *ep;
-            matroska_segment_c *p_segment1 = new matroska_segment_c( *this, p_stream1->estream );
+            matroska_segment_c *p_segment1 = new matroska_segment_c( *this, p_stream1->estream, (KaxSegment*)p_l0 );
 
-            ep = new EbmlParser(&p_stream1->estream, p_l0, &demuxer,
-                                var_InheritBool( &demuxer, "mkv-use-dummy" ) );
-            p_segment1->ep = ep;
-            p_segment1->segment = (KaxSegment*)p_l0;
             p_segment1->Preload();
 
             b_keep_segment = (FindSegment( *p_segment1->p_segment_uid ) == NULL);
diff --git a/modules/demux/mkv/matroska_segment.cpp b/modules/demux/mkv/matroska_segment.cpp
index dc2f15f075..b54f7a56f5 100644
--- a/modules/demux/mkv/matroska_segment.cpp
+++ b/modules/demux/mkv/matroska_segment.cpp
@@ -32,8 +32,8 @@
 #include <new>
 #include <iterator>
 
-matroska_segment_c::matroska_segment_c( demux_sys_t & demuxer, EbmlStream & estream )
-    :segment(NULL)
+matroska_segment_c::matroska_segment_c( demux_sys_t & demuxer, EbmlStream & estream, KaxSegment *p_seg )
+    :segment(p_seg)
     ,es(estream)
     ,i_timescale(MKVD_TIMECODESCALE)
     ,i_duration(-1)
@@ -58,7 +58,7 @@ matroska_segment_c::matroska_segment_c( demux_sys_t & demuxer, EbmlStream & estr
     ,psz_date_utc(NULL)
     ,i_default_edition(0)
     ,sys(demuxer)
-    ,ep(NULL)
+    ,ep( EbmlParser(&estream, p_seg, &demuxer.demuxer, var_InheritBool( &demuxer.demuxer, "mkv-use-dummy" ) ))
     ,b_preloaded(false)
     ,b_ref_external_segments(false)
 {
@@ -72,7 +72,6 @@ matroska_segment_c::~matroska_segment_c()
     free( psz_title );
     free( psz_date_utc );
 
-    delete ep;
     delete segment;
     delete p_segment_uid;
     delete p_prev_segment_uid;
@@ -275,7 +274,7 @@ bool matroska_segment_c::ParseSimpleTags( SimpleTag* pout_simple, KaxTagSimple *
         demux_sys_t        & sys;
         SimpleTag          & out;
         int                target_type;
-    } payload = { this, ep, sys, *pout_simple, 50 };
+    } payload = { this, &ep, sys, *pout_simple, 50 };
     MKV_SWITCH_CREATE( EbmlTypeDispatcher, SimpleTagHandler, SimpleTagHandlerPayload )
     {
         MKV_SWITCH_INIT();
@@ -356,7 +355,7 @@ void matroska_segment_c::LoadTags( KaxTags *tags )
         EbmlParser         * const ep;
         demux_sys_t        & sys;
         int                target_type;
-    } payload = { this, ep, sys, 50 };
+    } payload = { this, &ep, sys, 50 };
     MKV_SWITCH_CREATE( EbmlTypeDispatcher, KaxTagsHandler, TagsHandlerPayload )
     {
         MKV_SWITCH_INIT();
@@ -565,9 +564,9 @@ bool matroska_segment_c::Preload( )
 
     EbmlElement *el = NULL;
 
-    ep->Reset( &sys.demuxer );
+    ep.Reset( &sys.demuxer );
 
-    while( ( el = ep->Get() ) != NULL )
+    while( ( el = ep.Get() ) != NULL )
     {
         if( MKV_IS_ID( el, KaxSeekHead ) )
         {
@@ -1149,7 +1148,7 @@ int matroska_segment_c::BlockGet( KaxBlock * & pp_block, KaxSimpleBlock * & pp_s
         bool                 b_cluster_timecode;
 
     } payload = {
-        this, ep, &sys.demuxer, pp_block, pp_simpleblock,
+        this, &ep, &sys.demuxer, pp_block, pp_simpleblock,
         *pi_duration, *pb_key_picture, *pb_discardable_picture, true
     };
 
@@ -1289,13 +1288,13 @@ int matroska_segment_c::BlockGet( KaxBlock * & pp_block, KaxSimpleBlock * & pp_s
         EbmlElement *el = NULL;
         int         i_level;
 
-        if( pp_simpleblock != NULL || ((el = ep->Get()) == NULL && pp_block != NULL) )
+        if( pp_simpleblock != NULL || ((el = ep.Get()) == NULL && pp_block != NULL) )
         {
             /* Check blocks validity to protect againts broken files */
             const mkv_track_t *p_track = FindTrackByBlock( pp_block , pp_simpleblock );
             if( p_track == NULL )
             {
-                ep->Unkeep();
+                ep.Unkeep();
                 pp_simpleblock = NULL;
                 pp_block = NULL;
                 continue;
@@ -1327,13 +1326,13 @@ int matroska_segment_c::BlockGet( KaxBlock * & pp_block, KaxSimpleBlock * & pp_s
             return VLC_SUCCESS;
         }
 
-        i_level = ep->GetLevel();
+        i_level = ep.GetLevel();
 
         if( el == NULL )
         {
             if( i_level > 1 )
             {
-                ep->Up();
+                ep.Up();
                 continue;
             }
             msg_Warn( &sys.demuxer, "EOF" );
@@ -1345,7 +1344,7 @@ int matroska_segment_c::BlockGet( KaxBlock * & pp_block, KaxSimpleBlock * & pp_s
          * without index */
         if( i_level > 1 )
         {
-            if( cluster && !ep->IsTopPresent( cluster ) )
+            if( cluster && !ep.IsTopPresent( cluster ) )
             {
                 msg_Warn( &sys.demuxer, "Unexpected escape from current cluster" );
                 cluster = NULL;
@@ -1365,12 +1364,12 @@ int matroska_segment_c::BlockGet( KaxBlock * & pp_block, KaxSimpleBlock * & pp_s
                     if( unlikely( !el->ValidateSize() || ( el->IsFiniteSize() && el->GetSize() >= SIZE_MAX ) ) )
                     {
                         msg_Err( &sys.demuxer, "Error while reading %s... upping level", typeid(*el).name());
-                        ep->Up();
+                        ep.Up();
 
                         if ( i_level == 2 )
                             break;
 
-                        ep->Unkeep();
+                        ep.Unkeep();
                         pp_simpleblock = NULL;
                         pp_block = NULL;
 
@@ -1396,8 +1395,8 @@ int matroska_segment_c::BlockGet( KaxBlock * & pp_block, KaxSimpleBlock * & pp_s
         catch (...)
         {
             msg_Err( &sys.demuxer, "Error while reading %s... upping level", typeid(*el).name());
-            ep->Up();
-            ep->Unkeep();
+            ep.Up();
+            ep.Unkeep();
             pp_simpleblock = NULL;
             pp_block = NULL;
         }
diff --git a/modules/demux/mkv/matroska_segment.hpp b/modules/demux/mkv/matroska_segment.hpp
index 8a0ac57c0d..8c102bebb4 100644
--- a/modules/demux/mkv/matroska_segment.hpp
+++ b/modules/demux/mkv/matroska_segment.hpp
@@ -34,6 +34,8 @@
 #include <set>
 #include <memory>
 
+#include "Ebml_parser.hpp"
+
 class EbmlParser;
 
 class chapter_edition_c;
@@ -78,7 +80,7 @@ public:
     typedef std::map<mkv_track_t::track_id_t, std::unique_ptr<mkv_track_t>> tracks_map_t;
     typedef std::vector<Tag>            tags_t;
 
-    matroska_segment_c( demux_sys_t & demuxer, EbmlStream & estream );
+    matroska_segment_c( demux_sys_t &, EbmlStream &, KaxSegment * );
     virtual ~matroska_segment_c();
 
     KaxSegment              *segment;
@@ -130,7 +132,7 @@ public:
     tags_t                          tags;
 
     demux_sys_t                    & sys;
-    EbmlParser                     *ep;
+    EbmlParser                     ep;
     bool                           b_preloaded;
     bool                           b_ref_external_segments;
 
diff --git a/modules/demux/mkv/matroska_segment_seeker.cpp b/modules/demux/mkv/matroska_segment_seeker.cpp
index 617a808ce4..e6f8a5b13d 100644
--- a/modules/demux/mkv/matroska_segment_seeker.cpp
+++ b/modules/demux/mkv/matroska_segment_seeker.cpp
@@ -467,13 +467,13 @@ SegmentSeeker::mkv_jump_to( matroska_segment_c& ms, fptr_t fpos )
             );
 
             ms.es.I_O().setFilePointer( *cluster_it );
-            ms.ep->reconstruct( &ms.es, ms.segment, &ms.sys.demuxer );
+            ms.ep.reconstruct( &ms.es, ms.segment, &ms.sys.demuxer );
         }
 
         while( ms.cluster == NULL || (
               ms.cluster->IsFiniteSize() && ms.cluster->GetEndPosition() < fpos ) )
         {
-            if( !( ms.cluster = static_cast<KaxCluster*>( ms.ep->Get() ) ) )
+            if( !( ms.cluster = static_cast<KaxCluster*>( ms.ep.Get() ) ) )
             {
                 msg_Err( &ms.sys.demuxer, "unable to read KaxCluster during seek, giving up" );
                 return;
@@ -487,11 +487,11 @@ SegmentSeeker::mkv_jump_to( matroska_segment_c& ms, fptr_t fpos )
         }
     }
 
-    ms.ep->Down();
+    ms.ep.Down();
 
     /* read until cluster/timecode to initialize cluster */
 
-    while( EbmlElement * el = ms.ep->Get() )
+    while( EbmlElement * el = ms.ep.Get() )
     {
         if( MKV_CHECKED_PTR_DECL( p_tc, KaxClusterTimecode, el ) )
         {



More information about the vlc-commits mailing list