summaryrefslogtreecommitdiff
path: root/codecs/codec_ilbc.c
diff options
context:
space:
mode:
authorAlexander Traud <pabstraud@compuserve.com>2015-08-28 22:42:23 +0200
committerAlexander Traud <pabstraud@compuserve.com>2015-09-17 16:58:57 +0200
commit077adf48b8410740c1b002be353652d41d160aea (patch)
tree2a89e570e63c8c8c98b55bc149527ca18bd517d4 /codecs/codec_ilbc.c
parent229b95d253e7e3bf51cd431f021cff7993655dc7 (diff)
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
Diffstat (limited to 'codecs/codec_ilbc.c')
-rw-r--r--codecs/codec_ilbc.c28
1 files changed, 19 insertions, 9 deletions
diff --git a/codecs/codec_ilbc.c b/codecs/codec_ilbc.c
index 8247f2473..3e480e8fd 100644
--- a/codecs/codec_ilbc.c
+++ b/codecs/codec_ilbc.c
@@ -37,6 +37,7 @@ ASTERISK_REGISTER_FILE()
#include "asterisk/translate.h"
#include "asterisk/module.h"
#include "asterisk/utils.h"
+#include "asterisk/linkedlists.h"
#ifdef ILBC_WEBRTC
#include <ilbc.h>
@@ -150,31 +151,40 @@ static int lintoilbc_framein(struct ast_trans_pvt *pvt, struct ast_frame *f)
static struct ast_frame *lintoilbc_frameout(struct ast_trans_pvt *pvt)
{
struct ilbc_coder_pvt *tmp = pvt->pvt;
- int datalen = 0;
- int samples = 0;
+ struct ast_frame *result = NULL;
+ struct ast_frame *last = NULL;
+ int samples = 0; /* output samples */
- /* We can't work on anything less than a frame in size */
- if (pvt->samples < ILBC_SAMPLES)
- return NULL;
while (pvt->samples >= ILBC_SAMPLES) {
+ struct ast_frame *current;
ilbc_block tmpf[ILBC_SAMPLES];
int i;
/* Encode a frame of data */
for (i = 0 ; i < ILBC_SAMPLES ; i++)
tmpf[i] = tmp->buf[samples + i];
- iLBC_encode( (ilbc_bytes*)pvt->outbuf.BUF_TYPE + datalen, tmpf, &tmp->enc);
+ iLBC_encode((ilbc_bytes *) pvt->outbuf.BUF_TYPE, tmpf, &tmp->enc);
- datalen += ILBC_FRAME_LEN;
samples += ILBC_SAMPLES;
pvt->samples -= ILBC_SAMPLES;
+
+ current = ast_trans_frameout(pvt, ILBC_FRAME_LEN, ILBC_SAMPLES);
+ 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;
}
static struct ast_translator ilbctolin = {