| 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 <limits> |
| 14 | 15 |
| 15 #include "webrtc/base/checks.h" | 16 #include "webrtc/base/checks.h" |
| 16 #include "webrtc/base/criticalsection.h" | 17 #include "webrtc/base/criticalsection.h" |
| 17 #include "webrtc/base/thread_annotations.h" | 18 #include "webrtc/base/thread_annotations.h" |
| 18 #include "webrtc/call.h" | 19 #include "webrtc/call.h" |
| 19 #include "webrtc/modules/rtp_rtcp/source/byte_io.h" | 20 #include "webrtc/modules/rtp_rtcp/source/byte_io.h" |
| 20 #include "webrtc/system_wrappers/interface/clock.h" | 21 #include "webrtc/system_wrappers/interface/clock.h" |
| 21 #include "webrtc/system_wrappers/interface/file_wrapper.h" | 22 #include "webrtc/system_wrappers/interface/file_wrapper.h" |
| 22 | 23 |
| 23 #ifdef ENABLE_RTC_EVENT_LOG | 24 #ifdef ENABLE_RTC_EVENT_LOG |
| 24 // Files generated at build-time by the protobuf compiler. | 25 // Files generated at build-time by the protobuf compiler. |
| 25 #ifdef WEBRTC_ANDROID_PLATFORM_BUILD | 26 #ifdef WEBRTC_ANDROID_PLATFORM_BUILD |
| 26 #include "external/webrtc/webrtc/call/rtc_event_log.pb.h" | 27 #include "external/webrtc/webrtc/call/rtc_event_log.pb.h" |
| 27 #else | 28 #else |
| 28 #include "webrtc/call/rtc_event_log.pb.h" | 29 #include "webrtc/call/rtc_event_log.pb.h" |
| 29 #endif | 30 #endif |
| 30 #endif | 31 #endif |
| 31 | 32 |
| 32 namespace webrtc { | 33 namespace webrtc { |
| 33 | 34 |
| 34 #ifndef ENABLE_RTC_EVENT_LOG | 35 #ifndef ENABLE_RTC_EVENT_LOG |
| 35 | 36 |
| 36 // No-op implementation if flag is not set. | 37 // No-op implementation if flag is not set. |
| 37 class RtcEventLogImpl final : public RtcEventLog { | 38 class RtcEventLogImpl final : public RtcEventLog { |
| 38 public: | 39 public: |
| 39 void StartLogging(const std::string& file_name, int duration_ms) override {} | 40 void StartLogging(const std::string& file_name, int duration_ms) override {} |
| 41 int StartLogging(FILE* log_file) override { return -1; } |
| 40 void StopLogging(void) override {} | 42 void StopLogging(void) override {} |
| 41 void LogVideoReceiveStreamConfig( | 43 void LogVideoReceiveStreamConfig( |
| 42 const VideoReceiveStream::Config& config) override {} | 44 const VideoReceiveStream::Config& config) override {} |
| 43 void LogVideoSendStreamConfig( | 45 void LogVideoSendStreamConfig( |
| 44 const VideoSendStream::Config& config) override {} | 46 const VideoSendStream::Config& config) override {} |
| 45 void LogRtpHeader(bool incoming, | 47 void LogRtpHeader(bool incoming, |
| 46 MediaType media_type, | 48 MediaType media_type, |
| 47 const uint8_t* header, | 49 const uint8_t* header, |
| 48 size_t packet_length) override {} | 50 size_t packet_length) override {} |
| 49 void LogRtcpPacket(bool incoming, | 51 void LogRtcpPacket(bool incoming, |
| 50 MediaType media_type, | 52 MediaType media_type, |
| 51 const uint8_t* packet, | 53 const uint8_t* packet, |
| 52 size_t length) override {} | 54 size_t length) override {} |
| 53 void LogAudioPlayout(uint32_t ssrc) override {} | 55 void LogAudioPlayout(uint32_t ssrc) override {} |
| 54 }; | 56 }; |
| 55 | 57 |
| 56 #else // ENABLE_RTC_EVENT_LOG is defined | 58 #else // ENABLE_RTC_EVENT_LOG is defined |
| 57 | 59 |
| 58 class RtcEventLogImpl final : public RtcEventLog { | 60 class RtcEventLogImpl final : public RtcEventLog { |
| 59 public: | 61 public: |
| 60 RtcEventLogImpl(); | 62 RtcEventLogImpl(); |
| 61 | 63 |
| 62 void StartLogging(const std::string& file_name, int duration_ms) override; | 64 void StartLogging(const std::string& file_name, int duration_ms) override; |
| 65 int StartLogging(FILE* log_file) override; |
| 63 void StopLogging() override; | 66 void StopLogging() override; |
| 64 void LogVideoReceiveStreamConfig( | 67 void LogVideoReceiveStreamConfig( |
| 65 const VideoReceiveStream::Config& config) override; | 68 const VideoReceiveStream::Config& config) override; |
| 66 void LogVideoSendStreamConfig(const VideoSendStream::Config& config) override; | 69 void LogVideoSendStreamConfig(const VideoSendStream::Config& config) override; |
| 67 void LogRtpHeader(bool incoming, | 70 void LogRtpHeader(bool incoming, |
| 68 MediaType media_type, | 71 MediaType media_type, |
| 69 const uint8_t* header, | 72 const uint8_t* header, |
| 70 size_t packet_length) override; | 73 size_t packet_length) override; |
| 71 void LogRtcpPacket(bool incoming, | 74 void LogRtcpPacket(bool incoming, |
| 72 MediaType media_type, | 75 MediaType media_type, |
| 73 const uint8_t* packet, | 76 const uint8_t* packet, |
| 74 size_t length) override; | 77 size_t length) override; |
| 75 void LogAudioPlayout(uint32_t ssrc) override; | 78 void LogAudioPlayout(uint32_t ssrc) override; |
| 76 | 79 |
| 77 private: | 80 private: |
| 81 // Starts logging. This function assumes the file_ has been opened succesfully |
| 82 // and that the start_time_us_ and _duration_us_ have been set. |
| 83 void StartLoggingLocked() EXCLUSIVE_LOCKS_REQUIRED(crit_); |
| 78 // Stops logging and clears the stored data and buffers. | 84 // Stops logging and clears the stored data and buffers. |
| 79 void StopLoggingLocked() EXCLUSIVE_LOCKS_REQUIRED(crit_); | 85 void StopLoggingLocked() EXCLUSIVE_LOCKS_REQUIRED(crit_); |
| 80 // Adds a new event to the logfile if logging is active, or adds it to the | 86 // Adds a new event to the logfile if logging is active, or adds it to the |
| 81 // list of recent log events otherwise. | 87 // list of recent log events otherwise. |
| 82 void HandleEvent(rtclog::Event* event) EXCLUSIVE_LOCKS_REQUIRED(crit_); | 88 void HandleEvent(rtclog::Event* event) EXCLUSIVE_LOCKS_REQUIRED(crit_); |
| 83 // Writes the event to the file. Note that this will destroy the state of the | 89 // Writes the event to the file. Note that this will destroy the state of the |
| 84 // input argument. | 90 // input argument. |
| 85 void StoreToFile(rtclog::Event* event) EXCLUSIVE_LOCKS_REQUIRED(crit_); | 91 void StoreToFile(rtclog::Event* event) EXCLUSIVE_LOCKS_REQUIRED(crit_); |
| 86 // Adds the event to the list of recent events, and removes any events that | 92 // Adds the event to the list of recent events, and removes any events that |
| 87 // are too old and no longer fall in the time window. | 93 // are too old and no longer fall in the time window. |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 | 158 |
| 153 void RtcEventLogImpl::StartLogging(const std::string& file_name, | 159 void RtcEventLogImpl::StartLogging(const std::string& file_name, |
| 154 int duration_ms) { | 160 int duration_ms) { |
| 155 rtc::CritScope lock(&crit_); | 161 rtc::CritScope lock(&crit_); |
| 156 if (currently_logging_) { | 162 if (currently_logging_) { |
| 157 StopLoggingLocked(); | 163 StopLoggingLocked(); |
| 158 } | 164 } |
| 159 if (file_->OpenFile(file_name.c_str(), false) != 0) { | 165 if (file_->OpenFile(file_name.c_str(), false) != 0) { |
| 160 return; | 166 return; |
| 161 } | 167 } |
| 162 currently_logging_ = true; | |
| 163 start_time_us_ = clock_->TimeInMicroseconds(); | 168 start_time_us_ = clock_->TimeInMicroseconds(); |
| 164 duration_us_ = static_cast<int64_t>(duration_ms) * 1000; | 169 duration_us_ = static_cast<int64_t>(duration_ms) * 1000; |
| 170 StartLoggingLocked(); |
| 171 } |
| 172 |
| 173 int RtcEventLogImpl::StartLogging(FILE* log_file) { |
| 174 rtc::CritScope lock(&crit_); |
| 175 |
| 176 if (currently_logging_) |
| 177 StopLoggingLocked(); |
| 178 RTC_DCHECK(log_file); |
| 179 if (file_->OpenFromFileHandle(log_file, true, false) != 0) { |
| 180 return -1; |
| 181 } |
| 182 // Set the start time and duration to keep logging for 10 minutes. |
| 183 start_time_us_ = clock_->TimeInMicroseconds(); |
| 184 duration_us_ = 10 * 60 * 1000000; |
| 185 StartLoggingLocked(); |
| 186 return 0; |
| 187 } |
| 188 |
| 189 void RtcEventLogImpl::StartLoggingLocked() { |
| 190 currently_logging_ = true; |
| 165 // Write all the recent events to the log file, ignoring any old events. | 191 // Write all the recent events to the log file, ignoring any old events. |
| 166 for (auto& event : recent_log_events_) { | 192 for (auto& event : recent_log_events_) { |
| 167 if (event.timestamp_us() >= start_time_us_ - recent_log_duration_us) { | 193 if (event.timestamp_us() >= start_time_us_ - recent_log_duration_us) { |
| 168 StoreToFile(&event); | 194 StoreToFile(&event); |
| 169 } | 195 } |
| 170 } | 196 } |
| 171 recent_log_events_.clear(); | 197 recent_log_events_.clear(); |
| 172 // Write a LOG_START event to the file. | 198 // Write a LOG_START event to the file. |
| 173 rtclog::Event start_event; | 199 rtclog::Event start_event; |
| 174 start_event.set_timestamp_us(start_time_us_); | 200 start_event.set_timestamp_us(start_time_us_); |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 396 return result->ParseFromString(dump_buffer); | 422 return result->ParseFromString(dump_buffer); |
| 397 } | 423 } |
| 398 | 424 |
| 399 #endif // ENABLE_RTC_EVENT_LOG | 425 #endif // ENABLE_RTC_EVENT_LOG |
| 400 | 426 |
| 401 // RtcEventLog member functions. | 427 // RtcEventLog member functions. |
| 402 rtc::scoped_ptr<RtcEventLog> RtcEventLog::Create() { | 428 rtc::scoped_ptr<RtcEventLog> RtcEventLog::Create() { |
| 403 return rtc::scoped_ptr<RtcEventLog>(new RtcEventLogImpl()); | 429 return rtc::scoped_ptr<RtcEventLog>(new RtcEventLogImpl()); |
| 404 } | 430 } |
| 405 } // namespace webrtc | 431 } // namespace webrtc |
| OLD | NEW |