aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordvossel <dvossel@f38db490-d61c-443f-a65b-d21fe96a405b>2010-07-27 20:54:32 +0000
committerdvossel <dvossel@f38db490-d61c-443f-a65b-d21fe96a405b>2010-07-27 20:54:32 +0000
commitafcd803da1b7c0b248709a80c6c904a1f57eccb2 (patch)
tree322a2cfad1c3a18f03f9895dd10b0b7845af9d97
parent64d9c842655f5fdacfca1411006b8eb8bb82e006 (diff)
Merged revisions 279945 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r279945 | dvossel | 2010-07-27 15:33:40 -0500 (Tue, 27 Jul 2010) | 19 lines remove empty audiohook write list on channel If a channel has an audiohook write list created on it, that list stays on the channel until the channel is destroyed. There is no reason to keep that list on the channel if it becomes empty. If it is empty that just means we are doing needless translating for every ast_read and ast_write. This patch removes the audiohook list from the channel once it is detected to be empty on either a read or write. If a audiohook is added back to the channel after this list is destroyed, the list just gets recreated as if it never existed to begin with. (closes issue #17630) Reported by: manvirr Review: https://reviewboard.asterisk.org/r/799/ ........ git-svn-id: http://svn.digium.com/svn/asterisk/branches/1.6.2@279946 f38db490-d61c-443f-a65b-d21fe96a405b
-rw-r--r--include/asterisk/audiohook.h7
-rw-r--r--main/audiohook.c12
-rw-r--r--main/channel.c10
3 files changed, 28 insertions, 1 deletions
diff --git a/include/asterisk/audiohook.h b/include/asterisk/audiohook.h
index a42d48fef..d7ee80568 100644
--- a/include/asterisk/audiohook.h
+++ b/include/asterisk/audiohook.h
@@ -200,6 +200,13 @@ int ast_audiohook_detach_source(struct ast_channel *chan, const char *source);
*/
int ast_audiohook_remove(struct ast_channel *chan, struct ast_audiohook *audiohook);
+/*!
+ * \brief determines if a audiohook_list is empty or not.
+ *
+ * retval 0 false, 1 true
+ */
+int ast_audiohook_write_list_empty(struct ast_audiohook_list *audiohook_list);
+
/*! \brief Pass a frame off to be handled by the audiohook core
* \param chan Channel that the list is coming off of
* \param audiohook_list List of audiohooks
diff --git a/main/audiohook.c b/main/audiohook.c
index 2dd2bea35..fda532eff 100644
--- a/main/audiohook.c
+++ b/main/audiohook.c
@@ -723,6 +723,17 @@ static struct ast_frame *audio_audiohook_write_list(struct ast_channel *chan, st
return end_frame;
}
+int ast_audiohook_write_list_empty(struct ast_audiohook_list *audiohook_list)
+{
+ if (AST_LIST_EMPTY(&audiohook_list->spy_list) &&
+ AST_LIST_EMPTY(&audiohook_list->whisper_list) &&
+ AST_LIST_EMPTY(&audiohook_list->manipulate_list)) {
+
+ return 1;
+ }
+ return 0;
+}
+
/*! \brief Pass a frame off to be handled by the audiohook core
* \param chan Channel that the list is coming off of
* \param audiohook_list List of audiohooks
@@ -740,7 +751,6 @@ struct ast_frame *ast_audiohook_write_list(struct ast_channel *chan, struct ast_
else
return frame;
}
-
/*! \brief Wait for audiohook trigger to be triggered
* \param audiohook Audiohook to wait on
diff --git a/main/channel.c b/main/channel.c
index fdb88a8d1..f69b29cf2 100644
--- a/main/channel.c
+++ b/main/channel.c
@@ -3162,6 +3162,11 @@ done:
if (chan->music_state && chan->generator && chan->generator->digit && f && f->frametype == AST_FRAME_DTMF_END)
chan->generator->digit(chan, f->subclass);
+ if (chan->audiohooks && ast_audiohook_write_list_empty(chan->audiohooks)) {
+ /* The list gets recreated if audiohooks are added again later */
+ ast_audiohook_detach_list(chan->audiohooks);
+ chan->audiohooks = NULL;
+ }
ast_channel_unlock(chan);
return f;
}
@@ -3851,6 +3856,11 @@ int ast_write(struct ast_channel *chan, struct ast_frame *fr)
chan->fout = FRAMECOUNT_INC(chan->fout);
}
done:
+ if (chan->audiohooks && ast_audiohook_write_list_empty(chan->audiohooks)) {
+ /* The list gets recreated if audiohooks are added again later */
+ ast_audiohook_detach_list(chan->audiohooks);
+ chan->audiohooks = NULL;
+ }
ast_channel_unlock(chan);
return res;
}