XnStatus XnSensor::LoadConfigFromFile(const XnChar* csINIFilePath, const XnChar* csSectionName) { XnStatus nRetVal = XN_STATUS_OK; XN_VALIDATE_INPUT_PTR(csINIFilePath); XN_VALIDATE_INPUT_PTR(csSectionName); // we first need to configure the USB interface (we want to do so BEFORE creating streams) nRetVal = m_Interface.ReadValueFromFile(csINIFilePath, XN_MODULE_NAME_DEVICE); XN_IS_STATUS_OK(nRetVal); nRetVal = m_ReadFromEP1.ReadValueFromFile(csINIFilePath, XN_MODULE_NAME_DEVICE); XN_IS_STATUS_OK(nRetVal); nRetVal = m_ReadFromEP2.ReadValueFromFile(csINIFilePath, XN_MODULE_NAME_DEVICE); XN_IS_STATUS_OK(nRetVal); nRetVal = m_ReadFromEP3.ReadValueFromFile(csINIFilePath, XN_MODULE_NAME_DEVICE); XN_IS_STATUS_OK(nRetVal); // now create all streams nRetVal = CreateStreamsFromFile(csINIFilePath, csSectionName); XN_IS_STATUS_OK(nRetVal); // now configure DEVICE module (primary stream, global mirror, etc.) nRetVal = DeviceModule()->LoadConfigFromFile(csINIFilePath, XN_MODULE_NAME_DEVICE); XN_IS_STATUS_OK(nRetVal); // and now configure the streams XnDeviceModuleHolderList streams; nRetVal = GetStreamsList(streams); XN_IS_STATUS_OK(nRetVal); for (XnDeviceModuleHolderList::Iterator it = streams.Begin(); it != streams.End(); ++it) { XnDeviceModuleHolder* pHolder = *it; nRetVal = pHolder->GetModule()->LoadConfigFromFile(csINIFilePath); XN_IS_STATUS_OK(nRetVal); } 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); }
XnStatus XnDeviceFileReader::Rewind() { XnStatus nRetVal = XN_STATUS_OK; // go back to start of stream nRetVal = GetIOStream()->Seek(XN_DEVICE_FILE_MAGIC_LEN); XN_IS_STATUS_OK(nRetVal); // read initial state XN_PROPERTY_SET_CREATE_ON_STACK(state); nRetVal = ReadInitialState(&state); XN_IS_STATUS_OK(nRetVal); // first handle current streams. remove or reset them XnDeviceModuleHolderList streams; nRetVal = GetStreamsList(streams); XN_IS_STATUS_OK(nRetVal); for (XnDeviceModuleHolderList::Iterator it = streams.Begin(); it != streams.End(); ++it) { XnDeviceModuleHolder* pHolder = *it; if (m_bStreamsCollectionChanged) { // we need to destroy all streams, and recreate them later nRetVal = DestroyStream(pHolder->GetModule()->GetName()); XN_IS_STATUS_OK(nRetVal); } else { // just reset frame ID XnStreamReaderStream* pStream = (XnStreamReaderStream*)pHolder->GetModule(); pStream->Reset(); } } // if we need, recreate streams if (m_bStreamsCollectionChanged) { nRetVal = CreateStreams(&state); XN_IS_STATUS_OK(nRetVal); } // now set state. for (XnPropertySetData::Iterator it = state.pData->Begin(); it != state.pData->End(); ++it) { const XnChar* strName = it->Key(); XnActualPropertiesHash* pHash = it->Value(); // fix it first if (strcmp(strName, XN_MODULE_NAME_DEVICE) == 0) { pHash->Remove(XN_MODULE_PROPERTY_READ_WRITE_MODE); pHash->Remove(XN_MODULE_PROPERTY_PRIMARY_STREAM); } XnDeviceModule* pModule; nRetVal = FindModule(strName, &pModule); XN_IS_STATUS_OK(nRetVal); nRetVal = pModule->UnsafeBatchConfig(*pHash); XN_IS_STATUS_OK(nRetVal); } ResetLastTimestampAndFrame(); m_nReferenceTimestamp = 0; m_nReferenceTime = 0; m_bStreamsCollectionChanged = FALSE; return (XN_STATUS_OK); }