1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
|
/****************************************************************************
* *
* PrimeSense Sensor 5.x Alpha *
* Copyright (C) 2011 PrimeSense Ltd. *
* *
* This file is part of PrimeSense Sensor. *
* *
* PrimeSense Sensor is free software: you can redistribute it and/or modify*
* it under the terms of the GNU Lesser General Public License as published *
* by the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* PrimeSense Sensor is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with PrimeSense Sensor. If not, see <http://www.gnu.org/licenses/>.*
* *
****************************************************************************/
#ifndef __XN_FRAME_STREAM_PROCESSOR_H__
#define __XN_FRAME_STREAM_PROCESSOR_H__
//---------------------------------------------------------------------------
// Includes
//---------------------------------------------------------------------------
#include "XnStreamProcessor.h"
#include <XnDDK/XnFrameStream.h>
//---------------------------------------------------------------------------
// Code
//---------------------------------------------------------------------------
/*
* A processor for streams that are frame-based.
*/
class XnFrameStreamProcessor : public XnStreamProcessor
{
public:
/*
* Initializes a new frame-stream-processor.
*
* @param pDevicePrivateData [in] A pointer to the device.
* @param csName [in] Name of this stream.
* @param nTypeSOF [in] The packet type that signifies start-of-frame.
* @param nTypeEOF [in] The packet type that signifies end-of-frame.
*/
XnFrameStreamProcessor(XnFrameStream* pStream, XnSensorStreamHelper* pHelper, XnUInt16 nTypeSOF, XnUInt16 nTypeEOF);
/**
* Destroys a frame-based stream processor
*/
virtual ~XnFrameStreamProcessor();
protected:
//---------------------------------------------------------------------------
// Overridden Functions
//---------------------------------------------------------------------------
virtual void ProcessPacketChunk(const XnSensorProtocolResponseHeader* pHeader, const XnUChar* pData, XnUInt32 nDataOffset, XnUInt32 nDataSize);
virtual void OnPacketLost();
//---------------------------------------------------------------------------
// New Virtual Functions
//---------------------------------------------------------------------------
/*
* Called when a frame starts.
*
* @param pHeader [in] Header for current packet.
*/
virtual void OnStartOfFrame(const XnSensorProtocolResponseHeader* pHeader);
/*
* Called for every chunk received
*
* @param pHeader [in] A pointer to current packet header.
* @param pData [in] A pointer to the data.
* @param nDataOffset [in] The offset of this data chunk inside current packet.
* @param nDataSize [in] Size of the data in bytes.
*/
virtual void ProcessFramePacketChunk(const XnSensorProtocolResponseHeader* pHeader, const XnUChar* pData, XnUInt32 nDataOffset, XnUInt32 nDataSize) = 0;
/*
* Called when a frame ends.
*
* @param pHeader [in] Header for current packet.
*/
virtual void OnEndOfFrame(const XnSensorProtocolResponseHeader* pHeader);
/*
* Called when a frame is ready for reading.
*
* @param nFrameID [in] ID of this frame.
* @param nFrameTS [in] Timestamp of this frame.
*/
virtual void OnFrameReady(XnUInt32 /*nFrameID*/, XnUInt64 /*nFrameTS*/) {}
//---------------------------------------------------------------------------
// Utility Functions
//---------------------------------------------------------------------------
inline XnFrameStream* GetStream()
{
return (XnFrameStream*)XnStreamProcessor::GetStream();
}
/*
* Gets the expected output size.
*/
inline XnUInt32 GetExpectedOutputSize()
{
return GetStream()->GetRequiredDataSize();
}
/*
* Gets current write buffer.
*/
inline XnBuffer* GetWriteBuffer()
{
return m_pTripleBuffer->GetWriteBuffer();
}
/*
* Gets current frame ID (for logging purposes mainly).
*/
inline XnUInt32 GetCurrentFrameID()
{
return m_pTripleBuffer->GetLastFrameID();
}
/*
* Notifies that write buffer has overflowed, logging a warning and reseting it.
*/
void WriteBufferOverflowed();
/*
* Checks if write buffer has overflowed, if so, a log will be issued and buffer will reset.
*/
inline XnBool CheckWriteBufferForOverflow(XnUInt32 nWriteSize)
{
if (GetWriteBuffer()->GetFreeSpaceInBuffer() < nWriteSize)
{
WriteBufferOverflowed();
return FALSE;
}
return TRUE;
}
/*
* Marks current frame as corrupted.
*/
void FrameIsCorrupted();
void SetAllowDoubleSOFPackets(XnBool bAllow) { m_bAllowDoubleSOF = bAllow; }
private:
//---------------------------------------------------------------------------
// Class Members
//---------------------------------------------------------------------------
/* The type of start-of-frame packet. */
XnUInt16 m_nTypeSOF;
/* The type of end-of-frame packet. */
XnUInt16 m_nTypeEOF;
/* A pointer to the triple frame buffer of this stream. */
XnFrameBufferManager* m_pTripleBuffer;
XnChar m_csInDumpMask[100];
XnChar m_csInternalDumpMask[100];
XnDumpFile* m_InDump;
XnDumpFile* m_InternalDump;
XnBool m_bFrameCorrupted;
XnBool m_bAllowDoubleSOF;
XnUInt16 m_nLastSOFPacketID;
};
#endif //__XN_FRAME_STREAM_PROCESSOR_H__
|