=== added file 'check/elements/cmmldec.c'
--- /dev/null
+++ check/elements/cmmldec.c
@@ -0,0 +1,389 @@
+/*
+ * cmmldec.c - GStreamer CMML decoder test suite
+ * Copyright (C) 2005 Alessandro Decina
+ * 
+ * Authors:
+ *   Alessandro Decina <alessandro@nnva.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.
+ */
+
+#include <gst/check/gstcheck.h>
+
+GList *buffers;
+GList *out_buf = NULL;
+
+GstPad *srcpad, *sinkpad;
+
+#define SINK_CAPS "text/xml"
+#define SRC_CAPS "text/x-cmml"
+
+#define CMML_IDENT_HEADER \
+  "CMML\x00\x00\x00\x00"\
+  "\x02\x00\x01\x00"\
+  "\x00\x00\x00\x00\x00\x00\x00\x00"\
+  "\x00\x00\x00\x00\x00\x00\x00\x00"\
+  "\x00"
+
+#define XML_PREAMBLE \ 
+ "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"\
+  "<!DOCTYPE cmml SYSTEM \"cmml.dtd\">\n"\
+  
+
+#define CMML_FIRST_HEADER \
+ XML_PREAMBLE "<?cmml?>"
+
+#define CMML_FIRST_HEADER_DECODED \
+ XML_PREAMBLE "<cmml >"
+
+#define CMML_SECOND_HEADER \
+  "<head>"\
+  "<title>The Research Hunter</title>"\
+  "<meta name=\"DC.audience\" content=\"General\"/>"\
+  "<meta name=\"DC.author\" content=\"CSIRO Publishing\"/>"\
+  "<meta name=\"DC.format\" content=\"video\"/>"\
+  "<meta name=\"DC.language\" content=\"English\"/>"\
+  "<meta name=\"DC.publisher\" content=\"CSIRO Australia\"/>"\
+  "</head>"
+
+#define CMML_SECOND_HEADER_DECODED \
+  CMML_SECOND_HEADER
+
+#define CMML_CLIP \
+  "<clip id=\"intro\" track=\"default\">"\
+  "<a href=\"http://www.csiro.au/\">http://www.csiro.au</a>"\
+  "<img src=\"images/index1.jpg\"/>"\
+  "<desc>Welcome to CSIRO</desc>"\
+  "<meta name=\"test\" content=\"test content\"/>"\
+  "</clip>"
+
+#define CMML_CLIP_DECODED \
+  "<clip id=\"intro\" track=\"default\" start=\"0:00:00.000\">"\
+  "<a href=\"http://www.csiro.au/\">http://www.csiro.au</a>"\
+  "<img src=\"images/index1.jpg\"/>"\
+  "<desc>Welcome to CSIRO</desc>"\
+  "<meta name=\"test\" content=\"test content\"/>"\
+  "</clip>"
+
+static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
+    GST_PAD_SINK,
+    GST_PAD_ALWAYS,
+    GST_STATIC_CAPS (SINK_CAPS)
+    );
+
+static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
+    GST_PAD_SRC,
+    GST_PAD_ALWAYS,
+    GST_STATIC_CAPS (SRC_CAPS)
+    );
+
+GstElement *
+setup_cmmldec ()
+{
+  GstElement *cmmldec;
+
+  GST_DEBUG ("setup_cmmldec");
+  cmmldec = gst_check_setup_element ("cmmldec");
+  srcpad = gst_check_setup_src_pad (cmmldec, &srctemplate, NULL);
+  sinkpad = gst_check_setup_sink_pad (cmmldec, &sinktemplate, NULL);
+  
+  return cmmldec;
+}
+
+void
+cleanup_cmmldec (GstElement * cmmldec)
+{
+  GST_DEBUG ("cleanup_cmmldec");
+
+  gst_check_teardown_src_pad (cmmldec);
+  gst_check_teardown_sink_pad (cmmldec);
+  gst_check_teardown_element (cmmldec);
+}
+
+GstBuffer *
+cmml_buffer_new (gchar * buffer_data, guint size)
+{
+  GstBuffer *buffer;
+  GstCaps *caps;
+  
+  buffer = gst_buffer_new_and_alloc (size);
+  memcpy (GST_BUFFER_DATA (buffer), buffer_data, size);
+  caps = gst_caps_from_string (SRC_CAPS);
+  gst_buffer_set_caps (buffer, caps);
+  gst_caps_unref (caps);
+
+  return buffer;
+}
+
+void
+cmml_buffer_unref (void *buffer, void *user_data)
+{
+  ASSERT_OBJECT_REFCOUNT (buffer, "buf", 1);
+  gst_buffer_unref (GST_BUFFER (buffer));
+}
+
+void
+decode_ident_header ()
+{
+  GstBuffer *buffer;
+  
+  /* push the CMML ident packet: the decoder shouldn't output anything */
+  buffer = cmml_buffer_new (CMML_IDENT_HEADER, 29);
+  fail_unless_equals_int (gst_pad_push (srcpad, buffer), GST_FLOW_OK);
+  fail_unless (buffers == NULL);
+}
+
+void
+decode_first_header ()
+{
+  GstBuffer *buffer;
+  gchar *data;
+  
+  /* push the first secondary header: the decoder should output the pushed
+   * header unchanged and the cmml start tag (so two buffers)
+   */
+  buffer = cmml_buffer_new (CMML_FIRST_HEADER, strlen (CMML_FIRST_HEADER));
+  fail_unless_equals_int (gst_pad_push (srcpad, buffer), GST_FLOW_OK);
+  out_buf = buffers;
+  /* should output two buffers */
+  fail_unless_equals_int (g_list_length (out_buf), 1);
+  
+  buffer = GST_BUFFER (out_buf->data);
+  ASSERT_BUFFER_REFCOUNT (buffer, "first-header-buffer", 1);
+  data = g_strndup ((gchar *)GST_BUFFER_DATA (buffer),
+      GST_BUFFER_SIZE (buffer));
+  fail_unless_equals_string (data, CMML_FIRST_HEADER_DECODED); 
+  g_free (data);
+}
+
+void
+decode_second_header ()
+{
+  GstBuffer *buffer;
+  gchar *data;
+
+  /* push the second secondary header: the decoder should output the header
+   * unchanged
+   */
+  buffer = cmml_buffer_new (CMML_SECOND_HEADER, strlen (CMML_SECOND_HEADER));
+  fail_unless_equals_int (gst_pad_push (srcpad, buffer), GST_FLOW_OK);
+  out_buf = out_buf->next;
+  /* should output one buffer */
+  fail_unless_equals_int (g_list_length (out_buf), 1);
+  buffer = GST_BUFFER (out_buf->data);
+  ASSERT_BUFFER_REFCOUNT (buffer, "second-header-buffer", 1);
+  data = g_strndup ((gchar *)GST_BUFFER_DATA (buffer),
+      GST_BUFFER_SIZE (buffer));
+  fail_unless_equals_string (data, CMML_SECOND_HEADER_DECODED);
+  g_free (data);
+}
+
+void
+decode_clip ()
+{
+  GstBuffer *buffer;
+  guchar *data;
+  
+  /* push a cmml clip: the decoder should add the start attribute to
+   * the clip tag and output the cmml end tag on EOS
+   */
+  buffer = cmml_buffer_new (CMML_CLIP, strlen (CMML_CLIP));
+  GST_BUFFER_OFFSET_END (buffer) = 3 * GST_SECOND;
+  fail_unless_equals_int (gst_pad_push (srcpad, buffer), GST_FLOW_OK);
+  /* send EOS so cmmldec will flush the last clip */
+  gst_pad_push_event (srcpad, gst_event_new_eos ());
+  out_buf = out_buf->next;
+  /* there must be two buffers */
+  fail_unless_equals_int (g_list_length (out_buf), 2);
+  /* check if the clip has been decoded correctly */
+  buffer = GST_BUFFER (out_buf->data);
+  ASSERT_OBJECT_REFCOUNT (buffer, "clip-buffer", 1);
+  data = g_strndup (GST_BUFFER_DATA (buffer), GST_BUFFER_SIZE (buffer));
+  fail_unless_equals_string ((gchar *)data, CMML_CLIP_DECODED);
+  g_free (data);
+  /* check the cmml end tag */
+  out_buf = out_buf->next;
+  buffer = GST_BUFFER (out_buf->data);
+  ASSERT_OBJECT_REFCOUNT (buffer, "cmml-end-tag-buffer", 1);
+}
+
+GST_START_TEST (test_dec)
+{
+  GstElement *cmmldec;
+  GstBus *bus;
+  
+  cmmldec = setup_cmmldec (); 
+  
+  bus = gst_bus_new ();
+  gst_element_set_bus (cmmldec, bus);
+
+  fail_unless (gst_element_set_state (cmmldec,
+        GST_STATE_PLAYING) != GST_STATE_CHANGE_FAILURE,
+      "could not set to playing");
+
+  decode_ident_header();
+  decode_first_header ();
+  decode_second_header ();
+  decode_clip();
+
+  g_list_foreach (buffers, cmml_buffer_unref, NULL);
+  g_list_free (buffers);
+  buffers = NULL;
+  gst_bus_set_flushing (bus, TRUE);
+  gst_object_unref (bus);
+  cleanup_cmmldec (cmmldec);
+}
+GST_END_TEST;
+
+GST_START_TEST (test_tags)
+{
+  GstElement *cmmldec;
+  GstBus *bus;
+  GstMessage *message;
+  GstTagList *tags;
+  const GValue *tag_val;
+  GObject *tag;
+  gchar *title, *base;
+  gboolean empty;
+  gchar *id, *track;
+  gint64 start_time, end_time;
+  gchar *anchor_href, *anchor_text;
+  gchar *img_src, *img_alt;
+  gchar *desc;
+  GValueArray *meta;
+  
+  cmmldec = setup_cmmldec ();
+  
+  bus = gst_bus_new ();
+  gst_element_set_bus (cmmldec, bus);
+
+  fail_unless (gst_element_set_state (cmmldec,
+        GST_STATE_PLAYING) != GST_STATE_CHANGE_FAILURE,
+      "could not set to playing");
+  
+  decode_ident_header ();
+  decode_first_header ();
+  decode_second_header ();
+  
+  /* read the GstCmmlTagHead tag */
+  message = gst_bus_poll (bus, GST_MESSAGE_TAG, -1);
+  fail_unless (message != NULL);
+  
+  gst_message_parse_tag (message, &tags);
+  fail_unless (tags != NULL);
+
+  tag_val = gst_tag_list_get_value_index (tags, GST_TAG_CMML_HEAD, 0);
+  fail_unless (tag_val != NULL);
+
+  tag = g_value_get_object (tag_val);
+  fail_unless (tags != NULL);
+
+  g_object_get (tag, "title", &title, "base", &base, "meta", &meta, NULL);
+  fail_unless_equals_string ("The Research Hunter", title);
+  fail_unless (base == NULL);
+  fail_unless (meta != NULL);
+  fail_unless_equals_int (meta->n_values, 10);
+  
+  gst_message_unref (message);
+  gst_tag_list_free (tags);
+  g_free (title);
+  g_free (base);
+  g_value_array_free (meta);
+  
+  decode_clip ();
+
+  /* read the GstCmmlTagClip */
+  message = gst_bus_poll (bus, GST_MESSAGE_TAG, -1);
+  fail_unless (message != NULL);
+  
+  gst_message_parse_tag (message, &tags);
+  fail_unless (tags != NULL);
+  
+  tag_val = gst_tag_list_get_value_index (tags, GST_TAG_CMML_CLIP, 0);
+  fail_unless (tag_val != NULL);
+  
+  tag = g_value_get_object (tag_val);
+  fail_unless (tag != NULL);
+  
+  g_object_get (tag, "id", &id, "empty", &empty, "track", &track,
+      "start-time", &start_time, "end-time", &end_time,
+      "anchor-href", &anchor_href, "anchor-text", &anchor_text,
+      "img-src", &img_src, "img-alt", &img_alt,
+      "desc", &desc, "meta", &meta,
+      NULL);
+  
+  fail_unless (empty == FALSE);
+  fail_unless_equals_string (id, "intro");
+  fail_unless_equals_string (track, "default");
+  fail_unless_equals_int (start_time, 0);
+  fail_unless_equals_uint64 (end_time, GST_CLOCK_TIME_NONE);
+  fail_unless_equals_string (anchor_href, "http://www.csiro.au/");
+  fail_unless_equals_string (anchor_text, "http://www.csiro.au");
+  fail_unless_equals_string (img_src, "images/index1.jpg");
+  fail_unless (img_alt == NULL);
+  fail_unless_equals_string (desc, "Welcome to CSIRO");
+  fail_unless (meta != NULL); 
+  fail_unless_equals_int (meta->n_values, 2);
+
+  g_free (id);
+  g_free (track);
+  g_free (anchor_href);
+  g_free (anchor_text);
+  g_free (img_src);
+  g_free (img_alt);
+  g_free (desc);
+  g_value_array_free (meta); 
+  gst_tag_list_free (tags);
+ 
+  g_list_foreach (buffers, cmml_buffer_unref, NULL);
+  g_list_free (buffers);
+  buffers = NULL;
+  gst_message_unref (message);
+  gst_bus_set_flushing (bus, TRUE);
+  gst_object_unref (bus);
+  cleanup_cmmldec (cmmldec);
+}
+GST_END_TEST;
+
+Suite *
+cmmldec_suite ()
+{
+  Suite *s = suite_create ("cmmldec");
+  TCase *tc_chain = tcase_create ("general");
+
+  suite_add_tcase (s, tc_chain);
+  tcase_add_test (tc_chain, test_dec);
+  tcase_add_test (tc_chain, test_tags);
+  
+  return s;
+}
+
+int
+main (int argc, char **argv)
+{
+  int nf;
+
+  Suite *s = cmmldec_suite ();
+  SRunner *sr = srunner_create (s);
+
+  gst_check_init (&argc, &argv);
+
+  srunner_run_all (sr, CK_NORMAL);
+  nf = srunner_ntests_failed (sr);
+  srunner_free (sr);
+
+  return nf;
+}

=== added file 'check/elements/cmmlenc.c'
--- /dev/null
+++ check/elements/cmmlenc.c
@@ -0,0 +1,264 @@
+/*
+ * cmmlenc.c - GStreamer CMML decoder test suite
+ * Copyright (C) 2005 Alessandro Decina
+ * 
+ * Authors:
+ *   Alessandro Decina <alessandro@nnva.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.
+ */
+
+#include <gst/check/gstcheck.h>
+
+GList *buffers;
+GList *out_buf = NULL;
+
+GstPad *srcpad, *sinkpad;
+
+#define SINK_CAPS "text/x-cmml"
+#define SRC_CAPS "text/xml"
+
+#define IDENT_HEADER \
+  "CMML\x00\x00\x00\x00"\
+  "\x03\x00\x00\x00"\
+  "\xe8\x03\x00\x00\x00\x00\x00\x00"\
+  "\x01\x00\x00\x00\x00\x00\x00\x00"\
+  "\x20"
+
+#define XML_PREAMBLE \
+  "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"\
+  "<!DOCTYPE cmml SYSTEM \"cmml.dtd\">\n"
+
+#define START_TAG \
+  "<cmml>"
+
+#define PROCESSING_INSTRUCTION \
+  "<?cmml ?>"
+
+#define PREAMBLE \
+  XML_PREAMBLE START_TAG
+
+#define PREAMBLE_ENCODED \
+  XML_PREAMBLE PROCESSING_INSTRUCTION
+
+#define STREAM_TAG \
+  "<stream timebase=\"10\">"\
+     "<import src=\"test.ogg\"/>"\
+     "<import src=\"test1.ogg\"/>"\
+   "</stream>"
+
+#define STREAM_TAG_ENCODED STREAM_TAG
+
+#define HEAD_TAG \
+  "<head>"\
+    "<title>The Research Hunter</title>"\
+    "<meta name=\"DC.audience\" content=\"General\"/>"\
+    "<meta name=\"DC.author\" content=\"CSIRO Publishing\"/>"\
+    "<meta name=\"DC.format\" content=\"video\"/>"\
+    "<meta name=\"DC.language\" content=\"English\"/>"\
+    "<meta name=\"DC.publisher\" content=\"CSIRO Australia\"/>"\
+  "</head>"
+
+#define HEAD_TAG_ENCODED HEAD_TAG
+
+#define CLIP_TAG \
+  "<clip id=\"intro\" track=\"default\" start=\"1.234\">"\
+    "<a href=\"http://www.csiro.au/\">http://www.csiro.au</a>"\
+    "<img src=\"images/index1.jpg\"/>"\
+    "<desc>Welcome to CSIRO</desc>"\
+    "<meta name=\"test\" content=\"test content\"/>"\
+  "</clip>"
+
+#define CLIP_TAG_ENCODED \
+  "<clip id=\"intro\" track=\"default\">"\
+    "<a href=\"http://www.csiro.au/\">http://www.csiro.au</a>"\
+    "<img src=\"images/index1.jpg\"/>"\
+    "<desc>Welcome to CSIRO</desc>"\
+    "<meta name=\"test\" content=\"test content\"/>"\
+  "</clip>"
+
+#define END_TAG \
+  "</cmml>"
+  
+static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
+    GST_PAD_SINK,
+    GST_PAD_ALWAYS,
+    GST_STATIC_CAPS (SINK_CAPS)
+    );
+
+static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
+    GST_PAD_SRC,
+    GST_PAD_ALWAYS,
+    GST_STATIC_CAPS (SRC_CAPS)
+    );
+
+GstElement *
+setup_cmmlenc ()
+{
+  GstElement *cmmlenc;
+
+  GST_DEBUG ("setup_cmmlenc");
+  cmmlenc = gst_check_setup_element ("cmmlenc");
+  srcpad = gst_check_setup_src_pad (cmmlenc, &srctemplate, NULL);
+  sinkpad = gst_check_setup_sink_pad (cmmlenc, &sinktemplate, NULL);
+  
+  return cmmlenc;
+}
+
+void
+cleanup_cmmlenc (GstElement * cmmlenc)
+{
+  GST_DEBUG ("cleanup_cmmlenc");
+
+  gst_check_teardown_src_pad (cmmlenc);
+  gst_check_teardown_sink_pad (cmmlenc);
+  gst_check_teardown_element (cmmlenc);
+}
+
+GstBuffer *
+buffer_new (gchar * buffer_data, guint size)
+{
+  GstBuffer *buffer;
+  GstCaps *caps;
+  
+  buffer = gst_buffer_new_and_alloc (size);
+  memcpy (GST_BUFFER_DATA (buffer), buffer_data, size);
+  caps = gst_caps_from_string (SRC_CAPS);
+  gst_buffer_set_caps (buffer, caps);
+  gst_caps_unref (caps);
+
+  return buffer;
+}
+
+void
+check_output_buffer_is_equal (gchar *name, gchar * data, gint refcount) {
+  GstBuffer *buffer = GST_BUFFER (out_buf->data);
+  ASSERT_OBJECT_REFCOUNT (buffer, name, refcount);
+  fail_unless (memcmp (GST_BUFFER_DATA (buffer), data,
+        GST_BUFFER_SIZE (buffer)) == 0,
+      "'%s' (%s) is not equal to (%s)", name,
+      GST_BUFFER_DATA (buffer), data);
+}
+
+void
+buffer_unref (void *buffer, void *user_data)
+{
+  gst_buffer_unref (GST_BUFFER (buffer));
+}
+
+void
+push_data (gchar *data, gint size)
+{
+  GstBuffer *buffer;
+  
+  buffer = buffer_new (data, size);
+  fail_unless_equals_int (gst_pad_push (srcpad, buffer), GST_FLOW_OK);
+}
+
+GST_START_TEST (test_enc)
+{
+  GstElement *cmmlenc;
+  GstBus *bus;
+  
+  cmmlenc = setup_cmmlenc (); 
+  
+  bus = gst_bus_new ();
+  gst_element_set_bus (cmmlenc, bus);
+
+  fail_unless (gst_element_set_state (cmmlenc,
+        GST_STATE_PLAYING) != GST_STATE_CHANGE_FAILURE,
+      "could not set to playing");
+ 
+  /* push the cmml start tag */
+  push_data (PREAMBLE, strlen (PREAMBLE));
+  /* push the stream tag */
+  push_data (STREAM_TAG, strlen (STREAM_TAG));
+  /* push the head tag */
+  push_data (HEAD_TAG, strlen (HEAD_TAG)); 
+  
+  /* should output the cmml ident header and the cmml start tag transformed
+   * into a processing instruction */
+  out_buf = buffers;
+  fail_unless_equals_int (g_list_length (out_buf), 3);
+  
+  /* check the ident header */
+  check_output_buffer_is_equal ("cmml-ident-buffer", IDENT_HEADER, 2);
+  
+  /* check the cmml processing instruction */
+  out_buf = out_buf->next;
+  check_output_buffer_is_equal ("cmml-preamble-buffer", PREAMBLE_ENCODED, 2);
+
+  /* check the encoded head tag */
+  out_buf = out_buf->next;
+  fail_unless_equals_int (g_list_length (out_buf), 1);
+  check_output_buffer_is_equal ("head-tag-buffer", HEAD_TAG_ENCODED, 2);
+
+  /* push the clip tag */
+  push_data (CLIP_TAG, strlen (CLIP_TAG));
+ 
+  /* check the encoded clip */
+  out_buf = out_buf->next;
+  fail_unless_equals_int (g_list_length (out_buf), 1);
+  check_output_buffer_is_equal ("clip-tag-buffer", CLIP_TAG_ENCODED, 1);
+  fail_unless_equals_uint64 (GST_BUFFER_OFFSET_END (GST_BUFFER (out_buf->data)),
+        1234);
+  
+  /* push the cmml end tag */
+  push_data (END_TAG, strlen (END_TAG));
+  
+  /* should output the EOS page */
+  out_buf = out_buf->next;
+  fail_unless_equals_int (g_list_length (out_buf), 1);
+  check_output_buffer_is_equal ("cmml-eos-buffer", NULL, 1); 
+  
+  g_list_foreach (buffers, buffer_unref, NULL);
+  g_list_free (buffers);
+  buffers = NULL;
+  gst_bus_set_flushing (bus, TRUE);
+  gst_object_unref (bus);
+  cleanup_cmmlenc (cmmlenc);
+}
+GST_END_TEST;
+
+Suite *
+cmmlenc_suite ()
+{
+  Suite *s = suite_create ("cmmlenc");
+  TCase *tc_chain = tcase_create ("general");
+
+  suite_add_tcase (s, tc_chain);
+  tcase_add_test (tc_chain, test_enc);
+  /* tcase_add_test (tc_chain, test_tags);
+  */
+  return s;
+}
+
+int
+main (int argc, char **argv)
+{
+  int nf;
+
+  Suite *s = cmmlenc_suite ();
+  SRunner *sr = srunner_create (s);
+
+  gst_check_init (&argc, &argv);
+
+  srunner_run_all (sr, CK_NORMAL);
+  nf = srunner_ntests_failed (sr);
+  srunner_free (sr);
+
+  return nf;
+}

