Main Page | Modules | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages

clone.c

00001 /*****************************************************************************
00002  * clone.c : Clone video plugin for vlc
00003  *****************************************************************************
00004  * Copyright (C) 2002, 2003 the VideoLAN team
00005  * $Id: clone.c 12968 2005-10-25 19:24:21Z gbazin $
00006  *
00007  * Authors: Samuel Hocevar <[email protected]>
00008  *
00009  * This program is free software; you can redistribute it and/or modify
00010  * it under the terms of the GNU General Public License as published by
00011  * the Free Software Foundation; either version 2 of the License, or
00012  * (at your option) any later version.
00013  *
00014  * This program is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  * GNU General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU General Public License
00020  * along with this program; if not, write to the Free Software
00021  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
00022  *****************************************************************************/
00023 
00024 /*****************************************************************************
00025  * Preamble
00026  *****************************************************************************/
00027 #include <stdlib.h>                                      /* malloc(), free() */
00028 #include <string.h>
00029 
00030 #include <vlc/vlc.h>
00031 #include <vlc/vout.h>
00032 
00033 #include "filter_common.h"
00034 
00035 #define VOUTSEPARATOR ','
00036 
00037 /*****************************************************************************
00038  * Local prototypes
00039  *****************************************************************************/
00040 static int  Create    ( vlc_object_t * );
00041 static void Destroy   ( vlc_object_t * );
00042 
00043 static int  Init      ( vout_thread_t * );
00044 static void End       ( vout_thread_t * );
00045 static void Render    ( vout_thread_t *, picture_t * );
00046 
00047 static void RemoveAllVout  ( vout_thread_t *p_vout );
00048 
00049 static int  SendEvents( vlc_object_t *, char const *,
00050                         vlc_value_t, vlc_value_t, void * );
00051 
00052 /*****************************************************************************
00053  * Module descriptor
00054  *****************************************************************************/
00055 #define COUNT_TEXT N_("Number of clones")
00056 #define COUNT_LONGTEXT N_("Select the number of video windows in which to "\
00057     "clone the video.")
00058 
00059 #define VOUTLIST_TEXT N_("List of video output modules")
00060 #define VOUTLIST_LONGTEXT N_("Select the specific video output modules that you want to activate.")
00061 
00062 vlc_module_begin();
00063     set_description( _("Clone video filter") );
00064     set_capability( "video filter", 0 );
00065     set_shortname( N_("Clone" ));
00066     set_category( CAT_VIDEO );
00067     set_subcategory( SUBCAT_VIDEO_VFILTER );
00068 
00069     add_integer( "clone-count", 2, NULL, COUNT_TEXT, COUNT_LONGTEXT, VLC_FALSE );
00070     add_string ( "clone-vout-list", NULL, NULL, VOUTLIST_TEXT, VOUTLIST_LONGTEXT, VLC_TRUE );
00071 
00072     add_shortcut( "clone" );
00073     set_callbacks( Create, Destroy );
00074 vlc_module_end();
00075 
00076 /*****************************************************************************
00077  * vout_sys_t: Clone video output method descriptor
00078  *****************************************************************************
00079  * This structure is part of the video output thread descriptor.
00080  * It describes the Clone specific properties of an output thread.
00081  *****************************************************************************/
00082 struct vout_sys_t
00083 {
00084     int    i_clones;
00085 
00086     /* list of vout modules to use. "default" will launch a default
00087      * module. If specified, overrides the setting in i_clones (which it
00088      * sets to the list length) */
00089     char **ppsz_vout_list;
00090 
00091     vout_thread_t **pp_vout;
00092 };
00093 
00094 /*****************************************************************************
00095  * Control: control facility for the vout (forwards to child vout)
00096  *****************************************************************************/
00097 static int Control( vout_thread_t *p_vout, int i_query, va_list args )
00098 {
00099     int i_vout;
00100     for( i_vout = 0; i_vout < p_vout->p_sys->i_clones; i_vout++ )
00101     {
00102         vout_vaControl( p_vout->p_sys->pp_vout[ i_vout ], i_query, args );
00103     }
00104     return VLC_SUCCESS;
00105 }
00106 
00107 /*****************************************************************************
00108  * Create: allocates Clone video thread output method
00109  *****************************************************************************
00110  * This function allocates and initializes a Clone vout method.
00111  *****************************************************************************/
00112 static int Create( vlc_object_t *p_this )
00113 {
00114     vout_thread_t *p_vout = (vout_thread_t *)p_this;
00115     char *psz_clonelist;
00116 
00117     /* Allocate structure */
00118     p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
00119     if( p_vout->p_sys == NULL )
00120     {
00121         msg_Err( p_vout, "out of memory" );
00122         return VLC_ENOMEM;
00123     }
00124 
00125     p_vout->pf_init = Init;
00126     p_vout->pf_end = End;
00127     p_vout->pf_manage = NULL;
00128     p_vout->pf_render = Render;
00129     p_vout->pf_display = NULL;
00130     p_vout->pf_control = Control;
00131 
00132     psz_clonelist = config_GetPsz( p_vout, "clone-vout-list" );
00133     if( psz_clonelist )
00134     {
00135         int i_dummy;
00136         char *psz_token;
00137 
00138         /* Count the number of defined vout */
00139         p_vout->p_sys->i_clones = 1;
00140         i_dummy = 0;
00141         while( psz_clonelist[i_dummy] != 0 )
00142         {
00143             if( psz_clonelist[i_dummy] == VOUTSEPARATOR )
00144                 p_vout->p_sys->i_clones++;
00145             i_dummy++;
00146         }
00147 
00148         p_vout->p_sys->ppsz_vout_list = malloc( p_vout->p_sys->i_clones
00149                                                 * sizeof(char *) );
00150         if( !p_vout->p_sys->ppsz_vout_list )
00151         {
00152             msg_Err( p_vout, "out of memory" );
00153             free( p_vout->p_sys );
00154             return VLC_ENOMEM;
00155         }
00156 
00157         /* Tokenize the list */
00158         i_dummy = 0;
00159         psz_token = psz_clonelist;
00160         while( psz_token && *psz_token )
00161         {
00162            char *psz_module;
00163            psz_module = psz_token;
00164            psz_token = strchr( psz_module, VOUTSEPARATOR );
00165            if( psz_token )
00166            {
00167                *psz_token = '\0';
00168                psz_token++;
00169            }
00170            p_vout->p_sys->ppsz_vout_list[i_dummy] = strdup( psz_module );
00171            i_dummy++;
00172         }
00173 
00174         free( psz_clonelist );
00175     }
00176     else
00177     {
00178         /* No list was specified. We will use the default vout, and get
00179          * the number of clones from clone-count */
00180         p_vout->p_sys->i_clones = config_GetInt( p_vout, "clone-count" );
00181         p_vout->p_sys->ppsz_vout_list = NULL;
00182     }
00183 
00184     p_vout->p_sys->i_clones = __MAX( 1, __MIN( 99, p_vout->p_sys->i_clones ) );
00185 
00186     msg_Dbg( p_vout, "spawning %i clone(s)", p_vout->p_sys->i_clones );
00187 
00188     p_vout->p_sys->pp_vout = malloc( p_vout->p_sys->i_clones *
00189                                      sizeof(vout_thread_t *) );
00190     if( p_vout->p_sys->pp_vout == NULL )
00191     {
00192         msg_Err( p_vout, "out of memory" );
00193         free( p_vout->p_sys );
00194         return VLC_ENOMEM;
00195     }
00196 
00197     return VLC_SUCCESS;
00198 }
00199 
00200 /*****************************************************************************
00201  * Init: initialize Clone video thread output method
00202  *****************************************************************************/
00203 static int Init( vout_thread_t *p_vout )
00204 {
00205     int   i_index, i_vout;
00206     picture_t *p_pic;
00207     char *psz_default_vout;
00208     video_format_t fmt = {0};
00209 
00210     I_OUTPUTPICTURES = 0;
00211 
00212     /* Initialize the output structure */
00213     p_vout->output.i_chroma = p_vout->render.i_chroma;
00214     p_vout->output.i_width  = p_vout->render.i_width;
00215     p_vout->output.i_height = p_vout->render.i_height;
00216     p_vout->output.i_aspect = p_vout->render.i_aspect;
00217     p_vout->fmt_out = p_vout->fmt_in;
00218     fmt = p_vout->fmt_out;
00219 
00220     /* Try to open the real video output */
00221     msg_Dbg( p_vout, "spawning the real video outputs" );
00222 
00223     /* Save the default vout */
00224     psz_default_vout = config_GetPsz( p_vout, "vout" );
00225 
00226     for( i_vout = 0; i_vout < p_vout->p_sys->i_clones; i_vout++ )
00227     {
00228         if( p_vout->p_sys->ppsz_vout_list == NULL 
00229             || ( !strncmp( p_vout->p_sys->ppsz_vout_list[i_vout],
00230                            "default", 8 ) ) )
00231         {
00232             p_vout->p_sys->pp_vout[i_vout] =
00233                 vout_Create( p_vout, &fmt );
00234         }
00235         else
00236         {
00237             /* create the appropriate vout instead of the default one */
00238             config_PutPsz( p_vout, "vout",
00239                            p_vout->p_sys->ppsz_vout_list[i_vout] );
00240             p_vout->p_sys->pp_vout[i_vout] =
00241                 vout_Create( p_vout, &fmt );
00242 
00243             /* Reset the default value */
00244             config_PutPsz( p_vout, "vout", psz_default_vout );
00245         }
00246 
00247         if( p_vout->p_sys->pp_vout[ i_vout ] == NULL )
00248         {
00249             msg_Err( p_vout, "failed to clone %i vout threads",
00250                      p_vout->p_sys->i_clones );
00251             p_vout->p_sys->i_clones = i_vout;
00252             if( psz_default_vout ) free( psz_default_vout );
00253             RemoveAllVout( p_vout );
00254             return VLC_EGENERIC;
00255         }
00256 
00257         ADD_CALLBACKS( p_vout->p_sys->pp_vout[ i_vout ], SendEvents );
00258     }
00259 
00260     if( psz_default_vout ) free( psz_default_vout );
00261     ALLOCATE_DIRECTBUFFERS( VOUT_MAX_PICTURES );
00262 
00263     ADD_PARENT_CALLBACKS( SendEventsToChild );
00264 
00265     return VLC_SUCCESS;
00266 }
00267 
00268 /*****************************************************************************
00269  * End: terminate Clone video thread output method
00270  *****************************************************************************/
00271 static void End( vout_thread_t *p_vout )
00272 {
00273     int i_index;
00274 
00275     /* Free the fake output buffers we allocated */
00276     for( i_index = I_OUTPUTPICTURES ; i_index ; )
00277     {
00278         i_index--;
00279         free( PP_OUTPUTPICTURE[ i_index ]->p_data_orig );
00280     }
00281 }
00282 
00283 /*****************************************************************************
00284  * Destroy: destroy Clone video thread output method
00285  *****************************************************************************
00286  * Terminate an output method created by CloneCreateOutputMethod
00287  *****************************************************************************/
00288 static void Destroy( vlc_object_t *p_this )
00289 {
00290     vout_thread_t *p_vout = (vout_thread_t *)p_this;
00291 
00292     RemoveAllVout( p_vout );
00293 
00294     DEL_PARENT_CALLBACKS( SendEventsToChild );
00295 
00296     free( p_vout->p_sys->pp_vout );
00297     free( p_vout->p_sys );
00298 }
00299 
00300 /*****************************************************************************
00301  * Render: displays previously rendered output
00302  *****************************************************************************
00303  * This function send the currently rendered image to Clone image, waits
00304  * until it is displayed and switch the two rendering buffers, preparing next
00305  * frame.
00306  *****************************************************************************/
00307 static void Render( vout_thread_t *p_vout, picture_t *p_pic )
00308 {
00309     picture_t *p_outpic = NULL;
00310     int i_vout, i_plane;
00311 
00312     for( i_vout = 0; i_vout < p_vout->p_sys->i_clones; i_vout++ )
00313     {
00314         while( ( p_outpic =
00315             vout_CreatePicture( p_vout->p_sys->pp_vout[ i_vout ], 0, 0, 0 )
00316                ) == NULL )
00317         {
00318             if( p_vout->b_die || p_vout->b_error )
00319             {
00320                 vout_DestroyPicture(
00321                     p_vout->p_sys->pp_vout[ i_vout ], p_outpic );
00322                 return;
00323             }
00324 
00325             msleep( VOUT_OUTMEM_SLEEP );
00326         }
00327 
00328         vout_DatePicture( p_vout->p_sys->pp_vout[ i_vout ],
00329                           p_outpic, p_pic->date );
00330         vout_LinkPicture( p_vout->p_sys->pp_vout[ i_vout ], p_outpic );
00331 
00332         for( i_plane = 0 ; i_plane < p_pic->i_planes ; i_plane++ )
00333         {
00334             uint8_t *p_in, *p_in_end, *p_out;
00335             int i_in_pitch = p_pic->p[i_plane].i_pitch;
00336             const int i_out_pitch = p_outpic->p[i_plane].i_pitch;
00337             const int i_copy_pitch = p_outpic->p[i_plane].i_visible_pitch;
00338 
00339             p_in = p_pic->p[i_plane].p_pixels;
00340             p_out = p_outpic->p[i_plane].p_pixels;
00341 
00342             if( i_in_pitch == i_copy_pitch
00343                  && i_out_pitch == i_copy_pitch )
00344             {
00345                 p_vout->p_vlc->pf_memcpy( p_out, p_in, i_in_pitch
00346                                      * p_outpic->p[i_plane].i_visible_lines );
00347             }
00348             else
00349             {
00350                 p_in_end = p_in + i_in_pitch *
00351                     p_outpic->p[i_plane].i_visible_lines;
00352 
00353                 while( p_in < p_in_end )
00354                 {
00355                     p_vout->p_vlc->pf_memcpy( p_out, p_in, i_copy_pitch );
00356                     p_in += i_in_pitch;
00357                     p_out += i_out_pitch;
00358                 }
00359             }
00360         }
00361 
00362         vout_UnlinkPicture( p_vout->p_sys->pp_vout[ i_vout ], p_outpic );
00363         vout_DisplayPicture( p_vout->p_sys->pp_vout[ i_vout ], p_outpic );
00364     }
00365 }
00366 
00367 /*****************************************************************************
00368  * RemoveAllVout: destroy all the child video output threads
00369  *****************************************************************************/
00370 static void RemoveAllVout( vout_thread_t *p_vout )
00371 {
00372     while( p_vout->p_sys->i_clones )
00373     {
00374          --p_vout->p_sys->i_clones;
00375          DEL_CALLBACKS( p_vout->p_sys->pp_vout[p_vout->p_sys->i_clones],
00376                         SendEvents );
00377          vlc_object_detach( p_vout->p_sys->pp_vout[p_vout->p_sys->i_clones] );
00378          vout_Destroy( p_vout->p_sys->pp_vout[p_vout->p_sys->i_clones] );
00379     }
00380 }
00381 
00382 /*****************************************************************************
00383  * SendEvents: forward mouse and keyboard events to the parent p_vout
00384  *****************************************************************************/
00385 static int SendEvents( vlc_object_t *p_this, char const *psz_var,
00386                        vlc_value_t oldval, vlc_value_t newval, void *p_data )
00387 {
00388     var_Set( (vlc_object_t *)p_data, psz_var, newval );
00389 
00390     return VLC_SUCCESS;
00391 }
00392 
00393 /*****************************************************************************
00394  * SendEventsToChild: forward events to the child/children vout
00395  *****************************************************************************/
00396 static int SendEventsToChild( vlc_object_t *p_this, char const *psz_var,
00397                        vlc_value_t oldval, vlc_value_t newval, void *p_data )
00398 {
00399     vout_thread_t *p_vout = (vout_thread_t *)p_this;
00400     int i_vout;
00401 
00402     for( i_vout = 0; i_vout < p_vout->p_sys->i_clones; i_vout++ )
00403     {
00404         var_Set( p_vout->p_sys->pp_vout[ i_vout ], psz_var, newval );
00405 
00406         if( !strcmp( psz_var, "fullscreen" ) ) break;
00407     }
00408 
00409     return VLC_SUCCESS;
00410 }

Generated on Tue Dec 20 10:14:51 2005 for vlc-0.8.4a by  doxygen 1.4.2