switch_thread_t *thread;
switch_mutex_t *buffer_mutex;
int thread_ready;
+ uint32_t writes;
+ uint32_t vwrites;
const char *completion_cause;
};
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:
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:
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");
}
}
}
return SWITCH_FALSE;
}
-
+
+ rh->writes++;
+
/* check for silence timeout */
if (rh->silence_threshold) {
switch_codec_implementation_t read_impl = { 0 };
switch_core_session_reset(session, SWITCH_TRUE, SWITCH_TRUE);
return SWITCH_FALSE;
}
+ rh->vwrites++;
}
break;