--- codecs/codec_lpc10.c (Asterisk 13.5.0) +++ codecs/codec_lpc10.c (working copy) @@ -39,6 +39,7 @@ #include "asterisk/config.h" #include "asterisk/module.h" #include "asterisk/utils.h" +#include "asterisk/linkedlists.h" #include "lpc10/lpc10.h" @@ -160,31 +161,45 @@ static struct ast_frame *lintolpc10_frameout(struct ast_trans_pvt *pvt) { struct lpc10_coder_pvt *tmp = pvt->pvt; - int x; - int datalen = 0; /* output frame */ - int samples = 0; /* output samples */ - float tmpbuf[LPC10_SAMPLES_PER_FRAME]; - INT32 bits[LPC10_BITS_IN_COMPRESSED_FRAME]; /* XXX what ??? */ - /* We can't work on anything less than a frame in size */ - if (pvt->samples < LPC10_SAMPLES_PER_FRAME) - return NULL; - while (pvt->samples >= LPC10_SAMPLES_PER_FRAME) { + struct ast_frame *result = NULL; + struct ast_frame *last = NULL; + int samples = 0; /* output samples */ + + while (pvt->samples >= LPC10_SAMPLES_PER_FRAME) { + struct ast_frame *current; + float tmpbuf[LPC10_SAMPLES_PER_FRAME]; + INT32 bits[LPC10_BITS_IN_COMPRESSED_FRAME]; /* XXX what ??? */ + int x; + /* Encode a frame of data */ for (x=0;xbuf[x + samples] / 32768.0; lpc10_encode(tmpbuf, bits, tmp->lpc10.enc); - build_bits(pvt->outbuf.uc + datalen, bits); - datalen += LPC10_BYTES_IN_COMPRESSED_FRAME; + build_bits(pvt->outbuf.uc, bits); + samples += LPC10_SAMPLES_PER_FRAME; pvt->samples -= LPC10_SAMPLES_PER_FRAME; /* Use one of the two left over bits to record if this is a 22 or 23 ms frame... important for IAX use */ tmp->longer = 1 - tmp->longer; + + current = ast_trans_frameout(pvt, LPC10_BYTES_IN_COMPRESSED_FRAME, LPC10_SAMPLES_PER_FRAME); + if (!current) { + continue; + } else if (last) { + AST_LIST_NEXT(last, frame_list) = current; + } else { + result = current; + } + last = current; } + /* Move the data at the end of the buffer to the front */ - if (pvt->samples) + if (samples) { memmove(tmp->buf, tmp->buf + samples, pvt->samples * 2); - return ast_trans_frameout(pvt, datalen, samples); + } + + return result; }