/// <summary>
/// Does the actual sending of an RTP packet using the specified data nad header values.
/// </summary>
/// <param name="srcRtpSocket">Socket to send from.</param>
/// <param name="dstRtpSocket">Destination to send to.</param>
/// <param name="data">The RTP packet payload.</param>
/// <param name="timestamp">The RTP header timestamp.</param>
/// <param name="markerBit">The RTP header marker bit.</param>
/// <param name="payloadType">The RTP header payload type.</param>
private void SendRtpPacket(Socket srcRtpSocket, IPEndPoint dstRtpSocket, byte[] data, uint timestamp, int markerBit, int payloadType)
{
int srtpProtectionLength = (SrtpProtect != null) ? SRTP_AUTH_KEY_LENGTH : 0;
RTPPacket rtpPacket = new RTPPacket(data.Length + srtpProtectionLength);
rtpPacket.Header.SyncSource = Ssrc;
rtpPacket.Header.SequenceNumber = SeqNum;
rtpPacket.Header.Timestamp = timestamp;
rtpPacket.Header.MarkerBit = markerBit;
rtpPacket.Header.PayloadType = payloadType;
Buffer.BlockCopy(data, 0, rtpPacket.Payload, 0, data.Length);
var rtpBuffer = rtpPacket.GetBytes();
int rtperr = SrtpProtect == null ? 0 : SrtpProtect(rtpBuffer, rtpBuffer.Length - srtpProtectionLength);
if (rtperr != 0)
{
logger.LogError("SendDtmfEvent SRTP packet protection failed, result " + rtperr + ".");
}
else
{
srcRtpSocket.SendTo(rtpBuffer, dstRtpSocket);
}
}