demux:mkv: get the track directly from FindTrackByBlock
authorSteve Lhomme <robUx4@videolabs.io>
Wed, 2 Aug 2017 15:07:26 +0000 (17:07 +0200)
committerJean-Baptiste Kempf <jb@videolan.org>
Wed, 2 Aug 2017 15:54:48 +0000 (17:54 +0200)
And use const is places where the track is not modified.

Signed-off-by: Jean-Baptiste Kempf <jb@videolan.org>
modules/demux/mkv/matroska_segment.cpp
modules/demux/mkv/matroska_segment.hpp
modules/demux/mkv/matroska_segment_seeker.cpp
modules/demux/mkv/mkv.cpp

index 664a868..69522f3 100644 (file)
@@ -870,24 +870,22 @@ bool matroska_segment_c::Seek( mtime_t i_absolute_mk_date, mtime_t i_mk_time_off
 }
 
 
-int matroska_segment_c::FindTrackByBlock(tracks_map_t::iterator* p_track_it,
+mkv_track_t * matroska_segment_c::FindTrackByBlock(
                                              const KaxBlock *p_block, const KaxSimpleBlock *p_simpleblock )
 {
-    *p_track_it = tracks.end();
-
-    if( p_block == NULL && p_simpleblock == NULL )
-        return VLC_EGENERIC;
+    tracks_map_t::iterator track_it;
 
     if (p_block != NULL)
-    {
-        *p_track_it = tracks.find( p_block->TrackNum() );
-    }
+        track_it = tracks.find( p_block->TrackNum() );
     else if( p_simpleblock != NULL)
-    {
-        *p_track_it = tracks.find( p_simpleblock->TrackNum() );
-    }
+        track_it = tracks.find( p_simpleblock->TrackNum() );
+    else
+        track_it = tracks.end();
+
+    if (track_it == tracks.end())
+        return NULL;
 
-    return *p_track_it != tracks.end() ? VLC_SUCCESS : VLC_EGENERIC;
+    return track_it->second.get();
 }
 
 void matroska_segment_c::ComputeTrackPriority()
@@ -1124,8 +1122,6 @@ void matroska_segment_c::ESDestroy( )
 
 int matroska_segment_c::BlockGet( KaxBlock * & pp_block, KaxSimpleBlock * & pp_simpleblock, bool *pb_key_picture, bool *pb_discardable_picture, int64_t *pi_duration )
 {
-    tracks_map_t::iterator track_it;
-
     pp_simpleblock = NULL;
     pp_block = NULL;
 
@@ -1208,8 +1204,7 @@ int matroska_segment_c::BlockGet( KaxBlock * & pp_block, KaxSimpleBlock * & pp_s
 
             if( ksblock.IsKeyframe() )
             {
-                tracks_map_t::iterator track_it;
-                bool const b_valid_track = !vars.obj->FindTrackByBlock( &track_it, NULL, &ksblock );
+                bool const b_valid_track = vars.obj->FindTrackByBlock( NULL, &ksblock ) != NULL;
                 if (b_valid_track)
                     vars.obj->_seeker.add_seekpoint( ksblock.TrackNum(), SegmentSeeker::Seekpoint::TRUSTED, ksblock.GetElementPosition(), ksblock.GlobalTimecode() / 1000 );
             }
@@ -1226,9 +1221,8 @@ int matroska_segment_c::BlockGet( KaxBlock * & pp_block, KaxSimpleBlock * & pp_s
             vars.block->ReadData( vars.obj->es.I_O() );
             vars.block->SetParent( *vars.obj->cluster );
 
-            tracks_map_t::iterator track_it;
-            bool const b_valid_track = !vars.obj->FindTrackByBlock( &track_it, &kblock, NULL );
-            if( b_valid_track && track_it->second->fmt.i_cat == SPU_ES )
+            const mkv_track_t *p_track = vars.obj->FindTrackByBlock( &kblock, NULL );
+            if( p_track != NULL && p_track->fmt.i_cat == SPU_ES )
             {
                 vars.obj->_seeker.add_seekpoint( kblock.TrackNum(), SegmentSeeker::Seekpoint::TRUSTED, kblock.GetElementPosition(), kblock.GlobalTimecode() / 1000 );
             }
@@ -1292,7 +1286,8 @@ 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( FindTrackByBlock( &track_it, pp_block , pp_simpleblock ) )
+            const mkv_track_t *p_track = FindTrackByBlock( pp_block , pp_simpleblock );
+            if( p_track == NULL )
             {
                 ep->Unkeep();
                 pp_simpleblock = NULL;
@@ -1307,7 +1302,7 @@ int matroska_segment_c::BlockGet( KaxBlock * & pp_block, KaxSimpleBlock * & pp_s
             /* We have block group let's check if the picture is a keyframe */
             else if( *pb_key_picture )
             {
-                if( track_it->second->fmt.i_codec == VLC_CODEC_THEORA )
+                if( p_track->fmt.i_codec == VLC_CODEC_THEORA )
                 {
                     DataBuffer *    p_data = &pp_block->GetBuffer(0);
                     const uint8_t * p_buff = p_data->Buffer();
index cd36f1c..65b8681 100644 (file)
@@ -144,7 +144,7 @@ public:
 
     int BlockGet( KaxBlock * &, KaxSimpleBlock * &, bool *, bool *, int64_t *);
 
-    int FindTrackByBlock(tracks_map_t::iterator* track_it, const KaxBlock *, const KaxSimpleBlock * );
+    mkv_track_t * FindTrackByBlock(const KaxBlock *, const KaxSimpleBlock * );
 
     bool ESCreate( );
     void ESDestroy( );
index a3ea921..928c33a 100644 (file)
@@ -312,7 +312,6 @@ SegmentSeeker::index_unsearched_range( matroska_segment_c& ms, Range search_area
         bool     b_discardable_picture;
         int64_t  i_block_duration;
         track_id_t track_id;
-        matroska_segment_c::tracks_map_t::iterator i_track = ms.tracks.end();
 
         if( ms.BlockGet( block, simpleblock, &b_key_picture, &b_discardable_picture, &i_block_duration ) )
             break;
@@ -328,7 +327,7 @@ SegmentSeeker::index_unsearched_range( matroska_segment_c& ms, Range search_area
             track_id  = block->TrackNum();
         }
 
-        bool const b_valid_track = !ms.FindTrackByBlock( &i_track, block, simpleblock );
+        bool const b_valid_track = ms.FindTrackByBlock( block, simpleblock ) != NULL;
 
         delete block;
 
index 6cdef12..544f425 100644 (file)
@@ -496,22 +496,19 @@ void BlockDecode( demux_t *p_demux, KaxBlock *block, KaxSimpleBlock *simpleblock
                   mtime_t i_pts, mtime_t i_duration, bool b_key_picture,
                   bool b_discardable_picture )
 {
-    typedef matroska_segment_c::tracks_map_t tracks_map_t;
-
     demux_sys_t        *p_sys = p_demux->p_sys;
     matroska_segment_c *p_segment = p_sys->p_current_vsegment->CurrentSegment();
 
     if( !p_segment ) return;
 
-    tracks_map_t::iterator track_it;
-
-    if( p_segment->FindTrackByBlock( &track_it, block, simpleblock ) )
+    mkv_track_t *p_track = p_segment->FindTrackByBlock( block, simpleblock );
+    if( p_track == NULL )
     {
         msg_Err( p_demux, "invalid track number" );
         return;
     }
 
-    mkv_track_t &track = *track_it->second;
+    mkv_track_t &track = *p_track;
 
     if( track.fmt.i_cat != NAV_ES && track.p_es == NULL )
     {
@@ -717,16 +714,16 @@ static int Demux( demux_t *p_demux)
     }
 
     {
-        matroska_segment_c::tracks_map_t::iterator track_it;
+        mkv_track_t *p_track = p_segment->FindTrackByBlock( block, simpleblock );
 
-        if( p_segment->FindTrackByBlock( &track_it, block, simpleblock ) )
+        if( p_track == NULL )
         {
             msg_Err( p_demux, "invalid track number" );
             delete block;
             return 0;
         }
 
-        mkv_track_t &track = *track_it->second;
+        mkv_track_t &track = *p_track;
 
 
         if( track.i_skip_until_fpos != std::numeric_limits<uint64_t>::max() ) {