rtpbasepayload: pass optional caps fields in a GstStructure
authorJakub Adam <jakub.adam@collabora.com>
Mon, 30 Nov 2020 20:38:08 +0000 (21:38 +0100)
committerGStreamer Merge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Sat, 5 Dec 2020 08:29:31 +0000 (08:29 +0000)
For more flexibility, allow to pass the extra output caps fields as
a GstStructure.

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

gst-libs/gst/rtp/gstrtpbasepayload.c
gst-libs/gst/rtp/gstrtpbasepayload.h

index 7bbbf3d..545fd7b 100644 (file)
@@ -891,22 +891,28 @@ update_max_ptime (GstRTPBasePayload * rtpbasepayload)
     rtpbasepayload->max_ptime = DEFAULT_MAX_PTIME;
 }
 
+static gboolean
+_set_caps (GQuark field_id, const GValue * value, GstCaps * caps)
+{
+  gst_caps_set_value (caps, g_quark_to_string (field_id), value);
+
+  return TRUE;
+}
+
 /**
- * gst_rtp_base_payload_set_outcaps:
+ * gst_rtp_base_payload_set_outcaps_structure:
  * @payload: a #GstRTPBasePayload
- * @fieldname: the first field name or %NULL
- * @...: field values
- *
- * Configure the output caps with the optional parameters.
+ * @s: (nullable): a #GstStructure with the caps fields
  *
- * Variable arguments should be in the form field name, field type
- * (as a GType), value(s).  The last variable argument should be NULL.
+ * Configure the output caps with the optional fields.
  *
  * Returns: %TRUE if the caps could be set.
+ *
+ * Since: 1.20
  */
 gboolean
-gst_rtp_base_payload_set_outcaps (GstRTPBasePayload * payload,
-    const gchar * fieldname, ...)
+gst_rtp_base_payload_set_outcaps_structure (GstRTPBasePayload * payload,
+    GstStructure * s)
 {
   GstCaps *srccaps;
 
@@ -918,21 +924,54 @@ gst_rtp_base_payload_set_outcaps (GstRTPBasePayload * payload,
 
   GST_DEBUG_OBJECT (payload, "defaults: %" GST_PTR_FORMAT, srccaps);
 
+  if (s && gst_structure_n_fields (s) > 0) {
+    gst_structure_foreach (s, (GstStructureForeachFunc) _set_caps, srccaps);
+
+    GST_DEBUG_OBJECT (payload, "custom added: %" GST_PTR_FORMAT, srccaps);
+  }
+
+  gst_caps_replace (&payload->priv->subclass_srccaps, srccaps);
+  gst_caps_unref (srccaps);
+
+  return gst_rtp_base_payload_negotiate (payload);
+}
+
+/**
+ * gst_rtp_base_payload_set_outcaps:
+ * @payload: a #GstRTPBasePayload
+ * @fieldname: the first field name or %NULL
+ * @...: field values
+ *
+ * Configure the output caps with the optional parameters.
+ *
+ * Variable arguments should be in the form field name, field type
+ * (as a GType), value(s).  The last variable argument should be NULL.
+ *
+ * Returns: %TRUE if the caps could be set.
+ */
+gboolean
+gst_rtp_base_payload_set_outcaps (GstRTPBasePayload * payload,
+    const gchar * fieldname, ...)
+{
+  gboolean result;
+  GstStructure *s = NULL;
+
   if (fieldname) {
     va_list varargs;
 
+    s = gst_structure_new_empty ("unused");
+
     /* override with custom properties */
     va_start (varargs, fieldname);
-    gst_caps_set_simple_valist (srccaps, fieldname, varargs);
+    gst_structure_set_valist (s, fieldname, varargs);
     va_end (varargs);
-
-    GST_DEBUG_OBJECT (payload, "custom added: %" GST_PTR_FORMAT, srccaps);
   }
 
-  gst_caps_replace (&payload->priv->subclass_srccaps, srccaps);
-  gst_caps_unref (srccaps);
+  result = gst_rtp_base_payload_set_outcaps_structure (payload, s);
 
-  return gst_rtp_base_payload_negotiate (payload);
+  gst_clear_structure (&s);
+
+  return result;
 }
 
 static void
index 8cc7852..00bf99e 100644 (file)
@@ -161,6 +161,10 @@ gboolean        gst_rtp_base_payload_set_outcaps        (GstRTPBasePayload *payl
                                                          const gchar *fieldname, ...);
 
 GST_RTP_API
+gboolean        gst_rtp_base_payload_set_outcaps_structure (GstRTPBasePayload *payload,
+                                                            GstStructure *s);
+
+GST_RTP_API
 gboolean        gst_rtp_base_payload_is_filled          (GstRTPBasePayload *payload,
                                                          guint size, GstClockTime duration);