Skip to content
Draft
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
39 changes: 24 additions & 15 deletions src/SIPSorcery.VP8/DebugProbe.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
//-----------------------------------------------------------------------------

using System.Diagnostics;
using System.Text;

namespace Vpx.Net
{
Expand All @@ -30,13 +31,14 @@ public static void DumpMotionVectors(MODE_INFO[] mip, int macroBlockCols, int ma
Debug.WriteLine("Macro Block Modes:");
for (int i = 0; i < macroBlockRows + 1; i++)
{
string rowStr = $"Row {i} | ";
var rowBuilder = new StringBuilder().Append("Row ").Append(i).Append(" | ");
for (int j = 0; j < macroBlockCols + 1; j++)
{
byte yMode = mip[i * (macroBlockRows + 1) + j].mbmi.mode;
byte uvMode = mip[i * (macroBlockRows + 1) + j].mbmi.uv_mode;
rowStr += $"y={yMode}, uvMode={uvMode} | ";
rowBuilder.Append("y=").Append(yMode).Append(", uvMode=").Append(uvMode).Append(" | ");
}
string rowStr = rowBuilder.ToString();
Debug.WriteLine(rowStr);
}

Expand All @@ -54,15 +56,20 @@ public static void DumpMotionVectors(MODE_INFO[] mip, int macroBlockCols, int ma
public static string GetBModeInfoMatrix(b_mode_info[] bModes)
{
// The array will always be 16 elements.
string matrixStr = null;
var matrixBuilder = new StringBuilder();

for(int row=0; row<4; row++)
{
matrixStr += $"[{bModes[row * 4].mv.as_int},{bModes[row * 4 + 1].mv.as_int}" +
$",{bModes[row * 4 +2].mv.as_int},{bModes[row * 4 + 3].mv.as_int}]\n";
matrixBuilder
.Append('[')
.Append(bModes[row * 4].mv.as_int).Append(',')
.Append(bModes[row * 4 + 1].mv.as_int).Append(',')
.Append(bModes[row * 4 + 2].mv.as_int).Append(',')
.Append(bModes[row * 4 + 3].mv.as_int)
.Append("]\n");
}

return matrixStr;
return matrixBuilder.ToString();
}

public static unsafe void DumpMacroBlock(MACROBLOCKD macroBlock, int macroBlockIndex)
Expand All @@ -89,11 +96,12 @@ public static unsafe void DumpSubBlockCoefficients(MACROBLOCKD macroBlock)
for(int i=0; i< macroBlock.block.Length; i++)
{
var subBlock = macroBlock.block[i];
string qCoeff = null;
var qCoeffBuilder = new StringBuilder();
for(int j=subBlock.qcoeff.Index; j< subBlock.qcoeff.Index+16; j++)
{
qCoeff += subBlock.qcoeff.src()[j].ToString() + ",";
qCoeffBuilder.Append(subBlock.qcoeff.src()[j]).Append(',');
}
string qCoeff = qCoeffBuilder.ToString();
Debug.WriteLine($"block[{i}].qcoeff={qCoeff}");
}

Expand All @@ -104,11 +112,12 @@ public static unsafe void DumpSubBlockCoefficients(MACROBLOCKD macroBlock)
for (int i = 0; i < macroBlock.block.Length; i++)
{
var subBlock = macroBlock.block[i];
string dqCoeff = null;
var dqCoeffBuilder = new StringBuilder();
for (int j = subBlock.dqcoeff.Index; j < subBlock.dqcoeff.Index + 16; j++)
{
dqCoeff += subBlock.dqcoeff.src()[j].ToString() + ",";
dqCoeffBuilder.Append(subBlock.dqcoeff.src()[j]).Append(',');
}
string dqCoeff = dqCoeffBuilder.ToString();
Debug.WriteLine($"block[{i}].dqcoeff={dqCoeff}");
}

Expand Down Expand Up @@ -160,21 +169,21 @@ public static class DebugProbeHexStr

public unsafe static string ToHexStr(byte* buffer, int length, char? separator = null)
{
string rv = string.Empty;
var builder = new StringBuilder(length * (separator == null ? 2 : 3));

for (int i = 0; i < length; i++)
{
var val = buffer[i];
rv += hexmap[val >> 4];
rv += hexmap[val & 15];
builder.Append(hexmap[val >> 4]);
builder.Append(hexmap[val & 15]);

if (separator != null && i != length - 1)
{
rv += separator;
builder.Append(separator);
}
}

return rv.ToLower();
return builder.ToString().ToLower();
}
}
}
5 changes: 2 additions & 3 deletions src/SIPSorcery.VP8/VP8Codec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public byte[] EncodeVideo(int width, int height, byte[] sample, VideoPixelFormat
// The foundation encoder requires multiples of 16 — no
// padding/cropping support yet.
throw new NotSupportedException(
"Width and height must be positive multiples of 16. Got " + width + "x" + height + ".");
$"Width and height must be positive multiples of 16. Got {width}x{height}.");
}

