Index: Makefile
===================================================================
--- Makefile	(revision 38)
+++ Makefile	(working copy)
@@ -9,11 +9,15 @@
 LIBS=
 THREADLIB=-lpthread
 SLIBS=$(THREADLIB) $(LIBS)
+GST_LIBS=`pkg-config --libs gstreamer-0.10 gstreamer-base-0.10`
+GST_CFLAGS=`pkg-config --cflags gstreamer-0.10 gstreamer-base-0.10`
+GST_EXTRA_CFLAGS=-DGETTEXT_PACKAGE="\"flvstreamer\"" -DGST_LICENSE="\"LGPL\"" -DGST_PACKAGE_NAME="\"flvstreamer\"" -DGST_PACKAGE_ORIGIN="\"\"" -DVERSION="\"1.9\"" -DPACKAGE="\"flvstreamer\""
 
 EXT=
 
 all:
 	@echo 'use "make linux" for a native Linux build, or'
+	@echo '    "make gstreamer" for a native Linux build of the GStreamer plugin, or'
 	@echo '    "make osx"   for a native OSX build, or'
 	@echo '    "make mingw" for a MinGW32 build, or'
 	@echo '    "make cygwin" for a CygWin build, or'
@@ -21,6 +25,12 @@
 
 progs:	flvstreamer streams
 
+gstreamer:
+	@$(MAKE) $(MAKEFLAGS) OPT=-fPIC libgstrtmpsrc.so
+
+gstreamer-install: gstreamer
+	install -m 0755 -D libgstrtmpsrc.so ~/.gstreamer-0.10/plugins/
+
 linux:
 	@$(MAKE) $(MAKEFLAGS) progs
 
@@ -37,7 +47,7 @@
 	@$(MAKE) CROSS_COMPILE=armv7a-angstrom-linux-gnueabi- INC=-I/OE/tmp/staging/armv7a-angstrom-linux-gnueabi/usr/include $(MAKEFLAGS) progs
 
 clean:
-	rm -f *.o flvstreamer$(EXT) streams$(EXT)
+	rm -f *.o flvstreamer$(EXT) streams$(EXT) libgstrtmpsrc.so
 
 streams: bytes.o log.o rtmp.o AMFObject.o rtmppacket.o streams.o parseurl.o 
 	$(CXX) $(LDFLAGS) $^ -o $@$(EXT) $(SLIBS)
@@ -45,6 +55,9 @@
 flvstreamer: bytes.o log.o rtmp.o AMFObject.o rtmppacket.o flvstreamer.o parseurl.o 
 	$(CXX) $(LDFLAGS) $^ -o $@$(EXT) $(LIBS)
 
+libgstrtmpsrc.so: bytes.o log.o rtmp.o AMFObject.o rtmppacket.o parseurl.o gstrtmpsrc.o
+	$(CXX) $(LDFLAGS) -shared $^ -o $@$(EXT) $(GST_LIBS)
+
 bytes.o: bytes.c bytes.h Makefile
 log.o: log.c log.h Makefile
 rtmp.o: rtmp.cpp rtmp.h log.h AMFObject.h Makefile
@@ -53,6 +66,7 @@
 flvstreamer.o: flvstreamer.cpp rtmp.h log.h AMFObject.h Makefile
 parseurl.o: parseurl.c parseurl.h log.h Makefile
 streams.o: streams.cpp rtmp.h log.h Makefile
