terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2016 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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #ifndef RTC_TOOLS_EVENT_LOG_VISUALIZER_ANALYZER_H_ |
| 12 | #define RTC_TOOLS_EVENT_LOG_VISUALIZER_ANALYZER_H_ |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 13 | |
terelius | 88e64e5 | 2016-07-19 01:51:06 -0700 | [diff] [blame] | 14 | #include <map> |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 15 | #include <memory> |
terelius | 0740a20 | 2016-08-08 10:21:04 -0700 | [diff] [blame] | 16 | #include <set> |
philipel | ccd7489 | 2016-09-05 02:46:25 -0700 | [diff] [blame] | 17 | #include <string> |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 18 | #include <utility> |
philipel | ccd7489 | 2016-09-05 02:46:25 -0700 | [diff] [blame] | 19 | #include <vector> |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 20 | |
Björn Terelius | ff61273 | 2018-04-25 14:23:01 +0000 | [diff] [blame] | 21 | #include "logging/rtc_event_log/rtc_event_log_parser.h" |
| 22 | #include "modules/audio_coding/audio_network_adaptor/include/audio_network_adaptor.h" |
| 23 | #include "modules/rtp_rtcp/include/rtp_rtcp_defines.h" |
| 24 | #include "modules/rtp_rtcp/source/rtcp_packet.h" |
| 25 | #include "rtc_base/function_view.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 26 | #include "rtc_tools/event_log_visualizer/plot_base.h" |
Bjorn Terelius | 2eb3188 | 2017-11-30 15:15:25 +0100 | [diff] [blame] | 27 | #include "rtc_tools/event_log_visualizer/triage_notifications.h" |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 28 | |
| 29 | namespace webrtc { |
Björn Terelius | ff61273 | 2018-04-25 14:23:01 +0000 | [diff] [blame] | 30 | namespace plotting { |
| 31 | |
| 32 | struct LoggedRtpPacket { |
| 33 | LoggedRtpPacket(uint64_t timestamp, |
| 34 | RTPHeader header, |
| 35 | size_t header_length, |
| 36 | size_t total_length) |
| 37 | : timestamp(timestamp), |
| 38 | header(header), |
| 39 | header_length(header_length), |
| 40 | total_length(total_length) {} |
| 41 | uint64_t timestamp; |
| 42 | // TODO(terelius): This allocates space for 15 CSRCs even if none are used. |
| 43 | RTPHeader header; |
| 44 | size_t header_length; |
| 45 | size_t total_length; |
| 46 | }; |
| 47 | |
| 48 | struct LoggedRtcpPacket { |
| 49 | LoggedRtcpPacket(uint64_t timestamp, |
| 50 | RTCPPacketType rtcp_type, |
| 51 | std::unique_ptr<rtcp::RtcpPacket> rtcp_packet) |
| 52 | : timestamp(timestamp), type(rtcp_type), packet(std::move(rtcp_packet)) {} |
| 53 | uint64_t timestamp; |
| 54 | RTCPPacketType type; |
| 55 | std::unique_ptr<rtcp::RtcpPacket> packet; |
| 56 | }; |
| 57 | |
| 58 | struct LossBasedBweUpdate { |
| 59 | uint64_t timestamp; |
| 60 | int32_t new_bitrate; |
| 61 | uint8_t fraction_loss; |
| 62 | int32_t expected_packets; |
| 63 | }; |
| 64 | |
| 65 | struct AudioNetworkAdaptationEvent { |
| 66 | uint64_t timestamp; |
| 67 | AudioEncoderRuntimeConfig config; |
| 68 | }; |
michaelt | 6e5b219 | 2017-02-22 07:33:27 -0800 | [diff] [blame] | 69 | |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 70 | class EventLogAnalyzer { |
| 71 | public: |
| 72 | // The EventLogAnalyzer keeps a reference to the ParsedRtcEventLog for the |
| 73 | // duration of its lifetime. The ParsedRtcEventLog must not be destroyed or |
| 74 | // modified while the EventLogAnalyzer is being used. |
| 75 | explicit EventLogAnalyzer(const ParsedRtcEventLog& log); |
| 76 | |
Björn Terelius | ff61273 | 2018-04-25 14:23:01 +0000 | [diff] [blame] | 77 | void CreatePacketGraph(PacketDirection desired_direction, Plot* plot); |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 78 | |
Björn Terelius | ff61273 | 2018-04-25 14:23:01 +0000 | [diff] [blame] | 79 | void CreateAccumulatedPacketsGraph(PacketDirection desired_direction, |
| 80 | Plot* plot); |
philipel | ccd7489 | 2016-09-05 02:46:25 -0700 | [diff] [blame] | 81 | |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 82 | void CreatePlayoutGraph(Plot* plot); |
| 83 | |
Björn Terelius | ff61273 | 2018-04-25 14:23:01 +0000 | [diff] [blame] | 84 | void CreateAudioLevelGraph(Plot* plot); |
ivoc | aac9d6f | 2016-09-22 07:01:47 -0700 | [diff] [blame] | 85 | |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 86 | void CreateSequenceNumberGraph(Plot* plot); |
| 87 | |
Stefan Holmer | 99f8e08 | 2016-09-09 13:37:50 +0200 | [diff] [blame] | 88 | void CreateIncomingPacketLossGraph(Plot* plot); |
| 89 | |
terelius | 2ee076d | 2017-08-15 02:04:02 -0700 | [diff] [blame] | 90 | void CreateIncomingDelayDeltaGraph(Plot* plot); |
| 91 | void CreateIncomingDelayGraph(Plot* plot); |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 92 | |
terelius | f736d23 | 2016-08-04 10:00:11 -0700 | [diff] [blame] | 93 | void CreateFractionLossGraph(Plot* plot); |
| 94 | |
Björn Terelius | ff61273 | 2018-04-25 14:23:01 +0000 | [diff] [blame] | 95 | void CreateTotalBitrateGraph(PacketDirection desired_direction, |
| 96 | Plot* plot, |
| 97 | bool show_detector_state = false, |
| 98 | bool show_alr_state = false); |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 99 | |
Björn Terelius | ff61273 | 2018-04-25 14:23:01 +0000 | [diff] [blame] | 100 | void CreateStreamBitrateGraph(PacketDirection desired_direction, Plot* plot); |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 101 | |
Bjorn Terelius | 28db266 | 2017-10-04 14:22:43 +0200 | [diff] [blame] | 102 | void CreateSendSideBweSimulationGraph(Plot* plot); |
| 103 | void CreateReceiveSideBweSimulationGraph(Plot* plot); |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 104 | |
terelius | e34c19c | 2016-08-15 08:47:14 -0700 | [diff] [blame] | 105 | void CreateNetworkDelayFeedbackGraph(Plot* plot); |
Bjorn Terelius | 0295a96 | 2017-10-25 17:42:41 +0200 | [diff] [blame] | 106 | void CreatePacerDelayGraph(Plot* plot); |
Björn Terelius | ff61273 | 2018-04-25 14:23:01 +0000 | [diff] [blame] | 107 | void CreateTimestampGraph(Plot* plot); |
stefan | c3de033 | 2016-08-02 07:22:17 -0700 | [diff] [blame] | 108 | |
michaelt | 6e5b219 | 2017-02-22 07:33:27 -0800 | [diff] [blame] | 109 | void CreateAudioEncoderTargetBitrateGraph(Plot* plot); |
| 110 | void CreateAudioEncoderFrameLengthGraph(Plot* plot); |
terelius | 2ee076d | 2017-08-15 02:04:02 -0700 | [diff] [blame] | 111 | void CreateAudioEncoderPacketLossGraph(Plot* plot); |
michaelt | 6e5b219 | 2017-02-22 07:33:27 -0800 | [diff] [blame] | 112 | void CreateAudioEncoderEnableFecGraph(Plot* plot); |
| 113 | void CreateAudioEncoderEnableDtxGraph(Plot* plot); |
| 114 | void CreateAudioEncoderNumChannelsGraph(Plot* plot); |
henrik.lundin | 3c938fc | 2017-06-14 06:09:58 -0700 | [diff] [blame] | 115 | void CreateAudioJitterBufferGraph(const std::string& replacement_file_name, |
| 116 | int file_sample_rate_hz, |
| 117 | Plot* plot); |
michaelt | 6e5b219 | 2017-02-22 07:33:27 -0800 | [diff] [blame] | 118 | |
Qingsi Wang | 8eca1ff | 2018-02-02 11:49:44 -0800 | [diff] [blame] | 119 | void CreateIceCandidatePairConfigGraph(Plot* plot); |
| 120 | void CreateIceConnectivityCheckGraph(Plot* plot); |
| 121 | |
Björn Terelius | ff61273 | 2018-04-25 14:23:01 +0000 | [diff] [blame] | 122 | // Returns a vector of capture and arrival timestamps for the video frames |
| 123 | // of the stream with the most number of frames. |
| 124 | std::vector<std::pair<int64_t, int64_t>> GetFrameTimestamps() const; |
| 125 | |
Bjorn Terelius | 2eb3188 | 2017-11-30 15:15:25 +0100 | [diff] [blame] | 126 | void CreateTriageNotifications(); |
| 127 | void PrintNotifications(FILE* file); |
| 128 | |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 129 | private: |
Björn Terelius | ff61273 | 2018-04-25 14:23:01 +0000 | [diff] [blame] | 130 | class StreamId { |
| 131 | public: |
| 132 | StreamId(uint32_t ssrc, webrtc::PacketDirection direction) |
| 133 | : ssrc_(ssrc), direction_(direction) {} |
| 134 | bool operator<(const StreamId& other) const { |
| 135 | return std::tie(ssrc_, direction_) < |
| 136 | std::tie(other.ssrc_, other.direction_); |
terelius | 0740a20 | 2016-08-08 10:21:04 -0700 | [diff] [blame] | 137 | } |
Björn Terelius | ff61273 | 2018-04-25 14:23:01 +0000 | [diff] [blame] | 138 | bool operator==(const StreamId& other) const { |
| 139 | return std::tie(ssrc_, direction_) == |
| 140 | std::tie(other.ssrc_, other.direction_); |
terelius | 0740a20 | 2016-08-08 10:21:04 -0700 | [diff] [blame] | 141 | } |
Björn Terelius | ff61273 | 2018-04-25 14:23:01 +0000 | [diff] [blame] | 142 | uint32_t GetSsrc() const { return ssrc_; } |
| 143 | webrtc::PacketDirection GetDirection() const { return direction_; } |
terelius | 88e64e5 | 2016-07-19 01:51:06 -0700 | [diff] [blame] | 144 | |
Björn Terelius | ff61273 | 2018-04-25 14:23:01 +0000 | [diff] [blame] | 145 | private: |
| 146 | uint32_t ssrc_; |
| 147 | webrtc::PacketDirection direction_; |
| 148 | }; |
terelius | 88e64e5 | 2016-07-19 01:51:06 -0700 | [diff] [blame] | 149 | |
Björn Terelius | ff61273 | 2018-04-25 14:23:01 +0000 | [diff] [blame] | 150 | template <typename T> |
| 151 | void CreateAccumulatedPacketsTimeSeries( |
| 152 | PacketDirection desired_direction, |
| 153 | Plot* plot, |
| 154 | const std::map<StreamId, std::vector<T>>& packets, |
| 155 | const std::string& label_prefix); |
philipel | ccd7489 | 2016-09-05 02:46:25 -0700 | [diff] [blame] | 156 | |
Björn Terelius | ff61273 | 2018-04-25 14:23:01 +0000 | [diff] [blame] | 157 | bool IsRtxSsrc(StreamId stream_id) const; |
terelius | 0740a20 | 2016-08-08 10:21:04 -0700 | [diff] [blame] | 158 | |
Björn Terelius | ff61273 | 2018-04-25 14:23:01 +0000 | [diff] [blame] | 159 | bool IsVideoSsrc(StreamId stream_id) const; |
| 160 | |
| 161 | bool IsAudioSsrc(StreamId stream_id) const; |
| 162 | |
| 163 | std::string GetStreamName(StreamId stream_id) const; |
| 164 | |
| 165 | rtc::Optional<uint32_t> EstimateRtpClockFrequency( |
| 166 | const std::vector<LoggedRtpPacket>& packets) const; |
terelius | 0740a20 | 2016-08-08 10:21:04 -0700 | [diff] [blame] | 167 | |
Bjorn Terelius | 2eb3188 | 2017-11-30 15:15:25 +0100 | [diff] [blame] | 168 | float ToCallTime(int64_t timestamp) const; |
| 169 | |
Björn Terelius | ff61273 | 2018-04-25 14:23:01 +0000 | [diff] [blame] | 170 | void Notification(std::unique_ptr<TriageNotification> notification); |
Bjorn Terelius | 2eb3188 | 2017-11-30 15:15:25 +0100 | [diff] [blame] | 171 | |
Qingsi Wang | 8eca1ff | 2018-02-02 11:49:44 -0800 | [diff] [blame] | 172 | std::string GetCandidatePairLogDescriptionFromId(uint32_t candidate_pair_id); |
| 173 | |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 174 | const ParsedRtcEventLog& parsed_log_; |
| 175 | |
| 176 | // A list of SSRCs we are interested in analysing. |
| 177 | // If left empty, all SSRCs will be considered relevant. |
| 178 | std::vector<uint32_t> desired_ssrc_; |
| 179 | |
Björn Terelius | ff61273 | 2018-04-25 14:23:01 +0000 | [diff] [blame] | 180 | // Tracks what each stream is configured for. Note that a single SSRC can be |
| 181 | // in several sets. For example, the SSRC used for sending video over RTX |
| 182 | // will appear in both video_ssrcs_ and rtx_ssrcs_. In the unlikely case that |
| 183 | // an SSRC is reconfigured to a different media type mid-call, it will also |
| 184 | // appear in multiple sets. |
| 185 | std::set<StreamId> rtx_ssrcs_; |
| 186 | std::set<StreamId> video_ssrcs_; |
| 187 | std::set<StreamId> audio_ssrcs_; |
| 188 | |
| 189 | // Maps a stream identifier consisting of ssrc and direction to the parsed |
| 190 | // RTP headers in that stream. Header extensions are parsed if the stream |
| 191 | // has been configured. |
| 192 | std::map<StreamId, std::vector<LoggedRtpPacket>> rtp_packets_; |
| 193 | |
| 194 | std::map<StreamId, std::vector<LoggedRtcpPacket>> rtcp_packets_; |
| 195 | |
| 196 | // Maps an SSRC to the timestamps of parsed audio playout events. |
| 197 | std::map<uint32_t, std::vector<uint64_t>> audio_playout_events_; |
| 198 | |
henrik.lundin | 3c938fc | 2017-06-14 06:09:58 -0700 | [diff] [blame] | 199 | // Stores the timestamps for all log segments, in the form of associated start |
| 200 | // and end events. |
Björn Terelius | ff61273 | 2018-04-25 14:23:01 +0000 | [diff] [blame] | 201 | std::vector<std::pair<uint64_t, uint64_t>> log_segments_; |
henrik.lundin | 3c938fc | 2017-06-14 06:09:58 -0700 | [diff] [blame] | 202 | |
Björn Terelius | ff61273 | 2018-04-25 14:23:01 +0000 | [diff] [blame] | 203 | // A list of all updates from the send-side loss-based bandwidth estimator. |
| 204 | std::vector<LossBasedBweUpdate> bwe_loss_updates_; |
| 205 | |
| 206 | std::vector<AudioNetworkAdaptationEvent> audio_network_adaptation_events_; |
| 207 | |
| 208 | std::vector<ParsedRtcEventLog::BweProbeClusterCreatedEvent> |
| 209 | bwe_probe_cluster_created_events_; |
| 210 | |
| 211 | std::vector<ParsedRtcEventLog::BweProbeResultEvent> bwe_probe_result_events_; |
| 212 | |
| 213 | std::vector<ParsedRtcEventLog::BweDelayBasedUpdate> bwe_delay_updates_; |
| 214 | |
| 215 | std::vector<std::unique_ptr<TriageNotification>> notifications_; |
| 216 | |
| 217 | std::vector<ParsedRtcEventLog::AlrStateEvent> alr_state_events_; |
| 218 | |
| 219 | std::vector<ParsedRtcEventLog::IceCandidatePairConfig> |
| 220 | ice_candidate_pair_configs_; |
| 221 | |
| 222 | std::vector<ParsedRtcEventLog::IceCandidatePairEvent> |
| 223 | ice_candidate_pair_events_; |
Qingsi Wang | 8eca1ff | 2018-02-02 11:49:44 -0800 | [diff] [blame] | 224 | |
| 225 | std::map<uint32_t, std::string> candidate_pair_desc_by_id_; |
| 226 | |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 227 | // Window and step size used for calculating moving averages, e.g. bitrate. |
| 228 | // The generated data points will be |step_| microseconds apart. |
| 229 | // Only events occuring at most |window_duration_| microseconds before the |
| 230 | // current data point will be part of the average. |
Björn Terelius | ff61273 | 2018-04-25 14:23:01 +0000 | [diff] [blame] | 231 | uint64_t window_duration_; |
| 232 | uint64_t step_; |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 233 | |
| 234 | // First and last events of the log. |
Björn Terelius | ff61273 | 2018-04-25 14:23:01 +0000 | [diff] [blame] | 235 | uint64_t begin_time_; |
| 236 | uint64_t end_time_; |
terelius | dc35dcd | 2016-08-01 12:03:27 -0700 | [diff] [blame] | 237 | |
| 238 | // Duration (in seconds) of log file. |
| 239 | float call_duration_s_; |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 240 | }; |
| 241 | |
Björn Terelius | ff61273 | 2018-04-25 14:23:01 +0000 | [diff] [blame] | 242 | } // namespace plotting |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 243 | } // namespace webrtc |
| 244 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 245 | #endif // RTC_TOOLS_EVENT_LOG_VISUALIZER_ANALYZER_H_ |