OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #ifndef WEBRTC_CALL_RTC_EVENT_LOG_H_ | 11 #ifndef WEBRTC_CALL_RTC_EVENT_LOG_H_ |
12 #define WEBRTC_CALL_RTC_EVENT_LOG_H_ | 12 #define WEBRTC_CALL_RTC_EVENT_LOG_H_ |
13 | 13 |
14 #include <memory> | 14 #include <memory> |
15 #include <string> | 15 #include <string> |
16 | 16 |
17 #include "webrtc/base/platform_file.h" | 17 #include "webrtc/base/platform_file.h" |
18 #include "webrtc/video_receive_stream.h" | 18 #include "webrtc/video_receive_stream.h" |
19 #include "webrtc/video_send_stream.h" | 19 #include "webrtc/video_send_stream.h" |
20 | 20 |
21 namespace webrtc { | 21 namespace webrtc { |
22 | 22 |
23 // Forward declaration of storage class that is automatically generated from | 23 // Forward declaration of storage class that is automatically generated from |
24 // the protobuf file. | 24 // the protobuf file. |
25 namespace rtclog { | 25 namespace rtclog { |
26 class EventStream; | 26 class EventStream; |
27 } // namespace rtclog | 27 } // namespace rtclog |
28 | 28 |
| 29 class Clock; |
29 class RtcEventLogImpl; | 30 class RtcEventLogImpl; |
30 | 31 |
31 enum class MediaType; | 32 enum class MediaType; |
32 | 33 |
33 enum PacketDirection { kIncomingPacket = 0, kOutgoingPacket }; | 34 enum PacketDirection { kIncomingPacket = 0, kOutgoingPacket }; |
34 | 35 |
35 class RtcEventLog { | 36 class RtcEventLog { |
36 public: | 37 public: |
37 virtual ~RtcEventLog() {} | 38 virtual ~RtcEventLog() {} |
38 | 39 |
39 static std::unique_ptr<RtcEventLog> Create(); | 40 // Factory method to create an RtcEventLog object. |
| 41 static std::unique_ptr<RtcEventLog> Create(const Clock* clock); |
40 | 42 |
41 // Sets the time that events are stored in the internal event buffer | 43 // Starts logging a maximum of max_size_bytes bytes to the specified file. |
42 // before the user calls StartLogging. The default is 10 000 000 us = 10 s | 44 // If the file already exists it will be overwritten. |
43 virtual void SetBufferDuration(int64_t buffer_duration_us) = 0; | 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; |
44 | 50 |
45 // Starts logging for the specified duration to the specified file. | 51 // Same as above. The RtcEventLog takes ownership of the file if the call |
46 // The logging will stop automatically after the specified duration. | 52 // is successful, i.e. if it returns true. |
47 // If the file already exists it will be overwritten. | 53 virtual bool StartLogging(rtc::PlatformFile platform_file, |
48 // If the file cannot be opened, the RtcEventLog will not start logging. | 54 int64_t max_size_bytes) = 0; |
49 virtual void StartLogging(const std::string& file_name, int duration_ms) = 0; | |
50 | 55 |
51 // Starts logging until either the 10 minute timer runs out or the StopLogging | 56 // Deprecated. Pass an explicit file size limit. |
52 // function is called. The RtcEventLog takes ownership of the supplied | 57 bool StartLogging(const std::string& file_name) { |
53 // rtc::PlatformFile. | 58 return StartLogging(file_name, 10000000); |
54 virtual bool StartLogging(rtc::PlatformFile log_file) = 0; | 59 } |
55 | 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. |
56 virtual void StopLogging() = 0; | 67 virtual void StopLogging() = 0; |
57 | 68 |
58 // Logs configuration information for webrtc::VideoReceiveStream | 69 // Logs configuration information for webrtc::VideoReceiveStream. |
59 virtual void LogVideoReceiveStreamConfig( | 70 virtual void LogVideoReceiveStreamConfig( |
60 const webrtc::VideoReceiveStream::Config& config) = 0; | 71 const webrtc::VideoReceiveStream::Config& config) = 0; |
61 | 72 |
62 // Logs configuration information for webrtc::VideoSendStream | 73 // Logs configuration information for webrtc::VideoSendStream. |
63 virtual void LogVideoSendStreamConfig( | 74 virtual void LogVideoSendStreamConfig( |
64 const webrtc::VideoSendStream::Config& config) = 0; | 75 const webrtc::VideoSendStream::Config& config) = 0; |
65 | 76 |
66 // Logs the header of an incoming or outgoing RTP packet. packet_length | 77 // Logs the header of an incoming or outgoing RTP packet. packet_length |
67 // is the total length of the packet, including both header and payload. | 78 // is the total length of the packet, including both header and payload. |
68 virtual void LogRtpHeader(PacketDirection direction, | 79 virtual void LogRtpHeader(PacketDirection direction, |
69 MediaType media_type, | 80 MediaType media_type, |
70 const uint8_t* header, | 81 const uint8_t* header, |
71 size_t packet_length) = 0; | 82 size_t packet_length) = 0; |
72 | 83 |
73 // Logs an incoming or outgoing RTCP packet. | 84 // Logs an incoming or outgoing RTCP packet. |
74 virtual void LogRtcpPacket(PacketDirection direction, | 85 virtual void LogRtcpPacket(PacketDirection direction, |
75 MediaType media_type, | 86 MediaType media_type, |
76 const uint8_t* packet, | 87 const uint8_t* packet, |
77 size_t length) = 0; | 88 size_t length) = 0; |
78 | 89 |
79 // Logs an audio playout event | 90 // Logs an audio playout event. |
80 virtual void LogAudioPlayout(uint32_t ssrc) = 0; | 91 virtual void LogAudioPlayout(uint32_t ssrc) = 0; |
81 | 92 |
82 // Logs a bitrate update from the bandwidth estimator based on packet loss. | 93 // Logs a bitrate update from the bandwidth estimator based on packet loss. |
83 virtual void LogBwePacketLossEvent(int32_t bitrate, | 94 virtual void LogBwePacketLossEvent(int32_t bitrate, |
84 uint8_t fraction_loss, | 95 uint8_t fraction_loss, |
85 int32_t total_packets) = 0; | 96 int32_t total_packets) = 0; |
86 | 97 |
87 // Reads an RtcEventLog file and returns true when reading was successful. | 98 // Reads an RtcEventLog file and returns true when reading was successful. |
88 // The result is stored in the given EventStream object. | 99 // The result is stored in the given EventStream object. |
| 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? |
89 static bool ParseRtcEventLog(const std::string& file_name, | 105 static bool ParseRtcEventLog(const std::string& file_name, |
90 rtclog::EventStream* result); | 106 rtclog::EventStream* result); |
91 }; | 107 }; |
92 | 108 |
93 } // namespace webrtc | 109 } // namespace webrtc |
94 | 110 |
95 #endif // WEBRTC_CALL_RTC_EVENT_LOG_H_ | 111 #endif // WEBRTC_CALL_RTC_EVENT_LOG_H_ |
OLD | NEW |