Debian Codegraph @

ext/cdio/gstcdio.c

raw symbols SCIP
1 /* GStreamer
2 * Copyright (C) 1999 Erik Walthinsen <[email protected]>
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 GST_DEBUG_CATEGORY_EXTERN (gst_cdio_debug);
29 #define GST_CAT_DEFAULT gst_cdio_debug
30
31 static gboolean plugin_init (GstPlugin * plugin);
32
33 /* cdio headers redefine VERSION etc., so do this here before including them */
34 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
35 GST_VERSION_MINOR,
36 cdio,
37 "Read audio from audio CDs",
38 plugin_init, VERSION, "GPL", GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN);
39
40 #include "gstcdio.h"
41 #include "gstcdiocddasrc.h"
42
43 void
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)
46 {
47 const gchar *vars[] = { "GST_CDTEXT_TAG_ENCODING", "GST_TAG_ENCODING", NULL };
48 const gchar *txt;
49 gchar *txt_utf8;
50
51 #if LIBCDIO_VERSION_NUM > 83 || LIBCDIO_VERSION_NUM < 76
52 txt = cdtext_get_const (cdtext, field, track);
53 #else
54 txt = cdtext_get_const (field, cdtext);
55 #endif
56 if (txt == NULL || *txt == '\0') {
57 GST_DEBUG_OBJECT (src, "empty CD-TEXT field %u (%s)", field, gst_tag);
58 return;
59 }
60
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);
64
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);
69 return;
70 }
71
72 /* FIXME: beautify strings (they might be all uppercase for example)? */
73
74 if (*p_tags == NULL)
75 *p_tags = gst_tag_list_new_empty ();
76
77 gst_tag_list_add (*p_tags, GST_TAG_MERGE_REPLACE, gst_tag, txt_utf8, NULL);
78
79 GST_DEBUG_OBJECT (src, "CD-TEXT: %s = %s", gst_tag, txt_utf8);
80 g_free (txt_utf8);
81 }
82
83 GstTagList *
84 #if LIBCDIO_VERSION_NUM > 83 || LIBCDIO_VERSION_NUM < 76
85 gst_cdio_get_cdtext (GstObject * src, cdtext_t * t, track_t track)
86 {
87 GstTagList *tags = NULL;
88
89 #else
90 gst_cdio_get_cdtext (GstObject * src, CdIo * cdio, track_t track)
91 {
92 GstTagList *tags = NULL;
93 cdtext_t *t;
94
95 t = cdio_get_cdtext (cdio, track);
96 if (t == NULL) {
97 GST_DEBUG_OBJECT (src, "no CD-TEXT for track %u", track);
98 return NULL;
99 }
100 #endif
101
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,
105 &tags);
106
107 return tags;
108 }
109
110 void
111 #if LIBCDIO_VERSION_NUM > 83 || LIBCDIO_VERSION_NUM < 76
112 gst_cdio_add_cdtext_album_tags (GstObject * src, cdtext_t * t,
113 GstTagList * tags)
114 {
115 #else
116 gst_cdio_add_cdtext_album_tags (GstObject * src, CdIo * cdio, GstTagList * tags)
117 {
118 cdtext_t *t;
119
120 t = cdio_get_cdtext (cdio, 0);
121 if (t == NULL) {
122 GST_DEBUG_OBJECT (src, "no CD-TEXT for album");
123 return;
124 }
125 #endif
126
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,
130 &tags);
131 gst_cdio_add_cdtext_field (src, t, 0, CDTEXT_FIELD_GENRE, GST_TAG_GENRE,
132 &tags);
133 GST_DEBUG ("CD-TEXT album tags: %" GST_PTR_FORMAT, tags);
134 }
135
136 void
137 gst_cdio_log_handler (cdio_log_level_t level, const char *msg)
138 {
139 const gchar *level_str[] = { "DEBUG", "INFO", "WARN", "ERROR", "ASSERT" };
140 const gchar *s;
141
142 s = level_str[CLAMP (level, 1, G_N_ELEMENTS (level_str)) - 1];
143 GST_DEBUG ("CDIO-%s: %s", s, GST_STR_NULL (msg));
144 }
145
146 static gboolean
147 plugin_init (GstPlugin * plugin)
148 {
149 return GST_ELEMENT_REGISTER (cdiocddasrc, plugin);
150 }