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
44
45
46
47
|
#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, GError **error) {
lame_global_flags *gfp = data;
const int inbuf_size = 0x400*8;
const int outbuf_size = 0x400*8;
unsigned char inbuf[inbuf_size];
unsigned char 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);
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) {
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,
};
|