Plot delay feedback in RTCP arrival order.

This fixes a minor bug in the event_log_visualizer where packets are
processed in RTP send time order rather than RTCP arrival time order.
The bug makes time appear to move backwards if RTCP feedback for a later
RTP packet arrives before the feedback of an earlier RTP packet.

Bug: None
Change-Id: I06e8a25d5c65602bedcfd9e4ea1d23874bee9318
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/156169
Commit-Queue: Björn Terelius <terelius@webrtc.org>
Reviewed-by: Sebastian Jansson <srte@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#29448}
diff --git a/rtc_tools/BUILD.gn b/rtc_tools/BUILD.gn
index c99ed9b..8d09587 100644
--- a/rtc_tools/BUILD.gn
+++ b/rtc_tools/BUILD.gn
@@ -305,6 +305,7 @@
         "../rtc_base:rtc_base_approved",
         "../rtc_base:rtc_numerics",
         "../rtc_base:stringutils",
+        "//third_party/abseil-cpp/absl/algorithm:container",
         "//third_party/abseil-cpp/absl/strings",
       ]
     }
diff --git a/rtc_tools/rtc_event_log_visualizer/analyzer.cc b/rtc_tools/rtc_event_log_visualizer/analyzer.cc
index 126d9ca..0b5f795 100644
--- a/rtc_tools/rtc_event_log_visualizer/analyzer.cc
+++ b/rtc_tools/rtc_event_log_visualizer/analyzer.cc
@@ -18,6 +18,7 @@
 #include <string>
 #include <utility>
 
+#include "absl/algorithm/container.h"
 #include "absl/strings/string_view.h"
 #include "api/function_view.h"
 #include "api/transport/field_trial_based_config.h"
@@ -1455,7 +1456,13 @@
   int64_t min_rtt_ms = std::numeric_limits<int64_t>::max();
 
   int64_t prev_y = 0;
-  for (auto packet : GetNetworkTrace(parsed_log_)) {
+  std::vector<MatchedSendArrivalTimes> matched_rtp_rtcp =
+      GetNetworkTrace(parsed_log_);
+  absl::c_stable_sort(matched_rtp_rtcp, [](const MatchedSendArrivalTimes& a,
+                                           const MatchedSendArrivalTimes& b) {
+    return a.feedback_arrival_time_ms < b.feedback_arrival_time_ms;
+  });
+  for (const auto& packet : matched_rtp_rtcp) {
     if (packet.arrival_time_ms == PacketFeedback::kNotReceived)
       continue;
     float x = config_.GetCallTimeSec(1000 * packet.feedback_arrival_time_ms);