rtpopuspay: make use of gst_rtp_base_payload_set_outcaps_structure()
authorJakub Adam <jakub.adam@collabora.com>
Mon, 30 Nov 2020 21:10:14 +0000 (22:10 +0100)
committerGStreamer Merge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Thu, 11 Feb 2021 07:46:04 +0000 (07:46 +0000)
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-good/-/merge_requests/832>

gst/rtp/gstrtpopuspay.c

index 871a182..48a454e 100644 (file)
@@ -101,11 +101,11 @@ gst_rtp_opus_pay_setcaps (GstRTPBasePayload * payload, GstCaps * caps)
 {
   gboolean res;
   GstCaps *src_caps;
-  GstStructure *s;
+  GstStructure *s, *outcaps;
   const char *encoding_name = "OPUS";
   gint channels, rate;
-  const char *sprop_stereo = NULL;
-  char *sprop_maxcapturerate = NULL;
+
+  outcaps = gst_structure_new_empty ("unused");
 
   src_caps = gst_pad_get_allowed_caps (GST_RTP_BASE_PAYLOAD_SRCPAD (payload));
   if (src_caps) {
@@ -133,38 +133,27 @@ gst_rtp_opus_pay_setcaps (GstRTPBasePayload * payload, GstCaps * caps)
       GST_ERROR_OBJECT (payload,
           "More than 2 channels with channel-mapping-family=0 is invalid");
       return FALSE;
-    } else if (channels == 2) {
-      sprop_stereo = "1";
     } else {
-      sprop_stereo = "0";
+      gst_structure_set (outcaps, "sprop-stereo", G_TYPE_STRING,
+          (channels == 2) ? "1" : "0", NULL);
     }
   }
 
   if (gst_structure_get_int (s, "rate", &rate)) {
-    sprop_maxcapturerate = g_strdup_printf ("%d", rate);
+    gchar *sprop_maxcapturerate = g_strdup_printf ("%d", rate);
+
+    gst_structure_set (outcaps, "sprop-maxcapturerate", G_TYPE_STRING,
+        sprop_maxcapturerate, NULL);
+
+    g_free (sprop_maxcapturerate);
   }
 
   gst_rtp_base_payload_set_options (payload, "audio", FALSE,
       encoding_name, 48000);
 
-  if (sprop_maxcapturerate && sprop_stereo) {
-    res =
-        gst_rtp_base_payload_set_outcaps (payload, "sprop-maxcapturerate",
-        G_TYPE_STRING, sprop_maxcapturerate, "sprop-stereo", G_TYPE_STRING,
-        sprop_stereo, NULL);
-  } else if (sprop_maxcapturerate) {
-    res =
-        gst_rtp_base_payload_set_outcaps (payload, "sprop-maxcapturerate",
-        G_TYPE_STRING, sprop_maxcapturerate, NULL);
-  } else if (sprop_stereo) {
-    res =
-        gst_rtp_base_payload_set_outcaps (payload, "sprop-stereo",
-        G_TYPE_STRING, sprop_stereo, NULL);
-  } else {
-    res = gst_rtp_base_payload_set_outcaps (payload, NULL);
-  }
+  res = gst_rtp_base_payload_set_outcaps_structure (payload, outcaps);
 
-  g_free (sprop_maxcapturerate);
+  gst_structure_free (outcaps);
 
   return res;
 }