2009-05-21 20:15:46 +00:00
|
|
|
/* GStreamer ID3 v1 and v2 muxer
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006 Christophe Fergeau <teuf@gnome.org>
|
2012-08-21 09:22:49 +00:00
|
|
|
* Copyright (C) 2006-2012 Tim-Philipp Müller <tim centricular net>
|
2009-05-21 20:15:46 +00:00
|
|
|
* Copyright (C) 2009 Pioneers of the Inevitable <songbird@songbirdnest.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
|
2012-11-03 20:38:00 +00:00
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
2009-05-21 20:15:46 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2009-06-05 23:39:10 +00:00
|
|
|
* SECTION:element-id3mux
|
2009-05-21 20:15:46 +00:00
|
|
|
* @see_also: #GstID3Demux, #GstTagSetter
|
|
|
|
*
|
|
|
|
* This element adds ID3v2 tags to the beginning of a stream, and ID3v1 tags
|
|
|
|
* to the end.
|
2009-06-05 23:39:10 +00:00
|
|
|
*
|
2009-05-21 20:15:46 +00:00
|
|
|
* It defaults to writing ID3 version 2.3.0 tags (since those are the most
|
|
|
|
* widely supported), but can optionally write version 2.4.0 tags.
|
|
|
|
*
|
|
|
|
* Applications can set the tags to write using the #GstTagSetter interface.
|
|
|
|
* Tags sent by upstream elements will be picked up automatically (and merged
|
|
|
|
* according to the merge mode set via the tag setter interface).
|
|
|
|
*
|
|
|
|
* <refsect2>
|
|
|
|
* <title>Example pipelines</title>
|
|
|
|
* |[
|
2009-06-05 23:39:10 +00:00
|
|
|
* gst-launch -v filesrc location=foo.ogg ! decodebin ! audioconvert ! lame ! id3mux ! filesink location=foo.mp3
|
2009-05-21 20:15:46 +00:00
|
|
|
* ]| A pipeline that transcodes a file from Ogg/Vorbis to mp3 format with
|
|
|
|
* ID3 tags that contain the same metadata as the the Ogg/Vorbis file.
|
|
|
|
* Make sure the Ogg/Vorbis file actually has comments to preserve.
|
|
|
|
* |[
|
|
|
|
* gst-launch -m filesrc location=foo.mp3 ! id3demux ! fakesink silent=TRUE 2> /dev/null | grep taglist
|
|
|
|
* ]| Verify that tags have been written.
|
|
|
|
* </refsect2>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include <config.h>
|
|
|
|
#endif
|
|
|
|
|
2009-06-05 23:39:10 +00:00
|
|
|
#include "gstid3mux.h"
|
2009-05-21 20:15:46 +00:00
|
|
|
#include <gst/tag/tag.h>
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
2009-06-05 23:39:10 +00:00
|
|
|
GST_DEBUG_CATEGORY (gst_id3_mux_debug);
|
|
|
|
#define GST_CAT_DEFAULT gst_id3_mux_debug
|
2009-05-21 20:15:46 +00:00
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
ARG_0,
|
|
|
|
ARG_WRITE_V1,
|
|
|
|
ARG_WRITE_V2,
|
|
|
|
ARG_V2_MAJOR_VERSION
|
|
|
|
};
|
|
|
|
|
2009-06-06 00:05:49 +00:00
|
|
|
#define DEFAULT_WRITE_V1 FALSE
|
2009-05-21 20:15:46 +00:00
|
|
|
#define DEFAULT_WRITE_V2 TRUE
|
|
|
|
#define DEFAULT_V2_MAJOR_VERSION 3
|
|
|
|
|
2011-07-28 19:38:37 +00:00
|
|
|
static GstStaticPadTemplate sink_template = GST_STATIC_PAD_TEMPLATE ("sink",
|
|
|
|
GST_PAD_SINK,
|
|
|
|
GST_PAD_ALWAYS,
|
|
|
|
GST_STATIC_CAPS ("ANY"));
|
|
|
|
|
2009-05-21 20:15:46 +00:00
|
|
|
static GstStaticPadTemplate src_template = GST_STATIC_PAD_TEMPLATE ("src",
|
|
|
|
GST_PAD_SRC,
|
|
|
|
GST_PAD_ALWAYS,
|
|
|
|
GST_STATIC_CAPS ("application/x-id3"));
|
|
|
|
|
2012-08-21 09:22:49 +00:00
|
|
|
G_DEFINE_TYPE (GstId3Mux, gst_id3_mux, GST_TYPE_TAG_MUX);
|
2009-05-21 20:15:46 +00:00
|
|
|
|
2009-06-05 23:39:10 +00:00
|
|
|
static GstBuffer *gst_id3_mux_render_v2_tag (GstTagMux * mux,
|
2011-07-15 19:57:47 +00:00
|
|
|
const GstTagList * taglist);
|
2009-06-05 23:39:10 +00:00
|
|
|
static GstBuffer *gst_id3_mux_render_v1_tag (GstTagMux * mux,
|
2011-07-15 19:57:47 +00:00
|
|
|
const GstTagList * taglist);
|
2009-05-21 20:15:46 +00:00
|
|
|
|
2009-06-05 23:39:10 +00:00
|
|
|
static void gst_id3_mux_set_property (GObject * object, guint prop_id,
|
2009-05-21 20:15:46 +00:00
|
|
|
const GValue * value, GParamSpec * pspec);
|
2009-06-05 23:39:10 +00:00
|
|
|
static void gst_id3_mux_get_property (GObject * object, guint prop_id,
|
2009-05-21 20:15:46 +00:00
|
|
|
GValue * value, GParamSpec * pspec);
|
|
|
|
|
|
|
|
static void
|
2009-06-05 23:39:10 +00:00
|
|
|
gst_id3_mux_class_init (GstId3MuxClass * klass)
|
2009-05-21 20:15:46 +00:00
|
|
|
{
|
2012-08-21 09:22:49 +00:00
|
|
|
GstElementClass *element_class = (GstElementClass *) klass;
|
2009-05-21 20:15:46 +00:00
|
|
|
GObjectClass *gobject_class = (GObjectClass *) klass;
|
|
|
|
|
2009-06-05 23:39:10 +00:00
|
|
|
gobject_class->set_property = gst_id3_mux_set_property;
|
|
|
|
gobject_class->get_property = gst_id3_mux_get_property;
|
2009-05-21 20:15:46 +00:00
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class, ARG_WRITE_V1,
|
|
|
|
g_param_spec_boolean ("write-v1", "Write id3v1 tag",
|
|
|
|
"Write an id3v1 tag at the end of the file", DEFAULT_WRITE_V1,
|
2010-10-19 10:43:14 +00:00
|
|
|
G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS));
|
2009-05-21 20:15:46 +00:00
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class, ARG_WRITE_V2,
|
|
|
|
g_param_spec_boolean ("write-v2", "Write id3v2 tag",
|
|
|
|
"Write an id3v2 tag at the start of the file", DEFAULT_WRITE_V2,
|
2010-10-19 10:43:14 +00:00
|
|
|
G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS));
|
2009-05-21 20:15:46 +00:00
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class, ARG_V2_MAJOR_VERSION,
|
|
|
|
g_param_spec_int ("v2-version", "Version (3 or 4) of id3v2 tag",
|
|
|
|
"Set version (3 for id3v2.3, 4 for id3v2.4) of id3v2 tags",
|
|
|
|
3, 4, DEFAULT_V2_MAJOR_VERSION,
|
2010-10-19 10:43:14 +00:00
|
|
|
G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS));
|
2009-05-21 20:15:46 +00:00
|
|
|
|
|
|
|
GST_TAG_MUX_CLASS (klass)->render_start_tag =
|
2009-06-05 23:39:10 +00:00
|
|
|
GST_DEBUG_FUNCPTR (gst_id3_mux_render_v2_tag);
|
2011-07-15 19:57:47 +00:00
|
|
|
GST_TAG_MUX_CLASS (klass)->render_end_tag =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_id3_mux_render_v1_tag);
|
2012-08-21 09:22:49 +00:00
|
|
|
|
2012-10-17 16:34:26 +00:00
|
|
|
gst_element_class_set_static_metadata (element_class,
|
2012-08-21 09:22:49 +00:00
|
|
|
"ID3 v1 and v2 Muxer", "Formatter/Metadata",
|
|
|
|
"Adds an ID3v2 header and ID3v1 footer to a file",
|
|
|
|
"Michael Smith <msmith@songbirdnest.com>, "
|
|
|
|
"Tim-Philipp Müller <tim centricular net>");
|
|
|
|
|
|
|
|
gst_element_class_add_pad_template (element_class,
|
|
|
|
gst_static_pad_template_get (&sink_template));
|
|
|
|
|
|
|
|
gst_element_class_add_pad_template (element_class,
|
|
|
|
gst_static_pad_template_get (&src_template));
|
2009-05-21 20:15:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-08-21 09:22:49 +00:00
|
|
|
gst_id3_mux_init (GstId3Mux * id3mux)
|
2009-05-21 20:15:46 +00:00
|
|
|
{
|
|
|
|
id3mux->write_v1 = DEFAULT_WRITE_V1;
|
|
|
|
id3mux->write_v2 = DEFAULT_WRITE_V2;
|
|
|
|
|
|
|
|
id3mux->v2_major_version = DEFAULT_V2_MAJOR_VERSION;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-06-05 23:39:10 +00:00
|
|
|
gst_id3_mux_set_property (GObject * object, guint prop_id,
|
2009-05-21 20:15:46 +00:00
|
|
|
const GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
2009-06-05 23:39:10 +00:00
|
|
|
GstId3Mux *mux = GST_ID3_MUX (object);
|
2009-05-21 20:15:46 +00:00
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case ARG_WRITE_V1:
|
|
|
|
mux->write_v1 = g_value_get_boolean (value);
|
|
|
|
break;
|
|
|
|
case ARG_WRITE_V2:
|
|
|
|
mux->write_v2 = g_value_get_boolean (value);
|
|
|
|
break;
|
|
|
|
case ARG_V2_MAJOR_VERSION:
|
|
|
|
mux->v2_major_version = g_value_get_int (value);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-06-05 23:39:10 +00:00
|
|
|
gst_id3_mux_get_property (GObject * object, guint prop_id,
|
2009-05-21 20:15:46 +00:00
|
|
|
GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
2009-06-05 23:39:10 +00:00
|
|
|
GstId3Mux *mux = GST_ID3_MUX (object);
|
2009-05-21 20:15:46 +00:00
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case ARG_WRITE_V1:
|
|
|
|
g_value_set_boolean (value, mux->write_v1);
|
|
|
|
break;
|
|
|
|
case ARG_WRITE_V2:
|
|
|
|
g_value_set_boolean (value, mux->write_v2);
|
|
|
|
break;
|
|
|
|
case ARG_V2_MAJOR_VERSION:
|
|
|
|
g_value_set_int (value, mux->v2_major_version);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstBuffer *
|
2011-07-15 19:57:47 +00:00
|
|
|
gst_id3_mux_render_v2_tag (GstTagMux * mux, const GstTagList * taglist)
|
2009-05-21 20:15:46 +00:00
|
|
|
{
|
2009-06-05 23:39:10 +00:00
|
|
|
GstId3Mux *id3mux = GST_ID3_MUX (mux);
|
2009-05-21 20:15:46 +00:00
|
|
|
|
|
|
|
if (id3mux->write_v2)
|
2009-06-05 23:39:10 +00:00
|
|
|
return id3_mux_render_v2_tag (mux, taglist, id3mux->v2_major_version);
|
2009-05-21 20:15:46 +00:00
|
|
|
else
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstBuffer *
|
2011-07-15 19:57:47 +00:00
|
|
|
gst_id3_mux_render_v1_tag (GstTagMux * mux, const GstTagList * taglist)
|
2009-05-21 20:15:46 +00:00
|
|
|
{
|
2009-06-05 23:39:10 +00:00
|
|
|
GstId3Mux *id3mux = GST_ID3_MUX (mux);
|
2009-05-21 20:15:46 +00:00
|
|
|
|
|
|
|
if (id3mux->write_v1)
|
2009-06-05 23:39:10 +00:00
|
|
|
return id3_mux_render_v1_tag (mux, taglist);
|
2009-05-21 20:15:46 +00:00
|
|
|
else
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
plugin_init (GstPlugin * plugin)
|
|
|
|
{
|
2009-06-05 23:39:10 +00:00
|
|
|
GST_DEBUG_CATEGORY_INIT (gst_id3_mux_debug, "id3mux", 0,
|
|
|
|
"ID3 v1 and v2 tag muxer");
|
|
|
|
|
2010-12-22 17:13:04 +00:00
|
|
|
if (!gst_element_register (plugin, "id3mux", GST_RANK_PRIMARY,
|
|
|
|
GST_TYPE_ID3_MUX))
|
2009-05-21 20:15:46 +00:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
gst_tag_register_musicbrainz_tags ();
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
|
|
|
|
GST_VERSION_MINOR,
|
2012-04-05 16:02:56 +00:00
|
|
|
id3tag,
|
2009-05-21 20:15:46 +00:00
|
|
|
"ID3 v1 and v2 muxing plugin",
|
|
|
|
plugin_init, VERSION, "LGPL", GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN);
|