[gst-cvs] CVS: gstreamer/gst/elements gstsinesrc.c,1.23,1.24 gstsinesrc.h,1.13,1.14 Makefile.am,1.29,1.30 gstaggregator.c,1.5,1.6 gstdisksrc.c,1.36,1.37 gstdisksrc.h,1.9,1.10 gstfakesink.c,1.23,1.24 gstfakesink.h,1.11,1.12 gstfakesrc.c,1.31,1.32 gstfakesrc.h,1.17,1.18 gstfilesrc.c,1.4,1.5 gsttee.c,1.8,1.9

Erik Walthinsen omegahacker at users.sourceforge.net
Wed Oct 17 03:23:07 PDT 2001


Update of /cvsroot/gstreamer/gstreamer/gst/elements
In directory usw-pr-cvs1:/tmp/cvs-serv21419/gst/elements

Modified Files:
	Makefile.am gstaggregator.c gstdisksrc.c gstdisksrc.h 
	gstfakesink.c gstfakesink.h gstfakesrc.c gstfakesrc.h 
	gstfilesrc.c gsttee.c 
Added Files:
	gstsinesrc.c gstsinesrc.h 
Log Message:
merge from EVENTS1 on 20011016



Index: Makefile.am
===================================================================
RCS file: /cvsroot/gstreamer/gstreamer/gst/elements/Makefile.am,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -d -r1.29 -r1.30
--- Makefile.am	2001/10/06 12:46:50	1.29
+++ Makefile.am	2001/10/17 10:21:24	1.30
@@ -8,6 +8,8 @@
 GSTHTTPSRC=
 endif
 
+#CFLAGS += -O2 -Wall -finstrument-functions -DGST_ENABLE_FUNC_INSTRUMENTATION
+
 libgstelements_la_DEPENDENCIES = ../libgst.la
 libgstelements_la_SOURCES =	\
 	gstelements.c		\
@@ -37,8 +39,10 @@
 	gstfdsink.h		\
 	gstpipefilter.h		\
 	gsttee.h		\
-	gstaggregator.h
-CFLAGS += -O2 -Wall
+	gstaggregator.h		\
+	gstsinesrc.h
+
+CFLAGS += -O2 -Wall 
 LDFLAGS += -lm
 
 libgstelements_la_LIBADD = $(GHTTP_LIBS)

Index: gstaggregator.c
===================================================================
RCS file: /cvsroot/gstreamer/gstreamer/gst/elements/gstaggregator.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- gstaggregator.c	2001/09/10 19:46:01	1.5
+++ gstaggregator.c	2001/10/17 10:21:24	1.6
@@ -76,7 +76,8 @@
 static void 	gst_aggregator_class_init	(GstAggregatorClass *klass);
 static void 	gst_aggregator_init		(GstAggregator *aggregator);
 
-static GstPad* 	gst_aggregator_request_new_pad	(GstElement *element, GstPadTemplate *temp);
+static GstPad* 	gst_aggregator_request_new_pad	(GstElement *element, GstPadTemplate *temp, const
+                                                 gchar *unused);
 
 static void 	gst_aggregator_set_property 	(GObject *object, guint prop_id, 
 						 const GValue *value, GParamSpec *pspec);
@@ -150,7 +151,7 @@
 }
 
 static GstPad*
-gst_aggregator_request_new_pad (GstElement *element, GstPadTemplate *templ) 
+gst_aggregator_request_new_pad (GstElement *element, GstPadTemplate *templ, const gchar *unused) 
 {
   gchar *name;
   GstPad *sinkpad;

Index: gstdisksrc.c
===================================================================
RCS file: /cvsroot/gstreamer/gstreamer/gst/elements/gstdisksrc.c,v
retrieving revision 1.36
retrieving revision 1.37
diff -u -d -r1.36 -r1.37
--- gstdisksrc.c	2001/08/22 21:45:25	1.36
+++ gstdisksrc.c	2001/10/17 10:21:24	1.37
@@ -64,8 +64,8 @@
 static void		gst_disksrc_get_property	(GObject *object, guint prop_id, 
 							 GValue *value, GParamSpec *pspec);
 
-static GstBuffer *	gst_disksrc_get			(GstPad *pad);
-static GstBuffer *	gst_disksrc_get_region		(GstPad *pad,GstRegionType type,guint64 offset,guint64 len);
+static GstBuffer*	gst_disksrc_get			(GstPad *pad);
+static GstBufferPool* 	gst_disksrc_get_bufferpool 	(GstPad *pad);
 
 static GstElementStateReturn	
                  	gst_disksrc_change_state	(GstElement *element);
@@ -73,7 +73,7 @@
 static gboolean		gst_disksrc_open_file		(GstDiskSrc *src);
 static void		gst_disksrc_close_file		(GstDiskSrc *src);
 
-static GstElementClass *parent_class = NULL;
+static GstElementClass* parent_class = NULL;
 //static guint gst_disksrc_signals[LAST_SIGNAL] = { 0 };
 
 GType
@@ -133,8 +133,8 @@
 //  GST_FLAG_SET (disksrc, GST_SRC_);
 
   disksrc->srcpad = gst_pad_new ("src", GST_PAD_SRC);
-  gst_pad_set_get_function (disksrc->srcpad,gst_disksrc_get);
-  gst_pad_set_getregion_function (disksrc->srcpad,gst_disksrc_get_region);
+  gst_pad_set_get_function (disksrc->srcpad, gst_disksrc_get);
+  gst_pad_set_bufferpool_function (disksrc->srcpad, gst_disksrc_get_bufferpool);
   gst_element_add_pad (GST_ELEMENT (disksrc), disksrc->srcpad);
 
   disksrc->filename = NULL;
@@ -220,120 +220,97 @@
   }
 }
 
-/**
- * gst_disksrc_get:
- * @pad: #GstPad to push a buffer from
- *
- * Push a new buffer from the disksrc at the current offset.
- */
-static GstBuffer *
-gst_disksrc_get (GstPad *pad)
+static GstBuffer*
+gst_disksrc_buffer_new (GstBufferPool *pool, gint64 location, gint size, gpointer user_data)
 {
   GstDiskSrc *src;
   GstBuffer *buf;
-
-  g_return_val_if_fail (pad != NULL, NULL);
-  src = GST_DISKSRC (gst_pad_get_parent (pad));
-  g_return_val_if_fail (GST_FLAG_IS_SET (src, GST_DISKSRC_OPEN), NULL);
 
+  src = GST_DISKSRC (user_data);
 
-  /* deal with EOF state */
-  if (src->curoffset >= src->size) {
-    GST_DEBUG (0,"map offset %ld >= size %ld --> eos\n", src->curoffset, src->size);
-    gst_pad_event(pad, GST_EVENT_EOS, 0LL, 0);
-    buf =  gst_buffer_new();
-    GST_BUFFER_FLAG_SET (buf, GST_BUFFER_EOS);
-    return buf;
-  }
-
-  /* create the buffer */
-  // FIXME: should eventually use a bufferpool for this
   buf = gst_buffer_new ();
-
   g_return_val_if_fail (buf != NULL, NULL);
 
   /* simply set the buffer to point to the correct region of the file */
-  GST_BUFFER_DATA (buf) = src->map + src->curoffset;
-  GST_BUFFER_OFFSET (buf) = src->curoffset;
+  GST_BUFFER_DATA (buf) = src->map + location;
+  GST_BUFFER_OFFSET (buf) = location;
   GST_BUFFER_FLAG_SET (buf, GST_BUFFER_DONTFREE);
 
-  if ((src->curoffset + src->bytes_per_read) > src->size) {
-    GST_BUFFER_SIZE (buf) = src->size - src->curoffset;
-    // FIXME: set the buffer's EOF bit here
-  } else
-    GST_BUFFER_SIZE (buf) = src->bytes_per_read;
+  if ((location + size) > src->size) 
+    GST_BUFFER_SIZE (buf) = src->size - location;
+  else
+    GST_BUFFER_SIZE (buf) = size;
 
   GST_DEBUG (0,"map %p, offset %ld (%p), size %d\n", src->map, src->curoffset,
              src->map + src->curoffset, GST_BUFFER_SIZE (buf));
 
-  //gst_util_dump_mem (GST_BUFFER_DATA (buf), GST_BUFFER_SIZE (buf));
+  return buf;
+}
 
