Index: configure.ac
===================================================================
RCS file: /cvs/gstreamer/gst-plugins-bad/configure.ac,v
retrieving revision 1.651
diff -u -u -r1.651 configure.ac
--- configure.ac	22 Mar 2006 14:31:46 -0000	1.651
+++ configure.ac	8 Apr 2006 23:50:46 -0000
@@ -650,6 +650,17 @@
   fi
 ])
 
+dnl *** vorbis ***
+translit(dnm, m, l) AM_CONDITIONAL(USE_VORBISTAG, true)
+GST_CHECK_FEATURE(VORBISTAG, [vorbis retagging plug-in], vorbistag, [
+  PKG_CHECK_MODULES(VORBISTAG, vorbis, [
+    HAVE_VORBISTAG="yes"
+  ], [
+    XIPH_PATH_VORBIS(HAVE_VORBISTAG="yes", HAVE_VORBISTAG="no")
+    AS_SCRUB_INCLUDE(VORBISTAG_CFLAGS)
+  ])
+])
+
 dnl *** XVideo ***
 dnl Look for the PIC library first, Debian requires it.
 dnl Check debian-devel archives for gory details.
@@ -835,6 +854,7 @@
 ext/sdl/Makefile
 ext/swfdec/Makefile
 ext/taglib/Makefile
+ext/vorbistag/Makefile
 ext/xvid/Makefile
 docs/Makefile
 docs/plugins/Makefile
Index: ext/Makefile.am
===================================================================
RCS file: /cvs/gstreamer/gst-plugins-bad/ext/Makefile.am,v
retrieving revision 1.170
diff -u -u -r1.170 Makefile.am
--- ext/Makefile.am	22 Mar 2006 14:31:46 -0000	1.170
+++ ext/Makefile.am	8 Apr 2006 23:50:47 -0000
@@ -202,6 +202,8 @@
 TAGLIB_DIR =
 endif
 
+VORBISTAG_DIR = vorbistag
+
 # if USE_TARKIN
 # TARKIN_DIR=tarkin
 # else
@@ -255,6 +257,7 @@
 	$(SWFDEC_DIR) \
 	$(TAGLIB_DIR) \
 	$(TARKIN_DIR) \
+	$(VORBISTAG_DIR) \
 	$(WAVPACK_DIR) \
 	$(XINE_DIR) \
 	$(XVID_DIR)
@@ -275,5 +278,6 @@
 	swfdec \
 	soundtouch \
 	taglib \
+	vorbistag \
 	wavpack \
 	xvid
