rtphdrext: Pass just the attributes to the subclass
authorOlivier CrĂȘte <olivier.crete@collabora.com>
Fri, 24 Sep 2021 17:38:39 +0000 (13:38 -0400)
committerGStreamer Marge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Tue, 28 Sep 2021 20:04:55 +0000 (20:04 +0000)
Since the base class now does the parsing, there is no need
to reproduce that code in all the subclasses, just pass the attributes
which are the only relevant bit anyway.

Also, only store the direction if the subclass accepted the caps

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/906>

subprojects/gst-docs/symbols/symbol_index.json
subprojects/gst-plugins-base/gst-libs/gst/rtp/gstrtphdrext.c
subprojects/gst-plugins-base/gst-libs/gst/rtp/gstrtphdrext.h
subprojects/gst-plugins-base/tests/check/libs/rtpdummyhdrextimpl.c
subprojects/gst-plugins-good/gst/rtpmanager/gstrtphdrext-rfc6464.c

index d0448a9..e53c438 100644 (file)
   "GstRTPHeaderExtensionClass::get_max_size",
   "GstRTPHeaderExtensionClass::get_supported_flags",
   "GstRTPHeaderExtensionClass::read",
-  "GstRTPHeaderExtensionClass::set_attributes_from_caps",
+  "GstRTPHeaderExtensionClass::set_attributes",
   "GstRTPHeaderExtensionClass::set_caps_from_attributes",
   "GstRTPHeaderExtensionClass::set_non_rtp_sink_caps",
   "GstRTPHeaderExtensionClass::update_non_rtp_src_caps",
   "zbar:message",
   "zebrastripe",
   "zebrastripe:threshold"
