Rtspsrc keep-alive behavior with TCP vs. UDP

I’m investigating the keep-alive functionality of the rtspsrc element in GStreamer. Specifically, I’m observing a discrepancy in behavior between UDP and TCP transport.

The rtspsrc element has a property do-rtsp-keep-alive that’s intended to periodically send RTSP GET_PARAMETER requests to maintain the RTSP connection.
This functionality works correctly when receiving data over UDP. However, when receiving data over TCP, the keep-alive mechanism appears to fail.

Root Cause (as understood):

Upon examining the GStreamer code, I’ve noticed that gst_rtspsrc_send_keep_alive() is triggered only when rtspsrc hasn’t received any messages from the server within a specified timeout period.

UDP: This timeout condition is met because RTP data packets are transmitted over a separate connection, allowing the RTSP connection to remain idle.
TCP: In TCP mode, data is received continuously over the same connection, preventing the timeout condition from being met. Consequently, keep-alive requests are never sent.

Questions/Concerns:

  • I’d like to understand the reason for different behavior between TCP and UDP in the rtspsrc plugin.

  • Some RTSP servers (e.g., cameras) require keep-alive requests even when using TCP, or they will terminate the RTSP connection, so keep-alive is required for some cases.

  • While the get-parameters action signal can be used as a workaround, it’s not a viable solution for gst-launch based pipelines.

Would modifying the rtspsrc plugin to send keep-alive requests for TCP streams be an acceptable solution for the GStreamer community?
I noted that GStreamer 1.16 exhibited different behavior, sending keep-alive requests even for TCP streams. Why was this changed?

That doesn’t sound like an intentional change. Can you maybe git bisect it, or at least check between which major release (1.16, 1.18, 1.20, …, 1.26) this changed?

Also this should really be tracked in a gitlab issue.

This behaviour changed started with - 1.17.1

This keep-alive was removed with -

https://bugzilla.gnome.org/show_bug.cgi?id=744209

That bugzilla ticket is moved to rtspsrc: May stop sending keep alive due to buggy timeout in rtspconnection (#159) · Issues · GStreamer / gst-plugins-good · GitLab and no changes related to it were merged AFAICS.

This commit removed the keep-alive -

I believe the keep-alive was removed because of ONVIF specification about keep-alive

5.2.2.2 Timeout and keep-alive handling
• A server shall interpret any RTSP request other than TEARDOWN as a keep-alive.
• A server shall interpret any RTCP receiver report for a unicast stream as keep-alive for the RTSP
session.

Still some camera may not follow specification.