--- /dev/null	2006-04-04 03:40:38.000000000 +1000
+++ ext/vorbistag/Makefile.am	2006-04-01 15:20:10.000000000 +1100
@@ -0,0 +1,8 @@
+plugin_LTLIBRARIES = libgstvorbistag.la
+
+libgstvorbistag_la_SOURCES = vorbistag.c
+libgstvorbistag_la_CFLAGS = $(GST_CFLAGS) $(VORBIS_CFLAGS) $(GST_PLUGINS_BASE_CFLAGS)
+libgstvorbistag_la_LIBADD = $(GST_LIBS) $(VORBIS_LIBS) $(GST_PLUGINS_BASE_LIBS) \
+	-lgsttag-@GST_MAJORMINOR@
+libgstvorbistag_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
+
--- /dev/null	2006-04-04 03:40:38.000000000 +1000
+++ ext/vorbistag/vorbistag.c	2006-04-01 15:20:10.000000000 +1100
@@ -0,0 +1,193 @@
+/*
+ * Copyright (C) 2006 James Livingston <doclivingston@gmail.com>
+ *
+ * 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 <gst/tag/tag.h>
+#include <gst/gsttagsetter.h>
+
+#include <vorbis/codec.h>
+
+GST_DEBUG_CATEGORY_EXTERN (vorbistag_debug);
+#define GST_CAT_DEFAULT vorbistag_debug
+
+
+#define GST_TYPE_VORBIS_TAG \
+  (gst_vorbis_tag_get_type())
+#define GST_VORBIS_TAG(obj) \
+  (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_VORBIS_TAG,GstVorbisTag))
+#define GST_VORBIS_TAG_CLASS(klass) \
+  (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_VORBIS_TAG,GstVorbisTag))
+#define GST_IS_VORBIS_TAG(obj) \
+  (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_VORBIS_TAG))
+#define GST_IS_VORBIS_TAG_CLASS(obj) \
+  (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_VORBIS_TAG))
+
+typedef struct _GstVorbisTag GstVorbisTag;
+typedef struct _GstVorbisTagClass GstVorbisTagClass;
+
+
+static void gst_vorbis_tag_base_init (gpointer g_class);
+static void gst_vorbis_tag_class_init (GstVorbisTagClass *klass);
+static void gst_vorbis_tag_init (GstVorbisTag *tagger, GstVorbisTagClass *g_class);
+
+static GstFlowReturn gst_vorbis_tag_chain (GstPad *pad, GstBuffer *buffer);
+
+struct _GstVorbisTag {
+  GstElement            element;
+
+  GstPad *              sinkpad;
+  GstPad *              srcpad;
+
+  guint                 packetno;
+};
+
+struct _GstVorbisTagClass {
+  GstElementClass parent_class;
+};
+
+#define _do_init(type)                                                          \
+  G_STMT_START{                                                                 \
+    static const GInterfaceInfo tag_setter_info = {                             \
+      NULL,                                                                     \
+      NULL,                                                                     \
+      NULL                                                                      \
+    };                                                                          \
+    g_type_add_interface_static (type, GST_TYPE_TAG_SETTER,                     \
+                                 &tag_setter_info);                             \
+  }G_STMT_END
+
+GST_BOILERPLATE_FULL (GstVorbisTag, gst_vorbis_tag, GstElement,
+    GST_TYPE_ELEMENT, _do_init);
+
+static GstElementDetails vorbis_tag_details = {
+  "VorbisTag",
+  "Formatter/Metadata",
+  "Retags vorbis streams",
+  "James Livingston <doclivingston@gmail.com>"
+};
+
+GST_DEBUG_CATEGORY (vorbistag_debug);
+
+static gboolean
+plugin_init (GstPlugin * plugin)
+{
+  if (!gst_element_register (plugin, "vorbistag", GST_RANK_NONE, GST_TYPE_VORBIS_TAG))
+    return FALSE;
+
+  GST_DEBUG_CATEGORY_INIT (vorbistag_debug, "vorbistag", 0,
+      "vorbis re-tagging element");
+
+  return TRUE;
+}
+
+GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
+    GST_VERSION_MINOR,
+    "vorbistag",
+    "Vorbis retagging plugin",
+    plugin_init, VERSION, "LGPL",
+    GST_PACKAGE, GST_ORIGIN)
+
+
+static GstStaticPadTemplate vorbis_tag_sink_factory =
+GST_STATIC_PAD_TEMPLATE ("sink",
+    GST_PAD_SINK,
+    GST_PAD_ALWAYS,
+    GST_STATIC_CAPS ("audio/x-vorbis")
+    );
+
+static GstStaticPadTemplate vorbis_tag_src_factory =
+GST_STATIC_PAD_TEMPLATE ("src",
+    GST_PAD_SRC,
+    GST_PAD_ALWAYS,
+    GST_STATIC_CAPS ("audio/x-vorbis")
+    );
+
+
+static void
+gst_vorbis_tag_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 (&vorbis_tag_src_factory));
+  gst_element_class_add_pad_template (element_class,
+      gst_static_pad_template_get (&vorbis_tag_sink_factory));
+  gst_element_class_set_details (element_class, &vorbis_tag_details);
+}
+
+static void
+gst_vorbis_tag_class_init (GstVorbisTagClass * klass)
+{
+  /*GstElementClass *gstelement_class = GST_ELEMENT_CLASS (klass);*/
+}
+
+static void
+gst_vorbis_tag_init (GstVorbisTag *tagger, GstVorbisTagClass * g_class)
+{
+  tagger->sinkpad =
+      gst_pad_new_from_static_template (&vorbis_tag_sink_factory, "sink");
+  gst_element_add_pad (GST_ELEMENT (tagger), tagger->sinkpad);
+  gst_pad_set_chain_function (tagger->sinkpad, gst_vorbis_tag_chain);
+
+  tagger->srcpad = gst_pad_new_from_static_template (&vorbis_tag_src_factory, "src");
+  gst_element_add_pad (GST_ELEMENT (tagger), tagger->srcpad);
+}
+
+static GstFlowReturn
+gst_vorbis_tag_chain (GstPad *pad, GstBuffer *buffer)
+{
+  GstVorbisTag *tagger;
+  ogg_packet packet;
+  const GstTagList *user_tags;
+  GstTagList *old_tags, *new_tags;
+  gchar *encoder = NULL;
+  GstBuffer *new_buf;
+
+  tagger = GST_VORBIS_TAG (GST_PAD_PARENT (pad));
+
+  packet.packet = GST_BUFFER_DATA (buffer);
+
+  /* just pass everything except the comments packet */
+  if (packet.packet[0] != 0x03) {
+    return gst_pad_push (tagger->srcpad, buffer);
+  }
+
+  old_tags = gst_tag_list_from_vorbiscomment_buffer (buffer, (guint8 *) "\003vorbis", 7, &encoder);
+  gst_buffer_unref (buffer);
+
+  /* build new tag list */
+  user_tags = gst_tag_setter_get_tag_list (GST_TAG_SETTER (tagger));
+  if (user_tags) {
+    new_tags = gst_tag_list_merge (user_tags, old_tags,
+                                   gst_tag_setter_get_tag_merge_mode (GST_TAG_SETTER (tagger)));
+    gst_tag_list_free (old_tags);
+  } else {
+    new_tags = old_tags;
+  }
+
+  new_buf = gst_tag_list_to_vorbiscomment_buffer (new_tags, (guint8 *) "\003vorbis", 7, encoder);
+  gst_tag_list_free (new_tags);
+  g_free (encoder);
+
+  return gst_pad_push (tagger->srcpad, new_buf);
+}
+
