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
|
/****************************************************************************
* *
* 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_DEVICE_STREAM_H__
#define __XN_DEVICE_STREAM_H__
//---------------------------------------------------------------------------
// Includes
//---------------------------------------------------------------------------
#include <XnDDK/XnDeviceModule.h>
#include <XnDDK/XnActualIntProperty.h>
#include <XnDDK/XnActualStringProperty.h>
#include <XnEvent.h>
#include <XnOS.h>
//---------------------------------------------------------------------------
// Types
//---------------------------------------------------------------------------
/** Represents a stream in a device. */
class XN_DDK_CPP_API XnDeviceStream : public XnDeviceModule
{
public:
XnDeviceStream(const XnChar* csType, const XnChar* csName);
~XnDeviceStream() { Free(); }
XnStatus Init();
XnStatus Free();
virtual XnStatus CreateStreamData(XnStreamData** ppStreamData);
/** Reads latest stream info into stream output. */
virtual XnStatus Read(XnStreamData* pStreamData);
/** Writes stream data into stream. */
virtual XnStatus Write(XnStreamData* pStreamData);
/** Checks if new data is available from stream. */
inline XnBool IsNewDataAvailable() const { return m_bNewDataAvailable; }
typedef void (*NewDataCallbackPtr)(XnDeviceStream* pSender, XnUInt64 nTimestamp, XnUInt32 nFrameID, void* pCookie);
/** Sets a function callback to be called when new data is available. */
void SetNewDataCallback(NewDataCallbackPtr pFunc, void* pCookie);
/** Notifies new data is available in this stream. */
virtual void NewDataAvailable(XnUInt64 nTimestamp, XnUInt32 nFrameID);
void ResetLastTimestampAndFrameID();
//---------------------------------------------------------------------------
// Getters
//---------------------------------------------------------------------------
inline const XnChar* GetType() const { return m_Type.GetValue(); }
inline XnBool IsOpen() const { return (XnBool)m_IsOpen.GetValue(); }
inline XnOutputFormats GetOutputFormat() const { return (XnOutputFormats)m_OutputFormat.GetValue(); }
inline XnBool IsMirrored() const { return (XnBool)m_IsMirrored.GetValue(); }
inline XnUInt32 GetRequiredDataSize() const { return (XnUInt32)m_RequiredSize.GetValue(); }
inline XnUInt64 GetLastTimestamp() const { return m_nTimestamp; }
inline XnUInt32 GetLastFrameID() const { return m_nFrameID; }
//---------------------------------------------------------------------------
// Setters
//---------------------------------------------------------------------------
virtual XnStatus Open();
virtual XnStatus Close();
virtual XnStatus SetOutputFormat(XnOutputFormats nOutputFormat);
virtual XnStatus SetMirror(XnBool bIsMirrored);
protected:
//---------------------------------------------------------------------------
// Properties Getters
//---------------------------------------------------------------------------
inline XnActualIntProperty& IsOpenProperty() { return m_IsOpen; }
inline XnActualIntProperty& OutputFormatProperty() { return m_OutputFormat; }
inline XnActualIntProperty& RequiredSizeProperty() { return m_RequiredSize; }
inline XnActualIntProperty& IsMirroredProperty() { return m_IsMirrored; }
inline XN_CRITICAL_SECTION_HANDLE* GetLock() { return &m_hCriticalSection; }
protected:
//---------------------------------------------------------------------------
// Virtual Functions
//---------------------------------------------------------------------------
/** Actually reads data into the stream output object. */
virtual XnStatus ReadImpl(XnStreamData* pStreamOutput) = 0;
/** Actually writes data from the stream output object. */
virtual XnStatus WriteImpl(XnStreamData* pStreamData) = 0;
/** Performs mirror on the given stream output. */
virtual XnStatus Mirror(XnStreamData* pStreamOutput) const = 0;
/** Calculates the required size. */
virtual XnStatus CalcRequiredSize(XnUInt32* pnRequiredSize) const = 0;
//---------------------------------------------------------------------------
// Utility Functions
//---------------------------------------------------------------------------
XnStatus RegisterRequiredSizeProperty(XnProperty* pProperty);
private:
XnStatus UpdateRequiredSize();
static XnStatus XN_CALLBACK_TYPE UpdateRequiredSizeCallback(const XnProperty* pSenser, void* pCookie);
static XnStatus XN_CALLBACK_TYPE SetIsOpenCallback(XnActualIntProperty* pSender, XnUInt64 nValue, void* pCookie);
static XnStatus XN_CALLBACK_TYPE SetOutputFormatCallback(XnActualIntProperty* pSender, XnUInt64 nValue, void* pCookie);
static XnStatus XN_CALLBACK_TYPE SetIsMirrorCallback(XnActualIntProperty* pSender, XnUInt64 nValue, void* pCookie);
//---------------------------------------------------------------------------
// Members
//---------------------------------------------------------------------------
XnActualIntProperty m_IsStream;
XnActualStringProperty m_Type;
XnActualIntProperty m_IsOpen;
XnActualIntProperty m_RequiredSize;
XnActualIntProperty m_OutputFormat;
XnActualIntProperty m_IsMirrored;
/** TRUE if new data is available. */
XnBool m_bNewDataAvailable;
/** Current timestamp of this stream. */
XnUInt64 m_nTimestamp;
/** Current frame id of this stream. */
XnUInt32 m_nFrameID;
NewDataCallbackPtr m_pNewDataCallback;
void* m_pNewDataCallbackCookie;
XN_CRITICAL_SECTION_HANDLE m_hCriticalSection;
};
#endif //__XN_DEVICE_STREAM_H__
|