Resume playing existing hold music for cached realtime MOH
authorTerry Wilson <twilson@digium.com>
Wed, 23 Nov 2011 16:12:34 +0000 (16:12 +0000)
committerTerry Wilson <twilson@digium.com>
Wed, 23 Nov 2011 16:12:34 +0000 (16:12 +0000)
As a result of the fix for ASTERISK-18039, realtime caching MOH no longer
properly resumes playing back a file between different holds in the same call.
This is because scanning for new files causes the existing file array to be
emptied and we were just comparing that the saved pointer to the filename
matched the pointer to the filename in a particular position in the array. An
easy fix is to save the filename instead of a pointer to it and then do a
strcmp instead of comparing the addresses.

(closes issue ASTERISK-18912)
Review: https://reviewboard.asterisk.org/r/1596/
........

Merged revisions 346030 from http://svn.asterisk.org/svn/asterisk/branches/1.8
........

Merged revisions 346031 from http://svn.asterisk.org/svn/asterisk/branches/10

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@346033 65c4cc65-6c06-0410-ace0-fbb531ad65f3

res/res_musiconhold.c

index a857b9a..d5f9e2c 100644 (file)
@@ -163,7 +163,7 @@ struct moh_files_state {
        int pos;
        int save_pos;
        int save_total;
-       char *save_pos_filename;
+       char save_pos_filename[PATH_MAX];
 };
 
 #define MOH_QUIET              (1 << 0)
@@ -298,10 +298,10 @@ static int ast_moh_files_next(struct ast_channel *chan)
                return -1;
        }
 
-       if (state->pos == 0 && state->save_pos_filename == NULL) {
+       if (state->pos == 0 && ast_strlen_zero(state->save_pos_filename)) {
                /* First time so lets play the file. */
                state->save_pos = -1;
-       } else if (state->save_pos >= 0 && state->save_pos < state->class->total_files && state->class->filearray[state->save_pos] == state->save_pos_filename) {
+       } else if (state->save_pos >= 0 && state->save_pos < state->class->total_files && !strcmp(state->class->filearray[state->save_pos], state->save_pos_filename)) {
                /* If a specific file has been saved confirm it still exists and that it is still valid */
                state->pos = state->save_pos;
                state->save_pos = -1;
@@ -338,7 +338,7 @@ static int ast_moh_files_next(struct ast_channel *chan)
        }
 
        /* Record the pointer to the filename for position resuming later */
-       state->save_pos_filename = state->class->filearray[state->pos];
+       ast_copy_string(state->save_pos_filename, state->class->filearray[state->pos], sizeof(state->save_pos_filename));
 
        ast_debug(1, "%s Opened file %d '%s'\n", chan->name, state->pos, state->class->filearray[state->pos]);