void XnImageProcessor::OnEndOfFrame(const XnSensorProtocolResponseHeader* pHeader) { XnUInt32 nExpectedSize = CalculateExpectedSize(); if (GetWriteBuffer()->GetSize() != nExpectedSize) { xnLogWarning(XN_MASK_SENSOR_READ, "Read: Image buffer is corrupt. Size is %u (!= %u)", GetWriteBuffer()->GetSize(), nExpectedSize); FrameIsCorrupted(); } // call base XnFrameStreamProcessor::OnEndOfFrame(pHeader); }
void XnFrameStreamProcessor::OnPacketLost() { FrameIsCorrupted(); }
void XnFrameStreamProcessor::WriteBufferOverflowed() { XnBuffer* pBuffer = GetWriteBuffer(); xnLogWarning(XN_MASK_SENSOR_PROTOCOL, "%s Frame Buffer overflow! current size: %d", m_csName, pBuffer->GetSize()); FrameIsCorrupted(); }
void XnPSCompressedDepthProcessor::ProcessFramePacketChunk(const XnSensorProtocolResponseHeader* pHeader, const XnUChar* pData, XnUInt32 nDataOffset, XnUInt32 nDataSize) { XN_PROFILING_START_SECTION("XnPSCompressedDepthProcessor::ProcessFramePacketChunk") XnBuffer* pWriteBuffer = GetWriteBuffer(); const XnUChar* pBuf = NULL; XnUInt32 nBufSize = 0; // check if we have bytes stored from previous calls if (m_RawData.GetSize() > 0) { // we have no choice. We need to append current buffer to previous bytes if (m_RawData.GetFreeSpaceInBuffer() < nDataSize) { xnLogWarning(XN_MASK_SENSOR_PROTOCOL_DEPTH, "Bad overflow depth! %d", m_RawData.GetSize()); FrameIsCorrupted(); } else { m_RawData.UnsafeWrite(pData, nDataSize); } pBuf = m_RawData.GetData(); nBufSize = m_RawData.GetSize(); } else { // we can process the data directly pBuf = pData; nBufSize = nDataSize; } XnUInt32 nOutputSize = pWriteBuffer->GetFreeSpaceInBuffer(); XnUInt32 nWrittenOutput = nOutputSize; XnUInt32 nActualRead = 0; XnBool bLastPart = pHeader->nType == XN_SENSOR_PROTOCOL_RESPONSE_DEPTH_END && (nDataOffset + nDataSize) == pHeader->nBufSize; XnStatus nRetVal = UncompressDepthPS(pBuf, nBufSize, (XnUInt16*)pWriteBuffer->GetUnsafeWritePointer(), &nWrittenOutput, &nActualRead, bLastPart); if (nRetVal != XN_STATUS_OK) { FrameIsCorrupted(); static XnUInt64 nLastPrinted = 0; XnUInt64 nCurrTime; xnOSGetTimeStamp(&nCurrTime); if (nOutputSize != 0 || (nCurrTime - nLastPrinted) > 1000) { xnLogWarning(XN_MASK_SENSOR_PROTOCOL_DEPTH, "Uncompress depth failed: %s. Input Size: %u, Output Space: %u, Last Part: %d.", xnGetStatusString(nRetVal), nBufSize, nOutputSize, bLastPart); xnOSGetTimeStamp(&nLastPrinted); } } pWriteBuffer->UnsafeUpdateSize(nWrittenOutput); nBufSize -= nActualRead; m_RawData.Reset(); // if we have any bytes left, keep them for next time if (nBufSize > 0) { pBuf += nActualRead; m_RawData.UnsafeWrite(pBuf, nBufSize); } XN_PROFILING_END_SECTION }
void XnBayerImageProcessor::ProcessFramePacketChunk(const XnSensorProtocolResponseHeader* pHeader, const XnUChar* pData, XnUInt32 nDataOffset, XnUInt32 nDataSize) { XN_PROFILING_START_SECTION("XnBayerImageProcessor::ProcessFramePacketChunk") // if output format is Gray8, we can write directly to output buffer. otherwise, we need // to write to a temp buffer. XnBuffer* pWriteBuffer = (GetStream()->GetOutputFormat() == XN_OUTPUT_FORMAT_GRAYSCALE8) ? GetWriteBuffer() : &m_UncompressedBayerBuffer; const XnUChar* pBuf = NULL; XnUInt32 nBufSize = 0; // check if we have bytes stored from previous calls if (m_ContinuousBuffer.GetSize() > 0) { // we have no choice. We need to append current buffer to previous bytes if (m_ContinuousBuffer.GetFreeSpaceInBuffer() < nDataSize) { xnLogWarning(XN_MASK_SENSOR_PROTOCOL_DEPTH, "Bad overflow image! %d", m_ContinuousBuffer.GetSize()); FrameIsCorrupted(); } else { m_ContinuousBuffer.UnsafeWrite(pData, nDataSize); } pBuf = m_ContinuousBuffer.GetData(); nBufSize = m_ContinuousBuffer.GetSize(); } else { // we can process the data directly pBuf = pData; nBufSize = nDataSize; } XnUInt32 nOutputSize = pWriteBuffer->GetFreeSpaceInBuffer(); XnUInt32 nWrittenOutput = nOutputSize; XnUInt32 nActualRead = 0; XnBool bLastPart = pHeader->nType == XN_SENSOR_PROTOCOL_RESPONSE_IMAGE_END && (nDataOffset + nDataSize) == pHeader->nBufSize; XnStatus nRetVal = XnStreamUncompressImageNew(pBuf, nBufSize, pWriteBuffer->GetUnsafeWritePointer(), &nWrittenOutput, (XnUInt16)GetActualXRes(), &nActualRead, bLastPart); if (nRetVal != XN_STATUS_OK) { xnLogWarning(XN_MASK_SENSOR_PROTOCOL_IMAGE, "Image decompression failed: %s (%d of %d, requested %d, last %d)", xnGetStatusString(nRetVal), nWrittenOutput, nBufSize, nOutputSize, bLastPart); FrameIsCorrupted(); } pWriteBuffer->UnsafeUpdateSize(nWrittenOutput); nBufSize -= nActualRead; m_ContinuousBuffer.Reset(); // if we have any bytes left, keep them for next time if (nBufSize > 0) { pBuf += nActualRead; m_ContinuousBuffer.UnsafeWrite(pBuf, nBufSize); } XN_PROFILING_END_SECTION }