[324] | 1 | //codecfilter_celt.c: |
---|
| 2 | |
---|
| 3 | #include "roard.h" |
---|
| 4 | |
---|
| 5 | int cf_celt_open(CODECFILTER_USERDATA_T * inst, int codec, |
---|
| 6 | struct roar_stream_server * info, |
---|
| 7 | struct roar_codecfilter * filter) { |
---|
| 8 | struct codecfilter_celt_inst * self = malloc(sizeof(struct codecfilter_celt_inst)); |
---|
[325] | 9 | struct roar_stream * s = (struct roar_stream *) info; |
---|
[324] | 10 | |
---|
| 11 | if ( !self ) |
---|
| 12 | return -1; |
---|
| 13 | |
---|
[325] | 14 | /* |
---|
| 15 | CELTMode * mode; |
---|
| 16 | CELTEncoder * encoder; |
---|
| 17 | CELTDecoder * decoder; |
---|
| 18 | int frame_size; |
---|
| 19 | int lookahead; |
---|
| 20 | int out_size; |
---|
| 21 | char * ibuf; |
---|
| 22 | char * obuf; |
---|
| 23 | char * rest; |
---|
| 24 | int s_buf; |
---|
| 25 | int f_rest; /-* how much is in rest? *-/ |
---|
| 26 | */ |
---|
| 27 | |
---|
[324] | 28 | self->stream = info; |
---|
[325] | 29 | self->frame_size = 256; |
---|
| 30 | self->lookahead = self->frame_size; |
---|
| 31 | self->encoder = NULL; |
---|
| 32 | self->decoder = NULL; |
---|
[326] | 33 | self->s_buf = s->info.channels * self->frame_size; |
---|
| 34 | self->ibuf = malloc(self->s_buf); |
---|
| 35 | self->obuf = malloc(self->s_buf); |
---|
| 36 | self->rest = malloc(self->s_buf); |
---|
| 37 | self->f_rest = 0; |
---|
| 38 | |
---|
| 39 | if ( !(self->ibuf && self->obuf && self->rest) ) { |
---|
| 40 | if ( self->ibuf ) |
---|
| 41 | free(self->ibuf); |
---|
| 42 | |
---|
| 43 | if ( self->obuf ) |
---|
| 44 | free(self->obuf); |
---|
| 45 | |
---|
| 46 | if ( self->rest ) |
---|
| 47 | free(self->rest); |
---|
| 48 | |
---|
| 49 | free(self); |
---|
| 50 | return -1; |
---|
| 51 | } |
---|
| 52 | |
---|
| 53 | self->mode = celt_mode_create(s->info.rate, s->info.channels, self->frame_size, self->lookahead, NULL); |
---|
[325] | 54 | |
---|
| 55 | if ( !self->mode ) { |
---|
| 56 | free(self); |
---|
| 57 | return -1; |
---|
| 58 | } |
---|
| 59 | |
---|
| 60 | if ( s->dir == ROAR_DIR_PLAY ) { |
---|
| 61 | self->decoder = celt_decoder_create(self->mode); |
---|
| 62 | } else if ( s->dir == ROAR_DIR_MONITOR ) { |
---|
| 63 | self->encoder = celt_encoder_create(self->mode); |
---|
| 64 | } else { |
---|
| 65 | celt_mode_destroy(self->mode); |
---|
| 66 | free(self); |
---|
| 67 | return -1; |
---|
| 68 | } |
---|
[324] | 69 | |
---|
| 70 | *inst = (CODECFILTER_USERDATA_T) self; |
---|
| 71 | |
---|
[326] | 72 | s->info.codec = ROAR_CODEC_DEFAULT; |
---|
| 73 | s->info.bits = 16; // CELT hardcoded |
---|
[324] | 74 | |
---|
| 75 | return 0; |
---|
| 76 | } |
---|
| 77 | |
---|
| 78 | int cf_celt_close(CODECFILTER_USERDATA_T inst) { |
---|
| 79 | struct codecfilter_celt_inst * self = (struct codecfilter_celt_inst *) inst; |
---|
| 80 | |
---|
| 81 | if ( !inst ) |
---|
| 82 | return -1; |
---|
| 83 | |
---|
[325] | 84 | if ( self->encoder ) |
---|
| 85 | celt_encoder_destroy(self->encoder); |
---|
| 86 | |
---|
| 87 | if ( self->decoder ) |
---|
| 88 | celt_decoder_destroy(self->decoder); |
---|
| 89 | |
---|
| 90 | if ( self->mode ) |
---|
| 91 | celt_mode_destroy(self->mode); |
---|
| 92 | |
---|
[324] | 93 | free(inst); |
---|
| 94 | return 0; |
---|
| 95 | } |
---|
| 96 | |
---|
| 97 | int cf_celt_read(CODECFILTER_USERDATA_T inst, char * buf, int len) { |
---|
| 98 | struct codecfilter_celt_inst * self = (struct codecfilter_celt_inst *) inst; |
---|
| 99 | |
---|
| 100 | return 0; |
---|
| 101 | } |
---|
| 102 | |
---|
| 103 | int cf_celt_write(CODECFILTER_USERDATA_T inst, char * buf, int len) { |
---|
| 104 | struct codecfilter_celt_inst * self = (struct codecfilter_celt_inst *) inst; |
---|
| 105 | |
---|
| 106 | return 0; |
---|
| 107 | } |
---|
| 108 | |
---|
| 109 | //ll |
---|