summaryrefslogtreecommitdiff
path: root/codecs/codec_gsm.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 10:01:48 -0500
commitb88c54fa4bd537bde46519abb95e30a5f96673ac (patch)
tree84318723a2ab5ce06f0880b3f0cbb144f8e8e3cd /codecs/codec_gsm.c
parent5c713fdf18ffa934e0cac8ddb29e4ad95a68200b (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_gsm.c')
-rw-r--r--codecs/codec_gsm.c29
1 files changed, 20 insertions, 9 deletions
diff --git a/codecs/codec_gsm.c b/codecs/codec_gsm.c
index 8cb49430f..a18dc0abe 100644
--- a/codecs/codec_gsm.c
+++ b/codecs/codec_gsm.c
@@ -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"
#ifdef HAVE_GSM_HEADER
#include "gsm.h"
@@ -139,25 +140,35 @@ static int lintogsm_framein(struct ast_trans_pvt *pvt, struct ast_frame *f)
static struct ast_frame *lintogsm_frameout(struct ast_trans_pvt *pvt)
{
struct gsm_translator_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 < GSM_SAMPLES)
- return NULL;
while (pvt->samples >= GSM_SAMPLES) {
+ struct ast_frame *current;
+
/* Encode a frame of data */
- gsm_encode(tmp->gsm, tmp->buf + samples, (gsm_byte *) pvt->outbuf.c + datalen);
- datalen += GSM_FRAME_LEN;
+ gsm_encode(tmp->gsm, tmp->buf + samples, (gsm_byte *) pvt->outbuf.c);
samples += GSM_SAMPLES;
pvt->samples -= GSM_SAMPLES;
+
+ current = ast_trans_frameout(pvt, GSM_FRAME_LEN, GSM_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 void gsm_destroy_stuff(struct ast_trans_pvt *pvt)