Exemplo n.º 1
0
        public void Unpack(byte[] buffer, ref int offset, int count)
        {
            if (count < GetByteLength())
            {
                throw new ArgumentOutOfRangeException(nameof(count));
            }

            var bitOffset = 0;

            CsrcCount    = BufferBits.GetByte(buffer, offset, ref bitOffset, 4);
            HasExtension = BufferBits.GetBool(buffer, offset, ref bitOffset);
            HasPadding   = BufferBits.GetBool(buffer, offset, ref bitOffset);
            Version      = BufferBits.GetByte(buffer, ref offset, ref bitOffset, 2);
            if (Version != DEFAULT_VERSION_VALUE)
            {
                throw new ArgumentException(nameof(Version));
            }

            bitOffset   = 0;
            PayloadType = BufferBits.GetByte(buffer, offset, ref bitOffset, 7);
            Marker      = BufferBits.GetBool(buffer, ref offset, ref bitOffset);

            SequenceNumber = BufferBits.GetUInt16(buffer, ref offset);
            TimeStamp      = BufferBits.GetUInt32(buffer, ref offset);
            Ssrc           = BufferBits.GetUInt32(buffer, ref offset);

            if (count < GetByteLength())
            {
                throw new ArgumentOutOfRangeException(nameof(count));
            }

            for (int i = 0; i < CsrcCount; i++)
            {
                _csrcList.Add(BufferBits.GetUInt32(buffer, ref offset));
            }

            if (HasExtension)
            {
                Extension.Unpack(buffer, ref offset, buffer.Length);
            }

            var payloadCount = buffer.Length - offset;

            if (HasPadding)
            {
                var remain = buffer.Length - 1;
                PaddingCount = BufferBits.GetByte(buffer, ref remain);
                if (PaddingCount > 0)
                {
                    payloadCount -= PaddingCount;
                }
            }

            Payload = BufferBits.GetBytes(buffer, ref offset, payloadCount);

            if (HasPadding)
            {
                offset += PaddingCount;
            }
        }
Exemplo n.º 2
0
        public void Pack(T packet, ref byte[] buffer, ref int offset, int extraBytes = 0)
        {
            byte[] message = Encoding.GetBytes(Pack(packet));

            BufferBits.Prepare(ref buffer, offset, message.Length + extraBytes);
            BufferBits.SetBytes(message, buffer, ref offset);
        }
Exemplo n.º 3
0
 public void Pack(ref byte[] buffer, ref int offset)
 {
     BufferBits.SetUInt16(Profile, buffer, ref offset);
     BufferBits.SetUInt16(Length, buffer, ref offset);
     foreach (var extension in Extension)
     {
         BufferBits.SetUInt32(extension, buffer, ref offset);
     }
 }
Exemplo n.º 4
0
        public override void Pack(ref byte[] buffer, ref int offset)
        {
            _builder.Pack(this, ref buffer, ref offset, ContentLength);

            if (ContentLength > 0)
            {
                BufferBits.SetBytes(Content.ToArray(), buffer, ref offset);
            }
        }
Exemplo n.º 5
0
        public void Unpack(byte[] buffer, ref int offset, int count)
        {
            if (count < GetByteLength())
            {
                throw new ArgumentOutOfRangeException(nameof(count));
            }

            Profile = BufferBits.GetUInt16(buffer, ref offset);
            Length  = BufferBits.GetUInt16(buffer, ref offset);
            for (int i = 0; i < Length; i++)
            {
                _extensionList.Add(BufferBits.GetUInt32(buffer, ref offset));
            }

            offset += Extension.Count * 8;
        }
Exemplo n.º 6
0
        public void Pack(ref byte[] buffer, ref int offset)
        {
            BufferBits.Prepare(ref buffer, offset, GetByteLength());

            var bitOffset = 0;

            BufferBits.SetByte(CsrcCount, buffer, offset, ref bitOffset, 4);
            BufferBits.SetBool(HasExtension, buffer, offset, ref bitOffset);
            BufferBits.SetBool(HasPadding, buffer, offset, ref bitOffset);
            BufferBits.SetByte(Version, buffer, ref offset, ref bitOffset, 2);

            bitOffset = 0;
            BufferBits.SetByte(PayloadType, buffer, offset, ref bitOffset, 7);
            BufferBits.SetBool(Marker, buffer, ref offset, ref bitOffset);

            BufferBits.SetUInt16(SequenceNumber, buffer, ref offset);
            BufferBits.SetUInt32(TimeStamp, buffer, ref offset);
            BufferBits.SetUInt32(Ssrc, buffer, ref offset);
            foreach (var csrc in CsrcList.Take(CsrcCount))
            {
                BufferBits.SetUInt32(csrc, buffer, ref offset);
            }

            if (HasExtension)
            {
                Extension.Pack(ref buffer, ref offset);
            }

            if (Payload.Count > 0)
            {
                BufferBits.SetBytes(Payload.ToArray(), buffer, ref offset);
            }

            if (HasPadding && PaddingCount > 0)
            {
                offset += PaddingCount - 1;
                BufferBits.SetByte(PaddingCount, buffer, ref offset);
            }
        }
Exemplo n.º 7
0
 public void Clear(BufferBits mask) => this.CallMethod <object>(CLEAR, mask);