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 <atomic> | 13 #include <atomic> |
14 #include <deque> | 14 #include <deque> |
15 #include <functional> | 15 #include <functional> |
16 #include <limits> | 16 #include <limits> |
17 #include <memory> | 17 #include <memory> |
18 #include <utility> | 18 #include <utility> |
19 #include <vector> | 19 #include <vector> |
20 | 20 |
| 21 #include "webrtc/logging/rtc_event_log/encoder/rtc_event_log_encoder_legacy.h" |
21 #include "webrtc/modules/audio_coding/audio_network_adaptor/include/audio_networ
k_adaptor.h" | 22 #include "webrtc/modules/audio_coding/audio_network_adaptor/include/audio_networ
k_adaptor.h" |
22 #include "webrtc/modules/remote_bitrate_estimator/include/bwe_defines.h" | 23 #include "webrtc/modules/remote_bitrate_estimator/include/bwe_defines.h" |
23 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" | 24 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" |
24 #include "webrtc/modules/rtp_rtcp/source/byte_io.h" | 25 #include "webrtc/modules/rtp_rtcp/source/byte_io.h" |
25 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/app.h" | 26 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/app.h" |
26 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/bye.h" | 27 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/bye.h" |
27 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/common_header.h" | 28 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/common_header.h" |
28 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/extended_jitter_report.h" | 29 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/extended_jitter_report.h" |
29 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/extended_reports.h" | 30 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/extended_reports.h" |
30 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/psfb.h" | 31 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/psfb.h" |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 return true; | 90 return true; |
90 } | 91 } |
91 | 92 |
92 private: | 93 private: |
93 std::unique_ptr<T> resource_; | 94 std::unique_ptr<T> resource_; |
94 std::function<void(std::unique_ptr<T>)> handler_; | 95 std::function<void(std::unique_ptr<T>)> handler_; |
95 }; | 96 }; |
96 } // namespace | 97 } // namespace |
97 | 98 |
98 class RtcEventLogImpl final : public RtcEventLog { | 99 class RtcEventLogImpl final : public RtcEventLog { |
99 friend std::unique_ptr<RtcEventLog> RtcEventLog::Create(); | 100 friend std::unique_ptr<RtcEventLog> RtcEventLog::Create(EncodingType); |
100 | 101 |
101 public: | 102 public: |
102 ~RtcEventLogImpl() override; | 103 ~RtcEventLogImpl() override; |
103 | 104 |
104 bool StartLogging(const std::string& file_name, | 105 bool StartLogging(const std::string& file_name, |
105 int64_t max_size_bytes) override; | 106 int64_t max_size_bytes) override; |
106 bool StartLogging(rtc::PlatformFile platform_file, | 107 bool StartLogging(rtc::PlatformFile platform_file, |
107 int64_t max_size_bytes) override; | 108 int64_t max_size_bytes) override; |
108 void StopLogging() override; | 109 void StopLogging() override; |
109 void LogVideoReceiveStreamConfig(const rtclog::StreamConfig& config) override; | 110 void LogVideoReceiveStreamConfig(const rtclog::StreamConfig& config) override; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 const AudioEncoderRuntimeConfig& config) override; | 142 const AudioEncoderRuntimeConfig& config) override; |
142 void LogProbeClusterCreated(int id, | 143 void LogProbeClusterCreated(int id, |
143 int bitrate_bps, | 144 int bitrate_bps, |
144 int min_probes, | 145 int min_probes, |
145 int min_bytes) override; | 146 int min_bytes) override; |
146 void LogProbeResultSuccess(int id, int bitrate_bps) override; | 147 void LogProbeResultSuccess(int id, int bitrate_bps) override; |
147 void LogProbeResultFailure(int id, | 148 void LogProbeResultFailure(int id, |
148 ProbeFailureReason failure_reason) override; | 149 ProbeFailureReason failure_reason) override; |
149 | 150 |
150 private: | 151 private: |
| 152 // Creation is done by RtcEventLog::Create. |
| 153 explicit RtcEventLogImpl(std::unique_ptr<RtcEventLogEncoder> event_encoder); |
| 154 |
151 void StartLoggingInternal(std::unique_ptr<FileWrapper> file, | 155 void StartLoggingInternal(std::unique_ptr<FileWrapper> file, |
152 int64_t max_size_bytes); | 156 int64_t max_size_bytes); |
153 | 157 |
154 RtcEventLogImpl(); // Creation is done by RtcEventLog::Create. | |
155 | |
156 void StoreEvent(std::unique_ptr<rtclog::Event> event); | 158 void StoreEvent(std::unique_ptr<rtclog::Event> event); |
157 void LogProbeResult(int id, | 159 void LogProbeResult(int id, |
158 rtclog::BweProbeResult::ResultType result, | 160 rtclog::BweProbeResult::ResultType result, |
159 int bitrate_bps); | 161 int bitrate_bps); |
160 | 162 |
161 // Appends an event to the output protobuf string, returning true on success. | 163 // Appends an event to the output protobuf string, returning true on success. |
162 // Fails and returns false in case the limit on output size prevents the | 164 // Fails and returns false in case the limit on output size prevents the |
163 // event from being added; in this case, the output string is left unchanged. | 165 // event from being added; in this case, the output string is left unchanged. |
164 bool AppendEventToString(rtclog::Event* event, | 166 bool AppendEventToString(rtclog::Event* event, |
165 ProtoString* output_string) RTC_WARN_UNUSED_RESULT; | 167 ProtoString* output_string) RTC_WARN_UNUSED_RESULT; |
(...skipping 18 matching lines...) Expand all Loading... |
184 ACCESS_ON(task_queue_); | 186 ACCESS_ON(task_queue_); |
185 | 187 |
186 // History containing the most recent (non-configuration) events (~10s). | 188 // History containing the most recent (non-configuration) events (~10s). |
187 std::deque<std::unique_ptr<rtclog::Event>> history_ ACCESS_ON(task_queue_); | 189 std::deque<std::unique_ptr<rtclog::Event>> history_ ACCESS_ON(task_queue_); |
188 | 190 |
189 std::unique_ptr<FileWrapper> file_ ACCESS_ON(task_queue_); | 191 std::unique_ptr<FileWrapper> file_ ACCESS_ON(task_queue_); |
190 | 192 |
191 size_t max_size_bytes_ ACCESS_ON(task_queue_); | 193 size_t max_size_bytes_ ACCESS_ON(task_queue_); |
192 size_t written_bytes_ ACCESS_ON(task_queue_); | 194 size_t written_bytes_ ACCESS_ON(task_queue_); |
193 | 195 |
| 196 std::unique_ptr<RtcEventLogEncoder> event_encoder_ ACCESS_ON(task_queue_); |
| 197 |
194 // Keep this last to ensure it destructs first, or else tasks living on the | 198 // Keep this last to ensure it destructs first, or else tasks living on the |
195 // queue might access other members after they've been torn down. | 199 // queue might access other members after they've been torn down. |
196 rtc::TaskQueue task_queue_; | 200 rtc::TaskQueue task_queue_; |
197 | 201 |
198 RTC_DISALLOW_COPY_AND_ASSIGN(RtcEventLogImpl); | 202 RTC_DISALLOW_COPY_AND_ASSIGN(RtcEventLogImpl); |
199 }; | 203 }; |
200 | 204 |
201 namespace { | 205 namespace { |
202 // The functions in this namespace convert enums from the runtime format | 206 // The functions in this namespace convert enums from the runtime format |
203 // that the rest of the WebRtc project can use, to the corresponding | 207 // that the rest of the WebRtc project can use, to the corresponding |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 return rtclog::BweProbeResult::TIMEOUT; | 246 return rtclog::BweProbeResult::TIMEOUT; |
243 } | 247 } |
244 RTC_NOTREACHED(); | 248 RTC_NOTREACHED(); |
245 return rtclog::BweProbeResult::SUCCESS; | 249 return rtclog::BweProbeResult::SUCCESS; |
246 } | 250 } |
247 | 251 |
248 } // namespace | 252 } // namespace |
249 | 253 |
250 std::atomic<int> RtcEventLogImpl::log_count_(0); | 254 std::atomic<int> RtcEventLogImpl::log_count_(0); |
251 | 255 |
252 RtcEventLogImpl::RtcEventLogImpl() | 256 RtcEventLogImpl::RtcEventLogImpl( |
| 257 std::unique_ptr<RtcEventLogEncoder> event_encoder) |
253 : file_(FileWrapper::Create()), | 258 : file_(FileWrapper::Create()), |
254 max_size_bytes_(std::numeric_limits<decltype(max_size_bytes_)>::max()), | 259 max_size_bytes_(std::numeric_limits<decltype(max_size_bytes_)>::max()), |
255 written_bytes_(0), | 260 written_bytes_(0), |
| 261 event_encoder_(std::move(event_encoder)), |
256 task_queue_("rtc_event_log") {} | 262 task_queue_("rtc_event_log") {} |
257 | 263 |
258 RtcEventLogImpl::~RtcEventLogImpl() { | 264 RtcEventLogImpl::~RtcEventLogImpl() { |
259 RTC_DCHECK_CALLED_SEQUENTIALLY(&owner_sequence_checker_); | 265 RTC_DCHECK_CALLED_SEQUENTIALLY(&owner_sequence_checker_); |
260 | 266 |
261 // If we're logging to the file, this will stop that. Blocking function. | 267 // If we're logging to the file, this will stop that. Blocking function. |
262 StopLogging(); | 268 StopLogging(); |
263 | 269 |
264 int count = std::atomic_fetch_sub(&RtcEventLogImpl::log_count_, 1) - 1; | 270 int count = std::atomic_fetch_sub(&RtcEventLogImpl::log_count_, 1) - 1; |
265 RTC_DCHECK_GE(count, 0); | 271 RTC_DCHECK_GE(count, 0); |
(...skipping 584 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
850 while ((bytes_read = dump_file->Read(tmp_buffer, sizeof(tmp_buffer))) > 0) { | 856 while ((bytes_read = dump_file->Read(tmp_buffer, sizeof(tmp_buffer))) > 0) { |
851 dump_buffer.append(tmp_buffer, bytes_read); | 857 dump_buffer.append(tmp_buffer, bytes_read); |
852 } | 858 } |
853 dump_file->CloseFile(); | 859 dump_file->CloseFile(); |
854 return result->ParseFromString(dump_buffer); | 860 return result->ParseFromString(dump_buffer); |
855 } | 861 } |
856 | 862 |
857 #endif // ENABLE_RTC_EVENT_LOG | 863 #endif // ENABLE_RTC_EVENT_LOG |
858 | 864 |
859 // RtcEventLog member functions. | 865 // RtcEventLog member functions. |
860 std::unique_ptr<RtcEventLog> RtcEventLog::Create() { | 866 std::unique_ptr<RtcEventLog> RtcEventLog::Create(EncodingType encoding_type) { |
861 #ifdef ENABLE_RTC_EVENT_LOG | 867 #ifdef ENABLE_RTC_EVENT_LOG |
862 // TODO(eladalon): Known issue - there's a race over |log_count_| here. | 868 // TODO(eladalon): Known issue - there's a race over |log_count_| here. |
863 constexpr int kMaxLogCount = 5; | 869 constexpr int kMaxLogCount = 5; |
864 int count = 1 + std::atomic_fetch_add(&RtcEventLogImpl::log_count_, 1); | 870 int count = 1 + std::atomic_fetch_add(&RtcEventLogImpl::log_count_, 1); |
865 if (count > kMaxLogCount) { | 871 if (count > kMaxLogCount) { |
866 LOG(LS_WARNING) << "Denied creation of additional WebRTC event logs. " | 872 LOG(LS_WARNING) << "Denied creation of additional WebRTC event logs. " |
867 << count - 1 << " logs open already."; | 873 << count - 1 << " logs open already."; |
868 std::atomic_fetch_sub(&RtcEventLogImpl::log_count_, 1); | 874 std::atomic_fetch_sub(&RtcEventLogImpl::log_count_, 1); |
869 return std::unique_ptr<RtcEventLog>(new RtcEventLogNullImpl()); | 875 return CreateNull(); |
870 } | 876 } |
871 return std::unique_ptr<RtcEventLog>(new RtcEventLogImpl()); | 877 auto encoder = CreateEncoder(encoding_type); |
| 878 return rtc::WrapUnique<RtcEventLog>(new RtcEventLogImpl(std::move(encoder))); |
872 #else | 879 #else |
873 return CreateNull(); | 880 return CreateNull(); |
874 #endif // ENABLE_RTC_EVENT_LOG | 881 #endif // ENABLE_RTC_EVENT_LOG |
875 } | 882 } |
876 | 883 |
877 std::unique_ptr<RtcEventLog> RtcEventLog::CreateNull() { | 884 std::unique_ptr<RtcEventLog> RtcEventLog::CreateNull() { |
878 return std::unique_ptr<RtcEventLog>(new RtcEventLogNullImpl()); | 885 return std::unique_ptr<RtcEventLog>(new RtcEventLogNullImpl()); |
879 } | 886 } |
880 | 887 |
| 888 std::unique_ptr<RtcEventLogEncoder> RtcEventLog::CreateEncoder( |
| 889 EncodingType type) { |
| 890 switch (type) { |
| 891 case EncodingType::Legacy: |
| 892 return rtc::MakeUnique<RtcEventLogEncoderLegacy>(); |
| 893 default: |
| 894 LOG(LS_ERROR) << "Unknown RtcEventLog encoder type (" << int(type) << ")"; |
| 895 RTC_NOTREACHED(); |
| 896 } |
| 897 } |
| 898 |
881 } // namespace webrtc | 899 } // namespace webrtc |
OLD | NEW |