blob: 88ba10e5cc1878bf29192ac9e8c1a5f3d947f992 [file] [log] [blame]
Bjorn Terelius36411852015-07-30 12:45:18 +02001/*
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 Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef LOGGING_RTC_EVENT_LOG_RTC_EVENT_LOG_H_
12#define LOGGING_RTC_EVENT_LOG_RTC_EVENT_LOG_H_
Bjorn Terelius36411852015-07-30 12:45:18 +020013
kwibergb25345e2016-03-12 06:10:44 -080014#include <memory>
Bjorn Terelius36411852015-07-30 12:45:18 +020015#include <string>
16
Bjorn Terelius440216f2017-09-29 21:01:42 +020017#include "api/array_view.h"
eladalon4bb3b9c2017-09-11 07:25:26 -070018// TODO(eladalon): Get rid of this later in the CL-stack.
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020019#include "api/rtpparameters.h"
Mirko Bonadei71207422017-09-15 13:58:09 +020020#include "common_types.h" // NOLINT(build/include)
Elad Alon078a7812017-10-02 13:33:31 +020021// TODO(eladalon): This is here because of ProbeFailureReason; remove this
22// dependency along with the deprecated LogProbeResultFailure().
23#include "logging/rtc_event_log/events/rtc_event_probe_result_failure.h"
Elad Alon4a87e1c2017-10-03 16:11:34 +020024// TODO(eladalon): Remove this in an upcoming CL, that will modularize the
25// log output into its own class.
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020026#include "rtc_base/platform_file.h"
Bjorn Terelius36411852015-07-30 12:45:18 +020027
28namespace webrtc {
29
Bjorn Terelius36411852015-07-30 12:45:18 +020030namespace rtclog {
eladalon4bb3b9c2017-09-11 07:25:26 -070031class EventStream; // Storage class automatically generated from protobuf.
Elad Alon99a81b62017-09-21 10:25:29 +020032// TODO(eladalon): Get rid of this when deprecated methods are removed.
33struct StreamConfig;
Bjorn Terelius36411852015-07-30 12:45:18 +020034} // namespace rtclog
35
terelius4311ba52016-04-22 12:40:37 -070036class Clock;
Elad Alon4a87e1c2017-10-03 16:11:34 +020037// TODO(eladalon): The following may be removed when the deprecated methods
38// are removed.
michaeltcde46b72017-04-06 05:59:10 -070039struct AudioEncoderRuntimeConfig;
Bjorn Terelius440216f2017-09-29 21:01:42 +020040class RtpPacketReceived;
41class RtpPacketToSend;
michaelt97653702017-04-11 00:49:44 -070042enum class BandwidthUsage;
terelius429c3452016-01-21 05:42:04 -080043enum PacketDirection { kIncomingPacket = 0, kOutgoingPacket };
44
Bjorn Terelius36411852015-07-30 12:45:18 +020045class RtcEventLog {
46 public:
Elad Alon4a87e1c2017-10-03 16:11:34 +020047 // TODO(eladalon): Two stages are upcoming.
48 // 1. Extend this to actually support the new encoding.
49 // 2. Get rid of the legacy encoding, allowing us to get rid of this enum.
50 enum class EncodingType { Legacy };
51
Bjorn Terelius36411852015-07-30 12:45:18 +020052 virtual ~RtcEventLog() {}
53
terelius4311ba52016-04-22 12:40:37 -070054 // Factory method to create an RtcEventLog object.
Elad Alon4a87e1c2017-10-03 16:11:34 +020055 // TODO(eladalon): Get rid of the default value after internal projects fixed.
56 static std::unique_ptr<RtcEventLog> Create(
57 EncodingType encoding_type = EncodingType::Legacy);
nisse30612762016-12-20 05:03:58 -080058 // TODO(nisse): webrtc::Clock is deprecated. Delete this method and
59 // above forward declaration of Clock when
Elad Alon4a87e1c2017-10-03 16:11:34 +020060 // webrtc/system_wrappers/include/clock.h is deleted.
61 // TODO(eladalon): Get rid of the default value after internal projects fixed.
62 static std::unique_ptr<RtcEventLog> Create(
63 const Clock* clock,
64 EncodingType encoding_type = EncodingType::Legacy) {
65 return Create(encoding_type);
nisse30612762016-12-20 05:03:58 -080066 }
Bjorn Terelius36411852015-07-30 12:45:18 +020067
ivoc14d5dbe2016-07-04 07:06:55 -070068 // Create an RtcEventLog object that does nothing.
69 static std::unique_ptr<RtcEventLog> CreateNull();
70
terelius4311ba52016-04-22 12:40:37 -070071 // Starts logging a maximum of max_size_bytes bytes to the specified file.
Bjorn Terelius36411852015-07-30 12:45:18 +020072 // If the file already exists it will be overwritten.
terelius4311ba52016-04-22 12:40:37 -070073 // If max_size_bytes <= 0, logging will be active until StopLogging is called.
74 // The function has no effect and returns false if we can't start a new log
75 // e.g. because we are already logging or the file cannot be opened.
76 virtual bool StartLogging(const std::string& file_name,
77 int64_t max_size_bytes) = 0;
Bjorn Terelius36411852015-07-30 12:45:18 +020078
terelius4311ba52016-04-22 12:40:37 -070079 // Same as above. The RtcEventLog takes ownership of the file if the call
80 // is successful, i.e. if it returns true.
81 virtual bool StartLogging(rtc::PlatformFile platform_file,
82 int64_t max_size_bytes) = 0;
ivoc112a3d82015-10-16 02:22:18 -070083
terelius4311ba52016-04-22 12:40:37 -070084 // Deprecated. Pass an explicit file size limit.
eladalon248fd4f2017-09-06 05:18:15 -070085 RTC_DEPRECATED bool StartLogging(const std::string& file_name) {
terelius4311ba52016-04-22 12:40:37 -070086 return StartLogging(file_name, 10000000);
87 }
88
89 // Deprecated. Pass an explicit file size limit.
eladalon248fd4f2017-09-06 05:18:15 -070090 RTC_DEPRECATED bool StartLogging(rtc::PlatformFile platform_file) {
terelius4311ba52016-04-22 12:40:37 -070091 return StartLogging(platform_file, 10000000);
92 }
93
eladalon248fd4f2017-09-06 05:18:15 -070094 // Stops logging to file and waits until the file has been closed, after
95 // which it would be permissible to read and/or modify it.
Bjorn Terelius36411852015-07-30 12:45:18 +020096 virtual void StopLogging() = 0;
97
Elad Alon4a87e1c2017-10-03 16:11:34 +020098 // Log an RTC event (the type of event is determined by the subclass).
99 virtual void Log(std::unique_ptr<RtcEvent> event) = 0;
100
perkjc0876aa2017-05-22 04:08:28 -0700101 // Logs configuration information for a video receive stream.
Elad Alon4a87e1c2017-10-03 16:11:34 +0200102 RTC_DEPRECATED virtual void LogVideoReceiveStreamConfig(
perkj09e71da2017-05-22 03:26:49 -0700103 const rtclog::StreamConfig& config) = 0;
Bjorn Terelius36411852015-07-30 12:45:18 +0200104
perkjc0876aa2017-05-22 04:08:28 -0700105 // Logs configuration information for a video send stream.
Elad Alon4a87e1c2017-10-03 16:11:34 +0200106 RTC_DEPRECATED virtual void LogVideoSendStreamConfig(
107 const rtclog::StreamConfig& config) = 0;
Bjorn Terelius36411852015-07-30 12:45:18 +0200108
perkjac8f52d2017-05-22 09:36:28 -0700109 // Logs configuration information for an audio receive stream.
Elad Alon4a87e1c2017-10-03 16:11:34 +0200110 RTC_DEPRECATED virtual void LogAudioReceiveStreamConfig(
perkjac8f52d2017-05-22 09:36:28 -0700111 const rtclog::StreamConfig& config) = 0;
ivoce0928d82016-10-10 05:12:51 -0700112
perkjf4726992017-05-22 10:12:26 -0700113 // Logs configuration information for an audio send stream.
Elad Alon4a87e1c2017-10-03 16:11:34 +0200114 RTC_DEPRECATED virtual void LogAudioSendStreamConfig(
115 const rtclog::StreamConfig& config) = 0;
ivoce0928d82016-10-10 05:12:51 -0700116
Bjorn Terelius440216f2017-09-29 21:01:42 +0200117 RTC_DEPRECATED virtual void LogRtpHeader(PacketDirection direction,
118 const uint8_t* header,
119 size_t packet_length) {}
120
121 RTC_DEPRECATED virtual void LogRtpHeader(PacketDirection direction,
122 const uint8_t* header,
123 size_t packet_length,
124 int probe_cluster_id) {}
125
126 // Logs the header of an incoming RTP packet. |packet_length|
terelius2f9fd5d2015-09-04 03:39:42 -0700127 // is the total length of the packet, including both header and payload.
Elad Alon4a87e1c2017-10-03 16:11:34 +0200128 RTC_DEPRECATED virtual void LogIncomingRtpHeader(
129 const RtpPacketReceived& packet) = 0;
Bjorn Terelius36411852015-07-30 12:45:18 +0200130
Bjorn Terelius440216f2017-09-29 21:01:42 +0200131 // Logs the header of an incoming RTP packet. |packet_length|
132 // is the total length of the packet, including both header and payload.
Elad Alon4a87e1c2017-10-03 16:11:34 +0200133 RTC_DEPRECATED virtual void LogOutgoingRtpHeader(
134 const RtpPacketToSend& packet,
135 int probe_cluster_id) = 0;
philipel32d00102017-02-27 02:18:46 -0800136
Bjorn Terelius440216f2017-09-29 21:01:42 +0200137 RTC_DEPRECATED virtual void LogRtcpPacket(PacketDirection direction,
138 const uint8_t* header,
139 size_t packet_length) {}
140
141 // Logs an incoming RTCP packet.
Elad Alon4a87e1c2017-10-03 16:11:34 +0200142 RTC_DEPRECATED virtual void LogIncomingRtcpPacket(
143 rtc::ArrayView<const uint8_t> packet) = 0;
Bjorn Terelius440216f2017-09-29 21:01:42 +0200144
145 // Logs an outgoing RTCP packet.
Elad Alon4a87e1c2017-10-03 16:11:34 +0200146 RTC_DEPRECATED virtual void LogOutgoingRtcpPacket(
147 rtc::ArrayView<const uint8_t> packet) = 0;
Bjorn Terelius36411852015-07-30 12:45:18 +0200148
terelius4311ba52016-04-22 12:40:37 -0700149 // Logs an audio playout event.
Elad Alon4a87e1c2017-10-03 16:11:34 +0200150 RTC_DEPRECATED virtual void LogAudioPlayout(uint32_t ssrc) = 0;
Bjorn Terelius36411852015-07-30 12:45:18 +0200151
terelius006d93d2015-11-05 12:02:15 -0800152 // Logs a bitrate update from the bandwidth estimator based on packet loss.
Elad Alon4a87e1c2017-10-03 16:11:34 +0200153 RTC_DEPRECATED virtual void LogLossBasedBweUpdate(int32_t bitrate_bps,
154 uint8_t fraction_loss,
155 int32_t total_packets) = 0;
terelius006d93d2015-11-05 12:02:15 -0800156
terelius0baf55d2017-02-17 03:38:28 -0800157 // Logs a bitrate update from the bandwidth estimator based on delay changes.
Elad Alon4a87e1c2017-10-03 16:11:34 +0200158 RTC_DEPRECATED virtual void LogDelayBasedBweUpdate(
159 int32_t bitrate_bps,
160 BandwidthUsage detector_state) = 0;
terelius0baf55d2017-02-17 03:38:28 -0800161
minyue4b7c9522017-01-24 04:54:59 -0800162 // Logs audio encoder re-configuration driven by audio network adaptor.
Elad Alon4a87e1c2017-10-03 16:11:34 +0200163 RTC_DEPRECATED virtual void LogAudioNetworkAdaptation(
michaeltcde46b72017-04-06 05:59:10 -0700164 const AudioEncoderRuntimeConfig& config) = 0;
minyue4b7c9522017-01-24 04:54:59 -0800165
philipel32d00102017-02-27 02:18:46 -0800166 // Logs when a probe cluster is created.
Elad Alon4a87e1c2017-10-03 16:11:34 +0200167 RTC_DEPRECATED virtual void LogProbeClusterCreated(int id,
168 int bitrate_bps,
169 int min_probes,
170 int min_bytes) = 0;
philipel32d00102017-02-27 02:18:46 -0800171
172 // Logs the result of a successful probing attempt.
Elad Alon4a87e1c2017-10-03 16:11:34 +0200173 RTC_DEPRECATED virtual void LogProbeResultSuccess(int id,
174 int bitrate_bps) = 0;
philipel32d00102017-02-27 02:18:46 -0800175
176 // Logs the result of an unsuccessful probing attempt.
Elad Alon4a87e1c2017-10-03 16:11:34 +0200177 RTC_DEPRECATED virtual void LogProbeResultFailure(
178 int id,
179 ProbeFailureReason failure_reason) = 0;
Bjorn Terelius36411852015-07-30 12:45:18 +0200180};
181
Stefan Holmer13181032016-07-29 14:48:54 +0200182// No-op implementation is used if flag is not set, or in tests.
perkj33bb86d2017-05-29 02:46:05 -0700183class RtcEventLogNullImpl : public RtcEventLog {
Stefan Holmer13181032016-07-29 14:48:54 +0200184 public:
185 bool StartLogging(const std::string& file_name,
186 int64_t max_size_bytes) override {
187 return false;
188 }
189 bool StartLogging(rtc::PlatformFile platform_file,
zhihuang38ede132017-06-15 12:52:32 -0700190 int64_t max_size_bytes) override {
191 return false;
192 }
Stefan Holmer13181032016-07-29 14:48:54 +0200193 void StopLogging() override {}
Elad Alon4a87e1c2017-10-03 16:11:34 +0200194 void Log(std::unique_ptr<RtcEvent> event) override {}
Stefan Holmer13181032016-07-29 14:48:54 +0200195 void LogVideoReceiveStreamConfig(
perkj09e71da2017-05-22 03:26:49 -0700196 const rtclog::StreamConfig& config) override {}
perkjc0876aa2017-05-22 04:08:28 -0700197 void LogVideoSendStreamConfig(const rtclog::StreamConfig& config) override {}
ivoce0928d82016-10-10 05:12:51 -0700198 void LogAudioReceiveStreamConfig(
perkjac8f52d2017-05-22 09:36:28 -0700199 const rtclog::StreamConfig& config) override {}
perkjf4726992017-05-22 10:12:26 -0700200 void LogAudioSendStreamConfig(const rtclog::StreamConfig& config) override {}
Bjorn Terelius440216f2017-09-29 21:01:42 +0200201 void LogIncomingRtpHeader(const RtpPacketReceived& packet) override {}
202 void LogOutgoingRtpHeader(const RtpPacketToSend& packet,
203 int probe_cluster_id) override {}
204 void LogIncomingRtcpPacket(rtc::ArrayView<const uint8_t> packet) override {}
205 void LogOutgoingRtcpPacket(rtc::ArrayView<const uint8_t> packet) override {}
Stefan Holmer13181032016-07-29 14:48:54 +0200206 void LogAudioPlayout(uint32_t ssrc) override {}
terelius424e6cf2017-02-20 05:14:41 -0800207 void LogLossBasedBweUpdate(int32_t bitrate_bps,
Stefan Holmer13181032016-07-29 14:48:54 +0200208 uint8_t fraction_loss,
209 int32_t total_packets) override {}
terelius424e6cf2017-02-20 05:14:41 -0800210 void LogDelayBasedBweUpdate(int32_t bitrate_bps,
terelius0baf55d2017-02-17 03:38:28 -0800211 BandwidthUsage detector_state) override {}
minyue4b7c9522017-01-24 04:54:59 -0800212 void LogAudioNetworkAdaptation(
michaeltcde46b72017-04-06 05:59:10 -0700213 const AudioEncoderRuntimeConfig& config) override {}
philipel32d00102017-02-27 02:18:46 -0800214 void LogProbeClusterCreated(int id,
215 int bitrate_bps,
216 int min_probes,
217 int min_bytes) override{};
218 void LogProbeResultSuccess(int id, int bitrate_bps) override{};
219 void LogProbeResultFailure(int id,
220 ProbeFailureReason failure_reason) override{};
Stefan Holmer13181032016-07-29 14:48:54 +0200221};
222
Bjorn Terelius36411852015-07-30 12:45:18 +0200223} // namespace webrtc
224
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200225#endif // LOGGING_RTC_EVENT_LOG_RTC_EVENT_LOG_H_