Changeset 4497 for trunk/MagicSoft
- Timestamp:
- 08/04/04 16:58:33 (20 years ago)
- Location:
- trunk/MagicSoft/AMC/activemirrorcontrol/activemirrorcontrol
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/AMC/activemirrorcontrol/activemirrorcontrol/videospotthread.cpp
r3401 r4497 30 30 : m_pReceiver(p_pReceiver), m_pImage(p_pImage), m_pDark(p_pDark) 31 31 { 32 m_pData = m_pImage->bits();32 m_pData = p_pImage->bits(); 33 33 m_iScaleMax = 200; 34 34 m_zDarks = false; 35 35 m_zScale = false; 36 36 m_iSigmas = 15; 37 m_zIsActive = false; 38 m_zStop = false; 37 39 38 40 m_qlSpotList.setAutoDelete( true ); … … 47 49 void VideoSpotThread::run() 48 50 { 49 // qDebug("VideoSpotThread PID: %d - PPID: %d", getpid(), getppid() ); 50 findSpot(); 51 QThread::postEvent( m_pReceiver, new QCustomEvent( THREAD_END_EVENT ) ); 51 qDebug("VideoSpotThread PID: %d - PPID: %d", getpid(), getppid() ); 52 m_zIsActive = false; 53 m_zStop = false; 54 55 while( true ) 56 { 57 /* 58 * Check our protected state variable to see if we should stop running 59 */ 60 m_aMutex.lock(); 61 if( m_zStop ) 62 { 63 m_zIsActive = false; 64 m_aMutex.unlock(); 65 return; 66 } 67 68 /* 69 * We wait here to be woken up to process the next frame. 70 * This ensures that when we stop the thread and wan't do delete this class 71 * we get woken up for sure. 72 * Otherwise it could be that when the controlling thread sets the stop varible 73 * and tries to wake us up to finish this loop, we would still process a frame 74 * and will not get woken up. In this case the program would hang. 75 */ 76 m_aWaitCondition.wait( &m_aMutex ); 77 if( m_zStop ) 78 { 79 // qDebug("Preparing to exit: Unlocking Mutex"); 80 m_zIsActive = false; 81 m_aMutex.unlock(); 82 // qDebug("Stoping running Thread"); 83 return; 84 } 85 m_aMutex.unlock(); 86 87 findSpot(); 88 QThread::postEvent( m_pReceiver, new QCustomEvent( THREAD_SPOT_EVENT ) ); 89 90 m_aMutex.lock(); 91 m_zIsActive = false; 92 m_aMutex.unlock(); 93 } 52 94 } 53 95 … … 114 156 uchar* pData = m_pData; 115 157 uchar* pDark = m_pDark; 116 uchar* pEnd = m_pData + ( MY_HEIGHT * MY_WIDTH * MY_DEPTH);158 uchar* pEnd = pData + ( MY_HEIGHT * MY_WIDTH * MY_DEPTH); 117 159 for( ; pData < pEnd; pData++, pDark++ ) 118 160 { … … 164 206 return threshold; 165 207 } 208 209 void VideoSpotThread::stop() 210 { 211 // qDebug("Setting stop flag"); 212 m_aMutex.lock(); 213 m_zStop = true; 214 m_aMutex.unlock(); 215 } 216 217 bool VideoSpotThread::isActive() 218 { 219 m_aMutex.lock(); 220 bool zIsActive = m_zIsActive; 221 m_aMutex.unlock(); 222 223 return zIsActive; 224 } 225 226 void VideoSpotThread::wake() 227 { 228 // qDebug("Waking up the spot thread"); 229 if( running() ) 230 { 231 while( true ) 232 { 233 m_aMutex.lock(); 234 if( ! m_zIsActive ) 235 break; 236 m_aMutex.unlock(); 237 } 238 // qDebug("Setting active"); 239 m_zIsActive = true; 240 m_aMutex.unlock(); 241 242 m_aWaitCondition.wakeOne(); 243 } 244 245 } 246 247 void VideoSpotThread::getSpotList( QList<VideoSpot>* p_pSpots ) 248 { 249 250 while( true ) 251 { 252 m_aMutex.lock(); 253 if( ! m_zIsActive ) 254 break; 255 m_aMutex.unlock(); 256 } 257 p_pSpots->clear(); 258 for( VideoSpot* pActualSpot = m_qlSpotList.first(); 259 pActualSpot; pActualSpot = m_qlSpotList.next() ) 260 { 261 p_pSpots->append( new VideoSpot( *pActualSpot ) ); 262 } 263 m_aMutex.unlock(); 264 return; 265 }; 266 267 void VideoSpotThread::getFrame( uchar* p_pData ) 268 { 269 270 while( true ) 271 { 272 m_aMutex.lock(); 273 if( ! m_zIsActive ) 274 break; 275 m_aMutex.unlock(); 276 } 277 278 m_aDataMutex.lock(); 279 memcpy( p_pData, m_pData, m_pImage->numBytes()); 280 m_aDataMutex.unlock(); 281 m_aMutex.unlock(); 282 } 283 -
trunk/MagicSoft/AMC/activemirrorcontrol/activemirrorcontrol/videospotthread.h
r3401 r4497 36 36 37 37 /** No descriptions */ 38 bool isActive(); 39 40 /** No descriptions */ 41 virtual void wake(); 42 43 /** No descriptions */ 44 virtual void stop(); 45 46 /** No descriptions */ 38 47 virtual void subtractDarks(); 39 48 /** No descriptions */ … … 44 53 virtual int getThreshold(); 45 54 /** No descriptions */ 46 virtual QList<VideoSpot>& getSpotList() { return m_qlSpotList; }; 55 virtual void getSpotList( QList<VideoSpot>* p_pSpots ); 56 /** No descriptions */ 57 virtual void getFrame( uchar* p_pData ); 47 58 /** No descriptions */ 48 59 virtual void setScalingMax( int p_iVal ) { m_iScaleMax = p_iVal; }; … … 59 70 /** No descriptions */ 60 71 virtual void run(); 72 61 73 private: // Private attributes 62 74 /** */ … … 70 82 /** */ 71 83 QList<VideoSpot> m_qlSpotList; 84 /** */ 85 QMutex m_aMutex; 86 /** */ 87 QMutex m_aDataMutex; 88 /** */ 89 QWaitCondition m_aWaitCondition; 90 /** */ 91 bool m_zStop; 92 /** */ 93 bool m_zIsActive; 72 94 /** */ 73 95 bool m_zDarks;
Note:
See TracChangeset
for help on using the changeset viewer.