• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
9from optparse import OptionParser
10import random
11import string
12import subprocess
13import sys
14import time
15
16from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice
17
18
19def main():
20    parser = OptionParser()
21
22    parser.add_option('--devname', dest='devname', help='The device id')
23
24    parser.add_option(
25        '--videooutsave',
26        dest='videooutsave',
27        help='The path where to save the video out file on local computer')
28
29    parser.add_option('--videoout',
30                      dest='videoout',
31                      help='The path where to put the video out file')
32
33    parser.add_option('--videoout_width',
34                      dest='videoout_width',
35                      type='int',
36                      help='The width for the video out file')
37
38    parser.add_option('--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('--call_length',
49                      dest='call_length',
50                      type='int',
51                      help='The length of the call')
52
53    (options, args) = parser.parse_args()
54
55    print(options, args)
56
57    devname = options.devname
58
59    videoin = options.videoin
60
61    videoout = options.videoout
62    videoout_width = options.videoout_width
63    videoout_height = options.videoout_height
64
65    videooutsave = options.videooutsave
66
67    call_length = options.call_length or 10
68
69    room = ''.join(
70        random.choice(string.ascii_letters + string.digits) for _ in range(8))
71
72    # Delete output video file.
73    if videoout:
74        subprocess.check_call(
75            ['adb', '-s', devname, 'shell', 'rm', '-f', videoout])
76
77    device = MonkeyRunner.waitForConnection(2, devname)
78
79    extras = {
80        'org.appspot.apprtc.USE_VALUES_FROM_INTENT': True,
81        'org.appspot.apprtc.AUDIOCODEC': 'OPUS',
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
89    if videoin:
90        extras.update({'org.appspot.apprtc.VIDEO_FILE_AS_CAMERA': videoin})
91
92    if videoout:
93        extras.update({
94            'org.appspot.apprtc.SAVE_REMOTE_VIDEO_TO_FILE':
95            videoout,
96            'org.appspot.apprtc.SAVE_REMOTE_VIDEO_TO_FILE_WIDTH':
97            videoout_width,
98            'org.appspot.apprtc.SAVE_REMOTE_VIDEO_TO_FILE_HEIGHT':
99            videoout_height
100        })
101
102    print extras
103
104    device.startActivity(data='https://appr.tc',
105                         action='android.intent.action.VIEW',
106                         component='org.appspot.apprtc/.ConnectActivity',
107                         extras=extras)
108
109    print 'Running a call for %d seconds' % call_length
110    for _ in xrange(call_length):
111        sys.stdout.write('.')
112        sys.stdout.flush()
113        time.sleep(1)
114    print '\nEnding call.'
115
116    # Press back to end the call. Will end on both sides.
117    device.press('KEYCODE_BACK', MonkeyDevice.DOWN_AND_UP)
118
119    if videooutsave:
120        time.sleep(2)
121
122        subprocess.check_call(
123            ['adb', '-s', devname, 'pull', videoout, videooutsave])
124
125
126if __name__ == '__main__':
127    main()
128