Example #1
0
        public void ParseTest()
        {
            byte[] bytes1 = new byte[]
            {
                0xff, 0xff, 0xff, 0xff,
                0xb2, 0xEA, 0x46, 0x5C,
                0x06, 0xE7, 0x95, 0xA7,
                0x00, 0x01, 0x50, 0x61,
                0x00, 0x00, 0x00, 0x01,                 // CSRC1
                0x00, 0x00, 0x00, 0x02,                 // CSRC2
                0x01, 0x0A, 0x03, 0xC0,
            };
            int startIndex1 = 4;
            int length      = bytes1.Length;

            var message1 = RtpMessage.Parse(bytes1, startIndex1, length);

            Assert.AreEqual(message1.Version, 2, "Rtp.Version");
            Assert.AreEqual(message1.Padding, true, "Rtp.Padding");
            Assert.AreEqual(message1.Extension, true, "Rtp.Extension");
            Assert.AreEqual(message1.CsrcCount, 2, "Rtp.CsrcCount");
            Assert.AreEqual(message1.Marker, true, "Rtp.Marker");
            Assert.AreEqual(message1.PayloadType, 106, "Rtp.PayloadType");
            Assert.AreEqual(message1.SequenceNumber, 0x465c, "Rtp.SequenceNumber");
            Assert.AreEqual(message1.Timestamp, 0x006E795A7u, "Rtp.Timestamp");
            Assert.AreEqual(message1.Ssrc, 0x00015061u, "Rtp.Ssrc");
            Assert.AreEqual(message1.CsrcList[0], 0x00000001u, "CsrcList[0]");
            Assert.AreEqual(message1.CsrcList[1], 0x00000002u, "CsrcList[1]");
            Assert.AreEqual(message1.GetPayloadLength(startIndex1, bytes1.Length), 4, "Rtp.PayloadLength");
        }
Example #2
0
        public void IsRtpMessageTest()
        {
            byte[] bytes1 = new byte[]
            {
                0xff, 0xff, 0xff, 0xff,
                0xb2, 0xEA, 0x46, 0x5C,
            };

            byte[] bytes2 = new byte[]
            {
                0xb2, 0xC8, 0x46, 0x5C,
            };

            byte[] bytes3 = new byte[]
            {
                0xb2, 0xC9, 0x46, 0x5C,
            };

            byte[] bytes4 = new byte[]
            {
                0x02, 0xEA, 0x46, 0x5C,
            };

            Assert.IsTrue(RtpMessage.IsRtpMessage(bytes1, 4, bytes1.Length));
            Assert.IsFalse(RtpMessage.IsRtpMessage(bytes2, 0, bytes2.Length));
            Assert.IsFalse(RtpMessage.IsRtpMessage(bytes3, 0, bytes3.Length));
            Assert.IsFalse(RtpMessage.IsRtpMessage(bytes4, 0, bytes4.Length));
        }
Example #3
0
		public void GetBytesTest()
		{
			RtpMessage target = new RtpMessage(); // TODO: Initialize to an appropriate value
			byte[] bytes = null; // TODO: Initialize to an appropriate value
			int startIndex = 0; // TODO: Initialize to an appropriate value
			target.GetBytes(bytes, startIndex);
			Assert.Inconclusive("A method that does not return a value cannot be verified.");
		}
Example #4
0
		public void InsertMessage(RtpMessage message)
		{
			var ssrc = FindSsrc(message.Ssrc);
			if (ssrc == null)
				ssrc = AddSsrc(message.Ssrc, 0x000fffffffffffff, message.Timestamp);

			ssrc.InsertMessage(message);
		}
Example #5
0
        protected override async Task ProcessAsync(Datagram datagram)
        {
            await NextAsync(datagram);

            if (RtpMessage.TryParse(datagram.Buffer, out var message))
            {
                await responseBuffer.SendAsync(message);
            }
        }
Example #6
0
        public void GetBytesTest()
        {
            RtpMessage target = new RtpMessage(); // TODO: Initialize to an appropriate value

            byte[] bytes      = null;             // TODO: Initialize to an appropriate value
            int    startIndex = 0;                // TODO: Initialize to an appropriate value

            target.GetBytes(bytes, startIndex);
            Assert.Inconclusive("A method that does not return a value cannot be verified.");
        }
Example #7
0
		public UInt64 GetNtpTimestamp(RtpMessage message, int rate)
		{
			if (rate != 0)
			{
				UInt32 delta1 = message.Timestamp - baseRtpTimestamp;
				UInt32 delta2 = baseRtpTimestamp - message.Timestamp;

				if (delta1 <= delta2)
					return baseNtpTimestamp +
						((UInt64)delta1 << 32) / (UInt64)rate;
				else
					return baseNtpTimestamp -
						((UInt64)delta2 << 32) / (UInt64)rate;
			}

			return 0;
		}
Example #8
0
		public void Insert(RtpMessage message)
		{
			if (message.SequenceNumber > dequeuedSequenceNumber)
			{
				int index = messages.FindIndex(
					(oldMessage) => { return message.SequenceNumber <= oldMessage.SequenceNumber; });

				if (index < 0)
				{
					messages.Add(message);
				}
				else
				{
					if (messages[index].SequenceNumber != message.SequenceNumber)
						messages.Insert(index, message);
				}
			}
		}
        public void ParseMessage()
        {
            var bytes = new byte[]
            {
                179,               // 2, true, true, 3
                239,               // true, 111
                2, 27,             // 539
                0, 7, 4, 17,       // 459793
                32, 150, 138, 169, // 546736809
                0, 0, 0, 10,       // 10
                0, 3, 149, 145,    // 234897
                21, 35, 239, 62,   // 354676542
                1, 2, 3, 4,        // payload
                0, 0, 3            // padding 3
            };

            var result  = RtpMessage.TryParse(bytes, out var message);
            var sources = message.Sources.GetEnumerator();

            Assert.True(result);
            Assert.Equal(2, message.Version);
            Assert.True(message.HasHeaderExtension);
            Assert.True(message.IsMarker);
            Assert.Equal(111, message.PayloadType);
            Assert.Equal(539, message.SequenceNumber);
            Assert.Equal(459793, message.Timestamp);
            Assert.Equal(546736809, message.SourceIdentifier);

            Assert.Equal(3, message.Sources.Count);
            Assert.True(sources.MoveNext());
            Assert.Equal(10, sources.Current);
            Assert.True(sources.MoveNext());
            Assert.Equal(234897, sources.Current);
            Assert.True(sources.MoveNext());
            Assert.Equal(354676542, sources.Current);

            Assert.True(message.Payload.Span.SequenceEqual(new byte[] { 1, 2, 3, 4 }));
        }
Example #10
0
		public bool DequeueAvailable(UInt64 maxNtpTimestamp, out RtpMessage message)
		{
			message = DequeueAvailable(maxNtpTimestamp);

			return message != null;
		}
Example #11
0
		public void InsertMessage(RtpMessage message)
		{
			if (JitterBuffers[message.PayloadType] != null)
				JitterBuffers[message.PayloadType].Insert(message);
		}
Example #12
0
		public UInt64 GetNtpTimestamp(RtpMessage message)
		{
			return GetNtpTimestamp(message, JitterBuffers[message.PayloadType].Rate);
		}