コード例 #1
0
ファイル: PlayerNode.cpp プロジェクト: 3david/OpenNI
XnStatus PlayerNode::HandleNodeStateReadyRecord(NodeStateReadyRecord record)
{
	XN_VALIDATE_INPUT_PTR(m_pNodeNotifications);
	XnStatus nRetVal = record.Decode();
	XN_IS_STATUS_OK(nRetVal);
	DEBUG_LOG_RECORD(record, "NodeStateReady");
	PlayerNodeInfo* pPlayerNodeInfo = GetPlayerNodeInfo(record.GetNodeID());
	XN_VALIDATE_PTR(pPlayerNodeInfo, XN_STATUS_CORRUPT_FILE);
	if (!pPlayerNodeInfo->bValid)
	{
		XN_ASSERT(FALSE);
		return XN_STATUS_CORRUPT_FILE;
	}

	nRetVal = m_pNodeNotifications->OnNodeStateReady(m_pNotificationsCookie, pPlayerNodeInfo->strName);
	XN_IS_STATUS_OK(nRetVal);
	if (pPlayerNodeInfo->bIsGenerator && 
		(pPlayerNodeInfo->compression != XN_CODEC_NULL) && 
		!pPlayerNodeInfo->codec.IsValid())
	{
		xn::ProductionNode node;
		/*at this point the node should have all its properties set so we can create the codec. A node 
		  with the name pPlayerNodeInfo->strName should have been created by now. If it wasn't,
		  GetProductionNodeByName() will fail. */
		nRetVal = m_context.GetProductionNodeByName(pPlayerNodeInfo->strName, node);
		XN_IS_STATUS_OK(nRetVal);
		nRetVal = m_context.CreateCodec(pPlayerNodeInfo->compression, node, pPlayerNodeInfo->codec);
		XN_IS_STATUS_OK(nRetVal);

		// make the player dependent on the codec
		xn::Player playerNode;
		nRetVal = m_context.GetProductionNodeByName(m_strName, playerNode);
		if (nRetVal != XN_STATUS_OK)
		{
			pPlayerNodeInfo->codec.Unref();
			return (nRetVal);
		}

		nRetVal = playerNode.AddNeededNode(pPlayerNodeInfo->codec);
		if (nRetVal != XN_STATUS_OK)
		{
			pPlayerNodeInfo->codec.Unref();
			return (nRetVal);
		}

		// at this point, we can unref the codec (it will still have at least one ref, as we added it to needed nodes).
		xn::Codec codec = pPlayerNodeInfo->codec;
		codec.Unref();
	}

	pPlayerNodeInfo->bStateReady = TRUE;
	return XN_STATUS_OK;
}
コード例 #2
0
ファイル: PlayerNode.cpp プロジェクト: HairyFotr/OpenNI
XnStatus PlayerNode::HandleNodeStateReadyRecord(NodeStateReadyRecord record)
{
	XN_VALIDATE_INPUT_PTR(m_pNodeNotifications);
	XnStatus nRetVal = record.Decode();
	XN_IS_STATUS_OK(nRetVal);
	DEBUG_LOG_RECORD(record, "NodeStateReady");
	PlayerNodeInfo* pPlayerNodeInfo = GetPlayerNodeInfo(record.GetNodeID());
	XN_VALIDATE_PTR(pPlayerNodeInfo, XN_STATUS_CORRUPT_FILE);
	if (!pPlayerNodeInfo->bValid)
	{
		XN_ASSERT(FALSE);
		return XN_STATUS_CORRUPT_FILE;
	}

	// after wrap-around, if node wasn't destroyed, no need to notify about state ready
	if (!pPlayerNodeInfo->bStateReady)
	{
		nRetVal = m_pNodeNotifications->OnNodeStateReady(m_pNotificationsCookie, pPlayerNodeInfo->strName);
		XN_IS_STATUS_OK(nRetVal);
	}

	if (pPlayerNodeInfo->bIsGenerator && 
		(pPlayerNodeInfo->compression != XN_CODEC_NULL) && 
		!pPlayerNodeInfo->codec.IsValid())
	{
		xn::ProductionNode node;
		/*at this point the node should have all its properties set so we can create the codec. A node 
		  with the name pPlayerNodeInfo->strName should have been created by now. If it wasn't,
		  GetProductionNodeByName() will fail. */
		nRetVal = m_context.GetProductionNodeByName(pPlayerNodeInfo->strName, node);
		XN_IS_STATUS_OK(nRetVal);

		nRetVal = m_context.CreateCodec(pPlayerNodeInfo->compression, node, pPlayerNodeInfo->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(), pPlayerNodeInfo->codec);
		XN_IS_STATUS_OK(nRetVal);
	}

	pPlayerNodeInfo->bStateReady = TRUE;
	return XN_STATUS_OK;
}