void XnPacked11DepthProcessor::ProcessFramePacketChunk(const XnSensorProtocolResponseHeader* /*pHeader*/, const XnUChar* pData, XnUInt32 /*nDataOffset*/, XnUInt32 nDataSize) { XN_PROFILING_START_SECTION("XnPacked11DepthProcessor::ProcessFramePacketChunk") XnStatus nRetVal = XN_STATUS_OK; // check if we have data from previous packet if (m_ContinuousBuffer.GetSize() != 0) { // fill in to a whole element XnUInt32 nReadBytes = XN_MIN(nDataSize, XN_INPUT_ELEMENT_SIZE - m_ContinuousBuffer.GetSize()); m_ContinuousBuffer.UnsafeWrite(pData, nReadBytes); pData += nReadBytes; nDataSize -= nReadBytes; if (m_ContinuousBuffer.GetSize() == XN_INPUT_ELEMENT_SIZE) { // process it XnUInt32 nActualRead = 0; Unpack11to16(m_ContinuousBuffer.GetData(), XN_INPUT_ELEMENT_SIZE, &nActualRead); m_ContinuousBuffer.Reset(); } } // find out the number of input elements we have XnUInt32 nActualRead = 0; nRetVal = Unpack11to16(pData, nDataSize, &nActualRead); if (nRetVal == XN_STATUS_OK) { pData += nActualRead; nDataSize -= nActualRead; // if we have any bytes left, store them for next packet. if (nDataSize > 0) { // no need to check for overflow. there can not be a case in which more than XN_INPUT_ELEMENT_SIZE // are left. m_ContinuousBuffer.UnsafeWrite(pData, nDataSize); } } XN_PROFILING_END_SECTION }
int main (int argc, char* argv[]) { struct timespec now; struct timespec later; int size; clock_gettime (CLOCK_REALTIME, &now); for (int h = 0; h < LOOPS; h++) size = Unpack11to16( packedfield, output, sizeof(packedfield)); clock_gettime (CLOCK_REALTIME, &later); double nowtime = (double) (now.tv_sec) + ((double) (now.tv_nsec)) / 1000000000; double latertime = (double) (later.tv_sec) + ((double) (later.tv_nsec)) / 1000000000; printf("%3.3g mus\n", (latertime - nowtime)*1000000/LOOPS); unsigned long nElements = size / XN_INPUT_ELEMENT_SIZE; // floored printf("got %ld elements\n", nElements); for (int i = 0; i < nElements; i++) printf("%d ", output[i]); printf("\n"); }