]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FS-9933: [freeswitch-core] Fallback from native file failure to alternate ext #resolve
authorAnthony Minessale <anthm@freeswitch.org>
Tue, 10 Jan 2017 23:00:18 +0000 (17:00 -0600)
committerAnthony Minessale <anthm@freeswitch.org>
Tue, 10 Jan 2017 23:00:18 +0000 (17:00 -0600)
src/switch_ivr_play_say.c

index f034f80a979c107fa6770e80b7acf793b65395c5..db5873c04344a36706214c68c4ac5798c033adc8 100644 (file)
@@ -1169,6 +1169,8 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_play_file(switch_core_session_t *sess
        const char *p;
        //char *title = "", *copyright = "", *software = "", *artist = "", *comment = "", *date = "";
        char *ext;
+       char *backup_file = NULL;
+       const char *backup_ext;
        const char *prefix;
        const char *timer_name;
        const char *prebuf;
@@ -1371,7 +1373,13 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_play_file(switch_core_session_t *sess
                        if ((ext = strrchr(file, '.'))) {
                                ext++;
                        } else {
+
+                               if (!(backup_ext = switch_channel_get_variable(channel, "native_backup_extension"))) {
+                                       backup_ext = "wav";
+                               }
+
                                ext = read_impl.iananame;
+                               backup_file = switch_core_session_sprintf(session, "%s.%s", file, backup_ext);
                                file = switch_core_session_sprintf(session, "%s.%s", file, ext);
                        }
                }
@@ -1395,10 +1403,24 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_play_file(switch_core_session_t *sess
                        //switch_channel_set_flag_recursive(channel, CF_VIDEO_DECODED_READ);
                }
 
-               if (switch_core_file_open(fh,
-                                                                 file,
-                                                                 read_impl.number_of_channels,
-                                                                 read_impl.actual_samples_per_second, flags, NULL) != SWITCH_STATUS_SUCCESS) {
+
+               for(;;) {
+                       if (switch_core_file_open(fh,
+                                                                         file,
+                                                                         read_impl.number_of_channels,
+                                                                         read_impl.actual_samples_per_second, flags, NULL) == SWITCH_STATUS_SUCCESS) {
+                               break;
+                       }
+
+                       if (backup_file) {
+                               file = backup_file;
+                               backup_file = NULL;
+                       } else {
+                               break;
+                       }
+               }
+
+               if (!switch_test_flag(fh, SWITCH_FILE_OPEN)) {
                        switch_core_session_reset(session, SWITCH_TRUE, SWITCH_FALSE);
                        status = SWITCH_STATUS_NOTFOUND;
                        continue;