OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include <string> |
| 6 |
| 7 #include "base/command_line.h" |
| 8 #include "base/test/test_timeouts.h" |
| 9 #include "base/time/time.h" |
| 10 #include "chrome/browser/media/webrtc/test_stats_dictionary.h" |
| 11 #include "chrome/browser/media/webrtc/webrtc_browsertest_base.h" |
| 12 #include "chrome/browser/media/webrtc/webrtc_browsertest_common.h" |
| 13 #include "content/public/common/content_switches.h" |
| 14 #include "content/public/common/feature_h264_with_openh264_ffmpeg.h" |
| 15 #include "media/base/media_switches.h" |
| 16 #include "testing/perf/perf_test.h" |
| 17 |
| 18 namespace content { |
| 19 |
| 20 namespace { |
| 21 |
| 22 const char kMainWebrtcTestHtmlPage[] = "/webrtc/webrtc_jsep01_test.html"; |
| 23 |
| 24 const char kInboundRtp[] = "inbound-rtp"; |
| 25 const char kOutboundRtp[] = "outbound-rtp"; |
| 26 |
| 27 // Sums up "RTC[In/Out]boundRTPStreamStats.bytes_[received/sent]" values. |
| 28 double GetTotalRTPStreamBytes( |
| 29 TestStatsReportDictionary* report, const char* type, |
| 30 const char* media_type) { |
| 31 DCHECK(type == kInboundRtp || type == kOutboundRtp); |
| 32 const char* bytes_name = |
| 33 (type == kInboundRtp) ? "bytesReceived" : "bytesSent"; |
| 34 double total_bytes = 0.0; |
| 35 report->ForEach([&type, &bytes_name, &media_type, &total_bytes]( |
| 36 const TestStatsDictionary& stats) { |
| 37 if (stats.GetString("type") == type && |
| 38 stats.GetString("mediaType") == media_type) { |
| 39 total_bytes += stats.GetNumber(bytes_name); |
| 40 } |
| 41 }); |
| 42 return total_bytes; |
| 43 } |
| 44 |
| 45 double GetAudioBytesSent(TestStatsReportDictionary* report) { |
| 46 return GetTotalRTPStreamBytes(report, kOutboundRtp, "audio"); |
| 47 } |
| 48 |
| 49 double GetAudioBytesReceived(TestStatsReportDictionary* report) { |
| 50 return GetTotalRTPStreamBytes(report, kInboundRtp, "audio"); |
| 51 } |
| 52 |
| 53 double GetVideoBytesSent(TestStatsReportDictionary* report) { |
| 54 return GetTotalRTPStreamBytes(report, kOutboundRtp, "video"); |
| 55 } |
| 56 |
| 57 double GetVideoBytesReceived(TestStatsReportDictionary* report) { |
| 58 return GetTotalRTPStreamBytes(report, kInboundRtp, "video"); |
| 59 } |
| 60 |
| 61 // Performance browsertest for WebRTC. This test is manual since it takes long |
| 62 // to execute and requires the reference files provided by the webrtc.DEPS |
| 63 // solution (which is only available on WebRTC internal bots). |
| 64 // Gets its metrics from the standards conformant "RTCPeerConnection.getStats". |
| 65 class WebRtcStatsPerfBrowserTest : public WebRtcTestBase { |
| 66 public: |
| 67 void SetUpInProcessBrowserTestFixture() override { |
| 68 DetectErrorsInJavaScript(); |
| 69 } |
| 70 |
| 71 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 72 // Ensure the infobar is enabled, since we expect that in this test. |
| 73 EXPECT_FALSE(command_line->HasSwitch(switches::kUseFakeUIForMediaStream)); |
| 74 |
| 75 // Play a suitable, somewhat realistic video file. |
| 76 base::FilePath input_video = test::GetReferenceFilesDir() |
| 77 .Append(test::kReferenceFileName360p) |
| 78 .AddExtension(test::kY4mFileExtension); |
| 79 command_line->AppendSwitchPath(switches::kUseFileForFakeVideoCapture, |
| 80 input_video); |
| 81 command_line->AppendSwitch(switches::kUseFakeDeviceForMediaStream); |
| 82 |
| 83 command_line->AppendSwitchASCII(switches::kEnableBlinkFeatures, |
| 84 "RTCPeerConnectionNewGetStats"); |
| 85 } |
| 86 |
| 87 void RunsAudioAndVideoCall( |
| 88 const std::string& audio_codec, const std::string& video_codec) { |
| 89 ASSERT_TRUE(test::HasReferenceFilesInCheckout()); |
| 90 ASSERT_TRUE(embedded_test_server()->Start()); |
| 91 ASSERT_TRUE(audio_codec != kUseDefaultAudioCodec || |
| 92 video_codec != kUseDefaultVideoCodec); |
| 93 |
| 94 ASSERT_GE(TestTimeouts::action_max_timeout().InSeconds(), 100) |
| 95 << "This is a long-running test; you must specify " |
| 96 "--ui-test-action-max-timeout to have a value of at least 100000."; |
| 97 |
| 98 content::WebContents* left_tab = |
| 99 OpenTestPageAndGetUserMediaInNewTab(kMainWebrtcTestHtmlPage); |
| 100 content::WebContents* right_tab = |
| 101 OpenTestPageAndGetUserMediaInNewTab(kMainWebrtcTestHtmlPage); |
| 102 |
| 103 SetupPeerconnectionWithLocalStream(left_tab); |
| 104 SetupPeerconnectionWithLocalStream(right_tab); |
| 105 SetDefaultAudioCodec(left_tab, audio_codec); |
| 106 SetDefaultAudioCodec(right_tab, audio_codec); |
| 107 SetDefaultVideoCodec(left_tab, video_codec); |
| 108 SetDefaultVideoCodec(right_tab, video_codec); |
| 109 NegotiateCall(left_tab, right_tab); |
| 110 StartDetectingVideo(left_tab, "remote-view"); |
| 111 StartDetectingVideo(right_tab, "remote-view"); |
| 112 WaitForVideoToPlay(left_tab); |
| 113 WaitForVideoToPlay(right_tab); |
| 114 |
| 115 // Call for 60 seconds so that values may stabilize, bandwidth ramp up, etc. |
| 116 test::SleepInJavascript(left_tab, 60000); |
| 117 |
| 118 // 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 |
| 120 // look at the average bytes/second in that window. |
| 121 double audio_bytes_sent_before = 0.0; |
| 122 double audio_bytes_received_before = 0.0; |
| 123 double video_bytes_sent_before = 0.0; |
| 124 double video_bytes_received_before = 0.0; |
| 125 |
| 126 scoped_refptr<TestStatsReportDictionary> report = |
| 127 GetStatsReportDictionary(left_tab); |
| 128 if (audio_codec != kUseDefaultAudioCodec) { |
| 129 audio_bytes_sent_before = GetAudioBytesSent(report.get()); |
| 130 audio_bytes_received_before = GetAudioBytesReceived(report.get()); |
| 131 |
| 132 } |
| 133 if (video_codec != kUseDefaultVideoCodec) { |
| 134 video_bytes_sent_before = GetVideoBytesSent(report.get()); |
| 135 video_bytes_received_before = GetVideoBytesReceived(report.get()); |
| 136 } |
| 137 |
| 138 double measure_duration_seconds = 10.0; |
| 139 test::SleepInJavascript(left_tab, static_cast<int>( |
| 140 measure_duration_seconds * base::Time::kMillisecondsPerSecond)); |
| 141 |
| 142 report = GetStatsReportDictionary(left_tab); |
| 143 if (audio_codec != kUseDefaultAudioCodec) { |
| 144 double audio_bytes_sent_after = GetAudioBytesSent(report.get()); |
| 145 double audio_bytes_received_after = GetAudioBytesReceived(report.get()); |
| 146 |
| 147 double audio_send_rate = |
| 148 (audio_bytes_sent_after - audio_bytes_sent_before) / |
| 149 measure_duration_seconds; |
| 150 double audio_receive_rate = |
| 151 (audio_bytes_received_after - audio_bytes_received_before) / |
| 152 measure_duration_seconds; |
| 153 |
| 154 std::string audio_codec_modifier = "_" + audio_codec; |
| 155 perf_test::PrintResult( |
| 156 "audio", audio_codec_modifier, "send_rate", audio_send_rate, |
| 157 "bytes/second", false); |
| 158 perf_test::PrintResult( |
| 159 "audio", audio_codec_modifier, "receive_rate", audio_receive_rate, |
| 160 "bytes/second", false); |
| 161 } |
| 162 if (video_codec != kUseDefaultVideoCodec) { |
| 163 double video_bytes_sent_after = GetVideoBytesSent(report.get()); |
| 164 double video_bytes_received_after = GetVideoBytesReceived(report.get()); |
| 165 |
| 166 double video_send_rate = |
| 167 (video_bytes_sent_after - video_bytes_sent_before) / |
| 168 measure_duration_seconds; |
| 169 double video_receive_rate = |
| 170 (video_bytes_received_after - video_bytes_received_before) / |
| 171 measure_duration_seconds; |
| 172 |
| 173 std::string video_codec_modifier = "_" + video_codec; |
| 174 perf_test::PrintResult( |
| 175 "video", video_codec_modifier, "send_rate", video_send_rate, |
| 176 "bytes/second", false); |
| 177 perf_test::PrintResult( |
| 178 "video", video_codec_modifier, "receive_rate", video_receive_rate, |
| 179 "bytes/second", false); |
| 180 } |
| 181 |
| 182 HangUp(left_tab); |
| 183 HangUp(right_tab); |
| 184 } |
| 185 }; |
| 186 |
| 187 IN_PROC_BROWSER_TEST_F(WebRtcStatsPerfBrowserTest, |
| 188 MANUAL_RunsAudioAndVideoCall_AudioCodec_opus) { |
| 189 RunsAudioAndVideoCall("opus", kUseDefaultVideoCodec); |
| 190 } |
| 191 |
| 192 IN_PROC_BROWSER_TEST_F(WebRtcStatsPerfBrowserTest, |
| 193 MANUAL_RunsAudioAndVideoCall_AudioCodec_ISAC) { |
| 194 RunsAudioAndVideoCall("ISAC", kUseDefaultVideoCodec); |
| 195 } |
| 196 |
| 197 IN_PROC_BROWSER_TEST_F(WebRtcStatsPerfBrowserTest, |
| 198 MANUAL_RunsAudioAndVideoCall_AudioCodec_G722) { |
| 199 RunsAudioAndVideoCall("G722", kUseDefaultVideoCodec); |
| 200 } |
| 201 |
| 202 IN_PROC_BROWSER_TEST_F(WebRtcStatsPerfBrowserTest, |
| 203 MANUAL_RunsAudioAndVideoCall_AudioCodec_PCMU) { |
| 204 RunsAudioAndVideoCall("PCMU", kUseDefaultVideoCodec); |
| 205 } |
| 206 |
| 207 IN_PROC_BROWSER_TEST_F(WebRtcStatsPerfBrowserTest, |
| 208 MANUAL_RunsAudioAndVideoCall_AudioCodec_PCMA) { |
| 209 RunsAudioAndVideoCall("PCMA", kUseDefaultVideoCodec); |
| 210 } |
| 211 |
| 212 IN_PROC_BROWSER_TEST_F(WebRtcStatsPerfBrowserTest, |
| 213 MANUAL_RunsAudioAndVideoCall_VideoCodec_VP8) { |
| 214 RunsAudioAndVideoCall(kUseDefaultAudioCodec, "VP8"); |
| 215 } |
| 216 |
| 217 IN_PROC_BROWSER_TEST_F(WebRtcStatsPerfBrowserTest, |
| 218 MANUAL_RunsAudioAndVideoCall_VideoCodec_VP9) { |
| 219 RunsAudioAndVideoCall(kUseDefaultAudioCodec, "VP9"); |
| 220 } |
| 221 |
| 222 #if BUILDFLAG(RTC_USE_H264) |
| 223 |
| 224 IN_PROC_BROWSER_TEST_F(WebRtcStatsPerfBrowserTest, |
| 225 MANUAL_RunsAudioAndVideoCall_VideoCodec_H264) { |
| 226 // Only run test if run-time feature corresponding to |rtc_use_h264| is on. |
| 227 if (!base::FeatureList::IsEnabled(content::kWebRtcH264WithOpenH264FFmpeg)) { |
| 228 LOG(WARNING) << "Run-time feature WebRTC-H264WithOpenH264FFmpeg disabled. " |
| 229 "Skipping WebRtcPerfBrowserTest." |
| 230 "MANUAL_RunsAudioAndVideoCall_VideoCodec_H264 (test \"OK\")"; |
| 231 return; |
| 232 } |
| 233 RunsAudioAndVideoCall(kUseDefaultAudioCodec, "H264"); |
| 234 } |
| 235 |
| 236 #endif // BUILDFLAG(RTC_USE_H264) |
| 237 |
| 238 } // namespace |
| 239 |
| 240 } // namespace content |
OLD | NEW |