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 30 matching lines...) Expand all Loading... |
41 "resources/human-voice-win.wav"; | 41 "resources/human-voice-win.wav"; |
42 #else | 42 #else |
43 "resources/human-voice-linux.wav"; | 43 "resources/human-voice-linux.wav"; |
44 #endif | 44 #endif |
45 | 45 |
46 static const char kMainWebrtcTestHtmlPage[] = | 46 static const char kMainWebrtcTestHtmlPage[] = |
47 "/webrtc/webrtc_audio_quality_test.html"; | 47 "/webrtc/webrtc_audio_quality_test.html"; |
48 | 48 |
49 // Test we can set up a WebRTC call and play audio through it. | 49 // Test we can set up a WebRTC call and play audio through it. |
50 // | 50 // |
51 // You must have the src-internal solution in your .gclient to put the required | 51 // If you're not a googler and want to run this test, you need to provide a |
52 // pyauto_private directory into chrome/test/data/. | 52 // pesq binary for your platform (and sox.exe on windows). Read more on how |
| 53 // resources are managed in chrome/test/data/webrtc/resources/README. |
53 // | 54 // |
54 // This test will only work on machines that have been configured to record | 55 // This test will only work on machines that have been configured to record |
55 // their own input. | 56 // their own input. |
56 // | 57 // |
57 // On Linux: | 58 // On Linux: |
58 // 1. # sudo apt-get install pavucontrol | 59 // 1. # sudo apt-get install pavucontrol sox |
59 // 2. For the user who will run the test: # pavucontrol | 60 // 2. For the user who will run the test: # pavucontrol |
60 // 3. In a separate terminal, # arecord dummy | 61 // 3. In a separate terminal, # arecord dummy |
61 // 4. In pavucontrol, go to the recording tab. | 62 // 4. In pavucontrol, go to the recording tab. |
62 // 5. For the ALSA plug-in [aplay]: ALSA Capture from, change from <x> to | 63 // 5. For the ALSA plug-in [aplay]: ALSA Capture from, change from <x> to |
63 // <Monitor of x>, where x is whatever your primary sound device is called. | 64 // <Monitor of x>, where x is whatever your primary sound device is called. |
64 // 6. Try launching chrome as the target user on the target machine, try | 65 // 6. Try launching chrome as the target user on the target machine, try |
65 // playing, say, a YouTube video, and record with # arecord -f dat tmp.dat. | 66 // playing, say, a YouTube video, and record with # arecord -f dat tmp.dat. |
66 // Verify the recording with aplay (should have recorded what you played | 67 // Verify the recording with aplay (should have recorded what you played |
67 // from chrome). | 68 // from chrome). |
68 // | 69 // |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 int exit_code = -1; | 185 int exit_code = -1; |
185 base::WaitForExitCode(recording_application_, &exit_code); | 186 base::WaitForExitCode(recording_application_, &exit_code); |
186 return exit_code == 0; | 187 return exit_code == 0; |
187 } | 188 } |
188 private: | 189 private: |
189 base::ProcessHandle recording_application_; | 190 base::ProcessHandle recording_application_; |
190 }; | 191 }; |
191 | 192 |
192 bool ForceMicrophoneVolumeTo100Percent() { | 193 bool ForceMicrophoneVolumeTo100Percent() { |
193 #if defined(OS_WIN) | 194 #if defined(OS_WIN) |
| 195 // Note: the force binary isn't in tools since it's one of our own. |
194 CommandLine command_line(test::GetReferenceFilesDir().Append( | 196 CommandLine command_line(test::GetReferenceFilesDir().Append( |
195 FILE_PATH_LITERAL("force_mic_volume_max.exe"))); | 197 FILE_PATH_LITERAL("force_mic_volume_max.exe"))); |
196 VLOG(0) << "Running " << command_line.GetCommandLineString(); | 198 VLOG(0) << "Running " << command_line.GetCommandLineString(); |
197 std::string result; | 199 std::string result; |
198 if (!base::GetAppOutput(command_line, &result)) { | 200 if (!base::GetAppOutput(command_line, &result)) { |
199 LOG(ERROR) << "Failed to set source volume: output was " << result; | 201 LOG(ERROR) << "Failed to set source volume: output was " << result; |
200 return false; | 202 return false; |
201 } | 203 } |
202 #else | 204 #else |
203 // Just force the volume of, say the first 5 devices. A machine will rarely | 205 // Just force the volume of, say the first 5 devices. A machine will rarely |
(...skipping 28 matching lines...) Expand all Loading... |
232 // ABOVE_PERIODS: The period for which silence occurs. Value 1 is used for | 234 // ABOVE_PERIODS: The period for which silence occurs. Value 1 is used for |
233 // silence at beginning of audio. | 235 // silence at beginning of audio. |
234 // DURATION: the amount of time in seconds that non-silence must be detected | 236 // DURATION: the amount of time in seconds that non-silence must be detected |
235 // before sox stops trimming audio. | 237 // before sox stops trimming audio. |
236 // THRESHOLD: value used to indicate what sample value is treates as silence. | 238 // THRESHOLD: value used to indicate what sample value is treates as silence. |
237 const char* kAbovePeriods = "1"; | 239 const char* kAbovePeriods = "1"; |
238 const char* kDuration = "2"; | 240 const char* kDuration = "2"; |
239 const char* kTreshold = "5%"; | 241 const char* kTreshold = "5%"; |
240 | 242 |
241 #if defined(OS_WIN) | 243 #if defined(OS_WIN) |
242 CommandLine command_line(test::GetReferenceFilesDir().Append( | 244 base::FilePath sox_path = test::GetReferenceFilesDir().Append( |
243 FILE_PATH_LITERAL("sox.exe"))); | 245 FILE_PATH_LITERAL("tools/sox.exe")); |
| 246 if (!base::PathExists(sox_path)) { |
| 247 LOG(ERROR) << "Missing sox.exe binary in " << sox_path.value() |
| 248 << "; you may have to provide this binary yourself."; |
| 249 return false; |
| 250 } |
| 251 CommandLine command_line(sox_path); |
244 #else | 252 #else |
245 CommandLine command_line(base::FilePath(FILE_PATH_LITERAL("sox"))); | 253 CommandLine command_line(base::FilePath(FILE_PATH_LITERAL("sox"))); |
246 #endif | 254 #endif |
247 command_line.AppendArgPath(input_file); | 255 command_line.AppendArgPath(input_file); |
248 command_line.AppendArgPath(output_file); | 256 command_line.AppendArgPath(output_file); |
249 command_line.AppendArg("silence"); | 257 command_line.AppendArg("silence"); |
250 command_line.AppendArg(kAbovePeriods); | 258 command_line.AppendArg(kAbovePeriods); |
251 command_line.AppendArg(kDuration); | 259 command_line.AppendArg(kDuration); |
252 command_line.AppendArg(kTreshold); | 260 command_line.AppendArg(kTreshold); |
253 command_line.AppendArg("reverse"); | 261 command_line.AppendArg("reverse"); |
(...skipping 27 matching lines...) Expand all Loading... |
281 // "3.145", etc). Returns true on success. | 289 // "3.145", etc). Returns true on success. |
282 bool RunPesq(const base::FilePath& reference_file, | 290 bool RunPesq(const base::FilePath& reference_file, |
283 const base::FilePath& actual_file, | 291 const base::FilePath& actual_file, |
284 int sample_rate, std::string* raw_mos, std::string* mos_lqo) { | 292 int sample_rate, std::string* raw_mos, std::string* mos_lqo) { |
285 // PESQ will break if the paths are too long (!). | 293 // PESQ will break if the paths are too long (!). |
286 EXPECT_LT(reference_file.value().length(), 128u); | 294 EXPECT_LT(reference_file.value().length(), 128u); |
287 EXPECT_LT(actual_file.value().length(), 128u); | 295 EXPECT_LT(actual_file.value().length(), 128u); |
288 | 296 |
289 #if defined(OS_WIN) | 297 #if defined(OS_WIN) |
290 base::FilePath pesq_path = | 298 base::FilePath pesq_path = |
291 test::GetReferenceFilesDir().Append(FILE_PATH_LITERAL("pesq.exe")); | 299 test::GetReferenceFilesDir().Append(FILE_PATH_LITERAL("tools/pesq.exe")); |
292 #else | 300 #else |
293 base::FilePath pesq_path = | 301 base::FilePath pesq_path = |
294 test::GetReferenceFilesDir().Append(FILE_PATH_LITERAL("pesq")); | 302 test::GetReferenceFilesDir().Append(FILE_PATH_LITERAL("tools/pesq")); |
295 #endif | 303 #endif |
296 | 304 |
297 if (!base::PathExists(pesq_path)) { | 305 if (!base::PathExists(pesq_path)) { |
298 LOG(ERROR) << "Missing PESQ binary in " << pesq_path.value(); | 306 LOG(ERROR) << "Missing PESQ binary in " << pesq_path.value() |
| 307 << "; you may have to provide this binary yourself."; |
299 return false; | 308 return false; |
300 } | 309 } |
301 | 310 |
302 CommandLine command_line(pesq_path); | 311 CommandLine command_line(pesq_path); |
303 command_line.AppendArg(base::StringPrintf("+%d", sample_rate)); | 312 command_line.AppendArg(base::StringPrintf("+%d", sample_rate)); |
304 command_line.AppendArgPath(reference_file); | 313 command_line.AppendArgPath(reference_file); |
305 command_line.AppendArgPath(actual_file); | 314 command_line.AppendArgPath(actual_file); |
306 | 315 |
307 VLOG(0) << "Running " << command_line.GetCommandLineString(); | 316 VLOG(0) << "Running " << command_line.GetCommandLineString(); |
308 std::string result; | 317 std::string result; |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
407 test::GetReferenceFilesDir().Append(kReferenceFile); | 416 test::GetReferenceFilesDir().Append(kReferenceFile); |
408 ASSERT_TRUE(RunPesq(reference_file_in_test_dir, trimmed_recording, 16000, | 417 ASSERT_TRUE(RunPesq(reference_file_in_test_dir, trimmed_recording, 16000, |
409 &raw_mos, &mos_lqo)); | 418 &raw_mos, &mos_lqo)); |
410 | 419 |
411 perf_test::PrintResult("audio_pesq", "", "raw_mos", raw_mos, "score", true); | 420 perf_test::PrintResult("audio_pesq", "", "raw_mos", raw_mos, "score", true); |
412 perf_test::PrintResult("audio_pesq", "", "mos_lqo", mos_lqo, "score", true); | 421 perf_test::PrintResult("audio_pesq", "", "mos_lqo", mos_lqo, "score", true); |
413 | 422 |
414 EXPECT_TRUE(base::DeleteFile(recording, false)); | 423 EXPECT_TRUE(base::DeleteFile(recording, false)); |
415 EXPECT_TRUE(base::DeleteFile(trimmed_recording, false)); | 424 EXPECT_TRUE(base::DeleteFile(trimmed_recording, false)); |
416 } | 425 } |
OLD | NEW |