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