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