1 | //codecfilter_speex.c: |
---|
2 | |
---|
3 | #include "roard.h" |
---|
4 | #ifdef ROAR_HAVE_LIBSPEEX |
---|
5 | |
---|
6 | int cf_speex_open(CODECFILTER_USERDATA_T * inst, int codec, |
---|
7 | struct roar_stream_server * info, |
---|
8 | struct roar_codecfilter * filter) { |
---|
9 | struct codecfilter_speex_inst * self = malloc(sizeof(struct codecfilter_speex_inst)); |
---|
10 | |
---|
11 | *inst = NULL; |
---|
12 | |
---|
13 | if (!self) |
---|
14 | return -1; |
---|
15 | |
---|
16 | self->encoder = NULL; |
---|
17 | self->decoder = NULL; |
---|
18 | |
---|
19 | self->stream = info; |
---|
20 | |
---|
21 | speex_bits_init(&(self->bits)); |
---|
22 | |
---|
23 | *inst = (void*) self; |
---|
24 | |
---|
25 | return 0; |
---|
26 | } |
---|
27 | |
---|
28 | int cf_speex_close(CODECFILTER_USERDATA_T inst) { |
---|
29 | struct codecfilter_speex_inst * self = (struct codecfilter_speex_inst *) inst; |
---|
30 | |
---|
31 | if (!self) |
---|
32 | return -1; |
---|
33 | |
---|
34 | if ( self->encoder ) |
---|
35 | speex_encoder_destroy(self->decoder); |
---|
36 | |
---|
37 | self->encoder = NULL; |
---|
38 | |
---|
39 | if ( self->decoder ) |
---|
40 | speex_decoder_destroy(self->decoder); |
---|
41 | |
---|
42 | self->decoder = NULL; |
---|
43 | |
---|
44 | speex_bits_destroy(&(self->bits)); |
---|
45 | |
---|
46 | free((void*)self); |
---|
47 | |
---|
48 | return 0; |
---|
49 | } |
---|
50 | |
---|
51 | int cf_speex_read(CODECFILTER_USERDATA_T inst, char * buf, int len) { |
---|
52 | struct codecfilter_speex_inst * self = (struct codecfilter_speex_inst *) inst; |
---|
53 | struct roar_stream * s = (struct roar_stream *) self->stream; |
---|
54 | int mode; |
---|
55 | uint16_t ui; |
---|
56 | |
---|
57 | if ( ! self->decoder ) { |
---|
58 | if ( read(s->fh, &ui, 2) != 2 ) |
---|
59 | return 0; |
---|
60 | |
---|
61 | mode = ntohs(ui); |
---|
62 | |
---|
63 | if ( mode == ROAR_SPEEX_MODE_NB ) { |
---|
64 | self->decoder = speex_decoder_init(&speex_nb_mode); |
---|
65 | } else if ( mode == ROAR_SPEEX_MODE_WB ) { |
---|
66 | self->decoder = speex_decoder_init(&speex_wb_mode); |
---|
67 | } else if ( mode == ROAR_SPEEX_MODE_UWB ) { |
---|
68 | self->decoder = speex_decoder_init(&speex_uwb_mode); |
---|
69 | } else { |
---|
70 | return 0; |
---|
71 | } |
---|
72 | } |
---|
73 | |
---|
74 | return -1; |
---|
75 | } |
---|
76 | |
---|
77 | int cf_speex_write(CODECFILTER_USERDATA_T inst, char * buf, int len) { |
---|
78 | struct codecfilter_speex_inst * self = (struct codecfilter_speex_inst *) inst; |
---|
79 | |
---|
80 | return -1; |
---|
81 | } |
---|
82 | |
---|
83 | #endif |
---|
84 | |
---|
85 | //ll |
---|