Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(146)

Side by Side Diff: webrtc/api/statscollector_unittest.cc

Issue 2583883002: RTCStatsCollector: Utilize network thread to minimize thread hops. (Closed)
Patch Set: Addressed comments Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/api/statscollector.cc ('k') | webrtc/api/test/mock_webrtcsession.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2014 The WebRTC project authors. All Rights Reserved. 2 * Copyright 2014 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 23 matching lines...) Expand all
34 #include "webrtc/media/base/fakemediaengine.h" 34 #include "webrtc/media/base/fakemediaengine.h"
35 #include "webrtc/media/base/test/mock_mediachannel.h" 35 #include "webrtc/media/base/test/mock_mediachannel.h"
36 #include "webrtc/p2p/base/faketransportcontroller.h" 36 #include "webrtc/p2p/base/faketransportcontroller.h"
37 #include "webrtc/pc/channelmanager.h" 37 #include "webrtc/pc/channelmanager.h"
38 #include "webrtc/test/gmock.h" 38 #include "webrtc/test/gmock.h"
39 #include "webrtc/test/gtest.h" 39 #include "webrtc/test/gtest.h"
40 40
41 using testing::_; 41 using testing::_;
42 using testing::DoAll; 42 using testing::DoAll;
43 using testing::Field; 43 using testing::Field;
44 using testing::Invoke;
44 using testing::Return; 45 using testing::Return;
45 using testing::ReturnNull; 46 using testing::ReturnNull;
46 using testing::ReturnRef; 47 using testing::ReturnRef;
47 using testing::SetArgPointee; 48 using testing::SetArgPointee;
48 using webrtc::PeerConnectionInterface; 49 using webrtc::PeerConnectionInterface;
49 using webrtc::StatsReport; 50 using webrtc::StatsReport;
50 using webrtc::StatsReports; 51 using webrtc::StatsReports;
51 52
52 namespace { 53 namespace {
53 const bool kDefaultRtcpEnabled = false; 54 const bool kDefaultRtcpEnabled = false;
(...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after
502 channel_manager_(new cricket::ChannelManager(media_engine_, 503 channel_manager_(new cricket::ChannelManager(media_engine_,
503 worker_thread_, 504 worker_thread_,
504 network_thread_)), 505 network_thread_)),
505 media_controller_( 506 media_controller_(
506 webrtc::MediaControllerInterface::Create(cricket::MediaConfig(), 507 webrtc::MediaControllerInterface::Create(cricket::MediaConfig(),
507 worker_thread_, 508 worker_thread_,
508 channel_manager_.get(), 509 channel_manager_.get(),
509 &event_log_)), 510 &event_log_)),
510 session_(media_controller_.get()) { 511 session_(media_controller_.get()) {
511 // By default, we ignore session GetStats calls. 512 // By default, we ignore session GetStats calls.
512 EXPECT_CALL(session_, GetTransportStats(_)).WillRepeatedly(Return(false)); 513 EXPECT_CALL(session_, GetStats(_)).WillRepeatedly(ReturnNull());
513 // Add default returns for mock classes. 514 // Add default returns for mock classes.
514 EXPECT_CALL(session_, video_channel()).WillRepeatedly(ReturnNull()); 515 EXPECT_CALL(session_, video_channel()).WillRepeatedly(ReturnNull());
515 EXPECT_CALL(session_, voice_channel()).WillRepeatedly(ReturnNull()); 516 EXPECT_CALL(session_, voice_channel()).WillRepeatedly(ReturnNull());
516 EXPECT_CALL(pc_, session()).WillRepeatedly(Return(&session_)); 517 EXPECT_CALL(pc_, session()).WillRepeatedly(Return(&session_));
517 EXPECT_CALL(pc_, sctp_data_channels()) 518 EXPECT_CALL(pc_, sctp_data_channels())
518 .WillRepeatedly(ReturnRef(data_channels_)); 519 .WillRepeatedly(ReturnRef(data_channels_));
519 } 520 }
520 521
521 ~StatsCollectorTest() {} 522 ~StatsCollectorTest() {}
522 523
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
605 cricket::VoiceSenderInfo* voice_sender_info, 606 cricket::VoiceSenderInfo* voice_sender_info,
606 cricket::VoiceReceiverInfo* voice_receiver_info, 607 cricket::VoiceReceiverInfo* voice_receiver_info,
607 cricket::VoiceMediaInfo* stats_read, 608 cricket::VoiceMediaInfo* stats_read,
608 StatsReports* reports) { 609 StatsReports* reports) {
609 // A track can't have both sender report and recv report at the same time 610 // A track can't have both sender report and recv report at the same time
610 // for now, this might change in the future though. 611 // for now, this might change in the future though.
611 ASSERT((voice_sender_info == NULL) ^ (voice_receiver_info == NULL)); 612 ASSERT((voice_sender_info == NULL) ^ (voice_receiver_info == NULL));
612 613
613 // Instruct the session to return stats containing the transport channel. 614 // Instruct the session to return stats containing the transport channel.
614 InitSessionStats(vc_name); 615 InitSessionStats(vc_name);
615 EXPECT_CALL(session_, GetTransportStats(_)) 616 EXPECT_CALL(session_, GetStats(_)).WillRepeatedly(Invoke(
616 .WillRepeatedly(DoAll(SetArgPointee<0>(session_stats_), 617 [this](const ChannelNamePairs&) {
617 Return(true))); 618 return std::unique_ptr<SessionStats>(
619 new SessionStats(session_stats_));
620 }));
618 621
619 // Constructs an ssrc stats update. 622 // Constructs an ssrc stats update.
620 if (voice_sender_info) 623 if (voice_sender_info)
621 stats_read->senders.push_back(*voice_sender_info); 624 stats_read->senders.push_back(*voice_sender_info);
622 if (voice_receiver_info) 625 if (voice_receiver_info)
623 stats_read->receivers.push_back(*voice_receiver_info); 626 stats_read->receivers.push_back(*voice_receiver_info);
624 627
625 EXPECT_CALL(session_, voice_channel()).WillRepeatedly( 628 EXPECT_CALL(session_, voice_channel()).WillRepeatedly(
626 Return(voice_channel)); 629 Return(voice_channel));
627 EXPECT_CALL(session_, video_channel()).WillRepeatedly(ReturnNull()); 630 EXPECT_CALL(session_, video_channel()).WillRepeatedly(ReturnNull());
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
705 rtc::RTCCertificate::Create(std::unique_ptr<rtc::FakeSSLIdentity>( 708 rtc::RTCCertificate::Create(std::unique_ptr<rtc::FakeSSLIdentity>(
706 new rtc::FakeSSLIdentity(local_cert)))); 709 new rtc::FakeSSLIdentity(local_cert))));
707 710
708 // Configure MockWebRtcSession 711 // Configure MockWebRtcSession
709 EXPECT_CALL(session_, 712 EXPECT_CALL(session_,
710 GetLocalCertificate(transport_stats.transport_name, _)) 713 GetLocalCertificate(transport_stats.transport_name, _))
711 .WillOnce(DoAll(SetArgPointee<1>(local_certificate), Return(true))); 714 .WillOnce(DoAll(SetArgPointee<1>(local_certificate), Return(true)));
712 EXPECT_CALL(session_, GetRemoteSSLCertificate_ReturnsRawPointer( 715 EXPECT_CALL(session_, GetRemoteSSLCertificate_ReturnsRawPointer(
713 transport_stats.transport_name)) 716 transport_stats.transport_name))
714 .WillOnce(Return(remote_cert.release())); 717 .WillOnce(Return(remote_cert.release()));
715 EXPECT_CALL(session_, GetTransportStats(_)) 718 EXPECT_CALL(session_, GetStats(_)).WillOnce(Invoke(
716 .WillOnce(DoAll(SetArgPointee<0>(session_stats), 719 [&session_stats](const ChannelNamePairs&) {
717 Return(true))); 720 return std::unique_ptr<SessionStats>(
721 new SessionStats(session_stats));
722 }));
718 723
719 stats.UpdateStats(PeerConnectionInterface::kStatsOutputLevelStandard); 724 stats.UpdateStats(PeerConnectionInterface::kStatsOutputLevelStandard);
720 725
721 stats.GetStats(NULL, &reports); 726 stats.GetStats(NULL, &reports);
722 727
723 const StatsReport* channel_report = FindNthReportByType( 728 const StatsReport* channel_report = FindNthReportByType(
724 reports, StatsReport::kStatsReportTypeComponent, 1); 729 reports, StatsReport::kStatsReportTypeComponent, 1);
725 EXPECT_TRUE(channel_report != NULL); 730 EXPECT_TRUE(channel_report != NULL);
726 731
727 // Check local certificate chain. 732 // Check local certificate chain.
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
846 StatsCollectorForTest stats(&pc_); 851 StatsCollectorForTest stats(&pc_);
847 852
848 EXPECT_CALL(session_, GetLocalCertificate(_, _)) 853 EXPECT_CALL(session_, GetLocalCertificate(_, _))
849 .WillRepeatedly(Return(false)); 854 .WillRepeatedly(Return(false));
850 EXPECT_CALL(session_, GetRemoteSSLCertificate_ReturnsRawPointer(_)) 855 EXPECT_CALL(session_, GetRemoteSSLCertificate_ReturnsRawPointer(_))
851 .WillRepeatedly(Return(nullptr)); 856 .WillRepeatedly(Return(nullptr));
852 857
853 const char kVideoChannelName[] = "video"; 858 const char kVideoChannelName[] = "video";
854 859
855 InitSessionStats(kVideoChannelName); 860 InitSessionStats(kVideoChannelName);
856 EXPECT_CALL(session_, GetTransportStats(_)) 861 EXPECT_CALL(session_, GetStats(_)).WillRepeatedly(Invoke(
857 .WillRepeatedly(DoAll(SetArgPointee<0>(session_stats_), 862 [this](const ChannelNamePairs&) {
858 Return(true))); 863 return std::unique_ptr<SessionStats>(
864 new SessionStats(session_stats_));
865 }));
859 866
860 MockVideoMediaChannel* media_channel = new MockVideoMediaChannel(); 867 MockVideoMediaChannel* media_channel = new MockVideoMediaChannel();
861 cricket::VideoChannel video_channel( 868 cricket::VideoChannel video_channel(
862 worker_thread_, network_thread_, media_channel, nullptr, 869 worker_thread_, network_thread_, media_channel, nullptr,
863 kVideoChannelName, kDefaultRtcpEnabled, kDefaultSrtpRequired); 870 kVideoChannelName, kDefaultRtcpEnabled, kDefaultSrtpRequired);
864 StatsReports reports; // returned values. 871 StatsReports reports; // returned values.
865 cricket::VideoSenderInfo video_sender_info; 872 cricket::VideoSenderInfo video_sender_info;
866 cricket::VideoMediaInfo stats_read; 873 cricket::VideoMediaInfo stats_read;
867 // The number of bytes must be larger than 0xFFFFFFFF for this test. 874 // The number of bytes must be larger than 0xFFFFFFFF for this test.
868 const int64_t kBytesSent = 12345678901234LL; 875 const int64_t kBytesSent = 12345678901234LL;
(...skipping 24 matching lines...) Expand all
893 StatsCollectorForTest stats(&pc_); 900 StatsCollectorForTest stats(&pc_);
894 901
895 EXPECT_CALL(session_, GetLocalCertificate(_, _)) 902 EXPECT_CALL(session_, GetLocalCertificate(_, _))
896 .WillRepeatedly(Return(false)); 903 .WillRepeatedly(Return(false));
897 EXPECT_CALL(session_, GetRemoteSSLCertificate_ReturnsRawPointer(_)) 904 EXPECT_CALL(session_, GetRemoteSSLCertificate_ReturnsRawPointer(_))
898 .WillRepeatedly(Return(nullptr)); 905 .WillRepeatedly(Return(nullptr));
899 906
900 const char kVideoChannelName[] = "video"; 907 const char kVideoChannelName[] = "video";
901 908
902 InitSessionStats(kVideoChannelName); 909 InitSessionStats(kVideoChannelName);
903 EXPECT_CALL(session_, GetTransportStats(_)) 910 EXPECT_CALL(session_, GetStats(_)).WillRepeatedly(Invoke(
904 .WillRepeatedly(DoAll(SetArgPointee<0>(session_stats_), 911 [this](const ChannelNamePairs&) {
905 Return(true))); 912 return std::unique_ptr<SessionStats>(
913 new SessionStats(session_stats_));
914 }));
906 915
907 MockVideoMediaChannel* media_channel = new MockVideoMediaChannel(); 916 MockVideoMediaChannel* media_channel = new MockVideoMediaChannel();
908 cricket::VideoChannel video_channel( 917 cricket::VideoChannel video_channel(
909 worker_thread_, network_thread_, media_channel, nullptr, 918 worker_thread_, network_thread_, media_channel, nullptr,
910 kVideoChannelName, kDefaultRtcpEnabled, kDefaultSrtpRequired); 919 kVideoChannelName, kDefaultRtcpEnabled, kDefaultSrtpRequired);
911 920
912 StatsReports reports; // returned values. 921 StatsReports reports; // returned values.
913 cricket::VideoSenderInfo video_sender_info; 922 cricket::VideoSenderInfo video_sender_info;
914 cricket::VideoMediaInfo stats_read; 923 cricket::VideoMediaInfo stats_read;
915 // Set up an SSRC just to test that we get both kinds of stats back: SSRC and 924 // Set up an SSRC just to test that we get both kinds of stats back: SSRC and
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
1006 TEST_F(StatsCollectorTest, TrackAndSsrcObjectExistAfterUpdateSsrcStats) { 1015 TEST_F(StatsCollectorTest, TrackAndSsrcObjectExistAfterUpdateSsrcStats) {
1007 StatsCollectorForTest stats(&pc_); 1016 StatsCollectorForTest stats(&pc_);
1008 1017
1009 EXPECT_CALL(session_, GetLocalCertificate(_, _)) 1018 EXPECT_CALL(session_, GetLocalCertificate(_, _))
1010 .WillRepeatedly(Return(false)); 1019 .WillRepeatedly(Return(false));
1011 EXPECT_CALL(session_, GetRemoteSSLCertificate_ReturnsRawPointer(_)) 1020 EXPECT_CALL(session_, GetRemoteSSLCertificate_ReturnsRawPointer(_))
1012 .WillRepeatedly(Return(nullptr)); 1021 .WillRepeatedly(Return(nullptr));
1013 1022
1014 const char kVideoChannelName[] = "video"; 1023 const char kVideoChannelName[] = "video";
1015 InitSessionStats(kVideoChannelName); 1024 InitSessionStats(kVideoChannelName);
1016 EXPECT_CALL(session_, GetTransportStats(_)) 1025 EXPECT_CALL(session_, GetStats(_)).WillRepeatedly(Invoke(
1017 .WillRepeatedly(DoAll(SetArgPointee<0>(session_stats_), 1026 [this](const ChannelNamePairs&) {
1018 Return(true))); 1027 return std::unique_ptr<SessionStats>(
1028 new SessionStats(session_stats_));
1029 }));
1019 1030
1020 MockVideoMediaChannel* media_channel = new MockVideoMediaChannel(); 1031 MockVideoMediaChannel* media_channel = new MockVideoMediaChannel();
1021 cricket::VideoChannel video_channel( 1032 cricket::VideoChannel video_channel(
1022 worker_thread_, network_thread_, media_channel, nullptr, 1033 worker_thread_, network_thread_, media_channel, nullptr,
1023 kVideoChannelName, kDefaultRtcpEnabled, kDefaultSrtpRequired); 1034 kVideoChannelName, kDefaultRtcpEnabled, kDefaultSrtpRequired);
1024 AddOutgoingVideoTrackStats(); 1035 AddOutgoingVideoTrackStats();
1025 stats.AddStream(stream_); 1036 stats.AddStream(stream_);
1026 1037
1027 // Constructs an ssrc stats update. 1038 // Constructs an ssrc stats update.
1028 cricket::VideoSenderInfo video_sender_info; 1039 cricket::VideoSenderInfo video_sender_info;
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
1103 video_sender_info.bytes_sent = kBytesSent; 1114 video_sender_info.bytes_sent = kBytesSent;
1104 stats_read.senders.push_back(video_sender_info); 1115 stats_read.senders.push_back(video_sender_info);
1105 1116
1106 EXPECT_CALL(session_, video_channel()).WillRepeatedly(Return(&video_channel)); 1117 EXPECT_CALL(session_, video_channel()).WillRepeatedly(Return(&video_channel));
1107 EXPECT_CALL(session_, voice_channel()).WillRepeatedly(ReturnNull()); 1118 EXPECT_CALL(session_, voice_channel()).WillRepeatedly(ReturnNull());
1108 EXPECT_CALL(*media_channel, GetStats(_)) 1119 EXPECT_CALL(*media_channel, GetStats(_))
1109 .WillRepeatedly(DoAll(SetArgPointee<0>(stats_read), 1120 .WillRepeatedly(DoAll(SetArgPointee<0>(stats_read),
1110 Return(true))); 1121 Return(true)));
1111 1122
1112 InitSessionStats(kVcName); 1123 InitSessionStats(kVcName);
1113 EXPECT_CALL(session_, GetTransportStats(_)) 1124 EXPECT_CALL(session_, GetStats(_)).WillRepeatedly(Invoke(
1114 .WillRepeatedly(DoAll(SetArgPointee<0>(session_stats_), 1125 [this](const ChannelNamePairs&) {
1115 Return(true))); 1126 return std::unique_ptr<SessionStats>(
1127 new SessionStats(session_stats_));
1128 }));
1116 1129
1117 stats.UpdateStats(PeerConnectionInterface::kStatsOutputLevelStandard); 1130 stats.UpdateStats(PeerConnectionInterface::kStatsOutputLevelStandard);
1118 StatsReports reports; 1131 StatsReports reports;
1119 stats.GetStats(NULL, &reports); 1132 stats.GetStats(NULL, &reports);
1120 std::string transport_id = ExtractStatsValue( 1133 std::string transport_id = ExtractStatsValue(
1121 StatsReport::kStatsReportTypeSsrc, 1134 StatsReport::kStatsReportTypeSsrc,
1122 reports, 1135 reports,
1123 StatsReport::kStatsValueNameTransportId); 1136 StatsReport::kStatsValueNameTransportId);
1124 ASSERT_NE(kNotFound, transport_id); 1137 ASSERT_NE(kNotFound, transport_id);
1125 // Transport id component ID will always be 1. 1138 // Transport id component ID will always be 1.
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
1174 // The transport_name known by the video channel. 1187 // The transport_name known by the video channel.
1175 const std::string kVcName("vcname"); 1188 const std::string kVcName("vcname");
1176 cricket::VideoChannel video_channel( 1189 cricket::VideoChannel video_channel(
1177 worker_thread_, network_thread_, media_channel, nullptr, kVcName, 1190 worker_thread_, network_thread_, media_channel, nullptr, kVcName,
1178 kDefaultRtcpEnabled, kDefaultSrtpRequired); 1191 kDefaultRtcpEnabled, kDefaultSrtpRequired);
1179 AddOutgoingVideoTrackStats(); 1192 AddOutgoingVideoTrackStats();
1180 stats.AddStream(stream_); 1193 stats.AddStream(stream_);
1181 1194
1182 // Instruct the session to return stats containing the transport channel. 1195 // Instruct the session to return stats containing the transport channel.
1183 InitSessionStats(kVcName); 1196 InitSessionStats(kVcName);
1184 EXPECT_CALL(session_, GetTransportStats(_)) 1197 EXPECT_CALL(session_, GetStats(_)).WillRepeatedly(Invoke(
1185 .WillRepeatedly(DoAll(SetArgPointee<0>(session_stats_), 1198 [this](const ChannelNamePairs&) {
1186 Return(true))); 1199 return std::unique_ptr<SessionStats>(
1200 new SessionStats(session_stats_));
1201 }));
1187 1202
1188 // Constructs an ssrc stats update. 1203 // Constructs an ssrc stats update.
1189 cricket::VideoMediaInfo stats_read; 1204 cricket::VideoMediaInfo stats_read;
1190 1205
1191 cricket::SsrcReceiverInfo remote_ssrc_stats; 1206 cricket::SsrcReceiverInfo remote_ssrc_stats;
1192 remote_ssrc_stats.timestamp = 12345.678; 1207 remote_ssrc_stats.timestamp = 12345.678;
1193 remote_ssrc_stats.ssrc = kSsrcOfTrack; 1208 remote_ssrc_stats.ssrc = kSsrcOfTrack;
1194 cricket::VideoSenderInfo video_sender_info; 1209 cricket::VideoSenderInfo video_sender_info;
1195 video_sender_info.add_ssrc(kSsrcOfTrack); 1210 video_sender_info.add_ssrc(kSsrcOfTrack);
1196 video_sender_info.remote_stats.push_back(remote_ssrc_stats); 1211 video_sender_info.remote_stats.push_back(remote_ssrc_stats);
(...skipping 20 matching lines...) Expand all
1217 TEST_F(StatsCollectorTest, ReportsFromRemoteTrack) { 1232 TEST_F(StatsCollectorTest, ReportsFromRemoteTrack) {
1218 StatsCollectorForTest stats(&pc_); 1233 StatsCollectorForTest stats(&pc_);
1219 1234
1220 EXPECT_CALL(session_, GetLocalCertificate(_, _)) 1235 EXPECT_CALL(session_, GetLocalCertificate(_, _))
1221 .WillRepeatedly(Return(false)); 1236 .WillRepeatedly(Return(false));
1222 EXPECT_CALL(session_, GetRemoteSSLCertificate_ReturnsRawPointer(_)) 1237 EXPECT_CALL(session_, GetRemoteSSLCertificate_ReturnsRawPointer(_))
1223 .WillRepeatedly(Return(nullptr)); 1238 .WillRepeatedly(Return(nullptr));
1224 1239
1225 const char kVideoChannelName[] = "video"; 1240 const char kVideoChannelName[] = "video";
1226 InitSessionStats(kVideoChannelName); 1241 InitSessionStats(kVideoChannelName);
1227 EXPECT_CALL(session_, GetTransportStats(_)) 1242 EXPECT_CALL(session_, GetStats(_)).WillRepeatedly(Invoke(
1228 .WillRepeatedly(DoAll(SetArgPointee<0>(session_stats_), 1243 [this](const ChannelNamePairs&) {
1229 Return(true))); 1244 return std::unique_ptr<SessionStats>(
1245 new SessionStats(session_stats_));
1246 }));
1230 1247
1231 MockVideoMediaChannel* media_channel = new MockVideoMediaChannel(); 1248 MockVideoMediaChannel* media_channel = new MockVideoMediaChannel();
1232 cricket::VideoChannel video_channel( 1249 cricket::VideoChannel video_channel(
1233 worker_thread_, network_thread_, media_channel, nullptr, 1250 worker_thread_, network_thread_, media_channel, nullptr,
1234 kVideoChannelName, kDefaultRtcpEnabled, kDefaultSrtpRequired); 1251 kVideoChannelName, kDefaultRtcpEnabled, kDefaultSrtpRequired);
1235 AddIncomingVideoTrackStats(); 1252 AddIncomingVideoTrackStats();
1236 stats.AddStream(stream_); 1253 stats.AddStream(stream_);
1237 1254
1238 // Constructs an ssrc stats update. 1255 // Constructs an ssrc stats update.
1239 cricket::VideoReceiverInfo video_receiver_info; 1256 cricket::VideoReceiverInfo video_receiver_info;
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
1423 1440
1424 cricket::TransportStats transport_stats; 1441 cricket::TransportStats transport_stats;
1425 transport_stats.transport_name = "audio"; 1442 transport_stats.transport_name = "audio";
1426 transport_stats.channel_stats.push_back(channel_stats); 1443 transport_stats.channel_stats.push_back(channel_stats);
1427 1444
1428 SessionStats session_stats; 1445 SessionStats session_stats;
1429 session_stats.transport_stats[transport_stats.transport_name] = 1446 session_stats.transport_stats[transport_stats.transport_name] =
1430 transport_stats; 1447 transport_stats;
1431 1448
1432 // Configure MockWebRtcSession 1449 // Configure MockWebRtcSession
1433 EXPECT_CALL(session_, GetTransportStats(_)) 1450 EXPECT_CALL(session_, GetStats(_)).WillRepeatedly(Invoke(
1434 .WillOnce(DoAll(SetArgPointee<0>(session_stats), 1451 [&session_stats](const ChannelNamePairs&) {
1435 Return(true))); 1452 return std::unique_ptr<SessionStats>(
1453 new SessionStats(session_stats));
1454 }));
1436 1455
1437 stats.UpdateStats(PeerConnectionInterface::kStatsOutputLevelStandard); 1456 stats.UpdateStats(PeerConnectionInterface::kStatsOutputLevelStandard);
1438 stats.GetStats(NULL, &reports); 1457 stats.GetStats(NULL, &reports);
1439 1458
1440 // Check that the local certificate is absent. 1459 // Check that the local certificate is absent.
1441 std::string local_certificate_id = ExtractStatsValue( 1460 std::string local_certificate_id = ExtractStatsValue(
1442 StatsReport::kStatsReportTypeComponent, 1461 StatsReport::kStatsReportTypeComponent,
1443 reports, 1462 reports,
1444 StatsReport::kStatsValueNameLocalCertificateId); 1463 StatsReport::kStatsValueNameLocalCertificateId);
1445 ASSERT_EQ(kNotFound, local_certificate_id); 1464 ASSERT_EQ(kNotFound, local_certificate_id);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1480 1499
1481 cricket::TransportStats transport_stats; 1500 cricket::TransportStats transport_stats;
1482 transport_stats.transport_name = "audio"; 1501 transport_stats.transport_name = "audio";
1483 transport_stats.channel_stats.push_back(channel_stats); 1502 transport_stats.channel_stats.push_back(channel_stats);
1484 1503
1485 SessionStats session_stats; 1504 SessionStats session_stats;
1486 session_stats.transport_stats[transport_stats.transport_name] = 1505 session_stats.transport_stats[transport_stats.transport_name] =
1487 transport_stats; 1506 transport_stats;
1488 1507
1489 // Configure MockWebRtcSession 1508 // Configure MockWebRtcSession
1490 EXPECT_CALL(session_, GetTransportStats(_)) 1509 EXPECT_CALL(session_, GetStats(_)).WillRepeatedly(Invoke(
1491 .WillOnce(DoAll(SetArgPointee<0>(session_stats), 1510 [&session_stats](const ChannelNamePairs&) {
1492 Return(true))); 1511 return std::unique_ptr<SessionStats>(
1512 new SessionStats(session_stats));
1513 }));
1493 stats.UpdateStats(PeerConnectionInterface::kStatsOutputLevelStandard); 1514 stats.UpdateStats(PeerConnectionInterface::kStatsOutputLevelStandard);
1494 stats.GetStats(NULL, &reports); 1515 stats.GetStats(NULL, &reports);
1495 1516
1496 // Check that the local certificate is absent. 1517 // Check that the local certificate is absent.
1497 std::string local_certificate_id = ExtractStatsValue( 1518 std::string local_certificate_id = ExtractStatsValue(
1498 StatsReport::kStatsReportTypeComponent, 1519 StatsReport::kStatsReportTypeComponent,
1499 reports, 1520 reports,
1500 StatsReport::kStatsValueNameLocalCertificateId); 1521 StatsReport::kStatsValueNameLocalCertificateId);
1501 ASSERT_EQ(kNotFound, local_certificate_id); 1522 ASSERT_EQ(kNotFound, local_certificate_id);
1502 1523
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
1559 webrtc::MediaStream::Create("remotestreamlabel")); 1580 webrtc::MediaStream::Create("remotestreamlabel"));
1560 rtc::scoped_refptr<FakeAudioTrackWithInitValue> remote_track( 1581 rtc::scoped_refptr<FakeAudioTrackWithInitValue> remote_track(
1561 new rtc::RefCountedObject<FakeAudioTrackWithInitValue>(kRemoteTrackId)); 1582 new rtc::RefCountedObject<FakeAudioTrackWithInitValue>(kRemoteTrackId));
1562 EXPECT_CALL(session_, GetRemoteTrackIdBySsrc(kSsrcOfTrack, _)) 1583 EXPECT_CALL(session_, GetRemoteTrackIdBySsrc(kSsrcOfTrack, _))
1563 .WillOnce(DoAll(SetArgPointee<1>(kRemoteTrackId), Return(true))); 1584 .WillOnce(DoAll(SetArgPointee<1>(kRemoteTrackId), Return(true)));
1564 remote_stream->AddTrack(remote_track); 1585 remote_stream->AddTrack(remote_track);
1565 stats.AddStream(remote_stream); 1586 stats.AddStream(remote_stream);
1566 1587
1567 // Instruct the session to return stats containing the transport channel. 1588 // Instruct the session to return stats containing the transport channel.
1568 InitSessionStats(kVcName); 1589 InitSessionStats(kVcName);
1569 EXPECT_CALL(session_, GetTransportStats(_)) 1590 EXPECT_CALL(session_, GetStats(_)).WillRepeatedly(Invoke(
1570 .WillRepeatedly(DoAll(SetArgPointee<0>(session_stats_), Return(true))); 1591 [this](const ChannelNamePairs&) {
1592 return std::unique_ptr<SessionStats>(
1593 new SessionStats(session_stats_));
1594 }));
1571 1595
1572 cricket::VoiceSenderInfo voice_sender_info; 1596 cricket::VoiceSenderInfo voice_sender_info;
1573 voice_sender_info.add_ssrc(kSsrcOfTrack); 1597 voice_sender_info.add_ssrc(kSsrcOfTrack);
1574 // These values are set to -1 initially in audio_send_stream. 1598 // These values are set to -1 initially in audio_send_stream.
1575 // The voice_sender_info will read the values from audio_send_stream. 1599 // The voice_sender_info will read the values from audio_send_stream.
1576 voice_sender_info.rtt_ms = -1; 1600 voice_sender_info.rtt_ms = -1;
1577 voice_sender_info.packets_lost = -1; 1601 voice_sender_info.packets_lost = -1;
1578 voice_sender_info.jitter_ms = -1; 1602 voice_sender_info.jitter_ms = -1;
1579 1603
1580 // Some of the contents in |voice_sender_info| needs to be updated from the 1604 // Some of the contents in |voice_sender_info| needs to be updated from the
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
1713 const std::string kVcName("vcname"); 1737 const std::string kVcName("vcname");
1714 cricket::VoiceChannel voice_channel( 1738 cricket::VoiceChannel voice_channel(
1715 worker_thread_, network_thread_, media_engine_, media_channel, nullptr, 1739 worker_thread_, network_thread_, media_engine_, media_channel, nullptr,
1716 kVcName, kDefaultRtcpEnabled, kDefaultSrtpRequired); 1740 kVcName, kDefaultRtcpEnabled, kDefaultSrtpRequired);
1717 AddOutgoingAudioTrackStats(); 1741 AddOutgoingAudioTrackStats();
1718 stats.AddStream(stream_); 1742 stats.AddStream(stream_);
1719 stats.AddLocalAudioTrack(audio_track_.get(), kSsrcOfTrack); 1743 stats.AddLocalAudioTrack(audio_track_.get(), kSsrcOfTrack);
1720 1744
1721 // Instruct the session to return stats containing the transport channel. 1745 // Instruct the session to return stats containing the transport channel.
1722 InitSessionStats(kVcName); 1746 InitSessionStats(kVcName);
1723 EXPECT_CALL(session_, GetTransportStats(_)) 1747 EXPECT_CALL(session_, GetStats(_)).WillRepeatedly(Invoke(
1724 .WillRepeatedly(DoAll(SetArgPointee<0>(session_stats_), 1748 [this](const ChannelNamePairs&) {
1725 Return(true))); 1749 return std::unique_ptr<SessionStats>(
1750 new SessionStats(session_stats_));
1751 }));
1726 1752
1727 stats.RemoveLocalAudioTrack(audio_track_.get(), kSsrcOfTrack); 1753 stats.RemoveLocalAudioTrack(audio_track_.get(), kSsrcOfTrack);
1728 cricket::VoiceSenderInfo voice_sender_info; 1754 cricket::VoiceSenderInfo voice_sender_info;
1729 InitVoiceSenderInfo(&voice_sender_info); 1755 InitVoiceSenderInfo(&voice_sender_info);
1730 1756
1731 // Constructs an ssrc stats update. 1757 // Constructs an ssrc stats update.
1732 cricket::VoiceMediaInfo stats_read; 1758 cricket::VoiceMediaInfo stats_read;
1733 stats_read.senders.push_back(voice_sender_info); 1759 stats_read.senders.push_back(voice_sender_info);
1734 1760
1735 EXPECT_CALL(session_, voice_channel()).WillRepeatedly(Return(&voice_channel)); 1761 EXPECT_CALL(session_, voice_channel()).WillRepeatedly(Return(&voice_channel));
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
1787 webrtc::MediaStream::Create("remotestreamlabel")); 1813 webrtc::MediaStream::Create("remotestreamlabel"));
1788 rtc::scoped_refptr<FakeAudioTrack> remote_track( 1814 rtc::scoped_refptr<FakeAudioTrack> remote_track(
1789 new rtc::RefCountedObject<FakeAudioTrack>(kRemoteTrackId)); 1815 new rtc::RefCountedObject<FakeAudioTrack>(kRemoteTrackId));
1790 EXPECT_CALL(session_, GetRemoteTrackIdBySsrc(kSsrcOfTrack, _)) 1816 EXPECT_CALL(session_, GetRemoteTrackIdBySsrc(kSsrcOfTrack, _))
1791 .WillOnce(DoAll(SetArgPointee<1>(kRemoteTrackId), Return(true))); 1817 .WillOnce(DoAll(SetArgPointee<1>(kRemoteTrackId), Return(true)));
1792 remote_stream->AddTrack(remote_track); 1818 remote_stream->AddTrack(remote_track);
1793 stats.AddStream(remote_stream); 1819 stats.AddStream(remote_stream);
1794 1820
1795 // Instruct the session to return stats containing the transport channel. 1821 // Instruct the session to return stats containing the transport channel.
1796 InitSessionStats(kVcName); 1822 InitSessionStats(kVcName);
1797 EXPECT_CALL(session_, GetTransportStats(_)) 1823 EXPECT_CALL(session_, GetStats(_)).WillRepeatedly(Invoke(
1798 .WillRepeatedly(DoAll(SetArgPointee<0>(session_stats_), 1824 [this](const ChannelNamePairs&) {
1799 Return(true))); 1825 return std::unique_ptr<SessionStats>(
1826 new SessionStats(session_stats_));
1827 }));
1800 1828
1801 cricket::VoiceSenderInfo voice_sender_info; 1829 cricket::VoiceSenderInfo voice_sender_info;
1802 InitVoiceSenderInfo(&voice_sender_info); 1830 InitVoiceSenderInfo(&voice_sender_info);
1803 1831
1804 // Some of the contents in |voice_sender_info| needs to be updated from the 1832 // Some of the contents in |voice_sender_info| needs to be updated from the
1805 // |audio_track_|. 1833 // |audio_track_|.
1806 UpdateVoiceSenderInfoFromAudioTrack(audio_track_.get(), &voice_sender_info); 1834 UpdateVoiceSenderInfoFromAudioTrack(audio_track_.get(), &voice_sender_info);
1807 1835
1808 cricket::VoiceReceiverInfo voice_receiver_info; 1836 cricket::VoiceReceiverInfo voice_receiver_info;
1809 InitVoiceReceiverInfo(&voice_receiver_info); 1837 InitVoiceReceiverInfo(&voice_receiver_info);
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
1907 StatsCollectorForTest stats(&pc_); 1935 StatsCollectorForTest stats(&pc_);
1908 1936
1909 EXPECT_CALL(session_, GetLocalCertificate(_, _)) 1937 EXPECT_CALL(session_, GetLocalCertificate(_, _))
1910 .WillRepeatedly(Return(false)); 1938 .WillRepeatedly(Return(false));
1911 EXPECT_CALL(session_, GetRemoteSSLCertificate_ReturnsRawPointer(_)) 1939 EXPECT_CALL(session_, GetRemoteSSLCertificate_ReturnsRawPointer(_))
1912 .WillRepeatedly(Return(nullptr)); 1940 .WillRepeatedly(Return(nullptr));
1913 1941
1914 const char kVideoChannelName[] = "video"; 1942 const char kVideoChannelName[] = "video";
1915 1943
1916 InitSessionStats(kVideoChannelName); 1944 InitSessionStats(kVideoChannelName);
1917 EXPECT_CALL(session_, GetTransportStats(_)) 1945 EXPECT_CALL(session_, GetStats(_)).WillRepeatedly(Invoke(
1918 .WillRepeatedly(DoAll(SetArgPointee<0>(session_stats_), Return(true))); 1946 [this](const ChannelNamePairs&) {
1947 return std::unique_ptr<SessionStats>(
1948 new SessionStats(session_stats_));
1949 }));
1919 1950
1920 MockVideoMediaChannel* media_channel = new MockVideoMediaChannel(); 1951 MockVideoMediaChannel* media_channel = new MockVideoMediaChannel();
1921 cricket::VideoChannel video_channel( 1952 cricket::VideoChannel video_channel(
1922 worker_thread_, network_thread_, media_channel, nullptr, 1953 worker_thread_, network_thread_, media_channel, nullptr,
1923 kVideoChannelName, kDefaultRtcpEnabled, kDefaultSrtpRequired); 1954 kVideoChannelName, kDefaultRtcpEnabled, kDefaultSrtpRequired);
1924 StatsReports reports; // returned values. 1955 StatsReports reports; // returned values.
1925 cricket::VideoSenderInfo video_sender_info; 1956 cricket::VideoSenderInfo video_sender_info;
1926 cricket::VideoMediaInfo stats_read; 1957 cricket::VideoMediaInfo stats_read;
1927 1958
1928 AddOutgoingVideoTrackStats(); 1959 AddOutgoingVideoTrackStats();
(...skipping 23 matching lines...) Expand all
1952 StatsCollectorForTest stats(&pc_); 1983 StatsCollectorForTest stats(&pc_);
1953 1984
1954 EXPECT_CALL(session_, GetLocalCertificate(_, _)) 1985 EXPECT_CALL(session_, GetLocalCertificate(_, _))
1955 .WillRepeatedly(Return(false)); 1986 .WillRepeatedly(Return(false));
1956 EXPECT_CALL(session_, GetRemoteSSLCertificate_ReturnsRawPointer(_)) 1987 EXPECT_CALL(session_, GetRemoteSSLCertificate_ReturnsRawPointer(_))
1957 .WillRepeatedly(Return(nullptr)); 1988 .WillRepeatedly(Return(nullptr));
1958 1989
1959 const char kVideoChannelName[] = "video"; 1990 const char kVideoChannelName[] = "video";
1960 1991
1961 InitSessionStats(kVideoChannelName); 1992 InitSessionStats(kVideoChannelName);
1962 EXPECT_CALL(session_, GetTransportStats(_)) 1993 EXPECT_CALL(session_, GetStats(_)).WillRepeatedly(Invoke(
1963 .WillRepeatedly(DoAll(SetArgPointee<0>(session_stats_), Return(true))); 1994 [this](const ChannelNamePairs&) {
1995 return std::unique_ptr<SessionStats>(
1996 new SessionStats(session_stats_));
1997 }));
1964 1998
1965 MockVideoMediaChannel* media_channel = new MockVideoMediaChannel(); 1999 MockVideoMediaChannel* media_channel = new MockVideoMediaChannel();
1966 cricket::VideoChannel video_channel( 2000 cricket::VideoChannel video_channel(
1967 worker_thread_, network_thread_, media_channel, nullptr, 2001 worker_thread_, network_thread_, media_channel, nullptr,
1968 kVideoChannelName, kDefaultRtcpEnabled, kDefaultSrtpRequired); 2002 kVideoChannelName, kDefaultRtcpEnabled, kDefaultSrtpRequired);
1969 StatsReports reports; // returned values. 2003 StatsReports reports; // returned values.
1970 cricket::VideoReceiverInfo video_receiver_info; 2004 cricket::VideoReceiverInfo video_receiver_info;
1971 cricket::VideoMediaInfo stats_read; 2005 cricket::VideoMediaInfo stats_read;
1972 2006
1973 AddIncomingVideoTrackStats(); 2007 AddIncomingVideoTrackStats();
1974 stats.AddStream(stream_); 2008 stats.AddStream(stream_);
1975 2009
1976 // Construct a stats value to read. 2010 // Construct a stats value to read.
1977 video_receiver_info.add_ssrc(1234); 2011 video_receiver_info.add_ssrc(1234);
1978 video_receiver_info.frames_decoded = 10; 2012 video_receiver_info.frames_decoded = 10;
1979 stats_read.receivers.push_back(video_receiver_info); 2013 stats_read.receivers.push_back(video_receiver_info);
1980 2014
1981 EXPECT_CALL(session_, video_channel()).WillRepeatedly(Return(&video_channel)); 2015 EXPECT_CALL(session_, video_channel()).WillRepeatedly(Return(&video_channel));
1982 EXPECT_CALL(session_, voice_channel()).WillRepeatedly(ReturnNull()); 2016 EXPECT_CALL(session_, voice_channel()).WillRepeatedly(ReturnNull());
1983 EXPECT_CALL(*media_channel, GetStats(_)) 2017 EXPECT_CALL(*media_channel, GetStats(_))
1984 .WillOnce(DoAll(SetArgPointee<0>(stats_read), Return(true))); 2018 .WillOnce(DoAll(SetArgPointee<0>(stats_read), Return(true)));
1985 stats.UpdateStats(PeerConnectionInterface::kStatsOutputLevelStandard); 2019 stats.UpdateStats(PeerConnectionInterface::kStatsOutputLevelStandard);
1986 stats.GetStats(NULL, &reports); 2020 stats.GetStats(NULL, &reports);
1987 EXPECT_EQ(rtc::ToString(video_receiver_info.frames_decoded), 2021 EXPECT_EQ(rtc::ToString(video_receiver_info.frames_decoded),
1988 ExtractSsrcStatsValue(reports, 2022 ExtractSsrcStatsValue(reports,
1989 StatsReport::kStatsValueNameFramesDecoded)); 2023 StatsReport::kStatsValueNameFramesDecoded));
1990 } 2024 }
1991 2025
1992 } // namespace webrtc 2026 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/api/statscollector.cc ('k') | webrtc/api/test/mock_webrtcsession.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698