rtspsrc: Do not wait for response while flushing
authorTobias Ronge <tobiasr@axis.com>
Mon, 7 Dec 2020 09:01:53 +0000 (10:01 +0100)
committerGStreamer Merge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Fri, 15 Jan 2021 09:24:51 +0000 (09:24 +0000)
Due to the may_cancel flag in GstRTSPConnection, receiving might not get
cancelled when supposed to. In this case, gst_rtsp_src_receive_response
will have to wait until timeout instead but if busy receiving RTP
data, this timeout will never occur.

With this patch, gst_rtsp_src_receive_response returns GST_RTSP_EINTR
if flushing is set to TRUE instead of continuing to receive.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-good/-/merge_requests/831>

gst/rtsp/gstrtspsrc.c

index dd871c9..bf5b72f 100644 (file)
@@ -5596,11 +5596,15 @@ gst_rtspsrc_loop_interleaved (GstRTSPSrc * src)
   while (TRUE) {
     gst_rtsp_message_unset (&message);
 
-    /* protect the connection with the connection lock so that we can see when
-     * we are finished doing server communication */
-    res =
-        gst_rtspsrc_connection_receive (src, &src->conninfo,
-        &message, src->tcp_timeout);
+    if (src->conninfo.flushing) {
+      /* do not attempt to receive if flushing */
+      res = GST_RTSP_EINTR;
+    } else {
+      /* protect the connection with the connection lock so that we can see when
+       * we are finished doing server communication */
+      res = gst_rtspsrc_connection_receive (src, &src->conninfo, &message,
+          src->tcp_timeout);
+    }
 
     switch (res) {
       case GST_RTSP_OK:
@@ -5715,8 +5719,13 @@ gst_rtspsrc_loop_udp (GstRTSPSrc * src)
     /* we should continue reading the TCP socket because the server might
      * send us requests. When the session timeout expires, we need to send a
      * keep-alive request to keep the session open. */
-    res = gst_rtspsrc_connection_receive (src, &src->conninfo, &message,
-        timeout);
+    if (src->conninfo.flushing) {
+      /* do not attempt to receive if flushing */
+      res = GST_RTSP_EINTR;
+    } else {
+      res = gst_rtspsrc_connection_receive (src, &src->conninfo, &message,
+          timeout);
+    }
 
     switch (res) {
       case GST_RTSP_OK:
@@ -6363,8 +6372,13 @@ gst_rtsp_src_receive_response (GstRTSPSrc * src, GstRTSPConnInfo * conninfo,
   GstRTSPResult res;
 
 next:
-  res = gst_rtspsrc_connection_receive (src, conninfo, response,
-      src->tcp_timeout);
+  if (conninfo->flushing) {
+    /* do not attempt to receive if flushing */
+    res = GST_RTSP_EINTR;
+  } else {
+    res = gst_rtspsrc_connection_receive (src, conninfo, response,
+        src->tcp_timeout);
+  }
 
   if (res < 0)
     goto receive_error;