[Asterisk-code-review] res_musiconhold: Add option to loop last file. (asterisk[master])
N A
asteriskteam at digium.com
Sun Mar 12 15:28:29 CDT 2023
N A has uploaded this change for review. ( https://gerrit.asterisk.org/c/asterisk/+/19968 )
Change subject: res_musiconhold: Add option to loop last file.
......................................................................
res_musiconhold: Add option to loop last file.
Adds the looplast option to res_musiconhold,
which allows the last audio file in the directory
to be looped perpetually once reached, rather than
circling back to the beginning again.
ASTERISK-30462 #close
Change-Id: I5d49058f1b0647238809936e279868e98aeb3dfb
---
M configs/samples/musiconhold.conf.sample
A doc/CHANGES-staging/res_musiconhold_looplast.txt
M res/res_musiconhold.c
3 files changed, 41 insertions(+), 1 deletion(-)
git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/68/19968/1
diff --git a/configs/samples/musiconhold.conf.sample b/configs/samples/musiconhold.conf.sample
index 1737c7a..69c7d12 100644
--- a/configs/samples/musiconhold.conf.sample
+++ b/configs/samples/musiconhold.conf.sample
@@ -82,6 +82,14 @@
; ; in alphabetical order. If 'randstart', the files are sorted
; ; in alphabetical order as well, but the first file is chosen
; ; at random. If unspecified, the sort order is undefined.
+;looplast=no ; If enabled, once the end of the directory is reached,
+ ; the last file played will be looped perpetually, rather than
+ ; starting over at the beginning again.
+ ; Typically used with sort=alpha or randstart so you can control
+ ; which file gets looped (the last one sorted alphabetically).
+ ; (If sort=alpha, all files will be played at least once, but
+ ; this may not be true with sort=randstart.)
+ ; Default is no.
;answeredonly=yes ; Only allow answered channels to have music on hold.
; Enabling this will prevent MOH on unanswered channels.
; (default: "no")
diff --git a/doc/CHANGES-staging/res_musiconhold_looplast.txt b/doc/CHANGES-staging/res_musiconhold_looplast.txt
new file mode 100644
index 0000000..cf6608d
--- /dev/null
+++ b/doc/CHANGES-staging/res_musiconhold_looplast.txt
@@ -0,0 +1,4 @@
+Subject: res_musiconhold
+
+The looplast option now allows the last file
+in the directory to be looped once reached.
diff --git a/res/res_musiconhold.c b/res/res_musiconhold.c
index 6196211..28ca110 100644
--- a/res/res_musiconhold.c
+++ b/res/res_musiconhold.c
@@ -153,6 +153,8 @@
#define MOH_ANNOUNCEMENT (1 << 6) /*!< Do we play announcement files between songs on this channel? */
#define MOH_PREFERCHANNELCLASS (1 << 7) /*!< Should queue moh override channel moh */
+#define MOH_LOOPLAST (1 << 8) /*!< Whether to loop the last file in the music class when we reach the end, rather than starting over */
+
/* Custom astobj2 flag */
#define MOH_NOTDELETED (1 << 30) /*!< Find only records that aren't deleted? */
#define MOH_REALTIME (1 << 31) /*!< Find only records that are realtime */
@@ -366,7 +368,11 @@
} else {
/* This is easy, just increment our position and make sure we don't exceed the total file count */
state->pos++;
- state->pos %= file_count;
+ if (ast_test_flag(state->class, MOH_LOOPLAST)) {
+ state->pos = MIN(file_count - 1, state->pos);
+ } else {
+ state->pos %= file_count;
+ }
state->save_pos = -1;
state->samples = 0;
}
@@ -1172,6 +1178,12 @@
} else if (!strcasecmp(var->value, "randstart")) {
ast_set_flag(mohclass, MOH_RANDSTART);
}
+ } else if (!strcasecmp(var->name, "looplast")) {
+ if (ast_true(var->value)) {
+ ast_set_flag(mohclass, MOH_LOOPLAST);
+ } else {
+ ast_clear_flag(mohclass, MOH_LOOPLAST);
+ }
} else if (!strcasecmp(var->name, "format") && !ast_strlen_zero(var->value)) {
ao2_cleanup(mohclass->format);
mohclass->format = ast_format_cache_get(var->value);
--
To view, visit https://gerrit.asterisk.org/c/asterisk/+/19968
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings
Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Change-Id: I5d49058f1b0647238809936e279868e98aeb3dfb
Gerrit-Change-Number: 19968
Gerrit-PatchSet: 1
Gerrit-Owner: N A <asterisk at phreaknet.org>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20230312/b721f9a8/attachment.html>
More information about the asterisk-code-review
mailing list