--- gstcollectpads.c	2006-05-04 21:30:01.000000000 +0300
+++ gstcollectpads.c.patched	2006-05-03 23:34:31.000000000 +0300
@@ -178,6 +178,31 @@
 }
 
 /**
+ * gst_collect_pads_set_event_function:
+ * @pads: the collectspads to use
+ * @func: the function to set
+ * @user_data: user data passed to the function
+ *
+ * Set the event callback function and user data that will be called after
+ * collectpads has processed and event originating from one of the collected
+ * pads.
+ *
+ * MT safe.
+ */
+void
+gst_collect_pads_set_event_function (GstCollectPads *pads,
+    GstCollectPadsEventFunction func, gpointer user_data)
+{
+  g_return_if_fail (pads != NULL);
+  g_return_if_fail (GST_IS_COLLECT_PADS (pads));
+
+  GST_OBJECT_LOCK (pads);
+  pads->event_func = func;
+  pads->event_user_data = user_data;
+  GST_OBJECT_UNLOCK (pads);
+}
+
+/**
  * gst_collect_pads_add_pad:
  * @pads: the collectspads to use
  * @pad: the pad to add
@@ -667,6 +692,7 @@
 static gboolean
 gst_collect_pads_event (GstPad * pad, GstEvent * event)
 {
+  gboolean res = FALSE;
   GstCollectData *data;
   GstCollectPads *pads;
 
@@ -684,7 +710,11 @@
     case GST_EVENT_FLUSH_START:
     {
       /* forward event to unblock is_collected */
-      gst_pad_event_default (pad, event);
+      res = FALSE;
+      if (pads->event_func)
+        res = pads->event_func (pads, pad, event, pads->event_user_data);
+      if (!res)
+        res = gst_pad_event_default (pad, event);
 
       /* now unblock the chain function
          no cond per pad, so they all unblock, non-flushing block again */
@@ -694,7 +724,7 @@
       GST_OBJECT_UNLOCK (pads);
 
       /* event already cleaned up by forwarding */
-      return TRUE;
+      return res;
     }
     case GST_EVENT_FLUSH_STOP:
     {
@@ -703,21 +733,15 @@
       data->abidata.ABI.flushing = FALSE;
       gst_collect_pads_pop (pads, data);
       GST_OBJECT_UNLOCK (pads);
-      goto beach;
+      goto forward_or_default;
     }
     case GST_EVENT_EOS:
     {
       GST_OBJECT_LOCK (pads);
-
       pads->eospads++;
-
       gst_collect_pads_is_collected (pads, NULL);
-
       GST_OBJECT_UNLOCK (pads);
-
-      /* We eat this event */
-      gst_event_unref (event);
-      return TRUE;
+      goto forward_or_eat;
     }
     case GST_EVENT_NEWSEGMENT:
     {
@@ -741,26 +765,28 @@
 
       data->abidata.ABI.new_segment = TRUE;
 
-      /* For now we eat this event */
-      gst_event_unref (event);
-      /* FIXME: collect-pads based elements need to create their own newsegment
-         event (and only one really)
-         (a) make the segment part of the GstCollectData structure of each pad,
-         so you can just check that once you have a buffer queued on that pad,
-         (b) you can override a pad's event function with your own,
-         catch the newsegment event and then pass it on to the original
-         gstcollectpads event function
-         (that's what avimux does for something IIRC)
-         see #340060
-       */
-      return TRUE;
+      goto forward_or_eat;
     }
     default:
-      goto beach;
+      goto forward_or_default;
   }
 
-beach:
-  return gst_pad_event_default (pad, event);
+forward_or_default:
+  res = FALSE;
+  if (pads->event_func)
+    res = pads->event_func (pads, pad, event, pads->event_user_data);
+  if (!res)
+    res = gst_pad_event_default (pad, event);
+  return res;
+
+forward_or_eat:
+  if (pads->event_func)
+    res = pads->event_func (pads, pad, event, pads->event_user_data);
+  if (!res) {
+    gst_event_unref (event);
+    res = TRUE;
+  }
+  return res;
 
   /* ERRORS */
 not_ours:
--- gstcollectpads.h	2006-05-04 21:30:01.000000000 +0300
+++ gstcollectpads.h.patched	2006-05-03 21:06:10.000000000 +0300
@@ -77,6 +77,19 @@
  */
 typedef GstFlowReturn (*GstCollectPadsFunction) (GstCollectPads *pads, gpointer user_data);
 
+/**
+ * GstCollectPadsEventFunction:
+ * @pads: the #GstCollectPads that trigered the callback
+ * @pad: the @GstPad that received an event
+ * @event: the #GstEvent received
+ * @user_data: user data passed to gst_collect_pads_set_event_function()
+ *
+ * A function that will be called after collectpads has processed the event.
+ *
+ * Returns: %TRUE if the pad could handle the event
+ */
+typedef gboolean (*GstCollectPadsEventFunction) (GstCollectPads *pads, GstPad * pad, GstEvent * event, gpointer user_data);
+
 #define GST_COLLECT_PADS_GET_COND(pads) (((GstCollectPads *)pads)->cond)
 #define GST_COLLECT_PADS_WAIT(pads)     (g_cond_wait (GST_COLLECT_PADS_GET_COND (pads), GST_OBJECT_GET_LOCK (pads)))
 #define GST_COLLECT_PADS_SIGNAL(pads)   (g_cond_signal (GST_COLLECT_PADS_GET_COND (pads)))
@@ -108,6 +121,9 @@
   guint		 eospads;		/* number of pads that are EOS */
 
   gboolean	 started;
+  
+  GstCollectPadsEventFunction event_func; /* function and user_data for event callback */
+  gpointer	 event_user_data;
 
   /*< private >*/
   gpointer       _gst_reserved[GST_PADDING];
@@ -125,9 +141,12 @@
 /* creating the object */
 GstCollectPads*	gst_collect_pads_new	 	(void);
 
-/* set the callback */
+/* set the callbacks */
 void		gst_collect_pads_set_function 	(GstCollectPads *pads, GstCollectPadsFunction func,
 						 gpointer user_data);
+                                                 
+void            gst_collect_pads_set_event_function (GstCollectPads *pads, GstCollectPadsEventFunction func,
+						 gpointer user_data);
 
 /* pad management */
 GstCollectData*	gst_collect_pads_add_pad	(GstCollectPads *pads, GstPad *pad, guint size);
