Index: webrtc/audio/test/low_bandwidth_audio_test.py |
diff --git a/webrtc/audio/test/low_bandwidth_audio_test.py b/webrtc/audio/test/low_bandwidth_audio_test.py |
index aaba9d23984c587fce0a0a8b4686a80f29b5a080..6482d3d0209cba828185f771b1299d8c0e355304 100755 |
--- a/webrtc/audio/test/low_bandwidth_audio_test.py |
+++ b/webrtc/audio/test/low_bandwidth_audio_test.py |
@@ -17,6 +17,7 @@ output files will be performed. |
import argparse |
import logging |
import os |
+import re |
import subprocess |
import sys |
@@ -26,30 +27,96 @@ SRC_DIR = os.path.normpath(os.path.join(SCRIPT_DIR, os.pardir, os.pardir, |
os.pardir)) |
-def _RunCommand(argv, cwd=SRC_DIR, **kwargs): |
- logging.info('Running %r', argv) |
- subprocess.check_call(argv, cwd=cwd, **kwargs) |
+def _LogCommand(command): |
+ logging.info('Running %r', command) |
+ return command |
def _ParseArgs(): |
parser = argparse.ArgumentParser(description='Run low-bandwidth audio tests.') |
parser.add_argument('build_dir', |
help='Path to the build directory (e.g. out/Release).') |
+ parser.add_argument('--remove', action='store_true', |
+ help='Remove output audio files after testing.') |
args = parser.parse_args() |
return args |
+def _GetPlatform(): |
+ if sys.platform == 'win32': |
+ return 'win' |
+ elif sys.platform == 'darwin': |
+ return 'mac' |
+ elif sys.platform.startswith('linux'): |
+ return 'linux' |
+ |
+ |
+def _GetExecutableExtension(): |
+ if sys.platform == 'win32': |
+ return '.exe' |
+ else: |
+ return '' |
+ |
+ |
+def _DownloadTools(): |
+ tools_dir = os.path.join(SRC_DIR, 'tools-webrtc') |
+ toolchain_dir = os.path.join(tools_dir, 'audio_quality') |
+ |
+ # Download pesq. |
+ download_script = os.path.join(tools_dir, 'download_tools.py') |
+ command = [sys.executable, download_script, toolchain_dir] |
+ subprocess.check_call(_LogCommand(command)) |
+ |
+ pesq_path = os.path.join(toolchain_dir, _GetPlatform(), |
+ 'pesq' + _GetExecutableExtension()) |
+ return pesq_path |
+ |
+ |
def main(): |
# pylint: disable=W0101 |
logging.basicConfig(level=logging.INFO) |
args = _ParseArgs() |
- test_executable = os.path.join(args.build_dir, 'low_bandwidth_audio_test') |
- if sys.platform == 'win32': |
- test_executable += '.exe' |
+ pesq_path = _DownloadTools() |
+ |
+ test_executable_path = os.path.join(args.build_dir, |
+ 'low_bandwidth_audio_test' + _GetExecutableExtension()) |
+ |
+ # Start the test executable that produces audio files. |
+ command = [test_executable_path] |
+ test_process = subprocess.Popen(_LogCommand(command), stdout=subprocess.PIPE) |
+ |
+ for line in iter(test_process.stdout.readline, ''): |
+ # Echo the output to screen. |
+ sys.stdout.write(line) |
+ |
+ # Extract specific lines that contain information about produced files. |
+ match = re.search(r'^TEST (\w+) ([^:]+?):([^:]+?)\n?$', line) |
+ if not match: |
+ continue |
+ test_name, reference_file, degraded_file = match.groups() |
+ |
+ # Analyze audio |
+ command = [pesq_path, '+16000', reference_file, degraded_file] |
+ pesq_output = subprocess.check_output(_LogCommand(command)) |
+ |
+ if args.remove: |
+ os.remove(degraded_file) |
+ |
+ # Find the scores in stdout of pesq. |
+ match = re.search( |
+ r'Prediction \(Raw MOS, MOS-LQO\):\s+=\s+([\d.]+)\s+([\d.]+)', |
+ pesq_output) |
+ if match: |
+ raw_mos, _ = match.groups() |
+ |
+ # Output a result for the perf dashboard. |
+ print 'RESULT pesq_mos: %s= %s score' % (test_name, raw_mos) |
+ else: |
+ logging.error('PESQ: %s', pesq_output.splitlines()[-1]) |
- _RunCommand([test_executable]) |
+ return test_process.wait() |
if __name__ == '__main__': |