[vlc-commits] [Git][videolan/vlc][master] 6 commits: demux: mkv: only create the DVD interpretor when we need it
Steve Lhomme (@robUx4)
gitlab at videolan.org
Wed Jul 3 07:41:05 UTC 2024
Steve Lhomme pushed to branch master at VideoLAN / VLC
Commits:
dbe0de90 by Steve Lhomme at 2024-07-03T07:27:24+00:00
demux: mkv: only create the DVD interpretor when we need it
99.9999% of the time we won't need it.
- - - - -
c0d0e045 by Steve Lhomme at 2024-07-03T07:27:24+00:00
demux: mkv: use cbegin/cend to navigate chapter codecs
- - - - -
8924fff9 by Steve Lhomme at 2024-07-03T07:27:24+00:00
demux: mkv: pass the Chapter Codec ID as an enum value
This allows stronger typing and easier debugging.
- - - - -
f721aa88 by Steve Lhomme at 2024-07-03T07:27:24+00:00
demux: mkv: compare chapter codec ID valus using the enum
- - - - -
887c29f5 by Steve Lhomme at 2024-07-03T07:27:24+00:00
demux: mkv: keep the Chapter Codec ID as an enum
- - - - -
2c6d9de9 by Steve Lhomme at 2024-07-03T07:27:24+00:00
demux: mkv: only parse codec private for the matching Chapter Codec ID
- - - - -
11 changed files:
- modules/demux/mkv/chapter_command.cpp
- modules/demux/mkv/chapter_command.hpp
- modules/demux/mkv/chapters.cpp
- modules/demux/mkv/chapters.hpp
- modules/demux/mkv/demux.cpp
- modules/demux/mkv/demux.hpp
- modules/demux/mkv/events.cpp
- modules/demux/mkv/matroska_segment_parse.cpp
- modules/demux/mkv/mkv.hpp
- modules/demux/mkv/virtual_segment.cpp
- modules/demux/mkv/virtual_segment.hpp
Changes:
=====================================
modules/demux/mkv/chapter_command.cpp
=====================================
@@ -91,7 +91,7 @@ bool dvd_chapter_codec_c::EnterLeaveHelper( char const * str_diag, std::vector<K
for( ; i_size > 0; i_size -=1, p_data += 8 )
{
msg_Dbg( &sys.demuxer, "%s", str_diag);
- f_result |= sys.dvd_interpretor.Interpret( p_data );
+ f_result |= sys.GetDVDInterpretor().Interpret( p_data );
}
}
++it;
@@ -285,7 +285,7 @@ bool dvd_command_interpretor_c::Interpret( const binary * p_command, size_t i_si
msg_Dbg( &sys.demuxer, "JumpTT %d", i_title );
// find in the ChapProcessPrivate matching this Title level
- p_vchapter = sys.BrowseCodecPrivate( 1, MatchTitleNumber, &i_title, sizeof(i_title), p_vsegment );
+ p_vchapter = sys.BrowseCodecPrivate( MATROSKA_CHAPTER_CODEC_DVD, MatchTitleNumber, &i_title, sizeof(i_title), p_vsegment );
if ( p_vsegment != NULL && p_vchapter != NULL )
{
/* enter via the First Cell */
@@ -334,7 +334,7 @@ bool dvd_command_interpretor_c::Interpret( const binary * p_command, size_t i_si
msg_Dbg( &sys.demuxer, "CallSS <unknown> (rsm_cell %x)", p_command[4]);
break;
}
- p_vchapter = sys.BrowseCodecPrivate( 1, MatchPgcType, &p_type, 1, p_vsegment );
+ p_vchapter = sys.BrowseCodecPrivate( MATROSKA_CHAPTER_CODEC_DVD, MatchPgcType, &p_type, 1, p_vsegment );
if ( p_vsegment != NULL && p_vchapter != NULL )
{
/* enter via the first Cell */
@@ -394,10 +394,10 @@ bool dvd_command_interpretor_c::Interpret( const binary * p_command, size_t i_si
break;
}
// find the VMG
- p_vchapter = sys.BrowseCodecPrivate( 1, MatchIsVMG, NULL, 0, p_vsegment );
+ p_vchapter = sys.BrowseCodecPrivate( MATROSKA_CHAPTER_CODEC_DVD, MatchIsVMG, NULL, 0, p_vsegment );
if ( p_vsegment != NULL )
{
- p_vchapter = p_vsegment->BrowseCodecPrivate( 1, MatchPgcType, &p_type, 1 );
+ p_vchapter = p_vsegment->BrowseCodecPrivate( MATROSKA_CHAPTER_CODEC_DVD, MatchPgcType, &p_type, 1 );
if ( p_vchapter != NULL )
{
sys.JumpTo( *p_vsegment, *p_vchapter );
@@ -432,16 +432,16 @@ bool dvd_command_interpretor_c::Interpret( const binary * p_command, size_t i_si
break;
}
- p_vchapter = sys.BrowseCodecPrivate( 1, MatchVTSMNumber, &p_command[4], 1, p_vsegment );
+ p_vchapter = sys.BrowseCodecPrivate( MATROSKA_CHAPTER_CODEC_DVD, MatchVTSMNumber, &p_command[4], 1, p_vsegment );
if ( p_vsegment != NULL && p_vchapter != NULL )
{
// find the title in the VTS
- p_vchapter = p_vchapter->BrowseCodecPrivate( 1, MatchTitleNumber, &p_command[3], 1 );
+ p_vchapter = p_vchapter->BrowseCodecPrivate( MATROSKA_CHAPTER_CODEC_DVD, MatchTitleNumber, &p_command[3], 1 );
if ( p_vchapter != NULL )
{
// find the specified menu in the VTSM
- p_vchapter = p_vsegment->BrowseCodecPrivate( 1, MatchPgcType, &p_type, 1 );
+ p_vchapter = p_vsegment->BrowseCodecPrivate( MATROSKA_CHAPTER_CODEC_DVD, MatchPgcType, &p_type, 1 );
if ( p_vchapter != NULL )
{
sys.JumpTo( *p_vsegment, *p_vchapter );
@@ -468,22 +468,22 @@ bool dvd_command_interpretor_c::Interpret( const binary * p_command, size_t i_si
msg_Dbg( &sys.demuxer, "JumpVTS Title (%d) PTT (%d)", i_title, i_ptt);
// find the current VTS content segment
- p_vchapter = sys.p_current_vsegment->BrowseCodecPrivate( 1, MatchIsDomain, NULL, 0 );
+ p_vchapter = sys.p_current_vsegment->BrowseCodecPrivate( MATROSKA_CHAPTER_CODEC_DVD, MatchIsDomain, NULL, 0 );
if ( p_vchapter != NULL )
{
int16_t i_curr_title = ( p_vchapter->p_chapter )? p_vchapter->p_chapter->GetTitleNumber() : 0;
if ( i_curr_title > 0 )
{
- p_vchapter = sys.BrowseCodecPrivate( 1, MatchVTSNumber, &i_curr_title, sizeof(i_curr_title), p_vsegment );
+ p_vchapter = sys.BrowseCodecPrivate( MATROSKA_CHAPTER_CODEC_DVD, MatchVTSNumber, &i_curr_title, sizeof(i_curr_title), p_vsegment );
if ( p_vsegment != NULL && p_vchapter != NULL )
{
// find the title in the VTS
- p_vchapter = p_vchapter->BrowseCodecPrivate( 1, MatchTitleNumber, &i_title, sizeof(i_title) );
+ p_vchapter = p_vchapter->BrowseCodecPrivate( MATROSKA_CHAPTER_CODEC_DVD, MatchTitleNumber, &i_title, sizeof(i_title) );
if ( p_vchapter != NULL )
{
// find the chapter in the title
- p_vchapter = p_vchapter->BrowseCodecPrivate( 1, MatchChapterNumber, &i_ptt, sizeof(i_ptt) );
+ p_vchapter = p_vchapter->BrowseCodecPrivate( MATROSKA_CHAPTER_CODEC_DVD, MatchChapterNumber, &i_ptt, sizeof(i_ptt) );
if ( p_vchapter != NULL )
{
sys.JumpTo( *p_vsegment, *p_vchapter );
@@ -516,7 +516,7 @@ bool dvd_command_interpretor_c::Interpret( const binary * p_command, size_t i_si
uint16_t i_pgcn = (p_command[6] << 8) + p_command[7];
msg_Dbg( &sys.demuxer, "Link PGCN(%d)", i_pgcn );
- p_vchapter = sys.p_current_vsegment->BrowseCodecPrivate( 1, MatchPgcNumber, &i_pgcn, 2 );
+ p_vchapter = sys.p_current_vsegment->BrowseCodecPrivate( MATROSKA_CHAPTER_CODEC_DVD, MatchPgcNumber, &i_pgcn, 2 );
if ( p_vchapter != NULL )
{
sys.JumpTo( *sys.p_current_vsegment, *p_vchapter );
@@ -531,7 +531,7 @@ bool dvd_command_interpretor_c::Interpret( const binary * p_command, size_t i_si
p_vchapter = sys.p_current_vsegment->CurrentChapter();
msg_Dbg( &sys.demuxer, "LinkCN (cell %d)", i_cn );
- p_vchapter = p_vchapter->BrowseCodecPrivate( 1, MatchCellNumber, &i_cn, 1 );
+ p_vchapter = p_vchapter->BrowseCodecPrivate( MATROSKA_CHAPTER_CODEC_DVD, MatchCellNumber, &i_cn, 1 );
if ( p_vchapter != NULL )
{
sys.JumpTo( *sys.p_current_vsegment, *p_vchapter );
=====================================
modules/demux/mkv/chapter_command.hpp
=====================================
@@ -29,9 +29,6 @@
namespace mkv {
-const int MATROSKA_CHAPTER_CODEC_NATIVE = 0x00;
-const int MATROSKA_CHAPTER_CODEC_DVD = 0x01;
-
const binary MATROSKA_DVD_LEVEL_SS = 0x30;
const binary MATROSKA_DVD_LEVEL_LU = 0x2A;
const binary MATROSKA_DVD_LEVEL_TT = 0x28;
@@ -45,9 +42,9 @@ struct demux_sys_t;
class chapter_codec_cmds_c
{
public:
- chapter_codec_cmds_c( demux_sys_t & demuxer, int codec_id = -1)
- :p_private_data(NULL)
- ,i_codec_id( codec_id )
+ chapter_codec_cmds_c( demux_sys_t & demuxer, enum chapter_codec_id codec_id)
+ :i_codec_id( codec_id )
+ ,p_private_data(NULL)
,sys( demuxer )
{}
@@ -72,6 +69,8 @@ public:
virtual std::string GetCodecName( bool ) const { return ""; }
virtual int16_t GetTitleNumber() { return -1; }
+ const enum chapter_codec_id i_codec_id;
+
KaxChapterProcessPrivate *p_private_data;
protected:
@@ -79,7 +78,6 @@ protected:
std::vector<KaxChapterProcessData*> during_cmds;
std::vector<KaxChapterProcessData*> leave_cmds;
- int i_codec_id;
demux_sys_t & sys;
};
@@ -250,7 +248,7 @@ class dvd_chapter_codec_c : public chapter_codec_cmds_c
{
public:
dvd_chapter_codec_c( demux_sys_t & sys )
- :chapter_codec_cmds_c( sys, 1 )
+ :chapter_codec_cmds_c( sys, MATROSKA_CHAPTER_CODEC_DVD )
{}
bool Enter();
@@ -284,7 +282,7 @@ class matroska_script_codec_c : public chapter_codec_cmds_c
{
public:
matroska_script_codec_c( demux_sys_t & sys )
- :chapter_codec_cmds_c( sys, 0 )
+ :chapter_codec_cmds_c( sys, MATROSKA_CHAPTER_CODEC_NATIVE )
,interpreter( sys )
{}
=====================================
modules/demux/mkv/chapters.cpp
=====================================
@@ -38,17 +38,17 @@ chapter_item_c::~chapter_item_c()
vlc_delete_all( sub_chapters );
}
-chapter_item_c *chapter_item_c::BrowseCodecPrivate( unsigned int codec_id,
+chapter_item_c *chapter_item_c::BrowseCodecPrivate( chapter_codec_id codec_id,
bool (*match)(const chapter_codec_cmds_c &data, const void *p_cookie, size_t i_cookie_size ),
const void *p_cookie,
size_t i_cookie_size )
{
- VLC_UNUSED( codec_id );
// this chapter
- std::vector<chapter_codec_cmds_c*>::const_iterator index = codecs.begin();
- while ( index != codecs.end() )
+ auto index = codecs.cbegin();
+ while ( index != codecs.cend() )
{
- if ( match( **index ,p_cookie, i_cookie_size ) )
+ if ( (*index)->i_codec_id == codec_id &&
+ match( **index ,p_cookie, i_cookie_size ) )
return this;
++index;
}
@@ -96,8 +96,8 @@ std::string chapter_item_c::GetCodecName( bool f_for_title ) const
{
std::string result;
- std::vector<chapter_codec_cmds_c*>::const_iterator index = codecs.begin();
- while ( index != codecs.end() )
+ auto index = codecs.cbegin();
+ while ( index != codecs.cend() )
{
result = (*index)->GetCodecName( f_for_title );
if ( !result.empty () )
@@ -112,8 +112,8 @@ int16_t chapter_item_c::GetTitleNumber( ) const
{
int result = -1;
- std::vector<chapter_codec_cmds_c*>::const_iterator index = codecs.begin();
- while ( index != codecs.end() )
+ auto index = codecs.cbegin();
+ while ( index != codecs.cend() )
{
result = (*index)->GetTitleNumber( );
if ( result >= 0 )
=====================================
modules/demux/mkv/chapters.hpp
=====================================
@@ -65,7 +65,7 @@ public:
virtual ~chapter_item_c();
void Append( const chapter_item_c & edition );
chapter_item_c * FindChapter( int64_t i_find_uid );
- virtual chapter_item_c *BrowseCodecPrivate( unsigned int codec_id,
+ virtual chapter_item_c *BrowseCodecPrivate( chapter_codec_id codec_id,
bool (*match)(const chapter_codec_cmds_c &data, const void *p_cookie, size_t i_cookie_size ),
const void *p_cookie,
size_t i_cookie_size );
=====================================
modules/demux/mkv/demux.cpp
=====================================
@@ -323,7 +323,7 @@ matroska_segment_c *demux_sys_t::FindSegment( const EbmlBinary & uid ) const
return NULL;
}
-virtual_chapter_c *demux_sys_t::BrowseCodecPrivate( unsigned int codec_id,
+virtual_chapter_c *demux_sys_t::BrowseCodecPrivate( chapter_codec_id codec_id,
bool (*match)(const chapter_codec_cmds_c &data, const void *p_cookie, size_t i_cookie_size ),
const void *p_cookie,
size_t i_cookie_size,
=====================================
modules/demux/mkv/demux.hpp
=====================================
@@ -56,7 +56,6 @@ public:
,i_current_seekpoint(0)
,i_updates(0)
,p_current_vsegment(NULL)
- ,dvd_interpretor( *this )
,i_duration(-1)
,trust_cues(trust_cues)
,ev(&demux)
@@ -90,15 +89,13 @@ public:
std::vector<virtual_segment_c*> used_vsegments;
virtual_segment_c *p_current_vsegment;
- dvd_command_interpretor_c dvd_interpretor;
-
/* 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,
+ virtual_chapter_c *BrowseCodecPrivate( chapter_codec_id codec_id,
bool (*match)(const chapter_codec_cmds_c &data, const void *p_cookie, size_t i_cookie_size ),
const void *p_cookie,
size_t i_cookie_size,
@@ -112,11 +109,24 @@ public:
bool AnalyseAllSegmentsFound( demux_t *p_demux, matroska_stream_c * );
void JumpTo( virtual_segment_c & vsegment, virtual_chapter_c & vchapter );
+ dvd_command_interpretor_c & GetDVDInterpretor()
+ {
+ if (!dvd_interpretor)
+ {
+ dvd_interpretor = std::make_unique<dvd_command_interpretor_c>( *this );
+ assert(dvd_interpretor);
+ }
+ return *dvd_interpretor;
+ }
+
uint8_t palette[4][4];
vlc_mutex_t lock_demuxer;
/* event */
event_thread_t ev;
+
+private:
+ std::unique_ptr<dvd_command_interpretor_c> dvd_interpretor;
};
} // namespace
=====================================
modules/demux/mkv/events.cpp
=====================================
@@ -172,7 +172,7 @@ void event_thread_t::ProcessNavAction( uint16_t button, pci_t* pci )
if( button <= 0 || button > pci->hli.hl_gi.btn_ns )
return;
- p_sys->dvd_interpretor.SetSPRM( 0x88, button );
+ p_sys->GetDVDInterpretor().SetSPRM( 0x88, button );
btni_t button_ptr = pci->hli.btnit[button-1];
if ( button_ptr.auto_action_mode )
{
@@ -180,7 +180,7 @@ void event_thread_t::ProcessNavAction( uint16_t button, pci_t* pci )
vlc_mutex_lock( &p_sys->lock_demuxer );
// process the button action
- p_sys->dvd_interpretor.Interpret( button_ptr.cmd.bytes, 8 );
+ p_sys->GetDVDInterpretor().Interpret( button_ptr.cmd.bytes, 8 );
vlc_mutex_unlock( &p_sys->lock_demuxer );
vlc_mutex_lock( &lock );
@@ -194,7 +194,7 @@ void event_thread_t::HandleKeyEvent( EventInfo const& ev )
demux_sys_t* p_sys = (demux_sys_t*)p_demux->p_sys;
pci_t *pci = &pci_packet;
- uint16_t i_curr_button = p_sys->dvd_interpretor.GetSPRM( 0x88 );
+ uint16_t i_curr_button = p_sys->GetDVDInterpretor().GetSPRM( 0x88 );
if( i_curr_button <= 0 || i_curr_button > pci->hli.hl_gi.btn_ns )
return;
@@ -213,7 +213,7 @@ void event_thread_t::HandleKeyEvent( EventInfo const& ev )
vlc_mutex_lock( &p_sys->lock_demuxer );
// process the button action
- p_sys->dvd_interpretor.Interpret( button_ptr.cmd.bytes, 8 );
+ p_sys->GetDVDInterpretor().Interpret( button_ptr.cmd.bytes, 8 );
vlc_mutex_unlock( &p_sys->lock_demuxer );
vlc_mutex_lock( &lock );
@@ -270,15 +270,15 @@ void event_thread_t::HandleMouseEvent( EventInfo const& event )
if ( best != 0)
{
btni_t button_ptr = pci->hli.btnit[best-1];
- uint16_t i_curr_button = p_sys->dvd_interpretor.GetSPRM( 0x88 );
+ uint16_t i_curr_button = p_sys->GetDVDInterpretor().GetSPRM( 0x88 );
msg_Dbg( &p_sys->demuxer, "Clicked button %d", best );
vlc_mutex_unlock( &lock );
vlc_mutex_lock( &p_sys->lock_demuxer );
// process the button action
- p_sys->dvd_interpretor.SetSPRM( 0x88, best );
- p_sys->dvd_interpretor.Interpret( button_ptr.cmd.bytes, 8 );
+ p_sys->GetDVDInterpretor().SetSPRM( 0x88, best );
+ p_sys->GetDVDInterpretor().Interpret( button_ptr.cmd.bytes, 8 );
msg_Dbg( &p_sys->demuxer, "Processed button %d", best );
=====================================
modules/demux/mkv/matroska_segment_parse.cpp
=====================================
@@ -1438,9 +1438,9 @@ void matroska_segment_c::ParseChapterAtom( int i_level, KaxChapterAtom *ca, chap
{
if( MKV_CHECKED_PTR_DECL( p_codec_id, KaxChapterProcessCodecID, cp[j] ) )
{
- if ( static_cast<uint32_t>(*p_codec_id) == 0 )
+ if ( p_codec_id->GetValue() == MATROSKA_CHAPTER_CODEC_NATIVE )
p_ccodec = new matroska_script_codec_c( vars.obj->sys );
- else if ( static_cast<uint32_t>(*p_codec_id) == 1 )
+ else if ( p_codec_id->GetValue() == MATROSKA_CHAPTER_CODEC_DVD )
p_ccodec = new dvd_chapter_codec_c( vars.obj->sys );
break;
}
=====================================
modules/demux/mkv/mkv.hpp
=====================================
@@ -111,6 +111,12 @@ enum
MATROSKA_ENCODING_SCOPE_NEXT = 4 /* unsupported */
};
+enum chapter_codec_id
+{
+ MATROSKA_CHAPTER_CODEC_NATIVE = 0,
+ MATROSKA_CHAPTER_CODEC_DVD = 1,
+};
+
#define MKVD_TIMECODESCALE 1000000
#define MKV_IS_ID( el, C ) ( el != NULL && (el->operator const EbmlId&()) == EBML_ID(C) && !el->IsDummy() )
=====================================
modules/demux/mkv/virtual_segment.cpp
=====================================
@@ -327,7 +327,7 @@ virtual_segment_c::~virtual_segment_c()
delete veditions[i];
}
-virtual_chapter_c *virtual_segment_c::BrowseCodecPrivate( unsigned int codec_id,
+virtual_chapter_c *virtual_segment_c::BrowseCodecPrivate( chapter_codec_id codec_id,
bool (*match)(const chapter_codec_cmds_c &data, const void *p_cookie, size_t i_cookie_size ),
const void *p_cookie,
size_t i_cookie_size )
@@ -340,7 +340,7 @@ virtual_chapter_c *virtual_segment_c::BrowseCodecPrivate( unsigned int codec_id,
}
-virtual_chapter_c * virtual_edition_c::BrowseCodecPrivate( unsigned int codec_id,
+virtual_chapter_c * virtual_edition_c::BrowseCodecPrivate( chapter_codec_id codec_id,
bool (*match)(const chapter_codec_cmds_c &data, const void *p_cookie, size_t i_cookie_size ),
const void *p_cookie,
size_t i_cookie_size )
@@ -359,7 +359,7 @@ virtual_chapter_c * virtual_edition_c::BrowseCodecPrivate( unsigned int codec_id
-virtual_chapter_c * virtual_chapter_c::BrowseCodecPrivate( unsigned int codec_id,
+virtual_chapter_c * virtual_chapter_c::BrowseCodecPrivate( chapter_codec_id codec_id,
bool (*match)(const chapter_codec_cmds_c &data, const void *p_cookie, size_t i_cookie_size ),
const void *p_cookie,
size_t i_cookie_size )
=====================================
modules/demux/mkv/virtual_segment.hpp
=====================================
@@ -55,7 +55,7 @@ public:
virtual_chapter_c * FindChapter( int64_t i_find_uid );
int PublishChapters( input_title_t & title, int & i_user_chapters, int i_level, bool allow_no_name );
- virtual_chapter_c * BrowseCodecPrivate( unsigned int codec_id,
+ virtual_chapter_c * BrowseCodecPrivate( chapter_codec_id codec_id,
bool (*match)( const chapter_codec_cmds_c &data,
const void *p_cookie,
size_t i_cookie_size ),
@@ -92,7 +92,7 @@ public:
virtual_chapter_c* getChapterbyTimecode( vlc_tick_t time );
std::string GetMainName();
int PublishChapters( input_title_t & title, int & i_user_chapters, int i_level );
- virtual_chapter_c * BrowseCodecPrivate( unsigned int codec_id,
+ virtual_chapter_c * BrowseCodecPrivate( chapter_codec_id codec_id,
bool (*match)( const chapter_codec_cmds_c &data,
const void *p_cookie,
size_t i_cookie_size ),
@@ -151,7 +151,7 @@ public:
inline std::vector<virtual_edition_c*>* Editions() { return &veditions; }
- virtual_chapter_c *BrowseCodecPrivate( unsigned int codec_id,
+ virtual_chapter_c *BrowseCodecPrivate( chapter_codec_id codec_id,
bool (*match)( const chapter_codec_cmds_c &data,
const void *p_cookie,
size_t i_cookie_size ),
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/135f1d2255a739a8eebd1b27001a59f7d3b59fbe...2c6d9de9f66aefb639ac8f00af7b030760cce294
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/135f1d2255a739a8eebd1b27001a59f7d3b59fbe...2c6d9de9f66aefb639ac8f00af7b030760cce294
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