[vlc-commits] [Git][videolan/vlc][3.0.x] 30 commits: demux:mkv: unmark the EOF if the seek failed and we're still in usable data
Steve Lhomme (@robUx4)
gitlab at videolan.org
Tue Mar 17 07:11:53 UTC 2026
Steve Lhomme pushed to branch 3.0.x at VideoLAN / VLC
Commits:
bddb763d by Steve Lhomme at 2026-03-16T07:35:01+01:00
demux:mkv: unmark the EOF if the seek failed and we're still in usable data
(cherry picked from commit 42b2aee790300d175c2141657d47c325442213c2)
- - - - -
10446fc1 by Zhao Zhili at 2026-03-16T07:35:01+01:00
demux: mkv: don't use psz prefix with std::string type
Signed-off-by: Steve Lhomme <robux4 at ycbcr.xyz>
(cherry picked from commit f57dce91c47d34be0994bbbd375e6e664aeafd36)
- - - - -
b07f22bb by Zhao Zhili at 2026-03-16T07:35:01+01:00
demux: mkv: simplify string operation
Signed-off-by: Steve Lhomme <robux4 at ycbcr.xyz>
(cherry picked from commit d621b278b975dbd656fb76da157b27f079662cb8)
- - - - -
641b648c by Zhao Zhili at 2026-03-16T07:35:01+01:00
demux: mkv: remove useless temporary variable
Signed-off-by: Rémi Denis-Courmont <remi at remlab.net>
(cherry picked from commit ad00299b128285dc5e32476775640cddce8c8e16)
- - - - -
d638b194 by Zhao Zhili at 2026-03-16T07:35:01+01:00
demux: mkv: remove workaround of KaxBlockVirtual
The workaround was added by ce718de in 2008. The bug was fixed in
upstream in 2010.
Signed-off-by: Steve Lhomme <robux4 at ycbcr.xyz>
(cherry picked from commit c49651c087c7b9b1b265cb911f6d006db914197f)
- - - - -
1e58300a by Filip Roséen at 2026-03-16T07:35:01+01:00
demux: mkv: use vlc_demux.h return codes
Signed-off-by: Steve Lhomme <robux4 at ycbcr.xyz>
(cherry picked from commit 2862e43e39d7a62b6fb1cb1b48441cd71333bc73) (edited)
edited:
- some KaxBlockAdditions leaks were already backported
- - - - -
3480e2d8 by Filip Roséen at 2026-03-16T07:35:02+01:00
demux: mkv: Demux: return VLC_DEMUXER_EGENERIC on error
VLC_DEMUXER_EOF is not correct if we abort due to an error.
Signed-off-by: Steve Lhomme <robux4 at ycbcr.xyz>
(cherry picked from commit 6d83d2a6d59092892a9db4fcc4b462ea45fb945d) (edited)
edited:
- the fix on UpdatePCR() error has already been backported
- - - - -
fdfd4fc5 by Filip Roséen at 2026-03-16T07:35:02+01:00
demux: mkv: simplify block handling
As KaxSimpleBlock and KaxBlock inherit from the same base we can get
rid of all these nasty if-else's by creating an object that refers to
the one we are interested in.
Signed-off-by: Steve Lhomme <robux4 at ycbcr.xyz>
(cherry picked from commit 5feb3a0476643324f8e418c89abb44b61cf75cae) (rebased)
rebased:
- some KaxBlockAdditions leaks were already backported
- - - - -
32d97cf1 by Hugo Beauzée-Luyssen at 2026-03-16T07:35:02+01:00
mkv: Don't probe position for non finite elements
(cherry picked from commit 7f5d54574e9d9889f72c17ca80148689de6e5b28)
- - - - -
2d65d0f3 by François Cartegnie at 2026-03-16T07:35:02+01:00
demux: mkv: read dimensions as stored size (fix #25012)
(cherry picked from commit 0d02c4aa6c2286116174c3d2a575a6fe0c6d7942)
- - - - -
28975f98 by Lyndon Brown at 2026-03-16T07:35:02+01:00
mkv: fix statement has no effect warning
Loop revised to c11 style rather than just dropping the unnecessary `t;`
upon request by Alexandre in review.
```
../../modules/demux/mkv/matroska_segment_parse.cpp: In member function 'void mkv::matroska_segment_c::ParseTracks(libmatroska::KaxTracks*)':
WARNING : ../../modules/demux/mkv/matroska_segment_parse.cpp:1102: 10: statement has no effect [-Wunused-value]
1102 | for (t; t != matroska_segment_c::tracks.end(); ++t)
| ^
```
(cherry picked from commit cf8225b3f3ceaeadb37fdf99c0ffb6c4c5010991)
- - - - -
e97ecbc6 by Steve Lhomme at 2026-03-16T07:35:02+01:00
demux/mkv: remove dead code
(cherry picked from commit 1c80e8c327c819b2655eb1a934cf5349a2e4a97b) (rebased)
rebased:
- VLC 4 has a namespace around the code
- VLC 4 uses standard integer types
- - - - -
dee6d534 by Steve Lhomme at 2026-03-16T07:35:02+01:00
demux/mkv: add override on overriden virtual methods
(cherry picked from commit 7e77a2335f5cd23c0c91c9b39ef451663e280971) (edited)
edited:
- 3.0 doesn't use regular integer types
- - - - -
d93f6d61 by Steve Lhomme at 2026-03-16T07:35:02+01:00
demux/mkv: use dedicated macro to get the EbmlID of a class
(cherry picked from commit 4323b35b96fd6bffad46953ff7173c0a124871d3)
- - - - -
f5e34494 by Steve Lhomme at 2026-03-16T07:35:02+01:00
demux/mkv: remove virtual on override methods
It's implied.
(cherry picked from commit d54cf7ee9aea855205b481cbb563072d009daa59) (edited)
edited:
- 3.0 doesn't use regular integer types
- - - - -
3e05f6c7 by Steve Lhomme at 2026-03-16T07:35:02+01:00
demux/mkv: define the file context with no globals like the real one
We should not access the internal list of the original context directly. The type will change.
In a Matroska or WebM file there can only be an Ebml Header or a Matroska at the top level.
The CRC32 cannot be found. And the Void element should not be found either.
(cherry picked from commit de03f1e026976220eab1c6b8d091e93a4760194f)
- - - - -
4ef8408a by Steve Lhomme at 2026-03-16T07:35:02+01:00
demux: mkv: initialize chapter values directly
(cherry picked from commit 1665c95abdcf00f37f01f1b8aa2c15e3582cc151) (edited)
edited:
- chapter UIDs still use int64 on VLC 3
- chapter start/end are in int64_t, not vlc_tick_t
- - - - -
2d8cc0a5 by Steve Lhomme at 2026-03-16T07:35:02+01:00
demux: mkv: add a template to get mandatory elements
We get a reference to the object, or it throws an error that a mandatory element
is missing.
This should only be used for elements without a default value. Otherwise the
missing element would be added automatically to get the default value. But
since it's a const EbmlElement, we don't want to modify it.
(cherry picked from commit 29ce258f38da6a408690901ecd7bc512f2aea1b3)
- - - - -
c31f897b by Steve Lhomme at 2026-03-16T07:35:02+01:00
demux: mkv: use GetMandatoryChild to read the track type
If it's missing, we can't use the track. For now we keep using a dummy track.
(cherry picked from commit 6001b567fe4e5193ef9f3fd46a939f73ae17b7c0) (edited)
edited:
- 3.0 didn't switch to standard integer types
- - - - -
542de73c by Steve Lhomme at 2026-03-16T07:35:02+01:00
demux: mkv: don't try to create elements if they may not exist
GetNextChild() should not be used to check for a nullptr value.
(cherry picked from commit 5509178b92f8d960e15ab2f0b93f94596e18397b) (rebased)
rebased:
- VLC 4 uses MissingMandatory to check attachements before
- - - - -
d80350d4 by Steve Lhomme at 2026-03-16T07:35:02+01:00
demux: mkv: fix leaking virtual segment on error
Fixes #29289
(cherry picked from commit 11d013a6109a7e3b55c2218d231febda705faebf) (rebased)
rebased:
- the code around is slightly different
- - - - -
4674a729 by Steve Lhomme at 2026-03-16T07:35:02+01:00
demux: mkv: fix leak of KaxCodecPrivate
If the element appears twice in the same track, the previous value must be free'd
or properly discarded.
Fixes #29290
(cherry picked from commit 223e87ef2623247ace83f281b72f6af9305a22da)
- - - - -
afa1f094 by Steve Lhomme at 2026-03-16T07:35:02+01:00
demux: mkv: avoid leaking string on overwriting
(cherry picked from commit 59f5eb9acc795cadfb9ba7345ffdfd46fbd59685)
- - - - -
dcdbcac6 by Steve Lhomme at 2026-03-16T07:35:02+01:00
demux: mkv: avoid leaking KaxChapterTranslateID on overwriting
(cherry picked from commit e323603c614435c720fb47260e4b08d1c706657a)
- - - - -
88b2892d by Steve Lhomme at 2026-03-16T07:35:02+01:00
demux: mkv: move local classes into tags containers
(cherry picked from commit ed4a4b30b9edba0b7b2ebedb2bbab8df0bdfc0a6) (edited)
edited:
- the container that receive the tags are in a different parent class
- - - - -
26663d84 by Steve Lhomme at 2026-03-16T07:35:02+01:00
demux: mkv: move local updated range into ranges
(cherry picked from commit 520ccf8912d862f7476d787de41ef362b6a1b6e5)
- - - - -
045c7cd7 by Steve Lhomme at 2026-03-16T07:35:02+01:00
demux: mkv: fix frame leak on Block read error
Fixes #29449
(cherry picked from commit 8f5fc2c2f148bac08cb8fe488038323537e63680)
- - - - -
244e6869 by Steve Lhomme at 2026-03-16T07:35:02+01:00
demux: mkv: fix leak on multiple string definition
These elements are all supposed to be unique. But as we always kept the last
value, we continue to do so without leaking the previous value.
Fixes #29521
(cherry picked from commit 36d591a3e93dbf99e1d23a3c06e8ace98995e83e)
- - - - -
b8529751 by Mathias APARICIO at 2026-03-16T07:35:02+01:00
demux: mkv: Prevent leak in ParseTrackEntry
Oss-fuzz 4605658287898624 highlights a memory leak in the
KaxCompSettings handler.
Delete the pointer vars.tk->p_compression_data before allocating again
so it is not overwritten.
Address https://code.videolan.org/videolan/vlc/-/issues/29561
(cherry picked from commit 2df6bca67b6ebbdcd336cfe7bc88faca14ec2da6)
- - - - -
6de34d81 by unichronic at 2026-03-16T07:35:02+01:00
demux: mkv: fix NULL deference error with invalid header compression
(cherry picked from commit 107825b609fecdf2bf0e5fa8bbef066327f473e6) (rebased)
rebased:
- VLC 3 doesn't handle LZO compression
- - - - -
13 changed files:
- modules/demux/mkv/Ebml_dispatcher.hpp
- modules/demux/mkv/Ebml_parser.cpp
- modules/demux/mkv/Ebml_parser.hpp
- modules/demux/mkv/chapters.hpp
- modules/demux/mkv/demux.cpp
- modules/demux/mkv/matroska_segment.cpp
- modules/demux/mkv/matroska_segment_parse.cpp
- modules/demux/mkv/matroska_segment_seeker.cpp
- modules/demux/mkv/mkv.cpp
- modules/demux/mkv/mkv.hpp
- modules/demux/mkv/stream_io_callback.cpp
- modules/demux/mkv/stream_io_callback.hpp
- modules/demux/mkv/virtual_segment.cpp
Changes:
=====================================
modules/demux/mkv/Ebml_dispatcher.hpp
=====================================
@@ -117,7 +117,7 @@ namespace {
#define E_CASE(EbmlType_, VariableName_) \
EBML_ELEMENT_CASE_DEF(EbmlType_, EbmlType_, VariableName_, \
- (dispatcher.insert( EbmlProcessorEntry( EbmlType_ ::ClassInfos.ClassId(), &EbmlType_ ## _callback) ) ) \
+ (dispatcher.insert( EbmlProcessorEntry( EBML_ID(EbmlType_), &EbmlType_ ## _callback) ) ) \
)
#define E_CASE_DEFAULT(VariableName_) \
=====================================
modules/demux/mkv/Ebml_parser.cpp
=====================================
@@ -122,11 +122,13 @@ static const EbmlSemanticContext & GetEbmlNoGlobal_Context()
}
// the Segment Context should not allow Void or CRC32 elements to avoid lookup false alarm
-const EbmlSemanticContext Context_KaxSegmentVLC = EbmlSemanticContext(KaxSegment_Context.GetSize(),
- KaxSegment_Context.MyTable,
- KaxSegment_Context.Parent(),
- GetEbmlNoGlobal_Context,
- KaxSegment_Context.GetMaster());
+DEFINE_START_SEMANTIC(KaxSegmentVLC)
+DEFINE_SEMANTIC_ITEM(true, true, EbmlHead)
+DEFINE_SEMANTIC_ITEM(false, false, KaxSegment)
+DEFINE_END_SEMANTIC(KaxSegmentVLC)
+
+DEFINE_xxx_CONTEXT(KaxSegmentVLC,GetEbmlNoGlobal_Context)
+
EbmlElement *EbmlParser::Get( bool allow_overshoot )
{
@@ -163,7 +165,7 @@ next:
if (i_max_read == 0)
{
/* check if the parent still has data to read */
- if ( mi_level > 1 &&
+ if ( mi_level > 1 && m_el[mi_level-2]->IsFiniteSize() &&
m_el[mi_level-1]->GetEndPosition() < m_el[mi_level-2]->GetEndPosition() )
{
uint64 top = m_el[mi_level-2]->GetEndPosition();
@@ -223,8 +225,6 @@ next:
{
if( !mb_keep )
{
- if( MKV_IS_ID( p_prev, KaxBlockVirtual ) )
- static_cast<KaxBlockVirtualWorkaround*>(p_prev)->Fix(); // !! WARNING : TODO !! this is undefined-behavior
delete p_prev;
p_prev = NULL;
}
@@ -284,8 +284,6 @@ next:
{
if( !mb_keep )
{
- if( MKV_IS_ID( p_prev, KaxBlockVirtual ) )
- static_cast<KaxBlockVirtualWorkaround*>(p_prev)->Fix(); // !! WARNING : TODO !! this is undefined-behavior
delete p_prev;
p_prev = NULL;
}
@@ -302,6 +300,7 @@ next:
m_el[mi_level]->GetElementPosition() );
if( mi_level >= 1 &&
+ m_el[mi_level]->IsFiniteSize() && m_el[mi_level-1]->IsFiniteSize() &&
m_el[mi_level]->GetElementPosition() >= m_el[mi_level-1]->GetEndPosition() )
{
msg_Err(p_demux, "This element is outside its known parent... upping level");
@@ -317,8 +316,6 @@ next:
{
if( !mb_keep )
{
- if( MKV_IS_ID( p_prev, KaxBlockVirtual ) )
- static_cast<KaxBlockVirtualWorkaround*>(p_prev)->Fix(); // !! WARNING : TODO !! this is undefined-behavior
delete p_prev;
p_prev = NULL;
}
@@ -332,8 +329,6 @@ next:
{
if( !mb_keep )
{
- if( MKV_IS_ID( p_prev, KaxBlockVirtual ) )
- static_cast<KaxBlockVirtualWorkaround*>(p_prev)->Fix();
delete p_prev;
}
mb_keep = false;
=====================================
modules/demux/mkv/Ebml_parser.hpp
=====================================
@@ -66,15 +66,4 @@ class EbmlParser
bool mb_dummy;
};
-/* This class works around a bug in KaxBlockVirtual implementation */
-class KaxBlockVirtualWorkaround : public KaxBlockVirtual
-{
-public:
- void Fix()
- {
- if( GetBuffer() == DataBlock )
- SetBuffer( NULL, 0 );
- }
-};
-
#endif
=====================================
modules/demux/mkv/chapters.hpp
=====================================
@@ -51,14 +51,6 @@ class chapter_item_c
{
public:
chapter_item_c()
- :i_start_time(0)
- ,i_end_time(-1)
- ,p_segment_uid(NULL)
- ,p_segment_edition_uid(NULL)
- ,b_display_seekpoint(true)
- ,b_user_display(true)
- ,p_parent(NULL)
- ,b_is_leaving(false)
{}
virtual ~chapter_item_c();
@@ -72,16 +64,17 @@ public:
bool ParentOf( const chapter_item_c & item ) const;
int16 GetTitleNumber( ) const;
- int64_t i_start_time, i_end_time;
+ int64_t i_start_time = 0;
+ int64_t i_end_time = -1;
std::vector<chapter_item_c*> sub_chapters;
- KaxChapterSegmentUID *p_segment_uid;
- KaxChapterSegmentEditionUID *p_segment_edition_uid;
- int64_t i_uid;
- bool b_display_seekpoint;
- bool b_user_display;
- std::string psz_name;
- chapter_item_c *p_parent;
- bool b_is_leaving;
+ KaxChapterSegmentUID *p_segment_uid = nullptr;
+ KaxChapterSegmentEditionUID *p_segment_edition_uid = nullptr;
+ int64_t i_uid = 0;
+ bool b_display_seekpoint = true;
+ bool b_user_display = true;
+ std::string str_name;
+ chapter_item_c *p_parent = nullptr;
+ bool b_is_leaving = false;
std::vector<chapter_codec_cmds_c*> codecs;
=====================================
modules/demux/mkv/demux.cpp
=====================================
@@ -454,7 +454,7 @@ bool demux_sys_t::AnalyseAllSegmentsFound( demux_t *p_demux, matroska_stream_c *
{
int i_upper_lvl = 0;
EbmlElement *p_l0;
- bool b_keep_stream = false, b_keep_segment = false;
+ bool b_keep_stream = false;
/* verify the EBML Header... it shouldn't be bigger than 1kB */
p_l0 = p_stream1->estream.FindNextID(EBML_INFO(EbmlHead), 1024);
@@ -522,7 +522,7 @@ bool demux_sys_t::AnalyseAllSegmentsFound( demux_t *p_demux, matroska_stream_c *
p_segment1->Preload();
if ( !p_segment1->p_segment_uid ||
- (b_keep_segment = (FindSegment( *p_segment1->p_segment_uid ) == NULL)))
+ FindSegment( *p_segment1->p_segment_uid ) == NULL)
{
opened_segments.push_back( p_segment1 );
b_keep_stream = true;
@@ -630,7 +630,10 @@ bool demux_sys_t::PreloadLinked()
return false;
if ( unlikely(p_current_vsegment->CurrentEdition() == NULL) )
+ {
+ delete p_current_vsegment;
return false;
+ }
/* Set current chapter */
p_current_vsegment->p_current_vchapter = p_current_vsegment->CurrentEdition()->getChapterbyTimecode(0);
@@ -686,6 +689,7 @@ bool demux_sys_t::PreloadLinked()
if ( st.tag_name == "TITLE" )
{
msg_Dbg( &demuxer, "Using title \"%s\" from tag for edition %" PRIu64, st.value.c_str (), i_ed_uid );
+ free(p_title->psz_name);
p_title->psz_name = strdup( st.value.c_str () );
break;
}
=====================================
modules/demux/mkv/matroska_segment.cpp
=====================================
@@ -315,7 +315,7 @@ bool matroska_segment_c::ParseSimpleTags( SimpleTag* pout_simple, KaxTagSimple *
// the SimpleTag is valid if ParseSimpleTags returns `true`
if (ParseSimpleTags( &st, kts_ptr, target_type )) {
- pout_simple->sub_tags.push_back( st );
+ pout_simple->sub_tags.push_back( std::move(st) );
}
}
/*TODO Handle binary tags*/
@@ -439,7 +439,7 @@ void matroska_segment_c::LoadTags( KaxTags *tags )
SimpleTag simple;
if (ParseSimpleTags(&simple, kts_ptr, target_type )) {
- tag.simple_tags.push_back( simple );
+ tag.simple_tags.push_back( std::move(simple) );
}
}
else
@@ -448,7 +448,7 @@ void matroska_segment_c::LoadTags( KaxTags *tags )
}
}
eparser.Up();
- this->tags.push_back(tag);
+ this->tags.push_back(std::move(tag));
}
else
{
@@ -1266,6 +1266,7 @@ int matroska_segment_c::BlockGet( KaxBlock * & pp_block, KaxSimpleBlock * & pp_s
}
if (read == 0 && ksblock.GetSize() != 0) {
msg_Err( vars.p_demuxer,"Error while reading %s", EBML_NAME(&ksblock) );
+ ksblock.ReleaseFrames();
return;
}
vars.simpleblock = &ksblock;
@@ -1294,6 +1295,7 @@ int matroska_segment_c::BlockGet( KaxBlock * & pp_block, KaxSimpleBlock * & pp_s
}
if (unlikely(read == 0) && kblock.GetSize() != 0) {
msg_Err( vars.p_demuxer,"Error while reading %s", EBML_NAME(&kblock) );
+ kblock.ReleaseFrames();
return;
}
vars.block = &kblock;
=====================================
modules/demux/mkv/matroska_segment_parse.cpp
=====================================
@@ -204,12 +204,14 @@ void matroska_segment_c::ParseTrackEntry( const KaxTrackEntry *m )
{
bool bSupported = true;
- EbmlUInteger *pTrackType = static_cast<EbmlUInteger*>(m->FindElt(EBML_INFO(KaxTrackType)));
uint8 ttype;
- if (likely(pTrackType != NULL))
- ttype = (uint8) *pTrackType;
- else
+ try {
+ KaxTrackType & pTrackType = GetMandatoryChild<KaxTrackType>(*m);
+ ttype = pTrackType;
+ } catch (const MissingMandatory & err) {
+ msg_Dbg( &sys.demuxer, "%s", err.what());
ttype = 0;
+ }
enum es_format_category_e es_cat;
switch( ttype )
@@ -344,6 +346,7 @@ void matroska_segment_c::ParseTrackEntry( const KaxTrackEntry *m )
}
E_CASE( KaxTrackName, tname )
{
+ free(vars.tk->fmt.psz_description);
vars.tk->fmt.psz_description = ToUTF8( UTFstring( tname ) );
debug( vars, "Track Name=%s", vars.tk->fmt.psz_description ? vars.tk->fmt.psz_description : "(null)" );
}
@@ -365,6 +368,7 @@ void matroska_segment_c::ParseTrackEntry( const KaxTrackEntry *m )
vars.tk->i_extra_data = cpriv.GetSize();
if( vars.tk->i_extra_data > 0 )
{
+ free( vars.tk->p_extra_data );
vars.tk->p_extra_data = static_cast<uint8_t*>( malloc( vars.tk->i_extra_data ) );
if( likely( vars.tk->p_extra_data ) )
@@ -458,6 +462,7 @@ void matroska_segment_c::ParseTrackEntry( const KaxTrackEntry *m )
}
E_CASE( KaxContentCompSettings, kccs )
{
+ delete vars.tk->p_compression_data;
vars.tk->p_compression_data = new KaxContentCompSettings( kccs );
}
E_CASE( KaxTrackVideo, tkv )
@@ -564,50 +569,50 @@ void matroska_segment_c::ParseTrackEntry( const KaxTrackEntry *m )
E_CASE( KaxVideoPixelWidth, vwidth )
{
ONLY_FMT(VIDEO);
- vars.tk->fmt.video.i_width += static_cast<uint16>( vwidth );
- debug( vars, "width=%d", vars.tk->fmt.video.i_width );
+ vars.tk->fmt.video.i_width += static_cast<uint32>( vwidth );
+ debug( vars, "width=%u", vars.tk->fmt.video.i_width );
}
E_CASE( KaxVideoPixelHeight, vheight )
{
ONLY_FMT(VIDEO);
- vars.tk->fmt.video.i_height += static_cast<uint16>( vheight );
- debug( vars, "height=%d", vars.tk->fmt.video.i_height );
+ vars.tk->fmt.video.i_height += static_cast<uint32>( vheight );
+ debug( vars, "height=%u", vars.tk->fmt.video.i_height );
}
E_CASE( KaxVideoDisplayWidth, vwidth )
{
ONLY_FMT(VIDEO);
- vars.track_video_info.i_display_width = static_cast<uint16>( vwidth );
- debug( vars, "display width=%d", vars.track_video_info.i_display_width );
+ vars.track_video_info.i_display_width = static_cast<uint32>( vwidth );
+ debug( vars, "display width=%u", vars.track_video_info.i_display_width );
}
E_CASE( KaxVideoDisplayHeight, vheight )
{
ONLY_FMT(VIDEO);
- vars.track_video_info.i_display_height = static_cast<uint16>( vheight );
- debug( vars, "display height=%d", vars.track_video_info.i_display_height );
+ vars.track_video_info.i_display_height = static_cast<uint32>( vheight );
+ debug( vars, "display height=%u", vars.track_video_info.i_display_height );
}
E_CASE( KaxVideoPixelCropBottom, cropval )
{
ONLY_FMT(VIDEO);
- vars.track_video_info.i_crop_bottom = static_cast<uint16>( cropval );
- debug( vars, "crop pixel bottom=%d", vars.track_video_info.i_crop_bottom );
+ vars.track_video_info.i_crop_bottom = static_cast<uint32>( cropval );
+ debug( vars, "crop pixel bottom=%u", vars.track_video_info.i_crop_bottom );
}
E_CASE( KaxVideoPixelCropTop, cropval )
{
ONLY_FMT(VIDEO);
- vars.track_video_info.i_crop_top = static_cast<uint16>( cropval );
- debug( vars, "crop pixel top=%d", vars.track_video_info.i_crop_top );
+ vars.track_video_info.i_crop_top = static_cast<uint32>( cropval );
+ debug( vars, "crop pixel top=%u", vars.track_video_info.i_crop_top );
}
E_CASE( KaxVideoPixelCropRight, cropval )
{
ONLY_FMT(VIDEO);
- vars.track_video_info.i_crop_right = static_cast<uint16>( cropval );
- debug( vars, "crop pixel right=%d", vars.track_video_info.i_crop_right );
+ vars.track_video_info.i_crop_right = static_cast<uint32>( cropval );
+ debug( vars, "crop pixel right=%u", vars.track_video_info.i_crop_right );
}
E_CASE( KaxVideoPixelCropLeft, cropval )
{
ONLY_FMT(VIDEO);
- vars.track_video_info.i_crop_left = static_cast<uint16>( cropval );
- debug( vars, "crop pixel left=%d", vars.track_video_info.i_crop_left );
+ vars.track_video_info.i_crop_left = static_cast<uint32>( cropval );
+ debug( vars, "crop pixel left=%u", vars.track_video_info.i_crop_left );
}
E_CASE( KaxVideoDisplayUnit, vdmode )
{
@@ -899,6 +904,14 @@ void matroska_segment_c::ParseTrackEntry( const KaxTrackEntry *m )
return;
}
#endif
+ if( p_track->i_compression_type == MATROSKA_COMPRESSION_HEADER &&
+ p_track->p_compression_data == NULL )
+ {
+ msg_Err(&sys.demuxer, "Track %u header compression missing header data", p_track->i_number );
+ delete p_track;
+ return;
+ }
+
if( !TrackInit( p_track ) )
{
msg_Err(&sys.demuxer, "Couldn't init track %u", p_track->i_number );
@@ -951,10 +964,9 @@ void matroska_segment_c::ParseTracks( KaxTracks *tracks )
TrackHandlers::Dispatcher().iterate( tracks->begin(), tracks->end(), &payload );
- auto t = matroska_segment_c::tracks.begin();
- for (t; t != matroska_segment_c::tracks.end(); ++t)
+ for (auto &track : matroska_segment_c::tracks)
{
- pcr_shift = std::max(pcr_shift, t->second->i_codec_delay);
+ pcr_shift = std::max(pcr_shift, track.second->i_codec_delay);
}
}
@@ -1023,11 +1035,13 @@ void matroska_segment_c::ParseInfo( KaxInfo *info )
}
E_CASE( KaxMuxingApp, mapp )
{
+ free(vars.obj->psz_muxing_application);
vars.obj->psz_muxing_application = ToUTF8( UTFstring( mapp ) );
debug( vars, "Muxing Application=%s", vars.obj->psz_muxing_application );
}
E_CASE( KaxWritingApp, wapp )
{
+ free(vars.obj->psz_writing_application);
vars.obj->psz_writing_application = ToUTF8( UTFstring( wapp ) );
debug( vars, "Writing Application=%s", vars.obj->psz_writing_application );
}
@@ -1038,6 +1052,7 @@ void matroska_segment_c::ParseInfo( KaxInfo *info )
}
E_CASE( KaxTitle, title )
{
+ free(vars.obj->psz_title);
vars.obj->psz_title = ToUTF8( UTFstring( title ) );
debug( vars, "Title=%s", vars.obj->psz_title );
}
@@ -1076,6 +1091,7 @@ void matroska_segment_c::ParseInfo( KaxInfo *info )
}
E_CASE( KaxChapterTranslateID, translated_id )
{
+ delete vars->p_translated;
vars->p_translated = new KaxChapterTranslateID( translated_id );
}
};
@@ -1193,18 +1209,16 @@ void matroska_segment_c::ParseChapterAtom( int i_level, KaxChapterAtom *ca, chap
}
E_CASE( KaxChapterString, name )
{
- char *psz_tmp_utf8 = ToUTF8( UTFstring( name ) );
+ std::string str_name( UTFstring( name ).GetUTF8() );
for ( int k = 0; k < vars.i_level; k++)
- vars.chapters.psz_name += '+';
+ vars.chapters.str_name += '+';
- vars.chapters.psz_name += ' ';
- vars.chapters.psz_name += psz_tmp_utf8;
+ vars.chapters.str_name += ' ';
+ vars.chapters.str_name += str_name;
vars.chapters.b_user_display = true;
- debug( vars, "ChapterString=%s", psz_tmp_utf8 );
-
- free( psz_tmp_utf8 );
+ debug( vars, "ChapterString=%s", str_name.c_str() );
}
E_CASE( KaxChapterLanguage, lang )
{
@@ -1280,9 +1294,7 @@ void matroska_segment_c::ParseAttachments( KaxAttachments *attachments )
while( attachedFile && ( attachedFile->GetSize() > 0 ) )
{
KaxFileData &img_data = GetChild<KaxFileData>( *attachedFile );
- char *psz_tmp_utf8 = ToUTF8( UTFstring( GetChild<KaxFileName>( *attachedFile ) ) );
- std::string attached_filename(psz_tmp_utf8);
- free(psz_tmp_utf8);
+ std::string attached_filename( UTFstring( GetChild<KaxFileName>( *attachedFile ) ).GetUTF8() );
attachment_c *new_attachment = new attachment_c( attached_filename,
GetChild<KaxMimeType>( *attachedFile ),
img_data.GetSize() );
@@ -1310,7 +1322,7 @@ void matroska_segment_c::ParseAttachments( KaxAttachments *attachments )
delete new_attachment;
}
- attachedFile = &GetNextChild<KaxAttached>( *attachments, *attachedFile );
+ attachedFile = FindNextChild<KaxAttached>( *attachments, *attachedFile );
}
}
=====================================
modules/demux/mkv/matroska_segment_seeker.cpp
=====================================
@@ -372,16 +372,13 @@ SegmentSeeker::index_unsearched_range( matroska_segment_c& ms, Range search_area
}
delete additions;
- if( simpleblock ) {
- block_pos = simpleblock->GetElementPosition();
- block_pts = simpleblock->GlobalTimecode() / 1000;
- track_id = simpleblock->TrackNum();
- }
- else {
- block_pos = block->GetElementPosition();
- block_pts = block->GlobalTimecode() / 1000;
- track_id = block->TrackNum();
- }
+ KaxInternalBlock& internal_block = simpleblock
+ ? static_cast<KaxInternalBlock&>( *simpleblock )
+ : static_cast<KaxInternalBlock&>( *block );
+
+ block_pos = internal_block.GetElementPosition();
+ block_pts = internal_block.GlobalTimecode() / 1000;
+ track_id = internal_block.TrackNum();
bool const b_valid_track = ms.FindTrackByBlock( block, simpleblock ) != NULL;
@@ -434,7 +431,7 @@ SegmentSeeker::mark_range_as_searched( Range data )
merged.push_back( *it );
}
- _ranges_searched = merged;
+ _ranges_searched = std::move(merged);
}
}
=====================================
modules/demux/mkv/mkv.cpp
=====================================
@@ -495,6 +495,10 @@ static void BlockDecode( demux_t *p_demux, KaxBlock *block, KaxSimpleBlock *simp
demux_sys_t *p_sys = p_demux->p_sys;
matroska_segment_c *p_segment = p_sys->p_current_vsegment->CurrentSegment();
+ KaxInternalBlock& internal_block = simpleblock
+ ? static_cast<KaxInternalBlock&>( *simpleblock )
+ : static_cast<KaxInternalBlock&>( *block );
+
if( !p_segment ) return;
mkv_track_t *p_track = p_segment->FindTrackByBlock( block, simpleblock );
@@ -529,28 +533,14 @@ static void BlockDecode( demux_t *p_demux, KaxBlock *block, KaxSimpleBlock *simp
}
size_t frame_size = 0;
- size_t block_size = 0;
-
- if( simpleblock != NULL )
- block_size = simpleblock->GetSize();
- else
- block_size = block->GetSize();
-
- const unsigned int i_number_frames = block != NULL ? block->NumberFrames() :
- ( simpleblock != NULL ? simpleblock->NumberFrames() : 0 );
+ size_t block_size = internal_block.GetSize();
+ const unsigned i_number_frames = internal_block.NumberFrames();
for( unsigned int i_frame = 0; i_frame < i_number_frames; i_frame++ )
{
block_t *p_block;
- DataBuffer *data;
- if( simpleblock != NULL )
- {
- data = &simpleblock->GetBuffer(i_frame);
- }
- else
- {
- data = &block->GetBuffer(i_frame);
- }
+ DataBuffer *data = &internal_block.GetBuffer(i_frame);
+
frame_size += data->Size();
if( !data->Buffer() || data->Size() > frame_size || frame_size > block_size )
{
@@ -560,7 +550,6 @@ static void BlockDecode( demux_t *p_demux, KaxBlock *block, KaxSimpleBlock *simp
size_t extra_data = track.fmt.i_codec == VLC_CODEC_PRORES ? 8 : 0;
if( track.i_compression_type == MATROSKA_COMPRESSION_HEADER &&
- track.p_compression_data != NULL &&
track.i_encoding_scope & MATROSKA_ENCODING_SCOPE_ALL_FRAMES )
p_block = MemToBlock( data->Buffer(), data->Size(), track.p_compression_data->GetSize() + extra_data );
else if( unlikely( track.fmt.i_codec == VLC_CODEC_WAVPACK ) )
@@ -725,13 +714,13 @@ static int Demux( demux_t *p_demux)
if( p_sys->i_pts >= p_sys->i_start_pts )
{
if ( p_vsegment->UpdateCurrentToChapter( *p_demux ) )
- return 1;
+ return VLC_DEMUXER_SUCCESS;
p_vsegment = p_sys->p_current_vsegment;
}
matroska_segment_c *p_segment = p_vsegment->CurrentSegment();
if ( p_segment == NULL )
- return 0;
+ return VLC_DEMUXER_EOF;
KaxBlock *block;
KaxSimpleBlock *simpleblock;
@@ -754,14 +743,18 @@ static int Demux( demux_t *p_demux)
p_sys->i_pts = p_chap->i_mk_virtual_stop_time + VLC_TICK_0;
p_sys->i_pts++; // trick to avoid staying on segments with no duration and no content
- return 1;
+ return VLC_DEMUXER_SUCCESS;
}
}
msg_Warn( p_demux, "cannot get block EOF?" );
- return 0;
+ return VLC_DEMUXER_EOF;
}
+ KaxInternalBlock& internal_block = block
+ ? static_cast<KaxInternalBlock&>( *block )
+ : static_cast<KaxInternalBlock&>( *simpleblock );
+
{
mkv_track_t *p_track = p_segment->FindTrackByBlock( block, simpleblock );
@@ -770,7 +763,7 @@ static int Demux( demux_t *p_demux)
msg_Err( p_demux, "invalid track number" );
delete block;
delete additions;
- return 0;
+ return VLC_DEMUXER_EGENERIC;
}
mkv_track_t &track = *p_track;
@@ -778,16 +771,13 @@ static int Demux( demux_t *p_demux)
if( track.i_skip_until_fpos != std::numeric_limits<uint64_t>::max() ) {
- uint64_t block_fpos = 0;
-
- if( block ) block_fpos = block->GetElementPosition();
- else block_fpos = simpleblock->GetElementPosition();
+ uint64_t block_fpos = internal_block.GetElementPosition();
if ( track.i_skip_until_fpos > block_fpos )
{
delete block;
delete additions;
- return 1; // this block shall be ignored
+ return VLC_DEMUXER_SUCCESS; // this block shall be ignored
}
}
}
@@ -803,9 +793,7 @@ static int Demux( demux_t *p_demux)
/* set pts */
{
p_sys->i_pts = p_sys->i_mk_chapter_time + VLC_TICK_0;
-
- if( simpleblock != NULL ) p_sys->i_pts += simpleblock->GlobalTimecode() / INT64_C( 1000 );
- else p_sys->i_pts += block->GlobalTimecode() / INT64_C( 1000 );
+ p_sys->i_pts += internal_block.GlobalTimecode() / INT64_C( 1000 );
}
if ( p_vsegment->CurrentEdition() &&
@@ -815,7 +803,7 @@ static int Demux( demux_t *p_demux)
/* nothing left to read in this ordered edition */
delete block;
delete additions;
- return 0;
+ return VLC_DEMUXER_EOF;
}
BlockDecode( p_demux, block, simpleblock, additions,
@@ -824,7 +812,7 @@ static int Demux( demux_t *p_demux)
delete block;
delete additions;
- return 1;
+ return VLC_DEMUXER_SUCCESS;
}
mkv_track_t::mkv_track_t(enum es_format_category_e es_cat) :
=====================================
modules/demux/mkv/mkv.hpp
=====================================
@@ -113,10 +113,28 @@ enum
#define MKVD_TIMECODESCALE 1000000
-#define MKV_IS_ID( el, C ) ( el != NULL && (el->operator const EbmlId&()) == (C::ClassInfos.ClassId()) && !el->IsDummy() )
+#define MKV_IS_ID( el, C ) ( el != NULL && (el->operator const EbmlId&()) == EBML_ID(C) && !el->IsDummy() )
#define MKV_CHECKED_PTR_DECL( name, type, src ) type * name = MKV_IS_ID(src, type) ? static_cast<type*>(src) : NULL
#define MKV_CHECKED_PTR_DECL_CONST( name, type, src ) const type * name = MKV_IS_ID(src, type) ? static_cast<const type*>(src) : NULL
+class MissingMandatory : public std::runtime_error
+{
+public:
+ MissingMandatory(const char * type_name)
+ :std::runtime_error(std::string("missing mandatory element without a default ") + type_name)
+ {}
+};
+
+template <typename Type>
+Type & GetMandatoryChild(const EbmlMaster & Master)
+{
+ auto p = static_cast<Type *>(Master.FindFirstElt(EBML_INFO(Type)));
+ if (p == nullptr)
+ {
+ throw MissingMandatory(EBML_INFO_NAME(EBML_INFO(Type)));
+ }
+ return *p;
+}
#if LIBEBML_VERSION < 0x020000
template <typename Type>
Type * FindChild(const EbmlMaster & Master)
@@ -136,10 +154,10 @@ using namespace LIBMATROSKA_NAMESPACE;
class attachment_c
{
public:
- attachment_c( const std::string& _psz_file_name, const std::string& _psz_mime_type, int _i_size )
+ attachment_c( const std::string& _str_file_name, const std::string& _str_mime_type, int _i_size )
:i_size(_i_size)
- ,psz_file_name( _psz_file_name)
- ,psz_mime_type( _psz_mime_type)
+ ,str_file_name( _str_file_name)
+ ,str_mime_type( _str_mime_type)
{
p_data = NULL;
}
@@ -152,15 +170,15 @@ public:
return (p_data != NULL);
}
- const char* fileName() const { return psz_file_name.c_str(); }
- const char* mimeType() const { return psz_mime_type.c_str(); }
+ const char* fileName() const { return str_file_name.c_str(); }
+ const char* mimeType() const { return str_mime_type.c_str(); }
int size() const { return i_size; }
void *p_data;
private:
int i_size;
- std::string psz_file_name;
- std::string psz_mime_type;
+ std::string str_file_name;
+ std::string str_mime_type;
};
class matroska_segment_c;
=====================================
modules/demux/mkv/stream_io_callback.cpp
=====================================
@@ -64,7 +64,16 @@ void vlc_stream_io_callback::setFilePointer(int64_t i_offset, seek_mode mode )
}
if(i_pos == i_current)
+ {
+ if (mb_eof)
+ {
+ // if previous setFilePointer() failed we may be back in the available data
+ i_size = stream_Size( s );
+ if ( i_size != 0 && i_pos < i_size )
+ mb_eof = vlc_stream_Seek( s, i_pos ) != VLC_SUCCESS;
+ }
return;
+ }
if( i_pos < 0 || ( ( i_size = stream_Size( s ) ) != 0 && i_pos >= i_size ) )
{
@@ -92,18 +101,3 @@ size_t vlc_stream_io_callback::write(const void *, size_t )
return 0;
}
-uint64 vlc_stream_io_callback::toRead( void )
-{
- uint64_t i_size;
-
- if( s == NULL)
- return 0;
-
- i_size = stream_Size( s );
-
- if( i_size <= 0 )
- return UINT64_MAX;
-
- return static_cast<uint64>( i_size - vlc_stream_Tell( s ) );
-}
-
=====================================
modules/demux/mkv/stream_io_callback.hpp
=====================================
@@ -44,11 +44,10 @@ class vlc_stream_io_callback: public IOCallback
bool IsEOF() const { return mb_eof; }
- virtual uint32 read ( void *p_buffer, size_t i_size);
- virtual void setFilePointer ( int64_t i_offset, seek_mode mode = seek_beginning );
- virtual size_t write ( const void *p_buffer, size_t i_size);
- virtual uint64 getFilePointer ( void );
- virtual void close ( void ) { return; }
- uint64 toRead ( void );
+ uint32 read ( void *p_buffer, size_t i_size) override;
+ void setFilePointer ( int64_t i_offset, seek_mode mode = seek_beginning ) override;
+ size_t write ( const void *p_buffer, size_t i_size) override;
+ uint64 getFilePointer ( void ) override;
+ void close ( void ) override { return; }
};
=====================================
modules/demux/mkv/virtual_segment.cpp
=====================================
@@ -57,7 +57,7 @@ virtual_chapter_c * virtual_chapter_c::CreateVirtualChapter( chapter_item_c * p_
{
msg_Warn( &main_segment.sys.demuxer,
"Couldn't find segment 0x%x or not ordered... - ignoring chapter %s",
- *( (uint32_t *) p_chap->p_segment_uid->GetBuffer() ),p_chap->psz_name.c_str() );
+ *( (uint32_t *) p_chap->p_segment_uid->GetBuffer() ),p_chap->str_name.c_str() );
return NULL;
}
@@ -96,7 +96,7 @@ virtual_chapter_c * virtual_chapter_c::CreateVirtualChapter( chapter_item_c * p_
msg_Dbg( &main_segment.sys.demuxer,
"Virtual chapter %s from %" PRId64 " to %" PRId64 " - " ,
- p_chap->psz_name.c_str(), p_vchap->i_mk_virtual_start_time, p_vchap->i_mk_virtual_stop_time );
+ p_chap->str_name.c_str(), p_vchap->i_mk_virtual_start_time, p_vchap->i_mk_virtual_stop_time );
return p_vchap;
}
@@ -597,7 +597,7 @@ int virtual_chapter_c::PublishChapters( input_title_t & title, int & i_user_chap
{
std::string chap_name;
if ( p_chapter->b_user_display )
- chap_name = p_chapter->psz_name;
+ chap_name = p_chapter->str_name;
if (chap_name == "")
chap_name = p_chapter->GetCodecName();
@@ -636,7 +636,7 @@ int virtual_edition_c::PublishChapters( input_title_t & title, int & i_user_chap
{
seekpoint_t *sk = vlc_seekpoint_New();
sk->i_time_offset = 0;
- sk->psz_name = strdup( p_edition->psz_name.c_str() );
+ sk->psz_name = strdup( p_edition->str_name.c_str() );
title.i_seekpoint++;
title.seekpoint = static_cast<seekpoint_t**>( xrealloc( title.seekpoint,
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/6850b3b237ef1208be5bfe74de90c84bc9e420d4...6de34d81b42fcaef3184add2adc0843aa8514a5d
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/6850b3b237ef1208be5bfe74de90c84bc9e420d4...6de34d81b42fcaef3184add2adc0843aa8514a5d
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