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