Commit 6e6eec39 authored by Victorien Le Couviour--Tuffet's avatar Victorien Le Couviour--Tuffet Committed by Thomas Guillem

filter: move filter proxy callbacks system from vout to filter

parent 4d35bc81
......@@ -214,6 +214,29 @@ static inline int filter_GetInputAttachments( filter_t *p_filter,
ppp_attachment, pi_attachment );
}
/**
* 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.
*
......
......@@ -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
......
......@@ -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 )
......
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment