Add apev2mux element (#343122).
authorSebastian Dröge <mail@slomosnail.de>
Tue, 30 May 2006 14:35:18 +0000 (14:35 +0000)
committerTim-Philipp Müller <tim@centricular.net>
Tue, 30 May 2006 14:35:18 +0000 (14:35 +0000)
Original commit message from CVS:
Patch by: Sebastian Dröge  <mail at slomosnail de >
* docs/plugins/gst-plugins-good-plugins-docs.sgml:
* docs/plugins/gst-plugins-good-plugins-sections.txt:
* ext/taglib/Makefile.am:
* ext/taglib/gstapev2mux.cc:
* ext/taglib/gstapev2mux.h:
* ext/taglib/gstid3v2mux.cc:
* ext/taglib/gsttaglibmux.c: (plugin_init):
* ext/taglib/gsttaglibmux.h:
Add apev2mux element (#343122).
* tests/check/Makefile.am:
* tests/check/elements/apev2mux.c:
(test_taglib_apev2mux_create_tags),
(test_taglib_apev2mux_check_tags), (fill_mp3_buffer), (got_buffer),
(demux_pad_added), (test_taglib_apev2mux_check_output_buffer),
(test_taglib_apev2mux_with_tags), (GST_START_TEST),
(apev2mux_suite), (main):
Add unit test for apev2mux element.

ChangeLog
docs/plugins/gst-plugins-good-plugins-docs.sgml
docs/plugins/gst-plugins-good-plugins-sections.txt
ext/taglib/Makefile.am
ext/taglib/gstapev2mux.cc [new file with mode: 0644]
ext/taglib/gstapev2mux.h [new file with mode: 0644]
ext/taglib/gstid3v2mux.cc
ext/taglib/gsttaglibmux.c
ext/taglib/gsttaglibmux.h
tests/check/Makefile.am
tests/check/elements/apev2mux.c [new file with mode: 0644]

index e1a1395..7e6f57a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,26 @@
+2006-05-30  Tim-Philipp Müller  <tim at centricular dot net>
+
+       Patch by: Sebastian Dröge  <mail at slomosnail de >
+
+       * docs/plugins/gst-plugins-good-plugins-docs.sgml:
+       * docs/plugins/gst-plugins-good-plugins-sections.txt:
+       * ext/taglib/Makefile.am:
+       * ext/taglib/gstapev2mux.cc:
+       * ext/taglib/gstapev2mux.h:
+       * ext/taglib/gstid3v2mux.cc:
+       * ext/taglib/gsttaglibmux.c: (plugin_init):
+       * ext/taglib/gsttaglibmux.h:
+         Add apev2mux element (#343122).
+       
+       * tests/check/Makefile.am:
+       * tests/check/elements/apev2mux.c:
+       (test_taglib_apev2mux_create_tags),
+       (test_taglib_apev2mux_check_tags), (fill_mp3_buffer), (got_buffer),
+       (demux_pad_added), (test_taglib_apev2mux_check_output_buffer),
+       (test_taglib_apev2mux_with_tags), (GST_START_TEST),
+       (apev2mux_suite), (main):
+         Add unit test for apev2mux element.
+
 2006-05-28  Tim-Philipp Müller  <tim at centricular dot net>
 
        * gst/alpha/gstalphacolor.c: (gst_alpha_color_transform_caps):
index acdac9c..b77f46f 100644 (file)
@@ -13,6 +13,7 @@
   <chapter>
     <title>gst-plugins-good Elements</title>
     <xi:include href="xml/element-apedemux.xml" />
+    <xi:include href="xml/element-apev2mux.xml" />
     <xi:include href="xml/element-autoaudiosink.xml" />
     <xi:include href="xml/element-autovideosink.xml" />
     <xi:include href="xml/element-avidemux.xml" />
index 7715742..8100749 100644 (file)
@@ -119,6 +119,14 @@ GstId3v2MuxClass
 </SECTION>
 
 <SECTION>
+<FILE>element-apev2mux</FILE>
+GstApev2Mux
+<TITLE>apev2mux</TITLE>
+<SUBSECTION Standard>
+GstApev2MuxClass
+</SECTION>
+
+<SECTION>
 <FILE>element-jpegdec</FILE>
 GstJpegDec
 GstJpegDecErrorMgr
index e1ffd5c..0377442 100644 (file)
@@ -1,6 +1,6 @@
 plugin_LTLIBRARIES = libgsttaglib.la
 
-libgsttaglib_la_SOURCES = gsttaglibmux.c gstid3v2mux.cc
+libgsttaglib_la_SOURCES = gsttaglibmux.c gstid3v2mux.cc gstapev2mux.cc
 libgsttaglib_la_CFLAGS = \
        $(GST_CFLAGS) \
        $(GST_PLUGINS_BASE_CFLAGS) \
@@ -15,4 +15,4 @@ libgsttaglib_la_LIBADD = \
        $(TAGLIB_LIBS)
 libgsttaglib_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
 
-noinst_HEADERS = gsttaglibmux.h gstid3v2mux.h
+noinst_HEADERS = gsttaglibmux.h gstid3v2mux.h gstapev2mux.h
diff --git a/ext/taglib/gstapev2mux.cc b/ext/taglib/gstapev2mux.cc
new file mode 100644 (file)
index 0000000..637286e
--- /dev/null
@@ -0,0 +1,382 @@
+/* GStreamer taglib-based APEv2 muxer
+ * Copyright (C) 2006 Christophe Fergeau <teuf@gnome.org>
+ * Copyright (C) 2006 Tim-Philipp Müller <tim centricular net>
+ * Copyright (C) 2006 Sebastian Dröge <mail@slomosnail.de>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+/**
+ * SECTION:element-apev2mux
+ * @see_also: #GstTagSetter
+ *
+ * <refsect2>
+ * <para>
+ * This element adds APEv2 tags to the beginning of a stream using the taglib
+ * library.
+ * </para>
+ * <para>
+ * Applications can set the tags to write using the #GstTagSetter interface.
+ * Tags sent by upstream elements will be picked up automatically (and merged
+ * according to the merge mode set via the tag setter interface).
+ * </para>
+ * <para>
+ * Here is a simple pipeline that transcodes a file from Ogg/Vorbis to mp3
+ * format with an APEv2 that contains the same as the the Ogg/Vorbis file:
+ * <programlisting>
+ * gst-launch -v filesrc location=foo.ogg ! decodebin ! audioconvert ! lame ! apev2mux ! filesink location=foo.mp3
+ * </programlisting>
+ * Make sure the Ogg/Vorbis file actually has comments to preserve.
+ * You can verify the tags were written using:
+ * <programlisting>
+ * gst-launch -m filesrc location=foo.mp3 ! apedemux ! fakesink silent=TRUE 2&gt; /dev/null | grep taglist
+ * </programlisting>
+ * </para>
+ * </refsect2>
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "gstapev2mux.h"
+
+#include <string.h>
+
+#include <apetag.h>
+#include <gst/tag/tag.h>
+
+using namespace TagLib;
+
+GST_DEBUG_CATEGORY_STATIC (gst_apev2_mux_debug);
+#define GST_CAT_DEFAULT gst_apev2_mux_debug
+
+static const GstElementDetails gst_apev2_mux_details =
+GST_ELEMENT_DETAILS ("TagLib-based APEv2 Muxer",
+    "Formatter/Metadata",
+    "Adds an APEv2 header to the beginning of files using taglib",
+    "Sebastian Dröge <mail@slomosnail.de>");
+
+static GstStaticPadTemplate src_template = GST_STATIC_PAD_TEMPLATE ("src",
+    GST_PAD_SRC,
+    GST_PAD_ALWAYS,
+    GST_STATIC_CAPS ("application/x-apetag"));
+
+
+GST_BOILERPLATE (GstApev2Mux, gst_apev2_mux, GstTagLibMux,
+    GST_TYPE_TAG_LIB_MUX);
+
+static GstBuffer *gst_apev2_mux_render_tag (GstTagLibMux * mux,
+    GstTagList * taglist);
+
+static void
+gst_apev2_mux_base_init (gpointer g_class)
+{
+  GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
+
+  gst_element_class_add_pad_template (element_class,
+      gst_static_pad_template_get (&src_template));
+
+  gst_element_class_set_details (element_class, &gst_apev2_mux_details);
+
+  GST_DEBUG_CATEGORY_INIT (gst_apev2_mux_debug, "apev2mux", 0,
+      "taglib-based APEv2 tag muxer");
+}
+
+static void
+gst_apev2_mux_class_init (GstApev2MuxClass * klass)
+{
+  GST_TAG_LIB_MUX_CLASS (klass)->render_tag =
+      GST_DEBUG_FUNCPTR (gst_apev2_mux_render_tag);
+}
+
+static void
+gst_apev2_mux_init (GstApev2Mux * apev2mux, GstApev2MuxClass * apev2mux_class)
+{
+  /* nothing to do */
+}
+
+static void
+add_one_tag (const GstTagList * list, const gchar * tag, gpointer user_data)
+{
+  APE::Tag * apev2tag = (APE::Tag *) user_data;
+  gboolean result;
+
+  /* FIXME: if there are several values set for the same tag, this won't
+   * work, only the first value will be taken into account
+   */
+  if (strcmp (tag, GST_TAG_TITLE) == 0) {
+    char *title;
+
+    result = gst_tag_list_get_string_index (list, tag, 0, &title);
+    if (result != FALSE) {
+      GST_DEBUG ("Setting title to %s", title);
+      apev2tag->setTitle (String::String (title, String::UTF8));
+    }
+    g_free (title);
+  } else if (strcmp (tag, GST_TAG_ALBUM) == 0) {
+    char *album;
+
+    result = gst_tag_list_get_string_index (list, tag, 0, &album);
+    if (result != FALSE) {
+      GST_DEBUG ("Setting album to %s", album);
+      apev2tag->setAlbum (String::String (album, String::UTF8));
+    }
+    g_free (album);
+  } else if (strcmp (tag, GST_TAG_ARTIST) == 0) {
+    char *artist;
+
+    result = gst_tag_list_get_string_index (list, tag, 0, &artist);
+    if (result != FALSE) {
+      GST_DEBUG ("Setting artist to %s", artist);
+      apev2tag->setArtist (String::String (artist, String::UTF8));
+    }
+    g_free (artist);
+  } else if (strcmp (tag, GST_TAG_GENRE) == 0) {
+    char *genre;
+
+    result = gst_tag_list_get_string_index (list, tag, 0, &genre);
+    if (result != FALSE) {
+      GST_DEBUG ("Setting genre to %s", genre);
+      apev2tag->setGenre (String::String (genre, String::UTF8));
+    }
+    g_free (genre);
+  } else if (strcmp (tag, GST_TAG_COMMENT) == 0) {
+    char *comment;
+
+    result = gst_tag_list_get_string_index (list, tag, 0, &comment);
+    if (result != FALSE) {
+      GST_DEBUG ("Setting comment to %s", comment);
+      apev2tag->setComment (String::String (comment, String::UTF8));
+    }
+    g_free (comment);
+  } else if (strcmp (tag, GST_TAG_DATE) == 0) {
+    GDate *date;
+
+    result = gst_tag_list_get_date_index (list, tag, 0, &date);
+    if (result != FALSE) {
+      GDateYear year;
+
+      year = g_date_get_year (date);
+      GST_DEBUG ("Setting track year to %d", year);
+      apev2tag->setYear (year);
+      g_date_free (date);
+    }
+  } else if (strcmp (tag, GST_TAG_TRACK_NUMBER) == 0) {
+    guint track_number;
+
+    result = gst_tag_list_get_uint_index (list, tag, 0, &track_number);
+    if (result != FALSE) {
+      guint total_tracks;
+
+      result = gst_tag_list_get_uint_index (list, GST_TAG_TRACK_COUNT,
+          0, &total_tracks);
+      if (result) {
+        gchar *tag_str;
+
+        tag_str = g_strdup_printf ("%d/%d", track_number, total_tracks);
+        GST_DEBUG ("Setting track number to %s", tag_str);
+        apev2tag->addValue (String::String ("TRACK", String::UTF8),
+            String::String (tag_str, String::UTF8), true);
+        g_free (tag_str);
+      } else {
+        GST_DEBUG ("Setting track number to %d", track_number);
+        apev2tag->setTrack (track_number);
+      }
+    }
+  } else if (strcmp (tag, GST_TAG_TRACK_COUNT) == 0) {
+    guint n;
+
+    if (gst_tag_list_get_uint_index (list, GST_TAG_TRACK_NUMBER, 0, &n)) {
+      GST_DEBUG ("track-count handled with track-number, skipping");
+    } else if (gst_tag_list_get_uint_index (list, GST_TAG_TRACK_COUNT, 0, &n)) {
+      gchar *tag_str;
+
+      tag_str = g_strdup_printf ("0/%d", n);
+      GST_DEBUG ("Setting track number to %s", tag_str);
+      apev2tag->addValue (String::String ("TRACK", String::UTF8),
+          String::String (tag_str, String::UTF8), true);
+      g_free (tag_str);
+    }
+#if 0
+  } else if (strcmp (tag, GST_TAG_ALBUM_VOLUME_NUMBER) == 0) {
+    guint volume_number;
+
+    result = gst_tag_list_get_uint_index (list, tag, 0, &volume_number);
+
+    if (result != FALSE) {
+      guint volume_count;
+      gchar *tag_str;
+
+      result = gst_tag_list_get_uint_index (list, GST_TAG_ALBUM_VOLUME_COUNT,
+          0, &volume_count);
+
+      if (result) {
+        tag_str = g_strdup_printf ("CD %d/%d", volume_number, volume_count);
+      } else {
+        tag_str = g_strdup_printf ("CD %d", volume_number);
+      }
+
+      GST_DEBUG ("Setting album number to %s", tag_str);
+
+      apev2tag->addValue (String::String ("MEDIA", String::UTF8),
+          String::String (tag_str, String::UTF8), true);
+      g_free (tag_str);
+    }
+  } else if (strcmp (tag, GST_TAG_ALBUM_VOLUME_COUNT) == 0) {
+    guint n;
+
+    if (gst_tag_list_get_uint_index (list, GST_TAG_ALBUM_VOLUME_NUMBER, 0, &n)) {
+      GST_DEBUG ("volume-count handled with volume-number, skipping");
+    } else if (gst_tag_list_get_uint_index (list, GST_TAG_ALBUM_VOLUME_COUNT,
+            0, &n)) {
+      gchar *tag_str;
+
+      tag_str = g_strdup_printf ("CD 0/%u", n);
+      GST_DEBUG ("Setting album volume number/count to %s", tag_str);
+
+      apev2tag->addValue (String::String ("MEDIA", String::UTF8),
+          String::String (tag_str, String::UTF8), true);
+      g_free (tag_str);
+    }
+#endif
+  } else if (strcmp (tag, GST_TAG_COPYRIGHT) == 0) {
+    gchar *copyright;
+
+    result = gst_tag_list_get_string_index (list, tag, 0, &copyright);
+
+    if (result != FALSE) {
+      GST_DEBUG ("Setting copyright to %s", copyright);
+      apev2tag->addValue (String::String ("COPYRIGHT", String::UTF8),
+          String::String (copyright, String::UTF8), true);
+      g_free (copyright);
+    }
+  } else if (strcmp (tag, GST_TAG_LOCATION) == 0) {
+    gchar *location;
+
+    result = gst_tag_list_get_string_index (list, tag, 0, &location);
+
+    if (result != FALSE) {
+      GST_DEBUG ("Setting location to %s", location);
+      apev2tag->addValue (String::String ("FILE", String::UTF8),
+          String::String (location, String::UTF8), true);
+      g_free (location);
+    }
+  } else if (strcmp (tag, GST_TAG_ISRC) == 0) {
+    gchar *isrc;
+
+    result = gst_tag_list_get_string_index (list, tag, 0, &isrc);
+
+    if (result != FALSE) {
+      GST_DEBUG ("Setting ISRC to %s", isrc);
+      apev2tag->addValue (String::String ("ISRC", String::UTF8),
+          String::String (isrc, String::UTF8), true);
+      g_free (isrc);
+    }
+  } else if (strcmp (tag, GST_TAG_TRACK_GAIN) == 0) {
+    gdouble value;
+
+    result = gst_tag_list_get_double_index (list, tag, 0, &value);
+
+    if (result != FALSE) {
+      gchar *track_gain = (gchar *) g_malloc0 (G_ASCII_DTOSTR_BUF_SIZE);
+
+      track_gain = g_ascii_dtostr (track_gain, G_ASCII_DTOSTR_BUF_SIZE, value);
+      GST_DEBUG ("Setting track gain to %s", track_gain);
+      apev2tag->addValue (String::String ("REPLAYGAIN_TRACK_GAIN",
+              String::UTF8), String::String (track_gain, String::UTF8), true);
+      g_free (track_gain);
+    }
+  } else if (strcmp (tag, GST_TAG_TRACK_PEAK) == 0) {
+    gdouble value;
+
+    result = gst_tag_list_get_double_index (list, tag, 0, &value);
+
+    if (result != FALSE) {
+      gchar *track_peak = (gchar *) g_malloc0 (G_ASCII_DTOSTR_BUF_SIZE);
+
+      track_peak = g_ascii_dtostr (track_peak, G_ASCII_DTOSTR_BUF_SIZE, value);
+      GST_DEBUG ("Setting track peak to %s", track_peak);
+      apev2tag->addValue (String::String ("REPLAYGAIN_TRACK_PEAK",
+              String::UTF8), String::String (track_peak, String::UTF8), true);
+      g_free (track_peak);
+    }
+  } else if (strcmp (tag, GST_TAG_ALBUM_GAIN) == 0) {
+    gdouble value;
+
+    result = gst_tag_list_get_double_index (list, tag, 0, &value);
+
+    if (result != FALSE) {
+      gchar *album_gain = (gchar *) g_malloc0 (G_ASCII_DTOSTR_BUF_SIZE);
+
+      album_gain = g_ascii_dtostr (album_gain, G_ASCII_DTOSTR_BUF_SIZE, value);
+      GST_DEBUG ("Setting album gain to %s", album_gain);
+      apev2tag->addValue (String::String ("REPLAYGAIN_ALBUM_GAIN",
+              String::UTF8), String::String (album_gain, String::UTF8), true);
+      g_free (album_gain);
+    }
+  } else if (strcmp (tag, GST_TAG_ALBUM_PEAK) == 0) {
+    gdouble value;
+
+    result = gst_tag_list_get_double_index (list, tag, 0, &value);
+
+    if (result != FALSE) {
+      gchar *album_peak = (gchar *) g_malloc0 (G_ASCII_DTOSTR_BUF_SIZE);
+
+      album_peak = g_ascii_dtostr (album_peak, G_ASCII_DTOSTR_BUF_SIZE, value);
+      GST_DEBUG ("Setting album peak to %s", album_peak);
+      apev2tag->addValue (String::String ("REPLAYGAIN_ALBUM_PEAK",
+              String::UTF8), String::String (album_peak, String::UTF8), true);
+      g_free (album_peak);
+    }
+  } else {
+    GST_WARNING ("Unsupported tag: %s", tag);
+  }
+}
+
+static GstBuffer *
+gst_apev2_mux_render_tag (GstTagLibMux * mux, GstTagList * taglist)
+{
+  APE::Tag apev2tag;
+  ByteVector rendered_tag;
+  GstBuffer *buf;
+  guint tag_size;
+
+  /* Render the tag */
+  gst_tag_list_foreach (taglist, add_one_tag, &apev2tag);
+
+  rendered_tag = apev2tag.render ();
+  tag_size = rendered_tag.size ();
+
+  GST_LOG_OBJECT (mux, "tag size = %d bytes", tag_size);
+
+  /* Create buffer with tag */
+  buf = gst_buffer_new_and_alloc (tag_size);
+  memcpy (GST_BUFFER_DATA (buf), rendered_tag.data (), tag_size);
+  gst_buffer_set_caps (buf, GST_PAD_CAPS (mux->srcpad));
+
+  return buf;
+}
+
+gboolean
+gst_apev2_mux_plugin_init (GstPlugin * plugin)
+{
+  if (!gst_element_register (plugin, "apev2mux", GST_RANK_NONE,
+          GST_TYPE_APEV2_MUX))
+    return FALSE;
+
+  return TRUE;
+}
diff --git a/ext/taglib/gstapev2mux.h b/ext/taglib/gstapev2mux.h
new file mode 100644 (file)
index 0000000..1c05bd4
--- /dev/null
@@ -0,0 +1,55 @@
+/* GStreamer taglib-based APEv2 muxer
+ * Copyright (C) 2006 Christophe Fergeau <teuf@gnome.org>
+ * Copyright (C) 2006 Tim-Philipp Müller <tim centricular net>
+ * Copyright (C) 2006 Sebastian Dröge <mail@slomosnail.de>
+ *
+ * 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_APEV2_MUX_H
+#define GST_APEV2_MUX_H
+
+#include "gsttaglibmux.h"
+
+G_BEGIN_DECLS
+
+typedef struct _GstApev2Mux GstApev2Mux;
+typedef struct _GstApev2MuxClass GstApev2MuxClass;
+
+typedef struct _GstApev2Mux {
+  GstTagLibMux  taglibmux;
+};
+
+typedef struct _GstApev2MuxClass {
+  GstTagLibMuxClass  taglibmux_class;
+};
+
+#define GST_TYPE_APEV2_MUX \
+  (gst_apev2_mux_get_type())
+#define GST_APEV2_MUX(obj) \
+  (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_APEV2_MUX,GstApev2Mux))
+#define GST_APEV2_MUX_CLASS(klass) \
+  (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_APEV2_MUX,GstApev2MuxClass))
+#define GST_IS_APEV2_MUX(obj) \
+  (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_APEV2_MUX))
+#define GST_IS_APEV2_MUX_CLASS(klass) \
+  (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_APEV2_MUX))
+
+GType gst_apev2_mux_get_type (void);
+
+G_END_DECLS
+
+#endif /* GST_APEV2_MUX_H */
index 6427b82..0a40d9e 100644 (file)
@@ -424,8 +424,8 @@ gst_id3v2_mux_render_tag (GstTagLibMux * mux, GstTagList * taglist)
   return buf;
 }
 
-static gboolean
-plugin_init (GstPlugin * plugin)
+gboolean
+gst_id3v2_mux_plugin_init (GstPlugin * plugin)
 {
   if (!gst_element_register (plugin, "id3v2mux", GST_RANK_NONE,
           GST_TYPE_ID3V2_MUX))
@@ -435,9 +435,3 @@ plugin_init (GstPlugin * plugin)
 
   return TRUE;
 }
-
-GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
-    GST_VERSION_MINOR,
-    "taglib",
-    "Tag writing plug-in based on taglib",
-    plugin_init, VERSION, "LGPL", GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN);
index f3321d3..b0f22ea 100644 (file)
@@ -1,6 +1,7 @@
 /* GStreamer taglib-based muxer base class
  * Copyright (C) 2006 Christophe Fergeau  <teuf@gnome.org>
  * Copyright (C) 2006 Tim-Philipp Müller <tim centricular net>
+ * Copyright (C) 2006 Sebastian Dröge <mail@slomosnail.de>
 
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -386,3 +387,16 @@ gst_tag_lib_mux_change_state (GstElement * element, GstStateChange transition)
 
   return result;
 }
+
+static gboolean
+plugin_init (GstPlugin * plugin)
+{
+  return (gst_id3v2_mux_plugin_init (plugin)
+      && gst_apev2_mux_plugin_init (plugin));
+}
+
+GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
+    GST_VERSION_MINOR,
+    "taglib",
+    "Tag writing plug-in based on taglib",
+    plugin_init, VERSION, "LGPL", GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN);
index 26c9de7..d26ff30 100644 (file)
@@ -63,6 +63,8 @@ struct _GstTagLibMuxClass {
 
 /* Standard function returning type information. */
 GType gst_tag_lib_mux_get_type (void);
