Ap4MoovAtom.cpp
上传用户:xjjlds
上传日期:2015-12-05
资源大小:22823k
文件大小:4k
源码类别:

多媒体编程

开发平台:

Visual C++

  1. /*****************************************************************
  2. |
  3. |    AP4 - moov Atoms 
  4. |
  5. |    Copyright 2002 Gilles Boccon-Gibod
  6. |
  7. |
  8. |    This file is part of Bento4/AP4 (MP4 Atom Processing Library).
  9. |
  10. |    Unless you have obtained Bento4 under a difference license,
  11. |    this version of Bento4 is Bento4|GPL.
  12. |    Bento4|GPL is free software; you can redistribute it and/or modify
  13. |    it under the terms of the GNU General Public License as published by
  14. |    the Free Software Foundation; either version 2, or (at your option)
  15. |    any later version.
  16. |
  17. |    Bento4|GPL is distributed in the hope that it will be useful,
  18. |    but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. |    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20. |    GNU General Public License for more details.
  21. |
  22. |    You should have received a copy of the GNU General Public License
  23. |    along with Bento4|GPL; see the file COPYING.  If not, write to the
  24. |    Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
  25. |    02111-1307, USA.
  26. |
  27.  ****************************************************************/
  28. /*----------------------------------------------------------------------
  29. |       includes
  30. +---------------------------------------------------------------------*/
  31. #include "Ap4.h"
  32. #include "Ap4MoovAtom.h"
  33. #include "Ap4TrakAtom.h"
  34. #include "Ap4AtomFactory.h"
  35. /*----------------------------------------------------------------------
  36. |       AP4_TrakAtomCollector
  37. +---------------------------------------------------------------------*/
  38. class AP4_TrakAtomCollector : public AP4_List<AP4_Atom>::Item::Operator
  39. {
  40. public:
  41.     AP4_TrakAtomCollector(AP4_List<AP4_TrakAtom>* track_atoms) :
  42.         m_TrakAtoms(track_atoms) {}
  43.     AP4_Result Action(AP4_Atom* atom) const {
  44.         if (atom->GetType() == AP4_ATOM_TYPE_TRAK) {
  45.             AP4_TrakAtom* trak = dynamic_cast<AP4_TrakAtom*>(atom);
  46.             if (trak) {
  47.                 m_TrakAtoms->Add(trak);
  48.             }
  49.         }
  50.         return AP4_SUCCESS;
  51.     }
  52. private:
  53.     AP4_List<AP4_TrakAtom>* m_TrakAtoms;
  54. };
  55. /*----------------------------------------------------------------------
  56. |       AP4_MoovAtom::AP4_MoovAtom
  57. +---------------------------------------------------------------------*/
  58. AP4_MoovAtom::AP4_MoovAtom() :
  59.     AP4_ContainerAtom(AP4_ATOM_TYPE_MOOV),
  60.     m_TimeScale(0)
  61. {
  62. }
  63. /*----------------------------------------------------------------------
  64. |       AP4_MoovAtom::AP4_MoovAtom
  65. +---------------------------------------------------------------------*/
  66. AP4_MoovAtom::AP4_MoovAtom(AP4_Size         size,
  67.                            AP4_ByteStream&  stream,
  68.                            AP4_AtomFactory& atom_factory) :
  69.     AP4_ContainerAtom(AP4_ATOM_TYPE_MOOV, size, false, stream, atom_factory),
  70.     m_TimeScale(0)
  71. {
  72.     // collect all trak atoms
  73.     m_Children.Apply(AP4_TrakAtomCollector(&m_TrakAtoms));    
  74. }
  75. /*----------------------------------------------------------------------
  76. |       AP4_MoovAtom::OnChildAdded
  77. +---------------------------------------------------------------------*/
  78. void
  79. AP4_MoovAtom::OnChildAdded(AP4_Atom* atom)
  80. {
  81.     // keep the atom in the list of trak atoms
  82.     if (atom->GetType() == AP4_ATOM_TYPE_TRAK) {
  83.         AP4_TrakAtom* trak = dynamic_cast<AP4_TrakAtom*>(atom);
  84.         if (trak) {
  85.             m_TrakAtoms.Add(trak);
  86.         }
  87.     }
  88.     // call the base class implementation
  89.     AP4_ContainerAtom::OnChildAdded(atom);
  90. }
  91. /*----------------------------------------------------------------------
  92. |       AP4_MoovAtom::OnChildRemoved
  93. +---------------------------------------------------------------------*/
  94. void
  95. AP4_MoovAtom::OnChildRemoved(AP4_Atom* atom)
  96. {
  97.     // remove the atom from the list of trak atoms
  98.     if (atom->GetType() == AP4_ATOM_TYPE_TRAK) {
  99.         AP4_TrakAtom* trak = dynamic_cast<AP4_TrakAtom*>(atom);
  100.         if (trak) {
  101.             m_TrakAtoms.Remove(trak);
  102.         }
  103.     }
  104.     // call the base class implementation
  105.     AP4_ContainerAtom::OnChildRemoved(atom);
  106. }