<p>N A has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/19968">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">res_musiconhold: Add option to loop last file.<br><br>Adds the looplast option to res_musiconhold,<br>which allows the last audio file in the directory<br>to be looped perpetually once reached, rather than<br>circling back to the beginning again.<br><br>ASTERISK-30462 #close<br><br>Change-Id: I5d49058f1b0647238809936e279868e98aeb3dfb<br>---<br>M configs/samples/musiconhold.conf.sample<br>A doc/CHANGES-staging/res_musiconhold_looplast.txt<br>M res/res_musiconhold.c<br>3 files changed, 41 insertions(+), 1 deletion(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/68/19968/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/configs/samples/musiconhold.conf.sample b/configs/samples/musiconhold.conf.sample</span><br><span>index 1737c7a..69c7d12 100644</span><br><span>--- a/configs/samples/musiconhold.conf.sample</span><br><span>+++ b/configs/samples/musiconhold.conf.sample</span><br><span>@@ -82,6 +82,14 @@</span><br><span> ; ; in alphabetical order. If 'randstart', the files are sorted</span><br><span> ; ; in alphabetical order as well, but the first file is chosen</span><br><span> ; ; at random. If unspecified, the sort order is undefined.</span><br><span style="color: hsl(120, 100%, 40%);">+;looplast=no ; If enabled, once the end of the directory is reached,</span><br><span style="color: hsl(120, 100%, 40%);">+ ; the last file played will be looped perpetually, rather than</span><br><span style="color: hsl(120, 100%, 40%);">+ ; starting over at the beginning again.</span><br><span style="color: hsl(120, 100%, 40%);">+ ; Typically used with sort=alpha or randstart so you can control</span><br><span style="color: hsl(120, 100%, 40%);">+ ; which file gets looped (the last one sorted alphabetically).</span><br><span style="color: hsl(120, 100%, 40%);">+ ; (If sort=alpha, all files will be played at least once, but</span><br><span style="color: hsl(120, 100%, 40%);">+ ; this may not be true with sort=randstart.)</span><br><span style="color: hsl(120, 100%, 40%);">+ ; Default is no.</span><br><span> ;answeredonly=yes ; Only allow answered channels to have music on hold.</span><br><span> ; Enabling this will prevent MOH on unanswered channels.</span><br><span> ; (default: "no")</span><br><span>diff --git a/doc/CHANGES-staging/res_musiconhold_looplast.txt b/doc/CHANGES-staging/res_musiconhold_looplast.txt</span><br><span>new file mode 100644</span><br><span>index 0000000..cf6608d</span><br><span>--- /dev/null</span><br><span>+++ b/doc/CHANGES-staging/res_musiconhold_looplast.txt</span><br><span>@@ -0,0 +1,4 @@</span><br><span style="color: hsl(120, 100%, 40%);">+Subject: res_musiconhold</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+The looplast option now allows the last file</span><br><span style="color: hsl(120, 100%, 40%);">+in the directory to be looped once reached.</span><br><span>diff --git a/res/res_musiconhold.c b/res/res_musiconhold.c</span><br><span>index 6196211..28ca110 100644</span><br><span>--- a/res/res_musiconhold.c</span><br><span>+++ b/res/res_musiconhold.c</span><br><span>@@ -153,6 +153,8 @@</span><br><span> #define MOH_ANNOUNCEMENT (1 << 6) /*!< Do we play announcement files between songs on this channel? */</span><br><span> #define MOH_PREFERCHANNELCLASS (1 << 7) /*!< Should queue moh override channel moh */</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+#define MOH_LOOPLAST (1 << 8) /*!< Whether to loop the last file in the music class when we reach the end, rather than starting over */</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> /* Custom astobj2 flag */</span><br><span> #define MOH_NOTDELETED (1 << 30) /*!< Find only records that aren't deleted? */</span><br><span> #define MOH_REALTIME (1 << 31) /*!< Find only records that are realtime */</span><br><span>@@ -366,7 +368,11 @@</span><br><span> } else {</span><br><span> /* This is easy, just increment our position and make sure we don't exceed the total file count */</span><br><span> state->pos++;</span><br><span style="color: hsl(0, 100%, 40%);">- state->pos %= file_count;</span><br><span style="color: hsl(120, 100%, 40%);">+ if (ast_test_flag(state->class, MOH_LOOPLAST)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ state->pos = MIN(file_count - 1, state->pos);</span><br><span style="color: hsl(120, 100%, 40%);">+ } else {</span><br><span style="color: hsl(120, 100%, 40%);">+ state->pos %= file_count;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span> state->save_pos = -1;</span><br><span> state->samples = 0;</span><br><span> }</span><br><span>@@ -1172,6 +1178,12 @@</span><br><span> } else if (!strcasecmp(var->value, "randstart")) {</span><br><span> ast_set_flag(mohclass, MOH_RANDSTART);</span><br><span> }</span><br><span style="color: hsl(120, 100%, 40%);">+ } else if (!strcasecmp(var->name, "looplast")) {</span><br><span style="color: hsl(120, 100%, 40%);">+ if (ast_true(var->value)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_set_flag(mohclass, MOH_LOOPLAST);</span><br><span style="color: hsl(120, 100%, 40%);">+ } else {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_clear_flag(mohclass, MOH_LOOPLAST);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span> } else if (!strcasecmp(var->name, "format") && !ast_strlen_zero(var->value)) {</span><br><span> ao2_cleanup(mohclass->format);</span><br><span> mohclass->format = ast_format_cache_get(var->value);</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/19968">change 19968</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/+/19968"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-Change-Id: I5d49058f1b0647238809936e279868e98aeb3dfb </div>
<div style="display:none"> Gerrit-Change-Number: 19968 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: N A <asterisk@phreaknet.org> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>