Example #1
0
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);
}
Example #2
0
XnStatus PlayerNode::RemovePlayerNodeInfo(XnUInt32 nNodeID)
{
	XnStatus nRetVal = XN_STATUS_OK;

	PlayerNodeInfo* pPlayerNodeInfo = GetPlayerNodeInfo(nNodeID);
	XN_VALIDATE_PTR(pPlayerNodeInfo, XN_STATUS_CORRUPT_FILE);
	if (pPlayerNodeInfo->bValid)
	{
		if (m_pNodeNotifications != NULL)
		{
			nRetVal = m_pNodeNotifications->OnNodeRemoved(m_pNotificationsCookie, pPlayerNodeInfo->strName);
			if (nRetVal != XN_STATUS_OK)
			{
				return nRetVal;
			}
		}

		if (pPlayerNodeInfo->codec.IsValid())
		{
			xnRemoveNeededNode(GetSelfNodeHandle(), pPlayerNodeInfo->codec);
			pPlayerNodeInfo->codec.Release();
		}
		pPlayerNodeInfo->Reset(); //Now it's not valid anymore
	}

	return XN_STATUS_OK;
}
Example #3
0
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;
}
Example #4
0
void XnFileDevice::Free()
{
    for (XnNodeInfoMap::Iterator it = m_nodeInfoMap.Begin(); it != m_nodeInfoMap.End(); ++it)
    {
        XnNodeInfo& nodeInfo = it->Value();
        XN_DELETE(nodeInfo.pXnCodec);
        if (nodeInfo.codec.IsValid())
        {
            xnRemoveNeededNode(GetSelfNodeHandle(), nodeInfo.codec);
            nodeInfo.codec.Release();
        }

    }
    m_nodeInfoMap.Clear();

    if (m_ShiftToDepth.bIsInitialized)
    {
        XnShiftToDepthFree(&m_ShiftToDepth);
    }

    if (m_pInputStream != NULL)
    {
        XN_DELETE(m_pInputStream);
        m_pInputStream = NULL;
    }

    if (m_pDataPacker != NULL)
    {
        m_pDataPacker->Free();
        XN_DELETE(m_pDataPacker);
        m_pDataPacker = NULL;
    }

    if (m_pStreamData != NULL)
    {
        XnStreamDataDestroy(&m_pStreamData);
        m_pStreamData = NULL;
    }
}