forked from kthompson/RtpLib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RtcpReceiverReport.cs
159 lines (130 loc) · 4.64 KB
/
RtcpReceiverReport.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Net;
namespace RtpLib
{
public class RtcpReceiverReport : RtcpPacket
{
#region Public Methods
public override void ParseData(Stream stream)
{
byte[] bytes = new byte[28];
int length = stream.Read(bytes, 0, bytes.Length);
// The receiver report may only contain the SSRC, but may contain more
// So as long as we have at least 4 bytes then we have valid data
if (length < 4)
throw new InvalidDataException();
this.Ssrc = (uint)IPAddress.NetworkToHostOrder(BitConverter.ToInt32(bytes, 0));
this.SsrcOnly = (length == bytes.Length);
if (!this.SsrcOnly)
{
this.ReporteeSsrc = (uint)IPAddress.NetworkToHostOrder(BitConverter.ToInt32(bytes, 4));
this.LossFraction = bytes[4];
this.CumulativeLoss = (uint)IPAddress.NetworkToHostOrder(BitConverter.ToInt32(bytes, 4)) & 0x00FFFFFF;
this.ExtendedHighestSequenceNumber = (uint)IPAddress.NetworkToHostOrder(BitConverter.ToInt32(bytes, 8));
this.InterarrivalJitter = (uint)IPAddress.NetworkToHostOrder(BitConverter.ToInt32(bytes, 12));
this.LastSenderReportTimestamp = (uint)IPAddress.NetworkToHostOrder(BitConverter.ToInt32(bytes, 16));
this.LastSenderReportDelay = (uint)IPAddress.NetworkToHostOrder(BitConverter.ToInt32(bytes, 20));
// Need to sign-extend this value.
if ((0x00800000 & this.CumulativeLoss) != 0)
{
this.CumulativeLoss |= 0xFF000000;
}
}
else
{
this.ReporteeSsrc = 0;
this.LossFraction = 0;
this.CumulativeLoss = 0;
this.ExtendedHighestSequenceNumber = 0;
this.InterarrivalJitter = 0;
this.LastSenderReportTimestamp = 0;
this.LastSenderReportDelay = 0;
}
}
#endregion
#region Protected Methods
protected override int GetByteCount()
{
return (this.SsrcOnly ? 4 : 24);
}
protected override void ToStreamInternal(Stream stream)
{
var writer = new BinaryWriter(stream);
writer.Write((uint)IPAddress.HostToNetworkOrder((int)this.Ssrc));
// If we're only writing the SSRC then we're done
if (this.SsrcOnly)
return;
writer.Write((uint)IPAddress.HostToNetworkOrder((int)this.ReporteeSsrc));
writer.Write(this.LossFraction);
writer.Write(BitConverter.GetBytes(IPAddress.HostToNetworkOrder((int)this.CumulativeLoss)), 1, 3);
writer.Write((uint)IPAddress.HostToNetworkOrder((int)this.ExtendedHighestSequenceNumber));
writer.Write((uint)IPAddress.HostToNetworkOrder((int)this.InterarrivalJitter));
writer.Write((uint)IPAddress.HostToNetworkOrder((int)this.LastSenderReportTimestamp));
writer.Write((uint)IPAddress.HostToNetworkOrder((int)this.LastSenderReportDelay));
}
#endregion
#region
public override Rtcp.PacketType PacketType
{
get { return Rtcp.PacketType.ReceiverReport; }
}
public bool SsrcOnly
{
get;
set;
}
public uint Ssrc
{
get;
set;
}
public uint ReporteeSsrc
{
get;
set;
}
public byte LossFraction
{
get;
set;
}
public uint CumulativeLoss
{
get;
set;
}
public uint ExtendedHighestSequenceNumber
{
get;
set;
}
public uint InterarrivalJitter
{
get;
set;
}
public uint LastSenderReportTimestamp
{
get;
set;
}
public uint LastSenderReportDelay
{
get;
set;
}
#endregion
#region ICloneable Implementation
public override object Clone()
{
var packet = this.MemberwiseClone() as RtcpReceiverReport;
packet.Header = packet.Header.Clone() as RtcpHeader;
return packet;
}
#endregion
}
}