[gst-cvs] CVS: gstreamer/plugins/avi gstavidemux.c,1.9,1.9.4.1 gstavidemux.h,1.3,1.3.4.1

Wim Taymans wtay at users.sourceforge.net
Sun Sep 16 11:26:03 PDT 2001


Update of /cvsroot/gstreamer/gstreamer/plugins/avi
In directory usw-pr-cvs1:/tmp/cvs-serv9797

Modified Files:
      Tag: BRANCH-EVENTS1
	gstavidemux.c gstavidemux.h 
Log Message:
A new avidemuxer based on bytestreams.


Index: gstavidemux.c
===================================================================
RCS file: /cvsroot/gstreamer/gstreamer/plugins/avi/gstavidemux.c,v
retrieving revision 1.9
retrieving revision 1.9.4.1
diff -u -d -r1.9 -r1.9.4.1
--- gstavidemux.c	2001/08/21 20:16:45	1.9
+++ gstavidemux.c	2001/09/16 18:25:49	1.9.4.1
@@ -24,7 +24,6 @@
 #include "gstavidemux.h"
 
 
-
 /* elementfactory information */
 static GstElementDetails gst_avi_demux_details = {
   ".avi parser",
@@ -99,10 +98,10 @@
 static void 	gst_avi_demux_class_init	(GstAviDemuxClass *klass);
 static void 	gst_avi_demux_init		(GstAviDemux *avi_demux);
 
-static void 	gst_avi_demux_chain 		(GstPad *pad, GstBuffer *buf);
 static void 	gst_avi_demux_loop 		(GstElement *element);
 
-static void     gst_avi_demux_get_property      (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec);
+static void     gst_avi_demux_get_property      (GObject *object, guint prop_id, 	
+						 GValue *value, GParamSpec *pspec);
 
 
 static GstElementClass *parent_class = NULL;
@@ -205,16 +204,16 @@
 }
 
 static void
-gst_avi_demux_avih (GstRiffChunk *chunk,
-		   GstAviDemux *avi_demux)
+gst_avi_demux_avih (GstAviDemux *avi_demux)
 {
   gst_riff_avih *avih;
-  g_return_if_fail (chunk != NULL);
-  g_return_if_fail (GST_IS_AVI_DEMUX (avi_demux));
+  GstByteStream *bs = avi_demux->bs;
+  GstBuffer *buf;
 
-  avih = (gst_riff_avih *)chunk->data;
+  buf = gst_bytestream_bytes_peek (bs, sizeof (gst_riff_avih));
+  avih = (gst_riff_avih *) GST_BUFFER_DATA (buf);
 
-  GST_INFO (GST_CAT_PLUGIN_INFO, "gst_avi_demux: avih tag found size %08x", chunk->size);
+  GST_INFO (GST_CAT_PLUGIN_INFO, "gst_avi_demux: avih tag found");
   GST_INFO (GST_CAT_PLUGIN_INFO, "gst_avi_demux:  us_frame    %d", GUINT32_FROM_LE (avih->us_frame));
   GST_INFO (GST_CAT_PLUGIN_INFO, "gst_avi_demux:  max_bps     %d", GUINT32_FROM_LE (avih->max_bps));
   GST_INFO (GST_CAT_PLUGIN_INFO, "gst_avi_demux:  pad_gran    %d", GUINT32_FROM_LE (avih->pad_gran));
@@ -233,16 +232,21 @@
   avi_demux->time_interval = GUINT32_FROM_LE (avih->us_frame);
   avi_demux->tot_frames = GUINT32_FROM_LE (avih->tot_frames);
   avi_demux->flags = GUINT32_FROM_LE (avih->flags);
+
+  gst_buffer_unref (buf);
 }
 
 static void 
