summaryrefslogtreecommitdiffstats
path: root/gst/id3demux
diff options
context:
space:
mode:
authorJan Schmidt <thaytan@mad.scientist.com>2005-12-18 15:14:44 +0000
committerJan Schmidt <thaytan@mad.scientist.com>2005-12-18 15:14:44 +0000
commita05fc627837838ff157ab4b702674407e627c498 (patch)
tree4c4761c9fdce1b4a1eb17d24b04c53761885769e /gst/id3demux
parent3ba78f01938cff141b93018d7f7523079a256873 (diff)
configure.ac: Check for optional dependency on zlib for id3demux
Original commit message from CVS: * configure.ac: Check for optional dependency on zlib for id3demux * gst/id3demux/Makefile.am: * gst/id3demux/gstid3demux.c: (gst_gst_id3demux_get_type), (gst_id3demux_base_init), (gst_id3demux_class_init), (gst_id3demux_reset), (gst_id3demux_init), (gst_id3demux_dispose), (gst_id3demux_add_srcpad), (gst_id3demux_remove_srcpad), (gst_id3demux_trim_buffer), (gst_id3demux_chain), (gst_id3demux_set_property), (gst_id3demux_get_property), (id3demux_get_upstream_size), (gst_id3demux_srcpad_event), (gst_id3demux_read_id3v1), (gst_id3demux_read_id3v2), (gst_id3demux_sink_activate), (gst_id3demux_src_activate_pull), (gst_id3demux_src_checkgetrange), (gst_id3demux_read_range), (gst_id3demux_src_getrange), (gst_id3demux_change_state), (gst_id3demux_pad_query), (gst_id3demux_get_query_types), (simple_find_peek), (simple_find_suggest), (gst_id3demux_do_typefind), (gst_id3demux_send_tag_event), (plugin_init): * gst/id3demux/gstid3demux.h: * gst/id3demux/id3tags.c: (read_synch_uint), (id3demux_read_id3v1_tag), (id3demux_read_id3v2_tag), (id3demux_id3v2_frame_hdr_size), (convert_fid_to_v240), (id3demux_id3v2_frames_to_tag_list): * gst/id3demux/id3tags.h: * gst/id3demux/id3v2.4.0-frames.txt: * gst/id3demux/id3v2.4.0-structure.txt: * gst/id3demux/id3v2frames.c: (id3demux_id3v2_parse_frame), (parse_comment_frame), (parse_text_identification_frame), (id3v2_tag_to_taglist), (parse_split_strings): All new LGPL id3 demuxer. Can use zlib for compressed frames, otherwise it discards them. Works on my test files. * gst/wavparse/gstwavparse.c: (gst_wavparse_loop): Don't send EOS to a non-existing srcpad The debug category can be static
Diffstat (limited to 'gst/id3demux')
-rw-r--r--gst/id3demux/Makefile.am8
-rw-r--r--gst/id3demux/gstid3demux.c1086
-rw-r--r--gst/id3demux/gstid3demux.h79
-rw-r--r--gst/id3demux/id3tags.c431
-rw-r--r--gst/id3demux/id3tags.h112
-rw-r--r--gst/id3demux/id3v2.4.0-frames.txt1734
-rw-r--r--gst/id3demux/id3v2.4.0-structure.txt733
-rw-r--r--gst/id3demux/id3v2frames.c382
8 files changed, 4565 insertions, 0 deletions
diff --git a/gst/id3demux/Makefile.am b/gst/id3demux/Makefile.am
new file mode 100644
index 00000000..afb79c31
--- /dev/null
+++ b/gst/id3demux/Makefile.am
@@ -0,0 +1,8 @@
+plugin_LTLIBRARIES = libgstid3demux.la
+
+libgstid3demux_la_SOURCES = gstid3demux.c id3tags.c id3v2frames.c
+libgstid3demux_la_CFLAGS = $(GST_PLUGINS_BASE_CFLAGS) $(GST_CFLAGS)
+libgstid3demux_la_LIBADD = $(GST_PLUGINS_BASE_LIBS) -lgsttag-@GST_MAJORMINOR@ $(ZLIB_LIBS)
+libgstid3demux_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
+
+noinst_HEADERS = gstid3demux.h id3tags.h
diff --git a/gst/id3demux/gstid3demux.c b/gst/id3demux/gstid3demux.c
new file mode 100644
index 00000000..4a7a370d
--- /dev/null
+++ b/gst/id3demux/gstid3demux.c
@@ -0,0 +1,1086 @@
+/* -*- Mode: C; tab-width: 2; indent-tabs-mode: t; c-basic-offset: 2 -*- */
+/* Copyright 2005 Jan Schmidt <thaytan@mad.scientist.com>
+ * Copyright (C) 2003-2004 Benjamin Otte <otte@gnome.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 <gst/gst.h>
+#include <gst/gst-i18n-plugin.h>
+
+#include "gstid3demux.h"
+#include "id3tags.h"
+
+enum
+{
+ ARG_0,
+ ARG_PREFER_V1
+};
+
+/* Require at least 4kB of data before we attempt typefind.
+ * Seems a decent value based on test files
+ * 40kB is massive overkill for the maximum, I think, but it
+ * doesn't do any harm */
+#define ID3_TYPE_FIND_MIN_SIZE 4096
+#define ID3_TYPE_FIND_MAX_SIZE 40960
+
+GST_DEBUG_CATEGORY (id3demux_debug);
+#define GST_CAT_DEFAULT (id3demux_debug)
+
+static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink",
+ GST_PAD_SINK,
+ GST_PAD_ALWAYS,
+ GST_STATIC_CAPS ("application/x-id3")
+ );
+
+static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src",
+ GST_PAD_SRC,
+ GST_PAD_SOMETIMES,
+ GST_STATIC_CAPS ("ANY")
+ );
+
+static void gst_id3demux_class_init (GstID3DemuxClass * klass);
+static void gst_id3demux_base_init (GstID3DemuxClass * klass);
+static void gst_id3demux_init (GstID3Demux * id3demux);
+static void gst_id3demux_dispose (GObject * object);
+
+static void gst_id3demux_set_property (GObject * object, guint prop_id,
+ const GValue * value, GParamSpec * pspec);
+static void gst_id3demux_get_property (GObject * object, guint prop_id,
+ GValue * value, GParamSpec * pspec);
+
+static GstFlowReturn gst_id3demux_chain (GstPad * pad, GstBuffer * buf);
+
+static gboolean gst_id3demux_src_activate_pull (GstPad * pad, gboolean active);
+static GstFlowReturn gst_id3demux_read_range (GstID3Demux * id3demux,
+ guint64 offset, guint length, GstBuffer ** buffer);
+
+static gboolean gst_id3demux_src_checkgetrange (GstPad * srcpad);
+static GstFlowReturn gst_id3demux_src_getrange (GstPad * srcpad,
+ guint64 offset, guint length, GstBuffer ** buffer);
+
+static gboolean gst_id3demux_add_srcpad (GstID3Demux * id3demux,
+ GstCaps * new_caps);
+static gboolean gst_id3demux_remove_srcpad (GstID3Demux * id3demux);
+
+static gboolean gst_id3demux_srcpad_event (GstPad * pad, GstEvent * event);
+static gboolean gst_id3demux_sink_activate (GstPad * sinkpad);
+static GstStateChangeReturn gst_id3demux_change_state (GstElement * element,
+ GstStateChange transition);
+static gboolean gst_id3demux_pad_query (GstPad * pad, GstQuery * query);
+static const GstQueryType *gst_id3demux_get_query_types (GstPad * pad);
+static gboolean id3demux_get_upstream_size (GstID3Demux * id3demux);
+static GstCaps *gst_id3demux_do_typefind (GstID3Demux * id3demux,
+ GstBuffer * buffer);
+static void gst_id3demux_send_tag_event (GstID3Demux * id3demux);
+
+static GstElementClass *parent_class = NULL;
+
+GType
+gst_gst_id3demux_get_type (void)
+{
+ static GType plugin_type = 0;
+
+ if (!plugin_type) {
+ static const GTypeInfo plugin_info = {
+ sizeof (GstID3DemuxClass),
+ (GBaseInitFunc) gst_id3demux_base_init,
+ NULL,
+ (GClassInitFunc) gst_id3demux_class_init,
+ NULL,
+ NULL,
+ sizeof (GstID3Demux),
+ 0,
+ (GInstanceInitFunc) gst_id3demux_init,
+ };
+ plugin_type = g_type_register_static (GST_TYPE_ELEMENT,
+ "GstID3Demux", &plugin_info, 0);
+ }
+ return plugin_type;
+}
+
+static void
+gst_id3demux_base_init (GstID3DemuxClass * klass)
+{
+ static GstElementDetails plugin_details = {
+ "GStreamer ID3 Demuxer",
+ "Codec/Demuxer/Metadata",
+ "ID3 tag reader and demuxer",
+ "Jan Schmidt <thaytan@mad.scientist.com>"
+ };
+ GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
+
+ gst_element_class_add_pad_template (element_class,
+ gst_static_pad_template_get (&src_factory));
+ gst_element_class_add_pad_template (element_class,
+ gst_static_pad_template_get (&sink_factory));
+ gst_element_class_set_details (element_class, &plugin_details);
+}
+
+static void
+gst_id3demux_class_init (GstID3DemuxClass * klass)
+{
+ GObjectClass *gobject_class;
+ GstElementClass *gstelement_class;
+
+ gobject_class = (GObjectClass *) klass;
+ gstelement_class = (GstElementClass *) klass;
+
+ parent_class = g_type_class_ref (GST_TYPE_ELEMENT);
+
+ gobject_class->dispose = gst_id3demux_dispose;
+
+ gobject_class->set_property = gst_id3demux_set_property;
+ gobject_class->get_property = gst_id3demux_get_property;
+
+ gstelement_class->change_state = gst_id3demux_change_state;
+
+ g_object_class_install_property (gobject_class, ARG_PREFER_V1,
+ g_param_spec_boolean ("prefer-v1", "Prefer version 1 tag",
+ "Prefer tags from ID3v1 tag at end of file", FALSE,
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+}
+
+static void
+gst_id3demux_reset (GstID3Demux * id3demux)
+{
+ id3demux->strip_start = 0;
+ id3demux->strip_end = 0;
+ id3demux->upstream_size = -1;
+ id3demux->state = GST_ID3DEMUX_READID3V2;
+ id3demux->send_tag_event = FALSE;
+
+ gst_buffer_replace (&(id3demux->collect), NULL);
+ gst_caps_replace (&(id3demux->src_caps), NULL);
+
+ gst_id3demux_remove_srcpad (id3demux);
+
+ if (id3demux->event_tags) {
+ gst_tag_list_free (id3demux->event_tags);
+ id3demux->event_tags = NULL;
+ }
+ if (id3demux->parsed_tags) {
+ gst_tag_list_free (id3demux->parsed_tags);
+ id3demux->parsed_tags = NULL;
+ }
+
+}
+
+static void
+gst_id3demux_init (GstID3Demux * id3demux)
+{
+ GstElementClass *klass = GST_ELEMENT_GET_CLASS (id3demux);
+
+ id3demux->sinkpad =
+ gst_pad_new_from_template (gst_element_class_get_pad_template (klass,
+ "sink"), "sink");
+ gst_pad_set_activate_function (id3demux->sinkpad,
+ GST_DEBUG_FUNCPTR (gst_id3demux_sink_activate));
+ gst_pad_set_chain_function (id3demux->sinkpad,
+ GST_DEBUG_FUNCPTR (gst_id3demux_chain));
+ gst_element_add_pad (GST_ELEMENT (id3demux), id3demux->sinkpad);
+
+ id3demux->prefer_v1 = FALSE;
+ gst_id3demux_reset (id3demux);
+}
+
+static void
+gst_id3demux_dispose (GObject * object)
+{
+ GstID3Demux *id3demux = GST_ID3DEMUX (object);
+
+ gst_id3demux_reset (id3demux);
+
+ G_OBJECT_CLASS (parent_class)->dispose (object);
+}
+
+static gboolean
+gst_id3demux_add_srcpad (GstID3Demux * id3demux, GstCaps * new_caps)
+{
+ GstPad *srcpad = NULL;
+
+ if (id3demux->src_caps == NULL ||
+ !gst_caps_is_equal (new_caps, id3demux->src_caps)) {
+
+ gst_caps_replace (&(id3demux->src_caps), new_caps);
+ if (id3demux->srcpad != NULL) {
+ GST_DEBUG_OBJECT (id3demux, "Changing src pad caps to %" GST_PTR_FORMAT,
+ id3demux->src_caps);
+
+ gst_pad_set_caps (id3demux->srcpad, id3demux->src_caps);
+ }
+ } else {
+ /* Caps never changed */
+ gst_caps_unref (new_caps);
+ }
+
+ if (id3demux->srcpad == NULL) {
+ srcpad = id3demux->srcpad =
+ gst_pad_new_from_template (gst_element_class_get_pad_template
+ (GST_ELEMENT_GET_CLASS (id3demux), "src"), "src");
+ g_return_val_if_fail (id3demux->srcpad != NULL, FALSE);
+
+ gst_pad_set_query_type_function (id3demux->srcpad,
+ GST_DEBUG_FUNCPTR (gst_id3demux_get_query_types));
+ gst_pad_set_query_function (id3demux->srcpad,
+ GST_DEBUG_FUNCPTR (gst_id3demux_pad_query));
+ gst_pad_set_event_function (id3demux->srcpad,
+ GST_DEBUG_FUNCPTR (gst_id3demux_srcpad_event));
+ gst_pad_set_activatepull_function (id3demux->srcpad,
+ GST_DEBUG_FUNCPTR (gst_id3demux_src_activate_pull));
+ gst_pad_set_checkgetrange_function (id3demux->srcpad,
+ GST_DEBUG_FUNCPTR (gst_id3demux_src_checkgetrange));
+ gst_pad_set_getrange_function (id3demux->srcpad,
+ GST_DEBUG_FUNCPTR (gst_id3demux_src_getrange));
+
+ gst_pad_use_fixed_caps (id3demux->srcpad);
+
+ if (id3demux->src_caps)
+ gst_pad_set_caps (id3demux->srcpad, id3demux->src_caps);
+
+ GST_DEBUG_OBJECT (id3demux, "Adding src pad with caps %" GST_PTR_FORMAT,
+ id3demux->src_caps);
+
+ gst_object_ref (id3demux->srcpad);
+ return gst_element_add_pad (GST_ELEMENT (id3demux), id3demux->srcpad);
+ }
+
+ return TRUE;
+}
+
+static gboolean
+gst_id3demux_remove_srcpad (GstID3Demux * id3demux)
+{
+ if (id3demux->srcpad != NULL) {
+ GST_DEBUG_OBJECT (id3demux, "Removing src pad");
+ g_return_val_if_fail (gst_element_remove_pad (GST_ELEMENT (id3demux),
+ id3demux->srcpad), FALSE);
+ gst_object_unref (id3demux->srcpad);
+ id3demux->srcpad = NULL;
+ }
+
+ return TRUE;
+};
+
+static gboolean
+gst_id3demux_trim_buffer (GstID3Demux * id3demux, GstBuffer ** buf_ref)
+{
+ GstBuffer *buf = *buf_ref;
+
+ guint trim_start = 0;
+ guint out_size = GST_BUFFER_SIZE (buf);
+ guint64 out_offset = GST_BUFFER_OFFSET (buf);
+ gboolean need_sub = FALSE;
+
+ /* Adjust offset and length */
+ if (!GST_BUFFER_OFFSET_IS_VALID (buf)) {
+ /* Can't change anything without an offset */
+ return TRUE;
+ }
+
+ /* If the buffer crosses the ID3v1 tag at the end of file, trim it */
+ if (id3demux->strip_end > 0) {
+ if (id3demux_get_upstream_size (id3demux)) {
+ guint64 v1tag_offset = id3demux->upstream_size - id3demux->strip_end;
+
+ if (out_offset >= v1tag_offset) {
+ GST_DEBUG_OBJECT (id3demux, "Buffer is past the end of the data");
+ goto no_out_buffer;
+ }
+
+ if (out_offset + out_size > v1tag_offset) {
+ out_size = v1tag_offset - out_offset;
+ need_sub = TRUE;
+ }
+ }
+ }
+
+ if (id3demux->strip_start > 0) {
+ /* If the buffer crosses the ID3v2 tag at the start of file, trim it */
+ if (out_offset <= id3demux->strip_start) {
+ if (out_offset + out_size <= id3demux->strip_start) {
+ GST_DEBUG_OBJECT (id3demux, "Buffer is before the start of the data");
+ goto no_out_buffer;
+ }
+
+ trim_start = id3demux->strip_start - out_offset;
+ out_size -= trim_start;
+ out_offset = 0;
+ } else {
+ out_offset -= id3demux->strip_start;
+ }
+ need_sub = TRUE;
+ }
+
+ g_assert (out_size > 0);
+
+ if (need_sub == TRUE) {
+ if (out_size != GST_BUFFER_SIZE (buf) || !gst_buffer_is_writable (buf)) {
+ GstBuffer *sub;
+
+ GST_DEBUG_OBJECT (id3demux, "Sub-buffering to trim size %d offset %"
+ G_GINT64_FORMAT " to %d offset %" G_GINT64_FORMAT,
+ GST_BUFFER_SIZE (buf), GST_BUFFER_OFFSET (buf), out_size, out_offset);
+
+ sub = gst_buffer_create_sub (buf, trim_start, out_size);
+ g_return_val_if_fail (sub != NULL, FALSE);
+ gst_buffer_unref (buf);
+ *buf_ref = buf = sub;
+ } else {
+ GST_DEBUG_OBJECT (id3demux, "Adjusting buffer from size %d offset %"
+ G_GINT64_FORMAT " to %d offset %" G_GINT64_FORMAT,
+ GST_BUFFER_SIZE (buf), GST_BUFFER_OFFSET (buf), out_size, out_offset);
+ }
+
+ GST_BUFFER_OFFSET (buf) = out_offset;
+ GST_BUFFER_OFFSET_END (buf) = out_offset + out_size;
+ gst_buffer_set_caps (buf, id3demux->src_caps);
+ }
+
+ return TRUE;
+no_out_buffer:
+ gst_buffer_unref (buf);
+ *buf_ref = NULL;
+ return TRUE;
+}
+
+static GstFlowReturn
+gst_id3demux_chain (GstPad * pad, GstBuffer * buf)
+{
+ GstID3Demux *id3demux;
+
+ id3demux = GST_ID3DEMUX (GST_PAD_PARENT (pad));
+ g_return_val_if_fail (GST_IS_ID3DEMUX (id3demux), GST_FLOW_ERROR);
+
+ if (id3demux->collect == NULL) {
+ id3demux->collect = buf;
+ } else {
+ id3demux->collect = gst_buffer_join (id3demux->collect, buf);
+ }
+ buf = NULL;
+
+ switch (id3demux->state) {
+ case GST_ID3DEMUX_READID3V2:
+ /* If we receive a buffer that's from the middle of the file,
+ * we can't read tags so move to typefinding */
+ if (GST_BUFFER_OFFSET (id3demux->collect) != 0) {
+ GST_DEBUG_OBJECT (id3demux,
+ "Received buffer from non-zero offset. Can't read tags");
+ id3demux->state = GST_ID3DEMUX_TYPEFINDING;
+ break;
+ } else {
+ ID3TagsResult tag_result;
+
+ tag_result = id3demux_read_id3v2_tag (id3demux->collect,
+ &id3demux->strip_start, &id3demux->parsed_tags);
+ if (tag_result == ID3TAGS_MORE_DATA)
+ break; /* Go get more data and try again */
+ else if (tag_result == ID3TAGS_BROKEN_TAG)
+ GST_WARNING_OBJECT (id3demux,
+ "Ignoring broken ID3v2 tag of size %d", id3demux->strip_start);
+ else
+ GST_DEBUG_OBJECT (id3demux, "Found an ID3v2 tag of size %d\n",
+ id3demux->strip_start);
+
+ id3demux->state = GST_ID3DEMUX_TYPEFINDING;
+ id3demux->send_tag_event = TRUE;
+ }
+
+ /* Fall-through */
+ case GST_ID3DEMUX_TYPEFINDING:{
+ GstCaps *caps;
+ GstBuffer *typefind_buf = NULL;
+
+ if (GST_BUFFER_SIZE (id3demux->collect) < ID3_TYPE_FIND_MIN_SIZE)
+ break; /* Go get more data first */
+
+ GST_DEBUG_OBJECT (id3demux, "Typefinding with size %d",
+ GST_BUFFER_SIZE (id3demux->collect));
+
+ /* Trim the buffer and adjust offset for typefinding */
+ typefind_buf = id3demux->collect;
+ gst_buffer_ref (typefind_buf);
+ if (!gst_id3demux_trim_buffer (id3demux, &typefind_buf))
+ return GST_FLOW_ERROR;
+
+ caps = gst_id3demux_do_typefind (id3demux, typefind_buf);
+
+ if (caps == NULL) {
+ if (GST_BUFFER_SIZE (typefind_buf) < ID3_TYPE_FIND_MAX_SIZE) {
+ /* Just break for more data */
+ gst_buffer_unref (typefind_buf);
+ return GST_FLOW_OK;
+ }
+
+ /* We failed typefind */
+ GST_ELEMENT_ERROR (id3demux, CORE, CAPS, (NULL), ("no caps found"));
+ gst_buffer_unref (typefind_buf);
+ gst_buffer_unref (id3demux->collect);
+ id3demux->collect = NULL;
+ return GST_FLOW_ERROR;
+ }
+ gst_buffer_unref (typefind_buf);
+
+ if (!gst_id3demux_add_srcpad (id3demux, caps)) {
+ GST_DEBUG_OBJECT (id3demux, "Failed to add srcpad");
+ gst_caps_unref (caps);
+ goto error;
+ }
+ gst_caps_unref (caps);
+
+ /* Move onto streaming and fall-through to push out existing
+ * data */
+ id3demux->state = GST_ID3DEMUX_STREAMING;
+ /* fall-through */
+ }
+ case GST_ID3DEMUX_STREAMING:{
+ GstBuffer *outbuf = NULL;
+
+ if (id3demux->send_tag_event) {
+ gst_id3demux_send_tag_event (id3demux);
+ id3demux->send_tag_event = FALSE;
+ }
+
+ /* Trim the buffer and adjust offset */
+ if (id3demux->collect) {
+ outbuf = id3demux->collect;
+ id3demux->collect = NULL;
+ if (!gst_id3demux_trim_buffer (id3demux, &outbuf))
+ return GST_FLOW_ERROR;
+ }
+ if (outbuf) {
+ if (G_UNLIKELY (id3demux->srcpad == NULL)) {
+ gst_buffer_unref (outbuf);
+ return GST_FLOW_ERROR;
+ }
+
+ GST_DEBUG_OBJECT (id3demux, "Pushing buffer %p", outbuf);
+ return gst_pad_push (id3demux->srcpad, outbuf);
+ }
+ }
+ }
+ return GST_FLOW_OK;
+
+error:
+ GST_DEBUG_OBJECT (id3demux, "error in chain function");
+
+ return GST_FLOW_ERROR;
+}
+
+static void
+gst_id3demux_set_property (GObject * object, guint prop_id,
+ const GValue * value, GParamSpec * pspec)
+{
+ GstID3Demux *id3demux;
+
+ g_return_if_fail (GST_IS_ID3DEMUX (object));
+ id3demux = GST_ID3DEMUX (object);
+
+ switch (prop_id) {
+ case ARG_PREFER_V1:
+ id3demux->prefer_v1 = g_value_get_boolean (value);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+gst_id3demux_get_property (GObject * object, guint prop_id,
+ GValue * value, GParamSpec * pspec)
+{
+ GstID3Demux *id3demux;
+
+ g_return_if_fail (GST_IS_ID3DEMUX (object));
+ id3demux = GST_ID3DEMUX (object);
+
+ switch (prop_id) {
+ case ARG_PREFER_V1:
+ g_value_set_boolean (value, id3demux->prefer_v1);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static gboolean
+id3demux_get_upstream_size (GstID3Demux * id3demux)
+{
+ GstQuery *query;
+ GstPad *peer = NULL;
+ GstFormat format;
+ gint64 result;
+ gboolean res = FALSE;
+
+ /* Short-cut if we already queried upstream */
+ if (id3demux->upstream_size > 0)
+ return TRUE;
+
+ if ((peer = gst_pad_get_peer (id3demux->sinkpad)) == NULL)
+ return FALSE;
+
+ query = gst_query_new_duration (GST_FORMAT_BYTES);
+ gst_query_set_duration (query, GST_FORMAT_BYTES, -1);
+
+ if (!gst_pad_query (peer, query))
+ goto out;
+
+ gst_query_parse_duration (query, &format, &result);
+
+ if (format != GST_FORMAT_BYTES || result == -1)
+ goto out;
+
+ id3demux->upstream_size = result;
+ res = TRUE;
+
+out:
+ gst_object_unref (peer);
+ return res;
+}
+
+static gboolean
+gst_id3demux_srcpad_event (GstPad * pad, GstEvent * event)
+{
+ gboolean res = FALSE;
+ GstID3Demux *id3demux = GST_ID3DEMUX (GST_PAD_PARENT (pad));
+
+ /* Handle SEEK events, with adjusted byte offsets and sizes. */
+
+ switch (GST_EVENT_TYPE (event)) {
+ case GST_EVENT_SEEK:
+ {
+ gdouble rate;
+ GstFormat format;
+ GstSeekType cur_type, stop_type;
+ GstSeekFlags flags;
+ gint64 cur, stop;
+
+ gst_event_parse_seek (event, &rate, &format, &flags,
+ &cur_type, &cur, &stop_type, &stop);
+
+ if (format == GST_FORMAT_BYTES &&
+ id3demux->state == GST_ID3DEMUX_STREAMING &&
+ gst_pad_is_linked (id3demux->sinkpad)) {
+ GstEvent *upstream;
+
+ switch (cur_type) {
+ case GST_SEEK_TYPE_SET:
+ cur += id3demux->strip_start;
+ break;
+ case GST_SEEK_TYPE_CUR:
+ break;
+ case GST_SEEK_TYPE_END:
+ cur += id3demux->strip_end;
+ break;
+ default:
+ g_assert_not_reached ();
+ break;
+ }
+ switch (stop_type) {
+ case GST_SEEK_TYPE_SET:
+ stop += id3demux->strip_start;
+ break;
+ case GST_SEEK_TYPE_CUR:
+ break;
+ case GST_SEEK_TYPE_END:
+ stop += id3demux->strip_end;
+ break;
+ default:
+ break;
+ }
+ upstream = gst_event_new_seek (rate, format, flags,
+ cur_type, cur, stop_type, stop);
+ res = gst_pad_push_event (id3demux->sinkpad, upstream);
+ }
+ break;
+ }
+ default:
+ break;
+ }
+
+ gst_event_unref (event);
+ return res;
+}
+
+/* Read and interpret any ID3v1 tag when activating in pull_range */
+static gboolean
+gst_id3demux_read_id3v1 (GstID3Demux * id3demux, GstTagList ** tags)
+{
+ GstBuffer *buffer = NULL;
+ gboolean res = FALSE;
+ ID3TagsResult tag_res;
+ GstFlowReturn flow_ret;
+ guint64 id3v1_offset;
+
+ if (id3demux->upstream_size < ID3V1_TAG_SIZE)
+ return TRUE;
+ id3v1_offset = id3demux->upstream_size - ID3V1_TAG_SIZE;
+
+ flow_ret = gst_pad_pull_range (id3demux->sinkpad, id3v1_offset,
+ ID3V1_TAG_SIZE, &buffer);
+ if (flow_ret != GST_FLOW_OK) {
+ GST_DEBUG_OBJECT (id3demux,
+ "Could not read data from start of file ret=%d", flow_ret);
+ goto beach;
+ }
+
+ if (GST_BUFFER_SIZE (buffer) != ID3V1_TAG_SIZE) {
+ GST_DEBUG_OBJECT (id3demux,
+ "Only managed to read %u bytes from file - not an ID3 file",
+ GST_BUFFER_SIZE (buffer));
+ goto beach;
+ }
+
+ tag_res = id3demux_read_id3v1_tag (buffer, &id3demux->strip_end, tags);
+ if (tag_res == ID3TAGS_READ_TAG) {
+ GST_DEBUG_OBJECT (id3demux, "Read ID3v1 tag");
+ res = TRUE;
+ } else if (tag_res == ID3TAGS_BROKEN_TAG) {
+ GST_WARNING_OBJECT (id3demux, "Ignoring broken ID3v1 tag");
+ res = TRUE;
+ }
+beach:
+ if (buffer)
+ gst_buffer_unref (buffer);
+ return res;
+}
+
+/* Read and interpret any ID3v2 tag when activating in pull_range */
+static gboolean
+gst_id3demux_read_id3v2 (GstID3Demux * id3demux, GstTagList ** tags)
+{
+ GstBuffer *buffer = NULL;
+ gboolean res = FALSE;
+ ID3TagsResult tag_res;
+ GstFlowReturn flow_ret;
+
+ /* Handle ID3V2 tag. Try with 4kB to start with */
+ flow_ret = gst_pad_pull_range (id3demux->sinkpad, 0, 4096, &buffer);
+ if (flow_ret != GST_FLOW_OK) {
+ GST_DEBUG_OBJECT (id3demux,
+ "Could not read data from start of file ret=%d", flow_ret);
+ goto beach;
+ }
+
+ if (GST_BUFFER_SIZE (buffer) < ID3V2_HDR_SIZE) {
+ GST_DEBUG_OBJECT (id3demux,
+ "Only managed to read %u bytes from file - not an ID3 file",
+ GST_BUFFER_SIZE (buffer));
+ goto beach;
+ }
+
+ tag_res = id3demux_read_id3v2_tag (buffer, &id3demux->strip_start, tags);
+ if (tag_res == ID3TAGS_MORE_DATA) {
+ /* Need more data to interpret the tag */
+ if (buffer) {
+ gst_buffer_unref (buffer);
+ buffer = NULL;
+ }
+ g_assert (id3demux->strip_start > ID3V2_HDR_SIZE);
+
+ GST_DEBUG_OBJECT (id3demux, "Reading %u bytes to decode ID3v2",
+ id3demux->strip_start);
+ flow_ret = gst_pad_pull_range (id3demux->sinkpad, 0, id3demux->strip_start,
+ &buffer);
+ if (flow_ret != GST_FLOW_OK) {
+ GST_DEBUG_OBJECT (id3demux,
+ "Could not read data from start of file ret=%d", flow_ret);
+ goto beach;
+ }
+ tag_res = id3demux_read_id3v2_tag (buffer, &id3demux->strip_start, tags);
+ }
+
+ if (tag_res == ID3TAGS_READ_TAG) {
+ res = TRUE;
+ GST_DEBUG_OBJECT (id3demux, "Read ID3v2 tag of size %d",
+ id3demux->strip_start);
+ } else if (tag_res == ID3TAGS_BROKEN_TAG) {
+ res = TRUE;
+ GST_WARNING_OBJECT (id3demux, "Ignoring broken ID3v2 tag of size %d",
+ id3demux->strip_start);
+ }
+beach:
+ if (buffer)
+ gst_buffer_unref (buffer);
+ return res;
+}
+
+/* This function operates similarly to gst_type_find_element_activate
+ * in the typefind element
+ * 1. try to activate in pull mode. if not, switch to push and succeed.
+ * 2. try to read tags in pull mode
+ * 3. typefind the contents
+ * 4. deactivate pull mode.
+ * 5. if we didn't find any caps, fail.
+ * 6. Add the srcpad
+ * 7. if the sink pad is activated, we are in pull mode. succeed.
+ * otherwise activate both pads in push mode and succeed.
+ */
+static gboolean
+gst_id3demux_sink_activate (GstPad * sinkpad)
+{
+ GstID3Demux *id3demux = GST_ID3DEMUX (GST_PAD_PARENT (sinkpad));
+ gboolean ret = FALSE;
+ GstBuffer *buf = NULL;
+ GstCaps *caps = NULL;
+ GstFlowReturn flow_ret;
+
+ /* 1: */
+ /* If we can activate pull_range upstream, then read any ID3v1 and ID3v2
+ * tags, otherwise activate in push mode and the chain function will
+ * collect buffers, read the ID3v2 tag and output a buffer to end
+ * preroll.
+ */
+ if (!gst_pad_check_pull_range (sinkpad) ||
+ !gst_pad_activate_pull (sinkpad, TRUE)) {
+ GST_DEBUG_OBJECT (id3demux,
+ "No pull mode. Changing to push, but won't be able to read ID3v1 tags");
+ id3demux->state = GST_ID3DEMUX_READID3V2;
+ return gst_pad_activate_push (sinkpad, TRUE);
+ }
+
+ /* Look for tags at start and end of file */
+ GST_DEBUG_OBJECT (id3demux, "Activated pull mode. Looking for tags");
+ if (!id3demux_get_upstream_size (id3demux))
+ return FALSE;
+
+ id3demux->strip_start = 0;
+ id3demux->strip_end = 0;
+
+
+ if (id3demux->prefer_v1) {
+ if (!gst_id3demux_read_id3v2 (id3demux, &(id3demux->parsed_tags)))
+ return FALSE;
+ if (!gst_id3demux_read_id3v1 (id3demux, &(id3demux->parsed_tags)))
+ return FALSE;
+ } else {
+ if (!gst_id3demux_read_id3v1 (id3demux, &(id3demux->parsed_tags)))
+ return FALSE;
+ if (!gst_id3demux_read_id3v2 (id3demux, &(id3demux->parsed_tags)))
+ return FALSE;
+ }
+ if (id3demux->parsed_tags != NULL) {
+ id3demux->send_tag_event = TRUE;
+ }
+
+ flow_ret =
+ gst_id3demux_read_range (id3demux, 0, ID3_TYPE_FIND_MAX_SIZE, &buf);
+ if (flow_ret != GST_FLOW_OK) {
+ GST_DEBUG_OBJECT (id3demux, "Could not read data from start of file ret=%d",
+ flow_ret);
+ goto done_activate;
+ }
+
+ caps = gst_id3demux_do_typefind (id3demux, buf);
+ gst_buffer_unref (buf);
+ buf = NULL;
+
+ /* 4 - Deactivate pull mode */
+ if (!gst_pad_activate_pull (sinkpad, FALSE)) {
+ if (caps)
+ gst_caps_unref (caps);
+ GST_DEBUG_OBJECT (id3demux,
+ "Could not deactivate sinkpad after reading tags");
+ return FALSE;
+ }
+
+ /* 5 - If we didn't find the caps, fail */
+ if (caps == NULL) {
+ GST_DEBUG_OBJECT (id3demux, "Could not detect type of contents");
+ goto done_activate;
+ }
+
+ /* tag reading and typefinding were already done, don't do them again in
+ the chain function if we end up in push mode */
+ id3demux->state = GST_ID3DEMUX_STREAMING;
+
+ /* 6 Add the srcpad for output now we know caps. */
+ /* add_srcpad takes ownership of the caps */
+ if (!gst_id3demux_add_srcpad (id3demux, caps)) {
+ GST_DEBUG_OBJECT (id3demux, "Could not add source pad");
+ goto done_activate;
+ }
+
+ /* 7 - if the sinkpad is active, it was done by downstream so we're
+ * done, otherwise switch to push */
+ ret = TRUE;
+ if (!gst_pad_is_active (sinkpad)) {
+ ret = gst_pad_activate_push (id3demux->srcpad, TRUE);
+ ret &= gst_pad_activate_push (sinkpad, TRUE);
+ }
+
+done_activate:
+ if (buf)
+ gst_buffer_unref (buf);
+
+ return ret;
+}
+
+static gboolean
+gst_id3demux_src_activate_pull (GstPad * pad, gboolean active)
+{
+ GstID3Demux *id3demux = GST_ID3DEMUX (GST_PAD_PARENT (pad));
+
+ return gst_pad_activate_pull (id3demux->sinkpad, active);
+}
+
+static gboolean
+gst_id3demux_src_checkgetrange (GstPad * srcpad)
+{
+ GstID3Demux *id3demux = GST_ID3DEMUX (GST_PAD_PARENT (srcpad));
+
+ return gst_pad_check_pull_range (id3demux->sinkpad);
+}
+
+static GstFlowReturn
+gst_id3demux_read_range (GstID3Demux * id3demux,
+ guint64 offset, guint length, GstBuffer ** buffer)
+{
+ GstFlowReturn ret;
+ guint64 in_offset;
+ guint in_length;
+
+ g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
+
+ /* Adjust offset and length of the request to trim off ID3 information.
+ * For the returned buffer, adjust the output offset to match what downstream
+ * should see */
+ in_offset = offset + id3demux->strip_start;
+
+ if (!id3demux_get_upstream_size (id3demux))
+ return GST_FLOW_ERROR;
+
+ if (in_offset + length >= id3demux->upstream_size - id3demux->strip_end)
+ in_length = id3demux->upstream_size - id3demux->strip_end - in_offset;
+ else
+ in_length = length;
+
+ ret = gst_pad_pull_range (id3demux->sinkpad, in_offset, in_length, buffer);
+
+ if (ret == GST_FLOW_OK && *buffer) {
+ if (!gst_id3demux_trim_buffer (id3demux, buffer))
+ goto error;
+ }
+
+ return ret;
+error:
+ if (*buffer != NULL) {
+ gst_buffer_unref (buffer);
+ *buffer = NULL;
+ }
+ return GST_FLOW_ERROR;
+}
+
+static GstFlowReturn
+gst_id3demux_src_getrange (GstPad * srcpad,
+ guint64 offset, guint length, GstBuffer ** buffer)
+{
+ GstID3Demux *id3demux = GST_ID3DEMUX (GST_PAD_PARENT (srcpad));
+
+ if (id3demux->send_tag_event) {
+ gst_id3demux_send_tag_event (id3demux);
+ id3demux->send_tag_event = FALSE;
+ }
+ return gst_id3demux_read_range (id3demux, offset, length, buffer);
+}
+
+static GstStateChangeReturn
+gst_id3demux_change_state (GstElement * element, GstStateChange transition)
+{
+ GstStateChangeReturn ret;
+ GstID3Demux *id3demux = GST_ID3DEMUX (element);
+
+ ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
+
+ switch (transition) {
+ case GST_STATE_CHANGE_PAUSED_TO_READY:
+ gst_id3demux_reset (id3demux);
+ break;
+ default:
+ break;
+ }
+ return ret;
+}
+
+static gboolean
+gst_id3demux_pad_query (GstPad * pad, GstQuery * query)
+{
+ /* For a position or duration query, adjust the returned
+ * bytes to strip off the id3v1 and id3v2 areas */
+
+ GstID3Demux *id3demux = GST_ID3DEMUX (GST_PAD_PARENT (pad));
+ GstPad *peer = NULL;
+ GstFormat format;
+ gint64 result;
+
+ if ((peer = gst_pad_get_peer (id3demux->sinkpad)) == NULL)
+ return FALSE;
+
+ if (!gst_pad_query (peer, query)) {
+ gst_object_unref (peer);
+ return FALSE;
+ }
+
+ gst_object_unref (peer);
+
+ switch (GST_QUERY_TYPE (query)) {
+ case GST_QUERY_POSITION:
+ {
+ gst_query_parse_position (query, &format, &result);
+ if (format == GST_FORMAT_BYTES) {
+ result -= id3demux->strip_start;
+ gst_query_set_position (query, format, result);
+ }
+ break;
+ }
+ case GST_QUERY_DURATION:
+ {
+ gst_query_parse_duration (query, &format, &result);
+ if (format == GST_FORMAT_BYTES) {
+ result -= id3demux->strip_start + id3demux->strip_end;
+ gst_query_set_duration (query, format, result);
+ }
+ break;
+ }
+ default:
+ break;
+ }
+
+ return TRUE;
+}
+
+static const GstQueryType *
+gst_id3demux_get_query_types (GstPad * pad)
+{
+ static const GstQueryType types[] = {
+ GST_QUERY_POSITION,
+ GST_QUERY_DURATION,
+ 0
+ };
+
+ return types;
+}
+
+typedef struct
+{
+ guint best_probability;
+ GstCaps *caps;
+ GstBuffer *buffer;
+}
+
+SimpleTypeFind;
+guint8 *
+simple_find_peek (gpointer data, gint64 offset, guint size)
+{
+ SimpleTypeFind *find = (SimpleTypeFind *) data;
+
+ if (offset < 0)
+ return NULL;
+
+ if (GST_BUFFER_SIZE (find->buffer) >= offset + size) {
+ return GST_BUFFER_DATA (find->buffer) + offset;
+ }
+ return NULL;
+}
+static void
+simple_find_suggest (gpointer data, guint probability, const GstCaps * caps)
+{
+ SimpleTypeFind *find = (SimpleTypeFind *) data;
+
+ if (probability > find->best_probability) {
+ GstCaps *copy = gst_caps_copy (caps);
+
+ gst_caps_replace (&find->caps, copy);
+ gst_caps_unref (copy);
+ find->best_probability = probability;
+ }
+}
+
+static GstCaps *
+gst_id3demux_do_typefind (GstID3Demux * id3demux, GstBuffer * buffer)
+{
+ GList *walk, *type_list;
+ SimpleTypeFind find;
+ GstTypeFind gst_find;
+
+ walk = type_list = gst_type_find_factory_get_list ();
+
+ find.buffer = buffer;
+ find.best_probability = 0;
+ find.caps = NULL;
+ gst_find.data = &find;
+ gst_find.peek = simple_find_peek;
+ gst_find.get_length = NULL;
+ gst_find.suggest = simple_find_suggest;
+ while (walk) {
+ GstTypeFindFactory *factory = GST_TYPE_FIND_FACTORY (walk->data);
+
+ gst_type_find_factory_call_function (factory, &gst_find);
+ if (find.best_probability >= GST_TYPE_FIND_MAXIMUM)
+ break;
+ walk = g_list_next (walk);
+ }
+ gst_plugin_feature_list_free (type_list);
+ if (find.best_probability > 0) {
+ GST_DEBUG ("Found caps %" GST_PTR_FORMAT " with buf size %u", find.caps,
+ GST_BUFFER_SIZE (buffer));
+ return find.caps;
+ }
+
+ return NULL;
+}
+
+static void
+gst_id3demux_send_tag_event (GstID3Demux * id3demux)
+{
+ /* FIXME: what's the correct merge mode? Docs need to tell... */
+ GstTagList *merged = gst_tag_list_merge (id3demux->event_tags,
+ id3demux->parsed_tags, GST_TAG_MERGE_KEEP);
+
+ if (id3demux->parsed_tags)
+ gst_element_post_message (GST_ELEMENT (id3demux),
+ gst_message_new_tag (GST_OBJECT (id3demux),
+ gst_tag_list_copy (id3demux->parsed_tags)));
+
+ if (merged) {
+ GstEvent *event = gst_event_new_tag (merged);
+
+ GST_EVENT_TIMESTAMP (event) = 0;
+ GST_DEBUG_OBJECT (id3demux, "Sending tag event on src pad");
+ gst_pad_push_event (id3demux->srcpad, event);
+ }
+}
+
+static gboolean
+plugin_init (GstPlugin * plugin)
+{
+ GST_DEBUG_CATEGORY_INIT (id3demux_debug, "id3demux", 0,
+ "GStreamer ID3 tag demuxer");
+
+ return gst_element_register (plugin, "id3demux",
+ GST_RANK_PRIMARY, GST_TYPE_ID3DEMUX);
+}
+
+GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
+ GST_VERSION_MINOR,
+ "id3demux",
+ "Demux ID3v1 and ID3v2 tags from a file",
+ plugin_init, VERSION, GST_LICENSE, GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN)
diff --git a/gst/id3demux/gstid3demux.h b/gst/id3demux/gstid3demux.h
new file mode 100644
index 00000000..46ae6f1e
--- /dev/null
+++ b/gst/id3demux/gstid3demux.h
@@ -0,0 +1,79 @@
+/* Copyright 2005 Jan Schmidt <thaytan@mad.scientist.com>
+ * Copyright (C) 2003-2004 Benjamin Otte <otte@gnome.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_ID3DEMUX_H__
+#define __GST_ID3DEMUX_H__
+
+#include <gst/gst.h>
+
+G_BEGIN_DECLS
+
+#define GST_TYPE_ID3DEMUX \
+ (gst_gst_id3demux_get_type())
+#define GST_ID3DEMUX(obj) \
+ (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_ID3DEMUX,GstID3Demux))
+#define GST_ID3DEMUX_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_ID3DEMUX,GstID3Demux))
+#define GST_IS_ID3DEMUX(obj) \
+ (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_ID3DEMUX))
+#define GST_IS_ID3DEMUX_CLASS(obj) \
+ (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_ID3DEMUX))
+
+typedef struct _GstID3Demux GstID3Demux;
+typedef struct _GstID3DemuxClass GstID3DemuxClass;
+
+typedef enum {
+ GST_ID3DEMUX_READID3V2,
+ GST_ID3DEMUX_TYPEFINDING,
+ GST_ID3DEMUX_STREAMING
+} GstID3DemuxState;
+
+struct _GstID3Demux
+{
+ GstElement element;
+
+ GstPad *sinkpad, *srcpad;
+
+ /* Number of bytes to remove from the start of file (ID3v2) */
+ guint strip_start;
+ /* Number of bytes to remove from the end of file (ID3v1) */
+ guint strip_end;
+
+ gint64 upstream_size;
+
+ GstID3DemuxState state;
+ GstBuffer *collect;
+ GstCaps *src_caps;
+
+ gboolean prefer_v1;
+ GstTagList *event_tags;
+ GstTagList *parsed_tags;
+ gboolean send_tag_event;
+};
+
+struct _GstID3DemuxClass
+{
+ GstElementClass parent_class;
+};
+
+GType gst_gst_id3demux_get_type (void);
+
+G_END_DECLS
+
+#endif /* __GST_ID3DEMUX_H__ */
diff --git a/gst/id3demux/id3tags.c b/gst/id3demux/id3tags.c
new file mode 100644
index 00000000..1cc8c14e
--- /dev/null
+++ b/gst/id3demux/id3tags.c
@@ -0,0 +1,431 @@
+/* -*- Mode: C; tab-width: 2; indent-tabs-mode: t; c-basic-offset: 2 -*- */
+/* Copyright 2005 Jan Schmidt <thaytan@mad.scientist.com>
+ * Copyright 2002,2003 Scott Wheeler <wheeler@kde.org> (portions from taglib)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <string.h>
+#include <gst/tag/tag.h>
+
+#include "id3tags.h"
+
+GST_DEBUG_CATEGORY_EXTERN (id3demux_debug);
+#define GST_CAT_DEFAULT (id3demux_debug)
+
+#define HANDLE_INVALID_SYNCSAFE
+static ID3TagsResult
+id3demux_id3v2_frames_to_tag_list (ID3TagsWorking * work, guint size);
+
+guint
+read_synch_uint (guint8 * data, guint size)
+{
+ gint i;
+ guint result = 0;
+ gint invalid = 0;
+
+ g_assert (size <= 4);
+
+ size--;
+ for (i = 0; i <= size; i++) {
+ invalid |= data[i] & 0x80;
+ result |= (data[i] & 0x7f) << ((size - i) * 7);
+ }
+
+#ifdef HANDLE_INVALID_SYNCSAFE
+ if (invalid) {
+ GST_WARNING ("Invalid synch-safe integer in ID3v2 frame "
+ "- using the actual value instead");
+ result = 0;
+ for (i = 0; i <= size; i++) {
+ result |= data[i] << ((size - i) * 8);
+ }
+ }
+#endif
+ return result;
+}
+
+ID3TagsResult
+id3demux_read_id3v1_tag (GstBuffer * buffer, guint * id3v1_size,
+ GstTagList ** tags)
+{
+ GstTagList *new_tags;
+
+ guint8 *data;
+
+ g_return_val_if_fail (buffer != NULL, ID3TAGS_V1_BAD_SIZE);
+
+ data = GST_BUFFER_DATA (buffer);
+
+ if (GST_BUFFER_SIZE (buffer) != ID3V1_TAG_SIZE)
+ return ID3TAGS_V1_BAD_SIZE;
+
+ /* Check that buffer starts with 'TAG' */
+ if (data[0] != 'T' || data[1] != 'A' || data[2] != 'G') {
+ if (id3v1_size)
+ *id3v1_size = 0;
+ GST_DEBUG ("No ID3v1 tag in data");
+ return ID3TAGS_READ_TAG;
+ }
+
+ g_return_val_if_fail (tags != NULL, ID3TAGS_READ_TAG);
+
+ new_tags = gst_tag_list_new_from_id3v1 (GST_BUFFER_DATA (buffer));
+ if (new_tags == NULL)
+ return ID3TAGS_BROKEN_TAG;
+
+ if (*tags) {
+ GstTagList *merged;
+
+ merged = gst_tag_list_merge (*tags, new_tags, GST_TAG_MERGE_REPLACE);
+ gst_tag_list_free (*tags);
+ gst_tag_list_free (new_tags);
+ *tags = merged;
+ } else
+ *tags = new_tags;
+
+ return ID3TAGS_READ_TAG;
+}
+
+ID3TagsResult
+id3demux_read_id3v2_tag (GstBuffer * buffer, guint * id3v2_size,
+ GstTagList ** tags)
+{
+ guint8 *data;
+ guint read_size;
+ ID3TagsWorking work;
+ guint8 flags;
+ ID3TagsResult result;
+ guint16 version;
+
+ g_return_val_if_fail (buffer != NULL, ID3TAGS_MORE_DATA);
+
+ if (GST_BUFFER_SIZE (buffer) < ID3V2_MARK_SIZE)
+ return ID3TAGS_MORE_DATA; /* Need more data to decide with */
+
+ data = GST_BUFFER_DATA (buffer);
+
+ /* Check for 'ID3' string at start of buffer */
+ if (data[0] != 'I' || data[1] != 'D' || data[2] != '3') {
+ if (id3v2_size)
+ *id3v2_size = 0;
+ GST_DEBUG ("No ID3v2 tag in data");
+ return ID3TAGS_READ_TAG;
+ }
+
+ /* OK, get enough data to read the entire header */
+ if (GST_BUFFER_SIZE (buffer) < ID3V2_HDR_SIZE)
+ return ID3TAGS_MORE_DATA; /* Need more data to decide with */
+
+ /* Read the version */
+ version = GST_READ_UINT16_BE (data + 3);
+
+ /* Read the flags */
+ flags = data[5];
+
+ /* Read the size from the header */
+ read_size = read_synch_uint (data + 6, 4);
+ if (read_size == 0) {
+ return ID3TAGS_BROKEN_TAG;
+ }
+ read_size += 10;
+
+ /* Expand the read size to include a footer if there is one */
+ if (flags & ID3V2_HDR_FLAG_FOOTER) {
+ read_size += 10;
+ }
+
+ if (id3v2_size)
+ *id3v2_size = read_size;
+
+ /* Validate the version. At the moment, we only support up to 2.4.0 */
+ if (ID3V2_VER_MAJOR (version) > 4 || ID3V2_VER_MINOR (version) > 0) {
+ GST_WARNING ("ID3v2 tag is from revision 2.%d.%d, "
+ "but decoder only supports 2.%d.%d. Ignoring as per spec.",
+ version >> 8, version & 0xff, ID3V2_VERSION >> 8, ID3V2_VERSION & 0xff);
+ return ID3TAGS_READ_TAG;
+ }
+ GST_DEBUG ("ID3v2 tag with revision 2.%d.%d\n", version >> 8, version & 0xff);
+
+ if (GST_BUFFER_SIZE (buffer) < read_size)
+ return ID3TAGS_MORE_DATA; /* Need more data to decode with */
+
+ g_return_val_if_fail (tags != NULL, ID3TAGS_READ_TAG);
+
+ memset (&work, 0, sizeof (ID3TagsWorking));
+ work.buffer = buffer;
+ work.hdr.version = version;
+ work.hdr.size = read_size;
+ work.hdr.flags = flags;
+ work.hdr.frame_data = GST_BUFFER_DATA (buffer) + ID3V2_HDR_SIZE;
+ if (flags & ID3V2_HDR_FLAG_FOOTER)
+ work.hdr.frame_data_size = read_size - ID3V2_HDR_SIZE - 10;
+ else
+ work.hdr.frame_data_size = read_size - ID3V2_HDR_SIZE;
+
+ result = id3demux_id3v2_frames_to_tag_list (&work, read_size);
+
+ /* Actually read the tags */
+ if (work.tags != NULL) {
+ if (*tags) {
+ GstTagList *merged;
+
+ merged = gst_tag_list_merge (*tags, work.tags, GST_TAG_MERGE_REPLACE);
+ gst_tag_list_free (*tags);
+ gst_tag_list_free (work.tags);
+ *tags = merged;
+ } else
+ *tags = work.tags;
+ }
+
+ return result;
+}
+
+static guint
+id3demux_id3v2_frame_hdr_size (guint id3v2ver)
+{
+ /* ID3v2 < 2.3.0 only had 6 byte header */
+ switch (ID3V2_VER_MAJOR (id3v2ver)) {
+ case 0:
+ case 1:
+ case 2:
+ return 6;
+ case 3:
+ case 4:
+ default:
+ return 10;
+ }
+}
+
+static const gchar *obsolete_frame_ids[] = {
+ "CRM", "EQU", "LNK", "RVA", "TIM", "TSI", /* From 2.2 */
+ "EQUA", "RVAD", "TIME", "TRDA", "TSIZ", /* From 2.3 */
+ NULL
+};
+
+const struct ID3v2FrameIDConvert
+{
+ gchar *orig;
+ gchar *new;
+} frame_id_conversions[] = {
+ /* 2.3.x frames */
+ {
+ "TDAT", "TDRC"}, {
+ "TORY", "TDOR"}, {
+ "TYER", "TDRC"},
+ /* 2.2.x frames */
+ {
+ "BUF", "RBUF"}, {
+ "CNT", "PCNT"}, {
+ "COM", "COMM"}, {
+ "CRA", "AENC"}, {
+ "ETC", "ETCO"}, {
+ "GEO", "GEOB"}, {
+ "IPL", "TIPL"}, {
+ "MCI", "MCDI"}, {
+ "MLL", "MLLT"}, {
+ "PIC", "APIC"}, {
+ "POP", "POPM"}, {
+ "REV", "RVRB"}, {
+ "SLT", "SYLT"}, {
+ "STC", "SYTC"}, {
+ "TAL", "TALB"}, {
+ "TBP", "TBPM"}, {
+ "TCM", "TCOM"}, {
+ "TCR", "TCOP"}, {
+ "TDA", "TDRC"}, {
+ "TDY", "TDLY"}, {
+ "TEN", "TENC"}, {
+ "TFT", "TFLT"}, {
+ "TKE", "TKEY"}, {
+ "TLA", "TLAN"}, {
+ "TLE", "TLEN"}, {
+ "TMT", "TMED"}, {
+ "TOA", "TOAL"}, {
+ "TOF", "TOFN"}, {
+ "TOL", "TOLY"}, {
+ "TOR", "TDOR"}, {
+ "TOT", "TOAL"}, {
+ "TP1", "TPE1"}, {
+ "TP2", "TPE2"}, {
+ "TP3", "TPE3"}, {
+ "TP4", "TPE4"}, {
+ "TPA", "TPOS"}, {
+ "TPB", "TPUB"}, {
+ "TRC", "TSRC"}, {
+ "TRD", "TDRC"}, {
+ "TRK", "TRCK"}, {
+ "TSS", "TSSE"}, {
+ "TT1", "TIT1"}, {
+ "TT2", "TIT2"}, {
+ "TT3", "TIT3"}, {
+ "TXT", "TOLY"}, {
+ "TXX", "TXXX"}, {
+ "TYE", "TDRC"}, {
+ "UFI", "UFID"}, {
+ "ULT", "USLT"}, {
+ "WAF", "WOAF"}, {
+ "WAR", "WOAR"}, {
+ "WAS", "WOAS"}, {
+ "WCM", "WCOM"}, {
+ "WCP", "WCOP"}, {
+ "WPB", "WPUB"}, {
+ "WXX", "WXXX"}, {
+ NULL, NULL}
+};
+
+static gboolean
+convert_fid_to_v240 (gchar * frame_id)
+{
+ gint i = 0;
+
+ while (obsolete_frame_ids[i] != NULL) {
+ if (strncmp (frame_id, obsolete_frame_ids[i], 5) == 0)
+ return TRUE;
+ i++;
+ }
+
+ i = 0;
+ while (frame_id_conversions[i].orig != NULL) {
+ if (strncmp (frame_id, frame_id_conversions[i].orig, 5) == 0) {
+ strcpy (frame_id, frame_id_conversions[i].new);
+ return FALSE;
+ }
+ i++;
+ }
+ return FALSE;
+}
+
+static ID3TagsResult
+id3demux_id3v2_frames_to_tag_list (ID3TagsWorking * work, guint size)
+{
+ guint frame_hdr_size;
+ gboolean read_a_frame = FALSE;
+ guint8 *start;
+
+ /* Extended header if present */
+ if (work->hdr.flags & ID3V2_HDR_FLAG_EXTHDR) {
+ work->hdr.ext_hdr_size = read_synch_uint (work->hdr.frame_data, 4);
+ if (work->hdr.ext_hdr_size < 6 ||
+ (work->hdr.ext_hdr_size) > work->hdr.frame_data_size) {
+ return ID3TAGS_BROKEN_TAG;
+ }
+ work->hdr.ext_flag_bytes = work->hdr.frame_data[4];
+ if (5 + work->hdr.ext_flag_bytes > work->hdr.frame_data_size) {
+ GST_DEBUG
+ ("Tag claims extended header, but doesn't have enough bytes. Broken tag");
+ return ID3TAGS_BROKEN_TAG;
+ }
+
+ work->hdr.ext_flag_data = work->hdr.frame_data + 5;
+ work->hdr.frame_data += work->hdr.ext_hdr_size;
+ work->hdr.frame_data_size -= work->hdr.ext_hdr_size;
+ }
+
+ start = GST_BUFFER_DATA (work->buffer);
+ frame_hdr_size = id3demux_id3v2_frame_hdr_size (work->hdr.version);
+ if (work->hdr.frame_data_size <= frame_hdr_size) {
+ GST_DEBUG ("Tag has no data frames. Broken tag");
+ return ID3TAGS_BROKEN_TAG; /* Must have at least one frame */
+ }
+
+ work->tags = gst_tag_list_new ();
+ g_return_val_if_fail (work->tags != NULL, ID3TAGS_READ_TAG);
+
+ while (work->hdr.frame_data_size > frame_hdr_size) {
+ guint frame_size = 0;
+ gchar frame_id[5] = "";
+ guint16 frame_flags = 0x0;
+ gboolean obsolete_id = FALSE;
+
+ /* Read the header */
+ switch (ID3V2_VER_MAJOR (work->hdr.version)) {
+ case 0:
+ case 1:
+ case 2:
+ frame_id[0] = work->hdr.frame_data[0];
+ frame_id[1] = work->hdr.frame_data[1];
+ frame_id[2] = work->hdr.frame_data[2];
+ frame_id[3] = 0;
+ frame_id[4] = 0;
+ obsolete_id = convert_fid_to_v240 (frame_id);
+
+ frame_size = read_synch_uint (work->hdr.frame_data + 3, 3);
+ frame_flags = 0;
+ break;
+ case 3:
+ case 4:
+ default:
+ frame_id[0] = work->hdr.frame_data[0];
+ frame_id[1] = work->hdr.frame_data[1];
+ frame_id[2] = work->hdr.frame_data[2];
+ frame_id[3] = work->hdr.frame_data[3];
+ frame_id[4] = 0;
+ frame_size = read_synch_uint (work->hdr.frame_data + 4, 4);
+ frame_flags = GST_READ_UINT16_BE (work->hdr.frame_data + 8);
+
+ if (ID3V2_VER_MAJOR (work->hdr.version) == 3) {
+ frame_flags &= ID3V2_3_FRAME_FLAGS_MASK;
+ obsolete_id = convert_fid_to_v240 (frame_id);
+ }
+ break;
+ }
+
+ work->hdr.frame_data += frame_hdr_size;
+ work->hdr.frame_data_size -= frame_hdr_size;
+
+ if (frame_size > work->hdr.frame_data_size ||
+ frame_size == 0 || strcmp (frame_id, "") == 0)
+ break; /* No more frames to read */
+
+#if 0
+ g_print
+ ("Frame @ %d (0x%02x) id %s size %d, next=%d (0x%02x) obsolete=%d\n",
+ work->hdr.frame_data - start, work->hdr.frame_data - start, frame_id,
+ frame_size, work->hdr.frame_data + frame_hdr_size + frame_size - start,
+ work->hdr.frame_data + frame_hdr_size + frame_size - start,
+ obsolete_id);
+#endif
+
+ if (!obsolete_id) {
+ /* Now, read, decompress etc the contents of the frame
+ * into a TagList entry */
+ work->cur_frame_size = frame_size;
+ work->frame_id = frame_id;
+ work->frame_flags = frame_flags;
+
+ if (id3demux_id3v2_parse_frame (work)) {
+ read_a_frame = TRUE;
+ GST_LOG ("Extracted frame with id %s", frame_id);
+ }
+ }
+ work->hdr.frame_data += frame_size;
+ work->hdr.frame_data_size -= frame_size;
+ }
+
+ if (!read_a_frame) {
+ GST_DEBUG ("Could not extract any frames from tag. Broken tag");
+ gst_tag_list_free (work->tags);
+ work->tags = NULL;
+ return ID3TAGS_BROKEN_TAG;
+ }
+
+ return ID3TAGS_READ_TAG;
+}
diff --git a/gst/id3demux/id3tags.h b/gst/id3demux/id3tags.h
new file mode 100644
index 00000000..c81cd550
--- /dev/null
+++ b/gst/id3demux/id3tags.h
@@ -0,0 +1,112 @@
+/* Copyright 2005 Jan Schmidt <thaytan@mad.scientist.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __ID3TAGS_H__
+#define __ID3TAGS_H__
+
+#include <gst/gst.h>
+
+G_BEGIN_DECLS
+
+#define ID3V1_TAG_SIZE 128
+#define ID3V2_MARK_SIZE 3
+#define ID3V2_HDR_SIZE 10
+
+typedef enum {
+ ID3TAGS_V1_BAD_SIZE,
+ ID3TAGS_MORE_DATA,
+ ID3TAGS_READ_TAG,
+ ID3TAGS_BROKEN_TAG
+} ID3TagsResult;
+
+/* From id3tags.c */
+ID3TagsResult id3demux_read_id3v1_tag (GstBuffer *buffer, guint *id3v1_size,
+ GstTagList **tags);
+ID3TagsResult id3demux_read_id3v2_tag (GstBuffer *buffer, guint *id3v2_size,
+ GstTagList **tags);
+G_END_DECLS
+
+/* Things shared by id3tags.c and id3v2frames.c */
+#define ID3V2_VERSION 0x0400
+#define ID3V2_VER_MAJOR(v) ((v) >> 8)
+#define ID3V2_VER_MINOR(v) ((v) & 0xff)
+
+typedef struct {
+ guint16 version;
+ guint8 flags;
+ guint32 size;
+
+ guint8 *frame_data;
+ guint32 frame_data_size;
+
+ guint32 ext_hdr_size;
+ guint8 ext_flag_bytes;
+ guint8 *ext_flag_data;
+} ID3v2Header;
+
+typedef struct {
+ ID3v2Header hdr;
+
+ GstBuffer *buffer;
+ GstTagList *tags;
+
+ /* Current frame decoding */
+ guint cur_frame_size;
+ gchar *frame_id;
+ guint16 frame_flags;
+
+ guint8 *parse_data;
+ guint parse_size;
+} ID3TagsWorking;
+
+enum {
+ ID3V2_HDR_FLAG_UNSYNC = 0x80,
+ ID3V2_HDR_FLAG_EXTHDR = 0x40,
+ ID3V2_HDR_FLAG_EXPERIMENTAL = 0x20,
+ ID3V2_HDR_FLAG_FOOTER = 0x10
+};
+
+enum {
+ ID3V2_EXT_FLAG_UPDATE = 0x80,
+ ID3V2_EXT_FLAG_CRC = 0x40,
+ ID3V2_EXT_FLAG_RESTRICTED = 0x20
+};
+
+enum {
+ ID3V2_FRAME_STATUS_FRAME_ALTER_PRESERVE = 0x4000,
+ ID3V2_FRAME_STATUS_FILE_ALTER_PRESERVE = 0x2000,
+ ID3V2_FRAME_STATUS_READONLY = 0x1000,
+ ID3V2_FRAME_FORMAT_GROUPING_ID = 0x0040,
+ ID3V2_FRAME_FORMAT_COMPRESSION = 0x0008,
+ ID3V2_FRAME_FORMAT_ENCRYPTION = 0x0004,
+ ID3V2_FRAME_FORMAT_UNSYNCHRONISATION = 0x0002,
+ ID3V2_FRAME_FORMAT_DATA_LENGTH_INDICATOR = 0x0001
+};
+
+#define ID3V2_3_FRAME_FLAGS_MASK \
+ (ID3V2_FRAME_STATUS_FRAME_ALTER_PRESERVE | \
+ ID3V2_FRAME_STATUS_FILE_ALTER_PRESERVE | \
+ ID3V2_FRAME_STATUS_READONLY | \
+ ID3V2_FRAME_FORMAT_GROUPING_ID | \
+ ID3V2_FRAME_FORMAT_COMPRESSION | \
+ ID3V2_FRAME_FORMAT_ENCRYPTION)
+
+/* From id3v2frames.c */
+gboolean id3demux_id3v2_parse_frame (ID3TagsWorking *work);
+
+#endif
diff --git a/gst/id3demux/id3v2.4.0-frames.txt b/gst/id3demux/id3v2.4.0-frames.txt
new file mode 100644
index 00000000..74a21bed
--- /dev/null
+++ b/gst/id3demux/id3v2.4.0-frames.txt
@@ -0,0 +1,1734 @@
+$Id$
+
+Informal standard M. Nilsson
+Document: id3v2.4.0-frames.txt 1st November 2000
+
+
+ ID3 tag version 2.4.0 - Native Frames
+
+Status of this document
+
+ This document is an informal standard and replaces the ID3v2.3.0
+ standard [ID3v2]. A formal standard will use another revision number
+ even if the content is identical to document. The contents in this
+ document may change for clarifications but never for added or altered
+ functionallity.
+
+ Distribution of this document is unlimited.
+
+
+Abstract
+
+ This document describes the frames natively supported by ID3v2.4.0,
+ which is a revised version of the ID3v2 informal standard [ID3v2.3.0]
+ version 2.3.0. The ID3v2 offers a flexible way of storing audio meta
+ information within audio file itself. The information may be
+ technical information, such as equalisation curves, as well as title,
+ performer, copyright etc.
+
+ ID3v2.4.0 is meant to be as close as possible to ID3v2.3.0 in order
+ to allow for implementations to be revised as easily as possible.
+
+
+1. Table of contents
+
+ 2. Conventions in this document
+ 3. Default flags
+ 4. Declared ID3v2 frames
+ 4.1. Unique file identifier
+ 4.2. Text information frames
+ 4.2.1. Identification frames
+ 4.2.2. Involved persons frames
+ 4.2.3. Derived and subjective properties frames
+ 4.2.4. Rights and license frames
+ 4.2.5. Other text frames
+ 4.2.6. User defined text information frame
+ 4.3. URL link frames
+ 4.3.1. URL link frames - details
+ 4.3.2. User defined URL link frame
+ 4.4. Music CD Identifier
+ 4.5. Event timing codes
+ 4.6. MPEG location lookup table
+ 4.7. Synced tempo codes
+ 4.8. Unsynchronised lyrics/text transcription
+ 4.9. Synchronised lyrics/text
+ 4.10. Comments
+ 4.11. Relative volume adjustment (2)
+ 4.12. Equalisation (2)
+ 4.13. Reverb
+ 4.14. Attached picture
+ 4.15. General encapsulated object
+ 4.16. Play counter
+ 4.17. Popularimeter
+ 4.18. Recommended buffer size
+ 4.19. Audio encryption
+ 4.20. Linked information
+ 4.21. Position synchronisation frame
+ 4.22. Terms of use
+ 4.23. Ownership frame
+ 4.24. Commercial frame
+ 4.25. Encryption method registration
+ 4.26. Group identification registration
+ 4.27. Private frame
+ 4.28. Signature frame
+ 4.29. Seek frame
+ 4.30. Audio seek point index
+ 5. Copyright
+ 6. References
+ 7. Appendix
+ A. Appendix A - Genre List from ID3v1
+ 8. Author's Address
+
+
+2. Conventions in this document
+
+ Text within "" is a text string exactly as it appears in a tag.
+ Numbers preceded with $ are hexadecimal and numbers preceded with %
+ are binary. $xx is used to indicate a byte with unknown content. %x
+ is used to indicate a bit with unknown content. The most significant
+ bit (MSB) of a byte is called 'bit 7' and the least significant bit
+ (LSB) is called 'bit 0'.
+
+ A tag is the whole tag described the ID3v2 main structure document
+ [ID3v2-strct]. A frame is a block of information in the tag. The tag
+ consists of a header, frames and optional padding. A field is a piece
+ of information; one value, a string etc. A numeric string is a string
+ that consists of the characters "0123456789" only.
+
+ The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT",
+ "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this
+ document are to be interpreted as described in RFC 2119 [KEYWORDS].
+
+
+3. Default flags
+
+ The default settings for the frames described in this document can be
+ divided into the following classes. The flags may be set differently
+ if found more suitable by the software.
+
+ 1. Discarded if tag is altered, discarded if file is altered.
+
+ None.
+
+ 2. Discarded if tag is altered, preserved if file is altered.
+
+ None.
+
+ 3. Preserved if tag is altered, discarded if file is altered.
+
+ ASPI, AENC, ETCO, EQU2, MLLT, POSS, SEEK, SYLT, SYTC, RVA2, TENC,
+ TLEN
+
+ 4. Preserved if tag is altered, preserved if file is altered.
+
+ The rest of the frames.
+
+
+4. Declared ID3v2 frames
+
+ The following frames are declared in this draft.
+
+ 4.19 AENC Audio encryption
+ 4.14 APIC Attached picture
+ 4.30 ASPI Audio seek point index
+
+ 4.10 COMM Comments
+ 4.24 COMR Commercial frame
+
+ 4.25 ENCR Encryption method registration
+ 4.12 EQU2 Equalisation (2)
+ 4.5 ETCO Event timing codes
+
+ 4.15 GEOB General encapsulated object
+ 4.26 GRID Group identification registration
+
+ 4.20 LINK Linked information
+
+ 4.4 MCDI Music CD identifier
+ 4.6 MLLT MPEG location lookup table
+
+ 4.23 OWNE Ownership frame
+
+ 4.27 PRIV Private frame
+ 4.16 PCNT Play counter
+ 4.17 POPM Popularimeter
+ 4.21 POSS Position synchronisation frame
+
+ 4.18 RBUF Recommended buffer size
+ 4.11 RVA2 Relative volume adjustment (2)
+ 4.13 RVRB Reverb
+
+ 4.29 SEEK Seek frame
+ 4.28 SIGN Signature frame
+ 4.9 SYLT Synchronised lyric/text
+ 4.7 SYTC Synchronised tempo codes
+
+ 4.2.1 TALB Album/Movie/Show title
+ 4.2.3 TBPM BPM (beats per minute)
+ 4.2.2 TCOM Composer
+ 4.2.3 TCON Content type
+ 4.2.4 TCOP Copyright message
+ 4.2.5 TDEN Encoding time
+ 4.2.5 TDLY Playlist delay
+ 4.2.5 TDOR Original release time
+ 4.2.5 TDRC Recording time
+ 4.2.5 TDRL Release time
+ 4.2.5 TDTG Tagging time
+ 4.2.2 TENC Encoded by
+ 4.2.2 TEXT Lyricist/Text writer
+ 4.2.3 TFLT File type
+ 4.2.2 TIPL Involved people list
+ 4.2.1 TIT1 Content group description
+ 4.2.1 TIT2 Title/songname/content description
+ 4.2.1 TIT3 Subtitle/Description refinement
+ 4.2.3 TKEY Initial key
+ 4.2.3 TLAN Language(s)
+ 4.2.3 TLEN Length
+ 4.2.2 TMCL Musician credits list
+ 4.2.3 TMED Media type
+ 4.2.3 TMOO Mood
+ 4.2.1 TOAL Original album/movie/show title
+ 4.2.5 TOFN Original filename
+ 4.2.2 TOLY Original lyricist(s)/text writer(s)
+ 4.2.2 TOPE Original artist(s)/performer(s)
+ 4.2.4 TOWN File owner/licensee
+ 4.2.2 TPE1 Lead performer(s)/Soloist(s)
+ 4.2.2 TPE2 Band/orchestra/accompaniment
+ 4.2.2 TPE3 Conductor/performer refinement
+ 4.2.2 TPE4 Interpreted, remixed, or otherwise modified by
+ 4.2.1 TPOS Part of a set
+ 4.2.4 TPRO Produced notice
+ 4.2.4 TPUB Publisher
+ 4.2.1 TRCK Track number/Position in set
+ 4.2.4 TRSN Internet radio station name
+ 4.2.4 TRSO Internet radio station owner
+ 4.2.5 TSOA Album sort order
+ 4.2.5 TSOP Performer sort order
+ 4.2.5 TSOT Title sort order
+ 4.2.1 TSRC ISRC (international standard recording code)
+ 4.2.5 TSSE Software/Hardware and settings used for encoding
+ 4.2.1 TSST Set subtitle
+ 4.2.2 TXXX User defined text information frame
+
+ 4.1 UFID Unique file identifier
+ 4.22 USER Terms of use
+ 4.8 USLT Unsynchronised lyric/text transcription
+
+ 4.3.1 WCOM Commercial information
+ 4.3.1 WCOP Copyright/Legal information
+ 4.3.1 WOAF Official audio file webpage
+ 4.3.1 WOAR Official artist/performer webpage
+ 4.3.1 WOAS Official audio source webpage
+ 4.3.1 WORS Official Internet radio station homepage
+ 4.3.1 WPAY Payment
+ 4.3.1 WPUB Publishers official webpage
+ 4.3.2 WXXX User defined URL link frame
+
+
+4.1. Unique file identifier
+
+ This frame's purpose is to be able to identify the audio file in a
+ database, that may provide more information relevant to the content.
+ Since standardisation of such a database is beyond this document, all
+ UFID frames begin with an 'owner identifier' field. It is a null-
+ terminated string with a URL [URL] containing an email address, or a
+ link to a location where an email address can be found, that belongs
+ to the organisation responsible for this specific database
+ implementation. Questions regarding the database should be sent to
+ the indicated email address. The URL should not be used for the
+ actual database queries. The string
+ "http://www.id3.org/dummy/ufid.html" should be used for tests. The
+ 'Owner identifier' must be non-empty (more than just a termination).
+ The 'Owner identifier' is then followed by the actual identifier,
+ which may be up to 64 bytes. There may be more than one "UFID" frame
+ in a tag, but only one with the same 'Owner identifier'.
+
+ <Header for 'Unique file identifier', ID: "UFID">
+ Owner identifier <text string> $00
+ Identifier <up to 64 bytes binary data>
+
+
+4.2. Text information frames
+
+ The text information frames are often the most important frames,
+ containing information like artist, album and more. There may only be
+ one text information frame of its kind in an tag. All text
+ information frames supports multiple strings, stored as a null
+ separated list, where null is reperesented by the termination code
+ for the charater encoding. All text frame identifiers begin with "T".
+ Only text frame identifiers begin with "T", with the exception of the
+ "TXXX" frame. All the text information frames have the following
+ format:
+
+ <Header for 'Text information frame', ID: "T000" - "TZZZ",
+ excluding "TXXX" described in 4.2.6.>
+ Text encoding $xx
+ Information <text string(s) according to encoding>
+
+
+4.2.1. Identification frames
+
+ TIT1
+ The 'Content group description' frame is used if the sound belongs to
+ a larger category of sounds/music. For example, classical music is
+ often sorted in different musical sections (e.g. "Piano Concerto",
+ "Weather - Hurricane").
+
+ TIT2
+ The 'Title/Songname/Content description' frame is the actual name of
+ the piece (e.g. "Adagio", "Hurricane Donna").
+
+ TIT3
+ The 'Subtitle/Description refinement' frame is used for information
+ directly related to the contents title (e.g. "Op. 16" or "Performed
+ live at Wembley").
+
+ TALB
+ The 'Album/Movie/Show title' frame is intended for the title of the
+ recording (or source of sound) from which the audio in the file is
+ taken.
+
+ TOAL
+ The 'Original album/movie/show title' frame is intended for the title
+ of the original recording (or source of sound), if for example the
+ music in the file should be a cover of a previously released song.
+
+ TRCK
+ The 'Track number/Position in set' frame is a numeric string
+ containing the order number of the audio-file on its original
+ recording. This MAY be extended with a "/" character and a numeric
+ string containing the total number of tracks/elements on the original
+ recording. E.g. "4/9".
+
+ TPOS
+ The 'Part of a set' frame is a numeric string that describes which
+ part of a set the audio came from. This frame is used if the source
+ described in the "TALB" frame is divided into several mediums, e.g. a
+ double CD. The value MAY be extended with a "/" character and a
+ numeric string containing the total number of parts in the set. E.g.
+ "1/2".
+
+ TSST
+ The 'Set subtitle' frame is intended for the subtitle of the part of
+ a set this track belongs to.
+
+ TSRC
+ The 'ISRC' frame should contain the International Standard Recording
+ Code [ISRC] (12 characters).
+
+
+4.2.2. Involved persons frames
+
+ TPE1
+ The 'Lead artist/Lead performer/Soloist/Performing group' is
+ used for the main artist.
+
+ TPE2
+ The 'Band/Orchestra/Accompaniment' frame is used for additional
+ information about the performers in the recording.
+
+ TPE3
+ The 'Conductor' frame is used for the name of the conductor.
+
+ TPE4
+ The 'Interpreted, remixed, or otherwise modified by' frame contains
+ more information about the people behind a remix and similar
+ interpretations of another existing piece.
+
+ TOPE
+ The 'Original artist/performer' frame is intended for the performer
+ of the original recording, if for example the music in the file
+ should be a cover of a previously released song.
+
+ TEXT
+ The 'Lyricist/Text writer' frame is intended for the writer of the
+ text or lyrics in the recording.
+
+ TOLY
+ The 'Original lyricist/text writer' frame is intended for the
+ text writer of the original recording, if for example the music in
+ the file should be a cover of a previously released song.
+
+ TCOM
+ The 'Composer' frame is intended for the name of the composer.
+
+ TMCL
+ The 'Musician credits list' is intended as a mapping between
+ instruments and the musician that played it. Every odd field is an
+ instrument and every even is an artist or a comma delimited list of
+ artists.
+
+ TIPL
+ The 'Involved people list' is very similar to the musician credits
+ list, but maps between functions, like producer, and names.
+
+ TENC
+ The 'Encoded by' frame contains the name of the person or
+ organisation that encoded the audio file. This field may contain a
+ copyright message, if the audio file also is copyrighted by the
+ encoder.
+
+
+4.2.3. Derived and subjective properties frames
+
+ TBPM
+ The 'BPM' frame contains the number of beats per minute in the
+ main part of the audio. The BPM is an integer and represented as a
+ numerical string.
+
+ TLEN
+ The 'Length' frame contains the length of the audio file in
+ milliseconds, represented as a numeric string.
+
+ TKEY
+ The 'Initial key' frame contains the musical key in which the sound
+ starts. It is represented as a string with a maximum length of three
+ characters. The ground keys are represented with "A","B","C","D","E",
+ "F" and "G" and halfkeys represented with "b" and "#". Minor is
+ represented as "m", e.g. "Dbm" $00. Off key is represented with an
+ "o" only.
+
+ TLAN
+ The 'Language' frame should contain the languages of the text or
+ lyrics spoken or sung in the audio. The language is represented with
+ three characters according to ISO-639-2 [ISO-639-2]. If more than one
+ language is used in the text their language codes should follow
+ according to the amount of their usage, e.g. "eng" $00 "sve" $00.
+
+ TCON
+ The 'Content type', which ID3v1 was stored as a one byte numeric
+ value only, is now a string. You may use one or several of the ID3v1
+ types as numerical strings, or, since the category list would be
+ impossible to maintain with accurate and up to date categories,
+ define your own. Example: "21" $00 "Eurodisco" $00
+
+ You may also use any of the following keywords:
+
+ RX Remix
+ CR Cover
+
+ TFLT
+ The 'File type' frame indicates which type of audio this tag defines.
+ The following types and refinements are defined:
+
+ MIME MIME type follows
+ MPG MPEG Audio
+ /1 MPEG 1/2 layer I
+ /2 MPEG 1/2 layer II
+ /3 MPEG 1/2 layer III
+ /2.5 MPEG 2.5
+ /AAC Advanced audio compression
+ VQF Transform-domain Weighted Interleave Vector Quantisation
+ PCM Pulse Code Modulated audio
+
+ but other types may be used, but not for these types though. This is
+ used in a similar way to the predefined types in the "TMED" frame,
+ but without parentheses. If this frame is not present audio type is
+ assumed to be "MPG".
+
+ TMED
+ The 'Media type' frame describes from which media the sound
+ originated. This may be a text string or a reference to the
+ predefined media types found in the list below. Example:
+ "VID/PAL/VHS" $00.
+
+ DIG Other digital media
+ /A Analogue transfer from media
+
+ ANA Other analogue media
+ /WAC Wax cylinder
+ /8CA 8-track tape cassette
+
+ CD CD
+ /A Analogue transfer from media
+ /DD DDD
+ /AD ADD
+ /AA AAD
+
+ LD Laserdisc
+
+ TT Turntable records
+ /33 33.33 rpm
+ /45 45 rpm
+ /71 71.29 rpm
+ /76 76.59 rpm
+ /78 78.26 rpm
+ /80 80 rpm
+
+ MD MiniDisc
+ /A Analogue transfer from media
+
+ DAT DAT
+ /A Analogue transfer from media
+ /1 standard, 48 kHz/16 bits, linear
+ /2 mode 2, 32 kHz/16 bits, linear
+ /3 mode 3, 32 kHz/12 bits, non-linear, low speed
+ /4 mode 4, 32 kHz/12 bits, 4 channels
+ /5 mode 5, 44.1 kHz/16 bits, linear
+ /6 mode 6, 44.1 kHz/16 bits, 'wide track' play
+
+ DCC DCC
+ /A Analogue transfer from media
+
+ DVD DVD
+ /A Analogue transfer from media
+
+ TV Television
+ /PAL PAL
+ /NTSC NTSC
+ /SECAM SECAM
+
+ VID Video
+ /PAL PAL
+ /NTSC NTSC
+ /SECAM SECAM
+ /VHS VHS
+ /SVHS S-VHS
+ /BETA BETAMAX
+
+ RAD Radio
+ /FM FM
+ /AM AM
+ /LW LW
+ /MW MW
+
+ TEL Telephone
+ /I ISDN
+
+ MC MC (normal cassette)
+ /4 4.75 cm/s (normal speed for a two sided cassette)
+ /9 9.5 cm/s
+ /I Type I cassette (ferric/normal)
+ /II Type II cassette (chrome)
+ /III Type III cassette (ferric chrome)
+ /IV Type IV cassette (metal)
+
+ REE Reel
+ /9 9.5 cm/s
+ /19 19 cm/s
+ /38 38 cm/s
+ /76 76 cm/s
+ /I Type I cassette (ferric/normal)
+ /II Type II cassette (chrome)
+ /III Type III cassette (ferric chrome)
+ /IV Type IV cassette (metal)
+
+ TMOO
+ The 'Mood' frame is intended to reflect the mood of the audio with a
+ few keywords, e.g. "Romantic" or "Sad".
+
+
+4.2.4. Rights and license frames
+
+ TCOP
+ The 'Copyright message' frame, in which the string must begin with a
+ year and a space character (making five characters), is intended for
+ the copyright holder of the original sound, not the audio file
+ itself. The absence of this frame means only that the copyright
+ information is unavailable or has been removed, and must not be
+ interpreted to mean that the audio is public domain. Every time this
+ field is displayed the field must be preceded with "Copyright " (C) "
+ ", where (C) is one character showing a C in a circle.
+
+ TPRO
+ The 'Produced notice' frame, in which the string must begin with a
+ year and a space character (making five characters), is intended for
+ the production copyright holder of the original sound, not the audio
+ file itself. The absence of this frame means only that the production
+ copyright information is unavailable or has been removed, and must
+ not be interpreted to mean that the audio is public domain. Every
+ time this field is displayed the field must be preceded with
+ "Produced " (P) " ", where (P) is one character showing a P in a
+ circle.
+
+ TPUB
+ The 'Publisher' frame simply contains the name of the label or
+ publisher.
+
+ TOWN
+ The 'File owner/licensee' frame contains the name of the owner or
+ licensee of the file and it's contents.
+
+ TRSN
+ The 'Internet radio station name' frame contains the name of the
+ internet radio station from which the audio is streamed.
+
+ TRSO
+ The 'Internet radio station owner' frame contains the name of the
+ owner of the internet radio station from which the audio is
+ streamed.
+
+4.2.5. Other text frames
+
+ TOFN
+ The 'Original filename' frame contains the preferred filename for the
+ file, since some media doesn't allow the desired length of the
+ filename. The filename is case sensitive and includes its suffix.
+
+ TDLY
+ The 'Playlist delay' defines the numbers of milliseconds of silence
+ that should be inserted before this audio. The value zero indicates
+ that this is a part of a multifile audio track that should be played
+ continuously.
+
+ TDEN
+ The 'Encoding time' frame contains a timestamp describing when the
+ audio was encoded. Timestamp format is described in the ID3v2
+ structure document [ID3v2-strct].
+
+ TDOR
+ The 'Original release time' frame contains a timestamp describing
+ when the original recording of the audio was released. Timestamp
+ format is described in the ID3v2 structure document [ID3v2-strct].
+
+ TDRC
+ The 'Recording time' frame contains a timestamp describing when the
+ audio was recorded. Timestamp format is described in the ID3v2
+ structure document [ID3v2-strct].
+
+ TDRL
+ The 'Release time' frame contains a timestamp describing when the
+ audio was first released. Timestamp format is described in the ID3v2
+ structure document [ID3v2-strct].
+
+ TDTG
+ The 'Tagging time' frame contains a timestamp describing then the
+ audio was tagged. Timestamp format is described in the ID3v2
+ structure document [ID3v2-strct].
+
+ TSSE
+ The 'Software/Hardware and settings used for encoding' frame
+ includes the used audio encoder and its settings when the file was
+ encoded. Hardware refers to hardware encoders, not the computer on
+ which a program was run.
+
+ TSOA
+ The 'Album sort order' frame defines a string which should be used
+ instead of the album name (TALB) for sorting purposes. E.g. an album
+ named "A Soundtrack" might preferably be sorted as "Soundtrack".
+
+ TSOP
+ The 'Performer sort order' frame defines a string which should be
+ used instead of the performer (TPE2) for sorting purposes.
+
+ TSOT
+ The 'Title sort order' frame defines a string which should be used
+ instead of the title (TIT2) for sorting purposes.
+
+
+4.2.6. User defined text information frame
+
+ This frame is intended for one-string text information concerning the
+ audio file in a similar way to the other "T"-frames. The frame body
+ consists of a description of the string, represented as a terminated
+ string, followed by the actual string. There may be more than one
+ "TXXX" frame in each tag, but only one with the same description.
+
+ <Header for 'User defined text information frame', ID: "TXXX">
+ Text encoding $xx
+ Description <text string according to encoding> $00 (00)
+ Value <text string according to encoding>
+
+
+4.3. URL link frames
+
+ With these frames dynamic data such as webpages with touring
+ information, price information or plain ordinary news can be added to
+ the tag. There may only be one URL [URL] link frame of its kind in an
+ tag, except when stated otherwise in the frame description. If the
+ text string is followed by a string termination, all the following
+ information should be ignored and not be displayed. All URL link
+ frame identifiers begins with "W". Only URL link frame identifiers
+ begins with "W", except for "WXXX". All URL link frames have the
+ following format:
+
+ <Header for 'URL link frame', ID: "W000" - "WZZZ", excluding "WXXX"
+ described in 4.3.2.>
+ URL <text string>
+
+
+4.3.1. URL link frames - details
+
+ WCOM
+ The 'Commercial information' frame is a URL pointing at a webpage
+ with information such as where the album can be bought. There may be
+ more than one "WCOM" frame in a tag, but not with the same content.
+
+ WCOP
+ The 'Copyright/Legal information' frame is a URL pointing at a
+ webpage where the terms of use and ownership of the file is
+ described.
+
+ WOAF
+ The 'Official audio file webpage' frame is a URL pointing at a file
+ specific webpage.
+
+ WOAR
+ The 'Official artist/performer webpage' frame is a URL pointing at
+ the artists official webpage. There may be more than one "WOAR" frame
+ in a tag if the audio contains more than one performer, but not with
+ the same content.
+
+ WOAS
+ The 'Official audio source webpage' frame is a URL pointing at the
+ official webpage for the source of the audio file, e.g. a movie.
+
+ WORS
+ The 'Official Internet radio station homepage' contains a URL
+ pointing at the homepage of the internet radio station.
+
+ WPAY
+ The 'Payment' frame is a URL pointing at a webpage that will handle
+ the process of paying for this file.
+
+ WPUB
+ The 'Publishers official webpage' frame is a URL pointing at the
+ official webpage for the publisher.
+
+
+4.3.2. User defined URL link frame
+
+ This frame is intended for URL [URL] links concerning the audio file
+ in a similar way to the other "W"-frames. The frame body consists
+ of a description of the string, represented as a terminated string,
+ followed by the actual URL. The URL is always encoded with ISO-8859-1
+ [ISO-8859-1]. There may be more than one "WXXX" frame in each tag,
+ but only one with the same description.
+
+ <Header for 'User defined URL link frame', ID: "WXXX">
+ Text encoding $xx
+ Description <text string according to encoding> $00 (00)
+ URL <text string>
+
+
+4.4. Music CD identifier
+
+ This frame is intended for music that comes from a CD, so that the CD
+ can be identified in databases such as the CDDB [CDDB]. The frame
+ consists of a binary dump of the Table Of Contents, TOC, from the CD,
+ which is a header of 4 bytes and then 8 bytes/track on the CD plus 8
+ bytes for the 'lead out', making a maximum of 804 bytes. The offset
+ to the beginning of every track on the CD should be described with a
+ four bytes absolute CD-frame address per track, and not with absolute
+ time. When this frame is used the presence of a valid "TRCK" frame is
+ REQUIRED, even if the CD's only got one track. It is recommended that
+ this frame is always added to tags originating from CDs. There may
+ only be one "MCDI" frame in each tag.
+
+ <Header for 'Music CD identifier', ID: "MCDI">
+ CD TOC <binary data>
+
+
+4.5. Event timing codes
+
+ This frame allows synchronisation with key events in the audio. The
+ header is:
+
+ <Header for 'Event timing codes', ID: "ETCO">
+ Time stamp format $xx
+
+ Where time stamp format is:
+
+ $01 Absolute time, 32 bit sized, using MPEG [MPEG] frames as unit
+ $02 Absolute time, 32 bit sized, using milliseconds as unit
+
+ Absolute time means that every stamp contains the time from the
+ beginning of the file.
+
+ Followed by a list of key events in the following format:
+
+ Type of event $xx
+ Time stamp $xx (xx ...)
+
+ The 'Time stamp' is set to zero if directly at the beginning of the
+ sound or after the previous event. All events MUST be sorted in
+ chronological order. The type of event is as follows:
+
+ $00 padding (has no meaning)
+ $01 end of initial silence
+ $02 intro start
+ $03 main part start
+ $04 outro start
+ $05 outro end
+ $06 verse start
+ $07 refrain start
+ $08 interlude start
+ $09 theme start
+ $0A variation start
+ $0B key change
+ $0C time change
+ $0D momentary unwanted noise (Snap, Crackle & Pop)
+ $0E sustained noise
+ $0F sustained noise end
+ $10 intro end
+ $11 main part end
+ $12 verse end
+ $13 refrain end
+ $14 theme end
+ $15 profanity
+ $16 profanity end
+
+ $17-$DF reserved for future use
+
+ $E0-$EF not predefined synch 0-F
+
+ $F0-$FC reserved for future use
+
+ $FD audio end (start of silence)
+ $FE audio file ends
+ $FF one more byte of events follows (all the following bytes with
+ the value $FF have the same function)
+
+ Terminating the start events such as "intro start" is OPTIONAL. The
+ 'Not predefined synch's ($E0-EF) are for user events. You might want
+ to synchronise your music to something, like setting off an explosion
+ on-stage, activating a screensaver etc.
+
+ There may only be one "ETCO" frame in each tag.
+
+
+4.6. MPEG location lookup table
+
+ To increase performance and accuracy of jumps within a MPEG [MPEG]
+ audio file, frames with time codes in different locations in the file
+ might be useful. This ID3v2 frame includes references that the
+ software can use to calculate positions in the file. After the frame
+ header follows a descriptor of how much the 'frame counter' should be
+ increased for every reference. If this value is two then the first
+ reference points out the second frame, the 2nd reference the 4th
+ frame, the 3rd reference the 6th frame etc. In a similar way the
+ 'bytes between reference' and 'milliseconds between reference' points
+ out bytes and milliseconds respectively.
+
+ Each reference consists of two parts; a certain number of bits, as
+ defined in 'bits for bytes deviation', that describes the difference
+ between what is said in 'bytes between reference' and the reality and
+ a certain number of bits, as defined in 'bits for milliseconds
+ deviation', that describes the difference between what is said in
+ 'milliseconds between reference' and the reality. The number of bits
+ in every reference, i.e. 'bits for bytes deviation'+'bits for
+ milliseconds deviation', must be a multiple of four. There may only
+ be one "MLLT" frame in each tag.
+
+ <Header for 'Location lookup table', ID: "MLLT">
+ MPEG frames between reference $xx xx
+ Bytes between reference $xx xx xx
+ Milliseconds between reference $xx xx xx
+ Bits for bytes deviation $xx
+ Bits for milliseconds dev. $xx
+
+ Then for every reference the following data is included;
+
+ Deviation in bytes %xxx....
+ Deviation in milliseconds %xxx....
+
+
+4.7. Synchronised tempo codes
+
+ For a more accurate description of the tempo of a musical piece, this
+ frame might be used. After the header follows one byte describing
+ which time stamp format should be used. Then follows one or more
+ tempo codes. Each tempo code consists of one tempo part and one time
+ part. The tempo is in BPM described with one or two bytes. If the
+ first byte has the value $FF, one more byte follows, which is added
+ to the first giving a range from 2 - 510 BPM, since $00 and $01 is
+ reserved. $00 is used to describe a beat-free time period, which is
+ not the same as a music-free time period. $01 is used to indicate one
+ single beat-stroke followed by a beat-free period.
+
+ The tempo descriptor is followed by a time stamp. Every time the
+ tempo in the music changes, a tempo descriptor may indicate this for
+ the player. All tempo descriptors MUST be sorted in chronological
+ order. The first beat-stroke in a time-period is at the same time as
+ the beat description occurs. There may only be one "SYTC" frame in
+ each tag.
+
+ <Header for 'Synchronised tempo codes', ID: "SYTC">
+ Time stamp format $xx
+ Tempo data <binary data>
+
+ Where time stamp format is:
+
+ $01 Absolute time, 32 bit sized, using MPEG [MPEG] frames as unit
+ $02 Absolute time, 32 bit sized, using milliseconds as unit
+
+ Absolute time means that every stamp contains the time from the
+ beginning of the file.
+
+
+4.8. Unsynchronised lyrics/text transcription
+
+ This frame contains the lyrics of the song or a text transcription of
+ other vocal activities. The head includes an encoding descriptor and
+ a content descriptor. The body consists of the actual text. The
+ 'Content descriptor' is a terminated string. If no descriptor is
+ entered, 'Content descriptor' is $00 (00) only. Newline characters
+ are allowed in the text. There may be more than one 'Unsynchronised
+ lyrics/text transcription' frame in each tag, but only one with the
+ same language and content descriptor.
+
+ <Header for 'Unsynchronised lyrics/text transcription', ID: "USLT">
+ Text encoding $xx
+ Language $xx xx xx
+ Content descriptor <text string according to encoding> $00 (00)
+ Lyrics/text <full text string according to encoding>
+
+
+4.9. Synchronised lyrics/text
+
+ This is another way of incorporating the words, said or sung lyrics,
+ in the audio file as text, this time, however, in sync with the
+ audio. It might also be used to describing events e.g. occurring on a
+ stage or on the screen in sync with the audio. The header includes a
+ content descriptor, represented with as terminated text string. If no
+ descriptor is entered, 'Content descriptor' is $00 (00) only.
+
+ <Header for 'Synchronised lyrics/text', ID: "SYLT">
+ Text encoding $xx
+ Language $xx xx xx
+ Time stamp format $xx
+ Content type $xx
+ Content descriptor <text string according to encoding> $00 (00)
+
+ Content type: $00 is other
+ $01 is lyrics
+ $02 is text transcription
+ $03 is movement/part name (e.g. "Adagio")
+ $04 is events (e.g. "Don Quijote enters the stage")
+ $05 is chord (e.g. "Bb F Fsus")
+ $06 is trivia/'pop up' information
+ $07 is URLs to webpages
+ $08 is URLs to images
+
+ Time stamp format:
+
+ $01 Absolute time, 32 bit sized, using MPEG [MPEG] frames as unit
+ $02 Absolute time, 32 bit sized, using milliseconds as unit
+
+ Absolute time means that every stamp contains the time from the
+ beginning of the file.
+
+ The text that follows the frame header differs from that of the
+ unsynchronised lyrics/text transcription in one major way. Each
+ syllable (or whatever size of text is considered to be convenient by
+ the encoder) is a null terminated string followed by a time stamp
+ denoting where in the sound file it belongs. Each sync thus has the
+ following structure:
+
+ Terminated text to be synced (typically a syllable)
+ Sync identifier (terminator to above string) $00 (00)
+ Time stamp $xx (xx ...)
+
+ The 'time stamp' is set to zero or the whole sync is omitted if
+ located directly at the beginning of the sound. All time stamps
+ should be sorted in chronological order. The sync can be considered
+ as a validator of the subsequent string.
+
+ Newline characters are allowed in all "SYLT" frames and MUST be used
+ after every entry (name, event etc.) in a frame with the content type
+ $03 - $04.
+
+ A few considerations regarding whitespace characters: Whitespace
+ separating words should mark the beginning of a new word, thus
+ occurring in front of the first syllable of a new word. This is also
+ valid for new line characters. A syllable followed by a comma should
+ not be broken apart with a sync (both the syllable and the comma
+ should be before the sync).
+
+ An example: The "USLT" passage
+
+ "Strangers in the night" $0A "Exchanging glances"
+
+ would be "SYLT" encoded as:
+
+ "Strang" $00 xx xx "ers" $00 xx xx " in" $00 xx xx " the" $00 xx xx
+ " night" $00 xx xx 0A "Ex" $00 xx xx "chang" $00 xx xx "ing" $00 xx
+ xx "glan" $00 xx xx "ces" $00 xx xx
+
+ There may be more than one "SYLT" frame in each tag, but only one
+ with the same language and content descriptor.
+
+
+4.10. Comments
+
+ This frame is intended for any kind of full text information that
+ does not fit in any other frame. It consists of a frame header
+ followed by encoding, language and content descriptors and is ended
+ with the actual comment as a text string. Newline characters are
+ allowed in the comment text string. There may be more than one
+ comment frame in each tag, but only one with the same language and
+ content descriptor.
+
+ <Header for 'Comment', ID: "COMM">
+ Text encoding $xx
+ Language $xx xx xx
+ Short content descrip. <text string according to encoding> $00 (00)
+ The actual text <full text string according to encoding>
+
+
+4.11. Relative volume adjustment (2)
+
+ This is a more subjective frame than the previous ones. It allows the
+ user to say how much he wants to increase/decrease the volume on each
+ channel when the file is played. The purpose is to be able to align
+ all files to a reference volume, so that you don't have to change the
+ volume constantly. This frame may also be used to balance adjust the
+ audio. The volume adjustment is encoded as a fixed point decibel
+ value, 16 bit signed integer representing (adjustment*512), giving
+ +/- 64 dB with a precision of 0.001953125 dB. E.g. +2 dB is stored as
+ $04 00 and -2 dB is $FC 00. There may be more than one "RVA2" frame
+ in each tag, but only one with the same identification string.
+
+ <Header for 'Relative volume adjustment (2)', ID: "RVA2">
+ Identification <text string> $00
+
+ The 'identification' string is used to identify the situation and/or
+ device where this adjustment should apply. The following is then
+ repeated for every channel
+
+ Type of channel $xx
+ Volume adjustment $xx xx
+ Bits representing peak $xx
+ Peak volume $xx (xx ...)
+
+
+ Type of channel: $00 Other
+ $01 Master volume
+ $02 Front right
+ $03 Front left
+ $04 Back right
+ $05 Back left
+ $06 Front centre
+ $07 Back centre
+ $08 Subwoofer
+
+ Bits representing peak can be any number between 0 and 255. 0 means
+ that there is no peak volume field. The peak volume field is always
+ padded to whole bytes, setting the most significant bits to zero.
+
+
+4.12. Equalisation (2)
+
+ This is another subjective, alignment frame. It allows the user to
+ predefine an equalisation curve within the audio file. There may be
+ more than one "EQU2" frame in each tag, but only one with the same
+ identification string.
+
+ <Header of 'Equalisation (2)', ID: "EQU2">
+ Interpolation method $xx
+ Identification <text string> $00
+
+ The 'interpolation method' describes which method is preferred when
+ an interpolation between the adjustment point that follows. The
+ following methods are currently defined:
+
+ $00 Band
+ No interpolation is made. A jump from one adjustment level to
+ another occurs in the middle between two adjustment points.
+ $01 Linear
+ Interpolation between adjustment points is linear.
+
+ The 'identification' string is used to identify the situation and/or
+ device where this adjustment should apply. The following is then
+ repeated for every adjustment point
+
+ Frequency $xx xx
+ Volume adjustment $xx xx
+
+ The frequency is stored in units of 1/2 Hz, giving it a range from 0
+ to 32767 Hz.
+
+ The volume adjustment is encoded as a fixed point decibel value, 16
+ bit signed integer representing (adjustment*512), giving +/- 64 dB
+ with a precision of 0.001953125 dB. E.g. +2 dB is stored as $04 00
+ and -2 dB is $FC 00.
+
+ Adjustment points should be ordered by frequency and one frequency
+ should only be described once in the frame.
+
+
+4.13. Reverb
+
+ Yet another subjective frame, with which you can adjust echoes of
+ different kinds. Reverb left/right is the delay between every bounce
+ in ms. Reverb bounces left/right is the number of bounces that should
+ be made. $FF equals an infinite number of bounces. Feedback is the
+ amount of volume that should be returned to the next echo bounce. $00
+ is 0%, $FF is 100%. If this value were $7F, there would be 50% volume
+ reduction on the first bounce, 50% of that on the second and so on.
+ Left to left means the sound from the left bounce to be played in the
+ left speaker, while left to right means sound from the left bounce to
+ be played in the right speaker.
+
+ 'Premix left to right' is the amount of left sound to be mixed in the
+ right before any reverb is applied, where $00 id 0% and $FF is 100%.
+ 'Premix right to left' does the same thing, but right to left.
+ Setting both premix to $FF would result in a mono output (if the
+ reverb is applied symmetric). There may only be one "RVRB" frame in
+ each tag.
+
+ <Header for 'Reverb', ID: "RVRB">
+ Reverb left (ms) $xx xx
+ Reverb right (ms) $xx xx
+ Reverb bounces, left $xx
+ Reverb bounces, right $xx
+ Reverb feedback, left to left $xx
+ Reverb feedback, left to right $xx
+ Reverb feedback, right to right $xx
+ Reverb feedback, right to left $xx
+ Premix left to right $xx
+ Premix right to left $xx
+
+
+4.14. Attached picture
+
+ This frame contains a picture directly related to the audio file.
+ Image format is the MIME type and subtype [MIME] for the image. In
+ the event that the MIME media type name is omitted, "image/" will be
+ implied. The "image/png" [PNG] or "image/jpeg" [JFIF] picture format
+ should be used when interoperability is wanted. Description is a
+ short description of the picture, represented as a terminated
+ text string. There may be several pictures attached to one file, each
+ in their individual "APIC" frame, but only one with the same content
+ descriptor. There may only be one picture with the picture type
+ declared as picture type $01 and $02 respectively. There is the
+ possibility to put only a link to the image file by using the 'MIME
+ type' "-->" and having a complete URL [URL] instead of picture data.
+ The use of linked files should however be used sparingly since there
+ is the risk of separation of files.
+
+ <Header for 'Attached picture', ID: "APIC">
+ Text encoding $xx
+ MIME type <text string> $00
+ Picture type $xx
+ Description <text string according to encoding> $00 (00)
+ Picture data <binary data>
+
+
+ Picture type: $00 Other
+ $01 32x32 pixels 'file icon' (PNG only)
+ $02 Other file icon
+ $03 Cover (front)
+ $04 Cover (back)
+ $05 Leaflet page
+ $06 Media (e.g. label side of CD)
+ $07 Lead artist/lead performer/soloist
+ $08 Artist/performer
+ $09 Conductor
+ $0A Band/Orchestra
+ $0B Composer
+ $0C Lyricist/text writer
+ $0D Recording Location
+ $0E During recording
+ $0F During performance
+ $10 Movie/video screen capture
+ $11 A bright coloured fish
+ $12 Illustration
+ $13 Band/artist logotype
+ $14 Publisher/Studio logotype
+
+
+4.15. General encapsulated object
+
+ In this frame any type of file can be encapsulated. After the header,
+ 'Frame size' and 'Encoding' follows 'MIME type' [MIME] represented as
+ as a terminated string encoded with ISO 8859-1 [ISO-8859-1]. The
+ filename is case sensitive and is encoded as 'Encoding'. Then follows
+ a content description as terminated string, encoded as 'Encoding'.
+ The last thing in the frame is the actual object. The first two
+ strings may be omitted, leaving only their terminations. MIME type is
+ always an ISO-8859-1 text string. There may be more than one "GEOB"
+ frame in each tag, but only one with the same content descriptor.
+
+ <Header for 'General encapsulated object', ID: "GEOB">
+ Text encoding $xx
+ MIME type <text string> $00
+ Filename <text string according to encoding> $00 (00)
+ Content description <text string according to encoding> $00 (00)
+ Encapsulated object <binary data>
+
+
+4.16. Play counter
+
+ This is simply a counter of the number of times a file has been
+ played. The value is increased by one every time the file begins to
+ play. There may only be one "PCNT" frame in each tag. When the
+ counter reaches all one's, one byte is inserted in front of the
+ counter thus making the counter eight bits bigger. The counter must
+ be at least 32-bits long to begin with.
+
+ <Header for 'Play counter', ID: "PCNT">
+ Counter $xx xx xx xx (xx ...)
+
+
+4.17. Popularimeter
+
+ The purpose of this frame is to specify how good an audio file is.
+ Many interesting applications could be found to this frame such as a
+ playlist that features better audio files more often than others or
+ it could be used to profile a person's taste and find other 'good'
+ files by comparing people's profiles. The frame contains the email
+ address to the user, one rating byte and a four byte play counter,
+ intended to be increased with one for every time the file is played.
+ The email is a terminated string. The rating is 1-255 where 1 is
+ worst and 255 is best. 0 is unknown. If no personal counter is wanted
+ it may be omitted. When the counter reaches all one's, one byte is
+ inserted in front of the counter thus making the counter eight bits
+ bigger in the same away as the play counter ("PCNT"). There may be
+ more than one "POPM" frame in each tag, but only one with the same
+ email address.
+
+ <Header for 'Popularimeter', ID: "POPM">
+ Email to user <text string> $00
+ Rating $xx
+ Counter $xx xx xx xx (xx ...)
+
+
+4.18. Recommended buffer size
+
+ Sometimes the server from which an audio file is streamed is aware of
+ transmission or coding problems resulting in interruptions in the
+ audio stream. In these cases, the size of the buffer can be
+ recommended by the server using this frame. If the 'embedded info
+ flag' is true (1) then this indicates that an ID3 tag with the
+ maximum size described in 'Buffer size' may occur in the audio
+ stream. In such case the tag should reside between two MPEG [MPEG]
+ frames, if the audio is MPEG encoded. If the position of the next tag
+ is known, 'offset to next tag' may be used. The offset is calculated
+ from the end of tag in which this frame resides to the first byte of
+ the header in the next. This field may be omitted. Embedded tags are
+ generally not recommended since this could render unpredictable
+ behaviour from present software/hardware.
+
+ For applications like streaming audio it might be an idea to embed
+ tags into the audio stream though. If the clients connects to
+ individual connections like HTTP and there is a possibility to begin
+ every transmission with a tag, then this tag should include a
+ 'recommended buffer size' frame. If the client is connected to a
+ arbitrary point in the stream, such as radio or multicast, then the
+ 'recommended buffer size' frame SHOULD be included in every tag.
+
+ The 'Buffer size' should be kept to a minimum. There may only be one
+ "RBUF" frame in each tag.
+
+ <Header for 'Recommended buffer size', ID: "RBUF">
+ Buffer size $xx xx xx
+ Embedded info flag %0000000x
+ Offset to next tag $xx xx xx xx
+
+
+4.19. Audio encryption
+
+ This frame indicates if the actual audio stream is encrypted, and by
+ whom. Since standardisation of such encryption scheme is beyond this
+ document, all "AENC" frames begin with a terminated string with a
+ URL containing an email address, or a link to a location where an
+ email address can be found, that belongs to the organisation
+ responsible for this specific encrypted audio file. Questions
+ regarding the encrypted audio should be sent to the email address
+ specified. If a $00 is found directly after the 'Frame size' and the
+ audio file indeed is encrypted, the whole file may be considered
+ useless.
+
+ After the 'Owner identifier', a pointer to an unencrypted part of the
+ audio can be specified. The 'Preview start' and 'Preview length' is
+ described in frames. If no part is unencrypted, these fields should
+ be left zeroed. After the 'preview length' field follows optionally a
+ data block required for decryption of the audio. There may be more
+ than one "AENC" frames in a tag, but only one with the same 'Owner
+ identifier'.
+
+ <Header for 'Audio encryption', ID: "AENC">
+ Owner identifier <text string> $00
+ Preview start $xx xx
+ Preview length $xx xx
+ Encryption info <binary data>
+
+
+4.20. Linked information
+
+ To keep information duplication as low as possible this frame may be
+ used to link information from another ID3v2 tag that might reside in
+ another audio file or alone in a binary file. It is RECOMMENDED that
+ this method is only used when the files are stored on a CD-ROM or
+ other circumstances when the risk of file separation is low. The
+ frame contains a frame identifier, which is the frame that should be
+ linked into this tag, a URL [URL] field, where a reference to the
+ file where the frame is given, and additional ID data, if needed.
+ Data should be retrieved from the first tag found in the file to
+ which this link points. There may be more than one "LINK" frame in a
+ tag, but only one with the same contents. A linked frame is to be
+ considered as part of the tag and has the same restrictions as if it
+ was a physical part of the tag (i.e. only one "RVRB" frame allowed,
+ whether it's linked or not).
+
+ <Header for 'Linked information', ID: "LINK">
+ Frame identifier $xx xx xx xx
+ URL <text string> $00
+ ID and additional data <text string(s)>
+
+ Frames that may be linked and need no additional data are "ASPI",
+ "ETCO", "EQU2", "MCID", "MLLT", "OWNE", "RVA2", "RVRB", "SYTC", the
+ text information frames and the URL link frames.
+
+ The "AENC", "APIC", "GEOB" and "TXXX" frames may be linked with
+ the content descriptor as additional ID data.
+
+ The "USER" frame may be linked with the language field as additional
+ ID data.
+
+ The "PRIV" frame may be linked with the owner identifier as
+ additional ID data.
+
+ The "COMM", "SYLT" and "USLT" frames may be linked with three bytes
+ of language descriptor directly followed by a content descriptor as
+ additional ID data.
+
+
+4.21. Position synchronisation frame
+
+ This frame delivers information to the listener of how far into the
+ audio stream he picked up; in effect, it states the time offset from
+ the first frame in the stream. The frame layout is:
+
+ <Head for 'Position synchronisation', ID: "POSS">
+ Time stamp format $xx
+ Position $xx (xx ...)
+
+ Where time stamp format is:
+
+ $01 Absolute time, 32 bit sized, using MPEG frames as unit
+ $02 Absolute time, 32 bit sized, using milliseconds as unit
+
+ and position is where in the audio the listener starts to receive,
+ i.e. the beginning of the next frame. If this frame is used in the
+ beginning of a file the value is always 0. There may only be one
+ "POSS" frame in each tag.
+
+
+4.22. Terms of use frame
+
+ This frame contains a brief description of the terms of use and
+ ownership of the file. More detailed information concerning the legal
+ terms might be available through the "WCOP" frame. Newlines are
+ allowed in the text. There may be more than one 'Terms of use' frame
+ in a tag, but only one with the same 'Language'.
+
+ <Header for 'Terms of use frame', ID: "USER">
+ Text encoding $xx
+ Language $xx xx xx
+ The actual text <text string according to encoding>
+
+
+4.23. Ownership frame
+
+ The ownership frame might be used as a reminder of a made transaction
+ or, if signed, as proof. Note that the "USER" and "TOWN" frames are
+ good to use in conjunction with this one. The frame begins, after the
+ frame ID, size and encoding fields, with a 'price paid' field. The
+ first three characters of this field contains the currency used for
+ the transaction, encoded according to ISO 4217 [ISO-4217] alphabetic
+ currency code. Concatenated to this is the actual price paid, as a
+ numerical string using "." as the decimal separator. Next is an 8
+ character date string (YYYYMMDD) followed by a string with the name
+ of the seller as the last field in the frame. There may only be one
+ "OWNE" frame in a tag.
+
+ <Header for 'Ownership frame', ID: "OWNE">
+ Text encoding $xx
+ Price paid <text string> $00
+ Date of purch. <text string>
+ Seller <text string according to encoding>
+
+
+4.24. Commercial frame
+
+ This frame enables several competing offers in the same tag by
+ bundling all needed information. That makes this frame rather complex
+ but it's an easier solution than if one tries to achieve the same
+ result with several frames. The frame begins, after the frame ID,
+ size and encoding fields, with a price string field. A price is
+ constructed by one three character currency code, encoded according
+ to ISO 4217 [ISO-4217] alphabetic currency code, followed by a
+ numerical value where "." is used as decimal separator. In the price
+ string several prices may be concatenated, separated by a "/"
+ character, but there may only be one currency of each type.
+
+ The price string is followed by an 8 character date string in the
+ format YYYYMMDD, describing for how long the price is valid. After
+ that is a contact URL, with which the user can contact the seller,
+ followed by a one byte 'received as' field. It describes how the
+ audio is delivered when bought according to the following list:
+
+ $00 Other
+ $01 Standard CD album with other songs
+ $02 Compressed audio on CD
+ $03 File over the Internet
+ $04 Stream over the Internet
+ $05 As note sheets
+ $06 As note sheets in a book with other sheets
+ $07 Music on other media
+ $08 Non-musical merchandise
+
+ Next follows a terminated string with the name of the seller followed
+ by a terminated string with a short description of the product. The
+ last thing is the ability to include a company logotype. The first of
+ them is the 'Picture MIME type' field containing information about
+ which picture format is used. In the event that the MIME media type
+ name is omitted, "image/" will be implied. Currently only "image/png"
+ and "image/jpeg" are allowed. This format string is followed by the
+ binary picture data. This two last fields may be omitted if no
+ picture is attached. There may be more than one 'commercial frame' in
+ a tag, but no two may be identical.
+
+ <Header for 'Commercial frame', ID: "COMR">
+ Text encoding $xx
+ Price string <text string> $00
+ Valid until <text string>
+ Contact URL <text string> $00
+ Received as $xx
+ Name of seller <text string according to encoding> $00 (00)
+ Description <text string according to encoding> $00 (00)
+ Picture MIME type <string> $00
+ Seller logo <binary data>
+
+
+4.25. Encryption method registration
+
+ To identify with which method a frame has been encrypted the
+ encryption method must be registered in the tag with this frame. The
+ 'Owner identifier' is a null-terminated string with a URL [URL]
+ containing an email address, or a link to a location where an email
+ address can be found, that belongs to the organisation responsible
+ for this specific encryption method. Questions regarding the
+ encryption method should be sent to the indicated email address. The
+ 'Method symbol' contains a value that is associated with this method
+ throughout the whole tag, in the range $80-F0. All other values are
+ reserved. The 'Method symbol' may optionally be followed by
+ encryption specific data. There may be several "ENCR" frames in a tag
+ but only one containing the same symbol and only one containing the
+ same owner identifier. The method must be used somewhere in the tag.
+ See the description of the frame encryption flag in the ID3v2
+ structure document [ID3v2-strct] for more information.
+
+ <Header for 'Encryption method registration', ID: "ENCR">
+ Owner identifier <text string> $00
+ Method symbol $xx
+ Encryption data <binary data>
+
+
+4.26. Group identification registration
+
+ This frame enables grouping of otherwise unrelated frames. This can
+ be used when some frames are to be signed. To identify which frames
+ belongs to a set of frames a group identifier must be registered in
+ the tag with this frame. The 'Owner identifier' is a null-terminated
+ string with a URL [URL] containing an email address, or a link to a
+ location where an email address can be found, that belongs to the
+ organisation responsible for this grouping. Questions regarding the
+ grouping should be sent to the indicated email address. The 'Group
+ symbol' contains a value that associates the frame with this group
+ throughout the whole tag, in the range $80-F0. All other values are
+ reserved. The 'Group symbol' may optionally be followed by some group
+ specific data, e.g. a digital signature. There may be several "GRID"
+ frames in a tag but only one containing the same symbol and only one
+ containing the same owner identifier. The group symbol must be used
+ somewhere in the tag. See the description of the frame grouping flag
+ in the ID3v2 structure document [ID3v2-strct] for more information.
+
+ <Header for 'Group ID registration', ID: "GRID">
+ Owner identifier <text string> $00
+ Group symbol $xx
+ Group dependent data <binary data>
+
+
+4.27. Private frame
+
+ This frame is used to contain information from a software producer
+ that its program uses and does not fit into the other frames. The
+ frame consists of an 'Owner identifier' string and the binary data.
+ The 'Owner identifier' is a null-terminated string with a URL [URL]
+ containing an email address, or a link to a location where an email
+ address can be found, that belongs to the organisation responsible
+ for the frame. Questions regarding the frame should be sent to the
+ indicated email address. The tag may contain more than one "PRIV"
+ frame but only with different contents.
+
+ <Header for 'Private frame', ID: "PRIV">
+ Owner identifier <text string> $00
+ The private data <binary data>
+
+
+4.28. Signature frame
+
+ This frame enables a group of frames, grouped with the 'Group
+ identification registration', to be signed. Although signatures can
+ reside inside the registration frame, it might be desired to store
+ the signature elsewhere, e.g. in watermarks. There may be more than
+ one 'signature frame' in a tag, but no two may be identical.
+
+ <Header for 'Signature frame', ID: "SIGN">
+ Group symbol $xx
+ Signature <binary data>
+
+
+4.29. Seek frame
+
+ This frame indicates where other tags in a file/stream can be found.
+ The 'minimum offset to next tag' is calculated from the end of this
+ tag to the beginning of the next. There may only be one 'seek frame'
+ in a tag.
+
+ <Header for 'Seek frame', ID: "SEEK">
+ Minimum offset to next tag $xx xx xx xx
+
+
+4.30. Audio seek point index
+
+ Audio files with variable bit rates are intrinsically difficult to
+ deal with in the case of seeking within the file. The ASPI frame
+ makes seeking easier by providing a list a seek points within the
+ audio file. The seek points are a fractional offset within the audio
+ data, providing a starting point from which to find an appropriate
+ point to start decoding. The presence of an ASPI frame requires the
+ existence of a TLEN frame, indicating the duration of the file in
+ milliseconds. There may only be one 'audio seek point index' frame in
+ a tag.
+
+ <Header for 'Seek Point Index', ID: "ASPI">
+ Indexed data start (S) $xx xx xx xx
+ Indexed data length (L) $xx xx xx xx
+ Number of index points (N) $xx xx
+ Bits per index point (b) $xx
+
+ Then for every index point the following data is included;
+
+ Fraction at index (Fi) $xx (xx)
+
+ 'Indexed data start' is a byte offset from the beginning of the file.
+ 'Indexed data length' is the byte length of the audio data being
+ indexed. 'Number of index points' is the number of index points, as
+ the name implies. The recommended number is 100. 'Bits per index
+ point' is 8 or 16, depending on the chosen precision. 8 bits works
+ well for short files (less than 5 minutes of audio), while 16 bits is
+ advantageous for long files. 'Fraction at index' is the numerator of
+ the fraction representing a relative position in the data. The
+ denominator is 2 to the power of b.
+
+ Here are the algorithms to be used in the calculation. The known data
+ must be the offset of the start of the indexed data (S), the offset
+ of the end of the indexed data (E), the number of index points (N),
+ the offset at index i (Oi). We calculate the fraction at index i
+ (Fi).
+
+ Oi is the offset of the frame whose start is soonest after the point
+ for which the time offset is (i/N * duration).
+
+ The frame data should be calculated as follows:
+
+ Fi = Oi/L * 2^b (rounded down to the nearest integer)
+
+ Offset calculation should be calculated as follows from data in the
+ frame:
+
+ Oi = (Fi/2^b)*L (rounded up to the nearest integer)
+
+
+5. Copyright
+
+ Copyright (C) Martin Nilsson 2000. All Rights Reserved.
+
+ This document and translations of it may be copied and furnished to
+ others, and derivative works that comment on or otherwise explain it
+ or assist in its implementation may be prepared, copied, published
+ and distributed, in whole or in part, without restriction of any
+ kind, provided that a reference to this document is included on all
+ such copies and derivative works. However, this document itself may
+ not be modified in any way and reissued as the original document.
+
+ The limited permissions granted above are perpetual and will not be
+ revoked.
+
+ This document and the information contained herein is provided on an
+ "AS IS" basis and THE AUTHORS DISCLAIMS ALL WARRANTIES, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTY THAT THE USE OF
+ THE INFORMATION HEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED
+ WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
+
+
+6. References
+
+ [CDDB] Compact Disc Data Base
+
+ <url:http://www.cddb.com>
+
+ [ID3v2.3.0] Martin Nilsson, "ID3v2 informal standard".
+
+ <url:http://www.id3.org/id3v2.3.0.txt>
+
+ [ID3v2-strct] Martin Nilsson,
+ "ID3 tag version 2.4.0 - Main Structure"
+
+ <url:http//www.id3.org/id3v2.4.0-structure.txt>
+
+ [ISO-639-2] ISO/FDIS 639-2.
+ Codes for the representation of names of languages, Part 2: Alpha-3
+ code. Technical committee / subcommittee: TC 37 / SC 2
+
+ [ISO-4217] ISO 4217:1995.
+ Codes for the representation of currencies and funds.
+ Technical committee / subcommittee: TC 68
+
+ [ISO-8859-1] ISO/IEC DIS 8859-1.
+ 8-bit single-byte coded graphic character sets, Part 1: Latin
+ alphabet No. 1. Technical committee / subcommittee: JTC 1 / SC 2
+
+ [ISRC] ISO 3901:1986
+ International Standard Recording Code (ISRC).
+ Technical committee / subcommittee: TC 46 / SC 9
+
+ [JFIF] JPEG File Interchange Format, version 1.02
+
+ <url:http://www.w3.org/Graphics/JPEG/jfif.txt>
+
+ [KEYWORDS] S. Bradner, 'Key words for use in RFCs to Indicate
+ Requirement Levels', RFC 2119, March 1997.
+
+ <url:ftp://ftp.isi.edu/in-notes/rfc2119.txt>
+
+ [MIME] Freed, N. and N. Borenstein, "Multipurpose Internet Mail
+ Extensions (MIME) Part One: Format of Internet Message Bodies",
+ RFC 2045, November 1996.
+
+ <url:ftp://ftp.isi.edu/in-notes/rfc2045.txt>
+
+ [MPEG] ISO/IEC 11172-3:1993.
+ Coding of moving pictures and associated audio for digital storage
+ media at up to about 1,5 Mbit/s, Part 3: Audio.
+ Technical committee / subcommittee: JTC 1 / SC 29
+ and
+ ISO/IEC 13818-3:1995
+ Generic coding of moving pictures and associated audio information,
+ Part 3: Audio.
+ Technical committee / subcommittee: JTC 1 / SC 29
+ and
+ ISO/IEC DIS 13818-3
+ Generic coding of moving pictures and associated audio information,
+ Part 3: Audio (Revision of ISO/IEC 13818-3:1995)
+
+
+ [PNG] Portable Network Graphics, version 1.0
+
+ <url:http://www.w3.org/TR/REC-png-multi.html>
+
+ [URL] T. Berners-Lee, L. Masinter & M. McCahill, "Uniform Resource
+ Locators (URL).", RFC 1738, December 1994.
+
+ <url:ftp://ftp.isi.edu/in-notes/rfc1738.txt>
+
+ [ZLIB] P. Deutsch, Aladdin Enterprises & J-L. Gailly, "ZLIB
+ Compressed
+ Data Format Specification version 3.3", RFC 1950, May 1996.
+
+ <url:ftp://ftp.isi.edu/in-notes/rfc1950.txt>
+
+
+7. Appendix
+
+
+A. Appendix A - Genre List from ID3v1
+
+ The following genres is defined in ID3v1
+
+ 0.Blues
+ 1.Classic Rock
+ 2.Country
+ 3.Dance
+ 4.Disco
+ 5.Funk
+ 6.Grunge
+ 7.Hip-Hop
+ 8.Jazz
+ 9.Metal
+ 10.New Age
+ 11.Oldies
+ 12.Other
+ 13.Pop
+ 14.R&B
+ 15.Rap
+ 16.Reggae
+ 17.Rock
+ 18.Techno
+ 19.Industrial
+ 20.Alternative
+ 21.Ska
+ 22.Death Metal
+ 23.Pranks
+ 24.Soundtrack
+ 25.Euro-Techno
+ 26.Ambient
+ 27.Trip-Hop
+ 28.Vocal
+ 29.Jazz+Funk
+ 30.Fusion
+ 31.Trance
+ 32.Classical
+ 33.Instrumental
+ 34.Acid
+ 35.House
+ 36.Game
+ 37.Sound Clip
+ 38.Gospel
+ 39.Noise
+ 40.AlternRock
+ 41.Bass
+ 42.Soul
+ 43.Punk
+ 44.Space
+ 45.Meditative
+ 46.Instrumental Pop
+ 47.Instrumental Rock
+ 48.Ethnic
+ 49.Gothic
+ 50.Darkwave
+ 51.Techno-Industrial
+ 52.Electronic
+ 53.Pop-Folk
+ 54.Eurodance
+ 55.Dream
+ 56.Southern Rock
+ 57.Comedy
+ 58.Cult
+ 59.Gangsta
+ 60.Top 40
+ 61.Christian Rap
+ 62.Pop/Funk
+ 63.Jungle
+ 64.Native American
+ 65.Cabaret
+ 66.New Wave
+ 67.Psychadelic
+ 68.Rave
+ 69.Showtunes
+ 70.Trailer
+ 71.Lo-Fi
+ 72.Tribal
+ 73.Acid Punk
+ 74.Acid Jazz
+ 75.Polka
+ 76.Retro
+ 77.Musical
+ 78.Rock & Roll
+ 79.Hard Rock
+
+
+8. Author's Address
+
+ Written by
+
+ Martin Nilsson
+ Rydsvägen 246 C. 30
+ SE-584 34 Linköping
+ Sweden
+
+ Email: nilsson@id3.org
diff --git a/gst/id3demux/id3v2.4.0-structure.txt b/gst/id3demux/id3v2.4.0-structure.txt
new file mode 100644
index 00000000..5fa156a0
--- /dev/null
+++ b/gst/id3demux/id3v2.4.0-structure.txt
@@ -0,0 +1,733 @@
+
+Informal standard M. Nilsson
+Document: id3v2.4.0-structure.txt 16 September 2001
+
+
+ ID3 tag version 2.4.0 - Main Structure
+
+Status of this document
+
+ This document is an informal standard and replaces the ID3v2.3.0
+ standard [ID3v2]. A formal standard will use another revision number
+ even if the content is identical to document. The contents in this
+ document may change for clarifications but never for added or altered
+ functionallity.
+
+ Distribution of this document is unlimited.
+
+
+Abstract
+
+ This document describes the main structure of ID3v2.4.0, which is a
+ revised version of the ID3v2 informal standard [ID3v2] version
+ 2.3.0. The ID3v2 offers a flexible way of storing audio meta
+ information within the audio file itself. The information may be
+ technical information, such as equalisation curves, as well as
+ title, performer, copyright etc.
+
+ ID3v2.4.0 is meant to be as close as possible to ID3v2.3.0 in order
+ to allow for implementations to be revised as easily as possible.
+
+
+1. Table of contents
+
+ Status of this document
+ Abstract
+ 1. Table of contents
+ 2. Conventions in this document
+ 2. Standard overview
+ 3. ID3v2 overview
+ 3.1. ID3v2 header
+ 3.2. ID3v2 extended header
+ 3.3. Padding
+ 3.4. ID3v2 footer
+ 4. ID3v2 frames overview
+ 4.1. Frame header flags
+ 4.1.1. Frame status flags
+ 4.1.2. Frame format flags
+ 5. Tag location
+ 6. Unsynchronisation
+ 6.1. The unsynchronisation scheme
+ 6.2. Synchsafe integers
+ 7. Copyright
+ 8. References
+ 9. Author's Address
+
+
+2. Conventions in this document
+
+ Text within "" is a text string exactly as it appears in a tag.
+ Numbers preceded with $ are hexadecimal and numbers preceded with %
+ are binary. $xx is used to indicate a byte with unknown content. %x
+ is used to indicate a bit with unknown content. The most significant
+ bit (MSB) of a byte is called 'bit 7' and the least significant bit
+ (LSB) is called 'bit 0'.
+
+ A tag is the whole tag described in this document. A frame is a block
+ of information in the tag. The tag consists of a header, frames and
+ optional padding. A field is a piece of information; one value, a
+ string etc. A numeric string is a string that consists of the
+ characters "0123456789" only.
+
+ The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT",
+ "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this
+ document are to be interpreted as described in RFC 2119 [KEYWORDS].
+
+
+3. ID3v2 overview
+
+ ID3v2 is a general tagging format for audio, which makes it possible
+ to store meta data about the audio inside the audio file itself. The
+ ID3 tag described in this document is mainly targeted at files
+ encoded with MPEG-1/2 layer I, MPEG-1/2 layer II, MPEG-1/2 layer III
+ and MPEG-2.5, but may work with other types of encoded audio or as a
+ stand alone format for audio meta data.
+
+ ID3v2 is designed to be as flexible and expandable as possible to
+ meet new meta information needs that might arise. To achieve that
+ ID3v2 is constructed as a container for several information blocks,
+ called frames, whose format need not be known to the software that
+ encounters them. At the start of every frame is an unique and
+ predefined identifier, a size descriptor that allows software to skip
+ unknown frames and a flags field. The flags describes encoding
+ details and if the frame should remain in the tag, should it be
+ unknown to the software, if the file is altered.
+
+ The bitorder in ID3v2 is most significant bit first (MSB). The
+ byteorder in multibyte numbers is most significant byte first (e.g.
+ $12345678 would be encoded $12 34 56 78), also known as big endian
+ and network byte order.
+
+ Overall tag structure:
+
+ +-----------------------------+
+ | Header (10 bytes) |
+ +-----------------------------+
+ | Extended Header |
+ | (variable length, OPTIONAL) |
+ +-----------------------------+
+ | Frames (variable length) |
+ +-----------------------------+
+ | Padding |
+ | (variable length, OPTIONAL) |
+ +-----------------------------+
+ | Footer (10 bytes, OPTIONAL) |
+ +-----------------------------+
+
+ In general, padding and footer are mutually exclusive. See details in
+ sections 3.3, 3.4 and 5.
+
+
+3.1. ID3v2 header
+
+ The first part of the ID3v2 tag is the 10 byte tag header, laid out
+ as follows:
+
+ ID3v2/file identifier "ID3"
+ ID3v2 version $04 00
+ ID3v2 flags %abcd0000
+ ID3v2 size 4 * %0xxxxxxx
+
+ The first three bytes of the tag are always "ID3", to indicate that
+ this is an ID3v2 tag, directly followed by the two version bytes. The
+ first byte of ID3v2 version is its major version, while the second
+ byte is its revision number. In this case this is ID3v2.4.0. All
+ revisions are backwards compatible while major versions are not. If
+ software with ID3v2.4.0 and below support should encounter version
+ five or higher it should simply ignore the whole tag. Version or
+ revision will never be $FF.
+
+ The version is followed by the ID3v2 flags field, of which currently
+ four flags are used.
+
+
+ a - Unsynchronisation
+
+ Bit 7 in the 'ID3v2 flags' indicates whether or not
+ unsynchronisation is applied on all frames (see section 6.1 for
+ details); a set bit indicates usage.
+
+
+ b - Extended header
+
+ The second bit (bit 6) indicates whether or not the header is
+ followed by an extended header. The extended header is described in
+ section 3.2. A set bit indicates the presence of an extended
+ header.
+
+
+ c - Experimental indicator
+
+ The third bit (bit 5) is used as an 'experimental indicator'. This
+ flag SHALL always be set when the tag is in an experimental stage.
+
+
+ d - Footer present
+
+ Bit 4 indicates that a footer (section 3.4) is present at the very
+ end of the tag. A set bit indicates the presence of a footer.
+
+
+ All the other flags MUST be cleared. If one of these undefined flags
+ are set, the tag might not be readable for a parser that does not
+ know the flags function.
+
+ The ID3v2 tag size is stored as a 32 bit synchsafe integer (section
+ 6.2), making a total of 28 effective bits (representing up to 256MB).
+
+ The ID3v2 tag size is the sum of the byte length of the extended
+ header, the padding and the frames after unsynchronisation. If a
+ footer is present this equals to ('total size' - 20) bytes, otherwise
+ ('total size' - 10) bytes.
+
+ An ID3v2 tag can be detected with the following pattern:
+ $49 44 33 yy yy xx zz zz zz zz
+ Where yy is less than $FF, xx is the 'flags' byte and zz is less than
+ $80.
+
+
+3.2. Extended header
+
+ The extended header contains information that can provide further
+ insight in the structure of the tag, but is not vital to the correct
+ parsing of the tag information; hence the extended header is
+ optional.
+
+ Extended header size 4 * %0xxxxxxx
+ Number of flag bytes $01
+ Extended Flags $xx
+
+ Where the 'Extended header size' is the size of the whole extended
+ header, stored as a 32 bit synchsafe integer. An extended header can
+ thus never have a size of fewer than six bytes.
+
+ The extended flags field, with its size described by 'number of flag
+ bytes', is defined as:
+
+ %0bcd0000
+
+ Each flag that is set in the extended header has data attached, which
+ comes in the order in which the flags are encountered (i.e. the data
+ for flag 'b' comes before the data for flag 'c'). Unset flags cannot
+ have any attached data. All unknown flags MUST be unset and their
+ corresponding data removed when a tag is modified.
+
+ Every set flag's data starts with a length byte, which contains a
+ value between 0 and 127 ($00 - $7f), followed by data that has the
+ field length indicated by the length byte. If a flag has no attached
+ data, the value $00 is used as length byte.
+
+
+ b - Tag is an update
+
+ If this flag is set, the present tag is an update of a tag found
+ earlier in the present file or stream. If frames defined as unique
+ are found in the present tag, they are to override any
+ corresponding ones found in the earlier tag. This flag has no
+ corresponding data.
+
+ Flag data length $00
+
+ c - CRC data present
+
+ If this flag is set, a CRC-32 [ISO-3309] data is included in the
+ extended header. The CRC is calculated on all the data between the
+ header and footer as indicated by the header's tag length field,
+ minus the extended header. Note that this includes the padding (if
+ there is any), but excludes the footer. The CRC-32 is stored as an
+ 35 bit synchsafe integer, leaving the upper four bits always
+ zeroed.
+
+ Flag data length $05
+ Total frame CRC 5 * %0xxxxxxx
+
+ d - Tag restrictions
+
+ For some applications it might be desired to restrict a tag in more
+ ways than imposed by the ID3v2 specification. Note that the
+ presence of these restrictions does not affect how the tag is
+ decoded, merely how it was restricted before encoding. If this flag
+ is set the tag is restricted as follows:
+
+ Flag data length $01
+ Restrictions %ppqrrstt
+
+ p - Tag size restrictions
+
+ 00 No more than 128 frames and 1 MB total tag size.
+ 01 No more than 64 frames and 128 KB total tag size.
+ 10 No more than 32 frames and 40 KB total tag size.
+ 11 No more than 32 frames and 4 KB total tag size.
+
+ q - Text encoding restrictions
+
+ 0 No restrictions
+ 1 Strings are only encoded with ISO-8859-1 [ISO-8859-1] or
+ UTF-8 [UTF-8].
+
+ r - Text fields size restrictions
+
+ 00 No restrictions
+ 01 No string is longer than 1024 characters.
+ 10 No string is longer than 128 characters.
+ 11 No string is longer than 30 characters.
+
+ Note that nothing is said about how many bytes is used to
+ represent those characters, since it is encoding dependent. If a
+ text frame consists of more than one string, the sum of the
+ strungs is restricted as stated.
+
+ s - Image encoding restrictions
+
+ 0 No restrictions
+ 1 Images are encoded only with PNG [PNG] or JPEG [JFIF].
+
+ t - Image size restrictions
+
+ 00 No restrictions
+ 01 All images are 256x256 pixels or smaller.
+ 10 All images are 64x64 pixels or smaller.
+ 11 All images are exactly 64x64 pixels, unless required
+ otherwise.
+
+
+3.3. Padding
+
+ It is OPTIONAL to include padding after the final frame (at the end
+ of the ID3 tag), making the size of all the frames together smaller
+ than the size given in the tag header. A possible purpose of this
+ padding is to allow for adding a few additional frames or enlarge
+ existing frames within the tag without having to rewrite the entire
+ file. The value of the padding bytes must be $00. A tag MUST NOT have
+ any padding between the frames or between the tag header and the
+ frames. Furthermore it MUST NOT have any padding when a tag footer is
+ added to the tag.
+
+
+3.4. ID3v2 footer
+
+ To speed up the process of locating an ID3v2 tag when searching from
+ the end of a file, a footer can be added to the tag. It is REQUIRED
+ to add a footer to an appended tag, i.e. a tag located after all
+ audio data. The footer is a copy of the header, but with a different
+ identifier.
+
+ ID3v2 identifier "3DI"
+ ID3v2 version $04 00
+ ID3v2 flags %abcd0000
+ ID3v2 size 4 * %0xxxxxxx
+
+
+4. ID3v2 frame overview
+
+ All ID3v2 frames consists of one frame header followed by one or more
+ fields containing the actual information. The header is always 10
+ bytes and laid out as follows:
+
+ Frame ID $xx xx xx xx (four characters)
+ Size 4 * %0xxxxxxx
+ Flags $xx xx
+
+ The frame ID is made out of the characters capital A-Z and 0-9.
+ Identifiers beginning with "X", "Y" and "Z" are for experimental
+ frames and free for everyone to use, without the need to set the
+ experimental bit in the tag header. Bear in mind that someone else
+ might have used the same identifier as you. All other identifiers are
+ either used or reserved for future use.
+
+ The frame ID is followed by a size descriptor containing the size of
+ the data in the final frame, after encryption, compression and
+ unsynchronisation. The size is excluding the frame header ('total
+ frame size' - 10 bytes) and stored as a 32 bit synchsafe integer.
+
+ In the frame header the size descriptor is followed by two flag
+ bytes. These flags are described in section 4.1.
+
+ There is no fixed order of the frames' appearance in the tag,
+ although it is desired that the frames are arranged in order of
+ significance concerning the recognition of the file. An example of
+ such order: UFID, TIT2, MCDI, TRCK ...
+
+ A tag MUST contain at least one frame. A frame must be at least 1
+ byte big, excluding the header.
+
+ If nothing else is said, strings, including numeric strings and URLs
+ [URL], are represented as ISO-8859-1 [ISO-8859-1] characters in the
+ range $20 - $FF. Such strings are represented in frame descriptions
+ as <text string>, or <full text string> if newlines are allowed. If
+ nothing else is said newline character is forbidden. In ISO-8859-1 a
+ newline is represented, when allowed, with $0A only.
+
+ Frames that allow different types of text encoding contains a text
+ encoding description byte. Possible encodings:
+
+ $00 ISO-8859-1 [ISO-8859-1]. Terminated with $00.
+ $01 UTF-16 [UTF-16] encoded Unicode [UNICODE] with BOM. All
+ strings in the same frame SHALL have the same byteorder.
+ Terminated with $00 00.
+ $02 UTF-16BE [UTF-16] encoded Unicode [UNICODE] without BOM.
+ Terminated with $00 00.
+ $03 UTF-8 [UTF-8] encoded Unicode [UNICODE]. Terminated with $00.
+
+ Strings dependent on encoding are represented in frame descriptions
+ as <text string according to encoding>, or <full text string
+ according to encoding> if newlines are allowed. Any empty strings of
+ type $01 which are NULL-terminated may have the Unicode BOM followed
+ by a Unicode NULL ($FF FE 00 00 or $FE FF 00 00).
+
+ The timestamp fields are based on a subset of ISO 8601. When being as
+ precise as possible the format of a time string is
+ yyyy-MM-ddTHH:mm:ss (year, "-", month, "-", day, "T", hour (out of
+ 24), ":", minutes, ":", seconds), but the precision may be reduced by
+ removing as many time indicators as wanted. Hence valid timestamps
+ are
+ yyyy, yyyy-MM, yyyy-MM-dd, yyyy-MM-ddTHH, yyyy-MM-ddTHH:mm and
+ yyyy-MM-ddTHH:mm:ss. All time stamps are UTC. For durations, use
+ the slash character as described in 8601, and for multiple non-
+ contiguous dates, use multiple strings, if allowed by the frame
+ definition.
+
+ The three byte language field, present in several frames, is used to
+ describe the language of the frame's content, according to ISO-639-2
+ [ISO-639-2]. The language should be represented in lower case. If the
+ language is not known the string "XXX" should be used.
+
+ All URLs [URL] MAY be relative, e.g. "picture.png", "../doc.txt".
+
+ If a frame is longer than it should be, e.g. having more fields than
+ specified in this document, that indicates that additions to the
+ frame have been made in a later version of the ID3v2 standard. This
+ is reflected by the revision number in the header of the tag.
+
+
+4.1. Frame header flags
+
+ In the frame header the size descriptor is followed by two flag
+ bytes. All unused flags MUST be cleared. The first byte is for
+ 'status messages' and the second byte is a format description. If an
+ unknown flag is set in the first byte the frame MUST NOT be changed
+ without that bit cleared. If an unknown flag is set in the second
+ byte the frame is likely to not be readable. Some flags in the second
+ byte indicates that extra information is added to the header. These
+ fields of extra information is ordered as the flags that indicates
+ them. The flags field is defined as follows (l and o left out because
+ ther resemblence to one and zero):
+
+ %0abc0000 %0h00kmnp
+
+ Some frame format flags indicate that additional information fields
+ are added to the frame. This information is added after the frame
+ header and before the frame data in the same order as the flags that
+ indicates them. I.e. the four bytes of decompressed size will precede
+ the encryption method byte. These additions affects the 'frame size'
+ field, but are not subject to encryption or compression.
+
+ The default status flags setting for a frame is, unless stated
+ otherwise, 'preserved if tag is altered' and 'preserved if file is
+ altered', i.e. %00000000.
+
+
+4.1.1. Frame status flags
+
+ a - Tag alter preservation
+
+ This flag tells the tag parser what to do with this frame if it is
+ unknown and the tag is altered in any way. This applies to all
+ kinds of alterations, including adding more padding and reordering
+ the frames.
+
+ 0 Frame should be preserved.
+ 1 Frame should be discarded.
+
+
+ b - File alter preservation
+
+ This flag tells the tag parser what to do with this frame if it is
+ unknown and the file, excluding the tag, is altered. This does not
+ apply when the audio is completely replaced with other audio data.
+
+ 0 Frame should be preserved.
+ 1 Frame should be discarded.
+
+
+ c - Read only
+
+ This flag, if set, tells the software that the contents of this
+ frame are intended to be read only. Changing the contents might
+ break something, e.g. a signature. If the contents are changed,
+ without knowledge of why the frame was flagged read only and
+ without taking the proper means to compensate, e.g. recalculating
+ the signature, the bit MUST be cleared.
+
+
+4.1.2. Frame format flags
+
+ h - Grouping identity
+
+ This flag indicates whether or not this frame belongs in a group
+ with other frames. If set, a group identifier byte is added to the
+ frame. Every frame with the same group identifier belongs to the
+ same group.
+
+ 0 Frame does not contain group information
+ 1 Frame contains group information
+
+
+ k - Compression
+
+ This flag indicates whether or not the frame is compressed.
+ A 'Data Length Indicator' byte MUST be included in the frame.
+
+ 0 Frame is not compressed.
+ 1 Frame is compressed using zlib [zlib] deflate method.
+ If set, this requires the 'Data Length Indicator' bit
+ to be set as well.
+
+
+ m - Encryption
+
+ This flag indicates whether or not the frame is encrypted. If set,
+ one byte indicating with which method it was encrypted will be
+ added to the frame. See description of the ENCR frame for more
+ information about encryption method registration. Encryption
+ should be done after compression. Whether or not setting this flag
+ requires the presence of a 'Data Length Indicator' depends on the
+ specific algorithm used.
+
+ 0 Frame is not encrypted.
+ 1 Frame is encrypted.
+
+ n - Unsynchronisation
+
+ This flag indicates whether or not unsynchronisation was applied
+ to this frame. See section 6 for details on unsynchronisation.
+ If this flag is set all data from the end of this header to the
+ end of this frame has been unsynchronised. Although desirable, the
+ presence of a 'Data Length Indicator' is not made mandatory by
+ unsynchronisation.
+
+ 0 Frame has not been unsynchronised.
+ 1 Frame has been unsyrchronised.
+
+ p - Data length indicator
+
+ This flag indicates that a data length indicator has been added to
+ the frame. The data length indicator is the value one would write
+ as the 'Frame length' if all of the frame format flags were
+ zeroed, represented as a 32 bit synchsafe integer.
+
+ 0 There is no Data Length Indicator.
+ 1 A data length Indicator has been added to the frame.
+
+
+5. Tag location
+
+ The default location of an ID3v2 tag is prepended to the audio so
+ that players can benefit from the information when the data is
+ streamed. It is however possible to append the tag, or make a
+ prepend/append combination. When deciding upon where an unembedded
+ tag should be located, the following order of preference SHOULD be
+ considered.
+
+ 1. Prepend the tag.
+
+ 2. Prepend a tag with all vital information and add a second tag at
+ the end of the file, before tags from other tagging systems. The
+ first tag is required to have a SEEK frame.
+
+ 3. Add a tag at the end of the file, before tags from other tagging
+ systems.
+
+ In case 2 and 3 the tag can simply be appended if no other known tags
+ are present. The suggested method to find ID3v2 tags are:
+
+ 1. Look for a prepended tag using the pattern found in section 3.1.
+
+ 2. If a SEEK frame was found, use its values to guide further
+ searching.
+
+ 3. Look for a tag footer, scanning from the back of the file.
+
+ For every new tag that is found, the old tag should be discarded
+ unless the update flag in the extended header (section 3.2) is set.
+
+
+6. Unsynchronisation
+
+ The only purpose of unsynchronisation is to make the ID3v2 tag as
+ compatible as possible with existing software and hardware. There is
+ no use in 'unsynchronising' tags if the file is only to be processed
+ only by ID3v2 aware software and hardware. Unsynchronisation is only
+ useful with tags in MPEG 1/2 layer I, II and III, MPEG 2.5 and AAC
+ files.
+
+
+6.1. The unsynchronisation scheme
+
+ Whenever a false synchronisation is found within the tag, one zeroed
+ byte is inserted after the first false synchronisation byte. The
+ format of synchronisations that should be altered by ID3 encoders is
+ as follows:
+
+ %11111111 111xxxxx
+
+ and should be replaced with:
+
+ %11111111 00000000 111xxxxx
+
+ This has the side effect that all $FF 00 combinations have to be
+ altered, so they will not be affected by the decoding process.
+ Therefore all the $FF 00 combinations have to be replaced with the
+ $FF 00 00 combination during the unsynchronisation.
+
+ To indicate usage of the unsynchronisation, the unsynchronisation
+ flag in the frame header should be set. This bit MUST be set if the
+ frame was altered by the unsynchronisation and SHOULD NOT be set if
+ unaltered. If all frames in the tag are unsynchronised the
+ unsynchronisation flag in the tag header SHOULD be set. It MUST NOT
+ be set if the tag has a frame which is not unsynchronised.
+
+ Assume the first byte of the audio to be $FF. The special case when
+ the last byte of the last frame is $FF and no padding nor footer is
+ used will then introduce a false synchronisation. This can be solved
+ by adding a footer, adding padding or unsynchronising the frame and
+ add $00 to the end of the frame data, thus adding more byte to the
+ frame size than a normal unsynchronisation would. Although not
+ preferred, it is allowed to apply the last method on all frames
+ ending with $FF.
+
+ It is preferred that the tag is either completely unsynchronised or
+ not unsynchronised at all. A completely unsynchronised tag has no
+ false synchonisations in it, as defined above, and does not end with
+ $FF. A completely non-unsynchronised tag contains no unsynchronised
+ frames, and thus the unsynchronisation flag in the header is cleared.
+
+ Do bear in mind, that if compression or encryption is used, the
+ unsynchronisation scheme MUST be applied afterwards. When decoding an
+ unsynchronised frame, the unsynchronisation scheme MUST be reversed
+ first, encryption and decompression afterwards.
+
+
+6.2. Synchsafe integers
+
+ In some parts of the tag it is inconvenient to use the
+ unsychronisation scheme because the size of unsynchronised data is
+ not known in advance, which is particularly problematic with size
+ descriptors. The solution in ID3v2 is to use synchsafe integers, in
+ which there can never be any false synchs. Synchsafe integers are
+ integers that keep its highest bit (bit 7) zeroed, making seven bits
+ out of eight available. Thus a 32 bit synchsafe integer can store 28
+ bits of information.
+
+ Example:
+
+ 255 (%11111111) encoded as a 16 bit synchsafe integer is 383
+ (%00000001 01111111).
+
+
+7. Copyright
+
+ Copyright (C) Martin Nilsson 2000. All Rights Reserved.
+
+ This document and translations of it may be copied and furnished to
+ others, and derivative works that comment on or otherwise explain it
+ or assist in its implementation may be prepared, copied, published
+ and distributed, in whole or in part, without restriction of any
+ kind, provided that a reference to this document is included on all
+ such copies and derivative works. However, this document itself may
+ not be modified in any way and reissued as the original document.
+
+ The limited permissions granted above are perpetual and will not be
+ revoked.
+
+ This document and the information contained herein is provided on an
+ 'AS IS' basis and THE AUTHORS DISCLAIMS ALL WARRANTIES, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTY THAT THE USE OF
+ THE INFORMATION HEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED
+ WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
+
+
+8. References
+
+ [ID3v2] Martin Nilsson, 'ID3v2 informal standard'.
+
+ <url:http://www.id3.org/id3v2.3.0.txt>
+
+ [ISO-639-2] ISO/FDIS 639-2.
+ 'Codes for the representation of names of languages, Part 2: Alpha-3
+ code.' Technical committee / subcommittee: TC 37 / SC 2
+
+ [ISO-3309] ISO 3309
+ 'Information Processing Systems--Data Communication High-Level Data
+ Link Control Procedure--Frame Structure', IS 3309, October 1984, 3rd
+ Edition.
+
+ [ISO-8859-1] ISO/IEC DIS 8859-1.
+ '8-bit single-byte coded graphic character sets, Part 1: Latin
+ alphabet No. 1.' Technical committee / subcommittee: JTC 1 / SC 2
+
+ [JFIF] 'JPEG File Interchange Format, version 1.02'
+
+ <url:http://www.w3.org/Graphics/JPEG/jfif.txt>
+
+ [KEYWORDS] S. Bradner, 'Key words for use in RFCs to Indicate
+ Requirement Levels', RFC 2119, March 1997.
+
+ <url:ftp://ftp.isi.edu/in-notes/rfc2119.txt>
+
+ [MPEG] ISO/IEC 11172-3:1993.
+ 'Coding of moving pictures and associated audio for digital storage
+ media at up to about 1,5 Mbit/s, Part 3: Audio.'
+ Technical committee / subcommittee: JTC 1 / SC 29
+ and
+ ISO/IEC 13818-3:1995
+ 'Generic coding of moving pictures and associated audio information,
+ Part 3: Audio.'
+ Technical committee / subcommittee: JTC 1 / SC 29
+ and
+ ISO/IEC DIS 13818-3
+ 'Generic coding of moving pictures and associated audio information,
+ Part 3: Audio (Revision of ISO/IEC 13818-3:1995)'
+
+ [PNG] 'Portable Network Graphics, version 1.0'
+
+ <url:http://www.w3.org/TR/REC-png-multi.html>
+
+ [UNICODE] The Unicode Consortium,
+ 'The Unicode Standard Version 3.0', ISBN 0-201-61633-5.
+
+ <url:http://www.unicode.org/unicode/standard/versions/Unicode3.0.htm>
+
+ [URL] T. Berners-Lee, L. Masinter & M. McCahill, 'Uniform Resource
+ Locators (URL)', RFC 1738, December 1994.
+
+ <url:ftp://ftp.isi.edu/in-notes/rfc1738.txt>
+
+ [UTF-8] F. Yergeau, 'UTF-8, a transformation format of ISO 10646',
+ RFC 2279, January 1998.
+
+ <url:ftp://ftp.isi.edu/in-notes/rfc2279.txt>
+
+ [UTF-16] F. Yergeau, 'UTF-16, an encoding of ISO 10646', RFC 2781,
+ February 2000.
+
+ <url:ftp://ftp.isi.edu/in-notes/rfc2781.txt>
+
+ [ZLIB] P. Deutsch, Aladdin Enterprises & J-L. Gailly, 'ZLIB
+ Compressed Data Format Specification version 3.3', RFC 1950,
+ May 1996.
+
+ <url:ftp://ftp.isi.edu/in-notes/rfc1950.txt>
+
+
+9. Author's Address
+
+ Written by
+
+ Martin Nilsson
+ Rydsvägen 246 C. 30
+ SE-584 34 Linköping
+ Sweden
+
+ Email: nilsson@id3.org
+
diff --git a/gst/id3demux/id3v2frames.c b/gst/id3demux/id3v2frames.c
new file mode 100644
index 00000000..fec70123
--- /dev/null
+++ b/gst/id3demux/id3v2frames.c
@@ -0,0 +1,382 @@
+/* -*- Mode: C; tab-width: 2; indent-tabs-mode: t; c-basic-offset: 2 -*- */
+/* Copyright 2005 Jan Schmidt <thaytan@mad.scientist.com>
+ * Copyright 2002,2003 Scott Wheeler <wheeler@kde.org> (portions from taglib)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <string.h>
+#include <gst/tag/tag.h>
+
+#ifdef HAVE_ZLIB
+#include <zlib.h>
+#endif
+
+#include "id3tags.h"
+
+GST_DEBUG_CATEGORY_EXTERN (id3demux_debug);
+#define GST_CAT_DEFAULT (id3demux_debug)
+
+static gchar *parse_comment_frame (ID3TagsWorking * work);
+static gchar *parse_text_identification_frame (ID3TagsWorking * work);
+static gboolean id3v2_tag_to_taglist (ID3TagsWorking * work,
+ const gchar * tag_name, gchar * tag_str);
+static void parse_split_strings (ID3TagsWorking * work, guint8 encoding,
+ gchar ** field1, gchar ** field2);
+
+#define ID3V2_ENCODING_ISO8859 0x00
+#define ID3V2_ENCODING_UTF16 0x01
+#define ID3V2_ENCODING_UTF16BE 0x02
+#define ID3V2_ENCODING_UTF8 0x03
+
+extern guint read_synch_uint (guint8 * data, guint size);
+
+gboolean
+id3demux_id3v2_parse_frame (ID3TagsWorking * work)
+{
+ const gchar *tag_name;
+ gboolean result = FALSE;
+ gint i;
+ guint8 *frame_data = work->hdr.frame_data;
+ guint frame_data_size = work->cur_frame_size;
+ gchar *tag_str = NULL;
+
+ /* Check that the frame id is valid */
+ for (i = 0; i < 5 && work->frame_id[i] != '\0'; i++) {
+ if (!g_ascii_isalnum (work->frame_id[i])) {
+ GST_DEBUG ("Encountered invalid frame_id");
+ return FALSE;
+ }
+ }
+
+ /* Can't handle encrypted frames right now */
+ if (work->frame_flags & ID3V2_FRAME_FORMAT_ENCRYPTION) {
+ GST_WARNING ("Encrypted frames are not supported");
+ return FALSE;
+ }
+
+ if (work->frame_flags & ID3V2_FRAME_FORMAT_UNSYNCHRONISATION) {
+ GST_WARNING ("ID3v2 frame with unsupported unsynchronisation applied. "
+ "May fail badly");
+ }
+
+ tag_name = gst_tag_from_id3_tag (work->frame_id);
+ if (tag_name == NULL)
+ return FALSE;
+
+ if (work->frame_flags & (ID3V2_FRAME_FORMAT_COMPRESSION |
+ ID3V2_FRAME_FORMAT_DATA_LENGTH_INDICATOR)) {
+ if (work->hdr.frame_data_size <= 4)
+ return FALSE;
+ work->parse_size = read_synch_uint (frame_data, 4);
+ frame_data += 4;
+ frame_data_size -= 4;
+ } else
+ work->parse_size = frame_data_size;
+
+ if (work->frame_flags & ID3V2_FRAME_FORMAT_COMPRESSION) {
+ uLongf destSize = work->parse_size;
+ Bytef *dest, *src;
+
+ work->parse_data = g_malloc (work->parse_size);
+ g_return_val_if_fail (work->parse_data != NULL, FALSE);
+
+ dest = (Bytef *) work->parse_data;
+ src = (Bytef *) frame_data;
+
+ if (uncompress (dest, &destSize, src, frame_data_size) != Z_OK) {
+ g_free (work->parse_data);
+ return FALSE;
+ }
+ } else {
+ work->parse_data = work->hdr.frame_data;
+ }
+
+ if (work->frame_id[0] == 'T') {
+ if (strcmp (work->frame_id, "TXXX") != 0) {
+ /* Text identification frame */
+ tag_str = parse_text_identification_frame (work);
+ } else {
+ /* Handle user text frame */
+ }
+ } else if (!strcmp (work->frame_id, "COMM")) {
+ /* Comment */
+ tag_str = parse_comment_frame (work);
+ } else if (!strcmp (work->frame_id, "APIC")) {
+ /* Attached picture */
+ } else if (!strcmp (work->frame_id, "RVA2")) {
+ /* Relative volume */
+ } else if (!strcmp (work->frame_id, "UFID")) {
+ /* Unique file identifier */
+ }
+
+ if (work->frame_flags & ID3V2_FRAME_FORMAT_COMPRESSION) {
+ g_free (work->parse_data);
+ }
+
+ if (tag_str != NULL) {
+ /* g_print ("Tag %s value %s\n", tag_name, tag_str); */
+ result = id3v2_tag_to_taglist (work, tag_name, tag_str);
+ g_free (tag_str);
+ }
+
+ return result;
+}
+
+static gchar *
+parse_comment_frame (ID3TagsWorking * work)
+{
+ guint8 encoding;
+ gchar language[4];
+ gchar *description = NULL;
+ gchar *text = NULL;
+ gchar *out_str = NULL;
+
+ if (work->parse_size < 6)
+ return NULL;
+
+ encoding = work->parse_data[0];
+ language[0] = work->parse_data[1];
+ language[1] = work->parse_data[2];
+ language[2] = work->parse_data[3];
+ language[3] = 0;
+
+ parse_split_strings (work, encoding, &description, &text);
+
+ if (text == NULL || description == NULL) {
+ GST_ERROR ("Failed to decode comment frame");
+ goto fail;
+ }
+
+ if (!g_utf8_validate (text, -1, NULL)) {
+ GST_ERROR ("Converted string is not valid utf-8");
+ goto fail;
+ } else {
+ if (strlen (description) > 0 && g_utf8_validate (description, -1, NULL)) {
+ out_str = g_strdup_printf ("Description: %s\nComment: %s",
+ description, text);
+ } else {
+ out_str = g_strdup (text);
+ }
+ }
+
+fail:
+ g_free (description);
+ g_free (text);
+
+ return out_str;
+}
+
+static gchar *
+parse_text_identification_frame (ID3TagsWorking * work)
+{
+ guchar encoding;
+ gchar *text = NULL;
+
+ if (work->parse_size < 2)
+ return NULL;
+
+ encoding = work->parse_data[0];
+
+ switch (encoding) {
+ case ID3V2_ENCODING_ISO8859:
+ text = g_convert ((gchar *) (work->parse_data + 1),
+ work->parse_size - 1, "UTF-8", "ISO-8859-1", NULL, NULL, NULL);
+ break;
+ case ID3V2_ENCODING_UTF8:
+ text = g_strndup ((gchar *) (work->parse_data + 1), work->parse_size - 1);
+ break;
+ case ID3V2_ENCODING_UTF16:
+ text = g_convert ((gchar *) (work->parse_data + 1),
+ work->parse_size - 1, "UTF-8", "UTF-16", NULL, NULL, NULL);
+ break;
+ case ID3V2_ENCODING_UTF16BE:
+ text = g_convert ((gchar *) (work->parse_data + 1),
+ work->parse_size - 1, "UTF-8", "UTF-16BE", NULL, NULL, NULL);
+ break;
+ }
+
+ if (text != NULL && !g_utf8_validate (text, -1, NULL)) {
+ GST_ERROR ("Converted string is not valid utf-8");
+ g_free (text);
+ text = NULL;
+ }
+
+ return text;
+}
+
+static gboolean
+id3v2_tag_to_taglist (ID3TagsWorking * work, const gchar * tag_name,
+ gchar * tag_str)
+{
+ GType tag_type = gst_tag_get_type (tag_name);
+ GstTagList *tag_list = work->tags;
+
+ switch (tag_type) {
+ case G_TYPE_UINT:
+ {
+ guint tmp;
+ gchar *check;
+
+ tmp = strtoul ((char *) tag_str, &check, 10);
+
+ if (strcmp (tag_name, GST_TAG_DATE) == 0) {
+ GDate *d;
+
+ if (*check != '\0')
+ break;
+ if (tmp == 0)
+ break;
+ d = g_date_new_dmy (1, 1, tmp);
+ tmp = g_date_get_julian (d);
+ g_date_free (d);
+ } else if (strcmp (tag_name, GST_TAG_TRACK_NUMBER) == 0) {
+ if (*check == '/') {
+ guint total;
+
+ check++;
+ total = strtoul (check, &check, 10);
+ if (*check != '\0')
+ break;
+
+ gst_tag_list_add (tag_list, GST_TAG_MERGE_APPEND,
+ GST_TAG_TRACK_COUNT, total, NULL);
+ }
+ } else if (strcmp (tag_name, GST_TAG_ALBUM_VOLUME_NUMBER) == 0) {
+ if (*check == '/') {
+ guint total;
+
+ check++;
+ total = strtoul (check, &check, 10);
+ if (*check != '\0')
+ break;
+
+ gst_tag_list_add (tag_list, GST_TAG_MERGE_APPEND,
+ GST_TAG_ALBUM_VOLUME_COUNT, total, NULL);
+ }
+ }
+
+ if (*check != '\0')
+ break;
+
+ gst_tag_list_add (tag_list, GST_TAG_MERGE_APPEND, tag_name, tmp, NULL);
+ break;
+ }
+ case G_TYPE_UINT64:
+ {
+ guint64 tmp;
+
+ g_assert (strcmp (tag_name, GST_TAG_DURATION) == 0);
+ tmp = strtoul ((char *) tag_str, NULL, 10);
+ if (tmp == 0) {
+ break;
+ }
+ gst_tag_list_add (tag_list, GST_TAG_MERGE_APPEND,
+ GST_TAG_DURATION, tmp * 1000 * 1000, NULL);
+ break;
+ }
+ case G_TYPE_STRING:{
+ gst_tag_list_add (tag_list, GST_TAG_MERGE_APPEND,
+ tag_name, (const gchar *) tag_str, NULL);
+ break;
+ }
+ /* handles GST_TYPE_DATE and anything else */
+ default:{
+ GValue src = { 0, };
+ GValue dest = { 0, };
+
+ g_value_init (&src, G_TYPE_STRING);
+ g_value_set_string (&src, (const gchar *) tag_str);
+
+ g_value_init (&dest, tag_type);
+ if (g_value_transform (&src, &dest)) {
+ gst_tag_list_add_values (tag_list, GST_TAG_MERGE_APPEND,
+ tag_name, &dest, NULL);
+ } else {
+ GST_WARNING ("Failed to transform tag from string to type '%s'",
+ g_type_name (tag_type));
+ }
+ g_value_unset (&src);
+ g_value_unset (&dest);
+ break;
+ }
+ }
+
+ return TRUE;
+}
+
+static void
+parse_split_strings (ID3TagsWorking * work, guint8 encoding,
+ gchar ** field1, gchar ** field2)
+{
+ guint text_pos;
+
+ *field1 = *field2 = NULL;
+
+ switch (encoding) {
+ case ID3V2_ENCODING_ISO8859:
+ for (text_pos = 4; text_pos < work->parse_size - 1; text_pos++) {
+ if (work->parse_data[text_pos] == 0) {
+ *field1 = g_convert ((gchar *) (work->parse_data + 4),
+ text_pos - 4, "UTF-8", "ISO-8859-1", NULL, NULL, NULL);
+ *field2 = g_convert ((gchar *) (work->parse_data + text_pos + 5),
+ work->parse_size - text_pos - 5,
+ "UTF-8", "ISO-8859-1", NULL, NULL, NULL);
+ break;
+ }
+ }
+ break;
+ case ID3V2_ENCODING_UTF8:
+ *field1 = g_strndup ((gchar *) (work->parse_data + 4),
+ work->parse_size - 4);
+ text_pos = 4 + strlen (*field1) + 1; /* Offset by one more for the null */
+ if (text_pos < work->parse_size) {
+ *field2 = g_strndup ((gchar *) (work->parse_data + text_pos),
+ work->parse_size - text_pos);
+ }
+ break;
+ case ID3V2_ENCODING_UTF16:
+ case ID3V2_ENCODING_UTF16BE:
+ {
+ /* Find '\0\0' terminator */
+ for (text_pos = 4; text_pos < work->parse_size - 2; text_pos++) {
+ if (work->parse_data[text_pos] == 0 &&
+ work->parse_data[text_pos + 1] == 0) {
+ /* found our delimiter */
+ if (encoding == ID3V2_ENCODING_UTF16) {
+ *field1 = g_convert ((gchar *) (work->parse_data + 4),
+ text_pos - 4, "UTF-8", "UTF-16", NULL, NULL, NULL);
+ *field2 = g_convert ((gchar *) (work->parse_data + text_pos + 6),
+ work->parse_size - text_pos - 6,
+ "UTF-8", "UTF-16", NULL, NULL, NULL);
+ } else {
+ *field1 = g_convert ((gchar *) (work->parse_data + 4),
+ text_pos - 4, "UTF-8", "UTF-16BE", NULL, NULL, NULL);
+ *field2 = g_convert ((gchar *) (work->parse_data + text_pos + 6),
+ work->parse_size - text_pos - 6,
+ "UTF-8", "UTF-16BE", NULL, NULL, NULL);
+ }
+ break;
+ }
+ }
+ break;
+ }
+ }
+}