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