| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2012 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 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 if (r->type() == StatsReport::kStatsReportTypeSsrc) { | 118 if (r->type() == StatsReport::kStatsReportTypeSsrc) { |
| 119 stats_.timestamp = r->timestamp(); | 119 stats_.timestamp = r->timestamp(); |
| 120 GetIntValue(r, StatsReport::kStatsValueNameAudioOutputLevel, | 120 GetIntValue(r, StatsReport::kStatsValueNameAudioOutputLevel, |
| 121 &stats_.audio_output_level); | 121 &stats_.audio_output_level); |
| 122 GetIntValue(r, StatsReport::kStatsValueNameAudioInputLevel, | 122 GetIntValue(r, StatsReport::kStatsValueNameAudioInputLevel, |
| 123 &stats_.audio_input_level); | 123 &stats_.audio_input_level); |
| 124 GetIntValue(r, StatsReport::kStatsValueNameBytesReceived, | 124 GetIntValue(r, StatsReport::kStatsValueNameBytesReceived, |
| 125 &stats_.bytes_received); | 125 &stats_.bytes_received); |
| 126 GetIntValue(r, StatsReport::kStatsValueNameBytesSent, | 126 GetIntValue(r, StatsReport::kStatsValueNameBytesSent, |
| 127 &stats_.bytes_sent); | 127 &stats_.bytes_sent); |
| 128 GetInt64Value(r, StatsReport::kStatsValueNameCaptureStartNtpTimeMs, |
| 129 &stats_.capture_start_ntp_time); |
| 128 } else if (r->type() == StatsReport::kStatsReportTypeBwe) { | 130 } else if (r->type() == StatsReport::kStatsReportTypeBwe) { |
| 129 stats_.timestamp = r->timestamp(); | 131 stats_.timestamp = r->timestamp(); |
| 130 GetIntValue(r, StatsReport::kStatsValueNameAvailableReceiveBandwidth, | 132 GetIntValue(r, StatsReport::kStatsValueNameAvailableReceiveBandwidth, |
| 131 &stats_.available_receive_bandwidth); | 133 &stats_.available_receive_bandwidth); |
| 132 } else if (r->type() == StatsReport::kStatsReportTypeComponent) { | 134 } else if (r->type() == StatsReport::kStatsReportTypeComponent) { |
| 133 stats_.timestamp = r->timestamp(); | 135 stats_.timestamp = r->timestamp(); |
| 134 GetStringValue(r, StatsReport::kStatsValueNameDtlsCipher, | 136 GetStringValue(r, StatsReport::kStatsValueNameDtlsCipher, |
| 135 &stats_.dtls_cipher); | 137 &stats_.dtls_cipher); |
| 136 GetStringValue(r, StatsReport::kStatsValueNameSrtpCipher, | 138 GetStringValue(r, StatsReport::kStatsValueNameSrtpCipher, |
| 137 &stats_.srtp_cipher); | 139 &stats_.srtp_cipher); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 156 int BytesReceived() const { | 158 int BytesReceived() const { |
| 157 RTC_CHECK(called_); | 159 RTC_CHECK(called_); |
| 158 return stats_.bytes_received; | 160 return stats_.bytes_received; |
| 159 } | 161 } |
| 160 | 162 |
| 161 int BytesSent() const { | 163 int BytesSent() const { |
| 162 RTC_CHECK(called_); | 164 RTC_CHECK(called_); |
| 163 return stats_.bytes_sent; | 165 return stats_.bytes_sent; |
| 164 } | 166 } |
| 165 | 167 |
| 168 int64_t CaptureStartNtpTime() const { |
| 169 RTC_CHECK(called_); |
| 170 return stats_.capture_start_ntp_time; |
| 171 } |
| 172 |
| 166 int AvailableReceiveBandwidth() const { | 173 int AvailableReceiveBandwidth() const { |
| 167 RTC_CHECK(called_); | 174 RTC_CHECK(called_); |
| 168 return stats_.available_receive_bandwidth; | 175 return stats_.available_receive_bandwidth; |
| 169 } | 176 } |
| 170 | 177 |
| 171 std::string DtlsCipher() const { | 178 std::string DtlsCipher() const { |
| 172 RTC_CHECK(called_); | 179 RTC_CHECK(called_); |
| 173 return stats_.dtls_cipher; | 180 return stats_.dtls_cipher; |
| 174 } | 181 } |
| 175 | 182 |
| 176 std::string SrtpCipher() const { | 183 std::string SrtpCipher() const { |
| 177 RTC_CHECK(called_); | 184 RTC_CHECK(called_); |
| 178 return stats_.srtp_cipher; | 185 return stats_.srtp_cipher; |
| 179 } | 186 } |
| 180 | 187 |
| 181 private: | 188 private: |
| 182 bool GetIntValue(const StatsReport* report, | 189 bool GetIntValue(const StatsReport* report, |
| 183 StatsReport::StatsValueName name, | 190 StatsReport::StatsValueName name, |
| 184 int* value) { | 191 int* value) { |
| 185 const StatsReport::Value* v = report->FindValue(name); | 192 const StatsReport::Value* v = report->FindValue(name); |
| 186 if (v) { | 193 if (v) { |
| 187 // TODO(tommi): We should really just be using an int here :-/ | 194 // TODO(tommi): We should really just be using an int here :-/ |
| 188 *value = rtc::FromString<int>(v->ToString()); | 195 *value = rtc::FromString<int>(v->ToString()); |
| 189 } | 196 } |
| 190 return v != nullptr; | 197 return v != nullptr; |
| 191 } | 198 } |
| 192 | 199 |
| 200 bool GetInt64Value(const StatsReport* report, |
| 201 StatsReport::StatsValueName name, |
| 202 int64_t* value) { |
| 203 const StatsReport::Value* v = report->FindValue(name); |
| 204 if (v) { |
| 205 // TODO(tommi): We should really just be using an int here :-/ |
| 206 *value = rtc::FromString<int64_t>(v->ToString()); |
| 207 } |
| 208 return v != nullptr; |
| 209 } |
| 210 |
| 193 bool GetStringValue(const StatsReport* report, | 211 bool GetStringValue(const StatsReport* report, |
| 194 StatsReport::StatsValueName name, | 212 StatsReport::StatsValueName name, |
| 195 std::string* value) { | 213 std::string* value) { |
| 196 const StatsReport::Value* v = report->FindValue(name); | 214 const StatsReport::Value* v = report->FindValue(name); |
| 197 if (v) | 215 if (v) |
| 198 *value = v->ToString(); | 216 *value = v->ToString(); |
| 199 return v != nullptr; | 217 return v != nullptr; |
| 200 } | 218 } |
| 201 | 219 |
| 202 bool called_; | 220 bool called_; |
| 203 struct { | 221 struct { |
| 204 void Clear() { | 222 void Clear() { |
| 205 number_of_reports = 0; | 223 number_of_reports = 0; |
| 206 timestamp = 0; | 224 timestamp = 0; |
| 207 audio_output_level = 0; | 225 audio_output_level = 0; |
| 208 audio_input_level = 0; | 226 audio_input_level = 0; |
| 209 bytes_received = 0; | 227 bytes_received = 0; |
| 210 bytes_sent = 0; | 228 bytes_sent = 0; |
| 229 capture_start_ntp_time = 0; |
| 211 available_receive_bandwidth = 0; | 230 available_receive_bandwidth = 0; |
| 212 dtls_cipher.clear(); | 231 dtls_cipher.clear(); |
| 213 srtp_cipher.clear(); | 232 srtp_cipher.clear(); |
| 214 } | 233 } |
| 215 | 234 |
| 216 size_t number_of_reports; | 235 size_t number_of_reports; |
| 217 double timestamp; | 236 double timestamp; |
| 218 int audio_output_level; | 237 int audio_output_level; |
| 219 int audio_input_level; | 238 int audio_input_level; |
| 220 int bytes_received; | 239 int bytes_received; |
| 221 int bytes_sent; | 240 int bytes_sent; |
| 241 int64_t capture_start_ntp_time; |
| 222 int available_receive_bandwidth; | 242 int available_receive_bandwidth; |
| 223 std::string dtls_cipher; | 243 std::string dtls_cipher; |
| 224 std::string srtp_cipher; | 244 std::string srtp_cipher; |
| 225 } stats_; | 245 } stats_; |
| 226 }; | 246 }; |
| 227 | 247 |
| 228 // Helper class that just stores the report from the callback. | 248 // Helper class that just stores the report from the callback. |
| 229 class MockRTCStatsCollectorCallback : public webrtc::RTCStatsCollectorCallback { | 249 class MockRTCStatsCollectorCallback : public webrtc::RTCStatsCollectorCallback { |
| 230 public: | 250 public: |
| 231 rtc::scoped_refptr<const RTCStatsReport> report() { return report_; } | 251 rtc::scoped_refptr<const RTCStatsReport> report() { return report_; } |
| 232 | 252 |
| 233 bool called() const { return called_; } | 253 bool called() const { return called_; } |
| 234 | 254 |
| 235 protected: | 255 protected: |
| 236 void OnStatsDelivered( | 256 void OnStatsDelivered( |
| 237 const rtc::scoped_refptr<const RTCStatsReport>& report) override { | 257 const rtc::scoped_refptr<const RTCStatsReport>& report) override { |
| 238 report_ = report; | 258 report_ = report; |
| 239 called_ = true; | 259 called_ = true; |
| 240 } | 260 } |
| 241 | 261 |
| 242 private: | 262 private: |
| 243 bool called_ = false; | 263 bool called_ = false; |
| 244 rtc::scoped_refptr<const RTCStatsReport> report_; | 264 rtc::scoped_refptr<const RTCStatsReport> report_; |
| 245 }; | 265 }; |
| 246 | 266 |
| 247 } // namespace webrtc | 267 } // namespace webrtc |
| 248 | 268 |
| 249 #endif // WEBRTC_PC_TEST_MOCKPEERCONNECTIONOBSERVERS_H_ | 269 #endif // WEBRTC_PC_TEST_MOCKPEERCONNECTIONOBSERVERS_H_ |
| OLD | NEW |