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"));
75 static GstStaticPadTemplate sink_template = GST_STATIC_PAD_TEMPLATE ("sink",
78 GST_STATIC_CAPS ("ANY"));
80 G_DEFINE_TYPE (GstId3v2Mux, gst_id3v2_mux, GST_TYPE_TAG_MUX);
82 static GstBuffer *gst_id3v2_mux_render_tag (GstTagMux * mux,
83 const GstTagList * taglist);
84 static GstBuffer *gst_id3v2_mux_render_end_tag (GstTagMux * mux,
85 const GstTagList * taglist);
88 gst_id3v2_mux_class_init (GstId3v2MuxClass * klass)
90 GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
92 GST_TAG_MUX_CLASS (klass)->render_start_tag =
93 GST_DEBUG_FUNCPTR (gst_id3v2_mux_render_tag);
94 GST_TAG_MUX_CLASS (klass)->render_end_tag =
95 GST_DEBUG_FUNCPTR (gst_id3v2_mux_render_end_tag);
97 gst_element_class_add_pad_template (element_class,
98 gst_static_pad_template_get (&sink_template));
99 gst_element_class_add_pad_template (element_class,
100 gst_static_pad_template_get (&src_template));
102 gst_element_class_set_details_simple (element_class,
103 "TagLib-based ID3v2 Muxer", "Formatter/Metadata",
104 "Adds an ID3v2 header to the beginning of MP3 files using taglib",
105 "Christophe Fergeau <teuf@gnome.org>");
107 GST_DEBUG_CATEGORY_INIT (gst_id3v2_mux_debug, "id3v2mux", 0,
108 "taglib-based ID3v2 tag muxer");
112 gst_id3v2_mux_init (GstId3v2Mux * id3v2mux)
119 add_one_txxx_tag (ID3v2::Tag * id3v2tag, const gchar * key, const gchar * val)
121 ID3v2::UserTextIdentificationFrame * frame;
126 GST_DEBUG ("Setting %s to %s", key, val);
127 frame = new ID3v2::UserTextIdentificationFrame (String::UTF8);
128 id3v2tag->addFrame (frame);
129 frame->setDescription (key);
130 frame->setText (val);
134 typedef void (*GstId3v2MuxAddTagFunc) (ID3v2::Tag * id3v2tag,
135 const GstTagList * list,
136 const gchar * tag, guint num_tags, const gchar * data);
139 add_encoder_tag (ID3v2::Tag * id3v2tag, const GstTagList * list,
140 const gchar * tag, guint num_tags, const gchar * unused)
142 TagLib::StringList string_list;
145 /* ENCODER_VERSION is either handled with the ENCODER tag or not at all */
146 if (strcmp (tag, GST_TAG_ENCODER_VERSION) == 0)
149 for (n = 0; n < num_tags; ++n) {
150 gchar *encoder = NULL;
152 if (gst_tag_list_get_string_index (list, tag, n, &encoder) && encoder) {
153 guint encoder_version;
156 if (gst_tag_list_get_uint_index (list, GST_TAG_ENCODER_VERSION, n,
157 &encoder_version) && encoder_version > 0) {
158 s = g_strdup_printf ("%s %u", encoder, encoder_version);
160 s = g_strdup (encoder);
163 GST_LOG ("encoder[%u] = '%s'", n, s);
164 string_list.append (String (s, String::UTF8));
170 if (!string_list.isEmpty ()) {
171 ID3v2::TextIdentificationFrame * f;
173 f = new ID3v2::TextIdentificationFrame ("TSSE", String::UTF8);
174 id3v2tag->addFrame (f);
175 f->setText (string_list);
177 GST_WARNING ("Empty list for tag %s, skipping", tag);
182 add_date_tag (ID3v2::Tag * id3v2tag, const GstTagList * list,
183 const gchar * tag, guint num_tags, const gchar * unused)
185 TagLib::StringList string_list;
188 GST_LOG ("Adding date frame");
190 for (n = 0; n < num_tags; ++n) {
193 if (gst_tag_list_get_date_index (list, tag, n, &date) && date != NULL) {
197 year = g_date_get_year (date);
198 if (year > 500 && year < 2100) {
199 s = g_strdup_printf ("%u", year);
200 GST_LOG ("%s[%u] = '%s'", tag, n, s);
201 string_list.append (String (s, String::UTF8));
204 GST_WARNING ("invalid year %u, skipping", year);
211 if (!string_list.isEmpty ()) {
212 ID3v2::TextIdentificationFrame * f;
214 f = new ID3v2::TextIdentificationFrame ("TDRC", String::UTF8);
215 id3v2tag->addFrame (f);
216 f->setText (string_list);
218 GST_WARNING ("Empty list for tag %s, skipping", tag);
223 add_count_or_num_tag (ID3v2::Tag * id3v2tag, const GstTagList * list,
224 const gchar * tag, guint num_tags, const gchar * frame_id)
228 const gchar *gst_tag;
229 const gchar *corr_count; /* corresponding COUNT tag (if number) */
230 const gchar *corr_num; /* corresponding NUMBER tag (if count) */
233 GST_TAG_TRACK_NUMBER, GST_TAG_TRACK_COUNT, NULL}, {
234 GST_TAG_TRACK_COUNT, NULL, GST_TAG_TRACK_NUMBER}, {
235 GST_TAG_ALBUM_VOLUME_NUMBER, GST_TAG_ALBUM_VOLUME_COUNT, NULL}, {
236 GST_TAG_ALBUM_VOLUME_COUNT, NULL, GST_TAG_ALBUM_VOLUME_NUMBER}
240 for (idx = 0; idx < G_N_ELEMENTS (corr); ++idx) {
241 if (strcmp (corr[idx].gst_tag, tag) == 0)
245 g_assert (idx < G_N_ELEMENTS (corr));
246 g_assert (frame_id && strlen (frame_id) == 4);
248 if (corr[idx].corr_num == NULL) {
252 if (gst_tag_list_get_uint_index (list, tag, 0, &number)) {
253 ID3v2::TextIdentificationFrame * frame;
257 if (gst_tag_list_get_uint_index (list, corr[idx].corr_count, 0, &count))
258 tag_str = g_strdup_printf ("%u/%u", number, count);
260 tag_str = g_strdup_printf ("%u", number);
262 GST_DEBUG ("Setting %s to %s (frame_id = %s)", tag, tag_str, frame_id);
263 frame = new ID3v2::TextIdentificationFrame (frame_id, String::UTF8);
264 id3v2tag->addFrame (frame);
265 frame->setText (tag_str);
268 } else if (corr[idx].corr_count == NULL) {
272 if (gst_tag_list_get_uint_index (list, corr[idx].corr_num, 0, &count)) {
273 GST_DEBUG ("%s handled with %s, skipping", tag, corr[idx].corr_num);
274 } else if (gst_tag_list_get_uint_index (list, tag, 0, &count)) {
275 ID3v2::TextIdentificationFrame * frame;
278 tag_str = g_strdup_printf ("0/%u", count);
279 GST_DEBUG ("Setting %s to %s (frame_id = %s)", tag, tag_str, frame_id);
280 frame = new ID3v2::TextIdentificationFrame (frame_id, String::UTF8);
281 id3v2tag->addFrame (frame);
282 frame->setText (tag_str);
288 GST_WARNING ("more than one %s, can only handle one", tag);
293 add_unique_file_id_tag (ID3v2::Tag * id3v2tag, const GstTagList * list,
294 const gchar * tag, guint num_tags, const gchar * unused)
296 const gchar *origin = "http://musicbrainz.org";
297 gchar *id_str = NULL;
299 if (gst_tag_list_get_string_index (list, tag, 0, &id_str) && id_str) {
300 ID3v2::UniqueFileIdentifierFrame * frame;
302 GST_LOG ("Adding %s (%s): %s", tag, origin, id_str);
303 frame = new ID3v2::UniqueFileIdentifierFrame (origin, id_str);
304 id3v2tag->addFrame (frame);
310 add_musicbrainz_tag (ID3v2::Tag * id3v2tag, const GstTagList * list,
311 const gchar * tag, guint num_tags, const gchar * data)
315 const gchar gst_tag[28];
316 const gchar spec_id[28];
317 const gchar realworld_id[28];
320 GST_TAG_MUSICBRAINZ_ARTISTID, "MusicBrainz Artist Id",
321 "musicbrainz_artistid"}, {
322 GST_TAG_MUSICBRAINZ_ALBUMID, "MusicBrainz Album Id", "musicbrainz_albumid"}, {
323 GST_TAG_MUSICBRAINZ_ALBUMARTISTID, "MusicBrainz Album Artist Id",
324 "musicbrainz_albumartistid"}, {
325 GST_TAG_MUSICBRAINZ_TRMID, "MusicBrainz TRM Id", "musicbrainz_trmid"}, {
326 GST_TAG_CDDA_MUSICBRAINZ_DISCID, "MusicBrainz DiscID",
327 "musicbrainz_discid"}, {
328 /* the following one is more or less made up, there seems to be little
329 * evidence that any popular application is actually putting this info
330 * into TXXX frames; the first one comes from a musicbrainz wiki 'proposed
331 * tags' page, the second one is analogue to the vorbis/ape/flac tag. */
332 GST_TAG_CDDA_CDDB_DISCID, "CDDB DiscID", "discid"}
336 idx = (guint8) data[0];
337 g_assert (idx < G_N_ELEMENTS (mb_ids));
339 for (i = 0; i < num_tags; ++i) {
340 ID3v2::UserTextIdentificationFrame * frame;
343 if (gst_tag_list_get_string_index (list, tag, 0, &id_str) && id_str) {
344 GST_DEBUG ("Setting '%s' to '%s'", mb_ids[idx].spec_id, id_str);
346 /* add two frames, one with the ID the musicbrainz.org spec mentions
347 * and one with the ID that applications use in the real world */
348 frame = new ID3v2::UserTextIdentificationFrame (String::Latin1);
349 id3v2tag->addFrame (frame);
350 frame->setDescription (mb_ids[idx].spec_id);
351 frame->setText (id_str);
353 frame = new ID3v2::UserTextIdentificationFrame (String::Latin1);
354 id3v2tag->addFrame (frame);
355 frame->setDescription (mb_ids[idx].realworld_id);
356 frame->setText (id_str);
364 add_id3v2frame_tag (ID3v2::Tag * id3v2tag, const GstTagList * list,
365 const gchar * tag, guint num_tags, const gchar * frame_id)
367 ID3v2::FrameFactory * factory = ID3v2::FrameFactory::instance ();
370 for (i = 0; i < num_tags; ++i) {
371 ID3v2::Frame * frame;
376 val = gst_tag_list_get_value_index (list, tag, i);
377 sample = (GstSample *) g_value_get_boxed (val);
379 if (sample && (buf = gst_sample_get_buffer (sample)) &&
380 gst_sample_get_caps (sample)) {
384 s = gst_caps_get_structure (gst_sample_get_caps (sample), 0);
385 if (s && gst_structure_get_int (s, "version", &version) && version > 0) {
388 gst_buffer_map (buf, &map, GST_MAP_READ);
389 GST_DEBUG ("Injecting ID3v2.%u frame %u/%u of length %u and type %"
390 GST_PTR_FORMAT, version, i, num_tags, map.size, s);
392 frame = factory->createFrame (ByteVector ((const char *) map.data,
393 map.size), (TagLib::uint) version);
395 id3v2tag->addFrame (frame);
397 gst_buffer_unmap (buf, &map);
404 add_image_tag (ID3v2::Tag * id3v2tag, const GstTagList * list,
405 const gchar * tag, guint num_tags, const gchar * unused)
409 for (n = 0; n < num_tags; ++n) {
414 GST_DEBUG ("image %u/%u", n + 1, num_tags);
416 val = gst_tag_list_get_value_index (list, tag, n);
417 sample = (GstSample *) g_value_get_boxed (val);
419 if (GST_IS_SAMPLE (sample) && (image = gst_sample_get_buffer (sample)) &&
420 GST_IS_BUFFER (image) && gst_buffer_get_size (image) > 0 &&
421 gst_sample_get_caps (sample) != NULL &&
422 !gst_caps_is_empty (gst_sample_get_caps (sample))) {
423 const gchar *mime_type;
426 s = gst_caps_get_structure (gst_sample_get_caps (sample), 0);
427 mime_type = gst_structure_get_name (s);
428 if (mime_type != NULL) {
429 ID3v2::AttachedPictureFrame * frame;
433 if (strcmp (mime_type, "text/uri-list") == 0)
436 frame = new ID3v2::AttachedPictureFrame ();
438 gst_buffer_map (image, &map, GST_MAP_READ);
440 GST_DEBUG ("Attaching picture of %u bytes and mime type %s",
441 map.size, mime_type);
443 id3v2tag->addFrame (frame);
444 frame->setPicture (ByteVector ((const char *) map.data, map.size));
445 frame->setTextEncoding (String::UTF8);
446 frame->setMimeType (mime_type);
448 gst_buffer_unmap (image, &map);
450 desc = gst_structure_get_string (s, "image-description");
451 frame->setDescription ((desc) ? desc : "");
453 /* FIXME set image type properly from caps */
454 if (strcmp (tag, GST_TAG_PREVIEW_IMAGE) == 0) {
455 frame->setType (ID3v2::AttachedPictureFrame::FileIcon);
457 frame->setType (ID3v2::AttachedPictureFrame::Other);
461 GST_WARNING ("NULL image or no caps on image sample (%p, caps=%"
462 GST_PTR_FORMAT ")", sample,
463 (sample) ? gst_sample_get_caps (sample) : NULL);
469 add_comment_tag (ID3v2::Tag * id3v2tag, const GstTagList * list,
470 const gchar * tag, guint num_tags, const gchar * unused)
472 TagLib::StringList string_list;
475 GST_LOG ("Adding comment frames");
476 for (n = 0; n < num_tags; ++n) {
479 if (gst_tag_list_get_string_index (list, tag, n, &s) && s != NULL) {
480 ID3v2::CommentsFrame * f;
481 gchar *desc = NULL, *val = NULL, *lang = NULL;
483 f = new ID3v2::CommentsFrame (String::UTF8);
485 if (strcmp (tag, GST_TAG_COMMENT) == 0 ||
486 !gst_tag_parse_extended_comment (s, &desc, &lang, &val, TRUE)) {
487 /* create dummy description to allow for multiple comment frames
488 * (taglib will drop comment frames if descriptions are not unique) */
489 desc = g_strdup_printf ("c%u", n);
493 GST_LOG ("%s[%u] = '%s' (%s|%s|%s)", tag, n, s, GST_STR_NULL (desc),
494 GST_STR_NULL (lang), GST_STR_NULL (val));
496 f->setDescription (desc);
499 f->setLanguage (lang);
506 id3v2tag->addFrame (f);
513 add_text_tag (ID3v2::Tag * id3v2tag, const GstTagList * list,
514 const gchar * tag, guint num_tags, const gchar * frame_id)
516 ID3v2::TextIdentificationFrame * f;
517 TagLib::StringList string_list;
520 GST_LOG ("Adding '%s' frame", frame_id);
521 for (n = 0; n < num_tags; ++n) {
524 if (gst_tag_list_get_string_index (list, tag, n, &s) && s != NULL) {
525 GST_LOG ("%s: %s[%u] = '%s'", frame_id, tag, n, s);
526 string_list.append (String (s, String::UTF8));
531 if (!string_list.isEmpty ()) {
532 f = new ID3v2::TextIdentificationFrame (frame_id, String::UTF8);
533 id3v2tag->addFrame (f);
534 f->setText (string_list);
536 GST_WARNING ("Empty list for tag %s, skipping", tag);
541 add_uri_tag (ID3v2::Tag * id3v2tag, const GstTagList * list,
542 const gchar * tag, guint num_tags, const gchar * frame_id)
546 g_assert (frame_id != NULL);
548 /* URI tags are limited to one of each per taglist */
549 if (gst_tag_list_get_string_index (list, tag, 0, &url) && url != NULL) {
552 url_len = strlen (url);
553 if (url_len > 0 && gst_uri_is_valid (url)) {
554 ID3v2::FrameFactory * factory = ID3v2::FrameFactory::instance ();
555 ID3v2::Frame * frame;
558 data = g_new0 (char, 10 + url_len);
560 memcpy (data, frame_id, 4);
561 memcpy (data + 4, ID3v2::SynchData::fromUInt (url_len).data (), 4);
562 memcpy (data + 10, url, url_len);
563 ByteVector bytes (data, 10 + url_len);
567 frame = factory->createFrame (bytes, (TagLib::uint) 4);
569 id3v2tag->addFrame (frame);
571 GST_LOG ("%s: %s = '%s'", frame_id, tag, url);
574 GST_WARNING ("Tag %s does not contain a valid URI (%s)", tag, url);
582 add_relative_volume_tag (ID3v2::Tag * id3v2tag, const GstTagList * list,
583 const gchar * tag, guint num_tags, const gchar * frame_id)
585 const char *gain_tag_name;
586 const char *peak_tag_name;
589 ID3v2::RelativeVolumeFrame * frame;
591 frame = new ID3v2::RelativeVolumeFrame ();
593 /* figure out tag names and the identification string to use */
594 if (strcmp (tag, GST_TAG_TRACK_PEAK) == 0 ||
595 strcmp (tag, GST_TAG_TRACK_GAIN) == 0) {
596 gain_tag_name = GST_TAG_TRACK_GAIN;
597 peak_tag_name = GST_TAG_TRACK_PEAK;
598 frame->setIdentification ("track");
599 GST_DEBUG ("adding track relative-volume frame");
601 gain_tag_name = GST_TAG_ALBUM_GAIN;
602 peak_tag_name = GST_TAG_ALBUM_PEAK;
603 frame->setIdentification ("album");
604 GST_DEBUG ("adding album relative-volume frame");
607 /* find the value for the paired tag (gain, if this is peak, and
608 * vice versa). if both tags exist, only write the frame when
609 * we're processing the peak tag.
611 if (strcmp (tag, GST_TAG_TRACK_PEAK) == 0 ||
612 strcmp (tag, GST_TAG_ALBUM_PEAK) == 0) {
613 ID3v2::RelativeVolumeFrame::PeakVolume encoded_peak;
616 gst_tag_list_get_double (list, tag, &peak_val);
618 if (gst_tag_list_get_tag_size (list, gain_tag_name) > 0) {
619 gst_tag_list_get_double (list, gain_tag_name, &gain_val);
620 GST_DEBUG ("setting volume adjustment %g", gain_val);
621 frame->setVolumeAdjustment (gain_val);
624 /* copying mutagen: always write as 16 bits for sanity. */
625 peak_int = (short)(peak_val * G_MAXSHORT);
626 encoded_peak.bitsRepresentingPeak = 16;
627 encoded_peak.peakVolume = ByteVector::fromShort(peak_int, true);
628 GST_DEBUG ("setting peak value %g", peak_val);
629 frame->setPeakVolume(encoded_peak);
632 gst_tag_list_get_double (list, tag, &gain_val);
633 GST_DEBUG ("setting volume adjustment %g", gain_val);
634 frame->setVolumeAdjustment (gain_val);
636 if (gst_tag_list_get_tag_size (list, peak_tag_name) != 0) {
637 GST_DEBUG ("both gain and peak tags exist, not adding frame this time around");
643 id3v2tag->addFrame (frame);
647 add_bpm_tag (ID3v2::Tag * id3v2tag, const GstTagList * list,
648 const gchar * tag, guint num_tags, const gchar * frame_id)
652 if (gst_tag_list_get_double_index (list, tag, 0, &bpm)) {
653 ID3v2::TextIdentificationFrame * frame;
656 tag_str = g_strdup_printf ("%u", (guint)bpm);
658 GST_DEBUG ("Setting %s to %s", tag, tag_str);
659 frame = new ID3v2::TextIdentificationFrame ("TBPM", String::UTF8);
660 id3v2tag->addFrame (frame);
661 frame->setText (tag_str);
666 /* id3demux produces these for frames it cannot parse */
667 #define GST_ID3_DEMUX_TAG_ID3V2_FRAME "private-id3v2-frame"
671 const gchar *gst_tag;
672 const GstId3v2MuxAddTagFunc func;
676 GST_TAG_ARTIST, add_text_tag, "TPE1"}, {
677 GST_TAG_ALBUM_ARTIST, add_text_tag, "TPE2"}, {
678 GST_TAG_TITLE, add_text_tag, "TIT2"}, {
679 GST_TAG_ALBUM, add_text_tag, "TALB"}, {
680 GST_TAG_COPYRIGHT, add_text_tag, "TCOP"}, {
681 GST_TAG_COMPOSER, add_text_tag, "TCOM"}, {
682 GST_TAG_GENRE, add_text_tag, "TCON"}, {
683 GST_TAG_COMMENT, add_comment_tag, ""}, {
684 GST_TAG_EXTENDED_COMMENT, add_comment_tag, ""}, {
685 GST_TAG_DATE, add_date_tag, ""}, {
686 GST_TAG_IMAGE, add_image_tag, ""}, {
687 GST_TAG_PREVIEW_IMAGE, add_image_tag, ""}, {
688 GST_ID3_DEMUX_TAG_ID3V2_FRAME, add_id3v2frame_tag, ""}, {
689 GST_TAG_MUSICBRAINZ_ARTISTID, add_musicbrainz_tag, "\000"}, {
690 GST_TAG_MUSICBRAINZ_ALBUMID, add_musicbrainz_tag, "\001"}, {
691 GST_TAG_MUSICBRAINZ_ALBUMARTISTID, add_musicbrainz_tag, "\002"}, {
692 GST_TAG_MUSICBRAINZ_TRMID, add_musicbrainz_tag, "\003"}, {
693 GST_TAG_CDDA_MUSICBRAINZ_DISCID, add_musicbrainz_tag, "\004"}, {
694 GST_TAG_CDDA_CDDB_DISCID, add_musicbrainz_tag, "\005"}, {
695 GST_TAG_MUSICBRAINZ_TRACKID, add_unique_file_id_tag, ""}, {
696 GST_TAG_ARTIST_SORTNAME, add_text_tag, "TSOP"}, {
697 GST_TAG_ALBUM_SORTNAME, add_text_tag, "TSOA"}, {
698 GST_TAG_TITLE_SORTNAME, add_text_tag, "TSOT"}, {
699 GST_TAG_TRACK_NUMBER, add_count_or_num_tag, "TRCK"}, {
700 GST_TAG_TRACK_COUNT, add_count_or_num_tag, "TRCK"}, {
701 GST_TAG_ALBUM_VOLUME_NUMBER, add_count_or_num_tag, "TPOS"}, {
702 GST_TAG_ALBUM_VOLUME_COUNT, add_count_or_num_tag, "TPOS"}, {
703 GST_TAG_ENCODER, add_encoder_tag, ""}, {
704 GST_TAG_ENCODER_VERSION, add_encoder_tag, ""}, {
705 GST_TAG_COPYRIGHT_URI, add_uri_tag, "WCOP"}, {
706 GST_TAG_LICENSE_URI, add_uri_tag, "WCOP"}, {
707 GST_TAG_TRACK_PEAK, add_relative_volume_tag, ""}, {
708 GST_TAG_TRACK_GAIN, add_relative_volume_tag, ""}, {
709 GST_TAG_ALBUM_PEAK, add_relative_volume_tag, ""}, {
710 GST_TAG_ALBUM_GAIN, add_relative_volume_tag, ""}, {
711 GST_TAG_BEATS_PER_MINUTE, add_bpm_tag, ""}
716 foreach_add_tag (const GstTagList * list, const gchar * tag, gpointer userdata)
718 ID3v2::Tag * id3v2tag = (ID3v2::Tag *) userdata;
719 TagLib::StringList string_list;
722 num_tags = gst_tag_list_get_tag_size (list, tag);
724 GST_LOG ("Processing tag %s (num=%u)", tag, num_tags);
726 if (num_tags > 1 && gst_tag_is_fixed (tag)) {
727 GST_WARNING ("Multiple occurences of fixed tag '%s', ignoring some", tag);
731 for (i = 0; i < G_N_ELEMENTS (add_funcs); ++i) {
732 if (strcmp (add_funcs[i].gst_tag, tag) == 0) {
733 add_funcs[i].func (id3v2tag, list, tag, num_tags, add_funcs[i].data);
738 if (i == G_N_ELEMENTS (add_funcs)) {
739 GST_WARNING ("Unsupported tag '%s' - not written", tag);
744 gst_id3v2_mux_render_tag (GstTagMux * mux, const GstTagList * taglist)
747 ByteVector rendered_tag;
751 /* write all strings as UTF-8 by default */
752 TagLib::ID3v2::FrameFactory::instance ()->
753 setDefaultTextEncoding (TagLib::String::UTF8);
756 gst_tag_list_foreach (taglist, foreach_add_tag, &id3v2tag);
759 /* Do we want to add our own signature to the tag somewhere? */
761 gchar *tag_producer_str;
763 tag_producer_str = g_strdup_printf ("(GStreamer id3v2mux %s, using "
764 "taglib %u.%u)", VERSION, TAGLIB_MAJOR_VERSION, TAGLIB_MINOR_VERSION);
765 add_one_txxx_tag (id3v2tag, "tag_encoder", tag_producer_str);
766 g_free (tag_producer_str);
770 rendered_tag = id3v2tag.render ();
771 tag_size = rendered_tag.size ();
773 GST_LOG_OBJECT (mux, "tag size = %d bytes", tag_size);
775 /* Create buffer with tag */
776 buf = gst_buffer_new_and_alloc (tag_size);
777 gst_buffer_fill (buf, 0, rendered_tag.data (), tag_size);
783 gst_id3v2_mux_render_end_tag (GstTagMux * mux, const GstTagList * taglist)