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_static_pad_template (element_class, &src_template);
89 gst_element_class_set_details_simple (element_class,
90 "TagLib-based ID3v2 Muxer", "Formatter/Metadata",
91 "Adds an ID3v2 header to the beginning of MP3 files using taglib",
92 "Christophe Fergeau <teuf@gnome.org>");
94 GST_DEBUG_CATEGORY_INIT (gst_id3v2_mux_debug, "id3v2mux", 0,
95 "taglib-based ID3v2 tag muxer");
99 gst_id3v2_mux_class_init (GstId3v2MuxClass * klass)
101 GST_TAG_LIB_MUX_CLASS (klass)->render_tag =
102 GST_DEBUG_FUNCPTR (gst_id3v2_mux_render_tag);
106 gst_id3v2_mux_init (GstId3v2Mux * id3v2mux, GstId3v2MuxClass * id3v2mux_class)
113 add_one_txxx_tag (ID3v2::Tag * id3v2tag, const gchar * key, const gchar * val)
115 ID3v2::UserTextIdentificationFrame * frame;
120 GST_DEBUG ("Setting %s to %s", key, val);
121 frame = new ID3v2::UserTextIdentificationFrame (String::UTF8);
122 id3v2tag->addFrame (frame);
123 frame->setDescription (key);
124 frame->setText (val);
128 typedef void (*GstId3v2MuxAddTagFunc) (ID3v2::Tag * id3v2tag,
129 const GstTagList * list,
130 const gchar * tag, guint num_tags, const gchar * data);
133 add_encoder_tag (ID3v2::Tag * id3v2tag, const GstTagList * list,
134 const gchar * tag, guint num_tags, const gchar * unused)
136 TagLib::StringList string_list;
139 /* ENCODER_VERSION is either handled with the ENCODER tag or not at all */
140 if (strcmp (tag, GST_TAG_ENCODER_VERSION) == 0)
143 for (n = 0; n < num_tags; ++n) {
144 gchar *encoder = NULL;
146 if (gst_tag_list_get_string_index (list, tag, n, &encoder) && encoder) {
147 guint encoder_version;
150 if (gst_tag_list_get_uint_index (list, GST_TAG_ENCODER_VERSION, n,
151 &encoder_version) && encoder_version > 0) {
152 s = g_strdup_printf ("%s %u", encoder, encoder_version);
154 s = g_strdup (encoder);
157 GST_LOG ("encoder[%u] = '%s'", n, s);
158 string_list.append (String (s, String::UTF8));
164 if (!string_list.isEmpty ()) {
165 ID3v2::TextIdentificationFrame * f;
167 f = new ID3v2::TextIdentificationFrame ("TSSE", String::UTF8);
168 id3v2tag->addFrame (f);
169 f->setText (string_list);
171 GST_WARNING ("Empty list for tag %s, skipping", tag);
176 add_date_tag (ID3v2::Tag * id3v2tag, const GstTagList * list,
177 const gchar * tag, guint num_tags, const gchar * unused)
179 TagLib::StringList string_list;
182 GST_LOG ("Adding date frame");
184 for (n = 0; n < num_tags; ++n) {
187 if (gst_tag_list_get_date_index (list, tag, n, &date) && date != NULL) {
191 year = g_date_get_year (date);
192 if (year > 500 && year < 2100) {
193 s = g_strdup_printf ("%u", year);
194 GST_LOG ("%s[%u] = '%s'", tag, n, s);
195 string_list.append (String (s, String::UTF8));
198 GST_WARNING ("invalid year %u, skipping", year);
205 if (!string_list.isEmpty ()) {
206 ID3v2::TextIdentificationFrame * f;
208 f = new ID3v2::TextIdentificationFrame ("TDRC", String::UTF8);
209 id3v2tag->addFrame (f);
210 f->setText (string_list);
212 GST_WARNING ("Empty list for tag %s, skipping", tag);
217 add_count_or_num_tag (ID3v2::Tag * id3v2tag, const GstTagList * list,
218 const gchar * tag, guint num_tags, const gchar * frame_id)
222 const gchar *gst_tag;
223 const gchar *corr_count; /* corresponding COUNT tag (if number) */
224 const gchar *corr_num; /* corresponding NUMBER tag (if count) */
227 GST_TAG_TRACK_NUMBER, GST_TAG_TRACK_COUNT, NULL}, {
228 GST_TAG_TRACK_COUNT, NULL, GST_TAG_TRACK_NUMBER}, {
229 GST_TAG_ALBUM_VOLUME_NUMBER, GST_TAG_ALBUM_VOLUME_COUNT, NULL}, {
230 GST_TAG_ALBUM_VOLUME_COUNT, NULL, GST_TAG_ALBUM_VOLUME_NUMBER}
234 for (idx = 0; idx < G_N_ELEMENTS (corr); ++idx) {
235 if (strcmp (corr[idx].gst_tag, tag) == 0)
239 g_assert (idx < G_N_ELEMENTS (corr));
240 g_assert (frame_id && strlen (frame_id) == 4);
242 if (corr[idx].corr_num == NULL) {
246 if (gst_tag_list_get_uint_index (list, tag, 0, &number)) {
247 ID3v2::TextIdentificationFrame * frame;
251 if (gst_tag_list_get_uint_index (list, corr[idx].corr_count, 0, &count))
252 tag_str = g_strdup_printf ("%u/%u", number, count);
254 tag_str = g_strdup_printf ("%u", number);
256 GST_DEBUG ("Setting %s to %s (frame_id = %s)", tag, tag_str, frame_id);
257 frame = new ID3v2::TextIdentificationFrame (frame_id, String::UTF8);
258 id3v2tag->addFrame (frame);
259 frame->setText (tag_str);
262 } else if (corr[idx].corr_count == NULL) {
266 if (gst_tag_list_get_uint_index (list, corr[idx].corr_num, 0, &count)) {
267 GST_DEBUG ("%s handled with %s, skipping", tag, corr[idx].corr_num);
268 } else if (gst_tag_list_get_uint_index (list, tag, 0, &count)) {
269 ID3v2::TextIdentificationFrame * frame;
272 tag_str = g_strdup_printf ("0/%u", count);
273 GST_DEBUG ("Setting %s to %s (frame_id = %s)", tag, tag_str, frame_id);
274 frame = new ID3v2::TextIdentificationFrame (frame_id, String::UTF8);
275 id3v2tag->addFrame (frame);
276 frame->setText (tag_str);
282 GST_WARNING ("more than one %s, can only handle one", tag);
287 add_unique_file_id_tag (ID3v2::Tag * id3v2tag, const GstTagList * list,
288 const gchar * tag, guint num_tags, const gchar * unused)
290 const gchar *origin = "http://musicbrainz.org";
291 gchar *id_str = NULL;
293 if (gst_tag_list_get_string_index (list, tag, 0, &id_str) && id_str) {
294 ID3v2::UniqueFileIdentifierFrame * frame;
296 GST_LOG ("Adding %s (%s): %s", tag, origin, id_str);
297 frame = new ID3v2::UniqueFileIdentifierFrame (origin, id_str);
298 id3v2tag->addFrame (frame);
304 add_musicbrainz_tag (ID3v2::Tag * id3v2tag, const GstTagList * list,
305 const gchar * tag, guint num_tags, const gchar * data)
309 const gchar gst_tag[28];
310 const gchar spec_id[28];
311 const gchar realworld_id[28];
314 GST_TAG_MUSICBRAINZ_ARTISTID, "MusicBrainz Artist Id",
315 "musicbrainz_artistid"}, {
316 GST_TAG_MUSICBRAINZ_ALBUMID, "MusicBrainz Album Id", "musicbrainz_albumid"}, {
317 GST_TAG_MUSICBRAINZ_ALBUMARTISTID, "MusicBrainz Album Artist Id",
318 "musicbrainz_albumartistid"}, {
319 GST_TAG_MUSICBRAINZ_TRMID, "MusicBrainz TRM Id", "musicbrainz_trmid"}, {
320 GST_TAG_CDDA_MUSICBRAINZ_DISCID, "MusicBrainz DiscID",
321 "musicbrainz_discid"}, {
322 /* the following one is more or less made up, there seems to be little
323 * evidence that any popular application is actually putting this info
324 * into TXXX frames; the first one comes from a musicbrainz wiki 'proposed
325 * tags' page, the second one is analogue to the vorbis/ape/flac tag. */
326 GST_TAG_CDDA_CDDB_DISCID, "CDDB DiscID", "discid"}
330 idx = (guint8) data[0];
331 g_assert (idx < G_N_ELEMENTS (mb_ids));
333 for (i = 0; i < num_tags; ++i) {
334 ID3v2::UserTextIdentificationFrame * frame;
337 if (gst_tag_list_get_string_index (list, tag, 0, &id_str) && id_str) {
338 GST_DEBUG ("Setting '%s' to '%s'", mb_ids[idx].spec_id, id_str);
340 /* add two frames, one with the ID the musicbrainz.org spec mentions
341 * and one with the ID that applications use in the real world */
342 frame = new ID3v2::UserTextIdentificationFrame (String::Latin1);
343 id3v2tag->addFrame (frame);
344 frame->setDescription (mb_ids[idx].spec_id);
345 frame->setText (id_str);
347 frame = new ID3v2::UserTextIdentificationFrame (String::Latin1);
348 id3v2tag->addFrame (frame);
349 frame->setDescription (mb_ids[idx].realworld_id);
350 frame->setText (id_str);
358 add_id3v2frame_tag (ID3v2::Tag * id3v2tag, const GstTagList * list,
359 const gchar * tag, guint num_tags, const gchar * frame_id)
361 ID3v2::FrameFactory * factory = ID3v2::FrameFactory::instance ();
364 for (i = 0; i < num_tags; ++i) {
365 ID3v2::Frame * frame;
369 val = gst_tag_list_get_value_index (list, tag, i);
370 buf = (GstBuffer *) gst_value_get_mini_object (val);
372 if (buf && GST_BUFFER_CAPS (buf)) {
376 s = gst_caps_get_structure (GST_BUFFER_CAPS (buf), 0);
377 if (s && gst_structure_get_int (s, "version", &version) && version > 0) {
378 ByteVector bytes ((char *) GST_BUFFER_DATA (buf),
379 GST_BUFFER_SIZE (buf));
381 GST_DEBUG ("Injecting ID3v2.%u frame %u/%u of length %u and type %"
382 GST_PTR_FORMAT, version, i, num_tags, GST_BUFFER_SIZE (buf), s);
384 frame = factory->createFrame (bytes, (TagLib::uint) version);
386 id3v2tag->addFrame (frame);
393 add_image_tag (ID3v2::Tag * id3v2tag, const GstTagList * list,
394 const gchar * tag, guint num_tags, const gchar * unused)
398 for (n = 0; n < num_tags; ++n) {
402 GST_DEBUG ("image %u/%u", n + 1, num_tags);
404 val = gst_tag_list_get_value_index (list, tag, n);
405 image = (GstBuffer *) gst_value_get_mini_object (val);
407 if (GST_IS_BUFFER (image) && GST_BUFFER_SIZE (image) > 0 &&
408 GST_BUFFER_CAPS (image) != NULL &&
409 !gst_caps_is_empty (GST_BUFFER_CAPS (image))) {
410 const gchar *mime_type;
413 s = gst_caps_get_structure (GST_BUFFER_CAPS (image), 0);
414 mime_type = gst_structure_get_name (s);
415 if (mime_type != NULL) {
416 ID3v2::AttachedPictureFrame * frame;
419 if (strcmp (mime_type, "text/uri-list") == 0)
422 frame = new ID3v2::AttachedPictureFrame ();
424 GST_DEBUG ("Attaching picture of %u bytes and mime type %s",
425 GST_BUFFER_SIZE (image), mime_type);
427 id3v2tag->addFrame (frame);
428 frame->setPicture (ByteVector ((const char *) GST_BUFFER_DATA (image),
429 GST_BUFFER_SIZE (image)));
430 frame->setTextEncoding (String::UTF8);
431 frame->setMimeType (mime_type);
433 desc = gst_structure_get_string (s, "image-description");
434 frame->setDescription ((desc) ? desc : "");
436 /* FIXME set image type properly from caps */
437 if (strcmp (tag, GST_TAG_PREVIEW_IMAGE) == 0) {
438 frame->setType (ID3v2::AttachedPictureFrame::FileIcon);
440 frame->setType (ID3v2::AttachedPictureFrame::Other);
444 GST_WARNING ("NULL image or no caps on image buffer (%p, caps=%"
445 GST_PTR_FORMAT ")", image, (image) ? GST_BUFFER_CAPS (image) : NULL);
451 add_comment_tag (ID3v2::Tag * id3v2tag, const GstTagList * list,
452 const gchar * tag, guint num_tags, const gchar * unused)
454 TagLib::StringList string_list;
457 GST_LOG ("Adding comment frames");
458 for (n = 0; n < num_tags; ++n) {
461 if (gst_tag_list_get_string_index (list, tag, n, &s) && s != NULL) {
462 ID3v2::CommentsFrame * f;
463 gchar *desc = NULL, *val = NULL, *lang = NULL;
465 f = new ID3v2::CommentsFrame (String::UTF8);
467 if (strcmp (tag, GST_TAG_COMMENT) == 0 ||
468 !gst_tag_parse_extended_comment (s, &desc, &lang, &val, TRUE)) {
469 /* create dummy description to allow for multiple comment frames
470 * (taglib will drop comment frames if descriptions are not unique) */
471 desc = g_strdup_printf ("c%u", n);
475 GST_LOG ("%s[%u] = '%s' (%s|%s|%s)", tag, n, s, GST_STR_NULL (desc),
476 GST_STR_NULL (lang), GST_STR_NULL (val));
478 f->setDescription (desc);
481 f->setLanguage (lang);
488 id3v2tag->addFrame (f);
495 add_text_tag (ID3v2::Tag * id3v2tag, const GstTagList * list,
496 const gchar * tag, guint num_tags, const gchar * frame_id)
498 ID3v2::TextIdentificationFrame * f;
499 TagLib::StringList string_list;
502 GST_LOG ("Adding '%s' frame", frame_id);
503 for (n = 0; n < num_tags; ++n) {
506 if (gst_tag_list_get_string_index (list, tag, n, &s) && s != NULL) {
507 GST_LOG ("%s: %s[%u] = '%s'", frame_id, tag, n, s);
508 string_list.append (String (s, String::UTF8));
513 if (!string_list.isEmpty ()) {
514 f = new ID3v2::TextIdentificationFrame (frame_id, String::UTF8);
515 id3v2tag->addFrame (f);
516 f->setText (string_list);
518 GST_WARNING ("Empty list for tag %s, skipping", tag);
523 add_uri_tag (ID3v2::Tag * id3v2tag, const GstTagList * list,
524 const gchar * tag, guint num_tags, const gchar * frame_id)
528 g_assert (frame_id != NULL);
530 /* URI tags are limited to one of each per taglist */
531 if (gst_tag_list_get_string_index (list, tag, 0, &url) && url != NULL) {
534 url_len = strlen (url);
535 if (url_len > 0 && gst_uri_is_valid (url)) {
536 ID3v2::FrameFactory * factory = ID3v2::FrameFactory::instance ();
537 ID3v2::Frame * frame;
540 data = g_new0 (char, 10 + url_len);
542 memcpy (data, frame_id, 4);
543 memcpy (data + 4, ID3v2::SynchData::fromUInt (url_len).data (), 4);
544 memcpy (data + 10, url, url_len);
545 ByteVector bytes (data, 10 + url_len);
549 frame = factory->createFrame (bytes, (TagLib::uint) 4);
551 id3v2tag->addFrame (frame);
553 GST_LOG ("%s: %s = '%s'", frame_id, tag, url);
556 GST_WARNING ("Tag %s does not contain a valid URI (%s)", tag, url);
564 add_relative_volume_tag (ID3v2::Tag * id3v2tag, const GstTagList * list,
565 const gchar * tag, guint num_tags, const gchar * frame_id)
567 const char *gain_tag_name;
568 const char *peak_tag_name;
571 ID3v2::RelativeVolumeFrame * frame;
573 frame = new ID3v2::RelativeVolumeFrame ();
575 /* figure out tag names and the identification string to use */
576 if (strcmp (tag, GST_TAG_TRACK_PEAK) == 0 ||
577 strcmp (tag, GST_TAG_TRACK_GAIN) == 0) {
578 gain_tag_name = GST_TAG_TRACK_GAIN;
579 peak_tag_name = GST_TAG_TRACK_PEAK;
580 frame->setIdentification ("track");
581 GST_DEBUG ("adding track relative-volume frame");
583 gain_tag_name = GST_TAG_ALBUM_GAIN;
584 peak_tag_name = GST_TAG_ALBUM_PEAK;
585 frame->setIdentification ("album");
586 GST_DEBUG ("adding album relative-volume frame");
589 /* find the value for the paired tag (gain, if this is peak, and
590 * vice versa). if both tags exist, only write the frame when
591 * we're processing the peak tag.
593 if (strcmp (tag, GST_TAG_TRACK_PEAK) == 0 ||
594 strcmp (tag, GST_TAG_ALBUM_PEAK) == 0) {
595 ID3v2::RelativeVolumeFrame::PeakVolume encoded_peak;
598 gst_tag_list_get_double (list, tag, &peak_val);
600 if (gst_tag_list_get_tag_size (list, gain_tag_name) > 0) {
601 gst_tag_list_get_double (list, gain_tag_name, &gain_val);
602 GST_DEBUG ("setting volume adjustment %g", gain_val);
603 frame->setVolumeAdjustment (gain_val);
606 /* copying mutagen: always write as 16 bits for sanity. */
607 peak_int = (short)(peak_val * G_MAXSHORT);
608 encoded_peak.bitsRepresentingPeak = 16;
609 encoded_peak.peakVolume = ByteVector::fromShort(peak_int, true);
610 GST_DEBUG ("setting peak value %g", peak_val);
611 frame->setPeakVolume(encoded_peak);
614 gst_tag_list_get_double (list, tag, &gain_val);
615 GST_DEBUG ("setting volume adjustment %g", gain_val);
616 frame->setVolumeAdjustment (gain_val);
618 if (gst_tag_list_get_tag_size (list, peak_tag_name) != 0) {
619 GST_DEBUG ("both gain and peak tags exist, not adding frame this time around");
625 id3v2tag->addFrame (frame);
629 add_bpm_tag (ID3v2::Tag * id3v2tag, const GstTagList * list,
630 const gchar * tag, guint num_tags, const gchar * frame_id)
634 if (gst_tag_list_get_double_index (list, tag, 0, &bpm)) {
635 ID3v2::TextIdentificationFrame * frame;
638 tag_str = g_strdup_printf ("%u", (guint)bpm);
640 GST_DEBUG ("Setting %s to %s", tag, tag_str);
641 frame = new ID3v2::TextIdentificationFrame ("TBPM", String::UTF8);
642 id3v2tag->addFrame (frame);
643 frame->setText (tag_str);
648 /* id3demux produces these for frames it cannot parse */
649 #define GST_ID3_DEMUX_TAG_ID3V2_FRAME "private-id3v2-frame"
653 const gchar *gst_tag;
654 const GstId3v2MuxAddTagFunc func;
658 GST_TAG_ARTIST, add_text_tag, "TPE1"}, {
659 GST_TAG_ALBUM_ARTIST, add_text_tag, "TPE2"}, {
660 GST_TAG_TITLE, add_text_tag, "TIT2"}, {
661 GST_TAG_ALBUM, add_text_tag, "TALB"}, {
662 GST_TAG_COPYRIGHT, add_text_tag, "TCOP"}, {
663 GST_TAG_COMPOSER, add_text_tag, "TCOM"}, {
664 GST_TAG_GENRE, add_text_tag, "TCON"}, {
665 GST_TAG_COMMENT, add_comment_tag, ""}, {
666 GST_TAG_EXTENDED_COMMENT, add_comment_tag, ""}, {
667 GST_TAG_DATE, add_date_tag, ""}, {
668 GST_TAG_IMAGE, add_image_tag, ""}, {
669 GST_TAG_PREVIEW_IMAGE, add_image_tag, ""}, {
670 GST_ID3_DEMUX_TAG_ID3V2_FRAME, add_id3v2frame_tag, ""}, {
671 GST_TAG_MUSICBRAINZ_ARTISTID, add_musicbrainz_tag, "\000"}, {
672 GST_TAG_MUSICBRAINZ_ALBUMID, add_musicbrainz_tag, "\001"}, {
673 GST_TAG_MUSICBRAINZ_ALBUMARTISTID, add_musicbrainz_tag, "\002"}, {
674 GST_TAG_MUSICBRAINZ_TRMID, add_musicbrainz_tag, "\003"}, {
675 GST_TAG_CDDA_MUSICBRAINZ_DISCID, add_musicbrainz_tag, "\004"}, {
676 GST_TAG_CDDA_CDDB_DISCID, add_musicbrainz_tag, "\005"}, {
677 GST_TAG_MUSICBRAINZ_TRACKID, add_unique_file_id_tag, ""}, {
678 GST_TAG_ARTIST_SORTNAME, add_text_tag, "TSOP"}, {
679 GST_TAG_ALBUM_SORTNAME, add_text_tag, "TSOA"}, {
680 GST_TAG_TITLE_SORTNAME, add_text_tag, "TSOT"}, {
681 GST_TAG_TRACK_NUMBER, add_count_or_num_tag, "TRCK"}, {
682 GST_TAG_TRACK_COUNT, add_count_or_num_tag, "TRCK"}, {
683 GST_TAG_ALBUM_VOLUME_NUMBER, add_count_or_num_tag, "TPOS"}, {
684 GST_TAG_ALBUM_VOLUME_COUNT, add_count_or_num_tag, "TPOS"}, {
685 GST_TAG_ENCODER, add_encoder_tag, ""}, {
686 GST_TAG_ENCODER_VERSION, add_encoder_tag, ""}, {
687 GST_TAG_COPYRIGHT_URI, add_uri_tag, "WCOP"}, {
688 GST_TAG_LICENSE_URI, add_uri_tag, "WCOP"}, {
689 GST_TAG_TRACK_PEAK, add_relative_volume_tag, ""}, {
690 GST_TAG_TRACK_GAIN, add_relative_volume_tag, ""}, {
691 GST_TAG_ALBUM_PEAK, add_relative_volume_tag, ""}, {
692 GST_TAG_ALBUM_GAIN, add_relative_volume_tag, ""}, {
693 GST_TAG_BEATS_PER_MINUTE, add_bpm_tag, ""}
698 foreach_add_tag (const GstTagList * list, const gchar * tag, gpointer userdata)
700 ID3v2::Tag * id3v2tag = (ID3v2::Tag *) userdata;
701 TagLib::StringList string_list;
704 num_tags = gst_tag_list_get_tag_size (list, tag);
706 GST_LOG ("Processing tag %s (num=%u)", tag, num_tags);
708 if (num_tags > 1 && gst_tag_is_fixed (tag)) {
709 GST_WARNING ("Multiple occurences of fixed tag '%s', ignoring some", tag);
713 for (i = 0; i < G_N_ELEMENTS (add_funcs); ++i) {
714 if (strcmp (add_funcs[i].gst_tag, tag) == 0) {
715 add_funcs[i].func (id3v2tag, list, tag, num_tags, add_funcs[i].data);
720 if (i == G_N_ELEMENTS (add_funcs)) {
721 GST_WARNING ("Unsupported tag '%s' - not written", tag);
726 gst_id3v2_mux_render_tag (GstTagLibMux * mux, GstTagList * taglist)
729 ByteVector rendered_tag;
733 /* write all strings as UTF-8 by default */
734 TagLib::ID3v2::FrameFactory::instance ()->
735 setDefaultTextEncoding (TagLib::String::UTF8);
738 gst_tag_list_foreach (taglist, foreach_add_tag, &id3v2tag);
741 /* Do we want to add our own signature to the tag somewhere? */
743 gchar *tag_producer_str;
745 tag_producer_str = g_strdup_printf ("(GStreamer id3v2mux %s, using "
746 "taglib %u.%u)", VERSION, TAGLIB_MAJOR_VERSION, TAGLIB_MINOR_VERSION);
747 add_one_txxx_tag (id3v2tag, "tag_encoder", tag_producer_str);
748 g_free (tag_producer_str);
752 rendered_tag = id3v2tag.render ();
753 tag_size = rendered_tag.size ();
755 GST_LOG_OBJECT (mux, "tag size = %d bytes", tag_size);
757 /* Create buffer with tag */
758 buf = gst_buffer_new_and_alloc (tag_size);
759 memcpy (GST_BUFFER_DATA (buf), rendered_tag.data (), tag_size);
760 gst_buffer_set_caps (buf, GST_PAD_CAPS (mux->srcpad));
766 gst_id3v2_mux_plugin_init (GstPlugin * plugin)
768 if (!gst_element_register (plugin, "id3v2mux", GST_RANK_NONE,
772 gst_tag_register_musicbrainz_tags ();