summaryrefslogtreecommitdiff
path: root/decoders/decoder_mpg123.c
diff options
context:
space:
mode:
Diffstat (limited to 'decoders/decoder_mpg123.c')
-rw-r--r--decoders/decoder_mpg123.c24
1 files changed, 18 insertions, 6 deletions
diff --git a/decoders/decoder_mpg123.c b/decoders/decoder_mpg123.c
index 50391f4..41d25c1 100644
--- a/decoders/decoder_mpg123.c
+++ b/decoders/decoder_mpg123.c
@@ -3,7 +3,7 @@
#include <mpg123.h>
#include <stdio.h>
-static gboolean mpg123_decoder_init(gpointer *data) {
+static gboolean mpg123_decoder_init(struct decoder *decoder) {
mpg123_handle *handle;
int error;
@@ -24,14 +24,14 @@ static gboolean mpg123_decoder_init(gpointer *data) {
mpg123_format_none(handle);
mpg123_format(handle, 44100, 2, MPG123_ENC_SIGNED_16);
- *data = handle;
+ decoder->data = handle;
return TRUE;
}
-static gssize mpg123_decoder_decode(gpointer data, GInputStream *input,
+static gssize mpg123_decoder_decode(struct decoder *decoder, GInputStream *input,
GOutputStream *output, GError **error) {
- mpg123_handle *handle = data;
+ mpg123_handle *handle = decoder->data;
gssize size;
int ret;
const int inbuf_size = 0x400*8;
@@ -55,6 +55,18 @@ static gssize mpg123_decoder_decode(gpointer data, GInputStream *input,
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);
+ decoder->rate = rate;
+ /* TODO: mpg123 uses native byte order, add endian check here */
+ /* assuming little endian for now... */
+ switch(enc) {
+ case MPG123_ENC_SIGNED_16:
+ decoder->format = AUDIO_FORMAT_S16LE;
+ break;
+ default:
+ *error = g_error_new(decoder_quark(), DECODER_CODE_ERROR, g_strdup("unknown audio format"));
+ return -1;
+ }
+ decoder->channels = channels;
}
if(ret != MPG123_OK && ret != MPG123_DONE && ret != MPG123_NEW_FORMAT
@@ -68,8 +80,8 @@ static gssize mpg123_decoder_decode(gpointer data, GInputStream *input,
return size;
}
-static void mpg123_decoder_close(gpointer data) {
- mpg123_handle *handle = data;
+static void mpg123_decoder_close(struct decoder *decoder) {
+ mpg123_handle *handle = decoder->data;
mpg123_close(handle);
mpg123_delete(handle);
}