From b3572f38280a5f7c1383b4c03722764987d4263c Mon Sep 17 00:00:00 2001 From: Richard Mudgett <rmudgett@digium.com> Date: Mon, 25 Aug 2014 16:07:28 +0000 Subject: [PATCH] res_musiconhold: Fix MOH restarting where it left off from the last hold. Restore code removed by https://reviewboard.asterisk.org/r/3536/ that introduced a regression that prevents MOH from restarting were it left off the last time. ASTERISK-24019 #close Reported by: Jason Richards Patches: jira_asterisk_24019_v1.8.patch (license #5621) patch uploaded by rmudgett Review: https://reviewboard.asterisk.org/r/3928/ ........ Merged revisions 421976 from http://svn.asterisk.org/svn/asterisk/branches/1.8 git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/11@421977 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- res/res_musiconhold.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/res/res_musiconhold.c b/res/res_musiconhold.c index 7b66b522e1..dbf2c60568 100644 --- a/res/res_musiconhold.c +++ b/res/res_musiconhold.c @@ -162,6 +162,8 @@ struct moh_files_state { int sample_queue; int pos; int save_pos; + int save_total; + char name[MAX_MUSICCLASS]; char save_pos_filename[PATH_MAX]; }; @@ -452,11 +454,9 @@ static void *moh_files_alloc(struct ast_channel *chan, void *params) } } - /* class is reffed, so we can safely compare it against the (possibly - * recently unreffed) state->class. The unref was done after the ref - * of class, so we're sure that they won't point to the same memory - * by accident. */ - if (state->class != class) { + /* Resume MOH from where we left off last time or start from scratch? */ + if (state->save_total != class->total_files || strcmp(state->name, class->name) != 0) { + /* Start MOH from scratch. */ memset(state, 0, sizeof(*state)); if (ast_test_flag(class, MOH_RANDOMIZE) && class->total_files) { state->pos = ast_random() % class->total_files; @@ -466,6 +466,9 @@ static void *moh_files_alloc(struct ast_channel *chan, void *params) state->class = mohclass_ref(class, "Reffing music class for channel"); ast_format_copy(&state->origwfmt, ast_channel_writeformat(chan)); ast_format_copy(&state->mohwfmt, ast_channel_writeformat(chan)); + /* For comparison on restart of MOH (see above) */ + ast_copy_string(state->name, class->name, sizeof(state->name)); + state->save_total = class->total_files; ast_verb(3, "Started music on hold, class '%s', on %s\n", class->name, ast_channel_name(chan)); -- GitLab