]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FS-8770 #resolve [media_bug_answer_req=true results in a file being created for unans...
authorAnthony Minessale <anthm@freeswitch.org>
Tue, 26 Jan 2016 17:00:41 +0000 (11:00 -0600)
committerAnthony Minessale <anthm@freeswitch.org>
Tue, 26 Jan 2016 17:00:41 +0000 (11:00 -0600)
src/switch_ivr_async.c

index bd6cb6f34f3c566d054bb15fea49d4b6c97810dd..036b0177d07a558038c03904ac067ca2792ef53b 100644 (file)
@@ -1048,6 +1048,8 @@ struct record_helper {
        switch_thread_t *thread;
        switch_mutex_t *buffer_mutex;
        int thread_ready;
+       uint32_t writes;
+       uint32_t vwrites;
        const char *completion_cause;
 };
 
@@ -1253,7 +1255,7 @@ static switch_bool_t record_callback(switch_media_bug_t *bug, void *user_data, s
 
                        switch_core_file_write(&rh->in_fh, mask ? null_data : nframe->data, &len);
                        rh->last_read_time = now;
-                       
+                       rh->writes++;
                }
                break;
        case SWITCH_ABC_TYPE_TAP_NATIVE_WRITE:
@@ -1292,7 +1294,7 @@ static switch_bool_t record_callback(switch_media_bug_t *bug, void *user_data, s
                        
                        switch_core_file_write(&rh->out_fh, mask ? null_data : nframe->data, &len);
                        rh->last_write_time = now;
-                       
+                       rh->writes++;
                }
                break;
        case SWITCH_ABC_TYPE_CLOSE:
@@ -1352,28 +1354,32 @@ static switch_bool_t record_callback(switch_media_bug_t *bug, void *user_data, s
 
                                switch_core_file_close(rh->fh);
 
-                               
-
-                               if (rh->fh->samples_out < rh->fh->samplerate * rh->min_sec) {
+                               if (!rh->writes && !rh->vwrites) {
+                                       switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Discarding empty file %s\n", rh->file);
+                                       switch_channel_set_variable(channel, "RECORD_DISCARDED", "true");
+                                       switch_file_remove(rh->file, switch_core_session_get_pool(session));
+                                       set_completion_cause(rh, "empty-file");
+                               } else if (rh->fh->samples_out < rh->fh->samplerate * rh->min_sec) {
                                        switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Discarding short file %s\n", rh->file);
                                        switch_channel_set_variable(channel, "RECORD_DISCARDED", "true");
                                        switch_file_remove(rh->file, switch_core_session_get_pool(session));
                                        set_completion_cause(rh, "input-too-short");
-                               }
+                               } else {
 
-                               if (switch_channel_down_nosig(channel)) {
-                                       /* We got hung up */
-                                       switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Channel is hung up\n");
-                                       if (rh->speech_detected) {
-                                               /* Treat it as equivalent with final-silence */
-                                               set_completion_cause(rh, "success-silence");
+                                       if (switch_channel_down_nosig(channel)) {
+                                               /* We got hung up */
+                                               switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Channel is hung up\n");
+                                               if (rh->speech_detected) {
+                                                       /* Treat it as equivalent with final-silence */
+                                                       set_completion_cause(rh, "success-silence");
+                                               } else {
+                                                       /* Treat it as equivalent with inital-silence timeout */
+                                                       set_completion_cause(rh, "no-input-timeout");
+                                               }
                                        } else {
-                                               /* Treat it as equivalent with inital-silence timeout */
-                                               set_completion_cause(rh, "no-input-timeout");
+                                               /* Set the completion_cause to maxtime reached, unless it's already set */
+                                               set_completion_cause(rh, "success-maxtime");
                                        }
-                               } else {
-                                       /* Set the completion_cause to maxtime reached, unless it's already set */
-                                       set_completion_cause(rh, "success-maxtime");
                                }
                        }
                        
@@ -1441,7 +1447,9 @@ static switch_bool_t record_callback(switch_media_bug_t *bug, void *user_data, s
                                                }
                                                return SWITCH_FALSE;
                                        }
-
+                                       
+                                       rh->writes++;
+                                       
                                        /* check for silence timeout */
                                        if (rh->silence_threshold) {
                                                switch_codec_implementation_t read_impl = { 0 };
@@ -1500,6 +1508,7 @@ static switch_bool_t record_callback(switch_media_bug_t *bug, void *user_data, s
                                switch_core_session_reset(session, SWITCH_TRUE, SWITCH_TRUE);
                                return SWITCH_FALSE;
                        }
+                       rh->vwrites++;
                }
                break;