fix build failure
[profile/ivi/gst-plugins-bad0.10.git] / gst / id3tag / gstid3mux.c
1 /* GStreamer ID3 v1 and v2 muxer
2  *
3  * Copyright (C) 2006 Christophe Fergeau <teuf@gnome.org>
4  * Copyright (C) 2006 Tim-Philipp Müller <tim centricular net>
5  * Copyright (C) 2009 Pioneers of the Inevitable <songbird@songbirdnest.com>
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Library General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Library General Public License for more details.
16  *
17  * You should have received a copy of the GNU Library General Public
18  * License along with this library; if not, write to the
19  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20  * Boston, MA 02111-1307, USA.
21  */
22
23 /**
24  * SECTION:element-id3mux
25  * @see_also: #GstID3Demux, #GstTagSetter
26  *
27  * This element adds ID3v2 tags to the beginning of a stream, and ID3v1 tags
28  * to the end.
29  *
30  * It defaults to writing ID3 version 2.3.0 tags (since those are the most
31  * widely supported), but can optionally write version 2.4.0 tags.
32  *
33  * Applications can set the tags to write using the #GstTagSetter interface.
34  * Tags sent by upstream elements will be picked up automatically (and merged
35  * according to the merge mode set via the tag setter interface).
36  *
37  * <refsect2>
38  * <title>Example pipelines</title>
39  * |[
40  * gst-launch -v filesrc location=foo.ogg ! decodebin ! audioconvert ! lame ! id3mux ! filesink location=foo.mp3
41  * ]| A pipeline that transcodes a file from Ogg/Vorbis to mp3 format with
42  * ID3 tags that contain the same metadata as the the Ogg/Vorbis file.
43  * Make sure the Ogg/Vorbis file actually has comments to preserve.
44  * |[
45  * gst-launch -m filesrc location=foo.mp3 ! id3demux ! fakesink silent=TRUE 2&gt; /dev/null | grep taglist
46  * ]| Verify that tags have been written.
47  * </refsect2>
48  */
49
50 #ifdef HAVE_CONFIG_H
51 #include <config.h>
52 #endif
53
54 #include "gstid3mux.h"
55 #include <gst/tag/tag.h>
56
57 #include <string.h>
58
59 GST_DEBUG_CATEGORY (gst_id3_mux_debug);
60 #define GST_CAT_DEFAULT gst_id3_mux_debug
61
62 enum
63 {
64   ARG_0,
65   ARG_WRITE_V1,
66   ARG_WRITE_V2,
67   ARG_V2_MAJOR_VERSION
68 };
69
70 #define DEFAULT_WRITE_V1 FALSE
71 #define DEFAULT_WRITE_V2 TRUE
72 #define DEFAULT_V2_MAJOR_VERSION 3
73
74 static GstStaticPadTemplate sink_template = GST_STATIC_PAD_TEMPLATE ("sink",
75     GST_PAD_SINK,
76     GST_PAD_ALWAYS,
77     GST_STATIC_CAPS ("ANY"));
78
79 static GstStaticPadTemplate src_template = GST_STATIC_PAD_TEMPLATE ("src",
80     GST_PAD_SRC,
81     GST_PAD_ALWAYS,
82     GST_STATIC_CAPS ("application/x-id3"));
83
84 GST_BOILERPLATE (GstId3Mux, gst_id3_mux, GstTagMux, GST_TYPE_TAG_MUX);
85
86 static GstBuffer *gst_id3_mux_render_v2_tag (GstTagMux * mux,
87     const GstTagList * taglist);
88 static GstBuffer *gst_id3_mux_render_v1_tag (GstTagMux * mux,
89     const GstTagList * taglist);
90
91 static void gst_id3_mux_set_property (GObject * object, guint prop_id,
92     const GValue * value, GParamSpec * pspec);
93 static void gst_id3_mux_get_property (GObject * object, guint prop_id,
94     GValue * value, GParamSpec * pspec);
95
96 static void
97 gst_id3_mux_base_init (gpointer g_class)
98 {
99   GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
100
101   gst_element_class_add_static_pad_template (element_class,
102       &sink_template);
103
104   gst_element_class_add_static_pad_template (element_class, &src_template);
105
106   gst_element_class_set_details_simple (element_class,
107       "ID3 v1 and v2 Muxer", "Formatter/Metadata",
108       "Adds an ID3v2 header and ID3v1 footer to a file",
109       "Michael Smith <msmith@songbirdnest.com>, "
110       "Tim-Philipp Müller <tim centricular net>");
111 }
112
113 static void
114 gst_id3_mux_class_init (GstId3MuxClass * klass)
115 {
116   GObjectClass *gobject_class = (GObjectClass *) klass;
117
118   gobject_class->set_property = gst_id3_mux_set_property;
119   gobject_class->get_property = gst_id3_mux_get_property;
120
121   g_object_class_install_property (gobject_class, ARG_WRITE_V1,
122       g_param_spec_boolean ("write-v1", "Write id3v1 tag",
123           "Write an id3v1 tag at the end of the file", DEFAULT_WRITE_V1,
124           G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS));
125
126   g_object_class_install_property (gobject_class, ARG_WRITE_V2,
127       g_param_spec_boolean ("write-v2", "Write id3v2 tag",
128           "Write an id3v2 tag at the start of the file", DEFAULT_WRITE_V2,
129           G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS));
130
131   g_object_class_install_property (gobject_class, ARG_V2_MAJOR_VERSION,
132       g_param_spec_int ("v2-version", "Version (3 or 4) of id3v2 tag",
133           "Set version (3 for id3v2.3, 4 for id3v2.4) of id3v2 tags",
134           3, 4, DEFAULT_V2_MAJOR_VERSION,
135           G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS));
136
137   GST_TAG_MUX_CLASS (klass)->render_start_tag =
138       GST_DEBUG_FUNCPTR (gst_id3_mux_render_v2_tag);
139   GST_TAG_MUX_CLASS (klass)->render_end_tag =
140       GST_DEBUG_FUNCPTR (gst_id3_mux_render_v1_tag);
141 }
142
143 static void
144 gst_id3_mux_init (GstId3Mux * id3mux, GstId3MuxClass * id3mux_class)
145 {
146   id3mux->write_v1 = DEFAULT_WRITE_V1;
147   id3mux->write_v2 = DEFAULT_WRITE_V2;
148
149   id3mux->v2_major_version = DEFAULT_V2_MAJOR_VERSION;
150 }
151
152 static void
153 gst_id3_mux_set_property (GObject * object, guint prop_id,
154     const GValue * value, GParamSpec * pspec)
155 {
156   GstId3Mux *mux = GST_ID3_MUX (object);
157
158   switch (prop_id) {
159     case ARG_WRITE_V1:
160       mux->write_v1 = g_value_get_boolean (value);
161       break;
162     case ARG_WRITE_V2:
163       mux->write_v2 = g_value_get_boolean (value);
164       break;
165     case ARG_V2_MAJOR_VERSION:
166       mux->v2_major_version = g_value_get_int (value);
167       break;
168     default:
169       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
170       break;
171   }
172 }
173
174 static void
175 gst_id3_mux_get_property (GObject * object, guint prop_id,
176     GValue * value, GParamSpec * pspec)
177 {
178   GstId3Mux *mux = GST_ID3_MUX (object);
179
180   switch (prop_id) {
181     case ARG_WRITE_V1:
182       g_value_set_boolean (value, mux->write_v1);
183       break;
184     case ARG_WRITE_V2:
185       g_value_set_boolean (value, mux->write_v2);
186       break;
187     case ARG_V2_MAJOR_VERSION:
188       g_value_set_int (value, mux->v2_major_version);
189       break;
190     default:
191       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
192       break;
193   }
194 }
195
196 static GstBuffer *
197 gst_id3_mux_render_v2_tag (GstTagMux * mux, const GstTagList * taglist)
198 {
199   GstId3Mux *id3mux = GST_ID3_MUX (mux);
200
201   if (id3mux->write_v2)
202     return id3_mux_render_v2_tag (mux, taglist, id3mux->v2_major_version);
203   else
204     return NULL;
205 }
206
207 static GstBuffer *
208 gst_id3_mux_render_v1_tag (GstTagMux * mux, const GstTagList * taglist)
209 {
210   GstId3Mux *id3mux = GST_ID3_MUX (mux);
211
212   if (id3mux->write_v1)
213     return id3_mux_render_v1_tag (mux, taglist);
214   else
215     return NULL;
216 }
217
218 static gboolean
219 plugin_init (GstPlugin * plugin)
220 {
221   GST_DEBUG_CATEGORY_INIT (gst_id3_mux_debug, "id3mux", 0,
222       "ID3 v1 and v2 tag muxer");
223
224   if (!gst_element_register (plugin, "id3mux", GST_RANK_PRIMARY,
225           GST_TYPE_ID3_MUX))
226     return FALSE;
227
228   gst_tag_register_musicbrainz_tags ();
229
230   return TRUE;
231 }
232
233 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
234     GST_VERSION_MINOR,
235     "id3tag",
236     "ID3 v1 and v2 muxing plugin",
237     plugin_init, VERSION, "LGPL", GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN);