2008-06-11 14:28:44 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) 2008 Stefan Kost <ensonic@users.sf.net>
|
|
|
|
*
|
|
|
|
* gsttaginject.c:
|
|
|
|
*
|
|
|
|
* 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.
|
2008-06-11 14:28:44 +00:00
|
|
|
*/
|
|
|
|
/**
|
|
|
|
* SECTION:element-taginject
|
|
|
|
*
|
2008-07-22 06:32:03 +00:00
|
|
|
* Element that injects new metadata tags, but passes incomming data through
|
2008-06-11 14:28:44 +00:00
|
|
|
* unmodified.
|
2009-01-28 10:29:42 +00:00
|
|
|
*
|
|
|
|
* <refsect2>
|
|
|
|
* <title>Example launch lines</title>
|
2008-06-11 14:28:44 +00:00
|
|
|
* |[
|
2012-08-26 21:39:55 +00:00
|
|
|
* gst-launch-1.0 audiotestsrc num-buffers=100 ! taginject tags="title=testsrc,artist=gstreamer" ! vorbisenc ! oggmux ! filesink location=test.ogg
|
2008-09-03 11:10:25 +00:00
|
|
|
* ]| set title and artist
|
|
|
|
* |[
|
2012-08-26 21:39:55 +00:00
|
|
|
* gst-launch-1.0 audiotestsrc num-buffers=100 ! taginject tags="keywords=\{\"testone\",\"audio\"\},title=\"audio testtone\"" ! vorbisenc ! oggmux ! filesink location=test.ogg
|
2010-02-05 11:28:53 +00:00
|
|
|
* ]| set keywords and title demonstrating quoting of special chars and handling lists
|
2009-01-28 10:29:42 +00:00
|
|
|
* </refsect2>
|
2008-06-11 14:28:44 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include "gsttaginject.h"
|
|
|
|
|
|
|
|
static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
|
|
|
|
GST_PAD_SINK,
|
|
|
|
GST_PAD_ALWAYS,
|
|
|
|
GST_STATIC_CAPS_ANY);
|
|
|
|
|
|
|
|
static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
|
|
|
|
GST_PAD_SRC,
|
|
|
|
GST_PAD_ALWAYS,
|
|
|
|
GST_STATIC_CAPS_ANY);
|
|
|
|
|
|
|
|
GST_DEBUG_CATEGORY_STATIC (gst_tag_inject_debug);
|
|
|
|
#define GST_CAT_DEFAULT gst_tag_inject_debug
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
2008-06-13 21:13:46 +00:00
|
|
|
PROP_TAGS = 1
|
2008-06-11 14:28:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2011-06-07 10:06:08 +00:00
|
|
|
#define gst_tag_inject_parent_class parent_class
|
|
|
|
G_DEFINE_TYPE (GstTagInject, gst_tag_inject, GST_TYPE_BASE_TRANSFORM);
|
2008-06-11 14:28:44 +00:00
|
|
|
|
|
|
|
static void gst_tag_inject_finalize (GObject * object);
|
|
|
|
static void gst_tag_inject_set_property (GObject * object, guint prop_id,
|
|
|
|
const GValue * value, GParamSpec * pspec);
|
|
|
|
static void gst_tag_inject_get_property (GObject * object, guint prop_id,
|
|
|
|
GValue * value, GParamSpec * pspec);
|
|
|
|
|
2008-07-22 06:32:03 +00:00
|
|
|
static GstFlowReturn gst_tag_inject_transform_ip (GstBaseTransform * trans,
|
|
|
|
GstBuffer * buf);
|
2008-06-11 14:28:44 +00:00
|
|
|
static gboolean gst_tag_inject_start (GstBaseTransform * trans);
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_tag_inject_finalize (GObject * object)
|
|
|
|
{
|
|
|
|
GstTagInject *self = GST_TAG_INJECT (object);
|
|
|
|
|
2008-06-13 21:13:46 +00:00
|
|
|
if (self->tags) {
|
2012-08-04 15:10:16 +00:00
|
|
|
gst_tag_list_unref (self->tags);
|
2008-06-13 21:13:46 +00:00
|
|
|
self->tags = NULL;
|
|
|
|
}
|
2008-06-11 14:28:44 +00:00
|
|
|
|
|
|
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_tag_inject_class_init (GstTagInjectClass * klass)
|
|
|
|
{
|
|
|
|
GObjectClass *gobject_class;
|
2011-06-07 10:06:08 +00:00
|
|
|
GstElementClass *gstelement_class;
|
2008-06-11 14:28:44 +00:00
|
|
|
GstBaseTransformClass *gstbasetrans_class;
|
|
|
|
|
|
|
|
gobject_class = G_OBJECT_CLASS (klass);
|
2011-06-07 10:06:08 +00:00
|
|
|
gstelement_class = GST_ELEMENT_CLASS (klass);
|
2008-06-11 14:28:44 +00:00
|
|
|
gstbasetrans_class = GST_BASE_TRANSFORM_CLASS (klass);
|
|
|
|
|
2011-06-07 10:06:08 +00:00
|
|
|
GST_DEBUG_CATEGORY_INIT (gst_tag_inject_debug, "taginject", 0,
|
|
|
|
"tag inject element");
|
|
|
|
|
2010-06-06 15:52:40 +00:00
|
|
|
gobject_class->set_property = gst_tag_inject_set_property;
|
|
|
|
gobject_class->get_property = gst_tag_inject_get_property;
|
2008-06-11 14:28:44 +00:00
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class, PROP_TAGS,
|
|
|
|
g_param_spec_string ("tags", "taglist",
|
|
|
|
"List of tags to inject into the target file",
|
|
|
|
NULL, G_PARAM_WRITABLE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
2010-06-06 15:52:40 +00:00
|
|
|
gobject_class->finalize = gst_tag_inject_finalize;
|
2008-06-11 14:28:44 +00:00
|
|
|
|
2012-04-09 23:51:41 +00:00
|
|
|
gst_element_class_set_static_metadata (gstelement_class,
|
2011-06-07 10:06:08 +00:00
|
|
|
"TagInject",
|
|
|
|
"Generic", "inject metadata tags", "Stefan Kost <ensonic@users.sf.net>");
|
|
|
|
gst_element_class_add_pad_template (gstelement_class,
|
|
|
|
gst_static_pad_template_get (&srctemplate));
|
|
|
|
gst_element_class_add_pad_template (gstelement_class,
|
|
|
|
gst_static_pad_template_get (&sinktemplate));
|
|
|
|
|
2008-07-22 06:32:03 +00:00
|
|
|
gstbasetrans_class->transform_ip =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_tag_inject_transform_ip);
|
2008-06-13 21:13:46 +00:00
|
|
|
|
2008-06-11 14:28:44 +00:00
|
|
|
gstbasetrans_class->start = GST_DEBUG_FUNCPTR (gst_tag_inject_start);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-06-07 10:06:08 +00:00
|
|
|
gst_tag_inject_init (GstTagInject * self)
|
2008-06-11 14:28:44 +00:00
|
|
|
{
|
2011-11-28 10:47:11 +00:00
|
|
|
GstBaseTransform *trans = GST_BASE_TRANSFORM (self);
|
|
|
|
|
|
|
|
gst_base_transform_set_gap_aware (trans, TRUE);
|
|
|
|
|
2008-06-11 14:28:44 +00:00
|
|
|
self->tags = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstFlowReturn
|
|
|
|
gst_tag_inject_transform_ip (GstBaseTransform * trans, GstBuffer * buf)
|
|
|
|
{
|
2008-06-13 21:13:46 +00:00
|
|
|
GstTagInject *self = GST_TAG_INJECT (trans);
|
2008-06-11 14:28:44 +00:00
|
|
|
|
2008-07-22 06:32:03 +00:00
|
|
|
if (G_UNLIKELY (!self->tags_sent)) {
|
|
|
|
self->tags_sent = TRUE;
|
|
|
|
/* send tags */
|
|
|
|
if (self->tags && !gst_tag_list_is_empty (self->tags)) {
|
2008-09-03 11:10:25 +00:00
|
|
|
GST_DEBUG ("tag event :%" GST_PTR_FORMAT, self->tags);
|
2011-11-02 11:09:20 +00:00
|
|
|
gst_pad_push_event (GST_BASE_TRANSFORM_SRC_PAD (trans),
|
2012-07-27 22:19:51 +00:00
|
|
|
gst_event_new_tag (gst_tag_list_ref (self->tags)));
|
2008-07-22 06:32:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-06-11 14:28:44 +00:00
|
|
|
return GST_FLOW_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_tag_inject_set_property (GObject * object, guint prop_id,
|
|
|
|
const GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
|
|
|
GstTagInject *self = GST_TAG_INJECT (object);
|
|
|
|
|
|
|
|
switch (prop_id) {
|
2008-09-03 11:10:25 +00:00
|
|
|
case PROP_TAGS:{
|
|
|
|
gchar *structure =
|
|
|
|
g_strdup_printf ("taglist,%s", g_value_get_string (value));
|
2011-10-30 11:44:53 +00:00
|
|
|
if (!(self->tags = gst_tag_list_new_from_string (structure))) {
|
2008-09-03 11:10:25 +00:00
|
|
|
GST_WARNING ("unparsable taglist = '%s'", structure);
|
|
|
|
}
|
2011-02-14 13:21:29 +00:00
|
|
|
|
|
|
|
/* make sure that tags will be send */
|
|
|
|
self->tags_sent = FALSE;
|
2008-06-11 14:28:44 +00:00
|
|
|
g_free (structure);
|
|
|
|
break;
|
2008-09-03 11:10:25 +00:00
|
|
|
}
|
2008-06-11 14:28:44 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_tag_inject_get_property (GObject * object, guint prop_id, GValue * value,
|
|
|
|
GParamSpec * pspec)
|
|
|
|
{
|
|
|
|
/*GstTagInject *self = GST_TAG_INJECT (object); */
|
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_tag_inject_start (GstBaseTransform * trans)
|
|
|
|
{
|
|
|
|
GstTagInject *self = GST_TAG_INJECT (trans);
|
|
|
|
|
2008-07-22 06:32:03 +00:00
|
|
|
/* we need to sent tags _transform_ip() once */
|
|
|
|
self->tags_sent = FALSE;
|
2008-06-11 14:28:44 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|