rtphdrext: allow the extension to inspect payloader's sink caps
authorJakub Adam <jakub.adam@collabora.com>
Tue, 12 Jan 2021 21:11:46 +0000 (22:11 +0100)
committerJakub Adam <jakub.adam@collabora.com>
Fri, 12 Mar 2021 17:45:04 +0000 (18:45 +0100)
Some header extensions may need to read information from the payloader's
sink caps. Introduce gst_rtp_header_extension_update_from_sinkcaps ()
that passes the caps to the extension, which can then use it to update
its internal state.

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

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

index bb86946..8be9df3 100644 (file)
@@ -1475,6 +1475,25 @@ gst_rtp_base_payload_negotiate (GstRTPBasePayload * payload)
         payload->priv->header_exts);
     g_ptr_array_foreach (to_add, (GFunc) add_item_to,
         payload->priv->header_exts);
+    /* let extensions update their internal state from sinkcaps */
+    if (payload->priv->sinkcaps) {
+      gint i;
+
+      for (i = 0; i < payload->priv->header_exts->len; i++) {
+        GstRTPHeaderExtension *ext;
+
+        ext = g_ptr_array_index (payload->priv->header_exts, i);
+        if (!gst_rtp_header_extension_set_non_rtp_sink_caps (ext,
+                payload->priv->sinkcaps)) {
+          GST_WARNING_OBJECT (payload,
+              "Failed to update rtp header extension (%s) from sink caps",
+              GST_OBJECT_NAME (ext));
+          res = FALSE;
+          GST_OBJECT_UNLOCK (payload);
+          goto ext_out;
+        }
+      }
+    }
     /* add extension information to srccaps */
     g_ptr_array_foreach (payload->priv->header_exts,
         (GFunc) add_header_ext_to_caps, srccaps);
index e3a908c..1988e44 100644 (file)
@@ -395,6 +395,36 @@ gst_rtp_header_extension_set_attributes_from_caps (GstRTPHeaderExtension * ext,
 }
 
 /**
+ * gst_rtp_header_extension_set_non_rtp_sink_caps:
+ * @ext: a #GstRTPHeaderExtension
+ * @caps: sink #GstCaps
+ *
+ * Passes RTP payloader's sink (i.e. not payloaded) @caps to the header
+ * extension.
+ *
+ * Returns: Whether @caps could be read successfully
+ *
+ * Since: 1.20
+ */
+gboolean
+gst_rtp_header_extension_set_non_rtp_sink_caps (GstRTPHeaderExtension * ext,
+    const GstCaps * caps)
+{
+  GstRTPHeaderExtensionClass *klass;
+
+  g_return_val_if_fail (GST_IS_CAPS (caps), FALSE);
+  g_return_val_if_fail (GST_IS_RTP_HEADER_EXTENSION (ext), FALSE);
+  g_return_val_if_fail (ext->ext_id <= MAX_RTP_EXT_ID, FALSE);
+  klass = GST_RTP_HEADER_EXTENSION_GET_CLASS (ext);
+
+  if (klass->set_non_rtp_sink_caps) {
+    return klass->set_non_rtp_sink_caps (ext, caps);
+  }
+
+  return TRUE;
+}
+
+/**
  * gst_rtp_header_extension_set_caps_from_attributes:
  * @ext: a #GstRTPHeaderExtension
  * @caps: writable #GstCaps to modify
index 551ba30..1f0e9b1 100644 (file)
@@ -138,7 +138,9 @@ struct _GstRTPHeaderExtension
  *     information is provided to help writing extensions in particular cases.
  * @read: read from a rtp payloaded buffer and extract the extension
  *     information, optionally adding some meta onto the output buffer.
- * @set_attributes_from_caps: read the caps information to set the necesary
+ * @set_non_rtp_sink_caps: read any information from sink caps that the header
+ *     extension needs for its function.
+ * @set_attributes_from_caps: read the caps information to set the necessary
  *     attributes that may be signaled e.g. with an SDP.
  * @set_caps_from_attributes: write the necessary caps field/s for the configured
  *     attributes e.g. as signalled with SDP.
@@ -169,6 +171,8 @@ struct _GstRTPHeaderExtensionClass
                                                      const guint8 * data,
                                                      gsize size,
                                                      GstBuffer * buffer);
+  gboolean              (*set_non_rtp_sink_caps)    (GstRTPHeaderExtension * ext,
+                                                     const GstCaps * caps);
   gboolean              (*set_attributes_from_caps) (GstRTPHeaderExtension * ext,
                                                      const GstCaps * caps);
   gboolean              (*set_caps_from_attributes) (GstRTPHeaderExtension * ext,
@@ -217,6 +221,9 @@ gboolean            gst_rtp_header_extension_read               (GstRTPHeaderExt
                                                                  gsize size,
                                                                  GstBuffer * buffer);
 GST_RTP_API
+gboolean            gst_rtp_header_extension_set_non_rtp_sink_caps (GstRTPHeaderExtension * ext,
+                                                                    const GstCaps * caps);
+GST_RTP_API
 gboolean            gst_rtp_header_extension_set_caps_from_attributes (GstRTPHeaderExtension * ext,
                                                                        GstCaps * caps);
 GST_RTP_API