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

多媒体编程

开发平台:

Visual C++

  1. /*****************************************************************
  2. |
  3. |    AP4 - dref 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 "Ap4DrefAtom.h"
  33. #include "Ap4AtomFactory.h"
  34. #include "Ap4Utils.h"
  35. #include "Ap4ContainerAtom.h"
  36. /*----------------------------------------------------------------------
  37. |       AP4_DrefAtom::AP4_DrefAtom
  38. +---------------------------------------------------------------------*/
  39. AP4_DrefAtom::AP4_DrefAtom(AP4_Atom** refs, AP4_Cardinal refs_count) :
  40.     AP4_ContainerAtom(AP4_ATOM_TYPE_DREF, AP4_FULL_ATOM_HEADER_SIZE+4, true)
  41. {
  42.     for (unsigned i=0; i<refs_count; i++) {
  43.         m_Children.Add(refs[i]);
  44.         m_Size += refs[i]->GetSize();
  45.     }
  46. }
  47. /*----------------------------------------------------------------------
  48. |       AP4_DrefAtom::AP4_DrefAtom
  49. +---------------------------------------------------------------------*/
  50. AP4_DrefAtom::AP4_DrefAtom(AP4_Size         size,
  51.                            AP4_ByteStream&  stream,
  52.                            AP4_AtomFactory& atom_factory) :
  53.     AP4_ContainerAtom(AP4_ATOM_TYPE_DREF, size, true, stream)
  54. {
  55.     // read the number of entries
  56.     AP4_UI32 entry_count;
  57.     stream.ReadUI32(entry_count);
  58.     // read children
  59.     AP4_Size bytes_available = size-AP4_FULL_ATOM_HEADER_SIZE-4;
  60.     while (entry_count--) {
  61.         AP4_Atom* atom; 
  62.         while (AP4_SUCCEEDED(atom_factory.CreateAtomFromStream(stream, 
  63.                                                                bytes_available,
  64.                                                                atom))) {
  65.             m_Children.Add(atom);
  66.         }
  67.     }
  68. }
  69. /*----------------------------------------------------------------------
  70. |       AP4_DrefAtom::WriteFields
  71. +---------------------------------------------------------------------*/
  72. AP4_Result
  73. AP4_DrefAtom::WriteFields(AP4_ByteStream& stream)
  74. {
  75.     AP4_Result result;
  76.     // write the number of entries
  77.     result = stream.WriteUI32(m_Children.ItemCount());
  78.     if (AP4_FAILED(result)) return result;
  79.     // write the children
  80.     return m_Children.Apply(AP4_AtomListWriter(stream));
  81. }