-  src->curoffset += GST_BUFFER_SIZE (buf);
+static void
+gst_disksrc_buffer_free (GstBuffer *buf)
+{
+  // FIXME do something here
+}
 
-  if (src->new_seek) {
-    GST_BUFFER_FLAG_SET (buf, GST_BUFFER_FLUSH);
-    GST_DEBUG (0,"new seek\n");
-    src->new_seek = FALSE;
+static GstBufferPool*
+gst_disksrc_get_bufferpool (GstPad *pad)
+{
+  GstDiskSrc *src;
+  
+  src = GST_DISKSRC (gst_pad_get_parent (pad));
+
+  if (!src->bufferpool) {
+    src->bufferpool = gst_buffer_pool_new ();
+    gst_buffer_pool_set_buffer_new_function 	(src->bufferpool, gst_disksrc_buffer_new);
+    gst_buffer_pool_set_buffer_free_function 	(src->bufferpool, gst_disksrc_buffer_free);
+    gst_buffer_pool_set_user_data 		(src->bufferpool, src);
   }
 
-  /* we're done, return the buffer */
-  return buf;
+  return src->bufferpool;
 }
 
 /**
- * gst_disksrc_get_region:
- * @src: #GstSrc to push a buffer from
- * @offset: offset in file
- * @size: number of bytes
+ * gst_disksrc_get:
+ * @pad: #GstPad to push a buffer from
  *
- * Push a new buffer from the disksrc of given size at given offset.
+ * Push a new buffer from the disksrc at the current offset.
  */
 static GstBuffer *
-gst_disksrc_get_region (GstPad *pad, GstRegionType type,guint64 offset,guint64 len)
+gst_disksrc_get (GstPad *pad)
 {
   GstDiskSrc *src;
   GstBuffer *buf;
 
   g_return_val_if_fail (pad != NULL, NULL);
-  g_return_val_if_fail (type == GST_REGION_OFFSET_LEN, NULL);
-
   src = GST_DISKSRC (gst_pad_get_parent (pad));
-
-  g_return_val_if_fail (GST_IS_DISKSRC (src), NULL);
   g_return_val_if_fail (GST_FLAG_IS_SET (src, GST_DISKSRC_OPEN), NULL);
 
+
   /* deal with EOF state */
-  if (offset >= src->size) {
-    gst_pad_event (pad, GST_EVENT_EOS, 0LL, 0);
-    GST_DEBUG (0,"map offset %lld >= size %ld --> eos\n", offset, src->size);
-    //FIXME
+  if (src->curoffset >= src->size) {
+    GST_DEBUG (0,"map offset %ld >= size %ld --> eos\n", src->curoffset, src->size);
+    gst_pad_event(pad, GST_EVENT_EOS, 0LL, 0);
     buf =  gst_buffer_new();
     GST_BUFFER_FLAG_SET (buf, GST_BUFFER_EOS);
     return buf;
   }
-
-  /* create the buffer */
-  // FIXME: should eventually use a bufferpool for this
-  buf = gst_buffer_new ();
-  g_return_val_if_fail (buf != NULL, NULL);
 
-  /* simply set the buffer to point to the correct region of the file */
-  GST_BUFFER_DATA (buf) = src->map + offset;
-  GST_BUFFER_OFFSET (buf) = offset;
-  GST_BUFFER_FLAG_SET (buf, GST_BUFFER_DONTFREE);
+  // FIXME use a bufferpool
+  buf = gst_disksrc_buffer_new (NULL, src->curoffset, src->bytes_per_read, src);
 
-  if ((offset + len) > src->size) {
-    GST_BUFFER_SIZE (buf) = src->size - offset;
-    // FIXME: set the buffer's EOF bit here
-  } else
-    GST_BUFFER_SIZE (buf) = len;
+  //gst_util_dump_mem (GST_BUFFER_DATA (buf), GST_BUFFER_SIZE (buf));
+  src->curoffset += GST_BUFFER_SIZE (buf);
 
-  GST_DEBUG (0,"map %p, offset %lld, size %d\n", src->map, offset, GST_BUFFER_SIZE (buf));
+  if (src->new_seek) {
+    GST_BUFFER_FLAG_SET (buf, GST_BUFFER_FLUSH);
+    GST_DEBUG (0,"new seek\n");
+    src->new_seek = FALSE;
+  }
 
-  /* we're done, return the buffer off now */
+  /* we're done, return the buffer */
   return buf;
 }
-
 
 /* open the file and mmap it, necessary to go to READY state */
 static gboolean 

Index: gstdisksrc.h
===================================================================
RCS file: /cvsroot/gstreamer/gstreamer/gst/elements/gstdisksrc.h,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- gstdisksrc.h	2001/06/25 01:20:08	1.9
+++ gstdisksrc.h	2001/10/17 10:21:24	1.10
@@ -64,6 +64,7 @@
   gchar *filename;
   /* fd */
   gint fd;
+  GstBufferPool *bufferpool;
 
   /* mapping parameters */
   gulong size;				/* how long is the file? */

Index: gstfakesink.c
===================================================================
RCS file: /cvsroot/gstreamer/gstreamer/gst/elements/gstfakesink.c,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -d -r1.23 -r1.24
--- gstfakesink.c	2001/08/22 21:45:25	1.23
+++ gstfakesink.c	2001/10/17 10:21:24	1.24
@@ -45,6 +45,7 @@
   ARG_0,
   ARG_NUM_SINKS,
   ARG_SILENT,
+  ARG_DUMP,
 };
 
 GST_PADTEMPLATE_FACTORY (fakesink_sink_factory,
@@ -58,7 +59,8 @@
 static void	gst_fakesink_class_init		(GstFakeSinkClass *klass);
 static void	gst_fakesink_init		(GstFakeSink *fakesink);
 
-static GstPad* 	gst_fakesink_request_new_pad 	(GstElement *element, GstPadTemplate *templ);
+static GstPad* 	gst_fakesink_request_new_pad 	(GstElement *element, GstPadTemplate *templ, const
+                                                 gchar *unused);
 
 static void	gst_fakesink_set_property	(GObject *object, guint prop_id, 
 						 const GValue *value, GParamSpec *pspec);
@@ -66,7 +68,6 @@
 						 GValue *value, GParamSpec *pspec);
 
 static void	gst_fakesink_chain		(GstPad *pad, GstBuffer *buf);
-static gboolean	gst_fakesink_event		(GstPad *pad, GstEventType event, guint64 timestamp, guint32 data);
 
 static GstElementClass *parent_class = NULL;
 static guint gst_fakesink_signals[LAST_SIGNAL] = { 0 };
@@ -109,6 +110,9 @@
   g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_SILENT,
     g_param_spec_boolean ("silent", "silent", "silent",
                           FALSE, G_PARAM_READWRITE)); 
