1 /* GStreamer taglib-based ID3v2 muxer
2 * Copyright (C) 2006 Christophe Fergeau <teuf@gnome.org>
3 * Copyright (C) 2006 Tim-Philipp Müller <tim centricular net>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
22 * SECTION:element-id3v2mux
23 * @see_also: #GstID3Demux, #GstTagSetter
25 * This element adds ID3v2 tags to the beginning of a stream using the taglib
26 * library. More precisely, the tags written are ID3 version 2.4.0 tags (which
27 * means in practice that some hardware players or outdated programs might not
28 * be able to read them properly).
30 * Applications can set the tags to write using the #GstTagSetter interface.
31 * Tags sent by upstream elements will be picked up automatically (and merged
32 * according to the merge mode set via the tag setter interface).
35 * <title>Example pipelines</title>
37 * gst-launch -v filesrc location=foo.ogg ! decodebin ! audioconvert ! lame ! id3v2mux ! filesink location=foo.mp3
38 * ]| A pipeline that transcodes a file from Ogg/Vorbis to mp3 format with an
39 * ID3v2 that contains the same as the the Ogg/Vorbis file. Make sure the
40 * Ogg/Vorbis file actually has comments to preserve.
42 * gst-launch -m filesrc location=foo.mp3 ! id3demux ! fakesink silent=TRUE 2> /dev/null | grep taglist
43 * ]| Verify that tags have been written.
51 #include "gstid3v2mux.h"
55 #include <textidentificationframe.h>
56 #include <uniquefileidentifierframe.h>
57 #include <attachedpictureframe.h>
58 #include <relativevolumeframe.h>
59 #include <commentsframe.h>
60 #include <unknownframe.h>
61 #include <id3v2synchdata.h>
63 #include <gst/tag/tag.h>
65 using namespace TagLib;
67 GST_DEBUG_CATEGORY_STATIC (gst_id3v2_mux_debug);
68 #define GST_CAT_DEFAULT gst_id3v2_mux_debug
70 static GstStaticPadTemplate src_template = GST_STATIC_PAD_TEMPLATE ("src",
73 GST_STATIC_CAPS ("application/x-id3"));
76 GST_BOILERPLATE (GstId3v2Mux, gst_id3v2_mux, GstTagLibMux,
77 GST_TYPE_TAG_LIB_MUX);
79 static GstBuffer *gst_id3v2_mux_render_tag (GstTagLibMux * mux,
80 GstTagList * taglist);
83 gst_id3v2_mux_base_init (gpointer g_class)
85 GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
87 gst_element_class_add_pad_template (element_class,
88 gst_static_pad_template_get (&src_template));
90 gst_element_class_set_details_simple (element_class,
91 "TagLib-based ID3v2 Muxer", "Formatter/Metadata",
92 "Adds an ID3v2 header to the beginning of MP3 files using taglib",
93 "Christophe Fergeau <teuf@gnome.org>");
95 GST_DEBUG_CATEGORY_INIT (gst_id3v2_mux_debug, "id3v2mux", 0,
96 "taglib-based ID3v2 tag muxer");
100 gst_id3v2_mux_class_init (GstId3v2MuxClass * klass)
102 GST_TAG_LIB_MUX_CLASS (klass)->render_tag =
103 GST_DEBUG_FUNCPTR (gst_id3v2_mux_render_tag);
107 gst_id3v2_mux_init (GstId3v2Mux * id3v2mux, GstId3v2MuxClass * id3v2mux_class)
114 add_one_txxx_tag (ID3v2::Tag * id3v2tag, const gchar * key, const gchar * val)
116 ID3v2::UserTextIdentificationFrame * frame;
121 GST_DEBUG ("Setting %s to %s", key, val);
122 frame = new ID3v2::UserTextIdentificationFrame (String::UTF8);
123 id3v2tag->addFrame (frame);
124 frame->setDescription (key);
125 frame->setText (val);
129 typedef void (*GstId3v2MuxAddTagFunc) (ID3v2::Tag * id3v2tag,
130 const GstTagList * list,
131 const gchar * tag, guint num_tags, const gchar * data);
134 add_encoder_tag (ID3v2::Tag * id3v2tag, const GstTagList * list,
135 const gchar * tag, guint num_tags, const gchar * unused)
137 TagLib::StringList string_list;
140 /* ENCODER_VERSION is either handled with the ENCODER tag or not at all */
141 if (strcmp (tag, GST_TAG_ENCODER_VERSION) == 0)
144 for (n = 0; n < num_tags; ++n) {
145 gchar *encoder = NULL;
147 if (gst_tag_list_get_string_index (list, tag, n, &encoder) && encoder) {
148 guint encoder_version;
151 if (gst_tag_list_get_uint_index (list, GST_TAG_ENCODER_VERSION, n,
152 &encoder_version) && encoder_version > 0) {
153 s = g_strdup_printf ("%s %u", encoder, encoder_version);
155 s = g_strdup (encoder);
158 GST_LOG ("encoder[%u] = '%s'", n, s);
159 string_list.append (String (s, String::UTF8));
165 if (!string_list.isEmpty ()) {
166 ID3v2::TextIdentificationFrame * f;
168 f = new ID3v2::TextIdentificationFrame ("TSSE", String::UTF8);
169 id3v2tag->addFrame (f);
170 f->setText (string_list);
172 GST_WARNING ("Empty list for tag %s, skipping", tag);
177 add_date_tag (ID3v2::Tag * id3v2tag, const GstTagList * list,
178 const gchar * tag, guint num_tags, const gchar * unused)
180 TagLib::StringList string_list;
183 GST_LOG ("Adding date frame");
185 for (n = 0; n < num_tags; ++n) {
188 if (gst_tag_list_get_date_index (list, tag, n, &date) && date != NULL) {
192 year = g_date_get_year (date);
193 if (year > 500 && year < 2100) {
194 s = g_strdup_printf ("%u", year);
195 GST_LOG ("%s[%u] = '%s'", tag, n, s);
196 string_list.append (String (s, String::UTF8));
199 GST_WARNING ("invalid year %u, skipping", year);
206 if (!string_list.isEmpty ()) {
207 ID3v2::TextIdentificationFrame * f;
209 f = new ID3v2::TextIdentificationFrame ("TDRC", String::UTF8);
210 id3v2tag->addFrame (f);
211 f->setText (string_list);
213 GST_WARNING ("Empty list for tag %s, skipping", tag);
218 add_count_or_num_tag (ID3v2::Tag * id3v2tag, const GstTagList * list,
219 const gchar * tag, guint num_tags, const gchar * frame_id)
223 const gchar *gst_tag;
224 const gchar *corr_count; /* corresponding COUNT tag (if number) */
225 const gchar *corr_num; /* corresponding NUMBER tag (if count) */
228 GST_TAG_TRACK_NUMBER, GST_TAG_TRACK_COUNT, NULL}, {
229 GST_TAG_TRACK_COUNT, NULL, GST_TAG_TRACK_NUMBER}, {
230 GST_TAG_ALBUM_VOLUME_NUMBER, GST_TAG_ALBUM_VOLUME_COUNT, NULL}, {
231 GST_TAG_ALBUM_VOLUME_COUNT, NULL, GST_TAG_ALBUM_VOLUME_NUMBER}
235 for (idx = 0; idx < G_N_ELEMENTS (corr); ++idx) {
236 if (strcmp (corr[idx].gst_tag, tag) == 0)
240 g_assert (idx < G_N_ELEMENTS (corr));
241 g_assert (frame_id && strlen (frame_id) == 4);
243 if (corr[idx].corr_num == NULL) {
247 if (gst_tag_list_get_uint_index (list, tag, 0, &number)) {
248 ID3v2::TextIdentificationFrame * frame;
252 if (gst_tag_list_get_uint_index (list, corr[idx].corr_count, 0, &count))
253 tag_str = g_strdup_printf ("%u/%u", number, count);
255 tag_str = g_strdup_printf ("%u", number);
257 GST_DEBUG ("Setting %s to %s (frame_id = %s)", tag, tag_str, frame_id);
258 frame = new ID3v2::TextIdentificationFrame (frame_id, String::UTF8);
259 id3v2tag->addFrame (frame);
260 frame->setText (tag_str);
263 } else if (corr[idx].corr_count == NULL) {
267 if (gst_tag_list_get_uint_index (list, corr[idx].corr_num, 0, &count)) {
268 GST_DEBUG ("%s handled with %s, skipping", tag, corr[idx].corr_num);
269 } else if (gst_tag_list_get_uint_index (list, tag, 0, &count)) {
270 ID3v2::TextIdentificationFrame * frame;
273 tag_str = g_strdup_printf ("0/%u", count);
274 GST_DEBUG ("Setting %s to %s (frame_id = %s)", tag, tag_str, frame_id);
275 frame = new ID3v2::TextIdentificationFrame (frame_id, String::UTF8);
276 id3v2tag->addFrame (frame);
277 frame->setText (tag_str);
283 GST_WARNING ("more than one %s, can only handle one", tag);
288 add_unique_file_id_tag (ID3v2::Tag * id3v2tag, const GstTagList * list,
289 const gchar * tag, guint num_tags, const gchar * unused)
291 const gchar *origin = "http://musicbrainz.org";
292 gchar *id_str = NULL;
294 if (gst_tag_list_get_string_index (list, tag, 0, &id_str) && id_str) {
295 ID3v2::UniqueFileIdentifierFrame * frame;
297 GST_LOG ("Adding %s (%s): %s", tag, origin, id_str);
298 frame = new ID3v2::UniqueFileIdentifierFrame (origin, id_str);
299 id3v2tag->addFrame (frame);
305 add_musicbrainz_tag (ID3v2::Tag * id3v2tag, const GstTagList * list,
306 const gchar * tag, guint num_tags, const gchar * data)
310 const gchar gst_tag[28];
311 const gchar spec_id[28];
312 const gchar realworld_id[28];
315 GST_TAG_MUSICBRAINZ_ARTISTID, "MusicBrainz Artist Id",
316 "musicbrainz_artistid"}, {
317 GST_TAG_MUSICBRAINZ_ALBUMID, "MusicBrainz Album Id", "musicbrainz_albumid"}, {
318 GST_TAG_MUSICBRAINZ_ALBUMARTISTID, "MusicBrainz Album Artist Id",
319 "musicbrainz_albumartistid"}, {
320 GST_TAG_MUSICBRAINZ_TRMID, "MusicBrainz TRM Id", "musicbrainz_trmid"}, {
321 GST_TAG_CDDA_MUSICBRAINZ_DISCID, "MusicBrainz DiscID",
322 "musicbrainz_discid"}, {
323 /* the following one is more or less made up, there seems to be little
324 * evidence that any popular application is actually putting this info
325 * into TXXX frames; the first one comes from a musicbrainz wiki 'proposed
326 * tags' page, the second one is analogue to the vorbis/ape/flac tag. */
327 GST_TAG_CDDA_CDDB_DISCID, "CDDB DiscID", "discid"}
331 idx = (guint8) data[0];
332 g_assert (idx < G_N_ELEMENTS (mb_ids));
334 for (i = 0; i < num_tags; ++i) {
335 ID3v2::UserTextIdentificationFrame * frame;
338 if (gst_tag_list_get_string_index (list, tag, 0, &id_str) && id_str) {
339 GST_DEBUG ("Setting '%s' to '%s'", mb_ids[idx].spec_id, id_str);
341 /* add two frames, one with the ID the musicbrainz.org spec mentions
342 * and one with the ID that applications use in the real world */
343 frame = new ID3v2::UserTextIdentificationFrame (String::Latin1);
344 id3v2tag->addFrame (frame);
345 frame->setDescription (mb_ids[idx].spec_id);
346 frame->setText (id_str);
348 frame = new ID3v2::UserTextIdentificationFrame (String::Latin1);
349 id3v2tag->addFrame (frame);
350 frame->setDescription (mb_ids[idx].realworld_id);
351 frame->setText (id_str);
359 add_id3v2frame_tag (ID3v2::Tag * id3v2tag, const GstTagList * list,
360 const gchar * tag, guint num_tags, const gchar * frame_id)
362 ID3v2::FrameFactory * factory = ID3v2::FrameFactory::instance ();
365 for (i = 0; i < num_tags; ++i) {
366 ID3v2::Frame * frame;
370 val = gst_tag_list_get_value_index (list, tag, i);
371 buf = (GstBuffer *) gst_value_get_mini_object (val);
373 if (buf && GST_BUFFER_CAPS (buf)) {
377 s = gst_caps_get_structure (GST_BUFFER_CAPS (buf), 0);
378 if (s && gst_structure_get_int (s, "version", &version) && version > 0) {
379 ByteVector bytes ((char *) GST_BUFFER_DATA (buf),
380 GST_BUFFER_SIZE (buf));
382 GST_DEBUG ("Injecting ID3v2.%u frame %u/%u of length %u and type %"
383 GST_PTR_FORMAT, version, i, num_tags, GST_BUFFER_SIZE (buf), s);
385 frame = factory->createFrame (bytes, (TagLib::uint) version);
387 id3v2tag->addFrame (frame);
394 add_image_tag (ID3v2::Tag * id3v2tag, const GstTagList * list,
395 const gchar * tag, guint num_tags, const gchar * unused)
399 for (n = 0; n < num_tags; ++n) {
403 GST_DEBUG ("image %u/%u", n + 1, num_tags);
405 val = gst_tag_list_get_value_index (list, tag, n);
406 image = (GstBuffer *) gst_value_get_mini_object (val);
408 if (GST_IS_BUFFER (image) && GST_BUFFER_SIZE (image) > 0 &&
409 GST_BUFFER_CAPS (image) != NULL &&
410 !gst_caps_is_empty (GST_BUFFER_CAPS (image))) {
411 const gchar *mime_type;
414 s = gst_caps_get_structure (GST_BUFFER_CAPS (image), 0);
415 mime_type = gst_structure_get_name (s);
416 if (mime_type != NULL) {
417 ID3v2::AttachedPictureFrame * frame;
420 if (strcmp (mime_type, "text/uri-list") == 0)
423 frame = new ID3v2::AttachedPictureFrame ();
425 GST_DEBUG ("Attaching picture of %u bytes and mime type %s",
426 GST_BUFFER_SIZE (image), mime_type);
428 id3v2tag->addFrame (frame);
429 frame->setPicture (ByteVector ((const char *) GST_BUFFER_DATA (image),
430 GST_BUFFER_SIZE (image)));
431 frame->setTextEncoding (String::UTF8);
432 frame->setMimeType (mime_type);
434 desc = gst_structure_get_string (s, "image-description");
435 frame->setDescription ((desc) ? desc : "");
437 /* FIXME set image type properly from caps */
438 if (strcmp (tag, GST_TAG_PREVIEW_IMAGE) == 0) {
439 frame->setType (ID3v2::AttachedPictureFrame::FileIcon);
441 frame->setType (ID3v2::AttachedPictureFrame::Other);
445 GST_WARNING ("NULL image or no caps on image buffer (%p, caps=%"
446 GST_PTR_FORMAT ")", image, (image) ? GST_BUFFER_CAPS (image) : NULL);
452 add_comment_tag (ID3v2::Tag * id3v2tag, const GstTagList * list,
453 const gchar * tag, guint num_tags, const gchar * unused)
455 TagLib::StringList string_list;
458 GST_LOG ("Adding comment frames");
459 for (n = 0; n < num_tags; ++n) {
462 if (gst_tag_list_get_string_index (list, tag, n, &s) && s != NULL) {
463 ID3v2::CommentsFrame * f;
464 gchar *desc = NULL, *val = NULL, *lang = NULL;
466 f = new ID3v2::CommentsFrame (String::UTF8);
468 if (strcmp (tag, GST_TAG_COMMENT) == 0 ||
469 !gst_tag_parse_extended_comment (s, &desc, &lang, &val, TRUE)) {
470 /* create dummy description to allow for multiple comment frames
471 * (taglib will drop comment frames if descriptions are not unique) */
472 desc = g_strdup_printf ("c%u", n);
476 GST_LOG ("%s[%u] = '%s' (%s|%s|%s)", tag, n, s, GST_STR_NULL (desc),
477 GST_STR_NULL (lang), GST_STR_NULL (val));
479 f->setDescription (desc);
482 f->setLanguage (lang);
489 id3v2tag->addFrame (f);
496 add_text_tag (ID3v2::Tag * id3v2tag, const GstTagList * list,
497 const gchar * tag, guint num_tags, const gchar * frame_id)
499 ID3v2::TextIdentificationFrame * f;
500 TagLib::StringList string_list;
503 GST_LOG ("Adding '%s' frame", frame_id);
504 for (n = 0; n < num_tags; ++n) {
507 if (gst_tag_list_get_string_index (list, tag, n, &s) && s != NULL) {
508 GST_LOG ("%s: %s[%u] = '%s'", frame_id, tag, n, s);
509 string_list.append (String (s, String::UTF8));
514 if (!string_list.isEmpty ()) {
515 f = new ID3v2::TextIdentificationFrame (frame_id, String::UTF8);
516 id3v2tag->addFrame (f);
517 f->setText (string_list);
519 GST_WARNING ("Empty list for tag %s, skipping", tag);
524 add_uri_tag (ID3v2::Tag * id3v2tag, const GstTagList * list,
525 const gchar * tag, guint num_tags, const gchar * frame_id)
529 g_assert (frame_id != NULL);
531 /* URI tags are limited to one of each per taglist */
532 if (gst_tag_list_get_string_index (list, tag, 0, &url) && url != NULL) {
535 url_len = strlen (url);
536 if (url_len > 0 && gst_uri_is_valid (url)) {
537 ID3v2::FrameFactory * factory = ID3v2::FrameFactory::instance ();
538 ID3v2::Frame * frame;
541 data = g_new0 (char, 10 + url_len);
543 memcpy (data, frame_id, 4);
544 memcpy (data + 4, ID3v2::SynchData::fromUInt (url_len).data (), 4);
545 memcpy (data + 10, url, url_len);
546 ByteVector bytes (data, 10 + url_len);
550 frame = factory->createFrame (bytes, (TagLib::uint) 4);
552 id3v2tag->addFrame (frame);
554 GST_LOG ("%s: %s = '%s'", frame_id, tag, url);
557 GST_WARNING ("Tag %s does not contain a valid URI (%s)", tag, url);
565 add_relative_volume_tag (ID3v2::Tag * id3v2tag, const GstTagList * list,
566 const gchar * tag, guint num_tags, const gchar * frame_id)
568 const char *gain_tag_name;
569 const char *peak_tag_name;
572 ID3v2::RelativeVolumeFrame * frame;
574 frame = new ID3v2::RelativeVolumeFrame ();
576 /* figure out tag names and the identification string to use */
577 if (strcmp (tag, GST_TAG_TRACK_PEAK) == 0 ||
578 strcmp (tag, GST_TAG_TRACK_GAIN) == 0) {
579 gain_tag_name = GST_TAG_TRACK_GAIN;
580 peak_tag_name = GST_TAG_TRACK_PEAK;
581 frame->setIdentification ("track");
582 GST_DEBUG ("adding track relative-volume frame");
584 gain_tag_name = GST_TAG_ALBUM_GAIN;
585 peak_tag_name = GST_TAG_ALBUM_PEAK;
586 frame->setIdentification ("album");
587 GST_DEBUG ("adding album relative-volume frame");
590 /* find the value for the paired tag (gain, if this is peak, and
591 * vice versa). if both tags exist, only write the frame when
592 * we're processing the peak tag.
594 if (strcmp (tag, GST_TAG_TRACK_PEAK) == 0 ||
595 strcmp (tag, GST_TAG_ALBUM_PEAK) == 0) {
596 ID3v2::RelativeVolumeFrame::PeakVolume encoded_peak;
599 gst_tag_list_get_double (list, tag, &peak_val);
601 if (gst_tag_list_get_tag_size (list, gain_tag_name) > 0) {
602 gst_tag_list_get_double (list, gain_tag_name, &gain_val);
603 GST_DEBUG ("setting volume adjustment %g", gain_val);
604 frame->setVolumeAdjustment (gain_val);
607 /* copying mutagen: always write as 16 bits for sanity. */
608 peak_int = (short)(peak_val * G_MAXSHORT);
609 encoded_peak.bitsRepresentingPeak = 16;
610 encoded_peak.peakVolume = ByteVector::fromShort(peak_int, true);
611 GST_DEBUG ("setting peak value %g", peak_val);
612 frame->setPeakVolume(encoded_peak);
615 gst_tag_list_get_double (list, tag, &gain_val);
616 GST_DEBUG ("setting volume adjustment %g", gain_val);
617 frame->setVolumeAdjustment (gain_val);
619 if (gst_tag_list_get_tag_size (list, peak_tag_name) != 0) {
620 GST_DEBUG ("both gain and peak tags exist, not adding frame this time around");
626 id3v2tag->addFrame (frame);
630 add_bpm_tag (ID3v2::Tag * id3v2tag, const GstTagList * list,
631 const gchar * tag, guint num_tags, const gchar * frame_id)
635 if (gst_tag_list_get_double_index (list, tag, 0, &bpm)) {
636 ID3v2::TextIdentificationFrame * frame;
639 tag_str = g_strdup_printf ("%u", (guint)bpm);
641 GST_DEBUG ("Setting %s to %s", tag, tag_str);
642 frame = new ID3v2::TextIdentificationFrame ("TBPM", String::UTF8);
643 id3v2tag->addFrame (frame);
644 frame->setText (tag_str);
649 /* id3demux produces these for frames it cannot parse */
650 #define GST_ID3_DEMUX_TAG_ID3V2_FRAME "private-id3v2-frame"
654 const gchar *gst_tag;
655 const GstId3v2MuxAddTagFunc func;
659 GST_TAG_ARTIST, add_text_tag, "TPE1"}, {
660 GST_TAG_ALBUM_ARTIST, add_text_tag, "TPE2"}, {
661 GST_TAG_TITLE, add_text_tag, "TIT2"}, {
662 GST_TAG_ALBUM, add_text_tag, "TALB"}, {
663 GST_TAG_COPYRIGHT, add_text_tag, "TCOP"}, {
664 GST_TAG_COMPOSER, add_text_tag, "TCOM"}, {
665 GST_TAG_GENRE, add_text_tag, "TCON"}, {
666 GST_TAG_COMMENT, add_comment_tag, ""}, {
667 GST_TAG_EXTENDED_COMMENT, add_comment_tag, ""}, {
668 GST_TAG_DATE, add_date_tag, ""}, {
669 GST_TAG_IMAGE, add_image_tag, ""}, {
670 GST_TAG_PREVIEW_IMAGE, add_image_tag, ""}, {
671 GST_ID3_DEMUX_TAG_ID3V2_FRAME, add_id3v2frame_tag, ""}, {
672 GST_TAG_MUSICBRAINZ_ARTISTID, add_musicbrainz_tag, "\000"}, {
673 GST_TAG_MUSICBRAINZ_ALBUMID, add_musicbrainz_tag, "\001"}, {
674 GST_TAG_MUSICBRAINZ_ALBUMARTISTID, add_musicbrainz_tag, "\002"}, {
675 GST_TAG_MUSICBRAINZ_TRMID, add_musicbrainz_tag, "\003"}, {
676 GST_TAG_CDDA_MUSICBRAINZ_DISCID, add_musicbrainz_tag, "\004"}, {
677 GST_TAG_CDDA_CDDB_DISCID, add_musicbrainz_tag, "\005"}, {
678 GST_TAG_MUSICBRAINZ_TRACKID, add_unique_file_id_tag, ""}, {
679 GST_TAG_ARTIST_SORTNAME, add_text_tag, "TSOP"}, {
680 GST_TAG_ALBUM_SORTNAME, add_text_tag, "TSOA"}, {
681 GST_TAG_TITLE_SORTNAME, add_text_tag, "TSOT"}, {
682 GST_TAG_TRACK_NUMBER, add_count_or_num_tag, "TRCK"}, {
683 GST_TAG_TRACK_COUNT, add_count_or_num_tag, "TRCK"}, {
684 GST_TAG_ALBUM_VOLUME_NUMBER, add_count_or_num_tag, "TPOS"}, {
685 GST_TAG_ALBUM_VOLUME_COUNT, add_count_or_num_tag, "TPOS"}, {
686 GST_TAG_ENCODER, add_encoder_tag, ""}, {
687 GST_TAG_ENCODER_VERSION, add_encoder_tag, ""}, {
688 GST_TAG_COPYRIGHT_URI, add_uri_tag, "WCOP"}, {
689 GST_TAG_LICENSE_URI, add_uri_tag, "WCOP"}, {
690 GST_TAG_TRACK_PEAK, add_relative_volume_tag, ""}, {
691 GST_TAG_TRACK_GAIN, add_relative_volume_tag, ""}, {
692 GST_TAG_ALBUM_PEAK, add_relative_volume_tag, ""}, {
693 GST_TAG_ALBUM_GAIN, add_relative_volume_tag, ""}, {
694 GST_TAG_BEATS_PER_MINUTE, add_bpm_tag, ""}
699 foreach_add_tag (const GstTagList * list, const gchar * tag, gpointer userdata)
701 ID3v2::Tag * id3v2tag = (ID3v2::Tag *) userdata;
702 TagLib::StringList string_list;
705 num_tags = gst_tag_list_get_tag_size (list, tag);
707 GST_LOG ("Processing tag %s (num=%u)", tag, num_tags);
709 if (num_tags > 1 && gst_tag_is_fixed (tag)) {
710 GST_WARNING ("Multiple occurences of fixed tag '%s', ignoring some", tag);
714 for (i = 0; i < G_N_ELEMENTS (add_funcs); ++i) {
715 if (strcmp (add_funcs[i].gst_tag, tag) == 0) {
716 add_funcs[i].func (id3v2tag, list, tag, num_tags, add_funcs[i].data);
721 if (i == G_N_ELEMENTS (add_funcs)) {
722 GST_WARNING ("Unsupported tag '%s' - not written", tag);
727 gst_id3v2_mux_render_tag (GstTagLibMux * mux, GstTagList * taglist)
730 ByteVector rendered_tag;
734 /* write all strings as UTF-8 by default */
735 TagLib::ID3v2::FrameFactory::instance ()->
736 setDefaultTextEncoding (TagLib::String::UTF8);
739 gst_tag_list_foreach (taglist, foreach_add_tag, &id3v2tag);
742 /* Do we want to add our own signature to the tag somewhere? */
744 gchar *tag_producer_str;
746 tag_producer_str = g_strdup_printf ("(GStreamer id3v2mux %s, using "
747 "taglib %u.%u)", VERSION, TAGLIB_MAJOR_VERSION, TAGLIB_MINOR_VERSION);
748 add_one_txxx_tag (id3v2tag, "tag_encoder", tag_producer_str);
749 g_free (tag_producer_str);
753 rendered_tag = id3v2tag.render ();
754 tag_size = rendered_tag.size ();
756 GST_LOG_OBJECT (mux, "tag size = %d bytes", tag_size);
758 /* Create buffer with tag */
759 buf = gst_buffer_new_and_alloc (tag_size);
760 memcpy (GST_BUFFER_DATA (buf), rendered_tag.data (), tag_size);
761 gst_buffer_set_caps (buf, GST_PAD_CAPS (mux->srcpad));
767 gst_id3v2_mux_plugin_init (GstPlugin * plugin)
769 if (!gst_element_register (plugin, "id3v2mux", GST_RANK_NONE,
773 gst_tag_register_musicbrainz_tags ();