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> |
| 17 | #include <utility> |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 18 | |
| 19 | #include "webrtc/call/rtc_event_log_parser.h" |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 20 | #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" |
| 21 | #include "webrtc/modules/rtp_rtcp/source/rtcp_packet.h" |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 22 | #include "webrtc/tools/event_log_visualizer/plot_base.h" |
| 23 | |
| 24 | namespace webrtc { |
| 25 | namespace plotting { |
| 26 | |
| 27 | class EventLogAnalyzer { |
| 28 | public: |
| 29 | // The EventLogAnalyzer keeps a reference to the ParsedRtcEventLog for the |
| 30 | // duration of its lifetime. The ParsedRtcEventLog must not be destroyed or |
| 31 | // modified while the EventLogAnalyzer is being used. |
| 32 | explicit EventLogAnalyzer(const ParsedRtcEventLog& log); |
| 33 | |
| 34 | void CreatePacketGraph(PacketDirection desired_direction, Plot* plot); |
| 35 | |
| 36 | void CreatePlayoutGraph(Plot* plot); |
| 37 | |
| 38 | void CreateSequenceNumberGraph(Plot* plot); |
| 39 | |
| 40 | void CreateDelayChangeGraph(Plot* plot); |
| 41 | |
| 42 | void CreateAccumulatedDelayChangeGraph(Plot* plot); |
| 43 | |
| 44 | void CreateTotalBitrateGraph(PacketDirection desired_direction, Plot* plot); |
| 45 | |
| 46 | void CreateStreamBitrateGraph(PacketDirection desired_direction, Plot* plot); |
| 47 | |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 48 | void CreateBweGraph(Plot* plot); |
| 49 | |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 50 | private: |
terelius | 88e64e5 | 2016-07-19 01:51:06 -0700 | [diff] [blame] | 51 | class StreamId { |
| 52 | public: |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 53 | StreamId(uint32_t ssrc, webrtc::PacketDirection direction) |
| 54 | : ssrc_(ssrc), direction_(direction) {} |
terelius | 88e64e5 | 2016-07-19 01:51:06 -0700 | [diff] [blame] | 55 | bool operator<(const StreamId& other) const; |
| 56 | bool operator==(const StreamId& other) const; |
| 57 | uint32_t GetSsrc() const { return ssrc_; } |
| 58 | webrtc::PacketDirection GetDirection() const { return direction_; } |
terelius | 88e64e5 | 2016-07-19 01:51:06 -0700 | [diff] [blame] | 59 | |
| 60 | private: |
| 61 | uint32_t ssrc_; |
| 62 | webrtc::PacketDirection direction_; |
terelius | 88e64e5 | 2016-07-19 01:51:06 -0700 | [diff] [blame] | 63 | }; |
| 64 | |
| 65 | struct LoggedRtpPacket { |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 66 | LoggedRtpPacket(uint64_t timestamp, RTPHeader header, size_t total_length) |
| 67 | : timestamp(timestamp), header(header), total_length(total_length) {} |
terelius | 88e64e5 | 2016-07-19 01:51:06 -0700 | [diff] [blame] | 68 | uint64_t timestamp; |
| 69 | RTPHeader header; |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 70 | size_t total_length; |
| 71 | }; |
| 72 | |
| 73 | struct LoggedRtcpPacket { |
| 74 | LoggedRtcpPacket(uint64_t timestamp, |
| 75 | RTCPPacketType rtcp_type, |
| 76 | std::unique_ptr<rtcp::RtcpPacket> rtcp_packet) |
| 77 | : timestamp(timestamp), |
| 78 | type(rtcp_type), |
| 79 | packet(std::move(rtcp_packet)) {} |
| 80 | uint64_t timestamp; |
| 81 | RTCPPacketType type; |
| 82 | std::unique_ptr<rtcp::RtcpPacket> packet; |
terelius | 88e64e5 | 2016-07-19 01:51:06 -0700 | [diff] [blame] | 83 | }; |
| 84 | |
terelius | 8058e58 | 2016-07-25 01:32:41 -0700 | [diff] [blame] | 85 | struct BwePacketLossEvent { |
| 86 | uint64_t timestamp; |
| 87 | int32_t new_bitrate; |
| 88 | uint8_t fraction_loss; |
| 89 | int32_t expected_packets; |
| 90 | }; |
| 91 | |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 92 | const ParsedRtcEventLog& parsed_log_; |
| 93 | |
| 94 | // A list of SSRCs we are interested in analysing. |
| 95 | // If left empty, all SSRCs will be considered relevant. |
| 96 | std::vector<uint32_t> desired_ssrc_; |
| 97 | |
terelius | 88e64e5 | 2016-07-19 01:51:06 -0700 | [diff] [blame] | 98 | // Maps a stream identifier consisting of ssrc, direction and MediaType |
| 99 | // to the parsed RTP headers in that stream. Header extensions are parsed |
| 100 | // if the stream has been configured. |
| 101 | std::map<StreamId, std::vector<LoggedRtpPacket>> rtp_packets_; |
| 102 | |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 103 | std::map<StreamId, std::vector<LoggedRtcpPacket>> rtcp_packets_; |
| 104 | |
terelius | 8058e58 | 2016-07-25 01:32:41 -0700 | [diff] [blame] | 105 | // A list of all updates from the send-side loss-based bandwidth estimator. |
| 106 | std::vector<BwePacketLossEvent> bwe_loss_updates_; |
| 107 | |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 108 | // Window and step size used for calculating moving averages, e.g. bitrate. |
| 109 | // The generated data points will be |step_| microseconds apart. |
| 110 | // Only events occuring at most |window_duration_| microseconds before the |
| 111 | // current data point will be part of the average. |
| 112 | uint64_t window_duration_; |
| 113 | uint64_t step_; |
| 114 | |
| 115 | // First and last events of the log. |
| 116 | uint64_t begin_time_; |
| 117 | uint64_t end_time_; |
terelius | dc35dcd | 2016-08-01 12:03:27 -0700 | [diff] [blame^] | 118 | |
| 119 | // Duration (in seconds) of log file. |
| 120 | float call_duration_s_; |
terelius | 54ce680 | 2016-07-13 06:44:41 -0700 | [diff] [blame] | 121 | }; |
| 122 | |
| 123 | } // namespace plotting |
| 124 | } // namespace webrtc |
| 125 | |
| 126 | #endif // WEBRTC_TOOLS_EVENT_LOG_VISUALIZER_ANALYZER_H_ |