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
This commit is contained in:
Andre Barbosa 2021-06-04 12:11:10 +01:00 committed by Friendly Automation
parent 88da59efe7
commit 283812e492
4 changed files with 23 additions and 2 deletions

View File

@ -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.

View 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. */

View 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,
};

View File

@ -154,7 +154,8 @@
"queued",
"playing",
"continuing",
"done"
"done",
"failed"
]
}
}