[asterisk-commits] dvossel: branch 1.10 r328120 - /branches/1.10/apps/app_mixmonitor.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Jul 13 17:09:39 CDT 2011


Author: dvossel
Date: Wed Jul 13 17:09:34 2011
New Revision: 328120

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=328120
Log:
Preserve sample rate quality of wideband mixmonitor recordings.

MixMonitor has the ability to record in any file format Asterisk supports,
but the quality of wideband audio is not preserved.  This is because
regardless of the sample rate the call is being recorded in, the audio
is always downsampled to 8khz and then upsampled to whatever wideband
format it is being written as.  This patch resolves this by requesting
the audio from the audiohook in the signed linear format closest to the
sample rate of the format we are writing.  This fix is only possible for
Asterisk 1.10 because audio hooks in 1.8 are not capable of wideband
audio.

Review: https://reviewboard.asterisk.org/r/1314/


Modified:
    branches/1.10/apps/app_mixmonitor.c

Modified: branches/1.10/apps/app_mixmonitor.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.10/apps/app_mixmonitor.c?view=diff&rev=328120&r1=328119&r2=328120
==============================================================================
--- branches/1.10/apps/app_mixmonitor.c (original)
+++ branches/1.10/apps/app_mixmonitor.c Wed Jul 13 17:09:34 2011
@@ -47,6 +47,7 @@
 #include "asterisk/channel.h"
 #include "asterisk/autochan.h"
 #include "asterisk/manager.h"
+#include "asterisk/mod_format.h"
 
 /*** DOCUMENTATION
 	<application name="MixMonitor" language="en_US">
@@ -225,6 +226,8 @@
 	struct ast_filestream *fs_write;
 
 	struct ast_audiohook *audiohook;
+
+	unsigned int samp_rate;
 };
 
 /*!
@@ -334,7 +337,7 @@
 		if (!*fs && !*errflag && !mixmonitor->mixmonitor_ds->fs_quit) {
 			*oflags = O_CREAT | O_WRONLY;
 			*oflags |= ast_test_flag(mixmonitor, MUXFLAG_APPEND) ? O_APPEND : O_TRUNC;
-			
+
 			last_slash = strrchr(filename, '/');
 
 			if ((ext = strrchr(filename, '.')) && (ext > last_slash)) {
@@ -346,6 +349,9 @@
 			if (!(*fs = ast_writefile(filename, ext, NULL, *oflags, 0, 0666))) {
 				ast_log(LOG_ERROR, "Cannot open %s.%s\n", filename, ext);
 				*errflag = 1;
+			} else {
+				struct ast_filestream *tmp = *fs;
+				mixmonitor->mixmonitor_ds->samp_rate = MAX(mixmonitor->mixmonitor_ds->samp_rate, ast_format_rate(&tmp->fmt->format));
 			}
 		}
 	}
@@ -363,12 +369,21 @@
 	int errflag = 0;
 	struct ast_format format_slin;
 
-	ast_format_set(&format_slin, AST_FORMAT_SLINEAR, 0);
 	ast_verb(2, "Begin MixMonitor Recording %s\n", mixmonitor->name);
 
 	fs = &mixmonitor->mixmonitor_ds->fs;
 	fs_read = &mixmonitor->mixmonitor_ds->fs_read;
 	fs_write = &mixmonitor->mixmonitor_ds->fs_write;
+
+	ast_mutex_lock(&mixmonitor->mixmonitor_ds->lock);
+	mixmonitor_save_prep(mixmonitor, mixmonitor->filename, fs, &oflags, &errflag);
+	mixmonitor_save_prep(mixmonitor, mixmonitor->filename_read, fs_read, &oflags, &errflag);
+	mixmonitor_save_prep(mixmonitor, mixmonitor->filename_write, fs_write, &oflags, &errflag);
+
+	ast_format_set(&format_slin, ast_format_slin_by_rate(mixmonitor->mixmonitor_ds->samp_rate), 0);
+
+	ast_mutex_unlock(&mixmonitor->mixmonitor_ds->lock);
+
 
 	/* The audiohook must enter and exit the loop locked */
 	ast_audiohook_lock(&mixmonitor->audiohook);
@@ -393,9 +408,6 @@
 
 		if (!ast_test_flag(mixmonitor, MUXFLAG_BRIDGED) || (mixmonitor->autochan->chan && ast_bridged_channel(mixmonitor->autochan->chan))) {
 			ast_mutex_lock(&mixmonitor->mixmonitor_ds->lock);
-			mixmonitor_save_prep(mixmonitor, mixmonitor->filename, fs, &oflags, &errflag);
-			mixmonitor_save_prep(mixmonitor, mixmonitor->filename_read, fs_read, &oflags, &errflag);
-			mixmonitor_save_prep(mixmonitor, mixmonitor->filename_write, fs_write, &oflags, &errflag);
 
 			/* Write out the frame(s) */
 			if ((*fs_read) && (fr_read)) {
@@ -484,6 +496,8 @@
 		return -1;
 	}
 
+
+	mixmonitor_ds->samp_rate = 8000;
 	mixmonitor_ds->audiohook = &mixmonitor->audiohook;
 	datastore->data = mixmonitor_ds;
 




More information about the asterisk-commits mailing list