Ap4MetaData.h

Go to the documentation of this file.
00001 /*****************************************************************
00002 |
00003 |    AP4 - MetaData 
00004 |
00005 |    Copyright 2002-2006 Gilles Boccon-Gibod & Julien Boeuf & 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_META_DATA_H_
00030 #define _AP4_META_DATA_H_
00031 
00032 /*----------------------------------------------------------------------
00033 |   includes
00034 +---------------------------------------------------------------------*/
00035 #include "Ap4Atom.h"
00036 #include "Ap4AtomFactory.h"
00037 #include "Ap4String.h"
00038 #include "Ap4Array.h"
00039 #include "Ap4List.h"
00040 
00041 /*----------------------------------------------------------------------
00042 |   class references
00043 +---------------------------------------------------------------------*/
00044 class AP4_MoovAtom;
00045 class AP4_DataBuffer;
00046 class AP4_ContainerAtom;
00047 class AP4_DataAtom;
00048 
00049 /*----------------------------------------------------------------------
00050 |   metadata keys
00051 +---------------------------------------------------------------------*/
00052 const AP4_Atom::Type AP4_ATOM_TYPE_DATA = AP4_ATOM_TYPE('d','a','t','a'); // data
00053 const AP4_Atom::Type AP4_ATOM_TYPE_MEAN = AP4_ATOM_TYPE('m','e','a','n'); // namespace
00054 const AP4_Atom::Type AP4_ATOM_TYPE_NAME = AP4_ATOM_TYPE('n','a','m','e'); // name
00055 const AP4_Atom::Type AP4_ATOM_TYPE_dddd = AP4_ATOM_TYPE('-','-','-','-'); // free form
00056 const AP4_Atom::Type AP4_ATOM_TYPE_cNAM = AP4_ATOM_TYPE('©','n','a','m'); // name
00057 const AP4_Atom::Type AP4_ATOM_TYPE_cART = AP4_ATOM_TYPE('©','A','R','T'); // artist
00058 const AP4_Atom::Type AP4_ATOM_TYPE_cCOM = AP4_ATOM_TYPE('©','c','o','m'); // composer
00059 const AP4_Atom::Type AP4_ATOM_TYPE_cWRT = AP4_ATOM_TYPE('©','w','r','t'); // writer
00060 const AP4_Atom::Type AP4_ATOM_TYPE_cALB = AP4_ATOM_TYPE('©','a','l','b'); // album
00061 const AP4_Atom::Type AP4_ATOM_TYPE_cGEN = AP4_ATOM_TYPE('©','g','e','n'); // genre
00062 const AP4_Atom::Type AP4_ATOM_TYPE_cGRP = AP4_ATOM_TYPE('©','g','r','p'); // group
00063 const AP4_Atom::Type AP4_ATOM_TYPE_cDAY = AP4_ATOM_TYPE('©','d','a','y'); // date
00064 const AP4_Atom::Type AP4_ATOM_TYPE_cTOO = AP4_ATOM_TYPE('©','t','o','o'); // tool
00065 const AP4_Atom::Type AP4_ATOM_TYPE_cCMT = AP4_ATOM_TYPE('©','c','m','t'); // comment
00066 const AP4_Atom::Type AP4_ATOM_TYPE_cLYR = AP4_ATOM_TYPE('©','l','y','r'); // lyrics
00067 const AP4_Atom::Type AP4_ATOM_TYPE_CPRT = AP4_ATOM_TYPE('c','p','r','t'); // copyright
00068 const AP4_Atom::Type AP4_ATOM_TYPE_TRKN = AP4_ATOM_TYPE('t','r','k','n'); // track#
00069 const AP4_Atom::Type AP4_ATOM_TYPE_DISK = AP4_ATOM_TYPE('d','i','s','k'); // disk#
00070 const AP4_Atom::Type AP4_ATOM_TYPE_COVR = AP4_ATOM_TYPE('c','o','v','r'); // cover art
00071 const AP4_Atom::Type AP4_ATOM_TYPE_DESC = AP4_ATOM_TYPE('d','e','s','c'); // description
00072 const AP4_Atom::Type AP4_ATOM_TYPE_GNRE = AP4_ATOM_TYPE('g','n','r','e'); // genre (ID3v1 index + 1)
00073 const AP4_Atom::Type AP4_ATOM_TYPE_CPIL = AP4_ATOM_TYPE('c','p','i','l'); // compilation?
00074 const AP4_Atom::Type AP4_ATOM_TYPE_TMPO = AP4_ATOM_TYPE('t','m','p','o'); // tempo
00075 const AP4_Atom::Type AP4_ATOM_TYPE_RTNG = AP4_ATOM_TYPE('r','t','n','g'); // rating
00076 const AP4_Atom::Type AP4_ATOM_TYPE_apID = AP4_ATOM_TYPE('a','p','I','D');
00077 const AP4_Atom::Type AP4_ATOM_TYPE_cnID = AP4_ATOM_TYPE('c','n','I','D');
00078 const AP4_Atom::Type AP4_ATOM_TYPE_atID = AP4_ATOM_TYPE('a','t','I','D');
00079 const AP4_Atom::Type AP4_ATOM_TYPE_plID = AP4_ATOM_TYPE('p','l','I','D');
00080 const AP4_Atom::Type AP4_ATOM_TYPE_geID = AP4_ATOM_TYPE('g','e','I','D');
00081 const AP4_Atom::Type AP4_ATOM_TYPE_sfID = AP4_ATOM_TYPE('s','f','I','D');
00082 const AP4_Atom::Type AP4_ATOM_TYPE_akID = AP4_ATOM_TYPE('a','k','I','D');
00083 const AP4_Atom::Type AP4_ATOM_TYPE_aART = AP4_ATOM_TYPE('a','A','R','T');
00084 const AP4_Atom::Type AP4_ATOM_TYPE_TVNN = AP4_ATOM_TYPE('t','v','n','n'); // TV network
00085 const AP4_Atom::Type AP4_ATOM_TYPE_TVSH = AP4_ATOM_TYPE('t','v','s','h'); // TV show
00086 const AP4_Atom::Type AP4_ATOM_TYPE_TVEN = AP4_ATOM_TYPE('t','v','e','n'); // TV episode name
00087 const AP4_Atom::Type AP4_ATOM_TYPE_TVSN = AP4_ATOM_TYPE('t','v','s','n'); // TV show season #
00088 const AP4_Atom::Type AP4_ATOM_TYPE_TVES = AP4_ATOM_TYPE('t','v','e','s'); // TV show episode #
00089 const AP4_Atom::Type AP4_ATOM_TYPE_STIK = AP4_ATOM_TYPE('s','t','i','k');
00090 const AP4_Atom::Type AP4_ATOM_TYPE_PGAP = AP4_ATOM_TYPE('p','g','a','p'); // Gapless Playback
00091 
00092 /*----------------------------------------------------------------------
00093 |   AP4_MetaData
00094 +---------------------------------------------------------------------*/
00095 class AP4_MetaData {
00096 public:
00097     typedef enum {
00098         DATA_TYPE_BINARY             = 0,
00099         DATA_TYPE_STRING_UTF8        = 1,
00100         DATA_TYPE_STRING_UTF16       = 2,
00101         DATA_TYPE_STRING_MAC_ENCODED = 3,
00102         DATA_TYPE_JPEG               = 14,
00103         DATA_TYPE_SIGNED_INT_BE      = 21, /* the size of the integer is derived from the container size */
00104         DATA_TYPE_FLOAT32_BE         = 22,
00105         DATA_TYPE_FLOAT64_BE         = 23
00106     } DataType;
00107 
00108     typedef enum {
00109         LANGUAGE_ENGLISH = 0
00110     } Language;
00111 
00112     class Key {
00113     public:
00114         // constructors
00115         Key(const char* name, const char* ns) :
00116           m_Name(name), m_Namespace(ns) {}
00117 
00118         // methods
00119         const char* GetNamespace() { return m_Namespace.GetChars(); }
00120         const char* GetName()      { return m_Name.GetChars();      }
00121 
00122     private:
00123         // members
00124         const AP4_String m_Name;
00125         const AP4_String m_Namespace;
00126     };
00127 
00128     class Value {
00129     public:
00130         // types 
00131         typedef enum {
00132             TYPE_STRING,
00133             TYPE_BINARY,
00134             TYPE_INTEGER
00135         } Type;
00136 
00137         typedef enum {
00138             MEANING_UNKNOWN,
00139             MEANING_ID3_GENRE,
00140             MEANING_BOOLEAN
00141         } Meaning;
00142 
00143         // destructor
00144         virtual ~Value() {}
00145 
00146         // methods
00147         Type               GetType()    { return m_Type;    }
00148         Meaning            GetMeaning() { return m_Meaning; }
00149         virtual AP4_String ToString() = 0;
00150         virtual AP4_Result ToBytes(AP4_DataBuffer& bytes) = 0;
00151         virtual long       ToInteger() = 0;
00152 
00153     protected:
00154         // constructor
00155         Value(Type type, Meaning meaning = MEANING_UNKNOWN) : 
00156              m_Type(type), m_Meaning(meaning) {}
00157 
00158         // members
00159         Type     m_Type;
00160         Meaning m_Meaning;
00161     };
00162 
00163     class KeyInfo {
00164     public:
00165         // members
00166         const char* name;
00167         const char* description;
00168         AP4_UI32    four_cc;
00169         Value::Type value_type;
00170     };
00171 
00172     class Entry {
00173     public:
00174         // constructor
00175         Entry(const char* name, const char* ns, Value* value) :
00176           m_Key(name, ns), m_Value(value) {}
00177 
00178         // destructor
00179         ~Entry() { delete m_Value; }
00180 
00181         // members
00182         Key    m_Key;
00183         Value* m_Value;    
00184     };
00185 
00186     // class members
00187     static AP4_Array<KeyInfo> KeysInfos;
00188 
00189     // constructor
00190     AP4_MetaData(AP4_MoovAtom* moov);
00191 
00192     // destructor
00193     ~AP4_MetaData();
00194 
00195     // accessors
00196     const AP4_List<Entry>& GetEntries() const { return m_Entries; }
00197 
00198     // methods
00199     AP4_Result AddEntries(AP4_ContainerAtom* atom);
00200 
00201 private:
00202     // members
00203     AP4_List<Entry> m_Entries;
00204 };
00205 
00206 /*----------------------------------------------------------------------
00207 |   AP4_MetaDataAtomTypeHandler
00208 +---------------------------------------------------------------------*/
00209 class AP4_MetaDataAtomTypeHandler : public AP4_AtomFactory::TypeHandler
00210 {
00211 public:
00212     // constructor
00213     AP4_MetaDataAtomTypeHandler(AP4_AtomFactory* atom_factory) :
00214       m_AtomFactory(atom_factory) {}
00215     virtual AP4_Result CreateAtom(AP4_Atom::Type  type,
00216                                   AP4_UI32        size,
00217                                   AP4_ByteStream& stream,
00218                                   AP4_Atom::Type  context,
00219                                   AP4_Atom*&      atom);
00220 
00221 private:
00222     // methods
00223     bool IsMetaDataType(AP4_Atom::Type type);
00224 
00225     // members
00226     AP4_AtomFactory* m_AtomFactory;
00227 };
00228 
00229 /*----------------------------------------------------------------------
00230 |   AP4_MetaDataTag
00231 +---------------------------------------------------------------------*/
00232 class AP4_MetaDataTag
00233 {
00234 public:
00235 
00236     // destructor
00237     virtual ~AP4_MetaDataTag() {}
00238 
00239     // methods
00240     virtual AP4_Result Write(AP4_ByteStream& stream);
00241     virtual AP4_Result Inspect(AP4_AtomInspector& inspector);
00242 
00243 protected:
00244     // constructor
00245     AP4_MetaDataTag(AP4_UI32        data_type, 
00246                     AP4_UI32        data_lang,
00247                     AP4_Size        size, 
00248                     AP4_ByteStream& stream);
00249 
00250 };
00251 
00252 /*----------------------------------------------------------------------
00253 |   AP4_StringAtom
00254 +---------------------------------------------------------------------*/
00255 class AP4_StringAtom : public AP4_Atom
00256 {
00257 public:
00258     // constructor
00259     AP4_StringAtom(Type type, AP4_UI32 size, AP4_ByteStream& stream);
00260 
00261     // AP4_Atom methods
00262     virtual AP4_Result InspectFields(AP4_AtomInspector& inspector);
00263     virtual AP4_Result WriteFields(AP4_ByteStream& stream);
00264 
00265     // methods
00266     const AP4_String& GetValue() { return m_Value; }
00267 
00268 private:
00269     // methods
00270 
00271     // members
00272     AP4_UI32   m_Reserved;
00273     AP4_String m_Value;
00274 };
00275 
00276 /*----------------------------------------------------------------------
00277 |   AP4_DataAtom
00278 +---------------------------------------------------------------------*/
00279 class AP4_DataAtom : public AP4_Atom
00280 {
00281 public:
00282     // constructor
00283     AP4_DataAtom(AP4_UI32 size, AP4_ByteStream& stream);
00284 
00285     // destructor
00286     ~AP4_DataAtom();
00287 
00288     // AP4_Atom methods
00289     virtual AP4_Result InspectFields(AP4_AtomInspector& inspector);
00290     virtual AP4_Result WriteFields(AP4_ByteStream& stream);
00291 
00292     // accessors
00293     AP4_MetaData::DataType GetDataType() { return m_DataType; }
00294     AP4_MetaData::Language GetDataLang() { return m_DataLang; }
00295 
00296     // methods
00297     AP4_Result LoadString(AP4_String*& string);
00298     AP4_Result LoadBytes(AP4_DataBuffer& bytes);
00299     AP4_Result LoadInteger(long& value);
00300 
00301 private:
00302     // members
00303     AP4_MetaData::DataType m_DataType;
00304     AP4_MetaData::Language m_DataLang;
00305     AP4_ByteStream*        m_Source;
00306 };
00307 
00308 /*----------------------------------------------------------------------
00309 |   AP4_AtomMetaDataValue
00310 +---------------------------------------------------------------------*/
00311 class AP4_AtomMetaDataValue : public AP4_MetaData::Value
00312 {
00313 public:
00314     // constructor
00315     AP4_AtomMetaDataValue(AP4_DataAtom* data_atom, AP4_UI32 parent_type);
00316 
00317     // AP4_MetaData::Value methods
00318     virtual AP4_String ToString();
00319     virtual AP4_Result ToBytes(AP4_DataBuffer& bytes);
00320     virtual long       ToInteger();
00321 
00322 private:
00323     // class methods
00324     static AP4_MetaData::Value::Type MapDataType(AP4_MetaData::DataType data_type);
00325 
00326     // members
00327     AP4_DataAtom* m_DataAtom;
00328 };
00329 
00330 #endif // _AP4_META_DATA_H_

Generated on Thu Mar 15 16:06:11 2007 for Bento4 MP4 SDK by  doxygen 1.5.1-p1