gstreamerrtsprtsp-client

gst-rtsp-server: detect client disconnect


I am implementing a video streaming pipeline using gst-rtsp-server. I need to know when an RTSP client both connects and disconnects.

From the examples provided with gst-rtsp-server, I can detect a client connecting using the "client-connected" signal of the GstRTSPServer. I'm looking for something similar for when the client disconnects.

I have tried the "closed" and "teardown-request" signals of GstRTSPClient, but those don't do anything when I disconnect the client.

I have also tried calling the following function on a timer, like it is done in several examples. I would expect that to print "Removed 1 sessions" at some point after I've terminated the client, but it never does.

static gboolean
remove_sessions (GstRTSPServer * server)
{
  GstRTSPSessionPool *pool;

  pool = gst_rtsp_server_get_session_pool (server);
  guint removed = gst_rtsp_session_pool_cleanup (pool);
  g_object_unref (pool);
  g_print("Removed %d sessions\n", removed);

  return TRUE;
}

My client is the following gstreamer pipeline:

gst-launch-1.0 -v rtspsrc location=rtsp://$STREAM_IP:8554/test latency=50 ! queue ! rtph264depay ! queue ! avdec_h264 ! autovideosink sync=false

How can I detect client disconnections?


Solution

  • Not sure what problems I had before, but this actually works:

    When the client is shut down (Ctrl+C on the gst-launch-1.0 pipeline), the "teardown-request" signal of GstRTSPClient is emitted.

    If the client loses connection to the server, the remove_sessions (GstRTSPServer * server) function I posted will report that it removed a session after some time.