Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(198)

Side by Side Diff: webrtc/call/rtc_event_log.cc

Issue 1374253002: Added functions on libjingle API to start and stop the recording of an RtcEventLog. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Addressed comments from the sun. Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« webrtc/call/rtc_event_log.h ('K') | « webrtc/call/rtc_event_log.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
(...skipping 19 matching lines...) Expand all
30 #endif 30 #endif
31 31
32 namespace webrtc { 32 namespace webrtc {
33 33
34 #ifndef ENABLE_RTC_EVENT_LOG 34 #ifndef ENABLE_RTC_EVENT_LOG
35 35
36 // No-op implementation if flag is not set. 36 // No-op implementation if flag is not set.
37 class RtcEventLogImpl final : public RtcEventLog { 37 class RtcEventLogImpl final : public RtcEventLog {
38 public: 38 public:
39 void StartLogging(const std::string& file_name, int duration_ms) override {} 39 void StartLogging(const std::string& file_name, int duration_ms) override {}
40 bool StartLogging(rtc::PlatformFile& log_file) override { return false; }
40 void StopLogging(void) override {} 41 void StopLogging(void) override {}
41 void LogVideoReceiveStreamConfig( 42 void LogVideoReceiveStreamConfig(
42 const VideoReceiveStream::Config& config) override {} 43 const VideoReceiveStream::Config& config) override {}
43 void LogVideoSendStreamConfig( 44 void LogVideoSendStreamConfig(
44 const VideoSendStream::Config& config) override {} 45 const VideoSendStream::Config& config) override {}
45 void LogRtpHeader(bool incoming, 46 void LogRtpHeader(bool incoming,
46 MediaType media_type, 47 MediaType media_type,
47 const uint8_t* header, 48 const uint8_t* header,
48 size_t packet_length) override {} 49 size_t packet_length) override {}
49 void LogRtcpPacket(bool incoming, 50 void LogRtcpPacket(bool incoming,
50 MediaType media_type, 51 MediaType media_type,
51 const uint8_t* packet, 52 const uint8_t* packet,
52 size_t length) override {} 53 size_t length) override {}
53 void LogAudioPlayout(uint32_t ssrc) override {} 54 void LogAudioPlayout(uint32_t ssrc) override {}
54 }; 55 };
55 56
56 #else // ENABLE_RTC_EVENT_LOG is defined 57 #else // ENABLE_RTC_EVENT_LOG is defined
57 58
58 class RtcEventLogImpl final : public RtcEventLog { 59 class RtcEventLogImpl final : public RtcEventLog {
59 public: 60 public:
60 RtcEventLogImpl();
61
62 void StartLogging(const std::string& file_name, int duration_ms) override; 61 void StartLogging(const std::string& file_name, int duration_ms) override;
62 bool StartLogging(rtc::PlatformFile& log_file) override;
63 void StopLogging() override; 63 void StopLogging() override;
64 void LogVideoReceiveStreamConfig( 64 void LogVideoReceiveStreamConfig(
65 const VideoReceiveStream::Config& config) override; 65 const VideoReceiveStream::Config& config) override;
66 void LogVideoSendStreamConfig(const VideoSendStream::Config& config) override; 66 void LogVideoSendStreamConfig(const VideoSendStream::Config& config) override;
67 void LogRtpHeader(bool incoming, 67 void LogRtpHeader(bool incoming,
68 MediaType media_type, 68 MediaType media_type,
69 const uint8_t* header, 69 const uint8_t* header,
70 size_t packet_length) override; 70 size_t packet_length) override;
71 void LogRtcpPacket(bool incoming, 71 void LogRtcpPacket(bool incoming,
72 MediaType media_type, 72 MediaType media_type,
73 const uint8_t* packet, 73 const uint8_t* packet,
74 size_t length) override; 74 size_t length) override;
75 void LogAudioPlayout(uint32_t ssrc) override; 75 void LogAudioPlayout(uint32_t ssrc) override;
76 76
77 private: 77 private:
78 // Starts logging. This function assumes the file_ has been opened succesfully
79 // and that the start_time_us_ and _duration_us_ have been set.
80 void StartLoggingLocked() EXCLUSIVE_LOCKS_REQUIRED(crit_);
78 // Stops logging and clears the stored data and buffers. 81 // Stops logging and clears the stored data and buffers.
79 void StopLoggingLocked() EXCLUSIVE_LOCKS_REQUIRED(crit_); 82 void StopLoggingLocked() EXCLUSIVE_LOCKS_REQUIRED(crit_);
80 // Adds a new event to the logfile if logging is active, or adds it to the 83 // Adds a new event to the logfile if logging is active, or adds it to the
81 // list of recent log events otherwise. 84 // list of recent log events otherwise.
82 void HandleEvent(rtclog::Event* event) EXCLUSIVE_LOCKS_REQUIRED(crit_); 85 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 86 // Writes the event to the file. Note that this will destroy the state of the
84 // input argument. 87 // input argument.
85 void StoreToFile(rtclog::Event* event) EXCLUSIVE_LOCKS_REQUIRED(crit_); 88 void StoreToFile(rtclog::Event* event) EXCLUSIVE_LOCKS_REQUIRED(crit_);
86 // Adds the event to the list of recent events, and removes any events that 89 // 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. 90 // are too old and no longer fall in the time window.
88 void AddRecentEvent(const rtclog::Event& event) 91 void AddRecentEvent(const rtclog::Event& event)
89 EXCLUSIVE_LOCKS_REQUIRED(crit_); 92 EXCLUSIVE_LOCKS_REQUIRED(crit_);
90 93
91 // Amount of time in microseconds to record log events, before starting the 94 // Amount of time in microseconds to record log events, before starting the
92 // actual log. 95 // actual log.
93 const int recent_log_duration_us = 10000000; 96 const int recent_log_duration_us = 10000000;
94 97
95 rtc::CriticalSection crit_; 98 rtc::CriticalSection crit_;
96 rtc::scoped_ptr<FileWrapper> file_ GUARDED_BY(crit_); 99 rtc::scoped_ptr<FileWrapper> file_ GUARDED_BY(crit_) =
100 rtc::scoped_ptr<FileWrapper>(FileWrapper::Create());
101 rtc::PlatformFile platform_file_ GUARDED_BY(crit_) =
102 rtc::kInvalidPlatformFileValue;
97 rtclog::EventStream stream_ GUARDED_BY(crit_); 103 rtclog::EventStream stream_ GUARDED_BY(crit_);
98 std::deque<rtclog::Event> recent_log_events_ GUARDED_BY(crit_); 104 std::deque<rtclog::Event> recent_log_events_ GUARDED_BY(crit_);
99 bool currently_logging_ GUARDED_BY(crit_); 105 bool currently_logging_ GUARDED_BY(crit_) = false;
100 int64_t start_time_us_ GUARDED_BY(crit_); 106 int64_t start_time_us_ GUARDED_BY(crit_) = 0;
101 int64_t duration_us_ GUARDED_BY(crit_); 107 int64_t duration_us_ GUARDED_BY(crit_) = 0;
102 const Clock* const clock_; 108 const Clock* const clock_ = Clock::GetRealTimeClock();
103 }; 109 };
104 110
105 namespace { 111 namespace {
106 // The functions in this namespace convert enums from the runtime format 112 // The functions in this namespace convert enums from the runtime format
107 // that the rest of the WebRtc project can use, to the corresponding 113 // that the rest of the WebRtc project can use, to the corresponding
108 // serialized enum which is defined by the protobuf. 114 // serialized enum which is defined by the protobuf.
109 115
110 // Do not add default return values to the conversion functions in this 116 // Do not add default return values to the conversion functions in this
111 // unnamed namespace. The intention is to make the compiler warn if anyone 117 // unnamed namespace. The intention is to make the compiler warn if anyone
112 // adds unhandled new events/modes/etc. 118 // adds unhandled new events/modes/etc.
(...skipping 23 matching lines...) Expand all
136 case MediaType::DATA: 142 case MediaType::DATA:
137 return rtclog::MediaType::DATA; 143 return rtclog::MediaType::DATA;
138 } 144 }
139 RTC_NOTREACHED(); 145 RTC_NOTREACHED();
140 return rtclog::ANY; 146 return rtclog::ANY;
141 } 147 }
142 148
143 } // namespace 149 } // namespace
144 150
145 // RtcEventLogImpl member functions. 151 // RtcEventLogImpl member functions.
146 RtcEventLogImpl::RtcEventLogImpl()
147 : file_(FileWrapper::Create()),
148 stream_(),
149 currently_logging_(false),
150 start_time_us_(0),
151 duration_us_(0),
152 clock_(Clock::GetRealTimeClock()) {
153 }
154 152
155 void RtcEventLogImpl::StartLogging(const std::string& file_name, 153 void RtcEventLogImpl::StartLogging(const std::string& file_name,
156 int duration_ms) { 154 int duration_ms) {
157 rtc::CritScope lock(&crit_); 155 rtc::CritScope lock(&crit_);
158 if (currently_logging_) { 156 if (currently_logging_) {
159 StopLoggingLocked(); 157 StopLoggingLocked();
160 } 158 }
161 if (file_->OpenFile(file_name.c_str(), false) != 0) { 159 if (file_->OpenFile(file_name.c_str(), false) != 0) {
162 return; 160 return;
163 } 161 }
164 currently_logging_ = true;
165 start_time_us_ = clock_->TimeInMicroseconds(); 162 start_time_us_ = clock_->TimeInMicroseconds();
166 duration_us_ = static_cast<int64_t>(duration_ms) * 1000; 163 duration_us_ = static_cast<int64_t>(duration_ms) * 1000;
164 StartLoggingLocked();
165 }
166
167 bool RtcEventLogImpl::StartLogging(rtc::PlatformFile& log_file) {
168 rtc::CritScope lock(&crit_);
169
170 if (currently_logging_) {
171 StopLoggingLocked();
172 }
173 RTC_DCHECK(platform_file_ == rtc::kInvalidPlatformFileValue);
174
175 FILE* file_stream = rtc::FdopenPlatformFileForWriting(log_file);
176 if (!file_stream) {
177 rtc::ClosePlatformFile(log_file);
178 return false;
179 }
180
181 if (file_->OpenFromFileHandle(file_stream, true, false) != 0) {
182 rtc::ClosePlatformFile(log_file);
183 return false;
184 }
185 platform_file_ = log_file;
186 // Set the start time and duration to keep logging for 10 minutes.
187 start_time_us_ = clock_->TimeInMicroseconds();
188 duration_us_ = 10 * 60 * 1000000;
189 StartLoggingLocked();
190 return true;
191 }
192
193 void RtcEventLogImpl::StartLoggingLocked() {
194 currently_logging_ = true;
167 // Write all the recent events to the log file, ignoring any old events. 195 // Write all the recent events to the log file, ignoring any old events.
168 for (auto& event : recent_log_events_) { 196 for (auto& event : recent_log_events_) {
169 if (event.timestamp_us() >= start_time_us_ - recent_log_duration_us) { 197 if (event.timestamp_us() >= start_time_us_ - recent_log_duration_us) {
170 StoreToFile(&event); 198 StoreToFile(&event);
171 } 199 }
172 } 200 }
173 recent_log_events_.clear(); 201 recent_log_events_.clear();
174 // Write a LOG_START event to the file. 202 // Write a LOG_START event to the file.
175 rtclog::Event start_event; 203 rtclog::Event start_event;
176 start_event.set_timestamp_us(start_time_us_); 204 start_event.set_timestamp_us(start_time_us_);
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 currently_logging_ = false; 360 currently_logging_ = false;
333 // Create a LogEnd event 361 // Create a LogEnd event
334 rtclog::Event event; 362 rtclog::Event event;
335 int64_t timestamp = clock_->TimeInMicroseconds(); 363 int64_t timestamp = clock_->TimeInMicroseconds();
336 event.set_timestamp_us(timestamp); 364 event.set_timestamp_us(timestamp);
337 event.set_type(rtclog::Event::LOG_END); 365 event.set_type(rtclog::Event::LOG_END);
338 // Store the event and close the file 366 // Store the event and close the file
339 RTC_DCHECK(file_->Open()); 367 RTC_DCHECK(file_->Open());
340 StoreToFile(&event); 368 StoreToFile(&event);
341 file_->CloseFile(); 369 file_->CloseFile();
370 if (platform_file_ != rtc::kInvalidPlatformFileValue) {
371 rtc::ClosePlatformFile(platform_file_);
372 platform_file_ = rtc::kInvalidPlatformFileValue;
373 }
342 } 374 }
343 RTC_DCHECK(!file_->Open()); 375 RTC_DCHECK(!file_->Open());
344 stream_.Clear(); 376 stream_.Clear();
345 } 377 }
346 378
347 void RtcEventLogImpl::HandleEvent(rtclog::Event* event) { 379 void RtcEventLogImpl::HandleEvent(rtclog::Event* event) {
348 if (currently_logging_) { 380 if (currently_logging_) {
349 if (clock_->TimeInMicroseconds() < start_time_us_ + duration_us_) { 381 if (clock_->TimeInMicroseconds() < start_time_us_ + duration_us_) {
350 StoreToFile(event); 382 StoreToFile(event);
351 return; 383 return;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 return result->ParseFromString(dump_buffer); 425 return result->ParseFromString(dump_buffer);
394 } 426 }
395 427
396 #endif // ENABLE_RTC_EVENT_LOG 428 #endif // ENABLE_RTC_EVENT_LOG
397 429
398 // RtcEventLog member functions. 430 // RtcEventLog member functions.
399 rtc::scoped_ptr<RtcEventLog> RtcEventLog::Create() { 431 rtc::scoped_ptr<RtcEventLog> RtcEventLog::Create() {
400 return rtc::scoped_ptr<RtcEventLog>(new RtcEventLogImpl()); 432 return rtc::scoped_ptr<RtcEventLog>(new RtcEventLogImpl());
401 } 433 }
402 } // namespace webrtc 434 } // namespace webrtc
OLDNEW
« webrtc/call/rtc_event_log.h ('K') | « webrtc/call/rtc_event_log.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698