diff options
-rw-r--r-- | transcode.c | 38 | ||||
-rw-r--r-- | transcode.h | 12 |
2 files changed, 50 insertions, 0 deletions
diff --git a/transcode.c b/transcode.c new file mode 100644 index 0000000..6508b28 --- /dev/null +++ b/transcode.c @@ -0,0 +1,38 @@ +#include "transcode.h" +#include "decode_converter.h" +#include "encode_converter.h" + +#include <glib.h> + +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); + + if(size == -1) { + if(error) { + g_warning(error->message); + g_error_free(error); + } else { + g_debug("g_output_stream_splice returned -1, but error is NULL!"); + } + } + + g_debug("transcode ended"); + + g_object_unref(encoded_stream); + g_object_unref(ec); + + g_object_unref(decoded_stream); + g_object_unref(dc); +} diff --git a/transcode.h b/transcode.h new file mode 100644 index 0000000..69f19f3 --- /dev/null +++ b/transcode.h @@ -0,0 +1,12 @@ +#ifndef _TRANSCODE_H_ +#define _TRANSCODE_H_ + +#include "decoder.h" +#include "encoder.h" + +#include <gio/gio.h> + +void transcode(GInputStream *input, const struct decoder_plugin *decoder, + GOutputStream *output, const struct encoder_plugin *encoder); + +#endif |