rtsp-session: Handle the case when timeout=0
authorJonathan Karlsson <jonakn@axis.com>
Wed, 9 Aug 2017 09:52:38 +0000 (11:52 +0200)
committerSebastian Dröge <sebastian@centricular.com>
Wed, 15 Nov 2017 15:20:33 +0000 (17:20 +0200)
According to the documentation, a timeout of value 0 means
that the session never timeouts. This adds handling of that.
If timeout=0 we just return with a -1 from
gst_rtsp_session_next_timeout_usec ().

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

gst/rtsp-server/rtsp-session.c
tests/check/gst/rtspserver.c

index e6faaf5..e8fd68b 100644 (file)
@@ -69,6 +69,7 @@ struct _GstRTSPSessionPrivate
 #undef DEBUG
 
 #define DEFAULT_TIMEOUT               60
+#define NO_TIMEOUT              -1
 #define DEFAULT_ALWAYS_VISIBLE  FALSE
 
 enum
@@ -634,6 +635,14 @@ gst_rtsp_session_next_timeout_usec (GstRTSPSession * session, gint64 now)
 
   priv = session->priv;
 
+  g_mutex_lock (&priv->lock);
+  /* If timeout is set to 0, we never timeout */
+  if (priv->timeout == 0) {
+    g_mutex_unlock (&priv->lock);
+    return NO_TIMEOUT;
+  }
+  g_mutex_unlock (&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 */
index 1a92d52..7f636f5 100644 (file)
@@ -1559,6 +1559,27 @@ GST_START_TEST (test_play_multithreaded_timeout_session)
 GST_END_TEST;
 
 
+GST_START_TEST (test_no_session_timeout)
+{
+  GstRTSPSession *session;
+  gint64 now;
+  gboolean is_expired;
+
+  session = gst_rtsp_session_new ("test-session");
+  gst_rtsp_session_set_timeout (session, 0);
+
+  now = g_get_monotonic_time ();
+  /* add more than the extra 5 seconds that are usually added in
+   * gst_rtsp_session_next_timeout_usec */
+  now += 7000000;
+
+  is_expired = gst_rtsp_session_is_expired_usec (session, now);
+  fail_unless (is_expired == FALSE);
+}
+
+GST_END_TEST;
+
+
 GST_START_TEST (test_play_disconnect)
 {
   GstRTSPConnection *conn;
@@ -2118,6 +2139,7 @@ rtspserver_suite (void)
   tcase_add_test (tc, test_play_multithreaded_block_in_describe);
   tcase_add_test (tc, test_play_multithreaded_timeout_client);
   tcase_add_test (tc, test_play_multithreaded_timeout_session);
+  tcase_add_test (tc, test_no_session_timeout);
   tcase_add_test (tc, test_play_disconnect);
   tcase_add_test (tc, test_play_specific_server_port);
   tcase_add_test (tc, test_play_smpte_range);