2

我正在编写 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)

有什么想法吗?

谢谢。

4

1 回答 1

1

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

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 会话的日志:

播放 Youtube RTSP:客户端 openrtsp

VLC 客户端播放 RTSP 流

于 2012-04-25T21:50:25.993 回答