Chromium Code Reviews| Index: webrtc/examples/androidapp/start_loopback_stubbed_camera_saved_video_out.py |
| diff --git a/webrtc/examples/androidapp/start_loopback_stubbed_camera_saved_video_out.py b/webrtc/examples/androidapp/start_loopback_stubbed_camera_saved_video_out.py |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..801f949f6ebd26392df61d343d7e3605a0c66cc3 |
| --- /dev/null |
| +++ b/webrtc/examples/androidapp/start_loopback_stubbed_camera_saved_video_out.py |
| @@ -0,0 +1,122 @@ |
| +# 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
|
| +# Use of this source code is governed by a BSD-style license |
| +# that can be found in the LICENSE file in the root of the source |
| +# tree. An additional intellectual property rights grant can be found |
| +# in the file PATENTS. All contributing project authors may |
| +# be found in the AUTHORS file in the root of the source tree. |
| +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.
|
| + |
| +from optparse import OptionParser |
| +import random |
| +import string |
| +import subprocess |
| +import sys |
| +import time |
| + |
| +def main(): |
| + parser = OptionParser() |
| + |
| + parser.add_option('--devname', dest='devname', help='The device id') |
| + |
| + parser.add_option( |
| + '--videooutsave', |
| + dest='videooutsave', |
| + help='The path where to save the video out file on local computer') |
| + |
| + parser.add_option( |
| + '--videoout', |
| + dest='videoout', |
| + help='The path where to put the video out file') |
| + |
| + parser.add_option( |
| + '--videoout_width', |
| + dest='videoout_width', |
| + type='int', |
| + help='The width for the video out file') |
| + |
| + parser.add_option( |
| + '--videoout_height', |
| + dest='videoout_height', |
| + type='int', |
| + help='The height for the video out file') |
| + |
| + parser.add_option( |
| + '--videoin', |
| + dest='videoin', |
| + help='The path where to read input file instead of camera') |
| + |
| + parser.add_option( |
| + '--call_length', |
| + dest='call_length', |
| + type='int', |
| + help='The length of the call') |
| + |
| + (options, args) = parser.parse_args() |
| + |
| + print (options, args) |
| + |
| + devname = options.devname |
| + |
| + videoin = options.videoin |
| + |
| + videoout = options.videoout |
| + videoout_width = options.videoout_width |
| + videoout_height = options.videoout_height |
| + |
| + videooutsave = options.videooutsave |
| + |
| + call_length = options.call_length or 10 |
| + |
| + room = ''.join(random.choice(string.ascii_letters + string.digits) |
| + for _ in range(8)) |
| + |
| + # Delete output video file. |
| + if videoout: |
| + subprocess.Popen(['adb', '-s', devname, 'shell', 'rm', |
| + videoout]) |
| + |
| + device = MonkeyRunner.waitForConnection(2, devname) |
| + |
| + extras = { |
| + '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.
|
| + 'org.appspot.apprtc.LOOPBACK': True, |
| + 'org.appspot.apprtc.VIDEOCODEC': 'VP8', |
| + 'org.appspot.apprtc.CAPTURETOTEXTURE': False, |
| + 'org.appspot.apprtc.CAMERA2': False, |
| + 'org.appspot.apprtc.ROOMID': room} |
| + |
| + if videoin: |
| + extras.update({'org.appspot.apprtc.VIDEO_FILE_AS_CAMERA': videoin}) |
| + |
| + if videoout: |
| + extras.update({ |
| + 'org.appspot.apprtc.SAVE_REMOTE_VIDEO_TO_FILE': videoout, |
| + 'org.appspot.apprtc.SAVE_REMOTE_VIDEO_TO_FILE_WIDTH': videoout_width, |
| + 'org.appspot.apprtc.SAVE_REMOTE_VIDEO_TO_FILE_HEIGHT': videoout_height}) |
| + |
| + print extras |
| + |
| + # ACTION_VIEW is equivalent to android.intent.action.VIEW, |
| + # see https://developer.android.com/reference/android/content/Intent.html#ACTION_VIEW. |
| + device.startActivity(data='https://appr.tc', action='ACTION_VIEW', |
| + component='org.appspot.apprtc/.CallActivity', extras=extras) |
| + |
| + print 'Running a call for %d seconds' % call_length |
| + for _ in xrange(call_length): |
| + sys.stdout.write('.') |
| + sys.stdout.flush() |
| + time.sleep(1) |
| + print '\nEnding call.' |
| + |
| + # Press back to end the call. Will end on both sides. |
| + device.press('KEYCODE_BACK', MonkeyDevice.DOWN_AND_UP) |
| + |
| + if videooutsave: |
| + time.sleep(2) |
| + |
| + subprocess.Popen(['adb', '-s', devname, 'pull', |
| + videoout, videooutsave]) |
| + |
| +if __name__ == '__main__': |
| + main() |
| + |