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 | |
ivoc | 14d5dbe | 2016-07-04 07:06:55 -0700 | [diff] [blame^] | 43 | // Create an RtcEventLog object that does nothing. |
| 44 | static std::unique_ptr<RtcEventLog> CreateNull(); |
| 45 | |
terelius | 4311ba5 | 2016-04-22 12:40:37 -0700 | [diff] [blame] | 46 | // 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] | 47 | // If the file already exists it will be overwritten. |
terelius | 4311ba5 | 2016-04-22 12:40:37 -0700 | [diff] [blame] | 48 | // 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 Terelius | 3641185 | 2015-07-30 12:45:18 +0200 | [diff] [blame] | 53 | |
terelius | 4311ba5 | 2016-04-22 12:40:37 -0700 | [diff] [blame] | 54 | // 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; |
ivoc | 112a3d8 | 2015-10-16 02:22:18 -0700 | [diff] [blame] | 58 | |
terelius | 4311ba5 | 2016-04-22 12:40:37 -0700 | [diff] [blame] | 59 | // 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 Terelius | 3641185 | 2015-07-30 12:45:18 +0200 | [diff] [blame] | 70 | virtual void StopLogging() = 0; |
| 71 | |
terelius | 4311ba5 | 2016-04-22 12:40:37 -0700 | [diff] [blame] | 72 | // Logs configuration information for webrtc::VideoReceiveStream. |
Bjorn Terelius | 3641185 | 2015-07-30 12:45:18 +0200 | [diff] [blame] | 73 | virtual void LogVideoReceiveStreamConfig( |
| 74 | const webrtc::VideoReceiveStream::Config& config) = 0; |
| 75 | |
terelius | 4311ba5 | 2016-04-22 12:40:37 -0700 | [diff] [blame] | 76 | // Logs configuration information for webrtc::VideoSendStream. |
Bjorn Terelius | 3641185 | 2015-07-30 12:45:18 +0200 | [diff] [blame] | 77 | virtual void LogVideoSendStreamConfig( |
| 78 | const webrtc::VideoSendStream::Config& config) = 0; |
| 79 | |
terelius | 2f9fd5d | 2015-09-04 03:39:42 -0700 | [diff] [blame] | 80 | // 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. |
terelius | 429c345 | 2016-01-21 05:42:04 -0800 | [diff] [blame] | 82 | virtual void LogRtpHeader(PacketDirection direction, |
Bjorn Terelius | 3641185 | 2015-07-30 12:45:18 +0200 | [diff] [blame] | 83 | MediaType media_type, |
| 84 | const uint8_t* header, |
terelius | 2f9fd5d | 2015-09-04 03:39:42 -0700 | [diff] [blame] | 85 | size_t packet_length) = 0; |
Bjorn Terelius | 3641185 | 2015-07-30 12:45:18 +0200 | [diff] [blame] | 86 | |
| 87 | // Logs an incoming or outgoing RTCP packet. |
terelius | 429c345 | 2016-01-21 05:42:04 -0800 | [diff] [blame] | 88 | virtual void LogRtcpPacket(PacketDirection direction, |
Bjorn Terelius | 3641185 | 2015-07-30 12:45:18 +0200 | [diff] [blame] | 89 | MediaType media_type, |
| 90 | const uint8_t* packet, |
| 91 | size_t length) = 0; |
| 92 | |
terelius | 4311ba5 | 2016-04-22 12:40:37 -0700 | [diff] [blame] | 93 | // Logs an audio playout event. |
Ivo Creusen | ae856f2 | 2015-09-17 16:30:16 +0200 | [diff] [blame] | 94 | virtual void LogAudioPlayout(uint32_t ssrc) = 0; |
Bjorn Terelius | 3641185 | 2015-07-30 12:45:18 +0200 | [diff] [blame] | 95 | |
terelius | 006d93d | 2015-11-05 12:02:15 -0800 | [diff] [blame] | 96 | // 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 Terelius | 3641185 | 2015-07-30 12:45:18 +0200 | [diff] [blame] | 101 | // Reads an RtcEventLog file and returns true when reading was successful. |
| 102 | // The result is stored in the given EventStream object. |
terelius | 4311ba5 | 2016-04-22 12:40:37 -0700 | [diff] [blame] | 103 | // 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 Terelius | 3641185 | 2015-07-30 12:45:18 +0200 | [diff] [blame] | 108 | static bool ParseRtcEventLog(const std::string& file_name, |
| 109 | rtclog::EventStream* result); |
| 110 | }; |
| 111 | |
| 112 | } // namespace webrtc |
| 113 | |
Peter Boström | 5c389d3 | 2015-09-25 13:58:30 +0200 | [diff] [blame] | 114 | #endif // WEBRTC_CALL_RTC_EVENT_LOG_H_ |