bin: Add setter and getter to suppress element flags
authorWonchul Lee <wonchul.lee@collabora.com>
Fri, 2 Sep 2016 08:39:17 +0000 (17:39 +0900)
committerThiago Santos <thiagossantos@gmail.com>
Sat, 10 Sep 2016 16:28:21 +0000 (13:28 -0300)
Suppress-flags is for preventing propagation of child element's specific
flag when it is added to the bin.

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

gst/gstbin.c
gst/gstbin.h
win32/common/libgstreamer.def

index e7218f8..b193be1 100644 (file)
@@ -197,6 +197,7 @@ struct _GstBinPrivate
 
   gboolean posted_eos;
   gboolean posted_playing;
+  GstElementFlags suppressed_flags;
 };
 
 typedef struct
@@ -1206,23 +1207,25 @@ gst_bin_add_func (GstBin * bin, GstElement * element)
     goto had_parent;
 
   /* if we add a sink we become a sink */
-  if (is_sink) {
+  if (is_sink && !(bin->priv->suppressed_flags & GST_ELEMENT_FLAG_SINK)) {
     GST_CAT_DEBUG_OBJECT (GST_CAT_PARENTAGE, bin, "element \"%s\" was sink",
         elem_name);
     GST_OBJECT_FLAG_SET (bin, GST_ELEMENT_FLAG_SINK);
   }
-  if (is_source) {
+  if (is_source && !(bin->priv->suppressed_flags & GST_ELEMENT_FLAG_SOURCE)) {
     GST_CAT_DEBUG_OBJECT (GST_CAT_PARENTAGE, bin, "element \"%s\" was source",
         elem_name);
     GST_OBJECT_FLAG_SET (bin, GST_ELEMENT_FLAG_SOURCE);
   }
-  if (provides_clock) {
+  if (provides_clock
+      && !(bin->priv->suppressed_flags & GST_ELEMENT_FLAG_PROVIDE_CLOCK)) {
     GST_DEBUG_OBJECT (bin, "element \"%s\" can provide a clock", elem_name);
     clock_message =
         gst_message_new_clock_provide (GST_OBJECT_CAST (element), NULL, TRUE);
     GST_OBJECT_FLAG_SET (bin, GST_ELEMENT_FLAG_PROVIDE_CLOCK);
   }
-  if (requires_clock) {
+  if (requires_clock
+      && !(bin->priv->suppressed_flags & GST_ELEMENT_FLAG_REQUIRE_CLOCK)) {
     GST_DEBUG_OBJECT (bin, "element \"%s\" requires a clock", elem_name);
     GST_OBJECT_FLAG_SET (bin, GST_ELEMENT_FLAG_REQUIRE_CLOCK);
   }
@@ -1407,6 +1410,59 @@ had_parent:
   }
 }
 
+/**
+ * gst_bin_set_suppressed_flags:
+ * @bin: a #GstBin
+ * @flags: the #GstElementFlags to suppress
+ *
+ * Suppress the given flags on the bin. #GstElementFlags of a
+ * child element are propagated when it is added to the bin.
+ * When suppressed flags are set, those specified flags will
+ * not be propagated to the bin.
+ *
+ * MT safe.
+ *
+ * Since: 1.10
+ */
+void
+gst_bin_set_suppressed_flags (GstBin * bin, GstElementFlags flags)
+{
+  g_return_if_fail (GST_IS_BIN (bin));
+
+  GST_OBJECT_LOCK (bin);
+  bin->priv->suppressed_flags = bin->priv->suppressed_flags | flags;
+  GST_OBJECT_UNLOCK (bin);
+
+  GST_DEBUG_OBJECT (bin, "Set suppressed flags(0x%x) to bin '%s'", flags,
+      GST_ELEMENT_NAME (bin));
+}
+
+/**
+ * gst_bin_get_suppressed_flags:
+ * @bin: a #GstBin
+ *
+ * Return the suppressed flags of the bin.
+ *
+ * MT safe.
+ *
+ * Returns: the bin's suppressed #GstElementFlags.
+ *
+ * Since: 1.10
+ */
+GstElementFlags
+gst_bin_get_suppressed_flags (GstBin * bin)
+{
+  GstElementFlags res;
+
+  g_return_val_if_fail (GST_IS_BIN (bin), 0);
+
+  GST_OBJECT_LOCK (bin);
+  res = bin->priv->suppressed_flags;
+  GST_OBJECT_UNLOCK (bin);
+
+  return res;
+}
+
 /* signal vfunc, will be called when a new element was added */
 static void
 gst_bin_deep_element_added_func (GstBin * bin, GstBin * sub_bin,
index 809bb79..04afa2d 100644 (file)
@@ -208,6 +208,9 @@ GstIterator*        gst_bin_iterate_all_by_interface (GstBin *bin, GType iface);
 /* latency */
 gboolean        gst_bin_recalculate_latency      (GstBin * bin);
 
+/* set and get suppressed flags */
+void            gst_bin_set_suppressed_flags (GstBin * bin, GstElementFlags flags);
+GstElementFlags gst_bin_get_suppressed_flags (GstBin * bin);
 
 #ifdef G_DEFINE_AUTOPTR_CLEANUP_FUNC
 G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstBin, gst_object_unref)
index 9313d92..79fe904 100644 (file)
@@ -98,6 +98,7 @@ EXPORTS
        gst_bin_get_by_interface
        gst_bin_get_by_name
        gst_bin_get_by_name_recurse_up
+       gst_bin_get_suppressed_flags
        gst_bin_get_type
        gst_bin_iterate_all_by_interface
        gst_bin_iterate_elements
@@ -109,6 +110,7 @@ EXPORTS
        gst_bin_recalculate_latency
        gst_bin_remove
        gst_bin_remove_many
+       gst_bin_set_suppressed_flags
        gst_bin_sync_children_states
        gst_bitmask_get_type
        gst_buffer_add_meta