=== added file 'check/elements/skeldec.c'
--- /dev/null
+++ check/elements/skeldec.c
@@ -0,0 +1,252 @@
+/*
+ * skeldec.c - GStreamer annodex skeleton decoder test suite
+ * Copyright (C) 2005 Alessandro Decina
+ * 
+ * Authors:
+ *   Alessandro Decina <alessandro@nnva.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.
+ */
+
+#include <gst/check/gstcheck.h>
+
+GList *buffers;
+
+GstPad *srcpad, *sinkpad;
+
+#define SKELETON_CAPS "application/x-ogg-skeleton"
+
+#define SKELETON_FISHEAD \
+  "fishead\0"\
+  "\x03\0\0\0"\
+  "\x39\x30\0\0\0\0\0\0"\
+  "\x39\x30\0\0\0\0\0\0"\
+  "\x39\x30\0\0\0\0\0\0"\
+  "\x39\x30\0\0\0\0\0\0"\
+  "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" 
+
+#define SKELETON_FISHEAD_SIZE 64
+
+#define SKELETON_FISBONE \
+  "fisbone\0"\
+  "\x2c\0\0\0"\
+  "\x39\x30\0\0"\
+  "\x39\x30\0\0"\
+  "\x39\x30\0\0\0\0\0\0"\
+  "\x39\x30\0\0\0\0\0\0"\
+  "\x39\x30\0\0\0\0\0\0"\
+  "\x39\x30\0\0"\
+  "\x20"\
+  "\0\0\0"\
+  "Content-Type: application/ogg; UTF-8\r\n"
+
+#define SKELETON_FISBONE_SIZE 90
+
+static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
+    GST_PAD_SINK,
+    GST_PAD_ALWAYS,
+    GST_STATIC_CAPS_ANY
+    );
+
+static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
+    GST_PAD_SRC,
+    GST_PAD_ALWAYS,
+    GST_STATIC_CAPS (SKELETON_CAPS)
+    );
+
+GstElement *
+setup_skeldec ()
+{
+  GstElement *skeldec;
+
+  GST_DEBUG ("setup_skeldec");
+  skeldec = gst_check_setup_element ("skeldec");
+  srcpad = gst_check_setup_src_pad (skeldec, &srctemplate, NULL);
+  sinkpad = gst_check_setup_sink_pad (skeldec, &sinktemplate, NULL);
+  
+  return skeldec;
+}
+
+void
+cleanup_skeldec (GstElement * skeldec)
+{
+  GST_DEBUG ("cleanup_skeldec");
+
+  gst_check_teardown_src_pad (skeldec);
+  gst_check_teardown_sink_pad (skeldec);
+  gst_check_teardown_element (skeldec);
+}
+
+GstBuffer *
+skel_buffer_new (gchar * buffer_data, guint size)
+{
+  GstBuffer *buffer;
+
+  buffer = gst_buffer_new_and_alloc (size);
+  memcpy (GST_BUFFER_DATA (buffer), buffer_data, size);
+  gst_buffer_set_caps (buffer, gst_caps_from_string (SKELETON_CAPS));
+
+  return buffer;
+}
+
+void
+skel_buffer_unref (void *buffer, void *user_data)
+{
+  gst_buffer_unref (GST_BUFFER (buffer));
+}
+
+GST_START_TEST (test_dec)
+{
+  GstElement *skeldec;
+  GstBus *bus;
+  GstBuffer *inbuffer;
+  GstMessage *message;
+  GstTagList *tags;
+  const GValue *tag_val, *val;
+  GObject *tag;
+  gint major, minor;
+  gint64 prestime_n, prestime_d;
+  gint64 basetime_n, basetime_d;
+  guint serial_number;
+  gint64 granule_rate_n, granule_rate_d;
+  gint64 granule_start;
+  guint64 preroll;
+  guint granule_shift;
+  GValueArray *headers;
+  gchar *content_type;
+  gchar *encoding;
+  
+  skeldec = setup_skeldec (); 
+  
+  bus = gst_bus_new ();
+  gst_element_set_bus (skeldec, bus);
+
+  fail_unless (gst_element_set_state (skeldec,
+        GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
+      "could not set to playing");
+
+  /* test the fishead */
+  inbuffer = skel_buffer_new (SKELETON_FISHEAD, SKELETON_FISHEAD_SIZE);
+  fail_unless_equals_int (gst_pad_push (srcpad, inbuffer), GST_FLOW_OK);
+
+  message = gst_bus_poll (bus, GST_MESSAGE_TAG, -1);
+  fail_unless (GST_MESSAGE_SRC (message) == GST_OBJECT (skeldec));
+
+  gst_message_parse_tag (message, &tags);
+  fail_unless (tags != NULL);
+  fail_unless_equals_int (gst_tag_list_get_tag_size (tags,
+        GST_TAG_SKELETON_FISHEAD), 1);
+  
+  tag_val = gst_tag_list_get_value_index (tags, GST_TAG_SKELETON_FISHEAD, 0);
+  fail_unless (tag_val != NULL);
+
+  tag = g_value_get_object (tag_val);   
+  fail_unless (tag != NULL);
+  
+  g_object_get (tag,
+      "version-major", &major,  "version-minor", &minor,
+      "presentation-time-numerator", &prestime_n,
+      "presentation-time-denominator", &prestime_d,
+      "base-time-numerator", &basetime_n,
+      "base-time-denominator", &basetime_d,
+      NULL);
+      
+  fail_unless_equals_int (major, 3);
+  fail_unless_equals_int (minor, 0);
+  fail_unless_equals_int (prestime_n, 12345);
+  fail_unless_equals_int (prestime_d, 12345);
+  fail_unless_equals_int (basetime_n, 12345);
+  fail_unless_equals_int (basetime_d, 12345);
+  
+  gst_tag_list_free (tags);
+  gst_message_unref (message);
+
+  /* test the fisbone */
+  inbuffer = skel_buffer_new (SKELETON_FISBONE, SKELETON_FISBONE_SIZE);
+  fail_unless_equals_int (gst_pad_push (srcpad, inbuffer), GST_FLOW_OK);
+
+  message = gst_bus_poll (bus, GST_MESSAGE_TAG, -1);
+  fail_unless (GST_MESSAGE_SRC (message) == GST_OBJECT (skeldec));
+
+  gst_message_parse_tag (message, &tags);
+  fail_unless (tags != NULL);
+  fail_unless_equals_int (gst_tag_list_get_tag_size (tags,
+        GST_TAG_SKELETON_FISBONE), 1);
+  
+  tag_val = gst_tag_list_get_value_index (tags, GST_TAG_SKELETON_FISBONE, 0);
+  fail_unless (tag_val != NULL);
+
+  tag = g_value_get_object (tag_val);   
+  fail_unless (tag != NULL);
+  
+  g_object_get (tag, "serial-number", &serial_number,
+      "granule-rate-numerator", &granule_rate_n,
+      "granule-rate-denominator", &granule_rate_d,
+      "granule-start", &granule_start,
+      "granule-shift", &granule_shift,
+      "preroll", &preroll,
+      "headers", &headers,
+      "content-type", &content_type,
+      "encoding", &encoding,
+      NULL);
+  
+  fail_unless_equals_int (serial_number, 12345);
+  fail_unless_equals_int (granule_rate_n, 12345);
+  fail_unless_equals_int (granule_rate_d, 12345);
+  fail_unless_equals_int (granule_start, 12345);
+  fail_unless_equals_int (preroll, 12345);
+  fail_unless_equals_int (granule_shift, 32); 
+  fail_unless_equals_int (headers->n_values, 2);
+  fail_unless_equals_string (content_type, "application/ogg");
+  fail_unless_equals_string (encoding, "UTF-8");
+
+  g_free (headers);
+  gst_tag_list_free (tags);
+  gst_message_unref (message);
+  gst_bus_set_flushing (bus, TRUE);
+  gst_object_unref (bus);
+  cleanup_skeldec (skeldec);
+}
+GST_END_TEST;
+
+Suite *
+skeldec_suite ()
+{
+  Suite *s = suite_create ("skeldec");
+  TCase *tc_chain = tcase_create ("general");
+
+  suite_add_tcase (s, tc_chain);
+  tcase_add_test (tc_chain, test_dec);
+
+  return s;
+}
+
+int
+main (int argc, char **argv)
+{
+  int nf;
+
+  Suite *s = skeldec_suite ();
+  SRunner *sr = srunner_create (s);
+
+  gst_check_init (&argc, &argv);
+
+  srunner_run_all (sr, CK_NORMAL);
+  nf = srunner_ntests_failed (sr);
+  srunner_free (sr);
+
+  return nf;
+}

=== added directory 'gst/annodex'
=== added file 'gst/annodex/Makefile.am'
--- /dev/null
+++ gst/annodex/Makefile.am
@@ -0,0 +1,27 @@
+# plugindir is set in configure
+
+# change libgstplugin.la to something more suitable
+plugin_LTLIBRARIES = libgstannodex.la
+
+# for the next set of variables, rename the prefix if you renamed the .la
+
+# sources used to compile this plug-in
+libgstannodex_la_SOURCES = \
+	gstannodex.c \
+	gstcmmlclock.c \
+	gstcmmldec.c \
+	gstcmmlenc.c \
+	gstcmmltag.c \
+	gstcmmlparser.c \
+	gstskeldec.c \
+	gstskeltag.c
+
+# flags used to compile this plugin
+# we use the GST_LIBS flags because we might be using plug-in libs
+libgstannodex_la_CFLAGS = $(GST_CFLAGS)
+libgstannodex_la_LIBADD = $(GST_BASE_LIBS) $(GST_LIBS) $(GST_CTRL_LIBS)
+libgstannodex_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
+
+# headers we need but don't want installed
+noinst_HEADERS = gstannodex.h gstcmmltag.h gstcmmlparser.h \
+	gstcmmldec.h gstskeldec.h

=== added file 'gst/annodex/gstannodex.c'
--- /dev/null
+++ gst/annodex/gstannodex.c
@@ -0,0 +1,165 @@
+/*
+ * gstannodex.c - GStreamer annodex plugin
+ * Copyright (C) 2005 Alessandro Decina
+ * 
+ * Authors:
+ *   Alessandro Decina <alessandro@nnva.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.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <math.h>
+
+#include "gstcmmlenc.h"
+#include "gstcmmldec.h"
+#include "gstskeldec.h"
+
+GstClockTime
+gst_annodex_granule_to_time (gint64 granulepos, gint64 granulerate_n,
+    gint64 granulerate_d, guint8 granuleshift)
+{
+  gint64 keyindex, keyoffset;
+  GstClockTime res;
+
+  if (granulepos == -1)
+    return GST_CLOCK_TIME_NONE;
+  
+  if (granulepos == 0 || granulerate_n == 0 || granulerate_d == 0)
+    return 0;
+  
+  if (granuleshift != 0) {
+    keyindex = granulepos >> granuleshift;
+    keyoffset = granulepos - (keyindex << granuleshift);
+    granulepos = keyindex + keyoffset;
+  }
+  
+  res = GST_SECOND * (granulepos * granulerate_d) / granulerate_n;
+
+  return res;
+}
+
+GValueArray *
+gst_annodex_parse_headers (const gchar * headers) {
+  GValueArray *array;
+  GValue val = {0};
+  gchar *header_name = NULL;
+  gchar *header_value = NULL;
+  gchar *line, *column, *space, *tmp;
+  gchar **lines;
+  gint i = 0;
+
+  array = g_value_array_new (0);
+  g_value_init (&val, G_TYPE_STRING);
+  
+  lines = g_strsplit (headers, "\r\n", 0);
+  line = lines[i];
+  while (line != NULL && *line != '\0') {
+    if (line[0] == '\t' || line[0] == ' ') {
+      /* WSP: continuation line */
+      if (header_value == NULL)
+        /* continuation line without a previous value */
+        goto fail;
+
+      tmp = g_strjoin (" ", header_value, g_strstrip (line), NULL);
+      g_free (header_value);
+      header_value = tmp;
+    } else {
+      /* find the column */
+      column = g_strstr_len (line, strlen (line), ":");
+      /* find the space after the column */
+      space = g_strstr_len (line, column + 2 - line, " ");
+      if (column == NULL || space == NULL || space != column + 1)
+        /* bad syntax */
+        goto fail;
+
+      if (header_name) {
+        g_value_take_string (&val, header_name);
+        g_value_array_append (array, &val);
+        g_value_take_string (&val, header_value);
+        g_value_array_append (array, &val);
+      }
+
+      header_name = g_strndup (line, column - line);
+      header_value = g_strdup (space + 1);
+    }
+
+    line = lines[++i];
+  }
+
+  if (header_name) {
+    g_value_take_string (&val, header_name);
+    g_value_array_append (array, &val);
+    g_value_take_string (&val, header_value);
+    g_value_array_append (array, &val);
+  }
+  
+  g_value_unset (&val);
+  g_strfreev (lines);
+  
+  return array;
+
+fail:
+  g_warning ("could not parse annodex headers");
+  g_free (header_name);
+  g_free (header_value);
+  g_strfreev (lines);
+  g_value_array_free (array);
+  g_value_unset (&val);
+  return NULL;
+}
+
+static gboolean
+plugin_init (GstPlugin *plugin) {
+
+  gst_tag_register (GST_TAG_CMML_STREAM, GST_TAG_FLAG_META,
+    GST_TYPE_CMML_TAG_STREAM, "cmml-stream",
+    "annodex CMML stream tag", NULL);
+
+  gst_tag_register (GST_TAG_CMML_HEAD, GST_TAG_FLAG_META,
+    GST_TYPE_CMML_TAG_HEAD, "cmml-head",
+    "annodex CMML head tag", NULL);
+
+  gst_tag_register (GST_TAG_CMML_CLIP, GST_TAG_FLAG_META,
+    GST_TYPE_CMML_TAG_CLIP, "cmml-clip",
+    "annodex CMML clip tag", NULL);
+ 
+  if (!gst_cmml_enc_plugin_init (plugin))
+    return FALSE;
+
+  if (!gst_cmml_dec_plugin_init (plugin))
+    return FALSE;
+    
+  if (!gst_skel_dec_plugin_init (plugin))
+    return FALSE;
+    
+  return TRUE;
+}
+
+GST_PLUGIN_DEFINE (
+    GST_VERSION_MAJOR,
+    GST_VERSION_MINOR,
+    "annodex",
+    "annodex stream manipulation (info about annodex: http://www.annodex.net)",
+    plugin_init,
+    VERSION,
+    GST_LICENSE,
+    GST_PACKAGE_NAME,
+    GST_PACKAGE_ORIGIN
+)

=== added file 'gst/annodex/gstannodex.h'
--- /dev/null
+++ gst/annodex/gstannodex.h
@@ -0,0 +1,34 @@
+/*
+ * gstannodex.h - (VL_UNRESOLVED)
+ * Copyright (C) 2005 (VL_UNRESOLVED)
+ * 
+ * Authors:
+ *   Alessandro Decina <alessandro@nnva.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_ANNODEX_H__
+#define __GST_ANNODEX_H__
+
+#include <gst/gst.h>
+
+GstClockTime gst_annodex_granule_to_time (gint64 granulepos,
+    gint64 granulerate_n, gint64 granulerate_d, guint8 granuleshift);
+gchar *gst_annodex_time_to_npt (GstClockTime time);
+GValueArray *gst_annodex_parse_headers (const gchar * headers);
+
+#endif /* __GST_ANNODEX_H__ */

=== added file 'gst/annodex/gstcmmlclock.c'
--- /dev/null
+++ gst/annodex/gstcmmlclock.c
@@ -0,0 +1,72 @@
+#include "gstcmmlclock.h"
+
+#include <math.h>
+
+GstClockTime
+gst_cmml_clock_time_from_npt (const gchar * time)
+{
+  GstClockTime res;
+  gint fields;
+  gint hours;
+  gint minutes;
+  gint seconds;
+  gint mseconds = 0;
+
+  /* parse npt-hhmmss */
+  fields = sscanf (time, "%d:%d:%d.%d", &hours, &minutes, &seconds, &mseconds);
+
+  if (fields == 4) {
+    res = (((hours * 3600) + (minutes * 60) + seconds) * GST_SECOND) +
+      (mseconds * GST_MSECOND);
+  } else {
+    /* parse npt-sec */
+    fields = sscanf (time, "%d.%d", &seconds, &mseconds);
+    res = seconds * GST_SECOND + mseconds * GST_MSECOND;
+  }
+    
+  return res;
+}
+
+GstClockTime
+gst_cmml_clock_time_from_smpte (const gchar * time, const gdouble framerate)
+{
+  GstClockTime res;
+  gint hours, minutes, seconds;
+  gfloat frames;
+  gint fields;
+
+  g_return_val_if_fail (framerate > 0, GST_CLOCK_TIME_NONE);
+  
+  fields = sscanf (time, "%d:%d:%d:%f", &hours, &minutes, &seconds, &frames);
+  if (fields == 4) {
+    g_return_val_if_fail (frames > ceil (framerate) || frames < 0,
+        GST_CLOCK_TIME_NONE);
+
+    res = ((hours * 3600) + (minutes * 60) + seconds) * GST_SECOND + 
+      (frames / framerate);
+  } else {
+    res = GST_CLOCK_TIME_NONE;
+  }
+  
+  return res;
+}
+
+gchar *
+gst_cmml_clock_time_to_npt (const GstClockTime time)
+{
+  guint seconds, hours, minutes, mseconds;
+  gchar *res;
+
+  g_return_val_if_fail (time != GST_CLOCK_TIME_NONE, NULL);
+  
+  hours = time / (GST_SECOND * 3600);
+  minutes = (time / ((GST_SECOND * 60)) % 60);
+  seconds = (time / GST_SECOND) % 60;
+  mseconds = (time % GST_SECOND) / GST_MSECOND;
+ 
+  res = g_strdup_printf ("%u:%02u:%02u.%03u",
+      hours, minutes, seconds, mseconds);
+
+  return res;
+}
+

=== added file 'gst/annodex/gstcmmlclock.h'
--- /dev/null
+++ gst/annodex/gstcmmlclock.h
@@ -0,0 +1,36 @@
+/*
+ * gstcmmlclock.h - (VL_UNRESOLVED)
+ * Copyright (C) 2005 (VL_UNRESOLVED)
+ * 
+ * Authors:
+ *   Alessandro Decina <alessandro@nnva.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_CMML_CLOCK_TIME_H__
+#define __GST_CMML_CLOCK_TIME_H__
+
+#include <gst/gst.h>
+
+GstClockTime gst_cmml_clock_time_from_npt (const gchar * time);
+GstClockTime gst_cmml_clock_time_from_smpte (const gchar * time,
+    const gdouble framerate);
+gchar * gst_cmml_clock_time_to_npt (const GstClockTime time);
+#if 0
+const gchar * gst_cmml_clock_time_to_smpte (const GstClockTime * time);
+#endif
+#endif /* __GST_CMML_CLOCK_TIME_H__ */

