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> | |
the sun
2015/10/13 11:00:40
where do you use something from limits (in the cha
ivoc
2015/10/13 13:50:50
Thanks, this looks like a leftover of some earlier
| |
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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
154 | 160 |
155 void RtcEventLogImpl::StartLogging(const std::string& file_name, | 161 void RtcEventLogImpl::StartLogging(const std::string& file_name, |
156 int duration_ms) { | 162 int duration_ms) { |
157 rtc::CritScope lock(&crit_); | 163 rtc::CritScope lock(&crit_); |
158 if (currently_logging_) { | 164 if (currently_logging_) { |
159 StopLoggingLocked(); | 165 StopLoggingLocked(); |
160 } | 166 } |
161 if (file_->OpenFile(file_name.c_str(), false) != 0) { | 167 if (file_->OpenFile(file_name.c_str(), false) != 0) { |
162 return; | 168 return; |
163 } | 169 } |
164 currently_logging_ = true; | |
165 start_time_us_ = clock_->TimeInMicroseconds(); | 170 start_time_us_ = clock_->TimeInMicroseconds(); |
166 duration_us_ = static_cast<int64_t>(duration_ms) * 1000; | 171 duration_us_ = static_cast<int64_t>(duration_ms) * 1000; |
172 StartLoggingLocked(); | |
173 } | |
174 | |
175 int RtcEventLogImpl::StartLogging(FILE* log_file) { | |
176 rtc::CritScope lock(&crit_); | |
177 | |
178 if (currently_logging_) | |
179 StopLoggingLocked(); | |
180 RTC_DCHECK(log_file); | |
181 if (file_->OpenFromFileHandle(log_file, true, false) != 0) { | |
182 return -1; | |
183 } | |
184 // Set the start time and duration to keep logging for 10 minutes. | |
185 start_time_us_ = clock_->TimeInMicroseconds(); | |
186 duration_us_ = 10 * 60 * 1000000; | |
187 StartLoggingLocked(); | |
188 return 0; | |
189 } | |
190 | |
191 void RtcEventLogImpl::StartLoggingLocked() { | |
192 currently_logging_ = true; | |
167 // Write all the recent events to the log file, ignoring any old events. | 193 // Write all the recent events to the log file, ignoring any old events. |
168 for (auto& event : recent_log_events_) { | 194 for (auto& event : recent_log_events_) { |
169 if (event.timestamp_us() >= start_time_us_ - recent_log_duration_us) { | 195 if (event.timestamp_us() >= start_time_us_ - recent_log_duration_us) { |
170 StoreToFile(&event); | 196 StoreToFile(&event); |
171 } | 197 } |
172 } | 198 } |
173 recent_log_events_.clear(); | 199 recent_log_events_.clear(); |
174 // Write a LOG_START event to the file. | 200 // Write a LOG_START event to the file. |
175 rtclog::Event start_event; | 201 rtclog::Event start_event; |
176 start_event.set_timestamp_us(start_time_us_); | 202 start_event.set_timestamp_us(start_time_us_); |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
393 return result->ParseFromString(dump_buffer); | 419 return result->ParseFromString(dump_buffer); |
394 } | 420 } |
395 | 421 |
396 #endif // ENABLE_RTC_EVENT_LOG | 422 #endif // ENABLE_RTC_EVENT_LOG |
397 | 423 |
398 // RtcEventLog member functions. | 424 // RtcEventLog member functions. |
399 rtc::scoped_ptr<RtcEventLog> RtcEventLog::Create() { | 425 rtc::scoped_ptr<RtcEventLog> RtcEventLog::Create() { |
400 return rtc::scoped_ptr<RtcEventLog>(new RtcEventLogImpl()); | 426 return rtc::scoped_ptr<RtcEventLog>(new RtcEventLogImpl()); |
401 } | 427 } |
402 } // namespace webrtc | 428 } // namespace webrtc |
OLD | NEW |