HardwareSingleVideoSource.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 "HardwareSingleVideoSource.hh"
00021 
00022 
00023 HardwareSingleVideoSource::HardwareSingleVideoSource( int camera_num ) : BaseInputVideo(),
00024                         _camera_num( camera_num )
00025 {
00026         _initialized = false;
00027 }
00028 
00029 HardwareSingleVideoSource::~HardwareSingleVideoSource()
00030 {
00031         if ( _cam_input != NULL )
00032                 cvReleaseCapture( &_cam_input );
00033         _cam_input = NULL;
00034 
00035         _initialized = false;
00036 }
00037 
00038 bool HardwareSingleVideoSource::init_device ( ) 
00039 {
00040 
00041         if ( _initialized == true )
00042                 return true;
00043 
00044         if ( (_cam_input = cvCaptureFromCAM( _camera_num )) == NULL ) {
00045                 DEBUG_PRINT( "Error initializing webcam device\n" );
00046                 return false;
00047         }
00048         
00049         _initialized = true;
00050         return true;
00051 }
00052 
00053 IplImage * HardwareSingleVideoSource::get_next_frame ()
00054 {
00055         IplImage *tmp_image;
00056         IplImage *res_image;
00057         
00058         if ( !_initialized ) {
00059                 // try to initialize the device. If it returns false then we'll return NULL
00060                 if ( init_device () == false )
00061                         return NULL;
00062         }
00063         
00064         if( !cvGrabFrame( _cam_input )) {
00065                 DEBUG_PRINT( "Error getting frame from webcam\n" );
00066                 return NULL;
00067         }
00068         
00069         
00070     tmp_image = cvRetrieveFrame( _cam_input );
00071 
00072         res_image = cvCreateImage( cvGetSize( tmp_image ), 8, 3 );
00073         
00074         // make a copy of the image so that it can be freed later.
00075         cvCopy( tmp_image, res_image, 0 );
00076         return res_image;
00077 }
00078 
00079 IplImage * HardwareSingleVideoSource::get_next_frame_by_stream_id( int stream_id ) 
00080 { 
00081         return NULL; 
00082 }
00083 
00084 void HardwareSingleVideoSource::add_image_by_stream_id( IplImage *image, int stream_id, 
00085                                                                    char* __unused__, void* callback_data  ) 
00086 {
00087 }
00088 
00089 bool HardwareSingleVideoSource::is_multi_stream() 
00090 {
00091         return false;
00092 }

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