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

多媒体编程

开发平台:

Visual C++

  1. /*****************************************************************
  2. |
  3. |    AP4 - RTP Hint Objects
  4. |
  5. |    Copyright 2002-2005 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_RTP_HINT_H_
  29. #define _AP4_RTP_HINT_H_
  30. /*----------------------------------------------------------------------
  31. |       includes
  32. +---------------------------------------------------------------------*/
  33. #include "Ap4.h"
  34. #include "Ap4List.h"
  35. #include "Ap4DataBuffer.h"
  36. #include "Ap4Interfaces.h"
  37. /*----------------------------------------------------------------------
  38. |       forward declarations
  39. +---------------------------------------------------------------------*/
  40. class AP4_ByteStream;
  41. class AP4_RtpConstructor;
  42. class AP4_RtpPacket;
  43. /*----------------------------------------------------------------------
  44. |       AP4_RtpSampleData
  45. +---------------------------------------------------------------------*/
  46. class AP4_RtpSampleData
  47. {
  48. public:
  49.     // constructors and destructor
  50.     AP4_RtpSampleData(AP4_ByteStream& stream, AP4_Size size);
  51.     AP4_RtpSampleData() {}
  52.     virtual ~AP4_RtpSampleData();
  53.     // methods
  54.     virtual AP4_Result          AddPacket(AP4_RtpPacket* packet);
  55.     virtual AP4_Size            GetSize();
  56.     virtual AP4_ByteStream*     ToByteStream();
  57.     
  58.     // accessors
  59.     AP4_List<AP4_RtpPacket>& GetPackets() {
  60.         return m_Packets;
  61.     }
  62.     const AP4_DataBuffer& GetExtraData() const {
  63.         return m_ExtraData;
  64.     }
  65. protected:
  66.     // members
  67.     AP4_List<AP4_RtpPacket>     m_Packets;
  68.     AP4_DataBuffer              m_ExtraData;
  69. };
  70. /*----------------------------------------------------------------------
  71. |       AP4_RtpPacket
  72. +---------------------------------------------------------------------*/
  73. class AP4_RtpPacket : public AP4_Referenceable
  74. {
  75. public:
  76.     // constructor and destructor
  77.     AP4_RtpPacket(AP4_ByteStream& stream);
  78.     AP4_RtpPacket(AP4_Integer relative_time,
  79.                   bool p_bit,
  80.                   bool x_bit,
  81.                   bool m_bit,
  82.                   AP4_UI08 payload_type,
  83.                   AP4_UI16 sequence_seed,
  84.                   AP4_Integer time_stamp_offset = 0,
  85.                   bool bframe_flag = false,
  86.                   bool repeat_flag = false);
  87.     ~AP4_RtpPacket();
  88.     // methods
  89.     AP4_Result Write(AP4_ByteStream& stream);
  90.     AP4_Result AddConstructor(AP4_RtpConstructor* constructor);
  91.     AP4_Size GetSize();
  92.     AP4_Size GetConstructedDataSize();
  93.     // Referenceable methods
  94.     void AddReference();
  95.     void Release();
  96.     
  97.     // Accessors
  98.     AP4_Integer GetRelativeTime() const { return m_RelativeTime; }
  99.     bool GetPBit() const { return m_PBit; }
  100.     bool GetXBit() const { return m_XBit; }
  101.     bool GetMBit() const { return m_MBit; }
  102.     AP4_UI08 GetPayloadType() const { return m_PayloadType; }
  103.     AP4_UI16 GetSequenceSeed() const { return m_SequenceSeed; }
  104.     AP4_Integer GetTimeStampOffset() const { return m_TimeStampOffset; }
  105.     bool GetBFrameFlag() const { return m_BFrameFlag; }
  106.     bool GetRepeatFlag() const { return m_RepeatFlag; }
  107.     AP4_List<AP4_RtpConstructor>& GetConstructors() {
  108.         return m_Constructors;
  109.     }
  110. private:
  111.     // members
  112.     AP4_Cardinal                    m_ReferenceCount;                        
  113.     AP4_Integer                     m_RelativeTime;
  114.     bool                            m_PBit;
  115.     bool                            m_XBit;
  116.     bool                            m_MBit;
  117.     AP4_UI08                        m_PayloadType;
  118.     AP4_UI16                        m_SequenceSeed;
  119.     AP4_Integer                     m_TimeStampOffset;
  120.     bool                            m_BFrameFlag;
  121.     bool                            m_RepeatFlag;
  122.     AP4_List<AP4_RtpConstructor>    m_Constructors;
  123. };
  124. /*----------------------------------------------------------------------
  125. |       AP4_RtpContructor
  126. +---------------------------------------------------------------------*/
  127. class AP4_RtpConstructor : public AP4_Referenceable
  128. {
  129. public:
  130.     // types
  131.     typedef AP4_UI08 Type;
  132.     // constructor & destructor
  133.     AP4_RtpConstructor(Type type) : m_ReferenceCount(1), m_Type(type) {}
  134.     // methods
  135.     Type GetType() const { return m_Type; }
  136.     AP4_Result Write(AP4_ByteStream& stream);
  137.     virtual AP4_Size GetConstructedDataSize() = 0;
  138.     // Referenceable methods
  139.     void AddReference();
  140.     void Release();
  141. protected:
  142.     // methods
  143.     virtual ~AP4_RtpConstructor() {}
  144.     virtual AP4_Result DoWrite(AP4_ByteStream& stream) = 0;
  145.     // members
  146.     AP4_Cardinal m_ReferenceCount;
  147.     Type         m_Type;
  148. };
  149. /*----------------------------------------------------------------------
  150. |       constructor size
  151. +---------------------------------------------------------------------*/
  152. const AP4_Size AP4_RTP_CONSTRUCTOR_SIZE = 16;
  153. /*----------------------------------------------------------------------
  154. |       constructor types
  155. +---------------------------------------------------------------------*/
  156. const AP4_RtpConstructor::Type AP4_RTP_CONSTRUCTOR_TYPE_NOOP        = 0;
  157. const AP4_RtpConstructor::Type AP4_RTP_CONSTRUCTOR_TYPE_IMMEDIATE   = 1;
  158. const AP4_RtpConstructor::Type AP4_RTP_CONSTRUCTOR_TYPE_SAMPLE      = 2;
  159. const AP4_RtpConstructor::Type AP4_RTP_CONSTRUCTOR_TYPE_SAMPLE_DESC = 3;
  160. /*----------------------------------------------------------------------
  161. |       AP4_NoopRtpConstructor
  162. +---------------------------------------------------------------------*/
  163. class AP4_NoopRtpConstructor : public AP4_RtpConstructor
  164. {
  165. public:
  166.     // constructor
  167.     AP4_NoopRtpConstructor(AP4_ByteStream& stream);
  168.     AP4_NoopRtpConstructor() : AP4_RtpConstructor(AP4_RTP_CONSTRUCTOR_TYPE_NOOP) {}
  169.     // methods
  170.     virtual AP4_Size GetConstructedDataSize() { return 0; }
  171. protected:
  172.     // methods
  173.     virtual AP4_Result DoWrite(AP4_ByteStream& stream);
  174. };
  175. /*----------------------------------------------------------------------
  176. |       AP4_ImmediateRtpConstructor
  177. +---------------------------------------------------------------------*/
  178. class AP4_ImmediateRtpConstructor : public AP4_RtpConstructor
  179. {
  180. public:
  181.     // constructor
  182.     AP4_ImmediateRtpConstructor(AP4_ByteStream& stream);
  183.     AP4_ImmediateRtpConstructor(const AP4_DataBuffer& data);
  184.     
  185.     // accessors
  186.     const AP4_DataBuffer& GetData() const { return m_Data; }
  187.     // methods
  188.     virtual AP4_Size GetConstructedDataSize() { return m_Data.GetDataSize(); }
  189. protected:
  190.     // methods
  191.     virtual AP4_Result DoWrite(AP4_ByteStream& stream);
  192.     // members
  193.     AP4_DataBuffer m_Data;
  194. };
  195. /*----------------------------------------------------------------------
  196. |       AP4_SampleRtpConstructor
  197. +---------------------------------------------------------------------*/
  198. class AP4_SampleRtpConstructor : public AP4_RtpConstructor
  199. {
  200. public:
  201.     // constructor
  202.     AP4_SampleRtpConstructor(AP4_ByteStream& stream);
  203.     AP4_SampleRtpConstructor(AP4_UI08 track_ref_index,
  204.                              AP4_UI16 length,
  205.                              AP4_UI32 sample_num,
  206.                              AP4_UI32 sample_offset);
  207.     
  208.     // accessors
  209.     AP4_UI08 GetTrackRefIndex() const { return m_TrackRefIndex; }
  210.     AP4_UI16 GetLength() const { return m_Length; }
  211.     AP4_UI32 GetSampleNum() const { return m_SampleNum; }
  212.     AP4_UI32 GetSampleOffset() const { return m_SampleOffset; }
  213.     // methods
  214.     virtual AP4_Size GetConstructedDataSize() { return m_Length; }
  215. protected:
  216.     // methods
  217.     virtual AP4_Result DoWrite(AP4_ByteStream& stream);
  218.     // members
  219.     AP4_UI08    m_TrackRefIndex;
  220.     AP4_UI16    m_Length;
  221.     AP4_UI32    m_SampleNum;
  222.     AP4_UI32    m_SampleOffset;
  223. };
  224. /*----------------------------------------------------------------------
  225. |       AP4_SampleDescRtpConstructor
  226. +---------------------------------------------------------------------*/
  227. class AP4_SampleDescRtpConstructor : public AP4_RtpConstructor
  228. {
  229. public:
  230.     // constructor
  231.     AP4_SampleDescRtpConstructor(AP4_ByteStream& stream);
  232.     AP4_SampleDescRtpConstructor(AP4_UI08 track_ref_index,
  233.                                  AP4_UI16 length,
  234.                                  AP4_UI32 sample_desc_index,
  235.                                  AP4_UI32 sample_desc_offset);
  236.     // accessors
  237.     AP4_UI08 GetTrackRefIndex() const { return m_TrackRefIndex; }
  238.     AP4_UI16 GetLength() const { return m_Length; }
  239.     AP4_UI32 GetSampleDescIndex() const { return m_SampleDescIndex; }
  240.     AP4_UI32 GetSampleDescOffset() const { return m_SampleDescOffset; }
  241.     // methods
  242.     virtual AP4_Size GetConstructedDataSize() { return m_Length; }
  243.         
  244. protected:
  245.     // methods
  246.     virtual AP4_Result DoWrite(AP4_ByteStream& stream);
  247.     // members
  248.     AP4_UI08    m_TrackRefIndex;
  249.     AP4_UI16    m_Length;
  250.     AP4_UI32    m_SampleDescIndex;
  251.     AP4_UI32    m_SampleDescOffset;
  252. };
  253. /*----------------------------------------------------------------------
  254. |       AP4_RtpConstructorFactory
  255. +---------------------------------------------------------------------*/
  256. class AP4_RtpConstructorFactory 
  257. {
  258. public:
  259.     static AP4_Result CreateConstructorFromStream(AP4_ByteStream& stream,
  260.                                                   AP4_RtpConstructor*& constructor);
  261. };
  262. #endif // _AP4_RTP_HINT_H_