-]
\ No newline at end of file
+]
index 6791952..0efd9bc 100644 (file)
@@ -412,6 +412,10 @@ gst_rtp_header_extension_set_attributes_from_caps (GstRTPHeaderExtension * ext,
   GstStructure *structure;
   gchar *field_name;
   const GValue *val;
+  GstRTPHeaderExtensionDirection direction =
+      GST_RTP_HEADER_EXTENSION_DIRECTION_DEFAULT;
+  const gchar *attributes = "";
+  gboolean ret = TRUE;
 
   g_return_val_if_fail (GST_IS_CAPS (caps), FALSE);
   g_return_val_if_fail (gst_caps_is_fixed (caps), FALSE);
@@ -443,15 +447,15 @@ gst_rtp_header_extension_set_attributes_from_caps (GstRTPHeaderExtension * ext,
       const gchar *dir = g_value_get_string (inner_val);
 
       if (!strcmp (dir, ""))
-        priv->direction = GST_RTP_HEADER_EXTENSION_DIRECTION_DEFAULT;
+        direction = GST_RTP_HEADER_EXTENSION_DIRECTION_DEFAULT;
       else if (!strcmp (dir, "sendrecv"))
-        priv->direction = GST_RTP_HEADER_EXTENSION_DIRECTION_SENDRECV;
+        direction = GST_RTP_HEADER_EXTENSION_DIRECTION_SENDRECV;
       else if (!strcmp (dir, "sendonly"))
-        priv->direction = GST_RTP_HEADER_EXTENSION_DIRECTION_SENDONLY;
+        direction = GST_RTP_HEADER_EXTENSION_DIRECTION_SENDONLY;
       else if (!strcmp (dir, "recvonly"))
-        priv->direction = GST_RTP_HEADER_EXTENSION_DIRECTION_RECVONLY;
+        direction = GST_RTP_HEADER_EXTENSION_DIRECTION_RECVONLY;
       else if (!strcmp (dir, "inactive"))
-        priv->direction = GST_RTP_HEADER_EXTENSION_DIRECTION_INACTIVE;
+        direction = GST_RTP_HEADER_EXTENSION_DIRECTION_INACTIVE;
       else
         goto error;
     } else {
@@ -468,15 +472,20 @@ gst_rtp_header_extension_set_attributes_from_caps (GstRTPHeaderExtension * ext,
     inner_val = gst_value_array_get_value (val, 2);
     if (!G_VALUE_HOLDS_STRING (inner_val))
       goto error;
+
+    attributes = g_value_get_string (inner_val);
   } else {
     /* unknown caps format */
     goto error;
   }
 
-  if (klass->set_attributes_from_caps)
-    return klass->set_attributes_from_caps (ext, caps);
-  else
-    return TRUE;
+  if (klass->set_attributes)
+    ret = klass->set_attributes (ext, direction, attributes);
+
+  if (ret)
+    priv->direction = direction;
+
+  return ret;
 
 error:
   return FALSE;
index 73e6daf..be2a67e 100644 (file)
@@ -167,8 +167,8 @@ struct _GstRTPHeaderExtension
  *     extension needs for its function.
  * @update_non_rtp_src_caps: update depayloader non-RTP (depayloaded) caps with
  *     the information parsed from RTP header.
- * @set_attributes_from_caps: read the caps information to set the necessary
- *     attributes that may be signaled e.g. with an SDP.
+ * @set_attributes: 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.
  *
@@ -202,8 +202,9 @@ struct _GstRTPHeaderExtensionClass
                                                      const GstCaps * caps);
   gboolean              (*update_non_rtp_src_caps)  (GstRTPHeaderExtension * ext,
                                                      GstCaps * caps);
-  gboolean              (*set_attributes_from_caps) (GstRTPHeaderExtension * ext,
-                                                     const GstCaps * caps);
+  gboolean              (*set_attributes)            (GstRTPHeaderExtension * ext,
+                                                      GstRTPHeaderExtensionDirection direction,
+                                                      const gchar * attributes);
   gboolean              (*set_caps_from_attributes) (GstRTPHeaderExtension * ext,
                                                      GstCaps * caps);
 
index 4e881ac..a6f8440 100644 (file)
@@ -83,8 +83,8 @@ static gboolean
 gst_rtp_dummy_hdr_ext_set_caps_from_attributes (GstRTPHeaderExtension * ext,
     GstCaps * caps);
 static gboolean
-gst_rtp_dummy_hdr_ext_set_attributes_from_caps (GstRTPHeaderExtension * ext,
-    const GstCaps * caps);
+gst_rtp_dummy_hdr_ext_set_attributes (GstRTPHeaderExtension * ext,
+    GstRTPHeaderExtensionDirection direction, const gchar * attributes);
 static gboolean
 gst_rtp_dummy_hdr_ext_update_non_rtp_src_caps (GstRTPHeaderExtension * ext,
     GstCaps * caps);
@@ -108,8 +108,8 @@ gst_rtp_dummy_hdr_ext_class_init (GstRTPDummyHdrExtClass * klass)
       gst_rtp_dummy_hdr_ext_get_max_size;
   gstrtpheaderextension_class->write = gst_rtp_dummy_hdr_ext_write;
   gstrtpheaderextension_class->read = gst_rtp_dummy_hdr_ext_read;
-  gstrtpheaderextension_class->set_attributes_from_caps =
-      gst_rtp_dummy_hdr_ext_set_attributes_from_caps;
+  gstrtpheaderextension_class->set_attributes =
+      gst_rtp_dummy_hdr_ext_set_attributes;
   gstrtpheaderextension_class->set_caps_from_attributes =
       gst_rtp_dummy_hdr_ext_set_caps_from_attributes;
   gstrtpheaderextension_class->update_non_rtp_src_caps =
@@ -211,57 +211,17 @@ gst_rtp_dummy_hdr_ext_set_caps_from_attributes (GstRTPHeaderExtension * ext,
 }
 
 static gboolean
-gst_rtp_dummy_hdr_ext_set_attributes_from_caps (GstRTPHeaderExtension * ext,
-    const GstCaps * caps)
+gst_rtp_dummy_hdr_ext_set_attributes (GstRTPHeaderExtension * ext,
+    GstRTPHeaderExtensionDirection direction, const gchar * attributes)
 {
   GstRTPDummyHdrExt *dummy = GST_RTP_DUMMY_HDR_EXT (ext);
-  gchar *field_name = gst_rtp_header_extension_get_sdp_caps_field_name (ext);
-  GstStructure *s = gst_caps_get_structure (caps, 0);
-  const gchar *ext_uri;
-  const GValue *arr;
-  gchar *new_attrs = NULL;
 
   dummy->set_attributes_count++;
 
-  if (!field_name)
-    return FALSE;
-
-  if ((ext_uri = gst_structure_get_string (s, field_name))) {
-    if (g_strcmp0 (ext_uri, gst_rtp_header_extension_get_uri (ext)) != 0) {
-      /* incompatible extension uri for this instance */
-      goto error;
-    }
-  } else if ((arr = gst_structure_get_value (s, field_name))
-      && GST_VALUE_HOLDS_ARRAY (arr)
-      && gst_value_array_get_size (arr) == 3) {
-    const GValue *val;
-
-    val = gst_value_array_get_value (arr, 1);
-    if (!G_VALUE_HOLDS_STRING (val))
-      goto error;
-    if (g_strcmp0 (g_value_get_string (val),
-            gst_rtp_header_extension_get_uri (ext)) != 0)
-      goto error;
-
-    val = gst_value_array_get_value (arr, 2);
-    if (!G_VALUE_HOLDS_STRING (val))
-      goto error;
-    new_attrs = g_value_dup_string (val);
-  } else {
-    /* unknown caps format */
-    goto error;
-  }
-
   g_free (dummy->attributes);
-  dummy->attributes = new_attrs;
+  dummy->attributes = g_strdup (attributes);
 
-  g_free (field_name);
   return TRUE;
-
-error:
-  g_free (field_name);
-  g_free (new_attrs);
-  return FALSE;
 }
 
 static gboolean
index eb80b8e..d93fcaf 100644 (file)
@@ -114,28 +114,16 @@ set_vad (GstRTPHeaderExtension * ext, gboolean vad)
 }
 
 static gboolean
