ThreadedFrameStream.h

Go to the documentation of this file.
00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 #ifndef CSL_ThreadedFrameStream_H
00010 #define CSL_ThreadedFrameStream_H
00011 
00012 #include "CSL_Core.h"
00013 #include "RingBuffer.h"
00014 #include "ThreadUtilities.h"
00015 
00016 namespace csl {
00017 
00018 
00022 class ThreadUtil {
00023 public: 
00024                         // state
00025     unsigned    mNumChannels;               
00026     unsigned    mNumBufferFrames;           
00027     bool        mIsRunning;                 
00028     int         mNumAvailableFrames;        
00029     unsigned    mAvailableFrameThreshold;   
00030     RingBuffer  mRingBuffer;                    
00031 
00033     void setSize(unsigned numChannels, unsigned numBufferFrames);
00034     void setThreshold(unsigned threshold);
00035     void setChannels(unsigned numChannels); 
00036     virtual void init(unsigned numChannels, unsigned numBufferFrames) = 0;
00037 
00038     virtual void start();
00039     virtual void stop();    
00040 
00041 protected:
00042     Synch * mSynch;
00043     Thread * mThread;
00044     Buffer mBuffer;                 
00045 };
00046 
00047 class ThreadedReader : public Effect, public ThreadUtil {
00048 public: 
00050     ThreadedReader();
00051     ThreadedReader(UnitGenerator inp);
00052     ThreadedReader(unsigned numChannels);
00053     ThreadedReader(unsigned numChannels, unsigned numFrames);
00054     ~ThreadedReader();
00055     
00056     void init(unsigned numChannels, unsigned numBufferFrames);
00058     void nextBuffer(Buffer & outputBuffer, unsigned chan) throw(CException);
00059     void start();
00060 
00061 protected:
00062     static void * FeederFunction(void * arg);       
00063     void readIntoBuffer();
00064     
00065 };
00066 
00067 class ThreadedWriter : public Writeable, public ThreadUtil {
00068 public:
00069                 // ctor / dtor
00070     ThreadedWriter();
00071     ThreadedWriter(unsigned numChannels);
00072     ThreadedWriter(unsigned numChannels, unsigned numBufferFrames);
00073     virtual ~ThreadedWriter();
00074 
00075     Writeable * mOutput;
00076     
00077                 // methods
00078     void init(unsigned numChannels, unsigned numBufferFrames);
00079     void setOutput(Writeable& output) { mOutput = &output; }
00080     void writeBuffer(Buffer & inputBuffer) throw(CException);
00081     void start();
00082     void stop();    
00083 
00084 protected:  
00085     static void * FeederFunction(void* arg);        // thread function
00086     void writeToOutput();
00087 };
00088 
00089 }
00090 
00091 #endif

Generated on Thu Sep 17 23:14:16 2009 for CSL by  doxygen 1.5.8