Example #1
0
XnStatus XnServerSession::NewStreamImpl(const XnChar* strType, const XnChar* strName, const XnPropertySet* pInitialValues)
{
	XnStatus nRetVal = XN_STATUS_OK;
	
	xnLogVerbose(XN_MASK_SENSOR_SERVER, "Client %u requested to create stream '%s' (%s)", m_nID, strName, strType);

	nRetVal = m_pSensor->GetStream(strType, pInitialValues);
	XN_IS_STATUS_OK(nRetVal);

	// send client the new stream data
	XN_PROPERTY_SET_CREATE_ON_STACK(streamProps);
	XN_PROPERTY_SET_CREATE_ON_STACK(clientStreamProps);

	// take properties
	nRetVal = m_pSensor->GetAllProperties(&streamProps, FALSE, strType);
	XN_IS_STATUS_OK(nRetVal);

	// copy relevant ones
	nRetVal = XnPropertySetCloneModule(&streamProps, &clientStreamProps, strType, strName);
	XN_IS_STATUS_OK(nRetVal);

	// now change the state property. It should be OFF, and not the real value (each client has
	// its own stream state).
	nRetVal = XnPropertySetRemoveProperty(&clientStreamProps, strName, XN_STREAM_PROPERTY_STATE);
	XN_IS_STATUS_OK(nRetVal);

	nRetVal = XnPropertySetAddIntProperty(&clientStreamProps, strName, XN_STREAM_PROPERTY_STATE, FALSE);
	XN_IS_STATUS_OK(nRetVal);

	m_pLogger->DumpMessage("NewStream", 0, m_nID, strName);

	{
		XnAutoCSLocker lock(m_hCommLock);
		nRetVal = m_privateOutgoingPacker.WriteNewStream(strType, strName, &clientStreamProps);
	}
	XN_IS_STATUS_OK(nRetVal);

	// now add it to client data
	nRetVal = AddSessionModule(strName, strType);
	XN_IS_STATUS_OK(nRetVal);

	// create client stream data
	XnStreamData* pStreamData = NULL;
	nRetVal = m_pSensor->CreateStreamData(strType, &pStreamData);
	XN_IS_STATUS_OK(nRetVal);

	// and add it to set
	nRetVal = XnStreamDataSetAdd(m_pStreamDataSet, pStreamData);
	XN_IS_STATUS_OK(nRetVal);
	
	return (XN_STATUS_OK);
}
Example #2
0
XnStatus XnServerSession::HandleNewStream()
{
	XnStatus nRetVal = XN_STATUS_OK;

	// read it
	XN_PROPERTY_SET_CREATE_ON_STACK(props);

	XnChar strType[XN_DEVICE_MAX_STRING_LENGTH];
	XnChar strName[XN_DEVICE_MAX_STRING_LENGTH];
	nRetVal = m_privateIncomingPacker.ReadNewStream(strType, strName, &props);
	XN_IS_STATUS_OK(nRetVal);

	XnPropertySet* pInitialValues = &props;
	if (props.pData->begin() == props.pData->end())
	{
		pInitialValues = NULL;
	}

	XnStatus nActionResult = NewStreamImpl(strType, strName, pInitialValues);

	nRetVal = SendReply(XN_SENSOR_SERVER_MESSAGE_GENERAL_OP_RESPOND, nActionResult);
	XN_IS_STATUS_OK(nRetVal);

	return (XN_STATUS_OK);
}
Example #3
0
XnStatus XnServerSession::HandleNewStream()
{
	XnStatus nRetVal = XN_STATUS_OK;

	// read it
	XN_PROPERTY_SET_CREATE_ON_STACK(props);

	XnChar strType[XN_DEVICE_MAX_STRING_LENGTH];
	XnChar strName[XN_DEVICE_MAX_STRING_LENGTH];
	nRetVal = m_privateIncomingPacker.ReadNewStream(strType, strName, &props);
	XN_IS_STATUS_OK(nRetVal);

	XnPropertySet* pInitialValues = &props;
	if (props.pData->Begin() == props.pData->End())
	{
		pInitialValues = NULL;
	}

	XnStatus nActionResult = NewStreamImpl(strType, strName, pInitialValues);
	if (nActionResult != XN_STATUS_OK)
	{
		xnLogWarning(XN_MASK_SENSOR_SERVER, "Client %u failed to create stream of type '%s': %s", m_nID, strType, xnGetStatusString(nActionResult));
	}

	nRetVal = SendReply(XN_SENSOR_SERVER_MESSAGE_GENERAL_OP_RESPOND, nActionResult);
	XN_IS_STATUS_OK(nRetVal);

	return (XN_STATUS_OK);
}
XnStatus XnServerSensorInvoker::Init(const XnChar* strDevicePath, const XnChar* strGlobalConfigFile, XnUInt32 nAdditionalProps, XnProperty** aAdditionalProps)
{
	XnStatus nRetVal = XN_STATUS_OK;
	
	nRetVal = m_sensor.SetGlobalConfigFile(strGlobalConfigFile);
	XN_IS_STATUS_OK(nRetVal);

	nRetVal = xnOSCreateCriticalSection(&m_hSensorLock);
	XN_IS_STATUS_OK(nRetVal);

	XnDeviceConfig config;
	config.DeviceMode = XN_DEVICE_MODE_READ;
	config.cpConnectionString = strDevicePath;
	config.pInitialValues = NULL;
	config.SharingMode = XN_DEVICE_SHARED;

	nRetVal = m_sensor.Init(&config);
	XN_IS_STATUS_OK(nRetVal);

	nRetVal = m_sensor.DeviceModule()->AddProperties(aAdditionalProps, nAdditionalProps);
	XN_IS_STATUS_OK(nRetVal);

	XnProperty* aInvokerAdditionalProps[] = { &m_numberOfBuffers, &m_allowOtherUsers };
	nRetVal = m_sensor.DeviceModule()->AddProperties(aInvokerAdditionalProps, sizeof(aInvokerAdditionalProps) / sizeof(aInvokerAdditionalProps[0]));
	XN_IS_STATUS_OK(nRetVal);

	// configure from global file
	nRetVal = m_sensor.ConfigureModuleFromGlobalFile(XN_MODULE_NAME_DEVICE, XN_SENSOR_SERVER_CONFIG_FILE_SECTION);
	XN_IS_STATUS_OK(nRetVal);

	// register to events
	XnCallbackHandle hDummy = NULL;
	nRetVal = m_sensor.OnStreamCollectionChangedEvent().Register(StreamCollectionChangedCallback, this, hDummy);
	XN_IS_STATUS_OK(nRetVal);

	nRetVal = m_sensor.OnNewStreamDataEvent().Register(NewStreamDataCallback, this, hDummy);
	XN_IS_STATUS_OK(nRetVal);

	// register to all properties
	XN_PROPERTY_SET_CREATE_ON_STACK(props);
	nRetVal = m_sensor.DeviceModule()->GetAllProperties(&props);
	XN_IS_STATUS_OK(nRetVal);

	nRetVal = RegisterToProps(&props);
	XN_IS_STATUS_OK(nRetVal);

	nRetVal = xnOSCreateEvent(&m_hNewDataEvent, FALSE);
	XN_IS_STATUS_OK(nRetVal);

	// start reader thread
	nRetVal = xnOSCreateThread(ReaderThread, this, &m_hReaderThread);
	XN_IS_STATUS_OK(nRetVal);
	
	return (XN_STATUS_OK);
}
XnStatus XnSensorImageGenerator::SetPixelFormat(XnPixelFormat Format)
{
	if (GetPixelFormat() == Format)
	{
		return (XN_STATUS_OK);
	}

	XN_PROPERTY_SET_CREATE_ON_STACK(props);
	XnStatus nRetVal = XnPropertySetAddModule(&props, m_strModule);
	XN_IS_STATUS_OK(nRetVal);

	XnOutputFormats OutputFormat;
	XnUInt32* anAllowedInputFormats = NULL;
	XnUInt32 nAllowedInputFormats = 0;

	switch (Format)
	{
	case XN_PIXEL_FORMAT_RGB24:
		OutputFormat = XN_OUTPUT_FORMAT_RGB24;
		anAllowedInputFormats = g_anAllowedRGBFormats;
		nAllowedInputFormats = sizeof(g_anAllowedRGBFormats)/sizeof(XnUInt32);
		break;
	case XN_PIXEL_FORMAT_YUV422:
		OutputFormat = XN_OUTPUT_FORMAT_YUV422;
		anAllowedInputFormats = g_anAllowedYUVFormats;
		nAllowedInputFormats = sizeof(g_anAllowedYUVFormats)/sizeof(XnUInt32);
		break;
	case XN_PIXEL_FORMAT_GRAYSCALE_8_BIT:
		OutputFormat = XN_OUTPUT_FORMAT_GRAYSCALE8;
		anAllowedInputFormats = g_anAllowedGray8Formats;
		nAllowedInputFormats = sizeof(g_anAllowedGray8Formats)/sizeof(XnUInt32);
		break;
	case XN_PIXEL_FORMAT_MJPEG:
		OutputFormat = XN_OUTPUT_FORMAT_JPEG;
		anAllowedInputFormats = g_anAllowedJPEGFormats;
		nAllowedInputFormats = sizeof(g_anAllowedJPEGFormats)/sizeof(XnUInt32);
		break;
	default:
		return XN_STATUS_INVALID_OPERATION;
	}

	XnUInt32 nInputFormat = FindSupportedInputFormat(anAllowedInputFormats, nAllowedInputFormats);
	if (nInputFormat == INVALID_INPUT_FORMAT)
	{
		XN_LOG_WARNING_RETURN(XN_STATUS_DEVICE_BAD_PARAM, XN_MASK_DEVICE_SENSOR, "Cannot set pixel format to %s - no matching input format.", xnPixelFormatToString(Format));
	}

	XnPropertySetAddIntProperty(&props, m_strModule, XN_STREAM_PROPERTY_INPUT_FORMAT, (XnUInt64)nInputFormat);
	XnPropertySetAddIntProperty(&props, m_strModule, XN_STREAM_PROPERTY_OUTPUT_FORMAT, (XnUInt64)OutputFormat);

	return m_pSensor->BatchConfig(&props);
}
Example #6
0
XnStatus XnFileDevice::Rewind()
{
    XnStatus nRetVal = XN_STATUS_OK;

    // go back to start of stream
    nRetVal = m_pInputStream->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
    for (XnNodeInfoMap::Iterator it = m_nodeInfoMap.Begin(); it != m_nodeInfoMap.End(); ++it)
    {
        const XnChar* strName = it->Key();

        if (m_bNodeCollectionChanged)
        {
            // we need to destroy all streams, and recreate them later
            nRetVal = m_pNotifications->OnNodeRemoved(m_pNotificationsCookie, strName);
            XN_IS_STATUS_OK(nRetVal);
        }
        else
        {
            // just reset frame ID
            it->Value().nCurrFrameID = 0;
            // and mark not to recreate it
            nRetVal = m_ignoreNewNodes.Set(strName, it->Value());
            XN_IS_STATUS_OK(nRetVal);
        }
    }

    // if we need, recreate nodes
    if (m_bNodeCollectionChanged)
    {
        nRetVal = SetInitialState(&state);
        XN_IS_STATUS_OK(nRetVal);
    }

// 	ResetLastTimestampAndFrame();
// 	m_nReferenceTimestamp = 0;
// 	m_nReferenceTime = 0;

    m_bNodeCollectionChanged = FALSE;
    m_nCurrTimestamp = 0;

    return (XN_STATUS_OK);
}
Example #7
0
XnStatus XnFileDevice::SetInputStream(void *pStreamCookie, XnPlayerInputStreamInterface *pStream)
{
    XnStatus nRetVal = XN_STATUS_OK;

    XN_VALIDATE_NEW(m_pInputStream, XnInputStream, pStream, pStreamCookie);

    nRetVal = m_pInputStream->Init();
    if (nRetVal != XN_STATUS_OK)
    {
        XN_DELETE(m_pInputStream);
        m_pInputStream = NULL;
        return (nRetVal);
    }

    // read format version
    nRetVal = ReadFileVersion();
    XN_IS_STATUS_OK(nRetVal);

    m_pDataPacker = XN_NEW(XnDataPacker, m_pInputStream, XN_DEVICE_FILE_MAX_INTERNAL_BUFFER);
    if (m_pDataPacker == NULL)
    {
        XN_DELETE(m_pInputStream);
        return (XN_STATUS_ALLOC_FAILED);
    }

    nRetVal = m_pDataPacker->Init();
    if (nRetVal != XN_STATUS_OK)
    {
        XN_DELETE(m_pDataPacker);
        XN_DELETE(m_pInputStream);
        return (nRetVal);
    }

    // read initial state
    XN_PROPERTY_SET_CREATE_ON_STACK(props);
    nRetVal = ReadInitialState(&props);
    XN_IS_STATUS_OK(nRetVal);

    nRetVal = SetInitialState(&props);
    XN_IS_STATUS_OK(nRetVal);

    // now read till first data
    XnBool bWrap;
    nRetVal = ReadTillNextData(&bWrap);
    XN_IS_STATUS_OK(nRetVal);

    return (XN_STATUS_OK);
}
Example #8
0
XnStatus XnSensorImageGenerator::SetPixelFormat(XnPixelFormat Format)
{
	if (GetPixelFormat() == Format)
	{
		return (XN_STATUS_OK);
	}

	XnUInt64 nCurrentInputFormat;
	GetIntProperty(XN_STREAM_PROPERTY_INPUT_FORMAT, nCurrentInputFormat);

	XN_PROPERTY_SET_CREATE_ON_STACK(props);
	XnStatus nRetVal = XnPropertySetAddModule(&props, m_strModule);
	XN_IS_STATUS_OK(nRetVal);

	XnOutputFormats OutputFormat;

	switch (Format)
	{
	case XN_PIXEL_FORMAT_RGB24:
		OutputFormat = XN_OUTPUT_FORMAT_RGB24;
		break;
	case XN_PIXEL_FORMAT_YUV422:
		OutputFormat = XN_OUTPUT_FORMAT_YUV422;
		break;
	case XN_PIXEL_FORMAT_GRAYSCALE_8_BIT:
		OutputFormat = XN_OUTPUT_FORMAT_GRAYSCALE8;
		break;
	case XN_PIXEL_FORMAT_MJPEG:
		OutputFormat = XN_OUTPUT_FORMAT_JPEG;
		break;
	default:
		return XN_STATUS_INVALID_OPERATION;
	}

	if (nCurrentInputFormat != XN_IO_IMAGE_FORMAT_JPEG && OutputFormat == XN_OUTPUT_FORMAT_JPEG)
	{
		XnPropertySetAddIntProperty(&props, m_strModule, XN_STREAM_PROPERTY_INPUT_FORMAT, (XnUInt64)XN_IO_IMAGE_FORMAT_JPEG);
	}
	else if (nCurrentInputFormat == XN_IO_IMAGE_FORMAT_JPEG && OutputFormat != XN_OUTPUT_FORMAT_JPEG)
	{
		XnPropertySetAddIntProperty(&props, m_strModule, XN_STREAM_PROPERTY_INPUT_FORMAT, (XnUInt64)XN_IMAGE_STREAM_DEFAULT_INPUT_FORMAT);
	}

	XnPropertySetAddIntProperty(&props, m_strModule, XN_STREAM_PROPERTY_OUTPUT_FORMAT, (XnUInt64)OutputFormat);

	return m_pSensor->BatchConfig(&props);
}
Example #9
0
XnStatus XnServerSession::HandleBatchConfig()
{
	XnStatus nRetVal = XN_STATUS_OK;

	// read it
	XN_PROPERTY_SET_CREATE_ON_STACK(props);

	nRetVal = m_privateIncomingPacker.ReadPropertySet(&props);
	XN_IS_STATUS_OK(nRetVal);

	XnStatus nActionResult = BatchConfigImpl(&props);

	nRetVal = SendReply(XN_SENSOR_SERVER_MESSAGE_GENERAL_OP_RESPOND, nActionResult);
	XN_IS_STATUS_OK(nRetVal);

	return (XN_STATUS_OK);
}
XnStatus XnSensorAudioGenerator::SetWaveOutputMode(const XnWaveOutputMode& OutputMode)
{
	XnStatus nRetVal = XN_STATUS_OK;

	if (OutputMode.nBitsPerSample != 16)
	{
		return XN_STATUS_INVALID_OPERATION;
	}

	XN_PROPERTY_SET_CREATE_ON_STACK(props);
	XnPropertySetAddModule(&props, m_strModule);
	XnPropertySetAddIntProperty(&props, m_strModule, XN_STREAM_PROPERTY_SAMPLE_RATE, OutputMode.nSampleRate);
	XnPropertySetAddIntProperty(&props, m_strModule, XN_STREAM_PROPERTY_NUMBER_OF_CHANNELS, OutputMode.nChannels);

	nRetVal = m_pSensor->BatchConfig(&props);
	XN_IS_STATUS_OK(nRetVal);

	return (XN_STATUS_OK);
}
Example #11
0
XnStatus XnSensorClient::CreateStream(const XnChar* StreamType, const XnChar* StreamName /* = NULL */, const XnPropertySet* pInitialValues /* = NULL */)
{
	XnStatus nRetVal = XN_STATUS_OK;

	XN_PROPERTY_SET_CREATE_ON_STACK(props);
	if (pInitialValues == NULL)
	{
		pInitialValues = &props;
	}
	
	xnLogVerbose(XN_MASK_SENSOR_CLIENT, "Creating stream %s (of type %s)", StreamName, StreamType);

	nRetVal = m_pOutgoingPacker->WriteNewStream(StreamType, StreamName, pInitialValues);
	XN_IS_STATUS_OK(nRetVal);

	nRetVal = WaitForReply(XN_SENSOR_SERVER_MESSAGE_GENERAL_OP_RESPOND);
	XN_IS_STATUS_OK(nRetVal);

	return (XN_STATUS_OK);
}
Example #12
0
XnStatus XnServerSession::HandleBatchConfig()
{
	XnStatus nRetVal = XN_STATUS_OK;

	// read it
	XN_PROPERTY_SET_CREATE_ON_STACK(props);

	nRetVal = m_privateIncomingPacker.ReadPropertySet(&props);
	XN_IS_STATUS_OK(nRetVal);

	XnStatus nActionResult = BatchConfigImpl(&props);
	if (nActionResult != XN_STATUS_OK)
	{
		xnLogWarning(XN_MASK_SENSOR_SERVER, "Client %u failed to batch config: %s", m_nID, xnGetStatusString(nActionResult));
	}

	nRetVal = SendReply(XN_SENSOR_SERVER_MESSAGE_GENERAL_OP_RESPOND, nActionResult);
	XN_IS_STATUS_OK(nRetVal);

	return (XN_STATUS_OK);
}
Example #13
0
XnStatus XnServerSession::SendInitialState()
{
	XnStatus nRetVal = XN_STATUS_OK;

	XN_PROPERTY_SET_CREATE_ON_STACK(props);

	// get it
	nRetVal = m_pSensor->GetAllProperties(&props, TRUE);
	XN_IS_STATUS_OK(nRetVal);

	// and send it
	m_pLogger->DumpMessage("InitialState", 0, m_nID);

	{
		XnAutoCSLocker lock(m_hCommLock);
		nRetVal = m_privateOutgoingPacker.WritePropertySet(&props);
	}
	XN_IS_STATUS_OK(nRetVal);

	return (XN_STATUS_OK);
}
Example #14
0
XnStatus XnServerSession::BatchConfigImpl(const XnPropertySet* pProps)
{
	XnStatus nRetVal = XN_STATUS_OK;
	
	xnLogVerbose(XN_MASK_SENSOR_SERVER, "Client %u requested a batch config", m_nID);

	XN_PROPERTY_SET_CREATE_ON_STACK(serverProps);
	for (XnPropertySetData::Iterator it = pProps->pData->Begin(); it != pProps->pData->End(); ++it)
	{
		SessionStream* pStream = NULL;
		nRetVal = m_streamsHash.Get(it->Key(), pStream);
		XN_IS_STATUS_OK(nRetVal);

		nRetVal = XnPropertySetCloneModule(pProps, &serverProps, it->Key(), pStream->strStreamName);
		XN_IS_STATUS_OK(nRetVal);
	}

	nRetVal = m_pSensor->BatchConfig(&serverProps);
	XN_IS_STATUS_OK(nRetVal);
	
	return (XN_STATUS_OK);
}
XnStatus XnServerSensorInvoker::OnStreamAdded(const XnChar* StreamName)
{
	XnStatus nRetVal = XN_STATUS_OK;

	// get all props
	XN_PROPERTY_SET_CREATE_ON_STACK(props);
	nRetVal = m_sensor.GetAllProperties(&props, FALSE, StreamName);
	XN_IS_STATUS_OK(nRetVal);

	// register to all props
	nRetVal = RegisterToProps(&props);
	XN_IS_STATUS_OK(nRetVal);

	XnActualPropertiesHash* pStreamProps = props.pData->Begin()->Value();

	// create stream data
	SensorInvokerStream serverStream;
	xnOSMemSet(&serverStream, 0, sizeof(serverStream));
	strcpy(serverStream.strType, StreamName);

	XN_VALIDATE_NEW(serverStream.pNewDataEvent, NewStreamDataEvent);

	// check if this is a frame stream
	XnProperty* pIsFrameBased;
	nRetVal = pStreamProps->Get(XN_STREAM_PROPERTY_IS_FRAME_BASED, pIsFrameBased);
	if (nRetVal == XN_STATUS_OK)
	{
		XnActualIntProperty* pIntProp = (XnActualIntProperty*)pIsFrameBased;
		serverStream.bFrameStream = (pIntProp->GetValue() == TRUE);
	}

	if (serverStream.bFrameStream)
	{
		// create the "shared memory name" property
		XN_VALIDATE_NEW(serverStream.pSharedMemoryName, XnActualStringProperty, XN_STREAM_PROPERTY_SHARED_BUFFER_NAME);

		// and add it to the stream
		XnDeviceStream* pStream;
		nRetVal = m_sensor.GetStream(StreamName, &pStream);
		if (nRetVal != XN_STATUS_OK)
		{
			XN_DELETE(serverStream.pNewDataEvent);
			XN_DELETE(serverStream.pSharedMemoryName);
			return nRetVal;
		}

		nRetVal = pStream->AddProperty(serverStream.pSharedMemoryName);
		if (nRetVal != XN_STATUS_OK)
		{
			XN_DELETE(serverStream.pNewDataEvent);
			XN_DELETE(serverStream.pSharedMemoryName);
			return nRetVal;
		}

		// create a shared memory buffer pool for it
		nRetVal = SetStreamSharedMemory(&serverStream);
		if (nRetVal != XN_STATUS_OK)
		{
			XN_DELETE(serverStream.pNewDataEvent);
			XN_DELETE(serverStream.pSharedMemoryName);
			return nRetVal;
		}
	}

	// create a stream data object for the stream
	nRetVal = m_sensor.CreateStreamData(StreamName, &serverStream.pStreamData);
	if (nRetVal != XN_STATUS_OK)
	{
		XN_DELETE(serverStream.pNewDataEvent);
		XN_DELETE(serverStream.pSharedMemoryName);
		return (nRetVal);
	}

	// and add it to our list of streams
	nRetVal = m_streams.Set(StreamName, serverStream);
	if (nRetVal != XN_STATUS_OK)
	{
		XN_DELETE(serverStream.pNewDataEvent);
		XN_DELETE(serverStream.pSharedMemoryName);
		return (nRetVal);
	}

	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);
}
XnStatus XnDeviceFileReader::ReadInitialState(XnPropertySet *pSet)
{
	XnStatus nRetVal = XN_STATUS_OK;

	if (m_nFileVersion < 4)
	{
		if (m_pBCData == NULL)
		{
			nRetVal = BCInit();
			XN_IS_STATUS_OK(nRetVal);
		}

		return BCReadInitialState(pSet);
	}

	// first read first object - modules properties - using base
	nRetVal = XnStreamReaderDevice::ReadInitialState(pSet);
	XN_IS_STATUS_OK(nRetVal);

	// now continue reading until we get to first data
	XnPackedDataType nType;
	XnBool bStateEnd = FALSE;
	XnUInt64 nPositionBefore;

	while (!bStateEnd)
	{
		nRetVal = GetIOStream()->Tell(&nPositionBefore);
		XN_IS_STATUS_OK(nRetVal);

		nRetVal = GetDataPacker()->ReadNextObject(&nType);
		XN_IS_STATUS_OK(nRetVal);

		switch (nType)
		{
		case XN_PACKED_NEW_STREAM:
			{
				XnChar strType[XN_DEVICE_MAX_STRING_LENGTH];
				XnChar strName[XN_DEVICE_MAX_STRING_LENGTH];
				XN_PROPERTY_SET_CREATE_ON_STACK(props);
				nRetVal = GetDataPacker()->ReadNewStream(strType, strName, &props);
				XN_IS_STATUS_OK(nRetVal);

				XnActualPropertiesHash* pStreamProps;
				nRetVal = XnPropertySetDataDetachModule(props.pData, strName, &pStreamProps);
				XN_IS_STATUS_OK(nRetVal);

				nRetVal = XnPropertySetDataAttachModule(pSet->pData, strName, pStreamProps);
				XN_IS_STATUS_OK(nRetVal);
				break;
			}
		case XN_PACKED_INT_PROPERTY:
			{
				XnChar strModule[XN_DEVICE_MAX_STRING_LENGTH];
				XnChar strProp[XN_DEVICE_MAX_STRING_LENGTH];
				XnUInt64 nValue;
				nRetVal = GetDataPacker()->ReadProperty(strModule, strProp, &nValue);
				XN_IS_STATUS_OK(nRetVal);

				XnActualPropertiesHash* pModule = NULL;
				nRetVal = pSet->pData->Get(strModule, pModule);
				XN_IS_STATUS_OK(nRetVal);

				XnProperty* pProp = NULL;
				nRetVal = pModule->Get(strProp, pProp);
				XN_IS_STATUS_OK(nRetVal);

				XnActualIntProperty* pIntProp = (XnActualIntProperty*)pProp;
				nRetVal = pIntProp->UnsafeUpdateValue(nValue);
				XN_IS_STATUS_OK(nRetVal);
				break;
			}
		case XN_PACKED_REAL_PROPERTY:
			{
				XnChar strModule[XN_DEVICE_MAX_STRING_LENGTH];
				XnChar strProp[XN_DEVICE_MAX_STRING_LENGTH];
				XnDouble dValue;
				nRetVal = GetDataPacker()->ReadProperty(strModule, strProp, &dValue);
				XN_IS_STATUS_OK(nRetVal);

				XnActualPropertiesHash* pModule;
				nRetVal = pSet->pData->Get(strModule, pModule);
				XN_IS_STATUS_OK(nRetVal);

				XnProperty* pProp;
				nRetVal = pModule->Get(strProp, pProp);
				XN_IS_STATUS_OK(nRetVal);

				XnActualRealProperty* pRealProp = (XnActualRealProperty*)pProp;
				nRetVal = pRealProp->UnsafeUpdateValue(dValue);
				XN_IS_STATUS_OK(nRetVal);
				break;
			}
		case XN_PACKED_STRING_PROPERTY:
			{
				XnChar strModule[XN_DEVICE_MAX_STRING_LENGTH];
				XnChar strProp[XN_DEVICE_MAX_STRING_LENGTH];
				XnChar strValue[XN_DEVICE_MAX_STRING_LENGTH];
				nRetVal = GetDataPacker()->ReadProperty(strModule, strProp, strValue);
				XN_IS_STATUS_OK(nRetVal);

				XnActualPropertiesHash* pModule;
				nRetVal = pSet->pData->Get(strModule, pModule);
				XN_IS_STATUS_OK(nRetVal);

				XnProperty* pProp;
				nRetVal = pModule->Get(strProp, pProp);
				XN_IS_STATUS_OK(nRetVal);

				XnActualStringProperty* pStringProp = (XnActualStringProperty*)pProp;
				nRetVal = pStringProp->UnsafeUpdateValue(strValue);
				XN_IS_STATUS_OK(nRetVal);
				break;
			}
		case XN_PACKED_GENERAL_PROPERTY:
			{
				XnChar strModule[XN_DEVICE_MAX_STRING_LENGTH];
				XnChar strProp[XN_DEVICE_MAX_STRING_LENGTH];
				XnGeneralBuffer gbValue;
				nRetVal = GetDataPacker()->ReadProperty(strModule, strProp, &gbValue);
				XN_IS_STATUS_OK(nRetVal);

				XnActualPropertiesHash* pModule;
				nRetVal = pSet->pData->Get(strModule, pModule);
				XN_IS_STATUS_OK(nRetVal);

				XnProperty* pProp;
				nRetVal = pModule->Get(strProp, pProp);
				XN_IS_STATUS_OK(nRetVal);

				XnActualGeneralProperty* pIntProp = (XnActualGeneralProperty*)pProp;
				nRetVal = pIntProp->UnsafeUpdateValue(gbValue);
				XN_IS_STATUS_OK(nRetVal);
				break;
			}
		default:
			// reached end of initial state. go back to beginning of this object
			nRetVal = GetIOStream()->Seek(nPositionBefore);
			XN_IS_STATUS_OK(nRetVal);

			// stop reading
			bStateEnd = TRUE;
		}
	} // objects loop
	
	return (XN_STATUS_OK);
}
XnStatus XnSensorProductionNode::NotifyExState(XnNodeNotifications* pNotifications, void* pCookie)
{
	XnStatus nRetVal = XN_STATUS_OK;
	
	// get all properties
	XN_PROPERTY_SET_CREATE_ON_STACK(props);
	nRetVal = m_pSensor->GetAllProperties(&props, FALSE, GetModuleName());
	XN_IS_STATUS_OK(nRetVal);

	XnActualPropertiesHash* pPropsHash = props.pData->begin().Value();

	// filter properties (remove the ones already exposed as OpenNI interfaces)
	FilterProperties(pPropsHash);

	const XnChar* astrIntProps[200] = {0};
	const XnChar* astrRealProps[200] = {0};
	const XnChar* astrStringProps[200] = {0};
	const XnChar* astrGeneralProps[200] = {0};

	XnUInt32 nIntProps = 0;
	XnUInt32 nRealProps = 0;
	XnUInt32 nStringProps = 0;
	XnUInt32 nGeneralProps = 0;

	// enumerate over properties
	for (XnActualPropertiesHash::Iterator it = pPropsHash->begin(); it != pPropsHash->end(); ++it)
	{
		XnProperty* pProp = it.Value();

		switch (pProp->GetType())
		{
		case XN_PROPERTY_TYPE_INTEGER:
			{
				XnActualIntProperty* pIntProp = (XnActualIntProperty*)pProp;
				pNotifications->OnNodeIntPropChanged(pCookie, GetInstanceName(), pProp->GetName(), pIntProp->GetValue());
				astrIntProps[nIntProps++] = pProp->GetName();
			}
			break;
		case XN_PROPERTY_TYPE_REAL:
			{
				XnActualRealProperty* pRealProp = (XnActualRealProperty*)pProp;
				pNotifications->OnNodeRealPropChanged(pCookie, GetInstanceName(), pProp->GetName(), pRealProp->GetValue());
				astrRealProps[nRealProps++] = pProp->GetName();
			}
			break;
		case XN_PROPERTY_TYPE_STRING:
			{
				XnActualStringProperty* pStrProp = (XnActualStringProperty*)pProp;
				pNotifications->OnNodeStringPropChanged(pCookie, GetInstanceName(), pProp->GetName(), pStrProp->GetValue());
				astrStringProps[nStringProps++] = pProp->GetName();
			}
			break;
		case XN_PROPERTY_TYPE_GENERAL:
			{
				XnActualGeneralProperty* pGenProp = (XnActualGeneralProperty*)pProp;
				pNotifications->OnNodeGeneralPropChanged(pCookie, GetInstanceName(), pProp->GetName(), pGenProp->GetValue().nDataSize, pGenProp->GetValue().pData);
				astrGeneralProps[nGeneralProps++] = pProp->GetName();
			}
			break;
		default:
			XN_LOG_WARNING_RETURN(XN_STATUS_ERROR, XN_MASK_DEVICE_SENSOR, "Unknown property type: %d", pProp->GetType());
		}
	}

	// TODO: also register to these properties, and if changed, notify.

	// store notifications object
	m_pNotifications = pNotifications;
	m_pCookie = pCookie;

	return (XN_STATUS_OK);
}