[vlc-commits] variables: make forth var_Change() argument optional

Rémi Denis-Courmont git at videolan.org
Sun Jun 10 12:10:52 CEST 2018


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sat Jun  9 13:03:55 2018 +0300| [d01c9337a44291799cf0b0844340fd81bdea7576] | committer: Rémi Denis-Courmont

variables: make forth var_Change() argument optional

Most requests do not actually need it.

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

 include/vlc_variables.h   |  5 ++---
 lib/audio.c               |  3 ++-
 lib/video.c               |  8 +++++---
 modules/gui/ncurses.c     |  3 ++-
 src/audio_output/output.c |  3 ++-
 src/input/input.c         |  3 ++-
 src/misc/variables.c      | 16 +++++++++++++---
 7 files changed, 28 insertions(+), 13 deletions(-)

diff --git a/include/vlc_variables.h b/include/vlc_variables.h
index 09c1913d8a..0be78c8023 100644
--- a/include/vlc_variables.h
+++ b/include/vlc_variables.h
@@ -147,10 +147,9 @@ VLC_API void var_Destroy(vlc_object_t *obj, const char *name);
  * \param name Variable name
  * \param action Action to perform. Must be one of \ref var_action
  * \param val First action parameter
- * \param val2 Second action parameter
  */
 VLC_API int var_Change(vlc_object_t *obj, const char *name, int action,
-                       vlc_value_t *val, vlc_value_t *val2);
+                       vlc_value_t *val, ...);
 
 /**
  * Get the type of a variable.
@@ -780,7 +779,7 @@ VLC_API int var_LocationParse(vlc_object_t *, const char *mrl, const char *prefi
 #ifndef DOC
 #define var_Create(a,b,c) var_Create(VLC_OBJECT(a), b, c)
 #define var_Destroy(a,b) var_Destroy(VLC_OBJECT(a), b)
-#define var_Change(a,b,c,d,e) var_Change(VLC_OBJECT(a), b, c, d, e)
+#define var_Change(a,b,c,...) var_Change(VLC_OBJECT(a), b, c, __VA_ARGS__)
 #define var_Type(a,b) var_Type(VLC_OBJECT(a), b)
 #define var_Set(a,b,c) var_Set(VLC_OBJECT(a), b, c)
 #define var_Get(a,b,c) var_Get(VLC_OBJECT(a), b, c)
diff --git a/lib/audio.c b/lib/audio.c
index 0c4285b1de..0ea1cd4023 100644
--- a/lib/audio.c
+++ b/lib/audio.c
@@ -387,7 +387,8 @@ int libvlc_audio_set_track( libvlc_media_player_t *p_mi, int i_track )
     if( !p_input_thread )
         return -1;
 
-    var_Change( p_input_thread, "audio-es", VLC_VAR_GETCHOICES, &val_list, NULL );
+    var_Change( p_input_thread, "audio-es", VLC_VAR_GETCHOICES, &val_list,
+                (vlc_value_t *)NULL );
     for( int i = 0; i < val_list.p_list->i_count; i++ )
     {
         if( i_track == val_list.p_list->p_values[i].i_int )
diff --git a/lib/video.c b/lib/video.c
index 3071b14157..e9f95fc2c7 100644
--- a/lib/video.c
+++ b/lib/video.c
@@ -359,7 +359,8 @@ int libvlc_video_set_spu( libvlc_media_player_t *p_mi, int i_spu )
     if( !p_input_thread )
         return -1;
 
-    var_Change (p_input_thread, "spu-es", VLC_VAR_GETCHOICES, &list, NULL);
+    var_Change(p_input_thread, "spu-es", VLC_VAR_GETCHOICES, &list,
+               (vlc_value_t *)NULL);
     for (int i = 0; i < list.p_list->i_count; i++)
     {
         if( i_spu == list.p_list->p_values[i].i_int )
@@ -452,7 +453,7 @@ static void teletext_enable( input_thread_t *p_input_thread, bool b_enable )
     {
         vlc_value_t list;
         if( !var_Change( p_input_thread, "teletext-es", VLC_VAR_GETCHOICES,
-                         &list, NULL ) )
+                         &list, (vlc_value_t *)NULL ) )
         {
             if( list.p_list->i_count > 0 )
                 var_SetInteger( p_input_thread, "spu-es",
@@ -573,7 +574,8 @@ int libvlc_video_set_track( libvlc_media_player_t *p_mi, int i_track )
     if( !p_input_thread )
         return -1;
 
-    var_Change( p_input_thread, "video-es", VLC_VAR_GETCHOICES, &val_list, NULL );
+    var_Change( p_input_thread, "video-es", VLC_VAR_GETCHOICES, &val_list,
+                (vlc_value_t *)NULL );
     for( int i = 0; i < val_list.p_list->i_count; i++ )
     {
         if( i_track == val_list.p_list->p_values[i].i_int )
diff --git a/modules/gui/ncurses.c b/modules/gui/ncurses.c
index 876eda8ac4..5b50f5a52e 100644
--- a/modules/gui/ncurses.c
+++ b/modules/gui/ncurses.c
@@ -1530,7 +1530,8 @@ static void CycleESTrack(input_thread_t *input, const char *var)
         return;
 
     vlc_value_t val;
-    if (var_Change(input, var, VLC_VAR_GETCHOICES, &val, NULL) < 0)
+    if (var_Change(input, var, VLC_VAR_GETCHOICES, &val,
+                   (vlc_value_t *)NULL) < 0)
         return;
 
     vlc_list_t *list = val.p_list;
diff --git a/src/audio_output/output.c b/src/audio_output/output.c
index adc816827c..423cbb22ce 100644
--- a/src/audio_output/output.c
+++ b/src/audio_output/output.c
@@ -489,7 +489,8 @@ static void aout_PrepareStereoMode (audio_output_t *aout,
 
     bool mode_available = false;
     vlc_value_t vals;
-    if (!var_Change(aout, "stereo-mode", VLC_VAR_GETCHOICES, &vals, NULL))
+    if (!var_Change(aout, "stereo-mode", VLC_VAR_GETCHOICES, &vals,
+                    (vlc_value_t *)NULL))
     {
         for (int i = 0; !mode_available && i < vals.p_list->i_count; ++i)
         {
diff --git a/src/input/input.c b/src/input/input.c
index 80fcea5d3d..38fc3b0fe0 100644
--- a/src/input/input.c
+++ b/src/input/input.c
@@ -3279,7 +3279,8 @@ static int input_SlaveSourceAdd( input_thread_t *p_input,
     /* Select the ES */
     vlc_value_t list;
 
