Search code examples
network-programminggstreamerrtsp

RTSP: RTP uses the same port as RTSP


It really isn't a problem but I would like to hear from the community about this "strange" phenomenon or at least it seems to me.

I have written an RTSP application that streams video and audio (as RTP payload 96 and 97 respectively)

RTSP client make connection and setup and play correctly (the video could be seen over the client end). What I am bother about is that RTP (video and audio) is send out through TCP (through port 554). Yah I know its correct behaviour but I quite confuse that it uses the same port as RTSP (port 554). I have always have the idea that RTSP would have a static port number and after RTSP connection is established, client would then negotiate the RTP/RTCP connection with server (which will results in creation of additional port (4 in my case). However, it seem that all RTP/RTSP/RTCP traffic is tunneled through the same port (or I have misinterpreted the result)

Below is the rtsp transaction captured by wireshark

C->S (video payload)
SETUP rtsp://192.168.22.33:554/MOVIE/stream=0 RTSP/1.0
CSeq: 3
Transport: RTP/AVP/TCP;unicast;interleaved=0-1
User-Agent: happytimesoft rtsp client

S->C (video payload ok)
RTSP/1.0 200 OK
CSeq: 3
Transport: RTP/AVP/TCP;unicast;interleaved=0-1;ssrc=7C0EAE5B;mode="PLAY"
Server: GStreamer RTSP server
Session: -8lIe87._f3qX4.h
Date: Wed, 24 Mar 2021 15:23:22 GMT

C->S (audio payload)
SETUP rtsp://192.168.22.33:554/MOVIE/stream=1 RTSP/1.0
CSeq: 4
Session: -8lIe87._f3qX4.h
Transport: RTP/AVP/TCP;unicast;interleaved=2-3
User-Agent: happytimesoft rtsp client

S->C (audio payload)
RTSP/1.0 200 OK
CSeq: 4
Transport: RTP/AVP/TCP;unicast;interleaved=2-3;ssrc=2E0ECCA6;mode="PLAY"
Server: GStreamer RTSP server
Session: -8lIe87._f3qX4.h
Date: Wed, 24 Mar 2021 15:23:22 GMT

C->S
PLAY rtsp://192.168.22.33:554/MOVIE/ RTSP/1.0
CSeq: 5
Session: -8lIe87._f3qX4.h
Range: npt=0.000-
User-Agent: happytimesoft rtsp client

After which it plays with both of the payload into one port

Package played

Is my interpretation correct? Is there any problem of sending all communication via one port (albeit latency)? Or is there any chances that the packets might be rerouted?

Thanks

https://www.rfc-editor.org/rfc/rfc2326.txt


Solution

  • RTSP/RTP has several sending modes. Your client explicitly requests for RTSP interleaving - where RTP data gets send interleaved in the RTSP channel. That a nice fallback for firewall restricted environments. If you don't request this RTP channels should be send over their individual UDP ports.