=== added file 'gst/annodex/gstcmmldec.c'
--- /dev/null
+++ gst/annodex/gstcmmldec.c
@@ -0,0 +1,696 @@
+/*
+ * gstcmmldec.c - GStreamer annodex CMML decoder
+ * Copyright (C) 2005 Alessandro Decina
+ * 
+ * Authors:
+ *   Alessandro Decina <alessandro@nnva.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.
+ */
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <string.h>
+#include <glib.h>
+
+#include "gstannodex.h"
+#include "gstcmmltag.h"
+#include "gstcmmldec.h"
+
+GST_DEBUG_CATEGORY (cmmldec);
+#define GST_CAT_DEFAULT cmmldec
+
+enum
+{
+  ARG_0,
+  GST_CMML_DEC_EXTRACT_MODE
+};
+
+enum
+{
+  LAST_SIGNAL
+};
+
+static GstElementDetails gst_cmml_dec_details = {
+  "CmmlDec", "Codec/Decoder",
+  "decode CMML streams",
+  "Alessandro Decina <alessandro@nnva.org>",
+};
+
+static GstStaticPadTemplate gst_cmml_dec_src_factory =
+GST_STATIC_PAD_TEMPLATE ("src",
+    GST_PAD_SRC,
+    GST_PAD_ALWAYS,
+    /* this should really be text/x-cmml but that would break autoplugging */
+    GST_STATIC_CAPS ("text/xml")
+    );
+
+static GstStaticPadTemplate gst_cmml_dec_sink_factory =
+GST_STATIC_PAD_TEMPLATE ("sink",
+    GST_PAD_SINK,
+    GST_PAD_ALWAYS,
+    GST_STATIC_CAPS ("text/x-cmml")
+    );
+
+/* GstCmmlDec */
+GST_BOILERPLATE (GstCmmlDec, gst_cmml_dec, GstElement, GST_TYPE_ELEMENT);
+static void gst_cmml_dec_get_property (GObject * dec, guint property_id,
+    GValue * value, GParamSpec * pspec);
+static void gst_cmml_dec_set_property (GObject * dec, guint property_id,
+    const GValue * value, GParamSpec * pspec);
+static const GstQueryType *gst_cmml_dec_query_types (GstPad * pad);
+static gboolean gst_cmml_dec_sink_query (GstPad * pad, GstQuery * query);
+static gboolean gst_cmml_dec_sink_event (GstPad * pad, GstEvent * event);
+static gboolean gst_cmml_dec_convert (GstPad * pad, GstFormat src_fmt,
+    gint64 src_val, GstFormat * dest_fmt, gint64 * dest_val);
+static GstStateChangeReturn gst_cmml_dec_change_state (GstElement * element, GstStateChange transition);
+static GstFlowReturn gst_cmml_dec_chain (GstPad * pad, GstBuffer * buffer);
+
+static GstCmmlPacketType gst_cmml_dec_parse_packet_type (GstCmmlDec * dec,
+    GstBuffer * buffer);
+static void gst_cmml_dec_parse_ident_header (GstCmmlDec * dec,
+    GstBuffer * buf);
+static void gst_cmml_dec_parse_first_header (GstCmmlDec * dec,
+    GstBuffer * buf);
+static void gst_cmml_dec_parse_preamble (GstCmmlDec * dec,
+    guchar * preamble, guchar * cmml_root_element);
+static void gst_cmml_dec_parse_xml (GstCmmlDec * dec,
+    guchar * data, guint size);
+static void gst_cmml_dec_parse_head (GstCmmlDec * dec, GstCmmlTagHead * head);
+static void gst_cmml_dec_parse_clip (GstCmmlDec * dec, GstCmmlTagClip * clip);
+static gboolean gst_cmml_dec_clip_extracted (GstCmmlDec * dec,
+    const guchar * id);
+
+static GstFlowReturn gst_cmml_dec_new_buffer (GstCmmlDec * dec,
+    guchar * data, gint size, GstBuffer ** buffer);
+static void gst_cmml_dec_push_clip (GstCmmlDec * dec, GstCmmlTagClip * clip);
+static void gst_cmml_dec_send_clip_tag (GstCmmlDec * dec, GstCmmlTagClip * clip);
+
+static void
+gst_cmml_dec_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 (&gst_cmml_dec_sink_factory));
+  gst_element_class_add_pad_template (element_class,
+      gst_static_pad_template_get (&gst_cmml_dec_src_factory));
+  gst_element_class_set_details (element_class, &gst_cmml_dec_details);
+}
+
+static void
+gst_cmml_dec_class_init (GstCmmlDecClass * dec_class)
+{
+  GObjectClass *klass = G_OBJECT_CLASS (dec_class);
+
+  GST_ELEMENT_CLASS (klass)->change_state = gst_cmml_dec_change_state;
+
+  klass->set_property = gst_cmml_dec_set_property;
+  klass->get_property = gst_cmml_dec_get_property;
+  
+  g_object_class_install_property (klass, GST_CMML_DEC_EXTRACT_MODE,
+      g_param_spec_boolean ("extract-mode",
+        "Extract mode",
+        "Set when pre-extracting CMML clips",
+        FALSE,
+        G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE)); 
+}
+
+static void
+gst_cmml_dec_init (GstCmmlDec * dec, GstCmmlDecClass * klass)
+{
+  dec->sinkpad =
+      gst_pad_new_from_static_template (&gst_cmml_dec_sink_factory, "sink");
+  gst_pad_set_chain_function (dec->sinkpad, gst_cmml_dec_chain);
+  gst_pad_set_query_type_function (dec->sinkpad, gst_cmml_dec_query_types);
+  gst_pad_set_query_function (dec->sinkpad, gst_cmml_dec_sink_query);
+  gst_pad_set_event_function (dec->sinkpad, gst_cmml_dec_sink_event);
+  gst_element_add_pad (GST_ELEMENT (dec), dec->sinkpad);
+
+  dec->srcpad =
+      gst_pad_new_from_static_template (&gst_cmml_dec_src_factory, "src");
+  gst_element_add_pad (GST_ELEMENT (dec), dec->srcpad);
+
+  dec->extract_mode = FALSE;
+}
+
+static void
+gst_cmml_dec_get_property (GObject * object, guint property_id,
+    GValue * value, GParamSpec * pspec)
+{
+  GstCmmlDec *dec = GST_CMML_DEC (object);
+  
+  switch (property_id) {
+    case GST_CMML_DEC_EXTRACT_MODE:
+      g_value_set_boolean (value, dec->extract_mode);
+      break;
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+  }
+}
+
+static void
+gst_cmml_dec_set_property (GObject * object, guint property_id,
+    const GValue * value, GParamSpec * pspec)
+{
+  GstCmmlDec *dec = GST_CMML_DEC (object);
+
+  switch (property_id) {
+    case GST_CMML_DEC_EXTRACT_MODE:
+    {
+      gboolean new_val = g_value_get_boolean (value);
+      if (dec->extract_mode == TRUE && new_val == FALSE) {
+        if (dec->last_clip)
+        /* send now the TAG_MESSAGE for the last clip */
+          gst_cmml_dec_send_clip_tag (dec, dec->last_clip);
+      }
+      /* note: if dec->extract_mode is FALSE and new_val is TRUE the TAG_MESSAGE
+       * for dec->last_clip could be sent twice */
+      
+      dec->extract_mode = new_val;
+      break;
+    }
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (dec, property_id, pspec);
+  }
+}
+
+static GstStateChangeReturn gst_cmml_dec_change_state (GstElement * element,
+    GstStateChange transition)
+{
+  GstCmmlDec *dec = GST_CMML_DEC (element);  
+  GstStateChangeReturn res;
+  
+  switch (transition) {
+    case GST_STATE_CHANGE_READY_TO_PAUSED:
+      dec->parser = gst_cmml_parser_new (GST_CMML_PARSER_DECODE);
+      dec->parser->user_data = dec;
+      dec->parser->preamble_callback =
+        (GstCmmlParserPreambleCallback) gst_cmml_dec_parse_preamble;
+      dec->parser->head_callback =
+        (GstCmmlParserHeadCallback) gst_cmml_dec_parse_head;
+      dec->parser->clip_callback =
+        (GstCmmlParserClipCallback) gst_cmml_dec_parse_clip;
+      dec->major = -1;
+      dec->minor = -1;
+      dec->granulerate_n = -1;
+      dec->granulerate_d = -1;
+      dec->granuleshift = 0;
+      dec->granulepos = 0;
+      dec->chain_return = GST_FLOW_OK;
+      dec->sent_root = FALSE;
+      dec->last_clip = NULL;
+      dec->extracted_clips = NULL;
+      break;
+    default:
+      break;
+  }
+
+  res = parent_class->change_state (element, transition);
+
+  switch (transition) {
+    case GST_STATE_CHANGE_PAUSED_TO_READY:
+    {
+      GSList *iter;
+      
+      gst_cmml_parser_free (dec->parser);
+      if (dec->last_clip)
+        g_object_unref (dec->last_clip);
+      
+      for (iter = dec->extracted_clips; iter; iter = iter->next)
+        g_free (iter->data);
+      g_slist_free (dec->extracted_clips);
+      
+      break;
+    }
+    default:
+      break;
+  }
+
+  return res;
+}
+
+static const GstQueryType *
+gst_cmml_dec_query_types (GstPad * pad)
+{
+  static const GstQueryType query_types[] = {
+    GST_QUERY_CONVERT,
+    0
+  };
+
+  return query_types;
+}
+
+static gboolean
+gst_cmml_dec_sink_query (GstPad * pad, GstQuery * query)
+{
+  gboolean res = FALSE;
+
+  switch (GST_QUERY_TYPE (query)) {
+    case GST_QUERY_CONVERT:
+    {
+      GstFormat src_fmt, dest_fmt;
+      gint64 src_val, dest_val;
+
+      gst_query_parse_convert (query, &src_fmt, &src_val, &dest_fmt, &dest_val);
+      res = gst_cmml_dec_convert (pad, src_fmt, src_val, &dest_fmt, &dest_val);
+      if (res)
+        gst_query_set_convert (query, src_fmt, src_val, dest_fmt, dest_val);
+      break;
+    }
+    default:
+      break;
+  }
+
+  return res;
+}
+
+static gboolean
+gst_cmml_dec_convert (GstPad * pad,
+    GstFormat src_fmt, gint64 src_val, GstFormat * dest_fmt, gint64 * dest_val)
+{
+  GstCmmlDec *dec = GST_CMML_DEC (GST_PAD_PARENT (pad));
+  gboolean res = FALSE;
+
+  switch (src_fmt) {
+    case GST_FORMAT_DEFAULT:
+      switch (*dest_fmt) {
+        case GST_FORMAT_TIME:
+        {
+          *dest_val = gst_annodex_granule_to_time (src_val, dec->granulerate_n,
+              dec->granulerate_d, dec->granuleshift);
+          res = TRUE;
+          break;
+        }
+        default:
+        break;
+      }
+      break;
+    default:
+      break;
+  }
+
+  return res;
+}
+
+/* on EOS outputs the last clip and the cmml end tag */
+static gboolean
+gst_cmml_dec_sink_event (GstPad * pad, GstEvent * event)
+{
+  GstCmmlDec *dec = GST_CMML_DEC (GST_PAD_PARENT (pad));
+  
+  switch (GST_EVENT_TYPE (event)) {
+    case GST_EVENT_EOS:
+    {
+      GstBuffer * buffer;
+      
+      if (dec->last_clip) {   
+        gst_cmml_dec_push_clip (dec, dec->last_clip);
+      
+        if (dec->extract_mode) {
+          dec->last_clip->end_time = dec->timestamp;
+          gst_cmml_dec_send_clip_tag (dec, dec->last_clip);
+        }
+      }
+     
+      dec->chain_return = gst_cmml_dec_new_buffer (dec,
+        (guchar *)"</cmml>", strlen ("</cmml>"), &buffer);
+     
+      if (dec->chain_return == GST_FLOW_OK)
+        dec->chain_return = gst_pad_push (dec->srcpad, buffer);
+
+      break;
+    }
+    default:
+      break;
+  }
+
+  return gst_pad_event_default (pad, event);
+}
+
+static GstFlowReturn
+gst_cmml_dec_chain (GstPad * pad, GstBuffer * buffer)
+{
+  GstCmmlDec *dec = GST_CMML_DEC (GST_PAD_PARENT (pad));
+  GstCmmlPacketType packet;
+
+  if (GST_BUFFER_SIZE (buffer) == 0) {
+    /* the cmml EOS page has no data */
+    dec->chain_return = GST_FLOW_OK;
+    goto done;
+  }
+  
+  dec->granulepos = GST_BUFFER_OFFSET_END (buffer);
+  dec->timestamp = gst_annodex_granule_to_time (dec->granulepos,
+      dec->granulerate_n, dec->granulerate_d, dec->granuleshift);
+
+  /* identify the packet type */
+  packet = gst_cmml_dec_parse_packet_type (dec, buffer);
+  
+  /* handle the packet type. the handlers will set dec->chain_return */
+  switch (packet) {
+    case GST_CMML_PACKET_IDENT_HEADER:
+      gst_cmml_dec_parse_ident_header (dec, buffer);
+      break;
+    case GST_CMML_PACKET_FIRST_HEADER:
+      gst_cmml_dec_parse_first_header (dec, buffer);
+      break;
+    case GST_CMML_PACKET_SECOND_HEADER:
+    case GST_CMML_PACKET_CLIP:
+      gst_cmml_dec_parse_xml (dec,
+          GST_BUFFER_DATA (buffer), GST_BUFFER_SIZE (buffer));
+      break;
+    case GST_CMML_PACKET_UNKNOWN:
+    default:
+      /* maybe it would be better to ignore unknown packets */
+      GST_ELEMENT_ERROR (dec, STREAM, DECODE, (NULL), ("unknown packet type"));
+      dec->chain_return = GST_FLOW_ERROR;
+  }
+
+done:
+  gst_buffer_unref (buffer);
+  return dec->chain_return;
+}
+
+/* finds the packet type in the buffer
+ */
+static GstCmmlPacketType
+gst_cmml_dec_parse_packet_type (GstCmmlDec * dec, GstBuffer * buffer)
+{
+  GstCmmlPacketType packet_type = GST_CMML_PACKET_UNKNOWN;
+  gchar *data = (gchar *)GST_BUFFER_DATA (buffer);
+  guint size = GST_BUFFER_SIZE (buffer);
+  
+  if (size >= 8 && !strncmp (data, "CMML\0\0\0\0", 8)) {
+    packet_type = GST_CMML_PACKET_IDENT_HEADER;
+  } else if (size >= 5) {
+    if (!strncmp (data, "<?xml", 5))
+      packet_type = GST_CMML_PACKET_FIRST_HEADER;
+    else if (!strncmp (data, "<head", 5))
+      packet_type = GST_CMML_PACKET_SECOND_HEADER;
+    else if (!strncmp (data, "<clip", 5))
+      packet_type = GST_CMML_PACKET_CLIP;
+  }
+
+  return packet_type;
+}
+
+/* creates a new buffer and sets caps and timestamp on it
+ */
+static GstFlowReturn
+gst_cmml_dec_new_buffer (GstCmmlDec * dec,
+    guchar * data, gint size, GstBuffer ** buffer)
+{
+  GstFlowReturn res;
+  
+  res = gst_pad_alloc_buffer (dec->srcpad, GST_BUFFER_OFFSET_NONE,
+      size, gst_static_pad_template_get_caps (&gst_cmml_dec_src_factory),
+      buffer);
+ 
+  if (res == GST_FLOW_OK) {
+    memcpy (GST_BUFFER_DATA (*buffer), data, size);
+    GST_BUFFER_TIMESTAMP (*buffer) = dec->timestamp;
+  } else {
+    GST_ELEMENT_ERROR (dec, STREAM, DECODE,
+        ("could not allocate buffer"),
+        ("alloc function returned error %s", gst_flow_get_name (res)));
+  }
+  
+  return res;
+}
+
+/* parses the first CMML packet (the ident header)
+ */
+static void
+gst_cmml_dec_parse_ident_header (GstCmmlDec * dec, GstBuffer * buffer)
+{
+  guint8 *data = GST_BUFFER_DATA (buffer);
+  
+  data += 8;
+  dec->major = GST_READ_UINT16_LE (data);
+  data += 2;
+  dec->minor = GST_READ_UINT16_LE (data);
+  data += 2;
+  dec->granulerate_n = GST_READ_UINT64_LE (data);
+  data += 8;
+  dec->granulerate_d = GST_READ_UINT64_LE (data);
+  data += 8;
+  dec->granuleshift = GST_READ_UINT8 (data);
+ 
+  GST_INFO_OBJECT (dec, "bitstream initialized "
+      "(major: %" G_GINT16_FORMAT " minor: %" G_GINT16_FORMAT ")",
+      dec->major, dec->minor);
+ 
+  dec->chain_return = GST_FLOW_OK;
+}
+
+/* parses the first secondary header.
+ *
+ * The first secondary header contains the xml version, the doctype and the
+ * optional "cmml" processing instruction.
+ */
+static void
+gst_cmml_dec_parse_first_header (GstCmmlDec * dec, GstBuffer * buffer)
+{ 
+  gst_cmml_dec_parse_xml (dec,
+      GST_BUFFER_DATA (buffer), GST_BUFFER_SIZE (buffer));
+  
+  /* if there is a processing instruction, gst_cmml_dec_parse_preamble
+   * will be triggered. Otherwise we need to call it manually.
+   */
+  if (dec->chain_return != GST_FLOW_ERROR && !dec->sent_root) {
+    gst_cmml_dec_parse_preamble (dec, GST_BUFFER_DATA (buffer),
+        (guchar *)"<cmml>");
+  }
+}
+
+/* feeds data into the cmml parser.
+ */
+static void
+gst_cmml_dec_parse_xml (GstCmmlDec * dec, guchar * data, guint size)
+{
+  if (!gst_cmml_parser_parse_chunk (dec->parser,
+      (gchar *)data, size)) {
+    /* bad xml */
+    GST_ELEMENT_ERROR (dec, STREAM, DECODE,
+        ("bad xml"),
+        ("bad xml"));
+    dec->chain_return = GST_FLOW_ERROR;
+  }
+}
+
+/* transform a cmml processing instruction into a cmml element
+ *
+ * This callback is the GstCmmlParserCmmlPICallback registered with
+ * dec->parser. It is called if the "cmml" processing instruction is found.
+ */
+static void
+gst_cmml_dec_parse_preamble (GstCmmlDec * dec, guchar * preamble,
+    guchar * root_element)
+{
+  GstBuffer *buffer;
+  guchar *encoded_preamble;
+  
+  encoded_preamble = (guchar *)g_strconcat ((gchar *)preamble,
+      (gchar *)root_element, NULL);
+  
+  /* send the root element to the internal parser */
+  gst_cmml_dec_parse_xml (dec, root_element, strlen ((gchar *)root_element));
+  
+  /* push the root element */
+  dec->chain_return = gst_cmml_dec_new_buffer (dec,
+      encoded_preamble, strlen ((gchar *)encoded_preamble), &buffer);
+  if (dec->chain_return != GST_FLOW_OK)
+    goto done;
+  
+  dec->chain_return = gst_pad_push (dec->srcpad, buffer);
+  if (dec->chain_return != GST_FLOW_ERROR) {
+    GST_INFO_OBJECT (dec, "preamble parsed");
+    dec->sent_root = TRUE;
+  }
+
+done:
+  g_free (encoded_preamble);
+  return;
+}
+
+/* outputs the cmml head element and send TITLE and CMML_HEAD tags
+ *
+ * This callback is registered with dec->parser. It is called when the
+ * head element is parsed.
+ */
+static void
+gst_cmml_dec_parse_head (GstCmmlDec * dec, GstCmmlTagHead * head)
+{
+  GstTagList *tags;
+  GValue str_val = {0}, title_val = {0};
+  guchar *head_str;
+  GstBuffer *buffer;
+  
+  GST_DEBUG_OBJECT (dec, "found CMML head (title: %s base: %s)",
+      head->title, head->base);
+  
+  /* create the GST_TAG_TITLE tag */
+  g_value_init (&str_val, G_TYPE_STRING);
+  g_value_init (&title_val, gst_tag_get_type (GST_TAG_TITLE));
+  g_value_set_string (&str_val, (gchar *)head->title);
+  g_value_transform (&str_val, &title_val);
+
+  tags = gst_tag_list_new ();
+  gst_tag_list_add_values (tags, GST_TAG_MERGE_APPEND,
+      GST_TAG_TITLE, &title_val, NULL);
+  gst_tag_list_add (tags, GST_TAG_MERGE_APPEND,
+      GST_TAG_CMML_HEAD, head, NULL);
+  gst_element_found_tags_for_pad (GST_ELEMENT (dec), dec->srcpad, tags);
+  
+  g_value_unset (&str_val);
+  g_value_unset (&title_val);
+  
+  head_str = gst_cmml_parser_tag_head_to_string (dec->parser, head);
+  
+  dec->chain_return = gst_cmml_dec_new_buffer (dec,
+      head_str, strlen ((gchar *)head_str), &buffer);
+  if (dec->chain_return == GST_FLOW_OK)
+    dec->chain_return = gst_pad_push (dec->srcpad, buffer);
+
+  g_free (head_str);
+}  
+
+/* send a TAG_MESSAGE event for a clip */
+static void
+gst_cmml_dec_send_clip_tag (GstCmmlDec * dec, GstCmmlTagClip * clip)
+{
+  GstTagList *tags;  
+
+  GST_DEBUG_OBJECT (dec, "sending clip tag %s", clip->id);
+  
+  tags = gst_tag_list_new ();
+  gst_tag_list_add (tags, GST_TAG_MERGE_APPEND,
+      GST_TAG_CMML_CLIP, clip,
+      NULL);
+  gst_element_found_tags_for_pad (GST_ELEMENT (dec), dec->srcpad, tags);
+}
+
+/* push a string representation of a clip on the srcpad */
+static void
+gst_cmml_dec_push_clip (GstCmmlDec * dec, GstCmmlTagClip * clip)
+{  
+  GstBuffer * buffer;
+  guchar *clip_str;
+  
+  GST_DEBUG_OBJECT (dec, "pushing clip %s", clip->id);
+
+  clip_str = gst_cmml_parser_tag_clip_to_string (dec->parser, clip);
+  dec->chain_return = gst_cmml_dec_new_buffer (dec,
+      clip_str, strlen ((gchar *)clip_str), &buffer);
+  if (dec->chain_return == GST_FLOW_OK)
+    dec->chain_return = gst_pad_push (dec->srcpad, buffer);
+
+  g_free (clip_str);
+}
+
+/* handle a clip object
+ *
+ * This callback is registered with dec->parser. It is called whenever a
+ * clip is parsed.
+ */
+static void
+gst_cmml_dec_parse_clip (GstCmmlDec * dec, GstCmmlTagClip * clip)
+{ 
+  dec->chain_return = GST_FLOW_OK;
+  
+  if (clip->empty)
+    GST_INFO_OBJECT (dec, "parsing empty clip");
+  else
+    GST_INFO_OBJECT (dec, "parsing clip (id: %s)", clip->id);
+    
+  clip->start_time = dec->timestamp;
+
+  /* output the previous clip setting its end_time if the current clip
+   * is empty */
+  if (dec->last_clip) {
+    if (clip->empty)
+      dec->last_clip->end_time = clip->start_time;
+  
+    gst_cmml_dec_push_clip (dec, dec->last_clip);
+  }
+
+  if (dec->extract_mode) {
+    /* in extract mode we send the MESSAGE_TAG for a clip when we find the
+     * next clip so that we can always set its end time */
+    if (dec->last_clip) {
+      /* always set the end_time in extract_mode */
+      dec->last_clip->end_time = clip->start_time;
+      gst_cmml_dec_send_clip_tag (dec, dec->last_clip);
+      g_object_unref (dec->last_clip);
+    }
+    
+    if (clip->empty) {
+      dec->last_clip = NULL;
+    } else {
+      if (!gst_cmml_dec_clip_extracted (dec, clip->id)) {
+        dec->last_clip = g_object_ref (clip);
+        dec->extracted_clips = g_slist_append (dec->extracted_clips,
+            g_strdup ((gchar *)clip->id));
+      } else {
+        dec->last_clip = NULL;
+        GST_INFO_OBJECT (dec, "skipping already extracted clip (id %s)",
+            clip->id);
+      }
+    }
+  } else {
+    /* send the TAG_MESSAGE for the current clip and push the previous clip */
+    if (dec->last_clip)
+      g_object_unref (dec->last_clip);
+
+    if (clip->empty) {
+      dec->last_clip = NULL;
+    } else {
+      gst_cmml_dec_send_clip_tag (dec, clip);
+      dec->last_clip = g_object_ref (clip);
+    }
+  } 
+}
+
+/* returns TRUE if the clip with the given id has already been parsed
+ */
+static gboolean
+gst_cmml_dec_clip_extracted (GstCmmlDec * dec, const guchar * id)
+{
+  GSList *iter;
+  gboolean extracted = FALSE;
+
+  for (iter = dec->extracted_clips; iter != NULL && !extracted;
+          iter = iter->next)
+    if (!strcmp (iter->data, (gchar *)id))
+      extracted = TRUE;
+
+  return extracted;
+}
+
+gboolean
+gst_cmml_dec_plugin_init (GstPlugin * plugin)
+{
+  if (!gst_element_register (plugin, "cmmldec", GST_RANK_PRIMARY,
+          GST_TYPE_CMML_DEC))
+    return FALSE;
+
+  GST_DEBUG_CATEGORY_INIT (cmmldec, "cmmldec", 0,
+      "annodex CMML decoding element");
+
+  return TRUE;
+}

