Mercurial > audlegacy
annotate Plugins/Input/aac/libmp4v2/mp4atom.cpp @ 199:0a2ad94e8607 trunk
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
author | chainsaw |
---|---|
date | Wed, 16 Nov 2005 16:21:11 -0800 |
parents | fa848bd484d8 |
children | f2dc045d2327 |
rev | line source |
---|---|
61 | 1 /* |
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/ | |
6 * | |
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. | |
11 * | |
12 * The Original Code is MPEG4IP. | |
13 * | |
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. | |
17 * | |
18 * 3GPP features implementation is based on 3GPP's TS26.234-v5.60, | |
19 * and was contributed by Ximpo Group Ltd. | |
20 * | |
21 * Portions created by Ximpo Group Ltd. are | |
22 * Copyright (C) Ximpo Group Ltd. 2003, 2004. All Rights Reserved. | |
23 * | |
24 * Contributor(s): | |
25 * Dave Mackie dmackie@cisco.com | |
26 * Alix Marchandise-Franquet alix@cisco.com | |
27 * Ximpo Group Ltd. mp4v2@ximpo.com | |
28 */ | |
29 | |
30 #include "mp4common.h" | |
31 #include "atoms.h" | |
32 | |
33 MP4AtomInfo::MP4AtomInfo(const char* name, bool mandatory, bool onlyOne) | |
34 { | |
35 m_name = name; | |
36 m_mandatory = mandatory; | |
37 m_onlyOne = onlyOne; | |
38 m_count = 0; | |
39 } | |
40 | |
41 MP4Atom::MP4Atom(const char* type) | |
42 { | |
43 SetType(type); | |
44 m_unknownType = FALSE; | |
45 m_pFile = NULL; | |
46 m_start = 0; | |
47 m_end = 0; | |
48 m_size = 0; | |
49 m_pParentAtom = NULL; | |
50 m_depth = 0xFF; | |
51 } | |
52 | |
53 MP4Atom::~MP4Atom() | |
54 { | |
55 u_int32_t i; | |
56 | |
57 for (i = 0; i < m_pProperties.Size(); i++) { | |
58 delete m_pProperties[i]; | |
59 } | |
60 for (i = 0; i < m_pChildAtomInfos.Size(); i++) { | |
61 delete m_pChildAtomInfos[i]; | |
62 } | |
63 for (i = 0; i < m_pChildAtoms.Size(); i++) { | |
64 delete m_pChildAtoms[i]; | |
65 } | |
66 } | |
67 | |
68 MP4Atom* MP4Atom::CreateAtom(const char* type) | |
69 { | |
70 MP4Atom* pAtom = NULL; | |
71 | |
72 if (type == NULL) { | |
73 pAtom = new MP4RootAtom(); | |
74 } else { | |
75 switch((uint8_t)type[0]) { | |
76 case 'a': | |
77 if (ATOMID(type) == ATOMID("avc1")) { | |
78 pAtom = new MP4Avc1Atom(); | |
79 } else if (ATOMID(type) == ATOMID("avcC")) { | |
80 pAtom = new MP4AvcCAtom(); | |
81 } else if (ATOMID(type) == ATOMID("alis")) { | |
82 pAtom = new MP4UrlAtom("alis"); | |
83 } else if (ATOMID(type) == ATOMID("alaw")) { | |
84 pAtom = new MP4SoundAtom("alaw"); | |
85 } | |
86 break; | |
199
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
87 case 'b': |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
88 if (ATOMID(type) == ATOMID("bitr")) { |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
89 pAtom = new MP4BitrAtom(); |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
90 } else if (ATOMID(type) == ATOMID("btrt")) { |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
91 pAtom = new MP4BtrtAtom(); |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
92 } |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
93 break; |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
94 case 'c': |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
95 if (ATOMID(type) == ATOMID("ctts")) { |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
96 pAtom = new MP4CttsAtom(); |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
97 } else if (ATOMID(type) == ATOMID("co64")) { |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
98 pAtom = new MP4Co64Atom(); |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
99 } else if (ATOMID(type) == ATOMID("cprt")) { |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
100 pAtom = new MP4CprtAtom(); |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
101 } else if (ATOMID(type) == ATOMID("cpil")) { /* Apple iTunes */ |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
102 pAtom = new MP4CpilAtom(); |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
103 } else if (ATOMID(type) == ATOMID("covr")) { /* Apple iTunes */ |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
104 pAtom = new MP4CovrAtom(); |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
105 } |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
106 break; |
61 | 107 case 'd': |
108 if (ATOMID(type) == ATOMID("d263")) { | |
109 pAtom = new MP4D263Atom(); | |
110 } else if (ATOMID(type) == ATOMID("damr")) { | |
111 pAtom = new MP4DamrAtom(); | |
199
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
112 } else if (ATOMID(type) == ATOMID("dinf")) { |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
113 pAtom = new MP4DinfAtom(); |
61 | 114 } else if (ATOMID(type) == ATOMID("dref")) { |
115 pAtom = new MP4DrefAtom(); | |
116 } else if (ATOMID(type) == ATOMID("dpnd")) { | |
117 pAtom = new MP4TrefTypeAtom(type); | |
199
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
118 } else if (ATOMID(type) == ATOMID("dmed")) { |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
119 pAtom = new MP4DmedAtom(); |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
120 } else if (ATOMID(type) == ATOMID("dimm")) { |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
121 pAtom = new MP4DimmAtom(); |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
122 } else if (ATOMID(type) == ATOMID("drep")) { |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
123 pAtom = new MP4DrepAtom(); |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
124 } else if (ATOMID(type) == ATOMID("dmax")) { |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
125 pAtom = new MP4DmaxAtom(); |
61 | 126 } else if (ATOMID(type) == ATOMID("data")) { /* Apple iTunes */ |
127 pAtom = new MP4DataAtom(); | |
199
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
128 } else if (ATOMID(type) == ATOMID("disk")) { /* Apple iTunes */ |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
129 pAtom = new MP4DiskAtom(); |
61 | 130 } |
131 break; | |
132 case 'e': | |
199
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
133 if (ATOMID(type) == ATOMID("esds")) { |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
134 pAtom = new MP4EsdsAtom(); |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
135 } else if (ATOMID(type) == ATOMID("edts")) { |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
136 pAtom = new MP4EdtsAtom(); |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
137 } else if (ATOMID(type) == ATOMID("elst")) { |
61 | 138 pAtom = new MP4ElstAtom(); |
139 } else if (ATOMID(type) == ATOMID("enca")) { | |
140 pAtom = new MP4EncaAtom(); | |
141 } else if (ATOMID(type) == ATOMID("encv")) { | |
142 pAtom = new MP4EncvAtom(); | |
143 } | |
144 break; | |
145 case 'f': | |
146 if (ATOMID(type) == ATOMID("free")) { | |
147 pAtom = new MP4FreeAtom(); | |
199
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
148 } else if (ATOMID(type) == ATOMID("frma")) { |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
149 pAtom = new MP4FrmaAtom(); |
61 | 150 } else if (ATOMID(type) == ATOMID("ftyp")) { |
151 pAtom = new MP4FtypAtom(); | |
152 } | |
153 break; | |
199
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
154 case 'g': |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
155 if (ATOMID(type) == ATOMID("gnre")) { // Apple iTunes |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
156 pAtom = new MP4GnreAtom(); |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
157 } |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
158 break; |
61 | 159 case 'h': |
160 if (ATOMID(type) == ATOMID("hdlr")) { | |
161 pAtom = new MP4HdlrAtom(); | |
199
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
162 } else if (ATOMID(type) == ATOMID("hmhd")) { |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
163 pAtom = new MP4HmhdAtom(); |
61 | 164 } else if (ATOMID(type) == ATOMID("hint")) { |
165 pAtom = new MP4TrefTypeAtom(type); | |
166 } else if (ATOMID(type) == ATOMID("hnti")) { | |
167 pAtom = new MP4HntiAtom(); | |
168 } else if (ATOMID(type) == ATOMID("hinf")) { | |
169 pAtom = new MP4HinfAtom(); | |
170 } else if (ATOMID(type) == ATOMID("h263")) { | |
171 pAtom = new MP4VideoAtom("h263"); | |
172 } | |
173 break; | |
174 case 'i': | |
199
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
175 if (ATOMID(type) == ATOMID("iKMS")) { |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
176 pAtom = new MP4IKMSAtom(); |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
177 } else if (ATOMID(type) == ATOMID("iSFM")) { |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
178 pAtom = new MP4ISFMAtom(); |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
179 } else if (ATOMID(type) == ATOMID("iods")) { |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
180 pAtom = new MP4IodsAtom(); |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
181 } else if (ATOMID(type) == ATOMID("ipir")) { |
61 | 182 pAtom = new MP4TrefTypeAtom(type); |
199
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
183 } else if (ATOMID(type) == ATOMID("ilst")) { |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
184 pAtom = new MP4IlstAtom(); |
61 | 185 } else if (ATOMID(type) == ATOMID("ima4")) { |
186 pAtom = new MP4SoundAtom("ima4"); | |
187 } | |
188 break; | |
189 case 'j': | |
190 if (ATOMID(type) == ATOMID("jpeg")) { | |
191 pAtom = new MP4VideoAtom("jpeg"); | |
192 } | |
193 break; | |
194 case 'm': | |
199
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
195 if (ATOMID(type) == ATOMID("mdia")) { |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
196 pAtom = new MP4MdiaAtom(); |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
197 } else if (ATOMID(type) == ATOMID("minf")) { |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
198 pAtom = new MP4MinfAtom(); |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
199 } else if (ATOMID(type) == ATOMID("mdhd")) { |
61 | 200 pAtom = new MP4MdhdAtom(); |
199
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
201 } else if (ATOMID(type) == ATOMID("mdat")) { |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
202 pAtom = new MP4MdatAtom(); |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
203 } else if (ATOMID(type) == ATOMID("moov")) { |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
204 pAtom = new MP4MoovAtom(); |
61 | 205 } else if (ATOMID(type) == ATOMID("mvhd")) { |
206 pAtom = new MP4MvhdAtom(); | |
207 } else if (ATOMID(type) == ATOMID("mpod")) { | |
208 pAtom = new MP4TrefTypeAtom(type); | |
209 } else if (ATOMID(type) == ATOMID("mp4a")) { | |
210 pAtom = new MP4Mp4aAtom(); | |
211 } else if (ATOMID(type) == ATOMID("mp4s")) { | |
212 pAtom = new MP4Mp4sAtom(); | |
213 } else if (ATOMID(type) == ATOMID("mp4v")) { | |
214 pAtom = new MP4Mp4vAtom(); | |
199
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
215 } else if (ATOMID(type) == ATOMID("moof")) { |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
216 pAtom = new MP4MoofAtom(); |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
217 } else if (ATOMID(type) == ATOMID("mfhd")) { |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
218 pAtom = new MP4MfhdAtom(); |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
219 } else if (ATOMID(type) == ATOMID("mvex")) { |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
220 pAtom = new MP4MvexAtom(); |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
221 } else if (ATOMID(type) == ATOMID("maxr")) { |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
222 pAtom = new MP4MaxrAtom(); |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
223 } else if (ATOMID(type) == ATOMID("meta")) { // iTunes |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
224 pAtom = new MP4MetaAtom(); |
61 | 225 } else if (ATOMID(type) == ATOMID("mean")) { // iTunes |
226 pAtom = new MP4MeanAtom(); | |
227 } | |
228 break; | |
229 case 'n': | |
199
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
230 if (ATOMID(type) == ATOMID("nmhd")) { |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
231 pAtom = new MP4NmhdAtom(); |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
232 } else if (ATOMID(type) == ATOMID("nump")) { |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
233 pAtom = new MP4NumpAtom(); |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
234 } else if (ATOMID(type) == ATOMID("name")) { // iTunes |
61 | 235 pAtom = new MP4NameAtom(); |
236 } | |
237 break; | |
199
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
238 case 'p': |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
239 if (ATOMID(type) == ATOMID("pmax")) { |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
240 pAtom = new MP4PmaxAtom(); |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
241 } else if (ATOMID(type) == ATOMID("payt")) { |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
242 pAtom = new MP4PaytAtom(); |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
243 } |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
244 break; |
61 | 245 case 'r': |
246 if (ATOMID(type) == ATOMID("rtp ")) { | |
247 pAtom = new MP4RtpAtom(); | |
248 } else if (ATOMID(type) == ATOMID("raw ")) { | |
249 pAtom = new MP4VideoAtom("raw "); | |
250 } | |
251 break; | |
252 case 's': | |
253 if (ATOMID(type) == ATOMID("s263")) { | |
254 pAtom = new MP4S263Atom(); | |
255 } else if (ATOMID(type) == ATOMID("samr")) { | |
256 pAtom = new MP4AmrAtom("samr"); | |
257 } else if (ATOMID(type) == ATOMID("sawb")) { | |
258 pAtom = new MP4AmrAtom("sawb"); | |
199
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
259 } else if (ATOMID(type) == ATOMID("schi")) { |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
260 pAtom = new MP4SchiAtom(); |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
261 } else if (ATOMID(type) == ATOMID("schm")) { |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
262 pAtom = new MP4SchmAtom(); |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
263 } else if (ATOMID(type) == ATOMID("sinf")) { |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
264 pAtom = new MP4SinfAtom(); |
61 | 265 } else if (ATOMID(type) == ATOMID("stbl")) { |
266 pAtom = new MP4StblAtom(); | |
267 } else if (ATOMID(type) == ATOMID("stsd")) { | |
268 pAtom = new MP4StsdAtom(); | |
199
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
269 } else if (ATOMID(type) == ATOMID("stts")) { |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
270 pAtom = new MP4SttsAtom(); |
61 | 271 } else if (ATOMID(type) == ATOMID("stsz")) { |
272 pAtom = new MP4StszAtom(); | |
273 } else if (ATOMID(type) == ATOMID("stsc")) { | |
274 pAtom = new MP4StscAtom(); | |
199
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
275 } else if (ATOMID(type) == ATOMID("stco")) { |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
276 pAtom = new MP4StcoAtom(); |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
277 } else if (ATOMID(type) == ATOMID("stss")) { |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
278 pAtom = new MP4StssAtom(); |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
279 } else if (ATOMID(type) == ATOMID("stsh")) { |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
280 pAtom = new MP4StshAtom(); |
61 | 281 } else if (ATOMID(type) == ATOMID("stdp")) { |
282 pAtom = new MP4StdpAtom(); | |
199
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
283 } else if (ATOMID(type) == ATOMID("smhd")) { |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
284 pAtom = new MP4SmhdAtom(); |
61 | 285 } else if (ATOMID(type) == ATOMID("sdp ")) { |
286 pAtom = new MP4SdpAtom(); | |
199
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
287 } else if (ATOMID(type) == ATOMID("snro")) { |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
288 pAtom = new MP4SnroAtom(); |
61 | 289 } else if (ATOMID(type) == ATOMID("sync")) { |
290 pAtom = new MP4TrefTypeAtom(type); | |
291 } else if (ATOMID(type) == ATOMID("skip")) { | |
292 pAtom = new MP4FreeAtom(); | |
293 pAtom->SetType("skip"); | |
294 } else if (ATOMID(type) == ATOMID("sowt")) { | |
295 pAtom = new MP4SoundAtom("sowt"); | |
296 } | |
297 break; | |
298 case 't': | |
199
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
299 if (ATOMID(type) == ATOMID("trak")) { |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
300 pAtom = new MP4TrakAtom(); |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
301 } else if (ATOMID(type) == ATOMID("tkhd")) { |
61 | 302 pAtom = new MP4TkhdAtom(); |
199
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
303 } else if (ATOMID(type) == ATOMID("tref")) { |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
304 pAtom = new MP4TrefAtom(); |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
305 } else if (ATOMID(type) == ATOMID("traf")) { |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
306 pAtom = new MP4TrafAtom(); |
61 | 307 } else if (ATOMID(type) == ATOMID("tfhd")) { |
308 pAtom = new MP4TfhdAtom(); | |
199
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
309 } else if (ATOMID(type) == ATOMID("trex")) { |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
310 pAtom = new MP4TrexAtom(); |
61 | 311 } else if (ATOMID(type) == ATOMID("trun")) { |
312 pAtom = new MP4TrunAtom(); | |
199
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
313 } else if (ATOMID(type) == ATOMID("tmin")) { |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
314 pAtom = new MP4TminAtom(); |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
315 } else if (ATOMID(type) == ATOMID("tmax")) { |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
316 pAtom = new MP4TmaxAtom(); |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
317 } else if (ATOMID(type) == ATOMID("trpy")) { |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
318 pAtom = new MP4TrpyAtom(); |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
319 } else if (ATOMID(type) == ATOMID("tpyl")) { |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
320 pAtom = new MP4TpylAtom(); |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
321 } else if (ATOMID(type) == ATOMID("tims")) { |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
322 pAtom = new MP4TimsAtom(); |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
323 } else if (ATOMID(type) == ATOMID("tsro")) { |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
324 pAtom = new MP4TsroAtom(); |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
325 } else if (ATOMID(type) == ATOMID("trkn")) { // iTunes |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
326 pAtom = new MP4TrknAtom(); |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
327 } else if (ATOMID(type) == ATOMID("tmpo")) { // iTunes |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
328 pAtom = new MP4TmpoAtom(); |
61 | 329 } else if (ATOMID(type) == ATOMID("twos")) { |
330 pAtom = new MP4SoundAtom("twos"); | |
331 } | |
332 break; | |
333 case 'u': | |
334 if (ATOMID(type) == ATOMID("udta")) { | |
335 pAtom = new MP4UdtaAtom(); | |
336 } else if (ATOMID(type) == ATOMID("url ")) { | |
337 pAtom = new MP4UrlAtom(); | |
338 } else if (ATOMID(type) == ATOMID("urn ")) { | |
339 pAtom = new MP4UrnAtom(); | |
340 } else if (ATOMID(type) == ATOMID("ulaw")) { | |
341 pAtom = new MP4SoundAtom("ulaw"); | |
342 } | |
343 break; | |
344 case 'v': | |
345 if (ATOMID(type) == ATOMID("vmhd")) { | |
346 pAtom = new MP4VmhdAtom(); | |
347 } | |
348 break; | |
349 case 'y': | |
350 if (ATOMID(type) == ATOMID("yuv2")) { | |
351 pAtom = new MP4VideoAtom("yuv2"); | |
352 } | |
353 break; | |
354 case 'S': | |
355 if (ATOMID(type) == ATOMID("SVQ3")) { | |
356 pAtom = new MP4VideoAtom("SVQ3"); | |
357 } else if (ATOMID(type) == ATOMID("SMI ")) { | |
358 pAtom = new MP4SmiAtom(); | |
359 } | |
360 break; | |
199
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
361 case 0251: { // copyright symbol |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
362 static const char name[5]={0251,'n', 'a', 'm', '\0'}; |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
363 static const char art[5]={0251,'A', 'R', 'T', '\0'}; |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
364 static const char wrt[5]={0251,'w', 'r', 't', '\0'}; |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
365 static const char alb[5]={0251,'a', 'l', 'b', '\0'}; |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
366 static const char day[5]={0251,'d', 'a', 'y', '\0'}; |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
367 static const char too[5]={0251,'t', 'o', 'o', '\0'}; |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
368 static const char cmt[5]={0251,'c', 'm', 't', '\0'}; |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
369 static const char gen[5]={0251,'g', 'e', 'n', '\0'}; |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
370 if (ATOMID(type) == ATOMID(name)) { |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
371 pAtom = new MP4NamAtom(); |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
372 } else if (ATOMID(type) == ATOMID(art)) { /* Apple iTunes */ |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
373 pAtom = new MP4ArtAtom(); |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
374 } else if (ATOMID(type) == ATOMID(wrt)) { /* Apple iTunes */ |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
375 pAtom = new MP4WrtAtom(); |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
376 } else if (ATOMID(type) == ATOMID(alb)) { /* Apple iTunes */ |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
377 pAtom = new MP4AlbAtom(); |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
378 } else if (ATOMID(type) == ATOMID(day)) { /* Apple iTunes */ |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
379 pAtom = new MP4DayAtom(); |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
380 } else if (ATOMID(type) == ATOMID(too)) { /* Apple iTunes */ |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
381 pAtom = new MP4TooAtom(); |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
382 } else if (ATOMID(type) == ATOMID(cmt)) { /* Apple iTunes */ |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
383 pAtom = new MP4CmtAtom(); |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
384 } else if (ATOMID(type) == ATOMID(gen)) { /* Apple iTunes */ |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
385 pAtom = new MP4GenAtom(); |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
386 } |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
387 break; |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
388 } |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
389 case '-': |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
390 if (ATOMID(type) == ATOMID("----")) { /* Apple iTunes */ |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
391 pAtom = new MP4DashAtom(); |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
392 } |
61 | 393 } |
394 } | |
395 | |
396 if (pAtom == NULL) { | |
199
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
397 pAtom = new MP4Atom(type); |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
398 pAtom->SetUnknownType(true); |
61 | 399 } |
400 | |
401 ASSERT(pAtom); | |
402 return pAtom; | |
403 } | |
404 | |
405 // generate a skeletal self | |
406 | |
407 void MP4Atom::Generate() | |
408 { | |
409 u_int32_t i; | |
410 | |
411 // for all properties | |
412 for (i = 0; i < m_pProperties.Size(); i++) { | |
413 // ask it to self generate | |
414 m_pProperties[i]->Generate(); | |
415 } | |
416 | |
417 // for all mandatory, single child atom types | |
418 for (i = 0; i < m_pChildAtomInfos.Size(); i++) { | |
419 if (m_pChildAtomInfos[i]->m_mandatory | |
420 && m_pChildAtomInfos[i]->m_onlyOne) { | |
421 | |
422 // create the mandatory, single child atom | |
423 MP4Atom* pChildAtom = | |
424 CreateAtom(m_pChildAtomInfos[i]->m_name); | |
425 | |
426 AddChildAtom(pChildAtom); | |
427 | |
428 // and ask it to self generate | |
429 pChildAtom->Generate(); | |
430 } | |
431 } | |
432 } | |
433 | |
434 MP4Atom* MP4Atom::ReadAtom(MP4File* pFile, MP4Atom* pParentAtom) | |
435 { | |
436 u_int8_t hdrSize = 8; | |
437 u_int8_t extendedType[16]; | |
438 | |
439 u_int64_t pos = pFile->GetPosition(); | |
440 | |
441 VERBOSE_READ(pFile->GetVerbosity(), | |
199
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
442 printf("ReadAtom: pos = 0x"X64"\n", pos)); |
61 | 443 |
444 u_int64_t dataSize = pFile->ReadUInt32(); | |
445 | |
446 char type[5]; | |
447 pFile->ReadBytes((u_int8_t*)&type[0], 4); | |
448 type[4] = '\0'; | |
449 | |
450 // extended size | |
451 if (dataSize == 1) { | |
452 dataSize = pFile->ReadUInt64(); | |
453 hdrSize += 8; | |
454 } | |
455 | |
456 // extended type | |
457 if (ATOMID(type) == ATOMID("uuid")) { | |
458 pFile->ReadBytes(extendedType, sizeof(extendedType)); | |
459 hdrSize += sizeof(extendedType); | |
460 } | |
461 | |
462 if (dataSize == 0) { | |
463 // extends to EOF | |
464 dataSize = pFile->GetSize() - pos; | |
465 } | |
466 | |
467 dataSize -= hdrSize; | |
468 | |
469 VERBOSE_READ(pFile->GetVerbosity(), | |
199
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
470 printf("ReadAtom: type = %s data-size = "U64" (0x"X64")\n", |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
471 type, dataSize, dataSize)); |
61 | 472 |
473 if (pos + hdrSize + dataSize > pParentAtom->GetEnd()) { | |
474 VERBOSE_ERROR(pFile->GetVerbosity(), | |
199
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
475 printf("ReadAtom: invalid atom size, extends outside parent atom - skipping to end of %s \"%s\"\n", |
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
476 pParentAtom->GetType(), type)); |
61 | 477 VERBOSE_READ(pFile->GetVerbosity(), |
199
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
478 printf("parent %s ("U64") pos "U64" hdr %d data "U64" sum "U64"\n", |
61 | 479 pParentAtom->GetType(), |
480 pParentAtom->GetEnd(), | |
481 pos, | |
482 hdrSize, | |
483 dataSize, | |
484 pos + hdrSize + dataSize)); | |
485 #if 0 | |
486 throw new MP4Error("invalid atom size", "ReadAtom"); | |
487 #else | |
488 // skip to end of atom | |
489 dataSize = pParentAtom->GetEnd() - pos - hdrSize; | |
490 #endif | |
491 } | |
492 | |
493 | |
494 MP4Atom* pAtom = CreateAtom(type); | |
495 pAtom->SetFile(pFile); | |
496 pAtom->SetStart(pos); | |
497 pAtom->SetEnd(pos + hdrSize + dataSize); | |
498 pAtom->SetSize(dataSize); | |
499 if (ATOMID(type) == ATOMID("uuid")) { | |
500 pAtom->SetExtendedType(extendedType); | |
501 } | |
502 if (pAtom->IsUnknownType()) { | |
503 if (!IsReasonableType(pAtom->GetType())) { | |
504 VERBOSE_READ(pFile->GetVerbosity(), | |
505 printf("Warning: atom type %s is suspect\n", pAtom->GetType())); | |
506 } else { | |
507 VERBOSE_READ(pFile->GetVerbosity(), | |
508 printf("Info: atom type %s is unknown\n", pAtom->GetType())); | |
509 } | |
510 | |
511 if (dataSize > 0) { | |
512 pAtom->AddProperty( | |
513 new MP4BytesProperty("data", dataSize)); | |
514 } | |
515 } | |
516 | |
517 pAtom->SetParentAtom(pParentAtom); | |
518 | |
519 pAtom->Read(); | |
520 | |
521 return pAtom; | |
522 } | |
523 | |
524 bool MP4Atom::IsReasonableType(const char* type) | |
525 { | |
526 for (u_int8_t i = 0; i < 4; i++) { | |
527 if (isalnum(type[i])) { | |
528 continue; | |
529 } | |
530 if (i == 3 && type[i] == ' ') { | |
531 continue; | |
532 } | |
533 return false; | |
534 } | |
535 return true; | |
536 } | |
537 | |
538 // generic read | |
539 void MP4Atom::Read() | |
540 { | |
541 ASSERT(m_pFile); | |
542 | |
543 if (ATOMID(m_type) != 0 && m_size > 1000000) { | |
544 VERBOSE_READ(GetVerbosity(), | |
199
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
545 printf("Warning: %s atom size "U64" is suspect\n", |
61 | 546 m_type, m_size)); |
547 } | |
548 | |
549 ReadProperties(); | |
550 | |
551 // read child atoms, if we expect there to be some | |
552 if (m_pChildAtomInfos.Size() > 0) { | |
553 ReadChildAtoms(); | |
554 } | |
555 | |
556 Skip(); // to end of atom | |
557 } | |
558 | |
559 void MP4Atom::Skip() | |
560 { | |
561 if (m_pFile->GetPosition() != m_end) { | |
562 VERBOSE_READ(m_pFile->GetVerbosity(), | |
199
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
563 printf("Skip: "U64" bytes\n", m_end - m_pFile->GetPosition())); |
61 | 564 } |
565 m_pFile->SetPosition(m_end); | |
566 } | |
567 | |
568 MP4Atom* MP4Atom::FindAtom(const char* name) | |
569 { | |
570 if (!IsMe(name)) { | |
571 return NULL; | |
572 } | |
573 | |
574 if (!IsRootAtom()) { | |
575 VERBOSE_FIND(m_pFile->GetVerbosity(), | |
576 printf("FindAtom: matched %s\n", name)); | |
577 | |
578 name = MP4NameAfterFirst(name); | |
579 | |
580 // I'm the sought after atom | |
581 if (name == NULL) { | |
582 return this; | |
583 } | |
584 } | |
585 | |
586 // else it's one of my children | |
587 return FindChildAtom(name); | |
588 } | |
589 | |
590 bool MP4Atom::FindProperty(const char *name, | |
591 MP4Property** ppProperty, u_int32_t* pIndex) | |
592 { | |
593 if (!IsMe(name)) { | |
594 return false; | |
595 } | |
596 | |
597 if (!IsRootAtom()) { | |
598 VERBOSE_FIND(m_pFile->GetVerbosity(), | |
599 printf("FindProperty: matched %s\n", name)); | |
600 | |
601 name = MP4NameAfterFirst(name); | |
602 | |
603 // no property name given | |
604 if (name == NULL) { | |
605 return false; | |
606 } | |
607 } | |
608 | |
609 return FindContainedProperty(name, ppProperty, pIndex); | |
610 } | |
611 | |
612 bool MP4Atom::IsMe(const char* name) | |
613 { | |
614 if (name == NULL) { | |
615 return false; | |
616 } | |
617 | |
618 // root atom always matches | |
619 if (!strcmp(m_type, "")) { | |
620 return true; | |
621 } | |
622 | |
623 // check if our atom name is specified as the first component | |
624 if (!MP4NameFirstMatches(m_type, name)) { | |
625 return false; | |
626 } | |
627 | |
628 return true; | |
629 } | |
630 | |
631 MP4Atom* MP4Atom::FindChildAtom(const char* name) | |
632 { | |
633 u_int32_t atomIndex = 0; | |
634 | |
635 // get the index if we have one, e.g. moov.trak[2].mdia... | |
636 MP4NameFirstIndex(name, &atomIndex); | |
637 | |
638 // need to get to the index'th child atom of the right type | |
639 for (u_int32_t i = 0; i < m_pChildAtoms.Size(); i++) { | |
640 if (MP4NameFirstMatches(m_pChildAtoms[i]->GetType(), name)) { | |
641 if (atomIndex == 0) { | |
642 // this is the one, ask it to match | |
643 return m_pChildAtoms[i]->FindAtom(name); | |
644 } | |
645 atomIndex--; | |
646 } | |
647 } | |
648 | |
649 return NULL; | |
650 } | |
651 | |
652 bool MP4Atom::FindContainedProperty(const char *name, | |
653 MP4Property** ppProperty, u_int32_t* pIndex) | |
654 { | |
655 u_int32_t numProperties = m_pProperties.Size(); | |
656 u_int32_t i; | |
657 // check all of our properties | |
658 for (i = 0; i < numProperties; i++) { | |
659 if (m_pProperties[i]->FindProperty(name, ppProperty, pIndex)) { | |
660 return true; | |
661 } | |
662 } | |
663 | |
664 // not one of our properties, | |
665 // presumably one of our children's properties | |
666 // check child atoms... | |
667 | |
668 // check if we have an index, e.g. trak[2].mdia... | |
669 u_int32_t atomIndex = 0; | |
670 MP4NameFirstIndex(name, &atomIndex); | |
671 | |
672 // need to get to the index'th child atom of the right type | |
673 for (i = 0; i < m_pChildAtoms.Size(); i++) { | |
674 if (MP4NameFirstMatches(m_pChildAtoms[i]->GetType(), name)) { | |
675 if (atomIndex == 0) { | |
676 // this is the one, ask it to match | |
677 return m_pChildAtoms[i]->FindProperty(name, ppProperty, pIndex); | |
678 } | |
679 atomIndex--; | |
680 } | |
681 } | |
682 | |
683 VERBOSE_FIND(m_pFile->GetVerbosity(), | |
684 printf("FindProperty: no match for %s\n", name)); | |
685 return false; | |
686 } | |
687 | |
688 void MP4Atom::ReadProperties(u_int32_t startIndex, u_int32_t count) | |
689 { | |
690 u_int32_t numProperties = MIN(count, m_pProperties.Size() - startIndex); | |
691 | |
692 // read any properties of the atom | |
693 for (u_int32_t i = startIndex; i < startIndex + numProperties; i++) { | |
694 | |
695 m_pProperties[i]->Read(m_pFile); | |
696 | |
697 if (m_pFile->GetPosition() > m_end) { | |
698 VERBOSE_READ(GetVerbosity(), | |
199
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
699 printf("ReadProperties: insufficient data for property: %s pos 0x"X64" atom end 0x"X64"\n", |
61 | 700 m_pProperties[i]->GetName(), |
701 m_pFile->GetPosition(), m_end)); | |
702 | |
703 throw new MP4Error("atom is too small", "Atom ReadProperties"); | |
704 } | |
705 | |
706 if (m_pProperties[i]->GetType() == TableProperty) { | |
707 VERBOSE_READ_TABLE(GetVerbosity(), | |
708 printf("Read: "); m_pProperties[i]->Dump(stdout, 0, true)); | |
709 } else if (m_pProperties[i]->GetType() != DescriptorProperty) { | |
710 VERBOSE_READ(GetVerbosity(), | |
711 printf("Read: "); m_pProperties[i]->Dump(stdout, 0, true)); | |
712 } | |
713 } | |
714 } | |
715 | |
716 void MP4Atom::ReadChildAtoms() | |
717 { | |
718 bool this_is_udta = ATOMID(m_type) == ATOMID("udta"); | |
719 | |
720 VERBOSE_READ(GetVerbosity(), | |
721 printf("ReadChildAtoms: of %s\n", m_type[0] ? m_type : "root")); | |
722 for (u_int64_t position = m_pFile->GetPosition(); | |
723 position < m_end; | |
724 position = m_pFile->GetPosition()) { | |
725 // make sure that we have enough to read at least 8 bytes | |
726 // size and type. | |
727 if (m_end - position < 2 * sizeof(uint32_t)) { | |
728 // if we're reading udta, it's okay to have 4 bytes of 0 | |
729 if (this_is_udta && | |
730 m_end - position == sizeof(uint32_t)) { | |
731 u_int32_t mbz = m_pFile->ReadUInt32(); | |
732 if (mbz != 0) { | |
733 VERBOSE_WARNING(GetVerbosity(), | |
734 printf("Error: In udta atom, end value is not zero %x\n", | |
735 mbz)); | |
736 } | |
737 continue; | |
738 } | |
739 // otherwise, output a warning, but don't care | |
740 VERBOSE_WARNING(GetVerbosity(), | |
199
0a2ad94e8607
[svn] Synced with bmp-mp4. Build system is fragile, but should work now.
chainsaw
parents:
61
diff
changeset
|
741 printf("Error: In %s atom, extra "D64" bytes at end of atom\n", |
61 | 742 m_type, (m_end - position))); |
743 for (uint64_t ix = 0; ix < m_end - position; ix++) { | |
744 m_pFile->ReadUInt8(); | |
745 } | |
746 continue; | |
747 } | |
748 MP4Atom* pChildAtom = MP4Atom::ReadAtom(m_pFile, this); | |
749 | |
750 AddChildAtom(pChildAtom); | |
751 | |
752 MP4AtomInfo* pChildAtomInfo = FindAtomInfo(pChildAtom->GetType()); | |
753 | |
754 // if child atom is of known type | |
755 // but not expected here print warning | |
756 if (pChildAtomInfo == NULL && !pChildAtom->IsUnknownType()) { | |
757 VERBOSE_READ(GetVerbosity(), | |
758 printf("Warning: In atom %s unexpected child atom %s\n", | |
759 GetType(), pChildAtom->GetType())); | |
760 } | |
761 | |
762 // if child atoms should have just one instance | |
763 // and this is more than one, print warning | |
764 if (pChildAtomInfo) { | |
765 pChildAtomInfo->m_count++; | |
766 | |
767 if (pChildAtomInfo->m_onlyOne && pChildAtomInfo->m_count > 1) { | |
768 VERBOSE_READ(GetVerbosity(), | |
769 printf("Warning: In atom %s multiple child atoms %s\n", | |
770 GetType(), pChildAtom->GetType())); | |
771 } | |
772 } | |
773 | |
774 } | |
775 | |
776 // if mandatory child atom doesn't exist, print warning | |
777 u_int32_t numAtomInfo = m_pChildAtomInfos.Size(); | |
778 for (u_int32_t i = 0; i < numAtomInfo; i++) { | |
779 if (m_pChildAtomInfos[i]->m_mandatory | |
780 && m_pChildAtomInfos[i]->m_count == 0) { | |
781 VERBOSE_READ(GetVerbosity(), | |
782 printf("Warning: In atom %s missing child atom %s\n", | |
783 GetType(), m_pChildAtomInfos[i]->m_name)); | |
784 } | |
785 } | |
786 | |
787 VERBOSE_READ(GetVerbosity(), | |
788 printf("ReadChildAtoms: finished %s\n", m_type)); | |
789 } | |
790 | |
791 MP4AtomInfo* MP4Atom::FindAtomInfo(const char* name) | |
792 { | |
793 u_int32_t numAtomInfo = m_pChildAtomInfos.Size(); | |
794 for (u_int32_t i = 0; i < numAtomInfo; i++) { | |
795 if (ATOMID(m_pChildAtomInfos[i]->m_name) == ATOMID(name)) { | |
796 return m_pChildAtomInfos[i]; | |
797 } | |
798 } | |
799 return NULL; | |
800 } | |
801 | |
802 // generic write | |
803 void MP4Atom::Write() | |
804 { | |
805 ASSERT(m_pFile); | |
806 | |
807 BeginWrite(); | |
808 | |
809 WriteProperties(); | |
810 | |
811 WriteChildAtoms(); | |
812 | |
813 FinishWrite(); | |
814 } | |
815 | |
816 void MP4Atom::Rewrite() | |
817 { | |
818 ASSERT(m_pFile); | |
819 | |
820 if (!m_end) { | |
821 // This atom hasn't been written yet... | |
822 return; | |
823 } | |
824 | |
825 u_int64_t fPos = m_pFile->GetPosition(); | |
826 m_pFile->SetPosition(GetStart()); | |
827 Write(); | |
828 m_pFile->SetPosition(fPos); | |
829 } | |
830 | |
831 void MP4Atom::BeginWrite(bool use64) | |
832 { | |
833 m_start = m_pFile->GetPosition(); | |
834 //use64 = m_pFile->Use64Bits(); | |
835 if (use64) { | |
836 m_pFile->WriteUInt32(1); | |
837 } else { | |
838 m_pFile->WriteUInt32(0); | |
839 } | |
840 m_pFile->WriteBytes((u_int8_t*)&m_type[0], 4); | |
841 if (use64) { | |
842 m_pFile->WriteUInt64(0); | |
843 } | |
844 if (ATOMID(m_type) == ATOMID("uuid")) { | |
845 m_pFile->WriteBytes(m_extendedType, sizeof(m_extendedType)); | |
846 } | |
847 } | |
848 | |
849 void MP4Atom::FinishWrite(bool use64) | |
850 { | |
851 m_end = m_pFile->GetPosition(); | |
852 m_size = (m_end - m_start); | |
853 //use64 = m_pFile->Use64Bits(); | |
854 if (use64) { | |
855 m_pFile->SetPosition(m_start + 8); | |
856 m_pFile->WriteUInt64(m_size); | |
857 } else { | |
858 ASSERT(m_size <= (u_int64_t)0xFFFFFFFF); | |
859 m_pFile->SetPosition(m_start); | |
860 m_pFile->WriteUInt32(m_size); | |
861 } | |
862 m_pFile->SetPosition(m_end); | |
863 | |
864 // adjust size to just reflect data portion of atom | |
865 m_size -= (use64 ? 16 : 8); | |
866 if (ATOMID(m_type) == ATOMID("uuid")) { | |
867 m_size -= sizeof(m_extendedType); | |
868 } | |
869 } | |
870 | |
871 void MP4Atom::WriteProperties(u_int32_t startIndex, u_int32_t count) | |
872 { | |
873 u_int32_t numProperties = MIN(count, m_pProperties.Size() - startIndex); | |
874 | |
875 VERBOSE_WRITE(GetVerbosity(), | |
876 printf("Write: type %s\n", m_type)); | |
877 | |
878 for (u_int32_t i = startIndex; i < startIndex + numProperties; i++) { | |
879 m_pProperties[i]->Write(m_pFile); | |
880 | |
881 if (m_pProperties[i]->GetType() == TableProperty) { | |
882 VERBOSE_WRITE_TABLE(GetVerbosity(), | |
883 printf("Write: "); m_pProperties[i]->Dump(stdout, 0, false)); | |
884 } else { | |
885 VERBOSE_WRITE(GetVerbosity(), | |
886 printf("Write: "); m_pProperties[i]->Dump(stdout, 0, false)); | |
887 } | |
888 } | |
889 } | |
890 | |
891 void MP4Atom::WriteChildAtoms() | |
892 { | |
893 u_int32_t size = m_pChildAtoms.Size(); | |
894 for (u_int32_t i = 0; i < size; i++) { | |
895 m_pChildAtoms[i]->Write(); | |
896 } | |
897 | |
898 VERBOSE_WRITE(GetVerbosity(), | |
899 printf("Write: finished %s\n", m_type)); | |
900 } | |
901 | |
902 void MP4Atom::AddProperty(MP4Property* pProperty) | |
903 { | |
904 ASSERT(pProperty); | |
905 m_pProperties.Add(pProperty); | |
906 pProperty->SetParentAtom(this); | |
907 } | |
908 | |
909 void MP4Atom::AddVersionAndFlags() | |
910 { | |
911 AddProperty(new MP4Integer8Property("version")); | |
912 AddProperty(new MP4Integer24Property("flags")); | |
913 } | |
914 | |
915 void MP4Atom::AddReserved(char* name, u_int32_t size) | |
916 { | |
917 MP4BytesProperty* pReserved = new MP4BytesProperty(name, size); | |
918 pReserved->SetReadOnly(); | |
919 AddProperty(pReserved); | |
920 } | |
921 | |
922 void MP4Atom::ExpectChildAtom(const char* name, bool mandatory, bool onlyOne) | |
923 { | |
924 m_pChildAtomInfos.Add(new MP4AtomInfo(name, mandatory, onlyOne)); | |
925 } | |
926 | |
927 u_int8_t MP4Atom::GetVersion() | |
928 { | |
929 if (strcmp("version", m_pProperties[0]->GetName())) { | |
930 return 0; | |
931 } | |
932 return ((MP4Integer8Property*)m_pProperties[0])->GetValue(); | |
933 } | |
934 | |
935 void MP4Atom::SetVersion(u_int8_t version) | |
936 { | |
937 if (strcmp("version", m_pProperties[0]->GetName())) { | |
938 return; | |
939 } | |
940 ((MP4Integer8Property*)m_pProperties[0])->SetValue(version); | |
941 } | |
942 | |
943 u_int32_t MP4Atom::GetFlags() | |
944 { | |
945 if (strcmp("flags", m_pProperties[1]->GetName())) { | |
946 return 0; | |
947 } | |
948 return ((MP4Integer24Property*)m_pProperties[1])->GetValue(); | |
949 } | |
950 | |
951 void MP4Atom::SetFlags(u_int32_t flags) | |
952 { | |
953 if (strcmp("flags", m_pProperties[1]->GetName())) { | |
954 return; | |
955 } | |
956 ((MP4Integer24Property*)m_pProperties[1])->SetValue(flags); | |
957 } | |
958 | |
959 void MP4Atom::Dump(FILE* pFile, u_int8_t indent, bool dumpImplicits) | |
960 { | |
961 if (m_type[0] != '\0') { | |
962 Indent(pFile, indent); | |
963 fprintf(pFile, "type %s\n", m_type); | |
964 fflush(pFile); | |
965 } | |
966 | |
967 u_int32_t i; | |
968 u_int32_t size; | |
969 | |
970 // dump our properties | |
971 size = m_pProperties.Size(); | |
972 for (i = 0; i < size; i++) { | |
973 | |
974 /* skip details of tables unless we're told to be verbose */ | |
975 if (m_pProperties[i]->GetType() == TableProperty | |
976 && !(GetVerbosity() & MP4_DETAILS_TABLE)) { | |
977 Indent(pFile, indent + 1); | |
978 fprintf(pFile, "<table entries suppressed>\n"); | |
979 continue; | |
980 } | |
981 | |
982 m_pProperties[i]->Dump(pFile, indent + 1, dumpImplicits); | |
983 } | |
984 | |
985 // dump our children | |
986 size = m_pChildAtoms.Size(); | |
987 for (i = 0; i < size; i++) { | |
988 m_pChildAtoms[i]->Dump(pFile, indent + 1, dumpImplicits); | |
989 } | |
990 } | |
991 | |
992 u_int32_t MP4Atom::GetVerbosity() | |
993 { | |
994 ASSERT(m_pFile); | |
995 return m_pFile->GetVerbosity(); | |
996 } | |
997 | |
998 u_int8_t MP4Atom::GetDepth() | |
999 { | |
1000 if (m_depth < 0xFF) { | |
1001 return m_depth; | |
1002 } | |
1003 | |
1004 MP4Atom *pAtom = this; | |
1005 m_depth = 0; | |
1006 | |
1007 while ((pAtom = pAtom->GetParentAtom()) != NULL) { | |
1008 m_depth++; | |
1009 ASSERT(m_depth < 255); | |
1010 } | |
1011 return m_depth; | |
1012 } | |
1013 |