summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJon Bergli Heier <snakebite@jvnv.net>2010-08-17 18:18:13 +0200
committerJon Bergli Heier <snakebite@jvnv.net>2010-08-17 18:18:13 +0200
commitb0ac9c1ffb46aa06541b276f209d80eba24e99df (patch)
tree585ba7fc67516abc7feba98f8ddd74a8d446449d
parenteb543b8ddb00761de3a52f6da024ffacf5ba9b92 (diff)
Added mpg123 decoder.
-rw-r--r--decoders/decoder_mpg123.c79
1 files changed, 79 insertions, 0 deletions
diff --git a/decoders/decoder_mpg123.c b/decoders/decoder_mpg123.c
new file mode 100644
index 0000000..4d93f27
--- /dev/null
+++ b/decoders/decoder_mpg123.c
@@ -0,0 +1,79 @@
+#include "decoder.h"
+
+#include <mpg123.h>
+#include <stdio.h>
+
+static gboolean mpg123_decoder_init(gpointer *data) {
+ mpg123_handle *handle;
+
+ int error;
+ mpg123_init();
+
+ handle = mpg123_new("generic", &error);
+ if(error) {
+ g_warning("Error: %s", mpg123_plain_strerror(error));
+ return FALSE;
+ }
+
+ error = mpg123_open_feed(handle);
+ if(error) {
+ g_warning("Error: %s", mpg123_plain_strerror(error));
+ }
+
+ /* force format for now */
+ mpg123_format_none(handle);
+ mpg123_format(handle, 44100, 2, MPG123_ENC_SIGNED_16);
+
+ *data = handle;
+
+ return TRUE;
+}
+
+static gssize mpg123_decoder_decode(gpointer data, const guchar *inbuf,
+ gsize inbuf_size, guchar *outbuf, gsize outbuf_size) {
+ mpg123_handle *handle = data;
+ gssize size;
+ int ret;
+
+ if(mpg123_feed(handle, inbuf, inbuf_size) != MPG123_OK) {
+ g_debug("asdfasdf");
+ g_warning(mpg123_strerror(handle));
+ return -1;
+ }
+
+ ret = mpg123_read(handle, outbuf, outbuf_size, (size_t*)&size);
+
+ if(ret == MPG123_NEW_FORMAT) {
+ long rate;
+ int channels, enc;
+ mpg123_getformat(handle, &rate, &channels, &enc);
+ g_debug("New format: %li Hz, %i channels, encoding value %i", rate, channels, enc);
+ ret = mpg123_read(handle, outbuf, outbuf_size, (size_t*)&size);
+ }
+
+ if(ret != MPG123_OK && ret != MPG123_DONE && ret != MPG123_NEW_FORMAT
+ && ret != MPG123_NEED_MORE) {
+ g_warning(mpg123_plain_strerror(ret));
+ return -1;
+ }
+
+ return size;
+}
+
+static void mpg123_decoder_close(gpointer data) {
+ mpg123_handle *handle = data;
+ mpg123_close(handle);
+ mpg123_delete(handle);
+}
+
+static const gchar * const decoder_mpg123_extensions[] = {
+ "mp3", NULL,
+};
+
+const struct decoder_plugin decoder_mpg123_decoder = {
+ .name = "mpg123 decoder",
+ .extensions = decoder_mpg123_extensions,
+ .init = mpg123_decoder_init,
+ .decode = mpg123_decoder_decode,
+ .close = mpg123_decoder_close,
+};