[asterisk-commits] russell: branch 1.6.0 r106502 - in /branches/1.6.0: ./ codecs/ formats/ main/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Mar 6 18:25:49 CST 2008


Author: russell
Date: Thu Mar  6 18:25:48 2008
New Revision: 106502

URL: http://svn.digium.com/view/asterisk?view=rev&rev=106502
Log:
Merged revisions 106501 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/trunk

........
r106501 | russell | 2008-03-06 18:24:58 -0600 (Thu, 06 Mar 2008) | 28 lines

Merge changes from team/russell/g722-sillyness ...

Fix a number of other places where the number of samples in a G722 frame was
not properly handled because of various reasons.

main/rtp.c:
 - When a G722 frame is read from the smoother, the number of samples in the
   frame must be divided by 2 before being sent out over the network.  Even
   though G722 is 16 kHz, an error in some previous spec has made it so that
   we have to list the number of samples such as if it was 8 kHz.

main/file.c:
 - When scheduling the next time to expect a frame, take into account that the
   format of the file we're reading from may not be 8 kHz.

codecs/codec_g722.c:
 - When converting from G722 to slinear, g722_decode() expects its samples
   parameter to be in the silly (real samples / 2) format.  Make it so.
 - When converting from slinear to G722, properly set the number of samples in
   the frame to be the number of bytes of output * 2.

formats/format_pcm.c:
 - This format module handles G722, among a number of other formats.  However,
   the read() and seek() functions did not account for the fact that G722 has
   2 samples per byte.

(closes issue #12130, reported by rickross, patched by me)

........

Modified:
    branches/1.6.0/   (props changed)
    branches/1.6.0/codecs/codec_g722.c
    branches/1.6.0/formats/format_pcm.c
    branches/1.6.0/main/file.c
    branches/1.6.0/main/rtp.c

Propchange: branches/1.6.0/
------------------------------------------------------------------------------
--- trunk-merged (original)
+++ trunk-merged Thu Mar  6 18:25:48 2008
@@ -1,1 +1,1 @@
-/trunk:1-105595,105675,105677,105733-105734,105773,105785,105804,105840-105841,105864,105899,105933,106036,106040,106139,106186,106238-106239,106329,106346,106399,106438-106439
+/trunk:1-105595,105675,105677,105733-105734,105773,105785,105804,105840-105841,105864,105899,105933,106036,106040,106139,106186,106238-106239,106329,106346,106399,106438-106439,106501

Modified: branches/1.6.0/codecs/codec_g722.c
URL: http://svn.digium.com/view/asterisk/branches/1.6.0/codecs/codec_g722.c?view=diff&rev=106502&r1=106501&r2=106502
==============================================================================
--- branches/1.6.0/codecs/codec_g722.c (original)
+++ branches/1.6.0/codecs/codec_g722.c Thu Mar  6 18:25:48 2008
@@ -102,9 +102,13 @@
 {
 	struct g722_decoder_pvt *tmp = pvt->pvt;
 	int out_samples;
+	int in_samples;
+
+	/* g722_decode expects the samples to be in the invalid samples / 2 format */
+	in_samples = f->samples / 2;
 
 	out_samples = g722_decode(&tmp->g722, (int16_t *) &pvt->outbuf[pvt->samples * sizeof(int16_t)], 
-		(uint8_t *) f->data, f->samples);
+		(uint8_t *) f->data, in_samples);
 
 	pvt->samples += out_samples;
 
@@ -121,7 +125,7 @@
 	outlen = g722_encode(&tmp->g722, (uint8_t *) (&pvt->outbuf[pvt->datalen]), 
 		(int16_t *) f->data, f->samples);
 
-	pvt->samples += outlen;
+	pvt->samples += outlen * 2;
 
 	pvt->datalen += outlen;
 

Modified: branches/1.6.0/formats/format_pcm.c
URL: http://svn.digium.com/view/asterisk/branches/1.6.0/formats/format_pcm.c?view=diff&rev=106502&r1=106501&r2=106502
==============================================================================
--- branches/1.6.0/formats/format_pcm.c (original)
+++ branches/1.6.0/formats/format_pcm.c Thu Mar  6 18:25:48 2008
@@ -89,7 +89,10 @@
 		return NULL;
 	}
 	s->fr.datalen = res;
