mandermo | ed582f7 | 2017-01-23 07:55:42 -0800 | [diff] [blame] | 1 | #!/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 | """ |
| 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 |
| 13 | reference input video. |
| 14 | |
| 15 | It expect to be given the webrtc output build directory as the first argument |
| 16 | all other arguments are optional. |
| 17 | |
| 18 | It assumes you have a Android device plugged in. |
| 19 | """ |
| 20 | |
| 21 | import argparse |
| 22 | import logging |
| 23 | import os |
| 24 | import shutil |
| 25 | import subprocess |
| 26 | import sys |
| 27 | import tempfile |
| 28 | |
| 29 | |
| 30 | SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) |
kjellander | 3029210 | 2017-02-09 01:05:54 -0800 | [diff] [blame] | 31 | SRC_DIR = os.path.normpath(os.path.join(SCRIPT_DIR, os.pardir, os.pardir, |
| 32 | os.pardir)) |
mandermo | ed582f7 | 2017-01-23 07:55:42 -0800 | [diff] [blame] | 33 | |
| 34 | |
ehmaldonado | d103f4b | 2017-02-16 07:20:26 -0800 | [diff] [blame] | 35 | def _RunCommand(argv, cwd=SRC_DIR, **kwargs): |
mandermo | ed582f7 | 2017-01-23 07:55:42 -0800 | [diff] [blame] | 36 | logging.info('Running %r', argv) |
ehmaldonado | d103f4b | 2017-02-16 07:20:26 -0800 | [diff] [blame] | 37 | subprocess.check_call(argv, cwd=cwd, **kwargs) |
mandermo | ed582f7 | 2017-01-23 07:55:42 -0800 | [diff] [blame] | 38 | |
| 39 | |
| 40 | def _ParseArgs(): |
| 41 | parser = argparse.ArgumentParser(description='Start loopback video analysis.') |
mandermo | ed582f7 | 2017-01-23 07:55:42 -0800 | [diff] [blame] | 42 | 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 | |
| 53 | def main(): |
Henrik Kjellander | 6951a28 | 2017-02-19 06:53:23 +0100 | [diff] [blame^] | 54 | 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 | |
mandermo | ed582f7 | 2017-01-23 07:55:42 -0800 | [diff] [blame] | 59 | logging.basicConfig(level=logging.INFO) |
| 60 | |
| 61 | args = _ParseArgs() |
| 62 | |
mandermo | ed582f7 | 2017-01-23 07:55:42 -0800 | [diff] [blame] | 63 | 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 | |
ehmaldonado | d103f4b | 2017-02-16 07:20:26 -0800 | [diff] [blame] | 77 | toolchain_dir = os.path.join(SRC_DIR, 'tools-webrtc', |
mandermo | ed582f7 | 2017-01-23 07:55:42 -0800 | [diff] [blame] | 78 | '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 | |
ehmaldonado | d103f4b | 2017-02-16 07:20:26 -0800 | [diff] [blame] | 102 | reference_video = os.path.join(SRC_DIR, |
mandermo | ed582f7 | 2017-01-23 07:55:42 -0800 | [diff] [blame] | 103 | '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. |
ehmaldonado | d103f4b | 2017-02-16 07:20:26 -0800 | [diff] [blame] | 111 | compare_script = os.path.join(SRC_DIR, 'webrtc', 'tools', |
mandermo | ed582f7 | 2017-01-23 07:55:42 -0800 | [diff] [blame] | 112 | '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 | |
| 136 | if __name__ == '__main__': |
| 137 | sys.exit(main()) |
| 138 | |