Chromium Code Reviews| 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 #include "webrtc/call/rtc_event_log.h" | 11 #include "webrtc/call/rtc_event_log.h" |
| 12 | 12 |
| 13 #include <deque> | 13 #include <deque> |
| 14 #include <vector> | 14 #include <vector> |
| 15 | 15 |
| 16 #include "webrtc/base/checks.h" | 16 #include "webrtc/base/checks.h" |
| 17 #include "webrtc/base/criticalsection.h" | 17 #include "webrtc/base/criticalsection.h" |
| 18 #include "webrtc/base/thread_annotations.h" | 18 #include "webrtc/base/thread_annotations.h" |
| 19 #include "webrtc/base/thread_checker.h" | |
| 19 #include "webrtc/call.h" | 20 #include "webrtc/call.h" |
| 20 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" | 21 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" |
| 21 #include "webrtc/modules/rtp_rtcp/source/byte_io.h" | 22 #include "webrtc/modules/rtp_rtcp/source/byte_io.h" |
| 22 #include "webrtc/modules/rtp_rtcp/source/rtcp_utility.h" | 23 #include "webrtc/modules/rtp_rtcp/source/rtcp_utility.h" |
| 23 #include "webrtc/system_wrappers/include/clock.h" | 24 #include "webrtc/system_wrappers/include/clock.h" |
| 24 #include "webrtc/system_wrappers/include/file_wrapper.h" | 25 #include "webrtc/system_wrappers/include/file_wrapper.h" |
| 25 | 26 |
| 26 #ifdef ENABLE_RTC_EVENT_LOG | 27 #ifdef ENABLE_RTC_EVENT_LOG |
| 27 // Files generated at build-time by the protobuf compiler. | 28 // Files generated at build-time by the protobuf compiler. |
| 28 #ifdef WEBRTC_ANDROID_PLATFORM_BUILD | 29 #ifdef WEBRTC_ANDROID_PLATFORM_BUILD |
| 29 #include "external/webrtc/webrtc/call/rtc_event_log.pb.h" | 30 #include "external/webrtc/webrtc/call/rtc_event_log.pb.h" |
| 30 #else | 31 #else |
| 31 #include "webrtc/call/rtc_event_log.pb.h" | 32 #include "webrtc/call/rtc_event_log.pb.h" |
| 32 #endif | 33 #endif |
| 33 #endif | 34 #endif |
| 34 | 35 |
| 35 namespace webrtc { | 36 namespace webrtc { |
| 36 | 37 |
| 37 #ifndef ENABLE_RTC_EVENT_LOG | 38 #ifndef ENABLE_RTC_EVENT_LOG |
| 38 | 39 |
| 39 // No-op implementation if flag is not set. | 40 // No-op implementation if flag is not set. |
| 40 class RtcEventLogImpl final : public RtcEventLog { | 41 class RtcEventLogImpl final : public RtcEventLog { |
| 41 public: | 42 public: |
| 42 void SetBufferDuration(int64_t buffer_duration_us) override {} | 43 void SetBufferDuration(int64_t buffer_duration_us) override {} |
| 43 void StartLogging(const std::string& file_name, int duration_ms) override {} | 44 void StartLogging(const std::string& file_name, int duration_ms) override {} |
| 44 bool StartLogging(rtc::PlatformFile log_file) override { return false; } | 45 bool StartLogging(rtc::PlatformFile log_file, |
| 46 int64_t max_size_bytes) override { | |
| 47 return false; | |
| 48 } | |
| 45 void StopLogging(void) override {} | 49 void StopLogging(void) override {} |
| 46 void LogVideoReceiveStreamConfig( | 50 void LogVideoReceiveStreamConfig( |
| 47 const VideoReceiveStream::Config& config) override {} | 51 const VideoReceiveStream::Config& config) override {} |
| 48 void LogVideoSendStreamConfig( | 52 void LogVideoSendStreamConfig( |
| 49 const VideoSendStream::Config& config) override {} | 53 const VideoSendStream::Config& config) override {} |
| 50 void LogRtpHeader(PacketDirection direction, | 54 void LogRtpHeader(PacketDirection direction, |
| 51 MediaType media_type, | 55 MediaType media_type, |
| 52 const uint8_t* header, | 56 const uint8_t* header, |
| 53 size_t packet_length) override {} | 57 size_t packet_length) override {} |
| 54 void LogRtcpPacket(PacketDirection direction, | 58 void LogRtcpPacket(PacketDirection direction, |
| 55 MediaType media_type, | 59 MediaType media_type, |
| 56 const uint8_t* packet, | 60 const uint8_t* packet, |
| 57 size_t length) override {} | 61 size_t length) override {} |
| 58 void LogAudioPlayout(uint32_t ssrc) override {} | 62 void LogAudioPlayout(uint32_t ssrc) override {} |
| 59 void LogBwePacketLossEvent(int32_t bitrate, | 63 void LogBwePacketLossEvent(int32_t bitrate, |
| 60 uint8_t fraction_loss, | 64 uint8_t fraction_loss, |
| 61 int32_t total_packets) override {} | 65 int32_t total_packets) override {} |
| 62 }; | 66 }; |
| 63 | 67 |
| 64 #else // ENABLE_RTC_EVENT_LOG is defined | 68 #else // ENABLE_RTC_EVENT_LOG is defined |
| 65 | 69 |
| 66 class RtcEventLogImpl final : public RtcEventLog { | 70 class RtcEventLogImpl final : public RtcEventLog { |
| 67 public: | 71 public: |
| 68 RtcEventLogImpl(); | 72 RtcEventLogImpl(); |
| 73 ~RtcEventLogImpl(); | |
| 69 | 74 |
| 70 void SetBufferDuration(int64_t buffer_duration_us) override; | 75 void SetBufferDuration(int64_t buffer_duration_us) override; |
| 71 void StartLogging(const std::string& file_name, int duration_ms) override; | 76 void StartLogging(const std::string& file_name, int duration_ms) override; |
| 72 bool StartLogging(rtc::PlatformFile log_file) override; | 77 bool StartLogging(rtc::PlatformFile log_file, |
| 78 int64_t max_size_bytes) override; | |
| 73 void StopLogging() override; | 79 void StopLogging() override; |
| 74 void LogVideoReceiveStreamConfig( | 80 void LogVideoReceiveStreamConfig( |
| 75 const VideoReceiveStream::Config& config) override; | 81 const VideoReceiveStream::Config& config) override; |
| 76 void LogVideoSendStreamConfig(const VideoSendStream::Config& config) override; | 82 void LogVideoSendStreamConfig(const VideoSendStream::Config& config) override; |
| 77 void LogRtpHeader(PacketDirection direction, | 83 void LogRtpHeader(PacketDirection direction, |
| 78 MediaType media_type, | 84 MediaType media_type, |
| 79 const uint8_t* header, | 85 const uint8_t* header, |
| 80 size_t packet_length) override; | 86 size_t packet_length) override; |
| 81 void LogRtcpPacket(PacketDirection direction, | 87 void LogRtcpPacket(PacketDirection direction, |
| 82 MediaType media_type, | 88 MediaType media_type, |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 97 // list of recent log events otherwise. | 103 // list of recent log events otherwise. |
| 98 void HandleEvent(rtclog::Event* event) EXCLUSIVE_LOCKS_REQUIRED(crit_); | 104 void HandleEvent(rtclog::Event* event) EXCLUSIVE_LOCKS_REQUIRED(crit_); |
| 99 // Writes the event to the file. Note that this will destroy the state of the | 105 // Writes the event to the file. Note that this will destroy the state of the |
| 100 // input argument. | 106 // input argument. |
| 101 void StoreToFile(rtclog::Event* event) EXCLUSIVE_LOCKS_REQUIRED(crit_); | 107 void StoreToFile(rtclog::Event* event) EXCLUSIVE_LOCKS_REQUIRED(crit_); |
| 102 // Adds the event to the list of recent events, and removes any events that | 108 // Adds the event to the list of recent events, and removes any events that |
| 103 // are too old and no longer fall in the time window. | 109 // are too old and no longer fall in the time window. |
| 104 void AddRecentEvent(const rtclog::Event& event) | 110 void AddRecentEvent(const rtclog::Event& event) |
| 105 EXCLUSIVE_LOCKS_REQUIRED(crit_); | 111 EXCLUSIVE_LOCKS_REQUIRED(crit_); |
| 106 | 112 |
| 113 rtc::ThreadChecker thread_checker_; | |
| 107 rtc::CriticalSection crit_; | 114 rtc::CriticalSection crit_; |
| 108 rtc::scoped_ptr<FileWrapper> file_ GUARDED_BY(crit_) = | 115 rtc::scoped_ptr<FileWrapper> file_ GUARDED_BY(crit_) = |
| 109 rtc::scoped_ptr<FileWrapper>(FileWrapper::Create()); | 116 rtc::scoped_ptr<FileWrapper>(FileWrapper::Create()); |
| 110 rtc::PlatformFile platform_file_ GUARDED_BY(crit_) = | 117 rtc::PlatformFile platform_file_ GUARDED_BY(crit_) = |
| 111 rtc::kInvalidPlatformFileValue; | 118 rtc::kInvalidPlatformFileValue; |
| 112 rtclog::EventStream stream_ GUARDED_BY(crit_); | 119 rtclog::EventStream stream_ GUARDED_BY(crit_); |
| 113 std::deque<rtclog::Event> recent_log_events_ GUARDED_BY(crit_); | 120 std::deque<rtclog::Event> recent_log_events_ GUARDED_BY(crit_); |
| 114 std::vector<rtclog::Event> config_events_ GUARDED_BY(crit_); | 121 std::vector<rtclog::Event> config_events_ GUARDED_BY(crit_); |
| 115 | 122 |
| 116 // Microseconds to record log events, before starting the actual log. | 123 // Microseconds to record log events, before starting the actual log. |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 173 | 180 |
| 174 // RtcEventLogImpl member functions. | 181 // RtcEventLogImpl member functions. |
| 175 RtcEventLogImpl::RtcEventLogImpl() | 182 RtcEventLogImpl::RtcEventLogImpl() |
| 176 : file_(FileWrapper::Create()), | 183 : file_(FileWrapper::Create()), |
| 177 stream_(), | 184 stream_(), |
| 178 buffer_duration_us_(10000000), | 185 buffer_duration_us_(10000000), |
| 179 currently_logging_(false), | 186 currently_logging_(false), |
| 180 start_time_us_(0), | 187 start_time_us_(0), |
| 181 duration_us_(0), | 188 duration_us_(0), |
| 182 clock_(Clock::GetRealTimeClock()) { | 189 clock_(Clock::GetRealTimeClock()) { |
| 190 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | |
| 191 } | |
| 192 | |
| 193 RtcEventLogImpl::~RtcEventLogImpl() { | |
| 194 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | |
| 183 } | 195 } |
| 184 | 196 |
| 185 void RtcEventLogImpl::SetBufferDuration(int64_t buffer_duration_us) { | 197 void RtcEventLogImpl::SetBufferDuration(int64_t buffer_duration_us) { |
| 186 rtc::CritScope lock(&crit_); | 198 rtc::CritScope lock(&crit_); |
| 187 buffer_duration_us_ = buffer_duration_us; | 199 buffer_duration_us_ = buffer_duration_us; |
| 188 } | 200 } |
| 189 | 201 |
| 190 void RtcEventLogImpl::StartLogging(const std::string& file_name, | 202 void RtcEventLogImpl::StartLogging(const std::string& file_name, |
| 191 int duration_ms) { | 203 int duration_ms) { |
| 192 rtc::CritScope lock(&crit_); | 204 rtc::CritScope lock(&crit_); |
| 193 if (currently_logging_) { | 205 if (currently_logging_) { |
| 194 StopLoggingLocked(); | 206 StopLoggingLocked(); |
| 195 } | 207 } |
| 196 if (file_->OpenFile(file_name.c_str(), false) != 0) { | 208 if (file_->OpenFile(file_name.c_str(), false) != 0) { |
| 197 return; | 209 return; |
| 198 } | 210 } |
| 199 start_time_us_ = clock_->TimeInMicroseconds(); | 211 start_time_us_ = clock_->TimeInMicroseconds(); |
| 200 duration_us_ = static_cast<int64_t>(duration_ms) * 1000; | 212 duration_us_ = static_cast<int64_t>(duration_ms) * 1000; |
| 201 StartLoggingLocked(); | 213 StartLoggingLocked(); |
| 202 } | 214 } |
| 203 | 215 |
| 204 bool RtcEventLogImpl::StartLogging(rtc::PlatformFile log_file) { | 216 bool RtcEventLogImpl::StartLogging(rtc::PlatformFile log_file, |
| 217 int64_t max_size_bytes) { | |
|
stefan-webrtc
2016/03/11 10:11:53
Can we break this change out to a separate CL, or
terelius
2016/03/11 12:30:44
I think the total amount of work will decrease by
ivoc
2016/03/16 17:00:32
The max size and moving to call are pretty indepen
stefan-webrtc
2016/03/21 13:25:47
Thanks.
| |
| 205 rtc::CritScope lock(&crit_); | 218 rtc::CritScope lock(&crit_); |
| 206 | 219 |
| 207 if (currently_logging_) { | 220 if (currently_logging_) { |
| 208 StopLoggingLocked(); | 221 StopLoggingLocked(); |
| 209 } | 222 } |
| 210 RTC_DCHECK(platform_file_ == rtc::kInvalidPlatformFileValue); | 223 RTC_DCHECK(platform_file_ == rtc::kInvalidPlatformFileValue); |
| 211 | 224 |
| 212 FILE* file_stream = rtc::FdopenPlatformFileForWriting(log_file); | 225 FILE* file_stream = rtc::FdopenPlatformFileForWriting(log_file); |
| 213 if (!file_stream) { | 226 if (!file_stream) { |
| 214 rtc::ClosePlatformFile(log_file); | 227 rtc::ClosePlatformFile(log_file); |
| (...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 514 } | 527 } |
| 515 | 528 |
| 516 #endif // ENABLE_RTC_EVENT_LOG | 529 #endif // ENABLE_RTC_EVENT_LOG |
| 517 | 530 |
| 518 // RtcEventLog member functions. | 531 // RtcEventLog member functions. |
| 519 rtc::scoped_ptr<RtcEventLog> RtcEventLog::Create() { | 532 rtc::scoped_ptr<RtcEventLog> RtcEventLog::Create() { |
| 520 return rtc::scoped_ptr<RtcEventLog>(new RtcEventLogImpl()); | 533 return rtc::scoped_ptr<RtcEventLog>(new RtcEventLogImpl()); |
| 521 } | 534 } |
| 522 | 535 |
| 523 } // namespace webrtc | 536 } // namespace webrtc |
| OLD | NEW |