[gst-devel] mad events

vishnu at pobox.com vishnu at pobox.com
Fri Oct 26 22:14:02 CEST 2001


The attached patch makes mad work with events.  There is some additional
"cleanup" of the COTHREAD stuff which you may not want to apply.  i'm
not sure it's correct but it works and it seems to make more sense.

-- 
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.17
diff -u -p -r1.17 gstmad.c
--- gstmad.c	2001/10/17 22:04:11	1.17
+++ gstmad.c	2001/10/27 05:10:30
@@ -161,30 +161,52 @@ gst_mad_input (void *user_data,
 
   mad = GST_MAD (user_data);
 
-  // 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)) {
-    GST_DEBUG(0, "HACK HACK HACK, switching to cothread zero on COTHREAD_STOPPING\n");
-    cothread_switch(cothread_current_main());
-  }
+ restart:
 
   do {
     GstBuffer *inbuf;
+
+    // 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))
+      return MAD_FLOW_BREAK;
+
     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);
+      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 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) {
@@ -196,11 +218,6 @@ gst_mad_input (void *user_data,
   }
   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
@@ -268,6 +285,9 @@ gst_mad_output (void *data,
 
   mad = GST_MAD (data);
 
+  if (GST_ELEMENT_IS_COTHREAD_STOPPING (mad))
+    return MAD_FLOW_BREAK;
+
   GST_DEBUG (0, "decoder_out\n");
 
   /* header->sfreq or header->samplerate contains the sampling frequency */
@@ -323,7 +343,8 @@ gst_mad_output (void *data,
   }
 
   if (mad->need_sync) {
-    GST_BUFFER_FLAG_SET (buffer, GST_BUFFER_FLUSH);
+    // use an event XXX
+    // 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