
RTP协议介绍:http://www.360doc.com/content/11/1009/15/496343_154624612.shtml
本文中使用了 StreamCoders 的 RTP.net组件,此组件中有些和c++ 混合编程部分,我已将此组件转成全部c#代码
收听端代码
RTPSession session;
RTPReceiver receiver;
RTPParticipant participant; WinSound.Player m_Player;
public Form1()
{
InitializeComponent();
m_Player = new WinSound.Player();
List<String> names = WinSound.WinSound.GetPlaybackNames();
m_Player.Open(names[], , , , );
} private void btnListen_Click(object sender, EventArgs e)
{
IPAddress ipaddr;
ushort usPort; if (!(IPAddress.TryParse(txtIp.Text, out ipaddr) && ushort.TryParse(txtPort.Text, out usPort)))
{
MessageBox.Show("IP地址或端口填写错误!");
return;
}
session = new RTPSession();
receiver = new RTPReceiver();
IPEndPoint rtpEp = new IPEndPoint(ipaddr, usPort); participant = new RTPParticipant(rtpEp);
session.NewRTPPacket = NewRTPPacket;
session.NewRTCPPacket = NewRTCPPacket;
receiver.AddParticipant(participant);
session.AddReceiver(receiver);
} bool NewRTPPacket(RTPPacket packet)
{
if (packet.DataPointer != null)
{
//Nach Linear umwandeln
Byte[] linearBytes = WinSound.Utils.MuLawToLinear(packet.DataPointer, , );
//Abspielen
m_Player.PlayData(linearBytes, false);
}
return true; }
全部源码可有偿提供