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 14 matching lines...) Expand all Loading... |
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 | 33 |
34 | 34 |
35 def _RunCommand(argv, **kwargs): | 35 def _RunCommand(argv, cwd=SRC_DIR, **kwargs): |
36 logging.info('Running %r', argv) | 36 logging.info('Running %r', argv) |
37 subprocess.check_call(argv, **kwargs) | 37 subprocess.check_call(argv, cwd=cwd, **kwargs) |
38 | 38 |
39 | 39 |
40 def _ParseArgs(): | 40 def _ParseArgs(): |
41 parser = argparse.ArgumentParser(description='Start loopback video analysis.') | 41 parser = argparse.ArgumentParser(description='Start loopback video analysis.') |
42 parser.add_argument('--source_dir', default=SRC_DIR, | |
43 help='The path to the WebRTC source directory. Default: %(default)s.') | |
44 parser.add_argument('build_dir_android', | 42 parser.add_argument('build_dir_android', |
45 help='The path to the build directory for Android.') | 43 help='The path to the build directory for Android.') |
46 parser.add_argument('--build_dir_x86', | 44 parser.add_argument('--build_dir_x86', |
47 help='The path to the build directory for building locally.') | 45 help='The path to the build directory for building locally.') |
48 parser.add_argument('--temp_dir', | 46 parser.add_argument('--temp_dir', |
49 help='A temporary directory to put the output.') | 47 help='A temporary directory to put the output.') |
50 | 48 |
51 args = parser.parse_args() | 49 args = parser.parse_args() |
52 return args | 50 return args |
53 | 51 |
54 | 52 |
55 def main(): | 53 def main(): |
56 logging.basicConfig(level=logging.INFO) | 54 logging.basicConfig(level=logging.INFO) |
57 | 55 |
58 args = _ParseArgs() | 56 args = _ParseArgs() |
59 | 57 |
60 source_dir = args.source_dir | |
61 build_dir_android = args.build_dir_android | 58 build_dir_android = args.build_dir_android |
62 build_dir_x86 = args.build_dir_x86 | 59 build_dir_x86 = args.build_dir_x86 |
63 temp_dir = args.temp_dir | 60 temp_dir = args.temp_dir |
64 if not temp_dir: | 61 if not temp_dir: |
65 temp_dir = tempfile.mkdtemp() | 62 temp_dir = tempfile.mkdtemp() |
66 else: | 63 else: |
67 if not os.path.exists(temp_dir): | 64 if not os.path.exists(temp_dir): |
68 os.makedirs(temp_dir) | 65 os.makedirs(temp_dir) |
69 | 66 |
70 if not build_dir_x86: | 67 if not build_dir_x86: |
71 build_dir_x86 = os.path.join(temp_dir, 'LocalBuild') | 68 build_dir_x86 = os.path.join(temp_dir, 'LocalBuild') |
72 _RunCommand(['gn', 'gen', build_dir_x86]) | 69 _RunCommand(['gn', 'gen', build_dir_x86]) |
73 _RunCommand(['ninja', '-C', build_dir_x86, 'frame_analyzer']) | 70 _RunCommand(['ninja', '-C', build_dir_x86, 'frame_analyzer']) |
74 | 71 |
75 toolchain_dir = os.path.join(source_dir, 'tools-webrtc', | 72 toolchain_dir = os.path.join(SRC_DIR, 'tools-webrtc', |
76 'video_quality_toolchain') | 73 'video_quality_toolchain') |
77 | 74 |
78 # Download ffmpeg and zxing. | 75 # Download ffmpeg and zxing. |
79 download_script = os.path.join(toolchain_dir, 'download.py') | 76 download_script = os.path.join(toolchain_dir, 'download.py') |
80 _RunCommand([sys.executable, download_script]) | 77 _RunCommand([sys.executable, download_script]) |
81 | 78 |
82 # Run the Espresso code. | 79 # Run the Espresso code. |
83 test_script = os.path.join(build_dir_android, | 80 test_script = os.path.join(build_dir_android, |
84 'bin', 'run_AppRTCMobileTestStubbedVideoIO') | 81 'bin', 'run_AppRTCMobileTestStubbedVideoIO') |
85 _RunCommand([sys.executable, test_script]) | 82 _RunCommand([sys.executable, test_script]) |
86 | 83 |
87 # Pull the output video. | 84 # Pull the output video. |
88 test_video = os.path.join(temp_dir, 'test_video.y4m') | 85 test_video = os.path.join(temp_dir, 'test_video.y4m') |
89 _RunCommand(['adb', 'pull', '/sdcard/output.y4m', test_video]) | 86 _RunCommand(['adb', 'pull', '/sdcard/output.y4m', test_video]) |
90 | 87 |
91 test_video_yuv = os.path.join(temp_dir, 'test_video.yuv') | 88 test_video_yuv = os.path.join(temp_dir, 'test_video.yuv') |
92 | 89 |
93 ffmpeg_path = os.path.join(toolchain_dir, 'linux', 'ffmpeg') | 90 ffmpeg_path = os.path.join(toolchain_dir, 'linux', 'ffmpeg') |
94 | 91 |
95 def convert_video(input_video, output_video): | 92 def convert_video(input_video, output_video): |
96 _RunCommand([ffmpeg_path, '-y', '-i', input_video, output_video]) | 93 _RunCommand([ffmpeg_path, '-y', '-i', input_video, output_video]) |
97 | 94 |
98 convert_video(test_video, test_video_yuv) | 95 convert_video(test_video, test_video_yuv) |
99 | 96 |
100 reference_video = os.path.join(source_dir, | 97 reference_video = os.path.join(SRC_DIR, |
101 'resources', 'reference_video_640x360_30fps.y4m') | 98 'resources', 'reference_video_640x360_30fps.y4m') |
102 | 99 |
103 reference_video_yuv = os.path.join(temp_dir, | 100 reference_video_yuv = os.path.join(temp_dir, |
104 'reference_video_640x360_30fps.yuv') | 101 'reference_video_640x360_30fps.yuv') |
105 | 102 |
106 convert_video(reference_video, reference_video_yuv) | 103 convert_video(reference_video, reference_video_yuv) |
107 | 104 |
108 # Run compare script. | 105 # Run compare script. |
109 compare_script = os.path.join(source_dir, 'webrtc', 'tools', | 106 compare_script = os.path.join(SRC_DIR, 'webrtc', 'tools', |
110 'compare_videos.py') | 107 'compare_videos.py') |
111 zxing_path = os.path.join(toolchain_dir, 'linux', 'zxing') | 108 zxing_path = os.path.join(toolchain_dir, 'linux', 'zxing') |
112 | 109 |
113 # The frame_analyzer binary should be built for local computer and not for | 110 # The frame_analyzer binary should be built for local computer and not for |
114 # Android | 111 # Android |
115 frame_analyzer = os.path.join(build_dir_x86, 'frame_analyzer') | 112 frame_analyzer = os.path.join(build_dir_x86, 'frame_analyzer') |
116 | 113 |
117 frame_width = 640 | 114 frame_width = 640 |
118 frame_height = 360 | 115 frame_height = 360 |
119 | 116 |
120 stats_file_ref = os.path.join(temp_dir, 'stats_ref.txt') | 117 stats_file_ref = os.path.join(temp_dir, 'stats_ref.txt') |
121 stats_file_test = os.path.join(temp_dir, 'stats_test.txt') | 118 stats_file_test = os.path.join(temp_dir, 'stats_test.txt') |
122 | 119 |
123 _RunCommand([ | 120 _RunCommand([ |
124 sys.executable, compare_script, '--ref_video', reference_video_yuv, | 121 sys.executable, compare_script, '--ref_video', reference_video_yuv, |
125 '--test_video', test_video_yuv, '--yuv_frame_width', str(frame_width), | 122 '--test_video', test_video_yuv, '--yuv_frame_width', str(frame_width), |
126 '--yuv_frame_height', str(frame_height), | 123 '--yuv_frame_height', str(frame_height), |
127 '--stats_file_ref', stats_file_ref, | 124 '--stats_file_ref', stats_file_ref, |
128 '--stats_file_test', stats_file_test, '--frame_analyzer', frame_analyzer, | 125 '--stats_file_test', stats_file_test, '--frame_analyzer', frame_analyzer, |
129 '--ffmpeg_path', ffmpeg_path, '--zxing_path', zxing_path]) | 126 '--ffmpeg_path', ffmpeg_path, '--zxing_path', zxing_path]) |
130 | 127 |
131 shutil.rmtree(temp_dir) | 128 shutil.rmtree(temp_dir) |
132 | 129 |
133 | 130 |
134 if __name__ == '__main__': | 131 if __name__ == '__main__': |
135 sys.exit(main()) | 132 sys.exit(main()) |
136 | 133 |
OLD | NEW |