Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/OpenAIExamples/WebRTCOpenAI/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// demo so if not provided by the OS then ChatGPT will end up talking to itself.
//
// NOTE: As of 24 Dec 2024 the official OpenAI dotnet SDK is missing the realtime
// models that represent the JSON datachannel messages. As such some ruidimentary
// models that represent the JSON datachannel messages. As such some rudimentary
// models have been created.
// The official SDK is available at https://github.com/openai/openai-dotnet.
// The OpenAI API realtime server events reference is available at
Expand All @@ -22,7 +22,7 @@
// If you don't want to pass your OpenAI API key to this app an alternative approach is
// to create an ephemeral secret using the curl comamnd below and then hard code it into
// the application.
// NOTE each epehmeral key seems like it can ONLY be used once:
// NOTE each ephemeral key seems like it can ONLY be used once:
// curl -v https://api.openai.com/v1/realtime/sessions ^
// --header "Authorization: Bearer %OPENAI_TOKEN%" ^
// --header "Content-Type: application/json" ^
Expand Down
2 changes: 1 addition & 1 deletion src/app/Media/Codecs/AudioEncoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public List<AudioFormat> SupportedFormats
/// </summary>
/// <param name="includeLinearFormats">If set to true the linear audio formats will be added
/// to the list of supported formats. The reason they are only included if explicitly requested
/// is they are not very popular for other VoIP systems and thereofre needlessly pollute the SDP.</param>
/// is they are not very popular for other VoIP systems and therefore needlessly pollute the SDP.</param>
public AudioEncoder(bool includeLinearFormats = false, bool includeOpus = false)
{
if (includeLinearFormats)
Expand Down
9 changes: 2 additions & 7 deletions src/core/CallProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
//-----------------------------------------------------------------------------

using System;
using System.Text.RegularExpressions;
using SIPSorcery.Sys;

namespace SIPSorcery.SIP
Expand All @@ -23,11 +22,7 @@ public class CallProperties
{
public static string CreateNewCallId()
{
Guid callIdGuid = Guid.NewGuid();

string callIdStr = Regex.Replace(callIdGuid.ToString(), "-", "");

return callIdStr;
return Guid.NewGuid().ToString("N");
}

public static string CreateNewTag()
Expand Down Expand Up @@ -59,7 +54,7 @@ public static string CreateBranchId(string magicCookie, string toTag, string fro

public static string CreateBranchId()
{
return SIPConstants.SIP_BRANCH_MAGICCOOKIE + Regex.Replace(Guid.NewGuid().ToString(), "-", "");
return SIPConstants.SIP_BRANCH_MAGICCOOKIE + Guid.NewGuid().ToString("N");
}
}
}
29 changes: 5 additions & 24 deletions src/core/SIP/SIPConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,17 +159,9 @@ public static SIPSchemesEnum GetSchemeType(string schemeType)

public static bool IsAllowedScheme(string schemeType)
{
try
{
Enum.Parse(typeof(SIPSchemesEnum), schemeType, true);
return true;
return Enum.TryParse<SIPSchemesEnum>(schemeType, true, out _);
}
catch
{
return false;
}
}
}

/// <summary>
/// A list of the transport layer protocols that are supported (the network layers
Expand Down Expand Up @@ -213,16 +205,8 @@ public static SIPProtocolsEnum GetProtocolTypeFromId(int protocolTypeId)

public static bool IsAllowedProtocol(string protocol)
{
try
{
Enum.Parse(typeof(SIPProtocolsEnum), protocol, true);
return true;
}
catch
{
return false;
return Enum.TryParse<SIPProtocolsEnum>(protocol, true, out _);
}
}