+  g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_DUMP,
+    g_param_spec_boolean ("dump", "dump", "dump",
+                          FALSE, G_PARAM_READWRITE)); 
 
   gst_fakesink_signals[SIGNAL_HANDOFF] =
     g_signal_new ("handoff", G_TYPE_FROM_CLASS(klass), G_SIGNAL_RUN_LAST,
@@ -129,15 +133,15 @@
   pad = gst_pad_new ("sink", GST_PAD_SINK);
   gst_element_add_pad (GST_ELEMENT (fakesink), pad);
   gst_pad_set_chain_function (pad, GST_DEBUG_FUNCPTR (gst_fakesink_chain));
-  gst_pad_set_event_function (pad, GST_DEBUG_FUNCPTR (gst_fakesink_event));
 
   fakesink->sinkpads = g_slist_prepend (NULL, pad);
   fakesink->numsinkpads = 1;
   fakesink->silent = FALSE;
+  fakesink->dump = FALSE;
 }
 
 static GstPad*
-gst_fakesink_request_new_pad (GstElement *element, GstPadTemplate *templ)
+gst_fakesink_request_new_pad (GstElement *element, GstPadTemplate *templ, const gchar *unused)
 {
   gchar *name;
   GstPad *sinkpad;
@@ -175,6 +179,9 @@
     case ARG_SILENT:
       sink->silent = g_value_get_boolean (value);
       break;
+    case ARG_DUMP:
+      sink->dump = g_value_get_boolean (value);
+      break;
     default:
       break;
   }
@@ -197,6 +204,9 @@
     case ARG_SILENT:
       g_value_set_boolean (value, sink->silent);
       break;
+    case ARG_DUMP:
+      g_value_set_boolean (value, sink->dump);
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -206,9 +216,9 @@
 /**
  * gst_fakesink_chain:
  * @pad: the pad this faksink is connected to
- * @buf: the buffer that has to be absorbed
+ * @buffer: the buffer or event that has to be absorbed
  *
- * take the buffer from the pad and unref it without doing
+ * Take the buffer or event from the pad and unref it without doing
  * anything with it.
  */
 static void 
@@ -221,13 +231,34 @@
   g_return_if_fail (buf != NULL);
 
   fakesink = GST_FAKESINK (gst_pad_get_parent (pad));
+
+  if (GST_IS_EVENT(buf)) {
+    GstEvent *event = GST_EVENT (buf);
+
+    switch (GST_EVENT_TYPE (event)) {
+      case GST_EVENT_EOS:
+        g_print("fakesink: have EOS event!\n");
+        gst_element_set_state (GST_ELEMENT (fakesink), GST_STATE_PAUSED);
+	break;
+      default:
+        g_print("fakesink: have unhandled event!\n");
+	break;
+    }
+    gst_event_free (event);
+    return;
+  }
+
   if (!fakesink->silent)
-    g_print("fakesink: chain   ******* (%s:%s)< (%d bytes, %lld) \n",
-		    GST_DEBUG_PAD_NAME (pad), GST_BUFFER_SIZE (buf), GST_BUFFER_TIMESTAMP (buf));
-  
-  g_signal_emit (G_OBJECT (fakesink), gst_fakesink_signals[SIGNAL_HANDOFF], 0,
-                   buf);
+    g_print("fakesink: chain   ******* (%s:%s)< (%d bytes, %lld) %p\n",
+		GST_DEBUG_PAD_NAME (pad), GST_BUFFER_SIZE (buf), GST_BUFFER_TIMESTAMP (buf), buf);
+
+  g_signal_emit (G_OBJECT (fakesink), gst_fakesink_signals[SIGNAL_HANDOFF], 0, buf, pad);
 
+  if (fakesink->dump)
+  {
+    gst_util_dump_mem (GST_BUFFER_DATA (buf), GST_BUFFER_SIZE (buf));
+  }
+
   gst_buffer_unref (buf);
 }
 
@@ -237,15 +268,4 @@
   gst_elementfactory_add_padtemplate (factory, GST_PADTEMPLATE_GET (fakesink_sink_factory));
 
   return TRUE;
-}
-
-
-
-static gboolean
-gst_fakesink_event (GstPad *pad, GstEventType event, guint64 timestamp, guint32 data)
-{
-  GST_DEBUG (GST_CAT_EVENT, "fakesink has event %d on pad %s:%s\n",event,GST_DEBUG_PAD_NAME(pad));
-  if (event == GST_EVENT_EOS) {
-    GST_DEBUG(GST_CAT_EVENT, "have EOS\n");
-  }
 }

Index: gstfakesink.h
===================================================================
RCS file: /cvsroot/gstreamer/gstreamer/gst/elements/gstfakesink.h,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- gstfakesink.h	2001/07/11 16:45:43	1.11
+++ gstfakesink.h	2001/10/17 10:21:24	1.12
@@ -57,6 +57,7 @@
   GSList *sinkpads;
   gint numsinkpads;
   gboolean silent;
+  gboolean dump;
 };
 
 struct _GstFakeSinkClass {

Index: gstfakesrc.c
===================================================================
RCS file: /cvsroot/gstreamer/gstreamer/gst/elements/gstfakesrc.c,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -d -r1.31 -r1.32
--- gstfakesrc.c	2001/08/22 21:45:25	1.31
+++ gstfakesrc.c	2001/10/17 10:21:24	1.32
@@ -21,6 +21,9 @@
  */
 
 
+#include <stdlib.h>
+#include <string.h>
+
 #include <gstfakesrc.h>
 
 
@@ -47,10 +50,17 @@
   ARG_NUM_SOURCES,
   ARG_LOOP_BASED,
   ARG_OUTPUT,
+  ARG_DATA,
+  ARG_SIZETYPE,
+  ARG_SIZEMIN,
+  ARG_SIZEMAX,
+  ARG_FILLTYPE,
   ARG_PATTERN,
   ARG_NUM_BUFFERS,
   ARG_EOS,
-  ARG_SILENT
+  ARG_SILENT,
+  ARG_DUMP,
+  ARG_PARENTSIZE
 };
 
 GST_PADTEMPLATE_FACTORY (fakesrc_src_factory,
@@ -82,13 +92,70 @@
   return fakesrc_output_type;
 }
 
