OLD | NEW |
1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 2013 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 import logging | 5 import logging |
6 import os | 6 import os |
7 import tempfile | 7 import tempfile |
8 import time | 8 import time |
9 | 9 |
10 from pylib import cmd_helper | 10 from pylib import cmd_helper |
11 from pylib import device_signal | 11 from pylib import device_signal |
12 from pylib.device import device_errors | 12 from pylib.device import device_errors |
13 | 13 |
14 # TODO(jbudorick) Remove once telemetry gets switched over. | |
15 import pylib.android_commands | |
16 import pylib.device.device_utils | 14 import pylib.device.device_utils |
17 | 15 |
18 | 16 |
19 class VideoRecorder(object): | 17 class VideoRecorder(object): |
20 """Records a screen capture video from an Android Device (KitKat or newer). | 18 """Records a screen capture video from an Android Device (KitKat or newer). |
21 | 19 |
22 Args: | 20 Args: |
23 device: DeviceUtils instance. | 21 device: DeviceUtils instance. |
24 host_file: Path to the video file to store on the host. | 22 host_file: Path to the video file to store on the host. |
25 megabits_per_second: Video bitrate in megabits per second. Allowed range | 23 megabits_per_second: Video bitrate in megabits per second. Allowed range |
26 from 0.1 to 100 mbps. | 24 from 0.1 to 100 mbps. |
27 size: Video frame size tuple (width, height) or None to use the device | 25 size: Video frame size tuple (width, height) or None to use the device |
28 default. | 26 default. |
29 rotate: If True, the video will be rotated 90 degrees. | 27 rotate: If True, the video will be rotated 90 degrees. |
30 """ | 28 """ |
31 def __init__(self, device, megabits_per_second=4, size=None, | 29 def __init__(self, device, megabits_per_second=4, size=None, |
32 rotate=False): | 30 rotate=False): |
33 # TODO(jbudorick) Remove once telemetry gets switched over. | |
34 assert not isinstance(device, pylib.android_commands.AndroidCommands) | |
35 self._device = device | 31 self._device = device |
36 self._device_file = ( | 32 self._device_file = ( |
37 '%s/screen-recording.mp4' % device.GetExternalStoragePath()) | 33 '%s/screen-recording.mp4' % device.GetExternalStoragePath()) |
38 self._recorder = None | 34 self._recorder = None |
39 self._recorder_stdout = None | 35 self._recorder_stdout = None |
40 self._is_started = False | 36 self._is_started = False |
41 | 37 |
42 self._args = ['adb'] | 38 self._args = ['adb'] |
43 if str(self._device): | 39 if str(self._device): |
44 self._args += ['-s', str(self._device)] | 40 self._args += ['-s', str(self._device)] |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 # TODO(jbudorick): Merge filename generation with the logic for doing so in | 85 # TODO(jbudorick): Merge filename generation with the logic for doing so in |
90 # DeviceUtils. | 86 # DeviceUtils. |
91 host_file_name = ( | 87 host_file_name = ( |
92 host_file | 88 host_file |
93 or 'screen-recording-%s.mp4' % time.strftime('%Y%m%dT%H%M%S', | 89 or 'screen-recording-%s.mp4' % time.strftime('%Y%m%dT%H%M%S', |
94 time.localtime())) | 90 time.localtime())) |
95 host_file_name = os.path.abspath(host_file_name) | 91 host_file_name = os.path.abspath(host_file_name) |
96 self._device.PullFile(self._device_file, host_file_name) | 92 self._device.PullFile(self._device_file, host_file_name) |
97 self._device.RunShellCommand('rm -f "%s"' % self._device_file) | 93 self._device.RunShellCommand('rm -f "%s"' % self._device_file) |
98 return host_file_name | 94 return host_file_name |
OLD | NEW |