用于从 IP 摄像机流式传输的 RTSP 和 RTP

RTSP and RTP for streaming from an IP Camera

我有一个简单的 c# 应用程序,它打开一个 RTSP 会话并发送适当的命令(如 DESCRIBE、SETUP 等)来控制 RTP 数据流。

我的问题是:在通过 RTP 传输数据时,TCP 会话(用于 RTSP 通信)是否必须保持打开状态?无需详细说明原因,我希望能够在设置 RTP 流后关闭 RTSP 会话。

简短的回答是肯定的,您必须保持 rtsp 套接字打开。

如果流是通过 TCP 传输的,RTP 数据包将通过 RTSP 会话的套接字传输。如果流是通过 UDP 的,则服务器使用套接字来知道它是否应该继续向客户端发送数据包,因为如果客户端还活着,UDP 数据包传输没有任何反馈。

已编辑:

我认为标记为正确的答案实际上是不正确的。一般来说,摄像机执行 RTSP 协议版本 1 而不是版本 2。在我 10 年的视频监控系统经验中,我发现有几种型号的摄像机在关闭 RTSP 会话套接字后停止发送 RTP 数据包。

RFC 7826 Real-Time Streaming Protocol Version 2.0

A persistent connection is RECOMMENDED to be used for all
transactions between the server and client, including messages for
multiple RTSP sessions. However, a persistent connection MAY be
closed after a few message exchanges. For example, a client may use
a persistent connection for the initial SETUP and PLAY message
exchanges in a session and then close the connection. Later, when
the client wishes to send a new request, such as a PAUSE for the
session, a new connection would be opened. This connection may be
either transient or persistent.

所以不,流数据时不需要打开。