-    if( var_Change( p_input, psz_es, VLC_VAR_GETCHOICES, &list, NULL ) )
+    if( var_Change( p_input, psz_es, VLC_VAR_GETCHOICES, &list,
+                    (vlc_value_t *)NULL ) )
         return VLC_SUCCESS;
 
     if( count.i_int == 0 )
diff --git a/src/misc/variables.c b/src/misc/variables.c
index 2de43df165..174a8f6fab 100644
--- a/src/misc/variables.c
+++ b/src/misc/variables.c
@@ -421,8 +421,9 @@ void var_DestroyAll( vlc_object_t *obj )
 }
 
 int (var_Change)(vlc_object_t *p_this, const char *psz_name,
-                 int i_action, vlc_value_t *p_val, vlc_value_t *p_val2)
+                 int i_action, vlc_value_t *p_val, ...)
 {
+    va_list ap;
     int ret = VLC_SUCCESS;
     variable_t *p_var;
     vlc_value_t oldval;
@@ -439,6 +440,7 @@ int (var_Change)(vlc_object_t *p_this, const char *psz_name,
         return VLC_ENOVAR;
     }
 
+    va_start(ap, p_val);
     switch( i_action )
     {
         case VLC_VAR_GETMIN:
@@ -448,10 +450,14 @@ int (var_Change)(vlc_object_t *p_this, const char *psz_name,
             *p_val = p_var->max;
             break;
         case VLC_VAR_SETMINMAX:
+        {
+            const vlc_value_t *p_val2 = va_arg(ap, vlc_value_t *);
+
             assert(p_var->ops->pf_free == FreeDummy);
             p_var->min = *p_val;
             p_var->max = *p_val2;
             break;
+        }
         case VLC_VAR_SETSTEP:
             assert(p_var->ops->pf_free == FreeDummy);
             p_var->step = *p_val;
@@ -476,6 +482,7 @@ int (var_Change)(vlc_object_t *p_this, const char *psz_name,
             break;
         case VLC_VAR_ADDCHOICE:
         {
+            const vlc_value_t *p_val2 = va_arg(ap, vlc_value_t *);
             int i = p_var->choices.i_count;
 
             TAB_APPEND(p_var->choices.i_count,
@@ -546,6 +553,9 @@ int (var_Change)(vlc_object_t *p_this, const char *psz_name,
             p_var->ops->pf_free( &oldval );
             break;
         case VLC_VAR_GETCHOICES:
+        {
+            vlc_value_t *p_val2 = va_arg(ap, vlc_value_t *);
+
             p_val->p_list = xmalloc( sizeof(vlc_list_t) );
             p_val->p_list->p_values =
                 xmalloc( p_var->choices.i_count * sizeof(vlc_value_t) );
@@ -571,6 +581,7 @@ int (var_Change)(vlc_object_t *p_this, const char *psz_name,
                 }
             }
             break;
+        }
         case VLC_VAR_SETTEXT:
             free( p_var->psz_text );
             if( p_val && p_val->psz_string )
@@ -585,9 +596,8 @@ int (var_Change)(vlc_object_t *p_this, const char *psz_name,
         default:
             break;
     }
-
+    va_end(ap);
     vlc_mutex_unlock( &p_priv->var_lock );
-
     return ret;
 }
 



More information about the vlc-commits mailing list