summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Jordan <mjordan@digium.com>2015-05-07 06:39:26 -0500
committerGerrit Code Review <gerrit2@gerrit.digium.api>2015-05-07 06:39:27 -0500
commitfa59e23ddf11a1a1e23471563067c88ca4ad8374 (patch)
tree82db0113b89a4c43d9a4d82ad68f5b228598ab03
parent746220769415130df9dfdf687cd61a824de22e7d (diff)
parent1f5db1c7e31a76aa9223dfa22030fec0a45c5552 (diff)
Merge "res_stasis_snoop: Spying on a single direction continually increases CPU"
-rw-r--r--res/res_stasis_snoop.c24
1 files changed, 20 insertions, 4 deletions
diff --git a/res/res_stasis_snoop.c b/res/res_stasis_snoop.c
index 5311aed26..68d76a420 100644
--- a/res/res_stasis_snoop.c
+++ b/res/res_stasis_snoop.c
@@ -177,12 +177,28 @@ static struct ast_frame *snoop_read(struct ast_channel *chan)
}
/* 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;
}