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

多媒体编程

开发平台:

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. /*----------------------------------------------------------------------
  29. |       includes
  30. +---------------------------------------------------------------------*/
  31. #include "Ap4SampleDescription.h"
  32. #include "Ap4EsDescriptor.h"
  33. #include "Ap4SampleEntry.h"
  34. /*----------------------------------------------------------------------
  35. |       AP4_UnknownSampleDescription::AP4_UnknownSampleDescription
  36. +---------------------------------------------------------------------*/
  37. AP4_UnknownSampleDescription::AP4_UnknownSampleDescription(AP4_SampleEntry* entry) :
  38.     AP4_SampleDescription(AP4_SampleDescription::TYPE_UNKNOWN),
  39.     m_SampleEntry(entry)
  40. {
  41. }
  42. /*----------------------------------------------------------------------
  43. |       AP4_UnknownSampleDescription::~AP4_UnknownSampleDescription
  44. +---------------------------------------------------------------------*/
  45. AP4_UnknownSampleDescription::~AP4_UnknownSampleDescription()
  46. {
  47. }
  48. /*----------------------------------------------------------------------
  49. |       AP4_UnknownSampleDescription::ToAtom
  50. +---------------------------------------------------------------------*/
  51. AP4_Atom*
  52. AP4_UnknownSampleDescription::ToAtom() const
  53. {
  54.     return new AP4_SampleEntry(m_SampleEntry->GetType(),
  55.                                m_SampleEntry->GetDataReferenceIndex());
  56. }
  57. /*----------------------------------------------------------------------
  58. |       AP4_MpegSampleDescription::AP4_MpegSampleDescription
  59. +---------------------------------------------------------------------*/
  60. AP4_MpegSampleDescription::AP4_MpegSampleDescription(
  61.     StreamType            stream_type,
  62.     OTI                   oti,
  63.     const AP4_DataBuffer* decoder_info,
  64.     AP4_UI32              buffer_size,
  65.     AP4_UI32              max_bitrate,
  66.     AP4_UI32              avg_bitrate) :
  67.     AP4_SampleDescription(TYPE_MPEG),
  68.     m_StreamType(stream_type),
  69.     m_ObjectTypeId(oti),
  70.     m_DecoderInfo(NULL),
  71.     m_BufferSize(buffer_size),
  72.     m_MaxBitrate(max_bitrate),
  73.     m_AvgBitrate(avg_bitrate)
  74. {
  75.     if (decoder_info != NULL) {
  76.         m_DecoderInfo = new AP4_DataBuffer(*decoder_info);
  77.     }
  78. }
  79. /*----------------------------------------------------------------------
  80. |       AP4_MpegSampleDescription::~AP4_MpegSampleDescription
  81. +---------------------------------------------------------------------*/
  82. AP4_MpegSampleDescription::~AP4_MpegSampleDescription()
  83. {
  84.     delete m_DecoderInfo;
  85. }
  86. /*----------------------------------------------------------------------
  87. |       AP4_MpegSampleDescription::CreateEsDescriptor
  88. +---------------------------------------------------------------------*/
  89. AP4_EsDescriptor* 
  90. AP4_MpegSampleDescription::CreateEsDescriptor() const
  91. {
  92.     AP4_EsDescriptor* desc = new AP4_EsDescriptor(0);
  93.     AP4_DecoderSpecificInfoDescriptor* dsi_desc;
  94.     if (m_DecoderInfo) {
  95.         dsi_desc = new AP4_DecoderSpecificInfoDescriptor(*m_DecoderInfo);
  96.     } else {
  97.         dsi_desc = NULL;
  98.     }
  99.     AP4_DecoderConfigDescriptor* decoder_config = 
  100.         new AP4_DecoderConfigDescriptor(m_StreamType,
  101.         m_ObjectTypeId,
  102.         m_BufferSize,
  103.         m_MaxBitrate,
  104.         m_AvgBitrate,
  105.         dsi_desc);
  106.     desc->AddSubDescriptor(decoder_config);
  107.     return desc;
  108. }
  109. /*----------------------------------------------------------------------
  110. |       AP4_MpegSystemSampleDescription::AP4_MpegSystemSampleDescription
  111. +---------------------------------------------------------------------*/
  112. AP4_MpegSystemSampleDescription::AP4_MpegSystemSampleDescription(
  113.     StreamType            stream_type,
  114.     OTI                   oti,
  115.     const AP4_DataBuffer* decoder_info,
  116.     AP4_UI32              buffer_size,
  117.     AP4_UI32              max_bitrate,
  118.     AP4_UI32              avg_bitrate) :
  119.     AP4_MpegSampleDescription(stream_type,
  120.                               oti,
  121.                               decoder_info,
  122.                               buffer_size,
  123.                               max_bitrate,
  124.                               avg_bitrate)
  125. {
  126. }
  127. /*----------------------------------------------------------------------
  128. |       AP4_MpegSystemSampleDescription::ToAtom
  129. +---------------------------------------------------------------------*/
  130. AP4_Atom*
  131. AP4_MpegSystemSampleDescription::ToAtom() const
  132. {
  133.     return new AP4_Mp4sSampleEntry(CreateEsDescriptor());
  134. }
  135. /*----------------------------------------------------------------------
  136. |       AP4_MpegAudioSampleDescription::AP4_MpegAudioSampleDescription
  137. +---------------------------------------------------------------------*/
  138. AP4_MpegAudioSampleDescription::AP4_MpegAudioSampleDescription(
  139.     OTI                   oti,
  140.     unsigned int          sample_rate,
  141.     unsigned int          sample_size,
  142.     unsigned int          channel_count,
  143.     const AP4_DataBuffer* decoder_info,
  144.     AP4_UI32              buffer_size,
  145.     AP4_UI32              max_bitrate,
  146.     AP4_UI32              avg_bitrate) :
  147.     AP4_MpegSampleDescription(AP4_AUDIO_STREAM_TYPE,
  148.                               oti, 
  149.                               decoder_info, buffer_size, 
  150.                               max_bitrate, avg_bitrate),
  151.     m_SampleRate(sample_rate),
  152.     m_SampleSize(sample_size),
  153.     m_ChannelCount(channel_count)
  154. {
  155. }
  156. /*----------------------------------------------------------------------
  157. |       AP4_MpegAudioSampleDescription::ToAtom
  158. +---------------------------------------------------------------------*/
  159. AP4_Atom*
  160. AP4_MpegAudioSampleDescription::ToAtom() const
  161. {
  162.     return new AP4_Mp4aSampleEntry(m_SampleRate<<16,
  163.                                    m_SampleSize,
  164.                                    m_ChannelCount,
  165.                                    CreateEsDescriptor());
  166. }
  167. /*----------------------------------------------------------------------
  168. |       AP4_MpegVideoSampleDescription::AP4_MpegVideoSampleDescription
  169. +---------------------------------------------------------------------*/
  170. AP4_MpegVideoSampleDescription::AP4_MpegVideoSampleDescription(
  171.     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.     AP4_MpegSampleDescription(AP4_VISUAL_STREAM_TYPE,
  181.                               oti,
  182.                               decoder_info,
  183.                               buffer_size,
  184.                               max_bitrate,
  185.                               avg_bitrate),
  186.     m_Width(width),
  187.     m_Height(height),
  188.     m_Depth(depth),
  189.     m_CompressorName(compressor_name)
  190. {
  191. }
  192. /*----------------------------------------------------------------------
  193. |       AP4_MpegVideoSampleDescription::ToAtom
  194. +---------------------------------------------------------------------*/
  195. AP4_Atom*
  196. AP4_MpegVideoSampleDescription::ToAtom() const
  197. {
  198.     return new AP4_Mp4vSampleEntry(m_Width,
  199.                                    m_Height,
  200.                                    m_Depth,
  201.                                    m_CompressorName.c_str(),
  202.                                    CreateEsDescriptor());
  203. }
  204. /*----------------------------------------------------------------------
  205. |       AP4_MpegSampleDescription::GetStreamTypeString
  206. +---------------------------------------------------------------------*/
  207. const char* 
  208. AP4_MpegSampleDescription::GetStreamTypeString(StreamType type)
  209. {
  210.     switch (type) {
  211.         case AP4_FORBIDDEN_STREAM_TYPE: return "INVALID"; 
  212.         case AP4_OD_STREAM_TYPE:        return "Object Descriptor";
  213.         case AP4_CR_STREAM_TYPE:        return "CR";
  214.         case AP4_BIFS_STREAM_TYPE:      return "BIFS";
  215.         case AP4_VISUAL_STREAM_TYPE:    return "Visual";
  216.         case AP4_AUDIO_STREAM_TYPE:     return "Audio";
  217.         case AP4_MPEG7_STREAM_TYPE:     return "MPEG-7";
  218.         case AP4_IPMP_STREAM_TYPE:      return "IPMP";
  219.         case AP4_OCI_STREAM_TYPE:       return "OCI";
  220.         case AP4_MPEGJ_STREAM_TYPE:     return "MPEG-J";
  221.         default:                        return "UNKNOWN";
  222.     }
  223. }
  224. /*----------------------------------------------------------------------
  225. |       AP4_MpegSampleDescription::GetObjectTypeString
  226. +---------------------------------------------------------------------*/
  227. const char* 
  228. AP4_MpegSampleDescription::GetObjectTypeString(OTI oti)
  229. {
  230.     switch (oti) {
  231.         case AP4_MPEG4_SYSTEM_OTI:         return "MPEG-4 System";
  232.         case AP4_MPEG4_SYSTEM_COR_OTI:     return "MPEG-4 System COR";
  233.         case AP4_MPEG4_VISUAL_OTI:         return "MPEG-4 Video";
  234.         case AP4_MPEG4_AUDIO_OTI:          return "MPEG-4 Audio";
  235.         case AP4_MPEG2_VISUAL_SIMPLE_OTI:  return "MPEG-2 Video Simple Profile";
  236.         case AP4_MPEG2_VISUAL_MAIN_OTI:    return "MPEG-2 Video Main Profile";
  237.         case AP4_MPEG2_VISUAL_SNR_OTI:     return "MPEG-2 Video SNR";
  238.         case AP4_MPEG2_VISUAL_SPATIAL_OTI: return "MPEG-2 Video Spatial";
  239.         case AP4_MPEG2_VISUAL_HIGH_OTI:    return "MPEG-2 Video High";
  240.         case AP4_MPEG2_VISUAL_422_OTI:     return "MPEG-2 Video 4:2:2";
  241.         case AP4_MPEG2_AAC_AUDIO_MAIN_OTI: return "MPEG-2 Audio AAC Main Profile";
  242.         case AP4_MPEG2_AAC_AUDIO_LC_OTI:   return "MPEG-2 Audio AAC Low Complexity";
  243.         case AP4_MPEG2_AAC_AUDIO_SSRP_OTI: return "MPEG-2 Audio AAC SSRP";
  244.         case AP4_MPEG2_PART3_AUDIO_OTI:    return "MPEG-2 Audio Part-3";
  245.         case AP4_MPEG1_VISUAL_OTI:         return "MPEG-1 Video";
  246.         case AP4_MPEG1_AUDIO_OTI:          return "MPEG-1 Audio";
  247.         case AP4_JPEG_OTI:                 return "JPEG";
  248.         default:                           return "UNKNOWN";
  249.     }
  250. }