XnStatus XnDeviceFileReader::HandleStreamData(XnStreamData* pDataProps, XnCompressionFormats nCompression, XnUInt32 nCompressedSize) { XnStatus nRetVal = XN_STATUS_OK; XnUInt64 nPosition; nRetVal = GetIOStream()->Tell(&nPosition); XN_IS_STATUS_OK(nRetVal); XnUIntHash::Iterator it = m_PositionsToIgnore.End(); if (XN_STATUS_OK == m_PositionsToIgnore.Find(nPosition, it)) { // ignore this one. Just update the frame ID XnStreamDeviceStreamHolder* pHolder; nRetVal = FindStream(pDataProps->StreamName, &pHolder); XN_IS_STATUS_OK(nRetVal); XnStreamReaderStream* pStream = (XnStreamReaderStream*)pHolder->GetStream(); pStream->NewDataAvailable(pDataProps->nTimestamp, pDataProps->nFrameID); // and remove it from list nRetVal = m_PositionsToIgnore.Remove(it); XN_IS_STATUS_OK(nRetVal); } else { // normal case. handle it nRetVal = XnStreamReaderDevice::HandleStreamData(pDataProps, nCompression, nCompressedSize); XN_IS_STATUS_OK(nRetVal); } return (XN_STATUS_OK); }
XnStatus XnDeviceFileWriter::FindStream(const XnChar* strName, XnFileWriterStream** ppStream) { XnStatus nRetVal = XN_STATUS_OK; XnStreamDeviceStreamHolder* pHolder = NULL; nRetVal = XnStreamWriterDevice::FindStream(strName, &pHolder); XN_IS_STATUS_OK(nRetVal); *ppStream = (XnFileWriterStream*)pHolder->GetStream(); return (XN_STATUS_OK); }
XnStatus XnSensorClient::HandlePackedObject(XnPackedDataType nObjectType) { XnStatus nRetVal = XN_STATUS_OK; XnUInt32 nDataSize = sizeof(m_LastReply); switch (nObjectType) { case XN_SENSOR_SERVER_MESSAGE_GENERAL_OP_RESPOND: case XN_SENSOR_SERVER_MESSAGE_GET_INT_PROPERTY: case XN_SENSOR_SERVER_MESSAGE_GET_REAL_PROPERTY: case XN_SENSOR_SERVER_MESSAGE_GET_STRING_PROPERTY: case XN_SENSOR_SERVER_MESSAGE_GET_GENERAL_PROPERTY: case XN_SENSOR_SERVER_MESSAGE_READ_STREAM: case XN_SENSOR_SERVER_MESSAGE_BYE: { nRetVal = GetDataPacker()->ReadCustomData(nObjectType, &m_LastReply, &nDataSize); XN_IS_STATUS_OK(nRetVal); nRetVal = xnOSSetEvent(m_hReplyEvent); XN_IS_STATUS_OK(nRetVal); break; } case XN_SENSOR_SERVER_MESSAGE_NEW_STREAM_DATA: { XnSensorServerNewStreamData message; XnUInt32 nDataSize = sizeof(message); nRetVal = GetDataPacker()->ReadCustomData(nObjectType, &message, &nDataSize); XN_IS_STATUS_OK(nRetVal); // find the stream XnStreamDeviceStreamHolder* pHolder = NULL; nRetVal = FindStream(message.strStreamName, &pHolder); XN_IS_STATUS_OK(nRetVal); pHolder->GetStream()->NewDataAvailable(message.nTimestamp, message.nFrameID); break; } default: { nRetVal = XnStreamReaderDevice::HandlePackedObject(nObjectType); XN_IS_STATUS_OK(nRetVal); } } return (XN_STATUS_OK); }
XnStatus XnSensorClient::HandleNewStream(const XnChar* strType, const XnChar* strName, const XnActualPropertiesHash* pInitialValues) { XnStatus nRetVal = XN_STATUS_OK; nRetVal = XnStreamReaderDevice::HandleNewStream(strType, strName, pInitialValues); XN_IS_STATUS_OK(nRetVal); // open shared memory XnStreamDeviceStreamHolder* pHolder = NULL; nRetVal = FindStream(strName, &pHolder); XN_IS_STATUS_OK(nRetVal); XnSensorClientStream* pStream = (XnSensorClientStream*)pHolder->GetStream(); nRetVal = pStream->OpenSharedMemory(); XN_IS_STATUS_OK(nRetVal); return (XN_STATUS_OK); }
XnStatus XnStreamReaderDevice::HandleStreamData(XnStreamData* pDataProps, XnCompressionFormats nCompression, XnUInt32 nCompressedSize) { XnStatus nRetVal = XN_STATUS_OK; // find the stream XnStreamDeviceStreamHolder* pStreamHolder; nRetVal = FindStream(pDataProps->StreamName, &pStreamHolder); XN_IS_STATUS_OK(nRetVal); XnStreamReaderStream* pStream = (XnStreamReaderStream*)pStreamHolder->GetStream(); XnStreamData* pStreamData = pStream->GetStreamData(); // check size nRetVal = XnStreamDataCheckSize(pStreamData, pStream->GetRequiredDataSize()); XN_IS_STATUS_OK(nRetVal); nRetVal = GetDataPacker()->ReadStreamData(pStreamData, pStreamHolder->GetCodec()); XN_IS_STATUS_OK(nRetVal); pStream->NewDataAvailable(pStreamData->nTimestamp, pStreamData->nFrameID); 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); }