summaryrefslogtreecommitdiff
path: root/transcode.c
diff options
context:
space:
mode:
Diffstat (limited to 'transcode.c')
-rw-r--r--transcode.c52
1 files changed, 24 insertions, 28 deletions
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);*/
}