XnStatus PlayerNode::HandleDataIndexRecord(DataIndexRecordHeader record, XnBool bReadPayload) { XnStatus nRetVal = XN_STATUS_OK; XN_VALIDATE_INPUT_PTR(m_pNodeNotifications); nRetVal = record.Decode(); XN_IS_STATUS_OK(nRetVal); DEBUG_LOG_RECORD(record, "DataIndex"); XN_ASSERT(record.GetNodeID() != INVALID_NODE_ID); PlayerNodeInfo* pPlayerNodeInfo = GetPlayerNodeInfo(record.GetNodeID()); XN_VALIDATE_PTR(pPlayerNodeInfo, XN_STATUS_CORRUPT_FILE); XnUInt32 nRecordTotalSize = record.GetSize() + record.GetPayloadSize(); if (nRecordTotalSize > RECORD_MAX_SIZE) { XN_ASSERT(FALSE); XN_LOG_ERROR_RETURN(XN_STATUS_INTERNAL_BUFFER_TOO_SMALL, XN_MASK_OPEN_NI, "Record size %u is larger than player internal buffer", nRecordTotalSize); } if (bReadPayload) { // make sure node exists if (!pPlayerNodeInfo->bValid) { XN_ASSERT(FALSE); return XN_STATUS_CORRUPT_FILE; } if (record.GetPayloadSize() != (pPlayerNodeInfo->nFrames+1) * sizeof(DataIndexEntry)) { XN_ASSERT(FALSE); XN_LOG_WARNING_RETURN(XN_STATUS_CORRUPT_FILE, XN_MASK_OPEN_NI, "Seek table has %u entries, but node has %u frames!", record.GetPayloadSize() / sizeof(DataIndexEntry), pPlayerNodeInfo->nFrames); } // allocate our data index pPlayerNodeInfo->pDataIndex = (DataIndexEntry*)xnOSCalloc(pPlayerNodeInfo->nFrames+1, sizeof(DataIndexEntry)); XN_VALIDATE_ALLOC_PTR(pPlayerNodeInfo->pDataIndex); //Now read the actual data XnUInt32 nBytesRead = 0; nRetVal = Read(pPlayerNodeInfo->pDataIndex, record.GetPayloadSize(), nBytesRead); XN_IS_STATUS_OK(nRetVal); if (nBytesRead < record.GetPayloadSize()) { XN_LOG_ERROR_RETURN(XN_STATUS_CORRUPT_FILE, XN_MASK_OPEN_NI, "Not enough bytes read"); } } else { //Just skip the data nRetVal = SkipRecordPayload(record); XN_IS_STATUS_OK(nRetVal); } return XN_STATUS_OK; }
XnStatus RecorderImpl::Init(XnNodeHandle hRecorder) { XN_VALIDATE_PTR(hRecorder, XN_STATUS_ERROR); XnModuleInstance* pModuleInstance = hRecorder->pModuleInstance; XN_VALIDATE_PTR(pModuleInstance, XN_STATUS_ERROR); XnModuleNodeHandle hModule = pModuleInstance->hNode; XN_VALIDATE_PTR(hModule, XN_STATUS_ERROR); XN_VALIDATE_PTR(pModuleInstance->pLoaded, XN_STATUS_ERROR); XN_VALIDATE_PTR(pModuleInstance->pLoaded->pInterface, XN_STATUS_ERROR); m_hRecorder = hRecorder; return XN_STATUS_OK; }
XnStatus PlayerNode::RemovePlayerNodeInfo(XnUInt32 nNodeID) { XnStatus nRetVal = XN_STATUS_OK; xn::Player playerNode; nRetVal = m_context.GetProductionNodeByName(m_strName, playerNode); XN_IS_STATUS_OK(nRetVal); 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; } } playerNode.RemoveNeededNode(pPlayerNodeInfo->codec); pPlayerNodeInfo->codec = NULL; pPlayerNodeInfo->Reset(); //Now it's not valid anymore } return XN_STATUS_OK; }
XN_C_API XnStatus xnOSCreateNamedMutex(XN_MUTEX_HANDLE* pMutexHandle, const XnChar* cpMutexName) { // Local function variables XnStatus nRetVal = XN_STATUS_OK; XnBool bRetVal = FALSE; // Validate the input/output pointers (to make sure none of them is NULL) XN_VALIDATE_INPUT_PTR(pMutexHandle); // remove bad chars from name XnChar strMutexOSName[MAX_PATH]; if (cpMutexName != NULL) { int i = 0; for (; (i < MAX_PATH) && (cpMutexName[i] != '\0'); ++i) strMutexOSName[i] = cpMutexName[i] == '\\' ? '_' : cpMutexName[i]; if (i == MAX_PATH) { xnLogWarning(XN_MASK_OS, "Mutex name is too long!"); return XN_STATUS_OS_MUTEX_CREATION_FAILED; } strMutexOSName[i] = '\0'; } // Create a named mutex via the OS *pMutexHandle = CreateMutex(NULL, FALSE, (cpMutexName == NULL) ? NULL : strMutexOSName); // Make sure it succeeded (return value is not null) XN_VALIDATE_PTR(*pMutexHandle, XN_STATUS_OS_MUTEX_CREATION_FAILED); // All is good... return (XN_STATUS_OK); }
XnStatus PlayerNode::HandleStringPropRecord(StringPropRecord record) { XN_VALIDATE_INPUT_PTR(m_pNodeNotifications); XnStatus nRetVal = record.Decode(); XN_IS_STATUS_OK(nRetVal); DEBUG_LOG_RECORD(record, "StringProp"); 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->OnNodeStringPropChanged(m_pNotificationsCookie, pPlayerNodeInfo->strName, record.GetPropName(), record.GetValue()); XN_IS_STATUS_OK(nRetVal); nRetVal = SaveRecordUndoInfo(pPlayerNodeInfo, record.GetPropName(), TellStream() - record.GetSize(), record.GetUndoRecordPos()); XN_IS_STATUS_OK(nRetVal); return XN_STATUS_OK; }
XnStatus PlayerImpl::SeekFileImpl(XnOSSeekType seekType, XnInt32 nOffset) { XN_VALIDATE_PTR(m_pInFile, XN_STATUS_ERROR); long nOrigin = 0; switch (seekType) { case XN_OS_SEEK_CUR: nOrigin = SEEK_CUR; break; case XN_OS_SEEK_END: nOrigin = SEEK_END; break; case SEEK_SET: nOrigin = SEEK_SET; break; default: XN_ASSERT(FALSE); return XN_STATUS_BAD_PARAM; } if (fseek(m_pInFile, nOffset, nOrigin) != 0) { return XN_STATUS_ERROR; } return XN_STATUS_OK; }
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; }
XnStatus MockMapGenerator::GetSupportedMapOutputModes(XnMapOutputMode aModes[], XnUInt32& nCount) { XN_VALIDATE_PTR(m_pSupportedMapOutputModes, XN_STATUS_PROPERTY_NOT_SET); nCount = XN_MIN(nCount, m_nSupportedMapOutputModesCount); xnOSMemCopy(aModes, m_pSupportedMapOutputModes, nCount * sizeof(m_pSupportedMapOutputModes[0])); return XN_STATUS_OK; }
OniStatus Context::enableFrameSyncEx(VideoStream** pStreams, int numStreams, DeviceDriver* pDeviceDriver, OniFrameSyncHandle* pFrameSyncHandle) { // Make sure the device driver is valid. if (pDeviceDriver == NULL) { return ONI_STATUS_ERROR; } // Create the new frame sync group (it will link all the streams). SyncedStreamsFrameHolder* pSyncedStreamsFrameHolder = XN_NEW(SyncedStreamsFrameHolder, m_frameManager, pStreams, numStreams); XN_VALIDATE_PTR(pSyncedStreamsFrameHolder, ONI_STATUS_ERROR); // Configure frame-sync group in driver. void* driverHandle = pDeviceDriver->enableFrameSync(pStreams, numStreams); XN_VALIDATE_PTR(driverHandle, ONI_STATUS_ERROR); // Return the frame sync handle. *pFrameSyncHandle = XN_NEW(_OniFrameSync); if (*pFrameSyncHandle == NULL) { m_errorLogger.Append("Couldn't allocate memory for FrameSyncHandle"); return ONI_STATUS_ERROR; } (*pFrameSyncHandle)->pSyncedStreamsFrameHolder = pSyncedStreamsFrameHolder; (*pFrameSyncHandle)->pDeviceDriver = pDeviceDriver; (*pFrameSyncHandle)->pFrameSyncHandle = driverHandle; // Update the frame holders of all the streams. pSyncedStreamsFrameHolder->lock(); for (int j = 0; j < numStreams; ++j) { FrameHolder* pOldFrameHolder = pStreams[j]->getFrameHolder(); pOldFrameHolder->lock(); pOldFrameHolder->setStreamEnabled(pStreams[j], FALSE); pStreams[j]->setFrameHolder(pSyncedStreamsFrameHolder); pOldFrameHolder->unlock(); XN_DELETE(pOldFrameHolder); } pSyncedStreamsFrameHolder->unlock(); return ONI_STATUS_OK; }
XnStatus PlayerImpl::Init(XnNodeHandle hPlayer) { XN_VALIDATE_PTR(hPlayer, XN_STATUS_ERROR); XnModuleInstance* pModuleInstance = hPlayer->pModuleInstance; XN_VALIDATE_PTR(pModuleInstance, XN_STATUS_ERROR); XnModuleNodeHandle hModule = pModuleInstance->hNode; XN_VALIDATE_PTR(hModule, XN_STATUS_ERROR); XN_VALIDATE_PTR(pModuleInstance->pLoaded, XN_STATUS_ERROR); XN_VALIDATE_PTR(pModuleInstance->pLoaded->pInterface, XN_STATUS_ERROR); m_hPlayer = hPlayer; XnStatus nRetVal = ModulePlayer().SetNodeNotifications(ModuleHandle(), this, &s_nodeNotifications); XN_IS_STATUS_OK(nRetVal); XnCallbackHandle hDummy; // node will be destroyed anyway nRetVal = ModulePlayer().RegisterToEndOfFileReached(ModuleHandle(), EndOfFileReachedCallback, this, &hDummy); XN_IS_STATUS_OK(nRetVal); return XN_STATUS_OK; }
XnStatus PlayerImpl::ReadFileImpl(void* pData, XnUInt32 nSize, XnUInt32 &nBytesRead) { XN_VALIDATE_PTR(m_pInFile, XN_STATUS_ERROR); nBytesRead = fread(pData, 1, nSize, m_pInFile); if (ferror(m_pInFile)) { return XN_STATUS_OS_FILE_READ_FAILED; } //nBytesRead could be smaller than nSize at the end, but that's not an error 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; } 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; }
XnUInt32 PlayerNode::GetNumFrames(const XnChar* strNodeName, XnUInt32& nFrames) { PlayerNodeInfo* pPlayerNodeInfo = GetPlayerNodeInfoByName(strNodeName); XN_VALIDATE_PTR(pPlayerNodeInfo, XN_STATUS_BAD_NODE_NAME); if (!pPlayerNodeInfo->bValid) { XN_ASSERT(FALSE); return XN_STATUS_BAD_NODE_NAME; } nFrames = pPlayerNodeInfo->nFrames; return XN_STATUS_OK; }
XnStatus PlayerNode::TellFrame(const XnChar* strNodeName, XnUInt32& nFrameNumber) { PlayerNodeInfo* pPlayerNodeInfo = GetPlayerNodeInfoByName(strNodeName); XN_VALIDATE_PTR(pPlayerNodeInfo, XN_STATUS_BAD_NODE_NAME); if (!pPlayerNodeInfo->bValid) { XN_ASSERT(FALSE); return XN_STATUS_BAD_NODE_NAME; } nFrameNumber = pPlayerNodeInfo->nCurFrame; return XN_STATUS_OK; }
XnStatus RecorderImpl::WriteFileImpl(const XnChar* strNodeName, const void* pData, XnUInt32 nSize) { //strNodeName may be NULL XN_VALIDATE_PTR(m_pOutFile, XN_STATUS_ERROR); size_t nBytesWritten = fwrite(pData, 1, nSize, m_pOutFile); if (nBytesWritten < nSize) { xnLogWarning(XN_MASK_OPEN_NI, "Written only %u bytes out of %u to file", nBytesWritten, nSize); return XN_STATUS_OS_FILE_WRITE_FAILED; } return XN_STATUS_OK; }
//--------------------------------------------------------------------------- // Code //--------------------------------------------------------------------------- XN_C_API XnStatus xnOSCreateThread(XN_THREAD_PROC_PROTO pThreadProc, const XN_THREAD_PARAM pThreadParam, XN_THREAD_HANDLE* pThreadHandle) { // Validate the input/output pointers (to make sure none of them is NULL) XN_VALIDATE_INPUT_PTR(pThreadProc); XN_VALIDATE_OUTPUT_PTR(pThreadHandle); // Create a thread via the OS *pThreadHandle = CreateThread(NULL, 0, pThreadProc, pThreadParam, 0, NULL); // Make sure it succeeded (return value is not null) XN_VALIDATE_PTR(*pThreadHandle, XN_STATUS_OS_THREAD_CREATION_FAILED); // All is good... return (XN_STATUS_OK); }
XN_C_API XnStatus xnOSGetProcAddress(const XN_LIB_HANDLE LibHandle, const XnChar* cpProcName, XnFarProc* pProcAddr) { // Validate the input/output pointers (to make sure none of them is NULL) XN_VALIDATE_INPUT_PTR(cpProcName); XN_VALIDATE_OUTPUT_PTR(pProcAddr); // Make sure the actual shared library handle isn't NULL XN_RET_IF_NULL(LibHandle, XN_STATUS_OS_INVALID_LIBRARY); // Get the requested procedure address from the shared library via the OS *pProcAddr = GetProcAddress(LibHandle, cpProcName); // Make sure it succeeded (return value is not NULL). If not return an error.... XN_VALIDATE_PTR(*pProcAddr, XN_STATUS_OS_PROC_NOT_FOUND); // All is good... return (XN_STATUS_OK); }
ONI_C_API OniStatus oniRegisterDeviceCallbacks(OniDeviceCallbacks* pCallbacks, void* pCookie, OniCallbackHandle* pHandle) { g_Context.clearErrorLogger(); DeviceHandles* pDeviceHandles = XN_NEW(DeviceHandles); XN_VALIDATE_PTR(pDeviceHandles, ONI_STATUS_ERROR); pDeviceHandles->deviceConnectedHandle = NULL; pDeviceHandles->deviceDisconnectedHandle = NULL; pDeviceHandles->deviceStateChangedHandle = NULL; pDeviceHandles->pCookie = pCookie; g_Context.registerDeviceConnectedCallback(pCallbacks->deviceConnected, pCookie, pDeviceHandles->deviceConnectedHandle); g_Context.registerDeviceDisconnectedCallback(pCallbacks->deviceDisconnected, pCookie, pDeviceHandles->deviceDisconnectedHandle); g_Context.registerDeviceStateChangedCallback(pCallbacks->deviceStateChanged, pCookie, pDeviceHandles->deviceStateChangedHandle); *pHandle = (OniCallbackHandle)pDeviceHandles; return ONI_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; }
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; }
XnStatus PlayerNode::HandleNodeAddedImpl(XnUInt32 nNodeID, XnProductionNodeType type, const XnChar* strName, XnCodecID compression, XnUInt32 nNumberOfFrames, XnUInt64 nMinTimestamp, XnUInt64 nMaxTimestamp) { XN_VALIDATE_INPUT_PTR(m_pNodeNotifications); XnStatus nRetVal = XN_STATUS_OK; PlayerNodeInfo* pPlayerNodeInfo = GetPlayerNodeInfo(nNodeID); XN_VALIDATE_PTR(pPlayerNodeInfo, XN_STATUS_CORRUPT_FILE); //Notify node was added nRetVal = m_pNodeNotifications->OnNodeAdded(m_pNotificationsCookie, strName, type, compression); XN_IS_STATUS_OK(nRetVal); pPlayerNodeInfo->compression = compression; nRetVal = xnOSStrCopy(pPlayerNodeInfo->strName, strName, sizeof(pPlayerNodeInfo->strName)); XN_IS_STATUS_OK(nRetVal); if (xnIsTypeGenerator(type)) { pPlayerNodeInfo->bIsGenerator = TRUE; pPlayerNodeInfo->nFrames = nNumberOfFrames; pPlayerNodeInfo->nMaxTimeStamp = nMaxTimestamp; } //Mark this player node as valid pPlayerNodeInfo->bValid = TRUE; //Loop until this node's state is ready. //TODO: Check for eof while (!pPlayerNodeInfo->bStateReady) { nRetVal = ProcessRecord(TRUE); if (nRetVal != XN_STATUS_OK) { pPlayerNodeInfo->bValid = FALSE; return nRetVal; } } return (XN_STATUS_OK); }
ONI_C_API OniStatus oniStreamRegisterNewFrameCallback(OniStreamHandle stream, OniNewFrameCallback handler, void* pCookie, OniCallbackHandle* pHandle) { g_Context.clearErrorLogger(); if (*pHandle != NULL) { // Already registered to something g_Context.addToLogger("Can't register same listener instance to multiple events"); return ONI_STATUS_ERROR; } OniNewFrameCookie* pNewFrameCookie = XN_NEW(OniNewFrameCookie); XN_VALIDATE_PTR(pNewFrameCookie, ONI_STATUS_ERROR); pNewFrameCookie->streamHandle = stream; pNewFrameCookie->handler = handler; pNewFrameCookie->pCookie = pCookie; *pHandle = (OniCallbackHandle)pNewFrameCookie; return stream->pStream->registerNewFrameCallback(OniNewFrameTranslationHandler, pNewFrameCookie, &(pNewFrameCookie->handle)); }
XnStatus PlayerNode::HandleNodeDataBeginRecord(NodeDataBeginRecord record) { XN_VALIDATE_INPUT_PTR(m_pNodeNotifications); XnStatus nRetVal = record.Decode(); XN_IS_STATUS_OK(nRetVal); DEBUG_LOG_RECORD(record, "NodeDataBegin"); PlayerNodeInfo* pPlayerNodeInfo = GetPlayerNodeInfo(record.GetNodeID()); XN_VALIDATE_PTR(pPlayerNodeInfo, XN_STATUS_CORRUPT_FILE); if (!pPlayerNodeInfo->bValid) { XN_ASSERT(FALSE); return XN_STATUS_CORRUPT_FILE; } if (!pPlayerNodeInfo->bIsGenerator) { XN_ASSERT(FALSE); XN_LOG_ERROR_RETURN(XN_STATUS_CORRUPT_FILE, XN_MASK_OPEN_NI, "Got data for non-generator node '%s'", pPlayerNodeInfo->strName); } m_bDataBegun = TRUE; return XN_STATUS_OK; }
XN_C_API XnModuleNodeHandle xnGetModuleNodeHandle(XnNodeHandle hNode) { XN_VALIDATE_PTR(hNode, NULL); return hNode->pModuleInstance->hNode; }
XnUInt32 PlayerImpl::TellFileImpl() { XN_VALIDATE_PTR(m_pInFile, (XnUInt32)-1); return ftell(m_pInFile); }
XnStatus PlayerNode::HandleNewDataRecord(NewDataRecordHeader record, XnBool bReadPayload) { XN_VALIDATE_INPUT_PTR(m_pNodeNotifications); XnStatus nRetVal = record.Decode(); XN_IS_STATUS_OK(nRetVal); DEBUG_LOG_RECORD(record, "NewData"); XN_ASSERT(record.GetNodeID() != INVALID_NODE_ID); PlayerNodeInfo* pPlayerNodeInfo = GetPlayerNodeInfo(record.GetNodeID()); XN_VALIDATE_PTR(pPlayerNodeInfo, XN_STATUS_CORRUPT_FILE); if (!pPlayerNodeInfo->bValid) { XN_ASSERT(FALSE); return XN_STATUS_CORRUPT_FILE; } XnUInt32 nRecordTotalSize = record.GetSize() + record.GetPayloadSize(); if (nRecordTotalSize > RECORD_MAX_SIZE) { XN_ASSERT(FALSE); XN_LOG_ERROR_RETURN(XN_STATUS_INTERNAL_BUFFER_TOO_SMALL, XN_MASK_OPEN_NI, "Record size %u is larger than player internal buffer", nRecordTotalSize); } pPlayerNodeInfo->nLastDataPos = TellStream() - record.GetSize(); pPlayerNodeInfo->newDataUndoInfo.nRecordPos = pPlayerNodeInfo->nLastDataPos; pPlayerNodeInfo->newDataUndoInfo.nUndoRecordPos = record.GetUndoRecordPos(); if (record.GetFrameNumber() > pPlayerNodeInfo->nFrames) { XN_ASSERT(FALSE); return XN_STATUS_CORRUPT_FILE; } pPlayerNodeInfo->nCurFrame = record.GetFrameNumber(); if (record.GetTimeStamp() > m_nGlobalMaxTimeStamp) { XN_ASSERT(FALSE); XN_LOG_ERROR_RETURN(XN_STATUS_CORRUPT_FILE, XN_MASK_OPEN_NI, "Record timestamp for record in position %u is larger than reported max timestamp", pPlayerNodeInfo->nLastDataPos); } m_nTimeStamp = record.GetTimeStamp(); if (bReadPayload) { //Now read the actual data XnUInt32 nBytesRead = 0; nRetVal = Read(record.GetPayload(), record.GetPayloadSize(), nBytesRead); XN_IS_STATUS_OK(nRetVal); if (nBytesRead < record.GetPayloadSize()) { XN_LOG_ERROR_RETURN(XN_STATUS_CORRUPT_FILE, XN_MASK_OPEN_NI, "Not enough bytes read"); } const XnUInt8* pCompressedData = record.GetPayload(); //The new (compressed) data is right at the end of the header XnUInt32 nCompressedDataSize = record.GetPayloadSize(); const XnUInt8* pUncompressedData = NULL; XnUInt32 nUncompressedDataSize = 0; XnCodecID compression = pPlayerNodeInfo->codec.GetCodecID(); if (compression == XN_CODEC_UNCOMPRESSED) { pUncompressedData = pCompressedData; nUncompressedDataSize = nCompressedDataSize; } else { //Decode data with codec nRetVal = pPlayerNodeInfo->codec.DecodeData(pCompressedData, nCompressedDataSize, m_pUncompressedData, DATA_MAX_SIZE, &nUncompressedDataSize); XN_IS_STATUS_OK(nRetVal); pUncompressedData = m_pUncompressedData; } nRetVal = m_pNodeNotifications->OnNodeNewData(m_pNotificationsCookie, pPlayerNodeInfo->strName, record.GetTimeStamp(), record.GetFrameNumber(), pUncompressedData, nUncompressedDataSize); XN_IS_STATUS_OK(nRetVal); } else { //Just skip the data nRetVal = SkipRecordPayload(record); XN_IS_STATUS_OK(nRetVal); } return XN_STATUS_OK; }
XnUInt32 PlayerNode::TellStream() { XN_VALIDATE_PTR(m_pInputStream, (XnUInt32)-1); return m_pInputStream->Tell(m_pStreamCookie); }
XnUInt32 XN_CALLBACK_TYPE PlayerImpl::TellFile(void* pCookie) { PlayerImpl* pThis = (PlayerImpl*)pCookie; XN_VALIDATE_PTR(pThis, (XnUInt32)-1); return pThis->TellFileImpl(); }
XnStatus PlayerNode::HandleGeneralPropRecord(GeneralPropRecord record) { XN_VALIDATE_INPUT_PTR(m_pNodeNotifications); XnStatus nRetVal = record.Decode(); XN_IS_STATUS_OK(nRetVal); DEBUG_LOG_RECORD(record, "GeneralProp"); PlayerNodeInfo* pPlayerNodeInfo = GetPlayerNodeInfo(record.GetNodeID()); XN_VALIDATE_PTR(pPlayerNodeInfo, XN_STATUS_CORRUPT_FILE); if (!pPlayerNodeInfo->bValid) { XN_ASSERT(FALSE); return XN_STATUS_CORRUPT_FILE; } // Fix backwards compatibility issues if (strcmp(record.GetPropName(), XN_PROP_REAL_WORLD_TRANSLATION_DATA) == 0) { // old recordings held the RealWorldTranslationData, but API has changed. Translate // it to Field Of View if (record.GetPropDataSize() != sizeof(XnRealWorldTranslationData)) { return XN_STATUS_CORRUPT_FILE; } const XnRealWorldTranslationData* pTransData = (const XnRealWorldTranslationData*)record.GetPropData(); // we also need resolution for the translation xn::DepthGenerator depthGen; nRetVal = m_context.GetProductionNodeByName(pPlayerNodeInfo->strName, depthGen); XN_IS_STATUS_OK(nRetVal); XnMapOutputMode outputMode; nRetVal = depthGen.GetMapOutputMode(outputMode); XN_IS_STATUS_OK(nRetVal); XnFieldOfView FOV; FOV.fHFOV = 2*atan(pTransData->dPixelSizeAtZeroPlane * pTransData->dSourceToDepthPixelRatio * outputMode.nXRes / 2 / pTransData->dZeroPlaneDistance); FOV.fVFOV = 2*atan(pTransData->dPixelSizeAtZeroPlane * pTransData->dSourceToDepthPixelRatio * outputMode.nYRes / 2 / pTransData->dZeroPlaneDistance); nRetVal = m_pNodeNotifications->OnNodeGeneralPropChanged(m_pNotificationsCookie, pPlayerNodeInfo->strName, XN_PROP_FIELD_OF_VIEW, sizeof(FOV), &FOV); XN_IS_STATUS_OK(nRetVal); } else { nRetVal = m_pNodeNotifications->OnNodeGeneralPropChanged(m_pNotificationsCookie, pPlayerNodeInfo->strName, record.GetPropName(), record.GetPropDataSize(), record.GetPropData()); XN_IS_STATUS_OK(nRetVal); } nRetVal = SaveRecordUndoInfo(pPlayerNodeInfo, record.GetPropName(), TellStream() - record.GetSize(), record.GetUndoRecordPos()); XN_IS_STATUS_OK(nRetVal); return XN_STATUS_OK; }