RTSP服务器java实现问题:(

时间:2012-04-25 19:29:29

标签: java rtsp vlc

我正在编写RTSP服务器并遇到一些问题。 我正在使用VLC作为客户端。

服务器从客户端(VLC播放器)接收OPTIONS,DESCRIBE,SETUP和PLAY命令以及该命令的答案。

通过SETUP命令,客户端发送端口号,我正在使用该端口发送数据。 当我的服务器收到PLAY命令时,它会发送答案并开始传输数据。我正在使用客户端端口创建两个DatagramSocket实例。

我正在尝试流式传输mp4文件。 我正在使用mp4parse java库来获取要传输的音频和视频轨道数据。

所以,当我点击VLC上的播放时,它正在连接并开始等待数据,几秒钟之后我在VLC消息中收到了这条消息:

live555 warning: no data received in 10s. Switching to TCP

这是我的SDP数据:

v=0
o=- 0 0 IN IP4 127.0.0.1
m=video 0 RTP/AVP 96
b=AS:1633
a=rtpmap:96 H264/90000
a=control:trackID=65536
a=fmtp:96 profile-level-id=64001F; packetization-mode=1; sprop-parameter-sets=Z2QAH6zZgFAFuhAAAAMAEAAAAwMg8YMZoA==,aOl7LIs=
a=framesize:96 1280-720
m=audio 0 RTP/AVP 97
b=AS:129
a=rtpmap:97 mpeg4-generic/48000/2
a=control:trackID=65537
a=fmtp:97 profile-level-id=41; config=1190; streamType=5; mode=AAC-hbr; objectType=64; constantDuration=1024; sizeLength=13; indexLength=3; indexDeltaLength=3

另外,我正在使用jlibrtp创建RTP数据包并发送它们。

这是服务器 - 客户端通信日志:

+++++++CLIENT+S++++++++++
OPTIONS rtsp://127.0.0.1:4444/aaa RTSP/1.0
CSeq: 2
User-Agent: LibVLC/2.0.1 (LIVE555 Streaming Media v2011.12.23)
+++++++CLIENT+E++++++++++
+++++++SERVER+S++++++++++
RTSP/1.0 200 OK
CSeq: 2
Public: DESCRIBE, SETUP, TEARDOWN, PLAY, PAUSE

+++++++SERVER+E++++++++++
+++++++CLIENT+S++++++++++
DESCRIBE rtsp://127.0.0.1:4444/aaa RTSP/1.0
CSeq: 3
User-Agent: LibVLC/2.0.1 (LIVE555 Streaming Media v2011.12.23)
Accept: application/sdp
+++++++CLIENT+E++++++++++
+++++++SERVER+S++++++++++
RTSP/1.0 200 OK
CSeq: 3
Content-Type: application/sdp

v=0
o=- 0 0 IN IP4 127.0.0.1
m=video 0 RTP/AVP 96
b=AS:1633
a=rtpmap:96 H264/90000
a=control:trackID=65536
a=fmtp:96 profile-level-id=64001F; packetization-mode=1; sprop-parameter-sets=Z2QAH6zZgFAFuhAAAAMAEAAAAwMg8YMZoA==,aOl7LIs=
a=framesize:96 1280-720
m=audio 0 RTP/AVP 97
b=AS:129
a=rtpmap:97 mpeg4-generic/48000/2
a=control:trackID=65537
a=fmtp:97 profile-level-id=41; config=1190; streamType=5; mode=AAC-hbr; objectType=64; constantDuration=1024; sizeLength=13; indexLength=3; indexDeltaLength=3

+++++++SERVER+E++++++++++
+++++++CLIENT+S++++++++++
SETUP rtsp://127.0.0.1:4444/aaa/trackID=65536 RTSP/1.0
CSeq: 4
User-Agent: LibVLC/2.0.1 (LIVE555 Streaming Media v2011.12.23)
Transport: RTP/AVP;unicast;client_port=59298-59299
+++++++CLIENT+E++++++++++
+++++++SERVER+S++++++++++
RTSP/1.0 200 OK
CSeq: 4
Transport: RTP/AVP;unicast;client_port=59298-59299
Session: 00007689

+++++++SERVER+E++++++++++
+++++++CLIENT+S++++++++++
SETUP rtsp://127.0.0.1:4444/aaa/trackID=65537 RTSP/1.0
CSeq: 5
User-Agent: LibVLC/2.0.1 (LIVE555 Streaming Media v2011.12.23)
Transport: RTP/AVP;unicast;client_port=62520-62521
Session: 00007689
+++++++CLIENT+E++++++++++
+++++++SERVER+S++++++++++
RTSP/1.0 200 OK
CSeq: 5
Transport: RTP/AVP;unicast;client_port=62520-62521
Session: 00007689

+++++++SERVER+E++++++++++
+++++++CLIENT+S++++++++++
PLAY rtsp://127.0.0.1:4444/aaa RTSP/1.0
CSeq: 6
User-Agent: LibVLC/2.0.1 (LIVE555 Streaming Media v2011.12.23)
Session: 00007689
Range: npt=0.000-
+++++++CLIENT+E++++++++++
+++++++SERVER+S++++++++++
RTSP/1.0 200 OK
CSeq: 6

+++++++SERVER+E++++++++++
Streaming...
+++++++CLIENT+S++++++++++
TEARDOWN rtsp://127.0.0.1:4444/aaa RTSP/1.0
CSeq: 7
User-Agent: LibVLC/2.0.1 (LIVE555 Streaming Media v2011.12.23)
Session: 00007689
+++++++CLIENT+E++++++++++
+++++++SERVER+S++++++++++
RTSP/1.0 200 OK
CSeq: 7

+++++++SERVER+E++++++++++
Exception in thread "main" java.net.SocketException: Connection reset
    at java.net.SocketInputStream.read(SocketInputStream.java:168)
    at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:264)
    at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:306)
    at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:158)
    at java.io.InputStreamReader.read(InputStreamReader.java:167)
    at java.io.BufferedReader.fill(BufferedReader.java:136)
    at java.io.BufferedReader.readLine(BufferedReader.java:299)
    at java.io.BufferedReader.readLine(BufferedReader.java:362)
    at com.vtgsoftwares.ekiz.server.RTSPServer.<init>(RTSPServer.java:71)
    at com.vtgsoftwares.ekiz.server.RTSPServer.main(RTSPServer.java:80)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)

有什么想法吗?

感谢。

1 个答案:

答案 0 :(得分:1)

服务器日志中的RTSP对等体应该在客户端发送RTSP SETUP请求后同意“传输”作为协议的一部分...

Received 360 new bytes of response data.
Received a complete SETUP response:
RTSP/1.0 200 OK
Session: 70cd7f38;timeout=90
Transport: RTP/AVP;unicast;mode=play;client_port=64498-64499;server_port=10580-10581;source=74.125.212.247;ssrc=50DF166F

您的服务器日志应显示同意RTCP的端口集(C / S)和协议的数据部分的对等方。

猜测是你的VLC客户端不知道在哪里找到要读取的数据流...即我应该等待哪个端口(可读取的数据)。

来自一些成功的RTSP会话的日志:

Play Youtube RTSP:客户端openrtsp

VLC client Play RTSP stream