<p>Friendly Automation <strong>submitted</strong> this change.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/16118">View Change</a></p><div style="white-space:pre-wrap">Approvals:
George Joseph: Looks good to me, approved
Friendly Automation: Approved for Submit
</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">res_stasis_playback: Send PlaybackFinish event only once for errors<br><br>When we try to play a list of sound files in the same Play command,<br>we get only one PlaybackFinish event, after all sounds are played.<br><br>But in the case where the Play fails (because channel is destroyed<br>for example), Asterisk will send one PlaybackFinish event for each<br>sound file still to be played. If the list is big, Asterisk is<br>sending many events.<br><br>This patch adds a failed state so we can understand that the play<br>failed. On that case we don't send the event, if we still have a<br>list of sounds to be played.<br><br>When we reach the last sound, we send the PlaybackFinish with<br>the failed state.<br><br>ASTERISK-29464 #close<br><br>Change-Id: I4c2e5921cc597702513af0d7c6c2c982e1798322<br>---<br>A doc/CHANGES-staging/res_stasis_playback.txt<br>M include/asterisk/stasis_app_playback.h<br>M res/res_stasis_playback.c<br>M rest-api/api-docs/playbacks.json<br>4 files changed, 23 insertions(+), 2 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/doc/CHANGES-staging/res_stasis_playback.txt b/doc/CHANGES-staging/res_stasis_playback.txt</span><br><span>new file mode 100644</span><br><span>index 0000000..cd5fa11</span><br><span>--- /dev/null</span><br><span>+++ b/doc/CHANGES-staging/res_stasis_playback.txt</span><br><span>@@ -0,0 +1,9 @@</span><br><span style="color: hsl(120, 100%, 40%);">+Subject: PlaybackFinished has a new error state</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+The PlaybackFinished event now has a new state "failed"</span><br><span style="color: hsl(120, 100%, 40%);">+that is used when the sound file was not played due to an error.</span><br><span style="color: hsl(120, 100%, 40%);">+Before the state on PlaybackFinished was always "done".</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+In case of multiple sound files to be played,</span><br><span style="color: hsl(120, 100%, 40%);">+the PlaybackFinished is sent only once in the end of the list,</span><br><span style="color: hsl(120, 100%, 40%);">+even in case of error.</span><br><span>diff --git a/include/asterisk/stasis_app_playback.h b/include/asterisk/stasis_app_playback.h</span><br><span>index 0038fd6..ab49b09 100644</span><br><span>--- a/include/asterisk/stasis_app_playback.h</span><br><span>+++ b/include/asterisk/stasis_app_playback.h</span><br><span>@@ -45,6 +45,8 @@</span><br><span> STASIS_PLAYBACK_STATE_CONTINUING,</span><br><span> /*! The media has stopped playing */</span><br><span> STASIS_PLAYBACK_STATE_COMPLETE,</span><br><span style="color: hsl(120, 100%, 40%);">+ /*! The media has stopped because of an error playing the file */</span><br><span style="color: hsl(120, 100%, 40%);">+ STASIS_PLAYBACK_STATE_FAILED,</span><br><span> /*! The playback was canceled. */</span><br><span> STASIS_PLAYBACK_STATE_CANCELED,</span><br><span> /*! The playback was stopped. */</span><br><span>diff --git a/res/res_stasis_playback.c b/res/res_stasis_playback.c</span><br><span>index d60a49a..2013bb7 100644</span><br><span>--- a/res/res_stasis_playback.c</span><br><span>+++ b/res/res_stasis_playback.c</span><br><span>@@ -107,6 +107,8 @@</span><br><span> type = "PlaybackContinuing";</span><br><span> } else if (!strcmp(state, "done")) {</span><br><span> type = "PlaybackFinished";</span><br><span style="color: hsl(120, 100%, 40%);">+ } else if (!strcmp(state, "failed")) {</span><br><span style="color: hsl(120, 100%, 40%);">+ type = "PlaybackFinished";</span><br><span> } else {</span><br><span> return NULL;</span><br><span> }</span><br><span>@@ -202,6 +204,8 @@</span><br><span> return "paused";</span><br><span> case STASIS_PLAYBACK_STATE_CONTINUING:</span><br><span> return "continuing";</span><br><span style="color: hsl(120, 100%, 40%);">+ case STASIS_PLAYBACK_STATE_FAILED:</span><br><span style="color: hsl(120, 100%, 40%);">+ return "failed";</span><br><span> case STASIS_PLAYBACK_STATE_STOPPED:</span><br><span> case STASIS_PLAYBACK_STATE_COMPLETE:</span><br><span> case STASIS_PLAYBACK_STATE_CANCELED:</span><br><span>@@ -275,7 +279,11 @@</span><br><span> } else {</span><br><span> ast_log(LOG_WARNING, "%s: Playback failed for %s\n",</span><br><span> uniqueid, playback->media);</span><br><span style="color: hsl(0, 100%, 40%);">- playback->state = STASIS_PLAYBACK_STATE_STOPPED;</span><br><span style="color: hsl(120, 100%, 40%);">+ if (playback->media_index == AST_VECTOR_SIZE(&playback->medias) - 1) {</span><br><span style="color: hsl(120, 100%, 40%);">+ playback->state = STASIS_PLAYBACK_STATE_FAILED;</span><br><span style="color: hsl(120, 100%, 40%);">+ } else {</span><br><span style="color: hsl(120, 100%, 40%);">+ playback->state = STASIS_PLAYBACK_STATE_CONTINUING;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span> }</span><br><span> }</span><br><span> </span><br><span>@@ -701,6 +709,7 @@</span><br><span> [STASIS_PLAYBACK_STATE_PAUSED][STASIS_PLAYBACK_UNPAUSE] = playback_unpause,</span><br><span> </span><br><span> [STASIS_PLAYBACK_STATE_COMPLETE][STASIS_PLAYBACK_STOP] = playback_noop,</span><br><span style="color: hsl(120, 100%, 40%);">+ [STASIS_PLAYBACK_STATE_FAILED][STASIS_PLAYBACK_STOP] = playback_noop,</span><br><span> [STASIS_PLAYBACK_STATE_CANCELED][STASIS_PLAYBACK_STOP] = playback_noop,</span><br><span> [STASIS_PLAYBACK_STATE_STOPPED][STASIS_PLAYBACK_STOP] = playback_noop,</span><br><span> };</span><br><span>diff --git a/rest-api/api-docs/playbacks.json b/rest-api/api-docs/playbacks.json</span><br><span>index a78dcae..793986f 100644</span><br><span>--- a/rest-api/api-docs/playbacks.json</span><br><span>+++ b/rest-api/api-docs/playbacks.json</span><br><span>@@ -154,7 +154,8 @@</span><br><span> "queued",</span><br><span> "playing",</span><br><span> "continuing",</span><br><span style="color: hsl(0, 100%, 40%);">- "done"</span><br><span style="color: hsl(120, 100%, 40%);">+ "done",</span><br><span style="color: hsl(120, 100%, 40%);">+ "failed"</span><br><span> ]</span><br><span> }</span><br><span> }</span><br><span></span><br></pre><div style="white-space:pre-wrap"></div><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/16118">change 16118</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/c/asterisk/+/16118"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 16 </div>
<div style="display:none"> Gerrit-Change-Id: I4c2e5921cc597702513af0d7c6c2c982e1798322 </div>
<div style="display:none"> Gerrit-Change-Number: 16118 </div>
<div style="display:none"> Gerrit-PatchSet: 2 </div>
<div style="display:none"> Gerrit-Owner: Andre Barbosa <andre.emanuel.barbosa@gmail.com> </div>
<div style="display:none"> Gerrit-Reviewer: Friendly Automation </div>
<div style="display:none"> Gerrit-Reviewer: George Joseph <gjoseph@sangoma.com> </div>
<div style="display:none"> Gerrit-MessageType: merged </div>