+#define GST_TYPE_FAKESRC_DATA (gst_fakesrc_data_get_type())
+static GType
+gst_fakesrc_data_get_type (void) 
+{
+  static GType fakesrc_data_type = 0;
+  static GEnumValue fakesrc_data[] = {
+    { FAKESRC_DATA_ALLOCATE, 		"2", "Allocate data"},
+    { FAKESRC_DATA_SUBBUFFER, 		"3", "Subbuffer data"},
+    {0, NULL, NULL},
+  };
+  if (!fakesrc_data_type) {
+    fakesrc_data_type = g_enum_register_static ("GstFakeSrcData", fakesrc_data);
+  }
+  return fakesrc_data_type;
+}
+
+#define GST_TYPE_FAKESRC_SIZETYPE (gst_fakesrc_sizetype_get_type())
+static GType
+gst_fakesrc_sizetype_get_type (void) 
+{
+  static GType fakesrc_sizetype_type = 0;
+  static GEnumValue fakesrc_sizetype[] = {
+    { FAKESRC_SIZETYPE_NULL, 		"1", "Send empty buffers"},
+    { FAKESRC_SIZETYPE_FIXED, 		"2", "Fixed size buffers (sizemax sized)"},
+    { FAKESRC_SIZETYPE_RANDOM, 		"3", "Random sized buffers (sizemin <= size <= sizemax)"},
+    {0, NULL, NULL},
+  };
+  if (!fakesrc_sizetype_type) {
+    fakesrc_sizetype_type = g_enum_register_static ("GstFakeSrcSizeType", fakesrc_sizetype);
+  }
+  return fakesrc_sizetype_type;
+}
+
+#define GST_TYPE_FAKESRC_FILLTYPE (gst_fakesrc_filltype_get_type())
+static GType
+gst_fakesrc_filltype_get_type (void) 
+{
+  static GType fakesrc_filltype_type = 0;
+  static GEnumValue fakesrc_filltype[] = {
+    { FAKESRC_FILLTYPE_NOTHING, 	"1", "Leave data as malloced"},
+    { FAKESRC_FILLTYPE_NULL, 		"2", "Fill buffers with zeros"},
+    { FAKESRC_FILLTYPE_RANDOM, 		"3", "Fill buffers with random crap"},
+    { FAKESRC_FILLTYPE_PATTERN, 	"4", "Fill buffers with pattern 0x00 -> 0xff"},
+    { FAKESRC_FILLTYPE_PATTERN_CONT, 	"5", "Fill buffers with pattern 0x00 -> 0xff that spans buffers"},
+    {0, NULL, NULL},
+  };
+  if (!fakesrc_filltype_type) {
+    fakesrc_filltype_type = g_enum_register_static ("GstFakeSrcFillType", fakesrc_filltype);
+  }
+  return fakesrc_filltype_type;
+}
+
 static void		gst_fakesrc_class_init		(GstFakeSrcClass *klass);
 static void		gst_fakesrc_init		(GstFakeSrc *fakesrc);
 
 static GstPad* 		gst_fakesrc_request_new_pad 	(GstElement *element, GstPadTemplate *templ);
-static void		gst_fakesrc_set_property	(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec);
-static void		gst_fakesrc_get_property	(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec);
+static void 		gst_fakesrc_update_functions 	(GstFakeSrc *src);
+static void		gst_fakesrc_set_property	(GObject *object, guint prop_id, 
+							 const GValue *value, GParamSpec *pspec);
+static void		gst_fakesrc_get_property	(GObject *object, guint prop_id, 
+							 GValue *value, GParamSpec *pspec);
 
+static GstElementStateReturn gst_fakesrc_change_state 	(GstElement *element);
+
 static GstBuffer*	gst_fakesrc_get			(GstPad *pad);
 static void 		gst_fakesrc_loop		(GstElement *element);
 
@@ -137,6 +204,24 @@
   g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_OUTPUT,
     g_param_spec_enum("output","output","output",
                       GST_TYPE_FAKESRC_OUTPUT,FAKESRC_FIRST_LAST_LOOP,G_PARAM_READWRITE)); // CHECKME!
+  g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_DATA,
+    g_param_spec_enum ("data", "data", "data",
+                       GST_TYPE_FAKESRC_DATA, FAKESRC_DATA_ALLOCATE, G_PARAM_READWRITE)); 
+  g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_SIZETYPE,
+    g_param_spec_enum ("sizetype", "sizetype", "sizetype",
+                       GST_TYPE_FAKESRC_SIZETYPE, FAKESRC_SIZETYPE_NULL, G_PARAM_READWRITE)); 
+  g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_SIZEMIN,
+    g_param_spec_int ("sizemin","sizemin","sizemin",
+                      0, G_MAXINT, 0, G_PARAM_READWRITE)); 
+  g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_SIZEMAX,
+    g_param_spec_int ("sizemax","sizemax","sizemax",
+                      0, G_MAXINT, 4096, G_PARAM_READWRITE)); 
+  g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_PARENTSIZE,
+    g_param_spec_int ("parentsize","parentsize","parentsize",
+                      0, G_MAXINT, 4096 * 10, G_PARAM_READWRITE)); 
+  g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_FILLTYPE,
+    g_param_spec_enum ("filltype", "filltype", "filltype",
+                       GST_TYPE_FAKESRC_FILLTYPE, FAKESRC_FILLTYPE_NULL, G_PARAM_READWRITE)); 
   g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_PATTERN,
     g_param_spec_string("pattern","pattern","pattern",
                         NULL, G_PARAM_READWRITE)); // CHECKME
@@ -149,6 +234,9 @@
   g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_SILENT,
     g_param_spec_boolean("silent","silent","silent",
                          FALSE, G_PARAM_READWRITE)); // CHECKME
+  g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_DUMP,
+    g_param_spec_boolean ("dump","dump","dump",
+                          FALSE, G_PARAM_READWRITE)); 
 
   gst_fakesrc_signals[SIGNAL_HANDOFF] =
     g_signal_new ("handoff", G_TYPE_FROM_CLASS(klass), G_SIGNAL_RUN_LAST,
@@ -159,7 +247,8 @@
   gobject_class->set_property = GST_DEBUG_FUNCPTR (gst_fakesrc_set_property);
   gobject_class->get_property = GST_DEBUG_FUNCPTR (gst_fakesrc_get_property);
 
-  gstelement_class->request_new_pad = GST_DEBUG_FUNCPTR (gst_fakesrc_request_new_pad);
+  gstelement_class->request_new_pad = 	GST_DEBUG_FUNCPTR (gst_fakesrc_request_new_pad);
+  gstelement_class->change_state = 	GST_DEBUG_FUNCPTR (gst_fakesrc_change_state);
 }
 
 static void 
@@ -176,17 +265,21 @@
   fakesrc->srcpads = g_slist_append (NULL, pad);
 
   fakesrc->loop_based = FALSE;
-
-  if (fakesrc->loop_based)
-    gst_element_set_loop_function (GST_ELEMENT (fakesrc), GST_DEBUG_FUNCPTR (gst_fakesrc_loop));
-  else
-    gst_pad_set_get_function (pad, GST_DEBUG_FUNCPTR (gst_fakesrc_get));
+  gst_fakesrc_update_functions (fakesrc);
 
   fakesrc->num_buffers = -1;
   fakesrc->buffer_count = 0;
   fakesrc->silent = FALSE;
-  // we're ready right away, since we don't have any args...
-//  gst_element_set_state(GST_ELEMENT(fakesrc),GST_STATE_READY);
+  fakesrc->dump = FALSE;
+  fakesrc->pattern_byte = 0x00;
+  fakesrc->need_flush = FALSE;
+  fakesrc->data = FAKESRC_DATA_ALLOCATE;
+  fakesrc->sizetype = FAKESRC_SIZETYPE_NULL;
+  fakesrc->filltype = FAKESRC_FILLTYPE_NOTHING;
+  fakesrc->sizemin = 0;
+  fakesrc->sizemax = 4096;
+  fakesrc->parent = NULL;
+  fakesrc->parentsize = 4096 * 10;
 }
 
 static GstPad*
@@ -216,6 +309,34 @@
   return srcpad;
 }
 
