1 /* GStreamer
2 * Copyright (C) 2004 Benjamin Otte <otte@gnome.org>
3 * 2012 Stefan Sauer <ensonic@users.sf.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 "visual.h"
26
27 GST_DEBUG_CATEGORY (libvisual_debug);
28 #define GST_CAT_DEFAULT (libvisual_debug)
29
30 static void
libvisual_log_handler(const char * message,const char * funcname,void * priv)31 libvisual_log_handler (const char *message, const char *funcname, void *priv)
32 {
33 GST_CAT_LEVEL_LOG (libvisual_debug, (GstDebugLevel) GPOINTER_TO_INT (priv),
34 NULL, "%s - %s", funcname, message);
35 }
36
37 /*
38 * Replace invalid chars with _ in the type name
39 */
40 static void
make_valid_name(gchar * name)41 make_valid_name (gchar * name)
42 {
43 static const gchar extra_chars[] = "-_+";
44 gchar *p = name;
45
46 for (; *p; p++) {
47 gint valid = ((p[0] >= 'A' && p[0] <= 'Z') ||
48 (p[0] >= 'a' && p[0] <= 'z') ||
49 (p[0] >= '0' && p[0] <= '9') || strchr (extra_chars, p[0]));
50 if (!valid)
51 *p = '_';
52 }
53 }
54
55 static gboolean
gst_visual_actor_plugin_is_gl(VisObject * plugin,const gchar * name)56 gst_visual_actor_plugin_is_gl (VisObject * plugin, const gchar * name)
57 {
58 gboolean is_gl;
59 gint depth;
60
61 depth = VISUAL_ACTOR_PLUGIN (plugin)->vidoptions.depth;
62 /* FIXME: how to figure this out correctly in 0.4? */
63 is_gl = (depth & VISUAL_VIDEO_DEPTH_GL) == VISUAL_VIDEO_DEPTH_GL;
64
65 if (!is_gl) {
66 GST_DEBUG ("plugin %s is not a GL plugin (%d), registering", name, depth);
67 } else {
68 GST_DEBUG ("plugin %s is a GL plugin (%d), ignoring", name, depth);
69 }
70
71 return is_gl;
72 }
73
74 static gboolean
plugin_init(GstPlugin * plugin)75 plugin_init (GstPlugin * plugin)
76 {
77 guint i, count;
78 VisList *list;
79
80 GST_DEBUG_CATEGORY_INIT (libvisual_debug, "libvisual", 0,
81 "libvisual audio visualisations");
82
83 #ifdef LIBVISUAL_PLUGINSBASEDIR
84 gst_plugin_add_dependency_simple (plugin, "HOME/.libvisual/actor",
85 LIBVISUAL_PLUGINSBASEDIR "/actor", NULL, GST_PLUGIN_DEPENDENCY_FLAG_NONE);
86 #endif
87
88 visual_log_set_verboseness (VISUAL_LOG_VERBOSENESS_LOW);
89 visual_log_set_info_handler (libvisual_log_handler,
90 GINT_TO_POINTER (GST_LEVEL_INFO));
91 visual_log_set_warning_handler (libvisual_log_handler,
92 GINT_TO_POINTER (GST_LEVEL_WARNING));
93 visual_log_set_critical_handler (libvisual_log_handler,
94 GINT_TO_POINTER (GST_LEVEL_ERROR));
95 visual_log_set_error_handler (libvisual_log_handler,
96 GINT_TO_POINTER (GST_LEVEL_ERROR));
97
98 if (!visual_is_initialized ())
99 if (visual_init (NULL, NULL) != 0)
100 return FALSE;
101
102 list = visual_actor_get_list ();
103
104 count = visual_collection_size (VISUAL_COLLECTION (list));
105
106 for (i = 0; i < count; i++) {
107 VisPluginRef *ref = visual_list_get (list, i);
108 VisPluginData *visplugin = NULL;
109 gboolean skip = FALSE;
110 GType type;
111 gchar *name;
112 GTypeInfo info = {
113 sizeof (GstVisualClass),
114 NULL,
115 NULL,
116 gst_visual_class_init,
117 NULL,
118 ref,
119 sizeof (GstVisual),
120 0,
121 NULL
122 };
123
124 visplugin = visual_plugin_load (ref);
125
126 if (ref->info->plugname == NULL)
127 continue;
128
129 /* Blacklist some plugins */
130 if (strcmp (ref->info->plugname, "gstreamer") == 0 ||
131 strcmp (ref->info->plugname, "gdkpixbuf") == 0) {
132 skip = TRUE;
133 } else {
134 /* Ignore plugins that only support GL output for now */
135 skip = gst_visual_actor_plugin_is_gl (visplugin->info->plugin,
136 visplugin->info->plugname);
137 }
138
139 visual_plugin_unload (visplugin);
140
141 if (!skip) {
142 name = g_strdup_printf ("GstVisual%s", ref->info->plugname);
143 make_valid_name (name);
144 type = g_type_register_static (GST_TYPE_VISUAL, name, &info, 0);
145 g_free (name);
146
147 name = g_strdup_printf ("libvisual_%s", ref->info->plugname);
148 make_valid_name (name);
149 if (!gst_element_register (plugin, name, GST_RANK_NONE, type)) {
150 g_free (name);
151 return FALSE;
152 }
153 g_free (name);
154 }
155 }
156
157 return TRUE;
158 }
159
160 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
161 GST_VERSION_MINOR,
162 libvisual,
163 "libvisual visualization plugins",
164 plugin_init, VERSION, "LGPL", GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN)
165