[vlc-devel] [PATCH 3/4] demux: mkv: add a version of the demuxer that trust Cues

Steve Lhomme robux4 at ycbcr.xyz
Fri Oct 2 13:19:37 CEST 2020


It can only be loaded with the proper name, it is not automatically loaded.

It is necessary to know when opening the module because we start parsing the
Matroska data to find the mandatory headers and the Cues may be parsed during
that time.
---
 modules/demux/mkv/demux.hpp            |  5 ++++-
 modules/demux/mkv/matroska_segment.cpp |  4 +++-
 modules/demux/mkv/mkv.cpp              | 23 ++++++++++++++++++++---
 3 files changed, 27 insertions(+), 5 deletions(-)

diff --git a/modules/demux/mkv/demux.hpp b/modules/demux/mkv/demux.hpp
index e6842790713..e5d53596e4a 100644
--- a/modules/demux/mkv/demux.hpp
+++ b/modules/demux/mkv/demux.hpp
@@ -39,7 +39,7 @@ class chapter_item_c;
 struct demux_sys_t
 {
 public:
-    demux_sys_t( demux_t & demux )
+    demux_sys_t( demux_t & demux, bool trust_cues )
         :demuxer(demux)
         ,b_seekable(false)
         ,b_fastseekable(false)
@@ -54,6 +54,7 @@ public:
         ,p_current_vsegment(NULL)
         ,dvd_interpretor( *this )
         ,i_duration(-1)
+        ,trust_cues(trust_cues)
         ,ev(&demux)
     {
         vlc_mutex_init( &lock_demuxer );
@@ -89,6 +90,8 @@ public:
     /* duration of the stream */
     vlc_tick_t              i_duration;
 
+    const bool              trust_cues;
+
     matroska_segment_c *FindSegment( const EbmlBinary & uid ) const;
     virtual_chapter_c *BrowseCodecPrivate( unsigned int codec_id,
                                         bool (*match)(const chapter_codec_cmds_c &data, const void *p_cookie, size_t i_cookie_size ),
diff --git a/modules/demux/mkv/matroska_segment.cpp b/modules/demux/mkv/matroska_segment.cpp
index 57cc84c8160..da5473f5760 100644
--- a/modules/demux/mkv/matroska_segment.cpp
+++ b/modules/demux/mkv/matroska_segment.cpp
@@ -216,7 +216,9 @@ void matroska_segment_c::LoadCues( KaxCues *cues )
 
                 if( ! b_invalid_cue && tracks.find( track_id ) != tracks.end() )
                 {
-                    level = SegmentSeeker::Seekpoint::QUESTIONABLE; // TODO: var_InheritBool( ..., "mkv-trust-cues" );
+                    level = sys.trust_cues ?
+                            SegmentSeeker::Seekpoint::TRUSTED :
+                            SegmentSeeker::Seekpoint::QUESTIONABLE;
                 }
 
                 _seeker.add_seekpoint( track_id,
diff --git a/modules/demux/mkv/mkv.cpp b/modules/demux/mkv/mkv.cpp
index 4685968f2bc..bcbc0c61366 100644
--- a/modules/demux/mkv/mkv.cpp
+++ b/modules/demux/mkv/mkv.cpp
@@ -44,6 +44,7 @@ extern "C" {
  *****************************************************************************/
 namespace mkv {
 static int  Open ( vlc_object_t * );
+static int  OpenTrusted ( vlc_object_t * );
 static void Close( vlc_object_t * );
 } // namespace
 
@@ -81,6 +82,11 @@ vlc_module_begin ()
             N_("Find all cluster positions by jumping cluster-to-cluster before playback"), true );
 
     add_shortcut( "mka", "mkv" )
+
+    add_submodule()
+        set_callbacks( OpenTrusted, Close )
+        set_capability( "demux", 0 )
+        add_shortcut( "mka_trusted", "mkv_trusted" )
 vlc_module_end ()
 
 namespace mkv {
@@ -94,9 +100,8 @@ static int  Seek   ( demux_t *, vlc_tick_t i_mk_date, double f_percent, virtual_
 /*****************************************************************************
  * Open: initializes matroska demux structures
  *****************************************************************************/
-static int Open( vlc_object_t * p_this )
+static int OpenInternal( demux_t *p_demux, bool trust_cues )
 {
-    demux_t            *p_demux = (demux_t*)p_this;
     demux_sys_t        *p_sys;
     matroska_stream_c  *p_stream;
     matroska_segment_c *p_segment;
@@ -114,7 +119,7 @@ static int Open( vlc_object_t * p_this )
     /* Set the demux function */
     p_demux->pf_demux   = Demux;
     p_demux->pf_control = Control;
-    p_demux->p_sys      = p_sys = new demux_sys_t( *p_demux );
+    p_demux->p_sys      = p_sys = new demux_sys_t( *p_demux, trust_cues );
 
     vlc_stream_Control( p_demux->s, STREAM_CAN_SEEK, &p_sys->b_seekable );
     if ( !p_sys->b_seekable || vlc_stream_Control(
@@ -267,6 +272,18 @@ error:
     return VLC_EGENERIC;
 }
 
+static int Open( vlc_object_t *p_this )
+{
+    demux_t *p_demux = (demux_t*)p_this;
+    return OpenInternal( p_demux, false );
+}
+
+static int OpenTrusted( vlc_object_t *p_this )
+{
+    demux_t *p_demux = (demux_t*)p_this;
+    return OpenInternal( p_demux, true );
+}
+
 /*****************************************************************************
  * Close: frees unused data
  *****************************************************************************/
-- 
2.26.2



More information about the vlc-devel mailing list