public static RtpPacket Decode(byte[] buffer) { var packet = new RtpPacket(); packet.Version = buffer[0] >> 6; packet.Padding = (buffer[0] & 0x20) != 0; packet.Extension = (buffer[0] & 0x10) != 0; packet.ContributingSourceCount = buffer[0] & 0x0f; packet.Marker = (buffer[1] & 0x80) != 0; packet.PayloadType = buffer[1] & 0x7f; packet.SequenceNumber = Utils.Convert2BytesToInt(buffer, 2); packet.TimeStamp = Utils.Convert4BytesToLong(buffer, 4); packet.SynchronizationSource = Utils.Convert4BytesToLong(buffer, 8); int index = 12; if (packet.ContributingSourceCount != 0) { packet.ContributingSources = new Collection<string>(); while (packet.ContributingSources.Count < packet.ContributingSourceCount) { packet.ContributingSources.Add(Utils.ConvertBytesToString(buffer, index, 4)); index += 4; } } var dataoffset = 0; if (!packet.Extension) dataoffset = index; else { packet.ExtensionHeaderId = Utils.Convert2BytesToInt(buffer, index); packet.ExtensionHeaderLength = Utils.Convert2BytesToInt(buffer, index + 2); dataoffset = index + packet.ExtensionHeaderLength + 4; } var dataLength = buffer.Length - dataoffset; if (dataLength > dataoffset) { packet.HasPayload = true; packet.Payload = new byte[dataLength]; Array.Copy(buffer, dataoffset, packet.Payload, 0, dataLength); } else { packet.HasPayload = false; } return packet; }
public RtpPacketReceivedArgs(RtpPacket packet) { Packet = packet; }