summaryrefslogtreecommitdiff
path: root/decoder.c
blob: dbb373bb6c366ddd3d4c915de4adba181bb55154 (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
#include "decoder.h"

gboolean decoder_init(struct decoder *decoder) {
	return decoder->decoder->init(&(decoder->data));
}

gssize decoder_decode(struct decoder *decoder, const guchar *inbuf,
		gsize inbuf_size, guchar *outbuf, gsize outbuf_size) {
	return decoder->decoder->decode(decoder->data, inbuf, inbuf_size,
			outbuf, outbuf_size);
}

void decoder_close(struct decoder *decoder) {
	decoder->decoder->close(decoder->data);
}

extern const struct decoder_plugin decoder_mpg123_decoder;

static const struct decoder_plugin *decoder_plugins[] = {
	&decoder_mpg123_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[i].extensions[j]; j++) {
			if(g_strcmp0(plugin[i].extensions[j], ext) == 0) {
				return plugin;
			}
		}
	}

	return NULL;
}