示例#1
0
XnStatus XnDeviceBase::OpenAllStreams()
{
    XnStatus nRetVal = XN_STATUS_OK;

    xnLogVerbose(XN_MASK_DDK, "Opening all streams...");

    // go over modules list, and look for closed streams
    for (ModuleHoldersHash::Iterator it = m_Modules.Begin(); it != m_Modules.End(); ++it)
    {
        XnDeviceModuleHolder* pModuleHolder = it->Value();
        if (IsStream(pModuleHolder->GetModule()))
        {
            XnDeviceStream* pStream = (XnDeviceStream*)pModuleHolder->GetModule();
            if (!pStream->IsOpen())
            {
                nRetVal = pStream->Open();
                XN_IS_STATUS_OK(nRetVal);
            }
        }
    }

    xnLogInfo(XN_MASK_DDK, "All streams are open.");

    return XN_STATUS_OK;
}
示例#2
0
XnStatus XnDeviceBase::CloseAllStreams()
{
	XnStatus nRetVal = XN_STATUS_OK;

	xnLogVerbose(XN_MASK_DDK, "Closing all streams...");

	// go over modules list, and look for closed streams
	for (XnStringsHash::Iterator it = m_Modules.begin(); it != m_Modules.end(); ++it)
	{
		XnDeviceModuleHolder* pModuleHolder = (XnDeviceModuleHolder*)it.Value();
		if (IsStream(pModuleHolder->GetModule()))
		{
			XnDeviceStream* pStream = (XnDeviceStream*)pModuleHolder->GetModule();
			if (pStream->IsOpen())
			{
				nRetVal = pStream->Close();
				XN_IS_STATUS_OK(nRetVal);
			}
		}
	}

	xnLogInfo(XN_MASK_DDK, "All streams are closed.");

	return XN_STATUS_OK;
}
示例#3
0
XnStatus XnDeviceBase::FindStream(const XnChar* StreamName, XnDeviceStream** ppStream)
{
	// find the module
	XnDeviceModuleHolder* pStreamHolder = NULL;
	XnStatus nRetVal = FindStream(StreamName, &pStreamHolder);
	XN_IS_STATUS_OK(nRetVal);

	*ppStream = (XnDeviceStream*)pStreamHolder->GetModule();

	return XN_STATUS_OK;
}
示例#4
0
XnStatus XnDeviceBase::FindModule(const XnChar* ModuleName, XnDeviceModule** ppModule)
{
	XnStatus nRetVal = XN_STATUS_OK;
	
	XnDeviceModuleHolder* pHolder;
	nRetVal = FindModule(ModuleName, &pHolder);
	XN_IS_STATUS_OK(nRetVal);

	*ppModule = pHolder->GetModule();
	
	return (XN_STATUS_OK);
}
示例#5
0
XnStatus XnDeviceBase::GetStreamsList(XnDeviceModuleHolderList& list)
{
	list.Clear();

	for (XnStringsHash::Iterator it = m_Modules.begin(); it != m_Modules.end(); ++it)
	{
		XnDeviceModuleHolder* pModuleHolder = (XnDeviceModuleHolder*)it.Value();
		if (IsStream(pModuleHolder->GetModule()))
		{
			list.AddLast(pModuleHolder);
		}
	}

	return (XN_STATUS_OK);
}
示例#6
0
XnStatus XnDeviceBase::FindStream(const XnChar* StreamName, XnDeviceModuleHolder** ppStreamHolder)
{
	// find the module
	XnDeviceModuleHolder* pModuleHolder = NULL;
	XnStatus nRetVal = FindModule(StreamName, &pModuleHolder);
	XN_IS_STATUS_OK(nRetVal);

	// check if this is a stream
	if (!IsStream(pModuleHolder->GetModule()))
		return XN_STATUS_MODULE_IS_NOT_STREAM;

	*ppStreamHolder = pModuleHolder;

	return XN_STATUS_OK;
}
示例#7
0
XnStatus XnSensor::LoadConfigFromFile(const XnChar* csINIFilePath, const XnChar* csSectionName)
{
	XnStatus nRetVal = XN_STATUS_OK;

	XN_VALIDATE_INPUT_PTR(csINIFilePath);
	XN_VALIDATE_INPUT_PTR(csSectionName);

	// we first need to configure the USB interface (we want to do so BEFORE creating streams)
	nRetVal = m_Interface.ReadValueFromFile(csINIFilePath, XN_MODULE_NAME_DEVICE);
	XN_IS_STATUS_OK(nRetVal);

	nRetVal = m_NumberOfBuffers.ReadValueFromFile(csINIFilePath, XN_MODULE_NAME_DEVICE);
	XN_IS_STATUS_OK(nRetVal);

	nRetVal = m_ReadFromEP1.ReadValueFromFile(csINIFilePath, XN_MODULE_NAME_DEVICE);
	XN_IS_STATUS_OK(nRetVal);

	nRetVal = m_ReadFromEP2.ReadValueFromFile(csINIFilePath, XN_MODULE_NAME_DEVICE);
	XN_IS_STATUS_OK(nRetVal);

	nRetVal = m_ReadFromEP3.ReadValueFromFile(csINIFilePath, XN_MODULE_NAME_DEVICE);
	XN_IS_STATUS_OK(nRetVal);

	// now create all streams
	nRetVal = CreateStreamsFromFile(csINIFilePath, csSectionName);
	XN_IS_STATUS_OK(nRetVal);

	// now configure DEVICE module (primary stream, global mirror, etc.)
	nRetVal = DeviceModule()->LoadConfigFromFile(csINIFilePath, XN_MODULE_NAME_DEVICE);
	XN_IS_STATUS_OK(nRetVal);

	// and now configure the streams
	XnDeviceModuleHolderList streams;
	nRetVal = GetStreamsList(streams);
	XN_IS_STATUS_OK(nRetVal);

	for (XnDeviceModuleHolderList::Iterator it = streams.begin(); it != streams.end(); ++it)
	{
		XnDeviceModuleHolder* pHolder = *it;
		nRetVal = pHolder->GetModule()->LoadConfigFromFile(csINIFilePath);
		XN_IS_STATUS_OK(nRetVal);
	}

	return (XN_STATUS_OK);
}
示例#8
0
XnStatus XnDeviceBase::Destroy()
{
    XnStatus nRetVal = XN_STATUS_OK;

    // free all modules
    while (m_Modules.Size() != 0)
    {
        XnDeviceModuleHolder* pModuleHolder = m_Modules.Begin()->Value();
        if (IsStream(pModuleHolder->GetModule()))
        {
            XnChar strName[XN_DEVICE_MAX_STRING_LENGTH];
            strcpy(strName, pModuleHolder->GetModule()->GetName());
            nRetVal = DestroyStream(strName);
            XN_IS_STATUS_OK(nRetVal);
        }
        else
        {
            // free memory of registered properties to this module
            FreeModuleRegisteredProperties(m_Modules.Begin()->Key());

            pModuleHolder->GetModule()->Free();
            DestroyModule(pModuleHolder);
            m_Modules.Remove(m_Modules.Begin());
        }
    }

    m_pDevicePropertiesHolder = NULL;

    m_Modules.Clear();

    // close dump
    xnDumpFileClose(m_StreamsDataDump);

    if (m_hLock != NULL)
    {
        xnOSCloseCriticalSection(&m_hLock);
        m_hLock = NULL;
    }

    return XN_STATUS_OK;
}
示例#9
0
XnStatus XnDeviceBase::DestroyStream(const XnChar* StreamName)
{
    XnStatus nRetVal = XN_STATUS_OK;

    xnLogInfo(XN_MASK_DDK, "Destroying stream '%s'...", StreamName);

    // keep the stream name (we now delete the module, so the name will be lost)
    XnChar strStreamName[XN_DEVICE_MAX_STRING_LENGTH];
    strncpy(strStreamName, StreamName, XN_DEVICE_MAX_STRING_LENGTH);

    xnl::AutoCSLocker lock(m_hLock);

    // Find the stream
    XnDeviceModuleHolder* pStreamHolder;
    nRetVal = FindStream(strStreamName, &pStreamHolder);
    XN_IS_STATUS_OK(nRetVal);

    XnDeviceStream* pStream = (XnDeviceStream*)pStreamHolder->GetModule();
    XnUInt32 nRefCount = pStream->DecRef();
    if (0 == nRefCount)
    {
        // remove it from map
        nRetVal = RemoveModule(strStreamName);
        XN_IS_STATUS_OK(nRetVal);

        // and free it's memory
        DestroyStreamModule(pStreamHolder);

        // free memory of registered properties to this stream
        FreeModuleRegisteredProperties(StreamName);

        xnLogVerbose(XN_MASK_DDK, "'%s' stream destroyed.", strStreamName);
    }
    else
    {
        xnLogVerbose(XN_MASK_DDK, "'%s' stream now has %d references.", strStreamName, nRefCount);
    }

    return XN_STATUS_OK;
}
示例#10
0
XnStatus XnDeviceBase::SetMirror(XnBool bMirror)
{
	XnStatus nRetVal = XN_STATUS_OK;
	
	// change all streams
	for (XnStringsHash::Iterator it = m_Modules.begin(); it != m_Modules.end(); ++it)
	{
		XnDeviceModuleHolder* pModuleHolder = (XnDeviceModuleHolder*)it.Value();
		if (IsStream(pModuleHolder->GetModule()))
		{
			XnDeviceStream* pStream = (XnDeviceStream*)pModuleHolder->GetModule();
			nRetVal = pStream->SetMirror(bMirror);
			XN_IS_STATUS_OK(nRetVal);
		}
	}

	// and set property
	nRetVal = m_DeviceMirror.UnsafeUpdateValue(bMirror);
	XN_IS_STATUS_OK(nRetVal);
	
	return (XN_STATUS_OK);
}
示例#11
0
XnStatus XnDeviceBase::GetStreamNames(const XnChar** pstrNames, XnUInt32* pnNamesCount)
{
	// first we need to count them
	XnUInt32 nCount = 0;

	for (XnStringsHash::Iterator it = m_Modules.begin(); it != m_Modules.end(); ++it)
	{
		XnDeviceModuleHolder* pModuleHolder = (XnDeviceModuleHolder*)it.Value();
		if (IsStream(pModuleHolder->GetModule()))
		{
			nCount++;
		}
	}

	if (nCount > *pnNamesCount)
	{
		*pnNamesCount = nCount;
		return XN_STATUS_OUTPUT_BUFFER_OVERFLOW;
	}

	// OK. we have enough space. Copy into it
	nCount = 0;
	for (XnStringsHash::Iterator it = m_Modules.begin(); it != m_Modules.end(); ++it)
	{
		XnDeviceModuleHolder* pModuleHolder = (XnDeviceModuleHolder*)it.Value();
		if (IsStream(pModuleHolder->GetModule()))
		{
			pstrNames[nCount] = it.Key();
			nCount++;
		}
	}

	*pnNamesCount = nCount;

	return XN_STATUS_OK;
}
示例#12
0
XnStatus XnDeviceBase::GetAllProperties(XnPropertySet* pSet, XnBool bNoStreams /* = FALSE */, const XnChar* strModule /* = NULL */)
{
	XnStatus nRetVal = XN_STATUS_OK;

	XN_VALIDATE_INPUT_PTR(pSet);

	// clear the set
	nRetVal = XnPropertySetClear(pSet);
	XN_IS_STATUS_OK(nRetVal);

	if (strModule != NULL)
	{
		XnDeviceModule* pModule;
		nRetVal = FindModule(strModule, &pModule);
		XN_IS_STATUS_OK(nRetVal);

		nRetVal = pModule->GetAllProperties(pSet);
		XN_IS_STATUS_OK(nRetVal);
	}
	else
	{
		// enumerate over modules
		for (XnStringsHash::Iterator it = m_Modules.begin(); it != m_Modules.end(); ++it)
		{
			XnDeviceModuleHolder* pModuleHolder = (XnDeviceModuleHolder*)it.Value();

			if (bNoStreams && IsStream(pModuleHolder->GetModule()))
				continue;

			nRetVal = pModuleHolder->GetModule()->GetAllProperties(pSet);
			XN_IS_STATUS_OK(nRetVal);
		}
	}

	return XN_STATUS_OK;
}
示例#13
0
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 XnStreamReaderDevice::SetInitialState(const XnDeviceConfig* pDeviceConfig, XnPropertySet* pSet)
{
	XnStatus nRetVal = XN_STATUS_OK;
	
	// Fix state (remove some properties that we don't wish to reflect in reader device)
	XnActualPropertiesHash* pDeviceModule = NULL;
	if (XN_STATUS_OK == pSet->pData->Get(XN_MODULE_NAME_DEVICE, pDeviceModule))
	{
		pDeviceModule->Remove(XN_MODULE_PROPERTY_READ_WRITE_MODE);
		pDeviceModule->Remove(XN_MODULE_PROPERTY_PRIMARY_STREAM);
	}

	// now init base using this state (this will also create module DEVICE)
	XnDeviceConfig initConfig;
	initConfig.cpConnectionString = pDeviceConfig->cpConnectionString;
	initConfig.DeviceMode = pDeviceConfig->DeviceMode;
	initConfig.pInitialValues = pSet;
	initConfig.SharingMode = pDeviceConfig->SharingMode;

	nRetVal = XnStreamDevice::InitImpl(&initConfig);
	XN_IS_STATUS_OK(nRetVal);

	// now create the rest of the modules and streams (DEVICE was already created)
	XnPropertySetData* pPropSetData = pSet->pData;
	for (XnPropertySetData::ConstIterator it = pPropSetData->begin(); it != pPropSetData->end(); ++it)
	{
		// ignore module DEVICE
		if (strcmp(XN_MODULE_NAME_DEVICE, it.Key()) == 0)
		{
			continue;
		}

		// check if this is a stream
		XnActualPropertiesHash::ConstIterator itProp = it.Value()->end();
		if (XN_STATUS_OK == it.Value()->Find(XN_STREAM_PROPERTY_TYPE, itProp))
		{
			XnActualStringProperty* pTypeProp = (XnActualStringProperty*)itProp.Value();
			nRetVal = HandleNewStream(pTypeProp->GetValue(), it.Key(), it.Value());
			XN_IS_STATUS_OK(nRetVal);
		}
		else
		{
			// this is module. create it
			XnDeviceModuleHolder* pHolder = NULL;
			nRetVal = CreateModule(it.Key(), &pHolder);
			XN_IS_STATUS_OK(nRetVal);

			// set its props
			nRetVal = pHolder->Init(it.Value());
			if (nRetVal != XN_STATUS_OK)
			{
				DestroyModule(pHolder);
				return (nRetVal);
			}

			// and add it
			nRetVal = AddModule(pHolder);
			if (nRetVal != XN_STATUS_OK)
			{
				DestroyModule(pHolder);
				return (nRetVal);
			}
		}
	} // modules loop
	
	return (XN_STATUS_OK);
}
示例#15
0
XnStatus XnDeviceBase::CreateStreamImpl(const XnChar* strType, const XnChar* strName, const XnActualPropertiesHash* pInitialSet)
{
	XnStatus nRetVal = XN_STATUS_OK;

	xnLogInfo(XN_MASK_DDK, "Creating stream '%s' of type '%s'...", strName, strType);

	XnDeviceModule* pModule;
	if (FindModule(strName, &pModule) == XN_STATUS_OK)
	{
		// already exists. check sharing mode (when shared, we allow "creating" the same stream)
		if (GetSharingMode() != XN_DEVICE_SHARED ||
			!IsStream(pModule) ||
			strcmp(strType, ((XnDeviceStream*)pModule)->GetType()) != 0)
		{
			XN_LOG_WARNING_RETURN(XN_STATUS_STREAM_ALREADY_EXISTS, XN_MASK_DDK, "A stream with this name already exists!");
		}

		// OK, we'll allow this. Just set new configuration
		if (pInitialSet != NULL)
		{
			nRetVal = pModule->BatchConfig(*pInitialSet);
			XN_IS_STATUS_OK(nRetVal);
		}
	}
	else
	{
		// create stream
		XnDeviceModuleHolder* pNewStreamHolder = NULL;

		nRetVal = CreateStreamModule(strType, strName, &pNewStreamHolder);
		XN_IS_STATUS_OK(nRetVal);

		XnDeviceStream* pNewStream = (XnDeviceStream*)(pNewStreamHolder->GetModule());
		if (pNewStream == NULL)
		{
			DestroyStreamModule(pNewStreamHolder);
			XN_LOG_ERROR_RETURN(XN_STATUS_ERROR, XN_MASK_DDK, "Internal Error: Invalid new stream!");
		}

		// initialize the stream
		xnLogVerbose(XN_MASK_DDK, "Initializing stream '%s'...", strName);

		nRetVal = pNewStreamHolder->Init(pInitialSet);
		if (nRetVal != XN_STATUS_OK)
		{
			DestroyStreamModule(pNewStreamHolder);
			return (nRetVal);
		}

		// set it's mirror value (if not requested otherwise)
		XnBool bSetMirror = TRUE;

		if (pInitialSet != NULL)
		{
			XnActualPropertiesHash::ConstIterator it = pInitialSet->end();
			if (XN_STATUS_OK == pInitialSet->Find(XN_MODULE_PROPERTY_MIRROR, it))
			{
				bSetMirror = FALSE;
			}
		}

		if (bSetMirror)
		{
			nRetVal = pNewStream->SetMirror((XnBool)m_DeviceMirror.GetValue());
			if (nRetVal != XN_STATUS_OK)
			{
				DestroyStreamModule(pNewStreamHolder);
				return (nRetVal);
			}
		}

		// add it to the list of existing modules
		nRetVal = AddModule(pNewStreamHolder);
		if (nRetVal != XN_STATUS_OK)
		{
			DestroyStreamModule(pNewStreamHolder);
			return (nRetVal);
		}

		xnLogInfo(XN_MASK_DDK, "Stream '%s' was initialized.", strName);

		nRetVal = StreamAdded(pNewStream);
		XN_IS_STATUS_OK(nRetVal);

		xnLogInfo(XN_MASK_DDK, "'%s' stream was created.", strName);
	}

	return (XN_STATUS_OK);
}