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

多媒体编程

开发平台:

Visual C++

  1. /*****************************************************************
  2. |
  3. |    AP4 - ftyp 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 "Ap4FtypAtom.h"
  33. #include "Ap4AtomFactory.h"
  34. #include "Ap4Utils.h"
  35. /*----------------------------------------------------------------------
  36. |       AP4_FtypAtom::AP4_FtypAtom
  37. +---------------------------------------------------------------------*/
  38. AP4_FtypAtom::AP4_FtypAtom(AP4_Size size, AP4_ByteStream& stream) :
  39.     AP4_Atom(AP4_ATOM_TYPE_FTYP, size, false, stream)
  40. {
  41.     stream.ReadUI32(m_MajorBrand);
  42.     stream.ReadUI32(m_MinorVersion);
  43.     size -= 16;
  44.     while (size) {
  45.         AP4_UI32 compatible_brand;
  46.         stream.ReadUI32(compatible_brand);
  47.         m_CompatibleBrands.Append(compatible_brand);
  48.         size -= 4;
  49.     }
  50. }
  51. /*----------------------------------------------------------------------
  52. |       AP4_FtypAtom::WriteFields
  53. +---------------------------------------------------------------------*/
  54. AP4_Result
  55. AP4_FtypAtom::WriteFields(AP4_ByteStream& stream)
  56. {
  57.     AP4_Result result;
  58.    
  59.     // major brand
  60.     result = stream.WriteUI32(m_MajorBrand);
  61.     if (AP4_FAILED(result)) return result;
  62.     // minor version
  63.     result = stream.WriteUI32(m_MinorVersion);
  64.     if (AP4_FAILED(result)) return result;
  65.     // compatible brands
  66.     AP4_Cardinal compat_brand_count = m_CompatibleBrands.ItemCount();
  67.     for (AP4_Ordinal i=0; i<compat_brand_count; i++) {
  68.         result = stream.WriteUI32(m_CompatibleBrands[i]);
  69.         if (AP4_FAILED(result)) return result;
  70.     }
  71.     return result;
  72. }
  73. /*----------------------------------------------------------------------
  74. |       AP4_FtypAtom::InspectFields
  75. +---------------------------------------------------------------------*/
  76. AP4_Result
  77. AP4_FtypAtom::InspectFields(AP4_AtomInspector& inspector)
  78. {
  79.     char name[5];
  80.     AP4_FormatFourChars(name, m_MajorBrand);
  81.     inspector.AddField("major_brand", name);
  82.     inspector.AddField("minor_version", m_MinorVersion);
  83.     // compatible brands
  84.     for (unsigned int i=0; i<m_CompatibleBrands.ItemCount(); i++) {
  85.         AP4_UI32 cb = m_CompatibleBrands[i];
  86.         AP4_FormatFourChars(name, cb);
  87.         inspector.AddField("compatible_brand", name);
  88.     }
  89.     return AP4_SUCCESS;
  90. }