[vlc-commits] [Git][videolan/vlc][master] 2 commits: demux: mkv: create only one instance of matroska script interpreter

Steve Lhomme (@robUx4) gitlab at videolan.org
Mon Jul 22 07:00:34 UTC 2024



Steve Lhomme pushed to branch master at VideoLAN / VLC


Commits:
ee7b4cc2 by Khalid Masum at 2024-07-22T06:14:25+00:00
demux: mkv: create only one instance of matroska script interpreter

- - - - -
199a534a by Khalid Masum at 2024-07-22T06:14:25+00:00
demux: mkv: create necessary classes for more codecs

- - - - -


9 changed files:

- modules/demux/Makefile.am
- modules/demux/meson.build
- modules/demux/mkv/chapter_command.hpp
- modules/demux/mkv/chapter_command_script.cpp
- modules/demux/mkv/chapter_command_script.hpp
- + modules/demux/mkv/chapter_command_script_common.cpp
- + modules/demux/mkv/chapter_command_script_common.hpp
- modules/demux/mkv/demux.hpp
- modules/demux/mkv/matroska_segment_parse.cpp


Changes:

=====================================
modules/demux/Makefile.am
=====================================
@@ -198,6 +198,7 @@ libmkv_plugin_la_SOURCES = \
 	demux/mkv/chapter_command.hpp demux/mkv/chapter_command.cpp \
 	demux/mkv/chapter_command_dvd.hpp demux/mkv/chapter_command_dvd.cpp \
 	demux/mkv/chapter_command_script.hpp demux/mkv/chapter_command_script.cpp \
+	demux/mkv/chapter_command_script_common.hpp demux/mkv/chapter_command_script_common.cpp \
 	demux/mkv/stream_io_callback.hpp demux/mkv/stream_io_callback.cpp \
 	demux/mkv/vlc_colors.c demux/mkv/vlc_colors.h \
 	demux/vobsub.h \


=====================================
modules/demux/meson.build
=====================================
@@ -275,6 +275,7 @@ if libebml_dep.found() and libmatroska_dep.found()
             'mkv/chapter_command.cpp',
             'mkv/chapter_command_dvd.cpp',
             'mkv/chapter_command_script.cpp',
+            'mkv/chapter_command_script_common.cpp',
             'mkv/stream_io_callback.cpp',
             'mkv/vlc_colors.c',
             'mp4/libmp4.c',


=====================================
modules/demux/mkv/chapter_command.hpp
=====================================
@@ -89,7 +89,6 @@ protected:
     struct vlc_logger *l;
     chapter_codec_vm & vm;
 };
-
 } // namespace
 
 #endif


=====================================
modules/demux/mkv/chapter_command_script.cpp
=====================================
@@ -1,7 +1,7 @@
 // Copyright (C) 2003-2024 VLC authors and VideoLAN
 // SPDX-License-Identifier: LGPL-2.1-or-later
 //
-// chapter_command_script.cpp : DVD codec for Matroska Chapter Codecs
+// chapter_command_script.cpp : Matroska Script Codec for Matroska Chapter Codecs
 // Authors: Laurent Aimar <fenrir at via.ecp.fr>
 //          Steve Lhomme <steve.lhomme at free.fr>
 
@@ -11,6 +11,7 @@
 
 namespace mkv {
 
+//Matroska Script
 const std::string matroska_script_interpretor_c::CMD_MS_GOTO_AND_PLAY = "GotoAndPlay";
 
 // see http://www.matroska.org/technical/specs/chapters/index.html#mscript
@@ -65,36 +66,4 @@ bool matroska_script_interpretor_c::Interpret( const binary * p_command, size_t
     return b_result;
 }
 
-bool matroska_script_codec_c::Enter()
-{
-    bool f_result = false;
-    ChapterProcess::iterator index = enter_cmds.begin();
-    while ( index != enter_cmds.end() )
-    {
-        if ( (*index).GetSize() )
-        {
-            vlc_debug( l, "Matroska Script enter command" );
-            f_result |= interpreter.Interpret( (*index).GetBuffer(), (*index).GetSize() );
-        }
-        ++index;
-    }
-    return f_result;
-}
-
-bool matroska_script_codec_c::Leave()
-{
-    bool f_result = false;
-    ChapterProcess::iterator index = leave_cmds.begin();
-    while ( index != leave_cmds.end() )
-    {
-        if ( (*index).GetSize() )
-        {
-            vlc_debug( l, "Matroska Script leave command" );
-            f_result |= interpreter.Interpret( (*index).GetBuffer(), (*index).GetSize() );
-        }
-        ++index;
-    }
-    return f_result;
-}
-
 } // namespace