/// <summary>
/// Returns true for connectionless transport protocols, such as UDP, and false for
Expand Down Expand Up @@ -392,15 +376,12 @@ public static class SIPMethods
{
public static SIPMethodsEnum GetMethod(string method)
{
SIPMethodsEnum sipMethod = SIPMethodsEnum.UNKNOWN;

try
if (Enum.TryParse<SIPMethodsEnum>(method, true, out var sipMethod))
{
sipMethod = (SIPMethodsEnum)Enum.Parse(typeof(SIPMethodsEnum), method, true);
return sipMethod;
}
catch { }

return sipMethod;
return SIPMethodsEnum.UNKNOWN;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/core/SIP/SIPHeader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -856,7 +856,7 @@ public static SIPAuthenticationHeader ParseSIPAuthenticationHeader(SIPAuthorisat
{
Value = headerValue
};
if (headerValue.StartsWith(SIPAuthorisationDigest.METHOD))
if (headerValue.StartsWith(SIPAuthorisationDigest.METHOD, StringComparison.OrdinalIgnoreCase))
{
authHeader.SIPDigest = SIPAuthorisationDigest.ParseAuthorisationDigest(authorizationType, headerValue);
}
Expand Down
4 changes: 2 additions & 2 deletions src/net/HEP/HepPacket.cs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ public static byte[] GetBytes(SIPEndPoint srcEndPoint, SIPEndPoint dstEndPoint,
offset += dstPortBuffer.Length;

// Timestamp.
var timestampBuffer = HepChunk.GetBytes(ChunkTypeEnum.TimestampSeconds, (uint)timestamp.GetEpoch());
var timestampBuffer = HepChunk.GetBytes(ChunkTypeEnum.TimestampSeconds, (uint)timestamp.ToUnixTime());
Buffer.BlockCopy(timestampBuffer, 0, packetBuffer, offset, timestampBuffer.Length);
offset += timestampBuffer.Length;

Expand Down Expand Up @@ -319,4 +319,4 @@ public static byte[] GetBytes(SIPEndPoint srcEndPoint, SIPEndPoint dstEndPoint,
return packetBuffer.Take(offset).ToArray();
}
}
}
}
45 changes: 33 additions & 12 deletions src/net/RTCP/RTCPCompoundPacket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using Microsoft.Extensions.Logging;
Expand All @@ -39,6 +40,7 @@ public class RTCPCompoundPacket
public RTCPSDesReport SDesReport { get; private set; }
public RTCPBye Bye { get; set; }
public RTCPFeedback Feedback { get; set; }
public RTCPTWCCFeedback TWCCFeedback { get; set; }

protected internal RTCPCompoundPacket()
{
Expand Down Expand Up @@ -99,12 +101,19 @@ public RTCPCompoundPacket(byte[] packet)
offset += byeLength;
break;
case (byte)RTCPReportTypesEnum.RTPFB:
// TODO: Interpret Generic RTP feedback reports.
Feedback = new RTCPFeedback(buffer);
int rtpfbFeedbackLength = (Feedback != null) ? Feedback.GetBytes().Length : Int32.MaxValue;
offset += rtpfbFeedbackLength;
//var rtpfbHeader = new RTCPHeader(buffer);
//offset += rtpfbHeader.Length * 4 + 4;
var typ = RTCPHeader.ParseFeedbackType(buffer);
switch (typ) {
case RTCPFeedbackTypesEnum.TWCC:
TWCCFeedback = new RTCPTWCCFeedback(buffer);
int twccFeedbackLength = (TWCCFeedback.Header.Length + 1) * 4;
offset += twccFeedbackLength;
break;
default:
Feedback = new RTCPFeedback(buffer);
int rtpfbFeedbackLength = Feedback.GetBytes().Length;
offset += rtpfbFeedbackLength;
break;
}
break;
case (byte)RTCPReportTypesEnum.PSFB:
// TODO: Interpret Payload specific feedback reports.
Expand Down Expand Up @@ -255,12 +264,24 @@ public static bool TryParse(
offset += byeLength;
break;
case (byte)RTCPReportTypesEnum.RTPFB:
// TODO: Interpret Generic RTP feedback reports.
rtcpCompoundPacket.Feedback = new RTCPFeedback(buffer);
int rtpfbFeedbackLength = (rtcpCompoundPacket.Feedback != null) ? rtcpCompoundPacket.Feedback.GetBytes().Length : Int32.MaxValue;
offset += rtpfbFeedbackLength;
//var rtpfbHeader = new RTCPHeader(buffer);
//offset += rtpfbHeader.Length * 4 + 4;
var typ = RTCPHeader.ParseFeedbackType(buffer);
switch (typ)
{
default:
{
rtcpCompoundPacket.Feedback = new RTCPFeedback(buffer);
int rtpfbFeedbackLength = (rtcpCompoundPacket.Feedback != null) ? rtcpCompoundPacket.Feedback.GetBytes().Length : Int32.MaxValue;
offset += rtpfbFeedbackLength;
}
break;
case RTCPFeedbackTypesEnum.TWCC:
{
rtcpCompoundPacket.TWCCFeedback = new RTCPTWCCFeedback(buffer);
int twccFeedbackLength = (rtcpCompoundPacket.TWCCFeedback != null) ? rtcpCompoundPacket.TWCCFeedback.GetBytes().Length : Int32.MaxValue;
offset += twccFeedbackLength;
}
break;
}
break;
case (byte)RTCPReportTypesEnum.PSFB:
// TODO: Interpret Payload specific feedback reports.
Expand Down
4 changes: 2 additions & 2 deletions src/net/RTCP/RTCPFeedback.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ public enum RTCPFeedbackTypesEnum : int
TLLEI = 7, // Transport-Layer Third-Party Loss Early Indication [RFC6642]
RTCP_ECN_FB = 8, // RTCP ECN Feedback [RFC6679]
PAUSE_RESUME = 9, // Media Pause/Resume [RFC7728]

DBI = 10 // Delay Budget Information (DBI) [3GPP TS 26.114 v16.3.0][Ozgur_Oyman]
DBI = 10, // Delay Budget Information (DBI) [3GPP TS 26.114 v16.3.0][Ozgur_Oyman]
TWCC = 15, // Transport-Wide Congestion Control [RFC8888]
// 11-30 // Unassigned
// Extension = 31 // Reserved for future extensions [RFC4585]
}
Expand Down
17 changes: 16 additions & 1 deletion src/net/RTCP/RTCPHeader.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// Filename: RTCPHeader.cs
//
// Description: RTCP Header as defined in RFC3550.
Expand Down Expand Up @@ -128,6 +128,21 @@ public bool IsFeedbackReport()
}
}

public static RTCPFeedbackTypesEnum ParseFeedbackType(byte[] packet)
{
if (packet.Length < HEADER_BYTES_LENGTH)
{
throw new ApplicationException("The packet did not contain the minimum number of bytes for an RTCP header packet.");
}
UInt16 firstWord = BitConverter.ToUInt16(packet, 0);

if (BitConverter.IsLittleEndian)
{
firstWord = NetConvert.DoReverseEndian(firstWord);
}
return (RTCPFeedbackTypesEnum)((firstWord >> 8) & 0x1f);
}

/// <summary>
/// Extract and load the RTCP header from an RTCP packet.
/// </summary>
Expand Down
10 changes: 7 additions & 3 deletions src/net/RTCP/RTCPReceiverReport.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// Filename: RTCPReceiverReport.cs
//
// Description:
Expand Down Expand Up @@ -98,8 +98,12 @@ public RTCPReceiverReport(byte[] packet)
int rrIndex = 8;
for (int i = 0; i < Header.ReceptionReportCount; i++)
{
var rr = new ReceptionReportSample(packet.Skip(rrIndex + i * ReceptionReportSample.PAYLOAD_SIZE).ToArray());
ReceptionReports.Add(rr);
var pkt = packet.Skip(rrIndex + i * ReceptionReportSample.PAYLOAD_SIZE).ToArray();
if (pkt.Length >= ReceptionReportSample.PAYLOAD_SIZE)
{
var rr = new ReceptionReportSample(pkt);
ReceptionReports.Add(rr);
}
}
}

Expand Down
11 changes: 8 additions & 3 deletions src/net/RTCP/RTCPSenderReport.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// Filename: RTCPSenderReport.cs
//
// Description:
Expand Down Expand Up @@ -121,8 +121,13 @@ public RTCPSenderReport(byte[] packet)
int rrIndex = 28;
for (int i = 0; i < Header.ReceptionReportCount; i++)
{
var rr = new ReceptionReportSample(packet.Skip(rrIndex + i * ReceptionReportSample.PAYLOAD_SIZE).ToArray());
ReceptionReports.Add(rr);
var pkt = packet.Skip(rrIndex + i * ReceptionReportSample.PAYLOAD_SIZE).ToArray();
if (pkt.Length >= ReceptionReportSample.PAYLOAD_SIZE)
{
var rr = new ReceptionReportSample(pkt);
ReceptionReports.Add(rr);
}

}
}

Expand Down
Loading
Loading