OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <ctime> | 5 #include <ctime> |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
10 #include "base/process/launch.h" | 10 #include "base/process/launch.h" |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 // 5. Launch chrome and try playing a video with sound. You should see | 80 // 5. Launch chrome and try playing a video with sound. You should see |
81 // in the volume meter for the mix device. Configure the mix device to have | 81 // in the volume meter for the mix device. Configure the mix device to have |
82 // 50 / 100 in level. Also go into the playback tab, right-click Speakers, | 82 // 50 / 100 in level. Also go into the playback tab, right-click Speakers, |
83 // and set that level to 50 / 100. Otherwise you will get distortion in | 83 // and set that level to 50 / 100. Otherwise you will get distortion in |
84 // the recording. | 84 // the recording. |
85 class WebRtcAudioQualityBrowserTest : public WebRtcTestBase, | 85 class WebRtcAudioQualityBrowserTest : public WebRtcTestBase, |
86 public testing::WithParamInterface<bool> { | 86 public testing::WithParamInterface<bool> { |
87 public: | 87 public: |
88 WebRtcAudioQualityBrowserTest() {} | 88 WebRtcAudioQualityBrowserTest() {} |
89 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { | 89 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { |
90 test::PeerConnectionServerRunner::KillAllPeerConnectionServers(); | |
91 DetectErrorsInJavaScript(); // Look for errors in our rather complex js. | 90 DetectErrorsInJavaScript(); // Look for errors in our rather complex js. |
92 } | 91 } |
93 | 92 |
94 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 93 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
95 // This test expects real device handling and requires a real webcam / audio | 94 // This test expects real device handling and requires a real webcam / audio |
96 // device; it will not work with fake devices. | 95 // device; it will not work with fake devices. |
97 EXPECT_FALSE(command_line->HasSwitch( | 96 EXPECT_FALSE(command_line->HasSwitch( |
98 switches::kUseFakeDeviceForMediaStream)); | 97 switches::kUseFakeDeviceForMediaStream)); |
99 EXPECT_FALSE(command_line->HasSwitch( | 98 EXPECT_FALSE(command_line->HasSwitch( |
100 switches::kUseFakeUIForMediaStream)); | 99 switches::kUseFakeUIForMediaStream)); |
101 | 100 |
102 bool enable_audio_track_processing = GetParam(); | 101 bool enable_audio_track_processing = GetParam(); |
103 if (enable_audio_track_processing) | 102 if (enable_audio_track_processing) |
104 command_line->AppendSwitch(switches::kEnableAudioTrackProcessing); | 103 command_line->AppendSwitch(switches::kEnableAudioTrackProcessing); |
105 } | 104 } |
106 | 105 |
107 void AddAudioFile(const std::string& input_file_relative_url, | 106 void AddAudioFile(const std::string& input_file_relative_url, |
108 content::WebContents* tab_contents) { | 107 content::WebContents* tab_contents) { |
109 EXPECT_EQ("ok-added", ExecuteJavascript( | 108 EXPECT_EQ("ok-added", ExecuteJavascript( |
110 "addAudioFile('" + input_file_relative_url + "')", tab_contents)); | 109 "addAudioFile('" + input_file_relative_url + "')", tab_contents)); |
111 } | 110 } |
112 | 111 |
113 void PlayAudioFile(content::WebContents* tab_contents) { | 112 void PlayAudioFile(content::WebContents* tab_contents) { |
114 EXPECT_EQ("ok-playing", ExecuteJavascript("playAudioFile()", tab_contents)); | 113 EXPECT_EQ("ok-playing", ExecuteJavascript("playAudioFile()", tab_contents)); |
115 } | 114 } |
116 | 115 |
117 void EstablishCall(content::WebContents* from_tab, | |
118 content::WebContents* to_tab) { | |
119 EXPECT_EQ("ok-negotiating", | |
120 ExecuteJavascript("negotiateCall()", from_tab)); | |
121 | |
122 // Ensure the call gets up on both sides. | |
123 EXPECT_TRUE(test::PollingWaitUntil("getPeerConnectionReadyState()", | |
124 "active", from_tab)); | |
125 EXPECT_TRUE(test::PollingWaitUntil("getPeerConnectionReadyState()", | |
126 "active", to_tab)); | |
127 } | |
128 | |
129 base::FilePath CreateTemporaryWaveFile() { | 116 base::FilePath CreateTemporaryWaveFile() { |
130 base::FilePath filename; | 117 base::FilePath filename; |
131 EXPECT_TRUE(base::CreateTemporaryFile(&filename)); | 118 EXPECT_TRUE(base::CreateTemporaryFile(&filename)); |
132 base::FilePath wav_filename = | 119 base::FilePath wav_filename = |
133 filename.AddExtension(FILE_PATH_LITERAL(".wav")); | 120 filename.AddExtension(FILE_PATH_LITERAL(".wav")); |
134 EXPECT_TRUE(base::Move(filename, wav_filename)); | 121 EXPECT_TRUE(base::Move(filename, wav_filename)); |
135 return wav_filename; | 122 return wav_filename; |
136 } | 123 } |
137 | |
138 test::PeerConnectionServerRunner peerconnection_server_; | |
139 }; | 124 }; |
140 | 125 |
141 class AudioRecorder { | 126 class AudioRecorder { |
142 public: | 127 public: |
143 AudioRecorder(): recording_application_(base::kNullProcessHandle) {} | 128 AudioRecorder(): recording_application_(base::kNullProcessHandle) {} |
144 ~AudioRecorder() {} | 129 ~AudioRecorder() {} |
145 | 130 |
146 // Starts the recording program for the specified duration. Returns true | 131 // Starts the recording program for the specified duration. Returns true |
147 // on success. | 132 // on success. |
148 bool StartRecording(int duration_sec, const base::FilePath& output_file, | 133 bool StartRecording(int duration_sec, const base::FilePath& output_file, |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
366 MAYBE_MANUAL_TestAudioQuality) { | 351 MAYBE_MANUAL_TestAudioQuality) { |
367 #if defined(OS_WIN) | 352 #if defined(OS_WIN) |
368 if (base::win::GetVersion() < base::win::VERSION_VISTA) { | 353 if (base::win::GetVersion() < base::win::VERSION_VISTA) { |
369 // It would take work to implement this on XP; not prioritized right now. | 354 // It would take work to implement this on XP; not prioritized right now. |
370 LOG(ERROR) << "This test is not implemented for Windows XP."; | 355 LOG(ERROR) << "This test is not implemented for Windows XP."; |
371 return; | 356 return; |
372 } | 357 } |
373 #endif | 358 #endif |
374 ASSERT_TRUE(test::HasReferenceFilesInCheckout()); | 359 ASSERT_TRUE(test::HasReferenceFilesInCheckout()); |
375 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 360 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
376 ASSERT_TRUE(peerconnection_server_.Start()); | |
377 | 361 |
378 ASSERT_TRUE(ForceMicrophoneVolumeTo100Percent()); | 362 ASSERT_TRUE(ForceMicrophoneVolumeTo100Percent()); |
379 | 363 |
380 ui_test_utils::NavigateToURL( | 364 ui_test_utils::NavigateToURL( |
381 browser(), embedded_test_server()->GetURL(kMainWebrtcTestHtmlPage)); | 365 browser(), embedded_test_server()->GetURL(kMainWebrtcTestHtmlPage)); |
382 content::WebContents* left_tab = | 366 content::WebContents* left_tab = |
383 browser()->tab_strip_model()->GetActiveWebContents(); | 367 browser()->tab_strip_model()->GetActiveWebContents(); |
384 | 368 |
385 chrome::AddTabAt(browser(), GURL(), -1, true); | 369 chrome::AddTabAt(browser(), GURL(), -1, true); |
386 content::WebContents* right_tab = | 370 content::WebContents* right_tab = |
387 browser()->tab_strip_model()->GetActiveWebContents(); | 371 browser()->tab_strip_model()->GetActiveWebContents(); |
388 ui_test_utils::NavigateToURL( | 372 ui_test_utils::NavigateToURL( |
389 browser(), embedded_test_server()->GetURL(kMainWebrtcTestHtmlPage)); | 373 browser(), embedded_test_server()->GetURL(kMainWebrtcTestHtmlPage)); |
390 | 374 |
391 ConnectToPeerConnectionServer("peer 1", left_tab); | 375 // Prepare the peer connections manually in this test since we don't add |
392 ConnectToPeerConnectionServer("peer 2", right_tab); | 376 // getUserMedia-derived media streams in this test like the other tests. |
393 | |
394 EXPECT_EQ("ok-peerconnection-created", | 377 EXPECT_EQ("ok-peerconnection-created", |
395 ExecuteJavascript("preparePeerConnection()", left_tab)); | 378 ExecuteJavascript("preparePeerConnection()", left_tab)); |
| 379 EXPECT_EQ("ok-peerconnection-created", |
| 380 ExecuteJavascript("preparePeerConnection()", right_tab)); |
396 | 381 |
397 AddAudioFile(kReferenceFileRelativeUrl, left_tab); | 382 AddAudioFile(kReferenceFileRelativeUrl, left_tab); |
398 | 383 |
399 EstablishCall(left_tab, right_tab); | 384 NegotiateCall(left_tab, right_tab); |
400 | 385 |
401 // Note: the media flow isn't necessarily established on the connection just | 386 // Note: the media flow isn't necessarily established on the connection just |
402 // because the ready state is ok on both sides. We sleep a bit between call | 387 // because the ready state is ok on both sides. We sleep a bit between call |
403 // establishment and playing to avoid cutting of the beginning of the audio | 388 // establishment and playing to avoid cutting of the beginning of the audio |
404 // file. | 389 // file. |
405 test::SleepInJavascript(left_tab, 2000); | 390 test::SleepInJavascript(left_tab, 2000); |
406 | 391 |
407 base::FilePath recording = CreateTemporaryWaveFile(); | 392 base::FilePath recording = CreateTemporaryWaveFile(); |
408 | 393 |
409 // Note: the sound clip is about 10 seconds: record for 15 seconds to get some | 394 // Note: the sound clip is about 10 seconds: record for 15 seconds to get some |
410 // safety margins on each side. | 395 // safety margins on each side. |
411 AudioRecorder recorder; | 396 AudioRecorder recorder; |
412 static int kRecordingTimeSeconds = 15; | 397 static int kRecordingTimeSeconds = 15; |
413 ASSERT_TRUE(recorder.StartRecording(kRecordingTimeSeconds, recording, true)); | 398 ASSERT_TRUE(recorder.StartRecording(kRecordingTimeSeconds, recording, true)); |
414 | 399 |
415 PlayAudioFile(left_tab); | 400 PlayAudioFile(left_tab); |
416 | 401 |
417 ASSERT_TRUE(recorder.WaitForRecordingToEnd()); | 402 ASSERT_TRUE(recorder.WaitForRecordingToEnd()); |
418 VLOG(0) << "Done recording to " << recording.value() << std::endl; | 403 VLOG(0) << "Done recording to " << recording.value() << std::endl; |
419 | 404 |
420 HangUp(left_tab); | 405 HangUp(left_tab); |
421 WaitUntilHangupVerified(left_tab); | |
422 WaitUntilHangupVerified(right_tab); | |
423 | 406 |
424 base::FilePath trimmed_recording = CreateTemporaryWaveFile(); | 407 base::FilePath trimmed_recording = CreateTemporaryWaveFile(); |
425 | 408 |
426 ASSERT_TRUE(RemoveSilence(recording, trimmed_recording)); | 409 ASSERT_TRUE(RemoveSilence(recording, trimmed_recording)); |
427 VLOG(0) << "Trimmed silence: " << trimmed_recording.value() << std::endl; | 410 VLOG(0) << "Trimmed silence: " << trimmed_recording.value() << std::endl; |
428 | 411 |
429 std::string raw_mos; | 412 std::string raw_mos; |
430 std::string mos_lqo; | 413 std::string mos_lqo; |
431 base::FilePath reference_file_in_test_dir = | 414 base::FilePath reference_file_in_test_dir = |
432 test::GetReferenceFilesDir().Append(kReferenceFile); | 415 test::GetReferenceFilesDir().Append(kReferenceFile); |
433 ASSERT_TRUE(RunPesq(reference_file_in_test_dir, trimmed_recording, 16000, | 416 ASSERT_TRUE(RunPesq(reference_file_in_test_dir, trimmed_recording, 16000, |
434 &raw_mos, &mos_lqo)); | 417 &raw_mos, &mos_lqo)); |
435 | 418 |
436 perf_test::PrintResult("audio_pesq", "", "raw_mos", raw_mos, "score", true); | 419 perf_test::PrintResult("audio_pesq", "", "raw_mos", raw_mos, "score", true); |
437 perf_test::PrintResult("audio_pesq", "", "mos_lqo", mos_lqo, "score", true); | 420 perf_test::PrintResult("audio_pesq", "", "mos_lqo", mos_lqo, "score", true); |
438 | 421 |
439 EXPECT_TRUE(base::DeleteFile(recording, false)); | 422 EXPECT_TRUE(base::DeleteFile(recording, false)); |
440 EXPECT_TRUE(base::DeleteFile(trimmed_recording, false)); | 423 EXPECT_TRUE(base::DeleteFile(trimmed_recording, false)); |
441 | |
442 ASSERT_TRUE(peerconnection_server_.Stop()); | |
443 } | 424 } |
OLD | NEW |