[Asterisk-code-review] res_stasis_playback: Send PlaybackFinish event only once for errors (asterisk[18])

Friendly Automation asteriskteam at digium.com
Thu Jun 24 08:56:09 CDT 2021


Friendly Automation has submitted this change. ( https://gerrit.asterisk.org/c/asterisk/+/16117 )

Change subject: res_stasis_playback: Send PlaybackFinish event only once for errors
......................................................................

res_stasis_playback: Send PlaybackFinish event only once for errors

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 many events.

This patch adds a failed 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 send the PlaybackFinish with
the failed state.

ASTERISK-29464 #close

Change-Id: I4c2e5921cc597702513af0d7c6c2c982e1798322
---
A doc/CHANGES-staging/res_stasis_playback.txt
M include/asterisk/stasis_app_playback.h
M res/res_stasis_playback.c
M rest-api/api-docs/playbacks.json
4 files changed, 23 insertions(+), 2 deletions(-)

Approvals:
  George Joseph: Looks good to me, approved
  Friendly Automation: Approved for Submit



diff --git a/doc/CHANGES-staging/res_stasis_playback.txt b/doc/CHANGES-staging/res_stasis_playback.txt
new file mode 100644
index 0000000..cd5fa11
--- /dev/null
+++ b/doc/CHANGES-staging/res_stasis_playback.txt
@@ -0,0 +1,9 @@
+Subject: PlaybackFinished has a new error state
+
+The PlaybackFinished event now has a new state "failed"
+that is used when the sound file was not played due to an error.
+Before the state on PlaybackFinished was always "done".
+
+In case of multiple sound files to be played,
+the PlaybackFinished is sent only once in the end of the list,
+even in case of error.
diff --git a/include/asterisk/stasis_app_playback.h b/include/asterisk/stasis_app_playback.h
index 0038fd6..ab49b09 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_FAILED,
 	/*! 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..2013bb7 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, "failed")) {
+		type = "PlaybackFinished";
 	} else {
 		return NULL;
 	}
@@ -202,6 +204,8 @@
 		return "paused";
 	case STASIS_PLAYBACK_STATE_CONTINUING:
 		return "continuing";
+	case STASIS_PLAYBACK_STATE_FAILED:
+		return "failed";
 	case STASIS_PLAYBACK_STATE_STOPPED:
 	case STASIS_PLAYBACK_STATE_COMPLETE:
 	case STASIS_PLAYBACK_STATE_CANCELED:
@@ -275,7 +279,11 @@
 		} 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_FAILED;
+			} else {
+				playback->state = STASIS_PLAYBACK_STATE_CONTINUING;
+			}
 		}
 	}
 
@@ -701,6 +709,7 @@
 	[STASIS_PLAYBACK_STATE_PAUSED][STASIS_PLAYBACK_UNPAUSE] = playback_unpause,
 
 	[STASIS_PLAYBACK_STATE_COMPLETE][STASIS_PLAYBACK_STOP] = playback_noop,
+	[STASIS_PLAYBACK_STATE_FAILED][STASIS_PLAYBACK_STOP] = playback_noop,
 	[STASIS_PLAYBACK_STATE_CANCELED][STASIS_PLAYBACK_STOP] = playback_noop,
 	[STASIS_PLAYBACK_STATE_STOPPED][STASIS_PLAYBACK_STOP] = playback_noop,
 };
diff --git a/rest-api/api-docs/playbacks.json b/rest-api/api-docs/playbacks.json
index a78dcae..793986f 100644
--- a/rest-api/api-docs/playbacks.json
+++ b/rest-api/api-docs/playbacks.json
@@ -154,7 +154,8 @@
 							"queued",
 							"playing",
 							"continuing",
-							"done"
+							"done",
+							"failed"
 						]
 					}
 				}

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

Gerrit-Project: asterisk
Gerrit-Branch: 18
Gerrit-Change-Id: I4c2e5921cc597702513af0d7c6c2c982e1798322
Gerrit-Change-Number: 16117
Gerrit-PatchSet: 2
Gerrit-Owner: Andre Barbosa <andre.emanuel.barbosa at gmail.com>
Gerrit-Reviewer: Friendly Automation
Gerrit-Reviewer: George Joseph <gjoseph at sangoma.com>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20210624/a1668541/attachment-0001.html>


More information about the asterisk-code-review mailing list