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

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

Issue 2825313002: Espresso test for loopback video quality testing (Closed)
Patch Set: Rework colliderUrl as urlParameters 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 | « webrtc/examples/androidtests/src/org/appspot/apprtc/test/ConnectActivityStubbedInputOutputTest.java ('k') | no next file » | no next file with comments »
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
22 import logging 23 import logging
23 import os 24 import os
24 import shutil 25 import shutil
25 import subprocess 26 import subprocess
26 import sys 27 import sys
27 import tempfile 28 import tempfile
29 import time
28 30
29 31
30 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) 32 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
31 SRC_DIR = os.path.normpath(os.path.join(SCRIPT_DIR, os.pardir, os.pardir, 33 SRC_DIR = os.path.normpath(os.path.join(SCRIPT_DIR, os.pardir, os.pardir,
32 os.pardir)) 34 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
43
44 class Error(Exception):
45 pass
46
47
48 class VideoQualityTestError(Error):
49 pass
33 50
34 51
35 def _RunCommand(argv, cwd=SRC_DIR, **kwargs): 52 def _RunCommand(argv, cwd=SRC_DIR, **kwargs):
36 logging.info('Running %r', argv) 53 logging.info('Running %r', argv)
37 subprocess.check_call(argv, cwd=cwd, **kwargs) 54 subprocess.check_call(argv, cwd=cwd, **kwargs)
38 55
39 56
57 def _RunCommandWithOutput(argv, cwd=SRC_DIR, **kwargs):
58 logging.info('Running %r', argv)
59 return subprocess.check_output(argv, cwd=cwd, **kwargs)
60
61
62 def _RunBackgroundCommand(argv, cwd=SRC_DIR):
63 logging.info('Running %r', argv)
64 process = subprocess.Popen(argv, cwd=cwd)
65 atexit.register(process.terminate)
66 time.sleep(0.5)
67 status = process.poll()
68 if status: # is not None or 0
69 raise subprocess.CalledProcessError(status, argv)
70 return process
71
72
40 def _ParseArgs(): 73 def _ParseArgs():
41 parser = argparse.ArgumentParser(description='Start loopback video analysis.') 74 parser = argparse.ArgumentParser(description='Start loopback video analysis.')
42 parser.add_argument('build_dir_android', 75 parser.add_argument('build_dir_android',
43 help='The path to the build directory for Android.') 76 help='The path to the build directory for Android.')
44 parser.add_argument('--build_dir_x86', 77 parser.add_argument('--build_dir_x86',
45 help='The path to the build directory for building locally.') 78 help='The path to the build directory for building locally.')
46 parser.add_argument('--temp_dir', 79 parser.add_argument('--temp_dir',
47 help='A temporary directory to put the output.') 80 help='A temporary directory to put the output.')
81 parser.add_argument('--adb-path', help='Path to adb binary.', default='adb')
48 82
49 args = parser.parse_args() 83 args = parser.parse_args()
50 return args 84 return args
51 85
52 86
53 def main(): 87 def main():
54 logging.basicConfig(level=logging.INFO) 88 logging.basicConfig(level=logging.INFO)
55 89
56 args = _ParseArgs() 90 args = _ParseArgs()
57 91
58 build_dir_android = args.build_dir_android 92 build_dir_android = args.build_dir_android
59 build_dir_x86 = args.build_dir_x86 93 build_dir_x86 = args.build_dir_x86
60 temp_dir = args.temp_dir 94 temp_dir = args.temp_dir
95 adb_path = args.adb_path
61 if not temp_dir: 96 if not temp_dir:
62 temp_dir = tempfile.mkdtemp() 97 temp_dir = tempfile.mkdtemp()
63 else: 98 else:
64 if not os.path.exists(temp_dir): 99 if not os.path.exists(temp_dir):
65 os.makedirs(temp_dir) 100 os.makedirs(temp_dir)
66 101
67 if not build_dir_x86: 102 if not build_dir_x86:
68 build_dir_x86 = os.path.join(temp_dir, 'LocalBuild') 103 build_dir_x86 = os.path.join(temp_dir, 'LocalBuild')
69 _RunCommand(['gn', 'gen', build_dir_x86]) 104 _RunCommand(['gn', 'gen', build_dir_x86])
70 _RunCommand(['ninja', '-C', build_dir_x86, 'frame_analyzer']) 105 _RunCommand(['ninja', '-C', build_dir_x86, 'frame_analyzer'])
71 106
72 tools_dir = os.path.join(SRC_DIR, 'tools-webrtc') 107 tools_dir = os.path.join(SRC_DIR, 'tools-webrtc')
73 toolchain_dir = os.path.join(tools_dir, 'video_quality_toolchain') 108 toolchain_dir = os.path.join(tools_dir, 'video_quality_toolchain')
74 109
75 # Download ffmpeg and zxing. 110 # Download ffmpeg and zxing.
76 download_script = os.path.join(tools_dir, 'download_tools.py') 111 download_script = os.path.join(tools_dir, 'download_tools.py')
77 _RunCommand([sys.executable, download_script, toolchain_dir]) 112 _RunCommand([sys.executable, download_script, toolchain_dir])
78 113
114 # Select an Android device in case multiple are connected
115 for line in _RunCommandWithOutput([adb_path, 'devices']).splitlines():
116 if line.endswith('\tdevice'):
117 android_device = line.split('\t')[0]
118 break
119 else:
120 raise VideoQualityTestError('Cannot find any connected Android device.')
121
122 # Start AppRTC Server
123 dev_appserver = os.path.join(SRC_DIR, 'out', 'apprtc', 'google_appengine',
124 'dev_appserver.py')
125 if not os.path.isfile(dev_appserver):
126 raise VideoQualityTestError('Cannot find %s.\n%s' %
127 (dev_appserver, WEBRTC_DEPS_INSTRUCTIONS))
128 appengine_dir = os.path.join(SRC_DIR, 'out', 'apprtc', 'out', 'app_engine')
129 _RunBackgroundCommand(['python', dev_appserver, appengine_dir,
130 '--port=9999', '--admin_port=9998',
131 '--skip_sdk_update_check', '--clear_datastore=yes'])
132
133 # Start Collider
134 collider_path = os.path.join(SRC_DIR, 'out', 'go-workspace', 'bin',
135 'collidermain')
136 if not os.path.isfile(collider_path):
137 raise VideoQualityTestError('Cannot find %s.\n%s' %
138 (collider_path, WEBRTC_DEPS_INSTRUCTIONS))
139 _RunBackgroundCommand([collider_path, '-tls=false',
140 '-port=8089', '-room-server=http://localhost:9999'])
141
142 # Start adb reverse forwarder
143 reverseforwarder_path = os.path.join(
144 SRC_DIR, 'build', 'android', 'adb_reverse_forwarder.py')
145 _RunBackgroundCommand([reverseforwarder_path, '--device', android_device,
146 '9999', '9999', '8089', '8089'])
147
79 # Run the Espresso code. 148 # Run the Espresso code.
80 test_script = os.path.join(build_dir_android, 149 test_script = os.path.join(build_dir_android,
81 'bin', 'run_AppRTCMobileTestStubbedVideoIO') 150 'bin', 'run_AppRTCMobileTestStubbedVideoIO')
82 _RunCommand([sys.executable, test_script]) 151 _RunCommand([test_script, '--device', android_device])
83 152
84 # Pull the output video. 153 # Pull the output video.
85 test_video = os.path.join(temp_dir, 'test_video.y4m') 154 test_video = os.path.join(temp_dir, 'test_video.y4m')
86 _RunCommand(['adb', 'pull', '/sdcard/output.y4m', test_video]) 155 _RunCommand([adb_path, '-s', android_device,
156 'pull', '/sdcard/output.y4m', test_video])
87 157
88 test_video_yuv = os.path.join(temp_dir, 'test_video.yuv') 158 test_video_yuv = os.path.join(temp_dir, 'test_video.yuv')
89 159
90 ffmpeg_path = os.path.join(toolchain_dir, 'linux', 'ffmpeg') 160 ffmpeg_path = os.path.join(toolchain_dir, 'linux', 'ffmpeg')
91 161
92 def ConvertVideo(input_video, output_video): 162 def ConvertVideo(input_video, output_video):
93 _RunCommand([ffmpeg_path, '-y', '-i', input_video, output_video]) 163 _RunCommand([ffmpeg_path, '-y', '-i', input_video, output_video])
94 164
95 ConvertVideo(test_video, test_video_yuv) 165 ConvertVideo(test_video, test_video_yuv)
96 166
97 reference_video = os.path.join(SRC_DIR, 167 reference_video = os.path.join(SRC_DIR,
98 'resources', 'reference_video_640x360_30fps.y4m') 168 'resources', 'reference_video_640x360_30fps.y4m')
99 169
100 reference_video_yuv = os.path.join(temp_dir, 170 reference_video_yuv = os.path.join(temp_dir,
101 'reference_video_640x360_30fps.yuv') 171 'reference_video_640x360_30fps.yuv')
102 172
103 ConvertVideo(reference_video, reference_video_yuv) 173 ConvertVideo(reference_video, reference_video_yuv)
104 174
105 # Run compare script. 175 # Run compare script.
106 compare_script = os.path.join(SRC_DIR, 'webrtc', 'tools', 176 compare_script = os.path.join(SRC_DIR, 'webrtc', 'tools', 'compare_videos.py')
107 'compare_videos.py')
108 zxing_path = os.path.join(toolchain_dir, 'linux', 'zxing') 177 zxing_path = os.path.join(toolchain_dir, 'linux', 'zxing')
109 178
110 # The frame_analyzer binary should be built for local computer and not for 179 # The frame_analyzer binary should be built for local computer and not for
111 # Android 180 # Android
112 frame_analyzer = os.path.join(build_dir_x86, 'frame_analyzer') 181 frame_analyzer = os.path.join(build_dir_x86, 'frame_analyzer')
113 182
114 frame_width = 640 183 frame_width = 640
115 frame_height = 360 184 frame_height = 360
116 185
117 stats_file_ref = os.path.join(temp_dir, 'stats_ref.txt') 186 stats_file_ref = os.path.join(temp_dir, 'stats_ref.txt')
118 stats_file_test = os.path.join(temp_dir, 'stats_test.txt') 187 stats_file_test = os.path.join(temp_dir, 'stats_test.txt')
119 188
120 _RunCommand([ 189 _RunCommand([
121 sys.executable, compare_script, '--ref_video', reference_video_yuv, 190 sys.executable, compare_script, '--ref_video', reference_video_yuv,
122 '--test_video', test_video_yuv, '--yuv_frame_width', str(frame_width), 191 '--test_video', test_video_yuv, '--yuv_frame_width', str(frame_width),
123 '--yuv_frame_height', str(frame_height), 192 '--yuv_frame_height', str(frame_height),
124 '--stats_file_ref', stats_file_ref, 193 '--stats_file_ref', stats_file_ref,
125 '--stats_file_test', stats_file_test, '--frame_analyzer', frame_analyzer, 194 '--stats_file_test', stats_file_test, '--frame_analyzer', frame_analyzer,
126 '--ffmpeg_path', ffmpeg_path, '--zxing_path', zxing_path]) 195 '--ffmpeg_path', ffmpeg_path, '--zxing_path', zxing_path])
127 196
128 shutil.rmtree(temp_dir) 197 shutil.rmtree(temp_dir)
129 198
130 199
131 if __name__ == '__main__': 200 if __name__ == '__main__':
132 sys.exit(main()) 201 sys.exit(main())
133 202
OLDNEW
« no previous file with comments | « webrtc/examples/androidtests/src/org/appspot/apprtc/test/ConnectActivityStubbedInputOutputTest.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698