webrtc: explicitly error out in a couple of renegotiation cases
authorMatthew Waters <matthew@centricular.com>
Tue, 16 Nov 2021 06:28:04 +0000 (17:28 +1100)
committerGStreamer Marge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Tue, 29 Mar 2022 23:55:40 +0000 (23:55 +0000)
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/1664>

subprojects/gst-plugins-bad/ext/webrtc/gstwebrtcbin.c
subprojects/gst-plugins-bad/gst-libs/gst/webrtc/webrtc_fwd.h

index 8def7cf..bfc7d47 100644 (file)
@@ -3047,10 +3047,15 @@ sdp_media_from_transceiver (GstWebRTCBin * webrtc, GstSDPMedia * media,
 
   if (last_media) {
     const char *setup = gst_sdp_media_get_attribute_val (last_media, "setup");
-    if (setup)
+    if (setup) {
       gst_sdp_media_add_attribute (media, "setup", setup);
-    else
+    } else {
+      g_set_error (error, GST_WEBRTC_ERROR,
+          GST_WEBRTC_ERROR_INVALID_MODIFICATION,
+          "media %u cannot renegotiate without an existing a=setup line",
+          media_idx);
       return FALSE;
+    }
   } else {
     /* mandated by JSEP */
     gst_sdp_media_add_attribute (media, "setup", "actpass");
@@ -3179,7 +3184,16 @@ sdp_media_from_transceiver (GstWebRTCBin * webrtc, GstSDPMedia * media,
 
   /* Some identifier; we also add the media name to it so it's identifiable */
   if (trans->mid) {
-    gst_sdp_media_add_attribute (media, "mid", trans->mid);
+    const char *media_mid = gst_sdp_media_get_attribute_val (media, "mid");
+    if (!media_mid) {
+      gst_sdp_media_add_attribute (media, "mid", trans->mid);
+    } else if (g_strcmp0 (media_mid, trans->mid) != 0) {
+      g_set_error (error, GST_WEBRTC_ERROR,
+          GST_WEBRTC_ERROR_INVALID_MODIFICATION,
+          "Cannot change media %u mid value from \'%s\' to \'%s\'",
+          media_idx, media_mid, trans->mid);
+      return FALSE;
+    }
     mid = g_strdup (trans->mid);
   } else {
     const GstStructure *s = gst_caps_get_structure (caps, 0);
@@ -4168,7 +4182,7 @@ _create_answer_task (GstWebRTCBin * webrtc, const GstStructure * options,
          * that we cannot actually support */
         if (trans_caps) {
           answer_caps = gst_caps_intersect (offer_caps, trans_caps);
-          gst_caps_unref (trans_caps);
+          gst_clear_caps (&trans_caps);
         } else {
           answer_caps = gst_caps_ref (offer_caps);
         }
@@ -4180,8 +4194,8 @@ _create_answer_task (GstWebRTCBin * webrtc, const GstStructure * options,
 
       if (gst_caps_is_empty (answer_caps)) {
         GST_WARNING_OBJECT (webrtc, "Could not create caps for media");
-        gst_caps_unref (answer_caps);
-        gst_caps_unref (offer_caps);
+        gst_clear_caps (&answer_caps);
+        gst_clear_caps (&offer_caps);
         goto rejected;
       }
 
index d181873..e8858ac 100644 (file)
@@ -450,6 +450,13 @@ GQuark gst_webrtc_error_quark (void);
  *
  * Since: 1.20
  */
+/**
+ * GST_WEBRTC_ERROR_INVALID_MODIFICATION:
+ *
+ * invalid-modification (part of WebIDL specification)
+ *
+ * Since: 1.22
+ */
 typedef enum /*<underscore_name=gst_webrtc_error>*/
 {
   GST_WEBRTC_ERROR_DATA_CHANNEL_FAILURE,
@@ -460,8 +467,8 @@ typedef enum /*<underscore_name=gst_webrtc_error>*/
   GST_WEBRTC_ERROR_HARDWARE_ENCODER_NOT_AVAILABLE,
   GST_WEBRTC_ERROR_ENCODER_ERROR,
   GST_WEBRTC_ERROR_INVALID_STATE,
-  GST_WEBRTC_ERROR_INTERNAL_FAILURE
+  GST_WEBRTC_ERROR_INTERNAL_FAILURE,
+  GST_WEBRTC_ERROR_INVALID_MODIFICATION,
 } GstWebRTCError;
 
-
 #endif /* __GST_WEBRTC_FWD_H__ */