mandermo | 1be3b12 | 2016-10-18 15:47:51 | [diff] [blame] | 1 | # Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. |
| 2 | # |
| 3 | # Use of this source code is governed by a BSD-style license |
| 4 | # that can be found in the LICENSE file in the root of the source |
| 5 | # tree. An additional intellectual property rights grant can be found |
| 6 | # in the file PATENTS. All contributing project authors may |
| 7 | # be found in the AUTHORS file in the root of the source tree. |
| 8 | |
| 9 | from optparse import OptionParser |
| 10 | import random |
| 11 | import string |
| 12 | import subprocess |
| 13 | import sys |
| 14 | import time |
| 15 | |
| 16 | from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice |
| 17 | |
| 18 | def main(): |
| 19 | parser = OptionParser() |
| 20 | |
| 21 | parser.add_option('--devname', dest='devname', help='The device id') |
| 22 | |
| 23 | parser.add_option( |
| 24 | '--videooutsave', |
| 25 | dest='videooutsave', |
| 26 | help='The path where to save the video out file on local computer') |
| 27 | |
| 28 | parser.add_option( |
| 29 | '--videoout', |
| 30 | dest='videoout', |
| 31 | help='The path where to put the video out file') |
| 32 | |
| 33 | parser.add_option( |
| 34 | '--videoout_width', |
| 35 | dest='videoout_width', |
| 36 | type='int', |
| 37 | help='The width for the video out file') |
| 38 | |
| 39 | parser.add_option( |
| 40 | '--videoout_height', |
| 41 | dest='videoout_height', |
| 42 | type='int', |
| 43 | help='The height for the video out file') |
| 44 | |
| 45 | parser.add_option( |
| 46 | '--videoin', |
| 47 | dest='videoin', |
| 48 | help='The path where to read input file instead of camera') |
| 49 | |
| 50 | parser.add_option( |
| 51 | '--call_length', |
| 52 | dest='call_length', |
| 53 | type='int', |
| 54 | help='The length of the call') |
| 55 | |
| 56 | (options, args) = parser.parse_args() |
| 57 | |
| 58 | print (options, args) |
| 59 | |
| 60 | devname = options.devname |
| 61 | |
| 62 | videoin = options.videoin |
| 63 | |
| 64 | videoout = options.videoout |
| 65 | videoout_width = options.videoout_width |
| 66 | videoout_height = options.videoout_height |
| 67 | |
| 68 | videooutsave = options.videooutsave |
| 69 | |
| 70 | call_length = options.call_length or 10 |
| 71 | |
| 72 | room = ''.join(random.choice(string.ascii_letters + string.digits) |
| 73 | for _ in range(8)) |
| 74 | |
| 75 | # Delete output video file. |
| 76 | if videoout: |
mandermo | 9a67d0b | 2016-11-16 10:31:25 | [diff] [blame] | 77 | subprocess.check_call(['adb', '-s', devname, 'shell', 'rm', '-f', |
mandermo | 1be3b12 | 2016-10-18 15:47:51 | [diff] [blame] | 78 | videoout]) |
| 79 | |
| 80 | device = MonkeyRunner.waitForConnection(2, devname) |
| 81 | |
| 82 | extras = { |
| 83 | 'org.appspot.apprtc.USE_VALUES_FROM_INTENT': True, |
| 84 | 'org.appspot.apprtc.AUDIOCODEC': 'OPUS', |
| 85 | 'org.appspot.apprtc.LOOPBACK': True, |
| 86 | 'org.appspot.apprtc.VIDEOCODEC': 'VP8', |
| 87 | 'org.appspot.apprtc.CAPTURETOTEXTURE': False, |
| 88 | 'org.appspot.apprtc.CAMERA2': False, |
| 89 | 'org.appspot.apprtc.ROOMID': room} |
| 90 | |
| 91 | if videoin: |
| 92 | extras.update({'org.appspot.apprtc.VIDEO_FILE_AS_CAMERA': videoin}) |
| 93 | |
| 94 | if videoout: |
| 95 | extras.update({ |
| 96 | 'org.appspot.apprtc.SAVE_REMOTE_VIDEO_TO_FILE': videoout, |
| 97 | 'org.appspot.apprtc.SAVE_REMOTE_VIDEO_TO_FILE_WIDTH': videoout_width, |
| 98 | 'org.appspot.apprtc.SAVE_REMOTE_VIDEO_TO_FILE_HEIGHT': videoout_height}) |
| 99 | |
| 100 | print extras |
| 101 | |
| 102 | device.startActivity(data='https://appr.tc', |
| 103 | action='android.intent.action.VIEW', |
| 104 | component='org.appspot.apprtc/.ConnectActivity', extras=extras) |
| 105 | |
| 106 | print 'Running a call for %d seconds' % call_length |
| 107 | for _ in xrange(call_length): |
| 108 | sys.stdout.write('.') |
| 109 | sys.stdout.flush() |
| 110 | time.sleep(1) |
| 111 | print '\nEnding call.' |
| 112 | |
| 113 | # Press back to end the call. Will end on both sides. |
| 114 | device.press('KEYCODE_BACK', MonkeyDevice.DOWN_AND_UP) |
| 115 | |
| 116 | if videooutsave: |
| 117 | time.sleep(2) |
| 118 | |
mandermo | d12dd15 | 2016-11-02 16:19:45 | [diff] [blame] | 119 | subprocess.check_call(['adb', '-s', devname, 'pull', |
mandermo | 1be3b12 | 2016-10-18 15:47:51 | [diff] [blame] | 120 | videoout, videooutsave]) |
| 121 | |
| 122 | if __name__ == '__main__': |
| 123 | main() |
| 124 | |