Index: gst/gstbus.c
===================================================================
RCS file: /cvs/gstreamer/gstreamer/gst/gstbus.c,v
retrieving revision 1.55
diff -u -p -r1.55 gstbus.c
--- gst/gstbus.c	28 Feb 2006 10:52:02 -0000	1.55
+++ gst/gstbus.c	7 Mar 2006 19:51:39 -0000
@@ -72,6 +72,7 @@
 
 #include "gst_private.h"
 #include "gstinfo.h"
+#include "gstutils.h"
 
 #include "gstbus.h"
 
@@ -102,9 +103,12 @@ static GMainContext *main_context;
 
 struct _GstBusPrivate
 {
-  guint num_sync_message_emitters;
+  guint     num_sync_message_emitters;
+  gint      auto_flush; /* ATOMIC */
 };
 
+#define AUTO_FLUSH_DEFAULT  (TRUE)
+
 GType
 gst_bus_get_type (void)
 {
@@ -216,6 +220,8 @@ gst_bus_init (GstBus * bus)
 
   bus->priv = G_TYPE_INSTANCE_GET_PRIVATE (bus, GST_TYPE_BUS, GstBusPrivate);
 
+  bus->priv->auto_flush = AUTO_FLUSH_DEFAULT;
+
   GST_DEBUG_OBJECT (bus, "created");
 }
 
@@ -1084,3 +1090,51 @@ error:
     return;
   }
 }
+
+/**
+ * gst_bus_set_auto_flushing:
+ * @bus: a #GstBus
+ * @auto_flush: whether or not to automatically flush the bus when
+ * the owning element goes from READY to NULL state
+ *
+ * Usually, when a pipeline goes from READY to NULL state, it automatically
+ * flushes all pending messages on the bus, which is done for refcounting
+ * purposes, to break circular references. This means that applications
+ * that update state using (async) bus messages (e.g. do certain things when a
+ * pipeline goes from PAUSED to READY) might not get to see messages when the
+ * pipeline is shut down, because they might be flushed before they can be
+ * dispatched in the main thread. This behaviour can be disabled using this
+ * function.
+ *
+ * MT safe.
+ */
+void
+gst_bus_set_auto_flushing (GstBus * bus, gboolean auto_flush)
+{
+  g_return_if_fail (GST_IS_BUS (bus));
+
+  gst_atomic_int_set (&bus->priv->auto_flush, auto_flush);
+
+  GST_LOG_OBJECT (bus, "auto-flush %s", (auto_flush) ? "enabled" : "disabled");
+}
+
+/**
+ * gst_bus_get_auto_flushing:
+ * @bus: a #GstBus
+ *
+ * Returns: whether the bus has auto-flushing enabled or not
+ *
+ * MT safe.
+ */
+gboolean
+gst_bus_get_auto_flushing (GstBus * bus)
+{
+  gboolean ret;
+
+  g_return_val_if_fail (GST_IS_BUS (bus), FALSE);
+
+  ret = (g_atomic_int_get (&bus->priv->auto_flush) != 0);
+
+  return ret;
+}
+
Index: gst/gstbus.h
===================================================================
RCS file: /cvs/gstreamer/gstreamer/gst/gstbus.h,v
retrieving revision 1.20
diff -u -p -r1.20 gstbus.h
--- gst/gstbus.h	10 Feb 2006 16:04:58 -0000	1.20
+++ gst/gstbus.h	7 Mar 2006 19:51:39 -0000
@@ -149,6 +149,9 @@ GstMessage *		gst_bus_peek 			(GstBus * 
 GstMessage *		gst_bus_pop 			(GstBus * bus);
 void			gst_bus_set_flushing		(GstBus * bus, gboolean flushing);
 
+void                    gst_bus_set_auto_flushing       (GstBus * bus, gboolean auto_flush);
+gboolean                gst_bus_get_auto_flushing       (GstBus * bus);
+
 /* synchronous dispatching */
 void 			gst_bus_set_sync_handler 	(GstBus * bus, GstBusSyncHandler func,
     							 gpointer data);
Index: gst/gstpipeline.c
===================================================================
RCS file: /cvs/gstreamer/gstreamer/gst/gstpipeline.c,v
retrieving revision 1.127
diff -u -p -r1.127 gstpipeline.c
--- gst/gstpipeline.c	20 Jan 2006 19:01:59 -0000	1.127
+++ gst/gstpipeline.c	7 Mar 2006 19:51:39 -0000
@@ -420,7 +420,11 @@ gst_pipeline_change_state (GstElement * 
     case GST_STATE_CHANGE_READY_TO_NULL:
       GST_OBJECT_LOCK (element);
       if (element->bus) {
-        gst_bus_set_flushing (element->bus, TRUE);
+        if (gst_bus_get_auto_flushing (element->bus)) {
+          gst_bus_set_flushing (element->bus, TRUE);
+        } else {
+          GST_INFO_OBJECT (element, "not flushing bus, auto-flushing disabled");
+        }
       }
       GST_OBJECT_UNLOCK (element);
       break;
