Skip to content
Snippets Groups Projects
Commit fcba224b authored by Mark Spencer's avatar Mark Spencer
Browse files

Version 0.1.7 from FTP

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@237 65c4cc65-6c06-0410-ace0-fbb531ad65f3
parent 7157261b
Branches
Tags
No related merge requests found
...@@ -75,7 +75,7 @@ struct g723_encoder_pvt { ...@@ -75,7 +75,7 @@ struct g723_encoder_pvt {
/* Space to build offset */ /* Space to build offset */
char offset[AST_FRIENDLY_OFFSET]; char offset[AST_FRIENDLY_OFFSET];
/* Buffer for our outgoing frame */ /* Buffer for our outgoing frame */
char outbuf[24]; char outbuf[8000];
/* Enough to store a full second */ /* Enough to store a full second */
short buf[8000]; short buf[8000];
int tail; int tail;
...@@ -185,27 +185,60 @@ static struct ast_frame *g723tolin_frameout(struct ast_translator_pvt *pvt) ...@@ -185,27 +185,60 @@ static struct ast_frame *g723tolin_frameout(struct ast_translator_pvt *pvt)
return &tmp->f; return &tmp->f;
} }
static int g723_len(unsigned char buf)
{
switch(buf & TYPE_MASK) {
case TYPE_MASK:
case TYPE_SILENCE:
return 4;
break;
case TYPE_HIGH:
return 24;
break;
case TYPE_LOW:
return 20;
break;
default:
ast_log(LOG_WARNING, "Badly encoded frame (%d)\n", buf & TYPE_MASK);
}
return -1;
}
static int g723tolin_framein(struct ast_translator_pvt *pvt, struct ast_frame *f) static int g723tolin_framein(struct ast_translator_pvt *pvt, struct ast_frame *f)
{ {
struct g723_decoder_pvt *tmp = (struct g723_decoder_pvt *)pvt; struct g723_decoder_pvt *tmp = (struct g723_decoder_pvt *)pvt;
int len = 0;
int res;
#ifdef ANNEX_B #ifdef ANNEX_B
FLOAT tmpdata[Frame]; FLOAT tmpdata[Frame];
int x; int x;
#endif #endif
/* Assuming there's space left, decode into the current buffer at while(len < f->datalen) {
the tail location */ /* Assuming there's space left, decode into the current buffer at
if (tmp->tail + Frame < sizeof(tmp->buf)/2) { the tail location */
res = g723_len(((unsigned char *)f->data + len)[0]);
if (res < 0) {
ast_log(LOG_WARNING, "Invalid data\n");
return -1;
}
if (res + len > f->datalen) {
ast_log(LOG_WARNING, "Measured length exceeds frame length\n");
return -1;
}
if (tmp->tail + Frame < sizeof(tmp->buf)/2) {
#ifdef ANNEX_B #ifdef ANNEX_B
Decod(&tmp->dec, tmpdata, f->data, 0); Decod(&tmp->dec, tmpdata, f->data + len, 0);
for (x=0;x<Frame;x++) for (x=0;x<Frame;x++)
(tmp->buf + tmp->tail)[x] = (short)(tmpdata[x]); (tmp->buf + tmp->tail)[x] = (short)(tmpdata[x]);
#else #else
Decod(&tmp->dec, tmp->buf + tmp->tail, f->data, 0); Decod(&tmp->dec, tmp->buf + tmp->tail, f->data + len, 0);
#endif #endif
tmp->tail+=Frame; tmp->tail+=Frame;
} else { } else {
ast_log(LOG_WARNING, "Out of buffer space\n"); ast_log(LOG_WARNING, "Out of buffer space\n");
return -1; return -1;
}
len += res;
} }
return 0; return 0;
} }
...@@ -234,43 +267,39 @@ static struct ast_frame *lintog723_frameout(struct ast_translator_pvt *pvt) ...@@ -234,43 +267,39 @@ static struct ast_frame *lintog723_frameout(struct ast_translator_pvt *pvt)
int x; int x;
FLOAT tmpdata[Frame]; FLOAT tmpdata[Frame];
#endif #endif
int cnt=0;
/* We can't work on anything less than a frame in size */ /* We can't work on anything less than a frame in size */
if (tmp->tail < Frame) if (tmp->tail < Frame)
return NULL; return NULL;
/* Encode a frame of data */
#ifdef ANNEX_B
for (x=0;x<Frame;x++)
tmpdata[x] = tmp->buf[x];
Coder(&tmp->cod, tmpdata, tmp->outbuf);
#else
Coder(&tmp->cod, tmp->buf, tmp->outbuf);
#endif
tmp->f.frametype = AST_FRAME_VOICE; tmp->f.frametype = AST_FRAME_VOICE;
tmp->f.subclass = AST_FORMAT_G723_1; tmp->f.subclass = AST_FORMAT_G723_1;
/* Assume 8000 Hz */
tmp->f.timelen = 30;
tmp->f.mallocd = 0;
tmp->f.offset = AST_FRIENDLY_OFFSET; tmp->f.offset = AST_FRIENDLY_OFFSET;
tmp->f.src = __PRETTY_FUNCTION__; tmp->f.src = __PRETTY_FUNCTION__;
tmp->f.data = tmp->outbuf; tmp->f.timelen = 0;
switch(tmp->outbuf[0] & TYPE_MASK) { tmp->f.mallocd = 0;
case TYPE_MASK: while(tmp->tail >= Frame) {
case TYPE_SILENCE: /* Encode a frame of data */
tmp->f.datalen = 4; if (cnt + 24 >= sizeof(tmp->outbuf)) {
break; ast_log(LOG_WARNING, "Out of buffer space\n");
case TYPE_HIGH: return NULL;
tmp->f.datalen = 24; }
break; #ifdef ANNEX_B
case TYPE_LOW: for (x=0;x<Frame;x++)
tmp->f.datalen = 20; tmpdata[x] = tmp->buf[x];
break; Coder(&tmp->cod, tmpdata, tmp->outbuf + cnt);
default: #else
ast_log(LOG_WARNING, "Badly encoded frame (%d)\n", tmp->outbuf[0] & TYPE_MASK); Coder(&tmp->cod, tmp->buf, tmp->outbuf + cnt);
#endif
/* Assume 8000 Hz */
tmp->f.timelen += 30;
cnt += g723_len(tmp->outbuf[0]);
tmp->tail -= Frame;
/* Move the data at the end of the buffer to the front */
if (tmp->tail)
memmove(tmp->buf, tmp->buf + Frame, tmp->tail * 2);
} }
tmp->tail -= Frame; tmp->f.datalen = cnt;
/* Move the data at the end of the buffer to the front */ tmp->f.data = tmp->outbuf;
if (tmp->tail)
memmove(tmp->buf, tmp->buf + Frame, tmp->tail * 2);
#if 0 #if 0
/* Save to a g723 sample output file... */ /* Save to a g723 sample output file... */
{ {
...@@ -360,3 +389,8 @@ int usecount(void) ...@@ -360,3 +389,8 @@ int usecount(void)
STANDARD_USECOUNT(res); STANDARD_USECOUNT(res);
return res; return res;
} }
char *key()
{
return ASTERISK_GPL_KEY;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment