2003-12-07 21:40:11 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) 2003 Christophe Fergeau <teuf@gnome.org>
|
2008-08-06 15:34:55 +00:00
|
|
|
* Copyright (C) 2008 Jonathan Matthew <jonathan@d14n.org>
|
|
|
|
* Copyright (C) 2008 Sebastian Dröge <sebastian.droege@collabora.co.uk>
|
2003-12-07 21:40:11 +00:00
|
|
|
*
|
|
|
|
* gstflactag.c: plug-in for reading/modifying vorbis comments in flac files
|
|
|
|
*
|
|
|
|
* 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-04 00:07:18 +00:00
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
2003-12-07 21:40:11 +00:00
|
|
|
*/
|
|
|
|
|
2008-08-06 15:34:55 +00:00
|
|
|
/**
|
|
|
|
* SECTION:element-flactag
|
|
|
|
* @see_also: #flacenc, #flacdec, #GstTagSetter
|
|
|
|
*
|
|
|
|
* The flactag element can change the tag contained within a raw
|
|
|
|
* FLAC stream. Specifically, it modifies the comments header packet
|
|
|
|
* of the FLAC stream.
|
|
|
|
*
|
|
|
|
* Applications can set the tags to write using the #GstTagSetter interface.
|
|
|
|
* Tags contained withing the FLAC bitstream will be picked up
|
|
|
|
* automatically (and merged according to the merge mode set via the tag
|
|
|
|
* setter interface).
|
|
|
|
*
|
|
|
|
* <refsect2>
|
|
|
|
* <title>Example pipelines</title>
|
|
|
|
* |[
|
2012-08-26 21:39:55 +00:00
|
|
|
* gst-launch-1.0 -v filesrc location=foo.flac ! flactag ! filesink location=bar.flac
|
2008-08-06 15:34:55 +00:00
|
|
|
* ]| This element is not useful with gst-launch, because it does not support
|
|
|
|
* setting the tags on a #GstTagSetter interface. Conceptually, the element
|
|
|
|
* will usually be used in this order though.
|
|
|
|
* </refsect2>
|
|
|
|
*/
|
|
|
|
|
2003-12-07 21:40:11 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
2008-08-06 15:34:55 +00:00
|
|
|
|
|
|
|
#include <gst/gst.h>
|
2005-09-07 13:49:37 +00:00
|
|
|
#include <gst/gsttagsetter.h>
|
2008-08-06 15:34:55 +00:00
|
|
|
#include <gst/base/gstadapter.h>
|
2003-12-14 19:09:23 +00:00
|
|
|
#include <gst/tag/tag.h>
|
2003-12-07 21:40:11 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
2008-08-06 15:34:55 +00:00
|
|
|
#include "gstflactag.h"
|
2003-12-07 21:40:11 +00:00
|
|
|
|
2008-08-06 15:34:55 +00:00
|
|
|
GST_DEBUG_CATEGORY_STATIC (flactag_debug);
|
|
|
|
#define GST_CAT_DEFAULT flactag_debug
|
2003-12-07 21:40:11 +00:00
|
|
|
|
|
|
|
/* elementfactory information */
|
2008-08-06 15:34:55 +00:00
|
|
|
static GstStaticPadTemplate flac_tag_src_template =
|
|
|
|
GST_STATIC_PAD_TEMPLATE ("src",
|
|
|
|
GST_PAD_SRC,
|
|
|
|
GST_PAD_ALWAYS,
|
|
|
|
GST_STATIC_CAPS ("audio/x-flac")
|
|
|
|
);
|
2003-12-07 21:40:11 +00:00
|
|
|
|
2008-08-06 15:34:55 +00:00
|
|
|
static GstStaticPadTemplate flac_tag_sink_template =
|
|
|
|
GST_STATIC_PAD_TEMPLATE ("sink",
|
|
|
|
GST_PAD_SINK,
|
|
|
|
GST_PAD_ALWAYS,
|
|
|
|
GST_STATIC_CAPS ("audio/x-flac")
|
|
|
|
);
|
2003-12-07 21:40:11 +00:00
|
|
|
|
|
|
|
|
2008-08-06 15:34:55 +00:00
|
|
|
static void gst_flac_tag_dispose (GObject * object);
|
2003-12-07 21:40:11 +00:00
|
|
|
|
2011-11-17 14:02:55 +00:00
|
|
|
static GstFlowReturn gst_flac_tag_chain (GstPad * pad, GstObject * parent,
|
|
|
|
GstBuffer * buffer);
|
2003-12-07 21:40:11 +00:00
|
|
|
|
2005-09-02 15:44:50 +00:00
|
|
|
static GstStateChangeReturn gst_flac_tag_change_state (GstElement * element,
|
|
|
|
GstStateChange transition);
|
2003-12-07 21:40:11 +00:00
|
|
|
|
2011-11-17 14:02:55 +00:00
|
|
|
static gboolean gst_flac_tag_sink_event (GstPad * pad, GstObject * parent,
|
|
|
|
GstEvent * event);
|
2003-12-07 21:40:11 +00:00
|
|
|
|
2011-04-19 16:55:31 +00:00
|
|
|
#define gst_flac_tag_parent_class parent_class
|
|
|
|
G_DEFINE_TYPE_WITH_CODE (GstFlacTag, gst_flac_tag, GST_TYPE_ELEMENT,
|
|
|
|
G_IMPLEMENT_INTERFACE (GST_TYPE_TAG_SETTER, NULL));
|
2003-12-07 21:40:11 +00:00
|
|
|
|
2003-12-08 22:04:46 +00:00
|
|
|
|
2003-12-07 21:40:11 +00:00
|
|
|
static void
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_flac_tag_class_init (GstFlacTagClass * klass)
|
2003-12-07 21:40:11 +00:00
|
|
|
{
|
|
|
|
GstElementClass *gstelement_class;
|
|
|
|
GObjectClass *gobject_class;
|
|
|
|
|
2011-04-19 16:55:31 +00:00
|
|
|
GST_DEBUG_CATEGORY_INIT (flactag_debug, "flactag", 0, "flac tag rewriter");
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
gstelement_class = (GstElementClass *) klass;
|
|
|
|
gobject_class = (GObjectClass *) klass;
|
|
|
|
|
2008-08-06 15:34:55 +00:00
|
|
|
gobject_class->dispose = gst_flac_tag_dispose;
|
2003-12-07 21:40:11 +00:00
|
|
|
gstelement_class->change_state = gst_flac_tag_change_state;
|
2011-04-19 16:55:31 +00:00
|
|
|
|
2012-04-09 23:51:41 +00:00
|
|
|
gst_element_class_set_static_metadata (gstelement_class, "FLAC tagger",
|
2011-04-19 16:55:31 +00:00
|
|
|
"Formatter/Metadata",
|
|
|
|
"Rewrite tags in a FLAC file", "Christophe Fergeau <teuf@gnome.org>");
|
|
|
|
|
|
|
|
gst_element_class_add_pad_template (gstelement_class,
|
|
|
|
gst_static_pad_template_get (&flac_tag_sink_template));
|
|
|
|
|
|
|
|
gst_element_class_add_pad_template (gstelement_class,
|
|
|
|
gst_static_pad_template_get (&flac_tag_src_template));
|
2003-12-07 21:40:11 +00:00
|
|
|
}
|
|
|
|
|
2008-08-06 15:34:55 +00:00
|
|
|
static void
|
|
|
|
gst_flac_tag_dispose (GObject * object)
|
|
|
|
{
|
|
|
|
GstFlacTag *tag = GST_FLAC_TAG (object);
|
|
|
|
|
|
|
|
if (tag->adapter) {
|
2009-08-31 12:07:53 +00:00
|
|
|
g_object_unref (tag->adapter);
|
2008-08-06 15:34:55 +00:00
|
|
|
tag->adapter = NULL;
|
|
|
|
}
|
|
|
|
if (tag->vorbiscomment) {
|
|
|
|
gst_buffer_unref (tag->vorbiscomment);
|
|
|
|
tag->vorbiscomment = NULL;
|
|
|
|
}
|
|
|
|
if (tag->tags) {
|
2012-08-04 15:10:16 +00:00
|
|
|
gst_tag_list_unref (tag->tags);
|
2008-08-06 15:34:55 +00:00
|
|
|
tag->tags = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (parent_class)->dispose (object);
|
|
|
|
}
|
|
|
|
|
2003-12-07 21:40:11 +00:00
|
|
|
|
|
|
|
static void
|
2011-04-19 16:55:31 +00:00
|
|
|
gst_flac_tag_init (GstFlacTag * tag)
|
2003-12-07 21:40:11 +00:00
|
|
|
{
|
|
|
|
/* create the sink and src pads */
|
2004-03-14 22:34:33 +00:00
|
|
|
tag->sinkpad =
|
2007-06-22 10:12:15 +00:00
|
|
|
gst_pad_new_from_static_template (&flac_tag_sink_template, "sink");
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_pad_set_chain_function (tag->sinkpad,
|
|
|
|
GST_DEBUG_FUNCPTR (gst_flac_tag_chain));
|
2011-09-28 15:40:01 +00:00
|
|
|
gst_pad_set_event_function (tag->sinkpad,
|
|
|
|
GST_DEBUG_FUNCPTR (gst_flac_tag_sink_event));
|
2008-08-06 15:34:55 +00:00
|
|
|
gst_element_add_pad (GST_ELEMENT (tag), tag->sinkpad);
|
2003-12-07 21:40:11 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
tag->srcpad =
|
2007-06-22 10:12:15 +00:00
|
|
|
gst_pad_new_from_static_template (&flac_tag_src_template, "src");
|
2003-12-07 21:40:11 +00:00
|
|
|
gst_element_add_pad (GST_ELEMENT (tag), tag->srcpad);
|
|
|
|
|
2008-08-06 15:34:55 +00:00
|
|
|
tag->adapter = gst_adapter_new ();
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2011-11-17 14:02:55 +00:00
|
|
|
gst_flac_tag_sink_event (GstPad * pad, GstObject * parent, GstEvent * event)
|
2008-08-06 15:34:55 +00:00
|
|
|
{
|
2013-04-17 19:12:55 +00:00
|
|
|
GstFlacTag *tag;
|
2011-09-28 15:40:01 +00:00
|
|
|
gboolean ret;
|
2008-08-06 15:34:55 +00:00
|
|
|
|
2013-04-17 19:12:55 +00:00
|
|
|
tag = GST_FLAC_TAG (parent);
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (pad, "Received %s event on sinkpad, %" GST_PTR_FORMAT,
|
|
|
|
GST_EVENT_TYPE_NAME (event), event);
|
|
|
|
|
2011-09-28 15:40:01 +00:00
|
|
|
switch (GST_EVENT_TYPE (event)) {
|
2013-04-17 19:12:55 +00:00
|
|
|
case GST_EVENT_CAPS:
|
|
|
|
/* FIXME: parse and store the caps. Once we parsed and built the headers,
|
|
|
|
* update the "streamheader" field in the caps and send a new caps event
|
|
|
|
*/
|
|
|
|
ret = gst_pad_push_event (tag->srcpad, event);
|
|
|
|
break;
|
2011-09-28 15:40:01 +00:00
|
|
|
default:
|
2011-11-17 14:02:55 +00:00
|
|
|
ret = gst_pad_event_default (pad, parent, event);
|
2011-09-28 15:40:01 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
2003-12-07 21:40:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#define FLAC_MAGIC "fLaC"
|
|
|
|
#define FLAC_MAGIC_SIZE (sizeof (FLAC_MAGIC) - 1)
|
|
|
|
|
2008-08-06 15:34:55 +00:00
|
|
|
static GstFlowReturn
|
2011-11-17 14:02:55 +00:00
|
|
|
gst_flac_tag_chain (GstPad * pad, GstObject * parent, GstBuffer * buffer)
|
2003-12-07 21:40:11 +00:00
|
|
|
{
|
|
|
|
GstFlacTag *tag;
|
2008-08-06 15:34:55 +00:00
|
|
|
GstFlowReturn ret;
|
2012-01-24 13:38:58 +00:00
|
|
|
GstMapInfo map;
|
2011-04-19 16:55:31 +00:00
|
|
|
gsize size;
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2008-08-06 15:34:55 +00:00
|
|
|
ret = GST_FLOW_OK;
|
2011-11-17 14:02:55 +00:00
|
|
|
tag = GST_FLAC_TAG (parent);
|
2003-12-07 21:40:11 +00:00
|
|
|
|
2008-08-06 15:34:55 +00:00
|
|
|
gst_adapter_push (tag->adapter, buffer);
|
2003-12-07 21:40:11 +00:00
|
|
|
|
2013-04-17 05:50:27 +00:00
|
|
|
GST_LOG_OBJECT (pad, "state: %d", tag->state);
|
|
|
|
|
2003-12-07 21:40:11 +00:00
|
|
|
/* Initial state, we don't even know if we are dealing with a flac file */
|
|
|
|
if (tag->state == GST_FLAC_TAG_STATE_INIT) {
|
2008-08-06 15:34:55 +00:00
|
|
|
GstBuffer *id_buffer;
|
2003-12-08 22:04:46 +00:00
|
|
|
|
2008-08-06 15:34:55 +00:00
|
|
|
if (gst_adapter_available (tag->adapter) < sizeof (FLAC_MAGIC))
|
close #333784 unref the result of gst_pad_get_parent() by: Christophe Fergeau.
Original commit message from CVS:
* ext/cairo/gsttextoverlay.c: (gst_text_overlay_setcaps):
* ext/esd/esdmon.c: (gst_esdmon_get):
* ext/flac/gstflactag.c: (gst_flac_tag_chain):
* ext/gdk_pixbuf/gstgdkpixbuf.c: (gst_gdk_pixbuf_sink_setcaps),
(gst_gdk_pixbuf_sink_getcaps):
* ext/jpeg/gstjpegenc.c: (gst_jpegenc_getcaps),
(gst_jpegenc_setcaps):
* ext/jpeg/gstsmokedec.c: (gst_smokedec_chain):
* ext/jpeg/gstsmokeenc.c: (gst_smokeenc_getcaps),
(gst_smokeenc_setcaps):
* ext/libmng/gstmngdec.c: (gst_mngdec_sinklink),
(gst_mngdec_src_getcaps):
* ext/libmng/gstmngenc.c: (gst_mngenc_sinklink),
(gst_mngenc_chain):
* ext/libpng/gstpngenc.c: (gst_pngenc_setcaps):
* ext/mikmod/gstmikmod.c: (gst_mikmod_srclink):
* ext/speex/gstspeexdec.c: (speex_dec_convert),
(speex_dec_src_event), (speex_dec_chain):
* gst/avi/gstavimux.c: (gst_avimux_vidsinkconnect),
(gst_avimux_audsinkconnect), (gst_avimux_handle_event):
* gst/debug/negotiation.c: (gst_negotiation_getcaps),
(gst_negotiation_pad_link), (gst_negotiation_chain):
* gst/flx/gstflxdec.c: (gst_flxdec_src_query_handler),
(gst_flxdec_chain):
* gst/interleave/deinterleave.c: (deinterleave_sink_link),
(deinterleave_chain):
* gst/law/mulaw-encode.c: (mulawenc_setcaps):
* gst/median/gstmedian.c: (gst_median_link):
* gst/monoscope/gstmonoscope.c: (gst_monoscope_srcconnect),
(gst_monoscope_chain):
* gst/rtp/gstrtpL16pay.c: (gst_rtpL16pay_sinkconnect):
* gst/wavenc/gstwavenc.c: (gst_wavenc_sink_setcaps):
* sys/osxaudio/gstosxaudiosink.c: (gst_osxaudiosink_chain):
* sys/osxaudio/gstosxaudiosrc.c: (gst_osxaudiosrc_get):
close #333784 unref the result of gst_pad_get_parent()
by: Christophe Fergeau.
2006-03-13 15:49:08 +00:00
|
|
|
goto cleanup;
|
2003-12-07 21:40:11 +00:00
|
|
|
|
2008-08-06 15:34:55 +00:00
|
|
|
id_buffer = gst_adapter_take_buffer (tag->adapter, FLAC_MAGIC_SIZE);
|
|
|
|
GST_DEBUG_OBJECT (tag, "looking for " FLAC_MAGIC " identifier");
|
2011-04-19 16:55:31 +00:00
|
|
|
if (gst_buffer_memcmp (id_buffer, 0, FLAC_MAGIC, FLAC_MAGIC_SIZE) == 0) {
|
2008-08-06 15:34:55 +00:00
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (tag, "pushing " FLAC_MAGIC " identifier buffer");
|
|
|
|
ret = gst_pad_push (tag->srcpad, id_buffer);
|
|
|
|
if (ret != GST_FLOW_OK)
|
|
|
|
goto cleanup;
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2003-12-07 21:40:11 +00:00
|
|
|
tag->state = GST_FLAC_TAG_STATE_METADATA_BLOCKS;
|
|
|
|
} else {
|
|
|
|
/* FIXME: does that work well with FLAC files containing ID3v2 tags ? */
|
2008-08-06 15:34:55 +00:00
|
|
|
gst_buffer_unref (id_buffer);
|
2004-02-02 17:23:33 +00:00
|
|
|
GST_ELEMENT_ERROR (tag, STREAM, WRONG_TYPE, (NULL), (NULL));
|
2008-08-06 15:34:55 +00:00
|
|
|
ret = GST_FLOW_ERROR;
|
2003-12-07 21:40:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-12-08 22:04:46 +00:00
|
|
|
|
2003-12-07 21:40:11 +00:00
|
|
|
/* The fLaC magic string has been skipped, try to detect the beginning
|
|
|
|
* of a metadata block
|
|
|
|
*/
|
|
|
|
if (tag->state == GST_FLAC_TAG_STATE_METADATA_BLOCKS) {
|
|
|
|
guint type;
|
|
|
|
gboolean is_last;
|
2008-08-06 15:34:55 +00:00
|
|
|
const guint8 *block_header;
|
2003-12-07 21:40:11 +00:00
|
|
|
|
2008-08-06 15:34:55 +00:00
|
|
|
g_assert (tag->metadata_block_size == 0);
|
2003-12-07 21:40:11 +00:00
|
|
|
g_assert (tag->metadata_last_block == FALSE);
|
|
|
|
|
|
|
|
/* The header of a flac metadata block is 4 bytes long:
|
|
|
|
* 1st bit: indicates whether this is the last metadata info block
|
|
|
|
* 7 next bits: 4 if vorbis comment block
|
|
|
|
* 24 next bits: size of the metadata to follow (big endian)
|
|
|
|
*/
|
2008-08-06 15:34:55 +00:00
|
|
|
if (gst_adapter_available (tag->adapter) < 4)
|
close #333784 unref the result of gst_pad_get_parent() by: Christophe Fergeau.
Original commit message from CVS:
* ext/cairo/gsttextoverlay.c: (gst_text_overlay_setcaps):
* ext/esd/esdmon.c: (gst_esdmon_get):
* ext/flac/gstflactag.c: (gst_flac_tag_chain):
* ext/gdk_pixbuf/gstgdkpixbuf.c: (gst_gdk_pixbuf_sink_setcaps),
(gst_gdk_pixbuf_sink_getcaps):
* ext/jpeg/gstjpegenc.c: (gst_jpegenc_getcaps),
(gst_jpegenc_setcaps):
* ext/jpeg/gstsmokedec.c: (gst_smokedec_chain):
* ext/jpeg/gstsmokeenc.c: (gst_smokeenc_getcaps),
(gst_smokeenc_setcaps):
* ext/libmng/gstmngdec.c: (gst_mngdec_sinklink),
(gst_mngdec_src_getcaps):
* ext/libmng/gstmngenc.c: (gst_mngenc_sinklink),
(gst_mngenc_chain):
* ext/libpng/gstpngenc.c: (gst_pngenc_setcaps):
* ext/mikmod/gstmikmod.c: (gst_mikmod_srclink):
* ext/speex/gstspeexdec.c: (speex_dec_convert),
(speex_dec_src_event), (speex_dec_chain):
* gst/avi/gstavimux.c: (gst_avimux_vidsinkconnect),
(gst_avimux_audsinkconnect), (gst_avimux_handle_event):
* gst/debug/negotiation.c: (gst_negotiation_getcaps),
(gst_negotiation_pad_link), (gst_negotiation_chain):
* gst/flx/gstflxdec.c: (gst_flxdec_src_query_handler),
(gst_flxdec_chain):
* gst/interleave/deinterleave.c: (deinterleave_sink_link),
(deinterleave_chain):
* gst/law/mulaw-encode.c: (mulawenc_setcaps):
* gst/median/gstmedian.c: (gst_median_link):
* gst/monoscope/gstmonoscope.c: (gst_monoscope_srcconnect),
(gst_monoscope_chain):
* gst/rtp/gstrtpL16pay.c: (gst_rtpL16pay_sinkconnect):
* gst/wavenc/gstwavenc.c: (gst_wavenc_sink_setcaps):
* sys/osxaudio/gstosxaudiosink.c: (gst_osxaudiosink_chain):
* sys/osxaudio/gstosxaudiosrc.c: (gst_osxaudiosrc_get):
close #333784 unref the result of gst_pad_get_parent()
by: Christophe Fergeau.
2006-03-13 15:49:08 +00:00
|
|
|
goto cleanup;
|
2003-12-07 21:40:11 +00:00
|
|
|
|
2011-04-19 16:55:31 +00:00
|
|
|
block_header = gst_adapter_map (tag->adapter, 4);
|
2008-08-06 15:34:55 +00:00
|
|
|
|
|
|
|
is_last = ((block_header[0] & 0x80) == 0x80);
|
|
|
|
type = block_header[0] & 0x7F;
|
|
|
|
size = (block_header[1] << 16)
|
|
|
|
| (block_header[2] << 8)
|
|
|
|
| block_header[3];
|
2011-11-10 17:32:58 +00:00
|
|
|
gst_adapter_unmap (tag->adapter);
|
2003-12-07 21:40:11 +00:00
|
|
|
|
|
|
|
/* The 4 bytes long header isn't included in the metadata size */
|
2008-08-06 15:34:55 +00:00
|
|
|
tag->metadata_block_size = size + 4;
|
2003-12-07 21:40:11 +00:00
|
|
|
tag->metadata_last_block = is_last;
|
|
|
|
|
2008-08-06 15:34:55 +00:00
|
|
|
GST_DEBUG_OBJECT (tag,
|
2011-11-22 01:40:39 +00:00
|
|
|
"got metadata block: %" G_GSIZE_FORMAT " bytes, type %d, "
|
|
|
|
"is vorbiscomment: %d, is last: %d",
|
2008-08-06 15:34:55 +00:00
|
|
|
size, type, (type == 0x04), is_last);
|
|
|
|
|
2003-12-07 21:40:11 +00:00
|
|
|
/* Metadata blocks of type 4 are vorbis comment blocks */
|
2003-12-08 22:04:46 +00:00
|
|
|
if (type == 0x04) {
|
|
|
|
tag->state = GST_FLAC_TAG_STATE_VC_METADATA_BLOCK;
|
2003-12-07 21:40:11 +00:00
|
|
|
} else {
|
|
|
|
tag->state = GST_FLAC_TAG_STATE_WRITING_METADATA_BLOCK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-12-08 22:04:46 +00:00
|
|
|
|
2003-12-07 21:40:11 +00:00
|
|
|
/* Reads a metadata block */
|
|
|
|
if ((tag->state == GST_FLAC_TAG_STATE_WRITING_METADATA_BLOCK) ||
|
2004-03-14 22:34:33 +00:00
|
|
|
(tag->state == GST_FLAC_TAG_STATE_VC_METADATA_BLOCK)) {
|
2008-08-06 15:34:55 +00:00
|
|
|
GstBuffer *metadata_buffer;
|
2003-12-07 21:40:11 +00:00
|
|
|
|
2008-08-06 15:34:55 +00:00
|
|
|
if (gst_adapter_available (tag->adapter) < tag->metadata_block_size)
|
|
|
|
goto cleanup;
|
2003-12-07 21:40:11 +00:00
|
|
|
|
2008-08-06 15:34:55 +00:00
|
|
|
metadata_buffer = gst_adapter_take_buffer (tag->adapter,
|
|
|
|
tag->metadata_block_size);
|
|
|
|
/* clear the is-last flag, as the last metadata block will
|
|
|
|
* be the vorbis comment block which we will build ourselves.
|
|
|
|
*/
|
2012-01-24 13:38:58 +00:00
|
|
|
gst_buffer_map (metadata_buffer, &map, GST_MAP_READWRITE);
|
|
|
|
map.data[0] &= (~0x80);
|
|
|
|
gst_buffer_unmap (metadata_buffer, &map);
|
2003-12-08 22:04:46 +00:00
|
|
|
|
2003-12-07 21:40:11 +00:00
|
|
|
if (tag->state == GST_FLAC_TAG_STATE_WRITING_METADATA_BLOCK) {
|
2008-08-06 15:34:55 +00:00
|
|
|
GST_DEBUG_OBJECT (tag, "pushing metadata block buffer");
|
|
|
|
ret = gst_pad_push (tag->srcpad, metadata_buffer);
|
|
|
|
if (ret != GST_FLOW_OK)
|
|
|
|
goto cleanup;
|
2003-12-07 21:40:11 +00:00
|
|
|
} else {
|
2008-08-06 15:34:55 +00:00
|
|
|
tag->vorbiscomment = metadata_buffer;
|
2003-12-07 21:40:11 +00:00
|
|
|
}
|
2008-08-06 15:34:55 +00:00
|
|
|
tag->metadata_block_size = 0;
|
|
|
|
tag->state = GST_FLAC_TAG_STATE_METADATA_NEXT_BLOCK;
|
2003-12-07 21:40:11 +00:00
|
|
|
}
|
|
|
|
|
2003-12-08 22:04:46 +00:00
|
|
|
/* This state is mainly used to be able to stop as soon as we read
|
|
|
|
* a vorbiscomment block from the flac file if we are in an only output
|
|
|
|
* tags mode
|
|
|
|
*/
|
|
|
|
if (tag->state == GST_FLAC_TAG_STATE_METADATA_NEXT_BLOCK) {
|
|
|
|
/* Check if in the previous iteration we read a vorbis comment metadata
|
|
|
|
* block, and stop now if the user only wants to read tags
|
|
|
|
*/
|
|
|
|
if (tag->vorbiscomment != NULL) {
|
2011-04-19 16:55:31 +00:00
|
|
|
guint8 id_data[4];
|
2003-12-08 22:04:46 +00:00
|
|
|
/* We found some tags, try to parse them and notify the other elements
|
2008-08-06 15:34:55 +00:00
|
|
|
* that we encountered some tags
|
2004-03-14 22:34:33 +00:00
|
|
|
*/
|
2008-08-06 15:34:55 +00:00
|
|
|
GST_DEBUG_OBJECT (tag, "emitting vorbiscomment tags");
|
2011-04-19 16:55:31 +00:00
|
|
|
gst_buffer_extract (tag->vorbiscomment, 0, id_data, 4);
|
2004-03-14 22:34:33 +00:00
|
|
|
tag->tags = gst_tag_list_from_vorbiscomment_buffer (tag->vorbiscomment,
|
2011-04-19 16:55:31 +00:00
|
|
|
id_data, 4, NULL);
|
2003-12-08 22:04:46 +00:00
|
|
|
if (tag->tags != NULL) {
|
2011-11-02 11:09:20 +00:00
|
|
|
gst_pad_push_event (tag->srcpad,
|
2012-07-27 22:19:51 +00:00
|
|
|
gst_event_new_tag (gst_tag_list_ref (tag->tags)));
|
2003-12-08 22:04:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gst_buffer_unref (tag->vorbiscomment);
|
|
|
|
tag->vorbiscomment = NULL;
|
|
|
|
}
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2003-12-08 22:04:46 +00:00
|
|
|
/* Skip to next state */
|
|
|
|
if (tag->metadata_last_block == FALSE) {
|
|
|
|
tag->state = GST_FLAC_TAG_STATE_METADATA_BLOCKS;
|
|
|
|
} else {
|
2008-08-06 15:34:55 +00:00
|
|
|
tag->state = GST_FLAC_TAG_STATE_ADD_VORBIS_COMMENT;
|
2003-12-08 22:04:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-12-07 21:40:11 +00:00
|
|
|
/* Creates a vorbis comment block from the metadata which was set
|
|
|
|
* on the gstreamer element, and add it to the flac stream
|
|
|
|
*/
|
|
|
|
if (tag->state == GST_FLAC_TAG_STATE_ADD_VORBIS_COMMENT) {
|
|
|
|
GstBuffer *buffer;
|
2003-12-08 22:04:46 +00:00
|
|
|
const GstTagList *user_tags;
|
|
|
|
GstTagList *merged_tags;
|
|
|
|
|
2008-08-06 15:34:55 +00:00
|
|
|
/* merge the tag lists */
|
2005-11-22 12:38:33 +00:00
|
|
|
user_tags = gst_tag_setter_get_tag_list (GST_TAG_SETTER (tag));
|
2008-08-06 15:34:55 +00:00
|
|
|
if (user_tags != NULL) {
|
|
|
|
merged_tags = gst_tag_list_merge (user_tags, tag->tags,
|
|
|
|
gst_tag_setter_get_tag_merge_mode (GST_TAG_SETTER (tag)));
|
|
|
|
} else {
|
|
|
|
merged_tags = gst_tag_list_copy (tag->tags);
|
|
|
|
}
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2003-12-08 22:04:46 +00:00
|
|
|
if (merged_tags == NULL) {
|
|
|
|
/* If we get a NULL list of tags, we must generate a padding block
|
|
|
|
* which is marked as the last metadata block, otherwise we'll
|
|
|
|
* end up with a corrupted flac file.
|
2003-12-07 21:40:11 +00:00
|
|
|
*/
|
2008-08-06 15:34:55 +00:00
|
|
|
GST_WARNING_OBJECT (tag, "No tags found");
|
2003-12-08 22:04:46 +00:00
|
|
|
buffer = gst_buffer_new_and_alloc (12);
|
2011-04-19 16:55:31 +00:00
|
|
|
if (buffer == NULL)
|
|
|
|
goto no_buffer;
|
|
|
|
|
2012-01-24 13:38:58 +00:00
|
|
|
gst_buffer_map (buffer, &map, GST_MAP_WRITE);
|
|
|
|
memset (map.data, 0, map.size);
|
|
|
|
map.data[0] = 0x81; /* 0x80 = Last metadata block,
|
2011-04-19 16:55:31 +00:00
|
|
|
* 0x01 = padding block */
|
2012-01-24 13:38:58 +00:00
|
|
|
gst_buffer_unmap (buffer, &map);
|
2003-12-08 22:04:46 +00:00
|
|
|
} else {
|
|
|
|
guchar header[4];
|
2011-04-19 16:55:31 +00:00
|
|
|
guint8 fbit[1];
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2004-02-02 20:09:09 +00:00
|
|
|
memset (header, 0, sizeof (header));
|
2004-03-15 19:32:27 +00:00
|
|
|
header[0] = 0x84; /* 0x80 = Last metadata block,
|
2011-04-19 16:55:31 +00:00
|
|
|
* 0x04 = vorbiscomment block */
|
2004-03-14 22:34:33 +00:00
|
|
|
buffer = gst_tag_list_to_vorbiscomment_buffer (merged_tags, header,
|
2004-03-15 19:32:27 +00:00
|
|
|
sizeof (header), NULL);
|
2008-08-06 15:34:55 +00:00
|
|
|
GST_DEBUG_OBJECT (tag, "Writing tags %" GST_PTR_FORMAT, merged_tags);
|
2012-08-04 15:10:16 +00:00
|
|
|
gst_tag_list_unref (merged_tags);
|
2011-04-19 16:55:31 +00:00
|
|
|
if (buffer == NULL)
|
|
|
|
goto no_comment;
|
|
|
|
|
|
|
|
size = gst_buffer_get_size (buffer);
|
|
|
|
if ((size < 4) || ((size - 4) > 0xFFFFFF))
|
|
|
|
goto comment_too_long;
|
2004-06-01 20:23:12 +00:00
|
|
|
|
2011-04-19 16:55:31 +00:00
|
|
|
fbit[0] = 1;
|
2004-06-01 20:23:12 +00:00
|
|
|
/* Get rid of the framing bit at the end of the vorbiscomment buffer
|
|
|
|
* if it exists since libFLAC seems to lose sync because of this
|
|
|
|
* bit in gstflacdec
|
|
|
|
*/
|
2011-04-19 16:55:31 +00:00
|
|
|
if (gst_buffer_memcmp (buffer, size - 1, fbit, 1) == 0) {
|
|
|
|
buffer = gst_buffer_make_writable (buffer);
|
|
|
|
gst_buffer_resize (buffer, 0, size - 1);
|
2004-06-01 20:23:12 +00:00
|
|
|
}
|
2003-12-08 22:04:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* The 4 byte metadata block header isn't accounted for in the total
|
|
|
|
* size of the metadata block
|
|
|
|
*/
|
2012-01-24 13:38:58 +00:00
|
|
|
gst_buffer_map (buffer, &map, GST_MAP_WRITE);
|
|
|
|
map.data[1] = (((map.size - 4) & 0xFF0000) >> 16);
|
|
|
|
map.data[2] = (((map.size - 4) & 0x00FF00) >> 8);
|
|
|
|
map.data[3] = ((map.size - 4) & 0x0000FF);
|
|
|
|
gst_buffer_unmap (buffer, &map);
|
2011-04-19 16:55:31 +00:00
|
|
|
|
2011-11-22 01:40:39 +00:00
|
|
|
GST_DEBUG_OBJECT (tag, "pushing %" G_GSIZE_FORMAT " byte vorbiscomment "
|
2012-01-24 13:38:58 +00:00
|
|
|
"buffer", map.size);
|
2003-12-08 22:04:46 +00:00
|
|
|
|
2008-08-06 15:34:55 +00:00
|
|
|
ret = gst_pad_push (tag->srcpad, buffer);
|
|
|
|
if (ret != GST_FLOW_OK) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2003-12-07 21:40:11 +00:00
|
|
|
tag->state = GST_FLAC_TAG_STATE_AUDIO_DATA;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The metadata blocks have been read, now we are reading audio data */
|
|
|
|
if (tag->state == GST_FLAC_TAG_STATE_AUDIO_DATA) {
|
2008-08-06 15:34:55 +00:00
|
|
|
GstBuffer *buffer;
|
2010-04-14 22:46:06 +00:00
|
|
|
guint avail;
|
|
|
|
|
|
|
|
avail = gst_adapter_available (tag->adapter);
|
|
|
|
if (avail > 0) {
|
|
|
|
buffer = gst_adapter_take_buffer (tag->adapter, avail);
|
|
|
|
ret = gst_pad_push (tag->srcpad, buffer);
|
|
|
|
}
|
2003-12-07 21:40:11 +00:00
|
|
|
}
|
close #333784 unref the result of gst_pad_get_parent() by: Christophe Fergeau.
Original commit message from CVS:
* ext/cairo/gsttextoverlay.c: (gst_text_overlay_setcaps):
* ext/esd/esdmon.c: (gst_esdmon_get):
* ext/flac/gstflactag.c: (gst_flac_tag_chain):
* ext/gdk_pixbuf/gstgdkpixbuf.c: (gst_gdk_pixbuf_sink_setcaps),
(gst_gdk_pixbuf_sink_getcaps):
* ext/jpeg/gstjpegenc.c: (gst_jpegenc_getcaps),
(gst_jpegenc_setcaps):
* ext/jpeg/gstsmokedec.c: (gst_smokedec_chain):
* ext/jpeg/gstsmokeenc.c: (gst_smokeenc_getcaps),
(gst_smokeenc_setcaps):
* ext/libmng/gstmngdec.c: (gst_mngdec_sinklink),
(gst_mngdec_src_getcaps):
* ext/libmng/gstmngenc.c: (gst_mngenc_sinklink),
(gst_mngenc_chain):
* ext/libpng/gstpngenc.c: (gst_pngenc_setcaps):
* ext/mikmod/gstmikmod.c: (gst_mikmod_srclink):
* ext/speex/gstspeexdec.c: (speex_dec_convert),
(speex_dec_src_event), (speex_dec_chain):
* gst/avi/gstavimux.c: (gst_avimux_vidsinkconnect),
(gst_avimux_audsinkconnect), (gst_avimux_handle_event):
* gst/debug/negotiation.c: (gst_negotiation_getcaps),
(gst_negotiation_pad_link), (gst_negotiation_chain):
* gst/flx/gstflxdec.c: (gst_flxdec_src_query_handler),
(gst_flxdec_chain):
* gst/interleave/deinterleave.c: (deinterleave_sink_link),
(deinterleave_chain):
* gst/law/mulaw-encode.c: (mulawenc_setcaps):
* gst/median/gstmedian.c: (gst_median_link):
* gst/monoscope/gstmonoscope.c: (gst_monoscope_srcconnect),
(gst_monoscope_chain):
* gst/rtp/gstrtpL16pay.c: (gst_rtpL16pay_sinkconnect):
* gst/wavenc/gstwavenc.c: (gst_wavenc_sink_setcaps):
* sys/osxaudio/gstosxaudiosink.c: (gst_osxaudiosink_chain):
* sys/osxaudio/gstosxaudiosrc.c: (gst_osxaudiosrc_get):
close #333784 unref the result of gst_pad_get_parent()
by: Christophe Fergeau.
2006-03-13 15:49:08 +00:00
|
|
|
|
|
|
|
cleanup:
|
2013-04-17 05:50:27 +00:00
|
|
|
GST_LOG_OBJECT (pad, "state: %d, ret: %d", tag->state, ret);
|
2008-08-06 15:34:55 +00:00
|
|
|
return ret;
|
2003-12-07 21:40:11 +00:00
|
|
|
|
2011-04-19 16:55:31 +00:00
|
|
|
/* ERRORS */
|
|
|
|
no_buffer:
|
|
|
|
{
|
|
|
|
GST_ELEMENT_ERROR (tag, CORE, TOO_LAZY, (NULL),
|
|
|
|
("Error creating 12-byte buffer for padding block"));
|
|
|
|
ret = GST_FLOW_ERROR;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
no_comment:
|
|
|
|
{
|
|
|
|
GST_ELEMENT_ERROR (tag, CORE, TAG, (NULL),
|
|
|
|
("Error converting tag list to vorbiscomment buffer"));
|
|
|
|
ret = GST_FLOW_ERROR;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
comment_too_long:
|
|
|
|
{
|
|
|
|
/* FLAC vorbis comment blocks are limited to 2^24 bytes,
|
|
|
|
* while the vorbis specs allow more than that. Shouldn't
|
|
|
|
* be a real world problem though
|
|
|
|
*/
|
|
|
|
GST_ELEMENT_ERROR (tag, CORE, TAG, (NULL),
|
2011-11-22 01:40:39 +00:00
|
|
|
("Vorbis comment of size %" G_GSIZE_FORMAT " too long", size));
|
2011-04-19 16:55:31 +00:00
|
|
|
ret = GST_FLOW_ERROR;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
2003-12-07 21:40:11 +00:00
|
|
|
|
2005-09-02 15:44:50 +00:00
|
|
|
static GstStateChangeReturn
|
|
|
|
gst_flac_tag_change_state (GstElement * element, GstStateChange transition)
|
2003-12-07 21:40:11 +00:00
|
|
|
{
|
|
|
|
GstFlacTag *tag;
|
|
|
|
|
|
|
|
tag = GST_FLAC_TAG (element);
|
|
|
|
|
2005-09-02 15:44:50 +00:00
|
|
|
switch (transition) {
|
|
|
|
case GST_STATE_CHANGE_NULL_TO_READY:
|
2003-12-07 21:40:11 +00:00
|
|
|
break;
|
2005-09-02 15:44:50 +00:00
|
|
|
case GST_STATE_CHANGE_READY_TO_PAUSED:
|
2003-12-07 21:40:11 +00:00
|
|
|
break;
|
2005-09-02 15:44:50 +00:00
|
|
|
case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
|
2003-12-07 21:40:11 +00:00
|
|
|
/* do something to get out of the chain function faster */
|
|
|
|
break;
|
2005-09-02 15:44:50 +00:00
|
|
|
case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
|
2003-12-07 21:40:11 +00:00
|
|
|
break;
|
2005-09-02 15:44:50 +00:00
|
|
|
case GST_STATE_CHANGE_PAUSED_TO_READY:
|
2008-08-06 15:34:55 +00:00
|
|
|
gst_adapter_clear (tag->adapter);
|
2003-12-08 22:04:46 +00:00
|
|
|
if (tag->vorbiscomment) {
|
2004-03-15 19:32:27 +00:00
|
|
|
gst_buffer_unref (tag->vorbiscomment);
|
|
|
|
tag->vorbiscomment = NULL;
|
2003-12-08 22:04:46 +00:00
|
|
|
}
|
|
|
|
if (tag->tags) {
|
2012-08-04 15:10:16 +00:00
|
|
|
gst_tag_list_unref (tag->tags);
|
2008-08-06 15:34:55 +00:00
|
|
|
tag->tags = NULL;
|
2003-12-08 22:04:46 +00:00
|
|
|
}
|
2008-08-06 15:34:55 +00:00
|
|
|
tag->metadata_block_size = 0;
|
|
|
|
tag->metadata_last_block = FALSE;
|
2003-12-07 21:40:11 +00:00
|
|
|
tag->state = GST_FLAC_TAG_STATE_INIT;
|
|
|
|
break;
|
2005-09-02 15:44:50 +00:00
|
|
|
case GST_STATE_CHANGE_READY_TO_NULL:
|
2003-12-07 21:40:11 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-04-19 16:55:31 +00:00
|
|
|
return GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
|
2003-12-07 21:40:11 +00:00
|
|
|
}
|