-gst_avi_demux_strh (GstRiffChunk *chunk, 
-		   GstAviDemux *avi_demux)
+gst_avi_demux_strh (GstAviDemux *avi_demux)
 {
   gst_riff_strh *strh;
+  GstByteStream *bs = avi_demux->bs;
+  GstBuffer *buf;
 
-  strh = (gst_riff_strh *)chunk->data;
-  GST_INFO (GST_CAT_PLUGIN_INFO, "gst_avi_demux: strh tag found size %08x", chunk->size);
+  buf =  gst_bytestream_bytes_peek (bs, sizeof (gst_riff_strh));
+  strh = (gst_riff_strh *) GST_BUFFER_DATA (buf);
+
+  GST_INFO (GST_CAT_PLUGIN_INFO, "gst_avi_demux: strh tag found");
   GST_INFO (GST_CAT_PLUGIN_INFO, "gst_avi_demux:  type        0x%08x (%s)", 
 		  GUINT32_FROM_LE (strh->type), gst_riff_id_to_fourcc (strh->type));
   GST_INFO (GST_CAT_PLUGIN_INFO, "gst_avi_demux:  fcc_handler 0x%08x (%s)", 
@@ -257,17 +261,24 @@
   GST_INFO (GST_CAT_PLUGIN_INFO, "gst_avi_demux:  bufsize     %d", GUINT32_FROM_LE (strh->bufsize));
   GST_INFO (GST_CAT_PLUGIN_INFO, "gst_avi_demux:  quality     %d", GUINT32_FROM_LE (strh->quality));
   GST_INFO (GST_CAT_PLUGIN_INFO, "gst_avi_demux:  samplesize  %d", GUINT32_FROM_LE (strh->samplesize));
+
+  avi_demux->fcc_type = GUINT32_FROM_LE (strh->type);
+
+  gst_buffer_unref (buf);
 }
 
 static void 
-gst_avi_demux_strf_vids (GstRiffChunk *chunk, 
-		        GstAviDemux *avi_demux)
+gst_avi_demux_strf_vids (GstAviDemux *avi_demux)
 {
   gst_riff_strf_vids *strf;
   GstPad *srcpad;
+  GstByteStream *bs = avi_demux->bs;
+  GstBuffer *buf;
 
-  strf = (gst_riff_strf_vids *)chunk->data;
-  GST_INFO (GST_CAT_PLUGIN_INFO, "gst_avi_demux: strf tag found in context vids size %08x", chunk->size);
+  buf = gst_bytestream_bytes_peek (bs, sizeof (gst_riff_strf_vids));
+  strf = (gst_riff_strf_vids *) GST_BUFFER_DATA (buf);
+
+  GST_INFO (GST_CAT_PLUGIN_INFO, "gst_avi_demux: strf tag found in context vids");
   GST_INFO (GST_CAT_PLUGIN_INFO, "gst_avi_demux:  size        %d", GUINT32_FROM_LE (strf->size));
   GST_INFO (GST_CAT_PLUGIN_INFO, "gst_avi_demux:  width       %d", GUINT32_FROM_LE (strf->width));
   GST_INFO (GST_CAT_PLUGIN_INFO, "gst_avi_demux:  height      %d", GUINT32_FROM_LE (strf->height));
@@ -305,17 +316,22 @@
 
   avi_demux->video_pad[avi_demux->num_video_pads++] = srcpad;
   gst_element_add_pad (GST_ELEMENT (avi_demux), srcpad);
+
+  gst_buffer_unref (buf);
 }
 
 static void 
-gst_avi_demux_strf_auds (GstRiffChunk *chunk, 
-		           GstAviDemux *avi_demux)
+gst_avi_demux_strf_auds (GstAviDemux *avi_demux)
 {
   gst_riff_strf_auds *strf;
   GstPad *srcpad;
+  GstByteStream *bs = avi_demux->bs;
+  GstBuffer *buf;
 
-  strf = (gst_riff_strf_auds *)chunk->data;
-  GST_INFO (GST_CAT_PLUGIN_INFO, "gst_avi_demux: strf tag found in context auds size %08x", chunk->size);
+  buf = gst_bytestream_bytes_peek (bs, sizeof (gst_riff_strf_auds));
+  strf = (gst_riff_strf_auds *) GST_BUFFER_DATA (buf);
+
+  GST_INFO (GST_CAT_PLUGIN_INFO, "gst_avi_demux: strf tag found in context auds");
   GST_INFO (GST_CAT_PLUGIN_INFO, "gst_avi_demux:  format      %d", GUINT16_FROM_LE (strf->format));
   GST_INFO (GST_CAT_PLUGIN_INFO, "gst_avi_demux:  channels    %d", GUINT16_FROM_LE (strf->channels));
   GST_INFO (GST_CAT_PLUGIN_INFO, "gst_avi_demux:  rate        %d", GUINT32_FROM_LE (strf->rate));
@@ -342,17 +358,22 @@
 
   avi_demux->audio_pad[avi_demux->num_audio_pads++] = srcpad;
   gst_element_add_pad (GST_ELEMENT (avi_demux), srcpad);
+
+  gst_buffer_unref (buf);
 }
 
 static void 
-gst_avi_demux_strf_iavs (GstRiffChunk *chunk, 
-		           GstAviDemux *avi_demux)
+gst_avi_demux_strf_iavs (GstAviDemux *avi_demux)
 {
   gst_riff_strf_iavs *strf;
   GstPad *srcpad;
+  GstByteStream *bs = avi_demux->bs;
+  GstBuffer *buf;
 
-  strf = (gst_riff_strf_iavs *)chunk->data;
-  GST_INFO (GST_CAT_PLUGIN_INFO, "gst_avi_demux: strf tag found in context iavs size %08x", chunk->size);
+  buf = gst_bytestream_bytes_peek (bs, sizeof (gst_riff_strf_iavs));
+  strf = (gst_riff_strf_iavs *)GST_BUFFER_DATA (buf);
+
+  GST_INFO (GST_CAT_PLUGIN_INFO, "gst_avi_demux: strf tag found in context iavs");
   GST_INFO (GST_CAT_PLUGIN_INFO, "gst_avi_demux:  DVAAuxSrc   %08x", GUINT32_FROM_LE (strf->DVAAuxSrc));
   GST_INFO (GST_CAT_PLUGIN_INFO, "gst_avi_demux:  DVAAuxCtl   %08x", GUINT32_FROM_LE (strf->DVAAuxCtl));
   GST_INFO (GST_CAT_PLUGIN_INFO, "gst_avi_demux:  DVAAuxSrc1  %08x", GUINT32_FROM_LE (strf->DVAAuxSrc1));
@@ -383,7 +404,10 @@
 
   avi_demux->video_pad[avi_demux->num_video_pads++] = srcpad;
   gst_element_add_pad (GST_ELEMENT (avi_demux), srcpad);
+
+  gst_buffer_unref (buf);
 }
+
 static void
 gst_avidemux_parse_index (GstAviDemux *avi_demux,
 		            gulong offset)
@@ -417,285 +441,195 @@
   buf = gst_pad_pullregion(avi_demux->sinkpad, GST_REGION_OFFSET_LEN, avi_demux->index_offset, 0);
 }
 