+gstrtmpsrc.o: gstrtmpsrc.cpp gstrtmpsrc.h Makefile
+	$(CXX) -fPIC $(GST_EXTRA_CFLAGS) -c -o gstrtmpsrc.o gstrtmpsrc.cpp $(OPT) $(GST_CFLAGS)
 
 
-
--- /dev/null	2009-11-22 16:15:38.285077524 +0000
+++ gstrtmpsrc.cpp	2009-11-25 19:01:01.000000000 +0000
@@ -0,0 +1,868 @@
+/* GStreamer
+ * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
+ *                    2000 Wim Taymans <wtay@chello.be>
+ *                    2001 Bastien Nocera <hadess@hadess.net>
+ *                    2002 Kristian Rietveld <kris@gtk.org>
+ *                    2002,2003 Colin Walters <walters@gnu.org>
+ *
+ * rtmpsrc.c:
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+/**
+ * SECTION:element-rtmpsrc
+ * @see_also: #GstFileSrc, #GstRTMPSink
+ *
+ * This plugin reads data from a local or remote location specified
+ * by an URI. This location can be specified using any protocol supported by
+ * the RTMP library. Common protocols are 'file', 'http', 'ftp', or 'smb'.
+ *
+ * In case the #GstRTMPSrc:iradio-mode property is set and the
+ * location is a http resource, rtmpsrc will send special icecast http
+ * headers to the server to request additional icecast metainformation. If
+ * the server is not an icecast server, it will display the same behaviour
+ * as if the #GstRTMPSrc:iradio-mode property was not set. However,
+ * if the server is in fact an icecast server, rtmpsrc will output
+ * data with a media type of application/x-icy, in which case you will
+ * need to use the #GstICYDemux element as follow-up element to extract
+ * the icecast meta data and to determine the underlying media type.
+ *
+ * <refsect2>
+ * <title>Example launch lines</title>
+ * |[
+ * gst-launch -v rtmpsrc location=file:///home/joe/foo.xyz ! fakesink
+ * ]| The above pipeline will simply read a local file and do nothing with the
+ * data read. Instead of rtmpsrc, we could just as well have used the
+ * filesrc element here.
+ * |[
+ * gst-launch -v rtmpsrc location=smb://othercomputer/foo.xyz ! filesink location=/home/joe/foo.xyz
+ * ]| The above pipeline will copy a file from a remote host to the local file
+ * system using the Samba protocol.
+ * |[
+ * gst-launch -v rtmpsrc location=http://music.foobar.com/demo.mp3 ! mad ! audioconvert ! audioresample ! alsasink
+ * ]| The above pipeline will read and decode and play an mp3 file from a
+ * web server using the http protocol.
+ * </refsect2>
+ */
+
+/* Crappy globals */
+int debuglevel = 0;
+bool bCtrlC = false;
+
+#define DEFAULT_RTMP_PORT 1935
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <glib/gi18n-lib.h>
+
+#include "gstrtmpsrc.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/time.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <netdb.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <sys/mman.h>
+#include <errno.h>
+#include <string.h>
+
+#include <gst/gst.h>
+#include <gst/tag/tag.h>
+
+GST_DEBUG_CATEGORY_STATIC (rtmpsrc_debug);
+#define GST_CAT_DEFAULT rtmpsrc_debug
+
+static const GstElementDetails gst_rtmp_src_details =
+GST_ELEMENT_DETAILS ("RTMP Source",
+    "Source/File",
+    "Read RTMP streams",
+    "Bastien Nocera <hadess@hadess.net>\n"
+    "GStreamer maintainers <gstreamer-devel@lists.sourceforge.net>");
+
+static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
+    GST_PAD_SRC,
+    GST_PAD_ALWAYS,
+    GST_STATIC_CAPS_ANY);
+
+enum
+{
+  ARG_0,
+  ARG_LOCATION,
+  ARG_TCURL,
+  ARG_HOST,
+  ARG_PLAYPATH,
+  ARG_APP,
+  ARG_PORT,
+  ARG_PROTOCOL,
+  ARG_SWFURL
+};
+
+static void gst_rtmp_src_base_init (gpointer g_class);
+static void gst_rtmp_src_class_init (GstRTMPSrcClass * klass);
+static void gst_rtmp_src_init (GstRTMPSrc * rtmpsrc);
+static void gst_rtmp_src_finalize (GObject * object);
+static void gst_rtmp_src_uri_handler_init (gpointer g_iface,
+    gpointer iface_data);
+
+static void gst_rtmp_src_set_property (GObject * object, guint prop_id,
+    const GValue * value, GParamSpec * pspec);
+static void gst_rtmp_src_get_property (GObject * object, guint prop_id,
+    GValue * value, GParamSpec * pspec);
+
+static gboolean gst_rtmp_src_stop (GstBaseSrc * src);
+static gboolean gst_rtmp_src_start (GstBaseSrc * src);
+static gboolean gst_rtmp_src_is_seekable (GstBaseSrc * src);
+#if 0
+static gboolean gst_rtmp_src_check_get_range (GstBaseSrc * src);
+static gboolean gst_rtmp_src_get_size (GstBaseSrc * src, guint64 * size);
+#endif
+static GstFlowReturn gst_rtmp_src_create (GstBaseSrc * basesrc,
+    guint64 offset, guint size, GstBuffer ** buffer);
+#if 0
+static gboolean gst_rtmp_src_query (GstBaseSrc * src, GstQuery * query);
+#endif
+
+static GstElementClass *parent_class = NULL;
+
+static gboolean
+plugin_init (GstPlugin * plugin)
+{
+	return gst_element_register (plugin, "rtmpsrc", GST_RANK_NONE,
+				     GST_TYPE_RTMP_SRC);
+}
+
+GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
+		   GST_VERSION_MINOR,
+		   "rtmpsrc",
+		   "flvstreamer sources",
+		   plugin_init, VERSION, GST_LICENSE, GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN);
+
+GType
+gst_rtmp_src_get_type (void)
+{
+  static GType rtmpsrc_type = 0;
+
+  if (!rtmpsrc_type) {
+    static const GTypeInfo rtmpsrc_info = {
+      sizeof (GstRTMPSrcClass),
+      gst_rtmp_src_base_init,
+      NULL,
+      (GClassInitFunc) gst_rtmp_src_class_init,
+      NULL,
+      NULL,
+      sizeof (GstRTMPSrc),
+      0,
+      (GInstanceInitFunc) gst_rtmp_src_init,
+    };
+    static const GInterfaceInfo urihandler_info = {
+      gst_rtmp_src_uri_handler_init,
+      NULL,
+      NULL
+    };
+
+    rtmpsrc_type =
+        g_type_register_static (GST_TYPE_BASE_SRC,
+        "GstRTMPSrc", &rtmpsrc_info, (GTypeFlags) 0);
+    g_type_add_interface_static (rtmpsrc_type, GST_TYPE_URI_HANDLER,
+        &urihandler_info);
+  }
+  return rtmpsrc_type;
+}
+
+static void
+gst_rtmp_src_base_init (gpointer g_class)
+{
+  GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
+
+  gst_element_class_add_pad_template (element_class,
+      gst_static_pad_template_get (&srctemplate));
+  gst_element_class_set_details (element_class, &gst_rtmp_src_details);
+
+  GST_DEBUG_CATEGORY_INIT (rtmpsrc_debug, "rtmpsrc", 0,
+      "RTMP Source");
+}
+
+static void
+gst_rtmp_src_class_init (GstRTMPSrcClass * klass)
+{
+  GObjectClass *gobject_class;
+  GstBaseSrcClass *gstbasesrc_class;
+
+  gobject_class = G_OBJECT_CLASS (klass);
+  gstbasesrc_class = GST_BASE_SRC_CLASS (klass);
+
+  parent_class = (GstElementClass *) g_type_class_peek_parent (klass);
+
+  gobject_class->finalize = gst_rtmp_src_finalize;
+  gobject_class->set_property = gst_rtmp_src_set_property;
+  gobject_class->get_property = gst_rtmp_src_get_property;
+
+  /* properties */
+  gst_element_class_install_std_props (GST_ELEMENT_CLASS (klass),
+      "location", ARG_LOCATION, G_PARAM_READWRITE, NULL);
+
+  /* FIXME, add blurbs for gst-inspect */
+  g_object_class_install_property (gobject_class,
+				   ARG_TCURL,
+				   g_param_spec_string ("tcurl",
+							"tcurl",
+							NULL,
+							NULL,
+							(GParamFlags) G_PARAM_READWRITE));
+  g_object_class_install_property (gobject_class,
+				   ARG_HOST,
+				   g_param_spec_string ("host",
+							"host",
+							NULL,
+							NULL,
+							(GParamFlags) G_PARAM_READWRITE));
+  g_object_class_install_property (gobject_class,
+				   ARG_PLAYPATH,
+				   g_param_spec_string ("playpath",
+							"playpath",
+							NULL,
+							NULL,
+							(GParamFlags) G_PARAM_READWRITE));
+  g_object_class_install_property (gobject_class,
+				   ARG_APP,
+				   g_param_spec_string ("app",
+							"app",
+							NULL,
+							NULL,
+							(GParamFlags) G_PARAM_READWRITE));
+  g_object_class_install_property (gobject_class,
+				   ARG_PORT,
+				   g_param_spec_int ("port",
+						     "port",
+						     NULL,
+						     -1,
+						     G_MAXINT,
+						     -1,
+						     (GParamFlags) G_PARAM_READWRITE));
+
+  /* FIXME: should this be an enum instead? */
+  g_object_class_install_property (gobject_class,
+				   ARG_PROTOCOL,
+				   g_param_spec_int ("protocol",
+						     "protocol",
+						     NULL,
+						     RTMP_PROTOCOL_UNDEFINED,
+						     RTMP_PROTOCOL_RTMFP,
+						     RTMP_PROTOCOL_UNDEFINED,
+						     (GParamFlags) G_PARAM_READWRITE));
+  g_object_class_install_property (gobject_class,
+				   ARG_SWFURL,
+				   g_param_spec_string ("swfurl",
+							"swfurl",
+							NULL,
+							NULL,
+							(GParamFlags) G_PARAM_READWRITE));
+
+  gstbasesrc_class->start = GST_DEBUG_FUNCPTR (gst_rtmp_src_start);
+  gstbasesrc_class->stop = GST_DEBUG_FUNCPTR (gst_rtmp_src_stop);
+#if 0
+  gstbasesrc_class->get_size = GST_DEBUG_FUNCPTR (gst_rtmp_src_get_size);
+#endif
+  gstbasesrc_class->is_seekable =
+      GST_DEBUG_FUNCPTR (gst_rtmp_src_is_seekable);
+#if 0
+  gstbasesrc_class->check_get_range =
+      GST_DEBUG_FUNCPTR (gst_rtmp_src_check_get_range);
+#endif
+  gstbasesrc_class->create = GST_DEBUG_FUNCPTR (gst_rtmp_src_create);
+#if 0
+  gstbasesrc_class->query = GST_DEBUG_FUNCPTR (gst_rtmp_src_query);
+#endif
+}
+
+static void
+gst_rtmp_src_init (GstRTMPSrc * rtmpsrc)
+{
+  rtmpsrc->uri = NULL;
+
+  rtmpsrc->tcurl = NULL;
+  rtmpsrc->host = NULL;
+  rtmpsrc->playpath = NULL;
+  rtmpsrc->app = NULL;
+  rtmpsrc->port = RTMP_PROTOCOL_UNDEFINED;
+  rtmpsrc->protocol = 0;
+
+  rtmpsrc->swfurl = NULL;
+
+  rtmpsrc->rtmp = NULL;
+
+  rtmpsrc->curoffset = 0;
+  rtmpsrc->seekable = FALSE;
+}
+
+static void
+gst_rtmp_src_finalize (GObject * object)
+{
+  GstRTMPSrc *rtmpsrc = GST_RTMP_SRC (object);
+
+  g_free (rtmpsrc->uri);
+  rtmpsrc->uri = NULL;
+
+  g_free (rtmpsrc->tcurl);
+  rtmpsrc->tcurl = NULL;
+  g_free (rtmpsrc->host);
+  rtmpsrc->host = NULL;
+  g_free (rtmpsrc->playpath);
+  rtmpsrc->playpath = NULL;
+  g_free (rtmpsrc->app);
+  rtmpsrc->app = NULL;
+
+  g_free (rtmpsrc->swfurl);
+  rtmpsrc->swfurl = NULL;
+
+  //FIXME close rtmp?
+
+  if (rtmpsrc->rtmp) {
+    delete rtmpsrc->rtmp;
+    rtmpsrc->rtmp = NULL;
+  }
+
+  G_OBJECT_CLASS (parent_class)->finalize (object);
+}
+
+/*
+ * URI interface support.
+ */
+
+static GstURIType
+gst_rtmp_src_uri_get_type (void)
+{
+  return GST_URI_SRC;
+}
+
+static gchar **
+gst_rtmp_src_uri_get_protocols (void)
+{
+  static gchar *protocols[] = { "rtmp", NULL };
+  return protocols;
+}
+
+static const gchar *
+gst_rtmp_src_uri_get_uri (GstURIHandler * handler)
+{
+  GstRTMPSrc *src = GST_RTMP_SRC (handler);
+
+  return src->uri;
+}
+
+static gboolean
+gst_rtmp_src_uri_set_uri (GstURIHandler * handler, const gchar * uri)
+{
+  GstRTMPSrc *src = GST_RTMP_SRC (handler);
+
+  if (GST_STATE (src) == GST_STATE_PLAYING ||
+      GST_STATE (src) == GST_STATE_PAUSED)
+    return FALSE;
+
+  g_object_set (G_OBJECT (src), "location", uri, NULL);
+
+  return TRUE;
+}
+
+static void
+gst_rtmp_src_uri_handler_init (gpointer g_iface, gpointer iface_data)
+{
+  GstURIHandlerInterface *iface = (GstURIHandlerInterface *) g_iface;
+
+  iface->get_type = gst_rtmp_src_uri_get_type;
+  iface->get_protocols = gst_rtmp_src_uri_get_protocols;
+  iface->get_uri = gst_rtmp_src_uri_get_uri;
+  iface->set_uri = gst_rtmp_src_uri_set_uri;
+}
+
+static void
+gst_rtmp_src_set_property (GObject * object, guint prop_id,
+    const GValue * value, GParamSpec * pspec)
+{
+  GstRTMPSrc *src;
+
+  src = GST_RTMP_SRC (object);
+
+  switch (prop_id) {
+    case ARG_LOCATION:{
+      const gchar *new_location;
+
+      /* the element must be stopped or paused in order to do this */
+      if (GST_STATE (src) == GST_STATE_PLAYING ||
+          GST_STATE (src) == GST_STATE_PAUSED)
+        break;
+
+      g_free (src->host);
+      src->host = NULL;
+      g_free (src->playpath);
+      src->playpath = NULL;
+      g_free (src->tcurl);
+      src->tcurl = NULL;
+      src->port = -1;
+      src->protocol = RTMP_PROTOCOL_UNDEFINED;
+      //FIXME more to free/init
+
+      new_location = g_value_get_string (value);
+      if (new_location) {
+        char *parsedHost = 0; 
+	unsigned int parsedPort = 0; 
+	char *parsedPlaypath = 0; 
+	char *parsedApp = 0; 
+	int parsedProtocol = RTMP_PROTOCOL_UNDEFINED;
+
+	if(!ParseUrl((char *) new_location, &parsedProtocol, &parsedHost, &parsedPort, &parsedPlaypath, &parsedApp)) {
+	  //FIXME warning here
+	  //Log(LOGWARNING, "Couldn't parse the specified url (%s)!", optarg);
+	} else {
+	  src->host = parsedHost;
+	  src->port = parsedPort;
+	  src->playpath = parsedPlaypath;
+	  src->protocol = parsedProtocol;
+	  src->app = parsedApp;
+	  src->uri = g_strdup (new_location);
+	  src->tcurl = g_strdup_printf ("%s://%s:%d/%s", RTMPProtocolStringsLower[src->protocol], src->host, src->port, src->app);
+	}
+      }
+      break;
+    }
+    case ARG_TCURL:
+      g_free (src->tcurl);
+      src->tcurl = g_value_dup_string (value);
+      break;
+    case ARG_HOST:
+      g_free (src->host);
+      src->host = g_value_dup_string (value);
+      break;
+    case ARG_PLAYPATH:
+      g_free (src->playpath);
+      src->playpath = g_value_dup_string (value);
+      break;
+    case ARG_APP:
+      g_free (src->app);
+      src->playpath = g_value_dup_string (value);
+      break;
+    case ARG_PORT:
+      src->port = g_value_get_int (value);
+      break;
+    case ARG_PROTOCOL:
+      src->protocol = g_value_get_int (value);
+      break;
+    case ARG_SWFURL:
+      g_free (src->swfurl);
+      src->swfurl = g_value_dup_string (value);
+      break;
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+  }
+}
+
+static void
+gst_rtmp_src_get_property (GObject * object, guint prop_id, GValue * value,
+    GParamSpec * pspec)
+{
+  GstRTMPSrc *src;
+
+  src = GST_RTMP_SRC (object);
+
+  switch (prop_id) {
+    case ARG_LOCATION:
+      g_value_set_string (value, src->uri);
+      break;
+    case ARG_TCURL:
+      g_value_set_string (value, src->tcurl);
+      break;
+    case ARG_HOST:
+      g_value_set_string (value, src->host);
+      break;
+    case ARG_PLAYPATH:
+      g_value_set_string (value, src->playpath);
+      break;
+    case ARG_APP:
+      g_value_set_string (value, src->app);
+      break;
+    case ARG_PORT:
+      g_value_set_int (value, src->port);
+      break;
+    case ARG_PROTOCOL:
+      g_value_set_int (value, src->protocol);
+      break;
+    case ARG_SWFURL:
+      g_value_set_string (value, src->swfurl);
+      break;
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+  }
+}
+
+/*
+ * Check whether we have enough parameters to start a stream
+ */
+static gboolean
+gst_rtmp_src_check_params (GstRTMPSrc *src)
+{
+  if (src->uri != NULL ||
+      (src->protocol != RTMP_PROTOCOL_UNDEFINED &&
+       src->host != NULL &&
+       src->port != -1 &&
+       src->playpath != NULL &&
+       src->app != NULL)) {
+    return TRUE;
+  }
+  return FALSE;
+}
+
+/*
+ * Read a new buffer from src->reqoffset, takes care of events
+ * and seeking and such.
+ */
+static GstFlowReturn
+gst_rtmp_src_create (GstBaseSrc * basesrc, guint64 offset, guint size,
+    GstBuffer ** buffer)
+{
+  GstRTMPSrc *src;
+  GstBuffer *buf;
+  guint8 *data;
+  guint todo;
+  int read;
+
+  src = GST_RTMP_SRC (basesrc);
+
+  GST_DEBUG ("now at %" G_GINT64_FORMAT ", reading from %" G_GUINT64_FORMAT
+      ", size %u", src->curoffset, offset, size);
+
+  /* open if required */
+  if (G_UNLIKELY (!src->rtmp->IsConnected ())) {
+    if (!src->rtmp->Connect()) {
+      GST_ELEMENT_ERROR (src, RESOURCE, NOT_FOUND, (NULL),
+			 ("Could not connect to host \"%s\" for reading: %s (%d)",
+			  src->tcurl, "FIXME" , 0));
+      return GST_FLOW_ERROR;
+    }
+    if (!src->rtmp->ConnectStream(0, 0)) {
+      GST_ELEMENT_ERROR (src, RESOURCE, NOT_FOUND, (NULL),
+			 ("Could not connect to RTMP stream \"%s\" for reading: %s (%d)",
+			  src->tcurl, "FIXME", 0));
+      return GST_FLOW_ERROR;
+    }
+  }
+
+  /* seek if required */
+  if (G_UNLIKELY (src->curoffset != offset)) {
+    GST_DEBUG ("need to seek");
+    if (src->seekable) {
+#if 0
+      GST_DEBUG ("seeking to %" G_GUINT64_FORMAT, offset);
+      res = rtmp_seek (src->handle, RTMP_SEEK_START, offset);
+      if (res != RTMP_OK)
+        goto seek_failed;
+      src->curoffset = offset;
+#endif
+    } else {
+      goto cannot_seek;
+    }
+  }
+
+  buf = gst_buffer_try_new_and_alloc (size);
+  if (G_UNLIKELY (buf == NULL && size == 0)) {
+    GST_ERROR_OBJECT (src, "Failed to allocate %u bytes", size);
+    return GST_FLOW_ERROR;
+  }
+
+  data = GST_BUFFER_DATA (buf);
+
+  /* FIXME add FLV header first time around? */
+  read = 0;
+
+  todo = size;
+  while (todo > 0) {
+    read = -1;
+#if 0
+    /* this can return less that we ask for */
+    read = WriteStream(src->rtmp, &data, todo,
+		       &timestamp,
+		       bResume && nInitialFrameSize > 0,
+		       bLiveStream,
+		       dSeek,
+		       metaHeader,
+		       nMetaHeaderSize,
+		       initialFrame,
+		       initialFrameType,
+		       nInitialFrameSize,
+		       &dataType);
+#endif
+    if (G_UNLIKELY (read == -1))
+      goto eos;
+
+    if (G_UNLIKELY (read == -2))
+      goto read_failed;
+
+    /* FIXME handle -3 ? */
+
+    if (read < todo) {
+      data = &data[read];
+      todo -= read;
+    } else {
+      todo = 0;
+    }
+    GST_LOG ("  got size %" G_GUINT64_FORMAT, read);
+  }
+  GST_BUFFER_OFFSET (buf) = src->curoffset;
+  src->curoffset += size;
+
+  /* we're done, return the buffer */
+  *buffer = buf;
+
+#if 0
+  RTMPFileSize readbytes;
+  guint todo;
+
+
+
+  return GST_FLOW_OK;
+#endif
+  return GST_FLOW_OK;
+
+seek_failed:
+  {
+    GST_ELEMENT_ERROR (src, RESOURCE, SEEK, (NULL),
+        ("Failed to seek to requested position %" G_GINT64_FORMAT ": %s",
+            offset, "FIXME"));
+    return GST_FLOW_ERROR;
+  }
+cannot_seek:
+  {
+    GST_ELEMENT_ERROR (src, RESOURCE, SEEK, (NULL),
+        ("Requested seek from %" G_GINT64_FORMAT " to %" G_GINT64_FORMAT
+            " on non-seekable stream", src->curoffset, offset));
+    return GST_FLOW_ERROR;
+  }
+read_failed:
+  {
+    gst_buffer_unref (buf);
+    GST_ELEMENT_ERROR (src, RESOURCE, READ, (NULL),
+        ("Failed to read data: %s", "FIXME"));
+    return GST_FLOW_ERROR;
+  }
+eos:
+  {
+    gst_buffer_unref (buf);
+    GST_DEBUG_OBJECT (src, "Reading data gave EOS");
+    return GST_FLOW_UNEXPECTED;
+  }
+}
+
+#if 0
+static gboolean
+gst_rtmp_src_query (GstBaseSrc * basesrc, GstQuery * query)
+{
+  gboolean ret = FALSE;
+  GstRTMPSrc *src = GST_RTMP_SRC (basesrc);
+
+  switch (GST_QUERY_TYPE (query)) {
+    case GST_QUERY_URI:
+      gst_query_set_uri (query, src->uri);
+      ret = TRUE;
+      break;
+    default:
+      ret = FALSE;
+      break;
+  }
+
+  if (!ret)
+    ret = GST_BASE_SRC_CLASS (parent_class)->query (basesrc, query);
+
+  return ret;
+}
+#endif
+static gboolean
+gst_rtmp_src_is_seekable (GstBaseSrc * basesrc)
+{
+  GstRTMPSrc *src;
+
+  src = GST_RTMP_SRC (basesrc);
+
+  return src->seekable;
+}
+
+#if 0
+static gboolean
+gst_rtmp_src_check_get_range (GstBaseSrc * basesrc)
+{
+  GstRTMPSrc *src;
+  const gchar *protocol;
+
+  src = GST_RTMP_SRC (basesrc);
+
+  if (src->uri == NULL) {
+    GST_WARNING_OBJECT (src, "no URI set yet");
+    return FALSE;
+  }
+
+  if (rtmp_uri_is_local (src->uri)) {
+    GST_LOG_OBJECT (src, "local URI (%s), assuming random access is possible",
+        GST_STR_NULL (src->uri_name));
+    return TRUE;
+  }
+
+  /* blacklist certain protocols we know won't work getrange-based */
+  protocol = rtmp_uri_get_scheme (src->uri);
+  if (protocol == NULL)
+    goto undecided;
+
+  if (strcmp (protocol, "http") == 0 || strcmp (protocol, "https") == 0) {
+    GST_LOG_OBJECT (src, "blacklisted protocol '%s', no random access possible"
+        " (URI=%s)", protocol, GST_STR_NULL (src->uri_name));
+    return FALSE;
+  }
+
+  /* fall through to undecided */
+
+undecided:
+  {
+    /* don't know what to do, let the basesrc class decide for us */
+    GST_LOG_OBJECT (src, "undecided about URI '%s', let base class handle it",
+        GST_STR_NULL (src->uri_name));
+
+    if (GST_BASE_SRC_CLASS (parent_class)->check_get_range)
+      return GST_BASE_SRC_CLASS (parent_class)->check_get_range (basesrc);
+
+    return FALSE;
+  }
+}
+#endif
+
+#if 0
+static gboolean
+gst_rtmp_src_get_size (GstBaseSrc * basesrc, guint64 * size)
+{
+  GstRTMPSrc *src;
+  RTMPFileInfo *info;
+  RTMPFileInfoOptions options;
+  RTMPResult res;
+
+  src = GST_RTMP_SRC (basesrc);
+
+  *size = -1;
+  info = rtmp_file_info_new ();
+  options = RTMP_FILE_INFO_DEFAULT | RTMP_FILE_INFO_FOLLOW_LINKS;
+  res = rtmp_get_file_info_from_handle (src->handle, info, options);
+  if (res == RTMP_OK) {
+    if ((info->valid_fields & RTMP_FILE_INFO_FIELDS_SIZE) != 0) {
+      *size = info->size;
+      GST_DEBUG_OBJECT (src, "from handle: %" G_GUINT64_FORMAT " bytes", *size);
+    } else if (src->own_handle && rtmp_uri_is_local (src->uri)) {
+      GST_DEBUG_OBJECT (src,
+          "file size not known, file local, trying fallback");
+      res = rtmp_get_file_info_uri (src->uri, info, options);
+      if (res == RTMP_OK &&
+          (info->valid_fields & RTMP_FILE_INFO_FIELDS_SIZE) != 0) {
+        *size = info->size;
+        GST_DEBUG_OBJECT (src, "from uri: %" G_GUINT64_FORMAT " bytes", *size);
+      }
+    }
+  } else {
+    GST_WARNING_OBJECT (src, "getting info failed: %s",
+        rtmp_result_to_string (res));
+  }
+  rtmp_file_info_unref (info);
+
+  if (*size == (RTMPFileSize) - 1)
+    return FALSE;
+
+  GST_DEBUG_OBJECT (src, "return size %" G_GUINT64_FORMAT, *size);
+
+  return TRUE;
+}
+#endif
+
+/* open the file, do stuff necessary to go to PAUSED state */
+static gboolean
+gst_rtmp_src_start (GstBaseSrc * basesrc)
+{
+  GstRTMPSrc *src;
+  int port;
+
+  src = GST_RTMP_SRC (basesrc);
+
+  if (!gst_rtmp_src_check_params (src)) {
+    GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ, (NULL), ("No filename given"));
+    return FALSE;
+  }
+
+  if (src->rtmp) {
+    delete src->rtmp;
+    src->rtmp = NULL;
+  }
+
+  src->rtmp = new CRTMP ();
+
+  if (src->port <= 0)
+    port = DEFAULT_RTMP_PORT;
+  else
+    port = src->port;
+
+  src->rtmp->SetupStream (src->protocol,
+			  src->host,
+			  src->port,
+			  NULL, /* sockshost */
+			  src->playpath,
+			  src->tcurl,
+			  src->swfurl,
+			  NULL, /* pageUrl */
+			  src->app,
+			  NULL, /* auth */
+			  NULL, /* swfHash */
+			  NULL, /* swfSize */
+			  NULL, /* flashVer */
+			  NULL, /* subscribepath */
+			  0, /* dSeek */
+			  0,
+			  false, /* bLiveStream */
+			  120); /* timeout */
+
+  return TRUE;
+}
+
+static gboolean
+gst_rtmp_src_stop (GstBaseSrc * basesrc)
+{
+  GstRTMPSrc *src;
+
+  src = GST_RTMP_SRC (basesrc);
+
+  src->rtmp->Close ();
+  delete src->rtmp;
+  src->rtmp = NULL;
+
+  src->curoffset = 0;
+
+  return TRUE;
+}
+
+/*
+ * vim: sw=2 ts=8 cindent noai bs=2
+ */
--- /dev/null	2009-11-22 16:15:38.285077524 +0000
+++ gstrtmpsrc.h	2009-11-25 18:10:09.000000000 +0000
@@ -0,0 +1,88 @@
+/* GStreamer
+ * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
+ *                    2000 Wim Taymans <wtay@chello.be>
+ *                    2001 Bastien Nocera <hadess@hadess.net>
+ *                    2002 Kristian Rietveld <kris@gtk.org>
+ *                    2002,2003 Colin Walters <walters@gnu.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __GST_RTMP_SRC_H__
+#define __GST_RTMP_SRC_H__
+
+#include <gst/base/gstbasesrc.h>
+
+#include "rtmp.h"
+#include "log.h"
+#include "AMFObject.h"
+#include "parseurl.h"
+
+G_BEGIN_DECLS
+
+using namespace RTMP_LIB;
+
+#define GST_TYPE_RTMP_SRC \
+  (gst_rtmp_src_get_type())
+#define GST_RTMP_SRC(obj) \
+  (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_RTMP_SRC,GstRTMPSrc))
+#define GST_RTMP_SRC_CLASS(klass) \
+  (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_RTMP_SRC,GstRTMPSrcClass))
+#define GST_IS_RTMP_SRC(obj) \
+  (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_RTMP_SRC))
+#define GST_IS_RTMP_SRC_CLASS(klass) \
+  (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_RTMP_SRC))
+
+typedef struct _GstRTMPSrc      GstRTMPSrc;
+typedef struct _GstRTMPSrcClass GstRTMPSrcClass;
+
+/**
+ * GstRTMPSrc:
+ *
+ * Opaque data structure.
+ */
+struct _GstRTMPSrc
+{
+  GstBaseSrc basesrc;
+
+  char *uri;
+
+  char *tcurl;
+  char *host;
+  char *playpath;
+  char *app;
+  int port;
+  int protocol;
+
+  char *swfurl;
+
+  CRTMP *rtmp;
+
+  gboolean seekable;
+  gint64 curoffset;
+};
+
+struct _GstRTMPSrcClass
+{
+  GstBaseSrcClass  basesrc_class;
+};
+
+GType gst_rtmp_src_get_type (void);
+
+G_END_DECLS
+
+#endif /* __GST_RTMP_SRC_H__ */
+
