Exemplo n.º 1
0
        public override bool SignalInputData(InputStream inputStream, IPEndPoint address)
        {
            if (address != _lastAddress)
            {
                _lastAddress = address;
                _validLastAddress = true;
            }
            var bufferLength = inputStream.AvaliableByteCounts;
            var pos = inputStream.Position;
            //1. Parse the SR
            if (bufferLength < 16) return true;
            inputStream.Reader.ReadByte();
            var PT = inputStream.Reader.ReadByte();
            var len = inputStream.Reader.ReadUInt16();
            len = (ushort) ((len + 1) * 4);
            if (len > bufferLength)
            {
                inputStream.IgnoreAll();
                return true;
            }
            switch (PT)
            {
                case 200:
                    if (len < 28)
                    {
                        Logger.WARN("Invalid RTCP packet length: {0}", len);
                        inputStream.IgnoreAll();
                        return true;
                    }
                    inputStream.Reader.ReadUInt32();
                    var ntpSec = inputStream.Reader.ReadUInt32()- 2208988800U;
                    var ntpFrac = inputStream.Reader.ReadUInt32();
                    ulong ntpMicroseconds = (ulong)((ntpFrac / (double)(0x100000000L))*1000000.0);
                    ntpMicroseconds += ((ulong)ntpSec) * 1000000;
                    var rtpTimestamp = inputStream.Reader.ReadUInt32();
                    _pConnectivity.ReportSR(ntpMicroseconds, rtpTimestamp, _isAudio);
                    break;
                default:
                    inputStream.IgnoreAll();
                    return true;
            }
            inputStream.Position = pos + 10;
            _lsr = inputStream.Reader.ReadUInt32();
            inputStream.IgnoreAll();
            //2. Send the RR
            if (_pConnectivity == null)
            {
                Logger.FATAL("no connectivity");
                return false;
            }
            if (!_pConnectivity.SendRR(_isAudio))
            {
                Logger.FATAL("Unable to send RR");
                _pConnectivity.EnqueueForDelete();
                _pConnectivity = null;
                return false;
            }

            return true;
        }
Exemplo n.º 2
0
 public override bool SignalInputData(InputStream inputStream, IPEndPoint address)
 {
     inputStream.IgnoreAll();
     if (OutboundAddress == null) return true;
     if (!OutboundAddress.Address.Equals(address.Address))
     {
         WARN("Attempt to divert traffic. DoS attack!?");
         return true;
     }
     if (OutboundAddress.Port == address.Port)
     {
         INFO("The client has public endpoint: {0}:{1}",OutboundAddress.Address.ToString(),OutboundAddress.Port);
     }
     else
     {
         INFO("The client is behind firewall: {0}:{1} -> {0}:{2}", OutboundAddress.Address.ToString(), OutboundAddress.Port,address.Port);
         OutboundAddress.Port = address.Port;
     }
     OutboundAddress = null;
     return true;
 }