00001 /***************************************************************** 00002 | 00003 | AP4 - Descriptors 00004 | 00005 | Copyright 2002-2006 Gilles Boccon-Gibod & Julien Boeuf 00006 | 00007 | 00008 | This file is part of Bento4/AP4 (MP4 Atom Processing Library). 00009 | 00010 | Unless you have obtained Bento4 under a difference license, 00011 | this version of Bento4 is Bento4|GPL. 00012 | Bento4|GPL is free software; you can redistribute it and/or modify 00013 | it under the terms of the GNU General Public License as published by 00014 | the Free Software Foundation; either version 2, or (at your option) 00015 | any later version. 00016 | 00017 | Bento4|GPL is distributed in the hope that it will be useful, 00018 | but WITHOUT ANY WARRANTY; without even the implied warranty of 00019 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00020 | GNU General Public License for more details. 00021 | 00022 | You should have received a copy of the GNU General Public License 00023 | along with Bento4|GPL; see the file COPYING. If not, write to the 00024 | Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 00025 | 02111-1307, USA. 00026 | 00027 ****************************************************************/ 00028 00029 #ifndef _AP4_DESCRIPTOR_H_ 00030 #define _AP4_DESCRIPTOR_H_ 00031 00032 /*---------------------------------------------------------------------- 00033 | includes 00034 +---------------------------------------------------------------------*/ 00035 #include "Ap4Types.h" 00036 #include "Ap4List.h" 00037 00038 /*---------------------------------------------------------------------- 00039 | class references 00040 +---------------------------------------------------------------------*/ 00041 class AP4_ByteStream; 00042 class AP4_AtomInspector; 00043 00044 /*---------------------------------------------------------------------- 00045 | AP4_Descriptor 00046 +---------------------------------------------------------------------*/ 00047 class AP4_Descriptor 00048 { 00049 public: 00050 // types 00051 typedef unsigned char Tag; 00052 00053 // class methods 00054 static AP4_Size MinHeaderSize(AP4_Size payload_size); 00055 00056 // methods 00057 AP4_Descriptor(Tag tag, AP4_Size header_size, AP4_Size payload_size); 00058 virtual ~AP4_Descriptor() {} 00059 Tag GetTag() { return m_Tag; } 00060 AP4_Size GetSize() { return m_PayloadSize+m_HeaderSize; } 00061 AP4_Size GetHeaderSize() { return m_HeaderSize; } 00062 virtual AP4_Result Write(AP4_ByteStream& stream); 00063 virtual AP4_Result WriteFields(AP4_ByteStream& stream) = 0; 00064 virtual AP4_Result Inspect(AP4_AtomInspector& inspector); 00065 00066 protected: 00067 // members 00068 Tag m_Tag; 00069 AP4_Size m_HeaderSize; 00070 AP4_Size m_PayloadSize; 00071 }; 00072 00073 /*---------------------------------------------------------------------- 00074 | AP4_DescriptorFinder 00075 +---------------------------------------------------------------------*/ 00076 class AP4_DescriptorFinder : public AP4_List<AP4_Descriptor>::Item::Finder 00077 { 00078 public: 00079 AP4_DescriptorFinder(AP4_Descriptor::Tag tag) : m_Tag(tag) {} 00080 AP4_Result Test(AP4_Descriptor* descriptor) const { 00081 return descriptor->GetTag() == m_Tag ? AP4_SUCCESS : AP4_FAILURE; 00082 } 00083 private: 00084 AP4_Descriptor::Tag m_Tag; 00085 }; 00086 00087 /*---------------------------------------------------------------------- 00088 | AP4_DescriptorListWriter 00089 +---------------------------------------------------------------------*/ 00090 class AP4_DescriptorListWriter : public AP4_List<AP4_Descriptor>::Item::Operator 00091 { 00092 public: 00093 AP4_DescriptorListWriter(AP4_ByteStream& stream) : 00094 m_Stream(stream) {} 00095 AP4_Result Action(AP4_Descriptor* descriptor) const { 00096 return descriptor->Write(m_Stream); 00097 } 00098 00099 private: 00100 AP4_ByteStream& m_Stream; 00101 }; 00102 00103 /*---------------------------------------------------------------------- 00104 | AP4_DescriptorListInspector 00105 +---------------------------------------------------------------------*/ 00106 class AP4_DescriptorListInspector : public AP4_List<AP4_Descriptor>::Item::Operator 00107 { 00108 public: 00109 AP4_DescriptorListInspector(AP4_AtomInspector& inspector) : 00110 m_Inspector(inspector) {} 00111 AP4_Result Action(AP4_Descriptor* descriptor) const { 00112 descriptor->Inspect(m_Inspector); 00113 return AP4_SUCCESS; 00114 } 00115 00116 private: 00117 AP4_AtomInspector& m_Inspector; 00118 }; 00119 00120 #endif // _AP4_DESCRIPTOR_H_