[vlc-devel] [PATCH 18/34] mkv: changed matroska_segment_c::BlockFindTrackIndex to FindTrackByBlock

Filip Roséen filip at videolabs.io
Fri May 6 19:08:57 CEST 2016


Since our tracks are now managed by a map instead of a vector, we no
longer are interested in the "index" for a track that a certain block
corresponds to; instead we would like to directly access the track.

This function tries to accomplish this as smoothly as possible, using
iterators to signal whether the block is valid for a known track or not.
---
 modules/demux/mkv/matroska_segment.cpp | 32 +++++++++++++++-----------------
 modules/demux/mkv/matroska_segment.hpp |  3 +--
 2 files changed, 16 insertions(+), 19 deletions(-)

diff --git a/modules/demux/mkv/matroska_segment.cpp b/modules/demux/mkv/matroska_segment.cpp
index dbcdf65..270ef0a 100644
--- a/modules/demux/mkv/matroska_segment.cpp
+++ b/modules/demux/mkv/matroska_segment.cpp
@@ -980,27 +980,25 @@ void matroska_segment_c::Seek( mtime_t i_mk_date, mtime_t i_mk_time_offset, int6
     }
 }
 
-int matroska_segment_c::BlockFindTrackIndex( size_t *pi_track,
+
+int matroska_segment_c::FindTrackByBlock(tracks_map_t::iterator* p_track_it,
                                              const KaxBlock *p_block, const KaxSimpleBlock *p_simpleblock )
 {
-    size_t i_track;
-    for( i_track = 0; i_track < tracks.size(); i_track++ )
-    {
-        const mkv_track_t *tk = tracks[i_track];
-
-        if( ( p_block != NULL && tk->i_number == p_block->TrackNum() ) ||
-            ( p_simpleblock != NULL && tk->i_number == p_simpleblock->TrackNum() ) )
-        {
-            break;
-        }
-    }
+    *p_track_it = tracks.end();
 
-    if( i_track >= tracks.size() )
+    if( p_block == NULL && p_simpleblock == NULL )
         return VLC_EGENERIC;
 
-    if( pi_track )
-        *pi_track = i_track;
-    return VLC_SUCCESS;
+    if (p_block != NULL)
+    {
+        *p_track_it = tracks.find( p_block->TrackNum() );
+    }
+    else if( p_simpleblock != NULL)
+    {
+        *p_track_it = tracks.find( p_simpleblock->TrackNum() );
+    }
+
+    return *p_track_it != tracks.end() ? VLC_SUCCESS : VLC_EGENERIC;
 }
 
 void matroska_segment_c::ComputeTrackPriority()
@@ -1357,7 +1355,7 @@ int matroska_segment_c::BlockGet( KaxBlock * & pp_block, KaxSimpleBlock * & pp_s
         if( pp_simpleblock != NULL || ((el = ep->Get()) == NULL && pp_block != NULL) )
         {
             /* Check blocks validity to protect againts broken files */
-            if( BlockFindTrackIndex( &i_tk, pp_block , pp_simpleblock ) )
+            if( FindTrackByBlock( &track_it, pp_block , pp_simpleblock ) )
             {
                 ep->Unkeep();
                 pp_simpleblock = NULL;
diff --git a/modules/demux/mkv/matroska_segment.hpp b/modules/demux/mkv/matroska_segment.hpp
index 14498b7..d596cb3 100644
--- a/modules/demux/mkv/matroska_segment.hpp
+++ b/modules/demux/mkv/matroska_segment.hpp
@@ -137,10 +137,9 @@ public:
     void Seek( mtime_t i_mk_date, mtime_t i_mk_time_offset );
     int BlockGet( KaxBlock * &, KaxSimpleBlock * &, bool *, bool *, int64_t *);
 
-    int BlockFindTrackIndex( size_t *pi_track,
-                             const KaxBlock *, const KaxSimpleBlock * );
 
 
+    int FindTrackByBlock(tracks_map_t::iterator* track_it, const KaxBlock *, const KaxSimpleBlock * );
 
     bool ESCreate( );
     void ESDestroy( );
-- 
2.8.2



More information about the vlc-devel mailing list