summaryrefslogtreecommitdiff
path: root/codecs/codec_lpc10.c
diff options
context:
space:
mode:
Diffstat (limited to 'codecs/codec_lpc10.c')
-rw-r--r--codecs/codec_lpc10.c41
1 files changed, 28 insertions, 13 deletions
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;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;
}