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 | |
| 11 | #ifndef WEBRTC_TOOLS_EVENT_LOG_VISUALIZER_ANALYZER_H_ |
| 12 | #define WEBRTC_TOOLS_EVENT_LOG_VISUALIZER_ANALYZER_H_ |
| 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 | |
michaelt | 6e5b219 | 2017-02-22 07:33:27 -0800 | [diff] [blame] | 21 | #include "webrtc/base/function_view.h" |
skvlad | cc91d28 | 2016-10-03 18:31:22 -0700 | [diff] [blame] | 22 | #include "webrtc/logging/rtc_event_log/rtc_event_log_parser.h" |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 23 | #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" |
| 24 | #include "webrtc/modules/rtp_rtcp/source/rtcp_packet.h" |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 25 | #include "webrtc/tools/event_log_visualizer/plot_base.h" |
| 26 | |
| 27 | namespace webrtc { |
| 28 | namespace plotting { |
| 29 | |
terelius | ccbbf8d | 2016-08-10 07:34:28 -0700 | [diff] [blame] | 30 | struct LoggedRtpPacket { |
| 31 | LoggedRtpPacket(uint64_t timestamp, RTPHeader header, size_t total_length) |
| 32 | : timestamp(timestamp), header(header), total_length(total_length) {} |
| 33 | uint64_t timestamp; |
terelius | 6addf49 | 2016-08-23 17:34:07 -0700 | [diff] [blame] | 34 | // TODO(terelius): This allocates space for 15 CSRCs even if none are used. |
terelius | ccbbf8d | 2016-08-10 07:34:28 -0700 | [diff] [blame] | 35 | RTPHeader header; |
| 36 | size_t total_length; |
| 37 | }; |
| 38 | |
| 39 | struct LoggedRtcpPacket { |
| 40 | LoggedRtcpPacket(uint64_t timestamp, |
| 41 | RTCPPacketType rtcp_type, |
| 42 | std::unique_ptr<rtcp::RtcpPacket> rtcp_packet) |
| 43 | : timestamp(timestamp), type(rtcp_type), packet(std::move(rtcp_packet)) {} |
| 44 | uint64_t timestamp; |
| 45 | RTCPPacketType type; |
| 46 | std::unique_ptr<rtcp::RtcpPacket> packet; |
| 47 | }; |
| 48 | |
terelius | 424e6cf | 2017-02-20 05:14:41 -0800 | [diff] [blame] | 49 | struct LossBasedBweUpdate { |
terelius | ccbbf8d | 2016-08-10 07:34:28 -0700 | [diff] [blame] | 50 | uint64_t timestamp; |
| 51 | int32_t new_bitrate; |
| 52 | uint8_t fraction_loss; |
| 53 | int32_t expected_packets; |
| 54 | }; |
| 55 | |
michaelt | 6e5b219 | 2017-02-22 07:33:27 -0800 | [diff] [blame] | 56 | struct AudioNetworkAdaptationEvent { |
| 57 | uint64_t timestamp; |
| 58 | AudioNetworkAdaptor::EncoderRuntimeConfig config; |
| 59 | }; |
| 60 | |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 61 | class EventLogAnalyzer { |
| 62 | public: |
| 63 | // The EventLogAnalyzer keeps a reference to the ParsedRtcEventLog for the |
| 64 | // duration of its lifetime. The ParsedRtcEventLog must not be destroyed or |
| 65 | // modified while the EventLogAnalyzer is being used. |
| 66 | explicit EventLogAnalyzer(const ParsedRtcEventLog& log); |
| 67 | |
| 68 | void CreatePacketGraph(PacketDirection desired_direction, Plot* plot); |
| 69 | |
philipel | ccd7489 | 2016-09-05 02:46:25 -0700 | [diff] [blame] | 70 | void CreateAccumulatedPacketsGraph(PacketDirection desired_direction, |
| 71 | Plot* plot); |
| 72 | |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 73 | void CreatePlayoutGraph(Plot* plot); |
| 74 | |
ivoc | aac9d6f | 2016-09-22 07:01:47 -0700 | [diff] [blame] | 75 | void CreateAudioLevelGraph(Plot* plot); |
| 76 | |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 77 | void CreateSequenceNumberGraph(Plot* plot); |
| 78 | |
Stefan Holmer | 99f8e08 | 2016-09-09 13:37:50 +0200 | [diff] [blame] | 79 | void CreateIncomingPacketLossGraph(Plot* plot); |
| 80 | |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 81 | void CreateDelayChangeGraph(Plot* plot); |
| 82 | |
| 83 | void CreateAccumulatedDelayChangeGraph(Plot* plot); |
| 84 | |
terelius | f736d23 | 2016-08-04 10:00:11 -0700 | [diff] [blame] | 85 | void CreateFractionLossGraph(Plot* plot); |
| 86 | |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 87 | void CreateTotalBitrateGraph(PacketDirection desired_direction, Plot* plot); |
| 88 | |
| 89 | void CreateStreamBitrateGraph(PacketDirection desired_direction, Plot* plot); |
| 90 | |
terelius | e34c19c | 2016-08-15 08:47:14 -0700 | [diff] [blame] | 91 | void CreateBweSimulationGraph(Plot* plot); |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 92 | |
terelius | e34c19c | 2016-08-15 08:47:14 -0700 | [diff] [blame] | 93 | void CreateNetworkDelayFeedbackGraph(Plot* plot); |
stefan | e372d3c | 2017-02-02 08:04:18 -0800 | [diff] [blame] | 94 | void CreateTimestampGraph(Plot* plot); |
stefan | c3de033 | 2016-08-02 07:22:17 -0700 | [diff] [blame] | 95 | |
michaelt | 6e5b219 | 2017-02-22 07:33:27 -0800 | [diff] [blame] | 96 | void CreateAudioEncoderTargetBitrateGraph(Plot* plot); |
| 97 | void CreateAudioEncoderFrameLengthGraph(Plot* plot); |
| 98 | void CreateAudioEncoderUplinkPacketLossFractionGraph(Plot* plot); |
| 99 | void CreateAudioEncoderEnableFecGraph(Plot* plot); |
| 100 | void CreateAudioEncoderEnableDtxGraph(Plot* plot); |
| 101 | void CreateAudioEncoderNumChannelsGraph(Plot* plot); |
| 102 | |
stefan | 0838327 | 2016-12-20 08:51:52 -0800 | [diff] [blame] | 103 | // Returns a vector of capture and arrival timestamps for the video frames |
| 104 | // of the stream with the most number of frames. |
| 105 | std::vector<std::pair<int64_t, int64_t>> GetFrameTimestamps() const; |
| 106 | |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 107 | private: |
terelius | 88e64e5 | 2016-07-19 01:51:06 -0700 | [diff] [blame] | 108 | class StreamId { |
| 109 | public: |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 110 | StreamId(uint32_t ssrc, webrtc::PacketDirection direction) |
| 111 | : ssrc_(ssrc), direction_(direction) {} |
terelius | 0740a20 | 2016-08-08 10:21:04 -0700 | [diff] [blame] | 112 | bool operator<(const StreamId& other) const { |
| 113 | return std::tie(ssrc_, direction_) < |
| 114 | std::tie(other.ssrc_, other.direction_); |
| 115 | } |
| 116 | bool operator==(const StreamId& other) const { |
| 117 | return std::tie(ssrc_, direction_) == |
| 118 | std::tie(other.ssrc_, other.direction_); |
| 119 | } |
terelius | 88e64e5 | 2016-07-19 01:51:06 -0700 | [diff] [blame] | 120 | uint32_t GetSsrc() const { return ssrc_; } |
| 121 | webrtc::PacketDirection GetDirection() const { return direction_; } |
terelius | 88e64e5 | 2016-07-19 01:51:06 -0700 | [diff] [blame] | 122 | |
| 123 | private: |
| 124 | uint32_t ssrc_; |
| 125 | webrtc::PacketDirection direction_; |
terelius | 88e64e5 | 2016-07-19 01:51:06 -0700 | [diff] [blame] | 126 | }; |
| 127 | |
philipel | ccd7489 | 2016-09-05 02:46:25 -0700 | [diff] [blame] | 128 | template <typename T> |
| 129 | void CreateAccumulatedPacketsTimeSeries( |
| 130 | PacketDirection desired_direction, |
| 131 | Plot* plot, |
| 132 | const std::map<StreamId, std::vector<T>>& packets, |
| 133 | const std::string& label_prefix); |
| 134 | |
Stefan Holmer | 99f8e08 | 2016-09-09 13:37:50 +0200 | [diff] [blame] | 135 | bool IsRtxSsrc(StreamId stream_id) const; |
terelius | 0740a20 | 2016-08-08 10:21:04 -0700 | [diff] [blame] | 136 | |
Stefan Holmer | 99f8e08 | 2016-09-09 13:37:50 +0200 | [diff] [blame] | 137 | bool IsVideoSsrc(StreamId stream_id) const; |
terelius | 0740a20 | 2016-08-08 10:21:04 -0700 | [diff] [blame] | 138 | |
Stefan Holmer | 99f8e08 | 2016-09-09 13:37:50 +0200 | [diff] [blame] | 139 | bool IsAudioSsrc(StreamId stream_id) const; |
| 140 | |
| 141 | std::string GetStreamName(StreamId) const; |
terelius | 0740a20 | 2016-08-08 10:21:04 -0700 | [diff] [blame] | 142 | |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 143 | const ParsedRtcEventLog& parsed_log_; |
| 144 | |
| 145 | // A list of SSRCs we are interested in analysing. |
| 146 | // If left empty, all SSRCs will be considered relevant. |
| 147 | std::vector<uint32_t> desired_ssrc_; |
| 148 | |
terelius | 0740a20 | 2016-08-08 10:21:04 -0700 | [diff] [blame] | 149 | // Tracks what each stream is configured for. Note that a single SSRC can be |
| 150 | // in several sets. For example, the SSRC used for sending video over RTX |
| 151 | // will appear in both video_ssrcs_ and rtx_ssrcs_. In the unlikely case that |
| 152 | // an SSRC is reconfigured to a different media type mid-call, it will also |
| 153 | // appear in multiple sets. |
| 154 | std::set<StreamId> rtx_ssrcs_; |
| 155 | std::set<StreamId> video_ssrcs_; |
| 156 | std::set<StreamId> audio_ssrcs_; |
| 157 | |
| 158 | // Maps a stream identifier consisting of ssrc and direction to the parsed |
| 159 | // RTP headers in that stream. Header extensions are parsed if the stream |
| 160 | // has been configured. |
terelius | 88e64e5 | 2016-07-19 01:51:06 -0700 | [diff] [blame] | 161 | std::map<StreamId, std::vector<LoggedRtpPacket>> rtp_packets_; |
| 162 | |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 163 | std::map<StreamId, std::vector<LoggedRtcpPacket>> rtcp_packets_; |
| 164 | |
terelius | 8058e58 | 2016-07-25 01:32:41 -0700 | [diff] [blame] | 165 | // A list of all updates from the send-side loss-based bandwidth estimator. |
terelius | 424e6cf | 2017-02-20 05:14:41 -0800 | [diff] [blame] | 166 | std::vector<LossBasedBweUpdate> bwe_loss_updates_; |
terelius | 8058e58 | 2016-07-25 01:32:41 -0700 | [diff] [blame] | 167 | |
michaelt | 6e5b219 | 2017-02-22 07:33:27 -0800 | [diff] [blame] | 168 | std::vector<AudioNetworkAdaptationEvent> audio_network_adaptation_events_; |
| 169 | |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 170 | // Window and step size used for calculating moving averages, e.g. bitrate. |
| 171 | // The generated data points will be |step_| microseconds apart. |
| 172 | // Only events occuring at most |window_duration_| microseconds before the |
| 173 | // current data point will be part of the average. |
| 174 | uint64_t window_duration_; |
| 175 | uint64_t step_; |
| 176 | |
| 177 | // First and last events of the log. |
| 178 | uint64_t begin_time_; |
| 179 | uint64_t end_time_; |
terelius | dc35dcd | 2016-08-01 12:03:27 -0700 | [diff] [blame] | 180 | |
| 181 | // Duration (in seconds) of log file. |
| 182 | float call_duration_s_; |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 183 | }; |
| 184 | |
| 185 | } // namespace plotting |
| 186 | } // namespace webrtc |
| 187 | |
| 188 | #endif // WEBRTC_TOOLS_EVENT_LOG_VISUALIZER_ANALYZER_H_ |