blob: 7c72dd5ce995a4443a25af429154c4ce7f651bab [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
Peter Boström5c389d32015-09-25 13:58:30 +020011#ifndef WEBRTC_CALL_RTC_EVENT_LOG_H_
12#define WEBRTC_CALL_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
ivoc112a3d82015-10-16 02:22:18 -070017#include "webrtc/base/platform_file.h"
Bjorn Terelius36411852015-07-30 12:45:18 +020018#include "webrtc/video_receive_stream.h"
19#include "webrtc/video_send_stream.h"
20
21namespace webrtc {
22
23// Forward declaration of storage class that is automatically generated from
24// the protobuf file.
25namespace rtclog {
26class EventStream;
27} // namespace rtclog
28
terelius4311ba52016-04-22 12:40:37 -070029class Clock;
Bjorn Terelius36411852015-07-30 12:45:18 +020030class RtcEventLogImpl;
31
32enum class MediaType;
33
terelius429c3452016-01-21 05:42:04 -080034enum PacketDirection { kIncomingPacket = 0, kOutgoingPacket };
35
Bjorn Terelius36411852015-07-30 12:45:18 +020036class RtcEventLog {
37 public:
Bjorn Terelius36411852015-07-30 12:45:18 +020038 virtual ~RtcEventLog() {}
39
terelius4311ba52016-04-22 12:40:37 -070040 // Factory method to create an RtcEventLog object.
41 static std::unique_ptr<RtcEventLog> Create(const Clock* clock);
Bjorn Terelius36411852015-07-30 12:45:18 +020042
ivoc14d5dbe2016-07-04 07:06:55 -070043 // Create an RtcEventLog object that does nothing.
44 static std::unique_ptr<RtcEventLog> CreateNull();
45
terelius4311ba52016-04-22 12:40:37 -070046 // Starts logging a maximum of max_size_bytes bytes to the specified file.
Bjorn Terelius36411852015-07-30 12:45:18 +020047 // If the file already exists it will be overwritten.
terelius4311ba52016-04-22 12:40:37 -070048 // If max_size_bytes <= 0, logging will be active until StopLogging is called.
49 // The function has no effect and returns false if we can't start a new log
50 // e.g. because we are already logging or the file cannot be opened.
51 virtual bool StartLogging(const std::string& file_name,
52 int64_t max_size_bytes) = 0;
Bjorn Terelius36411852015-07-30 12:45:18 +020053
terelius4311ba52016-04-22 12:40:37 -070054 // Same as above. The RtcEventLog takes ownership of the file if the call
55 // is successful, i.e. if it returns true.
56 virtual bool StartLogging(rtc::PlatformFile platform_file,
57 int64_t max_size_bytes) = 0;
ivoc112a3d82015-10-16 02:22:18 -070058
terelius4311ba52016-04-22 12:40:37 -070059 // Deprecated. Pass an explicit file size limit.
60 bool StartLogging(const std::string& file_name) {
61 return StartLogging(file_name, 10000000);
62 }
63
64 // Deprecated. Pass an explicit file size limit.
65 bool StartLogging(rtc::PlatformFile platform_file) {
66 return StartLogging(platform_file, 10000000);
67 }
68
69 // Stops logging to file and waits until the thread has finished.
Bjorn Terelius36411852015-07-30 12:45:18 +020070 virtual void StopLogging() = 0;
71
terelius4311ba52016-04-22 12:40:37 -070072 // Logs configuration information for webrtc::VideoReceiveStream.
Bjorn Terelius36411852015-07-30 12:45:18 +020073 virtual void LogVideoReceiveStreamConfig(
74 const webrtc::VideoReceiveStream::Config& config) = 0;
75
terelius4311ba52016-04-22 12:40:37 -070076 // Logs configuration information for webrtc::VideoSendStream.
Bjorn Terelius36411852015-07-30 12:45:18 +020077 virtual void LogVideoSendStreamConfig(
78 const webrtc::VideoSendStream::Config& config) = 0;
79
terelius2f9fd5d2015-09-04 03:39:42 -070080 // Logs the header of an incoming or outgoing RTP packet. packet_length
81 // is the total length of the packet, including both header and payload.
terelius429c3452016-01-21 05:42:04 -080082 virtual void LogRtpHeader(PacketDirection direction,
Bjorn Terelius36411852015-07-30 12:45:18 +020083 MediaType media_type,
84 const uint8_t* header,
terelius2f9fd5d2015-09-04 03:39:42 -070085 size_t packet_length) = 0;
Bjorn Terelius36411852015-07-30 12:45:18 +020086
87 // Logs an incoming or outgoing RTCP packet.
terelius429c3452016-01-21 05:42:04 -080088 virtual void LogRtcpPacket(PacketDirection direction,
Bjorn Terelius36411852015-07-30 12:45:18 +020089 MediaType media_type,
90 const uint8_t* packet,
91 size_t length) = 0;
92
terelius4311ba52016-04-22 12:40:37 -070093 // Logs an audio playout event.
Ivo Creusenae856f22015-09-17 16:30:16 +020094 virtual void LogAudioPlayout(uint32_t ssrc) = 0;
Bjorn Terelius36411852015-07-30 12:45:18 +020095
terelius006d93d2015-11-05 12:02:15 -080096 // Logs a bitrate update from the bandwidth estimator based on packet loss.
97 virtual void LogBwePacketLossEvent(int32_t bitrate,
98 uint8_t fraction_loss,
99 int32_t total_packets) = 0;
100
Bjorn Terelius36411852015-07-30 12:45:18 +0200101 // Reads an RtcEventLog file and returns true when reading was successful.
102 // The result is stored in the given EventStream object.
terelius4311ba52016-04-22 12:40:37 -0700103 // The order of the events in the EventStream is implementation defined.
104 // The current implementation writes a LOG_START event, then the old
105 // configurations, then the remaining events in timestamp order and finally
106 // a LOG_END event. However, this might change without further notice.
107 // TODO(terelius): Change result type to a vector?
Bjorn Terelius36411852015-07-30 12:45:18 +0200108 static bool ParseRtcEventLog(const std::string& file_name,
109 rtclog::EventStream* result);
110};
111
112} // namespace webrtc
113
Peter Boström5c389d32015-09-25 13:58:30 +0200114#endif // WEBRTC_CALL_RTC_EVENT_LOG_H_