1
0

atom_sound.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. 2004. All Rights Reserved.
  17. *
  18. * Contributor(s):
  19. * Bill May [email protected]
  20. */
  21. #include "mp4common.h"
  22. MP4SoundAtom::MP4SoundAtom(const char *atomid)
  23. : MP4Atom(atomid)
  24. {
  25. AddReserved("reserved1", 6); /* 0 */
  26. AddProperty( /* 1 */
  27. new MP4Integer16Property("dataReferenceIndex"));
  28. AddProperty( /* 2 */
  29. new MP4Integer16Property("soundVersion"));
  30. AddReserved( "reserved2", 6); /* 3 */
  31. AddProperty( /* 4 */
  32. new MP4Integer16Property("channels"));
  33. AddProperty( /* 5 */
  34. new MP4Integer16Property("sampleSize"));
  35. AddProperty( /* 6 */
  36. new MP4Integer16Property("packetSize"));
  37. AddProperty( /* 7 */
  38. new MP4Integer32Property("timeScale"));
  39. if (ATOMID(atomid) == ATOMID("mp4a")) {
  40. AddReserved("reserved3", 2); /* 8 */
  41. ExpectChildAtom("esds", Required, OnlyOne);
  42. ExpectChildAtom("wave", Optional, OnlyOne);
  43. } else if (ATOMID(atomid) == ATOMID("alac")) {
  44. AddReserved("reserved3", 2); /* 8 */
  45. ExpectChildAtom("alac", Optional, Optional);
  46. //AddProperty( new MP4BytesProperty("alacInfo", 36));
  47. }
  48. }
  49. void MP4SoundAtom::AddProperties (uint8_t version)
  50. {
  51. if (version > 0) {
  52. AddProperty( /* 8 */
  53. new MP4Integer32Property("samplesPerPacket"));
  54. AddProperty( /* 9 */
  55. new MP4Integer32Property("bytesPerPacket"));
  56. AddProperty( /* 10 */
  57. new MP4Integer32Property("bytesPerFrame"));
  58. AddProperty( /* 11 */
  59. new MP4Integer32Property("bytesPerSample"));
  60. }
  61. if (version == 2) {
  62. AddReserved("reserved4", 20);
  63. }
  64. }
  65. void MP4SoundAtom::Generate()
  66. {
  67. MP4Atom::Generate();
  68. ((MP4Integer16Property*)m_pProperties[1])->SetValue(1);
  69. // property reserved2 has non-zero fixed values
  70. ((MP4Integer16Property*)m_pProperties[2])->SetValue(0);
  71. static const u_int8_t reserved2[6] = {
  72. 0x00, 0x00, 0x00, 0x00,
  73. 0x00, 0x00,
  74. };
  75. m_pProperties[3]->SetReadOnly(false);
  76. ((MP4BytesProperty*)m_pProperties[3])->
  77. SetValue(reserved2, sizeof(reserved2));
  78. m_pProperties[3]->SetReadOnly(true);
  79. ((MP4Integer16Property*)m_pProperties[4])->SetValue(2);
  80. ((MP4Integer16Property*)m_pProperties[5])->SetValue(0x0010);
  81. ((MP4Integer16Property*)m_pProperties[6])->SetValue(0);
  82. }
  83. void MP4SoundAtom::Read()
  84. {
  85. MP4Atom *parent = GetParentAtom();
  86. if (ATOMID(parent->GetType()) != ATOMID("stsd")) {
  87. // Quicktime has an interesting thing - they'll put an mp4a atom
  88. // which is blank inside a wave atom, which is inside an mp4a atom
  89. // we have a mp4a inside an wave inside an mp4a - delete all properties
  90. m_pProperties.Delete(8);
  91. m_pProperties.Delete(7);
  92. m_pProperties.Delete(6);
  93. m_pProperties.Delete(5);
  94. m_pProperties.Delete(4);
  95. m_pProperties.Delete(3);
  96. m_pProperties.Delete(2);
  97. m_pProperties.Delete(1);
  98. m_pProperties.Delete(0);
  99. if (ATOMID(GetType()) == ATOMID("alac")) {
  100. AddProperty(new MP4BytesProperty("decoderConfig", m_size));
  101. ReadProperties();
  102. }
  103. if (m_pChildAtomInfos.Size() > 0) {
  104. ReadChildAtoms();
  105. }
  106. } else {
  107. ReadProperties(0, 3); // read first 3 properties
  108. AddProperties(((MP4IntegerProperty *)m_pProperties[2])->GetValue());
  109. ReadProperties(3); // continue
  110. if (m_pChildAtomInfos.Size() > 0) {
  111. ReadChildAtoms();
  112. }
  113. }
  114. Skip();
  115. }