atom_mdhd.cpp 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. MP4MdhdAtom::MP4MdhdAtom()
  23. : MP4Atom("mdhd")
  24. {
  25. AddVersionAndFlags();
  26. }
  27. void MP4MdhdAtom::AddProperties(u_int8_t version)
  28. {
  29. if (version == 1) {
  30. AddProperty(
  31. new MP4Integer64Property("creationTime"));
  32. AddProperty(
  33. new MP4Integer64Property("modificationTime"));
  34. } else {
  35. AddProperty(
  36. new MP4Integer32Property("creationTime"));
  37. AddProperty(
  38. new MP4Integer32Property("modificationTime"));
  39. }
  40. AddProperty(
  41. new MP4Integer32Property("timeScale"));
  42. if (version == 1) {
  43. AddProperty(
  44. new MP4Integer64Property("duration"));
  45. } else {
  46. AddProperty(
  47. new MP4Integer32Property("duration"));
  48. }
  49. AddProperty(
  50. new MP4Integer16Property("language"));
  51. AddReserved("reserved", 2);
  52. }
  53. void MP4MdhdAtom::Generate()
  54. {
  55. u_int8_t version = m_pFile->Use64Bits(GetType()) ? 1 : 0;
  56. SetVersion(version);
  57. AddProperties(version);
  58. MP4Atom::Generate();
  59. // set creation and modification times
  60. MP4Timestamp now = MP4GetAbsTimestamp();
  61. if (version == 1) {
  62. ((MP4Integer64Property*)m_pProperties[2])->SetValue(now);
  63. ((MP4Integer64Property*)m_pProperties[3])->SetValue(now);
  64. } else {
  65. ((MP4Integer32Property*)m_pProperties[2])->SetValue(now);
  66. ((MP4Integer32Property*)m_pProperties[3])->SetValue(now);
  67. }
  68. }
  69. void MP4MdhdAtom::Read()
  70. {
  71. /* read atom version */
  72. ReadProperties(0, 1);
  73. /* need to create the properties based on the atom version */
  74. AddProperties(GetVersion());
  75. /* now we can read the remaining properties */
  76. ReadProperties(1);
  77. Skip(); // to end of atom
  78. }