2 * iaxclient: a cross-platform IAX softphone library
5 * Copyright (C) 2003-2006, Horizon Wimba, Inc.
6 * Copyright (C) 2007, Wimba, Inc.
9 * Steve Kann <stevek@stevek.com>
11 * This program is free software, distributed under the terms of
12 * the GNU Lesser (Library) General Public License.
15 #include "codec_gsm.h"
16 #include "iaxclient_lib.h"
25 static void destroy ( struct iaxc_audio_codec *c) {
27 struct state * encstate = (struct state *) c->encstate;
28 struct state * decstate = (struct state *) c->decstate;
30 gsm_destroy(encstate->gsmstate);
31 gsm_destroy(decstate->gsmstate);
38 static int decode ( struct iaxc_audio_codec *c,
39 int *inlen, unsigned char *in, int *outlen, short *out ) {
40 struct state * decstate = (struct state *) c->decstate;
42 /* use generic interpolation */
45 if(*outlen < interp_len) interp_len = *outlen;
46 plc_fillin(&decstate->plc,out,interp_len);
47 *outlen -= interp_len;
51 /* need to decode minimum of 33 bytes to 160 byte output */
52 while( (*inlen >= 33) && (*outlen >= 160) ) {
53 if(gsm_decode(decstate->gsmstate, in, out))
55 fprintf(stderr, "codec_gsm: gsm_decode returned error\n");
59 /* push decoded data to interpolation buffer */
60 plc_rx(&decstate->plc,out,160);
62 /* we used 33 bytes of input, and 160 bytes of output */
72 static int encode ( struct iaxc_audio_codec *c,
73 int *inlen, short *in, int *outlen, unsigned char *out ) {
75 struct state * encstate = (struct state *) c->encstate;
78 /* need to encode minimum of 160 bytes to 33 byte output */
79 while( (*inlen >= 160) && (*outlen >= 33) ) {
80 gsm_encode(encstate->gsmstate, in, out);
82 /* we used 160 bytes of input, and 33 bytes of output */
92 struct iaxc_audio_codec *codec_audio_gsm_new() {
94 struct state * encstate;
95 struct state * decstate;
96 struct iaxc_audio_codec *c = (struct iaxc_audio_codec *)calloc(sizeof(struct iaxc_audio_codec),1);
101 strcpy(c->name,"gsm 06.10");
102 c->format = IAXC_FORMAT_GSM;
105 c->destroy = destroy;
107 c->minimum_frame_size = 160;
109 c->encstate = calloc(sizeof(struct state),1);
110 c->decstate = calloc(sizeof(struct state),1);
112 /* leaks a bit on no-memory */
113 if(!(c->encstate && c->decstate))
116 encstate = (struct state *) c->encstate;
117 decstate = (struct state *) c->decstate;
119 encstate->gsmstate = gsm_create();
120 decstate->gsmstate = gsm_create();
122 if(!(encstate->gsmstate && decstate->gsmstate))