=====================================
modules/demux/mkv/chapter_command_script.hpp
=====================================
@@ -8,42 +8,39 @@
 #ifndef VLC_MKV_CHAPTER_COMMAND_SCRIPT_HPP_
 #define VLC_MKV_CHAPTER_COMMAND_SCRIPT_HPP_
 
-#include "chapter_command.hpp"
+#include "chapter_command_script_common.hpp"
 
 namespace mkv {
 
-class matroska_script_interpretor_c
+class matroska_script_interpretor_c : public matroska_script_interpreter_common_c
 {
 public:
     matroska_script_interpretor_c( struct vlc_logger *log, chapter_codec_vm & vm_ )
-    :l( log )
-    ,vm( vm_ )
+    :matroska_script_interpreter_common_c(log, vm_)
     {}
 
-    bool Interpret( const binary * p_command, size_t i_size );
+    bool Interpret( const binary * p_command, size_t i_size ) override;
 
-    // DVD command IDs
+    // Matroska Script commands
     static const std::string CMD_MS_GOTO_AND_PLAY;
 
-protected:
-    struct vlc_logger *l;
-    chapter_codec_vm & vm;
 };
 
-
-class matroska_script_codec_c : public chapter_codec_cmds_c
+class matroska_script_codec_c : public matroska_script_codec_common_c
 {
 public:
-    matroska_script_codec_c( struct vlc_logger *log, chapter_codec_vm & vm_ )
-    :chapter_codec_cmds_c( log, vm_, MATROSKA_CHAPTER_CODEC_NATIVE )
-    ,interpreter( log, vm_ )
+    matroska_script_codec_c( struct vlc_logger *log, chapter_codec_vm & vm_, matroska_script_interpretor_c & interpreter_)
+    :matroska_script_codec_common_c( log, vm_, MATROSKA_CHAPTER_CODEC_NATIVE )
+    ,interpreter( interpreter_ )
     {}
 
-    bool Enter();
-    bool Leave();
+    matroska_script_interpreter_common_c & get_interpreter() override
+    {
+        return interpreter;
+    }
 
 protected:
-    matroska_script_interpretor_c interpreter;
+    matroska_script_interpretor_c & interpreter;
 };
 
 } // namespace


=====================================
modules/demux/mkv/chapter_command_script_common.cpp
=====================================
@@ -0,0 +1,47 @@
+// Copyright (C) 2024 VLC authors and VideoLAN
+// SPDX-License-Identifier: LGPL-2.1-or-later
+//
+// chapter_command_script_common.cpp : 
+// Common file for Matroska JS and Matroska Script
+// Authors: Laurent Aimar <fenrir at via.ecp.fr>
+//          Steve Lhomme <steve.lhomme at free.fr>
+//          Khalid Masum <khalid.masum.92 at gmail.com>
+
+
+#include "chapter_command_script_common.hpp"
+
+namespace mkv {
+
+bool matroska_script_codec_common_c::Enter()
+{
+    bool f_result = false;
+    ChapterProcess::iterator index = enter_cmds.begin();
+    while ( index != enter_cmds.end() )
+    {
+        if ( (*index).GetSize() )
+        {
+            vlc_debug( l, "Matroska Script enter command" );
+            f_result |= get_interpreter().Interpret( (*index).GetBuffer(), (*index).GetSize() );
+        }
+        ++index;
+    }
+    return f_result;
+}
+
+bool matroska_script_codec_common_c::Leave()
+{
+    bool f_result = false;
+    ChapterProcess::iterator index = leave_cmds.begin();
+    while ( index != leave_cmds.end() )
+    {
+        if ( (*index).GetSize() )
+        {
+            vlc_debug( l, "Matroska Script leave command" );
+            f_result |= get_interpreter().Interpret( (*index).GetBuffer(), (*index).GetSize() );
+        }
+        ++index;
+    }
+    return f_result;
+}
+
+} // namespace


