1 /* 2 * Copyright (c) 2018 The WebRTC project authors. All Rights Reserved. 3 * 4 * Use of this source code is governed by a BSD-style license 5 * that can be found in the LICENSE file in the root of the source 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 11 #include "modules/audio_coding/neteq/tools/neteq_stats_plotter.h" 12 13 #include <inttypes.h> 14 #include <stdio.h> 15 16 #include <utility> 17 18 #include "absl/strings/string_view.h" 19 20 namespace webrtc { 21 namespace test { 22 NetEqStatsPlotter(bool make_matlab_plot,bool make_python_plot,bool show_concealment_events,absl::string_view base_file_name)23 NetEqStatsPlotter::NetEqStatsPlotter(bool make_matlab_plot, 24 bool make_python_plot, 25 bool show_concealment_events, 26 absl::string_view base_file_name) 27 : make_matlab_plot_(make_matlab_plot), 28 make_python_plot_(make_python_plot), 29 show_concealment_events_(show_concealment_events), 30 base_file_name_(base_file_name) { 31 std::unique_ptr<NetEqDelayAnalyzer> delay_analyzer; 32 if (make_matlab_plot || make_python_plot) { 33 delay_analyzer.reset(new NetEqDelayAnalyzer); 34 } 35 stats_getter_.reset(new NetEqStatsGetter(std::move(delay_analyzer))); 36 } 37 SimulationEnded(int64_t simulation_time_ms)38 void NetEqStatsPlotter::SimulationEnded(int64_t simulation_time_ms) { 39 if (make_matlab_plot_) { 40 auto matlab_script_name = base_file_name_; 41 std::replace(matlab_script_name.begin(), matlab_script_name.end(), '.', 42 '_'); 43 printf("Creating Matlab plot script %s.m\n", matlab_script_name.c_str()); 44 stats_getter_->delay_analyzer()->CreateMatlabScript(matlab_script_name + 45 ".m"); 46 } 47 if (make_python_plot_) { 48 auto python_script_name = base_file_name_; 49 std::replace(python_script_name.begin(), python_script_name.end(), '.', 50 '_'); 51 printf("Creating Python plot script %s.py\n", python_script_name.c_str()); 52 stats_getter_->delay_analyzer()->CreatePythonScript(python_script_name + 53 ".py"); 54 } 55 56 printf("Simulation statistics:\n"); 57 printf(" output duration: %" PRId64 " ms\n", simulation_time_ms); 58 auto stats = stats_getter_->AverageStats(); 59 printf(" packet_loss_rate: %f %%\n", 100.0 * stats.packet_loss_rate); 60 printf(" expand_rate: %f %%\n", 100.0 * stats.expand_rate); 61 printf(" speech_expand_rate: %f %%\n", 100.0 * stats.speech_expand_rate); 62 printf(" preemptive_rate: %f %%\n", 100.0 * stats.preemptive_rate); 63 printf(" accelerate_rate: %f %%\n", 100.0 * stats.accelerate_rate); 64 printf(" secondary_decoded_rate: %f %%\n", 65 100.0 * stats.secondary_decoded_rate); 66 printf(" secondary_discarded_rate: %f %%\n", 67 100.0 * stats.secondary_discarded_rate); 68 printf(" clockdrift_ppm: %f ppm\n", stats.clockdrift_ppm); 69 printf(" mean_waiting_time_ms: %f ms\n", stats.mean_waiting_time_ms); 70 printf(" median_waiting_time_ms: %f ms\n", stats.median_waiting_time_ms); 71 printf(" min_waiting_time_ms: %f ms\n", stats.min_waiting_time_ms); 72 printf(" max_waiting_time_ms: %f ms\n", stats.max_waiting_time_ms); 73 printf(" current_buffer_size_ms: %f ms\n", stats.current_buffer_size_ms); 74 printf(" preferred_buffer_size_ms: %f ms\n", stats.preferred_buffer_size_ms); 75 if (show_concealment_events_) { 76 printf(" concealment_events_ms:\n"); 77 for (auto concealment_event : stats_getter_->concealment_events()) 78 printf("%s\n", concealment_event.ToString().c_str()); 79 printf(" end of concealment_events_ms\n"); 80 } 81 82 const auto lifetime_stats_vector = stats_getter_->lifetime_stats(); 83 if (!lifetime_stats_vector->empty()) { 84 auto lifetime_stats = lifetime_stats_vector->back().second; 85 printf(" total_samples_received: %" PRIu64 "\n", 86 lifetime_stats.total_samples_received); 87 printf(" concealed_samples: %" PRIu64 "\n", 88 lifetime_stats.concealed_samples); 89 printf(" concealment_events: %" PRIu64 "\n", 90 lifetime_stats.concealment_events); 91 printf(" delayed_packet_outage_samples: %" PRIu64 "\n", 92 lifetime_stats.delayed_packet_outage_samples); 93 printf(" num_interruptions: %d\n", lifetime_stats.interruption_count); 94 printf(" sum_interruption_length_ms: %d ms\n", 95 lifetime_stats.total_interruption_duration_ms); 96 printf(" interruption_ratio: %f\n", 97 static_cast<double>(lifetime_stats.total_interruption_duration_ms) / 98 simulation_time_ms); 99 printf(" removed_samples_for_acceleration: %" PRIu64 "\n", 100 lifetime_stats.removed_samples_for_acceleration); 101 printf(" inserted_samples_for_deceleration: %" PRIu64 "\n", 102 lifetime_stats.inserted_samples_for_deceleration); 103 printf(" generated_noise_samples: %" PRIu64 "\n", 104 lifetime_stats.generated_noise_samples); 105 printf(" packets_discarded: %" PRIu64 "\n", 106 lifetime_stats.packets_discarded); 107 } 108 } 109 110 } // namespace test 111 } // namespace webrtc 112