[gst-devel] events for mad

Joshua N Pritikin noreply at eth.net
Sat Dec 8 20:51:02 CET 2001


Here it is again.  This patch adds event support to the mad plugin.

Once patch is against gstmad.c#1.17 (tested), the other patch is
against HEAD (untested).

Feedback welcome.

-- 
Victory to the Divine Mother!!         after all,
  http://sahajayoga.org                  http://why-compete.org
-------------- next part --------------
Index: gstmad.c
===================================================================
RCS file: /cvsroot/gstreamer/gstreamer/plugins/mp3decode/mad/gstmad.c,v
retrieving revision 1.18
diff -u -r1.18 gstmad.c
--- gstmad.c	2001/12/04 22:12:46	1.18
+++ gstmad.c	2001/12/05 06:29:39
@@ -161,6 +161,8 @@
 
   mad = GST_MAD (user_data);
 
+ restart:
+
   // HACK HACK HACK HACK because mad's API is fragged, we have to try to
   // trap COTHREAD_STOPPING here
   if (GST_ELEMENT_IS_COTHREAD_STOPPING (mad)) {
@@ -174,16 +176,38 @@
 
     // deal with events
     if (GST_IS_EVENT (inbuf)) {
-      gst_element_set_state (GST_ELEMENT (mad), GST_STATE_PAUSED);
+      GstEvent *event = GST_EVENT (inbuf);
 
-      // FIXME call the default handler here?
-      if (GST_PAD_CONNECTED (mad->srcpad))
-        gst_pad_push (mad->srcpad, inbuf);
+      switch (GST_EVENT_TYPE (event)) {
+      case GST_EVENT_DISCONTINUOUS:
+	mad->need_sync = TRUE;
+	if (buffer) {
+	  gst_buffer_unref (buffer);
+	  buffer = NULL;
+	}
+	break;
+	
+      case GST_EVENT_EOS:
+	gst_element_set_state (GST_ELEMENT (mad), GST_STATE_PAUSED);
+	break;
+	
+      default:
+	g_warning ("Don't know how to cope with event type %d",
+		   GST_EVENT_TYPE (event));
+	break;
+      }
+
+      gst_event_free (event);
+
+      /* osssink, etc doesn't understand or need events yet
+	
+	if (GST_PAD_CONNECTED (mad->srcpad))
+	 gst_pad_push (mad->srcpad, inbuf); */
 
       // FIXME eek!!
       //cothread_switch(cothread_current_main());
 
-      return MAD_FLOW_BREAK;
+      goto restart;
     }
 
     if (buffer) {
@@ -195,11 +219,6 @@
   }
   while (GST_BUFFER_SIZE (buffer) < 4096);
 
-  if (GST_BUFFER_FLAG_IS_SET (buffer, GST_BUFFER_FLUSH)) {
-    GST_DEBUG (0, "flush\n");
-    mad->need_sync = TRUE;
-  }
-
   mad->last_time = GST_BUFFER_TIMESTAMP (buffer);
 
   /* thomas added this bit to implement timestamps */
@@ -323,7 +342,8 @@
   }
 
   if (mad->need_sync) {
-    GST_BUFFER_FLAG_SET (buffer, GST_BUFFER_FLUSH);
+    // use an event FIXME
+    // GST_BUFFER_FLAG_SET (buffer, GST_BUFFER_FLUSH);
     mad->need_sync = FALSE;
   }
   if (GST_PAD_CONNECTED (mad->srcpad))
-------------- next part --------------
Index: gstmad.c
===================================================================
RCS file: /cvsroot/gstreamer/gstreamer/plugins/mp3decode/mad/gstmad.c,v
retrieving revision 1.17
diff -u -r1.17 gstmad.c
--- gstmad.c	2001/10/17 22:04:11	1.17
+++ gstmad.c	2001/12/09 04:49:12
@@ -161,6 +161,8 @@
 
   mad = GST_MAD (user_data);
 
+ restart:
+
   // HACK HACK HACK HACK because mad's API is fragged, we have to try to
   // trap COTHREAD_STOPPING here
   if (GST_ELEMENT_IS_COTHREAD_STOPPING (mad)) {
@@ -171,20 +173,41 @@
   do {
     GstBuffer *inbuf;
     inbuf = gst_pad_pull (mad->sinkpad);
-
+    
     // deal with events
     if (GST_IS_EVENT (inbuf)) {
-      g_print ("have event!\n");
-      gst_element_set_state (GST_ELEMENT (mad), GST_STATE_PAUSED);
-
-      // FIXME call the default handler here?
+      GstEvent *event = GST_EVENT (inbuf);
+      
+      switch (GST_EVENT_TYPE (event)) {
+      case GST_EVENT_DISCONTINUOUS:
+	mad->need_sync = TRUE;
+	if (buffer) {
+	  gst_buffer_unref (buffer);
+	  buffer = NULL;
+	}
+	break;
+	
+      case GST_EVENT_EOS:
+	gst_element_set_state (GST_ELEMENT (mad), GST_STATE_PAUSED);
+	break;
+	
+      default:
+	g_warning ("Don't know how to cope with event type %d",
+		   GST_EVENT_TYPE (event));
+	break;
+      }
+      
+      gst_event_free (event);
+      
+      /* osssink, etc doesn't understand or need events yet
+	 
       if (GST_PAD_CONNECTED (mad->srcpad))
-        gst_pad_push (mad->srcpad, inbuf);
-
+         gst_pad_push (mad->srcpad, inbuf); */
+      
       // FIXME eek!!
       //cothread_switch(cothread_current_main());
-
-      return MAD_FLOW_BREAK;
+      
+      goto restart;
     }
 
     if (buffer) {
@@ -196,11 +219,6 @@
   }
   while (GST_BUFFER_SIZE (buffer) < 4096);
 
-  if (GST_BUFFER_FLAG_IS_SET (buffer, GST_BUFFER_FLUSH)) {
-    GST_DEBUG (0, "flush\n");
-    mad->need_sync = TRUE;
-  }
-
   mad->last_time = GST_BUFFER_TIMESTAMP (buffer);
   /* thomas added this bit to implement timestamps */
 #ifdef DEBUG_TIMESTAMP
@@ -323,7 +341,8 @@
   }
 
   if (mad->need_sync) {
-    GST_BUFFER_FLAG_SET (buffer, GST_BUFFER_FLUSH);
+    // use an event FIXME
+    // GST_BUFFER_FLAG_SET (buffer, GST_BUFFER_FLUSH);
     mad->need_sync = FALSE;
   }
   if (GST_PAD_CONNECTED (mad->srcpad))


More information about the gstreamer-devel mailing list