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

多媒体编程

开发平台:

Visual C++

  1. /*****************************************************************
  2. |
  3. |    AP4 - Descriptors 
  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. #ifndef _AP4_DESCRIPTOR_H_
  29. #define _AP4_DESCRIPTOR_H_
  30. /*----------------------------------------------------------------------
  31. |       includes
  32. +---------------------------------------------------------------------*/
  33. #include "Ap4.h"
  34. #include "Ap4ByteStream.h"
  35. #include "Ap4List.h"
  36. #include "Ap4Atom.h"
  37. /*----------------------------------------------------------------------
  38. |       AP4_Descriptor
  39. +---------------------------------------------------------------------*/
  40. class AP4_Descriptor 
  41. {
  42.  public:
  43.     // types
  44.     typedef unsigned char Tag;
  45.     // class methods
  46.     static AP4_Size MinHeaderSize(AP4_Size payload_size);
  47.     // methods
  48.     AP4_Descriptor(Tag tag, AP4_Size header_size, AP4_Size payload_size);
  49.     virtual ~AP4_Descriptor() {}
  50.     Tag                GetTag()  { return m_Tag; }
  51.     AP4_Size           GetSize() { return m_PayloadSize+m_HeaderSize; }
  52.     AP4_Size           GetHeaderSize() { return m_HeaderSize; }
  53.     virtual AP4_Result Write(AP4_ByteStream& stream);
  54.     virtual AP4_Result WriteFields(AP4_ByteStream& stream) = 0;
  55.     virtual AP4_Result Inspect(AP4_AtomInspector& inspector);
  56.  protected:
  57.     // members
  58.     Tag      m_Tag;
  59.     AP4_Size m_HeaderSize;
  60.     AP4_Size m_PayloadSize;
  61. };
  62. /*----------------------------------------------------------------------
  63. |       AP4_DescriptorFinder
  64. +---------------------------------------------------------------------*/
  65. class AP4_DescriptorFinder : public AP4_List<AP4_Descriptor>::Item::Finder
  66. {
  67.  public:
  68.     AP4_DescriptorFinder(AP4_Descriptor::Tag tag) : m_Tag(tag) {}
  69.     AP4_Result Test(AP4_Descriptor* descriptor) const {
  70.         return descriptor->GetTag() == m_Tag ? AP4_SUCCESS : AP4_FAILURE;
  71.     }
  72.  private:
  73.     AP4_Descriptor::Tag m_Tag;
  74. };
  75. /*----------------------------------------------------------------------
  76. |       AP4_DescriptorListWriter
  77. +---------------------------------------------------------------------*/
  78. class AP4_DescriptorListWriter : public AP4_List<AP4_Descriptor>::Item::Operator
  79. {
  80. public:
  81.     AP4_DescriptorListWriter(AP4_ByteStream& stream) :
  82.       m_Stream(stream) {}
  83.     AP4_Result Action(AP4_Descriptor* descriptor) const {
  84.         return descriptor->Write(m_Stream);
  85.     }
  86. private:
  87.     AP4_ByteStream& m_Stream;
  88. };
  89. /*----------------------------------------------------------------------
  90. |       AP4_DescriptorListInspector
  91. +---------------------------------------------------------------------*/
  92. class AP4_DescriptorListInspector : public AP4_List<AP4_Descriptor>::Item::Operator
  93. {
  94.  public:
  95.     AP4_DescriptorListInspector(AP4_AtomInspector& inspector) :
  96.         m_Inspector(inspector) {}
  97.     AP4_Result Action(AP4_Descriptor* descriptor) const {
  98.         descriptor->Inspect(m_Inspector);
  99.         return AP4_SUCCESS;
  100.     }
  101.  private:
  102.     AP4_AtomInspector& m_Inspector;
  103. };
  104. #endif // _AP4_DESCRIPTOR_H_