[asterisk-commits] trunk - r7801 in /trunk: ./ formats/

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Wed Jan 4 17:29:38 CST 2006


Author: kpfleming
Date: Wed Jan  4 17:29:37 2006
New Revision: 7801

URL: http://svn.digium.com/view/asterisk?rev=7801&view=rev
Log:
Merged revisions 7799-7800 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.2

........
r7799 | kpfleming | 2006-01-04 17:02:38 -0600 (Wed, 04 Jan 2006) | 2 lines

make monitoring more tolerant of peers that deliver frames in bursts

........
r7800 | kpfleming | 2006-01-04 17:27:57 -0600 (Wed, 04 Jan 2006) | 2 lines

ensure that ulaw/alaw sound files are filled with silence when extended (not zeroes)

........

Modified:
    trunk/   (props changed)
    trunk/channel.c
    trunk/formats/format_pcm.c
    trunk/formats/format_pcm_alaw.c

Propchange: trunk/
------------------------------------------------------------------------------
--- svnmerge-integrated (original)
+++ svnmerge-integrated Wed Jan  4 17:29:37 2006
@@ -1,1 +1,1 @@
-/branches/1.2:1-7489,7491-7496,7498-7516,7518-7528,7530-7545,7547-7549,7551,7553-7556,7558-7579,7581-7585,7587-7594,7596-7604,7606-7640,7642-7662,7664-7705,7707-7737,7739-7770,7772-7791,7793-7795
+/branches/1.2:1-7489,7491-7496,7498-7516,7518-7528,7530-7545,7547-7549,7551,7553-7556,7558-7579,7581-7585,7587-7594,7596-7604,7606-7640,7642-7662,7664-7705,7707-7737,7739-7770,7772-7791,7793-7800

