Chromium Code Reviews| Index: webrtc/call/rtc_event_log.cc |
| diff --git a/webrtc/call/rtc_event_log.cc b/webrtc/call/rtc_event_log.cc |
| index 97885cc066a609d79cf13b69beabc4874d838b57..ce06e8b2f2f8bf10d9e29bf925054ac008284564 100644 |
| --- a/webrtc/call/rtc_event_log.cc |
| +++ b/webrtc/call/rtc_event_log.cc |
| @@ -37,6 +37,8 @@ namespace webrtc { |
| class RtcEventLogImpl final : public RtcEventLog { |
| public: |
| void StartLogging(const std::string& file_name, int duration_ms) override {} |
| + int StartLogging(FILE* log_file) override { return -1; } |
| + int StartLogging(rtc::PlatformFile& log_file) override { return -1; } |
| void StopLogging(void) override {} |
| void LogVideoReceiveStreamConfig( |
| const VideoReceiveStream::Config& config) override {} |
| @@ -60,6 +62,8 @@ class RtcEventLogImpl final : public RtcEventLog { |
| RtcEventLogImpl(); |
| void StartLogging(const std::string& file_name, int duration_ms) override; |
| + int StartLogging(FILE* log_file) override; |
| + int StartLogging(rtc::PlatformFile& log_file) override; |
| void StopLogging() override; |
| void LogVideoReceiveStreamConfig( |
| const VideoReceiveStream::Config& config) override; |
| @@ -75,6 +79,9 @@ class RtcEventLogImpl final : public RtcEventLog { |
| void LogAudioPlayout(uint32_t ssrc) override; |
| private: |
| + // Starts logging. This function assumes the file_ has been opened succesfully |
| + // and that the start_time_us_ and _duration_us_ have been set. |
| + void StartLoggingLocked() EXCLUSIVE_LOCKS_REQUIRED(crit_); |
| // Stops logging and clears the stored data and buffers. |
| void StopLoggingLocked() EXCLUSIVE_LOCKS_REQUIRED(crit_); |
| // Adds a new event to the logfile if logging is active, or adds it to the |
| @@ -94,6 +101,8 @@ class RtcEventLogImpl final : public RtcEventLog { |
| rtc::CriticalSection crit_; |
| rtc::scoped_ptr<FileWrapper> file_ GUARDED_BY(crit_); |
| + rtc::PlatformFile platform_file_ GUARDED_BY(crit_); |
| + bool using_platform_file_ GUARDED_BY(crit_); |
| rtclog::EventStream stream_ GUARDED_BY(crit_); |
| std::deque<rtclog::Event> recent_log_events_ GUARDED_BY(crit_); |
| bool currently_logging_ GUARDED_BY(crit_); |
| @@ -145,6 +154,8 @@ rtclog::MediaType ConvertMediaType(MediaType media_type) { |
| // RtcEventLogImpl member functions. |
| RtcEventLogImpl::RtcEventLogImpl() |
| : file_(FileWrapper::Create()), |
| + platform_file_(static_cast<rtc::PlatformFile>(0)), |
|
the sun
2015/10/14 09:29:09
Use C++11 initialization (at member declaration).
ivoc
2015/10/14 12:23:47
Nice, was not familiar with this. I changed it for
|
| + using_platform_file_(false), |
| stream_(), |
| currently_logging_(false), |
| start_time_us_(0), |
| @@ -161,9 +172,53 @@ void RtcEventLogImpl::StartLogging(const std::string& file_name, |
| if (file_->OpenFile(file_name.c_str(), false) != 0) { |
| return; |
| } |
| - currently_logging_ = true; |
| start_time_us_ = clock_->TimeInMicroseconds(); |
| duration_us_ = static_cast<int64_t>(duration_ms) * 1000; |
| + StartLoggingLocked(); |
| +} |
| + |
| +int RtcEventLogImpl::StartLogging(FILE* log_file) { |
|
the sun
2015/10/14 09:29:09
Used?
ivoc
2015/10/14 12:23:47
Not currently, I left it in because I thought it m
|
| + rtc::CritScope lock(&crit_); |
| + |
| + if (currently_logging_) |
| + StopLoggingLocked(); |
| + RTC_DCHECK(log_file); |
| + if (file_->OpenFromFileHandle(log_file, true, false) != 0) { |
| + return -1; |
| + } |
| + // Set the start time and duration to keep logging for 10 minutes. |
| + start_time_us_ = clock_->TimeInMicroseconds(); |
| + duration_us_ = 10 * 60 * 1000000; |
| + StartLoggingLocked(); |
| + return 0; |
| +} |
| + |
| +int RtcEventLogImpl::StartLogging(rtc::PlatformFile& log_file) { |
| + rtc::CritScope lock(&crit_); |
| + |
| + if (currently_logging_) |
|
the sun
2015/10/14 09:29:09
please, always use braces
ivoc
2015/10/14 12:23:47
Done.
|
| + StopLoggingLocked(); |
| + |
|
the sun
2015/10/14 09:29:09
RTC_DCHECK(!using_platform_file)
ivoc
2015/10/14 12:23:47
Done.
|
| + FILE* file_stream = rtc::FdopenPlatformFileForWriting(log_file); |
| + if (!file_stream) { |
| + rtc::ClosePlatformFile(log_file); |
| + return -1; |
| + } |
| + |
| + if (file_->OpenFromFileHandle(file_stream, true, false) != 0) { |
| + rtc::ClosePlatformFile(log_file); |
| + return -1; |
| + } |
| + using_platform_file_ = true; |
| + // Set the start time and duration to keep logging for 10 minutes. |
| + start_time_us_ = clock_->TimeInMicroseconds(); |
| + duration_us_ = 10 * 60 * 1000000; |
| + StartLoggingLocked(); |
| + return 0; |
| +} |
| + |
| +void RtcEventLogImpl::StartLoggingLocked() { |
| + currently_logging_ = true; |
| // Write all the recent events to the log file, ignoring any old events. |
| for (auto& event : recent_log_events_) { |
| if (event.timestamp_us() >= start_time_us_ - recent_log_duration_us) { |
| @@ -339,6 +394,10 @@ void RtcEventLogImpl::StopLoggingLocked() { |
| RTC_DCHECK(file_->Open()); |
| StoreToFile(&event); |
| file_->CloseFile(); |
| + if (using_platform_file_) { |
| + rtc::ClosePlatformFile(platform_file_); |
|
the sun
2015/10/14 09:29:09
platform_file_ is never set. Also, you don't need
ivoc
2015/10/14 12:23:47
Good points, have updated.
|
| + using_platform_file_ = false; |
| + } |
| } |
| RTC_DCHECK(!file_->Open()); |
| stream_.Clear(); |