Ap4SampleDescription.h

Go to the documentation of this file.
00001 /*****************************************************************
00002 |
00003 |    AP4 - Sample Descriptions
00004 |
00005 |    Copyright 2002-2005 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_SAMPLE_DESCRIPTION_H_
00030 #define _AP4_SAMPLE_DESCRIPTION_H_
00031 
00032 /*----------------------------------------------------------------------
00033 |   includes
00034 +---------------------------------------------------------------------*/
00035 #include "Ap4Types.h"
00036 #include "Ap4Atom.h"
00037 #include "Ap4EsDescriptor.h"
00038 #include "Ap4EsdsAtom.h"
00039 
00040 /*----------------------------------------------------------------------
00041 |   class references
00042 +---------------------------------------------------------------------*/
00043 class AP4_SampleEntry;
00044 class AP4_DataBuffer;
00045 
00046 /*----------------------------------------------------------------------
00047 |   constants
00048 +---------------------------------------------------------------------*/
00049 #define AP4_SAMPLE_FORMAT_MP4A AP4_ATOM_TYPE_MP4A
00050 #define AP4_SAMPLE_FORMAT_MP4V AP4_ATOM_TYPE_MP4V
00051 #define AP4_SAMPLE_FORMAT_AVC1 AP4_ATOM_TYPE_AVC1
00052 
00053 /*----------------------------------------------------------------------
00054 |   AP4_SampleDescription
00055 +---------------------------------------------------------------------*/
00056 class AP4_SampleDescription
00057 {
00058  public:
00059     // type constants of the sample description
00060     enum Type {
00061         TYPE_UNKNOWN   = 0x00,
00062         TYPE_MPEG      = 0x01,
00063         TYPE_PROTECTED = 0x02
00064     };
00065 
00066     // constructors & destructor
00067     AP4_SampleDescription(Type type, AP4_UI32 format) : 
00068         m_Type(type), m_Format(format) {}
00069     virtual ~AP4_SampleDescription() {}
00070                  
00071     // accessors
00072     Type GetType()       const { return m_Type;   }
00073     AP4_UI32 GetFormat() const { return m_Format; }
00074 
00075     // factories
00076     virtual AP4_Atom* ToAtom() const = 0;
00077 
00078  protected:
00079     Type     m_Type;
00080     AP4_UI32 m_Format;
00081 };
00082 
00083 /*----------------------------------------------------------------------
00084 |   AP4_AudioSampleDescription  // MIXIN class
00085 +---------------------------------------------------------------------*/
00086 class AP4_AudioSampleDescription
00087 {
00088 public:
00089     // constructor
00090     AP4_AudioSampleDescription(unsigned int sample_rate,
00091                                unsigned int sample_size,
00092                                unsigned int channel_count) :
00093     m_SampleRate(sample_rate),
00094     m_SampleSize(sample_size),
00095     m_ChannelCount(channel_count) {}
00096 
00097     // accessors
00098     AP4_UI32 GetSampleRate()   { return m_SampleRate;   }
00099     AP4_UI16 GetSampleSize()   { return m_SampleSize;   }
00100     AP4_UI16 GetChannelCount() { return m_ChannelCount; }
00101 
00102 protected:
00103     // members
00104     AP4_UI32 m_SampleRate;
00105     AP4_UI16 m_SampleSize;
00106     AP4_UI16 m_ChannelCount;
00107 };
00108 
00109 /*----------------------------------------------------------------------
00110 |   AP4_VideoSampleDescription  // MIXIN class
00111 +---------------------------------------------------------------------*/
00112 class AP4_VideoSampleDescription
00113 {
00114 public:
00115     // constructor
00116     AP4_VideoSampleDescription(AP4_UI16    width,
00117                                AP4_UI16    height,
00118                                AP4_UI16    depth,
00119                                const char* compressor_name) :
00120     m_Width(width),
00121     m_Height(height),
00122     m_Depth(depth),
00123     m_CompressorName(compressor_name) {}
00124 
00125     // accessors
00126     AP4_UI32    GetWidth()          { return m_Width;   }
00127     AP4_UI16    GetHeight()         { return m_Height;   }
00128     AP4_UI16    GetDepth()          { return m_Depth; }
00129     const char* GetCompressorName() { return m_CompressorName.GetChars(); }
00130 
00131 protected:
00132     // members
00133     AP4_UI16   m_Width;
00134     AP4_UI16   m_Height;
00135     AP4_UI16   m_Depth;
00136     AP4_String m_CompressorName;
00137 };
00138 
00139 /*----------------------------------------------------------------------
00140 |   AP4_UnknownSampleDescription
00141 +---------------------------------------------------------------------*/
00142 class AP4_UnknownSampleDescription : public AP4_SampleDescription
00143 {
00144 public:
00145     // methods
00146     AP4_UnknownSampleDescription(AP4_UI32 format);
00147     ~AP4_UnknownSampleDescription();
00148     AP4_Atom* ToAtom() const;
00149 };
00150 
00151 /*----------------------------------------------------------------------
00152 |   AP4_GenericAudioSampleDescription
00153 +---------------------------------------------------------------------*/
00154 class AP4_GenericAudioSampleDescription : public AP4_UnknownSampleDescription,
00155                                           public AP4_AudioSampleDescription
00156 {
00157 public:
00158     // constructor
00159     AP4_GenericAudioSampleDescription(AP4_UI32     format,
00160                                       unsigned int sample_rate,
00161                                       unsigned int sample_size,
00162                                       unsigned int channel_count) :
00163     AP4_UnknownSampleDescription(format),
00164     AP4_AudioSampleDescription(sample_rate, sample_size, channel_count) {}
00165 };
00166 
00167 /*----------------------------------------------------------------------
00168 |   AP4_GenericVideoSampleDescription
00169 +---------------------------------------------------------------------*/
00170 class AP4_GenericVideoSampleDescription : public AP4_UnknownSampleDescription,
00171                                           public AP4_VideoSampleDescription
00172 {
00173 public:
00174     // constructor
00175     AP4_GenericVideoSampleDescription(AP4_UI32    format,
00176                                       AP4_UI16    width,
00177                                       AP4_UI16    height,
00178                                       AP4_UI16    depth,
00179                                       const char* compressor_name) :
00180     AP4_UnknownSampleDescription(format),
00181     AP4_VideoSampleDescription(width, height, depth, compressor_name) {}
00182 };
00183 
00184 /*----------------------------------------------------------------------
00185 |   AP4_MpegSampleDescription
00186 +---------------------------------------------------------------------*/
00187 class AP4_MpegSampleDescription : public AP4_SampleDescription
00188 {
00189  public:
00190     // types
00191     typedef AP4_UI08 StreamType;
00192     typedef AP4_UI08 OTI;
00193     
00194     // class methods
00195     static const char* GetStreamTypeString(StreamType type);
00196     static const char* GetObjectTypeString(OTI oti);
00197 
00198     // constructors & destructor
00199     AP4_MpegSampleDescription(AP4_UI32      format,
00200                               AP4_EsdsAtom* esds);
00201     AP4_MpegSampleDescription(AP4_UI32              format,
00202                               StreamType            stream_type,
00203                               OTI                   oti,
00204                               const AP4_DataBuffer* decoder_info,
00205                               AP4_UI32              buffer_size,
00206                               AP4_UI32              max_bitrate,
00207                               AP4_UI32              avg_bitrate);
00208     virtual ~AP4_MpegSampleDescription();
00209     
00210     // accessors
00211     AP4_Byte GetStreamType() const { return m_StreamType; }
00212     AP4_Byte GetObjectTypeId() const { return m_ObjectTypeId; }
00213     const AP4_DataBuffer* GetDecoderInfo() const { return m_DecoderInfo; }
00214     AP4_UI32 GetBufferSize() const { return m_BufferSize; }
00215     AP4_UI32 GetMaxBitrate() const { return m_MaxBitrate; }
00216     AP4_UI32 GetAvgBitrate() const { return m_AvgBitrate; }
00217 
00218     // methods
00219     AP4_EsDescriptor* CreateEsDescriptor() const;
00220 
00221  protected:
00222     // members
00223     AP4_UI32        m_Format;
00224     StreamType      m_StreamType;
00225     OTI             m_ObjectTypeId;
00226     AP4_DataBuffer* m_DecoderInfo;
00227     AP4_UI32        m_BufferSize;
00228     AP4_UI32        m_MaxBitrate;
00229     AP4_UI32        m_AvgBitrate;
00230     
00231 };
00232 
00233 /*----------------------------------------------------------------------
00234 |   AP4_MpegSystemSampleDescription
00235 +---------------------------------------------------------------------*/
00236 class AP4_MpegSystemSampleDescription : public AP4_MpegSampleDescription
00237 {
00238 public:
00239     // constructor
00240     AP4_MpegSystemSampleDescription(AP4_EsdsAtom* esds);
00241     AP4_MpegSystemSampleDescription(StreamType            stream_type,
00242                                     OTI                   oti,
00243                                     const AP4_DataBuffer* decoder_info,
00244                                     AP4_UI32              buffer_size,
00245                                     AP4_UI32              max_bitrate,
00246                                     AP4_UI32              avg_bitrate);
00247 
00248     // methods
00249     AP4_Atom* ToAtom() const;
00250 };
00251 
00252 /*----------------------------------------------------------------------
00253 |   AP4_MpegAudioSampleDescription
00254 +---------------------------------------------------------------------*/
00255 class AP4_MpegAudioSampleDescription : public AP4_MpegSampleDescription,
00256                                        public AP4_AudioSampleDescription
00257 {
00258 public:
00259     // constructor
00260     AP4_MpegAudioSampleDescription(AP4_EsdsAtom* esds,
00261                                    unsigned int  sample_rate,
00262                                    unsigned int  sample_size,
00263                                    unsigned int  channel_count);
00264     AP4_MpegAudioSampleDescription(OTI                   oti,
00265                                    unsigned int          sample_rate,
00266                                    unsigned int          sample_size,
00267                                    unsigned int          channel_count,
00268                                    const AP4_DataBuffer* decoder_info,
00269                                    AP4_UI32              buffer_size,
00270                                    AP4_UI32              max_bitrate,
00271                                    AP4_UI32              avg_bitrate);
00272 
00273     // methods
00274     AP4_Atom* ToAtom() const;
00275 };
00276 
00277 /*----------------------------------------------------------------------
00278 |   AP4_MpegVideoSampleDescription
00279 +---------------------------------------------------------------------*/
00280 class AP4_MpegVideoSampleDescription : public AP4_MpegSampleDescription,
00281                                        public AP4_VideoSampleDescription
00282 {
00283 public:
00284     // constructor
00285     AP4_MpegVideoSampleDescription(AP4_EsdsAtom* esds,
00286                                    AP4_UI16      width,
00287                                    AP4_UI16      height,
00288                                    AP4_UI16      depth,
00289                                    const char*   compressor_name);
00290     AP4_MpegVideoSampleDescription(OTI                   oti,
00291                                    AP4_UI16              width,
00292                                    AP4_UI16              height,
00293                                    AP4_UI16              depth,
00294                                    const char*           compressor_name,
00295                                    const AP4_DataBuffer* decoder_info,
00296                                    AP4_UI32              buffer_size,
00297                                    AP4_UI32              max_bitrate,
00298                                    AP4_UI32              avg_bitrate);
00299 
00300     // methods
00301     AP4_Atom* ToAtom() const;
00302 };
00303 
00304 /*----------------------------------------------------------------------
00305 |   constants
00306 +---------------------------------------------------------------------*/
00307 const AP4_MpegSampleDescription::StreamType AP4_FORBIDDEN_STREAM_TYPE = 0x00;
00308 const AP4_MpegSampleDescription::StreamType AP4_OD_STREAM_TYPE        = 0x01;
00309 const AP4_MpegSampleDescription::StreamType AP4_CR_STREAM_TYPE        = 0x02;   
00310 const AP4_MpegSampleDescription::StreamType AP4_BIFS_STREAM_TYPE      = 0x03;
00311 const AP4_MpegSampleDescription::StreamType AP4_VISUAL_STREAM_TYPE    = 0x04;
00312 const AP4_MpegSampleDescription::StreamType AP4_AUDIO_STREAM_TYPE     = 0x05;
00313 const AP4_MpegSampleDescription::StreamType AP4_MPEG7_STREAM_TYPE     = 0x06;
00314 const AP4_MpegSampleDescription::StreamType AP4_IPMP_STREAM_TYPE      = 0x07;
00315 const AP4_MpegSampleDescription::StreamType AP4_OCI_STREAM_TYPE       = 0x08;
00316 const AP4_MpegSampleDescription::StreamType AP4_MPEGJ_STREAM_TYPE     = 0x09;
00317 
00318 const AP4_MpegSampleDescription::OTI AP4_MPEG4_SYSTEM_OTI         = 0x01;
00319 const AP4_MpegSampleDescription::OTI AP4_MPEG4_SYSTEM_COR_OTI     = 0x02;
00320 const AP4_MpegSampleDescription::OTI AP4_MPEG4_VISUAL_OTI         = 0x20;
00321 const AP4_MpegSampleDescription::OTI AP4_MPEG4_AUDIO_OTI          = 0x40;
00322 const AP4_MpegSampleDescription::OTI AP4_MPEG2_VISUAL_SIMPLE_OTI  = 0x60;
00323 const AP4_MpegSampleDescription::OTI AP4_MPEG2_VISUAL_MAIN_OTI    = 0x61;
00324 const AP4_MpegSampleDescription::OTI AP4_MPEG2_VISUAL_SNR_OTI     = 0x62;
00325 const AP4_MpegSampleDescription::OTI AP4_MPEG2_VISUAL_SPATIAL_OTI = 0x63;
00326 const AP4_MpegSampleDescription::OTI AP4_MPEG2_VISUAL_HIGH_OTI    = 0x64;
00327 const AP4_MpegSampleDescription::OTI AP4_MPEG2_VISUAL_422_OTI     = 0x65;
00328 const AP4_MpegSampleDescription::OTI AP4_MPEG2_AAC_AUDIO_MAIN_OTI = 0x66;
00329 const AP4_MpegSampleDescription::OTI AP4_MPEG2_AAC_AUDIO_LC_OTI   = 0x67;
00330 const AP4_MpegSampleDescription::OTI AP4_MPEG2_AAC_AUDIO_SSRP_OTI = 0x68;
00331 const AP4_MpegSampleDescription::OTI AP4_MPEG2_PART3_AUDIO_OTI    = 0x69;
00332 const AP4_MpegSampleDescription::OTI AP4_MPEG1_VISUAL_OTI         = 0x6A;
00333 const AP4_MpegSampleDescription::OTI AP4_MPEG1_AUDIO_OTI          = 0x6B;
00334 const AP4_MpegSampleDescription::OTI AP4_JPEG_OTI                 = 0x6C;
00335 
00336 #endif // _AP4_SAMPLE_DESCRIPTION_H_
00337 

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