1 /* GStreamer
2 * Copyright (C) 1999 Erik Walthinsen <omega@cse.ogi.edu>
3 * Copyright (C) 2006 Tim-Philipp Müller <tim centricular net>
4 *
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.
9 *
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.
14 *
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.
19 */
20
21 #ifdef HAVE_CONFIG_H
22 #include "config.h"
23 #endif
24
25 #include <gst/gst.h>
26 #include <gst/tag/tag.h>
27
28 static gboolean plugin_init (GstPlugin * plugin);
29
30 /* cdio headers redefine VERSION etc., so do this here before including them */
31 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
32 GST_VERSION_MINOR,
33 cdio,
34 "Read audio from audio CDs",
35 plugin_init, VERSION, "GPL", GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN);
36
37 #include "gstcdio.h"
38 #include "gstcdiocddasrc.h"
39
40 #include <cdio/logging.h>
41
42 GST_DEBUG_CATEGORY (gst_cdio_debug);
43
44 void
gst_cdio_add_cdtext_field(GstObject * src,cdtext_t * cdtext,track_t track,cdtext_field_t field,const gchar * gst_tag,GstTagList ** p_tags)45 gst_cdio_add_cdtext_field (GstObject * src, cdtext_t * cdtext, track_t track,
46 cdtext_field_t field, const gchar * gst_tag, GstTagList ** p_tags)
47 {
48 const gchar *vars[] = { "GST_CDTEXT_TAG_ENCODING", "GST_TAG_ENCODING", NULL };
49 const gchar *txt;
50 gchar *txt_utf8;
51
52 #if LIBCDIO_VERSION_NUM > 83 || LIBCDIO_VERSION_NUM < 76
53 txt = cdtext_get_const (cdtext, field, track);
54 #else
55 txt = cdtext_get_const (field, cdtext);
56 #endif
57 if (txt == NULL || *txt == '\0') {
58 GST_DEBUG_OBJECT (src, "empty CD-TEXT field %u (%s)", field, gst_tag);
59 return;
60 }
61
62 /* The character encoding is not specified, and there is no provision
63 * for indicating in the CD-Text data which encoding is in use.. */
64 txt_utf8 = gst_tag_freeform_string_to_utf8 (txt, -1, vars);
65
66 if (txt_utf8 == NULL) {
67 GST_WARNING_OBJECT (src, "CD-TEXT %s could not be converted to UTF-8, "
68 "try setting the GST_CDTEXT_TAG_ENCODING or GST_TAG_ENCODING "
69 "environment variable", gst_tag);
70 return;
71 }
72
73 /* FIXME: beautify strings (they might be all uppercase for example)? */
74
75 if (*p_tags == NULL)
76 *p_tags = gst_tag_list_new_empty ();
77
78 gst_tag_list_add (*p_tags, GST_TAG_MERGE_REPLACE, gst_tag, txt_utf8, NULL);
79
80 GST_DEBUG_OBJECT (src, "CD-TEXT: %s = %s", gst_tag, txt_utf8);
81 g_free (txt_utf8);
82 }
83
84 GstTagList *
85 #if LIBCDIO_VERSION_NUM > 83 || LIBCDIO_VERSION_NUM < 76
gst_cdio_get_cdtext(GstObject * src,cdtext_t * t,track_t track)86 gst_cdio_get_cdtext (GstObject * src, cdtext_t * t, track_t track)
87 {
88 GstTagList *tags = NULL;
89
90 #else
91 gst_cdio_get_cdtext (GstObject * src, CdIo * cdio, track_t track)
92 {
93 GstTagList *tags = NULL;
94 cdtext_t *t;
95
96 t = cdio_get_cdtext (cdio, track);
97 if (t == NULL) {
98 GST_DEBUG_OBJECT (src, "no CD-TEXT for track %u", track);
99 return NULL;
100 }
101 #endif
102
103 gst_cdio_add_cdtext_field (src, t, track, CDTEXT_FIELD_PERFORMER,
104 GST_TAG_ARTIST, &tags);
105 gst_cdio_add_cdtext_field (src, t, track, CDTEXT_FIELD_TITLE, GST_TAG_TITLE,
106 &tags);
107
108 return tags;
109 }
110
111 void
112 #if LIBCDIO_VERSION_NUM > 83 || LIBCDIO_VERSION_NUM < 76
113 gst_cdio_add_cdtext_album_tags (GstObject * src, cdtext_t * t,
114 GstTagList * tags)
115 {
116 #else
117 gst_cdio_add_cdtext_album_tags (GstObject * src, CdIo * cdio, GstTagList * tags)
118 {
119 cdtext_t *t;
120
121 t = cdio_get_cdtext (cdio, 0);
122 if (t == NULL) {
123 GST_DEBUG_OBJECT (src, "no CD-TEXT for album");
124 return;
125 }
126 #endif
127
128 gst_cdio_add_cdtext_field (src, t, 0, CDTEXT_FIELD_PERFORMER,
129 GST_TAG_ALBUM_ARTIST, &tags);
130 gst_cdio_add_cdtext_field (src, t, 0, CDTEXT_FIELD_TITLE, GST_TAG_ALBUM,
131 &tags);
132 gst_cdio_add_cdtext_field (src, t, 0, CDTEXT_FIELD_GENRE, GST_TAG_GENRE,
133 &tags);
134 GST_DEBUG ("CD-TEXT album tags: %" GST_PTR_FORMAT, tags);
135 }
136
137 static void
138 gst_cdio_log_handler (cdio_log_level_t level, const char *msg)
139 {
140 const gchar *level_str[] = { "DEBUG", "INFO", "WARN", "ERROR", "ASSERT" };
141 const gchar *s;
142
143 s = level_str[CLAMP (level, 1, G_N_ELEMENTS (level_str)) - 1];
144 GST_DEBUG ("CDIO-%s: %s", s, GST_STR_NULL (msg));
145 }
146
147 static gboolean
148 plugin_init (GstPlugin * plugin)
149 {
150 if (!gst_element_register (plugin, "cdiocddasrc", GST_RANK_SECONDARY - 1,
151 GST_TYPE_CDIO_CDDA_SRC))
152 return FALSE;
153
154 cdio_log_set_handler (gst_cdio_log_handler);
155
156 GST_DEBUG_CATEGORY_INIT (gst_cdio_debug, "cdio", 0, "libcdio elements");
157
158 return TRUE;
159 }
160