+static gboolean
+gst_fakesrc_event_handler (GstPad *pad, GstEvent *event)
+{
+  GstFakeSrc *src;
+
+  src = GST_FAKESRC (gst_pad_get_parent (pad));
+
+  switch (GST_EVENT_TYPE (event)) {
+    case GST_EVENT_SEEK:
+      g_print("fakesrc: have seek event\n");
+      src->buffer_count = GST_EVENT_SEEK_OFFSET (event);
+      if (!GST_EVENT_SEEK_FLUSH (event)) {
+        gst_event_free (event);
+        break;
+      }
+      // else we do a flush too
+    case GST_EVENT_FLUSH:
+      g_print("fakesrc: have flush event\n");
+      src->need_flush = TRUE;
+      break;
+    default:
+      g_print("fakesrc: have unhandled event\n");
+      break;
+  }
+
+  return TRUE;
+}
+
 static void
 gst_fakesrc_update_functions (GstFakeSrc *src)
 {
@@ -238,11 +359,26 @@
     else {
       gst_pad_set_get_function (pad, GST_DEBUG_FUNCPTR (gst_fakesrc_get));
     }
+
+    gst_pad_set_event_function (pad, gst_fakesrc_event_handler);
     pads = g_slist_next (pads);
   }
 }
 
 static void
+gst_fakesrc_alloc_parent (GstFakeSrc *src)
+{
+  GstBuffer *buf;
+
+  buf = gst_buffer_new ();
+  GST_BUFFER_DATA (buf) = g_malloc (src->parentsize);
+  GST_BUFFER_SIZE (buf) = src->parentsize;
+
+  src->parent = buf;
+  src->parentoffset = 0;
+}
+
+static void
 gst_fakesrc_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
 {
   GstFakeSrc *src;
@@ -257,6 +393,37 @@
       break;
     case ARG_OUTPUT:
       break;
+    case ARG_DATA:
+      src->data = g_value_get_int (value);
+      switch (src->data) {
+	case FAKESRC_DATA_ALLOCATE:
+          if (src->parent) {
+            gst_buffer_unref (src->parent);
+            src->parent = NULL;
+	  }
+          break;
+	case FAKESRC_DATA_SUBBUFFER:
+	  if (!src->parent)
+	    gst_fakesrc_alloc_parent (src);
+	default:
+          break;
+      }
+      break;
+    case ARG_SIZETYPE:
+      src->sizetype = g_value_get_int (value);
+      break;
+    case ARG_SIZEMIN:
+      src->sizemin = g_value_get_int (value);
+      break;
+    case ARG_SIZEMAX:
+      src->sizemax = g_value_get_int (value);
+      break;
+    case ARG_PARENTSIZE:
+      src->parentsize = g_value_get_int (value);
+      break;
+    case ARG_FILLTYPE:
+      src->filltype = g_value_get_int (value);
+      break;
     case ARG_PATTERN:
       break;
     case ARG_NUM_BUFFERS:
@@ -269,6 +436,9 @@
     case ARG_SILENT:
       src->silent = g_value_get_boolean (value);
       break;
+    case ARG_DUMP:
+      src->dump = g_value_get_boolean (value);
+      break;
     default:
       break;
   }
@@ -294,6 +464,24 @@
     case ARG_OUTPUT:
       g_value_set_int (value, src->output);
       break;
+    case ARG_DATA:
+      g_value_set_int (value, src->data);
+      break;
+    case ARG_SIZETYPE:
+      g_value_set_int (value, src->sizetype);
+      break;
+    case ARG_SIZEMIN:
+      g_value_set_int (value, src->sizemin);
+      break;
+    case ARG_SIZEMAX:
+      g_value_set_int (value, src->sizemax);
+      break;
+    case ARG_PARENTSIZE:
+      g_value_set_int (value, src->parentsize);
+      break;
+    case ARG_FILLTYPE:
+      g_value_set_int (value, src->filltype);
+      break;
     case ARG_PATTERN:
       g_value_set_string (value, src->pattern);
       break;
@@ -306,22 +494,151 @@
     case ARG_SILENT:
       g_value_set_boolean (value, src->silent);
       break;
+    case ARG_DUMP:
+      g_value_set_boolean (value, src->dump);
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
   }
 }
 
+static void
+gst_fakesrc_prepare_buffer (GstFakeSrc *src, GstBuffer *buf)
+{
+  if (GST_BUFFER_SIZE (buf) == 0) 
+    return;
 
-/**
- * gst_fakesrc_get:
- * @src: the faksesrc to get
- * 
- * generate an empty buffer and return it
- *
- * Returns: a new empty buffer
- */
+  switch (src->filltype) {
+    case FAKESRC_FILLTYPE_NULL:
+      memset (GST_BUFFER_DATA (buf), 0, GST_BUFFER_SIZE (buf));
+      break;
+    case FAKESRC_FILLTYPE_RANDOM:
+    {
+      gint i;
+      guint8 *ptr = GST_BUFFER_DATA (buf);
+
+      for (i = GST_BUFFER_SIZE (buf); i; i--) {
+	*ptr++ = (gint8)((255.0)*rand()/(RAND_MAX));
+      }
+      break;
+    }
+    case FAKESRC_FILLTYPE_PATTERN:
+      src->pattern_byte = 0x00;
+    case FAKESRC_FILLTYPE_PATTERN_CONT:
+    {
+      gint i;
+      guint8 *ptr = GST_BUFFER_DATA (buf);
+
+      for (i = GST_BUFFER_SIZE (buf); i; i--) {
+	*ptr++ = src->pattern_byte++;
+      }
+      break;
+    }
+    case FAKESRC_FILLTYPE_NOTHING:
+    default:
+      break;
+  }
+}
+
+static GstBuffer*
+gst_fakesrc_alloc_buffer (GstFakeSrc *src, guint size)
+{
+  GstBuffer *buf;
+
+  buf = gst_buffer_new ();
+  GST_BUFFER_SIZE(buf) = size;
+
+  if (size != 0) { 
+    switch (src->filltype) {
+      case FAKESRC_FILLTYPE_NOTHING:
+        GST_BUFFER_DATA(buf) = g_malloc (size);
+        break;
+      case FAKESRC_FILLTYPE_NULL:
+        GST_BUFFER_DATA(buf) = g_malloc0 (size);
+        break;
+      case FAKESRC_FILLTYPE_RANDOM:
+      case FAKESRC_FILLTYPE_PATTERN:
+      case FAKESRC_FILLTYPE_PATTERN_CONT:
+      default:
+        GST_BUFFER_DATA(buf) = g_malloc (size);
+        gst_fakesrc_prepare_buffer (src, buf);
+        break;
+    }
+  }
+
+  return buf;
+}
+
+static guint
+gst_fakesrc_get_size (GstFakeSrc *src)
+{
+  guint size;
+
+  switch (src->sizetype) {
+    case FAKESRC_SIZETYPE_FIXED:
+      size = src->sizemax;
+      break;
+    case FAKESRC_SIZETYPE_RANDOM:
+      size = src->sizemin + (guint8)(((gfloat)src->sizemax)*rand()/(RAND_MAX + (gfloat)src->sizemin));
+      break;
+    case FAKESRC_SIZETYPE_NULL:
+    default:
+      size = 0; 
+      break;
+  }
+
+  return size;
+}
+
 static GstBuffer *
