]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FS-11014 fix fvad_free and validate vad_mode
authorSeven Du <dujinfang@gmail.com>
Thu, 19 Jul 2018 01:23:29 +0000 (09:23 +0800)
committerMuteesa Fred <muteesafred@hotmail.com>
Tue, 24 Jul 2018 07:21:58 +0000 (07:21 +0000)
src/switch_vad.c

index c22ed2f352e61e28e34f43a51bc735414c3d6c97..8d12c3bdb133608cca76b914ea7370cbdb4381b3 100644 (file)
@@ -75,17 +75,32 @@ SWITCH_DECLARE(switch_vad_t *) switch_vad_init(int sample_rate, int channels)
        return vad;
 }
 
-//Valid modes are 0 ("quality"), 1 ("low bitrate"), 2 ("aggressive"), and 3 * ("very aggressive"). The default mode is 0.
 SWITCH_DECLARE(int) switch_vad_set_mode(switch_vad_t *vad, int mode)
 {
 #ifdef SWITCH_HAVE_FVAD
-       int ret;
+       int ret = 0;
+
+       if (mode < 0 && vad->fvad) {
+               fvad_free(vad->fvad);
+               vad->fvad = NULL;
+               return ret;
+       } else if (mode > 3) {
+               mode = 3;
+       }
+
+       if (!vad->fvad) {
+               vad->fvad = fvad_new();
 
-       if (mode < 0) return 0;
+               if (!vad->fvad) {
+                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "libfvad init error\n");
+               }
+       }
+
+       if (vad->fvad) {
+               ret = fvad_set_mode(vad->fvad, mode);
+               fvad_set_sample_rate(vad->fvad, vad->sample_rate);
+       }
 
-       vad->fvad = fvad_new();
-       ret = fvad_set_mode(vad->fvad, mode);
-       fvad_set_sample_rate(vad->fvad, vad->sample_rate);
        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "libfvad started, mode = %d\n", mode);
        return ret;
 #else
@@ -210,7 +225,7 @@ SWITCH_DECLARE(void) switch_vad_destroy(switch_vad_t **vad)
        if (*vad) {
 
 #ifdef SWITCH_HAVE_FVAD
-               if ((*vad)->fvad) free ((*vad)->fvad);
+               if ((*vad)->fvad) fvad_free ((*vad)->fvad);
 #endif
 
                free(*vad);