1 /*****************************************************************************
2 * filter.c : filter_t helpers.
3 *****************************************************************************
4 * Copyright (C) 2009 Laurent Aimar
6 * Author: Laurent Aimar <fenrir _AT_ videolan _DOT_ org>
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU Lesser General Public License as published by
10 * the Free Software Foundation; either version 2.1 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with this program; if not, write to the Free Software Foundation,
20 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
21 *****************************************************************************/
29 #include <vlc_common.h>
31 #include <vlc_filter.h>
32 #include <vlc_modules.h>
33 #include "../misc/variables.h"
37 static int TriggerFilterCallback(vlc_object_t
*p_this
, char const *psz_var
,
38 vlc_value_t oldval
, vlc_value_t newval
,
41 (void) p_this
; (void) oldval
;
42 var_Set((filter_t
*)p_data
, psz_var
, newval
);
46 #undef filter_AddProxyCallbacks
47 void filter_AddProxyCallbacks( vlc_object_t
*obj
, filter_t
*filter
,
48 vlc_callback_t restart_cb
)
50 char **names
= var_GetAllNames(VLC_OBJECT(filter
));
54 for (char **pname
= names
; *pname
!= NULL
; pname
++)
57 int var_type
= var_Type(filter
, name
);
58 if (var_Type(obj
, name
) || config_GetType(name
) == 0)
64 var_type
| VLC_VAR_DOINHERIT
| VLC_VAR_ISCOMMAND
);
65 if ((var_type
& VLC_VAR_ISCOMMAND
))
66 var_AddCallback(obj
, name
, TriggerFilterCallback
, filter
);
68 var_AddCallback(obj
, name
, restart_cb
, obj
);
74 #undef filter_DelProxyCallbacks
75 void filter_DelProxyCallbacks( vlc_object_t
*obj
, filter_t
*filter
,
76 vlc_callback_t restart_cb
)
78 char **names
= var_GetAllNames(VLC_OBJECT(filter
));
82 for (char **pname
= names
; *pname
!= NULL
; pname
++)
85 if (!(var_Type(obj
, name
) & VLC_VAR_ISCOMMAND
))
90 int filter_var_type
= var_Type(filter
, name
);
92 if (filter_var_type
& VLC_VAR_ISCOMMAND
)
93 var_DelCallback(obj
, name
, TriggerFilterCallback
, filter
);
94 else if (filter_var_type
)
95 var_DelCallback(obj
, name
, restart_cb
, obj
);
96 var_Destroy(obj
, name
);
104 vlc_blender_t
*filter_NewBlend( vlc_object_t
*p_this
,
105 const video_format_t
*p_dst_chroma
)
107 vlc_blender_t
*p_blend
= vlc_custom_create( p_this
, sizeof(*p_blend
), "blend" );
111 es_format_Init( &p_blend
->fmt_in
, VIDEO_ES
, 0 );
113 es_format_Init( &p_blend
->fmt_out
, VIDEO_ES
, 0 );
115 p_blend
->fmt_out
.i_codec
=
116 p_blend
->fmt_out
.video
.i_chroma
= p_dst_chroma
->i_chroma
;
117 p_blend
->fmt_out
.video
.i_rmask
= p_dst_chroma
->i_rmask
;
118 p_blend
->fmt_out
.video
.i_gmask
= p_dst_chroma
->i_gmask
;
119 p_blend
->fmt_out
.video
.i_bmask
= p_dst_chroma
->i_bmask
;
121 /* The blend module will be loaded when needed with the real
123 p_blend
->p_module
= NULL
;
128 int filter_ConfigureBlend( vlc_blender_t
*p_blend
,
129 int i_dst_width
, int i_dst_height
,
130 const video_format_t
*p_src
)
133 if( p_blend
->p_module
&&
134 p_blend
->fmt_in
.video
.i_chroma
!= p_src
->i_chroma
)
136 /* The chroma is not the same, we need to reload the blend module */
137 filter_Close( p_blend
);
138 module_unneed( p_blend
, p_blend
->p_module
);
139 p_blend
->p_module
= NULL
;
144 p_blend
->fmt_in
.i_codec
= p_src
->i_chroma
;
145 p_blend
->fmt_in
.video
= *p_src
;
148 p_blend
->fmt_out
.video
.i_width
=
149 p_blend
->fmt_out
.video
.i_visible_width
= i_dst_width
;
150 p_blend
->fmt_out
.video
.i_height
=
151 p_blend
->fmt_out
.video
.i_visible_height
= i_dst_height
;
154 if( !p_blend
->p_module
)
155 p_blend
->p_module
= module_need( p_blend
, "video blending", NULL
, false );
156 if( !p_blend
->p_module
)
158 assert( p_blend
->ops
!= NULL
);
162 int filter_Blend( vlc_blender_t
*p_blend
,
163 picture_t
*p_dst
, int i_dst_x
, int i_dst_y
,
164 const picture_t
*p_src
, int i_alpha
)
166 if( !p_blend
->p_module
)
169 p_blend
->ops
->blend_video( p_blend
, p_dst
, p_src
, i_dst_x
, i_dst_y
, i_alpha
);
173 void filter_DeleteBlend( vlc_blender_t
*p_blend
)
175 if( p_blend
->p_module
)
177 filter_Close( p_blend
);
178 module_unneed( p_blend
, p_blend
->p_module
);
181 vlc_object_delete(p_blend
);
185 #include <vlc_video_splitter.h>
187 video_splitter_t
*video_splitter_New( vlc_object_t
*p_this
,
188 const char *psz_name
,
189 const video_format_t
*p_fmt
)
191 video_splitter_t
*p_splitter
= vlc_custom_create( p_this
,
192 sizeof(*p_splitter
), "video splitter" );
196 video_format_Copy( &p_splitter
->fmt
, p_fmt
);
199 p_splitter
->p_module
= module_need( p_splitter
, "video splitter", psz_name
, true );
200 if( ! p_splitter
->p_module
)
202 video_splitter_Delete( p_splitter
);
209 void video_splitter_Delete( video_splitter_t
*p_splitter
)
211 if( p_splitter
->p_module
)
212 module_unneed( p_splitter
, p_splitter
->p_module
);
214 video_format_Clean( &p_splitter
->fmt
);
215 vlc_object_delete(p_splitter
);