XnStatus XnDeviceBase::IsNewDataAvailable(const XnChar* StreamName, XnBool* pbNewDataAvailable, XnUInt64* pnTimestamp) { XnStatus nRetVal = XN_STATUS_OK; XN_VALIDATE_INPUT_PTR(StreamName); XN_VALIDATE_OUTPUT_PTR(pbNewDataAvailable); *pbNewDataAvailable = FALSE; if (strcmp(StreamName, XN_PRIMARY_STREAM_ANY) == 0) { const XnChar* aStreamNames[100]; XnUInt32 nCount = 100; nRetVal = GetStreamNames(aStreamNames, &nCount); XN_IS_STATUS_OK(nRetVal); for (XnUInt32 i = 0; i < nCount; ++i) { // find stream XnDeviceStream* pStream = NULL; nRetVal = FindStream(StreamName, &pStream); XN_IS_STATUS_OK(nRetVal); if (pStream->IsNewDataAvailable()) { *pbNewDataAvailable = TRUE; *pnTimestamp = pStream->GetLastTimestamp(); break; } } } else { // find stream XnDeviceStream* pStream = NULL; nRetVal = FindStream(StreamName, &pStream); XN_IS_STATUS_OK(nRetVal); if (pStream->IsNewDataAvailable()) { *pbNewDataAvailable = TRUE; *pnTimestamp = pStream->GetLastTimestamp(); } } return (XN_STATUS_OK); }
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; }