[vlc-devel] [PATCH 04/17] es_out: add a matching time to SET_*_PCR

Thomas Guillem thomas at gllm.fr
Tue Mar 9 15:15:33 UTC 2021


This will replace DEMUX_GET_NORMAL_TIME.

Demux modules should set a valid matching_time if the PCR and the time
reported by DEMUX_GET_TIME don't have the same origin.
This is the case for mpeg/ts, dvd, bluray, cdda, adaptive.
---
 include/vlc_es_out.h                        | 16 +++++++++++++---
 modules/demux/adaptive/PlaylistManager.cpp  |  2 +-
 modules/demux/adaptive/plumbing/Demuxer.cpp |  2 +-
 modules/demux/mpeg/ts.c                     |  2 +-
 modules/demux/timestamps_filter.h           |  5 +++--
 src/input/es_out_timeshift.c                |  7 +++++--
 6 files changed, 24 insertions(+), 10 deletions(-)

diff --git a/include/vlc_es_out.h b/include/vlc_es_out.h
index 49635f8594f..a10d2a1a555 100644
--- a/include/vlc_es_out.h
+++ b/include/vlc_es_out.h
@@ -60,9 +60,13 @@ enum es_out_query_e
      * to slow down the demuxer so that it reads at the right speed.
      * XXX: if you want PREROLL just call ES_OUT_SET_NEXT_DISPLAY_TIME and send
      * as you would normally do.
+     * Modules should set a valid matching_time (!= VLC_TICK_INVALID) when
+     * their PCR is not based on 0 (DEMUX_GET_TIME and PCR are not based on the
+     * same origin).
+     *
      */
-    ES_OUT_SET_PCR,             /* arg1=vlc_tick_t i_pcr(microsecond!) (using default group 0)*/
-    ES_OUT_SET_GROUP_PCR,       /* arg1= int i_group, arg2=vlc_tick_t i_pcr(microsecond!)*/
+    ES_OUT_SET_PCR,             /* arg1=vlc_tick_t i_pcr, arg2=vlc_tick_t i_matching_time (using default group 0) */
+    ES_OUT_SET_GROUP_PCR,       /* arg1= int i_group, arg2=vlc_tick_t i_pcr, arg3=vlc_tick_t i_matching_time */
     ES_OUT_RESET_PCR,           /* no arg */
 
     /* This will update the fmt, drain and restart the decoder (if any).
@@ -184,7 +188,13 @@ static inline void es_out_Delete( es_out_t *p_out )
 
 static inline int es_out_SetPCR( es_out_t *out, vlc_tick_t pcr )
 {
-    return es_out_Control( out, ES_OUT_SET_PCR, pcr );
+    return es_out_Control( out, ES_OUT_SET_PCR, pcr, VLC_TICK_INVALID );
+}
+
+static inline int es_out_SetPCRTime( es_out_t *out, vlc_tick_t pcr,
+                                     vlc_tick_t matching_time )
+{
+    return es_out_Control( out, ES_OUT_SET_PCR, pcr, matching_time );
 }
 
 static inline int es_out_ControlSetMeta( es_out_t *out, const vlc_meta_t *p_meta )
diff --git a/modules/demux/adaptive/PlaylistManager.cpp b/modules/demux/adaptive/PlaylistManager.cpp
index e38e4d2fd6d..12773950159 100644
--- a/modules/demux/adaptive/PlaylistManager.cpp
+++ b/modules/demux/adaptive/PlaylistManager.cpp
@@ -505,7 +505,7 @@ int PlaylistManager::doDemux(vlc_tick_t increment)
         {
             demux.i_nzpcr = i_nzbarrier;
             vlc_tick_t pcr = VLC_TICK_0 + std::max(INT64_C(0), demux.i_nzpcr - VLC_TICK_FROM_MS(100));
-            es_out_Control(p_demux->out, ES_OUT_SET_GROUP_PCR, 0, pcr);
+            es_out_Control(p_demux->out, ES_OUT_SET_GROUP_PCR, 0, pcr, VLC_TICK_INVALID);
         }
         vlc_mutex_unlock(&demux.lock);
         break;
diff --git a/modules/demux/adaptive/plumbing/Demuxer.cpp b/modules/demux/adaptive/plumbing/Demuxer.cpp
index 0317f7309a5..d00fe280073 100644
--- a/modules/demux/adaptive/plumbing/Demuxer.cpp
+++ b/modules/demux/adaptive/plumbing/Demuxer.cpp
@@ -281,6 +281,6 @@ AbstractDemuxer::Status SlaveDemuxer::demux(vlc_tick_t nz_deadline)
         return Status::Eof;
     }
     Status status = Demuxer::demux(i_next_demux_time);
-    es_out_Control(p_es_out, ES_OUT_SET_GROUP_PCR, 0, i_next_demux_time);
+    es_out_Control(p_es_out, ES_OUT_SET_GROUP_PCR, 0, i_next_demux_time, VLC_TICK_INVALID);
     return status;
 }
diff --git a/modules/demux/mpeg/ts.c b/modules/demux/mpeg/ts.c
index 6361715cc67..52319fd220c 100644
--- a/modules/demux/mpeg/ts.c
+++ b/modules/demux/mpeg/ts.c
@@ -2267,7 +2267,7 @@ static void ProgramSetPCR( demux_t *p_demux, ts_pmt_t *p_pmt, stime_t i_pcr )
 
     if ( p_sys->i_pmt_es )
     {
-        es_out_Control( p_demux->out, ES_OUT_SET_GROUP_PCR, p_pmt->i_number, FROM_SCALE(i_pcr) );
+        es_out_Control( p_demux->out, ES_OUT_SET_GROUP_PCR, p_pmt->i_number, FROM_SCALE(i_pcr), VLC_TICK_INVALID );
         /* growing files/named fifo handling */
         if( p_sys->b_access_control == false &&
             vlc_stream_Tell( p_sys->stream ) > p_pmt->i_last_dts_byte )
