| 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 """ |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 import os | 23 import os |
| 24 import shutil | 24 import shutil |
| 25 import subprocess | 25 import subprocess |
| 26 import sys | 26 import sys |
| 27 import tempfile | 27 import tempfile |
| 28 | 28 |
| 29 | 29 |
| 30 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) | 30 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) |
| 31 SRC_DIR = os.path.normpath(os.path.join(SCRIPT_DIR, os.pardir, os.pardir, | 31 SRC_DIR = os.path.normpath(os.path.join(SCRIPT_DIR, os.pardir, os.pardir, |
| 32 os.pardir)) | 32 os.pardir)) |
| 33 WEBRTC_DEPS_INSTRUCTIONS = """Please add a solution to your .gclient file like |
| 34 this and run gclient sync: |
| 35 { |
| 36 "name": "webrtc.DEPS", |
| 37 "url": "https://chromium.googlesource.com/chromium/deps/webrtc/webrtc.DEPS", |
| 38 }, |
| 39 """ |
| 40 |
| 41 class Error(Exception): |
| 42 pass |
| 43 |
| 44 |
| 45 class VideoQualityTestError(Error): |
| 46 pass |
| 33 | 47 |
| 34 | 48 |
| 35 def _RunCommand(argv, cwd=SRC_DIR, **kwargs): | 49 def _RunCommand(argv, cwd=SRC_DIR, **kwargs): |
| 36 logging.info('Running %r', argv) | 50 logging.info('Running %r', argv) |
| 37 subprocess.check_call(argv, cwd=cwd, **kwargs) | 51 subprocess.check_call(argv, cwd=cwd, **kwargs) |
| 38 | 52 |
| 53 def _Popen(argv, cwd=SRC_DIR): |
| 54 logging.info('Running %r', argv) |
| 55 return subprocess.Popen(argv, cwd=cwd) |
| 39 | 56 |
| 40 def _ParseArgs(): | 57 def _ParseArgs(): |
| 41 parser = argparse.ArgumentParser(description='Start loopback video analysis.') | 58 parser = argparse.ArgumentParser(description='Start loopback video analysis.') |
| 42 parser.add_argument('build_dir_android', | 59 parser.add_argument('build_dir_android', |
| 43 help='The path to the build directory for Android.') | 60 help='The path to the build directory for Android.') |
| 44 parser.add_argument('--build_dir_x86', | 61 parser.add_argument('--build_dir_x86', |
| 45 help='The path to the build directory for building locally.') | 62 help='The path to the build directory for building locally.') |
| 46 parser.add_argument('--temp_dir', | 63 parser.add_argument('--temp_dir', |
| 47 help='A temporary directory to put the output.') | 64 help='A temporary directory to put the output.') |
| 48 | 65 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 69 _RunCommand(['gn', 'gen', build_dir_x86]) | 86 _RunCommand(['gn', 'gen', build_dir_x86]) |
| 70 _RunCommand(['ninja', '-C', build_dir_x86, 'frame_analyzer']) | 87 _RunCommand(['ninja', '-C', build_dir_x86, 'frame_analyzer']) |
| 71 | 88 |
| 72 tools_dir = os.path.join(SRC_DIR, 'tools-webrtc') | 89 tools_dir = os.path.join(SRC_DIR, 'tools-webrtc') |
| 73 toolchain_dir = os.path.join(tools_dir, 'video_quality_toolchain') | 90 toolchain_dir = os.path.join(tools_dir, 'video_quality_toolchain') |
| 74 | 91 |
| 75 # Download ffmpeg and zxing. | 92 # Download ffmpeg and zxing. |
| 76 download_script = os.path.join(tools_dir, 'download_tools.py') | 93 download_script = os.path.join(tools_dir, 'download_tools.py') |
| 77 _RunCommand([sys.executable, download_script, toolchain_dir]) | 94 _RunCommand([sys.executable, download_script, toolchain_dir]) |
| 78 | 95 |
| 79 # Run the Espresso code. | 96 |
| 80 test_script = os.path.join(build_dir_android, | 97 apprtc_process = None |
| 81 'bin', 'run_AppRTCMobileTestStubbedVideoIO') | 98 collider_process = None |
| 82 _RunCommand([sys.executable, test_script]) | 99 reverseforwarder_process = None |
| 100 |
| 101 try: |
| 102 # Start AppRTC Server |
| 103 dev_appserver = os.path.join(SRC_DIR, 'out', 'apprtc', 'google_appengine', |
| 104 'dev_appserver.py') |
| 105 if not os.path.isfile(dev_appserver): |
| 106 raise VideoQualityTestError('Cannot find %s.\n%s' % |
| 107 (dev_appserver, WEBRTC_DEPS_INSTRUCTIONS)) |
| 108 appengine_dir = os.path.join(SRC_DIR, 'out', 'apprtc', 'out', 'app_engine') |
| 109 apprtc_process = _Popen(['python', dev_appserver, appengine_dir, |
| 110 '--port=9999', '--admin_port=9998', '--skip_sdk_update_check', |
| 111 '--clear_datastore=yes']) |
| 112 |
| 113 # Start Collider |
| 114 collider_path = os.path.join(SRC_DIR, 'out', 'go-workspace', 'bin', |
| 115 'collidermain') |
| 116 if not os.path.isfile(collider_path): |
| 117 raise VideoQualityTestError('Cannot find %s.\n%s' % |
| 118 (collider_path, WEBRTC_DEPS_INSTRUCTIONS)) |
| 119 collider_process = _Popen([collider_path, '-tls=false', '-port=8089', |
| 120 '-room-server=http://localhost:9999']) |
| 121 |
| 122 # Start adb reverse forwarder |
| 123 reverseforwarder_path = os.path.join( |
| 124 SRC_DIR, 'build', 'android', 'adb_reverse_forwarder.py') |
| 125 reverseforwarder_process = _Popen( |
| 126 [reverseforwarder_path, '9999', '9999', '8089', '8089']) |
| 127 |
| 128 # Run the Espresso code. |
| 129 test_script = os.path.join(build_dir_android, |
| 130 'bin', 'run_AppRTCMobileTestStubbedVideoIO') |
| 131 _RunCommand([sys.executable, test_script]) |
| 132 finally: |
| 133 if apprtc_process: |
| 134 apprtc_process.terminate() |
| 135 if collider_process: |
| 136 collider_process.terminate() |
| 137 if reverseforwarder_process: |
| 138 reverseforwarder_process.terminate() |
| 83 | 139 |
| 84 # Pull the output video. | 140 # Pull the output video. |
| 85 test_video = os.path.join(temp_dir, 'test_video.y4m') | 141 test_video = os.path.join(temp_dir, 'test_video.y4m') |
| 86 _RunCommand(['adb', 'pull', '/sdcard/output.y4m', test_video]) | 142 _RunCommand(['adb', 'pull', '/sdcard/output.y4m', test_video]) |
| 87 | 143 |
| 88 test_video_yuv = os.path.join(temp_dir, 'test_video.yuv') | 144 test_video_yuv = os.path.join(temp_dir, 'test_video.yuv') |
| 89 | 145 |
| 90 ffmpeg_path = os.path.join(toolchain_dir, 'linux', 'ffmpeg') | 146 ffmpeg_path = os.path.join(toolchain_dir, 'linux', 'ffmpeg') |
| 91 | 147 |
| 92 def convert_video(input_video, output_video): | 148 def convert_video(input_video, output_video): |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 '--stats_file_ref', stats_file_ref, | 180 '--stats_file_ref', stats_file_ref, |
| 125 '--stats_file_test', stats_file_test, '--frame_analyzer', frame_analyzer, | 181 '--stats_file_test', stats_file_test, '--frame_analyzer', frame_analyzer, |
| 126 '--ffmpeg_path', ffmpeg_path, '--zxing_path', zxing_path]) | 182 '--ffmpeg_path', ffmpeg_path, '--zxing_path', zxing_path]) |
| 127 | 183 |
| 128 shutil.rmtree(temp_dir) | 184 shutil.rmtree(temp_dir) |
| 129 | 185 |
| 130 | 186 |
| 131 if __name__ == '__main__': | 187 if __name__ == '__main__': |
| 132 sys.exit(main()) | 188 sys.exit(main()) |
| 133 | 189 |
| OLD | NEW |