From fd6c5e6a9beb150469d8151ad9c02a867a84f4c7 Mon Sep 17 00:00:00 2001 From: Jirka Novak Date: Sat, 2 Jan 2021 15:04:50 +0100 Subject: [PATCH] RTP analysis: Dialog uses common calculation function UpdateStatistics method uses common rtpstream_info_calculate function. --- ui/qt/rtp_analysis_dialog.cpp | 132 ++++++++++++---------------------- 1 file changed, 44 insertions(+), 88 deletions(-) diff --git a/ui/qt/rtp_analysis_dialog.cpp b/ui/qt/rtp_analysis_dialog.cpp index 26034e5725..a2827d1499 100644 --- a/ui/qt/rtp_analysis_dialog.cpp +++ b/ui/qt/rtp_analysis_dialog.cpp @@ -847,136 +847,92 @@ void RtpAnalysisDialog::savePayload(QTemporaryFile *tmpfile, tap_rtp_stat_t *sta void RtpAnalysisDialog::updateStatistics() { - unsigned int f_clock_rate = fwd_statinfo_.rtp_stats.clock_rate; - unsigned int r_clock_rate = rev_statinfo_.rtp_stats.clock_rate; - unsigned int f_expected = (fwd_statinfo_.rtp_stats.stop_seq_nr + fwd_statinfo_.rtp_stats.cycles*65536) - - fwd_statinfo_.rtp_stats.start_seq_nr + 1; - unsigned int r_expected = (rev_statinfo_.rtp_stats.stop_seq_nr + rev_statinfo_.rtp_stats.cycles*65536) - - rev_statinfo_.rtp_stats.start_seq_nr + 1; - unsigned int f_total_nr = fwd_statinfo_.rtp_stats.total_nr; - unsigned int r_total_nr = rev_statinfo_.rtp_stats.total_nr; - int f_lost = f_expected - f_total_nr; - int r_lost = r_expected - r_total_nr; - double f_sumt = fwd_statinfo_.rtp_stats.sumt; - double f_sumTS = fwd_statinfo_.rtp_stats.sumTS; - double f_sumt2 = fwd_statinfo_.rtp_stats.sumt2; - double f_sumtTS = fwd_statinfo_.rtp_stats.sumtTS; - double r_sumt = rev_statinfo_.rtp_stats.sumt; - double r_sumTS = rev_statinfo_.rtp_stats.sumTS; - double r_sumt2 = rev_statinfo_.rtp_stats.sumt2; - double r_sumtTS = rev_statinfo_.rtp_stats.sumtTS; - double f_perc, r_perc; - double f_clock_drift = 1.0; - double r_clock_drift = 1.0; - double f_duration = fwd_statinfo_.rtp_stats.time - fwd_statinfo_.rtp_stats.start_time; - double r_duration = rev_statinfo_.rtp_stats.time - rev_statinfo_.rtp_stats.start_time; + rtpstream_info_calc_t f_calc; + rtpstream_info_calc_t r_calc; - if (f_clock_rate == 0) { - f_clock_rate = 1; - } - - if (r_clock_rate == 0) { - r_clock_rate = 1; - } - - if (f_expected) { - f_perc = (double)(f_lost*100)/(double)f_expected; - } else { - f_perc = 0; - } - if (r_expected) { - r_perc = (double)(r_lost*100)/(double)r_expected; - } else { - r_perc = 0; - } - - if ((f_total_nr >0) && (f_sumt2 > 0)) { - f_clock_drift = (f_total_nr * f_sumtTS - f_sumt * f_sumTS) / (f_total_nr * f_sumt2 - f_sumt * f_sumt); - } - if ((r_total_nr >0) && (r_sumt2 > 0)) { - r_clock_drift = (r_total_nr * r_sumtTS - r_sumt * r_sumTS) / (r_total_nr * r_sumt2 - r_sumt * r_sumt); - } + rtpstream_info_calculate(&fwd_statinfo_, &f_calc); + rtpstream_info_calculate(&rev_statinfo_, &r_calc); QString stats_tables = "\n"; stats_tables += "

Forward

\n"; stats_tables += QString("

%1:%2 " UTF8_RIGHTWARDS_ARROW) - .arg(address_to_qstring(&fwd_statinfo_.id.src_addr, true)) - .arg(fwd_statinfo_.id.src_port); + .arg(f_calc.src_addr_str) + .arg(f_calc.src_port); stats_tables += QString("
%1:%2

\n") - .arg(address_to_qstring(&fwd_statinfo_.id.dst_addr, true)) - .arg(fwd_statinfo_.id.dst_port); + .arg(f_calc.dst_addr_str) + .arg(f_calc.dst_port); stats_tables += "

\n"; stats_tables += QString("") - .arg(int_to_qstring(fwd_statinfo_.id.ssrc, 8, 16)); + .arg(int_to_qstring(f_calc.ssrc, 8, 16)); stats_tables += QString("") - .arg(fwd_statinfo_.rtp_stats.max_delta, 0, 'f', prefs.gui_decimal_places3) - .arg(fwd_statinfo_.rtp_stats.max_nr); + .arg(f_calc.max_delta, 0, 'f', prefs.gui_decimal_places3) + .arg(f_calc.last_packet_num); stats_tables += QString("") - .arg(fwd_statinfo_.rtp_stats.max_jitter, 0, 'f', prefs.gui_decimal_places3); + .arg(f_calc.max_jitter, 0, 'f', prefs.gui_decimal_places3); stats_tables += QString("") - .arg(fwd_statinfo_.rtp_stats.mean_jitter, 0, 'f', prefs.gui_decimal_places3); + .arg(f_calc.mean_jitter, 0, 'f', prefs.gui_decimal_places3); stats_tables += QString("") - .arg(fwd_statinfo_.rtp_stats.max_skew, 0, 'f', prefs.gui_decimal_places3); + .arg(f_calc.max_skew, 0, 'f', prefs.gui_decimal_places3); stats_tables += QString("") - .arg(f_total_nr); + .arg(f_calc.total_nr); stats_tables += QString("") - .arg(f_expected); + .arg(f_calc.packet_expected); stats_tables += QString("") - .arg(f_lost).arg(f_perc, 0, 'f', prefs.gui_decimal_places1); + .arg(f_calc.lost_num).arg(f_calc.lost_perc, 0, 'f', prefs.gui_decimal_places1); stats_tables += QString("") - .arg(fwd_statinfo_.rtp_stats.sequence); + .arg(f_calc.sequence_err); stats_tables += QString("") - .arg(fwd_statinfo_.rtp_stats.start_time / 1000.0, 0, 'f', 6) - .arg(fwd_statinfo_.rtp_stats.first_packet_num); + .arg(f_calc.start_time_ms, 0, 'f', 6) + .arg(f_calc.first_packet_num); stats_tables += QString("") - .arg(f_duration / 1000.0, 0, 'f', prefs.gui_decimal_places1); + .arg(f_calc.duration_ms, 0, 'f', prefs.gui_decimal_places1); stats_tables += QString("") - .arg(f_duration * (f_clock_drift - 1.0), 0, 'f', 0); + .arg(f_calc.clock_drift_ms, 0, 'f', 0); stats_tables += QString("") // XXX Terminology? - .arg(f_clock_drift * f_clock_rate, 0, 'f', 0).arg(100.0 * (f_clock_drift - 1.0), 0, 'f', 2); + .arg(f_calc.freq_drift_hz, 0, 'f', 0).arg(f_calc.freq_drift_perc, 0, 'f', 2); stats_tables += "
SSRC%1
Max Delta%1 ms @ %2
Max Jitter%1 ms
Mean Jitter%1 ms
Max Skew%1 ms
RTP Packets%1
Expected%1
Lost%1 (%2 %)
Seq Errs%1
Start at%1 s @ %2
Duration%1 s
Clock Drift%1 ms
Freq Drift%1 Hz (%2 %)

\n"; stats_tables += "

Reverse

\n"; stats_tables += QString("

%1:%2 " UTF8_RIGHTWARDS_ARROW) - .arg(address_to_qstring(&rev_statinfo_.id.src_addr, true)) - .arg(rev_statinfo_.id.src_port); + .arg(r_calc.src_addr_str) + .arg(r_calc.src_port); stats_tables += QString("
%1:%2

\n") - .arg(address_to_qstring(&rev_statinfo_.id.dst_addr, true)) - .arg(rev_statinfo_.id.dst_port); + .arg(r_calc.dst_addr_str) + .arg(r_calc.dst_port); stats_tables += "

\n"; stats_tables += QString("") - .arg(int_to_qstring(rev_statinfo_.id.ssrc, 8, 16)); + .arg(int_to_qstring(r_calc.ssrc, 8, 16)); stats_tables += QString("") - .arg(rev_statinfo_.rtp_stats.max_delta, 0, 'f', prefs.gui_decimal_places3) - .arg(rev_statinfo_.rtp_stats.max_nr); + .arg(r_calc.max_delta, 0, 'f', prefs.gui_decimal_places3) + .arg(r_calc.last_packet_num); stats_tables += QString("") - .arg(rev_statinfo_.rtp_stats.max_jitter, 0, 'f', prefs.gui_decimal_places3); + .arg(r_calc.max_jitter, 0, 'f', prefs.gui_decimal_places3); stats_tables += QString("") - .arg(rev_statinfo_.rtp_stats.mean_jitter, 0, 'f', prefs.gui_decimal_places3); + .arg(r_calc.mean_jitter, 0, 'f', prefs.gui_decimal_places3); stats_tables += QString("") - .arg(rev_statinfo_.rtp_stats.max_skew, 0, 'f', prefs.gui_decimal_places3); + .arg(r_calc.max_skew, 0, 'f', prefs.gui_decimal_places3); stats_tables += QString("") - .arg(r_total_nr); + .arg(r_calc.total_nr); stats_tables += QString("") - .arg(r_expected); + .arg(r_calc.packet_expected); stats_tables += QString("") - .arg(r_lost).arg(r_perc, 0, 'f', prefs.gui_decimal_places1); + .arg(r_calc.lost_num).arg(r_calc.lost_perc, 0, 'f', prefs.gui_decimal_places1); stats_tables += QString("") - .arg(rev_statinfo_.rtp_stats.sequence); + .arg(r_calc.sequence_err); stats_tables += QString("") - .arg(rev_statinfo_.rtp_stats.start_time / 1000.0, 0, 'f', 6) - .arg(rev_statinfo_.rtp_stats.first_packet_num); + .arg(r_calc.start_time_ms, 0, 'f', 6) + .arg(r_calc.first_packet_num); stats_tables += QString("") - .arg(r_duration / 1000.0, 0, 'f', prefs.gui_decimal_places1); + .arg(r_calc.duration_ms, 0, 'f', prefs.gui_decimal_places1); stats_tables += QString("") - .arg(r_duration * (r_clock_drift - 1.0), 0, 'f', 0); + .arg(r_calc.clock_drift_ms, 0, 'f', 0); stats_tables += QString("") // XXX Terminology? - .arg(r_clock_drift * r_clock_rate, 0, 'f', 0).arg(100.0 * (r_clock_drift - 1.0), 0, 'f', 2); + .arg(r_calc.freq_drift_hz, 0, 'f', 0).arg(r_calc.freq_drift_perc, 0, 'f', 2); stats_tables += "
SSRC%1
Max Delta%1 ms @ %2
Max Jitter%1 ms
Mean Jitter%1 ms
Max Skew%1 ms
RTP Packets%1
Expected%1
Lost%1 (%2 %)
Seq Errs%1
Start at%1 s @ %2
Duration%1 s
Clock Drift%1 ms
Freq Drift%1 Hz (%2 %)

"; if (rev_statinfo_.rtp_stats.total_nr) { stats_tables += QString("

Forward to reverse
start diff %1 s @ %2

") - .arg((rev_statinfo_.rtp_stats.start_time - fwd_statinfo_.rtp_stats.start_time) / 1000.0, 0, 'f', 6) - .arg((int64_t)rev_statinfo_.rtp_stats.first_packet_num - (int64_t)fwd_statinfo_.rtp_stats.first_packet_num); + .arg(abs(r_calc.start_time_ms - f_calc.start_time_ms), 0, 'f', 6) + .arg(abs((int64_t)r_calc.first_packet_num - (int64_t)f_calc.first_packet_num)); } stats_tables += "\n";