1
0

atom_tkhd.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. MP4TkhdAtom::MP4TkhdAtom()
  23. : MP4Atom("tkhd")
  24. {
  25. AddVersionAndFlags();
  26. }
  27. void MP4TkhdAtom::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 { // version == 0
  35. AddProperty( /* 2 */
  36. new MP4Integer32Property("creationTime"));
  37. AddProperty( /* 3 */
  38. new MP4Integer32Property("modificationTime"));
  39. }
  40. AddProperty( /* 4 */
  41. new MP4Integer32Property("trackId"));
  42. AddReserved("reserved1", 4); /* 5 */
  43. if (version == 1) {
  44. AddProperty( /* 6 */
  45. new MP4Integer64Property("duration"));
  46. } else {
  47. AddProperty( /* 6 */
  48. new MP4Integer32Property("duration"));
  49. }
  50. AddReserved("reserved2", 12); /* 7 */
  51. MP4Float32Property* pProp;
  52. pProp = new MP4Float32Property("volume");
  53. pProp->SetFixed16Format();
  54. AddProperty(pProp); /* 8 */
  55. AddReserved("reserved3", 2); /* 9 */
  56. AddProperty(new MP4BytesProperty("matrix", 36)); /* 10 */
  57. pProp = new MP4Float32Property("width");
  58. pProp->SetFixed32Format();
  59. AddProperty(pProp); /* 11 */
  60. pProp = new MP4Float32Property("height");
  61. pProp->SetFixed32Format();
  62. AddProperty(pProp); /* 12 */
  63. }
  64. void MP4TkhdAtom::Generate()
  65. {
  66. u_int8_t version = m_pFile->Use64Bits(GetType()) ? 1 : 0;
  67. SetVersion(version);
  68. AddProperties(version);
  69. MP4Atom::Generate();
  70. // set creation and modification times
  71. MP4Timestamp now = MP4GetAbsTimestamp();
  72. if (version == 1) {
  73. ((MP4Integer64Property*)m_pProperties[2])->SetValue(now);
  74. ((MP4Integer64Property*)m_pProperties[3])->SetValue(now);
  75. } else {
  76. ((MP4Integer32Property*)m_pProperties[2])->SetValue(now);
  77. ((MP4Integer32Property*)m_pProperties[3])->SetValue(now);
  78. }
  79. // property "matrix" has non-zero fixed values
  80. // this default identity matrix indicates no transformation, i.e.
  81. // 1, 0, 0
  82. // 0, 1, 0
  83. // 0, 0, 1
  84. // see http://developer.apple.com/documentation/QuickTime/QTFF/QTFFChap4/chapter_5_section_4.html
  85. static u_int8_t matrix[36] = {
  86. 0x00, 0x01, 0x00, 0x00,
  87. 0x00, 0x00, 0x00, 0x00,
  88. 0x00, 0x00, 0x00, 0x00,
  89. 0x00, 0x00, 0x00, 0x00,
  90. 0x00, 0x01, 0x00, 0x00,
  91. 0x00, 0x00, 0x00, 0x00,
  92. 0x00, 0x00, 0x00, 0x00,
  93. 0x00, 0x00, 0x00, 0x00,
  94. 0x40, 0x00, 0x00, 0x00,
  95. };
  96. ((MP4BytesProperty*)m_pProperties[10])->
  97. SetValue(matrix, sizeof(matrix));
  98. }
  99. void MP4TkhdAtom::Read()
  100. {
  101. /* read atom version */
  102. ReadProperties(0, 1);
  103. /* need to create the properties based on the atom version */
  104. AddProperties(GetVersion());
  105. /* now we can read the remaining properties */
  106. ReadProperties(1);
  107. Skip(); // to end of atom
  108. }