[vlc-commits] filter: move filter proxy callbacks system from vout to filter

Victorien Le Couviour--Tuffet git at videolan.org
Sat Jul 1 18:24:56 CEST 2017


vlc | branch: master | Victorien Le Couviour--Tuffet <victorien.lecouviour.tuffet at gmail.com> | Fri Jun 23 15:26:41 2017 +0200| [6e6eec39702510677d503205f9005ddb468fed48] | committer: Thomas Guillem

filter: move filter proxy callbacks system from vout to filter

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

 include/vlc_filter.h            | 23 +++++++++++++++
 src/libvlccore.sym              |  2 ++
 src/misc/filter.c               | 65 +++++++++++++++++++++++++++++++++++++++++
 src/video_output/video_output.c | 57 ++----------------------------------
 4 files changed, 93 insertions(+), 54 deletions(-)

diff --git a/include/vlc_filter.h b/include/vlc_filter.h
index 3db7281671..52b84ba655 100644
--- a/include/vlc_filter.h
+++ b/include/vlc_filter.h
@@ -215,6 +215,29 @@ static inline int filter_GetInputAttachments( filter_t *p_filter,
 }
 
 /**
+ * This function duplicates every variables from the filter, and adds a proxy
+ * callback to trigger filter events from obj.
+ *
+ * \param restart_cb a vlc_callback_t to call if the event means restarting the
+ * filter (i.e. an event on a non-command variable)
+ */
+VLC_API void filter_AddProxyCallbacks( vlc_object_t *obj, filter_t *filter,
+                                       vlc_callback_t restart_cb );
+# define filter_AddProxyCallbacks(a, b, c) \
+    filter_AddProxyCallbacks(VLC_OBJECT(a), b, c)
+
+/**
+ * This function removes the callbacks previously added to every duplicated
+ * variables, and removes them afterward.
+ *
+ * \param restart_cb the same vlc_callback_t passed to filter_AddProxyCallbacks
+ */
+VLC_API void filter_DelProxyCallbacks( vlc_object_t *obj, filter_t *filter,
+                                       vlc_callback_t restart_cb);
+# define filter_DelProxyCallbacks(a, b, c) \
+    filter_DelProxyCallbacks(VLC_OBJECT(a), b, c)
+
+/**
  * It creates a blend filter.
  *
  * Only the chroma properties of the dest format is used (chroma
diff --git a/src/libvlccore.sym b/src/libvlccore.sym
index 58a54bb0f0..93c56d3749 100644
--- a/src/libvlccore.sym
+++ b/src/libvlccore.sym
@@ -98,6 +98,8 @@ es_format_Copy
 es_format_Init
 es_format_InitFromVideo
 es_format_IsSimilar
+filter_AddProxyCallbacks
+filter_DelProxyCallbacks
 filter_Blend
 filter_chain_AppendConverter
 filter_chain_AppendFilter
diff --git a/src/misc/filter.c b/src/misc/filter.c
index 36f1ba444c..7a2deb14ec 100644
--- a/src/misc/filter.c
+++ b/src/misc/filter.c
@@ -25,10 +25,75 @@
 # include "config.h"
 #endif
 
+#include <assert.h>
+
 #include <vlc_common.h>
 #include <libvlc.h>
 #include <vlc_filter.h>
 #include <vlc_modules.h>
+#include "../misc/variables.h"
+
+/* */
+
+static int TriggerFilterCallback(vlc_object_t *p_this, char const *psz_var,
+                                 vlc_value_t oldval, vlc_value_t newval,
+                                 void *p_data)
+{
+    (void) p_this; (void) oldval;
+    var_Set((filter_t *)p_data, psz_var, newval);
+    return 0;
+}
+
+#undef filter_AddProxyCallbacks
+void filter_AddProxyCallbacks( vlc_object_t *obj, filter_t *filter,
+                               vlc_callback_t restart_cb )
+{
+    char **names = var_GetAllNames(VLC_OBJECT(filter));
+    if (names == NULL)
+        return;
+
+    for (char **pname = names; *pname != NULL; pname++)
+    {
+        char *name = *pname;
+        int var_type = var_Type(filter, name);
+        assert(var_Type(obj, name) == 0);
+        var_Create(obj, name,
+                   var_type | VLC_VAR_DOINHERIT | VLC_VAR_ISCOMMAND);
+        if ((var_type & VLC_VAR_ISCOMMAND))
+            var_AddCallback(obj, name, TriggerFilterCallback, filter);
+        else
+            var_AddCallback(obj, name, restart_cb, obj);
+        free(name);
+    }
+    free(names);
+}
+
+#undef filter_DelProxyCallbacks
+void filter_DelProxyCallbacks( vlc_object_t *obj, filter_t *filter,
+                               vlc_callback_t restart_cb )
+{
+    char **names = var_GetAllNames(VLC_OBJECT(filter));
+    if (names == NULL)
+        return;
+
+    for (char **pname = names; *pname != NULL; pname++)
+    {
+        char *name = *pname;
+        if (!(var_Type(obj, name) & VLC_VAR_ISCOMMAND))
+            continue;
+        int filter_var_type = var_Type(filter, name);
+
+        if (filter_var_type & VLC_VAR_ISCOMMAND)
+            var_DelCallback(obj, name, TriggerFilterCallback, filter);
+        else if (filter_var_type)
+            var_DelCallback(obj, name, restart_cb, obj);
+        var_Destroy(obj, name);
+        free(name);
+    }
+    free(names);
+}
+
+/* */
 
 filter_t *filter_NewBlend( vlc_object_t *p_this,
                            const video_format_t *p_dst_chroma )
