]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FS-11340 export switch_vad_state2str and update vad_test to support the latest params
authorSeven Du <dujinfang@x-y-t.cn>
Tue, 21 Aug 2018 07:24:01 +0000 (15:24 +0800)
committerMike Jerris <mike@jerris.com>
Mon, 24 Sep 2018 20:22:24 +0000 (20:22 +0000)
FS-11340 check the status for read frame avoid crash

src/include/switch_vad.h
src/mod/applications/mod_dptools/mod_dptools.c
src/switch_vad.c

index 8cc6c63f0572378a1047ded07d170e57267080f2..d2a7f4a816c7e1141b09773ae6724dba5975434f 100644 (file)
@@ -52,6 +52,8 @@ SWITCH_DECLARE(switch_vad_state_t) switch_vad_process(switch_vad_t *vad, int16_t
 SWITCH_DECLARE(void) switch_vad_reset(switch_vad_t *vad);
 SWITCH_DECLARE(void) switch_vad_destroy(switch_vad_t **vad);
 
+SWITCH_DECLARE(const char *) switch_vad_state2str(switch_vad_state_t state);
+
 SWITCH_END_EXTERN_C
 #endif
 /* For Emacs:
index b69a0a402562edbca720c8a29550aa35a9ce197e..aa68cb2c5bf5826278f8092daafc12acb08d8f1c 100644 (file)
@@ -6169,14 +6169,27 @@ SWITCH_STANDARD_APP(vad_test_function)
                if (tmp > 0) switch_vad_set_param(vad, "thresh", tmp);
        }
 
-       if ((var = switch_channel_get_variable(channel, "vad_timeout_len"))) {
+       if ((var = switch_channel_get_variable(channel, "vad_listen_hits"))) {
                tmp = atoi(var);
 
-               if (tmp > 0) switch_vad_set_param(vad, "timeout_len", tmp);
+               if (tmp > 0) switch_vad_set_param(vad, "listen_hits", tmp);
        }
 
-       while(switch_channel_ready(channel)) {
-               switch_core_session_read_frame(session, &frame, SWITCH_IO_FLAG_NONE, 0);
+       if ((var = switch_channel_get_variable(channel, "vad_debug"))) {
+               tmp = atoi(var);
+
+               if (tmp < 0) tmp = 0;
+               if (tmp > 1) tmp = 1;
+
+               switch_vad_set_param(vad, "debug", tmp);
+       }
+
+       while (switch_channel_ready(channel)) {
+               switch_status_t status = switch_core_session_read_frame(session, &frame, SWITCH_IO_FLAG_NONE, 0);
+
+               if (!SWITCH_READ_ACCEPTABLE(status)) {
+                       break;
+               }
 
                if (switch_test_flag(frame, SFF_CNG)) {
                        continue;
@@ -6192,7 +6205,7 @@ SWITCH_STANDARD_APP(vad_test_function)
                } else if (vad_state == SWITCH_VAD_STATE_TALKING) {
                        switch_core_session_write_frame(session, frame, SWITCH_IO_FLAG_NONE, 0);
                } else {
-                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "vad_state: %d\n", vad_state);
+                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "vad_state: %s\n", switch_vad_state2str(vad_state));
                }
        }
 
index 0e0e7f09616a0f357522455f2b0af1fe912257ed..b71963052ec6b942af0c4cd4f5811a989da17000 100644 (file)
@@ -57,17 +57,17 @@ struct switch_vad_s {
 #endif
 };
 
-static const char *state2str(switch_vad_state_t state)
+SWITCH_DECLARE(const char *) switch_vad_state2str(switch_vad_state_t state)
 {
        switch(state) {
        case SWITCH_VAD_STATE_NONE:                                                                                                                                      return "none";
-               
+               return "none";
        case SWITCH_VAD_STATE_START_TALKING:                                                                                                                             return "start_talking";
-               
+               return "start-talking";
        case SWITCH_VAD_STATE_TALKING:                                                                                                                                   return "talking";
-               
+               return "talking";
        case SWITCH_VAD_STATE_STOP_TALKING:                                                                                                                              return "stop_talking";
-
+               return "stop-talking";
        default:
                return "error";
        }
@@ -232,7 +232,7 @@ SWITCH_DECLARE(switch_vad_state_t) switch_vad_process(switch_vad_t *vad, int16_t
        }
 
        if (vad->debug > 0) {
-               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "VAD DEBUG energy: %d state %s\n", score, state2str(vad->vad_state));
+               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "VAD DEBUG energy: %d state %s\n", score, switch_vad_state2str(vad->vad_state));
        }
        
        return vad->vad_state;