mp4property.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733
  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 [email protected]
  20. */
  21. #include "mp4common.h"
  22. MP4Property::MP4Property(const char* name)
  23. {
  24. m_name = name;
  25. m_pParentAtom = NULL;
  26. m_readOnly = false;
  27. m_implicit = false;
  28. }
  29. bool MP4Property::FindProperty(const char* name,
  30. MP4Property** ppProperty, u_int32_t* pIndex)
  31. {
  32. if (name == NULL) {
  33. return false;
  34. }
  35. if (!strcasecmp(m_name, name)) {
  36. if (m_pParentAtom) {
  37. VERBOSE_FIND(m_pParentAtom->GetFile()->GetVerbosity(),
  38. printf("FindProperty: matched %s\n", name));
  39. }
  40. *ppProperty = this;
  41. return true;
  42. }
  43. return false;
  44. }
  45. // Integer Property
  46. u_int64_t MP4IntegerProperty::GetValue(u_int32_t index)
  47. {
  48. switch (this->GetType()) {
  49. case Integer8Property:
  50. return ((MP4Integer8Property*)this)->GetValue(index);
  51. case Integer16Property:
  52. return ((MP4Integer16Property*)this)->GetValue(index);
  53. case Integer24Property:
  54. return ((MP4Integer24Property*)this)->GetValue(index);
  55. case Integer32Property:
  56. return ((MP4Integer32Property*)this)->GetValue(index);
  57. case Integer64Property:
  58. return ((MP4Integer64Property*)this)->GetValue(index);
  59. default:
  60. ASSERT(FALSE);
  61. }
  62. return (0);
  63. }
  64. void MP4IntegerProperty::SetValue(u_int64_t value, u_int32_t index)
  65. {
  66. switch (this->GetType()) {
  67. case Integer8Property:
  68. ((MP4Integer8Property*)this)->SetValue(value, index);
  69. break;
  70. case Integer16Property:
  71. ((MP4Integer16Property*)this)->SetValue(value, index);
  72. break;
  73. case Integer24Property:
  74. ((MP4Integer24Property*)this)->SetValue(value, index);
  75. break;
  76. case Integer32Property:
  77. ((MP4Integer32Property*)this)->SetValue(value, index);
  78. break;
  79. case Integer64Property:
  80. ((MP4Integer64Property*)this)->SetValue(value, index);
  81. break;
  82. default:
  83. ASSERT(FALSE);
  84. }
  85. }
  86. void MP4IntegerProperty::InsertValue(u_int64_t value, u_int32_t index)
  87. {
  88. switch (this->GetType()) {
  89. case Integer8Property:
  90. ((MP4Integer8Property*)this)->InsertValue(value, index);
  91. break;
  92. case Integer16Property:
  93. ((MP4Integer16Property*)this)->InsertValue(value, index);
  94. break;
  95. case Integer24Property:
  96. ((MP4Integer24Property*)this)->InsertValue(value, index);
  97. break;
  98. case Integer32Property:
  99. ((MP4Integer32Property*)this)->InsertValue(value, index);
  100. break;
  101. case Integer64Property:
  102. ((MP4Integer64Property*)this)->InsertValue(value, index);
  103. break;
  104. default:
  105. ASSERT(FALSE);
  106. }
  107. }
  108. void MP4IntegerProperty::DeleteValue(u_int32_t index)
  109. {
  110. switch (this->GetType()) {
  111. case Integer8Property:
  112. ((MP4Integer8Property*)this)->DeleteValue(index);
  113. break;
  114. case Integer16Property:
  115. ((MP4Integer16Property*)this)->DeleteValue(index);
  116. break;
  117. case Integer24Property:
  118. ((MP4Integer24Property*)this)->DeleteValue(index);
  119. break;
  120. case Integer32Property:
  121. ((MP4Integer32Property*)this)->DeleteValue(index);
  122. break;
  123. case Integer64Property:
  124. ((MP4Integer64Property*)this)->DeleteValue(index);
  125. break;
  126. default:
  127. ASSERT(FALSE);
  128. }
  129. }
  130. void MP4IntegerProperty::IncrementValue(int32_t increment, u_int32_t index)
  131. {
  132. SetValue(GetValue() + increment);
  133. }
  134. // MP4BitfieldProperty
  135. void MP4BitfieldProperty::Read(MP4File* pFile, u_int32_t index)
  136. {
  137. if (m_implicit) {
  138. return;
  139. }
  140. m_values[index] = pFile->ReadBits(m_numBits);
  141. }
  142. void MP4BitfieldProperty::Write(MP4File* pFile, u_int32_t index)
  143. {
  144. if (m_implicit) {
  145. return;
  146. }
  147. pFile->WriteBits(m_values[index], m_numBits);
  148. }
  149. // MP4Float32Property
  150. void MP4Float32Property::Read(MP4File* pFile, u_int32_t index)
  151. {
  152. if (m_implicit) {
  153. return;
  154. }
  155. if (m_useFixed16Format) {
  156. m_values[index] = pFile->ReadFixed16();
  157. } else if (m_useFixed32Format) {
  158. m_values[index] = pFile->ReadFixed32();
  159. } else {
  160. m_values[index] = pFile->ReadFloat();
  161. }
  162. }
  163. void MP4Float32Property::Write(MP4File* pFile, u_int32_t index)
  164. {
  165. if (m_implicit) {
  166. return;
  167. }
  168. if (m_useFixed16Format) {
  169. pFile->WriteFixed16(m_values[index]);
  170. } else if (m_useFixed32Format) {
  171. pFile->WriteFixed32(m_values[index]);
  172. } else {
  173. pFile->WriteFloat(m_values[index]);
  174. }
  175. }
  176. // MP4StringProperty
  177. MP4StringProperty::MP4StringProperty(char* name,
  178. bool useCountedFormat, bool useUnicode)
  179. : MP4Property(name)
  180. {
  181. SetCount(1);
  182. m_values[0] = NULL;
  183. m_useCountedFormat = useCountedFormat;
  184. m_useExpandedCount = false;
  185. m_useUnicode = useUnicode;
  186. m_fixedLength = 0; // length not fixed
  187. }
  188. MP4StringProperty::~MP4StringProperty()
  189. {
  190. u_int32_t count = GetCount();
  191. for (u_int32_t i = 0; i < count; i++) {
  192. MP4Free(m_values[i]);
  193. }
  194. }
  195. void MP4StringProperty::SetCount(u_int32_t count)
  196. {
  197. u_int32_t oldCount = m_values.Size();
  198. m_values.Resize(count);
  199. for (u_int32_t i = oldCount; i < count; i++) {
  200. m_values[i] = NULL;
  201. }
  202. }
  203. void MP4StringProperty::SetValue(const char* value, u_int32_t index)
  204. {
  205. if (m_readOnly) {
  206. throw new MP4Error(EACCES, "property is read-only", m_name);
  207. }
  208. MP4Free(m_values[index]);
  209. if (m_fixedLength) {
  210. m_values[index] = (char*)MP4Calloc(m_fixedLength + 1);
  211. if (value) {
  212. strncpy(m_values[index], value, m_fixedLength);
  213. }
  214. } else {
  215. if (value) {
  216. if (m_useUnicode)
  217. m_values[index] = (char *)MP4Stralloc((const uint16_t *)value);
  218. else
  219. m_values[index] = MP4Stralloc(value);
  220. } else {
  221. m_values[index] = NULL;
  222. }
  223. }
  224. }
  225. void MP4StringProperty::Read(MP4File* pFile, u_int32_t index)
  226. {
  227. if (m_implicit) {
  228. return;
  229. }
  230. if (m_useCountedFormat) {
  231. m_values[index] = pFile->ReadCountedString(
  232. (m_useUnicode ? 2 : 1), m_useExpandedCount);
  233. } else if (m_fixedLength) {
  234. MP4Free(m_values[index]);
  235. m_values[index] = (char*)MP4Calloc(m_fixedLength + 1);
  236. pFile->ReadBytes((u_int8_t*)m_values[index], m_fixedLength);
  237. } else {
  238. if (m_useUnicode)
  239. {
  240. m_values[index] = (char *)pFile->ReadUnicodeString();
  241. }
  242. else
  243. {
  244. char *str = pFile->ReadString();
  245. if (str && str[0] == 0xFF && str[1] == 0xFE)
  246. m_useUnicode = true;
  247. if (str && str[0] == 0xFE && str[1] == 0xFF)
  248. m_useUnicode = true;
  249. m_values[index] = str;
  250. }
  251. }
  252. }
  253. void MP4StringProperty::Write(MP4File* pFile, u_int32_t index)
  254. {
  255. if (m_implicit) {
  256. return;
  257. }
  258. if (m_useCountedFormat) {
  259. pFile->WriteCountedString(m_values[index],
  260. (m_useUnicode ? 2 : 1), m_useExpandedCount);
  261. } else if (m_fixedLength) {
  262. pFile->WriteBytes((u_int8_t*)m_values[index], m_fixedLength);
  263. } else {
  264. if (m_useUnicode)
  265. pFile->WriteUnicodeString((const uint16_t *)m_values[index]);
  266. else
  267. pFile->WriteString(m_values[index]);
  268. }
  269. }
  270. // MP4BytesProperty
  271. MP4BytesProperty::MP4BytesProperty(char* name, u_int32_t valueSize,
  272. u_int32_t defaultValueSize)
  273. : MP4Property(name)
  274. {
  275. SetCount(1);
  276. m_values[0] = (u_int8_t*)MP4Calloc(valueSize);
  277. m_valueSizes[0] = valueSize;
  278. m_fixedValueSize = 0;
  279. m_defaultValueSize = defaultValueSize;
  280. }
  281. MP4BytesProperty::~MP4BytesProperty()
  282. {
  283. u_int32_t count = GetCount();
  284. for (u_int32_t i = 0; i < count; i++) {
  285. MP4Free(m_values[i]);
  286. }
  287. }
  288. void MP4BytesProperty::SetCount(u_int32_t count)
  289. {
  290. u_int32_t oldCount = m_values.Size();
  291. m_values.Resize(count);
  292. m_valueSizes.Resize(count);
  293. for (u_int32_t i = oldCount; i < count; i++) {
  294. m_values[i] = NULL;
  295. m_valueSizes[i] = m_defaultValueSize;
  296. }
  297. }
  298. void MP4BytesProperty::SetValue(const u_int8_t* pValue, u_int32_t valueSize,
  299. u_int32_t index)
  300. {
  301. if (m_readOnly) {
  302. throw new MP4Error(EACCES, "property is read-only", m_name);
  303. }
  304. if (m_fixedValueSize) {
  305. if (valueSize > m_fixedValueSize) {
  306. throw new MP4Error("%s.%s value size %d exceeds fixed value size %d",
  307. "MP4BytesProperty::SetValue",
  308. GetParentAtom()->GetType(),
  309. GetName(),
  310. valueSize,
  311. m_fixedValueSize);
  312. }
  313. if (m_values[index] == NULL) {
  314. m_values[index] = (u_int8_t*)MP4Calloc(m_fixedValueSize);
  315. m_valueSizes[index] = m_fixedValueSize;
  316. }
  317. if (pValue) {
  318. memcpy(m_values[index], pValue, valueSize);
  319. }
  320. } else {
  321. MP4Free(m_values[index]);
  322. if (pValue) {
  323. m_values[index] = (u_int8_t*)MP4Malloc(valueSize);
  324. memcpy(m_values[index], pValue, valueSize);
  325. m_valueSizes[index] = valueSize;
  326. } else {
  327. m_values[index] = NULL;
  328. m_valueSizes[index] = 0;
  329. }
  330. }
  331. }
  332. void MP4BytesProperty::SetValueSize(u_int32_t valueSize, u_int32_t index)
  333. {
  334. if (m_fixedValueSize) {
  335. throw new MP4Error("can't change size of fixed sized property",
  336. "MP4BytesProperty::SetValueSize");
  337. }
  338. if (m_values[index] != NULL) {
  339. m_values[index] = (u_int8_t*)MP4Realloc(m_values[index], valueSize);
  340. }
  341. m_valueSizes[index] = valueSize;
  342. }
  343. void MP4BytesProperty::SetFixedSize(u_int32_t fixedSize)
  344. {
  345. m_fixedValueSize = 0;
  346. for (u_int32_t i = 0; i < GetCount(); i++) {
  347. SetValueSize(fixedSize, i);
  348. }
  349. m_fixedValueSize = fixedSize;
  350. }
  351. void MP4BytesProperty::Read(MP4File* pFile, u_int32_t index)
  352. {
  353. if (m_implicit) {
  354. return;
  355. }
  356. MP4Free(m_values[index]);
  357. m_values[index] = (u_int8_t*)MP4Malloc(m_valueSizes[index]);
  358. pFile->ReadBytes(m_values[index], m_valueSizes[index]);
  359. }
  360. void MP4BytesProperty::Write(MP4File* pFile, u_int32_t index)
  361. {
  362. if (m_implicit) {
  363. return;
  364. }
  365. pFile->WriteBytes(m_values[index], m_valueSizes[index]);
  366. }
  367. // MP4TableProperty
  368. MP4TableProperty::MP4TableProperty(char* name, MP4IntegerProperty* pCountProperty)
  369. : MP4Property(name)
  370. {
  371. m_pCountProperty = pCountProperty;
  372. m_pCountProperty->SetReadOnly();
  373. }
  374. MP4TableProperty::~MP4TableProperty()
  375. {
  376. for (u_int32_t i = 0; i < m_pProperties.Size(); i++) {
  377. delete m_pProperties[i];
  378. }
  379. }
  380. void MP4TableProperty::AddProperty(MP4Property* pProperty)
  381. {
  382. ASSERT(pProperty);
  383. ASSERT(pProperty->GetType() != TableProperty);
  384. ASSERT(pProperty->GetType() != DescriptorProperty);
  385. m_pProperties.Add(pProperty);
  386. pProperty->SetParentAtom(m_pParentAtom);
  387. pProperty->SetCount(0);
  388. }
  389. bool MP4TableProperty::FindProperty(const char *name,
  390. MP4Property** ppProperty, u_int32_t* pIndex)
  391. {
  392. ASSERT(m_name);
  393. // check if first component of name matches ourselves
  394. if (!MP4NameFirstMatches(m_name, name)) {
  395. return false;
  396. }
  397. // check if the specified table entry exists
  398. u_int32_t index;
  399. bool haveIndex = MP4NameFirstIndex(name, &index);
  400. if (haveIndex) {
  401. if (index >= GetCount()) {
  402. return false;
  403. }
  404. if (pIndex) {
  405. *pIndex = index;
  406. }
  407. }
  408. VERBOSE_FIND(m_pParentAtom->GetFile()->GetVerbosity(),
  409. printf("FindProperty: matched %s\n", name));
  410. // get name of table property
  411. const char *tablePropName = MP4NameAfterFirst(name);
  412. if (tablePropName == NULL) {
  413. if (!haveIndex) {
  414. *ppProperty = this;
  415. return true;
  416. }
  417. return false;
  418. }
  419. // check if this table property exists
  420. return FindContainedProperty(tablePropName, ppProperty, pIndex);
  421. }
  422. bool MP4TableProperty::FindContainedProperty(const char *name,
  423. MP4Property** ppProperty, u_int32_t* pIndex)
  424. {
  425. u_int32_t numProperties = m_pProperties.Size();
  426. for (u_int32_t i = 0; i < numProperties; i++) {
  427. if (m_pProperties[i]->FindProperty(name, ppProperty, pIndex)) {
  428. return true;
  429. }
  430. }
  431. return false;
  432. }
  433. void MP4TableProperty::Read(MP4File* pFile, u_int32_t index)
  434. {
  435. ASSERT(index == 0);
  436. if (m_implicit) {
  437. return;
  438. }
  439. u_int32_t numProperties = m_pProperties.Size();
  440. if (numProperties == 0) {
  441. WARNING(numProperties == 0);
  442. return;
  443. }
  444. u_int32_t numEntries = GetCount();
  445. /* for each property set size */
  446. for (u_int32_t j = 0; j < numProperties; j++) {
  447. m_pProperties[j]->SetCount(numEntries);
  448. }
  449. for (u_int32_t i = 0; i < numEntries; i++) {
  450. ReadEntry(pFile, i);
  451. }
  452. }
  453. void MP4TableProperty::ReadEntry(MP4File* pFile, u_int32_t index)
  454. {
  455. for (u_int32_t j = 0; j < m_pProperties.Size(); j++) {
  456. m_pProperties[j]->Read(pFile, index);
  457. }
  458. }
  459. void MP4TableProperty::Write(MP4File* pFile, u_int32_t index)
  460. {
  461. ASSERT(index == 0);
  462. if (m_implicit) {
  463. return;
  464. }
  465. u_int32_t numProperties = m_pProperties.Size();
  466. if (numProperties == 0) {
  467. WARNING(numProperties == 0);
  468. return;
  469. }
  470. u_int32_t numEntries = GetCount();
  471. if (m_pProperties[0]->GetCount() != numEntries) {
  472. fprintf(stderr, "%s %s \"%s\"table entries %u doesn't match count %u\n",
  473. GetParentAtom() != NULL ? GetParentAtom()->GetType() : "",
  474. GetName(), m_pProperties[0]->GetName(),
  475. m_pProperties[0]->GetCount(), numEntries);
  476. ASSERT(m_pProperties[0]->GetCount() == numEntries);
  477. }
  478. for (u_int32_t i = 0; i < numEntries; i++) {
  479. WriteEntry(pFile, i);
  480. }
  481. }
  482. void MP4TableProperty::WriteEntry(MP4File* pFile, u_int32_t index)
  483. {
  484. for (u_int32_t j = 0; j < m_pProperties.Size(); j++) {
  485. m_pProperties[j]->Write(pFile, index);
  486. }
  487. }
  488. // MP4DescriptorProperty
  489. MP4DescriptorProperty::MP4DescriptorProperty(char* name,
  490. u_int8_t tagsStart, u_int8_t tagsEnd, bool mandatory, bool onlyOne)
  491. : MP4Property(name)
  492. {
  493. SetTags(tagsStart, tagsEnd);
  494. m_sizeLimit = 0;
  495. m_mandatory = mandatory;
  496. m_onlyOne = onlyOne;
  497. }
  498. MP4DescriptorProperty::~MP4DescriptorProperty()
  499. {
  500. for (u_int32_t i = 0; i < m_pDescriptors.Size(); i++) {
  501. delete m_pDescriptors[i];
  502. }
  503. }
  504. void MP4DescriptorProperty::SetParentAtom(MP4Atom* pParentAtom) {
  505. m_pParentAtom = pParentAtom;
  506. for (u_int32_t i = 0; i < m_pDescriptors.Size(); i++) {
  507. m_pDescriptors[i]->SetParentAtom(pParentAtom);
  508. }
  509. }
  510. MP4Descriptor* MP4DescriptorProperty::AddDescriptor(u_int8_t tag)
  511. {
  512. // check that tag is in expected range
  513. ASSERT(tag >= m_tagsStart && tag <= m_tagsEnd);
  514. MP4Descriptor* pDescriptor = CreateDescriptor(tag);
  515. ASSERT(pDescriptor);
  516. m_pDescriptors.Add(pDescriptor);
  517. pDescriptor->SetParentAtom(m_pParentAtom);
  518. return pDescriptor;
  519. }
  520. void MP4DescriptorProperty::DeleteDescriptor(u_int32_t index)
  521. {
  522. delete m_pDescriptors[index];
  523. m_pDescriptors.Delete(index);
  524. }
  525. void MP4DescriptorProperty::Generate()
  526. {
  527. // generate a default descriptor
  528. // if it is mandatory, and single
  529. if (m_mandatory && m_onlyOne) {
  530. MP4Descriptor* pDescriptor =
  531. AddDescriptor(m_tagsStart);
  532. pDescriptor->Generate();
  533. }
  534. }
  535. bool MP4DescriptorProperty::FindProperty(const char *name,
  536. MP4Property** ppProperty, u_int32_t* pIndex)
  537. {
  538. // we're unnamed, so just check contained properties
  539. if (m_name == NULL || !strcmp(m_name, "")) {
  540. return FindContainedProperty(name, ppProperty, pIndex);
  541. }
  542. // check if first component of name matches ourselves
  543. if (!MP4NameFirstMatches(m_name, name)) {
  544. return false;
  545. }
  546. // check if the specific descriptor entry exists
  547. u_int32_t descrIndex;
  548. bool haveDescrIndex = MP4NameFirstIndex(name, &descrIndex);
  549. if (haveDescrIndex && descrIndex >= GetCount()) {
  550. return false;
  551. }
  552. if (m_pParentAtom) {
  553. VERBOSE_FIND(m_pParentAtom->GetFile()->GetVerbosity(),
  554. printf("FindProperty: matched %s\n", name));
  555. }
  556. // get name of descriptor property
  557. name = MP4NameAfterFirst(name);
  558. if (name == NULL) {
  559. if (!haveDescrIndex) {
  560. *ppProperty = this;
  561. return true;
  562. }
  563. return false;
  564. }
  565. /* check rest of name */
  566. if (haveDescrIndex) {
  567. return m_pDescriptors[descrIndex]->FindProperty(name,
  568. ppProperty, pIndex);
  569. } else {
  570. return FindContainedProperty(name, ppProperty, pIndex);
  571. }
  572. }
  573. bool MP4DescriptorProperty::FindContainedProperty(const char *name,
  574. MP4Property** ppProperty, u_int32_t* pIndex)
  575. {
  576. for (u_int32_t i = 0; i < m_pDescriptors.Size(); i++) {
  577. if (m_pDescriptors[i]->FindProperty(name, ppProperty, pIndex)) {
  578. return true;
  579. }
  580. }
  581. return false;
  582. }
  583. void MP4DescriptorProperty::Read(MP4File* pFile, u_int32_t index)
  584. {
  585. ASSERT(index == 0);
  586. if (m_implicit) {
  587. return;
  588. }
  589. u_int64_t start = pFile->GetPosition();
  590. while (true) {
  591. // enforce size limitation
  592. if (m_sizeLimit && pFile->GetPosition() >= start + m_sizeLimit) {
  593. break;
  594. }
  595. u_int8_t tag;
  596. try {
  597. pFile->PeekBytes(&tag, 1);
  598. }
  599. catch (MP4Error* e) {
  600. if (pFile->GetPosition() >= pFile->GetSize()) {
  601. // EOF
  602. delete e;
  603. break;
  604. }
  605. throw e;
  606. }
  607. // check if tag is in desired range
  608. if (tag < m_tagsStart || tag > m_tagsEnd) {
  609. break;
  610. }
  611. MP4Descriptor* pDescriptor =
  612. AddDescriptor(tag);
  613. pDescriptor->Read(pFile);
  614. }
  615. // warnings
  616. if (m_mandatory && m_pDescriptors.Size() == 0) {
  617. VERBOSE_READ(pFile->GetVerbosity(),
  618. printf("Warning: Mandatory descriptor 0x%02x missing\n",
  619. m_tagsStart));
  620. } else if (m_onlyOne && m_pDescriptors.Size() > 1) {
  621. VERBOSE_READ(pFile->GetVerbosity(),
  622. printf("Warning: Descriptor 0x%02x has more than one instance\n",
  623. m_tagsStart));
  624. }
  625. }
  626. void MP4DescriptorProperty::Write(MP4File* pFile, u_int32_t index)
  627. {
  628. ASSERT(index == 0);
  629. if (m_implicit) {
  630. return;
  631. }
  632. for (u_int32_t i = 0; i < m_pDescriptors.Size(); i++) {
  633. m_pDescriptors[i]->Write(pFile);
  634. }
  635. }