MpegInputStream.H

Go to the documentation of this file.
00001 /*!@file Media/MpegInputStream.H Read frames from movie files */
00002 
00003 // //////////////////////////////////////////////////////////////////// //
00004 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2000-2005   //
00005 // by the 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: Rob Peters <rjpeters at usc dot edu>
00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Media/MpegInputStream.H $
00035 // $Id: MpegInputStream.H 9547 2008-03-28 23:32:43Z rjpeters $
00036 //
00037 
00038 #ifndef MEDIA_MPEGINPUTSTREAM_H_DEFINED
00039 #define MEDIA_MPEGINPUTSTREAM_H_DEFINED
00040 
00041 #include "Component/ModelComponent.H"
00042 #include "Component/ModelParam.H"
00043 #include "Image/Dims.H"
00044 #include "Transport/FrameIstream.H"
00045 #include "Util/Types.H"      // for byte
00046 
00047 class MovieDecoder;
00048 class VideoFrame;
00049 
00050 // ######################################################################
00051 // ######################################################################
00052 //! InputMPEGStream is a wrapper class to read video frames from mpeg-1
00053 /*! InputMPEGStream is a wrapper class to read video frames from
00054     mpeg-1, mpeg-4 (aka divx), asf, avi, mov and any other format that
00055     mplayer can decode. Audio streams are entirely ignored. */
00056 
00057 class InputMPEGStream : public FrameIstream
00058 {
00059 public:
00060   //! Construct an mpegstream object for mpeg input
00061   InputMPEGStream(OptionManager& mgr,
00062                   const std::string& descrName = "Input MPEG Stream",
00063                   const std::string& tagName = "InputMPEGStream");
00064 
00065   //! Virtual destructor
00066   virtual ~InputMPEGStream();
00067 
00068   //! Override from FrameIstream; just calls setFileName()
00069   virtual void setConfigInfo(const std::string& filename);
00070 
00071   //! override the base class version so we can seek to the proper frame number
00072   virtual bool setFrameNumber(int n);
00073 
00074   //! get frame specifications, peeking at the first frame if necessary
00075   virtual GenericFrameSpec peekFrameSpec();
00076 
00077   //! Configure the MPEG Stream for decoding
00078   /*! @param fname name of file from which frames are to be read from */
00079   void setFileName(std::string fname);
00080 
00081   //! Read the next frame from the mpeg stream
00082   /*! The native representation of the GenericFrame will be a
00083       VideoFrame. */
00084   virtual GenericFrame readFrame();
00085 
00086   //! Read the next frame from the mpeg stream
00087   /*! returns an image of size (0,0) at the end of the stream */
00088   virtual Image<PixRGB<byte> > readRGB();
00089 
00090   /// Read a frame from the stream and discard it
00091   /** If you know you are going to discard the frame (e.g. to skip
00092       ahead to a certain frame number, or to count the frame), then it
00093       is more efficient to call readAndDiscardFrame() than to call
00094       readVideoFrame() or readRGB() but ignore the result. */
00095   virtual bool readAndDiscardFrame();
00096 
00097   /// Get the next raw VideoFrame from the stream
00098   VideoFrame readVideoFrame();
00099 
00100 protected:
00101   //! get stopped; close any open write stream
00102   void stop2();
00103 
00104   NModelParam<int>         itsBuffLen;
00105   OModelParam<std::string> itsCodecName;
00106   OModelParam<bool>        itsDoPreload;
00107   std::string              itsFileName;
00108 
00109 private:
00110   //! create our Decoder object if we haven't yet done so
00111   void createDecoder();
00112 
00113   MovieDecoder* dec;
00114 };
00115 
00116 // ######################################################################
00117 /* So things look consistent in everyone's emacs... */
00118 /* Local Variables: */
00119 /* mode: c++ */
00120 /* indent-tabs-mode: nil */
00121 /* End: */
00122 
00123 #endif // MEDIA_MPEGINPUTSTREAM_H_DEFINED
Generated on Sun May 8 08:41:01 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3