2
* The contents of this file are subject to the Mozilla Public
3
* License Version 1.1 (the "License"); you may not use this file
4
* except in compliance with the License. You may obtain a copy of
5
* the License at http://www.mozilla.org/MPL/
7
* Software distributed under the License is distributed on an "AS
8
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
9
* implied. See the License for the specific language governing
10
* rights and limitations under the License.
12
* The Original Code is MPEG4IP.
14
* The Initial Developer of the Original Code is Cisco Systems Inc.
15
* Portions created by Cisco Systems Inc. are
16
* Copyright (C) Cisco Systems Inc. 2001 - 2004. All Rights Reserved.
18
* 3GPP features implementation is based on 3GPP's TS26.234-v5.60,
19
* and was contributed by Ximpo Group Ltd.
21
* Portions created by Ximpo Group Ltd. are
22
* Copyright (C) Ximpo Group Ltd. 2003, 2004. All Rights Reserved.
25
* Dave Mackie dmackie@cisco.com
26
* Ximpo Group Ltd. mp4v2@ximpo.com
29
#ifndef __MP4_ATOM_INCLUDED__
30
#define __MP4_ATOM_INCLUDED__
33
MP4ARRAY_DECL(MP4Atom, MP4Atom*);
36
#define Optional false
47
MP4AtomInfo(const char* name, bool mandatory, bool onlyOne);
55
MP4ARRAY_DECL(MP4AtomInfo, MP4AtomInfo*);
59
MP4Atom(const char* type = NULL);
62
static MP4Atom* ReadAtom(MP4File* pFile, MP4Atom* pParentAtom);
63
static MP4Atom* CreateAtom(const char* type);
64
static bool IsReasonableType(const char* type);
69
void SetFile(MP4File* pFile) {
73
u_int64_t GetStart() {
76
void SetStart(u_int64_t pos) {
83
void SetEnd(u_int64_t pos) {
90
void SetSize(u_int64_t size) {
94
const char* GetType() {
97
void SetType(const char* type) {
98
if (type && *type != '\0') {
99
// not needed ASSERT(strlen(type) == 4);
100
memcpy(m_type, type, 4);
103
memset(m_type, 0, 5);
107
void GetExtendedType(u_int8_t* pExtendedType) {
108
memcpy(pExtendedType, m_extendedType, sizeof(m_extendedType));
110
void SetExtendedType(u_int8_t* pExtendedType) {
111
memcpy(m_extendedType, pExtendedType, sizeof(m_extendedType));
114
bool IsUnknownType() {
115
return m_unknownType;
117
void SetUnknownType(bool unknownType = true) {
118
m_unknownType = unknownType;
122
return m_type[0] == '\0';
125
MP4Atom* GetParentAtom() {
126
return m_pParentAtom;
128
void SetParentAtom(MP4Atom* pParentAtom) {
129
m_pParentAtom = pParentAtom;
132
void AddChildAtom(MP4Atom* pChildAtom) {
133
pChildAtom->SetFile(m_pFile);
134
pChildAtom->SetParentAtom(this);
135
m_pChildAtoms.Add(pChildAtom);
138
void InsertChildAtom(MP4Atom* pChildAtom, u_int32_t index) {
139
pChildAtom->SetFile(m_pFile);
140
pChildAtom->SetParentAtom(this);
141
m_pChildAtoms.Insert(pChildAtom, index);
144
void DeleteChildAtom(MP4Atom* pChildAtom) {
145
for (MP4ArrayIndex i = 0; i < m_pChildAtoms.Size(); i++) {
146
if (m_pChildAtoms[i] == pChildAtom) {
147
m_pChildAtoms.Delete(i);
153
u_int32_t GetNumberOfChildAtoms() {
154
return m_pChildAtoms.Size();
157
MP4Atom* GetChildAtom(u_int32_t index) {
158
return m_pChildAtoms[index];
161
MP4Property* GetProperty(u_int32_t index) {
162
return m_pProperties[index];
165
u_int32_t GetCount() {
166
return m_pProperties.Size();
170
void SetProperty(u_int32_t index, MP4Property *property) {
172
if (index > m_pProperties.Size())
175
t = property->Get(index);
176
m_pProperties[index]->Set(t, index);
180
MP4Atom* FindAtom(const char* name);
182
MP4Atom* FindChildAtom(const char* name);
184
bool FindProperty(const char* name,
185
MP4Property** ppProperty, u_int32_t* pIndex = NULL);
187
u_int32_t GetFlags();
188
void SetFlags(u_int32_t flags);
194
virtual void Generate();
196
virtual void BeginWrite(bool use64 = false);
197
virtual void Write();
198
virtual void Rewrite();
199
virtual void FinishWrite(bool use64 = false);
200
virtual void Dump(FILE* pFile, u_int8_t indent, bool dumpImplicits);
203
void AddProperty(MP4Property* pProperty);
205
void AddVersionAndFlags();
207
void AddReserved(char* name, u_int32_t size);
209
void ExpectChildAtom(const char* name,
210
bool mandatory, bool onlyOne = true);
212
MP4AtomInfo* FindAtomInfo(const char* name);
214
bool IsMe(const char* name);
216
bool FindContainedProperty(const char* name,
217
MP4Property** ppProperty, u_int32_t* pIndex);
220
u_int32_t startIndex = 0, u_int32_t count = 0xFFFFFFFF);
221
void ReadChildAtoms();
223
void WriteProperties(
224
u_int32_t startIndex = 0, u_int32_t count = 0xFFFFFFFF);
225
void WriteChildAtoms();
227
u_int8_t GetVersion();
228
void SetVersion(u_int8_t version);
231
u_int32_t GetVerbosity();
240
u_int8_t m_extendedType[16];
242
MP4Atom* m_pParentAtom;
245
MP4PropertyArray m_pProperties;
246
MP4AtomInfoArray m_pChildAtomInfos;
247
MP4AtomArray m_pChildAtoms;
250
inline u_int32_t ATOMID(const char* type) {
251
return STRTOINT32(type);
254
// inverse ATOMID - 32 bit id to string
255
inline void IDATOM(u_int32_t type, char *s) {
259
#endif /* __MP4_ATOM_INCLUDED__ */