+gst_fakesrc_create_buffer (GstFakeSrc *src)
+{
+  GstBuffer *buf;
+  guint size;
+  gboolean dump = src->dump;
+
+  size = gst_fakesrc_get_size (src);
+  if (size == 0)
+    return gst_buffer_new();
+
+  switch (src->data) {
+    case FAKESRC_DATA_ALLOCATE:
+      buf = gst_fakesrc_alloc_buffer (src, size);
+      break;
+    case FAKESRC_DATA_SUBBUFFER:
+      // see if we have a parent to subbuffer
+      if (!src->parent) {
+	gst_fakesrc_alloc_parent (src);
+	g_assert (src->parent);
+      }
+      // see if it's large enough
+      if ((GST_BUFFER_SIZE (src->parent) - src->parentoffset) >= size) {
+	 buf = gst_buffer_create_sub (src->parent, src->parentoffset, size);
+	 src->parentoffset += size;
+      }
+      else {
+	// the parent is useless now
+	gst_buffer_unref (src->parent);
+	src->parent = NULL;
+	// try again (this will allocate a new parent)
+        return gst_fakesrc_create_buffer (src);
+      }
+      gst_fakesrc_prepare_buffer (src, buf);
+      break;
+    default:
+      g_warning ("fakesrc: dunno how to allocate buffers !");
+      buf = gst_buffer_new();
+      break;
+  }
+  if (dump) {
+    gst_util_dump_mem (GST_BUFFER_DATA (buf), GST_BUFFER_SIZE (buf));
+  }
+
+  return buf;
+}
+
+static GstBuffer *
 gst_fakesrc_get(GstPad *pad)
 {
   GstFakeSrc *src;
@@ -333,9 +650,16 @@
 
   g_return_val_if_fail (GST_IS_FAKESRC (src), NULL);
 
+  if (src->need_flush) {
+    src->need_flush = FALSE;
+    g_print("fakesrc: sending FLUSH\n");
+    return GST_BUFFER(gst_event_new (GST_EVENT_FLUSH));
+  }
+
   if (src->num_buffers == 0) {
-    gst_pad_event (pad, GST_EVENT_EOS, 0LL, 0);
-    return NULL;
+    g_print("fakesrc: sending EOS\n");
+    gst_element_set_state (GST_ELEMENT (src), GST_STATE_PAUSED);
+    return GST_BUFFER(gst_event_new (GST_EVENT_EOS));
   }
   else {
     if (src->num_buffers > 0)
@@ -344,11 +668,11 @@
 
   if (src->eos) {
     GST_INFO (0, "fakesrc is setting eos on pad");
-    gst_pad_event (pad, GST_EVENT_EOS, 0LL, 0);
-    return NULL;
+    g_print("fakesrc: sending EOS\n");
+    return GST_BUFFER(gst_event_new (GST_EVENT_EOS));
   }
 
-  buf = gst_buffer_new();
+  buf = gst_fakesrc_create_buffer (src);
   GST_BUFFER_TIMESTAMP (buf) = src->buffer_count++;
 
   if (!src->silent)
@@ -356,7 +680,7 @@
                GST_DEBUG_PAD_NAME (pad), GST_BUFFER_SIZE (buf), GST_BUFFER_TIMESTAMP (buf));
 
   g_signal_emit (G_OBJECT (src), gst_fakesrc_signals[SIGNAL_HANDOFF], 0,
-                   buf);
+                   buf, pad);
 
   return buf;
 }
@@ -387,21 +711,20 @@
       GstBuffer *buf;
 
       if (src->num_buffers == 0) {
-        gst_pad_event (pad, GST_EVENT_EOS, 0LL, 0);
-        return;
+	src->eos = TRUE;
       }
       else {
-      if (src->num_buffers > 0)
-         src->num_buffers--;
+        if (src->num_buffers > 0)
+          src->num_buffers--;
       }
 
       if (src->eos) {
         GST_INFO (0, "fakesrc is setting eos on pad");
-        gst_pad_event (pad, GST_EVENT_EOS, 0LL, 0);
-        return;
+        gst_pad_push(pad, GST_BUFFER(gst_event_new (GST_EVENT_EOS)));
+	return;
       }
 
-      buf = gst_buffer_new();
+      buf = gst_fakesrc_create_buffer (src);
       GST_BUFFER_TIMESTAMP (buf) = src->buffer_count++;
 
       if (!src->silent)
@@ -409,12 +732,37 @@
                GST_DEBUG_PAD_NAME (pad), GST_BUFFER_SIZE (buf), GST_BUFFER_TIMESTAMP (buf));
 
       g_signal_emit (G_OBJECT (src), gst_fakesrc_signals[SIGNAL_HANDOFF], 0,
-                       buf);
+                       buf, pad);
       gst_pad_push (pad, buf);
 
       pads = g_slist_next (pads);
     }
   } while (!GST_ELEMENT_IS_COTHREAD_STOPPING (element));
+}
+
+static GstElementStateReturn
+gst_fakesrc_change_state (GstElement *element)
+{
+  GstFakeSrc *fakesrc;
+
+  g_return_val_if_fail (GST_IS_FAKESRC (element), GST_STATE_FAILURE);
+
+  fakesrc = GST_FAKESRC (element);
+
+  if (GST_STATE_PENDING (element) == GST_STATE_READY) {
+    fakesrc->buffer_count = 0;
+    fakesrc->pattern_byte = 0x00;
+    fakesrc->need_flush = FALSE;
+    if (fakesrc->parent) {
+      gst_buffer_unref (fakesrc->parent);
+      fakesrc->parent = NULL;
+    }
+  }
+
+  if (GST_ELEMENT_CLASS (parent_class)->change_state)
+    return GST_ELEMENT_CLASS (parent_class)->change_state (element);
+
+  return GST_STATE_SUCCESS;
 }
 
 gboolean

Index: gstfakesrc.h
===================================================================
RCS file: /cvsroot/gstreamer/gstreamer/gst/elements/gstfakesrc.h,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- gstfakesrc.h	2001/07/11 15:51:40	1.17
+++ gstfakesrc.h	2001/10/17 10:21:24	1.18
@@ -47,6 +47,25 @@
   FAKESRC_GET_ALWAYS_SUCEEDS,
 } GstFakeSrcOutputType;
 
+typedef enum {
+  FAKESRC_DATA_ALLOCATE = 1,
+  FAKESRC_DATA_SUBBUFFER,
+} GstFakeSrcDataType;
+
+typedef enum {
+  FAKESRC_SIZETYPE_NULL = 1,
+  FAKESRC_SIZETYPE_FIXED,
+  FAKESRC_SIZETYPE_RANDOM
+} GstFakeSrcSizeType;
+
+typedef enum {
+  FAKESRC_FILLTYPE_NOTHING = 1,
+  FAKESRC_FILLTYPE_NULL,
+  FAKESRC_FILLTYPE_RANDOM,
+  FAKESRC_FILLTYPE_PATTERN,
+  FAKESRC_FILLTYPE_PATTERN_CONT
+} GstFakeSrcFillType;
+
 #define GST_TYPE_FAKESRC \
   (gst_fakesrc_get_type())
 #define GST_FAKESRC(obj) \