=== added file 'gst/annodex/gstcmmldec.h'
--- /dev/null
+++ gst/annodex/gstcmmldec.h
@@ -0,0 +1,94 @@
+/*
+ * gstcmmldec.h - GStreamer annodex CMML decoder
+ * Copyright (C) 2005 Alessandro Decina
+ * 
+ * Authors:
+ *   Alessandro Decina <alessandro@nnva.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_CMML_DEC_H__
+#define __GST_CMML_DEC_H__
+
+#include <gst/gst.h>
+#include <gst/gstformat.h>
+#include <gst/controller/gstcontroller.h>
+
+#include "gstcmmlparser.h"
+
+/* GstCmmlDec */
+#define GST_TYPE_CMML_DEC (gst_cmml_dec_get_type())
+#define GST_CMML_DEC(obj) \
+    (G_TYPE_CHECK_INSTANCE_CAST((obj), GST_TYPE_CMML_DEC, GstCmmlDec))
+#define GST_CMML_DEC_CLASS(klass) \
+    (G_TYPE_CHECK_CLASS_CAST((klass), GST_TYPE_CMML_DEC, GstCmmlDec))
+#define GST_IS_CMML_DEC(obj) \
+    (G_TYPE_CHECK_INSTANCE_TYPE((obj), GST_TYPE_CMML_DEC))
+#define GST_IS_CMML_DEC_CLASS(obj) \
+    (G_TYPE_CHECK_CLASS_TYPE((klass), GST_TYPE_CMML_DEC))
+#define GST_CMML_DEC_GET_CLASS(obj) \
+    (G_TYPE_INSTANCE_GET_CLASS((obj), GST_TYPE_CMML_DEC, GstCmmlDecClass))
+
+typedef struct _GstCmmlDec GstCmmlDec;
+typedef struct _GstCmmlDecClass GstCmmlDecClass;
+typedef enum _GstCmmlPacketType GstCmmlPacketType;
+
+enum _GstCmmlPacketType {
+  GST_CMML_PACKET_UNKNOWN,
+  GST_CMML_PACKET_IDENT_HEADER,
+  GST_CMML_PACKET_FIRST_HEADER,
+  GST_CMML_PACKET_SECOND_HEADER,
+  GST_CMML_PACKET_CLIP
+};
+
+struct _GstCmmlDec {
+    GstElement element;
+    
+    /* element part */
+    GstPad *sinkpad;            
+    GstPad *srcpad;
+    
+    /* bitstream part */
+    gint16 major;                   /* bitstream version major*/
+    gint16 minor;                   /* bitstream version minor */
+    gint64 granulerate_n;           /* bitrstream granulerate numerator */
+    gint64 granulerate_d;           /* bitstream granulerate denominator */
+    gint8 granuleshift;             /* bitstreamgranuleshift */
+    gint64 granulepos;              /* bitstream granule position */
+    GstClockTime timestamp;         /* timestamp of the last buffer */
+    
+    /* decoder part */
+    GstCmmlParser *parser;              /* cmml parser */
+    gboolean sent_root;
+    GstFlowReturn chain_return;         /* _chain return value */
+    GstCmmlTagClip *last_clip;          /* last clip parsed */
+    gboolean extract_mode;          /* when TRUE, the GST_TAG_MESSAGE for a
+                                     * clip is sent when the next clip (or EOS)
+                                     * is found, so that the clip end-time is
+                                     * known. This is useful for pre-extracting
+                                     * the clips.
+                                     */
+    GSList *extracted_clips;
+};
+
+struct _GstCmmlDecClass {
+    GstElementClass parent_class;
+};
+
+gboolean gst_cmml_dec_plugin_init(GstPlugin *plugin);
+
+#endif /* __GST_CMML_DEC_H__ */    

=== added file 'gst/annodex/gstcmmlenc.c'
--- /dev/null
+++ gst/annodex/gstcmmlenc.c
@@ -0,0 +1,475 @@
+/*
+ * gstcmmlenc.c - GStreamer CMML encoder
+ * Copyright (C) 2005 Alessandro Decina
+ * 
+ * Authors:
+ *   Alessandro Decina <alessandro@nnva.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.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <string.h>
+#include "gstcmmlenc.h"
+#include "gstannodex.h"
+
+GST_DEBUG_CATEGORY (cmmlenc);
+#define GST_CAT_DEFAULT cmmlenc
+
+#define CMML_IDENT_HEADER_SIZE 29
+
+enum {
+  ARG_0,
+};
+
+enum {
+  LAST_SIGNAL
+};
+
+static GstElementDetails gst_cmml_enc_details = {
+  "CmmlEnc", "Coenc/Encoder",
+  "encode CMML streams",
+  "Alessandro Decina <alessandro@nnva.org>",
+};
+
+static GstStaticPadTemplate gst_cmml_enc_src_factory =
+GST_STATIC_PAD_TEMPLATE ("src",
+    GST_PAD_SRC,
+    GST_PAD_ALWAYS,
+    GST_STATIC_CAPS ("text/x-cmml")
+    );
+
+static GstStaticPadTemplate gst_cmml_enc_sink_factory =
+GST_STATIC_PAD_TEMPLATE ("sink",
+    GST_PAD_SINK,
+    GST_PAD_ALWAYS,
+    GST_STATIC_CAPS ("text/xml")
+    );
+
+GST_BOILERPLATE (GstCmmlEnc, gst_cmml_enc, GstElement, GST_TYPE_ELEMENT);
+static gboolean gst_cmml_enc_sink_event (GstPad * pad, GstEvent * event);
+static GstStateChangeReturn gst_cmml_enc_change_state (GstElement * element, GstStateChange transition);
+static GstFlowReturn gst_cmml_enc_chain (GstPad * pad, GstBuffer * buffer);
+static void gst_cmml_enc_parse_preamble (GstCmmlEnc * enc,
+    guchar * preamble, guchar * processing_instruction);
+static void gst_cmml_enc_parse_end_tag (GstCmmlEnc * enc);
+static void gst_cmml_enc_parse_tag_head (GstCmmlEnc * enc,
+    GstCmmlTagHead * head);
+static void gst_cmml_enc_parse_tag_clip (GstCmmlEnc * enc,
+    GstCmmlTagClip * tag);
+static GstFlowReturn gst_cmml_enc_new_buffer (GstCmmlEnc * enc,
+    guchar * data, gint size, GstBuffer ** buffer);
+static GstFlowReturn gst_cmml_enc_push (GstCmmlEnc * enc, GstBuffer * buffer,
+    GstClockTime timestamp);
+
+static void
+gst_cmml_enc_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 (&gst_cmml_enc_sink_factory));
+  gst_element_class_add_pad_template (element_class,
+      gst_static_pad_template_get (&gst_cmml_enc_src_factory));
+  gst_element_class_set_details (element_class, &gst_cmml_enc_details);
+}
+
+static void
+gst_cmml_enc_class_init (GstCmmlEncClass * enc_class)
+{
+  GObjectClass *klass = G_OBJECT_CLASS (enc_class);
+
+  GST_ELEMENT_CLASS (klass)->change_state = gst_cmml_enc_change_state;
+}
+
+static void
+gst_cmml_enc_init (GstCmmlEnc * enc, GstCmmlEncClass * klass)
+{
+  enc->sinkpad =
+    gst_pad_new_from_static_template (&gst_cmml_enc_sink_factory, "sink");
+  gst_pad_set_chain_function (enc->sinkpad, gst_cmml_enc_chain);
+  gst_pad_set_event_function (enc->sinkpad, gst_cmml_enc_sink_event);
+  gst_element_add_pad (GST_ELEMENT (enc), enc->sinkpad);
+
+  enc->srcpad =
+    gst_pad_new_from_static_template (&gst_cmml_enc_src_factory, "src");
+  gst_element_add_pad (GST_ELEMENT (enc), enc->srcpad);
+
+  enc->major = 3;
+  enc->minor = 0;
+  enc->granulerate_n = 1000;
+  enc->granulerate_d = 1;
+  enc->granuleshift = 32;
+}
+
+static GstStateChangeReturn gst_cmml_enc_change_state (GstElement * element,
+    GstStateChange transition)
+{
+  GstCmmlEnc *enc = GST_CMML_ENC (element);
+  GstStateChangeReturn res;
+
+  switch (transition) {
+    case GST_STATE_CHANGE_READY_TO_PAUSED:
+      enc->parser = gst_cmml_parser_new (GST_CMML_PARSER_ENCODE);
+      enc->parser->user_data = enc;
+      enc->parser->preamble_callback =
+        (GstCmmlParserPreambleCallback) gst_cmml_enc_parse_preamble;
+      enc->parser->head_callback =
+        (GstCmmlParserHeadCallback) gst_cmml_enc_parse_tag_head;
+      enc->parser->clip_callback =
+        (GstCmmlParserClipCallback) gst_cmml_enc_parse_tag_clip;
+      enc->parser->cmml_end_callback =
+        (GstCmmlParserCmmlEndCallback) gst_cmml_enc_parse_end_tag;
+      enc->sent_headers = FALSE;
+      enc->prev_clip_time = 0;
+      enc->sent_eos = FALSE;
+      enc->flow_result = GST_FLOW_OK;
+      break;
+    default:
+      break;
+  }
+
+  res = parent_class->change_state (element, transition);
+
+  switch (transition) {
+    case GST_STATE_CHANGE_PAUSED_TO_READY:
+      g_free (enc->preamble);
+      gst_cmml_parser_free (enc->parser);
+      break;
+    default:
+      break;
+  }
+
+  return res;
+}
+
+static gboolean
+gst_cmml_enc_sink_event (GstPad * pad, GstEvent * event)
+{
+  GstCmmlEnc *enc = GST_CMML_ENC (GST_PAD_PARENT (pad));
+
+  switch (GST_EVENT_TYPE (event)) {
+    case GST_EVENT_EOS:
+    {
+      if (!enc->sent_eos)
+        gst_cmml_enc_parse_end_tag (enc);
+
+      break;
+    }
+    default:
+      break;
+  }
+
+  return gst_pad_event_default (pad, event);
+}
+
+static GstFlowReturn
+gst_cmml_enc_new_buffer (GstCmmlEnc * enc,
+    guchar * data, gint size, GstBuffer ** buffer)
+{
+  GstFlowReturn res;
+  
+  res = gst_pad_alloc_buffer (enc->srcpad, GST_BUFFER_OFFSET_NONE, size,
+      NULL, buffer);
+  if (res == GST_FLOW_OK) {
+    if (data)
+      memcpy (GST_BUFFER_DATA (*buffer), data, size);
+  } else {
+    GST_ELEMENT_ERROR (enc, STREAM, ENCODE,
+        ("could not allocate a buffer"),
+        ("alloc function returned error %s", gst_flow_get_name (res)));
+  }
+
+  return res;
+}
+
+static GstCaps *
+gst_cmml_enc_set_header_on_caps (GstCaps * caps,
+    GstBuffer * ident, GstBuffer * preamble, GstBuffer * head)
+{
+  GValue array = {0};
+  GValue value = {0};
+  GstStructure *structure;
+  
+  caps = gst_caps_make_writable (caps);
+  structure = gst_caps_get_structure (caps, 0);
+
+  GST_BUFFER_FLAG_SET (ident, GST_BUFFER_FLAG_IN_CAPS);
+  
+  g_value_init (&array, GST_TYPE_ARRAY);
+  g_value_init (&value, GST_TYPE_BUFFER);
+
+  gst_value_set_buffer (&value, ident);
+  gst_value_array_append_value (&array, &value);
+  gst_value_set_buffer (&value, preamble);
+  gst_value_array_append_value (&array, &value);
+  gst_value_set_buffer (&value, head);
+  gst_value_array_append_value (&array, &value);
+
+  GST_BUFFER_FLAG_SET (ident, GST_BUFFER_FLAG_IN_CAPS);
+  GST_BUFFER_FLAG_SET (preamble, GST_BUFFER_FLAG_IN_CAPS);
+  GST_BUFFER_FLAG_SET (head, GST_BUFFER_FLAG_IN_CAPS);
+  
+  gst_structure_set_value (structure, "streamheader", &array);
+  
+  g_value_unset (&value);
+  g_value_unset (&array);
+ 
+  return caps;
+}
+
+/* create a CMML ident header buffer
+ */
+static GstFlowReturn
+gst_cmml_enc_new_ident_header (GstCmmlEnc * enc, GstBuffer ** buffer)
+{
+  guint8 ident_header[CMML_IDENT_HEADER_SIZE];
+  guint8 *wptr = ident_header;
+  
+  memcpy (wptr, "CMML\0\0\0\0", 8);
+  wptr += 8;
+  GST_WRITE_UINT16_LE (wptr, enc->major);
+  wptr += 2;
+  GST_WRITE_UINT16_LE (wptr, enc->minor);
+  wptr += 2;
+  GST_WRITE_UINT64_LE (wptr, enc->granulerate_n);
+  wptr += 8;
+  GST_WRITE_UINT64_LE (wptr, enc->granulerate_d);
+  wptr += 8;
+  *wptr = enc->granuleshift;
+
+  return gst_cmml_enc_new_buffer (enc,
+      (guchar *)&ident_header, CMML_IDENT_HEADER_SIZE, buffer); 
+
+}
+
+/* parse the CMML preamble */
+static void
+gst_cmml_enc_parse_preamble (GstCmmlEnc * enc,
+    guchar * preamble, guchar * processing_instruction)
+{ 
+  GST_INFO_OBJECT (enc, "parsing preamble");
+  
+  /* save the preamble: it will be pushed when the head tag is found */
+  enc->preamble = (guchar *)g_strconcat ((gchar *)preamble,
+      (gchar *)processing_instruction, NULL);
+}
+
+/* parse the CMML end tag */
+static void
+gst_cmml_enc_parse_end_tag (GstCmmlEnc * enc)
+{
+  GstBuffer *buffer;
+ 
+  GST_INFO_OBJECT (enc, "parsing end tag");
+  
+  /* push an empty buffer to signal EOS */
+  enc->flow_result = gst_cmml_enc_new_buffer (enc, NULL, 0, &buffer);
+  if (enc->flow_result == GST_FLOW_OK) {
+    enc->flow_result = gst_cmml_enc_push (enc, buffer, GST_CLOCK_TIME_NONE);
+    enc->sent_eos = TRUE;
+  }
+}
+
+/* encode the CMML head tag and push the CMML headers
+ */
+static void
+gst_cmml_enc_parse_tag_head (GstCmmlEnc * enc, GstCmmlTagHead * head)
+{
+  GSList *headers = NULL;
+  GSList *walk;
+  guchar *head_string;
+  GstCaps *caps;
+  GstBuffer *ident_buf, *preamble_buf, *head_buf;
+  GstBuffer *buffer;
+  
+  if (enc->preamble == NULL)
+    goto flow_unexpected;
+
+  GST_INFO_OBJECT (enc, "parsing head tag");
+  
+  enc->flow_result = gst_cmml_enc_new_ident_header (enc, &ident_buf);
+  if (enc->flow_result != GST_FLOW_OK)
+    goto alloc_error;
+  headers = g_slist_append (headers, ident_buf);
+  
+  enc->flow_result = gst_cmml_enc_new_buffer (enc,
+      enc->preamble, strlen ((gchar *)enc->preamble), &preamble_buf);
+  if (enc->flow_result != GST_FLOW_OK)
+    goto alloc_error;
+  headers = g_slist_append (headers, preamble_buf);
+  
+  head_string = gst_cmml_parser_tag_head_to_string (enc->parser, head);
+  enc->flow_result = gst_cmml_enc_new_buffer (enc,
+      head_string, strlen ((gchar *)head_string), &head_buf);
+  g_free (head_string);
+  if (enc->flow_result != GST_FLOW_OK)
+    goto alloc_error;
+  headers = g_slist_append (headers, head_buf);
+ 
+  caps = gst_pad_get_caps (enc->srcpad);
+  caps = gst_cmml_enc_set_header_on_caps (caps,
+      ident_buf, preamble_buf, head_buf);
+  
+  for (walk = headers; walk; walk = walk->next) {
+    buffer = GST_BUFFER (walk->data);
+    gst_buffer_set_caps (buffer, caps);
+    
+    enc->flow_result = gst_cmml_enc_push (enc, buffer, GST_CLOCK_TIME_NONE);
+    if (enc->flow_result != GST_FLOW_OK)
+      goto push_error;
+ 
+  }   
+
+  gst_caps_unref (caps);
+  g_slist_free (headers);
+  
+  enc->sent_headers = TRUE;
+  return;
+
+flow_unexpected:
+  GST_ELEMENT_ERROR (enc, STREAM, ENCODE,
+      ("got head tag before the cmml preamble"),
+      ("got head tag before the cmml preamble"));
+  enc->flow_result = GST_FLOW_UNEXPECTED;
+  return;
+push_error:
+  gst_caps_unref (caps);
+  /* fallthrough */
+alloc_error:
+  for (walk = headers; walk; walk = walk->next)
+    gst_buffer_unref (GST_BUFFER (walk->data));
+  g_slist_free (headers);
+  return;
+}
+
+/* encode a CMML clip tag
+ * remove the start and end attributes (GstCmmlParser does this itself) and
+ * push the tag with the timestamp of its start attribute. If the tag has the
+ * end attribute, create a new empty clip and encode it.
+ */
+static void
+gst_cmml_enc_parse_tag_clip (GstCmmlEnc * enc, GstCmmlTagClip * clip)
+{
+  GstBuffer *buffer;
+  gchar *clip_string;
+  
+  /* convert the tag object to string (removing start and end attributes) */
+  clip_string = (gchar *)gst_cmml_parser_tag_clip_to_string (enc->parser, clip);
+  
+  enc->flow_result = gst_cmml_enc_new_buffer (enc,
+      (guchar *)clip_string, strlen (clip_string), &buffer);
+  g_free (clip_string);
+  
+  if (enc->flow_result == GST_FLOW_OK) {
+    GST_INFO_OBJECT (enc, "encoding clip"
+        "(start-time: %"GST_TIME_FORMAT" end-time: %"GST_TIME_FORMAT,
+        GST_TIME_ARGS (clip->start_time), GST_TIME_ARGS (clip->end_time));
+    
+    enc->flow_result = gst_cmml_enc_push (enc, buffer, clip->start_time);
+    if (enc->flow_result == GST_FLOW_OK) {
+      if (!clip->empty)
+        enc->prev_clip_time = clip->start_time;
+        
+      if (clip->end_time != GST_CLOCK_TIME_NONE) {
+        /* create a new empty clip for the same cmml "track" starting at
+         * "end_time"
+         */
+        GObject *end_clip = g_object_new (GST_TYPE_CMML_TAG_CLIP,
+            "start-time", clip->end_time, "track", clip->track, NULL);
+
+        /* encode the empty end clip */
+        gst_cmml_enc_parse_tag_clip (enc, GST_CMML_TAG_CLIP (end_clip));
+        g_object_unref (end_clip);
+      }
+    }
+  } 
+}
+
+/* push a buffer setting its timestamp and granulepos
+ */
+static GstFlowReturn
+gst_cmml_enc_push (GstCmmlEnc * enc,
+    GstBuffer * buffer, GstClockTime timestamp)
+{
+  GstFlowReturn res;
+
+  GST_BUFFER_DURATION (buffer) = G_MAXINT;
+  GST_BUFFER_TIMESTAMP (buffer) = timestamp;
+  if (timestamp == GST_CLOCK_TIME_NONE) {
+    /* set granulepos 0 for packet that haven't a definite timestamp */
+    GST_BUFFER_OFFSET_END (buffer) = 0;
+  } else {
+    /* map the timestamp to the granulepos */
+    gint64 keyindex, keyoffset, granulepos;
+    gint64 granulerate;
+
+    granulerate = gst_util_uint64_scale (GST_SECOND,
+        enc->granulerate_d, enc->granulerate_n);
+    keyindex = gst_util_uint64_scale (enc->prev_clip_time, 1, granulerate);
+    keyindex = keyindex << enc->granuleshift;
+    keyoffset = gst_util_uint64_scale (timestamp - enc->prev_clip_time,
+        1, granulerate);
+    granulepos = keyindex | keyoffset;
+    GST_BUFFER_OFFSET_END (buffer) = granulepos;
+  }
+    
+  res = gst_pad_push (enc->srcpad, buffer);
+  if (res != GST_FLOW_OK)
+    GST_ELEMENT_ERROR (enc, STREAM, ENCODE,
+        ("could not push the buffer"),
+        ("could not push the buffer: %s", gst_flow_get_name (res)));
+  
+  return res;
+}
+
+static GstFlowReturn
+gst_cmml_enc_chain (GstPad * pad, GstBuffer * buffer)
+{
+  GstCmmlEnc *enc = GST_CMML_ENC (GST_PAD_PARENT (pad));
+  
+  /* the CMML handlers registered with enc->parser will set this value when
+   * encoding/pushing the buffers downstream
+   */
+  enc->flow_result = GST_FLOW_OK;
+
+  if (!gst_cmml_parser_parse_chunk (enc->parser,
+      (gchar *)GST_BUFFER_DATA (buffer), GST_BUFFER_SIZE (buffer))) {
+    GST_ELEMENT_ERROR (enc, STREAM, ENCODE,
+        ("xml error"),
+        ("xml error"));
+    enc->flow_result = GST_FLOW_ERROR;
+  }
+
+  gst_buffer_unref (buffer);
+  return enc->flow_result;
+}
+
+gboolean
+gst_cmml_enc_plugin_init (GstPlugin * plugin)
+{
+  if (!gst_element_register (plugin, "cmmlenc", GST_RANK_NONE,
+        GST_TYPE_CMML_ENC))
+    return FALSE;
+
+  GST_DEBUG_CATEGORY_INIT (cmmlenc, "cmmlenc", 0,
+      "annodex cmml decoding element");
+
+  return TRUE;
+}

