[Core] Delete recording files if media bug creation fails

Signed-off-by: hateeyan <hateeyan@gmail.com>
This commit is contained in:
hateeyan 2024-07-08 14:04:24 +08:00
parent 98f164d2bf
commit 0739809c76
No known key found for this signature in database
GPG Key ID: 0229683329C707BD
1 changed files with 3 additions and 2 deletions

View File

@ -1664,12 +1664,10 @@ static switch_bool_t record_callback(switch_media_bug_t *bug, void *user_data, s
if (!rh->writes && !rh->vwrites && !switch_test_flag(rh->fh, SWITCH_FILE_WRITE_APPEND)) { if (!rh->writes && !rh->vwrites && !switch_test_flag(rh->fh, SWITCH_FILE_WRITE_APPEND)) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Discarding empty file %s\n", rh->file); 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_channel_set_variable(channel, "RECORD_DISCARDED", "true");
switch_file_remove(rh->file, switch_core_session_get_pool(session));
set_completion_cause(rh, "empty-file"); set_completion_cause(rh, "empty-file");
} else if ((rh->fh->samples_out < rh->fh->samplerate * rh->min_sec) && !switch_test_flag(rh->fh, SWITCH_FILE_WRITE_APPEND)) { } else if ((rh->fh->samples_out < rh->fh->samplerate * rh->min_sec) && !switch_test_flag(rh->fh, SWITCH_FILE_WRITE_APPEND)) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Discarding short file %s\n", rh->file); 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_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"); set_completion_cause(rh, "input-too-short");
} else { } else {
@ -2899,6 +2897,9 @@ static switch_status_t record_helper_destroy(struct record_helper **rh, switch_c
switch_core_file_close(&(*rh)->out_fh); switch_core_file_close(&(*rh)->out_fh);
} else if((*rh)->fh) { } else if((*rh)->fh) {
switch_core_file_close((*rh)->fh); switch_core_file_close((*rh)->fh);
if (((!(*rh)->writes && !(*rh)->vwrites) || ((*rh)->fh->samples_out < (*rh)->fh->samplerate * (*rh)->min_sec)) && !switch_test_flag((*rh)->fh, SWITCH_FILE_WRITE_APPEND)) {
switch_file_remove((*rh)->file, switch_core_session_get_pool(session));
}
} }
switch_event_safe_destroy((*rh)->variables); switch_event_safe_destroy((*rh)->variables);