Index: configure.ac
===================================================================
--- configure.ac	(revision 423)
+++ configure.ac	(working copy)
@@ -78,6 +78,7 @@
 GST_PLUGINS_ALL="\
   cdxaparse \
   deinterlace \
+  dvdsubparse \
   filter \
   freeze \
   h264parse \
@@ -904,6 +905,7 @@
 gst/Makefile
 gst/cdxaparse/Makefile
 gst/deinterlace/Makefile
+gst/dvdsubparse/Makefile
 gst/filter/Makefile
 gst/freeze/Makefile
 gst/h264parse/Makefile
Index: gst/dvdsubparse/gstdvdsubparse.c
===================================================================
--- gst/dvdsubparse/gstdvdsubparse.c	(revision 0)
+++ gst/dvdsubparse/gstdvdsubparse.c	(revision 0)
@@ -0,0 +1,304 @@
+/* GStreamer Element
+ * Copyright (C) <2007> Mark Nauwelaerts <mnauw@users.sourceforge.net>
+ *
+ * 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.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+#include <string.h>
+#include <gst/gst.h>
+#include <gst/video/video.h>
+#include "gstdvdsubparse.h"
+
+
+static const GstElementDetails dvdsubparse_details =
+GST_ELEMENT_DETAILS ("DVD Subtitle Parser",
+    "Codec/Parser/Subtitle",
+    "Parses and packetizes DVD subtitle streams",
+    "Mark Nauwelaerts <mnauw@users.sourceforge.net>");
+
+GST_DEBUG_CATEGORY_STATIC (dvdsubparse_debug);
+#define GST_CAT_DEFAULT   dvdsubparse_debug
+
+
+/* Filter signals and args */
+enum
+{
+  /* FILL ME */
+  LAST_SIGNAL
+};
+
+enum
+{
+  ARG_0
+};
+
+static GstStaticPadTemplate src_template = GST_STATIC_PAD_TEMPLATE ("src",
+    GST_PAD_SRC,
+    GST_PAD_ALWAYS,
+    GST_STATIC_CAPS ("video/x-dvd-subpicture")
+    );
+
+static GstStaticPadTemplate sink_template = GST_STATIC_PAD_TEMPLATE ("sink",
+    GST_PAD_SINK,
+    GST_PAD_ALWAYS,
+    GST_STATIC_CAPS ("video/x-dvd-subpicture")
+    );
+
+
+static void gst_dvd_sub_parse_set_property (GObject * object,
+    guint prop_id, const GValue * value, GParamSpec * pspec);
+static void gst_dvd_sub_parse_get_property (GObject * object,
+    guint prop_id, GValue * value, GParamSpec * pspec);
+
+static void gst_dvd_sub_parse_finalize (GObject * object);
+
+static void gst_dvd_sub_parse_reset (GstDvdSubParse * parse);
+
+static gboolean gst_dvd_sub_parse_event (GstPad * pad, GstEvent * event);
+static GstFlowReturn gst_dvd_sub_parse_chain (GstPad * pad, GstBuffer * buf);
+
+static GstStateChangeReturn gst_dvd_sub_parse_change_state (GstElement * element,
+    GstStateChange transition);
+GST_BOILERPLATE (GstDvdSubParse, gst_dvd_sub_parse, GstElement, GST_TYPE_ELEMENT);
+
+
+static void
+gst_dvd_sub_parse_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 (&src_template));
+  gst_element_class_add_pad_template (element_class,
+      gst_static_pad_template_get (&sink_template));
+  gst_element_class_set_details (element_class, &dvdsubparse_details);
+}
+
+static void
+gst_dvd_sub_parse_class_init (GstDvdSubParseClass * klass)
+{
+  GObjectClass *gobject_class;
+  GstElementClass *gstelement_class;
+
+  gobject_class = (GObjectClass *) klass;
+  gstelement_class = (GstElementClass *) klass;
+
+  gobject_class->finalize = GST_DEBUG_FUNCPTR (gst_dvd_sub_parse_finalize);
+
+  GST_DEBUG_CATEGORY_INIT (dvdsubparse_debug, "dvdsubparse", 0,
+      "DVD Subtitle Parser");
+
+  gstelement_class->change_state =
+      GST_DEBUG_FUNCPTR (gst_dvd_sub_parse_change_state);
+
+  gobject_class->set_property = gst_dvd_sub_parse_set_property;
+  gobject_class->get_property = gst_dvd_sub_parse_get_property;
+}
+
+static void
+gst_dvd_sub_parse_finalize (GObject * object)
+{
+  GstDvdSubParse *parse = GST_DVD_SUB_PARSE (object);
+
+  gst_object_unref (parse->adapter);
+
+  G_OBJECT_CLASS (parent_class)->finalize (object);
+}
+
+static void
+gst_dvd_sub_parse_init (GstDvdSubParse * parse, GstDvdSubParseClass * klass)
+{
+  GstPad *pad;
+
+  /* pads */
+  pad = parse->sinkpad =
+      gst_pad_new_from_template (gst_static_pad_template_get
+      (&sink_template), "sink");
+  gst_element_add_pad (GST_ELEMENT (parse), pad);
+  gst_pad_set_chain_function (pad,
+      GST_DEBUG_FUNCPTR (gst_dvd_sub_parse_chain));
+  gst_pad_set_event_function (pad,
+      GST_DEBUG_FUNCPTR (gst_dvd_sub_parse_event));
+
+  pad = parse->srcpad =
+      gst_pad_new_from_template (gst_static_pad_template_get
+      (&src_template), "src");
+  gst_element_add_pad (GST_ELEMENT (parse), pad);
+  gst_pad_use_fixed_caps (parse->srcpad);
+  gst_pad_set_caps (parse->srcpad,
+      gst_pad_template_get_caps (gst_static_pad_template_get (&src_template)));
+
+  /* remainder */
+  parse->adapter = gst_adapter_new ();
+  gst_dvd_sub_parse_reset (parse);
+}
+
+static void
+gst_dvd_sub_parse_reset (GstDvdSubParse * parse)
+{
+  parse->needed = 0;
+  parse->stamp = GST_CLOCK_TIME_NONE;
+  gst_adapter_clear (parse->adapter);
+}
+
+static gboolean
+gst_dvd_sub_parse_event (GstPad * pad, GstEvent * event)
+{
+  GstDvdSubParse *parse = GST_DVD_SUB_PARSE (GST_PAD_PARENT (pad));
+
+  switch GST_EVENT_TYPE (event) {
+    case GST_EVENT_FLUSH_STOP:
+      gst_dvd_sub_parse_reset (parse);
+      /* fall-through */
+    default:
+      return gst_pad_event_default (pad, event);
+      break;
+  }
+}
+
+
+static GstFlowReturn
+gst_dvd_sub_parse_chain (GstPad * pad, GstBuffer * buf)
+{
+  GstDvdSubParse *parse = GST_DVD_SUB_PARSE (GST_PAD_PARENT (pad));
+  GstAdapter *adapter;
+  GstBuffer *outbuf = NULL;
+  GstFlowReturn ret = GST_FLOW_OK;
+
+  adapter = parse->adapter;
+
+  gst_adapter_push (adapter, buf);
+
+  if (!parse->needed) {
+    const guint8 *data;
+
+    data = gst_adapter_peek (adapter, 2);
+    parse->needed = GST_READ_UINT16_BE (data);
+  }
+
+  if (GST_BUFFER_TIMESTAMP_IS_VALID (buf)) {
+    if (GST_CLOCK_TIME_IS_VALID (parse->stamp))
+      /* normally, we expect only the first fragment to carry a timestamp */
+      GST_WARNING_OBJECT (parse, "Received more timestamps than expected.");
+    else
+      parse->stamp = GST_BUFFER_TIMESTAMP (buf);
+  }
+
+  if (parse->needed) {
+    guint av;
+
+    av = gst_adapter_available (adapter);
+    if (av >= parse->needed) {
+      if (av > parse->needed) {
+        /* normally, we expect several fragment, boundary aligned */
+        GST_WARNING_OBJECT (parse, "Unexpected: needed %d, "
+            "but more (%d) is available.", parse->needed, av);
+      }
+      outbuf = gst_adapter_take_buffer (adapter, parse->needed);
+      /* decorate buffer */
+      gst_buffer_set_caps (outbuf, GST_PAD_CAPS (parse->srcpad));
+      GST_BUFFER_TIMESTAMP (outbuf) = parse->stamp;
+      /* reset state */
+      parse->stamp = GST_CLOCK_TIME_NONE;
+      parse->needed = 0;
+      /* and send along */
+      ret = gst_pad_push (parse->srcpad, outbuf);
+    }
+  }
+
+  return ret;
+}
+
+
+
+static void
+gst_dvd_sub_parse_set_property (GObject * object, guint prop_id,
+    const GValue * value, GParamSpec * pspec)
+{
+  GstDvdSubParse *parse;
+
+  g_return_if_fail (GST_IS_DVD_SUB_PARSE (object));
+  parse = GST_DVD_SUB_PARSE (object);
+
+  switch (prop_id) {
+    default:
+      break;
+  }
+}
+
+static void
+gst_dvd_sub_parse_get_property (GObject * object, guint prop_id, GValue * value,
+    GParamSpec * pspec)
+{
+  GstDvdSubParse *parse;
+
+  g_return_if_fail (GST_IS_DVD_SUB_PARSE (object));
+  parse = GST_DVD_SUB_PARSE (object);
+
+  switch (prop_id) {
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+  }
+}
+
+static GstStateChangeReturn
+gst_dvd_sub_parse_change_state (GstElement * element, GstStateChange transition)
+{
+  GstDvdSubParse *parse = GST_DVD_SUB_PARSE (element);
+  GstStateChangeReturn ret;
+
+  switch (transition) {
+    case GST_STATE_CHANGE_NULL_TO_READY:
+    case GST_STATE_CHANGE_READY_TO_PAUSED:
+      break;
+    case GST_STATE_CHANGE_PAUSED_TO_READY:
+      break;
+    default:
+      break;
+  }
+
+  ret = GST_CALL_PARENT_WITH_DEFAULT (GST_ELEMENT_CLASS, change_state,
+      (element, transition), GST_STATE_CHANGE_SUCCESS);
+  if (ret != GST_STATE_CHANGE_SUCCESS)
+    return ret;
+
+  switch (transition) {
+    case GST_STATE_CHANGE_PAUSED_TO_READY:
+      gst_dvd_sub_parse_reset (parse);
+      break;
+    default:
+      break;
+  }
+
+  return GST_STATE_CHANGE_SUCCESS;
+}
+
+static gboolean
+plugin_init (GstPlugin * plugin)
+{
+  return gst_element_register (plugin, "dvdsubparse", GST_RANK_NONE,
+      GST_TYPE_DVD_SUB_PARSE);
+}
+
+GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
+    GST_VERSION_MINOR,
+    "dvdsubparse",
+    "Parse DVD subtitle stream",
+    plugin_init, VERSION, GST_LICENSE, GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN)
Index: gst/dvdsubparse/gstdvdsubparse.h
===================================================================
--- gst/dvdsubparse/gstdvdsubparse.h	(revision 0)
+++ gst/dvdsubparse/gstdvdsubparse.h	(revision 0)
@@ -0,0 +1,68 @@
+/* GStreamer Element
+ * Copyright (C) <2007> Mark Nauwelaerts <mnauw@users.sourceforge.net>
+ *
+ * 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_DVDSUBPARSE_H__
+#define __GST_DVDSUBPARSE_H__
+
+
+#include <gst/gst.h>
+#include <gst/base/gstadapter.h>
+
+G_BEGIN_DECLS
+
+#define GST_TYPE_DVD_SUB_PARSE \
+  (gst_dvd_sub_parse_get_type())
+#define GST_DVD_SUB_PARSE(obj) \
+  (G_TYPE_CHECK_INSTANCE_CAST((obj), GST_TYPE_DVD_SUB_PARSE, GstDvdSubParse))
+#define GST_DVD_SUB_PARSE_CLASS(klass) \
+  (G_TYPE_CHECK_CLASS_CAST((klass), GST_TYPE_DVD_SUB_PARSE, GstDvdSubParseClass))
+#define GST_DVD_SUB_PARSE_GET_CLASS(obj) \
+  (G_TYPE_INSTANCE_GET_CLASS((obj), GST_TYPE_DVD_SUB_PARSE, GstDvdSubParseClass))
+#define GST_IS_DVD_SUB_PARSE(obj) \
+  (G_TYPE_CHECK_INSTANCE_TYPE((obj), GST_TYPE_DVD_SUB_PARSE))
+#define GST_IS_DVD_SUB_PARSE_CLASS(klass) \
+  (G_TYPE_CHECK_CLASS_TYPE((klass), GST_TYPE_DVD_SUB_PARSE))
+
+typedef struct _GstDvdSubParse GstDvdSubParse;
+typedef struct _GstDvdSubParseClass GstDvdSubParseClass;
+
+struct _GstDvdSubParse {
+  GstElement element;
+
+  GstPad *srcpad;
+  GstPad *sinkpad;
+
+  /* buffer incoming data */
+  GstAdapter *adapter;
+  /* timestamp of current packet */
+  GstClockTime stamp;
+  /* size of current packet to be assembled */
+  guint needed;
+};
+
+struct _GstDvdSubParseClass {
+  GstElementClass parent_class;
+};
+
+GType gst_dvd_sub_parse_get_type (void);
+
+G_END_DECLS
+
+#endif /* __GST_DVDSUBPARSE_H__ */
Index: gst/dvdsubparse/Makefile.am
===================================================================
--- gst/dvdsubparse/Makefile.am	(revision 0)
+++ gst/dvdsubparse/Makefile.am	(revision 0)
@@ -0,0 +1,9 @@
+
+plugin_LTLIBRARIES = libgstdvdsubparse.la
+
+libgstdvdsubparse_la_SOURCES = gstdvdsubparse.c
+libgstdvdsubparse_la_CFLAGS = $(GST_CFLAGS) $(GST_BASE_CFLAGS) $(GST_PLUGINS_BASE_CFLAGS)
+libgstdvdsubparse_la_LIBADD = $(GST_LIBS) $(GST_BASE_LIBS)
+libgstdvdsubparse_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
+
+noinst_HEADERS = gstdvdsubparse.h
