[Asterisk-code-review] res_stasis_playback: Check for chan hangup on play_on_channels (asterisk[16])

Andre Barbosa asteriskteam at digium.com
Tue Jul 20 03:00:27 CDT 2021


Andre Barbosa has uploaded this change for review. ( https://gerrit.asterisk.org/c/asterisk/+/16180 )


Change subject: res_stasis_playback: Check for chan hangup on play_on_channels
......................................................................

res_stasis_playback: Check for chan hangup on play_on_channels

Verify `ast_check_hangup` before looping to the next sound file.
If the call is already hangup we just break the cycle.
It also ensures that the PlaybackFinished event is sent if the call was hangup.

This is also use-full when we are playing a big list of file for a channel that is hangup.
Before this patch Asterisk will give a warning for every sound not played and fire a PlaybackStart for every sound file on the list tried to be played.

With the patch we just break the playback cycle when the chan is hangup.

ASTERISK-29501 #close

Change-Id: Ic4e1c01b974c9a1f2d9678c9d6b380bcfc69feb8
---
M res/res_stasis_playback.c
1 file changed, 13 insertions(+), 4 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/80/16180/1

diff --git a/res/res_stasis_playback.c b/res/res_stasis_playback.c
index 2013bb7..d558e18 100644
--- a/res/res_stasis_playback.c
+++ b/res/res_stasis_playback.c
@@ -261,13 +261,13 @@
 }
 
 static void playback_final_update(struct stasis_app_playback *playback,
-	long playedms, int res, const char *uniqueid)
+	long playedms, int res, int hangup, const char *uniqueid)
 {
 	SCOPED_AO2LOCK(lock, playback);
 
 	playback->playedms = playedms;
 	if (res == 0) {
-		if (playback->media_index == AST_VECTOR_SIZE(&playback->medias) - 1) {
+		if (playback->media_index == AST_VECTOR_SIZE(&playback->medias) - 1 || hangup ) {
 			playback->state = STASIS_PLAYBACK_STATE_COMPLETE;
 		} else {
 			playback->state = STASIS_PLAYBACK_STATE_CONTINUING;
@@ -279,7 +279,7 @@
 		} else {
 			ast_log(LOG_WARNING, "%s: Playback failed for %s\n",
 				uniqueid, playback->media);
-			if (playback->media_index == AST_VECTOR_SIZE(&playback->medias) - 1) {
+			if (playback->media_index == AST_VECTOR_SIZE(&playback->medias) - 1 || hangup ) {
 				playback->state = STASIS_PLAYBACK_STATE_FAILED;
 			} else {
 				playback->state = STASIS_PLAYBACK_STATE_CONTINUING;
@@ -294,6 +294,7 @@
 	struct ast_channel *chan)
 {
 	int res;
+	int hangup;
 	long offsetms;
 	size_t index;
 
@@ -377,8 +378,16 @@
 			continue;
 		}
 
-		playback_final_update(playback, offsetms, res,
+		hangup = ast_check_hangup(chan);
+
+		playback_final_update(playback, offsetms, res, hangup,
 			ast_channel_uniqueid(chan));
+
+		if (hangup) {
+			ast_log(LOG_DEBUG, "Channel: %s already hangup, stop playback\n", ast_channel_name(chan));
+			break;
+		}
+
 		if (res == AST_CONTROL_STREAM_STOP) {
 			break;
 		}

-- 
To view, visit https://gerrit.asterisk.org/c/asterisk/+/16180
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 16
Gerrit-Change-Id: Ic4e1c01b974c9a1f2d9678c9d6b380bcfc69feb8
Gerrit-Change-Number: 16180
Gerrit-PatchSet: 1
Gerrit-Owner: Andre Barbosa <andre.emanuel.barbosa at gmail.com>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20210720/025d27ae/attachment.html>


More information about the asterisk-code-review mailing list