// Convert the input sample into planar I420.
Expand All @@ -168,8 +168,7 @@ public byte[] EncodeVideo(int width, int height, byte[] sample, VideoPixelFormat
if (i420.Length != ySize + 2 * cSize)
{
throw new ArgumentException(
"I420 buffer length " + i420.Length + " does not match expected " +
(ySize + 2 * cSize) + " for " + width + "x" + height + ".");
$"I420 buffer length {i420.Length} does not match expected {ySize + 2 * cSize} for {width}x{height}.");
}

if (_srcY == null || _srcY.Length < ySize) { _srcY = new byte[ySize]; }
Expand Down
17 changes: 13 additions & 4 deletions src/SIPSorcery/SIPSorcery.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
<PackageReference Include="BouncyCastle.Cryptography" Version="2.6.2" />
<PackageReference Include="DnsClient" Version="1.8.0" />
<PackageReference Include="Makaretu.Dns.Multicast" Version="0.27.0" />
<PackageReference Include="Polyfill" Version="10.7.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="SIPSorcery.WebSocketSharp" Version="0.0.1" />
<PackageReference Include="System.Net.WebSockets.Client" Version="4.3.2" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="10.0.203" PrivateAssets="All" />
Expand All @@ -35,13 +39,17 @@
<PackageReference Include="Microsoft.Bcl.HashCode" Version="6.0.0" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net462'">
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\SIPSorceryMedia.Abstractions\SIPSorceryMedia.Abstractions.csproj" />
</ItemGroup>

<PropertyGroup>
<TargetFrameworks>netstandard2.0;netstandard2.1;netcoreapp3.1;net462;net5.0;net6.0;net8.0;net9.0;net10.0</TargetFrameworks>
<LangVersion>latest</LangVersion>
<LangVersion>14.0</LangVersion>
<SuppressTfmSupportBuildWarnings>true</SuppressTfmSupportBuildWarnings>
<NoWarn>$(NoWarn);SYSLIB0050</NoWarn>
<TreatWarningsAsErrors>True</TreatWarningsAsErrors>
Expand All @@ -66,11 +74,12 @@
<RepositoryUrl>https://github.com/sipsorcery-org/sipsorcery</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<RepositoryBranch>master</RepositoryBranch>
<PolyArgumentExceptions>true</PolyArgumentExceptions>
<PackageTags>SIP WebRTC VoIP RTP SDP STUN ICE SIPSorcery</PackageTags>
<PackageReleaseNotes>-v10.0.8: Bug fixes.
-v10.0.7: Network address change fix for Unity.
-v10.0.6: Bug fixes.
-v10.0.5: Stable release. Bug fixes.
-v10.0.6: Bug fixes.
-v10.0.5: Stable release. Bug fixes.
-v10.0.4-pre: New SRTP and DTLS implementation (huge thanks to @jimm98y).
-v10.0.3: Removed null SRTP ciphers.
-v10.0.2: Removed use of master key index for SRTP.
Expand All @@ -94,7 +103,7 @@
-v8.0.0: RTP header extension improvements (thanks to @ChristopheI). Major version to 8 to reflect highest .net runtime supported.</PackageReleaseNotes>
<NeutralLanguage>en</NeutralLanguage>
<Version>10.0.8</Version>
<AssemblyVersion>10.0.8</AssemblyVersion>
<AssemblyVersion>10.0.8</AssemblyVersion>
<FileVersion>10.0.8</FileVersion>
</PropertyGroup>