=== added file 'gst/annodex/gstcmmlenc.h'
--- /dev/null
+++ gst/annodex/gstcmmlenc.h
@@ -0,0 +1,73 @@
+/*
+ * gstcmmlenc.h - (VL_UNRESOLVED)
+ * Copyright (C) 2005 (VL_UNRESOLVED)
+ * 
+ * Authors:
+ *   Alessandro Encina <alessandro@nnva.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_CMML_ENC_H__
+#define __GST_CMML_ENC_H__
+
+#define GST_TYPE_CMML_ENC (gst_cmml_enc_get_type())
+#define GST_CMML_ENC(obj) \
+      (G_TYPE_CHECK_INSTANCE_CAST((obj), GST_TYPE_CMML_ENC, GstCmmlEnc))
+#define GST_CMML_ENC_CLASS(klass) \
+      (G_TYPE_CHECK_CLASS_CAST((klass), GST_TYPE_CMML_ENC, GstCmmlEnc))
+#define GST_IS_CMML_ENC(obj) \
+      (G_TYPE_CHECK_INSTANCE_TYPE((obj), GST_TYPE_CMML_ENC))
+#define GST_IS_CMML_ENC_CLASS(obj) \
+      (G_TYPE_CHECK_CLASS_TYPE((klass), GST_TYPE_CMML_ENC))
+#define GST_CMML_ENC_GET_CLASS(obj) \
+      (G_TYPE_INSTANCE_GET_CLASS((obj), GST_TYPE_CMML_ENC, GstCmmlEncClass))
+
+#include <glib.h>
+#include <gst/gst.h>
+
+#include "gstcmmlparser.h"
+
+typedef struct _GstCmmlEnc GstCmmlEnc;
+typedef struct _GstCmmlEncClass GstCmmlEncClass;
+
+struct _GstCmmlEnc {
+  GstElement element;
+
+  GstPad *sinkpad;
+  GstPad *srcpad;
+  
+  gint16 major;
+  gint16 minor; 
+  gint64 granulerate_n;
+  gint64 granulerate_d;
+  gint8 granuleshift;
+
+  GstCmmlParser *parser;
+  GstFlowReturn flow_result;
+  guchar *preamble;
+  gboolean sent_headers;
+  gboolean sent_eos;
+  GstClockTime prev_clip_time;
+};
+
+struct _GstCmmlEncClass {
+  GstElementClass parent_class;
+};
+
+gboolean gst_cmml_enc_plugin_init (GstPlugin * plugin);
+
+#endif /* __GST_CMML_ENC_H__ */

=== added file 'gst/annodex/gstcmmlparser.c'
--- /dev/null
+++ gst/annodex/gstcmmlparser.c
@@ -0,0 +1,618 @@
+/*
+ * gstcmmlparser.c - GStreamer CMML parser
+ * Copyright (C) 2005 GStreamer CMML parser
+ * 
+ * Authors:
+ *   Alessandro Decina <alessandro@nnva.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.
+ */
+
+#include <string.h>
+#include <gst/gst.h>
+
+#include "gstcmmlparser.h"
+#include "gstannodex.h"
+#include "gstcmmlclock.h"
+
+static xmlNodePtr gst_cmml_parser_new_node (GstCmmlParser * parser,
+    const gchar * name, ...);
+static void
+gst_cmml_parser_parse_start_element_ns (xmlParserCtxt * ctxt,
+    const xmlChar * name, const xmlChar * prefix, const xmlChar *URI,
+    int nb_preferences, const xmlChar **namespaces,
+    int nb_attributes, int nb_defaulted, const xmlChar **attributes);
+static void gst_cmml_parser_parse_end_element_ns (xmlParserCtxt * ctxt,
+    const xmlChar * name, const xmlChar * prefix, const xmlChar * URI);
+static void gst_cmml_parser_parse_processing_instruction (xmlParserCtxtPtr ctxt,
+    const xmlChar * target, const xmlChar * data);
+static void gst_cmml_parser_meta_to_string (GstCmmlParser * parser,
+    xmlNodePtr parent, GValueArray * meta);
+
+/* create a new CMML parser
+ */
+GstCmmlParser *
+gst_cmml_parser_new (GstCmmlParserMode mode)
+{
+  GstCmmlParser * parser = g_malloc (sizeof (GstCmmlParser));
+ 
+  parser->mode = mode;
+  parser->context = xmlCreatePushParserCtxt (NULL, NULL,
+      NULL, 0, "cmml-bitstream");
+  xmlCtxtUseOptions (parser->context, XML_PARSE_NONET);
+  parser->context->_private = parser;
+  parser->context->sax->startElementNs =
+    (startElementNsSAX2Func)gst_cmml_parser_parse_start_element_ns;
+  parser->context->sax->endElementNs =
+    (endElementNsSAX2Func)gst_cmml_parser_parse_end_element_ns;
+  parser->context->sax->processingInstruction =
+    (processingInstructionSAXFunc)gst_cmml_parser_parse_processing_instruction;
+  parser->preamble_callback = NULL;
+  parser->cmml_end_callback = NULL;
+  parser->stream_callback = NULL;
+  parser->head_callback = NULL;
+  parser->clip_callback = NULL;
+  parser->user_data = NULL;
+  
+  return parser;
+}
+
+/* free a CMML parser instance
+ */
+void
+gst_cmml_parser_free (GstCmmlParser * parser)
+{
+  if (parser) {
+    xmlFreeDoc (parser->context->myDoc);
+    xmlFreeParserCtxt (parser->context);
+    g_free (parser);
+  }
+}
+
+/* parse an xml chunk
+ *
+ * returns false if the xml is invalid
+ */
+gboolean
+gst_cmml_parser_parse_chunk (GstCmmlParser * parser,
+    const gchar * data, guint size)
+{
+  gint xmlres;
+  
+  xmlres = xmlParseChunk (parser->context, data, size, 0);
+  if (xmlres != XML_ERR_OK) {
+    xmlErrorPtr error = xmlCtxtGetLastError (parser->context);
+
+    g_warning ("error parsing cmml: %s", error->message);
+    return FALSE;
+  }
+  
+  return TRUE;
+}
+
+/* convert an xmlNodePtr to a string
+ */
+guchar *
+gst_cmml_parser_node_to_string (GstCmmlParser * parser, xmlNodePtr node)
+{
+  xmlBufferPtr xml_buffer;
+  xmlDocPtr doc;
+  guchar *str;
+  
+  if (parser)
+    doc = parser->context->myDoc;
+  else
+    doc = NULL;
+  
+  xml_buffer = xmlBufferCreate ();
+  xmlNodeDump (xml_buffer, doc, node, 0, 0); 
+  str = xmlStrndup (xml_buffer->content, xml_buffer->use);
+  xmlBufferFree (xml_buffer);
+
+  return str;
+}
+
+guchar *
+gst_cmml_parser_tag_stream_to_string (GstCmmlParser * parser,
+    GstCmmlTagStream * stream)
+{
+  xmlNodePtr node;
+  xmlNodePtr import;
+  guchar *ret; 
+  
+  node = gst_cmml_parser_new_node (parser, "stream", NULL);
+  if (stream->timebase)
+    xmlSetProp (node, (xmlChar *)"timebase", stream->timebase);
+
+  if (stream->utc)
+    xmlSetProp (node, (xmlChar *)"utc", stream->utc);
+  
+  if (stream->imports) {
+    gint i;
+    GValue *val;
+    for (i = 0; i < stream->imports->n_values; ++i) {
+      val = g_value_array_get_nth (stream->imports, i);
+      import = gst_cmml_parser_new_node (parser, "import",
+          "src", g_value_get_string (val),
+          NULL);
+      xmlAddChild (node, import);
+    }
+  }
+  
+  ret = gst_cmml_parser_node_to_string (parser, node);
+
+  xmlUnlinkNode (node);
+  xmlFreeNode (node);
+
+  return ret;
+}
+
+/* convert a GstCmmlTagHead to its string representation
+ */
+guchar *
+gst_cmml_parser_tag_head_to_string (GstCmmlParser * parser, GstCmmlTagHead * head)
+{
+  xmlNodePtr node;
+  xmlNodePtr tmp;
+  guchar *ret; 
+  
+  node = gst_cmml_parser_new_node (parser, "head", NULL);
+  if (head->title) {
+    tmp = gst_cmml_parser_new_node (parser, "title", NULL);
+    xmlNodeSetContent (tmp, head->title);
+    xmlAddChild (node, tmp);
+  }
+  
+  if (head->base) {
+    tmp = gst_cmml_parser_new_node (parser, "base",
+        "uri", head->base,
+        NULL);
+    xmlAddChild (node, tmp);
+  }
+    
+  if (head->meta)
+    gst_cmml_parser_meta_to_string (parser, node, head->meta);
+
+  ret = gst_cmml_parser_node_to_string (parser, node);
+
+  xmlUnlinkNode (node);
+  xmlFreeNode (node);
+
+  return ret;
+}
+
+/* convert a GstCmmlTagClip to its string representation
+ */
+guchar *
+gst_cmml_parser_tag_clip_to_string (GstCmmlParser * parser, GstCmmlTagClip * clip)
+{
+  xmlNodePtr node;
+  xmlNodePtr tmp;
+  guchar *ret;
+  
+  node = gst_cmml_parser_new_node (parser, "clip",
+      "id", clip->id,
+      "track", clip->track,
+      NULL);
+  /* add the a element */
+  if (clip->anchor_href) {
+    tmp = gst_cmml_parser_new_node (parser, "a",
+        "href", clip->anchor_href,
+        NULL);
+    if (clip->anchor_text)
+      xmlNodeSetContent (tmp, clip->anchor_text);
+    
+    xmlAddChild (node, tmp);
+  }
+  /* add the img element */
+  if (clip->img_src) {
+    tmp = gst_cmml_parser_new_node (parser, "img",
+        "src", clip->img_src,
+        "alt", clip->img_alt,
+        NULL);
+
+    xmlAddChild (node, tmp);
+  }
+  /* add the desc element */
+  if (clip->desc_text) {
+    tmp = gst_cmml_parser_new_node (parser, "desc",
+        NULL);
+    xmlNodeSetContent (tmp, clip->desc_text);
+    
+    xmlAddChild (node, tmp);
+  } 
+  /* add the meta elements */
+  if (clip->meta)
+    gst_cmml_parser_meta_to_string (parser, node, clip->meta);
+  
+  if (parser->mode == GST_CMML_PARSER_DECODE) {
+    gchar *time_str;
+    
+    time_str = gst_cmml_clock_time_to_npt (clip->start_time);
+    xmlSetProp (node, (xmlChar *)"start", (xmlChar *)time_str);
+    g_free (time_str);
+      
+    if (clip->end_time != GST_CLOCK_TIME_NONE) {
+      time_str = gst_cmml_clock_time_to_npt (clip->end_time);
+      xmlSetProp (node, (xmlChar *)"end", (xmlChar *)time_str);
+      g_free (time_str);
+    }
+  }
+
+  ret = gst_cmml_parser_node_to_string (parser, node);
+  
+  xmlUnlinkNode (node);
+  xmlFreeNode (node);
+
+  return ret;
+}
+
+guchar *
+gst_cmml_parser_tag_object_to_string (GstCmmlParser * parser, GObject * tag)
+{
+  guchar *tag_string = NULL;
+  GType tag_type = G_OBJECT_TYPE (tag);
+
+  if (tag_type == GST_TYPE_CMML_TAG_STREAM)
+    tag_string = gst_cmml_parser_tag_stream_to_string (parser,
+          GST_CMML_TAG_STREAM (tag));
+  else if (tag_type == GST_TYPE_CMML_TAG_HEAD)
+    tag_string = gst_cmml_parser_tag_head_to_string (parser,
+          GST_CMML_TAG_HEAD (tag));
+  else if (tag_type == GST_TYPE_CMML_TAG_CLIP)    
+    tag_string = gst_cmml_parser_tag_clip_to_string (parser,
+          GST_CMML_TAG_CLIP (tag));
+  else
+    g_warning ("could not convert object to cmml");
+
+  return tag_string;
+}
+
+/*** private section ***/
+
+/* create a new node
+ *
+ * helper to create a node and set its attributes
+ */
+static xmlNodePtr
+gst_cmml_parser_new_node (GstCmmlParser * parser, const gchar * name, ...)
+{
+  va_list args;
+  xmlNodePtr node;
+  xmlChar *prop_name, *prop_value;
+
+  node = xmlNewNode (NULL, (xmlChar *)name);
+  
+  va_start (args, name);
+  
+  prop_name = va_arg (args, xmlChar *);
+  while (prop_name != NULL) {
+    prop_value = va_arg (args, xmlChar *);
+    if (prop_value != NULL)
+      xmlSetProp (node, prop_name, prop_value);
+
+    prop_name = va_arg (args, xmlChar *);
+  }
+  va_end (args);
+
+  return node;
+}
+
+/* get the last node of the stream
+ *
+ * returns the last node at depth 1 (if any) or the root node
+ */
+static xmlNodePtr
+gst_cmml_parser_get_last_element (GstCmmlParser * parser)
+{
+  xmlNodePtr  node;
+  
+  node = xmlDocGetRootElement (parser->context->myDoc);
+  if (!node) {
+    g_warning ("no last cmml element");
+    return NULL;
+  }
+  
+  if (node->children)
+    node = xmlGetLastChild (node);
+
+  return node;
+}
+
+static void
+gst_cmml_parser_parse_preamble (GstCmmlParser * parser,
+    const guchar *attributes)
+{
+  gchar *preamble;
+  gchar *element;
+  const gchar *version;
+  const gchar *encoding;
+  const gchar *standalone;
+  xmlDocPtr doc;
+
+  doc = parser->context->myDoc;
+  
+  version = (gchar *)doc->version;
+  if (version == NULL)
+    version = "1.0";
+
+  encoding = (gchar *)doc->encoding;
+  if (encoding == NULL)
+    encoding = "UTF-8";
+
+  standalone = doc->standalone ? "yes" : "no";
+
+  preamble = g_strdup_printf ("<?xml version=\"%s\" encoding=\"%s\" standalone=\"%s\"?>\n<!DOCTYPE cmml SYSTEM \"cmml.dtd\">\n", version, encoding, standalone);
+ 
+  if (attributes == NULL)
+    attributes = (guchar *)"";
+  
+  if (parser->mode == GST_CMML_PARSER_ENCODE)
+    element = g_strdup_printf ("<?cmml %s?>", attributes);
+  else
+    element = g_strdup_printf ("<cmml %s>", attributes);
+  
+  parser->preamble_callback (parser->user_data,
+      (guchar *)preamble, (guchar *)element);
+
+  g_free (preamble);
+  g_free (element);
+}
+
+/* parse the cmml stream tag */
+static void
+gst_cmml_parser_parse_stream (GstCmmlParser * parser, xmlNodePtr stream)
+{
+  GstCmmlTagStream *stream_tag;
+  GValue str_val = {0};
+  xmlNodePtr walk;
+  guchar *timebase;
+  
+  g_value_init (&str_val, G_TYPE_STRING);
+ 
+  /* read the timebase and utc attributes */
+  timebase = xmlGetProp (stream, (xmlChar *)"timebase");
+  if (timebase == NULL)
+    timebase = (guchar *)g_strdup ("0");
+  
+  stream_tag = g_object_new (GST_TYPE_CMML_TAG_STREAM, 
+      "timebase", timebase,
+      NULL);
+  g_free (timebase);  
+  
+  stream_tag->utc = xmlGetProp (stream, (xmlChar *)"utc");
+
+  /* walk the children nodes */
+  for (walk = stream->children; walk; walk = walk->next) {
+    /* for every import tag add its src attribute to stream_tag->imports */
+    if (!xmlStrcmp (walk->name, (xmlChar *)"import")) {
+      g_value_take_string (&str_val,
+          (gchar *)xmlGetProp (walk, (xmlChar *)"src"));
+      
+      if (stream_tag->imports == NULL)
+        stream_tag->imports = g_value_array_new (0);
+
+      g_value_array_append (stream_tag->imports, &str_val);
+    }
+  }
+  g_value_unset (&str_val);
+
+  parser->stream_callback (parser->user_data, stream_tag);
+  g_object_unref (stream_tag);
+}
+
+/* parse the cmml head tag */
+static void
+gst_cmml_parser_parse_head (GstCmmlParser * parser, xmlNodePtr head)
+{
+  GstCmmlTagHead *head_tag;
+  xmlNodePtr walk;
+  GValue str_val = {0};
+ 
+  head_tag = g_object_new (GST_TYPE_CMML_TAG_HEAD, NULL);
+  
+  g_value_init (&str_val, G_TYPE_STRING);
+
+  /* Parse the content of the node and setup the GST_TAG_CMML_HEAD tag.
+   * Create a GST_TAG_TITLE when we find the title element.
+   */
+  for (walk = head->children; walk; walk = walk->next) {
+    if (!xmlStrcmp (walk->name, (xmlChar *)"title")) {
+      head_tag->title = xmlNodeGetContent (walk);
+    }
+    else if (!xmlStrcmp (walk->name, (xmlChar *)"base")) {
+      head_tag->base = xmlGetProp (walk, (xmlChar *)"uri");
+    }
+    else if (!xmlStrcmp (walk->name, (xmlChar *)"meta")) {
+      if (head_tag->meta == NULL)
+        head_tag->meta = g_value_array_new (0); 
+      /* add a pair name, content to the meta value array */
+      g_value_take_string (&str_val,
+          (gchar *)xmlGetProp (walk, (xmlChar *)"name"));
+      g_value_array_append (head_tag->meta, &str_val);
+      g_value_take_string (&str_val,
+          (gchar *)xmlGetProp (walk, (xmlChar *)"content"));
+      g_value_array_append (head_tag->meta, &str_val);
+    }
+  }
+  g_value_unset (&str_val);
+
+  parser->head_callback (parser->user_data, head_tag); 
+  g_object_unref (head_tag);
+}
+
+/* parse a cmml clip tag */
+static void
+gst_cmml_parser_parse_clip (GstCmmlParser * parser, xmlNodePtr clip)
+{
+  GstCmmlTagClip *clip_tag;
+  GValue str_val = {0};
+  guchar *id, *track, *start, *end;
+  xmlNodePtr walk;
+  GstClockTime start_time = GST_CLOCK_TIME_NONE;
+  GstClockTime end_time = GST_CLOCK_TIME_NONE;
+  
+  g_value_init (&str_val, G_TYPE_STRING);
+  
+  id = xmlGetProp (clip, (xmlChar *)"id");
+  track = xmlGetProp (clip, (xmlChar *)"track");
+  start = xmlGetProp (clip, (xmlChar *)"start");
+  end = xmlGetProp (clip, (xmlChar *)"end");
+  
+  if (start)
+    start_time = gst_cmml_clock_time_from_npt ((gchar *)start);
+  if (end)    
+    end_time = gst_cmml_clock_time_from_npt ((gchar *)end);
+
+    
+  if (track == NULL)
+      track = (guchar *)g_strdup ("default");
+  
+  clip_tag = g_object_new (GST_TYPE_CMML_TAG_CLIP,
+          "id", id,
+          "track", track,
+          "start-time", start_time,
+          "end-time", end_time,
+          NULL);
+  
+  g_free (id);
+  g_free (track);
+  g_free (start);
+  g_free (end);
+
+  /* parse the children */
+  for (walk = clip->children; walk; walk = walk->next) {
+    /* the clip is not empty */
+    clip_tag->empty = FALSE;
+    
+    if (!xmlStrcmp (walk->name, (xmlChar *)"a")) {
+      clip_tag->anchor_href = xmlGetProp (walk, (xmlChar *)"href");
+      clip_tag->anchor_text = xmlNodeGetContent (walk);
+    }
+    else if (!xmlStrcmp (walk->name, (xmlChar *)"img")) {
+      clip_tag->img_src = xmlGetProp (walk, (xmlChar *)"src");
+      clip_tag->img_alt = xmlGetProp (walk, (xmlChar *)"alt");
+    }
+    else if (!xmlStrcmp (walk->name, (xmlChar *)"desc")) {
+      clip_tag->desc_text = xmlNodeGetContent (walk);
+    }
+    else if (!xmlStrcmp (walk->name, (xmlChar *)"meta")) {
+      if (clip_tag->meta == NULL)
+        clip_tag->meta = g_value_array_new (0); 
+      /* add a pair name, content to the meta value array */
+      g_value_take_string (&str_val,
+          (char *)xmlGetProp (walk, (xmlChar *)"name"));
+      g_value_array_append (clip_tag->meta, &str_val);
+      g_value_take_string (&str_val,
+          (char *)xmlGetProp (walk, (xmlChar *)"content"));
+      g_value_array_append (clip_tag->meta, &str_val);
+    }
+  }
+  g_value_unset (&str_val);
+  
+  parser->clip_callback (parser->user_data, clip_tag);
+  g_object_unref (clip_tag);
+}
+
+void
+gst_cmml_parser_meta_to_string (GstCmmlParser * parser, 
+    xmlNodePtr parent, GValueArray * array)
+{
+  gint i;
+  xmlNodePtr node;
+  GValue *name, *content;
+
+  for (i = 0; i < array->n_values-1; i+=2) {
+    name = g_value_array_get_nth (array, i);
+    content = g_value_array_get_nth (array, i+1);
+    node = gst_cmml_parser_new_node (parser, "meta",
+        "name", g_value_get_string (name),
+        "content", g_value_get_string (content),
+        NULL);
+    xmlAddChild (parent, node);
+  }
+}
+
+/* sax handler called when an element start tag is found
+ * this is used to parse the cmml start tag
+ */
+static void
+gst_cmml_parser_parse_start_element_ns (xmlParserCtxt * ctxt,
+    const xmlChar * name, const xmlChar * prefix, const xmlChar *URI,
+    int nb_preferences, const xmlChar **namespaces,
+    int nb_attributes, int nb_defaulted, const xmlChar **attributes)
+{
+  GstCmmlParser *parser = (GstCmmlParser *)ctxt->_private;
+  
+  xmlSAX2StartElementNs (ctxt, name, prefix, URI, nb_preferences, namespaces,
+      nb_attributes, nb_defaulted, attributes);
+
+  if (parser->mode == GST_CMML_PARSER_ENCODE)
+    if (!xmlStrcmp (name, (xmlChar *)"cmml"))
+      if (parser->preamble_callback)
+        /* FIXME: flatten attributes */
+        gst_cmml_parser_parse_preamble (parser, NULL);
+}
+
+/* sax processing instruction handler
+ * used to parse the cmml processing instruction
+ */
+static void
+gst_cmml_parser_parse_processing_instruction (xmlParserCtxtPtr ctxt,
+    const xmlChar * target, const xmlChar * data)
+{
+  GstCmmlParser *parser = (GstCmmlParser *)ctxt->_private;
+  
+  xmlSAX2ProcessingInstruction (ctxt, target, data);
+
+  if (parser->mode == GST_CMML_PARSER_DECODE)
+    if (!xmlStrcmp (target, (xmlChar *)"cmml"))
+      if (parser->preamble_callback)
+        gst_cmml_parser_parse_preamble (parser, data);
+}
+
+/* sax handler called when an xml end tag is found
+ * used to parse the stream, head and clip nodes
+ */
+static void
+gst_cmml_parser_parse_end_element_ns (xmlParserCtxt * ctxt,
+    const xmlChar * name, const xmlChar * prefix, const xmlChar * URI)
+{
+  xmlNodePtr node;
+  GstCmmlParser *parser = (GstCmmlParser *)ctxt->_private;
+ 
+  xmlSAX2EndElementNs (ctxt, name, prefix, URI);
+ 
+  if (!xmlStrcmp (name, (xmlChar *)"clip")) {
+    if (parser->clip_callback) {
+      node = gst_cmml_parser_get_last_element (parser);
+      gst_cmml_parser_parse_clip (parser, node);
+    }
+  } else if (!xmlStrcmp (name, (xmlChar *)"cmml")) {
+    if (parser->cmml_end_callback)
+      parser->cmml_end_callback (parser->user_data);
+  } else if (!xmlStrcmp (name, (xmlChar *)"stream")) {
+    if (parser->stream_callback) {
+      node = gst_cmml_parser_get_last_element (parser);
+      gst_cmml_parser_parse_stream (parser, node);
+    }
+  } else if (!xmlStrcmp (name, (xmlChar *)"head")) {
+    if (parser->head_callback) {
+      node = gst_cmml_parser_get_last_element (parser);
+      gst_cmml_parser_parse_head (parser, node);
+    }
+  }
+}

