From 8303597a865400a363ae574ccde819302495f498 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Tue, 2 Apr 2013 18:41:01 +0200 Subject: Just put everything new in. Conflict resolution will be later --- ftnoir_tracker_udp/ftnoir_ftnclientcontrols.ui | 2 +- ftnoir_tracker_udp/ftnoir_tracker_udp.cpp | 105 +++++++---------------- ftnoir_tracker_udp/ftnoir_tracker_udp.h | 32 +++---- ftnoir_tracker_udp/ftnoir_tracker_udp_dialog.cpp | 7 +- ftnoir_tracker_udp/ftnoir_tracker_udp_dll.cpp | 7 +- 5 files changed, 57 insertions(+), 96 deletions(-) (limited to 'ftnoir_tracker_udp') diff --git a/ftnoir_tracker_udp/ftnoir_ftnclientcontrols.ui b/ftnoir_tracker_udp/ftnoir_ftnclientcontrols.ui index 7ac6c0f4..5883e317 100644 --- a/ftnoir_tracker_udp/ftnoir_ftnclientcontrols.ui +++ b/ftnoir_tracker_udp/ftnoir_ftnclientcontrols.ui @@ -15,7 +15,7 @@ - images/FaceTrackNoIR.icoimages/FaceTrackNoIR.ico + images/FaceTrackNoIR.pngimages/FaceTrackNoIR.png Qt::LeftToRight diff --git a/ftnoir_tracker_udp/ftnoir_tracker_udp.cpp b/ftnoir_tracker_udp/ftnoir_tracker_udp.cpp index 102c85bd..4978fa8d 100644 --- a/ftnoir_tracker_udp/ftnoir_tracker_udp.cpp +++ b/ftnoir_tracker_udp/ftnoir_tracker_udp.cpp @@ -23,16 +23,13 @@ * * ********************************************************************************/ #include "ftnoir_tracker_udp.h" +#include "facetracknoir/global-settings.h" FTNoIR_Tracker::FTNoIR_Tracker() { inSocket = 0; outSocket = 0; - // Create events - m_StopThread = CreateEvent(0, TRUE, FALSE, 0); - m_WaitThread = CreateEvent(0, TRUE, FALSE, 0); - bEnableRoll = true; bEnablePitch = true; bEnableYaw = true; @@ -51,18 +48,6 @@ FTNoIR_Tracker::FTNoIR_Tracker() FTNoIR_Tracker::~FTNoIR_Tracker() { - // Trigger thread to stop - ::SetEvent(m_StopThread); - - // Wait until thread finished - if (isRunning()) { - ::WaitForSingleObject(m_WaitThread, INFINITE); - } - - // Close handles - ::CloseHandle(m_StopThread); - ::CloseHandle(m_WaitThread); - if (inSocket) { inSocket->close(); delete inSocket; @@ -77,7 +62,6 @@ FTNoIR_Tracker::~FTNoIR_Tracker() /** QThread run @override **/ void FTNoIR_Tracker::run() { -int no_bytes; QHostAddress sender; quint16 senderPort; @@ -85,77 +69,51 @@ quint16 senderPort; // Read the data that was received. // forever { - - // Check event for stop thread - if(::WaitForSingleObject(m_StopThread, 0) == WAIT_OBJECT_0) - { - // Set event - ::SetEvent(m_WaitThread); - qDebug() << "FTNoIR_Tracker::run() terminated run()"; - return; - } - + if (should_quit) + break; if (inSocket != 0) { while (inSocket->hasPendingDatagrams()) { QByteArray datagram; datagram.resize(inSocket->pendingDatagramSize()); - + mutex.lock(); inSocket->readDatagram( (char * ) &newHeadPose, sizeof(newHeadPose), &sender, &senderPort); + mutex.unlock(); } } else { - qDebug() << "FTNoIR_Tracker::run() insocket not ready: exit run()"; - return; + break; } - //for lower cpu load usleep(10000); -// yieldCurrentThread(); - } -} - -void FTNoIR_Tracker::Initialize( QFrame *videoframe ) -{ - qDebug() << "FTNoIR_Tracker::Initialize says: Starting "; - loadSettings(); - - // - // Create UDP-sockets if they don't exist already. - // They must be created here, because they must be in the new thread (FTNoIR_Tracker::run()) - // - if (inSocket == 0) { - qDebug() << "FTNoIR_Tracker::Initialize() creating insocket"; - inSocket = new QUdpSocket(); - // Connect the inSocket to the port, to receive messages - - if (!inSocket->bind(QHostAddress::Any, (int) portAddress, QUdpSocket::ShareAddress | QUdpSocket::ReuseAddressHint)) { - QMessageBox::warning(0,"FaceTrackNoIR Error", "Unable to bind UDP-port",QMessageBox::Ok,QMessageBox::NoButton); - delete inSocket; - inSocket = 0; - } } - - return; -} - -void FTNoIR_Tracker::StartTracker( HWND parent_window ) -{ - start( QThread::TimeCriticalPriority ); - return; } -void FTNoIR_Tracker::StopTracker( bool exit ) +void FTNoIR_Tracker::StartTracker(QFrame* videoFrame) { - // - // OK, the thread is not stopped, doing this. That might be dangerous anyway... - // - if (exit || !exit) return; + loadSettings(); + // + // Create UDP-sockets if they don't exist already. + // They must be created here, because they must be in the new thread (FTNoIR_Tracker::run()) + // + if (inSocket == 0) { + qDebug() << "FTNoIR_Tracker::Initialize() creating insocket"; + inSocket = new QUdpSocket(); + // Connect the inSocket to the port, to receive messages + + if (!inSocket->bind(QHostAddress::Any, (int) portAddress, QUdpSocket::ShareAddress | QUdpSocket::ReuseAddressHint)) { + QMessageBox::warning(0,"FaceTrackNoIR Error", "Unable to bind UDP-port",QMessageBox::Ok,QMessageBox::NoButton); + delete inSocket; + inSocket = 0; + } + } + start(); return; } bool FTNoIR_Tracker::GiveHeadPoseData(THeadPoseData *data) { + mutex.lock(); if (bEnableX) { data->x = newHeadPose.x; } @@ -165,15 +123,16 @@ bool FTNoIR_Tracker::GiveHeadPoseData(THeadPoseData *data) if (bEnableX) { data->z = newHeadPose.z; } - if (bEnableX) { + if (bEnableYaw) { data->yaw = newHeadPose.yaw; } - if (bEnableX) { + if (bEnablePitch) { data->pitch = newHeadPose.pitch; } - if (bEnableX) { + if (bEnableRoll) { data->roll = newHeadPose.roll; } + mutex.unlock(); return true; } @@ -209,9 +168,9 @@ void FTNoIR_Tracker::loadSettings() { // GetTracker - Undecorated name, which can be easily used with GetProcAddress // Win32 API function. // _GetTracker@0 - Common name decoration for __stdcall functions in C language. -#pragma comment(linker, "/export:GetTracker=_GetTracker@0") +//#pragma comment(linker, "/export:GetTracker=_GetTracker@0") -FTNOIR_TRACKER_BASE_EXPORT ITrackerPtr __stdcall GetTracker() +extern "C" FTNOIR_TRACKER_BASE_EXPORT void* CALLING_CONVENTION GetConstructor() { - return new FTNoIR_Tracker; + return (ITracker*) new FTNoIR_Tracker; } diff --git a/ftnoir_tracker_udp/ftnoir_tracker_udp.h b/ftnoir_tracker_udp/ftnoir_tracker_udp.h index 94645c84..d60b27a4 100644 --- a/ftnoir_tracker_udp/ftnoir_tracker_udp.h +++ b/ftnoir_tracker_udp/ftnoir_tracker_udp.h @@ -1,39 +1,38 @@ -#include "..\ftnoir_tracker_base\ftnoir_tracker_base.h" -#include "ui_FTNoIR_FTNClientcontrols.h" +#include "ftnoir_tracker_base/ftnoir_tracker_base.h" +#include "ui_ftnoir_ftnclientcontrols.h" #include #include #include #include -#include "Windows.h" -#include "math.h" +#include +#include +#include +#include "facetracknoir/global-settings.h" -class FTNoIR_Tracker : public ITracker, QThread +class FTNoIR_Tracker : public ITracker, public QThread { public: FTNoIR_Tracker(); ~FTNoIR_Tracker(); - void Initialize( QFrame *videoframe ); - void StartTracker( HWND parent_window ); - void StopTracker( bool exit ); + void StartTracker( QFrame *videoframe ); bool GiveHeadPoseData(THeadPoseData *data); void loadSettings(); + volatile bool should_quit; + void WaitForExit() { + should_quit = true; + wait(); + } protected: void run(); // qthread override run method private: - // Handles to neatly terminate thread... - HANDLE m_StopThread; - HANDLE m_WaitThread; - // UDP socket-variables QUdpSocket *inSocket; // Receive from ... QUdpSocket *outSocket; // Send to ... QHostAddress destIP; // Destination IP-address - int destPort; // Destination port-number QHostAddress srcIP; // Source IP-address - int srcPort; // Source port-number THeadPoseData newHeadPose; // Structure with new headpose @@ -44,6 +43,7 @@ private: bool bEnableX; bool bEnableY; bool bEnableZ; + QMutex mutex; }; // Widget that has controls for FTNoIR protocol client-settings. @@ -53,7 +53,7 @@ class TrackerControls: public QWidget, Ui::UICFTNClientControls, public ITracker public: explicit TrackerControls(); - virtual ~TrackerControls(); + ~TrackerControls(); void showEvent ( QShowEvent * event ); void Initialize(QWidget *parent); @@ -78,7 +78,7 @@ private slots: //******************************************************************************************************* // FaceTrackNoIR Tracker DLL. Functions used to get general info on the Tracker //******************************************************************************************************* -class FTNoIR_TrackerDll : public ITrackerDll +class FTNoIR_TrackerDll : public Metadata { public: FTNoIR_TrackerDll(); diff --git a/ftnoir_tracker_udp/ftnoir_tracker_udp_dialog.cpp b/ftnoir_tracker_udp/ftnoir_tracker_udp_dialog.cpp index b489822a..b67afc66 100644 --- a/ftnoir_tracker_udp/ftnoir_tracker_udp_dialog.cpp +++ b/ftnoir_tracker_udp/ftnoir_tracker_udp_dialog.cpp @@ -23,6 +23,7 @@ * * ********************************************************************************/ #include "ftnoir_tracker_udp.h" +#include "facetracknoir/global-settings.h" //******************************************************************************************************* // FaceTrackNoIR Client Settings-dialog. @@ -173,9 +174,9 @@ void TrackerControls::save() { // GetTrackerDialog - Undecorated name, which can be easily used with GetProcAddress // Win32 API function. // _GetTrackerDialog@0 - Common name decoration for __stdcall functions in C language. -#pragma comment(linker, "/export:GetTrackerDialog=_GetTrackerDialog@0") +//#pragma comment(linker, "/export:GetTrackerDialog=_GetTrackerDialog@0") -FTNOIR_TRACKER_BASE_EXPORT ITrackerDialogPtr __stdcall GetTrackerDialog( ) +extern "C" FTNOIR_TRACKER_BASE_EXPORT void* CALLING_CONVENTION GetDialog( ) { - return new TrackerControls; + return (ITrackerDialog*) new TrackerControls; } diff --git a/ftnoir_tracker_udp/ftnoir_tracker_udp_dll.cpp b/ftnoir_tracker_udp/ftnoir_tracker_udp_dll.cpp index a086a888..cbb0c644 100644 --- a/ftnoir_tracker_udp/ftnoir_tracker_udp_dll.cpp +++ b/ftnoir_tracker_udp/ftnoir_tracker_udp_dll.cpp @@ -32,6 +32,7 @@ */ #include "ftnoir_tracker_udp.h" #include +#include "facetracknoir/global-settings.h" FTNoIR_TrackerDll::FTNoIR_TrackerDll() { //populate the description strings @@ -67,7 +68,7 @@ void FTNoIR_TrackerDll::getDescription(QString *strToBeFilled) void FTNoIR_TrackerDll::getIcon(QIcon *icon) { - *icon = QIcon(":/images/FaceTrackNoIR.ico"); + *icon = QIcon(":/images/facetracknoir.png"); }; //////////////////////////////////////////////////////////////////////////////// @@ -77,9 +78,9 @@ void FTNoIR_TrackerDll::getIcon(QIcon *icon) // GetTrackerDll - Undecorated name, which can be easily used with GetProcAddress // Win32 API function. // _GetTrackerDll@0 - Common name decoration for __stdcall functions in C language. -#pragma comment(linker, "/export:GetTrackerDll=_GetTrackerDll@0") +//#pragma comment(linker, "/export:GetTrackerDll=_GetTrackerDll@0") -FTNOIR_TRACKER_BASE_EXPORT ITrackerDllPtr __stdcall GetTrackerDll() +extern "C" FTNOIR_TRACKER_BASE_EXPORT Metadata* CALLING_CONVENTION GetMetadata() { return new FTNoIR_TrackerDll; } -- cgit v1.2.3