]> git.sesse.net Git - vlc/blob - modules/video_splitter/clone.c
Reset input titles before adding new ones.
[vlc] / modules / video_splitter / clone.c
1 /*****************************************************************************
2  * clone.c : Clone video plugin for vlc
3  *****************************************************************************
4  * Copyright (C) 2002-2009 VLC authors and VideoLAN
5  * $Id$
6  *
7  * Authors: Samuel Hocevar <sam@zoy.org>
8  *
9  * This program is free software; you can redistribute it and/or modify it
10  * under the terms of the GNU Lesser General Public License as published by
11  * the Free Software Foundation; either version 2.1 of the License, or
12  * (at your option) any later version.
13  *
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 Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public License
20  * along with this program; if not, write to the Free Software Foundation,
21  * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27
28 #ifdef HAVE_CONFIG_H
29 # include "config.h"
30 #endif
31
32 #include <vlc_common.h>
33 #include <vlc_plugin.h>
34 #include <vlc_video_splitter.h>
35
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.")
42
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." )
46
47 #define CLONE_HELP N_("Duplicate your video to multiple windows " \
48         "and/or video output modules")
49 #define CFG_PREFIX "clone-"
50
51 static int  Open ( vlc_object_t * );
52 static void Close( vlc_object_t * );
53
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 )
61
62     add_integer( CFG_PREFIX "count", 2, COUNT_TEXT, COUNT_LONGTEXT, false )
63     add_module_list( CFG_PREFIX "vout-list", "vout display", NULL,
64                      VOUTLIST_TEXT, VOUTLIST_LONGTEXT, true )
65
66     add_shortcut( "clone" )
67     set_callbacks( Open, Close )
68 vlc_module_end ()
69
70 /*****************************************************************************
71  * Local prototypes
72  *****************************************************************************/
73 static const char *const ppsz_filter_options[] = {
74     "count", "vout-list", NULL
75 };
76
77 #define VOUTSEPARATOR ':'
78
79 static int Filter( video_splitter_t *, picture_t *pp_dst[], picture_t * );
80
81 /**
82  * This function allocates and initializes a Clone splitter module
83  */
84 static int Open( vlc_object_t *p_this )
85 {
86     video_splitter_t *p_splitter = (video_splitter_t*)p_this;
87
88     config_ChainParse( p_splitter, CFG_PREFIX, ppsz_filter_options,
89                        p_splitter->p_cfg );
90
91     char *psz_clonelist = var_CreateGetNonEmptyString( p_splitter,
92                                                        CFG_PREFIX "vout-list" );
93     if( psz_clonelist )
94     {
95         /* Count the number of defined vout */
96         p_splitter->i_output = 1;
97         for( int i = 0; psz_clonelist[i]; i++ )
98         {
99             if( psz_clonelist[i] == VOUTSEPARATOR )
100                 p_splitter->i_output++;
101         }
102
103         /* */
104         p_splitter->p_output = calloc( p_splitter->i_output,
105                                        sizeof(*p_splitter->p_output) );
106         if( !p_splitter->p_output )
107         {
108             free( psz_clonelist );
109             return VLC_EGENERIC;
110         }
111
112         /* Tokenize the list */
113         char *psz_tmp = psz_clonelist;
114         for( int i = 0; psz_tmp && *psz_tmp; i++ )
115         {
116             char *psz_new = strchr( psz_tmp, VOUTSEPARATOR );
117             if( psz_new )
118                 *psz_new++ = '\0';
119
120             p_splitter->p_output[i].psz_module = strdup( psz_tmp );
121
122             psz_tmp = psz_new;
123         }
124
125         free( psz_clonelist );
126     }
127     else
128     {
129         /* No list was specified. We will use the default vout, and get
130          * the number of clones from clone-count */
131         p_splitter->i_output = var_CreateGetInteger( p_splitter, CFG_PREFIX "count" );
132         if( p_splitter->i_output <= 0 )
133             p_splitter->i_output = 1;
134
135         p_splitter->p_output = calloc( p_splitter->i_output,
136                                        sizeof(*p_splitter->p_output) );
137
138         if( !p_splitter->p_output )
139             return VLC_EGENERIC;
140
141         for( int i = 0; i < p_splitter->i_output; i++ )
142             p_splitter->p_output[i].psz_module = NULL;
143     }
144
145     /* */
146     for( int i = 0; i < p_splitter->i_output; i++ )
147     {
148         video_splitter_output_t *p_cfg = &p_splitter->p_output[i];
149         video_format_Copy( &p_cfg->fmt, &p_splitter->fmt );
150         p_cfg->window.i_x = 0;
151         p_cfg->window.i_y = 0;
152         p_cfg->window.i_align = 0;
153     }
154
155     /* */
156     p_splitter->pf_filter = Filter;
157     p_splitter->pf_mouse  = NULL;
158
159     msg_Dbg( p_splitter, "spawning %i clone(s)", p_splitter->i_output );
160
161     return VLC_SUCCESS;
162 }
163
164 /**
165  * This function closes a clone video splitter module
166  */
167 static void Close( vlc_object_t *p_this )
168 {
169     video_splitter_t *p_splitter = (video_splitter_t*)p_this;
170
171     for( int i = 0; i < p_splitter->i_output; i++ )
172     {
173         video_splitter_output_t *p_cfg = &p_splitter->p_output[i];
174
175         free( p_cfg->psz_module );
176         video_format_Clean( &p_cfg->fmt );
177     }
178     free( p_splitter->p_output );
179 }
180
181 /**
182  * This function filter a picture
183  */
184 static int Filter( video_splitter_t *p_splitter,
185                    picture_t *pp_dst[], picture_t *p_src )
186 {
187     if( video_splitter_NewPicture( p_splitter, pp_dst ) )
188     {
189         picture_Release( p_src );
190         return VLC_EGENERIC;
191     }
192
193     for( int i = 0; i < p_splitter->i_output; i++ )
194         picture_Copy( pp_dst[i], p_src );
195
196     picture_Release( p_src );
197     return VLC_SUCCESS;
198 }
199