Bjorn Terelius | 3641185 | 2015-07-30 12:45:18 +0200 | [diff] [blame] | 1 | /* |
| 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öm | 5c389d3 | 2015-09-25 13:58:30 +0200 | [diff] [blame] | 11 | #ifndef WEBRTC_CALL_RTC_EVENT_LOG_H_ |
| 12 | #define WEBRTC_CALL_RTC_EVENT_LOG_H_ |
Bjorn Terelius | 3641185 | 2015-07-30 12:45:18 +0200 | [diff] [blame] | 13 | |
kwiberg | b25345e | 2016-03-12 06:10:44 -0800 | [diff] [blame] | 14 | #include <memory> |
Bjorn Terelius | 3641185 | 2015-07-30 12:45:18 +0200 | [diff] [blame] | 15 | #include <string> |
| 16 | |
ivoc | 112a3d8 | 2015-10-16 02:22:18 -0700 | [diff] [blame] | 17 | #include "webrtc/base/platform_file.h" |
Bjorn Terelius | 3641185 | 2015-07-30 12:45:18 +0200 | [diff] [blame] | 18 | #include "webrtc/video_receive_stream.h" |
| 19 | #include "webrtc/video_send_stream.h" |
| 20 | |
| 21 | namespace webrtc { |
| 22 | |
| 23 | // Forward declaration of storage class that is automatically generated from |
| 24 | // the protobuf file. |
| 25 | namespace rtclog { |
| 26 | class EventStream; |
| 27 | } // namespace rtclog |
| 28 | |
terelius | 4311ba5 | 2016-04-22 12:40:37 -0700 | [diff] [blame] | 29 | class Clock; |
Bjorn Terelius | 3641185 | 2015-07-30 12:45:18 +0200 | [diff] [blame] | 30 | class RtcEventLogImpl; |
| 31 | |
| 32 | enum class MediaType; |
| 33 | |
terelius | 429c345 | 2016-01-21 05:42:04 -0800 | [diff] [blame] | 34 | enum PacketDirection { kIncomingPacket = 0, kOutgoingPacket }; |
| 35 | |
Bjorn Terelius | 3641185 | 2015-07-30 12:45:18 +0200 | [diff] [blame] | 36 | class RtcEventLog { |
| 37 | public: |
Bjorn Terelius | 3641185 | 2015-07-30 12:45:18 +0200 | [diff] [blame] | 38 | virtual ~RtcEventLog() {} |
| 39 | |
terelius | 4311ba5 | 2016-04-22 12:40:37 -0700 | [diff] [blame] | 40 | // Factory method to create an RtcEventLog object. |
| 41 | static std::unique_ptr<RtcEventLog> Create(const Clock* clock); |
Bjorn Terelius | 3641185 | 2015-07-30 12:45:18 +0200 | [diff] [blame] | 42 | |
terelius | 4311ba5 | 2016-04-22 12:40:37 -0700 | [diff] [blame] | 43 | // Starts logging a maximum of max_size_bytes bytes to the specified file. |
Bjorn Terelius | 3641185 | 2015-07-30 12:45:18 +0200 | [diff] [blame] | 44 | // If the file already exists it will be overwritten. |
terelius | 4311ba5 | 2016-04-22 12:40:37 -0700 | [diff] [blame] | 45 | // 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 Terelius | 3641185 | 2015-07-30 12:45:18 +0200 | [diff] [blame] | 50 | |
terelius | 4311ba5 | 2016-04-22 12:40:37 -0700 | [diff] [blame] | 51 | // 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; |
ivoc | 112a3d8 | 2015-10-16 02:22:18 -0700 | [diff] [blame] | 55 | |
terelius | 4311ba5 | 2016-04-22 12:40:37 -0700 | [diff] [blame] | 56 | // 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 Terelius | 3641185 | 2015-07-30 12:45:18 +0200 | [diff] [blame] | 67 | virtual void StopLogging() = 0; |
| 68 | |
terelius | 4311ba5 | 2016-04-22 12:40:37 -0700 | [diff] [blame] | 69 | // Logs configuration information for webrtc::VideoReceiveStream. |
Bjorn Terelius | 3641185 | 2015-07-30 12:45:18 +0200 | [diff] [blame] | 70 | virtual void LogVideoReceiveStreamConfig( |
| 71 | const webrtc::VideoReceiveStream::Config& config) = 0; |
| 72 | |
terelius | 4311ba5 | 2016-04-22 12:40:37 -0700 | [diff] [blame] | 73 | // Logs configuration information for webrtc::VideoSendStream. |
Bjorn Terelius | 3641185 | 2015-07-30 12:45:18 +0200 | [diff] [blame] | 74 | virtual void LogVideoSendStreamConfig( |
| 75 | const webrtc::VideoSendStream::Config& config) = 0; |
| 76 | |
terelius | 2f9fd5d | 2015-09-04 03:39:42 -0700 | [diff] [blame] | 77 | // 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. |
terelius | 429c345 | 2016-01-21 05:42:04 -0800 | [diff] [blame] | 79 | virtual void LogRtpHeader(PacketDirection direction, |
Bjorn Terelius | 3641185 | 2015-07-30 12:45:18 +0200 | [diff] [blame] | 80 | MediaType media_type, |
| 81 | const uint8_t* header, |
terelius | 2f9fd5d | 2015-09-04 03:39:42 -0700 | [diff] [blame] | 82 | size_t packet_length) = 0; |
Bjorn Terelius | 3641185 | 2015-07-30 12:45:18 +0200 | [diff] [blame] | 83 | |
| 84 | // Logs an incoming or outgoing RTCP packet. |
terelius | 429c345 | 2016-01-21 05:42:04 -0800 | [diff] [blame] | 85 | virtual void LogRtcpPacket(PacketDirection direction, |
Bjorn Terelius | 3641185 | 2015-07-30 12:45:18 +0200 | [diff] [blame] | 86 | MediaType media_type, |
| 87 | const uint8_t* packet, |
| 88 | size_t length) = 0; |
| 89 | |
terelius | 4311ba5 | 2016-04-22 12:40:37 -0700 | [diff] [blame] | 90 | // Logs an audio playout event. |
Ivo Creusen | ae856f2 | 2015-09-17 16:30:16 +0200 | [diff] [blame] | 91 | virtual void LogAudioPlayout(uint32_t ssrc) = 0; |
Bjorn Terelius | 3641185 | 2015-07-30 12:45:18 +0200 | [diff] [blame] | 92 | |
terelius | 006d93d | 2015-11-05 12:02:15 -0800 | [diff] [blame] | 93 | // 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 Terelius | 3641185 | 2015-07-30 12:45:18 +0200 | [diff] [blame] | 98 | // Reads an RtcEventLog file and returns true when reading was successful. |
| 99 | // The result is stored in the given EventStream object. |
terelius | 4311ba5 | 2016-04-22 12:40:37 -0700 | [diff] [blame] | 100 | // 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 Terelius | 3641185 | 2015-07-30 12:45:18 +0200 | [diff] [blame] | 105 | static bool ParseRtcEventLog(const std::string& file_name, |
| 106 | rtclog::EventStream* result); |
| 107 | }; |
| 108 | |
| 109 | } // namespace webrtc |
| 110 | |
Peter Boström | 5c389d3 | 2015-09-25 13:58:30 +0200 | [diff] [blame] | 111 | #endif // WEBRTC_CALL_RTC_EVENT_LOG_H_ |