コード例 #1
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);

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

	// 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);

	// raise event
	m_OnStreamsChangeEvent.Raise(GetDeviceHandle(), strStreamName, XN_DEVICE_STREAM_DELETED);

	xnLogVerbose(XN_MASK_DDK, "'%s' stream destroyed.", strStreamName);

	return XN_STATUS_OK;
}
コード例 #2
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;
}
コード例 #3
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);
}