XnStatus XnDeviceFile::Init(const XnDeviceConfig* pDeviceConfig) { XnStatus nRetVal = XN_STATUS_OK; XN_VALIDATE_INPUT_PTR(pDeviceConfig); XnDeviceBase* pActualDeviceFile = NULL; switch (pDeviceConfig->DeviceMode) { case XN_DEVICE_MODE_READ: XN_VALIDATE_NEW(pActualDeviceFile, XnDeviceFileReader); break; case XN_DEVICE_MODE_WRITE: XN_VALIDATE_NEW(pActualDeviceFile, XnDeviceFileWriter); break; default: return XN_STATUS_IO_DEVICE_INVALID_MODE; } // init actual device nRetVal = pActualDeviceFile->Init(pDeviceConfig); XN_IS_STATUS_OK(nRetVal); ReplaceActualDevice(pActualDeviceFile); return (XN_STATUS_OK); }
XnStatus CreateNamedEventObject(XN_EVENT_HANDLE* pEventHandle, const XnChar* cpEventName, XnBool bCreate, XnBool bManualReset) { XnStatus nRetVal = XN_STATUS_OK; // Validate the input/output pointers (to make sure none of them is NULL) XN_VALIDATE_INPUT_PTR(cpEventName); XN_VALIDATE_OUTPUT_PTR(pEventHandle); *pEventHandle = NULL; XnLinuxNamedEvent* pEvent = NULL; #ifdef XN_PLATFORM_LINUX_NO_SYSV XN_VALIDATE_NEW(pEvent, XnLinuxPosixNamedEvent, bManualReset, cpEventName, bCreate); #else XN_VALIDATE_NEW(pEvent, XnLinuxSysVNamedEvent, bManualReset, cpEventName, bCreate); #endif nRetVal = pEvent->Init(); if (nRetVal != XN_STATUS_OK) { XN_DELETE(pEvent); return (nRetVal); } *pEventHandle = pEvent; return XN_STATUS_OK; }
//--------------------------------------------------------------------------- // Code //--------------------------------------------------------------------------- XnStatus XnActualPropertyFactory::CreateProperty(XnPropertyType nType, const XnChar* strName, XnProperty** ppProperty, XnUInt32 nSize /* = 0 */) { switch (nType) { case XN_PROPERTY_TYPE_INTEGER: XN_VALIDATE_NEW(*ppProperty, XnActualIntProperty, strName); break; case XN_PROPERTY_TYPE_REAL: XN_VALIDATE_NEW(*ppProperty, XnActualRealProperty, strName); break; case XN_PROPERTY_TYPE_STRING: XN_VALIDATE_NEW(*ppProperty, XnActualStringProperty, strName); break; case XN_PROPERTY_TYPE_GENERAL: XnGeneralBuffer gbValue; gbValue.pData = xnOSMalloc(nSize); XN_VALIDATE_ALLOC_PTR(gbValue.pData); gbValue.nDataSize = nSize; XN_VALIDATE_NEW(*ppProperty, XnActualGeneralProperty, strName, gbValue); break; } return (XN_STATUS_OK); }
XnStatus XnDeviceSensor::Init(const XnDeviceConfig* pDeviceConfig) { XnStatus nRetVal = XN_STATUS_OK; XN_VALIDATE_INPUT_PTR(pDeviceConfig); XnDeviceBase* pActualDevice = NULL; switch (pDeviceConfig->SharingMode) { case XN_DEVICE_EXCLUSIVE: XN_VALIDATE_NEW(pActualDevice, XnSensor); break; case XN_DEVICE_SHARED: #if (XN_PLATFORM != XN_PLATFORM_WIN32) XN_LOG_WARNING_RETURN(XN_STATUS_IO_DEVICE_INVALID_SHARING, XN_MASK_DEVICE_SENSOR, "Sensor sharing is only supported under win32!"); #endif XN_VALIDATE_NEW(pActualDevice, XnSensorClient); break; default: return XN_STATUS_IO_DEVICE_INVALID_SHARING; } // init actual device nRetVal = pActualDevice->Init(pDeviceConfig); XN_IS_STATUS_OK(nRetVal); ReplaceActualDevice(pActualDevice); return (XN_STATUS_OK); }
XnStatus XnFrameStream::Init() { XnStatus nRetVal = XN_STATUS_OK; // init base nRetVal = XnDeviceStream::Init(); XN_IS_STATUS_OK(nRetVal); XN_VALIDATE_ADD_PROPERTIES(this, &m_IsFrameStream, &m_FPS, &m_LastRawFrame); XnCallbackHandle hDummy; // be notified when required size changes nRetVal = RequiredSizeProperty().OnChangeEvent().Register(RequiredSizeChangedCallback, this, &hDummy); XN_IS_STATUS_OK(nRetVal); if (m_pBufferPool == NULL) { XN_VALIDATE_NEW(m_pBufferPool, XnSimpleBufferPool, 3); m_bPoolAllocated = TRUE; } // allocate buffer manager XN_VALIDATE_NEW(m_pBufferManager, XnFrameBufferManager, m_pBufferPool); nRetVal = m_pBufferManager->Init(GetRequiredDataSize()); XN_IS_STATUS_OK(nRetVal); // register for new data events nRetVal = m_pBufferManager->OnNewFrameEvent().Register(OnTripleBufferNewData, this, &hDummy); XN_IS_STATUS_OK(nRetVal); return (XN_STATUS_OK); }
XnStatus XnFrameStream::GetTripleBuffer(XnFrameBufferManager** pBufferManager) { XnStatus nRetVal = XN_STATUS_OK; // lazy initialization (this allows us to set buffer pool after initialization of the stream // and before data actually arrives (or stream data is allocated) if (m_pBufferManager == NULL) { if (m_pBufferPool == NULL) { XN_VALIDATE_NEW(m_pBufferPool, XnSimpleBufferPool, 3); m_bPoolAllocated = TRUE; nRetVal = m_pBufferPool->Init(GetRequiredDataSize()); XN_IS_STATUS_OK(nRetVal); } // allocate buffer manager XN_VALIDATE_NEW(m_pBufferManager, XnFrameBufferManager, m_pBufferPool); nRetVal = m_pBufferManager->Init(GetRequiredDataSize()); XN_IS_STATUS_OK(nRetVal); // register for new data events XnCallbackHandle hDummy; nRetVal = m_pBufferManager->OnNewFrameEvent().Register(OnTripleBufferNewData, this, hDummy); XN_IS_STATUS_OK(nRetVal); } *pBufferManager = m_pBufferManager; return (XN_STATUS_OK); }
XnStatus XnSensorClient::CreateStreamModule(const XnChar* StreamType, const XnChar* StreamName, XnDeviceModuleHolder** ppStreamHolder) { XnStatus nRetVal = XN_STATUS_OK; XnSensorClientStream* pStream; if (strcmp(StreamType, XN_STREAM_TYPE_AUDIO) == 0) { XN_VALIDATE_NEW(pStream, XnSensorClientAudioStream, this, StreamType, StreamName); } else { XN_VALIDATE_NEW(pStream, XnSensorClientFrameStream, this, StreamType, StreamName); } XnStreamReaderStreamHolder* pHolder = XN_NEW(XnStreamReaderStreamHolder, pStream); if (pHolder == NULL) { XN_DELETE(pStream); return XN_STATUS_ALLOC_FAILED; } *ppStreamHolder = pHolder; return (XN_STATUS_OK); }
XnStatus XnSensor::CreateStreamModule(const XnChar* StreamType, const XnChar* StreamName, XnDeviceModuleHolder** ppStreamHolder) { XnStatus nRetVal = XN_STATUS_OK; // make sure reading from streams is turned on if (!m_ReadData.GetValue()) { nRetVal = m_ReadData.SetValue(TRUE); XN_IS_STATUS_OK(nRetVal); } XnDeviceStream* pStream; XnSensorStreamHelper* pHelper; // create stream if (strcmp(StreamType, XN_STREAM_TYPE_DEPTH) == 0) { XnSensorDepthStream* pDepthStream; XN_VALIDATE_NEW(pDepthStream, XnSensorDepthStream, StreamName, &m_Objects); pStream = pDepthStream; pHelper = pDepthStream->GetHelper(); } else if (strcmp(StreamType, XN_STREAM_TYPE_IMAGE) == 0) { XnSensorImageStream* pImageStream; XN_VALIDATE_NEW(pImageStream, XnSensorImageStream, StreamName, &m_Objects); pStream = pImageStream; pHelper = pImageStream->GetHelper(); } else if (strcmp(StreamType, XN_STREAM_TYPE_IR) == 0) { XnSensorIRStream* pIRStream; XN_VALIDATE_NEW(pIRStream, XnSensorIRStream, StreamName, &m_Objects); pStream = pIRStream; pHelper = pIRStream->GetHelper(); } else if (strcmp(StreamType, XN_STREAM_TYPE_AUDIO) == 0) { if (!m_Firmware.GetInfo()->bAudioSupported) { XN_LOG_WARNING_RETURN(XN_STATUS_UNSUPPORTED_STREAM, XN_MASK_DEVICE_SENSOR, "Audio is not supported by this FW!"); } // TODO: use the allow other users property when constructing the audio stream XnSensorAudioStream* pAudioStream; XN_VALIDATE_NEW(pAudioStream, XnSensorAudioStream, GetUSBPath(), StreamName, &m_Objects, FALSE); pStream = pAudioStream; pHelper = pAudioStream->GetHelper(); } else { XN_LOG_WARNING_RETURN(XN_STATUS_UNSUPPORTED_STREAM, XN_MASK_DEVICE_SENSOR, "Unsupported stream type: %s", StreamType); } *ppStreamHolder = XN_NEW(XnSensorStreamHolder, pStream, pHelper); return (XN_STATUS_OK); }
XnStatus XnSensor::CreateStreamModule(const XnChar* StreamType, const XnChar* StreamName, XnDeviceModuleHolder** ppStreamHolder) { XnStatus nRetVal = XN_STATUS_OK; // make sure reading from streams is turned on if (!m_ReadData.GetValue()) { nRetVal = m_ReadData.SetValue(TRUE); XN_IS_STATUS_OK(nRetVal); } XnDeviceStream* pStream; XnSensorStreamHelper* pHelper; // create stream if (strcmp(StreamType, XN_STREAM_TYPE_DEPTH) == 0) { XnSensorDepthStream* pDepthStream; XN_VALIDATE_NEW(pDepthStream, XnSensorDepthStream, GetUSBPath(), StreamName, &m_Objects, m_NumberOfBuffers.GetValue()); pStream = pDepthStream; pHelper = pDepthStream->GetHelper(); } else if (strcmp(StreamType, XN_STREAM_TYPE_IMAGE) == 0) { XnSensorImageStream* pImageStream; XN_VALIDATE_NEW(pImageStream, XnSensorImageStream, GetUSBPath(), StreamName, &m_Objects, m_NumberOfBuffers.GetValue()); pStream = pImageStream; pHelper = pImageStream->GetHelper(); } else if (strcmp(StreamType, XN_STREAM_TYPE_IR) == 0) { XnSensorIRStream* pIRStream; XN_VALIDATE_NEW(pIRStream, XnSensorIRStream, GetUSBPath(), StreamName, &m_Objects, m_NumberOfBuffers.GetValue()); pStream = pIRStream; pHelper = pIRStream->GetHelper(); } else if (strcmp(StreamType, XN_STREAM_TYPE_AUDIO) == 0) { XnSensorAudioStream* pAudioStream; XN_VALIDATE_NEW(pAudioStream, XnSensorAudioStream, GetUSBPath(), StreamName, &m_Objects); pStream = pAudioStream; pHelper = pAudioStream->GetHelper(); } else { XN_LOG_WARNING_RETURN(XN_STATUS_UNSUPPORTED_STREAM, XN_MASK_DEVICE_SENSOR, "Unsupported stream type: %s", StreamType); } *ppStreamHolder = XN_NEW(XnSensorStreamHolder, pStream, pHelper); return (XN_STATUS_OK); }
XN_DDK_API XnStatus XnPropertySetGetEnumerator(const XnPropertySet* pSet, XnPropertySetEnumerator** ppEnumerator, const XnChar* strModule /* = NULL */) { XnStatus nRetVal = XN_STATUS_OK; XN_VALIDATE_INPUT_PTR(pSet); XN_VALIDATE_OUTPUT_PTR(ppEnumerator); if (strModule != NULL) { // make sure module exists XnPropertySetData::ConstIterator it = pSet->pData->End(); nRetVal = pSet->pData->Find(strModule, it); XN_IS_STATUS_OK(nRetVal); } XnPropertySetEnumerator* pEnumer; XN_VALIDATE_NEW(pEnumer, XnPropertySetEnumerator) pEnumer->bFirst = TRUE; pEnumer->pModules = pSet->pData; if (strModule != NULL) { strncpy(pEnumer->strModule, strModule, XN_DEVICE_MAX_STRING_LENGTH); } else { pEnumer->strModule[0] = '\0'; } *ppEnumerator = pEnumer; return (XN_STATUS_OK); }
XN_DDK_API XnStatus XnPropertySetAddModule(XnPropertySet* pSet, const XnChar* strModuleName) { XnStatus nRetVal = XN_STATUS_OK; XN_VALIDATE_INPUT_PTR(pSet); XN_VALIDATE_INPUT_PTR(strModuleName); XnActualPropertiesHash* pModule = NULL; // make sure this module doesn't already exists nRetVal = pSet->pData->Get(strModuleName, pModule); if (XN_STATUS_OK == nRetVal) { return XN_STATUS_DEVICE_MODULE_ALREADY_EXISTS; } // doesn't exist. create a new one XN_VALIDATE_NEW(pModule, XnActualPropertiesHash, strModuleName); nRetVal = XnPropertySetDataAttachModule(pSet->pData, strModuleName, pModule); if (nRetVal != XN_STATUS_OK) { XN_DELETE(pModule); return (nRetVal); } return (XN_STATUS_OK); }
XnStatus XnDeviceBase::RegisterToPropertyChange(const XnChar* Module, const XnChar* PropertyName, XnDeviceOnPropertyChangedEventHandler Handler, void* pCookie, XnCallbackHandle* phCallback) { XnStatus nRetVal = XN_STATUS_OK; XnDeviceModule* pModule; nRetVal = FindModule(Module, &pModule); XN_IS_STATUS_OK(nRetVal); XnPropertyCallback* pRealCookie; XN_VALIDATE_NEW(pRealCookie, XnPropertyCallback, GetDeviceHandle(), Module, PropertyName, Handler, pCookie); // register nRetVal = pModule->RegisterForOnPropertyValueChanged(PropertyName, PropertyValueChangedCallback, pRealCookie, &pRealCookie->hCallback); if (nRetVal != XN_STATUS_OK) { XN_DELETE(pRealCookie); return (nRetVal); } m_PropertyCallbacks.AddLast(pRealCookie); *phCallback = pRealCookie; return (XN_STATUS_OK); }
XnStatus XnFrameStream::SetExternalBufferPool(XnUInt32 nCount, XnGeneralBuffer* aBuffers) { XnStatus nRetVal = XN_STATUS_OK; if (m_pBufferPool != NULL) { xnLogError(XN_MASK_DDK, "Cannot change buffer pool."); return XN_STATUS_DEVICE_PROPERTY_READ_ONLY; } XnExternalBufferPool* pExternalBufferPool; XN_VALIDATE_NEW(pExternalBufferPool, XnExternalBufferPool); nRetVal = pExternalBufferPool->SetBuffers(nCount, aBuffers); if (nRetVal != XN_STATUS_OK) { XN_DELETE(pExternalBufferPool); return (nRetVal); } nRetVal = pExternalBufferPool->Init(GetRequiredDataSize()); if (nRetVal != XN_STATUS_OK) { XN_DELETE(pExternalBufferPool); return (nRetVal); } m_pBufferPool = pExternalBufferPool; return (XN_STATUS_OK); }
XN_DDK_API XnStatus XnPropertySetFindProperty(const XnPropertySet* pSet, const XnChar* strModule, const XnChar* strProp, XnPropertySetEnumerator** ppEnumerator) { XnStatus nRetVal = XN_STATUS_OK; XN_VALIDATE_INPUT_PTR(pSet); XN_VALIDATE_INPUT_PTR(strModule); XN_VALIDATE_INPUT_PTR(strProp); XN_VALIDATE_OUTPUT_PTR(ppEnumerator); // find module XnPropertySetData::Iterator itModule = pSet->pData->End(); nRetVal = pSet->pData->Find(strModule, itModule); XN_IS_STATUS_OK(nRetVal); XnActualPropertiesHash* pModule = itModule->Value(); // find property XnActualPropertiesHash::Iterator itProp = pModule->End(); nRetVal = pModule->Find(strProp, itProp); XN_IS_STATUS_OK(nRetVal); // create enumerator XnPropertySetEnumerator* pEnumer; XN_VALIDATE_NEW(pEnumer, XnPropertySetEnumerator); pEnumer->itModule = itModule; pEnumer->itProp = itProp; pEnumer->pModules = pSet->pData; pEnumer->strModule[0] = '\0'; pEnumer->bFirst = FALSE; *ppEnumerator = pEnumer; return XN_STATUS_OK; }
//--------------------------------------------------------------------------- // Code //--------------------------------------------------------------------------- XN_C_API XnStatus xnOSCreateEvent(XN_EVENT_HANDLE* pEventHandle, XnBool bManualReset) { // Local function variables XnStatus nRetVal = XN_STATUS_OK; // Validate the input/output pointers (to make sure none of them is NULL) XN_VALIDATE_INPUT_PTR(pEventHandle); *pEventHandle = NULL; XnLinuxEvent* pEvent = NULL; XN_VALIDATE_NEW(pEvent, XnLinuxPosixEvent, bManualReset); nRetVal = pEvent->Init(); if (nRetVal != XN_STATUS_OK) { XN_DELETE(pEvent); return (nRetVal); } *pEventHandle = pEvent; // All is good... return (XN_STATUS_OK); }
XnStatus XnActualPropertiesHash::Add(XnUInt32 propertyId, const XnChar* strName, const OniGeneralBuffer& gbValue) { XnStatus nRetVal = XN_STATUS_OK; Iterator it = End(); if (XN_STATUS_OK == Find(propertyId, it)) { return XN_STATUS_DEVICE_PROPERTY_ALREADY_EXISTS; } // create buffer OniGeneralBuffer gbNew; nRetVal = XnGeneralBufferAlloc(&gbNew, gbValue.dataSize); XN_IS_STATUS_OK(nRetVal); // copy content xnOSMemCopy(gbNew.data, gbValue.data, gbValue.dataSize); // create property XnActualGeneralProperty* pProp; XN_VALIDATE_NEW(pProp, XnActualGeneralProperty, propertyId, strName, gbNew, NULL, m_strName); pProp->SetAsBufferOwner(TRUE); // and add it to the hash nRetVal = m_Hash.Set(propertyId, pProp); if (nRetVal != XN_STATUS_OK) { XN_DELETE(pProp); return (nRetVal); } return (XN_STATUS_OK); }
XnStatus XnFileDevice::CreateCodec(xn::ProductionNode& node) { XnStatus nRetVal = XN_STATUS_OK; XnNodeInfo* pNodeInfo = NULL; if (m_nodeInfoMap.Get(node.GetName(), pNodeInfo) == XN_STATUS_OK) { XnUInt64 nValue; nRetVal = node.GetIntProperty(XN_STREAM_PROPERTY_COMPRESSION, nValue); XN_IS_STATUS_OK(nRetVal); // create new one XnCodecID codecID = XnCodec::GetCodecIDFromCompressionFormat((XnCompressionFormats)nValue); if (codecID == XN_CODEC_NULL) { XN_LOG_WARNING_RETURN(XN_STATUS_CORRUPT_FILE, XN_MASK_FILE, "Invalid compression type: %llu", nValue); } if (pNodeInfo->pXnCodec == NULL || pNodeInfo->pXnCodec->GetCompressionFormat() != nValue) { // release old codec XN_DELETE(pNodeInfo->pXnCodec); if (pNodeInfo->codec.IsValid()) { xnRemoveNeededNode(GetSelfNodeHandle(), pNodeInfo->codec); pNodeInfo->codec.Release(); } // special case: IR recorded with JPEG. This mode is no longer allowed by OpenNI (JPEG // can now only be used for image). We'll have to handle it ourselves. if (node.GetInfo().GetDescription().Type == XN_NODE_TYPE_IR && codecID == XN_CODEC_JPEG) { xn::IRGenerator irGen(node); XnMapOutputMode outputMode; nRetVal = irGen.GetMapOutputMode(outputMode); XN_IS_STATUS_OK(nRetVal); XN_VALIDATE_NEW_AND_INIT(pNodeInfo->pXnCodec, XnJpegCodec, TRUE, outputMode.nXRes, outputMode.nYRes); } else { // normal case nRetVal = m_context.CreateCodec(codecID, node, pNodeInfo->codec); XN_IS_STATUS_OK(nRetVal); // we need to make the codec a needed node, so that if xnForceShutdown() is called, we will be // destroyed *before* it does (as we hold a reference to it). nRetVal = xnAddNeededNode(GetSelfNodeHandle(), pNodeInfo->codec); XN_IS_STATUS_OK(nRetVal); XN_VALIDATE_NEW(pNodeInfo->pXnCodec, XnNiCodec, pNodeInfo->codec); } } } return (XN_STATUS_OK); }
XnStatus TypeManager::AddType(NodeTypeInfo& info) { XnStatus nRetVal = XN_STATUS_OK; // add the type to it's inheritance graph nRetVal = info.inheritanceGraph.Set(info.type, TRUE); XN_IS_STATUS_OK(nRetVal); // add it to array XN_VALIDATE_NEW(m_pTypesArray[info.type], NodeTypeInfo); *m_pTypesArray[info.type] = info; return (XN_STATUS_OK); }
XnStatus XnSensorGenerator::RegisterToNewDataAvailable(XnModuleStateChangedHandler handler, void* pCookie, XnCallbackHandle& hCallback) { XnStatus nRetVal = XN_STATUS_OK; NewDataCallback* pNewDataCallback; XN_VALIDATE_NEW(pNewDataCallback, NewDataCallback, this, handler, pCookie); hCallback = pNewDataCallback; nRetVal = m_pSensor->RegisterToNewStreamData(&OnDeviceNewStreamData, pNewDataCallback, &(pNewDataCallback->m_hCallback)); if (nRetVal != XN_STATUS_OK) { XN_DELETE(pNewDataCallback); return nRetVal; } return XN_STATUS_OK; }
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); }
XnStatus XnStreamReaderStreamHolder::Init(const XnActualPropertiesHash* pProps) { XnStatus nRetVal = XN_STATUS_OK; nRetVal = XnStreamDeviceStreamHolder::Init(pProps); XN_IS_STATUS_OK(nRetVal); if (strcmp(GetStream()->GetType(), XN_STREAM_TYPE_DEPTH) == 0) { XN_VALIDATE_NEW(m_pS2DHelper, XnShiftToDepthStreamHelper); nRetVal = m_pS2DHelper->Init(GetStream()); XN_IS_STATUS_OK(nRetVal); } return (XN_STATUS_OK); }
XnStatus XnDeviceFileWriter::CreateStreamModule(const XnChar* StreamType, const XnChar* StreamName, XnDeviceModuleHolder** ppStreamHolder) { XnFileWriterStream* pStream; XN_VALIDATE_NEW(pStream, XnFileWriterStream, StreamType, StreamName, GetDataPacker()); XnStreamDeviceStreamHolder* pHolder = XN_NEW(XnStreamDeviceStreamHolder, pStream, FALSE); if (pHolder == NULL) { XN_DELETE(pStream); return XN_STATUS_ALLOC_FAILED; } *ppStreamHolder = pHolder; return (XN_STATUS_OK); }
XnStatus XnStreamReaderDevice::CreateStreamModule(const XnChar* StreamType, const XnChar* StreamName, XnDeviceModuleHolder** ppStreamHolder) { XnStreamReaderStream* pStream; XN_VALIDATE_NEW(pStream, XnStreamReaderStream, StreamType, StreamName); XnStreamReaderStreamHolder* pHolder = XN_NEW(XnStreamReaderStreamHolder, pStream); if (pHolder == NULL) { XN_DELETE(pStream); return XN_STATUS_ALLOC_FAILED; } *ppStreamHolder = pHolder; return (XN_STATUS_OK); }
XN_DDK_API XnStatus XnPropertySetGetModuleEnumerator(const XnPropertySet* pSet, XnPropertySetModuleEnumerator** ppEnumerator) { XN_VALIDATE_INPUT_PTR(pSet); XN_VALIDATE_OUTPUT_PTR(ppEnumerator); XnPropertySetModuleEnumerator* pEnumer; XN_VALIDATE_NEW(pEnumer, XnPropertySetModuleEnumerator); pEnumer->bFirst = TRUE; pEnumer->it = pSet->pData->End(); pEnumer->pModules = pSet->pData; *ppEnumerator = pEnumer; return (XN_STATUS_OK); }
XnStatus XnDeviceBase::CreateModule(const XnChar* strName, XnDeviceModuleHolder** ppModuleHolder) { XnDeviceModule* pModule; XnDeviceModuleHolder* pHolder; // create module XN_VALIDATE_NEW(pModule, XnDeviceModule, strName); // create holder pHolder = XN_NEW(XnDeviceModuleHolder, pModule, !m_bStrictProperties); if (pHolder == NULL) { XN_DELETE(pModule); return XN_STATUS_ALLOC_FAILED; } *ppModuleHolder = pHolder; return XN_STATUS_OK; }
XnStatus XnFrameBufferManager::Init(XnUInt32 nBufferSize) { XnStatus nRetVal = XN_STATUS_OK; XN_VALIDATE_NEW(m_pBufferPool, XnOniFramePool); m_pBufferPool->SetFrameSize(nBufferSize); int numFrames = 6; // user, synced frame holder (last+synced), XnSensor frame-sync(last+incoming), working if (!m_pBufferPool->Initialize(numFrames)) { return XN_STATUS_ALLOC_FAILED; } nRetVal = xnOSCreateCriticalSection(&m_hLock); XN_IS_STATUS_OK(nRetVal); nRetVal = Reallocate(nBufferSize); XN_IS_STATUS_OK(nRetVal); return (XN_STATUS_OK); }
XnStatus XnSensorProductionNode::RegisterToProps(XnModuleStateChangedHandler handler, void* pCookie, XnCallbackHandle& hCallback, const XnChar** strNames, const XnChar* strModule /* = NULL */) { XnStatus nRetVal = XN_STATUS_OK; XnMultiPropStateChangedHandler* pHandler; XN_VALIDATE_NEW(pHandler, XnMultiPropStateChangedHandler, this, handler, pCookie, strModule); nRetVal = pHandler->AddProperties(strNames); if (nRetVal != XN_STATUS_OK) { XN_DELETE(pHandler); return (nRetVal); } // register it for later deletion m_AllHandlers.Set(pHandler, pHandler); hCallback = (XnCallbackHandle)pHandler; return (XN_STATUS_OK); }
XnStatus XnSensorsManager::GetSensor(const XnChar* strDevicePath, XnServerSensorInvoker** ppInvoker) { XnStatus nRetVal = XN_STATUS_OK; // check if the sensor is already open XnAutoCSLocker locker(m_hLock); ReferencedSensor* pSensor; nRetVal = m_sensors.Get(strDevicePath, pSensor); if (nRetVal == XN_STATUS_NO_MATCH) { // not open. open it now xnLogInfo(XN_MASK_SENSOR_SERVER, "Opening sensor '%s'...", strDevicePath); ReferencedSensor sensor; sensor.nRefCount = 0; XN_VALIDATE_NEW(sensor.pInvoker, XnServerSensorInvoker); XnProperty* aAdditionalProps[] = { &m_noClientTimeout, &m_startNewLog, &m_logFile }; nRetVal = sensor.pInvoker->Init(strDevicePath, m_strGlobalConfigFile, sizeof(aAdditionalProps)/sizeof(XnProperty*), aAdditionalProps); XN_IS_STATUS_OK(nRetVal); // add it to map nRetVal = m_sensors.Set(sensor.pInvoker->GetDevicePath(), sensor); XN_IS_STATUS_OK(nRetVal); // and take a reference to it nRetVal = m_sensors.Get(sensor.pInvoker->GetDevicePath(), pSensor); XN_IS_STATUS_OK(nRetVal); } ++pSensor->nRefCount; xnLogVerbose(XN_MASK_SENSOR_SERVER, "Sensor '%s' now has %u sessions", pSensor->pInvoker->GetDevicePath(), pSensor->nRefCount); *ppInvoker = pSensor->pInvoker; return (XN_STATUS_OK); }
XnStatus XnActualPropertiesHash::Add(const XnChar* strName, XnDouble dValue) { XnStatus nRetVal = XN_STATUS_OK; Iterator it = end(); if (XN_STATUS_OK == Find(strName, it)) { return XN_STATUS_DEVICE_PROPERTY_ALREADY_EXISTS; } // create property XnActualRealProperty* pProp; XN_VALIDATE_NEW(pProp, XnActualRealProperty, strName, dValue, m_strName); // and add it to the hash nRetVal = m_Hash.Set(strName, pProp); if (nRetVal != XN_STATUS_OK) { XN_DELETE(pProp); return (nRetVal); } return (XN_STATUS_OK); }
XnStatus XnActualPropertiesHash::Add(XnUInt32 propertyId, const XnChar* strName, const XnChar* strValue) { XnStatus nRetVal = XN_STATUS_OK; Iterator it = End(); if (XN_STATUS_OK == Find(propertyId, it)) { return XN_STATUS_DEVICE_PROPERTY_ALREADY_EXISTS; } // create property XnActualStringProperty* pProp; XN_VALIDATE_NEW(pProp, XnActualStringProperty, propertyId, strName, strValue, m_strName); // and add it to the hash nRetVal = m_Hash.Set(propertyId, pProp); if (nRetVal != XN_STATUS_OK) { XN_DELETE(pProp); return (nRetVal); } return (XN_STATUS_OK); }