XnStatus XnSensorClient::Listen() { XnStatus nRetVal = XN_STATUS_OK; while (m_bShouldRun) { nRetVal = ReadNextEventFromStream(); if (nRetVal == XN_STATUS_OS_NETWORK_TIMEOUT) { continue; } else if ((nRetVal == XN_STATUS_OS_NETWORK_CONNECTION_CLOSED) && !m_bShouldRun) { xnLogInfo(XN_MASK_SENSOR_CLIENT, "Client connection was closed gracefully"); } else if (nRetVal != XN_STATUS_OK) { XnIONetworkStream* pStream = (XnIONetworkStream*)GetIOStream(); if (!pStream->IsConnected()) { m_bConnected = FALSE; xnLogError(XN_MASK_SENSOR_CLIENT, "Server has disconnected!"); break; } else { xnLogWarning(XN_MASK_SENSOR_CLIENT, "Sensor client failed to handle event: %s", xnGetStatusString(nRetVal)); } } } return (XN_STATUS_OK); }
XnStatus XnFileDevice::ReadTillNextData(XnBool* pbWrapOccurred) { XnStatus nRetVal = XN_STATUS_OK; *pbWrapOccurred = FALSE; if (m_nFileVersion < 4) { nRetVal = BCReadFrame(pbWrapOccurred); XN_IS_STATUS_OK(nRetVal); } else { XnPackedDataType nType = XN_PACKED_END; while ((nType != XN_PACKED_STREAM_DATA) && (!m_bEOF)) { nRetVal = ReadNextEventFromStream(&nType); XN_IS_STATUS_OK(nRetVal); if (nType == XN_PACKED_END) { *pbWrapOccurred = TRUE; } } if (nType == XN_PACKED_STREAM_DATA) { m_bFileHasData = TRUE; } } return (XN_STATUS_OK); }
XnStatus XnFileDevice::SeekTo(XnUInt64 nMinTimestamp, const XnChar* strNodeName, XnUInt32 nMinFrameID) { XnStatus nRetVal = XN_STATUS_OK; // first check if we need to seek forward or backwards (even if we're in the correct location, // we need to rewind, so that next read will return this frame again). XnNodeInfo* pNodeInfo = NULL; if (strNodeName != NULL) { nRetVal = m_nodeInfoMap.Get(strNodeName, pNodeInfo); XN_IS_STATUS_OK(nRetVal); if (nMinFrameID <= pNodeInfo->nCurrFrameID) { nRetVal = Rewind(); XN_IS_STATUS_OK(nRetVal); } } else { if (nMinTimestamp <= m_nCurrTimestamp) { nRetVal = Rewind(); XN_IS_STATUS_OK(nRetVal); } } XnBool bFoundNewData = FALSE; // Keep current position. XnUInt32 nStartingPosition; nRetVal = m_pInputStream->Tell(&nStartingPosition); XN_IS_STATUS_OK(nRetVal); // start seeking forward until point is reached. XnUInt32 nFoundPosition; XnPackedDataType nType = (XnPackedDataType)-1; XnLastStreamDataHash StreamsHash; for (;;) { XnUInt32 nPositionBefore; nRetVal = m_pInputStream->Tell(&nPositionBefore); XN_IS_STATUS_OK(nRetVal); nRetVal = m_pDataPacker->ReadNextObject(&nType); XN_IS_STATUS_OK(nRetVal); XnUInt32 nPositionAfter; nRetVal = m_pInputStream->Tell(&nPositionAfter); XN_IS_STATUS_OK(nRetVal); if (nType == XN_PACKED_STREAM_DATA) { bFoundNewData = TRUE; XnStreamData props; XnCompressionFormats nCompression; XnUInt32 nCompressedSize; nRetVal = m_pDataPacker->ReadStreamDataProps(&props, &nCompression, &nCompressedSize); XN_IS_STATUS_OK(nRetVal); XnLastStreamData data; if (XN_STATUS_OK != StreamsHash.Get(props.StreamName, data)) { XnNodeInfo* pNodeInfo = NULL; nRetVal = m_nodeInfoMap.Get(props.StreamName, pNodeInfo); XN_IS_STATUS_OK(nRetVal); data.nFrameID = pNodeInfo->nCurrFrameID + 1; } else { // if we had previous data from this stream, ignore it m_PositionsToIgnore.Set(data.nPosition, 0); ++data.nFrameID; } data.nPosition = nPositionAfter; data.nTimestamp = props.nTimestamp; nRetVal = StreamsHash.Set(props.StreamName, data); XN_IS_STATUS_OK(nRetVal); // now check if condition is met if (strNodeName != NULL) { if (strcmp(strNodeName, props.StreamName) == 0 && data.nFrameID >= nMinFrameID) { // keep this position (we'll read up till here). nFoundPosition = nPositionAfter; break; } } else if (data.nTimestamp >= nMinTimestamp) { // keep this position (we'll read up till here). nFoundPosition = nPositionAfter; break; } } else if (nType == XN_PACKED_END) { // we'll read up to the last data of each stream nFoundPosition = nPositionBefore; break; } } // now seek back nRetVal = m_pInputStream->Seek(nStartingPosition); XN_IS_STATUS_OK(nRetVal); if (bFoundNewData) { // read everything up to position XnUInt32 nPositionAfter = nStartingPosition; while (nPositionAfter < nFoundPosition) { nRetVal = ReadNextEventFromStream(&nType); XN_IS_STATUS_OK(nRetVal); nRetVal = m_pInputStream->Tell(&nPositionAfter); XN_IS_STATUS_OK(nRetVal); } } else { /* // just remark the data as new (this is last frame, return it again to user) XnDeviceModuleHolderList streams; nRetVal = GetStreamsList(streams); XN_IS_STATUS_OK(nRetVal); for (XnDeviceModuleHolderList::Iterator it = streams.Begin(); it != streams.End(); ++it) { XnStreamReaderStream* pStream = (XnStreamReaderStream*)(*it)->GetModule(); pStream->ReMarkDataAsNew(); } */ } return (XN_STATUS_OK); }
XnStatus XnDeviceFileReader::SeekTo(XnUInt64 nMinTimestamp, XnUInt32 nMinFrameID) { XnStatus nRetVal = XN_STATUS_OK; // first check if we need to seek forward or backwards (even if we're in the correct location, // we need to rewind, so that next read will return this frame again). if ((nMinTimestamp != 0 && nMinTimestamp <= GetLastTimestamp()) || (nMinFrameID != 0 && nMinFrameID <= GetLastFrameID())) { nRetVal = Rewind(); XN_IS_STATUS_OK(nRetVal); } XnBool bFoundNewData = FALSE; // Keep current position. XnUInt64 nStartingPosition; nRetVal = GetIOStream()->Tell(&nStartingPosition); XN_IS_STATUS_OK(nRetVal); // Take primary stream (it determines frame ID and timestamp) XnPackedDataType nType = (XnPackedDataType)-1; const XnChar* strPrimaryStream = GetPrimaryStream(); if (strcmp(strPrimaryStream, XN_PRIMARY_STREAM_ANY) == 0 || strcmp(strPrimaryStream, XN_PRIMARY_STREAM_NONE) == 0) { strPrimaryStream = NULL; } // start seeking forward until point is reached. XnUInt64 nFoundPosition; XnLastStreamDataHash StreamsHash; for (;;) { XnUInt64 nPositionBefore; nRetVal = GetIOStream()->Tell(&nPositionBefore); XN_IS_STATUS_OK(nRetVal); nRetVal = GetDataPacker()->ReadNextObject(&nType); XN_IS_STATUS_OK(nRetVal); XnUInt64 nPositionAfter; nRetVal = GetIOStream()->Tell(&nPositionAfter); XN_IS_STATUS_OK(nRetVal); if (nType == XN_PACKED_STREAM_DATA) { bFoundNewData = TRUE; XnStreamData props; XnCompressionFormats nCompression; XnUInt32 nCompressedSize; nRetVal = GetDataPacker()->ReadStreamDataProps(&props, &nCompression, &nCompressedSize); XN_IS_STATUS_OK(nRetVal); XnLastStreamData data; if (XN_STATUS_OK != StreamsHash.Get(props.StreamName, data)) { XnStreamDeviceStreamHolder* pHolder; nRetVal = FindStream(props.StreamName, &pHolder); XN_IS_STATUS_OK(nRetVal); data.nFrameID = pHolder->GetStream()->GetLastFrameID() + 1; } else { // if we had previous data from this stream, ignore it m_PositionsToIgnore.Set(data.nPosition, 0); ++data.nFrameID; } data.nPosition = nPositionAfter; data.nTimestamp = props.nTimestamp; nRetVal = StreamsHash.Set(props.StreamName, data); XN_IS_STATUS_OK(nRetVal); // now check if condition is met if (strPrimaryStream == NULL || strcmp(strPrimaryStream, props.StreamName) == 0) { if (data.nFrameID >= nMinFrameID && data.nTimestamp >= nMinTimestamp) { // we have everything we need // keep this position (we'll read up till here). nFoundPosition = nPositionAfter; break; } } } else if (nType == XN_PACKED_END) { // we'll read up to the last data of each stream nFoundPosition = nPositionBefore; break; } } // now seek back nRetVal = GetIOStream()->Seek(nStartingPosition); XN_IS_STATUS_OK(nRetVal); if (bFoundNewData) { // read everything up to position XnUInt64 nPositionAfter = nStartingPosition; while (nPositionAfter < nFoundPosition) { nRetVal = ReadNextEventFromStream(&nType); XN_IS_STATUS_OK(nRetVal); nRetVal = GetIOStream()->Tell(&nPositionAfter); XN_IS_STATUS_OK(nRetVal); } } else { // just remark the data as new (this is last frame, return it again to user) XnDeviceModuleHolderList streams; nRetVal = GetStreamsList(streams); XN_IS_STATUS_OK(nRetVal); for (XnDeviceModuleHolderList::Iterator it = streams.Begin(); it != streams.End(); ++it) { XnStreamReaderStream* pStream = (XnStreamReaderStream*)(*it)->GetModule(); pStream->ReMarkDataAsNew(); } } return (XN_STATUS_OK); }