| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
#include "codec_ilbc.h" |
| 16 |
#include "iaxclient_lib.h" |
| 17 |
#include "iLBC/iLBC_encode.h" |
| 18 |
#include "iLBC/iLBC_decode.h" |
| 19 |
|
| 20 |
|
| 21 |
static void destroy ( struct iaxc_audio_codec *c) { |
| 22 |
free(c->encstate); |
| 23 |
free(c->decstate); |
| 24 |
free(c); |
| 25 |
} |
| 26 |
|
| 27 |
|
| 28 |
static int decode ( struct iaxc_audio_codec *c, |
| 29 |
int *inlen, char *in, int *outlen, short *out ) { |
| 30 |
|
| 31 |
float fbuf[240]; |
| 32 |
int i; |
| 33 |
|
| 34 |
if(*inlen == 0) { |
| 35 |
|
| 36 |
iLBC_decode(fbuf, NULL, c->decstate, 0); |
| 37 |
for(i=0;i<240;i++) |
| 38 |
out[i] = fbuf[i]; |
| 39 |
*outlen -= 240; |
| 40 |
return 0; |
| 41 |
} |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
if( (*inlen < 50) || (*outlen < 240) ) { |
| 46 |
fprintf(stderr, "codec_ilbc: inlen = %d outlen= %d\n",*inlen,*outlen); |
| 47 |
return -1; |
| 48 |
} |
| 49 |
|
| 50 |
while( (*inlen >= 50) && (*outlen >= 240) ) { |
| 51 |
iLBC_decode(fbuf, in, c->decstate, 1); |
| 52 |
for(i=0;i<240;i++) |
| 53 |
out[i] = fbuf[i]; |
| 54 |
|
| 55 |
out += 240; |
| 56 |
*outlen -= 240; |
| 57 |
in += 50; |
| 58 |
*inlen -= 50; |
| 59 |
} |
| 60 |
|
| 61 |
return 0; |
| 62 |
} |
| 63 |
|
| 64 |
static int encode ( struct iaxc_audio_codec *c, |
| 65 |
int *inlen, short *in, int *outlen, char *out ) { |
| 66 |
|
| 67 |
float fbuf[240]; |
| 68 |
int i; |
| 69 |
|
| 70 |
while( (*inlen >= 240) && (*outlen >= 50) ) { |
| 71 |
|
| 72 |
for(i=0;i<240;i++) |
| 73 |
fbuf[i] = in[i]; |
| 74 |
|
| 75 |
iLBC_encode(out,fbuf, c->encstate); |
| 76 |
|
| 77 |
out += 50; |
| 78 |
*outlen -= 50; |
| 79 |
in += 240; |
| 80 |
*inlen -= 240; |
| 81 |
} |
| 82 |
|
| 83 |
return 0; |
| 84 |
} |
| 85 |
|
| 86 |
struct iaxc_audio_codec *codec_audio_ilbc_new() { |
| 87 |
struct iaxc_audio_codec *c = calloc(sizeof(struct iaxc_audio_codec),1); |
| 88 |
|
| 89 |
|
| 90 |
if(!c) return c; |
| 91 |
|
| 92 |
strcpy(c->name,"iLBC"); |
| 93 |
c->format = IAXC_FORMAT_ILBC; |
| 94 |
c->encode = encode; |
| 95 |
c->decode = decode; |
| 96 |
c->destroy = destroy; |
| 97 |
|
| 98 |
c->minimum_frame_size = 240; |
| 99 |
|
| 100 |
c->encstate = calloc(sizeof(iLBC_Enc_Inst_t),1); |
| 101 |
c->decstate = calloc(sizeof(iLBC_Dec_Inst_t),1); |
| 102 |
|
| 103 |
|
| 104 |
if(!(c->encstate && c->decstate)) |
| 105 |
return NULL; |
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
initEncode(c->encstate, 30); |
| 111 |
initDecode(c->decstate, 30, 1); |
| 112 |
|
| 113 |
return c; |
| 114 |
} |
| 115 |
|