Merge remote-tracking branch 'origin/0.10'
[platform/upstream/gstreamer.git] / gst / gstbin.c
index 2f466e8..665259e 100644 (file)
  * </para>
  * </refsect2>
  *
- * Last reviewed on 2006-04-28 (0.10.6)
+ * Last reviewed on 2012-03-28 (0.11.3)
  */
 
 #include "gst_private.h"
 
 #include "gstevent.h"
 #include "gstbin.h"
-#include "gstmarshal.h"
 #include "gstinfo.h"
 #include "gsterror.h"
 
 #include "gstutils.h"
 #include "gstchildproxy.h"
 
-/* latency is by default enabled now.
- * live-preroll and no-live-preroll in the environment var GST_COMPAT
- * to enables or disable it respectively.
- */
-static gboolean enable_latency = TRUE;
-
 GST_DEBUG_CATEGORY_STATIC (bin_debug);
 #define GST_CAT_DEFAULT bin_debug
 
@@ -286,7 +279,6 @@ static guint gst_bin_signals[LAST_SIGNAL] = { 0 };
 
 #define _do_init \
 { \
-  const gchar *compat; \
   static const GInterfaceInfo iface_info = { \
     gst_bin_child_proxy_init, \
     NULL, \
@@ -297,20 +289,12 @@ static guint gst_bin_signals[LAST_SIGNAL] = { 0 };
   GST_DEBUG_CATEGORY_INIT (bin_debug, "bin", GST_DEBUG_BOLD, \
       "debugging info for the 'bin' container element"); \
   \
-  /* compatibility stuff */ \
-  compat = g_getenv ("GST_COMPAT"); \
-  if (compat != NULL) { \
-    if (strstr (compat, "no-live-preroll")) \
-      enable_latency = FALSE; \
-    else if (strstr (compat, "live-preroll")) \
-      enable_latency = TRUE; \
-  } \
 }
 
 #define gst_bin_parent_class parent_class
 G_DEFINE_TYPE_WITH_CODE (GstBin, gst_bin, GST_TYPE_ELEMENT, _do_init);
 
-static GstObject *
+static GObject *
 gst_bin_child_proxy_get_child_by_index (GstChildProxy * child_proxy,
     guint index)
 {
@@ -324,7 +308,7 @@ gst_bin_child_proxy_get_child_by_index (GstChildProxy * child_proxy,
     gst_object_ref (res);
   GST_OBJECT_UNLOCK (bin);
 
-  return res;
+  return (GObject *) res;
 }
 
 static guint
@@ -406,7 +390,7 @@ gst_bin_class_init (GstBinClass * klass)
   gst_bin_signals[ELEMENT_ADDED] =
       g_signal_new ("element-added", G_TYPE_FROM_CLASS (klass),
       G_SIGNAL_RUN_FIRST, G_STRUCT_OFFSET (GstBinClass, element_added), NULL,
-      NULL, gst_marshal_VOID__OBJECT, G_TYPE_NONE, 1, GST_TYPE_ELEMENT);
+      NULL, g_cclosure_marshal_generic, G_TYPE_NONE, 1, GST_TYPE_ELEMENT);
   /**
    * GstBin::element-removed:
    * @bin: the #GstBin
@@ -417,7 +401,7 @@ gst_bin_class_init (GstBinClass * klass)
   gst_bin_signals[ELEMENT_REMOVED] =
       g_signal_new ("element-removed", G_TYPE_FROM_CLASS (klass),
       G_SIGNAL_RUN_FIRST, G_STRUCT_OFFSET (GstBinClass, element_removed), NULL,
-      NULL, gst_marshal_VOID__OBJECT, G_TYPE_NONE, 1, GST_TYPE_ELEMENT);
+      NULL, g_cclosure_marshal_generic, G_TYPE_NONE, 1, GST_TYPE_ELEMENT);
   /**
    * GstBin::do-latency:
    * @bin: the #GstBin
@@ -439,7 +423,7 @@ gst_bin_class_init (GstBinClass * klass)
   gst_bin_signals[DO_LATENCY] =
       g_signal_new ("do-latency", G_TYPE_FROM_CLASS (klass),
       G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstBinClass, do_latency),
-      _gst_boolean_accumulator, NULL, gst_marshal_BOOLEAN__VOID,
+      _gst_boolean_accumulator, NULL, g_cclosure_marshal_generic,
       G_TYPE_BOOLEAN, 0, G_TYPE_NONE);
 
   /**
@@ -558,7 +542,7 @@ gst_bin_dispose (GObject * object)
  *
  * Creates a new bin with the given name.
  *
- * Returns: (transfer full): a new #GstBin
+ * Returns: (transfer floating): a new #GstBin
  */
 GstElement *
 gst_bin_new (const gchar * name)
@@ -1176,10 +1160,11 @@ no_state_recalc:
 
   GST_CAT_DEBUG_OBJECT (GST_CAT_PARENTAGE, bin, "added element \"%s\"",
       elem_name);
-  g_free (elem_name);
 
   g_signal_emit (bin, gst_bin_signals[ELEMENT_ADDED], 0, element);
-  gst_child_proxy_child_added ((GstObject *) bin, (GstObject *) element);
+  gst_child_proxy_child_added ((GObject *) bin, (GObject *) element, elem_name);
+
+  g_free (elem_name);
 
   return TRUE;
 
@@ -1496,7 +1481,6 @@ no_state_recalc:
 
   GST_CAT_INFO_OBJECT (GST_CAT_PARENTAGE, bin, "removed child \"%s\"",
       elem_name);
-  g_free (elem_name);
 
   gst_element_set_bus (element, NULL);
 
@@ -1513,8 +1497,10 @@ no_state_recalc:
   GST_OBJECT_UNLOCK (element);
 
   g_signal_emit (bin, gst_bin_signals[ELEMENT_REMOVED], 0, element);
-  gst_child_proxy_child_removed ((GstObject *) bin, (GstObject *) element);
+  gst_child_proxy_child_removed ((GObject *) bin, (GObject *) element,
+      elem_name);
 
+  g_free (elem_name);
   /* element is really out of our control now */
   gst_object_unref (element);
 
@@ -2222,18 +2208,9 @@ gst_bin_element_set_state (GstBin * bin, GstElement * element,
     if (next > current) {
       /* We found an async element check if we can force its state to change or
        * if we have to wait for it to preroll. */
-      if (G_UNLIKELY (!enable_latency)) {
-        g_warning ("Future versions of GStreamer will wait for element \"%s\"\n"
-            "\tto preroll in order to perform correct latency calculations.\n"
-            "\tPlease verify that the application continues to work correctly by\n"
-            "\tsetting the environment variable GST_COMPAT to a value containing\n"
-            "\tthe string 'live-preroll'.", GST_ELEMENT_NAME (element));
-        goto no_latency;
-      }
       goto was_busy;
     }
   }
-no_latency:
   GST_OBJECT_UNLOCK (bin);
 
 no_preroll:
@@ -3081,6 +3058,16 @@ bin_do_eos (GstBin * bin)
       && g_atomic_int_compare_and_exchange (&bin->priv->posted_eos, FALSE,
           TRUE)) {
     GstMessage *tmessage;
+
+    /* Clear out any further messages, and reset posted_eos so we can
+       detect any new EOS that happens (eg, after a seek). Since all
+       sinks have now posted an EOS, there will be no further EOS events
+       seen unless there is a new logical EOS */
+    GST_OBJECT_LOCK (bin);
+    bin_remove_messages (bin, NULL, GST_MESSAGE_EOS);
+    bin->priv->posted_eos = FALSE;
+    GST_OBJECT_UNLOCK (bin);
+
     tmessage = gst_message_new_eos (GST_OBJECT_CAST (bin));
     gst_message_set_seqnum (tmessage, seqnum);
     GST_DEBUG_OBJECT (bin,