如何强制客户端将 RTP 传输从 UDP 切换为 TCP?

发布于 2024-08-24 05:30:09 字数 195 浏览 6 评论 0原文

如果客户端想要观看 RTSP 服务器上的流,它首先尝试通过 UDP 协议设置流。我如何告诉它我的服务器仅支持 RTP/AVP/TCP 并且它应该切换传输?

我想终止我的服务器上的 UDP 支持,但所有客户端首先尝试通过 UDP 建立会话,然后通过 TCP 进行设置...我想在 RTSP 协议中尽快将它们切换到 TCP。

我怎样才能做到这一点?

If the client wants to watch a stream that is on my RTSP server, it first tries to setup a stream through the UDP protocol. How can I tell it that my server only supports RTP/AVP/TCP and that it should switch transports?

I want to terminate the UDP support on my server, but all the clients first try to SETUP the session over UDP, and later they do so over TCP... and I want to switch them to TCP as soon as possible in RTSP protocol.

How can I do that?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

蓝戈者 2024-08-31 05:30:09

据我所知,服务器端没有对传输类型首选项的控制。服务器应该是通用的,它应该支持 RTP over UDP、RTP over TCP、RTP over RTSP 和 RTP over RTSP over HTTP(S)。其客户可以选择选择哪种运输方式。传输字段首先在 SETUP 请求中发送

1) UDP

 C->A: SETUP rtsp://audio.example.com/twister/audio.en RTSP/1.0
               CSeq: 1
               Transport: RTP/AVP/UDP;unicast;client_port=3056-3057

2) TCP

    C->A: SETUP rtsp://audio.example.com/twister/audio.en RTSP/1.0
               CSeq: 1
               Transport: RTP/AVP/TCP;unicast;client_port=3056-3057

3) RTP over RTSP 和 RTP over RTSP over HTTP(S)

S->C: RTSP/1.0 200 OK
           CSeq: 2
           Date: 05 Jun 1997 18:57:18 GMT
           Transport: RTP/AVP/TCP;interleaved=0-1

我们可以看到“传输类型”请求是由客户端发送的。

如果您想仅支持 TCP 服务器,您可以按照您的建议发送“400 Bad Request”或“461 Unsupported Transport”来响应 SETUP 请求,或者另一种方法是发送 200 OK 但不传输任何 RTP 数据包。客户端将超时并知道它位于代理之后,并将再次使用 RTP/AVP/TCP 参数发送 SETUP 请求(不是理想情况)。

As far as I know, there is no control at server side for transport type preference. Server should be made generic it should support RTP over UDP, RTP over TCP, RTP over RTSP and RTP over RTSP over HTTP(S). And its clients choice which transport to choose. Transport field is first sent in SETUP request

1) UDP

 C->A: SETUP rtsp://audio.example.com/twister/audio.en RTSP/1.0
               CSeq: 1
               Transport: RTP/AVP/UDP;unicast;client_port=3056-3057

2) TCP

    C->A: SETUP rtsp://audio.example.com/twister/audio.en RTSP/1.0
               CSeq: 1
               Transport: RTP/AVP/TCP;unicast;client_port=3056-3057

3) RTP over RTSP and RTP over RTSP over HTTP(S)

S->C: RTSP/1.0 200 OK
           CSeq: 2
           Date: 05 Jun 1997 18:57:18 GMT
           Transport: RTP/AVP/TCP;interleaved=0-1

As we can see "Transport type" request is sent by client side.

If you want to support TCP only server you can send "400 Bad Request" or "461 Unsupported transport" in response to SETUP request as suggested by you or another way is to send 200 OK but do not transmit any RTP packets. Client will timeout and get to know that it is behind proxy and it will send SETUP request again with RTP/AVP/TCP parameter (Not an ideal case).

っ左 2024-08-31 05:30:09

为了扩展 android 的答案,
对于 Android 客户端,它们始终会首先尝试建立 UDP 连接。

对于 OpenCore 和 StageFright,我可以确认,如果我从服务器返回“461 Unsupported Transport”以响应 UDP 传输的第一个 SETUP 请求,则这两个客户端将立即尝试通过 RTSP 端口建立基于 TCP 的连接。

所有其他回复详细信息如下:http://www.ietf.org/rfc/rfc2326.txt< /a>

To expand on the answer for android,
For Android clients, they will always attempt to establish a UDP connection first.

For both OpenCore and StageFright I can confirm that if I return "461 Unsupported Transport" from my server in response to the first SETUP request for UDP transfer, both of these clients will then IMMEDIATELY attempt to establish a TCP based connection over the RTSP port.

All other responses are detailed here: http://www.ietf.org/rfc/rfc2326.txt

人海汹涌 2024-08-31 05:30:09

好的一种方法是发送“400 Bad Request”作为对客户端 SETUP 请求的响应......并且它会自动切换到 TCP 协议。这适用于 RealOne 和 QuickTime。

但我不确定它是否适用于所有其他玩家,因为这是一个黑客行为。

还有其他想法吗? =|

OK one way is to send "400 Bad Request" as the response to the client's SETUP request... and it automatically switches to TCP protocol. This is for RealOne and QuickTime.

But I am not sure that it will work on all other players since this is a hack.

Any other ideas? =|

倚栏听风 2024-08-31 05:30:09

如果你使用了ffmpeg,可以强制切换rtsp传输层协议。

av_dict_set(&format_opts, "rtsp_transport", "tcp", 0);
err = avformat_open_input(&ic, is->filename, is->iformat, &format_opts);

If you used ffmpeg, you can force switch rtsp transport layer protocol.

av_dict_set(&format_opts, "rtsp_transport", "tcp", 0);
err = avformat_open_input(&ic, is->filename, is->iformat, &format_opts);
徒留西风 2024-08-31 05:30:09

什么客户端连接到您的服务器?有些客户端可以通过URL中的URI方法来触发。例如,您可以指定 rtspt://myhost/path.sdp。

如果您可以控制客户端/服务器,则可以在客户端上使用 Require 标头,在服务器上使用 Unsupported 标头来指示不支持 UDP;但我见过的大多数客户都不使用这个。

What client connects to your server? Some clients can be triggered through the URI method in the URL. For example, you could specify rtspt://myhost/path.sdp.

If you have control over client/servers you could use the Require header on clients and Unsupported on servers to indicate that UDP isn't supported; but most clients I've seen don't use this.

佼人 2024-08-31 05:30:09

您可以尝试在对Describe请求的响应中传递“传输”标头,并在那里声明您的服务器仅支持RTP/AVP/TCP传输,并且客户端应该知道不支持UDP。

You can try to pass "transport" header in a response to Describe request, and state there that your server only supports RTP/AVP/TCP transport, and the client should know that UDP is unsupported.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文