[Asterisk-code-review] res_stasis_playback (asterisk[master])

Andre Barbosa asteriskteam at digium.com
Fri Jun 4 06:13:57 CDT 2021


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


Change subject: res_stasis_playback
......................................................................

res_stasis_playback

When we try to play a list of sound files in the same Play command, we get only one PlaybackFinish event, after all sounds are played.

But in the case where the Play fails (because channel is destroyed for example), Asterisk will send one PlaybackFinish event for each sound file still to be played. If the list is big, Asterisk is sending lot of events.

This patch adds STASIS_PLAYBACK_STATE_ERROR state so we can understand that the play failed. On that case we don't send the event, if we still have a list of sounds to be played.

When we reach the last sound, we fired the PlaybackFinish with the error state.

ASTERISK-29464 #close

Change-Id: I4c2e5921cc597702513af0d7c6c2c982e1798322
---
M include/asterisk/stasis_app_playback.h
M res/res_stasis_playback.c
2 files changed, 13 insertions(+), 1 deletion(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/87/15987/1

diff --git a/include/asterisk/stasis_app_playback.h b/include/asterisk/stasis_app_playback.h
index 0038fd6..110a516 100644
--- a/include/asterisk/stasis_app_playback.h
+++ b/include/asterisk/stasis_app_playback.h
@@ -45,6 +45,8 @@
 	STASIS_PLAYBACK_STATE_CONTINUING,
 	/*! The media has stopped playing */
 	STASIS_PLAYBACK_STATE_COMPLETE,
+	/*! The media has stopped because of an error playing the file */
+	STASIS_PLAYBACK_STATE_ERROR,
 	/*! The playback was canceled. */
 	STASIS_PLAYBACK_STATE_CANCELED,
 	/*! The playback was stopped. */
diff --git a/res/res_stasis_playback.c b/res/res_stasis_playback.c
index d60a49a..f479a38 100644
--- a/res/res_stasis_playback.c
+++ b/res/res_stasis_playback.c
@@ -107,6 +107,8 @@
 		type = "PlaybackContinuing";
 	} else if (!strcmp(state, "done")) {
 		type = "PlaybackFinished";
+	} else if (!strcmp(state, "error")) {
+		type = "PlaybackFinished";		
 	} else {
 		return NULL;
 	}
@@ -202,6 +204,8 @@
 		return "paused";
 	case STASIS_PLAYBACK_STATE_CONTINUING:
 		return "continuing";
+	case STASIS_PLAYBACK_STATE_ERROR:
+		return "error";		
 	case STASIS_PLAYBACK_STATE_STOPPED:
 	case STASIS_PLAYBACK_STATE_COMPLETE:
 	case STASIS_PLAYBACK_STATE_CANCELED:
@@ -275,7 +279,12 @@
 		} else {
 			ast_log(LOG_WARNING, "%s: Playback failed for %s\n",
 				uniqueid, playback->media);
-			playback->state = STASIS_PLAYBACK_STATE_STOPPED;
+				
+			if (playback->media_index == AST_VECTOR_SIZE(&playback->medias) - 1) {
+				playback->state = STASIS_PLAYBACK_STATE_ERROR;
+			} else {
+				playback->state = STASIS_PLAYBACK_STATE_CONTINUING;
+			}
 		}
 	}
 
@@ -701,6 +710,7 @@
 	[STASIS_PLAYBACK_STATE_PAUSED][STASIS_PLAYBACK_UNPAUSE] = playback_unpause,
 
 	[STASIS_PLAYBACK_STATE_COMPLETE][STASIS_PLAYBACK_STOP] = playback_noop,
+	[STASIS_PLAYBACK_STATE_ERROR][STASIS_PLAYBACK_STOP] = playback_noop,
 	[STASIS_PLAYBACK_STATE_CANCELED][STASIS_PLAYBACK_STOP] = playback_noop,
 	[STASIS_PLAYBACK_STATE_STOPPED][STASIS_PLAYBACK_STOP] = playback_noop,
 };

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

Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Change-Id: I4c2e5921cc597702513af0d7c6c2c982e1798322
Gerrit-Change-Number: 15987
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/20210604/a4106f12/attachment-0001.html>


More information about the asterisk-code-review mailing list