// start the color stream HRESULT KinectSensor::StartColorStream() { // since this can be call publically // we will ensure the stream is configured and ready if( nullptr == m_pColorStream ) { EnableColorStream(); } // previous call failed, must be memory issue if( nullptr == m_pColorStream ) { return E_OUTOFMEMORY; } // be sure the sensor is initialized before starting stream HRESULT hr = UpdateSensor(); if( FAILED(hr) ) { ResetDevice(); return hr; } return m_pColorStream->StartStream(); }
// get the color frame data structure from the sensor void KinectSensor::GetColorFrameFormat( _Inout_ KINECT_IMAGE_FRAME_FORMAT* pFrame ) { // color frame data requested, be sure it is configured if( nullptr == m_pColorStream ) { EnableColorStream(); } // get the frame format data if( nullptr != m_pColorStream ) { m_pColorStream->GetFrameFormat( pFrame ); } }
// setup or shutdown the sensor HRESULT KinectSensor::SelectSensor(bool bSelected) { HRESULT hr = S_OK; if (bSelected != m_bSelected) { // reset to a default state ResetDevice(); if (bSelected) { // enable default streams EnableColorStream(); EnableDepthStream(); } else { #ifdef KCB_ENABLE_FT // release the FaceTracker m_pFaceTracker.release(); #endif // release the coordinate mapper m_pCoordinateMapper.release(); // remove the streams m_pColorStream.release(); m_pDepthStream.release(); m_pSkeletonStream.release(); m_pAudioStream.release(); // reset the state m_hrLast = S_OK; m_eStatus = KinectSensorStatusNone; // Release the sensor m_pNuiSensor.Release(); } } m_bSelected = bSelected; // returns the state of the sensor to make a decision on being used return hr; }
// start the color stream HRESULT KinectSensor::StartColorStream() { AutoLock lock(m_nuiLock); // since this can be call publically // we will ensure the stream is configured and ready if (nullptr == m_pColorStream) { EnableColorStream(); assert(nullptr != m_pColorStream); } // be sure the sensor is initialized before starting stream HRESULT hr = UpdateSensor(); if (FAILED(hr)) { ResetDevice(); return hr; } return m_pColorStream->StartStream(); }
// setup or shutdown the sensor HRESULT KinectSensor::SelectSensor( bool bSelected ) { HRESULT hr = S_OK; if( bSelected != m_bSelected ) { // reset to a default state ResetDevice(); if( bSelected ) { // enable default streams EnableColorStream(); EnableDepthStream(); } else { // remove the streams m_pColorStream.reset(); m_pDepthStream.reset(); m_pSkeletonStream.reset(); // reset the state m_hrLast = S_OK; m_eStatus = KinectSensorStatusNone; // Release the sensor m_pNuiSensor.Release(); } } m_bSelected = bSelected; // returns the state of the sensor to make a decision on being used return hr; }
// default configuration for color stream void KinectSensor::EnableColorStream() { EnableColorStream(NUI_IMAGE_TYPE_COLOR, NUI_IMAGE_RESOLUTION_640x480); }