XCgrabberFlex.H

Go to the documentation of this file.
00001 
00002 /*!@file Devices/XCgrabberFlex.H Definition and access functions for
00003   Silicon Imaging HD Camera grabber */
00004 
00005 // //////////////////////////////////////////////////////////////////// //
00006 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2001 by the //
00007 // University of Southern California (USC) and the iLab at USC.         //
00008 // See http://iLab.usc.edu for information about this project.          //
00009 // //////////////////////////////////////////////////////////////////// //
00010 // Major portions of the iLab Neuromorphic Vision Toolkit are protected //
00011 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency //
00012 // in Visual Environments, and Applications'' by Christof Koch and      //
00013 // Laurent Itti, California Institute of Technology, 2001 (patent       //
00014 // pending; application number 09/912,225 filed July 23, 2001; see      //
00015 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status).     //
00016 // //////////////////////////////////////////////////////////////////// //
00017 // This file is part of the iLab Neuromorphic Vision C++ Toolkit.       //
00018 //                                                                      //
00019 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can   //
00020 // redistribute it and/or modify it under the terms of the GNU General  //
00021 // Public License as published by the Free Software Foundation; either  //
00022 // version 2 of the License, or (at your option) any later version.     //
00023 //                                                                      //
00024 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope  //
00025 // that it will be useful, but WITHOUT ANY WARRANTY; without even the   //
00026 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      //
00027 // PURPOSE.  See the GNU General Public License for more details.       //
00028 //                                                                      //
00029 // You should have received a copy of the GNU General Public License    //
00030 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write   //
00031 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,   //
00032 // Boston, MA 02111-1307 USA.                                           //
00033 // //////////////////////////////////////////////////////////////////// //
00034 //
00035 // Primary maintainer for this file: Farhan Baluch <fbaluch@usc.edu>
00036 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Devices/XCgrabberFlex.H $
00037 // $Id: XCgrabberFlex.H 12965 2010-03-06 03:23:30Z irock $
00038 //
00039 
00040 #ifndef XCGRABBERFLEX_H_DEFINED
00041 #define XCGRABBERFLEX_H_DEFINED
00042 
00043 #ifdef HAVE_XCLIB
00044 // xclib defines a bunch of types which conflicts with other packages;
00045 // namely: uint64 which we define in Util/Types.H, and, more
00046 // importantly, float4 which is defined by CUDA includes. So we just
00047 // resort to using it in a new xclib namespace. That means that all
00048 // the function calls and uses of xclib datatypes now must use the
00049 // xclib:: prefix:
00050 namespace xclib {
00051 #include <xclib/xcliball.h>
00052 }
00053 #endif
00054 
00055 
00056 #include "Component/ModelParam.H"
00057 #include "Image/Dims.H"
00058 #include "Transport/FrameIstream.H"
00059 #include "Util/Types.H"
00060 #include "Video/VideoFormat.H"
00061 
00062 #include <pthread.h>
00063 
00064 class VideoFrame;
00065 template <class T> class PixRGB;
00066 template <class T> class Image;
00067 
00068 class XCgrabberFlex : public FrameIstream
00069 {
00070 public:
00071   //! Constructor
00072   XCgrabberFlex(OptionManager& mgr,
00073             const std::string& descrName="XC Frame Grabber Driver",
00074             const std::string& tagName = "XCFrameGrabber",
00075             const ParamFlag flags = USE_MY_VAL);
00076 
00077   //! Destructor
00078   virtual ~XCgrabberFlex();
00079 
00080   //! Return the specifications of the next frame to be returned
00081   virtual GenericFrameSpec peekFrameSpec();
00082 
00083   //! Get the inter-frame time that matches our video mode
00084   virtual SimTime getNaturalFrameTime() const;
00085 
00086   //! White balance
00087   void WhiteBalance();
00088 
00089   //! Get the next frame from the frame-grabber
00090   /*! Returns grabbed frame. This call will block until a frame is
00091       ready and has been grabbed.
00092 
00093       Beware that the integrity of the GenericFrame object may not
00094       last "very long"; basically, try to be finished using the
00095       GenericFrame object before you attempt to grab the next frame in
00096       the stream. If you need it for longer than that, then you should
00097        use GenericFrame::deepCopyOf() to make a copy of the frame that
00098      can be safely held indefinitely. */
00099   virtual GenericFrame readFrame();
00100 
00101 #ifdef HAVE_XCLIB
00102   xclib::pxbuffer_t getCurrBufID();
00103 #endif
00104 
00105 protected:
00106   //! Grab raw data (the raw bayer format data)
00107   /*! Don't call this directly; use readFrame() instead. */
00108   VideoFrame grabRaw();
00109 
00110   //! get started
00111   virtual void start1();
00112 
00113   //! get stopped
00114   virtual void stop2();
00115 
00116 private:
00117   virtual void paramChanged(ModelParamBase* const param,
00118                             const bool valueChanged,
00119                             ParamClient::ChangeStatus* status);
00120 
00121   //! width of grabbed frames
00122   OModelParam<Dims> itsDims;
00123 
00124   //! grab mode that the hardware should use
00125   /*! Grabbed frames will internally be converted to Image<
00126     PixRGB<byte> > whatever that mode is, but playing with it may
00127     influence image quality, maximum achievable framerate, and amounts
00128     of CPU doing those conversions to RGB. */
00129   OModelParam<VideoFormat> itsGrabMode;
00130 
00131   //! determines whether byte swapping is done during conversion to RGB
00132   OModelParam<bool> itsByteSwap;
00133 
00134   //! for white balance
00135   OModelParam<int> itsWhiteBalTarR;
00136   OModelParam<int> itsWhiteBalTarG;
00137   OModelParam<int> itsWhiteBalTarB;
00138   OModelParam<int> itsWhiteBalRefR;
00139   OModelParam<int> itsWhiteBalRefG;
00140   OModelParam<int> itsWhiteBalRefB;
00141 
00142 
00143   //! gamma  - highly dependent on your driver
00144   OModelParam<float> itsGamma;
00145 
00146   //! frames per second
00147   OModelParam<float> itsFPS;
00148 
00149   //! bit depth
00150   int itsBitDepth;
00151 
00152   pthread_mutex_t qmutex_buf;
00153 
00154 // check whether the configure script found XClib and XC camera; if not, then
00155 // just stub out the core of the XCgrabber class and issue
00156 // LFATAL()s if somebody actually tries to use it
00157 #ifdef HAVE_XCLIB
00158   OModelParam<std::string> itsFormatFile;
00159   bool itsCameraOk;           // the camera is initialized and transmitting
00160   xclib::pxbuffer_t itsLastBuf;
00161   byte* itsImgBuf;
00162   struct xclib::xclibs itsXclib;
00163   struct xclib::pxvidstate *itsStatep;
00164   int itsStateid;
00165 #endif // HAVE_XCLIB
00166 
00167 };
00168 
00169 #endif
00170 
00171 // ######################################################################
00172 /* So things look consistent in everyone's emacs... */
00173 /* Local Variables: */
00174 /* indent-tabs-mode: nil */
00175 /* End: */
Generated on Sun May 8 08:04:45 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3