How to force client to switch RTP transport from UDP to TCP?

29,606

Solution 1

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? =|

Solution 2

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).

Solution 3

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

Solution 4

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);

Solution 5

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.

Share:
29,606
Cipi
Author by

Cipi

Advanced EXP in: C#, C++, Java, Shell script, JavaScript Windows SDK, DirectShow Filters, COM Interfaces and Classes, COM in C# Web services, AJAX, JQuery, ExtJS HTTP, RTSP, RTP, NTP, SDP, TCP/IP, UDP Low level networking using Winsock H264, MPEG4 Android, Java ME, Java MMAPI AXIS, HIKVISION, VIVOTEK - IP Camera embedded software developing

Updated on November 25, 2020

Comments

  • Cipi
    Cipi over 3 years

    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?