Add lower/upper link capacity to the outgoing bitrate graph.

Bug: webrtc:14273
Change-Id: I8d9f1ac0d41b74a226abdff00f420d6b0624b73c
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/250442
Commit-Queue: Diep Bui <diepbp@google.com>
Reviewed-by: Björn Terelius <terelius@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#37557}
diff --git a/rtc_tools/rtc_event_log_visualizer/analyzer.cc b/rtc_tools/rtc_event_log_visualizer/analyzer.cc
index 59f64ef..ddd65cb 100644
--- a/rtc_tools/rtc_event_log_visualizer/analyzer.cc
+++ b/rtc_tools/rtc_event_log_visualizer/analyzer.cc
@@ -882,9 +882,11 @@
 }
 
 // Plot the total bandwidth used by all RTP streams.
-void EventLogAnalyzer::CreateTotalOutgoingBitrateGraph(Plot* plot,
-                                                       bool show_detector_state,
-                                                       bool show_alr_state) {
+void EventLogAnalyzer::CreateTotalOutgoingBitrateGraph(
+    Plot* plot,
+    bool show_detector_state,
+    bool show_alr_state,
+    bool show_link_capacity) {
   // TODO(terelius): This could be provided by the parser.
   std::multimap<Timestamp, size_t> packets_in_order;
   for (const auto& stream : parsed_log_.outgoing_rtp_packets_by_ssrc()) {
@@ -930,6 +932,24 @@
     loss_series.points.emplace_back(x, y);
   }
 
+  TimeSeries link_capacity_lower_series("Link-capacity-lower",
+                                        LineStyle::kStep);
+  TimeSeries link_capacity_upper_series("Link-capacity-upper",
+                                        LineStyle::kStep);
+  for (auto& remote_estimate_event : parsed_log_.remote_estimate_events()) {
+    float x = config_.GetCallTimeSec(remote_estimate_event.log_time());
+    if (remote_estimate_event.link_capacity_lower.has_value()) {
+      float link_capacity_lower = static_cast<float>(
+          remote_estimate_event.link_capacity_lower.value().kbps());
+      link_capacity_lower_series.points.emplace_back(x, link_capacity_lower);
+    }
+    if (remote_estimate_event.link_capacity_upper.has_value()) {
+      float link_capacity_upper = static_cast<float>(
+          remote_estimate_event.link_capacity_upper.value().kbps());
+      link_capacity_upper_series.points.emplace_back(x, link_capacity_upper);
+    }
+  }
+
   TimeSeries delay_series("Delay-based estimate", LineStyle::kStep);
   IntervalSeries overusing_series("Overusing", "#ff8e82",
                                   IntervalSeries::kHorizontal);
@@ -1026,6 +1046,12 @@
   if (show_alr_state) {
     plot->AppendIntervalSeries(std::move(alr_state));
   }
+
+  if (show_link_capacity) {
+    plot->AppendTimeSeriesIfNotEmpty(std::move(link_capacity_lower_series));
+    plot->AppendTimeSeriesIfNotEmpty(std::move(link_capacity_upper_series));
+  }
+
   plot->AppendTimeSeries(std::move(loss_series));
   plot->AppendTimeSeriesIfNotEmpty(std::move(probe_failures_series));
   plot->AppendTimeSeries(std::move(delay_series));
diff --git a/rtc_tools/rtc_event_log_visualizer/analyzer.h b/rtc_tools/rtc_event_log_visualizer/analyzer.h
index 4918cf4..1f31d8b 100644
--- a/rtc_tools/rtc_event_log_visualizer/analyzer.h
+++ b/rtc_tools/rtc_event_log_visualizer/analyzer.h
@@ -59,7 +59,8 @@
   void CreateTotalIncomingBitrateGraph(Plot* plot);
   void CreateTotalOutgoingBitrateGraph(Plot* plot,
                                        bool show_detector_state = false,
-                                       bool show_alr_state = false);
+                                       bool show_alr_state = false,
+                                       bool show_link_capacity = false);
 
   void CreateStreamBitrateGraph(PacketDirection direction, Plot* plot);
   void CreateBitrateAllocationGraph(PacketDirection direction, Plot* plot);
diff --git a/rtc_tools/rtc_event_log_visualizer/main.cc b/rtc_tools/rtc_event_log_visualizer/main.cc
index 0870f8f..9f0c632 100644
--- a/rtc_tools/rtc_event_log_visualizer/main.cc
+++ b/rtc_tools/rtc_event_log_visualizer/main.cc
@@ -70,6 +70,12 @@
           "Show the state ALR state on the total bitrate graph");
 
 ABSL_FLAG(bool,
+          show_link_capacity,
+          true,
+          "Show the lower and upper link capacity on the outgoing bitrate "
+          "graph");
+
+ABSL_FLAG(bool,
           parse_unconfigured_header_extensions,
           true,
           "Attempt to parse unconfigured header extensions using the default "
@@ -337,7 +343,8 @@
   plots.RegisterPlot("outgoing_bitrate", [&](Plot* plot) {
     analyzer.CreateTotalOutgoingBitrateGraph(
         plot, absl::GetFlag(FLAGS_show_detector_state),
-        absl::GetFlag(FLAGS_show_alr_state));
+        absl::GetFlag(FLAGS_show_alr_state),
+        absl::GetFlag(FLAGS_show_link_capacity));
   });
   plots.RegisterPlot("incoming_stream_bitrate", [&](Plot* plot) {
     analyzer.CreateStreamBitrateGraph(webrtc::kIncomingPacket, plot);