-	*whennext = s->fr.samples = res;
+	if (s->fmt->format == AST_FORMAT_G722)
+		*whennext = s->fr.samples = res * 2;
+	else
+		*whennext = s->fr.samples = res;
 	return &s->fr;
 }
 
@@ -367,24 +370,32 @@
 static int au_seek(struct ast_filestream *fs, off_t sample_offset, int whence)
 {
 	off_t min, max, cur;
-	long offset = 0, samples;
-	
-	samples = sample_offset;
+	long offset = 0, bytes;
+
+	if (fs->fmt->format == AST_FORMAT_G722)
+		bytes = sample_offset / 2;
+	else
+		bytes = sample_offset;
+
 	min = AU_HEADER_SIZE;
 	cur = ftello(fs->f);
 	fseek(fs->f, 0, SEEK_END);
 	max = ftello(fs->f);
+
 	if (whence == SEEK_SET)
-		offset = samples + min;
+		offset = bytes + min;
 	else if (whence == SEEK_CUR || whence == SEEK_FORCECUR)
-		offset = samples + cur;
+		offset = bytes + cur;
 	else if (whence == SEEK_END)
-		offset = max - samples;
-        if (whence != SEEK_FORCECUR) {
+		offset = max - bytes;
+
+	if (whence != SEEK_FORCECUR) {
 		offset = (offset > max) ? max : offset;
 	}
+
 	/* always protect the header space. */
 	offset = (offset < min) ? min : offset;
+
 	return fseeko(fs->f, offset, SEEK_SET);
 }
 

Modified: branches/1.6.0/main/file.c
URL: http://svn.digium.com/view/asterisk/branches/1.6.0/main/file.c?view=diff&rev=106502&r1=106501&r2=106502
==============================================================================
--- branches/1.6.0/main/file.c (original)
+++ branches/1.6.0/main/file.c Thu Mar  6 18:25:48 2008
@@ -669,7 +669,8 @@
 			ast_settimeout(s->owner, whennext, ast_fsread_audio, s);
 		else
 #endif		
-			s->owner->streamid = ast_sched_add(s->owner->sched, whennext / 8, ast_fsread_audio, s);
+			s->owner->streamid = ast_sched_add(s->owner->sched, 
+				whennext / (ast_format_rate(s->fmt->format) / 1000), ast_fsread_audio, s);
 		s->lasttimeout = whennext;
 		return FSREAD_SUCCESS_NOSCHED;
 	}
@@ -713,7 +714,8 @@
 	}
 
 	if (whennext != s->lasttimeout) {
-		s->owner->vstreamid = ast_sched_add(s->owner->sched, whennext / 8, 
+		s->owner->vstreamid = ast_sched_add(s->owner->sched, 
+			whennext / (ast_format_rate(s->fmt->format) / 1000), 
 			ast_fsread_video, s);
 		s->lasttimeout = whennext;
 		return FSREAD_SUCCESS_NOSCHED;

Modified: branches/1.6.0/main/rtp.c
URL: http://svn.digium.com/view/asterisk/branches/1.6.0/main/rtp.c?view=diff&rev=106502&r1=106501&r2=106502
==============================================================================
--- branches/1.6.0/main/rtp.c (original)
+++ branches/1.6.0/main/rtp.c Thu Mar  6 18:25:48 2008
@@ -3186,8 +3186,14 @@
 			ast_smoother_feed(rtp->smoother, _f);
 		}
 
-		while ((f = ast_smoother_read(rtp->smoother)) && (f->data))
+		while ((f = ast_smoother_read(rtp->smoother)) && (f->data)) {
+			if (f->subclass == AST_FORMAT_G722) {
+				/* G.722 is silllllllllllllly */
+				f->samples /= 2;
+			}
+
 			ast_rtp_raw_write(rtp, f, codec);
+		}
 	} else {
 		/* Don't buffer outgoing frames; send them one-per-packet: */
 		if (_f->offset < hdrlen) 




More information about the asterisk-commits mailing list