blob: a6115f31e3ddc822fc4206f09ce3fa678060819d [file] [log] [blame]
mandermoed582f72017-01-23 07:55:42 -08001#!/usr/bin/env python
2# Copyright (c) 2017 The WebRTC project authors. All Rights Reserved.
3#
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
6# tree. An additional intellectual property rights grant can be found
7# in the file PATENTS. All contributing project authors may
8# be found in the AUTHORS file in the root of the source tree.
9
10"""
11This script is the wrapper that starts a loopback call with stubbed video in
12and out. It then analyses the video quality of the output video against the
13reference input video.
14
15It expect to be given the webrtc output build directory as the first argument
16all other arguments are optional.
17
18It assumes you have a Android device plugged in.
19"""
20
21import argparse
22import logging
23import os
24import shutil
25import subprocess
26import sys
27import tempfile
28
29
30SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
kjellander30292102017-02-09 01:05:54 -080031SRC_DIR = os.path.normpath(os.path.join(SCRIPT_DIR, os.pardir, os.pardir,
32 os.pardir))
mandermoed582f72017-01-23 07:55:42 -080033
34
ehmaldonadod103f4b2017-02-16 07:20:26 -080035def _RunCommand(argv, cwd=SRC_DIR, **kwargs):
mandermoed582f72017-01-23 07:55:42 -080036 logging.info('Running %r', argv)
ehmaldonadod103f4b2017-02-16 07:20:26 -080037 subprocess.check_call(argv, cwd=cwd, **kwargs)
mandermoed582f72017-01-23 07:55:42 -080038
39
40def _ParseArgs():
41 parser = argparse.ArgumentParser(description='Start loopback video analysis.')
mandermoed582f72017-01-23 07:55:42 -080042 parser.add_argument('build_dir_android',
43 help='The path to the build directory for Android.')
44 parser.add_argument('--build_dir_x86',
45 help='The path to the build directory for building locally.')
46 parser.add_argument('--temp_dir',
47 help='A temporary directory to put the output.')
48
49 args = parser.parse_args()
50 return args
51
52
53def main():
Henrik Kjellander6951a282017-02-19 06:53:23 +010054 print 'This test is currently disabled (https://bugs.webrtc.org/7185)'
Henrik Kjellander5d43f742017-02-19 09:31:01 +010055 return 0
Henrik Kjellander6951a282017-02-19 06:53:23 +010056
Henrik Kjellander5d43f742017-02-19 09:31:01 +010057 # pylint: disable=W0101
mandermoed582f72017-01-23 07:55:42 -080058 logging.basicConfig(level=logging.INFO)
59
60 args = _ParseArgs()
61
mandermoed582f72017-01-23 07:55:42 -080062 build_dir_android = args.build_dir_android
63 build_dir_x86 = args.build_dir_x86
64 temp_dir = args.temp_dir
65 if not temp_dir:
66 temp_dir = tempfile.mkdtemp()
67 else:
68 if not os.path.exists(temp_dir):
69 os.makedirs(temp_dir)
70
71 if not build_dir_x86:
72 build_dir_x86 = os.path.join(temp_dir, 'LocalBuild')
73 _RunCommand(['gn', 'gen', build_dir_x86])
74 _RunCommand(['ninja', '-C', build_dir_x86, 'frame_analyzer'])
75
oprypin3b2fb202017-03-06 02:23:34 -080076 tools_dir = os.path.join(SRC_DIR, 'tools-webrtc')
77 toolchain_dir = os.path.join(tools_dir, 'video_quality_toolchain')
mandermoed582f72017-01-23 07:55:42 -080078
79 # Download ffmpeg and zxing.
oprypin3b2fb202017-03-06 02:23:34 -080080 download_script = os.path.join(tools_dir, 'download_tools.py')
81 _RunCommand([sys.executable, download_script, toolchain_dir])
mandermoed582f72017-01-23 07:55:42 -080082
83 # Run the Espresso code.
84 test_script = os.path.join(build_dir_android,
85 'bin', 'run_AppRTCMobileTestStubbedVideoIO')
86 _RunCommand([sys.executable, test_script])
87
88 # Pull the output video.
89 test_video = os.path.join(temp_dir, 'test_video.y4m')
90 _RunCommand(['adb', 'pull', '/sdcard/output.y4m', test_video])
91
92 test_video_yuv = os.path.join(temp_dir, 'test_video.yuv')
93
94 ffmpeg_path = os.path.join(toolchain_dir, 'linux', 'ffmpeg')
95
96 def convert_video(input_video, output_video):
97 _RunCommand([ffmpeg_path, '-y', '-i', input_video, output_video])
98
99 convert_video(test_video, test_video_yuv)
100
ehmaldonadod103f4b2017-02-16 07:20:26 -0800101 reference_video = os.path.join(SRC_DIR,
mandermoed582f72017-01-23 07:55:42 -0800102 'resources', 'reference_video_640x360_30fps.y4m')
103
104 reference_video_yuv = os.path.join(temp_dir,
105 'reference_video_640x360_30fps.yuv')
106
107 convert_video(reference_video, reference_video_yuv)
108
109 # Run compare script.
ehmaldonadod103f4b2017-02-16 07:20:26 -0800110 compare_script = os.path.join(SRC_DIR, 'webrtc', 'tools',
mandermoed582f72017-01-23 07:55:42 -0800111 'compare_videos.py')
112 zxing_path = os.path.join(toolchain_dir, 'linux', 'zxing')
113
114 # The frame_analyzer binary should be built for local computer and not for
115 # Android
116 frame_analyzer = os.path.join(build_dir_x86, 'frame_analyzer')
117
118 frame_width = 640
119 frame_height = 360
120
121 stats_file_ref = os.path.join(temp_dir, 'stats_ref.txt')
122 stats_file_test = os.path.join(temp_dir, 'stats_test.txt')
123
124 _RunCommand([
125 sys.executable, compare_script, '--ref_video', reference_video_yuv,
126 '--test_video', test_video_yuv, '--yuv_frame_width', str(frame_width),
127 '--yuv_frame_height', str(frame_height),
128 '--stats_file_ref', stats_file_ref,
129 '--stats_file_test', stats_file_test, '--frame_analyzer', frame_analyzer,
130 '--ffmpeg_path', ffmpeg_path, '--zxing_path', zxing_path])
131
132 shutil.rmtree(temp_dir)
133
134
135if __name__ == '__main__':
136 sys.exit(main())
137