summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--decoder.c4
-rw-r--r--decoder.h13
-rw-r--r--decoders/decoder_mpg123.c6
-rw-r--r--encoder.c4
-rw-r--r--encoder.h13
-rw-r--r--encoders/encoder_lame.c10
-rw-r--r--transcode.c52
7 files changed, 61 insertions, 41 deletions
diff --git a/decoder.c b/decoder.c
index 1746467..85e2203 100644
--- a/decoder.c
+++ b/decoder.c
@@ -5,8 +5,8 @@ gboolean decoder_init(struct decoder *decoder) {
}
gssize decoder_decode(struct decoder *decoder, GInputStream *input,
- GOutputStream *output) {
- return decoder->decoder->decode(decoder->data, input, output);
+ GOutputStream *output, GError **error) {
+ return decoder->decoder->decode(decoder->data, input, output, error);
}
void decoder_close(struct decoder *decoder) {
diff --git a/decoder.h b/decoder.h
index 4464a50..e992af9 100644
--- a/decoder.h
+++ b/decoder.h
@@ -10,7 +10,7 @@ struct decoder_plugin {
gboolean (*init)(gpointer *data);
gssize (*decode)(gpointer data, GInputStream *input,
- GOutputStream *output);
+ GOutputStream *output, GError **error);
void (*close)(gpointer data);
};
@@ -22,10 +22,19 @@ struct decoder {
gboolean decoder_init(struct decoder *decoder);
gssize decoder_decode(struct decoder *decoder, GInputStream *input,
- GOutputStream *output);
+ GOutputStream *output, GError **error);
void decoder_close(struct decoder *decoder);
const struct decoder_plugin *decoder_get(const gchar *name);
const struct decoder_plugin *decoder_find(const gchar *filename);
+static inline GQuark decoder_quark() {
+ return g_quark_from_string("decoder");
+}
+
+enum {
+ DECODER_CODE_ERROR = 0,
+ DECODER_CODE_DONE,
+};
+
#endif
diff --git a/decoders/decoder_mpg123.c b/decoders/decoder_mpg123.c
index ea263f5..50391f4 100644
--- a/decoders/decoder_mpg123.c
+++ b/decoders/decoder_mpg123.c
@@ -30,7 +30,7 @@ static gboolean mpg123_decoder_init(gpointer *data) {
}
static gssize mpg123_decoder_decode(gpointer data, GInputStream *input,
- GOutputStream *output) {
+ GOutputStream *output, GError **error) {
mpg123_handle *handle = data;
gssize size;
int ret;
@@ -43,7 +43,7 @@ static gssize mpg123_decoder_decode(gpointer data, GInputStream *input,
if(mpg123_feed(handle, inbuf, inbuf_read) != MPG123_OK) {
g_debug("asdfasdf");
- g_warning(mpg123_strerror(handle));
+ *error = g_error_new(decoder_quark(), DECODER_CODE_ERROR, mpg123_strerror(handle));
return -1;
}
@@ -59,7 +59,7 @@ static gssize mpg123_decoder_decode(gpointer data, GInputStream *input,
if(ret != MPG123_OK && ret != MPG123_DONE && ret != MPG123_NEW_FORMAT
&& ret != MPG123_NEED_MORE) {
- g_warning(mpg123_plain_strerror(ret));
+ *error = g_error_new(decoder_quark(), DECODER_CODE_ERROR, mpg123_plain_strerror(ret));
return -1;
}
diff --git a/encoder.c b/encoder.c
index d039c9c..2af1de9 100644
--- a/encoder.c
+++ b/encoder.c
@@ -5,8 +5,8 @@ gboolean encoder_init(struct encoder *encoder) {
}
gssize encoder_encode(struct encoder *encoder, GInputStream *input,
- GOutputStream *output) {
- return encoder->encoder->encode(encoder->data, input, output);
+ GOutputStream *output, GError **error) {
+ return encoder->encoder->encode(encoder->data, input, output, error);
}
void encoder_close(struct encoder *encoder) {
diff --git a/encoder.h b/encoder.h
index c57eead..0ff21b2 100644
--- a/encoder.h
+++ b/encoder.h
@@ -9,7 +9,7 @@ struct encoder_plugin {
gboolean (*init)(gpointer *data);
gssize (*encode)(gpointer data, GInputStream *input,
- GOutputStream *output);
+ GOutputStream *output, GError **error);
void (*close)(gpointer data);
};
@@ -21,8 +21,17 @@ struct encoder {
gboolean encoder_init(struct encoder *encoder);
gssize encoder_encode(struct encoder *encoder, GInputStream *input,
- GOutputStream *output);
+ GOutputStream *output, GError **error);
void encoder_close(struct encoder *encoder);
const struct encoder_plugin *encoder_get(const gchar *name);
+static inline GQuark encoder_quark() {
+ return g_quark_from_string("encoder");
+}
+
+enum {
+ ENCODER_CODE_ERROR = 0,
+ ENCODER_CODE_DONE,
+};
+
#endif
diff --git a/encoders/encoder_lame.c b/encoders/encoder_lame.c
index bf3baff..0836d17 100644
--- a/encoders/encoder_lame.c
+++ b/encoders/encoder_lame.c
@@ -13,7 +13,7 @@ static gboolean lame_encoder_init(gpointer *data) {
}
static gssize lame_encoder_encode(gpointer data, GInputStream *input,
- GOutputStream *output) {
+ GOutputStream *output, GError **error) {
lame_global_flags *gfp = data;
const int inbuf_size = 0x400*8;
const int outbuf_size = 0x400*8;
@@ -25,7 +25,13 @@ static gssize lame_encoder_encode(gpointer data, GInputStream *input,
int ret = lame_encode_buffer_interleaved(gfp, (short*)inbuf, inbuf_read / 4,
outbuf, outbuf_size);
- return g_output_stream_write(output, outbuf, ret, NULL, NULL);
+ ret = g_output_stream_write(output, outbuf, ret, NULL, error);
+
+ if(ret == 0) {
+ *error = g_error_new(encoder_quark(), ENCODER_CODE_DONE, "encoding done");
+ }
+
+ return ret;
}
static void lame_encoder_close(gpointer data) {
diff --git a/transcode.c b/transcode.c
index c02f137..9bef8e7 100644
--- a/transcode.c
+++ b/transcode.c
@@ -6,17 +6,6 @@ void transcode(GInputStream *input, const struct decoder_plugin *_decoder,
GOutputStream *output, const struct encoder_plugin *_encoder) {
GError *error = NULL;
- /*DecodeConverter *dc = decode_converter_new(decoder);
- GInputStream *decoded_stream = g_converter_input_stream_new(input,
- (GConverter*)dc);
-
- EncodeConverter *ec = encode_converter_new(encoder);
- GInputStream *encoded_stream = g_converter_input_stream_new(decoded_stream,
- (GConverter*)ec);
-
- gssize size = g_output_stream_splice(output, encoded_stream,
- G_OUTPUT_STREAM_SPLICE_NONE, NULL, &error);*/
-
gboolean decode_done = FALSE, encode_done = FALSE;
struct decoder *decoder = g_new0(struct decoder, 1);
struct encoder *encoder = g_new0(struct encoder, 1);
@@ -32,9 +21,16 @@ void transcode(GInputStream *input, const struct decoder_plugin *_decoder,
/* holds decoded audio from decoder */
GOutputStream *decoded_out = g_memory_output_stream_new(NULL, 0, g_realloc, g_free);
- if(decode_done == FALSE && decoder_decode(decoder, input, decoded_out) <= 0) {
- g_debug("decoding done");
- decode_done = TRUE;
+ if(decode_done == FALSE && decoder_decode(decoder, input, decoded_out, &error) <= 0 && error != NULL) {
+ if(error->code == DECODER_CODE_DONE) {
+ decode_done = TRUE;
+ } else {
+ g_warning(error->message);
+ g_object_unref(decoded_out);
+ break;
+ }
+ g_error_free(error);
+ error = NULL;
}
/* temp variables */
@@ -48,27 +44,27 @@ void transcode(GInputStream *input, const struct decoder_plugin *_decoder,
g_object_unref(decoded_out);
- if(encode_done == FALSE && encoder_encode(encoder, decoded_in, output) <= 0) {
- g_debug("encoding done");
- encode_done = TRUE;
+ if(encode_done == FALSE && encoder_encode(encoder, decoded_in, output, &error) <= 0 && error != NULL) {
+ if(error->code == ENCODER_CODE_DONE) {
+ /* assume the encoder doesn't have enough data to continue
+ * if the decoder isn't done yet
+ */
+ encode_done = decode_done;
+ } else {
+ g_warning(error->message);
+ break;
+ }
+ g_error_free(error);
+ error = NULL;
}
}
- g_object_unref(decoded_in);
+ g_debug("transcoding done");
- /*if(size == -1 && error != NULL) {
- g_warning(error->message);
- g_error_free(error);
- }*/
+ g_object_unref(decoded_in);
decoder_close(decoder);
encoder_close(encoder);
g_free(decoder);
g_free(encoder);
-
- /*g_object_unref(encoded_stream);
- g_object_unref(ec);
-
- g_object_unref(decoded_stream);
- g_object_unref(dc);*/
}