Bjorn Terelius | 3641185 | 2015-07-30 12:45:18 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2015 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 LOGGING_RTC_EVENT_LOG_RTC_EVENT_LOG_H_ |
| 12 | #define LOGGING_RTC_EVENT_LOG_RTC_EVENT_LOG_H_ |
Bjorn Terelius | 3641185 | 2015-07-30 12:45:18 +0200 | [diff] [blame] | 13 | |
kwiberg | b25345e | 2016-03-12 06:10:44 -0800 | [diff] [blame] | 14 | #include <memory> |
Bjorn Terelius | 3641185 | 2015-07-30 12:45:18 +0200 | [diff] [blame] | 15 | #include <string> |
perkj | 09e71da | 2017-05-22 03:26:49 -0700 | [diff] [blame] | 16 | #include <vector> |
Bjorn Terelius | 3641185 | 2015-07-30 12:45:18 +0200 | [diff] [blame] | 17 | |
eladalon | 4bb3b9c | 2017-09-11 07:25:26 -0700 | [diff] [blame] | 18 | // TODO(eladalon): Get rid of this later in the CL-stack. |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 19 | #include "api/rtpparameters.h" |
| 20 | #include "common_types.h" |
eladalon | 4bb3b9c | 2017-09-11 07:25:26 -0700 | [diff] [blame] | 21 | // TODO(eladalon): Get rid of this later in the CL-stack. |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 22 | #include "logging/rtc_event_log/rtc_stream_config.h" |
| 23 | #include "rtc_base/platform_file.h" |
Bjorn Terelius | 3641185 | 2015-07-30 12:45:18 +0200 | [diff] [blame] | 24 | |
| 25 | namespace webrtc { |
| 26 | |
Bjorn Terelius | 3641185 | 2015-07-30 12:45:18 +0200 | [diff] [blame] | 27 | namespace rtclog { |
eladalon | 4bb3b9c | 2017-09-11 07:25:26 -0700 | [diff] [blame] | 28 | class EventStream; // Storage class automatically generated from protobuf. |
Bjorn Terelius | 3641185 | 2015-07-30 12:45:18 +0200 | [diff] [blame] | 29 | } // namespace rtclog |
| 30 | |
terelius | 4311ba5 | 2016-04-22 12:40:37 -0700 | [diff] [blame] | 31 | class Clock; |
michaelt | cde46b7 | 2017-04-06 05:59:10 -0700 | [diff] [blame] | 32 | struct AudioEncoderRuntimeConfig; |
Bjorn Terelius | 3641185 | 2015-07-30 12:45:18 +0200 | [diff] [blame] | 33 | |
| 34 | enum class MediaType; |
michaelt | 9765370 | 2017-04-11 00:49:44 -0700 | [diff] [blame] | 35 | enum class BandwidthUsage; |
Bjorn Terelius | 3641185 | 2015-07-30 12:45:18 +0200 | [diff] [blame] | 36 | |
terelius | 429c345 | 2016-01-21 05:42:04 -0800 | [diff] [blame] | 37 | enum PacketDirection { kIncomingPacket = 0, kOutgoingPacket }; |
philipel | 32d0010 | 2017-02-27 02:18:46 -0800 | [diff] [blame] | 38 | enum ProbeFailureReason { |
| 39 | kInvalidSendReceiveInterval, |
| 40 | kInvalidSendReceiveRatio, |
| 41 | kTimeout |
| 42 | }; |
terelius | 429c345 | 2016-01-21 05:42:04 -0800 | [diff] [blame] | 43 | |
Bjorn Terelius | 3641185 | 2015-07-30 12:45:18 +0200 | [diff] [blame] | 44 | class RtcEventLog { |
| 45 | public: |
Bjorn Terelius | 3641185 | 2015-07-30 12:45:18 +0200 | [diff] [blame] | 46 | virtual ~RtcEventLog() {} |
| 47 | |
terelius | 4311ba5 | 2016-04-22 12:40:37 -0700 | [diff] [blame] | 48 | // Factory method to create an RtcEventLog object. |
nisse | 3061276 | 2016-12-20 05:03:58 -0800 | [diff] [blame] | 49 | static std::unique_ptr<RtcEventLog> Create(); |
| 50 | // TODO(nisse): webrtc::Clock is deprecated. Delete this method and |
| 51 | // above forward declaration of Clock when |
| 52 | // webrtc/system_wrappers/include/clock.h is deleted. |
| 53 | static std::unique_ptr<RtcEventLog> Create(const Clock* clock) { |
| 54 | return Create(); |
| 55 | } |
Bjorn Terelius | 3641185 | 2015-07-30 12:45:18 +0200 | [diff] [blame] | 56 | |
ivoc | 14d5dbe | 2016-07-04 07:06:55 -0700 | [diff] [blame] | 57 | // Create an RtcEventLog object that does nothing. |
| 58 | static std::unique_ptr<RtcEventLog> CreateNull(); |
| 59 | |
terelius | 4311ba5 | 2016-04-22 12:40:37 -0700 | [diff] [blame] | 60 | // Starts logging a maximum of max_size_bytes bytes to the specified file. |
Bjorn Terelius | 3641185 | 2015-07-30 12:45:18 +0200 | [diff] [blame] | 61 | // If the file already exists it will be overwritten. |
terelius | 4311ba5 | 2016-04-22 12:40:37 -0700 | [diff] [blame] | 62 | // If max_size_bytes <= 0, logging will be active until StopLogging is called. |
| 63 | // The function has no effect and returns false if we can't start a new log |
| 64 | // e.g. because we are already logging or the file cannot be opened. |
| 65 | virtual bool StartLogging(const std::string& file_name, |
| 66 | int64_t max_size_bytes) = 0; |
Bjorn Terelius | 3641185 | 2015-07-30 12:45:18 +0200 | [diff] [blame] | 67 | |
terelius | 4311ba5 | 2016-04-22 12:40:37 -0700 | [diff] [blame] | 68 | // Same as above. The RtcEventLog takes ownership of the file if the call |
| 69 | // is successful, i.e. if it returns true. |
| 70 | virtual bool StartLogging(rtc::PlatformFile platform_file, |
| 71 | int64_t max_size_bytes) = 0; |
ivoc | 112a3d8 | 2015-10-16 02:22:18 -0700 | [diff] [blame] | 72 | |
terelius | 4311ba5 | 2016-04-22 12:40:37 -0700 | [diff] [blame] | 73 | // Deprecated. Pass an explicit file size limit. |
eladalon | 248fd4f | 2017-09-06 05:18:15 -0700 | [diff] [blame] | 74 | RTC_DEPRECATED bool StartLogging(const std::string& file_name) { |
terelius | 4311ba5 | 2016-04-22 12:40:37 -0700 | [diff] [blame] | 75 | return StartLogging(file_name, 10000000); |
| 76 | } |
| 77 | |
| 78 | // Deprecated. Pass an explicit file size limit. |
eladalon | 248fd4f | 2017-09-06 05:18:15 -0700 | [diff] [blame] | 79 | RTC_DEPRECATED bool StartLogging(rtc::PlatformFile platform_file) { |
terelius | 4311ba5 | 2016-04-22 12:40:37 -0700 | [diff] [blame] | 80 | return StartLogging(platform_file, 10000000); |
| 81 | } |
| 82 | |
eladalon | 248fd4f | 2017-09-06 05:18:15 -0700 | [diff] [blame] | 83 | // Stops logging to file and waits until the file has been closed, after |
| 84 | // which it would be permissible to read and/or modify it. |
Bjorn Terelius | 3641185 | 2015-07-30 12:45:18 +0200 | [diff] [blame] | 85 | virtual void StopLogging() = 0; |
| 86 | |
perkj | c0876aa | 2017-05-22 04:08:28 -0700 | [diff] [blame] | 87 | // Logs configuration information for a video receive stream. |
Bjorn Terelius | 3641185 | 2015-07-30 12:45:18 +0200 | [diff] [blame] | 88 | virtual void LogVideoReceiveStreamConfig( |
perkj | 09e71da | 2017-05-22 03:26:49 -0700 | [diff] [blame] | 89 | const rtclog::StreamConfig& config) = 0; |
Bjorn Terelius | 3641185 | 2015-07-30 12:45:18 +0200 | [diff] [blame] | 90 | |
perkj | c0876aa | 2017-05-22 04:08:28 -0700 | [diff] [blame] | 91 | // Logs configuration information for a video send stream. |
| 92 | virtual void LogVideoSendStreamConfig(const rtclog::StreamConfig& config) = 0; |
Bjorn Terelius | 3641185 | 2015-07-30 12:45:18 +0200 | [diff] [blame] | 93 | |
perkj | ac8f52d | 2017-05-22 09:36:28 -0700 | [diff] [blame] | 94 | // Logs configuration information for an audio receive stream. |
ivoc | e0928d8 | 2016-10-10 05:12:51 -0700 | [diff] [blame] | 95 | virtual void LogAudioReceiveStreamConfig( |
perkj | ac8f52d | 2017-05-22 09:36:28 -0700 | [diff] [blame] | 96 | const rtclog::StreamConfig& config) = 0; |
ivoc | e0928d8 | 2016-10-10 05:12:51 -0700 | [diff] [blame] | 97 | |
perkj | f472699 | 2017-05-22 10:12:26 -0700 | [diff] [blame] | 98 | // Logs configuration information for an audio send stream. |
| 99 | virtual void LogAudioSendStreamConfig(const rtclog::StreamConfig& config) = 0; |
ivoc | e0928d8 | 2016-10-10 05:12:51 -0700 | [diff] [blame] | 100 | |
terelius | 2f9fd5d | 2015-09-04 03:39:42 -0700 | [diff] [blame] | 101 | // Logs the header of an incoming or outgoing RTP packet. packet_length |
| 102 | // is the total length of the packet, including both header and payload. |
terelius | 429c345 | 2016-01-21 05:42:04 -0800 | [diff] [blame] | 103 | virtual void LogRtpHeader(PacketDirection direction, |
Bjorn Terelius | 3641185 | 2015-07-30 12:45:18 +0200 | [diff] [blame] | 104 | const uint8_t* header, |
terelius | 2f9fd5d | 2015-09-04 03:39:42 -0700 | [diff] [blame] | 105 | size_t packet_length) = 0; |
Bjorn Terelius | 3641185 | 2015-07-30 12:45:18 +0200 | [diff] [blame] | 106 | |
philipel | 32d0010 | 2017-02-27 02:18:46 -0800 | [diff] [blame] | 107 | // Same as above but used on the sender side to log packets that are part of |
| 108 | // a probe cluster. |
| 109 | virtual void LogRtpHeader(PacketDirection direction, |
philipel | 32d0010 | 2017-02-27 02:18:46 -0800 | [diff] [blame] | 110 | const uint8_t* header, |
| 111 | size_t packet_length, |
| 112 | int probe_cluster_id) = 0; |
| 113 | |
Bjorn Terelius | 3641185 | 2015-07-30 12:45:18 +0200 | [diff] [blame] | 114 | // Logs an incoming or outgoing RTCP packet. |
terelius | 429c345 | 2016-01-21 05:42:04 -0800 | [diff] [blame] | 115 | virtual void LogRtcpPacket(PacketDirection direction, |
Bjorn Terelius | 3641185 | 2015-07-30 12:45:18 +0200 | [diff] [blame] | 116 | const uint8_t* packet, |
| 117 | size_t length) = 0; |
| 118 | |
terelius | 4311ba5 | 2016-04-22 12:40:37 -0700 | [diff] [blame] | 119 | // Logs an audio playout event. |
Ivo Creusen | ae856f2 | 2015-09-17 16:30:16 +0200 | [diff] [blame] | 120 | virtual void LogAudioPlayout(uint32_t ssrc) = 0; |
Bjorn Terelius | 3641185 | 2015-07-30 12:45:18 +0200 | [diff] [blame] | 121 | |
terelius | 006d93d | 2015-11-05 12:02:15 -0800 | [diff] [blame] | 122 | // Logs a bitrate update from the bandwidth estimator based on packet loss. |
terelius | 424e6cf | 2017-02-20 05:14:41 -0800 | [diff] [blame] | 123 | virtual void LogLossBasedBweUpdate(int32_t bitrate_bps, |
terelius | 006d93d | 2015-11-05 12:02:15 -0800 | [diff] [blame] | 124 | uint8_t fraction_loss, |
| 125 | int32_t total_packets) = 0; |
| 126 | |
terelius | 0baf55d | 2017-02-17 03:38:28 -0800 | [diff] [blame] | 127 | // Logs a bitrate update from the bandwidth estimator based on delay changes. |
terelius | 424e6cf | 2017-02-20 05:14:41 -0800 | [diff] [blame] | 128 | virtual void LogDelayBasedBweUpdate(int32_t bitrate_bps, |
terelius | 0baf55d | 2017-02-17 03:38:28 -0800 | [diff] [blame] | 129 | BandwidthUsage detector_state) = 0; |
| 130 | |
minyue | 4b7c952 | 2017-01-24 04:54:59 -0800 | [diff] [blame] | 131 | // Logs audio encoder re-configuration driven by audio network adaptor. |
| 132 | virtual void LogAudioNetworkAdaptation( |
michaelt | cde46b7 | 2017-04-06 05:59:10 -0700 | [diff] [blame] | 133 | const AudioEncoderRuntimeConfig& config) = 0; |
minyue | 4b7c952 | 2017-01-24 04:54:59 -0800 | [diff] [blame] | 134 | |
philipel | 32d0010 | 2017-02-27 02:18:46 -0800 | [diff] [blame] | 135 | // Logs when a probe cluster is created. |
| 136 | virtual void LogProbeClusterCreated(int id, |
| 137 | int bitrate_bps, |
| 138 | int min_probes, |
| 139 | int min_bytes) = 0; |
| 140 | |
| 141 | // Logs the result of a successful probing attempt. |
| 142 | virtual void LogProbeResultSuccess(int id, int bitrate_bps) = 0; |
| 143 | |
| 144 | // Logs the result of an unsuccessful probing attempt. |
| 145 | virtual void LogProbeResultFailure(int id, |
| 146 | ProbeFailureReason failure_reason) = 0; |
| 147 | |
Bjorn Terelius | 3641185 | 2015-07-30 12:45:18 +0200 | [diff] [blame] | 148 | // Reads an RtcEventLog file and returns true when reading was successful. |
| 149 | // The result is stored in the given EventStream object. |
terelius | 4311ba5 | 2016-04-22 12:40:37 -0700 | [diff] [blame] | 150 | // The order of the events in the EventStream is implementation defined. |
| 151 | // The current implementation writes a LOG_START event, then the old |
| 152 | // configurations, then the remaining events in timestamp order and finally |
| 153 | // a LOG_END event. However, this might change without further notice. |
| 154 | // TODO(terelius): Change result type to a vector? |
Bjorn Terelius | 3641185 | 2015-07-30 12:45:18 +0200 | [diff] [blame] | 155 | static bool ParseRtcEventLog(const std::string& file_name, |
| 156 | rtclog::EventStream* result); |
| 157 | }; |
| 158 | |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 159 | // No-op implementation is used if flag is not set, or in tests. |
perkj | 33bb86d | 2017-05-29 02:46:05 -0700 | [diff] [blame] | 160 | class RtcEventLogNullImpl : public RtcEventLog { |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 161 | public: |
| 162 | bool StartLogging(const std::string& file_name, |
| 163 | int64_t max_size_bytes) override { |
| 164 | return false; |
| 165 | } |
| 166 | bool StartLogging(rtc::PlatformFile platform_file, |
zhihuang | 38ede13 | 2017-06-15 12:52:32 -0700 | [diff] [blame] | 167 | int64_t max_size_bytes) override { |
| 168 | return false; |
| 169 | } |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 170 | void StopLogging() override {} |
| 171 | void LogVideoReceiveStreamConfig( |
perkj | 09e71da | 2017-05-22 03:26:49 -0700 | [diff] [blame] | 172 | const rtclog::StreamConfig& config) override {} |
perkj | c0876aa | 2017-05-22 04:08:28 -0700 | [diff] [blame] | 173 | void LogVideoSendStreamConfig(const rtclog::StreamConfig& config) override {} |
ivoc | e0928d8 | 2016-10-10 05:12:51 -0700 | [diff] [blame] | 174 | void LogAudioReceiveStreamConfig( |
perkj | ac8f52d | 2017-05-22 09:36:28 -0700 | [diff] [blame] | 175 | const rtclog::StreamConfig& config) override {} |
perkj | f472699 | 2017-05-22 10:12:26 -0700 | [diff] [blame] | 176 | void LogAudioSendStreamConfig(const rtclog::StreamConfig& config) override {} |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 177 | void LogRtpHeader(PacketDirection direction, |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 178 | const uint8_t* header, |
| 179 | size_t packet_length) override {} |
philipel | 32d0010 | 2017-02-27 02:18:46 -0800 | [diff] [blame] | 180 | void LogRtpHeader(PacketDirection direction, |
philipel | 32d0010 | 2017-02-27 02:18:46 -0800 | [diff] [blame] | 181 | const uint8_t* header, |
| 182 | size_t packet_length, |
| 183 | int probe_cluster_id) override {} |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 184 | void LogRtcpPacket(PacketDirection direction, |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 185 | const uint8_t* packet, |
| 186 | size_t length) override {} |
| 187 | void LogAudioPlayout(uint32_t ssrc) override {} |
terelius | 424e6cf | 2017-02-20 05:14:41 -0800 | [diff] [blame] | 188 | void LogLossBasedBweUpdate(int32_t bitrate_bps, |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 189 | uint8_t fraction_loss, |
| 190 | int32_t total_packets) override {} |
terelius | 424e6cf | 2017-02-20 05:14:41 -0800 | [diff] [blame] | 191 | void LogDelayBasedBweUpdate(int32_t bitrate_bps, |
terelius | 0baf55d | 2017-02-17 03:38:28 -0800 | [diff] [blame] | 192 | BandwidthUsage detector_state) override {} |
minyue | 4b7c952 | 2017-01-24 04:54:59 -0800 | [diff] [blame] | 193 | void LogAudioNetworkAdaptation( |
michaelt | cde46b7 | 2017-04-06 05:59:10 -0700 | [diff] [blame] | 194 | const AudioEncoderRuntimeConfig& config) override {} |
philipel | 32d0010 | 2017-02-27 02:18:46 -0800 | [diff] [blame] | 195 | void LogProbeClusterCreated(int id, |
| 196 | int bitrate_bps, |
| 197 | int min_probes, |
| 198 | int min_bytes) override{}; |
| 199 | void LogProbeResultSuccess(int id, int bitrate_bps) override{}; |
| 200 | void LogProbeResultFailure(int id, |
| 201 | ProbeFailureReason failure_reason) override{}; |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 202 | }; |
| 203 | |
Bjorn Terelius | 3641185 | 2015-07-30 12:45:18 +0200 | [diff] [blame] | 204 | } // namespace webrtc |
| 205 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 206 | #endif // LOGGING_RTC_EVENT_LOG_RTC_EVENT_LOG_H_ |