annotate libvisual/lv_input.c @ 27:d160ae2251e9 trunk

[svn] Update SIGSEGV message, contained the BMP mailing information.
author nenolod
date Tue, 25 Oct 2005 21:26:50 -0700
parents 0db4a1dc75c4
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
23
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
1 /* Libvisual - The audio visualisation framework.
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
2 *
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
3 * Copyright (C) 2004, 2005 Dennis Smit <ds@nerds-incorporated.org>
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
4 *
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
5 * Authors: Dennis Smit <ds@nerds-incorporated.org>
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
6 *
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
7 * $Id:
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
8 *
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
9 * This program is free software; you can redistribute it and/or modify
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
10 * it under the terms of the GNU Lesser General Public License as
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
11 * published by the Free Software Foundation; either version 2.1
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
12 * of the License, or (at your option) any later version.
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
13 *
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
14 * This program is distributed in the hope that it will be useful,
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
17 * GNU Lesser General Public License for more details.
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
18 *
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
19 * You should have received a copy of the GNU Lesser General Public License
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
20 * along with this program; if not, write to the Free Software
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
22 */
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
23
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
24 #include <stdio.h>
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
25 #include <stdlib.h>
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
26 #include <unistd.h>
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
27 #include <string.h>
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
28
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
29 #include "lv_list.h"
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
30 #include "lv_input.h"
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
31
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
32 extern VisList *__lv_plugins_input;
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
33
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
34 static int input_dtor (VisObject *object);
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
35
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
36 static VisInputPlugin *get_input_plugin (VisInput *input);
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
37
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
38 static int input_dtor (VisObject *object)
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
39 {
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
40 VisInput *input = VISUAL_INPUT (object);
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
41
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
42 if (input->plugin != NULL)
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
43 visual_plugin_unload (input->plugin);
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
44
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
45 if (input->audio != NULL)
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
46 visual_object_unref (VISUAL_OBJECT (input->audio));
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
47
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
48 input->plugin = NULL;
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
49 input->audio = NULL;
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
50
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
51 return VISUAL_OK;
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
52 }
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
53
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
54 static VisInputPlugin *get_input_plugin (VisInput *input)
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
55 {
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
56 VisInputPlugin *inplugin;
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
57
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
58 visual_log_return_val_if_fail (input != NULL, NULL);
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
59 visual_log_return_val_if_fail (input->plugin != NULL, NULL);
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
60
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
61 inplugin = VISUAL_PLUGIN_INPUT (input->plugin->info->plugin);
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
62
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
63 return inplugin;
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
64 }
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
65
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
66 /**
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
67 * @defgroup VisInput VisInput
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
68 * @{
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
69 */
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
70
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
71 /**
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
72 * Gives the encapsulated VisPluginData from a VisInput.
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
73 *
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
74 * @param input Pointer of a VisInput of which the VisPluginData needs to be returned.
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
75 *
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
76 * @return VisPluginData that is encapsulated in the VisInput, possibly NULL.
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
77 */
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
78 VisPluginData *visual_input_get_plugin (VisInput *input)
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
79 {
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
80 return input->plugin;
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
81 }
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
82
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
83 /**
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
84 * Gives a list of input plugins in the current plugin registry.
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
85 *
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
86 * @return An VisList of VisPluginRef's containing the input plugins in the plugin registry.
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
87 */
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
88 VisList *visual_input_get_list ()
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
89 {
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
90 return __lv_plugins_input;
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
91 }
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
92
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
93 /**
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
94 * Gives the next input plugin based on the name of a plugin.
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
95 *
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
96 * @see visual_input_get_prev_by_name
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
97 *
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
98 * @param name The name of the current plugin, or NULL to get the first.
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
99 *
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
100 * @return The name of the next plugin within the list.
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
101 */
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
102 const char *visual_input_get_next_by_name (const char *name)
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
103 {
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
104 return visual_plugin_get_next_by_name (visual_input_get_list (), name);
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
105 }
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
106
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
107 /**
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
108 * Gives the previous input plugin based on the name of a plugin.
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
109 *
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
110 * @see visual_input_get_next_by_name
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
111 *
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
112 * @param name The name of the current plugin. or NULL to get the last.
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
113 *
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
114 * @return The name of the previous plugin within the list.
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
115 */
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
116 const char *visual_input_get_prev_by_name (const char *name)
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
117 {
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
118 return visual_plugin_get_prev_by_name (visual_input_get_list (), name);
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
119 }
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
120
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
121
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
122 /**
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
123 * Checks if the input plugin is in the registry, based on it's name.
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
124 *
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
125 * @param name The name of the plugin that needs to be checked.
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
126 *
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
127 * @return TRUE if found, else FALSE.
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
128 */
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
129 int visual_input_valid_by_name (const char *name)
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
130 {
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
131 if (visual_plugin_find (visual_input_get_list (), name) == NULL)
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
132 return FALSE;
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
133 else
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
134 return TRUE;
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
135 }
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
136
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
137 /**
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
138 * Creates a new VisInput from name, the plugin will be loaded but won't be realized.
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
139 *
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
140 * @param inputname
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
141 * The name of the plugin to load, or NULL to simply allocate a new
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
142 * input.
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
143 *
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
144 * @return A newly allocated VisInput, optionally containing a loaded plugin. Or NULL on failure.
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
145 */
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
146 VisInput *visual_input_new (const char *inputname)
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
147 {
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
148 VisInput *input;
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
149 VisPluginRef *ref;
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
150
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
151 // visual_log_return_val_if_fail (__lv_plugins_input != NULL && inputname == NULL, NULL);
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
152
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
153 if (__lv_plugins_input == NULL && inputname != NULL) {
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
154 visual_log (VISUAL_LOG_CRITICAL, "the plugin list is NULL");
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
155 return NULL;
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
156 }
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
157
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
158 input = visual_mem_new0 (VisInput, 1);
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
159
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
160 input->audio = visual_audio_new ();
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
161
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
162 /* Do the VisObject initialization */
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
163 visual_object_initialize (VISUAL_OBJECT (input), TRUE, input_dtor);
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
164
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
165 if (inputname == NULL)
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
166 return input;
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
167
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
168 ref = visual_plugin_find (__lv_plugins_input, inputname);
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
169
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
170 input->plugin = visual_plugin_load (ref);
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
171
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
172 return input;
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
173 }
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
174
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
175 /**
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
176 * Realize the VisInput. This also calls the plugin init function.
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
177 *
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
178 * @param input Pointer to a VisInput that needs to be realized.
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
179 *
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
180 * @return VISUAL_OK on succes, -VISUAL_ERROR_INPUT_NULL or error values returned by
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
181 * visual_plugin_realize () on failure.
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
182 */
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
183 int visual_input_realize (VisInput *input)
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
184 {
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
185 visual_log_return_val_if_fail (input != NULL, -VISUAL_ERROR_INPUT_NULL);
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
186
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
187 if (input->plugin != NULL && input->callback == NULL)
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
188 return visual_plugin_realize (input->plugin);
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
189
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
190 return VISUAL_OK;
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
191 }
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
192
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
193 /**
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
194 * Sets a callback function for VisInput. Callback functions can be used instead of plugins. Using
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
195 * a callback function you can implement an in app PCM data upload function which is like the
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
196 * upload callback that is used for input plugins.
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
197 *
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
198 * @param input Pointer to a VisInput that to which a callback needs to be set.
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
199 * @param callback The in app callback function that should be used instead of a plugin.
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
200 * @param priv A private that can be read within the callback function.
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
201 *
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
202 * @return VISUAL_OK on succes, -VISUAL_ERROR_INPUT_NULL on failure.
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
203 */
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
204 int visual_input_set_callback (VisInput *input, VisInputUploadCallbackFunc callback, void *priv)
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
205 {
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
206 visual_log_return_val_if_fail (input != NULL, -VISUAL_ERROR_INPUT_NULL);
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
207
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
208 input->callback = callback;
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
209 visual_object_set_private (VISUAL_OBJECT (input), priv);
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
210
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
211 return VISUAL_OK;
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
212 }
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
213
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
214 /**
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
215 * This is called to run a VisInput. This function will call the plugin to upload it's samples and run it
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
216 * through the visual_audio_analyze function. If a callback is set it will use the callback instead of
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
217 * the plugin.
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
218 *
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
219 * @param input A pointer to a VisInput that needs to be runned.
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
220 *
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
221 * @return VISUAL_OK on succes, -VISUAL_ERROR_INPUT_NULL or -VISUAL_ERROR_INPUT_PLUGIN_NULL on failure.
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
222 */
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
223 int visual_input_run (VisInput *input)
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
224 {
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
225 VisInputPlugin *inplugin;
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
226
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
227 visual_log_return_val_if_fail (input != NULL, -VISUAL_ERROR_INPUT_NULL);
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
228
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
229 if (input->callback == NULL) {
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
230 inplugin = get_input_plugin (input);
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
231
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
232 if (inplugin == NULL) {
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
233 visual_log (VISUAL_LOG_CRITICAL, "The input plugin is not loaded correctly.");
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
234
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
235 return -VISUAL_ERROR_INPUT_PLUGIN_NULL;
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
236 }
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
237
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
238 inplugin->upload (input->plugin, input->audio);
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
239 } else
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
240 input->callback (input, input->audio, visual_object_get_private (VISUAL_OBJECT (input)));
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
241
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
242 visual_audio_analyze (input->audio);
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
243
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
244 return VISUAL_OK;
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
245 }
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
246
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
247 /**
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
248 * @}
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
249 */
0db4a1dc75c4 [svn] libvisual.
nenolod
parents:
diff changeset
250