/// <summary> /// Event handler for receiving data on the RTP channel. /// </summary> /// <param name="remoteEndPoint">The remote end point the data was received from.</param> /// <param name="buffer">The data received.</param> private void RtpPacketReceived(IPEndPoint remoteEndPoint, byte[] buffer) { if (m_lastReceiveFromEndPoint == null || !m_lastReceiveFromEndPoint.Equals(remoteEndPoint)) { OnReceiveFromEndPointChanged?.Invoke(m_lastReceiveFromEndPoint, remoteEndPoint); m_lastReceiveFromEndPoint = remoteEndPoint; } // Quick sanity check on whether this is not an RTP or RTCP packet. if (buffer?.Length > RTPHeader.MIN_HEADER_LEN && buffer[0] >= 128 && buffer[0] <= 191) { var rtpPacket = new RTPPacket(buffer); OnRtpPacketReceived?.Invoke(rtpPacket); if (RemoteRtpEventPayloadID != 0 && rtpPacket.Header.PayloadType == RemoteRtpEventPayloadID) { RTPEvent rtpEvent = new RTPEvent(rtpPacket.Payload); OnRtpEvent?.Invoke(rtpEvent); } else { OnReceivedSampleReady?.Invoke(rtpPacket.Payload); } } }
/// <summary> /// Processes received RTP packets. /// </summary> /// <param name="buffer">The raw data received on the RTP socket.</param> /// <param name="offset">Offset in the buffer that the received data starts from.</param> /// <param name="count">The number of bytes received.</param> /// <param name="remoteEndPoint">The remote end point the receive was from.</param> /// <returns>An RTP packet.</returns> public RTPPacket RtpReceive(byte[] buffer, int offset, int count, IPEndPoint remoteEndPoint) { if (_lastReceiveFromEndPoint == null || !_lastReceiveFromEndPoint.Equals(remoteEndPoint)) { OnReceiveFromEndPointChanged?.Invoke(_lastReceiveFromEndPoint, remoteEndPoint); _lastReceiveFromEndPoint = remoteEndPoint; } return(new RTPPacket(buffer.Skip(offset).Take(count).ToArray())); }
/// <summary> /// Event handler for receiving data on the RTP channel. /// </summary> /// <param name="remoteEndPoint">The remote end point the data was received from.</param> /// <param name="buffer">The data received.</param> private void RtpPacketReceived(IPEndPoint remoteEndPoint, byte[] buffer) { if (m_lastReceiveFromEndPoint == null || !m_lastReceiveFromEndPoint.Equals(remoteEndPoint)) { OnReceiveFromEndPointChanged?.Invoke(m_lastReceiveFromEndPoint, remoteEndPoint); m_lastReceiveFromEndPoint = remoteEndPoint; } var rtpPacket = new RTPPacket(buffer); OnRtpPacketReceived?.Invoke(rtpPacket); if (m_remoteRtpEventPayloadID != 0 && rtpPacket.Header.PayloadType == m_remoteRtpEventPayloadID) { RTPEvent rtpEvent = new RTPEvent(rtpPacket.Payload); OnRtpEvent?.Invoke(rtpEvent); } else { OnReceivedSampleReady?.Invoke(rtpPacket.Payload); } }