]> git.sesse.net Git - vlc/blob - modules/video_filter/clone.c
Fixed window position for clone.
[vlc] / modules / video_filter / clone.c
1 /*****************************************************************************
2  * clone.c : Clone video plugin for vlc
3  *****************************************************************************
4  * Copyright (C) 2002-2009 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Samuel Hocevar <sam@zoy.org>
8  *
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.
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 General Public License for more details.
18  *
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  *****************************************************************************/
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 CFG_PREFIX "clone-"
48
49 static int  Open ( vlc_object_t * );
50 static void Close( vlc_object_t * );
51
52 vlc_module_begin ()
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 )
58
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 )
61
62     add_shortcut( "clone" )
63     set_callbacks( Open, Close )
64 vlc_module_end ()
65
66 /*****************************************************************************
67  * Local prototypes
68  *****************************************************************************/
69 static const char *const ppsz_filter_options[] = {
70     "count", "vout-list", NULL
71 };
72
73 #define VOUTSEPARATOR ','
74
75 static int Filter( video_splitter_t *, picture_t *pp_dst[], picture_t * );
76
77 /**
78  * This function allocates and initializes a Clone splitter module
79  */
80 static int Open( vlc_object_t *p_this )
81 {
82     video_splitter_t *p_splitter = (video_splitter_t*)p_this;
83
84     config_ChainParse( p_splitter, CFG_PREFIX, ppsz_filter_options,
85                        p_splitter->p_cfg );
86
87     char *psz_clonelist = var_CreateGetNonEmptyString( p_splitter,
88                                                        CFG_PREFIX "vout-list" );
89     if( psz_clonelist )
90     {
91         /* Count the number of defined vout */
92         p_splitter->i_output = 1;
93         for( int i = 0; psz_clonelist[i]; i++ )
94         {
95             if( psz_clonelist[i] == VOUTSEPARATOR )
96                 p_splitter->i_output++;
97         }
98
99         /* */
100         p_splitter->p_output = calloc( p_splitter->i_output,
101                                        sizeof(*p_splitter->p_output) );
102         if( !p_splitter->p_output )
103         {
104             free( psz_clonelist );
105             return VLC_EGENERIC;
106         }
107
108         /* Tokenize the list */
109         char *psz_tmp = psz_clonelist;
110         for( int i = 0; psz_tmp && *psz_tmp; i++ )
111         {
112             char *psz_new = strchr( psz_tmp, VOUTSEPARATOR );
113             if( psz_new )
114                 *psz_new++ = '\0';
115
116             p_splitter->p_output[i].psz_module = strdup( psz_tmp );
117
118             psz_tmp = psz_new;
119         }
120
121         free( psz_clonelist );
122     }
123     else
124     {
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;
130
131         p_splitter->p_output = calloc( p_splitter->i_output,
132                                        sizeof(*p_splitter->p_output) );
133
134         if( !p_splitter->p_output )
135             return VLC_EGENERIC;
136
137         for( int i = 0; i < p_splitter->i_output; i++ )
138             p_splitter->p_output[i].psz_module = NULL;
139     }
140
141     /* */
142     for( int i = 0; i < p_splitter->i_output; i++ )
143     {
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 = 0;
147         p_cfg->window.i_y = 0;
148         p_cfg->window.i_align = 0;
149     }
150
151     /* */
152     p_splitter->pf_filter = Filter;
153     p_splitter->pf_mouse  = NULL;
154
155     msg_Dbg( p_splitter, "spawning %i clone(s)", p_splitter->i_output );
156
157     return VLC_SUCCESS;
158 }
159
160 /**
161  * This function closes a clone video splitter module
162  */
163 static void Close( vlc_object_t *p_this )
164 {
165     video_splitter_t *p_splitter = (video_splitter_t*)p_this;
166
167     for( int i = 0; i < p_splitter->i_output; i++ )
168     {
169         video_splitter_output_t *p_cfg = &p_splitter->p_output[i];
170
171         free( p_cfg->psz_module );
172         video_format_Clean( &p_cfg->fmt );
173     }
174     free( p_splitter->p_output );
175 }
176
177 /**
178  * This function filter a picture
179  */
180 static int Filter( video_splitter_t *p_splitter,
181                    picture_t *pp_dst[], picture_t *p_src )
182 {
183     if( video_splitter_NewPicture( p_splitter, pp_dst ) )
184     {
185         picture_Release( p_src );
186         return VLC_EGENERIC;
187     }
188
189     for( int i = 0; i < p_splitter->i_output; i++ )
190         picture_Copy( pp_dst[i], p_src );
191
192     picture_Release( p_src );
193     return VLC_SUCCESS;
194 }
195