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

多媒体编程

开发平台:

Visual C++

  1. /*****************************************************************
  2. |
  3. |    AP4 - Sample Description Objects
  4. |
  5. |    Copyright 2002 Gilles Boccon-Gibod & Julien Boeuf
  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_SAMPLE_DESCRIPTION_H_
  29. #define _AP4_SAMPLE_DESCRIPTION_H_
  30. /*----------------------------------------------------------------------
  31. |       includes
  32. +---------------------------------------------------------------------*/
  33. #include "Ap4.h"
  34. #include "Ap4ByteStream.h"
  35. #include "Ap4DataBuffer.h"
  36. #include "Ap4Atom.h"
  37. #include "Ap4EsDescriptor.h"
  38. /*----------------------------------------------------------------------
  39. |       class references
  40. +---------------------------------------------------------------------*/
  41. class AP4_SampleEntry;
  42. /*----------------------------------------------------------------------
  43. |       AP4_SampleDescription
  44. +---------------------------------------------------------------------*/
  45. class AP4_SampleDescription
  46. {
  47.  public:
  48.     // type constants of the sample description
  49.     enum Type {
  50.         TYPE_UNKNOWN  = 0x00,
  51.         TYPE_MPEG     = 0x01,
  52.         TYPE_ISMACRYP = 0x02
  53.     };
  54.     // constructors & destructor
  55.     AP4_SampleDescription(Type type) : m_Type(type) {}
  56.     virtual ~AP4_SampleDescription() {}
  57.                  
  58.     // accessors
  59.     Type GetType() const { return m_Type; }
  60.     // factories
  61.     virtual AP4_Atom* ToAtom() const = 0;
  62.  protected:
  63.     Type m_Type;
  64. };
  65. /*----------------------------------------------------------------------
  66. |       AP4_UnknownSampleDescription
  67. +---------------------------------------------------------------------*/
  68. class AP4_UnknownSampleDescription : public AP4_SampleDescription
  69. {
  70.  public:
  71.     // methods
  72.     AP4_UnknownSampleDescription(AP4_SampleEntry* sample_entry);
  73.     ~AP4_UnknownSampleDescription();
  74.     AP4_SampleEntry* GetSampleEntry() { return m_SampleEntry; }
  75.     AP4_Atom* ToAtom() const;
  76.  protected:
  77.     AP4_SampleEntry* m_SampleEntry;
  78. };
  79.     
  80. /*----------------------------------------------------------------------
  81. |       AP4_MpegSampleDescription
  82. +---------------------------------------------------------------------*/
  83. class AP4_MpegSampleDescription : public AP4_SampleDescription
  84. {
  85.  public:
  86.     // types
  87.     typedef AP4_UI08 StreamType;
  88.     typedef AP4_UI08 OTI;
  89.     
  90.     // class methods
  91.     const char* GetStreamTypeString(StreamType type);
  92.     const char* GetObjectTypeString(OTI oti);
  93.     // constructors & destructor
  94.     AP4_MpegSampleDescription(StreamType            stream_type,
  95.                               OTI                   oti,
  96.                               const AP4_DataBuffer* decoder_info,
  97.                               AP4_UI32              buffer_size,
  98.                               AP4_UI32              max_bitrate,
  99.                               AP4_UI32              avg_bitrate);
  100.     virtual ~AP4_MpegSampleDescription();
  101.     
  102.     // accessors
  103.     AP4_Byte GetStreamType() const { return m_StreamType; }
  104.     AP4_Byte GetObjectTypeId() const { return m_ObjectTypeId; }
  105.     const AP4_DataBuffer* GetDecoderInfo() const { return m_DecoderInfo; }
  106.     AP4_UI32 GetBufferSize() const { return m_BufferSize; }
  107.     AP4_UI32 GetMaxBitrate() const { return m_MaxBitrate; }
  108.     AP4_UI32 GetAvgBitrate() const { return m_AvgBitrate; }
  109.     // methods
  110.     AP4_EsDescriptor* CreateEsDescriptor() const;
  111.  protected:
  112.     // members
  113.     StreamType      m_StreamType;
  114.     OTI             m_ObjectTypeId;
  115.     AP4_DataBuffer* m_DecoderInfo;
  116.     AP4_UI32        m_BufferSize;
  117.     AP4_UI32        m_MaxBitrate;
  118.     AP4_UI32        m_AvgBitrate;
  119.     
  120. };
  121. /*----------------------------------------------------------------------
  122. |       AP4_MpegSystemSampleDescription
  123. +---------------------------------------------------------------------*/
  124. class AP4_MpegSystemSampleDescription : public AP4_MpegSampleDescription
  125. {
  126. public:
  127.     // constructor
  128.     AP4_MpegSystemSampleDescription(StreamType            type,
  129.                                     OTI                   oti,
  130.                                     const AP4_DataBuffer* decoder_info,
  131.                                     AP4_UI32              buffer_size,
  132.                                     AP4_UI32              max_bitrate,
  133.                                     AP4_UI32              avg_bitrate);
  134.     // methods
  135.     AP4_Atom* ToAtom() const;
  136. };
  137. /*----------------------------------------------------------------------
  138. |       AP4_MpegAudioSampleDescription
  139. +---------------------------------------------------------------------*/
  140. class AP4_MpegAudioSampleDescription : public AP4_MpegSampleDescription
  141. {
  142. public:
  143.     // constructor
  144.     AP4_MpegAudioSampleDescription(OTI                   oti,
  145.                                    unsigned int          sample_rate,
  146.                                    unsigned int          sample_size,
  147.                                    unsigned int          channel_count,
  148.                                    const AP4_DataBuffer* decoder_info,
  149.                                    AP4_UI32              buffer_size,
  150.                                    AP4_UI32              max_bitrate,
  151.                                    AP4_UI32              avg_bitrate);
  152.     // accessors
  153.     AP4_UI32 GetSampleRate()   { return m_SampleRate;   }
  154.     AP4_UI16 GetSampleSize()   { return m_SampleSize;   }
  155.     AP4_UI16 GetChannelCount() { return m_ChannelCount; }
  156.     // methods
  157.     AP4_Atom* ToAtom() const;
  158. protected:
  159.     // members
  160.     AP4_UI32 m_SampleRate;
  161.     AP4_UI16 m_SampleSize;
  162.     AP4_UI16 m_ChannelCount;
  163. };
  164. /*----------------------------------------------------------------------
  165. |       AP4_MpegVideoSampleDescription
  166. +---------------------------------------------------------------------*/
  167. class AP4_MpegVideoSampleDescription : public AP4_MpegSampleDescription
  168. {
  169. public:
  170.     // constructor
  171.     AP4_MpegVideoSampleDescription(OTI                   oti,
  172.                                    AP4_UI16              width,
  173.                                    AP4_UI16              height,
  174.                                    AP4_UI16              depth,
  175.                                    const char*           compressor_name,
  176.                                    const AP4_DataBuffer* decoder_info,
  177.                                    AP4_UI32              buffer_size,
  178.                                    AP4_UI32              max_bitrate,
  179.                                    AP4_UI32              avg_bitrate);
  180.     // accessors
  181.     AP4_UI32    GetWidth()          { return m_Width;   }
  182.     AP4_UI16    GetHeight()         { return m_Height;   }
  183.     AP4_UI16    GetDepth()          { return m_Depth; }
  184.     const char* GetCompressorName() { return m_CompressorName.c_str(); }
  185.     // methods
  186.     AP4_Atom* ToAtom() const;
  187. protected:
  188.     // members
  189.     AP4_UI16   m_Width;
  190.     AP4_UI16   m_Height;
  191.     AP4_UI16   m_Depth;
  192.     AP4_String m_CompressorName;
  193. };
  194. /*----------------------------------------------------------------------
  195. |       constants
  196. +---------------------------------------------------------------------*/
  197. const AP4_MpegSampleDescription::StreamType AP4_FORBIDDEN_STREAM_TYPE = 0x00;
  198. const AP4_MpegSampleDescription::StreamType AP4_OD_STREAM_TYPE        = 0x01;
  199. const AP4_MpegSampleDescription::StreamType AP4_CR_STREAM_TYPE        = 0x02;
  200. const AP4_MpegSampleDescription::StreamType AP4_BIFS_STREAM_TYPE      = 0x03;
  201. const AP4_MpegSampleDescription::StreamType AP4_VISUAL_STREAM_TYPE    = 0x04;
  202. const AP4_MpegSampleDescription::StreamType AP4_AUDIO_STREAM_TYPE     = 0x05;
  203. const AP4_MpegSampleDescription::StreamType AP4_MPEG7_STREAM_TYPE     = 0x06;
  204. const AP4_MpegSampleDescription::StreamType AP4_IPMP_STREAM_TYPE      = 0x07;
  205. const AP4_MpegSampleDescription::StreamType AP4_OCI_STREAM_TYPE       = 0x08;
  206. const AP4_MpegSampleDescription::StreamType AP4_MPEGJ_STREAM_TYPE     = 0x09;
  207. const AP4_MpegSampleDescription::OTI AP4_MPEG4_SYSTEM_OTI         = 0x01;
  208. const AP4_MpegSampleDescription::OTI AP4_MPEG4_SYSTEM_COR_OTI     = 0x02;
  209. const AP4_MpegSampleDescription::OTI AP4_MPEG4_VISUAL_OTI         = 0x20;
  210. const AP4_MpegSampleDescription::OTI AP4_MPEG4_AUDIO_OTI          = 0x40;
  211. const AP4_MpegSampleDescription::OTI AP4_MPEG2_VISUAL_SIMPLE_OTI  = 0x60;
  212. const AP4_MpegSampleDescription::OTI AP4_MPEG2_VISUAL_MAIN_OTI    = 0x61;
  213. const AP4_MpegSampleDescription::OTI AP4_MPEG2_VISUAL_SNR_OTI     = 0x62;
  214. const AP4_MpegSampleDescription::OTI AP4_MPEG2_VISUAL_SPATIAL_OTI = 0x63;
  215. const AP4_MpegSampleDescription::OTI AP4_MPEG2_VISUAL_HIGH_OTI    = 0x64;
  216. const AP4_MpegSampleDescription::OTI AP4_MPEG2_VISUAL_422_OTI     = 0x65;
  217. const AP4_MpegSampleDescription::OTI AP4_MPEG2_AAC_AUDIO_MAIN_OTI = 0x66;
  218. const AP4_MpegSampleDescription::OTI AP4_MPEG2_AAC_AUDIO_LC_OTI   = 0x67;
  219. const AP4_MpegSampleDescription::OTI AP4_MPEG2_AAC_AUDIO_SSRP_OTI = 0x68;
  220. const AP4_MpegSampleDescription::OTI AP4_MPEG2_PART3_AUDIO_OTI    = 0x69;
  221. const AP4_MpegSampleDescription::OTI AP4_MPEG1_VISUAL_OTI         = 0x6A;
  222. const AP4_MpegSampleDescription::OTI AP4_MPEG1_AUDIO_OTI          = 0x6B;
  223. const AP4_MpegSampleDescription::OTI AP4_JPEG_OTI                 = 0x6C;
  224. #endif // _AP4_SAMPLE_DESCRIPTION_H_