hbos | d565b73 | 2016-08-30 14:04:35 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 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 |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #include "pc/rtcstatscollector.h" |
hbos | d565b73 | 2016-08-30 14:04:35 -0700 | [diff] [blame] | 12 | |
hbos | 9e30274 | 2017-01-20 02:47:10 -0800 | [diff] [blame] | 13 | #include <initializer_list> |
hbos | d565b73 | 2016-08-30 14:04:35 -0700 | [diff] [blame] | 14 | #include <memory> |
hbos | da389e3 | 2016-10-25 10:55:08 -0700 | [diff] [blame] | 15 | #include <ostream> |
hbos | d565b73 | 2016-08-30 14:04:35 -0700 | [diff] [blame] | 16 | #include <string> |
Steve Anton | 36b29d1 | 2017-10-30 09:57:42 -0700 | [diff] [blame] | 17 | #include <utility> |
hbos | d565b73 | 2016-08-30 14:04:35 -0700 | [diff] [blame] | 18 | #include <vector> |
| 19 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 20 | #include "api/jsepsessiondescription.h" |
| 21 | #include "api/rtpparameters.h" |
| 22 | #include "api/stats/rtcstats_objects.h" |
| 23 | #include "api/stats/rtcstatsreport.h" |
| 24 | #include "api/test/mock_rtpreceiver.h" |
| 25 | #include "api/test/mock_rtpsender.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 26 | #include "media/base/fakemediaengine.h" |
| 27 | #include "media/base/test/mock_mediachannel.h" |
| 28 | #include "p2p/base/p2pconstants.h" |
| 29 | #include "p2p/base/port.h" |
| 30 | #include "pc/mediastream.h" |
| 31 | #include "pc/mediastreamtrack.h" |
| 32 | #include "pc/test/mock_datachannel.h" |
| 33 | #include "pc/test/mock_peerconnection.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 34 | #include "pc/test/rtcstatsobtainer.h" |
| 35 | #include "rtc_base/checks.h" |
| 36 | #include "rtc_base/fakeclock.h" |
| 37 | #include "rtc_base/fakesslidentity.h" |
| 38 | #include "rtc_base/gunit.h" |
| 39 | #include "rtc_base/logging.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 40 | #include "rtc_base/thread_checker.h" |
| 41 | #include "rtc_base/timedelta.h" |
| 42 | #include "rtc_base/timeutils.h" |
hbos | d565b73 | 2016-08-30 14:04:35 -0700 | [diff] [blame] | 43 | |
hbos | 6ab97ce | 2016-10-03 14:16:56 -0700 | [diff] [blame] | 44 | using testing::_; |
| 45 | using testing::Invoke; |
hbos | d565b73 | 2016-08-30 14:04:35 -0700 | [diff] [blame] | 46 | using testing::Return; |
hbos | 6ded190 | 2016-11-01 01:50:46 -0700 | [diff] [blame] | 47 | using testing::ReturnNull; |
hbos | d565b73 | 2016-08-30 14:04:35 -0700 | [diff] [blame] | 48 | using testing::ReturnRef; |
hbos | 6ded190 | 2016-11-01 01:50:46 -0700 | [diff] [blame] | 49 | using testing::SetArgPointee; |
hbos | d565b73 | 2016-08-30 14:04:35 -0700 | [diff] [blame] | 50 | |
| 51 | namespace webrtc { |
| 52 | |
hbos | da389e3 | 2016-10-25 10:55:08 -0700 | [diff] [blame] | 53 | // These are used by gtest code, such as if |EXPECT_EQ| fails. |
| 54 | void PrintTo(const RTCCertificateStats& stats, ::std::ostream* os) { |
ehmaldonado | 35a872c | 2017-07-28 07:29:12 -0700 | [diff] [blame] | 55 | *os << stats.ToJson(); |
hbos | da389e3 | 2016-10-25 10:55:08 -0700 | [diff] [blame] | 56 | } |
| 57 | |
hbos | 0adb828 | 2016-11-23 02:32:06 -0800 | [diff] [blame] | 58 | void PrintTo(const RTCCodecStats& stats, ::std::ostream* os) { |
ehmaldonado | 35a872c | 2017-07-28 07:29:12 -0700 | [diff] [blame] | 59 | *os << stats.ToJson(); |
hbos | 0adb828 | 2016-11-23 02:32:06 -0800 | [diff] [blame] | 60 | } |
| 61 | |
hbos | da389e3 | 2016-10-25 10:55:08 -0700 | [diff] [blame] | 62 | void PrintTo(const RTCDataChannelStats& stats, ::std::ostream* os) { |
ehmaldonado | 35a872c | 2017-07-28 07:29:12 -0700 | [diff] [blame] | 63 | *os << stats.ToJson(); |
hbos | da389e3 | 2016-10-25 10:55:08 -0700 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | void PrintTo(const RTCIceCandidatePairStats& stats, ::std::ostream* os) { |
ehmaldonado | 35a872c | 2017-07-28 07:29:12 -0700 | [diff] [blame] | 67 | *os << stats.ToJson(); |
hbos | da389e3 | 2016-10-25 10:55:08 -0700 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | void PrintTo(const RTCLocalIceCandidateStats& stats, ::std::ostream* os) { |
ehmaldonado | 35a872c | 2017-07-28 07:29:12 -0700 | [diff] [blame] | 71 | *os << stats.ToJson(); |
hbos | da389e3 | 2016-10-25 10:55:08 -0700 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | void PrintTo(const RTCRemoteIceCandidateStats& stats, ::std::ostream* os) { |
ehmaldonado | 35a872c | 2017-07-28 07:29:12 -0700 | [diff] [blame] | 75 | *os << stats.ToJson(); |
hbos | da389e3 | 2016-10-25 10:55:08 -0700 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | void PrintTo(const RTCPeerConnectionStats& stats, ::std::ostream* os) { |
ehmaldonado | 35a872c | 2017-07-28 07:29:12 -0700 | [diff] [blame] | 79 | *os << stats.ToJson(); |
hbos | da389e3 | 2016-10-25 10:55:08 -0700 | [diff] [blame] | 80 | } |
| 81 | |
hbos | 09bc128 | 2016-11-08 06:29:22 -0800 | [diff] [blame] | 82 | void PrintTo(const RTCMediaStreamStats& stats, ::std::ostream* os) { |
ehmaldonado | 35a872c | 2017-07-28 07:29:12 -0700 | [diff] [blame] | 83 | *os << stats.ToJson(); |
hbos | 09bc128 | 2016-11-08 06:29:22 -0800 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | void PrintTo(const RTCMediaStreamTrackStats& stats, ::std::ostream* os) { |
ehmaldonado | 35a872c | 2017-07-28 07:29:12 -0700 | [diff] [blame] | 87 | *os << stats.ToJson(); |
hbos | 09bc128 | 2016-11-08 06:29:22 -0800 | [diff] [blame] | 88 | } |
| 89 | |
hbos | eeafe94 | 2016-11-01 03:00:17 -0700 | [diff] [blame] | 90 | void PrintTo(const RTCInboundRTPStreamStats& stats, ::std::ostream* os) { |
ehmaldonado | 35a872c | 2017-07-28 07:29:12 -0700 | [diff] [blame] | 91 | *os << stats.ToJson(); |
hbos | eeafe94 | 2016-11-01 03:00:17 -0700 | [diff] [blame] | 92 | } |
| 93 | |
hbos | 6ded190 | 2016-11-01 01:50:46 -0700 | [diff] [blame] | 94 | void PrintTo(const RTCOutboundRTPStreamStats& stats, ::std::ostream* os) { |
ehmaldonado | 35a872c | 2017-07-28 07:29:12 -0700 | [diff] [blame] | 95 | *os << stats.ToJson(); |
hbos | 6ded190 | 2016-11-01 01:50:46 -0700 | [diff] [blame] | 96 | } |
| 97 | |
hbos | da389e3 | 2016-10-25 10:55:08 -0700 | [diff] [blame] | 98 | void PrintTo(const RTCTransportStats& stats, ::std::ostream* os) { |
ehmaldonado | 35a872c | 2017-07-28 07:29:12 -0700 | [diff] [blame] | 99 | *os << stats.ToJson(); |
hbos | da389e3 | 2016-10-25 10:55:08 -0700 | [diff] [blame] | 100 | } |
| 101 | |
hbos | c82f2e1 | 2016-09-05 01:36:50 -0700 | [diff] [blame] | 102 | namespace { |
| 103 | |
| 104 | const int64_t kGetStatsReportTimeoutMs = 1000; |
deadbeef | ac22f70 | 2017-01-12 21:59:29 -0800 | [diff] [blame] | 105 | const bool kDefaultRtcpMuxRequired = true; |
deadbeef | 7af91dd | 2016-12-13 11:29:11 -0800 | [diff] [blame] | 106 | const bool kDefaultSrtpRequired = true; |
hbos | c82f2e1 | 2016-09-05 01:36:50 -0700 | [diff] [blame] | 107 | |
hbos | 6ab97ce | 2016-10-03 14:16:56 -0700 | [diff] [blame] | 108 | struct CertificateInfo { |
| 109 | rtc::scoped_refptr<rtc::RTCCertificate> certificate; |
| 110 | std::vector<std::string> ders; |
| 111 | std::vector<std::string> pems; |
| 112 | std::vector<std::string> fingerprints; |
| 113 | }; |
| 114 | |
| 115 | std::unique_ptr<CertificateInfo> CreateFakeCertificateAndInfoFromDers( |
| 116 | const std::vector<std::string>& ders) { |
| 117 | RTC_CHECK(!ders.empty()); |
| 118 | std::unique_ptr<CertificateInfo> info(new CertificateInfo()); |
| 119 | info->ders = ders; |
| 120 | for (const std::string& der : ders) { |
| 121 | info->pems.push_back(rtc::SSLIdentity::DerToPem( |
| 122 | "CERTIFICATE", |
| 123 | reinterpret_cast<const unsigned char*>(der.c_str()), |
| 124 | der.length())); |
| 125 | } |
| 126 | info->certificate = |
| 127 | rtc::RTCCertificate::Create(std::unique_ptr<rtc::FakeSSLIdentity>( |
| 128 | new rtc::FakeSSLIdentity(rtc::FakeSSLCertificate(info->pems)))); |
| 129 | // Strip header/footer and newline characters of PEM strings. |
| 130 | for (size_t i = 0; i < info->pems.size(); ++i) { |
| 131 | rtc::replace_substrs("-----BEGIN CERTIFICATE-----", 27, |
| 132 | "", 0, &info->pems[i]); |
| 133 | rtc::replace_substrs("-----END CERTIFICATE-----", 25, |
| 134 | "", 0, &info->pems[i]); |
| 135 | rtc::replace_substrs("\n", 1, |
| 136 | "", 0, &info->pems[i]); |
| 137 | } |
| 138 | // Fingerprint of leaf certificate. |
| 139 | std::unique_ptr<rtc::SSLFingerprint> fp( |
| 140 | rtc::SSLFingerprint::Create("sha-1", |
| 141 | &info->certificate->ssl_certificate())); |
| 142 | EXPECT_TRUE(fp); |
| 143 | info->fingerprints.push_back(fp->GetRfc4572Fingerprint()); |
| 144 | // Fingerprints of the rest of the chain. |
| 145 | std::unique_ptr<rtc::SSLCertChain> chain = |
| 146 | info->certificate->ssl_certificate().GetChain(); |
| 147 | if (chain) { |
| 148 | for (size_t i = 0; i < chain->GetSize(); i++) { |
| 149 | fp.reset(rtc::SSLFingerprint::Create("sha-1", &chain->Get(i))); |
| 150 | EXPECT_TRUE(fp); |
| 151 | info->fingerprints.push_back(fp->GetRfc4572Fingerprint()); |
| 152 | } |
| 153 | } |
| 154 | EXPECT_EQ(info->ders.size(), info->fingerprints.size()); |
| 155 | return info; |
| 156 | } |
| 157 | |
hbos | ab9f6e4 | 2016-10-07 02:18:47 -0700 | [diff] [blame] | 158 | std::unique_ptr<cricket::Candidate> CreateFakeCandidate( |
| 159 | const std::string& hostname, |
| 160 | int port, |
| 161 | const std::string& protocol, |
Gary Liu | 37e489c | 2017-11-21 10:49:36 -0800 | [diff] [blame] | 162 | const rtc::AdapterType adapter_type, |
hbos | ab9f6e4 | 2016-10-07 02:18:47 -0700 | [diff] [blame] | 163 | const std::string& candidate_type, |
| 164 | uint32_t priority) { |
| 165 | std::unique_ptr<cricket::Candidate> candidate(new cricket::Candidate()); |
| 166 | candidate->set_address(rtc::SocketAddress(hostname, port)); |
| 167 | candidate->set_protocol(protocol); |
Gary Liu | 37e489c | 2017-11-21 10:49:36 -0800 | [diff] [blame] | 168 | candidate->set_network_type(adapter_type); |
hbos | ab9f6e4 | 2016-10-07 02:18:47 -0700 | [diff] [blame] | 169 | candidate->set_type(candidate_type); |
| 170 | candidate->set_priority(priority); |
| 171 | return candidate; |
| 172 | } |
| 173 | |
hbos | 09bc128 | 2016-11-08 06:29:22 -0800 | [diff] [blame] | 174 | class FakeAudioTrackForStats |
| 175 | : public MediaStreamTrack<AudioTrackInterface> { |
| 176 | public: |
| 177 | static rtc::scoped_refptr<FakeAudioTrackForStats> Create( |
| 178 | const std::string& id, |
hbos | 9e30274 | 2017-01-20 02:47:10 -0800 | [diff] [blame] | 179 | MediaStreamTrackInterface::TrackState state) { |
hbos | 09bc128 | 2016-11-08 06:29:22 -0800 | [diff] [blame] | 180 | rtc::scoped_refptr<FakeAudioTrackForStats> audio_track_stats( |
hbos | 9e30274 | 2017-01-20 02:47:10 -0800 | [diff] [blame] | 181 | new rtc::RefCountedObject<FakeAudioTrackForStats>(id)); |
hbos | 09bc128 | 2016-11-08 06:29:22 -0800 | [diff] [blame] | 182 | audio_track_stats->set_state(state); |
| 183 | return audio_track_stats; |
| 184 | } |
| 185 | |
Steve Anton | 36b29d1 | 2017-10-30 09:57:42 -0700 | [diff] [blame] | 186 | explicit FakeAudioTrackForStats(const std::string& id) |
| 187 | : MediaStreamTrack<AudioTrackInterface>(id) {} |
hbos | 09bc128 | 2016-11-08 06:29:22 -0800 | [diff] [blame] | 188 | |
| 189 | std::string kind() const override { |
| 190 | return MediaStreamTrackInterface::kAudioKind; |
| 191 | } |
| 192 | webrtc::AudioSourceInterface* GetSource() const override { return nullptr; } |
| 193 | void AddSink(webrtc::AudioTrackSinkInterface* sink) override {} |
| 194 | void RemoveSink(webrtc::AudioTrackSinkInterface* sink) override {} |
hbos | 9e30274 | 2017-01-20 02:47:10 -0800 | [diff] [blame] | 195 | bool GetSignalLevel(int* level) override { return false; } |
hbos | 09bc128 | 2016-11-08 06:29:22 -0800 | [diff] [blame] | 196 | rtc::scoped_refptr<AudioProcessorInterface> GetAudioProcessor() override { |
hbos | 9e30274 | 2017-01-20 02:47:10 -0800 | [diff] [blame] | 197 | return nullptr; |
hbos | 09bc128 | 2016-11-08 06:29:22 -0800 | [diff] [blame] | 198 | } |
hbos | 09bc128 | 2016-11-08 06:29:22 -0800 | [diff] [blame] | 199 | }; |
| 200 | |
| 201 | class FakeVideoTrackForStats |
| 202 | : public MediaStreamTrack<VideoTrackInterface> { |
| 203 | public: |
| 204 | static rtc::scoped_refptr<FakeVideoTrackForStats> Create( |
| 205 | const std::string& id, |
hbos | 9e30274 | 2017-01-20 02:47:10 -0800 | [diff] [blame] | 206 | MediaStreamTrackInterface::TrackState state) { |
hbos | 09bc128 | 2016-11-08 06:29:22 -0800 | [diff] [blame] | 207 | rtc::scoped_refptr<FakeVideoTrackForStats> video_track( |
hbos | 9e30274 | 2017-01-20 02:47:10 -0800 | [diff] [blame] | 208 | new rtc::RefCountedObject<FakeVideoTrackForStats>(id)); |
hbos | 09bc128 | 2016-11-08 06:29:22 -0800 | [diff] [blame] | 209 | video_track->set_state(state); |
| 210 | return video_track; |
| 211 | } |
| 212 | |
Steve Anton | 36b29d1 | 2017-10-30 09:57:42 -0700 | [diff] [blame] | 213 | explicit FakeVideoTrackForStats(const std::string& id) |
| 214 | : MediaStreamTrack<VideoTrackInterface>(id) {} |
hbos | 09bc128 | 2016-11-08 06:29:22 -0800 | [diff] [blame] | 215 | |
| 216 | std::string kind() const override { |
| 217 | return MediaStreamTrackInterface::kVideoKind; |
| 218 | } |
perkj | 773be36 | 2017-07-31 23:22:01 -0700 | [diff] [blame] | 219 | |
| 220 | void AddOrUpdateSink(rtc::VideoSinkInterface<VideoFrame>* sink, |
| 221 | const rtc::VideoSinkWants& wants) override{}; |
| 222 | void RemoveSink(rtc::VideoSinkInterface<VideoFrame>* sink) override{}; |
| 223 | |
hbos | 9e30274 | 2017-01-20 02:47:10 -0800 | [diff] [blame] | 224 | VideoTrackSourceInterface* GetSource() const override { return nullptr; } |
hbos | 09bc128 | 2016-11-08 06:29:22 -0800 | [diff] [blame] | 225 | }; |
| 226 | |
hbos | 84abeb1 | 2017-01-16 06:16:44 -0800 | [diff] [blame] | 227 | rtc::scoped_refptr<MediaStreamTrackInterface> CreateFakeTrack( |
| 228 | cricket::MediaType media_type, |
hbos | 9e30274 | 2017-01-20 02:47:10 -0800 | [diff] [blame] | 229 | const std::string& track_id, |
| 230 | MediaStreamTrackInterface::TrackState track_state) { |
hbos | 84abeb1 | 2017-01-16 06:16:44 -0800 | [diff] [blame] | 231 | if (media_type == cricket::MEDIA_TYPE_AUDIO) { |
hbos | 9e30274 | 2017-01-20 02:47:10 -0800 | [diff] [blame] | 232 | return FakeAudioTrackForStats::Create(track_id, track_state); |
hbos | 84abeb1 | 2017-01-16 06:16:44 -0800 | [diff] [blame] | 233 | } else { |
| 234 | RTC_DCHECK_EQ(media_type, cricket::MEDIA_TYPE_VIDEO); |
hbos | 9e30274 | 2017-01-20 02:47:10 -0800 | [diff] [blame] | 235 | return FakeVideoTrackForStats::Create(track_id, track_state); |
hbos | 84abeb1 | 2017-01-16 06:16:44 -0800 | [diff] [blame] | 236 | } |
| 237 | } |
| 238 | |
hbos | 9e30274 | 2017-01-20 02:47:10 -0800 | [diff] [blame] | 239 | rtc::scoped_refptr<MockRtpSender> CreateMockSender( |
Mirko Bonadei | c61ce0d | 2017-11-21 17:04:20 +0100 | [diff] [blame] | 240 | const rtc::scoped_refptr<MediaStreamTrackInterface>& track, |
| 241 | uint32_t ssrc) { |
hbos | 9e30274 | 2017-01-20 02:47:10 -0800 | [diff] [blame] | 242 | rtc::scoped_refptr<MockRtpSender> sender( |
| 243 | new rtc::RefCountedObject<MockRtpSender>()); |
| 244 | EXPECT_CALL(*sender, track()).WillRepeatedly(Return(track)); |
| 245 | EXPECT_CALL(*sender, ssrc()).WillRepeatedly(Return(ssrc)); |
| 246 | EXPECT_CALL(*sender, media_type()).WillRepeatedly(Return( |
| 247 | track->kind() == MediaStreamTrackInterface::kAudioKind |
| 248 | ? cricket::MEDIA_TYPE_AUDIO : cricket::MEDIA_TYPE_VIDEO)); |
| 249 | EXPECT_CALL(*sender, GetParameters()).WillRepeatedly(Invoke( |
| 250 | [ssrc]() { |
| 251 | RtpParameters params; |
| 252 | params.encodings.push_back(RtpEncodingParameters()); |
Oskar Sundbom | cbc71b2 | 2017-11-16 10:56:07 +0100 | [diff] [blame] | 253 | params.encodings[0].ssrc = ssrc; |
hbos | 9e30274 | 2017-01-20 02:47:10 -0800 | [diff] [blame] | 254 | return params; |
| 255 | })); |
| 256 | return sender; |
| 257 | } |
| 258 | |
| 259 | rtc::scoped_refptr<MockRtpReceiver> CreateMockReceiver( |
Mirko Bonadei | c61ce0d | 2017-11-21 17:04:20 +0100 | [diff] [blame] | 260 | const rtc::scoped_refptr<MediaStreamTrackInterface>& track, |
| 261 | uint32_t ssrc) { |
hbos | 9e30274 | 2017-01-20 02:47:10 -0800 | [diff] [blame] | 262 | rtc::scoped_refptr<MockRtpReceiver> receiver( |
| 263 | new rtc::RefCountedObject<MockRtpReceiver>()); |
| 264 | EXPECT_CALL(*receiver, track()).WillRepeatedly(Return(track)); |
| 265 | EXPECT_CALL(*receiver, media_type()).WillRepeatedly(Return( |
| 266 | track->kind() == MediaStreamTrackInterface::kAudioKind |
| 267 | ? cricket::MEDIA_TYPE_AUDIO : cricket::MEDIA_TYPE_VIDEO)); |
| 268 | EXPECT_CALL(*receiver, GetParameters()).WillRepeatedly(Invoke( |
| 269 | [ssrc]() { |
| 270 | RtpParameters params; |
| 271 | params.encodings.push_back(RtpEncodingParameters()); |
Oskar Sundbom | cbc71b2 | 2017-11-16 10:56:07 +0100 | [diff] [blame] | 272 | params.encodings[0].ssrc = ssrc; |
hbos | 9e30274 | 2017-01-20 02:47:10 -0800 | [diff] [blame] | 273 | return params; |
| 274 | })); |
| 275 | return receiver; |
| 276 | } |
| 277 | |
hbos | c82f2e1 | 2016-09-05 01:36:50 -0700 | [diff] [blame] | 278 | class RTCStatsCollectorTestHelper : public SetSessionDescriptionObserver { |
hbos | d565b73 | 2016-08-30 14:04:35 -0700 | [diff] [blame] | 279 | public: |
hbos | c82f2e1 | 2016-09-05 01:36:50 -0700 | [diff] [blame] | 280 | RTCStatsCollectorTestHelper() |
hbos | d565b73 | 2016-08-30 14:04:35 -0700 | [diff] [blame] | 281 | : worker_thread_(rtc::Thread::Current()), |
| 282 | network_thread_(rtc::Thread::Current()), |
deadbeef | bad5dad | 2017-01-17 18:32:35 -0800 | [diff] [blame] | 283 | signaling_thread_(rtc::Thread::Current()), |
hbos | 6ded190 | 2016-11-01 01:50:46 -0700 | [diff] [blame] | 284 | media_engine_(new cricket::FakeMediaEngine()), |
Steve Anton | ba81867 | 2017-11-06 10:21:57 -0800 | [diff] [blame] | 285 | pc_factory_(new FakePeerConnectionFactory( |
| 286 | std::unique_ptr<cricket::MediaEngineInterface>(media_engine_))), |
Steve Anton | 75737c0 | 2017-11-06 10:37:17 -0800 | [diff] [blame] | 287 | pc_(pc_factory_) { |
hbos | 6ab97ce | 2016-10-03 14:16:56 -0700 | [diff] [blame] | 288 | // Default return values for mocks. |
Harald Alvestrand | 8906187 | 2018-01-02 14:08:34 +0100 | [diff] [blame] | 289 | EXPECT_CALL(pc_, GetCallStats()).WillRepeatedly(Return(Call::Stats())); |
hbos | 09bc128 | 2016-11-08 06:29:22 -0800 | [diff] [blame] | 290 | EXPECT_CALL(pc_, local_streams()).WillRepeatedly(Return(nullptr)); |
| 291 | EXPECT_CALL(pc_, remote_streams()).WillRepeatedly(Return(nullptr)); |
hbos | 84abeb1 | 2017-01-16 06:16:44 -0800 | [diff] [blame] | 292 | EXPECT_CALL(pc_, GetSenders()).WillRepeatedly(Return( |
| 293 | std::vector<rtc::scoped_refptr<RtpSenderInterface>>())); |
| 294 | EXPECT_CALL(pc_, GetReceivers()).WillRepeatedly(Return( |
| 295 | std::vector<rtc::scoped_refptr<RtpReceiverInterface>>())); |
hbos | d565b73 | 2016-08-30 14:04:35 -0700 | [diff] [blame] | 296 | EXPECT_CALL(pc_, sctp_data_channels()).WillRepeatedly( |
| 297 | ReturnRef(data_channels_)); |
Steve Anton | 75737c0 | 2017-11-06 10:37:17 -0800 | [diff] [blame] | 298 | EXPECT_CALL(pc_, video_channel()).WillRepeatedly(ReturnNull()); |
| 299 | EXPECT_CALL(pc_, voice_channel()).WillRepeatedly(ReturnNull()); |
| 300 | EXPECT_CALL(pc_, GetSessionStats(_)).WillRepeatedly(ReturnNull()); |
| 301 | EXPECT_CALL(pc_, GetLocalCertificate(_, _)).WillRepeatedly(Return(false)); |
| 302 | EXPECT_CALL(pc_, GetRemoteSSLCertificate_ReturnsRawPointer(_)) |
hbos | ab9f6e4 | 2016-10-07 02:18:47 -0700 | [diff] [blame] | 303 | .WillRepeatedly(Return(nullptr)); |
hbos | d565b73 | 2016-08-30 14:04:35 -0700 | [diff] [blame] | 304 | } |
| 305 | |
hbos | fdafab8 | 2016-09-14 06:02:13 -0700 | [diff] [blame] | 306 | rtc::ScopedFakeClock& fake_clock() { return fake_clock_; } |
hbos | 6ded190 | 2016-11-01 01:50:46 -0700 | [diff] [blame] | 307 | rtc::Thread* worker_thread() { return worker_thread_; } |
| 308 | rtc::Thread* network_thread() { return network_thread_; } |
deadbeef | bad5dad | 2017-01-17 18:32:35 -0800 | [diff] [blame] | 309 | rtc::Thread* signaling_thread() { return signaling_thread_; } |
hbos | 6ded190 | 2016-11-01 01:50:46 -0700 | [diff] [blame] | 310 | cricket::FakeMediaEngine* media_engine() { return media_engine_; } |
hbos | d565b73 | 2016-08-30 14:04:35 -0700 | [diff] [blame] | 311 | MockPeerConnection& pc() { return pc_; } |
| 312 | std::vector<rtc::scoped_refptr<DataChannel>>& data_channels() { |
| 313 | return data_channels_; |
| 314 | } |
| 315 | |
| 316 | // SetSessionDescriptionObserver overrides. |
| 317 | void OnSuccess() override {} |
| 318 | void OnFailure(const std::string& error) override { |
| 319 | RTC_NOTREACHED() << error; |
| 320 | } |
| 321 | |
hbos | 84abeb1 | 2017-01-16 06:16:44 -0800 | [diff] [blame] | 322 | void SetupLocalTrackAndSender(cricket::MediaType media_type, |
| 323 | const std::string& track_id, |
Harald Alvestrand | 8906187 | 2018-01-02 14:08:34 +0100 | [diff] [blame] | 324 | uint32_t ssrc, |
| 325 | bool add_stream) { |
hbos | 84abeb1 | 2017-01-16 06:16:44 -0800 | [diff] [blame] | 326 | rtc::scoped_refptr<StreamCollection> local_streams = |
| 327 | StreamCollection::Create(); |
| 328 | EXPECT_CALL(pc_, local_streams()) |
| 329 | .WillRepeatedly(Return(local_streams)); |
| 330 | |
Harald Alvestrand | 8906187 | 2018-01-02 14:08:34 +0100 | [diff] [blame] | 331 | rtc::scoped_refptr<MediaStream> local_stream; |
| 332 | if (add_stream) { |
| 333 | local_stream = MediaStream::Create("LocalStreamLabel"); |
| 334 | local_streams->AddStream(local_stream); |
| 335 | } |
hbos | 84abeb1 | 2017-01-16 06:16:44 -0800 | [diff] [blame] | 336 | |
| 337 | rtc::scoped_refptr<MediaStreamTrackInterface> track; |
| 338 | if (media_type == cricket::MEDIA_TYPE_AUDIO) { |
hbos | 9e30274 | 2017-01-20 02:47:10 -0800 | [diff] [blame] | 339 | track = CreateFakeTrack(media_type, track_id, |
| 340 | MediaStreamTrackInterface::kLive); |
Harald Alvestrand | 8906187 | 2018-01-02 14:08:34 +0100 | [diff] [blame] | 341 | if (add_stream) { |
| 342 | local_stream->AddTrack(static_cast<AudioTrackInterface*>(track.get())); |
| 343 | } |
hbos | 84abeb1 | 2017-01-16 06:16:44 -0800 | [diff] [blame] | 344 | } else { |
hbos | 9e30274 | 2017-01-20 02:47:10 -0800 | [diff] [blame] | 345 | track = CreateFakeTrack(media_type, track_id, |
| 346 | MediaStreamTrackInterface::kLive); |
Harald Alvestrand | 8906187 | 2018-01-02 14:08:34 +0100 | [diff] [blame] | 347 | if (add_stream) { |
| 348 | local_stream->AddTrack(static_cast<VideoTrackInterface*>(track.get())); |
| 349 | } |
hbos | 84abeb1 | 2017-01-16 06:16:44 -0800 | [diff] [blame] | 350 | } |
| 351 | |
hbos | 9e30274 | 2017-01-20 02:47:10 -0800 | [diff] [blame] | 352 | rtc::scoped_refptr<MockRtpSender> sender = CreateMockSender(track, ssrc); |
hbos | 84abeb1 | 2017-01-16 06:16:44 -0800 | [diff] [blame] | 353 | EXPECT_CALL(pc_, GetSenders()).WillRepeatedly(Return( |
| 354 | std::vector<rtc::scoped_refptr<RtpSenderInterface>>({ |
| 355 | rtc::scoped_refptr<RtpSenderInterface>(sender.get()) }))); |
| 356 | } |
| 357 | |
| 358 | void SetupRemoteTrackAndReceiver(cricket::MediaType media_type, |
| 359 | const std::string& track_id, |
| 360 | uint32_t ssrc) { |
| 361 | rtc::scoped_refptr<StreamCollection> remote_streams = |
| 362 | StreamCollection::Create(); |
| 363 | EXPECT_CALL(pc_, remote_streams()) |
| 364 | .WillRepeatedly(Return(remote_streams)); |
| 365 | |
| 366 | rtc::scoped_refptr<MediaStream> remote_stream = |
| 367 | MediaStream::Create("RemoteStreamLabel"); |
| 368 | remote_streams->AddStream(remote_stream); |
| 369 | |
| 370 | rtc::scoped_refptr<MediaStreamTrackInterface> track; |
| 371 | if (media_type == cricket::MEDIA_TYPE_AUDIO) { |
hbos | 9e30274 | 2017-01-20 02:47:10 -0800 | [diff] [blame] | 372 | track = CreateFakeTrack(media_type, track_id, |
| 373 | MediaStreamTrackInterface::kLive); |
hbos | 84abeb1 | 2017-01-16 06:16:44 -0800 | [diff] [blame] | 374 | remote_stream->AddTrack(static_cast<AudioTrackInterface*>(track.get())); |
| 375 | } else { |
hbos | 9e30274 | 2017-01-20 02:47:10 -0800 | [diff] [blame] | 376 | track = CreateFakeTrack(media_type, track_id, |
| 377 | MediaStreamTrackInterface::kLive); |
hbos | 84abeb1 | 2017-01-16 06:16:44 -0800 | [diff] [blame] | 378 | remote_stream->AddTrack(static_cast<VideoTrackInterface*>(track.get())); |
| 379 | } |
| 380 | |
hbos | 9e30274 | 2017-01-20 02:47:10 -0800 | [diff] [blame] | 381 | rtc::scoped_refptr<MockRtpReceiver> receiver = |
| 382 | CreateMockReceiver(track, ssrc); |
hbos | 84abeb1 | 2017-01-16 06:16:44 -0800 | [diff] [blame] | 383 | EXPECT_CALL(pc_, GetReceivers()).WillRepeatedly(Return( |
| 384 | std::vector<rtc::scoped_refptr<RtpReceiverInterface>>({ |
| 385 | rtc::scoped_refptr<RtpReceiverInterface>(receiver.get()) }))); |
| 386 | } |
| 387 | |
hbos | 9e30274 | 2017-01-20 02:47:10 -0800 | [diff] [blame] | 388 | // Attaches tracks to peer connections by configuring RTP senders and RTP |
| 389 | // receivers according to the tracks' pairings with |
| 390 | // |[Voice/Video][Sender/Receiver]Info| and their SSRCs. Local tracks can be |
| 391 | // associated with multiple |[Voice/Video]SenderInfo|s, remote tracks can only |
| 392 | // be associated with one |[Voice/Video]ReceiverInfo|. |
| 393 | void CreateMockRtpSendersReceiversAndChannels( |
| 394 | std::initializer_list<std::pair<MediaStreamTrackInterface*, |
| 395 | cricket::VoiceSenderInfo>> local_audio_track_info_pairs, |
| 396 | std::initializer_list<std::pair<MediaStreamTrackInterface*, |
| 397 | cricket::VoiceReceiverInfo>> remote_audio_track_info_pairs, |
| 398 | std::initializer_list<std::pair<MediaStreamTrackInterface*, |
| 399 | cricket::VideoSenderInfo>> local_video_track_info_pairs, |
| 400 | std::initializer_list<std::pair<MediaStreamTrackInterface*, |
| 401 | cricket::VideoReceiverInfo>> remote_video_track_info_pairs) { |
| 402 | voice_media_info_.reset(new cricket::VoiceMediaInfo()); |
| 403 | video_media_info_.reset(new cricket::VideoMediaInfo()); |
| 404 | rtp_senders_.clear(); |
| 405 | rtp_receivers_.clear(); |
| 406 | // Local audio tracks and voice sender infos |
| 407 | for (auto& pair : local_audio_track_info_pairs) { |
| 408 | MediaStreamTrackInterface* local_audio_track = pair.first; |
| 409 | const cricket::VoiceSenderInfo& voice_sender_info = pair.second; |
| 410 | RTC_DCHECK_EQ(local_audio_track->kind(), |
| 411 | MediaStreamTrackInterface::kAudioKind); |
| 412 | |
| 413 | voice_media_info_->senders.push_back(voice_sender_info); |
| 414 | rtc::scoped_refptr<MockRtpSender> rtp_sender = |
| 415 | CreateMockSender(rtc::scoped_refptr<MediaStreamTrackInterface>( |
| 416 | local_audio_track), |
| 417 | voice_sender_info.local_stats[0].ssrc); |
| 418 | rtp_senders_.push_back(rtc::scoped_refptr<RtpSenderInterface>( |
| 419 | rtp_sender.get())); |
| 420 | } |
| 421 | // Remote audio tracks and voice receiver infos |
| 422 | for (auto& pair : remote_audio_track_info_pairs) { |
| 423 | MediaStreamTrackInterface* remote_audio_track = pair.first; |
| 424 | const cricket::VoiceReceiverInfo& voice_receiver_info = pair.second; |
| 425 | RTC_DCHECK_EQ(remote_audio_track->kind(), |
| 426 | MediaStreamTrackInterface::kAudioKind); |
| 427 | |
| 428 | voice_media_info_->receivers.push_back(voice_receiver_info); |
| 429 | rtc::scoped_refptr<MockRtpReceiver> rtp_receiver = |
| 430 | CreateMockReceiver(rtc::scoped_refptr<MediaStreamTrackInterface>( |
| 431 | remote_audio_track), |
| 432 | voice_receiver_info.local_stats[0].ssrc); |
| 433 | rtp_receivers_.push_back(rtc::scoped_refptr<RtpReceiverInterface>( |
| 434 | rtp_receiver.get())); |
| 435 | } |
| 436 | // Local video tracks and video sender infos |
| 437 | for (auto& pair : local_video_track_info_pairs) { |
| 438 | MediaStreamTrackInterface* local_video_track = pair.first; |
| 439 | const cricket::VideoSenderInfo& video_sender_info = pair.second; |
| 440 | RTC_DCHECK_EQ(local_video_track->kind(), |
| 441 | MediaStreamTrackInterface::kVideoKind); |
| 442 | |
| 443 | video_media_info_->senders.push_back(video_sender_info); |
| 444 | rtc::scoped_refptr<MockRtpSender> rtp_sender = |
| 445 | CreateMockSender(rtc::scoped_refptr<MediaStreamTrackInterface>( |
| 446 | local_video_track), |
| 447 | video_sender_info.local_stats[0].ssrc); |
| 448 | rtp_senders_.push_back(rtc::scoped_refptr<RtpSenderInterface>( |
| 449 | rtp_sender.get())); |
| 450 | } |
| 451 | // Remote video tracks and video receiver infos |
| 452 | for (auto& pair : remote_video_track_info_pairs) { |
| 453 | MediaStreamTrackInterface* remote_video_track = pair.first; |
| 454 | const cricket::VideoReceiverInfo& video_receiver_info = pair.second; |
| 455 | RTC_DCHECK_EQ(remote_video_track->kind(), |
| 456 | MediaStreamTrackInterface::kVideoKind); |
| 457 | |
| 458 | video_media_info_->receivers.push_back(video_receiver_info); |
| 459 | rtc::scoped_refptr<MockRtpReceiver> rtp_receiver = |
| 460 | CreateMockReceiver(rtc::scoped_refptr<MediaStreamTrackInterface>( |
| 461 | remote_video_track), |
| 462 | video_receiver_info.local_stats[0].ssrc); |
| 463 | rtp_receivers_.push_back(rtc::scoped_refptr<RtpReceiverInterface>( |
| 464 | rtp_receiver.get())); |
| 465 | } |
| 466 | EXPECT_CALL(pc_, GetSenders()).WillRepeatedly(Return(rtp_senders_)); |
| 467 | EXPECT_CALL(pc_, GetReceivers()).WillRepeatedly(Return(rtp_receivers_)); |
| 468 | |
Steve Anton | 8699a32 | 2017-11-06 15:53:33 -0800 | [diff] [blame] | 469 | auto* voice_media_channel = new MockVoiceMediaChannel(); |
hbos | 9e30274 | 2017-01-20 02:47:10 -0800 | [diff] [blame] | 470 | voice_channel_.reset(new cricket::VoiceChannel( |
| 471 | worker_thread_, network_thread_, nullptr, media_engine_, |
Steve Anton | 8699a32 | 2017-11-06 15:53:33 -0800 | [diff] [blame] | 472 | rtc::WrapUnique(voice_media_channel), "VoiceContentName", |
| 473 | kDefaultRtcpMuxRequired, kDefaultSrtpRequired)); |
Steve Anton | 75737c0 | 2017-11-06 10:37:17 -0800 | [diff] [blame] | 474 | EXPECT_CALL(pc_, voice_channel()) |
hbos | 9e30274 | 2017-01-20 02:47:10 -0800 | [diff] [blame] | 475 | .WillRepeatedly(Return(voice_channel_.get())); |
| 476 | EXPECT_CALL(*voice_media_channel, GetStats(_)) |
| 477 | .WillOnce(DoAll(SetArgPointee<0>(*voice_media_info_), Return(true))); |
| 478 | |
Steve Anton | 8699a32 | 2017-11-06 15:53:33 -0800 | [diff] [blame] | 479 | auto* video_media_channel = new MockVideoMediaChannel(); |
hbos | 9e30274 | 2017-01-20 02:47:10 -0800 | [diff] [blame] | 480 | video_channel_.reset(new cricket::VideoChannel( |
Steve Anton | 8699a32 | 2017-11-06 15:53:33 -0800 | [diff] [blame] | 481 | worker_thread_, network_thread_, nullptr, |
| 482 | rtc::WrapUnique(video_media_channel), "VideoContentName", |
| 483 | kDefaultRtcpMuxRequired, kDefaultSrtpRequired)); |
Steve Anton | 75737c0 | 2017-11-06 10:37:17 -0800 | [diff] [blame] | 484 | EXPECT_CALL(pc_, video_channel()) |
hbos | 9e30274 | 2017-01-20 02:47:10 -0800 | [diff] [blame] | 485 | .WillRepeatedly(Return(video_channel_.get())); |
| 486 | EXPECT_CALL(*video_media_channel, GetStats(_)) |
| 487 | .WillOnce(DoAll(SetArgPointee<0>(*video_media_info_), Return(true))); |
| 488 | } |
| 489 | |
hbos | d565b73 | 2016-08-30 14:04:35 -0700 | [diff] [blame] | 490 | private: |
hbos | fdafab8 | 2016-09-14 06:02:13 -0700 | [diff] [blame] | 491 | rtc::ScopedFakeClock fake_clock_; |
hbos | 09bc128 | 2016-11-08 06:29:22 -0800 | [diff] [blame] | 492 | RtcEventLogNullImpl event_log_; |
hbos | d565b73 | 2016-08-30 14:04:35 -0700 | [diff] [blame] | 493 | rtc::Thread* const worker_thread_; |
| 494 | rtc::Thread* const network_thread_; |
deadbeef | bad5dad | 2017-01-17 18:32:35 -0800 | [diff] [blame] | 495 | rtc::Thread* const signaling_thread_; |
Steve Anton | ba81867 | 2017-11-06 10:21:57 -0800 | [diff] [blame] | 496 | // |media_engine_| is actually owned by |pc_factory_|. |
hbos | 6ded190 | 2016-11-01 01:50:46 -0700 | [diff] [blame] | 497 | cricket::FakeMediaEngine* media_engine_; |
Steve Anton | ba81867 | 2017-11-06 10:21:57 -0800 | [diff] [blame] | 498 | rtc::scoped_refptr<FakePeerConnectionFactory> pc_factory_; |
hbos | d565b73 | 2016-08-30 14:04:35 -0700 | [diff] [blame] | 499 | MockPeerConnection pc_; |
| 500 | |
| 501 | std::vector<rtc::scoped_refptr<DataChannel>> data_channels_; |
hbos | 9e30274 | 2017-01-20 02:47:10 -0800 | [diff] [blame] | 502 | std::unique_ptr<cricket::VoiceChannel> voice_channel_; |
| 503 | std::unique_ptr<cricket::VideoChannel> video_channel_; |
| 504 | std::unique_ptr<cricket::VoiceMediaInfo> voice_media_info_; |
| 505 | std::unique_ptr<cricket::VideoMediaInfo> video_media_info_; |
| 506 | std::vector<rtc::scoped_refptr<RtpSenderInterface>> rtp_senders_; |
| 507 | std::vector<rtc::scoped_refptr<RtpReceiverInterface>> rtp_receivers_; |
hbos | d565b73 | 2016-08-30 14:04:35 -0700 | [diff] [blame] | 508 | }; |
| 509 | |
hbos | c82f2e1 | 2016-09-05 01:36:50 -0700 | [diff] [blame] | 510 | class RTCTestStats : public RTCStats { |
hbos | d565b73 | 2016-08-30 14:04:35 -0700 | [diff] [blame] | 511 | public: |
hbos | fc5e050 | 2016-10-06 02:06:10 -0700 | [diff] [blame] | 512 | WEBRTC_RTCSTATS_DECL(); |
| 513 | |
hbos | c82f2e1 | 2016-09-05 01:36:50 -0700 | [diff] [blame] | 514 | RTCTestStats(const std::string& id, int64_t timestamp_us) |
| 515 | : RTCStats(id, timestamp_us), |
| 516 | dummy_stat("dummyStat") {} |
| 517 | |
hbos | c82f2e1 | 2016-09-05 01:36:50 -0700 | [diff] [blame] | 518 | RTCStatsMember<int32_t> dummy_stat; |
| 519 | }; |
| 520 | |
hbos | fc5e050 | 2016-10-06 02:06:10 -0700 | [diff] [blame] | 521 | WEBRTC_RTCSTATS_IMPL(RTCTestStats, RTCStats, "test-stats", |
| 522 | &dummy_stat); |
hbos | c82f2e1 | 2016-09-05 01:36:50 -0700 | [diff] [blame] | 523 | |
| 524 | // Overrides the stats collection to verify thread usage and that the resulting |
| 525 | // partial reports are merged. |
| 526 | class FakeRTCStatsCollector : public RTCStatsCollector, |
| 527 | public RTCStatsCollectorCallback { |
| 528 | public: |
| 529 | static rtc::scoped_refptr<FakeRTCStatsCollector> Create( |
| 530 | PeerConnection* pc, |
| 531 | int64_t cache_lifetime_us) { |
| 532 | return rtc::scoped_refptr<FakeRTCStatsCollector>( |
| 533 | new rtc::RefCountedObject<FakeRTCStatsCollector>( |
| 534 | pc, cache_lifetime_us)); |
| 535 | } |
| 536 | |
| 537 | // RTCStatsCollectorCallback implementation. |
| 538 | void OnStatsDelivered( |
| 539 | const rtc::scoped_refptr<const RTCStatsReport>& report) override { |
| 540 | EXPECT_TRUE(signaling_thread_->IsCurrent()); |
| 541 | rtc::CritScope cs(&lock_); |
| 542 | delivered_report_ = report; |
| 543 | } |
| 544 | |
| 545 | void VerifyThreadUsageAndResultsMerging() { |
| 546 | GetStatsReport(rtc::scoped_refptr<RTCStatsCollectorCallback>(this)); |
| 547 | EXPECT_TRUE_WAIT(HasVerifiedResults(), kGetStatsReportTimeoutMs); |
| 548 | } |
| 549 | |
| 550 | bool HasVerifiedResults() { |
| 551 | EXPECT_TRUE(signaling_thread_->IsCurrent()); |
| 552 | rtc::CritScope cs(&lock_); |
| 553 | if (!delivered_report_) |
| 554 | return false; |
| 555 | EXPECT_EQ(produced_on_signaling_thread_, 1); |
hbos | c82f2e1 | 2016-09-05 01:36:50 -0700 | [diff] [blame] | 556 | EXPECT_EQ(produced_on_network_thread_, 1); |
| 557 | |
| 558 | EXPECT_TRUE(delivered_report_->Get("SignalingThreadStats")); |
hbos | c82f2e1 | 2016-09-05 01:36:50 -0700 | [diff] [blame] | 559 | EXPECT_TRUE(delivered_report_->Get("NetworkThreadStats")); |
| 560 | |
| 561 | produced_on_signaling_thread_ = 0; |
hbos | c82f2e1 | 2016-09-05 01:36:50 -0700 | [diff] [blame] | 562 | produced_on_network_thread_ = 0; |
| 563 | delivered_report_ = nullptr; |
| 564 | return true; |
hbos | d565b73 | 2016-08-30 14:04:35 -0700 | [diff] [blame] | 565 | } |
| 566 | |
| 567 | protected: |
Steve Anton | 978b876 | 2017-09-29 12:15:02 -0700 | [diff] [blame] | 568 | FakeRTCStatsCollector(PeerConnection* pc, int64_t cache_lifetime) |
hbos | c82f2e1 | 2016-09-05 01:36:50 -0700 | [diff] [blame] | 569 | : RTCStatsCollector(pc, cache_lifetime), |
Steve Anton | 978b876 | 2017-09-29 12:15:02 -0700 | [diff] [blame] | 570 | signaling_thread_(pc->signaling_thread()), |
| 571 | worker_thread_(pc->worker_thread()), |
| 572 | network_thread_(pc->network_thread()) {} |
hbos | c82f2e1 | 2016-09-05 01:36:50 -0700 | [diff] [blame] | 573 | |
| 574 | void ProducePartialResultsOnSignalingThread(int64_t timestamp_us) override { |
| 575 | EXPECT_TRUE(signaling_thread_->IsCurrent()); |
| 576 | { |
| 577 | rtc::CritScope cs(&lock_); |
| 578 | EXPECT_FALSE(delivered_report_); |
| 579 | ++produced_on_signaling_thread_; |
| 580 | } |
| 581 | |
| 582 | rtc::scoped_refptr<RTCStatsReport> signaling_report = |
hbos | 6ded190 | 2016-11-01 01:50:46 -0700 | [diff] [blame] | 583 | RTCStatsReport::Create(0); |
hbos | c82f2e1 | 2016-09-05 01:36:50 -0700 | [diff] [blame] | 584 | signaling_report->AddStats(std::unique_ptr<const RTCStats>( |
| 585 | new RTCTestStats("SignalingThreadStats", timestamp_us))); |
| 586 | AddPartialResults(signaling_report); |
| 587 | } |
hbos | c82f2e1 | 2016-09-05 01:36:50 -0700 | [diff] [blame] | 588 | void ProducePartialResultsOnNetworkThread(int64_t timestamp_us) override { |
| 589 | EXPECT_TRUE(network_thread_->IsCurrent()); |
| 590 | { |
| 591 | rtc::CritScope cs(&lock_); |
| 592 | EXPECT_FALSE(delivered_report_); |
| 593 | ++produced_on_network_thread_; |
| 594 | } |
| 595 | |
| 596 | rtc::scoped_refptr<RTCStatsReport> network_report = |
hbos | 6ded190 | 2016-11-01 01:50:46 -0700 | [diff] [blame] | 597 | RTCStatsReport::Create(0); |
hbos | c82f2e1 | 2016-09-05 01:36:50 -0700 | [diff] [blame] | 598 | network_report->AddStats(std::unique_ptr<const RTCStats>( |
| 599 | new RTCTestStats("NetworkThreadStats", timestamp_us))); |
| 600 | AddPartialResults(network_report); |
| 601 | } |
| 602 | |
| 603 | private: |
| 604 | rtc::Thread* const signaling_thread_; |
| 605 | rtc::Thread* const worker_thread_; |
| 606 | rtc::Thread* const network_thread_; |
| 607 | |
| 608 | rtc::CriticalSection lock_; |
| 609 | rtc::scoped_refptr<const RTCStatsReport> delivered_report_; |
| 610 | int produced_on_signaling_thread_ = 0; |
hbos | c82f2e1 | 2016-09-05 01:36:50 -0700 | [diff] [blame] | 611 | int produced_on_network_thread_ = 0; |
hbos | d565b73 | 2016-08-30 14:04:35 -0700 | [diff] [blame] | 612 | }; |
| 613 | |
hbos | c82f2e1 | 2016-09-05 01:36:50 -0700 | [diff] [blame] | 614 | class RTCStatsCollectorTest : public testing::Test { |
| 615 | public: |
| 616 | RTCStatsCollectorTest() |
| 617 | : test_(new rtc::RefCountedObject<RTCStatsCollectorTestHelper>()), |
| 618 | collector_(RTCStatsCollector::Create( |
| 619 | &test_->pc(), 50 * rtc::kNumMicrosecsPerMillisec)) { |
| 620 | } |
| 621 | |
| 622 | rtc::scoped_refptr<const RTCStatsReport> GetStatsReport() { |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 623 | rtc::scoped_refptr<RTCStatsObtainer> callback = RTCStatsObtainer::Create(); |
hbos | c82f2e1 | 2016-09-05 01:36:50 -0700 | [diff] [blame] | 624 | collector_->GetStatsReport(callback); |
| 625 | EXPECT_TRUE_WAIT(callback->report(), kGetStatsReportTimeoutMs); |
hbos | cc555c5 | 2016-10-18 12:48:31 -0700 | [diff] [blame] | 626 | int64_t after = rtc::TimeUTCMicros(); |
| 627 | for (const RTCStats& stats : *callback->report()) { |
| 628 | EXPECT_LE(stats.timestamp_us(), after); |
| 629 | } |
hbos | c82f2e1 | 2016-09-05 01:36:50 -0700 | [diff] [blame] | 630 | return callback->report(); |
| 631 | } |
| 632 | |
hbos | 6ab97ce | 2016-10-03 14:16:56 -0700 | [diff] [blame] | 633 | void ExpectReportContainsCertificateInfo( |
| 634 | const rtc::scoped_refptr<const RTCStatsReport>& report, |
hbos | 23368e1 | 2016-12-21 04:29:17 -0800 | [diff] [blame] | 635 | const CertificateInfo& certinfo) { |
| 636 | for (size_t i = 0; i < certinfo.fingerprints.size(); ++i) { |
| 637 | RTCCertificateStats expected_certificate_stats( |
| 638 | "RTCCertificate_" + certinfo.fingerprints[i], |
| 639 | report->timestamp_us()); |
| 640 | expected_certificate_stats.fingerprint = certinfo.fingerprints[i]; |
| 641 | expected_certificate_stats.fingerprint_algorithm = "sha-1"; |
| 642 | expected_certificate_stats.base64_certificate = certinfo.pems[i]; |
| 643 | if (i + 1 < certinfo.fingerprints.size()) { |
| 644 | expected_certificate_stats.issuer_certificate_id = |
| 645 | "RTCCertificate_" + certinfo.fingerprints[i + 1]; |
hbos | 6ab97ce | 2016-10-03 14:16:56 -0700 | [diff] [blame] | 646 | } |
hbos | 23368e1 | 2016-12-21 04:29:17 -0800 | [diff] [blame] | 647 | ASSERT_TRUE(report->Get(expected_certificate_stats.id())); |
| 648 | EXPECT_EQ(expected_certificate_stats, |
| 649 | report->Get(expected_certificate_stats.id())->cast_to< |
| 650 | RTCCertificateStats>()); |
hbos | 6ab97ce | 2016-10-03 14:16:56 -0700 | [diff] [blame] | 651 | } |
| 652 | } |
| 653 | |
hbos | c82f2e1 | 2016-09-05 01:36:50 -0700 | [diff] [blame] | 654 | protected: |
| 655 | rtc::scoped_refptr<RTCStatsCollectorTestHelper> test_; |
| 656 | rtc::scoped_refptr<RTCStatsCollector> collector_; |
| 657 | }; |
| 658 | |
| 659 | TEST_F(RTCStatsCollectorTest, SingleCallback) { |
| 660 | rtc::scoped_refptr<const RTCStatsReport> result; |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 661 | collector_->GetStatsReport(RTCStatsObtainer::Create(&result)); |
hbos | c82f2e1 | 2016-09-05 01:36:50 -0700 | [diff] [blame] | 662 | EXPECT_TRUE_WAIT(result, kGetStatsReportTimeoutMs); |
| 663 | } |
| 664 | |
| 665 | TEST_F(RTCStatsCollectorTest, MultipleCallbacks) { |
| 666 | rtc::scoped_refptr<const RTCStatsReport> a; |
| 667 | rtc::scoped_refptr<const RTCStatsReport> b; |
| 668 | rtc::scoped_refptr<const RTCStatsReport> c; |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 669 | collector_->GetStatsReport(RTCStatsObtainer::Create(&a)); |
| 670 | collector_->GetStatsReport(RTCStatsObtainer::Create(&b)); |
| 671 | collector_->GetStatsReport(RTCStatsObtainer::Create(&c)); |
hbos | c82f2e1 | 2016-09-05 01:36:50 -0700 | [diff] [blame] | 672 | EXPECT_TRUE_WAIT(a, kGetStatsReportTimeoutMs); |
| 673 | EXPECT_TRUE_WAIT(b, kGetStatsReportTimeoutMs); |
| 674 | EXPECT_TRUE_WAIT(c, kGetStatsReportTimeoutMs); |
| 675 | EXPECT_EQ(a.get(), b.get()); |
| 676 | EXPECT_EQ(b.get(), c.get()); |
| 677 | } |
| 678 | |
| 679 | TEST_F(RTCStatsCollectorTest, CachedStatsReports) { |
hbos | d565b73 | 2016-08-30 14:04:35 -0700 | [diff] [blame] | 680 | // Caching should ensure |a| and |b| are the same report. |
hbos | c82f2e1 | 2016-09-05 01:36:50 -0700 | [diff] [blame] | 681 | rtc::scoped_refptr<const RTCStatsReport> a = GetStatsReport(); |
| 682 | rtc::scoped_refptr<const RTCStatsReport> b = GetStatsReport(); |
hbos | d565b73 | 2016-08-30 14:04:35 -0700 | [diff] [blame] | 683 | EXPECT_EQ(a.get(), b.get()); |
| 684 | // Invalidate cache by clearing it. |
hbos | c82f2e1 | 2016-09-05 01:36:50 -0700 | [diff] [blame] | 685 | collector_->ClearCachedStatsReport(); |
| 686 | rtc::scoped_refptr<const RTCStatsReport> c = GetStatsReport(); |
hbos | d565b73 | 2016-08-30 14:04:35 -0700 | [diff] [blame] | 687 | EXPECT_NE(b.get(), c.get()); |
| 688 | // Invalidate cache by advancing time. |
hbos | fdafab8 | 2016-09-14 06:02:13 -0700 | [diff] [blame] | 689 | test_->fake_clock().AdvanceTime(rtc::TimeDelta::FromMilliseconds(51)); |
hbos | c82f2e1 | 2016-09-05 01:36:50 -0700 | [diff] [blame] | 690 | rtc::scoped_refptr<const RTCStatsReport> d = GetStatsReport(); |
hbos | d565b73 | 2016-08-30 14:04:35 -0700 | [diff] [blame] | 691 | EXPECT_TRUE(d); |
| 692 | EXPECT_NE(c.get(), d.get()); |
| 693 | } |
| 694 | |
hbos | c82f2e1 | 2016-09-05 01:36:50 -0700 | [diff] [blame] | 695 | TEST_F(RTCStatsCollectorTest, MultipleCallbacksWithInvalidatedCacheInBetween) { |
hbos | c82f2e1 | 2016-09-05 01:36:50 -0700 | [diff] [blame] | 696 | rtc::scoped_refptr<const RTCStatsReport> a; |
| 697 | rtc::scoped_refptr<const RTCStatsReport> b; |
| 698 | rtc::scoped_refptr<const RTCStatsReport> c; |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 699 | collector_->GetStatsReport(RTCStatsObtainer::Create(&a)); |
| 700 | collector_->GetStatsReport(RTCStatsObtainer::Create(&b)); |
hbos | c82f2e1 | 2016-09-05 01:36:50 -0700 | [diff] [blame] | 701 | // Cache is invalidated after 50 ms. |
hbos | fdafab8 | 2016-09-14 06:02:13 -0700 | [diff] [blame] | 702 | test_->fake_clock().AdvanceTime(rtc::TimeDelta::FromMilliseconds(51)); |
hbos | db346a7 | 2016-11-29 01:57:01 -0800 | [diff] [blame] | 703 | collector_->GetStatsReport(RTCStatsObtainer::Create(&c)); |
hbos | c82f2e1 | 2016-09-05 01:36:50 -0700 | [diff] [blame] | 704 | EXPECT_TRUE_WAIT(a, kGetStatsReportTimeoutMs); |
| 705 | EXPECT_TRUE_WAIT(b, kGetStatsReportTimeoutMs); |
| 706 | EXPECT_TRUE_WAIT(c, kGetStatsReportTimeoutMs); |
| 707 | EXPECT_EQ(a.get(), b.get()); |
| 708 | // The act of doing |AdvanceTime| processes all messages. If this was not the |
| 709 | // case we might not require |c| to be fresher than |b|. |
| 710 | EXPECT_NE(c.get(), b.get()); |
| 711 | } |
| 712 | |
hbos | 6ab97ce | 2016-10-03 14:16:56 -0700 | [diff] [blame] | 713 | TEST_F(RTCStatsCollectorTest, CollectRTCCertificateStatsSingle) { |
| 714 | std::unique_ptr<CertificateInfo> local_certinfo = |
| 715 | CreateFakeCertificateAndInfoFromDers( |
| 716 | std::vector<std::string>({ "(local) single certificate" })); |
| 717 | std::unique_ptr<CertificateInfo> remote_certinfo = |
| 718 | CreateFakeCertificateAndInfoFromDers( |
| 719 | std::vector<std::string>({ "(remote) single certificate" })); |
| 720 | |
| 721 | // Mock the session to return the local and remote certificates. |
Steve Anton | 75737c0 | 2017-11-06 10:37:17 -0800 | [diff] [blame] | 722 | EXPECT_CALL(test_->pc(), GetSessionStats(_)) |
Steve Anton | ba81867 | 2017-11-06 10:21:57 -0800 | [diff] [blame] | 723 | .WillRepeatedly(Invoke([](const ChannelNamePairs&) { |
hbos | df6075a | 2016-12-19 04:58:02 -0800 | [diff] [blame] | 724 | std::unique_ptr<SessionStats> stats(new SessionStats()); |
hbos | 6ab97ce | 2016-10-03 14:16:56 -0700 | [diff] [blame] | 725 | stats->transport_stats["transport"].transport_name = "transport"; |
hbos | df6075a | 2016-12-19 04:58:02 -0800 | [diff] [blame] | 726 | return stats; |
hbos | 6ab97ce | 2016-10-03 14:16:56 -0700 | [diff] [blame] | 727 | })); |
Steve Anton | 75737c0 | 2017-11-06 10:37:17 -0800 | [diff] [blame] | 728 | EXPECT_CALL(test_->pc(), GetLocalCertificate(_, _)) |
| 729 | .WillRepeatedly( |
| 730 | Invoke([&local_certinfo]( |
| 731 | const std::string& transport_name, |
| 732 | rtc::scoped_refptr<rtc::RTCCertificate>* certificate) { |
| 733 | if (transport_name == "transport") { |
| 734 | *certificate = local_certinfo->certificate; |
| 735 | return true; |
| 736 | } |
| 737 | return false; |
| 738 | })); |
| 739 | EXPECT_CALL(test_->pc(), GetRemoteSSLCertificate_ReturnsRawPointer(_)) |
| 740 | .WillRepeatedly(Invoke([&remote_certinfo]( |
| 741 | const std::string& transport_name) { |
hbos | 6ab97ce | 2016-10-03 14:16:56 -0700 | [diff] [blame] | 742 | if (transport_name == "transport") |
| 743 | return remote_certinfo->certificate->ssl_certificate().GetReference(); |
| 744 | return static_cast<rtc::SSLCertificate*>(nullptr); |
| 745 | })); |
| 746 | |
| 747 | rtc::scoped_refptr<const RTCStatsReport> report = GetStatsReport(); |
hbos | 23368e1 | 2016-12-21 04:29:17 -0800 | [diff] [blame] | 748 | ExpectReportContainsCertificateInfo(report, *local_certinfo); |
| 749 | ExpectReportContainsCertificateInfo(report, *remote_certinfo); |
hbos | 6ab97ce | 2016-10-03 14:16:56 -0700 | [diff] [blame] | 750 | } |
| 751 | |
hbos | 0adb828 | 2016-11-23 02:32:06 -0800 | [diff] [blame] | 752 | TEST_F(RTCStatsCollectorTest, CollectRTCCodecStats) { |
Steve Anton | 8699a32 | 2017-11-06 15:53:33 -0800 | [diff] [blame] | 753 | auto* voice_media_channel = new MockVoiceMediaChannel(); |
hbos | 0adb828 | 2016-11-23 02:32:06 -0800 | [diff] [blame] | 754 | cricket::VoiceChannel voice_channel( |
deadbeef | bad5dad | 2017-01-17 18:32:35 -0800 | [diff] [blame] | 755 | test_->worker_thread(), test_->network_thread(), |
Steve Anton | 8699a32 | 2017-11-06 15:53:33 -0800 | [diff] [blame] | 756 | test_->signaling_thread(), test_->media_engine(), |
| 757 | rtc::WrapUnique(voice_media_channel), "VoiceContentName", |
| 758 | kDefaultRtcpMuxRequired, kDefaultSrtpRequired); |
hbos | 0adb828 | 2016-11-23 02:32:06 -0800 | [diff] [blame] | 759 | |
Steve Anton | 8699a32 | 2017-11-06 15:53:33 -0800 | [diff] [blame] | 760 | auto* video_media_channel = new MockVideoMediaChannel(); |
hbos | 0adb828 | 2016-11-23 02:32:06 -0800 | [diff] [blame] | 761 | cricket::VideoChannel video_channel( |
deadbeef | bad5dad | 2017-01-17 18:32:35 -0800 | [diff] [blame] | 762 | test_->worker_thread(), test_->network_thread(), |
Steve Anton | 8699a32 | 2017-11-06 15:53:33 -0800 | [diff] [blame] | 763 | test_->signaling_thread(), rtc::WrapUnique(video_media_channel), |
| 764 | "VideoContentName", kDefaultRtcpMuxRequired, kDefaultSrtpRequired); |
hbos | 0adb828 | 2016-11-23 02:32:06 -0800 | [diff] [blame] | 765 | |
| 766 | // Audio |
| 767 | cricket::VoiceMediaInfo voice_media_info; |
| 768 | |
| 769 | RtpCodecParameters inbound_audio_codec; |
| 770 | inbound_audio_codec.payload_type = 1; |
deadbeef | e702b30 | 2017-02-04 12:09:01 -0800 | [diff] [blame] | 771 | inbound_audio_codec.kind = cricket::MEDIA_TYPE_AUDIO; |
| 772 | inbound_audio_codec.name = "opus"; |
Oskar Sundbom | cbc71b2 | 2017-11-16 10:56:07 +0100 | [diff] [blame] | 773 | inbound_audio_codec.clock_rate = 1337; |
hbos | 0adb828 | 2016-11-23 02:32:06 -0800 | [diff] [blame] | 774 | voice_media_info.receive_codecs.insert( |
| 775 | std::make_pair(inbound_audio_codec.payload_type, inbound_audio_codec)); |
| 776 | |
| 777 | RtpCodecParameters outbound_audio_codec; |
| 778 | outbound_audio_codec.payload_type = 2; |
deadbeef | e702b30 | 2017-02-04 12:09:01 -0800 | [diff] [blame] | 779 | outbound_audio_codec.kind = cricket::MEDIA_TYPE_AUDIO; |
| 780 | outbound_audio_codec.name = "isac"; |
Oskar Sundbom | cbc71b2 | 2017-11-16 10:56:07 +0100 | [diff] [blame] | 781 | outbound_audio_codec.clock_rate = 1338; |
hbos | 0adb828 | 2016-11-23 02:32:06 -0800 | [diff] [blame] | 782 | voice_media_info.send_codecs.insert( |
| 783 | std::make_pair(outbound_audio_codec.payload_type, outbound_audio_codec)); |
| 784 | |
| 785 | EXPECT_CALL(*voice_media_channel, GetStats(_)) |
| 786 | .WillOnce(DoAll(SetArgPointee<0>(voice_media_info), Return(true))); |
| 787 | |
| 788 | // Video |
| 789 | cricket::VideoMediaInfo video_media_info; |
| 790 | |
| 791 | RtpCodecParameters inbound_video_codec; |
| 792 | inbound_video_codec.payload_type = 3; |
deadbeef | e702b30 | 2017-02-04 12:09:01 -0800 | [diff] [blame] | 793 | inbound_video_codec.kind = cricket::MEDIA_TYPE_VIDEO; |
| 794 | inbound_video_codec.name = "H264"; |
Oskar Sundbom | cbc71b2 | 2017-11-16 10:56:07 +0100 | [diff] [blame] | 795 | inbound_video_codec.clock_rate = 1339; |
hbos | 0adb828 | 2016-11-23 02:32:06 -0800 | [diff] [blame] | 796 | video_media_info.receive_codecs.insert( |
| 797 | std::make_pair(inbound_video_codec.payload_type, inbound_video_codec)); |
| 798 | |
| 799 | RtpCodecParameters outbound_video_codec; |
| 800 | outbound_video_codec.payload_type = 4; |
deadbeef | e702b30 | 2017-02-04 12:09:01 -0800 | [diff] [blame] | 801 | outbound_video_codec.kind = cricket::MEDIA_TYPE_VIDEO; |
| 802 | outbound_video_codec.name = "VP8"; |
Oskar Sundbom | cbc71b2 | 2017-11-16 10:56:07 +0100 | [diff] [blame] | 803 | outbound_video_codec.clock_rate = 1340; |
hbos | 0adb828 | 2016-11-23 02:32:06 -0800 | [diff] [blame] | 804 | video_media_info.send_codecs.insert( |
| 805 | std::make_pair(outbound_video_codec.payload_type, outbound_video_codec)); |
| 806 | |
| 807 | EXPECT_CALL(*video_media_channel, GetStats(_)) |
| 808 | .WillOnce(DoAll(SetArgPointee<0>(video_media_info), Return(true))); |
| 809 | |
| 810 | SessionStats session_stats; |
hbos | 0adb828 | 2016-11-23 02:32:06 -0800 | [diff] [blame] | 811 | session_stats.transport_stats["TransportName"].transport_name = |
| 812 | "TransportName"; |
| 813 | |
Steve Anton | 75737c0 | 2017-11-06 10:37:17 -0800 | [diff] [blame] | 814 | EXPECT_CALL(test_->pc(), GetSessionStats(_)) |
Steve Anton | ba81867 | 2017-11-06 10:21:57 -0800 | [diff] [blame] | 815 | .WillRepeatedly(Invoke([&session_stats](const ChannelNamePairs&) { |
hbos | df6075a | 2016-12-19 04:58:02 -0800 | [diff] [blame] | 816 | return std::unique_ptr<SessionStats>(new SessionStats(session_stats)); |
| 817 | })); |
Steve Anton | 75737c0 | 2017-11-06 10:37:17 -0800 | [diff] [blame] | 818 | EXPECT_CALL(test_->pc(), voice_channel()) |
hbos | 0adb828 | 2016-11-23 02:32:06 -0800 | [diff] [blame] | 819 | .WillRepeatedly(Return(&voice_channel)); |
Steve Anton | 75737c0 | 2017-11-06 10:37:17 -0800 | [diff] [blame] | 820 | EXPECT_CALL(test_->pc(), video_channel()) |
hbos | 0adb828 | 2016-11-23 02:32:06 -0800 | [diff] [blame] | 821 | .WillRepeatedly(Return(&video_channel)); |
| 822 | |
| 823 | rtc::scoped_refptr<const RTCStatsReport> report = GetStatsReport(); |
| 824 | |
| 825 | RTCCodecStats expected_inbound_audio_codec( |
| 826 | "RTCCodec_InboundAudio_1", report->timestamp_us()); |
| 827 | expected_inbound_audio_codec.payload_type = 1; |
hbos | 13f54b2 | 2017-02-28 06:56:04 -0800 | [diff] [blame] | 828 | expected_inbound_audio_codec.mime_type = "audio/opus"; |
hbos | 0adb828 | 2016-11-23 02:32:06 -0800 | [diff] [blame] | 829 | expected_inbound_audio_codec.clock_rate = 1337; |
| 830 | |
| 831 | RTCCodecStats expected_outbound_audio_codec( |
| 832 | "RTCCodec_OutboundAudio_2", report->timestamp_us()); |
| 833 | expected_outbound_audio_codec.payload_type = 2; |
hbos | 13f54b2 | 2017-02-28 06:56:04 -0800 | [diff] [blame] | 834 | expected_outbound_audio_codec.mime_type = "audio/isac"; |
hbos | 0adb828 | 2016-11-23 02:32:06 -0800 | [diff] [blame] | 835 | expected_outbound_audio_codec.clock_rate = 1338; |
| 836 | |
| 837 | RTCCodecStats expected_inbound_video_codec( |
| 838 | "RTCCodec_InboundVideo_3", report->timestamp_us()); |
| 839 | expected_inbound_video_codec.payload_type = 3; |
hbos | 13f54b2 | 2017-02-28 06:56:04 -0800 | [diff] [blame] | 840 | expected_inbound_video_codec.mime_type = "video/H264"; |
hbos | 0adb828 | 2016-11-23 02:32:06 -0800 | [diff] [blame] | 841 | expected_inbound_video_codec.clock_rate = 1339; |
| 842 | |
| 843 | RTCCodecStats expected_outbound_video_codec( |
| 844 | "RTCCodec_OutboundVideo_4", report->timestamp_us()); |
| 845 | expected_outbound_video_codec.payload_type = 4; |
hbos | 13f54b2 | 2017-02-28 06:56:04 -0800 | [diff] [blame] | 846 | expected_outbound_video_codec.mime_type = "video/VP8"; |
hbos | 0adb828 | 2016-11-23 02:32:06 -0800 | [diff] [blame] | 847 | expected_outbound_video_codec.clock_rate = 1340; |
| 848 | |
nisse | c8ee882 | 2017-01-18 07:20:55 -0800 | [diff] [blame] | 849 | ASSERT_TRUE(report->Get(expected_inbound_audio_codec.id())); |
hbos | 0adb828 | 2016-11-23 02:32:06 -0800 | [diff] [blame] | 850 | EXPECT_EQ(expected_inbound_audio_codec, |
| 851 | report->Get(expected_inbound_audio_codec.id())->cast_to< |
| 852 | RTCCodecStats>()); |
| 853 | |
nisse | c8ee882 | 2017-01-18 07:20:55 -0800 | [diff] [blame] | 854 | ASSERT_TRUE(report->Get(expected_outbound_audio_codec.id())); |
hbos | 0adb828 | 2016-11-23 02:32:06 -0800 | [diff] [blame] | 855 | EXPECT_EQ(expected_outbound_audio_codec, |
| 856 | report->Get(expected_outbound_audio_codec.id())->cast_to< |
| 857 | RTCCodecStats>()); |
| 858 | |
nisse | c8ee882 | 2017-01-18 07:20:55 -0800 | [diff] [blame] | 859 | ASSERT_TRUE(report->Get(expected_inbound_video_codec.id())); |
hbos | 0adb828 | 2016-11-23 02:32:06 -0800 | [diff] [blame] | 860 | EXPECT_EQ(expected_inbound_video_codec, |
| 861 | report->Get(expected_inbound_video_codec.id())->cast_to< |
| 862 | RTCCodecStats>()); |
| 863 | |
nisse | c8ee882 | 2017-01-18 07:20:55 -0800 | [diff] [blame] | 864 | ASSERT_TRUE(report->Get(expected_outbound_video_codec.id())); |
hbos | 0adb828 | 2016-11-23 02:32:06 -0800 | [diff] [blame] | 865 | EXPECT_EQ(expected_outbound_video_codec, |
| 866 | report->Get(expected_outbound_video_codec.id())->cast_to< |
| 867 | RTCCodecStats>()); |
| 868 | } |
| 869 | |
hbos | 6ab97ce | 2016-10-03 14:16:56 -0700 | [diff] [blame] | 870 | TEST_F(RTCStatsCollectorTest, CollectRTCCertificateStatsMultiple) { |
| 871 | std::unique_ptr<CertificateInfo> audio_local_certinfo = |
| 872 | CreateFakeCertificateAndInfoFromDers( |
| 873 | std::vector<std::string>({ "(local) audio" })); |
| 874 | audio_local_certinfo = CreateFakeCertificateAndInfoFromDers( |
| 875 | audio_local_certinfo->ders); |
| 876 | std::unique_ptr<CertificateInfo> audio_remote_certinfo = |
| 877 | CreateFakeCertificateAndInfoFromDers( |
| 878 | std::vector<std::string>({ "(remote) audio" })); |
| 879 | audio_remote_certinfo = CreateFakeCertificateAndInfoFromDers( |
| 880 | audio_remote_certinfo->ders); |
| 881 | |
| 882 | std::unique_ptr<CertificateInfo> video_local_certinfo = |
| 883 | CreateFakeCertificateAndInfoFromDers( |
| 884 | std::vector<std::string>({ "(local) video" })); |
| 885 | video_local_certinfo = CreateFakeCertificateAndInfoFromDers( |
| 886 | video_local_certinfo->ders); |
| 887 | std::unique_ptr<CertificateInfo> video_remote_certinfo = |
| 888 | CreateFakeCertificateAndInfoFromDers( |
| 889 | std::vector<std::string>({ "(remote) video" })); |
| 890 | video_remote_certinfo = CreateFakeCertificateAndInfoFromDers( |
| 891 | video_remote_certinfo->ders); |
| 892 | |
| 893 | // Mock the session to return the local and remote certificates. |
Steve Anton | 75737c0 | 2017-11-06 10:37:17 -0800 | [diff] [blame] | 894 | EXPECT_CALL(test_->pc(), GetSessionStats(_)) |
Steve Anton | ba81867 | 2017-11-06 10:21:57 -0800 | [diff] [blame] | 895 | .WillRepeatedly(Invoke([](const ChannelNamePairs&) { |
hbos | df6075a | 2016-12-19 04:58:02 -0800 | [diff] [blame] | 896 | std::unique_ptr<SessionStats> stats(new SessionStats()); |
hbos | 6ab97ce | 2016-10-03 14:16:56 -0700 | [diff] [blame] | 897 | stats->transport_stats["audio"].transport_name = "audio"; |
| 898 | stats->transport_stats["video"].transport_name = "video"; |
hbos | df6075a | 2016-12-19 04:58:02 -0800 | [diff] [blame] | 899 | return stats; |
hbos | 6ab97ce | 2016-10-03 14:16:56 -0700 | [diff] [blame] | 900 | })); |
Steve Anton | 75737c0 | 2017-11-06 10:37:17 -0800 | [diff] [blame] | 901 | EXPECT_CALL(test_->pc(), GetLocalCertificate(_, _)) |
| 902 | .WillRepeatedly( |
| 903 | Invoke([&audio_local_certinfo, &video_local_certinfo]( |
| 904 | const std::string& transport_name, |
| 905 | rtc::scoped_refptr<rtc::RTCCertificate>* certificate) { |
| 906 | if (transport_name == "audio") { |
| 907 | *certificate = audio_local_certinfo->certificate; |
| 908 | return true; |
| 909 | } |
| 910 | if (transport_name == "video") { |
| 911 | *certificate = video_local_certinfo->certificate; |
| 912 | return true; |
| 913 | } |
| 914 | return false; |
| 915 | })); |
| 916 | EXPECT_CALL(test_->pc(), GetRemoteSSLCertificate_ReturnsRawPointer(_)) |
| 917 | .WillRepeatedly(Invoke([&audio_remote_certinfo, &video_remote_certinfo]( |
| 918 | const std::string& transport_name) { |
hbos | 6ab97ce | 2016-10-03 14:16:56 -0700 | [diff] [blame] | 919 | if (transport_name == "audio") { |
| 920 | return audio_remote_certinfo->certificate->ssl_certificate() |
| 921 | .GetReference(); |
| 922 | } |
| 923 | if (transport_name == "video") { |
| 924 | return video_remote_certinfo->certificate->ssl_certificate() |
| 925 | .GetReference(); |
| 926 | } |
| 927 | return static_cast<rtc::SSLCertificate*>(nullptr); |
| 928 | })); |
| 929 | |
| 930 | rtc::scoped_refptr<const RTCStatsReport> report = GetStatsReport(); |
hbos | 23368e1 | 2016-12-21 04:29:17 -0800 | [diff] [blame] | 931 | ExpectReportContainsCertificateInfo(report, *audio_local_certinfo); |
| 932 | ExpectReportContainsCertificateInfo(report, *audio_remote_certinfo); |
| 933 | ExpectReportContainsCertificateInfo(report, *video_local_certinfo); |
| 934 | ExpectReportContainsCertificateInfo(report, *video_remote_certinfo); |
hbos | 6ab97ce | 2016-10-03 14:16:56 -0700 | [diff] [blame] | 935 | } |
| 936 | |
| 937 | TEST_F(RTCStatsCollectorTest, CollectRTCCertificateStatsChain) { |
| 938 | std::vector<std::string> local_ders; |
| 939 | local_ders.push_back("(local) this"); |
| 940 | local_ders.push_back("(local) is"); |
| 941 | local_ders.push_back("(local) a"); |
| 942 | local_ders.push_back("(local) chain"); |
| 943 | std::unique_ptr<CertificateInfo> local_certinfo = |
| 944 | CreateFakeCertificateAndInfoFromDers(local_ders); |
| 945 | std::vector<std::string> remote_ders; |
| 946 | remote_ders.push_back("(remote) this"); |
| 947 | remote_ders.push_back("(remote) is"); |
| 948 | remote_ders.push_back("(remote) another"); |
| 949 | remote_ders.push_back("(remote) chain"); |
| 950 | std::unique_ptr<CertificateInfo> remote_certinfo = |
| 951 | CreateFakeCertificateAndInfoFromDers(remote_ders); |
| 952 | |
| 953 | // Mock the session to return the local and remote certificates. |
Steve Anton | 75737c0 | 2017-11-06 10:37:17 -0800 | [diff] [blame] | 954 | EXPECT_CALL(test_->pc(), GetSessionStats(_)) |
Steve Anton | ba81867 | 2017-11-06 10:21:57 -0800 | [diff] [blame] | 955 | .WillRepeatedly(Invoke([](const ChannelNamePairs&) { |
hbos | df6075a | 2016-12-19 04:58:02 -0800 | [diff] [blame] | 956 | std::unique_ptr<SessionStats> stats(new SessionStats()); |
hbos | 6ab97ce | 2016-10-03 14:16:56 -0700 | [diff] [blame] | 957 | stats->transport_stats["transport"].transport_name = "transport"; |
hbos | df6075a | 2016-12-19 04:58:02 -0800 | [diff] [blame] | 958 | return stats; |
hbos | 6ab97ce | 2016-10-03 14:16:56 -0700 | [diff] [blame] | 959 | })); |
Steve Anton | 75737c0 | 2017-11-06 10:37:17 -0800 | [diff] [blame] | 960 | EXPECT_CALL(test_->pc(), GetLocalCertificate(_, _)) |
| 961 | .WillRepeatedly( |
| 962 | Invoke([&local_certinfo]( |
| 963 | const std::string& transport_name, |
| 964 | rtc::scoped_refptr<rtc::RTCCertificate>* certificate) { |
| 965 | if (transport_name == "transport") { |
| 966 | *certificate = local_certinfo->certificate; |
| 967 | return true; |
| 968 | } |
| 969 | return false; |
| 970 | })); |
| 971 | EXPECT_CALL(test_->pc(), GetRemoteSSLCertificate_ReturnsRawPointer(_)) |
| 972 | .WillRepeatedly(Invoke([&remote_certinfo]( |
| 973 | const std::string& transport_name) { |
hbos | 6ab97ce | 2016-10-03 14:16:56 -0700 | [diff] [blame] | 974 | if (transport_name == "transport") |
| 975 | return remote_certinfo->certificate->ssl_certificate().GetReference(); |
| 976 | return static_cast<rtc::SSLCertificate*>(nullptr); |
| 977 | })); |
| 978 | |
| 979 | rtc::scoped_refptr<const RTCStatsReport> report = GetStatsReport(); |
hbos | 23368e1 | 2016-12-21 04:29:17 -0800 | [diff] [blame] | 980 | ExpectReportContainsCertificateInfo(report, *local_certinfo); |
| 981 | ExpectReportContainsCertificateInfo(report, *remote_certinfo); |
hbos | 6ab97ce | 2016-10-03 14:16:56 -0700 | [diff] [blame] | 982 | } |
| 983 | |
hbos | cc555c5 | 2016-10-18 12:48:31 -0700 | [diff] [blame] | 984 | TEST_F(RTCStatsCollectorTest, CollectRTCDataChannelStats) { |
| 985 | test_->data_channels().push_back( |
hbos | dbb64d8 | 2016-12-21 01:57:46 -0800 | [diff] [blame] | 986 | new MockDataChannel( |
| 987 | 0, "MockDataChannel0", DataChannelInterface::kConnecting, "udp", |
| 988 | 1, 2, 3, 4)); |
| 989 | RTCDataChannelStats expected_data_channel0("RTCDataChannel_0", 0); |
| 990 | expected_data_channel0.label = "MockDataChannel0"; |
| 991 | expected_data_channel0.protocol = "udp"; |
| 992 | expected_data_channel0.datachannelid = 0; |
| 993 | expected_data_channel0.state = "connecting"; |
| 994 | expected_data_channel0.messages_sent = 1; |
| 995 | expected_data_channel0.bytes_sent = 2; |
| 996 | expected_data_channel0.messages_received = 3; |
| 997 | expected_data_channel0.bytes_received = 4; |
| 998 | |
hbos | cc555c5 | 2016-10-18 12:48:31 -0700 | [diff] [blame] | 999 | test_->data_channels().push_back( |
hbos | dbb64d8 | 2016-12-21 01:57:46 -0800 | [diff] [blame] | 1000 | new MockDataChannel( |
| 1001 | 1, "MockDataChannel1", DataChannelInterface::kOpen, "tcp", |
| 1002 | 5, 6, 7, 8)); |
| 1003 | RTCDataChannelStats expected_data_channel1("RTCDataChannel_1", 0); |
| 1004 | expected_data_channel1.label = "MockDataChannel1"; |
| 1005 | expected_data_channel1.protocol = "tcp"; |
| 1006 | expected_data_channel1.datachannelid = 1; |
| 1007 | expected_data_channel1.state = "open"; |
| 1008 | expected_data_channel1.messages_sent = 5; |
| 1009 | expected_data_channel1.bytes_sent = 6; |
| 1010 | expected_data_channel1.messages_received = 7; |
| 1011 | expected_data_channel1.bytes_received = 8; |
| 1012 | |
hbos | cc555c5 | 2016-10-18 12:48:31 -0700 | [diff] [blame] | 1013 | test_->data_channels().push_back( |
hbos | dbb64d8 | 2016-12-21 01:57:46 -0800 | [diff] [blame] | 1014 | new MockDataChannel( |
| 1015 | 2, "MockDataChannel2", DataChannelInterface::kClosing, "udp", |
| 1016 | 9, 10, 11, 12)); |
| 1017 | RTCDataChannelStats expected_data_channel2("RTCDataChannel_2", 0); |
| 1018 | expected_data_channel2.label = "MockDataChannel2"; |
| 1019 | expected_data_channel2.protocol = "udp"; |
| 1020 | expected_data_channel2.datachannelid = 2; |
| 1021 | expected_data_channel2.state = "closing"; |
| 1022 | expected_data_channel2.messages_sent = 9; |
| 1023 | expected_data_channel2.bytes_sent = 10; |
| 1024 | expected_data_channel2.messages_received = 11; |
| 1025 | expected_data_channel2.bytes_received = 12; |
| 1026 | |
hbos | cc555c5 | 2016-10-18 12:48:31 -0700 | [diff] [blame] | 1027 | test_->data_channels().push_back( |
hbos | dbb64d8 | 2016-12-21 01:57:46 -0800 | [diff] [blame] | 1028 | new MockDataChannel( |
| 1029 | 3, "MockDataChannel3", DataChannelInterface::kClosed, "tcp", |
| 1030 | 13, 14, 15, 16)); |
| 1031 | RTCDataChannelStats expected_data_channel3("RTCDataChannel_3", 0); |
| 1032 | expected_data_channel3.label = "MockDataChannel3"; |
| 1033 | expected_data_channel3.protocol = "tcp"; |
| 1034 | expected_data_channel3.datachannelid = 3; |
| 1035 | expected_data_channel3.state = "closed"; |
| 1036 | expected_data_channel3.messages_sent = 13; |
| 1037 | expected_data_channel3.bytes_sent = 14; |
| 1038 | expected_data_channel3.messages_received = 15; |
| 1039 | expected_data_channel3.bytes_received = 16; |
hbos | cc555c5 | 2016-10-18 12:48:31 -0700 | [diff] [blame] | 1040 | |
| 1041 | rtc::scoped_refptr<const RTCStatsReport> report = GetStatsReport(); |
hbos | dbb64d8 | 2016-12-21 01:57:46 -0800 | [diff] [blame] | 1042 | ASSERT_TRUE(report->Get(expected_data_channel0.id())); |
| 1043 | EXPECT_EQ(expected_data_channel0, |
| 1044 | report->Get(expected_data_channel0.id())->cast_to< |
| 1045 | RTCDataChannelStats>()); |
| 1046 | ASSERT_TRUE(report->Get(expected_data_channel1.id())); |
| 1047 | EXPECT_EQ(expected_data_channel1, |
| 1048 | report->Get(expected_data_channel1.id())->cast_to< |
| 1049 | RTCDataChannelStats>()); |
| 1050 | ASSERT_TRUE(report->Get(expected_data_channel2.id())); |
| 1051 | EXPECT_EQ(expected_data_channel2, |
| 1052 | report->Get(expected_data_channel2.id())->cast_to< |
| 1053 | RTCDataChannelStats>()); |
| 1054 | ASSERT_TRUE(report->Get(expected_data_channel3.id())); |
| 1055 | EXPECT_EQ(expected_data_channel3, |
| 1056 | report->Get(expected_data_channel3.id())->cast_to< |
| 1057 | RTCDataChannelStats>()); |
hbos | cc555c5 | 2016-10-18 12:48:31 -0700 | [diff] [blame] | 1058 | } |
| 1059 | |
hbos | ab9f6e4 | 2016-10-07 02:18:47 -0700 | [diff] [blame] | 1060 | TEST_F(RTCStatsCollectorTest, CollectRTCIceCandidateStats) { |
| 1061 | // Candidates in the first transport stats. |
Gary Liu | 37e489c | 2017-11-21 10:49:36 -0800 | [diff] [blame] | 1062 | std::unique_ptr<cricket::Candidate> a_local_host = |
| 1063 | CreateFakeCandidate("1.2.3.4", 5, "a_local_host's protocol", |
| 1064 | rtc::ADAPTER_TYPE_VPN, cricket::LOCAL_PORT_TYPE, 0); |
hbos | c42ba32 | 2016-12-21 03:31:45 -0800 | [diff] [blame] | 1065 | RTCLocalIceCandidateStats expected_a_local_host( |
| 1066 | "RTCIceCandidate_" + a_local_host->id(), 0); |
hbos | b4e426e | 2017-01-02 09:59:31 -0800 | [diff] [blame] | 1067 | expected_a_local_host.transport_id = "RTCTransport_a_0"; |
Gary Liu | 37e489c | 2017-11-21 10:49:36 -0800 | [diff] [blame] | 1068 | expected_a_local_host.network_type = "vpn"; |
hbos | c42ba32 | 2016-12-21 03:31:45 -0800 | [diff] [blame] | 1069 | expected_a_local_host.ip = "1.2.3.4"; |
| 1070 | expected_a_local_host.port = 5; |
| 1071 | expected_a_local_host.protocol = "a_local_host's protocol"; |
| 1072 | expected_a_local_host.candidate_type = "host"; |
| 1073 | expected_a_local_host.priority = 0; |
hbos | c3a2b7f | 2017-01-02 04:46:15 -0800 | [diff] [blame] | 1074 | EXPECT_FALSE(*expected_a_local_host.is_remote); |
hbos | c42ba32 | 2016-12-21 03:31:45 -0800 | [diff] [blame] | 1075 | |
hbos | ab9f6e4 | 2016-10-07 02:18:47 -0700 | [diff] [blame] | 1076 | std::unique_ptr<cricket::Candidate> a_remote_srflx = CreateFakeCandidate( |
Gary Liu | 37e489c | 2017-11-21 10:49:36 -0800 | [diff] [blame] | 1077 | "6.7.8.9", 10, "remote_srflx's protocol", rtc::ADAPTER_TYPE_UNKNOWN, |
| 1078 | cricket::STUN_PORT_TYPE, 1); |
hbos | c42ba32 | 2016-12-21 03:31:45 -0800 | [diff] [blame] | 1079 | RTCRemoteIceCandidateStats expected_a_remote_srflx( |
| 1080 | "RTCIceCandidate_" + a_remote_srflx->id(), 0); |
hbos | b4e426e | 2017-01-02 09:59:31 -0800 | [diff] [blame] | 1081 | expected_a_remote_srflx.transport_id = "RTCTransport_a_0"; |
hbos | c42ba32 | 2016-12-21 03:31:45 -0800 | [diff] [blame] | 1082 | expected_a_remote_srflx.ip = "6.7.8.9"; |
| 1083 | expected_a_remote_srflx.port = 10; |
| 1084 | expected_a_remote_srflx.protocol = "remote_srflx's protocol"; |
| 1085 | expected_a_remote_srflx.candidate_type = "srflx"; |
| 1086 | expected_a_remote_srflx.priority = 1; |
hbos | d17a5a7 | 2017-01-02 08:09:59 -0800 | [diff] [blame] | 1087 | expected_a_remote_srflx.deleted = false; |
hbos | c3a2b7f | 2017-01-02 04:46:15 -0800 | [diff] [blame] | 1088 | EXPECT_TRUE(*expected_a_remote_srflx.is_remote); |
hbos | c42ba32 | 2016-12-21 03:31:45 -0800 | [diff] [blame] | 1089 | |
hbos | ab9f6e4 | 2016-10-07 02:18:47 -0700 | [diff] [blame] | 1090 | std::unique_ptr<cricket::Candidate> a_local_prflx = CreateFakeCandidate( |
Gary Liu | 37e489c | 2017-11-21 10:49:36 -0800 | [diff] [blame] | 1091 | "11.12.13.14", 15, "a_local_prflx's protocol", rtc::ADAPTER_TYPE_CELLULAR, |
| 1092 | cricket::PRFLX_PORT_TYPE, 2); |
hbos | c42ba32 | 2016-12-21 03:31:45 -0800 | [diff] [blame] | 1093 | RTCLocalIceCandidateStats expected_a_local_prflx( |
| 1094 | "RTCIceCandidate_" + a_local_prflx->id(), 0); |
hbos | b4e426e | 2017-01-02 09:59:31 -0800 | [diff] [blame] | 1095 | expected_a_local_prflx.transport_id = "RTCTransport_a_0"; |
Gary Liu | 37e489c | 2017-11-21 10:49:36 -0800 | [diff] [blame] | 1096 | expected_a_local_prflx.network_type = "cellular"; |
hbos | c42ba32 | 2016-12-21 03:31:45 -0800 | [diff] [blame] | 1097 | expected_a_local_prflx.ip = "11.12.13.14"; |
| 1098 | expected_a_local_prflx.port = 15; |
| 1099 | expected_a_local_prflx.protocol = "a_local_prflx's protocol"; |
| 1100 | expected_a_local_prflx.candidate_type = "prflx"; |
| 1101 | expected_a_local_prflx.priority = 2; |
hbos | d17a5a7 | 2017-01-02 08:09:59 -0800 | [diff] [blame] | 1102 | expected_a_local_prflx.deleted = false; |
hbos | c3a2b7f | 2017-01-02 04:46:15 -0800 | [diff] [blame] | 1103 | EXPECT_FALSE(*expected_a_local_prflx.is_remote); |
hbos | c42ba32 | 2016-12-21 03:31:45 -0800 | [diff] [blame] | 1104 | |
hbos | ab9f6e4 | 2016-10-07 02:18:47 -0700 | [diff] [blame] | 1105 | std::unique_ptr<cricket::Candidate> a_remote_relay = CreateFakeCandidate( |
Gary Liu | 37e489c | 2017-11-21 10:49:36 -0800 | [diff] [blame] | 1106 | "16.17.18.19", 20, "a_remote_relay's protocol", rtc::ADAPTER_TYPE_UNKNOWN, |
| 1107 | cricket::RELAY_PORT_TYPE, 3); |
hbos | c42ba32 | 2016-12-21 03:31:45 -0800 | [diff] [blame] | 1108 | RTCRemoteIceCandidateStats expected_a_remote_relay( |
| 1109 | "RTCIceCandidate_" + a_remote_relay->id(), 0); |
hbos | b4e426e | 2017-01-02 09:59:31 -0800 | [diff] [blame] | 1110 | expected_a_remote_relay.transport_id = "RTCTransport_a_0"; |
hbos | c42ba32 | 2016-12-21 03:31:45 -0800 | [diff] [blame] | 1111 | expected_a_remote_relay.ip = "16.17.18.19"; |
| 1112 | expected_a_remote_relay.port = 20; |
| 1113 | expected_a_remote_relay.protocol = "a_remote_relay's protocol"; |
| 1114 | expected_a_remote_relay.candidate_type = "relay"; |
| 1115 | expected_a_remote_relay.priority = 3; |
hbos | d17a5a7 | 2017-01-02 08:09:59 -0800 | [diff] [blame] | 1116 | expected_a_remote_relay.deleted = false; |
hbos | c3a2b7f | 2017-01-02 04:46:15 -0800 | [diff] [blame] | 1117 | EXPECT_TRUE(*expected_a_remote_relay.is_remote); |
hbos | c42ba32 | 2016-12-21 03:31:45 -0800 | [diff] [blame] | 1118 | |
hbos | ab9f6e4 | 2016-10-07 02:18:47 -0700 | [diff] [blame] | 1119 | // Candidates in the second transport stats. |
Gary Liu | 37e489c | 2017-11-21 10:49:36 -0800 | [diff] [blame] | 1120 | std::unique_ptr<cricket::Candidate> b_local = |
| 1121 | CreateFakeCandidate("42.42.42.42", 42, "b_local's protocol", |
| 1122 | rtc::ADAPTER_TYPE_WIFI, cricket::LOCAL_PORT_TYPE, 42); |
hbos | c42ba32 | 2016-12-21 03:31:45 -0800 | [diff] [blame] | 1123 | RTCLocalIceCandidateStats expected_b_local( |
| 1124 | "RTCIceCandidate_" + b_local->id(), 0); |
hbos | b4e426e | 2017-01-02 09:59:31 -0800 | [diff] [blame] | 1125 | expected_b_local.transport_id = "RTCTransport_b_0"; |
Gary Liu | 37e489c | 2017-11-21 10:49:36 -0800 | [diff] [blame] | 1126 | expected_b_local.network_type = "wifi"; |
hbos | c42ba32 | 2016-12-21 03:31:45 -0800 | [diff] [blame] | 1127 | expected_b_local.ip = "42.42.42.42"; |
| 1128 | expected_b_local.port = 42; |
| 1129 | expected_b_local.protocol = "b_local's protocol"; |
| 1130 | expected_b_local.candidate_type = "host"; |
| 1131 | expected_b_local.priority = 42; |
hbos | d17a5a7 | 2017-01-02 08:09:59 -0800 | [diff] [blame] | 1132 | expected_b_local.deleted = false; |
hbos | c3a2b7f | 2017-01-02 04:46:15 -0800 | [diff] [blame] | 1133 | EXPECT_FALSE(*expected_b_local.is_remote); |
hbos | c42ba32 | 2016-12-21 03:31:45 -0800 | [diff] [blame] | 1134 | |
hbos | ab9f6e4 | 2016-10-07 02:18:47 -0700 | [diff] [blame] | 1135 | std::unique_ptr<cricket::Candidate> b_remote = CreateFakeCandidate( |
Gary Liu | 37e489c | 2017-11-21 10:49:36 -0800 | [diff] [blame] | 1136 | "42.42.42.42", 42, "b_remote's protocol", rtc::ADAPTER_TYPE_UNKNOWN, |
| 1137 | cricket::LOCAL_PORT_TYPE, 42); |
hbos | c42ba32 | 2016-12-21 03:31:45 -0800 | [diff] [blame] | 1138 | RTCRemoteIceCandidateStats expected_b_remote( |
| 1139 | "RTCIceCandidate_" + b_remote->id(), 0); |
hbos | b4e426e | 2017-01-02 09:59:31 -0800 | [diff] [blame] | 1140 | expected_b_remote.transport_id = "RTCTransport_b_0"; |
hbos | c42ba32 | 2016-12-21 03:31:45 -0800 | [diff] [blame] | 1141 | expected_b_remote.ip = "42.42.42.42"; |
| 1142 | expected_b_remote.port = 42; |
| 1143 | expected_b_remote.protocol = "b_remote's protocol"; |
| 1144 | expected_b_remote.candidate_type = "host"; |
| 1145 | expected_b_remote.priority = 42; |
hbos | d17a5a7 | 2017-01-02 08:09:59 -0800 | [diff] [blame] | 1146 | expected_b_remote.deleted = false; |
hbos | c3a2b7f | 2017-01-02 04:46:15 -0800 | [diff] [blame] | 1147 | EXPECT_TRUE(*expected_b_remote.is_remote); |
hbos | ab9f6e4 | 2016-10-07 02:18:47 -0700 | [diff] [blame] | 1148 | |
| 1149 | SessionStats session_stats; |
| 1150 | |
| 1151 | cricket::TransportChannelStats a_transport_channel_stats; |
| 1152 | a_transport_channel_stats.connection_infos.push_back( |
| 1153 | cricket::ConnectionInfo()); |
| 1154 | a_transport_channel_stats.connection_infos[0].local_candidate = |
| 1155 | *a_local_host.get(); |
| 1156 | a_transport_channel_stats.connection_infos[0].remote_candidate = |
| 1157 | *a_remote_srflx.get(); |
| 1158 | a_transport_channel_stats.connection_infos.push_back( |
| 1159 | cricket::ConnectionInfo()); |
| 1160 | a_transport_channel_stats.connection_infos[1].local_candidate = |
| 1161 | *a_local_prflx.get(); |
| 1162 | a_transport_channel_stats.connection_infos[1].remote_candidate = |
| 1163 | *a_remote_relay.get(); |
hbos | 02d2a92 | 2016-12-21 01:29:05 -0800 | [diff] [blame] | 1164 | session_stats.transport_stats["a"].transport_name = "a"; |
hbos | ab9f6e4 | 2016-10-07 02:18:47 -0700 | [diff] [blame] | 1165 | session_stats.transport_stats["a"].channel_stats.push_back( |
| 1166 | a_transport_channel_stats); |
| 1167 | |
| 1168 | cricket::TransportChannelStats b_transport_channel_stats; |
| 1169 | b_transport_channel_stats.connection_infos.push_back( |
| 1170 | cricket::ConnectionInfo()); |
| 1171 | b_transport_channel_stats.connection_infos[0].local_candidate = |
| 1172 | *b_local.get(); |
| 1173 | b_transport_channel_stats.connection_infos[0].remote_candidate = |
| 1174 | *b_remote.get(); |
hbos | 02d2a92 | 2016-12-21 01:29:05 -0800 | [diff] [blame] | 1175 | session_stats.transport_stats["b"].transport_name = "b"; |
hbos | ab9f6e4 | 2016-10-07 02:18:47 -0700 | [diff] [blame] | 1176 | session_stats.transport_stats["b"].channel_stats.push_back( |
| 1177 | b_transport_channel_stats); |
| 1178 | |
| 1179 | // Mock the session to return the desired candidates. |
Steve Anton | 75737c0 | 2017-11-06 10:37:17 -0800 | [diff] [blame] | 1180 | EXPECT_CALL(test_->pc(), GetSessionStats(_)) |
Steve Anton | ba81867 | 2017-11-06 10:21:57 -0800 | [diff] [blame] | 1181 | .WillRepeatedly(Invoke([&session_stats](const ChannelNamePairs&) { |
hbos | df6075a | 2016-12-19 04:58:02 -0800 | [diff] [blame] | 1182 | return std::unique_ptr<SessionStats>(new SessionStats(session_stats)); |
hbos | ab9f6e4 | 2016-10-07 02:18:47 -0700 | [diff] [blame] | 1183 | })); |
| 1184 | |
| 1185 | rtc::scoped_refptr<const RTCStatsReport> report = GetStatsReport(); |
hbos | c42ba32 | 2016-12-21 03:31:45 -0800 | [diff] [blame] | 1186 | |
hbos | b4e426e | 2017-01-02 09:59:31 -0800 | [diff] [blame] | 1187 | ASSERT_TRUE(report->Get(expected_a_local_host.id())); |
hbos | c42ba32 | 2016-12-21 03:31:45 -0800 | [diff] [blame] | 1188 | EXPECT_EQ(expected_a_local_host, |
| 1189 | report->Get(expected_a_local_host.id())->cast_to< |
| 1190 | RTCLocalIceCandidateStats>()); |
hbos | b4e426e | 2017-01-02 09:59:31 -0800 | [diff] [blame] | 1191 | ASSERT_TRUE(report->Get(expected_a_remote_srflx.id())); |
hbos | c42ba32 | 2016-12-21 03:31:45 -0800 | [diff] [blame] | 1192 | EXPECT_EQ(expected_a_remote_srflx, |
| 1193 | report->Get(expected_a_remote_srflx.id())->cast_to< |
| 1194 | RTCRemoteIceCandidateStats>()); |
hbos | b4e426e | 2017-01-02 09:59:31 -0800 | [diff] [blame] | 1195 | ASSERT_TRUE(report->Get(expected_a_local_prflx.id())); |
hbos | c42ba32 | 2016-12-21 03:31:45 -0800 | [diff] [blame] | 1196 | EXPECT_EQ(expected_a_local_prflx, |
| 1197 | report->Get(expected_a_local_prflx.id())->cast_to< |
| 1198 | RTCLocalIceCandidateStats>()); |
hbos | b4e426e | 2017-01-02 09:59:31 -0800 | [diff] [blame] | 1199 | ASSERT_TRUE(report->Get(expected_a_remote_relay.id())); |
hbos | c42ba32 | 2016-12-21 03:31:45 -0800 | [diff] [blame] | 1200 | EXPECT_EQ(expected_a_remote_relay, |
| 1201 | report->Get(expected_a_remote_relay.id())->cast_to< |
| 1202 | RTCRemoteIceCandidateStats>()); |
hbos | b4e426e | 2017-01-02 09:59:31 -0800 | [diff] [blame] | 1203 | ASSERT_TRUE(report->Get(expected_b_local.id())); |
hbos | c42ba32 | 2016-12-21 03:31:45 -0800 | [diff] [blame] | 1204 | EXPECT_EQ(expected_b_local, |
| 1205 | report->Get(expected_b_local.id())->cast_to< |
| 1206 | RTCLocalIceCandidateStats>()); |
hbos | b4e426e | 2017-01-02 09:59:31 -0800 | [diff] [blame] | 1207 | ASSERT_TRUE(report->Get(expected_b_remote.id())); |
hbos | c42ba32 | 2016-12-21 03:31:45 -0800 | [diff] [blame] | 1208 | EXPECT_EQ(expected_b_remote, |
| 1209 | report->Get(expected_b_remote.id())->cast_to< |
| 1210 | RTCRemoteIceCandidateStats>()); |
hbos | b4e426e | 2017-01-02 09:59:31 -0800 | [diff] [blame] | 1211 | EXPECT_TRUE(report->Get("RTCTransport_a_0")); |
| 1212 | EXPECT_TRUE(report->Get("RTCTransport_b_0")); |
hbos | ab9f6e4 | 2016-10-07 02:18:47 -0700 | [diff] [blame] | 1213 | } |
| 1214 | |
hbos | c47a0c3 | 2016-10-11 14:54:49 -0700 | [diff] [blame] | 1215 | TEST_F(RTCStatsCollectorTest, CollectRTCIceCandidatePairStats) { |
Steve Anton | 8699a32 | 2017-11-06 15:53:33 -0800 | [diff] [blame] | 1216 | auto* video_media_channel = new MockVideoMediaChannel(); |
hbos | 338f78a | 2017-02-07 06:41:21 -0800 | [diff] [blame] | 1217 | cricket::VideoChannel video_channel( |
| 1218 | test_->worker_thread(), test_->network_thread(), |
Steve Anton | 8699a32 | 2017-11-06 15:53:33 -0800 | [diff] [blame] | 1219 | test_->signaling_thread(), rtc::WrapUnique(video_media_channel), |
| 1220 | "VideoContentName", kDefaultRtcpMuxRequired, kDefaultSrtpRequired); |
hbos | 338f78a | 2017-02-07 06:41:21 -0800 | [diff] [blame] | 1221 | |
Gary Liu | 37e489c | 2017-11-21 10:49:36 -0800 | [diff] [blame] | 1222 | std::unique_ptr<cricket::Candidate> local_candidate = |
| 1223 | CreateFakeCandidate("42.42.42.42", 42, "protocol", rtc::ADAPTER_TYPE_WIFI, |
| 1224 | cricket::LOCAL_PORT_TYPE, 42); |
hbos | c47a0c3 | 2016-10-11 14:54:49 -0700 | [diff] [blame] | 1225 | std::unique_ptr<cricket::Candidate> remote_candidate = CreateFakeCandidate( |
Gary Liu | 37e489c | 2017-11-21 10:49:36 -0800 | [diff] [blame] | 1226 | "42.42.42.42", 42, "protocol", rtc::ADAPTER_TYPE_UNKNOWN, |
| 1227 | cricket::LOCAL_PORT_TYPE, 42); |
hbos | c47a0c3 | 2016-10-11 14:54:49 -0700 | [diff] [blame] | 1228 | |
| 1229 | SessionStats session_stats; |
| 1230 | |
| 1231 | cricket::ConnectionInfo connection_info; |
hbos | 338f78a | 2017-02-07 06:41:21 -0800 | [diff] [blame] | 1232 | connection_info.best_connection = false; |
hbos | c47a0c3 | 2016-10-11 14:54:49 -0700 | [diff] [blame] | 1233 | connection_info.local_candidate = *local_candidate.get(); |
| 1234 | connection_info.remote_candidate = *remote_candidate.get(); |
| 1235 | connection_info.writable = true; |
| 1236 | connection_info.sent_total_bytes = 42; |
| 1237 | connection_info.recv_total_bytes = 1234; |
hbos | bf8d3e5 | 2017-02-28 06:34:47 -0800 | [diff] [blame] | 1238 | connection_info.total_round_trip_time_ms = 0; |
Oskar Sundbom | cbc71b2 | 2017-11-16 10:56:07 +0100 | [diff] [blame] | 1239 | connection_info.current_round_trip_time_ms = rtc::nullopt; |
hbos | d82f512 | 2016-12-09 04:12:39 -0800 | [diff] [blame] | 1240 | connection_info.recv_ping_requests = 2020; |
hbos | e448dd5 | 2016-12-12 01:22:53 -0800 | [diff] [blame] | 1241 | connection_info.sent_ping_requests_total = 2020; |
| 1242 | connection_info.sent_ping_requests_before_first_response = 2000; |
hbos | c47a0c3 | 2016-10-11 14:54:49 -0700 | [diff] [blame] | 1243 | connection_info.recv_ping_responses = 4321; |
| 1244 | connection_info.sent_ping_responses = 1000; |
hbos | 06495bc | 2017-01-02 08:08:18 -0800 | [diff] [blame] | 1245 | connection_info.state = cricket::IceCandidatePairState::IN_PROGRESS; |
| 1246 | connection_info.priority = 5555; |
hbos | 92eaec6 | 2017-02-27 01:38:08 -0800 | [diff] [blame] | 1247 | connection_info.nominated = false; |
hbos | c47a0c3 | 2016-10-11 14:54:49 -0700 | [diff] [blame] | 1248 | |
| 1249 | cricket::TransportChannelStats transport_channel_stats; |
hbos | 0583b28 | 2016-11-30 01:50:14 -0800 | [diff] [blame] | 1250 | transport_channel_stats.component = cricket::ICE_CANDIDATE_COMPONENT_RTP; |
hbos | c47a0c3 | 2016-10-11 14:54:49 -0700 | [diff] [blame] | 1251 | transport_channel_stats.connection_infos.push_back(connection_info); |
| 1252 | session_stats.transport_stats["transport"].transport_name = "transport"; |
| 1253 | session_stats.transport_stats["transport"].channel_stats.push_back( |
| 1254 | transport_channel_stats); |
| 1255 | |
| 1256 | // Mock the session to return the desired candidates. |
Steve Anton | 75737c0 | 2017-11-06 10:37:17 -0800 | [diff] [blame] | 1257 | EXPECT_CALL(test_->pc(), GetSessionStats(_)) |
Steve Anton | ba81867 | 2017-11-06 10:21:57 -0800 | [diff] [blame] | 1258 | .WillRepeatedly(Invoke([&session_stats](const ChannelNamePairs&) { |
hbos | df6075a | 2016-12-19 04:58:02 -0800 | [diff] [blame] | 1259 | return std::unique_ptr<SessionStats>(new SessionStats(session_stats)); |
hbos | c47a0c3 | 2016-10-11 14:54:49 -0700 | [diff] [blame] | 1260 | })); |
| 1261 | |
hbos | 338f78a | 2017-02-07 06:41:21 -0800 | [diff] [blame] | 1262 | // Mock the session to return bandwidth estimation info. These should only |
| 1263 | // be used for a selected candidate pair. |
| 1264 | cricket::VideoMediaInfo video_media_info; |
hbos | 338f78a | 2017-02-07 06:41:21 -0800 | [diff] [blame] | 1265 | EXPECT_CALL(*video_media_channel, GetStats(_)) |
| 1266 | .WillOnce(DoAll(SetArgPointee<0>(video_media_info), Return(true))); |
Steve Anton | 75737c0 | 2017-11-06 10:37:17 -0800 | [diff] [blame] | 1267 | EXPECT_CALL(test_->pc(), video_channel()) |
hbos | 338f78a | 2017-02-07 06:41:21 -0800 | [diff] [blame] | 1268 | .WillRepeatedly(Return(&video_channel)); |
| 1269 | |
hbos | c47a0c3 | 2016-10-11 14:54:49 -0700 | [diff] [blame] | 1270 | rtc::scoped_refptr<const RTCStatsReport> report = GetStatsReport(); |
hbos | 0583b28 | 2016-11-30 01:50:14 -0800 | [diff] [blame] | 1271 | |
| 1272 | RTCIceCandidatePairStats expected_pair("RTCIceCandidatePair_" + |
| 1273 | local_candidate->id() + "_" + |
| 1274 | remote_candidate->id(), |
| 1275 | report->timestamp_us()); |
| 1276 | expected_pair.transport_id = |
| 1277 | "RTCTransport_transport_" + |
| 1278 | rtc::ToString<>(cricket::ICE_CANDIDATE_COMPONENT_RTP); |
| 1279 | expected_pair.local_candidate_id = "RTCIceCandidate_" + local_candidate->id(); |
| 1280 | expected_pair.remote_candidate_id = |
| 1281 | "RTCIceCandidate_" + remote_candidate->id(); |
hbos | 06495bc | 2017-01-02 08:08:18 -0800 | [diff] [blame] | 1282 | expected_pair.state = RTCStatsIceCandidatePairState::kInProgress; |
| 1283 | expected_pair.priority = 5555; |
hbos | 92eaec6 | 2017-02-27 01:38:08 -0800 | [diff] [blame] | 1284 | expected_pair.nominated = false; |
hbos | 0583b28 | 2016-11-30 01:50:14 -0800 | [diff] [blame] | 1285 | expected_pair.writable = true; |
| 1286 | expected_pair.bytes_sent = 42; |
| 1287 | expected_pair.bytes_received = 1234; |
hbos | bf8d3e5 | 2017-02-28 06:34:47 -0800 | [diff] [blame] | 1288 | expected_pair.total_round_trip_time = 0.0; |
hbos | d82f512 | 2016-12-09 04:12:39 -0800 | [diff] [blame] | 1289 | expected_pair.requests_received = 2020; |
hbos | e448dd5 | 2016-12-12 01:22:53 -0800 | [diff] [blame] | 1290 | expected_pair.requests_sent = 2000; |
hbos | 0583b28 | 2016-11-30 01:50:14 -0800 | [diff] [blame] | 1291 | expected_pair.responses_received = 4321; |
| 1292 | expected_pair.responses_sent = 1000; |
hbos | e448dd5 | 2016-12-12 01:22:53 -0800 | [diff] [blame] | 1293 | expected_pair.consent_requests_sent = (2020 - 2000); |
hbos | bf8d3e5 | 2017-02-28 06:34:47 -0800 | [diff] [blame] | 1294 | // |expected_pair.current_round_trip_time| should be undefined because the |
| 1295 | // current RTT is not set. |
hbos | 338f78a | 2017-02-07 06:41:21 -0800 | [diff] [blame] | 1296 | // |expected_pair.available_[outgoing/incoming]_bitrate| should be undefined |
| 1297 | // because is is not the current pair. |
hbos | 0583b28 | 2016-11-30 01:50:14 -0800 | [diff] [blame] | 1298 | |
hbos | dbb64d8 | 2016-12-21 01:57:46 -0800 | [diff] [blame] | 1299 | ASSERT_TRUE(report->Get(expected_pair.id())); |
hbos | 0583b28 | 2016-11-30 01:50:14 -0800 | [diff] [blame] | 1300 | EXPECT_EQ( |
| 1301 | expected_pair, |
| 1302 | report->Get(expected_pair.id())->cast_to<RTCIceCandidatePairStats>()); |
hbos | b4e426e | 2017-01-02 09:59:31 -0800 | [diff] [blame] | 1303 | EXPECT_TRUE(report->Get(*expected_pair.transport_id)); |
hbos | 0583b28 | 2016-11-30 01:50:14 -0800 | [diff] [blame] | 1304 | |
hbos | 92eaec6 | 2017-02-27 01:38:08 -0800 | [diff] [blame] | 1305 | // Set nominated and "GetStats" again. |
| 1306 | session_stats.transport_stats["transport"] |
| 1307 | .channel_stats[0] |
| 1308 | .connection_infos[0] |
| 1309 | .nominated = true; |
| 1310 | EXPECT_CALL(*video_media_channel, GetStats(_)) |
| 1311 | .WillOnce(DoAll(SetArgPointee<0>(video_media_info), Return(true))); |
| 1312 | collector_->ClearCachedStatsReport(); |
| 1313 | report = GetStatsReport(); |
| 1314 | expected_pair.nominated = true; |
| 1315 | ASSERT_TRUE(report->Get(expected_pair.id())); |
| 1316 | EXPECT_EQ( |
| 1317 | expected_pair, |
| 1318 | report->Get(expected_pair.id())->cast_to<RTCIceCandidatePairStats>()); |
| 1319 | EXPECT_TRUE(report->Get(*expected_pair.transport_id)); |
| 1320 | |
hbos | bf8d3e5 | 2017-02-28 06:34:47 -0800 | [diff] [blame] | 1321 | // Set round trip times and "GetStats" again. |
| 1322 | session_stats.transport_stats["transport"].channel_stats[0] |
| 1323 | .connection_infos[0].total_round_trip_time_ms = 7331; |
| 1324 | session_stats.transport_stats["transport"].channel_stats[0] |
Oskar Sundbom | cbc71b2 | 2017-11-16 10:56:07 +0100 | [diff] [blame] | 1325 | .connection_infos[0].current_round_trip_time_ms = 1337; |
hbos | bf8d3e5 | 2017-02-28 06:34:47 -0800 | [diff] [blame] | 1326 | EXPECT_CALL(*video_media_channel, GetStats(_)) |
| 1327 | .WillOnce(DoAll(SetArgPointee<0>(video_media_info), Return(true))); |
| 1328 | collector_->ClearCachedStatsReport(); |
| 1329 | report = GetStatsReport(); |
| 1330 | expected_pair.total_round_trip_time = 7.331; |
| 1331 | expected_pair.current_round_trip_time = 1.337; |
| 1332 | ASSERT_TRUE(report->Get(expected_pair.id())); |
| 1333 | EXPECT_EQ( |
| 1334 | expected_pair, |
| 1335 | report->Get(expected_pair.id())->cast_to<RTCIceCandidatePairStats>()); |
| 1336 | EXPECT_TRUE(report->Get(*expected_pair.transport_id)); |
| 1337 | |
hbos | 338f78a | 2017-02-07 06:41:21 -0800 | [diff] [blame] | 1338 | // Make pair the current pair, clear bandwidth and "GetStats" again. |
| 1339 | session_stats.transport_stats["transport"] |
| 1340 | .channel_stats[0] |
| 1341 | .connection_infos[0] |
| 1342 | .best_connection = true; |
hbos | 338f78a | 2017-02-07 06:41:21 -0800 | [diff] [blame] | 1343 | EXPECT_CALL(*video_media_channel, GetStats(_)) |
| 1344 | .WillOnce(DoAll(SetArgPointee<0>(video_media_info), Return(true))); |
| 1345 | collector_->ClearCachedStatsReport(); |
| 1346 | report = GetStatsReport(); |
| 1347 | // |expected_pair.available_[outgoing/incoming]_bitrate| should still be |
| 1348 | // undefined because bandwidth is not set. |
| 1349 | ASSERT_TRUE(report->Get(expected_pair.id())); |
| 1350 | EXPECT_EQ( |
| 1351 | expected_pair, |
| 1352 | report->Get(expected_pair.id())->cast_to<RTCIceCandidatePairStats>()); |
| 1353 | EXPECT_TRUE(report->Get(*expected_pair.transport_id)); |
| 1354 | |
| 1355 | // Set bandwidth and "GetStats" again. |
stefan | f79ade1 | 2017-06-02 06:44:03 -0700 | [diff] [blame] | 1356 | webrtc::Call::Stats call_stats; |
| 1357 | const int kSendBandwidth = 888; |
| 1358 | call_stats.send_bandwidth_bps = kSendBandwidth; |
| 1359 | const int kRecvBandwidth = 999; |
| 1360 | call_stats.recv_bandwidth_bps = kRecvBandwidth; |
Steve Anton | 75737c0 | 2017-11-06 10:37:17 -0800 | [diff] [blame] | 1361 | EXPECT_CALL(test_->pc(), GetCallStats()).WillRepeatedly(Return(call_stats)); |
hbos | 338f78a | 2017-02-07 06:41:21 -0800 | [diff] [blame] | 1362 | EXPECT_CALL(*video_media_channel, GetStats(_)) |
| 1363 | .WillOnce(DoAll(SetArgPointee<0>(video_media_info), Return(true))); |
| 1364 | collector_->ClearCachedStatsReport(); |
| 1365 | report = GetStatsReport(); |
stefan | f79ade1 | 2017-06-02 06:44:03 -0700 | [diff] [blame] | 1366 | expected_pair.available_outgoing_bitrate = kSendBandwidth; |
| 1367 | expected_pair.available_incoming_bitrate = kRecvBandwidth; |
hbos | 338f78a | 2017-02-07 06:41:21 -0800 | [diff] [blame] | 1368 | ASSERT_TRUE(report->Get(expected_pair.id())); |
| 1369 | EXPECT_EQ( |
| 1370 | expected_pair, |
| 1371 | report->Get(expected_pair.id())->cast_to<RTCIceCandidatePairStats>()); |
| 1372 | EXPECT_TRUE(report->Get(*expected_pair.transport_id)); |
| 1373 | |
hbos | c42ba32 | 2016-12-21 03:31:45 -0800 | [diff] [blame] | 1374 | RTCLocalIceCandidateStats expected_local_candidate( |
| 1375 | *expected_pair.local_candidate_id, report->timestamp_us()); |
hbos | b4e426e | 2017-01-02 09:59:31 -0800 | [diff] [blame] | 1376 | expected_local_candidate.transport_id = *expected_pair.transport_id; |
Gary Liu | 37e489c | 2017-11-21 10:49:36 -0800 | [diff] [blame] | 1377 | expected_local_candidate.network_type = "wifi"; |
hbos | c42ba32 | 2016-12-21 03:31:45 -0800 | [diff] [blame] | 1378 | expected_local_candidate.ip = "42.42.42.42"; |
| 1379 | expected_local_candidate.port = 42; |
| 1380 | expected_local_candidate.protocol = "protocol"; |
| 1381 | expected_local_candidate.candidate_type = "host"; |
| 1382 | expected_local_candidate.priority = 42; |
hbos | d17a5a7 | 2017-01-02 08:09:59 -0800 | [diff] [blame] | 1383 | expected_local_candidate.deleted = false; |
hbos | c3a2b7f | 2017-01-02 04:46:15 -0800 | [diff] [blame] | 1384 | EXPECT_FALSE(*expected_local_candidate.is_remote); |
hbos | c42ba32 | 2016-12-21 03:31:45 -0800 | [diff] [blame] | 1385 | ASSERT_TRUE(report->Get(expected_local_candidate.id())); |
| 1386 | EXPECT_EQ(expected_local_candidate, |
| 1387 | report->Get(expected_local_candidate.id())->cast_to< |
| 1388 | RTCLocalIceCandidateStats>()); |
| 1389 | |
| 1390 | RTCRemoteIceCandidateStats expected_remote_candidate( |
| 1391 | *expected_pair.remote_candidate_id, report->timestamp_us()); |
hbos | b4e426e | 2017-01-02 09:59:31 -0800 | [diff] [blame] | 1392 | expected_remote_candidate.transport_id = *expected_pair.transport_id; |
hbos | c42ba32 | 2016-12-21 03:31:45 -0800 | [diff] [blame] | 1393 | expected_remote_candidate.ip = "42.42.42.42"; |
| 1394 | expected_remote_candidate.port = 42; |
| 1395 | expected_remote_candidate.protocol = "protocol"; |
| 1396 | expected_remote_candidate.candidate_type = "host"; |
| 1397 | expected_remote_candidate.priority = 42; |
hbos | d17a5a7 | 2017-01-02 08:09:59 -0800 | [diff] [blame] | 1398 | expected_remote_candidate.deleted = false; |
hbos | c3a2b7f | 2017-01-02 04:46:15 -0800 | [diff] [blame] | 1399 | EXPECT_TRUE(*expected_remote_candidate.is_remote); |
hbos | c42ba32 | 2016-12-21 03:31:45 -0800 | [diff] [blame] | 1400 | ASSERT_TRUE(report->Get(expected_remote_candidate.id())); |
| 1401 | EXPECT_EQ(expected_remote_candidate, |
| 1402 | report->Get(expected_remote_candidate.id())->cast_to< |
| 1403 | RTCRemoteIceCandidateStats>()); |
hbos | c47a0c3 | 2016-10-11 14:54:49 -0700 | [diff] [blame] | 1404 | } |
| 1405 | |
hbos | d565b73 | 2016-08-30 14:04:35 -0700 | [diff] [blame] | 1406 | TEST_F(RTCStatsCollectorTest, CollectRTCPeerConnectionStats) { |
hbos | d565b73 | 2016-08-30 14:04:35 -0700 | [diff] [blame] | 1407 | { |
hbos | 82ebe02 | 2016-11-14 01:41:09 -0800 | [diff] [blame] | 1408 | rtc::scoped_refptr<const RTCStatsReport> report = GetStatsReport(); |
| 1409 | RTCPeerConnectionStats expected("RTCPeerConnection", |
| 1410 | report->timestamp_us()); |
| 1411 | expected.data_channels_opened = 0; |
| 1412 | expected.data_channels_closed = 0; |
hbos | dbb64d8 | 2016-12-21 01:57:46 -0800 | [diff] [blame] | 1413 | ASSERT_TRUE(report->Get("RTCPeerConnection")); |
hbos | 82ebe02 | 2016-11-14 01:41:09 -0800 | [diff] [blame] | 1414 | EXPECT_EQ(expected, |
| 1415 | report->Get("RTCPeerConnection")->cast_to< |
| 1416 | RTCPeerConnectionStats>()); |
hbos | d565b73 | 2016-08-30 14:04:35 -0700 | [diff] [blame] | 1417 | } |
| 1418 | |
hbos | 82ebe02 | 2016-11-14 01:41:09 -0800 | [diff] [blame] | 1419 | rtc::scoped_refptr<DataChannel> dummy_channel_a = DataChannel::Create( |
| 1420 | nullptr, cricket::DCT_NONE, "DummyChannelA", InternalDataChannelInit()); |
| 1421 | test_->pc().SignalDataChannelCreated(dummy_channel_a.get()); |
| 1422 | rtc::scoped_refptr<DataChannel> dummy_channel_b = DataChannel::Create( |
| 1423 | nullptr, cricket::DCT_NONE, "DummyChannelB", InternalDataChannelInit()); |
| 1424 | test_->pc().SignalDataChannelCreated(dummy_channel_b.get()); |
hbos | d565b73 | 2016-08-30 14:04:35 -0700 | [diff] [blame] | 1425 | |
hbos | 82ebe02 | 2016-11-14 01:41:09 -0800 | [diff] [blame] | 1426 | dummy_channel_a->SignalOpened(dummy_channel_a.get()); |
| 1427 | // Closing a channel that is not opened should not affect the counts. |
| 1428 | dummy_channel_b->SignalClosed(dummy_channel_b.get()); |
| 1429 | |
hbos | d565b73 | 2016-08-30 14:04:35 -0700 | [diff] [blame] | 1430 | { |
hbos | 82ebe02 | 2016-11-14 01:41:09 -0800 | [diff] [blame] | 1431 | collector_->ClearCachedStatsReport(); |
| 1432 | rtc::scoped_refptr<const RTCStatsReport> report = GetStatsReport(); |
| 1433 | RTCPeerConnectionStats expected("RTCPeerConnection", |
| 1434 | report->timestamp_us()); |
| 1435 | expected.data_channels_opened = 1; |
| 1436 | expected.data_channels_closed = 0; |
hbos | dbb64d8 | 2016-12-21 01:57:46 -0800 | [diff] [blame] | 1437 | ASSERT_TRUE(report->Get("RTCPeerConnection")); |
hbos | 82ebe02 | 2016-11-14 01:41:09 -0800 | [diff] [blame] | 1438 | EXPECT_EQ(expected, |
| 1439 | report->Get("RTCPeerConnection")->cast_to< |
| 1440 | RTCPeerConnectionStats>()); |
| 1441 | } |
| 1442 | |
| 1443 | dummy_channel_b->SignalOpened(dummy_channel_b.get()); |
| 1444 | dummy_channel_b->SignalClosed(dummy_channel_b.get()); |
| 1445 | |
| 1446 | { |
| 1447 | collector_->ClearCachedStatsReport(); |
| 1448 | rtc::scoped_refptr<const RTCStatsReport> report = GetStatsReport(); |
| 1449 | RTCPeerConnectionStats expected("RTCPeerConnection", |
| 1450 | report->timestamp_us()); |
| 1451 | expected.data_channels_opened = 2; |
| 1452 | expected.data_channels_closed = 1; |
hbos | dbb64d8 | 2016-12-21 01:57:46 -0800 | [diff] [blame] | 1453 | ASSERT_TRUE(report->Get("RTCPeerConnection")); |
hbos | 82ebe02 | 2016-11-14 01:41:09 -0800 | [diff] [blame] | 1454 | EXPECT_EQ(expected, |
| 1455 | report->Get("RTCPeerConnection")->cast_to< |
| 1456 | RTCPeerConnectionStats>()); |
hbos | d565b73 | 2016-08-30 14:04:35 -0700 | [diff] [blame] | 1457 | } |
hbos | 5bf9def | 2017-03-20 03:14:14 -0700 | [diff] [blame] | 1458 | |
| 1459 | // Re-opening a data channel (or opening a new data channel that is re-using |
| 1460 | // the same address in memory) should increase the opened count. |
| 1461 | dummy_channel_b->SignalOpened(dummy_channel_b.get()); |
| 1462 | |
| 1463 | { |
| 1464 | collector_->ClearCachedStatsReport(); |
| 1465 | rtc::scoped_refptr<const RTCStatsReport> report = GetStatsReport(); |
| 1466 | RTCPeerConnectionStats expected("RTCPeerConnection", |
| 1467 | report->timestamp_us()); |
| 1468 | expected.data_channels_opened = 3; |
| 1469 | expected.data_channels_closed = 1; |
| 1470 | ASSERT_TRUE(report->Get("RTCPeerConnection")); |
| 1471 | EXPECT_EQ(expected, |
| 1472 | report->Get("RTCPeerConnection")->cast_to< |
| 1473 | RTCPeerConnectionStats>()); |
| 1474 | } |
| 1475 | |
| 1476 | dummy_channel_a->SignalClosed(dummy_channel_a.get()); |
| 1477 | dummy_channel_b->SignalClosed(dummy_channel_b.get()); |
| 1478 | |
| 1479 | { |
| 1480 | collector_->ClearCachedStatsReport(); |
| 1481 | rtc::scoped_refptr<const RTCStatsReport> report = GetStatsReport(); |
| 1482 | RTCPeerConnectionStats expected("RTCPeerConnection", |
| 1483 | report->timestamp_us()); |
| 1484 | expected.data_channels_opened = 3; |
| 1485 | expected.data_channels_closed = 3; |
| 1486 | ASSERT_TRUE(report->Get("RTCPeerConnection")); |
| 1487 | EXPECT_EQ(expected, |
| 1488 | report->Get("RTCPeerConnection")->cast_to< |
| 1489 | RTCPeerConnectionStats>()); |
| 1490 | } |
hbos | d565b73 | 2016-08-30 14:04:35 -0700 | [diff] [blame] | 1491 | } |
| 1492 | |
hbos | 09bc128 | 2016-11-08 06:29:22 -0800 | [diff] [blame] | 1493 | TEST_F(RTCStatsCollectorTest, |
| 1494 | CollectRTCMediaStreamStatsAndRTCMediaStreamTrackStats_Audio) { |
| 1495 | rtc::scoped_refptr<StreamCollection> local_streams = |
| 1496 | StreamCollection::Create(); |
| 1497 | rtc::scoped_refptr<StreamCollection> remote_streams = |
| 1498 | StreamCollection::Create(); |
| 1499 | EXPECT_CALL(test_->pc(), local_streams()) |
| 1500 | .WillRepeatedly(Return(local_streams)); |
| 1501 | EXPECT_CALL(test_->pc(), remote_streams()) |
| 1502 | .WillRepeatedly(Return(remote_streams)); |
| 1503 | |
| 1504 | rtc::scoped_refptr<MediaStream> local_stream = |
| 1505 | MediaStream::Create("LocalStreamLabel"); |
| 1506 | local_streams->AddStream(local_stream); |
| 1507 | rtc::scoped_refptr<MediaStream> remote_stream = |
| 1508 | MediaStream::Create("RemoteStreamLabel"); |
| 1509 | remote_streams->AddStream(remote_stream); |
| 1510 | |
| 1511 | // Local audio track |
hbos | 9e30274 | 2017-01-20 02:47:10 -0800 | [diff] [blame] | 1512 | rtc::scoped_refptr<MediaStreamTrackInterface> local_audio_track = |
| 1513 | CreateFakeTrack(cricket::MEDIA_TYPE_AUDIO, "LocalAudioTrackID", |
| 1514 | MediaStreamTrackInterface::kEnded); |
| 1515 | local_stream->AddTrack(static_cast<AudioTrackInterface*>( |
| 1516 | local_audio_track.get())); |
| 1517 | |
| 1518 | cricket::VoiceSenderInfo voice_sender_info_ssrc1; |
| 1519 | voice_sender_info_ssrc1.local_stats.push_back(cricket::SsrcSenderInfo()); |
| 1520 | voice_sender_info_ssrc1.local_stats[0].ssrc = 1; |
| 1521 | voice_sender_info_ssrc1.audio_level = 32767; |
zstein | e76bd3a | 2017-07-14 12:17:49 -0700 | [diff] [blame] | 1522 | voice_sender_info_ssrc1.total_input_energy = 0.25; |
| 1523 | voice_sender_info_ssrc1.total_input_duration = 0.5; |
Ivo Creusen | 56d4609 | 2017-11-24 17:29:59 +0100 | [diff] [blame] | 1524 | voice_sender_info_ssrc1.apm_statistics.echo_return_loss = 42.0; |
| 1525 | voice_sender_info_ssrc1.apm_statistics.echo_return_loss_enhancement = 52.0; |
hbos | 9e30274 | 2017-01-20 02:47:10 -0800 | [diff] [blame] | 1526 | |
| 1527 | // Uses default values, the corresponding stats object should contain |
| 1528 | // undefined members. |
| 1529 | cricket::VoiceSenderInfo voice_sender_info_ssrc2; |
| 1530 | voice_sender_info_ssrc2.local_stats.push_back(cricket::SsrcSenderInfo()); |
| 1531 | voice_sender_info_ssrc2.local_stats[0].ssrc = 2; |
| 1532 | voice_sender_info_ssrc2.audio_level = 0; |
zstein | e76bd3a | 2017-07-14 12:17:49 -0700 | [diff] [blame] | 1533 | voice_sender_info_ssrc2.total_input_energy = 0.0; |
| 1534 | voice_sender_info_ssrc2.total_input_duration = 0.0; |
hbos | 09bc128 | 2016-11-08 06:29:22 -0800 | [diff] [blame] | 1535 | |
| 1536 | // Remote audio track |
hbos | 9e30274 | 2017-01-20 02:47:10 -0800 | [diff] [blame] | 1537 | rtc::scoped_refptr<MediaStreamTrackInterface> remote_audio_track = |
| 1538 | CreateFakeTrack(cricket::MEDIA_TYPE_AUDIO, "RemoteAudioTrackID", |
| 1539 | MediaStreamTrackInterface::kLive); |
| 1540 | remote_stream->AddTrack(static_cast<AudioTrackInterface*>( |
| 1541 | remote_audio_track.get())); |
| 1542 | |
| 1543 | cricket::VoiceReceiverInfo voice_receiver_info; |
| 1544 | voice_receiver_info.local_stats.push_back(cricket::SsrcReceiverInfo()); |
| 1545 | voice_receiver_info.local_stats[0].ssrc = 3; |
| 1546 | voice_receiver_info.audio_level = 16383; |
zstein | e76bd3a | 2017-07-14 12:17:49 -0700 | [diff] [blame] | 1547 | voice_receiver_info.total_output_energy = 0.125; |
Steve Anton | 2dbc69f | 2017-08-24 17:15:13 -0700 | [diff] [blame] | 1548 | voice_receiver_info.total_samples_received = 4567; |
zstein | e76bd3a | 2017-07-14 12:17:49 -0700 | [diff] [blame] | 1549 | voice_receiver_info.total_output_duration = 0.25; |
Steve Anton | 2dbc69f | 2017-08-24 17:15:13 -0700 | [diff] [blame] | 1550 | voice_receiver_info.concealed_samples = 123; |
Gustaf Ullberg | 9a2e906 | 2017-09-18 09:28:20 +0200 | [diff] [blame] | 1551 | voice_receiver_info.concealment_events = 12; |
Gustaf Ullberg | b0a0207 | 2017-10-02 12:00:34 +0200 | [diff] [blame] | 1552 | voice_receiver_info.jitter_buffer_delay_seconds = 3456; |
hbos | 9e30274 | 2017-01-20 02:47:10 -0800 | [diff] [blame] | 1553 | |
| 1554 | test_->CreateMockRtpSendersReceiversAndChannels( |
| 1555 | { std::make_pair(local_audio_track.get(), voice_sender_info_ssrc1), |
| 1556 | std::make_pair(local_audio_track.get(), voice_sender_info_ssrc2) }, |
| 1557 | { std::make_pair(remote_audio_track.get(), voice_receiver_info) }, |
| 1558 | {}, {}); |
hbos | 09bc128 | 2016-11-08 06:29:22 -0800 | [diff] [blame] | 1559 | |
| 1560 | rtc::scoped_refptr<const RTCStatsReport> report = GetStatsReport(); |
| 1561 | |
| 1562 | RTCMediaStreamStats expected_local_stream( |
hbos | 02d2a92 | 2016-12-21 01:29:05 -0800 | [diff] [blame] | 1563 | "RTCMediaStream_local_LocalStreamLabel", report->timestamp_us()); |
hbos | 09bc128 | 2016-11-08 06:29:22 -0800 | [diff] [blame] | 1564 | expected_local_stream.stream_identifier = local_stream->label(); |
hbos | 9e30274 | 2017-01-20 02:47:10 -0800 | [diff] [blame] | 1565 | expected_local_stream.track_ids = std::vector<std::string>( |
| 1566 | { "RTCMediaStreamTrack_local_audio_LocalAudioTrackID_1", |
| 1567 | "RTCMediaStreamTrack_local_audio_LocalAudioTrackID_2" }); |
hbos | dbb64d8 | 2016-12-21 01:57:46 -0800 | [diff] [blame] | 1568 | ASSERT_TRUE(report->Get(expected_local_stream.id())); |
hbos | 09bc128 | 2016-11-08 06:29:22 -0800 | [diff] [blame] | 1569 | EXPECT_EQ(expected_local_stream, |
| 1570 | report->Get(expected_local_stream.id())->cast_to< |
| 1571 | RTCMediaStreamStats>()); |
| 1572 | |
| 1573 | RTCMediaStreamStats expected_remote_stream( |
hbos | 02d2a92 | 2016-12-21 01:29:05 -0800 | [diff] [blame] | 1574 | "RTCMediaStream_remote_RemoteStreamLabel", report->timestamp_us()); |
hbos | 09bc128 | 2016-11-08 06:29:22 -0800 | [diff] [blame] | 1575 | expected_remote_stream.stream_identifier = remote_stream->label(); |
hbos | 9e30274 | 2017-01-20 02:47:10 -0800 | [diff] [blame] | 1576 | expected_remote_stream.track_ids = std::vector<std::string>({ |
| 1577 | "RTCMediaStreamTrack_remote_audio_RemoteAudioTrackID_3" }); |
hbos | dbb64d8 | 2016-12-21 01:57:46 -0800 | [diff] [blame] | 1578 | ASSERT_TRUE(report->Get(expected_remote_stream.id())); |
hbos | 09bc128 | 2016-11-08 06:29:22 -0800 | [diff] [blame] | 1579 | EXPECT_EQ(expected_remote_stream, |
| 1580 | report->Get(expected_remote_stream.id())->cast_to< |
| 1581 | RTCMediaStreamStats>()); |
| 1582 | |
hbos | 9e30274 | 2017-01-20 02:47:10 -0800 | [diff] [blame] | 1583 | RTCMediaStreamTrackStats expected_local_audio_track_ssrc1( |
| 1584 | "RTCMediaStreamTrack_local_audio_LocalAudioTrackID_1", |
| 1585 | report->timestamp_us(), RTCMediaStreamTrackKind::kAudio); |
| 1586 | expected_local_audio_track_ssrc1.track_identifier = local_audio_track->id(); |
| 1587 | expected_local_audio_track_ssrc1.remote_source = false; |
| 1588 | expected_local_audio_track_ssrc1.ended = true; |
| 1589 | expected_local_audio_track_ssrc1.detached = false; |
| 1590 | expected_local_audio_track_ssrc1.audio_level = 1.0; |
zstein | e76bd3a | 2017-07-14 12:17:49 -0700 | [diff] [blame] | 1591 | expected_local_audio_track_ssrc1.total_audio_energy = 0.25; |
| 1592 | expected_local_audio_track_ssrc1.total_samples_duration = 0.5; |
hbos | 9e30274 | 2017-01-20 02:47:10 -0800 | [diff] [blame] | 1593 | expected_local_audio_track_ssrc1.echo_return_loss = 42.0; |
| 1594 | expected_local_audio_track_ssrc1.echo_return_loss_enhancement = 52.0; |
| 1595 | ASSERT_TRUE(report->Get(expected_local_audio_track_ssrc1.id())); |
| 1596 | EXPECT_EQ(expected_local_audio_track_ssrc1, |
| 1597 | report->Get(expected_local_audio_track_ssrc1.id())->cast_to< |
| 1598 | RTCMediaStreamTrackStats>()); |
| 1599 | |
| 1600 | RTCMediaStreamTrackStats expected_local_audio_track_ssrc2( |
| 1601 | "RTCMediaStreamTrack_local_audio_LocalAudioTrackID_2", |
| 1602 | report->timestamp_us(), RTCMediaStreamTrackKind::kAudio); |
| 1603 | expected_local_audio_track_ssrc2.track_identifier = local_audio_track->id(); |
| 1604 | expected_local_audio_track_ssrc2.remote_source = false; |
| 1605 | expected_local_audio_track_ssrc2.ended = true; |
| 1606 | expected_local_audio_track_ssrc2.detached = false; |
| 1607 | expected_local_audio_track_ssrc2.audio_level = 0.0; |
zstein | e76bd3a | 2017-07-14 12:17:49 -0700 | [diff] [blame] | 1608 | expected_local_audio_track_ssrc2.total_audio_energy = 0.0; |
| 1609 | expected_local_audio_track_ssrc2.total_samples_duration = 0.0; |
hbos | 9e30274 | 2017-01-20 02:47:10 -0800 | [diff] [blame] | 1610 | // Should be undefined: |expected_local_audio_track_ssrc2.echo_return_loss| |
| 1611 | // and |expected_local_audio_track_ssrc2.echo_return_loss_enhancement|. |
| 1612 | ASSERT_TRUE(report->Get(expected_local_audio_track_ssrc2.id())); |
| 1613 | EXPECT_EQ(expected_local_audio_track_ssrc2, |
| 1614 | report->Get(expected_local_audio_track_ssrc2.id())->cast_to< |
hbos | 09bc128 | 2016-11-08 06:29:22 -0800 | [diff] [blame] | 1615 | RTCMediaStreamTrackStats>()); |
| 1616 | |
| 1617 | RTCMediaStreamTrackStats expected_remote_audio_track( |
hbos | 9e30274 | 2017-01-20 02:47:10 -0800 | [diff] [blame] | 1618 | "RTCMediaStreamTrack_remote_audio_RemoteAudioTrackID_3", |
| 1619 | report->timestamp_us(), RTCMediaStreamTrackKind::kAudio); |
hbos | 09bc128 | 2016-11-08 06:29:22 -0800 | [diff] [blame] | 1620 | expected_remote_audio_track.track_identifier = remote_audio_track->id(); |
| 1621 | expected_remote_audio_track.remote_source = true; |
| 1622 | expected_remote_audio_track.ended = false; |
| 1623 | expected_remote_audio_track.detached = false; |
hbos | 9e30274 | 2017-01-20 02:47:10 -0800 | [diff] [blame] | 1624 | expected_remote_audio_track.audio_level = 16383.0 / 32767.0; |
zstein | e76bd3a | 2017-07-14 12:17:49 -0700 | [diff] [blame] | 1625 | expected_remote_audio_track.total_audio_energy = 0.125; |
Steve Anton | 2dbc69f | 2017-08-24 17:15:13 -0700 | [diff] [blame] | 1626 | expected_remote_audio_track.total_samples_received = 4567; |
zstein | e76bd3a | 2017-07-14 12:17:49 -0700 | [diff] [blame] | 1627 | expected_remote_audio_track.total_samples_duration = 0.25; |
Steve Anton | 2dbc69f | 2017-08-24 17:15:13 -0700 | [diff] [blame] | 1628 | expected_remote_audio_track.concealed_samples = 123; |
Gustaf Ullberg | 9a2e906 | 2017-09-18 09:28:20 +0200 | [diff] [blame] | 1629 | expected_remote_audio_track.concealment_events = 12; |
Gustaf Ullberg | b0a0207 | 2017-10-02 12:00:34 +0200 | [diff] [blame] | 1630 | expected_remote_audio_track.jitter_buffer_delay = 3456; |
hbos | dbb64d8 | 2016-12-21 01:57:46 -0800 | [diff] [blame] | 1631 | ASSERT_TRUE(report->Get(expected_remote_audio_track.id())); |
hbos | 09bc128 | 2016-11-08 06:29:22 -0800 | [diff] [blame] | 1632 | EXPECT_EQ(expected_remote_audio_track, |
| 1633 | report->Get(expected_remote_audio_track.id())->cast_to< |
| 1634 | RTCMediaStreamTrackStats>()); |
| 1635 | } |
| 1636 | |
| 1637 | TEST_F(RTCStatsCollectorTest, |
| 1638 | CollectRTCMediaStreamStatsAndRTCMediaStreamTrackStats_Video) { |
| 1639 | rtc::scoped_refptr<StreamCollection> local_streams = |
| 1640 | StreamCollection::Create(); |
| 1641 | rtc::scoped_refptr<StreamCollection> remote_streams = |
| 1642 | StreamCollection::Create(); |
| 1643 | EXPECT_CALL(test_->pc(), local_streams()) |
| 1644 | .WillRepeatedly(Return(local_streams)); |
| 1645 | EXPECT_CALL(test_->pc(), remote_streams()) |
| 1646 | .WillRepeatedly(Return(remote_streams)); |
| 1647 | |
| 1648 | rtc::scoped_refptr<MediaStream> local_stream = |
| 1649 | MediaStream::Create("LocalStreamLabel"); |
| 1650 | local_streams->AddStream(local_stream); |
| 1651 | rtc::scoped_refptr<MediaStream> remote_stream = |
| 1652 | MediaStream::Create("RemoteStreamLabel"); |
| 1653 | remote_streams->AddStream(remote_stream); |
| 1654 | |
| 1655 | // Local video track |
hbos | 9e30274 | 2017-01-20 02:47:10 -0800 | [diff] [blame] | 1656 | rtc::scoped_refptr<MediaStreamTrackInterface> local_video_track = |
| 1657 | CreateFakeTrack(cricket::MEDIA_TYPE_VIDEO, "LocalVideoTrackID", |
| 1658 | MediaStreamTrackInterface::kLive); |
| 1659 | local_stream->AddTrack(static_cast<VideoTrackInterface*>( |
| 1660 | local_video_track.get())); |
hbos | 09bc128 | 2016-11-08 06:29:22 -0800 | [diff] [blame] | 1661 | |
hbos | 9e30274 | 2017-01-20 02:47:10 -0800 | [diff] [blame] | 1662 | cricket::VideoSenderInfo video_sender_info_ssrc1; |
| 1663 | video_sender_info_ssrc1.local_stats.push_back(cricket::SsrcSenderInfo()); |
| 1664 | video_sender_info_ssrc1.local_stats[0].ssrc = 1; |
| 1665 | video_sender_info_ssrc1.send_frame_width = 1234; |
| 1666 | video_sender_info_ssrc1.send_frame_height = 4321; |
hbos | fefe076 | 2017-01-20 06:14:25 -0800 | [diff] [blame] | 1667 | video_sender_info_ssrc1.frames_encoded = 11; |
hbos | 9e30274 | 2017-01-20 02:47:10 -0800 | [diff] [blame] | 1668 | |
| 1669 | cricket::VideoSenderInfo video_sender_info_ssrc2; |
| 1670 | video_sender_info_ssrc2.local_stats.push_back(cricket::SsrcSenderInfo()); |
| 1671 | video_sender_info_ssrc2.local_stats[0].ssrc = 2; |
| 1672 | video_sender_info_ssrc2.send_frame_width = 4321; |
| 1673 | video_sender_info_ssrc2.send_frame_height = 1234; |
hbos | fefe076 | 2017-01-20 06:14:25 -0800 | [diff] [blame] | 1674 | video_sender_info_ssrc2.frames_encoded = 22; |
hbos | 9e30274 | 2017-01-20 02:47:10 -0800 | [diff] [blame] | 1675 | |
| 1676 | // Remote video track with values |
| 1677 | rtc::scoped_refptr<MediaStreamTrackInterface> remote_video_track_ssrc3 = |
| 1678 | CreateFakeTrack(cricket::MEDIA_TYPE_VIDEO, "RemoteVideoTrackID3", |
| 1679 | MediaStreamTrackInterface::kEnded); |
| 1680 | remote_stream->AddTrack(static_cast<VideoTrackInterface*>( |
| 1681 | remote_video_track_ssrc3.get())); |
| 1682 | |
| 1683 | cricket::VideoReceiverInfo video_receiver_info_ssrc3; |
| 1684 | video_receiver_info_ssrc3.local_stats.push_back(cricket::SsrcReceiverInfo()); |
| 1685 | video_receiver_info_ssrc3.local_stats[0].ssrc = 3; |
| 1686 | video_receiver_info_ssrc3.frame_width = 6789; |
| 1687 | video_receiver_info_ssrc3.frame_height = 9876; |
hbos | 50cfe1f | 2017-01-23 07:21:55 -0800 | [diff] [blame] | 1688 | video_receiver_info_ssrc3.frames_received = 1000; |
| 1689 | video_receiver_info_ssrc3.frames_decoded = 995; |
| 1690 | video_receiver_info_ssrc3.frames_rendered = 990; |
hbos | 9e30274 | 2017-01-20 02:47:10 -0800 | [diff] [blame] | 1691 | |
| 1692 | // Remote video track with undefined (default) values |
| 1693 | rtc::scoped_refptr<MediaStreamTrackInterface> remote_video_track_ssrc4 = |
| 1694 | CreateFakeTrack(cricket::MEDIA_TYPE_VIDEO, "RemoteVideoTrackID4", |
| 1695 | MediaStreamTrackInterface::kLive); |
| 1696 | remote_stream->AddTrack(static_cast<VideoTrackInterface*>( |
| 1697 | remote_video_track_ssrc4.get())); |
| 1698 | |
| 1699 | cricket::VideoReceiverInfo video_receiver_info_ssrc4; |
| 1700 | video_receiver_info_ssrc4.local_stats.push_back(cricket::SsrcReceiverInfo()); |
| 1701 | video_receiver_info_ssrc4.local_stats[0].ssrc = 4; |
| 1702 | video_receiver_info_ssrc4.frame_width = 0; |
| 1703 | video_receiver_info_ssrc4.frame_height = 0; |
hbos | 42f6d2f | 2017-01-20 03:56:50 -0800 | [diff] [blame] | 1704 | video_receiver_info_ssrc4.frames_received = 0; |
hbos | f64941f | 2017-01-20 07:39:09 -0800 | [diff] [blame] | 1705 | video_receiver_info_ssrc4.frames_decoded = 0; |
hbos | 50cfe1f | 2017-01-23 07:21:55 -0800 | [diff] [blame] | 1706 | video_receiver_info_ssrc4.frames_rendered = 0; |
hbos | 9e30274 | 2017-01-20 02:47:10 -0800 | [diff] [blame] | 1707 | |
| 1708 | test_->CreateMockRtpSendersReceiversAndChannels( |
| 1709 | {}, {}, |
| 1710 | { std::make_pair(local_video_track.get(), video_sender_info_ssrc1), |
| 1711 | std::make_pair(local_video_track.get(), video_sender_info_ssrc2) }, |
| 1712 | { std::make_pair(remote_video_track_ssrc3.get(), |
| 1713 | video_receiver_info_ssrc3), |
| 1714 | std::make_pair(remote_video_track_ssrc4.get(), |
| 1715 | video_receiver_info_ssrc4) }); |
hbos | 09bc128 | 2016-11-08 06:29:22 -0800 | [diff] [blame] | 1716 | |
| 1717 | rtc::scoped_refptr<const RTCStatsReport> report = GetStatsReport(); |
| 1718 | |
| 1719 | RTCMediaStreamStats expected_local_stream( |
hbos | 02d2a92 | 2016-12-21 01:29:05 -0800 | [diff] [blame] | 1720 | "RTCMediaStream_local_LocalStreamLabel", report->timestamp_us()); |
hbos | 09bc128 | 2016-11-08 06:29:22 -0800 | [diff] [blame] | 1721 | expected_local_stream.stream_identifier = local_stream->label(); |
hbos | 9e30274 | 2017-01-20 02:47:10 -0800 | [diff] [blame] | 1722 | expected_local_stream.track_ids = std::vector<std::string>({ |
| 1723 | "RTCMediaStreamTrack_local_video_LocalVideoTrackID_1", |
| 1724 | "RTCMediaStreamTrack_local_video_LocalVideoTrackID_2" }); |
hbos | dbb64d8 | 2016-12-21 01:57:46 -0800 | [diff] [blame] | 1725 | ASSERT_TRUE(report->Get(expected_local_stream.id())); |
hbos | 09bc128 | 2016-11-08 06:29:22 -0800 | [diff] [blame] | 1726 | EXPECT_EQ(expected_local_stream, |
| 1727 | report->Get(expected_local_stream.id())->cast_to< |
| 1728 | RTCMediaStreamStats>()); |
| 1729 | |
| 1730 | RTCMediaStreamStats expected_remote_stream( |
hbos | 02d2a92 | 2016-12-21 01:29:05 -0800 | [diff] [blame] | 1731 | "RTCMediaStream_remote_RemoteStreamLabel", report->timestamp_us()); |
hbos | 09bc128 | 2016-11-08 06:29:22 -0800 | [diff] [blame] | 1732 | expected_remote_stream.stream_identifier = remote_stream->label(); |
hbos | 9e30274 | 2017-01-20 02:47:10 -0800 | [diff] [blame] | 1733 | expected_remote_stream.track_ids = std::vector<std::string>({ |
| 1734 | "RTCMediaStreamTrack_remote_video_RemoteVideoTrackID3_3", |
| 1735 | "RTCMediaStreamTrack_remote_video_RemoteVideoTrackID4_4" }); |
hbos | dbb64d8 | 2016-12-21 01:57:46 -0800 | [diff] [blame] | 1736 | ASSERT_TRUE(report->Get(expected_remote_stream.id())); |
hbos | 09bc128 | 2016-11-08 06:29:22 -0800 | [diff] [blame] | 1737 | EXPECT_EQ(expected_remote_stream, |
| 1738 | report->Get(expected_remote_stream.id())->cast_to< |
| 1739 | RTCMediaStreamStats>()); |
| 1740 | |
hbos | 9e30274 | 2017-01-20 02:47:10 -0800 | [diff] [blame] | 1741 | RTCMediaStreamTrackStats expected_local_video_track_ssrc1( |
| 1742 | "RTCMediaStreamTrack_local_video_LocalVideoTrackID_1", |
| 1743 | report->timestamp_us(), RTCMediaStreamTrackKind::kVideo); |
| 1744 | expected_local_video_track_ssrc1.track_identifier = local_video_track->id(); |
| 1745 | expected_local_video_track_ssrc1.remote_source = false; |
| 1746 | expected_local_video_track_ssrc1.ended = false; |
| 1747 | expected_local_video_track_ssrc1.detached = false; |
| 1748 | expected_local_video_track_ssrc1.frame_width = 1234; |
| 1749 | expected_local_video_track_ssrc1.frame_height = 4321; |
hbos | fefe076 | 2017-01-20 06:14:25 -0800 | [diff] [blame] | 1750 | expected_local_video_track_ssrc1.frames_sent = 11; |
hbos | 9e30274 | 2017-01-20 02:47:10 -0800 | [diff] [blame] | 1751 | ASSERT_TRUE(report->Get(expected_local_video_track_ssrc1.id())); |
| 1752 | EXPECT_EQ(expected_local_video_track_ssrc1, |
| 1753 | report->Get(expected_local_video_track_ssrc1.id())->cast_to< |
hbos | 09bc128 | 2016-11-08 06:29:22 -0800 | [diff] [blame] | 1754 | RTCMediaStreamTrackStats>()); |
| 1755 | |
hbos | 9e30274 | 2017-01-20 02:47:10 -0800 | [diff] [blame] | 1756 | RTCMediaStreamTrackStats expected_local_video_track_ssrc2( |
| 1757 | "RTCMediaStreamTrack_local_video_LocalVideoTrackID_2", |
| 1758 | report->timestamp_us(), RTCMediaStreamTrackKind::kVideo); |
| 1759 | expected_local_video_track_ssrc2.track_identifier = local_video_track->id(); |
| 1760 | expected_local_video_track_ssrc2.remote_source = false; |
| 1761 | expected_local_video_track_ssrc2.ended = false; |
| 1762 | expected_local_video_track_ssrc2.detached = false; |
| 1763 | expected_local_video_track_ssrc2.frame_width = 4321; |
| 1764 | expected_local_video_track_ssrc2.frame_height = 1234; |
hbos | fefe076 | 2017-01-20 06:14:25 -0800 | [diff] [blame] | 1765 | expected_local_video_track_ssrc2.frames_sent = 22; |
hbos | 9e30274 | 2017-01-20 02:47:10 -0800 | [diff] [blame] | 1766 | ASSERT_TRUE(report->Get(expected_local_video_track_ssrc2.id())); |
| 1767 | EXPECT_EQ(expected_local_video_track_ssrc2, |
| 1768 | report->Get(expected_local_video_track_ssrc2.id())->cast_to< |
| 1769 | RTCMediaStreamTrackStats>()); |
| 1770 | |
| 1771 | RTCMediaStreamTrackStats expected_remote_video_track_ssrc3( |
| 1772 | "RTCMediaStreamTrack_remote_video_RemoteVideoTrackID3_3", |
| 1773 | report->timestamp_us(), RTCMediaStreamTrackKind::kVideo); |
| 1774 | expected_remote_video_track_ssrc3.track_identifier = |
| 1775 | remote_video_track_ssrc3->id(); |
| 1776 | expected_remote_video_track_ssrc3.remote_source = true; |
| 1777 | expected_remote_video_track_ssrc3.ended = true; |
| 1778 | expected_remote_video_track_ssrc3.detached = false; |
| 1779 | expected_remote_video_track_ssrc3.frame_width = 6789; |
| 1780 | expected_remote_video_track_ssrc3.frame_height = 9876; |
hbos | 50cfe1f | 2017-01-23 07:21:55 -0800 | [diff] [blame] | 1781 | expected_remote_video_track_ssrc3.frames_received = 1000; |
| 1782 | expected_remote_video_track_ssrc3.frames_decoded = 995; |
| 1783 | expected_remote_video_track_ssrc3.frames_dropped = 1000 - 990; |
hbos | 9e30274 | 2017-01-20 02:47:10 -0800 | [diff] [blame] | 1784 | ASSERT_TRUE(report->Get(expected_remote_video_track_ssrc3.id())); |
| 1785 | EXPECT_EQ(expected_remote_video_track_ssrc3, |
| 1786 | report->Get(expected_remote_video_track_ssrc3.id())->cast_to< |
| 1787 | RTCMediaStreamTrackStats>()); |
| 1788 | |
| 1789 | RTCMediaStreamTrackStats expected_remote_video_track_ssrc4( |
| 1790 | "RTCMediaStreamTrack_remote_video_RemoteVideoTrackID4_4", |
| 1791 | report->timestamp_us(), RTCMediaStreamTrackKind::kVideo); |
| 1792 | expected_remote_video_track_ssrc4.track_identifier = |
| 1793 | remote_video_track_ssrc4->id(); |
| 1794 | expected_remote_video_track_ssrc4.remote_source = true; |
| 1795 | expected_remote_video_track_ssrc4.ended = false; |
| 1796 | expected_remote_video_track_ssrc4.detached = false; |
hbos | 42f6d2f | 2017-01-20 03:56:50 -0800 | [diff] [blame] | 1797 | expected_remote_video_track_ssrc4.frames_received = 0; |
hbos | f64941f | 2017-01-20 07:39:09 -0800 | [diff] [blame] | 1798 | expected_remote_video_track_ssrc4.frames_decoded = 0; |
hbos | 50cfe1f | 2017-01-23 07:21:55 -0800 | [diff] [blame] | 1799 | expected_remote_video_track_ssrc4.frames_dropped = 0; |
hbos | 9e30274 | 2017-01-20 02:47:10 -0800 | [diff] [blame] | 1800 | // Should be undefined: |expected_remote_video_track_ssrc4.frame_width| and |
| 1801 | // |expected_remote_video_track_ssrc4.frame_height|. |
| 1802 | ASSERT_TRUE(report->Get(expected_remote_video_track_ssrc4.id())); |
| 1803 | EXPECT_EQ(expected_remote_video_track_ssrc4, |
| 1804 | report->Get(expected_remote_video_track_ssrc4.id())->cast_to< |
hbos | 09bc128 | 2016-11-08 06:29:22 -0800 | [diff] [blame] | 1805 | RTCMediaStreamTrackStats>()); |
| 1806 | } |
| 1807 | |
hbos | eeafe94 | 2016-11-01 03:00:17 -0700 | [diff] [blame] | 1808 | TEST_F(RTCStatsCollectorTest, CollectRTCInboundRTPStreamStats_Audio) { |
Steve Anton | 8699a32 | 2017-11-06 15:53:33 -0800 | [diff] [blame] | 1809 | auto* voice_media_channel = new MockVoiceMediaChannel(); |
hbos | eeafe94 | 2016-11-01 03:00:17 -0700 | [diff] [blame] | 1810 | cricket::VoiceChannel voice_channel( |
deadbeef | bad5dad | 2017-01-17 18:32:35 -0800 | [diff] [blame] | 1811 | test_->worker_thread(), test_->network_thread(), |
Steve Anton | 8699a32 | 2017-11-06 15:53:33 -0800 | [diff] [blame] | 1812 | test_->signaling_thread(), test_->media_engine(), |
| 1813 | rtc::WrapUnique(voice_media_channel), "VoiceContentName", |
| 1814 | kDefaultRtcpMuxRequired, kDefaultSrtpRequired); |
Steve Anton | 593e325 | 2017-12-15 11:44:48 -0800 | [diff] [blame] | 1815 | voice_channel.set_transport_name_for_testing("TransportName"); |
hbos | eeafe94 | 2016-11-01 03:00:17 -0700 | [diff] [blame] | 1816 | |
hbos | 84abeb1 | 2017-01-16 06:16:44 -0800 | [diff] [blame] | 1817 | test_->SetupRemoteTrackAndReceiver( |
| 1818 | cricket::MEDIA_TYPE_AUDIO, "RemoteAudioTrackID", 1); |
| 1819 | |
hbos | eeafe94 | 2016-11-01 03:00:17 -0700 | [diff] [blame] | 1820 | cricket::VoiceMediaInfo voice_media_info; |
hbos | 0adb828 | 2016-11-23 02:32:06 -0800 | [diff] [blame] | 1821 | |
hbos | eeafe94 | 2016-11-01 03:00:17 -0700 | [diff] [blame] | 1822 | voice_media_info.receivers.push_back(cricket::VoiceReceiverInfo()); |
| 1823 | voice_media_info.receivers[0].local_stats.push_back( |
| 1824 | cricket::SsrcReceiverInfo()); |
| 1825 | voice_media_info.receivers[0].local_stats[0].ssrc = 1; |
Harald Alvestrand | 719487e | 2017-12-13 12:26:04 +0100 | [diff] [blame] | 1826 | voice_media_info.receivers[0].packets_lost = -1; // Signed per RFC3550 |
hbos | eeafe94 | 2016-11-01 03:00:17 -0700 | [diff] [blame] | 1827 | voice_media_info.receivers[0].packets_rcvd = 2; |
| 1828 | voice_media_info.receivers[0].bytes_rcvd = 3; |
Oskar Sundbom | cbc71b2 | 2017-11-16 10:56:07 +0100 | [diff] [blame] | 1829 | voice_media_info.receivers[0].codec_payload_type = 42; |
hbos | eeafe94 | 2016-11-01 03:00:17 -0700 | [diff] [blame] | 1830 | voice_media_info.receivers[0].jitter_ms = 4500; |
| 1831 | voice_media_info.receivers[0].fraction_lost = 5.5f; |
hbos | 0adb828 | 2016-11-23 02:32:06 -0800 | [diff] [blame] | 1832 | |
| 1833 | RtpCodecParameters codec_parameters; |
| 1834 | codec_parameters.payload_type = 42; |
deadbeef | e702b30 | 2017-02-04 12:09:01 -0800 | [diff] [blame] | 1835 | codec_parameters.kind = cricket::MEDIA_TYPE_AUDIO; |
| 1836 | codec_parameters.name = "dummy"; |
Oskar Sundbom | cbc71b2 | 2017-11-16 10:56:07 +0100 | [diff] [blame] | 1837 | codec_parameters.clock_rate = 0; |
hbos | 0adb828 | 2016-11-23 02:32:06 -0800 | [diff] [blame] | 1838 | voice_media_info.receive_codecs.insert( |
| 1839 | std::make_pair(codec_parameters.payload_type, codec_parameters)); |
| 1840 | |
hbos | eeafe94 | 2016-11-01 03:00:17 -0700 | [diff] [blame] | 1841 | EXPECT_CALL(*voice_media_channel, GetStats(_)) |
| 1842 | .WillOnce(DoAll(SetArgPointee<0>(voice_media_info), Return(true))); |
| 1843 | |
| 1844 | SessionStats session_stats; |
hbos | eeafe94 | 2016-11-01 03:00:17 -0700 | [diff] [blame] | 1845 | session_stats.transport_stats["TransportName"].transport_name = |
| 1846 | "TransportName"; |
| 1847 | |
| 1848 | // Make sure the associated |RTCTransportStats| is created. |
| 1849 | cricket::TransportChannelStats channel_stats; |
| 1850 | channel_stats.component = cricket::ICE_CANDIDATE_COMPONENT_RTP; |
| 1851 | session_stats.transport_stats["TransportName"].channel_stats.push_back( |
| 1852 | channel_stats); |
| 1853 | |
Steve Anton | 75737c0 | 2017-11-06 10:37:17 -0800 | [diff] [blame] | 1854 | EXPECT_CALL(test_->pc(), GetSessionStats(_)) |
Steve Anton | ba81867 | 2017-11-06 10:21:57 -0800 | [diff] [blame] | 1855 | .WillRepeatedly(Invoke([&session_stats](const ChannelNamePairs&) { |
hbos | df6075a | 2016-12-19 04:58:02 -0800 | [diff] [blame] | 1856 | return std::unique_ptr<SessionStats>(new SessionStats(session_stats)); |
| 1857 | })); |
Steve Anton | 75737c0 | 2017-11-06 10:37:17 -0800 | [diff] [blame] | 1858 | EXPECT_CALL(test_->pc(), voice_channel()) |
hbos | eeafe94 | 2016-11-01 03:00:17 -0700 | [diff] [blame] | 1859 | .WillRepeatedly(Return(&voice_channel)); |
| 1860 | |
| 1861 | rtc::scoped_refptr<const RTCStatsReport> report = GetStatsReport(); |
| 1862 | |
| 1863 | RTCInboundRTPStreamStats expected_audio( |
| 1864 | "RTCInboundRTPAudioStream_1", report->timestamp_us()); |
hbos | 3443bb7 | 2017-02-07 06:28:11 -0800 | [diff] [blame] | 1865 | expected_audio.ssrc = 1; |
hbos | eeafe94 | 2016-11-01 03:00:17 -0700 | [diff] [blame] | 1866 | expected_audio.is_remote = false; |
| 1867 | expected_audio.media_type = "audio"; |
hbos | b0ae920 | 2017-01-27 06:35:16 -0800 | [diff] [blame] | 1868 | expected_audio.track_id = |
hbos | 9e30274 | 2017-01-20 02:47:10 -0800 | [diff] [blame] | 1869 | "RTCMediaStreamTrack_remote_audio_RemoteAudioTrackID_1"; |
hbos | eeafe94 | 2016-11-01 03:00:17 -0700 | [diff] [blame] | 1870 | expected_audio.transport_id = "RTCTransport_TransportName_" + |
| 1871 | rtc::ToString<>(cricket::ICE_CANDIDATE_COMPONENT_RTP); |
hbos | 0adb828 | 2016-11-23 02:32:06 -0800 | [diff] [blame] | 1872 | expected_audio.codec_id = "RTCCodec_InboundAudio_42"; |
hbos | eeafe94 | 2016-11-01 03:00:17 -0700 | [diff] [blame] | 1873 | expected_audio.packets_received = 2; |
| 1874 | expected_audio.bytes_received = 3; |
Harald Alvestrand | 719487e | 2017-12-13 12:26:04 +0100 | [diff] [blame] | 1875 | expected_audio.packets_lost = -1; |
hbos | eeafe94 | 2016-11-01 03:00:17 -0700 | [diff] [blame] | 1876 | expected_audio.jitter = 4.5; |
| 1877 | expected_audio.fraction_lost = 5.5; |
| 1878 | |
nisse | c8ee882 | 2017-01-18 07:20:55 -0800 | [diff] [blame] | 1879 | ASSERT_TRUE(report->Get(expected_audio.id())); |
hbos | a51d4f3 | 2017-02-16 05:34:48 -0800 | [diff] [blame] | 1880 | EXPECT_EQ( |
| 1881 | report->Get(expected_audio.id())->cast_to<RTCInboundRTPStreamStats>(), |
| 1882 | expected_audio); |
hbos | b0ae920 | 2017-01-27 06:35:16 -0800 | [diff] [blame] | 1883 | EXPECT_TRUE(report->Get(*expected_audio.track_id)); |
hbos | 84abeb1 | 2017-01-16 06:16:44 -0800 | [diff] [blame] | 1884 | EXPECT_TRUE(report->Get(*expected_audio.transport_id)); |
| 1885 | EXPECT_TRUE(report->Get(*expected_audio.codec_id)); |
hbos | eeafe94 | 2016-11-01 03:00:17 -0700 | [diff] [blame] | 1886 | } |
| 1887 | |
| 1888 | TEST_F(RTCStatsCollectorTest, CollectRTCInboundRTPStreamStats_Video) { |
Steve Anton | 8699a32 | 2017-11-06 15:53:33 -0800 | [diff] [blame] | 1889 | auto* video_media_channel = new MockVideoMediaChannel(); |
hbos | eeafe94 | 2016-11-01 03:00:17 -0700 | [diff] [blame] | 1890 | cricket::VideoChannel video_channel( |
deadbeef | bad5dad | 2017-01-17 18:32:35 -0800 | [diff] [blame] | 1891 | test_->worker_thread(), test_->network_thread(), |
Steve Anton | 8699a32 | 2017-11-06 15:53:33 -0800 | [diff] [blame] | 1892 | test_->signaling_thread(), rtc::WrapUnique(video_media_channel), |
| 1893 | "VideoContentName", kDefaultRtcpMuxRequired, kDefaultSrtpRequired); |
Steve Anton | 593e325 | 2017-12-15 11:44:48 -0800 | [diff] [blame] | 1894 | video_channel.set_transport_name_for_testing("TransportName"); |
hbos | eeafe94 | 2016-11-01 03:00:17 -0700 | [diff] [blame] | 1895 | |
hbos | 84abeb1 | 2017-01-16 06:16:44 -0800 | [diff] [blame] | 1896 | test_->SetupRemoteTrackAndReceiver( |
| 1897 | cricket::MEDIA_TYPE_VIDEO, "RemoteVideoTrackID", 1); |
| 1898 | |
hbos | eeafe94 | 2016-11-01 03:00:17 -0700 | [diff] [blame] | 1899 | cricket::VideoMediaInfo video_media_info; |
hbos | 0adb828 | 2016-11-23 02:32:06 -0800 | [diff] [blame] | 1900 | |
hbos | eeafe94 | 2016-11-01 03:00:17 -0700 | [diff] [blame] | 1901 | video_media_info.receivers.push_back(cricket::VideoReceiverInfo()); |
| 1902 | video_media_info.receivers[0].local_stats.push_back( |
| 1903 | cricket::SsrcReceiverInfo()); |
| 1904 | video_media_info.receivers[0].local_stats[0].ssrc = 1; |
| 1905 | video_media_info.receivers[0].packets_rcvd = 2; |
hbos | 02cd4d6 | 2016-12-09 04:19:44 -0800 | [diff] [blame] | 1906 | video_media_info.receivers[0].packets_lost = 42; |
hbos | eeafe94 | 2016-11-01 03:00:17 -0700 | [diff] [blame] | 1907 | video_media_info.receivers[0].bytes_rcvd = 3; |
| 1908 | video_media_info.receivers[0].fraction_lost = 4.5f; |
Oskar Sundbom | cbc71b2 | 2017-11-16 10:56:07 +0100 | [diff] [blame] | 1909 | video_media_info.receivers[0].codec_payload_type = 42; |
hbos | 820f578 | 2016-11-22 03:16:50 -0800 | [diff] [blame] | 1910 | video_media_info.receivers[0].firs_sent = 5; |
| 1911 | video_media_info.receivers[0].plis_sent = 6; |
| 1912 | video_media_info.receivers[0].nacks_sent = 7; |
hbos | 6769c49 | 2017-01-02 08:35:13 -0800 | [diff] [blame] | 1913 | video_media_info.receivers[0].frames_decoded = 8; |
Oskar Sundbom | cbc71b2 | 2017-11-16 10:56:07 +0100 | [diff] [blame] | 1914 | video_media_info.receivers[0].qp_sum = rtc::nullopt; |
hbos | 0adb828 | 2016-11-23 02:32:06 -0800 | [diff] [blame] | 1915 | |
| 1916 | RtpCodecParameters codec_parameters; |
| 1917 | codec_parameters.payload_type = 42; |
deadbeef | e702b30 | 2017-02-04 12:09:01 -0800 | [diff] [blame] | 1918 | codec_parameters.kind = cricket::MEDIA_TYPE_AUDIO; |
| 1919 | codec_parameters.name = "dummy"; |
Oskar Sundbom | cbc71b2 | 2017-11-16 10:56:07 +0100 | [diff] [blame] | 1920 | codec_parameters.clock_rate = 0; |
hbos | 0adb828 | 2016-11-23 02:32:06 -0800 | [diff] [blame] | 1921 | video_media_info.receive_codecs.insert( |
| 1922 | std::make_pair(codec_parameters.payload_type, codec_parameters)); |
| 1923 | |
hbos | eeafe94 | 2016-11-01 03:00:17 -0700 | [diff] [blame] | 1924 | EXPECT_CALL(*video_media_channel, GetStats(_)) |
| 1925 | .WillOnce(DoAll(SetArgPointee<0>(video_media_info), Return(true))); |
| 1926 | |
| 1927 | SessionStats session_stats; |
hbos | eeafe94 | 2016-11-01 03:00:17 -0700 | [diff] [blame] | 1928 | session_stats.transport_stats["TransportName"].transport_name = |
| 1929 | "TransportName"; |
| 1930 | |
| 1931 | // Make sure the associated |RTCTransportStats| is created. |
| 1932 | cricket::TransportChannelStats channel_stats; |
| 1933 | channel_stats.component = cricket::ICE_CANDIDATE_COMPONENT_RTP; |
| 1934 | session_stats.transport_stats["TransportName"].channel_stats.push_back( |
| 1935 | channel_stats); |
| 1936 | |
Steve Anton | 75737c0 | 2017-11-06 10:37:17 -0800 | [diff] [blame] | 1937 | EXPECT_CALL(test_->pc(), GetSessionStats(_)) |
Steve Anton | ba81867 | 2017-11-06 10:21:57 -0800 | [diff] [blame] | 1938 | .WillRepeatedly(Invoke([&session_stats](const ChannelNamePairs&) { |
hbos | df6075a | 2016-12-19 04:58:02 -0800 | [diff] [blame] | 1939 | return std::unique_ptr<SessionStats>(new SessionStats(session_stats)); |
| 1940 | })); |
Steve Anton | 75737c0 | 2017-11-06 10:37:17 -0800 | [diff] [blame] | 1941 | EXPECT_CALL(test_->pc(), video_channel()) |
hbos | eeafe94 | 2016-11-01 03:00:17 -0700 | [diff] [blame] | 1942 | .WillRepeatedly(Return(&video_channel)); |
| 1943 | |
| 1944 | rtc::scoped_refptr<const RTCStatsReport> report = GetStatsReport(); |
| 1945 | |
hbos | 820f578 | 2016-11-22 03:16:50 -0800 | [diff] [blame] | 1946 | RTCInboundRTPStreamStats expected_video( |
hbos | eeafe94 | 2016-11-01 03:00:17 -0700 | [diff] [blame] | 1947 | "RTCInboundRTPVideoStream_1", report->timestamp_us()); |
hbos | 3443bb7 | 2017-02-07 06:28:11 -0800 | [diff] [blame] | 1948 | expected_video.ssrc = 1; |
hbos | 820f578 | 2016-11-22 03:16:50 -0800 | [diff] [blame] | 1949 | expected_video.is_remote = false; |
| 1950 | expected_video.media_type = "video"; |
hbos | b0ae920 | 2017-01-27 06:35:16 -0800 | [diff] [blame] | 1951 | expected_video.track_id = |
hbos | 9e30274 | 2017-01-20 02:47:10 -0800 | [diff] [blame] | 1952 | "RTCMediaStreamTrack_remote_video_RemoteVideoTrackID_1"; |
hbos | 820f578 | 2016-11-22 03:16:50 -0800 | [diff] [blame] | 1953 | expected_video.transport_id = "RTCTransport_TransportName_" + |
hbos | eeafe94 | 2016-11-01 03:00:17 -0700 | [diff] [blame] | 1954 | rtc::ToString<>(cricket::ICE_CANDIDATE_COMPONENT_RTP); |
hbos | 0adb828 | 2016-11-23 02:32:06 -0800 | [diff] [blame] | 1955 | expected_video.codec_id = "RTCCodec_InboundVideo_42"; |
hbos | 820f578 | 2016-11-22 03:16:50 -0800 | [diff] [blame] | 1956 | expected_video.fir_count = 5; |
| 1957 | expected_video.pli_count = 6; |
| 1958 | expected_video.nack_count = 7; |
| 1959 | expected_video.packets_received = 2; |
| 1960 | expected_video.bytes_received = 3; |
hbos | 02cd4d6 | 2016-12-09 04:19:44 -0800 | [diff] [blame] | 1961 | expected_video.packets_lost = 42; |
hbos | 820f578 | 2016-11-22 03:16:50 -0800 | [diff] [blame] | 1962 | expected_video.fraction_lost = 4.5; |
hbos | 6769c49 | 2017-01-02 08:35:13 -0800 | [diff] [blame] | 1963 | expected_video.frames_decoded = 8; |
hbos | a51d4f3 | 2017-02-16 05:34:48 -0800 | [diff] [blame] | 1964 | // |expected_video.qp_sum| should be undefined. |
hbos | eeafe94 | 2016-11-01 03:00:17 -0700 | [diff] [blame] | 1965 | |
nisse | c8ee882 | 2017-01-18 07:20:55 -0800 | [diff] [blame] | 1966 | ASSERT_TRUE(report->Get(expected_video.id())); |
hbos | a51d4f3 | 2017-02-16 05:34:48 -0800 | [diff] [blame] | 1967 | EXPECT_EQ( |
| 1968 | report->Get(expected_video.id())->cast_to<RTCInboundRTPStreamStats>(), |
| 1969 | expected_video); |
hbos | eeafe94 | 2016-11-01 03:00:17 -0700 | [diff] [blame] | 1970 | |
hbos | a51d4f3 | 2017-02-16 05:34:48 -0800 | [diff] [blame] | 1971 | // Set previously undefined values and "GetStats" again. |
Oskar Sundbom | cbc71b2 | 2017-11-16 10:56:07 +0100 | [diff] [blame] | 1972 | video_media_info.receivers[0].qp_sum = 9; |
hbos | a51d4f3 | 2017-02-16 05:34:48 -0800 | [diff] [blame] | 1973 | expected_video.qp_sum = 9; |
| 1974 | |
| 1975 | EXPECT_CALL(*video_media_channel, GetStats(_)) |
| 1976 | .WillOnce(DoAll(SetArgPointee<0>(video_media_info), Return(true))); |
| 1977 | collector_->ClearCachedStatsReport(); |
| 1978 | report = GetStatsReport(); |
| 1979 | |
| 1980 | ASSERT_TRUE(report->Get(expected_video.id())); |
| 1981 | EXPECT_EQ( |
| 1982 | report->Get(expected_video.id())->cast_to<RTCInboundRTPStreamStats>(), |
| 1983 | expected_video); |
hbos | b0ae920 | 2017-01-27 06:35:16 -0800 | [diff] [blame] | 1984 | EXPECT_TRUE(report->Get(*expected_video.track_id)); |
hbos | 84abeb1 | 2017-01-16 06:16:44 -0800 | [diff] [blame] | 1985 | EXPECT_TRUE(report->Get(*expected_video.transport_id)); |
hbos | a51d4f3 | 2017-02-16 05:34:48 -0800 | [diff] [blame] | 1986 | EXPECT_TRUE(report->Get(*expected_video.codec_id)); |
hbos | eeafe94 | 2016-11-01 03:00:17 -0700 | [diff] [blame] | 1987 | } |
| 1988 | |
hbos | 6ded190 | 2016-11-01 01:50:46 -0700 | [diff] [blame] | 1989 | TEST_F(RTCStatsCollectorTest, CollectRTCOutboundRTPStreamStats_Audio) { |
Steve Anton | 8699a32 | 2017-11-06 15:53:33 -0800 | [diff] [blame] | 1990 | auto* voice_media_channel = new MockVoiceMediaChannel(); |
hbos | 6ded190 | 2016-11-01 01:50:46 -0700 | [diff] [blame] | 1991 | cricket::VoiceChannel voice_channel( |
deadbeef | bad5dad | 2017-01-17 18:32:35 -0800 | [diff] [blame] | 1992 | test_->worker_thread(), test_->network_thread(), |
Steve Anton | 8699a32 | 2017-11-06 15:53:33 -0800 | [diff] [blame] | 1993 | test_->signaling_thread(), test_->media_engine(), |
| 1994 | rtc::WrapUnique(voice_media_channel), "VoiceContentName", |
| 1995 | kDefaultRtcpMuxRequired, kDefaultSrtpRequired); |
Steve Anton | 593e325 | 2017-12-15 11:44:48 -0800 | [diff] [blame] | 1996 | voice_channel.set_transport_name_for_testing("TransportName"); |
hbos | 6ded190 | 2016-11-01 01:50:46 -0700 | [diff] [blame] | 1997 | |
Harald Alvestrand | 8906187 | 2018-01-02 14:08:34 +0100 | [diff] [blame] | 1998 | test_->SetupLocalTrackAndSender(cricket::MEDIA_TYPE_AUDIO, |
| 1999 | "LocalAudioTrackID", 1, true); |
hbos | 84abeb1 | 2017-01-16 06:16:44 -0800 | [diff] [blame] | 2000 | |
hbos | 6ded190 | 2016-11-01 01:50:46 -0700 | [diff] [blame] | 2001 | cricket::VoiceMediaInfo voice_media_info; |
hbos | 0adb828 | 2016-11-23 02:32:06 -0800 | [diff] [blame] | 2002 | |
hbos | 6ded190 | 2016-11-01 01:50:46 -0700 | [diff] [blame] | 2003 | voice_media_info.senders.push_back(cricket::VoiceSenderInfo()); |
| 2004 | voice_media_info.senders[0].local_stats.push_back(cricket::SsrcSenderInfo()); |
| 2005 | voice_media_info.senders[0].local_stats[0].ssrc = 1; |
| 2006 | voice_media_info.senders[0].packets_sent = 2; |
| 2007 | voice_media_info.senders[0].bytes_sent = 3; |
Oskar Sundbom | cbc71b2 | 2017-11-16 10:56:07 +0100 | [diff] [blame] | 2008 | voice_media_info.senders[0].codec_payload_type = 42; |
hbos | 0adb828 | 2016-11-23 02:32:06 -0800 | [diff] [blame] | 2009 | |
| 2010 | RtpCodecParameters codec_parameters; |
| 2011 | codec_parameters.payload_type = 42; |
deadbeef | e702b30 | 2017-02-04 12:09:01 -0800 | [diff] [blame] | 2012 | codec_parameters.kind = cricket::MEDIA_TYPE_AUDIO; |
| 2013 | codec_parameters.name = "dummy"; |
Oskar Sundbom | cbc71b2 | 2017-11-16 10:56:07 +0100 | [diff] [blame] | 2014 | codec_parameters.clock_rate = 0; |
hbos | 0adb828 | 2016-11-23 02:32:06 -0800 | [diff] [blame] | 2015 | voice_media_info.send_codecs.insert( |
| 2016 | std::make_pair(codec_parameters.payload_type, codec_parameters)); |
| 2017 | |
hbos | 6ded190 | 2016-11-01 01:50:46 -0700 | [diff] [blame] | 2018 | EXPECT_CALL(*voice_media_channel, GetStats(_)) |
| 2019 | .WillOnce(DoAll(SetArgPointee<0>(voice_media_info), Return(true))); |
| 2020 | |
| 2021 | SessionStats session_stats; |
hbos | 6ded190 | 2016-11-01 01:50:46 -0700 | [diff] [blame] | 2022 | session_stats.transport_stats["TransportName"].transport_name = |
| 2023 | "TransportName"; |
| 2024 | |
| 2025 | // Make sure the associated |RTCTransportStats| is created. |
| 2026 | cricket::TransportChannelStats channel_stats; |
| 2027 | channel_stats.component = cricket::ICE_CANDIDATE_COMPONENT_RTP; |
hbos | 6ded190 | 2016-11-01 01:50:46 -0700 | [diff] [blame] | 2028 | session_stats.transport_stats["TransportName"].channel_stats.push_back( |
| 2029 | channel_stats); |
| 2030 | |
Steve Anton | 75737c0 | 2017-11-06 10:37:17 -0800 | [diff] [blame] | 2031 | EXPECT_CALL(test_->pc(), GetSessionStats(_)) |
Steve Anton | ba81867 | 2017-11-06 10:21:57 -0800 | [diff] [blame] | 2032 | .WillRepeatedly(Invoke([&session_stats](const ChannelNamePairs&) { |
hbos | df6075a | 2016-12-19 04:58:02 -0800 | [diff] [blame] | 2033 | return std::unique_ptr<SessionStats>(new SessionStats(session_stats)); |
| 2034 | })); |
Steve Anton | 75737c0 | 2017-11-06 10:37:17 -0800 | [diff] [blame] | 2035 | EXPECT_CALL(test_->pc(), voice_channel()) |
hbos | 6ded190 | 2016-11-01 01:50:46 -0700 | [diff] [blame] | 2036 | .WillRepeatedly(Return(&voice_channel)); |
| 2037 | |
| 2038 | rtc::scoped_refptr<const RTCStatsReport> report = GetStatsReport(); |
| 2039 | |
| 2040 | RTCOutboundRTPStreamStats expected_audio( |
| 2041 | "RTCOutboundRTPAudioStream_1", report->timestamp_us()); |
hbos | 3443bb7 | 2017-02-07 06:28:11 -0800 | [diff] [blame] | 2042 | expected_audio.ssrc = 1; |
hbos | 6ded190 | 2016-11-01 01:50:46 -0700 | [diff] [blame] | 2043 | expected_audio.is_remote = false; |
| 2044 | expected_audio.media_type = "audio"; |
hbos | b0ae920 | 2017-01-27 06:35:16 -0800 | [diff] [blame] | 2045 | expected_audio.track_id = |
hbos | 9e30274 | 2017-01-20 02:47:10 -0800 | [diff] [blame] | 2046 | "RTCMediaStreamTrack_local_audio_LocalAudioTrackID_1"; |
hbos | 6ded190 | 2016-11-01 01:50:46 -0700 | [diff] [blame] | 2047 | expected_audio.transport_id = "RTCTransport_TransportName_" + |
| 2048 | rtc::ToString<>(cricket::ICE_CANDIDATE_COMPONENT_RTP); |
hbos | 0adb828 | 2016-11-23 02:32:06 -0800 | [diff] [blame] | 2049 | expected_audio.codec_id = "RTCCodec_OutboundAudio_42"; |
hbos | 6ded190 | 2016-11-01 01:50:46 -0700 | [diff] [blame] | 2050 | expected_audio.packets_sent = 2; |
| 2051 | expected_audio.bytes_sent = 3; |
hbos | cd195be | 2017-02-07 08:31:27 -0800 | [diff] [blame] | 2052 | |
hbos | cd195be | 2017-02-07 08:31:27 -0800 | [diff] [blame] | 2053 | ASSERT_TRUE(report->Get(expected_audio.id())); |
hbos | a51d4f3 | 2017-02-16 05:34:48 -0800 | [diff] [blame] | 2054 | EXPECT_EQ( |
| 2055 | report->Get(expected_audio.id())->cast_to<RTCOutboundRTPStreamStats>(), |
| 2056 | expected_audio); |
skvlad | ed02c6d | 2017-02-07 10:45:31 -0800 | [diff] [blame] | 2057 | |
hbos | a51d4f3 | 2017-02-16 05:34:48 -0800 | [diff] [blame] | 2058 | ASSERT_TRUE(report->Get(expected_audio.id())); |
| 2059 | EXPECT_EQ( |
| 2060 | report->Get(expected_audio.id())->cast_to<RTCOutboundRTPStreamStats>(), |
| 2061 | expected_audio); |
hbos | b0ae920 | 2017-01-27 06:35:16 -0800 | [diff] [blame] | 2062 | EXPECT_TRUE(report->Get(*expected_audio.track_id)); |
hbos | 84abeb1 | 2017-01-16 06:16:44 -0800 | [diff] [blame] | 2063 | EXPECT_TRUE(report->Get(*expected_audio.transport_id)); |
| 2064 | EXPECT_TRUE(report->Get(*expected_audio.codec_id)); |
hbos | 6ded190 | 2016-11-01 01:50:46 -0700 | [diff] [blame] | 2065 | } |
| 2066 | |
| 2067 | TEST_F(RTCStatsCollectorTest, CollectRTCOutboundRTPStreamStats_Video) { |
Steve Anton | 8699a32 | 2017-11-06 15:53:33 -0800 | [diff] [blame] | 2068 | auto* video_media_channel = new MockVideoMediaChannel(); |
hbos | 6ded190 | 2016-11-01 01:50:46 -0700 | [diff] [blame] | 2069 | cricket::VideoChannel video_channel( |
deadbeef | bad5dad | 2017-01-17 18:32:35 -0800 | [diff] [blame] | 2070 | test_->worker_thread(), test_->network_thread(), |
Steve Anton | 8699a32 | 2017-11-06 15:53:33 -0800 | [diff] [blame] | 2071 | test_->signaling_thread(), rtc::WrapUnique(video_media_channel), |
| 2072 | "VideoContentName", kDefaultRtcpMuxRequired, kDefaultSrtpRequired); |
Steve Anton | 593e325 | 2017-12-15 11:44:48 -0800 | [diff] [blame] | 2073 | video_channel.set_transport_name_for_testing("TransportName"); |
hbos | 6ded190 | 2016-11-01 01:50:46 -0700 | [diff] [blame] | 2074 | |
Harald Alvestrand | 8906187 | 2018-01-02 14:08:34 +0100 | [diff] [blame] | 2075 | test_->SetupLocalTrackAndSender(cricket::MEDIA_TYPE_VIDEO, |
| 2076 | "LocalVideoTrackID", 1, true); |
hbos | 84abeb1 | 2017-01-16 06:16:44 -0800 | [diff] [blame] | 2077 | |
hbos | 6ded190 | 2016-11-01 01:50:46 -0700 | [diff] [blame] | 2078 | cricket::VideoMediaInfo video_media_info; |
hbos | 0adb828 | 2016-11-23 02:32:06 -0800 | [diff] [blame] | 2079 | |
hbos | 6ded190 | 2016-11-01 01:50:46 -0700 | [diff] [blame] | 2080 | video_media_info.senders.push_back(cricket::VideoSenderInfo()); |
| 2081 | video_media_info.senders[0].local_stats.push_back(cricket::SsrcSenderInfo()); |
| 2082 | video_media_info.senders[0].local_stats[0].ssrc = 1; |
| 2083 | video_media_info.senders[0].firs_rcvd = 2; |
| 2084 | video_media_info.senders[0].plis_rcvd = 3; |
| 2085 | video_media_info.senders[0].nacks_rcvd = 4; |
| 2086 | video_media_info.senders[0].packets_sent = 5; |
| 2087 | video_media_info.senders[0].bytes_sent = 6; |
Oskar Sundbom | cbc71b2 | 2017-11-16 10:56:07 +0100 | [diff] [blame] | 2088 | video_media_info.senders[0].codec_payload_type = 42; |
hbos | 6769c49 | 2017-01-02 08:35:13 -0800 | [diff] [blame] | 2089 | video_media_info.senders[0].frames_encoded = 8; |
Oskar Sundbom | cbc71b2 | 2017-11-16 10:56:07 +0100 | [diff] [blame] | 2090 | video_media_info.senders[0].qp_sum = rtc::nullopt; |
hbos | 0adb828 | 2016-11-23 02:32:06 -0800 | [diff] [blame] | 2091 | |
| 2092 | RtpCodecParameters codec_parameters; |
| 2093 | codec_parameters.payload_type = 42; |
deadbeef | e702b30 | 2017-02-04 12:09:01 -0800 | [diff] [blame] | 2094 | codec_parameters.kind = cricket::MEDIA_TYPE_AUDIO; |
| 2095 | codec_parameters.name = "dummy"; |
Oskar Sundbom | cbc71b2 | 2017-11-16 10:56:07 +0100 | [diff] [blame] | 2096 | codec_parameters.clock_rate = 0; |
hbos | 0adb828 | 2016-11-23 02:32:06 -0800 | [diff] [blame] | 2097 | video_media_info.send_codecs.insert( |
| 2098 | std::make_pair(codec_parameters.payload_type, codec_parameters)); |
| 2099 | |
hbos | 6ded190 | 2016-11-01 01:50:46 -0700 | [diff] [blame] | 2100 | EXPECT_CALL(*video_media_channel, GetStats(_)) |
| 2101 | .WillOnce(DoAll(SetArgPointee<0>(video_media_info), Return(true))); |
| 2102 | |
| 2103 | SessionStats session_stats; |
hbos | 6ded190 | 2016-11-01 01:50:46 -0700 | [diff] [blame] | 2104 | session_stats.transport_stats["TransportName"].transport_name = |
| 2105 | "TransportName"; |
| 2106 | |
| 2107 | // Make sure the associated |RTCTransportStats| is created. |
| 2108 | cricket::TransportChannelStats channel_stats; |
| 2109 | channel_stats.component = cricket::ICE_CANDIDATE_COMPONENT_RTP; |
hbos | 6ded190 | 2016-11-01 01:50:46 -0700 | [diff] [blame] | 2110 | session_stats.transport_stats["TransportName"].channel_stats.push_back( |
| 2111 | channel_stats); |
| 2112 | |
Steve Anton | 75737c0 | 2017-11-06 10:37:17 -0800 | [diff] [blame] | 2113 | EXPECT_CALL(test_->pc(), GetSessionStats(_)) |
Steve Anton | ba81867 | 2017-11-06 10:21:57 -0800 | [diff] [blame] | 2114 | .WillRepeatedly(Invoke([&session_stats](const ChannelNamePairs&) { |
hbos | df6075a | 2016-12-19 04:58:02 -0800 | [diff] [blame] | 2115 | return std::unique_ptr<SessionStats>(new SessionStats(session_stats)); |
| 2116 | })); |
Steve Anton | 75737c0 | 2017-11-06 10:37:17 -0800 | [diff] [blame] | 2117 | EXPECT_CALL(test_->pc(), video_channel()) |
hbos | 6ded190 | 2016-11-01 01:50:46 -0700 | [diff] [blame] | 2118 | .WillRepeatedly(Return(&video_channel)); |
| 2119 | |
| 2120 | rtc::scoped_refptr<const RTCStatsReport> report = GetStatsReport(); |
| 2121 | |
| 2122 | RTCOutboundRTPStreamStats expected_video( |
| 2123 | "RTCOutboundRTPVideoStream_1", report->timestamp_us()); |
hbos | 3443bb7 | 2017-02-07 06:28:11 -0800 | [diff] [blame] | 2124 | expected_video.ssrc = 1; |
hbos | 6ded190 | 2016-11-01 01:50:46 -0700 | [diff] [blame] | 2125 | expected_video.is_remote = false; |
| 2126 | expected_video.media_type = "video"; |
hbos | b0ae920 | 2017-01-27 06:35:16 -0800 | [diff] [blame] | 2127 | expected_video.track_id = |
hbos | 9e30274 | 2017-01-20 02:47:10 -0800 | [diff] [blame] | 2128 | "RTCMediaStreamTrack_local_video_LocalVideoTrackID_1"; |
hbos | 6ded190 | 2016-11-01 01:50:46 -0700 | [diff] [blame] | 2129 | expected_video.transport_id = "RTCTransport_TransportName_" + |
| 2130 | rtc::ToString<>(cricket::ICE_CANDIDATE_COMPONENT_RTP); |
hbos | 0adb828 | 2016-11-23 02:32:06 -0800 | [diff] [blame] | 2131 | expected_video.codec_id = "RTCCodec_OutboundVideo_42"; |
hbos | 6ded190 | 2016-11-01 01:50:46 -0700 | [diff] [blame] | 2132 | expected_video.fir_count = 2; |
| 2133 | expected_video.pli_count = 3; |
| 2134 | expected_video.nack_count = 4; |
| 2135 | expected_video.packets_sent = 5; |
| 2136 | expected_video.bytes_sent = 6; |
skvlad | ed02c6d | 2017-02-07 10:45:31 -0800 | [diff] [blame] | 2137 | expected_video.frames_encoded = 8; |
hbos | a7a9be1 | 2017-03-01 01:02:45 -0800 | [diff] [blame] | 2138 | // |expected_video.qp_sum| should be undefined. |
hbos | cd195be | 2017-02-07 08:31:27 -0800 | [diff] [blame] | 2139 | |
| 2140 | ASSERT_TRUE(report->Get(expected_video.id())); |
hbos | a51d4f3 | 2017-02-16 05:34:48 -0800 | [diff] [blame] | 2141 | EXPECT_EQ( |
| 2142 | report->Get(expected_video.id())->cast_to<RTCOutboundRTPStreamStats>(), |
| 2143 | expected_video); |
skvlad | ed02c6d | 2017-02-07 10:45:31 -0800 | [diff] [blame] | 2144 | |
hbos | a51d4f3 | 2017-02-16 05:34:48 -0800 | [diff] [blame] | 2145 | // Set previously undefined values and "GetStats" again. |
Oskar Sundbom | cbc71b2 | 2017-11-16 10:56:07 +0100 | [diff] [blame] | 2146 | video_media_info.senders[0].qp_sum = 9; |
hbos | a51d4f3 | 2017-02-16 05:34:48 -0800 | [diff] [blame] | 2147 | expected_video.qp_sum = 9; |
| 2148 | |
| 2149 | EXPECT_CALL(*video_media_channel, GetStats(_)) |
| 2150 | .WillOnce(DoAll(SetArgPointee<0>(video_media_info), Return(true))); |
| 2151 | collector_->ClearCachedStatsReport(); |
| 2152 | report = GetStatsReport(); |
| 2153 | |
| 2154 | ASSERT_TRUE(report->Get(expected_video.id())); |
| 2155 | EXPECT_EQ( |
| 2156 | report->Get(expected_video.id())->cast_to<RTCOutboundRTPStreamStats>(), |
| 2157 | expected_video); |
hbos | b0ae920 | 2017-01-27 06:35:16 -0800 | [diff] [blame] | 2158 | EXPECT_TRUE(report->Get(*expected_video.track_id)); |
hbos | 84abeb1 | 2017-01-16 06:16:44 -0800 | [diff] [blame] | 2159 | EXPECT_TRUE(report->Get(*expected_video.transport_id)); |
| 2160 | EXPECT_TRUE(report->Get(*expected_video.codec_id)); |
hbos | 6ded190 | 2016-11-01 01:50:46 -0700 | [diff] [blame] | 2161 | } |
| 2162 | |
hbos | 2fa7c67 | 2016-10-24 04:00:05 -0700 | [diff] [blame] | 2163 | TEST_F(RTCStatsCollectorTest, CollectRTCTransportStats) { |
Gary Liu | 37e489c | 2017-11-21 10:49:36 -0800 | [diff] [blame] | 2164 | std::unique_ptr<cricket::Candidate> rtp_local_candidate = |
| 2165 | CreateFakeCandidate("42.42.42.42", 42, "protocol", rtc::ADAPTER_TYPE_WIFI, |
| 2166 | cricket::LOCAL_PORT_TYPE, 42); |
hbos | 2fa7c67 | 2016-10-24 04:00:05 -0700 | [diff] [blame] | 2167 | std::unique_ptr<cricket::Candidate> rtp_remote_candidate = |
| 2168 | CreateFakeCandidate("42.42.42.42", 42, "protocol", |
Gary Liu | 37e489c | 2017-11-21 10:49:36 -0800 | [diff] [blame] | 2169 | rtc::ADAPTER_TYPE_UNKNOWN, cricket::LOCAL_PORT_TYPE, |
| 2170 | 42); |
hbos | 2fa7c67 | 2016-10-24 04:00:05 -0700 | [diff] [blame] | 2171 | std::unique_ptr<cricket::Candidate> rtcp_local_candidate = |
Gary Liu | 37e489c | 2017-11-21 10:49:36 -0800 | [diff] [blame] | 2172 | CreateFakeCandidate("42.42.42.42", 42, "protocol", rtc::ADAPTER_TYPE_WIFI, |
hbos | 2fa7c67 | 2016-10-24 04:00:05 -0700 | [diff] [blame] | 2173 | cricket::LOCAL_PORT_TYPE, 42); |
| 2174 | std::unique_ptr<cricket::Candidate> rtcp_remote_candidate = |
| 2175 | CreateFakeCandidate("42.42.42.42", 42, "protocol", |
Gary Liu | 37e489c | 2017-11-21 10:49:36 -0800 | [diff] [blame] | 2176 | rtc::ADAPTER_TYPE_UNKNOWN, cricket::LOCAL_PORT_TYPE, |
| 2177 | 42); |
hbos | 2fa7c67 | 2016-10-24 04:00:05 -0700 | [diff] [blame] | 2178 | |
| 2179 | SessionStats session_stats; |
| 2180 | session_stats.transport_stats["transport"].transport_name = "transport"; |
| 2181 | |
| 2182 | cricket::ConnectionInfo rtp_connection_info; |
| 2183 | rtp_connection_info.best_connection = false; |
| 2184 | rtp_connection_info.local_candidate = *rtp_local_candidate.get(); |
| 2185 | rtp_connection_info.remote_candidate = *rtp_remote_candidate.get(); |
| 2186 | rtp_connection_info.sent_total_bytes = 42; |
| 2187 | rtp_connection_info.recv_total_bytes = 1337; |
| 2188 | cricket::TransportChannelStats rtp_transport_channel_stats; |
| 2189 | rtp_transport_channel_stats.component = cricket::ICE_CANDIDATE_COMPONENT_RTP; |
| 2190 | rtp_transport_channel_stats.connection_infos.push_back(rtp_connection_info); |
hbos | 7064d59 | 2017-01-16 07:38:02 -0800 | [diff] [blame] | 2191 | rtp_transport_channel_stats.dtls_state = cricket::DTLS_TRANSPORT_NEW; |
hbos | 2fa7c67 | 2016-10-24 04:00:05 -0700 | [diff] [blame] | 2192 | session_stats.transport_stats["transport"].channel_stats.push_back( |
| 2193 | rtp_transport_channel_stats); |
| 2194 | |
| 2195 | |
| 2196 | // Mock the session to return the desired candidates. |
Steve Anton | 75737c0 | 2017-11-06 10:37:17 -0800 | [diff] [blame] | 2197 | EXPECT_CALL(test_->pc(), GetSessionStats(_)) |
Steve Anton | ba81867 | 2017-11-06 10:21:57 -0800 | [diff] [blame] | 2198 | .WillRepeatedly(Invoke([&session_stats](const ChannelNamePairs&) { |
hbos | df6075a | 2016-12-19 04:58:02 -0800 | [diff] [blame] | 2199 | return std::unique_ptr<SessionStats>(new SessionStats(session_stats)); |
hbos | 2fa7c67 | 2016-10-24 04:00:05 -0700 | [diff] [blame] | 2200 | })); |
| 2201 | |
| 2202 | // Get stats without RTCP, an active connection or certificates. |
| 2203 | rtc::scoped_refptr<const RTCStatsReport> report = GetStatsReport(); |
hbos | 0583b28 | 2016-11-30 01:50:14 -0800 | [diff] [blame] | 2204 | |
| 2205 | RTCTransportStats expected_rtp_transport( |
| 2206 | "RTCTransport_transport_" + |
| 2207 | rtc::ToString<>(cricket::ICE_CANDIDATE_COMPONENT_RTP), |
| 2208 | report->timestamp_us()); |
| 2209 | expected_rtp_transport.bytes_sent = 42; |
| 2210 | expected_rtp_transport.bytes_received = 1337; |
hbos | 7064d59 | 2017-01-16 07:38:02 -0800 | [diff] [blame] | 2211 | expected_rtp_transport.dtls_state = RTCDtlsTransportState::kNew; |
hbos | 0583b28 | 2016-11-30 01:50:14 -0800 | [diff] [blame] | 2212 | |
hbos | dbb64d8 | 2016-12-21 01:57:46 -0800 | [diff] [blame] | 2213 | ASSERT_TRUE(report->Get(expected_rtp_transport.id())); |
hbos | 0583b28 | 2016-11-30 01:50:14 -0800 | [diff] [blame] | 2214 | EXPECT_EQ( |
| 2215 | expected_rtp_transport, |
| 2216 | report->Get(expected_rtp_transport.id())->cast_to<RTCTransportStats>()); |
hbos | 2fa7c67 | 2016-10-24 04:00:05 -0700 | [diff] [blame] | 2217 | |
| 2218 | cricket::ConnectionInfo rtcp_connection_info; |
| 2219 | rtcp_connection_info.best_connection = false; |
| 2220 | rtcp_connection_info.local_candidate = *rtcp_local_candidate.get(); |
| 2221 | rtcp_connection_info.remote_candidate = *rtcp_remote_candidate.get(); |
| 2222 | rtcp_connection_info.sent_total_bytes = 1337; |
| 2223 | rtcp_connection_info.recv_total_bytes = 42; |
| 2224 | cricket::TransportChannelStats rtcp_transport_channel_stats; |
| 2225 | rtcp_transport_channel_stats.component = |
| 2226 | cricket::ICE_CANDIDATE_COMPONENT_RTCP; |
| 2227 | rtcp_transport_channel_stats.connection_infos.push_back(rtcp_connection_info); |
hbos | 7064d59 | 2017-01-16 07:38:02 -0800 | [diff] [blame] | 2228 | rtcp_transport_channel_stats.dtls_state = cricket::DTLS_TRANSPORT_CONNECTING; |
hbos | 2fa7c67 | 2016-10-24 04:00:05 -0700 | [diff] [blame] | 2229 | session_stats.transport_stats["transport"].channel_stats.push_back( |
| 2230 | rtcp_transport_channel_stats); |
| 2231 | |
| 2232 | collector_->ClearCachedStatsReport(); |
| 2233 | // Get stats with RTCP and without an active connection or certificates. |
| 2234 | report = GetStatsReport(); |
hbos | 0583b28 | 2016-11-30 01:50:14 -0800 | [diff] [blame] | 2235 | |
| 2236 | RTCTransportStats expected_rtcp_transport( |
| 2237 | "RTCTransport_transport_" + |
| 2238 | rtc::ToString<>(cricket::ICE_CANDIDATE_COMPONENT_RTCP), |
| 2239 | report->timestamp_us()); |
| 2240 | expected_rtcp_transport.bytes_sent = 1337; |
| 2241 | expected_rtcp_transport.bytes_received = 42; |
hbos | 7064d59 | 2017-01-16 07:38:02 -0800 | [diff] [blame] | 2242 | expected_rtcp_transport.dtls_state = RTCDtlsTransportState::kConnecting; |
hbos | 0583b28 | 2016-11-30 01:50:14 -0800 | [diff] [blame] | 2243 | |
| 2244 | expected_rtp_transport.rtcp_transport_stats_id = expected_rtcp_transport.id(); |
| 2245 | |
hbos | dbb64d8 | 2016-12-21 01:57:46 -0800 | [diff] [blame] | 2246 | ASSERT_TRUE(report->Get(expected_rtp_transport.id())); |
hbos | 0583b28 | 2016-11-30 01:50:14 -0800 | [diff] [blame] | 2247 | EXPECT_EQ( |
| 2248 | expected_rtp_transport, |
| 2249 | report->Get(expected_rtp_transport.id())->cast_to<RTCTransportStats>()); |
hbos | dbb64d8 | 2016-12-21 01:57:46 -0800 | [diff] [blame] | 2250 | ASSERT_TRUE(report->Get(expected_rtcp_transport.id())); |
hbos | 0583b28 | 2016-11-30 01:50:14 -0800 | [diff] [blame] | 2251 | EXPECT_EQ( |
| 2252 | expected_rtcp_transport, |
| 2253 | report->Get(expected_rtcp_transport.id())->cast_to<RTCTransportStats>()); |
hbos | 2fa7c67 | 2016-10-24 04:00:05 -0700 | [diff] [blame] | 2254 | |
hbos | 7064d59 | 2017-01-16 07:38:02 -0800 | [diff] [blame] | 2255 | // Get stats with an active connection (selected candidate pair). |
hbos | 0583b28 | 2016-11-30 01:50:14 -0800 | [diff] [blame] | 2256 | session_stats.transport_stats["transport"] |
| 2257 | .channel_stats[1] |
| 2258 | .connection_infos[0] |
| 2259 | .best_connection = true; |
hbos | 2fa7c67 | 2016-10-24 04:00:05 -0700 | [diff] [blame] | 2260 | |
| 2261 | collector_->ClearCachedStatsReport(); |
| 2262 | report = GetStatsReport(); |
hbos | 0583b28 | 2016-11-30 01:50:14 -0800 | [diff] [blame] | 2263 | |
hbos | 0583b28 | 2016-11-30 01:50:14 -0800 | [diff] [blame] | 2264 | expected_rtcp_transport.selected_candidate_pair_id = |
| 2265 | "RTCIceCandidatePair_" + rtcp_local_candidate->id() + "_" + |
| 2266 | rtcp_remote_candidate->id(); |
| 2267 | |
hbos | dbb64d8 | 2016-12-21 01:57:46 -0800 | [diff] [blame] | 2268 | ASSERT_TRUE(report->Get(expected_rtp_transport.id())); |
hbos | 0583b28 | 2016-11-30 01:50:14 -0800 | [diff] [blame] | 2269 | EXPECT_EQ( |
| 2270 | expected_rtp_transport, |
| 2271 | report->Get(expected_rtp_transport.id())->cast_to<RTCTransportStats>()); |
hbos | dbb64d8 | 2016-12-21 01:57:46 -0800 | [diff] [blame] | 2272 | ASSERT_TRUE(report->Get(expected_rtcp_transport.id())); |
hbos | 0583b28 | 2016-11-30 01:50:14 -0800 | [diff] [blame] | 2273 | EXPECT_EQ( |
| 2274 | expected_rtcp_transport, |
| 2275 | report->Get(expected_rtcp_transport.id())->cast_to<RTCTransportStats>()); |
hbos | 2fa7c67 | 2016-10-24 04:00:05 -0700 | [diff] [blame] | 2276 | |
| 2277 | // Get stats with certificates. |
| 2278 | std::unique_ptr<CertificateInfo> local_certinfo = |
| 2279 | CreateFakeCertificateAndInfoFromDers( |
| 2280 | std::vector<std::string>({ "(local) local", "(local) chain" })); |
| 2281 | std::unique_ptr<CertificateInfo> remote_certinfo = |
| 2282 | CreateFakeCertificateAndInfoFromDers( |
| 2283 | std::vector<std::string>({ "(remote) local", "(remote) chain" })); |
Steve Anton | 75737c0 | 2017-11-06 10:37:17 -0800 | [diff] [blame] | 2284 | EXPECT_CALL(test_->pc(), GetLocalCertificate(_, _)) |
| 2285 | .WillRepeatedly( |
| 2286 | Invoke([&local_certinfo]( |
| 2287 | const std::string& transport_name, |
| 2288 | rtc::scoped_refptr<rtc::RTCCertificate>* certificate) { |
| 2289 | if (transport_name == "transport") { |
| 2290 | *certificate = local_certinfo->certificate; |
| 2291 | return true; |
| 2292 | } |
| 2293 | return false; |
| 2294 | })); |
| 2295 | EXPECT_CALL(test_->pc(), GetRemoteSSLCertificate_ReturnsRawPointer(_)) |
| 2296 | .WillRepeatedly(Invoke([&remote_certinfo]( |
| 2297 | const std::string& transport_name) { |
hbos | 2fa7c67 | 2016-10-24 04:00:05 -0700 | [diff] [blame] | 2298 | if (transport_name == "transport") |
| 2299 | return remote_certinfo->certificate->ssl_certificate().GetReference(); |
| 2300 | return static_cast<rtc::SSLCertificate*>(nullptr); |
| 2301 | })); |
| 2302 | |
| 2303 | collector_->ClearCachedStatsReport(); |
| 2304 | report = GetStatsReport(); |
hbos | 0583b28 | 2016-11-30 01:50:14 -0800 | [diff] [blame] | 2305 | |
| 2306 | expected_rtp_transport.local_certificate_id = |
| 2307 | "RTCCertificate_" + local_certinfo->fingerprints[0]; |
| 2308 | expected_rtp_transport.remote_certificate_id = |
| 2309 | "RTCCertificate_" + remote_certinfo->fingerprints[0]; |
| 2310 | |
| 2311 | expected_rtcp_transport.local_certificate_id = |
| 2312 | *expected_rtp_transport.local_certificate_id; |
| 2313 | expected_rtcp_transport.remote_certificate_id = |
| 2314 | *expected_rtp_transport.remote_certificate_id; |
| 2315 | |
hbos | dbb64d8 | 2016-12-21 01:57:46 -0800 | [diff] [blame] | 2316 | ASSERT_TRUE(report->Get(expected_rtp_transport.id())); |
hbos | 0583b28 | 2016-11-30 01:50:14 -0800 | [diff] [blame] | 2317 | EXPECT_EQ( |
| 2318 | expected_rtp_transport, |
| 2319 | report->Get(expected_rtp_transport.id())->cast_to<RTCTransportStats>()); |
hbos | dbb64d8 | 2016-12-21 01:57:46 -0800 | [diff] [blame] | 2320 | ASSERT_TRUE(report->Get(expected_rtcp_transport.id())); |
hbos | 0583b28 | 2016-11-30 01:50:14 -0800 | [diff] [blame] | 2321 | EXPECT_EQ( |
| 2322 | expected_rtcp_transport, |
| 2323 | report->Get(expected_rtcp_transport.id())->cast_to<RTCTransportStats>()); |
hbos | 2fa7c67 | 2016-10-24 04:00:05 -0700 | [diff] [blame] | 2324 | } |
| 2325 | |
Harald Alvestrand | 8906187 | 2018-01-02 14:08:34 +0100 | [diff] [blame] | 2326 | TEST_F(RTCStatsCollectorTest, CollectNoStreamRTCOutboundRTPStreamStats_Audio) { |
| 2327 | // Emulates the case where AddTrack is used without an associated MediaStream |
| 2328 | auto* voice_media_channel = new MockVoiceMediaChannel(); |
| 2329 | cricket::VoiceChannel voice_channel( |
| 2330 | test_->worker_thread(), test_->network_thread(), |
| 2331 | test_->signaling_thread(), test_->media_engine(), |
| 2332 | rtc::WrapUnique(voice_media_channel), "VoiceContentName", |
| 2333 | kDefaultRtcpMuxRequired, kDefaultSrtpRequired); |
| 2334 | voice_channel.set_transport_name_for_testing("TransportName"); |
| 2335 | |
| 2336 | test_->SetupLocalTrackAndSender(cricket::MEDIA_TYPE_AUDIO, |
| 2337 | "LocalAudioTrackID", 1, false); |
| 2338 | |
| 2339 | cricket::VoiceMediaInfo voice_media_info; |
| 2340 | |
| 2341 | voice_media_info.senders.push_back(cricket::VoiceSenderInfo()); |
| 2342 | voice_media_info.senders[0].local_stats.push_back(cricket::SsrcSenderInfo()); |
| 2343 | voice_media_info.senders[0].local_stats[0].ssrc = 1; |
| 2344 | voice_media_info.senders[0].packets_sent = 2; |
| 2345 | voice_media_info.senders[0].bytes_sent = 3; |
| 2346 | voice_media_info.senders[0].codec_payload_type = 42; |
| 2347 | |
| 2348 | RtpCodecParameters codec_parameters; |
| 2349 | codec_parameters.payload_type = 42; |
| 2350 | codec_parameters.kind = cricket::MEDIA_TYPE_AUDIO; |
| 2351 | codec_parameters.name = "dummy"; |
| 2352 | codec_parameters.clock_rate = 0; |
| 2353 | voice_media_info.send_codecs.insert( |
| 2354 | std::make_pair(codec_parameters.payload_type, codec_parameters)); |
| 2355 | |
| 2356 | EXPECT_CALL(*voice_media_channel, GetStats(_)) |
| 2357 | .WillOnce(DoAll(SetArgPointee<0>(voice_media_info), Return(true))); |
| 2358 | |
| 2359 | SessionStats session_stats; |
| 2360 | session_stats.transport_stats["TransportName"].transport_name = |
| 2361 | "TransportName"; |
| 2362 | |
| 2363 | // Make sure the associated |RTCTransportStats| is created. |
| 2364 | cricket::TransportChannelStats channel_stats; |
| 2365 | channel_stats.component = cricket::ICE_CANDIDATE_COMPONENT_RTP; |
| 2366 | session_stats.transport_stats["TransportName"].channel_stats.push_back( |
| 2367 | channel_stats); |
| 2368 | |
| 2369 | EXPECT_CALL(test_->pc(), GetSessionStats(_)) |
| 2370 | .WillRepeatedly(Invoke([&session_stats](const ChannelNamePairs&) { |
| 2371 | return std::unique_ptr<SessionStats>(new SessionStats(session_stats)); |
| 2372 | })); |
| 2373 | EXPECT_CALL(test_->pc(), voice_channel()) |
| 2374 | .WillRepeatedly(Return(&voice_channel)); |
| 2375 | |
| 2376 | rtc::scoped_refptr<const RTCStatsReport> report = GetStatsReport(); |
| 2377 | |
| 2378 | RTCOutboundRTPStreamStats expected_audio("RTCOutboundRTPAudioStream_1", |
| 2379 | report->timestamp_us()); |
| 2380 | expected_audio.ssrc = 1; |
| 2381 | expected_audio.is_remote = false; |
| 2382 | expected_audio.media_type = "audio"; |
| 2383 | expected_audio.track_id = |
| 2384 | "RTCMediaStreamTrack_local_audio_LocalAudioTrackID_1"; |
| 2385 | expected_audio.transport_id = |
| 2386 | "RTCTransport_TransportName_" + |
| 2387 | rtc::ToString<>(cricket::ICE_CANDIDATE_COMPONENT_RTP); |
| 2388 | expected_audio.codec_id = "RTCCodec_OutboundAudio_42"; |
| 2389 | expected_audio.packets_sent = 2; |
| 2390 | expected_audio.bytes_sent = 3; |
| 2391 | |
| 2392 | ASSERT_TRUE(report->Get(expected_audio.id())); |
| 2393 | EXPECT_EQ( |
| 2394 | report->Get(expected_audio.id())->cast_to<RTCOutboundRTPStreamStats>(), |
| 2395 | expected_audio); |
| 2396 | |
| 2397 | ASSERT_TRUE(report->Get(expected_audio.id())); |
| 2398 | EXPECT_EQ( |
| 2399 | report->Get(expected_audio.id())->cast_to<RTCOutboundRTPStreamStats>(), |
| 2400 | expected_audio); |
| 2401 | EXPECT_TRUE(report->Get(*expected_audio.track_id)); |
| 2402 | EXPECT_TRUE(report->Get(*expected_audio.transport_id)); |
| 2403 | EXPECT_TRUE(report->Get(*expected_audio.codec_id)); |
| 2404 | } |
| 2405 | |
| 2406 | // When the PC has not had SetLocalDescription done, tracks all have |
| 2407 | // SSRC 0, meaning "unconnected". |
| 2408 | // We do not report stats on those tracks. https://bugs.webrtc.org/8673 |
| 2409 | TEST_F(RTCStatsCollectorTest, StatsNotReportedOnZeroSsrc) { |
| 2410 | rtc::scoped_refptr<MediaStreamTrackInterface> track = |
| 2411 | CreateFakeTrack(cricket::MEDIA_TYPE_AUDIO, "audioTrack", |
| 2412 | MediaStreamTrackInterface::kLive); |
| 2413 | rtc::scoped_refptr<MockRtpSender> sender = CreateMockSender(track, 0); |
| 2414 | EXPECT_CALL(test_->pc(), GetSenders()) |
| 2415 | .WillRepeatedly( |
| 2416 | Return(std::vector<rtc::scoped_refptr<RtpSenderInterface>>( |
| 2417 | {rtc::scoped_refptr<RtpSenderInterface>(sender.get())}))); |
| 2418 | rtc::scoped_refptr<const RTCStatsReport> report = GetStatsReport(); |
| 2419 | std::vector<const RTCMediaStreamTrackStats*> track_stats = |
| 2420 | report->GetStatsOfType<RTCMediaStreamTrackStats>(); |
| 2421 | EXPECT_EQ(0, track_stats.size()); |
| 2422 | } |
| 2423 | |
hbos | c82f2e1 | 2016-09-05 01:36:50 -0700 | [diff] [blame] | 2424 | class RTCStatsCollectorTestWithFakeCollector : public testing::Test { |
| 2425 | public: |
| 2426 | RTCStatsCollectorTestWithFakeCollector() |
| 2427 | : test_(new rtc::RefCountedObject<RTCStatsCollectorTestHelper>()), |
| 2428 | collector_(FakeRTCStatsCollector::Create( |
| 2429 | &test_->pc(), 50 * rtc::kNumMicrosecsPerMillisec)) { |
| 2430 | } |
| 2431 | |
| 2432 | protected: |
| 2433 | rtc::scoped_refptr<RTCStatsCollectorTestHelper> test_; |
| 2434 | rtc::scoped_refptr<FakeRTCStatsCollector> collector_; |
| 2435 | }; |
| 2436 | |
| 2437 | TEST_F(RTCStatsCollectorTestWithFakeCollector, ThreadUsageAndResultsMerging) { |
| 2438 | collector_->VerifyThreadUsageAndResultsMerging(); |
| 2439 | } |
| 2440 | |
| 2441 | } // namespace |
| 2442 | |
hbos | d565b73 | 2016-08-30 14:04:35 -0700 | [diff] [blame] | 2443 | } // namespace webrtc |