[vlc-devel] [PATCH 08/14] vlm: call vlm via ops

Romain Vimont rom1v at videolabs.io
Tue Sep 15 19:37:40 CEST 2020


This paves the way to move the implementation to a separate module.
---
 include/vlc_vlm.h | 28 ++++++++++++++++++++++++++--
 src/input/vlm.c   | 26 ++++++++++++++++----------
 2 files changed, 42 insertions(+), 12 deletions(-)

diff --git a/include/vlc_vlm.h b/include/vlc_vlm.h
index 1338f8af72..2c422478de 100644
--- a/include/vlc_vlm.h
+++ b/include/vlc_vlm.h
@@ -26,9 +26,17 @@
 
 #include <vlc_input.h>
 
+struct vlm_ops
+{
+    int (*execute)(vlm_t *vlm, const char *cmd, vlm_message_t **msg_out);
+    int (*va_control)(vlm_t *vlm, int query, va_list list);
+};
+
 struct vlm_t
 {
     struct vlc_object_t obj;
+
+    const struct vlm_ops *ops;
     void *sys;
 };
 
@@ -194,8 +202,24 @@ extern "C" {
 
 VLC_API vlm_t * vlm_New( libvlc_int_t * );
 VLC_API void vlm_Delete( vlm_t * );
-VLC_API int vlm_ExecuteCommand( vlm_t *, const char *, vlm_message_t ** );
-VLC_API int vlm_Control( vlm_t *p_vlm, int i_query, ... );
+
+static inline int
+vlm_ExecuteCommand( vlm_t *vlm, const char *cmd, vlm_message_t **msg_out)
+{
+    return vlm->ops->execute(vlm, cmd, msg_out);
+}
+
+static inline int
+vlm_Control( vlm_t *vlm, int query, ...)
+{
+    va_list args;
+
+    va_start(args, query);
+    int res = vlm->ops->va_control(vlm, query, args);
+    va_end(args);
+
+    return res;
+}
 
 VLC_API int vlm_LoadFile( vlm_t *p_vlm, const char *psz_vlmconf );
 
diff --git a/src/input/vlm.c b/src/input/vlm.c
index bb876011dc..dc6e2ab0e0 100644
--- a/src/input/vlm.c
+++ b/src/input/vlm.c
@@ -110,6 +110,15 @@ static void player_on_state_changed(vlc_player_t *player,
 
 static vlc_mutex_t vlm_mutex = VLC_STATIC_MUTEX;
 
+static int ExecuteCommandImpl( vlm_t *vlm, const char *cmd,
+                               vlm_message_t **msg_out );
+static int VaControlImpl( vlm_t *vlm, int query, va_list args );
+
+static const struct vlm_ops vlm_ops = {
+    .execute = ExecuteCommandImpl,
+    .va_control = VaControlImpl,
+};
+
 /*****************************************************************************
  * vlm_New:
  *****************************************************************************/
@@ -172,6 +181,8 @@ vlm_t *vlm_New( libvlc_int_t *libvlc )
         return NULL;
     }
 
+    p_vlm->ops = &vlm_ops;
+
     *pp_vlm = p_vlm; /* for future reference */
 
     vlc_mutex_unlock( &vlm_mutex );
@@ -250,8 +261,8 @@ void vlm_Delete( vlm_t *p_vlm )
 /*****************************************************************************
  * vlm_ExecuteCommand:
  *****************************************************************************/
-int vlm_ExecuteCommand( vlm_t *p_vlm, const char *psz_command,
-                        vlm_message_t **pp_message)
+static int ExecuteCommandImpl( vlm_t *p_vlm, const char *psz_command,
+                               vlm_message_t **pp_message)
 {
     int i_result;
 
@@ -995,21 +1006,16 @@ int vlm_ControlInternal( vlm_t *p_vlm, int i_query, ... )
     return i_result;
 }
 
-int vlm_Control( vlm_t *p_vlm, int i_query, ... )
+static int VaControlImpl( vlm_t *p_vlm, int i_query, va_list args )
 {
-    vlm_sys_t *sys = p_vlm->sys;
-
-    va_list args;
-    int     i_result;
+    int i_result;
 
-    va_start( args, i_query );
+    vlm_sys_t *sys = p_vlm->sys;
 
     vlc_mutex_lock( &sys->lock );
     i_result = vlm_vaControlInternal( p_vlm, i_query, args );
     vlc_mutex_unlock( &sys->lock );
 
-    va_end( args );
-
     return i_result;
 }
 
-- 
2.28.0



More information about the vlc-devel mailing list