OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2016 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2016 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 1197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1208 RTCLocalIceCandidateStats>()); | 1208 RTCLocalIceCandidateStats>()); |
1209 ASSERT_TRUE(report->Get(expected_b_remote.id())); | 1209 ASSERT_TRUE(report->Get(expected_b_remote.id())); |
1210 EXPECT_EQ(expected_b_remote, | 1210 EXPECT_EQ(expected_b_remote, |
1211 report->Get(expected_b_remote.id())->cast_to< | 1211 report->Get(expected_b_remote.id())->cast_to< |
1212 RTCRemoteIceCandidateStats>()); | 1212 RTCRemoteIceCandidateStats>()); |
1213 EXPECT_TRUE(report->Get("RTCTransport_a_0")); | 1213 EXPECT_TRUE(report->Get("RTCTransport_a_0")); |
1214 EXPECT_TRUE(report->Get("RTCTransport_b_0")); | 1214 EXPECT_TRUE(report->Get("RTCTransport_b_0")); |
1215 } | 1215 } |
1216 | 1216 |
1217 TEST_F(RTCStatsCollectorTest, CollectRTCIceCandidatePairStats) { | 1217 TEST_F(RTCStatsCollectorTest, CollectRTCIceCandidatePairStats) { |
| 1218 MockVideoMediaChannel* video_media_channel = new MockVideoMediaChannel(); |
| 1219 cricket::VideoChannel video_channel( |
| 1220 test_->worker_thread(), test_->network_thread(), |
| 1221 test_->signaling_thread(), video_media_channel, "VideoContentName", |
| 1222 kDefaultRtcpMuxRequired, kDefaultSrtpRequired); |
| 1223 |
1218 std::unique_ptr<cricket::Candidate> local_candidate = CreateFakeCandidate( | 1224 std::unique_ptr<cricket::Candidate> local_candidate = CreateFakeCandidate( |
1219 "42.42.42.42", 42, "protocol", cricket::LOCAL_PORT_TYPE, 42); | 1225 "42.42.42.42", 42, "protocol", cricket::LOCAL_PORT_TYPE, 42); |
1220 std::unique_ptr<cricket::Candidate> remote_candidate = CreateFakeCandidate( | 1226 std::unique_ptr<cricket::Candidate> remote_candidate = CreateFakeCandidate( |
1221 "42.42.42.42", 42, "protocol", cricket::LOCAL_PORT_TYPE, 42); | 1227 "42.42.42.42", 42, "protocol", cricket::LOCAL_PORT_TYPE, 42); |
1222 | 1228 |
1223 SessionStats session_stats; | 1229 SessionStats session_stats; |
1224 | 1230 |
1225 cricket::ConnectionInfo connection_info; | 1231 cricket::ConnectionInfo connection_info; |
| 1232 connection_info.best_connection = false; |
1226 connection_info.local_candidate = *local_candidate.get(); | 1233 connection_info.local_candidate = *local_candidate.get(); |
1227 connection_info.remote_candidate = *remote_candidate.get(); | 1234 connection_info.remote_candidate = *remote_candidate.get(); |
1228 connection_info.writable = true; | 1235 connection_info.writable = true; |
1229 connection_info.sent_total_bytes = 42; | 1236 connection_info.sent_total_bytes = 42; |
1230 connection_info.recv_total_bytes = 1234; | 1237 connection_info.recv_total_bytes = 1234; |
1231 connection_info.rtt = 1337; | 1238 connection_info.rtt = 1337; |
1232 connection_info.recv_ping_requests = 2020; | 1239 connection_info.recv_ping_requests = 2020; |
1233 connection_info.sent_ping_requests_total = 2020; | 1240 connection_info.sent_ping_requests_total = 2020; |
1234 connection_info.sent_ping_requests_before_first_response = 2000; | 1241 connection_info.sent_ping_requests_before_first_response = 2000; |
1235 connection_info.recv_ping_responses = 4321; | 1242 connection_info.recv_ping_responses = 4321; |
1236 connection_info.sent_ping_responses = 1000; | 1243 connection_info.sent_ping_responses = 1000; |
1237 connection_info.state = cricket::IceCandidatePairState::IN_PROGRESS; | 1244 connection_info.state = cricket::IceCandidatePairState::IN_PROGRESS; |
1238 connection_info.priority = 5555; | 1245 connection_info.priority = 5555; |
1239 | 1246 |
1240 cricket::TransportChannelStats transport_channel_stats; | 1247 cricket::TransportChannelStats transport_channel_stats; |
1241 transport_channel_stats.component = cricket::ICE_CANDIDATE_COMPONENT_RTP; | 1248 transport_channel_stats.component = cricket::ICE_CANDIDATE_COMPONENT_RTP; |
1242 transport_channel_stats.connection_infos.push_back(connection_info); | 1249 transport_channel_stats.connection_infos.push_back(connection_info); |
| 1250 session_stats.proxy_to_transport["VideoContentName"] = "transport"; |
1243 session_stats.transport_stats["transport"].transport_name = "transport"; | 1251 session_stats.transport_stats["transport"].transport_name = "transport"; |
1244 session_stats.transport_stats["transport"].channel_stats.push_back( | 1252 session_stats.transport_stats["transport"].channel_stats.push_back( |
1245 transport_channel_stats); | 1253 transport_channel_stats); |
1246 | 1254 |
1247 // Mock the session to return the desired candidates. | 1255 // Mock the session to return the desired candidates. |
1248 EXPECT_CALL(test_->session(), GetStats(_)).WillRepeatedly(Invoke( | 1256 EXPECT_CALL(test_->session(), GetStats(_)).WillRepeatedly(Invoke( |
1249 [&session_stats](const ChannelNamePairs&) { | 1257 [&session_stats](const ChannelNamePairs&) { |
1250 return std::unique_ptr<SessionStats>(new SessionStats(session_stats)); | 1258 return std::unique_ptr<SessionStats>(new SessionStats(session_stats)); |
1251 })); | 1259 })); |
1252 | 1260 |
| 1261 // Mock the session to return bandwidth estimation info. These should only |
| 1262 // be used for a selected candidate pair. |
| 1263 cricket::VideoMediaInfo video_media_info; |
| 1264 video_media_info.bw_estimations.push_back(cricket::BandwidthEstimationInfo()); |
| 1265 video_media_info.bw_estimations[0].available_send_bandwidth = 8888; |
| 1266 video_media_info.bw_estimations[0].available_recv_bandwidth = 9999; |
| 1267 EXPECT_CALL(*video_media_channel, GetStats(_)) |
| 1268 .WillOnce(DoAll(SetArgPointee<0>(video_media_info), Return(true))); |
| 1269 EXPECT_CALL(test_->session(), video_channel()) |
| 1270 .WillRepeatedly(Return(&video_channel)); |
| 1271 |
1253 rtc::scoped_refptr<const RTCStatsReport> report = GetStatsReport(); | 1272 rtc::scoped_refptr<const RTCStatsReport> report = GetStatsReport(); |
1254 | 1273 |
1255 RTCIceCandidatePairStats expected_pair("RTCIceCandidatePair_" + | 1274 RTCIceCandidatePairStats expected_pair("RTCIceCandidatePair_" + |
1256 local_candidate->id() + "_" + | 1275 local_candidate->id() + "_" + |
1257 remote_candidate->id(), | 1276 remote_candidate->id(), |
1258 report->timestamp_us()); | 1277 report->timestamp_us()); |
1259 expected_pair.transport_id = | 1278 expected_pair.transport_id = |
1260 "RTCTransport_transport_" + | 1279 "RTCTransport_transport_" + |
1261 rtc::ToString<>(cricket::ICE_CANDIDATE_COMPONENT_RTP); | 1280 rtc::ToString<>(cricket::ICE_CANDIDATE_COMPONENT_RTP); |
1262 expected_pair.local_candidate_id = "RTCIceCandidate_" + local_candidate->id(); | 1281 expected_pair.local_candidate_id = "RTCIceCandidate_" + local_candidate->id(); |
1263 expected_pair.remote_candidate_id = | 1282 expected_pair.remote_candidate_id = |
1264 "RTCIceCandidate_" + remote_candidate->id(); | 1283 "RTCIceCandidate_" + remote_candidate->id(); |
1265 expected_pair.state = RTCStatsIceCandidatePairState::kInProgress; | 1284 expected_pair.state = RTCStatsIceCandidatePairState::kInProgress; |
1266 expected_pair.priority = 5555; | 1285 expected_pair.priority = 5555; |
1267 expected_pair.writable = true; | 1286 expected_pair.writable = true; |
1268 expected_pair.bytes_sent = 42; | 1287 expected_pair.bytes_sent = 42; |
1269 expected_pair.bytes_received = 1234; | 1288 expected_pair.bytes_received = 1234; |
1270 expected_pair.current_round_trip_time = 1.337; | 1289 expected_pair.current_round_trip_time = 1.337; |
1271 expected_pair.requests_received = 2020; | 1290 expected_pair.requests_received = 2020; |
1272 expected_pair.requests_sent = 2000; | 1291 expected_pair.requests_sent = 2000; |
1273 expected_pair.responses_received = 4321; | 1292 expected_pair.responses_received = 4321; |
1274 expected_pair.responses_sent = 1000; | 1293 expected_pair.responses_sent = 1000; |
1275 expected_pair.consent_requests_sent = (2020 - 2000); | 1294 expected_pair.consent_requests_sent = (2020 - 2000); |
| 1295 // |expected_pair.available_[outgoing/incoming]_bitrate| should be undefined |
| 1296 // because is is not the current pair. |
1276 | 1297 |
1277 ASSERT_TRUE(report->Get(expected_pair.id())); | 1298 ASSERT_TRUE(report->Get(expected_pair.id())); |
1278 EXPECT_EQ( | 1299 EXPECT_EQ( |
1279 expected_pair, | 1300 expected_pair, |
| 1301 report->Get(expected_pair.id())->cast_to<RTCIceCandidatePairStats>()); |
| 1302 EXPECT_TRUE(report->Get(*expected_pair.transport_id)); |
| 1303 |
| 1304 // Make pair the current pair, clear bandwidth and "GetStats" again. |
| 1305 session_stats.transport_stats["transport"] |
| 1306 .channel_stats[0] |
| 1307 .connection_infos[0] |
| 1308 .best_connection = true; |
| 1309 video_media_info.bw_estimations[0].available_send_bandwidth = 0; |
| 1310 video_media_info.bw_estimations[0].available_recv_bandwidth = 0; |
| 1311 EXPECT_CALL(*video_media_channel, GetStats(_)) |
| 1312 .WillOnce(DoAll(SetArgPointee<0>(video_media_info), Return(true))); |
| 1313 collector_->ClearCachedStatsReport(); |
| 1314 report = GetStatsReport(); |
| 1315 expected_pair.set_timestamp_us_for_testing(report->timestamp_us()); |
| 1316 // |expected_pair.available_[outgoing/incoming]_bitrate| should still be |
| 1317 // undefined because bandwidth is not set. |
| 1318 ASSERT_TRUE(report->Get(expected_pair.id())); |
| 1319 EXPECT_EQ( |
| 1320 expected_pair, |
| 1321 report->Get(expected_pair.id())->cast_to<RTCIceCandidatePairStats>()); |
| 1322 EXPECT_TRUE(report->Get(*expected_pair.transport_id)); |
| 1323 |
| 1324 // Set bandwidth and "GetStats" again. |
| 1325 video_media_info.bw_estimations[0].available_send_bandwidth = 888; |
| 1326 video_media_info.bw_estimations[0].available_recv_bandwidth = 999; |
| 1327 EXPECT_CALL(*video_media_channel, GetStats(_)) |
| 1328 .WillOnce(DoAll(SetArgPointee<0>(video_media_info), Return(true))); |
| 1329 collector_->ClearCachedStatsReport(); |
| 1330 report = GetStatsReport(); |
| 1331 expected_pair.set_timestamp_us_for_testing(report->timestamp_us()); |
| 1332 expected_pair.available_outgoing_bitrate = 888; |
| 1333 expected_pair.available_incoming_bitrate = 999; |
| 1334 ASSERT_TRUE(report->Get(expected_pair.id())); |
| 1335 EXPECT_EQ( |
| 1336 expected_pair, |
1280 report->Get(expected_pair.id())->cast_to<RTCIceCandidatePairStats>()); | 1337 report->Get(expected_pair.id())->cast_to<RTCIceCandidatePairStats>()); |
1281 EXPECT_TRUE(report->Get(*expected_pair.transport_id)); | 1338 EXPECT_TRUE(report->Get(*expected_pair.transport_id)); |
1282 | 1339 |
1283 RTCLocalIceCandidateStats expected_local_candidate( | 1340 RTCLocalIceCandidateStats expected_local_candidate( |
1284 *expected_pair.local_candidate_id, report->timestamp_us()); | 1341 *expected_pair.local_candidate_id, report->timestamp_us()); |
1285 expected_local_candidate.transport_id = *expected_pair.transport_id; | 1342 expected_local_candidate.transport_id = *expected_pair.transport_id; |
1286 expected_local_candidate.ip = "42.42.42.42"; | 1343 expected_local_candidate.ip = "42.42.42.42"; |
1287 expected_local_candidate.port = 42; | 1344 expected_local_candidate.port = 42; |
1288 expected_local_candidate.protocol = "protocol"; | 1345 expected_local_candidate.protocol = "protocol"; |
1289 expected_local_candidate.candidate_type = "host"; | 1346 expected_local_candidate.candidate_type = "host"; |
(...skipping 967 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2257 rtc::scoped_refptr<FakeRTCStatsCollector> collector_; | 2314 rtc::scoped_refptr<FakeRTCStatsCollector> collector_; |
2258 }; | 2315 }; |
2259 | 2316 |
2260 TEST_F(RTCStatsCollectorTestWithFakeCollector, ThreadUsageAndResultsMerging) { | 2317 TEST_F(RTCStatsCollectorTestWithFakeCollector, ThreadUsageAndResultsMerging) { |
2261 collector_->VerifyThreadUsageAndResultsMerging(); | 2318 collector_->VerifyThreadUsageAndResultsMerging(); |
2262 } | 2319 } |
2263 | 2320 |
2264 } // namespace | 2321 } // namespace |
2265 | 2322 |
2266 } // namespace webrtc | 2323 } // namespace webrtc |
OLD | NEW |