srt: Check socket state before retrieving payload size
authorJan Alexander Steffens (heftig) <jan.steffens@ltnglobal.com>
Thu, 8 Oct 2020 15:48:20 +0000 (17:48 +0200)
committerGStreamer Merge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Fri, 9 Oct 2020 07:12:04 +0000 (07:12 +0000)
The connection might be broken, which we should detect instead of just
aborting the write.

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

ext/srt/gstsrtobject.c

index 6a0bd5a790a8fe08e0eb9baaa5dd5df3975af2f9..86dcf1eddef9be82cfaab81ff528481aef679323 100644 (file)
@@ -1534,13 +1534,6 @@ gst_srt_object_write_one (GstSRTObject * srtobject,
       continue;
     }
 
-    if (srt_getsockflag (wsock, SRTO_PAYLOADSIZE, &payload_size, &optlen)) {
-      GST_WARNING_OBJECT (srtobject->element, "%s", srt_getlasterror_str ());
-      break;
-    }
-
-    rest = MIN (mapinfo->size - len, payload_size);
-
     switch (srt_getsockstate (wsock)) {
       case SRTS_BROKEN:
       case SRTS_NONEXIST:
@@ -1562,6 +1555,14 @@ gst_srt_object_write_one (GstSRTObject * srtobject,
         continue;
     }
 
+    if (srt_getsockflag (wsock, SRTO_PAYLOADSIZE, &payload_size, &optlen)) {
+      GST_ELEMENT_ERROR (srtobject->element, RESOURCE, WRITE, NULL,
+          ("%s", srt_getlasterror_str ()));
+      break;
+    }
+
+    rest = MIN (mapinfo->size - len, payload_size);
+
     sent = srt_sendmsg2 (wsock, (char *) (msg + len), rest, 0);
     if (sent < 0) {
       GST_ELEMENT_ERROR (srtobject->element, RESOURCE, WRITE, NULL,