From a84ce1dd3c68f4b57824f6aa286bdf6fdd08cabb Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Fri, 16 Aug 2013 16:30:10 -0400 Subject: [PATCH] Improvements to mod_bert * Improve bert input debug * Check for SFF_CNG and ignore those frames --- src/mod/applications/mod_bert/mod_bert.c | 43 +++++++++++++++++------- 1 file changed, 30 insertions(+), 13 deletions(-) diff --git a/src/mod/applications/mod_bert/mod_bert.c b/src/mod/applications/mod_bert/mod_bert.c index 921d8bb821..cd1b5b12de 100644 --- a/src/mod/applications/mod_bert/mod_bert.c +++ b/src/mod/applications/mod_bert/mod_bert.c @@ -65,6 +65,25 @@ typedef struct { } \ } while (0); +#define bert_close_debug_streams(bert, session) \ + do { \ + int rc = 0; \ + if (bert.input_debug_f) { \ + rc = fclose(bert.input_debug_f); \ + if (rc) { \ + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Failed to close BERT input debug file!\n"); \ + } \ + bert.input_debug_f = NULL; \ + } \ + if (bert.output_debug_f) { \ + rc = fclose(bert.output_debug_f); \ + if (rc) { \ + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Failed to close BERT output debug file!\n"); \ + } \ + bert.output_debug_f = NULL; \ + } \ + } while (0); + #define BERT_DEFAULT_WINDOW_MS 1000 #define BERT_DEFAULT_MAX_ERR 10.0 #define BERT_DEFAULT_TIMEOUT_MS 10000 @@ -161,7 +180,7 @@ SWITCH_STANDARD_APP(bert_test_function) if (bert.timeout && !synced) { switch_time_t now = switch_micro_time_now(); if (now >= bert.timeout) { - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "BERT Timeout (read_samples=%d, read_bytes=%d, expected_samples=%d, %s)\n", + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "BERT Timeout (read_samples=%d, read_bytes=%d, expected_samples=%d, session=%s)\n", read_frame->samples, read_frame->datalen, read_impl.samples_per_packet, switch_core_session_get_uuid(session)); if (bert.hangup_on_error) { switch_channel_hangup(channel, SWITCH_CAUSE_MEDIA_TIMEOUT); @@ -169,20 +188,22 @@ SWITCH_STANDARD_APP(bert_test_function) } } - if (!read_frame->datalen) { + /* Ignore confort noise, TODO: we should probably deal with this and treat it as a full frame of silence?? */ + if (switch_test_flag(read_frame, SFF_CNG) || !read_frame->datalen) { continue; } if (read_frame->samples != read_impl.samples_per_packet) { - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Only read %d samples, expected %d!\n", read_frame->samples, read_impl.samples_per_packet); + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Only read %d samples, expected %d!\n", read_frame->samples, read_impl.samples_per_packet); continue; } read_samples = read_frame->data; write_samples = write_frame.data; - if (read_frame->samples) { - if (bert.input_debug_f) { - fwrite(read_frame->data, read_frame->datalen, 1, bert.input_debug_f); + if (bert.input_debug_f) { + size_t ret = fwrite(read_frame->data, read_frame->datalen, 1, bert.input_debug_f); + if (ret != 1) { + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Failed to write to BERT input debug file!\n"); } } @@ -194,9 +215,10 @@ SWITCH_STANDARD_APP(bert_test_function) if (err > bert.max_err) { if (bert.in_sync) { bert.in_sync = 0; - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "BERT Sync Lost: %f%% loss\n", err); + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "BERT Sync Lost: %f%% loss (err_samples=%u, session=%s)\n", err, bert.err_samples, switch_core_session_get_uuid(session)); if (bert.hangup_on_error) { switch_channel_hangup(channel, SWITCH_CAUSE_MEDIA_TIMEOUT); + bert_close_debug_streams(bert, session); } } } else if (!bert.in_sync) { @@ -253,12 +275,7 @@ SWITCH_STANDARD_APP(bert_test_function) } done: - if (bert.input_debug_f) { - fclose(bert.input_debug_f); - } - if (bert.output_debug_f) { - fclose(bert.output_debug_f); - } + bert_close_debug_streams(bert, session); switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "BERT Test Completed. MaxErr=%f%%\n", synced ? bert.max_err_hit : bert.max_err_ever); }