Modified: trunk/channel.c
URL: http://svn.digium.com/view/asterisk/trunk/channel.c?rev=7801&r1=7800&r2=7801&view=diff
==============================================================================
--- trunk/channel.c (original)
+++ trunk/channel.c Wed Jan  4 17:29:37 2006
@@ -1889,11 +1889,11 @@
 
 			if (chan->monitor && chan->monitor->read_stream ) {
 #ifndef MONITOR_CONSTANT_DELAY
-				int jump = chan->outsmpl - chan->insmpl - 2 * f->samples;
+				int jump = chan->outsmpl - chan->insmpl - 4 * f->samples;
 				if (jump >= 0) {
 					if (ast_seekstream(chan->monitor->read_stream, jump + f->samples, SEEK_FORCECUR) == -1)
 						ast_log(LOG_WARNING, "Failed to perform seek in monitoring read stream, synchronization between the files may be broken\n");
-					chan->insmpl += jump + 2 * f->samples;
+					chan->insmpl += jump + 4 * f->samples;
 				} else
 					chan->insmpl+= f->samples;
 #else
@@ -2250,11 +2250,11 @@
 				if( chan->monitor && chan->monitor->write_stream &&
 						f && ( f->frametype == AST_FRAME_VOICE ) ) {
 #ifndef MONITOR_CONSTANT_DELAY
-					int jump = chan->insmpl - chan->outsmpl - 2 * f->samples;
+					int jump = chan->insmpl - chan->outsmpl - 4 * f->samples;
 					if (jump >= 0) {
 						if (ast_seekstream(chan->monitor->write_stream, jump + f->samples, SEEK_FORCECUR) == -1)
 							ast_log(LOG_WARNING, "Failed to perform seek in monitoring write stream, synchronization between the files may be broken\n");
-						chan->outsmpl += jump + 2 * f->samples;
+						chan->outsmpl += jump + 4 * f->samples;
 					} else
 						chan->outsmpl += f->samples;
 #else

Modified: trunk/formats/format_pcm.c
URL: http://svn.digium.com/view/asterisk/trunk/formats/format_pcm.c?rev=7801&r1=7800&r2=7801&view=diff
==============================================================================
--- trunk/formats/format_pcm.c (original)
+++ trunk/formats/format_pcm.c Wed Jan  4 17:29:37 2006
@@ -1,7 +1,7 @@
 /*
  * Asterisk -- An open source telephony toolkit.
  *
- * Copyright (C) 1999 - 2005, Digium, Inc.
+ * Copyright (C) 1999 - 2006, Digium, Inc.
  *
  * Mark Spencer <markster at digium.com>
  *
@@ -44,6 +44,7 @@
 #include "asterisk/sched.h"
 #include "asterisk/module.h"
 #include "asterisk/endian.h"
+#include "asterisk/ulaw.h"
 
 #define BUF_SIZE 160		/* 160 samples */
 
@@ -66,6 +67,8 @@
 static char *name = "pcm";
 static char *desc = "Raw uLaw 8khz Audio support (PCM)";
 static char *exts = "pcm|ulaw|ul|mu";
+
+static char ulaw_silence[BUF_SIZE];
 
 static struct ast_filestream *pcm_open(FILE *f)
 {
@@ -173,24 +176,44 @@
 
 static int pcm_seek(struct ast_filestream *fs, long sample_offset, int whence)
 {
-	off_t offset=0,min,cur,max;
-
-	min = 0;
+	long cur, max, offset;
+
 	cur = ftell(fs->f);
-	fseek(fs->f, 0, SEEK_END);
-	max = ftell(fs->f);
-	if (whence == SEEK_SET)
+	max = fseek(fs->f, 0, SEEK_END);
+
+	switch (whence) {
+	case SEEK_SET:
 		offset = sample_offset;
-	else if (whence == SEEK_CUR || whence == SEEK_FORCECUR)
-		offset = sample_offset + cur;
-	else if (whence == SEEK_END)
+		break;
+	case SEEK_END:
 		offset = max - sample_offset;
-	if (whence != SEEK_FORCECUR) {
-		offset = (offset > max)?max:offset;
-	}
-	/* always protect against seeking past begining. */
-	offset = (offset < min)?min:offset;
-	return fseek(fs->f, offset, SEEK_SET);
+		break;
+	case SEEK_CUR:
+	case SEEK_FORCECUR:
+		offset = cur + sample_offset;
+		break;
+	}
+
+	switch (whence) {
+	case SEEK_FORCECUR:
+		if (offset > max) {
+			size_t left = offset - max;
+			size_t res;
+
+			while (left) {
+				res = fwrite(ulaw_silence, (left > BUF_SIZE) ? BUF_SIZE : left,
+					     sizeof(ulaw_silence[0]), fs->f);
+				if (res == -1)
+					return res;
+				left -= res;
+			}
+		}
+		/* fall through */
+	default:
+		offset = (offset > max) ? max : offset;
+		offset = (offset < 0) ? 0 : offset;
+		return fseek(fs->f, offset, SEEK_SET);
+	}
 }
 
 static int pcm_trunc(struct ast_filestream *fs)
@@ -212,18 +235,21 @@
 
 int load_module()
 {
+	int index;
+
+	for (index = 0; index < (sizeof(ulaw_silence) / sizeof(ulaw_silence[0])); index++)
+		ulaw_silence[index] = AST_LIN2MU(0);
+
 	return ast_format_register(name, exts, AST_FORMAT_ULAW,
-								pcm_open,
-								pcm_rewrite,
-								pcm_write,
-								pcm_seek,
-								pcm_trunc,
-								pcm_tell,
-								pcm_read,
-								pcm_close,
-								pcm_getcomment);
-								
-								
+				   pcm_open,
+				   pcm_rewrite,
+				   pcm_write,
+				   pcm_seek,
+				   pcm_trunc,
+				   pcm_tell,
+				   pcm_read,
+				   pcm_close,
+				   pcm_getcomment);
 }
 
 int unload_module()

Modified: trunk/formats/format_pcm_alaw.c
URL: http://svn.digium.com/view/asterisk/trunk/formats/format_pcm_alaw.c?rev=7801&r1=7800&r2=7801&view=diff
==============================================================================
--- trunk/formats/format_pcm_alaw.c (original)
+++ trunk/formats/format_pcm_alaw.c Wed Jan  4 17:29:37 2006
@@ -1,7 +1,7 @@
 /*
  * Asterisk -- An open source telephony toolkit.
  *
- * Copyright (C) 1999 - 2005, Digium, Inc.
+ * Copyright (C) 1999 - 2006, Digium, Inc.
  *
  * Mark Spencer <markster at digium.com>
  *
@@ -45,6 +45,7 @@
 #include "asterisk/sched.h"
 #include "asterisk/module.h"
 #include "asterisk/endian.h"
+#include "asterisk/alaw.h"
 
 #define BUF_SIZE 160		/* 160 samples */
 
@@ -73,6 +74,8 @@
 static char *desc = "Raw aLaw 8khz PCM Audio support";
 static char *exts = "alaw|al";
 
+static char alaw_silence[BUF_SIZE];
+
 
 #if 0
 /* Returns time in msec since system boot. */
@@ -248,24 +251,44 @@
 
 static int pcm_seek(struct ast_filestream *fs, long sample_offset, int whence)
 {
-	off_t offset=0,min,cur,max;
-
-	min = 0;
+	long cur, max, offset;
+
 	cur = ftell(fs->f);
-	fseek(fs->f, 0, SEEK_END);
-	max = ftell(fs->f);
-	if (whence == SEEK_SET)
+	max = fseek(fs->f, 0, SEEK_END);
+
+	switch (whence) {
+	case SEEK_SET:
 		offset = sample_offset;
-	else if (whence == SEEK_CUR || whence == SEEK_FORCECUR)
-		offset = sample_offset + cur;
-	else if (whence == SEEK_END)
+		break;
+	case SEEK_END:
 		offset = max - sample_offset;
-	if (whence != SEEK_FORCECUR) {
-		offset = (offset > max)?max:offset;
-	}
-	/* Always protect against seeking past begining */
-	offset = (offset < min)?min:offset;
-	return fseek(fs->f, offset, SEEK_SET);
+		break;
+	case SEEK_CUR:
+	case SEEK_FORCECUR:
+		offset = cur + sample_offset;
+		break;
+	}
+
+	switch (whence) {
+	case SEEK_FORCECUR:
+		if (offset > max) {
+			size_t left = offset - max;
+			size_t res;
+
+			while (left) {
+				res = fwrite(alaw_silence, (left > BUF_SIZE) ? BUF_SIZE : left,
+					     sizeof(alaw_silence[0]), fs->f);
+				if (res == -1)
+					return res;
+				left -= res;
+			}
+		}
+		/* fall through */
+	default:
+		offset = (offset > max) ? max : offset;
+		offset = (offset < 0) ? 0 : offset;
+		return fseek(fs->f, offset, SEEK_SET);
+	}
 }
 
 static int pcm_trunc(struct ast_filestream *fs)
@@ -288,16 +311,21 @@
 
 int load_module()
 {
+	int index;
+
+	for (index = 0; index < (sizeof(alaw_silence) / sizeof(alaw_silence[0])); index++)
+		alaw_silence[index] = AST_LIN2A(0);
+
 	return ast_format_register(name, exts, AST_FORMAT_ALAW,
-								pcm_open,
-								pcm_rewrite,
-								pcm_write,
-								pcm_seek,
-								pcm_trunc,
-								pcm_tell,
-								pcm_read,
-								pcm_close,
-								pcm_getcomment);
+				   pcm_open,
+				   pcm_rewrite,
+				   pcm_write,
+				   pcm_seek,
+				   pcm_trunc,
+				   pcm_tell,
+				   pcm_read,
+				   pcm_close,
+				   pcm_getcomment);
 }
 
 int unload_module()



More information about the asterisk-commits mailing list