[vlc-commits] core: change the "--clock-master" type to string

Thomas Guillem git at videolan.org
Mon Apr 12 07:49:36 UTC 2021


vlc | branch: master | Thomas Guillem <thomas at gllm.fr> | Wed Mar 31 15:10:04 2021 +0200| [40f20a4985603b7e43c462536ea9358313ad7303] | committer: Thomas Guillem

core: change the "--clock-master" type to string

Keeping compatibility with the legacy type (0 and 1).

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=40f20a4985603b7e43c462536ea9358313ad7303
---

 src/input/es_out.c  | 42 +++++++++++++++++++++++++++++++++++++++++-
 src/libvlc-module.c |  9 ++++-----
 2 files changed, 45 insertions(+), 6 deletions(-)

diff --git a/src/input/es_out.c b/src/input/es_out.c
index b3b3562105..d0c8ee587e 100644
--- a/src/input/es_out.c
+++ b/src/input/es_out.c
@@ -264,6 +264,46 @@ static int LanguageArrayIndex( char **ppsz_langs, const char *psz_lang );
 static char *EsOutProgramGetMetaName( es_out_pgrm_t *p_pgrm );
 static char *EsInfoCategoryName( es_out_id_t* es );
 
+struct clock_source_mapping
+{
+    char key[sizeof("monotonic")];
+    enum vlc_clock_master_source val;
+};
+
+static int clock_source_mapping_cmp(const void *key, const void *val)
+{
+    const struct clock_source_mapping *entry = val;
+    return strcasecmp( key, entry->key );
+}
+
+static enum vlc_clock_master_source
+clock_source_Inherit(vlc_object_t *obj)
+{
+    static const struct clock_source_mapping clock_source_list[] =
+    {
+        { "0", VLC_CLOCK_MASTER_AUDIO }, /* legacy option */
+        { "1", VLC_CLOCK_MASTER_MONOTONIC }, /* legacy option */
+        { "audio", VLC_CLOCK_MASTER_AUDIO },
+        { "monotonic", VLC_CLOCK_MASTER_MONOTONIC },
+    };
+
+    char *master_source_str = var_InheritString(obj, "clock-master");
+    if (master_source_str == NULL)
+        goto default_val;
+
+    const struct clock_source_mapping *entry =
+        bsearch(master_source_str, clock_source_list, ARRAY_SIZE(clock_source_list),
+                sizeof (*clock_source_list), clock_source_mapping_cmp);
+    free(master_source_str);
+    if (entry == NULL)
+        goto default_val;
+
+    return entry->val;
+
+default_val:
+    return VLC_CLOCK_MASTER_DEFAULT;
+}
+
 static inline int EsOutGetClosedCaptionsChannel( const es_format_t *p_fmt )
 {
     int i_channel;
@@ -517,7 +557,7 @@ es_out_t *input_EsOutNew( input_thread_t *p_input, input_source_t *main_source,
     p_sys->i_group_id = var_GetInteger( p_input, "program" );
 
     enum vlc_clock_master_source master_source =
-        var_InheritInteger( p_input, "clock-master" );
+        clock_source_Inherit( VLC_OBJECT(p_input) );
     switch( master_source )
     {
         case VLC_CLOCK_MASTER_AUDIO:
diff --git a/src/libvlc-module.c b/src/libvlc-module.c
index 16d96d53b5..94b6a644e5 100644
--- a/src/libvlc-module.c
+++ b/src/libvlc-module.c
@@ -538,9 +538,8 @@ static const char *const screensaver_texts[] = {
 
 #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_values[] = {
+    "audio", "monotonic",
 };
 static const char *const ppsz_clock_master_descriptions[] = {
     N_("Audio"),
@@ -1977,9 +1976,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,
+    add_string( "clock-master", "audio",
                  CLOCK_MASTER_TEXT, NULL, true )
-        change_integer_list( pi_clock_master_values, ppsz_clock_master_descriptions )
+        change_string_list( ppsz_clock_master_values, ppsz_clock_master_descriptions )
 
     add_directory("input-record-path", NULL,
                   INPUT_RECORD_PATH_TEXT, INPUT_RECORD_PATH_LONGTEXT)



More information about the vlc-commits mailing list