1
0

atom_mvhd.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. MP4MvhdAtom::MP4MvhdAtom()
  23. : MP4Atom("mvhd")
  24. {
  25. AddVersionAndFlags();
  26. }
  27. void MP4MvhdAtom::AddProperties(u_int8_t version)
  28. {
  29. if (version == 1) {
  30. AddProperty( /* 2 */
  31. new MP4Integer64Property("creationTime"));
  32. AddProperty( /* 3 */
  33. new MP4Integer64Property("modificationTime"));
  34. } else {
  35. AddProperty( /* 2 */
  36. new MP4Integer32Property("creationTime"));
  37. AddProperty( /* 3 */
  38. new MP4Integer32Property("modificationTime"));
  39. }
  40. AddProperty( /* 4 */
  41. new MP4Integer32Property("timeScale"));
  42. if (version == 1) {
  43. AddProperty( /* 5 */
  44. new MP4Integer64Property("duration"));
  45. } else {
  46. AddProperty( /* 5 */
  47. new MP4Integer32Property("duration"));
  48. }
  49. MP4Float32Property* pProp;
  50. pProp = new MP4Float32Property("rate");
  51. pProp->SetFixed32Format();
  52. AddProperty(pProp); /* 6 */
  53. pProp = new MP4Float32Property("volume");
  54. pProp->SetFixed16Format();
  55. AddProperty(pProp); /* 7 */
  56. AddReserved("reserved1", 70); /* 8 */
  57. AddProperty( /* 9 */
  58. new MP4Integer32Property("nextTrackId"));
  59. }
  60. void MP4MvhdAtom::Generate()
  61. {
  62. u_int8_t version = m_pFile->Use64Bits(GetType()) ? 1 : 0;
  63. SetVersion(version);
  64. AddProperties(version);
  65. MP4Atom::Generate();
  66. // set creation and modification times
  67. MP4Timestamp now = MP4GetAbsTimestamp();
  68. if (version == 1) {
  69. ((MP4Integer64Property*)m_pProperties[2])->SetValue(now);
  70. ((MP4Integer64Property*)m_pProperties[3])->SetValue(now);
  71. } else {
  72. ((MP4Integer32Property*)m_pProperties[2])->SetValue(now);
  73. ((MP4Integer32Property*)m_pProperties[3])->SetValue(now);
  74. }
  75. ((MP4Integer32Property*)m_pProperties[4])->SetValue(1000);
  76. ((MP4Float32Property*)m_pProperties[6])->SetValue(1.0);
  77. ((MP4Float32Property*)m_pProperties[7])->SetValue(1.0);
  78. // property reserved has non-zero fixed values
  79. static u_int8_t reserved[70] = {
  80. 0x00, 0x00,
  81. 0x00, 0x00, 0x00, 0x00,
  82. 0x00, 0x00, 0x00, 0x00,
  83. 0x00, 0x01, 0x00, 0x00,
  84. 0x00, 0x00, 0x00, 0x00,
  85. 0x00, 0x00, 0x00, 0x00,
  86. 0x00, 0x00, 0x00, 0x00,
  87. 0x00, 0x01, 0x00, 0x00,
  88. 0x00, 0x00, 0x00, 0x00,
  89. 0x00, 0x00, 0x00, 0x00,
  90. 0x00, 0x00, 0x00, 0x00,
  91. 0x40, 0x00, 0x00, 0x00,
  92. 0x00, 0x00, 0x00, 0x00,
  93. 0x00, 0x00, 0x00, 0x00,
  94. 0x00, 0x00, 0x00, 0x00,
  95. 0x00, 0x00, 0x00, 0x00,
  96. 0x00, 0x00, 0x00, 0x00,
  97. 0x00, 0x00, 0x00, 0x00,
  98. };
  99. m_pProperties[8]->SetReadOnly(false);
  100. ((MP4BytesProperty*)m_pProperties[8])->
  101. SetValue(reserved, sizeof(reserved));
  102. m_pProperties[8]->SetReadOnly(true);
  103. // set next track id
  104. ((MP4Integer32Property*)m_pProperties[9])->SetValue(1);
  105. }
  106. void MP4MvhdAtom::Read()
  107. {
  108. /* read atom version */
  109. ReadProperties(0, 1);
  110. /* need to create the properties based on the atom version */
  111. AddProperties(GetVersion());
  112. /* now we can read the remaining properties */
  113. ReadProperties(1);
  114. Skip(); // to end of atom
  115. }