[Asterisk-code-review] res stasis snoop: Spying on a single direction continually i... (asterisk[13])

Matt Jordan asteriskteam at digium.com
Thu May 7 06:39:20 CDT 2015


Matt Jordan has submitted this change and it was merged.

Change subject: res_stasis_snoop: Spying on a single direction continually increases CPU
......................................................................


res_stasis_snoop: Spying on a single direction continually increases CPU

Creating a snoop channel in ARI and spying only on a single direction (in or
out) results in CPU utilization continually increasing until the CPU is fully
consumed. This occurs because frames are being put in the opposing direction's
slin factory queue, but not being removed.

Fixed the problem by always reading and disposing of frames from the opposite
queue of the direction selected.

ASTERISK-24938 #closes

Change-Id: I935bfd15f1db958f364d9d6b3b45582c0113dd60
---
M res/res_stasis_snoop.c
1 file changed, 20 insertions(+), 4 deletions(-)

Approvals:
  Matt Jordan: Looks good to me, approved; Verified
  Joshua Colp: Looks good to me, but someone else must approve



diff --git a/res/res_stasis_snoop.c b/res/res_stasis_snoop.c
index 16d47f8..abdef6e 100644
--- a/res/res_stasis_snoop.c
+++ b/res/res_stasis_snoop.c
@@ -177,12 +177,28 @@
 	}
 
 	/* Only get audio from the spy audiohook if it is active */
-	if (snoop->spy_active) {
-		ast_audiohook_lock(&snoop->spy);
-		frame = ast_audiohook_read_frame(&snoop->spy, snoop->spy_samples, snoop->spy_direction, snoop->spy_format);
-		ast_audiohook_unlock(&snoop->spy);
+	if (!snoop->spy_active) {
+		return &ast_null_frame;
 	}
 
+	ast_audiohook_lock(&snoop->spy);
+	if (snoop->spy_direction != AST_AUDIOHOOK_DIRECTION_BOTH) {
+		/*
+		 * When a singular direction is chosen frames are still written to the
+		 * opposing direction's queue. Those frames must be read so the queue
+		 * does not continue to grow, however since they are not needed for the
+		 * selected direction they can be dropped.
+		 */
+		enum ast_audiohook_direction opposing_direction =
+			snoop->spy_direction == AST_AUDIOHOOK_DIRECTION_READ ?
+			AST_AUDIOHOOK_DIRECTION_WRITE : AST_AUDIOHOOK_DIRECTION_READ;
+		ast_frame_dtor(ast_audiohook_read_frame(&snoop->spy, snoop->spy_samples,
+							opposing_direction, snoop->spy_format));
+	}
+
+	frame = ast_audiohook_read_frame(&snoop->spy, snoop->spy_samples, snoop->spy_direction, snoop->spy_format);
+	ast_audiohook_unlock(&snoop->spy);
+
 	return frame ? frame : &ast_null_frame;
 }
 

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I935bfd15f1db958f364d9d6b3b45582c0113dd60
Gerrit-PatchSet: 4
Gerrit-Project: asterisk
Gerrit-Branch: 13
Gerrit-Owner: Kevin Harwell <kharwell at digium.com>
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
Gerrit-Reviewer: Kevin Harwell <kharwell at digium.com>
Gerrit-Reviewer: Matt Jordan <mjordan at digium.com>



More information about the asterisk-code-review mailing list