@@ -64,16 +83,29 @@
 struct _GstFakeSrc {
   GstElement element;
 
-  gboolean loop_based;
-  gboolean eos;
-  gint numsrcpads;
-  GSList *srcpads;
+  gboolean 	loop_based;
+  gboolean 	eos;
+  gint 		numsrcpads;
+  GSList 	*srcpads;
+
   GstFakeSrcOutputType output;
-  gchar *pattern;
-  GList *patternlist;
-  gint num_buffers;
-  guint64 buffer_count;
-  gboolean silent;
+  GstFakeSrcDataType data;
+  GstFakeSrcSizeType sizetype;
+  GstFakeSrcFillType filltype;
+
+  guint 	sizemin;
+  guint 	sizemax;
+  GstBuffer 	*parent;
+  guint 	parentsize;
+  guint 	parentoffset;
+  guint8 	pattern_byte;
+  gchar 	*pattern;
+  GList 	*patternlist;
+  gint 		num_buffers;
+  guint64 	buffer_count;
+  gboolean 	silent;
+  gboolean 	dump;
+  gboolean 	need_flush;
 };
 
 struct _GstFakeSrcClass {

Index: gstfilesrc.c
===================================================================
RCS file: /cvsroot/gstreamer/gstreamer/gst/elements/gstfilesrc.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- gstfilesrc.c	2001/09/14 22:13:55	1.4
+++ gstfilesrc.c	2001/10/17 10:21:24	1.5
@@ -27,6 +27,7 @@
 #include <fcntl.h>
 #include <unistd.h>
 #include <sys/mman.h>
+#include <errno.h>
 
 
 /**********************************************************************
@@ -74,6 +75,9 @@
   "(C) 1999",
 };
 
+//#define fs_print(format,args...) g_print(format, ## args)
+#define fs_print(format,args...)
+
 
 #define GST_TYPE_FILESRC \
   (gst_filesrc_get_type())
@@ -110,10 +114,12 @@
   gboolean touch;			// whether to touch every page
 
   GstBuffer *mapbuf;
-  off_t mapsize;
+  size_t mapsize;
 
   GTree *map_regions;
   GMutex *map_regions_lock;
+
+  gboolean seek_happened;
 };
 
 struct _GstFileSrcClass {
@@ -135,6 +141,7 @@
   ARG_BLOCKSIZE,
   ARG_OFFSET,
   ARG_MAPSIZE,
+  ARG_TOUCH,
 };
 
 
@@ -203,6 +210,9 @@
   g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_MAPSIZE,
     g_param_spec_ulong("mmapsize","mmap() Block Size","Size in bytes of mmap()d regions",
                        0,G_MAXULONG,4*1048576,G_PARAM_READWRITE));
+  g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_TOUCH,
+    g_param_spec_boolean("touch","Touch read data","Touch data to force disk read before push()",
+                         TRUE,G_PARAM_READWRITE));
 
   gobject_class->set_property = gst_filesrc_set_property;
   gobject_class->get_property = gst_filesrc_get_property;
@@ -246,6 +256,8 @@
 
   src->map_regions = g_tree_new(gst_filesrc_bufcmp);
   src->map_regions_lock = g_mutex_new();
+
+  src->seek_happened = FALSE;
 }
 
 
@@ -286,6 +298,9 @@
       else
         GST_INFO(0, "invalid mapsize, must a multiple of pagesize, which is %d\n",src->pagesize);
       break;
+    case ARG_TOUCH:
+      src->touch = g_value_get_boolean (value);
+      break;
     default:
       break;
   }
@@ -320,6 +335,9 @@
     case ARG_MAPSIZE:
       g_value_set_ulong (value, src->mapsize);
       break;
+    case ARG_TOUCH:
+      g_value_set_boolean (value, src->touch);
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -331,7 +349,7 @@
 {
   GstFileSrc *src = GST_FILESRC(GST_BUFFER_POOL_PRIVATE(buf));
 
-  // fprintf(stderr,"freeing mmap()d buffer at %d+%d\n",GST_BUFFER_OFFSET(buf),GST_BUFFER_SIZE(buf));
+  fs_print ("freeing mmap()d buffer at %d+%d\n",GST_BUFFER_OFFSET(buf),GST_BUFFER_SIZE(buf));
 
   // remove the buffer from the list of available mmap'd regions
   g_mutex_lock(src->map_regions_lock);
@@ -347,21 +365,24 @@
 }
 
 static GstBuffer *
-gst_filesrc_map_region (GstFileSrc *src, off_t offset, off_t size)
+gst_filesrc_map_region (GstFileSrc *src, off_t offset, size_t size)
 {
   GstBuffer *buf;
   gint retval;
 
-//  fprintf(stderr,"mapping region %d+%d from file into memory\n",offset,size);
+  g_return_val_if_fail (offset >= 0, NULL);
+
+  fs_print  ("mapping region %08lx+%08lx from file into memory\n",offset,size);
 
   // time to allocate a new mapbuf
   buf = gst_buffer_new();
   // mmap() the data into this new buffer
   GST_BUFFER_DATA(buf) = mmap (NULL, size, PROT_READ, MAP_SHARED, src->fd, offset);
   if (GST_BUFFER_DATA(buf) == NULL) {
-    fprintf(stderr, "ERROR: gstfilesrc couldn't map file!\n");
-  } else if (GST_BUFFER_DATA(buf) == (void *)-1) {
-    perror("gstfilesrc:mmap()");
+    fprintf (stderr, "ERROR: gstfilesrc couldn't map file!\n");
+  } else if (GST_BUFFER_DATA(buf) == MAP_FAILED) {
+    g_error ("gstfilesrc mmap(0x%x, %d, 0x%llx) : %s",
+ 	     size, src->fd, offset, sys_errlist[errno]);
   }
   // madvise to tell the kernel what to do with it
   retval = madvise(GST_BUFFER_DATA(buf),GST_BUFFER_SIZE(buf),MADV_SEQUENTIAL);
@@ -382,20 +403,27 @@
 }
 
 static GstBuffer *
-gst_filesrc_map_small_region (GstFileSrc *src, off_t offset, off_t size)
+gst_filesrc_map_small_region (GstFileSrc *src, off_t offset, size_t size)
 {
-  int mod, mapbase, mapsize;
+  size_t mapsize;
+  off_t mod, mapbase;
   GstBuffer *map;
 
 //  printf("attempting to map a small buffer at %d+%d\n",offset,size);
 
   // if the offset starts at a non-page boundary, we have to special case
   if ((mod = offset % src->pagesize)) {
+    GstBuffer *ret;
+
     mapbase = offset - mod;
     mapsize = ((size + mod + src->pagesize - 1) / src->pagesize) * src->pagesize;
 //    printf("not on page boundaries, resizing map to %d+%d\n",mapbase,mapsize);
     map = gst_filesrc_map_region(src, mapbase, mapsize);
-    return gst_buffer_create_sub (map, offset - mapbase, size);
+    ret = gst_buffer_create_sub (map, offset - mapbase, size);
+
+    gst_buffer_unref (map);
+
+    return ret;
   }
 
   return gst_filesrc_map_region(src,offset,size);
@@ -431,8 +459,8 @@
 {
   GstFileSrc *src;
   GstBuffer *buf = NULL, *map;
-  off_t readend,readsize,mapstart,mapend;
-  gboolean eof = FALSE;
+  size_t readsize;
+  off_t readend,mapstart,mapend;
   GstFileSrcRegion region;
   int i;
 
@@ -440,6 +468,18 @@
   src = GST_FILESRC (gst_pad_get_parent (pad));
   g_return_val_if_fail (GST_FLAG_IS_SET (src, GST_FILESRC_OPEN), NULL);
 
+  // check for seek
+  if (src->seek_happened) {
+    src->seek_happened = FALSE;
+    return gst_event_new(GST_EVENT_DISCONTINUOUS);
+  }
+
+  // check for EOF
+  if (src->curoffset == src->filelen) {
+    gst_element_set_state(src,GST_STATE_PAUSED);
+    return gst_event_new(GST_EVENT_EOS);
+  }
+
   // calculate end pointers so we don't have to do so repeatedly later
   readsize = src->block_size;
   readend = src->curoffset + src->block_size;		// note this is the byte *after* the read
@@ -450,7 +490,6 @@
   if (readend > src->filelen) {
     readsize = src->filelen - src->curoffset;
     readend = src->curoffset;
-    eof = TRUE;
   }
 
   // if the start is past the mapstart
@@ -458,15 +497,15 @@
     // if the end is before the mapend, the buffer is in current mmap region...
     // ('cause by definition if readend is in the buffer, so's readstart)
     if (readend <= mapend) {
-//      printf("read buf %d+%d lives in current mapbuf %d+%d, creating subbuffer of mapbuf\n",
-//             src->curoffset,readsize,GST_BUFFER_OFFSET(src->mapbuf),GST_BUFFER_SIZE(src->mapbuf));
+      fs_print ("read buf %d+%d lives in current mapbuf %d+%d, creating subbuffer of mapbuf\n",
+             src->curoffset,readsize,GST_BUFFER_OFFSET(src->mapbuf),GST_BUFFER_SIZE(src->mapbuf));
       buf = gst_buffer_create_sub (src->mapbuf, src->curoffset - GST_BUFFER_OFFSET(src->mapbuf),
                                    readsize);
 
     // if the start actually is within the current mmap region, map an overlap buffer
     } else if (src->curoffset < mapend) {
-//      printf("read buf %d+%d starts in mapbuf %d+%d but ends outside, creating new mmap\n",
-//             src->curoffset,readsize,GST_BUFFER_OFFSET(src->mapbuf),GST_BUFFER_SIZE(src->mapbuf));
+      fs_print ("read buf %d+%d starts in mapbuf %d+%d but ends outside, creating new mmap\n",
+             src->curoffset,readsize,GST_BUFFER_OFFSET(src->mapbuf),GST_BUFFER_SIZE(src->mapbuf));
       buf = gst_filesrc_map_small_region (src, src->curoffset, readsize);
     }
 
@@ -478,37 +517,39 @@
     // either the read buffer overlaps the start of the mmap region
     // or the read buffer fully contains the current mmap region
     // either way, it's really not relevant, we just create a new region anyway
-//    printf("read buf %d+%d starts before mapbuf %d+%d, but overlaps it\n",
-//             src->curoffset,readsize,GST_BUFFER_OFFSET(src->mapbuf),GST_BUFFER_SIZE(src->mapbuf));
+    fs_print ("read buf %d+%d starts before mapbuf %d+%d, but overlaps it\n",
+             src->curoffset,readsize,GST_BUFFER_OFFSET(src->mapbuf),GST_BUFFER_SIZE(src->mapbuf));
     buf = gst_filesrc_map_small_region (src, src->curoffset, readsize);
   }
 
   // then deal with the case where the read buffer is totally outside
   if (buf == NULL) {
     // first check to see if there's a map that covers the right region already
-//    printf("searching for mapbuf to cover %d+%d\n",src->curoffset,readsize);
+    fs_print ("searching for mapbuf to cover %d+%d\n",src->curoffset,readsize);
     region.offset = src->curoffset;
     region.size = readsize;
-    map = g_tree_search(src->map_regions,gst_filesrc_search_region_match,&region);
+    map = g_tree_search (src->map_regions,
+			 (GCompareFunc) gst_filesrc_search_region_match,
+			 &region);
 
     // if we found an exact match, subbuffer it
     if (map != NULL) {
-//      printf("found mapbuf at %d+%d, creating subbuffer\n",GST_BUFFER_OFFSET(map),GST_BUFFER_SIZE(map));
+      fs_print ("found mapbuf at %d+%d, creating subbuffer\n",GST_BUFFER_OFFSET(map),GST_BUFFER_SIZE(map));
       buf = gst_buffer_create_sub (map, src->curoffset - GST_BUFFER_OFFSET(map), readsize);
 
     // otherwise we need to create something out of thin air
     } else {
       // if the read buffer crosses a mmap region boundary, create a one-off region
       if ((src->curoffset / src->mapsize) != (readend / src->mapsize)) {
-//        printf("read buf %d+%d crosses a %d-byte boundary, creating a one-off\n",
-//               src->curoffset,readsize,src->mapsize);
+        fs_print ("read buf %d+%d crosses a %d-byte boundary, creating a one-off\n",
+               src->curoffset,readsize,src->mapsize);
         buf = gst_filesrc_map_small_region (src, src->curoffset, readsize);
 
       // otherwise we will create a new mmap region and set it to the default
       } else {
         off_t nextmap = src->curoffset - (src->curoffset % src->mapsize);
-//        printf("read buf %d+%d in new mapbuf at %d+%d, mapping and subbuffering\n",
-//               src->curoffset,readsize,nextmap,src->mapsize);
+        fs_print ("read buf %d+%d in new mapbuf at %d+%d, mapping and subbuffering\n",
+               src->curoffset,readsize,nextmap,src->mapsize);
         // first, we're done with the old mapbuf
         gst_buffer_unref(src->mapbuf);
         // create a new one
@@ -525,8 +566,6 @@
       *(GST_BUFFER_DATA(buf)+i) = *(GST_BUFFER_DATA(buf)+i);
   }
 
-  // if we hit EOF, 
-
   /* we're done, return the buffer */
   src->curoffset += GST_BUFFER_SIZE(buf);
   return buf;
@@ -567,6 +606,7 @@
 {
   g_return_if_fail (GST_FLAG_IS_SET (src, GST_FILESRC_OPEN));
 
+  g_print ("close\n");
   /* close the file */
   close (src->fd);
 
@@ -613,6 +653,7 @@
     } else if (data == SEEK_END) {
       src->curoffset = src->filelen - (guint64)location;
     }
+    src->seek_happened = TRUE;
     // push a discontinuous event?
     return TRUE;
   }

Index: gsttee.c
===================================================================
RCS file: /cvsroot/gstreamer/gstreamer/gst/elements/gsttee.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- gsttee.c	2001/09/10 19:46:01	1.8
+++ gsttee.c	2001/10/17 10:21:24	1.9
@@ -56,7 +56,7 @@
 static void 	gst_tee_class_init	(GstTeeClass *klass);
 static void 	gst_tee_init		(GstTee *tee);
 
-static GstPad* 	gst_tee_request_new_pad (GstElement *element, GstPadTemplate *temp);
+static GstPad* 	gst_tee_request_new_pad (GstElement *element, GstPadTemplate *temp, const gchar *unused);
 
 static void 	gst_tee_set_property 	(GObject *object, guint prop_id, 
 					 const GValue *value, GParamSpec *pspec);
@@ -127,7 +127,7 @@
 }
 
 static GstPad*
-gst_tee_request_new_pad (GstElement *element, GstPadTemplate *templ) 
+gst_tee_request_new_pad (GstElement *element, GstPadTemplate *templ, const gchar *unused) 
 {
   gchar *name;
   GstPad *srcpad;





More information about the Gstreamer-commits mailing list