message: Add gst_message_writable_structure()
authorFrançois Laignel <fengalin@free.fr>
Fri, 26 Jan 2018 11:42:28 +0000 (12:42 +0100)
committerSebastian Dröge <sebastian@centricular.com>
Fri, 26 Jan 2018 14:09:10 +0000 (16:09 +0200)
Add gst_message_writable_structure() to be able to add extra fields to
messages (and be on par with GstEvent).

https://bugzilla.gnome.org/show_bug.cgi?id=792928

docs/gst/gstreamer-sections.txt
gst/gstmessage.c
gst/gstmessage.h
tests/check/gst/gstmessage.c
win32/common/libgstreamer.def

index 1f65c31..ad81f6b 100644 (file)
@@ -1638,6 +1638,7 @@ gst_message_ref
 gst_message_unref
 gst_message_copy
 gst_message_get_structure
+gst_message_writable_structure
 gst_message_make_writable
 gst_message_get_seqnum
 gst_message_set_seqnum
index 33cf220..a5765da 100644 (file)
@@ -1159,6 +1159,43 @@ gst_message_get_structure (GstMessage * message)
 }
 
 /**
+ * gst_message_writable_structure:
+ * @message: The #GstMessage.
+ *
+ * Get a writable version of the structure.
+ *
+ * Returns: (transfer none): The structure of the message. The structure
+ * is still owned by the message, which means that you should not free
+ * it and that the pointer becomes invalid when you free the message.
+ * This function checks if @message is writable and will never return
+ * %NULL.
+ *
+ * MT safe.
+ *
+ * Since: 1.14
+ */
+GstStructure *
+gst_message_writable_structure (GstMessage * message)
+{
+  GstStructure *structure;
+
+  g_return_val_if_fail (GST_IS_MESSAGE (message), NULL);
+  g_return_val_if_fail (gst_message_is_writable (message), NULL);
+
+  structure = GST_MESSAGE_STRUCTURE (message);
+
+  if (structure == NULL) {
+    structure =
+        gst_structure_new_id_empty (gst_message_type_to_quark (GST_MESSAGE_TYPE
+            (message)));
+    gst_structure_set_parent_refcount (structure,
+        &message->mini_object.refcount);
+    GST_MESSAGE_STRUCTURE (message) = structure;
+  }
+  return structure;
+}
+
+/**
  * gst_message_has_name:
  * @message: The #GstMessage.
  * @name: name to check
index 67f4367..b110544 100644 (file)
@@ -450,6 +450,9 @@ const GstStructure *
                 gst_message_get_structure       (GstMessage *message);
 
 GST_EXPORT
+GstStructure *  gst_message_writable_structure  (GstMessage *message);
+
+GST_EXPORT
 gboolean        gst_message_has_name            (GstMessage *message, const gchar *name);
 
 /* identifiers for events and messages */
index 461e280..1f5b250 100644 (file)
@@ -35,10 +35,18 @@ GST_START_TEST (test_parsing)
 
   /* GST_MESSAGE_EOS */
   {
+    GstStructure *s;
+
     message = gst_message_new_eos (NULL);
     fail_if (message == NULL);
     fail_unless (GST_MESSAGE_TYPE (message) == GST_MESSAGE_EOS);
     fail_unless (GST_MESSAGE_SRC (message) == NULL);
+
+    /* Add an extra field */
+    s = gst_message_writable_structure (message);
+    fail_if (s == NULL);
+    gst_structure_set (s, "eos-extra-field", G_TYPE_BOOLEAN, TRUE, NULL);
+
     gst_message_unref (message);
   }
   /* GST_MESSAGE_ERROR */
index 2375ac2..06e3a8b 100644 (file)
@@ -826,6 +826,7 @@ EXPORTS
        gst_message_type_get_name
        gst_message_type_get_type
        gst_message_type_to_quark
+       gst_message_writable_structure
        gst_meta_api_type_get_tags
        gst_meta_api_type_has_tag
        gst_meta_api_type_register