00001 #ifndef _BufferedSDIFFileReader_ 00002 #define _BufferedSDIFFileReader_ 00003 00004 #include "SDIFInConfig.hxx" 00005 #include "SDIFFileReader.hxx" 00006 #include "Frame.hxx" 00007 #include "Thread.hxx" 00008 #include "Mutex.hxx" 00009 #include <deque> 00010 00014 #define DEFAULT_INITIAL_NUMBER_OF_FRAMES_TO_BUFFER 50 00015 00016 00017 #define DEFAULT_FRAME_LOAD_CHUNK_SIZE 5 00018 00019 00020 #define DEFAULT_THRESHHOLD_FOR_PRELOADING 5 00021 00022 00023 #define DEFAULT_THRESHHOLD_FOR_PRELOADING_ON_THREAD 20 00024 00025 namespace CLAM 00026 { 00027 00038 class BufferedSDIFFileReader 00039 { 00040 public: 00045 BufferedSDIFFileReader(const SDIFInConfig& argSDIFInConfig); 00046 00047 virtual ~BufferedSDIFFileReader(); 00048 00054 bool Configure(const SDIFInConfig& c); 00055 00056 const SDIFInConfig GetConfig(); 00057 00061 virtual Frame* ReadFrame(); 00062 00067 void LoadFramesIntoBufferOnThread(Thread* argThread); 00068 00076 void StopLoadingFramesIntoBufferOnThread(); 00077 00081 bool IsThreaded(); 00082 00086 int GetNumberOfFramesLoaded(); 00087 00088 protected: 00089 int GetFrameBufferPosition(); 00090 void SetFrameBufferPosition(int frameBufferPosition); 00091 Frame* GetFrame( int frameBufferPosition ); 00092 00093 private: 00097 bool LoadFramesIntoBuffer(int argNumberOfBuffers); 00098 00102 void Run(); 00103 00105 SDIFFileReader mSDIFFileReader; 00107 std::deque<Frame*> frameBuffer; 00109 int frameBufferPosition; 00110 00112 int mFrameLoadChunkSize; 00114 int mThreshholdForPreloading; 00118 int mThreshholdForPreloadingOnThread; 00119 // The maximum amount of time that a thread can remain idle. After this 00120 // threshhold is crossed, the thread is stopped thereby returning it to the 00121 // pool where it can be reused. 00122 int mMaximumThreadIdleTime; 00124 bool mReaderHasMoreFrames; 00126 Thread* mThreadPtr; 00128 CBL::Functor0 mFunctor; 00129 // This is used to prevent the main thread and the reader thread from trying 00130 // to access the deque of frames simultaneously 00131 Mutex dequeMutex; 00134 // if mThreshholdForPreloadingOnThread > mThreshholdForPreloading. 00135 Mutex readSDIFMutex; 00138 int totalNumberOfFramesToLoad; 00139 }; 00140 00141 } 00142 00143 #endif 00144