[vlc-commits] [Git][videolan/vlc][3.0.x] 4 commits: demux: mkv: process the block duration once we have read the whole BlockGroup
Jean-Baptiste Kempf (@jbk)
gitlab at videolan.org
Mon Aug 24 14:36:12 UTC 2026
Jean-Baptiste Kempf pushed to branch 3.0.x at VideoLAN / VLC
Commits:
7eb8b9e5 by Steve Lhomme at 2026-08-24T16:24:07+02:00
demux: mkv: process the block duration once we have read the whole BlockGroup
The order of elements doesn't guarantee we get the BlockDuration before the DiscardPadding.
(cherry picked from commit 2494e66ad789495ced07ab916cf0e773d9ac0faf) (edited)
edited:
- VLC 3 still uses libebml's int64
Signed-off-by: Steve Lhomme <robux4 at ycbcr.xyz>
- - - - -
bed88f89 by Steve Lhomme at 2026-08-24T16:24:07+02:00
demux: mkv: ignore negative DiscardPadding
A negative value means we have to pad the decoded data with silence
at the beginning [^1]. But VLC doesn't support that feature.
Co-authored-by: zhengjianfeng <jianfeng.zheng at mthreads.dev>
[^1]: https://www.rfc-editor.org/info/rfc9559/#section-5.1.3.5.7
(cherry picked from commit 144d53454a6c9fb76273ebd771c481da48edad9e)
Signed-off-by: Steve Lhomme <robux4 at ycbcr.xyz>
- - - - -
c01236ee by Steve Lhomme at 2026-08-24T16:24:07+02:00
demux:mkv: the duration is only transform into vlc_tick_t when needed
When the track is known and how many laces are in a Block
(cherry picked from commit 731bb51e2dc8c610e74dec9460e66a77cdadbd7a)
Signed-off-by: Steve Lhomme <robux4 at ycbcr.xyz>
- - - - -
bbc664cc by Steve Lhomme at 2026-08-24T16:24:07+02:00
demux: mkv: handle the block duration as always unsigned
(cherry picked from commit a35c3723f0c8423df4e9711abbb8fa0941e655f4)
Signed-off-by: Steve Lhomme <robux4 at ycbcr.xyz>
- - - - -
6 changed files:
- modules/demux/mkv/matroska_segment.cpp
- modules/demux/mkv/matroska_segment.hpp
- modules/demux/mkv/matroska_segment_seeker.cpp
- modules/demux/mkv/mkv.cpp
- modules/demux/mkv/util.cpp
- modules/demux/mkv/util.hpp
Changes:
=====================================
modules/demux/mkv/matroska_segment.cpp
=====================================
@@ -1180,7 +1180,7 @@ void matroska_segment_c::ESDestroy( )
int matroska_segment_c::BlockGet( KaxBlock * & pp_block, KaxSimpleBlock * & pp_simpleblock,
KaxBlockAdditions * & pp_additions,
bool *pb_key_picture, bool *pb_discardable_picture,
- int64_t *pi_duration )
+ uint64_t *pi_duration )
{
pp_simpleblock = NULL;
pp_block = NULL;
@@ -1190,6 +1190,9 @@ int matroska_segment_c::BlockGet( KaxBlock * & pp_block, KaxSimpleBlock * & pp_s
*pb_discardable_picture = false;
*pi_duration = 0;
+ uint64_t duration = 0;
+ int64_t duration_padding = 0;
+
struct BlockPayload {
matroska_segment_c * const obj;
EbmlParser * const ep;
@@ -1198,14 +1201,15 @@ int matroska_segment_c::BlockGet( KaxBlock * & pp_block, KaxSimpleBlock * & pp_s
KaxSimpleBlock *& simpleblock;
KaxBlockAdditions *& additions;
- int64_t & i_duration;
+ uint64_t & i_duration;
+ int64_t & duration_padding;
bool & b_key_picture;
bool & b_discardable_picture;
bool b_cluster_timecode;
} payload = {
this, &ep, &sys.demuxer, pp_block, pp_simpleblock, pp_additions,
- *pi_duration, *pb_key_picture, *pb_discardable_picture, true
+ duration, duration_padding, *pb_key_picture, *pb_discardable_picture, true
};
MKV_SWITCH_CREATE( EbmlTypeDispatcher, BlockGetHandler_l1, BlockPayload )
@@ -1341,12 +1345,7 @@ int matroska_segment_c::BlockGet( KaxBlock * & pp_block, KaxSimpleBlock * & pp_s
E_CASE( KaxDiscardPadding, kdiscardp )
{
kdiscardp.ReadData( vars.obj->es.I_O() );
- int64 i_duration = static_cast<int64>( kdiscardp );
-
- if( vars.i_duration < i_duration )
- vars.i_duration = 0;
- else
- vars.i_duration -= i_duration;
+ vars.duration_padding = static_cast<int64>( kdiscardp );
}
#endif
E_CASE_DEFAULT( element )
@@ -1404,6 +1403,20 @@ int matroska_segment_c::BlockGet( KaxBlock * & pp_block, KaxSimpleBlock * & pp_s
}
}
+ /* A negative DiscardPadding designates padding at the start of
+ * the block, which we don't handle; some files in the wild also
+ * carry bogus negative values due to encoder bugs. Never let it
+ * extend the block duration. */
+ if ( duration_padding < 0)
+ {
+ msg_Warn( &sys.demuxer, "ignoring negative DiscardPadding (%" PRId64 ")", duration_padding );
+ *pi_duration = duration;
+ }
+ else if( duration < (uint64_t)duration_padding )
+ *pi_duration = 0;
+ else
+ *pi_duration = duration - duration_padding;
+
return VLC_SUCCESS;
}
=====================================
modules/demux/mkv/matroska_segment.hpp
=====================================
@@ -145,7 +145,7 @@ public:
bool Seek( demux_t &, vlc_tick_t i_mk_date, vlc_tick_t i_mk_time_offset, bool b_accurate );
int BlockGet( KaxBlock * &, KaxSimpleBlock * &, KaxBlockAdditions * &,
- bool *, bool *, int64_t *);
+ bool *, bool *, uint64_t *);
mkv_track_t * FindTrackByBlock(const KaxBlock *, const KaxSimpleBlock * );
=====================================
modules/demux/mkv/matroska_segment_seeker.cpp
=====================================
@@ -361,7 +361,7 @@ SegmentSeeker::index_unsearched_range( matroska_segment_c& ms, Range search_area
bool b_key_picture;
bool b_discardable_picture;
- int64_t i_block_duration;
+ uint64_t i_block_duration;
track_id_t track_id;
if( ms.BlockGet( block, simpleblock, additions,
=====================================
modules/demux/mkv/mkv.cpp
=====================================
@@ -489,7 +489,7 @@ static int Seek( demux_t *p_demux, vlc_tick_t i_mk_date, double f_percent, virtu
/* Needed by matroska_segment::Seek() and Seek */
static void BlockDecode( demux_t *p_demux, KaxBlock *block, KaxSimpleBlock *simpleblock,
const KaxBlockAdditions *additions,
- vlc_tick_t i_pts, int64_t i_duration, bool b_key_picture,
+ vlc_tick_t i_pts, uint64_t i_duration, bool b_key_picture,
bool b_discardable_picture )
{
demux_sys_t *p_sys = p_demux->p_sys;
@@ -623,8 +623,8 @@ static void BlockDecode( demux_t *p_demux, KaxBlock *block, KaxSimpleBlock *simp
case VLC_CODEC_OPUS:
{
- vlc_tick_t i_length = i_duration * track. f_timecodescale *
- (double) p_segment->i_timescale / 1000.0;
+ vlc_tick_t i_length = VLC_TICK_FROM_NS(i_duration * track.f_timecodescale *
+ p_segment->i_timescale);
if ( i_length < 0 ) i_length = 0;
p_block->i_nb_samples = i_length * track.fmt.audio.i_rate
/ CLOCK_FREQ;
@@ -725,7 +725,7 @@ static int Demux( demux_t *p_demux)
KaxBlock *block;
KaxSimpleBlock *simpleblock;
KaxBlockAdditions *additions;
- int64_t i_block_duration = 0;
+ uint64_t i_block_duration = 0;
bool b_key_picture;
bool b_discardable_picture;
=====================================
modules/demux/mkv/util.cpp
=====================================
@@ -353,7 +353,7 @@ int UpdatePCR( demux_t * p_demux )
return VLC_SUCCESS;
}
-void send_Block( demux_t * p_demux, mkv_track_t * p_tk, block_t * p_block, unsigned int i_number_frames, vlc_tick_t i_duration )
+void send_Block( demux_t * p_demux, mkv_track_t * p_tk, block_t * p_block, unsigned int i_number_frames, uint64_t i_duration )
{
demux_sys_t *p_sys = p_demux->p_sys;
matroska_segment_c *p_segment = p_sys->p_current_vsegment->CurrentSegment();
@@ -373,8 +373,8 @@ void send_Block( demux_t * p_demux, mkv_track_t * p_tk, block_t * p_block, unsig
if( !p_tk->b_no_duration )
{
- p_block->i_length = i_duration * p_tk->f_timecodescale *
- (double) p_segment->i_timescale / ( 1000.0 * i_number_frames );
+ p_block->i_length = VLC_TICK_FROM_NS(i_duration * p_tk->f_timecodescale *
+ p_segment->i_timescale) / i_number_frames;
}
if( p_tk->b_discontinuity )
=====================================
modules/demux/mkv/util.hpp
=====================================
@@ -34,7 +34,7 @@ block_t *MemToBlock( uint8_t *p_mem, size_t i_mem, size_t offset);
void handle_real_audio(demux_t * p_demux, mkv_track_t * p_tk, block_t * p_blk, vlc_tick_t i_pts);
block_t *WEBVTT_Repack_Sample(block_t *p_block, bool b_webm = false,
const uint8_t * = NULL, size_t = 0);
-void send_Block( demux_t * p_demux, mkv_track_t * p_tk, block_t * p_block, unsigned int i_number_frames, vlc_tick_t i_duration );
+void send_Block( demux_t * p_demux, mkv_track_t * p_tk, block_t * p_block, unsigned int i_number_frames, uint64_t i_duration );
int UpdatePCR( demux_t * p_demux );
class ByteReader
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/5649394ca7aded73e6fd955ea77e1cb2fddab14c...bbc664ccb6509b7a8e8498b098991cb6d6f210cd
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/5649394ca7aded73e6fd955ea77e1cb2fddab14c...bbc664ccb6509b7a8e8498b098991cb6d6f210cd
You're receiving this email because of your account on code.videolan.org. Manage all notifications: https://code.videolan.org/-/profile/notifications | Help: https://code.videolan.org/help
More information about the vlc-commits
mailing list