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 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389
|
/*****************************************************************************
* *
* OpenNI 2.x Alpha *
* Copyright (C) 2012 PrimeSense Ltd. *
* *
* This file is part of OpenNI. *
* *
* Licensed under the Apache License, Version 2.0 (the "License"); *
* you may not use this file except in compliance with the License. *
* You may obtain a copy of the License at *
* *
* http://www.apache.org/licenses/LICENSE-2.0 *
* *
* Unless required by applicable law or agreed to in writing, software *
* distributed under the License is distributed on an "AS IS" BASIS, *
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
* See the License for the specific language governing permissions and *
* limitations under the License. *
* *
*****************************************************************************/
#ifndef __DATA_RECORDS_H__
#define __DATA_RECORDS_H__
#include "XnPlatform.h"
#include "XnStatus.h"
#include "XnPlayerTypes.h"
#pragma pack(push, 1)
#define HEADER_MAGIC_SIZE 4
enum RecordType
{
RECORD_NODE_ADDED_1_0_0_4 = 0x02,
RECORD_INT_PROPERTY = 0x03,
RECORD_REAL_PROPERTY = 0x04,
RECORD_STRING_PROPERTY = 0x05,
RECORD_GENERAL_PROPERTY = 0x06,
RECORD_NODE_REMOVED = 0x07,
RECORD_NODE_DATA_BEGIN = 0x08,
RECORD_NODE_STATE_READY = 0x09,
RECORD_NEW_DATA = 0x0A,
RECORD_END = 0x0B,
RECORD_NODE_ADDED_1_0_0_5 = 0x0C,
RECORD_NODE_ADDED = 0x0D,
RECORD_SEEK_TABLE = 0x0E,
};
#define INVALID_NODE_ID ((XnUInt32)-1)
#define INVALID_TIMESTAMP ((XnUInt64)-1)
struct RecordingHeader
{
XnChar headerMagic[HEADER_MAGIC_SIZE];
XnVersion version;
XnUInt64 nGlobalMaxTimeStamp;
XnUInt32 nMaxNodeID;
};
extern const RecordingHeader DEFAULT_RECORDING_HEADER;
class Record
{
public:
Record(XnUInt8* pData, XnSizeT nMaxSize, XnBool bUseOld32Header);
Record(const Record &other);
RecordType GetType() const;
XnUInt32 GetNodeID() const;
XnUInt32 GetSize() const; //GetSize() returns just the fields' size, not including the payload
XnUInt32 GetPayloadSize() const;
XnUInt64 GetUndoRecordPos() const;
void SetNodeID(XnUInt32 nNodeID);
void SetPayloadSize(XnUInt32 nPayloadSize);
void SetUndoRecordPos(XnUInt64 nUndoRecordPos);
XnUInt8* GetData(); //GetData() returns the entire encoded record
const XnUInt8* GetData() const; //GetData() returns the entire encoded record
void SetData(XnUInt8* pData, XnUInt32 nMaxSize);
XnUInt8* GetPayload(); //GetPayload() returns just the payload part of the record (after the fields)
const XnUInt8* GetPayload() const;
const XnUInt8* GetReadPos() const;
XnBool IsHeaderValid() const;
void ResetRead();
XnStatus AsString(XnChar* strDest, XnUInt32 nSize, XnUInt32& nCharsWritten);
protected:
const XnUInt8* GetWritePos() const;
XnStatus StartWrite(XnUInt32 nRecordType);
XnStatus Write(const void* pData, XnUInt32 nSize);
XnStatus WriteString(const XnChar* str);
XnStatus FinishWrite();
XnStatus StartRead();
//Copies the data to the specified output buffer
XnStatus Read(void* pData, XnUInt32 nSize) const;
//Gives a pointer to the string in the current position, and advances that position till after the string.
XnStatus ReadString(const XnChar*& strDest) const;
XnStatus FinishRead();
private:
struct Header_old32
{
XnUInt32 m_nMagic;
XnUInt32 m_nRecordType;
XnUInt32 m_nNodeID;
XnUInt32 m_nFieldsSize;
XnUInt32 m_nPayloadSize;
XnUInt32 m_nUndoRecordPos;
};
struct Header
{
XnUInt32 m_nMagic;
XnUInt32 m_nRecordType;
XnUInt32 m_nNodeID;
XnUInt32 m_nFieldsSize;
XnUInt32 m_nPayloadSize;
XnUInt64 m_nUndoRecordPos;
};
union
{
Header* m_pHeader;
XnUInt8* m_pData;
};
static const XnUInt32 MAGIC;
mutable XnUInt32 m_nReadOffset;
XnUInt32 m_nMaxSize;
protected:
enum {HEADER_SIZE_current = sizeof(Header),
HEADER_SIZE_old32 = sizeof(Header_old32)};
XnBool m_bUseOld32Header;
public:
XnUInt32 HEADER_SIZE;
};
class NodeAdded_1_0_0_4_Record : public Record
{
public:
NodeAdded_1_0_0_4_Record(XnUInt8* pData, XnUInt32 nMaxSize, XnBool bUseOld32Header);
NodeAdded_1_0_0_4_Record(const Record& record);
void SetNodeName(const XnChar* strNodeName);
void SetNodeType(XnProductionNodeType type);
void SetCompression(XnCodecID compression);
const XnChar* GetNodeName() const;
XnProductionNodeType GetNodeType() const;
XnCodecID GetCompression() const;
XnStatus Encode();
XnStatus Decode();
XnStatus AsString(XnChar* strDest, XnUInt32 nSize, XnUInt32& nCharsWritten);
protected:
XnStatus EncodeImpl();
XnStatus DecodeImpl();
private:
const XnChar* m_strNodeName;
XnProductionNodeType m_type;
XnCodecID m_compression;
};
class NodeAdded_1_0_0_5_Record : public NodeAdded_1_0_0_4_Record
{
public:
NodeAdded_1_0_0_5_Record(XnUInt8* pData, XnUInt32 nMaxSize, XnBool bUseOld32Header);
NodeAdded_1_0_0_5_Record(const Record& record);
void SetNumberOfFrames(XnUInt32 nNumberOfFrames);
void SetMinTimestamp(XnUInt64 nMinTimestamp);
void SetMaxTimestamp(XnUInt64 nMaxTimestamp);
XnUInt32 GetNumberOfFrames() const;
XnUInt64 GetMinTimestamp() const;
XnUInt64 GetMaxTimestamp() const;
XnStatus Encode();
XnStatus Decode();
XnStatus AsString(XnChar* strDest, XnUInt32 nSize, XnUInt32& nCharsWritten);
protected:
XnStatus EncodeImpl();
XnStatus DecodeImpl();
private:
XnUInt32 m_nNumberOfFrames;
XnUInt64 m_nMinTimestamp;
XnUInt64 m_nMaxTimestamp;
};
class NodeAddedRecord : public NodeAdded_1_0_0_5_Record
{
public:
NodeAddedRecord(XnUInt8* pData, XnUInt32 nMaxSize, XnBool bUseOld32Header);
NodeAddedRecord(const Record& record);
void SetSeekTablePosition(XnUInt64 nPos);
XnUInt64 GetSeekTablePosition();
XnStatus Encode();
XnStatus Decode();
XnStatus AsString(XnChar* strDest, XnUInt32 nSize, XnUInt32& nCharsWritten);
private:
XnUInt64 m_nSeekTablePosition;
};
class NodeRemovedRecord : public Record
{
public:
NodeRemovedRecord(XnUInt8* pData, XnUInt32 nMaxSize, XnBool bUseOld32Header);
NodeRemovedRecord(const Record& record);
XnStatus Encode();
XnStatus Decode();
XnStatus AsString(XnChar* strDest, XnUInt32 nSize, XnUInt32& nCharsWritten);
};
class GeneralPropRecord : public Record
{
public:
GeneralPropRecord(XnUInt8* pData, XnUInt32 nMaxSize, XnBool bUseOld32Header, XnUInt32 nPropRecordType = RECORD_GENERAL_PROPERTY);
GeneralPropRecord(const Record& record);
void SetPropName(const XnChar* strPropName);
void SetPropDataSize(XnUInt32 nPropDataSize);
void SetPropData(const void* pPropData);
const XnChar* GetPropName() const;
XnUInt32 GetPropDataSize() const;
const void* GetPropData() const;
XnStatus Encode();
XnStatus Decode();
XnStatus AsString(XnChar* strDest, XnUInt32 nSize, XnUInt32& nCharsWritten);
private:
XnUInt32 m_nPropRecordType;
const XnChar* m_strPropName;
XnUInt32 m_nPropDataSize;
void* m_pPropData;
};
class IntPropRecord : public GeneralPropRecord
{
public:
IntPropRecord(XnUInt8* pData, XnUInt32 nMaxSize, XnBool bUseOld32Header);
IntPropRecord(const Record& record);
void SetValue(XnUInt64 nValue);
XnUInt64 GetValue() const;
XnStatus AsString(XnChar* strDest, XnUInt32 nSize, XnUInt32& nCharsWritten);
private:
XnUInt64 m_nValue;
};
class RealPropRecord : public GeneralPropRecord
{
public:
RealPropRecord(XnUInt8* pData, XnUInt32 nMaxSize, XnBool bUseOld32Header);
RealPropRecord(const Record& record);
void SetValue(XnDouble dValue);
XnDouble GetValue() const;
XnStatus AsString(XnChar* strDest, XnUInt32 nSize, XnUInt32& nCharsWritten);
private:
XnDouble m_dValue;
};
class StringPropRecord : public GeneralPropRecord
{
public:
StringPropRecord(XnUInt8* pData, XnUInt32 nMaxSize, XnBool bUseOld32Header);
StringPropRecord(const Record& record);
void SetValue(const XnChar* strValue);
const XnChar* GetValue() const;
XnStatus AsString(XnChar* strDest, XnUInt32 nSize, XnUInt32& nCharsWritten);
};
struct SeekInfo
{
XnUInt32 m_nFrames;
XnUInt64 m_nMaxTimeStamp;
};
class NodeDataBeginRecord : public Record
{
public:
NodeDataBeginRecord(XnUInt8* pData, XnUInt32 nMaxSize, XnBool bUseOld32Header);
NodeDataBeginRecord(const Record& record);
XnUInt32 GetNumFrames() const;
XnUInt64 GetMaxTimeStamp() const;
XnStatus Encode();
XnStatus Decode();
XnStatus AsString(XnChar* strDest, XnUInt32 nSize, XnUInt32& nCharsWritten);
private:
SeekInfo m_seekInfo;
};
class NodeStateReadyRecord : public Record
{
public:
NodeStateReadyRecord(XnUInt8* pData, XnUInt32 nMaxSize, XnBool bUseOld32Header);
NodeStateReadyRecord(const Record& record);
XnStatus Encode();
XnStatus Decode();
XnStatus AsString(XnChar* strDest, XnUInt32 nSize, XnUInt32& nCharsWritten);
};
/*This class represents only the data record HEADER, not the data itself.
This is because we want to be able to read/write the data directly without copying it.*/
class NewDataRecordHeader : public Record
{
public:
enum {MAX_SIZE = Record::HEADER_SIZE_current + //Record header
(XN_MAX_NAME_LENGTH + 1) + //Max node name + terminating null
sizeof(XnUInt64) + //Data timestamp
sizeof(XnUInt32)}; //Frame number
NewDataRecordHeader(XnUInt8* pData, XnUInt32 nMaxSize, XnBool bUseOld32Header);
NewDataRecordHeader(const Record& record);
void SetTimeStamp(XnUInt64 nTimeStamp);
void SetFrameNumber(XnUInt32 nFrameNumber);
XnUInt64 GetTimeStamp() const;
XnUInt32 GetFrameNumber() const;
XnStatus Encode();
XnStatus Decode();
XnStatus AsString(XnChar* strDest, XnUInt32 nSize, XnUInt32& nCharsWritten);
private:
XnUInt64 m_nTimeStamp;
XnUInt32 m_nFrameNumber;
};
typedef struct
{
XnUInt64 nTimestamp;
XnUInt32 nConfigurationID;
XnUInt32 nSeekPos;
} DataIndexEntry_old32;
typedef struct _DataIndexEntry
{
XnUInt64 nTimestamp;
XnUInt32 nConfigurationID;
XnUInt64 nSeekPos;
static void FillFromOld32Entry(struct _DataIndexEntry *newEntry, DataIndexEntry_old32 *old32Entry)
{
newEntry->nTimestamp = old32Entry->nTimestamp;
newEntry->nConfigurationID = old32Entry->nConfigurationID;
newEntry->nSeekPos = old32Entry->nSeekPos;
}
} DataIndexEntry;
class DataIndexRecordHeader : public Record
{
public:
DataIndexRecordHeader(XnUInt8* pData, XnUInt32 nMaxSize, XnBool bUseOld32Header);
DataIndexRecordHeader(const Record& record);
XnStatus Encode();
XnStatus Decode();
XnStatus AsString(XnChar* strDest, XnUInt32 nSize, XnUInt32& nCharsWritten);
};
class EndRecord : public Record
{
public:
EndRecord(XnUInt8* pData, XnUInt32 nMaxSize, XnBool bUseOld32Header);
EndRecord(const Record& record);
XnStatus Encode();
XnStatus Decode();
XnStatus AsString(XnChar* strDest, XnUInt32 nSize, XnUInt32& nCharsWritten);
};
#pragma pack(pop)
#endif //__DATA_RECORDS_H__
|