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> |
| 16 | |
Danil Chapovalov | d312a91 | 2017-10-05 12:25:18 +0000 | [diff] [blame] | 17 | // TODO(eladalon): Remove this include once LogIncomingRtcpPacket(), etc., have |
| 18 | // been removed (they are currently deprecated). |
| 19 | #include "api/array_view.h" |
| 20 | #include "common_types.h" // NOLINT(build/include) |
Elad Alon | 83ccca1 | 2017-10-04 13:18:26 +0200 | [diff] [blame] | 21 | #include "logging/rtc_event_log/output/rtc_event_log_output.h" |
Danil Chapovalov | d312a91 | 2017-10-05 12:25:18 +0000 | [diff] [blame] | 22 | // TODO(eladalon): This is here because of ProbeFailureReason; remove this |
| 23 | // dependency along with the deprecated LogProbeResultFailure(). |
| 24 | #include "logging/rtc_event_log/events/rtc_event_probe_result_failure.h" |
| 25 | // TODO(eladalon): Remove this #include once the deprecated versions of |
| 26 | // StartLogging() have been removed. |
| 27 | #include "rtc_base/platform_file.h" |
Bjorn Terelius | 3641185 | 2015-07-30 12:45:18 +0200 | [diff] [blame] | 28 | |
| 29 | namespace webrtc { |
| 30 | |
Danil Chapovalov | d312a91 | 2017-10-05 12:25:18 +0000 | [diff] [blame] | 31 | namespace rtclog { |
| 32 | class EventStream; // Storage class automatically generated from protobuf. |
| 33 | // TODO(eladalon): Get rid of this when deprecated methods are removed. |
| 34 | struct StreamConfig; |
| 35 | } // namespace rtclog |
Elad Alon | 5fd6e5e | 2017-10-05 10:19:29 +0200 | [diff] [blame] | 36 | |
Danil Chapovalov | d312a91 | 2017-10-05 12:25:18 +0000 | [diff] [blame] | 37 | class Clock; |
| 38 | // TODO(eladalon): The following may be removed when the deprecated methods |
| 39 | // are removed. |
| 40 | struct AudioEncoderRuntimeConfig; |
| 41 | class RtpPacketReceived; |
| 42 | class RtpPacketToSend; |
| 43 | enum class BandwidthUsage; |
terelius | 429c345 | 2016-01-21 05:42:04 -0800 | [diff] [blame] | 44 | enum PacketDirection { kIncomingPacket = 0, kOutgoingPacket }; |
| 45 | |
Bjorn Terelius | 3641185 | 2015-07-30 12:45:18 +0200 | [diff] [blame] | 46 | class RtcEventLog { |
| 47 | public: |
Elad Alon | 83ccca1 | 2017-10-04 13:18:26 +0200 | [diff] [blame] | 48 | enum : size_t { kUnlimitedOutput = 0 }; |
| 49 | |
Elad Alon | 4a87e1c | 2017-10-03 16:11:34 +0200 | [diff] [blame] | 50 | // TODO(eladalon): Two stages are upcoming. |
| 51 | // 1. Extend this to actually support the new encoding. |
| 52 | // 2. Get rid of the legacy encoding, allowing us to get rid of this enum. |
| 53 | enum class EncodingType { Legacy }; |
| 54 | |
Bjorn Terelius | 3641185 | 2015-07-30 12:45:18 +0200 | [diff] [blame] | 55 | virtual ~RtcEventLog() {} |
| 56 | |
terelius | 4311ba5 | 2016-04-22 12:40:37 -0700 | [diff] [blame] | 57 | // Factory method to create an RtcEventLog object. |
Danil Chapovalov | d312a91 | 2017-10-05 12:25:18 +0000 | [diff] [blame] | 58 | // TODO(eladalon): Get rid of the default value after internal projects fixed. |
| 59 | static std::unique_ptr<RtcEventLog> Create( |
| 60 | EncodingType encoding_type = EncodingType::Legacy); |
nisse | 3061276 | 2016-12-20 05:03:58 -0800 | [diff] [blame] | 61 | // TODO(nisse): webrtc::Clock is deprecated. Delete this method and |
| 62 | // above forward declaration of Clock when |
Elad Alon | 4a87e1c | 2017-10-03 16:11:34 +0200 | [diff] [blame] | 63 | // webrtc/system_wrappers/include/clock.h is deleted. |
Danil Chapovalov | d312a91 | 2017-10-05 12:25:18 +0000 | [diff] [blame] | 64 | // TODO(eladalon): Get rid of the default value after internal projects fixed. |
| 65 | static std::unique_ptr<RtcEventLog> Create( |
| 66 | const Clock* clock, |
| 67 | EncodingType encoding_type = EncodingType::Legacy) { |
Elad Alon | 4a87e1c | 2017-10-03 16:11:34 +0200 | [diff] [blame] | 68 | return Create(encoding_type); |
nisse | 3061276 | 2016-12-20 05:03:58 -0800 | [diff] [blame] | 69 | } |
Bjorn Terelius | 3641185 | 2015-07-30 12:45:18 +0200 | [diff] [blame] | 70 | |
ivoc | 14d5dbe | 2016-07-04 07:06:55 -0700 | [diff] [blame] | 71 | // Create an RtcEventLog object that does nothing. |
| 72 | static std::unique_ptr<RtcEventLog> CreateNull(); |
| 73 | |
Elad Alon | 83ccca1 | 2017-10-04 13:18:26 +0200 | [diff] [blame] | 74 | // Starts logging to a given output. The output might be limited in size, |
| 75 | // and may close itself once it has reached the maximum size. |
| 76 | virtual bool StartLogging(std::unique_ptr<RtcEventLogOutput> output) = 0; |
| 77 | |
Danil Chapovalov | d312a91 | 2017-10-05 12:25:18 +0000 | [diff] [blame] | 78 | // Starts logging a maximum of max_size_bytes bytes to the specified file. |
| 79 | // If the file already exists it will be overwritten. |
| 80 | // If max_size_bytes <= 0, logging will be active until StopLogging is called. |
| 81 | // The function has no effect and returns false if we can't start a new log |
| 82 | // e.g. because we are already logging or the file cannot be opened. |
| 83 | RTC_DEPRECATED virtual bool StartLogging(const std::string& file_name, |
| 84 | int64_t max_size_bytes) = 0; |
| 85 | |
| 86 | // Same as above. The RtcEventLog takes ownership of the file if the call |
| 87 | // is successful, i.e. if it returns true. |
| 88 | RTC_DEPRECATED virtual bool StartLogging(rtc::PlatformFile platform_file, |
| 89 | int64_t max_size_bytes) = 0; |
| 90 | |
| 91 | // Deprecated. Pass an explicit file size limit. |
| 92 | RTC_DEPRECATED bool StartLogging(const std::string& file_name) { |
| 93 | return StartLogging(file_name, 10000000); |
| 94 | } |
| 95 | |
| 96 | // Deprecated. Pass an explicit file size limit. |
| 97 | RTC_DEPRECATED bool StartLogging(rtc::PlatformFile platform_file) { |
| 98 | return StartLogging(platform_file, 10000000); |
| 99 | } |
| 100 | |
eladalon | 248fd4f | 2017-09-06 05:18:15 -0700 | [diff] [blame] | 101 | // Stops logging to file and waits until the file has been closed, after |
| 102 | // which it would be permissible to read and/or modify it. |
Bjorn Terelius | 3641185 | 2015-07-30 12:45:18 +0200 | [diff] [blame] | 103 | virtual void StopLogging() = 0; |
| 104 | |
Elad Alon | 4a87e1c | 2017-10-03 16:11:34 +0200 | [diff] [blame] | 105 | // Log an RTC event (the type of event is determined by the subclass). |
| 106 | virtual void Log(std::unique_ptr<RtcEvent> event) = 0; |
Danil Chapovalov | d312a91 | 2017-10-05 12:25:18 +0000 | [diff] [blame] | 107 | |
| 108 | // Logs configuration information for a video receive stream. |
| 109 | RTC_DEPRECATED virtual void LogVideoReceiveStreamConfig( |
| 110 | const rtclog::StreamConfig& config) = 0; |
| 111 | |
| 112 | // Logs configuration information for a video send stream. |
| 113 | RTC_DEPRECATED virtual void LogVideoSendStreamConfig( |
| 114 | const rtclog::StreamConfig& config) = 0; |
| 115 | |
| 116 | // Logs configuration information for an audio receive stream. |
| 117 | RTC_DEPRECATED virtual void LogAudioReceiveStreamConfig( |
| 118 | const rtclog::StreamConfig& config) = 0; |
| 119 | |
| 120 | // Logs configuration information for an audio send stream. |
| 121 | RTC_DEPRECATED virtual void LogAudioSendStreamConfig( |
| 122 | const rtclog::StreamConfig& config) = 0; |
| 123 | |
| 124 | RTC_DEPRECATED virtual void LogRtpHeader(PacketDirection direction, |
| 125 | const uint8_t* header, |
| 126 | size_t packet_length) {} |
| 127 | |
| 128 | RTC_DEPRECATED virtual void LogRtpHeader(PacketDirection direction, |
| 129 | const uint8_t* header, |
| 130 | size_t packet_length, |
| 131 | int probe_cluster_id) {} |
| 132 | |
| 133 | // Logs the header of an incoming RTP packet. |packet_length| |
| 134 | // is the total length of the packet, including both header and payload. |
| 135 | RTC_DEPRECATED virtual void LogIncomingRtpHeader( |
| 136 | const RtpPacketReceived& packet) = 0; |
| 137 | |
| 138 | // Logs the header of an incoming RTP packet. |packet_length| |
| 139 | // is the total length of the packet, including both header and payload. |
| 140 | RTC_DEPRECATED virtual void LogOutgoingRtpHeader( |
| 141 | const RtpPacketToSend& packet, |
| 142 | int probe_cluster_id) = 0; |
| 143 | |
| 144 | RTC_DEPRECATED virtual void LogRtcpPacket(PacketDirection direction, |
| 145 | const uint8_t* header, |
| 146 | size_t packet_length) {} |
| 147 | |
| 148 | // Logs an incoming RTCP packet. |
| 149 | RTC_DEPRECATED virtual void LogIncomingRtcpPacket( |
| 150 | rtc::ArrayView<const uint8_t> packet) = 0; |
| 151 | |
| 152 | // Logs an outgoing RTCP packet. |
| 153 | RTC_DEPRECATED virtual void LogOutgoingRtcpPacket( |
| 154 | rtc::ArrayView<const uint8_t> packet) = 0; |
| 155 | |
| 156 | // Logs an audio playout event. |
| 157 | RTC_DEPRECATED virtual void LogAudioPlayout(uint32_t ssrc) = 0; |
| 158 | |
| 159 | // Logs a bitrate update from the bandwidth estimator based on packet loss. |
| 160 | RTC_DEPRECATED virtual void LogLossBasedBweUpdate(int32_t bitrate_bps, |
| 161 | uint8_t fraction_loss, |
| 162 | int32_t total_packets) = 0; |
| 163 | |
| 164 | // Logs a bitrate update from the bandwidth estimator based on delay changes. |
| 165 | RTC_DEPRECATED virtual void LogDelayBasedBweUpdate( |
| 166 | int32_t bitrate_bps, |
| 167 | BandwidthUsage detector_state) = 0; |
| 168 | |
| 169 | // Logs audio encoder re-configuration driven by audio network adaptor. |
| 170 | RTC_DEPRECATED virtual void LogAudioNetworkAdaptation( |
| 171 | const AudioEncoderRuntimeConfig& config) = 0; |
| 172 | |
| 173 | // Logs when a probe cluster is created. |
| 174 | RTC_DEPRECATED virtual void LogProbeClusterCreated(int id, |
| 175 | int bitrate_bps, |
| 176 | int min_probes, |
| 177 | int min_bytes) = 0; |
| 178 | |
| 179 | // Logs the result of a successful probing attempt. |
| 180 | RTC_DEPRECATED virtual void LogProbeResultSuccess(int id, |
| 181 | int bitrate_bps) = 0; |
| 182 | |
| 183 | // Logs the result of an unsuccessful probing attempt. |
| 184 | RTC_DEPRECATED virtual void LogProbeResultFailure( |
| 185 | int id, |
| 186 | ProbeFailureReason failure_reason) = 0; |
Bjorn Terelius | 3641185 | 2015-07-30 12:45:18 +0200 | [diff] [blame] | 187 | }; |
| 188 | |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 189 | // No-op implementation is used if flag is not set, or in tests. |
perkj | 33bb86d | 2017-05-29 02:46:05 -0700 | [diff] [blame] | 190 | class RtcEventLogNullImpl : public RtcEventLog { |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 191 | public: |
Elad Alon | 83ccca1 | 2017-10-04 13:18:26 +0200 | [diff] [blame] | 192 | bool StartLogging(std::unique_ptr<RtcEventLogOutput> output) override { |
| 193 | return false; |
| 194 | } |
Danil Chapovalov | d312a91 | 2017-10-05 12:25:18 +0000 | [diff] [blame] | 195 | bool StartLogging(const std::string& file_name, |
| 196 | int64_t max_size_bytes) override { |
| 197 | return false; |
| 198 | } |
| 199 | bool StartLogging(rtc::PlatformFile platform_file, |
| 200 | int64_t max_size_bytes) override { |
| 201 | return false; |
| 202 | } |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 203 | void StopLogging() override {} |
Elad Alon | 4a87e1c | 2017-10-03 16:11:34 +0200 | [diff] [blame] | 204 | void Log(std::unique_ptr<RtcEvent> event) override {} |
Danil Chapovalov | d312a91 | 2017-10-05 12:25:18 +0000 | [diff] [blame] | 205 | void LogVideoReceiveStreamConfig( |
| 206 | const rtclog::StreamConfig& config) override {} |
| 207 | void LogVideoSendStreamConfig(const rtclog::StreamConfig& config) override {} |
| 208 | void LogAudioReceiveStreamConfig( |
| 209 | const rtclog::StreamConfig& config) override {} |
| 210 | void LogAudioSendStreamConfig(const rtclog::StreamConfig& config) override {} |
| 211 | void LogIncomingRtpHeader(const RtpPacketReceived& packet) override {} |
| 212 | void LogOutgoingRtpHeader(const RtpPacketToSend& packet, |
| 213 | int probe_cluster_id) override {} |
| 214 | void LogIncomingRtcpPacket(rtc::ArrayView<const uint8_t> packet) override {} |
| 215 | void LogOutgoingRtcpPacket(rtc::ArrayView<const uint8_t> packet) override {} |
| 216 | void LogAudioPlayout(uint32_t ssrc) override {} |
| 217 | void LogLossBasedBweUpdate(int32_t bitrate_bps, |
| 218 | uint8_t fraction_loss, |
| 219 | int32_t total_packets) override {} |
| 220 | void LogDelayBasedBweUpdate(int32_t bitrate_bps, |
| 221 | BandwidthUsage detector_state) override {} |
| 222 | void LogAudioNetworkAdaptation( |
| 223 | const AudioEncoderRuntimeConfig& config) override {} |
| 224 | void LogProbeClusterCreated(int id, |
| 225 | int bitrate_bps, |
| 226 | int min_probes, |
| 227 | int min_bytes) override{}; |
| 228 | void LogProbeResultSuccess(int id, int bitrate_bps) override{}; |
| 229 | void LogProbeResultFailure(int id, |
| 230 | ProbeFailureReason failure_reason) override{}; |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 231 | }; |
| 232 | |
Bjorn Terelius | 3641185 | 2015-07-30 12:45:18 +0200 | [diff] [blame] | 233 | } // namespace webrtc |
| 234 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 235 | #endif // LOGGING_RTC_EVENT_LOG_RTC_EVENT_LOG_H_ |