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
This commit is contained in:
Sean Bright
2019-08-09 16:53:03 -04:00
parent 16bc4ed93c
commit ddc64ca059
4 changed files with 32 additions and 1 deletions

View File

@@ -335,6 +335,17 @@ static struct ast_frame *audiohook_read_frame_both(struct ast_audiohook *audioho
frame.subclass.format = ast_format_cache_get_slin_by_rate(audiohook->hook_internal_samp_rate);
/* Should we substitute silence if one side lacks audio? */
if ((ast_test_flag(audiohook, AST_AUDIOHOOK_SUBSTITUTE_SILENCE))) {
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;