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