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/logging/rtc_event_log/rtc_event_log.h" | 11 #include "webrtc/logging/rtc_event_log/rtc_event_log.h" |
12 | 12 |
13 #include <limits> | 13 #include <limits> |
14 #include <vector> | 14 #include <vector> |
15 | 15 |
| 16 #include "webrtc/base/atomicops.h" |
16 #include "webrtc/base/checks.h" | 17 #include "webrtc/base/checks.h" |
17 #include "webrtc/base/constructormagic.h" | 18 #include "webrtc/base/constructormagic.h" |
18 #include "webrtc/base/event.h" | 19 #include "webrtc/base/event.h" |
19 #include "webrtc/base/logging.h" | 20 #include "webrtc/base/logging.h" |
20 #include "webrtc/base/protobuf_utils.h" | 21 #include "webrtc/base/protobuf_utils.h" |
21 #include "webrtc/base/swap_queue.h" | 22 #include "webrtc/base/swap_queue.h" |
22 #include "webrtc/base/thread_checker.h" | 23 #include "webrtc/base/thread_checker.h" |
23 #include "webrtc/base/timeutils.h" | 24 #include "webrtc/base/timeutils.h" |
24 #include "webrtc/logging/rtc_event_log/rtc_event_log_helper_thread.h" | 25 #include "webrtc/logging/rtc_event_log/rtc_event_log_helper_thread.h" |
25 #include "webrtc/modules/audio_coding/audio_network_adaptor/include/audio_networ
k_adaptor.h" | 26 #include "webrtc/modules/audio_coding/audio_network_adaptor/include/audio_networ
k_adaptor.h" |
(...skipping 19 matching lines...) Expand all Loading... |
45 #else | 46 #else |
46 #include "webrtc/logging/rtc_event_log/rtc_event_log.pb.h" | 47 #include "webrtc/logging/rtc_event_log/rtc_event_log.pb.h" |
47 #endif | 48 #endif |
48 #endif | 49 #endif |
49 | 50 |
50 namespace webrtc { | 51 namespace webrtc { |
51 | 52 |
52 #ifdef ENABLE_RTC_EVENT_LOG | 53 #ifdef ENABLE_RTC_EVENT_LOG |
53 | 54 |
54 class RtcEventLogImpl final : public RtcEventLog { | 55 class RtcEventLogImpl final : public RtcEventLog { |
| 56 friend std::unique_ptr<RtcEventLog> RtcEventLog::Create(); |
| 57 |
55 public: | 58 public: |
56 RtcEventLogImpl(); | |
57 ~RtcEventLogImpl() override; | 59 ~RtcEventLogImpl() override; |
58 | 60 |
59 bool StartLogging(const std::string& file_name, | 61 bool StartLogging(const std::string& file_name, |
60 int64_t max_size_bytes) override; | 62 int64_t max_size_bytes) override; |
61 bool StartLogging(rtc::PlatformFile platform_file, | 63 bool StartLogging(rtc::PlatformFile platform_file, |
62 int64_t max_size_bytes) override; | 64 int64_t max_size_bytes) override; |
63 void StopLogging() override; | 65 void StopLogging() override; |
64 void LogVideoReceiveStreamConfig(const rtclog::StreamConfig& config) override; | 66 void LogVideoReceiveStreamConfig(const rtclog::StreamConfig& config) override; |
65 void LogVideoSendStreamConfig(const rtclog::StreamConfig& config) override; | 67 void LogVideoSendStreamConfig(const rtclog::StreamConfig& config) override; |
66 void LogAudioReceiveStreamConfig(const rtclog::StreamConfig& config) override; | 68 void LogAudioReceiveStreamConfig(const rtclog::StreamConfig& config) override; |
(...skipping 18 matching lines...) Expand all Loading... |
85 const AudioEncoderRuntimeConfig& config) override; | 87 const AudioEncoderRuntimeConfig& config) override; |
86 void LogProbeClusterCreated(int id, | 88 void LogProbeClusterCreated(int id, |
87 int bitrate_bps, | 89 int bitrate_bps, |
88 int min_probes, | 90 int min_probes, |
89 int min_bytes) override; | 91 int min_bytes) override; |
90 void LogProbeResultSuccess(int id, int bitrate_bps) override; | 92 void LogProbeResultSuccess(int id, int bitrate_bps) override; |
91 void LogProbeResultFailure(int id, | 93 void LogProbeResultFailure(int id, |
92 ProbeFailureReason failure_reason) override; | 94 ProbeFailureReason failure_reason) override; |
93 | 95 |
94 private: | 96 private: |
| 97 // Private constructor to ensure that creation is done by RtcEventLog::Create. |
| 98 RtcEventLogImpl(); |
| 99 |
95 void StoreEvent(std::unique_ptr<rtclog::Event>* event); | 100 void StoreEvent(std::unique_ptr<rtclog::Event>* event); |
96 void LogProbeResult(int id, | 101 void LogProbeResult(int id, |
97 rtclog::BweProbeResult::ResultType result, | 102 rtclog::BweProbeResult::ResultType result, |
98 int bitrate_bps); | 103 int bitrate_bps); |
99 | 104 |
| 105 static volatile int log_count_; |
| 106 |
100 // Message queue for passing control messages to the logging thread. | 107 // Message queue for passing control messages to the logging thread. |
101 SwapQueue<RtcEventLogHelperThread::ControlMessage> message_queue_; | 108 SwapQueue<RtcEventLogHelperThread::ControlMessage> message_queue_; |
102 | 109 |
103 // Message queue for passing events to the logging thread. | 110 // Message queue for passing events to the logging thread. |
104 SwapQueue<std::unique_ptr<rtclog::Event> > event_queue_; | 111 SwapQueue<std::unique_ptr<rtclog::Event> > event_queue_; |
105 | 112 |
106 RtcEventLogHelperThread helper_thread_; | 113 RtcEventLogHelperThread helper_thread_; |
107 rtc::ThreadChecker thread_checker_; | 114 rtc::ThreadChecker thread_checker_; |
108 | 115 |
109 RTC_DISALLOW_COPY_AND_ASSIGN(RtcEventLogImpl); | 116 RTC_DISALLOW_COPY_AND_ASSIGN(RtcEventLogImpl); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 RTC_NOTREACHED(); | 162 RTC_NOTREACHED(); |
156 return rtclog::BweProbeResult::SUCCESS; | 163 return rtclog::BweProbeResult::SUCCESS; |
157 } | 164 } |
158 | 165 |
159 // The RTP and RTCP buffers reserve space for twice the expected number of | 166 // The RTP and RTCP buffers reserve space for twice the expected number of |
160 // sent packets because they also contain received packets. | 167 // sent packets because they also contain received packets. |
161 static const int kEventsPerSecond = 1000; | 168 static const int kEventsPerSecond = 1000; |
162 static const int kControlMessagesPerSecond = 10; | 169 static const int kControlMessagesPerSecond = 10; |
163 } // namespace | 170 } // namespace |
164 | 171 |
| 172 volatile int RtcEventLogImpl::log_count_ = 0; |
| 173 |
165 // RtcEventLogImpl member functions. | 174 // RtcEventLogImpl member functions. |
166 RtcEventLogImpl::RtcEventLogImpl() | 175 RtcEventLogImpl::RtcEventLogImpl() |
167 // Allocate buffers for roughly one second of history. | 176 // Allocate buffers for roughly one second of history. |
168 : message_queue_(kControlMessagesPerSecond), | 177 : message_queue_(kControlMessagesPerSecond), |
169 event_queue_(kEventsPerSecond), | 178 event_queue_(kEventsPerSecond), |
170 helper_thread_(&message_queue_, &event_queue_), | 179 helper_thread_(&message_queue_, &event_queue_), |
171 thread_checker_() { | 180 thread_checker_() { |
172 thread_checker_.DetachFromThread(); | 181 thread_checker_.DetachFromThread(); |
173 } | 182 } |
174 | 183 |
175 RtcEventLogImpl::~RtcEventLogImpl() { | 184 RtcEventLogImpl::~RtcEventLogImpl() { |
176 // The RtcEventLogHelperThread destructor closes the file | 185 // The RtcEventLogHelperThread destructor closes the file |
177 // and waits for the thread to terminate. | 186 // and waits for the thread to terminate. |
| 187 int count = rtc::AtomicOps::Decrement(&RtcEventLogImpl::log_count_); |
| 188 RTC_DCHECK_GE(count, 0); |
178 } | 189 } |
179 | 190 |
180 bool RtcEventLogImpl::StartLogging(const std::string& file_name, | 191 bool RtcEventLogImpl::StartLogging(const std::string& file_name, |
181 int64_t max_size_bytes) { | 192 int64_t max_size_bytes) { |
182 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 193 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
183 RtcEventLogHelperThread::ControlMessage message; | 194 RtcEventLogHelperThread::ControlMessage message; |
184 message.message_type = RtcEventLogHelperThread::ControlMessage::START_FILE; | 195 message.message_type = RtcEventLogHelperThread::ControlMessage::START_FILE; |
185 message.max_size_bytes = max_size_bytes <= 0 | 196 message.max_size_bytes = max_size_bytes <= 0 |
186 ? std::numeric_limits<int64_t>::max() | 197 ? std::numeric_limits<int64_t>::max() |
187 : max_size_bytes; | 198 : max_size_bytes; |
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
576 } | 587 } |
577 dump_file->CloseFile(); | 588 dump_file->CloseFile(); |
578 return result->ParseFromString(dump_buffer); | 589 return result->ParseFromString(dump_buffer); |
579 } | 590 } |
580 | 591 |
581 #endif // ENABLE_RTC_EVENT_LOG | 592 #endif // ENABLE_RTC_EVENT_LOG |
582 | 593 |
583 // RtcEventLog member functions. | 594 // RtcEventLog member functions. |
584 std::unique_ptr<RtcEventLog> RtcEventLog::Create() { | 595 std::unique_ptr<RtcEventLog> RtcEventLog::Create() { |
585 #ifdef ENABLE_RTC_EVENT_LOG | 596 #ifdef ENABLE_RTC_EVENT_LOG |
| 597 constexpr int kMaxLogCount = 5; |
| 598 int count = rtc::AtomicOps::Increment(&RtcEventLogImpl::log_count_); |
| 599 if (count > kMaxLogCount) { |
| 600 LOG(LS_WARNING) << "Denied creation of additional WebRTC event logs. " |
| 601 << count - 1 << " logs open already."; |
| 602 rtc::AtomicOps::Decrement(&RtcEventLogImpl::log_count_); |
| 603 return std::unique_ptr<RtcEventLog>(new RtcEventLogNullImpl()); |
| 604 } |
586 return std::unique_ptr<RtcEventLog>(new RtcEventLogImpl()); | 605 return std::unique_ptr<RtcEventLog>(new RtcEventLogImpl()); |
587 #else | 606 #else |
588 return std::unique_ptr<RtcEventLog>(new RtcEventLogNullImpl()); | 607 return std::unique_ptr<RtcEventLog>(new RtcEventLogNullImpl()); |
589 #endif // ENABLE_RTC_EVENT_LOG | 608 #endif // ENABLE_RTC_EVENT_LOG |
590 } | 609 } |
591 | 610 |
592 std::unique_ptr<RtcEventLog> RtcEventLog::CreateNull() { | 611 std::unique_ptr<RtcEventLog> RtcEventLog::CreateNull() { |
593 return std::unique_ptr<RtcEventLog>(new RtcEventLogNullImpl()); | 612 return std::unique_ptr<RtcEventLog>(new RtcEventLogNullImpl()); |
594 } | 613 } |
595 | 614 |
596 } // namespace webrtc | 615 } // namespace webrtc |
OLD | NEW |