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 1201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1212 RTCLocalIceCandidateStats>()); | 1212 RTCLocalIceCandidateStats>()); |
1213 ASSERT_TRUE(report->Get(expected_b_remote.id())); | 1213 ASSERT_TRUE(report->Get(expected_b_remote.id())); |
1214 EXPECT_EQ(expected_b_remote, | 1214 EXPECT_EQ(expected_b_remote, |
1215 report->Get(expected_b_remote.id())->cast_to< | 1215 report->Get(expected_b_remote.id())->cast_to< |
1216 RTCRemoteIceCandidateStats>()); | 1216 RTCRemoteIceCandidateStats>()); |
1217 EXPECT_TRUE(report->Get("RTCTransport_a_0")); | 1217 EXPECT_TRUE(report->Get("RTCTransport_a_0")); |
1218 EXPECT_TRUE(report->Get("RTCTransport_b_0")); | 1218 EXPECT_TRUE(report->Get("RTCTransport_b_0")); |
1219 } | 1219 } |
1220 | 1220 |
1221 TEST_F(RTCStatsCollectorTest, CollectRTCIceCandidatePairStats) { | 1221 TEST_F(RTCStatsCollectorTest, CollectRTCIceCandidatePairStats) { |
| 1222 MockVideoMediaChannel* video_media_channel = new MockVideoMediaChannel(); |
| 1223 cricket::VideoChannel video_channel( |
| 1224 test_->worker_thread(), test_->network_thread(), |
| 1225 test_->signaling_thread(), video_media_channel, "VideoContentName", |
| 1226 kDefaultRtcpMuxRequired, kDefaultSrtpRequired); |
| 1227 |
1222 std::unique_ptr<cricket::Candidate> local_candidate = CreateFakeCandidate( | 1228 std::unique_ptr<cricket::Candidate> local_candidate = CreateFakeCandidate( |
1223 "42.42.42.42", 42, "protocol", cricket::LOCAL_PORT_TYPE, 42); | 1229 "42.42.42.42", 42, "protocol", cricket::LOCAL_PORT_TYPE, 42); |
1224 std::unique_ptr<cricket::Candidate> remote_candidate = CreateFakeCandidate( | 1230 std::unique_ptr<cricket::Candidate> remote_candidate = CreateFakeCandidate( |
1225 "42.42.42.42", 42, "protocol", cricket::LOCAL_PORT_TYPE, 42); | 1231 "42.42.42.42", 42, "protocol", cricket::LOCAL_PORT_TYPE, 42); |
1226 | 1232 |
1227 SessionStats session_stats; | 1233 SessionStats session_stats; |
1228 | 1234 |
1229 cricket::ConnectionInfo connection_info; | 1235 cricket::ConnectionInfo connection_info; |
| 1236 connection_info.best_connection = false; |
1230 connection_info.local_candidate = *local_candidate.get(); | 1237 connection_info.local_candidate = *local_candidate.get(); |
1231 connection_info.remote_candidate = *remote_candidate.get(); | 1238 connection_info.remote_candidate = *remote_candidate.get(); |
1232 connection_info.writable = true; | 1239 connection_info.writable = true; |
1233 connection_info.sent_total_bytes = 42; | 1240 connection_info.sent_total_bytes = 42; |
1234 connection_info.recv_total_bytes = 1234; | 1241 connection_info.recv_total_bytes = 1234; |
1235 connection_info.rtt = 1337; | 1242 connection_info.rtt = 1337; |
1236 connection_info.recv_ping_requests = 2020; | 1243 connection_info.recv_ping_requests = 2020; |
1237 connection_info.sent_ping_requests_total = 2020; | 1244 connection_info.sent_ping_requests_total = 2020; |
1238 connection_info.sent_ping_requests_before_first_response = 2000; | 1245 connection_info.sent_ping_requests_before_first_response = 2000; |
1239 connection_info.recv_ping_responses = 4321; | 1246 connection_info.recv_ping_responses = 4321; |
1240 connection_info.sent_ping_responses = 1000; | 1247 connection_info.sent_ping_responses = 1000; |
1241 connection_info.state = cricket::IceCandidatePairState::IN_PROGRESS; | 1248 connection_info.state = cricket::IceCandidatePairState::IN_PROGRESS; |
1242 connection_info.priority = 5555; | 1249 connection_info.priority = 5555; |
1243 | 1250 |
1244 cricket::TransportChannelStats transport_channel_stats; | 1251 cricket::TransportChannelStats transport_channel_stats; |
1245 transport_channel_stats.component = cricket::ICE_CANDIDATE_COMPONENT_RTP; | 1252 transport_channel_stats.component = cricket::ICE_CANDIDATE_COMPONENT_RTP; |
1246 transport_channel_stats.connection_infos.push_back(connection_info); | 1253 transport_channel_stats.connection_infos.push_back(connection_info); |
| 1254 session_stats.proxy_to_transport["VideoContentName"] = "transport"; |
1247 session_stats.transport_stats["transport"].transport_name = "transport"; | 1255 session_stats.transport_stats["transport"].transport_name = "transport"; |
1248 session_stats.transport_stats["transport"].channel_stats.push_back( | 1256 session_stats.transport_stats["transport"].channel_stats.push_back( |
1249 transport_channel_stats); | 1257 transport_channel_stats); |
1250 | 1258 |
1251 // Mock the session to return the desired candidates. | 1259 // Mock the session to return the desired candidates. |
1252 EXPECT_CALL(test_->session(), GetStats(_)).WillRepeatedly(Invoke( | 1260 EXPECT_CALL(test_->session(), GetStats(_)).WillRepeatedly(Invoke( |
1253 [&session_stats](const ChannelNamePairs&) { | 1261 [&session_stats](const ChannelNamePairs&) { |
1254 return std::unique_ptr<SessionStats>(new SessionStats(session_stats)); | 1262 return std::unique_ptr<SessionStats>(new SessionStats(session_stats)); |
1255 })); | 1263 })); |
1256 | 1264 |
| 1265 // Mock the session to return bandwidth estimation info. These should only |
| 1266 // be used for a selected candidate pair. |
| 1267 cricket::VideoMediaInfo video_media_info; |
| 1268 video_media_info.bw_estimations.push_back(cricket::BandwidthEstimationInfo()); |
| 1269 video_media_info.bw_estimations[0].available_send_bandwidth = 8888; |
| 1270 video_media_info.bw_estimations[0].available_recv_bandwidth = 9999; |
| 1271 EXPECT_CALL(*video_media_channel, GetStats(_)) |
| 1272 .WillOnce(DoAll(SetArgPointee<0>(video_media_info), Return(true))); |
| 1273 EXPECT_CALL(test_->session(), video_channel()) |
| 1274 .WillRepeatedly(Return(&video_channel)); |
| 1275 |
1257 rtc::scoped_refptr<const RTCStatsReport> report = GetStatsReport(); | 1276 rtc::scoped_refptr<const RTCStatsReport> report = GetStatsReport(); |
1258 | 1277 |
1259 RTCIceCandidatePairStats expected_pair("RTCIceCandidatePair_" + | 1278 RTCIceCandidatePairStats expected_pair("RTCIceCandidatePair_" + |
1260 local_candidate->id() + "_" + | 1279 local_candidate->id() + "_" + |
1261 remote_candidate->id(), | 1280 remote_candidate->id(), |
1262 report->timestamp_us()); | 1281 report->timestamp_us()); |
1263 expected_pair.transport_id = | 1282 expected_pair.transport_id = |
1264 "RTCTransport_transport_" + | 1283 "RTCTransport_transport_" + |
1265 rtc::ToString<>(cricket::ICE_CANDIDATE_COMPONENT_RTP); | 1284 rtc::ToString<>(cricket::ICE_CANDIDATE_COMPONENT_RTP); |
1266 expected_pair.local_candidate_id = "RTCIceCandidate_" + local_candidate->id(); | 1285 expected_pair.local_candidate_id = "RTCIceCandidate_" + local_candidate->id(); |
1267 expected_pair.remote_candidate_id = | 1286 expected_pair.remote_candidate_id = |
1268 "RTCIceCandidate_" + remote_candidate->id(); | 1287 "RTCIceCandidate_" + remote_candidate->id(); |
1269 expected_pair.state = RTCStatsIceCandidatePairState::kInProgress; | 1288 expected_pair.state = RTCStatsIceCandidatePairState::kInProgress; |
1270 expected_pair.priority = 5555; | 1289 expected_pair.priority = 5555; |
1271 expected_pair.writable = true; | 1290 expected_pair.writable = true; |
1272 expected_pair.bytes_sent = 42; | 1291 expected_pair.bytes_sent = 42; |
1273 expected_pair.bytes_received = 1234; | 1292 expected_pair.bytes_received = 1234; |
1274 expected_pair.current_round_trip_time = 1.337; | 1293 expected_pair.current_round_trip_time = 1.337; |
1275 expected_pair.requests_received = 2020; | 1294 expected_pair.requests_received = 2020; |
1276 expected_pair.requests_sent = 2000; | 1295 expected_pair.requests_sent = 2000; |
1277 expected_pair.responses_received = 4321; | 1296 expected_pair.responses_received = 4321; |
1278 expected_pair.responses_sent = 1000; | 1297 expected_pair.responses_sent = 1000; |
1279 expected_pair.consent_requests_sent = (2020 - 2000); | 1298 expected_pair.consent_requests_sent = (2020 - 2000); |
| 1299 // |expected_pair.available_[outgoing/incoming]_bitrate| should be undefined |
| 1300 // because is is not the current pair. |
1280 | 1301 |
1281 ASSERT_TRUE(report->Get(expected_pair.id())); | 1302 ASSERT_TRUE(report->Get(expected_pair.id())); |
1282 EXPECT_EQ( | 1303 EXPECT_EQ( |
1283 expected_pair, | 1304 expected_pair, |
| 1305 report->Get(expected_pair.id())->cast_to<RTCIceCandidatePairStats>()); |
| 1306 EXPECT_TRUE(report->Get(*expected_pair.transport_id)); |
| 1307 |
| 1308 // Make pair the current pair, clear bandwidth and "GetStats" again. |
| 1309 session_stats.transport_stats["transport"] |
| 1310 .channel_stats[0] |
| 1311 .connection_infos[0] |
| 1312 .best_connection = true; |
| 1313 video_media_info.bw_estimations[0].available_send_bandwidth = 0; |
| 1314 video_media_info.bw_estimations[0].available_recv_bandwidth = 0; |
| 1315 EXPECT_CALL(*video_media_channel, GetStats(_)) |
| 1316 .WillOnce(DoAll(SetArgPointee<0>(video_media_info), Return(true))); |
| 1317 collector_->ClearCachedStatsReport(); |
| 1318 report = GetStatsReport(); |
| 1319 // |expected_pair.available_[outgoing/incoming]_bitrate| should still be |
| 1320 // undefined because bandwidth is not set. |
| 1321 ASSERT_TRUE(report->Get(expected_pair.id())); |
| 1322 EXPECT_EQ( |
| 1323 expected_pair, |
| 1324 report->Get(expected_pair.id())->cast_to<RTCIceCandidatePairStats>()); |
| 1325 EXPECT_TRUE(report->Get(*expected_pair.transport_id)); |
| 1326 |
| 1327 // Set bandwidth and "GetStats" again. |
| 1328 video_media_info.bw_estimations[0].available_send_bandwidth = 888; |
| 1329 video_media_info.bw_estimations[0].available_recv_bandwidth = 999; |
| 1330 EXPECT_CALL(*video_media_channel, GetStats(_)) |
| 1331 .WillOnce(DoAll(SetArgPointee<0>(video_media_info), Return(true))); |
| 1332 collector_->ClearCachedStatsReport(); |
| 1333 report = GetStatsReport(); |
| 1334 expected_pair.available_outgoing_bitrate = 888; |
| 1335 expected_pair.available_incoming_bitrate = 999; |
| 1336 ASSERT_TRUE(report->Get(expected_pair.id())); |
| 1337 EXPECT_EQ( |
| 1338 expected_pair, |
1284 report->Get(expected_pair.id())->cast_to<RTCIceCandidatePairStats>()); | 1339 report->Get(expected_pair.id())->cast_to<RTCIceCandidatePairStats>()); |
1285 EXPECT_TRUE(report->Get(*expected_pair.transport_id)); | 1340 EXPECT_TRUE(report->Get(*expected_pair.transport_id)); |
1286 | 1341 |
1287 RTCLocalIceCandidateStats expected_local_candidate( | 1342 RTCLocalIceCandidateStats expected_local_candidate( |
1288 *expected_pair.local_candidate_id, report->timestamp_us()); | 1343 *expected_pair.local_candidate_id, report->timestamp_us()); |
1289 expected_local_candidate.transport_id = *expected_pair.transport_id; | 1344 expected_local_candidate.transport_id = *expected_pair.transport_id; |
1290 expected_local_candidate.ip = "42.42.42.42"; | 1345 expected_local_candidate.ip = "42.42.42.42"; |
1291 expected_local_candidate.port = 42; | 1346 expected_local_candidate.port = 42; |
1292 expected_local_candidate.protocol = "protocol"; | 1347 expected_local_candidate.protocol = "protocol"; |
1293 expected_local_candidate.candidate_type = "host"; | 1348 expected_local_candidate.candidate_type = "host"; |
(...skipping 971 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2265 rtc::scoped_refptr<FakeRTCStatsCollector> collector_; | 2320 rtc::scoped_refptr<FakeRTCStatsCollector> collector_; |
2266 }; | 2321 }; |
2267 | 2322 |
2268 TEST_F(RTCStatsCollectorTestWithFakeCollector, ThreadUsageAndResultsMerging) { | 2323 TEST_F(RTCStatsCollectorTestWithFakeCollector, ThreadUsageAndResultsMerging) { |
2269 collector_->VerifyThreadUsageAndResultsMerging(); | 2324 collector_->VerifyThreadUsageAndResultsMerging(); |
2270 } | 2325 } |
2271 | 2326 |
2272 } // namespace | 2327 } // namespace |
2273 | 2328 |
2274 } // namespace webrtc | 2329 } // namespace webrtc |
OLD | NEW |