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
This commit is contained in:
Alexander Traud
2015-08-28 22:42:23 +02:00
parent 5c713fdf18
commit b88c54fa4b
5 changed files with 139 additions and 72 deletions

View File

@@ -39,6 +39,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#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;x<LPC10_SAMPLES_PER_FRAME;x++)
tmpbuf[x] = (float)tmp->buf[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;
}