-static void
-gst_new_riff_tag_found (GstRiffChunk *chunk,
-		        gpointer data)
+static inline gboolean 
+gst_avidemux_read_chunk (GstByteStream *bs, guint32 *id, guint32 *size)
 {
-  GstAviDemux *avi_demux;
-  gst_riff_strh *strh;
+  gst_riff_chunk *chunk;
   GstBuffer *buf;
 
-  GST_DEBUG (0,"gst_avi_demux_chain: new tag found size %08x id %s\n",
-		  chunk->size, gst_riff_id_to_fourcc(chunk->id));
+  buf = gst_bytestream_bytes_read (bs, sizeof (gst_riff_chunk));
+  chunk = (gst_riff_chunk *) GST_BUFFER_DATA (buf);
+    
+  *id =   GUINT32_FROM_LE (chunk->id);
+  *size = GUINT32_FROM_LE (chunk->size);
 
-  g_return_if_fail (chunk != NULL);
-  g_return_if_fail (data != NULL);
-  g_return_if_fail (GST_IS_AVI_DEMUX (data));
+  gst_buffer_unref (buf);
 
-  avi_demux = GST_AVI_DEMUX (data);
+  return TRUE;
+}
 
-  switch (chunk->id) {
+static gboolean
+gst_avidemux_process_chunk (GstAviDemux *avi_demux, guint64 filepos,
+			     guint32 desired_tag,
+			     gint rec_depth, guint32 *chunksize)
+{
+  guint32 chunkid;	
+  guint64 datapos;
+  GstByteStream *bs = avi_demux->bs;
+
+  if (!gst_avidemux_read_chunk (bs, &chunkid, chunksize)) {
+    printf ("  *****  Error reading chunk at filepos 0x%08llx\n", filepos);
+    return FALSE;
+  }
+  if (desired_tag) {		/* do we have to test identity? */
+    if (desired_tag != chunkid) {
+      printf ("\n\n *** Error: Expected chunk '%08x', found '%08x'\n",
+	      desired_tag, chunkid);
+      return FALSE;
+    }
+  }
+
+  GST_INFO (GST_CAT_PLUGIN_INFO, "chunkid %s, size %08x, filepos %08llx", 
+		  gst_riff_id_to_fourcc (chunkid), *chunksize, filepos);
+
+  datapos = filepos + sizeof (guint32) + sizeof (guint32);
+
+  switch (chunkid) {
+    case GST_RIFF_TAG_RIFF:
     case GST_RIFF_TAG_LIST:
-      switch (chunk->form) {
-	case GST_RIFF_LIST_hdrl:
-          avi_demux->state = GST_AVI_DEMUX_HDRL;
-          break;
-	case GST_RIFF_LIST_strl:
-          avi_demux->state = GST_AVI_DEMUX_STRL;
-          break;
-	case GST_RIFF_LIST_movi:
-	  GST_INFO (GST_CAT_PLUGIN_INFO, "avidemux: index offset %08lx", chunk->offset);
-	  avi_demux->index_offset = chunk->offset;
-	  gst_avidemux_parse_index (avi_demux, chunk->offset + chunk->size);
-          avi_demux->state = GST_AVI_DEMUX_MOVI;
-          break;
-	default:
-          GST_INFO (GST_CAT_PLUGIN_INFO, "gst_avi_demux_chain: invalid LIST tag found size %08x form %s",
-			  chunk->size, gst_riff_id_to_fourcc (chunk->form));
+    {
+      guint32 datashowed;
+      guint32 formtype;
+      guint32 subchunksize;	/* size of a read subchunk             */
+      GstBuffer *buf;
+
+      buf = gst_bytestream_bytes_read (bs, sizeof (guint32));
+      formtype = *(guint32 *)GST_BUFFER_DATA (buf);
+      gst_buffer_unref (buf);
+
+      /* print out the indented form of the chunk: */
+
+      datashowed = sizeof (guint32);	/* we showed the form type      */
+      datapos += datashowed;	/* for the rest of the routine  */
+
+      while (datashowed < *chunksize) {	/* while not showed all: */
+
+	guint32 subchunklen;	/* complete size of a subchunk  */
+
+	/* recurse for subchunks of RIFF and LIST chunks: */
+	if (!gst_avidemux_process_chunk (avi_demux, datapos, 0,
+			   rec_depth + 1, &subchunksize))
+	  return FALSE;
+
+	subchunklen = sizeof (guint32) + sizeof (guint32) + ((subchunksize + 1) & ~1);
+
+	datashowed += subchunklen;
+	datapos += subchunklen;
       }
+      *chunksize -= datashowed;
       break;
+    }
     case GST_RIFF_TAG_avih:
-      if (avi_demux->state != GST_AVI_DEMUX_HDRL) {
-        GST_INFO (GST_CAT_PLUGIN_INFO, "gst_avi_demux_chain: invalid avih found");
-      }
-      gst_avi_demux_avih (chunk, avi_demux);
-      avi_demux->state = GST_AVI_DEMUX_AVIH;
+      gst_avi_demux_avih (avi_demux);
       break;
     case GST_RIFF_TAG_strh:
-      gst_avi_demux_strh (chunk, avi_demux);
-      strh = (gst_riff_strh *)chunk->data;
-      switch (GUINT32_FROM_LE (strh->type)) {
-	case GST_RIFF_FCC_vids:
-          avi_demux->state = GST_AVI_DEMUX_STRH_VIDS;
-          break;
-	case GST_RIFF_FCC_auds:
-          avi_demux->state = GST_AVI_DEMUX_STRH_AUDS;
-	  break;
-	case GST_RIFF_FCC_iavs:
-          avi_demux->state = GST_AVI_DEMUX_STRH_IAVS;
-	  break;
-	case GST_RIFF_FCC_pads:
-	case GST_RIFF_FCC_txts:
-          GST_INFO (GST_CAT_PLUGIN_INFO, "gst_avi_demux_chain: strh type %d not supported", strh->type);
-	  break;
-	default:
-          GST_INFO (GST_CAT_PLUGIN_INFO, "gst_avi_demux_chain: invalid strh type %d", strh->type);
-      }
+    {
+      gst_avi_demux_strh (avi_demux);
       break;
+    }
     case GST_RIFF_TAG_strf:
-      switch (avi_demux->state) {
-	case GST_AVI_DEMUX_STRH_VIDS:
-          gst_avi_demux_strf_vids (chunk, avi_demux);
+      switch (avi_demux->fcc_type) {
+        case GST_RIFF_FCC_vids:
+          gst_avi_demux_strf_vids (avi_demux);
 	  break;
-	case GST_AVI_DEMUX_STRH_AUDS:
-	  gst_avi_demux_strf_auds (chunk, avi_demux);
+        case GST_RIFF_FCC_auds:
+          gst_avi_demux_strf_auds (avi_demux);
 	  break;
-	case GST_AVI_DEMUX_STRH_IAVS:
-	  gst_avi_demux_strf_iavs (chunk, avi_demux);
+        case GST_RIFF_FCC_iavs:
+          gst_avi_demux_strf_iavs (avi_demux);
 	  break;
+	case GST_RIFF_FCC_pads:
+	case GST_RIFF_FCC_txts:
 	default:
-          GST_INFO (GST_CAT_PLUGIN_INFO, "gst_avi_demux_chain: unknown strf received");
+          GST_INFO (GST_CAT_PLUGIN_INFO, "gst_avi_demux_chain: strh type %s not supported", gst_riff_id_to_fourcc (avi_demux->fcc_type));
+	  break;
       }
-      break;
-    case GST_RIFF_TAG_JUNK:
       break;
-    default:
-      if (avi_demux->state != GST_AVI_DEMUX_MOVI) {
-        GST_INFO (GST_CAT_PLUGIN_INFO, "gst_avi_demux_chain: unknown tag found %s size %08x",
-			gst_riff_id_to_fourcc (chunk->id), chunk->size);
-      }
-      else {
-        switch (chunk->id) {
-	  case GST_RIFF_00dc:
-	  case GST_RIFF_00db:
-	  case GST_RIFF_00__:
+    case GST_RIFF_00dc:
+    case GST_RIFF_00db:
+    case GST_RIFF_00__:
+    {
+      GST_DEBUG (0,"gst_avi_demux_chain: tag found %08x size %08x\n",
+		    chunkid, *chunksize);
 
-            GST_DEBUG (0,"gst_avi_demux_chain: tag found %08x size %08x offset %08lx\n",
-			    chunk->id, chunk->size, chunk->offset);
+      if (GST_PAD_CONNECTED (avi_demux->video_pad[0])) {
+	GstBuffer *buf;
 
-	    if (GST_PAD_CONNECTED (avi_demux->video_pad[0])) {
-	      buf = gst_buffer_new ();
-	      GST_BUFFER_DATA (buf) = g_malloc (chunk->size);
-	      GST_BUFFER_SIZE (buf) = chunk->size;
-	      GST_BUFFER_TIMESTAMP (buf) = avi_demux->next_time;
-	      memcpy (GST_BUFFER_DATA (buf), chunk->data, chunk->size);
-	      avi_demux->next_time += avi_demux->time_interval;
+        buf = gst_bytestream_bytes_peek (bs, *chunksize);
+        GST_BUFFER_TIMESTAMP (buf) = avi_demux->next_time;
+        avi_demux->next_time += avi_demux->time_interval;
 
-	      if (avi_demux->video_need_flush[0]) {
-	        avi_demux->video_need_flush[0] = FALSE;
-		GST_BUFFER_FLAG_SET (buf, GST_BUFFER_FLUSH);
-	      }
+        if (avi_demux->video_need_flush[0]) {
+          avi_demux->video_need_flush[0] = FALSE;
+  	  GST_BUFFER_FLAG_SET (buf, GST_BUFFER_FLUSH);
+        }
 
-              GST_DEBUG (0,"gst_avi_demux_chain: send video buffer %08x\n", chunk->size);
-	      gst_pad_push(avi_demux->video_pad[0], buf);
-              GST_DEBUG (0,"gst_avi_demux_chain: sent video buffer %08x %p\n",
-			      chunk->size, &avi_demux->video_pad[0]);
-	      avi_demux->current_frame++;
-	    }
+        GST_DEBUG (0,"gst_avi_demux_chain: send video buffer %08x\n", *chunksize);
+        gst_pad_push(avi_demux->video_pad[0], buf);
+        GST_DEBUG (0,"gst_avi_demux_chain: sent video buffer %08x %p\n",
+		      *chunksize, &avi_demux->video_pad[0]);
+        avi_demux->current_frame++;
+      }
+      *chunksize = (*chunksize + 1) & ~1;
+      break;
+    }
+    case GST_RIFF_01wb:
+    {
+      GST_DEBUG (0,"gst_avi_demux_chain: tag found %08x size %08x\n",
+		    chunkid, *chunksize);
 
-	    break;
+      if (GST_PAD_CONNECTED (avi_demux->audio_pad[0])) {
+	GstBuffer *buf;
 
-	  case GST_RIFF_01wb:
-	    if (GST_PAD_CONNECTED (avi_demux->audio_pad[0])) {
-	      buf = gst_buffer_new ();
-	      GST_BUFFER_DATA (buf) = g_malloc (chunk->size);
-	      GST_BUFFER_SIZE (buf) = chunk->size;
-	      memcpy (GST_BUFFER_DATA (buf), chunk->data, chunk->size);
-	      GST_DEBUG (0,"gst_avi_demux_chain: buffer: %08x end %08x\n",
-			      *(guint32 *)chunk->data,
-			      *(guint32 *)(chunk->data+chunk->size-4));
+        buf = gst_bytestream_bytes_peek (bs, *chunksize);
 
-	      if (avi_demux->audio_need_flush[0]) {
-		GST_DEBUG (0,"audio flush\n");
-	        avi_demux->audio_need_flush[0] = FALSE;
-		GST_BUFFER_FLAG_SET (buf, GST_BUFFER_FLUSH);
-	      }
+        if (avi_demux->audio_need_flush[0]) {
+  	  GST_DEBUG (0,"audio flush\n");
+          avi_demux->audio_need_flush[0] = FALSE;
+  	  GST_BUFFER_FLAG_SET (buf, GST_BUFFER_FLUSH);
+        }
 
-              GST_DEBUG (0,"gst_avi_demux_chain: send audio buffer %08x\n", chunk->size);
-	      gst_pad_push (avi_demux->audio_pad[0], buf);
-              GST_DEBUG (0,"gst_avi_demux_chain: sent audio buffer %08x\n", chunk->size);
-	    }
-	    break;
-	  default:
-	    g_warning ("avidemux: unknown chunk 0x%08x\n", chunk->id);
-	}
+        GST_DEBUG (0,"gst_avi_demux_chain: send audio buffer %08x\n", *chunksize);
+        gst_pad_push (avi_demux->audio_pad[0], buf);
+        GST_DEBUG (0,"gst_avi_demux_chain: sent audio buffer %08x\n", *chunksize);
       }
+      *chunksize = (*chunksize + 1) & ~1;
+      break;
+    }
   }
+  GST_INFO (GST_CAT_PLUGIN_INFO, "chunkid %s, flush %08x, filepos %08llx", 
+		  gst_riff_id_to_fourcc (chunkid), *chunksize, filepos);
+  gst_bytestream_bytes_flush (bs, *chunksize);
+
+  return TRUE;
 }
 
 static void
 gst_avi_demux_loop (GstElement *element)
 {
   GstAviDemux *avi_demux;
-  GstBuffer *buf;
+  guint32 chunksize;
 
   g_return_if_fail (element != NULL);
   g_return_if_fail (GST_IS_AVI_DEMUX (element));
 
   avi_demux = GST_AVI_DEMUX (element);
-
-  do {
-    GST_DEBUG (0,"gst_avi_demux_chain: pulling buffer \n");
-    buf = gst_pad_pull(avi_demux->sinkpad);
-    GST_DEBUG (0,"gst_avi_demux_chain: pulling buffer done\n");
-
-    if (buf) gst_avi_demux_chain(avi_demux->sinkpad, buf);
-  } while (!GST_ELEMENT_IS_COTHREAD_STOPPING(element));
-}
-
-static void
-gst_avi_demux_chain (GstPad *pad,
-		       GstBuffer *buf)
-{
-  GstAviDemux *avi_demux;
-  guchar *data;
-  gulong size;
-
-  g_return_if_fail (pad != NULL);
-  g_return_if_fail (GST_IS_PAD(pad));
-  g_return_if_fail (buf != NULL);
-  g_return_if_fail (GST_BUFFER_DATA(buf) != NULL);
-
-  avi_demux = GST_AVI_DEMUX (gst_pad_get_parent (pad));
-  GST_DEBUG (0,"gst_avi_demux_chain: got buffer in %u\n", GST_BUFFER_OFFSET (buf));
-  data = (guchar *)GST_BUFFER_DATA (buf);
-  size = GST_BUFFER_SIZE (buf);
 
-  /* we're in null state now, look for the RIFF header, start parsing */
-  if (avi_demux->state == GST_AVI_DEMUX_UNKNOWN) {
-    gint retval;
-
-    GST_INFO (GST_CAT_PLUGIN_INFO, "GstAviDemux: checking for RIFF format");
-
-    avi_demux->state = GST_AVI_DEMUX_REGULAR;
-
-    /* create a new RIFF parser */
-    avi_demux->riff = gst_riff_parser_new (gst_new_riff_tag_found, avi_demux);
-    /* give it the current buffer to start parsing */
-    retval = gst_riff_parser_next_buffer (avi_demux->riff,buf,0);
-    if (retval < 0) {
-      GST_INFO (GST_CAT_PLUGIN_INFO, "sorry, isn't RIFF");
-      return;
-    }
+  avi_demux->bs = gst_bytestream_new (avi_demux->sinkpad);
 
-    /* this has to be a file of form AVI for us to deal with it */
-    if (avi_demux->riff->form != GST_RIFF_RIFF_AVI) {
+  do {
+    if (!gst_avidemux_process_chunk (avi_demux, 0, GST_RIFF_TAG_RIFF, 0, &chunksize)) {
       GST_INFO (GST_CAT_PLUGIN_INFO, "sorry, isn't AVI");
       return;
     }
-    avi_demux->current_frame = 0;
-  } else {
-
-    if (GST_BUFFER_FLAG_IS_SET (buf, GST_BUFFER_FLUSH)) {
-      gint i;
-      gst_riff_index_entry *entry = NULL;
-      gulong offset = 0;
-
-      GST_DEBUG (0,"avidemux: flushing\n");
-      
-      for (i=0; i<GST_AVI_DEMUX_MAX_VIDEO_PADS; i++) {
-	avi_demux->video_need_flush[i] = TRUE;
-      }
-      for (i=0; i<GST_AVI_DEMUX_MAX_AUDIO_PADS; i++) {
-	avi_demux->audio_need_flush[i] = TRUE;
-      }
-      
-      avi_demux->current_frame = 0;
-	      
-      for (i=0; i<avi_demux->index_size; i++) {
-
-	entry = &avi_demux->index_entries[i];
-
-	offset = entry->offset + avi_demux->index_offset;
-
-	if ((entry->id == GST_RIFF_00dc) || (entry->id == GST_RIFF_00db)) 
-	{
-	  avi_demux->current_frame++;
-
-	  if (offset >= GST_BUFFER_OFFSET (buf) && (entry->flags & GST_RIFF_IF_KEYFRAME))
-            break;
-	}
-      }
-
-      if (!entry) 
-	GST_INFO (GST_CAT_PLUGIN_INFO, "avidemux: cannot sync");
-      else  {
-        avi_demux->resync_offset = offset;
-
-	GST_DEBUG (0,"avidemux: sync from %08x to %08lx\n", GST_BUFFER_OFFSET (buf), offset);
-
-        gst_riff_parser_resync (avi_demux->riff, offset);
-      }
-    }
-
-    if (avi_demux->resync_offset) {
-      if ((avi_demux->resync_offset - GST_BUFFER_OFFSET (buf))
-		      < GST_BUFFER_SIZE (buf)) {
-	
-	GstBuffer *outbuf;
-	
-	GST_DEBUG (0,"creating subbuffer %08lx %08lx\n", avi_demux->resync_offset - GST_BUFFER_OFFSET (buf), 
-			GST_BUFFER_SIZE (buf) - (avi_demux->resync_offset - GST_BUFFER_OFFSET (buf)));
-
-	outbuf = gst_buffer_create_sub (buf, avi_demux->resync_offset - GST_BUFFER_OFFSET (buf),
-			GST_BUFFER_SIZE (buf) - (avi_demux->resync_offset - GST_BUFFER_OFFSET (buf)));
-
-        gst_riff_parser_next_buffer (avi_demux->riff, outbuf, avi_demux->resync_offset);
-
-	avi_demux->resync_offset = 0;
+  } while (!GST_ELEMENT_IS_COTHREAD_STOPPING(element));
 
-        gst_buffer_unref (outbuf);
-      }
-    }
-    else {
-      gst_riff_parser_next_buffer (avi_demux->riff, buf, GST_BUFFER_OFFSET (buf));
-    }
-  }
-  gst_buffer_unref (buf);
+  gst_bytestream_destroy (avi_demux->bs);
 }
 
 static void
-gst_avi_demux_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
+gst_avi_demux_get_property (GObject *object, guint prop_id, GValue *value,
+			    GParamSpec *pspec)
 {
   GstAviDemux *src;
 
@@ -703,21 +637,20 @@
 
   src = GST_AVI_DEMUX (object);
 
-  switch(prop_id) {
+  switch (prop_id) {
     case ARG_BITRATE:
       break;
     case ARG_MEDIA_TIME:
-      g_value_set_long (value, (src->tot_frames*src->time_interval)/1000000);
+      g_value_set_long (value, (src->tot_frames * src->time_interval) / 1000000);
       break;
     case ARG_CURRENT_TIME:
-      g_value_set_long (value, (src->current_frame*src->time_interval)/1000000);
+      g_value_set_long (value, (src->current_frame * src->time_interval) / 1000000);
       break;
     default:
       break;
   }
 }
 
-
 static gboolean
 plugin_init (GModule *module, GstPlugin *plugin)
 {
@@ -725,6 +658,10 @@
   GstTypeFactory *type;
 
   /* this filter needs the riff parser */
+  if (!gst_library_load ("gstbytestream")) {
+    gst_info("avidemux: could not load support library: 'gstbytestream'\n");
+    return FALSE;
+  }
   if (!gst_library_load ("gstriff")) {
     gst_info("avidemux: could not load support library: 'gstriff'\n");
     return FALSE;

Index: gstavidemux.h
===================================================================
RCS file: /cvsroot/gstreamer/gstreamer/plugins/avi/gstavidemux.h,v
retrieving revision 1.3
retrieving revision 1.3.4.1
diff -u -d -r1.3 -r1.3.4.1
--- gstavidemux.h	2001/07/01 13:58:39	1.3
+++ gstavidemux.h	2001/09/16 18:25:49	1.3.4.1
@@ -25,6 +25,7 @@
 #include <config.h>
 #include <gst/gst.h>
 #include <libs/riff/gstriff.h>
+#include <libs/bytestream/gstbytestream.h>
 
 
 #ifdef __cplusplus
@@ -67,10 +68,12 @@
 
   /* AVI decoding state */
   gint state;
+  guint32 fcc_type;
 
   /* RIFF decoding state */
   GstRiff *riff;
   GstRiff *index;
+  GstByteStream *bs;
 
   gst_riff_index_entry *index_entries;
   gulong index_size;





More information about the Gstreamer-commits mailing list