blob: 9d111e3b374a514e694f75b712a46e62e87c70ab [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 '@@@STEP_WARNINGS@@@'
55 print 'This test is currently disabled (https://bugs.webrtc.org/7185)'
56 print '@@@STEP_LINK@Disabled@https://bugs.webrtc.org/7185@@@ (webrtc:7185)'
57 sys.exit(0)
58
mandermoed582f72017-01-23 07:55:42 -080059 logging.basicConfig(level=logging.INFO)
60
61 args = _ParseArgs()
62
mandermoed582f72017-01-23 07:55:42 -080063 build_dir_android = args.build_dir_android
64 build_dir_x86 = args.build_dir_x86
65 temp_dir = args.temp_dir
66 if not temp_dir:
67 temp_dir = tempfile.mkdtemp()
68 else:
69 if not os.path.exists(temp_dir):
70 os.makedirs(temp_dir)
71
72 if not build_dir_x86:
73 build_dir_x86 = os.path.join(temp_dir, 'LocalBuild')
74 _RunCommand(['gn', 'gen', build_dir_x86])
75 _RunCommand(['ninja', '-C', build_dir_x86, 'frame_analyzer'])
76
ehmaldonadod103f4b2017-02-16 07:20:26 -080077 toolchain_dir = os.path.join(SRC_DIR, 'tools-webrtc',
mandermoed582f72017-01-23 07:55:42 -080078 'video_quality_toolchain')
79
80 # Download ffmpeg and zxing.
81 download_script = os.path.join(toolchain_dir, 'download.py')
82 _RunCommand([sys.executable, download_script])
83
84 # Run the Espresso code.
85 test_script = os.path.join(build_dir_android,
86 'bin', 'run_AppRTCMobileTestStubbedVideoIO')
87 _RunCommand([sys.executable, test_script])
88
89 # Pull the output video.
90 test_video = os.path.join(temp_dir, 'test_video.y4m')
91 _RunCommand(['adb', 'pull', '/sdcard/output.y4m', test_video])
92
93 test_video_yuv = os.path.join(temp_dir, 'test_video.yuv')
94
95 ffmpeg_path = os.path.join(toolchain_dir, 'linux', 'ffmpeg')
96
97 def convert_video(input_video, output_video):
98 _RunCommand([ffmpeg_path, '-y', '-i', input_video, output_video])
99
100 convert_video(test_video, test_video_yuv)
101
ehmaldonadod103f4b2017-02-16 07:20:26 -0800102 reference_video = os.path.join(SRC_DIR,
mandermoed582f72017-01-23 07:55:42 -0800103 'resources', 'reference_video_640x360_30fps.y4m')
104
105 reference_video_yuv = os.path.join(temp_dir,
106 'reference_video_640x360_30fps.yuv')
107
108 convert_video(reference_video, reference_video_yuv)
109
110 # Run compare script.
ehmaldonadod103f4b2017-02-16 07:20:26 -0800111 compare_script = os.path.join(SRC_DIR, 'webrtc', 'tools',
mandermoed582f72017-01-23 07:55:42 -0800112 'compare_videos.py')
113 zxing_path = os.path.join(toolchain_dir, 'linux', 'zxing')
114
115 # The frame_analyzer binary should be built for local computer and not for
116 # Android
117 frame_analyzer = os.path.join(build_dir_x86, 'frame_analyzer')
118
119 frame_width = 640
120 frame_height = 360
121
122 stats_file_ref = os.path.join(temp_dir, 'stats_ref.txt')
123 stats_file_test = os.path.join(temp_dir, 'stats_test.txt')
124
125 _RunCommand([
126 sys.executable, compare_script, '--ref_video', reference_video_yuv,
127 '--test_video', test_video_yuv, '--yuv_frame_width', str(frame_width),
128 '--yuv_frame_height', str(frame_height),
129 '--stats_file_ref', stats_file_ref,
130 '--stats_file_test', stats_file_test, '--frame_analyzer', frame_analyzer,
131 '--ffmpeg_path', ffmpeg_path, '--zxing_path', zxing_path])
132
133 shutil.rmtree(temp_dir)
134
135
136if __name__ == '__main__':
137 sys.exit(main())
138