Ejemplo n.º 1
0
XnStatus XnServerSession::HandleCloseSession()
{
	XnStatus nRetVal = XN_STATUS_OK;
	
	xnLogVerbose(XN_MASK_SENSOR_SERVER, "Received BYE from client %u", m_nID);

	XnStatus nActionResult = CloseSessionImpl();
	XN_ASSERT(nActionResult == XN_STATUS_OK);
	XN_REFERENCE_VARIABLE(nActionResult);

	// client shouldn't care if close succeeded or not. always send OK.
	nRetVal = SendReply(XN_SENSOR_SERVER_MESSAGE_BYE, XN_STATUS_OK);
	if (nRetVal != XN_STATUS_OK)
	{
		xnLogWarning(XN_MASK_SENSOR_SERVER, "Failed to send BYE reply to client %u: %s", m_nID, xnGetStatusString(nRetVal));
	}

	return (XN_STATUS_OK);
}
Ejemplo n.º 2
0
XN_C_API XnStatus xnOSLockSemaphore(XN_SEMAPHORE_HANDLE hSemaphore, XnUInt32 nMilliseconds)
{
	XN_RET_IF_NULL(hSemaphore, XN_STATUS_OS_INVALID_SEMAPHORE);
	DWORD nRetVal = WaitForSingleObject(hSemaphore, nMilliseconds);

	switch (nRetVal)
	{
		case WAIT_OBJECT_0:
			break;
		case WAIT_TIMEOUT:
			return XN_STATUS_OS_SEMAPHORE_TIMEOUT;
		default:
			xnLogError(XN_MASK_OS, "Failed to wait for semaphore. Last error was %u.", GetLastError());
			XN_ASSERT(FALSE);
			return XN_STATUS_OS_SEMAPHORE_LOCK_FAILED;
	}
	
	return XN_STATUS_OK;
}
Ejemplo n.º 3
0
XN_C_API XnUInt32 xnGetBytesPerPixelForPixelFormat(XnPixelFormat format)
{
	switch (format)
	{
	case XN_PIXEL_FORMAT_RGB24:
		return sizeof(XnRGB24Pixel);
	case XN_PIXEL_FORMAT_YUV422:
		return sizeof(XnYUV422DoublePixel) / 2;
	case XN_PIXEL_FORMAT_GRAYSCALE_8_BIT:
		return sizeof(XnUInt8);
	case XN_PIXEL_FORMAT_GRAYSCALE_16_BIT:
		return sizeof(XnUInt16);
	case XN_PIXEL_FORMAT_MJPEG:
		return 2;
	default:
		XN_ASSERT(FALSE);
		return 0;
	}
}
Ejemplo n.º 4
0
void XN_CALLBACK_TYPE GestureWatcher::HandleGestureProgress(GestureGenerator& generator, 
														    const XnChar* strGesture, 
														    const XnPoint3D* pPosition, 
														    XnFloat fProgress, 
														    void* pCookie)
{
	GestureWatcher *pThis = (GestureWatcher*)pCookie;

	if ((pThis == NULL) || (strGesture == NULL) || (pPosition == NULL))
	{
		xnLogWarning(XN_MASK_OPEN_NI, "Got NULL parameter");
		XN_ASSERT(FALSE);
		return;
	}

	XnGestureProgressParams gestureProgressParams(strGesture, *pPosition, fProgress);
	pThis->NotifyGeneralPropChanged(XN_PROP_GESTURE_PROGRESS, 
		sizeof(gestureProgressParams), &gestureProgressParams);
}
Ejemplo n.º 5
0
void calculateHistogram()
{
	xnOSMemSet(g_pDepthHist, 0, MAX_DEPTH*sizeof(float));
	int nNumberOfPoints = 0;

	openni::DepthPixel nValue;

	openni::VideoStream& depthGen = getDepthStream();

	if (!depthGen.isValid() || !getDepthFrame().isValid())
		return;

	const openni::DepthPixel* pDepth = (const openni::DepthPixel*)getDepthFrame().getData();
	const openni::DepthPixel* pDepthEnd = pDepth + (getDepthFrame().getDataSize() / sizeof(openni::DepthPixel));

	while (pDepth != pDepthEnd)
	{
		nValue = *pDepth;

		XN_ASSERT(nValue <= MAX_DEPTH);

		if (nValue != 0)
		{
			g_pDepthHist[nValue]++;
			nNumberOfPoints++;
		}

		pDepth++;
	}

	XnUInt32 nIndex;
	for (nIndex=1; nIndex<MAX_DEPTH; nIndex++)
	{
		g_pDepthHist[nIndex] += g_pDepthHist[nIndex-1];
	}
	for (nIndex=1; nIndex<MAX_DEPTH; nIndex++)
	{
		if (g_pDepthHist[nIndex] != 0)
		{
			g_pDepthHist[nIndex] = (nNumberOfPoints-g_pDepthHist[nIndex]) / nNumberOfPoints;
		}
	}
}
Ejemplo n.º 6
0
XnStatus PlayerNode::HandleNodeRemovedRecord(NodeRemovedRecord record)
{
	XN_VALIDATE_INPUT_PTR(m_pNodeNotifications);
	XnStatus nRetVal = record.Decode();
	XN_IS_STATUS_OK(nRetVal);
	DEBUG_LOG_RECORD(record, "NodeRemoved");

	PlayerNodeInfo* pPlayerNodeInfo = GetPlayerNodeInfo(record.GetNodeID());
	XN_VALIDATE_PTR(pPlayerNodeInfo, XN_STATUS_CORRUPT_FILE);
	if (!pPlayerNodeInfo->bValid)
	{
		XN_ASSERT(FALSE);
		XN_LOG_ERROR_RETURN(XN_STATUS_CORRUPT_FILE, XN_MASK_OPEN_NI, "Got a node removed record for non-existing node %u.", record.GetNodeID());
	}

	nRetVal = RemovePlayerNodeInfo(record.GetNodeID());
	XN_IS_STATUS_OK(nRetVal);
	return XN_STATUS_OK;
}
Ejemplo n.º 7
0
XnStatus LinkOniMapStream::SetVideoMode(OniVideoMode* pVideoMode)
{
	XnStatus nRetVal = XN_STATUS_OK;

	OniVideoMode current;
	GetVideoMode(&current);

	if (!xnOSMemCmp(&current, pVideoMode, sizeof(OniVideoMode)))
	{
		// nothing to do here
		return (ONI_STATUS_OK);
	}

	// now look for the first mode that matches
	const xnl::Array<XnFwStreamVideoMode>& supportedModes = m_pInputStream->GetSupportedVideoModes();
	XnInt32 selectedIndex = -1;
	for (XnUInt32 i = 0; i < supportedModes.GetSize(); ++i)
	{
		if (pVideoMode->resolutionX == (int)supportedModes[i].m_nXRes &&
			pVideoMode->resolutionY == (int)supportedModes[i].m_nYRes &&
			pVideoMode->fps         == (int)supportedModes[i].m_nFPS)
		{
			selectedIndex = i;
			break;
		}
	}

	if (selectedIndex == -1)
	{
		xnLogError(XN_MASK_LINK, "Tried to set unsupported mode: %ux%u@%u fps", 
			pVideoMode->resolutionX, pVideoMode->resolutionY, pVideoMode->fps);
		XN_ASSERT(FALSE);
		return XN_STATUS_BAD_PARAM;
	}

	nRetVal = m_pInputStream->SetVideoMode(supportedModes[selectedIndex]);
	XN_IS_STATUS_OK_LOG_ERROR("Set video mode", nRetVal);

	nRetVal = m_pInputStream->SetOutputFormat(pVideoMode->pixelFormat);
	XN_IS_STATUS_OK_LOG_ERROR("Set output format", nRetVal);

	return XN_STATUS_OK;
}
Ejemplo n.º 8
0
XnStatus XnFrameBufferManager::Reallocate(XnUInt32 nBufferSize)
{
    xnOSEnterCriticalSection(&m_hLock);

    // release current ones
    if (m_pWorkingBuffer != NULL)
    {
        m_pBufferPool->DecRef(m_pWorkingBuffer);
        m_pWorkingBuffer = NULL;
    }

    // Change the buffer size.
    m_pBufferPool->SetFrameSize(nBufferSize);

    // TODO: validate all is OK
    /*if (nRetVal != XN_STATUS_OK)
    {
    	xnOSLeaveCriticalSection(&m_hLock);
    	return (nRetVal);
    }*/

    // and take one
    if (nBufferSize == 0)
    {
        m_pWorkingBuffer = NULL;
    }
    else
    {
        // take working buffer
        m_pWorkingBuffer = m_pBufferPool->Acquire();
        if (m_pWorkingBuffer == NULL)
        {
            XN_ASSERT(FALSE);
            return XN_STATUS_ERROR;
        }
        m_writeBuffer.SetExternalBuffer((XnUChar*)m_pWorkingBuffer->data, nBufferSize);
    }

    xnOSLeaveCriticalSection(&m_hLock);

    return (XN_STATUS_OK);
}
Ejemplo n.º 9
0
XnBool XnSensorServer::ShutdownIfPossible()
{
	XnStatus nRetVal = XN_STATUS_OK;

	// lock sessions list
	XnAutoCSLocker locker(m_hSessionsLock);

	// check if no sessions and no sensors
	if (CanShutdown())
	{
		// lock the running lock
		XnAutoMutexLocker serverRunningLock(m_hServerRunningMutex, XN_SENSOR_SERVER_RUNNING_MUTEX_TIMEOUT);
		nRetVal = serverRunningLock.GetStatus();
		if (nRetVal == XN_STATUS_OK)
		{
			// make sure no client is waiting to connect
			CheckForNewClients(0);

			// re-check shutdown condition
			if (CanShutdown())
			{
				xnLogInfo(XN_MASK_SENSOR_SERVER, "No sensors are open and no client is connected. Shutting down...");

				// reset the event (to notify server is no longer up)
				nRetVal = xnOSResetEvent(m_hServerRunningEvent);
				if (nRetVal != XN_STATUS_OK)
				{
					xnLogWarning(XN_MASK_SENSOR_SERVER, "Failed to reset sensor server event: %s - proceeding with shutdown.", xnGetStatusString(nRetVal));
					XN_ASSERT(FALSE);
				}

				// and close the socket (to free the port for another server)
				xnOSCloseSocket(m_hListenSocket);
				m_hListenSocket = NULL;

				return TRUE;
			}
		}
	}

	return FALSE;
}
void FreenectColorStream::populateFrame(void* data, OniDriverFrame* pFrame) const
{
	pFrame->frame.sensorType = sensor_type;
	pFrame->frame.stride = video_mode.resolutionX*3;
	pFrame->frame.cropOriginX = pFrame->frame.cropOriginY = 0;
	pFrame->frame.croppingEnabled = FALSE;
	pFrame->frame.dataSize = device->getVideoBufferSize();
	pFrame->frame.data = xnOSMallocAligned(pFrame->frame.dataSize, XN_DEFAULT_MEM_ALIGN);
	if (pFrame->frame.data == NULL)
	{
		XN_ASSERT(FALSE);
		return;
	}
	// copy stream buffer from freenect
	switch (video_mode.pixelFormat)
	{
		default:
			printf("pixelFormat %s not supported by populateFrame\n", video_mode.pixelFormat);
			return;  
		case ONI_PIXEL_FORMAT_RGB888:
			unsigned char* _data = static_cast<unsigned char*>(data);
			unsigned char* frame_data = static_cast<unsigned char*>(pFrame->frame.data);
			if (mirroring)
			{
				for (unsigned int i = 0; i < pFrame->frame.dataSize; i += 3)
				{
					// find corresponding mirrored pixel
					unsigned int pixel = i / 3;
					unsigned int row = pixel / video_mode.resolutionX;
					unsigned int col = video_mode.resolutionX - (pixel % video_mode.resolutionX);
					unsigned int target = 3 * (row * video_mode.resolutionX + col);
					// copy it to this pixel
					frame_data[i] = _data[target];
					frame_data[i+1] = _data[target+1];
					frame_data[i+2] = _data[target+2];
				}
			}
			else
				std::copy(_data, _data+pFrame->frame.dataSize, frame_data);
			return;
	}
}
Ejemplo n.º 11
0
XnStatus MockDepthGenerator::SetGeneralProperty(const XnChar* strName, XnUInt32 nBufferSize, const void* pBuffer)
{
	XN_VALIDATE_INPUT_PTR(strName);
	XN_VALIDATE_INPUT_PTR(pBuffer);

	XnStatus nRetVal = XN_STATUS_OK;
	if (strcmp(strName, XN_PROP_FIELD_OF_VIEW) == 0)
	{
		if (nBufferSize != sizeof(XnFieldOfView))
		{
			XN_LOG_ERROR_RETURN(XN_STATUS_INVALID_BUFFER_SIZE, XN_MASK_OPEN_NI, "Cannot set XN_PROP_FIELD_OF_VIEW - buffer size is incorrect");
		}
		
		const XnFieldOfView* pFOV = (const XnFieldOfView*)pBuffer;
		nRetVal = SetFieldOfView(*pFOV);
		XN_IS_STATUS_OK(nRetVal);
	}
	else if (strcmp(strName, XN_PROP_USER_POSITIONS) == 0)
	{
		if (m_bSupportedUserPositionsCountReceived)
		{
			m_bSupportedUserPositionsCountReceived = FALSE;
			if (nBufferSize != m_nSupportedUserPositionsCount * sizeof(XnBoundingBox3D))
			{
				XN_LOG_ERROR_RETURN(XN_STATUS_INVALID_BUFFER_SIZE, XN_MASK_OPEN_NI, "Cannot set XN_PROP_USER_POSITIONS - buffer size is incorrect");
			}

			XN_DELETE_ARR(m_pUserPositions);
			m_pUserPositions = XN_NEW_ARR(XnBoundingBox3D, m_nSupportedUserPositionsCount);
			XN_VALIDATE_ALLOC_PTR(m_pUserPositions);
			xnOSMemCopy(m_pUserPositions, pBuffer, nBufferSize);
		}
		else
		{
			/*We got XN_PROP_USER_POSITIONS without 
			  XN_PROP_SUPPORTED_USER_POSITIONS_COUNT before it - that's an error*/
			XN_ASSERT(FALSE);
			XN_LOG_ERROR_RETURN(XN_STATUS_ERROR, XN_MASK_OPEN_NI, "got XN_PROP_USER_POSITIONS without XN_PROP_SUPPORTED_USER_POSITIONS_COUNT before it.")
		}
	}
	else
	{
Ejemplo n.º 12
0
XnStatus LinkContInputStream::UpdateData()
{
	xnl::AutoCSLocker csLock(m_hCriticalSection);
	if (!m_bInitialized)
	{
		xnLogError(XN_MASK_INPUT_STREAM, "Attempted to update data from stream %u which is not initialized", m_nStreamID);
		XN_ASSERT(FALSE);
		return XN_STATUS_NOT_INIT;
	}

	if (m_bNewDataAvailable)
	{
		//Copy working buffer to user buffer
		xnOSMemCopy(m_pUserBuffer, m_pWorkingBuffer, m_nUserBufferMaxSize);
		m_nUserBufferCurrentSize = m_nWorkingBufferCurrentSize;
		m_bNewDataAvailable = FALSE;
	}

	return XN_STATUS_OK;
}
XnStatus SocketInConnection::Connect()
{
	XnStatus nRetVal = XN_STATUS_OK;
	Disconnect(); // In case we're already connected
	nRetVal = xnOSCreateThread(&ReadThreadProc, this, &m_hReadThread);
	XN_IS_STATUS_OK_LOG_ERROR("Create input socket read thread", nRetVal);
	xnLogVerbose(XN_MASK_LINK, "Waiting for connection on socket %u...", m_nPort);
	nRetVal = xnOSWaitEvent(m_hConnectEvent, CONNECT_TIMEOUT);
	XN_IS_STATUS_OK_LOG_ERROR("Wait for input socket to connect", nRetVal);
	if (m_nConnectionStatus != XN_STATUS_OK)
	{
		xnLogError(XN_MASK_LINK, "Failed to connect to socket %u: %s", m_nPort, xnGetStatusString(m_nConnectionStatus));
		XN_ASSERT(FALSE);
		return m_nConnectionStatus;
	}
	xnLogVerbose(XN_MASK_LINK, "Socket %u connected.", m_nPort);
	nRetVal = xnOSSetThreadPriority(m_hReadThread, XN_PRIORITY_CRITICAL);
	XN_IS_STATUS_OK_LOG_ERROR("Set read thread priority", nRetVal);
	return XN_STATUS_OK;
}
Ejemplo n.º 14
0
XnStatus PlayerNode::SeekToFrame(const XnChar* strNodeName, XnInt32 nFrameOffset, XnPlayerSeekOrigin origin)
{
	XnStatus nRetVal = XN_STATUS_OK;
	XnUInt32 nNodeID = GetPlayerNodeIDByName(strNodeName);
	if (nNodeID == INVALID_NODE_ID)
	{
		XN_LOG_ERROR_RETURN(XN_STATUS_BAD_NODE_NAME, XN_MASK_OPEN_NI, "Bad node name '%s'", strNodeName);
	}

	PlayerNodeInfo* pPlayerNodeInfo = &m_pNodeInfoMap[nNodeID];

	XnInt64 nOriginFrame = 0;
	switch (origin)
	{
		case XN_PLAYER_SEEK_SET:
		{
			nOriginFrame = 0;
			break;
		}
		case XN_PLAYER_SEEK_CUR:
		{
			nOriginFrame = pPlayerNodeInfo->nCurFrame;
			break;
		}
		case XN_PLAYER_SEEK_END:
		{
			nOriginFrame = pPlayerNodeInfo->nFrames;
			break;
		}
		default:
		{
			XN_ASSERT(FALSE);
			XN_LOG_ERROR_RETURN(XN_STATUS_BAD_PARAM, XN_MASK_OPEN_NI, "Invalid seek origin: %u", origin);
		}
	}
	XnUInt32 nDestFrame = (XnUInt32)XN_MIN(XN_MAX(1, nOriginFrame + nFrameOffset), pPlayerNodeInfo->nFrames);
	nRetVal = SeekToFrameAbsolute(nNodeID, nDestFrame);
	XN_IS_STATUS_OK(nRetVal);

	return XN_STATUS_OK;
}
Ejemplo n.º 15
0
XN_C_API XnStatus XN_C_DECL xnLogSetMaskMinSeverity(const XnChar* strMask, XnLogSeverity minSeverity)
{
	LogData& logData = LogData::GetInstance();
	if (strcmp(strMask, XN_LOG_MASK_ALL) == 0)
	{
		logData.SetMinSeverityGlobally(minSeverity);
	}
	else
	{
		XnLogger* pLogger = xnLogGetLoggerForMask(strMask, TRUE);
		if (pLogger == NULL)
		{
			XN_ASSERT(FALSE);
			return XN_STATUS_ERROR;
		}

		pLogger->nMinSeverity = minSeverity;
	}

	return (XN_STATUS_OK);
}
Ejemplo n.º 16
0
XnStatus RecorderImpl::SetDestination(XnRecordMedium destType, const XnChar* strDest)
{
	XnStatus nRetVal = XN_STATUS_OK;
	switch (destType)
	{
		//Right now only file destination is supported
		case XN_RECORD_MEDIUM_FILE:
		{
			nRetVal = xnOSStrCopy(m_strFileName, strDest, sizeof(m_strFileName));
			XN_IS_STATUS_OK(nRetVal);
			nRetVal = ModuleRecorder().SetOutputStream(ModuleHandle(), this, &s_fileOutputStream);
			XN_IS_STATUS_OK(nRetVal);
			break;
		}
		default:
			XN_ASSERT(FALSE);
			return XN_STATUS_BAD_PARAM;
	}

	return XN_STATUS_OK;
}
Ejemplo n.º 17
0
XN_C_API void XN_C_DECL _xnDumpFileWriteString(XnDumpFile* pFile, const XnChar* strFormat, ...)
{
    XnStatus nRetVal = XN_STATUS_OK;
    XN_REFERENCE_VARIABLE(nRetVal);

    if (pFile == NULL)
    {
        return;
    }

    // format string
    XnChar strBuffer[XN_DUMP_MAX_FORMATTED_STRING_LENGTH];
    XnUInt32 nCharsWritten;
    va_list args;
    va_start(args, strFormat);
    nRetVal = xnOSStrFormatV(strBuffer, sizeof(strBuffer), &nCharsWritten, strFormat, args);
    XN_ASSERT(nRetVal == XN_STATUS_OK);
    va_end(args);

    _xnDumpFileWriteBuffer(pFile, (const XnUInt8*)strBuffer, nCharsWritten);
}
XnStatus XnServerSensorInvoker::GetStreamMaxResolution(SensorInvokerStream* pStream, XnUInt32& nMaxNumPixels)
{
	XnStatus nRetVal = XN_STATUS_OK;
	
	XnUInt64 nCount = 0;
	nRetVal = m_sensor.GetProperty(pStream->strType, XN_STREAM_PROPERTY_SUPPORT_MODES_COUNT, &nCount);
	XN_IS_STATUS_OK(nRetVal);

	XnCmosPreset* aPresets = XN_NEW_ARR(XnCmosPreset, nCount);
	nRetVal = m_sensor.GetProperty(pStream->strType, XN_STREAM_PROPERTY_SUPPORT_MODES, XnGeneralBufferPack(aPresets, nCount * sizeof(XnCmosPreset)));
	if (nRetVal != XN_STATUS_OK)
	{
		XN_DELETE_ARR(aPresets);
		return nRetVal;
	}

	XnUInt32 nMaxPixels = 0;
	for (XnUInt32 i = 0; i < nCount; ++i)
	{
		XnUInt32 nXRes;
		XnUInt32 nYRes;
		if (!XnDDKGetXYFromResolution((XnResolutions)aPresets[i].nResolution, &nXRes, &nYRes))
		{
			continue;
		}

		if (nXRes * nYRes > nMaxPixels)
		{
			nMaxPixels = nXRes * nYRes;
		}
	}

	XN_ASSERT(nMaxPixels > 0);

	XN_DELETE_ARR(aPresets);

	nMaxNumPixels = nMaxPixels;
	
	return (XN_STATUS_OK);
}
Ejemplo n.º 19
0
XnStatus PlayerImpl::SetSource(XnRecordMedium sourceType, const XnChar* strSource)
{
	XnStatus nRetVal = XN_STATUS_OK;
	m_sourceType = sourceType;
	//Right now the only record medium we support is a file
	
	switch (m_sourceType)
	{
		case XN_RECORD_MEDIUM_FILE:
		{
			nRetVal = xnOSStrCopy(m_strSource, strSource, sizeof(m_strSource));
			XN_IS_STATUS_OK(nRetVal);
			nRetVal = ModulePlayer().SetInputStream(ModuleHandle(), this, &s_fileInputStream);
			XN_IS_STATUS_OK(nRetVal);
			break;
		}
		default:
			XN_ASSERT(FALSE);
			return XN_STATUS_BAD_PARAM;
	}
	return XN_STATUS_OK;
}
Ejemplo n.º 20
0
XN_C_API void xnOSLogMemFree(const void* pMemBlock)
{
	if (pMemBlock == NULL)
		return;

	XnMemBlockDataNode* pPrev = NULL;

	XnAutoCSLocker lock(g_hCS);
	XnMemBlockDataNode* pNode = g_allocatedMemory.pFirst;
	while (pNode != NULL)
	{
		if (pNode->Data.pMemBlock == pMemBlock)
		{
			// found. Remove it from the list
			if (pPrev == NULL) // no previous
				g_allocatedMemory.pFirst = pNode->pNext;
			else
				pPrev->pNext = pNode->pNext;

			// if it was last, update last
			if (g_allocatedMemory.pLast == pNode)
				g_allocatedMemory.pLast = pPrev;

			xnDumpFileWriteString(g_dump, "Free,0x%x\n", pMemBlock);

			// deallocate memory
			xnOSFree(pNode);

			return;
		}

		// move to next
		pPrev = pNode;
		pNode = pNode->pNext;
	}

	// if we got here then we're trying to free a non-allocated memory
	XN_ASSERT(FALSE);
}
Ejemplo n.º 21
0
void XnBufferPool::DecRef(XnBuffer* pBuffer)
{
	if (pBuffer == NULL)
	{
		return;
	}

	XnBufferInPool* pBufInPool = (XnBufferInPool*)pBuffer;

	xnOSEnterCriticalSection(&m_hLock);

	xnDumpWriteString(m_dump, "%u dec ref (%d)", pBufInPool->m_nID, pBufInPool->m_nRefCount-1);

	if (--pBufInPool->m_nRefCount == 0)
	{
		if (pBufInPool->m_bDestroy)
		{
			// remove it from all buffers pool
			XnBuffersList::ConstIterator it = m_AllBuffers.Find(pBufInPool);
			XN_ASSERT(it != m_AllBuffers.end());
			m_AllBuffers.Remove(it);
			// and free it
			DestroyBuffer(pBufInPool);
			xnDumpWriteString(m_dump, "destroy!\n");
		}
		else
		{
			// return it to free buffers list
			m_FreeBuffers.AddLast(pBufInPool);
			xnDumpWriteString(m_dump, "return to pool!\n");
		}
	}
	else
	{
		xnDumpWriteString(m_dump, "\n");
	}

	xnOSLeaveCriticalSection(&m_hLock);
}
Ejemplo n.º 22
0
XnStatus PlayerImpl::RemoveNode(const XnChar* strNodeName)
{
	XnStatus nRetVal = XN_STATUS_OK;

	PlayedNodeInfo playedNodeInfo = {0};

	nRetVal = m_playedNodes.Get(strNodeName, playedNodeInfo);
	XN_IS_STATUS_OK(nRetVal);

	nRetVal = xnUnlockNodeForChanges(playedNodeInfo.hNode, playedNodeInfo.hLock);
	if (nRetVal != XN_STATUS_OK)
	{
		xnLogWarning(XN_MASK_OPEN_NI, "Failed to unlock node when removing from playing: %s", xnGetStatusString(nRetVal));
	}

	nRetVal = m_playedNodes.Remove(strNodeName);
	XN_ASSERT(nRetVal == XN_STATUS_OK);

	xnProductionNodeRelease(playedNodeInfo.hNode);

	return (XN_STATUS_OK);
}
Ejemplo n.º 23
0
static XnStatus xnLogBCSetMaskState(const XnChar* strMask, XnBool bEnabled)
{
	LogData& logData = LogData::GetInstance();
	if (strcmp(strMask, XN_LOG_MASK_ALL) == 0)
	{
		XnLogSeverity newGlobalSeverity = xnLogBCCalcSeverityByState(logData.defaultMinSeverity, bEnabled);
		logData.SetMinSeverityGlobally(newGlobalSeverity);
	}
	else
	{
		XnLogger* pLogger = xnLogGetLoggerForMask(strMask, TRUE);
		if (pLogger == NULL)
		{
			XN_ASSERT(FALSE);
			return XN_STATUS_ERROR;
		}

		pLogger->nMinSeverity = xnLogBCCalcSeverityByState(pLogger->nMinSeverity, bEnabled);
	}

	return (XN_STATUS_OK);
}
Ejemplo n.º 24
0
TypeManager::TypeManager()
{
	xnOSCreateCriticalSection(&m_hLock);

	// create built-in types inheritance graph
	NodeTypeInfo productionNodeInfo("ProductionNode", XN_NODE_TYPE_PRODUCTION_NODE);
	AddType(productionNodeInfo);

	// Production Nodes
	AddNewType("Device", XN_NODE_TYPE_DEVICE, XN_NODE_TYPE_PRODUCTION_NODE);
	AddNewType("Recorder", XN_NODE_TYPE_RECORDER, XN_NODE_TYPE_PRODUCTION_NODE);
	AddNewType("Player", XN_NODE_TYPE_PLAYER, XN_NODE_TYPE_PRODUCTION_NODE);
	AddNewType("Codec", XN_NODE_TYPE_CODEC, XN_NODE_TYPE_PRODUCTION_NODE);
	AddNewType("Script", XN_NODE_TYPE_SCRIPT, XN_NODE_TYPE_PRODUCTION_NODE);
	AddNewType("Generator", XN_NODE_TYPE_GENERATOR, XN_NODE_TYPE_PRODUCTION_NODE);

	// Generators
	AddNewType("User", XN_NODE_TYPE_USER, XN_NODE_TYPE_GENERATOR);
	AddNewType("Hands", XN_NODE_TYPE_HANDS, XN_NODE_TYPE_GENERATOR);
	AddNewType("Gesture", XN_NODE_TYPE_GESTURE, XN_NODE_TYPE_GENERATOR);
	AddNewType("Audio", XN_NODE_TYPE_AUDIO, XN_NODE_TYPE_GENERATOR);
	AddNewType("MapGenerator", XN_NODE_TYPE_MAP_GENERATOR, XN_NODE_TYPE_GENERATOR);

	// Map Generators
	AddNewType("Depth", XN_NODE_TYPE_DEPTH, XN_NODE_TYPE_MAP_GENERATOR);
	AddNewType("Image", XN_NODE_TYPE_IMAGE, XN_NODE_TYPE_MAP_GENERATOR);
	AddNewType("IR", XN_NODE_TYPE_IR, XN_NODE_TYPE_MAP_GENERATOR);
	AddNewType("Scene", XN_NODE_TYPE_SCENE, XN_NODE_TYPE_MAP_GENERATOR);

	m_nNextExtendedNodeType = XN_NODE_TYPE_FIRST_EXTENSION;

	// make sure all types are registered
	for (XnInt32 i = 1; i < m_nNextExtendedNodeType; ++i)
	{
		XN_ASSERT(m_pTypesArray[i] != NULL);
	}
}
Ejemplo n.º 25
0
XnProductionNodeType GetNodeType(const XnChar* strType)
{
    if (strcmp(strType, XN_STREAM_TYPE_DEPTH) == 0)
    {
        return XN_NODE_TYPE_DEPTH;
    }
    else if (strcmp(strType, XN_STREAM_TYPE_IMAGE) == 0)
    {
        return XN_NODE_TYPE_IMAGE;
    }
    else if (strcmp(strType, XN_STREAM_TYPE_IR) == 0)
    {
        return XN_NODE_TYPE_IR;
    }
    else if (strcmp(strType, XN_STREAM_TYPE_AUDIO) == 0)
    {
        return XN_NODE_TYPE_AUDIO;
    }
    else
    {
        XN_ASSERT(FALSE);
        return (XnProductionNodeType)-1;
    }
}
Ejemplo n.º 26
0
XnStatus XnPixelStream::OnResolutionChanged()
{
    XnStatus nRetVal = XN_STATUS_OK;

    XnResolutions res = (XnResolutions)m_Resolution.GetValue();
    if (res != XN_RESOLUTION_CUSTOM)
    {
        // update XRes and YRes accordingly
        XnUInt32 nXRes;
        XnUInt32 nYRes;
        if (!XnDDKGetXYFromResolution(res, &nXRes, &nYRes))
        {
            XN_ASSERT(FALSE);
        }

        nRetVal = m_XRes.UnsafeUpdateValue(nXRes);
        XN_IS_STATUS_OK(nRetVal);

        nRetVal = m_YRes.UnsafeUpdateValue(nYRes);
        XN_IS_STATUS_OK(nRetVal);
    }

    return (XN_STATUS_OK);
}
XnStatus XnShiftToDepthStreamHelper::GetShiftToDepthConfig(XnShiftToDepthConfig& Config)
{
	XnStatus nRetVal = XN_STATUS_OK;
	
	XnUInt64 nTemp;
	XnDouble dTemp;

	nRetVal = m_pModule->GetProperty(XN_STREAM_PROPERTY_ZERO_PLANE_DISTANCE, &nTemp);
	XN_IS_STATUS_OK(nRetVal);

	Config.nZeroPlaneDistance = (XnUInt16)nTemp;

	nRetVal = m_pModule->GetProperty(XN_STREAM_PROPERTY_ZERO_PLANE_PIXEL_SIZE, &dTemp);
	XN_IS_STATUS_OK(nRetVal);

	Config.fZeroPlanePixelSize = (XnFloat)dTemp;

	nRetVal = m_pModule->GetProperty(XN_STREAM_PROPERTY_EMITTER_DCMOS_DISTANCE, &dTemp);
	XN_IS_STATUS_OK(nRetVal);

	Config.fEmitterDCmosDistance = (XnFloat)dTemp;

	nRetVal = m_pModule->GetProperty(XN_STREAM_PROPERTY_MAX_SHIFT, &nTemp);
	XN_IS_STATUS_OK(nRetVal);

	Config.nDeviceMaxShiftValue = (XnUInt32)nTemp;

	nRetVal = m_pModule->GetProperty(XN_STREAM_PROPERTY_DEVICE_MAX_DEPTH, &nTemp);
	XN_IS_STATUS_OK(nRetVal);

	Config.nDeviceMaxDepthValue = (XnUInt32)nTemp;

	nRetVal = m_pModule->GetProperty(XN_STREAM_PROPERTY_CONST_SHIFT, &nTemp);
	XN_IS_STATUS_OK(nRetVal);

	Config.nConstShift = (XnUInt32)nTemp;

	nRetVal = m_pModule->GetProperty(XN_STREAM_PROPERTY_PIXEL_SIZE_FACTOR, &nTemp);
	XN_IS_STATUS_OK(nRetVal);

	Config.nPixelSizeFactor = (XnUInt32)nTemp;

	nRetVal = m_pModule->GetProperty(XN_STREAM_PROPERTY_PARAM_COEFF, &nTemp);
	XN_IS_STATUS_OK(nRetVal);

	Config.nParamCoeff = (XnUInt32)nTemp;

	nRetVal = m_pModule->GetProperty(XN_STREAM_PROPERTY_SHIFT_SCALE, &nTemp);
	XN_IS_STATUS_OK(nRetVal);

	Config.nShiftScale = (XnUInt32)nTemp;

	// change scale according to output format
	nRetVal = m_pModule->GetProperty(XN_STREAM_PROPERTY_OUTPUT_FORMAT, &nTemp);
	XN_IS_STATUS_OK(nRetVal);

	switch (nTemp)
	{
	case ONI_PIXEL_FORMAT_DEPTH_1_MM:
	case ONI_PIXEL_FORMAT_SHIFT_9_2:
		break;
	case ONI_PIXEL_FORMAT_DEPTH_100_UM:
		Config.nShiftScale *= 10;
		break;
	default:
		XN_ASSERT(FALSE);
	}

	nRetVal = m_pModule->GetProperty(XN_STREAM_PROPERTY_MIN_DEPTH, &nTemp);
	XN_IS_STATUS_OK(nRetVal);

	Config.nDepthMinCutOff = (OniDepthPixel)nTemp;

	nRetVal = m_pModule->GetProperty(XN_STREAM_PROPERTY_MAX_DEPTH, &nTemp);
	XN_IS_STATUS_OK(nRetVal);

	Config.nDepthMaxCutOff = (OniDepthPixel)nTemp;
	
	nRetVal = m_pModule->GetProperty(XN_STREAM_PROPERTY_CUSTOM_S2D_TABLE_ID, &nTemp);
	XN_IS_STATUS_OK(nRetVal);

	Config.nCustomS2DTableID = (XnUInt64)nTemp;

	return (XN_STATUS_OK);
}
Ejemplo n.º 28
0
void drawDepth(IntRect* pLocation, IntPair* pPointer)
{
	if (g_DrawConfig.Streams.Depth.Coloring != DEPTH_OFF)
	{
		if (!isDepthOn())
		{
			drawClosedStream(pLocation, "Depth");
			return;
		}

		openni::VideoFrameRef* pDepthMD = &getDepthFrame();

		if (!pDepthMD->isValid())
			return;

		const openni::DepthPixel* pDepth = (openni::DepthPixel*)pDepthMD->getData();
		XN_ASSERT(pDepth);
		
		int width = pDepthMD->getWidth();
		int height = pDepthMD->getHeight();
		int originX = pDepthMD->getCropOriginX();
		int originY = pDepthMD->getCropOriginY();

		if (pDepthMD->getFrameIndex() == 0)
		{
			return;
		}

		// copy depth into texture-map
		for (XnUInt16 nY = originY; nY < height + originY; nY++)
		{
			XnUInt8* pTexture = TextureMapGetLine(&g_texDepth, nY) + originX*4;
			for (XnUInt16 nX = 0; nX < width; nX++, pDepth++, pTexture+=4)
			{
				XnUInt8 nRed = 0;
				XnUInt8 nGreen = 0;
				XnUInt8 nBlue = 0;
				XnUInt8 nAlpha = g_DrawConfig.Streams.Depth.fTransparency*255;

				XnUInt16 nColIndex;

				switch (g_DrawConfig.Streams.Depth.Coloring)
				{
				case LINEAR_HISTOGRAM:
					nRed = nGreen = g_pDepthHist[*pDepth]*255;
					break;
				case PSYCHEDELIC_SHADES:
					nAlpha *= (((XnFloat)(*pDepth % 10) / 20) + 0.5);
				case PSYCHEDELIC:

					switch ((*pDepth/10) % 10)
					{
					case 0:
						nRed = 255;
						break;
					case 1:
						nGreen = 255;
						break;
					case 2:
						nBlue = 255;
						break;
					case 3:
						nRed = 255;
						nGreen = 255;
						break;
					case 4:
						nGreen = 255;
						nBlue = 255;
						break;
					case 5:
						nRed = 255;
						nBlue = 255;
						break;
					case 6:
						nRed = 255;
						nGreen = 255;
						nBlue = 255;
						break;
					case 7:
						nRed = 127;
						nBlue = 255;
						break;
					case 8:
						nRed = 255;
						nBlue = 127;
						break;
					case 9:
						nRed = 127;
						nGreen = 255;
						break;
					}
					break;
				case RAINBOW:
					nColIndex = (XnUInt16)((*pDepth / (g_fMaxDepth / 256)));
					nRed   = PalletIntsR[nColIndex];
					nGreen = PalletIntsG[nColIndex];
					nBlue  = PalletIntsB[nColIndex];
					break;
				case CYCLIC_RAINBOW:
					nColIndex = (*pDepth % 256);
					nRed   = PalletIntsR[nColIndex];
					nGreen = PalletIntsG[nColIndex];
					nBlue  = PalletIntsB[nColIndex];
					break;
				case CYCLIC_RAINBOW_HISTOGRAM:
				{
					float fHist = g_pDepthHist[*pDepth];
					nColIndex = (*pDepth % 256);
					nRed   = PalletIntsR[nColIndex] * fHist;
					nGreen = PalletIntsG[nColIndex] * fHist;
					nBlue  = PalletIntsB[nColIndex] * fHist;
					break;
				}
				default:
					assert(0);
					return;
				}

				pTexture[0] = nRed;
				pTexture[1] = nGreen;
				pTexture[2] = nBlue;

				if (*pDepth == 0)
					pTexture[3] = 0;
				else
					pTexture[3] = nAlpha;
			}
		}

		if (pPointer != NULL)
		{
			TextureMapDrawCursor(&g_texDepth, *pPointer);
		}

		TextureMapUpdate(&g_texDepth);
		TextureMapDraw(&g_texDepth, pLocation);
	}
}
Ejemplo n.º 29
0
XnDouble RealPropRecord::GetValue() const
{
	XN_ASSERT(GetPropDataSize() == sizeof(XnDouble));
	return *(XnDouble*)GetPropData();
}
Ejemplo n.º 30
0
XnUInt64 IntPropRecord::GetValue() const
{
	XN_ASSERT(GetPropDataSize() == sizeof(XnUInt64));
	return *(XnUInt64*)GetPropData();
}