예제 #1
0
        public ByteBuffer Encode()
        {
            var buffer = new ByteBuffer(PACKET_SIZE_IN_BYTES);

            NtpTime ntpTime = new NtpTime(Time);

            buffer.WriteUint32NetworkOrder(ntpTime.Seconds);
            buffer.WriteUint32NetworkOrder(ntpTime.Fraction);

            byte b = 0x00;

            if (CbitSet)
            {
                b |= C_BIT_FLAG_MASK;
            }

            if (DbitSet)
            {
                b |= D_BIT_FLAG_MASK;
            }

            if (EbitSet)
            {
                b |= E_BIT_FLAG_MASK;
            }

            buffer.WriteByte(b);
            buffer.WriteByte(CSeq);
            buffer.WriteInt16(0);
            buffer.SetPosition(0, ByteBuffer.PositionOrigin.BEGINNING); // Re-set so that we can read from the list
            buffer.MarkReadOnly();

            return(buffer);
        }
예제 #2
0
        public static OnvifRtpHeader Decode(ByteBuffer buffer)
        {
            var  ntpTime = new NtpTime(buffer.ReadInt64AsHost());
            byte b       = buffer.ReadByte();

            return(new OnvifRtpHeader()
            {
                Time = ntpTime.UtcDate,
                CbitSet = (b & C_BIT_FLAG_MASK) != 0,
                DbitSet = (b & D_BIT_FLAG_MASK) != 0,
                EbitSet = (b & E_BIT_FLAG_MASK) != 0,
                CSeq = buffer.ReadByte()
            });
        }
예제 #3
0
        public void TestConvertToNtp()
        {
            DateTime date    = new DateTime(2017, 10, 17, 4, 33, 17, 32, DateTimeKind.Local);
            NtpTime  ntpTime = new NtpTime(date);

            Assert.Equal(3717225197, ntpTime.Seconds);
            Assert.Equal((uint)137438953, ntpTime.Fraction);
            Assert.Equal(date, ntpTime.UtcDate.ToLocalTime());

            date    = new DateTime(2012, 8, 2, 8, 52, 1, 43);
            ntpTime = new NtpTime(date);

            Assert.Equal(3552907921, ntpTime.Seconds);
            Assert.Equal((uint)184683593, ntpTime.Fraction);
            Assert.Equal(date, ntpTime.UtcDate.ToLocalTime());
        }