OLD | NEW |
---|---|
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. | 2 # Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. |
3 # | 3 # |
4 # Use of this source code is governed by a BSD-style license | 4 # Use of this source code is governed by a BSD-style license |
5 # that can be found in the LICENSE file in the root of the source | 5 # that can be found in the LICENSE file in the root of the source |
6 # tree. An additional intellectual property rights grant can be found | 6 # tree. An additional intellectual property rights grant can be found |
7 # in the file PATENTS. All contributing project authors may | 7 # in the file PATENTS. All contributing project authors may |
8 # be found in the AUTHORS file in the root of the source tree. | 8 # be found in the AUTHORS file in the root of the source tree. |
9 | 9 |
10 """ | 10 """ |
11 This script is the wrapper that runs the low-bandwidth audio test. | 11 This script is the wrapper that runs the low-bandwidth audio test. |
12 | 12 |
13 After running the test, post-process steps for calculating audio quality of the | 13 After running the test, post-process steps for calculating audio quality of the |
14 output files will be performed. | 14 output files will be performed. |
15 """ | 15 """ |
16 | 16 |
17 import argparse | 17 import argparse |
18 import logging | 18 import logging |
19 import os | 19 import os |
20 import re | |
20 import subprocess | 21 import subprocess |
21 import sys | 22 import sys |
22 | 23 |
23 | 24 |
24 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) | 25 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) |
25 SRC_DIR = os.path.normpath(os.path.join(SCRIPT_DIR, os.pardir, os.pardir, | 26 SRC_DIR = os.path.normpath(os.path.join(SCRIPT_DIR, os.pardir, os.pardir, |
26 os.pardir)) | 27 os.pardir)) |
27 | 28 |
28 | 29 |
29 def _RunCommand(argv, cwd=SRC_DIR, **kwargs): | 30 def _LogCommand(command): |
30 logging.info('Running %r', argv) | 31 logging.info('Running %r', command) |
31 subprocess.check_call(argv, cwd=cwd, **kwargs) | 32 return command |
32 | 33 |
33 | 34 |
34 def _ParseArgs(): | 35 def _ParseArgs(): |
35 parser = argparse.ArgumentParser(description='Run low-bandwidth audio tests.') | 36 parser = argparse.ArgumentParser(description='Run low-bandwidth audio tests.') |
36 parser.add_argument('build_dir', | 37 parser.add_argument('build_dir', |
37 help='Path to the build directory (e.g. out/Release).') | 38 help='Path to the build directory (e.g. out/Release).') |
39 parser.add_argument('--remove', action='store_true', | |
40 help='Remove output audio files after testing.') | |
38 args = parser.parse_args() | 41 args = parser.parse_args() |
39 return args | 42 return args |
40 | 43 |
41 | 44 |
45 def _GetPlatform(): | |
46 if sys.platform == 'win32': | |
47 return 'win' | |
48 elif sys.platform == 'darwin': | |
49 return 'mac' | |
50 elif sys.platform.startswith('linux'): | |
51 return 'linux' | |
52 | |
53 | |
54 def _GetExecutableExtension(): | |
55 if sys.platform == 'win32': | |
56 return '.exe' | |
57 else: | |
58 return '' | |
59 | |
60 | |
61 def _DownloadTools(): | |
62 tools_dir = os.path.join(SRC_DIR, 'tools-webrtc') | |
63 toolchain_dir = os.path.join(tools_dir, 'audio_quality') | |
64 | |
65 # Download pesq. | |
66 download_script = os.path.join(tools_dir, 'download_tools.py') | |
67 command = [sys.executable, download_script, toolchain_dir] | |
68 subprocess.check_call(_LogCommand(command)) | |
69 | |
70 pesq_path = os.path.join(toolchain_dir, _GetPlatform(), | |
71 'pesq' + _GetExecutableExtension()) | |
72 return pesq_path | |
73 | |
74 | |
42 def main(): | 75 def main(): |
43 # pylint: disable=W0101 | 76 # pylint: disable=W0101 |
44 logging.basicConfig(level=logging.INFO) | 77 logging.basicConfig(level=logging.INFO) |
45 | 78 |
46 args = _ParseArgs() | 79 args = _ParseArgs() |
47 | 80 |
48 test_executable = os.path.join(args.build_dir, 'low_bandwidth_audio_test') | 81 pesq_path = _DownloadTools() |
49 if sys.platform == 'win32': | |
50 test_executable += '.exe' | |
51 | 82 |
52 _RunCommand([test_executable]) | 83 test_executable_path = os.path.join(args.build_dir, |
84 'low_bandwidth_audio_test' + _GetExecutableExtension()) | |
53 | 85 |
86 # Start the test executable that produces audio files. | |
87 command = [test_executable_path] | |
88 test_process = subprocess.Popen(_LogCommand(command), stdout=subprocess.PIPE) | |
89 | |
90 for line in iter(test_process.stdout.readline, ''): | |
91 # Echo the output to screen. | |
92 sys.stdout.write(line) | |
93 | |
94 # Extract specific lines that contain information about produced files. | |
95 match = re.search(r'^TEST (\w+) ([^:]+?):([^:]+?)\n?$', line) | |
96 if not match: | |
97 continue | |
98 test_name, reference_file, degraded_file = match.groups() | |
99 | |
100 # Analyze audio | |
101 command = [pesq_path, '+16000', reference_file, degraded_file] | |
102 pesq_output = subprocess.check_output(_LogCommand(command)) | |
103 | |
104 if args.remove: | |
105 os.remove(degraded_file) | |
106 | |
107 # Find the scores in stdout of pesq. | |
108 match = re.search( | |
109 r'Prediction \(Raw MOS, MOS-LQO\):\s+=\s+([\d.]+)\s+([\d.]+)', | |
110 pesq_output) | |
111 if match: | |
112 raw_mos, _ = match.groups() | |
113 | |
114 # Output a result for the perf dashboard. | |
115 print 'RESULT pesq_mos: %s= %s score' % (test_name, raw_mos) | |
116 else: | |
117 logging.error('PESQ: %s', pesq_output.splitlines()[-1]) | |
118 | |
119 return test_process.wait() | |
54 | 120 |
kjellander_webrtc
2017/03/17 07:11:41
+1 blank line for top-level statements
https://goo
oprypin_webrtc
2017/03/17 10:16:51
Done.
| |
55 if __name__ == '__main__': | 121 if __name__ == '__main__': |
56 sys.exit(main()) | 122 sys.exit(main()) |
OLD | NEW |