blob: bea57b01cd11eb4729b83f1967cb6258862ac7c2 [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
terelius4311ba52016-04-22 12:40:37 -070043 // Starts logging a maximum of max_size_bytes bytes to the specified file.
Bjorn Terelius36411852015-07-30 12:45:18 +020044 // If the file already exists it will be overwritten.
terelius4311ba52016-04-22 12:40:37 -070045 // If max_size_bytes <= 0, logging will be active until StopLogging is called.
46 // The function has no effect and returns false if we can't start a new log
47 // e.g. because we are already logging or the file cannot be opened.
48 virtual bool StartLogging(const std::string& file_name,
49 int64_t max_size_bytes) = 0;
Bjorn Terelius36411852015-07-30 12:45:18 +020050
terelius4311ba52016-04-22 12:40:37 -070051 // Same as above. The RtcEventLog takes ownership of the file if the call
52 // is successful, i.e. if it returns true.
53 virtual bool StartLogging(rtc::PlatformFile platform_file,
54 int64_t max_size_bytes) = 0;
ivoc112a3d82015-10-16 02:22:18 -070055
terelius4311ba52016-04-22 12:40:37 -070056 // Deprecated. Pass an explicit file size limit.
57 bool StartLogging(const std::string& file_name) {
58 return StartLogging(file_name, 10000000);
59 }
60
61 // Deprecated. Pass an explicit file size limit.
62 bool StartLogging(rtc::PlatformFile platform_file) {
63 return StartLogging(platform_file, 10000000);
64 }
65
66 // Stops logging to file and waits until the thread has finished.
Bjorn Terelius36411852015-07-30 12:45:18 +020067 virtual void StopLogging() = 0;
68
terelius4311ba52016-04-22 12:40:37 -070069 // Logs configuration information for webrtc::VideoReceiveStream.
Bjorn Terelius36411852015-07-30 12:45:18 +020070 virtual void LogVideoReceiveStreamConfig(
71 const webrtc::VideoReceiveStream::Config& config) = 0;
72
terelius4311ba52016-04-22 12:40:37 -070073 // Logs configuration information for webrtc::VideoSendStream.
Bjorn Terelius36411852015-07-30 12:45:18 +020074 virtual void LogVideoSendStreamConfig(
75 const webrtc::VideoSendStream::Config& config) = 0;
76
terelius2f9fd5d2015-09-04 03:39:42 -070077 // Logs the header of an incoming or outgoing RTP packet. packet_length
78 // is the total length of the packet, including both header and payload.
terelius429c3452016-01-21 05:42:04 -080079 virtual void LogRtpHeader(PacketDirection direction,
Bjorn Terelius36411852015-07-30 12:45:18 +020080 MediaType media_type,
81 const uint8_t* header,
terelius2f9fd5d2015-09-04 03:39:42 -070082 size_t packet_length) = 0;
Bjorn Terelius36411852015-07-30 12:45:18 +020083
84 // Logs an incoming or outgoing RTCP packet.
terelius429c3452016-01-21 05:42:04 -080085 virtual void LogRtcpPacket(PacketDirection direction,
Bjorn Terelius36411852015-07-30 12:45:18 +020086 MediaType media_type,
87 const uint8_t* packet,
88 size_t length) = 0;
89
terelius4311ba52016-04-22 12:40:37 -070090 // Logs an audio playout event.
Ivo Creusenae856f22015-09-17 16:30:16 +020091 virtual void LogAudioPlayout(uint32_t ssrc) = 0;
Bjorn Terelius36411852015-07-30 12:45:18 +020092
terelius006d93d2015-11-05 12:02:15 -080093 // Logs a bitrate update from the bandwidth estimator based on packet loss.
94 virtual void LogBwePacketLossEvent(int32_t bitrate,
95 uint8_t fraction_loss,
96 int32_t total_packets) = 0;
97
Bjorn Terelius36411852015-07-30 12:45:18 +020098 // Reads an RtcEventLog file and returns true when reading was successful.
99 // The result is stored in the given EventStream object.
terelius4311ba52016-04-22 12:40:37 -0700100 // The order of the events in the EventStream is implementation defined.
101 // The current implementation writes a LOG_START event, then the old
102 // configurations, then the remaining events in timestamp order and finally
103 // a LOG_END event. However, this might change without further notice.
104 // TODO(terelius): Change result type to a vector?
Bjorn Terelius36411852015-07-30 12:45:18 +0200105 static bool ParseRtcEventLog(const std::string& file_name,
106 rtclog::EventStream* result);
107};
108
109} // namespace webrtc
110
Peter Boström5c389d32015-09-25 13:58:30 +0200111#endif // WEBRTC_CALL_RTC_EVENT_LOG_H_