summaryrefslogtreecommitdiff
path: root/encoders/encoder_lame.c
blob: b28e52e6d9b5d0e42c628cb9874b769cf321e2c5 (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
39
40
41
42
43
#include "encoder.h"

#include <lame/lame.h>

static gboolean lame_encoder_init(gpointer *data) {
	lame_global_flags *gfp;

	gfp = lame_init();
	int ret = lame_init_params(gfp);
	*data = gfp;

	return (ret >= 0 ? TRUE : FALSE);
}

static gssize lame_encoder_encode(gpointer data, GInputStream *input,
			GOutputStream *output) {
	lame_global_flags *gfp = data;
	const inbuf_size = 0x400*8;
	const outbuf_size = 0x400*8;
	gchar inbuf[inbuf_size];
	gchar outbuf[inbuf_size];

	int inbuf_read = g_input_stream_read(input, inbuf, inbuf_size, NULL, NULL);

	int ret = lame_encode_buffer_interleaved(gfp, (short*)inbuf, inbuf_read / 4,
			outbuf, outbuf_size);

	g_output_stream_write(output, outbuf, ret, NULL, NULL);

	return ret;
}

static void lame_encoder_close(gpointer data) {
	lame_global_flags *gfp = data;
	lame_close(gfp);
}

const struct encoder_plugin encoder_lame_encoder = {
	.name = "lame",
	.init = lame_encoder_init,
	.encode = lame_encoder_encode,
	.close = lame_encoder_close,
};