[vlc-commits] [Git][videolan/vlc][master] 2 commits: dvdread: keep the timestamp anchor across seamless cell changes
Steve Lhomme (@robUx4)
gitlab at videolan.org
Mon Oct 26 11:12:55 UTC 2026
Steve Lhomme pushed to branch master at VideoLAN / VLC
Commits:
7f9c2d98 by Pierre Bogdanovscky at 2026-10-26T11:00:46+00:00
dvdread: keep the timestamp anchor across seamless cell changes
The anchor was reset at every cell change and re-taken on the IFO cell
playback times, which do not match the stream's clock exactly: every
cell change then shifted the timestamps, by the multiplex delay or by a
whole VOBU, and after a seek the sector-interpolated base could be
seconds off.
Anchor from the NAV pack instead: keep the anchor while a VOBU starts
where the previous one ended (PCI vobu_s_ptm/vobu_e_ptm), otherwise
anchor its SCR at the cell start plus the DSI cell elapsed time. A cell
flagged with an STC discontinuity still resets the anchor.
Work item : #30201
- - - - -
8fb41c3e by Pierre Bogdanovscky at 2026-10-26T11:00:46+00:00
dvdread: count an angle block once in title times
The cells of an angle block cover the same stretch of time, one per
angle, but the title length, the chapter offsets, the timeline base
and the seek mapping added up all of them: a title with a 3-angle
block was reported too long, and its chapters started too late.
Count each block by its first cell only. The seek mapping still steps
over the other angles' sectors, which the block offsets include.
- - - - -
3 changed files:
- modules/access/dvdread.c
- modules/access/dvdread.h
- modules/access/dvdread_video.c
Changes:
=====================================
modules/access/dvdread.c
=====================================
@@ -702,11 +702,13 @@ static int Demux( demux_t *p_demux )
/* Basic check to be sure we don't have a empty title
* go to next title if so */
//assert( p_buffer[41] == 0xbf && p_buffer[1027] == 0xbf );
- DemuxBlock( p_demux, p_buffer, DVD_VIDEO_LB_LEN );
- /* Parse the contained dsi packet */
+ /* Parse the contained dsi packet, before demuxing the NAV pack: it
+ * anchors the timestamps of this vobu, the NAV pack's SCR included */
DvdReadHandleDSI( p_demux, p_buffer );
+ DemuxBlock( p_demux, p_buffer, DVD_VIDEO_LB_LEN );
+
if( p_sys->i_pack_len >= 1024 )
{
msg_Err( p_demux, "i_pack_len >= 1024 (%i). "
=====================================
modules/access/dvdread.h
=====================================
@@ -161,6 +161,11 @@ struct demux_sys_t
vlc_tick_t ps;
} cell_ts;
+ /* dvd-video: presentation end of the last vobu, 90 kHz, for the
+ * continuity test of DvdReadAnchorVobu; b_vobu_e_ptm false when unknown */
+ uint32_t i_vobu_e_ptm;
+ bool b_vobu_e_ptm;
+
/* Track */
ps_track_t tk[PS_TK_COUNT];
@@ -180,6 +185,7 @@ static inline void DvdReadResetCellTs( demux_sys_t *p_sys )
{
p_sys->cell_ts.dvd = VLC_TICK_INVALID;
p_sys->cell_ts.ps = VLC_TICK_INVALID;
+ p_sys->b_vobu_e_ptm = false;
}
int OpenCommonDvdread( vlc_object_t *, dvd_type_t, const dvdread_ops_t * );
=====================================
modules/access/dvdread_video.c
=====================================
@@ -57,6 +57,14 @@ static vlc_tick_t dvdtime_to_time( const dvd_time_t *dtime )
return vlc_tick_from_sec(sec) + VLC_TICK_FROM_MS(f_ms);
}
+/* the cells of an angle block are one stretch of time, one per angle: the
+ * block counts once in the title's times, by its first cell */
+static bool DvdReadCellTimed( const cell_playback_t *cell )
+{
+ return cell->block_type != BLOCK_TYPE_ANGLE_BLOCK ||
+ cell->block_mode == BLOCK_MODE_FIRST_CELL;
+}
+
/* total playback duration of the current title in vlc_tick_t
* for dvd-video sums per-cell playback_time across the active cell range
* so angle-restricted titles report the correct length
@@ -70,7 +78,9 @@ static vlc_tick_t DvdReadVideoTitleDuration( const demux_sys_t *p_sys )
vlc_tick_t dur = 0;
for( int ci = p_sys->i_title_start_cell; ci <= p_sys->i_title_end_cell; ci++ )
{
- dur += dvdtime_to_time( &p_sys->p_cur_pgc->cell_playback[ci].playback_time );
+ const cell_playback_t *cell = &p_sys->p_cur_pgc->cell_playback[ci];
+ if( DvdReadCellTimed( cell ) )
+ dur += dvdtime_to_time( &cell->playback_time );
}
return dur;
}
@@ -85,6 +95,24 @@ static vlc_tick_t DvdReadTitleLength( const demux_sys_t *p_sys )
return DvdReadVideoTitleDuration( p_sys );
}
+/* start of a cell on the title timeline: playback time of the cells before */
+static vlc_tick_t DvdReadCellStart( const demux_sys_t *p_sys, int i_cell )
+{
+ const cell_playback_t *cells = p_sys->p_cur_pgc->cell_playback;
+
+ /* a cell inside an angle block starts with the block */
+ int i_end = i_cell;
+ while( i_end > p_sys->i_title_start_cell &&
+ !DvdReadCellTimed( &cells[i_end] ) )
+ i_end--;
+
+ vlc_tick_t t = 0;
+ for( int i = p_sys->i_title_start_cell; i < i_end; i++ )
+ if( DvdReadCellTimed( &cells[i] ) )
+ t += dvdtime_to_time( &cells[i].playback_time );
+ return t;
+}
+
static bool DvdReadTimelineBase( const demux_sys_t *p_sys, vlc_tick_t *base )
{
const pgc_t *p_pgc = p_sys->p_cur_pgc;
@@ -95,9 +123,7 @@ static bool DvdReadTimelineBase( const demux_sys_t *p_sys, vlc_tick_t *base )
p_sys->i_title_start_cell > p_sys->i_cur_cell )
return false;
- vlc_tick_t cell_dvd_time = 0;
- for( int i = p_sys->i_title_start_cell; i < p_sys->i_cur_cell; i++ )
- cell_dvd_time += dvdtime_to_time( &p_pgc->cell_playback[i].playback_time );
+ vlc_tick_t cell_dvd_time = DvdReadCellStart( p_sys, p_sys->i_cur_cell );
const cell_playback_t *p_cell = &p_pgc->cell_playback[p_sys->i_cur_cell];
vlc_tick_t cell_duration = dvdtime_to_time( &p_cell->playback_time );
@@ -149,10 +175,20 @@ static uint32_t DvdReadCellAwareBlock( const demux_sys_t *p_sys,
for( int ci = p_sys->i_title_start_cell; ci <= p_sys->i_title_end_cell; ci++ )
{
const cell_playback_t *cell = &p_pgc->cell_playback[ci];
+ const uint32_t blocks = cell->last_sector - cell->first_sector + 1;
+
+ /* the other angles of a block: no time of their own, but their
+ * sectors are in the offset DvdReadSeek() reads */
+ if( !DvdReadCellTimed( cell ) )
+ {
+ if( ckd_add( &block_acc, block_acc, blocks ) )
+ return i_block_offset;
+ continue;
+ }
+
const vlc_tick_t dur = dvdtime_to_time( &cell->playback_time );
if( dur == 0 )
continue;
- const uint32_t blocks = cell->last_sector - cell->first_sector + 1;
vlc_tick_t next_acc;
uint32_t next_block_acc;
@@ -232,6 +268,64 @@ static void DvdReadFindCell( demux_t *p_demux )
}
}
+/*****************************************************************************
+ * DvdReadAnchorVobu: anchor the timestamps of the vobu whose NAV pack is p_data
+ *****************************************************************************/
+/* libdvdread only defines DSI_START_BYTE: pack header (14) + system header
+ * (24) + PES header (6) + substream id (1) */
+#define DVDREAD_PCI_START_BYTE 45
+
+static void DvdReadAnchorVobu( demux_t *p_demux, uint8_t *p_data )
+{
+ demux_sys_t *p_sys = p_demux->p_sys;
+
+ const bool b_in_title =
+ p_sys->i_cur_cell >= p_sys->i_title_start_cell &&
+ p_sys->i_cur_cell < p_sys->p_cur_pgc->nr_of_cells;
+
+ /* first vobu of a cell where the disc says the timestamps restart */
+ const cell_playback_t *p_cell = b_in_title ?
+ &p_sys->p_cur_pgc->cell_playback[p_sys->i_cur_cell] : NULL;
+ const bool b_restart = p_cell != NULL && p_cell->stc_discontinuity &&
+ p_sys->dsi_pack.dsi_gi.nv_pck_lbn == p_cell->first_sector;
+
+ /* where this vobu starts and ends, when its PCI tells */
+ uint32_t s_ptm = 0, e_ptm = 0;
+ const uint8_t pciheader[7] = { 0x00, 0x00, 0x01, 0xbf, 0x03, 0xd4, 0x00 };
+ if( !memcmp( &p_data[DVDREAD_PCI_START_BYTE-7], pciheader, 7 ) )
+ {
+ pci_t pci;
+ navRead_PCI( &pci, &p_data[DVDREAD_PCI_START_BYTE] );
+ s_ptm = pci.pci_gi.vobu_s_ptm;
+ e_ptm = pci.pci_gi.vobu_e_ptm;
+ }
+ const bool b_ptm = s_ptm != 0 || e_ptm != 0;
+
+ /* seamless vobus abut exactly, a few 90 kHz ticks of slack */
+ const bool b_continuous = !b_restart && b_ptm &&
+ p_sys->cell_ts.dvd != VLC_TICK_INVALID &&
+ p_sys->cell_ts.ps != VLC_TICK_INVALID &&
+ p_sys->b_vobu_e_ptm &&
+ llabs( (int64_t)s_ptm - (int64_t)p_sys->i_vobu_e_ptm ) <= 90;
+
+ /* an end left unknown makes the next vobu re-anchor */
+ p_sys->i_vobu_e_ptm = e_ptm;
+ p_sys->b_vobu_e_ptm = b_ptm;
+
+ if( b_continuous || !b_in_title )
+ return;
+ /* without timestamps, the anchor is kept, unless the disc says they
+ * restart here: the anchor comes from the DSI alone */
+ if( !b_ptm && !b_restart )
+ return;
+
+ /* offset by VLC_TICK_0: the title start, time 0, is VLC_TICK_INVALID */
+ p_sys->cell_ts.dvd = VLC_TICK_0 +
+ DvdReadCellStart( p_sys, p_sys->i_cur_cell ) +
+ dvdtime_to_time( &p_sys->dsi_pack.dsi_gi.c_eltm );
+ p_sys->cell_ts.ps = FROM_SCALE( p_sys->dsi_pack.dsi_gi.nv_pck_scr );
+}
+
/*****************************************************************************
* DvdReadHandleDSI
*****************************************************************************/
@@ -247,6 +341,9 @@ void DvdReadHandleDSI( demux_t *p_demux, uint8_t *p_data )
{
navRead_DSI( &p_sys->dsi_pack, &p_data[DSI_START_BYTE] );
+ /* before the cell change below: the vobu belongs to i_cur_cell */
+ DvdReadAnchorVobu( p_demux, p_data );
+
/*
* Determine where we go next. These values are the ones we mostly
* care about.
@@ -321,8 +418,6 @@ void DvdReadHandleDSI( demux_t *p_demux, uint8_t *p_data )
{
p_sys->i_cur_cell = p_sys->i_next_cell;
- DvdReadResetCellTs( p_sys );
-
/* End of title */
if( p_sys->i_cur_cell >= p_sys->p_cur_pgc->nr_of_cells ) return;
@@ -852,7 +947,8 @@ static void DvdReadFillTitleTimes( const ifo_handle_t *p_vts, int i_ttn,
vlc_tick_t length = 0;
for( int ci = start_cell; ci <= end_cell; ci++ )
- length += dvdtime_to_time( &p_pgc->cell_playback[ci].playback_time );
+ if( DvdReadCellTimed( &p_pgc->cell_playback[ci] ) )
+ length += dvdtime_to_time( &p_pgc->cell_playback[ci].playback_time );
t->i_length = length;
const int max_sp = __MIN( t->i_seekpoint, ptt->nr_of_ptts );
@@ -868,7 +964,8 @@ static void DvdReadFillTitleTimes( const ifo_handle_t *p_vts, int i_ttn,
const int chapter_cell = p_pgc->program_map[sj_pgn - 1] - 1;
while( cell < chapter_cell && cell <= end_cell )
{
- offset += dvdtime_to_time( &p_pgc->cell_playback[cell].playback_time );
+ if( DvdReadCellTimed( &p_pgc->cell_playback[cell] ) )
+ offset += dvdtime_to_time( &p_pgc->cell_playback[cell].playback_time );
cell++;
}
t->seekpoint[sj]->i_time_offset = offset;
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/ba397b737b2d24cbed6913879714b1e5b0552070...8fb41c3ea2016ecb92b52412bd8460b1cfe75bb5
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/ba397b737b2d24cbed6913879714b1e5b0552070...8fb41c3ea2016ecb92b52412bd8460b1cfe75bb5
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