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
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
|
/*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (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.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is MPEG4IP.
*
* The Initial Developer of the Original Code is Cisco Systems Inc.
* Portions created by Cisco Systems Inc. are
* Copyright (C) Cisco Systems Inc. 2001. All Rights Reserved.
*
* Contributor(s):
* Dave Mackie dmackie@cisco.com
*/
#ifndef MP4V2_IMPL_MP4PROPERTY_H
#define MP4V2_IMPL_MP4PROPERTY_H
namespace mp4v2 { namespace impl {
///////////////////////////////////////////////////////////////////////////////
// forward declarations
class MP4Atom;
class MP4Descriptor;
MP4ARRAY_DECL(MP4Descriptor, MP4Descriptor*);
enum MP4PropertyType {
Integer8Property,
Integer16Property,
Integer24Property,
Integer32Property,
Integer64Property,
Float32Property,
StringProperty,
BytesProperty,
TableProperty,
DescriptorProperty,
LanguageCodeProperty,
BasicTypeProperty,
};
class MP4Property {
public:
MP4Property(MP4Atom& parentAtom, const char *name = NULL);
virtual ~MP4Property() { }
MP4Atom& GetParentAtom() {
return m_parentAtom;
}
const char *GetName() {
return m_name;
}
virtual MP4PropertyType GetType() = 0;
bool IsReadOnly() {
return m_readOnly;
}
void SetReadOnly(bool value = true) {
m_readOnly = value;
}
bool IsImplicit() {
return m_implicit;
}
void SetImplicit(bool value = true) {
m_implicit = value;
}
virtual uint32_t GetCount() = 0;
virtual void SetCount(uint32_t count) = 0;
virtual void Generate() { /* default is a no-op */ };
virtual void Read(MP4File& file, uint32_t index = 0) = 0;
virtual void Write(MP4File& file, uint32_t index = 0) = 0;
virtual void Dump(uint8_t indent,
bool dumpImplicits, uint32_t index = 0) = 0;
virtual bool FindProperty(const char* name,
MP4Property** ppProperty, uint32_t* pIndex = NULL);
protected:
MP4Atom& m_parentAtom;
const char* m_name;
bool m_readOnly;
bool m_implicit;
private:
MP4Property();
MP4Property ( const MP4Property &src );
MP4Property &operator= ( const MP4Property &src );
};
MP4ARRAY_DECL(MP4Property, MP4Property*);
class MP4IntegerProperty : public MP4Property {
protected:
MP4IntegerProperty(MP4Atom& parentAtom, const char* name)
: MP4Property(parentAtom, name) { };
public:
uint64_t GetValue(uint32_t index = 0);
void SetValue(uint64_t value, uint32_t index = 0);
void InsertValue(uint64_t value, uint32_t index = 0);
void DeleteValue(uint32_t index = 0);
void IncrementValue(int32_t increment = 1, uint32_t index = 0);
private:
MP4IntegerProperty();
MP4IntegerProperty ( const MP4IntegerProperty &src );
MP4IntegerProperty &operator= ( const MP4IntegerProperty &src );
};
#define MP4INTEGER_PROPERTY_DECL2(isize, xsize) \
class MP4Integer##xsize##Property : public MP4IntegerProperty { \
public: \
MP4Integer##xsize##Property(MP4Atom& parentAtom, const char* name) \
: MP4IntegerProperty(parentAtom, name) { \
SetCount(1); \
m_values[0] = 0; \
} \
\
MP4PropertyType GetType() { \
return Integer##xsize##Property; \
} \
\
uint32_t GetCount() { \
return m_values.Size(); \
} \
void SetCount(uint32_t count) { \
m_values.Resize(count); \
} \
\
uint##isize##_t GetValue(uint32_t index = 0) { \
return m_values[index]; \
} \
\
void SetValue(uint##isize##_t value, uint32_t index = 0) { \
if (m_readOnly) { \
ostringstream msg; \
msg << "property is read-only: " << m_name; \
throw new PlatformException(msg.str().c_str(), EACCES, __FILE__, __LINE__, __FUNCTION__); \
} \
m_values[index] = value; \
} \
void AddValue(uint##isize##_t value) { \
m_values.Add(value); \
} \
void InsertValue(uint##isize##_t value, uint32_t index) { \
m_values.Insert(value, index); \
} \
void DeleteValue(uint32_t index) { \
m_values.Delete(index); \
} \
void IncrementValue(int32_t increment = 1, uint32_t index = 0) { \
m_values[index] += increment; \
} \
void Read(MP4File& file, uint32_t index = 0) { \
if (m_implicit) { \
return; \
} \
m_values[index] = file.ReadUInt##xsize(); \
} \
\
void Write(MP4File& file, uint32_t index = 0) { \
if (m_implicit) { \
return; \
} \
file.WriteUInt##xsize(m_values[index]); \
} \
void Dump(uint8_t indent, \
bool dumpImplicits, uint32_t index = 0); \
\
protected: \
MP4Integer##isize##Array m_values; \
private: \
MP4Integer##xsize##Property(); \
MP4Integer##xsize##Property ( const MP4Integer##xsize##Property &src ); \
MP4Integer##xsize##Property &operator= ( const MP4Integer##xsize##Property &src ); \
};
#define MP4INTEGER_PROPERTY_DECL(size) \
MP4INTEGER_PROPERTY_DECL2(size, size)
MP4INTEGER_PROPERTY_DECL(8);
MP4INTEGER_PROPERTY_DECL(16);
MP4INTEGER_PROPERTY_DECL2(32, 24);
MP4INTEGER_PROPERTY_DECL(32);
MP4INTEGER_PROPERTY_DECL(64);
class MP4BitfieldProperty : public MP4Integer64Property {
public:
MP4BitfieldProperty(MP4Atom& parentAtom, const char* name, uint8_t numBits)
: MP4Integer64Property(parentAtom, name) {
ASSERT(numBits != 0);
ASSERT(numBits <= 64);
m_numBits = numBits;
}
uint8_t GetNumBits() {
return m_numBits;
}
void SetNumBits(uint8_t numBits) {
m_numBits = numBits;
}
void Read(MP4File& file, uint32_t index = 0);
void Write(MP4File& file, uint32_t index = 0);
void Dump(uint8_t indent,
bool dumpImplicits, uint32_t index = 0);
protected:
uint8_t m_numBits;
private:
MP4BitfieldProperty();
MP4BitfieldProperty ( const MP4BitfieldProperty &src );
MP4BitfieldProperty &operator= ( const MP4BitfieldProperty &src );
};
class MP4Float32Property : public MP4Property {
public:
MP4Float32Property(MP4Atom& parentAtom, const char* name)
: MP4Property(parentAtom, name) {
m_useFixed16Format = false;
m_useFixed32Format = false;
SetCount(1);
m_values[0] = 0.0;
}
MP4PropertyType GetType() {
return Float32Property;
}
uint32_t GetCount() {
return m_values.Size();
}
void SetCount(uint32_t count) {
m_values.Resize(count);
}
float GetValue(uint32_t index = 0) {
return m_values[index];
}
void SetValue(float value, uint32_t index = 0) {
if (m_readOnly) {
ostringstream msg;
msg << "property is read-only: " << m_name;
throw new PlatformException(msg.str().c_str(), EACCES, __FILE__, __LINE__, __FUNCTION__);
}
m_values[index] = value;
}
void AddValue(float value) {
m_values.Add(value);
}
void InsertValue(float value, uint32_t index) {
m_values.Insert(value, index);
}
bool IsFixed16Format() {
return m_useFixed16Format;
}
void SetFixed16Format(bool useFixed16Format = true) {
m_useFixed16Format = useFixed16Format;
}
bool IsFixed32Format() {
return m_useFixed32Format;
}
void SetFixed32Format(bool useFixed32Format = true) {
m_useFixed32Format = useFixed32Format;
}
void Read(MP4File& file, uint32_t index = 0);
void Write(MP4File& file, uint32_t index = 0);
void Dump(uint8_t indent,
bool dumpImplicits, uint32_t index = 0);
protected:
bool m_useFixed16Format;
bool m_useFixed32Format;
MP4Float32Array m_values;
private:
MP4Float32Property();
MP4Float32Property ( const MP4Float32Property &src );
MP4Float32Property &operator= ( const MP4Float32Property &src );
};
class MP4StringProperty : public MP4Property {
public:
MP4StringProperty(MP4Atom& parentAtom, const char* name,
bool useCountedFormat = false, bool useUnicode = false, bool arrayMode = false);
~MP4StringProperty();
MP4PropertyType GetType() {
return StringProperty;
}
uint32_t GetCount() {
return m_values.Size();
}
void SetCount(uint32_t count);
const char* GetValue(uint32_t index = 0) {
return m_values[index];
}
void SetValue(const char* value, uint32_t index = 0);
void AddValue(const char* value) {
uint32_t count = GetCount();
SetCount(count + 1);
SetValue(value, count);
}
bool IsCountedFormat() {
return m_useCountedFormat;
}
void SetCountedFormat(bool useCountedFormat) {
m_useCountedFormat = useCountedFormat;
}
bool IsExpandedCountedFormat() {
return m_useExpandedCount;
}
void SetExpandedCountedFormat(bool useExpandedCount) {
m_useExpandedCount = useExpandedCount;
}
bool IsUnicode() {
return m_useUnicode;
}
void SetUnicode(bool useUnicode) {
m_useUnicode = useUnicode;
}
uint32_t GetFixedLength() {
return m_fixedLength;
}
void SetFixedLength(uint32_t fixedLength) {
m_fixedLength = fixedLength;
}
void Read(MP4File& file, uint32_t index = 0);
void Write(MP4File& file, uint32_t index = 0);
void Dump(uint8_t indent,
bool dumpImplicits, uint32_t index = 0);
protected:
bool m_arrayMode; // during read/write ignore index and read/write full array
bool m_useCountedFormat;
bool m_useExpandedCount;
bool m_useUnicode;
uint32_t m_fixedLength;
MP4StringArray m_values;
private:
MP4StringProperty();
MP4StringProperty ( const MP4StringProperty &src );
MP4StringProperty &operator= ( const MP4StringProperty &src );
};
class MP4BytesProperty : public MP4Property {
public:
MP4BytesProperty(MP4Atom& parentAtom, const char* name, uint32_t valueSize = 0,
uint32_t defaultValueSize = 0);
~MP4BytesProperty();
MP4PropertyType GetType() {
return BytesProperty;
}
uint32_t GetCount() {
return m_values.Size();
}
void SetCount(uint32_t count);
void GetValue(uint8_t** ppValue, uint32_t* pValueSize,
uint32_t index = 0) {
// N.B. caller must free memory
*ppValue = (uint8_t*)MP4Malloc(m_valueSizes[index]);
memcpy(*ppValue, m_values[index], m_valueSizes[index]);
*pValueSize = m_valueSizes[index];
}
char* GetValueStringAlloc( uint32_t index = 0 ) {
char* buf = (char*)MP4Malloc( m_valueSizes[index] + 1 );
memcpy( buf, m_values[index], m_valueSizes[index] );
buf[m_valueSizes[index]] = '\0';
return buf;
}
bool CompareToString( const string& s, uint32_t index = 0 ) {
return string( (const char*)m_values[index], m_valueSizes[index] ) != s;
}
void CopyValue(uint8_t* pValue, uint32_t index = 0) {
// N.B. caller takes responsbility for valid pointer
// and sufficient memory at the destination
memcpy(pValue, m_values[index], m_valueSizes[index]);
}
void SetValue(const uint8_t* pValue, uint32_t valueSize,
uint32_t index = 0);
void AddValue(const uint8_t* pValue, uint32_t valueSize) {
uint32_t count = GetCount();
SetCount(count + 1);
SetValue(pValue, valueSize, count);
}
uint32_t GetValueSize( uint32_t index = 0 ) {
return m_valueSizes[index];
}
void SetValueSize(uint32_t valueSize, uint32_t index = 0);
uint32_t GetFixedSize() {
return m_fixedValueSize;
}
void SetFixedSize(uint32_t fixedSize);
void Read(MP4File& file, uint32_t index = 0);
void Write(MP4File& file, uint32_t index = 0);
void Dump(uint8_t indent,
bool dumpImplicits, uint32_t index = 0);
protected:
uint32_t m_fixedValueSize;
uint32_t m_defaultValueSize;
MP4Integer32Array m_valueSizes;
MP4BytesArray m_values;
private:
MP4BytesProperty();
MP4BytesProperty ( const MP4BytesProperty &src );
MP4BytesProperty &operator= ( const MP4BytesProperty &src );
};
class MP4TableProperty : public MP4Property {
public:
MP4TableProperty(MP4Atom& parentAtom, const char* name, MP4IntegerProperty* pCountProperty);
~MP4TableProperty();
MP4PropertyType GetType() {
return TableProperty;
}
void AddProperty(MP4Property* pProperty);
MP4Property* GetProperty(uint32_t index) {
return m_pProperties[index];
}
virtual uint32_t GetCount() {
return m_pCountProperty->GetValue();
}
virtual void SetCount(uint32_t count) {
m_pCountProperty->SetValue(count);
}
void Read(MP4File& file, uint32_t index = 0);
void Write(MP4File& file, uint32_t index = 0);
void Dump(uint8_t indent,
bool dumpImplicits, uint32_t index = 0);
bool FindProperty(const char* name,
MP4Property** ppProperty, uint32_t* pIndex = NULL);
protected:
virtual void ReadEntry(MP4File& file, uint32_t index);
virtual void WriteEntry(MP4File& file, uint32_t index);
bool FindContainedProperty(const char* name,
MP4Property** ppProperty, uint32_t* pIndex);
protected:
MP4IntegerProperty* m_pCountProperty;
MP4PropertyArray m_pProperties;
private:
MP4TableProperty();
MP4TableProperty ( const MP4TableProperty &src );
MP4TableProperty &operator= ( const MP4TableProperty &src );
};
class MP4DescriptorProperty : public MP4Property {
public:
MP4DescriptorProperty(MP4Atom& parentAtom, const char* name = NULL,
uint8_t tagsStart = 0, uint8_t tagsEnd = 0,
bool mandatory = false, bool onlyOne = false);
~MP4DescriptorProperty();
MP4PropertyType GetType() {
return DescriptorProperty;
}
void SetParentAtom(MP4Atom* pParentAtom);
void SetSizeLimit(uint64_t sizeLimit) {
m_sizeLimit = sizeLimit;
}
uint32_t GetCount() {
return m_pDescriptors.Size();
}
void SetCount(uint32_t count) {
m_pDescriptors.Resize(count);
}
void SetTags(uint8_t tagsStart, uint8_t tagsEnd = 0) {
m_tagsStart = tagsStart;
m_tagsEnd = tagsEnd ? tagsEnd : tagsStart;
}
MP4Descriptor* AddDescriptor(uint8_t tag);
void AppendDescriptor(MP4Descriptor* pDescriptor) {
m_pDescriptors.Add(pDescriptor);
}
void DeleteDescriptor(uint32_t index);
void Generate();
void Read(MP4File& file, uint32_t index = 0);
void Write(MP4File& file, uint32_t index = 0);
void Dump(uint8_t indent,
bool dumpImplicits, uint32_t index = 0);
bool FindProperty(const char* name,
MP4Property** ppProperty, uint32_t* pIndex = NULL);
protected:
virtual MP4Descriptor* CreateDescriptor(MP4Atom& parentAtom, uint8_t tag);
bool FindContainedProperty(const char* name,
MP4Property** ppProperty, uint32_t* pIndex);
protected:
uint8_t m_tagsStart;
uint8_t m_tagsEnd;
uint64_t m_sizeLimit;
bool m_mandatory;
bool m_onlyOne;
MP4DescriptorArray m_pDescriptors;
private:
MP4DescriptorProperty();
MP4DescriptorProperty ( const MP4DescriptorProperty &src );
MP4DescriptorProperty &operator= ( const MP4DescriptorProperty &src );
};
class MP4QosQualifierProperty : public MP4DescriptorProperty {
public:
MP4QosQualifierProperty(MP4Atom& parentAtom, const char* name = NULL,
uint8_t tagsStart = 0, uint8_t tagsEnd = 0,
bool mandatory = false, bool onlyOne = false) :
MP4DescriptorProperty(parentAtom, name, tagsStart, tagsEnd, mandatory, onlyOne) { }
protected:
MP4Descriptor* CreateDescriptor(MP4Atom& parentAtom, uint8_t tag);
private:
MP4QosQualifierProperty();
MP4QosQualifierProperty ( const MP4QosQualifierProperty &src );
MP4QosQualifierProperty &operator= ( const MP4QosQualifierProperty &src );
};
///////////////////////////////////////////////////////////////////////////////
/// ISO-639-2/T language code.
/// Language codes are 3-alpha (always lowercase) codes which are then
/// offset using 0x60 and packed as 5-bit values into 16-bits, most
/// significant bit is zero-padding.
class MP4LanguageCodeProperty : public MP4Property {
private:
bmff::LanguageCode _value;
public:
explicit MP4LanguageCodeProperty( MP4Atom& parentAtom, const char* , bmff::LanguageCode = bmff::ILC_UND );
MP4LanguageCodeProperty( MP4Atom& parentAtom, const char* , const string& );
MP4PropertyType GetType();
uint32_t GetCount();
void SetCount( uint32_t );
void Read( MP4File&, uint32_t = 0 );
void Write( MP4File&, uint32_t = 0 );
void Dump( uint8_t, bool, uint32_t = 0 );
bmff::LanguageCode GetValue();
void SetValue( bmff::LanguageCode );
private:
MP4LanguageCodeProperty();
MP4LanguageCodeProperty ( const MP4LanguageCodeProperty &src );
MP4LanguageCodeProperty &operator= ( const MP4LanguageCodeProperty &src );
};
///////////////////////////////////////////////////////////////////////////////
class MP4BasicTypeProperty : public MP4Property {
private:
itmf::BasicType _value;
public:
explicit MP4BasicTypeProperty( MP4Atom& parentAtom, const char* , itmf::BasicType = itmf::BT_UNDEFINED );
MP4PropertyType GetType();
uint32_t GetCount();
void SetCount( uint32_t );
void Read( MP4File&, uint32_t = 0 );
void Write( MP4File&, uint32_t = 0 );
void Dump( uint8_t, bool, uint32_t = 0 );
itmf::BasicType GetValue();
void SetValue( itmf::BasicType );
private:
MP4BasicTypeProperty();
MP4BasicTypeProperty ( const MP4BasicTypeProperty &src );
MP4BasicTypeProperty &operator= ( const MP4BasicTypeProperty &src );
};
///////////////////////////////////////////////////////////////////////////////
}} // namespace mp4v2::impl
#endif // MP4V2_IMPL_MP4PROPERTY_H
|