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

多媒体编程

开发平台:

Visual C++

  1. /*****************************************************************
  2. |
  3. |    AP4 - File
  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 "Ap4File.h"
  32. #include "Ap4Atom.h"
  33. #include "Ap4TrakAtom.h"
  34. #include "Ap4MoovAtom.h"
  35. #include "Ap4MvhdAtom.h"
  36. #include "Ap4AtomFactory.h"
  37. /*----------------------------------------------------------------------
  38. |       AP4_File::AP4_File
  39. +---------------------------------------------------------------------*/
  40. AP4_File::AP4_File(AP4_Movie* movie) :
  41.     m_Movie(movie)
  42. {
  43. }
  44. /*----------------------------------------------------------------------
  45. |       AP4_File::AP4_File
  46. +---------------------------------------------------------------------*/
  47. AP4_File::AP4_File(AP4_ByteStream& stream, AP4_AtomFactory& atom_factory) :
  48.     m_Movie(NULL)
  49. {
  50.     // get all atoms
  51.     AP4_Atom* atom;
  52.     while (AP4_SUCCEEDED(atom_factory.CreateAtomFromStream(stream, atom))) {
  53.         switch (atom->GetType()) {
  54.             case AP4_ATOM_TYPE_MOOV:
  55.                 m_Movie = new AP4_Movie(dynamic_cast<AP4_MoovAtom*>(atom),
  56.                                         stream);
  57.                 break;
  58.             default:
  59.                 m_OtherAtoms.Add(atom);
  60.         }
  61.     }
  62. }
  63.     
  64. /*----------------------------------------------------------------------
  65. |       AP4_File::~AP4_File
  66. +---------------------------------------------------------------------*/
  67. AP4_File::~AP4_File()
  68. {
  69.     delete m_Movie;
  70.     m_OtherAtoms.DeleteReferences();
  71. }
  72. /*----------------------------------------------------------------------
  73. |       AP4_File::Inspect
  74. +---------------------------------------------------------------------*/
  75. AP4_Result
  76. AP4_File::Inspect(AP4_AtomInspector& inspector)
  77. {
  78.     // dump the moov atom first
  79.     if (m_Movie) m_Movie->Inspect(inspector);
  80.     // dump the other atoms
  81.     m_OtherAtoms.Apply(AP4_AtomListInspector(inspector));
  82.     return AP4_SUCCESS;
  83. }