[Asterisk-code-review] res stasis snoop: spying with "out" direction only continual... (asterisk[13])

Kevin Harwell asteriskteam at digium.com
Mon May 4 17:46:57 CDT 2015


Kevin Harwell has uploaded a new change for review.

  https://gerrit.asterisk.org/356

Change subject: res_stasis_snoop: spying with "out" direction only continually increases CPU
......................................................................

res_stasis_snoop: spying with "out" direction only continually increases CPU

Creating a snoop channel with ARI and specifying "out" only for the spy mode
results in CPU utilization continually increasing until the CPU is fully
consumed. This occurs because frames are being put in the slin read_factory's
queue (the "in" direction not selected, thus ignored), but not being removed.

Fixed the problem by explicitly muting the opposite of the direction selected.
Also, modified the the audiohook write frame function to no longer "feed" the
associated slin factory if that direction is muted.

Change-Id: I935bfd15f1db958f364d9d6b3b45582c0113dd60
---
M main/audiohook.c
M res/res_stasis_snoop.c
2 files changed, 13 insertions(+), 4 deletions(-)


  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/56/356/1

diff --git a/main/audiohook.c b/main/audiohook.c
index 1883c00..60492bd 100644
--- a/main/audiohook.c
+++ b/main/audiohook.c
@@ -203,8 +203,10 @@
 		ast_frame_clear(frame);
 	}
 
-	/* Write frame out to respective factory */
-	ast_slinfactory_feed(factory, frame);
+	/* Only write frame out to the respective factory if not muted */
+	if (!muteme) {
+		ast_slinfactory_feed(factory, frame);
+	}
 
 	/* If we need to notify the respective handler of this audiohook, do so */
 	if ((ast_test_flag(audiohook, AST_AUDIOHOOK_TRIGGER_MODE) == AST_AUDIOHOOK_TRIGGER_READ) && (direction == AST_AUDIOHOOK_DIRECTION_READ)) {
diff --git a/res/res_stasis_snoop.c b/res/res_stasis_snoop.c
index 16d47f8..b1199b6 100644
--- a/res/res_stasis_snoop.c
+++ b/res/res_stasis_snoop.c
@@ -259,19 +259,26 @@
 static int snoop_setup_audiohook(struct ast_channel *chan, enum ast_audiohook_type type, enum stasis_app_snoop_direction requested_direction,
 	enum ast_audiohook_direction *direction, struct ast_audiohook *audiohook)
 {
-	ast_audiohook_init(audiohook, type, "Snoop", 0);
+#define AUDIOHOOK_SOURCE "Snoop"
+	ast_audiohook_init(audiohook, type, AUDIOHOOK_SOURCE, 0);
+
+	if (ast_audiohook_attach(chan, audiohook)) {
+		return -1;
+	}
 
 	if (requested_direction == STASIS_SNOOP_DIRECTION_OUT) {
 		*direction = AST_AUDIOHOOK_DIRECTION_WRITE;
+		ast_audiohook_set_mute(chan, AUDIOHOOK_SOURCE, AST_AUDIOHOOK_MUTE_READ, 0);
 	} else if (requested_direction == STASIS_SNOOP_DIRECTION_IN) {
 		*direction = AST_AUDIOHOOK_DIRECTION_READ;
+		ast_audiohook_set_mute(chan, AUDIOHOOK_SOURCE, AST_AUDIOHOOK_MUTE_WRITE, 0);
 	} else if (requested_direction == STASIS_SNOOP_DIRECTION_BOTH) {
 		*direction = AST_AUDIOHOOK_DIRECTION_BOTH;
 	} else {
 		return -1;
 	}
 
-	return ast_audiohook_attach(chan, audiohook);
+	return 0;
 }
 
 /*! \brief Helper function which gets the format for a Snoop channel based on the channel being snooped on */

-- 
To view, visit https://gerrit.asterisk.org/356
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I935bfd15f1db958f364d9d6b3b45582c0113dd60
Gerrit-PatchSet: 1
Gerrit-Project: asterisk
Gerrit-Branch: 13
Gerrit-Owner: Kevin Harwell <kharwell at digium.com>
Gerrit-Reviewer: Kevin Harwell <kharwell at digium.com>



More information about the asterisk-code-review mailing list