mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-03-27 11:32:51 +00:00
id3tag: Add new id3 tagging plugin, supports v1, v2.3, and v2.4.
By default, does v1 and v2.3, but there are properties to select. Will hopefully replace id3mux, id3v2mux, in the not-too-distant future.
This commit is contained in:
parent
b9ac26713b
commit
fe38f53572
8 changed files with 2108 additions and 0 deletions
|
@ -265,6 +265,7 @@ AG_GST_CHECK_PLUGIN(dvdspu)
|
|||
AG_GST_CHECK_PLUGIN(festival)
|
||||
AG_GST_CHECK_PLUGIN(freeze)
|
||||
AG_GST_CHECK_PLUGIN(h264parse)
|
||||
AG_GST_CHECK_PLUGIN(id3tag)
|
||||
AG_GST_CHECK_PLUGIN(librfb)
|
||||
AG_GST_CHECK_PLUGIN(liveadder)
|
||||
AG_GST_CHECK_PLUGIN(mpegdemux)
|
||||
|
@ -1574,6 +1575,7 @@ gst/dvdspu/Makefile
|
|||
gst/festival/Makefile
|
||||
gst/freeze/Makefile
|
||||
gst/h264parse/Makefile
|
||||
gst/id3tag/Makefile
|
||||
gst/librfb/Makefile
|
||||
gst/mpegdemux/Makefile
|
||||
gst/mpegtsmux/Makefile
|
||||
|
|
19
gst/id3tag/Makefile.am
Normal file
19
gst/id3tag/Makefile.am
Normal file
|
@ -0,0 +1,19 @@
|
|||
plugin_LTLIBRARIES = libgstid3tag.la
|
||||
|
||||
libgstid3tag_la_SOURCES = \
|
||||
gsttagmux.c \
|
||||
id3tag.c \
|
||||
gstid3tag.c
|
||||
|
||||
libgstid3tag_la_CFLAGS = \
|
||||
$(GST_PLUGINS_BASE_CFLAGS) \
|
||||
$(GST_CFLAGS)
|
||||
|
||||
libgstid3tag_la_LIBADD = \
|
||||
$(GST_PLUGINS_BASE_LIBS) -lgsttag-$(GST_MAJORMINOR) \
|
||||
$(GST_LIBS)
|
||||
|
||||
libgstid3tag_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
|
||||
libgstid3tag_la_LIBTOOLFLAGS = --tag=disable-static
|
||||
|
||||
noinst_HEADERS = gstid3tag.h id3tag.h gsttagmux.h
|
229
gst/id3tag/gstid3tag.c
Normal file
229
gst/id3tag/gstid3tag.c
Normal file
|
@ -0,0 +1,229 @@
|
|||
/* GStreamer ID3 v1 and v2 muxer
|
||||
*
|
||||
* Copyright (C) 2006 Christophe Fergeau <teuf@gnome.org>
|
||||
* Copyright (C) 2006 Tim-Philipp Müller <tim centricular net>
|
||||
* 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
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
/**
|
||||
* SECTION:element-id3tag
|
||||
* @see_also: #GstID3Demux, #GstTagSetter
|
||||
*
|
||||
* This element adds ID3v2 tags to the beginning of a stream, and ID3v1 tags
|
||||
* to the end.
|
||||
*
|
||||
* 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>
|
||||
* |[
|
||||
* gst-launch -v filesrc location=foo.ogg ! decodebin ! audioconvert ! lame ! id3tag ! filesink location=foo.mp3
|
||||
* ]| 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
|
||||
|
||||
#include "gstid3tag.h"
|
||||
#include <gst/tag/tag.h>
|
||||
|
||||
#include <string.h>
|
||||
|
||||
GST_DEBUG_CATEGORY (gst_id3tag_debug);
|
||||
#define GST_CAT_DEFAULT gst_id3tag_debug
|
||||
|
||||
enum
|
||||
{
|
||||
ARG_0,
|
||||
ARG_WRITE_V1,
|
||||
ARG_WRITE_V2,
|
||||
ARG_V2_MAJOR_VERSION
|
||||
};
|
||||
|
||||
#define DEFAULT_WRITE_V1 TRUE
|
||||
#define DEFAULT_WRITE_V2 TRUE
|
||||
#define DEFAULT_V2_MAJOR_VERSION 3
|
||||
|
||||
static GstStaticPadTemplate src_template = GST_STATIC_PAD_TEMPLATE ("src",
|
||||
GST_PAD_SRC,
|
||||
GST_PAD_ALWAYS,
|
||||
GST_STATIC_CAPS ("application/x-id3"));
|
||||
|
||||
GST_BOILERPLATE (GstID3Tag, gst_id3tag, GstTagMux, GST_TYPE_TAG_MUX);
|
||||
|
||||
static GstBuffer *gst_id3tag_render_v2_tag (GstTagMux * mux,
|
||||
GstTagList * taglist);
|
||||
static GstBuffer *gst_id3tag_render_v1_tag (GstTagMux * mux,
|
||||
GstTagList * taglist);
|
||||
|
||||
static void gst_id3tag_set_property (GObject * object, guint prop_id,
|
||||
const GValue * value, GParamSpec * pspec);
|
||||
static void gst_id3tag_get_property (GObject * object, guint prop_id,
|
||||
GValue * value, GParamSpec * pspec);
|
||||
|
||||
static void
|
||||
gst_id3tag_base_init (gpointer g_class)
|
||||
{
|
||||
GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
|
||||
|
||||
gst_element_class_add_pad_template (element_class,
|
||||
gst_static_pad_template_get (&src_template));
|
||||
|
||||
gst_element_class_set_details_simple (element_class,
|
||||
"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_DEBUG_CATEGORY_INIT (gst_id3tag_debug, "id3tag", 0,
|
||||
"ID3 v1 and v2 tag muxer");
|
||||
}
|
||||
|
||||
static void
|
||||
gst_id3tag_class_init (GstID3TagClass * klass)
|
||||
{
|
||||
GObjectClass *gobject_class = (GObjectClass *) klass;
|
||||
|
||||
gobject_class->set_property = gst_id3tag_set_property;
|
||||
gobject_class->get_property = gst_id3tag_get_property;
|
||||
|
||||
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,
|
||||
G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
|
||||
|
||||
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,
|
||||
G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
|
||||
|
||||
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,
|
||||
G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
|
||||
|
||||
GST_TAG_MUX_CLASS (klass)->render_start_tag =
|
||||
GST_DEBUG_FUNCPTR (gst_id3tag_render_v2_tag);
|
||||
|
||||
GST_TAG_MUX_CLASS (klass)->render_end_tag = gst_id3tag_render_v1_tag;
|
||||
}
|
||||
|
||||
static void
|
||||
gst_id3tag_init (GstID3Tag * id3mux, GstID3TagClass * id3mux_class)
|
||||
{
|
||||
id3mux->write_v1 = DEFAULT_WRITE_V1;
|
||||
id3mux->write_v2 = DEFAULT_WRITE_V2;
|
||||
|
||||
id3mux->v2_major_version = DEFAULT_V2_MAJOR_VERSION;
|
||||
}
|
||||
|
||||
static void
|
||||
gst_id3tag_set_property (GObject * object, guint prop_id,
|
||||
const GValue * value, GParamSpec * pspec)
|
||||
{
|
||||
GstID3Tag *mux = GST_ID3TAG (object);
|
||||
|
||||
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
|
||||
gst_id3tag_get_property (GObject * object, guint prop_id,
|
||||
GValue * value, GParamSpec * pspec)
|
||||
{
|
||||
GstID3Tag *mux = GST_ID3TAG (object);
|
||||
|
||||
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 *
|
||||
gst_id3tag_render_v2_tag (GstTagMux * mux, GstTagList * taglist)
|
||||
{
|
||||
GstID3Tag *id3mux = GST_ID3TAG (mux);
|
||||
|
||||
if (id3mux->write_v2)
|
||||
return gst_id3mux_render_v2_tag (mux, taglist, id3mux->v2_major_version);
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static GstBuffer *
|
||||
gst_id3tag_render_v1_tag (GstTagMux * mux, GstTagList * taglist)
|
||||
{
|
||||
GstID3Tag *id3mux = GST_ID3TAG (mux);
|
||||
|
||||
if (id3mux->write_v1)
|
||||
return gst_id3mux_render_v1_tag (mux, taglist);
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
plugin_init (GstPlugin * plugin)
|
||||
{
|
||||
if (!gst_element_register (plugin, "id3tag", GST_RANK_NONE, GST_TYPE_ID3TAG))
|
||||
return FALSE;
|
||||
|
||||
gst_tag_register_musicbrainz_tags ();
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
|
||||
GST_VERSION_MINOR,
|
||||
"id3tag",
|
||||
"ID3 v1 and v2 muxing plugin",
|
||||
plugin_init, VERSION, "LGPL", GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN);
|
63
gst/id3tag/gstid3tag.h
Normal file
63
gst/id3tag/gstid3tag.h
Normal file
|
@ -0,0 +1,63 @@
|
|||
/* GStreamer ID3 v1 and v2 muxer
|
||||
*
|
||||
* Copyright (C) 2006 Christophe Fergeau <teuf@gnome.org>
|
||||
* Copyright (C) 2006 Tim-Philipp Müller <tim centricular net>
|
||||
* 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
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifndef GST_ID3TAG_H
|
||||
#define GST_ID3TAG_H
|
||||
|
||||
#include "gsttagmux.h"
|
||||
#include "id3tag.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
typedef struct _GstID3Tag GstID3Tag;
|
||||
typedef struct _GstID3TagClass GstID3TagClass;
|
||||
|
||||
struct _GstID3Tag {
|
||||
GstTagMux tagmux;
|
||||
|
||||
gboolean write_v1;
|
||||
gboolean write_v2;
|
||||
|
||||
gint v2_major_version;
|
||||
};
|
||||
|
||||
struct _GstID3TagClass {
|
||||
GstTagMuxClass tagmux_class;
|
||||
};
|
||||
|
||||
#define GST_TYPE_ID3TAG \
|
||||
(gst_id3tag_get_type())
|
||||
#define GST_ID3TAG(obj) \
|
||||
(G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_ID3TAG,GstID3Tag))
|
||||
#define GST_ID3TAG_CLASS(klass) \
|
||||
(G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_ID3TAG,GstID3TagClass))
|
||||
#define GST_IS_ID3TAG(obj) \
|
||||
(G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_ID3TAG))
|
||||
#define GST_IS_ID3TAG_CLASS(klass) \
|
||||
(G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_ID3TAG))
|
||||
|
||||
GType gst_id3tag_get_type (void);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* GST_ID3TAG_H */
|
||||
|
490
gst/id3tag/gsttagmux.c
Normal file
490
gst/id3tag/gsttagmux.c
Normal file
|
@ -0,0 +1,490 @@
|
|||
/* GStreamer tag muxer base class
|
||||
*
|
||||
* Copyright (C) 2006 Christophe Fergeau <teuf@gnome.org>
|
||||
* Copyright (C) 2006 Tim-Philipp Müller <tim centricular net>
|
||||
* Copyright (C) 2006 Sebastian Dröge <slomo@circular-chaos.org>
|
||||
* 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
|
||||
* 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/gsttagsetter.h>
|
||||
#include <gst/tag/tag.h>
|
||||
|
||||
#include "gsttagmux.h"
|
||||
|
||||
GST_DEBUG_CATEGORY_STATIC (gst_tag_mux_debug);
|
||||
#define GST_CAT_DEFAULT gst_tag_mux_debug
|
||||
|
||||
/* Subclass provides a src template and pad. We accept anything as input here,
|
||||
however. */
|
||||
|
||||
static GstStaticPadTemplate gst_tag_mux_sink_template =
|
||||
GST_STATIC_PAD_TEMPLATE ("sink",
|
||||
GST_PAD_SINK,
|
||||
GST_PAD_ALWAYS,
|
||||
GST_STATIC_CAPS ("ANY"));
|
||||
|
||||
static void
|
||||
gst_tag_mux_iface_init (GType tag_type)
|
||||
{
|
||||
static const GInterfaceInfo tag_setter_info = {
|
||||
NULL,
|
||||
NULL,
|
||||
NULL
|
||||
};
|
||||
|
||||
g_type_add_interface_static (tag_type, GST_TYPE_TAG_SETTER, &tag_setter_info);
|
||||
}
|
||||
|
||||
GST_BOILERPLATE_FULL (GstTagMux, gst_tag_mux,
|
||||
GstElement, GST_TYPE_ELEMENT, gst_tag_mux_iface_init);
|
||||
|
||||
|
||||
static GstStateChangeReturn
|
||||
gst_tag_mux_change_state (GstElement * element, GstStateChange transition);
|
||||
static GstFlowReturn gst_tag_mux_chain (GstPad * pad, GstBuffer * buffer);
|
||||
static gboolean gst_tag_mux_sink_event (GstPad * pad, GstEvent * event);
|
||||
|
||||
static void
|
||||
gst_tag_mux_finalize (GObject * obj)
|
||||
{
|
||||
GstTagMux *mux = GST_TAG_MUX (obj);
|
||||
|
||||
if (mux->newsegment_ev) {
|
||||
gst_event_unref (mux->newsegment_ev);
|
||||
mux->newsegment_ev = NULL;
|
||||
}
|
||||
|
||||
if (mux->event_tags) {
|
||||
gst_tag_list_free (mux->event_tags);
|
||||
mux->event_tags = NULL;
|
||||
}
|
||||
|
||||
if (mux->final_tags) {
|
||||
gst_tag_list_free (mux->final_tags);
|
||||
mux->final_tags = NULL;
|
||||
}
|
||||
|
||||
G_OBJECT_CLASS (parent_class)->finalize (obj);
|
||||
}
|
||||
|
||||
static void
|
||||
gst_tag_mux_base_init (gpointer g_class)
|
||||
{
|
||||
GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
|
||||
|
||||
gst_element_class_add_pad_template (element_class,
|
||||
gst_static_pad_template_get (&gst_tag_mux_sink_template));
|
||||
|
||||
GST_DEBUG_CATEGORY_INIT (gst_tag_mux_debug, "tagmux", 0,
|
||||
"tag muxer base class");
|
||||
}
|
||||
|
||||
static void
|
||||
gst_tag_mux_class_init (GstTagMuxClass * klass)
|
||||
{
|
||||
GObjectClass *gobject_class;
|
||||
GstElementClass *gstelement_class;
|
||||
|
||||
gobject_class = (GObjectClass *) klass;
|
||||
gstelement_class = (GstElementClass *) klass;
|
||||
|
||||
gobject_class->finalize = GST_DEBUG_FUNCPTR (gst_tag_mux_finalize);
|
||||
gstelement_class->change_state = GST_DEBUG_FUNCPTR (gst_tag_mux_change_state);
|
||||
}
|
||||
|
||||
static void
|
||||
gst_tag_mux_init (GstTagMux * mux, GstTagMuxClass * mux_class)
|
||||
{
|
||||
GstElementClass *element_klass = GST_ELEMENT_CLASS (mux_class);
|
||||
GstPadTemplate *tmpl;
|
||||
|
||||
/* pad through which data comes in to the element */
|
||||
mux->sinkpad =
|
||||
gst_pad_new_from_static_template (&gst_tag_mux_sink_template, "sink");
|
||||
gst_pad_set_chain_function (mux->sinkpad,
|
||||
GST_DEBUG_FUNCPTR (gst_tag_mux_chain));
|
||||
gst_pad_set_event_function (mux->sinkpad,
|
||||
GST_DEBUG_FUNCPTR (gst_tag_mux_sink_event));
|
||||
gst_element_add_pad (GST_ELEMENT (mux), mux->sinkpad);
|
||||
|
||||
/* pad through which data goes out of the element */
|
||||
tmpl = gst_element_class_get_pad_template (element_klass, "src");
|
||||
if (tmpl) {
|
||||
mux->srcpad = gst_pad_new_from_template (tmpl, "src");
|
||||
gst_pad_use_fixed_caps (mux->srcpad);
|
||||
gst_pad_set_caps (mux->srcpad, gst_pad_template_get_caps (tmpl));
|
||||
gst_element_add_pad (GST_ELEMENT (mux), mux->srcpad);
|
||||
}
|
||||
|
||||
mux->render_start_tag = TRUE;
|
||||
mux->render_end_tag = TRUE;
|
||||
}
|
||||
|
||||
static GstTagList *
|
||||
gst_tag_mux_get_tags (GstTagMux * mux)
|
||||
{
|
||||
GstTagSetter *tagsetter = GST_TAG_SETTER (mux);
|
||||
const GstTagList *tagsetter_tags;
|
||||
GstTagMergeMode merge_mode;
|
||||
|
||||
if (mux->final_tags)
|
||||
return mux->final_tags;
|
||||
|
||||
tagsetter_tags = gst_tag_setter_get_tag_list (tagsetter);
|
||||
merge_mode = gst_tag_setter_get_tag_merge_mode (tagsetter);
|
||||
|
||||
GST_LOG_OBJECT (mux, "merging tags, merge mode = %d", merge_mode);
|
||||
GST_LOG_OBJECT (mux, "event tags: %" GST_PTR_FORMAT, mux->event_tags);
|
||||
GST_LOG_OBJECT (mux, "set tags: %" GST_PTR_FORMAT, tagsetter_tags);
|
||||
|
||||
mux->final_tags =
|
||||
gst_tag_list_merge (tagsetter_tags, mux->event_tags, merge_mode);
|
||||
|
||||
GST_LOG_OBJECT (mux, "final tags: %" GST_PTR_FORMAT, mux->final_tags);
|
||||
|
||||
return mux->final_tags;
|
||||
}
|
||||
|
||||
static GstFlowReturn
|
||||
gst_tag_mux_render_start_tag (GstTagMux * mux)
|
||||
{
|
||||
GstTagMuxClass *klass;
|
||||
GstBuffer *buffer;
|
||||
GstTagList *taglist;
|
||||
GstEvent *event;
|
||||
GstFlowReturn ret;
|
||||
|
||||
taglist = gst_tag_mux_get_tags (mux);
|
||||
|
||||
klass = GST_TAG_MUX_CLASS (G_OBJECT_GET_CLASS (mux));
|
||||
|
||||
if (klass->render_start_tag == NULL)
|
||||
goto no_vfunc;
|
||||
|
||||
buffer = klass->render_start_tag (mux, taglist);
|
||||
|
||||
/* Null buffer is ok, just means we're not outputting anything */
|
||||
if (buffer == NULL) {
|
||||
GST_INFO_OBJECT (mux, "No start tag generated");
|
||||
mux->start_tag_size = 0;
|
||||
return GST_FLOW_OK;
|
||||
}
|
||||
|
||||
mux->start_tag_size = GST_BUFFER_SIZE (buffer);
|
||||
GST_LOG_OBJECT (mux, "tag size = %" G_GSIZE_FORMAT " bytes",
|
||||
mux->start_tag_size);
|
||||
|
||||
/* Send newsegment event from byte position 0, so the tag really gets
|
||||
* written to the start of the file, independent of the upstream segment */
|
||||
gst_pad_push_event (mux->srcpad,
|
||||
gst_event_new_new_segment (FALSE, 1.0, GST_FORMAT_BYTES, 0, -1, 0));
|
||||
|
||||
/* Send an event about the new tags to downstream elements */
|
||||
/* gst_event_new_tag takes ownership of the list, so use a copy */
|
||||
event = gst_event_new_tag (gst_tag_list_copy (taglist));
|
||||
gst_pad_push_event (mux->srcpad, event);
|
||||
|
||||
GST_BUFFER_OFFSET (buffer) = 0;
|
||||
ret = gst_pad_push (mux->srcpad, buffer);
|
||||
|
||||
mux->current_offset = mux->start_tag_size;
|
||||
mux->max_offset = MAX (mux->max_offset, mux->current_offset);
|
||||
|
||||
return ret;
|
||||
|
||||
no_vfunc:
|
||||
{
|
||||
GST_ERROR_OBJECT (mux, "Subclass does not implement "
|
||||
"render_start_tag vfunc!");
|
||||
return GST_FLOW_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
static GstFlowReturn
|
||||
gst_tag_mux_render_end_tag (GstTagMux * mux)
|
||||
{
|
||||
GstTagMuxClass *klass;
|
||||
GstBuffer *buffer;
|
||||
GstTagList *taglist;
|
||||
GstFlowReturn ret;
|
||||
|
||||
taglist = gst_tag_mux_get_tags (mux);
|
||||
|
||||
klass = GST_TAG_MUX_CLASS (G_OBJECT_GET_CLASS (mux));
|
||||
|
||||
if (klass->render_end_tag == NULL)
|
||||
goto no_vfunc;
|
||||
|
||||
buffer = klass->render_end_tag (mux, taglist);
|
||||
|
||||
if (buffer == NULL) {
|
||||
GST_INFO_OBJECT (mux, "No end tag generated");
|
||||
mux->end_tag_size = 0;
|
||||
return GST_FLOW_OK;
|
||||
}
|
||||
|
||||
mux->end_tag_size = GST_BUFFER_SIZE (buffer);
|
||||
GST_LOG_OBJECT (mux, "tag size = %" G_GSIZE_FORMAT " bytes",
|
||||
mux->end_tag_size);
|
||||
|
||||
/* Send newsegment event from the end of the file, so it gets written there,
|
||||
independent of whatever new segment events upstream has sent us */
|
||||
gst_pad_push_event (mux->srcpad,
|
||||
gst_event_new_new_segment (FALSE, 1.0, GST_FORMAT_BYTES, mux->max_offset,
|
||||
-1, 0));
|
||||
|
||||
GST_BUFFER_OFFSET (buffer) = mux->max_offset;
|
||||
ret = gst_pad_push (mux->srcpad, buffer);
|
||||
|
||||
return ret;
|
||||
|
||||
no_vfunc:
|
||||
{
|
||||
GST_ERROR_OBJECT (mux, "Subclass does not implement "
|
||||
"render_end_tag vfunc!");
|
||||
return GST_FLOW_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
static GstEvent *
|
||||
gst_tag_mux_adjust_event_offsets (GstTagMux * mux,
|
||||
const GstEvent * newsegment_event)
|
||||
{
|
||||
GstFormat format;
|
||||
gint64 start, stop, cur;
|
||||
|
||||
gst_event_parse_new_segment ((GstEvent *) newsegment_event, NULL, NULL,
|
||||
&format, &start, &stop, &cur);
|
||||
|
||||
g_assert (format == GST_FORMAT_BYTES);
|
||||
|
||||
if (start != -1)
|
||||
start += mux->start_tag_size;
|
||||
if (stop != -1)
|
||||
stop += mux->start_tag_size;
|
||||
if (cur != -1)
|
||||
cur += mux->start_tag_size;
|
||||
|
||||
GST_DEBUG_OBJECT (mux, "adjusting newsegment event offsets to start=%"
|
||||
G_GINT64_FORMAT ", stop=%" G_GINT64_FORMAT ", cur=%" G_GINT64_FORMAT
|
||||
" (delta = +%" G_GSIZE_FORMAT ")", start, stop, cur, mux->start_tag_size);
|
||||
|
||||
return gst_event_new_new_segment (TRUE, 1.0, format, start, stop, cur);
|
||||
}
|
||||
|
||||
static GstFlowReturn
|
||||
gst_tag_mux_chain (GstPad * pad, GstBuffer * buffer)
|
||||
{
|
||||
GstTagMux *mux = GST_TAG_MUX (GST_OBJECT_PARENT (pad));
|
||||
GstFlowReturn ret;
|
||||
int length;
|
||||
|
||||
if (mux->render_start_tag) {
|
||||
|
||||
GST_INFO_OBJECT (mux, "Adding tags to stream");
|
||||
ret = gst_tag_mux_render_start_tag (mux);
|
||||
if (ret != GST_FLOW_OK) {
|
||||
GST_DEBUG_OBJECT (mux, "flow: %s", gst_flow_get_name (ret));
|
||||
gst_buffer_unref (buffer);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Now send the cached newsegment event that we got from upstream */
|
||||
if (mux->newsegment_ev) {
|
||||
gint64 start;
|
||||
GstEvent *newseg;
|
||||
|
||||
GST_DEBUG_OBJECT (mux, "sending cached newsegment event");
|
||||
newseg = gst_tag_mux_adjust_event_offsets (mux, mux->newsegment_ev);
|
||||
gst_event_unref (mux->newsegment_ev);
|
||||
mux->newsegment_ev = NULL;
|
||||
|
||||
gst_event_parse_new_segment (newseg, NULL, NULL, NULL, &start, NULL,
|
||||
NULL);
|
||||
|
||||
gst_pad_push_event (mux->srcpad, newseg);
|
||||
mux->current_offset = start;
|
||||
mux->max_offset = MAX (mux->max_offset, mux->current_offset);
|
||||
} else {
|
||||
/* upstream sent no newsegment event or only one in a non-BYTE format */
|
||||
}
|
||||
|
||||
mux->render_start_tag = FALSE;
|
||||
}
|
||||
|
||||
buffer = gst_buffer_make_metadata_writable (buffer);
|
||||
|
||||
if (GST_BUFFER_OFFSET (buffer) != GST_BUFFER_OFFSET_NONE) {
|
||||
GST_LOG_OBJECT (mux, "Adjusting buffer offset from %" G_GINT64_FORMAT
|
||||
" to %" G_GINT64_FORMAT, GST_BUFFER_OFFSET (buffer),
|
||||
GST_BUFFER_OFFSET (buffer) + mux->start_tag_size);
|
||||
GST_BUFFER_OFFSET (buffer) += mux->start_tag_size;
|
||||
}
|
||||
|
||||
length = GST_BUFFER_SIZE (buffer);
|
||||
|
||||
gst_buffer_set_caps (buffer, GST_PAD_CAPS (mux->srcpad));
|
||||
ret = gst_pad_push (mux->srcpad, buffer);
|
||||
|
||||
mux->current_offset += length;
|
||||
mux->max_offset = MAX (mux->max_offset, mux->current_offset);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gst_tag_mux_sink_event (GstPad * pad, GstEvent * event)
|
||||
{
|
||||
GstTagMux *mux;
|
||||
gboolean result;
|
||||
|
||||
mux = GST_TAG_MUX (gst_pad_get_parent (pad));
|
||||
result = FALSE;
|
||||
|
||||
switch (GST_EVENT_TYPE (event)) {
|
||||
case GST_EVENT_TAG:{
|
||||
GstTagList *tags;
|
||||
|
||||
gst_event_parse_tag (event, &tags);
|
||||
|
||||
GST_INFO_OBJECT (mux, "Got tag event: %" GST_PTR_FORMAT, tags);
|
||||
|
||||
if (mux->event_tags != NULL) {
|
||||
gst_tag_list_insert (mux->event_tags, tags, GST_TAG_MERGE_REPLACE);
|
||||
} else {
|
||||
mux->event_tags = gst_tag_list_copy (tags);
|
||||
}
|
||||
|
||||
GST_INFO_OBJECT (mux, "Event tags are now: %" GST_PTR_FORMAT,
|
||||
mux->event_tags);
|
||||
|
||||
/* just drop the event, we'll push a new tag event in render_start_tag */
|
||||
gst_event_unref (event);
|
||||
result = TRUE;
|
||||
break;
|
||||
}
|
||||
case GST_EVENT_NEWSEGMENT:{
|
||||
GstFormat fmt;
|
||||
gint64 start;
|
||||
|
||||
gst_event_parse_new_segment (event, NULL, NULL, &fmt, &start, NULL, NULL);
|
||||
|
||||
if (fmt != GST_FORMAT_BYTES) {
|
||||
GST_WARNING_OBJECT (mux, "dropping newsegment event in %s format",
|
||||
gst_format_get_name (fmt));
|
||||
gst_event_unref (event);
|
||||
break;
|
||||
}
|
||||
|
||||
if (mux->render_start_tag) {
|
||||
/* we have not rendered the tag yet, which means that we don't know
|
||||
* how large it is going to be yet, so we can't adjust the offsets
|
||||
* here at this point and need to cache the newsegment event for now
|
||||
* (also, there could be tag events coming after this newsegment event
|
||||
* and before the first buffer). */
|
||||
if (mux->newsegment_ev) {
|
||||
GST_WARNING_OBJECT (mux, "discarding old cached newsegment event");
|
||||
gst_event_unref (mux->newsegment_ev);
|
||||
}
|
||||
|
||||
GST_LOG_OBJECT (mux, "caching newsegment event for later");
|
||||
mux->newsegment_ev = event;
|
||||
} else {
|
||||
GST_DEBUG_OBJECT (mux, "got newsegment event, adjusting offsets");
|
||||
gst_pad_push_event (mux->srcpad,
|
||||
gst_tag_mux_adjust_event_offsets (mux, event));
|
||||
gst_event_unref (event);
|
||||
|
||||
mux->current_offset = start;
|
||||
mux->max_offset = MAX (mux->max_offset, mux->current_offset);
|
||||
}
|
||||
event = NULL;
|
||||
result = TRUE;
|
||||
break;
|
||||
}
|
||||
case GST_EVENT_EOS:{
|
||||
if (mux->render_end_tag) {
|
||||
GstFlowReturn ret;
|
||||
|
||||
GST_INFO_OBJECT (mux, "Adding tags to stream");
|
||||
ret = gst_tag_mux_render_end_tag (mux);
|
||||
if (ret != GST_FLOW_OK) {
|
||||
GST_DEBUG_OBJECT (mux, "flow: %s", gst_flow_get_name (ret));
|
||||
return ret;
|
||||
}
|
||||
|
||||
mux->render_end_tag = FALSE;
|
||||
}
|
||||
|
||||
/* Now forward EOS */
|
||||
result = gst_pad_event_default (pad, event);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
result = gst_pad_event_default (pad, event);
|
||||
break;
|
||||
}
|
||||
|
||||
gst_object_unref (mux);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
static GstStateChangeReturn
|
||||
gst_tag_mux_change_state (GstElement * element, GstStateChange transition)
|
||||
{
|
||||
GstTagMux *mux;
|
||||
GstStateChangeReturn result;
|
||||
|
||||
mux = GST_TAG_MUX (element);
|
||||
|
||||
result = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
|
||||
if (result != GST_STATE_CHANGE_SUCCESS) {
|
||||
return result;
|
||||
}
|
||||
|
||||
switch (transition) {
|
||||
case GST_STATE_CHANGE_PAUSED_TO_READY:{
|
||||
if (mux->newsegment_ev) {
|
||||
gst_event_unref (mux->newsegment_ev);
|
||||
mux->newsegment_ev = NULL;
|
||||
}
|
||||
if (mux->event_tags) {
|
||||
gst_tag_list_free (mux->event_tags);
|
||||
mux->event_tags = NULL;
|
||||
}
|
||||
mux->start_tag_size = 0;
|
||||
mux->end_tag_size = 0;
|
||||
mux->render_start_tag = TRUE;
|
||||
mux->render_end_tag = TRUE;
|
||||
mux->current_offset = 0;
|
||||
mux->max_offset = 0;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
79
gst/id3tag/gsttagmux.h
Normal file
79
gst/id3tag/gsttagmux.h
Normal file
|
@ -0,0 +1,79 @@
|
|||
/* GStreamer tag muxer base class
|
||||
*
|
||||
* Copyright (C) 2006 Christophe Fergeau <teuf@gnome.org>
|
||||
* Copyright (C) 2006 Tim-Philipp Müller <tim centricular net>
|
||||
* 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
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifndef GST_TAG_MUX_H
|
||||
#define GST_TAG_MUX_H
|
||||
|
||||
#include <gst/gst.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
typedef struct _GstTagMux GstTagMux;
|
||||
typedef struct _GstTagMuxClass GstTagMuxClass;
|
||||
|
||||
/* Definition of structure storing data for this element. */
|
||||
struct _GstTagMux {
|
||||
GstElement element;
|
||||
|
||||
GstPad *srcpad;
|
||||
GstPad *sinkpad;
|
||||
GstTagList *event_tags; /* tags received from upstream elements */
|
||||
GstTagList *final_tags; /* Final set of tags used for muxing */
|
||||
gsize start_tag_size;
|
||||
gsize end_tag_size;
|
||||
gboolean render_start_tag;
|
||||
gboolean render_end_tag;
|
||||
|
||||
gint64 current_offset;
|
||||
gint64 max_offset;
|
||||
|
||||
GstEvent *newsegment_ev; /* cached newsegment event from upstream */
|
||||
};
|
||||
|
||||
/* Standard definition defining a class for this element. */
|
||||
struct _GstTagMuxClass {
|
||||
GstElementClass parent_class;
|
||||
|
||||
/* vfuncs */
|
||||
GstBuffer * (*render_start_tag) (GstTagMux * mux, GstTagList * tag_list);
|
||||
GstBuffer * (*render_end_tag) (GstTagMux * mux, GstTagList * tag_list);
|
||||
};
|
||||
|
||||
/* Standard macros for defining types for this element. */
|
||||
#define GST_TYPE_TAG_MUX \
|
||||
(gst_tag_mux_get_type())
|
||||
#define GST_TAG_MUX(obj) \
|
||||
(G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_TAG_MUX,GstTagMux))
|
||||
#define GST_TAG_MUX_CLASS(klass) \
|
||||
(G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_TAG_MUX,GstTagMuxClass))
|
||||
#define GST_IS_TAG_MUX(obj) \
|
||||
(G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_TAG_MUX))
|
||||
#define GST_IS_TAG_MUX_CLASS(klass) \
|
||||
(G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_TAG_MUX))
|
||||
|
||||
/* Standard function returning type information. */
|
||||
GType gst_tag_mux_get_type (void);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif
|
||||
|
1194
gst/id3tag/id3tag.c
Normal file
1194
gst/id3tag/id3tag.c
Normal file
File diff suppressed because it is too large
Load diff
32
gst/id3tag/id3tag.h
Normal file
32
gst/id3tag/id3tag.h
Normal file
|
@ -0,0 +1,32 @@
|
|||
/* GStreamer ID3v2 tag writer
|
||||
* Copyright (C) 2009 Tim-Philipp Müller <tim centricular net>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include "gsttagmux.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define ID3_VERSION_2_3 3
|
||||
#define ID3_VERSION_2_4 4
|
||||
|
||||
GstBuffer * gst_id3mux_render_v2_tag (GstTagMux * mux, GstTagList * taglist,
|
||||
int version);
|
||||
GstBuffer * gst_id3mux_render_v1_tag (GstTagMux * mux, GstTagList * taglist);
|
||||
|
||||
G_END_DECLS
|
||||
|
Loading…
Reference in a new issue