[vlc-devel] [PATCH 18/18] clock: add 'clock-master' option to choose the master clock

Thomas Guillem thomas at gllm.fr
Thu Mar 7 15:25:40 CET 2019


---
 src/clock/clock.h   |  7 +++++++
 src/input/es_out.c  | 19 ++++++++++++++++++-
 src/libvlc-module.c | 16 ++++++++++++++++
 3 files changed, 41 insertions(+), 1 deletion(-)

diff --git a/src/clock/clock.h b/src/clock/clock.h
index 0088d89ebe..205a0b6fa6 100644
--- a/src/clock/clock.h
+++ b/src/clock/clock.h
@@ -20,6 +20,13 @@
 #ifndef VLC_CLOCK_H
 #define VLC_CLOCK_H
 
+enum vlc_clock_master_source
+{
+    VLC_CLOCK_MASTER_AUDIO = 0,
+    VLC_CLOCK_MASTER_MONOTONIC,
+    VLC_CLOCK_MASTER_DEFAULT = VLC_CLOCK_MASTER_AUDIO,
+};
+
 typedef struct vlc_clock_main_t vlc_clock_main_t;
 typedef struct vlc_clock_t vlc_clock_t;
 
diff --git a/src/input/es_out.c b/src/input/es_out.c
index 92fbb0c809..98b7da3c86 100644
--- a/src/input/es_out.c
+++ b/src/input/es_out.c
@@ -163,6 +163,8 @@ typedef struct
     struct vlc_list programs;
     es_out_pgrm_t *p_pgrm;  /* Master program */
 
+    enum es_format_category_e i_master_source_cat;
+
     /* all es */
     int         i_id;
     struct vlc_list es;
@@ -346,6 +348,19 @@ es_out_t *input_EsOutNew( input_thread_t *p_input, float rate )
 
     p_sys->i_group_id = var_GetInteger( p_input, "program" );
 
+    enum vlc_clock_master_source master_source =
+        var_InheritInteger( p_input, "clock-master" );
+    switch( master_source )
+    {
+        case VLC_CLOCK_MASTER_AUDIO:
+            p_sys->i_master_source_cat = AUDIO_ES;
+            break;
+        case VLC_CLOCK_MASTER_MONOTONIC:
+        default:
+            p_sys->i_master_source_cat = UNKNOWN_ES;
+            break;
+    }
+
     p_sys->i_pause_date = -1;
 
     p_sys->rate = rate;
@@ -1796,7 +1811,9 @@ static void EsOutCreateDecoder( es_out_t *out, es_out_id_t *p_es )
     input_thread_t *p_input = p_sys->p_input;
     decoder_t *dec;
 
-    if( p_es->fmt.i_cat == AUDIO_ES && p_es->p_pgrm->p_master_clock == NULL )
+    if( p_es->fmt.i_cat != UNKNOWN_ES
+     && p_es->fmt.i_cat == p_sys->i_master_source_cat
+     && p_es->p_pgrm->p_master_clock == NULL )
         p_es->p_pgrm->p_master_clock = p_es->p_clock =
             vlc_clock_main_CreateMaster( p_es->p_pgrm->p_main_clock );
     else
diff --git a/src/libvlc-module.c b/src/libvlc-module.c
index 9dc4a2c09f..5bd2431607 100644
--- a/src/libvlc-module.c
+++ b/src/libvlc-module.c
@@ -45,6 +45,8 @@
 #include <vlc_aout.h>
 #include <vlc_vout.h>
 
+#include "clock/clock.h"
+
 static const char *const ppsz_snap_formats[] =
 { "png", "jpg", "tiff" };
 
@@ -527,6 +529,17 @@ static const char *const ppsz_pos_descriptions[] =
     "This defines the maximum input delay jitter that the synchronization " \
     "algorithms should try to compensate (in milliseconds)." )
 
+#define CLOCK_MASTER_TEXT N_("Clock master source")
+
+static const int pi_clock_master_values[] = {
+    VLC_CLOCK_MASTER_AUDIO,
+    VLC_CLOCK_MASTER_MONOTONIC,
+};
+static const char *const ppsz_clock_master_descriptions[] = {
+    N_("Audio"),
+    N_("Monotonic")
+};
+
 #define NETSYNC_TEXT N_("Network synchronisation" )
 #define NETSYNC_LONGTEXT N_( "This allows you to remotely " \
         "synchronise clocks for server and client. The detailed settings " \
@@ -1940,6 +1953,9 @@ vlc_module_begin ()
     add_integer( "clock-jitter", 5000, CLOCK_JITTER_TEXT,
               CLOCK_JITTER_LONGTEXT, true )
         change_safe()
+    add_integer( "clock-master", VLC_CLOCK_MASTER_DEFAULT,
+                 CLOCK_MASTER_TEXT, NULL, true )
+        change_integer_list( pi_clock_master_values, ppsz_clock_master_descriptions )
 
     add_bool( "network-synchronisation", false, NETSYNC_TEXT,
               NETSYNC_LONGTEXT, true )
-- 
2.20.1



More information about the vlc-devel mailing list