]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
remove empty audiohook write list on channel
authorDavid Vossel <dvossel@digium.com>
Tue, 27 Jul 2010 20:33:40 +0000 (20:33 +0000)
committerDavid Vossel <dvossel@digium.com>
Tue, 27 Jul 2010 20:33:40 +0000 (20:33 +0000)
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: https://origsvn.digium.com/svn/asterisk/branches/1.4@279945 65c4cc65-6c06-0410-ace0-fbb531ad65f3

include/asterisk/audiohook.h
main/audiohook.c
main/channel.c

index 7163b944614f5ba6b1db9327310ba8d25b22b316..4bf041f037fc863ff9506aff03d593b5161709d7 100644 (file)
@@ -191,6 +191,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
index 905141850cb8980b40dfba388794eafe54eec42f..1e0841dd519201b77f3e94e261fe3ccf414f51b1 100644 (file)
@@ -725,6 +725,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
@@ -742,7 +753,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
index 62b774a66697781418b309dace4612345712840f..f060fdb59731b5af9ea44f859826560d43bc031d 100644 (file)
@@ -2612,6 +2612,11 @@ static struct ast_frame *__ast_read(struct ast_channel *chan, int dropaudio)
        chan->fin = FRAMECOUNT_INC(chan->fin);
 
 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 f;
 }
@@ -3285,6 +3290,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;
 }