+gboolean gst_apev2_mux_plugin_init (GstPlugin * plugin);
+gboolean gst_id3v2_mux_plugin_init (GstPlugin * plugin);
 
 G_END_DECLS
 
index 24e4f43..057ce16 100644 (file)
@@ -16,7 +16,9 @@ CLEANFILES = core.* test-registry.xml
 clean-local: clean-local-check
 
 if USE_TAGLIB
-check_taglib = elements/id3v2mux
+check_taglib = \
+       elements/id3v2mux \
+       elements/apev2mux
 else
 check_taglib =
 endif
diff --git a/tests/check/elements/apev2mux.c b/tests/check/elements/apev2mux.c
new file mode 100644 (file)
index 0000000..c4f7661
--- /dev/null
@@ -0,0 +1,432 @@
+/* GStreamer
+ *
+ * unit test for the taglib-based apev2mux element
+ *
+ * Copyright (C) 2006 Tim-Philipp Müller  <tim centricular net>
+ * Copyright (C) 2006 Sebastian Dröge <mail@slomosnail.de>
+ *
+ * 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>
+
+#include <gst/gst.h>
+#include <string.h>
+
+#define TEST_ARTIST           "Ar T\303\255st"
+#define TEST_TITLE            "M\303\274llermilch!"
+#define TEST_ALBUM            "Boom"
+#define TEST_DATE             g_date_new_dmy(1,1,2006)
+#define TEST_TRACK_NUMBER     7
+#define TEST_TRACK_COUNT      19
+#define TEST_TRACK_GAIN       1.45
+#define TEST_ALBUM_GAIN       0.78
+
+/* for dummy mp3 frame sized MP3_FRAME_SIZE bytes,
+ * start: ff fb b0 44 00 00 08 00  00 4b 00 00 00 00 00 00 */
+static const guint8 mp3_dummyhdr[] = { 0xff, 0xfb, 0xb0, 0x44, 0x00, 0x00,
+  0x08, 0x00, 0x4b, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00
+};
+
+#define MP3_FRAME_SIZE 626
+
+static GstTagList *
+test_taglib_apev2mux_create_tags (guint32 mask)
+{
+  GstTagList *tags;
+
+  tags = gst_tag_list_new ();
+
+  if (mask & (1 << 0)) {
+    gst_tag_list_add (tags, GST_TAG_MERGE_KEEP,
+        GST_TAG_ARTIST, TEST_ARTIST, NULL);
+  }
+  if (mask & (1 << 1)) {
+    gst_tag_list_add (tags, GST_TAG_MERGE_KEEP,
+        GST_TAG_TITLE, TEST_TITLE, NULL);
+  }
+  if (mask & (1 << 2)) {
+    gst_tag_list_add (tags, GST_TAG_MERGE_KEEP,
+        GST_TAG_ALBUM, TEST_ALBUM, NULL);
+  }
+  if (mask & (1 << 3)) {
+    GDate *date;
+
+    date = TEST_DATE;
+    gst_tag_list_add (tags, GST_TAG_MERGE_KEEP, GST_TAG_DATE, date, NULL);
+    g_date_free (date);
+  }
+  if (mask & (1 << 4)) {
+    gst_tag_list_add (tags, GST_TAG_MERGE_KEEP,
+        GST_TAG_TRACK_NUMBER, TEST_TRACK_NUMBER, NULL);
+  }
+  if (mask & (1 << 5)) {
+    gst_tag_list_add (tags, GST_TAG_MERGE_KEEP,
+        GST_TAG_TRACK_COUNT, TEST_TRACK_COUNT, NULL);
+  }
+  if (mask & (1 << 6)) {
+    gst_tag_list_add (tags, GST_TAG_MERGE_KEEP,
+        GST_TAG_TRACK_GAIN, TEST_TRACK_GAIN, NULL);
+  }
+  if (mask & (1 << 7)) {
+    gst_tag_list_add (tags, GST_TAG_MERGE_KEEP,
+        GST_TAG_ALBUM_GAIN, TEST_ALBUM_GAIN, NULL);
+  }
+  if (mask & (1 << 8)) {
+  }
+  if (mask & (1 << 9)) {
+  }
+  if (mask & (1 << 10)) {
+  }
+  if (mask & (1 << 11)) {
+  }
+  if (mask & (1 << 12)) {
+  }
+  if (mask & (1 << 13)) {
+  }
+  return tags;
+}
+
+static void
+test_taglib_apev2mux_check_tags (GstTagList * tags, guint32 mask)
+{
+  if (mask & (1 << 0)) {
+    gchar *s = NULL;
+
+    fail_unless (gst_tag_list_get_string (tags, GST_TAG_ARTIST, &s));
+    fail_unless (g_str_equal (s, TEST_ARTIST));
+    g_free (s);
+  }
+  if (mask & (1 << 1)) {
+    gchar *s = NULL;
+
+    fail_unless (gst_tag_list_get_string (tags, GST_TAG_TITLE, &s));
+    fail_unless (g_str_equal (s, TEST_TITLE));
+    g_free (s);
+  }
+  if (mask & (1 << 2)) {
+    gchar *s = NULL;
+
+    fail_unless (gst_tag_list_get_string (tags, GST_TAG_ALBUM, &s));
+    fail_unless (g_str_equal (s, TEST_ALBUM));
+    g_free (s);
+  }
+  if (mask & (1 << 3)) {
+    GDate *shouldbe, *date = NULL;
+
+    shouldbe = TEST_DATE;
+    fail_unless (gst_tag_list_get_date (tags, GST_TAG_DATE, &date));
+    fail_unless (g_date_compare (shouldbe, date) == 0);
+    g_date_free (shouldbe);
+    g_date_free (date);
+  }
+  if (mask & (1 << 4)) {
+    guint num;
+
+    fail_unless (gst_tag_list_get_uint (tags, GST_TAG_TRACK_NUMBER, &num));
+    fail_unless (num == TEST_TRACK_NUMBER);
+  }
+  if (mask & (1 << 5)) {
+    guint count;
+
+    fail_unless (gst_tag_list_get_uint (tags, GST_TAG_TRACK_COUNT, &count));
+    fail_unless (count == TEST_TRACK_COUNT);
+  }
+  if (mask & (1 << 6)) {
+    gdouble gain;
+
+    fail_unless (gst_tag_list_get_double (tags, GST_TAG_TRACK_GAIN, &gain));
+    fail_unless (gain == TEST_TRACK_GAIN);
+  }
+  if (mask & (1 << 7)) {
+    gdouble gain;
+
+    fail_unless (gst_tag_list_get_double (tags, GST_TAG_ALBUM_GAIN, &gain));
+    fail_unless (gain == TEST_ALBUM_GAIN);
+  }
+  if (mask & (1 << 8)) {
+  }
+  if (mask & (1 << 9)) {
+  }
+  if (mask & (1 << 10)) {
+  }
+  if (mask & (1 << 11)) {
+  }
+  if (mask & (1 << 12)) {
+  }
+  if (mask & (1 << 13)) {
+  }
+}
+
+static void
+fill_mp3_buffer (GstElement * fakesrc, GstBuffer * buf, GstPad * pad,
+    guint64 * p_offset)
+{
+  GstCaps *caps;
+
+  fail_unless (GST_BUFFER_SIZE (buf) == MP3_FRAME_SIZE);
+
+  GST_LOG ("filling buffer with fake mp3 data, offset = %" G_GUINT64_FORMAT,
+      *p_offset);
+
+  memcpy (GST_BUFFER_DATA (buf), mp3_dummyhdr, sizeof (mp3_dummyhdr));
+  caps = gst_caps_new_simple ("audio/mpeg", "mpegversion", G_TYPE_INT, 1,
+      "layer", G_TYPE_INT, 3, NULL);
+  gst_buffer_set_caps (buf, caps);
+  gst_caps_unref (caps);
+
+  GST_BUFFER_OFFSET (buf) = *p_offset;
+  *p_offset += GST_BUFFER_SIZE (buf);
+}
+
+static void
+got_buffer (GstElement * fakesink, GstBuffer * buf, GstPad * pad,
+    GstBuffer ** p_buf)
+{
+  gint64 off;
+  guint size;
+
+  off = GST_BUFFER_OFFSET (buf);
+  size = GST_BUFFER_SIZE (buf);
+
+  GST_LOG ("got buffer, size=%u, offset=%" G_GINT64_FORMAT, size, off);
+
+  fail_unless (GST_BUFFER_OFFSET_IS_VALID (buf));
+
+  if (*p_buf == NULL || (off + size) > GST_BUFFER_SIZE (*p_buf)) {
+    GstBuffer *newbuf;
+
+    /* not very elegant, but who cares */
+    newbuf = gst_buffer_new_and_alloc (off + size);
+    if (*p_buf) {
+      memcpy (GST_BUFFER_DATA (newbuf), GST_BUFFER_DATA (*p_buf),
+          GST_BUFFER_SIZE (*p_buf));
+    }
+    memcpy (GST_BUFFER_DATA (newbuf) + off, GST_BUFFER_DATA (buf), size);
+    if (*p_buf)
+      gst_buffer_unref (*p_buf);
+    *p_buf = newbuf;
+  } else {
+    memcpy (GST_BUFFER_DATA (*p_buf) + off, GST_BUFFER_DATA (buf), size);
+  }
+}
+static void
+demux_pad_added (GstElement * apedemux, GstPad * srcpad, GstBuffer ** p_outbuf)
+{
+  GstElement *fakesink, *pipeline;
+
+  GST_LOG ("apedemux added source pad with caps %" GST_PTR_FORMAT,
+      GST_PAD_CAPS (srcpad));
+
+  pipeline = apedemux;
+  while (GST_OBJECT_PARENT (pipeline) != NULL)
+    pipeline = (GstElement *) GST_OBJECT_PARENT (pipeline);
+
+  fakesink = gst_element_factory_make ("fakesink", "fakesink");
+  g_assert (fakesink != NULL);
+
+  /* set up sink */
+  g_object_set (fakesink, "signal-handoffs", TRUE, NULL);
+  g_signal_connect (fakesink, "handoff", G_CALLBACK (got_buffer), p_outbuf);
+
+  gst_bin_add (GST_BIN (pipeline), fakesink);
+  gst_element_set_state (fakesink, GST_STATE_PLAYING);
+
+  fail_unless (gst_element_link (apedemux, fakesink));
+}
+
+static void
+test_taglib_apev2mux_check_output_buffer (GstBuffer * buf)
+{
+  guint8 *data = GST_BUFFER_DATA (buf);
+  guint size = GST_BUFFER_SIZE (buf);
+  guint off;
+
+  g_assert (size % MP3_FRAME_SIZE == 0);
+
+  for (off = 0; off < size; off += MP3_FRAME_SIZE) {
+    fail_unless (memcmp (data + off, mp3_dummyhdr, sizeof (mp3_dummyhdr)) == 0);
+  }
+}
+
+static void
+test_taglib_apev2mux_with_tags (GstTagList * tags, guint32 mask)
+{
+  GstMessage *msg;
+  GstTagList *tags_read = NULL;
+  GstElement *pipeline, *apev2mux, *apedemux, *fakesrc;
+  GstBus *bus;
+  guint64 offset;
+  GstBuffer *outbuf = NULL;
+
+  pipeline = gst_pipeline_new ("pipeline");
+  g_assert (pipeline != NULL);
+
+  fakesrc = gst_element_factory_make ("fakesrc", "fakesrc");
+  g_assert (fakesrc != NULL);
+
+  apev2mux = gst_element_factory_make ("apev2mux", "apev2mux");
+  g_assert (apev2mux != NULL);
+
+  apedemux = gst_element_factory_make ("apedemux", "apedemux");
+  g_assert (apedemux != NULL);
+
+  outbuf = NULL;
+  g_signal_connect (apedemux, "pad-added",
+      G_CALLBACK (demux_pad_added), &outbuf);
+
+  gst_bin_add (GST_BIN (pipeline), fakesrc);
+  gst_bin_add (GST_BIN (pipeline), apev2mux);
+  gst_bin_add (GST_BIN (pipeline), apedemux);
+
+  gst_tag_setter_merge_tags (GST_TAG_SETTER (apev2mux), tags,
+      GST_TAG_MERGE_APPEND);
+
+  gst_element_link_many (fakesrc, apev2mux, apedemux, NULL);
+
+  /* set up source */
+  g_object_set (fakesrc, "signal-handoffs", TRUE, "can-activate-pull", FALSE,
+      "filltype", 2, "sizetype", 2, "sizemax", MP3_FRAME_SIZE,
+      "num-buffers", 16, NULL);
+
+  offset = 0;
+  g_signal_connect (fakesrc, "handoff", G_CALLBACK (fill_mp3_buffer), &offset);
+
+  gst_element_set_state (pipeline, GST_STATE_PLAYING);
+  fail_unless (gst_element_get_state (pipeline, NULL, NULL,
+          -1) == GST_STATE_CHANGE_SUCCESS);
+
+  bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
+
+  GST_LOG ("Waiting for tag ...");
+  msg =
+      gst_bus_poll (bus, GST_MESSAGE_TAG | GST_MESSAGE_EOS | GST_MESSAGE_ERROR,
+      -1);
+  if (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_ERROR) {
+    GError *err;
+    gchar *dbg;
+
+    gst_message_parse_error (msg, &err, &dbg);
+    g_printerr ("ERROR from element %s: %s\n%s\n",
+        GST_OBJECT_NAME (msg->src), err->message, GST_STR_NULL (dbg));
+    g_error_free (err);
+    g_free (dbg);
+  } else if (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_EOS) {
+    g_printerr ("EOS message, but were waiting for TAGS!\n");
+  }
+  fail_unless (msg->type == GST_MESSAGE_TAG);
+
+  gst_message_parse_tag (msg, &tags_read);
+  gst_message_unref (msg);
+
+  GST_LOG ("Got tags: %" GST_PTR_FORMAT, tags_read);
+  test_taglib_apev2mux_check_tags (tags_read, mask);
+  gst_tag_list_free (tags_read);
+
+  GST_LOG ("Waiting for EOS ...");
+  msg = gst_bus_poll (bus, GST_MESSAGE_EOS | GST_MESSAGE_ERROR, -1);
+  if (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_ERROR) {
+    GError *err;
+    gchar *dbg;
+
+    gst_message_parse_error (msg, &err, &dbg);
+    g_printerr ("ERROR from element %s: %s\n%s\n",
+        GST_OBJECT_NAME (msg->src), err->message, GST_STR_NULL (dbg));
+    g_error_free (err);
+    g_free (dbg);
+  }
+  fail_unless (msg->type == GST_MESSAGE_EOS);
+  gst_message_unref (msg);
+
+  gst_object_unref (bus);
+
+  GST_LOG ("Got EOS, shutting down ...");
+  gst_element_set_state (pipeline, GST_STATE_NULL);
+  gst_object_unref (pipeline);
+
+  test_taglib_apev2mux_check_output_buffer (outbuf);
+  gst_buffer_unref (outbuf);
+
+  GST_LOG ("Done");
+}
+
+GST_START_TEST (test_apev2mux)
+{
+  GstTagList *tags;
+  gint i;
+
+  g_random_set_seed (247166295);
+
+  /* internal consistency check */
+  tags = test_taglib_apev2mux_create_tags (0xFFFFFFFF);
+  test_taglib_apev2mux_check_tags (tags, 0xFFFFFFFF);
+  gst_tag_list_free (tags);
+
+  /* now the real tests */
+  for (i = 0; i < 50; ++i) {
+    guint32 mask;
+
+    mask = g_random_int ();
+    GST_LOG ("tag mask = %08x (i=%d)", mask, i);
+
+    if (mask == 0)
+      continue;
+
+    /* create tags */
+    tags = test_taglib_apev2mux_create_tags (mask);
+    GST_LOG ("tags for mask %08x = %" GST_PTR_FORMAT, mask, tags);
+
+    /* double-check for internal consistency */
+    test_taglib_apev2mux_check_tags (tags, mask);
+
+    /* test with pipeline */
+    test_taglib_apev2mux_with_tags (tags, mask);
+
+    /* free tags */
+    gst_tag_list_free (tags);
+  }
+}
+
+GST_END_TEST;
+
+static Suite *
+apev2mux_suite (void)
+{
+  Suite *s = suite_create ("apev2mux");
+  TCase *tc_chain = tcase_create ("general");
+
+  suite_add_tcase (s, tc_chain);
+  tcase_add_test (tc_chain, test_apev2mux);
+
+  return s;
+}
+
+int
+main (int argc, char **argv)
+{
+  int nf;
+
+  Suite *s = apev2mux_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;
+}