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

Steve Lhomme git at videolan.org
Thu Jan 25 17:39:38 CET 2018


vlc/vlc-3.0 | branch: master | Steve Lhomme <robux4 at ycbcr.xyz> | Thu Jan 25 13:32:27 2018 +0100| [4795f4e08fab3aacfa1f4af0a0a31a02acc154d6] | committer: Jean-Baptiste Kempf

demux:mkv: make the matroska_segment_c own its EbmlParser

(cherry picked from commit a62d3f305decd80c5c787a809904f95e1da383ff)

Signed-off-by: Steve Lhomme <robux4 at ycbcr.xyz>
Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>

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

 modules/demux/mkv/demux.cpp                   |  7 +-----
 modules/demux/mkv/matroska_segment.cpp        | 33 +++++++++++++--------------
 modules/demux/mkv/matroska_segment.hpp        |  6 +++--
 modules/demux/mkv/matroska_segment_seeker.cpp |  8 +++----
 4 files changed, 25 insertions(+), 29 deletions(-)

diff --git a/modules/demux/mkv/demux.cpp b/modules/demux/mkv/demux.cpp
index 2d58db352a..98092eed44 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 8c002ed357..7fca0fc60c 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;
@@ -576,9 +575,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 ) )
         {
@@ -648,7 +647,7 @@ bool matroska_segment_c::Preload( )
                     SegmentSeeker::Seekpoint( cluster->GetElementPosition(), 0 ) );
             }
 
-            ep->Down();
+            ep.Down();
             /* stop pre-parsing the stream */
             break;
         }
@@ -1172,7 +1171,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
     };
 
@@ -1312,13 +1311,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;
@@ -1350,13 +1349,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" );
@@ -1368,7 +1367,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;
@@ -1387,12 +1386,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;
 
@@ -1417,8 +1416,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 f2c9d3966c..637ef4eddf 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 1508a12bfc..13bc8f157f 100644
--- a/modules/demux/mkv/matroska_segment_seeker.cpp
+++ b/modules/demux/mkv/matroska_segment_seeker.cpp
@@ -468,13 +468,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 )
         mark_range_as_searched( Range( i_cluster_pos, ms.es.I_O().getFilePointer() ) );
     }
 
-    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