ext/amrnb/amrnbparse.c: Rewrite terminally broken sinkpad activation code. and push...
authorMichael Smith <msmith@xiph.org>
Mon, 16 Apr 2007 15:15:07 +0000 (15:15 +0000)
committerMichael Smith <msmith@xiph.org>
Mon, 16 Apr 2007 15:15:07 +0000 (15:15 +0000)
Original commit message from CVS:
* ext/amrnb/amrnbparse.c: (gst_amrnbparse_init),
(gst_amrnbparse_sink_activate),
(gst_amrnbparse_sink_activate_pull):
Rewrite terminally broken sinkpad activation code.
Now actually supports pull-mode activation (didn't before), and push
mode activation doesn't leave the sinkpad flushing.

ChangeLog
ext/amrnb/amrnbparse.c

index 6a23ad2..0f6b648 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2007-04-16  Michael Smith  <msmith@fluendo.com>
+
+       * ext/amrnb/amrnbparse.c: (gst_amrnbparse_init),
+       (gst_amrnbparse_sink_activate),
+       (gst_amrnbparse_sink_activate_pull):
+         Rewrite terminally broken sinkpad activation code.
+         Now actually supports pull-mode activation (didn't before), and push
+         mode activation doesn't leave the sinkpad flushing.
+
 2007-04-12  Tim-Philipp Müller  <tim at centricular dot net>
 
        * gst/asfdemux/asfheaders.c:
index 89c2579..a3f43ba 100644 (file)
@@ -48,7 +48,7 @@ static void gst_amrnbparse_base_init (GstAmrnbParseClass * klass);
 static void gst_amrnbparse_class_init (GstAmrnbParseClass * klass);
 static void gst_amrnbparse_init (GstAmrnbParse * amrnbparse);
 
-//static const GstFormat *gst_amrnbparse_formats (GstPad * pad);
+/*static const GstFormat *gst_amrnbparse_formats (GstPad * pad);*/
 static const GstQueryType *gst_amrnbparse_querytypes (GstPad * pad);
 static gboolean gst_amrnbparse_query (GstPad * pad, GstQuery * query);
 
@@ -56,6 +56,8 @@ static gboolean gst_amrnbparse_sink_event (GstPad * pad, GstEvent * event);
 static GstFlowReturn gst_amrnbparse_chain (GstPad * pad, GstBuffer * buffer);
 static void gst_amrnbparse_loop (GstPad * pad);
 static gboolean gst_amrnbparse_sink_activate (GstPad * sinkpad);
+static gboolean gst_amrnbparse_sink_activate_pull (GstPad * sinkpad,
+    gboolean active);
 static GstStateChangeReturn gst_amrnbparse_state_change (GstElement * element,
     GstStateChange transition);
 
@@ -131,6 +133,8 @@ gst_amrnbparse_init (GstAmrnbParse * amrnbparse)
       GST_DEBUG_FUNCPTR (gst_amrnbparse_sink_event));
   gst_pad_set_activate_function (amrnbparse->sinkpad,
       gst_amrnbparse_sink_activate);
+  gst_pad_set_activatepull_function (amrnbparse->sinkpad,
+      gst_amrnbparse_sink_activate_pull);
   gst_element_add_pad (GST_ELEMENT (amrnbparse), amrnbparse->sinkpad);
 
   /* create the src pad */
@@ -487,36 +491,36 @@ gst_amrnbparse_sink_activate (GstPad * sinkpad)
 {
   gboolean result = FALSE;
   GstAmrnbParse *amrnbparse;
-  GstActivateMode mode;
 
-  amrnbparse = GST_AMRNBPARSE (GST_OBJECT_PARENT (sinkpad));
-
-  /* FIXME, this will never activate the element in pull mode.
-   * see -base/ext/ogg/gstoggdemux.c for an example. */
-  GST_OBJECT_LOCK (sinkpad);
-  mode = GST_PAD_ACTIVATE_MODE (sinkpad);
-  GST_OBJECT_UNLOCK (sinkpad);
+  amrnbparse = GST_AMRNBPARSE (gst_pad_get_parent (sinkpad));
+
+  if (gst_pad_check_pull_range (sinkpad)) {
+    GST_DEBUG ("Trying to activate in pull mode");
+    amrnbparse->seekable = TRUE;
+    amrnbparse->ts = 0;
+    result = gst_pad_activate_pull (sinkpad, TRUE);
+  } else {
+    GST_DEBUG ("Try to activate in push mode");
+    amrnbparse->seekable = FALSE;
+    result = gst_pad_activate_push (sinkpad, TRUE);
+  }
 
-  switch (mode) {
-    case GST_ACTIVATE_PUSH:
-      amrnbparse->seekable = FALSE;
-      result = TRUE;
-      break;
-    case GST_ACTIVATE_PULL:
-      /*gst_pad_peer_set_active (sinkpad, mode); */
-      amrnbparse->seekable = TRUE;
-      amrnbparse->ts = 0;
+  gst_object_unref (amrnbparse);
+  return result;
+}
 
-      result = gst_pad_start_task (sinkpad,
-          (GstTaskFunction) gst_amrnbparse_loop, sinkpad);
-      break;
-    case GST_ACTIVATE_NONE:
-      /* step 1, unblock clock sync (if any) */
+static gboolean
+gst_amrnbparse_sink_activate_pull (GstPad * sinkpad, gboolean active)
+{
+  gboolean result;
 
-      /* step 2, make sure streaming finishes */
-      result = gst_pad_stop_task (sinkpad);
-      break;
+  if (active) {
+    result = gst_pad_start_task (sinkpad,
+        (GstTaskFunction) gst_amrnbparse_loop, sinkpad);
+  } else {
+    result = gst_pad_stop_task (sinkpad);
   }
+
   return result;
 }