Ejemplo n.º 1
0
        public RtpPacket(byte[] buffer, int offset, int count, bool shouldDispose = true) : base(shouldDispose)
        {
            if (buffer == null || buffer.Length == 0 || count <= 0)
            {
                throw new ArgumentException("Must have data in a RtpPacket");
            }

            m_OwnedOctets = new byte[count];

            Array.Copy(buffer, offset, m_OwnedOctets, 0, count);

            //Read the header
            Header = new RtpHeader(new MemorySegment(m_OwnedOctets, 0));

            m_OwnsHeader = true;

            if (count > RtpHeader.Length && false == Header.IsCompressed)
            {
                //Create a segment to the payload deleniated by the given offset and the constant Length of the RtpHeader.
                Payload = new MemorySegment(m_OwnedOctets, RtpHeader.Length, count - RtpHeader.Length);
            }
            else
            {
                //m_OwnedOctets = MemorySegment.EmptyBytes; //IsReadOnly should be false
                //Payload = new MemoryReference(m_OwnedOctets, 0, 0, m_OwnsHeader);
                Payload = MemorySegment.Empty;
            }
        }
Ejemplo n.º 2
0
        public RtpHeader(RtpHeader other, bool shouldDispose = true)
            : base(shouldDispose)
        {
            First16Bits = new RFC3550.CommonHeaderBits(other.First16Bits, shouldDispose);

            SegmentToLast10Bytes = new MemorySegment(other.SegmentToLast10Bytes, shouldDispose);
        }
Ejemplo n.º 3
0
        public RtpPacket(int size, bool shouldDispose = true)
            : base(shouldDispose)
        {
            size = Binary.Max(0, size);

            m_OwnedOctets = new byte[size];

            Header = new RtpHeader(new MemorySegment(m_OwnedOctets, 0, Binary.Min(size, RtpHeader.Length)));

            m_OwnsHeader = true;

            Payload = new MemorySegment(m_OwnedOctets, RtpHeader.Length, size - Header.Size);
        }
Ejemplo n.º 4
0
        public RtpPacket(RtpHeader header, MemorySegment payload, bool shouldDispose = true) : base(shouldDispose)
        {
            if (header == null)
            {
                throw new ArgumentNullException("header");
            }

            Header = header;

            m_OwnsHeader = shouldDispose;

            Payload = payload;
        }
Ejemplo n.º 5
0
 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);
     }
 }
Ejemplo n.º 6
0
        public RtpPacket(RtpHeader header, IEnumerable <byte> octets, bool shouldDispose = true) : base(shouldDispose)
        {
            if (header == null)
            {
                throw new ArgumentNullException("header");
            }

            //Assign the header (maybe referenced elsewhere, when dispose is called the given header will be disposed.)
            Header = header;

            m_OwnsHeader = shouldDispose;

            //Project the octets in the sequence of use the empty array
            m_OwnedOctets = (octets ?? MemorySegment.Empty).ToArray();

            //The Payload property must be assigned otherwise the properties will not function in the instance.
            Payload = new MemorySegment(m_OwnedOctets, 0, m_OwnedOctets.Length);
        }
Ejemplo n.º 7
0
 public bool Equals(RtpHeader other)
 {
     return(other.First16Bits.Equals(First16Bits)
            &&
            other.SynchronizationSourceIdentifier.Equals(SynchronizationSourceIdentifier));
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Generates a sequence of bytes containing the RtpHeader and any data contained in Payload.
 /// (Including the SourceList and RtpExtension if present)
 /// </summary>
 /// <param name="other">The optional other RtpHeader to utilize in the preperation</param>
 /// <returns>The sequence created.</returns>
 public IEnumerable <byte> Prepare(RtpHeader other = null)
 {
     return(Enumerable.Concat <byte>(other ?? Header, Payload ?? MemorySegment.Empty));
 }