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) (priv), NULL, "%s - %s",
34       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, (void *) GST_LEVEL_INFO);
90   visual_log_set_warning_handler (libvisual_log_handler,
91       (void *) GST_LEVEL_WARNING);
92   visual_log_set_critical_handler (libvisual_log_handler,
93       (void *) GST_LEVEL_ERROR);
94   visual_log_set_error_handler (libvisual_log_handler,
95       (void *) GST_LEVEL_ERROR);
96 
97   if (!visual_is_initialized ())
98     if (visual_init (NULL, NULL) != 0)
99       return FALSE;
100 
101   list = visual_actor_get_list ();
102 
103   count = visual_collection_size (VISUAL_COLLECTION (list));
104 
105   for (i = 0; i < count; i++) {
106     VisPluginRef *ref = visual_list_get (list, i);
107     VisPluginData *visplugin = NULL;
108     gboolean skip = FALSE;
109     GType type;
110     gchar *name;
111     GTypeInfo info = {
112       sizeof (GstVisualClass),
113       NULL,
114       NULL,
115       gst_visual_class_init,
116       NULL,
117       ref,
118       sizeof (GstVisual),
119       0,
120       NULL
121     };
122 
123     visplugin = visual_plugin_load (ref);
124 
125     if (ref->info->plugname == NULL)
126       continue;
127 
128     /* Blacklist some plugins */
129     if (strcmp (ref->info->plugname, "gstreamer") == 0 ||
130         strcmp (ref->info->plugname, "gdkpixbuf") == 0) {
131       skip = TRUE;
132     } else {
133       /* Ignore plugins that only support GL output for now */
134       skip = gst_visual_actor_plugin_is_gl (visplugin->info->plugin,
135           visplugin->info->plugname);
136     }
137 
138     visual_plugin_unload (visplugin);
139 
140     if (!skip) {
141       name = g_strdup_printf ("GstVisual%s", ref->info->plugname);
142       make_valid_name (name);
143       type = g_type_register_static (GST_TYPE_VISUAL, name, &info, 0);
144       g_free (name);
145 
146       name = g_strdup_printf ("libvisual_%s", ref->info->plugname);
147       make_valid_name (name);
148       if (!gst_element_register (plugin, name, GST_RANK_NONE, type)) {
149         g_free (name);
150         return FALSE;
151       }
152       g_free (name);
153     }
154   }
155 
156   return TRUE;
157 }
158 
159 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
160     GST_VERSION_MINOR,
161     libvisual,
162     "libvisual visualization plugins",
163     plugin_init, VERSION, "LGPL", GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN)
164