]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FSCORE-339
authorAnthony Minessale <anthony.minessale@gmail.com>
Fri, 20 Mar 2009 13:58:45 +0000 (13:58 +0000)
committerAnthony Minessale <anthony.minessale@gmail.com>
Fri, 20 Mar 2009 13:58:45 +0000 (13:58 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@12682 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/include/switch_module_interfaces.h
src/switch_core_file.c
src/switch_ivr_async.c

index 17536c4966f46ca237e117d6c582a6f6d738e5a2..ed0dcc3a5777de1c8da821fde25d65fdf0e931be 100644 (file)
@@ -317,7 +317,8 @@ struct switch_file_handle {
        uint32_t thresh;
        uint32_t silence_hits;
        uint32_t offset_pos;
-       //uint32_t last_pos;
+       switch_size_t samples_in;
+       switch_size_t samples_out;
        int32_t vol;
        switch_audio_resampler_t *resampler;
        switch_buffer_t *buffer;
index 8cf75089cb7bc6af92ebf8dbf521de9f9f71248b..1cc3f20d6924ed9d70152d390d465e0d2daa3ad4 100644 (file)
@@ -177,6 +177,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_file_read(switch_file_handle_t *fh,
                                if ((status = fh->file_interface->file_read(fh, fh->pre_buffer_data, &rlen)) != SWITCH_STATUS_SUCCESS || !rlen) {
                                        switch_set_flag(fh, SWITCH_FILE_BUFFER_DONE);
                                } else {
+                                       fh->samples_in += rlen;
                                        if (fh->channels > 1) {
                                                switch_mux_channels((int16_t *)fh->pre_buffer_data, rlen, fh->channels);
                                        }
@@ -202,6 +203,8 @@ SWITCH_DECLARE(switch_status_t) switch_core_file_read(switch_file_handle_t *fh,
                        goto top;
                }
 
+               fh->samples_in += *len;
+
                if (fh->channels > 1) {
                        switch_mux_channels((int16_t *)data, *len, fh->channels);
                }
@@ -317,11 +320,16 @@ SWITCH_DECLARE(switch_status_t) switch_core_file_write(switch_file_handle_t *fh,
                        if ((status = fh->file_interface->file_write(fh, fh->pre_buffer_data, &blen)) != SWITCH_STATUS_SUCCESS) {
                                *len = 0;
                        }
+                       fh->samples_out += blen;
                }
                
                return status;
        } else {
-               return fh->file_interface->file_write(fh, data, len);
+               switch_status_t status;
+               if ((status = fh->file_interface->file_write(fh, data, len)) == SWITCH_STATUS_SUCCESS) {
+                       fh->samples_out += *len;
+               }
+               return status;
        }
 }
 
index 881413c35bc002151387882638d96cd202d9a8a7..14b5e03b8e32b0bd5aa25c120c16bb1cb7a93984 100644 (file)
@@ -439,12 +439,23 @@ static switch_bool_t record_callback(switch_media_bug_t *bug, void *user_data, s
        case SWITCH_ABC_TYPE_INIT:
                break;
        case SWITCH_ABC_TYPE_CLOSE:
-               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Stop recording file %s\n", rh->file);
-               switch_channel_set_private(channel, rh->file, NULL);
+               {
+                       switch_codec_implementation_t read_impl = {0};
+                       switch_core_session_get_read_impl(session, &read_impl);
+
+                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Stop recording file %s\n", rh->file);
+                       switch_channel_set_private(channel, rh->file, NULL);
+                       
+                       if (rh->fh) {
+                               switch_core_file_close(rh->fh);
+                       }
                
-               if (rh->fh) {
-                       switch_core_file_close(rh->fh);
+                       if (rh->fh->samples_out < read_impl.samples_per_second * 3) {
+                               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Discarding short file %s\n", rh->file);
+                               switch_file_remove(rh->file, switch_core_session_get_pool(session));
+                       }
                }
+
                break;
        case SWITCH_ABC_TYPE_READ_PING:
                if (rh->fh) {