protected internal override void Dispose(bool disposing) { if (false.Equals(disposing) || false.Equals(ShouldDispose)) { return; } base.Dispose(ShouldDispose); if (false.Equals(IsDisposed)) { return; } if (false.Equals(IDisposedExtensions.IsNullOrDisposed(First16Bits))) { //Dispose the instance First16Bits.Dispose(); //Remove the reference to the CommonHeaderBits instance First16Bits = null; } if (false.Equals(IDisposedExtensions.IsNullOrDisposed(SegmentToLast6Bytes))) { //Invalidate the pointer SegmentToLast6Bytes.Dispose(); SegmentToLast6Bytes = null; } //Remove the reference to the allocated array. Last6Bytes = null; }
public RtcpHeader(MemorySegment memory, bool shouldDispose = true)//, int additionalOffset = 0) : base(shouldDispose) { First16Bits = new RFC3550.CommonHeaderBits(memory);//, additionalOffset); SegmentToLast6Bytes = new MemorySegment(memory.Array, memory.Offset + RFC3550.CommonHeaderBits.Size, Binary.Clamp(memory.Count - RFC3550.CommonHeaderBits.Size, 0, 6)); }
public RtcpHeader(RtcpHeader other, bool reference, bool shouldDispose = true) : base(shouldDispose) { if (reference) { First16Bits = other.First16Bits; Last6Bytes = other.Last6Bytes; SegmentToLast6Bytes = other.SegmentToLast6Bytes; } else { First16Bits = new RFC3550.CommonHeaderBits(other.First16Bits, false, shouldDispose); Last6Bytes = new byte[6]; SegmentToLast6Bytes = new MemorySegment(Last6Bytes, 0, 6, shouldDispose); if (other.Last6Bytes != null) { other.Last6Bytes.CopyTo(Last6Bytes, 0); } else { System.Array.Copy(other.SegmentToLast6Bytes.Array, other.SegmentToLast6Bytes.Offset, Last6Bytes, 0, 6); } } }
public RtcpHeader(RtcpHeader other, bool shouldDispose = true) : base(shouldDispose) { First16Bits = new RFC3550.CommonHeaderBits(other.First16Bits, shouldDispose); SegmentToLast6Bytes = new MemorySegment(other.SegmentToLast6Bytes, shouldDispose); }
public RtpHeader(MemorySegment memory, bool shouldDispose = true) : base(shouldDispose) { First16Bits = new RFC3550.CommonHeaderBits(memory, shouldDispose); SegmentToLast10Bytes = new MemorySegment(memory.Array, memory.Offset + RFC3550.CommonHeaderBits.Size, Binary.Clamp(memory.Count - RFC3550.CommonHeaderBits.Size, 0, 10), shouldDispose); }
public RtcpHeader(int version, int payloadType, bool padding, int blockCount, bool shouldDispose = true) : base(shouldDispose) { First16Bits = new RFC3550.CommonHeaderBits(version, padding, false, false, payloadType, (byte)blockCount); Last6Bytes = new byte[6]; SegmentToLast6Bytes = new MemorySegment(Last6Bytes, 0, 6); //The default value must be set into the LengthInWords field otherwise it will reflect 0 if (blockCount == 0) { LengthInWordsMinusOne = RtcpHeader.MaximumLengthInWords; // ushort (0 - 1) } }
public RtpHeader(int version, bool padding, bool extension, bool shouldDispose = true) : base(shouldDispose) { First16Bits = new RFC3550.CommonHeaderBits(version, padding, extension); //Allocate space for the other 10 octets Last10Bytes = new byte[10]; SegmentToLast10Bytes = new MemorySegment(Last10Bytes, 0, 10); Version = version; Padding = padding; Extension = extension; }
public RtpHeader(RtpHeader other, bool reference, bool shouldDispose = true) : base(shouldDispose) { if (reference) { First16Bits = other.First16Bits; Last10Bytes = other.Last10Bytes; SegmentToLast10Bytes = other.SegmentToLast10Bytes; } else { First16Bits = new RFC3550.CommonHeaderBits(other.First16Bits, false, shouldDispose); Last10Bytes = new byte[10]; SegmentToLast10Bytes = new MemorySegment(Last10Bytes, 0, 10, shouldDispose); other.Last10Bytes.CopyTo(Last10Bytes, 0); } }
public RtcpHeader(byte[] octets, int offset = 0, bool shouldDispose = true) : base(shouldDispose) { //If the octets reference is null throw an exception if (octets == null) { throw new ArgumentNullException("octets"); } //Determine the length of the array int octetsLength = octets.Length, availableOctets = octetsLength - offset; //Check range if (offset > octetsLength) { throw new ArgumentOutOfRangeException("offset", "Cannot be greater than the length of octets"); } //Check for the amount of octets required to build a RtcpHeader given by the delination of the offset if (octetsLength == 0 || availableOctets < RtcpHeader.Length) { throw new ArgumentException("octets must contain at least 4 elements given the deleniation of the offset parameter.", "octets"); } //Read a managed representation of the first two octets which are stored in Big ByteOrder / Network Byte Order First16Bits = new RFC3550.CommonHeaderBits(octets, offset); //Allocate space for the other 6 octets which consist of the //LengthInWordsMinusOne (16 bits) //SynchronizationSourceIdentifier (32 bits) // 48 Bits = 6 bytes Last6Bytes = new byte[6]; //Copy the remaining bytes of the header which consist of the aformentioned properties //If the LengthInWords is FFFF then this is extreanous and probably belongs to any padding... Array.Copy(octets, offset + RFC3550.CommonHeaderBits.Size, Last6Bytes, 0, Binary.Min(6, availableOctets - RFC3550.CommonHeaderBits.Size)); //Make a pointer to the last 6 bytes SegmentToLast6Bytes = new MemorySegment(Last6Bytes, 0, 6); }
public RtpHeader(byte[] octets, int offset = 0, bool shouldDispose = true) : base(shouldDispose) { //Determine the length of the array long octetsLength; //If the octets reference is null throw an exception if (ArrayExtensions.IsNullOrEmpty(octets, out octetsLength)) { throw new ArgumentException("octets must not be null and must contain at least 1 element given the deleniation of the offset parameter.", "octets"); } //Check range if (offset > octetsLength) { throw new ArgumentOutOfRangeException("offset", "Cannot be greater than the length of octets"); } //Todo, should not matter since this header instance would be allowed to be modified, saving the allocation here is not necessary. //The check is only relevent because octets my have less than 2 bytes which cannot be handled without exception in the CommonHeaderBits //Read a managed representation of the first two octets which are stored in Big ByteOrder / Network Byte Order First16Bits = octetsLength == 1 ? new RFC3550.CommonHeaderBits(octets[offset], default(byte)) : new RFC3550.CommonHeaderBits(octets, offset); //Allocate space for the other 10 octets Last10Bytes = new byte[10]; //If there are octets for those bytes in the source array if (octetsLength > 2) { //Copy the remaining bytes of the header which consist of the //SequenceNumber (2 octets / U16) //Timestamp (4 octets / U32) //SSRC (4 octets / U32) Array.Copy(octets, offset + 2, Last10Bytes, 0, Math.Min(10, octetsLength - 2)); } //Assign the segment SegmentToLast10Bytes = new MemorySegment(Last10Bytes, 0, Last10Bytes.Length); }