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 GetStatsVariation { | |
| 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 CreateDataChannel(left_tab_, "data"); |
| 110 StartDetectingVideo(left_tab, "remote-view"); | 111 CreateDataChannel(right_tab_, "data"); |
|
hta - Chromium
2017/01/26 08:13:58
I appreciate that creating data channels gives mor
hbos_chromium
2017/01/27 14:07:56
Nah, doesn't matter. I could add an argument to sp
| |
| 111 StartDetectingVideo(right_tab, "remote-view"); | 112 NegotiateCall(left_tab_, right_tab_); |
| 112 WaitForVideoToPlay(left_tab); | 113 StartDetectingVideo(left_tab_, "remote-view"); |
| 113 WaitForVideoToPlay(right_tab); | 114 StartDetectingVideo(right_tab_, "remote-view"); |
| 115 WaitForVideoToPlay(left_tab_); | |
| 116 WaitForVideoToPlay(right_tab_); | |
| 117 } | |
| 118 | |
| 119 void EndCall() { | |
| 120 if (left_tab_) | |
| 121 HangUp(left_tab_); | |
| 122 if (right_tab_) | |
| 123 HangUp(right_tab_); | |
| 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 GetStatsVariation variation) { | |
| 202 EXPECT_TRUE(base::TimeTicks::IsHighResolution()); | |
| 203 | |
| 204 StartCall(kUseDefaultAudioCodec, kUseDefaultVideoCodec); | |
| 205 | |
| 206 double invocation_time = 0.0; | |
| 207 switch (variation) { | |
| 208 case GetStatsVariation::PROMISE_BASED: | |
| 209 invocation_time = (MeasureGetStatsPerformance(left_tab_) + | |
| 210 MeasureGetStatsPerformance(right_tab_)) / 2.0; | |
| 211 break; | |
| 212 case GetStatsVariation::CALLBACK_BASED: | |
| 213 invocation_time = | |
| 214 (MeasureGetStatsCallbackPerformance(left_tab_) + | |
| 215 MeasureGetStatsCallbackPerformance(right_tab_)) / 2.0; | |
| 216 break; | |
| 217 } | |
| 218 perf_test::PrintResult( | |
| 219 "getStats", | |
| 220 (variation == GetStatsVariation::PROMISE_BASED) ? | |
| 221 "_promise" : "_callback", | |
| 222 "invocation_time", | |
| 223 invocation_time, | |
| 224 "milliseconds", | |
| 225 false); | |
| 226 | |
| 227 EndCall(); | |
| 228 } | |
| 229 | |
| 230 private: | |
| 231 content::WebContents* left_tab_ = nullptr; | |
| 232 content::WebContents* right_tab_ = nullptr; | |
| 185 }; | 233 }; |
| 186 | 234 |
| 187 IN_PROC_BROWSER_TEST_F(WebRtcStatsPerfBrowserTest, | 235 IN_PROC_BROWSER_TEST_F( |
| 188 MANUAL_RunsAudioAndVideoCall_AudioCodec_opus) { | 236 WebRtcStatsPerfBrowserTest, |
| 189 RunsAudioAndVideoCall("opus", kUseDefaultVideoCodec); | 237 MANUAL_RunsAudioAndVideoCallCollectingMetrics_AudioCodec_opus) { |
| 238 RunsAudioAndVideoCallCollectingMetrics("opus", kUseDefaultVideoCodec); | |
| 190 } | 239 } |
| 191 | 240 |
| 192 IN_PROC_BROWSER_TEST_F(WebRtcStatsPerfBrowserTest, | 241 IN_PROC_BROWSER_TEST_F( |
| 193 MANUAL_RunsAudioAndVideoCall_AudioCodec_ISAC) { | 242 WebRtcStatsPerfBrowserTest, |
| 194 RunsAudioAndVideoCall("ISAC", kUseDefaultVideoCodec); | 243 MANUAL_RunsAudioAndVideoCallCollectingMetrics_AudioCodec_ISAC) { |
| 244 RunsAudioAndVideoCallCollectingMetrics("ISAC", kUseDefaultVideoCodec); | |
| 195 } | 245 } |
| 196 | 246 |
| 197 IN_PROC_BROWSER_TEST_F(WebRtcStatsPerfBrowserTest, | 247 IN_PROC_BROWSER_TEST_F( |
| 198 MANUAL_RunsAudioAndVideoCall_AudioCodec_G722) { | 248 WebRtcStatsPerfBrowserTest, |
| 199 RunsAudioAndVideoCall("G722", kUseDefaultVideoCodec); | 249 MANUAL_RunsAudioAndVideoCallCollectingMetrics_AudioCodec_G722) { |
| 250 RunsAudioAndVideoCallCollectingMetrics("G722", kUseDefaultVideoCodec); | |
| 200 } | 251 } |
| 201 | 252 |
| 202 IN_PROC_BROWSER_TEST_F(WebRtcStatsPerfBrowserTest, | 253 IN_PROC_BROWSER_TEST_F( |
| 203 MANUAL_RunsAudioAndVideoCall_AudioCodec_PCMU) { | 254 WebRtcStatsPerfBrowserTest, |
| 204 RunsAudioAndVideoCall("PCMU", kUseDefaultVideoCodec); | 255 MANUAL_RunsAudioAndVideoCallCollectingMetrics_AudioCodec_PCMU) { |
| 256 RunsAudioAndVideoCallCollectingMetrics("PCMU", kUseDefaultVideoCodec); | |
| 205 } | 257 } |
| 206 | 258 |
| 207 IN_PROC_BROWSER_TEST_F(WebRtcStatsPerfBrowserTest, | 259 IN_PROC_BROWSER_TEST_F( |
| 208 MANUAL_RunsAudioAndVideoCall_AudioCodec_PCMA) { | 260 WebRtcStatsPerfBrowserTest, |
| 209 RunsAudioAndVideoCall("PCMA", kUseDefaultVideoCodec); | 261 MANUAL_RunsAudioAndVideoCallCollectingMetrics_AudioCodec_PCMA) { |
| 262 RunsAudioAndVideoCallCollectingMetrics("PCMA", kUseDefaultVideoCodec); | |
| 210 } | 263 } |
| 211 | 264 |
| 212 IN_PROC_BROWSER_TEST_F(WebRtcStatsPerfBrowserTest, | 265 IN_PROC_BROWSER_TEST_F( |
| 213 MANUAL_RunsAudioAndVideoCall_VideoCodec_VP8) { | 266 WebRtcStatsPerfBrowserTest, |
| 214 RunsAudioAndVideoCall(kUseDefaultAudioCodec, "VP8"); | 267 MANUAL_RunsAudioAndVideoCallCollectingMetrics_VideoCodec_VP8) { |
| 268 RunsAudioAndVideoCallCollectingMetrics(kUseDefaultAudioCodec, "VP8"); | |
| 215 } | 269 } |
| 216 | 270 |
| 217 IN_PROC_BROWSER_TEST_F(WebRtcStatsPerfBrowserTest, | 271 IN_PROC_BROWSER_TEST_F( |
| 218 MANUAL_RunsAudioAndVideoCall_VideoCodec_VP9) { | 272 WebRtcStatsPerfBrowserTest, |
| 219 RunsAudioAndVideoCall(kUseDefaultAudioCodec, "VP9"); | 273 MANUAL_RunsAudioAndVideoCallCollectingMetrics_VideoCodec_VP9) { |
| 274 RunsAudioAndVideoCallCollectingMetrics(kUseDefaultAudioCodec, "VP9"); | |
| 220 } | 275 } |
| 221 | 276 |
| 222 #if BUILDFLAG(RTC_USE_H264) | 277 #if BUILDFLAG(RTC_USE_H264) |
| 223 | 278 |
| 224 IN_PROC_BROWSER_TEST_F(WebRtcStatsPerfBrowserTest, | 279 IN_PROC_BROWSER_TEST_F( |
| 225 MANUAL_RunsAudioAndVideoCall_VideoCodec_H264) { | 280 WebRtcStatsPerfBrowserTest, |
| 281 MANUAL_RunsAudioAndVideoCallCollectingMetrics_VideoCodec_H264) { | |
| 226 // Only run test if run-time feature corresponding to |rtc_use_h264| is on. | 282 // Only run test if run-time feature corresponding to |rtc_use_h264| is on. |
| 227 if (!base::FeatureList::IsEnabled(content::kWebRtcH264WithOpenH264FFmpeg)) { | 283 if (!base::FeatureList::IsEnabled(content::kWebRtcH264WithOpenH264FFmpeg)) { |
| 228 LOG(WARNING) << "Run-time feature WebRTC-H264WithOpenH264FFmpeg disabled. " | 284 LOG(WARNING) << "Run-time feature WebRTC-H264WithOpenH264FFmpeg disabled. " |
| 229 "Skipping WebRtcPerfBrowserTest." | 285 "Skipping WebRtcPerfBrowserTest." |
| 230 "MANUAL_RunsAudioAndVideoCall_VideoCodec_H264 (test \"OK\")"; | 286 "MANUAL_RunsAudioAndVideoCallCollectingMetrics_VideoCodec_H264 (test " |
| 287 "\"OK\")"; | |
| 231 return; | 288 return; |
| 232 } | 289 } |
| 233 RunsAudioAndVideoCall(kUseDefaultAudioCodec, "H264"); | 290 RunsAudioAndVideoCallCollectingMetrics(kUseDefaultAudioCodec, "H264"); |
| 234 } | 291 } |
| 235 | 292 |
| 236 #endif // BUILDFLAG(RTC_USE_H264) | 293 #endif // BUILDFLAG(RTC_USE_H264) |
| 237 | 294 |
| 295 IN_PROC_BROWSER_TEST_F( | |
| 296 WebRtcStatsPerfBrowserTest, | |
| 297 MANUAL_RunsAudioAndVideoCallMeasuringGetStatsPerformance_Promise) { | |
| 298 RunsAudioAndVideoCallMeasuringGetStatsPerformance( | |
| 299 GetStatsVariation::PROMISE_BASED); | |
| 300 } | |
| 301 | |
| 302 IN_PROC_BROWSER_TEST_F( | |
| 303 WebRtcStatsPerfBrowserTest, | |
| 304 MANUAL_RunsAudioAndVideoCallMeasuringGetStatsPerformance_Callback) { | |
| 305 RunsAudioAndVideoCallMeasuringGetStatsPerformance( | |
| 306 GetStatsVariation::CALLBACK_BASED); | |
| 307 } | |
| 308 | |
| 238 } // namespace | 309 } // namespace |
| 239 | 310 |
| 240 } // namespace content | 311 } // namespace content |
| OLD | NEW |