[Asterisk-code-review] audiohook: add directional awareness (asterisk[18])

Michael Bradeen asteriskteam at digium.com
Thu Sep 29 15:56:47 CDT 2022


Michael Bradeen has uploaded this change for review. ( https://gerrit.asterisk.org/c/asterisk/+/19318 )


Change subject: audiohook: add directional awareness
......................................................................

audiohook: add directional awareness

Add enum to allow setting optional direction. If set to only one
direction, only feed matching-direction frames to the associated
slin factory.

This prevents mangling the transcoder on non-mixed frames when the
READ and WRITE frames would have otherwise required it.  Also
removes the need to mute or discard the un-wanted frames as they
are no longer added in the first place.

res_stasis_snoop is changed to use this addition to set direction
on audiohook based on spy direction.

If no direction is set, the ast_audiohook_init will init this enum
to BOTH which maintains existing functionality.

ASTERISK-30252

Change-Id: If8716bad334562a5d812be4eeb2a92e4f3be28eb
---
M include/asterisk/audiohook.h
M main/audiohook.c
M res/res_stasis_snoop.c
3 files changed, 40 insertions(+), 0 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/18/19318/1

diff --git a/include/asterisk/audiohook.h b/include/asterisk/audiohook.h
index 8e93d56..e9941ac 100644
--- a/include/asterisk/audiohook.h
+++ b/include/asterisk/audiohook.h
@@ -119,6 +119,7 @@
 	struct ast_audiohook_options options;                  /*!< Applicable options */
 	unsigned int hook_internal_samp_rate;                  /*!< internal read/write sample rate on the audiohook.*/
 	AST_LIST_ENTRY(ast_audiohook) list;                    /*!< Linked list information */
+	enum ast_audiohook_direction direction;                /*!< Intended audiohook direction, BOTH by default on init */
 };
 
 struct ast_audiohook_list;
diff --git a/main/audiohook.c b/main/audiohook.c
index 966d5f2..c671f37 100644
--- a/main/audiohook.c
+++ b/main/audiohook.c
@@ -109,6 +109,9 @@
 
 	audiohook->init_flags = init_flags;
 
+	/* Set direction to BOTH so that we feed frames in both directions */
+	audiohook->direction = AST_AUDIOHOOK_DIRECTION_BOTH;
+
 	/* initialize internal rate at 8khz, this will adjust if necessary */
 	audiohook_set_internal_rate(audiohook, DEFAULT_INTERNAL_SAMPLE_RATE, 0);
 
@@ -159,6 +162,13 @@
 	int other_factory_samples;
 	int other_factory_ms;
 
+	/* Don't feed the frame if we are set to read and this is a write frame or if set to
+	   write and this is a read frame as we don't want it. Plus, it can cause mis-resampling
+	   if the READ and WRITE frames have different bitrates */
+	if(audiohook->direction!= AST_AUDIOHOOK_DIRECTION_BOTH && audiohook->direction!=direction){
+		return 0;
+	}
+
 	/* Update last feeding time to be current */
 	*rwtime = ast_tvnow();
 
diff --git a/res/res_stasis_snoop.c b/res/res_stasis_snoop.c
index 8d0c6eb..6490a90 100644
--- a/res/res_stasis_snoop.c
+++ b/res/res_stasis_snoop.c
@@ -287,6 +287,9 @@
 		return -1;
 	}
 
+	/* Set the direction so we don't write unused frames */
+	audiohook->direction = *direction;
+
 	return ast_audiohook_attach(chan, audiohook);
 }
 

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

Gerrit-Project: asterisk
Gerrit-Branch: 18
Gerrit-Change-Id: If8716bad334562a5d812be4eeb2a92e4f3be28eb
Gerrit-Change-Number: 19318
Gerrit-PatchSet: 1
Gerrit-Owner: Michael Bradeen <mbradeen at sangoma.com>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20220929/7d552880/attachment.html>


More information about the asterisk-code-review mailing list