00001 /*!@file Media/BufferedInputFrameSeries.H Buffered input with frames loaded in a worker thread */ 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/BufferedInputFrameSeries.H $ 00035 // $Id: BufferedInputFrameSeries.H 9819 2008-06-17 05:48:53Z itti $ 00036 // 00037 00038 #ifndef MEDIA_BUFFEREDINPUTFRAMESERIES_H_DEFINED 00039 #define MEDIA_BUFFEREDINPUTFRAMESERIES_H_DEFINED 00040 00041 #include "Component/ModelComponent.H" 00042 #include "Media/FrameSeries.H" 00043 #include "Raster/GenericFrame.H" 00044 #include "rutz/atomic.h" 00045 #include "rutz/circular_queue.h" 00046 00047 #include <list> 00048 00049 /// Buffered version of InputFrameSeries 00050 /** Frames are read from their source in a separate worker thread 00051 which fills a frame buffer queue; clients of this class running in 00052 the main thread can frames out of the queue. */ 00053 class BufferedInputFrameSeries : public ModelComponent 00054 { 00055 public: 00056 /// Construct with buffer size qmax 00057 /** @param qsize size fo the buffer 00058 @param forcergb convert to RGB in the thread, so that the 00059 GenericFrame returned will have a native type of RGB instead of 00060 whatever it might have been from the source. This can save time 00061 for the recipient since asRGB() will then be a pass-through. */ 00062 BufferedInputFrameSeries(OptionManager& mgr, const size_t qsize, 00063 const bool forcergb = false); 00064 00065 /// Get the specs of our frames 00066 GenericFrameSpec peekFrameSpec() const; 00067 00068 /// Returns the next frame out of our buffer 00069 /** Returns an empty frame if either (1) the input source is 00070 exhausted, or (2) the input buffer underflowed prior to the 00071 input source being exhausted. If you care to distinguish between 00072 these, you can pass a non-null pointer did_underflow which will 00073 be set to false in case (1) and true in case (2). It is up to 00074 the caller whether to treat premature underflow as a fatal 00075 error, or whether to retry after a delay. */ 00076 GenericFrame get(bool* did_underflow = 0); 00077 00078 private: 00079 00080 virtual void start2(); 00081 00082 virtual void stop1(); 00083 00084 static void* c_fill(void* p); 00085 00086 struct Checkpoint; 00087 00088 nub::ref<InputFrameSeries> itsSrc; 00089 GenericFrameSpec itsFrameSpec; 00090 rutz::circular_queue<GenericFrame> itsQ; 00091 pthread_mutex_t itsQmut; 00092 bool itsInputDone; 00093 bool itsStop; 00094 00095 pthread_t itsFillThread; 00096 00097 rutz::atomic_int_t itsNumFilled; 00098 00099 int itsMinNumFilled; 00100 00101 int itsFrameNum; 00102 00103 std::list<Checkpoint> itsCheckpoints; 00104 00105 const bool itsForceRGB; 00106 }; 00107 00108 // ###################################################################### 00109 /* So things look consistent in everyone's emacs... */ 00110 /* Local Variables: */ 00111 /* mode: c++ */ 00112 /* indent-tabs-mode: nil */ 00113 /* End: */ 00114 00115 #endif // MEDIA_BUFFEREDINPUTFRAMESERIES_H_DEFINED