LoVideoStream.H

00001 /**
00002    \file Robots/LoBot/LoVideoStream.H
00003 
00004    \brief Video stream encapsulation for the Lobot/Robolocust project.
00005 
00006    This file defines the lobot::VideoStream class, which is used to wrap
00007    around the classes responsible for direct FireWire camera capture and
00008    MPEG reading. To its client, VideoStream then presents a uniform
00009    interface that simply provides images so that its clients don't have
00010    to know or care where those images came from or how they were
00011    obtained.
00012 */
00013 
00014 // //////////////////////////////////////////////////////////////////// //
00015 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2000-2005   //
00016 // by the University of Southern California (USC) and the iLab at USC.  //
00017 // See http://iLab.usc.edu for information about this project.          //
00018 // //////////////////////////////////////////////////////////////////// //
00019 // Major portions of the iLab Neuromorphic Vision Toolkit are protected //
00020 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency //
00021 // in Visual Environments, and Applications'' by Christof Koch and      //
00022 // Laurent Itti, California Institute of Technology, 2001 (patent       //
00023 // pending; application number 09/912,225 filed July 23, 2001; see      //
00024 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status).     //
00025 // //////////////////////////////////////////////////////////////////// //
00026 // This file is part of the iLab Neuromorphic Vision C++ Toolkit.       //
00027 //                                                                      //
00028 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can   //
00029 // redistribute it and/or modify it under the terms of the GNU General  //
00030 // Public License as published by the Free Software Foundation; either  //
00031 // version 2 of the License, or (at your option) any later version.     //
00032 //                                                                      //
00033 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope  //
00034 // that it will be useful, but WITHOUT ANY WARRANTY; without even the   //
00035 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      //
00036 // PURPOSE.  See the GNU General Public License for more details.       //
00037 //                                                                      //
00038 // You should have received a copy of the GNU General Public License    //
00039 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write   //
00040 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,   //
00041 // Boston, MA 02111-1307 USA.                                           //
00042 // //////////////////////////////////////////////////////////////////// //
00043 //
00044 // Primary maintainer for this file: Manu Viswanathan <mviswana at usc dot edu>
00045 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Robots/LoBot/io/LoVideoStream.H $
00046 // $Id: LoVideoStream.H 12785 2010-02-06 02:24:05Z irock $
00047 //
00048 
00049 #ifndef LOBOT_VIDEO_STREAM_DOT_H
00050 #define LOBOT_VIDEO_STREAM_DOT_H
00051 
00052 //------------------------------ HEADERS --------------------------------
00053 
00054 // lobot headers
00055 #include "Robots/LoBot/io/LoGrabber.H"
00056 
00057 #include "Robots/LoBot/config/LoDefaults.H"
00058 
00059 #include "Robots/LoBot/misc/LoTypes.H"
00060 
00061 // INVT MPEG decoding support
00062 //
00063 // DEVNOTE: Unfortunately, INVT's FfmpegDecoder class doesn't have a
00064 // "default" definition in case the FFmpeg libraries are missing. We
00065 // work around that here by supplying a fake FfmpegDecoder class so that
00066 // lobot builds succeed.
00067 #ifdef INV_HAVE_AVCODEC // FFmpeg libs available
00068 
00069 #include "Media/FfmpegDecoder.H"  // use INVT's MPEG decoding support
00070 
00071 #else // FFmpeg libs not available
00072 
00073 // Fake MPEG decoder to allow builds but fail at run-time...
00074 #include "Robots/LoBot/misc/LoExcept.H"
00075 #include "Raster/GenericFrame.H"
00076 
00077 struct FfmpegDecoder {
00078    FfmpegDecoder(const char*, int, const char*, bool){
00079       throw lobot::missing_libs(lobot::MISSING_FFMPEG) ;
00080    }
00081    lobot::ImageType readRGB() const {return lobot::ImageType() ;}
00082    GenericFrameSpec peekFrameSpec() const {return GenericFrameSpec() ;}
00083 } ;
00084 
00085 #endif
00086 
00087 // INVT image support
00088 #include "Image/Dims.H"
00089 
00090 // Standard C++ headers
00091 #include <string>
00092 
00093 //----------------------------- NAMESPACE -------------------------------
00094 
00095 namespace lobot {
00096 
00097 //------------------------- CLASS DEFINITION ----------------------------
00098 
00099 /**
00100    \class lobot::VideoStream
00101    \brief Video stream wrapper for Lobot/Robolocust project.
00102 
00103    This class wraps around lobot::Grabber and INVT's InputMPEGStream so
00104    that its clients can simply retrieve images either directly from
00105    multiple FireWire cameras or multiple MPEG files without having to be
00106    concerned about where or how those images were obtained.
00107 
00108    Ideally, we would not need this class. Unfortunately, we need this
00109    hack since lobot::Grabber is not implemented within the INVT
00110    ModelComponent hierarchy to act as an InputFrameSeries.
00111 */
00112 class VideoStream {
00113    // The video stream may be coming either directly from FireWire
00114    // cameras or from MPEG files.
00115    Grabber* m_grabber ;
00116    FfmpegDecoder* m_decoder ;
00117 
00118    // The video stream object caches input frames from its source camera
00119    // or MPEG file during its update cycle and then supplies the cached
00120    // image to all its clients when they request the next frame.
00121    ImageType m_image ;
00122 
00123    // Prevent copy and assignment
00124    VideoStream(const VideoStream&) ;
00125    VideoStream& operator=(const VideoStream&) ;
00126 
00127 public:
00128    /// This constructor sets up a grabber to read input images directly
00129    /// from a FireWire camera. It expects to be passed the FireWire
00130    /// sub-channel ID (i.e., camera number) of the camera it is to be
00131    /// bound to.
00132    VideoStream(int camera_number,
00133                const Dims& resolution = LOBOT_DEFAULT_GRAB_SIZE,
00134                float frame_rate = LOBOT_DEFAULT_GRAB_RATE) ;
00135 
00136    /// This constructor sets up an input MPEG stream to read input images
00137    /// from an MPEG file. It should be passed the name of the MPEG file
00138    /// name it is to read images from.
00139    VideoStream(const std::string& mpeg_file_name) ;
00140 
00141    /// This method reads the next frame from the input video source
00142    /// (either camera or MPEG file) and caches it internally. This method
00143    /// is meant to be called from the main loop of the
00144    /// application/program rather than directly by clients. Clients
00145    /// should, instead, use the readFrame() method.
00146    void update() ;
00147 
00148    /// This method returns the size of the frames being read from the
00149    /// input video source.
00150    Dims frameSize() const ;
00151 
00152    /// This method returns the rate at which frames are read from the
00153    /// input video source. The returned number's units are frames per
00154    /// second.
00155    float frameRate() const ;
00156 
00157    /// As far as VideoStream clients are concerned, this method reads the
00158    /// next frame from the input video source (i.e., either a firewire
00159    /// camera or MPEG file) and returns it as an Image<PixRGB<byte>>. In
00160    /// actuality, this method returns the frame read and cached by an
00161    /// earlier call to the update() method. Clients of VideoStream should
00162    /// not use update() directly; that is designed to be called from an
00163    /// application's main loop (or similar structure/place). Instead,
00164    /// clients should call this method to retrieve frames from the input
00165    /// video sources.
00166    ImageType readFrame() const {return m_image ;}
00167 
00168    // Clean-up
00169    ~VideoStream() ;
00170 } ;
00171 
00172 //-----------------------------------------------------------------------
00173 
00174 } // end of namespace encapsulating this file's definitions
00175 
00176 #endif
00177 
00178 /* So things look consistent in everyone's emacs... */
00179 /* Local Variables: */
00180 /* indent-tabs-mode: nil */
00181 /* End: */
Generated on Sun May 8 08:41:30 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3