=== added file 'gst/annodex/gstcmmlparser.h'
--- /dev/null
+++ gst/annodex/gstcmmlparser.h
@@ -0,0 +1,88 @@
+/*
+ * gstcmmlparser.h - (VL_UNRESOLVED)
+ * Copyright (C) 2005 (VL_UNRESOLVED)
+ * 
+ * Authors:
+ *   Alessandro Decina <alessandro@nnva.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_CMML_PARSER_H__
+#define __GST_CMML_PARSER_H__
+
+#include <libxml/parser.h>
+#include <glib.h>
+
+#include "gstcmmltag.h"
+
+typedef struct _GstCmmlParser GstCmmlParser;
+typedef enum _GstCmmlParserMode GstCmmlParserMode;
+
+typedef void (*GstCmmlParserPreambleCallback) (void * user_data, 
+    const guchar *xml_preamble, const guchar * cmml_attrs);
+
+typedef void (*GstCmmlParserCmmlEndCallback) (void * user_data);
+
+typedef void (*GstCmmlParserStreamCallback) (void * user_data,
+    GstCmmlTagStream * stream);
+
+typedef void (*GstCmmlParserHeadCallback) (void * user_data, 
+    GstCmmlTagHead * head);
+
+typedef void (*GstCmmlParserClipCallback) (void * user_data,
+    GstCmmlTagClip * clip);
+
+enum _GstCmmlParserMode {
+  GST_CMML_PARSER_ENCODE,
+  GST_CMML_PARSER_DECODE
+};
+
+struct _GstCmmlParser {
+  GstCmmlParserMode mode;
+
+  xmlParserCtxtPtr context;
+  
+  const gchar *preamble;
+  guint preamble_size;
+  
+  void *user_data;
+  GstCmmlParserPreambleCallback preamble_callback;
+  GstCmmlParserStreamCallback stream_callback;
+  GstCmmlParserCmmlEndCallback cmml_end_callback;
+  GstCmmlParserHeadCallback head_callback;
+  GstCmmlParserClipCallback clip_callback;
+};
+
+GstCmmlParser * gst_cmml_parser_new (GstCmmlParserMode mode);
+void gst_cmml_parser_free (GstCmmlParser * parser);
+
+gboolean gst_cmml_parser_parse_chunk (GstCmmlParser * parser,
+    const gchar *data, guint size);
+
+guchar *gst_cmml_parser_tag_stream_to_string (GstCmmlParser * parser,
+    GstCmmlTagStream * stream);
+
+guchar *gst_cmml_parser_tag_head_to_string (GstCmmlParser * parser,
+    GstCmmlTagHead * head);
+
+guchar *gst_cmml_parser_tag_clip_to_string (GstCmmlParser * parser,
+    GstCmmlTagClip * clip);
+
+guchar *gst_cmml_parser_tag_object_to_string (GstCmmlParser * parser,
+    GObject * tag);
+
+#endif /* __GST_CMML_PARSER_H__ */

