diff --git a/Common/Classes/SegmentStream.cs b/Common/Classes/SegmentStream.cs index 43eb54a9..95f54198 100644 --- a/Common/Classes/SegmentStream.cs +++ b/Common/Classes/SegmentStream.cs @@ -293,7 +293,7 @@ public int CopyTo(byte[] destination, int offset, int count) foreach (Common.MemorySegment ms in Segments) { - if (ms.Count.Equals(Common.Binary.Zero)) continue; + if (ms.Count is Common.Binary.Zero) continue; min = Binary.Min(count, ms.Count); diff --git a/Common/Extensions/EncodingExtensions.cs b/Common/Extensions/EncodingExtensions.cs index 7da9d9bf..2a8ee07f 100644 --- a/Common/Extensions/EncodingExtensions.cs +++ b/Common/Extensions/EncodingExtensions.cs @@ -110,7 +110,7 @@ public static bool ReadDelimitedDataFrom(this System.Text.Encoding encoding, byt int max; - if (count.Equals(Common.Binary.Zero) || Common.Extensions.Array.ArrayExtensions.IsNullOrEmpty(buffer, out max)) + if (count is Common.Binary.Zero || Common.Extensions.Array.ArrayExtensions.IsNullOrEmpty(buffer, out max)) { result = null; @@ -121,7 +121,7 @@ public static bool ReadDelimitedDataFrom(this System.Text.Encoding encoding, byt max -= offset; //The smaller of the two, max and count - if ((count = Common.Binary.Min(ref max, ref count)).Equals(0)) return false; + if ((count = Common.Binary.Min(ref max, ref count)) is 0) return false; bool sawDelimit = false; @@ -160,7 +160,7 @@ public static bool ReadDelimitedDataFrom(this System.Text.Encoding encoding, byt #endif //If there are not enough bytes to decode the char - if (justRead.Equals(Common.Binary.Zero)) + if (justRead is Common.Binary.Zero) { break; } @@ -199,7 +199,7 @@ public static bool ReadDelimitedDataFrom(this System.Text.Encoding encoding, byt return sawDelimit; } - result = builder.Length.Equals(Common.Binary.Zero) ? string.Empty : builder.ToString(); + result = builder.Length is Common.Binary.Zero ? string.Empty : builder.ToString(); //Take the amount of bytes in the string as what was read. read = encoding.GetByteCount(result); @@ -235,7 +235,7 @@ public static bool ReadDelimitedDataFrom(this System.Text.Encoding encoding, Sys if (delimits == null) delimits = EmptyChar; - if (stream == null || false.Equals(stream.CanRead) || count.Equals(Common.Binary.Zero)) + if (stream == null || false.Equals(stream.CanRead) || count is Common.Binary.Zero) { result = null; diff --git a/Common/Extensions/ExceptionExtensions.cs b/Common/Extensions/ExceptionExtensions.cs index 32666b92..7acbcb09 100644 --- a/Common/Extensions/ExceptionExtensions.cs +++ b/Common/Extensions/ExceptionExtensions.cs @@ -59,7 +59,7 @@ public static bool InException { //See http://geekswithblogs.net/akraus1/archive/2008/04/08/121121.aspx return System.Runtime.InteropServices.Marshal.GetExceptionPointers() == System.IntPtr.Zero && - System.Runtime.InteropServices.Marshal.GetExceptionCode().Equals(Common.Binary.Zero) ? false : true; + System.Runtime.InteropServices.Marshal.GetExceptionCode() is Common.Binary.Zero ? false : true; } } diff --git a/Common/Extensions/SocketExtensions.cs b/Common/Extensions/SocketExtensions.cs index 811bb1cf..a5ea93c0 100644 --- a/Common/Extensions/SocketExtensions.cs +++ b/Common/Extensions/SocketExtensions.cs @@ -793,7 +793,7 @@ public static bool IsTcpNotUrgent(System.Net.Sockets.Socket socket) if (Common.Extensions.Array.ArrayExtensions.IsNullOrEmpty(value, out len) || len < Common.Binary.BytesPerInteger) return false; //Read the 32 bits of the buffer in network byte order, return true if the value != 0 - return false.Equals(Common.Binary.Read32(value, Common.Binary.BytesPerInteger, Media.Common.Binary.IsLittleEndian).Equals(0)); + return false.Equals(Common.Binary.Read32(value, Common.Binary.BytesPerInteger, Media.Common.Binary.IsLittleEndian) is 0); } /// @@ -816,7 +816,7 @@ public static bool IsTcpStandardUrgency(System.Net.Sockets.Socket socket, bool c if (Common.Extensions.Array.ArrayExtensions.IsNullOrEmpty(value, out len) || len < Common.Binary.BytesPerInteger) return false; //Read the 32 bits of the buffer in network byte order, return true if the value != 0 - return false.Equals(Common.Binary.Read32(value, Common.Binary.BytesPerInteger, Media.Common.Binary.IsLittleEndian).Equals(0)); + return false.Equals(Common.Binary.Read32(value, Common.Binary.BytesPerInteger, Media.Common.Binary.IsLittleEndian) is 0); } public static int GetTcpExpedited(System.Net.Sockets.Socket socket) @@ -901,7 +901,7 @@ public static bool GetIsTcpOutOfBandInLine(System.Net.Sockets.Socket socket) if (Common.Extensions.Array.ArrayExtensions.IsNullOrEmpty(value, out len) || len < Common.Binary.BytesPerInteger) return false; //Read the 32 bits of the buffer in network byte order, return true if the value != 0 - return false.Equals(Common.Binary.Read32(value, Common.Binary.BytesPerInteger, Media.Common.Binary.IsLittleEndian).Equals(0)); + return false.Equals(Common.Binary.Read32(value, Common.Binary.BytesPerInteger, Media.Common.Binary.IsLittleEndian) is 0); } #endregion diff --git a/Common/Extensions/StringExtensions.cs b/Common/Extensions/StringExtensions.cs index 11d3889a..243afd54 100644 --- a/Common/Extensions/StringExtensions.cs +++ b/Common/Extensions/StringExtensions.cs @@ -74,7 +74,7 @@ public static byte[] HexStringToBytes(string str, int start = 0, int length = -1 //Dont check the results for overflow unchecked { - if (length.Equals(Common.Binary.Zero)) return null; + if (length is Common.Binary.Zero) return null; if (length <= -1) length = str.Length; @@ -230,7 +230,7 @@ public static string Substring(this string source, int startIndex, int count, st [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] public static string[] SplitTrim(this string ex, string[] seperator, int count, System.StringSplitOptions options) { - if (count.Equals(Common.Binary.Zero) || Common.Extensions.Array.ArrayExtensions.IsNullOrEmpty(seperator)) return new string[Common.Binary.Zero]; + if (count is Common.Binary.Zero || Common.Extensions.Array.ArrayExtensions.IsNullOrEmpty(seperator)) return new string[Common.Binary.Zero]; string[] results = ex.Split(seperator, count, options); @@ -242,7 +242,7 @@ public static string[] SplitTrim(this string ex, string[] seperator, int count, [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] public static string[] SplitTrim(this string ex, char[] seperator, int count, System.StringSplitOptions options) { - if (count.Equals(Common.Binary.Zero) || Common.Extensions.Array.ArrayExtensions.IsNullOrEmpty(seperator)) return new string[0]; + if (count is Common.Binary.Zero || Common.Extensions.Array.ArrayExtensions.IsNullOrEmpty(seperator)) return new string[0]; string[] results = ex.Split(seperator, count, options); @@ -254,7 +254,7 @@ public static string[] SplitTrim(this string ex, char[] seperator, int count, Sy [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] public static string[] SplitTrimEnd(this string ex, string[] seperator, int count, System.StringSplitOptions options) { - if (count.Equals(Common.Binary.Zero) || Common.Extensions.Array.ArrayExtensions.IsNullOrEmpty(seperator)) return new string[Common.Binary.Zero]; + if (count is Common.Binary.Zero || Common.Extensions.Array.ArrayExtensions.IsNullOrEmpty(seperator)) return new string[Common.Binary.Zero]; string[] results = ex.Split(seperator, count, options); @@ -266,7 +266,7 @@ public static string[] SplitTrimEnd(this string ex, string[] seperator, int coun [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] public static string[] SplitTrimEnd(this string ex, char[] seperator, int count, System.StringSplitOptions options) { - if (count.Equals(Common.Binary.Zero) || Common.Extensions.Array.ArrayExtensions.IsNullOrEmpty(seperator)) return new string[Common.Binary.Zero]; + if (count is Common.Binary.Zero || Common.Extensions.Array.ArrayExtensions.IsNullOrEmpty(seperator)) return new string[Common.Binary.Zero]; string[] results = ex.Split(seperator, count, options); @@ -278,7 +278,7 @@ public static string[] SplitTrimEnd(this string ex, char[] seperator, int count, [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] public static string[] SplitTrimStart(this string ex, string[] seperator, int count, System.StringSplitOptions options) { - if (count.Equals(Common.Binary.Zero) || Common.Extensions.Array.ArrayExtensions.IsNullOrEmpty(seperator)) return new string[Common.Binary.Zero]; + if (count is Common.Binary.Zero || Common.Extensions.Array.ArrayExtensions.IsNullOrEmpty(seperator)) return new string[Common.Binary.Zero]; string[] results = ex.Split(seperator, count, options); @@ -290,7 +290,7 @@ public static string[] SplitTrimStart(this string ex, string[] seperator, int co [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] public static string[] SplitTrimStart(this string ex, char[] seperator, int count, System.StringSplitOptions options) { - if (count.Equals(Common.Binary.Zero) || Common.Extensions.Array.ArrayExtensions.IsNullOrEmpty(seperator)) return new string[Common.Binary.Zero]; + if (count is Common.Binary.Zero || Common.Extensions.Array.ArrayExtensions.IsNullOrEmpty(seperator)) return new string[Common.Binary.Zero]; string[] results = ex.Split(seperator, count, options); diff --git a/Concepts/Classes/Arrays.cs b/Concepts/Classes/Arrays.cs index 5ea18a37..58f89547 100644 --- a/Concepts/Classes/Arrays.cs +++ b/Concepts/Classes/Arrays.cs @@ -759,7 +759,7 @@ public bool IsEmpty [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] get { - return m_Header.m_Length.Equals(Common.Binary.Zero); + return m_Header.m_Length is Common.Binary.Zero; } } diff --git a/Concepts/Classes/Threading/Pool.cs b/Concepts/Classes/Threading/Pool.cs index 175aa504..6f43c442 100644 --- a/Concepts/Classes/Threading/Pool.cs +++ b/Concepts/Classes/Threading/Pool.cs @@ -247,8 +247,8 @@ public double Occupancy { get { - if(Slots.Equals(0)) return -(Whole * m_Leases.Count); - else if (m_Leases.Count.Equals(0)) return -(Whole * Slots); + if(Slots is 0) return -(Whole * m_Leases.Count); + else if (m_Leases.Count is 0) return -(Whole * Slots); return (m_Leases.Count / Slots) / Whole; } } diff --git a/Http/HttpMessage.cs b/Http/HttpMessage.cs index 5e82f2af..aa22e33d 100644 --- a/Http/HttpMessage.cs +++ b/Http/HttpMessage.cs @@ -1300,7 +1300,7 @@ virtual protected bool ParseHeaders(bool force = false) sawDelemit = Media.Common.Extensions.Encoding.EncodingExtensions.ReadDelimitedDataFrom(HeaderEncoding, buffer, m_EncodedLineEnds, position, remains, out rawLine, out justRead, true); //There is not enough data in the buffer - if(justRead.Equals(0)) break; + if(justRead is 0) break; //Check for the empty line if (string.IsNullOrWhiteSpace(rawLine)) @@ -1629,7 +1629,7 @@ internal protected virtual bool ParseBody(out int remaining, bool force = false) //Todo, should only check this after determining whats available... //Empty body or no ContentLength - if (m_ContentLength.Equals(0)) + if (m_ContentLength is 0) { //m_Body = string.Empty; @@ -1642,7 +1642,7 @@ internal protected virtual bool ParseBody(out int remaining, bool force = false) //Calculate how much data remains based on the ContentLength //remaining = m_ContentLength - m_Body.Length; - if (available.Equals(0)) return false; + if (available is 0) return false; //Get the decoder to use for the body Encoding decoder = ParseContentEncoding(false, FallbackToDefaultEncoding); @@ -1655,7 +1655,7 @@ internal protected virtual bool ParseBody(out int remaining, bool force = false) remaining = ParseContentLength() ? m_ContentLength - existingBodySize : available; - if (remaining.Equals(0)) return true; + if (remaining is 0) return true; //Get the array of the memory stream byte[] buffer = m_Buffer.GetBuffer(); @@ -1735,7 +1735,7 @@ internal protected virtual bool ParseBody(out int remaining, bool force = false) m_Buffer.Seek(m_HeaderOffset = (int)lastPos, System.IO.SeekOrigin.Begin); return true; } - else if (chunkSize.Equals(0)) + else if (chunkSize is 0) { //Trailer @@ -1855,7 +1855,7 @@ internal string GetHeaderValue(string name, out string actualName) actualName = null; if (IsDisposed && false == IsPersistent || string.IsNullOrWhiteSpace(name)) return null; foreach (string headerName in GetHeaders()) - if (string.Compare(name, headerName, true).Equals(0)) //headerName.Equals(name, StringComparison.OrdinalIgnoreCase); + if (string.Compare(name, headerName, true) is 0) //headerName.Equals(name, StringComparison.OrdinalIgnoreCase); { actualName = headerName; @@ -1871,7 +1871,7 @@ internal string GetEntityHeaderValue(string name, out string actualName) actualName = null; if (IsDisposed && false == IsPersistent || string.IsNullOrWhiteSpace(name)) return null; foreach (string headerName in GetEntityHeaders()) - if (string.Compare(name, headerName, true).Equals(0)) //headerName.Equals(name, StringComparison.OrdinalIgnoreCase); + if (string.Compare(name, headerName, true) is 0) //headerName.Equals(name, StringComparison.OrdinalIgnoreCase); { actualName = headerName; @@ -2589,7 +2589,7 @@ public bool Equals(HttpMessage other) && other.GetHeaders().All(ContainsHeader) && - string.Compare(other.m_Body, m_Body, false).Equals(0); + string.Compare(other.m_Body, m_Body, false) is 0; //&& //other.Length == Length; } @@ -2796,7 +2796,7 @@ int ParseChunk(ref int offset, int length) //out string extensions } // /r or /n by itself, if there is another byte consume it. - if (read.Equals(1) && sawDelemit && length > 1) + if (read is 1 && sawDelemit && length > 1) { ++offset; diff --git a/Rtp/Rtcp/RtcpPacket.cs b/Rtp/Rtcp/RtcpPacket.cs index 1303bff9..4c2bb6ef 100644 --- a/Rtp/Rtcp/RtcpPacket.cs +++ b/Rtp/Rtcp/RtcpPacket.cs @@ -686,7 +686,7 @@ public IEnumerable RtcpData { get { - if (IsDisposed || Payload.Count.Equals(0)) return Media.Common.MemorySegment.Empty; + if (IsDisposed || Payload.Count is 0) return Media.Common.MemorySegment.Empty; //return Payload.Take(Payload.Count - PaddingOctets); @@ -701,7 +701,7 @@ public IEnumerable PaddingData { get { - if (IsDisposed || Padding is false || IsComplete is false || Payload.Count.Equals(0)) return Media.Common.MemorySegment.Empty; + if (IsDisposed || Padding is false || IsComplete is false || Payload.Count is 0) return Media.Common.MemorySegment.Empty; //return Payload.Skip(Payload.Count - PaddingOctets); diff --git a/Rtp/RtpClient.Constants.cs b/Rtp/RtpClient.Constants.cs index 411ffaee..84a35bda 100644 --- a/Rtp/RtpClient.Constants.cs +++ b/Rtp/RtpClient.Constants.cs @@ -248,7 +248,7 @@ public static RtpClient FromSessionDescription(Sdp.SessionDescription sessionDes byte lastChannel = 0; //Todo, check for session level ssrc - //if (remoteSsrc.Equals(0)) + //if (remoteSsrc is 0) //{ // //Sdp.SessionDescriptionLine ssrcLine = sessionDescription.SsrcGroupLine; // SsrcLine @ the session level could imply Group //} diff --git a/Rtp/RtpClient.Methods.cs b/Rtp/RtpClient.Methods.cs index 0eb9f922..187f803e 100644 --- a/Rtp/RtpClient.Methods.cs +++ b/Rtp/RtpClient.Methods.cs @@ -492,7 +492,7 @@ public partial class RtpClient : Media.Common.ILoggingReference if (Common.IDisposedExtensions.IsNullOrDisposed(this) || packets == null) return 0; //If we don't have an transportContext to send on or the transportContext has not been identified or Rtcp is Disabled or there is no remote rtcp end point - if (Common.IDisposedExtensions.IsNullOrDisposed(context) || context.SynchronizationSourceIdentifier.Equals(Common.Binary.Zero) | false.Equals(context.IsRtcpEnabled) | context.RemoteRtcp == null) + if (Common.IDisposedExtensions.IsNullOrDisposed(context) || context.SynchronizationSourceIdentifier is Common.Binary.Zero | false.Equals(context.IsRtcpEnabled) | context.RemoteRtcp == null) { //Return return 0; @@ -1468,7 +1468,7 @@ int ReadApplicationLayerFraming(ref int received, ref int sessionRequired, ref i //{ do received += justRecieved = socket.ReceiveFrom(buffer.Array, buffer.Offset + received, buffer.Count - received, System.Net.Sockets.SocketFlags.None, ref remote); - while (received.Equals(0) /*|| justRecieved > 0 && received + justRecieved < pmax*/ && socket.Connected); + while (received is 0 /*|| justRecieved > 0 && received + justRecieved < pmax*/ && socket.Connected); ////Lookup the context to determine if the packet will fit //var context = GetContextBySocket(socket); @@ -1920,7 +1920,7 @@ int ReadApplicationLayerFraming(ref int received, ref int sessionRequired, ref i registerX = memory.Count; //Don't use 0 as flow control here. Raising what potentially be multiple events would be dumb. - if (registerX.Equals(0)) + if (registerX is 0) { offset += sessionRequired; @@ -2006,7 +2006,7 @@ int ReadApplicationLayerFraming(ref int received, ref int sessionRequired, ref i internal protected /*virtual*/ void ParseAndHandleData(Common.MemorySegment memory, ref bool parseRtcp, ref bool parseRtp, ref int remaining, ref int expected) { - if (Common.IDisposedExtensions.IsNullOrDisposed(memory) || memory.Count.Equals(0) || remaining <= 0) return; + if (Common.IDisposedExtensions.IsNullOrDisposed(memory) || memory.Count is 0 || remaining <= 0) return; //handle demultiplex scenarios e.g. RFC5761 if (parseRtcp.Equals(parseRtp) && memory.Count > RFC3550.CommonHeaderBits.Size) @@ -2385,7 +2385,7 @@ void SendReceieve() receivedRtp += ReceiveData(tc.RtpSocket, ref tc.RemoteRtp, out lastError, rtpEnabled, duplexing, tc.ContextMemory); //Check if an error occured - if (receivedRtp.Equals(0) || false.Equals(lastError == System.Net.Sockets.SocketError.Success)) + if (receivedRtp is 0 || false.Equals(lastError == System.Net.Sockets.SocketError.Success)) { //Increment for failed receptions ++tc.m_FailedRtpReceptions; @@ -2441,7 +2441,7 @@ void SendReceieve() receivedRtcp += ReceiveData(tc.RtcpSocket, ref tc.RemoteRtcp, out lastError, duplexing, rtcpEnabled, tc.ContextMemory); //Check if an error occured - if (receivedRtcp.Equals(0) || false.Equals(lastError == System.Net.Sockets.SocketError.Success)) + if (receivedRtcp is 0 || false.Equals(lastError == System.Net.Sockets.SocketError.Success)) { //Increment for failed receptions ++tc.m_FailedRtcpReceptions; @@ -2492,7 +2492,7 @@ void SendReceieve() default: { //If there are no packets outgoing - if ((m_OutgoingRtcpPackets.Count + m_OutgoingRtpPackets.Count).Equals(0)) + if ((m_OutgoingRtcpPackets.Count + m_OutgoingRtpPackets.Count) is 0) { //Just Take no action (leave Priority Normal) diff --git a/Rtp/RtpClient.cs b/Rtp/RtpClient.cs index 98aa6358..9a7d5c6d 100644 --- a/Rtp/RtpClient.cs +++ b/Rtp/RtpClient.cs @@ -244,7 +244,7 @@ public static TransportContext FromMediaDescription(Sdp.SessionDescription sessi int ttl = 255; //If no remoteSsrc was given then check for one - if (remoteSsrc.Equals(0)) + if (remoteSsrc is 0) { //Check for SSRC Attribute Line on the Media Description //a=ssrc: @@ -286,7 +286,7 @@ public static TransportContext FromMediaDescription(Sdp.SessionDescription sessi if (Media.Sdp.Lines.SessionBandwidthLine.TryParseBandwidthDirectives(mediaDescription, out reportReceivingEvery, out reportSendingEvery, out asData)) { //Determine if rtcp is disabled in the media description - bool rtcpDisabled = reportReceivingEvery.Equals(0) && reportSendingEvery.Equals(0); + bool rtcpDisabled = reportReceivingEvery is 0 && reportSendingEvery is 0; //If Rtcp is not disabled then this will set the read and write timeouts. if (rtcpDisabled is false) @@ -398,7 +398,7 @@ number of senders. When the proportion of senders is greater than if (configure is not null) tc.ConfigureSocket = configure; //Check for udp if no existing socket was given - if (hasSocket is false && string.Compare(mediaDescription.MediaProtocol, Media.Rtp.RtpClient.RtpAvpProfileIdentifier, true).Equals(0)) + if (hasSocket is false && string.Compare(mediaDescription.MediaProtocol, Media.Rtp.RtpClient.RtpAvpProfileIdentifier, true) is 0) { //Registers must be stored, it might make more sense to leave the defaults as is and change the parameters of this function to then //- allow for sockets to be given to the Initialize e.g. a Initializer delegate. @@ -413,10 +413,10 @@ number of senders. When the proportion of senders is greater than //Create the sockets and connect tc.Initialize(localIp, remoteIp, //LocalIP, RemoteIP - localPort.Equals(0) ? localPort : localPort++, //LocalRtp - localPort.Equals(0) ? localPort : localPort++, //LocalRtcp + localPort is 0 ? localPort : localPort++, //LocalRtp + localPort is 0 ? localPort : localPort++, //LocalRtcp rtpPort ?? mediaDescription.MediaPort, //RemoteRtp - rtcpPort ?? (false.Equals(mediaDescription.MediaPort.Equals(0)) ? mediaDescription.MediaPort + 1 : mediaDescription.MediaPort)); //RemoteRtcp + rtcpPort ?? (false.Equals(mediaDescription.MediaPort is 0) ? mediaDescription.MediaPort + 1 : mediaDescription.MediaPort)); //RemoteRtcp } else if (hasSocket)//If had a socket use it { @@ -941,7 +941,7 @@ public bool HasSentRtcpWithinSendInterval internal bool InDiscovery { [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - get { return ValidRtpPacketsReceived < MinimumSequentialValidRtpPackets && RemoteSynchronizationSourceIdentifier.Equals(Common.Binary.Zero); } + get { return ValidRtpPacketsReceived < MinimumSequentialValidRtpPackets && RemoteSynchronizationSourceIdentifier is Common.Binary.Zero; } } /// @@ -1622,7 +1622,7 @@ public TransportContext(byte dataChannel, byte controlChannel, int ssrc, bool rt if (dataChannel.Equals(controlChannel)) throw new InvalidOperationException("dataChannel and controlChannel must be unique."); - if (ssrc.Equals(senderSsrc) && false.Equals(ssrc.Equals(0))) throw new InvalidOperationException("ssrc and senderSsrc must be unique."); + if (ssrc.Equals(senderSsrc) && false.Equals(ssrc is 0)) throw new InvalidOperationException("ssrc and senderSsrc must be unique."); if (minimumSequentialRtpPackets < 0) throw new InvalidOperationException("minimumSequentialRtpPackets must be >= 0"); @@ -1678,11 +1678,11 @@ public TransportContext(byte dataChannel, byte controlChannel, int ssrc, Sdp.Med [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] internal protected void AssignIdentity(int seed = SendersReport.PayloadType) { - if (SynchronizationSourceIdentifier.Equals(Common.Binary.Zero)) + if (SynchronizationSourceIdentifier is Common.Binary.Zero) { //Generate the id per RFC3550 do SynchronizationSourceIdentifier = RFC3550.Random32(seed); - while (SynchronizationSourceIdentifier.Equals(Common.Binary.Zero) || SynchronizationSourceIdentifier.Equals(RemoteSynchronizationSourceIdentifier)); + while (SynchronizationSourceIdentifier is Common.Binary.Zero || SynchronizationSourceIdentifier.Equals(RemoteSynchronizationSourceIdentifier)); } } @@ -2523,13 +2523,13 @@ protected internal virtual void HandleIncomingRtcpPacket(object rtpClient, RtcpP } //Only if the packet was not addressed to a unique party with the id of 0 and there is a null context or the context is in discovery. - if (false.Equals(partyId.Equals(0)) && false.Equals(Common.IDisposedExtensions.IsNullOrDisposed(transportContext)))// && transportContext.InDiscovery) + if (false.Equals(partyId is 0) && false.Equals(Common.IDisposedExtensions.IsNullOrDisposed(transportContext)))// && transportContext.InDiscovery) { //Cache the payloadType and blockCount int blockCount = packet.BlockCount; //Before checking the type ensure there is a party id and block count - ////if (blockCount.Equals(0)) + ////if (blockCount is 0) ////{ //// //If there was a context and the remote party has not yet been identified. //// if (false.Equals(Common.IDisposedExtensions.IsNullOrDisposed(transportContext)) && @@ -2560,7 +2560,7 @@ protected internal virtual void HandleIncomingRtcpPacket(object rtpClient, RtcpP { int blockId = reportBlock.BlockIdentifier; - if (blockCount.Equals(0)) continue; + if (blockCount is 0) continue; //Attempt to obtain a context by the identifier in the report block transportContext = GetContextBySourceId(blockId); @@ -2608,7 +2608,7 @@ protected internal virtual void HandleIncomingRtcpPacket(object rtpClient, RtcpP //Iterate each party leaving foreach (int party in sourceList) { - if (party.Equals(0)) continue; + if (party is 0) continue; //Attempt to obtain a context by the identifier in the report block transportContext = GetContextBySourceId(party); @@ -2646,7 +2646,7 @@ protected internal virtual void HandleIncomingRtcpPacket(object rtpClient, RtcpP { int blockId = reportBlock.BlockIdentifier; - if (blockCount.Equals(0)) continue; + if (blockCount is 0) continue; //Attempt to obtain a context by the identifier in the report block transportContext = GetContextBySourceId(blockId); @@ -2654,11 +2654,11 @@ protected internal virtual void HandleIncomingRtcpPacket(object rtpClient, RtcpP //If there was a context and the remote party has not yet been identified. if (false.Equals(Common.IDisposedExtensions.IsNullOrDisposed(transportContext)) && transportContext.Version == packetVersion) //&& - //transportContext.RemoteSynchronizationSourceIdentifier.Equals(0)) + //transportContext.RemoteSynchronizationSourceIdentifier is 0) { //Identify the remote party by this id. (This would be the id they think we have?) - if (transportContext.RemoteSynchronizationSourceIdentifier.Equals(0)) + if (transportContext.RemoteSynchronizationSourceIdentifier is 0) { Media.Common.ILoggingExtensions.Log(Logger, ToString() + "@HandleIncomingRtcpPacket Set RemoteSynchronizationSourceIdentifier @ SR " + transportContext.SynchronizationSourceIdentifier + " to=" + transportContext.RemoteSynchronizationSourceIdentifier + "RR blockId=" + blockId + " NtpTimestamp=" + transportContext.NtpTimestamp + " RtpTimestamp=" + transportContext.RtpTimestamp + " RtpJitter=" + transportContext.RtpJitter + " NtpOffset=" + transportContext.NtpOffset); @@ -3014,7 +3014,7 @@ protected internal virtual void HandleIncomingRtpPacket(object/*RtpClient*/ send //if (transportContext.InDiscovery || transportContext.IsValid && false.Equals(partyId.Equals(transportContext.RemoteSynchronizationSourceIdentifier))) //{ // //If not yet set, set the remote id - // if (transportContext.RemoteSynchronizationSourceIdentifier.Equals(0)) + // if (transportContext.RemoteSynchronizationSourceIdentifier is 0) // { // transportContext.RemoteSynchronizationSourceIdentifier = partyId; @@ -3067,7 +3067,7 @@ protected internal virtual void HandleIncomingRtpPacket(object/*RtpClient*/ send // //SendGoodbye(transportContext, System.Text.Encoding.UTF8.GetBytes("ssrc"), transportContext.SynchronizationSourceIdentifier, true, null, false); // //Option AssumeIdentity / CoalesceIdentities - // if(partyId.Equals(0)) packet.SynchronizationSourceIdentifier = transportContext.RemoteSynchronizationSourceIdentifier; + // if(partyId is 0) packet.SynchronizationSourceIdentifier = transportContext.RemoteSynchronizationSourceIdentifier; // } //} @@ -3381,7 +3381,7 @@ protected internal void OnOutOfBandData(byte[] data, int offset, int length) InterleavedDataHandler action = OutOfBandData; - if (action is null || data == null || length.Equals(Common.Binary.Zero)) return; + if (action is null || data == null || length is Common.Binary.Zero) return; if (m_ThreadEvents) { @@ -4054,7 +4054,7 @@ public bool AverageRtcpBandwidthExceeded int amountOfContexts = TransportContexts.Count; - if (amountOfContexts.Equals(Common.Binary.Zero)) return true; + if (amountOfContexts is Common.Binary.Zero) return true; //Obtain the summation of the total bytes sent over the amount of context's long totalReceived = TotalBytesReceieved; diff --git a/Rtp/RtpFrame.cs b/Rtp/RtpFrame.cs index 0b6b4e51..00dccf80 100644 --- a/Rtp/RtpFrame.cs +++ b/Rtp/RtpFrame.cs @@ -514,7 +514,7 @@ public int Count public bool IsEmpty { [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - get { return Count.Equals(0); } + get { return Count is 0; } } /// @@ -753,7 +753,7 @@ public void Add(RtpPacket packet, int count = Count, ssrc = packet.SynchronizationSourceIdentifier, seq = packet.SequenceNumber, ts = packet.Timestamp, pt = packet.PayloadType; //No packets contained yet - if (count.Equals(0)) + if (count is 0) { if (m_Ssrc.Equals(-1)) m_Ssrc = ssrc; else if (false.Equals(ssrc.Equals(m_Ssrc))) throw new ArgumentException("packet.SynchronizationSourceIdentifier must match frame SynchronizationSourceIdentifier", "packet"); @@ -796,7 +796,7 @@ public void Add(RtpPacket packet, goto Timestamp; } //If the packet has a source list - else if (false.Equals(packet.ContributingSourceCount.Equals(0))) + else if (false.Equals(packet.ContributingSourceCount is 0)) { using (RFC3550.SourceList sl = packet.GetSourceList()) { @@ -873,7 +873,7 @@ public void Add(RtpPacket packet, } //Handle prepend - if (insert.Equals(0)) + if (insert is 0) { Packets.Insert(0, packet); @@ -1092,7 +1092,7 @@ public RtpPacket Remove(ref int sequenceNumber) default: { //Skip the access of the array for all cases but when the sequence was == to the m_LowestSequenceNumber (i == 0) - if(i.Equals(0)) //(sequenceNumber == m_LowestSequenceNumber) + if(i is 0) //(sequenceNumber == m_LowestSequenceNumber) { m_LowestSequenceNumber = Packets[0].SequenceNumber; //First } diff --git a/Rtp/RtpPacket.cs b/Rtp/RtpPacket.cs index a036edfd..3240b559 100644 --- a/Rtp/RtpPacket.cs +++ b/Rtp/RtpPacket.cs @@ -96,7 +96,7 @@ public int ContributingSourceListOctets { [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - get { if (IsDisposed || Payload.Count.Equals(0)) return 0; return Binary.Clamp(Header.ContributingSourceCount * 4, 0, 60)/* Math.Min(60, Math.Max(0, Header.ContributingSourceCount * 4))*/; } + get { if (IsDisposed || Payload.Count is 0) return 0; return Binary.Clamp(Header.ContributingSourceCount * 4, 0, 60)/* Math.Min(60, Math.Max(0, Header.ContributingSourceCount * 4))*/; } } /// @@ -110,7 +110,7 @@ public int ExtensionOctets get { - if (IsDisposed || Payload.Count.Equals(0) || false.Equals(Header.Extension)) return 0; + if (IsDisposed || Payload.Count is 0 || false.Equals(Header.Extension)) return 0; using (RtpExtension extension = GetExtension()) return false.Equals(Common.IDisposedExtensions.IsNullOrDisposed(extension)) ? extension.Size : 0; } @@ -124,7 +124,7 @@ public int HeaderOctets { [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - get { if (IsDisposed || Payload.Count.Equals(0)) return 0; return ContributingSourceListOctets + ExtensionOctets; } + get { if (IsDisposed || Payload.Count is 0) return 0; return ContributingSourceListOctets + ExtensionOctets; } } /// @@ -202,7 +202,7 @@ internal protected Common.MemorySegment PayloadDataSegment get { //Proably don't have to check... - if (IsDisposed || Payload.Count.Equals(0)) return Media.Common.MemorySegment.Empty; + if (IsDisposed || Payload.Count is 0) return Media.Common.MemorySegment.Empty; int nonPayloadOctets = HeaderOctets, padding = PaddingOctets; @@ -236,7 +236,7 @@ internal protected Common.MemorySegment PaddingDataSegment int padding = PaddingOctets; - if (padding.Equals(0)) return Common.MemorySegment.Empty; + if (padding is 0) return Common.MemorySegment.Empty; return new Common.MemorySegment(Payload.Array, (Payload.Offset + Payload.Count) - padding, padding); diff --git a/Rtsp/RtspClient.cs b/Rtsp/RtspClient.cs index 0901c616..7a678f0d 100644 --- a/Rtsp/RtspClient.cs +++ b/Rtsp/RtspClient.cs @@ -1939,7 +1939,7 @@ SET_PARAMETER Location RTSP/1.0 //Check that only the rtx media is playing and then remove session if so - if (effectedMedia && m_Playing.Count.Equals(1) && m_Playing.Keys.First().GetAbsoluteControlUri(CurrentLocation, SessionDescription).AbsoluteUri.EndsWith("rtx", StringComparison.OrdinalIgnoreCase)) + if (effectedMedia && m_Playing.Count is 1 && m_Playing.Keys.First().GetAbsoluteControlUri(CurrentLocation, SessionDescription).AbsoluteUri.EndsWith("rtx", StringComparison.OrdinalIgnoreCase)) { //RemoveSession(m_SessionId); @@ -2453,7 +2453,7 @@ SharesSocket is false && //Take in some bytes from the socket int justReceived = interleaved.CompleteFrom(m_RtspSocket, m_Buffer); - if (justReceived.Equals(0)) break; + if (justReceived is 0) break; //Incrment for justReceived received += justReceived; @@ -2615,7 +2615,7 @@ public void StartPlaying(TimeSpan? start = null, TimeSpan? end = null, IEnumerab if (IsConnected is false) Connect(); //Send the options if nothing was received before - if (m_ReceivedMessages.Equals(0)) using (RtspMessage optionsResponse = SendOptions()) + if (m_ReceivedMessages is 0) using (RtspMessage optionsResponse = SendOptions()) { if (Common.IDisposedExtensions.IsNullOrDisposed(optionsResponse) || optionsResponse.ParsedProtocol.Equals(RtspMessage.MessageIdentifier) && // Fake protection from GStreamer @@ -2628,7 +2628,7 @@ public void StartPlaying(TimeSpan? start = null, TimeSpan? end = null, IEnumerab //Check if Describe is allowed or that a SessionDescription is present. if (SupportedMethods.Count > 0 && false.Equals(SupportedMethods.Contains(RtspMethod.DESCRIBE.ToString())) && - Common.IDisposedExtensions.IsNullOrDisposed(SessionDescription) && SupportedFeatures.Count.Equals(0)) + Common.IDisposedExtensions.IsNullOrDisposed(SessionDescription) && SupportedFeatures.Count is 0) { Media.Common.TaggedExceptionExtensions.RaiseTaggedException(SupportedMethods, "SupportedMethods does not allow Describe and SessionDescription is null. See Tag with SupportedMessages."); } @@ -2793,7 +2793,7 @@ public void StartPlaying(TimeSpan? start = null, TimeSpan? end = null, IEnumerab //As such it's importan't to keep this socket as busy as possible for the first few attempts and until the response or packets are received as required. if (m_RtpProtocol == ProtocolType.Udp) m_RtpProtocol = ProtocolType.Tcp; - else if (m_RtspSocket.Connected && m_RtspSocket.Poll(0, SelectMode.SelectRead) && m_RtspSocket.Available.Equals(0)) + else if (m_RtspSocket.Connected && m_RtspSocket.Poll(0, SelectMode.SelectRead) && m_RtspSocket.Available is 0) { Reconnect(); @@ -3030,7 +3030,7 @@ public void StartPlaying(TimeSpan? start = null, TimeSpan? end = null, IEnumerab (currentStatusCode = m_LastTransmitted.RtspStatusCode) <= RtspStatusCode.OK && currentStatusCode >= RtspStatusCode.Unknown) break; } - } while (IsConnected && m_RtpClient.TotalBytesReceieved.Equals(0)); + } while (IsConnected && m_RtpClient.TotalBytesReceieved is 0); //Ensure the RtpClient is still active. if(false.Equals(Common.IDisposedExtensions.IsNullOrDisposed(this))) m_RtpClient.Activate(); @@ -3682,10 +3682,10 @@ public virtual RtspMessage Authenticate(RtspMessage request, RtspMessage respons string[] baseParts = authenticateHeader.Split(RtspMessage.SpaceSplit, 2, StringSplitOptions.RemoveEmptyEntries); //If nothing was in the header then return the response given. - if (baseParts.Length.Equals(0)) return response; + if (baseParts.Length is 0) return response; else if (baseParts.Length > 1) baseParts = Media.Common.Extensions.Linq.LinqExtensions.Yield(baseParts[0]).Concat(baseParts[1].Split(RtspHeaders.Comma).Select(s => s.Trim())).ToArray(); - if (string.Compare(baseParts[0].Trim(), RtspHeaderFields.Authorization.Basic, true).Equals(0) || m_AuthenticationScheme == AuthenticationSchemes.Basic) + if (string.Compare(baseParts[0].Trim(), RtspHeaderFields.Authorization.Basic, true) is 0 || m_AuthenticationScheme == AuthenticationSchemes.Basic) { AuthenticationScheme = AuthenticationSchemes.Basic; @@ -3700,7 +3700,7 @@ public virtual RtspMessage Authenticate(RtspMessage request, RtspMessage respons //Recurse the call with the info from then authenticate header return SendRtspMessage(request); } - else if (string.Compare(baseParts[0].Trim(), RtspHeaderFields.Authorization.Digest, true).Equals(0) || m_AuthenticationScheme == AuthenticationSchemes.Digest) + else if (string.Compare(baseParts[0].Trim(), RtspHeaderFields.Authorization.Digest, true) is 0 || m_AuthenticationScheme == AuthenticationSchemes.Digest) { AuthenticationScheme = AuthenticationSchemes.Digest; @@ -3844,7 +3844,7 @@ public RtspMessage SendRtspMessage(RtspMessage message, out SocketError error, o //Check for illegal feeding of turtles if (IDisposedExtensions.IsNullOrDisposed(message) is false && - string.Compare("REGISTER", message.MethodString, true).Equals(0) && + string.Compare("REGISTER", message.MethodString, true) is 0 && string.IsNullOrWhiteSpace(UserAgent) is false) throw new InvalidOperationException("Please don't feed the turtles."); //Todo, add jump detection and if forbidden string is found then execute OOPS en los advertenica @@ -4362,7 +4362,7 @@ SharesSocket is false && //If we have a message to send and did not send it then goto send. //message.Transferred.HasValue if (message is not null && - sent.Equals(0)) goto Send; + sent is 0) goto Send; //Receive again goto Receive; @@ -4609,7 +4609,7 @@ SharesSocket is false && //If we dont have an exiting id then this is valid if the header was completely recieved only. if (false.Equals(string.IsNullOrWhiteSpace(value)) && string.IsNullOrWhiteSpace(m_SessionId) || - false.Equals(string.Compare(value, m_SessionId).Equals(Common.Binary.Zero))) + false.Equals(string.Compare(value, m_SessionId) is Common.Binary.Zero)) { //Get the SessionId if present m_SessionId = sessionHeaderParts[0].Trim(); @@ -4916,7 +4916,7 @@ public RtspMessage SendDescribe() //bool force, bool followRedirects //Handle MultipleChoice for Moved or ContentType... if (response.RtspStatusCode >= RtspStatusCode.MultipleChoices && false.Equals(string.IsNullOrEmpty(contentType)) && - string.Compare(contentType.TrimStart(), Sdp.SessionDescription.MimeType, true).Equals(0) is false) + string.Compare(contentType.TrimStart(), Sdp.SessionDescription.MimeType, true) is 0 is false) { Media.Common.TaggedExceptionExtensions.RaiseTaggedException(response.RtspStatusCode, "Unable to describe media. The StatusCode is in the Tag property."); } @@ -5464,7 +5464,7 @@ requested. The server MAY truncate this packet size to the closest } } } - else if (string.Compare(mediaDescription.MediaProtocol, RtpClient.RtpAvpProfileIdentifier, true).Equals(0)) // We need to find an open Udp Port + else if (string.Compare(mediaDescription.MediaProtocol, RtpClient.RtpAvpProfileIdentifier, true) is 0) // We need to find an open Udp Port { //Revise @@ -5824,8 +5824,8 @@ requested. The server MAY truncate this packet size to the closest else if (Common.IDisposedExtensions.IsNullOrDisposed(created)) { //Obtain the context via the given local or remote id - created = localSsrc.Equals(0) is false ? m_RtpClient.GetContextBySourceId(localSsrc) : - remoteSsrc.Equals(0) is false ? m_RtpClient.GetContextBySourceId(remoteSsrc) : null; + created = localSsrc is 0 is false ? m_RtpClient.GetContextBySourceId(localSsrc) : + remoteSsrc is 0 is false ? m_RtpClient.GetContextBySourceId(remoteSsrc) : null; //If the control channel is the same then just update the client and ensure connected. if (Common.IDisposedExtensions.IsNullOrDisposed(created) is false && diff --git a/Rtsp/RtspMessage.cs b/Rtsp/RtspMessage.cs index c8f34cbd..48ba62c3 100644 --- a/Rtsp/RtspMessage.cs +++ b/Rtsp/RtspMessage.cs @@ -665,7 +665,7 @@ protected internal override bool ParseBody(out int remaining, bool force = false //Empty body or no ContentLength //If the message cannot have a body it is parsed. //If the content length was set to 0 on purpose than this logic needs to be changed to continue parsing. - if (CanHaveBody is false || m_ContentLength.Equals(0)) return true; + if (CanHaveBody is false || m_ContentLength is 0) return true; //Get the decoder to use for the body Encoding decoder = ParseContentEncoding(false, FallbackToDefaultEncoding); @@ -708,7 +708,7 @@ protected internal override bool ParseBody(out int remaining, bool force = false { //Todo, copy or annotate, DO NOT ALLOCATE TO STRING... - if (existingBodySize.Equals(0)) + if (existingBodySize is 0) m_Body = decoder.GetString(buffer, position, Media.Common.Binary.Min(ref available, ref remaining)); else //Append to the existing body m_Body += decoder.GetString(buffer, position, Media.Common.Binary.Min(ref available, ref remaining)); diff --git a/Rtsp/RtspSession.cs b/Rtsp/RtspSession.cs index 8134511b..05f2c4c3 100644 --- a/Rtsp/RtspSession.cs +++ b/Rtsp/RtspSession.cs @@ -1392,7 +1392,7 @@ SharesSocket is false && //If we have a message to send and did not send it then goto send. //message.Transferred.HasValue if (message is not null && - sent.Equals(0)) goto Send; + sent is 0) goto Send; //Receive again goto Receive; @@ -1639,7 +1639,7 @@ SharesSocket is false && //If we dont have an exiting id then this is valid if the header was completely recieved only. if (false.Equals(string.IsNullOrWhiteSpace(value)) && string.IsNullOrWhiteSpace(SessionId) || - false.Equals(string.Compare(value, SessionId).Equals(Common.Binary.Zero))) + false.Equals(string.Compare(value, SessionId) is Common.Binary.Zero)) { //Get the SessionId if present SessionId = sessionHeaderParts[0].Trim(); @@ -1811,10 +1811,10 @@ public virtual RtspMessage Authenticate(RtspMessage request, RtspMessage respons string[] baseParts = authenticateHeader.Split(Media.Common.Extensions.Linq.LinqExtensions.Yield(((char)Common.ASCII.Space)).ToArray(), 2, StringSplitOptions.RemoveEmptyEntries); //If nothing was in the header then return the response given. - if (baseParts.Length.Equals(0)) return response; + if (baseParts.Length is 0) return response; else if (baseParts.Length > 1) baseParts = Media.Common.Extensions.Linq.LinqExtensions.Yield(baseParts[0]).Concat(baseParts[1].Split(RtspHeaders.Comma).Select(s => s.Trim())).ToArray(); - if (string.Compare(baseParts[0].Trim(), RtspHeaderFields.Authorization.Basic, true).Equals(0) || m_AuthenticationScheme == AuthenticationSchemes.Basic) + if (string.Compare(baseParts[0].Trim(), RtspHeaderFields.Authorization.Basic, true) is 0 || m_AuthenticationScheme == AuthenticationSchemes.Basic) { AuthenticationScheme = AuthenticationSchemes.Basic; @@ -1829,7 +1829,7 @@ public virtual RtspMessage Authenticate(RtspMessage request, RtspMessage respons //Recurse the call with the info from then authenticate header return SendRtspMessage(request); } - else if (string.Compare(baseParts[0].Trim(), RtspHeaderFields.Authorization.Digest, true).Equals(0) || m_AuthenticationScheme == AuthenticationSchemes.Digest) + else if (string.Compare(baseParts[0].Trim(), RtspHeaderFields.Authorization.Digest, true) is 0 || m_AuthenticationScheme == AuthenticationSchemes.Digest) { AuthenticationScheme = AuthenticationSchemes.Digest; diff --git a/RtspServer/ClientSession.cs b/RtspServer/ClientSession.cs index d249919f..3eb622b8 100644 --- a/RtspServer/ClientSession.cs +++ b/RtspServer/ClientSession.cs @@ -432,7 +432,7 @@ public void SendRtspData(byte[] data, int offset, int length, SocketFlags flags //Check for no data or 0 length when sharing socket. if (Common.Extensions.Array.ArrayExtensions.IsNullOrEmpty(data, out check) || length - offset > check || - (length.Equals(Common.Binary.Zero) && SharesSocket)) return; + (length is Common.Binary.Zero && SharesSocket)) return; try { @@ -1014,7 +1014,7 @@ further action and can be used by the client to test server liveness. Sdp.MediaType mediaType; //If the mediaType was specified there will be /audio or video and that will compare to the lastSegment, 3 previously would be parsed as text etc. - if (Enum.TryParse(lastSegment, true, out mediaType) && string.Compare(lastSegment, mediaType.ToString(), true).Equals(0)) + if (Enum.TryParse(lastSegment, true, out mediaType) && string.Compare(lastSegment, mediaType.ToString(), true) is 0) { var sourceContext = sourceAvailable.FirstOrDefault(tc => tc.MediaDescription.MediaType == mediaType); @@ -1380,13 +1380,13 @@ constraints on servers that need to support multiple session //QuickTime debug - if (clientRtpPort.Equals(0)) clientRtpPort = Media.Common.Extensions.Socket.SocketExtensions.ProbeForOpenPort(ProtocolType.Udp, 30000, true); + if (clientRtpPort is 0) clientRtpPort = Media.Common.Extensions.Socket.SocketExtensions.ProbeForOpenPort(ProtocolType.Udp, 30000, true); - if (clientRtcpPort.Equals(0)) clientRtcpPort = clientRtpPort + 1; + if (clientRtcpPort is 0) clientRtcpPort = clientRtpPort + 1; - if (serverRtpPort.Equals(0)) serverRtpPort = Media.Common.Extensions.Socket.SocketExtensions.ProbeForOpenPort(ProtocolType.Udp, 30000, true); + if (serverRtpPort is 0) serverRtpPort = Media.Common.Extensions.Socket.SocketExtensions.ProbeForOpenPort(ProtocolType.Udp, 30000, true); - if (serverRtcpPort.Equals(0)) serverRtcpPort = serverRtpPort + 1; + if (serverRtcpPort is 0) serverRtcpPort = serverRtpPort + 1; //Ensure the ports are allowed to be used. if (m_Server.MaximumUdpPort.HasValue && @@ -1618,7 +1618,7 @@ void ProcessClientSessionBuffer(object sender, byte[] data, int offset, int leng if(IsDisconnected is false) m_Server.ProcessClientBuffer(this, length); //Handle high usage when client disconnects. - if (length.Equals(0) && m_RtpClient.IsActive) + if (length is 0 && m_RtpClient.IsActive) { //should also check activity on each context to properly determine :) @@ -1922,7 +1922,7 @@ internal bool ReleaseUnusedResources() released = true; } - if (m_RtpClient.TransportContexts.Count.Equals(0)) + if (m_RtpClient.TransportContexts.Count is 0) { Common.ILoggingExtensions.Log(m_Server.Logger, "Session Deactivated - " + SessionId); @@ -2046,7 +2046,7 @@ internal bool ReleaseUnusedResources() // released = true; // } - // if (m_RtpClient.TransportContexts.Count.Equals(0)) + // if (m_RtpClient.TransportContexts.Count is 0) // { // m_RtpClient.Deactivate(); @@ -2151,7 +2151,7 @@ internal bool ReleaseUnusedResources() //Remove rtp theads if (false.Equals(Common.IDisposedExtensions.IsNullOrDisposed(m_RtpClient)) && m_RtpClient.IsActive) { - if (Playing.Count.Equals(0)) + if (Playing.Count is 0) { released = true; diff --git a/RtspServer/MediaTypes/RtpSink.cs b/RtspServer/MediaTypes/RtpSink.cs index d241fa7f..13327a12 100644 --- a/RtspServer/MediaTypes/RtpSink.cs +++ b/RtspServer/MediaTypes/RtpSink.cs @@ -155,7 +155,7 @@ internal virtual void SendPackets() { try { - if (Packets.Count.Equals(0)) + if (Packets.Count is 0) { System.Threading.Thread.Sleep(0); diff --git a/RtspServer/RtspServer.cs b/RtspServer/RtspServer.cs index db5972ee..3f951863 100644 --- a/RtspServer/RtspServer.cs +++ b/RtspServer/RtspServer.cs @@ -1974,7 +1974,7 @@ internal void ProcessClientBuffer(ClientSession session, int received) received = session.LastRequest.CompleteFrom(null, data); //If nothing was recieved then do nothing. - if (received.Equals(0)) + if (received is 0) { Media.Common.ILoggingExtensions.Log(Logger, "Session:" + session.Id + "Did not use buffer of " + data.Count + " bytes."); } @@ -2027,7 +2027,7 @@ internal void ProcessClientBuffer(ClientSession session, int received) session.LastRequest = request; //Ensure the session is still connected. - if (session.m_RtspSocket.Available.Equals(0)) session.SendRtspData(Media.Common.MemorySegment.EmptyBytes); + if (session.m_RtspSocket.Available is 0) session.SendRtspData(Media.Common.MemorySegment.EmptyBytes); else session.StartReceive(); //} } @@ -2728,7 +2728,7 @@ used by the client to compute the round-trip time to the server so else { //Test the connectivity and start another receive - if (session.m_RtspSocket.Available.Equals(0)) session.SendRtspData(Media.Common.MemorySegment.EmptyBytes); + if (session.m_RtspSocket.Available is 0) session.SendRtspData(Media.Common.MemorySegment.EmptyBytes); else session.StartReceive(); } } @@ -3042,7 +3042,7 @@ internal void ProcessRtspSetup(RtspMessage request, ClientSession session, bool Sdp.MediaDescription mediaDescription; if ((symbolIndex = track.IndexOf('=')) >= 0 && int.TryParse(Media.Common.ASCII.ExtractNumber(track, symbolIndex, track.Length), System.Globalization.NumberStyles.Integer, System.Globalization.CultureInfo.InvariantCulture, out trackId)) mediaDescription = found.SessionDescription.GetMediaDescription(trackId - 1); - else mediaDescription = found.SessionDescription.MediaDescriptions.FirstOrDefault(md => string.Compare(track, md.MediaType.ToString(), true, System.Globalization.CultureInfo.InvariantCulture).Equals(0)); + else mediaDescription = found.SessionDescription.MediaDescriptions.FirstOrDefault(md => string.Compare(track, md.MediaType.ToString(), true, System.Globalization.CultureInfo.InvariantCulture) is 0); ////Find the MediaDescription for the request based on the track variable //foreach (Sdp.MediaDescription md in found.SessionDescription.MediaDescriptions) @@ -3234,7 +3234,7 @@ internal void ProcessRtspTeardown(RtspMessage request, ClientSession session, bo if (string.IsNullOrWhiteSpace(connectionHeader) is false) { - if (string.Compare(connectionHeader.Trim(), RtspHeaderFields.Connection.Close, true).Equals(0)) + if (string.Compare(connectionHeader.Trim(), RtspHeaderFields.Connection.Close, true) is 0) { TryDisposeAndRemoveSession(session); } diff --git a/Sdp/Lines.cs b/Sdp/Lines.cs index 35f15fd2..52676d59 100644 --- a/Sdp/Lines.cs +++ b/Sdp/Lines.cs @@ -682,7 +682,7 @@ public SessionConnectionLine(SessionDescriptionLine line) //Needs to parse with seperator //Currently //ToString has logic which prevents this from mattering. - if (line.m_Parts.Count.Equals(1)) + if (line.m_Parts.Count is 1) { string temp = line.m_Parts[0]; @@ -882,7 +882,7 @@ public SessionOriginLine(SessionDescriptionLine line) m_Parts.Clear(); //Needs to parse with seperator (ToString is hacked up to prevent this from mattering) - if (line.m_Parts.Count.Equals(1)) + if (line.m_Parts.Count is 1) { string temp = line.m_Parts[0]; @@ -2337,7 +2337,7 @@ public string EncodingParameter public RtpMapLine(SessionDescriptionLine line) : base(line) { - if (m_Parts.Count.Equals(0) + if (m_Parts.Count is 0 || false.Equals(AttributeName.StartsWith(AttributeFields.RtpMap, StringComparison.OrdinalIgnoreCase))) throw new InvalidOperationException("Not a RtpMap line"); //Seperator? @@ -2370,7 +2370,7 @@ public RtpMapLine(int payloadType, string encodingNameToken, int clockRate, stri public RtpMapLine(string[] sdpLines, ref int index, string seperator = null, int partCount = 1) : base(sdpLines, ref index, seperator ?? SessionDescription.ForwardSlashString, partCount) { - if (m_Parts.Count.Equals(0) + if (m_Parts.Count is 0 || false.Equals(AttributeName.StartsWith(AttributeFields.RtpMap, StringComparison.OrdinalIgnoreCase))) throw new InvalidOperationException("Not a RtpMap line"); } @@ -2496,7 +2496,7 @@ public int FormatSpecificParametersCount public FormatTypeLine(SessionDescriptionLine line) : base(line) { - if (m_Parts.Count.Equals(0) + if (m_Parts.Count is 0 || false.Equals(AttributeName.StartsWith(AttributeFields.FormatType, StringComparison.OrdinalIgnoreCase))) throw new InvalidOperationException("Not a FormatTypeLine line"); //else if (m_Parts.Count == 1) @@ -2538,7 +2538,7 @@ public FormatTypeLine(int payloadType, string formatSpecificParameters) public FormatTypeLine(string[] sdpLines, ref int index, string seperator = null, int partCount = 1) : base(sdpLines, ref index, seperator ?? SessionDescription.SemiColonString, partCount) { - if (m_Parts.Count.Equals(0) + if (m_Parts.Count is 0 || false.Equals(AttributeName.StartsWith(AttributeFields.FormatType, StringComparison.OrdinalIgnoreCase))) throw new InvalidOperationException("Not a FormatTypeLine line"); //false == GetPart(0).StartsWith(AttributeFields.FormatType, StringComparison.OrdinalIgnoreCase)) throw new InvalidOperationException("Not a FormatTypeLine line"); diff --git a/Sdp/MediaDescription.cs b/Sdp/MediaDescription.cs index 13b5204d..c2ba330b 100644 --- a/Sdp/MediaDescription.cs +++ b/Sdp/MediaDescription.cs @@ -628,12 +628,12 @@ public static bool IsPlayable(this MediaDescription mediaDescription, SessionDes try { //Ensure not a bounded end and that the end time is less than now - if (false.Equals(td.StopTime.Equals(0)) + if (false.Equals(td.StopTime is 0) && td.NtpStopDateTime >= DateTime.UtcNow) return false; //Ensure start time is not bounded and that the start time is greater than now - if (false.Equals(td.StartTime.Equals(0)) + if (false.Equals(td.StartTime is 0) && td.NtpStartDateTime > DateTime.UtcNow) return false; @@ -645,7 +645,7 @@ public static bool IsPlayable(this MediaDescription mediaDescription, SessionDes catch { //Out of range values for conversion, assume true if end is unbounded - if (false.Equals(td.StopTime.Equals(0))) return false; + if (false.Equals(td.StopTime is 0)) return false; } finally { diff --git a/Sdp/SessionDescription.cs b/Sdp/SessionDescription.cs index 8bd2013a..0f44ad23 100644 --- a/Sdp/SessionDescription.cs +++ b/Sdp/SessionDescription.cs @@ -378,7 +378,7 @@ public string OriginatorAndSessionIdentifier bool hadValueWithSetVersion = m_OriginatorLine is not null && m_OriginatorLine.SessionVersion.Equals(Common.Binary.LongZero) is false; if (hadValueWithSetVersion && - string.Compare(value, m_OriginatorLine.ToString(), StringComparison.InvariantCultureIgnoreCase).Equals(0)) return; + string.Compare(value, m_OriginatorLine.ToString(), StringComparison.InvariantCultureIgnoreCase) is 0) return; var token = BeginUpdate(); @@ -402,7 +402,7 @@ public string SessionName if (IsDisposed) return; if (m_NameLine is not null && - string.Compare(value, m_NameLine.SessionName, StringComparison.InvariantCultureIgnoreCase).Equals(0)) return; + string.Compare(value, m_NameLine.SessionName, StringComparison.InvariantCultureIgnoreCase) is 0) return; var token = BeginUpdate(); @@ -430,7 +430,7 @@ public string SessionId if (string.IsNullOrWhiteSpace(value)) throw new ArgumentNullException(); - if (m_OriginatorLine is null || string.Compare(value, m_OriginatorLine.SessionId, StringComparison.InvariantCultureIgnoreCase).Equals(0)) return; + if (m_OriginatorLine is null || string.Compare(value, m_OriginatorLine.SessionId, StringComparison.InvariantCultureIgnoreCase) is 0) return; var token = BeginUpdate(); diff --git a/UnitTests/Code/RtpClientUnitTests.cs b/UnitTests/Code/RtpClientUnitTests.cs index 2d906718..7e29f561 100644 --- a/UnitTests/Code/RtpClientUnitTests.cs +++ b/UnitTests/Code/RtpClientUnitTests.cs @@ -822,7 +822,7 @@ public void TestBroadcast() using (Rtp.RtpClient test = Rtp.RtpClient.FromSessionDescription(sdp)) { //Verify that there are the expected amount of context's - if (false.Equals(test.GetTransportContexts().Count().Equals(1))) throw new System.Exception("Unexpected amount of TransportContext's"); + if (false.Equals(test.GetTransportContexts().Count() is 1)) throw new System.Exception("Unexpected amount of TransportContext's"); Rtp.RtpClient.TransportContext firstContext = test.GetTransportContexts().First();