XnStatus XnSensor::Destroy() { XnStatus nRetVal = XN_STATUS_OK; XnDevicePrivateData* pDevicePrivateData = GetDevicePrivateData(); // if needed, close the streams if (m_bInitialized && m_CloseStreamsOnShutdown.GetValue() == TRUE && m_ReadData.GetValue() == TRUE && m_ErrorState.GetValue() != XN_STATUS_DEVICE_NOT_CONNECTED) { nRetVal = m_Firmware.GetParams()->m_Stream0Mode.SetValue(XN_VIDEO_STREAM_OFF); nRetVal = m_Firmware.GetParams()->m_Stream1Mode.SetValue(XN_VIDEO_STREAM_OFF); nRetVal = m_Firmware.GetParams()->m_Stream2Mode.SetValue(XN_AUDIO_STREAM_OFF); } // close IO (including all reading threads) m_SensorIO.CloseDevice(); m_bInitialized = FALSE; if (pDevicePrivateData->hEndPointsCS != NULL) { xnOSCloseCriticalSection(&pDevicePrivateData->hEndPointsCS); pDevicePrivateData->hEndPointsCS = NULL; } // free buffers XnDeviceSensorFreeBuffers(pDevicePrivateData); if (pDevicePrivateData->hExecuteMutex != NULL) { xnOSCloseMutex(&pDevicePrivateData->hExecuteMutex); pDevicePrivateData->hExecuteMutex = NULL; } // Register USB event callback #if WIN32 nRetVal = m_SensorIO.SetCallback(NULL, this); XN_IS_STATUS_OK(nRetVal); #endif XnDeviceBase::Destroy(); // close dumps xnDumpFileClose(pDevicePrivateData->TimestampsDump); xnDumpFileClose(pDevicePrivateData->BandwidthDump); xnDumpFileClose(pDevicePrivateData->MiniPacketsDump); xnDumpFileClose(m_FrameSyncDump); m_Firmware.Free(); return (XN_STATUS_OK); }
void XnFrameStreamProcessor::OnEndOfFrame(const XnSensorProtocolResponseHeader* pHeader) { // write dump XnBuffer* pCurWriteBuffer = m_pTripleBuffer->GetWriteBuffer(); xnDumpFileWriteBuffer(m_InternalDump, pCurWriteBuffer->GetData(), pCurWriteBuffer->GetSize()); xnDumpFileClose(m_InternalDump); xnDumpFileClose(m_InDump); if (!m_bFrameCorrupted) { // mark the buffer as stable XnUInt64 nTimestamp; if (m_pDevicePrivateData->pSensor->ShouldUseHostTimestamps()) { // use the host timestamp of the first packet nTimestamp = m_nFirstPacketTimestamp; } else { // use timestamp in last packet nTimestamp = CreateTimestampFromDevice(pHeader->nTimeStamp); } OniFrame* pFrame = m_pTripleBuffer->GetWriteFrame(); pFrame->timestamp = nTimestamp; XnUInt32 nFrameID; m_pTripleBuffer->MarkWriteBufferAsStable(&nFrameID); // let inheriting classes do their stuff OnFrameReady(nFrameID, nTimestamp); } else { // restart m_pTripleBuffer->GetWriteBuffer()->Reset(); } // log bandwidth XnUInt64 nSysTime; xnOSGetTimeStamp(&nSysTime); xnDumpFileWriteString(m_pDevicePrivateData->BandwidthDump, "%llu,%s,%d,%d\n", nSysTime, m_csName, GetCurrentFrameID(), m_nBytesReceived); // re-init dumps m_InDump = xnDumpFileOpen(m_csInDumpMask, "%s_%d.raw", m_csInDumpMask, GetCurrentFrameID()); m_InternalDump = xnDumpFileOpen(m_csInternalDumpMask, "%s_%d.raw", m_csInternalDumpMask, GetCurrentFrameID()); m_nBytesReceived = 0; }
XnStatus LinkContInputStream::StopImpl() { XnStatus nRetVal = XN_STATUS_OK; if (!m_bStreaming) { return XN_STATUS_OK; } nRetVal = m_pLinkControlEndpoint->StopStreaming(m_nStreamID); XN_IS_STATUS_OK_LOG_ERROR("Stop streaming", nRetVal); m_pConnection->Disconnect(); m_bStreaming = FALSE; xnDumpFileClose(m_pDumpFile); return XN_STATUS_OK; }
XnStatus XnDeviceBase::Destroy() { XnStatus nRetVal = XN_STATUS_OK; // free all modules while (m_Modules.Size() != 0) { XnDeviceModuleHolder* pModuleHolder = m_Modules.Begin()->Value(); if (IsStream(pModuleHolder->GetModule())) { XnChar strName[XN_DEVICE_MAX_STRING_LENGTH]; strcpy(strName, pModuleHolder->GetModule()->GetName()); nRetVal = DestroyStream(strName); XN_IS_STATUS_OK(nRetVal); } else { // free memory of registered properties to this module FreeModuleRegisteredProperties(m_Modules.Begin()->Key()); pModuleHolder->GetModule()->Free(); DestroyModule(pModuleHolder); m_Modules.Remove(m_Modules.Begin()); } } m_pDevicePropertiesHolder = NULL; m_Modules.Clear(); // close dump xnDumpFileClose(m_StreamsDataDump); if (m_hLock != NULL) { xnOSCloseCriticalSection(&m_hLock); m_hLock = NULL; } return XN_STATUS_OK; }
XnAudioProcessor::~XnAudioProcessor() { xnDumpFileClose(m_AudioInDump); GetStream()->NumberOfChannelsProperty().OnChangeEvent().Unregister(m_hNumChannelsCallback); }
XnFrameStreamProcessor::~XnFrameStreamProcessor() { xnDumpFileClose(m_InDump); xnDumpFileClose(m_InternalDump); }