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. All Rights Reserved.
|
|
17 *
|
|
18 * Contributor(s):
|
|
19 * Dave Mackie dmackie@cisco.com
|
|
20 */
|
|
21
|
|
22 #include "mp4common.h"
|
|
23
|
|
24 MP4Container::~MP4Container()
|
|
25 {
|
|
26 for (u_int32_t i = 0; i < m_pProperties.Size(); i++) {
|
|
27 delete m_pProperties[i];
|
|
28 }
|
|
29 }
|
|
30
|
|
31 void MP4Container::AddProperty(MP4Property* pProperty)
|
|
32 {
|
|
33 ASSERT(pProperty);
|
|
34 m_pProperties.Add(pProperty);
|
|
35 }
|
|
36
|
|
37 bool MP4Container::FindProperty(const char *name,
|
|
38 MP4Property** ppProperty, u_int32_t* pIndex)
|
|
39 {
|
|
40 if (pIndex) {
|
|
41 *pIndex = 0; // set the default answer for index
|
|
42 }
|
|
43
|
|
44 u_int32_t numProperties = m_pProperties.Size();
|
|
45
|
|
46 for (u_int32_t i = 0; i < numProperties; i++) {
|
|
47 if (m_pProperties[i]->FindProperty(name, ppProperty, pIndex)) {
|
|
48 return true;
|
|
49 }
|
|
50 }
|
|
51 return false;
|
|
52 }
|
|
53
|
|
54 void MP4Container::FindIntegerProperty(const char* name,
|
|
55 MP4Property** ppProperty, u_int32_t* pIndex)
|
|
56 {
|
|
57 if (!FindProperty(name, ppProperty, pIndex)) {
|
|
58 throw new MP4Error("no such property",
|
|
59 "MP4Container::FindIntegerProperty");
|
|
60 }
|
|
61
|
|
62 switch ((*ppProperty)->GetType()) {
|
|
63 case Integer8Property:
|
|
64 case Integer16Property:
|
|
65 case Integer24Property:
|
|
66 case Integer32Property:
|
|
67 case Integer64Property:
|
|
68 break;
|
|
69 default:
|
|
70 throw new MP4Error("type mismatch",
|
|
71 "MP4Container::FindIntegerProperty");
|
|
72 }
|
|
73 }
|
|
74
|
|
75 u_int64_t MP4Container::GetIntegerProperty(const char* name)
|
|
76 {
|
|
77 MP4Property* pProperty;
|
|
78 u_int32_t index;
|
|
79
|
|
80 FindIntegerProperty(name, &pProperty, &index);
|
|
81
|
|
82 return ((MP4IntegerProperty*)pProperty)->GetValue(index);
|
|
83 }
|
|
84
|
|
85 void MP4Container::SetIntegerProperty(const char* name, u_int64_t value)
|
|
86 {
|
|
87 MP4Property* pProperty = NULL;
|
|
88 u_int32_t index = 0;
|
|
89
|
|
90 FindIntegerProperty(name, &pProperty, &index);
|
|
91
|
|
92 ((MP4IntegerProperty*)pProperty)->SetValue(value, index);
|
|
93 }
|
|
94
|
|
95 void MP4Container::FindFloatProperty(const char* name,
|
|
96 MP4Property** ppProperty, u_int32_t* pIndex)
|
|
97 {
|
|
98 if (!FindProperty(name, ppProperty, pIndex)) {
|
|
99 throw new MP4Error("no such property",
|
|
100 "MP4Container::FindFloatProperty");
|
|
101 }
|
|
102 if ((*ppProperty)->GetType() != Float32Property) {
|
|
103 throw new MP4Error("type mismatch",
|
|
104 "MP4Container::FindFloatProperty");
|
|
105 }
|
|
106 }
|
|
107
|
|
108 float MP4Container::GetFloatProperty(const char* name)
|
|
109 {
|
|
110 MP4Property* pProperty;
|
|
111 u_int32_t index;
|
|
112
|
|
113 FindFloatProperty(name, &pProperty, &index);
|
|
114
|
|
115 return ((MP4Float32Property*)pProperty)->GetValue(index);
|
|
116 }
|
|
117
|
|
118 void MP4Container::SetFloatProperty(const char* name, float value)
|
|
119 {
|
|
120 MP4Property* pProperty;
|
|
121 u_int32_t index;
|
|
122
|
|
123 FindFloatProperty(name, &pProperty, &index);
|
|
124
|
|
125 ((MP4Float32Property*)pProperty)->SetValue(value, index);
|
|
126 }
|
|
127
|
|
128 void MP4Container::FindStringProperty(const char* name,
|
|
129 MP4Property** ppProperty, u_int32_t* pIndex)
|
|
130 {
|
|
131 if (!FindProperty(name, ppProperty, pIndex)) {
|
|
132 throw new MP4Error("no such property",
|
|
133 "MP4Container::FindStringProperty");
|
|
134 }
|
|
135 if ((*ppProperty)->GetType() != StringProperty) {
|
|
136 throw new MP4Error("type mismatch",
|
|
137 "MP4Container::FindStringProperty");
|
|
138 }
|
|
139 }
|
|
140
|
|
141 const char* MP4Container::GetStringProperty(const char* name)
|
|
142 {
|
|
143 MP4Property* pProperty;
|
|
144 u_int32_t index;
|
|
145
|
|
146 FindStringProperty(name, &pProperty, &index);
|
|
147
|
|
148 return ((MP4StringProperty*)pProperty)->GetValue(index);
|
|
149 }
|
|
150
|
|
151 void MP4Container::SetStringProperty(const char* name, const char* value)
|
|
152 {
|
|
153 MP4Property* pProperty;
|
|
154 u_int32_t index;
|
|
155
|
|
156 FindStringProperty(name, &pProperty, &index);
|
|
157
|
|
158 ((MP4StringProperty*)pProperty)->SetValue(value, index);
|
|
159 }
|
|
160
|
|
161 void MP4Container::FindBytesProperty(const char* name,
|
|
162 MP4Property** ppProperty, u_int32_t* pIndex)
|
|
163 {
|
|
164 if (!FindProperty(name, ppProperty, pIndex)) {
|
|
165 throw new MP4Error("no such property",
|
|
166 "MP4Container::FindBytesProperty");
|
|
167 }
|
|
168 if ((*ppProperty)->GetType() != BytesProperty) {
|
|
169 throw new MP4Error("type mismatch",
|
|
170 "MP4Container::FindBytesProperty");
|
|
171 }
|
|
172 }
|
|
173
|
|
174 void MP4Container::GetBytesProperty(const char* name,
|
|
175 u_int8_t** ppValue, u_int32_t* pValueSize)
|
|
176 {
|
|
177 MP4Property* pProperty;
|
|
178 u_int32_t index;
|
|
179
|
|
180 FindBytesProperty(name, &pProperty, &index);
|
|
181
|
|
182 ((MP4BytesProperty*)pProperty)->GetValue(ppValue, pValueSize, index);
|
|
183 }
|
|
184
|
|
185 void MP4Container::SetBytesProperty(const char* name,
|
|
186 const u_int8_t* pValue, u_int32_t valueSize)
|
|
187 {
|
|
188 MP4Property* pProperty;
|
|
189 u_int32_t index;
|
|
190
|
|
191 FindBytesProperty(name, &pProperty, &index);
|
|
192
|
|
193 ((MP4BytesProperty*)pProperty)->SetValue(pValue, valueSize, index);
|
|
194 }
|
|
195
|
|
196 void MP4Container::Read(MP4File* pFile)
|
|
197 {
|
|
198 u_int32_t numProperties = m_pProperties.Size();
|
|
199
|
|
200 for (u_int32_t i = 0; i < numProperties; i++) {
|
|
201 m_pProperties[i]->Read(pFile);
|
|
202 }
|
|
203 }
|
|
204
|
|
205 void MP4Container::Write(MP4File* pFile)
|
|
206 {
|
|
207 u_int32_t numProperties = m_pProperties.Size();
|
|
208
|
|
209 if (numProperties == 0) {
|
|
210 WARNING(numProperties == 0);
|
|
211 return;
|
|
212 }
|
|
213
|
|
214 for (u_int32_t i = 0; i < numProperties; i++) {
|
|
215 m_pProperties[i]->Write(pFile);
|
|
216 }
|
|
217 }
|
|
218
|
|
219 void MP4Container::Dump(FILE* pFile, u_int8_t indent, bool dumpImplicits)
|
|
220 {
|
|
221 u_int32_t numProperties = m_pProperties.Size();
|
|
222
|
|
223 for (u_int32_t i = 0; i < numProperties; i++) {
|
|
224 m_pProperties[i]->Dump(pFile, indent, dumpImplicits);
|
|
225 }
|
|
226 }
|
|
227
|