コード例 #1
0
XnStatus XN_CALLBACK_TYPE IntPropertyValueChangedCallback(const XnProperty* pSender, void* pCookie)
{
	XnStatus nRetVal = XN_STATUS_OK;
	
	// get the property current value
	XnIntProperty* pIntProp = (XnIntProperty*)pSender;

	XnUInt64 nNewValue;
	nRetVal = pIntProp->GetValue(&nNewValue);
	XN_IS_STATUS_OK(nRetVal);

	XnIntSynchronizerCookie* pSynchData = (XnIntSynchronizerCookie*)pCookie;

	XnUInt64 nDestValue;

	// convert the value if needed
	if (pSynchData->pConvertFunc != NULL)
	{
		nRetVal = pSynchData->pConvertFunc(nNewValue, &nDestValue);
		XN_IS_STATUS_OK(nRetVal);
	}
	else
	{
		nDestValue = nNewValue;
	}

	// now set the new value
	nRetVal = pSynchData->pDestination->UnsafeUpdateValue(nDestValue);
	XN_IS_STATUS_OK(nRetVal);

	return (XN_STATUS_OK);
}
XnStatus XnDeviceModule::GetProperty(const XnChar* strName, XnUInt64* pnValue) const
{
	XnStatus nRetVal = XN_STATUS_OK;
	
	XnIntProperty* pProp;
	nRetVal = GetProperty(strName, &pProp);
	XN_IS_STATUS_OK(nRetVal);

	nRetVal = pProp->GetValue(pnValue);
	XN_IS_STATUS_OK(nRetVal);
	
	return (XN_STATUS_OK);
}
コード例 #3
0
XnBool XnDeviceBase::IsStream(XnDeviceModule* pModule)
{
	XnProperty* pProperty;
	XnStatus nRetVal = pModule->GetProperty(XN_STREAM_PROPERTY_IS_STREAM, &pProperty);
	if (nRetVal != XN_STATUS_OK)
		return FALSE;

	if (pProperty->GetType() != XN_PROPERTY_TYPE_INTEGER)
		return FALSE;

	XnIntProperty* pIntProperty = (XnIntProperty*)pProperty;

	XnUInt64 nValue;
	nRetVal = pIntProperty->GetValue(&nValue);
	if (nRetVal != XN_STATUS_OK)
	{
		xnLogError(XN_MASK_DDK, "Failed getting the value of the IsStream property: %s", xnGetStatusString(nRetVal));
		return FALSE;
	}

	return (XnBool)nValue;
}
コード例 #4
0
XnStatus XnShiftToDepthStreamHelper::Init(XnDeviceModule* pModule)
{
	XnStatus nRetVal = XN_STATUS_OK;

	XN_VALIDATE_INPUT_PTR(pModule);
	m_pModule = pModule;
	
	// old depth streams did not have S2D tables as actual properties. Add these properties
	XnBool bDoesExist = FALSE;
	nRetVal = m_pModule->DoesPropertyExist(XN_STREAM_PROPERTY_S2D_TABLE, &bDoesExist);
	XN_IS_STATUS_OK(nRetVal);

	if (!bDoesExist)
	{
		// add properties to the module
		XN_VALIDATE_ADD_PROPERTIES(m_pModule, &m_ShiftToDepthTable, &m_DepthToShiftTable);

		m_bPropertiesAdded = TRUE;

		// now create tables and register to properties
		XnIntProperty* pDeviceIDProperty;
		XnUInt64* pDeviceID = 0;
		pModule->GetProperty(XN_MODULE_PROPERTY_SERIAL_NUMBER, &pDeviceIDProperty);
		pDeviceIDProperty->GetValue(pDeviceID);
		xnLogVerbose("S2D", "S2D table init for sensor ID %d.", pDeviceID);
		nRetVal = InitShiftToDepth();
		XN_IS_STATUS_OK(nRetVal);
	}
	else
	{
		m_ShiftToDepthTables.pShiftToDepthTable = (OniDepthPixel*)m_ShiftToDepthTable.GetValue().data;
		m_ShiftToDepthTables.pDepthToShiftTable = (XnUInt16*)m_DepthToShiftTable.GetValue().data;
	}
	
	return (XN_STATUS_OK);
}
XnStatus XnStreamDeviceStreamHolder::ChooseCodec()
{
	XnStatus nRetVal = XN_STATUS_OK;

	// create new codec (we also need to register on all the properties)
	XnCodec* pCodec;
	XnPropertiesList CodecProps;

	switch (GetCompression())
	{
	case XN_COMPRESSION_NONE:
		{
			XN_VALIDATE_NEW_AND_INIT(pCodec, XnUncompressedCodec);
		}
		break;
	case XN_COMPRESSION_16Z:
		{
			XN_VALIDATE_NEW_AND_INIT(pCodec, Xn16zCodec);
		}
		break;
	case XN_COMPRESSION_16Z_EMB_TABLE:
		{
			// first we need to find max depth
			XnIntProperty* pDeviceMaxDepthProp;
			nRetVal = GetStream()->GetProperty(XN_STREAM_PROPERTY_DEVICE_MAX_DEPTH, &pDeviceMaxDepthProp);
			XN_IS_STATUS_OK(nRetVal);

			XnUInt64 nMaxDepth;
			nRetVal = pDeviceMaxDepthProp->GetValue(&nMaxDepth);
			XN_IS_STATUS_OK(nRetVal);

			nRetVal = CodecProps.AddLast(pDeviceMaxDepthProp);
			XN_IS_STATUS_OK(nRetVal);

			XN_VALIDATE_NEW_AND_INIT(pCodec, Xn16zEmbTablesCodec, (XnDepthPixel)nMaxDepth);
		}
		break;
	case XN_COMPRESSION_COLOR_8Z:
		{
			XN_VALIDATE_NEW_AND_INIT(pCodec, Xn8zCodec);
		}
		break;
	case XN_COMPRESSION_JPEG:
		{
			// check what is the output format
			XnIntProperty* pOutputFormatProp;
			nRetVal = GetStream()->GetProperty(XN_STREAM_PROPERTY_OUTPUT_FORMAT, &pOutputFormatProp);
			XN_IS_STATUS_OK(nRetVal);

			XnUInt64 nOutputFormat;
			nRetVal = pOutputFormatProp->GetValue(&nOutputFormat);
			XN_IS_STATUS_OK(nRetVal);

			XnBool bRGB = FALSE;

			switch (nOutputFormat)
			{
			case XN_OUTPUT_FORMAT_GRAYSCALE8:
				bRGB = FALSE;
				break;
			case XN_OUTPUT_FORMAT_RGB24:
				bRGB = TRUE;
				break;
			default:
				XN_LOG_WARNING_RETURN(XN_STATUS_ERROR, XN_MASK_DDK, "Codec factory currently supports JPEG codec only for streams of type Gray8 or RGB24!");
			}

			nRetVal = CodecProps.AddLast(pOutputFormatProp);
			XN_IS_STATUS_OK(nRetVal);

			// X res
			XnIntProperty* pXResProp;
			nRetVal = GetStream()->GetProperty(XN_STREAM_PROPERTY_X_RES, &pXResProp);
			XN_IS_STATUS_OK(nRetVal);

			XnUInt64 nXRes;
			nRetVal = pXResProp->GetValue(&nXRes);
			XN_IS_STATUS_OK(nRetVal);

			nRetVal = CodecProps.AddLast(pXResProp);
			XN_IS_STATUS_OK(nRetVal);

			// Y res
			XnIntProperty* pYResProp;
			nRetVal = GetStream()->GetProperty(XN_STREAM_PROPERTY_Y_RES, &pYResProp);
			XN_IS_STATUS_OK(nRetVal);

			XnUInt64 nYRes;
			nRetVal = pYResProp->GetValue(&nYRes);
			XN_IS_STATUS_OK(nRetVal);

			// Cropping
			XnGeneralProperty* pCroppingProp;
			nRetVal = GetStream()->GetProperty(XN_STREAM_PROPERTY_CROPPING, &pCroppingProp);
			XN_IS_STATUS_OK(nRetVal);

			XnCropping cropping;
			nRetVal = pCroppingProp->GetValue(XN_PACK_GENERAL_BUFFER(cropping));
			XN_IS_STATUS_OK(nRetVal);

			nRetVal = CodecProps.AddLast(pCroppingProp);
			XN_IS_STATUS_OK(nRetVal);

			// calc x,y
			if (cropping.bEnabled)
			{
				nXRes = cropping.nXSize;
				nYRes = cropping.nYSize;
			}

			XN_VALIDATE_NEW_AND_INIT(pCodec, XnJpegCodec, bRGB, (XnUInt32)nXRes, (XnUInt32)nYRes);
		}
		break;
	default:
		XN_LOG_WARNING_RETURN(XN_STATUS_ERROR, XN_MASK_DDK, "Codec factory does not support compression type %d", GetCompression());
	}

	// register to new props
	for (XnPropertiesList::Iterator it = CodecProps.Begin(); it != CodecProps.End(); ++it)
	{
		XnProperty* pProp = *it;

		XnPropertiesHash::Iterator hashIt = m_CodecProperties.End();
		nRetVal = m_CodecProperties.Find(pProp, hashIt);
		if (nRetVal == XN_STATUS_NO_MATCH)
		{
			XnCallbackHandle hCallbackDummy;
			nRetVal = pProp->OnChangeEvent().Register(CodecPropertyChangedCallback, this, hCallbackDummy);
			if (nRetVal != XN_STATUS_OK)
			{
				XN_DELETE(pCodec);
				return (nRetVal);
			}

			nRetVal = m_CodecProperties.Set(pProp, NULL);
			if (nRetVal != XN_STATUS_OK)
			{
				XN_DELETE(pCodec);
				return (nRetVal);
			}
		}
		else if (nRetVal != XN_STATUS_OK)
		{
			XN_DELETE(pCodec);
			return (nRetVal);
		}
	}

	// replace it
	XN_DELETE(m_pCodec);
	m_pCodec = pCodec;

	return (XN_STATUS_OK);
}