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

多媒体编程

开发平台:

Visual C++

  1. /*****************************************************************
  2. |
  3. |    AP4 - sample entries
  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_ENTRY_H_
  29. #define _AP4_SAMPLE_ENTRY_H_
  30. /*----------------------------------------------------------------------
  31. |       includes
  32. +---------------------------------------------------------------------*/
  33. #include "Ap4.h"
  34. #include "Ap4ByteStream.h"
  35. #include "Ap4List.h"
  36. #include "Ap4Atom.h"
  37. #include "Ap4EsdsAtom.h"
  38. #include "Ap4AtomFactory.h"
  39. #include "Ap4ContainerAtom.h"
  40. /*----------------------------------------------------------------------
  41. |       class references
  42. +---------------------------------------------------------------------*/
  43. class AP4_SampleDescription;
  44. /*----------------------------------------------------------------------
  45. |       AP4_SampleEntry
  46. +---------------------------------------------------------------------*/
  47. class AP4_SampleEntry : public AP4_ContainerAtom
  48. {
  49.  public: 
  50.     // methods
  51.     AP4_SampleEntry(AP4_Atom::Type format, AP4_UI16 data_ref_index = 1);
  52.     AP4_SampleEntry(AP4_Atom::Type   format, 
  53.                     AP4_Size         size,
  54.                     AP4_ByteStream&  stream,
  55.                     AP4_AtomFactory& atom_factory);
  56.     AP4_UI16           GetDataReferenceIndex() { return m_DataReferenceIndex; }
  57.     virtual AP4_Result Write(AP4_ByteStream& stream);
  58.     virtual AP4_Result Inspect(AP4_AtomInspector& inspector);
  59.     virtual AP4_SampleDescription* ToSampleDescription();
  60.     // AP4_AtomParent methods
  61.     virtual void OnChildChanged(AP4_Atom* child);
  62.  protected:
  63.     // constructor
  64.     AP4_SampleEntry(AP4_Atom::Type format, AP4_Size size);
  65.     // methods
  66.     virtual AP4_Size   GetFieldsSize();
  67.     virtual AP4_Result ReadFields(AP4_ByteStream& stream);
  68.     virtual AP4_Result WriteFields(AP4_ByteStream& stream);
  69.     virtual AP4_Result InspectFields(AP4_AtomInspector& inspector);
  70.     // members
  71.     AP4_UI08 m_Reserved1[6];         // = 0
  72.     AP4_UI16 m_DataReferenceIndex;
  73. };
  74. /*----------------------------------------------------------------------
  75. |       AP4_MpegSampleEntry
  76. +---------------------------------------------------------------------*/
  77. class AP4_MpegSampleEntry : public AP4_SampleEntry
  78. {
  79. protected:
  80.     // constructor
  81.     AP4_MpegSampleEntry(AP4_Atom::Type format);
  82.     AP4_MpegSampleEntry(AP4_Atom::Type format, AP4_Size size);
  83.     AP4_MpegSampleEntry(AP4_Atom::Type    format, 
  84.                         AP4_EsDescriptor* descriptor);
  85.     AP4_MpegSampleEntry(AP4_Atom::Type   format,
  86.                         AP4_Size         size,
  87.                         AP4_ByteStream&  stream,
  88.                         AP4_AtomFactory& atom_factory);
  89.     // methods
  90.     const AP4_DecoderConfigDescriptor* GetDecoderConfigDescriptor();
  91. };
  92. /*----------------------------------------------------------------------
  93. |       AP4_Mp4sSampleEntry
  94. +---------------------------------------------------------------------*/
  95. class AP4_Mp4sSampleEntry : public AP4_MpegSampleEntry
  96. {
  97.  public:
  98.     // constructors
  99.     AP4_Mp4sSampleEntry(AP4_Size         size,
  100.                         AP4_ByteStream&  stream,
  101.                         AP4_AtomFactory& atom_factory);
  102.     AP4_Mp4sSampleEntry(AP4_EsDescriptor* descriptor);
  103.     // methods
  104.     AP4_SampleDescription* ToSampleDescription();
  105. };
  106. /*----------------------------------------------------------------------
  107. |       AP4_AudioSampleEntry
  108. +---------------------------------------------------------------------*/
  109. class AP4_AudioSampleEntry : public AP4_MpegSampleEntry
  110. {
  111.  public:
  112.     // methods
  113.     AP4_AudioSampleEntry(AP4_Atom::Type    format,
  114.                          AP4_EsDescriptor* descriptor,
  115.                          AP4_UI32          sample_rate,
  116.                          AP4_UI16          sample_size,
  117.                          AP4_UI16          channel_count);
  118.     AP4_AudioSampleEntry(AP4_Atom::Type    format,
  119.                          AP4_Size          size,
  120.                          AP4_ByteStream&   stream,
  121.                          AP4_AtomFactory&  atom_factory);
  122.     
  123.     // accessors
  124.     AP4_UI32 GetSampleRate()   { return m_SampleRate>>16; }
  125.     AP4_UI16 GetSampleSize()   { return m_SampleSize;     }
  126.     AP4_UI16 GetChannelCount() { return m_ChannelCount;   }
  127.     // methods
  128.     AP4_SampleDescription* ToSampleDescription();
  129. protected:
  130.     // methods
  131.     virtual AP4_Size   GetFieldsSize();
  132.     virtual AP4_Result ReadFields(AP4_ByteStream& stream);
  133.     virtual AP4_Result WriteFields(AP4_ByteStream& stream);
  134.     virtual AP4_Result InspectFields(AP4_AtomInspector& inspector);
  135.     // members
  136.     AP4_UI08 m_Reserved2[8]; // = 0
  137.     AP4_UI32 m_SampleRate;           
  138.     AP4_UI16 m_ChannelCount; // = 2
  139.     AP4_UI16 m_SampleSize;   // = 16
  140.     AP4_UI16 m_Predefined1;  // = 0
  141.     AP4_UI16 m_Reserved3;    // = 0
  142. };
  143. /*----------------------------------------------------------------------
  144. |       AP4_Mp4aSampleEntry
  145. +---------------------------------------------------------------------*/
  146. class AP4_Mp4aSampleEntry : public AP4_AudioSampleEntry
  147. {
  148.  public:
  149.     // constructors
  150.     AP4_Mp4aSampleEntry(AP4_Size         size,
  151.                         AP4_ByteStream&  stream,
  152.                         AP4_AtomFactory& atom_factory);
  153.     AP4_Mp4aSampleEntry(AP4_UI32          sample_rate, 
  154.                         AP4_UI16          sample_size,
  155.                         AP4_UI16          channel_count,
  156.                         AP4_EsDescriptor* descriptor);
  157. };
  158. /*----------------------------------------------------------------------
  159. |       AP4_VisualSampleEntry
  160. +---------------------------------------------------------------------*/
  161. class AP4_VisualSampleEntry : public AP4_MpegSampleEntry
  162. {
  163.  public:
  164.     // methods
  165.     AP4_VisualSampleEntry(AP4_Atom::Type    format, 
  166.                           AP4_EsDescriptor* descriptor,
  167.                           AP4_UI16          width,
  168.                           AP4_UI16          height,
  169.                           AP4_UI16          depth,
  170.                           const char*       compressor_name);
  171.     AP4_VisualSampleEntry(AP4_Atom::Type   format,
  172.                           AP4_Size         size,
  173.                           AP4_ByteStream&  stream,
  174.                           AP4_AtomFactory& atom_factory);
  175.     // accessors
  176.     AP4_UI16    GetWidth()          { return m_Width;  }
  177.     AP4_UI16    GetHeight()         { return m_Height; }
  178.     AP4_UI16    GetHorizResolution(){ return m_HorizResolution;  }
  179.     AP4_UI16    GetVertResolution() { return m_VertResolution; }
  180.     AP4_UI16    GetDepth()          { return m_Depth;  }
  181.     const char* GetCompressorName() { return m_CompressorName.c_str(); }
  182.     // methods
  183.     AP4_SampleDescription* ToSampleDescription();
  184. protected:
  185.     // methods
  186.     virtual AP4_Size   GetFieldsSize();
  187.     virtual AP4_Result ReadFields(AP4_ByteStream& stream);
  188.     virtual AP4_Result WriteFields(AP4_ByteStream& stream);
  189.     virtual AP4_Result InspectFields(AP4_AtomInspector& inspector);
  190.     //members
  191.     AP4_UI16   m_Predefined1;     // = 0
  192. AP4_UI16   m_Reserved2;       // = 0
  193. AP4_UI08   m_Predefined2[12]; // = 0
  194. AP4_UI16   m_Width;
  195. AP4_UI16   m_Height;
  196. AP4_UI32   m_HorizResolution; // = 0x00480000 (72 dpi)
  197. AP4_UI32   m_VertResolution;  // = 0x00480000 (72 dpi)
  198. AP4_UI32   m_Reserved3;       // = 0
  199. AP4_UI16   m_FrameCount;      // = 1
  200. AP4_String m_CompressorName;       
  201. AP4_UI16   m_Depth;           // = 0x0018
  202. AP4_UI16   m_Predefined3;     // = 0xFFFF
  203. };
  204. /*----------------------------------------------------------------------
  205. |       AP4_Mp4vSampleEntry
  206. +---------------------------------------------------------------------*/
  207. class AP4_Mp4vSampleEntry : public AP4_VisualSampleEntry
  208. {
  209.  public:
  210.     // constructors
  211.     AP4_Mp4vSampleEntry(AP4_Size         size,
  212.                         AP4_ByteStream&  stream,
  213.                         AP4_AtomFactory& atom_factory);
  214.     AP4_Mp4vSampleEntry(AP4_UI16          width,
  215.                         AP4_UI16          height,
  216.                         AP4_UI16          depth,
  217.                         const char*       compressor_name,
  218.                         AP4_EsDescriptor* descriptor);
  219. };
  220. /*----------------------------------------------------------------------
  221. |       AP4_Avc1SampleEntry
  222. +---------------------------------------------------------------------*/
  223. class AP4_Avc1SampleEntry : public AP4_VisualSampleEntry
  224. {
  225. public:
  226.     // constructors
  227.     AP4_Avc1SampleEntry(AP4_Size         size,
  228.                         AP4_ByteStream&  stream,
  229.                         AP4_AtomFactory& atom_factory);
  230.     AP4_Avc1SampleEntry(AP4_UI16          width,
  231.                         AP4_UI16          height,
  232.                         AP4_UI16          depth,
  233.                         const char*       compressor_name,
  234.                         AP4_EsDescriptor* descriptor);
  235. };
  236. /*----------------------------------------------------------------------
  237. |       AP4_RtpHintSampleEntry
  238. +---------------------------------------------------------------------*/
  239. class AP4_RtpHintSampleEntry : public AP4_SampleEntry
  240. {
  241. public:
  242.     // methods
  243.     AP4_RtpHintSampleEntry(AP4_UI16 hint_track_version,
  244.                            AP4_UI16 highest_compatible_version,
  245.                            AP4_UI32 max_packet_size,
  246.                            AP4_UI32 timescale);
  247.     AP4_RtpHintSampleEntry(AP4_Size         size,
  248.                            AP4_ByteStream&  stream,
  249.                            AP4_AtomFactory& atom_factory);
  250.     virtual ~AP4_RtpHintSampleEntry();
  251.     
  252. protected:
  253.     // methods
  254.     virtual AP4_Size   GetFieldsSize();
  255.     virtual AP4_Result ReadFields(AP4_ByteStream& stream);
  256.     virtual AP4_Result WriteFields(AP4_ByteStream& stream);
  257.     virtual AP4_Result InspectFields(AP4_AtomInspector& inspector);
  258.     // members
  259.     AP4_UI16 m_HintTrackVersion;
  260.     AP4_UI16 m_HighestCompatibleVersion;
  261.     AP4_UI32 m_MaxPacketSize;
  262. };
  263. /*----------------------------------------------------------------------
  264. |       AP4_TextSampleEntry
  265. +---------------------------------------------------------------------*/
  266. class AP4_TextSampleEntry : public AP4_SampleEntry
  267. {
  268. public:
  269.     // methods
  270.     AP4_TextSampleEntry(AP4_Size         size,
  271.                            AP4_ByteStream&  stream,
  272.                            AP4_AtomFactory& atom_factory);
  273.     virtual ~AP4_TextSampleEntry();
  274.     
  275. struct AP4_TextDescription
  276. {
  277. AP4_UI32 DisplayFlags;
  278. AP4_UI32 TextJustification;
  279. AP4_UI32 BackgroundColor;
  280. struct {AP4_UI16 Top, Left, Bottom, Right;} TextBox;
  281. struct {AP4_UI16 StartChar, EndChar, Ascent; struct {AP4_UI16 Id; AP4_UI08 Face, Size; AP4_UI32 Color;} Font;} Style;
  282. AP4_String DefaultFontName;
  283. };
  284. const AP4_TextDescription& GetDescription() const { return m_Description; };
  285. protected:
  286.     // methods
  287.     virtual AP4_Result ReadFields(AP4_ByteStream& stream);
  288.     virtual AP4_Result WriteFields(AP4_ByteStream& stream);
  289.     virtual AP4_Result InspectFields(AP4_AtomInspector& inspector);
  290.     // members
  291. AP4_TextDescription m_Description;
  292. };
  293. /*----------------------------------------------------------------------
  294. |       AP4_Tx3gSampleEntry
  295. +---------------------------------------------------------------------*/
  296. class AP4_Tx3gSampleEntry : public AP4_SampleEntry
  297. {
  298. public:
  299.     // methods
  300.     AP4_Tx3gSampleEntry(AP4_Size         size,
  301.                            AP4_ByteStream&  stream,
  302.                            AP4_AtomFactory& atom_factory);
  303.     virtual ~AP4_Tx3gSampleEntry();
  304.     
  305. struct AP4_Tx3gDescription
  306. {
  307.     AP4_UI32 DisplayFlags;
  308. AP4_UI08 HorizontalJustification;
  309. AP4_UI08 VerticalJustification;
  310. AP4_UI32 BackgroundColor;
  311. struct {AP4_UI16 Top, Left, Bottom, Right;} TextBox;
  312. struct {AP4_UI16 StartChar, EndChar; struct {AP4_UI16 Id; AP4_UI08 Face, Size; AP4_UI32 Color;} Font;} Style;
  313. };
  314. const AP4_Tx3gDescription& GetDescription() const { return m_Description; };
  315. AP4_Result GetFontNameById(AP4_Ordinal Id, AP4_String& Name);
  316. protected:
  317.     // methods
  318.     virtual AP4_Size   GetFieldsSize();
  319.     virtual AP4_Result ReadFields(AP4_ByteStream& stream);
  320.     virtual AP4_Result WriteFields(AP4_ByteStream& stream);
  321.     virtual AP4_Result InspectFields(AP4_AtomInspector& inspector);
  322.     // members
  323. AP4_Tx3gDescription m_Description;
  324. };
  325. #endif // _AP4_SAMPLE_ENTRY_H_