Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <string> | 5 #include <string> |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/test/test_timeouts.h" | 8 #include "base/test/test_timeouts.h" |
| 9 #include "base/time/time.h" | 9 #include "base/time/time.h" |
| 10 #include "chrome/browser/media/webrtc/test_stats_dictionary.h" | 10 #include "chrome/browser/media/webrtc/test_stats_dictionary.h" |
| 11 #include "chrome/browser/media/webrtc/webrtc_browsertest_base.h" | 11 #include "chrome/browser/media/webrtc/webrtc_browsertest_base.h" |
| 12 #include "chrome/browser/media/webrtc/webrtc_browsertest_common.h" | 12 #include "chrome/browser/media/webrtc/webrtc_browsertest_common.h" |
| 13 #include "content/public/common/content_switches.h" | 13 #include "content/public/common/content_switches.h" |
| 14 #include "content/public/common/feature_h264_with_openh264_ffmpeg.h" | 14 #include "content/public/common/feature_h264_with_openh264_ffmpeg.h" |
| 15 #include "media/base/media_switches.h" | 15 #include "media/base/media_switches.h" |
| 16 #include "testing/perf/perf_test.h" | 16 #include "testing/perf/perf_test.h" |
| 17 | 17 |
| 18 namespace content { | 18 namespace content { |
| 19 | 19 |
| 20 namespace { | 20 namespace { |
| 21 | 21 |
| 22 const char kMainWebrtcTestHtmlPage[] = "/webrtc/webrtc_jsep01_test.html"; | 22 const char kMainWebrtcTestHtmlPage[] = "/webrtc/webrtc_jsep01_test.html"; |
| 23 | 23 |
| 24 const char kInboundRtp[] = "inbound-rtp"; | 24 const char kInboundRtp[] = "inbound-rtp"; |
| 25 const char kOutboundRtp[] = "outbound-rtp"; | 25 const char kOutboundRtp[] = "outbound-rtp"; |
| 26 | 26 |
| 27 enum class GetStatsVariety { | |
|
hta - Chromium
2017/01/23 14:53:52
English nit: This should be "GetStatsVariation", n
hbos_chromium
2017/01/24 12:08:36
Done.
| |
| 28 PROMISE_BASED, | |
| 29 CALLBACK_BASED | |
| 30 }; | |
| 31 | |
| 27 // Sums up "RTC[In/Out]boundRTPStreamStats.bytes_[received/sent]" values. | 32 // Sums up "RTC[In/Out]boundRTPStreamStats.bytes_[received/sent]" values. |
| 28 double GetTotalRTPStreamBytes( | 33 double GetTotalRTPStreamBytes( |
| 29 TestStatsReportDictionary* report, const char* type, | 34 TestStatsReportDictionary* report, const char* type, |
| 30 const char* media_type) { | 35 const char* media_type) { |
| 31 DCHECK(type == kInboundRtp || type == kOutboundRtp); | 36 DCHECK(type == kInboundRtp || type == kOutboundRtp); |
| 32 const char* bytes_name = | 37 const char* bytes_name = |
| 33 (type == kInboundRtp) ? "bytesReceived" : "bytesSent"; | 38 (type == kInboundRtp) ? "bytesReceived" : "bytesSent"; |
| 34 double total_bytes = 0.0; | 39 double total_bytes = 0.0; |
| 35 report->ForEach([&type, &bytes_name, &media_type, &total_bytes]( | 40 report->ForEach([&type, &bytes_name, &media_type, &total_bytes]( |
| 36 const TestStatsDictionary& stats) { | 41 const TestStatsDictionary& stats) { |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 77 .Append(test::kReferenceFileName360p) | 82 .Append(test::kReferenceFileName360p) |
| 78 .AddExtension(test::kY4mFileExtension); | 83 .AddExtension(test::kY4mFileExtension); |
| 79 command_line->AppendSwitchPath(switches::kUseFileForFakeVideoCapture, | 84 command_line->AppendSwitchPath(switches::kUseFileForFakeVideoCapture, |
| 80 input_video); | 85 input_video); |
| 81 command_line->AppendSwitch(switches::kUseFakeDeviceForMediaStream); | 86 command_line->AppendSwitch(switches::kUseFakeDeviceForMediaStream); |
| 82 | 87 |
| 83 command_line->AppendSwitchASCII(switches::kEnableBlinkFeatures, | 88 command_line->AppendSwitchASCII(switches::kEnableBlinkFeatures, |
| 84 "RTCPeerConnectionNewGetStats"); | 89 "RTCPeerConnectionNewGetStats"); |
| 85 } | 90 } |
| 86 | 91 |
| 87 void RunsAudioAndVideoCall( | 92 void StartCall(const std::string& audio_codec, |
| 88 const std::string& audio_codec, const std::string& video_codec) { | 93 const std::string& video_codec) { |
| 89 ASSERT_TRUE(test::HasReferenceFilesInCheckout()); | 94 ASSERT_TRUE(test::HasReferenceFilesInCheckout()); |
| 90 ASSERT_TRUE(embedded_test_server()->Start()); | 95 ASSERT_TRUE(embedded_test_server()->Start()); |
| 91 ASSERT_TRUE(audio_codec != kUseDefaultAudioCodec || | |
| 92 video_codec != kUseDefaultVideoCodec); | |
| 93 | 96 |
| 94 ASSERT_GE(TestTimeouts::action_max_timeout().InSeconds(), 100) | 97 ASSERT_GE(TestTimeouts::action_max_timeout().InSeconds(), 100) |
| 95 << "This is a long-running test; you must specify " | 98 << "This is a long-running test; you must specify " |
| 96 "--ui-test-action-max-timeout to have a value of at least 100000."; | 99 "--ui-test-action-max-timeout to have a value of at least 100000."; |
| 97 | 100 |
| 98 content::WebContents* left_tab = | 101 left_tab_ = OpenTestPageAndGetUserMediaInNewTab(kMainWebrtcTestHtmlPage); |
| 99 OpenTestPageAndGetUserMediaInNewTab(kMainWebrtcTestHtmlPage); | 102 right_tab_ = OpenTestPageAndGetUserMediaInNewTab(kMainWebrtcTestHtmlPage); |
| 100 content::WebContents* right_tab = | |
| 101 OpenTestPageAndGetUserMediaInNewTab(kMainWebrtcTestHtmlPage); | |
| 102 | 103 |
| 103 SetupPeerconnectionWithLocalStream(left_tab); | 104 SetupPeerconnectionWithLocalStream(left_tab_); |
| 104 SetupPeerconnectionWithLocalStream(right_tab); | 105 SetupPeerconnectionWithLocalStream(right_tab_); |
| 105 SetDefaultAudioCodec(left_tab, audio_codec); | 106 SetDefaultAudioCodec(left_tab_, audio_codec); |
| 106 SetDefaultAudioCodec(right_tab, audio_codec); | 107 SetDefaultAudioCodec(right_tab_, audio_codec); |
| 107 SetDefaultVideoCodec(left_tab, video_codec); | 108 SetDefaultVideoCodec(left_tab_, video_codec); |
| 108 SetDefaultVideoCodec(right_tab, video_codec); | 109 SetDefaultVideoCodec(right_tab_, video_codec); |
| 109 NegotiateCall(left_tab, right_tab); | 110 NegotiateCall(left_tab_, right_tab_); |
| 110 StartDetectingVideo(left_tab, "remote-view"); | 111 StartDetectingVideo(left_tab_, "remote-view"); |
| 111 StartDetectingVideo(right_tab, "remote-view"); | 112 StartDetectingVideo(right_tab_, "remote-view"); |
| 112 WaitForVideoToPlay(left_tab); | 113 WaitForVideoToPlay(left_tab_); |
| 113 WaitForVideoToPlay(right_tab); | 114 WaitForVideoToPlay(right_tab_); |
| 115 } | |
| 116 | |
| 117 void EndCall() { | |
| 118 if (left_tab_) { | |
|
tommi (sloooow) - chröme
2017/01/23 14:19:51
nit: no need for {} in cases like this
hbos_chromium
2017/01/24 12:08:36
Done.
| |
| 119 HangUp(left_tab_); | |
| 120 } | |
| 121 if (right_tab_) { | |
| 122 HangUp(right_tab_); | |
| 123 } | |
| 124 } | |
| 125 | |
| 126 void RunsAudioAndVideoCallCollectingMetrics( | |
| 127 const std::string& audio_codec, const std::string& video_codec) { | |
| 128 StartCall(audio_codec, video_codec); | |
| 114 | 129 |
| 115 // Call for 60 seconds so that values may stabilize, bandwidth ramp up, etc. | 130 // Call for 60 seconds so that values may stabilize, bandwidth ramp up, etc. |
| 116 test::SleepInJavascript(left_tab, 60000); | 131 test::SleepInJavascript(left_tab_, 60000); |
| 117 | 132 |
| 118 // The ramp-up may vary greatly and impact the resulting total bytes, to get | 133 // The ramp-up may vary greatly and impact the resulting total bytes, to get |
| 119 // reliable measurements we do two measurements, at 60 and 70 seconds and | 134 // reliable measurements we do two measurements, at 60 and 70 seconds and |
| 120 // look at the average bytes/second in that window. | 135 // look at the average bytes/second in that window. |
| 121 double audio_bytes_sent_before = 0.0; | 136 double audio_bytes_sent_before = 0.0; |
| 122 double audio_bytes_received_before = 0.0; | 137 double audio_bytes_received_before = 0.0; |
| 123 double video_bytes_sent_before = 0.0; | 138 double video_bytes_sent_before = 0.0; |
| 124 double video_bytes_received_before = 0.0; | 139 double video_bytes_received_before = 0.0; |
| 125 | 140 |
| 126 scoped_refptr<TestStatsReportDictionary> report = | 141 scoped_refptr<TestStatsReportDictionary> report = |
| 127 GetStatsReportDictionary(left_tab); | 142 GetStatsReportDictionary(left_tab_); |
| 128 if (audio_codec != kUseDefaultAudioCodec) { | 143 if (audio_codec != kUseDefaultAudioCodec) { |
| 129 audio_bytes_sent_before = GetAudioBytesSent(report.get()); | 144 audio_bytes_sent_before = GetAudioBytesSent(report.get()); |
| 130 audio_bytes_received_before = GetAudioBytesReceived(report.get()); | 145 audio_bytes_received_before = GetAudioBytesReceived(report.get()); |
| 131 | 146 |
| 132 } | 147 } |
| 133 if (video_codec != kUseDefaultVideoCodec) { | 148 if (video_codec != kUseDefaultVideoCodec) { |
| 134 video_bytes_sent_before = GetVideoBytesSent(report.get()); | 149 video_bytes_sent_before = GetVideoBytesSent(report.get()); |
| 135 video_bytes_received_before = GetVideoBytesReceived(report.get()); | 150 video_bytes_received_before = GetVideoBytesReceived(report.get()); |
| 136 } | 151 } |
| 137 | 152 |
| 138 double measure_duration_seconds = 10.0; | 153 double measure_duration_seconds = 10.0; |
| 139 test::SleepInJavascript(left_tab, static_cast<int>( | 154 test::SleepInJavascript(left_tab_, static_cast<int>( |
| 140 measure_duration_seconds * base::Time::kMillisecondsPerSecond)); | 155 measure_duration_seconds * base::Time::kMillisecondsPerSecond)); |
| 141 | 156 |
| 142 report = GetStatsReportDictionary(left_tab); | 157 report = GetStatsReportDictionary(left_tab_); |
| 143 if (audio_codec != kUseDefaultAudioCodec) { | 158 if (audio_codec != kUseDefaultAudioCodec) { |
| 144 double audio_bytes_sent_after = GetAudioBytesSent(report.get()); | 159 double audio_bytes_sent_after = GetAudioBytesSent(report.get()); |
| 145 double audio_bytes_received_after = GetAudioBytesReceived(report.get()); | 160 double audio_bytes_received_after = GetAudioBytesReceived(report.get()); |
| 146 | 161 |
| 147 double audio_send_rate = | 162 double audio_send_rate = |
| 148 (audio_bytes_sent_after - audio_bytes_sent_before) / | 163 (audio_bytes_sent_after - audio_bytes_sent_before) / |
| 149 measure_duration_seconds; | 164 measure_duration_seconds; |
| 150 double audio_receive_rate = | 165 double audio_receive_rate = |
| 151 (audio_bytes_received_after - audio_bytes_received_before) / | 166 (audio_bytes_received_after - audio_bytes_received_before) / |
| 152 measure_duration_seconds; | 167 measure_duration_seconds; |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 172 | 187 |
| 173 std::string video_codec_modifier = "_" + video_codec; | 188 std::string video_codec_modifier = "_" + video_codec; |
| 174 perf_test::PrintResult( | 189 perf_test::PrintResult( |
| 175 "video", video_codec_modifier, "send_rate", video_send_rate, | 190 "video", video_codec_modifier, "send_rate", video_send_rate, |
| 176 "bytes/second", false); | 191 "bytes/second", false); |
| 177 perf_test::PrintResult( | 192 perf_test::PrintResult( |
| 178 "video", video_codec_modifier, "receive_rate", video_receive_rate, | 193 "video", video_codec_modifier, "receive_rate", video_receive_rate, |
| 179 "bytes/second", false); | 194 "bytes/second", false); |
| 180 } | 195 } |
| 181 | 196 |
| 182 HangUp(left_tab); | 197 EndCall(); |
| 183 HangUp(right_tab); | |
| 184 } | 198 } |
| 199 | |
| 200 void RunsAudioAndVideoCallMeasuringGetStatsPerformance( | |
| 201 GetStatsVariety variety) { | |
| 202 EXPECT_TRUE(base::TimeTicks::IsHighResolution()); | |
|
hta - Chromium
2017/01/23 14:53:52
From the peanut gallery: I see that you are using
hbos_chromium
2017/01/24 12:08:36
I moved the time measurements to the JS layer. Thi
| |
| 203 | |
| 204 StartCall(kUseDefaultAudioCodec, kUseDefaultVideoCodec); | |
| 205 | |
| 206 // Let the call run for 10 seconds to ensure stats not immediately available | |
| 207 // may be collected by our GetStats call. | |
| 208 test::SleepInJavascript(left_tab_, 10000); | |
|
hta - Chromium
2017/01/23 14:53:52
Have you done some subjective testing to see if th
hbos_chromium
2017/01/24 12:08:36
The idea was to get full coverage of stats, things
| |
| 209 | |
| 210 base::TimeTicks ticks_before = base::TimeTicks::Now(); | |
| 211 switch (variety) { | |
| 212 case GetStatsVariety::PROMISE_BASED: | |
| 213 GetStatsAndReturn(left_tab_); | |
|
hta - Chromium
2017/01/23 14:53:52
Won't you get a semi-independent measure of the sa
hbos_chromium
2017/01/24 12:08:36
Done, taking average of left and right tab's getSt
| |
| 214 break; | |
| 215 case GetStatsVariety::CALLBACK_BASED: | |
| 216 GetStatsCallbackAndReturn(left_tab_); | |
| 217 break; | |
| 218 } | |
| 219 base::TimeTicks ticks_after = base::TimeTicks::Now(); | |
| 220 int64_t elapsed_us = (ticks_after - ticks_before).InMicroseconds(); | |
| 221 perf_test::PrintResult( | |
| 222 "getStats", | |
| 223 (variety == GetStatsVariety::PROMISE_BASED) ? "_promise" : "_callback", | |
| 224 "invocation_time", | |
| 225 static_cast<double>(elapsed_us) / | |
| 226 base::Time::kMicrosecondsPerMillisecond, | |
| 227 "milliseconds", | |
| 228 false); | |
| 229 | |
| 230 EndCall(); | |
| 231 } | |
| 232 | |
| 233 private: | |
| 234 content::WebContents* left_tab_ = nullptr; | |
| 235 content::WebContents* right_tab_ = nullptr; | |
| 185 }; | 236 }; |
| 186 | 237 |
| 187 IN_PROC_BROWSER_TEST_F(WebRtcStatsPerfBrowserTest, | 238 IN_PROC_BROWSER_TEST_F( |
| 188 MANUAL_RunsAudioAndVideoCall_AudioCodec_opus) { | 239 WebRtcStatsPerfBrowserTest, |
| 189 RunsAudioAndVideoCall("opus", kUseDefaultVideoCodec); | 240 MANUAL_RunsAudioAndVideoCallCollectingMetrics_AudioCodec_opus) { |
| 241 RunsAudioAndVideoCallCollectingMetrics("opus", kUseDefaultVideoCodec); | |
| 190 } | 242 } |
| 191 | 243 |
| 192 IN_PROC_BROWSER_TEST_F(WebRtcStatsPerfBrowserTest, | 244 IN_PROC_BROWSER_TEST_F( |
| 193 MANUAL_RunsAudioAndVideoCall_AudioCodec_ISAC) { | 245 WebRtcStatsPerfBrowserTest, |
| 194 RunsAudioAndVideoCall("ISAC", kUseDefaultVideoCodec); | 246 MANUAL_RunsAudioAndVideoCallCollectingMetrics_AudioCodec_ISAC) { |
| 247 RunsAudioAndVideoCallCollectingMetrics("ISAC", kUseDefaultVideoCodec); | |
| 195 } | 248 } |
| 196 | 249 |
| 197 IN_PROC_BROWSER_TEST_F(WebRtcStatsPerfBrowserTest, | 250 IN_PROC_BROWSER_TEST_F( |
| 198 MANUAL_RunsAudioAndVideoCall_AudioCodec_G722) { | 251 WebRtcStatsPerfBrowserTest, |
| 199 RunsAudioAndVideoCall("G722", kUseDefaultVideoCodec); | 252 MANUAL_RunsAudioAndVideoCallCollectingMetrics_AudioCodec_G722) { |
| 253 RunsAudioAndVideoCallCollectingMetrics("G722", kUseDefaultVideoCodec); | |
| 200 } | 254 } |
| 201 | 255 |
| 202 IN_PROC_BROWSER_TEST_F(WebRtcStatsPerfBrowserTest, | 256 IN_PROC_BROWSER_TEST_F( |
| 203 MANUAL_RunsAudioAndVideoCall_AudioCodec_PCMU) { | 257 WebRtcStatsPerfBrowserTest, |
| 204 RunsAudioAndVideoCall("PCMU", kUseDefaultVideoCodec); | 258 MANUAL_RunsAudioAndVideoCallCollectingMetrics_AudioCodec_PCMU) { |
| 259 RunsAudioAndVideoCallCollectingMetrics("PCMU", kUseDefaultVideoCodec); | |
| 205 } | 260 } |
| 206 | 261 |
| 207 IN_PROC_BROWSER_TEST_F(WebRtcStatsPerfBrowserTest, | 262 IN_PROC_BROWSER_TEST_F( |
| 208 MANUAL_RunsAudioAndVideoCall_AudioCodec_PCMA) { | 263 WebRtcStatsPerfBrowserTest, |
| 209 RunsAudioAndVideoCall("PCMA", kUseDefaultVideoCodec); | 264 MANUAL_RunsAudioAndVideoCallCollectingMetrics_AudioCodec_PCMA) { |
| 265 RunsAudioAndVideoCallCollectingMetrics("PCMA", kUseDefaultVideoCodec); | |
| 210 } | 266 } |
| 211 | 267 |
| 212 IN_PROC_BROWSER_TEST_F(WebRtcStatsPerfBrowserTest, | 268 IN_PROC_BROWSER_TEST_F( |
| 213 MANUAL_RunsAudioAndVideoCall_VideoCodec_VP8) { | 269 WebRtcStatsPerfBrowserTest, |
| 214 RunsAudioAndVideoCall(kUseDefaultAudioCodec, "VP8"); | 270 MANUAL_RunsAudioAndVideoCallCollectingMetrics_VideoCodec_VP8) { |
| 271 RunsAudioAndVideoCallCollectingMetrics(kUseDefaultAudioCodec, "VP8"); | |
| 215 } | 272 } |
| 216 | 273 |
| 217 IN_PROC_BROWSER_TEST_F(WebRtcStatsPerfBrowserTest, | 274 IN_PROC_BROWSER_TEST_F( |
| 218 MANUAL_RunsAudioAndVideoCall_VideoCodec_VP9) { | 275 WebRtcStatsPerfBrowserTest, |
| 219 RunsAudioAndVideoCall(kUseDefaultAudioCodec, "VP9"); | 276 MANUAL_RunsAudioAndVideoCallCollectingMetrics_VideoCodec_VP9) { |
| 277 RunsAudioAndVideoCallCollectingMetrics(kUseDefaultAudioCodec, "VP9"); | |
| 220 } | 278 } |
| 221 | 279 |
| 222 #if BUILDFLAG(RTC_USE_H264) | 280 #if BUILDFLAG(RTC_USE_H264) |
| 223 | 281 |
| 224 IN_PROC_BROWSER_TEST_F(WebRtcStatsPerfBrowserTest, | 282 IN_PROC_BROWSER_TEST_F( |
| 225 MANUAL_RunsAudioAndVideoCall_VideoCodec_H264) { | 283 WebRtcStatsPerfBrowserTest, |
| 284 MANUAL_RunsAudioAndVideoCallCollectingMetrics_VideoCodec_H264) { | |
| 226 // Only run test if run-time feature corresponding to |rtc_use_h264| is on. | 285 // Only run test if run-time feature corresponding to |rtc_use_h264| is on. |
| 227 if (!base::FeatureList::IsEnabled(content::kWebRtcH264WithOpenH264FFmpeg)) { | 286 if (!base::FeatureList::IsEnabled(content::kWebRtcH264WithOpenH264FFmpeg)) { |
| 228 LOG(WARNING) << "Run-time feature WebRTC-H264WithOpenH264FFmpeg disabled. " | 287 LOG(WARNING) << "Run-time feature WebRTC-H264WithOpenH264FFmpeg disabled. " |
| 229 "Skipping WebRtcPerfBrowserTest." | 288 "Skipping WebRtcPerfBrowserTest." |
| 230 "MANUAL_RunsAudioAndVideoCall_VideoCodec_H264 (test \"OK\")"; | 289 "MANUAL_RunsAudioAndVideoCallCollectingMetrics_VideoCodec_H264 (test " |
| 290 "\"OK\")"; | |
| 231 return; | 291 return; |
| 232 } | 292 } |
| 233 RunsAudioAndVideoCall(kUseDefaultAudioCodec, "H264"); | 293 RunsAudioAndVideoCallCollectingMetrics(kUseDefaultAudioCodec, "H264"); |
| 234 } | 294 } |
| 235 | 295 |
| 236 #endif // BUILDFLAG(RTC_USE_H264) | 296 #endif // BUILDFLAG(RTC_USE_H264) |
| 237 | 297 |
| 298 IN_PROC_BROWSER_TEST_F( | |
| 299 WebRtcStatsPerfBrowserTest, | |
| 300 MANUAL_RunsAudioAndVideoCallMeasuringGetStatsPerformance_Promise) { | |
| 301 RunsAudioAndVideoCallMeasuringGetStatsPerformance( | |
| 302 GetStatsVariety::PROMISE_BASED); | |
| 303 } | |
| 304 | |
| 305 IN_PROC_BROWSER_TEST_F( | |
| 306 WebRtcStatsPerfBrowserTest, | |
| 307 MANUAL_RunsAudioAndVideoCallMeasuringGetStatsPerformance_Callback) { | |
| 308 RunsAudioAndVideoCallMeasuringGetStatsPerformance( | |
| 309 GetStatsVariety::CALLBACK_BASED); | |
| 310 } | |
| 311 | |
| 238 } // namespace | 312 } // namespace |
| 239 | 313 |
| 240 } // namespace content | 314 } // namespace content |
| OLD | NEW |