// start the depth stream
HRESULT KinectSensor::StartDepthStream()
{
    // since this can be call publically
    // we will ensure the stream is configured and ready
    if( nullptr == m_pDepthStream )
    {
        EnableDepthStream();
    }

    // previous call failed, must be memory issue
    if( nullptr == m_pDepthStream )
    {
        return E_OUTOFMEMORY; 
    }

    // be sure the sensor is initialized before starting stream
    HRESULT hr = UpdateSensor();
    if( FAILED(hr) )
    {
        ResetDevice();
        return hr;
    }

    return m_pDepthStream->StartStream();
}
// get the depth frame data structure from the sensor
void KinectSensor::GetDepthFrameFormat( _Inout_ KINECT_IMAGE_FRAME_FORMAT* pFrame )
{
    // depth frame data requested, be sure it is configured
    if( nullptr == m_pDepthStream )
    {
        EnableDepthStream();
    }

    // get the frame format data
    if( nullptr != m_pDepthStream )
    {
        m_pDepthStream->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 depth stream
HRESULT KinectSensor::StartDepthStream()
{
    AutoLock lock(m_nuiLock);

    // since this can be call publically
    // we will ensure the stream is configured and ready
    if (nullptr == m_pDepthStream)
    {
        EnableDepthStream();
        assert(nullptr != m_pDepthStream);
    }

    // be sure the sensor is initialized before starting stream
    HRESULT hr = UpdateSensor();
    if (FAILED(hr))
    {
        ResetDevice();
        return hr;
    }

    return m_pDepthStream->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 depth stream
void KinectSensor::EnableDepthStream()
{
    EnableDepthStream(false, NUI_IMAGE_RESOLUTION_640x480);
}