1 /*****************************************************************************
2 * clone.c : Clone video plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2002-2009 the VideoLAN team
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 /*****************************************************************************
26 *****************************************************************************/
32 #include <vlc_common.h>
33 #include <vlc_plugin.h>
34 #include <vlc_video_splitter.h>
36 /*****************************************************************************
38 *****************************************************************************/
39 #define COUNT_TEXT N_("Number of clones")
40 #define COUNT_LONGTEXT N_("Number of video windows in which to "\
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 CFG_PREFIX "clone-"
49 static int Open ( vlc_object_t * );
50 static void Close( vlc_object_t * );
53 set_description( N_("Clone video filter") )
54 set_capability( "video splitter", 0 )
55 set_shortname( N_("Clone" ))
56 set_category( CAT_VIDEO )
57 set_subcategory( SUBCAT_VIDEO_VFILTER )
59 add_integer( CFG_PREFIX "count", 2, NULL, COUNT_TEXT, COUNT_LONGTEXT, false )
60 add_string ( CFG_PREFIX "vout-list", NULL, NULL, VOUTLIST_TEXT, VOUTLIST_LONGTEXT, true )
62 add_shortcut( "clone" )
63 set_callbacks( Open, Close )
66 /*****************************************************************************
68 *****************************************************************************/
69 static const char *const ppsz_filter_options[] = {
70 "count", "vout-list", NULL
73 #define VOUTSEPARATOR ','
75 static int Filter( video_splitter_t *, picture_t *pp_dst[], picture_t * );
78 * This function allocates and initializes a Clone splitter module
80 static int Open( vlc_object_t *p_this )
82 video_splitter_t *p_splitter = (video_splitter_t*)p_this;
84 config_ChainParse( p_splitter, CFG_PREFIX, ppsz_filter_options,
87 char *psz_clonelist = var_CreateGetNonEmptyString( p_splitter,
88 CFG_PREFIX "vout-list" );
91 /* Count the number of defined vout */
92 p_splitter->i_output = 1;
93 for( int i = 0; psz_clonelist[i]; i++ )
95 if( psz_clonelist[i] == VOUTSEPARATOR )
96 p_splitter->i_output++;
100 p_splitter->p_output = calloc( p_splitter->i_output,
101 sizeof(*p_splitter->p_output) );
102 if( !p_splitter->p_output )
104 free( psz_clonelist );
108 /* Tokenize the list */
109 char *psz_tmp = psz_clonelist;
110 for( int i = 0; psz_tmp && *psz_tmp; i++ )
112 char *psz_new = strchr( psz_tmp, VOUTSEPARATOR );
116 p_splitter->p_output[i].psz_module = strdup( psz_tmp );
121 free( psz_clonelist );
125 /* No list was specified. We will use the default vout, and get
126 * the number of clones from clone-count */
127 p_splitter->i_output = var_CreateGetInteger( p_splitter, CFG_PREFIX "count" );
128 if( p_splitter->i_output <= 0 )
129 p_splitter->i_output = 1;
131 p_splitter->p_output = calloc( p_splitter->i_output,
132 sizeof(*p_splitter->p_output) );
134 if( !p_splitter->p_output )
137 for( int i = 0; i < p_splitter->i_output; i++ )
138 p_splitter->p_output[i].psz_module = NULL;
142 for( int i = 0; i < p_splitter->i_output; i++ )
144 video_splitter_output_t *p_cfg = &p_splitter->p_output[i];
145 video_format_Copy( &p_cfg->fmt, &p_splitter->fmt );
146 p_cfg->window.i_x = -1;
147 p_cfg->window.i_y = -1;
148 p_cfg->window.i_align = 0;
152 p_splitter->pf_filter = Filter;
153 p_splitter->pf_mouse = NULL;
155 msg_Dbg( p_splitter, "spawning %i clone(s)", p_splitter->i_output );
161 * This function closes a clone video splitter module
163 static void Close( vlc_object_t *p_this )
165 video_splitter_t *p_splitter = (video_splitter_t*)p_this;
167 for( int i = 0; i < p_splitter->i_output; i++ )
169 video_splitter_output_t *p_cfg = &p_splitter->p_output[i];
171 free( p_cfg->psz_module );
172 video_format_Clean( &p_cfg->fmt );
174 free( p_splitter->p_output );
178 * This function filter a picture
180 static int Filter( video_splitter_t *p_splitter,
181 picture_t *pp_dst[], picture_t *p_src )
183 if( video_splitter_NewPicture( p_splitter, pp_dst ) )
186 for( int i = 0; i < p_splitter->i_output; i++ )
187 picture_Copy( pp_dst[i], p_src );
188 picture_Release( p_src );