mirror of
https://github.com/asterisk/asterisk.git
synced 2025-10-21 12:30:41 +00:00
Fix various issues in codec_g722.
- The most common fix being made here is to fix all of the places where the number of output samples and output bytes gets updated in the translator state structure. - Fix a number of other places where the number of samples provided as an initialization value to a struct was incorrect. git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@97975 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -98,11 +98,30 @@ static int g722tolin_framein(struct ast_trans_pvt *pvt, struct ast_frame *f)
|
|||||||
{
|
{
|
||||||
struct g722_decoder_pvt *tmp = pvt->pvt;
|
struct g722_decoder_pvt *tmp = pvt->pvt;
|
||||||
unsigned char *src = f->data;
|
unsigned char *src = f->data;
|
||||||
int16_t *dst = (int16_t *) pvt->outbuf + pvt->samples;
|
int out_samples;
|
||||||
|
|
||||||
g722_decode(&tmp->g722, dst, src, f->samples);
|
out_samples = g722_decode(&tmp->g722, (int16_t *) &pvt->outbuf[pvt->samples * sizeof(int16_t)],
|
||||||
pvt->samples += f->samples;
|
src, f->samples);
|
||||||
pvt->datalen += 2 * f->samples;
|
|
||||||
|
pvt->samples += out_samples;
|
||||||
|
|
||||||
|
pvt->datalen += (out_samples * sizeof(int16_t));
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int g722tolin16_framein(struct ast_trans_pvt *pvt, struct ast_frame *f)
|
||||||
|
{
|
||||||
|
struct g722_decoder_pvt *tmp = pvt->pvt;
|
||||||
|
int out_samples;
|
||||||
|
|
||||||
|
out_samples = g722_decode(&tmp->g722, (int16_t *) &pvt->outbuf[pvt->samples * sizeof(int16_t)],
|
||||||
|
(uint8_t *) f->data, f->samples);
|
||||||
|
|
||||||
|
/* sample rate the same between formats, but don't assume that it won't output more ... */
|
||||||
|
pvt->samples += out_samples;
|
||||||
|
|
||||||
|
pvt->datalen += (out_samples * sizeof(int16_t));
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -110,13 +129,29 @@ static int g722tolin_framein(struct ast_trans_pvt *pvt, struct ast_frame *f)
|
|||||||
static int lintog722_framein(struct ast_trans_pvt *pvt, struct ast_frame *f)
|
static int lintog722_framein(struct ast_trans_pvt *pvt, struct ast_frame *f)
|
||||||
{
|
{
|
||||||
struct g722_encoder_pvt *tmp = pvt->pvt;
|
struct g722_encoder_pvt *tmp = pvt->pvt;
|
||||||
int16_t *src = f->data;
|
int outlen;
|
||||||
|
|
||||||
g722_encode(&tmp->g722, (uint8_t*)(&pvt->outbuf[pvt->datalen]), src, f->samples);
|
outlen = g722_encode(&tmp->g722, (uint8_t *) (&pvt->outbuf[pvt->datalen]),
|
||||||
/* Since G.722 64kbps per second is one bye per sample, all of these
|
(int16_t *) f->data, f->samples);
|
||||||
calculations are easy */
|
|
||||||
pvt->samples += f->samples;
|
pvt->samples += outlen;
|
||||||
pvt->datalen += f->samples;
|
|
||||||
|
pvt->datalen += outlen;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int lin16tog722_framein(struct ast_trans_pvt *pvt, struct ast_frame *f)
|
||||||
|
{
|
||||||
|
struct g722_encoder_pvt *tmp = pvt->pvt;
|
||||||
|
int16_t *src = f->data;
|
||||||
|
int outlen;
|
||||||
|
|
||||||
|
outlen = g722_encode(&tmp->g722, (uint8_t*)(&pvt->outbuf[pvt->datalen]), src, f->samples);
|
||||||
|
|
||||||
|
pvt->samples += outlen;
|
||||||
|
|
||||||
|
pvt->datalen += outlen;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -127,7 +162,7 @@ static struct ast_frame *g722tolin_sample(void)
|
|||||||
.frametype = AST_FRAME_VOICE,
|
.frametype = AST_FRAME_VOICE,
|
||||||
.subclass = AST_FORMAT_G722,
|
.subclass = AST_FORMAT_G722,
|
||||||
.datalen = sizeof(g722_slin_ex),
|
.datalen = sizeof(g722_slin_ex),
|
||||||
.samples = sizeof(g722_slin_ex) / sizeof(g722_slin_ex[0]),
|
.samples = sizeof(g722_slin_ex),
|
||||||
.src = __PRETTY_FUNCTION__,
|
.src = __PRETTY_FUNCTION__,
|
||||||
.data = g722_slin_ex,
|
.data = g722_slin_ex,
|
||||||
};
|
};
|
||||||
@@ -141,7 +176,7 @@ static struct ast_frame *g722tolin16_sample(void)
|
|||||||
.frametype = AST_FRAME_VOICE,
|
.frametype = AST_FRAME_VOICE,
|
||||||
.subclass = AST_FORMAT_G722,
|
.subclass = AST_FORMAT_G722,
|
||||||
.datalen = sizeof(slin_g722_ex),
|
.datalen = sizeof(slin_g722_ex),
|
||||||
.samples = sizeof(slin_g722_ex) / sizeof(slin_g722_ex[0]),
|
.samples = sizeof(slin_g722_ex),
|
||||||
.src = __PRETTY_FUNCTION__,
|
.src = __PRETTY_FUNCTION__,
|
||||||
.data = slin_g722_ex,
|
.data = slin_g722_ex,
|
||||||
};
|
};
|
||||||
@@ -185,7 +220,7 @@ static struct ast_translator g722tolin = {
|
|||||||
.framein = g722tolin_framein,
|
.framein = g722tolin_framein,
|
||||||
.sample = g722tolin_sample,
|
.sample = g722tolin_sample,
|
||||||
.desc_size = sizeof(struct g722_decoder_pvt),
|
.desc_size = sizeof(struct g722_decoder_pvt),
|
||||||
.buffer_samples = BUFFER_SAMPLES,
|
.buffer_samples = BUFFER_SAMPLES / sizeof(int16_t),
|
||||||
.buf_size = BUFFER_SAMPLES,
|
.buf_size = BUFFER_SAMPLES,
|
||||||
.plc_samples = 160,
|
.plc_samples = 160,
|
||||||
};
|
};
|
||||||
@@ -207,10 +242,10 @@ static struct ast_translator g722tolin16 = {
|
|||||||
.srcfmt = AST_FORMAT_G722,
|
.srcfmt = AST_FORMAT_G722,
|
||||||
.dstfmt = AST_FORMAT_SLINEAR16,
|
.dstfmt = AST_FORMAT_SLINEAR16,
|
||||||
.newpvt = g722tolin16_new, /* same for both directions */
|
.newpvt = g722tolin16_new, /* same for both directions */
|
||||||
.framein = g722tolin_framein,
|
.framein = g722tolin16_framein,
|
||||||
.sample = g722tolin16_sample,
|
.sample = g722tolin16_sample,
|
||||||
.desc_size = sizeof(struct g722_decoder_pvt),
|
.desc_size = sizeof(struct g722_decoder_pvt),
|
||||||
.buffer_samples = BUFFER_SAMPLES,
|
.buffer_samples = BUFFER_SAMPLES / sizeof(int16_t),
|
||||||
.buf_size = BUFFER_SAMPLES,
|
.buf_size = BUFFER_SAMPLES,
|
||||||
.plc_samples = 160,
|
.plc_samples = 160,
|
||||||
};
|
};
|
||||||
@@ -220,7 +255,7 @@ static struct ast_translator lin16tog722 = {
|
|||||||
.srcfmt = AST_FORMAT_SLINEAR16,
|
.srcfmt = AST_FORMAT_SLINEAR16,
|
||||||
.dstfmt = AST_FORMAT_G722,
|
.dstfmt = AST_FORMAT_G722,
|
||||||
.newpvt = lin16tog722_new, /* same for both directions */
|
.newpvt = lin16tog722_new, /* same for both directions */
|
||||||
.framein = lintog722_framein,
|
.framein = lin16tog722_framein,
|
||||||
.sample = lin16tog722_sample,
|
.sample = lin16tog722_sample,
|
||||||
.desc_size = sizeof(struct g722_encoder_pvt),
|
.desc_size = sizeof(struct g722_encoder_pvt),
|
||||||
.buffer_samples = BUFFER_SAMPLES,
|
.buffer_samples = BUFFER_SAMPLES,
|
||||||
|
Reference in New Issue
Block a user