Expand Down
3 changes: 1 addition & 2 deletions src/SIPSorcery/app/Media/Sources/AudioExtrasSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,7 @@ public int AudioSamplePeriodMilliseconds
{
if (value < AUDIO_SAMPLE_PERIOD_MILLISECONDS_MIN || value > AUDIO_SAMPLE_PERIOD_MILLISECONDS_MAX)
{
throw new ApplicationException("Invalid value for the audio sample period. Must be between " +
$"{AUDIO_SAMPLE_PERIOD_MILLISECONDS_MIN} and {AUDIO_SAMPLE_PERIOD_MILLISECONDS_MAX}ms.");
throw new ApplicationException($"Invalid value for the audio sample period. Must be between {AUDIO_SAMPLE_PERIOD_MILLISECONDS_MIN} and {AUDIO_SAMPLE_PERIOD_MILLISECONDS_MAX}ms.");
}
else
{
Expand Down
4 changes: 2 additions & 2 deletions src/SIPSorcery/app/SIPPacketMangler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public static string MangleSDP(string sdpBody, string publicIPAddress, out bool
&& pubaddr.AddressFamily == AddressFamily.InterNetworkV6
&& addr.AddressFamily == AddressFamily.InterNetworkV6)
{
string mangledSDP = Regex.Replace(sdpBody, @"c=IN IP6 (?<ipaddress>([:a-fA-F0-9]+))", "c=IN IP6" + publicIPAddress, RegexOptions.Singleline);
string mangledSDP = Regex.Replace(sdpBody, @"c=IN IP6 (?<ipaddress>([:a-fA-F0-9]+))", $"c=IN IP6{publicIPAddress}", RegexOptions.Singleline);
wasMangled = true;

return mangledSDP;
Expand All @@ -65,7 +65,7 @@ public static string MangleSDP(string sdpBody, string publicIPAddress, out bool
&& addr.AddressFamily == AddressFamily.InterNetwork)
{
//logger.LogDebug("MangleSDP replacing private " + sdpAddress + " with " + publicIPAddress + ".");
string mangledSDP = Regex.Replace(sdpBody, @"c=IN IP4 (?<ipaddress>(\d+\.){3}\d+)", "c=IN IP4 " + publicIPAddress, RegexOptions.Singleline);
string mangledSDP = Regex.Replace(sdpBody, @"c=IN IP4 (?<ipaddress>(\d+\.){3}\d+)", $"c=IN IP4 {publicIPAddress}", RegexOptions.Singleline);
wasMangled = true;

return mangledSDP;
Expand Down
35 changes: 21 additions & 14 deletions src/SIPSorcery/app/SIPUserAgents/SIPCallDescriptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public class SIPCallDescriptor
public SIPCallDescriptor(ISIPAccount toSIPAccount, string uri, string fromHeader, string contentType, string content)
{
ToSIPAccount = toSIPAccount;
Uri = uri ?? toSIPAccount.SIPUsername + "@" + toSIPAccount.SIPDomain;
Uri = uri ?? $"{toSIPAccount.SIPUsername}@{toSIPAccount.SIPDomain}";
From = fromHeader;
ContentType = contentType;
Content = content;
Expand Down Expand Up @@ -291,14 +291,14 @@ public void ParseCallOptions(string options)
options = options.Trim('[', ']');

// Parse delay time option.
Match delayCallMatch = Regex.Match(options, DELAY_CALL_OPTION_KEY + @"=(?<delaytime>\d+)");
Match delayCallMatch = Regex.Match(options, $@"{DELAY_CALL_OPTION_KEY}=(?<delaytime>\d+)");
if (delayCallMatch.Success)
{
int.TryParse(delayCallMatch.Result("${delaytime}"), out DelaySeconds);
}

// Parse redirect mode option.
Match redirectModeMatch = Regex.Match(options, REDIRECT_MODE_OPTION_KEY + @"=(?<redirectmode>\w)");
Match redirectModeMatch = Regex.Match(options, $@"{REDIRECT_MODE_OPTION_KEY}=(?<redirectmode>\w)");
if (redirectModeMatch.Success)
{
string redirectMode = redirectModeMatch.Result("${redirectmode}");
Expand All @@ -321,42 +321,42 @@ public void ParseCallOptions(string options)
}

// Parse call duration limit option.
Match callDurationMatch = Regex.Match(options, CALL_DURATION_OPTION_KEY + @"=(?<callduration>\d+)");
Match callDurationMatch = Regex.Match(options, $@"{CALL_DURATION_OPTION_KEY}=(?<callduration>\d+)");
if (callDurationMatch.Success)
{
int.TryParse(callDurationMatch.Result("${callduration}"), out CallDurationLimit);
}

// Parse the mangle option.
Match mangleMatch = Regex.Match(options, MANGLE_MODE_OPTION_KEY + @"=(?<mangle>\w+)");
Match mangleMatch = Regex.Match(options, $@"{MANGLE_MODE_OPTION_KEY}=(?<mangle>\w+)");
if (mangleMatch.Success)
{
bool.TryParse(mangleMatch.Result("${mangle}"), out MangleResponseSDP);
}

// Parse the From header display name option.
Match fromDisplayNameMatch = Regex.Match(options, FROM_DISPLAY_NAME_KEY + @"=(?<displayname>.+?)(,|$)");
Match fromDisplayNameMatch = Regex.Match(options, $@"{FROM_DISPLAY_NAME_KEY}=(?<displayname>.+?)(,|$)");
if (fromDisplayNameMatch.Success)
{
FromDisplayName = fromDisplayNameMatch.Result("${displayname}").Trim();
}

// Parse the From header URI username option.
Match fromUsernameNameMatch = Regex.Match(options, FROM_USERNAME_KEY + @"=(?<username>.+?)(,|$)");
Match fromUsernameNameMatch = Regex.Match(options, $@"{FROM_USERNAME_KEY}=(?<username>.+?)(,|$)");
if (fromUsernameNameMatch.Success)
{
FromURIUsername = fromUsernameNameMatch.Result("${username}").Trim();
}

// Parse the From header URI host option.
Match fromURIHostMatch = Regex.Match(options, FROM_HOST_KEY + @"=(?<host>.+?)(,|$)");
Match fromURIHostMatch = Regex.Match(options, $@"{FROM_HOST_KEY}=(?<host>.+?)(,|$)");
if (fromURIHostMatch.Success)
{
FromURIHost = fromURIHostMatch.Result("${host}").Trim();
}

// Parse the Transfer behaviour option.
Match transferMatch = Regex.Match(options, TRANSFER_MODE_OPTION_KEY + @"=(?<transfermode>.+?)(,|$)");
Match transferMatch = Regex.Match(options, $@"{TRANSFER_MODE_OPTION_KEY}=(?<transfermode>.+?)(,|$)");
if (transferMatch.Success)
{
string transferMode = transferMatch.Result("${transfermode}");
Expand Down Expand Up @@ -387,28 +387,28 @@ public void ParseCallOptions(string options)
}

// Parse the request caller details option.
Match callerDetailsMatch = Regex.Match(options, REQUEST_CALLER_DETAILS + @"=(?<callerdetails>\w+)");
Match callerDetailsMatch = Regex.Match(options, $@"{REQUEST_CALLER_DETAILS}=(?<callerdetails>\w+)");
if (callerDetailsMatch.Success)
{
bool.TryParse(callerDetailsMatch.Result("${callerdetails}"), out RequestCallerDetails);
}

// Parse the accountcode.
Match accountCodeMatch = Regex.Match(options, ACCOUNT_CODE_KEY + @"=(?<accountCode>\w+)");
Match accountCodeMatch = Regex.Match(options, $@"{ACCOUNT_CODE_KEY}=(?<accountCode>\w+)");
if (accountCodeMatch.Success)
{
AccountCode = accountCodeMatch.Result("${accountCode}");
}

// Parse the rate code.
Match rateCodeMatch = Regex.Match(options, RATE_CODE_KEY + @"=(?<rateCode>\w+)");
Match rateCodeMatch = Regex.Match(options, $@"{RATE_CODE_KEY}=(?<rateCode>\w+)");
if (rateCodeMatch.Success)
{
RateCode = rateCodeMatch.Result("${rateCode}");
}

// Parse the delayed reinvite option.
Match delayedReinviteMatch = Regex.Match(options, DELAYED_REINVITE_KEY + @"=(?<delayedReinvite>\d+)");
Match delayedReinviteMatch = Regex.Match(options, $@"{DELAYED_REINVITE_KEY}=(?<delayedReinvite>\d+)");
if (delayedReinviteMatch.Success)
{
int.TryParse(delayedReinviteMatch.Result("${delayedReinvite}"), out ReinviteDelay);
Expand Down Expand Up @@ -457,7 +457,14 @@ public static List<string> ParseCustomHeaders(string customHeaders)
//string headerName = customHeader.Substring(0, colonIndex).Trim();
//string headerValue = (customHeader.Length > colonIndex) ? customHeader.Substring(colonIndex + 1).Trim() : String.Empty;

if (Regex.Match(customHeader.Trim(), "^(Via|From|Contact|CSeq|Call-ID|Max-Forwards|Content-Length)$", RegexOptions.IgnoreCase).Success)
var trimmedCustomHeader = customHeader.AsSpan().Trim();
if (trimmedCustomHeader.Equals(SIPHeaders.SIP_HEADER_VIA, StringComparison.OrdinalIgnoreCase) ||
trimmedCustomHeader.Equals(SIPHeaders.SIP_HEADER_FROM, StringComparison.OrdinalIgnoreCase) ||
trimmedCustomHeader.Equals(SIPHeaders.SIP_HEADER_CONTACT, StringComparison.OrdinalIgnoreCase) ||
trimmedCustomHeader.Equals(SIPHeaders.SIP_HEADER_CSEQ, StringComparison.OrdinalIgnoreCase) ||
trimmedCustomHeader.Equals(SIPHeaders.SIP_HEADER_CALLID, StringComparison.OrdinalIgnoreCase) ||
trimmedCustomHeader.Equals(SIPHeaders.SIP_HEADER_MAXFORWARDS, StringComparison.OrdinalIgnoreCase) ||
trimmedCustomHeader.Equals(SIPHeaders.SIP_HEADER_CONTENTLENGTH, StringComparison.OrdinalIgnoreCase))
{
logger.LogWarning("ParseCustomHeaders skipping custom header due to an non-permitted string in header name, {CustomHeader}.", customHeader);
continue;
Expand Down
Loading
Loading