Plot Scream delay and ref window in event_log_visualizer tool

Bug: webrtc:447037083
Change-Id: Ib1edff6de0df6d4f13f1b3400217dca2a851f91e
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/417380
Commit-Queue: Björn Terelius <terelius@webrtc.org>
Reviewed-by: Per Kjellander <perkj@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#45948}
diff --git a/rtc_tools/rtc_event_log_visualizer/analyzer.cc b/rtc_tools/rtc_event_log_visualizer/analyzer.cc
index 916ace1..f625f4d 100644
--- a/rtc_tools/rtc_event_log_visualizer/analyzer.cc
+++ b/rtc_tools/rtc_event_log_visualizer/analyzer.cc
@@ -628,6 +628,12 @@
   plots_.RegisterPlot("incoming_ecn_feedback", [this](Plot* plot) {
     this->CreateIncomingEcnFeedbackGraph(plot);
   });
+  plots_.RegisterPlot("scream_ref_window", [this](Plot* plot) {
+    this->CreateScreamRefWindowGraph(plot);
+  });
+  plots_.RegisterPlot("scream_delay_estimates", [this](Plot* plot) {
+    this->CreateScreamDelayEstimateGraph(plot);
+  });
   plots_.RegisterPlot("network_delay_feedback", [this](Plot* plot) {
     this->CreateNetworkDelayFeedbackGraph(plot);
   });
@@ -1358,6 +1364,13 @@
   last_series->intervals.emplace_back(last_detector_switch,
                                       config_.CallEndTimeSec());
 
+  TimeSeries scream_series("Scream target rate", LineStyle::kStep);
+  for (auto& scream_update : parsed_log_.bwe_scream_updates()) {
+    float x = config_.GetCallTimeSec(scream_update.log_time());
+    float y = static_cast<float>(scream_update.target_rate.kbps());
+    scream_series.points.emplace_back(x, y);
+  }
+
   TimeSeries created_series("Probe cluster created.", LineStyle::kNone,
                             PointStyle::kHighlight);
   for (auto& cluster : parsed_log_.bwe_probe_cluster_created_events()) {
@@ -1420,6 +1433,7 @@
   plot->AppendTimeSeries(std::move(loss_series));
   plot->AppendTimeSeriesIfNotEmpty(std::move(probe_failures_series));
   plot->AppendTimeSeries(std::move(delay_series));
+  plot->AppendTimeSeriesIfNotEmpty(std::move(scream_series));
   plot->AppendTimeSeries(std::move(created_series));
   plot->AppendTimeSeries(std::move(result_series));
 
@@ -1581,6 +1595,45 @@
   plot->SetTitle("Incoming ECN count per feedback");
 }
 
+void EventLogAnalyzer::CreateScreamRefWindowGraph(Plot* plot) const {
+  TimeSeries ref_window_series("RefWindow", LineStyle::kStep);
+
+  for (auto& scream_update : parsed_log_.bwe_scream_updates()) {
+    float x = config_.GetCallTimeSec(scream_update.log_time());
+    float y = static_cast<float>(scream_update.ref_window.bytes());
+    ref_window_series.points.emplace_back(x, y);
+  }
+
+  plot->AppendTimeSeries(std::move(ref_window_series));
+
+  plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
+                 "Time (s)", kLeftMargin, kRightMargin);
+  plot->SetSuggestedYAxis(0, 3000, "Bytes", kBottomMargin, kTopMargin);
+  plot->SetTitle("Scream Ref Window");
+}
+
+void EventLogAnalyzer::CreateScreamDelayEstimateGraph(Plot* plot) const {
+  TimeSeries smoothed_rtt_series("Smoothed RTT", LineStyle::kStep);
+  TimeSeries avg_queue_delay_series("Avg queue delay", LineStyle::kStep);
+
+  for (auto& scream_update : parsed_log_.bwe_scream_updates()) {
+    float x = config_.GetCallTimeSec(scream_update.log_time());
+    float smoothed_rtt_ms = static_cast<float>(scream_update.smoothed_rtt.ms());
+    smoothed_rtt_series.points.emplace_back(x, smoothed_rtt_ms);
+    float avg_queue_delay_ms =
+        static_cast<float>(scream_update.avg_queue_delay.ms());
+    avg_queue_delay_series.points.emplace_back(x, avg_queue_delay_ms);
+  }
+
+  plot->AppendTimeSeries(std::move(smoothed_rtt_series));
+  plot->AppendTimeSeries(std::move(avg_queue_delay_series));
+
+  plot->SetXAxis(config_.CallBeginTimeSec(), config_.CallEndTimeSec(),
+                 "Time (s)", kLeftMargin, kRightMargin);
+  plot->SetSuggestedYAxis(0, 50, "Delay (ms)", kBottomMargin, kTopMargin);
+  plot->SetTitle("Scream delay estimates");
+}
+
 void EventLogAnalyzer::CreateEcnFeedbackGraph(Plot* plot,
                                               PacketDirection direction) const {
   TimeSeries not_ect("Not ECN capable", LineStyle::kBar,
diff --git a/rtc_tools/rtc_event_log_visualizer/analyzer.h b/rtc_tools/rtc_event_log_visualizer/analyzer.h
index 1055821..86801ab 100644
--- a/rtc_tools/rtc_event_log_visualizer/analyzer.h
+++ b/rtc_tools/rtc_event_log_visualizer/analyzer.h
@@ -119,6 +119,8 @@
   void CreateOutgoingLossRateGraph(Plot* plot) const;
   void CreateOutgoingEcnFeedbackGraph(Plot* plot) const;
   void CreateIncomingEcnFeedbackGraph(Plot* plot) const;
+  void CreateScreamRefWindowGraph(Plot* plot) const;
+  void CreateScreamDelayEstimateGraph(Plot* plot) const;
   void CreateGoogCcSimulationGraph(Plot* plot) const;
   void CreateSendSideBweSimulationGraph(Plot* plot) const;
   void CreateReceiveSideBweSimulationGraph(Plot* plot) const;
diff --git a/rtc_tools/rtc_event_log_visualizer/main.cc b/rtc_tools/rtc_event_log_visualizer/main.cc
index 7748a59..1182f40 100644
--- a/rtc_tools/rtc_event_log_visualizer/main.cc
+++ b/rtc_tools/rtc_event_log_visualizer/main.cc
@@ -246,7 +246,8 @@
         "simulated_neteq_expand_rate"}},
       {"l4s",
        {"incoming_bitrate", "outgoing_bitrate", "incoming_ecn_feedback",
-        "outgoing_ecn_feedback"}}};
+        "outgoing_ecn_feedback", "scream_delay_estimates",
+        "scream_ref_window"}}};
 
   if (absl::GetFlag(FLAGS_list_plots)) {
     std::cerr << "List of registered plots (for use with the --plot flag):"