FileSingleVideoSource.cpp

Go to the documentation of this file.
00001 /*
00002  *  Copyright (C) Massimo Cora' 2006 <maxcvs@email.it>
00003  *
00004  *  This program is free software; you can redistribute it and/or modify
00005  *  it under the terms of the GNU General Public License as published by
00006  *  the Free Software Foundation; either version 2 of the License, or
00007  *  (at your option) any later version.
00008  *
00009  *  This program is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *  GNU Library General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU General Public License
00015  *  along with this program; if not, write to the Free Software
00016  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00017  */
00018 
00019 
00020 #include "FileSingleVideoSource.hh"
00021 
00022 
00023 FileSingleVideoSource::FileSingleVideoSource( char* file_path ) : BaseInputVideo()
00024 {
00025         _file_path = NULL;
00026 
00027         if ( file_path )
00028                 _file_path = strdup( file_path );
00029 
00030         _initialized = false;
00031 }
00032 
00033 FileSingleVideoSource::~FileSingleVideoSource()
00034 {
00035         if ( _file_path )
00036                 free( _file_path );
00037 
00038         if ( _file_input != NULL )
00039                 cvReleaseCapture( &_file_input );
00040         _file_input = NULL;
00041 }
00042 
00043 bool FileSingleVideoSource::init_device() 
00044 {
00045         // if already initialized just return it
00046         if ( _initialized == true )
00047                 return true;
00048 
00049         if ( (_file_input = cvCaptureFromFile( _file_path )) == NULL ) {
00050                 DEBUG_PRINT( "Error initializing file. Are you missing codecs?\n" );
00051                 return false;
00052         }
00053         
00054         _initialized = true;
00055         return true;
00056 }
00057 
00058 IplImage * FileSingleVideoSource::get_next_frame ()
00059 {
00060         IplImage *tmp_image;
00061         IplImage *res_image = NULL;
00062 
00063         if ( !_initialized ) {
00064                 // try to initialize the device. If it returns false then we'll return NULL
00065                 if ( init_device () == false )
00066                         return NULL;
00067         }
00068 
00069         if( !cvGrabFrame( _file_input )) {
00070                 DEBUG_PRINT( "Error getting frame from file or end of file reached.\n" );
00071                 return NULL;
00072         }
00073 
00074     tmp_image = cvRetrieveFrame( _file_input );
00075         
00076         res_image = cvCreateImage( cvGetSize( tmp_image ), 8, 3 );
00077         
00078         // make a copy of the image so that it can be freed later.
00079         cvCopy( tmp_image, res_image, 0 );
00080 
00081         return res_image;
00082 }
00083 
00084 
00085 IplImage * FileSingleVideoSource::get_next_frame_by_stream_id( int stream_id ) 
00086 { 
00087         return NULL; 
00088 }
00089 
00090 void FileSingleVideoSource::add_image_by_stream_id( IplImage *image, int stream_id, 
00091                                                                                                    char* __unused__, void* callback_data  ) 
00092 {
00093 
00094 }
00095 
00096 bool FileSingleVideoSource::is_multi_stream () 
00097 {
00098         return false;
00099 }
00100 

Generated on Tue Dec 26 10:32:38 2006 for Omnimeeting by  doxygen 1.4.7