diff --git a/src/video_output/video_output.c b/src/video_output/video_output.c
index 41c3d892fe..9448face90 100644
--- a/src/video_output/video_output.c
+++ b/src/video_output/video_output.c
@@ -651,15 +651,6 @@ int vout_HideWindowMouse(vout_thread_t *vout, bool hide)
 }
 
 /* */
-static int FilterProxyCallback(vlc_object_t *p_this, char const *psz_var,
-                         vlc_value_t oldval, vlc_value_t newval,
-                         void *p_data)
-{
-    (void) p_this; (void) oldval;
-    var_Set((filter_t *)p_data, psz_var, newval);
-    return 0;
-}
-
 static int FilterRestartCallback(vlc_object_t *p_this, char const *psz_var,
                                  vlc_value_t oldval, vlc_value_t newval,
                                  void *p_data)
@@ -669,52 +660,10 @@ static int FilterRestartCallback(vlc_object_t *p_this, char const *psz_var,
     return 0;
 }
 
-static void ThreadAddFilterCallbacks(vout_thread_t *vout, filter_t *filter)
-{
-    /* Duplicate every command variables from the filter, and add a proxy
-     * callback to trigger filters events from the vout. */
-
-    char **names = var_GetAllNames(VLC_OBJECT(filter));
-    if (names == NULL)
-        return;
-
-    for (char **pname = names; *pname != NULL; pname++)
-    {
-        char *name = *pname;
-        int var_type = var_Type(filter, name);
-        assert(var_Type(vout, name) == 0);
-        var_Create(vout, name, var_type | VLC_VAR_DOINHERIT | VLC_VAR_ISCOMMAND);
-        if ((var_type & VLC_VAR_ISCOMMAND))
-            var_AddCallback(vout, name, FilterProxyCallback, filter);
-        else
-            var_AddCallback(vout, name, FilterRestartCallback, vout);
-        free(name);
-    }
-    free(names);
-}
-
 static int ThreadDelFilterCallbacks(filter_t *filter, void *opaque)
 {
-    vout_thread_t *vout = opaque;
-    char **names = var_GetAllNames(VLC_OBJECT(filter));
-    if (names == NULL)
-        return VLC_SUCCESS;
-
-    for (char **pname = names; *pname != NULL; pname++)
-    {
-        char *name = *pname;
-        int var_type = var_Type(vout, name);
-        assert(var_type & VLC_VAR_ISCOMMAND);
-        int filter_var_type = var_Type(filter, name);
-
-        if (filter_var_type & VLC_VAR_ISCOMMAND)
-            var_DelCallback(vout, name, FilterProxyCallback, filter);
-        else if (filter_var_type)
-            var_DelCallback(vout, name, FilterRestartCallback, vout);
-        var_Destroy(vout, name);
-        free(name);
-    }
-    free(names);
+    filter_DelProxyCallbacks((vlc_object_t *)opaque, filter,
+                             FilterRestartCallback);
     return VLC_SUCCESS;
 }
 
@@ -855,7 +804,7 @@ static void ThreadChangeFilters(vout_thread_t *vout,
                 config_ChainDestroy(e->cfg);
             }
             else if (a == 1) /* Add callbacks for interactive filters */
-                ThreadAddFilterCallbacks(vout, filter);
+                filter_AddProxyCallbacks(vout, filter, FilterRestartCallback);
 
             free(e->name);
             free(e);



More information about the vlc-commits mailing list