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 PlayerImpl::AddNode(const XnChar* strNodeName, XnProductionNodeType type, XnCodecID compression) { XnStatus nRetVal = XN_STATUS_OK; PlayedNodeInfo playedNodeInfo = {0}; if (m_playedNodes.Get(strNodeName, playedNodeInfo) == XN_STATUS_OK) { // already in the list, just return OK. return (XN_STATUS_OK); } // check if we need to create it (maybe it's a rewind...) if (xnGetRefNodeHandleByName(m_hPlayer->pContext, strNodeName, &playedNodeInfo.hNode) != XN_STATUS_OK) { XnStatus nRetVal = xnCreateMockNode(m_hPlayer->pContext, type, strNodeName, &playedNodeInfo.hNode); XN_IS_STATUS_OK(nRetVal); // mark this node as needed node. We need this in order to make sure if xnForceShutdown() is called, // the player will be destroyed *before* mock node is (so we can release it). nRetVal = xnAddNeededNode(m_hPlayer, playedNodeInfo.hNode); if (nRetVal != XN_STATUS_OK) { xnProductionNodeRelease(playedNodeInfo.hNode); return (nRetVal); } } // lock it, so no one can change configuration (this is a file recording) nRetVal = xnLockNodeForChanges(playedNodeInfo.hNode, &playedNodeInfo.hLock); if (nRetVal != XN_STATUS_OK) { xnProductionNodeRelease(playedNodeInfo.hNode); return (nRetVal); } nRetVal = m_playedNodes.Set(strNodeName, playedNodeInfo); if (nRetVal != XN_STATUS_OK) { xnProductionNodeRelease(playedNodeInfo.hNode); return (nRetVal); } return XN_STATUS_OK; }
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; }