blob: 89b4fc1a0862d437d3ec89a6cb1a41659c639ba0 [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>
Bjorn Tereliusde939432017-11-20 17:38:14 +010016#include <utility>
Bjorn Terelius36411852015-07-30 12:45:18 +020017
Elad Alon80810732017-10-06 13:07:32 +020018#include "api/rtceventlogoutput.h"
Elad Alon604c14d2017-10-05 12:47:06 +000019#include "logging/rtc_event_log/events/rtc_event.h"
Bjorn Terelius36411852015-07-30 12:45:18 +020020
21namespace webrtc {
22
Danil Chapovalovd312a912017-10-05 12:25:18 +000023class Clock;
Elad Alon604c14d2017-10-05 12:47:06 +000024
terelius429c3452016-01-21 05:42:04 -080025enum PacketDirection { kIncomingPacket = 0, kOutgoingPacket };
26
Bjorn Terelius36411852015-07-30 12:45:18 +020027class RtcEventLog {
28 public:
Elad Alon83ccca12017-10-04 13:18:26 +020029 enum : size_t { kUnlimitedOutput = 0 };
Bjorn Tereliusde939432017-11-20 17:38:14 +010030 enum : int64_t { kImmediateOutput = 0 };
Elad Alon83ccca12017-10-04 13:18:26 +020031
Elad Alon4a87e1c2017-10-03 16:11:34 +020032 // TODO(eladalon): Two stages are upcoming.
33 // 1. Extend this to actually support the new encoding.
34 // 2. Get rid of the legacy encoding, allowing us to get rid of this enum.
35 enum class EncodingType { Legacy };
36
Bjorn Terelius36411852015-07-30 12:45:18 +020037 virtual ~RtcEventLog() {}
38
terelius4311ba52016-04-22 12:40:37 -070039 // Factory method to create an RtcEventLog object.
Elad Alon604c14d2017-10-05 12:47:06 +000040 static std::unique_ptr<RtcEventLog> Create(EncodingType encoding_type);
nisse30612762016-12-20 05:03:58 -080041 // TODO(nisse): webrtc::Clock is deprecated. Delete this method and
42 // above forward declaration of Clock when
Elad Alon4a87e1c2017-10-03 16:11:34 +020043 // webrtc/system_wrappers/include/clock.h is deleted.
Elad Alon604c14d2017-10-05 12:47:06 +000044 static std::unique_ptr<RtcEventLog> Create(const Clock* clock,
45 EncodingType encoding_type) {
Elad Alon4a87e1c2017-10-03 16:11:34 +020046 return Create(encoding_type);
nisse30612762016-12-20 05:03:58 -080047 }
Bjorn Terelius36411852015-07-30 12:45:18 +020048
ivoc14d5dbe2016-07-04 07:06:55 -070049 // Create an RtcEventLog object that does nothing.
50 static std::unique_ptr<RtcEventLog> CreateNull();
51
Elad Alon83ccca12017-10-04 13:18:26 +020052 // Starts logging to a given output. The output might be limited in size,
53 // and may close itself once it has reached the maximum size.
Bjorn Tereliusde939432017-11-20 17:38:14 +010054 virtual bool StartLogging(std::unique_ptr<RtcEventLogOutput> output,
55 int64_t output_period_ms) = 0;
Elad Alon83ccca12017-10-04 13:18:26 +020056
eladalon248fd4f2017-09-06 05:18:15 -070057 // Stops logging to file and waits until the file has been closed, after
58 // which it would be permissible to read and/or modify it.
Bjorn Terelius36411852015-07-30 12:45:18 +020059 virtual void StopLogging() = 0;
60
Elad Alon4a87e1c2017-10-03 16:11:34 +020061 // Log an RTC event (the type of event is determined by the subclass).
62 virtual void Log(std::unique_ptr<RtcEvent> event) = 0;
Bjorn Terelius36411852015-07-30 12:45:18 +020063};
64
Stefan Holmer13181032016-07-29 14:48:54 +020065// No-op implementation is used if flag is not set, or in tests.
perkj33bb86d2017-05-29 02:46:05 -070066class RtcEventLogNullImpl : public RtcEventLog {
Stefan Holmer13181032016-07-29 14:48:54 +020067 public:
Bjorn Tereliusde939432017-11-20 17:38:14 +010068 bool StartLogging(std::unique_ptr<RtcEventLogOutput> output,
69 int64_t output_period_ms) override {
Elad Alon83ccca12017-10-04 13:18:26 +020070 return false;
71 }
Stefan Holmer13181032016-07-29 14:48:54 +020072 void StopLogging() override {}
Elad Alon4a87e1c2017-10-03 16:11:34 +020073 void Log(std::unique_ptr<RtcEvent> event) override {}
Stefan Holmer13181032016-07-29 14:48:54 +020074};
75
Bjorn Terelius36411852015-07-30 12:45:18 +020076} // namespace webrtc
77
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020078#endif // LOGGING_RTC_EVENT_LOG_RTC_EVENT_LOG_H_