=== added file 'gst/annodex/gstcmmltag.c'
--- /dev/null
+++ gst/annodex/gstcmmltag.c
@@ -0,0 +1,584 @@
+/*
+ * gstcmmltags.c - GStreamer CMML tag support
+ * Copyright (C) 2005 Alessandro Decina
+ * 
+ * Authors:
+ *   Alessandro Decina <alessandro@nnva.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.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <string.h>
+
+#include "gstcmmlparser.h"
+#include "gstcmmltag.h"
+#include "gstannodex.h"
+
+enum
+{
+  ARG_0,
+  GST_CMML_TAG_STREAM_TIMEBASE,
+  GST_CMML_TAG_STREAM_UTC,
+  GST_CMML_TAG_STREAM_IMPORTS,
+  GST_CMML_TAG_HEAD_TITLE,
+  GST_CMML_TAG_HEAD_BASE,
+  GST_CMML_TAG_HEAD_META,
+  GST_CMML_TAG_CLIP_EMPTY,
+  GST_CMML_TAG_CLIP_ID,
+  GST_CMML_TAG_CLIP_TRACK,
+  GST_CMML_TAG_CLIP_START_TIME,
+  GST_CMML_TAG_CLIP_END_TIME,
+  GST_CMML_TAG_CLIP_ANCHOR_HREF,
+  GST_CMML_TAG_CLIP_ANCHOR_TEXT,
+  GST_CMML_TAG_CLIP_IMG_SRC,
+  GST_CMML_TAG_CLIP_IMG_ALT,
+  GST_CMML_TAG_CLIP_DESC_TEXT,
+  GST_CMML_TAG_CLIP_META,
+};
+
+G_DEFINE_TYPE (GstCmmlTagStream, gst_cmml_tag_stream, G_TYPE_OBJECT);
+static void gst_cmml_tag_stream_finalize (GObject * object);
+static void gst_cmml_tag_stream_set_property (GObject * object,
+    guint property_id, const GValue * value, GParamSpec * pspec);
+static void gst_cmml_tag_stream_get_property (GObject * object,
+    guint property_id, GValue * value, GParamSpec * pspec);
+static void gst_cmml_tag_stream_value_from_string_value (const GValue * src,
+    GValue * dest);
+
+G_DEFINE_TYPE (GstCmmlTagHead, gst_cmml_tag_head, G_TYPE_OBJECT);
+static void gst_cmml_tag_head_finalize (GObject *object);
+static void gst_cmml_tag_head_set_property (GObject * object, guint property_id,
+    const GValue * value, GParamSpec * pspec);
+static void gst_cmml_tag_head_get_property (GObject * object, guint property_id,
+    GValue * value, GParamSpec * pspec);
+static void gst_cmml_tag_head_value_from_string_value (const GValue * src,
+    GValue * dest);
+
+G_DEFINE_TYPE (GstCmmlTagClip, gst_cmml_tag_clip, G_TYPE_OBJECT);
+static void gst_cmml_tag_clip_finalize (GObject *object);
+static void gst_cmml_tag_clip_set_property (GObject * object, guint property_id,
+    const GValue * value, GParamSpec * pspec);
+static void gst_cmml_tag_clip_get_property (GObject * object, guint property_id,
+    GValue * value, GParamSpec * pspec);
+    
+static void gst_cmml_tag_clip_value_from_string_value (const GValue * src,
+    GValue * dest);
+
+static void set_object_on_value (GObject * object, GValue * dest);
+
+static const gchar *default_preamble =
+  "<?xml version=\"1.0\" standalone=\"yes\"?>";
+
+/* Stream tag */
+static void
+gst_cmml_tag_stream_class_init (GstCmmlTagStreamClass * stream_class)
+{
+  GObjectClass *klass = G_OBJECT_CLASS (stream_class);
+
+  klass->set_property = gst_cmml_tag_stream_set_property;
+  klass->get_property = gst_cmml_tag_stream_get_property;
+  klass->finalize = gst_cmml_tag_stream_finalize;
+
+  g_object_class_install_property (klass, GST_CMML_TAG_STREAM_TIMEBASE,
+      g_param_spec_string ("timebase",
+        "Timebase",
+        "Playback time in seconds of the first data packet",
+        "0",
+        G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+
+  g_object_class_install_property (klass, GST_CMML_TAG_STREAM_UTC,
+      g_param_spec_string ("utc",
+        "UTC time",
+        "Date and wall-clock time associated with the timebase",
+        NULL,
+        G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+
+  g_object_class_install_property (klass, GST_CMML_TAG_STREAM_IMPORTS,
+      g_param_spec_value_array ("imports",
+        "Import tags",
+        "Import tags",
+        NULL,
+        G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+  
+  g_value_register_transform_func (G_TYPE_STRING, GST_TYPE_CMML_TAG_STREAM,
+      gst_cmml_tag_stream_value_from_string_value);
+}
+
+static void
+gst_cmml_tag_stream_init (GstCmmlTagStream * stream)
+{
+}
+
+static void
+gst_cmml_tag_stream_finalize (GObject * object)
+{
+  GstCmmlTagStream *stream = GST_CMML_TAG_STREAM (object);
+
+  g_free (stream->timebase);
+  g_free (stream->utc);
+  if (stream->imports)
+    g_value_array_free (stream->imports);
+
+  if (G_OBJECT_CLASS (gst_cmml_tag_stream_parent_class)->finalize)
+    G_OBJECT_CLASS (gst_cmml_tag_stream_parent_class)->finalize (object);
+}
+
+static void
+gst_cmml_tag_stream_set_property (GObject * object, guint property_id,
+    const GValue * value, GParamSpec * pspec)
+{
+  GstCmmlTagStream *stream = GST_CMML_TAG_STREAM (object);
+
+  switch (property_id) {
+    case GST_CMML_TAG_STREAM_TIMEBASE:
+      g_free (stream->timebase);
+      stream->timebase = (guchar *)g_value_dup_string (value);
+      break;
+    case GST_CMML_TAG_STREAM_UTC:
+      g_free (stream->utc);
+      stream->utc = (guchar *)g_value_dup_string (value);
+      break;
+    case GST_CMML_TAG_STREAM_IMPORTS:
+    {
+      GValueArray *va = g_value_get_boxed (value);
+      if (stream->imports)
+        g_value_array_free (stream->imports);
+      stream->imports = va != NULL ? g_value_array_copy (va) : NULL;
+      break;
+    }
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);  
+  }
+}
+
+
+static void
+gst_cmml_tag_stream_value_from_string_value (const GValue * src, GValue * dest)
+{
+  GstCmmlParser *parser;
+  const gchar *str;
+  guint size;
+  
+  parser = gst_cmml_parser_new (GST_CMML_PARSER_DECODE);
+  parser->user_data = dest;
+  parser->stream_callback =
+    (GstCmmlParserStreamCallback) set_object_on_value;
+  gst_cmml_parser_parse_chunk (parser,
+      default_preamble, strlen (default_preamble));
+  
+  str = g_value_get_string (src);
+  size = strlen (str);
+  gst_cmml_parser_parse_chunk (parser, str, size);
+
+  gst_cmml_parser_free (parser);
+}
+
+static void
+gst_cmml_tag_stream_get_property (GObject * object, guint property_id,
+    GValue * value, GParamSpec * pspec)
+{
+  GstCmmlTagStream *stream = GST_CMML_TAG_STREAM (object);
+
+  switch (property_id) {
+    case GST_CMML_TAG_STREAM_TIMEBASE:
+      g_value_set_string (value, (gchar *)stream->timebase);
+      break;
+    case GST_CMML_TAG_STREAM_UTC:
+      g_value_set_string (value, (gchar *)stream->utc);
+      break;
+    case GST_CMML_TAG_STREAM_IMPORTS:
+      g_value_set_boxed (value,
+          stream->imports ? g_value_array_copy (stream->imports) : NULL);
+      break;
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+  }
+}
+
+/* Head tag */
+static void
+gst_cmml_tag_head_class_init (GstCmmlTagHeadClass * head_class)
+{
+  GObjectClass *klass = G_OBJECT_CLASS (head_class);
+  
+  klass->set_property = gst_cmml_tag_head_set_property;
+  klass->get_property = gst_cmml_tag_head_get_property;
+  klass->finalize = gst_cmml_tag_head_finalize;
+
+  g_object_class_install_property (klass, GST_CMML_TAG_HEAD_TITLE,
+      g_param_spec_string ("title",
+        "Stream title",
+        "The title of the media",
+        NULL,
+        G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+
+  g_object_class_install_property (klass, GST_CMML_TAG_HEAD_BASE,
+      g_param_spec_string ("base",
+        "Stream base",
+        "Stream base",
+        NULL,
+        G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+      
+  g_object_class_install_property (klass, GST_CMML_TAG_HEAD_META,
+      g_param_spec_value_array ("meta",
+        "Stream meta",
+        "Stream meta information",
+        NULL,
+        G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+      
+  g_value_register_transform_func (G_TYPE_STRING, GST_TYPE_CMML_TAG_HEAD,
+      gst_cmml_tag_head_value_from_string_value);
+}
+
+static void
+gst_cmml_tag_head_init (GstCmmlTagHead * head)
+{
+}
+
+static void
+gst_cmml_tag_head_finalize (GObject * object)
+{
+  GstCmmlTagHead *head = GST_CMML_TAG_HEAD (object);
+
+  g_free (head->title);
+  g_free (head->base);
+  if (head->meta)
+    g_value_array_free (head->meta);
+
+  if (G_OBJECT_CLASS (gst_cmml_tag_head_parent_class)->finalize)
+    G_OBJECT_CLASS (gst_cmml_tag_head_parent_class)->finalize (object);
+}
+
+static void
+gst_cmml_tag_head_set_property (GObject * object, guint property_id,
+    const GValue * value, GParamSpec * pspec)
+{
+  GstCmmlTagHead *head = GST_CMML_TAG_HEAD (object);
+
+  switch (property_id) {
+    case GST_CMML_TAG_HEAD_TITLE:
+      g_free (head->title);
+      head->title = (guchar *)g_value_dup_string (value);
+      break;
+    case GST_CMML_TAG_HEAD_BASE:
+      g_free (head->base);
+      head->base = (guchar *)g_value_dup_string (value);
+      break;
+    case GST_CMML_TAG_HEAD_META:
+    {
+      GValueArray *va = g_value_get_boxed (value);
+      if (head->meta)
+        g_value_array_free (head->meta);
+      head->meta = va != NULL ? g_value_array_copy (va) : NULL;
+     
+      break;
+    }
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+  }
+}
+
+static void
+gst_cmml_tag_head_get_property (GObject * object, guint property_id,
+    GValue * value, GParamSpec * pspec)
+{
+  GstCmmlTagHead *head = GST_CMML_TAG_HEAD (object);
+
+  switch (property_id) {
+    case GST_CMML_TAG_HEAD_TITLE:
+      g_value_set_string (value, (gchar *)head->title);
+      break;
+    case GST_CMML_TAG_HEAD_BASE:
+      g_value_set_string (value, (gchar *)head->base);
+      break;
+    case GST_CMML_TAG_HEAD_META:
+      g_value_set_boxed (value,
+          head->meta ? g_value_array_copy (head->meta) : NULL);
+      break;
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+  }
+}
+
+static void
+gst_cmml_tag_head_value_from_string_value (const GValue * src, GValue * dest)
+{
+  GstCmmlParser *parser;
+  const gchar *str;
+  guint size;
+  
+  parser = gst_cmml_parser_new (GST_CMML_PARSER_DECODE);
+  parser->user_data = dest;
+  parser->head_callback =
+    (GstCmmlParserHeadCallback) set_object_on_value;
+  gst_cmml_parser_parse_chunk (parser,
+      default_preamble, strlen (default_preamble));
+  
+  str = g_value_get_string (src);
+  size = strlen (str);
+  gst_cmml_parser_parse_chunk (parser, str, size);
+
+  gst_cmml_parser_free (parser);
+}
+
+/* Clip tag */
+static void
+gst_cmml_tag_clip_class_init (GstCmmlTagClipClass * clip_class)
+{
+  GObjectClass *klass = G_OBJECT_CLASS (clip_class);
+
+  klass->set_property = gst_cmml_tag_clip_set_property;
+  klass->get_property = gst_cmml_tag_clip_get_property;
+  klass->finalize = gst_cmml_tag_clip_finalize;
+
+  g_object_class_install_property (klass, GST_CMML_TAG_CLIP_EMPTY,
+      g_param_spec_boolean ("empty",
+        "Empty clip flag",
+        "If set marks the end of the previous clip",
+        TRUE,
+        G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+
+  g_object_class_install_property (klass, GST_CMML_TAG_CLIP_ID,
+      g_param_spec_string ("id",
+        "Clip id",
+        "The id of the clip",
+        NULL,
+        G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+      
+  g_object_class_install_property (klass, GST_CMML_TAG_CLIP_TRACK,
+      g_param_spec_string ("track",
+        "Track number",
+        "The track this clip belongs to",
+        "default",
+        G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+
+  g_object_class_install_property (klass, GST_CMML_TAG_CLIP_START_TIME,
+      g_param_spec_int64 ("start-time",
+        "Start time",
+        "The start time of the clip",
+        GST_CLOCK_TIME_NONE, G_MAXINT64, GST_CLOCK_TIME_NONE,
+        G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+      
+  g_object_class_install_property (klass, GST_CMML_TAG_CLIP_END_TIME,
+      g_param_spec_int64 ("end-time",
+        "End time",
+        "The end time of the clip (if available)",
+        GST_CLOCK_TIME_NONE, G_MAXINT64, GST_CLOCK_TIME_NONE,
+        G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+ 
+  g_object_class_install_property (klass, GST_CMML_TAG_CLIP_ANCHOR_HREF,
+      g_param_spec_string ("anchor-href",
+        "Anchor URI",
+        "An URI linked to the current clip",
+        NULL,
+        G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+      
+  g_object_class_install_property (klass, GST_CMML_TAG_CLIP_ANCHOR_TEXT,
+      g_param_spec_string ("anchor-text",
+        "Anchor text",
+        "A short description of the link",
+        NULL,
+        G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+      
+  g_object_class_install_property (klass, GST_CMML_TAG_CLIP_IMG_SRC,
+      g_param_spec_string ("img-src",
+        "Image URI",
+        "The URI of a representative image for the clip",
+        NULL,
+        G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+
+  g_object_class_install_property (klass, GST_CMML_TAG_CLIP_IMG_ALT,
+      g_param_spec_string ("img-alt",
+        "Image alternative text",
+        "The alternative text to be displayed instead of the image",
+        NULL,
+        G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+      
+  g_object_class_install_property (klass, GST_CMML_TAG_CLIP_DESC_TEXT,
+      g_param_spec_string ("desc",
+        "Description text",
+        "A textual description of the content of the clip",
+        NULL,
+        G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+
+  g_object_class_install_property (klass, GST_CMML_TAG_CLIP_META,
+      g_param_spec_value_array ("meta",
+        "Meta information",
+        "Meta information for the clip",
+        NULL,
+        G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+
+  g_value_register_transform_func (G_TYPE_STRING, GST_TYPE_CMML_TAG_CLIP,
+      gst_cmml_tag_clip_value_from_string_value);
+}
+
+static void
+gst_cmml_tag_clip_init (GstCmmlTagClip * clip)
+{
+}
+
+static void
+gst_cmml_tag_clip_finalize (GObject * object)
+{
+  GstCmmlTagClip *clip = GST_CMML_TAG_CLIP (object);
+
+  g_free (clip->id);
+  g_free (clip->track);
+  g_free (clip->anchor_href);
+  g_free (clip->anchor_text);
+  g_free (clip->img_src);
+  g_free (clip->img_alt);
+  g_free (clip->desc_text);
+  if (clip->meta)
+    g_value_array_free (clip->meta);
+
+  if (G_OBJECT_CLASS (gst_cmml_tag_clip_parent_class)->finalize)
+    G_OBJECT_CLASS (gst_cmml_tag_clip_parent_class)->finalize (object);
+}
+
+static void
+gst_cmml_tag_clip_set_property (GObject * object, guint property_id,
+    const GValue * value, GParamSpec * pspec)
+{
+  GstCmmlTagClip *clip = GST_CMML_TAG_CLIP (object);
+
+  switch (property_id) {
+    case GST_CMML_TAG_CLIP_EMPTY:
+      clip->empty = g_value_get_boolean (value);
+      break;
+    case GST_CMML_TAG_CLIP_ID:
+      g_free (clip->id);
+      clip->id = (guchar *)g_value_dup_string (value);
+      break;
+    case GST_CMML_TAG_CLIP_TRACK:
+      g_free (clip->track);
+      clip->track = (guchar *)g_value_dup_string (value);
+      break;
+    case GST_CMML_TAG_CLIP_START_TIME:
+      clip->start_time = g_value_get_int64 (value);
+      break;
+    case GST_CMML_TAG_CLIP_END_TIME:
+      clip->end_time = g_value_get_int64 (value);
+      break;
+    case GST_CMML_TAG_CLIP_ANCHOR_HREF:
+      g_free (clip->anchor_href);
+      clip->anchor_href = (guchar *)g_value_dup_string (value);
+      break;
+    case GST_CMML_TAG_CLIP_ANCHOR_TEXT:
+      g_free (clip->anchor_text);
+      clip->anchor_text = (guchar *)g_value_dup_string (value);
+      break;
+    case GST_CMML_TAG_CLIP_IMG_SRC:
+      g_free (clip->img_src);
+      clip->img_src = (guchar *)g_value_dup_string (value);
+      break;
+    case GST_CMML_TAG_CLIP_IMG_ALT:
+      g_free (clip->img_alt);
+      clip->img_alt = (guchar *)g_value_dup_string (value);
+      break;
+    case GST_CMML_TAG_CLIP_DESC_TEXT:
+      g_free (clip->desc_text);
+      clip->desc_text = (guchar *)g_value_dup_string (value);
+      break;
+    case GST_CMML_TAG_CLIP_META:
+    {
+      GValueArray *va = (GValueArray *) g_value_get_boxed (value);
+      if (clip->meta)
+        g_value_array_free (clip->meta);
+      
+      clip->meta = va != NULL ? g_value_array_copy (va) : NULL;
+      
+      break;
+    }
+  }
+}
+
+static void
+gst_cmml_tag_clip_get_property (GObject * object, guint property_id,
+    GValue * value, GParamSpec * pspec)
+{
+  GstCmmlTagClip *clip = GST_CMML_TAG_CLIP (object);
+
+  switch (property_id) {
+    case GST_CMML_TAG_CLIP_EMPTY:
+      g_value_set_boolean (value, clip->empty);
+      break;
+    case GST_CMML_TAG_CLIP_ID:
+      g_value_set_string (value, (gchar *)clip->id);
+      break;
+    case GST_CMML_TAG_CLIP_TRACK:
+      g_value_set_string (value, (gchar *)clip->track);
+      break;
+    case GST_CMML_TAG_CLIP_START_TIME:
+      g_value_set_int64 (value, clip->start_time);
+      break;
+    case GST_CMML_TAG_CLIP_END_TIME:
+      g_value_set_int64 (value, clip->end_time);
+      break;
+    case GST_CMML_TAG_CLIP_ANCHOR_HREF:
+      g_value_set_string (value, (gchar *)clip->anchor_href);
+      break;
+    case GST_CMML_TAG_CLIP_ANCHOR_TEXT:
+      g_value_set_string (value, (gchar *)clip->anchor_text);
+      break;
+    case GST_CMML_TAG_CLIP_IMG_SRC:
+      g_value_set_string (value, (gchar *)clip->img_src);
+      break;
+    case GST_CMML_TAG_CLIP_IMG_ALT:
+      g_value_set_string (value, (gchar *)clip->img_alt);
+      break;
+    case GST_CMML_TAG_CLIP_DESC_TEXT:
+      g_value_set_string (value, (gchar *)clip->desc_text);
+      break;
+    case GST_CMML_TAG_CLIP_META:
+      g_value_set_boxed (value,
+          clip->meta ? g_value_array_copy (clip->meta) : NULL);
+      break;
+  }
+}
+
+static void
+gst_cmml_tag_clip_value_from_string_value (const GValue * src, GValue * dest)
+{
+  GstCmmlParser *parser;
+  const gchar *str;
+  guint size;
+  
+  parser = gst_cmml_parser_new (GST_CMML_PARSER_DECODE);
+  parser->user_data = dest;
+  parser->clip_callback =
+    (GstCmmlParserClipCallback) set_object_on_value;
+
+  gst_cmml_parser_parse_chunk (parser, default_preamble,
+      strlen (default_preamble));
+  
+  str = g_value_get_string (src);
+  size = strlen (str);
+  
+  gst_cmml_parser_parse_chunk (parser, str, size);
+
+  gst_cmml_parser_free (parser);
+}
+
+static void
+set_object_on_value (GObject * tag, GValue * dest)
+{
+  g_value_take_object (dest, tag);
+}

=== added file 'gst/annodex/gstcmmltag.h'
--- /dev/null
+++ gst/annodex/gstcmmltag.h
@@ -0,0 +1,130 @@
+/*
+ * gstcmmltag.h - GStreamer annodex CMML tag support
+ * Copyright (C) 2005 Alessandro Decina
+ * 
+ * Authors:
+ *   Alessandro Decina <alessandro@nnva.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_CMML_TAG_H__
+#define __GST_CMML_TAG_H__
+
+#include <gst/gst.h>
+
+/* GstCmmlTagStream */
+#define GST_TYPE_CMML_TAG_STREAM (gst_cmml_tag_stream_get_type ())
+#define GST_CMML_TAG_STREAM(obj) \
+  (G_TYPE_CHECK_INSTANCE_CAST((obj), \
+                              GST_TYPE_CMML_TAG_STREAM, GstCmmlTagStream))
+#define GST_CMML_TAG_STREAM_CLASS(klass) \
+  (G_TYPE_CHECK_CLASS_CAST((klass), GST_TYPE_CMML_TAG_STREAM, GstCmmlTagStream))
+#define GST_CMML_TAG_STREAM_GET_CLASS(obj) \
+  (G_TYPE_INSTANCE_GET_CLASS((obj), \
+                             GST_TYPE_CMML_TAG_STREAM, GstCmmlTagStreamClass))
+
+/* GstCmmlTagHead */
+#define GST_TYPE_CMML_TAG_HEAD (gst_cmml_tag_head_get_type ())
+#define GST_CMML_TAG_HEAD(obj) \
+  (G_TYPE_CHECK_INSTANCE_CAST((obj), GST_TYPE_CMML_TAG_HEAD, GstCmmlTagHead))
+#define GST_CMML_TAG_HEAD_CLASS(klass) \
+  (G_TYPE_CHECK_CLASS_CAST((klass), GST_TYPE_CMML_TAG_HEAD, GstCmmlTagHead))
+#define GST_CMML_TAG_HEAD_GET_CLASS(obj) \
+  (G_TYPE_INSTANCE_GET_CLASS((obj), \
+                             GST_TYPE_CMML_TAG_HEAD, GstCmmlTagHeadClass))
+
+/* GstCmmlTagClip */
+#define GST_TYPE_CMML_TAG_CLIP (gst_cmml_tag_clip_get_type ())
+#define GST_CMML_TAG_CLIP(obj) \
+  (G_TYPE_CHECK_INSTANCE_CAST((obj), GST_TYPE_CMML_TAG_CLIP, GstCmmlTagClip))
+#define GST_CMML_TAG_CLIP_CLASS(obj) \
+  (G_TYPE_CHECK_CLASS_CAST((klass), GST_TYPE_CMML_TAG_CLIP, GstCmmlTagClip))
+#define GST_CMML_TAG_CLIP_GET_CLASS(obj) \
+(G_TYPE_INSTANCE_GET_CLASS((obj), GST_TYPE_CMML_TAG_CLIP, GstCmmlTagClipClass))
+
+typedef struct _GstCmmlTagStream GstCmmlTagStream;
+typedef struct _GstCmmlTagStreamClass GstCmmlTagStreamClass;
+typedef struct _GstCmmlTagHead GstCmmlTagHead;
+typedef struct _GstCmmlTagHeadClass GstCmmlTagHeadClass;
+typedef struct _GstCmmlTagClip GstCmmlTagClip;
+typedef struct _GstCmmlTagClipClass GstCmmlTagClipClass;
+
+struct _GstCmmlTagStream {
+  GObject object;
+
+  guchar *timebase;
+  guchar *utc;
+
+  GValueArray *imports;
+};
+
+struct _GstCmmlTagStreamClass {
+  GObjectClass parent_class;
+};
+
+struct _GstCmmlTagHead {
+  GObject object;
+  
+  guchar *title;                  /* title of the media */
+  guchar *base;
+  GValueArray *meta;              /* metadata attached to the media.
+                                 * The elements are positioned in key-value
+                                 * pairs ie (key, content, key2, content2,
+                                 * ...)
+                                 */
+};
+
+struct _GstCmmlTagHeadClass {
+  GObjectClass parent_class;
+};
+
+struct _GstCmmlTagClip {
+  GObject object;
+
+  gboolean empty;                 /* empty flag. An empty clip marks the
+                                   * end of the previous clip.
+                                   */
+  
+  guchar *id;                     /* clip id */
+  guchar *track;                  /* clip track */
+  GstClockTime start_time;        /* clip start time */
+  GstClockTime end_time;          /* clip end time */
+  
+  guchar *anchor_href;            /* anchor href URI */
+  guchar *anchor_text;            /* anchor text */
+  
+  guchar *img_src;                /* image URI */
+  guchar *img_alt;                /* image alternative text */
+  
+  guchar *desc_text;              /* clip description */
+  
+  GValueArray *meta;              /* metadata attached to the clip
+                                   * The elements are positioned in key-value
+                                   * pairs ie (key, content, key2, content2,
+                                   * ...)
+                                   */
+};
+
+struct _GstCmmlTagClipClass {
+  GObjectClass parent_class;
+};
+
+GType gst_cmml_tag_stream_get_type (void);
+GType gst_cmml_tag_head_get_type (void);
+GType gst_cmml_tag_clip_get_type (void);
+
+#endif /* __GST_CMML_TAG_H__ */

=== added file 'gst/annodex/gstskeldec.c'
--- /dev/null
+++ gst/annodex/gstskeldec.c
@@ -0,0 +1,336 @@
+/*
+ * gstskeldec.c - GStreamer annodex skeleton decoder
+ * Copyright (C) 2005 Alessandro Decina
+ * 
+ * Authors:
+ *   Alessandro Decina <alessandro@nnva.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.
+ */
+
+#include <string.h>
+#include "gstskeldec.h"
+#include "gstskeltag.h"
+#include "gstannodex.h"
+
+GST_DEBUG_CATEGORY (skeldec);
+#define GST_CAT_DEFAULT skeldec
+
+enum {
+  GST_SKEL_TAG_FISHEAD_UTC_LEN = 19
+};
+
+enum {
+  LAST_SIGNAL
+};
+
+static GstElementDetails gst_skel_dec_details = {
+  "skeldec: annodex skeleton stream decoder",
+  "Codec/Decoder",
+  "decode ogg skeleton streams",
+  "Alessandro Decina <alessandro@nnva.org>",
+};
+
+static GstStaticPadTemplate gst_skel_dec_src_factory =
+GST_STATIC_PAD_TEMPLATE ("src",
+    GST_PAD_SRC,
+    GST_PAD_ALWAYS,
+    /* this should be application/x-ogg-skeleton but that would break
+     * autoplugging */
+    GST_STATIC_CAPS ("application/octet-stream")
+    );
+
+static GstStaticPadTemplate gst_skel_dec_sink_factory =
+GST_STATIC_PAD_TEMPLATE ("sink",
+    GST_PAD_SINK,
+    GST_PAD_ALWAYS,
+    GST_STATIC_CAPS ("application/x-ogg-skeleton")
+    );
+
+/* GstSkelDec prototypes */
+GST_BOILERPLATE (GstSkelDec, gst_skel_dec, GstElement, GST_TYPE_ELEMENT);
+static gboolean gst_skel_dec_sink_query (GstPad * pad, GstQuery * query);
+static GstStateChangeReturn gst_skel_dec_change_state (GstElement * element, GstStateChange transition);
+static GstFlowReturn gst_skel_dec_chain (GstPad * pad, GstBuffer * buffer);
+static GstFlowReturn gst_skel_dec_parse_fishead (GstSkelDec *dec,
+    GstBuffer * buffer);
+static GstFlowReturn gst_skel_dec_parse_fisbone (GstSkelDec *dec,
+    GstBuffer * buffer);
+
+/* GstSkelDec code */
+static void
+gst_skel_dec_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 (&gst_skel_dec_sink_factory));
+  gst_element_class_add_pad_template (element_class,
+      gst_static_pad_template_get (&gst_skel_dec_src_factory));
+  gst_element_class_set_details (element_class, &gst_skel_dec_details);
+}
+
+static void
+gst_skel_dec_class_init (GstSkelDecClass * klass)
+{
+  GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
+
+  element_class->change_state = gst_skel_dec_change_state;
+}
+
+static void
+gst_skel_dec_init (GstSkelDec * dec, GstSkelDecClass * klass)
+{
+  dec->sinkpad =
+      gst_pad_new_from_static_template (&gst_skel_dec_sink_factory, "sink");
+  gst_pad_set_query_function (dec->sinkpad, gst_skel_dec_sink_query);
+  gst_pad_set_chain_function (dec->sinkpad, gst_skel_dec_chain);
+  gst_element_add_pad (GST_ELEMENT (dec), dec->sinkpad);
+
+  dec->srcpad =
+      gst_pad_new_from_static_template (&gst_skel_dec_src_factory, "src");
+  gst_element_add_pad (GST_ELEMENT (dec), dec->srcpad);
+
+}
+
+static gboolean
+gst_skel_dec_sink_query (GstPad * pad, GstQuery * query)
+{
+  gboolean res = FALSE;
+
+  switch (GST_QUERY_TYPE (query)) {
+    case GST_QUERY_CONVERT:
+    {
+      GstFormat src_format, dest_format;
+      gint64 src_val, dest_val;
+
+      gst_query_parse_convert (query, &src_format, &src_val,
+          &dest_format, &dest_val);
+      
+      if (dest_format == GST_FORMAT_TIME) {
+        dest_val = GST_CLOCK_TIME_NONE;
+        res = TRUE;
+      }
+
+      if (res) {
+        gst_query_set_convert (query, src_format, src_val,
+            dest_format, dest_val);
+      }
+      
+      break;
+    }
+    default:
+      break;
+  }
+
+  return res;
+}
+
+static GstStateChangeReturn
+gst_skel_dec_change_state (GstElement * element, GstStateChange transition)
+{
+  GstSkelDec *dec = GST_SKEL_DEC (element);
+  GstStateChangeReturn res;
+  
+  /* handle the upward state changes */
+  switch (transition) {
+    case GST_STATE_CHANGE_READY_TO_PAUSED:
+      dec->major = 0;
+      dec->minor = 0;
+      break;
+    default:
+      break;
+  }
+
+  res = parent_class->change_state (element, transition);
+  
+  /* no need to handle downward state changes */
+
+  return res;
+}
+
+static GstFlowReturn
+gst_skel_dec_chain (GstPad * pad, GstBuffer * buffer)
+{
+  GstSkelDec *dec = GST_SKEL_DEC (GST_PAD_PARENT (pad));
+  GstFlowReturn ret;
+
+  gint size = GST_BUFFER_SIZE (buffer);
+  guint8 *data = GST_BUFFER_DATA (buffer);
+  
+  if (GST_BUFFER_SIZE (buffer) == 0) {
+    /* the skeleton EOS has no packet data */
+    return GST_FLOW_OK;
+  }
+  
+  if (size >= GST_SKEL_OGG_FISHEAD_SIZE && !memcmp (data, "fishead\0", 8)) {
+    ret = gst_skel_dec_parse_fishead (dec, buffer);
+  } else if (size >= 8 && !memcmp (data, "fisbone\0", 8)) {
+    ret = gst_skel_dec_parse_fisbone (dec, buffer);
+  } else {
+    /* maybe it would be better to ignore the packet */
+    GST_ELEMENT_ERROR (dec, STREAM, DECODE, (NULL), ("unknown packet type"));
+    ret = GST_FLOW_ERROR;
+  }
+  
+  return ret;
+}
+
+static GstFlowReturn
+gst_skel_dec_parse_fishead (GstSkelDec * dec, GstBuffer * buffer)
+{
+  GstTagList *tags;
+  guint8 *data = GST_BUFFER_DATA (buffer);
+  GstSkelTagFishead *fishead = g_object_new (GST_TYPE_SKEL_TAG_FISHEAD, NULL);
+
+  data += 8;
+  fishead->major = GST_READ_UINT16_LE (data);
+  data += 2;
+  fishead->minor = GST_READ_UINT16_LE (data);
+  data += 2;
+  fishead->prestime_n = GST_READ_UINT64_LE (data);
+  data += 8;
+  fishead->prestime_d = GST_READ_UINT64_LE (data);
+  data += 8;
+  fishead->basetime_n = GST_READ_UINT64_LE (data);
+  data += 8;
+  fishead->basetime_d = GST_READ_UINT64_LE (data);
+  data += 8;
+  fishead->utc = g_strndup ((gchar *)data, GST_SKEL_TAG_FISHEAD_UTC_LEN);
+
+  GST_INFO_OBJECT (dec, "fishead parsed ("
+      "major: %"G_GUINT16_FORMAT " minor: %"G_GUINT16_FORMAT
+      " prestime_n: %"G_GINT64_FORMAT " prestime_d: %"G_GINT64_FORMAT
+      " basetime_n: %"G_GINT64_FORMAT " basetime_d: %"G_GINT64_FORMAT
+      " utc: %s)", fishead->major, fishead->minor, fishead->prestime_n,
+      fishead->prestime_d, fishead->basetime_n, fishead->basetime_d,
+      fishead->utc); 
+  
+  /* send the TAG_MESSAGE */
+  tags = gst_tag_list_new ();
+  gst_tag_list_add (tags, GST_TAG_MERGE_APPEND,
+      GST_TAG_SKELETON_FISHEAD, fishead, NULL);
+  gst_element_found_tags_for_pad (GST_ELEMENT (dec), dec->srcpad, tags);
+  
+  g_object_unref (fishead); 
+
+  /* forward the fishead */
+  gst_buffer_set_caps (buffer,
+      gst_static_pad_template_get_caps (&gst_skel_dec_src_factory));
+  return gst_pad_push (dec->srcpad, buffer);
+}
+
+static GstFlowReturn
+gst_skel_dec_parse_fisbone (GstSkelDec * dec, GstBuffer * buffer)
+{
+  GstSkelTagFisbone *fisbone;
+  guint8 *data;
+  gchar *headers;
+  gchar **tokens;
+  GstTagList *tags; 
+  GValue *val;
+  
+  data = GST_BUFFER_DATA (buffer);
+  fisbone = g_object_new (GST_TYPE_SKEL_TAG_FISBONE, NULL);
+  
+  data += 8;
+  fisbone->hdr_offset = GST_READ_UINT32_LE (data);
+  data += 4;
+  fisbone->serialno = GST_READ_UINT32_LE (data);
+  data += 4;
+  fisbone->hdr_num = GST_READ_UINT32_LE (data);
+  data += 4;
+  fisbone->granulerate_n = GST_READ_UINT64_LE (data);
+  data += 8;
+  fisbone->granulerate_d = GST_READ_UINT64_LE (data);
+  data += 8;
+  fisbone->start_granule = GST_READ_UINT64_LE (data);
+  data += 8;
+  fisbone->preroll = GST_READ_UINT32_LE (data);
+  data += 4;
+  fisbone->granuleshift = GST_READ_UINT8 (data);
+  data += 1;
+  data += 3; /* padding */
+
+  /* 8 = strlen ("fishead\0") */
+  headers = g_strndup ((gchar *)data,
+      GST_BUFFER_SIZE (buffer) - 8 - fisbone->hdr_offset);
+  fisbone->headers = gst_annodex_parse_headers (headers);
+  g_free (headers);
+ 
+  /* check for the mandatory Content-Type header: it MUST be the first
+   * header */
+  if (fisbone->headers->n_values < 2 ||
+      (val = g_value_array_get_nth (fisbone->headers, 0)) == NULL ||
+      strcmp (g_value_get_string (val), "Content-Type"))
+    goto no_content_type;
+   
+  /* the the Content-Type value */
+  val = g_value_array_get_nth (fisbone->headers, 1);
+  /* split it in "content_type; encoding" */
+  tokens = g_strsplit (g_value_get_string (val), ";", 2);
+  fisbone->content_type = g_strstrip (tokens[0]);
+  fisbone->encoding = tokens[1] == NULL ? NULL : g_strstrip (tokens[1]);
+      
+  GST_INFO_OBJECT (dec, "fisbone parsed ("
+      "serialno %"G_GUINT32_FORMAT " granulerate_n: %"G_GINT64_FORMAT
+      " granulerate_d: %"G_GINT64_FORMAT " start_granule: %"G_GINT64_FORMAT
+      " preroll: %"G_GUINT32_FORMAT " granuleshift: %d"
+      " content-type: %s)",
+      fisbone->serialno, fisbone->granulerate_n, fisbone->granulerate_d,
+      fisbone->start_granule, fisbone->preroll, fisbone->granuleshift,
+      fisbone->content_type);
+  
+  /* send the TAG_MESSAGE */
+  tags = gst_tag_list_new ();  
+  gst_tag_list_add (tags, GST_TAG_MERGE_APPEND,
+      GST_TAG_SKELETON_FISBONE, fisbone, NULL); 
+  gst_element_found_tags_for_pad (GST_ELEMENT (dec), dec->srcpad, tags);
+  
+  g_object_unref (fisbone);
+ 
+  gst_buffer_set_caps (buffer,
+      gst_static_pad_template_get_caps (&gst_skel_dec_src_factory));
+  return gst_pad_push (dec->srcpad, buffer);
+
+no_content_type:
+  gst_buffer_unref (buffer);
+  GST_ELEMENT_ERROR (dec, STREAM, DECODE, (NULL), 
+      ("no content type in fisbone %"G_GUINT32_FORMAT, fisbone->serialno));
+  g_object_unref (fisbone);
+  return GST_FLOW_ERROR;
+}
+
+gboolean
+gst_skel_dec_plugin_init (GstPlugin * plugin)
+{
+  if (!gst_element_register (plugin, "skeldec", GST_RANK_PRIMARY,
+          gst_skel_dec_get_type ()))
+    return FALSE;
+
+  gst_tag_register (GST_TAG_SKELETON_FISHEAD, GST_TAG_FLAG_META,
+      GST_TYPE_SKEL_TAG_FISHEAD, "skeleton-fishead",
+      "annodex skeleton fishead tag", NULL);
+
+  gst_tag_register (GST_TAG_SKELETON_FISBONE, GST_TAG_FLAG_META,
+      GST_TYPE_SKEL_TAG_FISBONE, "skeleton-fisbone",
+      "annodex skeleton fisbone tag", NULL);
+
+  GST_DEBUG_CATEGORY_INIT (skeldec, "skeldec", 0,
+      "annodex skeleton decoding element");
+
+  return TRUE;
+}

=== added file 'gst/annodex/gstskeldec.h'
--- /dev/null
+++ gst/annodex/gstskeldec.h
@@ -0,0 +1,60 @@
+/*
+ * gstskeldec.h - GStreamer annodex skeleton decoder
+ * Copyright (C) 2005 Alessandro Decina
+ * 
+ * Authors:
+ *   Alessandro Decina <alessandro@nnva.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_SKEL_DEC_H__
+#define __GST_SKEL_DEC_H__
+
+#include <gst/gst.h>
+
+/* GstSkelDec */
+#define GST_TYPE_SKEL_DEC (gst_skel_dec_get_type ())
+#define GST_SKEL_DEC(obj) \
+  (G_TYPE_CHECK_INSTANCE_CAST((obj), GST_TYPE_SKEL_DEC, GstSkelDec))
+#define GST_SKEL_DEC_CLASS(klass) \
+  (G_TYPE_CHECK_CLASS_CAST((klass), GST_TYPE_SKEL_DEC, GstSkelDec))
+#define GST_SKEL_DEC_GET_CLASS(obj) \
+  (G_TYPE_INSTANCE_GET_CLASS((obj), GST_TYPE_SKEL_DEC, GstSkelDecClass))
+
+typedef struct _GstSkelDec GstSkelDec;
+typedef struct _GstSkelDecClass GstSkelDecClass;
+
+#define GST_SKEL_OGG_FISHEAD_SIZE 64
+#define UTC_LEN 20
+
+struct _GstSkelDec {
+  GstElement element;
+
+  GstPad *sinkpad;
+  GstPad *srcpad;
+
+  gint16 major;   /* skeleton version major */
+  gint16 minor;   /* skeleton version minor */
+};
+
+struct _GstSkelDecClass {
+  GstElementClass parent_class;
+};
+
+GType gst_skel_dec_get_type (void);
+gboolean gst_skel_dec_plugin_init (GstPlugin * plugin);
+
+#endif /* __GST_SKEL_DEC_H__ */

=== added file 'gst/annodex/gstskeltag.c'
--- /dev/null
+++ gst/annodex/gstskeltag.c
@@ -0,0 +1,377 @@
+/*
+ * gstskeltag.c - (VL_UNRESOLVED)
+ * Copyright (C) 2005 (VL_UNRESOLVED)
+ * 
+ * Authors:
+ *   Alessandro Decina <alessandro@nnva.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.
+ */
+
+#include "gstskeltag.h"
+
+enum {
+  ARG_0,
+  GST_SKEL_TAG_FISHEAD_MAJOR,
+  GST_SKEL_TAG_FISHEAD_MINOR,
+  GST_SKEL_TAG_FISHEAD_PRESTIME_N,
+  GST_SKEL_TAG_FISHEAD_PRESTIME_D,
+  GST_SKEL_TAG_FISHEAD_BASETIME_N,
+  GST_SKEL_TAG_FISHEAD_BASETIME_D,
+  GST_SKEL_TAG_FISHEAD_UTC,
+  GST_SKEL_TAG_FISBONE_SERIALNO,
+  GST_SKEL_TAG_FISBONE_GRANULERATE_N,
+  GST_SKEL_TAG_FISBONE_GRANULERATE_D,
+  GST_SKEL_TAG_FISBONE_START_GRANULE,
+  GST_SKEL_TAG_FISBONE_PREROLL,
+  GST_SKEL_TAG_FISBONE_GRANULESHIFT,
+  GST_SKEL_TAG_FISBONE_HEADERS,
+  GST_SKEL_TAG_FISBONE_CONTENT_TYPE,
+  GST_SKEL_TAG_FISBONE_ENCODING,
+};
+
+/* GstSkelTagFishead prototypes */
+G_DEFINE_TYPE (GstSkelTagFishead, gst_skel_tag_fishead, G_TYPE_OBJECT);
+static void gst_skel_tag_fishead_finalize (GObject * object);
+static void gst_skel_tag_fishead_set_property (GObject * object, guint property_id, const GValue * value, GParamSpec * pspec);
+static void gst_skel_tag_fishead_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec);
+
+/* GstSkelTagFisbone prototypes */
+G_DEFINE_TYPE (GstSkelTagFisbone, gst_skel_tag_fisbone, G_TYPE_OBJECT);
+static void gst_skel_tag_fisbone_finalize (GObject * object);
+static void gst_skel_tag_fisbone_set_property (GObject * object, guint property_id, const GValue * value, GParamSpec * pspec);
+static void gst_skel_tag_fisbone_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec);
+
+/* GstSkelTagFishead */
+static void
+gst_skel_tag_fishead_class_init (GstSkelTagFisheadClass * fishead_class)
+{
+  GObjectClass *klass = G_OBJECT_CLASS (fishead_class);
+  
+  klass->set_property = gst_skel_tag_fishead_set_property;
+  klass->get_property = gst_skel_tag_fishead_get_property;
+  klass->finalize = gst_skel_tag_fishead_finalize;
+
+  g_object_class_install_property (klass, GST_SKEL_TAG_FISHEAD_MAJOR,
+      g_param_spec_int ("version-major",
+        "Major version number",
+        "Major number of the skeleton bitstream",
+        0, 0, 0, G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+ 
+  g_object_class_install_property (klass, GST_SKEL_TAG_FISHEAD_MINOR,  
+      g_param_spec_int ("version-minor",
+        "Minor version number",
+        "Minor number of the skeleton bitstream",
+        0, 0, 0, G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+  
+  g_object_class_install_property (klass, GST_SKEL_TAG_FISHEAD_PRESTIME_N,
+      g_param_spec_int64 ("presentation-time-numerator",
+        "Presentation time numerator",
+        "Stream presentation time numerator",
+        0, 0, 0, G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+
+      
+  g_object_class_install_property (klass, GST_SKEL_TAG_FISHEAD_PRESTIME_D,
+      g_param_spec_int64 ("presentation-time-denominator",
+        "Presentation time denominator",
+        "Stream presentation time denominator",
+        0, 0, 0, G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+
+  g_object_class_install_property (klass, GST_SKEL_TAG_FISHEAD_BASETIME_N,
+      g_param_spec_int64 ("base-time-numerator",
+        "Basetime numerator",
+        "Stream base time numerator",
+        0, 0, 0, G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+
+  g_object_class_install_property (klass, GST_SKEL_TAG_FISHEAD_BASETIME_D,  
+      g_param_spec_int64 ("base-time-denominator",
+        "Base time denominator",
+        "Stream base time denominator",
+        0, 0, 0, G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+
+  g_object_class_install_property (klass, GST_SKEL_TAG_FISHEAD_UTC, 
+      g_param_spec_string ("utc",
+        "UTC time",
+        "UTC time associated with the basetime",
+        NULL,
+        G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+}
+
+static void
+gst_skel_tag_fishead_init (GstSkelTagFishead * fishead)
+{
+}
+
+static void
+gst_skel_tag_fishead_finalize (GObject * object)
+{
+  GObjectClass *parent_class =
+    G_OBJECT_CLASS (gst_skel_tag_fishead_parent_class);
+  GstSkelTagFishead *fishead = GST_SKEL_TAG_FISHEAD (object);
+  
+  g_free (fishead->utc);
+  
+  GST_CALL_PARENT (G_OBJECT_CLASS, finalize, (object));
+}
+
+static void
+gst_skel_tag_fishead_set_property (GObject * object, guint property_id,
+    const GValue * value, GParamSpec * pspec)
+{
+  GstSkelTagFishead *fishead = GST_SKEL_TAG_FISHEAD (object);
+
+  switch (property_id) {
+    case GST_SKEL_TAG_FISHEAD_MAJOR:
+      fishead->major = g_value_get_int (value);
+      break;
+    case GST_SKEL_TAG_FISHEAD_MINOR:
+      fishead->minor = g_value_get_int (value);
+      break;
+    case GST_SKEL_TAG_FISHEAD_PRESTIME_N:
+      fishead->prestime_n = g_value_get_int64 (value);
+      break;
+    case GST_SKEL_TAG_FISHEAD_PRESTIME_D:
+      fishead->prestime_d = g_value_get_int64 (value);
+      break;
+    case GST_SKEL_TAG_FISHEAD_BASETIME_N:
+      fishead->basetime_n = g_value_get_int64 (value);
+      break;
+    case GST_SKEL_TAG_FISHEAD_BASETIME_D:
+      fishead->basetime_d = g_value_get_int64 (value);
+      break;
+    case GST_SKEL_TAG_FISHEAD_UTC:
+      g_free (fishead->utc);
+      fishead->utc = g_value_dup_string (value);
+      break;
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+  }
+}
+
+static void
+gst_skel_tag_fishead_get_property (GObject * object, guint property_id,
+    GValue * value, GParamSpec * pspec)
+{
+  GstSkelTagFishead *fishead = GST_SKEL_TAG_FISHEAD (object);
+
+  switch (property_id) {
+    case GST_SKEL_TAG_FISHEAD_MAJOR:
+      g_value_set_int (value, fishead->major);
+      break;
+    case GST_SKEL_TAG_FISHEAD_MINOR:
+      g_value_set_int (value, fishead->minor);
+      break;
+    case GST_SKEL_TAG_FISHEAD_BASETIME_N:
+      g_value_set_int64 (value, fishead->basetime_n);
+      break;
+    case GST_SKEL_TAG_FISHEAD_BASETIME_D:
+      g_value_set_int64 (value, fishead->basetime_d);
+      break;
+    case GST_SKEL_TAG_FISHEAD_PRESTIME_N:
+      g_value_set_int64 (value, fishead->prestime_n);
+      break;
+    case GST_SKEL_TAG_FISHEAD_PRESTIME_D:
+      g_value_set_int64 (value, fishead->prestime_d);
+      break;
+    case GST_SKEL_TAG_FISHEAD_UTC:
+      g_value_set_string (value, fishead->utc);
+      break;
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+  }
+}
+
+/* GstSkelTagFisbone code */
+
+static void
+gst_skel_tag_fisbone_class_init (GstSkelTagFisboneClass * fisbone_class)
+{
+  GObjectClass *klass = G_OBJECT_CLASS (fisbone_class);
+  
+  klass->set_property = gst_skel_tag_fisbone_set_property;
+  klass->get_property = gst_skel_tag_fisbone_get_property;
+  klass->finalize = gst_skel_tag_fisbone_finalize;
+
+  g_object_class_install_property (klass, GST_SKEL_TAG_FISBONE_SERIALNO, 
+      g_param_spec_uint ("serial-number", 
+        "Serial number", 
+        "Serial number of the logical bitstream",
+        0, 0, 0,
+        G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+  
+  g_object_class_install_property (klass, GST_SKEL_TAG_FISBONE_GRANULERATE_N, 
+      g_param_spec_int64 ("granule-rate-numerator",
+        "Granulerate numerator",
+        "Granulerate numerator",
+        0, 0, 0,
+        G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+
+  g_object_class_install_property (klass, GST_SKEL_TAG_FISBONE_GRANULERATE_D,
+      g_param_spec_int64 ("granule-rate-denominator",
+        "Granulerate denominator",
+        "Granulerate denominator",
+        0, 0, 0,
+        G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+
+  g_object_class_install_property (klass, GST_SKEL_TAG_FISBONE_START_GRANULE,
+      g_param_spec_int64 ("granule-start",
+        "Start granule",
+        "The granule number with which this bitstream starts",
+        0, 0, 0,
+        G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+      
+  g_object_class_install_property (klass, GST_SKEL_TAG_FISBONE_PREROLL, 
+      g_param_spec_uint64 ("preroll",
+        "The number of packets to preroll",
+        "The number of packets to preroll to decode a packet correctly",
+        0, 0, 0,
+        G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+      
+  g_object_class_install_property (klass, GST_SKEL_TAG_FISBONE_GRANULESHIFT,
+      g_param_spec_uint ("granule-shift",
+        "Granuleshift",
+        "The number of lower bits to use for partitioning a granule position",
+        0, 0, 0,
+        G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+
+  g_object_class_install_property (klass, GST_SKEL_TAG_FISBONE_HEADERS,
+      g_param_spec_boxed ("headers",
+        "Message header fields",
+        "RFC2822 header fields describing a bitstream",
+        G_TYPE_VALUE_ARRAY,
+        G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+  
+  g_object_class_install_property (klass, GST_SKEL_TAG_FISBONE_CONTENT_TYPE,
+      g_param_spec_string ("content-type",
+        "Content type",
+        "Bitstream content type",
+        NULL,
+        G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+
+  g_object_class_install_property (klass, GST_SKEL_TAG_FISBONE_ENCODING,
+      g_param_spec_string ("encoding",
+        "Encoding",
+        "Bitstream encoding",
+        NULL,
+        G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+}
+
+static void
+gst_skel_tag_fisbone_init (GstSkelTagFisbone * fisbone)
+{
+}
+
+static void
+gst_skel_tag_fisbone_finalize (GObject * object)
+{
+  GObjectClass *parent_class =
+    G_OBJECT_CLASS (gst_skel_tag_fishead_parent_class);
+  GstSkelTagFisbone *fisbone = GST_SKEL_TAG_FISBONE (object);
+  
+  g_free (fisbone->content_type);
+  g_free (fisbone->encoding);
+  g_value_array_free (fisbone->headers);
+  
+  GST_CALL_PARENT (G_OBJECT_CLASS, finalize, (object));
+}
+
+static void
+gst_skel_tag_fisbone_set_property (GObject * object, guint property_id,
+    const GValue * value, GParamSpec * pspec)
+{
+  GstSkelTagFisbone *fisbone = GST_SKEL_TAG_FISBONE (object);
+
+  switch (property_id) {
+    case GST_SKEL_TAG_FISBONE_SERIALNO:
+      fisbone->serialno = g_value_get_uint (value);
+      break;
+    case GST_SKEL_TAG_FISBONE_GRANULERATE_N:
+      fisbone->granulerate_n = g_value_get_int64 (value);
+      break;
+    case GST_SKEL_TAG_FISBONE_GRANULERATE_D:
+      fisbone->granulerate_d = g_value_get_int64 (value);
+      break;
+    case GST_SKEL_TAG_FISBONE_START_GRANULE:
+      fisbone->start_granule = g_value_get_int64 (value);
+      break;
+    case GST_SKEL_TAG_FISBONE_PREROLL:
+      fisbone->preroll = g_value_get_uint64 (value);
+      break;
+    case GST_SKEL_TAG_FISBONE_GRANULESHIFT:
+      fisbone->granuleshift = g_value_get_uint (value);
+      break;
+    case GST_SKEL_TAG_FISBONE_HEADERS:
+    {
+      GValueArray *va;
+
+      va = g_value_get_boxed (value);
+      if (fisbone->headers)
+        g_value_array_free (fisbone->headers);
+      fisbone->headers = va != NULL ? g_value_array_copy (va) : NULL;
+      break;
+    }
+    case GST_SKEL_TAG_FISBONE_CONTENT_TYPE:
+      g_free (fisbone->content_type);
+      fisbone->content_type = g_value_dup_string (value);
+      break;
+    case GST_SKEL_TAG_FISBONE_ENCODING:
+      g_free (fisbone->encoding);
+      fisbone->encoding = g_value_dup_string (value);
+      break;
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+  }
+}
+
+static void
+gst_skel_tag_fisbone_get_property (GObject * object, guint property_id,
+    GValue * value, GParamSpec * pspec)
+{
+  GstSkelTagFisbone *fisbone = GST_SKEL_TAG_FISBONE (object);
+
+  switch (property_id) {
+    case GST_SKEL_TAG_FISBONE_SERIALNO:
+      g_value_set_uint (value, fisbone->serialno);
+      break;
+    case GST_SKEL_TAG_FISBONE_GRANULERATE_N:
+      g_value_set_int64 (value, fisbone->granulerate_n);
+      break;
+    case GST_SKEL_TAG_FISBONE_GRANULERATE_D:
+      g_value_set_int64 (value, fisbone->granulerate_d);
+      break;
+    case GST_SKEL_TAG_FISBONE_START_GRANULE:
+      g_value_set_int64 (value, fisbone->start_granule);
+      break;
+    case GST_SKEL_TAG_FISBONE_GRANULESHIFT:
+      g_value_set_uint (value, fisbone->granuleshift);
+      break;
+    case GST_SKEL_TAG_FISBONE_PREROLL:
+      g_value_set_uint64 (value, fisbone->preroll);
+      break;
+    case GST_SKEL_TAG_FISBONE_HEADERS:
+      g_value_set_boxed (value, fisbone->headers);
+      break;
+    case GST_SKEL_TAG_FISBONE_CONTENT_TYPE:
+      g_value_set_string (value, fisbone->content_type);
+      break;
+    case GST_SKEL_TAG_FISBONE_ENCODING:
+      g_value_set_string (value, fisbone->encoding);
+      break;
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+  }
+}
+

=== added file 'gst/annodex/gstskeltag.h'
--- /dev/null
+++ gst/annodex/gstskeltag.h
@@ -0,0 +1,101 @@
+/*
+ * gstskeltag.h - (VL_UNRESOLVED)
+ * Copyright (C) 2005 (VL_UNRESOLVED)
+ * 
+ * Authors:
+ *   Alessandro Decina <alessandro@nnva.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_SKEL_TAG_H__
+#define __GST_SKEL_TAG_H__
+
+#include <gst/gst.h>
+
+/* GstSkelTagFishead */
+#define GST_TYPE_SKEL_TAG_FISHEAD (gst_skel_tag_fishead_get_type ())
+#define GST_SKEL_TAG_FISHEAD(obj) \
+  (G_TYPE_CHECK_INSTANCE_CAST((obj), GST_TYPE_SKEL_TAG_FISHEAD, \
+                           GstSkelTagFishead))
+#define GST_SKEL_TAG_FISHEAD_CLASS(klass) \
+  (G_TYPE_CHECK_CLASS_CAST((klass), GST_TYPE_SKEL_TAG_FISHEAD, \
+                           GstSkelTagFishead))
+#define GST_SKEL_TAG_FISHEAD_GET_CLASS(obj) \
+  (G_TYPE_INSTANCE_GET_CLASS((obj), GST_TYPE_SKEL_TAG_FISHEAD, \
+                             GstSkelTagFisheadClass))
+
+/* GstSkelTagFisbone */
+#define GST_TYPE_SKEL_TAG_FISBONE (gst_skel_tag_fisbone_get_type ())
+#define GST_SKEL_TAG_FISBONE(obj) \
+  (G_TYPE_CHECK_INSTANCE_CAST((obj), GST_TYPE_SKEL_TAG_FISBONE, \
+                           GstSkelTagFisbone))
+#define GST_SKEL_TAG_FISBONE_CLASS(klass) \
+  (G_TYPE_CHECK_CLASS_CAST((klass), GST_TYPE_SKEL_TAG_FISBONE, \
+                           GstSkelTagFisbone))
+#define GST_SKEL_TAG_FISBONE_GET_CLASS(obj) \
+  (G_TYPE_INSTANCE_GET_CLASS((obj), GST_TYPE_SKEL_TAG_FISBONE, \
+                             GstSkelTagFisboneClass))
+
+typedef struct _GstSkelTagFishead GstSkelTagFishead;
+typedef struct _GstSkelTagFisheadClass GstSkelTagFisheadClass;
+
+typedef struct _GstSkelTagFisbone GstSkelTagFisbone;
+typedef struct _GstSkelTagFisboneClass GstSkelTagFisboneClass;
+
+
+struct _GstSkelTagFishead {
+  GObject object;
+
+  guint16 major;
+  guint16 minor;
+
+  gint64 prestime_n;
+  gint64 prestime_d;
+
+  gint64 basetime_n;
+  gint64 basetime_d;
+
+  gchar *utc;
+};
+
+struct _GstSkelTagFisheadClass {
+  GObjectClass parent_class;
+};
+
+struct _GstSkelTagFisbone {
+  GObject object;
+
+  guint32 hdr_offset;
+  guint32 serialno;
+  guint32 hdr_num;
+  gint64 granulerate_n;
+  gint64 granulerate_d;
+  gint64 start_granule;
+  guint32 preroll;
+  guint8 granuleshift;
+  gchar *content_type;
+  gchar *encoding;
+  GValueArray *headers;
+};
+
+struct _GstSkelTagFisboneClass {
+  GObjectClass parent_class;
+};
+
+GType gst_skel_tag_fishead_get_type (void);
+GType gst_skel_tag_fisbone_get_type (void);
+
+#endif /* __GST_SKEL_TAG_H__ */

=== modified file 'check/Makefile.am'
--- check/Makefile.am
+++ check/Makefile.am
@@ -19,8 +19,10 @@
 
 check_PROGRAMS = \
 	elements/level \
-    elements/matroskamux
-    
+	elements/matroskamux \
+	elements/cmmlenc \
+	elements/cmmldec \
+	elements/skeldec
 
 # these tests don't even pass
 noinst_PROGRAMS =

=== modified file 'configure.ac'
--- configure.ac
+++ configure.ac
@@ -86,6 +86,7 @@
 		videomixer \
 		wavenc \
 		wavparse \
+        annodex \
                 "
 AC_SUBST(GST_PLUGINS_ALL)
 
@@ -125,6 +126,8 @@
 dnl common/m4/gst-arch.m4
 dnl check CPU type
 GST_ARCH
+
+AC_SUBST(GST_CTRL_LIBS)
 
 dnl Determine endianness
 AC_C_BIGENDIAN
@@ -543,6 +546,7 @@
 gst/videomixer/Makefile
 gst/wavenc/Makefile
 gst/wavparse/Makefile
+gst/annodex/Makefile
 gst/flx/Makefile
 ext/jpeg/Makefile
 ext/Makefile

