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 os | 6 import os |
6 import signal | 7 import signal |
7 import tempfile | 8 import tempfile |
8 | 9 |
9 from pylib import cmd_helper | 10 from pylib import cmd_helper |
| 11 from pylib.device import device_errors |
10 | 12 |
11 # TODO(jbudorick) Remove once telemetry gets switched over. | 13 # TODO(jbudorick) Remove once telemetry gets switched over. |
12 import pylib.android_commands | 14 import pylib.android_commands |
13 import pylib.device.device_utils | 15 import pylib.device.device_utils |
14 | 16 |
15 | 17 |
16 class VideoRecorder(object): | 18 class VideoRecorder(object): |
17 """Records a screen capture video from an Android Device (KitKat or newer). | 19 """Records a screen capture video from an Android Device (KitKat or newer). |
18 | 20 |
19 Args: | 21 Args: |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 if self._is_started: | 66 if self._is_started: |
65 break | 67 break |
66 return self._is_started | 68 return self._is_started |
67 | 69 |
68 def Stop(self): | 70 def Stop(self): |
69 """Stop recording video.""" | 71 """Stop recording video.""" |
70 os.remove(self._recorder_stdout) | 72 os.remove(self._recorder_stdout) |
71 self._is_started = False | 73 self._is_started = False |
72 if not self._recorder: | 74 if not self._recorder: |
73 return | 75 return |
74 self._device.KillAll('screenrecord', signum=signal.SIGINT) | 76 try: |
| 77 self._device.KillAll('screenrecord', signum=signal.SIGINT) |
| 78 except device_errors.CommandFailedError: |
| 79 logging.warning('Nothing to kill: screenrecord was not running') |
75 self._recorder.wait() | 80 self._recorder.wait() |
76 | 81 |
77 def Pull(self, host_file=None): | 82 def Pull(self, host_file=None): |
78 """Pull resulting video file from the device. | 83 """Pull resulting video file from the device. |
79 | 84 |
80 Args: | 85 Args: |
81 host_file: Path to the video file to store on the host. | 86 host_file: Path to the video file to store on the host. |
82 Returns: | 87 Returns: |
83 Output video file name on the host. | 88 Output video file name on the host. |
84 """ | 89 """ |
85 host_file_name = host_file or ('screen-recording-%s.mp4' % | 90 host_file_name = host_file or ('screen-recording-%s.mp4' % |
86 self._device.old_interface.GetTimestamp()) | 91 self._device.old_interface.GetTimestamp()) |
87 host_file_name = os.path.abspath(host_file_name) | 92 host_file_name = os.path.abspath(host_file_name) |
88 self._device.old_interface.EnsureHostDirectory(host_file_name) | 93 self._device.old_interface.EnsureHostDirectory(host_file_name) |
89 self._device.PullFile(self._device_file, host_file_name) | 94 self._device.PullFile(self._device_file, host_file_name) |
90 self._device.RunShellCommand('rm -f "%s"' % self._device_file) | 95 self._device.RunShellCommand('rm -f "%s"' % self._device_file) |
91 return host_file_name | 96 return host_file_name |
OLD | NEW |