From 077adf48b8410740c1b002be353652d41d160aea Mon Sep 17 00:00:00 2001 From: Alexander Traud Date: Fri, 28 Aug 2015 22:42:23 +0200 Subject: translate: Fix transcoding while different in frame size. When Asterisk translates between codecs, each with a different frame size (for example between iLBC 30 and Speex-WB), too large frames were created by ast_trans_frameout. Now, ast_trans_frameout is called with the correct frame length, creating several frames when necessary. Affects all transcoding modules which used ast_trans_frameout: GSM, iLBC, LPC10, and Speex. ASTERISK-25353 #close Change-Id: I2e229569d73191d66a4e43fef35432db24000212 --- codecs/codec_lpc10.c | 41 ++++++++++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 13 deletions(-) (limited to 'codecs/codec_lpc10.c') diff --git a/codecs/codec_lpc10.c b/codecs/codec_lpc10.c index 49df8f753..e6dcf8c99 100644 --- a/codecs/codec_lpc10.c +++ b/codecs/codec_lpc10.c @@ -39,6 +39,7 @@ ASTERISK_REGISTER_FILE() #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 int lintolpc10_framein(struct ast_trans_pvt *pvt, struct ast_frame *f) 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; } -- cgit v1.2.3