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 |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 | 89 |
90 bool Run() override { | 90 bool Run() override { |
91 handler_(std::move(resource_)); | 91 handler_(std::move(resource_)); |
92 return true; | 92 return true; |
93 } | 93 } |
94 | 94 |
95 private: | 95 private: |
96 std::unique_ptr<T> resource_; | 96 std::unique_ptr<T> resource_; |
97 std::function<void(std::unique_ptr<T>)> handler_; | 97 std::function<void(std::unique_ptr<T>)> handler_; |
98 }; | 98 }; |
99 } // namespace | |
100 | 99 |
101 class RtcEventLogImpl final : public RtcEventLog { | 100 class RtcEventLogImpl final : public RtcEventLog { |
102 friend std::unique_ptr<RtcEventLog> RtcEventLog::Create(); | |
103 | |
104 public: | 101 public: |
| 102 RtcEventLogImpl(); |
105 ~RtcEventLogImpl() override; | 103 ~RtcEventLogImpl() override; |
106 | 104 |
107 bool StartLogging(const std::string& file_name, | 105 bool StartLogging(const std::string& file_name, |
108 int64_t max_size_bytes) override; | 106 int64_t max_size_bytes) override; |
109 bool StartLogging(rtc::PlatformFile platform_file, | 107 bool StartLogging(rtc::PlatformFile platform_file, |
110 int64_t max_size_bytes) override; | 108 int64_t max_size_bytes) override; |
111 void StopLogging() override; | 109 void StopLogging() override; |
112 void LogVideoReceiveStreamConfig(const rtclog::StreamConfig& config) override; | 110 void LogVideoReceiveStreamConfig(const rtclog::StreamConfig& config) override; |
113 void LogVideoSendStreamConfig(const rtclog::StreamConfig& config) override; | 111 void LogVideoSendStreamConfig(const rtclog::StreamConfig& config) override; |
114 void LogAudioReceiveStreamConfig(const rtclog::StreamConfig& config) override; | 112 void LogAudioReceiveStreamConfig(const rtclog::StreamConfig& config) override; |
(...skipping 21 matching lines...) Expand all Loading... |
136 int min_probes, | 134 int min_probes, |
137 int min_bytes) override; | 135 int min_bytes) override; |
138 void LogProbeResultSuccess(int id, int bitrate_bps) override; | 136 void LogProbeResultSuccess(int id, int bitrate_bps) override; |
139 void LogProbeResultFailure(int id, | 137 void LogProbeResultFailure(int id, |
140 ProbeFailureReason failure_reason) override; | 138 ProbeFailureReason failure_reason) override; |
141 | 139 |
142 private: | 140 private: |
143 void StartLoggingInternal(std::unique_ptr<FileWrapper> file, | 141 void StartLoggingInternal(std::unique_ptr<FileWrapper> file, |
144 int64_t max_size_bytes); | 142 int64_t max_size_bytes); |
145 | 143 |
146 RtcEventLogImpl(); // Creation is done by RtcEventLog::Create. | |
147 | |
148 void StoreEvent(std::unique_ptr<rtclog::Event> event); | 144 void StoreEvent(std::unique_ptr<rtclog::Event> event); |
149 void LogProbeResult(int id, | 145 void LogProbeResult(int id, |
150 rtclog::BweProbeResult::ResultType result, | 146 rtclog::BweProbeResult::ResultType result, |
151 int bitrate_bps); | 147 int bitrate_bps); |
152 | 148 |
153 // Appends an event to the output protobuf string, returning true on success. | 149 // Appends an event to the output protobuf string, returning true on success. |
154 // Fails and returns false in case the limit on output size prevents the | 150 // Fails and returns false in case the limit on output size prevents the |
155 // event from being added; in this case, the output string is left unchanged. | 151 // event from being added; in this case, the output string is left unchanged. |
156 bool AppendEventToString(rtclog::Event* event, | 152 bool AppendEventToString(rtclog::Event* event, |
157 ProtoString* output_string) RTC_WARN_UNUSED_RESULT; | 153 ProtoString* output_string) RTC_WARN_UNUSED_RESULT; |
(...skipping 21 matching lines...) Expand all Loading... |
179 size_t max_size_bytes_ RTC_ACCESS_ON(task_queue_); | 175 size_t max_size_bytes_ RTC_ACCESS_ON(task_queue_); |
180 size_t written_bytes_ RTC_ACCESS_ON(task_queue_); | 176 size_t written_bytes_ RTC_ACCESS_ON(task_queue_); |
181 | 177 |
182 // Keep this last to ensure it destructs first, or else tasks living on the | 178 // Keep this last to ensure it destructs first, or else tasks living on the |
183 // queue might access other members after they've been torn down. | 179 // queue might access other members after they've been torn down. |
184 rtc::TaskQueue task_queue_; | 180 rtc::TaskQueue task_queue_; |
185 | 181 |
186 RTC_DISALLOW_COPY_AND_ASSIGN(RtcEventLogImpl); | 182 RTC_DISALLOW_COPY_AND_ASSIGN(RtcEventLogImpl); |
187 }; | 183 }; |
188 | 184 |
189 namespace { | |
190 // The functions in this namespace convert enums from the runtime format | |
191 // that the rest of the WebRtc project can use, to the corresponding | |
192 // serialized enum which is defined by the protobuf. | |
193 | |
194 rtclog::VideoReceiveConfig_RtcpMode ConvertRtcpMode(RtcpMode rtcp_mode) { | 185 rtclog::VideoReceiveConfig_RtcpMode ConvertRtcpMode(RtcpMode rtcp_mode) { |
195 switch (rtcp_mode) { | 186 switch (rtcp_mode) { |
196 case RtcpMode::kCompound: | 187 case RtcpMode::kCompound: |
197 return rtclog::VideoReceiveConfig::RTCP_COMPOUND; | 188 return rtclog::VideoReceiveConfig::RTCP_COMPOUND; |
198 case RtcpMode::kReducedSize: | 189 case RtcpMode::kReducedSize: |
199 return rtclog::VideoReceiveConfig::RTCP_REDUCEDSIZE; | 190 return rtclog::VideoReceiveConfig::RTCP_REDUCEDSIZE; |
200 case RtcpMode::kOff: | 191 case RtcpMode::kOff: |
201 RTC_NOTREACHED(); | 192 RTC_NOTREACHED(); |
202 return rtclog::VideoReceiveConfig::RTCP_COMPOUND; | 193 return rtclog::VideoReceiveConfig::RTCP_COMPOUND; |
203 } | 194 } |
(...skipping 605 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
809 // RtcEventLog member functions. | 800 // RtcEventLog member functions. |
810 std::unique_ptr<RtcEventLog> RtcEventLog::Create() { | 801 std::unique_ptr<RtcEventLog> RtcEventLog::Create() { |
811 #ifdef ENABLE_RTC_EVENT_LOG | 802 #ifdef ENABLE_RTC_EVENT_LOG |
812 // TODO(eladalon): Known issue - there's a race over |rtc_event_log_count|. | 803 // TODO(eladalon): Known issue - there's a race over |rtc_event_log_count|. |
813 constexpr int kMaxLogCount = 5; | 804 constexpr int kMaxLogCount = 5; |
814 int count = 1 + std::atomic_fetch_add(&rtc_event_log_count, 1); | 805 int count = 1 + std::atomic_fetch_add(&rtc_event_log_count, 1); |
815 if (count > kMaxLogCount) { | 806 if (count > kMaxLogCount) { |
816 LOG(LS_WARNING) << "Denied creation of additional WebRTC event logs. " | 807 LOG(LS_WARNING) << "Denied creation of additional WebRTC event logs. " |
817 << count - 1 << " logs open already."; | 808 << count - 1 << " logs open already."; |
818 std::atomic_fetch_sub(&rtc_event_log_count, 1); | 809 std::atomic_fetch_sub(&rtc_event_log_count, 1); |
819 return std::unique_ptr<RtcEventLog>(new RtcEventLogNullImpl()); | 810 return CreateNull(); |
820 } | 811 } |
821 return std::unique_ptr<RtcEventLog>(new RtcEventLogImpl()); | 812 return rtc::MakeUnique<RtcEventLogImpl>(); |
822 #else | 813 #else |
823 return CreateNull(); | 814 return CreateNull(); |
824 #endif // ENABLE_RTC_EVENT_LOG | 815 #endif // ENABLE_RTC_EVENT_LOG |
825 } | 816 } |
826 | 817 |
827 std::unique_ptr<RtcEventLog> RtcEventLog::CreateNull() { | 818 std::unique_ptr<RtcEventLog> RtcEventLog::CreateNull() { |
828 return std::unique_ptr<RtcEventLog>(new RtcEventLogNullImpl()); | 819 return std::unique_ptr<RtcEventLog>(new RtcEventLogNullImpl()); |
829 } | 820 } |
830 | 821 |
831 } // namespace webrtc | 822 } // namespace webrtc |
OLD | NEW |