[Asterisk-code-review] audiohook.c: Substitute silence for unavailable audio frames (...asterisk[13])

Sean Bright asteriskteam at digium.com
Mon Aug 12 10:04:58 CDT 2019


Sean Bright has uploaded this change for review. ( https://gerrit.asterisk.org/c/asterisk/+/12735


Change subject: audiohook.c: Substitute silence for unavailable audio frames
......................................................................

audiohook.c: Substitute silence for unavailable audio frames

There are 4 scenarios to consider when capturing audio from a channel
with an audiohook:

 1. There is no rx and no tx audio, so return nothing.
 2. There is rx but no tx audio, so return rx.
 3. There is tx but no rx audio, so return tx.
 4. There is rx and tx audio, so mix them and return.

The file passed as the primary argument to MixMonitor will be written to
in scenarios 2, 3, and 4. However, if you pass the r() and t() options
to MixMonitor, a frame will only be written to the r() file if there was
rx audio and a frame will only be written to the t() file if there was
tx audio.

If you subsequently take the r() and t() files and try to mix them, the
sides of the conversation will 'drift' and be non-representative of the
user experience.

This patch adds a new 'S' option to MixMonitor that injects a frame of
silence on either the r() side or the t() side of the channel so that
when later mixed, there is no such drift.

Change-Id: Ibf5ed73a811087727bd561a89a59f4447b4ee20e
---
M apps/app_mixmonitor.c
M include/asterisk/audiohook.h
M main/audiohook.c
3 files changed, 25 insertions(+), 1 deletion(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/35/12735/1

diff --git a/apps/app_mixmonitor.c b/apps/app_mixmonitor.c
index 9f14776..b067b8e 100644
--- a/apps/app_mixmonitor.c
+++ b/apps/app_mixmonitor.c
@@ -117,6 +117,11 @@
 						Like with the basic filename argument, if an absolute path isn't given, it will create
 						the file in the configured monitoring directory.</para>
 					</option>
+					<option name="S">
+						<para>When combined with the <replaceable>r</replaceable> or <replaceable>t</replaceable>
+						option, inserts silence when necessary to maintain synchronization between the receive
+						and transmit audio streams.</para>
+					</option>
 					<option name="i">
 						<argument name="chanvar" required="true" />
 						<para>Stores the MixMonitor's ID on this channel variable.</para>
@@ -349,7 +354,8 @@
 	MUXFLAG_VMRECIPIENTS = (1 << 10),
 	MUXFLAG_BEEP = (1 << 11),
 	MUXFLAG_BEEP_START = (1 << 12),
-	MUXFLAG_BEEP_STOP = (1 << 13)
+	MUXFLAG_BEEP_STOP = (1 << 13),
+	MUXFLAG_RWSYNC = (1 << 14),
 };
 
 enum mixmonitor_args {
@@ -361,6 +367,7 @@
 	OPT_ARG_UID,
 	OPT_ARG_VMRECIPIENTS,
 	OPT_ARG_BEEP_INTERVAL,
+	OPT_ARG_RWSYNC,
 	OPT_ARG_ARRAY_SIZE,	/* Always last element of the enum */
 };
 
@@ -377,6 +384,7 @@
 	AST_APP_OPTION_ARG('t', MUXFLAG_WRITE, OPT_ARG_WRITENAME),
 	AST_APP_OPTION_ARG('i', MUXFLAG_UID, OPT_ARG_UID),
 	AST_APP_OPTION_ARG('m', MUXFLAG_VMRECIPIENTS, OPT_ARG_VMRECIPIENTS),
+	AST_APP_OPTION_ARG('S', MUXFLAG_RWSYNC, OPT_ARG_RWSYNC),
 });
 
 struct mixmonitor_ds {
@@ -967,6 +975,9 @@
 	}
 
 	ast_set_flag(&mixmonitor->audiohook, AST_AUDIOHOOK_TRIGGER_SYNC);
+	if ((ast_test_flag(mixmonitor, MUXFLAG_RWSYNC))) {
+		ast_set_flag(&mixmonitor->audiohook, AST_AUDIOHOOK_SUBSITUTE_RW);
+	}
 
 	if (readvol)
 		mixmonitor->audiohook.options.read_volume = readvol;
diff --git a/include/asterisk/audiohook.h b/include/asterisk/audiohook.h
index cae8cc0..47aa4ed 100644
--- a/include/asterisk/audiohook.h
+++ b/include/asterisk/audiohook.h
@@ -64,6 +64,8 @@
 	AST_AUDIOHOOK_MUTE_READ     = (1 << 5), /*!< audiohook should be mute frames read */
 	AST_AUDIOHOOK_MUTE_WRITE    = (1 << 6), /*!< audiohook should be mute frames written */
 	AST_AUDIOHOOK_COMPATIBLE    = (1 << 7), /*!< is the audiohook native slin compatible */
+
+	AST_AUDIOHOOK_SUBSITUTE_RW  = (1 << 8), /*!< Substitute silence for missing audio */
 };
 
 enum ast_audiohook_init_flags {
diff --git a/main/audiohook.c b/main/audiohook.c
index cb3c4bc..765f0b4 100644
--- a/main/audiohook.c
+++ b/main/audiohook.c
@@ -335,6 +335,17 @@
 
 	frame.subclass.format = ast_format_cache_get_slin_by_rate(audiohook->hook_internal_samp_rate);
 
+	/* Should we subsitute silence if one side lacks audio? */
+	if ((ast_test_flag(audiohook, AST_AUDIOHOOK_SUBSITUTE_RW))) {
+		if (read_reference && !read_buf && write_buf) {
+			read_buf = buf1;
+			memset(buf1, 0, sizeof(buf1));
+		} else if (write_reference && read_buf && !write_buf) {
+			write_buf = buf2;
+			memset(buf2, 0, sizeof(buf2));
+		}
+	}
+
 	/* Basically we figure out which buffer to use... and if mixing can be done here */
 	if (read_buf && read_reference) {
 		frame.data.ptr = read_buf;

-- 
To view, visit https://gerrit.asterisk.org/c/asterisk/+/12735
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 13
Gerrit-Change-Id: Ibf5ed73a811087727bd561a89a59f4447b4ee20e
Gerrit-Change-Number: 12735
Gerrit-PatchSet: 1
Gerrit-Owner: Sean Bright <sean.bright at gmail.com>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20190812/41834879/attachment-0001.html>


More information about the asterisk-code-review mailing list