[farsight2/master] Make the element recursive element stuff also work on non-bin elements

Olivier Crête olivier.crete at collabora.co.uk
Tue Dec 23 15:20:41 PST 2008


---
 gst-libs/gst/farsight/fs-utils.c |   54 +++++++++++++++++++-------------------
 gst-libs/gst/farsight/fs-utils.h |   10 ++++---
 tests/check/utils/binadded.c     |   15 +++-------
 3 files changed, 38 insertions(+), 41 deletions(-)

diff --git a/gst-libs/gst/farsight/fs-utils.c b/gst-libs/gst/farsight/fs-utils.c
index 929e7b5..2a006e0 100644
--- a/gst-libs/gst/farsight/fs-utils.c
+++ b/gst-libs/gst/farsight/fs-utils.c
@@ -40,7 +40,7 @@ struct FsElementAddedData {
   gint refcount;
   FsElementAddedCallback callback;
   gpointer user_data;
-  GstBin *head;
+  GstElement *head;
 };
 
 
@@ -50,7 +50,7 @@ static gpointer _element_added_callback (GstBin *parent, GstElement *element,
 
 static struct FsElementAddedData *
 element_added_data_new (FsElementAddedCallback callback, gpointer user_data,
-                        GstBin *head)
+                        GstElement *head)
 {
   struct FsElementAddedData *data =
     g_new (struct FsElementAddedData, 1);
@@ -138,7 +138,7 @@ _element_added_callback (GstBin *parent, GstElement *element,
     g_signal_connect (element, "element-added",
         G_CALLBACK (_element_added_callback), user_data);
 
-    if (data->head != GST_BIN_CAST (element))
+    if (data->head != element)
       g_signal_connect (element, "parent-unset",
           G_CALLBACK (_bin_unparented_cb), user_data);
 
@@ -183,30 +183,30 @@ _element_added_callback (GstBin *parent, GstElement *element,
 
 /**
  * fs_utils_add_recursive_element_added_notification:
- * @bin: A #GstBin
+ * @element: A #GstElement
  * @callback: the function to be called when a new element is added
  * @user_data: data that will be passed to the callback
  *
- * The callback will be called on every element currently inside the bin,
- * and this will be done recursively. The function will also be called on any
- * element added in the future to the bin. The callback may be called more than
- * once and should be thread safe (elements may be added from the streaming
+ * The callback will be called on the element and every sub-element if its a
+ * bin and this will be done recursively. The function will also be called on
+ * any element added in the future to the bin. The callback may be called more
+ * than once and should be thread safe (elements may be added from the streaming
  * threads).
  *
  * Returns: a handle that can be used when calling
- *  #fs_utils_remove_recursive_element_added_notification
+ *  #fs_utils_remove_recursive_element_added_notification, or NULL if there was
+ *  an error
  */
 
 gpointer
-fs_utils_add_recursive_element_added_notification (GstBin *bin,
+fs_utils_add_recursive_element_added_notification (GstElement *element,
     FsElementAddedCallback callback,
     gpointer user_data)
 {
   g_assert (callback);
-  g_assert (GST_IS_BIN (bin));
 
-  return _element_added_callback (NULL, GST_ELEMENT_CAST (bin),
-      element_added_data_new (callback, user_data, bin));
+  return _element_added_callback (NULL, element,
+      element_added_data_new (callback, user_data, element));
 }
 
 /**
@@ -222,22 +222,22 @@ fs_utils_add_recursive_element_added_notification (GstBin *bin,
  * Returns: TRUE if the notification could be removed, FALSE otherwise
  */
 gboolean
-fs_utils_remove_recursive_element_added_notification (GstBin *bin,
+fs_utils_remove_recursive_element_added_notification (GstElement *element,
     gpointer handle)
 {
   struct FsElementAddedData *data = handle;
 
- if (g_signal_handler_find (bin,
-                 G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA,
-                 0, 0, NULL, /* id, detail, closure */
-                 _element_added_callback, data) != 0)
- {
-   g_assert (data->head == bin);
-   _bin_unparented_cb (GST_OBJECT (data->head), NULL, data);
-   return TRUE;
- }
- else
- {
-   return FALSE;
- }
+  if (g_signal_handler_find (element,
+          G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA,
+          0, 0, NULL, /* id, detail, closure */
+          _element_added_callback, data) != 0)
+  {
+    g_assert (data->head == element);
+    _bin_unparented_cb (GST_OBJECT (data->head), NULL, data);
+    return TRUE;
+  }
+  else
+  {
+    return FALSE;
+  }
 }
diff --git a/gst-libs/gst/farsight/fs-utils.h b/gst-libs/gst/farsight/fs-utils.h
index fb4fe3a..f1ba7c6 100644
--- a/gst-libs/gst/farsight/fs-utils.h
+++ b/gst-libs/gst/farsight/fs-utils.h
@@ -31,7 +31,8 @@ G_BEGIN_DECLS
 
 /**
  * FsElementAddedCallback:
- * @bin: The #GstBin to which the element was added
+ * @bin: The #GstBin to which the element was added, will be NULL if the element
+ *   is the top-level bin
  * @element: The just-added #GstElement
  * @user_data: The user data passed by the user
  *
@@ -42,15 +43,16 @@ typedef void (*FsElementAddedCallback) (GstBin *bin,
     GstElement *element,
     gpointer user_data);
 
-void fs_utils_recursive_element_added (GstBin *bin,
+void fs_utils_recursive_element_added (GstElement *element,
     FsElementAddedCallback callback,
     gpointer user_data);
 
-gpointer fs_utils_add_recursive_element_added_notification (GstBin *bin,
+gpointer fs_utils_add_recursive_element_added_notification (GstElement *element,
     FsElementAddedCallback callback,
     gpointer user_data);
 
-gboolean fs_utils_remove_recursive_element_added_notification (GstBin *bin,
+gboolean fs_utils_remove_recursive_element_added_notification (
+    GstElement *element,
     gpointer handle);
 
 
diff --git a/tests/check/utils/binadded.c b/tests/check/utils/binadded.c
index e21df7f..bfa5591 100644
--- a/tests/check/utils/binadded.c
+++ b/tests/check/utils/binadded.c
@@ -61,8 +61,7 @@ GST_START_TEST (test_bin_added_simple)
   identity = gst_element_factory_make ("identity", NULL);
   gst_object_ref (identity);
 
-  handle = fs_utils_add_recursive_element_added_notification (
-      GST_BIN (pipeline),
+  handle = fs_utils_add_recursive_element_added_notification (pipeline,
       _added_cb, &last_added);
 
   fail_if (handle == NULL, "Could not add notification to pipeline");
@@ -88,8 +87,7 @@ GST_START_TEST (test_bin_added_simple)
 
 
   fail_unless (
-      fs_utils_remove_recursive_element_added_notification (GST_BIN (pipeline),
-          handle),
+      fs_utils_remove_recursive_element_added_notification (pipeline, handle),
       "Could not remove notification handle %p", handle);
 
   fail_unless (gst_bin_add (GST_BIN (pipeline), identity),
@@ -123,8 +121,7 @@ GST_START_TEST (test_bin_added_recursive)
   identity = gst_element_factory_make ("identity", NULL);
   gst_object_ref (identity);
 
-  handle = fs_utils_add_recursive_element_added_notification (
-      GST_BIN (pipeline),
+  handle = fs_utils_add_recursive_element_added_notification (pipeline,
       _added_cb, &last_added);
 
   fail_if (handle == NULL, "Could not add notification to bin");
@@ -150,8 +147,7 @@ GST_START_TEST (test_bin_added_recursive)
 
 
   fail_unless (
-      fs_utils_remove_recursive_element_added_notification (GST_BIN (pipeline),
-          handle),
+      fs_utils_remove_recursive_element_added_notification (pipeline, handle),
       "Could not remove notification handle %p", handle);
 
   fail_unless (gst_bin_add (GST_BIN (bin), identity),
@@ -162,8 +158,7 @@ GST_START_TEST (test_bin_added_recursive)
   fail_unless (gst_bin_remove (GST_BIN (bin), identity),
       "Could not remove identity from bin");
 
-  handle = fs_utils_add_recursive_element_added_notification (
-      GST_BIN (pipeline),
+  handle = fs_utils_add_recursive_element_added_notification (pipeline,
       _added_cb, &last_added);
 
   fail_if (handle == NULL, "Could not re-add notification to bin");
-- 
1.5.6.5




More information about the farsight-commits mailing list