~ubuntu-branches/ubuntu/saucy/xmms2/saucy-proposed

« back to all changes in this revision

Viewing changes to src/xmms/xform_plugin.c

  • Committer: Bazaar Package Importer
  • Author(s): Benjamin Drung
  • Date: 2011-10-22 23:53:00 UTC
  • mto: (38.1.2 sid)
  • mto: This revision was merged to the branch mainline in revision 43.
  • Revision ID: james.westby@ubuntu.com-20111022235300-u50pdo3g341jvk7q
ImportĀ upstreamĀ versionĀ 0.8+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*  XMMS2 - X Music Multiplexer System
 
2
 *  Copyright (C) 2003-2011 XMMS2 Team
 
3
 *
 
4
 *  PLUGINS ARE NOT CONSIDERED TO BE DERIVED WORK !!!
 
5
 *
 
6
 *  This library is free software; you can redistribute it and/or
 
7
 *  modify it under the terms of the GNU Lesser General Public
 
8
 *  License as published by the Free Software Foundation; either
 
9
 *  version 2.1 of the License, or (at your option) any later version.
 
10
 *
 
11
 *  This library is distributed in the hope that it will be useful,
 
12
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
14
 *  Lesser General Public License for more details.
 
15
 */
 
16
 
 
17
#include "xmmspriv/xmms_xform.h"
 
18
#include "xmmspriv/xmms_xform_plugin.h"
 
19
#include "xmms/xmms_log.h"
 
20
 
 
21
struct xmms_xform_plugin_St {
 
22
        xmms_plugin_t plugin;
 
23
        xmms_xform_methods_t methods;
 
24
        GList *in_types;
 
25
};
 
26
 
 
27
static void
 
28
destroy (xmms_object_t *obj)
 
29
{
 
30
        xmms_xform_plugin_t *plugin = (xmms_xform_plugin_t *) obj;
 
31
 
 
32
        while (plugin->in_types) {
 
33
                xmms_object_unref (plugin->in_types->data);
 
34
 
 
35
                plugin->in_types = g_list_delete_link (plugin->in_types,
 
36
                                                       plugin->in_types);
 
37
        }
 
38
 
 
39
        xmms_plugin_destroy ((xmms_plugin_t *) obj);
 
40
}
 
41
 
 
42
xmms_plugin_t *
 
43
xmms_xform_plugin_new (void)
 
44
{
 
45
        xmms_xform_plugin_t *res;
 
46
 
 
47
        res = xmms_object_new (xmms_xform_plugin_t, destroy);
 
48
 
 
49
        return (xmms_plugin_t *)res;
 
50
}
 
51
 
 
52
void
 
53
xmms_xform_plugin_methods_set (xmms_xform_plugin_t *plugin,
 
54
                               xmms_xform_methods_t *methods)
 
55
{
 
56
        g_return_if_fail (plugin);
 
57
        g_return_if_fail (plugin->plugin.type == XMMS_PLUGIN_TYPE_XFORM);
 
58
 
 
59
        XMMS_DBG ("Registering xform '%s'",
 
60
                  xmms_plugin_shortname_get ((xmms_plugin_t *) plugin));
 
61
 
 
62
        memcpy (&plugin->methods, methods, sizeof (xmms_xform_methods_t));
 
63
}
 
64
 
 
65
gboolean
 
66
xmms_xform_plugin_verify (xmms_plugin_t *_plugin)
 
67
{
 
68
        xmms_xform_plugin_t *plugin = (xmms_xform_plugin_t *) _plugin;
 
69
 
 
70
        g_return_val_if_fail (plugin, FALSE);
 
71
        g_return_val_if_fail (plugin->plugin.type == XMMS_PLUGIN_TYPE_XFORM, FALSE);
 
72
 
 
73
        /* more checks */
 
74
 
 
75
        return TRUE;
 
76
}
 
77
 
 
78
void
 
79
xmms_xform_plugin_indata_add (xmms_xform_plugin_t *plugin, ...)
 
80
{
 
81
        xmms_stream_type_t *t;
 
82
        va_list ap;
 
83
        gchar *config_key, config_value[32];
 
84
        gint priority;
 
85
 
 
86
        va_start (ap, plugin);
 
87
        t = xmms_stream_type_parse (ap);
 
88
        va_end (ap);
 
89
 
 
90
        config_key = g_strconcat ("priority.",
 
91
                                  xmms_stream_type_get_str (t, XMMS_STREAM_TYPE_NAME),
 
92
                                  NULL);
 
93
        priority = xmms_stream_type_get_int (t, XMMS_STREAM_TYPE_PRIORITY);
 
94
        g_snprintf (config_value, sizeof (config_value), "%d", priority);
 
95
        xmms_xform_plugin_config_property_register (plugin, config_key,
 
96
                                                    config_value, NULL, NULL);
 
97
        g_free (config_key);
 
98
 
 
99
        plugin->in_types = g_list_prepend (plugin->in_types, t);
 
100
}
 
101
 
 
102
gboolean
 
103
xmms_xform_plugin_supports (const xmms_xform_plugin_t *plugin, xmms_stream_type_t *st,
 
104
                            gint *priority)
 
105
{
 
106
        GList *t;
 
107
 
 
108
        g_return_val_if_fail (st, FALSE);
 
109
        g_return_val_if_fail (plugin, FALSE);
 
110
        g_return_val_if_fail (priority, FALSE);
 
111
 
 
112
        for (t = plugin->in_types; t; t = g_list_next (t)) {
 
113
                xmms_config_property_t *config_priority;
 
114
                const gchar *type_name;
 
115
                gchar *config_key;
 
116
 
 
117
                if (!xmms_stream_type_match (t->data, st)) {
 
118
                        continue;
 
119
                }
 
120
 
 
121
                type_name = xmms_stream_type_get_str (t->data, XMMS_STREAM_TYPE_NAME);
 
122
 
 
123
                config_key = g_strconcat ("priority.", type_name, NULL);
 
124
                config_priority = xmms_plugin_config_lookup ((xmms_plugin_t *) plugin,
 
125
                                                             config_key);
 
126
                g_free (config_key);
 
127
 
 
128
                if (config_priority) {
 
129
                        *priority = xmms_config_property_get_int (config_priority);
 
130
                } else {
 
131
                        *priority = XMMS_STREAM_TYPE_PRIORITY_DEFAULT;
 
132
                }
 
133
 
 
134
                return TRUE;
 
135
        }
 
136
 
 
137
        return FALSE;
 
138
}
 
139
 
 
140
xmms_config_property_t *
 
141
xmms_xform_plugin_config_property_register (xmms_xform_plugin_t *xform_plugin,
 
142
                                            const gchar *name,
 
143
                                            const gchar *default_value,
 
144
                                            xmms_object_handler_t cb,
 
145
                                            gpointer userdata)
 
146
{
 
147
        xmms_plugin_t *plugin = (xmms_plugin_t *) xform_plugin;
 
148
 
 
149
        return xmms_plugin_config_property_register (plugin, name,
 
150
                                                     default_value,
 
151
                                                     cb, userdata);
 
152
}
 
153
 
 
154
gboolean
 
155
xmms_xform_plugin_can_init (const xmms_xform_plugin_t *plugin)
 
156
{
 
157
        return !!plugin->methods.init;
 
158
}
 
159
 
 
160
gboolean
 
161
xmms_xform_plugin_can_read (const xmms_xform_plugin_t *plugin)
 
162
{
 
163
        return !!plugin->methods.read;
 
164
}
 
165
 
 
166
gboolean
 
167
xmms_xform_plugin_can_seek (const xmms_xform_plugin_t *plugin)
 
168
{
 
169
        return !!plugin->methods.seek;
 
170
}
 
171
 
 
172
gboolean
 
173
xmms_xform_plugin_can_browse (const xmms_xform_plugin_t *plugin)
 
174
{
 
175
        return !!plugin->methods.browse;
 
176
}
 
177
 
 
178
gboolean
 
179
xmms_xform_plugin_can_destroy (const xmms_xform_plugin_t *plugin)
 
180
{
 
181
        return !!plugin->methods.destroy;
 
182
}
 
183
 
 
184
gboolean
 
185
xmms_xform_plugin_init (const xmms_xform_plugin_t *plugin, xmms_xform_t *xform)
 
186
{
 
187
        return plugin->methods.init (xform);
 
188
}
 
189
 
 
190
gint
 
191
xmms_xform_plugin_read (const xmms_xform_plugin_t *plugin, xmms_xform_t *xform,
 
192
                        xmms_sample_t *buf, gint length, xmms_error_t *error)
 
193
{
 
194
        return plugin->methods.read (xform, buf, length, error);
 
195
}
 
196
 
 
197
gint64
 
198
xmms_xform_plugin_seek (const xmms_xform_plugin_t *plugin, xmms_xform_t *xform,
 
199
                        gint64 offset, xmms_xform_seek_mode_t whence,
 
200
                        xmms_error_t *err)
 
201
{
 
202
        return plugin->methods.seek (xform, offset, whence, err);
 
203
}
 
204
 
 
205
 
 
206
gboolean
 
207
xmms_xform_plugin_browse (const xmms_xform_plugin_t *plugin, xmms_xform_t *xform,
 
208
                          const gchar *url, xmms_error_t *error)
 
209
{
 
210
        return plugin->methods.browse (xform, url, error);
 
211
}
 
212
 
 
213
void
 
214
xmms_xform_plugin_destroy (const xmms_xform_plugin_t *plugin, xmms_xform_t *xform)
 
215
{
 
216
        plugin->methods.destroy (xform);
 
217
}
 
218