Reputation: 355
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?
Upvotes: 3
Views: 4343
Reputation: 21
Call gst_rtsp_server_client_filter() when need to close RTSP server (before server deletion):
GstRTSPFilterResult clientFilterFunc(GstRTSPServer* server, GstRTSPClient* client, gpointer user)
{
return GST_RTSP_FILTER_REMOVE;
}
. . .
{
. . .
if( clientCount )
gst_rtsp_server_client_filter(server, clientFilterFunc, nullptr);
if (G_IS_OBJECT(server))
{
g_object_unref(server);
server = nullptr;
}
. . .
}
Code snipped for client connection and close: {
void clientClosed(GstRTSPClient* client, gpointer user)
{
--clientCount ;
std::stringstream strm;
strm << "Client closed ... count: " << ptrTestData->m_clientCount << std::endl;
g_print("%s", strm.str().c_str());
}
void clientConnected(GstRTSPServer* server, GstRTSPClient* client, gpointer user)
{
++clientCount ;
// hook the client close callback
g_signal_connect(client, "closed", reinterpret_cast<GCallback>(clientClosed), user);
std::stringstream strm;
strm << "Client connected ... count: " << ptrTestData->m_clientCount << std::endl;
g_print("%s", strm.str().c_str());
}
{
. . .
g_signal_connect(server, "client-connected", reinterpret_cast<GCallback>(clientConnected), &(testData));
. . .
}
}
Upvotes: 2
Reputation: 355
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.
Upvotes: 0