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

Last change on this file since 3401 was 3401, checked in by merck, 21 years ago
nitial checkin of AMC project
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 if( m_zValid )
33 for( int i=0; i<2; i++)
34 {
35 if ( m_pData != NULL )
36 delete[] m_pData[i];
37 }
38}
39
40/** No descriptions */
41void VideoThread::init( int p_iSize )
42{
43 if( m_zValid )
44 return;
45 m_iSize = p_iSize;
46 for( int i=0; i<2; i++)
47 {
48 m_pData[i] = new uchar[ p_iSize ];
49 if ( m_pData == NULL )
50 {
51 fprintf(stderr, "new char(%d) failed\n", m_iSize);
52 return;
53 }
54 m_zValid = true;
55 }
56}
57
58/** No descriptions */
59void VideoThread::run()
60{
61 qDebug("VideoThread PID: %d - PPID: %d", getpid(), getppid() );
62 m_aMutex.lock();
63 if( ! m_zValid )
64 {
65 m_aMutex.unlock();
66 return;
67 }
68
69 m_zRun = true;
70 m_aMutex.unlock();
71 while( true )
72 {
73 m_aMutex.lock();
74 if( ! m_zRun )
75 {
76 m_aMutex.unlock();
77 return;
78 }
79 uchar* pData = m_pData[m_iCurFrame];
80 if ( m_iCurFrame == 0 )
81 m_iCurFrame = 1;
82 else
83 m_iCurFrame = 0;
84 m_aMutex.unlock();
85
86 m_pFG->grabFrame( pData );
87 QThread::postEvent( m_pReceiver, new QCustomEvent( THREAD_FRAME_EVENT ) );
88
89 }
90
91}
92
93void VideoThread::stop()
94{
95 m_aMutex.lock();
96 m_zRun = false;
97 m_aMutex.unlock();
98}
99
100void VideoThread::getLastFrame( uchar* p_pData )
101{
102 m_aMutex.lock();
103 memcpy( p_pData, m_pData[m_iCurFrame], m_iSize);
104 m_aMutex.unlock();
105}
Note: See TracBrowser for help on using the repository browser.