]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
res_stasis_playback: Send PlaybackFinish event only once for errors
authorAndre Barbosa <andre.emanuel.barbosa@gmail.com>
Fri, 4 Jun 2021 11:11:10 +0000 (12:11 +0100)
committerGeorge Joseph <gjoseph@sangoma.com>
Thu, 24 Jun 2021 15:43:19 +0000 (10:43 -0500)
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

doc/CHANGES-staging/res_stasis_playback.txt [new file with mode: 0644]
include/asterisk/stasis_app_playback.h
res/res_stasis_playback.c
rest-api/api-docs/playbacks.json

diff --git a/doc/CHANGES-staging/res_stasis_playback.txt b/doc/CHANGES-staging/res_stasis_playback.txt
new file mode 100644 (file)
index 0000000..cd5fa11
--- /dev/null
@@ -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.
index 0038fd6d0810bbead8249570d16e6ae523ae49fd..ab49b09ab7d80af896369df89fb2cb6deb571137 100644 (file)
@@ -45,6 +45,8 @@ enum stasis_app_playback_state {
        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. */
index d60a49a519c2e7718a15e2ed482811db2ba21df2..2013bb717a0a6841c6a5c6278ef39983cc479fb8 100644 (file)
@@ -107,6 +107,8 @@ static struct ast_json *playback_to_json(struct stasis_message *message,
                type = "PlaybackContinuing";
        } else if (!strcmp(state, "done")) {
                type = "PlaybackFinished";
+       } else if (!strcmp(state, "failed")) {
+               type = "PlaybackFinished";
        } else {
                return NULL;
        }
@@ -202,6 +204,8 @@ static const char *state_to_string(enum stasis_app_playback_state state)
                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 @@ static void playback_final_update(struct stasis_app_playback *playback,
                } 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 @@ playback_opreation_cb operations[STASIS_PLAYBACK_STATE_MAX][STASIS_PLAYBACK_MEDI
        [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,
 };
index a78dcae7103ae90f958a2fa0d7e91796f300a901..793986fcca79555c225584c82280e13a962b01be 100644 (file)
                                                        "queued",
                                                        "playing",
                                                        "continuing",
-                                                       "done"
+                                                       "done",
+                                                       "failed"
                                                ]
                                        }
                                }