1
0

rtphint.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  1. /*
  2. * The contents of this file are subject to the Mozilla Public
  3. * License Version 1.1 (the "License"); you may not use this file
  4. * except in compliance with the License. You may obtain a copy of
  5. * the License at http://www.mozilla.org/MPL/
  6. *
  7. * Software distributed under the License is distributed on an "AS
  8. * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  9. * implied. See the License for the specific language governing
  10. * rights and limitations under the License.
  11. *
  12. * The Original Code is MPEG4IP.
  13. *
  14. * The Initial Developer of the Original Code is Cisco Systems Inc.
  15. * Portions created by Cisco Systems Inc. are
  16. * Copyright (C) Cisco Systems Inc. 2001. All Rights Reserved.
  17. *
  18. * Contributor(s):
  19. * Dave Mackie [email protected]
  20. */
  21. #ifndef __RTPHINT_INCLUDED__
  22. #define __RTPHINT_INCLUDED__
  23. // forward declarations
  24. class MP4RtpHintTrack;
  25. class MP4RtpHint;
  26. class MP4RtpPacket;
  27. class MP4RtpData : public MP4Container {
  28. public:
  29. MP4RtpData(MP4RtpPacket* pPacket);
  30. MP4RtpPacket* GetPacket() {
  31. return m_pPacket;
  32. }
  33. virtual u_int16_t GetDataSize() = 0;
  34. virtual void GetData(u_int8_t* pDest) = 0;
  35. MP4Track* FindTrackFromRefIndex(u_int8_t refIndex);
  36. virtual void WriteEmbeddedData(MP4File* pFile, u_int64_t startPos) {
  37. // default is no-op
  38. }
  39. protected:
  40. MP4RtpPacket* m_pPacket;
  41. };
  42. MP4ARRAY_DECL(MP4RtpData, MP4RtpData*)
  43. class MP4RtpNullData : public MP4RtpData {
  44. public:
  45. MP4RtpNullData(MP4RtpPacket* pPacket);
  46. u_int16_t GetDataSize() {
  47. return 0;
  48. }
  49. void GetData(u_int8_t* pDest) {
  50. // no-op
  51. }
  52. };
  53. class MP4RtpImmediateData : public MP4RtpData {
  54. public:
  55. MP4RtpImmediateData(MP4RtpPacket* pPacket);
  56. void Set(const u_int8_t* pBytes, u_int8_t numBytes);
  57. u_int16_t GetDataSize();
  58. void GetData(u_int8_t* pDest);
  59. };
  60. class MP4RtpSampleData : public MP4RtpData {
  61. public:
  62. MP4RtpSampleData(MP4RtpPacket* pPacket);
  63. ~MP4RtpSampleData(void) {
  64. CHECK_AND_FREE(m_pRefData);
  65. };
  66. void SetEmbeddedImmediate(
  67. MP4SampleId sampleId,
  68. u_int8_t* pData, u_int16_t dataLength);
  69. void SetReferenceSample(
  70. MP4SampleId refSampleId, u_int32_t refSampleOffset,
  71. u_int16_t sampleLength);
  72. void SetEmbeddedSample(
  73. MP4SampleId sampleId, MP4Track* pRefTrack,
  74. MP4SampleId refSampleId, u_int32_t refSampleOffset,
  75. u_int16_t sampleLength);
  76. u_int16_t GetDataSize();
  77. void GetData(u_int8_t* pDest);
  78. void WriteEmbeddedData(MP4File* pFile, u_int64_t startPos);
  79. protected:
  80. u_int8_t* m_pRefData;
  81. MP4Track* m_pRefTrack;
  82. MP4SampleId m_refSampleId;
  83. u_int32_t m_refSampleOffset;
  84. };
  85. class MP4RtpSampleDescriptionData : public MP4RtpData {
  86. public:
  87. MP4RtpSampleDescriptionData(MP4RtpPacket* pPacket);
  88. void Set(u_int32_t sampleDescrIndex,
  89. u_int32_t offset, u_int16_t length);
  90. u_int16_t GetDataSize();
  91. void GetData(u_int8_t* pDest);
  92. };
  93. class MP4RtpPacket : public MP4Container {
  94. public:
  95. MP4RtpPacket(MP4RtpHint* pHint);
  96. ~MP4RtpPacket();
  97. void AddExtraProperties();
  98. MP4RtpHint* GetHint() {
  99. return m_pHint;
  100. }
  101. void Set(u_int8_t payloadNumber, u_int32_t packetId, bool setMbit);
  102. int32_t GetTransmitOffset();
  103. bool GetPBit();
  104. bool GetXBit();
  105. bool GetMBit();
  106. u_int8_t GetPayload();
  107. u_int16_t GetSequenceNumber();
  108. void SetTransmitOffset(int32_t transmitOffset);
  109. bool IsBFrame();
  110. void SetBFrame(bool isBFrame);
  111. void SetTimestampOffset(u_int32_t timestampOffset);
  112. void AddData(MP4RtpData* pData);
  113. u_int32_t GetDataSize();
  114. void GetData(u_int8_t* pDest);
  115. void Read(MP4File* pFile);
  116. void ReadExtra(MP4File* pFile);
  117. void Write(MP4File* pFile);
  118. void WriteEmbeddedData(MP4File* pFile, u_int64_t startPos);
  119. protected:
  120. MP4RtpHint* m_pHint;
  121. MP4RtpDataArray m_rtpData;
  122. };
  123. MP4ARRAY_DECL(MP4RtpPacket, MP4RtpPacket*)
  124. class MP4RtpHint : public MP4Container {
  125. public:
  126. MP4RtpHint(MP4RtpHintTrack* pTrack);
  127. ~MP4RtpHint();
  128. MP4RtpHintTrack* GetTrack() {
  129. return m_pTrack;
  130. }
  131. u_int16_t GetNumberOfPackets() {
  132. return m_rtpPackets.Size();
  133. }
  134. bool IsBFrame() {
  135. return m_isBFrame;
  136. }
  137. void SetBFrame(bool isBFrame) {
  138. m_isBFrame = isBFrame;
  139. }
  140. u_int32_t GetTimestampOffset() {
  141. return m_timestampOffset;
  142. }
  143. void SetTimestampOffset(u_int32_t timestampOffset) {
  144. m_timestampOffset = timestampOffset;
  145. }
  146. MP4RtpPacket* AddPacket();
  147. MP4RtpPacket* GetPacket(u_int16_t index) {
  148. return m_rtpPackets[index];
  149. }
  150. MP4RtpPacket* GetCurrentPacket() {
  151. if (m_rtpPackets.Size() == 0) {
  152. return NULL;
  153. }
  154. return m_rtpPackets[m_rtpPackets.Size() - 1];
  155. }
  156. void Read(MP4File* pFile);
  157. void Write(MP4File* pFile);
  158. protected:
  159. MP4RtpHintTrack* m_pTrack;
  160. MP4RtpPacketArray m_rtpPackets;
  161. // values when adding packets to a hint (write mode)
  162. bool m_isBFrame;
  163. u_int32_t m_timestampOffset;
  164. };
  165. class MP4RtpHintTrack : public MP4Track {
  166. public:
  167. MP4RtpHintTrack(MP4File* pFile, MP4Atom* pTrakAtom);
  168. ~MP4RtpHintTrack();
  169. void InitRefTrack();
  170. void InitPayload();
  171. void InitRtpStart();
  172. void InitStats();
  173. MP4Track* GetRefTrack() {
  174. InitRefTrack();
  175. return m_pRefTrack;
  176. }
  177. void GetPayload(
  178. char** ppPayloadName = NULL,
  179. u_int8_t* pPayloadNumber = NULL,
  180. u_int16_t* pMaxPayloadSize = NULL,
  181. char **ppEncodingParams = NULL);
  182. void SetPayload(
  183. const char* payloadName,
  184. u_int8_t payloadNumber,
  185. u_int16_t maxPayloadSize,
  186. const char *encoding_parms,
  187. bool add_rtpmap,
  188. bool add_mpeg4_esid);
  189. void ReadHint(
  190. MP4SampleId hintSampleId,
  191. u_int16_t* pNumPackets = NULL);
  192. u_int16_t GetHintNumberOfPackets();
  193. bool GetPacketBFrame(u_int16_t packetIndex);
  194. u_int16_t GetPacketTransmitOffset(u_int16_t packetIndex);
  195. void ReadPacket(
  196. u_int16_t packetIndex,
  197. u_int8_t** ppBytes,
  198. u_int32_t* pNumBytes,
  199. u_int32_t ssrc,
  200. bool includeHeader = true,
  201. bool includePayload = true);
  202. MP4Timestamp GetRtpTimestampStart();
  203. void SetRtpTimestampStart(MP4Timestamp start);
  204. void AddHint(bool isBFrame, u_int32_t timestampOffset);
  205. void AddPacket(bool setMbit, int32_t transmitOffset = 0);
  206. void AddImmediateData(const u_int8_t* pBytes, u_int32_t numBytes);
  207. void AddSampleData(MP4SampleId sampleId,
  208. u_int32_t dataOffset, u_int32_t dataLength);
  209. void AddESConfigurationPacket();
  210. void WriteHint(MP4Duration duration, bool isSyncSample);
  211. void FinishWrite();
  212. protected:
  213. MP4Track* m_pRefTrack;
  214. MP4StringProperty* m_pRtpMapProperty;
  215. MP4Integer32Property* m_pPayloadNumberProperty;
  216. MP4Integer32Property* m_pMaxPacketSizeProperty;
  217. MP4Integer32Property* m_pSnroProperty;
  218. MP4Integer32Property* m_pTsroProperty;
  219. u_int32_t m_rtpSequenceStart;
  220. u_int32_t m_rtpTimestampStart;
  221. // reading
  222. MP4RtpHint* m_pReadHint;
  223. u_int8_t* m_pReadHintSample;
  224. u_int32_t m_readHintSampleSize;
  225. MP4Timestamp m_readHintTimestamp;
  226. // writing
  227. MP4RtpHint* m_pWriteHint;
  228. MP4SampleId m_writeHintId;
  229. u_int32_t m_writePacketId;
  230. // statistics
  231. // in trak.udta.hinf
  232. MP4Integer64Property* m_pTrpy;
  233. MP4Integer64Property* m_pNump;
  234. MP4Integer64Property* m_pTpyl;
  235. MP4Integer32Property* m_pMaxr;
  236. MP4Integer64Property* m_pDmed;
  237. MP4Integer64Property* m_pDimm;
  238. MP4Integer32Property* m_pPmax;
  239. MP4Integer32Property* m_pDmax;
  240. // in trak.mdia.minf.hmhd
  241. MP4Integer16Property* m_pMaxPdu;
  242. MP4Integer16Property* m_pAvgPdu;
  243. MP4Integer32Property* m_pMaxBitRate;
  244. MP4Integer32Property* m_pAvgBitRate;
  245. MP4Timestamp m_thisSec;
  246. u_int32_t m_bytesThisSec;
  247. u_int32_t m_bytesThisHint;
  248. u_int32_t m_bytesThisPacket;
  249. };
  250. #endif /* __RTPHINT_INCLUDED__ */