Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add RTCP packet #154

Merged
merged 11 commits into from
Oct 14, 2021
Prev Previous commit
Next Next commit
code modification based on PR review comments
  • Loading branch information
jgaulon committed Oct 12, 2021
commit 344b0b73c4ebf68e5efd9bfbb6dee9a9438c2f1e
2 changes: 1 addition & 1 deletion PacketDotNet/PacketDotNet.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard2.0;net47</TargetFrameworks>
<TargetFrameworks>netstandard2.0;net472</TargetFrameworks>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<Description>.Net assembly for dissecting and constructing network packets</Description>
Expand Down
16 changes: 9 additions & 7 deletions PacketDotNet/RtcpContainerPacket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public sealed class RtcpContainerPacket : Packet
private static readonly ILogInactive Log;
#pragma warning restore 0169, 0649
#endif
private LazySlim<List<RtcpPacket>> lazyRtcpPackets { get; } = new (null);
jgaulon marked this conversation as resolved.
Show resolved Hide resolved

/// <summary>
/// Create from values
Expand Down Expand Up @@ -62,14 +63,14 @@ public RtcpContainerPacket(ByteArraySegment byteArraySegment, Packet parentPacke
{
Log.Debug("");

LazyRtcpItems = new LazySlim<List<RtcpItemPacket>>(() =>
lazyRtcpPackets = new LazySlim<List<RtcpPacket>>(() =>
{
var list = new List<RtcpItemPacket>();
var list = new List<RtcpPacket>();
ByteArraySegment segment = byteArraySegment;
RtcpItemPacket item;
RtcpPacket item;
do
{
item = new RtcpItemPacket(segment, this);
item = new RtcpPacket(segment, this);
list.Add(item);
segment = item.HeaderDataSegment;
} while (segment.Length > 0);
Expand All @@ -83,8 +84,9 @@ public RtcpContainerPacket(ByteArraySegment byteArraySegment, Packet parentPacke
/// <summary>Fetch ascii escape sequence of the color associated with this packet type.</summary>
public override string Color => AnsiEscapeSequences.BlueBackground;

internal LazySlim<List<RtcpItemPacket>> LazyRtcpItems { get; } = new (null);

public List<RtcpItemPacket> RtcpItems => this.LazyRtcpItems.Value;
/// <summary>
/// Gets the Rtcp packets
/// </summary>
public List<RtcpPacket> Packets => this.lazyRtcpPackets.Value;
jgaulon marked this conversation as resolved.
Show resolved Hide resolved
}
}
8 changes: 5 additions & 3 deletions PacketDotNet/RtcpItemPacket.cs → PacketDotNet/RtcpPacket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace PacketDotNet
/// See: https://en.wikipedia.org/wiki/RTP_Control_Protocol
/// See: https://wiki.wireshark.org/RTCP
/// </summary>
public sealed class RtcpItemPacket : Packet
public sealed class RtcpPacket : Packet
{
#if DEBUG
private static readonly ILog Log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
Expand All @@ -40,7 +40,7 @@ public sealed class RtcpItemPacket : Packet
/// <summary>
/// Create from values
/// </summary>
public RtcpItemPacket()
public RtcpPacket()
{
Log.Debug("");

Expand All @@ -59,7 +59,7 @@ public RtcpItemPacket()
/// <param name="parentPacket">
/// A <see cref="Packet" />
/// </param>
public RtcpItemPacket(ByteArraySegment byteArraySegment, Packet parentPacket)
public RtcpPacket(ByteArraySegment byteArraySegment, Packet parentPacket)
{
Log.Debug("");

Expand Down Expand Up @@ -151,8 +151,10 @@ public bool IsValid()
{
if (Header.Length < RtcpFields.HeaderLength + (Length - 1) * 4)
return false;

if (Version != 2)
return false;

return true;
}
}
Expand Down
10 changes: 5 additions & 5 deletions Test/PacketType/RtcpPacketTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ public void RtcpGoodByeParsing()
Assert.IsFalse(rtcpContainer.HasPayloadData);
Assert.IsFalse(rtcpContainer.HasPayloadPacket);

Assert.AreEqual(1,rtcpContainer.RtcpItems.Count);
var rtcp = rtcpContainer.RtcpItems[0];
Assert.AreEqual(1,rtcpContainer.Packets.Count);
var rtcp = rtcpContainer.Packets[0];
Assert.IsTrue(rtcp.IsValid());
Assert.AreEqual(2, rtcp.Version);
Assert.IsFalse(rtcp.HasPadding);
Expand Down Expand Up @@ -98,8 +98,8 @@ public void RtcpReportsParsing()
Assert.IsFalse(rtcpContainer.HasPayloadData);
Assert.IsFalse(rtcpContainer.HasPayloadPacket);

Assert.AreEqual(2,rtcpContainer.RtcpItems.Count);
var rtcp = rtcpContainer.RtcpItems[0];
Assert.AreEqual(2,rtcpContainer.Packets.Count);
var rtcp = rtcpContainer.Packets[0];
Assert.IsTrue(rtcp.IsValid());
Assert.AreEqual(2, rtcp.Version);
Assert.IsFalse(rtcp.HasPadding);
Expand All @@ -110,7 +110,7 @@ public void RtcpReportsParsing()
Assert.IsTrue(rtcp.HasPayloadData);
Assert.IsFalse(rtcp.HasPayloadPacket);

var nextRtcp = rtcpContainer.RtcpItems[1];
var nextRtcp = rtcpContainer.Packets[1];
Assert.IsNotNull(nextRtcp);
Console.WriteLine(nextRtcp.GetType());
Assert.IsTrue(nextRtcp.IsValid());
Expand Down