=====================================
modules/demux/mkv/chapter_command_script_common.hpp
=====================================
@@ -0,0 +1,49 @@
+// Copyright (C) 2003-2024 VLC authors and VideoLAN
+// SPDX-License-Identifier: LGPL-2.1-or-later
+//
+// chapter_command_script.hpp : MatroskaScript codec for Matroska Chapter Codecs
+// Authors: Laurent Aimar <fenrir at via.ecp.fr>
+//          Steve Lhomme <steve.lhomme at free.fr>
+
+#ifndef VLC_MKV_CHAPTER_COMMAND_SCRIPT_COMMON_HPP_
+#define VLC_MKV_CHAPTER_COMMAND_SCRIPT_COMMON_HPP_
+
+#include "chapter_command.hpp"
+
+namespace mkv {
+
+class matroska_script_interpreter_common_c
+{
+public:
+    matroska_script_interpreter_common_c( struct vlc_logger *log, chapter_codec_vm & vm_ )
+    :l( log )
+    ,vm( vm_ )
+    {}
+
+    virtual ~matroska_script_interpreter_common_c() = default;
+
+    // DVD command IDs
+    virtual bool Interpret( const binary * p_command, size_t i_size ) = 0;
+
+protected:
+    struct vlc_logger *l;
+    chapter_codec_vm & vm;
+};
+
+class matroska_script_codec_common_c : public chapter_codec_cmds_c
+{
+public:
+
+    matroska_script_codec_common_c( struct vlc_logger *log, chapter_codec_vm &vm_, enum chapter_codec_id codec_id)
+    :chapter_codec_cmds_c(log, vm_, codec_id)
+    {}
+
+    bool Enter();
+    bool Leave();
+
+    virtual matroska_script_interpreter_common_c & get_interpreter()=0;
+};
+
+} // namespace
+
+#endif // VLC_MKV_CHAPTER_COMMAND_SCRIPT_HPP_


=====================================
modules/demux/mkv/demux.hpp
=====================================
@@ -28,6 +28,7 @@
 
 #include "chapter_command.hpp"
 #include "chapter_command_dvd.hpp"
+#include "chapter_command_script.hpp"
 #include "events.hpp"
 
 #include <memory>
@@ -123,6 +124,19 @@ public:
         return dvd_interpretor.get();
     }
 
+    matroska_script_interpretor_c * GetMatroskaScriptInterpreter()
+    {
+        if (!ms_interpreter)
+        {
+            try {
+                ms_interpreter = std::make_unique<matroska_script_interpretor_c> ( vlc_object_logger( &demuxer ), *this );
+            } catch ( const std::bad_alloc & ) {
+            }
+        }
+
+        return ms_interpreter.get();
+    }
+
     uint8_t        palette[4][4];
     vlc_mutex_t    lock_demuxer;
 
@@ -132,6 +146,7 @@ public:
 private:
     virtual_segment_c                *p_current_vsegment = nullptr;
     std::unique_ptr<dvd_command_interpretor_c> dvd_interpretor; // protected by lock_demuxer
+    std::unique_ptr<matroska_script_interpretor_c> ms_interpreter;
 };
 
 } // namespace


=====================================
modules/demux/mkv/matroska_segment_parse.cpp
=====================================
@@ -1442,7 +1442,16 @@ void matroska_segment_c::ParseChapterAtom( int i_level, KaxChapterAtom *ca, chap
                 if( MKV_CHECKED_PTR_DECL_CONST( p_codec_id, KaxChapterProcessCodecID, proc ) )
                 {
                     if ( p_codec_id->GetValue() == MATROSKA_CHAPTER_CODEC_NATIVE )
-                        p_ccodec = new matroska_script_codec_c( vlc_object_logger( &vars.obj->sys.demuxer ), vars.obj->sys );
+                    {
+                       auto interpreter = vars.obj->sys.GetMatroskaScriptInterpreter();
+                       if (unlikely(interpreter == nullptr))
+                            debug( vars, "failed to get the Matroska Script interpreter ");
+                       else
+                            p_ccodec = new matroska_script_codec_c(
+                            vlc_object_logger( &vars.obj->sys.demuxer ),
+                            vars.obj->sys, *interpreter
+                            );
+                    }
                     else if ( p_codec_id->GetValue() == MATROSKA_CHAPTER_CODEC_DVD )
                     {
                         auto interepreter = vars.obj->sys.GetDVDInterpretor();



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/dfc421a56b93ce980982a9a0bc6faada2610cb9e...199a534a28f9c84c05724993c47c6097ffed955d

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/dfc421a56b93ce980982a9a0bc6faada2610cb9e...199a534a28f9c84c05724993c47c6097ffed955d
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list