Stefan Kost | b3cfa35 | 2008-06-11 14:28:44 +0000 | [diff] [blame] | 1 | /* GStreamer |
| 2 | * Copyright (C) 2008 Stefan Kost <ensonic@users.sf.net> |
| 3 | * |
| 4 | * gsttaginject.c: |
| 5 | * |
| 6 | * This library is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU Library General Public |
| 8 | * License as published by the Free Software Foundation; either |
| 9 | * version 2 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * This library is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | * Library General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU Library General Public |
| 17 | * License along with this library; if not, write to the |
| 18 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
| 19 | * Boston, MA 02111-1307, USA. |
| 20 | */ |
| 21 | /** |
| 22 | * SECTION:element-taginject |
| 23 | * |
Stefan Kost | da2d6b6 | 2008-07-22 06:32:03 +0000 | [diff] [blame] | 24 | * Element that injects new metadata tags, but passes incomming data through |
Stefan Kost | b3cfa35 | 2008-06-11 14:28:44 +0000 | [diff] [blame] | 25 | * unmodified. |
Stefan Kost | a99d3f8 | 2009-01-28 12:29:42 +0200 | [diff] [blame] | 26 | * |
| 27 | * <refsect2> |
| 28 | * <title>Example launch lines</title> |
Stefan Kost | b3cfa35 | 2008-06-11 14:28:44 +0000 | [diff] [blame] | 29 | * |[ |
| 30 | * gst-launch audiotestsrc num-buffers=100 ! taginject tags="title=testsrc,artist=gstreamer" ! vorbisenc ! oggmux ! filesink location=test.ogg |
Stefan Kost | d64815f | 2008-09-03 11:10:25 +0000 | [diff] [blame] | 31 | * ]| set title and artist |
| 32 | * |[ |
Stefan Kost | f003fef | 2010-02-05 13:28:53 +0200 | [diff] [blame] | 33 | * gst-launch audiotestsrc num-buffers=100 ! taginject tags="keywords=\{\"testone\",\"audio\"\},title=\"audio testtone\"" ! vorbisenc ! oggmux ! filesink location=test.ogg |
| 34 | * ]| set keywords and title demonstrating quoting of special chars and handling lists |
Stefan Kost | a99d3f8 | 2009-01-28 12:29:42 +0200 | [diff] [blame] | 35 | * </refsect2> |
Stefan Kost | b3cfa35 | 2008-06-11 14:28:44 +0000 | [diff] [blame] | 36 | */ |
| 37 | |
| 38 | #ifdef HAVE_CONFIG_H |
| 39 | # include "config.h" |
| 40 | #endif |
| 41 | |
| 42 | #include <stdlib.h> |
| 43 | |
| 44 | #include "gsttaginject.h" |
| 45 | |
| 46 | static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink", |
| 47 | GST_PAD_SINK, |
| 48 | GST_PAD_ALWAYS, |
| 49 | GST_STATIC_CAPS_ANY); |
| 50 | |
| 51 | static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src", |
| 52 | GST_PAD_SRC, |
| 53 | GST_PAD_ALWAYS, |
| 54 | GST_STATIC_CAPS_ANY); |
| 55 | |
| 56 | GST_DEBUG_CATEGORY_STATIC (gst_tag_inject_debug); |
| 57 | #define GST_CAT_DEFAULT gst_tag_inject_debug |
| 58 | |
| 59 | enum |
| 60 | { |
Tim-Philipp Müller | 7a11861 | 2008-06-13 21:13:46 +0000 | [diff] [blame] | 61 | PROP_TAGS = 1 |
Stefan Kost | b3cfa35 | 2008-06-11 14:28:44 +0000 | [diff] [blame] | 62 | }; |
| 63 | |
| 64 | |
| 65 | #define DEBUG_INIT(bla) \ |
| 66 | GST_DEBUG_CATEGORY_INIT (gst_tag_inject_debug, "taginject", 0, "tag inject element"); |
| 67 | |
| 68 | GST_BOILERPLATE_FULL (GstTagInject, gst_tag_inject, GstBaseTransform, |
| 69 | GST_TYPE_BASE_TRANSFORM, DEBUG_INIT); |
| 70 | |
| 71 | static void gst_tag_inject_finalize (GObject * object); |
| 72 | static void gst_tag_inject_set_property (GObject * object, guint prop_id, |
| 73 | const GValue * value, GParamSpec * pspec); |
| 74 | static void gst_tag_inject_get_property (GObject * object, guint prop_id, |
| 75 | GValue * value, GParamSpec * pspec); |
| 76 | |
Stefan Kost | da2d6b6 | 2008-07-22 06:32:03 +0000 | [diff] [blame] | 77 | static GstFlowReturn gst_tag_inject_transform_ip (GstBaseTransform * trans, |
| 78 | GstBuffer * buf); |
Stefan Kost | b3cfa35 | 2008-06-11 14:28:44 +0000 | [diff] [blame] | 79 | static gboolean gst_tag_inject_start (GstBaseTransform * trans); |
| 80 | |
| 81 | |
| 82 | static void |
| 83 | gst_tag_inject_base_init (gpointer g_class) |
| 84 | { |
| 85 | GstElementClass *gstelement_class = GST_ELEMENT_CLASS (g_class); |
| 86 | |
| 87 | gst_element_class_set_details_simple (gstelement_class, |
| 88 | "TagInject", |
| 89 | "Generic", "inject metadata tags", "Stefan Kost <ensonic@users.sf.net>"); |
| 90 | gst_element_class_add_pad_template (gstelement_class, |
| 91 | gst_static_pad_template_get (&srctemplate)); |
| 92 | gst_element_class_add_pad_template (gstelement_class, |
| 93 | gst_static_pad_template_get (&sinktemplate)); |
| 94 | } |
| 95 | |
| 96 | static void |
| 97 | gst_tag_inject_finalize (GObject * object) |
| 98 | { |
| 99 | GstTagInject *self = GST_TAG_INJECT (object); |
| 100 | |
Tim-Philipp Müller | 7a11861 | 2008-06-13 21:13:46 +0000 | [diff] [blame] | 101 | if (self->tags) { |
| 102 | gst_tag_list_free (self->tags); |
| 103 | self->tags = NULL; |
| 104 | } |
Stefan Kost | b3cfa35 | 2008-06-11 14:28:44 +0000 | [diff] [blame] | 105 | |
| 106 | G_OBJECT_CLASS (parent_class)->finalize (object); |
| 107 | } |
| 108 | |
| 109 | static void |
| 110 | gst_tag_inject_class_init (GstTagInjectClass * klass) |
| 111 | { |
| 112 | GObjectClass *gobject_class; |
Stefan Kost | b3cfa35 | 2008-06-11 14:28:44 +0000 | [diff] [blame] | 113 | GstBaseTransformClass *gstbasetrans_class; |
| 114 | |
| 115 | gobject_class = G_OBJECT_CLASS (klass); |
Stefan Kost | b3cfa35 | 2008-06-11 14:28:44 +0000 | [diff] [blame] | 116 | gstbasetrans_class = GST_BASE_TRANSFORM_CLASS (klass); |
| 117 | |
Sebastian Dröge | f16ed4a | 2010-06-06 17:52:40 +0200 | [diff] [blame] | 118 | gobject_class->set_property = gst_tag_inject_set_property; |
| 119 | gobject_class->get_property = gst_tag_inject_get_property; |
Stefan Kost | b3cfa35 | 2008-06-11 14:28:44 +0000 | [diff] [blame] | 120 | |
| 121 | g_object_class_install_property (gobject_class, PROP_TAGS, |
| 122 | g_param_spec_string ("tags", "taglist", |
| 123 | "List of tags to inject into the target file", |
| 124 | NULL, G_PARAM_WRITABLE | G_PARAM_STATIC_STRINGS)); |
| 125 | |
Sebastian Dröge | f16ed4a | 2010-06-06 17:52:40 +0200 | [diff] [blame] | 126 | gobject_class->finalize = gst_tag_inject_finalize; |
Stefan Kost | b3cfa35 | 2008-06-11 14:28:44 +0000 | [diff] [blame] | 127 | |
Stefan Kost | da2d6b6 | 2008-07-22 06:32:03 +0000 | [diff] [blame] | 128 | gstbasetrans_class->transform_ip = |
| 129 | GST_DEBUG_FUNCPTR (gst_tag_inject_transform_ip); |
Tim-Philipp Müller | 7a11861 | 2008-06-13 21:13:46 +0000 | [diff] [blame] | 130 | |
Stefan Kost | b3cfa35 | 2008-06-11 14:28:44 +0000 | [diff] [blame] | 131 | gstbasetrans_class->start = GST_DEBUG_FUNCPTR (gst_tag_inject_start); |
| 132 | } |
| 133 | |
| 134 | static void |
| 135 | gst_tag_inject_init (GstTagInject * self, GstTagInjectClass * g_class) |
| 136 | { |
| 137 | self->tags = NULL; |
| 138 | } |
| 139 | |
Stefan Kost | b3cfa35 | 2008-06-11 14:28:44 +0000 | [diff] [blame] | 140 | static GstFlowReturn |
| 141 | gst_tag_inject_transform_ip (GstBaseTransform * trans, GstBuffer * buf) |
| 142 | { |
Tim-Philipp Müller | 7a11861 | 2008-06-13 21:13:46 +0000 | [diff] [blame] | 143 | GstTagInject *self = GST_TAG_INJECT (trans); |
Stefan Kost | b3cfa35 | 2008-06-11 14:28:44 +0000 | [diff] [blame] | 144 | |
Stefan Kost | da2d6b6 | 2008-07-22 06:32:03 +0000 | [diff] [blame] | 145 | if (G_UNLIKELY (!self->tags_sent)) { |
| 146 | self->tags_sent = TRUE; |
| 147 | /* send tags */ |
| 148 | if (self->tags && !gst_tag_list_is_empty (self->tags)) { |
Stefan Kost | d64815f | 2008-09-03 11:10:25 +0000 | [diff] [blame] | 149 | GST_DEBUG ("tag event :%" GST_PTR_FORMAT, self->tags); |
Stefan Kost | da2d6b6 | 2008-07-22 06:32:03 +0000 | [diff] [blame] | 150 | gst_element_found_tags (GST_ELEMENT (trans), |
| 151 | gst_tag_list_copy (self->tags)); |
| 152 | } |
| 153 | } |
| 154 | |
Stefan Kost | b3cfa35 | 2008-06-11 14:28:44 +0000 | [diff] [blame] | 155 | return GST_FLOW_OK; |
| 156 | } |
Stefan Kost | b3cfa35 | 2008-06-11 14:28:44 +0000 | [diff] [blame] | 157 | |
| 158 | static void |
| 159 | gst_tag_inject_set_property (GObject * object, guint prop_id, |
| 160 | const GValue * value, GParamSpec * pspec) |
| 161 | { |
| 162 | GstTagInject *self = GST_TAG_INJECT (object); |
Stefan Kost | b3cfa35 | 2008-06-11 14:28:44 +0000 | [diff] [blame] | 163 | |
| 164 | switch (prop_id) { |
Stefan Kost | d64815f | 2008-09-03 11:10:25 +0000 | [diff] [blame] | 165 | case PROP_TAGS:{ |
| 166 | gchar *structure = |
| 167 | g_strdup_printf ("taglist,%s", g_value_get_string (value)); |
| 168 | if (!(self->tags = gst_structure_from_string (structure, NULL))) { |
| 169 | GST_WARNING ("unparsable taglist = '%s'", structure); |
| 170 | } |
Tuukka Pasanen | d203b1e | 2011-02-14 15:21:29 +0200 | [diff] [blame] | 171 | |
| 172 | /* make sure that tags will be send */ |
| 173 | self->tags_sent = FALSE; |
Stefan Kost | b3cfa35 | 2008-06-11 14:28:44 +0000 | [diff] [blame] | 174 | g_free (structure); |
| 175 | break; |
Stefan Kost | d64815f | 2008-09-03 11:10:25 +0000 | [diff] [blame] | 176 | } |
Stefan Kost | b3cfa35 | 2008-06-11 14:28:44 +0000 | [diff] [blame] | 177 | default: |
| 178 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); |
| 179 | break; |
| 180 | } |
| 181 | } |
| 182 | |
| 183 | static void |
| 184 | gst_tag_inject_get_property (GObject * object, guint prop_id, GValue * value, |
| 185 | GParamSpec * pspec) |
| 186 | { |
| 187 | /*GstTagInject *self = GST_TAG_INJECT (object); */ |
| 188 | |
| 189 | switch (prop_id) { |
| 190 | default: |
| 191 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); |
| 192 | break; |
| 193 | } |
| 194 | } |
| 195 | |
| 196 | static gboolean |
| 197 | gst_tag_inject_start (GstBaseTransform * trans) |
| 198 | { |
| 199 | GstTagInject *self = GST_TAG_INJECT (trans); |
| 200 | |
Stefan Kost | da2d6b6 | 2008-07-22 06:32:03 +0000 | [diff] [blame] | 201 | /* we need to sent tags _transform_ip() once */ |
| 202 | self->tags_sent = FALSE; |
Stefan Kost | b3cfa35 | 2008-06-11 14:28:44 +0000 | [diff] [blame] | 203 | |
| 204 | return TRUE; |
| 205 | } |