Пример #1
0
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);
}
Пример #2
0
XnStatus XnDeviceBase::ReadStream(XnStreamData* pStreamOutput)
{
	XnStatus nRetVal = XN_STATUS_OK;

	XN_VALIDATE_INPUT_PTR(pStreamOutput);

	if (m_ReadWriteMode.GetValue() == XN_DEVICE_MODE_WRITE)
	{
		return XN_STATUS_IO_DEVICE_WRONG_MODE;
	}

	// take the stream to read
	XnDeviceStream* pStream;
	nRetVal = FindStream(pStreamOutput->StreamName, &pStream);
	XN_IS_STATUS_OK(nRetVal);

	// make sure it is open
	if (!pStream->IsNewDataAvailable() && !pStream->IsOpen())
	{
		return XN_STATUS_STREAM_NOT_OPEN;
	}

	// wait for it to advance
	nRetVal = WaitForStream(m_hNewDataEvent, pStream);
	XN_IS_STATUS_OK(nRetVal);

	// and read
	nRetVal = ReadFromStreamImpl(pStream, pStreamOutput);
	XN_IS_STATUS_OK(nRetVal);

	return (XN_STATUS_OK);
}
Пример #3
0
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;
}
Пример #4
0
XnBool XnDeviceBase::HasPrimaryStreamAdvanced(XnStreamDataSet* pOutputSet)
{
	if (strcmp(m_PrimaryStream.GetValue(), XN_PRIMARY_STREAM_NONE) == 0)
	{
		// special case of None: condition is always true
		return TRUE;
	}

	const XnChar* astrNames[XN_DEVICE_BASE_MAX_STREAMS_COUNT];
	XnUInt32 nArraySize = XN_DEVICE_BASE_MAX_STREAMS_COUNT;

	// take a list of streams to check for new data
	if (strcmp(m_PrimaryStream.GetValue(), XN_PRIMARY_STREAM_ANY) != 0)
	{
		// we have a specific stream. Add it to the list
		astrNames[0] = m_PrimaryStream.GetValue();
		nArraySize = 1;
	}
	else
	{
		// special case of ANY. we need to check every one of requested streams
		XnStreamData* apStreamOutputs[XN_DEVICE_BASE_MAX_STREAMS_COUNT];
		if (XN_STATUS_OK != XnStreamDataSetCopyToArray(pOutputSet, apStreamOutputs, &nArraySize))
		{
			return FALSE;
		}

		for (XnUInt32 i = 0; i < nArraySize; ++i)
		{
			astrNames[i] = apStreamOutputs[i]->StreamName;
		}
	}

	// now check if we have new data
	for (XnUInt32 i = 0; i < nArraySize; ++i)
	{
		XnDeviceStream* pStream = NULL;
		if (XN_STATUS_OK == FindStream(astrNames[i], &pStream))
		{
			if (pStream->IsNewDataAvailable())
				return TRUE;
		}
	}

	return FALSE;
}