-
Notifications
You must be signed in to change notification settings - Fork 137
/
Copy pathocidescriptors.cpp
320 lines (268 loc) · 10.3 KB
/
ocidescriptors.cpp
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
/*
* 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 [email protected]
*/
#include "src/impl.h"
namespace mp4v2 {
namespace impl {
///////////////////////////////////////////////////////////////////////////////
MP4ContentClassDescriptor::MP4ContentClassDescriptor(MP4Atom& parentAtom)
: MP4Descriptor(parentAtom)
{
AddProperty( /* 0 */
new MP4Integer32Property(parentAtom, "classificationEntity"));
AddProperty( /* 1 */
new MP4Integer16Property(parentAtom, "classificationTable"));
AddProperty( /* 2 */
new MP4BytesProperty(parentAtom, "contentClassificationData"));
}
void MP4ContentClassDescriptor::Read(MP4File& file)
{
ReadHeader(file);
/* byte properties need to know how long they are before reading */
((MP4BytesProperty*)m_pProperties[2])->SetValueSize(m_size - 6);
ReadProperties(file);
}
MP4KeywordDescriptor::MP4KeywordDescriptor(MP4Atom& parentAtom)
: MP4Descriptor(parentAtom)
{
AddProperty( /* 0 */
new MP4BytesProperty(parentAtom, "languageCode", 3));
AddProperty( /* 1 */
new MP4BitfieldProperty(parentAtom, "isUTF8String", 1));
AddProperty( /* 2 */
new MP4BitfieldProperty(parentAtom, "reserved", 7));
MP4Integer8Property* pCount =
new MP4Integer8Property(parentAtom, "keywordCount");
AddProperty(pCount); /* 3 */
MP4TableProperty* pTable = new MP4TableProperty(parentAtom, "keywords", pCount);
AddProperty(pTable); /* 4 */
pTable->AddProperty( /* 4, 0 */
new MP4StringProperty(pTable->GetParentAtom(), "string", Counted));
SetReadMutate(2);
}
void MP4KeywordDescriptor::Mutate()
{
bool utf8Flag = ((MP4BitfieldProperty*)m_pProperties[1])->GetValue();
MP4Property* pProperty =
((MP4TableProperty*)m_pProperties[4])->GetProperty(0);
ASSERT(pProperty);
((MP4StringProperty*)pProperty)->SetUnicode(!utf8Flag);
}
MP4RatingDescriptor::MP4RatingDescriptor(MP4Atom& parentAtom)
: MP4Descriptor(parentAtom)
{
AddProperty( /* 0 */
new MP4Integer32Property(parentAtom, "ratingEntity"));
AddProperty( /* 1 */
new MP4Integer16Property(parentAtom, "ratingCriteria"));
AddProperty( /* 2 */
new MP4BytesProperty(parentAtom, "ratingInfo"));
}
void MP4RatingDescriptor::Read(MP4File& file)
{
ReadHeader(file);
/* byte properties need to know how long they are before reading */
((MP4BytesProperty*)m_pProperties[2])->SetValueSize(m_size - 6);
ReadProperties(file);
}
MP4LanguageDescriptor::MP4LanguageDescriptor(MP4Atom& parentAtom)
: MP4Descriptor(parentAtom)
{
AddProperty( /* 0 */
new MP4BytesProperty(parentAtom, "languageCode", 3));
}
MP4ShortTextDescriptor::MP4ShortTextDescriptor(MP4Atom& parentAtom)
: MP4Descriptor(parentAtom)
{
AddProperty( /* 0 */
new MP4BytesProperty(parentAtom, "languageCode", 3));
AddProperty( /* 1 */
new MP4BitfieldProperty(parentAtom, "isUTF8String", 1));
AddProperty( /* 2 */
new MP4BitfieldProperty(parentAtom, "reserved", 7));
AddProperty( /* 3 */
new MP4StringProperty(parentAtom, "eventName", Counted));
AddProperty( /* 4 */
new MP4StringProperty(parentAtom, "eventText", Counted));
SetReadMutate(2);
}
void MP4ShortTextDescriptor::Mutate()
{
bool utf8Flag = ((MP4BitfieldProperty*)m_pProperties[1])->GetValue();
((MP4StringProperty*)m_pProperties[3])->SetUnicode(!utf8Flag);
((MP4StringProperty*)m_pProperties[4])->SetUnicode(!utf8Flag);
}
MP4ExpandedTextDescriptor::MP4ExpandedTextDescriptor(MP4Atom& parentAtom)
: MP4Descriptor(parentAtom)
{
AddProperty( /* 0 */
new MP4BytesProperty(parentAtom, "languageCode", 3));
AddProperty( /* 1 */
new MP4BitfieldProperty(parentAtom, "isUTF8String", 1));
AddProperty( /* 2 */
new MP4BitfieldProperty(parentAtom, "reserved", 7));
MP4Integer8Property* pCount =
new MP4Integer8Property(parentAtom, "itemCount");
AddProperty(pCount); /* 3 */
MP4TableProperty* pTable = new MP4TableProperty(parentAtom, "items", pCount);
AddProperty(pTable); /* 4 */
pTable->AddProperty( /* Table 0 */
new MP4StringProperty(pTable->GetParentAtom(), "itemDescription", Counted));
pTable->AddProperty( /* Table 1 */
new MP4StringProperty(pTable->GetParentAtom(), "itemText", Counted));
AddProperty( /* 5 */
new MP4StringProperty(parentAtom, "nonItemText"));
((MP4StringProperty*)m_pProperties[5])->SetExpandedCountedFormat(true);
SetReadMutate(2);
}
void MP4ExpandedTextDescriptor::Mutate()
{
bool utf8Flag = ((MP4BitfieldProperty*)m_pProperties[1])->GetValue();
MP4Property* pProperty =
((MP4TableProperty*)m_pProperties[4])->GetProperty(0);
ASSERT(pProperty);
((MP4StringProperty*)pProperty)->SetUnicode(!utf8Flag);
pProperty = ((MP4TableProperty*)m_pProperties[4])->GetProperty(1);
ASSERT(pProperty);
((MP4StringProperty*)pProperty)->SetUnicode(!utf8Flag);
((MP4StringProperty*)m_pProperties[5])->SetUnicode(!utf8Flag);
}
class MP4CreatorTableProperty : public MP4TableProperty {
public:
MP4CreatorTableProperty(MP4Atom& parentAtom, const char* name, MP4Integer8Property* pCountProperty) :
MP4TableProperty(parentAtom, name, pCountProperty) {
};
protected:
void ReadEntry(MP4File& file, uint32_t index);
void WriteEntry(MP4File& file, uint32_t index);
private:
MP4CreatorTableProperty();
MP4CreatorTableProperty ( const MP4CreatorTableProperty &src );
MP4CreatorTableProperty &operator= ( const MP4CreatorTableProperty &src );
};
MP4CreatorDescriptor::MP4CreatorDescriptor(MP4Atom& parentAtom, uint8_t tag)
: MP4Descriptor(parentAtom, tag)
{
MP4Integer8Property* pCount =
new MP4Integer8Property(parentAtom, "creatorCount");
AddProperty(pCount); /* 0 */
MP4TableProperty* pTable = new MP4CreatorTableProperty(parentAtom, "creators", pCount);
AddProperty(pTable); /* 1 */
pTable->AddProperty( /* Table 0 */
new MP4BytesProperty(pTable->GetParentAtom(), "languageCode", 3, 3));
pTable->AddProperty( /* Table 1 */
new MP4BitfieldProperty(pTable->GetParentAtom(), "isUTF8String", 1));
pTable->AddProperty( /* Table 2 */
new MP4BitfieldProperty(pTable->GetParentAtom(), "reserved", 7));
pTable->AddProperty( /* Table 3 */
new MP4StringProperty(pTable->GetParentAtom(), "name", Counted));
}
void MP4CreatorTableProperty::ReadEntry(MP4File& file, uint32_t index)
{
m_pProperties[0]->Read(file, index);
m_pProperties[1]->Read(file, index);
bool utf8Flag = ((MP4BitfieldProperty*)m_pProperties[1])->GetValue(index);
((MP4StringProperty*)m_pProperties[3])->SetUnicode(!utf8Flag);
m_pProperties[2]->Read(file, index);
m_pProperties[3]->Read(file, index);
}
void MP4CreatorTableProperty::WriteEntry(MP4File& file, uint32_t index)
{
bool utf8Flag = ((MP4BitfieldProperty*)m_pProperties[1])->GetValue(index);
((MP4StringProperty*)m_pProperties[3])->SetUnicode(!utf8Flag);
MP4TableProperty::WriteEntry(file, index);
}
MP4CreationDescriptor::MP4CreationDescriptor(MP4Atom& parentAtom, uint8_t tag)
: MP4Descriptor(parentAtom, tag)
{
AddProperty( /* 0 */
new MP4BitfieldProperty(parentAtom, "contentCreationDate", 40));
}
MP4SmpteCameraDescriptor::MP4SmpteCameraDescriptor(MP4Atom& parentAtom)
: MP4Descriptor(parentAtom)
{
MP4Integer8Property* pCount =
new MP4Integer8Property(parentAtom, "parameterCount");
AddProperty(pCount);
MP4TableProperty* pTable = new MP4TableProperty(parentAtom, "parameters", pCount);
AddProperty(pTable);
pTable->AddProperty(
new MP4Integer8Property(parentAtom, "id"));
pTable->AddProperty(
new MP4Integer32Property(parentAtom, "value"));
}
MP4UnknownOCIDescriptor::MP4UnknownOCIDescriptor(MP4Atom& parentAtom)
: MP4Descriptor(parentAtom)
{
AddProperty( /* 0 */
new MP4BytesProperty(parentAtom, "data"));
}
void MP4UnknownOCIDescriptor::Read(MP4File& file)
{
ReadHeader(file);
/* byte properties need to know how long they are before reading */
((MP4BytesProperty*)m_pProperties[0])->SetValueSize(m_size);
ReadProperties(file);
}
MP4Descriptor* CreateOCIDescriptor(MP4Atom& parentAtom, uint8_t tag)
{
MP4Descriptor* pDescriptor = NULL;
switch (tag) {
case MP4ContentClassDescrTag:
pDescriptor = new MP4ContentClassDescriptor(parentAtom);
break;
case MP4KeywordDescrTag:
pDescriptor = new MP4KeywordDescriptor(parentAtom);
break;
case MP4RatingDescrTag:
pDescriptor = new MP4RatingDescriptor(parentAtom);
break;
case MP4LanguageDescrTag:
pDescriptor = new MP4LanguageDescriptor(parentAtom);
break;
case MP4ShortTextDescrTag:
pDescriptor = new MP4ShortTextDescriptor(parentAtom);
break;
case MP4ExpandedTextDescrTag:
pDescriptor = new MP4ExpandedTextDescriptor(parentAtom);
break;
case MP4ContentCreatorDescrTag:
case MP4OCICreatorDescrTag:
pDescriptor = new MP4CreatorDescriptor(parentAtom, tag);
break;
case MP4ContentCreationDescrTag:
case MP4OCICreationDescrTag:
pDescriptor = new MP4CreationDescriptor(parentAtom, tag);
break;
case MP4SmpteCameraDescrTag:
pDescriptor = new MP4SmpteCameraDescriptor(parentAtom);
break;
}
if (pDescriptor == NULL) {
if (tag >= MP4OCIDescrTagsStart && tag <= MP4OCIDescrTagsEnd) {
pDescriptor = new MP4UnknownOCIDescriptor(parentAtom);
pDescriptor->SetTag(tag);
}
}
return pDescriptor;
}
///////////////////////////////////////////////////////////////////////////////
}
} // namespace mp4v2::impl