-gst_rtp_header_extension_rfc6464_set_attributes_from_caps (GstRTPHeaderExtension
-    * ext, const GstCaps * caps)
+gst_rtp_header_extension_rfc6464_set_attributes (GstRTPHeaderExtension * ext,
+    GstRTPHeaderExtensionDirection direction, const gchar * attributes)
 {
-  gchar *field_name = gst_rtp_header_extension_get_sdp_caps_field_name (ext);
-  GstStructure *s = gst_caps_get_structure (caps, 0);
-  const GValue *arr;
-
-  arr = gst_structure_get_value (s, field_name);
-  g_free (field_name);
-
-  if (GST_VALUE_HOLDS_ARRAY (arr)) {
-    const GValue *val = gst_value_array_get_value (arr, 2);
-    const gchar *vad_attr = g_value_get_string (val);
-
-    if (g_str_equal (vad_attr, "vad=on"))
-      set_vad (ext, TRUE);
-    else if (g_str_equal (vad_attr, "vad=off"))
-      set_vad (ext, FALSE);
-    else {
-      GST_WARNING_OBJECT (ext, "Invalid attribute: %s", vad_attr);
-      return FALSE;
-    }
+  if (g_str_equal (attributes, "vad=on") || g_str_equal (attributes, "")) {
+    set_vad (ext, TRUE);
+  } else if (g_str_equal (attributes, "vad=off")) {
+    set_vad (ext, FALSE);
+  } else {
+    GST_WARNING_OBJECT (ext, "Invalid attribute: %s", attributes);
+    return FALSE;
   }
 
   return TRUE;
@@ -247,8 +235,8 @@ gst_rtp_header_extension_rfc6464_class_init (GstRTPHeaderExtensionRfc6464Class *
   rtp_hdr_class->get_supported_flags =
       gst_rtp_header_extension_rfc6464_get_supported_flags;
   rtp_hdr_class->get_max_size = gst_rtp_header_extension_rfc6464_get_max_size;
-  rtp_hdr_class->set_attributes_from_caps =
-      gst_rtp_header_extension_rfc6464_set_attributes_from_caps;
+  rtp_hdr_class->set_attributes =
+      gst_rtp_header_extension_rfc6464_set_attributes;
   rtp_hdr_class->set_caps_from_attributes =
       gst_rtp_header_extension_rfc6464_set_caps_from_attributes;
   rtp_hdr_class->write = gst_rtp_header_extension_rfc6464_write;