source: trunk/MagicSoft/AMC/activemirrorcontrol/activemirrorcontrol/videothread.cpp@ 4498

Last change on this file since 4498 was 4498, checked in by merck, 20 years ago
MMerck: Added some code to synchronize with frame grabber.
File size: 2.5 KB
Line 
1/***************************************************************************
2 videothread.cpp - description
3 -------------------
4 begin : Sat Aug 30 2003
5 copyright : (C) 2003 by Martin Merck
6 email : merck@astro.uni-wuerzburg.de
7 ***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
18#include "videothread.h"
19#include "amcframegrabber.h"
20#include "threadevent.h"
21#include <unistd.h>
22
23VideoThread::VideoThread( QObject* p_pReceiver, AMCFrameGrabber* p_pFG )
24 : m_pReceiver(p_pReceiver), m_pFG(p_pFG), m_zValid(false), m_zRun(false), m_iCurFrame(0)
25{
26}
27
28VideoThread::~VideoThread()
29{
30 if( m_zRun )
31 stop();
32 wait();
33// m_pFG->waitTillInactive();
34
35 if( m_zValid )
36 for( int i=0; i<2; i++)
37 {
38 if ( m_pData != NULL )
39 delete[] m_pData[i];
40 }
41}
42
43/** No descriptions */
44void VideoThread::init( int p_iSize )
45{
46 if( m_zValid )
47 return;
48 m_iSize = p_iSize;
49 for( int i=0; i<2; i++)
50 {
51 m_pData[i] = new uchar[ p_iSize ];
52 if ( m_pData == NULL )
53 {
54 fprintf(stderr, "new char(%d) failed\n", m_iSize);
55 return;
56 }
57 m_zValid = true;
58 }
59}
60
61/** No descriptions */
62void VideoThread::run()
63{
64 qDebug("VideoThread PID: %d - PPID: %d", getpid(), getppid() );
65 m_aMutex.lock();
66 if( ! m_zValid )
67 {
68 m_aMutex.unlock();
69 return;
70 }
71
72 m_zRun = true;
73 m_aMutex.unlock();
74 while( true )
75 {
76 m_aMutex.lock();
77 if( ! m_zRun )
78 {
79 m_aMutex.unlock();
80 return;
81 }
82 uchar* pData = m_pData[m_iCurFrame];
83 if ( m_iCurFrame == 0 )
84 m_iCurFrame = 1;
85 else
86 m_iCurFrame = 0;
87 m_aMutex.unlock();
88
89 m_pFG->grabFrame( pData );
90 QThread::postEvent( m_pReceiver, new QCustomEvent( THREAD_FRAME_EVENT ) );
91
92 }
93
94}
95
96void VideoThread::stop()
97{
98 m_aMutex.lock();
99 m_zRun = false;
100 m_aMutex.unlock();
101}
102
103void VideoThread::getLastFrame( uchar* p_pData )
104{
105 m_aMutex.lock();
106 memcpy( p_pData, m_pData[m_iCurFrame], m_iSize);
107 m_aMutex.unlock();
108}
Note: See TracBrowser for help on using the repository browser.