Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(330)

Side by Side Diff: webrtc/examples/androidtests/video_quality_loopback_test.py

Issue 2882073003: Update testing tools (AppRTC, Go) to new versions (Closed)
Patch Set: Move readme Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | webrtc/tools/testing/README.md » ('j') | webrtc/tools/testing/README.md » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 starts a loopback call with stubbed video in 11 This script is the wrapper that starts a loopback call with stubbed video in
12 and out. It then analyses the video quality of the output video against the 12 and out. It then analyses the video quality of the output video against the
13 reference input video. 13 reference input video.
14 14
15 It expect to be given the webrtc output build directory as the first argument 15 It expect to be given the webrtc output build directory as the first argument
16 all other arguments are optional. 16 all other arguments are optional.
17 17
18 It assumes you have a Android device plugged in. 18 It assumes you have a Android device plugged in.
19 """ 19 """
20 20
21 import argparse 21 import argparse
22 import atexit
23 import logging 22 import logging
24 import os 23 import os
25 import shutil 24 import shutil
26 import subprocess 25 import subprocess
27 import sys 26 import sys
28 import tempfile 27 import tempfile
29 import time 28 import time
30 29
31 30
32 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) 31 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
33 SRC_DIR = os.path.normpath(os.path.join(SCRIPT_DIR, os.pardir, os.pardir, 32 SRC_DIR = os.path.normpath(os.path.join(SCRIPT_DIR, os.pardir, os.pardir,
34 os.pardir)) 33 os.pardir))
35 WEBRTC_DEPS_INSTRUCTIONS = """Please add a solution to your .gclient file like
36 this and run gclient sync:
37 {
38 "name": "webrtc.DEPS",
39 "url": "https://chromium.googlesource.com/chromium/deps/webrtc/webrtc.DEPS",
40 },
41 """
42 34
43 35
44 class Error(Exception): 36 class Error(Exception):
45 pass 37 pass
46 38
47 39
48 class VideoQualityTestError(Error): 40 class VideoQualityTestError(Error):
49 pass 41 pass
50 42
51 43
52 def _RunCommand(argv, cwd=SRC_DIR, **kwargs): 44 def _RunCommand(argv, cwd=SRC_DIR, **kwargs):
53 logging.info('Running %r', argv) 45 logging.info('Running %r', argv)
54 subprocess.check_call(argv, cwd=cwd, **kwargs) 46 subprocess.check_call(argv, cwd=cwd, **kwargs)
55 47
56 48
57 def _RunCommandWithOutput(argv, cwd=SRC_DIR, **kwargs): 49 def _RunCommandWithOutput(argv, cwd=SRC_DIR, **kwargs):
58 logging.info('Running %r', argv) 50 logging.info('Running %r', argv)
59 return subprocess.check_output(argv, cwd=cwd, **kwargs) 51 return subprocess.check_output(argv, cwd=cwd, **kwargs)
60 52
61 53
62 def _RunBackgroundCommand(argv, cwd=SRC_DIR): 54 def _RunBackgroundCommand(argv, cwd=SRC_DIR):
63 logging.info('Running %r', argv) 55 logging.info('Running %r', argv)
64 process = subprocess.Popen(argv, cwd=cwd) 56 process = subprocess.Popen(argv, cwd=cwd)
65 atexit.register(process.terminate)
66 time.sleep(0.5) 57 time.sleep(0.5)
67 status = process.poll() 58 status = process.poll()
68 if status: # is not None or 0 59 if status: # is not None or 0
69 raise subprocess.CalledProcessError(status, argv) 60 raise subprocess.CalledProcessError(status, argv)
70 return process 61 return process
71 62
72 63
73 def _ParseArgs(): 64 def _ParseArgs():
74 parser = argparse.ArgumentParser(description='Start loopback video analysis.') 65 parser = argparse.ArgumentParser(description='Start loopback video analysis.')
75 parser.add_argument('build_dir_android', 66 parser.add_argument('build_dir_android',
(...skipping 25 matching lines...) Expand all
101 92
102 if not build_dir_x86: 93 if not build_dir_x86:
103 build_dir_x86 = os.path.join(temp_dir, 'LocalBuild') 94 build_dir_x86 = os.path.join(temp_dir, 'LocalBuild')
104 _RunCommand(['gn', 'gen', build_dir_x86]) 95 _RunCommand(['gn', 'gen', build_dir_x86])
105 _RunCommand(['ninja', '-C', build_dir_x86, 'frame_analyzer']) 96 _RunCommand(['ninja', '-C', build_dir_x86, 'frame_analyzer'])
106 97
107 tools_dir = os.path.join(SRC_DIR, 'tools_webrtc') 98 tools_dir = os.path.join(SRC_DIR, 'tools_webrtc')
108 toolchain_dir = os.path.join(tools_dir, 'video_quality_toolchain') 99 toolchain_dir = os.path.join(tools_dir, 'video_quality_toolchain')
109 100
110 # Download ffmpeg and zxing. 101 # Download ffmpeg and zxing.
111 download_script = os.path.join(tools_dir, 'download_tools.py') 102 download_tools_script = os.path.join(tools_dir, 'download_tools.py')
112 _RunCommand([sys.executable, download_script, toolchain_dir]) 103 _RunCommand([sys.executable, download_tools_script, toolchain_dir])
104
105 testing_tools_dir = os.path.join(SRC_DIR, 'webrtc', 'tools', 'testing')
106
107 # Download, extract and build AppRTC.
108 setup_apprtc_script = os.path.join(testing_tools_dir, 'setup_apprtc.py')
109 _RunCommand([sys.executable, setup_apprtc_script, temp_dir])
113 110
114 # Select an Android device in case multiple are connected 111 # Select an Android device in case multiple are connected
115 for line in _RunCommandWithOutput([adb_path, 'devices']).splitlines(): 112 for line in _RunCommandWithOutput([adb_path, 'devices']).splitlines():
116 if line.endswith('\tdevice'): 113 if line.endswith('\tdevice'):
117 android_device = line.split('\t')[0] 114 android_device = line.split('\t')[0]
118 break 115 break
119 else: 116 else:
120 raise VideoQualityTestError('Cannot find any connected Android device.') 117 raise VideoQualityTestError('Cannot find any connected Android device.')
121 118
122 # Start AppRTC Server 119 processes = []
123 dev_appserver = os.path.join(SRC_DIR, 'out', 'apprtc', 'google_appengine', 120 try:
124 'dev_appserver.py') 121 # Start AppRTC Server
125 if not os.path.isfile(dev_appserver): 122 dev_appserver = os.path.join(temp_dir, 'apprtc', 'temp', 'google-cloud-sdk',
126 raise VideoQualityTestError('Cannot find %s.\n%s' % 123 'bin', 'dev_appserver.py')
127 (dev_appserver, WEBRTC_DEPS_INSTRUCTIONS)) 124 appengine_dir = os.path.join(temp_dir, 'apprtc', 'out', 'app_engine')
128 appengine_dir = os.path.join(SRC_DIR, 'out', 'apprtc', 'out', 'app_engine') 125 processes.append(_RunBackgroundCommand([
129 _RunBackgroundCommand(['python', dev_appserver, appengine_dir, 126 'python', dev_appserver, appengine_dir,
130 '--port=9999', '--admin_port=9998', 127 '--port=9999', '--admin_port=9998',
131 '--skip_sdk_update_check', '--clear_datastore=yes']) 128 '--skip_sdk_update_check', '--clear_datastore=yes']))
132 129
133 # Start Collider 130 # Start Collider
134 collider_path = os.path.join(SRC_DIR, 'out', 'go-workspace', 'bin', 131 collider_path = os.path.join(temp_dir, 'collider', 'collidermain')
135 'collidermain') 132 processes.append(_RunBackgroundCommand([
136 if not os.path.isfile(collider_path): 133 collider_path, '-tls=false', '-port=8089',
137 raise VideoQualityTestError('Cannot find %s.\n%s' % 134 '-room-server=http://localhost:9999']))
138 (collider_path, WEBRTC_DEPS_INSTRUCTIONS))
139 _RunBackgroundCommand([collider_path, '-tls=false',
140 '-port=8089', '-room-server=http://localhost:9999'])
141 135
142 # Start adb reverse forwarder 136 # Start adb reverse forwarder
143 reverseforwarder_path = os.path.join( 137 reverseforwarder_path = os.path.join(
144 SRC_DIR, 'build', 'android', 'adb_reverse_forwarder.py') 138 SRC_DIR, 'build', 'android', 'adb_reverse_forwarder.py')
145 _RunBackgroundCommand([reverseforwarder_path, '--device', android_device, 139 processes.append(_RunBackgroundCommand([
146 '9999', '9999', '8089', '8089']) 140 reverseforwarder_path, '--device', android_device,
141 '9999', '9999', '8089', '8089']))
147 142
148 # Run the Espresso code. 143 # Run the Espresso code.
149 test_script = os.path.join(build_dir_android, 144 test_script = os.path.join(build_dir_android,
150 'bin', 'run_AppRTCMobileTestStubbedVideoIO') 145 'bin', 'run_AppRTCMobileTestStubbedVideoIO')
151 _RunCommand([test_script, '--device', android_device]) 146 _RunCommand([test_script, '--device', android_device])
152 147
153 # Pull the output video. 148 # Pull the output video.
154 test_video = os.path.join(temp_dir, 'test_video.y4m') 149 test_video = os.path.join(temp_dir, 'test_video.y4m')
155 _RunCommand([adb_path, '-s', android_device, 150 _RunCommand([adb_path, '-s', android_device,
156 'pull', '/sdcard/output.y4m', test_video]) 151 'pull', '/sdcard/output.y4m', test_video])
157 152
158 test_video_yuv = os.path.join(temp_dir, 'test_video.yuv') 153 test_video_yuv = os.path.join(temp_dir, 'test_video.yuv')
159 154
160 ffmpeg_path = os.path.join(toolchain_dir, 'linux', 'ffmpeg') 155 ffmpeg_path = os.path.join(toolchain_dir, 'linux', 'ffmpeg')
161 156
162 def ConvertVideo(input_video, output_video): 157 def ConvertVideo(input_video, output_video):
163 _RunCommand([ffmpeg_path, '-y', '-i', input_video, output_video]) 158 _RunCommand([ffmpeg_path, '-y', '-i', input_video, output_video])
164 159
165 ConvertVideo(test_video, test_video_yuv) 160 ConvertVideo(test_video, test_video_yuv)
166 161
167 reference_video = os.path.join(SRC_DIR, 162 reference_video = os.path.join(SRC_DIR,
168 'resources', 'reference_video_640x360_30fps.y4m') 163 'resources', 'reference_video_640x360_30fps.y4m')
169 164
170 reference_video_yuv = os.path.join(temp_dir, 165 reference_video_yuv = os.path.join(temp_dir,
171 'reference_video_640x360_30fps.yuv') 166 'reference_video_640x360_30fps.yuv')
172 167
173 ConvertVideo(reference_video, reference_video_yuv) 168 ConvertVideo(reference_video, reference_video_yuv)
174 169
175 # Run compare script. 170 # Run compare script.
176 compare_script = os.path.join(SRC_DIR, 'webrtc', 'tools', 'compare_videos.py') 171 compare_script = os.path.join(SRC_DIR, 'webrtc', 'tools',
177 zxing_path = os.path.join(toolchain_dir, 'linux', 'zxing') 172 'compare_videos.py')
173 zxing_path = os.path.join(toolchain_dir, 'linux', 'zxing')
178 174
179 # The frame_analyzer binary should be built for local computer and not for 175 # The frame_analyzer binary should be built for local computer and not for
180 # Android 176 # Android
181 frame_analyzer = os.path.join(build_dir_x86, 'frame_analyzer') 177 frame_analyzer = os.path.join(build_dir_x86, 'frame_analyzer')
182 178
183 frame_width = 640 179 frame_width = 640
184 frame_height = 360 180 frame_height = 360
185 181
186 stats_file_ref = os.path.join(temp_dir, 'stats_ref.txt') 182 stats_file_ref = os.path.join(temp_dir, 'stats_ref.txt')
187 stats_file_test = os.path.join(temp_dir, 'stats_test.txt') 183 stats_file_test = os.path.join(temp_dir, 'stats_test.txt')
188 184
189 _RunCommand([ 185 _RunCommand([
190 sys.executable, compare_script, '--ref_video', reference_video_yuv, 186 sys.executable, compare_script, '--ref_video', reference_video_yuv,
191 '--test_video', test_video_yuv, '--yuv_frame_width', str(frame_width), 187 '--test_video', test_video_yuv, '--yuv_frame_width', str(frame_width),
192 '--yuv_frame_height', str(frame_height), 188 '--yuv_frame_height', str(frame_height),
193 '--stats_file_ref', stats_file_ref, 189 '--stats_file_ref', stats_file_ref,
194 '--stats_file_test', stats_file_test, '--frame_analyzer', frame_analyzer, 190 '--stats_file_test', stats_file_test,
195 '--ffmpeg_path', ffmpeg_path, '--zxing_path', zxing_path]) 191 '--frame_analyzer', frame_analyzer,
192 '--ffmpeg_path', ffmpeg_path, '--zxing_path', zxing_path])
196 193
197 shutil.rmtree(temp_dir) 194 finally:
195 for process in processes:
196 if process:
197 process.terminate()
198 process.wait()
199
200 shutil.rmtree(temp_dir)
198 201
199 202
200 if __name__ == '__main__': 203 if __name__ == '__main__':
201 sys.exit(main()) 204 sys.exit(main())
202 205
OLDNEW
« no previous file with comments | « no previous file | webrtc/tools/testing/README.md » ('j') | webrtc/tools/testing/README.md » ('J')

Powered by Google App Engine
This is Rietveld 408576698