Remove legacy parameter from add_string()
[vlc/asuraparaju-public.git] / modules / video_filter / clone.c
blobb6bf4d820e6431f9d7bb8a0feef4d6cd691deac7
1 /*****************************************************************************
2 * clone.c : Clone video plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2002-2009 the VideoLAN team
5 * $Id$
7 * Authors: Samuel Hocevar <sam@zoy.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 /*****************************************************************************
25 * Preamble
26 *****************************************************************************/
28 #ifdef HAVE_CONFIG_H
29 # include "config.h"
30 #endif
32 #include <vlc_common.h>
33 #include <vlc_plugin.h>
34 #include <vlc_video_splitter.h>
36 /*****************************************************************************
37 * Module descriptor
38 *****************************************************************************/
39 #define COUNT_TEXT N_("Number of clones")
40 #define COUNT_LONGTEXT N_("Number of video windows in which to "\
41 "clone the video.")
43 #define VOUTLIST_TEXT N_("Video output modules")
44 #define VOUTLIST_LONGTEXT N_("You can use specific video output modules " \
45 "for the clones. Use a comma-separated list of modules." )
47 #define CLONE_HELP N_("Duplicate your video to multiple windows " \
48 "and/or video output modules")
49 #define CFG_PREFIX "clone-"
51 static int Open ( vlc_object_t * );
52 static void Close( vlc_object_t * );
54 vlc_module_begin ()
55 set_description( N_("Clone video filter") )
56 set_capability( "video splitter", 0 )
57 set_shortname( N_("Clone" ))
58 set_help(CLONE_HELP)
59 set_category( CAT_VIDEO )
60 set_subcategory( SUBCAT_VIDEO_VFILTER )
62 add_integer( CFG_PREFIX "count", 2, NULL, COUNT_TEXT, COUNT_LONGTEXT, false )
63 add_string ( CFG_PREFIX "vout-list", NULL, VOUTLIST_TEXT, VOUTLIST_LONGTEXT, true )
65 add_shortcut( "clone" )
66 set_callbacks( Open, Close )
67 vlc_module_end ()
69 /*****************************************************************************
70 * Local prototypes
71 *****************************************************************************/
72 static const char *const ppsz_filter_options[] = {
73 "count", "vout-list", NULL
76 #define VOUTSEPARATOR ','
78 static int Filter( video_splitter_t *, picture_t *pp_dst[], picture_t * );
80 /**
81 * This function allocates and initializes a Clone splitter module
83 static int Open( vlc_object_t *p_this )
85 video_splitter_t *p_splitter = (video_splitter_t*)p_this;
87 config_ChainParse( p_splitter, CFG_PREFIX, ppsz_filter_options,
88 p_splitter->p_cfg );
90 char *psz_clonelist = var_CreateGetNonEmptyString( p_splitter,
91 CFG_PREFIX "vout-list" );
92 if( psz_clonelist )
94 /* Count the number of defined vout */
95 p_splitter->i_output = 1;
96 for( int i = 0; psz_clonelist[i]; i++ )
98 if( psz_clonelist[i] == VOUTSEPARATOR )
99 p_splitter->i_output++;
102 /* */
103 p_splitter->p_output = calloc( p_splitter->i_output,
104 sizeof(*p_splitter->p_output) );
105 if( !p_splitter->p_output )
107 free( psz_clonelist );
108 return VLC_EGENERIC;
111 /* Tokenize the list */
112 char *psz_tmp = psz_clonelist;
113 for( int i = 0; psz_tmp && *psz_tmp; i++ )
115 char *psz_new = strchr( psz_tmp, VOUTSEPARATOR );
116 if( psz_new )
117 *psz_new++ = '\0';
119 p_splitter->p_output[i].psz_module = strdup( psz_tmp );
121 psz_tmp = psz_new;
124 free( psz_clonelist );
126 else
128 /* No list was specified. We will use the default vout, and get
129 * the number of clones from clone-count */
130 p_splitter->i_output = var_CreateGetInteger( p_splitter, CFG_PREFIX "count" );
131 if( p_splitter->i_output <= 0 )
132 p_splitter->i_output = 1;
134 p_splitter->p_output = calloc( p_splitter->i_output,
135 sizeof(*p_splitter->p_output) );
137 if( !p_splitter->p_output )
138 return VLC_EGENERIC;
140 for( int i = 0; i < p_splitter->i_output; i++ )
141 p_splitter->p_output[i].psz_module = NULL;
144 /* */
145 for( int i = 0; i < p_splitter->i_output; i++ )
147 video_splitter_output_t *p_cfg = &p_splitter->p_output[i];
148 video_format_Copy( &p_cfg->fmt, &p_splitter->fmt );
149 p_cfg->window.i_x = 0;
150 p_cfg->window.i_y = 0;
151 p_cfg->window.i_align = 0;
154 /* */
155 p_splitter->pf_filter = Filter;
156 p_splitter->pf_mouse = NULL;
158 msg_Dbg( p_splitter, "spawning %i clone(s)", p_splitter->i_output );
160 return VLC_SUCCESS;
164 * This function closes a clone video splitter module
166 static void Close( vlc_object_t *p_this )
168 video_splitter_t *p_splitter = (video_splitter_t*)p_this;
170 for( int i = 0; i < p_splitter->i_output; i++ )
172 video_splitter_output_t *p_cfg = &p_splitter->p_output[i];
174 free( p_cfg->psz_module );
175 video_format_Clean( &p_cfg->fmt );
177 free( p_splitter->p_output );
181 * This function filter a picture
183 static int Filter( video_splitter_t *p_splitter,
184 picture_t *pp_dst[], picture_t *p_src )
186 if( video_splitter_NewPicture( p_splitter, pp_dst ) )
188 picture_Release( p_src );
189 return VLC_EGENERIC;
192 for( int i = 0; i < p_splitter->i_output; i++ )
193 picture_Copy( pp_dst[i], p_src );
195 picture_Release( p_src );
196 return VLC_SUCCESS;