atom_trun.cpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. MP4TrunAtom::MP4TrunAtom()
  23. : MP4Atom("trun")
  24. {
  25. AddVersionAndFlags(); /* 0, 1 */
  26. AddProperty( /* 2 */
  27. new MP4Integer32Property("sampleCount"));
  28. }
  29. void MP4TrunAtom::AddProperties(u_int32_t flags)
  30. {
  31. if (flags & 0x01) {
  32. // Note this is a signed 32 value
  33. AddProperty(
  34. new MP4Integer32Property("dataOffset"));
  35. }
  36. if (flags & 0x04) {
  37. AddProperty(
  38. new MP4Integer32Property("firstSampleFlags"));
  39. }
  40. MP4TableProperty* pTable =
  41. new MP4TableProperty("samples",
  42. (MP4Integer32Property *)m_pProperties[2]);
  43. AddProperty(pTable);
  44. if (flags & 0x100) {
  45. pTable->AddProperty(
  46. new MP4Integer32Property("sampleDuration"));
  47. }
  48. if (flags & 0x200) {
  49. pTable->AddProperty(
  50. new MP4Integer32Property("sampleSize"));
  51. }
  52. if (flags & 0x400) {
  53. pTable->AddProperty(
  54. new MP4Integer32Property("sampleFlags"));
  55. }
  56. if (flags & 0x800) {
  57. pTable->AddProperty(
  58. new MP4Integer32Property("sampleCompositionTimeOffset"));
  59. }
  60. }
  61. void MP4TrunAtom::Read()
  62. {
  63. /* read atom version, flags, and sampleCount */
  64. ReadProperties(0, 3);
  65. /* need to create the properties based on the atom flags */
  66. AddProperties(GetFlags());
  67. /* now we can read the remaining properties */
  68. ReadProperties(3);
  69. Skip(); // to end of atom
  70. }