State.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00031
00032
00033 #ifndef _STATEOV_H
00034 #define _STATEOV_H
00035
00036
00037 #include "openVideo.h"
00038 #include "PixelFormat.h"
00039
00040 #include <map>
00041 #include <string>
00042 #include <vector>
00043 #include <assert.h>
00044
00045
00046 class ACE_Thread_Mutex;
00047
00048
00049 namespace openvideo {
00050
00051
00052 class DSVLSrc;
00053
00054
00055 class OPENVIDEO_API Buffer
00056 {
00057 public:
00058 Buffer();
00059
00060 virtual ~Buffer();
00061
00062 virtual const unsigned char* getPixels() const { return buffer; }
00063
00064 virtual int getWidth() const { return width; }
00065
00066 virtual int getHeight() const { return height; }
00067
00068 virtual PIXEL_FORMAT getFormat() const { return format; }
00069
00070 virtual int getLockCounter() const { return lockCtr; }
00071
00072 virtual void lock();
00073
00074 virtual void unlock();
00075
00076 virtual bool isLocked() const { return lockCtr>0; }
00077
00078 virtual unsigned int getUpdateCounter() const { return updateCtr; }
00079
00080 protected:
00081 unsigned char* buffer;
00082 int lockCtr;
00083 unsigned int updateCtr;
00084 ACE_Thread_Mutex* mutex;
00085 int width,height;
00086 PIXEL_FORMAT format;
00087 };
00088
00089
00090 typedef std::vector<Buffer*> BufferVector;
00091
00104 class OPENVIDEO_API State
00105 {
00106 public:
00110 State();
00111
00115 virtual ~State();
00116
00120 int width;
00121
00125 int height;
00126
00130 PIXEL_FORMAT format;
00131
00135 void clear();
00136
00140 void addElement(std::string key,void* value);
00141
00145 void* getElementData(std::string key);
00146
00150 void removeElement(std::string key);
00151
00153 virtual Buffer* getCurrentBuffer() { return currentBuffer; }
00154
00156 void unlockAllBuffers();
00157
00158
00160 Buffer* findFreeBuffer();
00161
00162 int getNumFrames() const { return buffers.size(); }
00163
00164 int getNumLockedBuffers() const;
00165
00166 private:
00170 std::map<std::string,void*> elements;
00171
00172
00173 protected:
00174 BufferVector buffers;
00175 Buffer* currentBuffer;
00176 };
00177
00178
00180
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201 class OPENVIDEO_API BufferSynchronizer
00202 {
00203 public:
00204 BufferSynchronizer();
00205 ~BufferSynchronizer();
00206
00208
00212 void assign(Buffer* newBuffer);
00213
00215
00221 Buffer* getLocked();
00222
00223 protected:
00224 Buffer* buffer;
00225 ACE_Thread_Mutex* mutex;
00226 };
00227
00228
00229
00230
00231
00232 using namespace openvideo;
00233
00234 inline State::State()
00235 {
00236 clear();
00237 }
00238 inline State::~State()
00239 {
00240 clear();
00241 }
00242
00243 inline void
00244 State::clear()
00245 {
00246 elements.clear();
00247 width = height =0;
00248 format = FORMAT_UNKNOWN;
00249 currentBuffer = NULL;
00250
00251 }
00252 inline void
00253 State::addElement(std::string key,void* value)
00254 {
00255 elements[key]=value;
00256 }
00257
00258 inline void*
00259 State::getElementData(std::string key)
00260 {
00261 std::map<std::string,void*>::iterator it = elements.find( key );
00262 if( it == elements.end())
00263 return NULL;
00264
00265 return it->second;
00266 }
00267
00268 inline void
00269 State::removeElement(std::string key)
00270 {
00271 elements.erase(key);
00272 }
00273
00274
00275 }
00276
00277
00278 #endif //_STATEOV_H
00279