• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 namespace webrtc {
19 namespace test {
20 
NetEqStatsPlotter(bool make_matlab_plot,bool make_python_plot,bool show_concealment_events,std::string base_file_name)21 NetEqStatsPlotter::NetEqStatsPlotter(bool make_matlab_plot,
22                                      bool make_python_plot,
23                                      bool show_concealment_events,
24                                      std::string base_file_name)
25     : make_matlab_plot_(make_matlab_plot),
26       make_python_plot_(make_python_plot),
27       show_concealment_events_(show_concealment_events),
28       base_file_name_(base_file_name) {
29   std::unique_ptr<NetEqDelayAnalyzer> delay_analyzer;
30   if (make_matlab_plot || make_python_plot) {
31     delay_analyzer.reset(new NetEqDelayAnalyzer);
32   }
33   stats_getter_.reset(new NetEqStatsGetter(std::move(delay_analyzer)));
34 }
35 
SimulationEnded(int64_t simulation_time_ms,NetEq *)36 void NetEqStatsPlotter::SimulationEnded(int64_t simulation_time_ms,
37                                         NetEq* /*neteq*/) {
38   if (make_matlab_plot_) {
39     auto matlab_script_name = base_file_name_;
40     std::replace(matlab_script_name.begin(), matlab_script_name.end(), '.',
41                  '_');
42     printf("Creating Matlab plot script %s.m\n", matlab_script_name.c_str());
43     stats_getter_->delay_analyzer()->CreateMatlabScript(matlab_script_name +
44                                                         ".m");
45   }
46   if (make_python_plot_) {
47     auto python_script_name = base_file_name_;
48     std::replace(python_script_name.begin(), python_script_name.end(), '.',
49                  '_');
50     printf("Creating Python plot script %s.py\n", python_script_name.c_str());
51     stats_getter_->delay_analyzer()->CreatePythonScript(python_script_name +
52                                                         ".py");
53   }
54 
55   printf("Simulation statistics:\n");
56   printf("  output duration: %" PRId64 " ms\n", simulation_time_ms);
57   auto stats = stats_getter_->AverageStats();
58   printf("  packet_loss_rate: %f %%\n", 100.0 * stats.packet_loss_rate);
59   printf("  expand_rate: %f %%\n", 100.0 * stats.expand_rate);
60   printf("  speech_expand_rate: %f %%\n", 100.0 * stats.speech_expand_rate);
61   printf("  preemptive_rate: %f %%\n", 100.0 * stats.preemptive_rate);
62   printf("  accelerate_rate: %f %%\n", 100.0 * stats.accelerate_rate);
63   printf("  secondary_decoded_rate: %f %%\n",
64          100.0 * stats.secondary_decoded_rate);
65   printf("  secondary_discarded_rate: %f %%\n",
66          100.0 * stats.secondary_discarded_rate);
67   printf("  clockdrift_ppm: %f ppm\n", stats.clockdrift_ppm);
68   printf("  mean_waiting_time_ms: %f ms\n", stats.mean_waiting_time_ms);
69   printf("  median_waiting_time_ms: %f ms\n", stats.median_waiting_time_ms);
70   printf("  min_waiting_time_ms: %f ms\n", stats.min_waiting_time_ms);
71   printf("  max_waiting_time_ms: %f ms\n", stats.max_waiting_time_ms);
72   printf("  current_buffer_size_ms: %f ms\n", stats.current_buffer_size_ms);
73   printf("  preferred_buffer_size_ms: %f ms\n", stats.preferred_buffer_size_ms);
74   if (show_concealment_events_) {
75     printf(" concealment_events_ms:\n");
76     for (auto concealment_event : stats_getter_->concealment_events())
77       printf("%s\n", concealment_event.ToString().c_str());
78     printf(" end of concealment_events_ms\n");
79   }
80 
81   const auto lifetime_stats_vector = stats_getter_->lifetime_stats();
82   if (!lifetime_stats_vector->empty()) {
83     auto lifetime_stats = lifetime_stats_vector->back().second;
84     printf("  total_samples_received: %" PRIu64 "\n",
85            lifetime_stats.total_samples_received);
86     printf("  concealed_samples: %" PRIu64 "\n",
87            lifetime_stats.concealed_samples);
88     printf("  concealment_events: %" PRIu64 "\n",
89            lifetime_stats.concealment_events);
90     printf("  delayed_packet_outage_samples: %" PRIu64 "\n",
91            lifetime_stats.delayed_packet_outage_samples);
92     printf("  num_interruptions: %d\n", lifetime_stats.interruption_count);
93     printf("  sum_interruption_length_ms: %d ms\n",
94            lifetime_stats.total_interruption_duration_ms);
95     printf("  interruption_ratio: %f\n",
96            static_cast<double>(lifetime_stats.total_interruption_duration_ms) /
97                simulation_time_ms);
98   }
99 }
100 
101 }  // namespace test
102 }  // namespace webrtc
103