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

Kevin Harwell asteriskteam at digium.com
Tue May 5 14:03:57 CDT 2015


Kevin Harwell has uploaded a new change for review.

  https://gerrit.asterisk.org/367

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 always reading from the "in" direction queue. However,
in the case when specifying "out" only drop the "in" frames.

Change-Id: I935bfd15f1db958f364d9d6b3b45582c0113dd60

Localized changes to res_stasis_snoop

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


  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/67/367/1

diff --git a/res/res_stasis_snoop.c b/res/res_stasis_snoop.c
index 16d47f8..be41bfd 100644
--- a/res/res_stasis_snoop.c
+++ b/res/res_stasis_snoop.c
@@ -177,12 +177,25 @@
 	}
 
 	/* 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_WRITE) {
+		/*
+		 * Frames are still being written to the "in" queue. They must
+		 * be read so the queue does not continue to grow, however since
+		 * we don't need them for the "out" case they can be dropped.
+		 */
+		frame = ast_audiohook_read_frame(&snoop->spy, snoop->spy_samples,
+						 AST_AUDIOHOOK_DIRECTION_READ, snoop->spy_format);
+		ast_free(frame);
+	}
+
+	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/367
To unsubscribe, visit https://gerrit.asterisk.org/settings

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



More information about the asterisk-code-review mailing list