[asterisk-commits] russell: trunk r97975 - /trunk/codecs/codec_g722.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Jan 10 17:16:09 CST 2008


Author: russell
Date: Thu Jan 10 17:16:09 2008
New Revision: 97975

URL: http://svn.digium.com/view/asterisk?view=rev&rev=97975
Log:
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.

Modified:
    trunk/codecs/codec_g722.c

Modified: trunk/codecs/codec_g722.c
URL: http://svn.digium.com/view/asterisk/trunk/codecs/codec_g722.c?view=diff&rev=97975&r1=97974&r2=97975
==============================================================================
--- trunk/codecs/codec_g722.c (original)
+++ trunk/codecs/codec_g722.c Thu Jan 10 17:16:09 2008
@@ -98,25 +98,60 @@
 {
 	struct g722_decoder_pvt *tmp = pvt->pvt;
 	unsigned char *src = f->data;
-	int16_t *dst = (int16_t *) pvt->outbuf + pvt->samples;
-
-	g722_decode(&tmp->g722, dst, src, f->samples);
-	pvt->samples += f->samples;
-	pvt->datalen += 2 * f->samples;
+	int out_samples;
+
+	out_samples = g722_decode(&tmp->g722, (int16_t *) &pvt->outbuf[pvt->samples * sizeof(int16_t)], 
+		src, 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;
 }
 
 static int lintog722_framein(struct ast_trans_pvt *pvt, struct ast_frame *f)
+{
+	struct g722_encoder_pvt *tmp = pvt->pvt;
+	int outlen;
+
+	outlen = g722_encode(&tmp->g722, (uint8_t *) (&pvt->outbuf[pvt->datalen]), 
+		(int16_t *) f->data, f->samples);
+
+	pvt->samples += outlen;
+
+	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;
-
-	g722_encode(&tmp->g722, (uint8_t*)(&pvt->outbuf[pvt->datalen]), src, f->samples);
-	/* Since G.722 64kbps per second is one bye per sample, all of these
-	   calculations are easy */
-	pvt->samples += f->samples;
-	pvt->datalen += f->samples;
+	int outlen;
+
+	outlen = g722_encode(&tmp->g722, (uint8_t*)(&pvt->outbuf[pvt->datalen]), src, f->samples);
+
+	pvt->samples += outlen;
+
+	pvt->datalen += outlen;
 
 	return 0;
 }
@@ -127,7 +162,7 @@
 		.frametype = AST_FRAME_VOICE,
 		.subclass = AST_FORMAT_G722,
 		.datalen = sizeof(g722_slin_ex),
-		.samples = sizeof(g722_slin_ex) / sizeof(g722_slin_ex[0]),
+		.samples = sizeof(g722_slin_ex),
 		.src = __PRETTY_FUNCTION__,
 		.data = g722_slin_ex,
 	};
@@ -141,7 +176,7 @@
 		.frametype = AST_FRAME_VOICE,
 		.subclass = AST_FORMAT_G722,
 		.datalen = sizeof(slin_g722_ex),
-		.samples = sizeof(slin_g722_ex) / sizeof(slin_g722_ex[0]),
+		.samples = sizeof(slin_g722_ex),
 		.src = __PRETTY_FUNCTION__,
 		.data = slin_g722_ex,
 	};
@@ -185,7 +220,7 @@
 	.framein = g722tolin_framein,
 	.sample = g722tolin_sample,
 	.desc_size = sizeof(struct g722_decoder_pvt),
-	.buffer_samples = BUFFER_SAMPLES,
+	.buffer_samples = BUFFER_SAMPLES / sizeof(int16_t),
 	.buf_size = BUFFER_SAMPLES,
 	.plc_samples = 160,
 };
@@ -207,10 +242,10 @@
 	.srcfmt = AST_FORMAT_G722,
 	.dstfmt = AST_FORMAT_SLINEAR16,
 	.newpvt = g722tolin16_new,	/* same for both directions */
-	.framein = g722tolin_framein,
+	.framein = g722tolin16_framein,
 	.sample = g722tolin16_sample,
 	.desc_size = sizeof(struct g722_decoder_pvt),
-	.buffer_samples = BUFFER_SAMPLES,
+	.buffer_samples = BUFFER_SAMPLES / sizeof(int16_t),
 	.buf_size = BUFFER_SAMPLES,
 	.plc_samples = 160,
 };
@@ -220,7 +255,7 @@
 	.srcfmt = AST_FORMAT_SLINEAR16,
 	.dstfmt = AST_FORMAT_G722,
 	.newpvt = lin16tog722_new,	/* same for both directions */
-	.framein = lintog722_framein,
+	.framein = lin16tog722_framein,
 	.sample = lin16tog722_sample,
 	.desc_size = sizeof(struct g722_encoder_pvt),
 	.buffer_samples = BUFFER_SAMPLES,




More information about the asterisk-commits mailing list