blob: ade0797b692968557c9616a15277040dfcb85e65 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
#include "decoder.h"
gboolean decoder_init(struct decoder *decoder) {
return decoder->decoder->init(decoder);
}
gssize decoder_decode(struct decoder *decoder, GInputStream *input,
GOutputStream *output, GError **error) {
return decoder->decoder->decode(decoder, input, output, error);
}
void decoder_close(struct decoder *decoder) {
decoder->decoder->close(decoder);
}
extern const struct decoder_plugin decoder_mpg123_decoder;
extern const struct decoder_plugin decoder_flac_decoder;
static const struct decoder_plugin *decoder_plugins[] = {
&decoder_mpg123_decoder,
&decoder_flac_decoder,
NULL,
};
const struct decoder_plugin *decoder_get(const gchar *name) {
for(int i = 0; decoder_plugins[i]; i++) {
if(g_strcmp0(decoder_plugins[i]->name, name) == 0) {
return decoder_plugins[i];
}
}
return NULL;
}
const struct decoder_plugin *decoder_find(const gchar *filename) {
gchar *ext = g_strrstr(filename, ".");
if(ext == NULL) {
g_warning("decoder_find: no file extension found");
return NULL;
}
// exclude the dot
ext++;
for(int i = 0; decoder_plugins[i]; i++) {
const struct decoder_plugin *plugin = decoder_plugins[i];
for(int j = 0; plugin->extensions[j]; j++) {
if(g_strcmp0(plugin->extensions[j], ext) == 0) {
return plugin;
}
}
}
return NULL;
}
|