Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Reduced CPU usage

  • Loading branch information...
commit 4dcbcb8dcae9d356e5060c32cb97d0121bae9c9e 1 parent b43001a
@BanTheRewind authored
View
BIN  lib/KinectSdk.lib
Binary file not shown
View
BIN  lib/KinectSdk_d.lib
Binary file not shown
View
2  samples/KinectApp/src/KinectApp.cpp
@@ -122,7 +122,7 @@ class KinectApp : public ci::app::AppBasic
std::vector<std::vector<KinectSdk::JointName> > mSegments;
// Camera
- ci::CameraPersp mCamera;
+ ci::CameraPersp mCamera;
// Params
float mFrameRateApp;
View
519 src/Kinect.cpp
@@ -37,6 +37,11 @@
// Include header
#include "Kinect.h"
+#include "boost/date_time.hpp"
+#include "boost/date_time/posix_time/posix_time.hpp"
+#include "cinder/app/App.h"
+#include "cinder/Utilities.h"
+
// Kinect SDK namespace
namespace KinectSdk
{
@@ -92,25 +97,31 @@ namespace KinectSdk
{
// Initialize all values
+ mRunning = false;
init();
// Initialize skeletons
for ( int32_t i = 0; i < NUI_SKELETON_COUNT; i++ ) {
mSkeletons.push_back( Skeleton() );
}
-
+
}
// Destructor
Kinect::~Kinect()
{
- // Stop if running
+ // Stop
if ( mCapture ) {
stop();
}
+ if ( mRunning ) {
+ boost::lock_guard<boost::mutex> lock( mMutex );
+ mRunning = false;
+ mThread->join();
+ }
- // Stop threads
+ // Turn off features
enableDepth( false );
enableSkeletons( false );
enableVideo( false );
@@ -138,6 +149,11 @@ namespace KinectSdk
void Kinect::deactivateUsers()
{
+ // Thread sync
+ if ( mRunning ) {
+ boost::lock_guard<boost::mutex> lock( mMutex );
+ }
+
// DO IT!
for ( uint32_t i = 0; i < NUI_SKELETON_COUNT; i++ ) {
mActiveUsers[ i ] = false;
@@ -149,6 +165,11 @@ namespace KinectSdk
void Kinect::enableBinaryMode( bool enable, bool invertImage )
{
+ // Thread sync
+ if ( mRunning ) {
+ boost::lock_guard<boost::mutex> lock( mMutex );
+ }
+
// Update flags
mBinary = enable;
mInverted = invertImage;
@@ -158,7 +179,12 @@ namespace KinectSdk
// Enable or disable near mode
void Kinect::enableNearMode( bool enable )
{
-
+
+ // Thread sync
+ if ( mRunning ) {
+ boost::lock_guard<boost::mutex> lock( mMutex );
+ }
+
// Set flag
bool toggle = mEnabledNearMode != enable;
mEnabledNearMode = enable;
@@ -175,6 +201,11 @@ namespace KinectSdk
void Kinect::enableDepth( bool enable )
{
+ // Thread sync
+ if ( mRunning ) {
+ boost::lock_guard<boost::mutex> lock( mMutex );
+ }
+
// Set user count to 0 if disabled
if ( !enable ) {
deactivateUsers();
@@ -196,13 +227,6 @@ namespace KinectSdk
// Initialize surface
mDepthSurface = Surface8u( mDepthWidth, mDepthHeight, false, SurfaceChannelOrder::RGBA );
- // Start or stop thread
- if ( enable ) {
- mThreadDepth = boost::thread( & Kinect::processDepth, this );
- } else {
- mThreadDepth.join();
- }
-
}
}
@@ -211,6 +235,11 @@ namespace KinectSdk
void Kinect::enableSkeletons( bool enable )
{
+ // Thread sync
+ if ( mRunning ) {
+ boost::lock_guard<boost::mutex> lock( mMutex );
+ }
+
// Only supports skeletons on first device
if ( !mIsSkeletonDevice ) {
enable = false;
@@ -235,13 +264,6 @@ namespace KinectSdk
mSkeletons.push_back( Skeleton() );
}
- // Start or stop thread
- if ( enable ) {
- mThreadSkeletons = boost::thread( & Kinect::processSkeletons, this );
- } else {
- mThreadSkeletons.join();
- }
-
}
}
@@ -249,13 +271,25 @@ namespace KinectSdk
// Enable or disable user color
void Kinect::enableUserColor( bool enable )
{
+
+ // Thread sync
+ if ( mRunning ) {
+ boost::lock_guard<boost::mutex> lock( mMutex );
+ }
+
mGreyScale = !enable;
+
}
// Enable or disable video tracking
void Kinect::enableVideo( bool enable )
{
+ // Thread sync
+ if ( mRunning ) {
+ boost::lock_guard<boost::mutex> lock( mMutex );
+ }
+
// Set flag
bool toggle = mEnabledVideo != enable;
mEnabledVideo = enable;
@@ -272,13 +306,6 @@ namespace KinectSdk
// Initialize surface
mVideoSurface = Surface8u( mVideoWidth, mVideoHeight, false, SurfaceChannelOrder::RGBA );
- // Start or stop thread
- if ( enable ) {
- mThreadVideo = boost::thread( & Kinect::processVideo, this );
- } else {
- mThreadVideo.join();
- }
-
}
}
@@ -287,6 +314,11 @@ namespace KinectSdk
int32_t Kinect::getCameraAngle()
{
+ // Thread sync
+ if ( mRunning ) {
+ boost::lock_guard<boost::mutex> lock( mMutex );
+ }
+
// DO IT!
long degrees = 0L;
if ( mCapture && mSensor != 0 ) {
@@ -300,9 +332,11 @@ namespace KinectSdk
Surface8u Kinect::getDepth()
{
- // Lock thread
- boost::lock_guard<boost::mutex> lock( mMutexDepth );
-
+ // Thread sync
+ if ( mRunning ) {
+ boost::lock_guard<boost::mutex> lock( mMutex );
+ }
+
// Return surface and turn off new flag
mNewDepthFrame = false;
return mDepthSurface;
@@ -325,8 +359,10 @@ namespace KinectSdk
{
// Thread sync
- boost::lock_guard<boost::mutex> lock( mMutexSkeletons );
-
+ if ( mRunning ) {
+ boost::lock_guard<boost::mutex> lock( mMutex );
+ }
+
// Return skeletons and turn off new flag
mNewSkeletons = false;
return mSkeletons;
@@ -337,9 +373,11 @@ namespace KinectSdk
int32_t Kinect::getUserCount()
{
- // Lock thread
- boost::lock_guard<boost::mutex> lock( mMutexDepth );
-
+ // Thread sync
+ if ( mRunning ) {
+ boost::lock_guard<boost::mutex> lock( mMutex );
+ }
+
// Return user count
return mEnabledDepth ? mUserCount : 0;
@@ -349,9 +387,11 @@ namespace KinectSdk
Surface8u Kinect::getVideo()
{
- // Lock thread
- boost::lock_guard<boost::mutex> lock( mMutexVideo );
-
+ // Thread sync
+ if ( mRunning ) {
+ boost::lock_guard<boost::mutex> lock( mMutex );
+ }
+
// Return surface and turn off new flag
mNewVideoFrame = false;
return mVideoSurface;
@@ -393,7 +433,6 @@ namespace KinectSdk
mSkeletonBmp = 0;
mSkeletonDc = 0;
mSkeletonObject = 0;
- mThreadsRunning = false;
mTiltRequestTime = 0.0;
mUserCount = 0;
mVideoHeight = 480;
@@ -426,7 +465,7 @@ namespace KinectSdk
bool Kinect::openVideoStream()
{
if ( mSensor != 0 ) {
- if ( FAILED( mSensor->NuiImageStreamOpen( NUI_IMAGE_TYPE_COLOR, mVideoResolution, 0, 2, 0, & mVideoStreamHandle ) ) ) {
+ if ( FAILED( mSensor->NuiImageStreamOpen( NUI_IMAGE_TYPE_COLOR, mVideoResolution, 0, 2, 0, &mVideoStreamHandle ) ) ) {
trace( "Unable to open color image stream" );
stop();
return false;
@@ -435,266 +474,238 @@ namespace KinectSdk
return true;
}
- // Depth thread
- void Kinect::processDepth()
+ // Convert and copy pixel data to a surface
+ void Kinect::pixelToSurface( Surface8u & surface, uint8_t * buffer, bool depth )
{
- // Loop
- while ( mEnabledDepth ) {
-
- // Lock scope
- boost::lock_guard<boost::mutex> lock( mMutexDepth );
+ // Last frame still needs to be acquired
+ if ( ( depth && mNewDepthFrame ) || ( !depth && mNewVideoFrame ) ) {
+ return;
+ }
- // Need to acquire last image first
- if ( mCapture && mSensor != 0 && mDepthStreamHandle != 0 && !mNewDepthFrame ) {
+ // Get dimensions
+ int32_t height = surface.getHeight();
+ int32_t width = surface.getWidth();
+ int32_t size = width * height * 4;
- // Acquire depth image
- _NUI_IMAGE_FRAME imageFrame;
- if ( FAILED( mSensor->NuiImageStreamGetNextFrame( mDepthStreamHandle, WAIT_TIME, & imageFrame ) ) ) {
+ // This is depth data
+ if ( depth ) {
- // Try opening stream if process failed -- exit if error
- if ( !openDepthStream() ) {
- mEnabledDepth = false;
- }
+ // Draw the bits to the bitmap
+ Pixel * rgbRun = mRgbDepth;
+ uint16_t * bufferRun = (uint16_t *)buffer;
+ for ( int32_t y = 0; y < height; y++ ) {
+ for ( int32_t x = 0 ; x < width; x++ ) {
+ Pixel pixel = shortToPixel( * bufferRun );
+ bufferRun++;
+ * rgbRun = pixel;
+ rgbRun++;
+ }
+ }
- } else {
+ // Copy depth data to surface
+ memcpy( surface.getData(), (uint8_t *)mRgbDepth, size );
+ mNewDepthFrame = true;
- // Deactivate users
- deactivateUsers();
+ } else {
- // Read texture to surface
- INuiFrameTexture * texture = imageFrame.pFrameTexture;
- _NUI_LOCKED_RECT lockedRect;
- texture->LockRect( 0, & lockedRect, 0, 0 );
- if ( lockedRect.Pitch != 0 ) {
- pixelToSurface( mDepthSurface, (uint8_t *)lockedRect.pBits, true );
- } else {
- trace( "Invalid buffer length received" );
- }
+ // Swap red/blue channels
+ for ( int32_t i = 0; i < size; i += 4 ) {
+ uint8_t b = buffer[ i ];
+ buffer[ i ] = buffer[ i + 2 ];
+ buffer[ i + 2 ] = b;
+ }
- // Clean up
- mSensor->NuiImageStreamReleaseFrame( mDepthStreamHandle, & imageFrame );
+ // Copy color data to surface
+ memcpy( surface.getData(), buffer, size );
+ mNewVideoFrame = true;
- // Update frame rate
- double time = getElapsedSeconds();
- mFrameRateDepth = (float)( 1.0 / ( time - mReadTimeDepth ) );
- mReadTimeDepth = time;
+ }
- // Set flag
- mNewDepthFrame = true;
+ }
- // Update user count
- mUserCount = 0;
- for ( uint32_t i = 0; i < NUI_SKELETON_COUNT; i++ ) {
- if (mActiveUsers[ i ]) {
- mUserCount++;
- }
- }
+ // Remove background for cleaner user tracking
+ void Kinect::removeBackground( bool remove )
+ {
+ mRemoveBackground = remove;
+ }
- }
+ // Restart the device
+ void Kinect::restart()
+ {
+ stop();
+ start( mDeviceIndex, mVideoResolution, mDepthResolution, mEnabledNearMode );
+ }
- }
+ // Thread loop
+ void Kinect::run()
+ {
- // Sleep
- threadSleep();
+ // Turn on running flag
+ mRunning = true;
- }
+ // Capturing
+ while ( mRunning ) {
- // Return to join thread
- return;
+ // Lock scope
+ std::unique_lock<std::mutex> lock( mMutex );
- }
+ // Capturing
+ if ( mCapture && mSensor != 0 ) {
- // Skeleton thread
- void Kinect::processSkeletons() {
+ //////////////////////////////////////////////////////////////////////////////////////////////
- // Loop
- while (mEnabledSkeletons) {
+ if ( mEnabledDepth && mDepthStreamHandle != 0 && !mNewDepthFrame ) {
- // Lock scope
- boost::lock_guard<boost::mutex> lock( mMutexSkeletons );
-
- // Check capturing flag and device index
- if ( mCapture && mSensor != 0 && mIsSkeletonDevice && !mNewSkeletons ) {
-
- // Acquire skeleton
- _NUI_SKELETON_FRAME skeletonFrame;
- if ( !FAILED( mSensor->NuiSkeletonGetNextFrame( WAIT_TIME, & skeletonFrame ) ) ) {
-
- // Iterate through skeletons
- bool foundSkeleton = false;
- for ( int32_t i = 0; i < NUI_SKELETON_COUNT; i++ ) {
-
- // Clear skeleton data
- mSkeletons[ i ].clear();
-
- // Mark skeleton found
- if ( skeletonFrame.SkeletonData[i].eTrackingState == NUI_SKELETON_TRACKED ) {
-
- // Smooth out the skeleton data when found
- if ( !foundSkeleton ) {
- mSensor->NuiTransformSmooth( & skeletonFrame, 0 );
- PatBlt( mSkeletonDc, 0, 0, 8, 4, BLACKNESS );
- foundSkeleton = true;
- }
+ // Acquire depth image
+ _NUI_IMAGE_FRAME imageFrame;
+ if ( FAILED( mSensor->NuiImageStreamGetNextFrame( mDepthStreamHandle, WAIT_TIME, &imageFrame ) ) ) {
- // Get skeleton data
- _NUI_SKELETON_DATA skeletonData = skeletonFrame.SkeletonData[ i ];
+ // Try opening stream if process failed -- exit if error
+ if ( !openDepthStream() ) {
+ mEnabledDepth = false;
+ }
- // Set joint data
- for ( int32_t j = 0; j < (int32_t)NUI_SKELETON_POSITION_COUNT; j++ ) {
- Vector4 point = skeletonData.SkeletonPositions[ j ];
- mSkeletons[ i ].insert( std::make_pair<JointName, Vec3f>( (JointName)j, Vec3f( point.x, point.y, point.z ) ) );
- }
+ } else {
+ // Read texture to surface
+ INuiFrameTexture * texture = imageFrame.pFrameTexture;
+ _NUI_LOCKED_RECT lockedRect;
+ texture->LockRect( 0, &lockedRect, 0, 0 );
+ if ( lockedRect.Pitch != 0 ) {
+ pixelToSurface( mDepthSurface, (uint8_t *)lockedRect.pBits, true );
+ } else {
+ trace( "Invalid buffer length received" );
}
- }
+ // Clean up
+ mSensor->NuiImageStreamReleaseFrame( mDepthStreamHandle, &imageFrame );
- // Update frame rate
- double time = getElapsedSeconds();
- mFrameRateSkeletons = (float)( 1.0 / ( time - mReadTimeSkeletons ) );
- mReadTimeSkeletons = time;
+ // Update frame rate
+ double time = getElapsedSeconds();
+ mFrameRateDepth = (float)( 1.0 / ( time - mReadTimeDepth ) );
+ mReadTimeDepth = time;
- // Set flag
- mNewSkeletons = true;
+ // Set flag
+ mNewDepthFrame = true;
- }
+ // Update user count
+ mUserCount = 0;
+ for ( uint32_t i = 0; i < NUI_SKELETON_COUNT; i++ ) {
+ if ( mActiveUsers[ i ] ) {
+ mUserCount++;
+ }
+ }
- }
+ }
- // Sleep
- threadSleep();
-
- }
+ }
- // Return to join thread
- return;
+ //////////////////////////////////////////////////////////////////////////////////////////////
- }
+ if (mEnabledSkeletons && mIsSkeletonDevice && !mNewSkeletons ) {
- // Video data event handler
- void Kinect::processVideo()
- {
+ // Acquire skeleton
+ _NUI_SKELETON_FRAME skeletonFrame;
+ if ( !FAILED( mSensor->NuiSkeletonGetNextFrame( WAIT_TIME, & skeletonFrame ) ) ) {
- // Loop
- while ( mEnabledVideo ) {
+ // Iterate through skeletons
+ bool foundSkeleton = false;
+ for ( int32_t i = 0; i < NUI_SKELETON_COUNT; i++ ) {
- // Lock scope
- boost::lock_guard<boost::mutex> lock( mMutexVideo );
+ // Clear skeleton data
+ mSkeletons[ i ].clear();
- // Need to acquire last frame first
- if ( mCapture && mSensor != 0 && mVideoStreamHandle != 0 && !mNewVideoFrame ) {
+ // Mark skeleton found
+ if ( skeletonFrame.SkeletonData[i].eTrackingState == NUI_SKELETON_TRACKED ) {
- // Acquire video image
- _NUI_IMAGE_FRAME imageFrame;
- if ( FAILED( mSensor->NuiImageStreamGetNextFrame( mVideoStreamHandle, WAIT_TIME, & imageFrame ) ) ) {
+ // Smooth out the skeleton data when found
+ if ( !foundSkeleton ) {
+ mSensor->NuiTransformSmooth( & skeletonFrame, 0 );
+ PatBlt( mSkeletonDc, 0, 0, 8, 4, BLACKNESS );
+ foundSkeleton = true;
+ }
- // Try opening stream if process failed -- exit if error
- if ( openVideoStream() ) {
- mEnabledVideo = false;
- }
+ // Get skeleton data
+ _NUI_SKELETON_DATA skeletonData = skeletonFrame.SkeletonData[ i ];
- } else {
+ // Set joint data
+ for ( int32_t j = 0; j < (int32_t)NUI_SKELETON_POSITION_COUNT; j++ ) {
+ Vector4 point = skeletonData.SkeletonPositions[ j ];
+ mSkeletons[ i ].insert( std::make_pair<JointName, Vec3f>( (JointName)j, Vec3f( point.x, point.y, point.z ) ) );
+ }
- // Read texture
- INuiFrameTexture * texture = imageFrame.pFrameTexture;
- _NUI_LOCKED_RECT lockedRect;
- texture->LockRect( 0, & lockedRect, 0, 0 );
- if ( lockedRect.Pitch != 0 ) {
- pixelToSurface( mVideoSurface, (uint8_t *)lockedRect.pBits );
- } else {
- trace("Invalid buffer length received");
- }
+ }
- // Clean up
- mSensor->NuiImageStreamReleaseFrame( mVideoStreamHandle, & imageFrame );
+ }
- // Update frame rate
- double time = getElapsedSeconds();
- mFrameRateVideo = (float)( 1.0 / ( time - mReadTimeVideo ) );
- mReadTimeVideo = time;
+ // Update frame rate
+ double time = getElapsedSeconds();
+ mFrameRateSkeletons = (float)( 1.0 / ( time - mReadTimeSkeletons ) );
+ mReadTimeSkeletons = time;
- // Set flag
- mNewVideoFrame = true;
+ // Set flag
+ mNewSkeletons = true;
+
+ }
}
- }
+ //////////////////////////////////////////////////////////////////////////////////////////////
- // Sleep
- threadSleep();
+ if ( mEnabledVideo && mVideoStreamHandle != 0 && !mNewVideoFrame ) {
- }
+ // Acquire video image
+ _NUI_IMAGE_FRAME imageFrame;
+ if ( FAILED( mSensor->NuiImageStreamGetNextFrame( mVideoStreamHandle, WAIT_TIME, & imageFrame ) ) ) {
- // Return to join thread
- return;
-
- }
+ // Try opening stream if process failed -- exit if error
+ if ( openVideoStream() ) {
+ mEnabledVideo = false;
+ }
- // Convert and copy pixel data to a surface
- void Kinect::pixelToSurface( Surface8u & surface, uint8_t * buffer, bool depth )
- {
+ } else {
- // Last frame still needs to be acquired
- if ( ( depth && mNewDepthFrame ) || ( !depth && mNewVideoFrame ) ) {
- return;
- }
+ // Read texture
+ INuiFrameTexture * texture = imageFrame.pFrameTexture;
+ _NUI_LOCKED_RECT lockedRect;
+ texture->LockRect( 0, & lockedRect, 0, 0 );
+ if ( lockedRect.Pitch != 0 ) {
+ pixelToSurface( mVideoSurface, (uint8_t *)lockedRect.pBits );
+ } else {
+ trace("Invalid buffer length received");
+ }
- // Get dimensions
- int32_t height = surface.getHeight();
- int32_t width = surface.getWidth();
- int32_t size = width * height * 4;
+ // Clean up
+ mSensor->NuiImageStreamReleaseFrame( mVideoStreamHandle, &imageFrame );
- // This is depth data
- if ( depth ) {
+ // Update frame rate
+ double time = getElapsedSeconds();
+ mFrameRateVideo = (float)( 1.0 / ( time - mReadTimeVideo ) );
+ mReadTimeVideo = time;
- // Draw the bits to the bitmap
- Pixel * rgbRun = mRgbDepth;
- uint16_t * bufferRun = (uint16_t *)buffer;
- for ( int32_t y = 0; y < height; y++ ) {
- for ( int32_t x = 0 ; x < width; x++ ) {
- Pixel pixel = shortToPixel( * bufferRun );
- bufferRun++;
- * rgbRun = pixel;
- rgbRun++;
- }
- }
+ // Set flag
+ mNewVideoFrame = true;
- // Copy depth data to surface
- memcpy( surface.getData(), (uint8_t *)mRgbDepth, size );
- mNewDepthFrame = true;
+ }
- } else {
+ }
- // Swap red/blue channels
- for ( int32_t i = 0; i < size; i += 4 ) {
- uint8_t b = buffer[ i ];
- buffer[ i ] = buffer[ i + 2 ];
- buffer[ i + 2 ] = b;
}
- // Copy color data to surface
- memcpy( surface.getData(), buffer, size );
- mNewVideoFrame = true;
+ // Pause thread
+ boost::system_time const timeout = boost::get_system_time() + boost::posix_time::milliseconds( 17 );
+ mCond.timed_wait( lock, timeout, []() {
+ return true;
+ } );
}
- }
+ // Return to join thread
+ return;
- // Remove background for cleaner user tracking
- void Kinect::removeBackground( bool remove )
- {
- mRemoveBackground = remove;
}
- // Restart the device
- void Kinect::restart()
- {
- stop();
- start();
- }
-
// Set camera angle
void Kinect::setCameraAngle( int32_t degrees )
{
@@ -737,7 +748,7 @@ namespace KinectSdk
// Allocate bitmap data
mRgbDepth = new Pixel[ mDepthWidth * mDepthHeight * 4 ];
-
+
// Restart if capturing
if ( mCapture ) {
restart();
@@ -749,6 +760,11 @@ namespace KinectSdk
void Kinect::setDeviceIndex( int32_t deviceIndex )
{
+ // Thread sync
+ if ( mRunning ) {
+ boost::lock_guard<boost::mutex> lock( mMutex );
+ }
+
// Bail if no change
if ( mDeviceIndex == deviceIndex ) {
return;
@@ -827,7 +843,7 @@ namespace KinectSdk
// Binary mode
if ( mBinary ) {
-
+
// Set black and white values
uint8_t backgroundColor = mInverted ? 255 : 0;
uint8_t userColor = mInverted ? 0 : 255;
@@ -958,7 +974,7 @@ namespace KinectSdk
return;
}
- // Start threads
+ // Enable or disable features
bool enabledDepth = mEnabledDepth;
bool enabledSkeletons = mEnabledSkeletons;
bool enabledVideo = mEnabledVideo;
@@ -968,10 +984,13 @@ namespace KinectSdk
enableDepth( enabledDepth );
enableSkeletons( enabledSkeletons );
enableVideo( enabledVideo );
-
+
// Initialized
mCapture = true;
+ // Start thread
+ mThread = std::shared_ptr<boost::thread>( new boost::thread( boost::bind( &Kinect::run, this ) ) );
+
}
}
@@ -980,6 +999,12 @@ namespace KinectSdk
void Kinect::stop()
{
+ // Stop thread
+ if ( mRunning ) {
+ mRunning = false;
+ mThread->join();
+ }
+
// Only stop if capturing
if ( mCapture ) {
@@ -1008,7 +1033,7 @@ namespace KinectSdk
}
- // Stop threads
+ // Turn off features
bool enabledDepth = mEnabledDepth;
bool enabledSkeletons = mEnabledSkeletons;
bool enabledVideo = mEnabledVideo;
@@ -1026,27 +1051,13 @@ namespace KinectSdk
}
- // Sleep to improve performance
- void Kinect::threadSleep( double seconds )
- {
- static void * Timer = CreateWaitableTimer( 0, 0, 0 );
- _LARGE_INTEGER WaitTime; WaitTime.QuadPart = (long long)( seconds * -10000000.0 );
- if ( WaitTime.QuadPart >= 0 ) {
- return; // Give up the rest of the frame.
- }
- if ( !SetWaitableTimer( Timer, & WaitTime, 0, 0, 0, 0) ) {
- return;
- DWORD Result = MsgWaitForMultipleObjects( 1, &Timer, 0, 0xFFFFFFFF, QS_ALLINPUT );
- }
- }
-
// Debug trace
- void Kinect::trace( const string & message ) {
+ void Kinect::trace( const string & message )
+ {
// Write to console and debug window
console() << message << "\n";
- OutputDebugStringA( message.c_str() );
- OutputDebugStringA( "\n" );
+ OutputDebugStringA( ( message + "\n" ).c_str() );
}
View
21 src/Kinect.h
@@ -37,11 +37,9 @@
#pragma once
// Includes
-#include "cinder/app/App.h"
#include "cinder/Cinder.h"
#include "cinder/Surface.h"
#include "cinder/Thread.h"
-#include "cinder/Utilities.h"
#include <map>
#include "ole2.h"
#include "NuiApi.h"
@@ -163,7 +161,7 @@ namespace KinectSdk
static std::vector<ci::Colorf> getUserColors();
// Maximum wait time in milliseconds for new Kinect data
- static const int32_t WAIT_TIME = 175;
+ static const int32_t WAIT_TIME = 200;
static const double TILT_REQUEST_INTERVAL;
// Initialize properties
@@ -228,18 +226,11 @@ namespace KinectSdk
bool mRemoveBackground;
// Threading
- boost::mutex mMutexDepth;
- boost::mutex mMutexSkeletons;
- boost::mutex mMutexVideo;
- boost::thread mThreadDepth;
- boost::thread_group mThreadGroup;
- boost::thread mThreadSkeletons;
- bool mThreadsRunning;
- boost::thread mThreadVideo;
- void processDepth();
- void processSkeletons();
- void processVideo();
- void threadSleep( double seconds = 0.0166667 );
+ std::condition_variable mCond;
+ boost::mutex mMutex;
+ volatile bool mRunning;
+ std::shared_ptr<boost::thread> mThread;
+ void run();
// Image data
Pixel * mRgbDepth;
Please sign in to comment.
Something went wrong with that request. Please try again.