FfmpegPacketDecoder.H

Go to the documentation of this file.
00001 /*!@file Media/FfmpegPacketDecoder.H */
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/FfmpegPacketDecoder.H $
00035 // $Id: FfmpegPacketDecoder.H 12374 2009-12-22 16:38:48Z rand $
00036 //
00037 
00038 #ifndef MEDIA_FFMPEGPACKETDECODER_H_DEFINED
00039 #define MEDIA_FFMPEGPACKETDECODER_H_DEFINED
00040 
00041 #ifdef INVT_HAVE_AVCODEC
00042 
00043 #include "Media/MovieDecoder.H"
00044 
00045 #include <deque>
00046 #define attribute_deprecated
00047 extern "C"
00048 {
00049 #if defined (HAVE_FFMPEG_AVCODEC_H)
00050 #include <ffmpeg/avcodec.h>
00051 #elif defined(HAVE_LIBAVCODEC_AVCODEC_H)
00052 #include <libavcodec/avcodec.h>
00053 #endif
00054 
00055 #if defined (HAVE_FFMPEG_AVFORMAT_H)
00056 #include <ffmpeg/avformat.h>
00057 #elif defined(HAVE_LIBAVFORMAT_AVFORMAT_H)
00058 #include <libavformat/avformat.h>
00059 #endif
00060 }
00061 #include <string>
00062 #include <vector>
00063 
00064 /// Decode a movie using ffmpeg's libavformat packet streaming API
00065 class FfmpegPacketDecoder : public MovieDecoder
00066 {
00067 public:
00068 
00069   /// Construct from a given filename
00070   FfmpegPacketDecoder(const char* fname, const bool preload);
00071 
00072   /// Virtual destructor for safe inheritance
00073   ~FfmpegPacketDecoder();
00074 
00075   /// Get the "apparent" frame number
00076   /** This function takes into account whether or not the next frame
00077       will be a push-back frame */
00078   virtual int apparentFrameNumber() const;
00079 
00080   /// Get the specifications of the movie frames
00081   virtual GenericFrameSpec peekFrameSpec();
00082 
00083   /// Get the next raw VideoFrame from the stream
00084   virtual VideoFrame readVideoFrame();
00085 
00086   /// Read an RGB image from the stream
00087   virtual Image<PixRGB<byte> > readRGB();
00088 
00089   /// Read a frame from the stream and discard it
00090   /** If you know you are going to discard the frame (e.g. to skip
00091       ahead to a certain frame number, or to count the frame), then it
00092       is more efficient to call readAndDiscardFrame() than to call
00093       readVideoFrame() or readRGB() but ignore the result. */
00094   virtual bool readAndDiscardFrame();
00095 
00096 private:
00097   /// Try to read another AVPacket and add it to our queue; return true if successful
00098   bool getNextPacket();
00099 
00100   /// Read a raw frame from the stream
00101   /** NOTE: This function used to be public, but now we have
00102       readVideoFrame() to serve that purpose instead (returns a raw
00103       YUV frame, but with additional contextual information). If it
00104       seems that you need to make readRawFrame() public again, that
00105       wouldn't be the end of the world, but first check if you could
00106       achieve what you need with an appropriate extension to the
00107       VideoFrame class. */
00108   AVFrame* readRawFrame();
00109 
00110   std::string itsFilename;
00111 
00112   AVFormatContext* itsFormatContext;
00113   AVCodecContext* itsCodecContext;
00114 
00115   int itsStreamID;
00116 
00117   AVFrame itsPicture;
00118 
00119   int itsFrameNumber;
00120   bool itsDimsValid;
00121   bool itsNextFramePushback;
00122   bool itsPacketsExhausted;
00123 
00124   std::deque<AVPacket> itsPacketQ;
00125   std::vector<AVPacket> itsPacketTrashQ;
00126 };
00127 
00128 #endif // INVT_HAVE_AVCODEC
00129 
00130 // ######################################################################
00131 /* So things look consistent in everyone's emacs... */
00132 /* Local Variables: */
00133 /* mode: c++ */
00134 /* indent-tabs-mode: nil */
00135 /* End: */
00136 
00137 #endif // MEDIA_FFMPEGPACKETDECODER_H_DEFINED
Generated on Sun May 8 08:41:00 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3