Ejemplo n.º 1
0
 public RTPChannel(IPEndPoint localEndPoint, IPEndPoint remoteEndPoint)
 {
     m_localEndPoint = localEndPoint;
     m_remoteEndPoint = remoteEndPoint;
     m_rtpListener = new UDPListener(localEndPoint);
     m_rtpListener.PacketReceived += RTPPacketReceived;
 }
Ejemplo n.º 2
0
        private void RTPPacketReceived(UDPListener listener, IPEndPoint localEndPoint, IPEndPoint remoteEndPoint, byte[] buffer)
        {
            if ((buffer[0] == 0x0 || buffer[0] == 0x1) && buffer.Length >= 20)
            {
                // Probably a STUN request.
                STUNMessage stunMessage = STUNMessage.ParseSTUNMessage(buffer, buffer.Length);

                if (stunMessage != null)
                {
                    logger.Debug("STUN message received on RTP channel " + stunMessage.Header.MessageType + ".");

                    if (stunMessage.Header.MessageType == STUNMessageTypesEnum.BindingRequest)
                    {
                        logger.Debug("RTP channel sending STUN response to " + remoteEndPoint + ".");
                        STUNMessage stunResponse = new STUNMessage();
                        stunResponse.Header.MessageType = STUNMessageTypesEnum.BindingResponse;
                        stunResponse.Header.TransactionId = stunMessage.Header.TransactionId;
                        stunResponse.AddUsernameAttribute(Encoding.UTF8.GetString(stunMessage.Attributes[0].Value));
                        byte[] stunRespBytes = stunResponse.ToByteBuffer();
                        SendRaw(remoteEndPoint, stunRespBytes, stunRespBytes.Length);
                    }
                }
            }
            else
            {
                logger.Debug("RTP packet received from " + remoteEndPoint + ".");

                if (SampleReceived != null)
                {
                    var rtpHeader = new RTPHeader(buffer);

                    SampleReceived(buffer, rtpHeader.Length);
                }
            }
        }