RTSPGrabber.H

Go to the documentation of this file.
00001 /*!@file Devices/RTSPGrabber.H video stream grabber froman rtsp source using LiveMedia */
00002 
00003 // //////////////////////////////////////////////////////////////////// //
00004 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2001 by the //
00005 // University of Southern California (USC) and the iLab at USC.         //
00006 // See http://iLab.usc.edu for information about this project.          //
00007 // //////////////////////////////////////////////////////////////////// //
00008 // Major portions of the iLab Neuromorphic Vision Toolkit are protected //
00009 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency //
00010 // in Visual Environments, and Applications'' by Christof Koch and      //
00011 // Laurent Itti, California Institute of Technology, 2001 (patent       //
00012 // pending; application number 09/912,225 filed July 23, 2001; see      //
00013 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status).     //
00014 // //////////////////////////////////////////////////////////////////// //
00015 // This file is part of the iLab Neuromorphic Vision C++ Toolkit.       //
00016 //                                                                      //
00017 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can   //
00018 // redistribute it and/or modify it under the terms of the GNU General  //
00019 // Public License as published by the Free Software Foundation; either  //
00020 // version 2 of the License, or (at your option) any later version.     //
00021 //                                                                      //
00022 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope  //
00023 // that it will be useful, but WITHOUT ANY WARRANTY; without even the   //
00024 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      //
00025 // PURPOSE.  See the GNU General Public License for more details.       //
00026 //                                                                      //
00027 // You should have received a copy of the GNU General Public License    //
00028 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write   //
00029 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,   //
00030 // Boston, MA 02111-1307 USA.                                           //
00031 // //////////////////////////////////////////////////////////////////// //
00032 //
00033 // Primary maintainer for this file: Lior Elazary
00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Devices/RTSPGrabber.H $
00035 // $Id: RTSPGrabber.H 12962 2010-03-06 02:13:53Z irock $
00036 //
00037 
00038 #ifndef RTSPGrabber_H_DEFINED
00039 #define RTSPGrabber_H_DEFINED
00040 
00041 
00042 #include "Component/ModelParam.H"
00043 #include "Image/Dims.H"
00044 #include "Transport/FrameIstream.H"
00045 #include "Util/Types.H"
00046 #include "Video/VideoFormat.H"
00047 #include "Video/VideoFrame.H"
00048 #include "Media/FfmpegDecoder.H"
00049 #include <pthread.h>
00050 
00051 #ifdef INVT_HAVE_LIVEMEDIA
00052 #include <liveMedia/liveMedia.hh>
00053 #include <BasicUsageEnvironment/BasicUsageEnvironment.hh>
00054 #include <UsageEnvironment/UsageEnvironment.hh>
00055 #endif
00056 
00057 #ifdef HAVE_FFMPEG_AVCODEC_H
00058 extern "C"
00059 {
00060 #include <ffmpeg/avcodec.h>
00061 #include <ffmpeg/avformat.h>
00062 }
00063 #endif
00064 
00065 #ifdef HAVE_LIBAVCODEC_AVCODEC_H
00066 extern "C"
00067 {
00068 #include <libavcodec/avcodec.h>
00069 #include <libavformat/avformat.h>
00070 }
00071 #endif
00072 
00073 class VideoFrame;
00074 
00075 template <class T> class PixRGB;
00076 template <class T> class Image;
00077 
00078 class RTSPGrabber : public FrameIstream
00079 {
00080 public:
00081   //! Constructor
00082   RTSPGrabber(OptionManager& mgr,
00083             const std::string& descrName="RTSP Frame Grabber Driver",
00084             const std::string& tagName = "RTSPFrameGrabber",
00085             const ParamFlag flags = USE_MY_VAL,
00086             unsigned int bufferSize = 200000);
00087 
00088   //! Destructor
00089   virtual ~RTSPGrabber();
00090 
00091   //! Return the specifications of the next frame to be returned
00092   virtual GenericFrameSpec peekFrameSpec();
00093 
00094   //! Get the inter-frame time that matches our video mode
00095   virtual SimTime getNaturalFrameTime() const;
00096 
00097   //! Get the next frame from the frame-grabber
00098   /*! Returns grabbed frame. This call will block until a frame is
00099       ready and has been grabbed. */
00100   virtual GenericFrame readFrame();
00101 
00102   //! Override from FrameIstream; just set the url
00103   virtual void setConfigInfo(const std::string& url);
00104 
00105   //! get the size of the buffer
00106   unsigned int getFrameBufferSize() { return itsFrameBufferSize; }
00107 
00108   //! do not use!! used to implement synchronus reads
00109   char blockingFlag;
00110   //! set the frame size
00111   unsigned int itsFrameSize;
00112 
00113   //! the capture thread
00114   void run();
00115 protected:
00116   //! Grab raw data (the raw bayer format data)
00117   /*! Don't call this directly; use readFrame() instead. */
00118   VideoFrame grabRaw();
00119 
00120   //! get started
00121   virtual void start1();
00122 
00123   //! get stopped
00124   virtual void stop2();
00125 
00126   //! Create a decoder
00127   void createDecoder();
00128 
00129 
00130 private:
00131   virtual void paramChanged(ModelParamBase* const param,
00132                             const bool valueChanged,
00133                             ParamClient::ChangeStatus* status);
00134 
00135   void shutdown();
00136 
00137   //! width of grabbed frames
00138   OModelParam<Dims> itsDims;
00139 
00140   //! grab mode that the hardware should use
00141   /*! Grabbed frames will internally be converted to Image<
00142     PixRGB<byte> > whatever that mode is, but playing with it may
00143     influence image quality, maximum achievable framerate, and amounts
00144     of CPU doing those conversions to RGB. */
00145   OModelParam<VideoFormat> itsGrabMode;
00146 
00147   //! determines whether byte swapping is done during conversion to RGB
00148   OModelParam<bool> itsByteSwap;
00149 
00150   //! for white balance
00151   OModelParam<int> itsWhiteBalTarR;
00152   OModelParam<int> itsWhiteBalTarG;
00153   OModelParam<int> itsWhiteBalTarB;
00154   OModelParam<int> itsWhiteBalRefR;
00155   OModelParam<int> itsWhiteBalRefG;
00156   OModelParam<int> itsWhiteBalRefB;
00157 
00158   //! frames per second
00159   OModelParam<float> itsFPS;
00160 
00161   //! bit depth
00162   int itsBitDepth;
00163 
00164   //! the url to stream from
00165   std::string itsURL;
00166 
00167   unsigned int itsFrameBufferSize;
00168   unsigned char *itsFrameBuffer; //the frame buffer
00169 
00170 #ifdef INVT_HAVE_LIVEMEDIA
00171   UsageEnvironment* itsEnv;
00172   Medium* itsClient;
00173   RTSPClient* itsRTSPClient;
00174   MediaSession* itsSession;
00175   FramedSource* itsFramedSource;
00176 #endif
00177 
00178 #ifdef INVT_HAVE_AVCODEC
00179   AVFormatContext* itsFormatContext;
00180   AVCodecContext* itsCodecContext;
00181   AVFrame itsPicture;
00182   int itsGotPicture;
00183   VideoFrame itsCurrentFrame;
00184 #endif
00185 
00186   pthread_t itsRunThread;
00187   pthread_mutex_t itsLock;
00188   bool itsThreadRunning;
00189 
00190 
00191 };
00192 
00193 #endif
00194 
00195 // ######################################################################
00196 /* So things look consistent in everyone's emacs... */
00197 /* Local Variables: */
00198 /* indent-tabs-mode: nil */
00199 /* End: */
Generated on Sun May 8 08:04:45 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3