diff --git a/modules/demux/timestamps_filter.h b/modules/demux/timestamps_filter.h
index a3563326e30..46491021788 100644
--- a/modules/demux/timestamps_filter.h
+++ b/modules/demux/timestamps_filter.h
@@ -171,6 +171,7 @@ static int timestamps_filter_es_out_Control(es_out_t *out, input_source_t *in, i
             else
                 i_group = 0;
             int64_t pcr = va_arg(va_list, int64_t);
+            int64_t matching_time = va_arg(va_list, int64_t);
 
             if(timestamps_filter_push("PCR ", &p_sys->pcrtf, pcr, 0, p_sys->b_discontinuity, true))
             {
@@ -200,9 +201,9 @@ static int timestamps_filter_es_out_Control(es_out_t *out, input_source_t *in, i
             pcr += p_sys->pcrtf.sequence_offset;
 
             if(i_query == ES_OUT_SET_GROUP_PCR)
-                return es_out_Control(p_sys->original_es_out, i_query, i_group, pcr);
+                return es_out_Control(p_sys->original_es_out, i_query, i_group, pcr, matching_time);
             else
-                return es_out_SetPCR(p_sys->original_es_out, pcr);
+                return es_out_SetPCRTime(p_sys->original_es_out, pcr, matching_time);
         }
             break;
         case ES_OUT_RESET_PCR:
diff --git a/src/input/es_out_timeshift.c b/src/input/es_out_timeshift.c
index da01feb8b9c..2ecc7c3b6bd 100644
--- a/src/input/es_out_timeshift.c
+++ b/src/input/es_out_timeshift.c
@@ -1533,11 +1533,13 @@ static int CmdInitControl( ts_cmd_control_t *p_cmd, input_source_t *in,
 
     case ES_OUT_SET_PCR:
         p_cmd->u.int_i64_i64.i_i64_1 = va_arg( args, vlc_tick_t );
+        p_cmd->u.int_i64_i64.i_i64_2 = va_arg( args, vlc_tick_t );
         break;
 
     case ES_OUT_SET_GROUP_PCR:          /* arg1= int i_group, arg2=vlc_tick_t i_pcr(microsecond!)*/
         p_cmd->u.int_i64_i64.i_int = va_arg( args, int );
         p_cmd->u.int_i64_i64.i_i64_1 = va_arg( args, vlc_tick_t );
+        p_cmd->u.int_i64_i64.i_i64_2 = va_arg( args, vlc_tick_t );
         break;
 
     case ES_OUT_SET_ES_SCRAMBLED_STATE:
@@ -1670,11 +1672,12 @@ static int CmdExecuteControl( es_out_t *p_tsout, ts_cmd_control_t *p_cmd )
         return es_out_in_Control( p_sys->p_out, in, i_query, p_cmd->u.i_i64 );
 
     case ES_OUT_SET_PCR:
-        return es_out_in_Control( p_sys->p_out, in, i_query, p_cmd->u.int_i64_i64.i_i64_1 );
+        return es_out_in_Control( p_sys->p_out, in, i_query, p_cmd->u.int_i64_i64.i_i64_1,
+                                  p_cmd->u.int_i64_i64.i_i64_2 );
 
     case ES_OUT_SET_GROUP_PCR:          /* arg1= int i_group, arg2=vlc_tick_t i_pcr(microsecond!)*/
         return es_out_in_Control( p_sys->p_out, in, i_query, p_cmd->u.int_i64_i64.i_int,
-                                  p_cmd->u.int_i64_i64.i_i64_1 );
+                                  p_cmd->u.int_i64_i64.i_i64_1, p_cmd->u.int_i64_i64.i_i64_2 );
 
     case ES_OUT_RESET_PCR:           /* no arg */
         return es_out_in_Control( p_sys->p_out, in, i_query );
-- 
2.30.0



More information about the vlc-devel mailing list