]> git.sesse.net Git - vlc/blob - modules/video_filter/clone.c
Merge branch 'master' into lpcm_encoder
[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 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, NULL, COUNT_TEXT, COUNT_LONGTEXT, false )
63     add_string ( CFG_PREFIX "vout-list", NULL, NULL, VOUTLIST_TEXT, VOUTLIST_LONGTEXT, true )
64
65     add_shortcut( "clone" )
66     set_callbacks( Open, Close )
67 vlc_module_end ()
68
69 /*****************************************************************************
70  * Local prototypes
71  *****************************************************************************/
72 static const char *const ppsz_filter_options[] = {
73     "count", "vout-list", NULL
74 };
75
76 #define VOUTSEPARATOR ','
77
78 static int Filter( video_splitter_t *, picture_t *pp_dst[], picture_t * );
79
80 /**
81  * This function allocates and initializes a Clone splitter module
82  */
83 static int Open( vlc_object_t *p_this )
84 {
85     video_splitter_t *p_splitter = (video_splitter_t*)p_this;
86
87     config_ChainParse( p_splitter, CFG_PREFIX, ppsz_filter_options,
88                        p_splitter->p_cfg );
89
90     char *psz_clonelist = var_CreateGetNonEmptyString( p_splitter,
91                                                        CFG_PREFIX "vout-list" );
92     if( psz_clonelist )
93     {
94         /* Count the number of defined vout */
95         p_splitter->i_output = 1;
96         for( int i = 0; psz_clonelist[i]; i++ )
97         {
98             if( psz_clonelist[i] == VOUTSEPARATOR )
99                 p_splitter->i_output++;
100         }
101
102         /* */
103         p_splitter->p_output = calloc( p_splitter->i_output,
104                                        sizeof(*p_splitter->p_output) );
105         if( !p_splitter->p_output )
106         {
107             free( psz_clonelist );
108             return VLC_EGENERIC;
109         }
110
111         /* Tokenize the list */
112         char *psz_tmp = psz_clonelist;
113         for( int i = 0; psz_tmp && *psz_tmp; i++ )
114         {
115             char *psz_new = strchr( psz_tmp, VOUTSEPARATOR );
116             if( psz_new )
117                 *psz_new++ = '\0';
118
119             p_splitter->p_output[i].psz_module = strdup( psz_tmp );
120
121             psz_tmp = psz_new;
122         }
123
124         free( psz_clonelist );
125     }
126     else
127     {
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;
133
134         p_splitter->p_output = calloc( p_splitter->i_output,
135                                        sizeof(*p_splitter->p_output) );
136
137         if( !p_splitter->p_output )
138             return VLC_EGENERIC;
139
140         for( int i = 0; i < p_splitter->i_output; i++ )
141             p_splitter->p_output[i].psz_module = NULL;
142     }
143
144     /* */
145     for( int i = 0; i < p_splitter->i_output; i++ )
146     {
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;
152     }
153
154     /* */
155     p_splitter->pf_filter = Filter;
156     p_splitter->pf_mouse  = NULL;
157
158     msg_Dbg( p_splitter, "spawning %i clone(s)", p_splitter->i_output );
159
160     return VLC_SUCCESS;
161 }
162
163 /**
164  * This function closes a clone video splitter module
165  */
166 static void Close( vlc_object_t *p_this )
167 {
168     video_splitter_t *p_splitter = (video_splitter_t*)p_this;
169
170     for( int i = 0; i < p_splitter->i_output; i++ )
171     {
172         video_splitter_output_t *p_cfg = &p_splitter->p_output[i];
173
174         free( p_cfg->psz_module );
175         video_format_Clean( &p_cfg->fmt );
176     }
177     free( p_splitter->p_output );
178 }
179
180 /**
181  * This function filter a picture
182  */
183 static int Filter( video_splitter_t *p_splitter,
184                    picture_t *pp_dst[], picture_t *p_src )
185 {
186     if( video_splitter_NewPicture( p_splitter, pp_dst ) )
187     {
188         picture_Release( p_src );
189         return VLC_EGENERIC;
190     }
191
192     for( int i = 0; i < p_splitter->i_output; i++ )
193         picture_Copy( pp_dst[i], p_src );
194
195     picture_Release( p_src );
196     return VLC_SUCCESS;
197 }
198