cairotextoverlay: forward new segment events from the sink to the source
authorVincent Penquerc'h <vincent.penquerch@collabora.co.uk>
Sun, 23 Jan 2011 15:56:49 +0000 (15:56 +0000)
committerSebastian Dröge <sebastian.droege@collabora.co.uk>
Thu, 26 May 2011 09:35:01 +0000 (11:35 +0200)
Not doing so will cause buffers to be received by downstream without
a time base set.
We use the same method avimux uses to get access to the event when
collectpads got the sink event function.

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

ext/cairo/gsttextoverlay.c
ext/cairo/gsttextoverlay.h

index d9e6f7f..c210191 100644 (file)
@@ -109,6 +109,7 @@ static GstFlowReturn gst_text_overlay_collected (GstCollectPads * pads,
 static void gst_text_overlay_finalize (GObject * object);
 static void gst_text_overlay_font_init (GstCairoTextOverlay * overlay);
 static gboolean gst_text_overlay_src_event (GstPad * pad, GstEvent * event);
+static gboolean gst_text_overlay_video_event (GstPad * pad, GstEvent * event);
 
 /* These macros are adapted from videotestsrc.c */
 #define I420_Y_ROWSTRIDE(width) (GST_ROUND_UP_4(width))
@@ -277,6 +278,14 @@ gst_text_overlay_init (GstCairoTextOverlay * overlay,
   overlay->video_collect_data = gst_collect_pads_add_pad (overlay->collect,
       overlay->video_sinkpad, sizeof (GstCollectData));
 
+  /* FIXME: hacked way to override/extend the event function of
+   * GstCollectPads; because it sets its own event function giving the
+   * element no access to events. Nicked from avimux. */
+  overlay->collect_event =
+      (GstPadEventFunction) GST_PAD_EVENTFUNC (overlay->video_sinkpad);
+  gst_pad_set_event_function (overlay->video_sinkpad,
+      GST_DEBUG_FUNCPTR (gst_text_overlay_video_event));
+
   /* text pad will be added when it is linked */
   overlay->text_collect_data = NULL;
 }
@@ -963,6 +972,27 @@ gst_text_overlay_src_event (GstPad * pad, GstEvent * event)
   return ret;
 }
 
+static gboolean
+gst_text_overlay_video_event (GstPad * pad, GstEvent * event)
+{
+  gboolean ret = FALSE;
+  GstCairoTextOverlay *overlay = NULL;
+
+  overlay = GST_CAIRO_TEXT_OVERLAY (gst_pad_get_parent (pad));
+
+  if (GST_EVENT_TYPE (event) == GST_EVENT_NEWSEGMENT) {
+    GST_DEBUG_OBJECT (overlay,
+        "received new segment on video sink pad, forwarding");
+    gst_event_ref (event);
+    gst_pad_push_event (overlay->srcpad, event);
+  }
+
+  /* now GstCollectPads can take care of the rest, e.g. EOS */
+  ret = overlay->collect_event (pad, event);
+  gst_object_unref (overlay);
+  return ret;
+}
+
 static GstStateChangeReturn
 gst_text_overlay_change_state (GstElement * element, GstStateChange transition)
 {
index 8af3155..09cfd72 100644 (file)
@@ -48,6 +48,7 @@ struct _GstCairoTextOverlay {
     GstCollectPads       *collect;
     GstCollectData       *video_collect_data;
     GstCollectData       *text_collect_data;
+    GstPadEventFunction   collect_event;
 
     gint                  width;
     gint                  height;