blob: 40d89896351cd31cfc2a255705f21defb0c47f21 [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
skvladcc91d282016-10-03 18:31:22 -070011#ifndef WEBRTC_LOGGING_RTC_EVENT_LOG_RTC_EVENT_LOG_H_
12#define WEBRTC_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>
perkj09e71da2017-05-22 03:26:49 -070016#include <vector>
Bjorn Terelius36411852015-07-30 12:45:18 +020017
eladalon4bb3b9c2017-09-11 07:25:26 -070018// TODO(eladalon): Get rid of this later in the CL-stack.
Stefan Holmer1acbd682017-09-01 15:29:28 +020019#include "webrtc/api/rtpparameters.h"
20#include "webrtc/common_types.h"
eladalon4bb3b9c2017-09-11 07:25:26 -070021// TODO(eladalon): Get rid of this later in the CL-stack.
22#include "webrtc/logging/rtc_event_log/rtc_stream_config.h"
Edward Lemurc20978e2017-07-06 19:44:34 +020023#include "webrtc/rtc_base/platform_file.h"
Bjorn Terelius36411852015-07-30 12:45:18 +020024
25namespace webrtc {
26
Bjorn Terelius36411852015-07-30 12:45:18 +020027namespace rtclog {
eladalon4bb3b9c2017-09-11 07:25:26 -070028class EventStream; // Storage class automatically generated from protobuf.
Bjorn Terelius36411852015-07-30 12:45:18 +020029} // namespace rtclog
30
terelius4311ba52016-04-22 12:40:37 -070031class Clock;
michaeltcde46b72017-04-06 05:59:10 -070032struct AudioEncoderRuntimeConfig;
Bjorn Terelius36411852015-07-30 12:45:18 +020033
34enum class MediaType;
michaelt97653702017-04-11 00:49:44 -070035enum class BandwidthUsage;
Bjorn Terelius36411852015-07-30 12:45:18 +020036
terelius429c3452016-01-21 05:42:04 -080037enum PacketDirection { kIncomingPacket = 0, kOutgoingPacket };
philipel32d00102017-02-27 02:18:46 -080038enum ProbeFailureReason {
39 kInvalidSendReceiveInterval,
40 kInvalidSendReceiveRatio,
41 kTimeout
42};
terelius429c3452016-01-21 05:42:04 -080043
Bjorn Terelius36411852015-07-30 12:45:18 +020044class RtcEventLog {
45 public:
Bjorn Terelius36411852015-07-30 12:45:18 +020046 virtual ~RtcEventLog() {}
47
terelius4311ba52016-04-22 12:40:37 -070048 // Factory method to create an RtcEventLog object.
nisse30612762016-12-20 05:03:58 -080049 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 Terelius36411852015-07-30 12:45:18 +020056
ivoc14d5dbe2016-07-04 07:06:55 -070057 // Create an RtcEventLog object that does nothing.
58 static std::unique_ptr<RtcEventLog> CreateNull();
59
terelius4311ba52016-04-22 12:40:37 -070060 // Starts logging a maximum of max_size_bytes bytes to the specified file.
Bjorn Terelius36411852015-07-30 12:45:18 +020061 // If the file already exists it will be overwritten.
terelius4311ba52016-04-22 12:40:37 -070062 // 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 Terelius36411852015-07-30 12:45:18 +020067
terelius4311ba52016-04-22 12:40:37 -070068 // 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;
ivoc112a3d82015-10-16 02:22:18 -070072
terelius4311ba52016-04-22 12:40:37 -070073 // Deprecated. Pass an explicit file size limit.
eladalon248fd4f2017-09-06 05:18:15 -070074 RTC_DEPRECATED bool StartLogging(const std::string& file_name) {
terelius4311ba52016-04-22 12:40:37 -070075 return StartLogging(file_name, 10000000);
76 }
77
78 // Deprecated. Pass an explicit file size limit.
eladalon248fd4f2017-09-06 05:18:15 -070079 RTC_DEPRECATED bool StartLogging(rtc::PlatformFile platform_file) {
terelius4311ba52016-04-22 12:40:37 -070080 return StartLogging(platform_file, 10000000);
81 }
82
eladalon248fd4f2017-09-06 05:18:15 -070083 // 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 Terelius36411852015-07-30 12:45:18 +020085 virtual void StopLogging() = 0;
86
perkjc0876aa2017-05-22 04:08:28 -070087 // Logs configuration information for a video receive stream.
Bjorn Terelius36411852015-07-30 12:45:18 +020088 virtual void LogVideoReceiveStreamConfig(
perkj09e71da2017-05-22 03:26:49 -070089 const rtclog::StreamConfig& config) = 0;
Bjorn Terelius36411852015-07-30 12:45:18 +020090
perkjc0876aa2017-05-22 04:08:28 -070091 // Logs configuration information for a video send stream.
92 virtual void LogVideoSendStreamConfig(const rtclog::StreamConfig& config) = 0;
Bjorn Terelius36411852015-07-30 12:45:18 +020093
perkjac8f52d2017-05-22 09:36:28 -070094 // Logs configuration information for an audio receive stream.
ivoce0928d82016-10-10 05:12:51 -070095 virtual void LogAudioReceiveStreamConfig(
perkjac8f52d2017-05-22 09:36:28 -070096 const rtclog::StreamConfig& config) = 0;
ivoce0928d82016-10-10 05:12:51 -070097
perkjf4726992017-05-22 10:12:26 -070098 // Logs configuration information for an audio send stream.
99 virtual void LogAudioSendStreamConfig(const rtclog::StreamConfig& config) = 0;
ivoce0928d82016-10-10 05:12:51 -0700100
terelius2f9fd5d2015-09-04 03:39:42 -0700101 // 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.
terelius429c3452016-01-21 05:42:04 -0800103 virtual void LogRtpHeader(PacketDirection direction,
Bjorn Terelius36411852015-07-30 12:45:18 +0200104 const uint8_t* header,
terelius2f9fd5d2015-09-04 03:39:42 -0700105 size_t packet_length) = 0;
Bjorn Terelius36411852015-07-30 12:45:18 +0200106
philipel32d00102017-02-27 02:18:46 -0800107 // 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,
philipel32d00102017-02-27 02:18:46 -0800110 const uint8_t* header,
111 size_t packet_length,
112 int probe_cluster_id) = 0;
113
Bjorn Terelius36411852015-07-30 12:45:18 +0200114 // Logs an incoming or outgoing RTCP packet.
terelius429c3452016-01-21 05:42:04 -0800115 virtual void LogRtcpPacket(PacketDirection direction,
Bjorn Terelius36411852015-07-30 12:45:18 +0200116 const uint8_t* packet,
117 size_t length) = 0;
118
terelius4311ba52016-04-22 12:40:37 -0700119 // Logs an audio playout event.
Ivo Creusenae856f22015-09-17 16:30:16 +0200120 virtual void LogAudioPlayout(uint32_t ssrc) = 0;
Bjorn Terelius36411852015-07-30 12:45:18 +0200121
terelius006d93d2015-11-05 12:02:15 -0800122 // Logs a bitrate update from the bandwidth estimator based on packet loss.
terelius424e6cf2017-02-20 05:14:41 -0800123 virtual void LogLossBasedBweUpdate(int32_t bitrate_bps,
terelius006d93d2015-11-05 12:02:15 -0800124 uint8_t fraction_loss,
125 int32_t total_packets) = 0;
126
terelius0baf55d2017-02-17 03:38:28 -0800127 // Logs a bitrate update from the bandwidth estimator based on delay changes.
terelius424e6cf2017-02-20 05:14:41 -0800128 virtual void LogDelayBasedBweUpdate(int32_t bitrate_bps,
terelius0baf55d2017-02-17 03:38:28 -0800129 BandwidthUsage detector_state) = 0;
130
minyue4b7c9522017-01-24 04:54:59 -0800131 // Logs audio encoder re-configuration driven by audio network adaptor.
132 virtual void LogAudioNetworkAdaptation(
michaeltcde46b72017-04-06 05:59:10 -0700133 const AudioEncoderRuntimeConfig& config) = 0;
minyue4b7c9522017-01-24 04:54:59 -0800134
philipel32d00102017-02-27 02:18:46 -0800135 // 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 Terelius36411852015-07-30 12:45:18 +0200148 // Reads an RtcEventLog file and returns true when reading was successful.
149 // The result is stored in the given EventStream object.
terelius4311ba52016-04-22 12:40:37 -0700150 // 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 Terelius36411852015-07-30 12:45:18 +0200155 static bool ParseRtcEventLog(const std::string& file_name,
156 rtclog::EventStream* result);
157};
158
Stefan Holmer13181032016-07-29 14:48:54 +0200159// No-op implementation is used if flag is not set, or in tests.
perkj33bb86d2017-05-29 02:46:05 -0700160class RtcEventLogNullImpl : public RtcEventLog {
Stefan Holmer13181032016-07-29 14:48:54 +0200161 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,
zhihuang38ede132017-06-15 12:52:32 -0700167 int64_t max_size_bytes) override {
168 return false;
169 }
Stefan Holmer13181032016-07-29 14:48:54 +0200170 void StopLogging() override {}
171 void LogVideoReceiveStreamConfig(
perkj09e71da2017-05-22 03:26:49 -0700172 const rtclog::StreamConfig& config) override {}
perkjc0876aa2017-05-22 04:08:28 -0700173 void LogVideoSendStreamConfig(const rtclog::StreamConfig& config) override {}
ivoce0928d82016-10-10 05:12:51 -0700174 void LogAudioReceiveStreamConfig(
perkjac8f52d2017-05-22 09:36:28 -0700175 const rtclog::StreamConfig& config) override {}
perkjf4726992017-05-22 10:12:26 -0700176 void LogAudioSendStreamConfig(const rtclog::StreamConfig& config) override {}
Stefan Holmer13181032016-07-29 14:48:54 +0200177 void LogRtpHeader(PacketDirection direction,
Stefan Holmer13181032016-07-29 14:48:54 +0200178 const uint8_t* header,
179 size_t packet_length) override {}
philipel32d00102017-02-27 02:18:46 -0800180 void LogRtpHeader(PacketDirection direction,
philipel32d00102017-02-27 02:18:46 -0800181 const uint8_t* header,
182 size_t packet_length,
183 int probe_cluster_id) override {}
Stefan Holmer13181032016-07-29 14:48:54 +0200184 void LogRtcpPacket(PacketDirection direction,
Stefan Holmer13181032016-07-29 14:48:54 +0200185 const uint8_t* packet,
186 size_t length) override {}
187 void LogAudioPlayout(uint32_t ssrc) override {}
terelius424e6cf2017-02-20 05:14:41 -0800188 void LogLossBasedBweUpdate(int32_t bitrate_bps,
Stefan Holmer13181032016-07-29 14:48:54 +0200189 uint8_t fraction_loss,
190 int32_t total_packets) override {}
terelius424e6cf2017-02-20 05:14:41 -0800191 void LogDelayBasedBweUpdate(int32_t bitrate_bps,
terelius0baf55d2017-02-17 03:38:28 -0800192 BandwidthUsage detector_state) override {}
minyue4b7c9522017-01-24 04:54:59 -0800193 void LogAudioNetworkAdaptation(
michaeltcde46b72017-04-06 05:59:10 -0700194 const AudioEncoderRuntimeConfig& config) override {}
philipel32d00102017-02-27 02:18:46 -0800195 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 Holmer13181032016-07-29 14:48:54 +0200202};
203
Bjorn Terelius36411852015-07-30 12:45:18 +0200204} // namespace webrtc
205
skvladcc91d282016-10-03 18:31:22 -0700206#endif // WEBRTC_LOGGING_RTC_EVENT_LOG_RTC_EVENT_LOG_H_