[vlc-devel] [PATCH 05/10] demux:mkv: don't look for the upper seekpoint when we only want the lower one

Steve Lhomme robux4 at videolabs.io
Thu Aug 3 18:18:30 CEST 2017


---
 modules/demux/mkv/matroska_segment_seeker.cpp | 30 ++++++++++++++++++++++++++-
 modules/demux/mkv/matroska_segment_seeker.hpp |  1 +
 2 files changed, 30 insertions(+), 1 deletion(-)

diff --git a/modules/demux/mkv/matroska_segment_seeker.cpp b/modules/demux/mkv/matroska_segment_seeker.cpp
index 6ac257ce86..55b303d424 100644
--- a/modules/demux/mkv/matroska_segment_seeker.cpp
+++ b/modules/demux/mkv/matroska_segment_seeker.cpp
@@ -136,7 +136,7 @@ SegmentSeeker::find_greatest_seekpoints_in_range( fptr_t start_fpos, mtime_t end
 
     for( tracks_seekpoints_t::const_iterator it = _tracks_seekpoints.begin(); it != _tracks_seekpoints.end(); ++it )
     {
-        Seekpoint sp = get_seekpoints_around( end_pts, it->second, Seekpoint::TRUSTED ).first;
+        Seekpoint sp = get_first_seekpoint_around( end_pts, it->second );
 
         if( sp.fpos < start_fpos )
             continue;
@@ -150,6 +150,34 @@ SegmentSeeker::find_greatest_seekpoints_in_range( fptr_t start_fpos, mtime_t end
     return tpoints;
 }
 
+SegmentSeeker::Seekpoint
+SegmentSeeker::get_first_seekpoint_around( mtime_t pts, seekpoints_t const& seekpoints,
+                                           Seekpoint::TrustLevel trust_level )
+{
+    if( seekpoints.empty() )
+    {
+        return Seekpoint();
+    }
+
+    typedef seekpoints_t::const_iterator iterator;
+
+    Seekpoint const needle ( Seekpoint::DISABLED, std::numeric_limits<fptr_t>::max(), pts );
+
+    iterator const it_begin  = seekpoints.begin();
+    iterator const it_end    = seekpoints.end();
+    iterator const it_middle = greatest_lower_bound( it_begin, it_end, needle );
+
+    iterator it_before;
+
+    // rewrind to _previous_ seekpoint with appropriate trust
+    for( it_before = it_middle; it_before != it_begin; --it_before )
+    {
+        if( it_before->trust_level >= trust_level )
+            return *it_before;
+    }
+    return *it_begin;
+}
+
 SegmentSeeker::seekpoint_pair_t
 SegmentSeeker::get_seekpoints_around( mtime_t pts, seekpoints_t const& seekpoints,
                                       Seekpoint::TrustLevel trust_level )
diff --git a/modules/demux/mkv/matroska_segment_seeker.hpp b/modules/demux/mkv/matroska_segment_seeker.hpp
index 4eb9fc255a..6af3f51d9a 100644
--- a/modules/demux/mkv/matroska_segment_seeker.hpp
+++ b/modules/demux/mkv/matroska_segment_seeker.hpp
@@ -102,6 +102,7 @@ class SegmentSeeker
         void add_seekpoint( track_id_t track_id, Seekpoint::TrustLevel level, fptr_t fpos, mtime_t pts );
 
         seekpoint_pair_t get_seekpoints_around( mtime_t, seekpoints_t const&, Seekpoint::TrustLevel = Seekpoint::DISABLED );
+        Seekpoint get_first_seekpoint_around( mtime_t, seekpoints_t const&, Seekpoint::TrustLevel = Seekpoint::TRUSTED );
         seekpoint_pair_t get_seekpoints_around( mtime_t, track_ids_t const& );
 
         tracks_seekpoint_t get_seekpoints( matroska_segment_c&, mtime_t, track_ids_t const& );
-- 
2.13.0



More information about the vlc-devel mailing list