RtcpSenderReportPacket.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. using System.Collections.ObjectModel;
  2. /*
  3. Copyright (C) <2007-2016> <Kay Diefenthal>
  4. SatIp.RtspSample is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  8. SatIp.RtspSample is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with SatIp.RtspSample. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. using System.Text;
  16. namespace MediaBrowser.Server.Implementations.LiveTv.TunerHosts.SatIp.Rtcp
  17. {
  18. public class RtcpSenderReportPacket : RtcpPacket
  19. {
  20. #region Properties
  21. /// <summary>
  22. /// Get the synchronization source.
  23. /// </summary>
  24. public int SynchronizationSource { get; private set; }
  25. /// <summary>
  26. /// Get the NPT timestamp.
  27. /// </summary>
  28. public long NPTTimeStamp { get; private set; }
  29. /// <summary>
  30. /// Get the RTP timestamp.
  31. /// </summary>
  32. public int RTPTimeStamp { get; private set; }
  33. /// <summary>
  34. /// Get the packet count.
  35. /// </summary>
  36. public int SenderPacketCount { get; private set; }
  37. /// <summary>
  38. /// Get the octet count.
  39. /// </summary>
  40. public int SenderOctetCount { get; private set; }
  41. /// <summary>
  42. /// Get the list of report blocks.
  43. /// </summary>
  44. public Collection<ReportBlock> ReportBlocks { get; private set; }
  45. /// <summary>
  46. /// Get the profile extension data.
  47. /// </summary>
  48. public byte[] ProfileExtension { get; private set; }
  49. #endregion
  50. public override void Parse(byte[] buffer, int offset)
  51. {
  52. base.Parse(buffer, offset);
  53. SynchronizationSource = Utils.Convert4BytesToInt(buffer, offset + 4);
  54. NPTTimeStamp = Utils.Convert8BytesToLong(buffer, offset + 8);
  55. RTPTimeStamp = Utils.Convert4BytesToInt(buffer, offset + 16);
  56. SenderPacketCount = Utils.Convert4BytesToInt(buffer, offset + 20);
  57. SenderOctetCount = Utils.Convert4BytesToInt(buffer, offset + 24);
  58. ReportBlocks = new Collection<ReportBlock>();
  59. int index = 28;
  60. while (ReportBlocks.Count < ReportCount)
  61. {
  62. ReportBlock reportBlock = new ReportBlock();
  63. reportBlock.Process(buffer, offset + index);
  64. ReportBlocks.Add(reportBlock);
  65. index += reportBlock.BlockLength;
  66. }
  67. if (index < Length)
  68. {
  69. ProfileExtension = new byte[Length - index];
  70. for (int extensionIndex = 0; index < Length; index++)
  71. {
  72. ProfileExtension[extensionIndex] = buffer[offset + index];
  73. extensionIndex++;
  74. }
  75. }
  76. }
  77. public override string ToString()
  78. {
  79. StringBuilder sb = new StringBuilder();
  80. sb.AppendFormat("Sender Report.\n");
  81. sb.AppendFormat("Version : {0} .\n", Version);
  82. sb.AppendFormat("Padding : {0} .\n", Padding);
  83. sb.AppendFormat("Report Count : {0} .\n", ReportCount);
  84. sb.AppendFormat("PacketType: {0} .\n", Type);
  85. sb.AppendFormat("Length : {0} .\n", Length);
  86. sb.AppendFormat("SynchronizationSource : {0} .\n", SynchronizationSource);
  87. sb.AppendFormat("NTP Timestamp : {0} .\n", Utils.NptTimestampToDateTime(NPTTimeStamp));
  88. sb.AppendFormat("RTP Timestamp : {0} .\n", RTPTimeStamp);
  89. sb.AppendFormat("Sender PacketCount : {0} .\n", SenderPacketCount);
  90. sb.AppendFormat("Sender Octet Count : {0} .\n", SenderOctetCount);
  91. sb.AppendFormat(".\n");
  92. return sb.ToString();
  93. }
  94. }
  95. }