1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352
|
// Copyright 2016 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <string>
#include "base/command_line.h"
#include "base/memory/raw_ptr.h"
#include "base/test/test_timeouts.h"
#include "base/threading/thread_restrictions.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "chrome/browser/media/webrtc/test_stats_dictionary.h"
#include "chrome/browser/media/webrtc/webrtc_browsertest_base.h"
#include "chrome/browser/media/webrtc/webrtc_browsertest_common.h"
#include "content/public/common/content_switches.h"
#include "content/public/test/browser_test.h"
#include "media/base/media_switches.h"
#include "testing/perf/perf_test.h"
#include "third_party/blink/public/common/features.h"
namespace content {
namespace {
const char kMainWebrtcTestHtmlPage[] = "/webrtc/webrtc_jsep01_test.html";
const char kInboundRtp[] = "inbound-rtp";
const char kOutboundRtp[] = "outbound-rtp";
// Sums up "RTC[In/Out]boundRTPStreamStats.bytes_[received/sent]" values.
double GetTotalRTPStreamBytes(
TestStatsReportDictionary* report, const char* type,
const char* media_type) {
DCHECK(type == kInboundRtp || type == kOutboundRtp);
const char* bytes_name =
(type == kInboundRtp) ? "bytesReceived" : "bytesSent";
double total_bytes = 0.0;
report->ForEach([&type, &bytes_name, &media_type, &total_bytes](
const TestStatsDictionary& stats) {
if (stats.GetString("type") == type &&
stats.GetString("mediaType") == media_type) {
total_bytes += stats.GetNumber(bytes_name);
}
});
return total_bytes;
}
double GetAudioBytesSent(TestStatsReportDictionary* report) {
return GetTotalRTPStreamBytes(report, kOutboundRtp, "audio");
}
double GetAudioBytesReceived(TestStatsReportDictionary* report) {
return GetTotalRTPStreamBytes(report, kInboundRtp, "audio");
}
double GetVideoBytesSent(TestStatsReportDictionary* report) {
return GetTotalRTPStreamBytes(report, kOutboundRtp, "video");
}
double GetVideoBytesReceived(TestStatsReportDictionary* report) {
return GetTotalRTPStreamBytes(report, kInboundRtp, "video");
}
// Performance browsertest for WebRTC. This test is manual since it takes long
// to execute and requires the reference files provided by the webrtc.DEPS
// solution (which is only available on WebRTC internal bots).
// Gets its metrics from the standards conformant "RTCPeerConnection.getStats".
class WebRtcStatsPerfBrowserTest : public WebRtcTestBase {
public:
void SetUpInProcessBrowserTestFixture() override {
DetectErrorsInJavaScript();
}
void SetUpCommandLine(base::CommandLine* command_line) override {
// Ensure the infobar is enabled, since we expect that in this test.
EXPECT_FALSE(command_line->HasSwitch(switches::kUseFakeUIForMediaStream));
// Play a suitable, somewhat realistic video file.
base::FilePath input_video = test::GetReferenceFilesDir()
.Append(test::kReferenceFileName360p)
.AddExtension(test::kY4mFileExtension);
command_line->AppendSwitchPath(switches::kUseFileForFakeVideoCapture,
input_video);
}
void StartCall(const std::string& audio_codec,
const std::string& video_codec,
bool prefer_hw_video_codec,
const std::string& video_codec_profile) {
ASSERT_TRUE(test::HasReferenceFilesInCheckout());
ASSERT_TRUE(embedded_test_server()->Start());
ASSERT_GE(TestTimeouts::test_launcher_timeout().InSeconds(), 100)
<< "This is a long-running test; you must specify "
"--test-launcher-timeout to have a value of at least 100000.";
ASSERT_GE(TestTimeouts::action_max_timeout().InSeconds(), 100)
<< "This is a long-running test; you must specify "
"--ui-test-action-max-timeout to have a value of at least 100000.";
ASSERT_LT(TestTimeouts::action_max_timeout(),
TestTimeouts::test_launcher_timeout())
<< "action_max_timeout needs to be strictly-less-than "
"test_launcher_timeout";
left_tab_ = OpenTestPageAndGetUserMediaInNewTab(kMainWebrtcTestHtmlPage);
right_tab_ = OpenTestPageAndGetUserMediaInNewTab(kMainWebrtcTestHtmlPage);
SetupPeerconnectionWithLocalStream(left_tab_);
SetupPeerconnectionWithLocalStream(right_tab_);
SetDefaultAudioCodec(left_tab_, audio_codec);
SetDefaultAudioCodec(right_tab_, audio_codec);
SetDefaultVideoCodec(left_tab_, video_codec, prefer_hw_video_codec,
video_codec_profile);
SetDefaultVideoCodec(right_tab_, video_codec, prefer_hw_video_codec,
video_codec_profile);
CreateDataChannel(left_tab_, "data");
CreateDataChannel(right_tab_, "data");
NegotiateCall(left_tab_, right_tab_);
StartDetectingVideo(left_tab_, "remote-view");
StartDetectingVideo(right_tab_, "remote-view");
WaitForVideoToPlay(left_tab_);
WaitForVideoToPlay(right_tab_);
}
void EndCall() {
if (left_tab_)
HangUp(left_tab_);
if (right_tab_)
HangUp(right_tab_);
}
void RunsAudioAndVideoCallCollectingMetricsWithAudioCodec(
const std::string& audio_codec) {
RunsAudioAndVideoCallCollectingMetrics(
audio_codec, kUseDefaultVideoCodec, false /* prefer_hw_video_codec */,
"" /* video_codec_profile */, "" /* video_codec_print_modifier */);
}
void RunsAudioAndVideoCallCollectingMetricsWithVideoCodec(
const std::string& video_codec,
bool prefer_hw_video_codec = false,
const std::string& video_codec_profile = std::string(),
const std::string& video_codec_print_modifier = std::string()) {
RunsAudioAndVideoCallCollectingMetrics(
kUseDefaultAudioCodec, video_codec, prefer_hw_video_codec,
video_codec_profile, video_codec_print_modifier);
}
void RunsAudioAndVideoCallCollectingMetrics(
const std::string& audio_codec,
const std::string& video_codec,
bool prefer_hw_video_codec,
const std::string& video_codec_profile,
const std::string& video_codec_print_modifier) {
StartCall(audio_codec, video_codec, prefer_hw_video_codec,
video_codec_profile);
// Call for 60 seconds so that values may stabilize, bandwidth ramp up, etc.
test::SleepInJavascript(left_tab_, 60000);
// The ramp-up may vary greatly and impact the resulting total bytes, to get
// reliable measurements we do two measurements, at 60 and 70 seconds and
// look at the average bytes/second in that window.
double audio_bytes_sent_before = 0.0;
double audio_bytes_received_before = 0.0;
double video_bytes_sent_before = 0.0;
double video_bytes_received_before = 0.0;
scoped_refptr<TestStatsReportDictionary> report =
GetStatsReportDictionary(left_tab_);
if (audio_codec != kUseDefaultAudioCodec) {
audio_bytes_sent_before = GetAudioBytesSent(report.get());
audio_bytes_received_before = GetAudioBytesReceived(report.get());
}
if (video_codec != kUseDefaultVideoCodec) {
video_bytes_sent_before = GetVideoBytesSent(report.get());
video_bytes_received_before = GetVideoBytesReceived(report.get());
}
double measure_duration_seconds = 10.0;
test::SleepInJavascript(left_tab_, static_cast<int>(
measure_duration_seconds * base::Time::kMillisecondsPerSecond));
report = GetStatsReportDictionary(left_tab_);
if (audio_codec != kUseDefaultAudioCodec) {
double audio_bytes_sent_after = GetAudioBytesSent(report.get());
double audio_bytes_received_after = GetAudioBytesReceived(report.get());
double audio_send_rate =
(audio_bytes_sent_after - audio_bytes_sent_before) /
measure_duration_seconds;
double audio_receive_rate =
(audio_bytes_received_after - audio_bytes_received_before) /
measure_duration_seconds;
std::string audio_codec_modifier = "_" + audio_codec;
perf_test::PrintResult(
"audio", audio_codec_modifier, "send_rate", audio_send_rate,
"bytes/second", false);
perf_test::PrintResult(
"audio", audio_codec_modifier, "receive_rate", audio_receive_rate,
"bytes/second", false);
}
if (video_codec != kUseDefaultVideoCodec) {
double video_bytes_sent_after = GetVideoBytesSent(report.get());
double video_bytes_received_after = GetVideoBytesReceived(report.get());
double video_send_rate =
(video_bytes_sent_after - video_bytes_sent_before) /
measure_duration_seconds;
double video_receive_rate =
(video_bytes_received_after - video_bytes_received_before) /
measure_duration_seconds;
std::string video_codec_modifier =
"_" + (video_codec_print_modifier.empty()
? video_codec
: video_codec_print_modifier);
perf_test::PrintResult("video", video_codec_modifier, "send_rate",
video_send_rate, "bytes/second", false);
perf_test::PrintResult(
"video", video_codec_modifier, "receive_rate", video_receive_rate,
"bytes/second", false);
}
EndCall();
}
void RunsAudioAndVideoCallMeasuringGetStatsPerformance() {
EXPECT_TRUE(base::TimeTicks::IsHighResolution());
StartCall(kUseDefaultAudioCodec, kUseDefaultVideoCodec,
false /* prefer_hw_video_codec */, "");
double invocation_time = (MeasureGetStatsPerformance(left_tab_) +
MeasureGetStatsPerformance(right_tab_)) /
2.0;
perf_test::PrintResult("getStats", "_promise", "invocation_time",
invocation_time, "milliseconds", false);
EndCall();
}
private:
raw_ptr<content::WebContents> left_tab_ = nullptr;
raw_ptr<content::WebContents> right_tab_ = nullptr;
};
IN_PROC_BROWSER_TEST_F(
WebRtcStatsPerfBrowserTest,
MANUAL_RunsAudioAndVideoCallCollectingMetrics_AudioCodec_opus) {
base::ScopedAllowBlockingForTesting allow_blocking;
RunsAudioAndVideoCallCollectingMetricsWithAudioCodec("opus");
}
IN_PROC_BROWSER_TEST_F(
WebRtcStatsPerfBrowserTest,
MANUAL_RunsAudioAndVideoCallCollectingMetrics_AudioCodec_G722) {
base::ScopedAllowBlockingForTesting allow_blocking;
RunsAudioAndVideoCallCollectingMetricsWithAudioCodec("G722");
}
IN_PROC_BROWSER_TEST_F(
WebRtcStatsPerfBrowserTest,
MANUAL_RunsAudioAndVideoCallCollectingMetrics_AudioCodec_PCMU) {
base::ScopedAllowBlockingForTesting allow_blocking;
RunsAudioAndVideoCallCollectingMetricsWithAudioCodec("PCMU");
}
IN_PROC_BROWSER_TEST_F(
WebRtcStatsPerfBrowserTest,
MANUAL_RunsAudioAndVideoCallCollectingMetrics_AudioCodec_PCMA) {
base::ScopedAllowBlockingForTesting allow_blocking;
RunsAudioAndVideoCallCollectingMetricsWithAudioCodec("PCMA");
}
IN_PROC_BROWSER_TEST_F(
WebRtcStatsPerfBrowserTest,
MANUAL_RunsAudioAndVideoCallCollectingMetrics_VideoCodec_VP8) {
base::ScopedAllowBlockingForTesting allow_blocking;
RunsAudioAndVideoCallCollectingMetricsWithVideoCodec("VP8");
}
IN_PROC_BROWSER_TEST_F(
WebRtcStatsPerfBrowserTest,
MANUAL_RunsAudioAndVideoCallCollectingMetrics_VideoCodec_VP9) {
base::ScopedAllowBlockingForTesting allow_blocking;
RunsAudioAndVideoCallCollectingMetricsWithVideoCodec("VP9");
}
// TODO(crbug.com/40194627): test fails on some mac bots.
#if BUILDFLAG(IS_MAC)
#define MAYBE_MANUAL_RunsAudioAndVideoCallCollectingMetrics_VideoCodec_VP9Profile2 \
DISABLED_MANUAL_RunsAudioAndVideoCallCollectingMetrics_VideoCodec_VP9Profile2
#else
#define MAYBE_MANUAL_RunsAudioAndVideoCallCollectingMetrics_VideoCodec_VP9Profile2 \
MANUAL_RunsAudioAndVideoCallCollectingMetrics_VideoCodec_VP9Profile2
#endif
IN_PROC_BROWSER_TEST_F(
WebRtcStatsPerfBrowserTest,
MAYBE_MANUAL_RunsAudioAndVideoCallCollectingMetrics_VideoCodec_VP9Profile2) {
base::ScopedAllowBlockingForTesting allow_blocking;
RunsAudioAndVideoCallCollectingMetricsWithVideoCodec(
"VP9", true /* prefer_hw_video_codec */,
WebRtcTestBase::kVP9Profile2Specifier, "VP9p2");
}
#if BUILDFLAG(RTC_USE_H264)
// TODO(crbug.com/359253692): test fails on some mac bots.
#if BUILDFLAG(IS_MAC)
#define MAYBE_MANUAL_RunsAudioAndVideoCallCollectingMetrics_VideoCodec_H264 \
DISABLED_MANUAL_RunsAudioAndVideoCallCollectingMetrics_VideoCodec_H264
#else
#define MAYBE_MANUAL_RunsAudioAndVideoCallCollectingMetrics_VideoCodec_H264 \
MANUAL_RunsAudioAndVideoCallCollectingMetrics_VideoCodec_H264
#endif
IN_PROC_BROWSER_TEST_F(
WebRtcStatsPerfBrowserTest,
MAYBE_MANUAL_RunsAudioAndVideoCallCollectingMetrics_VideoCodec_H264) {
base::ScopedAllowBlockingForTesting allow_blocking;
// Only run test if run-time feature corresponding to |rtc_use_h264| is on.
if (!base::FeatureList::IsEnabled(
blink::features::kWebRtcH264WithOpenH264FFmpeg)) {
LOG(WARNING) << "Run-time feature WebRTC-H264WithOpenH264FFmpeg disabled. "
"Skipping WebRtcPerfBrowserTest."
"MANUAL_RunsAudioAndVideoCallCollectingMetrics_VideoCodec_"
"H264 (test "
"\"OK\")";
return;
}
RunsAudioAndVideoCallCollectingMetricsWithVideoCodec(
"H264", true /* prefer_hw_video_codec */);
}
#endif // BUILDFLAG(RTC_USE_H264)
IN_PROC_BROWSER_TEST_F(
WebRtcStatsPerfBrowserTest,
MANUAL_RunsAudioAndVideoCallMeasuringGetStatsPerformance_Promise) {
base::ScopedAllowBlockingForTesting allow_blocking;
RunsAudioAndVideoCallMeasuringGetStatsPerformance();
}
} // namespace
} // namespace content
|