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

image.c

00001 /*****************************************************************************
00002  * image.c : image video output
00003  *****************************************************************************
00004  * Copyright (C) 2004 the VideoLAN team
00005  * $Id: snapshot.c 8644 2004-09-05 16:53:04Z fkuehne $
00006  *
00007  * Authors: Clément Stenac <[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>
00028 
00029 #include <vlc/vlc.h>
00030 #include <vlc/vout.h>
00031 #include <vlc/intf.h>
00032 
00033 #include "vlc_image.h"
00034 
00035 /*****************************************************************************
00036  * Local prototypes
00037  *****************************************************************************/
00038 static int  Create    ( vlc_object_t * );
00039 static void Destroy   ( vlc_object_t * );
00040 
00041 static int  Init      ( vout_thread_t * );
00042 static void End       ( vout_thread_t *p_vout );
00043 static void Display   ( vout_thread_t *, picture_t * );
00044 
00045 /*****************************************************************************
00046  * Module descriptor
00047  *****************************************************************************/
00048 #define FORMAT_TEXT N_( "Image format" )
00049 #define FORMAT_LONGTEXT N_( "Set the format of the output image." )
00050 
00051 #define RATIO_TEXT N_( "Recording ratio" )
00052 #define RATIO_LONGTEXT N_( "Set the ratio of images that are recorded. "\
00053                            "3 means that one image out of three is recorded." )
00054 
00055 #define PREFIX_TEXT N_( "Filename prefix" )
00056 #define PREFIX_LONGTEXT N_( "Set the prefix of the filename. Output filename "\
00057                             "will have the form prefixNUMBER.format" )
00058 
00059 static char *psz_format_list[] = { "png" };
00060 static char *psz_format_list_text[] = { "PNG" };
00061 
00062 vlc_module_begin( );
00063     set_shortname( _( "Image file" ) );
00064     set_description( _( "Image video output" ) );
00065     set_category( CAT_VIDEO );
00066     set_subcategory( SUBCAT_VIDEO_VOUT );
00067     set_capability( "video output", 0 );
00068 
00069     add_string( "image-out-format", "png", NULL,  FORMAT_TEXT, FORMAT_LONGTEXT,
00070                                                   VLC_FALSE );
00071         change_string_list( psz_format_list, psz_format_list_text, 0 );
00072     add_integer( "image-out-ratio", 3 , NULL,  RATIO_TEXT, RATIO_LONGTEXT,
00073                                                   VLC_FALSE );
00074     add_string( "image-out-prefix", "img", NULL, PREFIX_TEXT, PREFIX_LONGTEXT,
00075                                                  VLC_FALSE );
00076     set_callbacks( Create, Destroy );
00077 vlc_module_end();
00078 
00079 /*****************************************************************************
00080  * vout_sys_t: video output descriptor
00081  *****************************************************************************/
00082 struct vout_sys_t
00083 {
00084     char        *psz_prefix;    /* Prefix */
00085     int         i_ratio;    /* Image ratio */
00086 
00087     int         i_current;  /* Current image */
00088     int         i_frames;  /* Number of frames */
00089 
00090     image_handler_t *p_image;
00091 };
00092 
00093 #define FREE( p ) if( p ) { free( p ); p = NULL; }
00094 
00095 /*****************************************************************************
00096  * Create: allocates video thread
00097  *****************************************************************************
00098  * This function allocates and initializes a vout method.
00099  *****************************************************************************/
00100 static int Create( vlc_object_t *p_this )
00101 {
00102     vout_thread_t *p_vout = ( vout_thread_t * )p_this;
00103 
00104     /* Allocate instance and initialize some members */
00105     p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
00106     if( ! p_vout->p_sys )
00107         return VLC_ENOMEM;
00108 
00109     p_vout->p_sys->psz_prefix =
00110             var_CreateGetString( p_this, "image-out-prefix" );
00111     p_vout->p_sys->i_ratio =
00112             var_CreateGetInteger( p_this, "image-out-ratio" );
00113     p_vout->p_sys->i_current = 0;
00114     p_vout->p_sys->p_image = image_HandlerCreate( p_vout );
00115 
00116     if( !p_vout->p_sys->p_image )
00117     {
00118         msg_Err( p_this, "unable to create image handler") ;
00119         FREE( p_vout->p_sys->psz_prefix );
00120         FREE( p_vout->p_sys );
00121         return VLC_EGENERIC;
00122     }
00123 
00124     p_vout->pf_init = Init;
00125     p_vout->pf_end = End;
00126     p_vout->pf_manage = NULL;
00127     p_vout->pf_render = Display;
00128     p_vout->pf_display = NULL;
00129 
00130     return VLC_SUCCESS;
00131 }
00132 
00133 /*****************************************************************************
00134  * Init: initialize video thread
00135  *****************************************************************************/
00136 static int Init( vout_thread_t *p_vout )
00137 {
00138     int i_index;
00139     picture_t *p_pic;
00140 
00141     /* Initialize the output structure */
00142     p_vout->output.i_chroma = p_vout->render.i_chroma;
00143     p_vout->output.pf_setpalette = NULL;
00144     p_vout->output.i_width = p_vout->render.i_width;
00145     p_vout->output.i_height = p_vout->render.i_height;
00146     p_vout->output.i_aspect = p_vout->output.i_width
00147                                * VOUT_ASPECT_FACTOR / p_vout->output.i_height;
00148 
00149     p_vout->output.i_rmask = 0xff0000;
00150     p_vout->output.i_gmask = 0x00ff00;
00151     p_vout->output.i_bmask = 0x0000ff;
00152 
00153     /* Try to initialize 1 direct buffer */
00154     p_pic = NULL;
00155 
00156     /* Find an empty picture slot */
00157     for( i_index = 0 ; i_index < VOUT_MAX_PICTURES ; i_index++ )
00158     {
00159         if( p_vout->p_picture[ i_index ].i_status == FREE_PICTURE )
00160         {
00161             p_pic = p_vout->p_picture + i_index;
00162             break;
00163         }
00164     }
00165 
00166     /* Allocate the picture */
00167     if( p_pic == NULL )
00168     {
00169         return VLC_EGENERIC;
00170     }
00171 
00172     vout_AllocatePicture( VLC_OBJECT(p_vout), p_pic, p_vout->output.i_chroma,
00173                           p_vout->output.i_width, p_vout->output.i_height,
00174                           p_vout->output.i_aspect );
00175 
00176     if( p_pic->i_planes == 0 )
00177     {
00178         return VLC_EGENERIC;
00179     }
00180 
00181     p_pic->i_status = DESTROYED_PICTURE;
00182     p_pic->i_type   = DIRECT_PICTURE;
00183 
00184     PP_OUTPUTPICTURE[ I_OUTPUTPICTURES ] = p_pic;
00185     I_OUTPUTPICTURES++;
00186     return VLC_SUCCESS;
00187 }
00188 
00189 /*****************************************************************************
00190  * Destroy: destroy video thread
00191  *****************************************************************************
00192  * Terminate an output method created by Create
00193  *****************************************************************************/
00194 static void Destroy( vlc_object_t *p_this )
00195 {
00196     int i_index;
00197     vout_thread_t *p_vout = ( vout_thread_t * )p_this;
00198 
00199     for( i_index = I_OUTPUTPICTURES-1; i_index >= 0; i_index-- )
00200     {
00201         free( PP_OUTPUTPICTURE[ i_index ]->p_data );
00202     }
00203 
00204     /* Destroy structure */
00205     image_HandlerDelete( p_vout->p_sys->p_image );
00206     FREE( p_vout->p_sys->psz_prefix );
00207     FREE( p_vout->p_sys );
00208 }
00209 
00210 /*****************************************************************************
00211  * Display: displays previously rendered output
00212  *****************************************************************************
00213  * This function copies the rendered picture into our circular buffer.
00214  *****************************************************************************/
00215 static void Display( vout_thread_t *p_vout, picture_t *p_pic )
00216 {
00217     video_format_t fmt_in = {0}, fmt_out = {0};
00218 
00219     char *psz_filename;
00220 
00221     if( p_vout->p_sys->i_frames % p_vout->p_sys->i_ratio != 0 )
00222     {
00223         p_vout->p_sys->i_frames++;
00224         return;
00225     }
00226     p_vout->p_sys->i_frames++;
00227     psz_filename = (char *)malloc( strlen( p_vout->p_sys->psz_prefix ) +
00228                                          10 );
00229 
00230     fmt_in.i_chroma = p_vout->render.i_chroma;
00231     fmt_out.i_width = fmt_in.i_width = p_vout->render.i_width;
00232     fmt_out.i_height = fmt_in.i_height = p_vout->render.i_height;
00233 
00234     p_vout->p_sys->i_current++;
00235 
00236     sprintf( psz_filename, "%s%.6i.%s", p_vout->p_sys->psz_prefix,
00237                                       p_vout->p_sys->i_current,
00238                                       "png" );
00239 
00240     image_WriteUrl( p_vout->p_sys->p_image, p_pic,
00241                     &fmt_in, &fmt_out, psz_filename ) ;
00242     free( psz_filename );
00243     return;
00244 }
00245 
00246 
00247 static void End( vout_thread_t *p_vout )
00248 {
00249 }

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