[asterisk-commits] channel: Fix issues in hangup scenarios caused by frame def... (asterisk[14])

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Nov 16 16:55:40 CST 2016


Joshua Colp has submitted this change and it was merged. ( https://gerrit.asterisk.org/4427 )

Change subject: channel:  Fix issues in hangup scenarios caused by frame deferral
......................................................................


channel:  Fix issues in hangup scenarios caused by frame deferral

ASTERISK-26343

Change-Id: I06dbf7366e26028251964143454a77d017bb61c8
(cherry picked from commit 0be46aaf6b8b9eb5b0160ec591cdc2c6e1802a6d)
(cherry picked from commit 7263a17ca046923c245296a3cee21df0e4bd499a)
(cherry picked from commit ebf8d94eb2f0d14b824ee6243789870325583624)
---
M include/asterisk/channel.h
M main/autoservice.c
M main/channel.c
3 files changed, 32 insertions(+), 7 deletions(-)

Approvals:
  Kevin Harwell: Looks good to me, but someone else must approve
  George Joseph: Looks good to me, approved
  Anonymous Coward #1000019: Verified
  Joshua Colp: Looks good to me, but someone else must approve



diff --git a/include/asterisk/channel.h b/include/asterisk/channel.h
index cf8c544..a962a5f 100644
--- a/include/asterisk/channel.h
+++ b/include/asterisk/channel.h
@@ -972,6 +972,11 @@
 	 * frames should be deferred.
 	 */
 	AST_FLAG_DEFER_FRAMES = (1 << 28),
+	/*!
+	 * The channel is currently deferring hangup frames
+	 * in addition to other frame types.
+	 */
+	AST_FLAG_DEFER_HANGUP_FRAMES = (1 << 29),
 };
 
 /*! \brief ast_bridge_config flags */
@@ -4680,11 +4685,17 @@
  * drop important frames. This function can be called so that important frames
  * will be deferred, rather than placed in the channel frame queue as normal.
  *
+ * Hangups are an interesting frame type. Hangups will always be detectable by
+ * a reader when a channel is deferring frames. If the defer_hangups parameter
+ * is non-zero, then the hangup frame will also be duplicated and deferred, so
+ * that the next reader of the channel will get the hangup frame, too.
+ *
  * \pre chan MUST be locked before calling
  *
  * \param chan The channel on which frames should be deferred
+ * \param defer_hangups Defer hangups in addition to other deferrable frames
  */
-void ast_channel_start_defer_frames(struct ast_channel *chan);
+void ast_channel_start_defer_frames(struct ast_channel *chan, int defer_hangups);
 
 /*!
  * \brief Stop deferring deferrable frames on this channel
diff --git a/main/autoservice.c b/main/autoservice.c
index 1af052d..a68860d 100644
--- a/main/autoservice.c
+++ b/main/autoservice.c
@@ -217,6 +217,7 @@
 	as->orig_end_dtmf_flag = ast_test_flag(ast_channel_flags(chan), AST_FLAG_END_DTMF_ONLY) ? 1 : 0;
 	if (!as->orig_end_dtmf_flag)
 		ast_set_flag(ast_channel_flags(chan), AST_FLAG_END_DTMF_ONLY);
+	ast_channel_start_defer_frames(chan, 1);
 	ast_channel_unlock(chan);
 
 	AST_LIST_LOCK(&aslist);
diff --git a/main/channel.c b/main/channel.c
index f00f222..52e0a2c 100644
--- a/main/channel.c
+++ b/main/channel.c
@@ -1064,9 +1064,10 @@
 	return tmp;
 }
 
-void ast_channel_start_defer_frames(struct ast_channel *chan)
+void ast_channel_start_defer_frames(struct ast_channel *chan, int defer_hangups)
 {
 	ast_set_flag(ast_channel_flags(chan), AST_FLAG_DEFER_FRAMES);
+	ast_set2_flag(ast_channel_flags(chan), defer_hangups, AST_FLAG_DEFER_HANGUP_FRAMES);
 }
 
 void ast_channel_stop_defer_frames(struct ast_channel *chan)
@@ -1554,6 +1555,10 @@
 	if (ast_opt_transmit_silence && !ast_channel_generatordata(chan)) {
 		silgen = ast_channel_start_silence_generator(chan);
 	}
+
+	ast_channel_lock(chan);
+	ast_channel_start_defer_frames(chan, 0);
+	ast_channel_unlock(chan);
 
 	start = ast_tvnow();
 	while ((ms = ast_remaining_ms(start, timeout_ms))) {
@@ -3907,9 +3912,9 @@
 		if (ast_test_flag(ast_channel_flags(chan), AST_FLAG_DEFER_FRAMES)) {
 			AST_LIST_TRAVERSE_SAFE_BEGIN(ast_channel_readq(chan), f, frame_list) {
 				if (ast_is_deferrable_frame(f)) {
-					if (f->frametype == AST_FRAME_CONTROL && f->subclass.integer == AST_CONTROL_HANGUP) {
-						struct ast_frame *dup;
-
+					if(f->frametype == AST_FRAME_CONTROL && 
+						(f->subclass.integer == AST_CONTROL_HANGUP ||
+						 f->subclass.integer == AST_CONTROL_END_OF_Q)) {
 						/* Hangup is a special case. We want to defer the frame, but we also do not
 						 * want to remove it from the frame queue. So rather than just moving the frame
 						 * over, we duplicate it and move the copy to the deferred readq.
@@ -3919,8 +3924,12 @@
 						 * when frame deferral finishes, then whoever calls ast_read() next will also get
 						 * the hangup.
 						 */
