blob: cb9d097888e092b4856a48ab774bd6aa0c497fb0 [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
Danil Chapovalovd312a912017-10-05 12:25:18 +000017// 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 Alon83ccca12017-10-04 13:18:26 +020021#include "logging/rtc_event_log/output/rtc_event_log_output.h"
Danil Chapovalovd312a912017-10-05 12:25:18 +000022// 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 Terelius36411852015-07-30 12:45:18 +020028
29namespace webrtc {
30
Danil Chapovalovd312a912017-10-05 12:25:18 +000031namespace rtclog {
32class EventStream; // Storage class automatically generated from protobuf.
33// TODO(eladalon): Get rid of this when deprecated methods are removed.
34struct StreamConfig;
35} // namespace rtclog
Elad Alon5fd6e5e2017-10-05 10:19:29 +020036
Danil Chapovalovd312a912017-10-05 12:25:18 +000037class Clock;
38// TODO(eladalon): The following may be removed when the deprecated methods
39// are removed.
40struct AudioEncoderRuntimeConfig;
41class RtpPacketReceived;
42class RtpPacketToSend;
43enum class BandwidthUsage;
terelius429c3452016-01-21 05:42:04 -080044enum PacketDirection { kIncomingPacket = 0, kOutgoingPacket };
45
Bjorn Terelius36411852015-07-30 12:45:18 +020046class RtcEventLog {
47 public:
Elad Alon83ccca12017-10-04 13:18:26 +020048 enum : size_t { kUnlimitedOutput = 0 };
49
Elad Alon4a87e1c2017-10-03 16:11:34 +020050 // 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 Terelius36411852015-07-30 12:45:18 +020055 virtual ~RtcEventLog() {}
56
terelius4311ba52016-04-22 12:40:37 -070057 // Factory method to create an RtcEventLog object.
Danil Chapovalovd312a912017-10-05 12:25:18 +000058 // 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);
nisse30612762016-12-20 05:03:58 -080061 // TODO(nisse): webrtc::Clock is deprecated. Delete this method and
62 // above forward declaration of Clock when
Elad Alon4a87e1c2017-10-03 16:11:34 +020063 // webrtc/system_wrappers/include/clock.h is deleted.
Danil Chapovalovd312a912017-10-05 12:25:18 +000064 // 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 Alon4a87e1c2017-10-03 16:11:34 +020068 return Create(encoding_type);
nisse30612762016-12-20 05:03:58 -080069 }
Bjorn Terelius36411852015-07-30 12:45:18 +020070
ivoc14d5dbe2016-07-04 07:06:55 -070071 // Create an RtcEventLog object that does nothing.
72 static std::unique_ptr<RtcEventLog> CreateNull();
73
Elad Alon83ccca12017-10-04 13:18:26 +020074 // 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 Chapovalovd312a912017-10-05 12:25:18 +000078 // 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
eladalon248fd4f2017-09-06 05:18:15 -0700101 // 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 Terelius36411852015-07-30 12:45:18 +0200103 virtual void StopLogging() = 0;
104
Elad Alon4a87e1c2017-10-03 16:11:34 +0200105 // Log an RTC event (the type of event is determined by the subclass).
106 virtual void Log(std::unique_ptr<RtcEvent> event) = 0;
Danil Chapovalovd312a912017-10-05 12:25:18 +0000107
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 Terelius36411852015-07-30 12:45:18 +0200187};
188
Stefan Holmer13181032016-07-29 14:48:54 +0200189// No-op implementation is used if flag is not set, or in tests.
perkj33bb86d2017-05-29 02:46:05 -0700190class RtcEventLogNullImpl : public RtcEventLog {
Stefan Holmer13181032016-07-29 14:48:54 +0200191 public:
Elad Alon83ccca12017-10-04 13:18:26 +0200192 bool StartLogging(std::unique_ptr<RtcEventLogOutput> output) override {
193 return false;
194 }
Danil Chapovalovd312a912017-10-05 12:25:18 +0000195 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 Holmer13181032016-07-29 14:48:54 +0200203 void StopLogging() override {}
Elad Alon4a87e1c2017-10-03 16:11:34 +0200204 void Log(std::unique_ptr<RtcEvent> event) override {}
Danil Chapovalovd312a912017-10-05 12:25:18 +0000205 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 Holmer13181032016-07-29 14:48:54 +0200231};
232
Bjorn Terelius36411852015-07-30 12:45:18 +0200233} // namespace webrtc
234
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200235#endif // LOGGING_RTC_EVENT_LOG_RTC_EVENT_LOG_H_