summaryrefslogtreecommitdiff
path: root/transcode.c
blob: 6508b2817e3f8da30d52e67abfb098f91609703e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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);
}