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);
}
goto top;
}
+ fh->samples_in += *len;
+
if (fh->channels > 1) {
switch_mux_channels((int16_t *)data, *len, fh->channels);
}
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;
}
}
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) {