XnBool XnSensor::HasSynchedFrameArrived(const XnChar* strDepthStream, const XnChar* strImageStream) { // find both streams XnDeviceStream* pDepth; XnDeviceStream* pImage; if (XN_STATUS_OK != FindStream(strDepthStream, &pDepth)) return FALSE; if (XN_STATUS_OK != FindStream(strImageStream, &pImage)) return FALSE; XnUInt32 nThreshold = XN_SENSOR_FRAME_SYNC_MAX_DIFF; if (IsHighResTimestamps()) nThreshold *= 1000; // wait for both to advance, and time difference to be less than threshold XnInt32 nTimestampDiff = XnInt32(pDepth->GetLastTimestamp() - pImage->GetLastTimestamp()); XnBool bConditionMet = ( pDepth->IsNewDataAvailable() && pImage->IsNewDataAvailable() && (XnUInt32)abs(nTimestampDiff) <= nThreshold ); if (xnLogIsDumpMaskEnabled(XN_DUMP_FRAME_SYNC)) { XnUInt64 nNow; xnOSGetHighResTimeStamp(&nNow); xnDumpWriteString(m_FrameSyncDump, "%llu,%u,%llu,%u,%llu,%s\n", nNow, pDepth->IsNewDataAvailable(), pDepth->GetLastTimestamp(), pImage->IsNewDataAvailable(), pImage->GetLastTimestamp(), bConditionMet ? "OK" : "Waiting"); } return bConditionMet; }
XnStatus PlayerNode::SeekToTimeStampAbsolute(XnUInt64 nDestTimeStamp) { XnStatus nRetVal = XN_STATUS_OK; XnUInt64 nRecordTimeStamp = 0LL; XnUInt32 nStartPos = TellStream(); //We'll revert to this in case nDestTimeStamp is beyond end of stream XN_IS_STATUS_OK(nRetVal); if (nDestTimeStamp < m_nTimeStamp) { nRetVal = Rewind(); } else if (nDestTimeStamp == m_nTimeStamp) { //Nothing to do return XN_STATUS_OK; } else if (nDestTimeStamp > m_nGlobalMaxTimeStamp) { nDestTimeStamp = m_nGlobalMaxTimeStamp; } Record record(m_pRecordBuffer, RECORD_MAX_SIZE); XnBool bEnd = FALSE; XnUInt32 nBytesRead = 0; while ((nRecordTimeStamp < nDestTimeStamp) && !bEnd) { nRetVal = ReadRecordHeader(record); XN_IS_STATUS_OK(nRetVal); switch (record.GetType()) { case RECORD_NEW_DATA: { //We already read Record::HEADER_SIZE, now read the rest of the new data record header nRetVal = Read(m_pRecordBuffer + Record::HEADER_SIZE, NewDataRecordHeader::MAX_SIZE - Record::HEADER_SIZE, nBytesRead); XN_IS_STATUS_OK(nRetVal); if (nBytesRead < NewDataRecordHeader::MAX_SIZE - Record::HEADER_SIZE) { return XN_STATUS_CORRUPT_FILE; } NewDataRecordHeader newDataRecordHeader(record); nRetVal = newDataRecordHeader.Decode(); XN_IS_STATUS_OK(nRetVal); //Save record time stamp nRecordTimeStamp = newDataRecordHeader.GetTimeStamp(); if (nRecordTimeStamp >= nDestTimeStamp) { //We're done - move back to beginning of record nRetVal = SeekStream(XN_OS_SEEK_CUR, -XnInt32(nBytesRead)); XN_IS_STATUS_OK(nRetVal); } else { //Skip to next record nRetVal = SeekStream(XN_OS_SEEK_CUR, newDataRecordHeader.GetSize() - NewDataRecordHeader::MAX_SIZE); XN_IS_STATUS_OK(nRetVal); } break; } case RECORD_END: { bEnd = TRUE; break; } case RECORD_NODE_ADDED_1_0_0_4: case RECORD_NODE_ADDED: case RECORD_INT_PROPERTY: case RECORD_REAL_PROPERTY: case RECORD_STRING_PROPERTY: case RECORD_GENERAL_PROPERTY: case RECORD_NODE_REMOVED: case RECORD_NODE_DATA_BEGIN: case RECORD_NODE_STATE_READY: { //Read rest of record and handle it normally nRetVal = Read(m_pRecordBuffer + Record::HEADER_SIZE, record.GetSize() - Record::HEADER_SIZE, nBytesRead); XN_IS_STATUS_OK(nRetVal); Record record(m_pRecordBuffer, RECORD_MAX_SIZE); nRetVal = HandleRecord(record, TRUE); XN_IS_STATUS_OK(nRetVal); break; } default: { XN_ASSERT(FALSE); return XN_STATUS_CORRUPT_FILE; } } //switch } //while if (bEnd) { SeekStream(XN_OS_SEEK_SET, nStartPos); return XN_STATUS_ILLEGAL_POSITION; } return XN_STATUS_OK; }//function