From: Branko Subasic Date: Fri, 19 Sep 2014 16:28:50 +0000 (+0200) Subject: rtsp-*: Treat sending packets to clients as keepalive X-Git-Tag: 1.19.3~495^2~743 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=2218510cae291dca6f27920583729f8cfaf276ff;p=platform%2Fupstream%2Fgstreamer.git rtsp-*: Treat sending packets to clients as keepalive As long as gst-rtsp-server can successfully send RTP/RTCP data to clients then the client must be reading. This change makes the server timeout the connection if the client stops reading. Fixes https://bugzilla.gnome.org/show_bug.cgi?id=736647 --- diff --git a/gst/rtsp-server/rtsp-client.c b/gst/rtsp-server/rtsp-client.c index 3d4ce91..40295fe 100644 --- a/gst/rtsp-server/rtsp-client.c +++ b/gst/rtsp-server/rtsp-client.c @@ -691,6 +691,7 @@ do_send_data (GstBuffer * buffer, guint8 channel, GstRTSPClient * client) { GstRTSPClientPrivate *priv = client->priv; GstRTSPMessage message = { 0 }; + GstRTSPResult res = GST_RTSP_OK; GstMapInfo map_info; guint8 *data; guint usize; @@ -705,7 +706,7 @@ do_send_data (GstBuffer * buffer, guint8 channel, GstRTSPClient * client) g_mutex_lock (&priv->send_lock); if (priv->send_func) - priv->send_func (client, &message, FALSE, priv->send_data); + res = priv->send_func (client, &message, FALSE, priv->send_data); g_mutex_unlock (&priv->send_lock); gst_rtsp_message_steal_body (&message, &data, &usize); @@ -713,7 +714,7 @@ do_send_data (GstBuffer * buffer, guint8 channel, GstRTSPClient * client) gst_rtsp_message_unset (&message); - return TRUE; + return res == GST_RTSP_OK; } /** diff --git a/gst/rtsp-server/rtsp-session.c b/gst/rtsp-server/rtsp-session.c index 372746a..1f4b650 100644 --- a/gst/rtsp-server/rtsp-session.c +++ b/gst/rtsp-server/rtsp-session.c @@ -58,6 +58,7 @@ struct _GstRTSPSessionPrivate guint timeout; gboolean timeout_always_visible; GTimeVal create_time; /* immutable */ + GMutex last_access_lock; GTimeVal last_access; gint expire_count; @@ -132,6 +133,7 @@ gst_rtsp_session_init (GstRTSPSession * session) GST_INFO ("init session %p", session); g_mutex_init (&priv->lock); + g_mutex_init (&priv->last_access_lock); priv->timeout = DEFAULT_TIMEOUT; g_get_current_time (&priv->create_time); gst_rtsp_session_touch (session); @@ -153,6 +155,7 @@ gst_rtsp_session_finalize (GObject * obj) /* free session id */ g_free (priv->sessionid); + g_mutex_clear (&priv->last_access_lock); g_mutex_clear (&priv->lock); G_OBJECT_CLASS (gst_rtsp_session_parent_class)->finalize (obj); @@ -555,9 +558,9 @@ gst_rtsp_session_touch (GstRTSPSession * session) priv = session->priv; - g_mutex_lock (&priv->lock); + g_mutex_lock (&priv->last_access_lock); g_get_current_time (&priv->last_access); - g_mutex_unlock (&priv->lock); + g_mutex_unlock (&priv->last_access_lock); } /** @@ -608,7 +611,7 @@ gst_rtsp_session_next_timeout (GstRTSPSession * session, GTimeVal * now) priv = session->priv; - g_mutex_lock (&priv->lock); + g_mutex_lock (&priv->last_access_lock); if (g_atomic_int_get (&priv->expire_count) != 0) { /* touch session when the expire count is not 0 */ g_get_current_time (&priv->last_access); @@ -617,7 +620,7 @@ gst_rtsp_session_next_timeout (GstRTSPSession * session, GTimeVal * now) last_access = GST_TIMEVAL_TO_TIME (priv->last_access); /* add timeout allow for 5 seconds of extra time */ last_access += priv->timeout * GST_SECOND + (5 * GST_SECOND); - g_mutex_unlock (&priv->lock); + g_mutex_unlock (&priv->last_access_lock); now_ns = GST_TIMEVAL_TO_TIME (*now); diff --git a/gst/rtsp-server/rtsp-stream-transport.c b/gst/rtsp-server/rtsp-stream-transport.c index cd0a143..c69de26 100644 --- a/gst/rtsp-server/rtsp-stream-transport.c +++ b/gst/rtsp-server/rtsp-stream-transport.c @@ -456,6 +456,9 @@ gst_rtsp_stream_transport_send_rtp (GstRTSPStreamTransport * trans, priv->send_rtp (buffer, priv->transport->interleaved.min, priv->user_data); + if (res) + gst_rtsp_stream_transport_keep_alive (trans); + return res; } @@ -482,6 +485,9 @@ gst_rtsp_stream_transport_send_rtcp (GstRTSPStreamTransport * trans, priv->send_rtcp (buffer, priv->transport->interleaved.max, priv->user_data); + if (res) + gst_rtsp_stream_transport_keep_alive (trans); + return res; }