2 * Copyright (C) 1999 Erik Walthinsen <omega@cse.ogi.edu>
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., 51 Franklin St, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
26 #include <gst/tag/tag.h>
28 GST_DEBUG_CATEGORY_EXTERN (gst_cdio_debug);
29 #define GST_CAT_DEFAULT gst_cdio_debug
31 static gboolean plugin_init (GstPlugin * plugin);
33 /* cdio headers redefine VERSION etc., so do this here before including them */
34 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
37 "Read audio from audio CDs",
38 plugin_init, VERSION, "GPL", GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN);
41 #include "gstcdiocddasrc.h"
44 gst_cdio_add_cdtext_field (GstObject * src, cdtext_t * cdtext, track_t track,
45 cdtext_field_t field, const gchar * gst_tag, GstTagList ** p_tags)
47 const gchar *vars[] = { "GST_CDTEXT_TAG_ENCODING", "GST_TAG_ENCODING", NULL };
51 #if LIBCDIO_VERSION_NUM > 83 || LIBCDIO_VERSION_NUM < 76
52 txt = cdtext_get_const (cdtext, field, track);
54 txt = cdtext_get_const (field, cdtext);
56 if (txt == NULL || *txt == '\0') {
57 GST_DEBUG_OBJECT (src, "empty CD-TEXT field %u (%s)", field, gst_tag);
61 /* The character encoding is not specified, and there is no provision
62 * for indicating in the CD-Text data which encoding is in use.. */
63 txt_utf8 = gst_tag_freeform_string_to_utf8 (txt, -1, vars);
65 if (txt_utf8 == NULL) {
66 GST_WARNING_OBJECT (src, "CD-TEXT %s could not be converted to UTF-8, "
67 "try setting the GST_CDTEXT_TAG_ENCODING or GST_TAG_ENCODING "
68 "environment variable", gst_tag);
72 /* FIXME: beautify strings (they might be all uppercase for example)? */
75 *p_tags = gst_tag_list_new_empty ();
77 gst_tag_list_add (*p_tags, GST_TAG_MERGE_REPLACE, gst_tag, txt_utf8, NULL);
79 GST_DEBUG_OBJECT (src, "CD-TEXT: %s = %s", gst_tag, txt_utf8);
84 #if LIBCDIO_VERSION_NUM > 83 || LIBCDIO_VERSION_NUM < 76
85 gst_cdio_get_cdtext (GstObject * src, cdtext_t * t, track_t track)
87 GstTagList *tags = NULL;
90 gst_cdio_get_cdtext (GstObject * src, CdIo * cdio, track_t track)
92 GstTagList *tags = NULL;
95 t = cdio_get_cdtext (cdio, track);
97 GST_DEBUG_OBJECT (src, "no CD-TEXT for track %u", track);
102 gst_cdio_add_cdtext_field (src, t, track, CDTEXT_FIELD_PERFORMER,
103 GST_TAG_ARTIST, &tags);
104 gst_cdio_add_cdtext_field (src, t, track, CDTEXT_FIELD_TITLE, GST_TAG_TITLE,
111 #if LIBCDIO_VERSION_NUM > 83 || LIBCDIO_VERSION_NUM < 76
112 gst_cdio_add_cdtext_album_tags (GstObject * src, cdtext_t * t,
116 gst_cdio_add_cdtext_album_tags (GstObject * src, CdIo * cdio, GstTagList * tags)
120 t = cdio_get_cdtext (cdio, 0);
122 GST_DEBUG_OBJECT (src, "no CD-TEXT for album");
127 gst_cdio_add_cdtext_field (src, t, 0, CDTEXT_FIELD_PERFORMER,
128 GST_TAG_ALBUM_ARTIST, &tags);
129 gst_cdio_add_cdtext_field (src, t, 0, CDTEXT_FIELD_TITLE, GST_TAG_ALBUM,
131 gst_cdio_add_cdtext_field (src, t, 0, CDTEXT_FIELD_GENRE, GST_TAG_GENRE,
133 GST_DEBUG ("CD-TEXT album tags: %" GST_PTR_FORMAT, tags);
137 gst_cdio_log_handler (cdio_log_level_t level, const char *msg)
139 const gchar *level_str[] = { "DEBUG", "INFO", "WARN", "ERROR", "ASSERT" };
142 s = level_str[CLAMP (level, 1, G_N_ELEMENTS (level_str)) - 1];
143 GST_DEBUG ("CDIO-%s: %s", s, GST_STR_NULL (msg));
147 plugin_init (GstPlugin * plugin)
149 return GST_ELEMENT_REGISTER (cdiocddasrc, plugin);