Debian Codegraph @

gst/id3tag/gstid3mux.c

raw symbols SCIP
1 /* GStreamer ID3 v1 and v2 muxer
2 *
3 * Copyright (C) 2006 Christophe Fergeau <[email protected]>
4 * Copyright (C) 2006-2012 Tim-Philipp Müller <tim centricular net>
5 * Copyright (C) 2009 Pioneers of the Inevitable <[email protected]>
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., 51 Franklin St, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
21 */
22
23 /**
24 * SECTION:element-id3mux
25 * @title: id3mux
26 * @see_also: #GstID3Demux, #GstTagSetter
27 *
28 * This element adds ID3v2 tags to the beginning of a stream, and ID3v1 tags
29 * to the end.
30 *
31 * It defaults to writing ID3 version 2.3.0 tags (since those are the most
32 * widely supported), but can optionally write version 2.4.0 tags.
33 *
34 * Applications can set the tags to write using the #GstTagSetter interface.
35 * Tags sent by upstream elements will be picked up automatically (and merged
36 * according to the merge mode set via the tag setter interface).
37 *
38 * ## Example pipelines
39 * |[
40 * gst-launch-1.0 -v filesrc location=foo.ogg ! decodebin ! audioconvert ! 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-1.0 -m filesrc location=foo.mp3 ! id3demux ! fakesink silent=TRUE
46 * ]| Verify that tags have been written.
47 *
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 PROP_0,
65 PROP_WRITE_V1,
66 PROP_WRITE_V2,
67 PROP_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 G_DEFINE_TYPE_WITH_CODE (GstId3Mux, gst_id3_mux, GST_TYPE_TAG_MUX,
85 GST_DEBUG_CATEGORY_INIT (gst_id3_mux_debug, "id3mux", 0,
86 "ID3 v1 and v2 tag muxer");
87 );
88 GST_ELEMENT_REGISTER_DEFINE_WITH_CODE (id3mux, "id3mux", GST_RANK_PRIMARY,
89 GST_TYPE_ID3_MUX, gst_tag_register_musicbrainz_tags ());
90
91 static GstBuffer *gst_id3_mux_render_v2_tag (GstTagMux * mux,
92 const GstTagList * taglist);
93 static GstBuffer *gst_id3_mux_render_v1_tag (GstTagMux * mux,
94 const GstTagList * taglist);
95
96 static void gst_id3_mux_set_property (GObject * object, guint prop_id,
97 const GValue * value, GParamSpec * pspec);
98 static void gst_id3_mux_get_property (GObject * object, guint prop_id,
99 GValue * value, GParamSpec * pspec);
100
101 static void
102 gst_id3_mux_class_init (GstId3MuxClass * klass)
103 {
104 GstElementClass *element_class = (GstElementClass *) klass;
105 GObjectClass *gobject_class = (GObjectClass *) klass;
106
107 gobject_class->set_property = gst_id3_mux_set_property;
108 gobject_class->get_property = gst_id3_mux_get_property;
109
110 g_object_class_install_property (gobject_class, PROP_WRITE_V1,
111 g_param_spec_boolean ("write-v1", "Write id3v1 tag",
112 "Write an id3v1 tag at the end of the file", DEFAULT_WRITE_V1,
113 G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS));
114
115 g_object_class_install_property (gobject_class, PROP_WRITE_V2,
116 g_param_spec_boolean ("write-v2", "Write id3v2 tag",
117 "Write an id3v2 tag at the start of the file", DEFAULT_WRITE_V2,
118 G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS));
119
120 g_object_class_install_property (gobject_class, PROP_V2_MAJOR_VERSION,
121 g_param_spec_int ("v2-version", "Version (3 or 4) of id3v2 tag",
122 "Set version (3 for id3v2.3, 4 for id3v2.4) of id3v2 tags",
123 3, 4, DEFAULT_V2_MAJOR_VERSION,
124 G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS));
125
126 GST_TAG_MUX_CLASS (klass)->render_start_tag =
127 GST_DEBUG_FUNCPTR (gst_id3_mux_render_v2_tag);
128 GST_TAG_MUX_CLASS (klass)->render_end_tag =
129 GST_DEBUG_FUNCPTR (gst_id3_mux_render_v1_tag);
130
131 gst_element_class_set_static_metadata (element_class,
132 "ID3 v1 and v2 Muxer", "Formatter/Metadata",
133 "Adds an ID3v2 header and ID3v1 footer to a file",
134 "Michael Smith <[email protected]>, "
135 "Tim-Philipp Müller <tim centricular net>");
136
137 gst_element_class_add_static_pad_template (element_class, &sink_template);
138 gst_element_class_add_static_pad_template (element_class, &src_template);
139 }
140
141 static void
142 gst_id3_mux_init (GstId3Mux * id3mux)
143 {
144 id3mux->write_v1 = DEFAULT_WRITE_V1;
145 id3mux->write_v2 = DEFAULT_WRITE_V2;
146
147 id3mux->v2_major_version = DEFAULT_V2_MAJOR_VERSION;
148 }
149
150 static void
151 gst_id3_mux_set_property (GObject * object, guint prop_id,
152 const GValue * value, GParamSpec * pspec)
153 {
154 GstId3Mux *mux = GST_ID3_MUX (object);
155
156 switch (prop_id) {
157 case PROP_WRITE_V1:
158 mux->write_v1 = g_value_get_boolean (value);
159 break;
160 case PROP_WRITE_V2:
161 mux->write_v2 = g_value_get_boolean (value);
162 break;
163 case PROP_V2_MAJOR_VERSION:
164 mux->v2_major_version = g_value_get_int (value);
165 break;
166 default:
167 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
168 break;
169 }
170 }
171
172 static void
173 gst_id3_mux_get_property (GObject * object, guint prop_id,
174 GValue * value, GParamSpec * pspec)
175 {
176 GstId3Mux *mux = GST_ID3_MUX (object);
177
178 switch (prop_id) {
179 case PROP_WRITE_V1:
180 g_value_set_boolean (value, mux->write_v1);
181 break;
182 case PROP_WRITE_V2:
183 g_value_set_boolean (value, mux->write_v2);
184 break;
185 case PROP_V2_MAJOR_VERSION:
186 g_value_set_int (value, mux->v2_major_version);
187 break;
188 default:
189 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
190 break;
191 }
192 }
193
194 static GstBuffer *
195 gst_id3_mux_render_v2_tag (GstTagMux * mux, const GstTagList * taglist)
196 {
197 GstId3Mux *id3mux = GST_ID3_MUX (mux);
198
199 if (id3mux->write_v2)
200 return id3_mux_render_v2_tag (mux, taglist, id3mux->v2_major_version);
201 else
202 return NULL;
203 }
204
205 static GstBuffer *
206 gst_id3_mux_render_v1_tag (GstTagMux * mux, const GstTagList * taglist)
207 {
208 GstId3Mux *id3mux = GST_ID3_MUX (mux);
209
210 if (id3mux->write_v1)
211 return id3_mux_render_v1_tag (mux, taglist);
212 else
213 return NULL;
214 }
215
216 static gboolean
217 plugin_init (GstPlugin * plugin)
218 {
219 return GST_ELEMENT_REGISTER (id3mux, plugin);
220 }
221
222 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
223 GST_VERSION_MINOR,
224 id3tag,
225 "ID3 v1 and v2 muxing plugin",
226 plugin_init, VERSION, "LGPL", GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN);