2

我已经开始在 Android 中使用 Java 上的 RTP,并且想知道是否有人可以给我一些帮助或指导。

这是我开始的代码:

public void rtpTest() throws UnknownHostException, SocketException, RtpException{

RtpManager rtpManager = new RtpManager(myAddress);
Log.d("RTPMANAGER", "IPADDRESS here = " + rtpManager.getMyIpAddress());

tpSession rtpSession = rtpManager.createRtpSession(6040);
Log.d("RTPMANAGER", "IPADDRESS here 2");

rtpSession.addRtpListener(this);
Log.d("RTPMANAGER", "IPADDRESS here 3");

RtpPacketReceiver rtpPacketReciever = new RtpPacketReceiver(rtpSession);
Log.d("RTPMANAGER", "IPADDRESS here 4");


//DatagramSocket ds = new DatagramSocket(6042);
//ds.bind(null);

rtpSession.setRemoteIpAddress(getLocalIpAddress());
Log.d("RTPMANAGER", "IPADDRESS recv port = " + getLocalIpAddress() );

rtpSession.setRemoteRtpRecvPort(5060);

rtpSession.receiveRTPPackets();

Log.d("RTPMANAGER", "REMOTE - IPADDRESS = " + rtpSession.getRemoteIpAddress());

Log.d("RTPMANAGER", "Recieve port = " + rtpSession.getMyRtpRecvPort());
Log.d("RTPMANAGER", "Recieve socket = " + rtpSession.getRtpRecvSocket());

Log.d("RTPMANAGER", "RTP SESSION = " + rtpSession.toString());
Log.d("RTPMANAGER", "RTP PACKET RECEIVER = " + rtpPacketReciever.toString());

Log.d("RTPMANAGER", "RTP PACKET RECEIVER is alive? = " + rtpPacketReciever.isAlive());

rtpPacketReciever.run();
Log.d("RTPMANAGER", "RTP PACKET RECEIVER is alive? = " + rtpPacketReciever.isAlive());

Log.d("RTPMANAGER", "IPADDRESS here 5");

}

我不确定设置 RTP 管理器、RTP 会话和 RTP 数据包接收器的正确方法。

我是否需要先打开一个数据报套接字并将其链接到 RTP 会话?

当我从上面的代码中将 RTPSession 打印为字符串时,我得到以下信息:

RTP SESSION = <rtp-session
senderIpAddress = "192.168.2.xxx"
remoteRtpRecvPort = "5060"
myAddress = "192.168.2.xxx"
myRtpRecvPort = "6040"
/>

我不确定这是正确还是错误?

此外,代码只能到达 rtpPacketReciever.run(); 并停在那里,这个方法之后的日志永远不会被打印,所以我认为 rtpPacketReciever.run(); 有问题?

我对 RTP 非常陌生,因此任何人都知道的任何指导或良好资源都会非常有帮助。

提前致谢

编辑:

编辑:

我现在添加了这段代码:

代码:

DatagramSocket ds = rtpSession.getRtpRecvSocket();
ds.connect(InetAddress.getByName(getLocalIpAddress()), 3120);
Log.d("RTPMANAGER", "ds is bound to remote socket? " +ds.getRemoteSocketAddress());

记录 ds 远程套接字会返回以下内容:

ds is bound to remote socket: 192.168.2.163/192.168.2.163:3120

在我看来哪个不对?是吗?

4

1 回答 1

2

嗨,我认为您应该尝试端口 5004。您可以参考以下链接 http://www.networksorcery.com/enp/protocol/rtp.htm

于 2012-09-03T04:51:36.633 回答