blob: e09d18483776cca7cc41bc8b93d05277c3399bf3 [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
Yves Gerey988cc082018-10-23 12:03:01 +020014#include <stdint.h>
kwibergb25345e2016-03-12 06:10:44 -080015#include <memory>
Bjorn Terelius36411852015-07-30 12:45:18 +020016
Elad Alon80810732017-10-06 13:07:32 +020017#include "api/rtceventlogoutput.h"
Elad Alon604c14d2017-10-05 12:47:06 +000018#include "logging/rtc_event_log/events/rtc_event.h"
Dino Radakoviće9d2e4d2018-03-20 18:15:39 +010019#include "rtc_base/task_queue.h"
Bjorn Terelius36411852015-07-30 12:45:18 +020020
21namespace webrtc {
22
Bjorn Tereliusc4ca1d32018-04-27 14:33:34 +020023// TODO(terelius): Move this to the parser.
terelius429c3452016-01-21 05:42:04 -080024enum PacketDirection { kIncomingPacket = 0, kOutgoingPacket };
25
Bjorn Terelius36411852015-07-30 12:45:18 +020026class RtcEventLog {
27 public:
Elad Alon83ccca12017-10-04 13:18:26 +020028 enum : size_t { kUnlimitedOutput = 0 };
Bjorn Tereliusde939432017-11-20 17:38:14 +010029 enum : int64_t { kImmediateOutput = 0 };
Elad Alon83ccca12017-10-04 13:18:26 +020030
Elad Alon4a87e1c2017-10-03 16:11:34 +020031 // TODO(eladalon): Two stages are upcoming.
32 // 1. Extend this to actually support the new encoding.
33 // 2. Get rid of the legacy encoding, allowing us to get rid of this enum.
34 enum class EncodingType { Legacy };
35
Bjorn Terelius36411852015-07-30 12:45:18 +020036 virtual ~RtcEventLog() {}
37
terelius4311ba52016-04-22 12:40:37 -070038 // Factory method to create an RtcEventLog object.
Elad Alon604c14d2017-10-05 12:47:06 +000039 static std::unique_ptr<RtcEventLog> Create(EncodingType encoding_type);
Bjorn Terelius36411852015-07-30 12:45:18 +020040
Dino Radakoviće9d2e4d2018-03-20 18:15:39 +010041 // Factory method to create an RtcEventLog object which uses the given
42 // rtc::TaskQueue for emitting output.
43 static std::unique_ptr<RtcEventLog> Create(
44 EncodingType encoding_type,
45 std::unique_ptr<rtc::TaskQueue> task_queue);
46
ivoc14d5dbe2016-07-04 07:06:55 -070047 // Create an RtcEventLog object that does nothing.
48 static std::unique_ptr<RtcEventLog> CreateNull();
49
Elad Alon83ccca12017-10-04 13:18:26 +020050 // Starts logging to a given output. The output might be limited in size,
51 // and may close itself once it has reached the maximum size.
Bjorn Tereliusde939432017-11-20 17:38:14 +010052 virtual bool StartLogging(std::unique_ptr<RtcEventLogOutput> output,
53 int64_t output_period_ms) = 0;
Elad Alon83ccca12017-10-04 13:18:26 +020054
eladalon248fd4f2017-09-06 05:18:15 -070055 // Stops logging to file and waits until the file has been closed, after
56 // which it would be permissible to read and/or modify it.
Bjorn Terelius36411852015-07-30 12:45:18 +020057 virtual void StopLogging() = 0;
58
Elad Alon4a87e1c2017-10-03 16:11:34 +020059 // Log an RTC event (the type of event is determined by the subclass).
60 virtual void Log(std::unique_ptr<RtcEvent> event) = 0;
Bjorn Terelius36411852015-07-30 12:45:18 +020061};
62
Stefan Holmer13181032016-07-29 14:48:54 +020063// No-op implementation is used if flag is not set, or in tests.
perkj33bb86d2017-05-29 02:46:05 -070064class RtcEventLogNullImpl : public RtcEventLog {
Stefan Holmer13181032016-07-29 14:48:54 +020065 public:
Bjorn Tereliusde939432017-11-20 17:38:14 +010066 bool StartLogging(std::unique_ptr<RtcEventLogOutput> output,
Danil Chapovalov2a5ce2b2018-02-07 09:38:31 +010067 int64_t output_period_ms) override;
Stefan Holmer13181032016-07-29 14:48:54 +020068 void StopLogging() override {}
Elad Alon4a87e1c2017-10-03 16:11:34 +020069 void Log(std::unique_ptr<RtcEvent> event) override {}
Stefan Holmer13181032016-07-29 14:48:54 +020070};
71
Bjorn Terelius36411852015-07-30 12:45:18 +020072} // namespace webrtc
73
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020074#endif // LOGGING_RTC_EVENT_LOG_RTC_EVENT_LOG_H_