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
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
|
/*
Copyright (c) 2005-2006, John Hurst
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*! \file MXFTypes.h
\version $Id$
\brief MXF objects
*/
#ifndef _MXFTYPES_H_
#define _MXFTYPES_H_
#include "KLV.h"
#include <list>
#include <vector>
#include <map>
#include <wchar.h>
// used with TLVReader::Read*
//
// these are used below to manufacture arguments
#define OBJ_READ_ARGS(s,l) Dict::Type(MDD_##s##_##l), &l
#define OBJ_WRITE_ARGS(s,l) Dict::Type(MDD_##s##_##l), &l
#define OBJ_TYPE_ARGS(t) Dict::Type(MDD_##t).ul
namespace ASDCP
{
namespace MXF
{
typedef std::pair<ui32_t, ui32_t> ItemInfo;
typedef std::map<TagValue, ItemInfo> TagMap;
//
class TLVReader : public ASDCP::MemIOReader
{
TagMap m_ElementMap;
IPrimerLookup* m_Lookup;
TLVReader();
ASDCP_NO_COPY_CONSTRUCT(TLVReader);
bool FindTL(const MDDEntry&);
public:
TLVReader(const byte_t* p, ui32_t c, IPrimerLookup* = 0);
Result_t ReadObject(const MDDEntry&, IArchive*);
Result_t ReadUi8(const MDDEntry&, ui8_t*);
Result_t ReadUi16(const MDDEntry&, ui16_t*);
Result_t ReadUi32(const MDDEntry&, ui32_t*);
Result_t ReadUi64(const MDDEntry&, ui64_t*);
};
//
class TLVWriter : public ASDCP::MemIOWriter
{
TagMap m_ElementMap;
IPrimerLookup* m_Lookup;
TLVWriter();
ASDCP_NO_COPY_CONSTRUCT(TLVWriter);
Result_t WriteTag(const MDDEntry&);
public:
TLVWriter(byte_t* p, ui32_t c, IPrimerLookup* = 0);
Result_t WriteObject(const MDDEntry&, IArchive*);
Result_t WriteUi8(const MDDEntry&, ui8_t*);
Result_t WriteUi16(const MDDEntry&, ui16_t*);
Result_t WriteUi32(const MDDEntry&, ui32_t*);
Result_t WriteUi64(const MDDEntry&, ui64_t*);
};
//
template <class T>
class Batch : public std::vector<T>, public IArchive
{
public:
Batch() {}
~Batch() {}
//
Result_t Unarchive(ASDCP::MemIOReader& Reader) {
ui32_t ItemCount, ItemSize;
Result_t result = Reader.ReadUi32BE(&ItemCount);
if ( ASDCP_SUCCESS(result) )
result = Reader.ReadUi32BE(&ItemSize);
if ( ( ItemCount > 65536 ) || ( ItemSize > 1024 ) )
return RESULT_FAIL;
for ( ui32_t i = 0; i < ItemCount && ASDCP_SUCCESS(result); i++ )
{
T Tmp;
result = Tmp.Unarchive(Reader);
if ( ASDCP_SUCCESS(result) )
push_back(Tmp);
}
return result;
}
inline bool HasValue() const { return ! empty(); }
//
Result_t Archive(ASDCP::MemIOWriter& Writer) const {
Result_t result = Writer.WriteUi32BE(size());
byte_t* p = Writer.CurrentData();
if ( ASDCP_SUCCESS(result) )
result = Writer.WriteUi32BE(0);
if ( ASDCP_FAILURE(result) || empty() )
return result;
typename std::vector<T>::const_iterator l_i = begin();
assert(l_i != end());
ui32_t ItemSize = Writer.Remainder();
result = (*l_i).Archive(Writer);
ItemSize -= Writer.Remainder();
i2p<ui32_t>(ASDCP_i32_BE(ItemSize), p);
l_i++;
for ( ; l_i != end() && ASDCP_SUCCESS(result); l_i++ )
result = (*l_i).Archive(Writer);
return result;
}
//
void Dump(FILE* stream = 0, ui32_t depth = 0)
{
char identbuf[IdentBufferLen];
if ( stream == 0 )
stream = stderr;
typename std::vector<T>::iterator i = this->begin();
for ( ; i != this->end(); i++ )
fprintf(stream, " %s\n", (*i).ToString(identbuf));
}
};
//
template <class T>
class Array : public std::list<T>, public IArchive
{
public:
Array() {}
~Array() {}
//
Result_t Unarchive(ASDCP::MemIOReader& Reader)
{
while ( Reader.Remainder() > 0 )
{
T Tmp;
Tmp.Unarchive(Reader);
push_back(Tmp);
}
return RESULT_OK;
}
inline bool HasValue() const { return ! empty(); }
//
Result_t Archive(ASDCP::MemIOWriter& Writer) const {
Result_t result = RESULT_OK;
typename std::list<T>::const_iterator l_i = begin();
for ( ; l_i != end() && ASDCP_SUCCESS(result); l_i++ )
result = (*l_i).Archive(Writer);
return result;
}
//
void Dump(FILE* stream = 0, ui32_t depth = 0)
{
char identbuf[IdentBufferLen];
if ( stream == 0 )
stream = stderr;
typename std::list<T>::iterator i = this->begin();
for ( ; i != this->end(); i++ )
fprintf(stream, " %s\n", (*i).ToString(identbuf));
}
};
//
class Timestamp : public IArchive
{
public:
ui16_t Year;
ui8_t Month;
ui8_t Day;
ui8_t Hour;
ui8_t Minute;
ui8_t Second;
ui8_t Tick;
Timestamp();
Timestamp(const Timestamp& rhs);
Timestamp(const char* datestr);
virtual ~Timestamp();
const Timestamp& operator=(const Timestamp& rhs);
bool operator<(const Timestamp& rhs) const;
bool operator==(const Timestamp& rhs) const;
bool operator!=(const Timestamp& rhs) const;
// decode and set value from string formatted by EncodeAsString
Result_t SetFromString(const char* datestr);
// add the given number of days or hours to the timestamp value. Values less than zero
// will cause the value to decrease
void AddDays(i32_t);
void AddHours(i32_t);
// Write the timestamp value to the given buffer in the form 2004-05-01 13:20:00.000
// returns 0 if the buffer is smaller than DateTimeLen
const char* ToString(char* str_buf) const;
//
inline Result_t Unarchive(ASDCP::MemIOReader& Reader) {
Result_t result = Reader.ReadUi16BE(&Year);
if ( ASDCP_SUCCESS(result) )
result = Reader.ReadRaw(&Month, 6);
return result;
}
inline bool HasValue() const { return true; }
//
inline Result_t Archive(ASDCP::MemIOWriter& Writer) const {
Result_t result = Writer.WriteUi16BE(Year);
if ( ASDCP_SUCCESS(result) )
result = Writer.WriteRaw(&Month, 6);
return result;
}
};
//
class UTF16String : public IArchive
{
ui16_t m_length;
char m_buffer[IdentBufferLen];
ASDCP_NO_COPY_CONSTRUCT(UTF16String);
public:
UTF16String() : m_length(0) { *m_buffer = 0; }
~UTF16String() {}
const UTF16String& operator=(const char*);
//
const char* ToString(char* str_buf) const {
strncpy(str_buf, m_buffer, m_length+1);
return str_buf;
}
Result_t Unarchive(ASDCP::MemIOReader& Reader);
inline bool HasValue() const { return true; }
Result_t Archive(ASDCP::MemIOWriter& Writer) const;
};
//
class Rational : public ASDCP::Rational, public IArchive
{
public:
Rational() {}
~Rational() {}
Rational(const Rational& rhs) {
Numerator = rhs.Numerator;
Denominator = rhs.Denominator;
}
const Rational& operator=(const Rational& rhs) {
Numerator = rhs.Numerator;
Denominator = rhs.Denominator;
return *this;
}
Rational(const ASDCP::Rational& rhs) {
Numerator = rhs.Numerator;
Denominator = rhs.Denominator;
}
const Rational& operator=(const ASDCP::Rational& rhs) {
Numerator = rhs.Numerator;
Denominator = rhs.Denominator;
return *this;
}
//
const char* ToString(char* str_buf) const {
snprintf(str_buf, IdentBufferLen, "%lu/%lu", Numerator, Denominator);
return str_buf;
}
Result_t Unarchive(ASDCP::MemIOReader& Reader) {
Result_t result = Reader.ReadUi32BE((ui32_t*)&Numerator);
if ( ASDCP_SUCCESS(result) )
result = Reader.ReadUi32BE((ui32_t*)&Denominator);
return result;
}
inline bool HasValue() const { return true; }
Result_t Archive(ASDCP::MemIOWriter& Writer) const {
Result_t result = Writer.WriteUi32BE((ui32_t)Numerator);
if ( ASDCP_SUCCESS(result) )
result = Writer.WriteUi32BE((ui32_t)Denominator);
return result;
}
};
//
class VersionType : public IArchive
{
ASDCP_NO_COPY_CONSTRUCT(VersionType);
public:
enum Release_t { RL_UNKNOWN, RM_RELEASE, RL_DEVELOPMENT, RL_PATCHED, RL_BETA, RL_PRIVATE };
ui16_t Major;
ui16_t Minor;
ui16_t Patch;
ui16_t Build;
ui16_t Release;
VersionType() : Major(0), Minor(0), Patch(0), Build(0), Release(RL_UNKNOWN) {}
~VersionType() {}
void Dump(FILE* = 0);
const char* ToString(char* str_buf) const {
snprintf(str_buf, IdentBufferLen, "%hu.%hu.%hu.%hur%hu", Major, Minor, Patch, Build, Release);
return str_buf;
}
Result_t Unarchive(ASDCP::MemIOReader& Reader) {
Result_t result = Reader.ReadUi16BE(&Major);
if ( ASDCP_SUCCESS(result) ) result = Reader.ReadUi16BE(&Minor);
if ( ASDCP_SUCCESS(result) ) result = Reader.ReadUi16BE(&Patch);
if ( ASDCP_SUCCESS(result) ) result = Reader.ReadUi16BE(&Build);
if ( ASDCP_SUCCESS(result) )
{
ui16_t tmp_release;
result = Reader.ReadUi16BE(&tmp_release);
Release = (Release_t)tmp_release;
}
return result;
}
inline bool HasValue() const { return true; }
Result_t Archive(ASDCP::MemIOWriter& Writer) const {
Result_t result = Writer.WriteUi16BE(Major);
if ( ASDCP_SUCCESS(result) ) result = Writer.WriteUi16BE(Minor);
if ( ASDCP_SUCCESS(result) ) result = Writer.WriteUi16BE(Patch);
if ( ASDCP_SUCCESS(result) ) result = Writer.WriteUi16BE(Build);
if ( ASDCP_SUCCESS(result) ) result = Writer.WriteUi16BE((ui16_t)(Release & 0x0000ffffL));
return result;
}
};
//
class Raw : public ASDCP::FrameBuffer, public IArchive
{
ASDCP_NO_COPY_CONSTRUCT(Raw);
public:
Raw();
~Raw();
//
Result_t Unarchive(ASDCP::MemIOReader& Reader);
inline bool HasValue() const { return true; }
Result_t Archive(ASDCP::MemIOWriter& Writer) const;
const char* ToString(char* str_buf) const;
};
} // namespace MXF
} // namespace ASDCP
#endif //_MXFTYPES_H_
//
// end MXFTypes.h
//
|