1
0

atom_hdlr.cpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. MP4HdlrAtom::MP4HdlrAtom()
  23. : MP4Atom("hdlr")
  24. {
  25. AddVersionAndFlags(); /* 0, 1 */
  26. AddReserved("reserved1", 4); /* 2 */
  27. MP4StringProperty* pProp = new MP4StringProperty("handlerType");
  28. pProp->SetFixedLength(4);
  29. AddProperty(pProp); /* 3 */
  30. AddReserved("reserved2", 12); /* 4 */
  31. AddProperty( /* 5 */
  32. new MP4StringProperty("name"));
  33. }
  34. // There is a spec incompatiblity between QT and MP4
  35. // QT says name field is a counted string
  36. // MP4 says name field is a null terminated string
  37. // Here we attempt to make all things work
  38. void MP4HdlrAtom::Read()
  39. {
  40. // read all the properties but the "name" field
  41. ReadProperties(0, 5);
  42. uint64_t pos = m_pFile->GetPosition();
  43. uint64_t end = GetEnd();
  44. if (pos == end) return;
  45. // take a peek at the next byte
  46. u_int8_t strLength;
  47. m_pFile->PeekBytes(&strLength, 1);
  48. // if the value matches the remaining atom length
  49. if (pos + strLength + 1 == end) {
  50. // read a counted string
  51. MP4StringProperty* pNameProp =
  52. (MP4StringProperty*)m_pProperties[5];
  53. pNameProp->SetCountedFormat(true);
  54. ReadProperties(5);
  55. pNameProp->SetCountedFormat(false);
  56. } else {
  57. // read a null terminated string
  58. ReadProperties(5);
  59. }
  60. Skip(); // to end of atom
  61. }