Receiving RTSP stream over TCP

146 views
Skip to first unread message

Béranger Kabbas

unread,
Dec 19, 2018, 11:43:31 AM12/19/18
to meetecho-janus
Hello, i'm trying to view RTSP streams that are coming from a SharpRTSP Server
The RTSP streams are correctly viewable in VLC or webrtc-streamer project because i suppose these solutions implement fallbacks from a protocol to another.
We tried to debug at SharpRTSP Server side and saw that SharpRTSP receive a SETUP with UDP protocol negociation, the problem is that the UDP protocol is not implemented at SharpRTSP side,
is janus capable of fallbacking to TCP or directly requesting in TCP ?


```
Creating new session: 613076985734297; 0x7fe8b8001a90
Creating new handle in session 613076985734297: 5897493383955881; 0x7fe8b8001a90 0x7fe8b80024e0
[5897493383955881] Creating ICE agent (ICE Full mode, controlling)
[5897493383955881] The DTLS handshake has been completed
[janus.plugin.streaming-0x7fe8b8002070] WebRTC media is now available
[WARN] [3139748193066770] 5s passed with no media, trying to reconnect the RTSP stream
[3139748193066770] Reconnected to the RTSP server, streaming again
[WARN] [3139748193066770] 5s passed with no media, trying to reconnect the RTSP stream
[3139748193066770] Reconnected to the RTSP server, streaming again
[WARN] [3139748193066770] 5s passed with no media, trying to reconnect the RTSP stream
[3139748193066770] Reconnected to the RTSP server, streaming again
[WARN] [3139748193066770] 5s passed with no media, trying to reconnect the RTSP stream
[3139748193066770] Reconnected to the RTSP server, streaming again
```

Thanks

Béranger Kabbas

unread,
Dec 19, 2018, 11:48:40 AM12/19/18
to meetecho-janus
Here is the code sample from SharpRTSP that handle the transport

```
           // Check the RTSP transport
            // If it is UDP or Multicast, create the sockets
            // If it is RTP over RTSP we send data via the RTSP Listener

            // FIXME client may send more than one possible transport.
            // very rare
            Rtsp.Messages.RtspTransport transport = setupMessage.GetTransports()[0];


            // Construct the Transport: reply from the Server to the client
            Rtsp.Messages.RtspTransport transport_reply = new Rtsp.Messages.RtspTransport();
            transport_reply.SSrc = global_ssrc.ToString("X8"); // Convert to Hex, padded to 8 characters

            if (transport.LowerTransport == Rtsp.Messages.RtspTransport.LowerTransportType.TCP)
            {
                // RTP over RTSP mode}
                transport_reply.LowerTransport = Rtsp.Messages.RtspTransport.LowerTransportType.TCP;
                transport_reply.Interleaved = new Rtsp.Messages.PortCouple(transport.Interleaved.First, transport.Interleaved.Second);
            }

            if (transport.LowerTransport == Rtsp.Messages.RtspTransport.LowerTransportType.UDP
                && transport.IsMulticast == false)
            {
                // RTP over UDP mode}
                // Create a pair of UDP sockets
                // Pass the Port of the two sockets back in the reply
                transport_reply.LowerTransport = Rtsp.Messages.RtspTransport.LowerTransportType.UDP;
                transport_reply.IsMulticast = false;
                transport_reply.ClientPort = transport.ClientPort;  // FIX
//transport_reply.ServerPort = new Rtsp.Messages.PortCouple(16384, 32767);
var firstPort = GetAvailablePort(16384, 32767);
var secondPort = GetAvailablePort(firstPort + 1, 32767);
transport_reply.ServerPort = new Rtsp.Messages.PortCouple(firstPort, secondPort);
//UDPSocket
// for now until implemented
                transport_reply = null;
            }

            if (transport.LowerTransport == Rtsp.Messages.RtspTransport.LowerTransportType.UDP
                && transport.IsMulticast == true)
            {
                // RTP over Multicast UDP mode}
                // Create a pair of UDP sockets in Multicast Mode
                // Pass the Ports of the two sockets back in the reply
                transport_reply.LowerTransport = Rtsp.Messages.RtspTransport.LowerTransportType.UDP;
                transport_reply.IsMulticast = true;
                transport_reply.Port = new Rtsp.Messages.PortCouple(7000, 7001);  // FIX

                // for now until implemented
                transport_reply = null;
            }


            if (transport_reply != null)
            {

                RTPSession new_session = new RTPSession();
new_session.rtspLink = setupMessage.RtspUri.AbsolutePath;
                new_session.listener = listener;
                new_session.sequence_number = (UInt16)rnd.Next(65535); // start with a random 16 bit sequence number
                new_session.ssrc = global_ssrc;

                // Add the transports to the Session
                new_session.client_transport = transport;
                new_session.transport_reply = transport_reply;

                lock (rtp_list)
                {
                    // Create a 'Session' and add it to the Session List
                    // ToDo - Check the Track ID. In the SDP the H264 video track is TrackID 0
                    // Place Lock() here so the Session Count and the addition to the list is locked
                    new_session.session_id = session_count.ToString();

                    // Add the new session to the Sessions List
                    rtp_list.Add(new_session);
                    session_count++;
                }


                Rtsp.Messages.RtspResponse setup_response = setupMessage.CreateResponse();
                setup_response.Headers[Rtsp.Messages.RtspHeaderNames.Transport] = transport_reply.ToString();
                setup_response.Session = new_session.session_id;
                listener.SendMessage(setup_response);
            }
            else
            {
                Rtsp.Messages.RtspResponse setup_response = setupMessage.CreateResponse();
                // unsuported transport
                setup_response.ReturnCode = 461;
                listener.SendMessage(setup_response);
            }
```

As you can see there is a "not implemented" comment, but it still sends a reply with code 461 (transport not supported)

lmin...@gmail.com

unread,
Dec 19, 2018, 11:52:53 AM12/19/18
to meetecho-janus
As clearly explained in the guidelines, PLEASE NO HUGE BUNCHES OF TEXT INLINE, *especially* code. Use pastebin/gist instead.
We don't support TCP in the Streaming plugin, and I don't expect we will anytime soon as we have other priorities. Pull requests welcome of course.

Lorenzo

lmin...@gmail.com

unread,
Dec 19, 2018, 11:54:01 AM12/19/18
to meetecho-janus
As a side note, you can try putting live555 between Janus and SharpRTSP to see if it can take care of the TCP-to-UDP translation for you.

L.

Béranger Kabbas

unread,
Dec 19, 2018, 11:58:23 AM12/19/18
to meetecho-janus
Thank you for the reply


Le mercredi 19 décembre 2018 17:43:31 UTC+1, Béranger Kabbas a écrit :

Béranger Kabbas

unread,
Dec 21, 2018, 9:16:43 AM12/21/18
to meetecho-janus
Lorenzo, i'm wondering if you have any guideline on how I can implement TCP communication for rtsp streaming, and where should I start ?

Thanks

Béranger Kabbas

unread,
Dec 21, 2018, 9:42:21 AM12/21/18
to meetecho-janus
By the way, I did put Live555 between Janus & SharpRTSP but it is still not working even though Live555 is correctly demanding TCP to SharpRTSP but janus is still not showing anything
Reply all
Reply to author
Forward
0 new messages