-						dup = ast_frdup(f);
-						AST_LIST_INSERT_TAIL(ast_channel_deferred_readq(chan), dup, frame_list);
+						if (ast_test_flag(ast_channel_flags(chan), AST_FLAG_DEFER_HANGUP_FRAMES)) {
+							struct ast_frame *dup;
+
+							dup = ast_frdup(f);
+							AST_LIST_INSERT_TAIL(ast_channel_deferred_readq(chan), dup, frame_list);
+						}
 					} else {
 						AST_LIST_INSERT_TAIL(ast_channel_deferred_readq(chan), f, frame_list);
 						AST_LIST_REMOVE_CURRENT(frame_list);
@@ -10261,6 +10270,7 @@
 
 		ast_party_connected_line_copy(ast_channel_connected(macro_chan), connected);
 	}
+	ast_channel_start_defer_frames(macro_chan, 0);
 	ast_channel_unlock(macro_chan);
 
 	retval = ast_app_run_macro(autoservice_chan, macro_chan, macro, macro_args);
@@ -10311,6 +10321,7 @@
 
 		ast_party_redirecting_copy(ast_channel_redirecting(macro_chan), redirecting);
 	}
+	ast_channel_start_defer_frames(macro_chan, 0);
 	ast_channel_unlock(macro_chan);
 
 	retval = ast_app_run_macro(autoservice_chan, macro_chan, macro, macro_args);
@@ -10354,6 +10365,7 @@
 
 		ast_party_connected_line_copy(ast_channel_connected(sub_chan), connected);
 	}
+	ast_channel_start_defer_frames(sub_chan, 0);
 	ast_channel_unlock(sub_chan);
 
 	retval = ast_app_run_sub(autoservice_chan, sub_chan, sub, sub_args, 0);
@@ -10397,6 +10409,7 @@
 
 		ast_party_redirecting_copy(ast_channel_redirecting(sub_chan), redirecting);
 	}
+	ast_channel_start_defer_frames(sub_chan, 0);
 	ast_channel_unlock(sub_chan);
 
 	retval = ast_app_run_sub(autoservice_chan, sub_chan, sub, sub_args, 0);

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I06dbf7366e26028251964143454a77d017bb61c8
Gerrit-PatchSet: 1
Gerrit-Project: asterisk
Gerrit-Branch: 14
Gerrit-Owner: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Anonymous Coward #1000019
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
Gerrit-Reviewer: Kevin Harwell <kharwell at digium.com>



More information about the asterisk-commits mailing list