Index: configure.ac
===================================================================
RCS file: /cvs/gstreamer/gst-plugins-bad/configure.ac,v
retrieving revision 1.788
diff -u -p -r1.788 configure.ac
--- configure.ac	7 Nov 2007 16:47:32 -0000	1.788
+++ configure.ac	15 Nov 2007 11:01:16 -0000
@@ -779,6 +779,17 @@ AG_GST_CHECK_FEATURE(NEON, [neon http cl
   AC_SUBST(NEON_LIBS)
 ])
 
+dnl *** soup ***
+translit(dnm, m, l) AM_CONDITIONAL(USE_SOUP, true)
+AG_GST_CHECK_FEATURE(SOUP, [soup http client plugins], souphttpsrc, [
+  PKG_CHECK_MODULES(SOUP, libsoup-2.2, HAVE_SOUP="yes", [
+    HAVE_SOUP="no"
+    AC_MSG_RESULT(no)
+  ])
+  AC_SUBST(SOUP_CFLAGS)
+  AC_SUBST(SOUP_LIBS)
+])
+
 dnl *** timidity ***
 translit(dnm, m, l) AM_CONDITIONAL(USE_TIMIDITY, true)
 AG_GST_CHECK_FEATURE(TIMIDITY, [timidity midi soft synth plugin], timidity, [
@@ -965,6 +976,7 @@ AM_CONDITIONAL(USE_MUSICBRAINZ, false)
 AM_CONDITIONAL(USE_MYTHTV, false)
 AM_CONDITIONAL(USE_NAS, false)
 AM_CONDITIONAL(USE_NEON, false)
+AM_CONDITIONAL(USE_SOUP, false)
 AM_CONDITIONAL(USE_SDL, false)
 AM_CONDITIONAL(USE_SNDFILE, false)
 AM_CONDITIONAL(USE_SOUNDTOUCH, false)
@@ -1100,6 +1112,7 @@ ext/musepack/Makefile
 ext/musicbrainz/Makefile
 ext/mythtv/Makefile
 ext/neon/Makefile
+ext/soup/Makefile
 ext/sdl/Makefile
 ext/sndfile/Makefile
 ext/soundtouch/Makefile
Index: ext/Makefile.am
===================================================================
RCS file: /cvs/gstreamer/gst-plugins-bad/ext/Makefile.am,v
retrieving revision 1.198
diff -u -p -r1.198 Makefile.am
--- ext/Makefile.am	30 Oct 2007 12:49:03 -0000	1.198
+++ ext/Makefile.am	15 Nov 2007 11:01:16 -0000
@@ -190,6 +190,12 @@ else
 NEON_DIR=
 endif
 
+if USE_SOUP
+SOUP_DIR=soup
+else
+SOUP_DIR=
+endif
+
 if USE_TIMIDITY
 TIMIDITY_DIR=timidity
 else
@@ -306,6 +312,7 @@ SUBDIRS=\
 	$(MYTHTV_DIR) \
 	$(NAS_DIR) \
 	$(NEON_DIR) \
+	$(SOUP_DIR) \
 	$(POLYP_DIR) \
 	$(SDL_DIR) \
 	$(SHOUT_DIR) \
@@ -345,6 +352,7 @@ DIST_SUBDIRS = \
 	mythtv \
 	nas \
 	neon \
+	soup \
 	sdl \
 	sndfile \
 	soundtouch \
--- ext/soup/Makefile.am    1970-01-01 01:00:00.000000000 +0100
+++ ext/soup/Makefile.am        2007-11-15 09:50:04.000000000 +0100
@@ -0,0 +1,9 @@
+plugin_LTLIBRARIES = libgstsouphttpsrc.la
+
+libgstsouphttpsrc_la_SOURCES = gstsouphttpsrc.c
+
+libgstsouphttpsrc_la_CFLAGS = $(GST_CFLAGS) $(SOUP_CFLAGS) 
+libgstsouphttpsrc_la_LIBADD = $(GST_BASE_LIBS) $(SOUP_LIBS)
+libgstsouphttpsrc_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
+
+noinst_HEADERS = gstsouphttpsrc.h
--- ext/soup/gstsouphttpsrc.c	1970-01-01 01:00:00.000000000 +0100
+++ ext/soup/gstsouphttpsrc.c	2007-11-15 11:38:27.000000000 +0100
@@ -0,0 +1,372 @@
+/* GStreamer
+ * Copyright (C) <2007> Wouter Cloetens <wouter@mind.be>
+ *
+ * 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
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <string.h>
+#include <libsoup/soup.h>
+#include "gstsouphttpsrc.h"
+
+GST_DEBUG_CATEGORY_STATIC (souphttpsrc_debug);
+#define GST_CAT_DEFAULT souphttpsrc_debug
+
+static const GstElementDetails gst_souphttp_src_details =
+GST_ELEMENT_DETAILS ("HTTP client source",
+    "Source/Network",
+    "Receive data as a client over the network via HTTP using SOUP",
+    "Wouter Cloetens <wouter@mind.be>");
+
+static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
+    GST_PAD_SRC,
+    GST_PAD_ALWAYS,
+    GST_STATIC_CAPS_ANY);
+
+enum
+{
+  PROP_0,
+  PROP_LOCATION,
+};
+
+static void gst_souphttp_src_dispose (GObject * gobject);
+static void gst_souphttp_src_set_property (GObject * object, guint prop_id,
+    const GValue * value, GParamSpec * pspec);
+static void gst_souphttp_src_get_property (GObject * object, guint prop_id,
+    GValue * value, GParamSpec * pspec);
+
+static GstFlowReturn gst_souphttp_src_create (GstPushSrc * psrc,
+    GstBuffer ** outbuf);
+static gboolean gst_souphttp_src_start (GstBaseSrc * bsrc);
+static gboolean gst_souphttp_src_stop (GstBaseSrc * bsrc);
+static gboolean gst_souphttp_src_unlock (GstBaseSrc * bsrc);
+
+static gboolean gst_souphttp_src_set_location (GstSouphttpSrc * src,
+    const gchar * uri);
+
+static void soup_got_chunk (SoupMessage *msg, GstSouphttpSrc *src);
+static void soup_response (SoupMessage *msg, gpointer user_data);
+
+static void
+_do_init (GType type)
+{
+  GST_DEBUG_CATEGORY_INIT (souphttpsrc_debug, "souphttpsrc", 0,
+      "SOUP HTTP src");
+}
+
+GST_BOILERPLATE_FULL (GstSouphttpSrc, gst_souphttp_src, GstPushSrc,
+    GST_TYPE_PUSH_SRC, _do_init);
+
+static void
+gst_souphttp_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_souphttp_src_details);
+}
+
+static void
+gst_souphttp_src_class_init (GstSouphttpSrcClass * klass)
+{
+  GObjectClass *gobject_class;
+  GstBaseSrcClass *gstbasesrc_class;
+  GstPushSrcClass *gstpushsrc_class;
+
+  gobject_class = (GObjectClass *) klass;
+  gstbasesrc_class = (GstBaseSrcClass *) klass;
+  gstpushsrc_class = (GstPushSrcClass *) klass;
+
+  gobject_class->set_property = gst_souphttp_src_set_property;
+  gobject_class->get_property = gst_souphttp_src_get_property;
+  gobject_class->dispose = gst_souphttp_src_dispose;
+
+  g_object_class_install_property
+      (gobject_class, PROP_LOCATION,
+      g_param_spec_string ("location", "Location",
+          "Location to read from", "", G_PARAM_READWRITE));
+
+  gstbasesrc_class->start = GST_DEBUG_FUNCPTR (gst_souphttp_src_start);
+  gstbasesrc_class->stop = GST_DEBUG_FUNCPTR (gst_souphttp_src_stop);
+  gstbasesrc_class->unlock = GST_DEBUG_FUNCPTR (gst_souphttp_src_unlock);
+
+  gstpushsrc_class->create = GST_DEBUG_FUNCPTR (gst_souphttp_src_create);
+
+  GST_DEBUG_CATEGORY_INIT (souphttpsrc_debug, "souphttpsrc", 0,
+      "SOUP HTTP Client Source");
+}
+
+static void
+gst_souphttp_src_init (GstSouphttpSrc * src, GstSouphttpSrcClass * g_class)
+{
+  src->location = NULL;
+  src->loop = NULL;
+  src->session = NULL;
+  src->msg = NULL;
+}
+
+static void
+gst_souphttp_src_dispose (GObject * gobject)
+{
+  GstSouphttpSrc *src = GST_SOUPHTTP_SRC (gobject);
+
+  GST_DEBUG_OBJECT (src, "dispose");
+  if (src->location) {
+    g_free (src->location);
+  }
+  if (src->session) {
+    soup_session_abort (src->session);  /* This unrefs the message. */
+    g_object_unref (src->session);
+    src->session = NULL;
+    src->msg = NULL;
+  }
+  if (src->loop) {
+    g_main_loop_unref (src->loop);
+    src->loop = NULL;
+  }
+
+  G_OBJECT_CLASS (parent_class)->dispose (gobject);
+}
+
+static void
+gst_souphttp_src_set_property (GObject * object, guint prop_id,
+    const GValue * value, GParamSpec * pspec)
+{
+  GstSouphttpSrc *src = GST_SOUPHTTP_SRC (object);
+
+  switch (prop_id) {
+    case PROP_LOCATION:
+    {
+      const gchar *location;
+
+      location = g_value_get_string (value);
+
+      if (location == NULL) {
+        GST_WARNING ("location property cannot be NULL");
+        goto done;
+      }
+      if (!gst_souphttp_src_set_location (src, location)) {
+        GST_WARNING ("badly formatted location");
+        goto done;
+      }
+      break;
+    }
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+  }
+done:
+  return;
+}
+
+static void
+gst_souphttp_src_get_property (GObject * object, guint prop_id,
+    GValue * value, GParamSpec * pspec)
+{
+  GstSouphttpSrc *souphttpsrc = GST_SOUPHTTP_SRC (object);
+
+  switch (prop_id) {
+    case PROP_LOCATION:
+      g_value_set_string (value, souphttpsrc->location);
+      break;
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+  }
+}
+
+static GstFlowReturn
+gst_souphttp_src_create (GstPushSrc * psrc, GstBuffer ** outbuf)
+{
+  GstSouphttpSrc *src;
+  src = GST_SOUPHTTP_SRC (psrc);
+
+  src->ret = GST_FLOW_CUSTOM_ERROR;
+  src->outbuf = outbuf;
+  do {
+    if (!src->session) {
+      GST_DEBUG_OBJECT (src, "EOS reached");
+      src->ret = GST_FLOW_UNEXPECTED;
+      break;
+    }
+
+    switch (src->msg->status)
+    {
+    case SOUP_MESSAGE_STATUS_IDLE:
+      GST_DEBUG_OBJECT (src, "Queueing connection request");
+      soup_session_queue_message (src->session, src->msg,
+                                  soup_response, src);
+      break;
+    case SOUP_MESSAGE_STATUS_FINISHED:
+      GST_DEBUG_OBJECT (src, "Connection closed");
+      if (src->session) {
+        soup_session_abort (src->session);  /* This unrefs the message. */
+        g_object_unref (src->session);
+        src->session = NULL;
+        src->msg = NULL;
+      }
+      src->ret = GST_FLOW_UNEXPECTED;
+      break;
+    case SOUP_MESSAGE_STATUS_QUEUED:
+    case SOUP_MESSAGE_STATUS_CONNECTING:
+    case SOUP_MESSAGE_STATUS_RUNNING:
+    default:
+      soup_message_io_unpause (src->msg);
+      break;
+    }
+
+    if (src->ret == GST_FLOW_CUSTOM_ERROR)
+      g_main_loop_run (src->loop);
+  } while (src->ret == GST_FLOW_CUSTOM_ERROR);
+
+  return src->ret;
+}
+
+/* create a socket for connecting to remote server */
+static gboolean
+gst_souphttp_src_start (GstBaseSrc * bsrc)
+{
+  GstSouphttpSrc *src = GST_SOUPHTTP_SRC (bsrc);
+  GMainContext *context;
+
+  if (!src->location) {
+    GST_ELEMENT_ERROR (src, LIBRARY, INIT,
+                       (NULL), ("Missing location property"));
+    return FALSE;
+  }
+
+  context = g_main_context_new ();
+
+  src->loop = g_main_loop_new (context, TRUE);
+  if (!src->loop)
+  {
+    GST_ELEMENT_ERROR (src, LIBRARY, INIT,
+                       (NULL), ("Failed to start GMainLoop"));
+    return FALSE;
+  }
+
+  src->session = soup_session_async_new_with_options (
+    SOUP_SESSION_ASYNC_CONTEXT, context,
+    NULL);
+  if (!src->session)
+  {
+    GST_ELEMENT_ERROR (src, LIBRARY, INIT,
+                       (NULL), ("Failed to create async session"));
+    return FALSE;
+  }
+
+  src->msg = soup_message_new (SOUP_METHOD_GET, src->location);
+  if (!src->msg) {
+    GST_ELEMENT_ERROR (src, LIBRARY, INIT,
+                       (NULL), ("Error parsing URL"));
+    return FALSE;
+  }
+
+  g_signal_connect (src->msg, "got_chunk",
+                    G_CALLBACK (soup_got_chunk), src);
+  soup_message_set_flags (src->msg, SOUP_MESSAGE_OVERWRITE_CHUNKS);
+
+  return TRUE;
+}
+
+/* close the socket and associated resources
+ * used both to recover from errors and go to NULL state */
+static gboolean
+gst_souphttp_src_stop (GstBaseSrc * bsrc)
+{
+  GstSouphttpSrc *src;
+
+  src = GST_SOUPHTTP_SRC (bsrc);
+  GST_DEBUG_OBJECT (src, "stop()");
+
+  if (src->session) {
+    soup_session_abort (src->session);  /* This unrefs the message. */
+    g_object_unref (src->session);
+    src->session = NULL;
+    src->msg = NULL;
+  }
+
+  return TRUE;
+}
+
+/* Interrupt a blocking request. */
+static gboolean
+gst_souphttp_src_unlock (GstBaseSrc * bsrc)
+{
+  GST_LOG_OBJECT (bsrc, "unlock");
+
+  return gst_souphttp_src_stop (bsrc);
+}
+
+static gboolean
+gst_souphttp_src_set_location (GstSouphttpSrc * src, const gchar * uri)
+{
+  if (src->location) {
+    g_free (src->location);
+    src->location = NULL;
+  }
+  src->location = g_strdup (uri);
+
+  return TRUE;
+}
+
+static void
+soup_got_chunk (SoupMessage *msg, GstSouphttpSrc *src)
+{
+  GstBaseSrc *basesrc;
+
+  basesrc = GST_BASE_SRC_CAST (src);
+  GST_DEBUG_OBJECT (src, "got chunk of %d bytes", msg->response.length);
+
+  /* Create the buffer. */
+  src->ret = gst_pad_alloc_buffer (GST_BASE_SRC_PAD (basesrc),
+      basesrc->segment.last_stop, msg->response.length,
+      GST_PAD_CAPS (GST_BASE_SRC_PAD (basesrc)), src->outbuf);
+  if (G_LIKELY (src->ret == GST_FLOW_OK))
+      memcpy (GST_BUFFER_DATA (*src->outbuf), msg->response.body, msg->response.length);
+
+  g_main_loop_quit (src->loop);
+  soup_message_io_pause (msg);
+}
+
+static void
+soup_response (SoupMessage *msg, gpointer user_data)
+{
+  GstSouphttpSrc *src = (GstSouphttpSrc *)user_data;
+
+  GST_DEBUG_OBJECT (src, "got response %d: %s", msg->status_code, msg->reason_phrase);
+  g_main_loop_quit (src->loop);
+}
+
+/* entry point to initialize the plug-in
+ * initialize the plug-in itself
+ * register the element factories and pad templates
+ * register the features
+ */
+static gboolean
+plugin_init (GstPlugin * plugin)
+{
+  return gst_element_register (plugin, "souphttpsrc", GST_RANK_NONE,
+      GST_TYPE_SOUPHTTP_SRC);
+}
+
+/* this is the structure that gst-register looks for
+ * so keep the name plugin_desc, or you cannot get your plug-in registered */
+GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
+    GST_VERSION_MINOR,
+    "soup",
+    "libsoup http client src",
+    plugin_init, VERSION, "LGPL", "GStreamer", "http://gstreamer.net/")
--- ext/soup/gstsouphttpsrc.h	1970-01-01 01:00:00.000000000 +0100
+++ ext/soup/gstsouphttpsrc.h	2007-11-15 11:08:17.000000000 +0100
@@ -0,0 +1,60 @@
+/* GStreamer
+ * Copyright (C) <2007> Wouter Cloetens <wouter@mind.be>
+ *
+ * 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 
+ */
+
+#ifndef __GST_SOUPHTTP_SRC_H__
+#define __GST_SOUPHTTP_SRC_H__
+
+#include <gst/gst.h>
+#include <gst/base/gstpushsrc.h>
+#include <glib.h>
+
+G_BEGIN_DECLS
+
+#include <libsoup/soup.h>
+
+#define GST_TYPE_SOUPHTTP_SRC \
+  (gst_souphttp_src_get_type())
+#define GST_SOUPHTTP_SRC(obj) \
+  (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_SOUPHTTP_SRC,GstSouphttpSrc))
+#define GST_SOUPHTTP_SRC_CLASS(klass) \
+  (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_SOUPHTTP_SRC,GstSouphttpSrcClass))
+#define GST_IS_SOUPHTTP_SRC(obj) \
+  (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_SOUPHTTP_SRC))
+#define GST_IS_SOUPHTTP_SRC_CLASS(klass) \
+  (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_SOUPHTTP_SRC))
+
+typedef struct _GstSouphttpSrc GstSouphttpSrc;
+typedef struct _GstSouphttpSrcClass GstSouphttpSrcClass;
+
+struct _GstSouphttpSrc {
+  GstPushSrc element;
+
+  gchar *location;                      /* Full URI. */
+  GMainLoop *loop;                      /* Event loop. */
+  SoupSession *session;                 /* Async context. */
+  SoupMessage *msg;                     /* Request message. */
+  GstFlowReturn ret;                    /* Return code from callback. */
+  GstBuffer **outbuf;                   /* Return buffer allocated by callback. */
+};
+
+struct _GstSouphttpSrcClass {
+  GstPushSrcClass parent_class;
+};
+
+GType gst_souphttp_src_get_type (void);
+
+G_END_DECLS
+
+#endif /* __GST_SOUPHTTP_SRC_H__ */
+
