Author: rmudgett
Date: Mon Aug 25 11:00:12 2014
New Revision: 421976

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=421976
Log:
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/

Modified:
    branches/1.8/res/res_musiconhold.c

Modified: branches/1.8/res/res_musiconhold.c
URL: 
http://svnview.digium.com/svn/asterisk/branches/1.8/res/res_musiconhold.c?view=diff&rev=421976&r1=421975&r2=421976
==============================================================================
--- branches/1.8/res/res_musiconhold.c (original)
+++ branches/1.8/res/res_musiconhold.c Mon Aug 25 11:00:12 2014
@@ -155,11 +155,13 @@
 struct moh_files_state {
        /*! Holds a reference to the MOH class. */
        struct mohclass *class;
+       char name[MAX_MUSICCLASS];
        format_t origwfmt;
        int samples;
        int sample_queue;
        int pos;
        int save_pos;
+       int save_total;
        char save_pos_filename[PATH_MAX];
 };
 
@@ -416,11 +418,9 @@
                }
        }
 
-       /* 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;
@@ -429,6 +429,9 @@
 
        state->class = mohclass_ref(class, "Reffing music class for channel");
        state->origwfmt = chan->writeformat;
+       /* 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, 
chan->name);
        


-- 
_____________________________________________________________________
-- Bandwidth and Colocation Provided by http://www.api-digital.com --

svn-commits mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/svn-commits

Reply via email to