Chromium Code Reviews| 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 "chrome/browser/media/webrtc/rtc_stats_dictionary.h" | |
| 10 #include "chrome/browser/media/webrtc/webrtc_browsertest_base.h" | |
| 11 #include "chrome/browser/media/webrtc/webrtc_browsertest_common.h" | |
| 12 #include "content/public/common/content_switches.h" | |
| 13 #include "content/public/common/feature_h264_with_openh264_ffmpeg.h" | |
| 14 #include "media/base/media_switches.h" | |
| 15 #include "testing/perf/perf_test.h" | |
| 16 | |
| 17 namespace content { | |
| 18 | |
| 19 namespace { | |
| 20 | |
| 21 const char kMainWebrtcTestHtmlPage[] = "/webrtc/webrtc_jsep01_test.html"; | |
| 22 | |
| 23 // Sums up "RTC[In/Out]boundRTPStreamStats.bytes_[received/sent]" values. | |
| 24 double GetTotalRTPStreamBytes( | |
| 25 RTCStatsReportDictionary* report, bool inbound, const char* media_type) { | |
|
hta - Chromium
2016/12/05 09:07:16
would actually like this better if the "inbound" p
hbos_chromium
2016/12/05 09:41:58
Done.
| |
| 26 const char* type = inbound ? "inbound-rtp" : "outbound-rtp"; | |
| 27 const char* bytes_name = inbound ? "bytesReceived" : "bytesSent"; | |
| 28 double total_bytes = 0.0; | |
| 29 report->ForEach([&type, &bytes_name, &media_type, &total_bytes]( | |
| 30 const RTCStatsDictionary& stats) { | |
| 31 if (stats.GetString("type") == type && | |
| 32 stats.GetString("mediaType") == media_type) { | |
| 33 total_bytes += stats.GetNumber(bytes_name); | |
| 34 } | |
| 35 }); | |
| 36 return total_bytes; | |
| 37 } | |
| 38 | |
| 39 double GetAudioBytesSent(RTCStatsReportDictionary* report) { | |
| 40 return GetTotalRTPStreamBytes(report, false, "audio"); | |
| 41 } | |
| 42 | |
| 43 double GetAudioBytesReceived(RTCStatsReportDictionary* report) { | |
| 44 return GetTotalRTPStreamBytes(report, true, "audio"); | |
| 45 } | |
| 46 | |
| 47 double GetVideoBytesSent(RTCStatsReportDictionary* report) { | |
| 48 return GetTotalRTPStreamBytes(report, false, "video"); | |
| 49 } | |
| 50 | |
| 51 double GetVideoBytesReceived(RTCStatsReportDictionary* report) { | |
| 52 return GetTotalRTPStreamBytes(report, true, "video"); | |
| 53 } | |
| 54 | |
| 55 // This is different from |WebRtcPerfBrowserTest| in that it uses the | |
| 56 // promise-based "RTCPeerConnection.getStats" (as opposed to | |
| 57 // "chrome://webrtc-internals/"). The stats provided are different. | |
|
hta - Chromium
2016/12/05 09:07:16
s/different/standards conformant/. Be proud!
hbos_chromium
2016/12/05 09:41:58
:D
| |
| 58 class WebRtcPerformanceBrowserTest : public WebRtcTestBase { | |
| 59 public: | |
| 60 void SetUpInProcessBrowserTestFixture() override { | |
| 61 DetectErrorsInJavaScript(); | |
| 62 } | |
| 63 | |
| 64 void SetUpCommandLine(base::CommandLine* command_line) override { | |
| 65 // Ensure the infobar is enabled, since we expect that in this test. | |
| 66 EXPECT_FALSE(command_line->HasSwitch(switches::kUseFakeUIForMediaStream)); | |
| 67 | |
| 68 // Play a suitable, somewhat realistic video file. | |
| 69 base::FilePath input_video = test::GetReferenceFilesDir() | |
| 70 .Append(test::kReferenceFileName360p) | |
| 71 .AddExtension(test::kY4mFileExtension); | |
| 72 command_line->AppendSwitchPath(switches::kUseFileForFakeVideoCapture, | |
| 73 input_video); | |
| 74 command_line->AppendSwitch(switches::kUseFakeDeviceForMediaStream); | |
| 75 | |
| 76 command_line->AppendSwitchASCII(switches::kEnableBlinkFeatures, | |
| 77 "RTCPeerConnectionNewGetStats"); | |
| 78 } | |
| 79 | |
| 80 void RunsAudioAndVideoCallFor60Secs( | |
| 81 const std::string& audio_codec, const std::string& video_codec) { | |
| 82 ASSERT_TRUE(test::HasReferenceFilesInCheckout()); | |
| 83 ASSERT_TRUE(embedded_test_server()->Start()); | |
| 84 | |
| 85 ASSERT_GE(TestTimeouts::action_max_timeout().InSeconds(), 100) | |
| 86 << "This is a long-running test; you must specify " | |
| 87 "--ui-test-action-max-timeout to have a value of at least 100000."; | |
| 88 | |
| 89 content::WebContents* left_tab = | |
| 90 OpenTestPageAndGetUserMediaInNewTab(kMainWebrtcTestHtmlPage); | |
| 91 content::WebContents* right_tab = | |
| 92 OpenTestPageAndGetUserMediaInNewTab(kMainWebrtcTestHtmlPage); | |
| 93 | |
| 94 SetupPeerconnectionWithLocalStream(left_tab); | |
| 95 SetupPeerconnectionWithLocalStream(right_tab); | |
| 96 SetDefaultAudioCodec(left_tab, audio_codec); | |
| 97 SetDefaultAudioCodec(right_tab, audio_codec); | |
| 98 SetDefaultVideoCodec(left_tab, video_codec); | |
| 99 SetDefaultVideoCodec(right_tab, video_codec); | |
| 100 NegotiateCall(left_tab, right_tab); | |
| 101 StartDetectingVideo(left_tab, "remote-view"); | |
| 102 StartDetectingVideo(right_tab, "remote-view"); | |
| 103 WaitForVideoToPlay(left_tab); | |
| 104 WaitForVideoToPlay(right_tab); | |
| 105 | |
| 106 // Let call last for 60 seconds so that values may stabilize, bandwidth can | |
| 107 // ramp up, etc. | |
| 108 test::SleepInJavascript(left_tab, 60000); | |
| 109 | |
| 110 scoped_refptr<RTCStatsReportDictionary> report = | |
| 111 GetStatsReportDictionary(left_tab); | |
| 112 | |
| 113 if (audio_codec != kUseDefaultAudioCodec) { | |
| 114 double audio_bytes_sent = GetAudioBytesSent(report.get()); | |
| 115 double audio_bytes_received = GetAudioBytesReceived(report.get()); | |
| 116 | |
| 117 std::string audio_codec_modifier = "_" + audio_codec; | |
| 118 perf_test::PrintResult( | |
| 119 "audio", audio_codec_modifier, "bytes_sent", audio_bytes_sent, | |
| 120 "bytes", false); | |
| 121 perf_test::PrintResult( | |
| 122 "audio", audio_codec_modifier, "bytes_received", audio_bytes_received, | |
| 123 "bytes", false); | |
| 124 } | |
| 125 | |
| 126 if (video_codec != kUseDefaultVideoCodec) { | |
| 127 double video_bytes_sent = GetVideoBytesSent(report.get()); | |
| 128 double video_bytes_received = GetVideoBytesReceived(report.get()); | |
| 129 | |
| 130 std::string video_codec_modifier = "_" + video_codec; | |
| 131 perf_test::PrintResult( | |
| 132 "video", video_codec_modifier, "bytes_sent", video_bytes_sent, | |
| 133 "bytes", false); | |
| 134 perf_test::PrintResult( | |
| 135 "video", video_codec_modifier, "bytes_received", video_bytes_received, | |
| 136 "bytes", false); | |
| 137 } | |
| 138 | |
| 139 HangUp(left_tab); | |
| 140 HangUp(right_tab); | |
| 141 } | |
| 142 }; | |
| 143 | |
| 144 IN_PROC_BROWSER_TEST_F(WebRtcPerformanceBrowserTest, | |
| 145 MANUAL_RunsAudioAndVideoCallFor60Secs_AudioCodec_opus) { | |
| 146 RunsAudioAndVideoCallFor60Secs("opus", kUseDefaultVideoCodec); | |
| 147 } | |
| 148 | |
| 149 IN_PROC_BROWSER_TEST_F(WebRtcPerformanceBrowserTest, | |
| 150 MANUAL_RunsAudioAndVideoCallFor60Secs_AudioCodec_ISAC) { | |
| 151 RunsAudioAndVideoCallFor60Secs("ISAC", kUseDefaultVideoCodec); | |
| 152 } | |
| 153 | |
| 154 IN_PROC_BROWSER_TEST_F(WebRtcPerformanceBrowserTest, | |
| 155 MANUAL_RunsAudioAndVideoCallFor60Secs_AudioCodec_G722) { | |
| 156 RunsAudioAndVideoCallFor60Secs("G722", kUseDefaultVideoCodec); | |
| 157 } | |
| 158 | |
| 159 IN_PROC_BROWSER_TEST_F(WebRtcPerformanceBrowserTest, | |
| 160 MANUAL_RunsAudioAndVideoCallFor60Secs_AudioCodec_PCMU) { | |
| 161 RunsAudioAndVideoCallFor60Secs("PCMU", kUseDefaultVideoCodec); | |
| 162 } | |
| 163 | |
| 164 IN_PROC_BROWSER_TEST_F(WebRtcPerformanceBrowserTest, | |
| 165 MANUAL_RunsAudioAndVideoCallFor60Secs_AudioCodec_PCMA) { | |
| 166 RunsAudioAndVideoCallFor60Secs("PCMA", kUseDefaultVideoCodec); | |
| 167 } | |
| 168 | |
| 169 IN_PROC_BROWSER_TEST_F(WebRtcPerformanceBrowserTest, | |
| 170 MANUAL_RunsAudioAndVideoCallFor60Secs_VideoCodec_VP8) { | |
| 171 RunsAudioAndVideoCallFor60Secs(kUseDefaultAudioCodec, "VP8"); | |
| 172 } | |
| 173 | |
| 174 IN_PROC_BROWSER_TEST_F(WebRtcPerformanceBrowserTest, | |
| 175 MANUAL_RunsAudioAndVideoCallFor60Secs_VideoCodec_VP9) { | |
| 176 RunsAudioAndVideoCallFor60Secs(kUseDefaultAudioCodec, "VP9"); | |
| 177 } | |
| 178 | |
| 179 #if BUILDFLAG(RTC_USE_H264) | |
| 180 | |
| 181 IN_PROC_BROWSER_TEST_F(WebRtcPerformanceBrowserTest, | |
| 182 MANUAL_RunsAudioAndVideoCallFor60Secs_VideoCodec_H264) { | |
| 183 // Only run test if run-time feature corresponding to |rtc_use_h264| is on. | |
| 184 if (!base::FeatureList::IsEnabled(content::kWebRtcH264WithOpenH264FFmpeg)) { | |
| 185 LOG(WARNING) << "Run-time feature WebRTC-H264WithOpenH264FFmpeg disabled. " | |
| 186 "Skipping WebRtcPerfBrowserTest." | |
| 187 "MANUAL_RunsAudioAndVideoCallFor60Secs_VideoCodec_H264 (test \"OK\")"; | |
| 188 return; | |
| 189 } | |
| 190 RunsAudioAndVideoCallFor60Secs(kUseDefaultAudioCodec, "H264"); | |
| 191 } | |
| 192 | |
| 193 #endif // BUILDFLAG(RTC_USE_H264) | |
| 194 | |
| 195 } // namespace | |
| 196 | |
| 197 } // namespace content | |
| OLD | NEW |